1 /*
2  * Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * 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 #define DeclareDCM8Vars                                         \
56     IfAlpha(unsigned int alpha_off;)                            \
57     unsigned int red_off, green_off, blue_off;
58 
59 #define InitPixelDCM8(CM)                                               \
60     do {                                                                \
61         Classjava_awt_image_DirectColorModel *dcm =                     \
62             (Classjava_awt_image_DirectColorModel *) CM;                \
63         red_off = dcm->red_offset;                                      \
64         green_off = dcm->green_offset;                                  \
65         blue_off = dcm->blue_offset;                                    \
66         IfAlpha(alpha_off = (dcm->alpha_mask == 0                       \
67                              ? -1                                       \
68                              : dcm->alpha_offset);)                     \
69     } while (0)
70 
71 #define PixelDCM8Decode(CM, pixel, red, green, blue, alpha)             \
72     do {                                                                \
73         IfAlpha(alpha = ((alpha_off < 0)                                \
74                          ? 255                                          \
75                          : (pixel >> alpha_off) & 0xff);)               \
76         red = (pixel >> red_off) & 0xff;                                \
77         green = (pixel >> green_off) & 0xff;                            \
78         blue = (pixel >> blue_off) & 0xff;                              \
79     } while (0)
80