colormodel.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 443 行 · 第 1/2 页

JAVA
443
字号
    }    /**     * Returns the number of bits per pixel described by this ColorModel.     */    public int getPixelSize() {        return pixel_bits;    }    /**     * The subclass must provide a function which provides the red     * color compoment for the specified pixel.     * @return		The red color component ranging from 0 to 255     */    public abstract int getRed(int pixel);    /**     * The subclass must provide a function which provides the green     * color compoment for the specified pixel.     * @return		The green color component ranging from 0 to 255     */    public abstract int getGreen(int pixel);    /**     * The subclass must provide a function which provides the blue     * color compoment for the specified pixel.     * @return		The blue color component ranging from 0 to 255     */    public abstract int getBlue(int pixel);    /**     * The subclass must provide a function which provides the alpha     * color compoment for the specified pixel.     * @return		The alpha transparency value ranging from 0 to 255     */    public abstract int getAlpha(int pixel);    /**     * Returns the color of the pixel in the default RGB color model.     * @see ColorModel#getRGBdefault     */    public int getRGB(int pixel) {        return (getAlpha(pixel) << 24)            | (getRed(pixel) << 16)            | (getGreen(pixel) << 8)            | (getBlue(pixel) << 0);    }    /**     * Tests if the specified <code>Object</code> is an instance of     * <code>ColorModel</code> and if it equals this     * <code>ColorModel</code>.     * @param obj the <code>Object</code> to test for equality     * @return <code>true</code> if the specified <code>Object</code>     * is an instance of <code>ColorModel</code> and equals this     * <code>ColorModel</code>; <code>false</code> otherwise.     */    public boolean equals(Object obj) {        if (!(obj instanceof ColorModel)) {            return false;        }        ColorModel cm = (ColorModel) obj;        if (this == cm) {            return true;        }        if (supportsAlpha != cm.hasAlpha() ||            isAlphaPremultiplied != cm.isAlphaPremultiplied() ||            transparency != cm.getTransparency() ||            pixel_bits != cm.getPixelSize()) {            return false;        }        return true;    }    /**     * Disposes of system resources associated with this     * <code>ColorModel</code> once this <code>ColorModel</code> is no     * longer referenced.     */    public void finalize() {    }    /**     * Returns the hash code for this ColorModel.     *     * @return    a hash code for this ColorModel.     */    public int hashCode() {        int result = 0;        result = (supportsAlpha ? 2 : 3) +                (isAlphaPremultiplied ? 4 : 5) +                pixel_bits * 6 +                transparency * 7;        return result;    }    /**     * Returns the <code>ColorSpace</code> associated with this     * <code>ColorModel</code>.     * @return the <code>ColorSpace</code> of this     * <code>ColorModel</code>.     */    final public ColorSpace getColorSpace() {        return colorSpace;    }    /**     * 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 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) {        // NOTE        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 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 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.     */    public final int getTransferType() {        return transferType;    }        static final int getDefaultTransferType(int pixel_bits) {        if (pixel_bits <= 8) {            return DataBuffer.TYPE_BYTE;        } else if (pixel_bits <= 16) {            return DataBuffer.TYPE_USHORT;        } else if (pixel_bits <= 32) {            return DataBuffer.TYPE_INT;        } else {            return DataBuffer.TYPE_UNDEFINED;        }    }         /**     * Returns the <code>String</code> representation of the contents of     * this <code>ColorModel</code>object.     * @return a <code>String</code> representing the contents of this     * <code>ColorModel</code> object.     */    public String toString() {        return new String("ColorModel: #pixelBits = " + pixel_bits                + " numComponents = " + numComponents                + " color space = " + colorSpace                + " transparency = " + transparency                + " has alpha = " + supportsAlpha                + " isAlphaPre = " + isAlphaPremultiplied            );    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?