Updates
This commit is contained in:
60
blender-deps/jbigkit-cmake/libjbig/Makefile
Normal file
60
blender-deps/jbigkit-cmake/libjbig/Makefile
Normal file
@@ -0,0 +1,60 @@
|
||||
# Unix makefile for the JBIG-KIT library
|
||||
|
||||
# Select an ANSI/ISO C compiler here, GNU gcc is recommended
|
||||
CC = gcc
|
||||
|
||||
# Options for the compiler: A high optimization level is suggested
|
||||
CFLAGS = -g -O -W -Wall -ansi -pedantic # --coverage
|
||||
|
||||
all: libjbig.a libjbig85.a tstcodec tstcodec85 tstjoint
|
||||
|
||||
tstcodec: tstcodec.o jbig.o jbig_ar.o
|
||||
$(CC) $(LDFLAGS) $(CFLAGS) -o tstcodec tstcodec.o jbig.o jbig_ar.o
|
||||
|
||||
tstcodec85: tstcodec85.o jbig85.o jbig_ar.o
|
||||
$(CC) $(LDFLAGS) $(CFLAGS) -o tstcodec85 tstcodec85.o jbig85.o jbig_ar.o
|
||||
|
||||
tstjoint: tstjoint.o jbig.o jbig85.o jbig_ar.o
|
||||
$(CC) $(LDFLAGS) $(CFLAGS) -o tstjoint \
|
||||
tstjoint.o jbig.o jbig85.o jbig_ar.o
|
||||
|
||||
libjbig.a: jbig.o jbig_ar.o
|
||||
rm -f libjbig.a
|
||||
ar rc libjbig.a jbig.o jbig_ar.o
|
||||
-ranlib libjbig.a
|
||||
|
||||
libjbig85.a: jbig85.o jbig_ar.o
|
||||
rm -f libjbig85.a
|
||||
ar rc libjbig85.a jbig85.o jbig_ar.o
|
||||
-ranlib libjbig85.a
|
||||
|
||||
jbig.o: jbig.c jbig.h jbig_ar.h
|
||||
jbig85.o: jbig85.c jbig85.h jbig_ar.h
|
||||
jbig_ar.o: jbig_ar.c jbig_ar.h
|
||||
tstcodec.o: tstcodec.c jbig.h
|
||||
tstcodec85.o: tstcodec85.c jbig85.h
|
||||
|
||||
update-po: jbig.c jbig85.c Makefile
|
||||
xgettext -ojbig.pot -k_ \
|
||||
--copyright-holder='Markus Kuhn' \
|
||||
--msgid-bugs-address='http://www.cl.cam.ac.uk/~mgk25/jbigkit/' \
|
||||
--package-name jbigkit \
|
||||
jbig.c jbig85.c
|
||||
cd po && for po in *.po ; do \
|
||||
msgmerge --update $$po ../jbig.pot ; done
|
||||
|
||||
analyze:
|
||||
clang --analyze *.c
|
||||
|
||||
test: tstcodec tstcodec85 tstjoint
|
||||
./tstcodec
|
||||
./tstcodec85
|
||||
./tstjoint
|
||||
|
||||
t82test.pbm: tstcodec
|
||||
./tstcodec $@
|
||||
|
||||
clean:
|
||||
rm -f *.o *.gcda *.gcno *.gcov *.plist *~ core gmon.out dbg_d\=??.pbm
|
||||
rm -f t82test.pbm
|
||||
rm -f tstcodec tstcodec85 tstjoint
|
||||
3292
blender-deps/jbigkit-cmake/libjbig/jbig.c
Normal file
3292
blender-deps/jbigkit-cmake/libjbig/jbig.c
Normal file
File diff suppressed because it is too large
Load Diff
235
blender-deps/jbigkit-cmake/libjbig/jbig.h
Normal file
235
blender-deps/jbigkit-cmake/libjbig/jbig.h
Normal file
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* Header file for the portable JBIG compression library
|
||||
*
|
||||
* Copyright 1995-2014 -- Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/
|
||||
*/
|
||||
|
||||
#ifndef JBG_H
|
||||
#define JBG_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "jbig_ar.h"
|
||||
|
||||
/*
|
||||
* JBIG-KIT version number
|
||||
*/
|
||||
|
||||
#define JBG_VERSION "2.1"
|
||||
#define JBG_VERSION_MAJOR 2
|
||||
#define JBG_VERSION_MINOR 1
|
||||
|
||||
/*
|
||||
* JBIG-KIT licence agreement reference code:
|
||||
* If you use JBIG-KIT under a commercial licence, please replace
|
||||
* below the letters GPL with the reference code that you received
|
||||
* with your licence agreement. (This code is typically a letter "A"
|
||||
* followed by four decimal digits, e.g. "A1234".)
|
||||
*/
|
||||
|
||||
#define JBG_LICENCE "GPL"
|
||||
|
||||
/*
|
||||
* Buffer block for SDEs which are temporarily stored by encoder
|
||||
*/
|
||||
|
||||
#define JBG_BUFSIZE 4000
|
||||
|
||||
struct jbg_buf {
|
||||
unsigned char d[JBG_BUFSIZE]; /* one block of a buffer list */
|
||||
int len; /* length of the data in this block */
|
||||
struct jbg_buf *next; /* pointer to next block */
|
||||
struct jbg_buf *previous; /* pointer to previous block *
|
||||
* (unused in freelist) */
|
||||
struct jbg_buf *last; /* only used in list head: final block of list */
|
||||
struct jbg_buf **free_list; /* pointer to pointer to head of free list */
|
||||
};
|
||||
|
||||
/*
|
||||
* Maximum number of ATMOVEs per stripe that decoder can handle
|
||||
*/
|
||||
|
||||
#define JBG_ATMOVES_MAX 64
|
||||
|
||||
/*
|
||||
* Option and order flags
|
||||
*/
|
||||
|
||||
#define JBG_HITOLO 0x08
|
||||
#define JBG_SEQ 0x04
|
||||
#define JBG_ILEAVE 0x02
|
||||
#define JBG_SMID 0x01
|
||||
|
||||
#define JBG_LRLTWO 0x40
|
||||
#define JBG_VLENGTH 0x20
|
||||
#define JBG_TPDON 0x10
|
||||
#define JBG_TPBON 0x08
|
||||
#define JBG_DPON 0x04
|
||||
#define JBG_DPPRIV 0x02
|
||||
#define JBG_DPLAST 0x01
|
||||
|
||||
/* encoding options that will not be indicated in the header */
|
||||
|
||||
#define JBG_DELAY_AT 0x100 /* Delay ATMOVE until the first line of the next
|
||||
* stripe. Option available for compatibility
|
||||
* with conformance test example in clause 7.2. */
|
||||
|
||||
#define JBG_SDRST 0x200 /* Use SDRST instead of SDNORM. This option is
|
||||
* there for anyone who needs to generate
|
||||
* test data that covers the SDRST cases. */
|
||||
|
||||
/*
|
||||
* Possible error code return values
|
||||
*/
|
||||
|
||||
#define JBG_EOK (0 << 4)
|
||||
#define JBG_EOK_INTR (1 << 4)
|
||||
#define JBG_EAGAIN (2 << 4)
|
||||
#define JBG_ENOMEM (3 << 4)
|
||||
#define JBG_EABORT (4 << 4)
|
||||
#define JBG_EMARKER (5 << 4)
|
||||
#define JBG_EINVAL (6 << 4)
|
||||
#define JBG_EIMPL (7 << 4)
|
||||
#define JBG_ENOCONT (8 << 4)
|
||||
|
||||
/*
|
||||
* Status of a JBIG encoder
|
||||
*/
|
||||
|
||||
struct jbg_enc_state {
|
||||
int d; /* resolution layer of the input image */
|
||||
unsigned long xd, yd; /* size of the input image (resolution layer d) */
|
||||
unsigned long yd1; /* BIH announced height of image, use yd1 != yd to
|
||||
emulate T.85-style NEWLEN height updates for tests */
|
||||
int planes; /* number of different bitmap planes */
|
||||
int dl; /* lowest resolution layer in the next BIE */
|
||||
int dh; /* highest resolution layer in the next BIE */
|
||||
unsigned long l0; /* number of lines per stripe at lowest *
|
||||
* resolution layer 0 */
|
||||
unsigned long stripes; /* number of stripes required (determ. by l0) */
|
||||
unsigned char **lhp[2]; /* pointers to lower/higher resolution images */
|
||||
int *highres; /* index [plane] of highres image in lhp[] */
|
||||
int order; /* SDE ordering parameters */
|
||||
int options; /* encoding parameters */
|
||||
unsigned mx, my; /* maximum ATMOVE window size */
|
||||
int *tx; /* array [plane] with x-offset of adaptive template pixel */
|
||||
char *dppriv; /* optional private deterministic prediction table */
|
||||
char *res_tab; /* table for the resolution reduction algorithm */
|
||||
struct jbg_buf ****sde; /* array [stripe][layer][plane] pointers to *
|
||||
* buffers for stored SDEs */
|
||||
struct jbg_arenc_state *s; /* array [planes] for arithm. encoder status */
|
||||
struct jbg_buf *free_list; /* list of currently unused SDE block buffers */
|
||||
void (*data_out)(unsigned char *start, size_t len, void *file);
|
||||
/* data write callback */
|
||||
void *file; /* parameter passed to data_out() */
|
||||
char *tp; /* buffer for temp. values used by diff. typical prediction */
|
||||
unsigned char *comment; /* content of comment marker segment to be added
|
||||
at next opportunity (will be reset to NULL
|
||||
as soon as comment has been written) */
|
||||
unsigned long comment_len; /* length of data pointed to by comment */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Status of a JBIG decoder
|
||||
*/
|
||||
|
||||
struct jbg_dec_state {
|
||||
/* data from BIH */
|
||||
int d; /* resolution layer of the full image */
|
||||
int dl; /* first resolution layer in this BIE */
|
||||
unsigned long xd, yd; /* size of the full image (resolution layer d) */
|
||||
int planes; /* number of different bitmap planes */
|
||||
unsigned long l0; /* number of lines per stripe at lowest *
|
||||
* resolution layer 0 */
|
||||
unsigned long stripes; /* number of stripes required (determ. by l0) */
|
||||
int order; /* SDE ordering parameters */
|
||||
int options; /* encoding parameters */
|
||||
int mx, my; /* maximum ATMOVE window size */
|
||||
char *dppriv; /* optional private deterministic prediction table */
|
||||
|
||||
/* loop variables */
|
||||
unsigned long ii[3]; /* current stripe, layer, plane (outer loop first) */
|
||||
|
||||
/*
|
||||
* Pointers to array [planes] of lower/higher resolution images.
|
||||
* lhp[d & 1] contains image of layer d.
|
||||
*/
|
||||
unsigned char **lhp[2];
|
||||
|
||||
/* status information */
|
||||
int **tx, **ty; /* array [plane][layer-dl] with x,y-offset of AT pixel */
|
||||
struct jbg_ardec_state **s; /* array [plane][layer-dl] for arithmetic *
|
||||
* decoder status */
|
||||
int **reset; /* array [plane][layer-dl] remembers if previous stripe *
|
||||
* in that plane/resolution ended with SDRST. */
|
||||
unsigned long bie_len; /* number of bytes read so far */
|
||||
unsigned char buffer[20]; /* used to store BIH or marker segments fragm. */
|
||||
int buf_len; /* number of bytes in buffer */
|
||||
unsigned long comment_skip; /* remaining bytes of a COMMENT segment */
|
||||
unsigned long x; /* x position of next pixel in current SDE */
|
||||
unsigned long i; /* line in current SDE (first line of each stripe is 0) */
|
||||
int at_moves; /* number of AT moves in the current stripe */
|
||||
unsigned long at_line[JBG_ATMOVES_MAX]; /* lines at which an *
|
||||
* AT move will happen */
|
||||
int at_tx[JBG_ATMOVES_MAX], at_ty[JBG_ATMOVES_MAX]; /* ATMOVE offsets in *
|
||||
* current stripe */
|
||||
unsigned long line_h1, line_h2, line_h3; /* variables of decode_pscd */
|
||||
unsigned long line_l1, line_l2, line_l3;
|
||||
int pseudo; /* flag for TPBON/TPDON: next pixel is pseudo pixel */
|
||||
int **lntp; /* flag [plane][layer-dl] for TP: line is not typical */
|
||||
|
||||
unsigned long xmax, ymax; /* if possible abort before image gets *
|
||||
* larger than this size */
|
||||
int dmax; /* abort after this layer */
|
||||
size_t maxmem; /* return JBG_ENOMEM if final image layer D
|
||||
would require more than maxmem bytes */
|
||||
};
|
||||
|
||||
|
||||
/* some macros (too trivial for a function) */
|
||||
|
||||
#define jbg_dec_getplanes(s) ((s)->planes)
|
||||
|
||||
|
||||
/* function prototypes */
|
||||
|
||||
void jbg_enc_init(struct jbg_enc_state *s, unsigned long x, unsigned long y,
|
||||
int planes, unsigned char **p,
|
||||
void (*data_out)(unsigned char *start, size_t len,
|
||||
void *file),
|
||||
void *file);
|
||||
int jbg_enc_lrlmax(struct jbg_enc_state *s, unsigned long mwidth,
|
||||
unsigned long mheight);
|
||||
void jbg_enc_layers(struct jbg_enc_state *s, int d);
|
||||
int jbg_enc_lrange(struct jbg_enc_state *s, int dl, int dh);
|
||||
void jbg_enc_options(struct jbg_enc_state *s, int order, int options,
|
||||
unsigned long l0, int mx, int my);
|
||||
void jbg_enc_out(struct jbg_enc_state *s);
|
||||
void jbg_enc_free(struct jbg_enc_state *s);
|
||||
|
||||
void jbg_dec_init(struct jbg_dec_state *s);
|
||||
void jbg_dec_maxsize(struct jbg_dec_state *s, unsigned long xmax,
|
||||
unsigned long ymax);
|
||||
int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len,
|
||||
size_t *cnt);
|
||||
unsigned long jbg_dec_getwidth(const struct jbg_dec_state *s);
|
||||
unsigned long jbg_dec_getheight(const struct jbg_dec_state *s);
|
||||
unsigned char *jbg_dec_getimage(const struct jbg_dec_state *s, int plane);
|
||||
unsigned long jbg_dec_getsize(const struct jbg_dec_state *s);
|
||||
void jbg_dec_merge_planes(const struct jbg_dec_state *s, int use_graycode,
|
||||
void (*data_out)(unsigned char *start, size_t len,
|
||||
void *file), void *file);
|
||||
unsigned long jbg_dec_getsize_merged(const struct jbg_dec_state *s);
|
||||
void jbg_dec_free(struct jbg_dec_state *s);
|
||||
|
||||
const char *jbg_strerror(int errnum);
|
||||
void jbg_int2dppriv(unsigned char *dptable, const char *internal);
|
||||
void jbg_dppriv2int(char *internal, const unsigned char *dptable);
|
||||
unsigned long jbg_ceil_half(unsigned long x, int n);
|
||||
void jbg_split_planes(unsigned long x, unsigned long y, int has_planes,
|
||||
int encode_planes,
|
||||
const unsigned char *src, unsigned char **dest,
|
||||
int use_graycode);
|
||||
int jbg_newlen(unsigned char *bie, size_t len);
|
||||
|
||||
#endif /* JBG_H */
|
||||
828
blender-deps/jbigkit-cmake/libjbig/jbig.txt
Normal file
828
blender-deps/jbigkit-cmake/libjbig/jbig.txt
Normal file
@@ -0,0 +1,828 @@
|
||||
|
||||
Using the JBIG-KIT library
|
||||
--------------------------
|
||||
|
||||
Markus Kuhn -- 2020-08-03
|
||||
|
||||
|
||||
This text explains how to use the functions provided by the JBIG-KIT
|
||||
portable image compression library jbig.c in your application
|
||||
software. The jbig.c library is a full-featured implementation of the
|
||||
JBIG1 standard aimed at applications that can hold the entire
|
||||
uncompressed and compressed image in RAM.
|
||||
|
||||
[For applications that require only the single-bit-per-pixel "fax
|
||||
subset" of the JBIG1 standard defined in ITU-T Recommendation T.85
|
||||
<http://www.itu.int/rec/T-REC-T.85/en>, the alternative implementation
|
||||
found in jbig85.c may be preferable. It keeps not more than three
|
||||
lines of the uncompressed image in RAM, which makes it particularly
|
||||
suitable for embedded applications. For information on how to use
|
||||
jbig85.c, please refer to the separate documentation file jbig85.txt.]
|
||||
|
||||
|
||||
1 Introduction to JBIG
|
||||
|
||||
We start with a short introduction to JBIG1. More detailed information
|
||||
is provided in the "Introduction and overview" section of the JBIG1
|
||||
standard. Information on how to obtain a copy of the standard is
|
||||
available from <http://www.itu.int/rec/T-REC-T.82/en> or
|
||||
<http://www.iso.ch/>.
|
||||
|
||||
Image data encoded with the JBIG algorithm is separated into planes,
|
||||
layers, and stripes. Each plane contains one bit per pixel. The number
|
||||
of planes stored in a JBIG data stream is the number of bits per
|
||||
pixel. Resolution layers are numbered from 0 to D with 0 being the
|
||||
layer with the lowest resolution and D the one with the highest. Each
|
||||
next higher resolution layer has twice the number of rows and columns.
|
||||
Layer 0 is encoded independently of any other data, all other
|
||||
resolution layers are encoded as only the difference between the next
|
||||
lower and the current layer. For applications that require very quick
|
||||
access to parts of an image, it is possible to divide an image into
|
||||
several horizontal stripes. All stripes of one resolution layer have
|
||||
equal size, except perhaps the final one. The number of stripes of an
|
||||
image is equal in all resolution layers and in all bit planes.
|
||||
|
||||
The compressed data stream specified by the JBIG standard is called a
|
||||
bi-level image entity (BIE). A BIE consists of a 20-byte header,
|
||||
followed by an optional 1728-byte table (usually not present, except
|
||||
in special applications) followed by a sequence of stripe data
|
||||
entities (SDE). Each SDE encodes the content of one single stripe in
|
||||
one plane of one resolution layer. Between the SDEs, other information
|
||||
blocks (called floating marker segments) can also be present. They are
|
||||
used to change certain parameters of the algorithm in the middle of an
|
||||
image or contain additional application specific information. A BIE
|
||||
looks like this:
|
||||
|
||||
|
||||
+------------------------------------------------+
|
||||
| |
|
||||
| 20-byte header (with image size, #planes, |
|
||||
| #layers, stripe size, first layer, options, |
|
||||
| SDE ordering, ...) |
|
||||
| |
|
||||
+------------------------------------------------+
|
||||
| |
|
||||
| optional 1728-byte table |
|
||||
| |
|
||||
+------------------------------------------------+
|
||||
| |
|
||||
| optional floating marker segments |
|
||||
| |
|
||||
+------------------------------------------------+
|
||||
| |
|
||||
| stripe data entity |
|
||||
| |
|
||||
+------------------------------------------------+
|
||||
| |
|
||||
| optional floating marker segments |
|
||||
| |
|
||||
+------------------------------------------------+
|
||||
| |
|
||||
| stripe data entity |
|
||||
| |
|
||||
+------------------------------------------------+
|
||||
...
|
||||
+------------------------------------------------+
|
||||
| |
|
||||
| stripe data entity |
|
||||
| |
|
||||
+------------------------------------------------+
|
||||
|
||||
|
||||
One BIE can contain all resolution layers of an image, but it is also
|
||||
possible to store various resolution layers in several BIEs. The BIE
|
||||
header contains the number of the first and the last resolution layer
|
||||
stored in this BIE, as well as the size of the highest resolution
|
||||
layer stored in this BIE. Progressive coding is deactivated by simply
|
||||
storing the image in one single resolution layer.
|
||||
|
||||
Different applications might have different requirements for the order
|
||||
in which the SDEs for stripes of various planes and layers are stored
|
||||
in the BIE, so all possible sensible orderings are allowed by the
|
||||
standard and indicated by four bits in the header.
|
||||
|
||||
It is possible to use the raw BIE data stream as specified by the JBIG
|
||||
standard directly as the format of a file used for storing images.
|
||||
This is what the pbmtojbg, jbgtopbm, pbmtojbg85, and jbgtopbm85
|
||||
conversion tools do that are provided in this package as demonstration
|
||||
applications. However, as the BIE format has been designed for a large
|
||||
number of very different applications, and to allow efficient direct
|
||||
processing by special JBIG hardware chip implementations, the BIE
|
||||
header contains only the minimum amount of information absolutely
|
||||
required by the decompression algorithm. Many features expected from a
|
||||
good file format are missing in the BIE data stream:
|
||||
|
||||
- no "magic code" in the first few bytes to allow identification
|
||||
of the file format on a typeless file system and to allow
|
||||
automatic distinction from other compression algorithms
|
||||
|
||||
- no standardized way to encode additional information such as a
|
||||
textual description, information about the meaning of various bit
|
||||
planes, the physical size and resolution of the document, etc.
|
||||
|
||||
- a checksum to ensure image integrity
|
||||
|
||||
- encryption and signature mechanisms
|
||||
|
||||
- many things more
|
||||
|
||||
Raw BIE data streams alone may therefore not be a suitable format for
|
||||
document archiving and exchange. A standard format for this purpose
|
||||
would typically combine a BIE representing the image data with an
|
||||
additional header providing auxiliary information into one file.
|
||||
Existing established multi-purpose file formats with a rich set of
|
||||
auxiliary information attributes like TIFF could be extended easily to
|
||||
also hold JBIG compressed data.
|
||||
|
||||
On the other hand, in e.g. database applications, a BIE might be
|
||||
stored directly in a binary variable-length field. Auxiliary
|
||||
information would then be stored in other fields of the same record,
|
||||
to simplify search operations.
|
||||
|
||||
|
||||
2 Compressing an image
|
||||
|
||||
2.1 Format of the source image
|
||||
|
||||
To be processed by the jbig.c encoder, the image has to be present in
|
||||
memory as separate bitmap planes. Each byte of a bitmap contains eight
|
||||
pixels, where the most significant bit represents the leftmost of
|
||||
these. Each line of a bitmap has to be stored in an integral number of
|
||||
bytes. If the image width is not an integral multiple of eight, then
|
||||
the final byte has to be padded with zero bits.
|
||||
|
||||
For example the 23x5 pixels large single plane image:
|
||||
|
||||
.XXXXX..XXX...X...XXX..
|
||||
.....X..X..X..X..X.....
|
||||
.....X..XXX...X..X.XXX.
|
||||
.X...X..X..X..X..X...X.
|
||||
..XXX...XXX...X...XXX..
|
||||
|
||||
is represented by the 15 bytes
|
||||
|
||||
01111100 11100010 00111000
|
||||
00000100 10010010 01000000
|
||||
00000100 11100010 01011100
|
||||
01000100 10010010 01000100
|
||||
00111000 11100010 00111000
|
||||
|
||||
or in hexadecimal notation
|
||||
|
||||
7c e2 38 04 92 40 04 e2 5c 44 92 44 38 e2 38
|
||||
|
||||
This is the format used in binary PBM files and it can also be handled
|
||||
directly by the Xlib library of the X Window System.
|
||||
|
||||
As JBIG can also handle images with multiple bit planes, the jbig.c
|
||||
library functions accept and return always arrays of pointers to
|
||||
bitmaps with one pointer per plane.
|
||||
|
||||
For single-plane images, the standard recommends that a 0 pixel
|
||||
represents the background and a 1 pixel represents the foreground
|
||||
colour of an image, in other words, 0 is white and 1 is black for
|
||||
scanned paper documents. For images with several bits per pixel, the
|
||||
JBIG standard makes no recommendations about how various colours should
|
||||
be encoded.
|
||||
|
||||
For grey-scale images, by using a Gray code instead of a simple binary
|
||||
weighted representation of the pixel intensity, some increase in
|
||||
coding efficiency can be reached.
|
||||
|
||||
A Gray code is also a binary representation of integer numbers, but it
|
||||
has the property that the representations of the integer numbers i and
|
||||
(i+1) always differ in exactly one bit. For example, the numbers 0 to
|
||||
7 can be represented in normal binary code and Gray code as in the
|
||||
following table:
|
||||
|
||||
normal
|
||||
number binary code Gray code
|
||||
---------------------------------------
|
||||
0 000 000
|
||||
1 001 001
|
||||
2 010 011
|
||||
3 011 010
|
||||
4 100 110
|
||||
5 101 111
|
||||
6 110 101
|
||||
7 111 100
|
||||
|
||||
The form of Gray code shown above has the property that the second
|
||||
half of the code (numbers 4 - 7) is simply the mirrored first half
|
||||
(numbers 3 - 0) with the first bit set to one. This way, arbitrarily
|
||||
large Gray codes can be generated quickly by mirroring the above
|
||||
example and prefixing the first half with zeros and the second half
|
||||
with ones as often as required. In grey-scale images, it is common
|
||||
practise to use the all-0 code for black and the all-1 code for white.
|
||||
|
||||
No matter whether a Gray code or a binary code is used for encoding a
|
||||
pixel intensity in several bit planes, it always makes sense to store
|
||||
the most significant (leftmost) bit in plane 0, which is transmitted
|
||||
first. This way, a decoder could increase the precision of the
|
||||
displayed pixel intensities while data is still being received and the
|
||||
basic structure of the image will become visible as early as possible
|
||||
during the transmission.
|
||||
|
||||
|
||||
2.2 A simple compression application
|
||||
|
||||
In order to use jbig.c in your application, just link your executable
|
||||
with both jbig.c and jbig_ar.c. Both are already combined into
|
||||
libjbig.a by the provided Makefile, so on Unix systems, just add
|
||||
-ljbig and -L. to the command line options of your compiler. On other
|
||||
systems you will probably have to write a new Makefile. Make sure your
|
||||
compiler can find the file jbig.h and put the line
|
||||
|
||||
#include "jbig.h"
|
||||
|
||||
into your source code.
|
||||
|
||||
The library interface follows object-oriented programming principles.
|
||||
You have to declare a variable (object)
|
||||
|
||||
struct jbg_enc_state s;
|
||||
|
||||
which contains the current status of an encoder. Then you initialize
|
||||
the encoder by calling the constructor function
|
||||
|
||||
void jbg_enc_init(struct jbg_enc_state *s, unsigned long x, unsigned long y,
|
||||
int pl, unsigned char **p,
|
||||
void (*data_out)(unsigned char *start, size_t len,
|
||||
void *file),
|
||||
void *file);
|
||||
|
||||
The parameters have the following meaning:
|
||||
|
||||
s A pointer to the jbg_enc_state structure that you want
|
||||
to initialize.
|
||||
|
||||
x The width of your image in pixels.
|
||||
|
||||
y The height of your image in pixels (lines).
|
||||
|
||||
pl the number of bitmap planes you want to encode.
|
||||
|
||||
p A pointer to an array of pl pointers, where each is again
|
||||
pointing to the first byte of a bitmap as described in
|
||||
section 2.1.
|
||||
|
||||
data_out This is a call-back function that the encoder will
|
||||
call during the compression process by in order to
|
||||
deliver the BIE data to your application. The
|
||||
parameters of the function data_out are a pointer
|
||||
start to the new block of data being delivered, as
|
||||
well as the number len of delivered bytes. The pointer
|
||||
file is transparently delivered to data_out, as
|
||||
specified in jbg_enc_init(). Typically, data_out will
|
||||
write the BIE portion to a file, send it to a network
|
||||
connection, or append it to some memory buffer.
|
||||
|
||||
file A pointer parameter that is passed on to data_out()
|
||||
and can be used, for instance, to allow data_out() to
|
||||
distinguish by which compression task it has been
|
||||
called in multi-threaded applications.
|
||||
|
||||
In the simplest case, the compression is then started by calling the
|
||||
function
|
||||
|
||||
void jbg_enc_out(struct jbg_enc_state *s);
|
||||
|
||||
which will deliver the complete BIE to data_out() in several calls.
|
||||
After jbg_enc_out has returned, a call to the destructor function
|
||||
|
||||
void jbg_enc_free(struct jbg_enc_state *s);
|
||||
|
||||
will release any heap memory allocated by the previous functions.
|
||||
|
||||
|
||||
A minimal example application, which sends the BIE of the above bitmap
|
||||
to stdout, looks like this:
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
/* A sample JBIG encoding application */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "jbig.h"
|
||||
|
||||
void output_bie(unsigned char *start, size_t len, void *file)
|
||||
{
|
||||
fwrite(start, 1, len, (FILE *) file);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned char bitmap[15] = {
|
||||
/* 23 x 5 pixels, "JBIG" */
|
||||
0x7c, 0xe2, 0x38, 0x04, 0x92, 0x40, 0x04, 0xe2,
|
||||
0x5c, 0x44, 0x92, 0x44, 0x38, 0xe2, 0x38
|
||||
};
|
||||
unsigned char *bitmaps[1] = { bitmap };
|
||||
struct jbg_enc_state se;
|
||||
|
||||
jbg_enc_init(&se, 23, 5, 1, bitmaps,
|
||||
output_bie, stdout); /* initialize encoder */
|
||||
jbg_enc_out(&se); /* encode image */
|
||||
jbg_enc_free(&se); /* release allocated resources */
|
||||
|
||||
return 0;
|
||||
}
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
This software produces a 42 byte long BIE. (JBIG is not very good at
|
||||
compressing extremely small images like in this example, because the
|
||||
arithmetic encoder requires some startup data in order to generate
|
||||
reasonable statistics which influence the compression process and
|
||||
because there is some header overhead.)
|
||||
|
||||
|
||||
2.3 More about compression
|
||||
|
||||
If jbg_enc_out() is called directly after jbg_enc_init(), the
|
||||
following default values are used for various compression parameters:
|
||||
|
||||
- Only one single resolution layer is used, i.e. no progressive
|
||||
mode.
|
||||
|
||||
- The number of lines per stripe is selected so that approximately
|
||||
35 stripes per image are used (as recommended in annex C of the
|
||||
standard together with the suggested adaptive template change
|
||||
algorithm). However, not less than 2 and not more than 128 lines
|
||||
are used in order to stay within the suggested minimum parameter
|
||||
support range specified in annex A of the standard).
|
||||
|
||||
- All optional parts of the JBIG algorithm are activated (TPBON,
|
||||
TPDON and DPON).
|
||||
|
||||
- The default resolution reduction table and the default deterministic
|
||||
prediction table are used
|
||||
|
||||
- The maximal vertical offset of the adaptive template pixel is 0
|
||||
and the maximal horizontal offset is 8 (mx = 8, my = 0).
|
||||
|
||||
In order to change any of these default parameters, additional
|
||||
functions have to be called between jbg_enc_init() and jbg_enc_out().
|
||||
|
||||
In order to activate progressive encoding, it is possible to specify
|
||||
with
|
||||
|
||||
void jbg_enc_layers(struct jbg_enc_state *s, int d);
|
||||
|
||||
the number d of differential resolution layers which shall be encoded
|
||||
in addition to the lowest resolution layer 0. For example, if a
|
||||
document with 60-micrometer pixels has to be stored, and the lowest
|
||||
resolution layer shall have 240-micrometer pixels, so that a screen
|
||||
previewer can directly decompress only the required resolution, then a
|
||||
call
|
||||
|
||||
jbg_enc_layers(&se, 2);
|
||||
|
||||
will cause three layers with 240, 120 and 60 micrometers resolution to
|
||||
be generated.
|
||||
|
||||
If the application does not know what typical resolutions are used and
|
||||
simply wants to ensure that the lowest resolution layer will fit into
|
||||
a given maximal window size, then as an alternative, a call to
|
||||
|
||||
int jbg_enc_lrlmax(struct jbg_enc_state *s, unsigned long mwidth,
|
||||
unsigned long mheight);
|
||||
|
||||
will cause the library to automatically determine the suitable number
|
||||
of resolutions so that the lowest resolution layer 0 will not be
|
||||
larger than mwidth x mheight pixels. E.g. if one wants to ensure that
|
||||
systems with a 640 x 480 pixel large screen can decode the required
|
||||
resolution directly, then call
|
||||
|
||||
jbg_enc_lrlmax(&se, 640, 480);
|
||||
|
||||
The return value is the number of differential layers selected.
|
||||
|
||||
After the number of resolution layers has been specified by calls to
|
||||
jbg_enc_layers() or jbg_enc_lrlmax(), by default, all these layers
|
||||
will be written into the BIE. This can be changed with a call to
|
||||
|
||||
int jbg_enc_lrange(struct jbg_enc_state *s, int dl, int dh);
|
||||
|
||||
Parameter dl specifies the lowest resolution layer and dh the highest
|
||||
resolution layer that will appear in the BIE. For instance, if layer 0
|
||||
shall be written to the first BIE and layer 1 and 2 shall be written
|
||||
to a second one, then before writing the first BIE, call
|
||||
|
||||
jbg_enc_lrange(&se, 0, 0);
|
||||
|
||||
and before writing the second BIE with jbg_enc_out(), call
|
||||
|
||||
jbg_enc_lrange(&se, 1, 2);
|
||||
|
||||
If any of the parameters is negative, it will be ignored. The return
|
||||
value is the total number of differential layers that will represent
|
||||
the input image. This way, jbg_enc_lrange(&se, -1, -1) can be used to
|
||||
query the layer of the full image resolution.
|
||||
|
||||
A number of other more exotic options of the JBIG algorithm can be
|
||||
modified by calling
|
||||
|
||||
void jbg_enc_options(struct jbg_enc_state *s, int order, int options,
|
||||
long l0, int mx, int my);
|
||||
|
||||
before calling jbg_enc_out().
|
||||
|
||||
The order parameter can be a combination of the bits JBG_HITOLO,
|
||||
JBG_SEQ, JBG_ILEAVE and JBG_SMID and it determines in which order
|
||||
the SDEs are stored in the BIE. The bits have the following meaning:
|
||||
|
||||
JBG_HITOLO Usually, the lower resolution layers are stored before
|
||||
the higher resolution layers, so that a decoder can
|
||||
already start to display a low resolution version of
|
||||
the full image once a prefix of the BIE has been
|
||||
received. When this bit is set, however, the BIE will
|
||||
contain the higher layers before the lower layers. This
|
||||
avoids additional buffer memory in the encoder and is
|
||||
intended for applications where the encoder is connected
|
||||
to a database which can easily reorder the SDEs before
|
||||
sending them to a decoder. Warning: JBIG decoders are
|
||||
not expected to support the HITOLO option (e.g. the
|
||||
jbig.c decoder currently does not) so you should
|
||||
normally not use it.
|
||||
|
||||
JBG_SEQ Usually, at first all stripes of one resolution layer
|
||||
are written to the BIE and then all stripes of the next
|
||||
layer, and so on. When the SEQ bit is set however, then
|
||||
all layers of the first stripe will be written,
|
||||
followed by all layers of the second stripe, etc. This
|
||||
option also should normally never be required and is
|
||||
not supported by the current jbig.c decoder.
|
||||
|
||||
JBG_SMID In case there exist several bit planes, then the order of
|
||||
the stripes is determined by three loops over all stripes,
|
||||
all planes and all layers. When SMID is set, the loop
|
||||
over all stripes is the middle loop.
|
||||
|
||||
JBG_ILEAVE If this bit is set, then at first all layers of one
|
||||
plane are written before the encoder starts with the next
|
||||
plane.
|
||||
|
||||
The above description may be somewhat confusing, but the following
|
||||
table (see also Table 11 in ITU-T T.82) clarifies how the three bits
|
||||
JBG_SEQ, JBIG_ILEAVE and JBG_SMID influence the ordering of the loops
|
||||
over all stripes, planes and layers:
|
||||
|
||||
|
||||
Loops:
|
||||
JBG_SEQ JBG_ILEAVE JBG_SMID | Outer Middle Inner
|
||||
------------------------------------+---------------------------
|
||||
0 0 0 | p d s
|
||||
0 1 0 | d p s
|
||||
0 1 1 | d s p
|
||||
1 0 0 | s p d
|
||||
1 0 1 | p s d
|
||||
1 1 0 | s d p
|
||||
|
||||
p: plane, s: stripe, d: layer
|
||||
|
||||
|
||||
By default, the order combination JBG_ILEAVE | JBG_SMID is used.
|
||||
|
||||
The options value can contain the following bits, which activate
|
||||
some of the optional algorithms defined by JBIG:
|
||||
|
||||
JBG_LRLTWO Normally, in the lowest resolution layer, pixels
|
||||
from three lines around the next pixel are used
|
||||
in order to determine the context in which the next
|
||||
pixel is encoded. Some people in the JBIG committee
|
||||
seem to have argued that using only 2 lines will
|
||||
make software implementations a little bit faster,
|
||||
however others have argued that using only two lines
|
||||
will decrease compression efficiency by around 5%.
|
||||
As you might expect from a committee, now both
|
||||
alternatives are allowed and if JBG_LRLTWO is set,
|
||||
the slightly faster but 5% less well compressing two
|
||||
line alternative is selected. God bless the committees.
|
||||
Although probably nobody will ever need this option,
|
||||
it has been implemented in jbig.c and is off by
|
||||
default.
|
||||
|
||||
JBG_TPDON This activates the "typical prediction" algorithm
|
||||
for differential layers which avoids that large
|
||||
areas of equal colour have to be encoded at all.
|
||||
This is on by default and there is no good reason to
|
||||
switch it off except for debugging or preparing data
|
||||
for cheap JBIG hardware that might not support this
|
||||
option.
|
||||
|
||||
JBG_TPBON Like JBG_TPDON this activates the "typical prediction"
|
||||
algorithm in the lowest resolution layer. Also activated
|
||||
by default.
|
||||
|
||||
JBG_DPON This bit activates for the differential resolution
|
||||
layers the "deterministic prediction" algorithm,
|
||||
which avoids that higher resolution layer pixels are
|
||||
encoded when their value can already be determined
|
||||
with the knowledge of the neighbour pixels, the
|
||||
corresponding lower resolution pixels and the
|
||||
resolution reduction algorithm. This is also
|
||||
activated by default and one reason for deactivating
|
||||
it would be if the default resolution reduction
|
||||
algorithm were replaced by another one.
|
||||
|
||||
JBG_DELAY_AT Use a slightly less efficient algorithm to determine
|
||||
when an adaptive template change is necessary. With
|
||||
this bit set, the encoder output is compatible to the
|
||||
conformance test examples in cause 7.2 of ITU-T T.82.
|
||||
Then all adaptive template changes are delayed until
|
||||
the first line of the next stripe. This option is by
|
||||
default deactivated and is only required for passing a
|
||||
special compatibility test suite.
|
||||
|
||||
In addition, parameter l0 in jbg_enc_options() allows you to specify
|
||||
the number of lines per stripe in resolution layer 0. The parameters
|
||||
mx and my change the maximal offset allowed for the adaptive template
|
||||
pixel. JBIG-KIT now supports the full range of possible mx values up
|
||||
to 127 in the encoder and decoder, but my is at the moment ignored and
|
||||
always set to 0. As the standard requires of all decoder
|
||||
implementations only to support maximum values mx = 16 and my = 0,
|
||||
higher values should normally be avoided in order to guarantee
|
||||
interoperability. The ITU-T T.85 profile for JBIG in fax machines
|
||||
requires support for mx = 127 and my = 0. Default is mx = 8 and my =
|
||||
0. If any of the parameters order, options, mx or my is negative, or
|
||||
l0 is zero, then the corresponding current value remains unmodified.
|
||||
|
||||
The resolution reduction and deterministic prediction tables can also
|
||||
be replaced. However as these options are anyway only for experts,
|
||||
please have a look at the source code of jbg_enc_out() and the struct
|
||||
members dppriv and res_tab of struct jbg_enc_state for the details of
|
||||
how to do this, in case you really need it. The functions
|
||||
jbg_int2dppriv and jbg_dppriv2int are provided in order to convert the
|
||||
DPTABLE data from the format used in the standard into the more
|
||||
efficient format used internally by JBIG-KIT.
|
||||
|
||||
If you want to encode a grey-scale image, you can use the library
|
||||
function
|
||||
|
||||
void jbg_split_planes(unsigned long x, unsigned long y, int has_planes,
|
||||
int encode_planes,
|
||||
const unsigned char *src, unsigned char **dest,
|
||||
int use_graycode);
|
||||
|
||||
It separates an image in which each pixel is represented by one or
|
||||
more bytes into separate bit planes. The dest array of pointers to
|
||||
these bit planes can then be handed over to jbg_enc_init(). The
|
||||
variables x and y specify the width and height of the image in pixels,
|
||||
and has_planes specifies how many bits per pixel are used. As each
|
||||
pixel is represented by an integral number of consecutive bytes, of
|
||||
which each contains up to eight bits, the total length of the input
|
||||
image array src[] will therefore be x * y * ((has_planes + 7) / 8)
|
||||
bytes. The pixels are stored as usually in English reading order, and
|
||||
for each pixel the integer value is stored with the most significant
|
||||
byte coming first (Bigendian). This is exactly the format used in raw
|
||||
PGM files. In encode_planes, the number of bit planes that shall be
|
||||
extracted can be specified. This allows for instance to extract only
|
||||
the most significant 8 bits of a 12-bit image, where each pixel is
|
||||
represented by two bytes, by specifying has_planes = 12 and
|
||||
encode_planes = 8. If use_graycode is zero, then the binary code of
|
||||
the pixel integer values will be used instead of the Gray code. Plane
|
||||
0 contains always the most significant bit.
|
||||
|
||||
|
||||
3 Decompressing an image
|
||||
|
||||
Like with the compression functions, if you want to use the jbig.c
|
||||
library, you have to put the line
|
||||
|
||||
#include "jbig.h"
|
||||
|
||||
into your source code and link your executable with libjbig.a.
|
||||
|
||||
The state of a JBIG decoder is stored completely in a struct and you
|
||||
will have to define a variable like
|
||||
|
||||
struct jbg_dec_state sd;
|
||||
|
||||
which is initialized by a call to
|
||||
|
||||
void jbg_dec_init(struct jbg_dec_state *s);
|
||||
|
||||
After this, you can directly start to pass data from the BIE to the decoder
|
||||
by calling the function
|
||||
|
||||
int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len,
|
||||
size_t *cnt);
|
||||
|
||||
The pointer data points to the first byte of a data block with length
|
||||
len, which contains bytes from a BIE. It is not necessary to pass a
|
||||
whole BIE at once to jbg_dec_in(), it can arrive fragmented in any way
|
||||
by calling jbg_dec_in() several times. It is also possible to send
|
||||
several BIEs concatenated to jbg_dec_in(), however these then have to
|
||||
fit together. If you send several BIEs to the decoder, the lowest
|
||||
resolution layer in each following BIE has to be the highest
|
||||
resolution layer in the previous BIE plus one and the image sizes and
|
||||
number of planes also have to fit together, otherwise jbg_dec_in()
|
||||
will return the error JBG_ENOCONT after the header of the new BIE has
|
||||
been received completely.
|
||||
|
||||
If pointer cnt is not NULL, then the number of bytes actually read
|
||||
from the data block will be stored there. In case the data block did
|
||||
not contain the end of the BIE, then the value JBG_EAGAIN will be
|
||||
returned and *cnt equals len.
|
||||
|
||||
Once the end of a BIE has been reached, the return value of
|
||||
jbg_dec_in() will be JBG_EOK. After this has happened, the functions
|
||||
and macros
|
||||
|
||||
unsigned long jbg_dec_getwidth(struct jbg_dec_state *s);
|
||||
unsigned long jbg_dec_getheight(struct jbg_dec_state *s);
|
||||
int jbg_dec_getplanes(struct jbg_dec_state *s);
|
||||
unsigned char *jbg_dec_getimage(struct jbg_dec_state *s, int plane);
|
||||
unsigned long jbg_dec_getsize(struct jbg_dec_state *s);
|
||||
|
||||
can be used to query the dimensions of the now completely decoded
|
||||
image and to get a pointer to all bitmap planes. The bitmaps are
|
||||
stored as described in section 2.1. The function jbg_dec_getsize()
|
||||
calculates the number of bytes which one bitmap requires.
|
||||
|
||||
The function
|
||||
|
||||
void jbg_dec_merge_planes(const struct jbg_dec_state *s, int use_graycode,
|
||||
void (*data_out)(unsigned char *start, size_t len,
|
||||
void *file), void *file);
|
||||
|
||||
allows you to merge the bit planes that can be accessed individually
|
||||
with jbg_dec_getimage() into an array with one or more bytes per pixel
|
||||
(i.e., the format provided to jbg_split_planes()). If use_graycode is
|
||||
zero, then a binary encoding will be used. The output array will be
|
||||
delivered via the callback function data_out, exactly in the same way
|
||||
in which the encoder provides the BIE. The function
|
||||
|
||||
unsigned long jbg_dec_getsize_merged(const struct jbg_dec_state *s);
|
||||
|
||||
determines how long the data array delivered by jbg_dec_merge_planes()
|
||||
is going to be.
|
||||
|
||||
Before calling jbg_dec_in() the first time, it is possible to specify with
|
||||
a call to
|
||||
|
||||
void jbg_dec_maxsize(struct jbg_dec_state *s, unsigned long xmax,
|
||||
unsigned long ymax);
|
||||
|
||||
an abort criterion for progressively encoded images. For instance if an
|
||||
application will display a whole document on a screen which is 1024 x
|
||||
768 pixels large, then this application should call
|
||||
|
||||
jbg_dec_maxsize(&sd, 1024, 768);
|
||||
|
||||
before the decoding process starts. If the image has been encoded in
|
||||
progressive mode (i.e. with several resolution layers), then the
|
||||
decoder will stop with a return value JBG_EOK_INTR after the largest
|
||||
resolution layer that is still smaller than 1024 x 768. However this
|
||||
is no guarantee that the image which can then be read out using
|
||||
jbg_dec_getimage(), etc. is really not larger than the specified
|
||||
maximal size. The application will have to check the size of the
|
||||
image, because the decoder does not automatically apply a resolution
|
||||
reduction if no suitable resolution layer is available in the BIE.
|
||||
|
||||
If jbg_dec_in() returned JBG_EOK_INTR or JBG_EOK, then it is possible
|
||||
to continue calling jbg_dec_in() with the remaining data in order to
|
||||
either decode the remaining resolution layers of the current BIE or in
|
||||
order to add another BIE with additional resolution layers. In both
|
||||
cases, after jbg_dec_in() returned JBG_EOK_INTR or JBG_EOK, *cnt is
|
||||
probably not equal to len and the remainder of the data block which
|
||||
has not yet been processed by the decoder has to be delivered to
|
||||
jbg_dec_in() again.
|
||||
|
||||
If any other return value than JBG_EOK, JBG_EOK_INTR or JBG_EAGAIN
|
||||
has been returned by jbg_dec_in(), then an error has occurred and
|
||||
|
||||
void jbg_dec_free(struct jbg_dec_state *s);
|
||||
|
||||
should be called in order to release any allocated memory. The
|
||||
destructor jbg_dec_free() should of course also be called, once the
|
||||
decoded bitmap returned by jbg_dec_getimage() is no longer required
|
||||
and the memory can be released.
|
||||
|
||||
The function
|
||||
|
||||
const char *jbg_strerror(int errnum);
|
||||
|
||||
returns a pointer to a short single line test message that explains
|
||||
the return value of jbg_dec_in(). This message can be used in order to
|
||||
provide the user a brief informative message about what when wrong
|
||||
while decompressing a JBIG image. The po/ subdirectory contains *.po
|
||||
files that translate the English ASCII strings returned by
|
||||
jbg_strerror() into other languages (e.g., for use with GNU gettext).
|
||||
The four least-significant bits of the return value of jbg_dec_in()
|
||||
may contain additional detailed technical information about the exact
|
||||
test that spotted the error condition (see source code for details),
|
||||
i.e. more than the text message returned by jbg_strerror() reveals.
|
||||
Therefore it may be useful to display the return value itself as a
|
||||
hexadecimal number, in addition to the string returned by
|
||||
jbg_strerror().
|
||||
|
||||
The current implementation of the jbig.c decoder has the following
|
||||
limitations:
|
||||
|
||||
- The maximal vertical offset MY of the adaptive template pixel
|
||||
must be zero.
|
||||
|
||||
- HITOLO and SEQ bits must not be set in the order value.
|
||||
|
||||
- Not more than JBG_ATMOVES_MAX (currently set to 64) ATMOVE
|
||||
marker segments can be handled per stripe.
|
||||
|
||||
- the number D of differential layers must be less than 32
|
||||
|
||||
None of the above limitations can be exceeded by a JBIG data stream
|
||||
that conforms to the ITU-T T.85 application profile for the use of
|
||||
JBIG1 in fax machines.
|
||||
|
||||
The maximum image size that a BIE header (BIH) can indicate is X_D =
|
||||
2^32-1 pixels wide, Y_D = 2^32-1 lines high, with P = 255 bits per
|
||||
pixel. Such an image would, in uncompressed form, require about 588
|
||||
exabytes. Once jbg_dec_in() has received the 20-byte long BIH at the
|
||||
start of the BIE, it will call malloc() to allocate enough memory to
|
||||
hold the uncompressed image planes. Users may, therefore, want to
|
||||
defend their application against excessive image-size parameters in a
|
||||
received BIH, by checking X_D, Y_D, and P against appropriate safety
|
||||
limits before handing over the BIE header to jbg_dec_in(). BIE headers
|
||||
indicating too large images might be abused for denial of service
|
||||
attacks, to exhaust the memory of a system (e.g., CVE-2017-9937). To
|
||||
manage this risk, the jbig.c decoder will now, by default, return "Not
|
||||
enough memory available" (JBG_ENOMEM) if the resulting final image
|
||||
layer would occupy more than 2 gigabytes. Users can adjust this limit
|
||||
by changing sd->maxmem right after having called jbg_dec_init(&sd).
|
||||
The actual amount of memory allocated with malloc() calls during the
|
||||
decoding process is somewhat higher (at least 25%) than the limit set
|
||||
in sd->maxmem, as the decoder requires additional heap memory that
|
||||
depends on the image dimensions.
|
||||
|
||||
The jbg_dec_in() function will return "Input data stream uses
|
||||
unimplemented JBIG features" (JBG_EIMPL | 1) if Y_D equals 0xffffffff,
|
||||
which is an extreme value commonly used to encode images according to
|
||||
ITU-T T.85 where the height was unknown when the BIH was emitted.
|
||||
|
||||
All malloc(), realloc() and free() functions called by jbig.c are
|
||||
wrapped by the functions checked_malloc(), checked_realloc() and
|
||||
checked_free(). These simply call abort() when memory allocation
|
||||
fails. Developpers of embedded systems may want to replace them with
|
||||
alternative forms of exception handling.
|
||||
|
||||
There are two more limitations of the current implementation of the
|
||||
jbig.c decoder that might cause problems with processing JBIG data
|
||||
stream that conform to ITU-T T.85:
|
||||
|
||||
- The jbig.c decoder was designed to operate incrementally.
|
||||
Each received byte is processed immediately as soon as it arrives.
|
||||
As a result, it does not look beyond the SDRST/SDNORM at the end
|
||||
of all stripes for any immediately following NEWLEN marker that
|
||||
might reduce the number of lines encoded by the current stripe.
|
||||
However section 6.2.6.2 of ITU-T T.82 says that a NEWLEN marker
|
||||
segment "could refer to a line in the immediately preceding stripe
|
||||
due to an unexpected termination of the image or the use of only
|
||||
such stripe", and ITU-T.85 explicitly suggests the use of this
|
||||
for fax machines that start transmission before having encountered
|
||||
the end of the page.
|
||||
|
||||
- The image size initially indicated in the BIE header is used to
|
||||
allocate memory for a bitmap of this size. This means that BIEs
|
||||
that set initially Y_D = 0xffffffff (as suggested in ITU-T T.85
|
||||
for fax machines that do not know the height of the page at the
|
||||
start of the transmission) cannot be decoded directly by this
|
||||
version.
|
||||
|
||||
For both issues, there is a workaround available:
|
||||
|
||||
If you encounter a BIE that has in the header the VLENGTH=1 option bit
|
||||
set, then first wait until you have received the entire BIE and stored
|
||||
it in memory. Then call the function
|
||||
|
||||
int jbg_newlen(unsigned char *bie, size_t len);
|
||||
|
||||
where bie is a pointer to the first byte of the BIE and len its length
|
||||
in bytes. This function will scan the entire BIE for the first NEWLEN
|
||||
marker segment. It will then take the updated image-height value YD
|
||||
from it and use it to overwrite the YD value in the BIE header. The
|
||||
jbg_newlen() can return some of the same error codes as jbg_dec_in(),
|
||||
namely JBG_EOK if everything went fine, JBG_EAGAIN is the data
|
||||
provided is too short to be a valid BIE, JBG_EINVAL if a format error
|
||||
was encountered, and JBG_EABORT if an ABORT marker segment was found.
|
||||
After having patched the image-height value in the BIE using
|
||||
jbg_newlen(), simply hand over the BIE as usual to jbg_dec_in().
|
||||
|
||||
In general, for applications where NEWLEN markers can appear, in
|
||||
particular fax reception, you should consider using the jbig85.c
|
||||
decoder instead, as it can process BIEs with NEWLEN markers in a
|
||||
single pass.
|
||||
|
||||
A more detailed description of the JBIG-KIT implementation is
|
||||
|
||||
Markus Kuhn: Effiziente Kompression von bi-level Bilddaten durch
|
||||
kontextsensitive arithmetische Codierung. Studienarbeit, Lehrstuhl
|
||||
für Betriebssysteme, IMMD IV, Universität Erlangen-Nürnberg,
|
||||
Erlangen, July 1995. (German, 62 pages)
|
||||
<http://www.cl.cam.ac.uk/~mgk25/kuhn-sta.pdf>
|
||||
|
||||
Please quote the above if you use JBIG-KIT in your research project.
|
||||
|
||||
*** Happy compressing ***
|
||||
|
||||
[end]
|
||||
1091
blender-deps/jbigkit-cmake/libjbig/jbig85.c
Normal file
1091
blender-deps/jbigkit-cmake/libjbig/jbig85.c
Normal file
File diff suppressed because it is too large
Load Diff
173
blender-deps/jbigkit-cmake/libjbig/jbig85.h
Normal file
173
blender-deps/jbigkit-cmake/libjbig/jbig85.h
Normal file
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Header file for the T.85 "light" version of the portable
|
||||
* JBIG image compression library
|
||||
*
|
||||
* Copyright 1995-2014 -- Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/
|
||||
*/
|
||||
|
||||
#ifndef JBG85_H
|
||||
#define JBG85_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "jbig_ar.h"
|
||||
|
||||
/*
|
||||
* JBIG-KIT version number
|
||||
*/
|
||||
|
||||
#define JBG85_VERSION "2.1"
|
||||
#define JBG85_VERSION_MAJOR 2
|
||||
#define JBG85_VERSION_MINOR 1
|
||||
|
||||
/*
|
||||
* JBIG-KIT licence agreement reference code:
|
||||
* If you use JBIG-KIT under a commercial licence, please replace
|
||||
* below the letters GPL with the reference code that you received
|
||||
* with your licence agreement. (This code is typically a letter "A"
|
||||
* followed by four decimal digits, e.g. "A1234".)
|
||||
*/
|
||||
|
||||
#define JBG85_LICENCE "GPL"
|
||||
|
||||
/*
|
||||
* Maximum number of ATMOVEs per stripe that decoder can handle
|
||||
*/
|
||||
|
||||
#define JBG85_ATMOVES_MAX 1
|
||||
|
||||
#ifndef JBG_LRLTWO
|
||||
|
||||
/*
|
||||
* Option and order flags
|
||||
*/
|
||||
|
||||
#define JBG_LRLTWO 0x40
|
||||
#define JBG_VLENGTH 0x20
|
||||
#define JBG_TPBON 0x08
|
||||
|
||||
/*
|
||||
* Possible error code return values
|
||||
*/
|
||||
|
||||
#define JBG_EOK (0 << 4)
|
||||
#define JBG_EOK_INTR (1 << 4)
|
||||
#define JBG_EAGAIN (2 << 4)
|
||||
#define JBG_ENOMEM (3 << 4)
|
||||
#define JBG_EABORT (4 << 4)
|
||||
#define JBG_EMARKER (5 << 4)
|
||||
#define JBG_EINVAL (6 << 4)
|
||||
#define JBG_EIMPL (7 << 4)
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Status of a JBIG encoder
|
||||
*/
|
||||
|
||||
struct jbg85_enc_state {
|
||||
unsigned long x0, y0; /* size of the input image */
|
||||
unsigned long l0; /* number of lines per stripe */
|
||||
int options; /* encoding parameters */
|
||||
int newlen; /* 0 = jbg85_enc_newlen() has not yet been called
|
||||
1 = jbg85_enc_newlen() has updated y0, NEWLEN pending
|
||||
2 = NEWLEN has already been output */
|
||||
unsigned mx; /* maximum ATMOVE window size */
|
||||
unsigned long y; /* next line number to be encoded */
|
||||
unsigned long i; /* next per-stripe line number to be encoded */
|
||||
int tx; /* x-offset of adaptive template pixel */
|
||||
unsigned long c_all, c[128]; /* adaptive template algorithm variables */
|
||||
int new_tx; /* -1 = no ATMOVE pending, otherwise new TX value */
|
||||
int ltp_old; /* true if line y-1 was "typical" */
|
||||
struct jbg_arenc_state s; /* arithmetic encoder status */
|
||||
void (*data_out)(unsigned char *start, size_t len, void *file);
|
||||
/* data write callback */
|
||||
void *file; /* parameter passed to data_out() */
|
||||
unsigned char *comment; /* content of comment marker segment to be added
|
||||
at next opportunity (will be reset to NULL
|
||||
as soon as comment has been written) */
|
||||
unsigned long comment_len; /* length of data pointed to by comment */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Status of a JBIG decoder
|
||||
*/
|
||||
|
||||
struct jbg85_dec_state {
|
||||
/* data from BIH */
|
||||
unsigned long x0, y0; /* size of the full image */
|
||||
unsigned long l0; /* number of lines per stripe */
|
||||
int options; /* encoding parameters */
|
||||
int mx; /* maximum ATMOVE window size */
|
||||
/* image data */
|
||||
int p[3]; /* curr. line starts at linebuf+bpl*p[0], prev. line starts
|
||||
* at linebuf+bpl*p[1], its predecessor at linebuf+bpl*p[2] */
|
||||
unsigned char *linebuf; /* buffer region provided by caller */
|
||||
size_t linebuf_len;
|
||||
size_t bpl; /* bytes per line */
|
||||
/* status information */
|
||||
int tx; /* x-offset of AT pixel */
|
||||
struct jbg_ardec_state s; /* arithmetic decoder status */
|
||||
unsigned long bie_len; /* number of bytes read so far */
|
||||
unsigned char buffer[20]; /* used to store BIH or marker segments fragm. */
|
||||
int buf_len; /* number of bytes in buffer */
|
||||
unsigned long comment_skip; /* remaining bytes of a COMMENT segment */
|
||||
unsigned long x; /* x position of next pixel */
|
||||
unsigned long stripe; /* current stripe */
|
||||
unsigned long y; /* line in image (first line is 0) */
|
||||
unsigned long i; /* line in current stripe (first line of stripe is 0) */
|
||||
int at_moves; /* number of AT moves in the current stripe */
|
||||
unsigned long at_line[JBG85_ATMOVES_MAX]; /* lines at which an *
|
||||
* AT move will happen */
|
||||
int at_tx[JBG85_ATMOVES_MAX]; /* ATMOVE x-offsets in current stripe */
|
||||
unsigned long line_h1, line_h2, line_h3; /* variables of decode_pscd */
|
||||
int pseudo; /* flag for TPBON/TPDON: next pixel is pseudo pixel */
|
||||
int lntp; /* flag for TP: line is not typical */
|
||||
int (*line_out)(const struct jbg85_dec_state *s,
|
||||
unsigned char *start, size_t len,
|
||||
unsigned long y, void *file);
|
||||
/* data write callback */
|
||||
void *file; /* parameter passed to data_out() */
|
||||
int intr; /* flag that line_out requested interrupt */
|
||||
int end_of_bie; /* flag that the end of the BIE has been signalled */
|
||||
};
|
||||
|
||||
|
||||
/* function prototypes */
|
||||
|
||||
void jbg85_enc_init(struct jbg85_enc_state *s,
|
||||
unsigned long x0, unsigned long y0,
|
||||
void (*data_out)(unsigned char *start, size_t len,
|
||||
void *file),
|
||||
void *file);
|
||||
void jbg85_enc_options(struct jbg85_enc_state *s, int options,
|
||||
unsigned long l0, int mx);
|
||||
void jbg85_enc_lineout(struct jbg85_enc_state *s, unsigned char *line,
|
||||
unsigned char *prevline, unsigned char *prevprevline);
|
||||
void jbg85_enc_newlen(struct jbg85_enc_state *s, unsigned long y0);
|
||||
void jbg85_enc_abort(struct jbg85_enc_state *s);
|
||||
|
||||
void jbg85_dec_init(struct jbg85_dec_state *s,
|
||||
unsigned char *buf, size_t buflen,
|
||||
int (*line_out)(const struct jbg85_dec_state *s,
|
||||
unsigned char *start, size_t len,
|
||||
unsigned long y, void *file),
|
||||
void *file);
|
||||
int jbg85_dec_in(struct jbg85_dec_state *s, unsigned char *data, size_t len,
|
||||
size_t *cnt);
|
||||
int jbg85_dec_end(struct jbg85_dec_state *s);
|
||||
const char *jbg85_strerror(int errnum);
|
||||
|
||||
/* some macros for examining decoder state */
|
||||
|
||||
#define jbg85_dec_finished(s) ((s)->bie_len == 20 && (s)->y >= (s)->y0)
|
||||
/* enquire about image size */
|
||||
#define jbg85_dec_getwidth(s) ((s)->x0)
|
||||
#define jbg85_dec_getheight(s) ((s)->y0)
|
||||
/* enquire about validity of image-size results */
|
||||
#define jbg85_dec_validwidth(s) ((s)->bie_len == 20)
|
||||
#define jbg85_dec_finalheight(s) ((s)->bie_len == 20 && \
|
||||
((((s)->options & JBG_VLENGHT) == 0) || \
|
||||
((s)->y >= (s)->y0)))
|
||||
|
||||
#endif /* JBG85_H */
|
||||
618
blender-deps/jbigkit-cmake/libjbig/jbig85.txt
Normal file
618
blender-deps/jbigkit-cmake/libjbig/jbig85.txt
Normal file
@@ -0,0 +1,618 @@
|
||||
|
||||
Using the T.85 "light" version of the JBIG-KIT library
|
||||
------------------------------------------------------
|
||||
|
||||
Markus Kuhn -- 2008-08-30
|
||||
|
||||
|
||||
This text explains how to use the functions provided by the JBIG-KIT
|
||||
portable image compression library jbig85.c in your application
|
||||
software.
|
||||
|
||||
|
||||
1 Distinguishing features
|
||||
|
||||
The jbig85.c library implements only the "single-progression
|
||||
sequential coding" subset of the JBIG1 standard, which is defined in
|
||||
ITU-T Recommendation T.85 <http://www.itu.int/rec/T-REC-T.85/en>, also
|
||||
known as the "facsimile application profile". This means that the
|
||||
JBIG1 data streams that the jbig85.c library can process can have
|
||||
|
||||
- no progressive encoding, i.e. the image is always encoded in a
|
||||
single resolution layer (and not as a sequence of layers of a
|
||||
resolution pyramid);
|
||||
|
||||
- only a single plane, i.e. the raw data are black/white images with
|
||||
only one bit per pixel information.
|
||||
|
||||
The jbig85.c library is not suitable for continuous-tone (colour or
|
||||
grey-scale) image applications, including the fax method described in
|
||||
ITU-R Recommendation T.43. For these applications, use the full jbig.c
|
||||
library instead.
|
||||
|
||||
The T.85 restrictions are sufficient for black/white fax transmission
|
||||
and several other common bi-level image applications (printer drivers,
|
||||
document archiving, etc.). They simplify the design of the encoder and
|
||||
decoder and allow the jbig85.c library to provide several advantages
|
||||
over the full-featured jbig.c:
|
||||
|
||||
- Only the last three lines of the uncompressed image need to be
|
||||
kept in RAM at any time.
|
||||
|
||||
- All memory allocation is done outside the jbig85.c library, which
|
||||
performs no calls to malloc(), free(), etc.
|
||||
|
||||
- The implementation can handle images whose height (number of pixel
|
||||
rows) is not yet known before the last line has been encoded or
|
||||
decoded.
|
||||
|
||||
- All usage modes of the NEWLEN marker segment are supported,
|
||||
including a NEWLEN occurring after the final stripe, as required by
|
||||
ITU-T Recommendation T.85, using only a single pass over the data.
|
||||
|
||||
- The code is smaller and there is no need to store tables related
|
||||
to the resolution-reduction algorithms.
|
||||
|
||||
This makes the jbig85.c library particularly suited for very small
|
||||
embedded applications, e.g. low-end fax machines, along with the fact
|
||||
that the library is non-recursive and requires only a very small stack
|
||||
(typically just a bit over 100 bytes on a 32-bit system). The jbig85.c
|
||||
library may also be a good choice where very large black/white images
|
||||
are processed.
|
||||
|
||||
The jbig85.c and jbig.c libraries both can be linked simultaneously
|
||||
with the same application if you #include jbig85.h after jbig.h into
|
||||
your source code.
|
||||
|
||||
|
||||
2 Introduction to JBIG (T.85 subset)
|
||||
|
||||
We start with a short introduction to the T.85 subset of JBIG1. More
|
||||
detailed information is provided in the "Introduction and overview"
|
||||
section of the JBIG1 standard. Information on how to obtain a copy of
|
||||
the standard is available from <http://www.itu.int/rec/T-REC-T.82/en>
|
||||
or <http://www.iso.ch/>.
|
||||
|
||||
The JBIG1 standard allows the encoder to divide an image into several
|
||||
horizontal stripes. All stripes have equal size, except perhaps the
|
||||
final one.
|
||||
|
||||
The compressed data stream specified by the JBIG standard is called a
|
||||
bi-level image entity (BIE). A BIE consists of a 20-byte header,
|
||||
followed by a sequence of stripe data entities (SDE). Each SDE encodes
|
||||
the content of one single stripe in one plane of one resolution layer.
|
||||
Between the SDEs, other information blocks (called floating marker
|
||||
segments) can also be present. They are used to change certain
|
||||
parameters of the algorithm in the middle of an image or contain
|
||||
additional application specific information. A BIE looks like this:
|
||||
|
||||
|
||||
+------------------------------------------------+
|
||||
| |
|
||||
| 20-byte header (specifying image size, stripe |
|
||||
| size, and options) |
|
||||
| |
|
||||
+------------------------------------------------+
|
||||
| |
|
||||
| optional floating marker segments |
|
||||
| |
|
||||
+------------------------------------------------+
|
||||
| |
|
||||
| stripe data entity |
|
||||
| |
|
||||
+------------------------------------------------+
|
||||
| |
|
||||
| optional floating marker segments |
|
||||
| |
|
||||
+------------------------------------------------+
|
||||
| |
|
||||
| stripe data entity |
|
||||
| |
|
||||
+------------------------------------------------+
|
||||
...
|
||||
+------------------------------------------------+
|
||||
| |
|
||||
| stripe data entity |
|
||||
| |
|
||||
+------------------------------------------------+
|
||||
|
||||
It is possible to use the raw BIE data stream as specified by the JBIG
|
||||
standard directly as the format of a file used for storing images.
|
||||
This is what the pbmtojbg, jbgtopbm, pbmtojbg85, and jbgtopbm85
|
||||
conversion tools do that are provided in this package as demonstration
|
||||
applications. However, as the BIE format has been designed for a large
|
||||
number of very different applications, and to allow efficient direct
|
||||
processing by special JBIG hardware chip implementations, the BIE
|
||||
header contains only the minimum amount of information absolutely
|
||||
required by the decompression algorithm. Many features expected from a
|
||||
good file format are missing in the BIE data stream:
|
||||
|
||||
- no "magic code" in the first few bytes to allow identification
|
||||
of the file format on a typeless file system and to allow
|
||||
automatic distinction from other compression algorithms
|
||||
|
||||
- no standardized way to encode additional information such as a
|
||||
textual description, the physical size and resolution of the
|
||||
document, etc.
|
||||
|
||||
- a checksum to ensure image integrity
|
||||
|
||||
- encryption and signature mechanisms
|
||||
|
||||
- many things more
|
||||
|
||||
Raw BIE data streams alone may therefore not be a suitable format for
|
||||
document archiving and exchange. A standard format for this purpose
|
||||
would typically combine a BIE representing the image data with an
|
||||
additional header providing auxiliary information into one file.
|
||||
Existing established multi-purpose file formats with a rich set of
|
||||
auxiliary information attributes like TIFF could be extended easily to
|
||||
also hold JBIG compressed data.
|
||||
|
||||
On the other hand, in e.g. database applications, a BIE might be
|
||||
stored directly in a binary variable-length field. Auxiliary
|
||||
information would then be stored in other fields of the same record,
|
||||
to simplify search operations.
|
||||
|
||||
|
||||
2 Compressing an image
|
||||
|
||||
2.1 Format of the source image
|
||||
|
||||
To be processed by the jbig85.c encoder, the image has to be present
|
||||
in memory a bitmap. Each byte of a bitmap contains eight pixels, where
|
||||
the most significant bit represents the leftmost of these. Each line
|
||||
of a bitmap has to be stored in an integral number of bytes. If the
|
||||
image width is not an integral multiple of eight, then the final byte
|
||||
has to be padded with zero bits.
|
||||
|
||||
For example the 23x5 pixels large single plane image:
|
||||
|
||||
.XXXXX..XXX...X...XXX..
|
||||
.....X..X..X..X..X.....
|
||||
.....X..XXX...X..X.XXX.
|
||||
.X...X..X..X..X..X...X.
|
||||
..XXX...XXX...X...XXX..
|
||||
|
||||
is represented by the 15 bytes
|
||||
|
||||
01111100 11100010 00111000
|
||||
00000100 10010010 01000000
|
||||
00000100 11100010 01011100
|
||||
01000100 10010010 01000100
|
||||
00111000 11100010 00111000
|
||||
|
||||
or in hexadecimal notation
|
||||
|
||||
7c e2 38 04 92 40 04 e2 5c 44 92 44 38 e2 38
|
||||
|
||||
This is the format used in binary PBM files and it can also be handled
|
||||
directly by the Xlib library of the X Window System.
|
||||
|
||||
The standard recommends that a 0 pixel represents the background and a
|
||||
1 pixel represents the foreground colour of an image, in other words, 0
|
||||
is white and 1 is black for scanned paper documents.
|
||||
|
||||
|
||||
2.2 A simple compression application
|
||||
|
||||
In order to use jbig85.c in your application, just link your
|
||||
executable with both jbig85.c and jbig_ar.c. Both are already combined
|
||||
into libjbig85.a by the provided Makefile, so on Unix systems, just
|
||||
add -ljbig85 and -L. to the command line options of your compiler. On
|
||||
other systems you will probably have to write a new Makefile. Make
|
||||
sure your compiler can find the file jbig85.h and put the line
|
||||
|
||||
#include "jbig85.h"
|
||||
|
||||
into your source code.
|
||||
|
||||
The library interface follows object-oriented programming principles.
|
||||
You have to declare a variable (object)
|
||||
|
||||
struct jbg85_enc_state s;
|
||||
|
||||
which contains the current status of an encoder. Then you initialize
|
||||
the encoder by calling
|
||||
|
||||
void jbg85_enc_init(struct jbg85_enc_state *s,
|
||||
unsigned long x, unsigned long y,
|
||||
void (*data_out)(unsigned char *start, size_t len,
|
||||
void *file),
|
||||
void *file);
|
||||
|
||||
The parameters have the following meaning:
|
||||
|
||||
s A pointer to the jbg85_enc_state structure that you want
|
||||
to initialize.
|
||||
|
||||
x The width of your image in pixels.
|
||||
|
||||
y The height of your image in pixels (lines). This can be
|
||||
a larger value than the actual height of the image, or
|
||||
even 2^32-1 (or equally -1), if the height of the
|
||||
image is not yet known. In that case, leave the
|
||||
JBG_VLENGTH option set (see below) and call
|
||||
jbg85_enc_newlen() as soon as the actual image height
|
||||
is known.
|
||||
|
||||
data_out This is a call-back function that the encoder will
|
||||
call during the compression process in order to
|
||||
deliver the BIE data to your application. The
|
||||
parameters of the function data_out are a pointer
|
||||
start to the new block of data being delivered, as
|
||||
well as the number len of delivered bytes. The pointer
|
||||
file is transparently delivered to data_out, as
|
||||
specified in jbg85_enc_init(). Typically, data_out
|
||||
will write the BIE portion to a file, send it to a
|
||||
network connection, or append it to some memory
|
||||
buffer.
|
||||
|
||||
file A pointer parameter that is passed on to data_out()
|
||||
and can be used, for instance, to allow data_out() to
|
||||
distinguish by which compression task it has been
|
||||
called in multi-threaded applications.
|
||||
|
||||
The compression can then be started by calling the function
|
||||
|
||||
void jbg85_enc_lineout(struct jbg85_enc_state *s, unsigned char *line,
|
||||
unsigned char *prevline, unsigned char *prevprevline);
|
||||
|
||||
successively for each line of the image, top to bottom. The parameters
|
||||
are:
|
||||
|
||||
line A pointer to the first byte of the line to be encoded.
|
||||
|
||||
prevline A pointer to the data that the line parameter pointed
|
||||
to in the previous call. The value will be ignored
|
||||
if this is the first call.
|
||||
|
||||
prevprevline A pointer to the data that the prevline parameter pointed
|
||||
to in the previous call. The value will be ignored
|
||||
if this is the first or second call.
|
||||
|
||||
After jbg85_enc_lineout() has been called for all lines of the image,
|
||||
the complete BIE will have been delivered via several callbacks to
|
||||
data_out(). These BIE bytes are delivered as soon as possible, as the
|
||||
encoder cannot buffer more than a few bytes internally.
|
||||
|
||||
A minimal example application, which sends the BIE of the above bitmap
|
||||
to stdout, looks like this:
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
/* A sample JBIG T.85 encoding application */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "jbig85.h"
|
||||
|
||||
void output_bie(unsigned char *start, size_t len, void *file)
|
||||
{
|
||||
fwrite(start, 1, len, (FILE *) file);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned char bitmap[15] = {
|
||||
/* 23 x 5 pixels, "JBIG" */
|
||||
0x7c, 0xe2, 0x38, 0x04, 0x92, 0x40, 0x04, 0xe2,
|
||||
0x5c, 0x44, 0x92, 0x44, 0x38, 0xe2, 0x38
|
||||
};
|
||||
struct jbg85_enc_state se;
|
||||
int i;
|
||||
|
||||
jbg85_enc_init(&se, 23, 5, output_bie, stdout); /* initialize encoder */
|
||||
jbg85_enc_options(&se, JBG_TPBON, 0, -1); /* clear JBG_VLENGTH option */
|
||||
for (i = 0; i < 5; i++) {
|
||||
/* encode line */
|
||||
jbg85_enc_lineout(&se, bitmap+i*3, bitmap+(i-1)*3, bitmap+(i-2)*3);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
This software produces a 37 byte long BIE. (JBIG is not very good at
|
||||
compressing extremely small images like in this example, because the
|
||||
arithmetic encoder requires some startup data in order to generate
|
||||
reasonable statistics which influence the compression process and
|
||||
because there is some header overhead.)
|
||||
|
||||
|
||||
2.3 More about compression
|
||||
|
||||
If jbg85_enc_lineout() is called directly after jbg85_enc_init(), the
|
||||
following default values are used for various compression parameters:
|
||||
|
||||
- The number of lines per stripe (l0) is set to 128, which is the
|
||||
T.85 BASIC setting.
|
||||
|
||||
- The typical-prediction (TPBON) and variable-length (VLENGTH) options
|
||||
are activated, but the two-line template (LRLTWO) option is not.
|
||||
|
||||
- The maximal horizontal offset of the adaptive template pixel is 127
|
||||
(mx = 127, my = 0).
|
||||
|
||||
In order to change any of these default parameters, an additional
|
||||
function has to be called between jbg85_enc_init() and the first
|
||||
jbg85_enc_lineout():
|
||||
|
||||
void jbg85_enc_options(struct jbg85_enc_state *s, int options,
|
||||
unsigned long l0, int mx)
|
||||
|
||||
The options value can contain the following bits, which activate some
|
||||
of the optional algorithms defined by JBIG:
|
||||
|
||||
JBG_LRLTWO This option bit changes the JBIG algorithm such that the
|
||||
context in which the probability of a pixel is
|
||||
estimated includes only the previous line (two-line
|
||||
template), rather than the previous two lines
|
||||
(three-line template). This option is off by default
|
||||
and the author cannot think of a good reason to set it.
|
||||
[Some people in the JBIG committee seem to have
|
||||
argued that using a two-line template will make
|
||||
software implementations a little bit faster, while
|
||||
others have argued that using only two lines will
|
||||
decrease compression efficiency by around 5%. As you
|
||||
might expect from a committee, now both alternatives
|
||||
are allowed (and add to the implementation and testing
|
||||
complexity of every decoder).]
|
||||
|
||||
JBG_TPBON This bit activates the "typical prediction" algorithm. It
|
||||
is set by default. Typical prediction means that JBIG
|
||||
prefixes each line to be encoded with a "pseudopixel"
|
||||
that indicates if the line is identical to the
|
||||
previous line, and skips encoding the line if it is.
|
||||
This helps to encode empty parts of a page very
|
||||
efficiently in just a few bytes, therefore this
|
||||
option should be left on. (The only reason the author
|
||||
could think of for ever deactivating this option is
|
||||
if you know in advance that there will never be two
|
||||
identical lines follow each other in the image to be
|
||||
encoded, in which case deactivating this option might
|
||||
provide a tiny performance improvement.)
|
||||
|
||||
JBG_VLENGTH This bit indicates that the image height y provided
|
||||
to jbg85_enc_init() was only an estimate and may
|
||||
be lowered sometimes during the encoding process
|
||||
using a call to jbg85_enc_newlen(). This feature
|
||||
is intended for fax machines that start transmitting
|
||||
a page while still scanning it and without knowing
|
||||
how long the page is going to be.
|
||||
|
||||
Value -1 for options keeps the current setting, the default is
|
||||
JBG_TPBON | JBG_VLENGTH.
|
||||
|
||||
The other parameters are:
|
||||
|
||||
l0 Sets the number of lines per stripe (valid range:
|
||||
1 to 2^32-1, default 128, value 0 keeps the current
|
||||
setting).
|
||||
|
||||
mx Changes the maximal offset allowed for the adaptive
|
||||
template pixel (valid range: 0 to 127, default 127,
|
||||
value -1 keeps the current setting).
|
||||
|
||||
If the JBG_VLENGTH option was set, then you can call at any time the
|
||||
function
|
||||
|
||||
void jbg85_enc_newlen(struct jbg85_enc_state *s, unsigned long newlen)
|
||||
|
||||
in order to announce the actual height of the image. You can call this
|
||||
function only once per image, and the provided new height value newlen
|
||||
must not be larger than the estimate y originally provided. It is good
|
||||
practice to call jbg85_enc_newlen() as soon as the height of the image
|
||||
is known. However, it is even possible to call it after the last line
|
||||
has already been encoded using jbg85_enc_lineout(). The latter case
|
||||
will result in a somewhat odd BIE, where an additional empty stripe
|
||||
has to be appended just to announce the new length. This is not pretty
|
||||
and was not described in great detail in the original JBIG1 standard,
|
||||
but decoders are required by ITU-T T.85 to understand even this
|
||||
extremely late announcement of the end of the image.
|
||||
|
||||
If the image height y initially given to jbg85_enc_init() is already
|
||||
the correct final value and you will therefore never call
|
||||
jbg85_enc_newlen(), then it is good practice to clear the JBG_VLENGTH
|
||||
option bit, which is set by default, e.g. by calling
|
||||
|
||||
jbg85_enc_options(&s, JBG_TPBON, 0, -1);
|
||||
|
||||
between jbg85_enc_init() and jbg85_enc_lineout().
|
||||
|
||||
The JBIG standard also has a provision for aborting a BIE with a
|
||||
special abort marker segment, and calling
|
||||
|
||||
void jbg85_enc_abort(struct jbg85_enc_state *s);
|
||||
|
||||
does that. This is probably only needed if there is no other way
|
||||
(e.g., end-of-file) of telling the decoder that no further data bytes
|
||||
will be coming.
|
||||
|
||||
|
||||
3 Decompressing an image
|
||||
|
||||
Like with the compression functions, if you want to use the jbig85.c
|
||||
library, you have to put the line
|
||||
|
||||
#include "jbig85.h"
|
||||
|
||||
into your source code and link your executable with libjbig85.a.
|
||||
|
||||
The state of a JBIG decoder is stored completely in a struct and you
|
||||
will have to define a variable like
|
||||
|
||||
struct jbg85_dec_state s;
|
||||
|
||||
which is initialized by a call to
|
||||
|
||||
void jbg85_dec_init(struct jbg85_dec_state *s,
|
||||
unsigned char *buf, size_t buflen,
|
||||
int (*line_out)(const struct jbg85_dec_state *s,
|
||||
unsigned char *start, size_t len,
|
||||
unsigned long y, void *file),
|
||||
void *file);
|
||||
|
||||
The parameters are:
|
||||
|
||||
buf A memory buffer that is long enough to store up to
|
||||
three lines of the image. This buffer will be used
|
||||
by the decoder to temporarily store decoded lines.
|
||||
If the decoded image uses the LRLTWO option, the buffer
|
||||
has to be only sufficient for two uncompressed
|
||||
image lines.
|
||||
|
||||
buflen The length in bytes of the buffer area to which buf
|
||||
points. Knowing this value prevents accidental buffer
|
||||
overflows and allows the decoder to abort with
|
||||
JBG_ENOMEM if the provided buffer was too small, once
|
||||
it knows the width of the image to be decoded from
|
||||
parsing its 20-byte header. If xmax is the expected
|
||||
maximum width of the image in pixels, then buflen
|
||||
should be at least ((xmax >> 3) + !!(xmax & 7)) * 3
|
||||
bytes. [If only BIEs with option LRLTWO set will be
|
||||
received, then ((xmax >> 3) + !!(xmax & 7)) * 2
|
||||
bytes will be sufficient.]
|
||||
|
||||
line_out This call-back function will be used whenever the decoder
|
||||
has completed another line. The start parameter will
|
||||
point to the location in buf where the len bytes of
|
||||
the just decoded line reside. The line_out() function
|
||||
has to read (and copy or output) this line, but it is
|
||||
not allowed to modify it in-place, as the decoder will
|
||||
also need to access it while decoding the following
|
||||
two lines. The parameter y is just the line number
|
||||
(starting from 0) and file is the jbg85_dec_init()
|
||||
parameter of the same name passed on. The normal
|
||||
return value of line_out is zero; a non-zero value
|
||||
can be returned to request an interrupt of the decoding
|
||||
process (see discussion of JBG_EOK_INTR below).
|
||||
|
||||
file A pointer parameter that is passed on to line_out()
|
||||
and can be used, for instance, to allow line_out() to
|
||||
distinguish by which compression task it has been
|
||||
called in multi-threaded applications.
|
||||
|
||||
After this, you can directly start to pass data from the BIE to the decoder
|
||||
by calling the function
|
||||
|
||||
int jbg85_dec_in(struct jbg85_dec_state *s, unsigned char *data, size_t len,
|
||||
size_t *cnt);
|
||||
|
||||
The pointer data points to the first byte of a data block with length
|
||||
len, which contains bytes from a BIE. It is not necessary to pass a
|
||||
whole BIE at once to jbg85_dec_in(), it can arrive fragmented in any
|
||||
way by calling jbg85_dec_in() several times. Only a single BIE can be
|
||||
delivered via jbg85_dec_in() calls and the decoder has to be
|
||||
reinitialized with jbg85_dec_init() before it is ready to accept
|
||||
another BIE.
|
||||
|
||||
If pointer cnt is not NULL, then the number of bytes actually read
|
||||
from the data block will be stored there. In case the decoder did not
|
||||
recognize the end of the BIE in the data block, then the value
|
||||
JBG_EAGAIN will be returned and *cnt equals len.
|
||||
|
||||
Once the end of a BIE has been reached, the return value of
|
||||
jbg85_dec_in() will be JBG_EOK.
|
||||
|
||||
The decoder can recognize the end of a BIE only if either the VLENGTH
|
||||
option is not set, or if there has been a NEWLEN marker segment before
|
||||
the start of the last stripe. Otherwise, the decoder cannot know
|
||||
whether there is or is not a NEWLEN marker segment following the last
|
||||
stripe. For this reason, jbg85_dec_in() can return JBG_EAGAIN even
|
||||
though you have already given it the last byte of the BIE. In this
|
||||
case, call
|
||||
|
||||
int jbg85_dec_end(struct jbg85_dec_state *s);
|
||||
|
||||
to explicitely signal to the decoder that it has already received all
|
||||
bytes of the BIE. This function will then output any remaining lines
|
||||
and return JBG_EOK if no problem has occurred.
|
||||
|
||||
The macros
|
||||
|
||||
unsigned long jbg85_dec_getwidth(struct jbg85_dec_state *s);
|
||||
unsigned long jbg85_dec_getheight(struct jbg85_dec_state *s);
|
||||
|
||||
can be used to query the dimensions of the image. The width will be
|
||||
known already after the first 20 bytes of the BIE have been provided,
|
||||
and also during the first callback to line_out(). But the height might
|
||||
not have reached its final value before jbg85_dec_in() has returned
|
||||
JBG_EOK. The additional boolean macros
|
||||
|
||||
int jbg85_dec_validwidth(struct jbg85_dec_state *s);
|
||||
int jbg85_dec_finalheight(struct jbg85_dec_state *s);
|
||||
int jbg85_dec_finished(struct jbg85_dec_state *s);
|
||||
|
||||
tell, whether the width and final height are already known, and
|
||||
whether the decoder has finished outputting all lines.
|
||||
|
||||
If one of the callbacks to line_out() provides a non-zero return
|
||||
value, then the decoder will interrupt the decoding process and
|
||||
jbg85_dec_in() or jbg85_dec_end() will return JBG_EOK_INTR. This
|
||||
feature might be useful to stop the decoding process temporarily, e.g.
|
||||
to load a new sheet of paper, where performing this task is
|
||||
inconvenient to complete inside line_out(). It is then possible to
|
||||
continue calling jbg85_dec_in() with the remaining data (or
|
||||
jbg85_dec_end() if there isn't any left) in order to decode the
|
||||
remaining lines of the BIE. After jbg85_dec_in() returned
|
||||
JBG_EOK_INTR, *cnt is probably not equal to len and the remainder of
|
||||
the data block which has not yet been processed by the decoder has to
|
||||
be delivered to jbg85_dec_in() again. Any line that has already been
|
||||
delivered to line_out() will not be delivered again.
|
||||
|
||||
If any other return value than JBG_EOK, JBG_EOK_INTR or JBG_EAGAIN has
|
||||
been returned by jbg85_dec_in() or jbg85_dec_end(), then an error has
|
||||
occurred and the decoding process has been aborted. The function
|
||||
|
||||
const char *jbg85_strerror(int errnum);
|
||||
|
||||
returns a pointer to a short single-line test message that explains
|
||||
the return value of jbg85_dec_in() or jbg85_dec_end(). This message
|
||||
can be used in order to provide the user a brief informative message
|
||||
about what when wrong while decompressing a JBIG image. The po/
|
||||
subdirectory contains *.po files that translate the English ASCII
|
||||
strings returned by jbg85_strerror() into other languages (e.g., for
|
||||
use with GNU gettext). The four least-significant bits of the return
|
||||
value of jbg85_dec_in() or jbg85_dec_end() may contain additional
|
||||
detailed technical information about the exact test that spotted the
|
||||
error condition (see source code for details), i.e. more than the text
|
||||
message returned by jbg85_strerror() reveals. Therefore it may be
|
||||
useful to display the return value itself as a hexadecimal number, in
|
||||
addition to the string returned by jbg85_strerror().
|
||||
|
||||
|
||||
4 Additional notes
|
||||
|
||||
The following remarks will not affect the normal user of the library
|
||||
but might be of interest to some users who have to deal with exotic
|
||||
cases, in particular dealing with broken non-JBIG-KIT encoders out
|
||||
there:
|
||||
|
||||
- There has been one report about malformed BIEs produced by another
|
||||
JBIG implementation that violates the standard by containing
|
||||
several NEWLEN marker segments in the same BIE. The jbig85.c
|
||||
decoder will normally abort with JBG_EINVALID when it encounters
|
||||
such an illegal BIE. The compile-time option
|
||||
JBG85_TOLERATE_MULTIPLE_NEWLEN can be used to make the decoder
|
||||
more tolerant to this type of syntax error.
|
||||
|
||||
- Even though the T.85 standard prescribes all-zero values for the
|
||||
order bits HITOLO, SEQ, ILEAVE, SMID, the jbig85.c decoder will
|
||||
not complain about any other values of these bits, as they do not
|
||||
affect the decoding process when there is only a single plane and
|
||||
resolution layer (the only case supported by this decoder). The
|
||||
compile-time option JBG85_STRICT_ORDER_BITS will make the decoder
|
||||
less tolerant and abort with JBG_EIMPL if the received order bits
|
||||
do not comply with the T.85 "single-progression sequential coding"
|
||||
requirements.
|
||||
|
||||
- The T.85 standard allows only a single ATMOVE marker segment per
|
||||
SDE, and the jbig85.c decoder enforces this limit by default. This
|
||||
limit can be increased by setting JBG85_ATMOVES_MAX in jbig85.h to
|
||||
the desired value. The encoder will never output more than a
|
||||
single ATMOVE marker segment per stripe.
|
||||
|
||||
*** Happy decompressing ***
|
||||
|
||||
[end]
|
||||
417
blender-deps/jbigkit-cmake/libjbig/jbig_ar.c
Normal file
417
blender-deps/jbigkit-cmake/libjbig/jbig_ar.c
Normal file
@@ -0,0 +1,417 @@
|
||||
/*
|
||||
* Arithmetic encoder and decoder of the portable JBIG
|
||||
* compression library
|
||||
*
|
||||
* Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/jbigkit/
|
||||
*
|
||||
* This module implements a portable standard C arithmetic encoder
|
||||
* and decoder used by the JBIG lossless bi-level image compression
|
||||
* algorithm as specified in International Standard ISO 11544:1993
|
||||
* and ITU-T Recommendation T.82.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* If you want to use this program under different license conditions,
|
||||
* then contact the author for an arrangement.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "jbig_ar.h"
|
||||
|
||||
/*
|
||||
* Probability estimation tables for the arithmetic encoder/decoder
|
||||
* given by ITU T.82 Table 24.
|
||||
*/
|
||||
|
||||
static short lsztab[113] = {
|
||||
0x5a1d, 0x2586, 0x1114, 0x080b, 0x03d8, 0x01da, 0x00e5, 0x006f,
|
||||
0x0036, 0x001a, 0x000d, 0x0006, 0x0003, 0x0001, 0x5a7f, 0x3f25,
|
||||
0x2cf2, 0x207c, 0x17b9, 0x1182, 0x0cef, 0x09a1, 0x072f, 0x055c,
|
||||
0x0406, 0x0303, 0x0240, 0x01b1, 0x0144, 0x00f5, 0x00b7, 0x008a,
|
||||
0x0068, 0x004e, 0x003b, 0x002c, 0x5ae1, 0x484c, 0x3a0d, 0x2ef1,
|
||||
0x261f, 0x1f33, 0x19a8, 0x1518, 0x1177, 0x0e74, 0x0bfb, 0x09f8,
|
||||
0x0861, 0x0706, 0x05cd, 0x04de, 0x040f, 0x0363, 0x02d4, 0x025c,
|
||||
0x01f8, 0x01a4, 0x0160, 0x0125, 0x00f6, 0x00cb, 0x00ab, 0x008f,
|
||||
0x5b12, 0x4d04, 0x412c, 0x37d8, 0x2fe8, 0x293c, 0x2379, 0x1edf,
|
||||
0x1aa9, 0x174e, 0x1424, 0x119c, 0x0f6b, 0x0d51, 0x0bb6, 0x0a40,
|
||||
0x5832, 0x4d1c, 0x438e, 0x3bdd, 0x34ee, 0x2eae, 0x299a, 0x2516,
|
||||
0x5570, 0x4ca9, 0x44d9, 0x3e22, 0x3824, 0x32b4, 0x2e17, 0x56a8,
|
||||
0x4f46, 0x47e5, 0x41cf, 0x3c3d, 0x375e, 0x5231, 0x4c0f, 0x4639,
|
||||
0x415e, 0x5627, 0x50e7, 0x4b85, 0x5597, 0x504f, 0x5a10, 0x5522,
|
||||
0x59eb
|
||||
};
|
||||
|
||||
static unsigned char nmpstab[113] = {
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
9, 10, 11, 12, 13, 13, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23, 24,
|
||||
25, 26, 27, 28, 29, 30, 31, 32,
|
||||
33, 34, 35, 9, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48,
|
||||
49, 50, 51, 52, 53, 54, 55, 56,
|
||||
57, 58, 59, 60, 61, 62, 63, 32,
|
||||
65, 66, 67, 68, 69, 70, 71, 72,
|
||||
73, 74, 75, 76, 77, 78, 79, 48,
|
||||
81, 82, 83, 84, 85, 86, 87, 71,
|
||||
89, 90, 91, 92, 93, 94, 86, 96,
|
||||
97, 98, 99, 100, 93, 102, 103, 104,
|
||||
99, 106, 107, 103, 109, 107, 111, 109,
|
||||
111
|
||||
};
|
||||
|
||||
/*
|
||||
* least significant 7 bits (mask 0x7f) of nlpstab[] contain NLPS value,
|
||||
* most significant bit (mask 0x80) contains SWTCH bit
|
||||
*/
|
||||
static unsigned char nlpstab[113] = {
|
||||
129, 14, 16, 18, 20, 23, 25, 28,
|
||||
30, 33, 35, 9, 10, 12, 143, 36,
|
||||
38, 39, 40, 42, 43, 45, 46, 48,
|
||||
49, 51, 52, 54, 56, 57, 59, 60,
|
||||
62, 63, 32, 33, 165, 64, 65, 67,
|
||||
68, 69, 70, 72, 73, 74, 75, 77,
|
||||
78, 79, 48, 50, 50, 51, 52, 53,
|
||||
54, 55, 56, 57, 58, 59, 61, 61,
|
||||
193, 80, 81, 82, 83, 84, 86, 87,
|
||||
87, 72, 72, 74, 74, 75, 77, 77,
|
||||
208, 88, 89, 90, 91, 92, 93, 86,
|
||||
216, 95, 96, 97, 99, 99, 93, 223,
|
||||
101, 102, 103, 104, 99, 105, 106, 107,
|
||||
103, 233, 108, 109, 110, 111, 238, 112,
|
||||
240
|
||||
};
|
||||
|
||||
/*
|
||||
* The next functions implement the arithmedic encoder and decoder
|
||||
* required for JBIG. The same algorithm is also used in the arithmetic
|
||||
* variant of JPEG.
|
||||
*/
|
||||
|
||||
/* marker codes */
|
||||
#define MARKER_STUFF 0x00
|
||||
#define MARKER_ESC 0xff
|
||||
|
||||
void arith_encode_init(struct jbg_arenc_state *s, int reuse_st)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!reuse_st)
|
||||
for (i = 0; i < 4096; s->st[i++] = 0) ;
|
||||
s->c = 0;
|
||||
s->a = 0x10000L;
|
||||
s->sc = 0;
|
||||
s->ct = 11;
|
||||
s->buffer = -1; /* empty */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void arith_encode_flush(struct jbg_arenc_state *s)
|
||||
{
|
||||
unsigned long temp;
|
||||
|
||||
/* find the s->c in the coding interval with the largest
|
||||
* number of trailing zero bits */
|
||||
if ((temp = (s->a - 1 + s->c) & 0xffff0000L) < s->c)
|
||||
s->c = temp + 0x8000;
|
||||
else
|
||||
s->c = temp;
|
||||
/* send remaining bytes to output */
|
||||
s->c <<= s->ct;
|
||||
if (s->c & 0xf8000000L) {
|
||||
/* one final overflow has to be handled */
|
||||
if (s->buffer >= 0) {
|
||||
s->byte_out(s->buffer + 1, s->file);
|
||||
if (s->buffer + 1 == MARKER_ESC)
|
||||
s->byte_out(MARKER_STUFF, s->file);
|
||||
}
|
||||
/* output 0x00 bytes only when more non-0x00 will follow */
|
||||
if (s->c & 0x7fff800L)
|
||||
for (; s->sc; --s->sc)
|
||||
s->byte_out(0x00, s->file);
|
||||
} else {
|
||||
if (s->buffer >= 0)
|
||||
s->byte_out(s->buffer, s->file);
|
||||
/* T.82 figure 30 says buffer+1 for the above line! Typo? */
|
||||
for (; s->sc; --s->sc) {
|
||||
s->byte_out(0xff, s->file);
|
||||
s->byte_out(MARKER_STUFF, s->file);
|
||||
}
|
||||
}
|
||||
/* output final bytes only if they are not 0x00 */
|
||||
if (s->c & 0x7fff800L) {
|
||||
s->byte_out((s->c >> 19) & 0xff, s->file);
|
||||
if (((s->c >> 19) & 0xff) == MARKER_ESC)
|
||||
s->byte_out(MARKER_STUFF, s->file);
|
||||
if (s->c & 0x7f800L) {
|
||||
s->byte_out((s->c >> 11) & 0xff, s->file);
|
||||
if (((s->c >> 11) & 0xff) == MARKER_ESC)
|
||||
s->byte_out(MARKER_STUFF, s->file);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void arith_encode(struct jbg_arenc_state *s, int cx, int pix)
|
||||
{
|
||||
register unsigned lsz, ss;
|
||||
register unsigned char *st;
|
||||
long temp;
|
||||
|
||||
assert(cx >= 0 && cx < 4096);
|
||||
st = s->st + cx;
|
||||
ss = *st & 0x7f;
|
||||
assert(ss < 113);
|
||||
lsz = lsztab[ss];
|
||||
|
||||
#if 0
|
||||
fprintf(stderr, "pix = %d, cx = %d, mps = %d, st = %3d, lsz = 0x%04x, "
|
||||
"a = 0x%05lx, c = 0x%08lx, ct = %2d, buf = 0x%02x\n",
|
||||
pix, cx, !!(s->st[cx] & 0x80), ss, lsz, s->a, s->c, s->ct,
|
||||
s->buffer);
|
||||
#endif
|
||||
|
||||
if (((pix << 7) ^ s->st[cx]) & 0x80) {
|
||||
/* encode the less probable symbol */
|
||||
if ((s->a -= lsz) >= lsz) {
|
||||
/* If the interval size (lsz) for the less probable symbol (LPS)
|
||||
* is larger than the interval size for the MPS, then exchange
|
||||
* the two symbols for coding efficiency, otherwise code the LPS
|
||||
* as usual: */
|
||||
s->c += s->a;
|
||||
s->a = lsz;
|
||||
}
|
||||
/* Check whether MPS/LPS exchange is necessary
|
||||
* and chose next probability estimator status */
|
||||
*st &= 0x80;
|
||||
*st ^= nlpstab[ss];
|
||||
} else {
|
||||
/* encode the more probable symbol */
|
||||
if ((s->a -= lsz) & 0xffff8000L)
|
||||
return; /* A >= 0x8000 -> ready, no renormalization required */
|
||||
if (s->a < lsz) {
|
||||
/* If the interval size (lsz) for the less probable symbol (LPS)
|
||||
* is larger than the interval size for the MPS, then exchange
|
||||
* the two symbols for coding efficiency: */
|
||||
s->c += s->a;
|
||||
s->a = lsz;
|
||||
}
|
||||
/* chose next probability estimator status */
|
||||
*st &= 0x80;
|
||||
*st |= nmpstab[ss];
|
||||
}
|
||||
|
||||
/* renormalization of coding interval */
|
||||
do {
|
||||
s->a <<= 1;
|
||||
s->c <<= 1;
|
||||
--s->ct;
|
||||
if (s->ct == 0) {
|
||||
/* another byte is ready for output */
|
||||
temp = s->c >> 19;
|
||||
if (temp & 0xffffff00L) {
|
||||
/* handle overflow over all buffered 0xff bytes */
|
||||
if (s->buffer >= 0) {
|
||||
++s->buffer;
|
||||
s->byte_out(s->buffer, s->file);
|
||||
if (s->buffer == MARKER_ESC)
|
||||
s->byte_out(MARKER_STUFF, s->file);
|
||||
}
|
||||
for (; s->sc; --s->sc)
|
||||
s->byte_out(0x00, s->file);
|
||||
s->buffer = temp & 0xff; /* new output byte, might overflow later */
|
||||
assert(s->buffer != 0xff);
|
||||
/* can s->buffer really never become 0xff here? */
|
||||
} else if (temp == 0xff) {
|
||||
/* buffer 0xff byte (which might overflow later) */
|
||||
++s->sc;
|
||||
} else {
|
||||
/* output all buffered 0xff bytes, they will not overflow any more */
|
||||
if (s->buffer >= 0)
|
||||
s->byte_out(s->buffer, s->file);
|
||||
for (; s->sc; --s->sc) {
|
||||
s->byte_out(0xff, s->file);
|
||||
s->byte_out(MARKER_STUFF, s->file);
|
||||
}
|
||||
s->buffer = temp; /* buffer new output byte (can still overflow) */
|
||||
}
|
||||
s->c &= 0x7ffffL;
|
||||
s->ct = 8;
|
||||
}
|
||||
} while (s->a < 0x8000);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void arith_decode_init(struct jbg_ardec_state *s, int reuse_st)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!reuse_st)
|
||||
for (i = 0; i < 4096; s->st[i++] = 0) ;
|
||||
s->c = 0;
|
||||
s->a = 1;
|
||||
s->ct = 0;
|
||||
s->startup = 1;
|
||||
s->nopadding = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decode and return one symbol from the provided PSCD byte stream
|
||||
* that starts in s->pscd_ptr and ends in the byte before s->pscd_end.
|
||||
* The context cx is a 12-bit integer in the range 0..4095. This
|
||||
* function will advance s->pscd_ptr each time it has consumed all
|
||||
* information from that PSCD byte.
|
||||
*
|
||||
* If a symbol has been decoded successfully, the return value will be
|
||||
* 0 or 1 (depending on the symbol).
|
||||
*
|
||||
* If the decoder was not able to decode a symbol from the provided
|
||||
* PSCD, then the return value will be -1, and two cases can be
|
||||
* distinguished:
|
||||
*
|
||||
* s->pscd_ptr == s->pscd_end:
|
||||
*
|
||||
* The decoder has used up all information in the provided PSCD
|
||||
* bytes. Further PSCD bytes have to be provided (via new values of
|
||||
* s->pscd_ptr and/or s->pscd_end) before another symbol can be
|
||||
* decoded.
|
||||
*
|
||||
* s->pscd_ptr == s->pscd_end - 1:
|
||||
*
|
||||
* The decoder has used up all provided PSCD bytes except for the
|
||||
* very last byte, because that has the value 0xff. The decoder can
|
||||
* at this point not yet tell whether this 0xff belongs to a
|
||||
* MARKER_STUFF sequence or marks the end of the PSCD. Further PSCD
|
||||
* bytes have to be provided (via new values of s->pscd_ptr and/or
|
||||
* s->pscd_end), including the not yet processed 0xff byte, before
|
||||
* another symbol can be decoded successfully.
|
||||
*
|
||||
* If s->nopadding != 0, the decoder will return -2 when it reaches
|
||||
* the first two bytes of the marker segment that follows (and
|
||||
* terminates) the PSCD, but before decoding the first symbol that
|
||||
* depends on a bit in the input data that could have been the result
|
||||
* of zero padding, and might, therefore, never have been encoded.
|
||||
* This gives the caller the opportunity to lookahead early enough
|
||||
* beyond a terminating SDNORM/SDRST for a trailing NEWLEN (as
|
||||
* required by T.85) before decoding remaining symbols. Call the
|
||||
* decoder again afterwards as often as necessary (leaving s->pscd_ptr
|
||||
* pointing to the start of the marker segment) to retrieve any
|
||||
* required remaining symbols that might depend on padding.
|
||||
*
|
||||
* [Note that each PSCD can be decoded into an infinitely long
|
||||
* sequence of symbols, because the encoder might have truncated away
|
||||
* an arbitrarily long sequence of trailing 0x00 bytes, which the
|
||||
* decoder will append automatically as needed when it reaches the end
|
||||
* of the PSCD. Therefore, the decoder cannot report any end of the
|
||||
* symbol sequence and other means (external to the PSCD and
|
||||
* arithmetic decoding process) are needed to determine that.]
|
||||
*/
|
||||
|
||||
int arith_decode(struct jbg_ardec_state *s, int cx)
|
||||
{
|
||||
register unsigned lsz, ss;
|
||||
register unsigned char *st;
|
||||
int pix;
|
||||
|
||||
/* renormalization */
|
||||
while (s->a < 0x8000 || s->startup) {
|
||||
while (s->ct <= 8 && s->ct >= 0) {
|
||||
/* first we can move a new byte into s->c */
|
||||
if (s->pscd_ptr >= s->pscd_end) {
|
||||
return -1; /* more bytes needed */
|
||||
}
|
||||
if (*s->pscd_ptr == 0xff)
|
||||
if (s->pscd_ptr + 1 >= s->pscd_end) {
|
||||
return -1; /* final 0xff byte not processed */
|
||||
} else {
|
||||
if (*(s->pscd_ptr + 1) == MARKER_STUFF) {
|
||||
s->c |= 0xffL << (8 - s->ct);
|
||||
s->ct += 8;
|
||||
s->pscd_ptr += 2;
|
||||
} else {
|
||||
s->ct = -1; /* start padding with zero bytes */
|
||||
if (s->nopadding) {
|
||||
s->nopadding = 0;
|
||||
return -2; /* subsequent symbols might depend on zero padding */
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
s->c |= (long)*(s->pscd_ptr++) << (8 - s->ct);
|
||||
s->ct += 8;
|
||||
}
|
||||
}
|
||||
s->c <<= 1;
|
||||
s->a <<= 1;
|
||||
if (s->ct >= 0) s->ct--;
|
||||
if (s->a == 0x10000L)
|
||||
s->startup = 0;
|
||||
}
|
||||
|
||||
st = s->st + cx;
|
||||
ss = *st & 0x7f;
|
||||
assert(ss < 113);
|
||||
lsz = lsztab[ss];
|
||||
|
||||
#if 0
|
||||
fprintf(stderr, "cx = %d, mps = %d, st = %3d, lsz = 0x%04x, a = 0x%05lx, "
|
||||
"c = 0x%08lx, ct = %2d\n",
|
||||
cx, !!(s->st[cx] & 0x80), ss, lsz, s->a, s->c, s->ct);
|
||||
#endif
|
||||
|
||||
if ((s->c >> 16) < (s->a -= lsz))
|
||||
if (s->a & 0xffff8000L)
|
||||
return *st >> 7;
|
||||
else {
|
||||
/* MPS_EXCHANGE */
|
||||
if (s->a < lsz) {
|
||||
pix = 1 - (*st >> 7);
|
||||
/* Check whether MPS/LPS exchange is necessary
|
||||
* and chose next probability estimator status */
|
||||
*st &= 0x80;
|
||||
*st ^= nlpstab[ss];
|
||||
} else {
|
||||
pix = *st >> 7;
|
||||
*st &= 0x80;
|
||||
*st |= nmpstab[ss];
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* LPS_EXCHANGE */
|
||||
if (s->a < lsz) {
|
||||
s->c -= s->a << 16;
|
||||
s->a = lsz;
|
||||
pix = *st >> 7;
|
||||
*st &= 0x80;
|
||||
*st |= nmpstab[ss];
|
||||
} else {
|
||||
s->c -= s->a << 16;
|
||||
s->a = lsz;
|
||||
pix = 1 - (*st >> 7);
|
||||
/* Check whether MPS/LPS exchange is necessary
|
||||
* and chose next probability estimator status */
|
||||
*st &= 0x80;
|
||||
*st ^= nlpstab[ss];
|
||||
}
|
||||
}
|
||||
|
||||
return pix;
|
||||
}
|
||||
53
blender-deps/jbigkit-cmake/libjbig/jbig_ar.h
Normal file
53
blender-deps/jbigkit-cmake/libjbig/jbig_ar.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Header file for the arithmetic encoder and decoder of
|
||||
* the portable JBIG compression library
|
||||
*
|
||||
* Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/jbigkit/
|
||||
*/
|
||||
|
||||
#ifndef JBG_AR_H
|
||||
#define JBG_AR_H
|
||||
|
||||
/*
|
||||
* Status of arithmetic encoder
|
||||
*/
|
||||
|
||||
struct jbg_arenc_state {
|
||||
unsigned char st[4096]; /* probability status for contexts, MSB = MPS */
|
||||
unsigned long c; /* register C: base of coding intervall, *
|
||||
* layout as in Table 23 */
|
||||
unsigned long a; /* register A: normalized size of coding interval */
|
||||
long sc; /* number of buffered 0xff values that might still overflow */
|
||||
int ct; /* bit shift counter, determines when next byte will be written */
|
||||
int buffer; /* buffer for most recent output byte != 0xff */
|
||||
void (*byte_out)(int, void *); /* function that receives all PSCD bytes */
|
||||
void *file; /* parameter passed to byte_out */
|
||||
};
|
||||
|
||||
/*
|
||||
* Status of arithmetic decoder
|
||||
*/
|
||||
|
||||
struct jbg_ardec_state {
|
||||
unsigned char st[4096]; /* probability status for contexts, MSB = MPS */
|
||||
unsigned long c; /* register C: base of coding intervall, *
|
||||
* layout as in Table 25 */
|
||||
unsigned long a; /* register A: normalized size of coding interval */
|
||||
unsigned char *pscd_ptr; /* pointer to next PSCD data byte */
|
||||
unsigned char *pscd_end; /* pointer to byte after PSCD */
|
||||
int ct; /* bit-shift counter, determines when next byte will be read;
|
||||
* special value -1 signals that zero-padding has started */
|
||||
int startup; /* boolean flag that controls initial fill of s->c */
|
||||
int nopadding; /* boolean flag that triggers return -2 between
|
||||
* reaching PSCD end and decoding the first symbol
|
||||
* that might never have been encoded in the first
|
||||
* place */
|
||||
};
|
||||
|
||||
void arith_encode_init(struct jbg_arenc_state *s, int reuse_st);
|
||||
void arith_encode_flush(struct jbg_arenc_state *s);
|
||||
void arith_encode(struct jbg_arenc_state *s, int cx, int pix);
|
||||
void arith_decode_init(struct jbg_ardec_state *s, int reuse_st);
|
||||
int arith_decode(struct jbg_ardec_state *s, int cx);
|
||||
|
||||
#endif /* JBG_AR_H */
|
||||
20
blender-deps/jbigkit-cmake/libjbig/po/README.txt
Normal file
20
blender-deps/jbigkit-cmake/libjbig/po/README.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
Older versions of jbig.c contained a list of human-readable
|
||||
result/error messages in both English and German.
|
||||
|
||||
These messages are highly technical and unlikely to be of much use to
|
||||
end users who are not familiar with the JBIG1 standard (which has only
|
||||
been published in English, Spanish and French). Therefore, in the
|
||||
interest of simplicity, since release 2.0 the source code contains in
|
||||
errmsg[] now only the English version of these messages.
|
||||
|
||||
The German version is preserved here in the form of a PO translation
|
||||
file, as used by the GNU gettext package, just in case anyone still
|
||||
finds it of use.
|
||||
|
||||
See http://www.gnu.org/software/gettext/manual/gettext.html for
|
||||
information on the PO file format and tools for creating and using
|
||||
them.
|
||||
|
||||
JBIG-KIT itself does not use gettext, but the included po files might
|
||||
help users of the library to translate the strings returned by
|
||||
jbg_strerror() or jbg85_strerror() into other languages.
|
||||
52
blender-deps/jbigkit-cmake/libjbig/po/de.po
Normal file
52
blender-deps/jbigkit-cmake/libjbig/po/de.po
Normal file
@@ -0,0 +1,52 @@
|
||||
# German translations for jbigkit package
|
||||
# Copyright (C) 2008 Markus Kuhn <http://www.cl.cam.ac.uk/~mgk25/>
|
||||
# This file is distributed under the same license as the jbigkit package.
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: jbigkit 2.0\n"
|
||||
"Report-Msgid-Bugs-To: http://www.cl.cam.ac.uk/~mgk25/jbigkit/\n"
|
||||
"POT-Creation-Date: 2014-03-24 15:35+0000\n"
|
||||
"PO-Revision-Date: 2008-08-27 20:16+0100\n"
|
||||
"Last-Translator: Markus Kuhn <http://www.cl.cam.ac.uk/~mgk25/>\n"
|
||||
"Language: de\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
#: jbig.c:98 jbig85.c:69
|
||||
msgid "All OK"
|
||||
msgstr "Kein Problem"
|
||||
|
||||
#: jbig.c:99 jbig85.c:70
|
||||
msgid "Reached specified image size"
|
||||
msgstr "Angeforderte Bildgröße erreicht"
|
||||
|
||||
#: jbig.c:100 jbig85.c:71
|
||||
msgid "Unexpected end of input data stream"
|
||||
msgstr "Unerwartetes Ende des Eingabedatenstroms"
|
||||
|
||||
#: jbig.c:101 jbig85.c:72
|
||||
msgid "Not enough memory available"
|
||||
msgstr "Nicht genügend Speicher vorhanden"
|
||||
|
||||
#: jbig.c:102 jbig85.c:73
|
||||
msgid "ABORT marker segment encountered"
|
||||
msgstr "Es wurde eine Abbruch-Sequenz gefunden"
|
||||
|
||||
#: jbig.c:103 jbig85.c:74
|
||||
msgid "Unknown marker segment encountered"
|
||||
msgstr "Es wurde eine unbekannte Marker-Sequenz gefunden"
|
||||
|
||||
#: jbig.c:104 jbig85.c:75
|
||||
msgid "Input data stream contains invalid data"
|
||||
msgstr "Es wurden ungültige Daten gefunden"
|
||||
|
||||
#: jbig.c:105 jbig85.c:76
|
||||
msgid "Input data stream uses unimplemented JBIG features"
|
||||
msgstr "Eingabedatenstrom benutzt nicht implementierte JBIG Optionen"
|
||||
|
||||
#: jbig.c:106
|
||||
msgid "Incremental BIE does not continue previous one"
|
||||
msgstr "Neue Bilddaten passen nicht zu vorangegangenen"
|
||||
51
blender-deps/jbigkit-cmake/libjbig/po/pl.po
Normal file
51
blender-deps/jbigkit-cmake/libjbig/po/pl.po
Normal file
@@ -0,0 +1,51 @@
|
||||
# Polish translation for jbigkit.
|
||||
# This file is distributed under the same license as the jbigkit package.
|
||||
# Jakub Bogusz <qboosh@pld-linux.org>, 2010-2014
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: jbigkit 2.0\n"
|
||||
"Report-Msgid-Bugs-To: http://www.cl.cam.ac.uk/~mgk25/jbigkit/\n"
|
||||
"POT-Creation-Date: 2014-03-24 15:35+0000\n"
|
||||
"PO-Revision-Date: 2014-11-16 16:45+0100\n"
|
||||
"Last-Translator: Jakub Bogusz <qboosh@pld-linux.org>\n"
|
||||
"Language-Team: Polish <translation-team-pl@lists.sourceforge.net>\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#: jbig.c:98 jbig85.c:69
|
||||
msgid "All OK"
|
||||
msgstr "Poprawnie"
|
||||
|
||||
#: jbig.c:99 jbig85.c:70
|
||||
msgid "Reached specified image size"
|
||||
msgstr "Osiągnięto określony rozmiar obrazu"
|
||||
|
||||
#: jbig.c:100 jbig85.c:71
|
||||
msgid "Unexpected end of input data stream"
|
||||
msgstr "Nieoczekiwany koniec strumienia danych wejściowych"
|
||||
|
||||
#: jbig.c:101 jbig85.c:72
|
||||
msgid "Not enough memory available"
|
||||
msgstr "Zbyt mało dostępnej pamięci"
|
||||
|
||||
#: jbig.c:102 jbig85.c:73
|
||||
msgid "ABORT marker segment encountered"
|
||||
msgstr "Napotkano segment znacznika ABORT"
|
||||
|
||||
#: jbig.c:103 jbig85.c:74
|
||||
msgid "Unknown marker segment encountered"
|
||||
msgstr "Napotkano segment nieznanego znacznika"
|
||||
|
||||
#: jbig.c:104 jbig85.c:75
|
||||
msgid "Input data stream contains invalid data"
|
||||
msgstr "Strumień danych wejściowych zawiera błędne dane"
|
||||
|
||||
#: jbig.c:105 jbig85.c:76
|
||||
msgid "Input data stream uses unimplemented JBIG features"
|
||||
msgstr "Strumień danych wejściowych korzysta z niezaimplementowanych cech JBIG"
|
||||
|
||||
#: jbig.c:106
|
||||
msgid "Incremental BIE does not continue previous one"
|
||||
msgstr "Przyrostowe dane obrazu nie są kontynuacją poprzednich"
|
||||
53
blender-deps/jbigkit-cmake/libjbig/po/ru.po
Normal file
53
blender-deps/jbigkit-cmake/libjbig/po/ru.po
Normal file
@@ -0,0 +1,53 @@
|
||||
# Russian translations for jbigkit package.
|
||||
# This file is distributed under the same license as the jbigkit package.
|
||||
# Russian translation by ghostmansd@gmil.com,
|
||||
# with some changes by Sergei Skorobogatov.
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: jbigkit 2.1\n"
|
||||
"Report-Msgid-Bugs-To: http://www.cl.cam.ac.uk/~mgk25/jbigkit/\n"
|
||||
"POT-Creation-Date: 2014-03-24 15:35+0000\n"
|
||||
"PO-Revision-Date: 2014-03-21 18:06+0000\n"
|
||||
"Language: ru\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
|
||||
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
|
||||
|
||||
#: jbig.c:98 jbig85.c:69
|
||||
msgid "All OK"
|
||||
msgstr "Успешное завершение"
|
||||
|
||||
#: jbig.c:99 jbig85.c:70
|
||||
msgid "Reached specified image size"
|
||||
msgstr "Указанный размер достигнут"
|
||||
|
||||
#: jbig.c:100 jbig85.c:71
|
||||
msgid "Unexpected end of input data stream"
|
||||
msgstr "Неожиданный конец входного потока"
|
||||
|
||||
#: jbig.c:101 jbig85.c:72
|
||||
msgid "Not enough memory available"
|
||||
msgstr "Недостаточно памяти"
|
||||
|
||||
#: jbig.c:102 jbig85.c:73
|
||||
msgid "ABORT marker segment encountered"
|
||||
msgstr "Обнаружен сегмент прерывания"
|
||||
|
||||
#: jbig.c:103 jbig85.c:74
|
||||
msgid "Unknown marker segment encountered"
|
||||
msgstr "Обнаружен неизвестный сегмент"
|
||||
|
||||
#: jbig.c:104 jbig85.c:75
|
||||
msgid "Input data stream contains invalid data"
|
||||
msgstr "Входной поток содержит неверные данные"
|
||||
|
||||
#: jbig.c:105 jbig85.c:76
|
||||
msgid "Input data stream uses unimplemented JBIG features"
|
||||
msgstr "Входной поток использует нереализованные функции"
|
||||
|
||||
#: jbig.c:106
|
||||
msgid "Incremental BIE does not continue previous one"
|
||||
msgstr "Следующий тип данных BIE не продолжает предыдущий"
|
||||
550
blender-deps/jbigkit-cmake/libjbig/tstcodec.c
Normal file
550
blender-deps/jbigkit-cmake/libjbig/tstcodec.c
Normal file
@@ -0,0 +1,550 @@
|
||||
/*
|
||||
* A sequence of test procedures for this JBIG implementation
|
||||
*
|
||||
* Run this test sequence after each modification on the JBIG library.
|
||||
*
|
||||
* Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jbig.h"
|
||||
|
||||
#define TESTBUF_SIZE 400000L
|
||||
#define TESTPIC_SIZE 477995L
|
||||
|
||||
#define FAILED "F\bFA\bAI\bIL\bLE\bED\bD"
|
||||
#define PASSED "PASSED"
|
||||
|
||||
unsigned char *testbuf;
|
||||
unsigned char *testpic;
|
||||
|
||||
long testbuf_len;
|
||||
|
||||
|
||||
static void *checkedmalloc(size_t n)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if ((p = malloc(n)) == NULL) {
|
||||
fprintf(stderr, "Sorry, not enough memory available!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
static void testbuf_write(int v, void *dummy)
|
||||
{
|
||||
if (testbuf_len < TESTBUF_SIZE)
|
||||
testbuf[testbuf_len++] = v;
|
||||
(void) dummy;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void testbuf_writel(unsigned char *start, size_t len, void *dummy)
|
||||
{
|
||||
if (testbuf_len < TESTBUF_SIZE) {
|
||||
if (testbuf_len + len < TESTBUF_SIZE)
|
||||
memcpy(testbuf + testbuf_len, start, len);
|
||||
else
|
||||
memcpy(testbuf + testbuf_len, start, TESTBUF_SIZE - testbuf_len);
|
||||
}
|
||||
testbuf_len += len;
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
unsigned char *p;
|
||||
unsigned sum = 0;
|
||||
|
||||
for (p = start; p - start < (ptrdiff_t) len; sum = (sum ^ *p++) << 1);
|
||||
printf(" testbuf_writel: %4lu bytes, checksum %04x\n",
|
||||
(unsigned long) len, sum & 0xffff);
|
||||
}
|
||||
#endif
|
||||
|
||||
(void) dummy;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Store the artificial test image defined in T.82, clause 7.2.1 at
|
||||
* pic. The image requires 477995 bytes of memory, is 1960 x 1951 pixels
|
||||
* large and has one plane.
|
||||
*/
|
||||
static void testimage(unsigned char *pic)
|
||||
{
|
||||
unsigned long i, j, sum;
|
||||
unsigned int prsg, repeat[8];
|
||||
unsigned char *p;
|
||||
|
||||
memset(pic, 0, TESTPIC_SIZE);
|
||||
p = pic;
|
||||
prsg = 1;
|
||||
for (j = 0; j < 1951; j++)
|
||||
for (i = 0; i < 1960; i++) {
|
||||
if (j >= 192) {
|
||||
if (j < 1023 || ((i >> 3) & 3) == 0) {
|
||||
sum = (prsg & 1) + ((prsg >> 2) & 1) + ((prsg >> 11) & 1) +
|
||||
((prsg >> 15) & 1);
|
||||
prsg = (prsg << 1) + (sum & 1);
|
||||
if ((prsg & 3) == 0) {
|
||||
*p |= 1 << (7 - (i & 7));
|
||||
repeat[i & 7] = 1;
|
||||
} else {
|
||||
repeat[i & 7] = 0;
|
||||
}
|
||||
} else {
|
||||
if (repeat[i & 7])
|
||||
*p |= 1 << (7 - (i & 7));
|
||||
}
|
||||
}
|
||||
if ((i & 7) == 7) ++p;
|
||||
}
|
||||
|
||||
/* verify test image */
|
||||
sum = 0;
|
||||
for (i = 0; i < TESTPIC_SIZE; i++)
|
||||
for (j = 0; j < 8; j++)
|
||||
sum += (pic[i] >> j) & 1;
|
||||
if (sum != 861965L)
|
||||
printf("WARNING: Artificial test image has %lu (not 861965) "
|
||||
"foreground pixels!\n", sum);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Perform a full test cycle with one set of parameters. Encode an image
|
||||
* and compare the length of the result with correct_length. Then decode
|
||||
* the image again both in one single chunk or byte by byte and compare
|
||||
* the results with the original input image.
|
||||
*/
|
||||
static int test_cycle(unsigned char **orig_image, int width, int height,
|
||||
int options, int order, int layers, int planes,
|
||||
unsigned long l0, int mx, long correct_length,
|
||||
const char *test_id)
|
||||
{
|
||||
struct jbg_enc_state sje;
|
||||
struct jbg_dec_state sjd;
|
||||
int trouble = 0;
|
||||
long l;
|
||||
size_t plane_size;
|
||||
int i, result;
|
||||
unsigned char **image;
|
||||
|
||||
plane_size = ((width + 7) / 8) * height;
|
||||
image = (unsigned char **) checkedmalloc(planes * sizeof(unsigned char *));
|
||||
for (i = 0; i < planes; i++) {
|
||||
image[i] = (unsigned char *) checkedmalloc(plane_size);
|
||||
memcpy(image[i], orig_image[i], plane_size);
|
||||
}
|
||||
|
||||
printf("\nTest %s.1: Encoding ...\n", test_id);
|
||||
testbuf_len = 0;
|
||||
jbg_enc_init(&sje, width, height, planes, image, testbuf_writel, NULL);
|
||||
jbg_enc_layers(&sje, layers);
|
||||
jbg_enc_options(&sje, order, options, l0, mx, 0);
|
||||
jbg_enc_out(&sje);
|
||||
jbg_enc_free(&sje);
|
||||
for (i = 0; i < planes; i++)
|
||||
free(image[i]);
|
||||
free(image);
|
||||
printf("Encoded BIE has %6ld bytes: ", testbuf_len);
|
||||
if (correct_length >= 0)
|
||||
if (testbuf_len == correct_length)
|
||||
puts(PASSED);
|
||||
else {
|
||||
trouble++;
|
||||
printf(FAILED ", correct would have been %ld\n", correct_length);
|
||||
}
|
||||
else
|
||||
puts("");
|
||||
|
||||
printf("Test %s.2: Decoding whole chunk ...\n", test_id);
|
||||
jbg_dec_init(&sjd);
|
||||
result = jbg_dec_in(&sjd, testbuf, testbuf_len, NULL);
|
||||
if (result != JBG_EOK) {
|
||||
printf("Decoder complained with return value %d: " FAILED "\n"
|
||||
"Cause: '%s'\n", result, jbg_strerror(result));
|
||||
trouble++;
|
||||
} else {
|
||||
printf("Image comparison: ");
|
||||
result = 1;
|
||||
for (i = 0; i < planes; i++) {
|
||||
if (memcmp(orig_image[i], sjd.lhp[layers & 1][i],
|
||||
((width + 7) / 8) * height)) {
|
||||
result = 0;
|
||||
trouble++;
|
||||
printf(FAILED " for plane %d\n", i);
|
||||
}
|
||||
}
|
||||
if (result)
|
||||
puts(PASSED);
|
||||
}
|
||||
jbg_dec_free(&sjd);
|
||||
|
||||
printf("Test %s.3: Decoding with single-byte feed ...\n", test_id);
|
||||
jbg_dec_init(&sjd);
|
||||
result = JBG_EAGAIN;
|
||||
for (l = 0; l < testbuf_len; l++) {
|
||||
result = jbg_dec_in(&sjd, testbuf + l, 1, NULL);
|
||||
if (l < testbuf_len - 1 && result != JBG_EAGAIN) {
|
||||
printf("Decoder complained with return value %d at byte %ld: " FAILED
|
||||
"\nCause: '%s'\n", result, l, jbg_strerror(result));
|
||||
trouble++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (l == testbuf_len) {
|
||||
if (result != JBG_EOK) {
|
||||
printf("Decoder complained with return value %d at final byte: " FAILED
|
||||
"\nCause: '%s'\n", result, jbg_strerror(result));
|
||||
trouble++;
|
||||
} else {
|
||||
printf("Image comparison: ");
|
||||
result = 1;
|
||||
for (i = 0; i < planes; i++) {
|
||||
if (memcmp(orig_image[i], sjd.lhp[layers & 1][i],
|
||||
((width + 7) / 8) * height)) {
|
||||
result = 0;
|
||||
trouble++;
|
||||
printf(FAILED " for plane %d\n", i);
|
||||
}
|
||||
}
|
||||
if (result)
|
||||
puts(PASSED);
|
||||
}
|
||||
}
|
||||
|
||||
jbg_dec_free(&sjd);
|
||||
puts("");
|
||||
|
||||
return trouble != 0;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int trouble, problems = 0;
|
||||
struct jbg_arenc_state *se;
|
||||
struct jbg_ardec_state *sd;
|
||||
long i;
|
||||
int pix, order, layers;
|
||||
char test[10];
|
||||
size_t st;
|
||||
unsigned char *pp;
|
||||
unsigned char *ppp[4];
|
||||
|
||||
int t82pix[16] = {
|
||||
0x05e0, 0x0000, 0x8b00, 0x01c4, 0x1700, 0x0034, 0x7fff, 0x1a3f,
|
||||
0x951b, 0x05d8, 0x1d17, 0xe770, 0x0000, 0x0000, 0x0656, 0x0e6a
|
||||
};
|
||||
int t82cx[16] = {
|
||||
0x0fe0, 0x0000, 0x0f00, 0x00f0, 0xff00, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
|
||||
};
|
||||
unsigned char t82sde[32] = {
|
||||
0x69, 0x89, 0x99, 0x5c, 0x32, 0xea, 0xfa, 0xa0,
|
||||
0xd5, 0xff, 0x00, 0x52, 0x7f, 0xff, 0x00, 0xff,
|
||||
0x00, 0xff, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x3f,
|
||||
0xff, 0x00, 0x2d, 0x20, 0x82, 0x91, 0xff, 0x02
|
||||
};
|
||||
|
||||
/* three 23x5 pixel test images with the letters JBIG */
|
||||
unsigned char jbig_normal[15*4] = {
|
||||
0x7c, 0xe2, 0x38, 0x04, 0x92, 0x40, 0x04, 0xe2, 0x5c, 0x44,
|
||||
0x92, 0x44, 0x38, 0xe2, 0x38,
|
||||
0x7c, 0xe2, 0x38, 0x04, 0x92, 0x40, 0x04, 0xe2, 0x5c, 0x44,
|
||||
0x92, 0x44, 0x38, 0xe2, 0x38,
|
||||
0x7c, 0xe2, 0x38, 0x04, 0x92, 0x40, 0x04, 0xe2, 0x5c, 0x44,
|
||||
0x92, 0x44, 0x38, 0xe2, 0x38,
|
||||
0x7c, 0xe2, 0x38, 0x04, 0x92, 0x40, 0x04, 0xe2, 0x5c, 0x44,
|
||||
0x92, 0x44, 0x38, 0xe2, 0x38
|
||||
};
|
||||
unsigned char jbig_upsidedown[15*4] = {
|
||||
0x38, 0xe2, 0x38, 0x44, 0x92, 0x44, 0x04, 0xe2, 0x5c, 0x04,
|
||||
0x92, 0x40, 0x7c, 0xe2, 0x38,
|
||||
0x38, 0xe2, 0x38, 0x44, 0x92, 0x44, 0x04, 0xe2, 0x5c, 0x04,
|
||||
0x92, 0x40, 0x7c, 0xe2, 0x38,
|
||||
0x38, 0xe2, 0x38, 0x44, 0x92, 0x44, 0x04, 0xe2, 0x5c, 0x04,
|
||||
0x92, 0x40, 0x7c, 0xe2, 0x38,
|
||||
0x38, 0xe2, 0x38, 0x44, 0x92, 0x44, 0x04, 0xe2, 0x5c, 0x04,
|
||||
0x92, 0x40, 0x7c, 0xe2, 0x38
|
||||
};
|
||||
unsigned char jbig_inverse[15*4] = {
|
||||
0xff^0x7c, 0xff^0xe2, 0xfe^0x38, 0xff^0x04, 0xff^0x92,
|
||||
0xfe^0x40, 0xff^0x04, 0xff^0xe2, 0xfe^0x5c, 0xff^0x44,
|
||||
0xff^0x92, 0xfe^0x44, 0xff^0x38, 0xff^0xe2, 0xfe^0x38,
|
||||
0xff^0x7c, 0xff^0xe2, 0xfe^0x38, 0xff^0x04, 0xff^0x92,
|
||||
0xfe^0x40, 0xff^0x04, 0xff^0xe2, 0xfe^0x5c, 0xff^0x44,
|
||||
0xff^0x92, 0xfe^0x44, 0xff^0x38, 0xff^0xe2, 0xfe^0x38,
|
||||
0xff^0x7c, 0xff^0xe2, 0xfe^0x38, 0xff^0x04, 0xff^0x92,
|
||||
0xfe^0x40, 0xff^0x04, 0xff^0xe2, 0xfe^0x5c, 0xff^0x44,
|
||||
0xff^0x92, 0xfe^0x44, 0xff^0x38, 0xff^0xe2, 0xfe^0x38,
|
||||
0xff^0x7c, 0xff^0xe2, 0xfe^0x38, 0xff^0x04, 0xff^0x92,
|
||||
0xfe^0x40, 0xff^0x04, 0xff^0xe2, 0xfe^0x5c, 0xff^0x44,
|
||||
0xff^0x92, 0xfe^0x44, 0xff^0x38, 0xff^0xe2, 0xfe^0x38
|
||||
};
|
||||
int orders[] = {
|
||||
0,
|
||||
JBG_ILEAVE,
|
||||
JBG_ILEAVE | JBG_SMID,
|
||||
#if 0
|
||||
JBG_SEQ,
|
||||
JBG_SEQ | JBG_SMID,
|
||||
JBG_SEQ | JBG_ILEAVE,
|
||||
JBG_HITOLO,
|
||||
JBG_HITOLO | JBG_ILEAVE,
|
||||
JBG_HITOLO | JBG_ILEAVE | JBG_SMID,
|
||||
JBG_HITOLO | JBG_SEQ,
|
||||
JBG_HITOLO | JBG_SEQ | JBG_SMID,
|
||||
JBG_HITOLO | JBG_SEQ | JBG_ILEAVE
|
||||
#endif
|
||||
};
|
||||
|
||||
printf("\nAutomatic JBIG Compatibility Test Suite\n"
|
||||
"---------------------------------------\n\n"
|
||||
"JBIG-KIT Version " JBG_VERSION
|
||||
" -- This test may take a few minutes.\n\n\n");
|
||||
|
||||
/* allocate test buffer memory */
|
||||
testbuf = (unsigned char *) checkedmalloc(TESTBUF_SIZE);
|
||||
testpic = (unsigned char *) checkedmalloc(TESTPIC_SIZE);
|
||||
se = (struct jbg_arenc_state *) checkedmalloc(sizeof(struct jbg_arenc_state));
|
||||
sd = (struct jbg_ardec_state *) checkedmalloc(sizeof(struct jbg_ardec_state));
|
||||
|
||||
/* test a few properties of the machine architecture */
|
||||
testbuf[0] = 42;
|
||||
testbuf[0x10000L] = 0x42;
|
||||
st = 1 << 16;
|
||||
testbuf[st]++;
|
||||
pp = testbuf + 0x4000;
|
||||
pp += 0x4000;
|
||||
pp += 0x4000;
|
||||
pp += 0x4000;
|
||||
if (testbuf[0] != 42 || *pp != 0x43) {
|
||||
printf("Porting error detected:\n\n"
|
||||
"Pointer arithmetic with this compiler has not at least 32 bits!\n"
|
||||
"Are you sure, you have not compiled this program on an 8-bit\n"
|
||||
"or 16-bit architecture? This compiler mode can obviously not\n"
|
||||
"handle arrays with a size of more than 65536 bytes. With this\n"
|
||||
"memory model, JBIG-KIT can only handle very small images and\n"
|
||||
"not even this compatibility test suite will run. :-(\n\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* only supported command line option:
|
||||
* output file name for exporting test image */
|
||||
if (argc > 1) {
|
||||
FILE *f;
|
||||
|
||||
puts("Generating test image ...");
|
||||
testimage(testpic);
|
||||
printf("Storing in '%s' ...\n", argv[1]);
|
||||
|
||||
/* write out test image as PBM file */
|
||||
f = fopen(argv[1], "wb");
|
||||
if (!f) abort();
|
||||
fprintf(f, "P4\n");
|
||||
#if 0
|
||||
fprintf(f, "# Test image as defined in ITU-T T.82, clause 7.2.1\n");
|
||||
#endif
|
||||
fprintf(f, "%10lu\n%10lu\n", 1960LU, 1951LU);
|
||||
fwrite(testpic, 1, TESTPIC_SIZE, f);
|
||||
fclose(f);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#if 1
|
||||
puts("1) Arithmetic encoder test sequence from ITU-T T.82, clause 7.1\n"
|
||||
"---------------------------------------------------------------\n");
|
||||
arith_encode_init(se, 0);
|
||||
testbuf_len = 0;
|
||||
se->byte_out = testbuf_write;
|
||||
for (i = 0; i < 16 * 16; i++)
|
||||
arith_encode(se, (t82cx[i >> 4] >> ((15 - i) & 15)) & 1,
|
||||
(t82pix[i >> 4] >> ((15 - i) & 15)) & 1);
|
||||
arith_encode_flush(se);
|
||||
printf("result of encoder:\n ");
|
||||
for (i = 0; i < testbuf_len && i < TESTBUF_SIZE; i++)
|
||||
printf("%02x", testbuf[i]);
|
||||
printf("\nexpected result:\n ");
|
||||
for (i = 0; i < 30; i++)
|
||||
printf("%02x", t82sde[i]);
|
||||
printf("\n\nTest 1: ");
|
||||
if (testbuf_len != 30 || memcmp(testbuf, t82sde, 30)) {
|
||||
problems++;
|
||||
printf(FAILED);
|
||||
} else
|
||||
printf(PASSED);
|
||||
printf("\n\n");
|
||||
|
||||
|
||||
puts("2) Arithmetic decoder test sequence from ITU-T T.82, clause 7.1\n"
|
||||
"---------------------------------------------------------------\n");
|
||||
printf("Test 2.1: Decoding whole chunk ...\n");
|
||||
arith_decode_init(sd, 0);
|
||||
sd->pscd_ptr = t82sde;
|
||||
sd->pscd_end = t82sde + 32;
|
||||
trouble = 0;
|
||||
for (i = 0; i < 16 * 16 && !trouble; i++) {
|
||||
pix = arith_decode(sd, (t82cx[i >> 4] >> ((15 - i) & 15)) & 1);
|
||||
if (pix < 0) {
|
||||
printf("Problem at pixel %ld, byte %ld.\n\n",
|
||||
i+1, (long) (sd->pscd_ptr - sd->pscd_end));
|
||||
trouble++;
|
||||
break;
|
||||
}
|
||||
if (pix != ((t82pix[i >> 4] >> ((15 - i) & 15)) & 1)) {
|
||||
printf("Wrong PIX answer (%d) at pixel %ld.\n\n", pix, i+1);
|
||||
trouble++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!trouble && sd->pscd_ptr != sd->pscd_end - 2) {
|
||||
printf("%ld bytes left after decoder finished.\n\n",
|
||||
(long) (sd->pscd_end - sd->pscd_ptr - 2));
|
||||
trouble++;
|
||||
}
|
||||
printf("Test result: ");
|
||||
if (trouble) {
|
||||
problems++;
|
||||
puts(FAILED);
|
||||
} else
|
||||
puts(PASSED);
|
||||
printf("\n");
|
||||
|
||||
printf("Test 2.2: Decoding with single byte feed ...\n");
|
||||
arith_decode_init(sd, 0);
|
||||
pp = t82sde;
|
||||
sd->pscd_ptr = pp;
|
||||
sd->pscd_end = pp + 1;
|
||||
trouble = 0;
|
||||
for (i = 0; i < 16 * 16 && !trouble; i++) {
|
||||
pix = arith_decode(sd, (t82cx[i >> 4] >> ((15 - i) & 15)) & 1);
|
||||
while (pix < 0 && sd->pscd_end < t82sde + 32) {
|
||||
pp++;
|
||||
if (sd->pscd_ptr != pp - 1)
|
||||
sd->pscd_ptr = pp;
|
||||
sd->pscd_end = pp + 1;
|
||||
pix = arith_decode(sd, (t82cx[i >> 4] >> ((15 - i) & 15)) & 1);
|
||||
}
|
||||
if (pix < 0) {
|
||||
printf("Problem at pixel %ld, byte %ld.\n\n",
|
||||
i+1, (long) (sd->pscd_ptr - sd->pscd_end));
|
||||
trouble++;
|
||||
break;
|
||||
}
|
||||
if (pix != ((t82pix[i >> 4] >> ((15 - i) & 15)) & 1)) {
|
||||
printf("Wrong PIX answer (%d) at pixel %ld.\n\n", pix, i+1);
|
||||
trouble++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!trouble && sd->pscd_ptr != sd->pscd_end - 2) {
|
||||
printf("%ld bytes left after decoder finished.\n\n",
|
||||
(long) (sd->pscd_end - sd->pscd_ptr - 2));
|
||||
trouble++;
|
||||
}
|
||||
printf("Test result: ");
|
||||
if (trouble) {
|
||||
problems++;
|
||||
puts(FAILED);
|
||||
} else
|
||||
puts(PASSED);
|
||||
printf("\n");
|
||||
|
||||
puts("3) Parametric algorithm test sequence from ITU-T T.82, clause 7.2\n"
|
||||
"-----------------------------------------------------------------\n");
|
||||
puts("Generating test image ...");
|
||||
testimage(testpic);
|
||||
putchar('\n');
|
||||
pp = testpic;
|
||||
|
||||
puts("Test 3.1: TPBON=0, Mx=0, LRLTWO=0, L0=1951, 0 layers");
|
||||
problems += test_cycle(&pp, 1960, 1951, JBG_DELAY_AT,
|
||||
0, 0, 1, 1951, 0, 317384L, "3.1");
|
||||
puts("Test 3.2: TPBON=0, Mx=0, LRLTWO=1, L0=1951, 0 layers");
|
||||
problems += test_cycle(&pp, 1960, 1951, JBG_DELAY_AT | JBG_LRLTWO,
|
||||
0, 0, 1, 1951, 0, 317132L, "3.2");
|
||||
puts("Test 3.3: TPBON=1, Mx=8, LRLTWO=0, L0=128, 0 layers");
|
||||
problems += test_cycle(&pp, 1960, 1951, JBG_DELAY_AT | JBG_TPBON,
|
||||
0, 0, 1, 128, 8, 253653L, "3.3");
|
||||
puts("Test 3.4: TPBON=1, DPON=1, TPDON=1, Mx=8, LRLTWO=0, L0=2, 6 layers");
|
||||
problems += test_cycle(&pp, 1960, 1951,
|
||||
JBG_DELAY_AT | JBG_TPBON | JBG_TPDON | JBG_DPON,
|
||||
0, 6, 1, 2, 8, 279314L, "3.4");
|
||||
puts("Test 3.5: as Test 3.4 but with DPPRIV=1");
|
||||
problems += test_cycle(&pp, 1960, 1951,
|
||||
JBG_DELAY_AT | JBG_TPBON | JBG_TPDON | JBG_DPON |
|
||||
JBG_DPPRIV,
|
||||
0, 6, 1, 2, 8, 279314L + 1728, "3.5");
|
||||
#if 0 /* Note: option SEQ is currently not supported by the decoder */
|
||||
puts("Test 3.6: as Test 3.4 but with order bit SEQ set");
|
||||
problems += test_cycle(&pp, 1960, 1951,
|
||||
JBG_DELAY_AT | JBG_TPBON | JBG_TPDON | JBG_DPON,
|
||||
JBG_SEQ, 6, 1, 2, 8, 279314L, "3.6");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
puts("4) Same T.82 tests with SDRST instead of SDNORM\n"
|
||||
"-----------------------------------------------\n");
|
||||
|
||||
puts("Test 4.0: TPBON=1, Mx=8, LRLTWO=0, L0=128, 0 layers");
|
||||
problems += test_cycle(&pp, 1960, 1951, JBG_SDRST | JBG_TPBON,
|
||||
0, 0, 1, 128, 8, -1, "4.0");
|
||||
|
||||
puts("Test 4.1: TPBON=0, Mx=0, LRLTWO=0, L0=1951, 0 layers");
|
||||
problems += test_cycle(&pp, 1960, 1951, JBG_SDRST,
|
||||
0, 0, 1, 1951, 0, -1, "4.1");
|
||||
puts("Test 4.2: TPBON=0, Mx=0, LRLTWO=1, L0=1951, 0 layers");
|
||||
problems += test_cycle(&pp, 1960, 1951, JBG_LRLTWO | JBG_SDRST,
|
||||
0, 0, 1, 1951, 0, -1, "4.2");
|
||||
puts("Test 4.3: TPBON=1, Mx=8, LRLTWO=0, L0=128, 0 layers");
|
||||
problems += test_cycle(&pp, 1960, 1951, JBG_TPBON | JBG_SDRST,
|
||||
0, 0, 1, 128, 8, -1, "4.3");
|
||||
puts("Test 4.4: TPBON=1, DPON=1, TPDON=1, Mx=8, LRLTWO=0, L0=2, 6 layers");
|
||||
problems += test_cycle(&pp, 1960, 1951,
|
||||
JBG_TPBON | JBG_TPDON |
|
||||
JBG_DPON | JBG_SDRST,
|
||||
0, 6, 1, 2, 8, -1, "4.4");
|
||||
|
||||
puts("5) Small test image, 0-3 layers, 4 planes, different orders\n"
|
||||
"-----------------------------------------------------------\n");
|
||||
|
||||
/* test a simple multi-plane image */
|
||||
ppp[0] = jbig_normal;
|
||||
ppp[1] = jbig_upsidedown;
|
||||
ppp[2] = jbig_inverse;
|
||||
ppp[3] = jbig_inverse;
|
||||
|
||||
i = 0;
|
||||
for (layers = 0; layers <= 3; layers++)
|
||||
for (order = 0; order < (int) (sizeof(orders)/sizeof(int)); order++) {
|
||||
sprintf(test, "5.%ld", ++i);
|
||||
printf("Test %s: order=%d, %d layers, 4 planes", test, orders[order],
|
||||
layers);
|
||||
problems += test_cycle(ppp, 23, 5*4, JBG_TPBON | JBG_TPDON | JBG_DPON,
|
||||
orders[order], layers, 4, 2, 8, -1, test);
|
||||
}
|
||||
|
||||
|
||||
printf("\nTest result summary: the library has %s the test suite.\n\n",
|
||||
problems ? FAILED : PASSED);
|
||||
if (problems)
|
||||
puts("This is bad. If you cannot identify the problem yourself, please "
|
||||
"send\nthis output plus a detailed description of your "
|
||||
"compile environment\n(OS, compiler, version, options, etc.) to "
|
||||
"Markus Kuhn\n<http://www.cl.cam.ac.uk/~mgk25/>.");
|
||||
else
|
||||
puts("Congratulations, everything is fine.\n");
|
||||
|
||||
return problems != 0;
|
||||
}
|
||||
450
blender-deps/jbigkit-cmake/libjbig/tstcodec85.c
Normal file
450
blender-deps/jbigkit-cmake/libjbig/tstcodec85.c
Normal file
@@ -0,0 +1,450 @@
|
||||
/*
|
||||
* A sequence of test procedures for this JBIG implementation
|
||||
*
|
||||
* Run this test sequence after each modification on the JBIG library.
|
||||
*
|
||||
* Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "jbig85.h"
|
||||
|
||||
#define TESTBUF_SIZE 400000L
|
||||
#define TESTPIC_SIZE 477995L
|
||||
|
||||
#define FAILED "F\bFA\bAI\bIL\bLE\bED\bD"
|
||||
#define PASSED "PASSED"
|
||||
|
||||
unsigned char *testbuf;
|
||||
unsigned char *testpic;
|
||||
|
||||
long testbuf_len;
|
||||
|
||||
|
||||
static void *checkedmalloc(size_t n)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if ((p = calloc(1, n)) == NULL) {
|
||||
fprintf(stderr, "Sorry, not enough memory available!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
static void testbuf_write(int v, void *dummy)
|
||||
{
|
||||
if (testbuf_len < TESTBUF_SIZE)
|
||||
testbuf[testbuf_len++] = v;
|
||||
(void) dummy;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void testbuf_writel(unsigned char *start, size_t len, void *dummy)
|
||||
{
|
||||
if (testbuf_len < TESTBUF_SIZE) {
|
||||
if (testbuf_len + len < TESTBUF_SIZE)
|
||||
memcpy(testbuf + testbuf_len, start, len);
|
||||
else
|
||||
memcpy(testbuf + testbuf_len, start, TESTBUF_SIZE - testbuf_len);
|
||||
}
|
||||
testbuf_len += len;
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
unsigned char *p;
|
||||
unsigned sum = 0;
|
||||
|
||||
for (p = start; p - start < (ptrdiff_t) len; sum = (sum ^ *p++) << 1);
|
||||
printf(" testbuf_writel: %4lu bytes, checksum %04x\n",
|
||||
(unsigned long) len, sum & 0xffff);
|
||||
}
|
||||
#endif
|
||||
|
||||
(void) dummy;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static int line_out(const struct jbg85_dec_state *s,
|
||||
unsigned char *start, size_t len,
|
||||
unsigned long y, void *bitmap)
|
||||
{
|
||||
assert(jbg85_dec_validwidth(s));
|
||||
assert(len == (jbg85_dec_getwidth(s) >> 3) + !!(jbg85_dec_getwidth(s) & 7));
|
||||
assert(y < jbg85_dec_getheight(s));
|
||||
memcpy((unsigned char *) bitmap + len * y, start, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Store the artificial test image defined in T.82, clause 7.2.1 at
|
||||
* pic. The image requires 477995 bytes of memory, is 1960 x 1951 pixels
|
||||
* large and has one plane.
|
||||
*/
|
||||
static void testimage(unsigned char *pic)
|
||||
{
|
||||
unsigned long i, j, sum;
|
||||
unsigned int prsg, repeat[8];
|
||||
unsigned char *p;
|
||||
|
||||
memset(pic, 0, TESTPIC_SIZE);
|
||||
p = pic;
|
||||
prsg = 1;
|
||||
for (j = 0; j < 1951; j++)
|
||||
for (i = 0; i < 1960; i++) {
|
||||
if (j >= 192) {
|
||||
if (j < 1023 || ((i >> 3) & 3) == 0) {
|
||||
sum = (prsg & 1) + ((prsg >> 2) & 1) + ((prsg >> 11) & 1) +
|
||||
((prsg >> 15) & 1);
|
||||
prsg = (prsg << 1) + (sum & 1);
|
||||
if ((prsg & 3) == 0) {
|
||||
*p |= 1 << (7 - (i & 7));
|
||||
repeat[i & 7] = 1;
|
||||
} else {
|
||||
repeat[i & 7] = 0;
|
||||
}
|
||||
} else {
|
||||
if (repeat[i & 7])
|
||||
*p |= 1 << (7 - (i & 7));
|
||||
}
|
||||
}
|
||||
if ((i & 7) == 7) ++p;
|
||||
}
|
||||
|
||||
/* verify test image */
|
||||
sum = 0;
|
||||
for (i = 0; i < TESTPIC_SIZE; i++)
|
||||
for (j = 0; j < 8; j++)
|
||||
sum += (pic[i] >> j) & 1;
|
||||
if (sum != 861965L)
|
||||
printf("WARNING: Artificial test image has %lu (not 861965) "
|
||||
"foreground pixels!\n", sum);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Perform a full test cycle with one set of parameters. Encode an image
|
||||
* and compare the length of the result with correct_length. Then decode
|
||||
* the image again both in one single chunk or byte by byte and compare
|
||||
* the results with the original input image.
|
||||
*/
|
||||
static int test_cycle(unsigned char *orig_image, int width, int height,
|
||||
int options, unsigned long l0, int mx,
|
||||
long correct_length, const char *test_id)
|
||||
{
|
||||
struct jbg85_enc_state sje;
|
||||
struct jbg85_dec_state sjd;
|
||||
int trouble = 0;
|
||||
long l;
|
||||
size_t plane_size, buffer_len;
|
||||
int i, result;
|
||||
unsigned char *image, *buffer;
|
||||
size_t bpl;
|
||||
size_t cnt;
|
||||
|
||||
bpl = (width + 7) / 8;
|
||||
plane_size = bpl * height;
|
||||
image = (unsigned char *) checkedmalloc(plane_size);
|
||||
memcpy(image, orig_image, plane_size);
|
||||
|
||||
printf("\nTest-85 %s.1: Encoding ...\n", test_id);
|
||||
testbuf_len = 0;
|
||||
jbg85_enc_init(&sje, width, height, testbuf_writel, NULL);
|
||||
jbg85_enc_options(&sje, options, l0, mx);
|
||||
for (i = 0; i < height; i++)
|
||||
jbg85_enc_lineout(&sje,
|
||||
image + i * bpl,
|
||||
image + (i-1) * bpl,
|
||||
image + (i-2) * bpl);
|
||||
free(image);
|
||||
printf("Encoded BIE has %6ld bytes: ", testbuf_len);
|
||||
if (correct_length >= 0)
|
||||
if (testbuf_len == correct_length)
|
||||
puts(PASSED);
|
||||
else {
|
||||
trouble++;
|
||||
printf(FAILED ", correct would have been %ld\n", correct_length);
|
||||
}
|
||||
else
|
||||
puts("");
|
||||
|
||||
#if 1
|
||||
buffer_len = ((width >> 3) + !!(width & 7)) * 3;
|
||||
buffer = (unsigned char *) checkedmalloc(buffer_len);
|
||||
image = (unsigned char *) checkedmalloc(plane_size);
|
||||
printf("Test-85 %s.2: Decoding whole chunk ...\n", test_id);
|
||||
jbg85_dec_init(&sjd, buffer, buffer_len, line_out, image);
|
||||
result = jbg85_dec_in(&sjd, testbuf, testbuf_len, &cnt);
|
||||
if (result != JBG_EOK) {
|
||||
printf("Decoder complained with return value 0x%02x: "
|
||||
FAILED "\nCause: '%s'\n", result, jbg85_strerror(result));
|
||||
printf("%ld bytes of BIE read, %lu lines decoded.\n",
|
||||
(long) cnt, sjd.y);
|
||||
trouble++;
|
||||
} else {
|
||||
printf("Image comparison: ");
|
||||
result = 1;
|
||||
if (memcmp(orig_image, image, plane_size)) {
|
||||
result = 0;
|
||||
trouble++;
|
||||
printf(FAILED);
|
||||
}
|
||||
if (result)
|
||||
puts(PASSED);
|
||||
}
|
||||
free(image);
|
||||
|
||||
image = (unsigned char *) checkedmalloc(plane_size);
|
||||
printf("Test-85 %s.3: Decoding with single-byte feed ...\n", test_id);
|
||||
jbg85_dec_init(&sjd, buffer, buffer_len, line_out, image);
|
||||
result = JBG_EAGAIN;
|
||||
for (l = 0; l < testbuf_len; l++) {
|
||||
result = jbg85_dec_in(&sjd, testbuf + l, 1, NULL);
|
||||
if (l < testbuf_len - 1 && result != JBG_EAGAIN) {
|
||||
printf("Decoder complained with return value 0x%02x at byte %ld: "
|
||||
FAILED "\nCause: '%s'\n", result, l, jbg85_strerror(result));
|
||||
trouble++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (l == testbuf_len) {
|
||||
if (result != JBG_EOK) {
|
||||
printf("Decoder complained with return value 0x%02x at final byte: "
|
||||
FAILED "\nCause: '%s'\n", result, jbg85_strerror(result));
|
||||
trouble++;
|
||||
} else {
|
||||
printf("Image comparison: ");
|
||||
result = 1;
|
||||
if (memcmp(orig_image, image, plane_size)) {
|
||||
result = 0;
|
||||
trouble++;
|
||||
printf(FAILED);
|
||||
}
|
||||
if (result)
|
||||
puts(PASSED);
|
||||
}
|
||||
}
|
||||
free(image);
|
||||
|
||||
#endif
|
||||
puts("");
|
||||
|
||||
return trouble != 0;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int trouble, problems = 0;
|
||||
struct jbg_arenc_state *se;
|
||||
struct jbg_ardec_state *sd;
|
||||
long i;
|
||||
int pix;
|
||||
unsigned char *pp;
|
||||
|
||||
int t82pix[16] = {
|
||||
0x05e0, 0x0000, 0x8b00, 0x01c4, 0x1700, 0x0034, 0x7fff, 0x1a3f,
|
||||
0x951b, 0x05d8, 0x1d17, 0xe770, 0x0000, 0x0000, 0x0656, 0x0e6a
|
||||
};
|
||||
int t82cx[16] = {
|
||||
0x0fe0, 0x0000, 0x0f00, 0x00f0, 0xff00, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
|
||||
};
|
||||
unsigned char t82sde[32] = {
|
||||
0x69, 0x89, 0x99, 0x5c, 0x32, 0xea, 0xfa, 0xa0,
|
||||
0xd5, 0xff, 0x00, 0x52, 0x7f, 0xff, 0x00, 0xff,
|
||||
0x00, 0xff, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x3f,
|
||||
0xff, 0x00, 0x2d, 0x20, 0x82, 0x91, 0xff, 0x02
|
||||
};
|
||||
|
||||
printf("\nAutomatic JBIG Compatibility Test Suite\n"
|
||||
"---------------------------------------\n\n"
|
||||
"JBIG-KIT Version " JBG85_VERSION " (T.85 version)"
|
||||
" -- This test may take a few minutes.\n\n\n");
|
||||
|
||||
/* allocate test buffer memory */
|
||||
testbuf = (unsigned char *) checkedmalloc(TESTBUF_SIZE);
|
||||
testpic = (unsigned char *) checkedmalloc(TESTPIC_SIZE);
|
||||
se = (struct jbg_arenc_state *) checkedmalloc(sizeof(struct jbg_arenc_state));
|
||||
sd = (struct jbg_ardec_state *) checkedmalloc(sizeof(struct jbg_ardec_state));
|
||||
|
||||
/* only supported command line option:
|
||||
* output file name for exporting test image */
|
||||
if (argc > 1) {
|
||||
FILE *f;
|
||||
|
||||
puts("Generating test image ...");
|
||||
testimage(testpic);
|
||||
printf("Storing in '%s' ...\n", argv[1]);
|
||||
|
||||
/* write out test image as PBM file */
|
||||
f = fopen(argv[1], "wb");
|
||||
if (!f) abort();
|
||||
fprintf(f, "P4\n");
|
||||
#if 0
|
||||
fprintf(f, "# Test image as defined in ITU-T T.82, clause 7.2.1\n");
|
||||
#endif
|
||||
fprintf(f, "1960 1951\n");
|
||||
fwrite(testpic, 1, TESTPIC_SIZE, f);
|
||||
fclose(f);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#if 1
|
||||
puts("1) Arithmetic encoder test sequence from ITU-T T.82, clause 7.1\n"
|
||||
"---------------------------------------------------------------\n");
|
||||
arith_encode_init(se, 0);
|
||||
testbuf_len = 0;
|
||||
se->byte_out = testbuf_write;
|
||||
for (i = 0; i < 16 * 16; i++)
|
||||
arith_encode(se, (t82cx[i >> 4] >> ((15 - i) & 15)) & 1,
|
||||
(t82pix[i >> 4] >> ((15 - i) & 15)) & 1);
|
||||
arith_encode_flush(se);
|
||||
printf("result of encoder:\n ");
|
||||
for (i = 0; i < testbuf_len && i < TESTBUF_SIZE; i++)
|
||||
printf("%02x", testbuf[i]);
|
||||
printf("\nexpected result:\n ");
|
||||
for (i = 0; i < 30; i++)
|
||||
printf("%02x", t82sde[i]);
|
||||
printf("\n\nTest 1: ");
|
||||
if (testbuf_len != 30 || memcmp(testbuf, t82sde, 30)) {
|
||||
problems++;
|
||||
printf(FAILED);
|
||||
} else
|
||||
printf(PASSED);
|
||||
printf("\n\n");
|
||||
|
||||
|
||||
puts("2) Arithmetic decoder test sequence from ITU-T T.82, clause 7.1\n"
|
||||
"---------------------------------------------------------------\n");
|
||||
printf("Test 2.1: Decoding whole chunk ...\n");
|
||||
arith_decode_init(sd, 0);
|
||||
sd->pscd_ptr = t82sde;
|
||||
sd->pscd_end = t82sde + 32;
|
||||
trouble = 0;
|
||||
for (i = 0; i < 16 * 16 && !trouble; i++) {
|
||||
pix = arith_decode(sd, (t82cx[i >> 4] >> ((15 - i) & 15)) & 1);
|
||||
if (pix < 0) {
|
||||
printf("Problem at pixel %ld, byte %ld.\n\n",
|
||||
i+1, (long) (sd->pscd_ptr - sd->pscd_end));
|
||||
trouble++;
|
||||
break;
|
||||
}
|
||||
if (pix != ((t82pix[i >> 4] >> ((15 - i) & 15)) & 1)) {
|
||||
printf("Wrong PIX answer (%d) at pixel %ld.\n\n", pix, i+1);
|
||||
trouble++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!trouble && sd->pscd_ptr != sd->pscd_end - 2) {
|
||||
printf("%ld bytes left after decoder finished.\n\n",
|
||||
(long) (sd->pscd_end - sd->pscd_ptr - 2));
|
||||
trouble++;
|
||||
}
|
||||
printf("Test result: ");
|
||||
if (trouble) {
|
||||
problems++;
|
||||
puts(FAILED);
|
||||
} else
|
||||
puts(PASSED);
|
||||
printf("\n");
|
||||
|
||||
printf("Test 2.2: Decoding with single byte feed ...\n");
|
||||
arith_decode_init(sd, 0);
|
||||
pp = t82sde;
|
||||
sd->pscd_ptr = pp;
|
||||
sd->pscd_end = pp + 1;
|
||||
trouble = 0;
|
||||
for (i = 0; i < 16 * 16 && !trouble; i++) {
|
||||
pix = arith_decode(sd, (t82cx[i >> 4] >> ((15 - i) & 15)) & 1);
|
||||
while (pix < 0 && sd->pscd_end < t82sde + 32) {
|
||||
pp++;
|
||||
if (sd->pscd_ptr != pp - 1)
|
||||
sd->pscd_ptr = pp;
|
||||
sd->pscd_end = pp + 1;
|
||||
pix = arith_decode(sd, (t82cx[i >> 4] >> ((15 - i) & 15)) & 1);
|
||||
}
|
||||
if (pix < 0) {
|
||||
printf("Problem at pixel %ld, byte %ld.\n\n",
|
||||
i+1, (long) (sd->pscd_ptr - sd->pscd_end));
|
||||
trouble++;
|
||||
break;
|
||||
}
|
||||
if (pix != ((t82pix[i >> 4] >> ((15 - i) & 15)) & 1)) {
|
||||
printf("Wrong PIX answer (%d) at pixel %ld.\n\n", pix, i+1);
|
||||
trouble++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!trouble && sd->pscd_ptr != sd->pscd_end - 2) {
|
||||
printf("%ld bytes left after decoder finished.\n\n",
|
||||
(long) (sd->pscd_end - sd->pscd_ptr - 2));
|
||||
trouble++;
|
||||
}
|
||||
printf("Test result: ");
|
||||
if (trouble) {
|
||||
problems++;
|
||||
puts(FAILED);
|
||||
} else
|
||||
puts(PASSED);
|
||||
printf("\n");
|
||||
|
||||
puts("3) Parametric algorithm test sequence from ITU-T T.82, clause 7.2\n"
|
||||
"-----------------------------------------------------------------\n");
|
||||
puts("Generating test image ...");
|
||||
testimage(testpic);
|
||||
putchar('\n');
|
||||
|
||||
puts("Test-85 3.1: TPBON=0, Mx=0, LRLTWO=0, L0=1951, 0 layers");
|
||||
problems += test_cycle(testpic, 1960, 1951, 0,
|
||||
1951, 0, 317384L, "3.1");
|
||||
puts("Test-85 3.2: TPBON=0, Mx=0, LRLTWO=1, L0=1951, 0 layers");
|
||||
problems += test_cycle(testpic, 1960, 1951, JBG_LRLTWO,
|
||||
1951, 0, 317132L, "3.2");
|
||||
puts("Test-85 3.3: TPBON=1, Mx=8, LRLTWO=0, L0=128, 0 layers");
|
||||
problems += test_cycle(testpic, 1960, 1951, JBG_TPBON,
|
||||
128, 8, 253653L, "3.3");
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
puts("4) Same T.82 tests with SDRST instead of SDNORM\n"
|
||||
"-----------------------------------------------\n");
|
||||
|
||||
puts("Test-85 4.0: TPBON=1, Mx=8, LRLTWO=0, L0=128, 0 layers");
|
||||
problems += test_cycle(&pp, 1960, 1951, JBG_SDRST | JBG_TPBON,
|
||||
128, 8, -1, "4.0");
|
||||
|
||||
puts("Test-85 4.1: TPBON=0, Mx=0, LRLTWO=0, L0=1951, 0 layers");
|
||||
problems += test_cycle(&pp, 1960, 1951, JBG_SDRST,
|
||||
1951, 0, -1, "4.1");
|
||||
puts("Test-85 4.2: TPBON=0, Mx=0, LRLTWO=1, L0=1951, 0 layers");
|
||||
problems += test_cycle(&pp, 1960, 1951, JBG_LRLTWO | JBG_SDRST,
|
||||
1951, 0, -1, "4.2");
|
||||
puts("Test-85 4.3: TPBON=1, Mx=8, LRLTWO=0, L0=128, 0 layers");
|
||||
problems += test_cycle(&pp, 1960, 1951, JBG_TPBON | JBG_SDRST,
|
||||
128, 8, -1, "4.3");
|
||||
#endif
|
||||
|
||||
printf("\nTest result summary: the T.85 library has %s the test suite.\n\n",
|
||||
problems ? FAILED : PASSED);
|
||||
if (problems)
|
||||
puts("This is bad. If you cannot identify the problem yourself, please "
|
||||
"send\nthis output plus a detailed description of your "
|
||||
"compile environment\n(OS, compiler, version, options, etc.) to "
|
||||
"Markus Kuhn\n<http://www.cl.cam.ac.uk/~mgk25/>.");
|
||||
else
|
||||
puts("Congratulations, everything is fine.\n");
|
||||
|
||||
return problems != 0;
|
||||
}
|
||||
14
blender-deps/jbigkit-cmake/libjbig/tstjoint.c
Normal file
14
blender-deps/jbigkit-cmake/libjbig/tstjoint.c
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* This test file exists to check for any compile-time problems
|
||||
* when linking an application with both jbig.c and jbig85.c simultanenously.
|
||||
*
|
||||
* Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/
|
||||
*/
|
||||
|
||||
#include "jbig.h"
|
||||
#include "jbig85.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user