Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/java2d/loops/vis_ByteIndexed.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_proto.h>28#include "java2d_Mlib.h"29#include "vis_AlphaMacros.h"3031/***************************************************************/3233const mlib_u8 vis_sat_sh3_tbl[128 + 256 + 128] = {340, 0, 0, 0, 0, 0, 0, 0,350, 0, 0, 0, 0, 0, 0, 0,360, 0, 0, 0, 0, 0, 0, 0,370, 0, 0, 0, 0, 0, 0, 0,380, 0, 0, 0, 0, 0, 0, 0,390, 0, 0, 0, 0, 0, 0, 0,400, 0, 0, 0, 0, 0, 0, 0,410, 0, 0, 0, 0, 0, 0, 0,420, 0, 0, 0, 0, 0, 0, 0,430, 0, 0, 0, 0, 0, 0, 0,440, 0, 0, 0, 0, 0, 0, 0,450, 0, 0, 0, 0, 0, 0, 0,460, 0, 0, 0, 0, 0, 0, 0,470, 0, 0, 0, 0, 0, 0, 0,480, 0, 0, 0, 0, 0, 0, 0,490, 0, 0, 0, 0, 0, 0, 0,500, 0, 0, 0, 0, 0, 0, 0,511, 1, 1, 1, 1, 1, 1, 1,522, 2, 2, 2, 2, 2, 2, 2,533, 3, 3, 3, 3, 3, 3, 3,544, 4, 4, 4, 4, 4, 4, 4,555, 5, 5, 5, 5, 5, 5, 5,566, 6, 6, 6, 6, 6, 6, 6,577, 7, 7, 7, 7, 7, 7, 7,588, 8, 8, 8, 8, 8, 8, 8,599, 9, 9, 9, 9, 9, 9, 9,6010, 10, 10, 10, 10, 10, 10, 10,6111, 11, 11, 11, 11, 11, 11, 11,6212, 12, 12, 12, 12, 12, 12, 12,6313, 13, 13, 13, 13, 13, 13, 13,6414, 14, 14, 14, 14, 14, 14, 14,6515, 15, 15, 15, 15, 15, 15, 15,6616, 16, 16, 16, 16, 16, 16, 16,6717, 17, 17, 17, 17, 17, 17, 17,6818, 18, 18, 18, 18, 18, 18, 18,6919, 19, 19, 19, 19, 19, 19, 19,7020, 20, 20, 20, 20, 20, 20, 20,7121, 21, 21, 21, 21, 21, 21, 21,7222, 22, 22, 22, 22, 22, 22, 22,7323, 23, 23, 23, 23, 23, 23, 23,7424, 24, 24, 24, 24, 24, 24, 24,7525, 25, 25, 25, 25, 25, 25, 25,7626, 26, 26, 26, 26, 26, 26, 26,7727, 27, 27, 27, 27, 27, 27, 27,7828, 28, 28, 28, 28, 28, 28, 28,7929, 29, 29, 29, 29, 29, 29, 29,8030, 30, 30, 30, 30, 30, 30, 30,8131, 31, 31, 31, 31, 31, 31, 31,8231, 31, 31, 31, 31, 31, 31, 31,8331, 31, 31, 31, 31, 31, 31, 31,8431, 31, 31, 31, 31, 31, 31, 31,8531, 31, 31, 31, 31, 31, 31, 31,8631, 31, 31, 31, 31, 31, 31, 31,8731, 31, 31, 31, 31, 31, 31, 31,8831, 31, 31, 31, 31, 31, 31, 31,8931, 31, 31, 31, 31, 31, 31, 31,9031, 31, 31, 31, 31, 31, 31, 31,9131, 31, 31, 31, 31, 31, 31, 31,9231, 31, 31, 31, 31, 31, 31, 31,9331, 31, 31, 31, 31, 31, 31, 31,9431, 31, 31, 31, 31, 31, 31, 31,9531, 31, 31, 31, 31, 31, 31, 31,9631, 31, 31, 31, 31, 31, 31, 31,9731, 31, 31, 31, 31, 31, 31, 31,98};99100/***************************************************************/101102#define CHECK_LUT103104/***************************************************************/105106#define FUNC_CONVERT(FUNC, SRC_T) \107void ADD_SUFF(SRC_T##ToByteIndexed##FUNC)(BLIT_PARAMS) \108{ \109const mlib_u8 *p_tbl = vis_sat_sh3_tbl + 128; \110mlib_s32 DstWriteXDither, DstWriteYDither; \111mlib_s8 *DstWritererr, *DstWritegerr, *DstWriteberr; \112mlib_u8 *DstWriteInvLut; \113mlib_s32 srcScan = pSrcInfo->scanStride; \114mlib_s32 dstScan = pDstInfo->scanStride; \115mlib_s32 r, g, b; \116mlib_s32 i, j; \117CHECK_LUT \118\119DstWriteYDither = (pDstInfo->bounds.y1 & 7) << 3; \120DstWriteInvLut = pDstInfo->invColorTable; \121\122for (j = 0; j < height; j++) { \123mlib_u8 *pSrc = srcBase; \124mlib_u8 *pDst = dstBase; \125\126DstWritererr = pDstInfo->redErrTable + DstWriteYDither; \127DstWritegerr = pDstInfo->grnErrTable + DstWriteYDither; \128DstWriteberr = pDstInfo->bluErrTable + DstWriteYDither; \129\130DstWriteXDither = pDstInfo->bounds.x1 & 7; \131\132for (i = 0; i < width; i++) { \133GET_RGB_##SRC_T(i) \134{ \135r = p_tbl[r + DstWritererr[DstWriteXDither]]; \136g = p_tbl[g + DstWritegerr[DstWriteXDither]]; \137b = p_tbl[b + DstWriteberr[DstWriteXDither]]; \138\139pDst[i] = DstWriteInvLut[(r << 10) + (g << 5) + b]; \140} \141\142DstWriteXDither = (DstWriteXDither + 1) & 7; \143} \144\145PTR_ADD(dstBase, dstScan); \146PTR_ADD(srcBase, srcScan); \147\148DstWriteYDither = (DstWriteYDither + (1 << 3)) & (7 << 3); \149} \150}151152/***************************************************************/153154#define FUNC_SCALE_CONVERT(FUNC, SRC_T) \155void ADD_SUFF(SRC_T##ToByteIndexed##FUNC)(SCALE_PARAMS) \156{ \157const mlib_u8 *p_tbl = vis_sat_sh3_tbl + 128; \158mlib_s32 DstWriteXDither, DstWriteYDither; \159mlib_s8 *DstWritererr, *DstWritegerr, *DstWriteberr; \160mlib_u8 *DstWriteInvLut; \161mlib_s32 srcScan = pSrcInfo->scanStride; \162mlib_s32 dstScan = pDstInfo->scanStride; \163mlib_s32 r, g, b; \164mlib_s32 i, j; \165CHECK_LUT \166\167DstWriteYDither = (pDstInfo->bounds.y1 & 7) << 3; \168DstWriteInvLut = pDstInfo->invColorTable; \169\170for (j = 0; j < height; j++) { \171mlib_u8 *pSrc = srcBase; \172mlib_u8 *pDst = dstBase; \173mlib_s32 tmpsxloc = sxloc; \174\175PTR_ADD(pSrc, (syloc >> shift) * srcScan); \176\177DstWritererr = pDstInfo->redErrTable + DstWriteYDither; \178DstWritegerr = pDstInfo->grnErrTable + DstWriteYDither; \179DstWriteberr = pDstInfo->bluErrTable + DstWriteYDither; \180\181DstWriteXDither = pDstInfo->bounds.x1 & 7; \182\183for (i = 0; i < width; i++) { \184mlib_s32 ii = tmpsxloc >> shift; \185GET_RGB_##SRC_T(ii) \186{ \187r = p_tbl[r + DstWritererr[DstWriteXDither]]; \188g = p_tbl[g + DstWritegerr[DstWriteXDither]]; \189b = p_tbl[b + DstWriteberr[DstWriteXDither]]; \190\191pDst[i] = DstWriteInvLut[(r << 10) + (g << 5) + b]; \192} \193\194DstWriteXDither = (DstWriteXDither + 1) & 7; \195tmpsxloc += sxinc; \196} \197\198PTR_ADD(dstBase, dstScan); \199syloc += syinc; \200\201DstWriteYDither = (DstWriteYDither + (1 << 3)) & (7 << 3); \202} \203}204205/***************************************************************/206207#define GET_PIX_IntArgbBm(i) \208mlib_s32 pixel = *(mlib_s32*)(pSrc + 4*i); \209if (pixel >> 24)210211#define GET_PIX_ByteIndexedBm(i) \212mlib_s32 pixel = SrcReadLut[pSrc[i]]; \213if (pixel < 0)214215#define FUNC_BGCOPY(SRC_T) \216void ADD_SUFF(SRC_T##ToByteIndexedXparBgCopy)(BCOPY_PARAMS) \217{ \218const mlib_u8 *p_tbl = vis_sat_sh3_tbl + 128; \219mlib_s32 DstWriteXDither, DstWriteYDither; \220mlib_s8 *DstWritererr, *DstWritegerr, *DstWriteberr; \221mlib_u8 *DstWriteInvLut; \222mlib_s32 srcScan = pSrcInfo->scanStride; \223mlib_s32 dstScan = pDstInfo->scanStride; \224mlib_s32 r, g, b; \225mlib_s32 i, j; \226jint *SrcReadLut = pSrcInfo->lutBase; \227\228DstWriteYDither = (pDstInfo->bounds.y1 & 7) << 3; \229DstWriteInvLut = pDstInfo->invColorTable; \230\231for (j = 0; j < height; j++) { \232mlib_u8 *pSrc = srcBase; \233mlib_u8 *pDst = dstBase; \234\235DstWritererr = pDstInfo->redErrTable + DstWriteYDither; \236DstWritegerr = pDstInfo->grnErrTable + DstWriteYDither; \237DstWriteberr = pDstInfo->bluErrTable + DstWriteYDither; \238\239DstWriteXDither = pDstInfo->bounds.x1 & 7; \240\241for (i = 0; i < width; i++) { \242GET_PIX_##SRC_T(i) \243{ \244b = (pixel) & 0xff; \245g = (pixel >> 8) & 0xff; \246r = (pixel >> 16) & 0xff; \247\248r = p_tbl[r + DstWritererr[DstWriteXDither]]; \249g = p_tbl[g + DstWritegerr[DstWriteXDither]]; \250b = p_tbl[b + DstWriteberr[DstWriteXDither]]; \251\252pDst[i] = DstWriteInvLut[(r << 10) + (g << 5) + b]; \253} else { \254pDst[i] = bgpixel; \255} \256\257DstWriteXDither = (DstWriteXDither + 1) & 7; \258} \259\260PTR_ADD(dstBase, dstScan); \261PTR_ADD(srcBase, srcScan); \262\263DstWriteYDither = (DstWriteYDither + (1 << 3)) & (7 << 3); \264} \265}266267FUNC_BGCOPY(ByteIndexedBm)268FUNC_BGCOPY(IntArgbBm)269270/***************************************************************/271272#define GET_RGB_IntArgb(i) \273mlib_u32 pixel = *(mlib_u32*)(pSrc + 4*i); \274b = (pixel) & 0xff; \275g = (pixel >> 8) & 0xff; \276r = (pixel >> 16) & 0xff;277278#define GET_RGB_ThreeByteBgr(i) \279b = pSrc[3*i]; \280g = pSrc[3*i + 1]; \281r = pSrc[3*i + 2];282283#define GET_RGB_ByteGray(i) \284r = g = b = pSrc[i];285286#define GET_RGB_Index12Gray(i) \287r = SrcReadLut[((mlib_u16*)pSrc)[i] & 0xfff]; \288r &= 0xff; \289g = b = r;290291#define GET_RGB_ByteIndexed(i) \292mlib_u32 pixel = SrcReadLut[pSrc[i]]; \293b = (pixel) & 0xff; \294g = (pixel >> 8) & 0xff; \295r = (pixel >> 16) & 0xff;296297#define GET_RGB_IntArgbBm(i) \298mlib_s32 pixel = *(mlib_s32*)(pSrc + 4*i); \299b = (pixel) & 0xff; \300g = (pixel >> 8) & 0xff; \301r = (pixel >> 16) & 0xff; \302if (pixel >> 24)303304#define GET_RGB_ByteIndexedBm(i) \305mlib_s32 pixel = SrcReadLut[pSrc[i]]; \306b = (pixel) & 0xff; \307g = (pixel >> 8) & 0xff; \308r = (pixel >> 16) & 0xff; \309if (pixel < 0)310311/***************************************************************/312313FUNC_CONVERT(Convert, IntArgb)314FUNC_CONVERT(Convert, ThreeByteBgr)315FUNC_CONVERT(Convert, ByteGray)316FUNC_CONVERT(XparOver, IntArgbBm)317FUNC_SCALE_CONVERT(ScaleConvert, IntArgb)318FUNC_SCALE_CONVERT(ScaleConvert, ThreeByteBgr)319FUNC_SCALE_CONVERT(ScaleConvert, ByteGray)320FUNC_SCALE_CONVERT(ScaleXparOver, IntArgbBm)321322/***************************************************************/323324#undef CHECK_LUT325#define CHECK_LUT \326jint *SrcReadLut = pSrcInfo->lutBase;327328FUNC_CONVERT(Convert, Index12Gray)329FUNC_SCALE_CONVERT(ScaleConvert, Index12Gray)330331FUNC_CONVERT(XparOver, ByteIndexedBm)332FUNC_SCALE_CONVERT(ScaleXparOver, ByteIndexedBm)333334/***************************************************************/335336#undef CHECK_LUT337#define CHECK_LUT \338jint *SrcReadLut = pSrcInfo->lutBase; \339jint *DstReadLut = pDstInfo->lutBase; \340if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) { \341ADD_SUFF(AnyByteIsomorphicCopy)(BLIT_CALL_PARAMS); \342return; \343}344345FUNC_CONVERT(Convert, ByteIndexed)346347#undef CHECK_LUT348#define CHECK_LUT \349jint *SrcReadLut = pSrcInfo->lutBase; \350jint *DstReadLut = pDstInfo->lutBase; \351if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) { \352ADD_SUFF(AnyByteIsomorphicScaleCopy)(SCALE_CALL_PARAMS); \353return; \354}355356FUNC_SCALE_CONVERT(ScaleConvert, ByteIndexed)357358/***************************************************************/359360void ADD_SUFF(IntArgbToByteIndexedXorBlit)(BLIT_PARAMS)361{362mlib_u8 *DstWriteInvLut;363mlib_s32 srcScan = pSrcInfo->scanStride;364mlib_s32 dstScan = pDstInfo->scanStride;365mlib_s32 xorpixel = pCompInfo->details.xorPixel;366mlib_s32 alphamask = pCompInfo->alphaMask;367mlib_s32 i, j;368369DstWriteInvLut = pDstInfo->invColorTable;370371for (j = 0; j < height; j++) {372mlib_s32 *pSrc = srcBase;373mlib_u8 *pDst = dstBase;374375for (i = 0; i < width; i++) {376mlib_s32 spix = pSrc[i];377mlib_s32 dpix;378if (spix < 0) {379dpix = DstWriteInvLut[((spix >> 9) & 0x7C00) +380((spix >> 6) & 0x03E0) +381((spix >> 3) & 0x001F)];382pDst[i] ^= (dpix ^ xorpixel) &~ alphamask;383}384}385386PTR_ADD(dstBase, dstScan);387PTR_ADD(srcBase, srcScan);388}389}390391/***************************************************************/392393#define MASK_FILL(rr, pathA, dstA, dstARGB) \394{ \395mlib_d64 t0, t1; \396mlib_s32 srcF, dstF, srcA; \397\398srcF = ((dstA & SrcOpAnd) ^ SrcOpXor) + SrcOpAdd; \399\400srcF = MUL8_INT(srcF, pathA); \401dstF = MUL8_INT(dstFbase, pathA) + (0xff - pathA); \402\403srcA = MUL8_INT(cnstA, srcF); \404dstA = MUL8_INT(dstF, dstA); \405\406t0 = MUL8_VIS(cnstARGB0, srcF); \407t1 = MUL8_VIS(dstARGB, dstA); \408rr = vis_fpadd16(t0, t1); \409\410dstA += srcA; \411DIV_ALPHA(rr, dstA); \412}413414/***************************************************************/415416void ADD_SUFF(ByteIndexedAlphaMaskFill)(void *dstBase,417jubyte *pMask,418jint maskOff,419jint maskScan,420jint width,421jint height,422jint fgColor,423SurfaceDataRasInfo *pDstInfo,424NativePrimitive *pPrim,425CompositeInfo *pCompInfo)426{427const mlib_u8 *mul8_tbl = (void*)mul8table;428const mlib_u8 *p_tbl = vis_sat_sh3_tbl + 128;429mlib_s32 DstWriteXDither, DstWriteYDither;430mlib_s8 *DstWritererr, *DstWritegerr, *DstWriteberr;431mlib_u8 *DstWriteInvLut;432mlib_s32 r, g, b;433mlib_f32 *DstReadLut = (void*)(pDstInfo->lutBase);434mlib_s32 cnstA, cnstR, cnstG, cnstB;435mlib_s32 dstScan = pDstInfo->scanStride;436mlib_f32 cnstARGB0;437mlib_s32 SrcOpAnd, SrcOpXor, SrcOpAdd;438mlib_s32 DstOpAnd, DstOpXor, DstOpAdd;439mlib_s32 dstFbase;440mlib_s32 j;441442cnstA = (fgColor >> 24) & 0xff;443cnstR = (fgColor >> 16) & 0xff;444cnstG = (fgColor >> 8) & 0xff;445cnstB = (fgColor ) & 0xff;446447if (cnstA != 0xff) {448cnstR = mul8table[cnstA][cnstR];449cnstG = mul8table[cnstA][cnstG];450cnstB = mul8table[cnstA][cnstB];451}452453cnstARGB0 = F32_FROM_U8x4(cnstA, cnstR, cnstG, cnstB);454455SrcOpAnd = (AlphaRules[pCompInfo->rule].srcOps).andval;456SrcOpXor = (AlphaRules[pCompInfo->rule].srcOps).xorval;457SrcOpAdd = (AlphaRules[pCompInfo->rule].srcOps).addval;458SrcOpAdd -= SrcOpXor;459460DstOpAnd = (AlphaRules[pCompInfo->rule].dstOps).andval;461DstOpXor = (AlphaRules[pCompInfo->rule].dstOps).xorval;462DstOpAdd = (AlphaRules[pCompInfo->rule].dstOps).addval;463DstOpAdd -= DstOpXor;464465dstFbase = (((cnstA) & DstOpAnd) ^ DstOpXor) + DstOpAdd;466467vis_write_gsr(7 << 3);468469if (pMask != NULL) {470DstWriteYDither = (pDstInfo->bounds.y1 & 7) << 3;471DstWriteInvLut = pDstInfo->invColorTable;472473pMask += maskOff;474475if (dstScan == width && maskScan == width) {476width *= height;477height = 1;478}479480for (j = 0; j < height; j++) {481mlib_u8 *pDst = dstBase;482mlib_s32 i;483mlib_s32 pathA0, dstA0, dst_val, pixel;484mlib_d64 res0;485mlib_f32 dstARGB0;486487DstWritererr = pDstInfo->redErrTable + DstWriteYDither;488DstWritegerr = pDstInfo->grnErrTable + DstWriteYDither;489DstWriteberr = pDstInfo->bluErrTable + DstWriteYDither;490491DstWriteXDither = pDstInfo->bounds.x1 & 7;492493#pragma pipeloop(0)494for (i = 0; i < width; i++) {495dst_val = pDst[i];496pathA0 = pMask[i];497dstA0 = *(mlib_u8*)(DstReadLut + dst_val);498dstARGB0 = DstReadLut[dst_val];499MASK_FILL(res0, pathA0, dstA0, dstARGB0);500dstARGB0 = vis_fpack16(res0);501502pixel = *(mlib_s32*)&dstARGB0;503b = (pixel) & 0xff;504g = (pixel >> 8) & 0xff;505r = (pixel >> 16) & 0xff;506r = p_tbl[r + DstWritererr[DstWriteXDither]];507g = p_tbl[g + DstWritegerr[DstWriteXDither]];508b = p_tbl[b + DstWriteberr[DstWriteXDither]];509pDst[i] = DstWriteInvLut[(r << 10) + (g << 5) + b];510511DstWriteXDither = (DstWriteXDither + 1) & 7;512}513514PTR_ADD(dstBase, dstScan);515PTR_ADD(pMask, maskScan);516DstWriteYDither = (DstWriteYDither + (1 << 3)) & (7 << 3);517}518}/* else {519if (dstScan == 4*width) {520width *= height;521height = 1;522}523524for (j = 0; j < height; j++) {525IntArgbAlphaMaskFill_A1_line(dstBase, pMask, width,526cnstARGB0,527log_val, mul8_cnstA, mul8_dstF,528(void*)mul8table);529530PTR_ADD(dstBase, dstScan);531}532}*/533}534535/***************************************************************/536537#endif538539540