Coder Social home page Coder Social logo

jbig2enc's Introduction

This is an encoder for JBIG2.

JBIG2 encodes bi-level (1 bpp) images using a number of clever tricks to get better compression than G4. This encoder can:

  • Generate JBIG2 files, or fragments for embedding in PDFs
  • Generic region encoding
  • Perform symbol extraction, classification and text region coding
  • Perform refinement coding and,
  • Compress multipage documents

It uses the (Apache-ish licensed) Leptonica library: http://leptonica.com/

You'll need version 1.68.

Known bugs

The refinement coding causes Acrobat to crash. It's not known if this is a bug in Acrobat, though it may well be.

Usage

See the jbig2enc.h header for the high level API, or the jbig2 program for an example of usage:

$ jbig2 -s -p -v *.jpg && pdf.py output >out.pdf

to encode jbig2 files for pdf creation. If you want to encode an image and then view output first to include in pdf

$ jbig2 -s -S -p -v -O out.png *.jpg

If you want to encode an image as jbig2 (can be view in STDU Viewer) run:

$ jbig2 -s feyn.tif >feyn.jb2

jbig2enc's People

Contributors

agl avatar dark-saber avatar mistydemeo avatar quaqo avatar smuehlst avatar zdenop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jbig2enc's Issues

Document all parameters - How is the endoder used without -s?

Would be nice to have some enhancement of the readme file to provide examples about the compressor parameters.

Eg.:

  • Usage examples without -s, both to produce jb2 files and PDF;
  • Role of -t
  • help file for "refinement" says "requires -s: lossless". Does -s imply lossless compression?
  • What is "mixed input" mentioned in -j
  • How to use with a multipage tiff as an input?

Binary Files

Hey,

Great job with the implementation. I was wondering if it was possible to pass a raw bit stream to the compressor and if so how would you do that?

Thanks.

Input images for jbig2 encoder

Hi all,
Now I have successfully build the leptonica Library and the jbig2 encoder. When I executed jbig2 with the following command
./jbig2 -v -s <imagefile1 ...> > <jbig2_file>
Its giving the following error
syntax error near unexpected token `>'
When I removed all >, < and executed the same command again then its giving the following error
Unable to open "imagefile1".

Please note that imagefile1 is a bmp image i.e imagefile1.bmp in the same directory.

Which kind of images we can give as an input to this jbig2 encoder.?
Please reply me soon.

Cannot read Tiff directory error

I am trying to encode .tif files to .jbig2 in Windows using the jbig2.exe file downloaded from this link: "http://soft.rubypdf.com/downloads/agl-jbig2enc-0.27-14-gc709efe-leptonlib-1.66-win32-bin.zip"
and I get the following error.

jbig2 -s *.tif > out.jbig2
TIFFFetchDirectory: TIFFstream: Can not read TIFF directory
TIFFReadDirectory: TIFFstream: Failed to read directory at offset 0.
Error in findTiffCompression: tif not opened.

Can I know why I am getting this error, is there a solution to this problem and how to solve it?

Thanks.

Memory requirment of JBIG2 Encoder

Hi all,
I have successfully compiled Leptonica Library and the JBIG2 encoder. Now I want to execute JBIG2 encoder on embedded platform. I want to know about the memory requirement of JBIG2. Its not the memory forJBIG2.elf file.
Rather I want to know how much run time memory does it needs.

Does it need to store the whole image in memory for compressing it?
Or
Only some lines of the input image is stored in RAM at any time and then for the next line of the input image the RAM is updated.

Please comment on it.........

Tag new release?

It's been a long long time since the last release, and there are build issues (related to leptonica) and runtime issues (Homebrew/homebrew-core#25714) that have been fixed since 0.28 was released.

Could you please tag a new release? This would allow us (Homebrew) to distribute this new version, without patching :)

Many thanks in advance

Lossless

How do I force lossless compression?
Where is this documented?

fatal error LNK1104 for 'zlib125-static-mtdll-debug.lib'

I am receiving the following fatal error link when attempting to build the solution in VC++ 2008:

LINK : fatal error LNK1104: cannot open file 'zlib125-static-mtdll-debug.lib'

As a note, changing the runtime library to other versions had no impact on the error.

Win32 compile problem

Fixed compile problem on Win32 regarding packed attribute

Index: jbig2structs.h

--- jbig2structs.h (revision 5948)
+++ jbig2structs.h (working copy)
@@ -137,7 +137,7 @@

u32 exsyms;
u32 newsyms;
-} attribute((packed));
+} PACKED;

struct jbig2_text_region {
u32 width;
@@ -171,15 +171,19 @@
#endif

// huffman flags omitted
-} attribute((packed));
+} PACKED;

struct jbig2_text_region_atflags {
signed char a1x, a1y, a2x, a2y;
-} attribute((packed));
+} PACKED;

struct jbig2_text_region_syminsts {
u32 sbnuminstances;
// huffman decoding table omitted
-} attribute((packed));
+} PACKED;

+#if defined(WIN32)
+#pragma pack()
+#endif
+
#endif // JBIG2ENC_JBIG2STRUCTS_H__

jbig2 pdf pages out of order

I am converting a series of 57 TIFF G4 compressed images to jbig2 and pdf, the images are of the form image-000.tif, image-001.tif, etc. I am using the command "jbig2 -s -p image*.tif" and "python pdf.py output > image-jbig2.pdf". The resultant pdf has the pages all out of sequence, for example the first page is #28 in the series, the second page is #23, the third is #43, etc. Tested with the Windows and Linux binaries from rubypdf.

NULL Pointer Dereference in jbig2_add_page

Hi,
My fuzzer found a testcase that causes a NULL Pointer Dereference when using the "-s" parameter.

The file content (encoded in base64) that crashes the program is the following:
UDIjTAo2CTM2CTMK

The program output under Valgrind is the following:

Error in pixReadStreamPnm: read abend
Error in pixThresholdToBinary: pixs must be 4 or 8 bpp
Error in pixClone: pixs not defined
Error in jbAddPage: pixs not defined or not 1 bpp
==58840== Invalid read of size 4
==58840==    at 0x10EF52: jbig2_add_page(jbig2ctx*, Pix*) (jbig2enc.cc:505)
==58840==    by 0x10CC7D: main (jbig2.cc:472)
==58840==  Address 0x0 is not stack'd, malloc'd or (recently) free'd

Although the crash point is the same as #61 it seems a different issue.

The concatenation of the first 3 errors in libleptonica causes pixCLone to return NULL and so
the variable bw is null when jbAddPage is called (that, in fact, print an error).

Breakpoint 1, jbig2_add_page (ctx=0x555555936c20, input=<optimized out>) at jbig2enc.cc:504
504	in jbig2enc.cc
(gdb) p bw
$4 = (PIX *) 0x0

So the crash is at line 505 ( ctx->page_width.push_back(bw->w);) cause bw->w is a NULL dereference.

As you can see in the snippet the problem is that you trust the returned value of pixClone assuming that pixClone returns without errors. A possible fix is a check against NULL.

void
jbig2_add_page(struct jbig2ctx *ctx, struct Pix *input) {
  PIX *bw;

  if (false /*ctx->xres >= 300*/) {
    bw = remove_flyspecks(input, (int) (0.0084*ctx->xres));
  } else {
    bw = pixClone(input);
  }

  if (ctx->refinement) {
    ctx->baseindexes.push_back(ctx->classer->baseindex);
  }

  jbAddPage(ctx->classer, bw);
  ctx->page_width.push_back(bw->w);

Insecure RPATH

RPATH is automatically set by libtool to:
jbig2enc/src/.libs

On most builds, is such that any user can create RPATH, into which malicious libraries can be placed.

RPATH isn't necessary if the resulting library will be placed in the dynamic loader's (ld.so) system paths (the case with --prefix="/usr" or --prefix="/usr/local")

I suggest adding --disable-rpath configure option, so that user-prefix installations can still work (as well as other OSs) rather than simply disabling RPATH.

I also don't know how to do this.

Memory leak in jbig2enc.cc

Hi all,

at first, thank you for the nice encoder project. I hope this is the right place for my bugreport.

While working with the lib I detect a memory leak in jbig2enc.cc at line 324 / 325 (function unite_templates_with_indexes). This function removes equivalent pix values and in line 324 the refcount of the deleted image is added to the reference counter of the remaining one:

pixChangeRefcount(
ctx->classer->pixat->pix[firstTemplateIndex], pixGetRefcount(ctx->classer->pixat->pix[second_template_index]));

This is unnecessary because the references on the deleted image are not changed. So the reference counter of the remaining image is to high and the image is finally not deallocated.

Regards,
Sebastian

all my jb2 images are black

on linux 64 with leptonica 1.76.0

jbig2 -s x.tif > x.jb2
gives me a file with only 145 bytes

jbig2dec x.jb2
gives me x.pgm, which when viewed is all black.

No PDFs are viewable either.

Tag a new release?

It's been a few months since the last set of changes to jbig2enc, and there have been some pretty major changes since the last stable release. Any chance of a 0.28 being tagged, with a prebuilt configure script?

Updated jbig2.cpp for Leptonlib 1.63

New leptonlib changed api for findFileFormat()

===================================================================
--- jbig2.cpp   (revision 5943)
+++ jbig2.cpp   (working copy)
@@ -348,7 +348,8 @@
         fprintf(stderr, "Unable to open \"%s\"", argv[i]);
         return 1;
       }
-      int filetype = findFileFormat(fp);
+      l_int32 filetype;
+      findFileFormat(fp, &filetype);
       if (filetype==IFF_TIFF && tiffGetCount(fp, &numsubimages)) {
         return 1;
       }

Endianness problem with jbig2

Hi all,

I have successfully built Leptonica library in Ubuntu10.04. Then I have compiled jbig2 also and used it for compressing many .bmp images in Ubuntu 10.04.

Now I have cross compiled leptonica and jbig2 for avr32 NGW100 micro controller. But when I am executing the jbig2.elf on the avr32 NGW100, I am getting the following error

Error in pixReadStream: Unknown format: no pix returned
Error in pixRead: pix not read

Is this error related to the endianness problem of bmp images.

Update on patent situation

Looks like all the relevant patents have expired:

Japanese Patent 2128110, Jan. 1989 (expired)
Mitsubishi Electric Corp., Ono (F.) et al.: CODING METHOD OF IMAGE INFORMATION

Japanese Patent 2128115, Feb. 1990 (expired)
Mitsubishi Electric Corp., Ono (F.) et al.: CODING SYSTEM

US Patent 4286256, filed November 28, 1979 (expired)
IBM, Method and means for arithmetic coding using a reduced number of operations

US Patent 4295125, filed April 28, 1980 (expired)
IBM, A method and means for pipeline decoding of the high to low order pairwise combined digits of a decodable set of relatively shifted finite number of strings

US Patent 4410916, filed July 9, 1981 (expired)
Compression Labs Inc, Dual mode facsimile coding system and method

US Patent 4463342, filed June 14, 1979 (expired)
IBM, A method and means for carry-over control in a high order to low order combining of digits of a decodable set of relatively shifted finite number strings

US Patent 4463386, filed May 3, 1982 (expired)
IBM, Facsimile data reduction

US Patent 4467317, filed March 30, 1981 (expired)
IBM, High-speed arithmetic compression using concurrent value updating

US Patent 4633490, filed March 15, 1984 (expired)
IBM, Symmetrical adaptive data compression/decompression system

US Patent 4652856, filed February 4, 1986 (expired)
IBM, A multiplication-free multi-alphabet arithmetic code

US Patent 4749983, filed April 29, 1986 (expired)
IBM, Compression of multilevel signals

US Patent 4891643, filed September 15, 1986 (expired)
IBM, Arithmetic coding data compression/de compression by selectively employed, diverse arithmetic encoders and decoders

US Patent 4901363, filed September 28, 1988 (expired)
IBM, System for compressing bi-level data

US Patent 4905297, filed November 18, 1988 (expired)
IBM, Arithmetic coding encoder and decoder system

US Patent 4922545, filed February 10, 1989 (expired)
KDD, Facsimile image encoding method

US Patent 4935882, filed July 20, 1988 (expired)
IBM, Probability adaptation for arithmetic coders

US Patent 5099440, filed January 5, 1990 (expired)
IBM, Probability adaptation for arithmetic coders

US Patent 5884014, filed May 23, 1996 (expired)
Xerox, Fontless structured document image representations for efficient rendering

US Patent 6020972, filed November 14, 1997 (expired)
Xerox, System for performing collective symbol-based compression of a corpus of documents

The right way to get DPI

from jbig2_page_info struct we can get not only width and height, but also xres and yres, so we can directly use xres and yres to generated proper page size.

and here is the patch
http://soft.rubypdf.com/download/jbig2/pdf.diff

btw,
http://soft.rubypdf.com/download/jbig2/jbig2.zip is the win 32 static binary built with the last version source code, and also include the modified version pdf.py

P.S.
to any one who want to get windows version Jbig2:
please visit http://soft.rubypdf.com/software/windows-version-jbig2-encoder-jbig2-exe

Image loses BIG symbol

I use this library in one of my programs. A user of it showed me an image that loses a very big symbol when converting it to jbig2.

Logo

Logo2

I would like to send you the full image, but the user does not want it to be publicly available, so I would have to do it by email.But I don't have any contact data of you.

If you are interested in fixing this bug, just leave a comment here ;)

Lossless ?

Hello,

I tried jbig2enc on some files but the result ends with unwanted letter swaps (n/u, b/h, I can provide a test file if needed).

Is it possible to get lossless compression with jbig2enc ? Tried with -r but it tells me to bug agl.

Thanks,

Daniel

Feature request: set dpi for pdf.py via environment variable

I've been using jbig2enc for years to make PDFs of monochrome scans (thanks for that!). But every time I install it, I have to remember to edit pdf.py and set dpi = 300 to match the dpi setting of my scanner script.

It'd be a useful and trivial addition to have pdf.py look for an environment variable like JBIG2ENC_DPI and default to 72 if not found. That way, I could set it in my scanner script and forget about modifying pdf.py.

Problem with misstd when building jbig2 encoder

Hello all,
I want to use jbig2 encoder for compressing binary images. I am quite new to leptonica and visual studio. I have made the directory Buildfolder and then downloaded leptonica 1.68 and unpacked it to Builfolder. I have also unpacked the binaries for vs2008 (visual studio 2008) to the Buildfolder.
Then I downloaded all the rquired files for jbig2 encoder from
https://github.com/agl/jbig2enc

When I tried to build jbig2enc I got the following error
\documents and settings\khukhu\desktop\test\test\test\jbig2.cc(9): fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory.

I think the problem is with unistd.h . Please help me in this problem. And please also tell me the way how to successfully compress binary images using jbig2 encoder. I will be very thankfull.

Regards,
Khursheed

jbig2enc does not compile with Leptonica 1.68

I'm unable to get jbig2enc to compile under Mac OS X, using either 0.27 or the latest source from git. I get the following error message for jbig2.cc:

g++ -o jbig2 jbig2.cc -L. -ljbig2enc brew --prefix/lib/liblept.a -Ibrew --prefix/include/leptonica/ -Wall -Ibrew --prefix/include -Lbrew --prefix/lib -O3 -lpng -ljpeg -ltiff -lm
jbig2.cc: In function ‘int main(int, char*)’:
jbig2.cc:349: error: cannot convert ‘FILE
’ to ‘const char_’ for argument ‘1’ to ‘l_int32 findFileFormat(const char_, l_int32_)’
make: *_* [jbig2] Error 1

a patch to improve pdf creation

Hi,

I propose a patch which changes jbig2 behavior at two aspects. First, the files generated in the "-p" mode now retain their original names, and just the extension is changed (I use ".jbig2", but whatever else would be OK). A numerical suffix is added in case of name clashes (or for images which go from multipage tiff files). For this reason the 'basename' parameter is gone. The reason for this change is that source images may have some accompanying files (such as background images previously separated with a scan processing application). In such case file names contain some useful information which should not be lost during the processing/conversion.

The second change allows to generate more than just one symbol dictionary, so that the loading speed for large PDF files can be increased. There is now a new option (-P, --pages-per-dict), which specifies how many pages should be processed at the same pass. The default value for this parameter is 15.

I also propose a modified version of pdf.py, implementing support for background images, which can be combined with the foreground mask in the same pdf file. Several graphical formats (PNG, TIFF, JPEG) are supported. It is possible either to use graphics stripped by jbig2 at the previous stage, or prepage images separately in a different application, given that the file names follow the same convention.

BTW it might be reasonable to rename pdf.py to something more meaningful, so that the script could be safely installed somewhere into the PATH.

The files can be downloaded here:
http://www.thessalonica.org.ru/downloads/jbig2.patch.gz
http://www.thessalonica.org.ru/downloads/pdf.py.gz

Problem in building jbig2 encoder in Linux

Hi all,
I want to compress binary images using jbig2 encoder. Leptonica is a library which which supports jbig2enc. I have tried leptonica library both in windows and Linux but I am unable to use jbig2enc because I am quite new to both visual studio (for windows based) and also Linux programming. I am not using Linux regularly.
I have successfully built leptonica library in Linux But now I have problem in using leptonica library for compressing images using jbig2enc. Please help me in this problem.

I am facing the problem in the lines below from the web page http://leptonica.org/source/README.html

To build the encoder, use the most recent version. This bundles
Leptonica 1.63. Once you've built the encoder, use it to compress
a set of input image files: (e.g.)

It says that once built the encoder use it to compress images.
My problem is that how can I build the encoder in Linux (jbig2enc).

Patch to properly set dpi for generated pages

Hi,

jbig2 currently doesn't preserve the original resolution of the processed images and always sets both xres and xres to zero. There is already is issue for this problem (#8), but it is closed without an apparent reason. Nevertheless the problem is serious, because dpi is necessary to properly calculate PDF media box. So I propose a patch which fixes the problem for multipage compression.

See http://www.thessalonica.org.ru/downloads/pagedpi.patch .

Error on the execution of JBIG2 on embedded platform

Hi,
hope everyone is fine. I have now successfully imported all the libraries required by JBIG2 to my embedded platform(NGW100 mkII). Now I am very close to successfully executing JBIG2 on my NGW100 mkII.

When I executed the following command
./jbig2 -v -s Image.bmp >Frame1

The I got the following errors

Error in pixReadStream: Unknown format: no pix returned
Error in pixRead: pix not read

I do not know, what is the cause of this error. Please comment on this error.

build fails on maeia2 (x86-64)

$ make
g++ -c jbig2enc.cc -I../leptonica-1.68/src -Wall -I/usr/include -L/usr/lib -O3
g++ -c jbig2arith.cc -I../leptonica-1.68/src -Wall -I/usr/include -L/usr/lib -O3
g++ -c jbig2sym.cc -DUSE_EXT -I../leptonica-1.68/src -Wall -I/usr/include -L/usr/lib -O3
ar -rcv libjbig2enc.a jbig2enc.o jbig2arith.o jbig2sym.o
a - jbig2enc.o
a - jbig2arith.o
a - jbig2sym.o
g++ -o jbig2 jbig2.cc -L. -ljbig2enc ../leptonica-1.68/src/.libs/liblept.a -I../leptonica-1.68/src -Wall -I/usr/include -L/usr/lib -O3 -lpng -ljpeg -ltiff -lm -lz
/usr/bin/ld: skipping incompatible /usr/lib/libz.so when searching for -lz
/usr/bin/ld: skipping incompatible /usr/lib/libz.a when searching for -lz
/usr/bin/ld: skipping incompatible /usr/lib/libm.so when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/libgcc_s.so when searching for -lgcc_s
../leptonica-1.68/src/.libs/liblept.a(gifio.o): In function pixReadStreamGif': /mnt/daten2/download/leptonica-1.68/src/gifio.c:92: undefined reference toDGifOpenFileHandle'
/mnt/daten2/download/leptonica-1.68/src/gifio.c:97: undefined reference to DGifSlurp' /mnt/daten2/download/leptonica-1.68/src/gifio.c:189: undefined reference toDGifCloseFile'
/mnt/daten2/download/leptonica-1.68/src/gifio.c:98: undefined reference to DGifCloseFile' /mnt/daten2/download/leptonica-1.68/src/gifio.c:111: undefined reference toDGifCloseFile'
/mnt/daten2/download/leptonica-1.68/src/gifio.c:130: undefined reference to DGifCloseFile' /mnt/daten2/download/leptonica-1.68/src/gifio.c:154: undefined reference toDGifCloseFile'
../leptonica-1.68/src/.libs/liblept.a(gifio.o):/mnt/daten2/download/leptonica-1.68/src/gifio.c:103: more undefined references to DGifCloseFile' follow ../leptonica-1.68/src/.libs/liblept.a(gifio.o): In functionpixWriteStreamGif':
/mnt/daten2/download/leptonica-1.68/src/gifio.c:308: undefined reference to MakeMapObject' /mnt/daten2/download/leptonica-1.68/src/gifio.c:329: undefined reference toEGifOpenFileHandle'
/mnt/daten2/download/leptonica-1.68/src/gifio.c:336: undefined reference to EGifPutScreenDesc' /mnt/daten2/download/leptonica-1.68/src/gifio.c:339: undefined reference toFreeMapObject'
/mnt/daten2/download/leptonica-1.68/src/gifio.c:340: undefined reference to EGifCloseFile' /mnt/daten2/download/leptonica-1.68/src/gifio.c:317: undefined reference toFreeMapObject'
/mnt/daten2/download/leptonica-1.68/src/gifio.c:343: undefined reference to FreeMapObject' /mnt/daten2/download/leptonica-1.68/src/gifio.c:345: undefined reference toEGifPutImageDesc'
/mnt/daten2/download/leptonica-1.68/src/gifio.c:347: undefined reference to EGifCloseFile' /mnt/daten2/download/leptonica-1.68/src/gifio.c:387: undefined reference toEGifPutLine'
/mnt/daten2/download/leptonica-1.68/src/gifio.c:400: undefined reference to EGifPutComment' /mnt/daten2/download/leptonica-1.68/src/gifio.c:406: undefined reference toEGifCloseFile'
/mnt/daten2/download/leptonica-1.68/src/gifio.c:331: undefined reference to FreeMapObject' /mnt/daten2/download/leptonica-1.68/src/gifio.c:390: undefined reference toEGifCloseFile'
/mnt/daten2/download/leptonica-1.68/src/gifio.c:355: undefined reference to EGifCloseFile' /mnt/daten2/download/leptonica-1.68/src/gifio.c:361: undefined reference toEGifCloseFile'
collect2: ld returned 1 exit status
make: *** [jbig2] Error 1

pdf.py can not create correct pdf under windows

python version 2.5
because of the bug of python under windows, file(p).read() can not read all content of output.0000, so the pdf created is not correct, I modify file(p,'rb').read(), but the pdf created is still not correct, is some bigger than it create under linux, I have send you the two pdf files as attachment.

Problem Building jbig2enc with CentOS 6.0

Make is failing after successfully install leptonica 1.68 under CentOS 6.0. I'm getting undefined references below...

[root@xaudits agl-jbig2enc-e8be922]# make
g++ -c jbig2enc.cc -I../leptonica-1.68/src -Wall -I/usr/include -L/usr/lib -O3
g++ -c jbig2arith.cc -I../leptonica-1.68/src -Wall -I/usr/include -L/usr/lib -O3
g++ -c jbig2sym.cc -DUSE_EXT -I../leptonica-1.68/src -Wall -I/usr/include -L/usr/lib -O3
ar -rcv libjbig2enc.a jbig2enc.o jbig2arith.o jbig2sym.o
a - jbig2enc.o
a - jbig2arith.o
a - jbig2sym.o
g++ -o jbig2 jbig2.cc -L. -ljbig2enc ../leptonica-1.68/src/.libs/liblept.a -I../leptonica-1.68/src -Wall -I/usr/include -L/usr/lib -O3 -lpng -ljpeg -ltiff -lm -lz
../leptonica-1.68/src/.libs/liblept.a(gifio.o): In function pixWriteStreamGif': /root/leptonica-1.68/src/gifio.c:308: undefined reference toMakeMapObject'
/root/leptonica-1.68/src/gifio.c:329: undefined reference to EGifOpenFileHandle' /root/leptonica-1.68/src/gifio.c:336: undefined reference toEGifPutScreenDesc'
/root/leptonica-1.68/src/gifio.c:339: undefined reference to FreeMapObject' /root/leptonica-1.68/src/gifio.c:340: undefined reference toEGifCloseFile'
/root/leptonica-1.68/src/gifio.c:317: undefined reference to FreeMapObject' /root/leptonica-1.68/src/gifio.c:343: undefined reference toFreeMapObject'
/root/leptonica-1.68/src/gifio.c:345: undefined reference to EGifPutImageDesc' /root/leptonica-1.68/src/gifio.c:347: undefined reference toEGifCloseFile'
/root/leptonica-1.68/src/gifio.c:387: undefined reference to EGifPutLine' /root/leptonica-1.68/src/gifio.c:400: undefined reference toEGifPutComment'
/root/leptonica-1.68/src/gifio.c:406: undefined reference to EGifCloseFile' /root/leptonica-1.68/src/gifio.c:331: undefined reference toFreeMapObject'
/root/leptonica-1.68/src/gifio.c:390: undefined reference to EGifCloseFile' /root/leptonica-1.68/src/gifio.c:355: undefined reference toEGifCloseFile'
/root/leptonica-1.68/src/gifio.c:361: undefined reference to EGifCloseFile' ../leptonica-1.68/src/.libs/liblept.a(gifio.o): In functionpixReadStreamGif':
/root/leptonica-1.68/src/gifio.c:92: undefined reference to DGifOpenFileHandle' /root/leptonica-1.68/src/gifio.c:97: undefined reference toDGifSlurp'
/root/leptonica-1.68/src/gifio.c:189: undefined reference to DGifCloseFile' /root/leptonica-1.68/src/gifio.c:98: undefined reference toDGifCloseFile'
/root/leptonica-1.68/src/gifio.c:111: undefined reference to DGifCloseFile' /root/leptonica-1.68/src/gifio.c:130: undefined reference toDGifCloseFile'
/root/leptonica-1.68/src/gifio.c:154: undefined reference to DGifCloseFile' ../leptonica-1.68/src/.libs/liblept.a(gifio.o):/root/leptonica-1.68/src/gifio.c:103: more undefined references toDGifCloseFile' follow
collect2: ld returned 1 exit status
make: *** [jbig2] Error 1
[root@xaudits agl-jbig2enc-e8be922]#

Processing TIFFs with a single image?

I believe there's an issue when processing TIFF images with only one image --- in jbig2.cc, tiffGetCount will return at least 1 for a valid TIFF (so numsubimages=1), but argc is only incremented when subimage==numsubimages, leading to an infinite loop.

Setting numsubimages to 0 in numsubimages<=1 condition closes the loop:

--- a/src/jbig2.cc
+++ b/src/jbig2.cc
@@ -392,6 +392,7 @@ main(int argc, char **argv) {
     PIX *source;
     if (numsubimages<=1) {
       source = pixRead(argv[i]);
+      numsubimages = 0; // done with this image, so increment to the next argc
     } else {
       source = pixReadTiff(argv[i], subimage++);
     }

jbig2 ignores image resolution

I am converting a 300 dpi series of TIFF images to jbig2 and pdf using jbig2 -s -p image*.tif and python pdf.py output > image-jbig2.pdf. The resultant pdf is at 72 dpi. I can't tell how to make jbig2enc read the image resolution from the tif file or how to feed it to jbig2 manually. Testing with the windows and linux binaries from rubypdf.

Compile error under Solaris 10

When compile jbig2enc under Solaris 10, I got the following error:

In file included from /usr/include/netinet/in.h:66,
from jbig2segments.h:19,
from jbig2enc.cc:39:
/usr/include/sys/stream.h:307: error: declaration of uint32_t datab::<anonymous union>::<anonymous struct>::<anonymous union>::uint32_t' /usr/include/sys/int_types.h:74: error: changes meaning ofuint32_t' from typedef unsigned int uint32_t' /usr/include/sys/stream.h:308: error: declaration ofuint16_t datab::::::::uint16_t'
/usr/include/sys/int_types.h:73: error: changes meaning of uint16_t' fromtypedef short unsigned int uint16_t'

Anyway to fix this?

zlib on mingw is misdetected

hi,
I got an error on ./configure using MSYS2 mingw64 shell:
user@HOST MINGW64 /d/AMBIENTE/Documents/c/jbig2enc
$ ./configure
...
checking how to hardcode library paths into programs... immediate
checking for _head_libws2_32_a in -lws2_32... no
Error! zlib not detected.

where zlib is installed, complete of all headers and dll:

user@HOST MSYS /d/AMBIENTE/Documents/c/jbig2enc
$ pacman -Sl | grep zlib
mingw32 mingw-w64-i686-zlib 1.2.11-5 [installato]
mingw64 mingw-w64-x86_64-zlib 1.2.11-5 [installato]
msys mingw-w64-cross-zlib 1.2.11-1 [installato]
msys zlib 1.2.11-1 [installato]
msys zlib-devel 1.2.11-1 [installato]

user@HOST MSYS /d/AMBIENTE/Documents/c/jbig2enc
$ pacman -Ql mingw-w64-x86_64-zlib
mingw-w64-x86_64-zlib /mingw64/
mingw-w64-x86_64-zlib /mingw64/bin/
mingw-w64-x86_64-zlib /mingw64/bin/libminizip-1.dll
mingw-w64-x86_64-zlib /mingw64/bin/zlib1.dll
mingw-w64-x86_64-zlib /mingw64/include/
mingw-w64-x86_64-zlib /mingw64/include/minizip/
mingw-w64-x86_64-zlib /mingw64/include/minizip/aes/
mingw-w64-x86_64-zlib /mingw64/include/minizip/aes/aes.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/aes/aes_ni.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/aes/aesopt.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/aes/aestab.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/aes/brg_endian.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/aes/brg_types.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/aes/fileenc.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/aes/hmac.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/aes/prng.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/aes/pwd2key.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/aes/sha1.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/crypt.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/ioapi.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/ioapi_buf.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/ioapi_mem.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/iowin32.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/unzip.h
mingw-w64-x86_64-zlib /mingw64/include/minizip/zip.h
mingw-w64-x86_64-zlib /mingw64/include/zconf.h
mingw-w64-x86_64-zlib /mingw64/include/zlib.h
mingw-w64-x86_64-zlib /mingw64/lib/
mingw-w64-x86_64-zlib /mingw64/lib/cmake/
mingw-w64-x86_64-zlib /mingw64/lib/cmake/minizip-exports-release.cmake
mingw-w64-x86_64-zlib /mingw64/lib/cmake/minizip-exports.cmake
mingw-w64-x86_64-zlib /mingw64/lib/libminizip.a
mingw-w64-x86_64-zlib /mingw64/lib/libminizip.dll.a
mingw-w64-x86_64-zlib /mingw64/lib/libz.a
mingw-w64-x86_64-zlib /mingw64/lib/libz.dll.a
mingw-w64-x86_64-zlib /mingw64/lib/pkgconfig/
mingw-w64-x86_64-zlib /mingw64/lib/pkgconfig/minizip.pc
mingw-w64-x86_64-zlib /mingw64/lib/pkgconfig/zlib.pc
mingw-w64-x86_64-zlib /mingw64/share/
mingw-w64-x86_64-zlib /mingw64/share/licenses/
mingw-w64-x86_64-zlib /mingw64/share/licenses/zlib/
mingw-w64-x86_64-zlib /mingw64/share/licenses/zlib/LICENSE
mingw-w64-x86_64-zlib /mingw64/share/man/
mingw-w64-x86_64-zlib /mingw64/share/man/man3/
mingw-w64-x86_64-zlib /mingw64/share/man/man3/zlib.3.gz

As 'zlib' is present in the system and 'libws2' is not needed,
a simple dirty hack like changing lines 47/48 of 'configure.ac' to:
echo "Error! zlib not detected.")
#exit -1)
let build the binary and it work.

Wrong bit field order on ARM

I've just spent a few hours figuring out why jbig2enc compiled for Android/arm produces output that cannot be decoded...

In jbig2structs.h there's a comment saying:

// GCC packs bit fields in a different order on big endian machines

The problem is Android has its own definition of _BIG_ENDIAN coming from here:

/tmp/my-android-toolchain/bin/../sysroot/usr/include/sys/endian.h:33:9: note: previous definition is here
#define _BIG_ENDIAN     4321

Which makes your code assume it's being compiled for a big endian platform.

Changing endianness of Leptonica Library

Hi,
Can I change the endianness of Leptonica Library in some way.
I hace crossed compiles Leptonica library and jbig2 encoder for AVR32 microcontroller (Linux based and it is big endian).

How can change the endianness of Leptonica Library, so that jbig2 encoder can be used on my target architecture.
I found a file name endianness.h in the src directory of Leptonica Library.

Please give me any clue or suggestion. Any help will be highly appreciated. Thank you in advance.

Character substitution in cyrillic texts witih Serif fonts?!

Hello, I find this bug very strange. I thought that the program treated the files as images and does not operate on characters. But it does. I use Ubuntu 11.04, jbig2enc was complied from source downloaded in the autumn of 2011. I use the following command for conversion:

jbig2 -b J -d -p -s *.jpg; pdf.py J > JBIG2.pdf

I haven't noticed any problems with texts in English, but when I do conversion of images, containing texts in cyrillic, it gives problems with Serif fonts, especially with Times New Roman. A picture is worth a thousand words, that is why I provide a link to a file containing 1) the original pdf file 2) the jpg file used as a source 3) the final pdf file, produced with jbig2enc. I include three such sets - for documents with Times New Roman, Liberation Serif, and Arial.

There are no problems for documents with Arial fonts. Liberation Serif leads to some character substitutions (see and compare word 1 on row 6 in the original and jbig2 encoded file). With Times New Roman character substitution is almost on every row (for an example see word 3 on row 1).

The files are here:
http://www.2shared.com/file/F-iXXDdC/jbig_files.html

Failed to build on Slackware/gcc/g++ 4.8.2

I attempted to build and package it for Slackware (Porteus, indeed), but it failed using gcc/g++ version 4.8.2; though I locally and successfully build the following dependencies:

openjpeg 2.1.2
libwebp 0.6.0
libtiff 3.9.7
libpng 1.4.12
libjpeg v8a
leptonica 1.74.4

jbig2.cc: In function ‘PIX* segment_image(PIX*, PIX*)’:
jbig2.cc:137:71: error: ‘expandBinaryPower2Low’ was not declared in this scope
                         pixd4->data, pixd4->w, pixd4->h, pixd4->wpl, 4);
                                                                       ^

I'm not a programmer, hence I followed INSTALL/README for all the above, but the jbig2enc lacks this kind of requisite and important information :-(

jbig2.exe -p can not output correct jbig2 data

I have fixed the issue, for details, please visit,
http://blog.rubypdf.com/2009/11/03/jbig2-exe-fix-a-bug-and-release-new-update/

add full_write method, and replease write with full_write

//set stdout to binary mode
void full_write(int fd, uint8_t *buf, size_t count)
{
#if defined(WIN32)
_setmode(fd, WINBINARY);
#endif
write(fd, buf, count);
}

btw, I found the way to let Python send binary data to stdout under Windows,
http://blog.rubypdf.com/2009/11/03/how-to-let-python-send-binary-data-to-stdout-under-windows/

Wrong Output Jbig2 image

Hi,

I have built leptonica successfully, and use it to encode a Pbm file and save it as jbig2 file format.
this worked with me successfully with a lot of files, but with this pbm
https://onedrive.live.com/redir?resid=BF8D672F16E7537C!54872&authkey=!AGOomuu4Y2rH_Ik&ithint=file%2cpbm
the result is wrong, there are errors in the text, here is the resulting jb2 image.
https://onedrive.live.com/redir?resid=BF8D672F16E7537C!54871&authkey=!ABN7KWMhSOgSM9U&ithint=file%2cjb2
I encoded with -s -v commands. any help here will be appreciated.
Thanks all.

Image loses BIG symbol

I use this library in one of my programs. A user of it showed me an image that loses a very big symbol when converting it to jbig2.

Logo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.