1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43:
44:
45:
50: public class ProfileHeader
51: {
52:
55: private static final int icMagicNumber = 0x61637370;
56:
57:
60: private static final int[] csTypeMap =
61: {
62: ICC_Profile.icSigXYZData,
63: ColorSpace.TYPE_XYZ,
64: ICC_Profile.icSigLabData,
65: ColorSpace.TYPE_Lab,
66: ICC_Profile.icSigLuvData,
67: ColorSpace.TYPE_Luv,
68: ICC_Profile.icSigYCbCrData,
69: ColorSpace.TYPE_YCbCr,
70: ICC_Profile.icSigYxyData,
71: ColorSpace.TYPE_Yxy,
72: ICC_Profile.icSigRgbData,
73: ColorSpace.TYPE_RGB,
74: ICC_Profile.icSigGrayData,
75: ColorSpace.TYPE_GRAY,
76: ICC_Profile.icSigHsvData,
77: ColorSpace.TYPE_HSV,
78: ICC_Profile.icSigHlsData,
79: ColorSpace.TYPE_HLS,
80: ICC_Profile.icSigCmykData,
81: ColorSpace.TYPE_CMYK,
82: ICC_Profile.icSigCmyData,
83: ColorSpace.TYPE_CMY,
84: ICC_Profile.icSigSpace2CLR,
85: ColorSpace.TYPE_2CLR,
86: ICC_Profile.icSigSpace3CLR,
87: ColorSpace.TYPE_3CLR,
88: ICC_Profile.icSigSpace4CLR,
89: ColorSpace.TYPE_4CLR,
90: ICC_Profile.icSigSpace5CLR,
91: ColorSpace.TYPE_5CLR,
92: ICC_Profile.icSigSpace6CLR,
93: ColorSpace.TYPE_6CLR,
94: ICC_Profile.icSigSpace7CLR,
95: ColorSpace.TYPE_7CLR,
96: ICC_Profile.icSigSpace8CLR,
97: ColorSpace.TYPE_8CLR,
98: ICC_Profile.icSigSpace9CLR,
99: ColorSpace.TYPE_9CLR,
100: ICC_Profile.icSigSpaceACLR,
101: ColorSpace.TYPE_ACLR,
102: ICC_Profile.icSigSpaceBCLR,
103: ColorSpace.TYPE_BCLR,
104: ICC_Profile.icSigSpaceCCLR,
105: ColorSpace.TYPE_CCLR,
106: ICC_Profile.icSigSpaceDCLR,
107: ColorSpace.TYPE_DCLR,
108: ICC_Profile.icSigSpaceECLR,
109: ColorSpace.TYPE_ECLR,
110: ICC_Profile.icSigSpaceFCLR,
111: ColorSpace.TYPE_FCLR
112: };
113:
114:
117: public static final int HEADERSIZE = 128;
118:
119:
122: private static final int[] classMap =
123: {
124: ICC_Profile.icSigInputClass,
125: ICC_Profile.CLASS_INPUT,
126: ICC_Profile.icSigDisplayClass,
127: ICC_Profile.CLASS_DISPLAY,
128: ICC_Profile.icSigOutputClass,
129: ICC_Profile.CLASS_OUTPUT,
130: ICC_Profile.icSigLinkClass,
131: ICC_Profile.CLASS_DEVICELINK,
132: ICC_Profile.icSigColorSpaceClass,
133: ICC_Profile.CLASS_COLORSPACECONVERSION,
134: ICC_Profile.icSigAbstractClass,
135: ICC_Profile.CLASS_ABSTRACT,
136: ICC_Profile.icSigNamedColorClass,
137: ICC_Profile.CLASS_NAMEDCOLOR
138: };
139: private int size;
140: private int cmmId;
141:
142:
143: private int majorVersion;
144:
145:
146: private int minorVersion;
147: private int profileClass;
148: private int colorSpace;
149: private int profileColorSpace;
150: private byte[] timestamp;
151: private int platform;
152: private int flags;
153: private int magic;
154: private int manufacturerSig;
155: private int modelSig;
156: private byte[] attributes;
157: private int intent;
158: private byte[] illuminant;
159: private int creatorSig;
160:
161:
165: public ProfileHeader()
166: {
167: creatorSig = 0;
168: intent = 0;
169: modelSig = manufacturerSig = (int) 0x6E6f6E65;
170: magic = icMagicNumber;
171: cmmId = 0;
172: platform = 0;
173: timestamp = new byte[8];
174: majorVersion = 2;
175: minorVersion = 0x10;
176: flags = 0;
177:
178:
179: illuminant = new byte[]
180: {
181: (byte) 0x00, (byte) 0x00, (byte) 0xf6, (byte) 0xd6,
182: (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00,
183: (byte) 0x00, (byte) 0x00, (byte) 0xd3, (byte) 0x2d
184: };
185: attributes = new byte[8];
186: profileClass = ICC_Profile.CLASS_DISPLAY;
187: }
188:
189:
193: public ProfileHeader(byte[] data)
194: {
195: ByteBuffer buf = ByteBuffer.wrap(data);
196:
197:
198:
199: size = buf.getInt(ICC_Profile.icHdrSize);
200:
201:
202: cmmId = buf.getInt(ICC_Profile.icHdrCmmId);
203:
204:
205: majorVersion = (int) (data[ICC_Profile.icHdrVersion]);
206: minorVersion = (int) (data[ICC_Profile.icHdrVersion + 1]);
207:
208:
209: int classSig = buf.getInt(ICC_Profile.icHdrDeviceClass);
210: profileClass = -1;
211: for (int i = 0; i < classMap.length; i += 2)
212: if (classMap[i] == classSig)
213: {
214: profileClass = classMap[i + 1];
215: break;
216: }
217:
218:
219: int csSig = buf.getInt(ICC_Profile.icHdrColorSpace);
220: colorSpace = -1;
221: for (int i = 0; i < csTypeMap.length; i += 2)
222: if (csTypeMap[i] == csSig)
223: {
224: colorSpace = csTypeMap[i + 1];
225: break;
226: }
227:
228:
229:
230: int pcsSig = buf.getInt(ICC_Profile.icHdrPcs);
231: profileColorSpace = -1;
232: if (profileClass != ICC_Profile.CLASS_DEVICELINK)
233: {
234: if (pcsSig == ICC_Profile.icSigXYZData)
235: profileColorSpace = ColorSpace.TYPE_XYZ;
236: if (pcsSig == ICC_Profile.icSigLabData)
237: profileColorSpace = ColorSpace.TYPE_Lab;
238: }
239: else
240: {
241: for (int i = 0; i < csTypeMap.length; i += 2)
242: if (csTypeMap[i] == pcsSig)
243: {
244: profileColorSpace = csTypeMap[i + 1];
245: break;
246: }
247: }
248:
249:
250: timestamp = new byte[8];
251: System.arraycopy(data, ICC_Profile.icHdrDate, timestamp, 0, 8);
252:
253:
254: magic = buf.getInt(ICC_Profile.icHdrMagic);
255:
256:
257: platform = buf.getInt(ICC_Profile.icHdrPlatform);
258:
259: flags = buf.getInt(ICC_Profile.icHdrFlags);
260:
261: manufacturerSig = buf.getInt(ICC_Profile.icHdrManufacturer);
262:
263: modelSig = buf.getInt(ICC_Profile.icHdrModel);
264:
265: attributes = new byte[8];
266: System.arraycopy(data, ICC_Profile.icHdrAttributes, attributes, 0, 8);
267:
268: intent = buf.getInt(ICC_Profile.icHdrRenderingIntent);
269:
270: illuminant = new byte[12];
271: System.arraycopy(data, ICC_Profile.icHdrIlluminant, illuminant, 0, 12);
272:
273: creatorSig = buf.getInt(ICC_Profile.icHdrCreator);
274:
275: }
276:
277:
282: public void verifyHeader(int size) throws IllegalArgumentException
283: {
284:
285: if (size != -1 && this.size != size)
286: throw new IllegalArgumentException("Invalid profile length:" + size);
287:
288:
289: if (majorVersion != 2)
290: throw new IllegalArgumentException("Wrong major version number:"
291: + majorVersion);
292:
293:
294: if (profileClass == -1)
295: throw new IllegalArgumentException("Invalid profile/device class");
296:
297:
298: if (colorSpace == -1)
299: throw new IllegalArgumentException("Invalid colorspace");
300:
301:
302: if (profileColorSpace == -1)
303: throw new IllegalArgumentException("Invalid PCS.");
304:
305:
306: if (magic != icMagicNumber)
307: throw new IllegalArgumentException("Invalid magic number!");
308: }
309:
310:
314: public byte[] getData(int size)
315: {
316: byte[] data = new byte[HEADERSIZE];
317: ByteBuffer buf = ByteBuffer.wrap(data);
318: buf.putInt(ICC_Profile.icHdrSize, size);
319: buf.putInt(ICC_Profile.icHdrCmmId, cmmId);
320: buf.putShort(ICC_Profile.icHdrVersion,
321: (short) (majorVersion << 8 | minorVersion));
322: for (int i = 1; i < classMap.length; i += 2)
323: if (profileClass == classMap[i])
324: buf.putInt(ICC_Profile.icHdrDeviceClass, classMap[i - 1]);
325: for (int i = 1; i < csTypeMap.length; i += 2)
326: if (csTypeMap[i] == colorSpace)
327: buf.putInt(ICC_Profile.icHdrColorSpace, csTypeMap[i - 1]);
328: for (int i = 1; i < csTypeMap.length; i += 2)
329: if (csTypeMap[i] == profileColorSpace)
330: buf.putInt(ICC_Profile.icHdrPcs, csTypeMap[i - 1]);
331:
332: System.arraycopy(timestamp, 0, data, ICC_Profile.icHdrDate,
333: timestamp.length);
334: buf.putInt(ICC_Profile.icHdrMagic, icMagicNumber);
335: buf.putInt(ICC_Profile.icHdrPlatform, platform);
336: buf.putInt(ICC_Profile.icHdrFlags, flags);
337: buf.putInt(ICC_Profile.icHdrManufacturer, manufacturerSig);
338: buf.putInt(ICC_Profile.icHdrModel, modelSig);
339: System.arraycopy(attributes, 0, data, ICC_Profile.icHdrAttributes,
340: attributes.length);
341: buf.putInt(ICC_Profile.icHdrRenderingIntent, intent);
342: System.arraycopy(illuminant, 0, data, ICC_Profile.icHdrIlluminant,
343: illuminant.length);
344: buf.putInt(ICC_Profile.icHdrCreator, creatorSig);
345: return buf.array();
346: }
347:
348: public int getSize()
349: {
350: return size;
351: }
352:
353: public void setSize(int s)
354: {
355: size = s;
356: }
357:
358: public int getMajorVersion()
359: {
360: return majorVersion;
361: }
362:
363: public int getMinorVersion()
364: {
365: return minorVersion;
366: }
367:
368: public int getProfileClass()
369: {
370: return profileClass;
371: }
372:
373: public void setProfileClass(int pc)
374: {
375: profileClass = pc;
376: }
377:
378: public int getColorSpace()
379: {
380: return colorSpace;
381: }
382:
383: public int getProfileColorSpace()
384: {
385: return profileColorSpace;
386: }
387:
388: public void setColorSpace(int cs)
389: {
390: colorSpace = cs;
391: }
392:
393: public void setProfileColorSpace(int pcs)
394: {
395: profileColorSpace = pcs;
396: }
397:
398: }