I'm trying to make tiled pyramidal tiffs from master tiff images using Java (JAI 1.1.3 + imageIO).
The problem is: I NEED to make tiff files compressed in jpeg with RGB photometric interpretation and no matter what I try, the image still faces YCbCr photometric interpretation.
Note: if I change compression type (eg. LZW or Deflate) I can get RGB colorspace but, as I said, I need jpeg compression.
Except this detail the tiled PTiff I create it's ok, so I think it's better to focus the attention on simple compression step (uncompressed tiff -- jpeg tiff)
this may be a basic example (removing any check to make it more readable)
// reading MASTER
BufferedImage img = ImageIO.read(uncompressedTiff);
ImageOutputStream ios=null;
ImageWriter writer=null;
ios = ImageIO.createImageOutputStream(outFile);
Iterator <ImageWriter> writers = ImageIO.getImageWritersByFormatName("tiff");
writer = writers.next();
// saving and compression params
writer.setOutput(ios);
ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionType("JPEG");
param.setCompressionQuality(0.8f);
param.setTilingMode(ImageWriteParam.MODE_EXPLICIT);
param.setTiling(256, 256, 0, 0);
IIOMetadata metadata = getWriteMD(writer, param);
// writing
writer.write(metadata, new IIOImage(img, null, metadata), param);
in getWriteMD method:
....
TIFFTag photoInterp = base.getTag(BaselineTIFFTagSet.TAG_PHOTOMETRIC_INTERPRETATION);
TIFFField fieldPhotoInter = new TIFFField(photoInterp, BaselineTIFFTagSet.PHOTOMETRIC_INTERPRETATION_RGB);
....
here is the full version of getWriteMD()