Showing the changes to java/pkg/com/sun/imageio/plugins/common/BogusColorSpace.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,136 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package com.sun.imageio.plugins.common; | ||
| 27 | |||
| 28 | import java.awt.color.ColorSpace; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * A dummy <code>ColorSpace</code> to enable <code>ColorModel</code> | ||
| 32 | * for image data which do not have an innate color representation. | ||
| 33 | */ | ||
| 34 | public class BogusColorSpace extends ColorSpace { | ||
| 35 | /** | ||
| 36 | * Return the type given the number of components. | ||
| 37 | * | ||
| 38 | * @param numComponents The number of components in the | ||
| 39 | * <code>ColorSpace</code>. | ||
| 40 | * @exception IllegalArgumentException if <code>numComponents</code> | ||
| 41 | * is less than 1. | ||
| 42 | */ | ||
| 43 | private static int getType(int numComponents) { | ||
| 44 | if(numComponents < 1) { | ||
| 45 | throw new IllegalArgumentException("numComponents < 1!"); | ||
| 46 | } | ||
| 47 | |||
| 48 | int type; | ||
| 49 | switch(numComponents) { | ||
| 50 | case 1: | ||
| 51 | type = ColorSpace.TYPE_GRAY; | ||
| 52 | break; | ||
| 53 | default: | ||
| 54 | // Based on the constant definitions TYPE_2CLR=12 through | ||
| 55 | // TYPE_FCLR=25. This will return unknown types for | ||
| 56 | // numComponents > 15. | ||
| 57 | type = numComponents + 10; | ||
| 58 | } | ||
| 59 | |||
| 60 | return type; | ||
| 61 | } | ||
| 62 | |||
| 63 | /** | ||
| 64 | * Constructs a bogus <code>ColorSpace</code>. | ||
| 65 | * | ||
| 66 | * @param numComponents The number of components in the | ||
| 67 | * <code>ColorSpace</code>. | ||
| 68 | * @exception IllegalArgumentException if <code>numComponents</code> | ||
| 69 | * is less than 1. | ||
| 70 | */ | ||
| 71 | public BogusColorSpace(int numComponents) { | ||
| 72 | super(getType(numComponents), numComponents); | ||
| 73 | } | ||
| 74 | |||
| 75 | // | ||
| 76 | // The following methods simply copy the input array to the | ||
| 77 | // output array while otherwise attempting to adhere to the | ||
| 78 | // specified behavior of the methods vis-a-vis exceptions. | ||
| 79 | // | ||
| 80 | |||
| 81 | public float[] toRGB(float[] colorvalue) { | ||
| 82 | if(colorvalue.length < getNumComponents()) { | ||
| 83 | throw new ArrayIndexOutOfBoundsException | ||
| 84 | ("colorvalue.length < getNumComponents()"); | ||
| 85 | } | ||
| 86 | |||
| 87 | float[] rgbvalue = new float[3]; | ||
| 88 | |||
| 89 | System.arraycopy(colorvalue, 0, rgbvalue, 0, | ||
| 90 | Math.min(3, getNumComponents())); | ||
| 91 | |||
| 92 | return colorvalue; | ||
| 93 | } | ||
| 94 | |||
| 95 | public float[] fromRGB(float[] rgbvalue) { | ||
| 96 | if(rgbvalue.length < 3) { | ||
| 97 | throw new ArrayIndexOutOfBoundsException | ||
| 98 | ("rgbvalue.length < 3"); | ||
| 99 | } | ||
| 100 | |||
| 101 | float[] colorvalue = new float[getNumComponents()]; | ||
| 102 | |||
| 103 | System.arraycopy(rgbvalue, 0, colorvalue, 0, | ||
| 104 | Math.min(3, colorvalue.length)); | ||
| 105 | |||
| 106 | return rgbvalue; | ||
| 107 | } | ||
| 108 | |||
| 109 | public float[] toCIEXYZ(float[] colorvalue) { | ||
| 110 | if(colorvalue.length < getNumComponents()) { | ||
| 111 | throw new ArrayIndexOutOfBoundsException | ||
| 112 | ("colorvalue.length < getNumComponents()"); | ||
| 113 | } | ||
| 114 | |||
| 115 | float[] xyzvalue = new float[3]; | ||
| 116 | |||
| 117 | System.arraycopy(colorvalue, 0, xyzvalue, 0, | ||
| 118 | Math.min(3, getNumComponents())); | ||
| 119 | |||
| 120 | return colorvalue; | ||
| 121 | } | ||
| 122 | |||
| 123 | public float[] fromCIEXYZ(float[] xyzvalue) { | ||
| 124 | if(xyzvalue.length < 3) { | ||
| 125 | throw new ArrayIndexOutOfBoundsException | ||
| 126 | ("xyzvalue.length < 3"); | ||
| 127 | } | ||
| 128 | |||
| 129 | float[] colorvalue = new float[getNumComponents()]; | ||
| 130 | |||
| 131 | System.arraycopy(xyzvalue, 0, colorvalue, 0, | ||
| 132 | Math.min(3, colorvalue.length)); | ||
| 133 | |||
| 134 | return xyzvalue; | ||
| 135 | } | ||
| 136 | } | ||