@@ -54,6 +54,7 @@ pub struct TgaDecoder<R> {
54
54
55
55
image_type : ImageType ,
56
56
color_type : ColorType ,
57
+ original_color_type : Option < ExtendedColorType > ,
57
58
58
59
header : Header ,
59
60
color_map : Option < ColorMap > ,
@@ -76,6 +77,7 @@ impl<R: Read + Seek> TgaDecoder<R> {
76
77
77
78
image_type : ImageType :: Unknown ,
78
79
color_type : ColorType :: L8 ,
80
+ original_color_type : None ,
79
81
80
82
header : Header :: default ( ) ,
81
83
color_map : None ,
@@ -153,6 +155,11 @@ impl<R: Read + Seek> TgaDecoder<R> {
153
155
( 0 , 24 , true ) => self . color_type = ColorType :: Rgb8 ,
154
156
( 8 , 8 , false ) => self . color_type = ColorType :: La8 ,
155
157
( 0 , 8 , false ) => self . color_type = ColorType :: L8 ,
158
+ ( 8 , 0 , false ) => {
159
+ // alpha-only image is treated as L8
160
+ self . color_type = ColorType :: L8 ;
161
+ self . original_color_type = Some ( ExtendedColorType :: A8 ) ;
162
+ } ,
156
163
_ => {
157
164
return Err ( ImageError :: Unsupported (
158
165
UnsupportedError :: from_format_and_kind (
@@ -376,6 +383,10 @@ impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for TgaDecoder<R> {
376
383
self . color_type
377
384
}
378
385
386
+ fn original_color_type ( & self ) -> ExtendedColorType {
387
+ self . original_color_type . unwrap_or_else ( || self . color_type ( ) . into ( ) )
388
+ }
389
+
379
390
fn scanline_bytes ( & self ) -> u64 {
380
391
// This cannot overflow because TGA has a maximum width of u16::MAX_VALUE and
381
392
// `bytes_per_pixel` is a u8.
0 commit comments