IJG's JPEG software v6b with lossless JPEG support
Patch obtained from: https://sourceforge.net/projects/jpeg/files/ftp.oceana.com Author date taken from original announcement and timestamp of patch tarball: https://groups.google.com/g/comp.protocols.dicom/c/rrkP8BxoMRk/m/Ij4dfprggp8J
This commit is contained in:
57
jcphuff.c
57
jcphuff.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jcphuff.c
|
||||
*
|
||||
* Copyright (C) 1995-1997, Thomas G. Lane.
|
||||
* Copyright (C) 1995-1998, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@@ -15,15 +15,14 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jchuff.h" /* Declarations shared with jchuff.c */
|
||||
#include "jlossy.h" /* Private declarations for lossy codec */
|
||||
#include "jchuff.h" /* Declarations shared with jc*huff.c */
|
||||
|
||||
#ifdef C_PROGRESSIVE_SUPPORTED
|
||||
|
||||
/* Expanded entropy encoder object for progressive Huffman encoding. */
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_entropy_encoder pub; /* public fields */
|
||||
|
||||
/* Mode flag: TRUE for optimization, FALSE for actual data output */
|
||||
boolean gather_statistics;
|
||||
|
||||
@@ -105,7 +104,8 @@ METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
|
||||
METHODDEF(void)
|
||||
start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
j_lossy_c_ptr lossyc = (j_lossy_c_ptr) cinfo->codec;
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) lossyc->entropy_private;
|
||||
boolean is_DC_band;
|
||||
int ci, tbl;
|
||||
jpeg_component_info * compptr;
|
||||
@@ -120,14 +120,14 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
|
||||
/* Select execution routines */
|
||||
if (cinfo->Ah == 0) {
|
||||
if (is_DC_band)
|
||||
entropy->pub.encode_mcu = encode_mcu_DC_first;
|
||||
lossyc->entropy_encode_mcu = encode_mcu_DC_first;
|
||||
else
|
||||
entropy->pub.encode_mcu = encode_mcu_AC_first;
|
||||
lossyc->entropy_encode_mcu = encode_mcu_AC_first;
|
||||
} else {
|
||||
if (is_DC_band)
|
||||
entropy->pub.encode_mcu = encode_mcu_DC_refine;
|
||||
lossyc->entropy_encode_mcu = encode_mcu_DC_refine;
|
||||
else {
|
||||
entropy->pub.encode_mcu = encode_mcu_AC_refine;
|
||||
lossyc->entropy_encode_mcu = encode_mcu_AC_refine;
|
||||
/* AC refinement needs a correction bit buffer */
|
||||
if (entropy->bit_buffer == NULL)
|
||||
entropy->bit_buffer = (char *)
|
||||
@@ -136,9 +136,9 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
|
||||
}
|
||||
}
|
||||
if (gather_statistics)
|
||||
entropy->pub.finish_pass = finish_pass_gather_phuff;
|
||||
lossyc->pub.entropy_finish_pass = finish_pass_gather_phuff;
|
||||
else
|
||||
entropy->pub.finish_pass = finish_pass_phuff;
|
||||
lossyc->pub.entropy_finish_pass = finish_pass_phuff;
|
||||
|
||||
/* Only DC coefficients may be interleaved, so cinfo->comps_in_scan = 1
|
||||
* for AC coefficients.
|
||||
@@ -376,7 +376,8 @@ emit_restart (phuff_entropy_ptr entropy, int restart_num)
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
j_lossy_c_ptr lossyc = (j_lossy_c_ptr) cinfo->codec;
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) lossyc->entropy_private;
|
||||
register int temp, temp2;
|
||||
register int nbits;
|
||||
int blkn, ci;
|
||||
@@ -394,7 +395,7 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
emit_restart(entropy, entropy->next_restart_num);
|
||||
|
||||
/* Encode the MCU data blocks */
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
for (blkn = 0; blkn < cinfo->data_units_in_MCU; blkn++) {
|
||||
block = MCU_data[blkn];
|
||||
ci = cinfo->MCU_membership[blkn];
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
@@ -463,7 +464,8 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
j_lossy_c_ptr lossyc = (j_lossy_c_ptr) cinfo->codec;
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) lossyc->entropy_private;
|
||||
register int temp, temp2;
|
||||
register int nbits;
|
||||
register int r, k;
|
||||
@@ -570,7 +572,8 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
j_lossy_c_ptr lossyc = (j_lossy_c_ptr) cinfo->codec;
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) lossyc->entropy_private;
|
||||
register int temp;
|
||||
int blkn;
|
||||
int Al = cinfo->Al;
|
||||
@@ -585,7 +588,7 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
emit_restart(entropy, entropy->next_restart_num);
|
||||
|
||||
/* Encode the MCU data blocks */
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
for (blkn = 0; blkn < cinfo->data_units_in_MCU; blkn++) {
|
||||
block = MCU_data[blkn];
|
||||
|
||||
/* We simply emit the Al'th bit of the DC coefficient value. */
|
||||
@@ -617,7 +620,8 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
j_lossy_c_ptr lossyc = (j_lossy_c_ptr) cinfo->codec;
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) lossyc->entropy_private;
|
||||
register int temp;
|
||||
register int r, k;
|
||||
int EOB;
|
||||
@@ -745,7 +749,8 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
METHODDEF(void)
|
||||
finish_pass_phuff (j_compress_ptr cinfo)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
j_lossy_c_ptr lossyc = (j_lossy_c_ptr) cinfo->codec;
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) lossyc->entropy_private;
|
||||
|
||||
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
||||
entropy->free_in_buffer = cinfo->dest->free_in_buffer;
|
||||
@@ -766,7 +771,8 @@ finish_pass_phuff (j_compress_ptr cinfo)
|
||||
METHODDEF(void)
|
||||
finish_pass_gather_phuff (j_compress_ptr cinfo)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
j_lossy_c_ptr lossyc = (j_lossy_c_ptr) cinfo->codec;
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) lossyc->entropy_private;
|
||||
boolean is_DC_band;
|
||||
int ci, tbl;
|
||||
jpeg_component_info * compptr;
|
||||
@@ -806,6 +812,13 @@ finish_pass_gather_phuff (j_compress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
METHODDEF(boolean)
|
||||
need_optimization_pass (j_compress_ptr cinfo)
|
||||
{
|
||||
return (cinfo->Ss != 0 || cinfo->Ah == 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Module initialization routine for progressive Huffman entropy encoding.
|
||||
*/
|
||||
@@ -813,14 +826,16 @@ finish_pass_gather_phuff (j_compress_ptr cinfo)
|
||||
GLOBAL(void)
|
||||
jinit_phuff_encoder (j_compress_ptr cinfo)
|
||||
{
|
||||
j_lossy_c_ptr lossyc = (j_lossy_c_ptr) cinfo->codec;
|
||||
phuff_entropy_ptr entropy;
|
||||
int i;
|
||||
|
||||
entropy = (phuff_entropy_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(phuff_entropy_encoder));
|
||||
cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
|
||||
entropy->pub.start_pass = start_pass_phuff;
|
||||
lossyc->entropy_private = (struct jpeg_entropy_encoder *) entropy;
|
||||
lossyc->pub.entropy_start_pass = start_pass_phuff;
|
||||
lossyc->pub.need_optimization_pass = need_optimization_pass;
|
||||
|
||||
/* Mark tables unallocated */
|
||||
for (i = 0; i < NUM_HUFF_TBLS; i++) {
|
||||
|
||||
Reference in New Issue
Block a user