blob: f8b3ecf1937d558affc56183bfd0a77c5d68c848 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003-2005 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 <vis_AlphaMacros.h>
29
30/***************************************************************/
31
32/* ##############################################################
33 * IntArgbSrcMaskFill()
34 * FourByteAbgrSrcMaskFill()
35 */
36
37#define MASK_FILL(rr, pathA, dstA, dstARGB) \
38{ \
39 mlib_d64 t0, t1; \
40 \
41 dstA = MUL8_INT(dstA, 0xff - pathA); \
42 \
43 t0 = MUL8_VIS(cnstARGB0, pathA); \
44 t1 = MUL8_VIS(dstARGB, dstA); \
45 rr = vis_fpadd16(t0, t1); \
46 \
47 dstA = dstA + mul8_cnstA[pathA]; \
48 DIV_ALPHA(rr, dstA); \
49}
50
51/***************************************************************/
52
53static void IntArgbSrcMaskFill_line(mlib_f32 *dst_ptr,
54 mlib_u8 *pMask,
55 mlib_s32 width,
56 mlib_d64 fgARGB,
57 mlib_f32 cnstARGB0,
58 mlib_u8 *mul8_cnstA,
59 mlib_u8 *mul8_tbl)
60{
61 mlib_s32 i, i0;
62 mlib_s32 pathA0, pathA1, dstA0, dstA1, msk;
63 mlib_d64 res0, res1, dstARGB;
64 mlib_f32 dstARGB0;
65
66 i = i0 = 0;
67
68 if ((mlib_s32)dst_ptr & 7) {
69 pathA0 = pMask[i];
70
71 if (pathA0 == 0xff) {
72 dst_ptr[i] = vis_read_hi(fgARGB);
73 } else if (pathA0) {
74 dstA0 = *(mlib_u8*)(dst_ptr + i);
75 dstARGB0 = dst_ptr[i];
76 MASK_FILL(res0, pathA0, dstA0, dstARGB0);
77 dst_ptr[i] = vis_fpack16(res0);
78 *(mlib_u8*)(dst_ptr + i) = dstA0;
79 }
80
81 i0 = 1;
82 }
83
84#pragma pipeloop(0)
85 for (i = i0; i <= width - 2; i += 2) {
86 pathA0 = pMask[i];
87 pathA1 = pMask[i + 1];
88 dstA0 = *(mlib_u8*)(dst_ptr + i);
89 dstA1 = *(mlib_u8*)(dst_ptr + i + 1);
90 dstARGB = *(mlib_d64*)(dst_ptr + i);
91
92 MASK_FILL(res0, pathA0, dstA0, vis_read_hi(dstARGB));
93 MASK_FILL(res1, pathA1, dstA1, vis_read_lo(dstARGB));
94
95 res0 = vis_fpack16_pair(res0, res1);
96
97 msk = (((-pathA0) & (1 << 11)) | ((-pathA1) & (1 << 10))) >> 10;
98 vis_pst_32(res0, dst_ptr + i, msk);
99
100 *(mlib_u8*)(dst_ptr + i ) = dstA0;
101 *(mlib_u8*)(dst_ptr + i + 1) = dstA1;
102
103 msk = (((254 - pathA0) & (1 << 11)) |
104 ((254 - pathA1) & (1 << 10))) >> 10;
105 vis_pst_32(fgARGB, dst_ptr + i, msk);
106 }
107
108 if (i < width) {
109 pathA0 = pMask[i];
110
111 if (pathA0 == 0xff) {
112 dst_ptr[i] = vis_read_hi(fgARGB);
113 } else if (pathA0) {
114 dstA0 = *(mlib_u8*)(dst_ptr + i);
115 dstARGB0 = dst_ptr[i];
116 MASK_FILL(res0, pathA0, dstA0, dstARGB0);
117 dst_ptr[i] = vis_fpack16(res0);
118 *(mlib_u8*)(dst_ptr + i) = dstA0;
119 }
120 }
121}
122
123/***************************************************************/
124
125void ADD_SUFF(IntArgbSrcMaskFill)(void *rasBase,
126 jubyte *pMask,
127 jint maskOff,
128 jint maskScan,
129 jint width,
130 jint height,
131 jint fgColor,
132 SurfaceDataRasInfo *pRasInfo,
133 NativePrimitive *pPrim,
134 CompositeInfo *pCompInfo)
135{
136 mlib_s32 cnstA, cnstR, cnstG, cnstB;
137 mlib_s32 rasScan = pRasInfo->scanStride;
138 mlib_f32 cnstARGB0;
139 mlib_d64 fgARGB;
140 mlib_u8 *mul8_cnstA;
141 mlib_s32 j;
142
143 cnstA = (fgColor >> 24) & 0xff;
144 cnstR = (fgColor >> 16) & 0xff;
145 cnstG = (fgColor >> 8) & 0xff;
146 cnstB = (fgColor ) & 0xff;
147
148 if (cnstA == 0) {
149 fgColor = 0;
150 }
151
152 if (pMask == NULL) {
153 ADD_SUFF(AnyIntSetRect)(pRasInfo,
154 pRasInfo->bounds.x1, pRasInfo->bounds.y1,
155 pRasInfo->bounds.x2, pRasInfo->bounds.y2,
156 fgColor, pPrim, pCompInfo);
157 return;
158 }
159
160 mul8_cnstA = mul8table[cnstA];
161 if (cnstA != 0xff) {
162 cnstR = mul8_cnstA[cnstR];
163 cnstG = mul8_cnstA[cnstG];
164 cnstB = mul8_cnstA[cnstB];
165 }
166
167 cnstARGB0 = F32_FROM_U8x4(cnstA, cnstR, cnstG, cnstB);
168
169 fgARGB = vis_to_double_dup(fgColor);
170
171 pMask += maskOff;
172
173 if (rasScan == 4*width && maskScan == width) {
174 width *= height;
175 height = 1;
176 }
177
178 vis_write_gsr(7 << 3);
179
180 for (j = 0; j < height; j++) {
181 IntArgbSrcMaskFill_line(rasBase, pMask, width, fgARGB, cnstARGB0,
182 mul8_cnstA, (void*)mul8table);
183
184 PTR_ADD(rasBase, rasScan);
185 PTR_ADD(pMask, maskScan);
186 }
187}
188
189/***************************************************************/
190
191void ADD_SUFF(FourByteAbgrSrcMaskFill)(void *rasBase,
192 jubyte *pMask,
193 jint maskOff,
194 jint maskScan,
195 jint width,
196 jint height,
197 jint fgColor,
198 SurfaceDataRasInfo *pRasInfo,
199 NativePrimitive *pPrim,
200 CompositeInfo *pCompInfo)
201{
202 mlib_d64 buff[BUFF_SIZE/2];
203 void *pbuff = buff;
204 mlib_s32 cnstA, cnstR, cnstG, cnstB;
205 mlib_s32 rasScan = pRasInfo->scanStride;
206 mlib_f32 cnstARGB0;
207 mlib_d64 fgARGB;
208 mlib_u8 *mul8_cnstA;
209 mlib_s32 j;
210
211 cnstA = (mlib_u32)fgColor >> 24;
212 cnstR = (fgColor >> 16) & 0xff;
213 cnstG = (fgColor >> 8) & 0xff;
214 cnstB = (fgColor ) & 0xff;
215
216 if (pMask == NULL) {
217 if (cnstA == 0) {
218 fgColor = 0;
219 } else {
220 fgColor = (fgColor << 8) | cnstA;
221 }
222 ADD_SUFF(Any4ByteSetRect)(pRasInfo,
223 pRasInfo->bounds.x1, pRasInfo->bounds.y1,
224 pRasInfo->bounds.x2, pRasInfo->bounds.y2,
225 fgColor, pPrim, pCompInfo);
226 return;
227 }
228
229 mul8_cnstA = mul8table[cnstA];
230
231 if (cnstA == 0) {
232 fgColor = 0;
233 cnstR = cnstG = cnstB = 0;
234 } else {
235 fgColor = (cnstA << 24) | (cnstB << 16) | (cnstG << 8) | cnstR;
236 if (cnstA != 0xff) {
237 cnstR = mul8_cnstA[cnstR];
238 cnstG = mul8_cnstA[cnstG];
239 cnstB = mul8_cnstA[cnstB];
240 }
241 }
242
243 cnstARGB0 = F32_FROM_U8x4(cnstA, cnstB, cnstG, cnstR);
244
245 fgARGB = vis_to_double_dup(fgColor);
246
247 pMask += maskOff;
248
249 if (((mlib_s32)rasBase | rasScan) & 3) {
250 if (width > BUFF_SIZE) pbuff = mlib_malloc(width*sizeof(mlib_s32));
251 } else {
252 if (rasScan == 4*width && maskScan == width) {
253 width *= height;
254 height = 1;
255 }
256 }
257
258 vis_write_gsr(7 << 3);
259
260 for (j = 0; j < height; j++) {
261 if (!((mlib_s32)rasBase & 3)) {
262 IntArgbSrcMaskFill_line(rasBase, pMask, width, fgARGB, cnstARGB0,
263 mul8_cnstA, (void*)mul8table);
264 } else {
265 mlib_ImageCopy_na(rasBase, pbuff, width*sizeof(mlib_s32));
266 IntArgbSrcMaskFill_line(pbuff, pMask, width, fgARGB, cnstARGB0,
267 mul8_cnstA, (void*)mul8table);
268 mlib_ImageCopy_na(pbuff, rasBase, width*sizeof(mlib_s32));
269 }
270
271 PTR_ADD(rasBase, rasScan);
272 PTR_ADD(pMask, maskScan);
273 }
274
275 if (pbuff != buff) {
276 mlib_free(pbuff);
277 }
278}
279
280/***************************************************************/
281
282/* ##############################################################
283 * IntRgbSrcMaskFill()
284 * IntBgrSrcMaskFill()
285 */
286
287#undef MASK_FILL
288#define MASK_FILL(rr, pathA, dstA, dstARGB) \
289{ \
290 mlib_d64 t0, t1; \
291 \
292 dstA = 0xff - pathA; \
293 \
294 t0 = MUL8_VIS(cnstARGB0, pathA); \
295 t1 = MUL8_VIS(dstARGB, dstA); \
296 rr = vis_fpadd16(t0, t1); \
297 \
298 dstA = dstA + mul8_cnstA[pathA]; \
299 DIV_ALPHA_RGB(rr, dstA); \
300}
301
302/***************************************************************/
303
304static void IntRgbSrcMaskFill_line(mlib_f32 *dst_ptr,
305 mlib_u8 *pMask,
306 mlib_s32 width,
307 mlib_d64 fgARGB,
308 mlib_f32 cnstARGB0,
309 mlib_u8 *mul8_cnstA,
310 mlib_u8 *mul8_tbl)
311{
312 mlib_s32 i, i0;
313 mlib_s32 pathA0, pathA1, dstA0, dstA1, msk;
314 mlib_d64 res0, res1, dstARGB;
315 mlib_f32 dstARGB0;
316
317 i = i0 = 0;
318
319 if ((mlib_s32)dst_ptr & 7) {
320 pathA0 = pMask[i];
321
322 if (pathA0 == 0xff) {
323 dst_ptr[i] = vis_read_hi(fgARGB);
324 } else if (pathA0) {
325 dstARGB0 = dst_ptr[i];
326 MASK_FILL(res0, pathA0, dstA0, dstARGB0);
327 dst_ptr[i] = vis_fpack16(res0);
328 }
329
330 i0 = 1;
331 }
332
333#pragma pipeloop(0)
334 for (i = i0; i <= width - 2; i += 2) {
335 pathA0 = pMask[i];
336 pathA1 = pMask[i + 1];
337 dstARGB = *(mlib_d64*)(dst_ptr + i);
338
339 MASK_FILL(res0, pathA0, dstA0, vis_read_hi(dstARGB));
340 MASK_FILL(res1, pathA1, dstA1, vis_read_lo(dstARGB));
341
342 res0 = vis_fpack16_pair(res0, res1);
343
344 msk = (((-pathA0) & (1 << 11)) | ((-pathA1) & (1 << 10))) >> 10;
345 vis_pst_32(res0, dst_ptr + i, msk);
346
347 msk = (((254 - pathA0) & (1 << 11)) |
348 ((254 - pathA1) & (1 << 10))) >> 10;
349 vis_pst_32(fgARGB, dst_ptr + i, msk);
350 }
351
352 if (i < width) {
353 pathA0 = pMask[i];
354
355 if (pathA0 == 0xff) {
356 dst_ptr[i] = vis_read_hi(fgARGB);
357 } else if (pathA0) {
358 dstARGB0 = dst_ptr[i];
359 MASK_FILL(res0, pathA0, dstA0, dstARGB0);
360 dst_ptr[i] = vis_fpack16(res0);
361 }
362 }
363}
364
365/***************************************************************/
366
367void ADD_SUFF(IntRgbSrcMaskFill)(void *rasBase,
368 jubyte *pMask,
369 jint maskOff,
370 jint maskScan,
371 jint width,
372 jint height,
373 jint fgColor,
374 SurfaceDataRasInfo *pRasInfo,
375 NativePrimitive *pPrim,
376 CompositeInfo *pCompInfo)
377{
378 mlib_s32 cnstA, cnstR, cnstG, cnstB;
379 mlib_s32 rasScan = pRasInfo->scanStride;
380 mlib_f32 cnstARGB0;
381 mlib_d64 fgARGB;
382 mlib_u8 *mul8_cnstA;
383 mlib_s32 j;
384
385 cnstA = (fgColor >> 24) & 0xff;
386 cnstR = (fgColor >> 16) & 0xff;
387 cnstG = (fgColor >> 8) & 0xff;
388 cnstB = (fgColor ) & 0xff;
389
390 if (cnstA == 0) fgColor = 0;
391
392 if (pMask == NULL) {
393 ADD_SUFF(AnyIntSetRect)(pRasInfo,
394 pRasInfo->bounds.x1, pRasInfo->bounds.y1,
395 pRasInfo->bounds.x2, pRasInfo->bounds.y2,
396 fgColor, pPrim, pCompInfo);
397 return;
398 }
399
400 mul8_cnstA = mul8table[cnstA];
401 if (cnstA != 0xff) {
402 cnstR = mul8_cnstA[cnstR];
403 cnstG = mul8_cnstA[cnstG];
404 cnstB = mul8_cnstA[cnstB];
405 }
406
407 cnstARGB0 = F32_FROM_U8x4(cnstA, cnstR, cnstG, cnstB);
408
409 fgARGB = vis_to_double_dup(fgColor);
410
411 pMask += maskOff;
412
413 if (rasScan == 4*width && maskScan == width) {
414 width *= height;
415 height = 1;
416 }
417
418 vis_write_gsr(7 << 3);
419
420 for (j = 0; j < height; j++) {
421 IntRgbSrcMaskFill_line(rasBase, pMask, width, fgARGB, cnstARGB0,
422 mul8_cnstA, (void*)mul8table);
423
424 PTR_ADD(rasBase, rasScan);
425 PTR_ADD(pMask, maskScan);
426 }
427}
428
429/***************************************************************/
430
431void ADD_SUFF(IntBgrSrcMaskFill)(void *rasBase,
432 jubyte *pMask,
433 jint maskOff,
434 jint maskScan,
435 jint width,
436 jint height,
437 jint fgColor,
438 SurfaceDataRasInfo *pRasInfo,
439 NativePrimitive *pPrim,
440 CompositeInfo *pCompInfo)
441{
442 mlib_s32 cnstA, cnstR, cnstG, cnstB;
443 mlib_s32 rasScan = pRasInfo->scanStride;
444 mlib_f32 cnstARGB0;
445 mlib_d64 fgARGB;
446 mlib_u8 *mul8_cnstA;
447 mlib_s32 j;
448
449 cnstA = (fgColor >> 24) & 0xff;
450 cnstR = (fgColor >> 16) & 0xff;
451 cnstG = (fgColor >> 8) & 0xff;
452 cnstB = (fgColor ) & 0xff;
453
454 if (cnstA == 0) {
455 fgColor = 0;
456 } else {
457 fgColor = (cnstB << 16) | (cnstG << 8) | (cnstR);
458 }
459
460 if (pMask == NULL) {
461 ADD_SUFF(AnyIntSetRect)(pRasInfo,
462 pRasInfo->bounds.x1, pRasInfo->bounds.y1,
463 pRasInfo->bounds.x2, pRasInfo->bounds.y2,
464 fgColor, pPrim, pCompInfo);
465 return;
466 }
467
468 mul8_cnstA = mul8table[cnstA];
469 if (cnstA != 0xff) {
470 cnstR = mul8_cnstA[cnstR];
471 cnstG = mul8_cnstA[cnstG];
472 cnstB = mul8_cnstA[cnstB];
473 }
474
475 cnstARGB0 = F32_FROM_U8x4(cnstA, cnstB, cnstG, cnstR);
476
477 fgARGB = vis_to_double_dup(fgColor);
478
479 pMask += maskOff;
480
481 if (rasScan == 4*width && maskScan == width) {
482 width *= height;
483 height = 1;
484 }
485
486 vis_write_gsr(7 << 3);
487
488 for (j = 0; j < height; j++) {
489 IntRgbSrcMaskFill_line(rasBase, pMask, width, fgARGB, cnstARGB0,
490 mul8_cnstA, (void*)mul8table);
491
492 PTR_ADD(rasBase, rasScan);
493 PTR_ADD(pMask, maskScan);
494 }
495}
496
497/***************************************************************/
498
499void ADD_SUFF(ThreeByteBgrSrcMaskFill)(void *rasBase,
500 jubyte *pMask,
501 jint maskOff,
502 jint maskScan,
503 jint width,
504 jint height,
505 jint fgColor,
506 SurfaceDataRasInfo *pRasInfo,
507 NativePrimitive *pPrim,
508 CompositeInfo *pCompInfo)
509{
510 mlib_d64 buff[BUFF_SIZE/2];
511 void *pbuff = buff;
512 mlib_s32 cnstA, cnstR, cnstG, cnstB;
513 mlib_s32 rasScan = pRasInfo->scanStride;
514 mlib_f32 cnstARGB0;
515 mlib_d64 fgARGB;
516 mlib_u8 *mul8_cnstA;
517 mlib_s32 j;
518
519 cnstA = (fgColor >> 24) & 0xff;
520 cnstR = (fgColor >> 16) & 0xff;
521 cnstG = (fgColor >> 8) & 0xff;
522 cnstB = (fgColor ) & 0xff;
523
524 if (cnstA == 0) {
525 fgColor = 0;
526 }
527
528 if (pMask == NULL) {
529 ADD_SUFF(Any3ByteSetRect)(pRasInfo,
530 pRasInfo->bounds.x1, pRasInfo->bounds.y1,
531 pRasInfo->bounds.x2, pRasInfo->bounds.y2,
532 fgColor, pPrim, pCompInfo);
533 return;
534 }
535
536 mul8_cnstA = mul8table[cnstA];
537 if (cnstA != 0xff) {
538 cnstR = mul8_cnstA[cnstR];
539 cnstG = mul8_cnstA[cnstG];
540 cnstB = mul8_cnstA[cnstB];
541 }
542
543 cnstARGB0 = F32_FROM_U8x4(cnstA, cnstR, cnstG, cnstB);
544
545 fgARGB = vis_to_double_dup(fgColor);
546
547 pMask += maskOff;
548
549 if (width > BUFF_SIZE) pbuff = mlib_malloc(width*sizeof(mlib_s32));
550
551 vis_write_gsr(7 << 3);
552
553 for (j = 0; j < height; j++) {
554 ADD_SUFF(ThreeByteBgrToIntArgbConvert)(rasBase, pbuff, width, 1,
555 pRasInfo, pRasInfo,
556 pPrim, pCompInfo);
557
558 IntRgbSrcMaskFill_line(pbuff, pMask, width, fgARGB, cnstARGB0,
559 mul8_cnstA, (void*)mul8table);
560
561 IntArgbToThreeByteBgrConvert(pbuff, rasBase, width, 1,
562 pRasInfo, pRasInfo, pPrim, pCompInfo);
563
564 PTR_ADD(rasBase, rasScan);
565 PTR_ADD(pMask, maskScan);
566 }
567
568 if (pbuff != buff) {
569 mlib_free(pbuff);
570 }
571}
572
573/***************************************************************/
574
575#endif