@@ -25,20 +25,22 @@ internal static class TiffDecoderOptionsParser
2525 /// <returns>True, if the image uses tiles. Otherwise the images has strip's.</returns>
2626 public static bool VerifyAndParse ( this TiffDecoderCore options , ExifProfile exifProfile , TiffFrameMetadata frameMetadata )
2727 {
28- IExifValue extraSamplesExifValue = exifProfile . GetValueInternal ( ExifTag . ExtraSamples ) ;
29- if ( extraSamplesExifValue is not null )
28+ if ( exifProfile . TryGetValue ( ExifTag . ExtraSamples , out IExifValue < ushort [ ] > samples ) )
3029 {
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 )
3334 {
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 ;
3539 }
3640
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 ) )
4042 {
41- TiffThrowHelper . ThrowNotSupported ( "Decoding Tiff images with ExtraSamples is not supported with UnspecifiedData." ) ;
43+ options . ExtraSamplesType = sampleType ;
4244 }
4345 }
4446
0 commit comments