libraries/jbig2enc: Added (encoder for JBIG2).

Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
This commit is contained in:
B. Watson 2016-11-06 07:27:15 +07:00 committed by Willy Sudiarto Raharjo
parent 1b9059091e
commit 29ca02bcf1
9 changed files with 686 additions and 0 deletions

11
libraries/jbig2enc/README Normal file
View file

@ -0,0 +1,11 @@
jbig2enc (encoder for JBIG2)
JBIG2 encodes bi-level (1 bpp) images using a number of clever tricks
to get better compression than G4.
The package includes shared libraries, headers, docs, the jbig2(1)
command-line conversion tool, and pdf.py(1) which post-processes JBIG2
files to create PDFs.
Use of this software may require patent licenses in some countries.
You are directed to annex I of the JBIG2 specification for information.

197
libraries/jbig2enc/jbig2.1 Normal file
View file

@ -0,0 +1,197 @@
.\" Man page generated from reStructuredText.
.
.TH JBIG2 1 "2016-11-05" "0.28" "SlackBuilds.org"
.SH NAME
jbig2 \- convert image files to JBIG2 format
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.\" RST source for jbig2(1) man page. Convert with:
.
.\" rst2man.py jbig2.rst > jbig2.1
.
.\" rst2man.py comes from the SBo development/docutils package.
.
.SH SYNOPSIS
.sp
\fBjbig2\fP [\fI\-options\fP] \fIimagefile\fP > \fIoutput.jb2\fP
.SH DESCRIPTION
.sp
JBIG2 is an image compression standard from the same people who brought
you the JPEG format. It compresses 1bpp (black and white) images only.
.sp
jbig2enc is a library that encodes JBIG2 images.
.sp
\fBjbig2\fP is a command\-line tool that uses the jbig2enc library to convert an
image to the JBIG2 format. \fIimagefile\fP can be in any format readable by
leptonica (png, jpeg, tiff, gif, webp, jp2, bmp, pnm, spix). The image
is converted to 1bbp (monochrome) before processing.
.sp
Without the \fI\-p\fP, \fI\-\-pdf\fP option, the converted image is written to
standard output. This should be redirected to a file, normally with
the \fI\&.jb2\fP extension. If stdout isn\(aqt redirected to a file (or a pipe),
the JBIG2 data will be written to the terminal, which may get confused.
.sp
There is no way to have \fBjbig2\fP read an image file on standard input. This
is by design, as it needs to seek within the file.
.sp
All options must appear before the filename. With the generic encoder
(no \fI\-s\fP option), anything after the filename is silently ignored. The
symbol encoder (\fI\-s\fP) can handle multiple images (which end up as pages
in the JBIG2 file).
.sp
The \fI\-r\fP, \fI\-\-refine\fP option mentioned in the documentation and in
the \fI\-\-help\fP output of \fBjbig2\fP is \fIdisabled\fP in this version of
\fBjbig2\fP\&.
.SH OPTIONS
.\" some of these are from the HTML file, some from --help.
.
.INDENT 0.0
.TP
.B \-b \fIbasename\fP
Output file root name when using symbol coding in PDF mode (\fI\-s\fP
and \fI\-p\fP). Default is \fBoutput\fP\&.
.UNINDENT
.INDENT 0.0
.TP
.B \-d\fP,\fB \-\-duplicate\-line\-removal
When encoding generic regions each scan line can be tagged to indicate
that it\(aqs the same as the last scanline \- and encoding that scanline
is skipped. This drastically reduces the encoding time (by a factor
of about 2 on some images) although it doesn\(aqt typically save any
bytes. This is an option because some versions of jbig2dec (an open
source decoding library) cannot handle this.
.TP
.B \-p\fP,\fB \-\-pdf
The PDF spec includes support for JBIG2 (Syntax\->Filters\->JBIG2Decode in
the PDF references for versions 1.4 and above). However, PDF requires
a slightly different format for JBIG2 streams: no file/page headers or
trailers and all pages are numbered 1. In symbol mode the output is to
a series of files: symboltable and page\-n (numbered from 0). By default
these are named \fBoutput.sym\fP and \fBoutput.0000\fP, \fBoutput.0001\fP,
etc. Use \fI\-b\fP to change the base filename.
.TP
.B \-s\fP,\fB \-\-symbol\-mode
Use symbol encoding. Turn on for scanned text pages.
.UNINDENT
.INDENT 0.0
.TP
.B \-t \fIthreshold\fP
Sets the fraction of pixels which have to match in order for
two symbols to be classed the same. This isn\(aqt strictly true, as there are
other tests as well, but increasing this will generally increase the number
of symbol classes. Default is 0.85.
.TP
.B \-T \fIthreshold\fP
Sets the black threshold (0\-255). Any gray value darker than
this is considered black. Anything lighter is considered white.
Default is 188.
.TP
.B \-O \fIoutfile\fP
Dump a PNG of the 1 bpp image before encoding. Can be used to
test loss.
.UNINDENT
.INDENT 0.0
.TP
.B \-2\fP,\fB \-4
Upscale either two or four times before converting to black and
white.
.TP
.B \-S
Segment an image into text and non\-text regions. This isn\(aqt perfect, but
running text through the symbol compressor is terrible so it\(aqs worth doing
if your input has images in it (like a magazine page).
.TP
.B \-\-image\-output
Set filename to which the parts which were removed by \-S are written.
Default is PNG format.
.TP
.B \-j\fP,\fB \-\-jpeg\-output
Write images from \-S as JPEG instead of PNG.
.TP
.B \-a\fP,\fB \-\-auto\-thresh
Use automatic thresholding in symbol encoder.
.TP
.B \-\-no\-hash
Disables use of hash function for automatic thresholding.
.TP
.B \-v
Be verbose.
.TP
.B \-V\fP,\fB \-\-version
Display version number and exit.
.TP
.B \-h\fP,\fB \-\-help
Display help and exit.
.UNINDENT
.SH EXIT STATUS
.sp
\fBjbig2\fP exits with 0 (success) status if the conversion completed
OK, and non\-zero status if anything went wrong. If standard output was
redirected to a file, the file will be empty or invalid when non\-zero
status is returned. Diagnostic messages are printed to standard error.
.SH COPYRIGHT
.sp
See the file /usr/doc/jbig2enc\-0.28/COPYING for license information.
.sp
This software is a description of processes which may be patented.
.sp
Use of this software may require patent licenses in some countries.
You are directed to annex I of the JBIG2 specification for information.
.INDENT 0.0
.TP
.B Some information could be found at:
\fI\%http://www.jpeg.org/jbig/index.html\fP
\fI\%http://www.cl.cam.ac.uk/~mgk25/jbigkit/patents/\fP
\fI\%http://www.jpeg.org/public/fcd14492.pdf\fP
\fI\%http://itscj.ipsj.or.jp/sc29/open/29view/29n55161.doc\fP
.UNINDENT
.SH AUTHORS
.INDENT 0.0
.TP
.B jbig2 and jbig2enc were written by:
Adam Langley <\fI\%agl@imperialviolet.org\fP>.
.UNINDENT
.sp
This man page written for the SlackBuilds.org project
by B. Watson, and is licensed under the WTFPL.
.SH SEE ALSO
.sp
\fBpdf.py(1)\fP, \fBjbig2dec(1)\fP
.INDENT 0.0
.TP
.B Full documentation for jbig2 and jbig2enc:
/usr/doc/jbig2enc\-0.28/jbig2enc.html
.TP
.B The JBIG2 specification was formerly located at:
\fI\%http://www.jpeg.org/public/fcd14492.pdf\fP
.TP
.B A copy can be found here:
\fI\%http://www.hlevkin.com/Standards/fcd14492.pdf\fP
.UNINDENT
.\" Generated by docutils manpage writer.
.

View file

@ -0,0 +1,176 @@
.. RST source for jbig2(1) man page. Convert with:
.. rst2man.py jbig2.rst > jbig2.1
.. rst2man.py comes from the SBo development/docutils package.
.. |version| replace:: 0.28
.. |date| date::
=====
jbig2
=====
-----------------------------------
convert image files to JBIG2 format
-----------------------------------
:Manual section: 1
:Manual group: SlackBuilds.org
:Date: |date|
:Version: |version|
SYNOPSIS
========
**jbig2** [*-options*] *imagefile* > *output.jb2*
DESCRIPTION
===========
JBIG2 is an image compression standard from the same people who brought
you the JPEG format. It compresses 1bpp (black and white) images only.
jbig2enc is a library that encodes JBIG2 images.
**jbig2** is a command-line tool that uses the jbig2enc library to convert an
image to the JBIG2 format. *imagefile* can be in any format readable by
leptonica (png, jpeg, tiff, gif, webp, jp2, bmp, pnm, spix). The image
is converted to 1bbp (monochrome) before processing.
Without the *-p*, *--pdf* option, the converted image is written to
standard output. This should be redirected to a file, normally with
the *.jb2* extension. If stdout isn't redirected to a file (or a pipe),
the JBIG2 data will be written to the terminal, which may get confused.
There is no way to have **jbig2** read an image file on standard input. This
is by design, as it needs to seek within the file.
All options must appear before the filename. With the generic encoder
(no *-s* option), anything after the filename is silently ignored. The
symbol encoder (*-s*) can handle multiple images (which end up as pages
in the JBIG2 file).
The *-r*, *--refine* option mentioned in the documentation and in
the *--help* output of **jbig2** is *disabled* in this version of
**jbig2**.
OPTIONS
=======
.. some of these are from the HTML file, some from --help.
-b *basename*
Output file root name when using symbol coding in PDF mode (*-s*
and *-p*). Default is **output**.
-d, --duplicate-line-removal
When encoding generic regions each scan line can be tagged to indicate
that it's the same as the last scanline - and encoding that scanline
is skipped. This drastically reduces the encoding time (by a factor
of about 2 on some images) although it doesn't typically save any
bytes. This is an option because some versions of jbig2dec (an open
source decoding library) cannot handle this.
-p, --pdf
The PDF spec includes support for JBIG2 (Syntax->Filters->JBIG2Decode in
the PDF references for versions 1.4 and above). However, PDF requires
a slightly different format for JBIG2 streams: no file/page headers or
trailers and all pages are numbered 1. In symbol mode the output is to
a series of files: symboltable and page-n (numbered from 0). By default
these are named **output.sym** and **output.0000**, **output.0001**,
etc. Use *-b* to change the base filename.
-s, --symbol-mode
Use symbol encoding. Turn on for scanned text pages.
-t *threshold*
Sets the fraction of pixels which have to match in order for
two symbols to be classed the same. This isn't strictly true, as there are
other tests as well, but increasing this will generally increase the number
of symbol classes. Default is 0.85.
-T *threshold*
Sets the black threshold (0-255). Any gray value darker than
this is considered black. Anything lighter is considered white.
Default is 188.
-O *outfile*
Dump a PNG of the 1 bpp image before encoding. Can be used to
test loss.
-2, -4
Upscale either two or four times before converting to black and
white.
-S
Segment an image into text and non-text regions. This isn't perfect, but
running text through the symbol compressor is terrible so it's worth doing
if your input has images in it (like a magazine page).
--image-output
Set filename to which the parts which were removed by -S are written.
Default is PNG format.
-j, --jpeg-output
Write images from -S as JPEG instead of PNG.
-a, --auto-thresh
Use automatic thresholding in symbol encoder.
--no-hash
Disables use of hash function for automatic thresholding.
-v
Be verbose.
-V, --version
Display version number and exit.
-h, --help
Display help and exit.
EXIT STATUS
===========
**jbig2** exits with 0 (success) status if the conversion completed
OK, and non-zero status if anything went wrong. If standard output was
redirected to a file, the file will be empty or invalid when non-zero
status is returned. Diagnostic messages are printed to standard error.
COPYRIGHT
=========
See the file /usr/doc/jbig2enc-|version|/COPYING for license information.
This software is a description of processes which may be patented.
Use of this software may require patent licenses in some countries.
You are directed to annex I of the JBIG2 specification for information.
Some information could be found at:
http://www.jpeg.org/jbig/index.html
http://www.cl.cam.ac.uk/~mgk25/jbigkit/patents/
http://www.jpeg.org/public/fcd14492.pdf
http://itscj.ipsj.or.jp/sc29/open/29view/29n55161.doc
AUTHORS
=======
jbig2 and jbig2enc were written by:
Adam Langley <agl@imperialviolet.org>.
This man page written for the SlackBuilds.org project
by B. Watson, and is licensed under the WTFPL.
SEE ALSO
========
**pdf.py(1)**, **jbig2dec(1)**
Full documentation for jbig2 and jbig2enc:
/usr/doc/jbig2enc-|version|/jbig2enc.html
The JBIG2 specification was formerly located at:
http://www.jpeg.org/public/fcd14492.pdf
A copy can be found here:
http://www.hlevkin.com/Standards/fcd14492.pdf

View file

@ -0,0 +1,98 @@
#!/bin/sh
# Slackware build script for jbig2enc
# Written by B. Watson (yalhcru@gmail.com)
# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.
PRGNAM=jbig2enc
VERSION=${VERSION:-0.28}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
if [ -z "$ARCH" ]; then
case "$( uname -m )" in
i?86) ARCH=i586 ;;
arm*) ARCH=arm ;;
*) ARCH=$( uname -m ) ;;
esac
fi
CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}
if [ "$ARCH" = "i586" ]; then
SLKCFLAGS="-O2 -march=i586 -mtune=i686"
LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
SLKCFLAGS="-O2 -march=i686 -mtune=i686"
LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
SLKCFLAGS="-O2 -fPIC"
LIBDIRSUFFIX="64"
else
SLKCFLAGS="-O2"
LIBDIRSUFFIX=""
fi
set -e
TARNAM=$PRGNAM-$VERSION-dist
rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $TARNAM
tar xvf $CWD/$TARNAM.tar.gz
cd $TARNAM
chown -R root:root .
find -L . \
\( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
-o -perm 511 \) -exec chmod 755 {} \; -o \
\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
-o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
# taken from upstream git, fix compile with leptonica >= 1.70 (we
# have 1.73). commit here:
# https://github.com/agl/jbig2enc/commit/53ce5fe7e73d7ed95c9e12b52dd4984723f865fa
patch -p1 < $CWD/leptonica_api_fix.diff
# have to do this, configure.ac was patched above.
autoreconf -if
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure \
--disable-static \
--enable-shared \
--prefix=/usr \
--libdir=/usr/lib${LIBDIRSUFFIX} \
--sysconfdir=/etc \
--localstatedir=/var \
--mandir=/usr/man \
--docdir=/usr/doc/$PRGNAM-$VERSION \
--build=$ARCH-slackware-linux
make
make install-strip DESTDIR=$PKG
# man pages written for this SlackBuild, submitted upstream for
# consideration.
MANPAGES="jbig2 pdf.py"
mkdir -p $PKG/usr/man/man1
for i in $MANPAGES; do
gzip -9c < $CWD/$i.1 > $PKG/usr/man/man1/$i.1.gz
done
# docs already installed.
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}

View file

@ -0,0 +1,10 @@
PRGNAM="jbig2enc"
VERSION="0.28"
HOMEPAGE="https://github.com/agl/jbig2enc"
DOWNLOAD="https://github.com/agl/jbig2enc/archive/0.28-dist/jbig2enc-0.28-dist.tar.gz"
MD5SUM="34a22be7dedc77d22c8e3f43224e38a7"
DOWNLOAD_x86_64=""
MD5SUM_x86_64=""
REQUIRES="leptonica"
MAINTAINER="B. Watson"
EMAIL="yalhcru@gmail.com"

View file

@ -0,0 +1,37 @@
diff --git a/configure.ac b/configure.ac
index fe37c22..753a607 100644
--- a/configure.ac
+++ b/configure.ac
@@ -55,6 +55,7 @@ AC_CHECK_LIB([lept], [findFileFormatStream], [], [
echo "Error! Leptonica not detected."
exit -1
])
+AC_CHECK_FUNCS(expandBinaryPower2Low,,)
# test for function - it should detect leptonica dependecies
# Check for possible dependancies of leptonica.
diff --git a/src/jbig2.cc b/src/jbig2.cc
index e10f042..515c1ef 100644
--- a/src/jbig2.cc
+++ b/src/jbig2.cc
@@ -130,11 +130,16 @@ segment_image(PIX *pixb, PIX *piximg) {
// input color image, so we have to do it this way...
// is there a better way?
// PIX *pixd = pixExpandBinary(pixd4, 4);
- PIX *pixd = pixCreate(piximg->w, piximg->h, 1);
- pixCopyResolution(pixd, piximg);
- if (verbose) pixInfo(pixd, "mask image: ");
- expandBinaryPower2Low(pixd->data, pixd->w, pixd->h, pixd->wpl,
+ PIX *pixd;
+#ifdef HAVE_EXPANDBINARYPOWER2LOW
+ pixd = pixCreate(piximg->w, piximg->h, 1);
+ pixCopyResolution(pixd, piximg);
+ expandBinaryPower2Low(pixd->data, pixd->w, pixd->h, pixd->wpl,
pixd4->data, pixd4->w, pixd4->h, pixd4->wpl, 4);
+#else
+ pixd = pixExpandBinaryPower2(pixd4, 4);
+#endif
+ if (verbose) pixInfo(pixd, "mask image: ");
pixDestroy(&pixd4);
pixDestroy(&pixsf4);

View file

@ -0,0 +1,77 @@
.\" Man page generated from reStructuredText.
.
.TH PDF.PY "" "" ""
.SH NAME
pdf.py \- create PDF files from JBIG2 images
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.\" RST source for pdf.py(1) man page. Convert with:
.
.\" rst2man.py pdf.py.rst > pdf.py.1
.
.\" rst2man.py comes from the SBo development/docutils package.
.
.SH SYNOPSIS
.sp
jbig2 \-b newdoc \-s \-p image1.jpg image2.jpg ...
.sp
pdf.py newdoc > newdoc.pdf
.SH DESCRIPTION
.sp
\fBpdf.py\fP creates a PDF document from \fBjbig2\fP\(aqs PDF\-ready output
(created using \fI\-s\fP and \fI\-p\fP, \fI\-\-pdf\fP).
.sp
\fBpdf.py\fP takes only one argument: the base name of the files created
by \fBjbig2\fP, which is set with \fBjbig2\fP\(aqs \fI\-b\fP option. Without \fI\-b\fP,
the default name is \fBoutput\fP\&.
.sp
The PDF is written to standard output, which normally should be redirected
to a file (see the example above).
.SH EXIT STATUS
.sp
\fBpdf.py\fP exits with 0 (success) status if the conversion completed
OK, and non\-zero status if anything went wrong. If standard output was
redirected to a file, the file will be empty or invalid when non\-zero
status is returned. Diagnostic messages are printed to standard error.
.SH COPYRIGHT
.sp
See the file /usr/doc/jbig2enc\-0.28/COPYING for license information.
.SH AUTHORS
.INDENT 0.0
.TP
.B pdf.py and jbig2enc were written by:
Adam Langley <\fI\%agl@imperialviolet.org\fP>.
.UNINDENT
.sp
This man page written for the SlackBuilds.org project
by B. Watson, and is licensed under the WTFPL.
.SH SEE ALSO
.sp
\fBjbig2(1)\fP, \fBjbig2dec(1)\fP
.\" Generated by docutils manpage writer.
.

View file

@ -0,0 +1,61 @@
.. RST source for pdf.py(1) man page. Convert with:
.. rst2man.py pdf.py.rst > pdf.py.1
.. rst2man.py comes from the SBo development/docutils package.
.. |version| replace:: 0.28
.. |date| date::
======
pdf.py
======
----------------------------------
create PDF files from JBIG2 images
----------------------------------
SYNOPSIS
========
jbig2 -b newdoc -s -p image1.jpg image2.jpg ...
pdf.py newdoc > newdoc.pdf
DESCRIPTION
===========
**pdf.py** creates a PDF document from **jbig2**'s PDF-ready output
(created using *-s* and *-p*, *--pdf*).
**pdf.py** takes only one argument: the base name of the files created
by **jbig2**, which is set with **jbig2**'s *-b* option. Without *-b*,
the default name is **output**.
The PDF is written to standard output, which normally should be redirected
to a file (see the example above).
EXIT STATUS
===========
**pdf.py** exits with 0 (success) status if the conversion completed
OK, and non-zero status if anything went wrong. If standard output was
redirected to a file, the file will be empty or invalid when non-zero
status is returned. Diagnostic messages are printed to standard error.
COPYRIGHT
=========
See the file /usr/doc/jbig2enc-|version|/COPYING for license information.
AUTHORS
=======
pdf.py and jbig2enc were written by:
Adam Langley <agl@imperialviolet.org>.
This man page written for the SlackBuilds.org project
by B. Watson, and is licensed under the WTFPL.
SEE ALSO
========
**jbig2(1)**, **jbig2dec(1)**

View file

@ -0,0 +1,19 @@
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description.
# Line up the first '|' above the ':' following the base package name, and
# the '|' on the right side marks the last column you can put a character in.
# You must make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':' except on otherwise blank lines.
|-----handy-ruler------------------------------------------------------|
jbig2enc: jbig2enc (encoder for JBIG2)
jbig2enc:
jbig2enc: JBIG2 encodes bi-level (1 bpp) images using a number of clever tricks
jbig2enc: to get better compression than G4.
jbig2enc:
jbig2enc: The package includes shared libraries, headers, docs, and the jbig2(1)
jbig2enc: command-line conversion tool.
jbig2enc:
jbig2enc:
jbig2enc:
jbig2enc: