Java Code Examples for javax.imageio.ImageTypeSpecifier#getColorModel()
The following examples show how to use
javax.imageio.ImageTypeSpecifier#getColorModel() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JPEG.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * 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; }
Example 2
Source File: GIFImageWriterSpi.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
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); } }
Example 3
Source File: GIFImageWriterSpi.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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); } }
Example 4
Source File: JPEGImageWriter.java From Bytecoder with Apache License 2.0 | 6 votes |
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; }
Example 5
Source File: JPEG.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * 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; }
Example 6
Source File: GIFImageWriterSpi.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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); } }
Example 7
Source File: JPEGImageWriter.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
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; }
Example 8
Source File: WebPImageWriterSpi.java From j-webp with Apache License 2.0 | 5 votes |
@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; }
Example 9
Source File: JPEGImageWriter.java From hottub with GNU General Public License v2.0 | 5 votes |
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; }
Example 10
Source File: JPEGImageWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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; }
Example 11
Source File: TIFFImageWriter.java From Bytecoder with Apache License 2.0 | 5 votes |
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(); } }
Example 12
Source File: JPEGImageWriter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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; }
Example 13
Source File: JPEG.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 14
Source File: PNGImageWriterSpi.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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; }
Example 15
Source File: GIFImageWriter.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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; }
Example 16
Source File: PNGImageWriterSpi.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
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; }
Example 17
Source File: GIFImageWriter.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
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; }
Example 18
Source File: PNGImageWriterSpi.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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; }
Example 19
Source File: GIFImageWriter.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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; }
Example 20
Source File: GIFImageWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
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; }