Path: blob/master/src/java.desktop/share/native/libawt/java2d/loops/ByteIndexed.c
41159 views
/*1* Copyright (c) 2000, 2004, 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#include <string.h>2627#include "AnyByte.h"28#include "ByteIndexed.h"29#include "AlphaMacros.h"3031#include "IntArgb.h"32#include "IntArgbBm.h"33#include "IntArgbPre.h"34#include "IntRgb.h"35#include "ThreeByteBgr.h"36#include "ByteGray.h"37#include "Index12Gray.h"3839/*40* This file declares, registers, and defines the various graphics41* primitive loops to manipulate surfaces of type "ByteIndexed".42*43* See also LoopMacros.h44*/4546RegisterFunc RegisterByteIndexed;4748DECLARE_CONVERT_BLIT(IntArgb, ByteIndexed);49DECLARE_CONVERT_BLIT(ThreeByteBgr, ByteIndexed);50DECLARE_CONVERT_BLIT(ByteGray, ByteIndexed);51DECLARE_CONVERT_BLIT(ByteIndexed, ByteIndexed);52DECLARE_CONVERT_BLIT(Index12Gray, ByteIndexed);53DECLARE_SCALE_BLIT(IntArgb, ByteIndexed);54DECLARE_SCALE_BLIT(ThreeByteBgr, ByteIndexed);55DECLARE_SCALE_BLIT(ByteGray, ByteIndexed);56DECLARE_SCALE_BLIT(Index12Gray, ByteIndexed);57DECLARE_SCALE_BLIT(ByteIndexed, ByteIndexed);58DECLARE_XPAR_CONVERT_BLIT(ByteIndexedBm, ByteIndexed);59DECLARE_XPAR_SCALE_BLIT(ByteIndexedBm, ByteIndexed);60DECLARE_XPAR_SCALE_BLIT(IntArgbBm, ByteIndexed);61DECLARE_XPAR_BLITBG(ByteIndexedBm, ByteIndexed);62DECLARE_XPAR_CONVERT_BLIT(IntArgbBm, ByteIndexed);63DECLARE_XPAR_BLITBG(IntArgbBm, ByteIndexed);6465DECLARE_XOR_BLIT(IntArgb, ByteIndexed);66DECLARE_ALPHA_MASKFILL(ByteIndexed);67DECLARE_ALPHA_MASKBLIT(IntArgb, ByteIndexed);68DECLARE_ALPHA_MASKBLIT(IntArgbPre, ByteIndexed);69DECLARE_ALPHA_MASKBLIT(IntRgb, ByteIndexed);70DECLARE_SOLID_DRAWGLYPHLISTAA(ByteIndexed);7172DECLARE_TRANSFORMHELPER_FUNCS(ByteIndexed);73DECLARE_TRANSFORMHELPER_FUNCS(ByteIndexedBm);7475NativePrimitive ByteIndexedPrimitives[] = {76REGISTER_CONVERT_BLIT(IntArgb, ByteIndexed),77REGISTER_CONVERT_BLIT_EQUIV(IntRgb, ByteIndexed,78NAME_CONVERT_BLIT(IntArgb, ByteIndexed)),79REGISTER_CONVERT_BLIT_EQUIV(IntArgbBm, ByteIndexed,80NAME_CONVERT_BLIT(IntArgb, ByteIndexed)),81REGISTER_CONVERT_BLIT(ThreeByteBgr, ByteIndexed),82REGISTER_CONVERT_BLIT(ByteGray, ByteIndexed),83REGISTER_CONVERT_BLIT(Index12Gray, ByteIndexed),84REGISTER_CONVERT_BLIT_FLAGS(ByteIndexed, ByteIndexed, 0, SD_LOCK_LUT),85REGISTER_SCALE_BLIT(IntArgb, ByteIndexed),86REGISTER_SCALE_BLIT_EQUIV(IntRgb, ByteIndexed,87NAME_SCALE_BLIT(IntArgb, ByteIndexed)),88REGISTER_SCALE_BLIT_EQUIV(IntArgbBm, ByteIndexed,89NAME_SCALE_BLIT(IntArgb, ByteIndexed)),90REGISTER_SCALE_BLIT(ThreeByteBgr, ByteIndexed),91REGISTER_SCALE_BLIT(ByteGray, ByteIndexed),92REGISTER_SCALE_BLIT(Index12Gray, ByteIndexed),93REGISTER_SCALE_BLIT_FLAGS(ByteIndexed, ByteIndexed, 0, SD_LOCK_LUT),94REGISTER_XPAR_CONVERT_BLIT(ByteIndexedBm, ByteIndexed),95REGISTER_XPAR_SCALE_BLIT(ByteIndexedBm, ByteIndexed),96REGISTER_XPAR_SCALE_BLIT(IntArgbBm, ByteIndexed),97REGISTER_XPAR_BLITBG(ByteIndexedBm, ByteIndexed),98REGISTER_XPAR_CONVERT_BLIT(IntArgbBm, ByteIndexed),99REGISTER_XPAR_BLITBG(IntArgbBm, ByteIndexed),100101REGISTER_XOR_BLIT(IntArgb, ByteIndexed),102REGISTER_ALPHA_MASKFILL(ByteIndexed),103REGISTER_ALPHA_MASKBLIT(IntArgb, ByteIndexed),104REGISTER_ALPHA_MASKBLIT(IntArgbPre, ByteIndexed),105REGISTER_ALPHA_MASKBLIT(IntRgb, ByteIndexed),106REGISTER_SOLID_DRAWGLYPHLISTAA(ByteIndexed),107108REGISTER_TRANSFORMHELPER_FUNCS(ByteIndexed),109REGISTER_TRANSFORMHELPER_FUNCS(ByteIndexedBm),110};111112jboolean RegisterByteIndexed(JNIEnv *env)113{114return RegisterPrimitives(env, ByteIndexedPrimitives,115ArraySize(ByteIndexedPrimitives));116}117118jint PixelForByteIndexed(SurfaceDataRasInfo *pRasInfo, jint rgb)119{120jint r, g, b;121ExtractIntDcmComponentsX123(rgb, r, g, b);122return SurfaceData_InvColorMap(pRasInfo->invColorTable, r, g, b);123}124125jboolean checkSameLut(jint *SrcReadLut, jint *DstReadLut,126SurfaceDataRasInfo *pSrcInfo,127SurfaceDataRasInfo *pDstInfo)128{129if (SrcReadLut != DstReadLut) {130juint lutSize = pSrcInfo->lutSize;131if (lutSize > pDstInfo->lutSize) {132return JNI_FALSE;133} else {134juint i;135for (i = 0; i < lutSize; i++) {136if (SrcReadLut[i] != DstReadLut[i]) {137return JNI_FALSE;138}139}140}141}142return JNI_TRUE;143}144145DEFINE_CONVERT_BLIT(IntArgb, ByteIndexed, 3ByteRgb)146147DEFINE_CONVERT_BLIT(ThreeByteBgr, ByteIndexed, 3ByteRgb)148149DEFINE_CONVERT_BLIT(ByteGray, ByteIndexed, 3ByteRgb)150151DEFINE_CONVERT_BLIT(Index12Gray, ByteIndexed, 3ByteRgb)152153void NAME_CONVERT_BLIT(ByteIndexed, ByteIndexed)154(void *srcBase, void *dstBase,155juint width, juint height,156SurfaceDataRasInfo *pSrcInfo,157SurfaceDataRasInfo *pDstInfo,158NativePrimitive *pPrim,159CompositeInfo *pCompInfo)160{161DeclareByteIndexedLoadVars(SrcRead)162DeclareByteIndexedLoadVars(DstRead)163jint srcScan = pSrcInfo->scanStride;164jint dstScan = pDstInfo->scanStride;165166InitByteIndexedLoadVars(SrcRead, pSrcInfo);167InitByteIndexedLoadVars(DstRead, pDstInfo);168169if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) {170do {171memcpy(dstBase, srcBase, width);172srcBase = PtrAddBytes(srcBase, srcScan);173dstBase = PtrAddBytes(dstBase, dstScan);174} while (--height > 0);175} else {176DeclareByteIndexedStoreVars(DstWrite);177178BlitLoopWidthHeight(ByteIndexed, pSrc, srcBase, pSrcInfo,179ByteIndexed, pDst, dstBase, pDstInfo, DstWrite,180width, height,181ConvertVia3ByteRgb182(pSrc, ByteIndexed, SrcRead,183pDst, ByteIndexed, DstWrite, 0, 0));184}185}186187DEFINE_SCALE_BLIT(IntArgb, ByteIndexed, 3ByteRgb)188189DEFINE_SCALE_BLIT(ThreeByteBgr, ByteIndexed, 3ByteRgb)190191DEFINE_SCALE_BLIT(ByteGray, ByteIndexed, 3ByteRgb)192193DEFINE_SCALE_BLIT(Index12Gray, ByteIndexed, 3ByteRgb)194195void NAME_SCALE_BLIT(ByteIndexed, ByteIndexed)196(void *srcBase, void *dstBase,197juint width, juint height,198jint sxloc, jint syloc,199jint sxinc, jint syinc, jint shift,200SurfaceDataRasInfo *pSrcInfo,201SurfaceDataRasInfo *pDstInfo,202NativePrimitive *pPrim,203CompositeInfo *pCompInfo)204{205DeclareByteIndexedLoadVars(SrcRead)206DeclareByteIndexedLoadVars(DstRead)207jint srcScan = pSrcInfo->scanStride;208jint dstScan = pDstInfo->scanStride;209DeclareByteIndexedStoreVars(DstWrite)210211InitByteIndexedLoadVars(SrcRead, pSrcInfo);212InitByteIndexedLoadVars(DstRead, pDstInfo);213214if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) {215BlitLoopScaleWidthHeight(ByteIndexed, pSrc, srcBase, pSrcInfo,216ByteIndexed, pDst, dstBase, pDstInfo, DstWrite,217x, width, height,218sxloc, syloc, sxinc, syinc, shift,219pDst[0] = pSrc[x]);220} else {221BlitLoopScaleWidthHeight(ByteIndexed, pSrc, srcBase, pSrcInfo,222ByteIndexed, pDst, dstBase, pDstInfo, DstWrite,223x, width, height,224sxloc, syloc, sxinc, syinc, shift,225ConvertVia3ByteRgb(pSrc, ByteIndexed, SrcRead,226pDst, ByteIndexed, DstWrite,227x, 0));228}229}230231DEFINE_XPAR_CONVERT_BLIT_LUT8(ByteIndexedBm, ByteIndexed, ConvertOnTheFly)232233DEFINE_XPAR_SCALE_BLIT_LUT8(ByteIndexedBm, ByteIndexed, ConvertOnTheFly)234235DEFINE_XPAR_SCALE_BLIT(IntArgbBm, ByteIndexed, 1IntRgb)236237DEFINE_XPAR_BLITBG_LUT8(ByteIndexedBm, ByteIndexed, ConvertOnTheFly)238239DEFINE_XPAR_CONVERT_BLIT(IntArgbBm, ByteIndexed, 1IntRgb)240241DEFINE_XPAR_BLITBG(IntArgbBm, ByteIndexed, 1IntRgb)242243DEFINE_XOR_BLIT(IntArgb, ByteIndexed, AnyByte)244245DEFINE_ALPHA_MASKFILL(ByteIndexed, 4ByteArgb)246247DEFINE_ALPHA_MASKBLIT(IntArgb, ByteIndexed, 4ByteArgb)248249DEFINE_ALPHA_MASKBLIT(IntArgbPre, ByteIndexed, 4ByteArgb)250251DEFINE_ALPHA_MASKBLIT(IntRgb, ByteIndexed, 4ByteArgb)252253DEFINE_SOLID_DRAWGLYPHLISTAA(ByteIndexed, 3ByteRgb)254255DEFINE_TRANSFORMHELPERS(ByteIndexed)256257DEFINE_TRANSFORMHELPERS(ByteIndexedBm)258259260