* @param imageObjectInfo the image object info
* @return a newly created IOCA Image Object
*/
public ImageObject createImage(AFPImageObjectInfo imageObjectInfo) {
// IOCA bitmap image
ImageObject imageObj = factory.createImageObject();
// set data object viewport (i.e. position, rotation, dimension, resolution)
imageObj.setViewport(imageObjectInfo);
if (imageObjectInfo.hasCompression()) {
int compression = imageObjectInfo.getCompression();
switch (compression) {
case TIFFImage.COMP_FAX_G3_1D:
imageObj.setEncoding(ImageContent.COMPID_G3_MH);
break;
case TIFFImage.COMP_FAX_G3_2D:
imageObj.setEncoding(ImageContent.COMPID_G3_MR);
break;
case TIFFImage.COMP_FAX_G4_2D:
imageObj.setEncoding(ImageContent.COMPID_G3_MMR);
break;
case ImageContent.COMPID_JPEG:
imageObj.setEncoding((byte)compression);
break;
default:
throw new IllegalStateException(
"Invalid compression scheme: " + compression);
}
}
ImageContent content = imageObj.getImageSegment().getImageContent();
int bitsPerPixel = imageObjectInfo.getBitsPerPixel();
imageObj.setIDESize((byte) bitsPerPixel);
IDEStructureParameter ideStruct;
switch (bitsPerPixel) {
case 1:
//Skip IDE Structure Parameter
break;
case 4:
case 8:
//A grayscale image
ideStruct = content.needIDEStructureParameter();
ideStruct.setBitsPerComponent(new int[] {bitsPerPixel});
ideStruct.setColorModel(IDEStructureParameter.COLOR_MODEL_YCBCR);
break;
case 24:
ideStruct = content.needIDEStructureParameter();
ideStruct.setDefaultRGBColorModel();
break;
case 32:
ideStruct = content.needIDEStructureParameter();
ideStruct.setDefaultCMYKColorModel();
break;
default:
throw new IllegalArgumentException("Unsupported number of bits per pixel: "
+ bitsPerPixel);
}
if (bitsPerPixel > 1 && imageObjectInfo.isSubtractive()) {
ideStruct = content.needIDEStructureParameter();
ideStruct.setSubtractive(imageObjectInfo.isSubtractive());
}
imageObj.setData(imageObjectInfo.getData());
return imageObj;
}