📄 colormodel.java
字号:
* separate spatial bands. If the <code>boolean</code> * is <code>true</code>, color samples are assumed to have been * multiplied by the alpha sample. The <code>transparency</code> * specifies what alpha values can be represented by this color model. * The transfer type is the type of primitive array used to represent * pixel values. Note that the bits array contains the number of * significant bits per color/alpha component after the translation * from pixel values. For example, for an * <code>IndexColorModel</code> with <code>pixel_bits</code> equal to * 16, the bits array might have four elements with each element set * to 8. * @param pixel_bits the number of bits in the pixel values * @param bits array that specifies the number of significant bits * per color and alpha component * @param cspace the specified <code>ColorSpace</code> * @param hasAlpha <code>true</code> if alpha information is present; * <code>false</code> otherwise * @param isAlphaPremultiplied <code>true</code> if color samples are * assumed to be premultiplied by the alpha samples; * <code>false</code> otherwise * @param transparency what alpha values can be represented by this * color model * @param transferType the type of the array used to represent pixel * values * @throws IllegalArgumentException if the length of * the bit array is less than the number of color or alpha * components in this <code>ColorModel</code>, or if the * transparency is not a valid value. * @throws IllegalArgumentException if the sum of the number * of bits in <code>bits</code> is less than 1 or if * any of the elements in <code>bits</code> is less than 0. * @see java.awt.Transparency */ protected ColorModel(int pixel_bits, int[] bits, ColorSpace cspace, boolean hasAlpha, boolean isAlphaPremultiplied, int transparency, int transferType) { colorSpace = cspace; colorSpaceType = cspace.getType(); numColorComponents = cspace.getNumComponents(); numComponents = numColorComponents + (hasAlpha ? 1 : 0); supportsAlpha = hasAlpha; if (bits.length < numComponents) { throw new IllegalArgumentException("Number of color/alpha "+ "components should be "+ numComponents+ " but length of bits array is "+ bits.length); } // 4186669 if (transparency < Transparency.OPAQUE || transparency > Transparency.TRANSLUCENT) { throw new IllegalArgumentException("Unknown transparency: "+ transparency); } if (supportsAlpha == false) { this.isAlphaPremultiplied = false; this.transparency = Transparency.OPAQUE; } else { this.isAlphaPremultiplied = isAlphaPremultiplied; this.transparency = transparency; } nBits = (int[]) bits.clone(); this.pixel_bits = pixel_bits; if (pixel_bits <= 0) { throw new IllegalArgumentException("Number of pixel bits must "+ "be > 0"); } // Check for bits < 0 maxBits = 0; for (int i=0; i < bits.length; i++) { // bug 4304697 if (bits[i] < 0) { throw new IllegalArgumentException("Number of bits must be >= 0"); } if (maxBits < bits[i]) { maxBits = bits[i]; } } // Make sure that we don't have all 0-bit components if (maxBits == 0) { throw new IllegalArgumentException("There must be at least "+ "one component with > 0 "+ "pixel bits."); } // Save this since we always need to check if it is the default CS if (cspace != ColorSpace.getInstance(ColorSpace.CS_sRGB)) { is_sRGB = false; } // Save the transfer type this.transferType = transferType; } /** * Returns whether or not alpha is supported in this * <code>ColorModel</code>. * @return <code>true</code> if alpha is supported in this * <code>ColorModel</code>; <code>false</code> otherwise. */ final public boolean hasAlpha() { return supportsAlpha; } /** * Returns whether or not the alpha has been premultiplied in the * pixel values to be translated by this <code>ColorModel</code>. * If the boolean is <code>true</code>, this <code>ColorModel</code> * is to be used to interpret pixel values in which color and alpha * information are represented as separate spatial bands, and color * samples are assumed to have been multiplied by the * alpha sample. * @return <code>true</code> if the alpha values are premultiplied * in the pixel values to be translated by this * <code>ColorModel</code>; <code>false</code> otherwise. */ final public boolean isAlphaPremultiplied() { return isAlphaPremultiplied; } /** * Returns the transfer type of this <code>ColorModel</code>. * The transfer type is the type of primitive array used to represent * pixel values as arrays. * @return the transfer type. */ final public int getTransferType() { return transferType; } /** * Returns the number of bits per pixel described by this * <code>ColorModel</code>. * @return the number of bits per pixel. */ public int getPixelSize() { return pixel_bits; } /** * Returns the number of bits for the specified color/alpha component. * Color components are indexed in the order specified by the * <code>ColorSpace</code>. Typically, this order reflects the name * of the color space type. For example, for TYPE_RGB, index 0 * corresponds to red, index 1 to green, and index 2 * to blue. If this <code>ColorModel</code> supports alpha, the alpha * component corresponds to the index following the last color * component. * @param componentIdx the index of the color/alpha component * @return the number of bits for the color/alpha component at the * specified index. * @throws ArrayIndexOutOfBoundsException if <code>componentIdx</code> * is greater than the number of components or * less than zero * @throws NullPointerException if the number of bits array is * <code>null</code> */ public int getComponentSize(int componentIdx) { // REMIND: if (nBits == null) { throw new NullPointerException("Number of bits array is null."); } return nBits[componentIdx]; } /** * Returns an array of the number of bits per color/alpha component. * The array contains the color components in the order specified by the * <code>ColorSpace</code>, followed by the alpha component, if * present. * @return an array of the number of bits per color/alpha component */ public int[] getComponentSize() { if (nBits != null) { return (int[]) nBits.clone(); } return null; } /** * Returns the transparency. Returns either OPAQUE, BITMASK, * or TRANSLUCENT. * @return the transparency of this <code>ColorModel</code>. * @see Transparency#OPAQUE * @see Transparency#BITMASK * @see Transparency#TRANSLUCENT */ public int getTransparency() { return transparency; } /** * Returns the number of components, including alpha, in this * <code>ColorModel</code>. This is equal to the number of color * components, optionally plus one, if there is an alpha component. * @return the number of components in this <code>ColorModel</code> */ public int getNumComponents() { return numComponents; } /** * Returns the number of color components in this * <code>ColorModel</code>. * This is the number of components returned by * {@link ColorSpace#getNumComponents}. * @return the number of color components in this * <code>ColorModel</code>. * @see ColorSpace#getNumComponents */ public int getNumColorComponents() { return numColorComponents; } /** * Returns the red color component for the specified pixel, scaled * from 0 to 255 in the default RGB ColorSpace, sRGB. A color conversion * is done if necessary. The pixel value is specified as an int. * An <code>IllegalArgumentException</code> is thrown if pixel * values for this <code>ColorModel</code> are not conveniently * representable as a single int. The returned value is not a * pre-multiplied value. For example, if the * alpha is premultiplied, this method divides it out before returning * the value. If the alpha value is 0, the red value is 0. * @param pixel a specified pixel * @return the value of the red component of the specified pixel. */ public abstract int getRed(int pixel); /** * Returns the green color component for the specified pixel, scaled * from 0 to 255 in the default RGB ColorSpace, sRGB. A color conversion * is done if necessary. The pixel value is specified as an int. * An <code>IllegalArgumentException</code> is thrown if pixel * values for this <code>ColorModel</code> are not conveniently * representable as a single int. The returned value is a non * pre-multiplied value. For example, if the alpha is premultiplied, * this method divides it out before returning * the value. If the alpha value is 0, the green value is 0. * @param pixel the specified pixel * @return the value of the green component of the specified pixel. */ public abstract int getGreen(int pixel); /** * Returns the blue color component for the specified pixel, scaled * from 0 to 255 in the default RGB ColorSpace, sRGB. A color conversion * is done if necessary. The pixel value is specified as an int. * An <code>IllegalArgumentException</code> is thrown if pixel values * for this <code>ColorModel</code> are not conveniently representable * as a single int. The returned value is a non pre-multiplied * value, for example, if the alpha is premultiplied, this method * divides it out before returning the value. If the alpha value is * 0, the blue value is 0. * @param pixel the specified pixel * @return the value of the blue component of the specified pixel. */ public abstract int getBlue(int pixel); /** * Returns the alpha component for the specified pixel, scaled * from 0 to 255. The pixel value is specified as an int.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -