1 /*
2  * Copyright (c) 2000, 2016, 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 #ifndef FourByteAbgrPre_h_Included
27 #define FourByteAbgrPre_h_Included
28 
29 /*
30  * This file contains macro and type definitions used by the macros in
31  * LoopMacros.h to manipulate a surface of type "FourByteAbgrPre".
32  */
33 
34 typedef jint    FourByteAbgrPrePixelType;
35 typedef jubyte  FourByteAbgrPreDataType;
36 
37 #define FourByteAbgrPreIsOpaque 0
38 
39 #define FourByteAbgrPrePixelStride              4
40 
41 #define DeclareFourByteAbgrPreLoadVars(PREFIX)
42 #define DeclareFourByteAbgrPreStoreVars(PREFIX)
43 #define SetFourByteAbgrPreStoreVarsYPos(PREFIX, pRasInfo, y)
44 #define SetFourByteAbgrPreStoreVarsXPos(PREFIX, pRasInfo, x)
45 #define InitFourByteAbgrPreLoadVars(PREFIX, pRasInfo)
46 #define InitFourByteAbgrPreStoreVarsY(PREFIX, pRasInfo)
47 #define InitFourByteAbgrPreStoreVarsX(PREFIX, pRasInfo)
48 #define NextFourByteAbgrPreStoreVarsX(PREFIX)
49 #define NextFourByteAbgrPreStoreVarsY(PREFIX)
50 
51 
52 #define FourByteAbgrPrePixelFromArgb(pixel, rgb, pRasInfo) \
53     do { \
54         jint a, r, g, b; \
55         if (((rgb) >> 24) == -1) { \
56             (pixel) = (((rgb) << 8) | (((juint) (rgb)) >> 24)); \
57         } else { \
58             ExtractIntDcmComponents1234(rgb, a, r, g, b); \
59             r = MUL8(a, r); \
60             g = MUL8(a, g); \
61             b = MUL8(a, b); \
62             (pixel) = ComposeIntDcmComponents1234(r, g, b, a); \
63         } \
64     } while (0)
65 
66 #define StoreFourByteAbgrPrePixel(pRas, x, pixel) \
67     do { \
68         (pRas)[4*(x)+0] = (jubyte) ((pixel) >> 0); \
69         (pRas)[4*(x)+1] = (jubyte) ((pixel) >> 8); \
70         (pRas)[4*(x)+2] = (jubyte) ((pixel) >> 16); \
71         (pRas)[4*(x)+3] = (jubyte) ((pixel) >> 24); \
72     } while (0)
73 
74 #define DeclareFourByteAbgrPrePixelData(PREFIX) \
75     jubyte PREFIX ## 0, PREFIX ## 1, PREFIX ## 2, PREFIX ## 3;
76 
77 #define ExtractFourByteAbgrPrePixelData(PIXEL, PREFIX) \
78     do { \
79         PREFIX ## 0 = (jubyte) (PIXEL >> 0); \
80         PREFIX ## 1 = (jubyte) (PIXEL >> 8); \
81         PREFIX ## 2 = (jubyte) (PIXEL >> 16); \
82         PREFIX ## 3 = (jubyte) (PIXEL >> 24); \
83     } while (0)
84 
85 #define StoreFourByteAbgrPrePixelData(pPix, x, pixel, PREFIX) \
86     do { \
87         pPix[4*(x)+0] = PREFIX ## 0; \
88         pPix[4*(x)+1] = PREFIX ## 1; \
89         pPix[4*(x)+2] = PREFIX ## 2; \
90         pPix[4*(x)+3] = PREFIX ## 3; \
91     } while (0)
92 
93 
94 #define LoadFourByteAbgrPreTo1IntRgb(pRas, PREFIX, x, rgb) \
95     LoadFourByteAbgrPreTo1IntArgb(pRas, PREFIX, x, rgb)
96 
97 #define LoadFourByteAbgrPreTo1IntArgb(pRas, PREFIX, x, argb) \
98     do { \
99         jint a = (pRas)[4*(x)+0]; \
100         if ((a == 0xff) || (a == 0)) { \
101             (argb) = (((pRas)[4*(x)+1] << 0) | \
102                       ((pRas)[4*(x)+2] << 8) | \
103                       ((pRas)[4*(x)+3] << 16) | \
104                       (a << 24)); \
105         } else { \
106             jint r, g, b; \
107             b = DIV8((pRas)[4*(x)+1], a); \
108             g = DIV8((pRas)[4*(x)+2], a); \
109             r = DIV8((pRas)[4*(x)+3], a); \
110             (argb) = ComposeIntDcmComponents1234(a, r, g, b); \
111         } \
112     } while (0)
113 
114 #define LoadFourByteAbgrPreTo3ByteRgb(pRas, PREFIX, x, r, g, b) \
115     do { \
116         jint a; \
117         LoadFourByteAbgrPreTo4ByteArgb(pRas, PREFIX, x, a, r, g, b); \
118     } while (0)
119 
120 #define LoadFourByteAbgrPreTo4ByteArgb(pRas, PREFIX, x, a, r, g, b) \
121     do { \
122         (a) = (pRas)[4*(x)+0]; \
123         (b) = (pRas)[4*(x)+1]; \
124         (g) = (pRas)[4*(x)+2]; \
125         (r) = (pRas)[4*(x)+3]; \
126         if ((a != 0xff) && (a != 0)) { \
127             r = DIV8(r, a); \
128             g = DIV8(g, a); \
129             b = DIV8(b, a); \
130         } \
131     } while (0)
132 
133 #define StoreFourByteAbgrPreFrom1IntRgb(pRas, PREFIX, x, rgb) \
134     do { \
135         (pRas)[4*(x)+0] = (jubyte) 0xff; \
136         (pRas)[4*(x)+1] = (jubyte) ((rgb) >> 0); \
137         (pRas)[4*(x)+2] = (jubyte) ((rgb) >> 8); \
138         (pRas)[4*(x)+3] = (jubyte) ((rgb) >> 16); \
139     } while (0)
140 
141 #define StoreFourByteAbgrPreFrom1IntArgb(pRas, PREFIX, x, argb) \
142     do { \
143         if ((((argb) >> 24) + 1) == 0) { \
144             (pRas)[4*(x)+0] = (jubyte) ((argb) >> 24); \
145             (pRas)[4*(x)+1] = (jubyte) ((argb) >> 0); \
146             (pRas)[4*(x)+2] = (jubyte) ((argb) >> 8); \
147             (pRas)[4*(x)+3] = (jubyte) ((argb) >> 16); \
148         } else { \
149             jint a, r, g, b; \
150             ExtractIntDcmComponents1234(argb, a, r, g, b); \
151             (pRas)[4*(x)+0] = (jubyte) a; \
152             (pRas)[4*(x)+1] = MUL8(a, b); \
153             (pRas)[4*(x)+2] = MUL8(a, g); \
154             (pRas)[4*(x)+3] = MUL8(a, r); \
155         } \
156     } while (0)
157 
158 #define StoreFourByteAbgrPreFrom3ByteRgb(pRas, PREFIX, x, r, g, b) \
159     do { \
160         (pRas)[4*(x)+0] = (jubyte) 0xff; \
161         (pRas)[4*(x)+1] = (jubyte) (b); \
162         (pRas)[4*(x)+2] = (jubyte) (g); \
163         (pRas)[4*(x)+3] = (jubyte) (r); \
164     } while (0)
165 
166 #define StoreFourByteAbgrPreFrom4ByteArgb(pRas, PREFIX, x, a, r, g, b) \
167     do { \
168         if ((a) == 0xff) { \
169             StoreFourByteAbgrPreFrom3ByteRgb(pRas, PREFIX, x, r, g, b); \
170         } else { \
171             (pRas)[4*(x)+0] = (jubyte) (a); \
172             (pRas)[4*(x)+1] = MUL8(a, b); \
173             (pRas)[4*(x)+2] = MUL8(a, g); \
174             (pRas)[4*(x)+3] = MUL8(a, r); \
175         } \
176     } while (0)
177 
178 #define CopyFourByteAbgrPreToIntArgbPre(pRGB, i, PREFIX, pRow, x) \
179     (pRGB)[i] = (((pRow)[4*(x)+0] << 24) | \
180                  ((pRow)[4*(x)+1] << 0) | \
181                  ((pRow)[4*(x)+2] << 8) | \
182                  ((pRow)[4*(x)+3] << 16))
183 
184 
185 #define DeclareFourByteAbgrPreAlphaLoadData(PREFIX)
186 #define InitFourByteAbgrPreAlphaLoadData(PREFIX, pRasInfo)
187 
188 #define LoadAlphaFromFourByteAbgrPreFor4ByteArgb(pRas, PREFIX, COMP_PREFIX) \
189     COMP_PREFIX ## A = (pRas)[0]
190 
191 #define Postload4ByteArgbFromFourByteAbgrPre(pRas, PREFIX, COMP_PREFIX) \
192     do { \
193         COMP_PREFIX ## B = (pRas)[1]; \
194         COMP_PREFIX ## G = (pRas)[2]; \
195         COMP_PREFIX ## R = (pRas)[3]; \
196     } while (0)
197 
198 
199 #define FourByteAbgrPreIsPremultiplied  1
200 
201 #define DeclareFourByteAbgrPreBlendFillVars(PREFIX)
202 
203 #define ClearFourByteAbgrPreBlendFillVars(PREFIX, argb)
204 
205 #define InitFourByteAbgrPreBlendFillVarsNonPre(PREFIX, argb, COMP_PREFIX)
206 
207 #define InitFourByteAbgrPreBlendFillVarsPre(PREFIX, argb, COMP_PREFIX)
208 
209 #define StoreFourByteAbgrPreBlendFill(pRas, PREFIX, x, argb, COMP_PREFIX) \
210     StoreFourByteAbgrPreFrom4ByteArgbComps(pRas, PREFIX, x, COMP_PREFIX)
211 
212 #define StoreFourByteAbgrPreFrom4ByteArgbComps(pRas, PREFIX, x, COMP_PREFIX)\
213     do { \
214         (pRas)[4*(x)+0] = (jubyte) COMP_PREFIX ## A; \
215         (pRas)[4*(x)+1] = (jubyte) COMP_PREFIX ## B; \
216         (pRas)[4*(x)+2] = (jubyte) COMP_PREFIX ## G; \
217         (pRas)[4*(x)+3] = (jubyte) COMP_PREFIX ## R; \
218     } while (0)
219 
220 /*
221  * SrcOver ## TYPE ## BlendFactor
222  * Returns appropriate blend value for use in blending calculations.
223  */
224 #define SrcOverFourByteAbgrPreBlendFactor(dF, dA) \
225     (dF)
226 
227 #endif /* FourByteAbgrPre_h_Included */
228