Lines Matching defs:entropy
8 * This file contains Huffman entropy encoding routines for progressive JPEG.
22 /* Expanded entropy encoder object for progressive Huffman encoding. */
108 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
113 entropy->cinfo = cinfo;
114 entropy->gather_statistics = gather_statistics;
123 entropy->pub.encode_mcu = encode_mcu_DC_first;
125 entropy->pub.encode_mcu = encode_mcu_AC_first;
128 entropy->pub.encode_mcu = encode_mcu_DC_refine;
130 entropy->pub.encode_mcu = encode_mcu_AC_refine;
132 if (entropy->bit_buffer == NULL)
133 entropy->bit_buffer = (char *)
139 entropy->pub.finish_pass = finish_pass_gather_phuff;
141 entropy->pub.finish_pass = finish_pass_phuff;
149 entropy->last_dc_val[ci] = 0;
156 entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
165 if (entropy->count_ptrs[tbl] == NULL)
166 entropy->count_ptrs[tbl] = (long *)
169 MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
174 & entropy->derived_tbls[tbl]);
179 entropy->EOBRUN = 0;
180 entropy->BE = 0;
183 entropy->put_buffer = 0;
184 entropy->put_bits = 0;
187 entropy->restarts_to_go = cinfo->restart_interval;
188 entropy->next_restart_num = 0;
194 * that is, entropy->gather_statistics == FALSE.
198 #define emit_byte(entropy,val) \
199 { *(entropy)->next_output_byte++ = (JOCTET) (val); \
200 if (--(entropy)->free_in_buffer == 0) \
201 dump_buffer(entropy); }
205 dump_buffer (phuff_entropy_ptr entropy)
208 struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
210 if (! (*dest->empty_output_buffer) (entropy->cinfo))
211 ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
213 entropy->next_output_byte = dest->next_output_byte;
214 entropy->free_in_buffer = dest->free_in_buffer;
228 emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size)
233 register int put_bits = entropy->put_bits;
237 ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
239 if (entropy->gather_statistics)
248 put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
253 emit_byte(entropy, c);
255 emit_byte(entropy, 0);
261 entropy->put_buffer = put_buffer; /* update variables */
262 entropy->put_bits = put_bits;
267 flush_bits (phuff_entropy_ptr entropy)
269 emit_bits(entropy, 0x7F, 7); /* fill any partial byte with ones */
270 entropy->put_buffer = 0; /* and reset bit-buffer to empty */
271 entropy->put_bits = 0;
281 emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
283 if (entropy->gather_statistics)
284 entropy->count_ptrs[tbl_no][symbol]++;
286 c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
287 emit_bits(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
297 emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
300 if (entropy->gather_statistics)
304 emit_bits(entropy, (unsigned int) (*bufstart), 1);
316 emit_eobrun (phuff_entropy_ptr entropy)
320 if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
321 temp = entropy->EOBRUN;
327 ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
329 emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
331 emit_bits(entropy, entropy->EOBRUN, nbits);
333 entropy->EOBRUN = 0;
336 emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
337 entropy->BE = 0;
347 emit_restart (phuff_entropy_ptr entropy, int restart_num)
351 emit_eobrun(entropy);
353 if (! entropy->gather_statistics) {
354 flush_bits(entropy);
355 emit_byte(entropy, 0xFF);
356 emit_byte(entropy, JPEG_RST0 + restart_num);
359 if (entropy->cinfo->Ss == 0) {
361 for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
362 entropy->last_dc_val[ci] = 0;
365 entropy->EOBRUN = 0;
366 entropy->BE = 0;
379 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
388 entropy->next_output_byte = cinfo->dest->next_output_byte;
389 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
393 if (entropy->restarts_to_go == 0)
394 emit_restart(entropy, entropy->next_restart_num);
408 temp = temp2 - entropy->last_dc_val[ci];
409 entropy->last_dc_val[ci] = temp2;
433 emit_symbol(entropy, compptr->dc_tbl_no, nbits);
438 emit_bits(entropy, (unsigned int) temp2, nbits);
441 cinfo->dest->next_output_byte = entropy->next_output_byte;
442 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
446 if (entropy->restarts_to_go == 0) {
447 entropy->restarts_to_go = cinfo->restart_interval;
448 entropy->next_restart_num++;
449 entropy->next_restart_num &= 7;
451 entropy->restarts_to_go--;
466 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
474 entropy->next_output_byte = cinfo->dest->next_output_byte;
475 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
479 if (entropy->restarts_to_go == 0)
480 emit_restart(entropy, entropy->next_restart_num);
515 if (entropy->EOBRUN > 0)
516 emit_eobrun(entropy);
519 emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
532 emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
536 emit_bits(entropy, (unsigned int) temp2, nbits);
542 entropy->EOBRUN++; /* count an EOB */
543 if (entropy->EOBRUN == 0x7FFF)
544 emit_eobrun(entropy); /* force it out to avoid overflow */
547 cinfo->dest->next_output_byte = entropy->next_output_byte;
548 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
552 if (entropy->restarts_to_go == 0) {
553 entropy->restarts_to_go = cinfo->restart_interval;
554 entropy->next_restart_num++;
555 entropy->next_restart_num &= 7;
557 entropy->restarts_to_go--;
573 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
579 entropy->next_output_byte = cinfo->dest->next_output_byte;
580 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
584 if (entropy->restarts_to_go == 0)
585 emit_restart(entropy, entropy->next_restart_num);
593 emit_bits(entropy, (unsigned int) (temp >> Al), 1);
596 cinfo->dest->next_output_byte = entropy->next_output_byte;
597 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
601 if (entropy->restarts_to_go == 0) {
602 entropy->restarts_to_go = cinfo->restart_interval;
603 entropy->next_restart_num++;
604 entropy->next_restart_num &= 7;
606 entropy->restarts_to_go--;
620 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
631 entropy->next_output_byte = cinfo->dest->next_output_byte;
632 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
636 if (entropy->restarts_to_go == 0)
637 emit_restart(entropy, entropy->next_restart_num);
664 BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
675 emit_eobrun(entropy);
677 emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
680 emit_buffered_bits(entropy, BR_buffer, BR);
681 BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
697 emit_eobrun(entropy);
700 emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
704 emit_bits(entropy, (unsigned int) temp, 1);
707 emit_buffered_bits(entropy, BR_buffer, BR);
708 BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
714 entropy->EOBRUN++; /* count an EOB */
715 entropy->BE += BR; /* concat my correction bits to older ones */
720 if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
721 emit_eobrun(entropy);
724 cinfo->dest->next_output_byte = entropy->next_output_byte;
725 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
729 if (entropy->restarts_to_go == 0) {
730 entropy->restarts_to_go = cinfo->restart_interval;
731 entropy->next_restart_num++;
732 entropy->next_restart_num &= 7;
734 entropy->restarts_to_go--;
748 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
750 entropy->next_output_byte = cinfo->dest->next_output_byte;
751 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
754 emit_eobrun(entropy);
755 flush_bits(entropy);
757 cinfo->dest->next_output_byte = entropy->next_output_byte;
758 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
769 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
777 emit_eobrun(entropy);
802 jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
810 * Module initialization routine for progressive Huffman entropy encoding.
816 phuff_entropy_ptr entropy;
819 entropy = (phuff_entropy_ptr)
822 cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
823 entropy->pub.start_pass = start_pass_phuff;
827 entropy->derived_tbls[i] = NULL;
828 entropy->count_ptrs[i] = NULL;
830 entropy->bit_buffer = NULL; /* needed only in AC refinement scan */