Skip to main content

Java ImageIO Read and Write compressed Tiff files with CIE lab colorspace

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
L_tD
Offline
Joined: 2014-07-14

Hi,

I'm new here and I'm not sure if this is the correct forum for this, but maybe someone could help.

I actually try to read and write compressed tif-files with CIE Lab colorspace.
Unfortunally if I try to just read and after this write the tif back to the HDD the color is different from the soure tif.
Is the ImageIO lib able to read and write compressed tif files with CIE lab color space?
Interesting is that both (GIMP and Photoshop) says that the source and the result image are both lab 8 bit images, but the
result is much brighter than the source, very confusing.

If it is possible to process such files with the imageIO lib I fear there is something wrong with my code?

Would be great if someone could help me. Thanks a lot!

<

public class TiffWriter
{
public static void main(String[] args) throws IOException, SaveErrorException
{
ArrayList list = new ArrayList<>();
File testTiff = new File("C:/temp/PA993862_hgb.tif");
ImageInputStream iis = ImageIO.createImageInputStream(testTiff);

Iterator readerIterator = ImageIO.getImageReadersByFormatName("tiff");
TIFFImageReader imageReader = (TIFFImageReader) readerIterator.next();
imageReader.setInput(iis);

TIFFImageReadParam tiffReadParam = new TIFFImageReadParam();
BufferedImage source = imageReader.read(0, tiffReadParam);
IIOMetadata imageMetadata = imageReader.getImageMetadata(0);
list.add(source);

File output = new File("C:/Temp/output.tif");

mergeTIFFs(list, output, imageMetadata);

// Done writing all images for this image
imageReader.dispose();
}

public static void mergeTIFFs(List singleTiffs, File newMultiPageTIFF, IIOMetadata imageMetadata) throws IOException
{
Iterator writers = ImageIO.getImageWritersByFormatName("tiff");
TIFFImageWriter writer = (TIFFImageWriter) writers.next();
ImageOutputStream ios = ImageIO.createImageOutputStream(newMultiPageTIFF);
writer.setOutput(ios);

// Write each image out to the new file
boolean firstImage = true;
for(int i = 0; i < singleTiffs.size(); i++)
{
BufferedImage bi = singleTiffs.get(i);
IIOImage image = new IIOImage(bi, null, imageMetadata);
if(firstImage)
{
TIFFImageWriteParam tiffWriteParam = new TIFFImageWriteParam(Locale.US);
tiffWriteParam.setCompressionMode(ImageWriteParam.MODE_COPY_FROM_METADATA);
writer.write(imageMetadata, image, tiffWriteParam);
firstImage = false;
}
else
{
TIFFImageWriteParam tiffWriteParam = new TIFFImageWriteParam(Locale.US);
tiffWriteParam.setCompressionMode(ImageWriteParam.MODE_COPY_FROM_METADATA);
writer.writeInsert(i, image, tiffWriteParam);
}
}
// End writing of all files
writer.dispose();
}
}
>