Java Code Examples for java.awt.image.SampleModel#getNumBands()
The following examples show how to use
java.awt.image.SampleModel#getNumBands() .
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: BMPImageWriterSpi.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public boolean canEncodeImage(ImageTypeSpecifier type) { int dataType= type.getSampleModel().getDataType(); if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT) return false; SampleModel sm = type.getSampleModel(); int numBands = sm.getNumBands(); if (!(numBands == 1 || numBands == 3)) return false; if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE) return false; if (dataType > DataBuffer.TYPE_BYTE && !(sm instanceof SinglePixelPackedSampleModel)) return false; return true; }
Example 2
Source File: BMPImageWriterSpi.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public boolean canEncodeImage(ImageTypeSpecifier type) { int dataType= type.getSampleModel().getDataType(); if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT) return false; SampleModel sm = type.getSampleModel(); int numBands = sm.getNumBands(); if (!(numBands == 1 || numBands == 3)) return false; if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE) return false; if (dataType > DataBuffer.TYPE_BYTE && !(sm instanceof SinglePixelPackedSampleModel)) return false; return true; }
Example 3
Source File: ImageUtil.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static int getElementSize(SampleModel sm) { int elementSize = DataBuffer.getDataTypeSize(sm.getDataType()); if (sm instanceof MultiPixelPackedSampleModel) { MultiPixelPackedSampleModel mppsm = (MultiPixelPackedSampleModel)sm; return mppsm.getSampleSize(0) * mppsm.getNumBands(); } else if (sm instanceof ComponentSampleModel) { return sm.getNumBands() * elementSize; } else if (sm instanceof SinglePixelPackedSampleModel) { return elementSize; } return elementSize * sm.getNumBands(); }
Example 4
Source File: GIFImageWriterSpi.java From jdk8u-dev-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: BMPImageWriterSpi.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public boolean canEncodeImage(ImageTypeSpecifier type) { int dataType= type.getSampleModel().getDataType(); if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT) return false; SampleModel sm = type.getSampleModel(); int numBands = sm.getNumBands(); if (!(numBands == 1 || numBands == 3)) return false; if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE) return false; if (dataType > DataBuffer.TYPE_BYTE && !(sm instanceof SinglePixelPackedSampleModel)) return false; return true; }
Example 6
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 7
Source File: GIFImageWriterSpi.java From openjdk-jdk8u-backup 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 8
Source File: ImageUtil.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static int getElementSize(SampleModel sm) { int elementSize = DataBuffer.getDataTypeSize(sm.getDataType()); if (sm instanceof MultiPixelPackedSampleModel) { MultiPixelPackedSampleModel mppsm = (MultiPixelPackedSampleModel)sm; return mppsm.getSampleSize(0) * mppsm.getNumBands(); } else if (sm instanceof ComponentSampleModel) { return sm.getNumBands() * elementSize; } else if (sm instanceof SinglePixelPackedSampleModel) { return elementSize; } return elementSize * sm.getNumBands(); }
Example 9
Source File: J2KImageWriterSpi.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
public boolean canEncodeImage(ImageTypeSpecifier type) { SampleModel sm = type.getSampleModel(); if (sm.getNumBands() > 16384) return false; if (sm.getDataType() < DataBuffer.TYPE_BYTE || sm.getDataType() > DataBuffer.TYPE_INT) return false; return true; }
Example 10
Source File: WBMPImageWriter.java From jdk8u-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 11
Source File: PNGImageWriterSpi.java From jdk1.8-source-analysis with Apache License 2.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 12
Source File: PNGImageWriterSpi.java From TencentKona-8 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 13
Source File: WBMPImageWriter.java From openjdk-jdk8u 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 14
Source File: PNGImageWriterSpi.java From jdk8u-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 15
Source File: GIFImageWriter.java From JDKSourceCode1.8 with MIT License | 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 16
Source File: ImageUtil.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static boolean isBinary(SampleModel sm) { return sm instanceof MultiPixelPackedSampleModel && ((MultiPixelPackedSampleModel)sm).getPixelBitStride() == 1 && sm.getNumBands() == 1; }
Example 17
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 18
Source File: ImageUtil.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static boolean isBinary(SampleModel sm) { return sm instanceof MultiPixelPackedSampleModel && ((MultiPixelPackedSampleModel)sm).getPixelBitStride() == 1 && sm.getNumBands() == 1; }
Example 19
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 20
Source File: WBMPImageWriter.java From openjdk-jdk9 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")); }