// TODO: Consolodate these image decoders into one crate
Consolodate these image decoders into one crate
Consolodate these image decoders into one crate
fn create_image(image_data: &[u8], palette_data: &[u8], texture_width: u32, texture_height: u32) -> image::ImageBuffer<image::Bgra<u8>, Vec<u8>> {
    let mut image_bgra_data = Vec::<u8>::new();
    for palette_index in image_data {
        let index = (*palette_index as usize) * 3;
        let r_color = palette_data[index + 0];
        let g_color = palette_data[index + 1];
        let b_color = palette_data[index + 2];
        if r_color == 0 &&
            g_color == 0 &&
            b_color == 255 {
            image_bgra_data.push(0);
            image_bgra_data.push(0);
            image_bgra_data.push(0);
            image_bgra_data.push(0);
        } else {
            // documentation says that this should be RGB data...
            // but it looks to be bgr?
            image_bgra_data.push(r_color); // should be b
            image_bgra_data.push(g_color);
            image_bgra_data.push(b_color); // should be r
            image_bgra_data.push(255);
        }
    }
    image::ImageBuffer::<image::Bgra<u8>, Vec<u8>>::from_vec(texture_width, texture_height, image_bgra_data).unwrap()
}
fn create_image ( image_data : & [ u8 ] , palette_data : & [ u8 ] , texture_width : u32 , texture_height : u32 ) -> image :: ImageBuffer < image :: Bgra < u8 > , Vec < u8 > > { let mut image_bgra_data = Vec :: < u8 > :: new ( ) ; for palette_index in image_data { let index = ( * palette_index as usize ) * 3 ; let r_color = palette_data [ index + 0 ] ; let g_color = palette_data [ index + 1 ] ; let b_color = palette_data [ index + 2 ] ; if r_color == 0 && g_color == 0 && b_color == 255 { image_bgra_data . push ( 0 ) ; image_bgra_data . push ( 0 ) ; image_bgra_data . push ( 0 ) ; image_bgra_data . push ( 0 ) ; } else { // documentation says that this should be RGB data... // but it looks to be bgr? image_bgra_data . push ( r_color ) ; // should be b image_bgra_data . push ( g_color ) ; image_bgra_data . push ( b_color ) ; // should be r image_bgra_data . push ( 255 ) ; } } image :: ImageBuffer :: < image :: Bgra < u8 > , Vec < u8 > > :: from_vec ( texture_width , texture_height , image_bgra_data ) . unwrap ( ) }
TODO: Consolodate these image decoders into one crate
TODO : Consolodate these image decoders into one crate
image_data
&[u8]
palette_data
&[u8]
texture_width
u32
texture_height
u32