01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: /* $Id$ */
19:
20: package org.apache.fop.util;
21:
22: import java.awt.color.ColorSpace;
23: import java.awt.color.ICC_ColorSpace;
24: import java.awt.color.ICC_Profile;
25: import java.io.UnsupportedEncodingException;
26:
27: /**
28: * Helper methods for handling color profiles.
29: */
30: public class ColorProfileUtil {
31:
32: /**
33: * Returns the profile description of an ICC profile
34: * @param profile the profile
35: * @return the description
36: */
37: public static String getICCProfileDescription(ICC_Profile profile) {
38: byte[] data = profile
39: .getData(ICC_Profile.icSigProfileDescriptionTag);
40: if (data == null) {
41: return null;
42: } else {
43: //Info on the data format: http://www.color.org/ICC-1_1998-09.PDF
44: int length = (data[8] << 3 * 8) | (data[9] << 2 * 8)
45: | (data[10] << 8) | data[11];
46: length--; //Remove trailing NUL character
47: try {
48: return new String(data, 12, length, "US-ASCII");
49: } catch (UnsupportedEncodingException e) {
50: throw new UnsupportedOperationException(
51: "Incompatible VM");
52: }
53: }
54: }
55:
56: /**
57: * Indicates whether a given color profile is identical to the default sRGB profile
58: * provided by the Java class library.
59: * @param profile the color profile to check
60: * @return true if it is the default sRGB profile
61: */
62: public static boolean isDefaultsRGB(ICC_Profile profile) {
63: ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
64: ICC_Profile sRGBProfile = null;
65: if (sRGB instanceof ICC_ColorSpace) {
66: sRGBProfile = ((ICC_ColorSpace) sRGB).getProfile();
67: }
68: return profile == sRGBProfile;
69: }
70:
71: }
|