Beispiel #1
0
  /**
   * 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);
  }
Beispiel #2
0
 /** Return the separate channel flag from specified writer and color space */
 private static boolean getSeparateChannelFlag(IFormatWriter writer, IcyColorModel colorModel) {
   return getSeparateChannelFlag(writer, colorModel.getNumComponents(), colorModel.getDataType_());
 }
Beispiel #3
0
 /**
  * Return true if the specified writer is compatible with the specified {@link IcyColorModel}.
  * <br>
  * That means the writer is able to save the data described by the colorModel without any loss or
  * conversion.<br>
  * The color map data are never preserved, they are always restored to their default.<br>
  */
 public static boolean isCompatible(IFormatWriter writer, IcyColorModel colorModel) {
   return colorModel.isCompatible(getCompatibleColorModel(writer, colorModel));
 }
Beispiel #4
0
 /**
  * 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));
 }
Beispiel #5
0
 /**
  * Return the closest compatible {@link IcyColorModel} supported by writer from the specified
  * {@link IcyColorModel}.<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 colorModel the colorModel describing data / image format
  */
 public static IcyColorModel getCompatibleColorModel(
     IFormatWriter writer, IcyColorModel colorModel) {
   return getCompatibleColorModel(
       writer, colorModel.getNumComponents(), colorModel.getDataType_());
 }