agl / jbig2enc

JBIG2 Encoder
Other
251 stars 86 forks source link

Making jbig2enc treat black as white and vice verse #80

Open yobesispa opened 1 year ago

yobesispa commented 1 year ago

Hello.

I am trying to compress a batch of about 450 purely black-and-white images, all of which are pages of a book. The colour depth of all images is 1 -- each pixel is either completely black, or it is completely white. (bpp=1)

The peculiarity of my use-case is that the images are white text on a black background rather than the "normal" black-text-on-white-background. This is because they have to be used as "image masks" in a much larger file on which I don't have much control.

I have compressed this 25MB white-text-on-black-background image group using jbig2 -t 0.9 -s -p -S <all-images> , resulting in 11MB compressed image data.

Out of curiosity, I then "inverted" the colours in all images so that they become ordinary black-text-on-white-background images, and compressed the resulting image group using the same command. This time, the whole compressed image data amounted to only 2MB!

To me, this means that if my use case allowed me to invert my white-text-on-black-background images before compressing them with jbig2enc, I could have obtained a much better compression ratio: 2MB compared to 11MB, in my particular case.

Now that I am not allowed to invert my image, is there any way for me to tell jbig2enc treat black as white and vice versa?

Many thanks!