/** * Return the closest compatible {@link IcyColorModel} supported by writer from the specified * image description.<br> * That means the writer is able to save the data described by the returned {@link IcyColorModel} * without any loss or conversion.<br> * * @param writer IFormatWriter we want to test compatibility * @param numChannel number of channel of the image * @param dataType image data type */ public static IcyColorModel getCompatibleColorModel( IFormatWriter writer, int numChannel, DataType dataType) { final DataType outDataType; final int outNumChannel; if (writer instanceof OMETiffWriter) { // TIFF supports all formats outDataType = dataType; outNumChannel = numChannel; } else if (writer instanceof APNGWriter) { // PNG only supports byte and short data type if (dataType.getSize() > 2) outDataType = DataType.USHORT; else outDataType = dataType; // PNG supports a maximum of 4 channels outNumChannel = Math.min(numChannel, 4); } else { // JPG, AVI, default only supports byte data type if (dataType.getSize() > 1) outDataType = DataType.UBYTE; else outDataType = dataType; // 3 channels at max if (numChannel > 3) outNumChannel = 3; else { // special case of 2 channels if (numChannel == 2) // convert to RGB outNumChannel = 3; else outNumChannel = numChannel; } } return IcyColorModel.createInstance(outNumChannel, outDataType); }
/** * Return true if the specified writer is compatible with the image description.<br> * That means the writer is able to save the data without any loss or conversion.<br> * * @param numChannel number of channel of the image * @param alpha true if the image has an alpha channel * @param dataType image data type */ public static boolean isCompatible( IFormatWriter writer, int numChannel, boolean alpha, DataType dataType) { return isCompatible(writer, IcyColorModel.createInstance(numChannel, dataType)); }