01: /*
02: * $Id: AlternateColorSpace.java,v 1.2 2007/12/20 18:33:34 rbair Exp $
03: *
04: * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
05: * Santa Clara, California 95054, U.S.A. All rights reserved.
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20: */
21:
22: package com.sun.pdfview.colorspace;
23:
24: import java.awt.color.ColorSpace;
25:
26: import com.sun.pdfview.PDFPaint;
27: import com.sun.pdfview.function.PDFFunction;
28:
29: /**
30: * A color space that uses another color space to return values, and a
31: * function to map between values in the input and input values to the
32: * alternate color space
33: */
34: public class AlternateColorSpace extends PDFColorSpace {
35: /** The alternate color space */
36: private PDFColorSpace alternate;
37:
38: /** The function */
39: private PDFFunction function;
40:
41: /** Creates a new instance of AlternateColorSpace */
42: public AlternateColorSpace(PDFColorSpace alternate,
43: PDFFunction function) {
44: super (null);
45:
46: this .alternate = alternate;
47: this .function = function;
48: }
49:
50: /**
51: * get the number of components expected in the getPaint command
52: */
53: @Override
54: public int getNumComponents() {
55: if (function != null) {
56: return function.getNumInputs();
57: } else {
58: return alternate.getNumComponents();
59: }
60: }
61:
62: /**
63: * get the PDFPaint representing the color described by the
64: * given color components
65: * @param components the color components corresponding to the given
66: * colorspace
67: * @return a PDFPaint object representing the closest Color to the
68: * given components.
69: */
70: @Override
71: public PDFPaint getPaint(float[] components) {
72: if (function != null) {
73: // translate values using function
74: components = function.calculate(components);
75: }
76:
77: return alternate.getPaint(components);
78: }
79:
80: /**
81: * get the original Java ColorSpace.
82: */
83: @Override
84: public ColorSpace getColorSpace() {
85: return alternate.getColorSpace();
86: }
87:
88: }
|