Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/java2d/loops/vis_SrcOverMaskFill.c
32288 views
/*1* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#if !defined(JAVA2D_NO_MLIB) || defined(MLIB_ADD_SUFF)2627#include <vis_AlphaMacros.h>2829/***************************************************************/3031/* ##############################################################32* IntArgbSrcOverMaskFill()33* FourByteAbgrSrcOverMaskFill()34*/3536#define MASK_FILL(rr, pathA, dstA, dstARGB) \37{ \38mlib_d64 t0, t1; \39mlib_s32 alp0; \40\41alp0 = mul8_cnstA[pathA]; \42dstA = MUL8_INT(dstA, 0xff - alp0); \43\44t0 = MUL8_VIS(cnstARGB0, pathA); \45t1 = MUL8_VIS(dstARGB, dstA); \46rr = vis_fpadd16(t0, t1); \47\48dstA = dstA + alp0; \49DIV_ALPHA(rr, dstA); \50}5152/***************************************************************/5354static void IntArgbSrcOverMaskFill_line(mlib_f32 *dst_ptr,55mlib_u8 *pMask,56mlib_s32 width,57mlib_f32 cnstARGB0,58mlib_u8 *mul8_cnstA,59mlib_u8 *mul8_tbl)60{61mlib_s32 i, i0;62mlib_s32 pathA0, pathA1, dstA0, dstA1, msk;63mlib_d64 res0, res1, dstARGB;64mlib_f32 dstARGB0;6566i = i0 = 0;6768if ((mlib_s32)dst_ptr & 7) {69pathA0 = pMask[i];7071if (pathA0) {72dstA0 = *(mlib_u8*)(dst_ptr + i);73dstARGB0 = dst_ptr[i];74MASK_FILL(res0, pathA0, dstA0, dstARGB0);75dst_ptr[i] = vis_fpack16(res0);76*(mlib_u8*)(dst_ptr + i) = dstA0;77}7879i0 = 1;80}8182#pragma pipeloop(0)83for (i = i0; i <= width - 2; i += 2) {84pathA0 = pMask[i];85pathA1 = pMask[i + 1];86dstA0 = *(mlib_u8*)(dst_ptr + i);87dstA1 = *(mlib_u8*)(dst_ptr + i + 1);88dstARGB = *(mlib_d64*)(dst_ptr + i);8990MASK_FILL(res0, pathA0, dstA0, vis_read_hi(dstARGB));91MASK_FILL(res1, pathA1, dstA1, vis_read_lo(dstARGB));9293res0 = vis_fpack16_pair(res0, res1);9495msk = (((-pathA0) & (1 << 11)) | ((-pathA1) & (1 << 10))) >> 10;96vis_pst_32(res0, dst_ptr + i, msk);9798*(mlib_u8*)(dst_ptr + i ) = dstA0;99*(mlib_u8*)(dst_ptr + i + 1) = dstA1;100}101102if (i < width) {103pathA0 = pMask[i];104105if (pathA0) {106dstA0 = *(mlib_u8*)(dst_ptr + i);107dstARGB0 = dst_ptr[i];108MASK_FILL(res0, pathA0, dstA0, dstARGB0);109dst_ptr[i] = vis_fpack16(res0);110*(mlib_u8*)(dst_ptr + i) = dstA0;111}112}113}114115/***************************************************************/116117#undef MASK_FILL118#define MASK_FILL(rr, pathA, dstA, dstARGB) \119{ \120dstA = mul8_cnstA[dstA]; \121\122rr = MUL8_VIS(dstARGB, dstA); \123rr = vis_fpadd16(rr, cnstARGB); \124\125dstA = dstA + cnstA; \126DIV_ALPHA(rr, dstA); \127}128129/***************************************************************/130131static void IntArgbSrcOverMaskFill_A1_line(mlib_f32 *dst_ptr,132mlib_u8 *pMask,133mlib_s32 width,134mlib_d64 cnstARGB,135mlib_s32 cnstA,136mlib_u8 *mul8_cnstA,137mlib_u8 *mul8_tbl)138{139mlib_s32 i, i0;140mlib_s32 dstA0, dstA1;141mlib_d64 res0, res1, dstARGB;142mlib_f32 dstARGB0;143144i = i0 = 0;145146if ((mlib_s32)dst_ptr & 7) {147{148dstA0 = *(mlib_u8*)(dst_ptr + i);149dstARGB0 = dst_ptr[i];150MASK_FILL(res0, pathA0, dstA0, dstARGB0);151dst_ptr[i] = vis_fpack16(res0);152*(mlib_u8*)(dst_ptr + i) = dstA0;153}154155i0 = 1;156}157158#pragma pipeloop(0)159for (i = i0; i <= width - 2; i += 2) {160dstA0 = *(mlib_u8*)(dst_ptr + i);161dstA1 = *(mlib_u8*)(dst_ptr + i + 1);162dstARGB = *(mlib_d64*)(dst_ptr + i);163164MASK_FILL(res0, pathA0, dstA0, vis_read_hi(dstARGB));165MASK_FILL(res1, pathA1, dstA1, vis_read_lo(dstARGB));166167res0 = vis_fpack16_pair(res0, res1);168169*(mlib_d64*)(dst_ptr + i) = res0;170171*(mlib_u8*)(dst_ptr + i ) = dstA0;172*(mlib_u8*)(dst_ptr + i + 1) = dstA1;173}174175if (i < width) {176{177dstA0 = *(mlib_u8*)(dst_ptr + i);178dstARGB0 = dst_ptr[i];179MASK_FILL(res0, pathA0, dstA0, dstARGB0);180dst_ptr[i] = vis_fpack16(res0);181*(mlib_u8*)(dst_ptr + i) = dstA0;182}183}184}185186/***************************************************************/187188void ADD_SUFF(IntArgbSrcOverMaskFill)(void *rasBase,189jubyte *pMask,190jint maskOff,191jint maskScan,192jint width,193jint height,194jint fgColor,195SurfaceDataRasInfo *pRasInfo,196NativePrimitive *pPrim,197CompositeInfo *pCompInfo)198{199mlib_s32 cnstA, cnstR, cnstG, cnstB;200mlib_s32 rasScan = pRasInfo->scanStride;201mlib_f32 cnstARGB0;202mlib_d64 cnstARGB;203mlib_u8 *mul8_cnstA;204mlib_s32 j;205206cnstA = (fgColor >> 24) & 0xff;207cnstR = (fgColor >> 16) & 0xff;208cnstG = (fgColor >> 8) & 0xff;209cnstB = (fgColor ) & 0xff;210211if (cnstA != 0xff) {212if (cnstA == 0) return;213214cnstR = mul8table[cnstA][cnstR];215cnstG = mul8table[cnstA][cnstG];216cnstB = mul8table[cnstA][cnstB];217}218219vis_write_gsr(7 << 3);220221if (pMask != NULL) {222pMask += maskOff;223224if (rasScan == 4*width && maskScan == width) {225width *= height;226height = 1;227}228229mul8_cnstA = mul8table[cnstA];230231cnstARGB0 = F32_FROM_U8x4(cnstA, cnstR, cnstG, cnstB);232233for (j = 0; j < height; j++) {234IntArgbSrcOverMaskFill_line(rasBase, pMask, width, cnstARGB0,235mul8_cnstA, (void*)mul8table);236237PTR_ADD(rasBase, rasScan);238PTR_ADD(pMask, maskScan);239}240} else {241if (rasScan == 4*width) {242width *= height;243height = 1;244}245246mul8_cnstA = mul8table[255 - cnstA];247248cnstARGB = vis_to_double((cnstA << 23) | (cnstR << 7),249(cnstG << 23) | (cnstB << 7));250251for (j = 0; j < height; j++) {252IntArgbSrcOverMaskFill_A1_line(rasBase, pMask, width, cnstARGB,253cnstA,mul8_cnstA, (void*)mul8table);254255PTR_ADD(rasBase, rasScan);256}257}258}259260/***************************************************************/261262void ADD_SUFF(FourByteAbgrSrcOverMaskFill)(void *rasBase,263jubyte *pMask,264jint maskOff,265jint maskScan,266jint width,267jint height,268jint fgColor,269SurfaceDataRasInfo *pRasInfo,270NativePrimitive *pPrim,271CompositeInfo *pCompInfo)272{273mlib_d64 buff[BUFF_SIZE/2];274void *pbuff = buff;275mlib_s32 cnstA, cnstR, cnstG, cnstB;276mlib_s32 rasScan = pRasInfo->scanStride;277mlib_f32 cnstARGB0;278mlib_d64 cnstARGB;279mlib_u8 *mul8_cnstA;280mlib_s32 j;281282cnstA = (mlib_u32)fgColor >> 24;283cnstR = (fgColor >> 16) & 0xff;284cnstG = (fgColor >> 8) & 0xff;285cnstB = (fgColor ) & 0xff;286287if (cnstA != 0xff) {288if (cnstA == 0) return;289290cnstR = mul8table[cnstA][cnstR];291cnstG = mul8table[cnstA][cnstG];292cnstB = mul8table[cnstA][cnstB];293}294295vis_write_gsr(7 << 3);296297if (pMask != NULL) {298pMask += maskOff;299300if (((mlib_s32)rasBase | rasScan) & 3) {301if (width > BUFF_SIZE) pbuff = mlib_malloc(width*sizeof(mlib_s32));302} else {303if (rasScan == 4*width && maskScan == width) {304width *= height;305height = 1;306}307}308309mul8_cnstA = mul8table[cnstA];310311cnstARGB0 = F32_FROM_U8x4(cnstA, cnstB, cnstG, cnstR);312313for (j = 0; j < height; j++) {314if (!((mlib_s32)rasBase & 3)) {315IntArgbSrcOverMaskFill_line(rasBase, pMask, width, cnstARGB0,316mul8_cnstA, (void*)mul8table);317} else {318mlib_ImageCopy_na(rasBase, pbuff, width*sizeof(mlib_s32));319IntArgbSrcOverMaskFill_line(pbuff, pMask, width, cnstARGB0,320mul8_cnstA, (void*)mul8table);321mlib_ImageCopy_na(pbuff, rasBase, width*sizeof(mlib_s32));322}323324PTR_ADD(rasBase, rasScan);325PTR_ADD(pMask, maskScan);326}327} else {328if (((mlib_s32)rasBase | rasScan) & 3) {329if (width > BUFF_SIZE) pbuff = mlib_malloc(width*sizeof(mlib_s32));330} else {331if (rasScan == 4*width) {332width *= height;333height = 1;334}335}336337mul8_cnstA = mul8table[255 - cnstA];338339cnstARGB = vis_to_double((cnstA << 23) | (cnstB << 7),340(cnstG << 23) | (cnstR << 7));341342for (j = 0; j < height; j++) {343if (!((mlib_s32)rasBase & 3)) {344IntArgbSrcOverMaskFill_A1_line(rasBase, pMask, width, cnstARGB,345cnstA, mul8_cnstA,346(void*)mul8table);347} else {348mlib_ImageCopy_na(rasBase, pbuff, width*sizeof(mlib_s32));349IntArgbSrcOverMaskFill_A1_line(pbuff, pMask, width, cnstARGB,350cnstA, mul8_cnstA,351(void*)mul8table);352mlib_ImageCopy_na(pbuff, rasBase, width*sizeof(mlib_s32));353}354355PTR_ADD(rasBase, rasScan);356}357}358359if (pbuff != buff) {360mlib_free(pbuff);361}362}363364/***************************************************************/365366/* ##############################################################367* IntRgbSrcOverMaskFill()368* IntBgrSrcOverMaskFill()369*/370371#undef MASK_FILL372#define MASK_FILL(rr, pathA, dstA, dstARGB) \373{ \374mlib_d64 t0, t1; \375mlib_s32 srcA; \376\377srcA = mul8_cnstA[pathA]; \378dstA = 0xff - srcA; \379\380t0 = MUL8_VIS(cnstARGB0, pathA); \381t1 = MUL8_VIS(dstARGB, dstA); \382rr = vis_fpadd16(t0, t1); \383rr = vis_fand(rr, maskRGB); \384}385386/***************************************************************/387388static void IntRgbSrcOverMaskFill_line(mlib_f32 *dst_ptr,389mlib_u8 *pMask,390mlib_s32 width,391mlib_f32 cnstARGB0,392mlib_u8 *mul8_cnstA,393mlib_u8 *mul8_tbl)394{395mlib_s32 i, i0;396mlib_s32 pathA0, pathA1, dstA0, dstA1, msk;397mlib_d64 res0, res1, dstARGB;398mlib_f32 dstARGB0;399/*mlib_d64 maskRGB = vis_to_double_dup(0x00FFFFFF);*/400mlib_d64 maskRGB = vis_to_double(0x0000FFFF, 0xFFFFFFFF);401402i = i0 = 0;403404if ((mlib_s32)dst_ptr & 7) {405pathA0 = pMask[i];406407if (pathA0) {408dstARGB0 = dst_ptr[i];409MASK_FILL(res0, pathA0, dstA0, dstARGB0);410dst_ptr[i] = vis_fpack16(res0);411}412413i0 = 1;414}415416#pragma pipeloop(0)417for (i = i0; i <= width - 2; i += 2) {418pathA0 = pMask[i];419pathA1 = pMask[i + 1];420dstARGB = *(mlib_d64*)(dst_ptr + i);421422MASK_FILL(res0, pathA0, dstA0, vis_read_hi(dstARGB));423MASK_FILL(res1, pathA1, dstA1, vis_read_lo(dstARGB));424425res0 = vis_fpack16_pair(res0, res1);426427msk = (((-pathA0) & (1 << 11)) | ((-pathA1) & (1 << 10))) >> 10;428vis_pst_32(res0, dst_ptr + i, msk);429}430431if (i < width) {432pathA0 = pMask[i];433434if (pathA0) {435dstARGB0 = dst_ptr[i];436MASK_FILL(res0, pathA0, dstA0, dstARGB0);437dst_ptr[i] = vis_fpack16(res0);438}439}440}441442/***************************************************************/443444#undef MASK_FILL445#define MASK_FILL(rr, pathA, dstA, dstARGB) \446{ \447rr = MUL8_VIS(dstARGB, cnstA); \448rr = vis_fpadd16(rr, cnstARGB); \449rr = vis_fand(rr, maskRGB); \450}451452/***************************************************************/453454static void IntRgbSrcOverMaskFill_A1_line(mlib_f32 *dst_ptr,455mlib_u8 *pMask,456mlib_s32 width,457mlib_d64 cnstARGB,458mlib_s32 cnstA,459mlib_u8 *mul8_tbl)460{461mlib_s32 i, i0;462mlib_d64 res0, res1, dstARGB;463mlib_f32 dstARGB0;464mlib_d64 maskRGB = vis_to_double(0x0000FFFF, 0xFFFFFFFF);465466i = i0 = 0;467468if ((mlib_s32)dst_ptr & 7) {469dstARGB0 = dst_ptr[i];470MASK_FILL(res0, pathA0, dstA0, dstARGB0);471dst_ptr[i] = vis_fpack16(res0);472473i0 = 1;474}475476#pragma pipeloop(0)477for (i = i0; i <= width - 2; i += 2) {478dstARGB = *(mlib_d64*)(dst_ptr + i);479480MASK_FILL(res0, pathA0, dstA0, vis_read_hi(dstARGB));481MASK_FILL(res1, pathA1, dstA1, vis_read_lo(dstARGB));482483res0 = vis_fpack16_pair(res0, res1);484485*(mlib_d64*)(dst_ptr + i) = res0;486}487488if (i < width) {489dstARGB0 = dst_ptr[i];490MASK_FILL(res0, pathA0, dstA0, dstARGB0);491dst_ptr[i] = vis_fpack16(res0);492}493}494495/***************************************************************/496497void ADD_SUFF(IntRgbSrcOverMaskFill)(void *rasBase,498jubyte *pMask,499jint maskOff,500jint maskScan,501jint width,502jint height,503jint fgColor,504SurfaceDataRasInfo *pRasInfo,505NativePrimitive *pPrim,506CompositeInfo *pCompInfo)507{508mlib_s32 cnstA, cnstR, cnstG, cnstB;509mlib_s32 rasScan = pRasInfo->scanStride;510mlib_f32 cnstARGB0;511mlib_d64 cnstARGB;512mlib_u8 *mul8_cnstA;513mlib_s32 j;514515cnstA = (fgColor >> 24) & 0xff;516cnstR = (fgColor >> 16) & 0xff;517cnstG = (fgColor >> 8) & 0xff;518cnstB = (fgColor ) & 0xff;519520if (cnstA != 0xff) {521if (cnstA == 0) return;522523cnstR = mul8table[cnstA][cnstR];524cnstG = mul8table[cnstA][cnstG];525cnstB = mul8table[cnstA][cnstB];526}527528vis_write_gsr(0 << 3);529530if (pMask != NULL) {531pMask += maskOff;532533if (rasScan == 4*width && maskScan == width) {534width *= height;535height = 1;536}537538mul8_cnstA = mul8table[cnstA];539540cnstARGB0 = F32_FROM_U8x4(cnstA, cnstR, cnstG, cnstB);541542for (j = 0; j < height; j++) {543IntRgbSrcOverMaskFill_line(rasBase, pMask, width, cnstARGB0,544mul8_cnstA, (void*)mul8table);545546PTR_ADD(rasBase, rasScan);547PTR_ADD(pMask, maskScan);548}549} else {550if (rasScan == 4*width) {551width *= height;552height = 1;553}554555cnstARGB = vis_to_double((cnstR << 7), (cnstG << 23) | (cnstB << 7));556557cnstA = 255 - cnstA;558559for (j = 0; j < height; j++) {560IntRgbSrcOverMaskFill_A1_line(rasBase, pMask, width, cnstARGB,561cnstA, (void*)mul8table);562563PTR_ADD(rasBase, rasScan);564}565}566}567568/***************************************************************/569570void ADD_SUFF(IntBgrSrcOverMaskFill)(void *rasBase,571jubyte *pMask,572jint maskOff,573jint maskScan,574jint width,575jint height,576jint fgColor,577SurfaceDataRasInfo *pRasInfo,578NativePrimitive *pPrim,579CompositeInfo *pCompInfo)580{581mlib_s32 cnstA, cnstR, cnstG, cnstB;582mlib_s32 rasScan = pRasInfo->scanStride;583mlib_f32 cnstARGB0;584mlib_d64 cnstARGB;585mlib_u8 *mul8_cnstA;586mlib_s32 j;587588cnstA = (fgColor >> 24) & 0xff;589cnstR = (fgColor >> 16) & 0xff;590cnstG = (fgColor >> 8) & 0xff;591cnstB = (fgColor ) & 0xff;592593if (cnstA != 0xff) {594if (cnstA == 0) return;595596cnstR = mul8table[cnstA][cnstR];597cnstG = mul8table[cnstA][cnstG];598cnstB = mul8table[cnstA][cnstB];599}600601vis_write_gsr(0 << 3);602603if (pMask != NULL) {604pMask += maskOff;605606if (rasScan == 4*width && maskScan == width) {607width *= height;608height = 1;609}610611mul8_cnstA = mul8table[cnstA];612613cnstARGB0 = F32_FROM_U8x4(cnstA, cnstB, cnstG, cnstR);614615for (j = 0; j < height; j++) {616IntRgbSrcOverMaskFill_line(rasBase, pMask, width, cnstARGB0,617mul8_cnstA, (void*)mul8table);618619PTR_ADD(rasBase, rasScan);620PTR_ADD(pMask, maskScan);621}622} else {623if (rasScan == 4*width) {624width *= height;625height = 1;626}627628cnstARGB = vis_to_double((cnstB << 7), (cnstG << 23) | (cnstR << 7));629630cnstA = 255 - cnstA;631632for (j = 0; j < height; j++) {633IntRgbSrcOverMaskFill_A1_line(rasBase, pMask, width, cnstARGB,634cnstA, (void*)mul8table);635636PTR_ADD(rasBase, rasScan);637}638}639}640641/***************************************************************/642643void ADD_SUFF(ThreeByteBgrSrcOverMaskFill)(void *rasBase,644jubyte *pMask,645jint maskOff,646jint maskScan,647jint width,648jint height,649jint fgColor,650SurfaceDataRasInfo *pRasInfo,651NativePrimitive *pPrim,652CompositeInfo *pCompInfo)653{654mlib_d64 buff[BUFF_SIZE/2];655void *pbuff = buff;656mlib_s32 cnstA, cnstR, cnstG, cnstB;657mlib_s32 rasScan = pRasInfo->scanStride;658mlib_f32 cnstARGB0;659mlib_d64 cnstARGB;660mlib_u8 *mul8_cnstA;661mlib_s32 j;662663if (width > BUFF_SIZE) pbuff = mlib_malloc(width*sizeof(mlib_s32));664665cnstA = (fgColor >> 24) & 0xff;666cnstR = (fgColor >> 16) & 0xff;667cnstG = (fgColor >> 8) & 0xff;668cnstB = (fgColor ) & 0xff;669670if (cnstA != 0xff) {671if (cnstA == 0) return;672673cnstR = mul8table[cnstA][cnstR];674cnstG = mul8table[cnstA][cnstG];675cnstB = mul8table[cnstA][cnstB];676}677678vis_write_gsr(0 << 3);679680if (pMask != NULL) {681pMask += maskOff;682683mul8_cnstA = mul8table[cnstA];684685cnstARGB0 = F32_FROM_U8x4(cnstA, cnstR, cnstG, cnstB);686687for (j = 0; j < height; j++) {688ADD_SUFF(ThreeByteBgrToIntArgbConvert)(rasBase, pbuff, width, 1,689pRasInfo, pRasInfo,690pPrim, pCompInfo);691692IntRgbSrcOverMaskFill_line(pbuff, pMask, width, cnstARGB0,693mul8_cnstA, (void*)mul8table);694695IntArgbToThreeByteBgrConvert(pbuff, rasBase, width, 1,696pRasInfo, pRasInfo, pPrim, pCompInfo);697698PTR_ADD(rasBase, rasScan);699PTR_ADD(pMask, maskScan);700}701} else {702cnstARGB = vis_to_double((cnstR << 7), (cnstG << 23) | (cnstB << 7));703704cnstA = 255 - cnstA;705706for (j = 0; j < height; j++) {707ADD_SUFF(ThreeByteBgrToIntArgbConvert)(rasBase, pbuff, width, 1,708pRasInfo, pRasInfo,709pPrim, pCompInfo);710711IntRgbSrcOverMaskFill_A1_line(pbuff, pMask, width, cnstARGB,712cnstA, (void*)mul8table);713714IntArgbToThreeByteBgrConvert(pbuff, rasBase, width, 1,715pRasInfo, pRasInfo, pPrim, pCompInfo);716717PTR_ADD(rasBase, rasScan);718}719}720721if (pbuff != buff) {722mlib_free(pbuff);723}724}725726/***************************************************************/727728#endif729730731