vis_SrcMaskFill.c revision 0
2407N/A/*
2407N/A * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
2407N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2407N/A *
2407N/A * This code is free software; you can redistribute it and/or modify it
2407N/A * under the terms of the GNU General Public License version 2 only, as
2407N/A * published by the Free Software Foundation. Sun designates this
2407N/A * particular file as subject to the "Classpath" exception as provided
2407N/A * by Sun in the LICENSE file that accompanied this code.
2407N/A *
2407N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2407N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2407N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2407N/A * version 2 for more details (a copy is included in the LICENSE file that
2407N/A * accompanied this code).
2407N/A *
2407N/A * You should have received a copy of the GNU General Public License version
2407N/A * 2 along with this work; if not, write to the Free Software Foundation,
2407N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2407N/A *
2407N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
2407N/A * CA 95054 USA or visit www.sun.com if you need additional information or
2407N/A * have any questions.
2407N/A */
2407N/A
2407N/A#if !defined(JAVA2D_NO_MLIB) || defined(MLIB_ADD_SUFF)
2407N/A
2407N/A#include <vis_AlphaMacros.h>
2644N/A
2407N/A/***************************************************************/
2407N/A
2407N/A/* ##############################################################
2412N/A * IntArgbSrcMaskFill()
2412N/A * FourByteAbgrSrcMaskFill()
2407N/A */
2407N/A
2407N/A#define MASK_FILL(rr, pathA, dstA, dstARGB) \
2407N/A{ \
2407N/A mlib_d64 t0, t1; \
2407N/A \
2407N/A dstA = MUL8_INT(dstA, 0xff - pathA); \
2407N/A \
2407N/A t0 = MUL8_VIS(cnstARGB0, pathA); \
2407N/A t1 = MUL8_VIS(dstARGB, dstA); \
2500N/A rr = vis_fpadd16(t0, t1); \
2500N/A \
2500N/A dstA = dstA + mul8_cnstA[pathA]; \
2644N/A DIV_ALPHA(rr, dstA); \
2644N/A}
2644N/A
2644N/A/***************************************************************/
2644N/A
2644N/Astatic void IntArgbSrcMaskFill_line(mlib_f32 *dst_ptr,
2535N/A mlib_u8 *pMask,
2535N/A mlib_s32 width,
2535N/A mlib_d64 fgARGB,
2407N/A mlib_f32 cnstARGB0,
2407N/A mlib_u8 *mul8_cnstA,
2407N/A mlib_u8 *mul8_tbl)
2407N/A{
2500N/A mlib_s32 i, i0;
2500N/A mlib_s32 pathA0, pathA1, dstA0, dstA1, msk;
2500N/A mlib_d64 res0, res1, dstARGB;
2500N/A mlib_f32 dstARGB0;
2500N/A
2500N/A i = i0 = 0;
2407N/A
2407N/A if ((mlib_s32)dst_ptr & 7) {
2407N/A pathA0 = pMask[i];
2407N/A
2407N/A if (pathA0 == 0xff) {
2407N/A dst_ptr[i] = vis_read_hi(fgARGB);
2407N/A } else if (pathA0) {
2407N/A dstA0 = *(mlib_u8*)(dst_ptr + i);
2407N/A dstARGB0 = dst_ptr[i];
2407N/A MASK_FILL(res0, pathA0, dstA0, dstARGB0);
2407N/A dst_ptr[i] = vis_fpack16(res0);
2407N/A *(mlib_u8*)(dst_ptr + i) = dstA0;
2407N/A }
2407N/A
2407N/A i0 = 1;
2407N/A }
2407N/A
2407N/A#pragma pipeloop(0)
2407N/A for (i = i0; i <= width - 2; i += 2) {
2407N/A pathA0 = pMask[i];
2407N/A pathA1 = pMask[i + 1];
2407N/A dstA0 = *(mlib_u8*)(dst_ptr + i);
2407N/A dstA1 = *(mlib_u8*)(dst_ptr + i + 1);
2501N/A dstARGB = *(mlib_d64*)(dst_ptr + i);
2501N/A
2407N/A MASK_FILL(res0, pathA0, dstA0, vis_read_hi(dstARGB));
2407N/A MASK_FILL(res1, pathA1, dstA1, vis_read_lo(dstARGB));
2407N/A
2644N/A res0 = vis_fpack16_pair(res0, res1);
2407N/A
2644N/A msk = (((-pathA0) & (1 << 11)) | ((-pathA1) & (1 << 10))) >> 10;
2644N/A vis_pst_32(res0, dst_ptr + i, msk);
2644N/A
2644N/A *(mlib_u8*)(dst_ptr + i ) = dstA0;
2644N/A *(mlib_u8*)(dst_ptr + i + 1) = dstA1;
2644N/A
2644N/A msk = (((254 - pathA0) & (1 << 11)) |
2407N/A ((254 - pathA1) & (1 << 10))) >> 10;
2644N/A vis_pst_32(fgARGB, dst_ptr + i, msk);
2644N/A }
2644N/A
2644N/A if (i < width) {
2407N/A pathA0 = pMask[i];
2407N/A
2412N/A if (pathA0 == 0xff) {
2412N/A dst_ptr[i] = vis_read_hi(fgARGB);
2412N/A } else if (pathA0) {
2412N/A dstA0 = *(mlib_u8*)(dst_ptr + i);
2412N/A dstARGB0 = dst_ptr[i];
2412N/A MASK_FILL(res0, pathA0, dstA0, dstARGB0);
2412N/A dst_ptr[i] = vis_fpack16(res0);
2412N/A *(mlib_u8*)(dst_ptr + i) = dstA0;
2407N/A }
2500N/A }
2500N/A}
2500N/A
2500N/A/***************************************************************/
2500N/A
2500N/Avoid ADD_SUFF(IntArgbSrcMaskFill)(void *rasBase,
2500N/A jubyte *pMask,
2500N/A jint maskOff,
2500N/A jint maskScan,
2500N/A jint width,
2500N/A jint height,
2500N/A jint fgColor,
2500N/A SurfaceDataRasInfo *pRasInfo,
2500N/A NativePrimitive *pPrim,
2500N/A CompositeInfo *pCompInfo)
2500N/A{
2500N/A mlib_s32 cnstA, cnstR, cnstG, cnstB;
2500N/A mlib_s32 rasScan = pRasInfo->scanStride;
2500N/A mlib_f32 cnstARGB0;
2500N/A mlib_d64 fgARGB;
2500N/A mlib_u8 *mul8_cnstA;
2500N/A mlib_s32 j;
2500N/A
2500N/A cnstA = (fgColor >> 24) & 0xff;
2500N/A cnstR = (fgColor >> 16) & 0xff;
2500N/A cnstG = (fgColor >> 8) & 0xff;
2500N/A cnstB = (fgColor ) & 0xff;
2500N/A
2500N/A if (cnstA == 0) {
2500N/A fgColor = 0;
2500N/A }
2500N/A
2500N/A if (pMask == NULL) {
2500N/A ADD_SUFF(AnyIntSetRect)(pRasInfo,
2500N/A pRasInfo->bounds.x1, pRasInfo->bounds.y1,
2500N/A pRasInfo->bounds.x2, pRasInfo->bounds.y2,
2500N/A fgColor, pPrim, pCompInfo);
2500N/A return;
2500N/A }
2500N/A
2500N/A mul8_cnstA = mul8table[cnstA];
2500N/A if (cnstA != 0xff) {
2500N/A cnstR = mul8_cnstA[cnstR];
2500N/A cnstG = mul8_cnstA[cnstG];
2500N/A cnstB = mul8_cnstA[cnstB];
2500N/A }
2500N/A
2500N/A cnstARGB0 = F32_FROM_U8x4(cnstA, cnstR, cnstG, cnstB);
2500N/A
2500N/A fgARGB = vis_to_double_dup(fgColor);
2500N/A
2500N/A pMask += maskOff;
2500N/A
2500N/A if (rasScan == 4*width && maskScan == width) {
2500N/A width *= height;
2500N/A height = 1;
2500N/A }
2500N/A
2500N/A vis_write_gsr(7 << 3);
2500N/A
2500N/A for (j = 0; j < height; j++) {
2500N/A IntArgbSrcMaskFill_line(rasBase, pMask, width, fgARGB, cnstARGB0,
2500N/A mul8_cnstA, (void*)mul8table);
2500N/A
2500N/A PTR_ADD(rasBase, rasScan);
2500N/A PTR_ADD(pMask, maskScan);
2500N/A }
2500N/A}
2500N/A
2500N/A/***************************************************************/
2500N/A
2500N/Avoid ADD_SUFF(FourByteAbgrSrcMaskFill)(void *rasBase,
2500N/A jubyte *pMask,
2500N/A jint maskOff,
2500N/A jint maskScan,
2500N/A jint width,
2500N/A jint height,
2500N/A jint fgColor,
2500N/A SurfaceDataRasInfo *pRasInfo,
2500N/A NativePrimitive *pPrim,
2500N/A CompositeInfo *pCompInfo)
2500N/A{
2500N/A mlib_d64 buff[BUFF_SIZE/2];
2500N/A void *pbuff = buff;
2500N/A mlib_s32 cnstA, cnstR, cnstG, cnstB;
2500N/A mlib_s32 rasScan = pRasInfo->scanStride;
2500N/A mlib_f32 cnstARGB0;
2500N/A mlib_d64 fgARGB;
2500N/A mlib_u8 *mul8_cnstA;
2500N/A mlib_s32 j;
2500N/A
2500N/A cnstA = (mlib_u32)fgColor >> 24;
2564N/A cnstR = (fgColor >> 16) & 0xff;
2564N/A cnstG = (fgColor >> 8) & 0xff;
2500N/A cnstB = (fgColor ) & 0xff;
2500N/A
2500N/A if (pMask == NULL) {
2500N/A if (cnstA == 0) {
2500N/A fgColor = 0;
2500N/A } else {
2500N/A fgColor = (fgColor << 8) | cnstA;
2500N/A }
2500N/A ADD_SUFF(Any4ByteSetRect)(pRasInfo,
2500N/A pRasInfo->bounds.x1, pRasInfo->bounds.y1,
2500N/A pRasInfo->bounds.x2, pRasInfo->bounds.y2,
2500N/A fgColor, pPrim, pCompInfo);
2500N/A return;
2500N/A }
2500N/A
2500N/A mul8_cnstA = mul8table[cnstA];
2500N/A
2500N/A if (cnstA == 0) {
2500N/A fgColor = 0;
2500N/A cnstR = cnstG = cnstB = 0;
2500N/A } else {
2500N/A fgColor = (cnstA << 24) | (cnstB << 16) | (cnstG << 8) | cnstR;
2500N/A if (cnstA != 0xff) {
2407N/A cnstR = mul8_cnstA[cnstR];
2407N/A cnstG = mul8_cnstA[cnstG];
2407N/A cnstB = mul8_cnstA[cnstB];
2407N/A }
2407N/A }
2407N/A
2407N/A cnstARGB0 = F32_FROM_U8x4(cnstA, cnstB, cnstG, cnstR);
2407N/A
2407N/A fgARGB = vis_to_double_dup(fgColor);
2407N/A
2407N/A pMask += maskOff;
2407N/A
2407N/A if (((mlib_s32)rasBase | rasScan) & 3) {
2407N/A if (width > BUFF_SIZE) pbuff = mlib_malloc(width*sizeof(mlib_s32));
2407N/A } else {
2407N/A if (rasScan == 4*width && maskScan == width) {
2407N/A width *= height;
2407N/A height = 1;
2407N/A }
2407N/A }
2407N/A
2407N/A vis_write_gsr(7 << 3);
2407N/A
2407N/A for (j = 0; j < height; j++) {
2407N/A if (!((mlib_s32)rasBase & 3)) {
2407N/A IntArgbSrcMaskFill_line(rasBase, pMask, width, fgARGB, cnstARGB0,
2407N/A mul8_cnstA, (void*)mul8table);
2407N/A } else {
2407N/A mlib_ImageCopy_na(rasBase, pbuff, width*sizeof(mlib_s32));
2407N/A IntArgbSrcMaskFill_line(pbuff, pMask, width, fgARGB, cnstARGB0,
2407N/A mul8_cnstA, (void*)mul8table);
2407N/A mlib_ImageCopy_na(pbuff, rasBase, width*sizeof(mlib_s32));
2407N/A }
2407N/A
2407N/A PTR_ADD(rasBase, rasScan);
2407N/A PTR_ADD(pMask, maskScan);
2407N/A }
2407N/A
2407N/A if (pbuff != buff) {
2407N/A mlib_free(pbuff);
2407N/A }
2407N/A}
2407N/A
2407N/A/***************************************************************/
2407N/A
2407N/A/* ##############################################################
2407N/A * IntRgbSrcMaskFill()
2407N/A * IntBgrSrcMaskFill()
2407N/A */
2407N/A
2407N/A#undef MASK_FILL
#define MASK_FILL(rr, pathA, dstA, dstARGB) \
{ \
mlib_d64 t0, t1; \
\
dstA = 0xff - pathA; \
\
t0 = MUL8_VIS(cnstARGB0, pathA); \
t1 = MUL8_VIS(dstARGB, dstA); \
rr = vis_fpadd16(t0, t1); \
\
dstA = dstA + mul8_cnstA[pathA]; \
DIV_ALPHA_RGB(rr, dstA); \
}
/***************************************************************/
static void IntRgbSrcMaskFill_line(mlib_f32 *dst_ptr,
mlib_u8 *pMask,
mlib_s32 width,
mlib_d64 fgARGB,
mlib_f32 cnstARGB0,
mlib_u8 *mul8_cnstA,
mlib_u8 *mul8_tbl)
{
mlib_s32 i, i0;
mlib_s32 pathA0, pathA1, dstA0, dstA1, msk;
mlib_d64 res0, res1, dstARGB;
mlib_f32 dstARGB0;
i = i0 = 0;
if ((mlib_s32)dst_ptr & 7) {
pathA0 = pMask[i];
if (pathA0 == 0xff) {
dst_ptr[i] = vis_read_hi(fgARGB);
} else if (pathA0) {
dstARGB0 = dst_ptr[i];
MASK_FILL(res0, pathA0, dstA0, dstARGB0);
dst_ptr[i] = vis_fpack16(res0);
}
i0 = 1;
}
#pragma pipeloop(0)
for (i = i0; i <= width - 2; i += 2) {
pathA0 = pMask[i];
pathA1 = pMask[i + 1];
dstARGB = *(mlib_d64*)(dst_ptr + i);
MASK_FILL(res0, pathA0, dstA0, vis_read_hi(dstARGB));
MASK_FILL(res1, pathA1, dstA1, vis_read_lo(dstARGB));
res0 = vis_fpack16_pair(res0, res1);
msk = (((-pathA0) & (1 << 11)) | ((-pathA1) & (1 << 10))) >> 10;
vis_pst_32(res0, dst_ptr + i, msk);
msk = (((254 - pathA0) & (1 << 11)) |
((254 - pathA1) & (1 << 10))) >> 10;
vis_pst_32(fgARGB, dst_ptr + i, msk);
}
if (i < width) {
pathA0 = pMask[i];
if (pathA0 == 0xff) {
dst_ptr[i] = vis_read_hi(fgARGB);
} else if (pathA0) {
dstARGB0 = dst_ptr[i];
MASK_FILL(res0, pathA0, dstA0, dstARGB0);
dst_ptr[i] = vis_fpack16(res0);
}
}
}
/***************************************************************/
void ADD_SUFF(IntRgbSrcMaskFill)(void *rasBase,
jubyte *pMask,
jint maskOff,
jint maskScan,
jint width,
jint height,
jint fgColor,
SurfaceDataRasInfo *pRasInfo,
NativePrimitive *pPrim,
CompositeInfo *pCompInfo)
{
mlib_s32 cnstA, cnstR, cnstG, cnstB;
mlib_s32 rasScan = pRasInfo->scanStride;
mlib_f32 cnstARGB0;
mlib_d64 fgARGB;
mlib_u8 *mul8_cnstA;
mlib_s32 j;
cnstA = (fgColor >> 24) & 0xff;
cnstR = (fgColor >> 16) & 0xff;
cnstG = (fgColor >> 8) & 0xff;
cnstB = (fgColor ) & 0xff;
if (cnstA == 0) fgColor = 0;
if (pMask == NULL) {
ADD_SUFF(AnyIntSetRect)(pRasInfo,
pRasInfo->bounds.x1, pRasInfo->bounds.y1,
pRasInfo->bounds.x2, pRasInfo->bounds.y2,
fgColor, pPrim, pCompInfo);
return;
}
mul8_cnstA = mul8table[cnstA];
if (cnstA != 0xff) {
cnstR = mul8_cnstA[cnstR];
cnstG = mul8_cnstA[cnstG];
cnstB = mul8_cnstA[cnstB];
}
cnstARGB0 = F32_FROM_U8x4(cnstA, cnstR, cnstG, cnstB);
fgARGB = vis_to_double_dup(fgColor);
pMask += maskOff;
if (rasScan == 4*width && maskScan == width) {
width *= height;
height = 1;
}
vis_write_gsr(7 << 3);
for (j = 0; j < height; j++) {
IntRgbSrcMaskFill_line(rasBase, pMask, width, fgARGB, cnstARGB0,
mul8_cnstA, (void*)mul8table);
PTR_ADD(rasBase, rasScan);
PTR_ADD(pMask, maskScan);
}
}
/***************************************************************/
void ADD_SUFF(IntBgrSrcMaskFill)(void *rasBase,
jubyte *pMask,
jint maskOff,
jint maskScan,
jint width,
jint height,
jint fgColor,
SurfaceDataRasInfo *pRasInfo,
NativePrimitive *pPrim,
CompositeInfo *pCompInfo)
{
mlib_s32 cnstA, cnstR, cnstG, cnstB;
mlib_s32 rasScan = pRasInfo->scanStride;
mlib_f32 cnstARGB0;
mlib_d64 fgARGB;
mlib_u8 *mul8_cnstA;
mlib_s32 j;
cnstA = (fgColor >> 24) & 0xff;
cnstR = (fgColor >> 16) & 0xff;
cnstG = (fgColor >> 8) & 0xff;
cnstB = (fgColor ) & 0xff;
if (cnstA == 0) {
fgColor = 0;
} else {
fgColor = (cnstB << 16) | (cnstG << 8) | (cnstR);
}
if (pMask == NULL) {
ADD_SUFF(AnyIntSetRect)(pRasInfo,
pRasInfo->bounds.x1, pRasInfo->bounds.y1,
pRasInfo->bounds.x2, pRasInfo->bounds.y2,
fgColor, pPrim, pCompInfo);
return;
}
mul8_cnstA = mul8table[cnstA];
if (cnstA != 0xff) {
cnstR = mul8_cnstA[cnstR];
cnstG = mul8_cnstA[cnstG];
cnstB = mul8_cnstA[cnstB];
}
cnstARGB0 = F32_FROM_U8x4(cnstA, cnstB, cnstG, cnstR);
fgARGB = vis_to_double_dup(fgColor);
pMask += maskOff;
if (rasScan == 4*width && maskScan == width) {
width *= height;
height = 1;
}
vis_write_gsr(7 << 3);
for (j = 0; j < height; j++) {
IntRgbSrcMaskFill_line(rasBase, pMask, width, fgARGB, cnstARGB0,
mul8_cnstA, (void*)mul8table);
PTR_ADD(rasBase, rasScan);
PTR_ADD(pMask, maskScan);
}
}
/***************************************************************/
void ADD_SUFF(ThreeByteBgrSrcMaskFill)(void *rasBase,
jubyte *pMask,
jint maskOff,
jint maskScan,
jint width,
jint height,
jint fgColor,
SurfaceDataRasInfo *pRasInfo,
NativePrimitive *pPrim,
CompositeInfo *pCompInfo)
{
mlib_d64 buff[BUFF_SIZE/2];
void *pbuff = buff;
mlib_s32 cnstA, cnstR, cnstG, cnstB;
mlib_s32 rasScan = pRasInfo->scanStride;
mlib_f32 cnstARGB0;
mlib_d64 fgARGB;
mlib_u8 *mul8_cnstA;
mlib_s32 j;
cnstA = (fgColor >> 24) & 0xff;
cnstR = (fgColor >> 16) & 0xff;
cnstG = (fgColor >> 8) & 0xff;
cnstB = (fgColor ) & 0xff;
if (cnstA == 0) {
fgColor = 0;
}
if (pMask == NULL) {
ADD_SUFF(Any3ByteSetRect)(pRasInfo,
pRasInfo->bounds.x1, pRasInfo->bounds.y1,
pRasInfo->bounds.x2, pRasInfo->bounds.y2,
fgColor, pPrim, pCompInfo);
return;
}
mul8_cnstA = mul8table[cnstA];
if (cnstA != 0xff) {
cnstR = mul8_cnstA[cnstR];
cnstG = mul8_cnstA[cnstG];
cnstB = mul8_cnstA[cnstB];
}
cnstARGB0 = F32_FROM_U8x4(cnstA, cnstR, cnstG, cnstB);
fgARGB = vis_to_double_dup(fgColor);
pMask += maskOff;
if (width > BUFF_SIZE) pbuff = mlib_malloc(width*sizeof(mlib_s32));
vis_write_gsr(7 << 3);
for (j = 0; j < height; j++) {
ADD_SUFF(ThreeByteBgrToIntArgbConvert)(rasBase, pbuff, width, 1,
pRasInfo, pRasInfo,
pPrim, pCompInfo);
IntRgbSrcMaskFill_line(pbuff, pMask, width, fgARGB, cnstARGB0,
mul8_cnstA, (void*)mul8table);
IntArgbToThreeByteBgrConvert(pbuff, rasBase, width, 1,
pRasInfo, pRasInfo, pPrim, pCompInfo);
PTR_ADD(rasBase, rasScan);
PTR_ADD(pMask, maskScan);
}
if (pbuff != buff) {
mlib_free(pbuff);
}
}
/***************************************************************/
#endif