Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/java2d/loops/vis_ByteGray.c
32288 views
/*1* Copyright (c) 2003, 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/***************************************************************/3233#define RGB2GRAY(r, g, b) \34(((77 * (r)) + (150 * (g)) + (29 * (b)) + 128) >> 8)3536/***************************************************************/3738#define Gray2Argb(x) \390xff000000 | (x << 16) | (x << 8) | x4041/***************************************************************/4243#define LUT(x) \44((mlib_u8*)LutU8)[4 * (x)]4546#define LUT12(x) \47((mlib_u8*)LutU8)[4 * ((x) & 0xfff)]4849/***************************************************************/5051void ADD_SUFF(UshortGrayToByteGrayConvert)(BLIT_PARAMS)52{53mlib_s32 dstScan = pDstInfo->scanStride;54mlib_s32 srcScan = pSrcInfo->scanStride;55mlib_u8 *dst_end;56mlib_d64 s0, s1, ss;57mlib_s32 i, j;5859if (width <= 8) {60for (j = 0; j < height; j++) {61mlib_u8 *src = srcBase;62mlib_u8 *dst = dstBase;6364for (i = 0; i < width; i++) {65dst[i] = src[2*i];66}6768PTR_ADD(dstBase, dstScan);69PTR_ADD(srcBase, srcScan);70}71return;72}7374if (srcScan == 2*width && dstScan == width) {75width *= height;76height = 1;77}7879for (j = 0; j < height; j++) {80mlib_u8 *src = srcBase;81mlib_u8 *dst = dstBase;82mlib_d64 *sp;8384dst_end = dst + width;8586while (((mlib_s32)dst & 3) && dst < dst_end) {87*dst++ = *src;88src += 2;89}9091if ((mlib_s32)src & 7) {92sp = vis_alignaddr(src, 0);93s1 = *sp++;9495#pragma pipeloop(0)96for (; dst <= (dst_end - 4); dst += 4) {97s0 = s1;98s1 = *sp++;99ss = vis_faligndata(s0, s1);100ss = vis_fpmerge(vis_read_hi(ss), vis_read_lo(ss));101ss = vis_fpmerge(vis_read_hi(ss), vis_read_lo(ss));102*(mlib_f32*)dst = vis_read_hi(ss);103src += 2*4;104}105} else {106#pragma pipeloop(0)107for (; dst <= (dst_end - 4); dst += 4) {108ss = *(mlib_d64*)src;109ss = vis_fpmerge(vis_read_hi(ss), vis_read_lo(ss));110ss = vis_fpmerge(vis_read_hi(ss), vis_read_lo(ss));111*(mlib_f32*)dst = vis_read_hi(ss);112src += 2*4;113}114}115116while (dst < dst_end) {117*dst++ = *src;118src += 2;119}120121PTR_ADD(dstBase, dstScan);122PTR_ADD(srcBase, srcScan);123}124}125126/***************************************************************/127128void ADD_SUFF(ByteGrayToIntArgbConvert)(BLIT_PARAMS)129{130mlib_s32 dstScan = pDstInfo->scanStride;131mlib_s32 srcScan = pSrcInfo->scanStride;132mlib_d64 d0, d1, d2, d3;133mlib_f32 ff, aa = vis_fones();134mlib_s32 i, j, x;135136if (width < 8) {137for (j = 0; j < height; j++) {138mlib_u8 *src = srcBase;139mlib_s32 *dst = dstBase;140141for (i = 0; i < width; i++) {142x = src[i];143dst[i] = Gray2Argb(x);144}145146PTR_ADD(dstBase, dstScan);147PTR_ADD(srcBase, srcScan);148}149return;150}151152if (srcScan == width && dstScan == 4*width) {153width *= height;154height = 1;155}156157for (j = 0; j < height; j++) {158mlib_u8 *src = srcBase;159mlib_s32 *dst = dstBase;160mlib_s32 *dst_end;161162dst_end = dst + width;163164while (((mlib_s32)src & 3) && dst < dst_end) {165x = *src++;166*dst++ = Gray2Argb(x);167}168169#pragma pipeloop(0)170for (; dst <= (dst_end - 4); dst += 4) {171ff = *(mlib_f32*)src;172d0 = vis_fpmerge(aa, ff);173d1 = vis_fpmerge(ff, ff);174d2 = vis_fpmerge(vis_read_hi(d0), vis_read_hi(d1));175d3 = vis_fpmerge(vis_read_lo(d0), vis_read_lo(d1));176((mlib_f32*)dst)[0] = vis_read_hi(d2);177((mlib_f32*)dst)[1] = vis_read_lo(d2);178((mlib_f32*)dst)[2] = vis_read_hi(d3);179((mlib_f32*)dst)[3] = vis_read_lo(d3);180src += 4;181}182183while (dst < dst_end) {184x = *src++;185*dst++ = Gray2Argb(x);186}187188PTR_ADD(dstBase, dstScan);189PTR_ADD(srcBase, srcScan);190}191}192193/***************************************************************/194195void ADD_SUFF(ByteGrayToIntArgbScaleConvert)(SCALE_PARAMS)196{197mlib_s32 dstScan = pDstInfo->scanStride;198mlib_s32 srcScan = pSrcInfo->scanStride;199mlib_d64 d0, d1, d2, d3, dd;200mlib_f32 ff, aa = vis_fones();201mlib_s32 i, j, x;202203if (width < 16) {204for (j = 0; j < height; j++) {205mlib_u8 *src = srcBase;206mlib_s32 *dst = dstBase;207mlib_s32 tmpsxloc = sxloc;208209PTR_ADD(src, (syloc >> shift) * srcScan);210211for (i = 0; i < width; i++) {212x = src[tmpsxloc >> shift];213tmpsxloc += sxinc;214dst[i] = Gray2Argb(x);215}216217PTR_ADD(dstBase, dstScan);218syloc += syinc;219}220return;221}222223vis_alignaddr(NULL, 7);224225for (j = 0; j < height; j++) {226mlib_u8 *src = srcBase;227mlib_s32 *dst = dstBase;228mlib_s32 *dst_end;229mlib_s32 tmpsxloc = sxloc;230231PTR_ADD(src, (syloc >> shift) * srcScan);232233dst_end = dst + width;234235#pragma pipeloop(0)236for (; dst <= (dst_end - 4); dst += 4) {237LOAD_NEXT_U8(dd, src + ((tmpsxloc + 3*sxinc) >> shift));238LOAD_NEXT_U8(dd, src + ((tmpsxloc + 2*sxinc) >> shift));239LOAD_NEXT_U8(dd, src + ((tmpsxloc + sxinc) >> shift));240LOAD_NEXT_U8(dd, src + ((tmpsxloc ) >> shift));241tmpsxloc += 4*sxinc;242ff = vis_read_hi(dd);243d0 = vis_fpmerge(aa, ff);244d1 = vis_fpmerge(ff, ff);245d2 = vis_fpmerge(vis_read_hi(d0), vis_read_hi(d1));246d3 = vis_fpmerge(vis_read_lo(d0), vis_read_lo(d1));247((mlib_f32*)dst)[0] = vis_read_hi(d2);248((mlib_f32*)dst)[1] = vis_read_lo(d2);249((mlib_f32*)dst)[2] = vis_read_hi(d3);250((mlib_f32*)dst)[3] = vis_read_lo(d3);251}252253while (dst < dst_end) {254x = src[tmpsxloc >> shift];255tmpsxloc += sxinc;256*dst++ = Gray2Argb(x);257}258259PTR_ADD(dstBase, dstScan);260syloc += syinc;261}262}263264/***************************************************************/265266#if 1267268#ifdef MLIB_ADD_SUFF269#pragma weak ByteGrayToIntArgbPreConvert_F = ByteGrayToIntArgbConvert_F270#else271#pragma weak ByteGrayToIntArgbPreConvert = ByteGrayToIntArgbConvert272#endif273274#ifdef MLIB_ADD_SUFF275#pragma weak ByteGrayToIntArgbPreScaleConvert_F = \276ByteGrayToIntArgbScaleConvert_F277#else278#pragma weak ByteGrayToIntArgbPreScaleConvert = \279ByteGrayToIntArgbScaleConvert280#endif281282#else283284void ADD_SUFF(ByteGrayToIntArgbPreConvert)(BLIT_PARAMS)285{286ADD_SUFF(ByteGrayToIntArgbConvert)(BLIT_CALL_PARAMS);287}288289void ADD_SUFF(ByteGrayToIntArgbPreScaleConvert)(SCALE_PARAMS)290{291ADD_SUFF(ByteGrayToIntArgbScaleConvert)(SCALE_CALL_PARAMS);292}293294#endif295296/***************************************************************/297298void ADD_SUFF(UshortGrayToByteGrayScaleConvert)(SCALE_PARAMS)299{300mlib_s32 srcScan = pSrcInfo->scanStride;301mlib_s32 dstScan = pDstInfo->scanStride;302mlib_s32 i, j, w, tmpsxloc;303304for (j = 0; j < height; j++) {305mlib_u8 *pSrc = srcBase;306mlib_u8 *pDst = dstBase;307308tmpsxloc = sxloc;309w = width;310311PTR_ADD(pSrc, (syloc >> shift) * srcScan);312313if ((mlib_s32)pDst & 1) {314*pDst++ = pSrc[2*(tmpsxloc >> shift)];315tmpsxloc += sxinc;316w--;317}318319#pragma pipeloop(0)320for (i = 0; i <= (w - 2); i += 2) {321mlib_s32 x0, x1;322x0 = pSrc[2*(tmpsxloc >> shift)];323x1 = pSrc[2*((tmpsxloc + sxinc) >> shift)];324*(mlib_u16*)pDst = (x0 << 8) | x1;325pDst += 2;326tmpsxloc += 2*sxinc;327}328329if (i < w) {330*pDst = pSrc[2*(tmpsxloc >> shift)];331}332333PTR_ADD(dstBase, dstScan);334syloc += syinc;335}336}337338/***************************************************************/339340void ADD_SUFF(Index8GrayToByteGrayConvert)(BLIT_PARAMS)341{342jint *SrcReadLut = pSrcInfo->lutBase;343mlib_u8 *LutU8 = (mlib_u8*)SrcReadLut + 3;344mlib_s32 dstScan = pDstInfo->scanStride;345mlib_s32 srcScan = pSrcInfo->scanStride;346mlib_s32 i, j;347348if (width < 8) {349for (j = 0; j < height; j++) {350Index8GrayDataType *src = srcBase;351mlib_u8 *dst = dstBase;352353for (i = 0; i < width; i++) {354dst[i] = LUT(src[i]);355}356357PTR_ADD(dstBase, dstScan);358PTR_ADD(srcBase, srcScan);359}360return;361}362363if (srcScan == width && dstScan == width) {364width *= height;365height = 1;366}367368for (j = 0; j < height; j++) {369Index8GrayDataType *src = srcBase;370mlib_u8 *dst = dstBase;371mlib_u8 *dst_end = dst + width;372373if ((mlib_s32)dst & 1) {374*dst++ = LUT(*src);375src++;376}377378#pragma pipeloop(0)379for (; dst <= (dst_end - 2); dst += 2) {380((mlib_u16*)dst)[0] = (LUT(src[0]) << 8) | LUT(src[1]);381src += 2;382}383384if (dst < dst_end) {385*dst++ = LUT(*src);386src++;387}388389PTR_ADD(dstBase, dstScan);390PTR_ADD(srcBase, srcScan);391}392}393394/***************************************************************/395396void ADD_SUFF(Index12GrayToByteGrayConvert)(BLIT_PARAMS)397{398jint *SrcReadLut = pSrcInfo->lutBase;399mlib_u8 *LutU8 = (mlib_u8*)SrcReadLut + 3;400mlib_s32 dstScan = pDstInfo->scanStride;401mlib_s32 srcScan = pSrcInfo->scanStride;402mlib_s32 i, j;403404if (width < 8) {405for (j = 0; j < height; j++) {406Index12GrayDataType *src = srcBase;407mlib_u8 *dst = dstBase;408409for (i = 0; i < width; i++) {410dst[i] = LUT12(src[i]);411}412413PTR_ADD(dstBase, dstScan);414PTR_ADD(srcBase, srcScan);415}416return;417}418419if (srcScan == 2*width && dstScan == width) {420width *= height;421height = 1;422}423424for (j = 0; j < height; j++) {425Index12GrayDataType *src = srcBase;426mlib_u8 *dst = dstBase;427mlib_u8 *dst_end = dst + width;428429if ((mlib_s32)dst & 1) {430*dst++ = LUT12(*src);431src++;432}433434#pragma pipeloop(0)435for (; dst <= (dst_end - 2); dst += 2) {436((mlib_u16*)dst)[0] = (LUT12(src[0]) << 8) | LUT12(src[1]);437src += 2;438}439440if (dst < dst_end) {441*dst++ = LUT12(*src);442src++;443}444445PTR_ADD(dstBase, dstScan);446PTR_ADD(srcBase, srcScan);447}448}449450/***************************************************************/451452void ADD_SUFF(Index8GrayToByteGrayScaleConvert)(SCALE_PARAMS)453{454jint *SrcReadLut = pSrcInfo->lutBase;455mlib_u8 *LutU8 = (mlib_u8*)SrcReadLut + 3;456mlib_s32 dstScan = pDstInfo->scanStride;457mlib_s32 srcScan = pSrcInfo->scanStride;458mlib_s32 i, j;459460if (width < 8) {461for (j = 0; j < height; j++) {462Index8GrayDataType *src = srcBase;463mlib_u8 *dst = dstBase;464jint tmpsxloc = sxloc;465466PTR_ADD(src, (syloc >> shift) * srcScan);467468for (i = 0; i < width; i++) {469dst[i] = LUT(src[tmpsxloc >> shift]);470tmpsxloc += sxinc;471}472473PTR_ADD(dstBase, dstScan);474syloc += syinc;475}476return;477}478479for (j = 0; j < height; j++) {480Index8GrayDataType *src = srcBase;481mlib_u8 *dst = dstBase;482mlib_u8 *dst_end = dst + width;483jint tmpsxloc = sxloc;484485PTR_ADD(src, (syloc >> shift) * srcScan);486487if ((mlib_s32)dst & 1) {488*dst++ = LUT(src[tmpsxloc >> shift]);489tmpsxloc += sxinc;490}491492#pragma pipeloop(0)493for (; dst <= (dst_end - 2); dst += 2) {494((mlib_u16*)dst)[0] = (LUT(src[tmpsxloc >> shift]) << 8) |495LUT(src[(tmpsxloc + sxinc) >> shift]);496tmpsxloc += 2*sxinc;497}498499if (dst < dst_end) {500*dst = LUT(src[tmpsxloc >> shift]);501}502503PTR_ADD(dstBase, dstScan);504syloc += syinc;505}506}507508/***************************************************************/509510void ADD_SUFF(Index12GrayToByteGrayScaleConvert)(SCALE_PARAMS)511{512jint *SrcReadLut = pSrcInfo->lutBase;513mlib_u8 *LutU8 = (mlib_u8*)SrcReadLut + 3;514mlib_s32 dstScan = pDstInfo->scanStride;515mlib_s32 srcScan = pSrcInfo->scanStride;516mlib_s32 i, j;517518if (width < 8) {519for (j = 0; j < height; j++) {520Index12GrayDataType *src = srcBase;521mlib_u8 *dst = dstBase;522jint tmpsxloc = sxloc;523524PTR_ADD(src, (syloc >> shift) * srcScan);525526for (i = 0; i < width; i++) {527dst[i] = LUT12(src[tmpsxloc >> shift]);528tmpsxloc += sxinc;529}530531PTR_ADD(dstBase, dstScan);532syloc += syinc;533}534return;535}536537for (j = 0; j < height; j++) {538Index12GrayDataType *src = srcBase;539mlib_u8 *dst = dstBase;540mlib_u8 *dst_end = dst + width;541jint tmpsxloc = sxloc;542543PTR_ADD(src, (syloc >> shift) * srcScan);544545if ((mlib_s32)dst & 1) {546*dst++ = LUT12(src[tmpsxloc >> shift]);547tmpsxloc += sxinc;548}549550#pragma pipeloop(0)551for (; dst <= (dst_end - 2); dst += 2) {552((mlib_u16*)dst)[0] = (LUT12(src[tmpsxloc >> shift]) << 8) |553LUT12(src[(tmpsxloc + sxinc) >> shift]);554tmpsxloc += 2*sxinc;555}556557if (dst < dst_end) {558*dst = LUT12(src[tmpsxloc >> shift]);559}560561PTR_ADD(dstBase, dstScan);562syloc += syinc;563}564}565566/***************************************************************/567568void ADD_SUFF(ByteIndexedToByteGrayConvert)(BLIT_PARAMS)569{570jint *srcLut = pSrcInfo->lutBase;571juint lutSize = pSrcInfo->lutSize;572mlib_u8 LutU8[256];573mlib_s32 dstScan = pDstInfo->scanStride;574mlib_s32 srcScan = pSrcInfo->scanStride;575mlib_s32 i, j;576577if (width < 8) {578for (j = 0; j < height; j++) {579mlib_u8 *src = srcBase;580mlib_u8 *dst = dstBase;581582for (i = 0; i < width; i++) {583jint argb = srcLut[src[i]];584int r, g, b;585b = (argb) & 0xff;586g = (argb >> 8) & 0xff;587r = (argb >> 16) & 0xff;588dst[i] = RGB2GRAY(r, g, b);589}590591PTR_ADD(dstBase, dstScan);592PTR_ADD(srcBase, srcScan);593}594return;595596}597598if (lutSize >= 256) lutSize = 256;599600ADD_SUFF(IntArgbToByteGrayConvert)(srcLut, LutU8, lutSize, 1,601pSrcInfo, pDstInfo, pPrim, pCompInfo);602603for (i = lutSize; i < 256; i++) {604LutU8[i] = 0;605}606607if (srcScan == width && dstScan == width) {608width *= height;609height = 1;610}611612for (j = 0; j < height; j++) {613mlib_u8 *src = srcBase;614mlib_u8 *dst = dstBase;615mlib_u8 *dst_end = dst + width;616617if ((mlib_s32)dst & 1) {618*dst++ = LutU8[*src];619src++;620}621622#pragma pipeloop(0)623for (; dst <= (dst_end - 2); dst += 2) {624((mlib_u16*)dst)[0] = (LutU8[src[0]] << 8) | LutU8[src[1]];625src += 2;626}627628if (dst < dst_end) {629*dst++ = LutU8[*src];630src++;631}632633PTR_ADD(dstBase, dstScan);634PTR_ADD(srcBase, srcScan);635}636}637638/***************************************************************/639640void ADD_SUFF(ByteIndexedToByteGrayScaleConvert)(SCALE_PARAMS)641{642jint *srcLut = pSrcInfo->lutBase;643juint lutSize = pSrcInfo->lutSize;644mlib_u8 LutU8[256];645mlib_s32 dstScan = pDstInfo->scanStride;646mlib_s32 srcScan = pSrcInfo->scanStride;647mlib_s32 i, j;648649if (width < 8) {650for (j = 0; j < height; j++) {651mlib_u8 *src = srcBase;652mlib_u8 *dst = dstBase;653jint tmpsxloc = sxloc;654655PTR_ADD(src, (syloc >> shift) * srcScan);656657for (i = 0; i < width; i++) {658jint argb = srcLut[src[tmpsxloc >> shift]];659int r, g, b;660b = (argb) & 0xff;661g = (argb >> 8) & 0xff;662r = (argb >> 16) & 0xff;663dst[i] = RGB2GRAY(r, g, b);664tmpsxloc += sxinc;665}666667PTR_ADD(dstBase, dstScan);668syloc += syinc;669}670return;671672}673674if (lutSize >= 256) lutSize = 256;675676ADD_SUFF(IntArgbToByteGrayConvert)(srcLut, LutU8, lutSize, 1,677pSrcInfo, pDstInfo, pPrim, pCompInfo);678679for (i = lutSize; i < 256; i++) {680LutU8[i] = 0;681}682683for (j = 0; j < height; j++) {684mlib_u8 *src = srcBase;685mlib_u8 *dst = dstBase;686mlib_u8 *dst_end = dst + width;687jint tmpsxloc = sxloc;688689PTR_ADD(src, (syloc >> shift) * srcScan);690691if ((mlib_s32)dst & 1) {692*dst++ = LutU8[src[tmpsxloc >> shift]];693tmpsxloc += sxinc;694}695696#pragma pipeloop(0)697for (; dst <= (dst_end - 2); dst += 2) {698((mlib_u16*)dst)[0] = (LutU8[src[tmpsxloc >> shift]] << 8) |699LutU8[src[(tmpsxloc + sxinc) >> shift]];700tmpsxloc += 2*sxinc;701}702703if (dst < dst_end) {704*dst = LutU8[src[tmpsxloc >> shift]];705}706707PTR_ADD(dstBase, dstScan);708syloc += syinc;709}710}711712/***************************************************************/713714void ADD_SUFF(ByteIndexedBmToByteGrayXparOver)(BLIT_PARAMS)715{716jint *srcLut = pSrcInfo->lutBase;717juint lutSize = pSrcInfo->lutSize;718mlib_u8 LutU8[256];719mlib_u32 LutU32[256];720mlib_s32 dstScan = pDstInfo->scanStride;721mlib_s32 srcScan = pSrcInfo->scanStride;722mlib_s32 i, j, x0, x1, mask, res;723724if (width < 16) {725for (j = 0; j < height; j++) {726mlib_u8 *src = srcBase;727mlib_u8 *dst = dstBase;728729for (i = 0; i < width; i++) {730mlib_s32 argb = srcLut[src[i]];731if (argb < 0) {732int r, g, b;733b = (argb) & 0xff;734g = (argb >> 8) & 0xff;735r = (argb >> 16) & 0xff;736dst[i] = RGB2GRAY(r, g, b);737}738}739740PTR_ADD(dstBase, dstScan);741PTR_ADD(srcBase, srcScan);742}743return;744}745746if (lutSize >= 256) lutSize = 256;747748ADD_SUFF(IntArgbToByteGrayConvert)(srcLut, LutU8, lutSize, 1,749pSrcInfo, pDstInfo, pPrim, pCompInfo);750751for (i = lutSize; i < 256; i++) {752LutU8[i] = 0;753}754755#pragma pipeloop(0)756for (i = 0; i < 256; i++) {757LutU32[i] = ((srcLut[i] >> 31) & 0xFF0000) | LutU8[i];758}759760if (srcScan == width && dstScan == width) {761width *= height;762height = 1;763}764765for (j = 0; j < height; j++) {766mlib_u8 *src = srcBase;767mlib_u8 *dst = dstBase;768mlib_u8 *dst_end = dst + width;769770if ((mlib_s32)dst & 1) {771x0 = *src;772res = LutU32[x0];773mask = res >> 16;774*dst++ = (res & mask) | (*dst &~ mask);775src++;776}777778#pragma pipeloop(0)779for (; dst <= (dst_end - 2); dst += 2) {780x0 = src[0];781x1 = src[1];782res = (LutU32[x0] << 8) | LutU32[x1];783mask = res >> 16;784((mlib_u16*)dst)[0] = (res & mask) | (((mlib_u16*)dst)[0] &~ mask);785src += 2;786}787788if (dst < dst_end) {789x0 = *src;790res = LutU32[x0];791mask = res >> 16;792*dst = (res & mask) | (*dst &~ mask);793}794795PTR_ADD(dstBase, dstScan);796PTR_ADD(srcBase, srcScan);797}798}799800/***************************************************************/801802void ADD_SUFF(ByteIndexedBmToByteGrayXparBgCopy)(BCOPY_PARAMS)803{804jint *srcLut = pSrcInfo->lutBase;805juint lutSize = pSrcInfo->lutSize;806mlib_u8 LutU8[256];807mlib_s32 dstScan = pDstInfo->scanStride;808mlib_s32 srcScan = pSrcInfo->scanStride;809mlib_s32 i, j;810811if (width < 16) {812for (j = 0; j < height; j++) {813mlib_u8 *src = srcBase;814mlib_u8 *dst = dstBase;815816for (i = 0; i < width; i++) {817mlib_s32 argb = srcLut[src[i]];818if (argb < 0) {819int r, g, b;820b = (argb) & 0xff;821g = (argb >> 8) & 0xff;822r = (argb >> 16) & 0xff;823dst[i] = RGB2GRAY(r, g, b);824} else {825dst[i] = bgpixel;826}827}828829PTR_ADD(dstBase, dstScan);830PTR_ADD(srcBase, srcScan);831}832return;833}834835if (lutSize >= 256) lutSize = 256;836837ADD_SUFF(IntArgbToByteGrayConvert)(srcLut, LutU8, lutSize, 1,838pSrcInfo, pDstInfo, pPrim, pCompInfo);839840for (i = lutSize; i < 256; i++) {841LutU8[i] = 0;842}843844#pragma pipeloop(0)845for (i = 0; i < 256; i++) {846if (srcLut[i] >= 0) LutU8[i] = bgpixel;847}848849if (srcScan == width && dstScan == width) {850width *= height;851height = 1;852}853854for (j = 0; j < height; j++) {855mlib_u8 *src = srcBase;856mlib_u8 *dst = dstBase;857mlib_u8 *dst_end = dst + width;858859if ((mlib_s32)dst & 1) {860*dst++ = LutU8[*src];861src++;862}863864#pragma pipeloop(0)865for (; dst <= (dst_end - 2); dst += 2) {866((mlib_u16*)dst)[0] = (LutU8[src[0]] << 8) | LutU8[src[1]];867src += 2;868}869870if (dst < dst_end) {871*dst++ = LutU8[*src];872src++;873}874875PTR_ADD(dstBase, dstScan);876PTR_ADD(srcBase, srcScan);877}878}879880/***************************************************************/881882void ADD_SUFF(ByteIndexedBmToByteGrayScaleXparOver)(SCALE_PARAMS)883{884jint *srcLut = pSrcInfo->lutBase;885juint lutSize = pSrcInfo->lutSize;886mlib_u8 LutU8[256];887mlib_u32 LutU32[256];888mlib_s32 dstScan = pDstInfo->scanStride;889mlib_s32 srcScan = pSrcInfo->scanStride;890mlib_s32 i, j, x0, x1, mask, res;891892if (width < 16) {893for (j = 0; j < height; j++) {894mlib_u8 *src = srcBase;895mlib_u8 *dst = dstBase;896jint tmpsxloc = sxloc;897898PTR_ADD(src, (syloc >> shift) * srcScan);899900for (i = 0; i < width; i++) {901mlib_s32 argb = srcLut[src[tmpsxloc >> shift]];902if (argb < 0) {903int r, g, b;904b = (argb) & 0xff;905g = (argb >> 8) & 0xff;906r = (argb >> 16) & 0xff;907dst[i] = RGB2GRAY(r, g, b);908}909tmpsxloc += sxinc;910}911912PTR_ADD(dstBase, dstScan);913syloc += syinc;914}915return;916}917918if (lutSize >= 256) lutSize = 256;919920ADD_SUFF(IntArgbToByteGrayConvert)(srcLut, LutU8, lutSize, 1,921pSrcInfo, pDstInfo, pPrim, pCompInfo);922923for (i = lutSize; i < 256; i++) {924LutU8[i] = 0;925}926927#pragma pipeloop(0)928for (i = 0; i < 256; i++) {929LutU32[i] = ((srcLut[i] >> 31) & 0xFF0000) | LutU8[i];930}931932for (j = 0; j < height; j++) {933mlib_u8 *src = srcBase;934mlib_u8 *dst = dstBase;935mlib_u8 *dst_end = dst + width;936jint tmpsxloc = sxloc;937938PTR_ADD(src, (syloc >> shift) * srcScan);939940if ((mlib_s32)dst & 1) {941x0 = src[tmpsxloc >> shift];942res = LutU32[x0];943mask = res >> 16;944*dst++ = (res & mask) | (*dst &~ mask);945tmpsxloc += sxinc;946}947948#pragma pipeloop(0)949for (; dst <= (dst_end - 2); dst += 2) {950x0 = src[tmpsxloc >> shift];951x1 = src[(tmpsxloc + sxinc) >> shift];952res = (LutU32[x0] << 8) | LutU32[x1];953mask = res >> 16;954((mlib_u16*)dst)[0] = (res & mask) | (((mlib_u16*)dst)[0] &~ mask);955tmpsxloc += 2*sxinc;956}957958if (dst < dst_end) {959x0 = src[tmpsxloc >> shift];960res = LutU32[x0];961mask = res >> 16;962*dst = (res & mask) | (*dst &~ mask);963}964965PTR_ADD(dstBase, dstScan);966syloc += syinc;967}968}969970/***************************************************************/971972#endif973974975