1 /* 2 * Copyright (c) 2003, 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 27 /* 28 * FUNCTION 29 * Internal functions for mlib_ImageAffine with Nearest Neighbor filtering. 30 */ 31 32 #include "mlib_ImageAffine.h" 33 34 /***************************************************************/ 35 #define DECLAREVAR_BIT() \ 36 DECLAREVAR0(); \ 37 mlib_s32 ySrc; \ 38 DTYPE *srcPixelPtr; \ 39 DTYPE *srcPixelPtr0; \ 40 DTYPE *srcPixelPtr1; \ 41 DTYPE *srcPixelPtr2; \ 42 DTYPE *srcPixelPtr3; \ 43 DTYPE *srcPixelPtr4; \ 44 DTYPE *srcPixelPtr5; \ 45 DTYPE *srcPixelPtr6; \ 46 DTYPE *srcPixelPtr7 47 48 /***************************************************************/ 49 #define CLIP_BIT() \ 50 dstData += dstYStride; \ 51 xLeft = leftEdges[j] + d_bitoff; \ 52 xRight = rightEdges[j] + d_bitoff; \ 53 X = xStarts[j] + (s_bitoff << MLIB_SHIFT); \ 54 Y = yStarts[j]; \ 55 if (xLeft > xRight) continue 56 57 /***************************************************************/ 58 #define DTYPE mlib_u8 59 60 void mlib_ImageAffine_bit_1ch_nn(mlib_affine_param *param, 61 mlib_s32 s_bitoff, 62 mlib_s32 d_bitoff) 63 { 64 DECLAREVAR_BIT(); 65 mlib_s32 i, bit, res; 66 67 for (j = yStart; j <= yFinish; j++) { 68 69 CLIP_BIT(); 70 xRight++; 71 72 i = xLeft; 73 74 if (i & 7) { 75 mlib_u8 *dp = dstData + (i >> 3); 76 mlib_s32 res = dp[0]; 77 mlib_s32 i_end = i + (8 - (i & 7)); 78 79 if (i_end > xRight) 80 i_end = xRight; 81 82 for (; i < i_end; i++) { 83 bit = 7 - (i & 7); 84 ySrc = MLIB_POINTER_SHIFT(Y); 85 srcPixelPtr = MLIB_POINTER_GET(lineAddr, ySrc); 86 87 res = (res & ~(1 << bit)) | (((srcPixelPtr[X >> (MLIB_SHIFT + 3)] >> (7 - ((X >> MLIB_SHIFT) & 7))) & 1) << bit); 88 89 X += dX; 90 Y += dY; 91 } 92 93 dp[0] = res; 94 } 95 96 #ifdef __SUNPRO_C 97 #pragma pipeloop(0) 98 #endif /* __SUNPRO_C */ 99 for (; i <= (xRight - 8); i += 8) { 100 srcPixelPtr0 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y)); 101 Y += dY; 102 res = ((srcPixelPtr0[X >> (MLIB_SHIFT + 3)] << (((X >> MLIB_SHIFT)) & 7)) & 0x0080); 103 X += dX; 104 105 srcPixelPtr1 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y)); 106 Y += dY; 107 res |= ((srcPixelPtr1[X >> (MLIB_SHIFT + 3)] << (((X >> MLIB_SHIFT) - 1) & 7)) & 0x4040); 108 X += dX; 109 110 srcPixelPtr2 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y)); 111 Y += dY; 112 res |= ((srcPixelPtr2[X >> (MLIB_SHIFT + 3)] << (((X >> MLIB_SHIFT) - 2) & 7)) & 0x2020); 113 X += dX; 114 115 srcPixelPtr3 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y)); 116 Y += dY; 117 res |= ((srcPixelPtr3[X >> (MLIB_SHIFT + 3)] << (((X >> MLIB_SHIFT) - 3) & 7)) & 0x1010); 118 X += dX; 119 120 srcPixelPtr4 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y)); 121 Y += dY; 122 res |= ((srcPixelPtr4[X >> (MLIB_SHIFT + 3)] << (((X >> MLIB_SHIFT) - 4) & 7)) & 0x0808); 123 X += dX; 124 125 srcPixelPtr5 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y)); 126 Y += dY; 127 res |= ((srcPixelPtr5[X >> (MLIB_SHIFT + 3)] << (((X >> MLIB_SHIFT) - 5) & 7)) & 0x0404); 128 X += dX; 129 130 srcPixelPtr6 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y)); 131 Y += dY; 132 res |= ((srcPixelPtr6[X >> (MLIB_SHIFT + 3)] << (((X >> MLIB_SHIFT) - 6) & 7)) & 0x0202); 133 X += dX; 134 135 srcPixelPtr7 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y)); 136 Y += dY; 137 res |= ((srcPixelPtr7[X >> (MLIB_SHIFT + 3)] >> (7 - ((X >> MLIB_SHIFT) & 7))) & 0x0001); 138 X += dX; 139 140 dstData[i >> 3] = res | (res >> 8); 141 } 142 143 if (i < xRight) { 144 mlib_u8 *dp = dstData + (i >> 3); 145 mlib_s32 res = dp[0]; 146 147 for (; i < xRight; i++) { 148 bit = 7 - (i & 7); 149 ySrc = MLIB_POINTER_SHIFT(Y); 150 srcPixelPtr = MLIB_POINTER_GET(lineAddr, ySrc); 151 152 res = (res & ~(1 << bit)) | (((srcPixelPtr[X >> (MLIB_SHIFT + 3)] >> (7 - ((X >> MLIB_SHIFT) & 7))) & 1) << bit); 153 154 X += dX; 155 Y += dY; 156 } 157 158 dp[0] = res; 159 } 160 } 161 } 162 163 /***************************************************************/