001: /**
002: * Copyright (c) 2004, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.pdmodel.graphics.color;
031:
032: import org.pdfbox.cos.COSArray;
033: import org.pdfbox.cos.COSBase;
034: import org.pdfbox.cos.COSFloat;
035: import org.pdfbox.cos.COSNumber;
036:
037: import org.pdfbox.pdmodel.common.COSObjectable;
038:
039: /**
040: * A tristimulus, or collection of three floating point parameters used for
041: * color operations.
042: *
043: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
044: * @version $Revision: 1.2 $
045: */
046: public class PDTristimulus implements COSObjectable {
047: private COSArray values = null;
048:
049: /**
050: * Constructor. Defaults all values to 0, 0, 0.
051: */
052: public PDTristimulus() {
053: values = new COSArray();
054: values.add(new COSFloat(0.0f));
055: values.add(new COSFloat(0.0f));
056: values.add(new COSFloat(0.0f));
057: }
058:
059: /**
060: * Constructor from COS object.
061: *
062: * @param array The array containing the XYZ values.
063: */
064: public PDTristimulus(COSArray array) {
065: values = array;
066: }
067:
068: /**
069: * Constructor from COS object.
070: *
071: * @param array The array containing the XYZ values.
072: */
073: public PDTristimulus(float[] array) {
074: values = new COSArray();
075: for (int i = 0; i < array.length && i < 3; i++) {
076: values.add(new COSFloat(array[i]));
077: }
078: }
079:
080: /**
081: * Convert this standard java object to a COS object.
082: *
083: * @return The cos object that matches this Java object.
084: */
085: public COSBase getCOSObject() {
086: return values;
087: }
088:
089: /**
090: * This will get the x value of the tristimulus.
091: *
092: * @return The X value.
093: */
094: public float getX() {
095: return ((COSNumber) values.get(0)).floatValue();
096: }
097:
098: /**
099: * This will set the x value of the tristimulus.
100: *
101: * @param x The x value for the tristimulus.
102: */
103: public void setX(float x) {
104: values.set(0, new COSFloat(x));
105: }
106:
107: /**
108: * This will get the y value of the tristimulus.
109: *
110: * @return The Y value.
111: */
112: public float getY() {
113: return ((COSNumber) values.get(1)).floatValue();
114: }
115:
116: /**
117: * This will set the y value of the tristimulus.
118: *
119: * @param y The y value for the tristimulus.
120: */
121: public void setY(float y) {
122: values.set(1, new COSFloat(y));
123: }
124:
125: /**
126: * This will get the z value of the tristimulus.
127: *
128: * @return The Z value.
129: */
130: public float getZ() {
131: return ((COSNumber) values.get(2)).floatValue();
132: }
133:
134: /**
135: * This will set the z value of the tristimulus.
136: *
137: * @param z The z value for the tristimulus.
138: */
139: public void setZ(float z) {
140: values.set(2, new COSFloat(z));
141: }
142: }
|