| 1 | /* |
| 2 | * Copyright (c) 2004, 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 UshortIndexed_h_Included |
| 27 | #define UshortIndexed_h_Included |
| 28 | |
| 29 | #include "IntDcm.h" |
| 30 | #include "ByteIndexed.h" |
| 31 | |
| 32 | /* |
| 33 | * This file contains macro and type definitions used by the macros in |
| 34 | * LoopMacros.h to manipulate a surface of type "UshortIndexed". |
| 35 | */ |
| 36 | |
| 37 | typedef jushort UshortIndexedPixelType; |
| 38 | typedef jushort UshortIndexedDataType; |
| 39 | |
| 40 | #define UshortIndexedPixelStride 2 |
| 41 | /* |
| 42 | * Note that even though the type is called UshortIndex it is |
| 43 | * really only used as 12-bit indexed (per the BitsPerPixel |
| 44 | * define), thus we need to mask 12 bits of the index into Lut. |
| 45 | */ |
| 46 | #define UshortIndexedBitsPerPixel 12 |
| 47 | #define UshortIndexedLutMask 0xfff |
| 48 | |
| 49 | #define DeclareUshortIndexedLoadVars(PREFIX) \ |
| 50 | jint *PREFIX ## Lut; |
| 51 | |
| 52 | #define DeclareUshortIndexedStoreVars(PREFIX) \ |
| 53 | int PREFIX ## XDither, PREFIX ## YDither; \ |
| 54 | char *PREFIX ## rerr, *PREFIX ## gerr, *PREFIX ## berr; \ |
| 55 | unsigned char *PREFIX ## InvLut; |
| 56 | |
| 57 | #define SetUshortIndexedStoreVarsYPos(PREFIX, pRasInfo, LOC) \ |
| 58 | do { \ |
| 59 | PREFIX ## YDither = ((LOC & 7) << 3); \ |
| 60 | } while (0) |
| 61 | |
| 62 | #define SetUshortIndexedStoreVarsXPos(PREFIX, pRasInfo, LOC) \ |
| 63 | do { \ |
| 64 | PREFIX ## rerr = (pRasInfo)->redErrTable + PREFIX ## YDither; \ |
| 65 | PREFIX ## gerr = (pRasInfo)->grnErrTable + PREFIX ## YDither; \ |
| 66 | PREFIX ## berr = (pRasInfo)->bluErrTable + PREFIX ## YDither; \ |
| 67 | PREFIX ## XDither = (LOC & 7); \ |
| 68 | } while (0) |
| 69 | |
| 70 | #define InitUshortIndexedLoadVars(PREFIX, pRasInfo) \ |
| 71 | PREFIX ## Lut = (pRasInfo)->lutBase |
| 72 | |
| 73 | /* REMIND Could collapse Init..Store..X and Init..Store..Y into one Init |
| 74 | * and factor out the Set.. macros. |
| 75 | */ |
| 76 | #define InitUshortIndexedStoreVarsY(PREFIX, pRasInfo) \ |
| 77 | do { \ |
| 78 | SetUshortIndexedStoreVarsYPos(PREFIX, pRasInfo, (pRasInfo)->bounds.y1); \ |
| 79 | PREFIX ## InvLut = (pRasInfo)->invColorTable; \ |
| 80 | } while (0) |
| 81 | |
| 82 | #define InitUshortIndexedStoreVarsX(PREFIX, pRasInfo) \ |
| 83 | SetUshortIndexedStoreVarsXPos(PREFIX, pRasInfo, (pRasInfo)->bounds.x1); |
| 84 | |
| 85 | |
| 86 | #define NextUshortIndexedStoreVarsX(PREFIX) \ |
| 87 | PREFIX ## XDither = (PREFIX ## XDither + 1) & 7 |
| 88 | |
| 89 | #define NextUshortIndexedStoreVarsY(PREFIX) \ |
| 90 | PREFIX ## YDither = (PREFIX ## YDither + (1 << 3)) & (7 << 3) |
| 91 | |
| 92 | typedef jushort UshortIndexedBmPixelType; |
| 93 | typedef jushort UshortIndexedBmDataType; |
| 94 | |
| 95 | #define UshortIndexedBmPixelStride 2 |
| 96 | #define UshortIndexedBmBitsPerPixel 12 |
| 97 | |
| 98 | #define DeclareUshortIndexedBmLoadVars DeclareUshortIndexedLoadVars |
| 99 | #define DeclareUshortIndexedBmStoreVars DeclareUshortIndexedStoreVars |
| 100 | #define InitUshortIndexedBmLoadVars InitUshortIndexedLoadVars |
| 101 | #define InitUshortIndexedBmStoreVarsY InitUshortIndexedStoreVarsY |
| 102 | #define InitUshortIndexedBmStoreVarsX InitUshortIndexedStoreVarsX |
| 103 | #define NextUshortIndexedBmStoreVarsX NextUshortIndexedStoreVarsX |
| 104 | #define NextUshortIndexedBmStoreVarsY NextUshortIndexedStoreVarsY |
| 105 | |
| 106 | #define UshortIndexedXparLutEntry -1 |
| 107 | #define UshortIndexedIsXparLutEntry(pix) (pix < 0) |
| 108 | #define StoreUshortIndexedNonXparFromArgb StoreUshortIndexedFrom1IntArgb |
| 109 | |
| 110 | #define StoreUshortIndexedPixel(pRas, x, pixel) \ |
| 111 | ((pRas)[x] = (jushort) (pixel)) |
| 112 | |
| 113 | #define DeclareUshortIndexedPixelData(PREFIX) |
| 114 | #define (PIXEL, PREFIX) |
| 115 | |
| 116 | #define StoreUshortIndexedPixelData(pPix, x, pixel, PREFIX) \ |
| 117 | (pPix)[x] = (jushort) (pixel) |
| 118 | |
| 119 | #define UshortIndexedPixelFromArgb(pixel, rgb, pRasInfo) \ |
| 120 | do { \ |
| 121 | jint r, g, b; \ |
| 122 | ExtractIntDcmComponentsX123(rgb, r, g, b); \ |
| 123 | (pixel) = SurfaceData_InvColorMap((pRasInfo)->invColorTable, \ |
| 124 | r, g, b); \ |
| 125 | } while (0) |
| 126 | |
| 127 | #define LoadUshortIndexedTo1IntRgb(pRas, PREFIX, x, rgb) \ |
| 128 | (rgb) = PREFIX ## Lut[(pRas[x])&UshortIndexedLutMask]; |
| 129 | |
| 130 | #define LoadUshortIndexedTo1IntArgb(pRas, PREFIX, x, argb) \ |
| 131 | (argb) = PREFIX ## Lut[(pRas[x])&UshortIndexedLutMask]; |
| 132 | |
| 133 | #define LoadUshortIndexedTo3ByteRgb(pRas, PREFIX, x, r, g, b) \ |
| 134 | do { \ |
| 135 | jint rgb = PREFIX ## Lut[(pRas[x])&UshortIndexedLutMask]; \ |
| 136 | ExtractIntDcmComponentsX123(rgb, r, g, b); \ |
| 137 | } while (0) |
| 138 | |
| 139 | #define LoadUshortIndexedTo4ByteArgb(pRas, PREFIX, x, a, r, g, b) \ |
| 140 | do { \ |
| 141 | jint argb = PREFIX ## Lut[(pRas[x])&UshortIndexedLutMask]; \ |
| 142 | ExtractIntDcmComponents1234(argb, a, r, g, b); \ |
| 143 | } while (0) |
| 144 | |
| 145 | #define StoreUshortIndexedFrom1IntRgb(pRas, PREFIX, x, rgb) \ |
| 146 | do { \ |
| 147 | int r, g, b; \ |
| 148 | ExtractIntDcmComponentsX123(rgb, r, g, b); \ |
| 149 | StoreUshortIndexedFrom3ByteRgb(pRas, PREFIX, x, r, g, b); \ |
| 150 | } while (0) |
| 151 | |
| 152 | #define StoreUshortIndexedFrom1IntArgb(pRas, PREFIX, x, argb) \ |
| 153 | StoreUshortIndexedFrom1IntRgb(pRas, PREFIX, x, argb) |
| 154 | |
| 155 | #define StoreUshortIndexedFrom3ByteRgb(pRas, PREFIX, x, r, g, b) \ |
| 156 | do { \ |
| 157 | r += PREFIX ## rerr[PREFIX ## XDither]; \ |
| 158 | g += PREFIX ## gerr[PREFIX ## XDither]; \ |
| 159 | b += PREFIX ## berr[PREFIX ## XDither]; \ |
| 160 | ByteClamp3Components(r, g, b); \ |
| 161 | (pRas)[x] = SurfaceData_InvColorMap(PREFIX ## InvLut, r, g, b); \ |
| 162 | } while (0) |
| 163 | |
| 164 | #define StoreUshortIndexedFrom4ByteArgb(pRas, PREFIX, x, a, r, g, b) \ |
| 165 | StoreUshortIndexedFrom3ByteRgb(pRas, PREFIX, x, r, g, b) |
| 166 | |
| 167 | |
| 168 | #define DeclareUshortIndexedAlphaLoadData(PREFIX) \ |
| 169 | jint *PREFIX ## Lut; \ |
| 170 | jint PREFIX ## rgb; |
| 171 | |
| 172 | #define InitUshortIndexedAlphaLoadData(PREFIX, pRasInfo) \ |
| 173 | do { \ |
| 174 | PREFIX ## Lut = (pRasInfo)->lutBase; \ |
| 175 | PREFIX ## rgb = 0; \ |
| 176 | } while (0) |
| 177 | |
| 178 | #define LoadAlphaFromUshortIndexedFor4ByteArgb(pRas, PREFIX, COMP_PREFIX) \ |
| 179 | do { \ |
| 180 | PREFIX ## rgb = PREFIX ## Lut[((pRas)[0])&UshortIndexedLutMask]; \ |
| 181 | COMP_PREFIX ## A = ((juint) PREFIX ## rgb) >> 24; \ |
| 182 | } while (0) |
| 183 | |
| 184 | #define Postload4ByteArgbFromUshortIndexed(pRas, PREFIX, COMP_PREFIX) \ |
| 185 | do { \ |
| 186 | COMP_PREFIX ## R = (PREFIX ## rgb >> 16) & 0xff; \ |
| 187 | COMP_PREFIX ## G = (PREFIX ## rgb >> 8) & 0xff; \ |
| 188 | COMP_PREFIX ## B = (PREFIX ## rgb >> 0) & 0xff; \ |
| 189 | } while (0) |
| 190 | |
| 191 | |
| 192 | #define UshortIndexedIsPremultiplied 0 |
| 193 | |
| 194 | #define StoreUshortIndexedFrom4ByteArgbComps(pRas, PREFIX, x, COMP_PREFIX) \ |
| 195 | StoreUshortIndexedFrom4ByteArgb(pRas, PREFIX, x, \ |
| 196 | COMP_PREFIX ## A, COMP_PREFIX ## R, \ |
| 197 | COMP_PREFIX ## G, COMP_PREFIX ## B) |
| 198 | |
| 199 | #endif /* UshortIndexed_h_Included */ |
| 200 | |