blob: b9212dc9d8d7042cdfc0ec4e0cc10a1c219d5564 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
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 DirectColorModel object. This implemenation will
32 * scale the decoded color components to 8-bit quantities if needed.
33 * Another file is provided to optimize DCM parsing when the masks
34 * are guaranteed to be at least 8-bits wide. 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 "DCM"
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 DeclareDCMVars
50#define InitPixelDecode(CM) InitPixelDCM(unhand(CM))
51#define PixelDecode PixelDCMDecode
52#define DecodeDeclared
53#endif
54
55#include "java_awt_image_DirectColorModel.h"
56
57#define DeclareDCMVars \
58 IfAlpha(int alpha_mask; \
59 int alpha_scale; \
60 unsigned int alpha_off;) \
61 int red_mask, green_mask, blue_mask; \
62 int red_scale, green_scale, blue_scale; \
63 unsigned int red_off, green_off, blue_off; \
64 int scale;
65
66#define InitPixelDCM(CM) \
67 do { \
68 Classjava_awt_image_DirectColorModel *dcm = \
69 (Classjava_awt_image_DirectColorModel *) CM; \
70 red_mask = dcm->red_mask; \
71 red_off = dcm->red_offset; \
72 red_scale = dcm->red_scale; \
73 green_mask = dcm->green_mask; \
74 green_off = dcm->green_offset; \
75 green_scale = dcm->green_scale; \
76 blue_mask = dcm->blue_mask; \
77 blue_off = dcm->blue_offset; \
78 blue_scale = dcm->blue_scale; \
79 IfAlpha(alpha_mask = dcm->alpha_mask; \
80 alpha_off = dcm->alpha_offset; \
81 alpha_scale = dcm->alpha_scale;) \
82 scale = (red_scale | green_scale | blue_scale \
83 IfAlpha(| alpha_scale)); \
84 } while (0)
85
86#define PixelDCMDecode(CM, pixel, red, green, blue, alpha) \
87 do { \
88 IfAlpha(alpha = ((alpha_mask == 0) \
89 ? 255 \
90 : ((pixel & alpha_mask) >> alpha_off));) \
91 red = ((pixel & red_mask) >> red_off); \
92 green = ((pixel & green_mask) >> green_off); \
93 blue = ((pixel & blue_mask) >> blue_off); \
94 if (scale) { \
95 if (red_scale) { \
96 red = red * 255 / (red_scale); \
97 } \
98 if (green_scale) { \
99 green = green * 255 / (green_scale); \
100 } \
101 if (blue_scale) { \
102 blue = blue * 255 / (blue_scale); \
103 } \
104 IfAlpha(if (alpha_scale) { \
105 alpha = alpha * 255 / (alpha_scale); \
106 }) \
107 } \
108 } while (0)