File tree Expand file tree Collapse file tree
main/java/com/lowagie/text/pdf/codec
java/com/lowagie/text/pdf/codec Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -325,11 +325,12 @@ else if (rot == TIFFConstants.ORIENTATION_RIGHTTOP || rot == TIFFConstants.ORIEN
325325 if (dir .isTagPresent (TIFFConstants .TIFFTAG_PLANARCONFIG )
326326 && dir .getFieldAsLong (TIFFConstants .TIFFTAG_PLANARCONFIG ) == TIFFConstants .PLANARCONFIG_SEPARATE )
327327 throw new IllegalArgumentException (MessageLocalization .getComposedMessage ("planar.images.are.not.supported" ));
328- if (dir .isTagPresent (TIFFConstants .TIFFTAG_EXTRASAMPLES ))
329- throw new IllegalArgumentException (MessageLocalization .getComposedMessage ("extra.samples.are.not.supported" ));
330328 int samplePerPixel = 1 ;
331329 if (dir .isTagPresent (TIFFConstants .TIFFTAG_SAMPLESPERPIXEL )) // 1,3,4
332330 samplePerPixel = (int )dir .getFieldAsLong (TIFFConstants .TIFFTAG_SAMPLESPERPIXEL );
331+ if (dir .isTagPresent (TIFFConstants .TIFFTAG_EXTRASAMPLES ))
332+ if (samplePerPixel != 4 ) // TIFFTAG_EXTRASAMPLES is supposed to be set when RGB image data has an alpha channel (the 4th channel in this case).
333+ throw new IllegalArgumentException (MessageLocalization .getComposedMessage ("extra.samples.are.not.supported" ));
333334 int bitsPerSample = 1 ;
334335 if (dir .isTagPresent (TIFFConstants .TIFFTAG_BITSPERSAMPLE ))
335336 bitsPerSample = (int )dir .getFieldAsLong (TIFFConstants .TIFFTAG_BITSPERSAMPLE );
Original file line number Diff line number Diff line change 1+ package com .lowagie .text .pdf .codec ;
2+
3+ import com .lowagie .text .pdf .RandomAccessFileOrArray ;
4+ import org .junit .Assert ;
5+ import org .junit .Test ;
6+
7+ import java .io .ByteArrayOutputStream ;
8+ import java .io .IOException ;
9+ import java .io .InputStream ;
10+
11+ /**
12+ * Tiff2PdfTest
13+ *
14+ * @author tellef
15+ * @date 02.10.2017
16+ */
17+ public class TiffReadingTest {
18+
19+ @ Test
20+ public void transparentTiffTest () throws IOException {
21+ InputStream inputStream = TiffReadingTest .class .getClassLoader ().getResourceAsStream ("gradient.tiff" );
22+ byte [] data ;
23+
24+ try (ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream ()) {
25+ int bytesRead ;
26+ byte [] buffer = new byte [8192 ];
27+
28+ while ((bytesRead = inputStream .read (buffer , 0 , 8192 )) != -1 ) {
29+ byteOutputStream .write (buffer , 0 , bytesRead );
30+ }
31+
32+ data = byteOutputStream .toByteArray ();
33+ }
34+
35+ RandomAccessFileOrArray ra = new RandomAccessFileOrArray (data );
36+ int pages = TiffImage .getNumberOfPages (ra );
37+
38+ for (int i = 1 ; i <= pages ; i ++) {
39+ Assert .assertNotNull (TiffImage .getTiffImage (ra , i ));
40+ }
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments