| 1 | /* |
| 2 | * Copyright (c) 2000, 2004, 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 | #include <string.h> |
| 27 | |
| 28 | #include "AnyByte.h" |
| 29 | #include "ByteIndexed.h" |
| 30 | #include "AlphaMacros.h" |
| 31 | |
| 32 | #include "IntArgb.h" |
| 33 | #include "IntArgbBm.h" |
| 34 | #include "IntArgbPre.h" |
| 35 | #include "IntRgb.h" |
| 36 | #include "ThreeByteBgr.h" |
| 37 | #include "ByteGray.h" |
| 38 | #include "Index12Gray.h" |
| 39 | |
| 40 | /* |
| 41 | * This file declares, registers, and defines the various graphics |
| 42 | * primitive loops to manipulate surfaces of type "ByteIndexed". |
| 43 | * |
| 44 | * See also LoopMacros.h |
| 45 | */ |
| 46 | |
| 47 | RegisterFunc RegisterByteIndexed; |
| 48 | |
| 49 | DECLARE_CONVERT_BLIT(IntArgb, ByteIndexed); |
| 50 | DECLARE_CONVERT_BLIT(ThreeByteBgr, ByteIndexed); |
| 51 | DECLARE_CONVERT_BLIT(ByteGray, ByteIndexed); |
| 52 | DECLARE_CONVERT_BLIT(ByteIndexed, ByteIndexed); |
| 53 | DECLARE_CONVERT_BLIT(Index12Gray, ByteIndexed); |
| 54 | DECLARE_SCALE_BLIT(IntArgb, ByteIndexed); |
| 55 | DECLARE_SCALE_BLIT(ThreeByteBgr, ByteIndexed); |
| 56 | DECLARE_SCALE_BLIT(ByteGray, ByteIndexed); |
| 57 | DECLARE_SCALE_BLIT(Index12Gray, ByteIndexed); |
| 58 | DECLARE_SCALE_BLIT(ByteIndexed, ByteIndexed); |
| 59 | DECLARE_XPAR_CONVERT_BLIT(ByteIndexedBm, ByteIndexed); |
| 60 | DECLARE_XPAR_SCALE_BLIT(ByteIndexedBm, ByteIndexed); |
| 61 | DECLARE_XPAR_SCALE_BLIT(IntArgbBm, ByteIndexed); |
| 62 | DECLARE_XPAR_BLITBG(ByteIndexedBm, ByteIndexed); |
| 63 | DECLARE_XPAR_CONVERT_BLIT(IntArgbBm, ByteIndexed); |
| 64 | DECLARE_XPAR_BLITBG(IntArgbBm, ByteIndexed); |
| 65 | |
| 66 | DECLARE_XOR_BLIT(IntArgb, ByteIndexed); |
| 67 | DECLARE_ALPHA_MASKFILL(ByteIndexed); |
| 68 | DECLARE_ALPHA_MASKBLIT(IntArgb, ByteIndexed); |
| 69 | DECLARE_ALPHA_MASKBLIT(IntArgbPre, ByteIndexed); |
| 70 | DECLARE_ALPHA_MASKBLIT(IntRgb, ByteIndexed); |
| 71 | DECLARE_SOLID_DRAWGLYPHLISTAA(ByteIndexed); |
| 72 | |
| 73 | DECLARE_TRANSFORMHELPER_FUNCS(ByteIndexed); |
| 74 | DECLARE_TRANSFORMHELPER_FUNCS(ByteIndexedBm); |
| 75 | |
| 76 | NativePrimitive ByteIndexedPrimitives[] = { |
| 77 | REGISTER_CONVERT_BLIT(IntArgb, ByteIndexed), |
| 78 | REGISTER_CONVERT_BLIT_EQUIV(IntRgb, ByteIndexed, |
| 79 | NAME_CONVERT_BLIT(IntArgb, ByteIndexed)), |
| 80 | REGISTER_CONVERT_BLIT_EQUIV(IntArgbBm, ByteIndexed, |
| 81 | NAME_CONVERT_BLIT(IntArgb, ByteIndexed)), |
| 82 | REGISTER_CONVERT_BLIT(ThreeByteBgr, ByteIndexed), |
| 83 | REGISTER_CONVERT_BLIT(ByteGray, ByteIndexed), |
| 84 | REGISTER_CONVERT_BLIT(Index12Gray, ByteIndexed), |
| 85 | REGISTER_CONVERT_BLIT_FLAGS(ByteIndexed, ByteIndexed, 0, SD_LOCK_LUT), |
| 86 | REGISTER_SCALE_BLIT(IntArgb, ByteIndexed), |
| 87 | REGISTER_SCALE_BLIT_EQUIV(IntRgb, ByteIndexed, |
| 88 | NAME_SCALE_BLIT(IntArgb, ByteIndexed)), |
| 89 | REGISTER_SCALE_BLIT_EQUIV(IntArgbBm, ByteIndexed, |
| 90 | NAME_SCALE_BLIT(IntArgb, ByteIndexed)), |
| 91 | REGISTER_SCALE_BLIT(ThreeByteBgr, ByteIndexed), |
| 92 | REGISTER_SCALE_BLIT(ByteGray, ByteIndexed), |
| 93 | REGISTER_SCALE_BLIT(Index12Gray, ByteIndexed), |
| 94 | REGISTER_SCALE_BLIT_FLAGS(ByteIndexed, ByteIndexed, 0, SD_LOCK_LUT), |
| 95 | REGISTER_XPAR_CONVERT_BLIT(ByteIndexedBm, ByteIndexed), |
| 96 | REGISTER_XPAR_SCALE_BLIT(ByteIndexedBm, ByteIndexed), |
| 97 | REGISTER_XPAR_SCALE_BLIT(IntArgbBm, ByteIndexed), |
| 98 | REGISTER_XPAR_BLITBG(ByteIndexedBm, ByteIndexed), |
| 99 | REGISTER_XPAR_CONVERT_BLIT(IntArgbBm, ByteIndexed), |
| 100 | REGISTER_XPAR_BLITBG(IntArgbBm, ByteIndexed), |
| 101 | |
| 102 | REGISTER_XOR_BLIT(IntArgb, ByteIndexed), |
| 103 | REGISTER_ALPHA_MASKFILL(ByteIndexed), |
| 104 | REGISTER_ALPHA_MASKBLIT(IntArgb, ByteIndexed), |
| 105 | REGISTER_ALPHA_MASKBLIT(IntArgbPre, ByteIndexed), |
| 106 | REGISTER_ALPHA_MASKBLIT(IntRgb, ByteIndexed), |
| 107 | REGISTER_SOLID_DRAWGLYPHLISTAA(ByteIndexed), |
| 108 | |
| 109 | REGISTER_TRANSFORMHELPER_FUNCS(ByteIndexed), |
| 110 | REGISTER_TRANSFORMHELPER_FUNCS(ByteIndexedBm), |
| 111 | }; |
| 112 | |
| 113 | jboolean RegisterByteIndexed(JNIEnv *env) |
| 114 | { |
| 115 | return RegisterPrimitives(env, ByteIndexedPrimitives, |
| 116 | ArraySize(ByteIndexedPrimitives)); |
| 117 | } |
| 118 | |
| 119 | jint PixelForByteIndexed(SurfaceDataRasInfo *pRasInfo, jint rgb) |
| 120 | { |
| 121 | jint r, g, b; |
| 122 | ExtractIntDcmComponentsX123(rgb, r, g, b); |
| 123 | return SurfaceData_InvColorMap(pRasInfo->invColorTable, r, g, b); |
| 124 | } |
| 125 | |
| 126 | jboolean checkSameLut(jint *SrcReadLut, jint *DstReadLut, |
| 127 | SurfaceDataRasInfo *pSrcInfo, |
| 128 | SurfaceDataRasInfo *pDstInfo) |
| 129 | { |
| 130 | if (SrcReadLut != DstReadLut) { |
| 131 | juint lutSize = pSrcInfo->lutSize; |
| 132 | if (lutSize > pDstInfo->lutSize) { |
| 133 | return JNI_FALSE; |
| 134 | } else { |
| 135 | juint i; |
| 136 | for (i = 0; i < lutSize; i++) { |
| 137 | if (SrcReadLut[i] != DstReadLut[i]) { |
| 138 | return JNI_FALSE; |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | return JNI_TRUE; |
| 144 | } |
| 145 | |
| 146 | DEFINE_CONVERT_BLIT(IntArgb, ByteIndexed, 3ByteRgb) |
| 147 | |
| 148 | DEFINE_CONVERT_BLIT(ThreeByteBgr, ByteIndexed, 3ByteRgb) |
| 149 | |
| 150 | DEFINE_CONVERT_BLIT(ByteGray, ByteIndexed, 3ByteRgb) |
| 151 | |
| 152 | DEFINE_CONVERT_BLIT(Index12Gray, ByteIndexed, 3ByteRgb) |
| 153 | |
| 154 | void NAME_CONVERT_BLIT(ByteIndexed, ByteIndexed) |
| 155 | (void *srcBase, void *dstBase, |
| 156 | juint width, juint height, |
| 157 | SurfaceDataRasInfo *pSrcInfo, |
| 158 | SurfaceDataRasInfo *pDstInfo, |
| 159 | NativePrimitive *pPrim, |
| 160 | CompositeInfo *pCompInfo) |
| 161 | { |
| 162 | DeclareByteIndexedLoadVars(SrcRead) |
| 163 | DeclareByteIndexedLoadVars(DstRead) |
| 164 | jint srcScan = pSrcInfo->scanStride; |
| 165 | jint dstScan = pDstInfo->scanStride; |
| 166 | |
| 167 | InitByteIndexedLoadVars(SrcRead, pSrcInfo); |
| 168 | InitByteIndexedLoadVars(DstRead, pDstInfo); |
| 169 | |
| 170 | if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) { |
| 171 | do { |
| 172 | memcpy(dstBase, srcBase, width); |
| 173 | srcBase = PtrAddBytes(srcBase, srcScan); |
| 174 | dstBase = PtrAddBytes(dstBase, dstScan); |
| 175 | } while (--height > 0); |
| 176 | } else { |
| 177 | DeclareByteIndexedStoreVars(DstWrite); |
| 178 | |
| 179 | BlitLoopWidthHeight(ByteIndexed, pSrc, srcBase, pSrcInfo, |
| 180 | ByteIndexed, pDst, dstBase, pDstInfo, DstWrite, |
| 181 | width, height, |
| 182 | ConvertVia3ByteRgb |
| 183 | (pSrc, ByteIndexed, SrcRead, |
| 184 | pDst, ByteIndexed, DstWrite, 0, 0)); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | DEFINE_SCALE_BLIT(IntArgb, ByteIndexed, 3ByteRgb) |
| 189 | |
| 190 | DEFINE_SCALE_BLIT(ThreeByteBgr, ByteIndexed, 3ByteRgb) |
| 191 | |
| 192 | DEFINE_SCALE_BLIT(ByteGray, ByteIndexed, 3ByteRgb) |
| 193 | |
| 194 | DEFINE_SCALE_BLIT(Index12Gray, ByteIndexed, 3ByteRgb) |
| 195 | |
| 196 | void NAME_SCALE_BLIT(ByteIndexed, ByteIndexed) |
| 197 | (void *srcBase, void *dstBase, |
| 198 | juint width, juint height, |
| 199 | jint sxloc, jint syloc, |
| 200 | jint sxinc, jint syinc, jint shift, |
| 201 | SurfaceDataRasInfo *pSrcInfo, |
| 202 | SurfaceDataRasInfo *pDstInfo, |
| 203 | NativePrimitive *pPrim, |
| 204 | CompositeInfo *pCompInfo) |
| 205 | { |
| 206 | DeclareByteIndexedLoadVars(SrcRead) |
| 207 | DeclareByteIndexedLoadVars(DstRead) |
| 208 | jint srcScan = pSrcInfo->scanStride; |
| 209 | jint dstScan = pDstInfo->scanStride; |
| 210 | DeclareByteIndexedStoreVars(DstWrite) |
| 211 | |
| 212 | InitByteIndexedLoadVars(SrcRead, pSrcInfo); |
| 213 | InitByteIndexedLoadVars(DstRead, pDstInfo); |
| 214 | |
| 215 | if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) { |
| 216 | BlitLoopScaleWidthHeight(ByteIndexed, pSrc, srcBase, pSrcInfo, |
| 217 | ByteIndexed, pDst, dstBase, pDstInfo, DstWrite, |
| 218 | x, width, height, |
| 219 | sxloc, syloc, sxinc, syinc, shift, |
| 220 | pDst[0] = pSrc[x]); |
| 221 | } else { |
| 222 | BlitLoopScaleWidthHeight(ByteIndexed, pSrc, srcBase, pSrcInfo, |
| 223 | ByteIndexed, pDst, dstBase, pDstInfo, DstWrite, |
| 224 | x, width, height, |
| 225 | sxloc, syloc, sxinc, syinc, shift, |
| 226 | ConvertVia3ByteRgb(pSrc, ByteIndexed, SrcRead, |
| 227 | pDst, ByteIndexed, DstWrite, |
| 228 | x, 0)); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | DEFINE_XPAR_CONVERT_BLIT_LUT8(ByteIndexedBm, ByteIndexed, ConvertOnTheFly) |
| 233 | |
| 234 | DEFINE_XPAR_SCALE_BLIT_LUT8(ByteIndexedBm, ByteIndexed, ConvertOnTheFly) |
| 235 | |
| 236 | DEFINE_XPAR_SCALE_BLIT(IntArgbBm, ByteIndexed, 1IntRgb) |
| 237 | |
| 238 | DEFINE_XPAR_BLITBG_LUT8(ByteIndexedBm, ByteIndexed, ConvertOnTheFly) |
| 239 | |
| 240 | DEFINE_XPAR_CONVERT_BLIT(IntArgbBm, ByteIndexed, 1IntRgb) |
| 241 | |
| 242 | DEFINE_XPAR_BLITBG(IntArgbBm, ByteIndexed, 1IntRgb) |
| 243 | |
| 244 | DEFINE_XOR_BLIT(IntArgb, ByteIndexed, AnyByte) |
| 245 | |
| 246 | DEFINE_ALPHA_MASKFILL(ByteIndexed, 4ByteArgb) |
| 247 | |
| 248 | DEFINE_ALPHA_MASKBLIT(IntArgb, ByteIndexed, 4ByteArgb) |
| 249 | |
| 250 | DEFINE_ALPHA_MASKBLIT(IntArgbPre, ByteIndexed, 4ByteArgb) |
| 251 | |
| 252 | DEFINE_ALPHA_MASKBLIT(IntRgb, ByteIndexed, 4ByteArgb) |
| 253 | |
| 254 | DEFINE_SOLID_DRAWGLYPHLISTAA(ByteIndexed, 3ByteRgb) |
| 255 | |
| 256 | DEFINE_TRANSFORMHELPERS(ByteIndexed) |
| 257 | |
| 258 | DEFINE_TRANSFORMHELPERS(ByteIndexedBm) |
| 259 | |