Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,12 @@ else if (rot == TIFFConstants.ORIENTATION_RIGHTTOP || rot == TIFFConstants.ORIEN
if (dir.isTagPresent(TIFFConstants.TIFFTAG_PLANARCONFIG)
&& dir.getFieldAsLong(TIFFConstants.TIFFTAG_PLANARCONFIG) == TIFFConstants.PLANARCONFIG_SEPARATE)
throw new IllegalArgumentException(MessageLocalization.getComposedMessage("planar.images.are.not.supported"));
if (dir.isTagPresent(TIFFConstants.TIFFTAG_EXTRASAMPLES))
throw new IllegalArgumentException(MessageLocalization.getComposedMessage("extra.samples.are.not.supported"));
int samplePerPixel = 1;
if (dir.isTagPresent(TIFFConstants.TIFFTAG_SAMPLESPERPIXEL)) // 1,3,4
samplePerPixel = (int)dir.getFieldAsLong(TIFFConstants.TIFFTAG_SAMPLESPERPIXEL);
if (dir.isTagPresent(TIFFConstants.TIFFTAG_EXTRASAMPLES))
if(samplePerPixel != 4) // TIFFTAG_EXTRASAMPLES is supposed to be set when RGB image data has an alpha channel (the 4th channel in this case).
throw new IllegalArgumentException(MessageLocalization.getComposedMessage("extra.samples.are.not.supported"));
int bitsPerSample = 1;
if (dir.isTagPresent(TIFFConstants.TIFFTAG_BITSPERSAMPLE))
bitsPerSample = (int)dir.getFieldAsLong(TIFFConstants.TIFFTAG_BITSPERSAMPLE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.lowagie.text.pdf.codec;

import com.lowagie.text.pdf.RandomAccessFileOrArray;
import org.junit.Assert;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
* Tiff2PdfTest
*
* @author tellef
* @date 02.10.2017
*/
public class TiffReadingTest {

@Test
public void transparentTiffTest() throws IOException {
InputStream inputStream = TiffReadingTest.class.getClassLoader().getResourceAsStream("gradient.tiff");
byte[] data;

try(ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream()) {
int bytesRead;
byte[] buffer = new byte[8192];

while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
byteOutputStream.write(buffer, 0, bytesRead);
}

data = byteOutputStream.toByteArray();
}

RandomAccessFileOrArray ra = new RandomAccessFileOrArray(data);
int pages = TiffImage.getNumberOfPages(ra);

for (int i = 1; i <= pages; i++) {
Assert.assertNotNull(TiffImage.getTiffImage(ra, i));
}
}
}
Binary file added openpdf/src/test/resources/gradient.tiff
Binary file not shown.