J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1996 Sun Microsystems, Inc. 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. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * This file contains macro definitions for the Decoding category of |
| 28 | * the macros used by the generic scaleloop function. |
| 29 | * |
| 30 | * This implementation can decode the pixel information associated |
| 31 | * with any Java IndexColorModel object. This implementation examines |
| 32 | * some of the private fields of the IndexColorModel object and decodes |
| 33 | * the red, green, blue, and possibly alpha values directly rather than |
| 34 | * calling the getRGB method on the Java object. |
| 35 | */ |
| 36 | |
| 37 | /* |
| 38 | * These definitions vector the standard macro names to the "ICM" |
| 39 | * versions of those macros only if the "DecodeDeclared" keyword has |
| 40 | * not yet been defined elsewhere. The "DecodeDeclared" keyword is |
| 41 | * also defined here to claim ownership of the primary implementation |
| 42 | * even though this file does not rely on the definitions in any other |
| 43 | * files. |
| 44 | */ |
| 45 | #ifndef DecodeDeclared |
| 46 | #define DeclareDecodeVars DeclareICMVars |
| 47 | #define InitPixelDecode(CM) InitPixelICM(unhand(CM)) |
| 48 | #define PixelDecode PixelICMDecode |
| 49 | #define DecodeDeclared |
| 50 | #endif |
| 51 | |
| 52 | #include "java_awt_image_IndexColorModel.h" |
| 53 | |
| 54 | #define DeclareICMVars \ |
| 55 | unsigned int mapsize; \ |
| 56 | unsigned int *cmrgb; |
| 57 | |
| 58 | #define InitPixelICM(CM) \ |
| 59 | do { \ |
| 60 | Classjava_awt_image_IndexColorModel *icm = \ |
| 61 | (Classjava_awt_image_IndexColorModel *) CM; \ |
| 62 | cmrgb = (unsigned int *) unhand(icm->rgb); \ |
| 63 | mapsize = obj_length(icm->rgb); \ |
| 64 | } while (0) |
| 65 | |
| 66 | #define PixelICMDecode(CM, pixel, red, green, blue, alpha) \ |
| 67 | do { \ |
| 68 | VerifyPixelRange(pixel, mapsize); \ |
| 69 | pixel = cmrgb[pixel]; \ |
| 70 | IfAlpha(alpha = (pixel >> ALPHASHIFT) & 0xff;) \ |
| 71 | red = (pixel >> REDSHIFT) & 0xff; \ |
| 72 | green = (pixel >> GREENSHIFT) & 0xff; \ |
| 73 | blue = (pixel >> BLUESHIFT) & 0xff; \ |
| 74 | } while (0) |