From c80be4b0215ba8a1e8d8d919740c5a0e46153fa7 Mon Sep 17 00:00:00 2001 From: MarkJoy Date: Sun, 8 Dec 2024 18:08:14 +0100 Subject: [PATCH 1/4] Fix Endian issue on ARM #63 --- src/jbig2segments.h | 4 ++-- src/jbig2structs.h | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/jbig2segments.h b/src/jbig2segments.h index a58a468..3cfaedb 100644 --- a/src/jbig2segments.h +++ b/src/jbig2segments.h @@ -33,7 +33,7 @@ #endif struct jbig2_segment { u32 number; -#ifndef _BIG_ENDIAN +#ifndef __BIG_ENDIAN__ unsigned char type : 6; unsigned char page_assoc_size : 1; unsigned char deferred_non_retain : 1; @@ -43,7 +43,7 @@ struct jbig2_segment { unsigned char type : 6; #endif -#ifndef _BIG_ENDIAN +#ifndef __BIG_ENDIAN__ unsigned char retain_bits : 5; unsigned char segment_count : 3; #else diff --git a/src/jbig2structs.h b/src/jbig2structs.h index ffedb53..e92a4f3 100644 --- a/src/jbig2structs.h +++ b/src/jbig2structs.h @@ -43,7 +43,7 @@ enum { struct jbig2_file_header { u8 id[8]; -#ifndef _BIG_ENDIAN +#ifndef __BIG_ENDIAN__ u8 organisation_type : 1; u8 unknown_n_pages : 1; u8 reserved : 6; @@ -60,7 +60,7 @@ struct jbig2_page_info { u32 height; u32 xres; u32 yres; -#ifndef _BIG_ENDIAN +#ifndef __BIG_ENDIAN__ u8 is_lossless : 1; u8 contains_refinements : 1; u8 default_pixel : 1; @@ -87,7 +87,7 @@ struct jbig2_generic_region { u32 y; u8 comb_operator; -#ifndef _BIG_ENDIAN +#ifndef __BIG_ENDIAN__ u8 mmr : 1; u8 gbtemplate : 2; u8 tpgdon : 1; @@ -105,7 +105,7 @@ struct jbig2_generic_region { } PACKED ; struct jbig2_symbol_dict { -#ifndef _BIG_ENDIAN +#ifndef __BIG_ENDIAN__ u8 sdhuff:1; u8 sdrefagg:1; u8 sdhuffdh:2; @@ -146,7 +146,7 @@ struct jbig2_text_region { u32 y; u8 comb_operator; -#ifndef _BIG_ENDIAN +#ifndef __BIG_ENDIAN__ u8 sbcombop2:1; u8 sbdefpixel:1; u8 sbdsoffset:5; From 07151c033981a41ddb8ce65ac893ed6c8e474bd6 Mon Sep 17 00:00:00 2001 From: zdenop Date: Sun, 8 Dec 2024 19:00:27 +0100 Subject: [PATCH 2/4] increase minimum cmake version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c9a0fd0..74978af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.6) +cmake_minimum_required(VERSION 3.10) project(jbig2enc CXX) set(Version "0.29") From f1edbd89944910672d6759aecb999f9c34132e98 Mon Sep 17 00:00:00 2001 From: zvezdochiot Date: Sun, 8 Dec 2024 19:03:01 +0100 Subject: [PATCH 3/4] neat symbolic threshold 0.92 --- README.md | 4 ++-- src/jbig2.cc | 8 ++++---- src/jbig2comparator.cc | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0801e1e..4ad214f 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,13 @@ See the `jbig2enc.h` header for the high level API, or the `jbig2` program for a example of usage: ``` -$ jbig2 -s -p -v *.jpg && python3 jbig2topdf.py output >out.pdf +$ jbig2 -s -a -p -v *.jpg && python3 jbig2topdf.py output >out.pdf ``` or with standalone mode: ``` -$ jbig2 -p -v images/feyn.tif > feyn.jbig2 && python3 jbig2topdf.py -s feyn.jbig2 > feyn.pdf +$ jbig2 -a -p -v images/feyn.tif > feyn.jbig2 && python3 jbig2topdf.py -s feyn.jbig2 > feyn.pdf ``` to encode jbig2 files for pdf creation. diff --git a/src/jbig2.cc b/src/jbig2.cc index 573e3f1..08b0e9c 100644 --- a/src/jbig2.cc +++ b/src/jbig2.cc @@ -49,7 +49,7 @@ usage(const char *argv0) { fprintf(stderr, " -d --duplicate-line-removal: use TPGD in generic region coder\n"); fprintf(stderr, " -p --pdf: produce PDF ready data\n"); fprintf(stderr, " -s --symbol-mode: use text region, not generic coder\n"); - fprintf(stderr, " -t : set classification threshold for symbol coder (def: 0.85)\n"); + fprintf(stderr, " -t : set classification threshold for symbol coder (def: 0.92)\n"); fprintf(stderr, " -T : set 1 bpp threshold (def: 188)\n"); fprintf(stderr, " -r --refine: use refinement (requires -s: lossless)\n"); fprintf(stderr, " -O : dump thresholded image as PNG\n"); @@ -202,7 +202,7 @@ int main(int argc, char **argv) { bool duplicate_line_removal = false; bool pdfmode = false; - float threshold = 0.85; + float threshold = 0.92; int bw_threshold = 188; bool symbol_mode = false; bool refine = false; @@ -308,9 +308,9 @@ main(int argc, char **argv) { return 1; } - if (threshold > 0.9 || threshold < 0.4) { + if (threshold > 0.97 || threshold < 0.4) { fprintf(stderr, "Invalid value for threshold\n"); - fprintf(stderr, "(must be between 0.4 and 0.9)\n"); + fprintf(stderr, "(must be between 0.4 and 0.97)\n"); return 10; } i++; diff --git a/src/jbig2comparator.cc b/src/jbig2comparator.cc index 6b7eac9..a5e1359 100644 --- a/src/jbig2comparator.cc +++ b/src/jbig2comparator.cc @@ -200,7 +200,7 @@ jbig2enc_are_equivalent(PIX *const first_template, PIX *const second_template) { horizontal_sum += horizontal_parsed_pix_counts[i+x][j+y]; } } - if (horizontal_sum > hline_thresh) { + if (horizontal_sum >= hline_thresh) { return 0; } } @@ -215,7 +215,7 @@ jbig2enc_are_equivalent(PIX *const first_template, PIX *const second_template) { vertical_sum += vertical_parsed_pix_counts[i+x][j+y]; } } - if (vertical_sum > vline_thresh) { + if (vertical_sum >= vline_thresh) { return 0; } } @@ -236,7 +236,7 @@ jbig2enc_are_equivalent(PIX *const first_template, PIX *const second_template) { } } } - if ((left_cross > hline_thresh) || (right_cross > hline_thresh)) { + if ((left_cross >= hline_thresh) || (right_cross >= hline_thresh)) { return 0; } } @@ -253,7 +253,7 @@ jbig2enc_are_equivalent(PIX *const first_template, PIX *const second_template) { sum += parsed_pix_counts[i+x][j+y]; } } - if (sum > point_thresh) { + if (sum >= point_thresh) { return 0; } } From a837ef52a8f3ba58bc7f9c5aefc4f2406811b818 Mon Sep 17 00:00:00 2001 From: zdenop Date: Sun, 8 Dec 2024 19:09:58 +0100 Subject: [PATCH 4/4] move 'Building' section from from `Readme.md` to `Install` --- INSTALL | 70 +++++++++++++++++++++++++++++++++++++++++++------------ README.md | 53 ----------------------------------------- 2 files changed, 55 insertions(+), 68 deletions(-) diff --git a/INSTALL b/INSTALL index 4df3e05..f55459a 100644 --- a/INSTALL +++ b/INSTALL @@ -1,27 +1,67 @@ -First, read the file PATENTS in the same directory as this file. +# Building -Fetch leptonica from its website (http://leptonica.com/) and build it. -For this you will also need the standard libtiff, libpng and libjpeg. +## Prerequisites -If you're running a Unix-like OS, such as Linux, BSD, Mac OS X or msys - just run: +* installed [Leptonica](http://www.leptonica.org/) including development parts +* installed [cmake](https://cmake.org/) or [autotools] (https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html) +* installed C++ compiller (gcc, clang, MSVC) +* installed [git](https://git-scm.com/) + + +## Unix-like OS + +If you're running a Unix-like OS, such as Linux, BSD, Mac OS X or msys just run: + +``` ./autogen.sh ./configure make make install (or sudo make install) +``` + + +## CMake + +CMake requires CMake build installation of Leptonica + + +### Windows + + +*Note*: `cat`, `rm` and `dos2unix` tool are part of [git for windows](https://gitforwindows.org/). You can add them to your path with `set PATH=%PATH%;C:\Program Files\Git\usr\bin`. Adjust path `f:\win64` to your Leptonica installation. + +``` +"c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" x64 +set INSTALL_DIR=f:\win64 +set INCLUDE_DIR=f:\win64\include +set LIB_DIR=f:\win64\lib +set PATH=%PATH%;%INSTALL_DIR%\bin +``` + +### Configuration + +``` +git clone --depth 1 https://github.com/agl/jbig2enc +cmake -Bbuild -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DCMAKE_PREFIX_PATH=%INSTALL_DIR% +cmake --build build --config Release +``` + +### Install + +``` +cmake --build build --config Release --target install +``` +### Uninstall -VC++ 2008 Notes -=============== +``` +cat build/install_manifest.txt | dos2unix | xargs rm -Download leptonica-1.68-win32-lib-include-dirs.zip from -http://leptonica.com/download.html and unpack it so 'include', 'lib' and -'jbig2enc' directories are at the same directory (or adjust include path -in VC++ project). +``` -Download stdint.h for Microsoft Visual Studio (part of package -msinttypes-r26.zip from http://code.google.com/p/msinttypes/downloads/list) -and place it to 'include' directory. +### Clean -Them open vs2008/jbig2enc.sln in Visual C++ 2008 and build solution. \ No newline at end of file +``` +rm -r build/* +``` \ No newline at end of file diff --git a/README.md b/README.md index 4ad214f..0651f7e 100644 --- a/README.md +++ b/README.md @@ -46,56 +46,3 @@ If you want to encode an image as jbig2 (can be view in [STDU Viewer](http://www ``` $ jbig2 -s images/feyn.tif >feyn.jb2 ``` - - -# Building - -## Prerequisites - -* installed [leptonica](http://www.leptonica.org/) including development parts -* installed [cmake](https://cmake.org/) or [autotools] (https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html) -* installed C++ compiller (gcc, clang, MSVC) -* installed [git](https://git-scm.com/) - - -## Cmake - -### Windows - - -*Note*: `cat`, `rm` and `dos2unix` tool are part of [git for windows](https://gitforwindows.org/). You can add them to your path with `set PATH=%PATH%;C:\Program Files\Git\usr\bin`. Adjust path `f:\win64` to your leptonica installation. - -``` -"c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" x64 -set INSTALL_DIR=f:\win64 -set INCLUDE_DIR=f:\win64\include -set LIB_DIR=f:\win64\lib -set PATH=%PATH%;%INSTALL_DIR%\bin -``` - -### Configuration - -``` -git clone --depth 1 https://github.com/agl/jbig2enc -cmake -Bbuild -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -cmake --build build --config Release -``` - -### Install - -``` -cmake --build build --config Release --target install -``` - -### Uninstall - -``` -cat build/install_manifest.txt | dos2unix | xargs rm - -``` - -### Clean - -``` -rm -r build/* -```