void TestGenPathname(L_REGPARAMS *rp, const char *dir, const char *fname, const char *result) { char expect[256], localdir[256]; char *path = genPathname(dir, fname); if (!dir || dir[0] == '\0') { if (!getcwd(localdir, sizeof(localdir))) fprintf(stderr, "bad bad bad -- no local directory!\n"); snprintf(expect, sizeof(expect), "%s/%s", localdir, result); #ifdef _WIN32 convertSepCharsInPath(expect, UNIX_PATH_SEPCHAR); #endif /* _WIN32 */ regTestCompareStrings(rp, (l_uint8 *)expect, strlen(expect), (l_uint8 *)path, strlen(path)); } else { regTestCompareStrings(rp, (l_uint8 *)result, strlen(result), (l_uint8 *)path, strlen(path)); } if (rp->display) { char *newdir = NULL; if (dir && dir[0] == '\0') newdir = stringNew("\"\""); else if (dir) newdir = stringNew(dir); fprintf(stderr, "genPathname(%s, %s) --> %s\n", newdir, fname, path); lept_free(newdir); } lept_free(path); return; }
void TestPathJoin(L_REGPARAMS *rp, const char *first, const char *second, const char *result) { char *newfirst = NULL; char *newsecond = NULL; char *newpath = NULL; char *path = pathJoin(first, second); regTestCompareStrings(rp, (l_uint8 *)result, strlen(result), (l_uint8 *)path, strlen(path)); if (first && first[0] == '\0') newfirst = stringNew("\"\""); else if (first) newfirst = stringNew(first); if (second && second[0] == '\0') newsecond = stringNew("\"\""); else if (second) newsecond = stringNew(second); if (path && path[0] == '\0') newpath = stringNew("\"\""); else if (path) newpath = stringNew(path); if (rp->display) fprintf(stderr, "join: %s + %s --> %s\n", newfirst, newsecond, newpath); lept_free(path); lept_free(newfirst); lept_free(newsecond); lept_free(newpath); return; }
int main(int argc, char **argv) { l_uint8 *array1, *array2; l_int32 n1, n2, n3; size_t size1, size2; FILE *fp; BOXA *boxa1, *boxa2; PIX *pixs, *pix1; PIXA *pixa1; PIXCMAP *cmap; L_REGPARAMS *rp; if (regTestSetup(argc, argv, &rp)) return 1; pixs = pixRead("feyn.tif"); /* --------------------------------------------------------------- * * Test pixConnComp() and pixCountConnComp(), * * with output to both boxa and pixa * * --------------------------------------------------------------- */ /* First, test with 4-cc */ boxa1= pixConnComp(pixs, &pixa1, 4); n1 = boxaGetCount(boxa1); boxa2= pixConnComp(pixs, NULL, 4); n2 = boxaGetCount(boxa2); pixCountConnComp(pixs, 4, &n3); fprintf(stderr, "Number of 4 c.c.: n1 = %d; n2 = %d, n3 = %d\n", n1, n2, n3); regTestCompareValues(rp, n1, n2, 0); /* 0 */ regTestCompareValues(rp, n1, n3, 0); /* 1 */ regTestCompareValues(rp, n1, 4452, 0); /* 2 */ pix1 = pixaDisplay(pixa1, pixGetWidth(pixs), pixGetHeight(pixs)); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 3 */ regTestComparePix(rp, pixs, pix1); /* 4 */ pixaDestroy(&pixa1); boxaDestroy(&boxa1); boxaDestroy(&boxa2); pixDestroy(&pix1); /* Test with 8-cc */ boxa1= pixConnComp(pixs, &pixa1, 8); n1 = boxaGetCount(boxa1); boxa2= pixConnComp(pixs, NULL, 8); n2 = boxaGetCount(boxa2); pixCountConnComp(pixs, 8, &n3); fprintf(stderr, "Number of 8 c.c.: n1 = %d; n2 = %d, n3 = %d\n", n1, n2, n3); regTestCompareValues(rp, n1, n2, 0); /* 5 */ regTestCompareValues(rp, n1, n3, 0); /* 6 */ regTestCompareValues(rp, n1, 4305, 0); /* 7 */ pix1 = pixaDisplay(pixa1, pixGetWidth(pixs), pixGetHeight(pixs)); regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 8 */ regTestComparePix(rp, pixs, pix1); /* 9 */ pixaDestroy(&pixa1); boxaDestroy(&boxa1); boxaDestroy(&boxa2); pixDestroy(&pix1); /* --------------------------------------------------------------- * * Test boxa I/O * * --------------------------------------------------------------- */ lept_mkdir("lept/conn"); boxa1 = pixConnComp(pixs, NULL, 4); fp = lept_fopen("/tmp/lept/conn/boxa1.ba", "wb+"); boxaWriteStream(fp, boxa1); lept_fclose(fp); fp = lept_fopen("/tmp/lept/conn/boxa1.ba", "rb"); boxa2 = boxaReadStream(fp); lept_fclose(fp); fp = lept_fopen("/tmp/lept/conn/boxa2.ba", "wb+"); boxaWriteStream(fp, boxa2); lept_fclose(fp); array1 = l_binaryRead("/tmp/lept/conn/boxa1.ba", &size1); array2 = l_binaryRead("/tmp/lept/conn/boxa2.ba", &size2); regTestCompareStrings(rp, array1, size1, array2, size2); /* 10 */ lept_free(array1); lept_free(array2); boxaDestroy(&boxa1); boxaDestroy(&boxa2); /* --------------------------------------------------------------- * * Just for fun, display each component as a random color in * * cmapped 8 bpp. Background is color 0; it is set to white. * * --------------------------------------------------------------- */ boxa1 = pixConnComp(pixs, &pixa1, 4); pix1 = pixaDisplayRandomCmap(pixa1, pixGetWidth(pixs), pixGetHeight(pixs)); cmap = pixGetColormap(pix1); pixcmapResetColor(cmap, 0, 255, 255, 255); /* reset background to white */ regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 11 */ if (rp->display) pixDisplay(pix1, 100, 100); boxaDestroy(&boxa1); pixDestroy(&pix1); pixaDestroy(&pixa1); pixDestroy(&pixs); return regTestCleanup(rp); }