001 /* ICC_ProfileGray.java -- the ICC profile for a Gray colorspace 002 Copyright (C) 2002, 2004 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 039 package java.awt.color; 040 041 /** 042 * ICC_ProfileGray - a special case of ICC_Profiles. 043 * 044 * The ICC_Profile.getInstance() method will return an instance of the 045 * ICC_ProfileGray subclass when all the following conditions are met: 046 * The device color space of the profile is TYPE_GRAY. 047 * The profile contains a gray TRCTag. 048 * The profile contains a mediaWhitePointTag. 049 * 050 * As per the ICC specification, the color space conversion can then 051 * be done through the following method: 052 * linearGray = grayTRC[deviceGray] 053 * 054 * Note that if the profile contains a CLUT for the color space conversion, 055 * it should be used instead, and the TRC information ignored. 056 * 057 * @author Sven de Marothy 058 * @since 1.2 059 */ 060 public class ICC_ProfileGray extends ICC_Profile 061 { 062 /** 063 * Compatible with JDK 1.2+. 064 */ 065 private static final long serialVersionUID = -1124721290732002649L; 066 private transient float[] whitePoint; 067 068 /** 069 * Package-private constructor used by ICC_ColorSpace for creating an 070 * ICC_ProfileGray from a predefined ColorSpace (CS_GRAY) 071 */ 072 ICC_ProfileGray(int cspace) 073 { 074 super(cspace); 075 whitePoint = getXYZData(icSigMediaWhitePointTag); 076 } 077 078 /** 079 * Package-private constructor used by ICC_ColorSpace for creating an 080 * ICC_ProfileGray from profile data. 081 */ 082 ICC_ProfileGray(byte[] data) 083 { 084 super(data); 085 whitePoint = getXYZData(icSigMediaWhitePointTag); 086 } 087 088 089 /** 090 * Returns the media white point of the profile. 091 */ 092 public float[] getMediaWhitePoint() 093 { 094 float[] wp = new float[3]; 095 wp[0] = whitePoint[0]; 096 wp[1] = whitePoint[1]; 097 wp[2] = whitePoint[2]; 098 return wp; 099 } 100 101 /** 102 * Returns the TRC gamma value. 103 * @throws ProfileDataException if the TRC is described by a lookup 104 * table and not a gamma value. 105 */ 106 public float getGamma() 107 { 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."); 113 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; 117 } 118 119 /** 120 * Returns the TRC lookup table. 121 * @throws ProfileDataException if the TRC is described by a gamma value 122 * and not a lookup table. 123 */ 124 public short[] getTRC() 125 { 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; 132 } 133 } // class ICC_ProfileGray