123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932 |
- #define JPEG_INTERNALS
- #include "jinclude.h"
- #include "jpeglib.h"
- typedef struct {
- struct jpeg_entropy_encoder pub;
- JLONG c;
- JLONG a;
- JLONG sc;
- JLONG zc;
- int ct;
- int buffer;
- int last_dc_val[MAX_COMPS_IN_SCAN];
- int dc_context[MAX_COMPS_IN_SCAN];
- unsigned int restarts_to_go;
- int next_restart_num;
-
- unsigned char *dc_stats[NUM_ARITH_TBLS];
- unsigned char *ac_stats[NUM_ARITH_TBLS];
-
- unsigned char fixed_bin[4];
- } arith_entropy_encoder;
- typedef arith_entropy_encoder *arith_entropy_ptr;
- #define DC_STAT_BINS 64
- #define AC_STAT_BINS 256
- #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)
- {
- 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);
- }
- METHODDEF(void)
- finish_pass(j_compress_ptr cinfo)
- {
- arith_entropy_ptr e = (arith_entropy_ptr)cinfo->entropy;
- JLONG temp;
-
-
- if ((temp = (e->a - 1 + e->c) & 0xFFFF0000UL) < e->c)
- e->c = temp + 0x8000L;
- else
- e->c = temp;
-
- e->c <<= e->ct;
- if (e->c & 0xF8000000UL) {
-
- 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;
- 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);
- }
- }
-
- if (e->c & 0x7FFF800L) {
- if (e->zc)
- 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);
- }
- }
- }
- LOCAL(void)
- arith_encode(j_compress_ptr cinfo, unsigned char *st, int val)
- {
- register arith_entropy_ptr e = (arith_entropy_ptr)cinfo->entropy;
- register unsigned char nl, nm;
- register JLONG qe, temp;
- register int sv;
-
- sv = *st;
- qe = jpeg_aritab[sv & 0x7F];
- nl = qe & 0xFF; qe >>= 8;
- nm = qe & 0xFF; qe >>= 8;
-
- e->a -= qe;
- if (val != (sv >> 7)) {
-
- if (e->a >= qe) {
-
- e->c += e->a;
- e->a = qe;
- }
- *st = (sv & 0x80) ^ nl;
- } else {
-
- if (e->a >= 0x8000L)
- return;
- if (e->a < qe) {
-
- e->c += e->a;
- e->a = qe;
- }
- *st = (sv & 0x80) ^ nm;
- }
-
- do {
- e->a <<= 1;
- e->c <<= 1;
- if (--e->ct == 0) {
-
- temp = e->c >> 19;
- if (temp > 0xFF) {
-
- 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;
- e->sc = 0;
-
- e->buffer = temp & 0xFF;
- } else if (temp == 0xFF) {
- ++e->sc;
- } 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);
- }
- e->buffer = temp & 0xFF;
- }
- e->c &= 0x7FFFFL;
- e->ct += 8;
- }
- } while (e->a < 0x8000L);
- }
- 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];
-
- if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
- MEMZERO(entropy->dc_stats[compptr->dc_tbl_no], DC_STAT_BINS);
-
- entropy->last_dc_val[ci] = 0;
- entropy->dc_context[ci] = 0;
- }
-
- if (cinfo->progressive_mode == 0 || cinfo->Se) {
- MEMZERO(entropy->ac_stats[compptr->ac_tbl_no], AC_STAT_BINS);
- }
- }
-
- entropy->c = 0;
- entropy->a = 0x10000L;
- entropy->sc = 0;
- entropy->zc = 0;
- entropy->ct = 11;
- entropy->buffer = -1;
- }
- 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
-
- 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--;
- }
-
- 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;
-
- m = IRIGHT_SHIFT((int)((*block)[0]), cinfo->Al);
-
-
- st = entropy->dc_stats[tbl] + entropy->dc_context[ci];
-
- if ((v = m - entropy->last_dc_val[ci]) == 0) {
- arith_encode(cinfo, st, 0);
- entropy->dc_context[ci] = 0;
- } else {
- entropy->last_dc_val[ci] = m;
- arith_encode(cinfo, st, 1);
-
-
- if (v > 0) {
- arith_encode(cinfo, st + 1, 0);
- st += 2;
- entropy->dc_context[ci] = 4;
- } else {
- v = -v;
- arith_encode(cinfo, st + 1, 1);
- st += 3;
- entropy->dc_context[ci] = 8;
- }
-
- m = 0;
- if (v -= 1) {
- arith_encode(cinfo, st, 1);
- m = 1;
- v2 = v;
- st = entropy->dc_stats[tbl] + 20;
- while (v2 >>= 1) {
- arith_encode(cinfo, st, 1);
- m <<= 1;
- st += 1;
- }
- }
- arith_encode(cinfo, st, 0);
-
- if (m < (int)((1L << cinfo->arith_dc_L[tbl]) >> 1))
- entropy->dc_context[ci] = 0;
- else if (m > (int)((1L << cinfo->arith_dc_U[tbl]) >> 1))
- entropy->dc_context[ci] += 8;
-
- st += 14;
- while (m >>= 1)
- arith_encode(cinfo, st, (m & v) ? 1 : 0);
- }
- }
- return TRUE;
- }
- METHODDEF(boolean)
- encode_mcu_AC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
- {
- arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
- JBLOCKROW block;
- unsigned char *st;
- int tbl, k, ke;
- int v, v2, m;
-
- 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--;
- }
-
- block = MCU_data[0];
- tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
-
-
- for (ke = cinfo->Se; ke > 0; ke--)
-
- if ((v = (*block)[jpeg_natural_order[ke]]) >= 0) {
- if (v >>= cinfo->Al) break;
- } else {
- v = -v;
- if (v >>= cinfo->Al) break;
- }
-
- for (k = cinfo->Ss; k <= ke; k++) {
- st = entropy->ac_stats[tbl] + 3 * (k - 1);
- arith_encode(cinfo, st, 0);
- for (;;) {
- if ((v = (*block)[jpeg_natural_order[k]]) >= 0) {
- if (v >>= cinfo->Al) {
- arith_encode(cinfo, st + 1, 1);
- arith_encode(cinfo, entropy->fixed_bin, 0);
- break;
- }
- } else {
- v = -v;
- if (v >>= cinfo->Al) {
- arith_encode(cinfo, st + 1, 1);
- arith_encode(cinfo, entropy->fixed_bin, 1);
- break;
- }
- }
- arith_encode(cinfo, st + 1, 0); st += 3; k++;
- }
- st += 2;
-
- m = 0;
- if (v -= 1) {
- arith_encode(cinfo, st, 1);
- m = 1;
- v2 = v;
- if (v2 >>= 1) {
- arith_encode(cinfo, st, 1);
- m <<= 1;
- st = entropy->ac_stats[tbl] +
- (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
- while (v2 >>= 1) {
- arith_encode(cinfo, st, 1);
- m <<= 1;
- st += 1;
- }
- }
- }
- arith_encode(cinfo, st, 0);
-
- st += 14;
- while (m >>= 1)
- arith_encode(cinfo, st, (m & v) ? 1 : 0);
- }
-
- if (k <= cinfo->Se) {
- st = entropy->ac_stats[tbl] + 3 * (k - 1);
- arith_encode(cinfo, st, 1);
- }
- return TRUE;
- }
- METHODDEF(boolean)
- encode_mcu_DC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
- {
- arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
- unsigned char *st;
- int Al, blkn;
-
- 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--;
- }
- st = entropy->fixed_bin;
- Al = cinfo->Al;
-
- for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
-
- arith_encode(cinfo, st, (MCU_data[blkn][0][0] >> Al) & 1);
- }
- return TRUE;
- }
- METHODDEF(boolean)
- encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
- {
- arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
- JBLOCKROW block;
- unsigned char *st;
- int tbl, k, ke, kex;
- int v;
-
- 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--;
- }
-
- block = MCU_data[0];
- tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
-
-
- for (ke = cinfo->Se; ke > 0; ke--)
-
- if ((v = (*block)[jpeg_natural_order[ke]]) >= 0) {
- if (v >>= cinfo->Al) break;
- } else {
- v = -v;
- if (v >>= cinfo->Al) break;
- }
-
- for (kex = ke; kex > 0; kex--)
- if ((v = (*block)[jpeg_natural_order[kex]]) >= 0) {
- if (v >>= cinfo->Ah) break;
- } else {
- v = -v;
- if (v >>= cinfo->Ah) break;
- }
-
- for (k = cinfo->Ss; k <= ke; k++) {
- st = entropy->ac_stats[tbl] + 3 * (k - 1);
- if (k > kex)
- arith_encode(cinfo, st, 0);
- for (;;) {
- if ((v = (*block)[jpeg_natural_order[k]]) >= 0) {
- if (v >>= cinfo->Al) {
- if (v >> 1)
- arith_encode(cinfo, st + 2, (v & 1));
- else {
- arith_encode(cinfo, st + 1, 1);
- arith_encode(cinfo, entropy->fixed_bin, 0);
- }
- break;
- }
- } else {
- v = -v;
- if (v >>= cinfo->Al) {
- if (v >> 1)
- arith_encode(cinfo, st + 2, (v & 1));
- else {
- arith_encode(cinfo, st + 1, 1);
- arith_encode(cinfo, entropy->fixed_bin, 1);
- }
- break;
- }
- }
- arith_encode(cinfo, st + 1, 0); st += 3; k++;
- }
- }
-
- if (k <= cinfo->Se) {
- st = entropy->ac_stats[tbl] + 3 * (k - 1);
- arith_encode(cinfo, st, 1);
- }
- return TRUE;
- }
- METHODDEF(boolean)
- encode_mcu(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
- {
- arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
- jpeg_component_info *compptr;
- JBLOCKROW block;
- unsigned char *st;
- int blkn, ci, tbl, k, ke;
- int v, v2, m;
-
- 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--;
- }
-
- for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
- block = MCU_data[blkn];
- ci = cinfo->MCU_membership[blkn];
- compptr = cinfo->cur_comp_info[ci];
-
- tbl = compptr->dc_tbl_no;
-
- st = entropy->dc_stats[tbl] + entropy->dc_context[ci];
-
- if ((v = (*block)[0] - entropy->last_dc_val[ci]) == 0) {
- arith_encode(cinfo, st, 0);
- entropy->dc_context[ci] = 0;
- } else {
- entropy->last_dc_val[ci] = (*block)[0];
- arith_encode(cinfo, st, 1);
-
-
- if (v > 0) {
- arith_encode(cinfo, st + 1, 0);
- st += 2;
- entropy->dc_context[ci] = 4;
- } else {
- v = -v;
- arith_encode(cinfo, st + 1, 1);
- st += 3;
- entropy->dc_context[ci] = 8;
- }
-
- m = 0;
- if (v -= 1) {
- arith_encode(cinfo, st, 1);
- m = 1;
- v2 = v;
- st = entropy->dc_stats[tbl] + 20;
- while (v2 >>= 1) {
- arith_encode(cinfo, st, 1);
- m <<= 1;
- st += 1;
- }
- }
- arith_encode(cinfo, st, 0);
-
- if (m < (int)((1L << cinfo->arith_dc_L[tbl]) >> 1))
- entropy->dc_context[ci] = 0;
- else if (m > (int)((1L << cinfo->arith_dc_U[tbl]) >> 1))
- entropy->dc_context[ci] += 8;
-
- st += 14;
- while (m >>= 1)
- arith_encode(cinfo, st, (m & v) ? 1 : 0);
- }
-
- tbl = compptr->ac_tbl_no;
-
- for (ke = DCTSIZE2 - 1; ke > 0; ke--)
- if ((*block)[jpeg_natural_order[ke]]) break;
-
- for (k = 1; k <= ke; k++) {
- st = entropy->ac_stats[tbl] + 3 * (k - 1);
- arith_encode(cinfo, st, 0);
- while ((v = (*block)[jpeg_natural_order[k]]) == 0) {
- arith_encode(cinfo, st + 1, 0); st += 3; k++;
- }
- arith_encode(cinfo, st + 1, 1);
-
-
- if (v > 0) {
- arith_encode(cinfo, entropy->fixed_bin, 0);
- } else {
- v = -v;
- arith_encode(cinfo, entropy->fixed_bin, 1);
- }
- st += 2;
-
- m = 0;
- if (v -= 1) {
- arith_encode(cinfo, st, 1);
- m = 1;
- v2 = v;
- if (v2 >>= 1) {
- arith_encode(cinfo, st, 1);
- m <<= 1;
- st = entropy->ac_stats[tbl] +
- (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
- while (v2 >>= 1) {
- arith_encode(cinfo, st, 1);
- m <<= 1;
- st += 1;
- }
- }
- }
- arith_encode(cinfo, st, 0);
-
- st += 14;
- while (m >>= 1)
- arith_encode(cinfo, st, (m & v) ? 1 : 0);
- }
-
- if (k <= DCTSIZE2 - 1) {
- st = entropy->ac_stats[tbl] + 3 * (k - 1);
- arith_encode(cinfo, st, 1);
- }
- }
- return TRUE;
- }
- METHODDEF(void)
- start_pass(j_compress_ptr cinfo, boolean gather_statistics)
- {
- arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
- int ci, tbl;
- jpeg_component_info *compptr;
- if (gather_statistics)
-
- ERREXIT(cinfo, JERR_NOT_COMPILED);
-
-
- if (cinfo->progressive_mode) {
- if (cinfo->Ah == 0) {
- if (cinfo->Ss == 0)
- entropy->pub.encode_mcu = encode_mcu_DC_first;
- else
- entropy->pub.encode_mcu = encode_mcu_AC_first;
- } else {
- if (cinfo->Ss == 0)
- entropy->pub.encode_mcu = encode_mcu_DC_refine;
- else
- entropy->pub.encode_mcu = encode_mcu_AC_refine;
- }
- } else
- entropy->pub.encode_mcu = encode_mcu;
-
- for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
- compptr = cinfo->cur_comp_info[ci];
-
- if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
- tbl = compptr->dc_tbl_no;
- if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
- ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
- if (entropy->dc_stats[tbl] == NULL)
- entropy->dc_stats[tbl] = (unsigned char *)(*cinfo->mem->alloc_small)
- ((j_common_ptr)cinfo, JPOOL_IMAGE, DC_STAT_BINS);
- MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS);
-
- entropy->last_dc_val[ci] = 0;
- entropy->dc_context[ci] = 0;
- }
-
- if (cinfo->progressive_mode == 0 || cinfo->Se) {
- tbl = compptr->ac_tbl_no;
- if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
- ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
- if (entropy->ac_stats[tbl] == NULL)
- entropy->ac_stats[tbl] = (unsigned char *)(*cinfo->mem->alloc_small)
- ((j_common_ptr)cinfo, JPOOL_IMAGE, AC_STAT_BINS);
- MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS);
- #ifdef CALCULATE_SPECTRAL_CONDITIONING
- if (cinfo->progressive_mode)
-
- cinfo->arith_ac_K[tbl] = cinfo->Ss +
- ((8 + cinfo->Se - cinfo->Ss) >> 4);
- #endif
- }
- }
-
- entropy->c = 0;
- entropy->a = 0x10000L;
- entropy->sc = 0;
- entropy->zc = 0;
- entropy->ct = 11;
- entropy->buffer = -1;
-
- entropy->restarts_to_go = cinfo->restart_interval;
- entropy->next_restart_num = 0;
- }
- GLOBAL(void)
- jinit_arith_encoder(j_compress_ptr cinfo)
- {
- arith_entropy_ptr entropy;
- int i;
- entropy = (arith_entropy_ptr)
- (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
- sizeof(arith_entropy_encoder));
- cinfo->entropy = (struct jpeg_entropy_encoder *)entropy;
- entropy->pub.start_pass = start_pass;
- entropy->pub.finish_pass = finish_pass;
-
- for (i = 0; i < NUM_ARITH_TBLS; i++) {
- entropy->dc_stats[i] = NULL;
- entropy->ac_stats[i] = NULL;
- }
-
- entropy->fixed_bin[0] = 113;
- }
|