Skip to content

Commit

Permalink
option to use autoThresholding. Improved version from bachelor thesis…
Browse files Browse the repository at this point in the history
  • Loading branch information
zdenop committed Jul 10, 2012
1 parent e197a9e commit 7409342
Show file tree
Hide file tree
Showing 11 changed files with 979 additions and 13 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Contributors:
Misty De Meo <[email protected]>
zdenop <[email protected]>
Steven Lee http://www.rubypdf.com
Radim Hatlapatka <[email protected]>
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* version info (-V --version)
* pdf.py now correctly retains DPI from input images (thanks to Steven Lee
http://blog.rubypdf.com/2011/09/09/jbig2-pdf-py-patch-the-right-way-to-get-dpi/)
* R. Hatlapatka: option to use autoThresholding. Improved version from
bachelor thesis JBIG2 compression http://is.muni.cz/th/208155/fi_b/.

0.27:
* Update to the latest Leptonica (1.58)
Expand Down
5 changes: 3 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
AM_CXXFLAGS = -Wall

lib_LTLIBRARIES = libjbig2enc.la
libjbig2enc_la_SOURCES = jbig2enc.cc jbig2arith.cc jbig2sym.cc
include_HEADERS = jbig2arith.h jbig2sym.h jbig2structs.h jbig2segments.h
libjbig2enc_la_SOURCES = jbig2enc.cc jbig2arith.cc jbig2sym.cc result.cc jbig2comparator.cc
libjbig2enc_la_LDFLAGS = -no-undefined -version-info $(GENERIC_LIBRARY_VERSION)
include_HEADERS = jbig2arith.h jbig2sym.h jbig2structs.h jbig2segments.h result.h jbig2comparator.h

bin_PROGRAMS = jbig2
jbig2_SOURCES = jbig2.cc
Expand Down
46 changes: 35 additions & 11 deletions src/jbig2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ usage(const char *argv0) {
fprintf(stderr, " -4: upsample 4x before thresholding\n");
fprintf(stderr, " -S: remove images from mixed input and save separately\n");
fprintf(stderr, " -j --jpeg-output: write images from mixed input as JPEG\n");
fprintf(stderr, " -a --autoThresh: engage using autoThresholding for symbol coder\n");
fprintf(stderr, " --nohash: only for debugging purposes to allow easily compare performance with older version\n");
fprintf(stderr, " -V --version: version info\n");
fprintf(stderr, " -v: be verbose\n");
}
Expand Down Expand Up @@ -209,13 +211,15 @@ main(int argc, char **argv) {
l_int32 img_fmt = IFF_PNG;
const char *img_ext = "png";
bool segment = false;
bool autoThresh = false;
bool hash = true;
int i;

#ifdef WIN32
int result = _setmode(_fileno(stdout), _O_BINARY);
if (result == -1)
fprintf(stderr, "Cannot set mode to binary for stdout\n");
#endif

#ifdef WIN32
int result = _setmode(_fileno(stdout), _O_BINARY);
if (result == -1)
fprintf(stderr, "Cannot set mode to binary for stdout\n");
#endif

for (i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-h") == 0 ||
Expand Down Expand Up @@ -327,6 +331,18 @@ main(int argc, char **argv) {
continue;
}

// engage auto thresholding
if (strcmp(argv[i], "--autoThresh") == 0 ||
strcmp(argv[i], "-a") == 0 ) {
autoThresh = true;
continue;
}

if (strcmp(argv[i], "--nohash") == 0) {
hash = false;
continue;
}

if (strcmp(argv[i], "-v") == 0) {
verbose = true;
continue;
Expand All @@ -340,7 +356,7 @@ main(int argc, char **argv) {
usage(argv[0]);
return 4;
}

if (refine && !symbol_mode) {
fprintf(stderr, "Refinement makes not sense unless in symbol mode!\n");
fprintf(stderr, "(if you have -r, you must have -s)\n");
Expand All @@ -360,17 +376,17 @@ main(int argc, char **argv) {
if (subimage==numsubimages) {
subimage = numsubimages = 0;
FILE *fp;
if (verbose) fprintf(stderr, "Processing \"%s\"...\n", argv[i]);
if ((fp=fopen(argv[i], "r"))==NULL) {
fprintf(stderr, "Unable to open \"%s\"\n", argv[i]);
if (verbose) fprintf(stderr, "Processing \"%s\"...\n", argv[i]);
if ((fp=lept_fopen(argv[i], "r"))==NULL) {
fprintf(stderr, "Unable to open \"%s\"\n", argv[i]);
return 1;
}
l_int32 filetype;
findFileFormatStream(fp, &filetype);
if (filetype==IFF_TIFF && tiffGetCount(fp, &numsubimages)) {
return 1;
}
fclose(fp);
lept_fclose(fp);
}

PIX *source;
Expand Down Expand Up @@ -455,6 +471,14 @@ main(int argc, char **argv) {
}
}

if (autoThresh) {
if (hash) {
autoThresholdUsingHash(ctx);
} else {
autoThreshold(ctx);
}
}

uint8_t *ret;
int length;
ret = jbig2_pages_complete(ctx, &length);
Expand Down
Loading

0 comments on commit 7409342

Please sign in to comment.