2828 RawDataSlice < ' a , R , LittleEndian > : IntoIterator < Item = R > ,
2929{
3030 /// Create a new raw color iterator.
31- pub fn new ( raw_bmp : & ' a RawBmp < ' a > ) -> Self {
31+ pub ( crate ) fn new ( raw_bmp : & ' a RawBmp < ' a > ) -> Self {
3232 let header = raw_bmp. header ( ) ;
3333
3434 let width = header. image_size . width as usize ;
@@ -62,24 +62,25 @@ where
6262 }
6363}
6464
65- /// Iterator over dynamic color. Positions are dependent on the row order.
66- #[ allow( missing_debug_implementations) ]
65+ /// Iterator over the raw colors in the image.
66+ ///
67+ /// See [`RawBmp::colors`](RawBmp::colors) for more information.
6768pub enum DynamicRawColors < ' a > {
6869 /// 1 bit per pixel
6970 Bpp1 ( RawColors < ' a , RawU1 > ) ,
70- /// 4 bit per pixel
71+ /// 4 bits per pixel
7172 Bpp4 ( RawColors < ' a , RawU4 > ) ,
72- /// 8 bit per pixel
73+ /// 8 bits per pixel
7374 Bpp8 ( RawColors < ' a , RawU8 > ) ,
74- /// 16 bit per pixel
75+ /// 16 bits per pixel
7576 Bpp16 ( RawColors < ' a , RawU16 > ) ,
76- /// 24 bit per pixel
77+ /// 24 bits per pixel
7778 Bpp24 ( RawColors < ' a , RawU24 > ) ,
78- /// 32 bit per pixel
79+ /// 32 bits per pixel
7980 Bpp32 ( RawColors < ' a , RawU32 > ) ,
80- /// 4 bit per pixel RLE encoded
81+ /// RLE encoded with 4 bits per pixel
8182 Bpp4Rle ( Rle4Colors < ' a > ) ,
82- /// 8 bit per pixel RLE encoded
83+ /// RLE encoded with 8 bits per pixel
8384 Bpp8Rle ( Rle8Colors < ' a > ) ,
8485}
8586
@@ -102,13 +103,14 @@ impl DynamicRawColors<'_> {
102103 /// Get the row order of the bitmap.
103104 pub fn row_order ( & self ) -> RowOrder {
104105 match self {
105- DynamicRawColors :: Bpp1 ( _)
106- | DynamicRawColors :: Bpp4 ( _)
107- | DynamicRawColors :: Bpp8 ( _)
108- | DynamicRawColors :: Bpp16 ( _)
109- | DynamicRawColors :: Bpp24 ( _)
110- | DynamicRawColors :: Bpp32 ( _) => RowOrder :: TopDown ,
111- DynamicRawColors :: Bpp4Rle ( _) | DynamicRawColors :: Bpp8Rle ( _) => RowOrder :: BottomUp ,
106+ DynamicRawColors :: Bpp1 ( colors) => colors. row_order ,
107+ DynamicRawColors :: Bpp4 ( colors) => colors. row_order ,
108+ DynamicRawColors :: Bpp8 ( colors) => colors. row_order ,
109+ DynamicRawColors :: Bpp16 ( colors) => colors. row_order ,
110+ DynamicRawColors :: Bpp24 ( colors) => colors. row_order ,
111+ DynamicRawColors :: Bpp32 ( colors) => colors. row_order ,
112+ DynamicRawColors :: Bpp4Rle ( _) => RowOrder :: BottomUp ,
113+ DynamicRawColors :: Bpp8Rle ( _) => RowOrder :: BottomUp ,
112114 }
113115 }
114116}
@@ -124,8 +126,8 @@ impl Iterator for DynamicRawColors<'_> {
124126 DynamicRawColors :: Bpp16 ( colors) => colors. next ( ) . map ( |r| u32:: from ( r. into_inner ( ) ) ) ,
125127 DynamicRawColors :: Bpp24 ( colors) => colors. next ( ) . map ( |r| r. into_inner ( ) ) ,
126128 DynamicRawColors :: Bpp32 ( colors) => colors. next ( ) . map ( |r| r. into_inner ( ) ) ,
127- DynamicRawColors :: Bpp4Rle ( state ) => state . next ( ) . map ( |r| u32:: from ( r. into_inner ( ) ) ) ,
128- DynamicRawColors :: Bpp8Rle ( state ) => state . next ( ) . map ( |r| u32:: from ( r. into_inner ( ) ) ) ,
129+ DynamicRawColors :: Bpp4Rle ( colors ) => colors . next ( ) . map ( |r| u32:: from ( r. into_inner ( ) ) ) ,
130+ DynamicRawColors :: Bpp8Rle ( colors ) => colors . next ( ) . map ( |r| u32:: from ( r. into_inner ( ) ) ) ,
129131 }
130132 }
131133}
@@ -152,25 +154,24 @@ enum RleState {
152154}
153155
154156pub struct PixelPoints {
155- /// The location of the next pixel
157+ /// The location of the next pixel.
156158 next_pixel : Point ,
157- /// The width of a line in pixels
159+ /// The number of pixels in a row.
158160 width : u32 ,
159161}
160162
161- /// Iterator over individual BMP RLE8 encoded pixels.
162- ///
163- /// Each pixel is returned as a `u32` regardless of the bit depth of the source image.
164- #[ derive( Debug ) ]
165- pub struct Rle8Colors < ' a > {
166- /// Our source data
167- data : & ' a [ u8 ] ,
168- /// Our state
169- rle_state : RleState ,
170- start_of_line : bool ,
171- }
172-
173163impl PixelPoints {
164+ pub ( crate ) fn new ( image_size : Size , row_order : RowOrder ) -> Self {
165+ let next_pixel = match row_order {
166+ RowOrder :: TopDown => Point :: new ( 0 , 0 ) ,
167+ RowOrder :: BottomUp => Point :: new ( 0 , ( image_size. height - 1 ) as i32 ) ,
168+ } ;
169+ Self {
170+ next_pixel,
171+ width : image_size. width ,
172+ }
173+ }
174+
174175 fn next_up_dir ( & mut self ) -> Point {
175176 let old_position = self . next_pixel ;
176177 self . next_pixel . x += 1 ;
@@ -192,26 +193,31 @@ impl PixelPoints {
192193 }
193194}
194195
196+ /// Iterator over individual BMP RLE8 encoded pixels.
197+ ///
198+ /// Each pixel is returned as a `u32` regardless of the bit depth of the source image.
199+ #[ derive( Debug ) ]
200+ pub struct Rle8Colors < ' a > {
201+ /// Our source data
202+ data : & ' a [ u8 ] ,
203+ /// Our state
204+ rle_state : RleState ,
205+ start_of_row : bool ,
206+ }
207+
195208impl < ' a > Rle8Colors < ' a > {
196209 /// Create a new RLE pixel iterator.
197- pub ( crate ) fn new ( raw_bmp : & RawBmp < ' a > ) -> ( Rle8Colors < ' a > , PixelPoints ) {
198- let header = raw_bmp. header ( ) ;
199- let points = PixelPoints {
200- width : header. image_size . width ,
201- // RLE encoded bitmaps are upside down
202- next_pixel : Point :: new ( 0 , ( header. image_size . height - 1 ) as i32 ) ,
203- } ;
204- let this = Rle8Colors {
210+ pub ( crate ) fn new ( raw_bmp : & RawBmp < ' a > ) -> Rle8Colors < ' a > {
211+ Rle8Colors {
205212 data : raw_bmp. image_data ( ) ,
206213 rle_state : RleState :: Starting ,
207- start_of_line : false ,
208- } ;
209- ( this, points)
214+ start_of_row : false ,
215+ }
210216 }
211217
212218 /// Indicate that a new line is starting. Required for correct RLE decoding.
213- pub fn start_a_line ( & mut self ) {
214- self . start_of_line = true ;
219+ pub fn start_row ( & mut self ) {
220+ self . start_of_row = true ;
215221 }
216222}
217223
@@ -276,7 +282,7 @@ impl<'a> Iterator for Rle8Colors<'a> {
276282 // the pair, which can be one of the following values.
277283 match param {
278284 0 => {
279- if !self . start_of_line {
285+ if !self . start_of_row {
280286 return None ;
281287 }
282288 }
@@ -323,29 +329,22 @@ pub struct Rle4Colors<'a> {
323329 data : & ' a [ u8 ] ,
324330 /// Our state
325331 rle_state : RleState ,
326- start_of_line : bool ,
332+ start_of_row : bool ,
327333}
328334
329335impl < ' a > Rle4Colors < ' a > {
330336 /// Create a new RLE pixel iterator.
331- pub ( crate ) fn new ( raw_bmp : & RawBmp < ' a > ) -> ( Rle4Colors < ' a > , PixelPoints ) {
332- let header = raw_bmp. header ( ) ;
333- let points = PixelPoints {
334- width : header. image_size . width ,
335- // RLE encoded bitmaps are upside down
336- next_pixel : Point :: new ( 0 , ( header. image_size . height - 1 ) as i32 ) ,
337- } ;
338- let this = Rle4Colors {
337+ pub ( crate ) fn new ( raw_bmp : & RawBmp < ' a > ) -> Rle4Colors < ' a > {
338+ Rle4Colors {
339339 data : raw_bmp. image_data ( ) ,
340340 rle_state : RleState :: Starting ,
341- start_of_line : false ,
342- } ;
343- ( this, points)
341+ start_of_row : false ,
342+ }
344343 }
345344
346345 /// Indicate that a new line is starting. Required for correct RLE decoding.
347- pub fn start_a_line ( & mut self ) {
348- self . start_of_line = true ;
346+ pub fn start_row ( & mut self ) {
347+ self . start_of_row = true ;
349348 }
350349}
351350
@@ -449,7 +448,7 @@ impl<'a> Iterator for Rle4Colors<'a> {
449448 // the pair, which can be one of the following values.
450449 match param {
451450 0 => {
452- if !self . start_of_line {
451+ if !self . start_of_row {
453452 return None ;
454453 }
455454 }
@@ -502,14 +501,16 @@ impl<'a> RawPixels<'a> {
502501 let header = raw_bmp. header ( ) ;
503502 match header. compression_method {
504503 CompressionMethod :: Rle4 => {
505- let ( colors, points) = Rle4Colors :: new ( raw_bmp) ;
504+ let colors = Rle4Colors :: new ( raw_bmp) ;
505+ let points = PixelPoints :: new ( header. image_size , RowOrder :: BottomUp ) ;
506506 Self {
507507 colors : DynamicRawColors :: Bpp4Rle ( colors) ,
508508 points,
509509 }
510510 }
511511 CompressionMethod :: Rle8 => {
512- let ( colors, points) = Rle8Colors :: new ( raw_bmp) ;
512+ let colors = Rle8Colors :: new ( raw_bmp) ;
513+ let points = PixelPoints :: new ( header. image_size , RowOrder :: BottomUp ) ;
513514 Self {
514515 colors : DynamicRawColors :: Bpp8Rle ( colors) ,
515516 points,
0 commit comments