Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / java / awt / color / ICC_ProfileGray.java
blob54c2771332d50ec2068f4991b11cff5864c90f79
1 /* ICC_ProfileGray.java -- the ICC profile for a Gray colorspace
2 Copyright (C) 2002, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java.awt.color;
41 /**
42 * ICC_ProfileGray - a special case of ICC_Profiles.
44 * The ICC_Profile.getInstance() method will return an instance of the
45 * ICC_ProfileGray subclass when all the following conditions are met:
46 * The device color space of the profile is TYPE_GRAY.
47 * The profile contains a gray TRCTag.
48 * The profile contains a mediaWhitePointTag.
50 * As per the ICC specification, the color space conversion can then
51 * be done through the following method:
52 * linearGray = grayTRC[deviceGray]
54 * Note that if the profile contains a CLUT for the color space conversion,
55 * it should be used instead, and the TRC information ignored.
57 * @author Sven de Marothy
58 * @since 1.2
60 public class ICC_ProfileGray extends ICC_Profile
62 /**
63 * Compatible with JDK 1.2+.
65 private static final long serialVersionUID = -1124721290732002649L;
66 private transient float[] whitePoint;
68 /**
69 * Package-private constructor used by ICC_ColorSpace for creating an
70 * ICC_ProfileGray from a predefined ColorSpace (CS_GRAY)
72 ICC_ProfileGray(int cspace)
74 super(cspace);
75 whitePoint = getXYZData(icSigMediaWhitePointTag);
78 /**
79 * Package-private constructor used by ICC_ColorSpace for creating an
80 * ICC_ProfileGray from profile data.
82 ICC_ProfileGray(byte[] data)
84 super(data);
85 whitePoint = getXYZData(icSigMediaWhitePointTag);
89 /**
90 * Returns the media white point of the profile.
92 public float[] getMediaWhitePoint()
94 float[] wp = new float[3];
95 wp[0] = whitePoint[0];
96 wp[1] = whitePoint[1];
97 wp[2] = whitePoint[2];
98 return wp;
102 * Returns the TRC gamma value.
103 * @throws ProfileDataException if the TRC is described by a lookup
104 * table and not a gamma value.
106 public float getGamma()
108 short[] data = getCurve(icSigGrayTRCTag);
109 if (data == null)
110 throw new IllegalArgumentException("Couldn't read Gray TRC data.");
111 if (data.length != 1)
112 throw new ProfileDataException("TRC is a table, not a gamma value.");
114 // convert the unsigned 7.8 fixed-point gamma to a float.
115 double gamma = (double) (data[0] & (0xFFFF)) / 256.0;
116 return (float) gamma;
120 * Returns the TRC lookup table.
121 * @throws ProfileDataException if the TRC is described by a gamma value
122 * and not a lookup table.
124 public short[] getTRC()
126 short[] data = getCurve(icSigGrayTRCTag);
127 if (data == null)
128 throw new IllegalArgumentException("Couldn't read Gray TRC data.");
129 if (data.length <= 1)
130 throw new ProfileDataException("Gamma value, not a TRC table.");
131 return data;
133 } // class ICC_ProfileGray