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; \ 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 } while (0) 74 75 #define InitByteIndexedStoreVarsX(PREFIX, pRasInfo) \ 76 SetByteIndexedStoreVarsXPos(PREFIX, pRasInfo, (pRasInfo)->bounds.x1); 77 78 79 #define NextByteIndexedStoreVarsX(PREFIX) \ 80 PREFIX ## XDither = (PREFIX ## XDither + 1) & 7 81 82 #define NextByteIndexedStoreVarsY(PREFIX) \ 83 PREFIX ## YDither = (PREFIX ## YDither + (1 << 3)) & (7 << 3) 84 85 typedef jubyte ByteIndexedBmPixelType; 86 typedef jubyte ByteIndexedBmDataType; 87 88 #define ByteIndexedBmPixelStride 1 89 #define ByteIndexedBmBitsPerPixel 8 90 91 #define DeclareByteIndexedBmLoadVars DeclareByteIndexedLoadVars 92 #define DeclareByteIndexedBmStoreVars DeclareByteIndexedStoreVars 93 #define InitByteIndexedBmLoadVars InitByteIndexedLoadVars 94 #define InitByteIndexedBmStoreVarsY InitByteIndexedStoreVarsY 95 #define InitByteIndexedBmStoreVarsX InitByteIndexedStoreVarsX 96 #define NextByteIndexedBmStoreVarsX NextByteIndexedStoreVarsX 97 #define NextByteIndexedBmStoreVarsY NextByteIndexedStoreVarsY 98 99 #define LoadByteIndexedBmTo1IntArgb LoadByteIndexedTo1IntArgb 100 101 #define CopyByteIndexedBmToIntArgbPre(pRGB, i, PREFIX, pRow, x) \ 102 do { \ 103 jint argb = PREFIX ## Lut[pRow[x]]; \ 104 (pRGB)[i] = argb & (argb >> 24); \ 105 } while (0) 106 107 108 #define ByteIndexedXparLutEntry -1 109 #define ByteIndexedIsXparLutEntry(pix) (pix < 0) 110 #define StoreByteIndexedNonXparFromArgb StoreByteIndexedFrom1IntArgb 111 112 #define StoreByteIndexedPixel(pRas, x, pixel) \ 113 ((pRas)[x] = (jubyte) (pixel)) 114 115 #define DeclareByteIndexedPixelData(PREFIX) 116 #define ExtractByteIndexedPixelData(PIXEL, PREFIX) 117 118 #define StoreByteIndexedPixelData(pPix, x, pixel, PREFIX) \ 119 (pPix)[x] = (jubyte) (pixel) 120 121 #define ByteIndexedPixelFromArgb(pixel, rgb, pRasInfo) \ 122 do { \ 123 jint r, g, b; \ 124 ExtractIntDcmComponentsX123(rgb, r, g, b); \ 125 (pixel) = SurfaceData_InvColorMap((pRasInfo)->invColorTable, \ 126 r, g, b); \ 127 } while (0) 128 129 #define LoadByteIndexedTo1IntRgb(pRas, PREFIX, x, rgb) \ 130 (rgb) = PREFIX ## Lut[pRas[x]] 131 132 #define LoadByteIndexedTo1IntArgb(pRas, PREFIX, x, argb) \ 133 (argb) = PREFIX ## Lut[pRas[x]] 134 135 #define LoadByteIndexedTo3ByteRgb(pRas, PREFIX, x, r, g, b) \ 136 do { \ 137 jint rgb = PREFIX ## Lut[pRas[x]]; \ 138 ExtractIntDcmComponentsX123(rgb, r, g, b); \ 139 } while (0) 140 141 #define LoadByteIndexedTo4ByteArgb(pRas, PREFIX, x, a, r, g, b) \ 142 do { \ 143 jint argb = PREFIX ## Lut[pRas[x]]; \ 144 ExtractIntDcmComponents1234(argb, a, r, g, b); \ 145 } while (0) 146 147 #define ByteClamp1Component(X) \ 148 do { if (((X) >> 8) != 0) {X = (~(X >> 31)) & 255; } } while (0) 149 150 #define ByteClamp3Components(R, G, B) \ 151 do { \ 152 if (((R|G|B) >> 8) != 0) { \ 153 ByteClamp1Component(R); \ 154 ByteClamp1Component(G); \ 155 ByteClamp1Component(B); \ 156 } \ 157 } while (0) 158 159 #define StoreByteIndexedFrom1IntRgb(pRas, PREFIX, x, rgb) \ 160 do { \ 161 int r, g, b; \ 162 ExtractIntDcmComponentsX123(rgb, r, g, b); \ 163 StoreByteIndexedFrom3ByteRgb(pRas, PREFIX, x, r, g, b); \ 164 } while (0) 165 166 #define StoreByteIndexedFrom1IntArgb(pRas, PREFIX, x, argb) \ 167 StoreByteIndexedFrom1IntRgb(pRas, PREFIX, x, argb) 168 169 /* For colors with 0 or 255 value in R,G,B components 170 * we dont add error value based on dithering indices 171 * as it is not needed. 172 */ 173 #define StoreByteIndexedFrom3ByteRgb(pRas, PREFIX, x, r, g, b) \ 174 do { \ 175 if(!(((r == 0) || (r == 255)) && \ 176 ((g == 0) || (g == 255)) && \ 177 ((b == 0) || (b == 255)))) { \ 178 r += PREFIX ## rerr[PREFIX ## XDither]; \ 179 g += PREFIX ## gerr[PREFIX ## XDither]; \ 180 b += PREFIX ## berr[PREFIX ## XDither]; \ 181 } \ 182 ByteClamp3Components(r, g, b); \ 183 (pRas)[x] = SurfaceData_InvColorMap(PREFIX ## InvLut, r, g, b); \ 184 } while (0) 185 186 #define StoreByteIndexedFrom4ByteArgb(pRas, PREFIX, x, a, r, g, b) \ 187 StoreByteIndexedFrom3ByteRgb(pRas, PREFIX, x, r, g, b) 188 189 #define CopyByteIndexedToIntArgbPre(pRGB, i, PREFIX, pRow, x) \ 190 do { \ 191 jint argb = PREFIX ## Lut[pRow[x]]; \ 192 jint a = URShift(argb, 24); \ 193 if (a == 0) { \ 194 argb = 0; \ 195 } else if (a < 0xff) { \ 196 jint r = (argb >> 16) & 0xff; \ 197 jint g = (argb >> 8) & 0xff; \ 198 jint b = (argb ) & 0xff; \ 199 r = MUL8(a, r); \ 200 g = MUL8(a, g); \ 201 b = MUL8(a, b); \ 202 argb = ComposeIntDcmComponents1234(a, r, g, b); \ 203 } \ 204 (pRGB)[i] = argb; \ 205 } while (0) 206 207 208 #define DeclareByteIndexedAlphaLoadData(PREFIX) \ 209 jint *PREFIX ## Lut; \ 210 jint PREFIX ## rgb; 211 212 #define InitByteIndexedAlphaLoadData(PREFIX, pRasInfo) \ 213 do { \ 214 PREFIX ## Lut = (pRasInfo)->lutBase; \ 215 PREFIX ## rgb = 0; \ 216 } while (0) 217 218 #define LoadAlphaFromByteIndexedFor4ByteArgb(pRas, PREFIX, COMP_PREFIX) \ 219 do { \ 220 PREFIX ## rgb = PREFIX ## Lut[(pRas)[0]]; \ 221 COMP_PREFIX ## A = ((juint) PREFIX ## rgb) >> 24; \ 222 } while (0) 223 224 #define Postload4ByteArgbFromByteIndexed(pRas, PREFIX, COMP_PREFIX) \ 225 do { \ 226 COMP_PREFIX ## R = (PREFIX ## rgb >> 16) & 0xff; \ 227 COMP_PREFIX ## G = (PREFIX ## rgb >> 8) & 0xff; \ 228 COMP_PREFIX ## B = (PREFIX ## rgb >> 0) & 0xff; \ 229 } while (0) 230 231 232 #define ByteIndexedIsPremultiplied 0 233 234 #define StoreByteIndexedFrom4ByteArgbComps(pRas, PREFIX, x, COMP_PREFIX) \ 235 StoreByteIndexedFrom4ByteArgb(pRas, PREFIX, x, \ 236 COMP_PREFIX ## A, COMP_PREFIX ## R, \ 237 COMP_PREFIX ## G, COMP_PREFIX ## B) 238 239 #endif /* ByteIndexed_h_Included */