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 * pixa2_reg.c 00018 * 00019 * Tests various replacement functions on pixa. 00020 */ 00021 00022 #include "allheaders.h" 00023 00024 main(int argc, 00025 char **argv) 00026 { 00027 const char *name; 00028 l_int32 i, n; 00029 BOX *box; 00030 FILE *fp; 00031 PIX *pix, *pixt0, *pixt1, *pixd; 00032 PIXA *pixa; 00033 SARRAY *sa1, *sa2, *sa3, *sa4, *sa; 00034 L_REGPARAMS *rp; 00035 00036 if (regTestSetup(argc, argv, &rp)) 00037 return 1; 00038 00039 /* ---------------- Find all the jpg and tif images --------------- */ 00040 sa1 = getSortedPathnamesInDirectory(".", ".jpg", 0, 0); 00041 sa2 = getSortedPathnamesInDirectory(".", ".tif", 0, 0); 00042 sa3 = sarraySelectByRange(sa1, 0, 9); 00043 sa4 = sarraySelectByRange(sa2, 0, 9); 00044 sarrayConcatenate(sa3, sa4); 00045 n =sarrayGetCount(sa3); 00046 sarrayDestroy(&sa1); 00047 sarrayDestroy(&sa2); 00048 sarrayDestroy(&sa4); 00049 00050 /* ---------------- Use replace to fill up a pixa -------------------*/ 00051 pixa = pixaCreate(1); 00052 pixaExtendArrayToSize(pixa, n); 00053 if ((pixt0 = pixRead("marge.jpg")) == NULL) 00054 rp->success = FALSE; 00055 pixt1 = pixScaleToSize(pixt0, 144, 108); /* scale 0.25 */ 00056 pixDestroy(&pixt0); 00057 pixaInitFull(pixa, pixt1, NULL); /* fill it up */ 00058 pixd = pixaDisplayTiledInRows(pixa, 32, 1000, 1.0, 0, 25, 2); 00059 pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display); 00060 pixWrite("/tmp/pix1.jpg", pixd, IFF_JFIF_JPEG); 00061 pixDestroy(&pixt1); 00062 pixDestroy(&pixd); 00063 00064 /* ---------------- And again with jpgs and tifs -------------------*/ 00065 for (i = 0; i < n; i++) { 00066 name = sarrayGetString(sa3, i, L_NOCOPY); 00067 if ((pixt0 = pixRead(name)) == NULL) 00068 rp->success = FALSE; 00069 pixt1 = pixScaleToSize(pixt0, 144, 108); 00070 pixaReplacePix(pixa, i, pixt1, NULL); 00071 pixDestroy(&pixt0); 00072 } 00073 pixd = pixaDisplayTiledInRows(pixa, 32, 1000, 1.0, 0, 25, 2); 00074 pixDisplayWithTitle(pixd, 400, 100, NULL, rp->display); 00075 pixWrite("/tmp/pix2.jpg", pixd, IFF_JFIF_JPEG); 00076 pixDestroy(&pixd); 00077 00078 /* ---------------- And again, reversing the order ------------------*/ 00079 pix = pixCreate(1, 1, 1); 00080 box = boxCreate(0, 0, 0, 0); 00081 pixaInitFull(pixa, pix, box); 00082 pixDestroy(&pix); 00083 boxDestroy(&box); 00084 for (i = 0; i < n; i++) { 00085 name = sarrayGetString(sa3, i, L_NOCOPY); 00086 if ((pixt0 = pixRead(name)) == NULL) 00087 rp->success = FALSE; 00088 pixt1 = pixScaleToSize(pixt0, 144, 108); 00089 pixaReplacePix(pixa, n - 1 - i, pixt1, NULL); 00090 pixDestroy(&pixt0); 00091 } 00092 pixd = pixaDisplayTiledInRows(pixa, 32, 1000, 1.0, 0, 25, 2); 00093 pixDisplayWithTitle(pixd, 700, 100, NULL, rp->display); 00094 pixWrite("/tmp/pix3.jpg", pixd, IFF_JFIF_JPEG); 00095 pixDestroy(&pixd); 00096 sarrayDestroy(&sa3); 00097 00098 pixaDestroy(&pixa); 00099 regTestCleanup(rp); 00100 return 0; 00101 }