Skip to content

Commit

Permalink
Merge pull request #101 from zdenop/various
Browse files Browse the repository at this point in the history
Various missing patches
  • Loading branch information
zdenop authored Dec 8, 2024
2 parents 7037b79 + a837ef5 commit 027a155
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 86 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.6)
cmake_minimum_required(VERSION 3.10)
project(jbig2enc CXX)
set(Version "0.29")

Expand Down
70 changes: 55 additions & 15 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -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.
```
rm -r build/*
```
57 changes: 2 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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/*
```
8 changes: 4 additions & 4 deletions src/jbig2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <threshold>: set classification threshold for symbol coder (def: 0.85)\n");
fprintf(stderr, " -t <threshold>: set classification threshold for symbol coder (def: 0.92)\n");
fprintf(stderr, " -T <bw threshold>: set 1 bpp threshold (def: 188)\n");
fprintf(stderr, " -r --refine: use refinement (requires -s: lossless)\n");
fprintf(stderr, " -O <outfile>: dump thresholded image as PNG\n");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
Expand Down
8 changes: 4 additions & 4 deletions src/jbig2comparator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/jbig2segments.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/jbig2structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 027a155

Please sign in to comment.