@@ -265,36 +265,43 @@ impl Icon {
265265 // EXPAND and ALPHA do not expand grayscale images into RGBA. We can just do this manually.
266266 match info. color_type {
267267 ColorType :: GrayscaleAlpha => {
268- if rgba_buf. len ( ) as u32 != info. width * info. height * 2 {
269- return Err ( DmiError :: Generic ( String :: from ( "GrayscaleAlpha buffer length mismatch" ) ) ) ;
270- }
271- let mut new_buf = Vec :: with_capacity ( ( info. width * info. height * 4 ) as usize ) ;
272- for chunk in rgba_buf. chunks ( 2 ) {
273- let gray = chunk[ 0 ] ;
274- let alpha = chunk[ 1 ] ;
275- new_buf. push ( gray) ;
276- new_buf. push ( gray) ;
277- new_buf. push ( gray) ;
278- new_buf. push ( alpha) ;
279- }
280- rgba_buf = new_buf;
281- }
282- ColorType :: Grayscale => {
283- if rgba_buf. len ( ) as u32 != info. width * info. height {
284- return Err ( DmiError :: Generic ( String :: from ( "Grayscale buffer length mismatch" ) ) ) ;
285- }
286- let mut new_buf = Vec :: with_capacity ( ( info. width * info. height * 4 ) as usize ) ;
287- for gray in rgba_buf {
288- new_buf. push ( gray) ;
289- new_buf. push ( gray) ;
290- new_buf. push ( gray) ;
291- new_buf. push ( 255 ) ;
292- }
293- rgba_buf = new_buf;
294- }
268+ if rgba_buf. len ( ) as u32 != info. width * info. height * 2 {
269+ return Err ( DmiError :: Generic ( String :: from (
270+ "GrayscaleAlpha buffer length mismatch" ,
271+ ) ) ) ;
272+ }
273+ let mut new_buf = Vec :: with_capacity ( ( info. width * info. height * 4 ) as usize ) ;
274+ for chunk in rgba_buf. chunks ( 2 ) {
275+ let gray = chunk[ 0 ] ;
276+ let alpha = chunk[ 1 ] ;
277+ new_buf. push ( gray) ;
278+ new_buf. push ( gray) ;
279+ new_buf. push ( gray) ;
280+ new_buf. push ( alpha) ;
281+ }
282+ rgba_buf = new_buf;
283+ }
284+ ColorType :: Grayscale => {
285+ if rgba_buf. len ( ) as u32 != info. width * info. height {
286+ return Err ( DmiError :: Generic ( String :: from (
287+ "Grayscale buffer length mismatch" ,
288+ ) ) ) ;
289+ }
290+ let mut new_buf = Vec :: with_capacity ( ( info. width * info. height * 4 ) as usize ) ;
291+ for gray in rgba_buf {
292+ new_buf. push ( gray) ;
293+ new_buf. push ( gray) ;
294+ new_buf. push ( gray) ;
295+ new_buf. push ( 255 ) ;
296+ }
297+ rgba_buf = new_buf;
298+ }
295299 ColorType :: Rgba => { }
296300 _ => {
297- return Err ( DmiError :: Generic ( format ! ( "Unsupported ColorType (must be RGBA or convertible to RGBA): {:#?}" , info. color_type) ) ) ;
301+ return Err ( DmiError :: Generic ( format ! (
302+ "Unsupported ColorType (must be RGBA or convertible to RGBA): {:#?}" ,
303+ info. color_type
304+ ) ) ) ;
298305 }
299306 }
300307
0 commit comments