Path: blob/master/src/java.desktop/share/native/libawt/java2d/loops/Index12Gray.c
41159 views
/*1* Copyright (c) 2001, 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 "AnyShort.h"28#include "Index12Gray.h"29#include "AlphaMacros.h"3031#include "IntArgb.h"32#include "IntArgbPre.h"33#include "IntRgb.h"34#include "ThreeByteBgr.h"35#include "ByteGray.h"36#include "ByteIndexed.h"37#include "Index8Gray.h"3839/*40* This file declares, registers, and defines the various graphics41* primitive loops to manipulate surfaces of type "Index12Gray".42*43* See also LoopMacros.h44*/4546RegisterFunc RegisterIndex12Gray;4748DECLARE_CONVERT_BLIT(Index12Gray, IntArgb);49DECLARE_CONVERT_BLIT(IntArgb, Index12Gray);50DECLARE_CONVERT_BLIT(ThreeByteBgr, Index12Gray);51DECLARE_CONVERT_BLIT(ByteGray, Index12Gray);52DECLARE_CONVERT_BLIT(Index8Gray, Index12Gray);53DECLARE_CONVERT_BLIT(ByteIndexed, Index12Gray);54DECLARE_CONVERT_BLIT(Index12Gray, Index12Gray);5556DECLARE_SCALE_BLIT(Index12Gray, Index12Gray);57DECLARE_SCALE_BLIT(Index12Gray, IntArgb);58DECLARE_SCALE_BLIT(IntArgb, Index12Gray);59DECLARE_SCALE_BLIT(ThreeByteBgr, Index12Gray);60DECLARE_SCALE_BLIT(UshortGray, Index12Gray);61DECLARE_SCALE_BLIT(ByteIndexed, Index12Gray);62DECLARE_SCALE_BLIT(ByteGray, Index12Gray);63DECLARE_SCALE_BLIT(Index8Gray, Index12Gray);6465DECLARE_XPAR_CONVERT_BLIT(ByteIndexedBm, Index12Gray);66DECLARE_XPAR_BLITBG(ByteIndexedBm, Index12Gray);6768DECLARE_XOR_BLIT(IntArgb, Index12Gray);69DECLARE_ALPHA_MASKFILL(Index12Gray);70DECLARE_ALPHA_MASKBLIT(IntArgb, Index12Gray);71DECLARE_ALPHA_MASKBLIT(IntArgbPre, Index12Gray);72DECLARE_ALPHA_MASKBLIT(IntRgb, Index12Gray);73DECLARE_SRCOVER_MASKFILL(Index12Gray);74DECLARE_SRCOVER_MASKBLIT(IntArgb, Index12Gray);75DECLARE_SRCOVER_MASKBLIT(IntArgbPre, Index12Gray);76DECLARE_SOLID_DRAWGLYPHLISTAA(Index12Gray);7778DECLARE_TRANSFORMHELPER_FUNCS(Index12Gray);7980NativePrimitive Index12GrayPrimitives[] = {81REGISTER_CONVERT_BLIT(IntArgb, Index12Gray),82REGISTER_CONVERT_BLIT_EQUIV(IntRgb, Index12Gray,83NAME_CONVERT_BLIT(IntArgb, Index12Gray)),84REGISTER_CONVERT_BLIT(ThreeByteBgr, Index12Gray),85REGISTER_CONVERT_BLIT(ByteGray, Index12Gray),86REGISTER_CONVERT_BLIT(Index8Gray, Index12Gray),87REGISTER_CONVERT_BLIT_FLAGS(Index12Gray, Index12Gray,88SD_LOCK_LUT,89SD_LOCK_LUT | SD_LOCK_INVGRAY),90REGISTER_CONVERT_BLIT(ByteIndexed, Index12Gray),9192REGISTER_SCALE_BLIT(Index12Gray, IntArgb),93REGISTER_SCALE_BLIT(IntArgb, Index12Gray),94REGISTER_SCALE_BLIT_EQUIV(IntRgb, Index12Gray,95NAME_SCALE_BLIT(IntArgb, Index12Gray)),96REGISTER_SCALE_BLIT(ThreeByteBgr, Index12Gray),97REGISTER_SCALE_BLIT(UshortGray, Index12Gray),98REGISTER_SCALE_BLIT(ByteIndexed, Index12Gray),99REGISTER_SCALE_BLIT(ByteGray, Index12Gray),100REGISTER_SCALE_BLIT(Index8Gray, Index12Gray),101REGISTER_SCALE_BLIT_FLAGS(Index12Gray, Index12Gray, 0,102SD_LOCK_LUT | SD_LOCK_INVGRAY),103104REGISTER_XPAR_CONVERT_BLIT(ByteIndexedBm, Index12Gray),105REGISTER_XPAR_BLITBG(ByteIndexedBm, Index12Gray),106107REGISTER_XOR_BLIT(IntArgb, Index12Gray),108REGISTER_ALPHA_MASKFILL(Index12Gray),109REGISTER_ALPHA_MASKBLIT(IntArgb, Index12Gray),110REGISTER_ALPHA_MASKBLIT(IntArgbPre, Index12Gray),111REGISTER_ALPHA_MASKBLIT(IntRgb, Index12Gray),112REGISTER_SRCOVER_MASKFILL(Index12Gray),113REGISTER_SRCOVER_MASKBLIT(IntArgb, Index12Gray),114REGISTER_SRCOVER_MASKBLIT(IntArgbPre, Index12Gray),115REGISTER_SOLID_DRAWGLYPHLISTAA(Index12Gray),116117REGISTER_TRANSFORMHELPER_FUNCS(Index12Gray),118};119120extern jboolean checkSameLut(jint *SrcReadLut, jint *DstReadLut,121SurfaceDataRasInfo *pSrcInfo,122SurfaceDataRasInfo *pDstInfo);123124jboolean RegisterIndex12Gray(JNIEnv *env)125{126return RegisterPrimitives(env, Index12GrayPrimitives,127ArraySize(Index12GrayPrimitives));128}129130jint PixelForIndex12Gray(SurfaceDataRasInfo *pRasInfo, jint rgb)131{132jint r, g, b, gray;133ExtractIntDcmComponentsX123(rgb, r, g, b);134gray = ComposeByteGrayFrom3ByteRgb(r, g, b);135return pRasInfo->invGrayTable[gray];136}137138DEFINE_CONVERT_BLIT(IntArgb, Index12Gray, 3ByteRgb)139140DEFINE_CONVERT_BLIT(ThreeByteBgr, Index12Gray, 3ByteRgb)141142DEFINE_CONVERT_BLIT(ByteGray, Index12Gray, 1ByteGray)143144DEFINE_CONVERT_BLIT(Index8Gray, Index12Gray, 1ByteGray)145146DEFINE_CONVERT_BLIT(ByteIndexed, Index12Gray, 3ByteRgb)147148void NAME_CONVERT_BLIT(Index12Gray, Index12Gray)149(void *srcBase, void *dstBase,150juint width, juint height,151SurfaceDataRasInfo *pSrcInfo,152SurfaceDataRasInfo *pDstInfo,153NativePrimitive *pPrim,154CompositeInfo *pCompInfo)155{156DeclareIndex12GrayLoadVars(SrcRead)157DeclareIndex12GrayLoadVars(DstRead)158jint srcScan = pSrcInfo->scanStride;159jint dstScan = pDstInfo->scanStride;160161InitIndex12GrayLoadVars(SrcRead, pSrcInfo);162InitIndex12GrayLoadVars(DstRead, pDstInfo);163164if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) {165do {166memcpy(dstBase, srcBase, width);167srcBase = PtrAddBytes(srcBase, srcScan);168dstBase = PtrAddBytes(dstBase, dstScan);169} while (--height > 0);170} else {171DeclareIndex12GrayStoreVars(DstWrite);172InitIndex12GrayStoreVarsY(DstWrite, pDstInfo);173174BlitLoopWidthHeight(Index12Gray, pSrc, srcBase, pSrcInfo,175Index12Gray, pDst, dstBase, pDstInfo, DstWrite,176width, height,177ConvertVia1ByteGray178(pSrc, Index12Gray, SrcRead,179pDst, Index12Gray, DstWrite, 0, 0));180}181}182183void NAME_SCALE_BLIT(Index12Gray, Index12Gray)184(void *srcBase, void *dstBase,185juint width, juint height,186jint sxloc, jint syloc,187jint sxinc, jint syinc, jint shift,188SurfaceDataRasInfo *pSrcInfo,189SurfaceDataRasInfo *pDstInfo,190NativePrimitive *pPrim,191CompositeInfo *pCompInfo)192{193DeclareIndex8GrayLoadVars(SrcRead)194DeclareIndex8GrayLoadVars(DstRead)195jint srcScan = pSrcInfo->scanStride;196jint dstScan = pDstInfo->scanStride;197DeclareIndex8GrayStoreVars(DstWrite)198199InitIndex8GrayLoadVars(SrcRead, pSrcInfo);200InitIndex8GrayLoadVars(DstRead, pDstInfo);201202if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) {203BlitLoopScaleWidthHeight(Index8Gray, pSrc, srcBase, pSrcInfo,204Index8Gray, pDst, dstBase, pDstInfo, DstWrite,205x, width, height,206sxloc, syloc, sxinc, syinc, shift,207pDst[0] = pSrc[x]);208} else {209DeclareIndex8GrayStoreVars(DstWrite);210InitIndex8GrayStoreVarsY(DstWrite, pDstInfo);211BlitLoopScaleWidthHeight(Index8Gray, pSrc, srcBase, pSrcInfo,212Index8Gray, pDst, dstBase, pDstInfo, DstWrite,213x, width, height,214sxloc, syloc, sxinc, syinc, shift,215ConvertVia1ByteGray(pSrc, Index8Gray, SrcRead,216pDst, Index8Gray, DstWrite,217x, 0));218}219}220221DEFINE_SCALE_BLIT(Index12Gray, IntArgb, 1IntArgb)222223DEFINE_SCALE_BLIT(IntArgb, Index12Gray, 3ByteRgb)224225DEFINE_SCALE_BLIT(ThreeByteBgr, Index12Gray, 3ByteRgb)226227DEFINE_SCALE_BLIT(UshortGray, Index12Gray, 1ByteGray)228229DEFINE_SCALE_BLIT_LUT8(ByteIndexed, Index12Gray, PreProcessLut)230231DEFINE_SCALE_BLIT(ByteGray, Index12Gray, 1ByteGray)232233DEFINE_SCALE_BLIT_LUT8(Index8Gray, Index12Gray, PreProcessLut)234235DEFINE_XPAR_CONVERT_BLIT_LUT8(ByteIndexedBm, Index12Gray, PreProcessLut)236237DEFINE_XPAR_BLITBG_LUT8(ByteIndexedBm, Index12Gray, PreProcessLut)238239DEFINE_XOR_BLIT(IntArgb, Index12Gray, AnyShort)240241DEFINE_ALPHA_MASKFILL(Index12Gray, 1ByteGray)242243DEFINE_ALPHA_MASKBLIT(IntArgb, Index12Gray, 1ByteGray)244245DEFINE_ALPHA_MASKBLIT(IntArgbPre, Index12Gray, 1ByteGray)246247DEFINE_ALPHA_MASKBLIT(IntRgb, Index12Gray, 1ByteGray)248249DEFINE_SRCOVER_MASKFILL(Index12Gray, 1ByteGray)250251DEFINE_SRCOVER_MASKBLIT(IntArgb, Index12Gray, 1ByteGray)252253DEFINE_SRCOVER_MASKBLIT(IntArgbPre, Index12Gray, 1ByteGray)254255DEFINE_SOLID_DRAWGLYPHLISTAA(Index12Gray, 1ByteGray)256257DEFINE_TRANSFORMHELPERS(Index12Gray)258259260