82char *fname, *tail, *basename;
83PIX *pixs, *pixg1, *pixg2, *pixb;
87 return ERROR_INT(
"dirin", __func__, 1);
89 return ERROR_INT(
"dirout", __func__, 1);
90 if (upscaling != 1 && upscaling != 2 && upscaling != 4)
91 return ERROR_INT(
"invalid upscaling factor", __func__, 1);
92 if (thresh <= 0) thresh = 180;
93 if (firstpage < 0) firstpage = 0;
94 if (npages < 0) npages = 0;
95 if (outformat != IFF_TIFF_G4)
98 safiles = getSortedPathnamesInDirectory(dirin, substr, firstpage, npages);
100 return ERROR_INT(
"safiles not made", __func__, 1);
101 if ((nfiles = sarrayGetCount(safiles)) == 0) {
102 sarrayDestroy(&safiles);
103 return ERROR_INT(
"no matching files in the directory", __func__, 1);
106 for (i = 0; i < nfiles; i++) {
107 fname = sarrayGetString(safiles, i,
L_NOCOPY);
108 if ((pixs = pixRead(fname)) == NULL) {
109 L_WARNING(
"Couldn't read file %s\n", __func__, fname);
112 if (pixGetDepth(pixs) == 32)
113 pixg1 = pixConvertRGBToLuminance(pixs);
115 pixg1 = pixClone(pixs);
117 if (pixGetDepth(pixg2) == 1) {
118 pixb = pixClone(pixg2);
121 pixb = pixThresholdToBinary(pixg2, thresh);
122 else if (upscaling == 2)
123 pixb = pixScaleGray2xLIThresh(pixg2, thresh);
125 pixb = pixScaleGray4xLIThresh(pixg2, thresh);
131 splitPathAtDirectory(fname, NULL, &tail);
132 splitPathAtExtension(tail, &basename, NULL);
133 if (outformat == IFF_TIFF_G4) {
134 snprintf(buf,
sizeof(buf),
"%s/%s.tif", dirout, basename);
135 pixWrite(buf, pixb, IFF_TIFF_G4);
137 snprintf(buf,
sizeof(buf),
"%s/%s.png", dirout, basename);
138 pixWrite(buf, pixb, IFF_PNG);
145 sarrayDestroy(&safiles);
l_ok convertFilesTo1bpp(const char *dirin, const char *substr, l_int32 upscaling, l_int32 thresh, l_int32 firstpage, l_int32 npages, const char *dirout, l_int32 outformat)
convertFilesTo1bpp()