Path: blob/master/src/java.desktop/share/native/libawt/java2d/loops/ByteIndexed.h
41159 views
/*1* Copyright (c) 2000, 2013, 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#ifndef ByteIndexed_h_Included26#define ByteIndexed_h_Included2728#include "IntDcm.h"2930/*31* This file contains macro and type definitions used by the macros in32* LoopMacros.h to manipulate a surface of type "ByteIndexed".33*/3435typedef jubyte ByteIndexedPixelType;36typedef jubyte ByteIndexedDataType;3738#define ByteIndexedPixelStride 139#define ByteIndexedBitsPerPixel 84041#define DeclareByteIndexedLoadVars(PREFIX) \42jint *PREFIX ## Lut;4344#define DeclareByteIndexedStoreVars(PREFIX) \45int PREFIX ## XDither, PREFIX ## YDither, PREFIX ## RepPrims; \46char *PREFIX ## rerr, *PREFIX ## gerr, *PREFIX ## berr; \47unsigned char *PREFIX ## InvLut;4849#define SetByteIndexedStoreVarsYPos(PREFIX, pRasInfo, LOC) \50do { \51PREFIX ## YDither = ((LOC & 7) << 3); \52} while (0)5354#define SetByteIndexedStoreVarsXPos(PREFIX, pRasInfo, LOC) \55do { \56PREFIX ## rerr = (pRasInfo)->redErrTable + PREFIX ## YDither; \57PREFIX ## gerr = (pRasInfo)->grnErrTable + PREFIX ## YDither; \58PREFIX ## berr = (pRasInfo)->bluErrTable + PREFIX ## YDither; \59PREFIX ## XDither = (LOC & 7); \60} while (0)6162#define InitByteIndexedLoadVars(PREFIX, pRasInfo) \63PREFIX ## Lut = (pRasInfo)->lutBase6465/* REMIND Could collapse Init..Store..X and Init..Store..Y into one Init66* and factor out the Set.. macros.67*/68#define InitByteIndexedStoreVarsY(PREFIX, pRasInfo) \69do { \70SetByteIndexedStoreVarsYPos(PREFIX, pRasInfo, (pRasInfo)->bounds.y1); \71PREFIX ## InvLut = (pRasInfo)->invColorTable; \72PREFIX ## RepPrims = (pRasInfo)->representsPrimaries; \73} while (0)7475#define InitByteIndexedStoreVarsX(PREFIX, pRasInfo) \76SetByteIndexedStoreVarsXPos(PREFIX, pRasInfo, (pRasInfo)->bounds.x1);777879#define NextByteIndexedStoreVarsX(PREFIX) \80PREFIX ## XDither = (PREFIX ## XDither + 1) & 78182#define NextByteIndexedStoreVarsY(PREFIX) \83PREFIX ## YDither = (PREFIX ## YDither + (1 << 3)) & (7 << 3)8485typedef jubyte ByteIndexedBmPixelType;86typedef jubyte ByteIndexedBmDataType;8788#define ByteIndexedBmPixelStride 189#define ByteIndexedBmBitsPerPixel 89091#define DeclareByteIndexedBmLoadVars DeclareByteIndexedLoadVars92#define DeclareByteIndexedBmStoreVars DeclareByteIndexedStoreVars93#define InitByteIndexedBmLoadVars InitByteIndexedLoadVars94#define InitByteIndexedBmStoreVarsY InitByteIndexedStoreVarsY95#define InitByteIndexedBmStoreVarsX InitByteIndexedStoreVarsX96#define NextByteIndexedBmStoreVarsX NextByteIndexedStoreVarsX97#define NextByteIndexedBmStoreVarsY NextByteIndexedStoreVarsY9899#define LoadByteIndexedBmTo1IntArgb LoadByteIndexedTo1IntArgb100101#define CopyByteIndexedBmToIntArgbPre(pRGB, i, PREFIX, pRow, x) \102do { \103jint argb = PREFIX ## Lut[pRow[x]]; \104(pRGB)[i] = argb & (argb >> 24); \105} while (0)106107108#define ByteIndexedXparLutEntry -1109#define ByteIndexedIsXparLutEntry(pix) (pix < 0)110#define StoreByteIndexedNonXparFromArgb StoreByteIndexedFrom1IntArgb111112#define StoreByteIndexedPixel(pRas, x, pixel) \113((pRas)[x] = (jubyte) (pixel))114115#define DeclareByteIndexedPixelData(PREFIX)116#define ExtractByteIndexedPixelData(PIXEL, PREFIX)117118#define StoreByteIndexedPixelData(pPix, x, pixel, PREFIX) \119(pPix)[x] = (jubyte) (pixel)120121#define ByteIndexedPixelFromArgb(pixel, rgb, pRasInfo) \122do { \123jint r, g, b; \124ExtractIntDcmComponentsX123(rgb, r, g, b); \125(pixel) = SurfaceData_InvColorMap((pRasInfo)->invColorTable, \126r, g, b); \127} while (0)128129#define LoadByteIndexedTo1IntRgb(pRas, PREFIX, x, rgb) \130(rgb) = PREFIX ## Lut[pRas[x]]131132#define LoadByteIndexedTo1IntArgb(pRas, PREFIX, x, argb) \133(argb) = PREFIX ## Lut[pRas[x]]134135#define LoadByteIndexedTo3ByteRgb(pRas, PREFIX, x, r, g, b) \136do { \137jint rgb = PREFIX ## Lut[pRas[x]]; \138ExtractIntDcmComponentsX123(rgb, r, g, b); \139} while (0)140141#define LoadByteIndexedTo4ByteArgb(pRas, PREFIX, x, a, r, g, b) \142do { \143jint argb = PREFIX ## Lut[pRas[x]]; \144ExtractIntDcmComponents1234(argb, a, r, g, b); \145} while (0)146147#define ByteClamp1Component(X) \148do { if (((X) >> 8) != 0) {X = (~(X >> 31)) & 255; } } while (0)149150#define ByteClamp3Components(R, G, B) \151do { \152if (((R|G|B) >> 8) != 0) { \153ByteClamp1Component(R); \154ByteClamp1Component(G); \155ByteClamp1Component(B); \156} \157} while (0)158159#define StoreByteIndexedFrom1IntRgb(pRas, PREFIX, x, rgb) \160do { \161int r, g, b; \162ExtractIntDcmComponentsX123(rgb, r, g, b); \163StoreByteIndexedFrom3ByteRgb(pRas, PREFIX, x, r, g, b); \164} while (0)165166#define StoreByteIndexedFrom1IntArgb(pRas, PREFIX, x, argb) \167StoreByteIndexedFrom1IntRgb(pRas, PREFIX, x, argb)168169#define StoreByteIndexedFrom3ByteRgb(pRas, PREFIX, x, r, g, b) \170do { \171if (!(((r == 0) || (r == 255)) && \172((g == 0) || (g == 255)) && \173((b == 0) || (b == 255)) && \174PREFIX ## RepPrims)) { \175r += PREFIX ## rerr[PREFIX ## XDither]; \176g += PREFIX ## gerr[PREFIX ## XDither]; \177b += PREFIX ## berr[PREFIX ## XDither]; \178} \179ByteClamp3Components(r, g, b); \180(pRas)[x] = SurfaceData_InvColorMap(PREFIX ## InvLut, r, g, b); \181} while (0)182183#define StoreByteIndexedFrom4ByteArgb(pRas, PREFIX, x, a, r, g, b) \184StoreByteIndexedFrom3ByteRgb(pRas, PREFIX, x, r, g, b)185186#define CopyByteIndexedToIntArgbPre(pRGB, i, PREFIX, pRow, x) \187do { \188jint argb = PREFIX ## Lut[pRow[x]]; \189jint a = URShift(argb, 24); \190if (a == 0) { \191argb = 0; \192} else if (a < 0xff) { \193jint r = (argb >> 16) & 0xff; \194jint g = (argb >> 8) & 0xff; \195jint b = (argb ) & 0xff; \196r = MUL8(a, r); \197g = MUL8(a, g); \198b = MUL8(a, b); \199argb = ComposeIntDcmComponents1234(a, r, g, b); \200} \201(pRGB)[i] = argb; \202} while (0)203204205#define DeclareByteIndexedAlphaLoadData(PREFIX) \206jint *PREFIX ## Lut; \207jint PREFIX ## rgb;208209#define InitByteIndexedAlphaLoadData(PREFIX, pRasInfo) \210do { \211PREFIX ## Lut = (pRasInfo)->lutBase; \212PREFIX ## rgb = 0; \213} while (0)214215#define LoadAlphaFromByteIndexedFor4ByteArgb(pRas, PREFIX, COMP_PREFIX) \216do { \217PREFIX ## rgb = PREFIX ## Lut[(pRas)[0]]; \218COMP_PREFIX ## A = ((juint) PREFIX ## rgb) >> 24; \219} while (0)220221#define Postload4ByteArgbFromByteIndexed(pRas, PREFIX, COMP_PREFIX) \222do { \223COMP_PREFIX ## R = (PREFIX ## rgb >> 16) & 0xff; \224COMP_PREFIX ## G = (PREFIX ## rgb >> 8) & 0xff; \225COMP_PREFIX ## B = (PREFIX ## rgb >> 0) & 0xff; \226} while (0)227228229#define ByteIndexedIsPremultiplied 0230231#define StoreByteIndexedFrom4ByteArgbComps(pRas, PREFIX, x, COMP_PREFIX) \232StoreByteIndexedFrom4ByteArgb(pRas, PREFIX, x, \233COMP_PREFIX ## A, COMP_PREFIX ## R, \234COMP_PREFIX ## G, COMP_PREFIX ## B)235236#endif /* ByteIndexed_h_Included */237238239