Home | History | Annotate | Download | only in libjpeg-turbo

Lines Matching defs:entropy

11  * This file contains Huffman entropy encoding routines for progressive JPEG.
25 /* Expanded entropy encoder object for progressive Huffman encoding. */
111 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
116 entropy->cinfo = cinfo;
117 entropy->gather_statistics = gather_statistics;
126 entropy->pub.encode_mcu = encode_mcu_DC_first;
128 entropy->pub.encode_mcu = encode_mcu_AC_first;
131 entropy->pub.encode_mcu = encode_mcu_DC_refine;
133 entropy->pub.encode_mcu = encode_mcu_AC_refine;
135 if (entropy->bit_buffer == NULL)
136 entropy->bit_buffer = (char *)
142 entropy->pub.finish_pass = finish_pass_gather_phuff;
144 entropy->pub.finish_pass = finish_pass_phuff;
152 entropy->last_dc_val[ci] = 0;
159 entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
168 if (entropy->count_ptrs[tbl] == NULL)
169 entropy->count_ptrs[tbl] = (long *)
172 MEMZERO(entropy->count_ptrs[tbl], 257 * sizeof(long));
177 & entropy->derived_tbls[tbl]);
182 entropy->EOBRUN = 0;
183 entropy->BE = 0;
186 entropy->put_buffer = 0;
187 entropy->put_bits = 0;
190 entropy->restarts_to_go = cinfo->restart_interval;
191 entropy->next_restart_num = 0;
197 * that is, entropy->gather_statistics == FALSE.
201 #define emit_byte(entropy,val) \
202 { *(entropy)->next_output_byte++ = (JOCTET) (val); \
203 if (--(entropy)->free_in_buffer == 0) \
204 dump_buffer(entropy); }
208 dump_buffer (phuff_entropy_ptr entropy)
211 struct jpeg_destination_mgr *dest = entropy->cinfo->dest;
213 if (! (*dest->empty_output_buffer) (entropy->cinfo))
214 ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
216 entropy->next_output_byte = dest->next_output_byte;
217 entropy->free_in_buffer = dest->free_in_buffer;
230 emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size)
235 register int put_bits = entropy->put_bits;
239 ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
241 if (entropy->gather_statistics)
250 put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
255 emit_byte(entropy, c);
257 emit_byte(entropy, 0);
263 entropy->put_buffer = put_buffer; /* update variables */
264 entropy->put_bits = put_bits;
269 flush_bits (phuff_entropy_ptr entropy)
271 emit_bits(entropy, 0x7F, 7); /* fill any partial byte with ones */
272 entropy->put_buffer = 0; /* and reset bit-buffer to empty */
273 entropy->put_bits = 0;
282 emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
284 if (entropy->gather_statistics)
285 entropy->count_ptrs[tbl_no][symbol]++;
287 c_derived_tbl *tbl = entropy->derived_tbls[tbl_no];
288 emit_bits(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
298 emit_buffered_bits (phuff_entropy_ptr entropy, char *bufstart,
301 if (entropy->gather_statistics)
305 emit_bits(entropy, (unsigned int) (*bufstart), 1);
317 emit_eobrun (phuff_entropy_ptr entropy)
321 if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
322 temp = entropy->EOBRUN;
328 ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
330 emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
332 emit_bits(entropy, entropy->EOBRUN, nbits);
334 entropy->EOBRUN = 0;
337 emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
338 entropy->BE = 0;
348 emit_restart (phuff_entropy_ptr entropy, int restart_num)
352 emit_eobrun(entropy);
354 if (! entropy->gather_statistics) {
355 flush_bits(entropy);
356 emit_byte(entropy, 0xFF);
357 emit_byte(entropy, JPEG_RST0 + restart_num);
360 if (entropy->cinfo->Ss == 0) {
362 for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
363 entropy->last_dc_val[ci] = 0;
366 entropy->EOBRUN = 0;
367 entropy->BE = 0;
380 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
389 entropy->next_output_byte = cinfo->dest->next_output_byte;
390 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
394 if (entropy->restarts_to_go == 0)
395 emit_restart(entropy, entropy->next_restart_num);
409 temp = temp2 - entropy->last_dc_val[ci];
410 entropy->last_dc_val[ci] = temp2;
434 emit_symbol(entropy, compptr->dc_tbl_no, nbits);
439 emit_bits(entropy, (unsigned int) temp2, nbits);
442 cinfo->dest->next_output_byte = entropy->next_output_byte;
443 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
447 if (entropy->restarts_to_go == 0) {
448 entropy->restarts_to_go = cinfo->restart_interval;
449 entropy->next_restart_num++;
450 entropy->next_restart_num &= 7;
452 entropy->restarts_to_go--;
467 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
475 entropy->next_output_byte = cinfo->dest->next_output_byte;
476 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
480 if (entropy->restarts_to_go == 0)
481 emit_restart(entropy, entropy->next_restart_num);
516 if (entropy->EOBRUN > 0)
517 emit_eobrun(entropy);
520 emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
533 emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
537 emit_bits(entropy, (unsigned int) temp2, nbits);
543 entropy->EOBRUN++; /* count an EOB */
544 if (entropy->EOBRUN == 0x7FFF)
545 emit_eobrun(entropy); /* force it out to avoid overflow */
548 cinfo->dest->next_output_byte = entropy->next_output_byte;
549 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
553 if (entropy->restarts_to_go == 0) {
554 entropy->restarts_to_go = cinfo->restart_interval;
555 entropy->next_restart_num++;
556 entropy->next_restart_num &= 7;
558 entropy->restarts_to_go--;
574 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
580 entropy->next_output_byte = cinfo->dest->next_output_byte;
581 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
585 if (entropy->restarts_to_go == 0)
586 emit_restart(entropy, entropy->next_restart_num);
594 emit_bits(entropy, (unsigned int) (temp >> Al), 1);
597 cinfo->dest->next_output_byte = entropy->next_output_byte;
598 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
602 if (entropy->restarts_to_go == 0) {
603 entropy->restarts_to_go = cinfo->restart_interval;
604 entropy->next_restart_num++;
605 entropy->next_restart_num &= 7;
607 entropy->restarts_to_go--;
621 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
632 entropy->next_output_byte = cinfo->dest->next_output_byte;
633 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
637 if (entropy->restarts_to_go == 0)
638 emit_restart(entropy, entropy->next_restart_num);
665 BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
676 emit_eobrun(entropy);
678 emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
681 emit_buffered_bits(entropy, BR_buffer, BR);
682 BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
698 emit_eobrun(entropy);
701 emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
705 emit_bits(entropy, (unsigned int) temp, 1);
708 emit_buffered_bits(entropy, BR_buffer, BR);
709 BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
715 entropy->EOBRUN++; /* count an EOB */
716 entropy->BE += BR; /* concat my correction bits to older ones */
721 if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
722 emit_eobrun(entropy);
725 cinfo->dest->next_output_byte = entropy->next_output_byte;
726 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
730 if (entropy->restarts_to_go == 0) {
731 entropy->restarts_to_go = cinfo->restart_interval;
732 entropy->next_restart_num++;
733 entropy->next_restart_num &= 7;
735 entropy->restarts_to_go--;
749 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
751 entropy->next_output_byte = cinfo->dest->next_output_byte;
752 entropy->free_in_buffer = cinfo->dest->free_in_buffer;
755 emit_eobrun(entropy);
756 flush_bits(entropy);
758 cinfo->dest->next_output_byte = entropy->next_output_byte;
759 cinfo->dest->free_in_buffer = entropy->free_in_buffer;
770 phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
778 emit_eobrun(entropy);
803 jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
811 * Module initialization routine for progressive Huffman entropy encoding.
817 phuff_entropy_ptr entropy;
820 entropy = (phuff_entropy_ptr)
823 cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
824 entropy->pub.start_pass = start_pass_phuff;
828 entropy->derived_tbls[i] = NULL;
829 entropy->count_ptrs[i] = NULL;
831 entropy->bit_buffer = NULL; /* needed only in AC refinement scan */