Path: blob/master/src/java.desktop/share/native/libawt/java2d/loops/Index8Gray.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>26#include <stdio.h>27#include "AnyByte.h"28#include "Index8Gray.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 "Index12Gray.h"3839/*40* This file declares, registers, and defines the various graphics41* primitive loops to manipulate surfaces of type "Index8Gray".42*43* See also LoopMacros.h44*/4546RegisterFunc RegisterIndex8Gray;4748DECLARE_CONVERT_BLIT(IntArgb, Index8Gray);49DECLARE_CONVERT_BLIT(ThreeByteBgr, Index8Gray);50DECLARE_CONVERT_BLIT(ByteGray, Index8Gray);51DECLARE_CONVERT_BLIT(Index12Gray, Index8Gray);52DECLARE_CONVERT_BLIT(ByteIndexed, Index8Gray);53DECLARE_CONVERT_BLIT(Index8Gray, Index8Gray);5455DECLARE_SCALE_BLIT(Index8Gray, Index8Gray);56DECLARE_SCALE_BLIT(IntArgb, Index8Gray);57DECLARE_SCALE_BLIT(ThreeByteBgr, Index8Gray);58DECLARE_SCALE_BLIT(UshortGray, Index8Gray);59DECLARE_SCALE_BLIT(ByteIndexed, Index8Gray);60DECLARE_SCALE_BLIT(ByteGray, Index8Gray);61DECLARE_SCALE_BLIT(Index12Gray, Index8Gray);6263DECLARE_XPAR_CONVERT_BLIT(ByteIndexedBm, Index8Gray);64DECLARE_XPAR_BLITBG(ByteIndexedBm, Index8Gray);6566DECLARE_XOR_BLIT(IntArgb, Index8Gray);67DECLARE_ALPHA_MASKFILL(Index8Gray);68DECLARE_ALPHA_MASKBLIT(IntArgb, Index8Gray);69DECLARE_ALPHA_MASKBLIT(IntArgbPre, Index8Gray);70DECLARE_ALPHA_MASKBLIT(IntRgb, Index8Gray);71DECLARE_SRCOVER_MASKFILL(Index8Gray);72DECLARE_SRCOVER_MASKBLIT(IntArgb, Index8Gray);73DECLARE_SRCOVER_MASKBLIT(IntArgbPre, Index8Gray);74DECLARE_SOLID_DRAWGLYPHLISTAA(Index8Gray);7576DECLARE_TRANSFORMHELPER_FUNCS(Index8Gray);7778NativePrimitive Index8GrayPrimitives[] = {79REGISTER_CONVERT_BLIT(IntArgb, Index8Gray),80REGISTER_CONVERT_BLIT_EQUIV(IntRgb, Index8Gray,81NAME_CONVERT_BLIT(IntArgb, Index8Gray)),82REGISTER_CONVERT_BLIT(ThreeByteBgr, Index8Gray),83REGISTER_CONVERT_BLIT(ByteGray, Index8Gray),84REGISTER_CONVERT_BLIT(Index12Gray, Index8Gray),85REGISTER_CONVERT_BLIT_FLAGS(Index8Gray, Index8Gray,86SD_LOCK_LUT,87SD_LOCK_LUT | SD_LOCK_INVGRAY),88REGISTER_CONVERT_BLIT(ByteIndexed, Index8Gray),8990REGISTER_SCALE_BLIT(IntArgb, Index8Gray),91REGISTER_SCALE_BLIT_EQUIV(IntRgb, Index8Gray,92NAME_SCALE_BLIT(IntArgb, Index8Gray)),93REGISTER_SCALE_BLIT(ThreeByteBgr, Index8Gray),94REGISTER_SCALE_BLIT(UshortGray, Index8Gray),95REGISTER_SCALE_BLIT(ByteIndexed, Index8Gray),96REGISTER_SCALE_BLIT(ByteGray, Index8Gray),97REGISTER_SCALE_BLIT(Index12Gray, Index8Gray),98REGISTER_SCALE_BLIT_FLAGS(Index8Gray, Index8Gray, 0,99SD_LOCK_LUT | SD_LOCK_INVGRAY),100101REGISTER_XPAR_CONVERT_BLIT(ByteIndexedBm, Index8Gray),102REGISTER_XPAR_BLITBG(ByteIndexedBm, Index8Gray),103104REGISTER_XOR_BLIT(IntArgb, Index8Gray),105REGISTER_ALPHA_MASKFILL(Index8Gray),106REGISTER_ALPHA_MASKBLIT(IntArgb, Index8Gray),107REGISTER_ALPHA_MASKBLIT(IntArgbPre, Index8Gray),108REGISTER_ALPHA_MASKBLIT(IntRgb, Index8Gray),109REGISTER_SRCOVER_MASKFILL(Index8Gray),110REGISTER_SRCOVER_MASKBLIT(IntArgb, Index8Gray),111REGISTER_SRCOVER_MASKBLIT(IntArgbPre, Index8Gray),112REGISTER_SOLID_DRAWGLYPHLISTAA(Index8Gray),113114REGISTER_TRANSFORMHELPER_FUNCS(Index8Gray),115};116117extern jboolean checkSameLut(jint *SrcReadLut, jint *DstReadLut,118SurfaceDataRasInfo *pSrcInfo,119SurfaceDataRasInfo *pDstInfo);120121jboolean RegisterIndex8Gray(JNIEnv *env)122{123return RegisterPrimitives(env, Index8GrayPrimitives,124ArraySize(Index8GrayPrimitives));125}126127jint PixelForIndex8Gray(SurfaceDataRasInfo *pRasInfo, jint rgb)128{129jint r, g, b, gray;130ExtractIntDcmComponentsX123(rgb, r, g, b);131gray = ComposeByteGrayFrom3ByteRgb(r, g, b);132return pRasInfo->invGrayTable[gray];133}134135DEFINE_CONVERT_BLIT(IntArgb, Index8Gray, 3ByteRgb)136137DEFINE_CONVERT_BLIT(ThreeByteBgr, Index8Gray, 3ByteRgb)138139DEFINE_CONVERT_BLIT(ByteGray, Index8Gray, 1ByteGray)140141DEFINE_CONVERT_BLIT(Index12Gray, Index8Gray, 1ByteGray)142143DEFINE_CONVERT_BLIT_LUT8(ByteIndexed, Index8Gray, PreProcessLut)144145void NAME_CONVERT_BLIT(Index8Gray, Index8Gray)146(void *srcBase, void *dstBase,147juint width, juint height,148SurfaceDataRasInfo *pSrcInfo,149SurfaceDataRasInfo *pDstInfo,150NativePrimitive *pPrim,151CompositeInfo *pCompInfo)152{153DeclareIndex8GrayLoadVars(SrcRead)154DeclareIndex8GrayLoadVars(DstRead)155jint srcScan = pSrcInfo->scanStride;156jint dstScan = pDstInfo->scanStride;157158InitIndex8GrayLoadVars(SrcRead, pSrcInfo);159InitIndex8GrayLoadVars(DstRead, pDstInfo);160161if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) {162do {163memcpy(dstBase, srcBase, width);164srcBase = PtrAddBytes(srcBase, srcScan);165dstBase = PtrAddBytes(dstBase, dstScan);166} while (--height > 0);167} else {168DeclareIndex8GrayStoreVars(DstWrite);169InitIndex8GrayStoreVarsY(DstWrite, pDstInfo);170171BlitLoopWidthHeight(Index8Gray, pSrc, srcBase, pSrcInfo,172Index8Gray, pDst, dstBase, pDstInfo, DstWrite,173width, height,174ConvertVia1ByteGray175(pSrc, Index8Gray, SrcRead,176pDst, Index8Gray, DstWrite, 0, 0));177}178}179180void NAME_SCALE_BLIT(Index8Gray, Index8Gray)181(void *srcBase, void *dstBase,182juint width, juint height,183jint sxloc, jint syloc,184jint sxinc, jint syinc, jint shift,185SurfaceDataRasInfo *pSrcInfo,186SurfaceDataRasInfo *pDstInfo,187NativePrimitive *pPrim,188CompositeInfo *pCompInfo)189{190DeclareIndex8GrayLoadVars(SrcRead)191DeclareIndex8GrayLoadVars(DstRead)192jint srcScan = pSrcInfo->scanStride;193jint dstScan = pDstInfo->scanStride;194DeclareIndex8GrayStoreVars(DstWrite)195196InitIndex8GrayLoadVars(SrcRead, pSrcInfo);197InitIndex8GrayLoadVars(DstRead, pDstInfo);198199if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) {200BlitLoopScaleWidthHeight(Index8Gray, pSrc, srcBase, pSrcInfo,201Index8Gray, pDst, dstBase, pDstInfo, DstWrite,202x, width, height,203sxloc, syloc, sxinc, syinc, shift,204pDst[0] = pSrc[x]);205} else {206DeclareIndex8GrayStoreVars(DstWrite);207InitIndex8GrayStoreVarsY(DstWrite, pDstInfo);208BlitLoopScaleWidthHeight(Index8Gray, pSrc, srcBase, pSrcInfo,209Index8Gray, pDst, dstBase, pDstInfo, DstWrite,210x, width, height,211sxloc, syloc, sxinc, syinc, shift,212ConvertVia1ByteGray(pSrc, Index8Gray, SrcRead,213pDst, Index8Gray, DstWrite,214x, 0));215}216}217218DEFINE_SCALE_BLIT(IntArgb, Index8Gray, 3ByteRgb)219220DEFINE_SCALE_BLIT(ThreeByteBgr, Index8Gray, 3ByteRgb)221222DEFINE_SCALE_BLIT(UshortGray, Index8Gray, 1ByteGray)223224DEFINE_SCALE_BLIT_LUT8(ByteIndexed, Index8Gray, PreProcessLut)225226DEFINE_SCALE_BLIT(ByteGray, Index8Gray, 1ByteGray)227228DEFINE_SCALE_BLIT(Index12Gray, Index8Gray, 1ByteGray)229230DEFINE_XPAR_CONVERT_BLIT_LUT8(ByteIndexedBm, Index8Gray, PreProcessLut)231232DEFINE_XPAR_BLITBG_LUT8(ByteIndexedBm, Index8Gray, PreProcessLut)233234DEFINE_XOR_BLIT(IntArgb, Index8Gray, AnyByte)235236DEFINE_ALPHA_MASKFILL(Index8Gray, 1ByteGray)237238DEFINE_ALPHA_MASKBLIT(IntArgb, Index8Gray, 1ByteGray)239240DEFINE_ALPHA_MASKBLIT(IntArgbPre, Index8Gray, 1ByteGray)241242DEFINE_ALPHA_MASKBLIT(IntRgb, Index8Gray, 1ByteGray)243244DEFINE_SRCOVER_MASKFILL(Index8Gray, 1ByteGray)245246DEFINE_SRCOVER_MASKBLIT(IntArgb, Index8Gray, 1ByteGray)247248DEFINE_SRCOVER_MASKBLIT(IntArgbPre, Index8Gray, 1ByteGray)249250DEFINE_SOLID_DRAWGLYPHLISTAA(Index8Gray, 1ByteGray)251252DEFINE_TRANSFORMHELPERS(Index8Gray)253254255