| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,231 @@ | ||
| /*====================================================================* | ||
| - Copyright (C) 2001 Leptonica. All rights reserved. | ||
| - | ||
| - Redistribution and use in source and binary forms, with or without | ||
| - modification, are permitted provided that the following conditions | ||
| - are met: | ||
| - 1. Redistributions of source code must retain the above copyright | ||
| - notice, this list of conditions and the following disclaimer. | ||
| - 2. Redistributions in binary form must reproduce the above | ||
| - copyright notice, this list of conditions and the following | ||
| - disclaimer in the documentation and/or other materials | ||
| - provided with the distribution. | ||
| - | ||
| - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY | ||
| - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
| - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| *====================================================================*/ | ||
|
|
||
| /* | ||
| * ccbord_reg.c | ||
| * | ||
| * Regression test for border-following representations of binary images. | ||
| * This uses the steps in ccbordtest.c to test specified images. | ||
| */ | ||
|
|
||
| #ifdef HAVE_CONFIG_H | ||
| #include <config_auto.h> | ||
| #endif /* HAVE_CONFIG_H */ | ||
|
|
||
| #include <string.h> | ||
| #include "allheaders.h" | ||
|
|
||
| void RunCCBordTest(const char *fname, L_REGPARAMS *rp); | ||
|
|
||
| int main(int argc, | ||
| char **argv) | ||
| { | ||
| L_REGPARAMS *rp; | ||
|
|
||
| if (regTestSetup(argc, argv, &rp)) | ||
| return 1; | ||
| lept_mkdir("lept/ccbord"); | ||
|
|
||
| RunCCBordTest("feyn-fract.tif", rp); | ||
| RunCCBordTest("dreyfus1.png", rp); | ||
| return regTestCleanup(rp); | ||
| } | ||
|
|
||
| /* ----------------------------------------------- */ | ||
| void RunCCBordTest(const char *fname, | ||
| L_REGPARAMS *rp) | ||
| { | ||
| char *svgstr; | ||
| l_int32 count, disp; | ||
| CCBORDA *ccba, *ccba2; | ||
| PIX *pixs, *pixd, *pixd2, *pixd3; | ||
| PIX *pixt, *pixc, *pixc2; | ||
|
|
||
| pixs = pixRead(fname); | ||
| disp = rp->display; | ||
|
|
||
| /*------------------------------------------------------------------* | ||
| * Get border representation and verify border pixels * | ||
| *------------------------------------------------------------------*/ | ||
| if(disp) lept_stderr("Get border representation..."); | ||
| ccba = pixGetAllCCBorders(pixs); | ||
|
|
||
| /* Get global locs directly and display borders */ | ||
| if (disp) lept_stderr("Convert from local to global locs..."); | ||
| ccbaGenerateGlobalLocs(ccba); | ||
| if (disp) lept_stderr("display border representation..."); | ||
| pixd = ccbaDisplayBorder(ccba); | ||
| regTestWritePixAndCheck(rp, pixd, IFF_PNG); /* 0,7 */ | ||
| pixDisplayWithTitle(pixd, 0, 0, NULL, rp->display); | ||
| pixDestroy(&pixd); | ||
|
|
||
| /* Get step chain code, then global coords, and display borders */ | ||
| if (disp) lept_stderr("get step chain code..."); | ||
| ccbaGenerateStepChains(ccba); | ||
| if (disp) lept_stderr("convert from step chain to global locs..."); | ||
| ccbaStepChainsToPixCoords(ccba, CCB_GLOBAL_COORDS); | ||
| if (disp) lept_stderr("display border representation\n"); | ||
| pixd = ccbaDisplayBorder(ccba); | ||
| regTestWritePixAndCheck(rp, pixd, IFF_PNG); /* 1,8 */ | ||
| pixDisplayWithTitle(pixd, 200, 0, NULL, rp->display); | ||
|
|
||
| /* Check if border pixels are in original set */ | ||
| lept_stderr("Check if border pixels are in original set\n"); | ||
| pixt = pixSubtract(NULL, pixd, pixs); | ||
| pixCountPixels(pixt, &count, NULL); | ||
| if (count == 0) | ||
| lept_stderr(" ==> all border pixels are in original set\n"); | ||
| else | ||
| lept_stderr(" ==> %d border pixels are not in original set\n", count); | ||
| pixDestroy(&pixt); | ||
|
|
||
| /* Display image */ | ||
| lept_stderr("Reconstruct image\n"); | ||
| pixc = ccbaDisplayImage2(ccba); | ||
| regTestWritePixAndCheck(rp, pixc, IFF_PNG); /* 2,9 */ | ||
| pixDisplayWithTitle(pixc, 400, 0, NULL, rp->display); | ||
|
|
||
| /* Check with original to see if correct */ | ||
| pixXor(pixc, pixc, pixs); | ||
| pixCountPixels(pixc, &count, NULL); | ||
| if (count == 0) | ||
| lept_stderr(" ==> perfect direct reconstruction\n"); | ||
| else { | ||
| l_int32 w, h, i, j; | ||
| l_uint32 val; | ||
| lept_stderr(" ==> %d pixels in error in reconstruction\n", count); | ||
| #if 1 | ||
| w = pixGetWidth(pixc); | ||
| h = pixGetHeight(pixc); | ||
| for (i = 0; i < h; i++) { | ||
| for (j = 0; j < w; j++) { | ||
| pixGetPixel(pixc, j, i, &val); | ||
| if (val == 1) | ||
| lept_stderr("bad pixel at (%d, %d)\n", j, i); | ||
| } | ||
| } | ||
| pixWrite("/tmp/lept/ccbord/badpixels1.png", pixc, IFF_PNG); | ||
| #endif | ||
| } | ||
|
|
||
| /*----------------------------------------------------------* | ||
| * Write to file (compressed) and read back * | ||
| *----------------------------------------------------------*/ | ||
| if (disp) lept_stderr("Write serialized step data..."); | ||
| ccbaWrite("/tmp/lept/ccbord/stepdata.ccb", ccba); | ||
| if (disp) lept_stderr("read serialized step data..."); | ||
| ccba2 = ccbaRead("/tmp/lept/ccbord/stepdata.ccb"); | ||
|
|
||
| /* Display the border pixels again */ | ||
| if (disp) lept_stderr("convert from step chain to global locs..."); | ||
| ccbaStepChainsToPixCoords(ccba2, CCB_GLOBAL_COORDS); | ||
| if (disp) lept_stderr("display border representation\n"); | ||
| pixd2 = ccbaDisplayBorder(ccba2); | ||
| regTestWritePixAndCheck(rp, pixd2, IFF_PNG); /* 3,10 */ | ||
| pixDisplayWithTitle(pixd2, 600, 0, NULL, rp->display); | ||
|
|
||
| /* Check if border pixels are same as first time */ | ||
| lept_stderr("Check border after write/read\n"); | ||
| pixXor(pixd2, pixd2, pixd); | ||
| pixCountPixels(pixd2, &count, NULL); | ||
| if (count == 0) | ||
| lept_stderr(" ==> perfect w/r border recon\n"); | ||
| else | ||
| lept_stderr(" ==> %d pixels in error in w/r recon\n", count); | ||
| pixDestroy(&pixd2); | ||
|
|
||
| /* Display image again */ | ||
| if (disp) lept_stderr("Convert from step chain to local coords...\n"); | ||
| ccbaStepChainsToPixCoords(ccba2, CCB_LOCAL_COORDS); | ||
| lept_stderr("Reconstruct image from file\n"); | ||
| pixc2 = ccbaDisplayImage2(ccba2); | ||
| regTestWritePixAndCheck(rp, pixc2, IFF_PNG); /* 4,11 */ | ||
| pixDisplayWithTitle(pixc2, 800, 0, NULL, rp->display); | ||
|
|
||
| /* Check with original to see if correct */ | ||
| pixXor(pixc2, pixc2, pixs); | ||
| pixCountPixels(pixc2, &count, NULL); | ||
| if (count == 0) | ||
| lept_stderr(" ==> perfect image recon\n"); | ||
| else { | ||
| l_int32 w, h, i, j; | ||
| l_uint32 val; | ||
| lept_stderr(" ==> %d pixels in error in image recon\n", count); | ||
| #if 1 | ||
| w = pixGetWidth(pixc2); | ||
| h = pixGetHeight(pixc2); | ||
| for (i = 0; i < h; i++) { | ||
| for (j = 0; j < w; j++) { | ||
| pixGetPixel(pixc2, j, i, &val); | ||
| if (val == 1) | ||
| lept_stderr("bad pixel at (%d, %d)\n", j, i); | ||
| } | ||
| } | ||
| pixWrite("/tmp/lept/ccbord/badpixels2.png", pixc, IFF_PNG); | ||
| #endif | ||
| } | ||
|
|
||
| /*----------------------------------------------------------* | ||
| * Make, display and check single path border for svg * | ||
| *----------------------------------------------------------*/ | ||
| /* Make local single path border for svg */ | ||
| if (disp) lept_stderr("Make local single path borders for svg ..."); | ||
| ccbaGenerateSinglePath(ccba); | ||
|
|
||
| /* Generate global single path border */ | ||
| if (disp) lept_stderr("generate global single path borders ..."); | ||
| ccbaGenerateSPGlobalLocs(ccba, CCB_SAVE_TURNING_PTS); | ||
|
|
||
| /* Display border pixels from single path */ | ||
| if (disp) lept_stderr("display border from single path\n"); | ||
| pixd3 = ccbaDisplaySPBorder(ccba); | ||
| regTestWritePixAndCheck(rp, pixd3, IFF_PNG); /* 5,12 */ | ||
| pixDisplayWithTitle(pixd3, 1000, 0, NULL, rp->display); | ||
|
|
||
| /* Check if border pixels are in original set */ | ||
| lept_stderr("Check if border pixels are in original set\n"); | ||
| pixt = pixSubtract(NULL, pixd3, pixs); | ||
| pixCountPixels(pixt, &count, NULL); | ||
| if (count == 0) | ||
| lept_stderr(" ==> all border pixels are in original set\n"); | ||
| else | ||
| lept_stderr(" ==> %d border pixels are not in original set\n", count); | ||
| lept_stderr("============================================\n"); | ||
| pixDestroy(&pixt); | ||
| pixDestroy(&pixd3); | ||
|
|
||
| /* Output in svg file format */ | ||
| svgstr = ccbaWriteSVGString(ccba); | ||
| regTestWriteDataAndCheck(rp, svgstr, strlen(svgstr), "ccb"); /* 6,13 */ | ||
|
|
||
| ccbaDestroy(&ccba2); | ||
| ccbaDestroy(&ccba); | ||
| pixDestroy(&pixs); | ||
| pixDestroy(&pixd); | ||
| pixDestroy(&pixc); | ||
| pixDestroy(&pixc2); | ||
| lept_free(svgstr); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /*====================================================================* | ||
| - Copyright (C) 2001 Leptonica. All rights reserved. | ||
| - | ||
| - Redistribution and use in source and binary forms, with or without | ||
| - modification, are permitted provided that the following conditions | ||
| - are met: | ||
| - 1. Redistributions of source code must retain the above copyright | ||
| - notice, this list of conditions and the following disclaimer. | ||
| - 2. Redistributions in binary form must reproduce the above | ||
| - copyright notice, this list of conditions and the following | ||
| - disclaimer in the documentation and/or other materials | ||
| - provided with the distribution. | ||
| - | ||
| - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY | ||
| - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
| - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| *====================================================================*/ | ||
|
|
||
| /* | ||
| * circle_reg.c | ||
| * | ||
| * Extract the digits from within a circle. In some cases the circle | ||
| * touches the digits, so this cannot be done by simply selecting | ||
| * connected components. | ||
| * | ||
| * Method: | ||
| * (1) Find a solid circle that covers the fg pixels. | ||
| * (2) Progressively erode the circle, computing the number of | ||
| * 8-connected components after each successive 3x3 erosion. | ||
| * (3) Stop when the minimum number of components is first reached, | ||
| * after passing the maximum number of components. Disregard the | ||
| * original image in the counting, because it can have noise. | ||
| */ | ||
|
|
||
| #ifdef HAVE_CONFIG_H | ||
| #include <config_auto.h> | ||
| #endif /* HAVE_CONFIG_H */ | ||
|
|
||
| #include "allheaders.h" | ||
|
|
||
| static const l_int32 num_erodes = 8; | ||
|
|
||
| int main(int argc, | ||
| char **argv) | ||
| { | ||
| l_int32 i, k, prevcount, count, nfiles, n, maxloc, maxval, minval; | ||
| NUMA *na; | ||
| PIX *pixs, *pixsi, *pixc, *pixoc, *pix1, *pix2, *pix3; | ||
| PIXA *pixas, *pixa1, *pixa2; | ||
| L_REGPARAMS *rp; | ||
|
|
||
| #if !defined(HAVE_LIBPNG) | ||
| L_ERROR("This test requires libpng to run.\n", "circle_reg"); | ||
| exit(77); | ||
| #endif | ||
|
|
||
| if (regTestSetup(argc, argv, &rp)) | ||
| return 1; | ||
|
|
||
| /* Read the images */ | ||
| pixas = pixaRead("circles.pa"); | ||
| n = pixaGetCount(pixas); | ||
|
|
||
| pixa2 = pixaCreate(0); | ||
| for (k = 0; k < n; k++) { | ||
| pixa1 = pixaCreate(0); | ||
| na = numaCreate(0); | ||
| pixs = pixaGetPix(pixas, k, L_COPY); | ||
| pixaAddPix(pixa1, pixs, L_INSERT); | ||
| pixsi = pixInvert(NULL, pixs); | ||
| pixc = pixCreateTemplate(pixs); | ||
| pixSetOrClearBorder(pixc, 1, 1, 1, 1, PIX_SET); | ||
| pixSeedfillBinary(pixc, pixc, pixsi, 4); | ||
| pixInvert(pixc, pixc); | ||
| pixoc = pixCopy(NULL, pixc); /* original circle */ | ||
| pixaAddPix(pixa1, pixoc, L_INSERT); | ||
| pix1 = pixAnd(NULL, pixs, pixc); | ||
| pixaAddPix(pixa1, pix1, L_INSERT); | ||
| pixCountConnComp(pix1, 8, &count); | ||
| numaAddNumber(na, count); | ||
| if (rp->display) lept_stderr("count[0] = %d\n", count); | ||
| for (i = 1; i < num_erodes; i++) { | ||
| pixErodeBrick(pixc, pixc, 3, 3); | ||
| pix1 = pixAnd(NULL, pixs, pixc); | ||
| pixaAddPix(pixa1, pix1, L_INSERT); | ||
| pixCountConnComp(pix1, 8, &count); | ||
| numaAddNumber(na, count); | ||
| if (rp->display) lept_stderr("count[%d] = %d\n", i, count); | ||
| } | ||
|
|
||
| /* Find the max value, not including the original image, which | ||
| * may have noise. Then find the first occurrence of the | ||
| * min value that follows this max value. */ | ||
| maxval = maxloc = 0; | ||
| for (i = 1; i < num_erodes; i++) { /* get max value starting at 1 */ | ||
| numaGetIValue(na, i, &count); | ||
| if (count > maxval) { | ||
| maxval = count; | ||
| maxloc = i; | ||
| } | ||
| } | ||
| minval = 1000; | ||
| for (i = maxloc + 1; i < num_erodes; i++) { /* get the min value */ | ||
| numaGetIValue(na, i, &count); | ||
| if (count < minval) minval = count; | ||
| } | ||
| for (i = maxloc + 1; i < num_erodes; i++) { /* get first occurrence */ | ||
| numaGetIValue(na, i, &count); | ||
| if (count == minval) break; | ||
| } | ||
|
|
||
| pix1 = pixErodeBrick(NULL, pixoc, 2 * i + 1, 2 * i + 1); | ||
| pix2 = pixAnd(NULL, pixs, pix1); | ||
| pixaAddPix(pixa1, pix2, L_INSERT); | ||
| pix3 = pixaDisplayTiledInColumns(pixa1, 11, 1.0, 10, 2); | ||
| regTestWritePixAndCheck(rp, pix3, IFF_PNG); | ||
| pixaAddPix(pixa2, pix3, L_INSERT); | ||
| pixaDestroy(&pixa1); | ||
| pixDestroy(&pix1); | ||
| pixDestroy(&pixsi); | ||
| pixDestroy(&pixc); | ||
| numaDestroy(&na); | ||
| } | ||
|
|
||
| pix1 = pixaDisplayTiledInColumns(pixa2, 1, 1.0, 10, 0); | ||
| regTestWritePixAndCheck(rp, pix1, IFF_PNG); | ||
| pixDisplayWithTitle(pix1, 100, 100, NULL, rp->display); | ||
| pixaDestroy(&pixas); | ||
| pixaDestroy(&pixa2); | ||
| pixDestroy(&pix1); | ||
| return regTestCleanup(rp); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| /*====================================================================* | ||
| - Copyright (C) 2001 Leptonica. All rights reserved. | ||
| - | ||
| - Redistribution and use in source and binary forms, with or without | ||
| - modification, are permitted provided that the following conditions | ||
| - are met: | ||
| - 1. Redistributions of source code must retain the above copyright | ||
| - notice, this list of conditions and the following disclaimer. | ||
| - 2. Redistributions in binary form must reproduce the above | ||
| - copyright notice, this list of conditions and the following | ||
| - disclaimer in the documentation and/or other materials | ||
| - provided with the distribution. | ||
| - | ||
| - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY | ||
| - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
| - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| *====================================================================*/ | ||
|
|
||
| /* | ||
| * colorfill_reg.c | ||
| * | ||
| * This tests the utility that does color segmentation by region growing. | ||
| */ | ||
|
|
||
| #ifdef HAVE_CONFIG_H | ||
| #include <config_auto.h> | ||
| #endif /* HAVE_CONFIG_H */ | ||
|
|
||
| #include "allheaders.h" | ||
|
|
||
| static PIX *makeSmallTestPix(l_uint32 c1, l_uint32 c2); | ||
|
|
||
|
|
||
| int main(int argc, | ||
| char **argv) | ||
| { | ||
| L_COLORFILL *cf; | ||
| PIX *pix1, *pix2, *pix3, *pix4; | ||
| PIXA *pixa1, *pixa2; | ||
| L_REGPARAMS *rp; | ||
|
|
||
| if (regTestSetup(argc, argv, &rp)) | ||
| return 1; | ||
|
|
||
| /* Test on a small image */ | ||
| pix1 = makeSmallTestPix(0x3070A000, 0xA0703000); | ||
| pix2 = pixExpandReplicate(pix1, 15); | ||
| regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 0 */ | ||
| pixDisplayWithTitle(pix2, 0, 0, NULL, rp->display); | ||
| pixDestroy(&pix2); | ||
| cf = l_colorfillCreate(pix1, 1, 1); | ||
| pixColorContentByLocation(cf, 0, 0, 0, 70, 15, 3, 1, 1); | ||
| pix2 = pixaDisplayTiledInColumns(cf->pixadb, cf->nx, 1.0, 10, 1); | ||
| pix3 = pixExpandReplicate(pix2, 10); | ||
| regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 1 */ | ||
| pixDisplayWithTitle(pix3, 300, 0, NULL, rp->display); | ||
| pixDestroy(&pix1); | ||
| pixDestroy(&pix2); | ||
| pixDestroy(&pix3); | ||
| l_colorfillDestroy(&cf); | ||
|
|
||
| /* Test on simple random image with many colors (1 tile and 4 tiles */ | ||
| pixa1 = makeColorfillTestData(350, 350, 35, 100); | ||
| pixa2 = pixaCreate(5); | ||
| pix1 = pixaGetPix(pixa1, 0, L_COPY); | ||
| pix2 = pixConvertTo32(pix1); | ||
| pixDestroy(&pix1); | ||
| regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 2 */ | ||
| pixaAddPix(pixa2, pix2, L_INSERT); | ||
| cf = l_colorfillCreate(pix2, 1, 1); /* 1 tile */ | ||
| pixColorContentByLocation(cf, 0, 0, 0, 70, 30, 500, 1, 1); | ||
| pix3 = pixaDisplayTiledInColumns(cf->pixam, cf->nx, 1.0, 10, 1); | ||
| pix4 = pixaDisplayTiledInColumns(cf->pixadb, cf->nx, 1.0, 10, 1); | ||
| regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 3 */ | ||
| regTestWritePixAndCheck(rp, pix4, IFF_PNG); /* 4 */ | ||
| pixaAddPix(pixa2, pix3, L_INSERT); | ||
| pixaAddPix(pixa2, pix4, L_INSERT); | ||
| l_colorfillDestroy(&cf); | ||
|
|
||
| cf = l_colorfillCreate(pix2, 2, 2); /* 4 tiles */ | ||
| pixColorContentByLocation(cf, 0, 0, 0, 70, 30, 500, 1, 1); | ||
| pix3 = pixaDisplayTiledInColumns(cf->pixam, cf->nx, 1.0, 10, 1); | ||
| pix4 = pixaDisplayTiledInColumns(cf->pixadb, cf->nx, 1.0, 10, 1); | ||
| regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 5 */ | ||
| regTestWritePixAndCheck(rp, pix4, IFF_PNG); /* 6 */ | ||
| pixaAddPix(pixa2, pix3, L_INSERT); | ||
| pixaAddPix(pixa2, pix4, L_INSERT); | ||
| if (rp->display) { | ||
| pix1 = pixaDisplayTiledInColumns(pixa2, 5, 1.0, 15, 2); | ||
| pixDisplay(pix1, 0, 400); | ||
| pixDestroy(&pix1); | ||
| } | ||
| pixaDestroy(&pixa1); | ||
| pixaDestroy(&pixa2); | ||
| l_colorfillDestroy(&cf); | ||
|
|
||
| /* Test on an image with lots of color (with 1 tile and 9 tiles) */ | ||
| pix1 = pixRead("lyra.005.jpg"); | ||
| pix2 = pixScale(pix1, 0.5, 0.5); | ||
| pixDestroy(&pix1); | ||
| cf = l_colorfillCreate(pix2, 1, 1); /* 1 tile */ | ||
| pixColorContentByLocation(cf, 0, 0, 0, 70, 30, 100, 1, 1); | ||
| pix3 = pixaDisplayTiledInColumns(cf->pixam, cf->nx, 1.0, 10, 1); | ||
| pix4 = pixaDisplayTiledInColumns(cf->pixadb, cf->nx, 1.0, 10, 1); | ||
| regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 7 */ | ||
| regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 8 */ | ||
| regTestWritePixAndCheck(rp, pix4, IFF_PNG); /* 9 */ | ||
| pixa2 = pixaCreate(3); | ||
| pixaAddPix(pixa2, pix2, L_COPY); | ||
| pixaAddPix(pixa2, pix3, L_INSERT); | ||
| pixaAddPix(pixa2, pix4, L_INSERT); | ||
| if (rp->display) { | ||
| pix1 = pixaDisplayTiledInColumns(pixa2, 3, 0.8, 15, 2); | ||
| pixDisplay(pix1, 0, 650); | ||
| pixDestroy(&pix1); | ||
| } | ||
| l_colorfillDestroy(&cf); | ||
| pixaDestroy(&pixa2); | ||
|
|
||
| cf = l_colorfillCreate(pix2, 3, 3); /* 9 tiles */ | ||
| pixColorContentByLocation(cf, 0, 0, 0, 70, 30, 100, 1, 1); | ||
| pix3 = pixaDisplayTiledInColumns(cf->pixam, cf->nx, 1.0, 10, 1); | ||
| pix4 = pixaDisplayTiledInColumns(cf->pixadb, cf->nx, 1.0, 10, 1); | ||
| regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 10 */ | ||
| regTestWritePixAndCheck(rp, pix4, IFF_PNG); /* 11 */ | ||
| pixa2 = pixaCreate(2); | ||
| pixaAddPix(pixa2, pix3, L_INSERT); | ||
| pixaAddPix(pixa2, pix4, L_INSERT); | ||
| if (rp->display) { | ||
| pix1 = pixaDisplayTiledInColumns(pixa2, 2, 0.8, 15, 2); | ||
| pixDisplay(pix1, 0, 1000); | ||
| pixDestroy(&pix1); | ||
| } | ||
| l_colorfillDestroy(&cf); | ||
| pixDestroy(&pix2); | ||
| pixaDestroy(&pixa2); | ||
|
|
||
| return regTestCleanup(rp); | ||
| } | ||
|
|
||
| static PIX *makeSmallTestPix(l_uint32 c1, l_uint32 c2) | ||
| { | ||
| l_int32 i, j; | ||
| PIX *pix1; | ||
|
|
||
| pix1 = pixCreate(17, 17, 32); | ||
| pixSetAllArbitrary(pix1, c1); | ||
| for (i = 0; i < 15; i++) { | ||
| for (j = 0; j < i; j++) | ||
| pixSetPixel(pix1, j, i, c2); | ||
| } | ||
| for (i = 0; i < 15; i++) { | ||
| for (j = 17 - i; j < 17; j++) | ||
| pixSetPixel(pix1, j, i, c2); | ||
| } | ||
| for (i = 9; i < 17; i++) | ||
| pixSetPixel(pix1, 8, i, c1); | ||
| return pix1; | ||
| } |