summaryrefslogtreecommitdiffstats
path: root/awt/java/awt/color/ICC_ProfileRGB.java
blob: 9c6010fcde63c2114dd50d014df8f11ef5a20f3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
/**
 * @author Oleg V. Khaschansky
 * @version $Revision$
 */
package java.awt.color;

import org.apache.harmony.awt.internal.nls.Messages;

/**
 * The ICC_ProfileRGB class represents profiles with RGB color space type and
 * contains the redColorantTag, greenColorantTag, blueColorantTag, redTRCTag,
 * greenTRCTag, blueTRCTag, and mediaWhitePointTag tags.
 * 
 * @since Android 1.0
 */
public class ICC_ProfileRGB extends ICC_Profile {
    
    /**
     * The Constant serialVersionUID.
     */
    private static final long serialVersionUID = 8505067385152579334L;

    /**
     * Instantiates a new RGB ICC_Profile.
     * 
     * @param profileHandle
     *            the profile handle
     */
    ICC_ProfileRGB(long profileHandle) {
        super(profileHandle);
    }

    /**
     * The Constant REDCOMPONENT indicates the red component.
     */
    public static final int REDCOMPONENT = 0;

    /**
     * The Constant GREENCOMPONENT indicates the green component.
     */
    public static final int GREENCOMPONENT = 1;

    /**
     * The Constant BLUECOMPONENT indicates the blue component.
     */
    public static final int BLUECOMPONENT = 2;

    // awt.15E=Unknown component. Must be REDCOMPONENT, GREENCOMPONENT or BLUECOMPONENT.
    /**
     * The Constant UNKNOWN_COMPONENT_MSG.
     */
    private static final String UNKNOWN_COMPONENT_MSG = Messages
            .getString("awt.15E"); //$NON-NLS-1$

    /**
     * Gets the TRC.
     * 
     * @param component
     *            the tag signature.
     * @return the TRC value.
     */
    @Override
    public short[] getTRC(int component) {
        switch (component) {
            case REDCOMPONENT:
                return super.getTRC(icSigRedTRCTag);
            case GREENCOMPONENT:
                return super.getTRC(icSigGreenTRCTag);
            case BLUECOMPONENT:
                return super.getTRC(icSigBlueTRCTag);
            default:
        }

        throw new IllegalArgumentException(UNKNOWN_COMPONENT_MSG);
    }

    /**
     * Gets the gamma.
     * 
     * @param component
     *            the tag signature.
     * @return the gamma value.
     */
    @Override
    public float getGamma(int component) {
        switch (component) {
            case REDCOMPONENT:
                return super.getGamma(icSigRedTRCTag);
            case GREENCOMPONENT:
                return super.getGamma(icSigGreenTRCTag);
            case BLUECOMPONENT:
                return super.getGamma(icSigBlueTRCTag);
            default:
        }

        throw new IllegalArgumentException(UNKNOWN_COMPONENT_MSG);
    }

    /**
     * Gets a float matrix which contains the X, Y, and Z components of the
     * profile's redColorantTag, greenColorantTag, and blueColorantTag.
     * 
     * @return the float matrix which contains the X, Y, and Z components of the
     *         profile's redColorantTag, greenColorantTag, and blueColorantTag.
     */
    public float[][] getMatrix() {
        float [][] m = new float[3][3]; // The matrix

        float[] redXYZ = getXYZValue(icSigRedColorantTag);
        float[] greenXYZ = getXYZValue(icSigGreenColorantTag);
        float[] blueXYZ = getXYZValue(icSigBlueColorantTag);

        m[0][0] = redXYZ[0];
        m[1][0] = redXYZ[1];
        m[2][0] = redXYZ[2];

        m[0][1] = greenXYZ[0];
        m[1][1] = greenXYZ[1];
        m[2][1] = greenXYZ[2];

        m[0][2] = blueXYZ[0];
        m[1][2] = blueXYZ[1];
        m[2][2] = blueXYZ[2];

        return m;
    }

    /**
     * Gets the media white point.
     * 
     * @return the media white point.
     */
    @Override
    public float[] getMediaWhitePoint() {
        return super.getMediaWhitePoint();
    }
}