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 * alphaxform_reg.c 00018 * 00019 * This tests the alpha blending functions when used with various 00020 * transforms (scaling, rotation, affine, projective, bilinear). 00021 * 00022 * It also tests the version that are wrapped in a gamma transform, 00023 * which is a technique for getting a truer color on transforming, 00024 * because it undoes the gamma that has been applied to an image 00025 * before transforming and then re-applying the gamma transform. 00026 */ 00027 00028 #include "allheaders.h" 00029 00030 static void MakePtas(l_int32 i, l_int32 npts, PTA **pptas, PTA **pptad); 00031 00032 00033 static const l_int32 x1[] = { 300, 300, 300, 95, 32 }; 00034 static const l_int32 y1[] = { 1200, 1200, 1250, 2821, 934 }; 00035 static const l_int32 x2[] = { 1200, 1200, 1125, 1432, 487 }; 00036 static const l_int32 y2[] = { 1100, 1100, 1100, 2682, 934 }; 00037 static const l_int32 x3[] = { 200, 200, 200, 232, 32 }; 00038 static const l_int32 y3[] = { 200, 200, 200, 657, 67 }; 00039 static const l_int32 x4[] = { 1200, 1200, 1125, 1432, 487 }; 00040 static const l_int32 y4[] = { 200, 200, 200, 242, 84 }; 00041 00042 00043 static const l_int32 xp1[] = { 500, 300, 350, 117, 32 }; 00044 static const l_int32 yp1[] = { 1700, 1400, 1100, 2629, 934 }; 00045 static const l_int32 xp2[] = { 850, 400, 1100, 1664, 487 }; 00046 static const l_int32 yp2[] = { 850, 500, 1300, 2432, 804 }; 00047 static const l_int32 xp3[] = { 450, 200, 400, 183, 61 }; 00048 static const l_int32 yp3[] = { 300, 300, 400, 490, 83 }; 00049 static const l_int32 xp4[] = { 850, 1000, 1100, 1664, 487 }; 00050 static const l_int32 yp4[] = { 350, 350, 400, 532, 114 }; 00051 00052 00053 00054 main(int argc, 00055 char **argv) 00056 { 00057 PIX *pix1, *pix2, *pixs1, *pixs2, *pixs3, *pixb1, *pixb2, *pixb3, *pixbs; 00058 PIX *pixg2, *pixg3, *pixr2, *pixr3; 00059 PIX *pixc1, *pixc2, *pixc3, *pixcs1, *pixcs2, *pixcs3; 00060 PIX *pixd, *pixt1, *pixt2, *pixt3; 00061 PTA *ptas1, *ptas2, *ptas3, *ptad1, *ptad2, *ptad3; 00062 L_REGPARAMS *rp; 00063 00064 if (regTestSetup(argc, argv, &rp)) 00065 return 1; 00066 00067 pixc1 = pixRead("test24.jpg"); 00068 pixc2 = pixRead("wyom.jpg"); 00069 pixc3 = pixRead("marge.jpg"); 00070 00071 /* Test alpha blend scaling */ 00072 pixd = pixCreate(900, 400, 32); 00073 pixSetAll(pixd); 00074 pixs2 = pixScaleWithAlpha(pixc2, 0.5, 0.5, NULL, 0.3); 00075 pixs3 = pixScaleWithAlpha(pixc3, 0.4, 0.4, NULL, 0.7); 00076 pixb1 = pixBlendWithGrayMask(pixd, pixs3, NULL, 100, 100); 00077 pixb2 = pixBlendWithGrayMask(pixb1, pixs2, NULL, 300, 130); 00078 pixb3 = pixBlendWithGrayMask(pixb2, pixs3, NULL, 600, 160); 00079 regTestWritePixAndCheck(rp, pixb3, IFF_PNG); /* 0 */ 00080 pixDisplayWithTitle(pixb3, 900, 100, NULL, rp->display); 00081 pixDestroy(&pixd); 00082 pixDestroy(&pixs2); 00083 pixDestroy(&pixs3); 00084 pixDestroy(&pixb1); 00085 pixDestroy(&pixb2); 00086 pixDestroy(&pixb3); 00087 00088 pixd = pixCreate(900, 400, 32); 00089 pixSetAll(pixd); 00090 pixs3 = pixScaleGammaXform(pixc3, 2.0, 0.4, 0.4, 0.7); 00091 pixs2 = pixScaleGammaXform(pixc2, 2.0, 0.5, 0.5, 0.3); 00092 pixb1 = pixBlendWithGrayMask(pixd, pixs3, NULL, 100, 100); 00093 pixb2 = pixBlendWithGrayMask(pixb1, pixs2, NULL, 300, 130); 00094 pixb3 = pixBlendWithGrayMask(pixb2, pixs3, NULL, 600, 160); 00095 regTestWritePixAndCheck(rp, pixb3, IFF_PNG); /* 1 */ 00096 pixDisplayWithTitle(pixb3, 900, 100, NULL, rp->display); 00097 pixDestroy(&pixd); 00098 pixDestroy(&pixs3); 00099 pixDestroy(&pixs2); 00100 pixDestroy(&pixb1); 00101 pixDestroy(&pixb2); 00102 pixDestroy(&pixb3); 00103 00104 /* Test alpha blend rotation */ 00105 pixd = pixCreate(1200, 800, 32); 00106 pixSetAll(pixd); 00107 pixr3 = pixRotateWithAlpha(pixc3, -0.3, NULL, 1.0); 00108 pixr2 = pixRotateWithAlpha(pixc2, +0.3, NULL, 1.0); 00109 pixb3 = pixBlendWithGrayMask(pixd, pixr3, NULL, 100, 100); 00110 pixb2 = pixBlendWithGrayMask(pixb3, pixr2, NULL, 400, 100); 00111 regTestWritePixAndCheck(rp, pixb2, IFF_PNG); /* 2 */ 00112 pixDisplayWithTitle(pixb2, 500, 100, NULL, rp->display); 00113 pixDestroy(&pixd); 00114 pixDestroy(&pixr3); 00115 pixDestroy(&pixr2); 00116 pixDestroy(&pixb3); 00117 pixDestroy(&pixb2); 00118 00119 pixd = pixCreate(1200, 800, 32); 00120 pixSetAll(pixd); 00121 pixr2 = pixRotateGammaXform(pixc2, 2.0, +0.3, 1.0); 00122 pixr3 = pixRotateGammaXform(pixc3, 2.0, -0.3, 1.0); 00123 pixb3 = pixBlendWithGrayMask(pixd, pixr3, NULL, 100, 100); 00124 pixb2 = pixBlendWithGrayMask(pixb3, pixr2, NULL, 400, 100); 00125 regTestWritePixAndCheck(rp, pixb2, IFF_PNG); /* 3 */ 00126 pixDisplayWithTitle(pixb2, 500, 100, NULL, rp->display); 00127 pixDestroy(&pixd); 00128 pixDestroy(&pixr2); 00129 pixDestroy(&pixr3); 00130 pixDestroy(&pixb2); 00131 pixDestroy(&pixb3); 00132 00133 pixcs1 = pixScale(pixc1, 0.35, 0.35); 00134 pixcs2 = pixScale(pixc2, 0.55, 0.55); 00135 pixcs3 = pixScale(pixc3, 0.65, 0.65); 00136 00137 /* Test alpha blend affine */ 00138 pixd = pixCreate(800, 900, 32); 00139 pixSetAll(pixd); 00140 MakePtas(2, 3, &ptas1, &ptad1); 00141 MakePtas(4, 3, &ptas2, &ptad2); 00142 MakePtas(3, 3, &ptas3, &ptad3); 00143 pixt1 = pixAffinePtaWithAlpha(pixcs1, ptad1, ptas1, NULL, 1.0, 300); 00144 pixt2 = pixAffinePtaWithAlpha(pixcs2, ptad2, ptas2, NULL, 0.8, 400); 00145 pixt3 = pixAffinePtaWithAlpha(pixcs3, ptad3, ptas3, NULL, 0.7, 300); 00146 pixb1 = pixBlendWithGrayMask(pixd, pixt1, NULL, -250, 20); 00147 pixb2 = pixBlendWithGrayMask(pixb1, pixt2, NULL, -150, -250); 00148 pixb3 = pixBlendWithGrayMask(pixb2, pixt3, NULL, -100, 220); 00149 regTestWritePixAndCheck(rp, pixb3, IFF_PNG); /* 4 */ 00150 pixDisplayWithTitle(pixb3, 100, 100, NULL, rp->display); 00151 pixDestroy(&pixd); 00152 pixDestroy(&pixb1); 00153 pixDestroy(&pixb2); 00154 pixDestroy(&pixb3); 00155 pixDestroy(&pixt1); 00156 pixDestroy(&pixt2); 00157 pixDestroy(&pixt3); 00158 ptaDestroy(&ptas1); 00159 ptaDestroy(&ptas2); 00160 ptaDestroy(&ptas3); 00161 ptaDestroy(&ptad1); 00162 ptaDestroy(&ptad2); 00163 ptaDestroy(&ptad3); 00164 00165 pixd = pixCreate(800, 900, 32); 00166 pixSetAll(pixd); 00167 MakePtas(2, 3, &ptas1, &ptad1); 00168 MakePtas(4, 3, &ptas2, &ptad2); 00169 MakePtas(3, 3, &ptas3, &ptad3); 00170 pixt1 = pixAffinePtaGammaXform(pixcs1, 2.0, ptad1, ptas1, 1.0, 300); 00171 pixt2 = pixAffinePtaGammaXform(pixcs2, 2.0, ptad2, ptas2, 0.8, 400); 00172 pixt3 = pixAffinePtaGammaXform(pixcs3, 2.0, ptad3, ptas3, 0.7, 300); 00173 pixb1 = pixBlendWithGrayMask(pixd, pixt1, NULL, -250, 20); 00174 pixb2 = pixBlendWithGrayMask(pixb1, pixt2, NULL, -150, -250); 00175 pixb3 = pixBlendWithGrayMask(pixb2, pixt3, NULL, -100, 220); 00176 regTestWritePixAndCheck(rp, pixb3, IFF_PNG); /* 5 */ 00177 pixDisplayWithTitle(pixb3, 100, 100, NULL, rp->display); 00178 pixDestroy(&pixd); 00179 pixDestroy(&pixb1); 00180 pixDestroy(&pixb2); 00181 pixDestroy(&pixb3); 00182 pixDestroy(&pixt1); 00183 pixDestroy(&pixt2); 00184 pixDestroy(&pixt3); 00185 ptaDestroy(&ptas1); 00186 ptaDestroy(&ptas2); 00187 ptaDestroy(&ptas3); 00188 ptaDestroy(&ptad1); 00189 ptaDestroy(&ptad2); 00190 ptaDestroy(&ptad3); 00191 00192 /* Test alpha blend projective */ 00193 pixd = pixCreate(900, 900, 32); 00194 pixSetAll(pixd); 00195 MakePtas(2, 4, &ptas1, &ptad1); 00196 MakePtas(4, 4, &ptas2, &ptad2); 00197 MakePtas(3, 4, &ptas3, &ptad3); 00198 pixt1 = pixProjectivePtaWithAlpha(pixcs1, ptad1, ptas1, NULL, 1.0, 300); 00199 pixt2 = pixProjectivePtaWithAlpha(pixcs2, ptad2, ptas2, NULL, 0.8, 400); 00200 pixt3 = pixProjectivePtaWithAlpha(pixcs3, ptad3, ptas3, NULL, 0.7, 400); 00201 pixb1 = pixBlendWithGrayMask(pixd, pixt1, NULL, -150, 20); 00202 pixb2 = pixBlendWithGrayMask(pixb1, pixt2, NULL, -50, -250); 00203 pixb3 = pixBlendWithGrayMask(pixb2, pixt3, NULL, -100, 220); 00204 regTestWritePixAndCheck(rp, pixb3, IFF_PNG); /* 6 */ 00205 pixDisplayWithTitle(pixb3, 300, 100, NULL, rp->display); 00206 pixDestroy(&pixd); 00207 pixDestroy(&pixb1); 00208 pixDestroy(&pixb2); 00209 pixDestroy(&pixb3); 00210 pixDestroy(&pixt1); 00211 pixDestroy(&pixt2); 00212 pixDestroy(&pixt3); 00213 ptaDestroy(&ptas1); 00214 ptaDestroy(&ptas2); 00215 ptaDestroy(&ptas3); 00216 ptaDestroy(&ptad1); 00217 ptaDestroy(&ptad2); 00218 ptaDestroy(&ptad3); 00219 00220 pixd = pixCreate(900, 900, 32); 00221 pixSetAll(pixd); 00222 MakePtas(2, 4, &ptas1, &ptad1); 00223 MakePtas(4, 4, &ptas2, &ptad2); 00224 MakePtas(3, 4, &ptas3, &ptad3); 00225 pixt1 = pixProjectivePtaGammaXform(pixcs1, 2.0, ptad1, ptas1, 1.0, 300); 00226 pixt2 = pixProjectivePtaGammaXform(pixcs2, 2.0, ptad2, ptas2, 0.8, 400); 00227 pixt3 = pixProjectivePtaGammaXform(pixcs3, 2.0, ptad3, ptas3, 0.7, 400); 00228 pixb1 = pixBlendWithGrayMask(pixd, pixt1, NULL, -150, 20); 00229 pixb2 = pixBlendWithGrayMask(pixb1, pixt2, NULL, -50, -250); 00230 pixb3 = pixBlendWithGrayMask(pixb2, pixt3, NULL, -100, 220); 00231 regTestWritePixAndCheck(rp, pixb3, IFF_PNG); /* 7 */ 00232 pixDisplayWithTitle(pixb3, 300, 100, NULL, rp->display); 00233 pixDestroy(&pixd); 00234 pixDestroy(&pixb1); 00235 pixDestroy(&pixb2); 00236 pixDestroy(&pixb3); 00237 pixDestroy(&pixt1); 00238 pixDestroy(&pixt2); 00239 pixDestroy(&pixt3); 00240 ptaDestroy(&ptas1); 00241 ptaDestroy(&ptas2); 00242 ptaDestroy(&ptas3); 00243 ptaDestroy(&ptad1); 00244 ptaDestroy(&ptad2); 00245 ptaDestroy(&ptad3); 00246 00247 /* Test alpha blend bilinear */ 00248 pixd = pixCreate(900, 900, 32); 00249 pixSetAll(pixd); 00250 MakePtas(2, 4, &ptas1, &ptad1); 00251 MakePtas(4, 4, &ptas2, &ptad2); 00252 MakePtas(3, 4, &ptas3, &ptad3); 00253 pixt1 = pixBilinearPtaWithAlpha(pixcs1, ptad1, ptas1, NULL, 1.0, 300); 00254 pixt2 = pixBilinearPtaWithAlpha(pixcs2, ptad2, ptas2, NULL, 0.8, 400); 00255 pixt3 = pixBilinearPtaWithAlpha(pixcs3, ptad3, ptas3, NULL, 0.7, 400); 00256 pixb1 = pixBlendWithGrayMask(pixd, pixt1, NULL, -150, 20); 00257 pixb2 = pixBlendWithGrayMask(pixb1, pixt2, NULL, -50, -250); 00258 pixb3 = pixBlendWithGrayMask(pixb2, pixt3, NULL, -100, 220); 00259 regTestWritePixAndCheck(rp, pixb3, IFF_PNG); /* 8 */ 00260 pixDisplayWithTitle(pixb3, 500, 100, NULL, rp->display); 00261 pixDestroy(&pixd); 00262 pixDestroy(&pixb1); 00263 pixDestroy(&pixb2); 00264 pixDestroy(&pixb3); 00265 pixDestroy(&pixt1); 00266 pixDestroy(&pixt2); 00267 pixDestroy(&pixt3); 00268 ptaDestroy(&ptas1); 00269 ptaDestroy(&ptas2); 00270 ptaDestroy(&ptas3); 00271 ptaDestroy(&ptad1); 00272 ptaDestroy(&ptad2); 00273 ptaDestroy(&ptad3); 00274 00275 pixd = pixCreate(900, 900, 32); 00276 pixSetAll(pixd); 00277 MakePtas(2, 4, &ptas1, &ptad1); 00278 MakePtas(4, 4, &ptas2, &ptad2); 00279 MakePtas(3, 4, &ptas3, &ptad3); 00280 pixt1 = pixBilinearPtaGammaXform(pixcs1, 2.0, ptad1, ptas1, 1.0, 300); 00281 pixt2 = pixBilinearPtaGammaXform(pixcs2, 2.0, ptad2, ptas2, 0.8, 400); 00282 pixt3 = pixBilinearPtaGammaXform(pixcs3, 2.0, ptad3, ptas3, 0.7, 400); 00283 pixb1 = pixBlendWithGrayMask(pixd, pixt1, NULL, -150, 20); 00284 pixb2 = pixBlendWithGrayMask(pixb1, pixt2, NULL, -50, -250); 00285 pixb3 = pixBlendWithGrayMask(pixb2, pixt3, NULL, -100, 220); 00286 regTestWritePixAndCheck(rp, pixb3, IFF_PNG); /* 9 */ 00287 pixDisplayWithTitle(pixb3, 500, 100, NULL, rp->display); 00288 pixDestroy(&pixd); 00289 pixDestroy(&pixb1); 00290 pixDestroy(&pixb2); 00291 pixDestroy(&pixb3); 00292 pixDestroy(&pixt1); 00293 pixDestroy(&pixt2); 00294 pixDestroy(&pixt3); 00295 ptaDestroy(&ptas1); 00296 ptaDestroy(&ptas2); 00297 ptaDestroy(&ptas3); 00298 ptaDestroy(&ptad1); 00299 ptaDestroy(&ptad2); 00300 ptaDestroy(&ptad3); 00301 00302 pixDestroy(&pixc1); 00303 pixDestroy(&pixc2); 00304 pixDestroy(&pixc3); 00305 pixDestroy(&pixcs1); 00306 pixDestroy(&pixcs2); 00307 pixDestroy(&pixcs3); 00308 00309 regTestCleanup(rp); 00310 return 0; 00311 } 00312 00313 00314 static void 00315 MakePtas(l_int32 i, 00316 l_int32 npts, /* 3 or 4 */ 00317 PTA **pptas, 00318 PTA **pptad) 00319 { 00320 00321 *pptas = ptaCreate(npts); 00322 ptaAddPt(*pptas, x1[i], y1[i]); 00323 ptaAddPt(*pptas, x2[i], y2[i]); 00324 ptaAddPt(*pptas, x3[i], y3[i]); 00325 if (npts == 4) ptaAddPt(*pptas, x4[i], y4[i]); 00326 *pptad = ptaCreate(npts); 00327 ptaAddPt(*pptad, xp1[i], yp1[i]); 00328 ptaAddPt(*pptad, xp2[i], yp2[i]); 00329 ptaAddPt(*pptad, xp3[i], yp3[i]); 00330 if (npts == 4) ptaAddPt(*pptad, xp4[i], yp4[i]); 00331 return; 00332 } 00333