fn parse_heirarchy<R: Read + Seek>(mut rdr: R) -> Result<PixelData, Error> {
        // read the heirarchy
        let width = rdr.read_u32::<BigEndian>()? as usize;
        let height = rdr.read_u32::<BigEndian>()? as usize;
        let bpp = rdr.read_u32::<BigEndian>()? as usize;
        if bpp != 3 && bpp != 4 {
            return Err(Error::NotSupported);
        }
        let lptr = rdr.read_u32::<BigEndian>()?;
        let _dummpy_ptr_pos = rdr.seek(SeekFrom::Current(0))?;
        rdr.seek(SeekFrom::Start(lptr as u64))?;
        // read the level
        let level_width = rdr.read_u32::<BigEndian>()? as usize;
        let level_height = rdr.read_u32::<BigEndian>()? as usize;
        if level_width != width || level_height != height {
            return Err(Error::InvalidFormat);
        }

        let mut pixels = vec![RgbaPixel([0, 0, 0, 255]); (width * height) as usize];
        let mut next_tptr_pos;

        let tiles_x = (width as f32 / 64.0).ceil() as usize;
        let tiles_y = (height as f32 / 64.0).ceil() as usize;
        for ty in 0..tiles_y {
            for tx in 0..tiles_x {
                let tptr = rdr.read_u32::<BigEndian>()?;
                next_tptr_pos = rdr.seek(SeekFrom::Current(0))?;
                rdr.seek(SeekFrom::Start(tptr as u64))?;

                let mut cursor = TileCursor::new(width, height, tx, ty, bpp);
                cursor.feed(&mut rdr, &mut pixels)?;

                rdr.seek(SeekFrom::Start(next_tptr_pos))?;
            }
        }

        // rdr.seek(SeekFrom::Start(dummpy_ptr_pos))?;
        // TODO: dummy levels? do we need to consider them?
        // if we do:
        /*loop {
            let dummy_level_ptr = rdr.read_u32::<BigEndian>()?;
            if dummy_level_ptr == 0 {
                break;
            }
        }*/
        // we are now at the end of the heirarchy structure.

        Ok(PixelData { pixels, width, height })
    }
/// Parses the (silly?) heirarchy structure in the xcf file into a pixel array
/// Makes lots of assumptions! Only supports RGBA for now.
Parses the (silly?) heirarchy structure in the xcf file into a pixel array
Makes lots of assumptions. Only supports RGBA for now.
Parses the ( silly? ) heirarchy structure in the xcf file into a pixel array Makes lots of assumptions . Only supports RGBA for now .
fn parse_heirarchy<R: Read + Seek>(mut rdr: R) -> Result<PixelData, Error> {
        // read the heirarchy
        let width = rdr.read_u32::<BigEndian>()? as usize;
        let height = rdr.read_u32::<BigEndian>()? as usize;
        let bpp = rdr.read_u32::<BigEndian>()? as usize;
        if bpp != 3 && bpp != 4 {
            return Err(Error::NotSupported);
        }
        let lptr = rdr.read_u32::<BigEndian>()?;
        let _dummpy_ptr_pos = rdr.seek(SeekFrom::Current(0))?;
        rdr.seek(SeekFrom::Start(lptr as u64))?;
        // read the level
        let level_width = rdr.read_u32::<BigEndian>()? as usize;
        let level_height = rdr.read_u32::<BigEndian>()? as usize;
        if level_width != width || level_height != height {
            return Err(Error::InvalidFormat);
        }
        let mut pixels = vec![RgbaPixel([0, 0, 0, 255]); (width * height) as usize];
        let mut next_tptr_pos;
        let tiles_x = (width as f32 / 64.0).ceil() as usize;
        let tiles_y = (height as f32 / 64.0).ceil() as usize;
        for ty in 0..tiles_y {
            for tx in 0..tiles_x {
                let tptr = rdr.read_u32::<BigEndian>()?;
                next_tptr_pos = rdr.seek(SeekFrom::Current(0))?;
                rdr.seek(SeekFrom::Start(tptr as u64))?;
                let mut cursor = TileCursor::new(width, height, tx, ty, bpp);
                cursor.feed(&mut rdr, &mut pixels)?;
                rdr.seek(SeekFrom::Start(next_tptr_pos))?;
            }
        }
        // rdr.seek(SeekFrom::Start(dummpy_ptr_pos))?;
        // TODO: dummy levels? do we need to consider them?
        // if we do:
        /*loop {
            let dummy_level_ptr = rdr.read_u32::<BigEndian>()?;
            if dummy_level_ptr == 0 {
                break;
            }
        }*/
        // we are now at the end of the heirarchy structure.
        Ok(PixelData { pixels, width, height })
    }
fn parse_heirarchy < R : Read + Seek > ( mut rdr : R ) -> Result < PixelData , Error > { // read the heirarchy let width = rdr . read_u32 :: < BigEndian > ( ) ? as usize ; let height = rdr . read_u32 :: < BigEndian > ( ) ? as usize ; let bpp = rdr . read_u32 :: < BigEndian > ( ) ? as usize ; if bpp != 3 && bpp != 4 { return Err ( Error :: NotSupported ) ; } let lptr = rdr . read_u32 :: < BigEndian > ( ) ? ; let _dummpy_ptr_pos = rdr . seek ( SeekFrom :: Current ( 0 ) ) ? ; rdr . seek ( SeekFrom :: Start ( lptr as u64 ) ) ? ; // read the level let level_width = rdr . read_u32 :: < BigEndian > ( ) ? as usize ; let level_height = rdr . read_u32 :: < BigEndian > ( ) ? as usize ; if level_width != width || level_height != height { return Err ( Error :: InvalidFormat ) ; } let mut pixels = vec ! [ RgbaPixel ( [ 0 0 0 255 ] ) ( width height ) as usize ] ; let mut next_tptr_pos ; let tiles_x = ( width as f32 / 64.0 ) . ceil ( ) as usize ; let tiles_y = ( height as f32 / 64.0 ) . ceil ( ) as usize ; for ty in 0 .. tiles_y { for tx in 0 .. tiles_x { let tptr = rdr . read_u32 :: < BigEndian > ( ) ? ; next_tptr_pos = rdr . seek ( SeekFrom :: Current ( 0 ) ) ? ; rdr . seek ( SeekFrom :: Start ( tptr as u64 ) ) ? ; let mut cursor = TileCursor :: new ( width , height , tx , ty , bpp ) ; cursor . feed ( & mut rdr , & mut pixels ) ? ; rdr . seek ( SeekFrom :: Start ( next_tptr_pos ) ) ? ; } } // rdr.seek(SeekFrom::Start(dummpy_ptr_pos))?; // TODO: dummy levels? do we need to consider them? // if we do: /*loop {
            let dummy_level_ptr = rdr.read_u32::<BigEndian>()?;
            if dummy_level_ptr == 0 {
                break;
            }
        }*/ // we are now at the end of the heirarchy structure. Ok ( PixelData { pixels , width , height } ) }
Parses the (silly?)
Parses the ( silly? )
rdr
R
rdr
R