Lines Matching refs: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;
227 emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size)
232 register int put_bits = entropy->put_bits;
236 ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
238 if (entropy->gather_statistics)
247 put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
252 emit_byte(entropy, c);
254 emit_byte(entropy, 0);
260 entropy->put_buffer = put_buffer; /* update variables */
261 entropy->put_bits = put_bits;
266 flush_bits (phuff_entropy_ptr entropy)
268 emit_bits(entropy, 0x7F, 7); /* fill any partial byte with ones */
269 entropy->put_buffer = 0; /* and reset bit-buffer to empty */
270 entropy->put_bits = 0;
279 emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
281 if (entropy->gather_statistics)
282 entropy->count_ptrs[tbl_no][symbol]++;
284 c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
285 emit_bits(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
295 emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
298 if (entropy->gather_statistics)
302 emit_bits(entropy, (unsigned int) (*bufstart), 1);
314 emit_eobrun (phuff_entropy_ptr entropy)
318 if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
319 temp = entropy->EOBRUN;
325 ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
327 emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
329 emit_bits(entropy, entropy->EOBRUN, nbits);
331 entropy->EOBRUN = 0;
334 emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
335 entropy->BE = 0;
345 emit_restart (phuff_entropy_ptr entropy, int restart_num)
349 emit_eobrun(entropy);
351 if (! entropy->gather_statistics) {
352 flush_bits(entropy);
353 emit_byte(entropy, 0xFF);
354 emit_byte(entropy, JPEG_RST0 + restart_num);
357 if (entropy->cinfo->Ss == 0) {
359 for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
360 entropy->last_dc_val[ci] = 0;
363 entropy->EOBRUN = 0;
364 entropy->BE = 0;
377 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
386 entropy->next_output_byte = cinfo->dest->next_output_byte;
387 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
391 if (entropy->restarts_to_go == 0)
392 emit_restart(entropy, entropy->next_restart_num);
406 temp = temp2 - entropy->last_dc_val[ci];
407 entropy->last_dc_val[ci] = temp2;
431 emit_symbol(entropy, compptr->dc_tbl_no, nbits);
436 emit_bits(entropy, (unsigned int) temp2, nbits);
439 cinfo->dest->next_output_byte = entropy->next_output_byte;
440 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
444 if (entropy->restarts_to_go == 0) {
445 entropy->restarts_to_go = cinfo->restart_interval;
446 entropy->next_restart_num++;
447 entropy->next_restart_num &= 7;
449 entropy->restarts_to_go--;
464 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
472 entropy->next_output_byte = cinfo->dest->next_output_byte;
473 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
477 if (entropy->restarts_to_go == 0)
478 emit_restart(entropy, entropy->next_restart_num);
513 if (entropy->EOBRUN > 0)
514 emit_eobrun(entropy);
517 emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
530 emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
534 emit_bits(entropy, (unsigned int) temp2, nbits);
540 entropy->EOBRUN++; /* count an EOB */
541 if (entropy->EOBRUN == 0x7FFF)
542 emit_eobrun(entropy); /* force it out to avoid overflow */
545 cinfo->dest->next_output_byte = entropy->next_output_byte;
546 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
550 if (entropy->restarts_to_go == 0) {
551 entropy->restarts_to_go = cinfo->restart_interval;
552 entropy->next_restart_num++;
553 entropy->next_restart_num &= 7;
555 entropy->restarts_to_go--;
571 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
577 entropy->next_output_byte = cinfo->dest->next_output_byte;
578 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
582 if (entropy->restarts_to_go == 0)
583 emit_restart(entropy, entropy->next_restart_num);
591 emit_bits(entropy, (unsigned int) (temp >> Al), 1);
594 cinfo->dest->next_output_byte = entropy->next_output_byte;
595 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
599 if (entropy->restarts_to_go == 0) {
600 entropy->restarts_to_go = cinfo->restart_interval;
601 entropy->next_restart_num++;
602 entropy->next_restart_num &= 7;
604 entropy->restarts_to_go--;
618 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
629 entropy->next_output_byte = cinfo->dest->next_output_byte;
630 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
634 if (entropy->restarts_to_go == 0)
635 emit_restart(entropy, entropy->next_restart_num);
662 BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
673 emit_eobrun(entropy);
675 emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
678 emit_buffered_bits(entropy, BR_buffer, BR);
679 BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
695 emit_eobrun(entropy);
698 emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
702 emit_bits(entropy, (unsigned int) temp, 1);
705 emit_buffered_bits(entropy, BR_buffer, BR);
706 BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
712 entropy->EOBRUN++; /* count an EOB */
713 entropy->BE += BR; /* concat my correction bits to older ones */
718 if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
719 emit_eobrun(entropy);
722 cinfo->dest->next_output_byte = entropy->next_output_byte;
723 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
727 if (entropy->restarts_to_go == 0) {
728 entropy->restarts_to_go = cinfo->restart_interval;
729 entropy->next_restart_num++;
730 entropy->next_restart_num &= 7;
732 entropy->restarts_to_go--;
746 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
748 entropy->next_output_byte = cinfo->dest->next_output_byte;
749 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
752 emit_eobrun(entropy);
753 flush_bits(entropy);
755 cinfo->dest->next_output_byte = entropy->next_output_byte;
756 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
767 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
775 emit_eobrun(entropy);
800 jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
808 * Module initialization routine for progressive Huffman entropy encoding.
814 phuff_entropy_ptr entropy;
817 entropy = (phuff_entropy_ptr)
820 cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
821 entropy->pub.start_pass = start_pass_phuff;
825 entropy->derived_tbls[i] = NULL;
826 entropy->count_ptrs[i] = NULL;
828 entropy->bit_buffer = NULL; /* needed only in AC refinement scan */