1 /* 2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #ifndef ByteIndexed_h_Included 27 #define ByteIndexed_h_Included 28 29 #include "IntDcm.h" 30 31 /* 32 * This file contains macro and type definitions used by the macros in 33 * LoopMacros.h to manipulate a surface of type "ByteIndexed". 34 */ 35 36 typedef jubyte ByteIndexedPixelType; 37 typedef jubyte ByteIndexedDataType; 38 39 #define ByteIndexedPixelStride 1 40 #define ByteIndexedBitsPerPixel 8 41 42 #define DeclareByteIndexedLoadVars(PREFIX) \ 43 jint *PREFIX ## Lut; 44 45 #define DeclareByteIndexedStoreVars(PREFIX) \ 46 int PREFIX ## XDither, PREFIX ## YDither, PREFIX ## RepPrims; \ 47 char *PREFIX ## rerr, *PREFIX ## gerr, *PREFIX ## berr; \ 48 unsigned char *PREFIX ## InvLut; 49 50 #define SetByteIndexedStoreVarsYPos(PREFIX, pRasInfo, LOC) \ 51 do { \ 52 PREFIX ## YDither = ((LOC & 7) << 3); \ 53 } while (0) 54 55 #define SetByteIndexedStoreVarsXPos(PREFIX, pRasInfo, LOC) \ 56 do { \ 57 PREFIX ## rerr = (pRasInfo)->redErrTable + PREFIX ## YDither; \ 58 PREFIX ## gerr = (pRasInfo)->grnErrTable + PREFIX ## YDither; \ 59 PREFIX ## berr = (pRasInfo)->bluErrTable + PREFIX ## YDither; \ 60 PREFIX ## XDither = (LOC & 7); \ 61 } while (0) 62 63 #define InitByteIndexedLoadVars(PREFIX, pRasInfo) \ 64 PREFIX ## Lut = (pRasInfo)->lutBase 65 66 /* REMIND Could collapse Init..Store..X and Init..Store..Y into one Init 67 * and factor out the Set.. macros. 68 */ 69 #define InitByteIndexedStoreVarsY(PREFIX, pRasInfo) \ 70 do { \ 71 SetByteIndexedStoreVarsYPos(PREFIX, pRasInfo, (pRasInfo)->bounds.y1); \ 72 PREFIX ## InvLut = (pRasInfo)->invColorTable; \ 73 PREFIX ## RepPrims = (pRasInfo)->representsPrimaries; \ 74 } while (0) 75 76 #define InitByteIndexedStoreVarsX(PREFIX, pRasInfo) \ 77 SetByteIndexedStoreVarsXPos(PREFIX, pRasInfo, (pRasInfo)->bounds.x1); 78 79 80 #define NextByteIndexedStoreVarsX(PREFIX) \ 81 PREFIX ## XDither = (PREFIX ## XDither + 1) & 7 82 83 #define NextByteIndexedStoreVarsY(PREFIX) \ 84 PREFIX ## YDither = (PREFIX ## YDither + (1 << 3)) & (7 << 3) 85 86 typedef jubyte ByteIndexedBmPixelType; 87 typedef jubyte ByteIndexedBmDataType; 88 89 #define ByteIndexedBmPixelStride 1 90 #define ByteIndexedBmBitsPerPixel 8 91 92 #define DeclareByteIndexedBmLoadVars DeclareByteIndexedLoadVars 93 #define DeclareByteIndexedBmStoreVars DeclareByteIndexedStoreVars 94 #define InitByteIndexedBmLoadVars InitByteIndexedLoadVars 95 #define InitByteIndexedBmStoreVarsY InitByteIndexedStoreVarsY 96 #define InitByteIndexedBmStoreVarsX InitByteIndexedStoreVarsX 97 #define NextByteIndexedBmStoreVarsX NextByteIndexedStoreVarsX 98 #define NextByteIndexedBmStoreVarsY NextByteIndexedStoreVarsY 99 100 #define LoadByteIndexedBmTo1IntArgb LoadByteIndexedTo1IntArgb 101 102 #define CopyByteIndexedBmToIntArgbPre(pRGB, i, PREFIX, pRow, x) \ 103 do { \ 104 jint argb = PREFIX ## Lut[pRow[x]]; \ 105 (pRGB)[i] = argb & (argb >> 24); \ 106 } while (0) 107 108 109 #define ByteIndexedXparLutEntry -1 110 #define ByteIndexedIsXparLutEntry(pix) (pix < 0) 111 #define StoreByteIndexedNonXparFromArgb StoreByteIndexedFrom1IntArgb 112 113 #define StoreByteIndexedPixel(pRas, x, pixel) \ 114 ((pRas)[x] = (jubyte) (pixel)) 115 116 #define DeclareByteIndexedPixelData(PREFIX) 117 #define ExtractByteIndexedPixelData(PIXEL, PREFIX) 118 119 #define StoreByteIndexedPixelData(pPix, x, pixel, PREFIX) \ 120 (pPix)[x] = (jubyte) (pixel) 121 122 #define ByteIndexedPixelFromArgb(pixel, rgb, pRasInfo) \ 123 do { \ 124 jint r, g, b; \ 125 ExtractIntDcmComponentsX123(rgb, r, g, b); \ 126 (pixel) = SurfaceData_InvColorMap((pRasInfo)->invColorTable, \ 127 r, g, b); \ 128 } while (0) 129 130 #define LoadByteIndexedTo1IntRgb(pRas, PREFIX, x, rgb) \ 131 (rgb) = PREFIX ## Lut[pRas[x]] 132 133 #define LoadByteIndexedTo1IntArgb(pRas, PREFIX, x, argb) \ 134 (argb) = PREFIX ## Lut[pRas[x]] 135 136 #define LoadByteIndexedTo3ByteRgb(pRas, PREFIX, x, r, g, b) \ 137 do { \ 138 jint rgb = PREFIX ## Lut[pRas[x]]; \ 139 ExtractIntDcmComponentsX123(rgb, r, g, b); \ 140 } while (0) 141 142 #define LoadByteIndexedTo4ByteArgb(pRas, PREFIX, x, a, r, g, b) \ 143 do { \ 144 jint argb = PREFIX ## Lut[pRas[x]]; \ 145 ExtractIntDcmComponents1234(argb, a, r, g, b); \ 146 } while (0) 147 148 #define ByteClamp1Component(X) \ 149 do { if (((X) >> 8) != 0) {X = (~(X >> 31)) & 255; } } while (0) 150 151 #define ByteClamp3Components(R, G, B) \ 152 do { \ 153 if (((R|G|B) >> 8) != 0) { \ 154 ByteClamp1Component(R); \ 155 ByteClamp1Component(G); \ 156 ByteClamp1Component(B); \ 157 } \ 158 } while (0) 159 160 #define StoreByteIndexedFrom1IntRgb(pRas, PREFIX, x, rgb) \ 161 do { \ 162 int r, g, b; \ 163 ExtractIntDcmComponentsX123(rgb, r, g, b); \ 164 StoreByteIndexedFrom3ByteRgb(pRas, PREFIX, x, r, g, b); \ 165 } while (0) 166 167 #define StoreByteIndexedFrom1IntArgb(pRas, PREFIX, x, argb) \ 168 StoreByteIndexedFrom1IntRgb(pRas, PREFIX, x, argb) 169 170 #define StoreByteIndexedFrom3ByteRgb(pRas, PREFIX, x, r, g, b) \ 171 do { \ 172 if (!(((r == 0) || (r == 255)) && \ 173 ((g == 0) || (g == 255)) && \ 174 ((b == 0) || (b == 255)) && \ 175 PREFIX ## RepPrims)) { \ 176 r += PREFIX ## rerr[PREFIX ## XDither]; \ 177 g += PREFIX ## gerr[PREFIX ## XDither]; \ 178 b += PREFIX ## berr[PREFIX ## XDither]; \ 179 } \ 180 ByteClamp3Components(r, g, b); \ 181 (pRas)[x] = SurfaceData_InvColorMap(PREFIX ## InvLut, r, g, b); \ 182 } while (0) 183 184 #define StoreByteIndexedFrom4ByteArgb(pRas, PREFIX, x, a, r, g, b) \ 185 StoreByteIndexedFrom3ByteRgb(pRas, PREFIX, x, r, g, b) 186 187 #define CopyByteIndexedToIntArgbPre(pRGB, i, PREFIX, pRow, x) \ 188 do { \ 189 jint argb = PREFIX ## Lut[pRow[x]]; \ 190 jint a = URShift(argb, 24); \ 191 if (a == 0) { \ 192 argb = 0; \ 193 } else if (a < 0xff) { \ 194 jint r = (argb >> 16) & 0xff; \ 195 jint g = (argb >> 8) & 0xff; \ 196 jint b = (argb ) & 0xff; \ 197 r = MUL8(a, r); \ 198 g = MUL8(a, g); \ 199 b = MUL8(a, b); \ 200 argb = ComposeIntDcmComponents1234(a, r, g, b); \ 201 } \ 202 (pRGB)[i] = argb; \ 203 } while (0) 204 205 206 #define DeclareByteIndexedAlphaLoadData(PREFIX) \ 207 jint *PREFIX ## Lut; \ 208 jint PREFIX ## rgb; 209 210 #define InitByteIndexedAlphaLoadData(PREFIX, pRasInfo) \ 211 do { \ 212 PREFIX ## Lut = (pRasInfo)->lutBase; \ 213 PREFIX ## rgb = 0; \ 214 } while (0) 215 216 #define LoadAlphaFromByteIndexedFor4ByteArgb(pRas, PREFIX, COMP_PREFIX) \ 217 do { \ 218 PREFIX ## rgb = PREFIX ## Lut[(pRas)[0]]; \ 219 COMP_PREFIX ## A = ((juint) PREFIX ## rgb) >> 24; \ 220 } while (0) 221 222 #define Postload4ByteArgbFromByteIndexed(pRas, PREFIX, COMP_PREFIX) \ 223 do { \ 224 COMP_PREFIX ## R = (PREFIX ## rgb >> 16) & 0xff; \ 225 COMP_PREFIX ## G = (PREFIX ## rgb >> 8) & 0xff; \ 226 COMP_PREFIX ## B = (PREFIX ## rgb >> 0) & 0xff; \ 227 } while (0) 228 229 230 #define ByteIndexedIsPremultiplied 0 231 232 #define StoreByteIndexedFrom4ByteArgbComps(pRas, PREFIX, x, COMP_PREFIX) \ 233 StoreByteIndexedFrom4ByteArgb(pRas, PREFIX, x, \ 234 COMP_PREFIX ## A, COMP_PREFIX ## R, \ 235 COMP_PREFIX ## G, COMP_PREFIX ## B) 236 237 #endif /* ByteIndexed_h_Included */