41 #include <config_auto.h>
45 #include "allheaders.h"
82 char *fname, *tail, *basename;
83 PIX *pixs, *pixg1, *pixg2, *pixb;
86 PROCNAME(
"convertFilesTo1bpp");
89 return ERROR_INT(
"dirin", procName, 1);
91 return ERROR_INT(
"dirout", procName, 1);
92 if (upscaling != 1 && upscaling != 2 && upscaling != 4)
93 return ERROR_INT(
"invalid upscaling factor", procName, 1);
94 if (thresh <= 0) thresh = 180;
95 if (firstpage < 0) firstpage = 0;
96 if (npages < 0) npages = 0;
97 if (outformat != IFF_TIFF_G4)
102 return ERROR_INT(
"safiles not made", procName, 1);
105 return ERROR_INT(
"no matching files in the directory", procName, 1);
108 for (i = 0; i < nfiles; i++) {
110 if ((pixs =
pixRead(fname)) == NULL) {
111 L_WARNING(
"Couldn't read file %s\n", procName, fname);
114 if (pixGetDepth(pixs) == 32)
119 if (pixGetDepth(pixg2) == 1) {
124 else if (upscaling == 2)
135 if (outformat == IFF_TIFF_G4) {
136 snprintf(buf,
sizeof(buf),
"%s/%s.tif", dirout, basename);
137 pixWrite(buf, pixb, IFF_TIFF_G4);
139 snprintf(buf,
sizeof(buf),
"%s/%s.png", dirout, basename);
140 pixWrite(buf, pixb, IFF_PNG);
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()
PIX * pixThresholdToBinary(PIX *pixs, l_int32 thresh)
pixThresholdToBinary()
void pixDestroy(PIX **ppix)
pixDestroy()
PIX * pixClone(PIX *pixs)
pixClone()
@ REMOVE_CMAP_TO_GRAYSCALE
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
PIX * pixConvertRGBToLuminance(PIX *pixs)
pixConvertRGBToLuminance()
PIX * pixRead(const char *filename)
pixRead()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
SARRAY * getSortedPathnamesInDirectory(const char *dirname, const char *substr, l_int32 first, l_int32 nfiles)
getSortedPathnamesInDirectory()
PIX * pixScaleGray4xLIThresh(PIX *pixs, l_int32 thresh)
pixScaleGray4xLIThresh()
PIX * pixScaleGray2xLIThresh(PIX *pixs, l_int32 thresh)
pixScaleGray2xLIThresh()
l_ok splitPathAtExtension(const char *pathname, char **pbasename, char **pextension)
splitPathAtExtension()
l_ok splitPathAtDirectory(const char *pathname, char **pdir, char **ptail)
splitPathAtDirectory()