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 valid Java ColorModel object by dynamically invoking the |
| 32 | * getRGB method on that object. The implementation will also |
| 33 | * optimally handle pixel data coming from IndexColorModel and |
| 34 | * DirectColorModel objects so that it can be used as the default |
| 35 | * fallback implementation for corner cases without imposing the |
| 36 | * enormous performance penalty required for handling the custom |
| 37 | * ColorModel objects in those cases. |
| 38 | * |
| 39 | * This file can be used to provide the default implementation of the |
| 40 | * Decoding macros, handling all color conversion cases. |
| 41 | */ |
| 42 | |
| 43 | /* |
| 44 | * These definitions vector the standard macro names to the "Any" |
| 45 | * versions of those macros. The "DecodeDeclared" keyword is also |
| 46 | * defined to indicate to the other include files that they are not |
| 47 | * defining the primary implementation. All other include files |
| 48 | * will check for the existance of the "DecodeDeclared" keyword |
| 49 | * and define their implementations of the Decoding macros using |
| 50 | * more specific names without overriding the standard names. |
| 51 | * This is done so that the other files can be included here to |
| 52 | * reuse their implementations for the specific optimization cases. |
| 53 | */ |
| 54 | #define DecodeDeclared |
| 55 | #define DeclareDecodeVars DeclareAnyVars |
| 56 | #define InitPixelDecode InitPixelAny |
| 57 | #define PixelDecode PixelAnyDecode |
| 58 | |
| 59 | /* Include the optimal implementations for Index and Direct ColorModels */ |
| 60 | #include "img_icm.h" |
| 61 | #include "img_dcm.h" |
| 62 | |
| 63 | #define ICMTYPE 0 |
| 64 | #define DCMTYPE 1 |
| 65 | #define OCMTYPE 2 |
| 66 | |
| 67 | #define DeclareAnyVars \ |
| 68 | DeclareICMVars \ |
| 69 | DeclareDCMVars \ |
| 70 | struct execenv *ee; \ |
| 71 | struct methodblock *mb = 0; \ |
| 72 | int CMtype; |
| 73 | |
| 74 | #define InitPixelAny(CM) \ |
| 75 | do { \ |
| 76 | Classjava_awt_image_ColorModel *cm = \ |
| 77 | (Classjava_awt_image_ColorModel *) unhand(CM); \ |
| 78 | ImgCMData *icmd = (ImgCMData *) cm->pData; \ |
| 79 | if ((icmd->type & IMGCV_CMBITS) == IMGCV_ICM) { \ |
| 80 | CMtype = ICMTYPE; \ |
| 81 | InitPixelICM(cm); \ |
| 82 | } else if (((icmd->type & IMGCV_CMBITS) == IMGCV_DCM) \ |
| 83 | || ((icmd->type & IMGCV_CMBITS) == IMGCV_DCM8)) { \ |
| 84 | CMtype = DCMTYPE; \ |
| 85 | InitPixelDCM(cm); \ |
| 86 | } else { \ |
| 87 | CMtype = OCMTYPE; \ |
| 88 | ee = EE(); \ |
| 89 | mb = icmd->mb; \ |
| 90 | } \ |
| 91 | } while (0) |
| 92 | |
| 93 | #define PixelAnyDecode(CM, pixel, red, green, blue, alpha) \ |
| 94 | do { \ |
| 95 | switch (CMtype) { \ |
| 96 | case ICMTYPE: \ |
| 97 | PixelICMDecode(CM, pixel, red, green, blue, alpha); \ |
| 98 | break; \ |
| 99 | case DCMTYPE: \ |
| 100 | PixelDCMDecode(CM, pixel, red, green, blue, alpha); \ |
| 101 | break; \ |
| 102 | case OCMTYPE: \ |
| 103 | pixel = do_execute_java_method(ee, (void *) CM, \ |
| 104 | "getRGB","(I)I", mb, \ |
| 105 | FALSE, pixel); \ |
| 106 | if (exceptionOccurred(ee)) { \ |
| 107 | return SCALEFAILURE; \ |
| 108 | } \ |
| 109 | IfAlpha(alpha = pixel >> ALPHASHIFT;) \ |
| 110 | red = (pixel >> REDSHIFT) & 0xff; \ |
| 111 | green = (pixel >> GREENSHIFT) & 0xff; \ |
| 112 | blue = (pixel >> BLUESHIFT) & 0xff; \ |
| 113 | break; \ |
| 114 | } \ |
| 115 | } while (0) |