blob: cf0a2773d0902871119a1e797ab92690e77f367d [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003 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#if !defined(JAVA2D_NO_MLIB) || defined(MLIB_ADD_SUFF)
27
28#include "java2d_Mlib.h"
29#include "SurfaceData.h"
30
31#include "mlib_ImageZoom.h"
32
33/***************************************************************/
34
35#define DEFINE_ISO_COPY(FUNC, ANYTYPE) \
36void ADD_SUFF(ANYTYPE##FUNC)(BLIT_PARAMS) \
37{ \
38 mlib_s32 srcScan = pSrcInfo->scanStride; \
39 mlib_s32 dstScan = pDstInfo->scanStride; \
40 mlib_s32 xsize = width*ANYTYPE##PixelStride; \
41 mlib_s32 i; \
42 \
43 if (srcScan == xsize && dstScan == xsize) { \
44 xsize *= height; \
45 height = 1; \
46 } \
47 \
48 for (i = 0; i < height; i++) { \
49 mlib_ImageCopy_na(srcBase, dstBase, xsize); \
50 srcBase = (mlib_u8*)srcBase + srcScan; \
51 dstBase = (mlib_u8*)dstBase + dstScan; \
52 } \
53}
54
55DEFINE_ISO_COPY(IsomorphicCopy, Any3Byte)
56DEFINE_ISO_COPY(IsomorphicCopy, Any4Byte)
57DEFINE_ISO_COPY(IsomorphicCopy, AnyByte)
58DEFINE_ISO_COPY(IsomorphicCopy, AnyInt)
59DEFINE_ISO_COPY(IsomorphicCopy, AnyShort)
60
61/***************************************************************/
62
63#define SET_PIX(index, chan) \
64 dst_ptr[index] = pixel##chan
65
66#define W_LEVEL_1 8
67#define W_LEVEL_3 16
68#define W_LEVEL_4 8
69
70#define DEFINE_SET_RECT(FUNC, ANYTYPE, NCHAN) \
71void ADD_SUFF(ANYTYPE##FUNC)(SurfaceDataRasInfo * pRasInfo, \
72 jint lox, jint loy, jint hix, \
73 jint hiy, jint pixel, \
74 NativePrimitive * pPrim, \
75 CompositeInfo * pCompInfo) \
76{ \
77 mlib_image dst[1]; \
78 mlib_s32 dstScan = pRasInfo->scanStride; \
79 mlib_s32 height = hiy - loy; \
80 mlib_s32 width = hix - lox; \
81 mlib_u8 *dstBase = (mlib_u8*)(pRasInfo->rasBase); \
82 mlib_s32 c_arr[4]; \
83 \
84 dstBase += loy*dstScan + lox*ANYTYPE##PixelStride; \
85 \
86 if (width <= W_LEVEL_##NCHAN) { \
87 EXTRACT_CONST_##NCHAN(pixel); \
88 \
89 LOOP_DST(ANYTYPE, NCHAN, dstBase, dstScan, SET_PIX); \
90 return; \
91 } \
92 \
93 STORE_CONST_##NCHAN(c_arr, pixel); \
94 \
95 MLIB_IMAGE_SET(dst, MLIB_##ANYTYPE, NCHAN, \
96 width, height, dstScan, dstBase); \
97 \
98 mlib_ImageClear(dst, c_arr); \
99}
100
101DEFINE_SET_RECT(SetRect, Any3Byte, 3)
102DEFINE_SET_RECT(SetRect, Any4Byte, 4)
103DEFINE_SET_RECT(SetRect, AnyByte, 1)
104DEFINE_SET_RECT(SetRect, AnyInt, 1)
105DEFINE_SET_RECT(SetRect, AnyShort, 1)
106
107/***************************************************************/
108
109#define XOR_PIX(index, chan) \
110 dst_ptr[index] ^= pixel##chan
111
112#define DEFINE_XOR_RECT(FUNC, ANYTYPE, NCHAN) \
113void ADD_SUFF(ANYTYPE##FUNC)(SurfaceDataRasInfo * pRasInfo, \
114 jint lox, jint loy, jint hix, \
115 jint hiy, jint pixel, \
116 NativePrimitive * pPrim, \
117 CompositeInfo * pCompInfo) \
118{ \
119 mlib_image dst[1]; \
120 mlib_s32 dstScan = pRasInfo->scanStride; \
121 mlib_s32 height = hiy - loy; \
122 mlib_s32 width = hix - lox; \
123 mlib_u8 *dstBase = (mlib_u8*)(pRasInfo->rasBase); \
124 mlib_s32 c_arr[4]; \
125 mlib_s32 xorpixel = pCompInfo->details.xorPixel; \
126 mlib_s32 alphamask = pCompInfo->alphaMask; \
127 \
128 pixel = (pixel ^ xorpixel) &~ alphamask; \
129 \
130 dstBase += loy*dstScan + lox*ANYTYPE##PixelStride; \
131 \
132 if (width < 8) { \
133 EXTRACT_CONST_##NCHAN(pixel); \
134 \
135 LOOP_DST(ANYTYPE, NCHAN, dstBase, dstScan, XOR_PIX); \
136 return; \
137 } \
138 \
139 STORE_CONST_##NCHAN(c_arr, pixel); \
140 \
141 MLIB_IMAGE_SET(dst, MLIB_##ANYTYPE, NCHAN, \
142 width, height, dstScan, dstBase); \
143 \
144 mlib_ImageConstXor(dst, dst, c_arr); \
145}
146
147DEFINE_XOR_RECT(XorRect, Any3Byte, 3)
148DEFINE_XOR_RECT(XorRect, Any4Byte, 4)
149DEFINE_XOR_RECT(XorRect, AnyByte, 1)
150DEFINE_XOR_RECT(XorRect, AnyInt, 1)
151DEFINE_XOR_RECT(XorRect, AnyShort, 1)
152
153/***************************************************************/
154
155#define XOR_COPY(index, chan) \
156 dst_ptr[index] = dst_ptr[index] ^ src_ptr[index] ^ pixel##chan
157
158#define DEFINE_XOR_COPY(FUNC, ANYTYPE, NCHAN) \
159void ADD_SUFF(ANYTYPE##FUNC)(void *srcBase, \
160 void *dstBase, \
161 juint width, \
162 juint height, \
163 SurfaceDataRasInfo *pSrcInfo, \
164 SurfaceDataRasInfo *pDstInfo, \
165 NativePrimitive *pPrim, \
166 CompositeInfo *pCompInfo) \
167{ \
168 mlib_image src[1], dst[1]; \
169 mlib_s32 srcScan = pSrcInfo->scanStride; \
170 mlib_s32 dstScan = pDstInfo->scanStride; \
171 mlib_s32 c_arr[4]; \
172 mlib_s32 pixel = pCompInfo->details.xorPixel; \
173 \
174 if (width < 8*sizeof(ANYTYPE##DataType)) { \
175 EXTRACT_CONST_##NCHAN(pixel); \
176 \
177 LOOP_DST_SRC(ANYTYPE, NCHAN, dstBase, dstScan, \
178 srcBase, srcScan, XOR_COPY); \
179 return; \
180 } \
181 \
182 STORE_CONST_##NCHAN(c_arr, pixel); \
183 \
184 MLIB_IMAGE_SET(src, MLIB_##ANYTYPE, NCHAN, \
185 width, height, srcScan, srcBase); \
186 MLIB_IMAGE_SET(dst, MLIB_##ANYTYPE, NCHAN, \
187 width, height, dstScan, dstBase); \
188 \
189 mlib_ImageXor(dst, dst, src); \
190 mlib_ImageConstXor(dst, dst, c_arr); \
191}
192
193DEFINE_XOR_COPY(IsomorphicXorCopy, Any3Byte, 3)
194DEFINE_XOR_COPY(IsomorphicXorCopy, Any4Byte, 4)
195DEFINE_XOR_COPY(IsomorphicXorCopy, AnyByte, 1)
196DEFINE_XOR_COPY(IsomorphicXorCopy, AnyInt, 1)
197DEFINE_XOR_COPY(IsomorphicXorCopy, AnyShort, 1)
198
199/***************************************************************/
200
201#define DEFINE_SET_SPANS(FUNC, ANYTYPE, NCHAN) \
202void ADD_SUFF(ANYTYPE##FUNC)(SurfaceDataRasInfo * pRasInfo, \
203 SpanIteratorFuncs * pSpanFuncs, \
204 void *siData, jint pixel, \
205 NativePrimitive * pPrim, \
206 CompositeInfo * pCompInfo) \
207{ \
208 mlib_image dst[1]; \
209 mlib_s32 dstScan = pRasInfo->scanStride; \
210 mlib_s32 height; \
211 mlib_s32 width; \
212 mlib_u8 *dstBase = (mlib_u8*)(pRasInfo->rasBase), *pdst; \
213 mlib_s32 c_arr[4]; \
214 jint bbox[4]; \
215 \
216 STORE_CONST_##NCHAN(c_arr, pixel); \
217 \
218 while ((*pSpanFuncs->nextSpan)(siData, bbox)) { \
219 mlib_s32 lox = bbox[0]; \
220 mlib_s32 loy = bbox[1]; \
221 mlib_s32 width = bbox[2] - lox; \
222 mlib_s32 height = bbox[3] - loy; \
223 \
224 pdst = dstBase + loy*dstScan + lox*ANYTYPE##PixelStride; \
225 \
226 MLIB_IMAGE_SET(dst, MLIB_##ANYTYPE, NCHAN_##ANYTYPE, \
227 width, height, dstScan, pdst); \
228 \
229 mlib_ImageClear(dst, c_arr); \
230 } \
231}
232
233DEFINE_SET_SPANS(SetSpans, Any3Byte, 3)
234DEFINE_SET_SPANS(SetSpans, Any4Byte, 4)
235DEFINE_SET_SPANS(SetSpans, AnyByte, 1)
236DEFINE_SET_SPANS(SetSpans, AnyInt, 1)
237DEFINE_SET_SPANS(SetSpans, AnyShort, 1)
238
239/***************************************************************/
240
241#define DEFINE_XOR_SPANS(FUNC, ANYTYPE, NCHAN) \
242void ADD_SUFF(ANYTYPE##FUNC)(SurfaceDataRasInfo * pRasInfo, \
243 SpanIteratorFuncs * pSpanFuncs, \
244 void *siData, jint pixel, \
245 NativePrimitive * pPrim, \
246 CompositeInfo * pCompInfo) \
247{ \
248 mlib_image dst[1]; \
249 mlib_s32 dstScan = pRasInfo->scanStride; \
250 mlib_s32 height; \
251 mlib_s32 width; \
252 mlib_u8 *dstBase = (mlib_u8*)(pRasInfo->rasBase), *pdst; \
253 mlib_s32 c_arr[4]; \
254 mlib_s32 xorpixel = pCompInfo->details.xorPixel; \
255 mlib_s32 alphamask = pCompInfo->alphaMask; \
256 jint bbox[4]; \
257 \
258 pixel = (pixel ^ xorpixel) &~ alphamask; \
259 \
260 STORE_CONST_##NCHAN(c_arr, pixel); \
261 \
262 while ((*pSpanFuncs->nextSpan)(siData, bbox)) { \
263 mlib_s32 lox = bbox[0]; \
264 mlib_s32 loy = bbox[1]; \
265 mlib_s32 width = bbox[2] - lox; \
266 mlib_s32 height = bbox[3] - loy; \
267 \
268 pdst = dstBase + loy*dstScan + lox*ANYTYPE##PixelStride; \
269 \
270 MLIB_IMAGE_SET(dst, MLIB_##ANYTYPE, NCHAN_##ANYTYPE, \
271 width, height, dstScan, pdst); \
272 \
273 mlib_ImageConstXor(dst, dst, c_arr); \
274 } \
275}
276
277DEFINE_XOR_SPANS(XorSpans, Any3Byte, 3)
278DEFINE_XOR_SPANS(XorSpans, Any4Byte, 4)
279DEFINE_XOR_SPANS(XorSpans, AnyByte, 1)
280DEFINE_XOR_SPANS(XorSpans, AnyInt, 1)
281DEFINE_XOR_SPANS(XorSpans, AnyShort, 1)
282
283/***************************************************************/
284
285#define SCALE_COPY(index, chan) \
286 pDst[chan] = pSrc[index]
287
288#define MLIB_ZOOM_NN_AnyByte mlib_ImageZoom_U8_1_Nearest(param);
289#define MLIB_ZOOM_NN_Any3Byte mlib_ImageZoom_U8_3_Nearest(param);
290#define MLIB_ZOOM_NN_AnyShort mlib_ImageZoom_S16_1_Nearest(param);
291#define MLIB_ZOOM_NN_AnyInt mlib_ImageZoom_S32_1_Nearest(param);
292
293#define MLIB_ZOOM_NN_Any4Byte \
294{ \
295 mlib_s32 b_align = (mlib_s32)srcBase | (mlib_s32)dstBase | \
296 srcScan | dstScan; \
297 \
298 if (!(b_align & 3)) { \
299 mlib_ImageZoom_S32_1_Nearest(param); \
300 } else if (!(b_align & 1)) { \
301 mlib_ImageZoom_S16_2_Nearest(param); \
302 } else { \
303 mlib_ImageZoom_U8_4_Nearest(param); \
304 } \
305}
306
307#define DEFINE_ISO_SCALE(FUNC, ANYTYPE, NCHAN) \
308void ADD_SUFF(ANYTYPE##FUNC)(void *srcBase, void *dstBase, \
309 juint width, juint height, \
310 jint sxloc, jint syloc, \
311 jint sxinc, jint syinc, \
312 jint shift, \
313 SurfaceDataRasInfo *pSrcInfo, \
314 SurfaceDataRasInfo *pDstInfo, \
315 NativePrimitive *pPrim, \
316 CompositeInfo *pCompInfo) \
317{ \
318 mlib_work_image param[1]; \
319 mlib_clipping current[1]; \
320 mlib_s32 srcScan = pSrcInfo->scanStride; \
321 mlib_s32 dstScan = pDstInfo->scanStride; \
322 \
323 if (width <= 32) { \
324 ANYTYPE##DataType *pSrc; \
325 ANYTYPE##DataType *pDst = dstBase; \
326 dstScan -= (width) * ANYTYPE##PixelStride; \
327 \
328 do { \
329 juint w = width; \
330 jint tmpsxloc = sxloc; \
331 pSrc = srcBase; \
332 PTR_ADD(pSrc, (syloc >> shift) * srcScan); \
333 do { \
334 jint i = (tmpsxloc >> shift); \
335 PROCESS_PIX_##NCHAN(SCALE_COPY); \
336 pDst += NCHAN; \
337 tmpsxloc += sxinc; \
338 } \
339 while (--w > 0); \
340 PTR_ADD(pDst, dstScan); \
341 syloc += syinc; \
342 } \
343 while (--height > 0); \
344 return; \
345 } \
346 \
347 param->current = current; \
348 \
349 if (shift <= MLIB_SHIFT /* 16 */) { \
350 jint dshift = MLIB_SHIFT - shift; \
351 sxloc <<= dshift; \
352 syloc <<= dshift; \
353 sxinc <<= dshift; \
354 syinc <<= dshift; \
355 } else { \
356 jint dshift = shift - MLIB_SHIFT; \
357 sxloc >>= dshift; \
358 syloc >>= dshift; \
359 sxinc >>= dshift; \
360 syinc >>= dshift; \
361 } \
362 \
363 current->width = width; \
364 current->height = height; \
365 param->DX = sxinc; \
366 param->DY = syinc; \
367 param->src_stride = srcScan; \
368 param->dst_stride = dstScan; \
369 current->srcX = sxloc; \
370 current->srcY = syloc; \
371 current->sp = (mlib_u8*)srcBase \
372 + (sxloc >> MLIB_SHIFT)*ANYTYPE##PixelStride \
373 + (syloc >> MLIB_SHIFT)*srcScan; \
374 current->dp = dstBase; \
375 \
376 MLIB_ZOOM_NN_##ANYTYPE \
377}
378
379DEFINE_ISO_SCALE(IsomorphicScaleCopy, Any3Byte, 3)
380DEFINE_ISO_SCALE(IsomorphicScaleCopy, Any4Byte, 4)
381DEFINE_ISO_SCALE(IsomorphicScaleCopy, AnyByte, 1)
382DEFINE_ISO_SCALE(IsomorphicScaleCopy, AnyInt, 1)
383DEFINE_ISO_SCALE(IsomorphicScaleCopy, AnyShort, 1)
384
385/***************************************************************/
386
387#endif /* JAVA2D_NO_MLIB */