📄 colormodel.java
字号:
* An <code>IllegalArgumentException</code> is thrown if pixel * values for this <code>ColorModel</code> are not conveniently * representable as a single int. * @param pixel the specified pixel * @return the value of alpha component of the specified pixel. */ public abstract int getAlpha(int pixel); /** * Returns the color/alpha components of the pixel in the default * RGB color model format. A color conversion is done if necessary. * The pixel value is specified as an int. * An <code>IllegalArgumentException</code> thrown if pixel values * for this <code>ColorModel</code> are not conveniently representable * as a single int. The returned value is in a non * pre-multiplied format. For example, if the alpha is premultiplied, * this method divides it out of the color components. If the alpha * value is 0, the color values are 0. * @param pixel the specified pixel * @return the RGB value of the color/alpha components of the * specified pixel. * @see ColorModel#getRGBdefault */ public int getRGB(int pixel) { return (getAlpha(pixel) << 24) | (getRed(pixel) << 16) | (getGreen(pixel) << 8) | (getBlue(pixel) << 0); } /** * Returns the red color component for the specified pixel, scaled * from 0 to 255 in the default RGB <code>ColorSpace</code>, sRGB. A * color conversion is done if necessary. The pixel value is * specified by an array of data elements of type transferType passed * in as an object reference. The returned value is a non * pre-multiplied value. For example, if alpha is premultiplied, * this method divides it out before returning * the value. If the alpha value is 0, the red value is 0. * If <code>inData</code> is not a primitive array of type * transferType, a <code>ClassCastException</code> is thrown. An * <code>ArrayIndexOutOfBoundsException</code> is thrown if * <code>inData</code> is not large enough to hold a pixel value for * this <code>ColorModel</code>. * If this <code>transferType</code> is not supported, a * <code>UnsupportedOperationException</code> will be * thrown. Since * <code>ColorModel</code> is an abstract class, any instance * must be an instance of a subclass. Subclasses inherit the * implementation of this method and if they don't override it, this * method throws an exception if the subclass uses a * <code>transferType</code> other than * <code>DataBuffer.TYPE_BYTE</code>, * <code>DataBuffer.TYPE_USHORT</code>, or * <code>DataBuffer.TYPE_INT</code>. * @param inData an array of pixel values * @return the value of the red component of the specified pixel. * @throws ClassCastException if <code>inData</code> * is not a primitive array of type <code>transferType</code> * @throws ArrayIndexOutOfBoundsException if * <code>inData</code> is not large enough to hold a pixel value * for this <code>ColorModel</code> * @throws UnsupportedOperationException if this * <code>tranferType</code> is not supported by this * <code>ColorModel</code> */ public int getRed(Object inData) { int pixel=0,length=0; switch (transferType) { case DataBuffer.TYPE_BYTE: byte bdata[] = (byte[])inData; pixel = bdata[0] & 0xff; length = bdata.length; break; case DataBuffer.TYPE_USHORT: short sdata[] = (short[])inData; pixel = sdata[0] & 0xffff; length = sdata.length; break; case DataBuffer.TYPE_INT: int idata[] = (int[])inData; pixel = idata[0]; length = idata.length; break; default: throw new UnsupportedOperationException("This method has not been "+ "implemented for transferType " + transferType); } if (length == 1) { return getRed(pixel); } else { throw new UnsupportedOperationException ("This method is not supported by this color model"); } } /** * Returns the green color component for the specified pixel, scaled * from 0 to 255 in the default RGB <code>ColorSpace</code>, sRGB. A * color conversion is done if necessary. The pixel value is * specified by an array of data elements of type transferType passed * in as an object reference. The returned value will be 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. If <code>inData</code> is * not a primitive array of type transferType, a * <code>ClassCastException</code> is thrown. An * <code>ArrayIndexOutOfBoundsException</code> is thrown if * <code>inData</code> is not large enough to hold a pixel value for * this <code>ColorModel</code>. * If this <code>transferType</code> is not supported, a * <code>UnsupportedOperationException</code> will be * thrown. Since * <code>ColorModel</code> is an abstract class, any instance * must be an instance of a subclass. Subclasses inherit the * implementation of this method and if they don't override it, this * method throws an exception if the subclass uses a * <code>transferType</code> other than * <code>DataBuffer.TYPE_BYTE</code>, * <code>DataBuffer.TYPE_USHORT</code>, or * <code>DataBuffer.TYPE_INT</code>. * @param inData an array of pixel values * @return the value of the green component of the specified pixel. * @throws <code>ClassCastException</code> if <code>inData</code> * is not a primitive array of type <code>transferType</code> * @throws <code>ArrayIndexOutOfBoundsException</code> if * <code>inData</code> is not large enough to hold a pixel value * for this <code>ColorModel</code> * @throws <code>UnsupportedOperationException</code> if this * <code>tranferType</code> is not supported by this * <code>ColorModel</code> */ public int getGreen(Object inData) { int pixel=0,length=0; switch (transferType) { case DataBuffer.TYPE_BYTE: byte bdata[] = (byte[])inData; pixel = bdata[0] & 0xff; length = bdata.length; break; case DataBuffer.TYPE_USHORT: short sdata[] = (short[])inData; pixel = sdata[0] & 0xffff; length = sdata.length; break; case DataBuffer.TYPE_INT: int idata[] = (int[])inData; pixel = idata[0]; length = idata.length; break; default: throw new UnsupportedOperationException("This method has not been "+ "implemented for transferType " + transferType); } if (length == 1) { return getGreen(pixel); } else { throw new UnsupportedOperationException ("This method is not supported by this color model"); } } /** * Returns the blue color component for the specified pixel, scaled * from 0 to 255 in the default RGB <code>ColorSpace</code>, sRGB. A * color conversion is done if necessary. The pixel value is * specified by an array of data elements of type transferType passed * in as an object reference. 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 will be 0. If * <code>inData</code> is not a primitive array of type transferType, * a <code>ClassCastException</code> is thrown. An * <code>ArrayIndexOutOfBoundsException</code> is * thrown if <code>inData</code> is not large enough to hold a pixel * value for this <code>ColorModel</code>. * If this <code>transferType</code> is not supported, a * <code>UnsupportedOperationException</code> will be * thrown. Since * <code>ColorModel</code> is an abstract class, any instance * must be an instance of a subclass. Subclasses inherit the * implementation of this method and if they don't override it, this * method throws an exception if the subclass uses a * <code>transferType</code> other than * <code>DataBuffer.TYPE_BYTE</code>, * <code>DataBuffer.TYPE_USHORT</code>, or * <code>DataBuffer.TYPE_INT</code>. * @param inData an array of pixel values * @return the value of the blue component of the specified pixel. * @throws ClassCastException if <code>inData</code> * is not a primitive array of type <code>transferType</code> * @throws ArrayIndexOutOfBoundsException if * <code>inData</code> is not large enough to hold a pixel value * for this <code>ColorModel</code> * @throws UnsupportedOperationException if this * <code>tranferType</code> is not supported by this * <code>ColorModel</code> */ public int getBlue(Object inData) { int pixel=0,length=0; switch (transferType) { case DataBuffer.TYPE_BYTE: byte bdata[] = (byte[])inData; pixel = bdata[0] & 0xff; length = bdata.length; break; case DataBuffer.TYPE_USHORT: short sdata[] = (short[])inData; pixel = sdata[0] & 0xffff; length = sdata.length; break; case DataBuffer.TYPE_INT: int idata[] = (int[])inData; pixel = idata[0]; length = idata.length; break; default: throw new UnsupportedOperationException("This method has not been "+ "implemented for transferType " + transferType); } if (length == 1) { return getBlue(pixel); } else { throw new UnsupportedOperationException ("This method is not supported by this color model"); } } /** * Returns the alpha component for the specified pixel, scaled * from 0 to 255. The pixel value is specified by an array of data * elements of type transferType passed in as an object reference. * If inData is not a primitive array of type transferType, a * <code>ClassCastException</code> is thrown. An * <code>ArrayIndexOutOfBoundsException</code> is thrown if * <code>inData</code> is not large enough to hold a pixel value for * this <code>ColorModel</code>. * If this <code>transferType</code> is not supported, a * <code>UnsupportedOperationException</code> will be * thrown. Since * <code>ColorModel</code> is an abstract class, any instance * must be an instance of a subclass. Subclasses inherit the * implementation of this method and if they don't override it, this * method throws an exception if the subclass uses a * <code>transferType</code> other than * <code>DataBuffer.TYPE_BYTE</code>, * <code>DataBuffer.TYPE_USHORT</code>, or * <code>DataBuffer.TYPE_INT</code>. * @param inData the specified pixel * @return the alpha component of the specified pixel, scaled from * 0 to 255. * @throws ClassCastException if <code>inData</code> * is not a primitive array of type <code>transferType</code> * @throws ArrayIndexOutOfBoundsException if * <code>inData</code> is not large enough to hold a pixel value * for this <code>ColorModel</code> * @throws UnsupportedOperationException if this * <code>tranferType</code> is not supported by this * <code>ColorModel</code> */ public int getAlpha(Object inData) { int pixel=0,length=0; switch (transferType) { case DataBuffer.TYPE_BYTE: byte bdata[] = (byte[])inData; pixel = bdata[0] & 0xff; length = bdata.length; break; case DataBuffer.TYPE_USHORT: short sdata[] = (short[])inData;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -