2362N/A * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This class provides utilities for converting between the standard 0N/A * rgb colorspace specification and the equivalent value for a pixel 0N/A * of a given surface type. The class was designed for use by the 0N/A * SurfaceType objects, since the conversion between pixel values 0N/A * and rgb values is inherently tied to the type of surface we are 0N/A * dealing with. Some conversions cannot be done automatically, 0N/A * however (for example, the AnyInt or AnyDCM surface types), so 0N/A * we require the caller to pass in a ColorModel object so that 0N/A * we can calculate the pixel values in these generic cases as well. 0N/A * Default object, used as a fallback for any surface types where 0N/A * we do not know enough about the surface to calculate the 0N/A * conversions directly. We use the ColorModel object to assist 0N/A * us in these cases. 0N/A default:
// bytearr.length >= 4 0N/A // REMIND: Not yet implemented 0N/A * Subclasses of PixelConverter. These subclasses are 0N/A * specific to surface types where we can definitively 0N/A * calculate the conversions. Note that some conversions 0N/A * are lossy; that is, we cannot necessarily convert a 0N/A * value and then convert it back and wind up with the 0N/A * original value. For example, an rgb value that has 0N/A * an alpha != 1 cannot be converted to an Xrgb pixel 0N/A * without losing the information in the alpha component. 0N/A * The conversion strategies associated with the ThreeByte* 0N/A * and FourByte* surface types swap the components around 0N/A * due to the ordering used when the bytes are stored. The 0N/A * low order byte of a packed-byte pixel will be the first 0N/A * byte stored and the high order byte will be the last byte 0N/A * stored. For example, the ThreeByteBgr surface type is 0N/A * associated with an Xrgb conversion object because the 0N/A * three bytes are stored as follows: 0N/A * pixels[0] = b; // low order byte of an Xrgb pixel 0N/A * pixels[2] = r; // high order byte of an Xrgb pixel 0N/A return (((
rgb >> (
16 +
3 -
11)) &
0xf800) |
0N/A ((
rgb >> (
8 +
2 -
5)) &
0x07e0) |
0N/A ((
rgb >> (
0 +
3 -
0)) &
0x001f));
0N/A r = (r <<
3) | (r >>
2);
0N/A g = (g <<
2) | (g >>
4);
0N/A b = (b <<
3) | (b >>
2);
0N/A return (
0xff000000 | (r <<
16) | (g <<
8) | (b));
0N/A return (((
rgb >> (
16 +
3 -
11)) &
0xf800) |
0N/A ((
rgb >> (
8 +
3 -
6)) &
0x07c0) |
0N/A ((
rgb >> (
0 +
3 -
1)) &
0x003e));
0N/A r = (r <<
3) | (r >>
2);
0N/A g = (g <<
3) | (g >>
2);
0N/A b = (b <<
3) | (b >>
2);
0N/A return (
0xff000000 | (r <<
16) | (g <<
8) | (b));
0N/A return (((
rgb >> (
16 +
3 -
10)) &
0x7c00) |
0N/A ((
rgb >> (
8 +
3 -
5)) &
0x03e0) |
0N/A ((
rgb >> (
0 +
3 -
0)) &
0x001f));
0N/A r = (r <<
3) | (r >>
2);
0N/A g = (g <<
3) | (g >>
2);
0N/A b = (b <<
3) | (b >>
2);
0N/A return (
0xff000000 | (r <<
16) | (g <<
8) | (b));
0N/A // use upper 4 bits for each color 0N/A // 0xAaRrGgBb -> 0x0000ARGB 0N/A return (a | r | g | b);
0N/A // replicate 4 bits for each color 0N/A // 0xARGB -> 0xAARRGGBB 0N/A return (a | r | g | b);
0N/A return (((
rgb &
0xff) <<
16) |
0N/A return (
0xff000000 |
0N/A return (
0xff000000 |
0N/A return ((r <<
24) | (g <<
16) | (b <<
8) | (a));
0N/A if ((a ==
0xff) || (a ==
0)) {
0N/A r = ((r <<
8) - r) / a;
0N/A g = ((g <<
8) - g) / a;
0N/A b = ((b <<
8) - b) / a;
0N/A return ((r <<
24) | (g <<
16) | (b <<
8) | (a));
0N/A return ((a <<
24) | (r <<
16) | (g <<
8) | (b));
0N/A if ((a ==
0xff) || (a ==
0)) {
0N/A r = ((r <<
8) - r) / a;
0N/A g = ((g <<
8) - g) / a;
0N/A b = ((b <<
8) - b) / a;
0N/A return ((a <<
24) | (r <<
16) | (g <<
8) | (b));