javax.imageio.ImageTypeSpecifier#getColorModel ( )源码实例Demo

下面列出了javax.imageio.ImageTypeSpecifier#getColorModel ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk1.8-source-analysis   文件: JPEG.java
/**
 * Given an image type, return the Adobe transform corresponding to
 * that type, or ADOBE_IMPOSSIBLE if the image type is incompatible
 * with an Adobe marker segment.  If <code>input</code> is true, then
 * the image type is considered before colorspace conversion.
 */
static int transformForType(ImageTypeSpecifier imageType, boolean input) {
    int retval = ADOBE_IMPOSSIBLE;
    ColorModel cm = imageType.getColorModel();
    switch (cm.getColorSpace().getType()) {
    case ColorSpace.TYPE_GRAY:
        retval = ADOBE_UNKNOWN;
        break;
    case ColorSpace.TYPE_RGB:
        retval = input ? ADOBE_YCC : ADOBE_UNKNOWN;
        break;
    case ColorSpace.TYPE_YCbCr:
        retval = ADOBE_YCC;
        break;
    case ColorSpace.TYPE_CMYK:
        retval = input ? ADOBE_YCCK : ADOBE_IMPOSSIBLE;
    }
    return retval;
}
 
public boolean canEncodeImage(ImageTypeSpecifier type) {
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }

    SampleModel sm = type.getSampleModel();
    ColorModel cm = type.getColorModel();

    boolean canEncode = sm.getNumBands() == 1 &&
        sm.getSampleSize(0) <= 8 &&
        sm.getWidth() <= 65535 &&
        sm.getHeight() <= 65535 &&
        (cm == null || cm.getComponentSize()[0] <= 8);

    if (canEncode) {
        return true;
    } else {
        return PaletteBuilder.canCreatePalette(type);
    }
}
 
源代码3 项目: openjdk-8-source   文件: GIFImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }

    SampleModel sm = type.getSampleModel();
    ColorModel cm = type.getColorModel();

    boolean canEncode = sm.getNumBands() == 1 &&
        sm.getSampleSize(0) <= 8 &&
        sm.getWidth() <= 65535 &&
        sm.getHeight() <= 65535 &&
        (cm == null || cm.getComponentSize()[0] <= 8);

    if (canEncode) {
        return true;
    } else {
        return PaletteBuilder.canCreatePalette(type);
    }
}
 
源代码4 项目: Bytecoder   文件: JPEGImageWriter.java
private int getDestCSType(ImageTypeSpecifier destType) {
ColorModel cm = destType.getColorModel();
boolean alpha = cm.hasAlpha();
ColorSpace cs = cm.getColorSpace();
int retval = JPEG.JCS_UNKNOWN;
switch (cs.getType()) {
case ColorSpace.TYPE_GRAY:
        retval = JPEG.JCS_GRAYSCALE;
        break;
    case ColorSpace.TYPE_RGB:
        retval = JPEG.JCS_RGB;
        break;
    case ColorSpace.TYPE_YCbCr:
        retval = JPEG.JCS_YCbCr;
        break;
    case ColorSpace.TYPE_CMYK:
        retval = JPEG.JCS_CMYK;
        break;
    }
return retval;
}
 
源代码5 项目: Bytecoder   文件: JPEG.java
/**
 * Given an image type, return the Adobe transform corresponding to
 * that type, or ADOBE_IMPOSSIBLE if the image type is incompatible
 * with an Adobe marker segment.  If {@code input} is true, then
 * the image type is considered before colorspace conversion.
 */
static int transformForType(ImageTypeSpecifier imageType, boolean input) {
    int retval = ADOBE_IMPOSSIBLE;
    ColorModel cm = imageType.getColorModel();
    switch (cm.getColorSpace().getType()) {
    case ColorSpace.TYPE_GRAY:
        retval = ADOBE_UNKNOWN;
        break;
    case ColorSpace.TYPE_RGB:
        retval = input ? ADOBE_YCC : ADOBE_UNKNOWN;
        break;
    case ColorSpace.TYPE_YCbCr:
        retval = ADOBE_YCC;
        break;
    case ColorSpace.TYPE_CMYK:
        retval = input ? ADOBE_YCCK : ADOBE_IMPOSSIBLE;
    }
    return retval;
}
 
源代码6 项目: openjdk-jdk9   文件: GIFImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }

    SampleModel sm = type.getSampleModel();
    ColorModel cm = type.getColorModel();

    boolean canEncode = sm.getNumBands() == 1 &&
        sm.getSampleSize(0) <= 8 &&
        sm.getWidth() <= 65535 &&
        sm.getHeight() <= 65535 &&
        (cm == null || cm.getComponentSize()[0] <= 8);

    if (canEncode) {
        return true;
    } else {
        return PaletteBuilder.canCreatePalette(type);
    }
}
 
源代码7 项目: hottub   文件: JPEGImageWriter.java
private int getDestCSType(ImageTypeSpecifier destType) {
ColorModel cm = destType.getColorModel();
boolean alpha = cm.hasAlpha();
ColorSpace cs = cm.getColorSpace();
int retval = JPEG.JCS_UNKNOWN;
switch (cs.getType()) {
case ColorSpace.TYPE_GRAY:
        retval = JPEG.JCS_GRAYSCALE;
        break;
    case ColorSpace.TYPE_RGB:
        if (alpha) {
            retval = JPEG.JCS_RGBA;
        } else {
            retval = JPEG.JCS_RGB;
        }
        break;
    case ColorSpace.TYPE_YCbCr:
        if (alpha) {
            retval = JPEG.JCS_YCbCrA;
        } else {
            retval = JPEG.JCS_YCbCr;
        }
        break;
    case ColorSpace.TYPE_3CLR:
        if (cs == JPEG.JCS.getYCC()) {
            if (alpha) {
                retval = JPEG.JCS_YCCA;
            } else {
                retval = JPEG.JCS_YCC;
            }
        }
    case ColorSpace.TYPE_CMYK:
        retval = JPEG.JCS_CMYK;
        break;
    }
return retval;
}
 
源代码8 项目: jdk1.8-source-analysis   文件: JPEGImageWriter.java
private int getDestCSType(ImageTypeSpecifier destType) {
ColorModel cm = destType.getColorModel();
boolean alpha = cm.hasAlpha();
ColorSpace cs = cm.getColorSpace();
int retval = JPEG.JCS_UNKNOWN;
switch (cs.getType()) {
case ColorSpace.TYPE_GRAY:
        retval = JPEG.JCS_GRAYSCALE;
        break;
    case ColorSpace.TYPE_RGB:
        if (alpha) {
            retval = JPEG.JCS_RGBA;
        } else {
            retval = JPEG.JCS_RGB;
        }
        break;
    case ColorSpace.TYPE_YCbCr:
        if (alpha) {
            retval = JPEG.JCS_YCbCrA;
        } else {
            retval = JPEG.JCS_YCbCr;
        }
        break;
    case ColorSpace.TYPE_3CLR:
        if (cs == JPEG.JCS.getYCC()) {
            if (alpha) {
                retval = JPEG.JCS_YCCA;
            } else {
                retval = JPEG.JCS_YCC;
            }
        }
    case ColorSpace.TYPE_CMYK:
        retval = JPEG.JCS_CMYK;
        break;
    }
return retval;
}
 
源代码9 项目: j-webp   文件: WebPImageWriterSpi.java
@Override
public boolean canEncodeImage( ImageTypeSpecifier type ) {
  ColorModel colorModel = type.getColorModel();
  SampleModel sampleModel = type.getSampleModel();
  int transferType = sampleModel.getTransferType();

  if ( colorModel instanceof ComponentColorModel ) {
    if ( !( sampleModel instanceof ComponentSampleModel ) ) {
      return false;
    }

    if ( transferType != DataBuffer.TYPE_BYTE && transferType != DataBuffer.TYPE_INT ) {
      return false;
    }
  }
  else if ( colorModel instanceof DirectColorModel ) {
    if ( !( sampleModel instanceof SinglePixelPackedSampleModel ) ) {
      return false;
    }

    if ( transferType != DataBuffer.TYPE_INT ) {
      return false;
    }
  }

  ColorSpace colorSpace = colorModel.getColorSpace();
  if ( !( colorSpace.isCS_sRGB() ) ) {
    return false;
  }

  int[] sampleSize = sampleModel.getSampleSize();
  for ( int i = 0; i < sampleSize.length; i++ ) {
    if ( sampleSize[ i ] > 8 ) {
      return false;
    }
  }


  return true;
}
 
源代码10 项目: openjdk-jdk9   文件: JPEGImageWriter.java
private int getDestCSType(ImageTypeSpecifier destType) {
ColorModel cm = destType.getColorModel();
boolean alpha = cm.hasAlpha();
ColorSpace cs = cm.getColorSpace();
int retval = JPEG.JCS_UNKNOWN;
switch (cs.getType()) {
case ColorSpace.TYPE_GRAY:
        retval = JPEG.JCS_GRAYSCALE;
        break;
    case ColorSpace.TYPE_RGB:
        if (alpha) {
            retval = JPEG.JCS_RGBA;
        } else {
            retval = JPEG.JCS_RGB;
        }
        break;
    case ColorSpace.TYPE_YCbCr:
        if (alpha) {
            retval = JPEG.JCS_YCbCrA;
        } else {
            retval = JPEG.JCS_YCbCr;
        }
        break;
    case ColorSpace.TYPE_3CLR:
        if (cs == JPEG.JCS.getYCC()) {
            if (alpha) {
                retval = JPEG.JCS_YCCA;
            } else {
                retval = JPEG.JCS_YCC;
            }
        }
        break;
    case ColorSpace.TYPE_CMYK:
        retval = JPEG.JCS_CMYK;
        break;
    }
return retval;
}
 
源代码11 项目: hottub   文件: JPEG.java
/**
 * Returns <code>true</code> if the given imageType can be used
 * in a JFIF file.  If <code>input</code> is true, then the
 * image type is considered before colorspace conversion.
 */
static boolean isJFIFcompliant(ImageTypeSpecifier imageType,
                               boolean input) {
    ColorModel cm = imageType.getColorModel();
    // Can't have alpha
    if (cm.hasAlpha()) {
        return false;
    }
    // Gray is OK, always
    int numComponents = imageType.getNumComponents();
    if (numComponents == 1) {
        return true;
    }

    // If it isn't gray, it must have 3 channels
    if (numComponents != 3) {
        return false;
    }

    if (input) {
        // Must be RGB
        if (cm.getColorSpace().getType() == ColorSpace.TYPE_RGB) {
            return true;
        }
    } else {
        // Must be YCbCr
        if (cm.getColorSpace().getType() == ColorSpace.TYPE_YCbCr) {
            return true;
        }
    }

    return false;
}
 
源代码12 项目: openjdk-8-source   文件: JPEGImageWriter.java
private int getDestCSType(ImageTypeSpecifier destType) {
ColorModel cm = destType.getColorModel();
boolean alpha = cm.hasAlpha();
ColorSpace cs = cm.getColorSpace();
int retval = JPEG.JCS_UNKNOWN;
switch (cs.getType()) {
case ColorSpace.TYPE_GRAY:
        retval = JPEG.JCS_GRAYSCALE;
        break;
    case ColorSpace.TYPE_RGB:
        if (alpha) {
            retval = JPEG.JCS_RGBA;
        } else {
            retval = JPEG.JCS_RGB;
        }
        break;
    case ColorSpace.TYPE_YCbCr:
        if (alpha) {
            retval = JPEG.JCS_YCbCrA;
        } else {
            retval = JPEG.JCS_YCbCr;
        }
        break;
    case ColorSpace.TYPE_3CLR:
        if (cs == JPEG.JCS.getYCC()) {
            if (alpha) {
                retval = JPEG.JCS_YCCA;
            } else {
                retval = JPEG.JCS_YCC;
            }
        }
    case ColorSpace.TYPE_CMYK:
        retval = JPEG.JCS_CMYK;
        break;
    }
return retval;
}
 
源代码13 项目: Bytecoder   文件: TIFFImageWriter.java
public void prepareWriteEmpty(IIOMetadata streamMetadata,
                              ImageTypeSpecifier imageType,
                              int width,
                              int height,
                              IIOMetadata imageMetadata,
                              List<? extends BufferedImage> thumbnails,
                              ImageWriteParam param) throws IOException {
    if (stream == null) {
        throw new IllegalStateException("output == null!");
    }

    checkParamsEmpty(imageType, width, height, thumbnails);

    this.isWritingEmpty = true;

    SampleModel emptySM = imageType.getSampleModel();
    RenderedImage emptyImage =
        new EmptyImage(0, 0, width, height,
                       0, 0, emptySM.getWidth(), emptySM.getHeight(),
                       emptySM, imageType.getColorModel());

    markPositions();
    write(streamMetadata, new IIOImage(emptyImage, null, imageMetadata),
          param, true, false);
    if (abortRequested()) {
        resetPositions();
    }
}
 
源代码14 项目: openjdk-jdk8u-backup   文件: GIFImageWriter.java
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    GIFWritableImageMetadata imageMetadata =
        new GIFWritableImageMetadata();

    // Image dimensions

    SampleModel sampleModel = imageType.getSampleModel();

    Rectangle sourceBounds = new Rectangle(sampleModel.getWidth(),
                                           sampleModel.getHeight());
    Dimension destSize = new Dimension();
    computeRegions(sourceBounds, destSize, param);

    imageMetadata.imageWidth = destSize.width;
    imageMetadata.imageHeight = destSize.height;

    // Interlacing

    if (param != null && param.canWriteProgressive() &&
        param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) {
        imageMetadata.interlaceFlag = false;
    } else {
        imageMetadata.interlaceFlag = true;
    }

    // Local color table

    ColorModel colorModel = imageType.getColorModel();

    imageMetadata.localColorTable =
        createColorTable(colorModel, sampleModel);

    // Transparency

    if (colorModel instanceof IndexColorModel) {
        int transparentIndex =
            ((IndexColorModel)colorModel).getTransparentPixel();
        if (transparentIndex != -1) {
            imageMetadata.transparentColorFlag = true;
            imageMetadata.transparentColorIndex = transparentIndex;
        }
    }

    return imageMetadata;
}
 
源代码15 项目: dragonwell8_jdk   文件: GIFImageWriter.java
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    GIFWritableImageMetadata imageMetadata =
        new GIFWritableImageMetadata();

    // Image dimensions

    SampleModel sampleModel = imageType.getSampleModel();

    Rectangle sourceBounds = new Rectangle(sampleModel.getWidth(),
                                           sampleModel.getHeight());
    Dimension destSize = new Dimension();
    computeRegions(sourceBounds, destSize, param);

    imageMetadata.imageWidth = destSize.width;
    imageMetadata.imageHeight = destSize.height;

    // Interlacing

    if (param != null && param.canWriteProgressive() &&
        param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) {
        imageMetadata.interlaceFlag = false;
    } else {
        imageMetadata.interlaceFlag = true;
    }

    // Local color table

    ColorModel colorModel = imageType.getColorModel();

    imageMetadata.localColorTable =
        createColorTable(colorModel, sampleModel);

    // Transparency

    if (colorModel instanceof IndexColorModel) {
        int transparentIndex =
            ((IndexColorModel)colorModel).getTransparentPixel();
        if (transparentIndex != -1) {
            imageMetadata.transparentColorFlag = true;
            imageMetadata.transparentColorIndex = transparentIndex;
        }
    }

    return imageMetadata;
}
 
源代码16 项目: dragonwell8_jdk   文件: PNGImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    SampleModel sampleModel = type.getSampleModel();
    ColorModel colorModel = type.getColorModel();

    // Find the maximum bit depth across all channels
    int[] sampleSize = sampleModel.getSampleSize();
    int bitDepth = sampleSize[0];
    for (int i = 1; i < sampleSize.length; i++) {
        if (sampleSize[i] > bitDepth) {
            bitDepth = sampleSize[i];
        }
    }

    // Ensure bitDepth is between 1 and 16
    if (bitDepth < 1 || bitDepth > 16) {
        return false;
    }

    // Check number of bands, alpha
    int numBands = sampleModel.getNumBands();
    if (numBands < 1 || numBands > 4) {
        return false;
    }

    boolean hasAlpha = colorModel.hasAlpha();
    // Fix 4464413: PNGTransparency reg-test was failing
    // because for IndexColorModels that have alpha,
    // numBands == 1 && hasAlpha == true, thus causing
    // the check below to fail and return false.
    if (colorModel instanceof IndexColorModel) {
        return true;
    }
    if ((numBands == 1 || numBands == 3) && hasAlpha) {
        return false;
    }
    if ((numBands == 2 || numBands == 4) && !hasAlpha) {
        return false;
    }

    return true;
}
 
源代码17 项目: jdk8u_jdk   文件: GIFImageWriter.java
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    GIFWritableImageMetadata imageMetadata =
        new GIFWritableImageMetadata();

    // Image dimensions

    SampleModel sampleModel = imageType.getSampleModel();

    Rectangle sourceBounds = new Rectangle(sampleModel.getWidth(),
                                           sampleModel.getHeight());
    Dimension destSize = new Dimension();
    computeRegions(sourceBounds, destSize, param);

    imageMetadata.imageWidth = destSize.width;
    imageMetadata.imageHeight = destSize.height;

    // Interlacing

    if (param != null && param.canWriteProgressive() &&
        param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) {
        imageMetadata.interlaceFlag = false;
    } else {
        imageMetadata.interlaceFlag = true;
    }

    // Local color table

    ColorModel colorModel = imageType.getColorModel();

    imageMetadata.localColorTable =
        createColorTable(colorModel, sampleModel);

    // Transparency

    if (colorModel instanceof IndexColorModel) {
        int transparentIndex =
            ((IndexColorModel)colorModel).getTransparentPixel();
        if (transparentIndex != -1) {
            imageMetadata.transparentColorFlag = true;
            imageMetadata.transparentColorIndex = transparentIndex;
        }
    }

    return imageMetadata;
}
 
源代码18 项目: jdk8u60   文件: PNGImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    SampleModel sampleModel = type.getSampleModel();
    ColorModel colorModel = type.getColorModel();

    // Find the maximum bit depth across all channels
    int[] sampleSize = sampleModel.getSampleSize();
    int bitDepth = sampleSize[0];
    for (int i = 1; i < sampleSize.length; i++) {
        if (sampleSize[i] > bitDepth) {
            bitDepth = sampleSize[i];
        }
    }

    // Ensure bitDepth is between 1 and 16
    if (bitDepth < 1 || bitDepth > 16) {
        return false;
    }

    // Check number of bands, alpha
    int numBands = sampleModel.getNumBands();
    if (numBands < 1 || numBands > 4) {
        return false;
    }

    boolean hasAlpha = colorModel.hasAlpha();
    // Fix 4464413: PNGTransparency reg-test was failing
    // because for IndexColorModels that have alpha,
    // numBands == 1 && hasAlpha == true, thus causing
    // the check below to fail and return false.
    if (colorModel instanceof IndexColorModel) {
        return true;
    }
    if ((numBands == 1 || numBands == 3) && hasAlpha) {
        return false;
    }
    if ((numBands == 2 || numBands == 4) && !hasAlpha) {
        return false;
    }

    return true;
}
 
源代码19 项目: openjdk-jdk8u   文件: GIFImageWriter.java
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    GIFWritableImageMetadata imageMetadata =
        new GIFWritableImageMetadata();

    // Image dimensions

    SampleModel sampleModel = imageType.getSampleModel();

    Rectangle sourceBounds = new Rectangle(sampleModel.getWidth(),
                                           sampleModel.getHeight());
    Dimension destSize = new Dimension();
    computeRegions(sourceBounds, destSize, param);

    imageMetadata.imageWidth = destSize.width;
    imageMetadata.imageHeight = destSize.height;

    // Interlacing

    if (param != null && param.canWriteProgressive() &&
        param.getProgressiveMode() == ImageWriteParam.MODE_DISABLED) {
        imageMetadata.interlaceFlag = false;
    } else {
        imageMetadata.interlaceFlag = true;
    }

    // Local color table

    ColorModel colorModel = imageType.getColorModel();

    imageMetadata.localColorTable =
        createColorTable(colorModel, sampleModel);

    // Transparency

    if (colorModel instanceof IndexColorModel) {
        int transparentIndex =
            ((IndexColorModel)colorModel).getTransparentPixel();
        if (transparentIndex != -1) {
            imageMetadata.transparentColorFlag = true;
            imageMetadata.transparentColorIndex = transparentIndex;
        }
    }

    return imageMetadata;
}
 
源代码20 项目: openjdk-jdk9   文件: PNGImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    SampleModel sampleModel = type.getSampleModel();
    ColorModel colorModel = type.getColorModel();

    // Find the maximum bit depth across all channels
    int[] sampleSize = sampleModel.getSampleSize();
    int bitDepth = sampleSize[0];
    for (int i = 1; i < sampleSize.length; i++) {
        if (sampleSize[i] > bitDepth) {
            bitDepth = sampleSize[i];
        }
    }

    // Ensure bitDepth is between 1 and 16
    if (bitDepth < 1 || bitDepth > 16) {
        return false;
    }

    // Check number of bands, alpha
    int numBands = sampleModel.getNumBands();
    if (numBands < 1 || numBands > 4) {
        return false;
    }

    boolean hasAlpha = colorModel.hasAlpha();
    // Fix 4464413: PNGTransparency reg-test was failing
    // because for IndexColorModels that have alpha,
    // numBands == 1 && hasAlpha == true, thus causing
    // the check below to fail and return false.
    if (colorModel instanceof IndexColorModel) {
        return true;
    }
    if ((numBands == 1 || numBands == 3) && hasAlpha) {
        return false;
    }
    if ((numBands == 2 || numBands == 4) && !hasAlpha) {
        return false;
    }

    return true;
}