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 
mlib_ImageAffine_bit_1ch_nn(mlib_affine_param * param,mlib_s32 s_bitoff,mlib_s32 d_bitoff)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) <<
88            bit);
89 
90         X += dX;
91         Y += dY;
92       }
93 
94       dp[0] = res;
95     }
96 
97 #ifdef __SUNPRO_C
98 #pragma pipeloop(0)
99 #endif /* __SUNPRO_C */
100     for (; i <= (xRight - 8); i += 8) {
101       srcPixelPtr0 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y));
102       Y += dY;
103       res = ((srcPixelPtr0[X >> (MLIB_SHIFT + 3)] << (((X >> MLIB_SHIFT)) & 7)) & 0x0080);
104       X += dX;
105 
106       srcPixelPtr1 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y));
107       Y += dY;
108       res |= ((srcPixelPtr1[X >> (MLIB_SHIFT + 3)] << (((X >> MLIB_SHIFT) - 1) & 7)) & 0x4040);
109       X += dX;
110 
111       srcPixelPtr2 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y));
112       Y += dY;
113       res |= ((srcPixelPtr2[X >> (MLIB_SHIFT + 3)] << (((X >> MLIB_SHIFT) - 2) & 7)) & 0x2020);
114       X += dX;
115 
116       srcPixelPtr3 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y));
117       Y += dY;
118       res |= ((srcPixelPtr3[X >> (MLIB_SHIFT + 3)] << (((X >> MLIB_SHIFT) - 3) & 7)) & 0x1010);
119       X += dX;
120 
121       srcPixelPtr4 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y));
122       Y += dY;
123       res |= ((srcPixelPtr4[X >> (MLIB_SHIFT + 3)] << (((X >> MLIB_SHIFT) - 4) & 7)) & 0x0808);
124       X += dX;
125 
126       srcPixelPtr5 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y));
127       Y += dY;
128       res |= ((srcPixelPtr5[X >> (MLIB_SHIFT + 3)] << (((X >> MLIB_SHIFT) - 5) & 7)) & 0x0404);
129       X += dX;
130 
131       srcPixelPtr6 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y));
132       Y += dY;
133       res |= ((srcPixelPtr6[X >> (MLIB_SHIFT + 3)] << (((X >> MLIB_SHIFT) - 6) & 7)) & 0x0202);
134       X += dX;
135 
136       srcPixelPtr7 = MLIB_POINTER_GET(lineAddr, MLIB_POINTER_SHIFT(Y));
137       Y += dY;
138       res |= ((srcPixelPtr7[X >> (MLIB_SHIFT + 3)] >> (7 - ((X >> MLIB_SHIFT) & 7))) & 0x0001);
139       X += dX;
140 
141       dstData[i >> 3] = res | (res >> 8);
142     }
143 
144     if (i < xRight) {
145       mlib_u8 *dp = dstData + (i >> 3);
146       mlib_s32 res = dp[0];
147 
148       for (; i < xRight; i++) {
149         bit = 7 - (i & 7);
150         ySrc = MLIB_POINTER_SHIFT(Y);
151         srcPixelPtr = MLIB_POINTER_GET(lineAddr, ySrc);
152 
153         res = (res & ~(1 << bit)) | (((srcPixelPtr[X >> (MLIB_SHIFT + 3)] >> (7 - (X >> MLIB_SHIFT) & 7)) & 1) << bit);
154 
155         X += dX;
156         Y += dY;
157       }
158 
159       dp[0] = res;
160     }
161   }
162 }
163 
164 /***************************************************************/
165