Leptonica 1.68
C Image Processing Library

inserttest.c

Go to the documentation of this file.
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  * inserttest.c
00018  *
00019  */
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <math.h>
00024 #include "allheaders.h"
00025 
00026 
00027 main(int    argc,
00028      char **argv)
00029 {
00030 l_int32     i, n;
00031 l_float32   pi, angle, val;
00032 BOX        *box;
00033 BOXA       *boxa, *boxa1, *boxa2;
00034 NUMA       *na1, *na2;
00035 PIX        *pix, *pix1, *pix2, *pix3, *pixd;
00036 PIXA       *pixa1, *pixa2, *pixa3, *pixa4;
00037 static char     mainName[] = "inserttest";
00038 
00039 #if 1
00040     pi = 3.1415926535;
00041     na1 = numaCreate(500);
00042     for (i = 0; i < 500; i++) {
00043         angle = 0.02293 * i * pi;
00044         val = (l_float32)sin(angle);
00045         numaAddNumber(na1, val);
00046     }
00047     numaWrite("/tmp/junknuma1", na1);
00048     na2 = numaCopy(na1);
00049     n = numaGetCount(na2);
00050     for (i = 0; i < n; i++) {
00051       numaGetFValue(na2, i, &val);
00052       numaRemoveNumber(na2, i);
00053       numaInsertNumber(na2, i, val);
00054     }
00055     numaWrite("/tmp/junknuma2", na2);
00056     numaDestroy(&na1);
00057     numaDestroy(&na2);
00058 #endif
00059 
00060 #if 1
00061     pix1 = pixRead("feyn.tif");
00062     box = boxCreate(1138, 1666, 1070, 380);
00063     pix2 = pixClipRectangle(pix1, box, NULL);
00064     boxDestroy(&box);
00065     boxa1 = pixConnComp(pix2, NULL, 8);
00066     boxaWrite("/tmp/junkboxa1", boxa1);
00067     boxa2 = boxaCopy(boxa1, L_COPY);
00068     n = boxaGetCount(boxa2);
00069     for (i = 0; i < n; i++) {
00070       box = boxaGetBox(boxa2, i, L_COPY);
00071       boxaRemoveBox(boxa2, i);
00072       boxaInsertBox(boxa2, i, box);
00073     }
00074     boxaWrite("/tmp/junkboxa2", boxa2);
00075     pixDestroy(&pix1);
00076     pixDestroy(&pix2);
00077     boxaDestroy(&boxa1);
00078     boxaDestroy(&boxa2);
00079 #endif
00080 
00081 #if 1
00082     pix1 = pixRead("feyn.tif");
00083     box = boxCreate(1138, 1666, 1070, 380);
00084     pix2 = pixClipRectangle(pix1, box, NULL);
00085     boxDestroy(&box);
00086     boxa = pixConnComp(pix2, &pixa1, 8);
00087     boxaDestroy(&boxa);
00088     pixaWrite("/tmp/junkpixa1", pixa1);
00089 
00090     pixa2 = pixaCopy(pixa1, L_COPY);
00091     n = pixaGetCount(pixa2);
00092         /* Remove and insert each one */
00093     for (i = 0; i < n; i++) {
00094       pix = pixaGetPix(pixa2, i, L_COPY);
00095       box = pixaGetBox(pixa2, i, L_COPY);
00096       pixaRemovePix(pixa2, i);
00097       pixaInsertPix(pixa2, i, pix, box);
00098     }
00099     pixaWrite("/tmp/junkpixa2", pixa2);
00100 
00101         /* Move the last to the beginning; do it n times */
00102     pixa3 = pixaCopy(pixa2, L_COPY);
00103     for (i = 0; i < n; i++) {
00104       pix = pixaGetPix(pixa3, n - 1, L_CLONE);
00105       box = pixaGetBox(pixa3, n - 1, L_CLONE);
00106       pixaInsertPix(pixa3, 0, pix, box);
00107       pixaRemovePix(pixa3, n);
00108     }
00109     pixaWrite("/tmp/junkpixa3", pixa3);
00110 
00111         /* Move the first one to the end; do it n times */
00112     pixa4 = pixaCopy(pixa3, L_COPY);
00113     for (i = 0; i < n; i++) {
00114       pix = pixaGetPix(pixa4, 0, L_CLONE);
00115       box = pixaGetBox(pixa4, 0, L_CLONE);
00116       pixaInsertPix(pixa4, n, pix, box);  /* make sure insert works at end */
00117       pixaRemovePix(pixa4, 0);
00118     }
00119     pixaWrite("/tmp/junkpixa4", pixa4);
00120 
00121     pixDestroy(&pix1);
00122     pixDestroy(&pix2);
00123     pixaDestroy(&pixa1);
00124     pixaDestroy(&pixa2);
00125     pixaDestroy(&pixa3);
00126     pixaDestroy(&pixa4);
00127 #endif
00128 
00129     return 0;
00130 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines