1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17/**
18 * @author Oleg V. Khaschansky
19 * @version $Revision$
20 */
21package org.apache.harmony.awt.gl.color;
22
23import java.awt.color.ICC_Profile;
24
25/**
26 * Includes utility methods for reading ICC profile data.
27 * Created to provide public access to ICC_Profile methods
28 * for classes outside of java.awt.color
29 */
30public class ICC_ProfileHelper {
31    /**
32     * Utility method.
33     * Gets integer value from the byte array
34     * @param byteArray - byte array
35     * @param idx - byte offset
36     * @return integer value
37     */
38    public static int getIntFromByteArray(byte[] byteArray, int idx) {
39        return (byteArray[idx] & 0xFF)|
40               ((byteArray[idx+1] & 0xFF) << 8) |
41               ((byteArray[idx+2] & 0xFF) << 16)|
42               ((byteArray[idx+3] & 0xFF) << 24);
43    }
44
45    /**
46     * Utility method.
47     * Gets big endian integer value from the byte array
48     * @param byteArray - byte array
49     * @param idx - byte offset
50     * @return integer value
51     */
52    public static int getBigEndianFromByteArray(byte[] byteArray, int idx) {
53        return ((byteArray[idx] & 0xFF) << 24)   |
54               ((byteArray[idx+1] & 0xFF) << 16) |
55               ((byteArray[idx+2] & 0xFF) << 8)  |
56               ( byteArray[idx+3] & 0xFF);
57    }
58
59    /**
60     * Utility method.
61     * Gets short value from the byte array
62     * @param byteArray - byte array
63     * @param idx - byte offset
64     * @return short value
65     */
66    public static short getShortFromByteArray(byte[] byteArray, int idx) {
67        return (short) ((byteArray[idx] & 0xFF) |
68                       ((byteArray[idx+1] & 0xFF) << 8));
69    }
70
71    /**
72     * Used in ICC_Transform class to check the rendering intent of the profile
73     * @param profile - ICC profile
74     * @return rendering intent
75     */
76    public static int getRenderingIntent(ICC_Profile profile) {
77        return getIntFromByteArray(
78                profile.getData(ICC_Profile.icSigHead), // pf header
79                ICC_Profile.icHdrRenderingIntent
80            );
81    }
82}
83