Leptonica 1.68
C Image Processing Library
|
00001 /*====================================================================* 00002 - Copyright (C) 2001 Leptonica. All rights reserved. 00003 - This software is distributed in the hope that it will be 00004 - useful, but with NO WARRANTY OF ANY KIND. 00005 - No author or distributor accepts responsibility to anyone for the 00006 - consequences of using this software, or for whether it serves any 00007 - particular purpose or works at all, unless he or she says so in 00008 - writing. Everyone is granted permission to copy, modify and 00009 - redistribute this source code, for commercial or non-commercial 00010 - purposes, with the following restrictions: (1) the origin of this 00011 - source code must not be misrepresented; (2) modified versions must 00012 - be plainly marked as such; and (3) this notice may not be removed 00013 - or altered from any source or modified source distribution. 00014 *====================================================================*/ 00015 00016 /*! 00017 * Low-level fast hit-miss transform with auto-generated sels 00018 * 00019 * Dispatcher: 00020 * l_int32 fhmtgen_low_1() 00021 * 00022 * Static Low-level: 00023 * void fhmt_1_*() 00024 */ 00025 00026 #include "allheaders.h" 00027 00028 static void fhmt_1_0(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32); 00029 static void fhmt_1_1(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32); 00030 static void fhmt_1_2(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32); 00031 static void fhmt_1_3(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32); 00032 static void fhmt_1_4(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32); 00033 static void fhmt_1_5(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32); 00034 00035 00036 /*---------------------------------------------------------------------* 00037 * Fast hmt dispatcher * 00038 *---------------------------------------------------------------------*/ 00039 /*! 00040 * fhmtgen_low_1() 00041 * 00042 * a dispatcher to appropriate low-level code 00043 */ 00044 l_int32 00045 fhmtgen_low_1(l_uint32 *datad, 00046 l_int32 w, 00047 l_int32 h, 00048 l_int32 wpld, 00049 l_uint32 *datas, 00050 l_int32 wpls, 00051 l_int32 index) 00052 { 00053 00054 switch (index) 00055 { 00056 case 0: 00057 fhmt_1_0(datad, w, h, wpld, datas, wpls); 00058 break; 00059 case 1: 00060 fhmt_1_1(datad, w, h, wpld, datas, wpls); 00061 break; 00062 case 2: 00063 fhmt_1_2(datad, w, h, wpld, datas, wpls); 00064 break; 00065 case 3: 00066 fhmt_1_3(datad, w, h, wpld, datas, wpls); 00067 break; 00068 case 4: 00069 fhmt_1_4(datad, w, h, wpld, datas, wpls); 00070 break; 00071 case 5: 00072 fhmt_1_5(datad, w, h, wpld, datas, wpls); 00073 break; 00074 } 00075 00076 return 0; 00077 } 00078 00079 00080 /*--------------------------------------------------------------------------* 00081 * Low-level auto-generated static routines * 00082 *--------------------------------------------------------------------------*/ 00083 /* 00084 * N.B. In all the low-level routines, the part of the image 00085 * that is accessed has been clipped by 32 pixels on 00086 * all four sides. This is done in the higher level 00087 * code by redefining w and h smaller and by moving the 00088 * start-of-image pointers up to the beginning of this 00089 * interior rectangle. 00090 */ 00091 static void 00092 fhmt_1_0(l_uint32 *datad, 00093 l_int32 w, 00094 l_int32 h, 00095 l_int32 wpld, 00096 l_uint32 *datas, 00097 l_int32 wpls) 00098 { 00099 l_int32 i; 00100 register l_int32 j, pwpls; 00101 register l_uint32 *sptr, *dptr; 00102 00103 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */ 00104 00105 for (i = 0; i < h; i++) { 00106 sptr = datas + i * wpls; 00107 dptr = datad + i * wpld; 00108 for (j = 0; j < pwpls; j++, sptr++, dptr++) { 00109 *dptr = ((~*(sptr - wpls) >> 1) | (~*(sptr - wpls - 1) << 31)) & 00110 (~*(sptr - wpls)) & 00111 ((~*(sptr - wpls) << 1) | (~*(sptr - wpls + 1) >> 31)) & 00112 ((~*(sptr) >> 1) | (~*(sptr - 1) << 31)) & 00113 (*sptr) & 00114 ((~*(sptr) << 1) | (~*(sptr + 1) >> 31)) & 00115 ((~*(sptr + wpls) >> 1) | (~*(sptr + wpls - 1) << 31)) & 00116 (~*(sptr + wpls)) & 00117 ((~*(sptr + wpls) << 1) | (~*(sptr + wpls + 1) >> 31)); 00118 } 00119 } 00120 } 00121 00122 static void 00123 fhmt_1_1(l_uint32 *datad, 00124 l_int32 w, 00125 l_int32 h, 00126 l_int32 wpld, 00127 l_uint32 *datas, 00128 l_int32 wpls) 00129 { 00130 l_int32 i; 00131 register l_int32 j, pwpls; 00132 register l_uint32 *sptr, *dptr; 00133 00134 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */ 00135 00136 for (i = 0; i < h; i++) { 00137 sptr = datas + i * wpls; 00138 dptr = datad + i * wpld; 00139 for (j = 0; j < pwpls; j++, sptr++, dptr++) { 00140 *dptr = ((*(sptr) >> 1) | (*(sptr - 1) << 31)) & 00141 (*sptr) & 00142 ((*(sptr) << 1) | (*(sptr + 1) >> 31)) & 00143 ((~*(sptr + wpls) >> 1) | (~*(sptr + wpls - 1) << 31)) & 00144 (~*(sptr + wpls)) & 00145 ((~*(sptr + wpls) << 1) | (~*(sptr + wpls + 1) >> 31)); 00146 } 00147 } 00148 } 00149 00150 static void 00151 fhmt_1_2(l_uint32 *datad, 00152 l_int32 w, 00153 l_int32 h, 00154 l_int32 wpld, 00155 l_uint32 *datas, 00156 l_int32 wpls) 00157 { 00158 l_int32 i; 00159 register l_int32 j, pwpls; 00160 register l_uint32 *sptr, *dptr; 00161 00162 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */ 00163 00164 for (i = 0; i < h; i++) { 00165 sptr = datas + i * wpls; 00166 dptr = datad + i * wpld; 00167 for (j = 0; j < pwpls; j++, sptr++, dptr++) { 00168 *dptr = ((~*(sptr - wpls) >> 1) | (~*(sptr - wpls - 1) << 31)) & 00169 (~*(sptr - wpls)) & 00170 ((~*(sptr - wpls) << 1) | (~*(sptr - wpls + 1) >> 31)) & 00171 ((*(sptr) >> 1) | (*(sptr - 1) << 31)) & 00172 (*sptr) & 00173 ((*(sptr) << 1) | (*(sptr + 1) >> 31)); 00174 } 00175 } 00176 } 00177 00178 static void 00179 fhmt_1_3(l_uint32 *datad, 00180 l_int32 w, 00181 l_int32 h, 00182 l_int32 wpld, 00183 l_uint32 *datas, 00184 l_int32 wpls) 00185 { 00186 l_int32 i; 00187 register l_int32 j, pwpls; 00188 register l_uint32 *sptr, *dptr; 00189 00190 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */ 00191 00192 for (i = 0; i < h; i++) { 00193 sptr = datas + i * wpls; 00194 dptr = datad + i * wpld; 00195 for (j = 0; j < pwpls; j++, sptr++, dptr++) { 00196 *dptr = (*(sptr - wpls)) & 00197 ((~*(sptr - wpls) << 1) | (~*(sptr - wpls + 1) >> 31)) & 00198 (*sptr) & 00199 ((~*(sptr) << 1) | (~*(sptr + 1) >> 31)) & 00200 (*(sptr + wpls)) & 00201 ((~*(sptr + wpls) << 1) | (~*(sptr + wpls + 1) >> 31)); 00202 } 00203 } 00204 } 00205 00206 static void 00207 fhmt_1_4(l_uint32 *datad, 00208 l_int32 w, 00209 l_int32 h, 00210 l_int32 wpld, 00211 l_uint32 *datas, 00212 l_int32 wpls) 00213 { 00214 l_int32 i; 00215 register l_int32 j, pwpls; 00216 register l_uint32 *sptr, *dptr; 00217 00218 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */ 00219 00220 for (i = 0; i < h; i++) { 00221 sptr = datas + i * wpls; 00222 dptr = datad + i * wpld; 00223 for (j = 0; j < pwpls; j++, sptr++, dptr++) { 00224 *dptr = ((~*(sptr - wpls) >> 1) | (~*(sptr - wpls - 1) << 31)) & 00225 (*(sptr - wpls)) & 00226 ((~*(sptr) >> 1) | (~*(sptr - 1) << 31)) & 00227 (*sptr) & 00228 ((~*(sptr + wpls) >> 1) | (~*(sptr + wpls - 1) << 31)) & 00229 (*(sptr + wpls)); 00230 } 00231 } 00232 } 00233 00234 static void 00235 fhmt_1_5(l_uint32 *datad, 00236 l_int32 w, 00237 l_int32 h, 00238 l_int32 wpld, 00239 l_uint32 *datas, 00240 l_int32 wpls) 00241 { 00242 l_int32 i; 00243 register l_int32 j, pwpls; 00244 register l_uint32 *sptr, *dptr; 00245 l_int32 wpls2, wpls3, wpls4; 00246 l_int32 wpls5, wpls6; 00247 00248 wpls2 = 2 * wpls; 00249 wpls3 = 3 * wpls; 00250 wpls4 = 4 * wpls; 00251 wpls5 = 5 * wpls; 00252 wpls6 = 6 * wpls; 00253 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */ 00254 00255 for (i = 0; i < h; i++) { 00256 sptr = datas + i * wpls; 00257 dptr = datad + i * wpld; 00258 for (j = 0; j < pwpls; j++, sptr++, dptr++) { 00259 *dptr = ((~*(sptr - wpls6) << 1) | (~*(sptr - wpls6 + 1) >> 31)) & 00260 ((*(sptr - wpls6) << 3) | (*(sptr - wpls6 + 1) >> 29)) & 00261 (~*(sptr - wpls2)) & 00262 ((*(sptr - wpls2) << 2) | (*(sptr - wpls2 + 1) >> 30)) & 00263 ((~*(sptr + wpls2) >> 1) | (~*(sptr + wpls2 - 1) << 31)) & 00264 ((*(sptr + wpls2) << 1) | (*(sptr + wpls2 + 1) >> 31)) & 00265 ((~*(sptr + wpls6) >> 2) | (~*(sptr + wpls6 - 1) << 30)) & 00266 (*(sptr + wpls6)); 00267 } 00268 } 00269 } 00270