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 * warpertest.c 00018 * 00019 * Tests stereoscopic warp and associated shear and stretching functions. 00020 * Uses gthumb for visually identifying problems. 00021 */ 00022 00023 #include <stdio.h> 00024 #include <stdlib.h> 00025 #include "allheaders.h" 00026 00027 static const char *opstr[3] = {"", "interpolated", "sampled"}; 00028 static const char *dirstr[3] = {"", "to left", "to right"}; 00029 00030 #define RUN_WARP 1 00031 #define RUN_QUAD_VERT_SHEAR 0 00032 #define RUN_LIN_HORIZ_STRETCH 0 00033 #define RUN_QUAD_HORIZ_STRETCH 0 00034 #define RUN_HORIZ_SHEAR 0 00035 #define RUN_VERT_SHEAR 0 00036 00037 main(int argc, 00038 char **argv) 00039 { 00040 char buf[256]; 00041 l_int32 w, h, i, j, k, index, op, dir, stretch; 00042 l_float32 del, angle, angledeg; 00043 BOX *box; 00044 L_BMF *bmf; 00045 PIX *pixs, *pixt, *pixt2, *pixd; 00046 static char mainName[] = "warpertest"; 00047 00048 if (argc != 1) 00049 exit(ERROR_INT("syntax: warpertest", mainName, 1)); 00050 00051 /* -------- Stereoscopic warping --------------*/ 00052 #if RUN_WARP 00053 pixs = pixRead("german.png"); 00054 pixGetDimensions(pixs, &w, &h, NULL); 00055 l_jpegSetNoChromaSampling(1); 00056 for (i = 0; i < 50; i++) { // need to test > 2 widths ! 00057 j = 7 * i; 00058 box = boxCreate(0, 0, w - j, h - j); 00059 pixt = pixClipRectangle(pixs, box, NULL); 00060 pixd = pixWarpStereoscopic(pixt, 15, 22, 8, 30, -20, 1); 00061 snprintf(buf, sizeof(buf), "/tmp/junkpixw.%02d.jpg", i); 00062 pixWrite(buf, pixd, IFF_JFIF_JPEG); 00063 pixDestroy(&pixd); 00064 pixDestroy(&pixt); 00065 boxDestroy(&box); 00066 } 00067 pixDestroy(&pixs); 00068 pixDisplayMultiple("/tmp/junkpixw*.jpg"); 00069 #endif 00070 00071 /* -------- Quadratic Vertical Shear --------------*/ 00072 #if RUN_QUAD_VERT_SHEAR 00073 pixs = pixCreate(501, 501, 32); 00074 pixGetDimensions(pixs, &w, &h, NULL); 00075 pixSetAll(pixs); 00076 pixRenderLineArb(pixs, 0, 30, 500, 30, 5, 0, 0, 255); 00077 pixRenderLineArb(pixs, 0, 110, 500, 110, 5, 0, 255, 0); 00078 pixRenderLineArb(pixs, 0, 190, 500, 190, 5, 0, 255, 255); 00079 pixRenderLineArb(pixs, 0, 270, 500, 270, 5, 255, 0, 0); 00080 pixRenderLineArb(pixs, 0, 360, 500, 360, 5, 255, 0, 255); 00081 pixRenderLineArb(pixs, 0, 450, 500, 450, 5, 255, 255, 0); 00082 bmf = bmfCreate("./fonts", 6); 00083 for (i = 0; i < 50; i++) { 00084 j = 3 * i; 00085 dir = ((i / 2) & 1) ? L_WARP_TO_RIGHT : L_WARP_TO_LEFT; 00086 op = (i & 1) ? L_INTERPOLATED : L_SAMPLED; 00087 Box *box = boxCreate(0, 0, w - j, h - j); 00088 pixt = pixClipRectangle(pixs, box, NULL); 00089 pixt2 = pixQuadraticVShear(pixt, dir, 60, -20, op, L_BRING_IN_WHITE); 00090 00091 snprintf(buf, sizeof(buf), "%s, %s", dirstr[dir], opstr[op]); 00092 pixd = pixAddSingleTextblock(pixt2, bmf, buf, 0xff000000, 00093 L_ADD_BELOW, 0); 00094 snprintf(buf, sizeof(buf), "/tmp/junkpixvs.%02d.png", i); 00095 pixWrite(buf, pixd, IFF_PNG); 00096 pixDestroy(&pixd); 00097 pixDestroy(&pixt); 00098 pixDestroy(&pixt2); 00099 boxDestroy(&box); 00100 } 00101 pixDestroy(&pixs); 00102 bmfDestroy(&bmf); 00103 pixDisplayMultiple("/tmp/junkpixvs*.png"); 00104 #endif 00105 00106 /* -------- Linear Horizontal stretching --------------*/ 00107 #if RUN_LIN_HORIZ_STRETCH 00108 pixs = pixRead("german.png"); 00109 bmf = bmfCreate("./fonts", 6); 00110 for (k = 0; k < 2; k++) { 00111 for (i = 0; i < 25; i++) { 00112 index = 25 * k + i; 00113 stretch = 10 + 4 * i; 00114 if (k == 0) stretch = -stretch; 00115 dir = (k == 1) ? L_WARP_TO_RIGHT : L_WARP_TO_LEFT; 00116 op = (i & 1) ? L_INTERPOLATED : L_SAMPLED; 00117 pixt = pixStretchHorizontal(pixs, dir, L_LINEAR_WARP, 00118 stretch, op, L_BRING_IN_WHITE); 00119 snprintf(buf, sizeof(buf), "%s, %s", dirstr[dir], opstr[op]); 00120 pixd = pixAddSingleTextblock(pixt, bmf, buf, 0xff000000, 00121 L_ADD_BELOW, 0); 00122 snprintf(buf, sizeof(buf), "/tmp/junkpixlhs.%02d.jpg", index); 00123 pixWrite(buf, pixd, IFF_JFIF_JPEG); 00124 pixDestroy(&pixd); 00125 pixDestroy(&pixt); 00126 } 00127 } 00128 00129 pixDestroy(&pixs); 00130 bmfDestroy(&bmf); 00131 pixDisplayMultiple("/tmp/junkpixlhs*.jpg"); 00132 #endif 00133 00134 /* -------- Quadratic Horizontal stretching --------------*/ 00135 #if RUN_QUAD_HORIZ_STRETCH 00136 pixs = pixRead("german.png"); 00137 bmf = bmfCreate("./fonts", 6); 00138 for (k = 0; k < 2; k++) { 00139 for (i = 0; i < 25; i++) { 00140 index = 25 * k + i; 00141 stretch = 10 + 4 * i; 00142 if (k == 0) stretch = -stretch; 00143 dir = (k == 1) ? L_WARP_TO_RIGHT : L_WARP_TO_LEFT; 00144 op = (i & 1) ? L_INTERPOLATED : L_SAMPLED; 00145 pixt = pixStretchHorizontal(pixs, dir, L_QUADRATIC_WARP, 00146 stretch, op, L_BRING_IN_WHITE); 00147 snprintf(buf, sizeof(buf), "%s, %s", dirstr[dir], opstr[op]); 00148 pixd = pixAddSingleTextblock(pixt, bmf, buf, 0xff000000, 00149 L_ADD_BELOW, 0); 00150 snprintf(buf, sizeof(buf), "/tmp/junkpixqhs.%02d.jpg", index); 00151 pixWrite(buf, pixd, IFF_JFIF_JPEG); 00152 pixDestroy(&pixd); 00153 pixDestroy(&pixt); 00154 } 00155 } 00156 00157 pixDestroy(&pixs); 00158 bmfDestroy(&bmf); 00159 pixDisplayMultiple("/tmp/junkpixqhs*.jpg"); 00160 #endif 00161 00162 /* -------- Horizontal Shear --------------*/ 00163 #if RUN_HORIZ_SHEAR 00164 pixs = pixRead("german.png"); 00165 pixGetDimensions(pixs, &w, &h, NULL); 00166 bmf = bmfCreate("./fonts", 6); 00167 for (i = 0; i < 25; i++) { 00168 del = 0.2 / 12.; 00169 angle = -0.2 + (i - (i & 1)) * del; 00170 angledeg = 180. * angle / 3.14159265; 00171 op = (i & 1) ? L_INTERPOLATED : L_SAMPLED; 00172 if (op == L_SAMPLED) 00173 pixt = pixHShear(NULL, pixs, h / 2, angle, L_BRING_IN_WHITE); 00174 else 00175 pixt = pixHShearLI(pixs, h / 2, angle, L_BRING_IN_WHITE); 00176 snprintf(buf, sizeof(buf), "%6.2f degree, %s", angledeg, opstr[op]); 00177 pixd = pixAddSingleTextblock(pixt, bmf, buf, 0xff000000, 00178 L_ADD_BELOW, 0); 00179 snprintf(buf, sizeof(buf), "/tmp/junkpixsh.%02d.jpg", i); 00180 pixWrite(buf, pixd, IFF_JFIF_JPEG); 00181 pixDestroy(&pixd); 00182 pixDestroy(&pixt); 00183 } 00184 00185 pixDestroy(&pixs); 00186 bmfDestroy(&bmf); 00187 pixDisplayMultiple("/tmp/junkpixsh*.jpg"); 00188 #endif 00189 00190 /* -------- Vertical Shear --------------*/ 00191 #if RUN_VERT_SHEAR 00192 pixs = pixRead("german.png"); 00193 pixGetDimensions(pixs, &w, &h, NULL); 00194 bmf = bmfCreate("./fonts", 6); 00195 for (i = 0; i < 25; i++) { 00196 del = 0.2 / 12.; 00197 angle = -0.2 + (i - (i & 1)) * del; 00198 angledeg = 180. * angle / 3.14159265; 00199 op = (i & 1) ? L_INTERPOLATED : L_SAMPLED; 00200 if (op == L_SAMPLED) 00201 pixt = pixVShear(NULL, pixs, w / 2, angle, L_BRING_IN_WHITE); 00202 else 00203 pixt = pixVShearLI(pixs, w / 2, angle, L_BRING_IN_WHITE); 00204 snprintf(buf, sizeof(buf), "%6.2f degree, %s", angledeg, opstr[op]); 00205 pixd = pixAddSingleTextblock(pixt, bmf, buf, 0xff000000, 00206 L_ADD_BELOW, 0); 00207 snprintf(buf, sizeof(buf), "/tmp/junkpixsv.%02d.jpg", i); 00208 pixWrite(buf, pixd, IFF_JFIF_JPEG); 00209 pixDestroy(&pixd); 00210 pixDestroy(&pixt); 00211 } 00212 00213 pixDestroy(&pixs); 00214 bmfDestroy(&bmf); 00215 pixDisplayMultiple("/tmp/junkpixsv*.jpg"); 00216 #endif 00217 00218 return 0; 00219 } 00220 00221