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 Java DirectColorModel objects where the color masks are |
| 32 | * guaranteed to be at least 8-bits wide each. It is slightly more |
| 33 | * efficient then the generic DCM parsing code since it does not need |
| 34 | * to store or test component scaling values. This implementation |
| 35 | * examines some of the private fields of the DirectColorModel |
| 36 | * object and decodes the red, green, blue, and possibly alpha values |
| 37 | * directly rather than calling the getRGB method on the Java object. |
| 38 | */ |
| 39 | |
| 40 | /* |
| 41 | * These definitions vector the standard macro names to the "DCM8" |
| 42 | * versions of those macros only if the "DecodeDeclared" keyword has |
| 43 | * not yet been defined elsewhere. The "DecodeDeclared" keyword is |
| 44 | * also defined here to claim ownership of the primary implementation |
| 45 | * even though this file does not rely on the definitions in any other |
| 46 | * files. |
| 47 | */ |
| 48 | #ifndef DecodeDeclared |
| 49 | #define DeclareDecodeVars DeclareDCM8Vars |
| 50 | #define InitPixelDecode(CM) InitPixelDCM8(unhand(CM)) |
| 51 | #define PixelDecode PixelDCM8Decode |
| 52 | #define DecodeDeclared |
| 53 | #endif |
| 54 | |
| 55 | #include "java_awt_image_DirectColorModel.h" |
| 56 | |
| 57 | #define DeclareDCM8Vars \ |
| 58 | IfAlpha(unsigned int alpha_off;) \ |
| 59 | unsigned int red_off, green_off, blue_off; |
| 60 | |
| 61 | #define InitPixelDCM8(CM) \ |
| 62 | do { \ |
| 63 | Classjava_awt_image_DirectColorModel *dcm = \ |
| 64 | (Classjava_awt_image_DirectColorModel *) CM; \ |
| 65 | red_off = dcm->red_offset; \ |
| 66 | green_off = dcm->green_offset; \ |
| 67 | blue_off = dcm->blue_offset; \ |
| 68 | IfAlpha(alpha_off = (dcm->alpha_mask == 0 \ |
| 69 | ? -1 \ |
| 70 | : dcm->alpha_offset);) \ |
| 71 | } while (0) |
| 72 | |
| 73 | #define PixelDCM8Decode(CM, pixel, red, green, blue, alpha) \ |
| 74 | do { \ |
| 75 | IfAlpha(alpha = ((alpha_off < 0) \ |
| 76 | ? 255 \ |
| 77 | : (pixel >> alpha_off) & 0xff);) \ |
| 78 | red = (pixel >> red_off) & 0xff; \ |
| 79 | green = (pixel >> green_off) & 0xff; \ |
| 80 | blue = (pixel >> blue_off) & 0xff; \ |
| 81 | } while (0) |