Author: ghibo Date: Sun Feb 18 17:47:03 2007 New Revision: 122424 Added: packages/cooker/jbigkit/current/SOURCES/jbigkit-1.6.patch Removed: packages/cooker/jbigkit/current/SOURCES/jbigkit-1.6.patch.bz2 Modified: packages/cooker/jbigkit/current/SPECS/jbigkit.spec
Log: - bunzip2 patches. Added: packages/cooker/jbigkit/current/SOURCES/jbigkit-1.6.patch ============================================================================== --- (empty file) +++ packages/cooker/jbigkit/current/SOURCES/jbigkit-1.6.patch Sun Feb 18 17:47:03 2007 @@ -0,0 +1,964 @@ +diff -uNr jbigkit-1.5/CHANGES jbigkit/CHANGES +--- jbigkit-1.5/CHANGES 2003-06-11 18:54:28.000000000 +0200 ++++ jbigkit/CHANGES 2004-06-11 20:04:51.000000000 +0200 +@@ -2,13 +2,27 @@ + JBIG-KIT revision history + ------------------------- + ++Changes in version 1.6 (2004-06-11) ++ ++ - various small changes to reduce the risk of 32-bit unsigned ++ integer overflows when dealing with extremely large images ++ ++ - robuster treatment of L0 = 0xffffffff ++ ++ - minor API modification in jbg_enc_options(): parameter l0 changed ++ from type long to unsigned long; previous value now remains ++ unchanged when l0 == 0 (was: l0 < 0) ++ ++ - lots of type casts added such that the C source code is now ++ also compilable as C++ ++ + Changes in version 1.5 (2003-06-11) + + - fixed two minor memory leaks (special thanks to Davide Pizzolato + <[EMAIL PROTECTED]> for locating one of these) + + - jbgtopbm does not attempt any more to parse multiple concatenated +- BIEs (options -m must be used now to enable this feature explicitely), ++ BIEs (options -m must be used now to enable this feature explicitly), + in order to handle BIEs with data after the last expected SDE gracefully + + - various extensions to improve support of JBIG fax applications +@@ -18,7 +32,7 @@ + to MX=127 in both encoder and decoder + + o encoder now has a hook for producing BIEs with a NEWLEN marker +- segment and VLENGHTH=1, in order to assist in testing decoders ++ segment and VLENGTH=1, in order to assist in testing decoders + for T.85 conformance (see also new pbmtojbg option -Y) + + o a new function jbg_newlen() can be used to scan an +diff -uNr jbigkit-1.5/libjbig/Makefile jbigkit/libjbig/Makefile +--- jbigkit-1.5/libjbig/Makefile 2003-06-11 18:57:56.000000000 +0200 ++++ jbigkit/libjbig/Makefile 2004-06-08 16:40:06.000000000 +0200 +@@ -23,5 +23,8 @@ + test: tstcodec + ./tstcodec + ++t82test.pbm: tstcodec ++ ./tstcodec $@ ++ + clean: +- rm -f *.o *~ core gmon.out dbg_d\=??.pbm tstcodec ++ rm -f *.o *~ core gmon.out dbg_d\=??.pbm tstcodec t82test.pbm +diff -uNr jbigkit-1.5/libjbig/jbig.c jbigkit/libjbig/jbig.c +--- jbigkit-1.5/libjbig/jbig.c 2003-06-11 18:57:18.000000000 +0200 ++++ jbigkit/libjbig/jbig.c 2004-06-11 16:17:29.000000000 +0200 +@@ -3,7 +3,7 @@ + * + * Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/ + * +- * $Id: jbig.c,v 1.19 2003-06-11 17:57:02+01 mgk25 Exp $ ++ * $Id: jbig.c,v 1.22 2004-06-11 15:17:06+01 mgk25 Exp $ + * + * This module implements a portable standard C encoder and decoder + * using the JBIG lossless bi-level image compression algorithm as +@@ -95,7 +95,7 @@ + + const char jbg_version[] = + " JBIG-KIT " JBG_VERSION " -- Markus Kuhn -- " +-"$Id: jbig.c,v 1.19 2003-06-11 17:57:02+01 mgk25 Exp $ "; ++"$Id: jbig.c,v 1.22 2004-06-11 15:17:06+01 mgk25 Exp $ "; + + /* + * the following array specifies for each combination of the 3 +@@ -165,44 +165,67 @@ + * The following three functions are the only places in this code, were + * C library memory management functions are called. The whole JBIG + * library has been designed in order to allow multi-threaded +- * execution. no static or global variables are used, so all fuctions ++ * execution. No static or global variables are used, so all fuctions + * are fully reentrant. However if you want to use this multi-thread + * capability and your malloc, realloc and free are not reentrant, + * then simply add the necessary semaphores or mutex primitives below. ++ * In contrast to C's malloc() and realloc(), but like C's calloc(), ++ * these functions take two parameters nmemb and size that are multiplied ++ * before being passed on to the corresponding C function. ++ * This we can catch all overflows during a size_t multiplication a ++ * a single place. + */ + +-static void *checked_malloc(size_t size) ++#ifndef SIZE_MAX ++#define SIZE_MAX ((size_t) -1) /* largest value of size_t */ ++#endif ++ ++static void *checked_malloc(size_t nmemb, size_t size) + { + void *p; +- +- p = malloc(size); ++ + /* Full manual exception handling is ugly here for performance + * reasons. If an adequate handling of lack of memory is required, +- * then use C++ and throw a C++ exception here. */ ++ * then use C++ and throw a C++ exception instead of abort(). */ ++ ++ /* assert that nmemb * size <= SIZE_MAX */ ++ if (size > SIZE_MAX / nmemb) ++ abort(); ++ ++ p = malloc(nmemb * size); ++ + if (!p) + abort(); + + #if 0 +- fprintf(stderr, "%p = malloc(%ld)\n", p, (long) size); ++ fprintf(stderr, "%p = malloc(%lu * %lu)\n", p, ++ (unsigned long) nmemb, (unsigned long) size); + #endif + + return p; + } + + +-static void *checked_realloc(void *ptr, size_t size) ++static void *checked_realloc(void *ptr, size_t nmemb, size_t size) + { + void *p; + +- p = realloc(ptr, size); + /* Full manual exception handling is ugly here for performance + * reasons. If an adequate handling of lack of memory is required, +- * then use C++ and throw a C++ exception here. */ ++ * then use C++ and throw a C++ exception here instead of abort(). */ ++ ++ /* assert that nmemb * size <= SIZE_MAX */ ++ if (size > SIZE_MAX / nmemb) ++ abort(); ++ ++ p = realloc(ptr, nmemb * size); ++ + if (!p) + abort(); + + #if 0 +- fprintf(stderr, "%p = realloc(%p, %ld)\n", p, ptr, (long) size); ++ fprintf(stderr, "%p = realloc(%p, %lu * %lu)\n", p, ptr, ++ (unsigned long) nmemb, (unsigned long) size); + #endif + + return p; +@@ -535,7 +558,7 @@ + *free_list = new_block->next; + } else { + /* request a new memory block */ +- new_block = (struct jbg_buf *) checked_malloc(sizeof(struct jbg_buf)); ++ new_block = (struct jbg_buf *) checked_malloc(1, sizeof(struct jbg_buf)); + } + new_block->len = 0; + new_block->next = NULL; +@@ -671,7 +694,8 @@ + + + /* +- * Calculate y = ceil(x/2) applied n times. This function is used to ++ * Calculate y = ceil(x/2) applied n times, which is equivalent to ++ * y = ceil(x/(2^n)). This function is used to + * determine the number of pixels per row or column after n resolution + * reductions. E.g. X[d-1] = jbg_ceil_half(X[d], 1) and X[0] = + * jbg_ceil_half(X[d], d) as defined in clause 6.2.3 of T.82. +@@ -680,12 +704,40 @@ + { + unsigned long mask; + ++ assert(n >= 0 && n < 32); + mask = (1UL << n) - 1; /* the lowest n bits are 1 here */ + return (x >> n) + ((mask & x) != 0); + } + + + /* ++ * Set L0 (the number of lines in a stripe at lowest resolution) ++ * to a default value, such that there are about 35 stripes, as ++ * suggested in Annex C of ITU-T T.82, without exceeding the ++ * limit 128/2^D suggested in Annex A. ++ */ ++static void jbg_set_default_l0(struct jbg_enc_state *s) ++{ ++ s->l0 = jbg_ceil_half(s->yd, s->d) / 35; /* 35 stripes/image */ ++ while ((s->l0 << s->d) > 128) /* but <= 128 lines/stripe */ ++ --s->l0; ++ if (s->l0 < 2) s->l0 = 2; ++} ++ ++ ++/* ++ * Calculate the number of stripes, as defined in clause 6.2.3 of T.82. ++ */ ++static unsigned long jbg_stripes(unsigned long l0, unsigned long yd, ++ unsigned long d) ++{ ++ unsigned long y0 = jbg_ceil_half(yd, d); ++ ++ return y0 / l0 + (y0 % l0 != 0); ++} ++ ++ ++/* + * Initialize the status struct for the encoder. + */ + void jbg_enc_init(struct jbg_enc_state *s, unsigned long x, unsigned long y, +@@ -696,7 +748,6 @@ + { + unsigned long l, lx; + int i; +- size_t bufsize; + + extern char jbg_resred[], jbg_dptable[]; + +@@ -712,10 +763,7 @@ + s->d = 0; + s->dl = 0; + s->dh = s->d; +- s->l0 = jbg_ceil_half(s->yd, s->d) / 35; /* 35 stripes/image */ +- while ((s->l0 << s->d) > 128) /* but <= 128 lines/stripe */ +- --s->l0; +- if (s->l0 < 2) s->l0 = 2; ++ jbg_set_default_l0(s); + s->mx = 8; + s->my = 0; + s->order = JBG_ILEAVE | JBG_SMID; +@@ -723,21 +771,22 @@ + s->dppriv = jbg_dptable; + s->res_tab = jbg_resred; + +- s->highres = checked_malloc(planes * sizeof(int)); ++ s->highres = (int *) checked_malloc(planes, sizeof(int)); + s->lhp[0] = p; +- s->lhp[1] = checked_malloc(planes * sizeof(unsigned char *)); +- bufsize = ((jbg_ceil_half(x, 1) + 7) / 8) * jbg_ceil_half(y, 1); ++ s->lhp[1] = (unsigned char **) ++ checked_malloc(planes, sizeof(unsigned char *)); + for (i = 0; i < planes; i++) { + s->highres[i] = 0; +- s->lhp[1][i] = checked_malloc(sizeof(unsigned char) * bufsize); ++ s->lhp[1][i] = (unsigned char *) ++ checked_malloc(jbg_ceil_half(y, 1), jbg_ceil_half(x, 1+3)); + } + + s->free_list = NULL; + s->s = (struct jbg_arenc_state *) +- checked_malloc(s->planes * sizeof(struct jbg_arenc_state)); +- s->tx = (int *) checked_malloc(s->planes * sizeof(int)); ++ checked_malloc(s->planes, sizeof(struct jbg_arenc_state)); ++ s->tx = (int *) checked_malloc(s->planes, sizeof(int)); + lx = jbg_ceil_half(x, 1); +- s->tp = (char *) checked_malloc(lx * sizeof(char)); ++ s->tp = (char *) checked_malloc(lx, sizeof(char)); + for (l = 0; l < lx; s->tp[l++] = 2); + s->sde = NULL; + +@@ -765,12 +814,7 @@ + break; + s->dl = 0; + s->dh = s->d; +- +- s->l0 = jbg_ceil_half(s->yd, s->d) / 35; /* 35 stripes/image */ +- while ((s->l0 << s->d) > 128) /* but <= 128 lines/stripe */ +- --s->l0; +- if (s->l0 < 2) s->l0 = 2; +- ++ jbg_set_default_l0(s); + return s->d; + } + +@@ -782,17 +826,12 @@ + */ + void jbg_enc_layers(struct jbg_enc_state *s, int d) + { +- if (d < 0 || d > 255) ++ if (d < 0 || d > 31) + return; + s->d = d; + s->dl = 0; + s->dh = s->d; +- +- s->l0 = jbg_ceil_half(s->yd, s->d) / 35; /* 35 stripes/image */ +- while ((s->l0 << s->d) > 128) /* but <= 128 lines/stripe */ +- --s->l0; +- if (s->l0 < 2) s->l0 = 2; +- ++ jbg_set_default_l0(s); + return; + } + +@@ -819,11 +858,11 @@ + * the number of layer 0 lines per stripes. + */ + void jbg_enc_options(struct jbg_enc_state *s, int order, int options, +- long l0, int mx, int my) ++ unsigned long l0, int mx, int my) + { + if (order >= 0 && order <= 0x0f) s->order = order; + if (options >= 0) s->options = options; +- if (l0 >= 0) s->l0 = l0; ++ if (l0 > 0) s->l0 = l0; + if (mx >= 0 && my < 128) s->mx = mx; + if (my >= 0 && my < 256) s->my = my; + +@@ -883,8 +922,8 @@ + lx = jbg_ceil_half(hx, 1); + ly = jbg_ceil_half(hy, 1); + /* bytes per line in highres and lowres image */ +- hbpl = (hx + 7) / 8; +- lbpl = (lx + 7) / 8; ++ hbpl = jbg_ceil_half(hx, 3); ++ lbpl = jbg_ceil_half(lx, 3); + /* pointer to first image byte of highres stripe */ + hp = s->lhp[s->highres[plane]][plane] + stripe * hl * hbpl; + lp2 = s->lhp[1 - s->highres[plane]][plane] + stripe * ll * lbpl; +@@ -1454,8 +1493,8 @@ + lx = jbg_ceil_half(hx, 1); + ly = jbg_ceil_half(hy, 1); + /* bytes per line in highres and lowres image */ +- hbpl = (hx + 7) / 8; +- lbpl = (lx + 7) / 8; ++ hbpl = jbg_ceil_half(hx, 3); ++ lbpl = jbg_ceil_half(lx, 3); + /* pointers to first image bytes */ + hp2 = s->lhp[s->highres[plane]][plane]; + hp1 = hp2 + hbpl; +@@ -1484,7 +1523,7 @@ + * 76543210 76543210 76543210 76543210 line_l2 + * X + */ +- ++ + for (i = 0; i < ly; i++) { + if (2*i + 1 >= hy) + hp1 = hp2; +@@ -1492,7 +1531,7 @@ + line_h1 = line_h2 = line_h3 = line_l2 = 0; + for (j = 0; j < lbpl * 8; j += 8) { + *lp = 0; +- line_l2 |= i ? lp[-lbpl] : 0; ++ line_l2 |= i ? *(lp-lbpl) : 0; + for (k = 0; k < 8 && j + k < lx; k += 4) { + if (((j + k) >> 2) < hbpl) { + line_h3 |= i ? *hp3 : 0; +@@ -1704,7 +1743,7 @@ + */ + void jbg_enc_out(struct jbg_enc_state *s) + { +- long bpl; ++ unsigned long bpl; + unsigned char buf[20]; + unsigned long xd, yd, y; + long ii[3], is[3], ie[3]; /* generic variables for the 3 nested loops */ +@@ -1729,6 +1768,9 @@ + if (s->d > 255 || s->d < 0 || s->dh > s->d || s->dh < 0 || + s->dl < 0 || s->dl > s->dh || s->planes < 0 || s->planes > 255) + return; ++ /* prevent uint32 overflow: s->l0 * 2 ^ s->d < 2 ^ 32 */ ++ if (s->d > 31 || (s->d != 0 && s->l0 >= (1UL << (32 - s->d)))) ++ return; + if (s->yd1 < s->yd) + s->yd1 = s->yd; + if (s->yd1 > s->yd) +@@ -1736,33 +1778,13 @@ + + /* ensure correct zero padding of bitmap at the final byte of each line */ + if (s->xd & 7) { +- bpl = (s->xd + 7) / 8; /* bytes per line */ ++ bpl = jbg_ceil_half(s->xd, 3); /* bytes per line */ + for (plane = 0; plane < s->planes; plane++) + for (y = 0; y < s->yd; y++) + s->lhp[0][plane][y * bpl + bpl - 1] &= ~((1 << (8 - (s->xd & 7))) - 1); + } + +- /* calculate number of stripes that will be required */ +- s->stripes = ((s->yd >> s->d) + +- ((((1UL << s->d) - 1) & s->yd) != 0) + s->l0 - 1) / s->l0; +- +- /* allocate buffers for SDE pointers */ +- if (s->sde == NULL) { +- s->sde = (struct jbg_buf ****) +- checked_malloc(s->stripes * sizeof(struct jbg_buf ***)); +- for (stripe = 0; stripe < s->stripes; stripe++) { +- s->sde[stripe] = (struct jbg_buf ***) +- checked_malloc((s->d + 1) * sizeof(struct jbg_buf **)); +- for (layer = 0; layer < s->d + 1; layer++) { +- s->sde[stripe][layer] = (struct jbg_buf **) +- checked_malloc(s->planes * sizeof(struct jbg_buf *)); +- for (plane = 0; plane < s->planes; plane++) +- s->sde[stripe][layer][plane] = SDE_TODO; +- } +- } +- } +- +- /* output BIH */ ++ /* prepare BIH */ + buf[0] = s->dl; + buf[1] = s->dh; + buf[2] = s->planes; +@@ -1785,6 +1807,33 @@ + buf[17] = s->my; + buf[18] = s->order; + buf[19] = s->options & 0x7f; ++ ++#if 0 ++ /* sanitize L0 (if it was set to 0xffffffff for T.85-style NEWLEN tests) */ ++ if (s->l0 > (s->yd >> s->d)) ++ s->l0 = s->yd >> s->d; ++#endif ++ ++ /* calculate number of stripes that will be required */ ++ s->stripes = jbg_stripes(s->l0, s->yd, s->d); ++ ++ /* allocate buffers for SDE pointers */ ++ if (s->sde == NULL) { ++ s->sde = (struct jbg_buf ****) ++ checked_malloc(s->stripes, sizeof(struct jbg_buf ***)); ++ for (stripe = 0; stripe < s->stripes; stripe++) { ++ s->sde[stripe] = (struct jbg_buf ***) ++ checked_malloc(s->d + 1, sizeof(struct jbg_buf **)); ++ for (layer = 0; layer < s->d + 1; layer++) { ++ s->sde[stripe][layer] = (struct jbg_buf **) ++ checked_malloc(s->planes, sizeof(struct jbg_buf *)); ++ for (plane = 0; plane < s->planes; plane++) ++ s->sde[stripe][layer][plane] = SDE_TODO; ++ } ++ } ++ } ++ ++ /* output BIH */ + s->data_out(buf, 20, s->file); + if ((s->options & (JBG_DPON | JBG_DPPRIV | JBG_DPLAST)) == + (JBG_DPON | JBG_DPPRIV)) { +@@ -2017,8 +2066,8 @@ + lx = jbg_ceil_half(hx, 1); + ly = jbg_ceil_half(hy, 1); + /* bytes per line in highres and lowres image */ +- hbpl = (hx + 7) / 8; +- lbpl = (lx + 7) / 8; ++ hbpl = jbg_ceil_half(hx, 3); ++ lbpl = jbg_ceil_half(lx, 3); + /* pointer to highres and lowres image bytes */ + hp = s->lhp[ layer & 1][plane] + (stripe * hl + s->i) * hbpl + + (s->x >> 3); +@@ -2456,7 +2505,6 @@ + int i, j, required_length; + unsigned long x, y; + unsigned long is[3], ie[3]; +- long hsize, lsize; + extern char jbg_dptable[]; + size_t dummy_cnt; + +@@ -2496,17 +2544,24 @@ + s->yd = y; + s->l0 = (((long) s->buffer[12] << 24) | ((long) s->buffer[13] << 16) | + ((long) s->buffer[14] << 8) | (long) s->buffer[15]); +- /* ITU-T T.85 trick currently not yet supported */ ++ /* ITU-T T.85 trick not directly supported by decoder; for full ++ * T.85 compatibility with respect to all NEWLEN marker scenarios, ++ * preprocess BIE with jbg_newlen() before passing it to the decoder. */ + if (s->yd == 0xffffffff) + return JBG_EIMPL; + if (!s->planes || !s->xd || !s->yd || !s->l0) + return JBG_EINVAL; ++ /* prevent uint32 overflow: s->l0 * 2 ^ s->d < 2 ^ 32 */ ++ if (s->d > 31 || (s->d != 0 && s->l0 >= (1UL << (32 - s->d)))) ++ return JBG_EIMPL; + s->mx = s->buffer[16]; + if (s->mx > 127) + return JBG_EINVAL; + s->my = s->buffer[17]; ++#if 0 + if (s->my > 0) + return JBG_EIMPL; ++#endif + s->order = s->buffer[18]; + if (iindex[s->order & 7][0] < 0) + return JBG_EINVAL; +@@ -2516,49 +2571,54 @@ + s->options = s->buffer[19]; + + /* calculate number of stripes that will be required */ +- s->stripes = ((s->yd >> s->d) + +- ((((1UL << s->d) - 1) & s->yd) != 0) + s->l0 - 1) / s->l0; +- ++ s->stripes = jbg_stripes(s->l0, s->yd, s->d); ++ + /* some initialization */ + s->ii[iindex[s->order & 7][STRIPE]] = 0; + s->ii[iindex[s->order & 7][LAYER]] = s->dl; + s->ii[iindex[s->order & 7][PLANE]] = 0; +- /* bytes required for resolution layer D and D-1 */ +- hsize = ((s->xd + 7) / 8) * s->yd; +- lsize = ((jbg_ceil_half(s->xd, 1) + 7) / 8) * +- jbg_ceil_half(s->yd, 1); + if (s->dl == 0) { +- s->s = checked_malloc(s->planes * sizeof(struct jbg_ardec_state *)); +- s->tx = checked_malloc(s->planes * sizeof(int *)); +- s->ty = checked_malloc(s->planes * sizeof(int *)); +- s->reset = checked_malloc(s->planes * sizeof(int *)); +- s->lntp = checked_malloc(s->planes * sizeof(int *)); +- s->lhp[0] = checked_malloc(s->planes * sizeof(unsigned char *)); +- s->lhp[1] = checked_malloc(s->planes * sizeof(unsigned char *)); ++ s->s = (struct jbg_ardec_state **) ++ checked_malloc(s->planes, sizeof(struct jbg_ardec_state *)); ++ s->tx = (int **) checked_malloc(s->planes, sizeof(int *)); ++ s->ty = (int **) checked_malloc(s->planes, sizeof(int *)); ++ s->reset = (int **) checked_malloc(s->planes, sizeof(int *)); ++ s->lntp = (int **) checked_malloc(s->planes, sizeof(int *)); ++ s->lhp[0] = (unsigned char **) ++ checked_malloc(s->planes, sizeof(unsigned char *)); ++ s->lhp[1] = (unsigned char **) ++ checked_malloc(s->planes, sizeof(unsigned char *)); + for (i = 0; i < s->planes; i++) { +- s->s[i] = checked_malloc((s->d - s->dl + 1) * +- sizeof(struct jbg_ardec_state)); +- s->tx[i] = checked_malloc((s->d - s->dl + 1) * sizeof(int)); +- s->ty[i] = checked_malloc((s->d - s->dl + 1) * sizeof(int)); +- s->reset[i] = checked_malloc((s->d - s->dl + 1) * sizeof(int)); +- s->lntp[i] = checked_malloc((s->d - s->dl + 1) * sizeof(int)); +- s->lhp[s->d &1][i] = checked_malloc(sizeof(unsigned char) * hsize); +- s->lhp[(s->d-1)&1][i] = checked_malloc(sizeof(unsigned char) * lsize); ++ s->s[i] = (struct jbg_ardec_state *) ++ checked_malloc(s->d - s->dl + 1, sizeof(struct jbg_ardec_state)); ++ s->tx[i] = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int)); ++ s->ty[i] = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int)); ++ s->reset[i] = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int)); ++ s->lntp[i] = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int)); ++ s->lhp[ s->d & 1][i] = (unsigned char *) ++ checked_malloc(s->yd, jbg_ceil_half(s->xd, 3)); ++ s->lhp[(s->d-1) & 1][i] = (unsigned char *) ++ checked_malloc(jbg_ceil_half(s->yd, 1), jbg_ceil_half(s->xd, 1+3)); + } + } else { + for (i = 0; i < s->planes; i++) { +- s->s[i] = checked_realloc(s->s[i], (s->d - s->dl + 1) * +- sizeof(struct jbg_ardec_state)); +- s->tx[i] = checked_realloc(s->tx[i], (s->d - s->dl + 1) * sizeof(int)); +- s->ty[i] = checked_realloc(s->ty[i], (s->d - s->dl + 1) * sizeof(int)); +- s->reset[i] = checked_realloc(s->reset[i], +- (s->d - s->dl +1) * sizeof(int)); +- s->lntp[i] = checked_realloc(s->lntp[i], +- (s->d - s->dl +1) * sizeof(int)); +- s->lhp[s->d &1][i] = checked_realloc(s->lhp[s->d & 1][i], +- sizeof(unsigned char) * hsize); +- s->lhp[(s->d-1)&1][i] = checked_realloc(s->lhp[(s->d-1)&1][i], +- sizeof(unsigned char) * lsize); ++ s->s[i] = (struct jbg_ardec_state *) ++ checked_realloc(s->s[i], s->d - s->dl + 1, ++ sizeof(struct jbg_ardec_state)); ++ s->tx[i] = (int *) checked_realloc(s->tx[i], ++ s->d - s->dl + 1, sizeof(int)); ++ s->ty[i] = (int *) checked_realloc(s->ty[i], ++ s->d - s->dl + 1, sizeof(int)); ++ s->reset[i] = (int *) checked_realloc(s->reset[i], ++ s->d - s->dl + 1, sizeof(int)); ++ s->lntp[i] = (int *) checked_realloc(s->lntp[i], ++ s->d - s->dl + 1, sizeof(int)); ++ s->lhp[ s->d & 1][i] = (unsigned char *) ++ checked_realloc(s->lhp[ s->d & 1][i], ++ s->yd, jbg_ceil_half(s->xd, 3)); ++ s->lhp[(s->d-1) & 1][i] = (unsigned char *) ++ checked_realloc(s->lhp[(s->d-1) & 1][i], ++ jbg_ceil_half(s->yd, 1), jbg_ceil_half(s->xd, 1+3)); + } + } + for (i = 0; i < s->planes; i++) +@@ -2584,7 +2644,7 @@ + if (s->bie_len < 20 + 1728) + return JBG_EAGAIN; + if (!s->dppriv || s->dppriv == jbg_dptable) +- s->dppriv = checked_malloc(sizeof(char) * 1728); ++ s->dppriv = (char *) checked_malloc(1728, sizeof(char)); + jbg_dppriv2int(s->dppriv, s->buffer); + } + +@@ -2651,6 +2711,8 @@ + s->at_ty[s->at_moves] > (int) s->my || + (s->at_ty[s->at_moves] == 0 && s->at_tx[s->at_moves] < 0)) + return JBG_EINVAL; ++ if (s->at_ty[s->at_moves] != 0) ++ return JBG_EIMPL; + s->at_moves++; + } else + return JBG_EIMPL; +@@ -2662,9 +2724,7 @@ + return JBG_EINVAL; + s->yd = y; + /* calculate again number of stripes that will be required */ +- s->stripes = +- ((s->yd >> s->d) + +- ((((1UL << s->d) - 1) & s->yd) != 0) + s->l0 - 1) / s->l0; ++ s->stripes = jbg_stripes(s->l0, s->yd, s->d); + break; + case MARKER_ABORT: + return JBG_EABORT; +@@ -2833,11 +2893,11 @@ + return -1; + else + return +- ((jbg_ceil_half(s->xd, s->d - (s->ii[0] - 1)) + 7) / 8) * ++ jbg_ceil_half(s->xd, s->d - (s->ii[0] - 1) + 3) * + jbg_ceil_half(s->yd, s->d - (s->ii[0] - 1)); + } + +- return ((s->xd + 7) / 8) * s->yd; ++ return jbg_ceil_half(s->xd, 3) * s->yd; + } + + +@@ -2916,10 +2976,10 @@ + const unsigned char *src, unsigned char **dest, + int use_graycode) + { +- unsigned bpl = (x + 7) / 8; /* bytes per line in dest plane */ +- unsigned i, k = 8; ++ unsigned long bpl = jbg_ceil_half(x, 3); /* bytes per line in dest plane */ ++ unsigned long line, i; ++ unsigned k = 8; + int p; +- unsigned long line; + unsigned prev; /* previous *src byte shifted by 8 bit to the left */ + register int bits, msb = has_planes - 1; + int bitno; +@@ -2977,9 +3037,9 @@ + void *file), void *file) + { + #define BUFLEN 4096 +- int bpp, bpl; +- unsigned long line; +- unsigned i, k = 8; ++ int bpp; ++ unsigned long bpl, line, i; ++ unsigned k = 8; + int p; + unsigned char buf[BUFLEN]; + unsigned char *bp = buf; +@@ -2995,7 +3055,7 @@ + if (x <= 0 || y <= 0) + return; + bpp = (s->planes + 7) / 8; /* bytes per pixel in dest image */ +- bpl = (x + 7) / 8; /* bytes per line in src plane */ ++ bpl = jbg_ceil_half(x, 3); /* bytes per line in src plane */ + + if (iindex[s->order & 7][LAYER] == 0) + if (s->ii[0] < 1) +@@ -3054,7 +3114,7 @@ + len -= 2; + if (len < 2) return NULL; + } +- pp = memchr(p, MARKER_ESC, len - 1); ++ pp = (unsigned char *) memchr(p, MARKER_ESC, len - 1); + if (!pp) return NULL; + l = pp - p; + assert(l < len); +diff -uNr jbigkit-1.5/libjbig/jbig.doc jbigkit/libjbig/jbig.doc +--- jbigkit-1.5/libjbig/jbig.doc 2003-06-11 18:52:55.000000000 +0200 ++++ jbigkit/libjbig/jbig.doc 2004-06-10 22:53:11.000000000 +0200 +@@ -2,7 +2,7 @@ + Using the JBIG-KIT library + -------------------------- + +-Markus Kuhn -- 2003-06-11 ++Markus Kuhn -- 2004-06-10 + + + This text explains how to use the functions provided by the JBIG-KIT +@@ -532,8 +532,8 @@ + 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, l0, mx or my is negative, +-then the corresponding current value remains unmodified. ++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, +@@ -714,6 +714,8 @@ + - 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. +@@ -730,7 +732,7 @@ + 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 explicitely suggests the use of this ++ 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. + +diff -uNr jbigkit-1.5/libjbig/jbig.h jbigkit/libjbig/jbig.h +--- jbigkit-1.5/libjbig/jbig.h 2003-06-11 18:57:19.000000000 +0200 ++++ jbigkit/libjbig/jbig.h 2004-06-11 16:18:45.000000000 +0200 +@@ -105,6 +105,14 @@ + * Status description of an arithmetic decoder + */ + ++enum jbg_ardec_result { ++ JBG_OK, /* symbol has been successfully decoded */ ++ JBG_READY, /* no more bytes of this PSCD required, marker * ++ * encountered, probably more symbols available */ ++ JBG_MORE, /* more PSCD data bytes required to decode a symbol */ ++ JBG_MARKER /* more PSCD data bytes required, ignored final 0xff byte */ ++}; ++ + struct jbg_ardec_state { + unsigned char st[4096]; /* probability status for contexts, MSB = MPS */ + unsigned long c; /* C register, base of coding intervall, * +@@ -113,13 +121,7 @@ + int ct; /* bit shift counter, determines when next byte will be read */ + unsigned char *pscd_ptr; /* pointer to next PSCD data byte */ + unsigned char *pscd_end; /* pointer to byte after PSCD */ +- enum { +- JBG_OK, /* symbol has been successfully decoded */ +- JBG_READY, /* no more bytes of this PSCD required, marker * +- * encountered, probably more symbols available */ +- JBG_MORE, /* more PSCD data bytes required to decode a symbol */ +- JBG_MARKER /* more PSCD data bytes required, ignored final 0xff byte */ +- } result; /* result of previous decode call */ ++ enum jbg_ardec_result result; /* result of previous decode call */ + int startup; /* controls initial fill of s->c */ + }; + +@@ -238,7 +240,7 @@ + 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, +- long l0, int mx, int my); ++ 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); + +diff -uNr jbigkit-1.5/libjbig/tstcodec.c jbigkit/libjbig/tstcodec.c +--- jbigkit-1.5/libjbig/tstcodec.c 2003-06-06 23:03:17.000000000 +0200 ++++ jbigkit/libjbig/tstcodec.c 2004-06-11 16:17:27.000000000 +0200 +@@ -5,7 +5,7 @@ + * + * Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/ + * +- * $Id: tstcodec.c,v 1.10 2003-06-06 22:03:17+01 mgk25 Exp $ ++ * $Id: tstcodec.c,v 1.14 2004-06-11 15:17:06+01 mgk25 Exp $ + */ + + #include <stdio.h> +@@ -117,25 +117,7 @@ + if (sum != 861965L) + printf("WARNING: Artificial test image has %lu (not 861965) " + "foreground pixels!\n", sum); +- +-#if 0 +- { +- FILE *f; +- + +- for (i = 0; i < TESTPIC_SIZE; i++) { +- sum = 0; +- for (j = 0; j < 8; j++) +- sum |= ((pic[i] >> j) & 1) << (7-j); +- pic[i] = sum; +- } +- +- f = fopen("t82demo.lit", "wb"); +- fwrite(pic, 1, TESTPIC_SIZE, f); +- fclose(f); +- } +-#endif +- + return; + } + +@@ -148,7 +130,7 @@ + */ + static int test_cycle(unsigned char **orig_image, int width, int height, + int options, int order, int layers, int planes, +- int l0, int mx, long correct_length, ++ unsigned long l0, int mx, long correct_length, + const char *test_id) + { + struct jbg_enc_state sje; +@@ -160,9 +142,9 @@ + unsigned char **image; + + plane_size = ((width + 7) / 8) * height; +- image = checkedmalloc(planes * sizeof(unsigned char *)); ++ image = (unsigned char **) checkedmalloc(planes * sizeof(unsigned char *)); + for (i = 0; i < planes; i++) { +- image[i] = checkedmalloc(plane_size); ++ image[i] = (unsigned char *) checkedmalloc(plane_size); + memcpy(image[i], orig_image[i], plane_size); + } + +@@ -250,7 +232,7 @@ + } + + +-int main(void) ++int main(int argc, char **argv) + { + int trouble, problems = 0; + struct jbg_arenc_state *se; +@@ -335,10 +317,10 @@ + " -- This test will take a few minutes.\n\n\n"); + + /* allocate test buffer memory */ +- testbuf = checkedmalloc(TESTBUF_SIZE); +- testpic = checkedmalloc(TESTPIC_SIZE); +- se = checkedmalloc(sizeof(struct jbg_arenc_state)); +- sd = checkedmalloc(sizeof(struct jbg_ardec_state)); ++ 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; +@@ -360,6 +342,28 @@ + 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, "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"); +diff -uNr jbigkit-1.5/pbmtools/jbgtopbm.c jbigkit/pbmtools/jbgtopbm.c +--- jbigkit-1.5/pbmtools/jbgtopbm.c 2003-06-11 18:56:24.000000000 +0200 ++++ jbigkit/pbmtools/jbgtopbm.c 2004-06-11 16:17:57.000000000 +0200 +@@ -3,7 +3,7 @@ + * + * Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/jbigkit/ + * +- * $Id: jbgtopbm.c,v 1.10 2003-06-11 17:56:19+01 mgk25 Exp $ ++ * $Id: jbgtopbm.c,v 1.11 2004-06-11 15:17:49+01 mgk25 Exp $ + */ + + #include <stdio.h> +@@ -53,7 +53,7 @@ + if (*buflen == 0) { + *buflen = 4000; + *len = 0; +- *buf = malloc(*buflen); ++ *buf = (unsigned char *) malloc(*buflen); + if (!*buf) { + fprintf(stderr, "Sorry, not enough memory available!\n"); + exit(1); +@@ -63,7 +63,7 @@ + *len += fread(*buf + *len, 1, *buflen - *len, f); + if (*len == *buflen) { + *buflen *= 2; +- *buf = realloc(*buf, *buflen); ++ *buf = (unsigned char *) realloc(*buf, *buflen); + if (!*buf) { + fprintf(stderr, "Sorry, not enough memory available!\n"); + exit(1); +@@ -75,7 +75,7 @@ + } + } while (!feof(f)); + *buflen = *len; +- *buf = realloc(*buf, *buflen); ++ *buf = (unsigned char *) realloc(*buf, *buflen); + if (!*buf) { + fprintf(stderr, "Oops, realloc failed when shrinking buffer!\n"); + exit(1); +@@ -236,7 +236,7 @@ + int plane = -1, use_graycode = 1, diagnose = 0, multi = 0; + + buflen = 8000; +- buffer = malloc(buflen); ++ buffer = (unsigned char *) malloc(buflen); + if (!buffer) { + printf("Sorry, not enough memory available!\n"); + exit(1); +diff -uNr jbigkit-1.5/pbmtools/pbmtojbg.c jbigkit/pbmtools/pbmtojbg.c +--- jbigkit-1.5/pbmtools/pbmtojbg.c 2003-06-11 18:56:25.000000000 +0200 ++++ jbigkit/pbmtools/pbmtojbg.c 2004-06-11 16:17:59.000000000 +0200 +@@ -3,7 +3,7 @@ + * + * Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/jbigkit/ + * +- * $Id: pbmtojbg.c,v 1.10 2003-06-11 17:56:19+01 mgk25 Exp $ ++ * $Id: pbmtojbg.c,v 1.12 2004-06-11 15:17:49+01 mgk25 Exp $ + */ + + #include <stdio.h> +@@ -117,8 +117,8 @@ + struct jbg_enc_state s; + int verbose = 0, delay_at = 0, use_graycode = 1; + long mwidth = 640, mheight = 480; +- int dl = -1, dh = -1, d = -1, l0 = -1, mx = -1; +- unsigned long y1 = 0; ++ int dl = -1, dh = -1, d = -1, mx = -1; ++ unsigned long l0 = 0, y1 = 0; + int options = JBG_TPDON | JBG_TPBON | JBG_DPON; + int order = JBG_ILEAVE | JBG_SMID; + +@@ -193,7 +193,7 @@ + case 's': + if (++i >= argc) usage(); + j = -1; +- l0 = atoi(argv[i]); ++ l0 = atol(argv[i]); + break; + case 't': + if (++i >= argc) usage(); +@@ -285,7 +285,7 @@ + case '2': + case '5': + /* PGM */ +- image = checkedmalloc(width * height * bpp); ++ image = (unsigned char *) checkedmalloc(width * height * bpp); + if (type == '2') { + for (x = 0; x < width * height; x++) { + v = getint(fin); +@@ -359,14 +359,14 @@ + if (verbose) { + fprintf(stderr, "Information about the created JBIG bi-level image entity " + "(BIE):\n\n"); +- fprintf(stderr, " input image size: %ld x %ld pixel\n", ++ fprintf(stderr, " input image size: %lu x %lu pixel\n", + s.xd, s.yd); + fprintf(stderr, " bit planes: %d\n", s.planes); + if (s.planes > 1) + fprintf(stderr, " encoding: %s code, MSB first\n", + use_graycode ? "Gray" : "binary"); +- fprintf(stderr, " stripes: %ld\n", s.stripes); +- fprintf(stderr, " lines per stripe in layer 0: %ld\n", s.l0); ++ fprintf(stderr, " stripes: %lu\n", s.stripes); ++ fprintf(stderr, " lines per stripe in layer 0: %lu\n", s.l0); + fprintf(stderr, " total number of diff. layers: %d\n", s.d); + fprintf(stderr, " lowest layer in BIE: %d\n", s.dl); + fprintf(stderr, " highest layer in BIE: %d\n", s.dh); Modified: packages/cooker/jbigkit/current/SPECS/jbigkit.spec ============================================================================== --- packages/cooker/jbigkit/current/SPECS/jbigkit.spec (original) +++ packages/cooker/jbigkit/current/SPECS/jbigkit.spec Sun Feb 18 17:47:03 2007 @@ -1,14 +1,14 @@ %define name jbigkit %define version 1.5 -%define release 4mdk +%define rel 5 Name: %{name} Summary: The JBIG Kit Version: %{version} -Release: %{release} +Release: %mkrel %{rel} License: GPL Source0: http://www.cl.cam.ac.uk/~mgk25/download/jbigkit-1.5.tar.bz2 -Patch0: jbigkit-1.6.patch.bz2 +Patch0: jbigkit-1.6.patch URL: http://www.cl.cam.ac.uk/~mgk25 Group: Graphics BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
