Java Code Examples for java.awt.image.SampleModel#getSampleSize()
The following examples show how to use
java.awt.image.SampleModel#getSampleSize() .
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: 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 2
Source File: GIFImageWriterSpi.java From JDKSourceCode1.8 with MIT License | 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: JPEGImageWriterSpi.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public boolean canEncodeImage(ImageTypeSpecifier type) { SampleModel sampleModel = type.getSampleModel(); // 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]; } } // 4450894: Ensure bitDepth is between 1 and 8 if (bitDepth < 1 || bitDepth > 8) { return false; } return true; }
Example 4
Source File: GIFImageWriterSpi.java From jdk8u_jdk 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 5
Source File: GIFImageWriterSpi.java From jdk8u60 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 6
Source File: JPEGImageWriterSpi.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
public boolean canEncodeImage(ImageTypeSpecifier type) { SampleModel sampleModel = type.getSampleModel(); // 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]; } } // 4450894: Ensure bitDepth is between 1 and 8 if (bitDepth < 1 || bitDepth > 8) { return false; } return true; }
Example 7
Source File: GIFImageWriter.java From Bytecoder with Apache License 2.0 | 5 votes |
private boolean needToCreateIndex(RenderedImage image) { SampleModel sampleModel = image.getSampleModel(); ColorModel colorModel = image.getColorModel(); return sampleModel.getNumBands() != 1 || sampleModel.getSampleSize()[0] > 8 || colorModel.getComponentSize()[0] > 8; }
Example 8
Source File: GIFImageWriter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private boolean needToCreateIndex(RenderedImage image) { SampleModel sampleModel = image.getSampleModel(); ColorModel colorModel = image.getColorModel(); return sampleModel.getNumBands() != 1 || sampleModel.getSampleSize()[0] > 8 || colorModel.getComponentSize()[0] > 8; }
Example 9
Source File: GIFImageWriter.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private boolean needToCreateIndex(RenderedImage image) { SampleModel sampleModel = image.getSampleModel(); ColorModel colorModel = image.getColorModel(); return sampleModel.getNumBands() != 1 || sampleModel.getSampleSize()[0] > 8 || colorModel.getComponentSize()[0] > 8; }
Example 10
Source File: GIFImageWriter.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private boolean needToCreateIndex(RenderedImage image) { SampleModel sampleModel = image.getSampleModel(); ColorModel colorModel = image.getColorModel(); return sampleModel.getNumBands() != 1 || sampleModel.getSampleSize()[0] > 8 || colorModel.getComponentSize()[0] > 8; }
Example 11
Source File: WBMPImageWriterSpi.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public boolean canEncodeImage(ImageTypeSpecifier type) { SampleModel sm = type.getSampleModel(); if (!(sm instanceof MultiPixelPackedSampleModel)) return false; if (sm.getSampleSize(0) != 1) return false; return true; }
Example 12
Source File: WBMPImageWriterSpi.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public boolean canEncodeImage(ImageTypeSpecifier type) { SampleModel sm = type.getSampleModel(); if (!(sm instanceof MultiPixelPackedSampleModel)) return false; if (sm.getSampleSize(0) != 1) return false; return true; }
Example 13
Source File: GIFImageWriter.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * Create a color table from the image ColorModel and SampleModel. */ private static byte[] createColorTable(ColorModel colorModel, SampleModel sampleModel) { byte[] colorTable; if (colorModel instanceof IndexColorModel) { IndexColorModel icm = (IndexColorModel)colorModel; int mapSize = icm.getMapSize(); /** * The GIF image format assumes that size of image palette * is power of two. We will use closest larger power of two * as size of color table. */ int ctSize = getGifPaletteSize(mapSize); byte[] reds = new byte[ctSize]; byte[] greens = new byte[ctSize]; byte[] blues = new byte[ctSize]; icm.getReds(reds); icm.getGreens(greens); icm.getBlues(blues); /** * fill tail of color component arrays by replica of first color * in order to avoid appearance of extra colors in the color table */ for (int i = mapSize; i < ctSize; i++) { reds[i] = reds[0]; greens[i] = greens[0]; blues[i] = blues[0]; } colorTable = new byte[3*ctSize]; int idx = 0; for (int i = 0; i < ctSize; i++) { colorTable[idx++] = reds[i]; colorTable[idx++] = greens[i]; colorTable[idx++] = blues[i]; } } else if (sampleModel.getNumBands() == 1) { // create gray-scaled color table for single-banded images int numBits = sampleModel.getSampleSize()[0]; if (numBits > 8) { numBits = 8; } int colorTableLength = 3*(1 << numBits); colorTable = new byte[colorTableLength]; for (int i = 0; i < colorTableLength; i++) { colorTable[i] = (byte)(i/3); } } else { // We do not have enough information here // to create well-fit color table for RGB image. colorTable = null; } return colorTable; }
Example 14
Source File: WBMPImageWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private void checkSampleModel(SampleModel sm) { int type = sm.getDataType(); if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT || sm.getNumBands() != 1 || sm.getSampleSize(0) != 1) throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2")); }
Example 15
Source File: PNGImageWriterSpi.java From openjdk-8-source 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 16
Source File: WBMPImageWriter.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
private void checkSampleModel(SampleModel sm) { int type = sm.getDataType(); if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT || sm.getNumBands() != 1 || sm.getSampleSize(0) != 1) throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2")); }
Example 17
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 18
Source File: GIFImageWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Create a color table from the image ColorModel and SampleModel. */ private static byte[] createColorTable(ColorModel colorModel, SampleModel sampleModel) { byte[] colorTable; if (colorModel instanceof IndexColorModel) { IndexColorModel icm = (IndexColorModel)colorModel; int mapSize = icm.getMapSize(); /** * The GIF image format assumes that size of image palette * is power of two. We will use closest larger power of two * as size of color table. */ int ctSize = getGifPaletteSize(mapSize); byte[] reds = new byte[ctSize]; byte[] greens = new byte[ctSize]; byte[] blues = new byte[ctSize]; icm.getReds(reds); icm.getGreens(greens); icm.getBlues(blues); /** * fill tail of color component arrays by replica of first color * in order to avoid appearance of extra colors in the color table */ for (int i = mapSize; i < ctSize; i++) { reds[i] = reds[0]; greens[i] = greens[0]; blues[i] = blues[0]; } colorTable = new byte[3*ctSize]; int idx = 0; for (int i = 0; i < ctSize; i++) { colorTable[idx++] = reds[i]; colorTable[idx++] = greens[i]; colorTable[idx++] = blues[i]; } } else if (sampleModel.getNumBands() == 1) { // create gray-scaled color table for single-banded images int numBits = sampleModel.getSampleSize()[0]; if (numBits > 8) { numBits = 8; } int colorTableLength = 3*(1 << numBits); colorTable = new byte[colorTableLength]; for (int i = 0; i < colorTableLength; i++) { colorTable[i] = (byte)(i/3); } } else { // We do not have enough information here // to create well-fit color table for RGB image. colorTable = null; } return colorTable; }
Example 19
Source File: WBMPImageWriter.java From JDKSourceCode1.8 with MIT License | 4 votes |
private void checkSampleModel(SampleModel sm) { int type = sm.getDataType(); if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT || sm.getNumBands() != 1 || sm.getSampleSize(0) != 1) throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2")); }
Example 20
Source File: GIFImageWriter.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Create a color table from the image ColorModel and SampleModel. */ private static byte[] createColorTable(ColorModel colorModel, SampleModel sampleModel) { byte[] colorTable; if (colorModel instanceof IndexColorModel) { IndexColorModel icm = (IndexColorModel)colorModel; int mapSize = icm.getMapSize(); /** * The GIF image format assumes that size of image palette * is power of two. We will use closest larger power of two * as size of color table. */ int ctSize = getGifPaletteSize(mapSize); byte[] reds = new byte[ctSize]; byte[] greens = new byte[ctSize]; byte[] blues = new byte[ctSize]; icm.getReds(reds); icm.getGreens(greens); icm.getBlues(blues); /** * fill tail of color component arrays by replica of first color * in order to avoid appearance of extra colors in the color table */ for (int i = mapSize; i < ctSize; i++) { reds[i] = reds[0]; greens[i] = greens[0]; blues[i] = blues[0]; } colorTable = new byte[3*ctSize]; int idx = 0; for (int i = 0; i < ctSize; i++) { colorTable[idx++] = reds[i]; colorTable[idx++] = greens[i]; colorTable[idx++] = blues[i]; } } else if (sampleModel.getNumBands() == 1) { // create gray-scaled color table for single-banded images int numBits = sampleModel.getSampleSize()[0]; if (numBits > 8) { numBits = 8; } int colorTableLength = 3*(1 << numBits); colorTable = new byte[colorTableLength]; for (int i = 0; i < colorTableLength; i++) { colorTable[i] = (byte)(i/3); } } else { // We do not have enough information here // to create well-fit color table for RGB image. colorTable = null; } return colorTable; }