KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > util > ColorProfileUtil


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 /* $Id$ */
19
20 package org.apache.fop.util;
21
22 import java.awt.color.ColorSpace JavaDoc;
23 import java.awt.color.ICC_ColorSpace JavaDoc;
24 import java.awt.color.ICC_Profile JavaDoc;
25 import java.io.UnsupportedEncodingException JavaDoc;
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 JavaDoc getICCProfileDescription(ICC_Profile JavaDoc profile) {
38         byte[] data = profile.getData(ICC_Profile.icSigProfileDescriptionTag);
39         if (data == null) {
40             return null;
41         } else {
42             //Info on the data format: http://www.color.org/ICC-1_1998-09.PDF
43
int length = (data[8] << 3 * 8) | (data[9] << 2 * 8) | (data[10] << 8) | data[11];
44             length--; //Remove trailing NUL character
45
try {
46                 return new String JavaDoc(data, 12, length, "US-ASCII");
47             } catch (UnsupportedEncodingException JavaDoc e) {
48                 throw new UnsupportedOperationException JavaDoc("Incompatible VM");
49             }
50         }
51     }
52     
53     /**
54      * Indicates whether a given color profile is identical to the default sRGB profile
55      * provided by the Java class library.
56      * @param profile the color profile to check
57      * @return true if it is the default sRGB profile
58      */

59     public static boolean isDefaultsRGB(ICC_Profile JavaDoc profile) {
60         ColorSpace JavaDoc sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
61         ICC_Profile JavaDoc sRGBProfile = null;
62         if (sRGB instanceof ICC_ColorSpace JavaDoc) {
63             sRGBProfile = ((ICC_ColorSpace JavaDoc)sRGB).getProfile();
64         }
65         return profile == sRGBProfile;
66     }
67     
68 }
69
Popular Tags