pub fn from_data<R: Read>(data: &mut R) -> TgaHeader {
        // we'll just read the header fields in order
        let mut id_length = [0];
        let mut colormap_type = [0];
        let mut image_type = [0];
        let mut colormap_spec = [0, 0, 0, 0, 0];
        let mut image_spec = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
        data.read_exact(&mut id_length)
            .expect("cannot read id length");
        data.read_exact(&mut colormap_type)
            .expect("cannot read colormap type");
        data.read_exact(&mut image_type)
            .expect("cannot read image type");
        data.read_exact(&mut colormap_spec)
            .expect("cannot read colormap spec");
        data.read_exact(&mut image_spec)
            .expect("cannot read image spec");

        // not all fields are used in this code,
        // but they are named for clarity
        let _id_length = id_length[0];
        let _colormap_type = colormap_type[0];
        let image_type = image_type[0];

        let _colormap_start = to_u16(&colormap_spec[0..2]);
        let colormap_length = to_u16(&colormap_spec[2..4]);
        let _colormap_bits = colormap_spec[4];

        let _origin_x = to_u16(&image_spec[0..2]);
        let _origin_y = to_u16(&image_spec[2..4]);
        let image_width = to_u16(&image_spec[4..6]) as usize;
        let image_height = to_u16(&image_spec[6..8]) as usize;
        let bit_depth = image_spec[8];
        let image_desc = image_spec[9];
        let _alpha_bits = image_desc & 0b0000_1111;
        let origin = (image_desc & 0b0011_0000) >> 4;

        assert_eq!(colormap_length, 0, "color maps are not supported");

        TgaHeader {
            image_type,
            image_width,
            image_height,
            bit_depth,
            origin,
        }
    }
/// Parse the TGA header in the given data.
Parse the TGA header in the given data.
Parse the TGA header in the given data .
pub fn from_data<R: Read>(data: &mut R) -> TgaHeader {
        // we'll just read the header fields in order
        let mut id_length = [0];
        let mut colormap_type = [0];
        let mut image_type = [0];
        let mut colormap_spec = [0, 0, 0, 0, 0];
        let mut image_spec = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
        data.read_exact(&mut id_length)
            .expect("cannot read id length");
        data.read_exact(&mut colormap_type)
            .expect("cannot read colormap type");
        data.read_exact(&mut image_type)
            .expect("cannot read image type");
        data.read_exact(&mut colormap_spec)
            .expect("cannot read colormap spec");
        data.read_exact(&mut image_spec)
            .expect("cannot read image spec");
        // not all fields are used in this code,
        // but they are named for clarity
        let _id_length = id_length[0];
        let _colormap_type = colormap_type[0];
        let image_type = image_type[0];
        let _colormap_start = to_u16(&colormap_spec[0..2]);
        let colormap_length = to_u16(&colormap_spec[2..4]);
        let _colormap_bits = colormap_spec[4];
        let _origin_x = to_u16(&image_spec[0..2]);
        let _origin_y = to_u16(&image_spec[2..4]);
        let image_width = to_u16(&image_spec[4..6]) as usize;
        let image_height = to_u16(&image_spec[6..8]) as usize;
        let bit_depth = image_spec[8];
        let image_desc = image_spec[9];
        let _alpha_bits = image_desc & 0b0000_1111;
        let origin = (image_desc & 0b0011_0000) >> 4;
        assert_eq!(colormap_length, 0, "color maps are not supported");
        TgaHeader {
            image_type,
            image_width,
            image_height,
            bit_depth,
            origin,
        }
    }
pub fn from_data < R : Read > ( data : & mut R ) -> TgaHeader { // we'll just read the header fields in order let mut id_length = [ 0 ] ; let mut colormap_type = [ 0 ] ; let mut image_type = [ 0 ] ; let mut colormap_spec = [ 0 , 0 , 0 , 0 , 0 ] ; let mut image_spec = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ; data . read_exact ( & mut id_length ) . expect ( " " ) ; data . read_exact ( & mut colormap_type ) . expect ( " " ) ; data . read_exact ( & mut image_type ) . expect ( " " ) ; data . read_exact ( & mut colormap_spec ) . expect ( " " ) ; data . read_exact ( & mut image_spec ) . expect ( " " ) ; // not all fields are used in this code, // but they are named for clarity let _id_length = id_length [ 0 ] ; let _colormap_type = colormap_type [ 0 ] ; let image_type = image_type [ 0 ] ; let _colormap_start = to_u16 ( & colormap_spec [ 0 .. 2 ] ) ; let colormap_length = to_u16 ( & colormap_spec [ 2 .. 4 ] ) ; let _colormap_bits = colormap_spec [ 4 ] ; let _origin_x = to_u16 ( & image_spec [ 0 .. 2 ] ) ; let _origin_y = to_u16 ( & image_spec [ 2 .. 4 ] ) ; let image_width = to_u16 ( & image_spec [ 4 .. 6 ] ) as usize ; let image_height = to_u16 ( & image_spec [ 6 .. 8 ] ) as usize ; let bit_depth = image_spec [ 8 ] ; let image_desc = image_spec [ 9 ] ; let _alpha_bits = image_desc & 0b0000_1111 ; let origin = ( image_desc & 0b0011_0000 ) >> 4 ; assert_eq ! ( colormap_length 0 " " ) ; TgaHeader { image_type , image_width , image_height , bit_depth , origin , } }
Parse the TGA header in the given data.
Parse the TGA header in the given data .
data
&mut R