SOURCES: libjpeg-arith.patch (NEW) - arithmetic encoding support f...
qboosh
qboosh at pld-linux.org
Sun Jan 27 21:21:06 CET 2008
Author: qboosh Date: Sun Jan 27 20:21:06 2008 GMT
Module: SOURCES Tag: HEAD
---- Log message:
- arithmetic encoding support from sylvana.net
---- Files affected:
SOURCES:
libjpeg-arith.patch (NONE -> 1.1) (NEW)
---- Diffs:
================================================================
Index: SOURCES/libjpeg-arith.patch
diff -u /dev/null SOURCES/libjpeg-arith.patch:1.1
--- /dev/null Sun Jan 27 21:21:06 2008
+++ SOURCES/libjpeg-arith.patch Sun Jan 27 21:21:01 2008
@@ -0,0 +1,2255 @@
+diff -Nur jpeg-6b.orig/jaricom.c jpeg-6b/jaricom.c
+--- jpeg-6b.orig/jaricom.c 1970-01-01 01:00:00.000000000 +0100
++++ jpeg-6b/jaricom.c 1997-08-10 18:40:45.000000000 +0200
+@@ -0,0 +1,149 @@
++/*
++ * jaricom.c
++ *
++ * Copyright (C) 1997, Guido Vollbeding <guivol at esc.de>.
++ * This file is NOT part of the Independent JPEG Group's software
++ * for legal reasons.
++ * See the accompanying README file for conditions of distribution and use.
++ *
++ * This file contains probability estimation tables for common use in
++ * arithmetic entropy encoding and decoding routines.
++ *
++ * This data represents Table D.2 in the JPEG spec (ISO/IEC IS 10918-1
++ * and CCITT Recommendation ITU-T T.81) and Table 24 in the JBIG spec
++ * (ISO/IEC IS 11544 and CCITT Recommendation ITU-T T.82).
++ */
++
++#define JPEG_INTERNALS
++#include "jinclude.h"
++#include "jpeglib.h"
++
++/* The following #define specifies the packing of the four components
++ * into the compact INT32 representation.
++ * Note that this formula must match the actual arithmetic encoder
++ * and decoder implementation. The implementation has to be changed
++ * if this formula is changed.
++ * The current organisation is leaned on Markus Kuhn's JBIG
++ * implementation (jbig_tab.c).
++ */
++
++#define V(a,b,c,d) (((INT32)a << 16) | ((INT32)c << 8) | ((INT32)d << 7) | b)
++
++const INT32 jaritab[113] = {
++/*
++ * Index, Qe_Value, Next_Index_LPS, Next_Index_MPS, Switch_MPS
++ */
++/* 0 */ V( 0x5a1d, 1, 1, 1 ),
++/* 1 */ V( 0x2586, 14, 2, 0 ),
++/* 2 */ V( 0x1114, 16, 3, 0 ),
++/* 3 */ V( 0x080b, 18, 4, 0 ),
++/* 4 */ V( 0x03d8, 20, 5, 0 ),
++/* 5 */ V( 0x01da, 23, 6, 0 ),
++/* 6 */ V( 0x00e5, 25, 7, 0 ),
++/* 7 */ V( 0x006f, 28, 8, 0 ),
++/* 8 */ V( 0x0036, 30, 9, 0 ),
++/* 9 */ V( 0x001a, 33, 10, 0 ),
++/* 10 */ V( 0x000d, 35, 11, 0 ),
++/* 11 */ V( 0x0006, 9, 12, 0 ),
++/* 12 */ V( 0x0003, 10, 13, 0 ),
++/* 13 */ V( 0x0001, 12, 13, 0 ),
++/* 14 */ V( 0x5a7f, 15, 15, 1 ),
++/* 15 */ V( 0x3f25, 36, 16, 0 ),
++/* 16 */ V( 0x2cf2, 38, 17, 0 ),
++/* 17 */ V( 0x207c, 39, 18, 0 ),
++/* 18 */ V( 0x17b9, 40, 19, 0 ),
++/* 19 */ V( 0x1182, 42, 20, 0 ),
++/* 20 */ V( 0x0cef, 43, 21, 0 ),
++/* 21 */ V( 0x09a1, 45, 22, 0 ),
++/* 22 */ V( 0x072f, 46, 23, 0 ),
++/* 23 */ V( 0x055c, 48, 24, 0 ),
++/* 24 */ V( 0x0406, 49, 25, 0 ),
++/* 25 */ V( 0x0303, 51, 26, 0 ),
++/* 26 */ V( 0x0240, 52, 27, 0 ),
++/* 27 */ V( 0x01b1, 54, 28, 0 ),
++/* 28 */ V( 0x0144, 56, 29, 0 ),
++/* 29 */ V( 0x00f5, 57, 30, 0 ),
++/* 30 */ V( 0x00b7, 59, 31, 0 ),
++/* 31 */ V( 0x008a, 60, 32, 0 ),
++/* 32 */ V( 0x0068, 62, 33, 0 ),
++/* 33 */ V( 0x004e, 63, 34, 0 ),
++/* 34 */ V( 0x003b, 32, 35, 0 ),
++/* 35 */ V( 0x002c, 33, 9, 0 ),
++/* 36 */ V( 0x5ae1, 37, 37, 1 ),
++/* 37 */ V( 0x484c, 64, 38, 0 ),
++/* 38 */ V( 0x3a0d, 65, 39, 0 ),
++/* 39 */ V( 0x2ef1, 67, 40, 0 ),
++/* 40 */ V( 0x261f, 68, 41, 0 ),
++/* 41 */ V( 0x1f33, 69, 42, 0 ),
++/* 42 */ V( 0x19a8, 70, 43, 0 ),
++/* 43 */ V( 0x1518, 72, 44, 0 ),
++/* 44 */ V( 0x1177, 73, 45, 0 ),
++/* 45 */ V( 0x0e74, 74, 46, 0 ),
++/* 46 */ V( 0x0bfb, 75, 47, 0 ),
++/* 47 */ V( 0x09f8, 77, 48, 0 ),
++/* 48 */ V( 0x0861, 78, 49, 0 ),
++/* 49 */ V( 0x0706, 79, 50, 0 ),
++/* 50 */ V( 0x05cd, 48, 51, 0 ),
++/* 51 */ V( 0x04de, 50, 52, 0 ),
++/* 52 */ V( 0x040f, 50, 53, 0 ),
++/* 53 */ V( 0x0363, 51, 54, 0 ),
++/* 54 */ V( 0x02d4, 52, 55, 0 ),
++/* 55 */ V( 0x025c, 53, 56, 0 ),
++/* 56 */ V( 0x01f8, 54, 57, 0 ),
++/* 57 */ V( 0x01a4, 55, 58, 0 ),
++/* 58 */ V( 0x0160, 56, 59, 0 ),
++/* 59 */ V( 0x0125, 57, 60, 0 ),
++/* 60 */ V( 0x00f6, 58, 61, 0 ),
++/* 61 */ V( 0x00cb, 59, 62, 0 ),
++/* 62 */ V( 0x00ab, 61, 63, 0 ),
++/* 63 */ V( 0x008f, 61, 32, 0 ),
++/* 64 */ V( 0x5b12, 65, 65, 1 ),
++/* 65 */ V( 0x4d04, 80, 66, 0 ),
++/* 66 */ V( 0x412c, 81, 67, 0 ),
++/* 67 */ V( 0x37d8, 82, 68, 0 ),
++/* 68 */ V( 0x2fe8, 83, 69, 0 ),
++/* 69 */ V( 0x293c, 84, 70, 0 ),
++/* 70 */ V( 0x2379, 86, 71, 0 ),
++/* 71 */ V( 0x1edf, 87, 72, 0 ),
++/* 72 */ V( 0x1aa9, 87, 73, 0 ),
++/* 73 */ V( 0x174e, 72, 74, 0 ),
++/* 74 */ V( 0x1424, 72, 75, 0 ),
++/* 75 */ V( 0x119c, 74, 76, 0 ),
++/* 76 */ V( 0x0f6b, 74, 77, 0 ),
++/* 77 */ V( 0x0d51, 75, 78, 0 ),
++/* 78 */ V( 0x0bb6, 77, 79, 0 ),
++/* 79 */ V( 0x0a40, 77, 48, 0 ),
++/* 80 */ V( 0x5832, 80, 81, 1 ),
++/* 81 */ V( 0x4d1c, 88, 82, 0 ),
++/* 82 */ V( 0x438e, 89, 83, 0 ),
++/* 83 */ V( 0x3bdd, 90, 84, 0 ),
++/* 84 */ V( 0x34ee, 91, 85, 0 ),
++/* 85 */ V( 0x2eae, 92, 86, 0 ),
++/* 86 */ V( 0x299a, 93, 87, 0 ),
++/* 87 */ V( 0x2516, 86, 71, 0 ),
++/* 88 */ V( 0x5570, 88, 89, 1 ),
++/* 89 */ V( 0x4ca9, 95, 90, 0 ),
++/* 90 */ V( 0x44d9, 96, 91, 0 ),
++/* 91 */ V( 0x3e22, 97, 92, 0 ),
++/* 92 */ V( 0x3824, 99, 93, 0 ),
++/* 93 */ V( 0x32b4, 99, 94, 0 ),
++/* 94 */ V( 0x2e17, 93, 86, 0 ),
++/* 95 */ V( 0x56a8, 95, 96, 1 ),
++/* 96 */ V( 0x4f46, 101, 97, 0 ),
++/* 97 */ V( 0x47e5, 102, 98, 0 ),
++/* 98 */ V( 0x41cf, 103, 99, 0 ),
++/* 99 */ V( 0x3c3d, 104, 100, 0 ),
++/* 100 */ V( 0x375e, 99, 93, 0 ),
++/* 101 */ V( 0x5231, 105, 102, 0 ),
++/* 102 */ V( 0x4c0f, 106, 103, 0 ),
++/* 103 */ V( 0x4639, 107, 104, 0 ),
++/* 104 */ V( 0x415e, 103, 99, 0 ),
++/* 105 */ V( 0x5627, 105, 106, 1 ),
++/* 106 */ V( 0x50e7, 108, 107, 0 ),
++/* 107 */ V( 0x4b85, 109, 103, 0 ),
++/* 108 */ V( 0x5597, 110, 109, 0 ),
++/* 109 */ V( 0x504f, 111, 107, 0 ),
++/* 110 */ V( 0x5a10, 110, 111, 1 ),
++/* 111 */ V( 0x5522, 112, 109, 0 ),
++/* 112 */ V( 0x59eb, 112, 111, 1 )
++};
+diff -Nur jpeg-6b.orig/jcarith.c jpeg-6b/jcarith.c
+--- jpeg-6b.orig/jcarith.c 1970-01-01 01:00:00.000000000 +0100
++++ jpeg-6b/jcarith.c 1997-08-10 18:40:45.000000000 +0200
+@@ -0,0 +1,922 @@
++/*
++ * jcarith.c
++ *
++ * Copyright (C) 1997, Guido Vollbeding <guivol at esc.de>.
++ * This file is NOT part of the Independent JPEG Group's software
++ * for legal reasons.
++ * See the accompanying README file for conditions of distribution and use.
++ *
++ * This file contains portable arithmetic entropy encoding routines for JPEG
++ * (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81).
++ *
++ * Both sequential and progressive modes are supported in this single module.
++ *
++ * Suspension is not currently supported in this module.
++ */
++
++#define JPEG_INTERNALS
++#include "jinclude.h"
++#include "jpeglib.h"
++
++
++/* Expanded entropy encoder object for arithmetic encoding. */
++
++typedef struct {
++ struct jpeg_entropy_encoder pub; /* public fields */
++
++ INT32 c; /* C register, base of coding interval, layout as in sec. D.1.3 */
++ INT32 a; /* A register, normalized size of coding interval */
++ INT32 sc; /* counter for stacked 0xFF values which might overflow */
++ INT32 zc; /* counter for pending 0x00 output values which might *
++ * be discarded at the end ("Pacman" termination) */
++ int ct; /* bit shift counter, determines when next byte will be written */
++ int buffer; /* buffer for most recent output byte != 0xFF */
++
++ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
++ int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */
++
++ unsigned int restarts_to_go; /* MCUs left in this restart interval */
++ int next_restart_num; /* next restart number to write (0-7) */
++
++ /* Pointers to statistics areas (these workspaces have image lifespan) */
++ unsigned char * dc_stats[NUM_ARITH_TBLS];
++ unsigned char * ac_stats[NUM_ARITH_TBLS];
++} arith_entropy_encoder;
++
++typedef arith_entropy_encoder * arith_entropy_ptr;
++
++/* The following two definitions specify the allocation chunk size
++ * for the statistics area.
++ * According to sections F.1.4.4.1.3 and F.1.4.4.2, we need at least
++ * 49 statistics bins for DC, and 245 statistics bins for AC coding.
++ * Note that we use one additional AC bin for codings with fixed
++ * probability (0.5), thus the minimum number for AC is 246.
++ *
++ * We use a compact representation with 1 byte per statistics bin,
++ * thus the numbers directly represent byte sizes.
++ * This 1 byte per statistics bin contains the meaning of the MPS
++ * (more probable symbol) in the highest bit (mask 0x80), and the
++ * index into the probability estimation state machine table
++ * in the lower bits (mask 0x7F).
++ */
++
++#define DC_STAT_BINS 64
++#define AC_STAT_BINS 256
++
++/* NOTE: Uncomment the following #define if you want to use the
++ * given formula for calculating the AC conditioning parameter Kx
++ * for spectral selection progressive coding in section G.1.3.2
++ * of the spec (Kx = Kmin + SRL (8 + Se - Kmin) 4).
++ * Although the spec and P&M authors claim that this "has proven
++ * to give good results for 8 bit precision samples", I'm not
++ * convinced yet that this is really beneficial.
++ * Early tests gave only very marginal compression enhancements
++ * (a few - around 5 or so - bytes even for very large files),
++ * which would turn out rather negative if we'd suppress the
++ * DAC (Define Arithmetic Conditioning) marker segments for
++ * the default parameters in the future.
++ * Note that currently the marker writing module emits 12-byte
++ * DAC segments for a full-component scan in a color image.
++ * This is not worth worrying about IMHO. However, since the
++ * spec defines the default values to be used if the tables
++ * are omitted (unlike Huffman tables, which are required
++ * anyway), one might optimize this behaviour in the future,
++ * and then it would be disadvantageous to use custom tables if
++ * they don't provide sufficient gain to exceed the DAC size.
++ *
++ * On the other hand, I'd consider it as a reasonable result
++ * that the conditioning has no significant influence on the
++ * compression performance. This means that the basic
++ * statistical model is already rather stable.
++ *
++ * Thus, at the moment, we use the default conditioning values
++ * anyway, and do not use the custom formula.
++ *
++#define CALCULATE_SPECTRAL_CONDITIONING
++ */
++
++/* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int rather than INT32.
++ * We assume that int right shift is unsigned if INT32 right shift is,
++ * which should be safe.
++ */
++
++#ifdef RIGHT_SHIFT_IS_UNSIGNED
++#define ISHIFT_TEMPS int ishift_temp;
++#define IRIGHT_SHIFT(x,shft) \
++ ((ishift_temp = (x)) < 0 ? \
++ (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
++ (ishift_temp >> (shft)))
++#else
++#define ISHIFT_TEMPS
++#define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
++#endif
++
++
++LOCAL(void)
++emit_byte (int val, j_compress_ptr cinfo)
++/* Write next output byte; we do not support suspension in this module. */
++{
++ struct jpeg_destination_mgr * dest = cinfo->dest;
++
++ *dest->next_output_byte++ = (JOCTET) val;
++ if (--dest->free_in_buffer == 0)
++ if (! (*dest->empty_output_buffer) (cinfo))
++ ERREXIT(cinfo, JERR_CANT_SUSPEND);
++}
++
++
++/*
++ * Finish up at the end of an arithmetic-compressed scan.
++ */
++
++METHODDEF(void)
++finish_pass (j_compress_ptr cinfo)
++{
++ arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy;
++ INT32 temp;
++
++ /* Section D.1.8: Termination of encoding */
++
++ /* Find the e->c in the coding interval with the largest
++ * number of trailing zero bits */
++ if ((temp = (e->a - 1 + e->c) & 0xFFFF0000L) < e->c)
++ e->c = temp + 0x8000L;
++ else
++ e->c = temp;
++ /* Send remaining bytes to output */
++ e->c <<= e->ct;
++ if (e->c & 0xF8000000L) {
++ /* One final overflow has to be handled */
++ if (e->buffer >= 0) {
++ if (e->zc)
++ do emit_byte(0x00, cinfo);
++ while (--e->zc);
++ emit_byte(e->buffer + 1, cinfo);
++ if (e->buffer + 1 == 0xFF)
++ emit_byte(0x00, cinfo);
++ }
++ e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */
++ e->sc = 0;
++ } else {
++ if (e->buffer == 0)
++ ++e->zc;
++ else if (e->buffer >= 0) {
++ if (e->zc)
++ do emit_byte(0x00, cinfo);
++ while (--e->zc);
++ emit_byte(e->buffer, cinfo);
++ }
++ if (e->sc) {
++ if (e->zc)
++ do emit_byte(0x00, cinfo);
++ while (--e->zc);
++ do {
++ emit_byte(0xFF, cinfo);
++ emit_byte(0x00, cinfo);
++ } while (--e->sc);
++ }
++ }
++ /* Output final bytes only if they are not 0x00 */
++ if (e->c & 0x7FFF800L) {
++ if (e->zc) /* output final pending zero bytes */
++ do emit_byte(0x00, cinfo);
++ while (--e->zc);
++ emit_byte((e->c >> 19) & 0xFF, cinfo);
++ if (((e->c >> 19) & 0xFF) == 0xFF)
++ emit_byte(0x00, cinfo);
++ if (e->c & 0x7F800L) {
++ emit_byte((e->c >> 11) & 0xFF, cinfo);
++ if (((e->c >> 11) & 0xFF) == 0xFF)
++ emit_byte(0x00, cinfo);
++ }
++ }
++}
++
++
++/*
++ * The core arithmetic encoding routine (common in JPEG and JBIG).
++ * This needs to go as fast as possible.
++ * Machine-dependent optimization facilities
++ * are not utilized in this portable implementation.
++ * However, this code should be fairly efficient and
++ * may be a good base for further optimizations anyway.
++ *
++ * Parameter 'val' to be encoded may be 0 or 1 (binary decision).
++ *
++ * Note: I've added full "Pacman" termination support to the
++ * byte output routines, which is equivalent to the optional
++ * Discard_final_zeros procedure (Figure D.15) in the spec.
++ * Thus, we always produce the shortest possible output
++ * stream compliant to the spec (no trailing zero bytes,
++ * except for FF stuffing).
++ *
++ * I've also introduced a new scheme for accessing
++ * the probability estimation state machine table,
++ * derived from Markus Kuhn's JBIG implementation.
++ */
++
++LOCAL(void)
++arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
++{
++ extern const INT32 jaritab[];
++ register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy;
++ register unsigned char nl, nm;
++ register INT32 qe, temp;
++ register int sv;
++
++ /* Fetch values from our compact representation of Table D.2:
++ * Qe values and probability estimation state machine
++ */
++ sv = *st;
++ qe = jaritab[sv & 0x7F]; /* => Qe_Value */
++ nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */
++ nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */
++
++ /* Encode & estimation procedures per sections D.1.4 & D.1.5 */
++ e->a -= qe;
++ if (val != (sv >> 7)) {
++ /* Encode the less probable symbol */
++ if (e->a >= qe) {
++ /* If the interval size (qe) 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: */
++ e->c += e->a;
++ e->a = qe;
++ }
++ *st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */
++ } else {
++ /* Encode the more probable symbol */
++ if (e->a >= 0x8000L)
++ return; /* A >= 0x8000 -> ready, no renormalization required */
++ if (e->a < qe) {
++ /* If the interval size (qe) for the less probable symbol (LPS)
++ * is larger than the interval size for the MPS, then exchange
++ * the two symbols for coding efficiency: */
++ e->c += e->a;
++ e->a = qe;
++ }
++ *st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */
++ }
++
++ /* Renormalization & data output per section D.1.6 */
++ do {
++ e->a <<= 1;
++ e->c <<= 1;
++ if (--e->ct == 0) {
++ /* Another byte is ready for output */
++ temp = e->c >> 19;
++ if (temp > 0xFF) {
++ /* Handle overflow over all stacked 0xFF bytes */
++ if (e->buffer >= 0) {
++ if (e->zc)
++ do emit_byte(0x00, cinfo);
++ while (--e->zc);
++ emit_byte(e->buffer + 1, cinfo);
++ if (e->buffer + 1 == 0xFF)
++ emit_byte(0x00, cinfo);
++ }
++ e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */
++ e->sc = 0;
++ /* Note: The 3 spacer bits in the C register guarantee
++ * that the new buffer byte can't be 0xFF here
++ * (see page 160 in the P&M JPEG book). */
++ e->buffer = temp & 0xFF; /* new output byte, might overflow later */
++ } else if (temp == 0xFF) {
++ ++e->sc; /* stack 0xFF byte (which might overflow later) */
++ } else {
++ /* Output all stacked 0xFF bytes, they will not overflow any more */
++ if (e->buffer == 0)
++ ++e->zc;
++ else if (e->buffer >= 0) {
++ if (e->zc)
++ do emit_byte(0x00, cinfo);
++ while (--e->zc);
++ emit_byte(e->buffer, cinfo);
++ }
++ if (e->sc) {
++ if (e->zc)
++ do emit_byte(0x00, cinfo);
++ while (--e->zc);
++ do {
++ emit_byte(0xFF, cinfo);
++ emit_byte(0x00, cinfo);
++ } while (--e->sc);
++ }
++ e->buffer = temp & 0xFF; /* new output byte (can still overflow) */
++ }
++ e->c &= 0x7FFFFL;
++ e->ct += 8;
++ }
++ } while (e->a < 0x8000L);
++}
++
++
++/*
++ * Emit a restart marker & resynchronize predictions.
++ */
++
++LOCAL(void)
++emit_restart (j_compress_ptr cinfo, int restart_num)
++{
++ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
++ int ci;
++ jpeg_component_info * compptr;
++
++ finish_pass(cinfo);
++
++ emit_byte(0xFF, cinfo);
++ emit_byte(JPEG_RST0 + restart_num, cinfo);
++
++ for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
++ compptr = cinfo->cur_comp_info[ci];
++ /* Re-initialize statistics areas */
++ if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
++ MEMZERO(entropy->dc_stats[compptr->dc_tbl_no], DC_STAT_BINS);
++ /* Reset DC predictions to 0 */
++ entropy->last_dc_val[ci] = 0;
++ entropy->dc_context[ci] = 0;
++ }
++ if (cinfo->progressive_mode == 0 || cinfo->Ss) {
++ MEMZERO(entropy->ac_stats[compptr->ac_tbl_no], AC_STAT_BINS);
++ }
++ }
++
++ /* Reset arithmetic encoding variables */
++ entropy->c = 0;
++ entropy->a = 0x10000L;
++ entropy->sc = 0;
++ entropy->zc = 0;
++ entropy->ct = 11;
++ entropy->buffer = -1; /* empty */
++}
++
++
++/*
++ * MCU encoding for DC initial scan (either spectral selection,
++ * or first pass of successive approximation).
++ */
++
++METHODDEF(boolean)
++encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
++{
++ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
++ JBLOCKROW block;
++ unsigned char *st;
++ int blkn, ci, tbl;
++ int v, v2, m;
++ ISHIFT_TEMPS
++
++ /* Emit restart marker if needed */
++ if (cinfo->restart_interval) {
++ if (entropy->restarts_to_go == 0) {
++ emit_restart(cinfo, entropy->next_restart_num);
++ entropy->restarts_to_go = cinfo->restart_interval;
++ entropy->next_restart_num++;
++ entropy->next_restart_num &= 7;
++ }
++ entropy->restarts_to_go--;
++ }
++
++ /* Encode the MCU data blocks */
++ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
++ block = MCU_data[blkn];
++ ci = cinfo->MCU_membership[blkn];
++ tbl = cinfo->cur_comp_info[ci]->dc_tbl_no;
++
++ /* Compute the DC value after the required point transform by Al.
++ * This is simply an arithmetic right shift.
++ */
++ m = IRIGHT_SHIFT((int) ((*block)[0]), cinfo->Al);
++
++ /* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */
++
++ /* Table F.4: Point to statistics bin S0 for DC coefficient coding */
++ st = entropy->dc_stats[tbl] + entropy->dc_context[ci];
++
++ /* Figure F.4: Encode_DC_DIFF */
++ if ((v = m - entropy->last_dc_val[ci]) == 0) {
++ arith_encode(cinfo, st, 0);
++ entropy->dc_context[ci] = 0; /* zero diff category */
++ } else {
++ entropy->last_dc_val[ci] = m;
++ arith_encode(cinfo, st, 1);
++ /* Figure F.6: Encoding nonzero value v */
++ /* Figure F.7: Encoding the sign of v */
++ if (v > 0) {
++ arith_encode(cinfo, st + 1, 0); /* Table F.4: SS = S0 + 1 */
++ st += 2; /* Table F.4: SP = S0 + 2 */
++ entropy->dc_context[ci] = 4; /* small positive diff category */
++ } else {
++ v = -v;
++ arith_encode(cinfo, st + 1, 1); /* Table F.4: SS = S0 + 1 */
++ st += 3; /* Table F.4: SN = S0 + 3 */
++ entropy->dc_context[ci] = 8; /* small negative diff category */
++ }
++ /* Figure F.8: Encoding the magnitude category of v */
++ m = 0;
++ if (v -= 1) {
++ arith_encode(cinfo, st, 1);
++ m = 1;
++ v2 = v;
++ st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
++ while (v2 >>= 1) {
++ arith_encode(cinfo, st, 1);
++ m <<= 1;
++ st += 1;
++ }
++ }
++ arith_encode(cinfo, st, 0);
++ /* Section F.1.4.4.1.2: Establish dc_context conditioning category */
++ if (m < (int) (((INT32) 1 << cinfo->arith_dc_L[tbl]) >> 1))
++ entropy->dc_context[ci] = 0; /* zero diff category */
++ else if (m > (int) (((INT32) 1 << cinfo->arith_dc_U[tbl]) >> 1))
++ entropy->dc_context[ci] += 8; /* large diff category */
<<Diff was trimmed, longer than 597 lines>>
More information about the pld-cvs-commit
mailing list