Example #1
0
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;
}
Example #2
0
    /* Returns 1 on error */
static l_int32
test_mem_gif(const char  *fname,
             l_int32      index)
{
l_uint8  *data = NULL;
l_int32   same;
size_t    size = 0;
PIX      *pixs;
PIX      *pixd = NULL;

    if ((pixs = pixRead(fname)) == NULL) {
        fprintf(stderr, "Failure to read gif file: %s\n", fname);
        return 1;
    }
    if (pixWriteMem(&data, &size, pixs, IFF_GIF)) {
        fprintf(stderr, "Mem gif write fail on image %d\n", index);
        return 1;
    }
    if ((pixd = pixReadMem(data, size)) == NULL) {
        fprintf(stderr, "Mem gif read fail on image %d\n", index);
        lept_free(data);
        return 1;
    }

    pixEqual(pixs, pixd, &same);
    pixDestroy(&pixs);
    pixDestroy(&pixd);
    lept_free(data);
    if (!same && index < 6) {
        fprintf(stderr, "Mem gif write/read fail for file %s\n", fname);
        return 1;
    }
    else
        return 0;
}
Example #3
0
    /* Returns 1 on error */
static l_int32
test_mem_png(const char  *fname)
{
l_uint8  *data = NULL;
l_int32   same;
size_t    size = 0;
PIX      *pixs;
PIX      *pixd = NULL;

    if ((pixs = pixRead(fname)) == NULL) {
        fprintf(stderr, "Failure to read %s\n", fname);
        return 1;
    }
    if (pixWriteMem(&data, &size, pixs, IFF_PNG)) {
        fprintf(stderr, "Mem write fail for png\n");
        return 1;
    }
    if ((pixd = pixReadMem(data, size)) == NULL) {
        fprintf(stderr, "Mem read fail for png\n");
        lept_free(data);
        return 1;
    }

    pixEqual(pixs, pixd, &same);
    if (!same)
        fprintf(stderr, "Mem write/read fail for file %s\n", fname);
    pixDestroy(&pixs);
    pixDestroy(&pixd);
    lept_free(data);
    return (!same);
}
Example #4
0
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;
}
Example #5
0
    /* Returns 1 on error */
static l_int32
test_writemem(PIX      *pixs,
              l_int32   format,
              char     *psfile)
{
l_uint8  *data = NULL;
l_int32   same;
size_t    size = 0;
PIX      *pixd = NULL;

    if (format == IFF_PS) {
        pixWriteMemPS(&data, &size, pixs, NULL, 0, 1.0);
        l_binaryWrite(psfile, "w", data, size);
        lept_free(data);
        return 0;
    }

    /* Fail silently if library is not available */
#if !HAVE_LIBJPEG
    if (format == IFF_JFIF_JPEG)
        return 0;
#endif  /* !HAVE_LIBJPEG */
#if !HAVE_LIBPNG
    if (format == IFF_PNG)
        return 0;
#endif  /* !HAVE_LIBPNG */
#if !HAVE_LIBTIFF
    if (format == IFF_TIFF)
        return 0;
#endif  /* !HAVE_LIBTIFF */

    if (pixWriteMem(&data, &size, pixs, format)) {
        fprintf(stderr, "Mem write fail for format %d\n", format);
        return 1;
    }
    if ((pixd = pixReadMem(data, size)) == NULL) {
        fprintf(stderr, "Mem read fail for format %d\n", format);
        lept_free(data);
        return 1;
    }
    if (format == IFF_JFIF_JPEG) {
        fprintf(stderr, "jpeg size = %ld\n", size);
        pixDisplayWrite(pixd, 1);
        same = TRUE;
    }
    else {
        pixEqual(pixs, pixd, &same);
        if (!same)
           fprintf(stderr, "Mem write/read fail for format %d\n", format);
    }
    pixDestroy(&pixd);
    lept_free(data);
    return (!same);
}
Example #6
0
int main(int    argc,
         char **argv)
{
char        *vers;
PIX         *pixs;
l_int32      i;
l_int32      nWriteTries = REPETITIONS;
static char  mainName[] = "gifio_leaktest";

    vers = getLeptonicaVersion();
    fprintf(stderr, "%s\n", vers);
    lept_free(vers);
    vers = getImagelibVersions();
    fprintf(stderr, "%s\n", vers);
    lept_free(vers);

    if (argc > 2)
        return ERROR_INT(" Syntax:  gifio_leaktest [skipWriteTests]",
                         mainName, 1);
    if (argc == 2)
        nWriteTries = 0;

    if ((pixs = pixRead("church.png")) == NULL)
        return ERROR_INT("pix not found", mainName, 1);

    for (i = 0; i < nWriteTries; i++) {
        fprintf(stderr, "Writing attempt %d\n", i+1);
        if (pixWrite("/tmp/church.gif", pixs, IFF_GIF)) {
            fprintf(stderr, "Failed to write gif file on %dth try.\n", i+1);
            break;
        }
    }
    pixDestroy(&pixs);
    if (i == REPETITIONS)
        fprintf(stderr, "Successfully wrote gif file %d times.\n", i);

    for (i = 0; i < REPETITIONS; i++) {
        fprintf(stderr, "Reading attempt %d\n", i+1);
        pixs = pixRead("/tmp/church.gif");
        if (pixs == NULL) {
            fprintf(stderr, "Failed to read gif file on %dth try.\n", i+1);
            break;
        } else {
        pixDestroy(&pixs);
        }
    }
    if (i == REPETITIONS)
        fprintf(stderr, "Successfully read gif file %d times.\n", i);

    return 0;
}
Example #7
0
int main(int    argc,
         char **argv)
{
l_int32      ret;
char        *filein, *tempfile, *printer;
char         buf[512];
static char  mainName[] = "printtiff";

    if (argc != 2 && argc != 3)
        return ERROR_INT(" Syntax:  printtiff filein [printer]", mainName, 1);
    filein = argv[1];
    if (argc == 3)
        printer = argv[2];

    fprintf(stderr,
         "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
         "   Warning: this program should only be used for testing,\n"
         "     and not in a production environment, because of a\n"
         "      potential vulnerability with the 'system' call.\n"
         "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n");

    setLeptDebugOK(1);
    (void)lept_rm(NULL, TEMP_PS);
    tempfile = genPathname("/tmp", TEMP_PS);
    convertTiffMultipageToPS(filein, tempfile, FILL_FACTOR);

    if (argc == 3) {
        snprintf(buf, sizeof(buf), "lpr -P%s %s &", printer, tempfile);
        ret = system(buf);
    }

    lept_free(tempfile);
    return 0;
}
Example #8
0
/*!
 * \brief   l_bootnum_gen2()
 *
 * \return   pixa  of labelled digits
 *
 * <pre>
 * Call this way:
 *      PIXA  *pixa = l_bootnum_gen2();   (C)
 *      Pixa  *pixa = l_bootnum_gen2();   (C++)
 * </pre>
 */
PIXA *
l_bootnum_gen2(void)
{
l_uint8  *data1, *data2;
l_int32   size1;
size_t    size2;
PIXA     *pixa;

        /* Unencode selected string, write to file, and read it */
    data1 = decodeBase64(l_bootnum2, strlen(l_bootnum2), &size1);
    data2 = zlibUncompress(data1, size1, &size2);
    pixa = pixaReadMem(data2, size2);
    lept_free(data1);
    lept_free(data2);
    return pixa;
}
Example #9
0
int main(int argc,
         char **argv) {
    char *filein, *tempfile, *printer;
    char buf[512];
    l_int32 ignore;
    static char mainName[] = "printtiff";

    if (argc != 2 && argc != 3)
        return ERROR_INT(" Syntax:  printtiff filein [printer]", mainName, 1);

    filein = argv[1];
    if (argc == 3)
        printer = argv[2];

    lept_rm(NULL, TEMP_PS);
    tempfile = genPathname("/tmp", TEMP_PS);
    convertTiffMultipageToPS(filein, tempfile, NULL, FILL_FACTOR);

    if (argc == 3) {
        sprintf(buf, "lpr -P%s %s &", printer, tempfile);
        ignore = system(buf);
    }

    lept_free(tempfile);
    return 0;
}
Example #10
0
static void test_parse_false() {
    lept_value v;
    lept_init(&v);
    lept_set_boolean(&v, 1);
    EXPECT_EQ_INT(LEPT_PARSE_OK, lept_parse(&v, "false"));
    EXPECT_EQ_INT(LEPT_FALSE, lept_get_type(&v));
    lept_free(&v);
}
Example #11
0
void PrintVersionInfo() {
  char* versionStrP;

  printf("tesseract %s\n", tesseract::TessBaseAPI::Version());

  versionStrP = getLeptonicaVersion();
  printf(" %s\n", versionStrP);
  lept_free(versionStrP);

  versionStrP = getImagelibVersions();
  printf("  %s\n", versionStrP);
  lept_free(versionStrP);

#ifdef USE_OPENCL
    cl_platform_id platform[4];
    cl_uint num_platforms;

    printf(" OpenCL info:\n");
    if (clGetPlatformIDs(4, platform, &num_platforms) == CL_SUCCESS) {
      printf("  Found %u platform(s).\n", num_platforms);
      for (unsigned n = 0; n < num_platforms; n++) {
        char info[256];
        if (clGetPlatformInfo(platform[n], CL_PLATFORM_NAME, 256, info, 0) == CL_SUCCESS) {
          printf("  Platform %u name: %s.\n", n + 1, info);
        }
        if (clGetPlatformInfo(platform[n], CL_PLATFORM_VERSION, 256, info, 0) == CL_SUCCESS) {
          printf("  Version: %s.\n", info);
        }
        cl_device_id devices[2];
        cl_uint num_devices;
        if (clGetDeviceIDs(platform[n], CL_DEVICE_TYPE_ALL, 2, devices, &num_devices) == CL_SUCCESS) {
          printf("  Found %u device(s).\n", num_devices);
          for (unsigned i = 0; i < num_devices; ++i) {
            if (clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 256, info, 0) == CL_SUCCESS) {
              printf("    Device %u name: %s.\n", i + 1, info);
            }
          }
        }
      }
    }
#endif
  if (SIMDDetect::IsAVXAvailable())
    printf(" Found AVX\n");
  if (SIMDDetect::IsSSEAvailable())
    printf(" Found SSE\n");
}
Example #12
0
static void test_access_null() {
    lept_value v;
    lept_init(&v);
    lept_set_string(&v, "a", 1);
    lept_set_null(&v);
    EXPECT_EQ_INT(LEPT_NULL, lept_get_type(&v));
    lept_free(&v);
}
Example #13
0
static void test_access_number() {
    lept_value v;
    lept_init(&v);
    lept_set_string(&v, "a", 1);
    lept_set_number(&v, 1234.5);
    EXPECT_EQ_DOUBLE(1234.5, lept_get_number(&v));
    lept_free(&v);
}
Example #14
0
static void test_parse_true() {
    lept_value v;
    lept_init(&v);
    lept_set_boolean(&v, 0);
    EXPECT_EQ_INT(LEPT_PARSE_OK, lept_parse(&v, "true"));
    EXPECT_EQ_INT(LEPT_TRUE, lept_get_type(&v));
    lept_free(&v);
}
Example #15
0
static void test_parse_null() {
    lept_value v;
    lept_init(&v);
    lept_set_boolean(&v, 0);
    EXPECT_EQ_INT(LEPT_PARSE_OK, lept_parse(&v, "null"));
    EXPECT_EQ_INT(LEPT_NULL, lept_get_type(&v));
    lept_free(&v);
}
/*!
 *  \brief   l_bootnum_gen3()
 *
 * \return   pixa  of labelled digits
 *
 * <pre>
 * Call this way:
 *      PIXA  *pixa = l_bootnum_gen3();   (C)
 *      Pixa  *pixa = l_bootnum_gen3();   (C++)
 * </pre>
 */
PIXA *
l_bootnum_gen3(void)
{
l_uint8  *data1, *data2;
l_int32   size1;
size_t    size2;
PIXA     *pixa;

    lept_mkdir("lept/auto");

        /* Unencode selected string, uncompress it, and read it */
    data1 = decodeBase64(l_strdata_0, strlen(l_strdata_0), &size1);
    data2 = zlibUncompress(data1, size1, &size2);
    pixa = pixaReadMem(data2, size2);
    lept_free(data1);
    lept_free(data2);
    return pixa;
}
Example #17
0
static void test_access_string() {
    lept_value v;
    lept_init(&v);
    lept_set_string(&v, "", 0);
    EXPECT_EQ_STRING("", lept_get_string(&v), lept_get_string_length(&v));
    lept_set_string(&v, "Hello", 5);
    EXPECT_EQ_STRING("Hello", lept_get_string(&v), lept_get_string_length(&v));
    lept_free(&v);
}
Example #18
0
/*!
 *  l_autodecode_137()
 *
 *      Input:  index into array of functions
 *      Return: data struct (e.g., pixa) in memory
 */
void *
l_autodecode_137(l_int32 index)
{
l_uint8  *data1, *data2;
l_int32   size1;
size_t    size2;
void     *result = NULL;
l_int32   nfunc = 2;

    PROCNAME("l_autodecode_137");

    if (index < 0 || index >= nfunc) {
        L_ERROR("invalid index = %d; must be less than %d\n", procName,
                index, nfunc);
        return NULL;
    }

    lept_mkdir("lept/auto");

        /* Unencode selected string, write to file, and read it */
    switch (index) {
    case 0:
        data1 = decodeBase64(l_strdata_0, strlen(l_strdata_0), &size1);
        data2 = zlibUncompress(data1, size1, &size2);
        l_binaryWrite("/tmp/lept/auto/data.bin","w", data2, size2);
        result = (void *)pixaRead("/tmp/lept/auto/data.bin");
        lept_free(data1);
        lept_free(data2);
        break;
    case 1:
        data1 = decodeBase64(l_strdata_1, strlen(l_strdata_1), &size1);
        data2 = zlibUncompress(data1, size1, &size2);
        l_binaryWrite("/tmp/lept/auto/data.bin","w", data2, size2);
        result = (void *)pixaRead("/tmp/lept/auto/data.bin");
        lept_free(data1);
        lept_free(data2);
        break;
    default:
        L_ERROR("invalid index", procName);
    }

    return result;
}
Example #19
0
static void test_access_boolean() {
    lept_value v;
    lept_init(&v);
    lept_set_string(&v, "a", 1);
    lept_set_boolean(&v, 1);
    EXPECT_TRUE(lept_get_boolean(&v));
    lept_set_boolean(&v, 0);
    EXPECT_FALSE(lept_get_boolean(&v));
    lept_free(&v);
}
Example #20
0
/*!
 *  l_bootnum_gen2()
 *
 *      Return: the bootnum2 pixa
 *
 *  Call this way:
 *      PIXA  *pixa = (PIXA *)l_bootnum_gen2();   (C)
 *      Pixa  *pixa = (Pixa *)l_bootnum_gen2();   (C++)
 */
void *
l_bootnum_gen2(void)
{
l_uint8  *data1, *data2;
l_int32   size1;
size_t    size2;
void     *result;

    lept_mkdir("lept/auto");

        /* Unencode selected string, write to file, and read it */
    data1 = decodeBase64(l_bootnum2, strlen(l_bootnum2), &size1);
    data2 = zlibUncompress(data1, size1, &size2);
    l_binaryWrite("/tmp/lept/auto/data.bin", "w", data2, size2);
    result = (void *)pixaRead("/tmp/lept/auto/data.bin");
    lept_free(data1);
    lept_free(data2);
    return result;
}
Example #21
0
int main(int    argc,
         char **argv)
{
l_int32      unique;
l_int32     *array;
L_SUDOKU    *sud;
static char  mainName[] = "sudokutest";

    if (argc != 1 && argc != 2)
	return ERROR_INT(" Syntax: sudokutest [filein]", mainName, 1);

    if (argc == 1) {
            /* Generate a new sudoku by element elimination */
        array = sudokuReadString(startsol);
        sud = sudokuGenerate(array, 3693, 28, 7);
        sudokuDestroy(&sud);
        lept_free(array);
        return 0;
    }

        /* Solve the input sudoku */
    if ((array = sudokuReadFile(argv[1])) == NULL)
        return ERROR_INT("invalid input", mainName, 1);
    if ((sud = sudokuCreate(array)) == NULL)
        return ERROR_INT("sud not made", mainName, 1);
    sudokuOutput(sud, L_SUDOKU_INIT);
    startTimer();
    sudokuSolve(sud);
    fprintf(stderr, "Time: %7.3f sec\n", stopTimer());
    sudokuOutput(sud, L_SUDOKU_STATE);
    sudokuDestroy(&sud);

        /* Test for uniqueness */
    sudokuTestUniqueness(array, &unique);
    if (unique)
        fprintf(stderr, "Sudoku is unique\n");
    else
        fprintf(stderr, "Sudoku is NOT unique\n");
    lept_free(array);

    return 0;
}
l_int32 main(int    argc,
             char **argv)
{
l_uint32     *colors;
l_int32       ncolors;
PIX          *pix1, *pix2, *pix3;
L_REGPARAMS  *rp;

    if (regTestSetup(argc, argv, &rp))
        return 1;

        /* Find the most populated colors */
    pix1 = pixRead("fish24.jpg");
    pixGetMostPopulatedColors(pix1, 2, 3, 10, &colors, NULL);
    pix2 = pixDisplayColorArray(colors, 10, 190, 5, 1);
    pixDisplayWithTitle(pix2, 0, 0, NULL, rp->display);
    regTestWritePixAndCheck(rp, pix2, IFF_PNG);  /* 0 */
    lept_free(colors);
    pixDestroy(&pix2);

        /* Do a simple color quantization with sigbits = 2 */
    pix2 = pixSimpleColorQuantize(pix1, 2, 3, 10);
    pixDisplayWithTitle(pix2, 0, 400, NULL, rp->display);
    regTestWritePixAndCheck(rp, pix2, IFF_PNG);  /* 1 */
    pix3 = pixRemoveColormap(pix2, REMOVE_CMAP_TO_FULL_COLOR);
    regTestComparePix(rp, pix2, pix3);  /* 2 */
    pixNumColors(pix3, 1, &ncolors);
    regTestCompareValues(rp, ncolors, 10, 0.0);  /* 3 */
    pixDestroy(&pix1);
    pixDestroy(&pix2);
    pixDestroy(&pix3);

        /* Do a simple color quantization with sigbits = 3 */
    pix1 = pixRead("wyom.jpg");
    pixNumColors(pix1, 1, &ncolors);  /* >255, so should give 0 */
    regTestCompareValues(rp, ncolors, 0, 0.0);  /* 4 */
    pix2 = pixSimpleColorQuantize(pix1, 3, 3, 20);
    pixDisplayWithTitle(pix2, 1000, 0, NULL, rp->display);
    regTestWritePixAndCheck(rp, pix2, IFF_PNG);  /* 5 */
    ncolors = pixcmapGetCount(pixGetColormap(pix2));
    regTestCompareValues(rp, ncolors, 20, 0.0);  /* 6 */
    pixDestroy(&pix1);
    pixDestroy(&pix2);

        /* Find the number of perceptually significant gray intensities */
    pix1 = pixRead("marge.jpg");
    pix2 = pixConvertTo8(pix1, 0);
    pixNumSignificantGrayColors(pix2, 20, 236, 0.0001, 1, &ncolors);
    regTestCompareValues(rp, ncolors, 219, 0.0);  /* 7 */
    pixDestroy(&pix1);
    pixDestroy(&pix2);

    return regTestCleanup(rp);
}
Example #23
0
    /* Retrieve header data from file and from array in memory */
static l_int32
get_header_data(const char  *filename)
{
l_uint8  *data;
l_int32   ret1, ret2, format1, format2;
l_int32   w1, w2, h1, h2, d1, d2, bps1, bps2, spp1, spp2, iscmap1, iscmap2;
size_t    nbytes1, nbytes2;

        /* Read header from file */
    nbytes1 = nbytesInFile(filename);
    ret1 = pixReadHeader(filename, &format1, &w1, &h1, &bps1, &spp1, &iscmap1);
    d1 = bps1 * spp1;
    if (d1 == 24) d1 = 32;
    if (ret1)
        fprintf(stderr, "Error: couldn't read header data from file: %s\n",
                filename);
    else {
        fprintf(stderr, "Format data for image %s with format %s:\n"
            "  nbytes = %ld, size (w, h, d) = (%d, %d, %d)\n"
            "  bps = %d, spp = %d, iscmap = %d\n",
            filename, ImageFileFormatExtensions[format1], nbytes1,
            w1, h1, d1, bps1, spp1, iscmap1);
        if (format1 != IFF_PNG) {
            fprintf(stderr, "Error: format is %d; should be %d\n",
                    format1, IFF_PNG);
            ret1 = 1;
        }
    }

        /* Read header from array in memory */
    ret2 = 0;
#if HAVE_FMEMOPEN
    data = l_binaryRead(filename, &nbytes2);
    ret2 = pixReadHeaderMem(data, nbytes2, &format2, &w2, &h2, &bps2,
                            &spp2, &iscmap2);
    lept_free(data);
    d2 = bps2 * spp2;
    if (d2 == 24) d2 = 32;
    if (ret2)
        fprintf(stderr, "Error: couldn't mem-read header data: %s\n", filename);
    else {
        if (nbytes1 != nbytes2 || format1 != format2 || w1 != w2 ||
            h1 != h2 || d1 != d2 || bps1 != bps2 || spp1 != spp2 ||
            iscmap1 != iscmap2) {
            fprintf(stderr, "Incomsistency reading image %s with format %s\n",
                    filename, ImageFileFormatExtensions[IFF_PNG]);
            ret2 = 1;
        }
    }
#endif  /* HAVE_FMEMOPEN */

    return ret1 || ret2;
}
Example #24
0
static void test_parse_array() {
    size_t i, j;
    lept_value v;

    lept_init(&v);
    EXPECT_EQ_INT(LEPT_PARSE_OK, lept_parse(&v, "[ ]"));
    EXPECT_EQ_INT(LEPT_ARRAY, lept_get_type(&v));
    EXPECT_EQ_SIZE_T(0, lept_get_array_size(&v));
    lept_free(&v);

    lept_init(&v);
    EXPECT_EQ_INT(LEPT_PARSE_OK, lept_parse(&v, "[ null , false , true , 123 , \"abc\" ]"));
    EXPECT_EQ_INT(LEPT_ARRAY, lept_get_type(&v));
    EXPECT_EQ_SIZE_T(5, lept_get_array_size(&v));
    EXPECT_EQ_INT(LEPT_NULL,   lept_get_type(lept_get_array_element(&v, 0)));
    EXPECT_EQ_INT(LEPT_FALSE,  lept_get_type(lept_get_array_element(&v, 1)));
    EXPECT_EQ_INT(LEPT_TRUE,   lept_get_type(lept_get_array_element(&v, 2)));
    EXPECT_EQ_INT(LEPT_NUMBER, lept_get_type(lept_get_array_element(&v, 3)));
    EXPECT_EQ_INT(LEPT_STRING, lept_get_type(lept_get_array_element(&v, 4)));
    EXPECT_EQ_DOUBLE(123.0, lept_get_number(lept_get_array_element(&v, 3)));
    EXPECT_EQ_STRING("abc", lept_get_string(lept_get_array_element(&v, 4)), lept_get_string_length(lept_get_array_element(&v, 4)));
    lept_free(&v);

    lept_init(&v);
    EXPECT_EQ_INT(LEPT_PARSE_OK, lept_parse(&v, "[ [ ] , [ 0 ] , [ 0 , 1 ] , [ 0 , 1 , 2 ] ]"));
    EXPECT_EQ_INT(LEPT_ARRAY, lept_get_type(&v));
    EXPECT_EQ_SIZE_T(4, lept_get_array_size(&v));
    for (i = 0; i < 4; i++) {
        lept_value* a = lept_get_array_element(&v, i);
        EXPECT_EQ_INT(LEPT_ARRAY, lept_get_type(a));
        EXPECT_EQ_SIZE_T(i, lept_get_array_size(a));
        for (j = 0; j < i; j++) {
            lept_value* e = lept_get_array_element(a, j);
            EXPECT_EQ_INT(LEPT_NUMBER, lept_get_type(e));
            EXPECT_EQ_DOUBLE((double)j, lept_get_number(e));
        }
    }
    lept_free(&v);
}
Example #25
0
void PrintVersionInfo() {
    char *versionStrP;

    fprintf(stderr, "tesseract %s\n", tesseract::TessBaseAPI::Version());

    versionStrP = getLeptonicaVersion();
    fprintf(stderr, " %s\n", versionStrP);
    lept_free(versionStrP);

    versionStrP = getImagelibVersions();
    fprintf(stderr, "  %s\n", versionStrP);
    lept_free(versionStrP);

#ifdef USE_OPENCL
    cl_platform_id platform;
    cl_uint num_platforms;
    cl_device_id devices[2];
    cl_uint num_devices;
    char info[256];
    int i;

    fprintf(stderr, " OpenCL info:\n");
    clGetPlatformIDs(1, &platform, &num_platforms);
    fprintf(stderr, "  Found %d platforms.\n", num_platforms);
    clGetPlatformInfo(platform, CL_PLATFORM_NAME, 256, info, 0);
    fprintf(stderr, "  Platform name: %s.\n", info);
    clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 256, info, 0);
    fprintf(stderr, "  Version: %s.\n", info);
    clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 2, devices, &num_devices);
    fprintf(stderr, "  Found %d devices.\n", num_devices);
    for (i = 0; i < num_devices; ++i) {
      clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 256, info, 0);
      fprintf(stderr, "    Device %d name: %s.\n", i+1, info);
    }
#endif
}
Example #26
0
static void
TestMapIterator5(L_AMAP  *m,
                 l_int32  print)  /* reverse iterator; rebuild the tree */
{
l_int32       count, npix, ival;
l_uint32      ukey;
L_AMAP       *m2;
L_AMAP_NODE  *n, *np, *n2;

    m2 = l_amapCreate(L_UINT_TYPE);
    n = l_amapGetLast(m);
    count = npix = 0;
    fprintf(stderr, "\n ------- Begin reverse iter; rebuild tree --------\n");
    while (n) {
        np = l_amapGetPrev(n);
        count++;
        ukey = n->key.utype;
        ival = n->value.itype;
        l_amapInsert(m2, n->key, n->value);
        npix += ival;
        if (print)
            fprintf(stderr, "key = %x, val = %d\n", ukey, ival);
        l_amapDelete(m, n->key);
        n = np;
    }
    m->root = m2->root;
    lept_free(m2);
    fprintf(stderr, "Count from iterator: %d\n", count);
    fprintf(stderr, "Number of pixels: %d\n", npix);
    count = npix = 0;
    n = l_amapGetLast(m);
    while (n) {
        np = l_amapGetPrev(n);
        count++;
        ukey = n->key.utype;
        ival = n->value.itype;
        npix += ival;
        if (print)
            fprintf(stderr, "key = %x, val = %d\n", ukey, ival);
        n = np;
    }
    fprintf(stderr, "Count from iterator: %d\n", count);
    fprintf(stderr, "Number of pixels: %d\n", npix);
    fprintf(stderr, " ------- End reverse iter; rebuild tree --------\n");
    return;
}
Example #27
0
// Send an image of type Pix.
void ScrollView::Image(struct Pix* image, int x_pos, int y_pos) {
  l_uint8* data;
  size_t size;
  pixWriteMem(&data, &size, image, IFF_PNG);
  int base64_len = (size + 2) / 3 * 4;
  y_pos = TranslateYCoordinate(y_pos);
  SendMsg("readImage(%d,%d,%d)", x_pos, y_pos, base64_len);
  // Base64 encode the data.
  const char kBase64Table[64] = {
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
    'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
    'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
    'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
    'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
    'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
    'w', 'x', 'y', 'z', '0', '1', '2', '3',
    '4', '5', '6', '7', '8', '9', '+', '/',
  };
  char* base64 = new char[base64_len + 1];
  memset(base64, '=', base64_len);
  base64[base64_len] = '\0';
  int remainder = 0;
  int bits_left = 0;
  int code_len = 0;
  for (size_t i = 0; i < size; ++i) {
    int code = (data[i] >> (bits_left + 2)) | remainder;
    base64[code_len++] = kBase64Table[code & 63];
    bits_left += 2;
    remainder = data[i] << (6 - bits_left);
    if (bits_left == 6) {
      base64[code_len++] = kBase64Table[remainder & 63];
      bits_left = 0;
      remainder = 0;
    }
  }
  if (bits_left > 0)
    base64[code_len++] = kBase64Table[remainder & 63];
  SendRawMessage(base64);
  delete [] base64;
  lept_free(data);
}
Example #28
0
int main(int argc, char **argv) {
  if ((argc == 2 && strcmp(argv[1], "-v") == 0) ||
      (argc == 2 && strcmp(argv[1], "--version") == 0)) {
    char *versionStrP;

    fprintf(stderr, "tesseract %s\n", tesseract::TessBaseAPI::Version());

    versionStrP = getLeptonicaVersion();
    fprintf(stderr, " %s\n", versionStrP);
    lept_free(versionStrP);

    versionStrP = getImagelibVersions();
    fprintf(stderr, "  %s\n", versionStrP);
    lept_free(versionStrP);

#ifdef USE_OPENCL
    cl_platform_id platform;
    cl_uint num_platforms;
    cl_device_id devices[2];
    cl_uint num_devices;
    char info[256];
    int i;

    fprintf(stderr, " OpenCL info:\n");
    clGetPlatformIDs(1, &platform, &num_platforms);
    fprintf(stderr, "  Found %d platforms.\n", num_platforms);
    clGetPlatformInfo(platform, CL_PLATFORM_NAME, 256, info, 0);
    fprintf(stderr, "  Platform name: %s.\n", info);
    clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 256, info, 0);
    fprintf(stderr, "  Version: %s.\n", info);
    clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 2, devices, &num_devices);
    fprintf(stderr, "  Found %d devices.\n", num_devices);
    for (i = 0; i < num_devices; ++i) {
      clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 256, info, 0);
      fprintf(stderr, "    Device %d name: %s.\n", i+1, info);
    }
#endif
    exit(0);
  }

  // Make the order of args a bit more forgiving than it used to be.
  const char* lang = "eng";
  const char* image = NULL;
  const char* outputbase = NULL;
  const char* datapath = NULL;
  bool noocr = false;
  bool list_langs = false;
  bool print_parameters = false;
  GenericVector<STRING> vars_vec, vars_values;

  tesseract::PageSegMode pagesegmode = tesseract::PSM_AUTO;
  int arg = 1;
  while (arg < argc && (outputbase == NULL || argv[arg][0] == '-')) {
    if (strcmp(argv[arg], "-l") == 0 && arg + 1 < argc) {
      lang = argv[arg + 1];
      ++arg;
    } else if (strcmp(argv[arg], "--tessdata-dir") == 0 && arg + 1 < argc) {
      datapath = argv[arg + 1];
      ++arg;
    } else if (strcmp(argv[arg], "--user-words") == 0 && arg + 1 < argc) {
      vars_vec.push_back("user_words_file");
      vars_values.push_back(argv[arg + 1]);
      ++arg;
    } else if (strcmp(argv[arg], "--user-patterns") == 0 && arg + 1 < argc) {
      vars_vec.push_back("user_patterns_file");
      vars_values.push_back(argv[arg + 1]);
      ++arg;
    } else if (strcmp(argv[arg], "--list-langs") == 0) {
      noocr = true;
      list_langs = true;
    } else if (strcmp(argv[arg], "-psm") == 0 && arg + 1 < argc) {
      pagesegmode = static_cast<tesseract::PageSegMode>(atoi(argv[arg + 1]));
      ++arg;
    } else if (strcmp(argv[arg], "--print-parameters") == 0) {
      noocr = true;
      print_parameters = true;
    } else if (strcmp(argv[arg], "-c") == 0 && arg + 1 < argc) {
      // handled properly after api init
      ++arg;
    } else if (image == NULL) {
      image = argv[arg];
    } else if (outputbase == NULL) {
      outputbase = argv[arg];
    }
    ++arg;
  }

  if (argc == 2 && strcmp(argv[1], "--list-langs") == 0) {
    list_langs = true;
    noocr = true;
  }

  if (outputbase == NULL && noocr == false) {
    fprintf(stderr, "Usage:\n  %s imagename|stdin outputbase|stdout "
            "[options...] [configfile...]\n\n", argv[0]);

    fprintf(stderr, "OCR options:\n");
    fprintf(stderr, "  --tessdata-dir /path\tspecify the location of tessdata"
                      " path\n");
    fprintf(stderr, "  --user-words /path/to/file\tspecify the location of user"
            " words file\n");
    fprintf(stderr, "  --user-patterns /path/to/file\tspecify the location of"
            " user patterns file\n");
    fprintf(stderr, "  -l lang[+lang]\tspecify language(s) used for OCR\n");
    fprintf(stderr, "  -c configvar=value\tset value for control parameter.\n"
                      "\t\t\tMultiple -c arguments are allowed.\n");
    fprintf(stderr, "  -psm pagesegmode\tspecify page segmentation mode.\n");
    fprintf(stderr, "These options must occur before any configfile.\n\n");
    fprintf(stderr,
            "pagesegmode values are:\n"
            "  0 = Orientation and script detection (OSD) only.\n"
            "  1 = Automatic page segmentation with OSD.\n"
            "  2 = Automatic page segmentation, but no OSD, or OCR\n"
            "  3 = Fully automatic page segmentation, but no OSD. (Default)\n"
            "  4 = Assume a single column of text of variable sizes.\n"
            "  5 = Assume a single uniform block of vertically aligned text.\n"
            "  6 = Assume a single uniform block of text.\n"
            "  7 = Treat the image as a single text line.\n"
            "  8 = Treat the image as a single word.\n"
            "  9 = Treat the image as a single word in a circle.\n"
            "  10 = Treat the image as a single character.\n\n");
    fprintf(stderr, "Single options:\n");
    fprintf(stderr, "  -v --version: version info\n");
    fprintf(stderr, "  --list-langs: list available languages for tesseract "
                      "engine. Can be used with --tessdata-dir.\n");
    fprintf(stderr, "  --print-parameters: print tesseract parameters to the "
                      "stdout.\n");
    exit(1);
  }

  if (outputbase != NULL && strcmp(outputbase, "-") &&
      strcmp(outputbase, "stdout")) {
    tprintf("Tesseract Open Source OCR Engine v%s with Leptonica\n",
           tesseract::TessBaseAPI::Version());
  }
  PERF_COUNT_START("Tesseract:main")
  tesseract::TessBaseAPI api;

  api.SetOutputName(outputbase);
  int rc = api.Init(datapath, lang, tesseract::OEM_DEFAULT,
                &(argv[arg]), argc - arg, &vars_vec, &vars_values, false);

  if (rc) {
    fprintf(stderr, "Could not initialize tesseract.\n");
    exit(1);
  }

  char opt1[255], opt2[255];
  for (arg = 0; arg < argc; arg++) {
    if (strcmp(argv[arg], "-c") == 0 && arg + 1 < argc) {
      strncpy(opt1, argv[arg + 1], 255);
      char *p = strchr(opt1, '=');
      if (!p) {
        fprintf(stderr, "Missing = in configvar assignment\n");
        exit(1);
      }
      *p = 0;
      strncpy(opt2, strchr(argv[arg + 1], '=') + 1, 255);
      opt2[254] = 0;
      ++arg;

      if (!api.SetVariable(opt1, opt2)) {
        fprintf(stderr, "Could not set option: %s=%s\n", opt1, opt2);
      }
    }
  }

  if (list_langs) {
     GenericVector<STRING> languages;
     api.GetAvailableLanguagesAsVector(&languages);
     fprintf(stderr, "List of available languages (%d):\n",
             languages.size());
     for (int index = 0; index < languages.size(); ++index) {
       STRING& string = languages[index];
       fprintf(stderr, "%s\n", string.string());
     }
     api.End();
     exit(0);
  }

  if (print_parameters) {
     FILE* fout = stdout;
     fprintf(stdout, "Tesseract parameters:\n");
     api.PrintVariables(fout);
     api.End();
     exit(0);
  }

  // We have 2 possible sources of pagesegmode: a config file and
  // the command line. For backwards compatibility reasons, the
  // default in tesseract is tesseract::PSM_SINGLE_BLOCK, but the
  // default for this program is tesseract::PSM_AUTO. We will let
  // the config file take priority, so the command-line default
  // can take priority over the tesseract default, so we use the
  // value from the command line only if the retrieved mode
  // is still tesseract::PSM_SINGLE_BLOCK, indicating no change
  // in any config file. Therefore the only way to force
  // tesseract::PSM_SINGLE_BLOCK is from the command line.
  // It would be simpler if we could set the value before Init,
  // but that doesn't work.
  if (api.GetPageSegMode() == tesseract::PSM_SINGLE_BLOCK)
     api.SetPageSegMode(pagesegmode);

  if (pagesegmode == tesseract::PSM_AUTO_ONLY ||
      pagesegmode == tesseract::PSM_OSD_ONLY) {
    int ret_val = 0;

    Pix* pixs = pixRead(image);
    if (!pixs) {
      fprintf(stderr, "Cannot open input file: %s\n", image);
      exit(2);
    }
    api.SetImage(pixs);

    if (pagesegmode == tesseract::PSM_OSD_ONLY) {
       OSResults osr;
       if (api.DetectOS(&osr)) {
         int orient = osr.best_result.orientation_id;
         int script_id = osr.get_best_script(orient);
         float orient_oco = osr.best_result.oconfidence;
         float orient_sco = osr.best_result.sconfidence;
         tprintf("Orientation: %d\nOrientation in degrees: %d\n" \
                 "Orientation confidence: %.2f\n" \
                 "Script: %d\nScript confidence: %.2f\n",
                 orient, OrientationIdToValue(orient), orient_oco,
                 script_id, orient_sco);
       } else {
         ret_val = 1;
       }
    } else {
       tesseract::Orientation orientation;
       tesseract::WritingDirection direction;
       tesseract::TextlineOrder order;
       float deskew_angle;
       tesseract::PageIterator* it =  api.AnalyseLayout();
       if (it) {
         it->Orientation(&orientation, &direction, &order, &deskew_angle);
         tprintf("Orientation: %d\nWritingDirection: %d\nTextlineOrder: %d\n" \
                 "Deskew angle: %.4f\n",
                 orientation, direction, order, deskew_angle);
       } else {
         ret_val = 1;
       }
       delete it;
    }
    pixDestroy(&pixs);
    exit(ret_val);
  }

  bool b;
  tesseract::PointerVector<tesseract::TessResultRenderer> renderers;
  api.GetBoolVariable("tessedit_create_hocr", &b);
  if (b) {
    bool font_info;
    api.GetBoolVariable("hocr_font_info", &font_info);
    renderers.push_back(new tesseract::TessHOcrRenderer(outputbase, font_info));
  }
  api.GetBoolVariable("tessedit_create_pdf", &b);
  if (b) {
    renderers.push_back(new tesseract::TessPDFRenderer(outputbase,
                                                       api.GetDatapath()));
  }
  api.GetBoolVariable("tessedit_write_unlv", &b);
  if (b) renderers.push_back(new tesseract::TessUnlvRenderer(outputbase));
  api.GetBoolVariable("tessedit_create_boxfile", &b);
  if (b) renderers.push_back(new tesseract::TessBoxTextRenderer(outputbase));
  api.GetBoolVariable("tessedit_create_txt", &b);
  if (b) renderers.push_back(new tesseract::TessTextRenderer(outputbase));
  if (!renderers.empty()) {
    // Since the PointerVector auto-deletes, null-out the renderers that are
    // added to the root, and leave the root in the vector.
    for (int r = 1; r < renderers.size(); ++r) {
      renderers[0]->insert(renderers[r]);
      renderers[r] = NULL;
    }
    if (!api.ProcessPages(image, NULL, 0, renderers[0])) {
      fprintf(stderr, "Error during processing.\n");
      exit(1);
    }
  }

  PERF_COUNT_END
  return 0;                      // Normal exit
}
Example #29
0
int main(int    argc,
         char **argv)
{
char        *filein, *str, *prestring, *outprotos, *protostr;
const char  *spacestr = " ";
char         buf[L_BUF_SIZE];
l_uint8     *allheaders;
l_int32      i, maxindex, in_line, nflags, protos_added, firstfile, len, ret;
size_t       nbytes;
L_BYTEA     *ba, *ba2;
SARRAY      *sa, *safirst;
static char  mainName[] = "xtractprotos";

    if (argc == 1) {
        fprintf(stderr,
                "xtractprotos [-prestring=<string>] [-protos=<where>] "
                "[list of C files]\n"
                "where the prestring is prepended to each prototype, and \n"
                "protos can be either 'inline' or the name of an output "
                "prototype file\n");
        return 1;
    }

    /* ---------------------------------------------------------------- */
    /* Parse input flags and find prestring and outprotos, if requested */
    /* ---------------------------------------------------------------- */
    prestring = outprotos = NULL;
    in_line = FALSE;
    nflags = 0;
    maxindex = L_MIN(3, argc);
    for (i = 1; i < maxindex; i++) {
        if (argv[i][0] == '-') {
            if (!strncmp(argv[i], "-prestring", 10)) {
                nflags++;
                ret = sscanf(argv[i] + 1, "prestring=%s", buf);
                if (ret != 1) {
                    fprintf(stderr, "parse failure for prestring\n");
                    return 1;
                }
                if ((len = strlen(buf)) > L_BUF_SIZE - 3) {
                    L_WARNING("prestring too large; omitting!\n", mainName);
                } else {
                    buf[len] = ' ';
                    buf[len + 1] = '\0';
                    prestring = stringNew(buf);
                }
            } else if (!strncmp(argv[i], "-protos", 7)) {
                nflags++;
                ret = sscanf(argv[i] + 1, "protos=%s", buf);
                if (ret != 1) {
                    fprintf(stderr, "parse failure for protos\n");
                    return 1;
                }
                outprotos = stringNew(buf);
                if (!strncmp(outprotos, "inline", 7))
                    in_line = TRUE;
            }
        }
    }

    if (argc - nflags < 2) {
        fprintf(stderr, "no files specified!\n");
        return 1;
    }


    /* ---------------------------------------------------------------- */
    /*                   Generate the prototype string                  */
    /* ---------------------------------------------------------------- */
    ba = l_byteaCreate(500);

        /* First the extern C head */
    sa = sarrayCreate(0);
    sarrayAddString(sa, (char *)"/*", 1);
    snprintf(buf, L_BUF_SIZE,
             " *  These prototypes were autogen'd by xtractprotos, v. %s",
             version);
    sarrayAddString(sa, buf, 1);
    sarrayAddString(sa, (char *)" */", 1);
    sarrayAddString(sa, (char *)"#ifdef __cplusplus", 1);
    sarrayAddString(sa, (char *)"extern \"C\" {", 1);
    sarrayAddString(sa, (char *)"#endif  /* __cplusplus */\n", 1);
    str = sarrayToString(sa, 1);
    l_byteaAppendString(ba, str);
    lept_free(str);
    sarrayDestroy(&sa);

        /* Then the prototypes */
    firstfile = 1 + nflags;
    protos_added = FALSE;
    for (i = firstfile; i < argc; i++) {
        filein = argv[i];
	len = strlen(filein);
	if (filein[len - 1] == 'h')  /* skip .h files */
	    continue;
	snprintf(buf, L_BUF_SIZE, "cpp -ansi -DNO_PROTOS %s %s",
	         filein, tempfile);
	ret = system(buf);
	if (ret) {
            fprintf(stderr, "cpp failure for %s; continuing\n", filein);
	    continue;
	}

	if ((str = parseForProtos(tempfile, prestring)) == NULL) {
            fprintf(stderr, "parse failure for %s; continuing\n", filein);
	    continue;
	}
	if (strlen(str) > 1) {  /* strlen(str) == 1 is a file without protos */
            l_byteaAppendString(ba, str);
            protos_added = TRUE;
        }
        lept_free(str);
    }

        /* Lastly the extern C tail */
    sa = sarrayCreate(0);
    sarrayAddString(sa, (char *)"\n#ifdef __cplusplus", 1);
    sarrayAddString(sa, (char *)"}", 1);
    sarrayAddString(sa, (char *)"#endif  /* __cplusplus */", 1);
    str = sarrayToString(sa, 1);
    l_byteaAppendString(ba, str);
    lept_free(str);
    sarrayDestroy(&sa);

    protostr = (char *)l_byteaCopyData(ba, &nbytes);
    l_byteaDestroy(&ba);


    /* ---------------------------------------------------------------- */
    /*                       Generate the output                        */
    /* ---------------------------------------------------------------- */
    if (!outprotos) {  /* just write to stdout */
        fprintf(stderr, "%s\n", protostr);
        lept_free(protostr);
        return 0;
    }

        /* If no protos were found, do nothing further */
    if (!protos_added) {
        fprintf(stderr, "No protos found\n");
        lept_free(protostr);
        return 1;
    }

        /* Make the output files */
    ba = l_byteaInitFromFile("allheaders_top.txt");
    if (!in_line) {
        snprintf(buf, sizeof(buf), "#include \"%s\"\n", outprotos);
        l_byteaAppendString(ba, buf);
        l_binaryWrite(outprotos, "w", protostr, nbytes);
    } else {
        l_byteaAppendString(ba, protostr);
    }
    ba2 = l_byteaInitFromFile("allheaders_bot.txt");
    l_byteaJoin(ba, &ba2);
    l_byteaWrite("allheaders.h", ba, 0, 0);
    l_byteaDestroy(&ba);
    lept_free(protostr);
    return 0;
}
Example #30
0
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);
}