@@ -25,20 +25,22 @@ internal static class TiffDecoderOptionsParser
25
25
/// <returns>True, if the image uses tiles. Otherwise the images has strip's.</returns>
26
26
public static bool VerifyAndParse ( this TiffDecoderCore options , ExifProfile exifProfile , TiffFrameMetadata frameMetadata )
27
27
{
28
- IExifValue extraSamplesExifValue = exifProfile . GetValueInternal ( ExifTag . ExtraSamples ) ;
29
- if ( extraSamplesExifValue is not null )
28
+ if ( exifProfile . TryGetValue ( ExifTag . ExtraSamples , out IExifValue < ushort [ ] > samples ) )
30
29
{
31
- short [ ] extraSamples = ( short [ ] ) extraSamplesExifValue . GetValue ( ) ;
32
- if ( extraSamples . Length != 1 )
30
+ // We only support a single sample pertaining to alpha data.
31
+ // Other information is discarded.
32
+ TiffExtraSampleType sampleType = ( TiffExtraSampleType ) samples . Value [ 0 ] ;
33
+ if ( sampleType is TiffExtraSampleType . CorelDrawUnassociatedAlphaData )
33
34
{
34
- TiffThrowHelper . ThrowNotSupported ( "ExtraSamples is only supported with one extra sample for alpha data." ) ;
35
+ // According to libtiff, this CorelDRAW-specific value indicates unassociated alpha.
36
+ // Patch required for compatibility with malformed CorelDRAW-generated TIFFs.
37
+ // https://libtiff.gitlab.io/libtiff/releases/v3.9.0beta.html
38
+ sampleType = TiffExtraSampleType . UnassociatedAlphaData ;
35
39
}
36
40
37
- TiffExtraSampleType extraSamplesType = ( TiffExtraSampleType ) extraSamples [ 0 ] ;
38
- options . ExtraSamplesType = extraSamplesType ;
39
- if ( extraSamplesType is not ( TiffExtraSampleType . UnassociatedAlphaData or TiffExtraSampleType . AssociatedAlphaData ) )
41
+ if ( sampleType is ( TiffExtraSampleType . UnassociatedAlphaData or TiffExtraSampleType . AssociatedAlphaData ) )
40
42
{
41
- TiffThrowHelper . ThrowNotSupported ( "Decoding Tiff images with ExtraSamples is not supported with UnspecifiedData." ) ;
43
+ options . ExtraSamplesType = sampleType ;
42
44
}
43
45
}
44
46
0 commit comments