1 /* 2 * Copyright (c) 2000, 2008, 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 UshortGray_h_Included 27 #define UshortGray_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 "UshortGray". 34 */ 35 36 typedef jushort UshortGrayPixelType; 37 typedef jushort UshortGrayDataType; 38 39 #define UshortGrayIsOpaque 1 40 41 #define UshortGrayPixelStride 2 42 #define UshortGrayBitsPerPixel 16 43 44 #define DeclareUshortGrayLoadVars(PREFIX) 45 #define DeclareUshortGrayStoreVars(PREFIX) 46 #define SetUshortGrayStoreVarsYPos(PREFIX, pRasInfo, y) 47 #define SetUshortGrayStoreVarsXPos(PREFIX, pRasInfo, x) 48 #define InitUshortGrayLoadVars(PREFIX, pRasInfo) 49 #define InitUshortGrayStoreVarsY(PREFIX, pRasInfo) 50 #define InitUshortGrayStoreVarsX(PREFIX, pRasInfo) 51 #define NextUshortGrayStoreVarsX(PREFIX) 52 #define NextUshortGrayStoreVarsY(PREFIX) 53 #define DeclareUshortGrayPixelData(PREFIX) 54 #define ExtractUshortGrayPixelData(PIXEL, PREFIX) 55 56 #define UshortGrayXparLutEntry -1 57 #define UshortGrayIsXparLutEntry(pix) (pix < 0) 58 #define StoreUshortGrayNonXparFromArgb StoreUshortGrayFrom1IntArgb 59 60 61 /* 62 * Note: The following (original) equation was incorrect: 63 * gray = (((19595*r) + (38470*g) + (7471*b) + 32768) / 65536); 64 * 65 * The new component coefficients were derived from the following equation: 66 * k*rf*255 + k*gf*255 + k*bf*255 = 2^24 - 1 67 * 68 * The new calculated coefficients are: 69 * rf = 19672 70 * gf = 38620 71 * bf = 7500 72 * 73 * Thus the new equation would be: 74 * gray = (((19672*r) + (38620*g) + (7500*b) + 128) / 255) 75 * but it has been tweaked so the faster "divide by 256" can be performed and 76 * the "add 128" can be removed. Therefore, the resultant formula is optimal: 77 * gray = (((19672*r) + (38621*g) + (7500*b)) / 256) 78 */ 79 #define ComposeUshortGrayFrom3ByteRgb(r, g, b) \ 80 (UshortGrayPixelType)(((19672*(r)) + (38621*(g)) + (7500*(b))) / 256) 81 82 #define UshortGrayPixelFromArgb(pixel, rgb, pRasInfo) \ 83 do { \ 84 int r, g, b; \ 85 ExtractIntDcmComponentsX123(rgb, r, g, b); \ 86 (pixel) = ComposeUshortGrayFrom3ByteRgb(r, g, b); \ 87 } while (0) 88 89 #define StoreUshortGrayPixel(pRas, x, pixel) \ 90 ((pRas)[x] = (jushort) (pixel)) 91 92 #define StoreUshortGrayPixelData(pPix, x, pixel, PREFIX) \ 93 StoreUshortGrayPixel(pPix, x, pixel) 94 95 96 #define LoadUshortGrayTo1IntRgb(pRas, PREFIX, x, rgb) \ 97 do { \ 98 int gray = (pRas)[x] >> 8; \ 99 (rgb) = (((gray << 8) | gray) << 8) | gray; \ 100 } while (0) 101 102 #define LoadUshortGrayTo1IntArgb(pRas, PREFIX, x, argb) \ 103 do { \ 104 int gray = (pRas)[x] >> 8; \ 105 (argb) = (((((0xff << 8) | gray) << 8) | gray) << 8) | gray; \ 106 } while (0) 107 108 #define LoadUshortGrayTo3ByteRgb(pRas, PREFIX, x, r, g, b) \ 109 ((r) = (g) = (b) = ((pRas)[x] >> 8)) 110 111 #define LoadUshortGrayTo4ByteArgb(pRas, PREFIX, x, a, r, g, b) \ 112 do { \ 113 LoadUshortGrayTo3ByteRgb(pRas, PREFIX, x, r, g, b); \ 114 (a) = 0xff; \ 115 } while (0) 116 117 #define LoadUshortGrayTo1ByteGray(pRas, PREFIX, x, gray) \ 118 (gray) = ((pRas)[x] >> 8) 119 120 #define LoadUshortGrayTo1ShortGray(pRas, PREFIX, x, gray) \ 121 (gray) = (pRas)[x] 122 123 #define StoreUshortGrayFrom1IntRgb(pRas, PREFIX, x, rgb) \ 124 do { \ 125 int r, g, b; \ 126 ExtractIntDcmComponentsX123(rgb, r, g, b); \ 127 StoreUshortGrayFrom3ByteRgb(pRas, PREFIX, x, r, g, b); \ 128 } while (0) 129 130 #define StoreUshortGrayFrom1IntArgb(pRas, PREFIX, x, argb) \ 131 StoreUshortGrayFrom1IntRgb(pRas, PREFIX, x, argb) 132 133 #define StoreUshortGrayFrom3ByteRgb(pRas, PREFIX, x, r, g, b) \ 134 (pRas)[x] = ComposeUshortGrayFrom3ByteRgb(r, g, b) 135 136 #define StoreUshortGrayFrom4ByteArgb(pRas, PREFIX, x, a, r, g, b) \ 137 StoreUshortGrayFrom3ByteRgb(pRas, PREFIX, x, r, g, b) 138 139 #define StoreUshortGrayFrom1ByteGray(pRas, PREFIX, x, gray) \ 140 (pRas)[x] = (jushort) (((gray) << 8) + (gray)) 141 142 #define StoreUshortGrayFrom1ShortGray(pRas, PREFIX, x, gray) \ 143 StoreUshortGrayPixel(pRas, x, gray) 144 145 146 #define DeclareUshortGrayAlphaLoadData(PREFIX) 147 #define InitUshortGrayAlphaLoadData(PREFIX, pRasInfo) 148 149 #define LoadAlphaFromUshortGrayFor1ShortGray(pRas, PREFIX, COMP_PREFIX) \ 150 COMP_PREFIX ## A = 0xffff 151 152 #define Postload1ShortGrayFromUshortGray(pRas, PREFIX, COMP_PREFIX) \ 153 COMP_PREFIX ## G = (pRas)[0] 154 155 156 #define UshortGrayIsPremultiplied 0 157 158 #define DeclareUshortGrayBlendFillVars(PREFIX) \ 159 jushort PREFIX; 160 161 #define ClearUshortGrayBlendFillVars(PREFIX, argb) \ 162 PREFIX = 0 163 164 #define InitUshortGrayBlendFillVarsNonPre(PREFIX, argb, COMP_PREFIX) \ 165 PREFIX = (jushort) COMP_PREFIX ## G 166 167 #define InitUshortGrayBlendFillVarsPre(PREFIX, argb, COMP_PREFIX) 168 169 #define StoreUshortGrayBlendFill(pRas, PREFIX, x, argb, COMP_PREFIX) \ 170 (pRas)[x] = PREFIX 171 172 #define StoreUshortGrayFrom1ShortGrayComps(pRas, PREFIX, x, COMP_PREFIX) \ 173 StoreUshortGrayPixel(pRas, x, COMP_PREFIX ## G) 174 175 #endif /* UshortGray_h_Included */ 176