📄 imagetypespecifier.java
字号:
boolean isAlphaPremultiplied) { if (bits != 1 && bits != 2 && bits != 4 && bits != 8 && bits != 16) throw new IllegalArgumentException ("invalid bit size"); if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_SHORT && dataType != DataBuffer.TYPE_USHORT) throw new IllegalArgumentException ("invalid data type"); if (dataType == DataBuffer.TYPE_BYTE && bits > 8) throw new IllegalArgumentException ("number of bits too large for data type"); // FIXME: this is probably wrong: return new ImageTypeSpecifier (new DirectColorModel (bits, 0xff, 0x0, 0x0, 0xff), new MultiPixelPackedSampleModel (dataType, 1, 1, bits)); } /** * Return an image type specifier for an image that uses an indexed * colour model where each colour value has the specified number of * bits and type and where the colour tables are those given. * * @param redLUT the red index values * @param greenLUT the green index values * @param blueLUT the blue index values * @param alphaLUT the alpha index values * @param bits the number of bits per index value * @param dataType the type of each index value * * @return an indexed image type specifier * * @exception IllegalArgumentException if any of the colour arrays, * not including alphaLUT, is null * @exception IllegalArgumentException if bits is not 1, 2, 4, 8 or * 16 * @exception IllegalArgumentException if dataType is not * DataBuffer.TYPE_BYTE, DataBuffer.TYPE_SHORT or * DataBuffer.TYPE_USHORT * @exception if bits is larger than the number of bits in the given * data type */ public static ImageTypeSpecifier createIndexed (byte[] redLUT, byte[] greenLUT, byte[] blueLUT, byte[] alphaLUT, int bits, int dataType) { if (redLUT == null || greenLUT == null || blueLUT == null) throw new IllegalArgumentException ("null colour table"); if (bits != 1 && bits != 2 && bits != 4 && bits != 8 && bits != 16) throw new IllegalArgumentException ("invalid bit size"); if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_SHORT && dataType != DataBuffer.TYPE_USHORT) throw new IllegalArgumentException ("invalid data type"); if (dataType == DataBuffer.TYPE_BYTE && bits > 8) throw new IllegalArgumentException ("number of bits too large for data type"); // FIXME: this is probably wrong: return new ImageTypeSpecifier (new IndexColorModel (bits, redLUT.length, redLUT, greenLUT, blueLUT, alphaLUT), new MultiPixelPackedSampleModel (dataType, 1, 1, bits)); } /** * Create an image type specifier that uses a component colour model * and a pixel interleaved sample model. Each pixel component will * be stored in a separate value of the given data type. * * @param colorSpace the colour space used by the colour model * @param bandOffsets the starting band offset for each band within * its bank * @param dataType the type of each pixel value * @param hasAlpha true if an alpha channel should be specified, * false otherwise * @param isAlphaPremultiplied true if other colour channels should * be premultiplied by the alpha value, false otherwise * * @return an interleaved image type specifier * * @exception IllegalArgumentException if either colorSpace or * bandOffsets is null * @excpetion IllegalArgumentException if the number of color space * components, including the alpha component if requested, is * different from bandOffsets.length * @exception if dataType is not a valid DataBuffer constant */ public static ImageTypeSpecifier createInterleaved (ColorSpace colorSpace, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) { if (colorSpace == null || bandOffsets == null) throw new IllegalArgumentException ("null argument"); if (bandOffsets.length != (colorSpace.getNumComponents() + (hasAlpha ? 1 : 0))) throw new IllegalArgumentException ("invalid bankOffsets length"); return new ImageTypeSpecifier (new ComponentColorModel (colorSpace, hasAlpha, isAlphaPremultiplied, hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE, dataType), new PixelInterleavedSampleModel (dataType, 1, 1, 1, 1, bandOffsets)); } /** * Create an image type specifier using a direct color model and a * packed sample model. All pixel components will be packed into * one value of the given data type. * * @param colorSpace the color space to use in the color model * @param redMask the bitmask for the red bits * @param greenMask the bitmask for the green bits * @param blueMask the bitmask for the blue bits * @param alphaMask the bitmask for the alpha bits * @param transferType the data type used to store pixel values * @param isAlphaPremultiplied true if other colour channels should * be premultiplied by the alpha value, false otherwise * * @return a packed image type specifier * * @exception IllegalArgumentException if colorSpace is null * @exception IllegalArgumentException if colorSpace does not have * type ColorSpace.TYPE_RGB * @exception IllegalArgumentException if all masks are 0 * @exception IllegalArgumentException if dataType is not * DataBuffer.TYPE_BYTE, DataBuffer.TYPE_SHORT or * DataBuffer.TYPE_INT */ public static ImageTypeSpecifier createPacked (ColorSpace colorSpace, int redMask, int greenMask, int blueMask, int alphaMask, int transferType, boolean isAlphaPremultiplied) { if (colorSpace == null) throw new IllegalArgumentException ("null color space"); if (colorSpace.getType() != ColorSpace.TYPE_RGB) throw new IllegalArgumentException ("invalid color space type"); if (redMask == 0 && greenMask == 0 && blueMask == 0 && alphaMask == 0) throw new IllegalArgumentException ("no non-zero mask"); if (transferType != DataBuffer.TYPE_BYTE && transferType != DataBuffer.TYPE_USHORT && transferType != DataBuffer.TYPE_INT) throw new IllegalArgumentException ("invalid data type"); // Assume DataBuffer.TYPE_BYTE. int numBits = 8; if (transferType == DataBuffer.TYPE_SHORT) numBits = 16; else if (transferType == DataBuffer.TYPE_INT) numBits = 32; return new ImageTypeSpecifier (new DirectColorModel (colorSpace, numBits, redMask, greenMask, blueMask, alphaMask, isAlphaPremultiplied, transferType), new MultiPixelPackedSampleModel (transferType, 1, 1, numBits)); } /** * Get the number of bits per sample in the given band. * * @param band the band from which to get the number of bits * * @return the number of bits in the given band * * @exception IllegalArgumentException if band is out-of-bounds */ public int getBitsPerBand (int band) { if (band < 0 || band > sampleModel.getNumBands()) throw new IllegalArgumentException ("band out-of-bounds"); return sampleModel.getSampleSize (band); } /** * Get the buffered image constant specified by this image type * specifier. * * @return a buffered image constant */ public int getBufferedImageType () { // FIXME: return BufferedImage.TYPE_INT_RGB; } /** * Create a sample model that is compatible with the one specified * by this image type specifier, with the given dimensions. * * @param width the width of the returned sample model * @param height the height of the returned sample model * * @return a sample model compatible with the one in this image type * specifier, with the given dimensions * * @exception IllegalArgumentException if either width or height is * less than or equal to 0 * @exception IllegalArgumentException if width * height is greater * than Intere.MAX_VALUE */ public SampleModel getSampleModel (int width, int height) { if (width <= 0 || height <= 0) throw new IllegalArgumentException ("invalid dimension"); // test for overflow if (width * height < Math.min (width, height)) throw new IllegalArgumentException ("width * height > Integer.MAX_VALUE"); return sampleModel.createCompatibleSampleModel (width, height); } /** * Get the color model specified by this image type specifier. * * @return the color model */ public ColorModel getColorModel() { return colorModel; } /** * Get the number of bands specified by this image type specifier's * sample model. * * @return the number of bands in the sample model */ public int getNumBands() { return sampleModel.getNumBands(); } /** * Get the number of components specified by this image type * specifier's color model. * * @return the number of color components per pixel */ public int getNumComponents() { return colorModel.getNumComponents(); } /** * Get the sample model specified by this image type specifier. * * @return the sample model */ public SampleModel getSampleModel() { return sampleModel; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -