j*huff.c: Remove crufty ASSIGN_STATE() macro
This macro is a relic of libjpeg's historic need to support a wide variety of C compilers with varying degrees of compatibility. Such was necessary during the open systems era, because C compilers were often supplied by the system vendor. Prior to 1989, there was no C standard per se, and even after ANSI C became a thing, there were still compilers in use that didn't conform to it (libjpeg was first released in 1991.) Realistically, only a handful of C compilers are in widespread use these days, and all modern C compilers should support structure assignment.
This commit is contained in:
28
jchuff.c
28
jchuff.c
@@ -78,26 +78,6 @@ typedef struct {
|
|||||||
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
|
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
|
||||||
} savable_state;
|
} savable_state;
|
||||||
|
|
||||||
/* This macro is to work around compilers with missing or broken
|
|
||||||
* structure assignment. You'll need to fix this code if you have
|
|
||||||
* such a compiler and you change MAX_COMPS_IN_SCAN.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NO_STRUCT_ASSIGN
|
|
||||||
#define ASSIGN_STATE(dest, src) ((dest) = (src))
|
|
||||||
#else
|
|
||||||
#if MAX_COMPS_IN_SCAN == 4
|
|
||||||
#define ASSIGN_STATE(dest, src) \
|
|
||||||
((dest).put_buffer = (src).put_buffer, \
|
|
||||||
(dest).put_bits = (src).put_bits, \
|
|
||||||
(dest).last_dc_val[0] = (src).last_dc_val[0], \
|
|
||||||
(dest).last_dc_val[1] = (src).last_dc_val[1], \
|
|
||||||
(dest).last_dc_val[2] = (src).last_dc_val[2], \
|
|
||||||
(dest).last_dc_val[3] = (src).last_dc_val[3])
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct jpeg_entropy_encoder pub; /* public fields */
|
struct jpeg_entropy_encoder pub; /* public fields */
|
||||||
|
|
||||||
@@ -661,7 +641,7 @@ encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
/* Load up working state */
|
/* Load up working state */
|
||||||
state.next_output_byte = cinfo->dest->next_output_byte;
|
state.next_output_byte = cinfo->dest->next_output_byte;
|
||||||
state.free_in_buffer = cinfo->dest->free_in_buffer;
|
state.free_in_buffer = cinfo->dest->free_in_buffer;
|
||||||
ASSIGN_STATE(state.cur, entropy->saved);
|
state.cur = entropy->saved;
|
||||||
state.cinfo = cinfo;
|
state.cinfo = cinfo;
|
||||||
|
|
||||||
/* Emit restart marker if needed */
|
/* Emit restart marker if needed */
|
||||||
@@ -701,7 +681,7 @@ encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
/* Completed MCU, so update state */
|
/* Completed MCU, so update state */
|
||||||
cinfo->dest->next_output_byte = state.next_output_byte;
|
cinfo->dest->next_output_byte = state.next_output_byte;
|
||||||
cinfo->dest->free_in_buffer = state.free_in_buffer;
|
cinfo->dest->free_in_buffer = state.free_in_buffer;
|
||||||
ASSIGN_STATE(entropy->saved, state.cur);
|
entropy->saved = state.cur;
|
||||||
|
|
||||||
/* Update restart-interval state too */
|
/* Update restart-interval state too */
|
||||||
if (cinfo->restart_interval) {
|
if (cinfo->restart_interval) {
|
||||||
@@ -730,7 +710,7 @@ finish_pass_huff(j_compress_ptr cinfo)
|
|||||||
/* Load up working state ... flush_bits needs it */
|
/* Load up working state ... flush_bits needs it */
|
||||||
state.next_output_byte = cinfo->dest->next_output_byte;
|
state.next_output_byte = cinfo->dest->next_output_byte;
|
||||||
state.free_in_buffer = cinfo->dest->free_in_buffer;
|
state.free_in_buffer = cinfo->dest->free_in_buffer;
|
||||||
ASSIGN_STATE(state.cur, entropy->saved);
|
state.cur = entropy->saved;
|
||||||
state.cinfo = cinfo;
|
state.cinfo = cinfo;
|
||||||
|
|
||||||
/* Flush out the last data */
|
/* Flush out the last data */
|
||||||
@@ -740,7 +720,7 @@ finish_pass_huff(j_compress_ptr cinfo)
|
|||||||
/* Update state */
|
/* Update state */
|
||||||
cinfo->dest->next_output_byte = state.next_output_byte;
|
cinfo->dest->next_output_byte = state.next_output_byte;
|
||||||
cinfo->dest->free_in_buffer = state.free_in_buffer;
|
cinfo->dest->free_in_buffer = state.free_in_buffer;
|
||||||
ASSIGN_STATE(entropy->saved, state.cur);
|
entropy->saved = state.cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
26
jdhuff.c
26
jdhuff.c
@@ -40,24 +40,6 @@ typedef struct {
|
|||||||
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
|
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
|
||||||
} savable_state;
|
} savable_state;
|
||||||
|
|
||||||
/* This macro is to work around compilers with missing or broken
|
|
||||||
* structure assignment. You'll need to fix this code if you have
|
|
||||||
* such a compiler and you change MAX_COMPS_IN_SCAN.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NO_STRUCT_ASSIGN
|
|
||||||
#define ASSIGN_STATE(dest, src) ((dest) = (src))
|
|
||||||
#else
|
|
||||||
#if MAX_COMPS_IN_SCAN == 4
|
|
||||||
#define ASSIGN_STATE(dest, src) \
|
|
||||||
((dest).last_dc_val[0] = (src).last_dc_val[0], \
|
|
||||||
(dest).last_dc_val[1] = (src).last_dc_val[1], \
|
|
||||||
(dest).last_dc_val[2] = (src).last_dc_val[2], \
|
|
||||||
(dest).last_dc_val[3] = (src).last_dc_val[3])
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct jpeg_entropy_decoder pub; /* public fields */
|
struct jpeg_entropy_decoder pub; /* public fields */
|
||||||
|
|
||||||
@@ -569,7 +551,7 @@ decode_mcu_slow(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
|
|
||||||
/* Load up working state */
|
/* Load up working state */
|
||||||
BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
|
BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
|
||||||
ASSIGN_STATE(state, entropy->saved);
|
state = entropy->saved;
|
||||||
|
|
||||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||||
JBLOCKROW block = MCU_data ? MCU_data[blkn] : NULL;
|
JBLOCKROW block = MCU_data ? MCU_data[blkn] : NULL;
|
||||||
@@ -654,7 +636,7 @@ decode_mcu_slow(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
|
|
||||||
/* Completed MCU, so update state */
|
/* Completed MCU, so update state */
|
||||||
BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
|
BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
|
||||||
ASSIGN_STATE(entropy->saved, state);
|
entropy->saved = state;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -672,7 +654,7 @@ decode_mcu_fast(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
/* Load up working state */
|
/* Load up working state */
|
||||||
BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
|
BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
|
||||||
buffer = (JOCTET *)br_state.next_input_byte;
|
buffer = (JOCTET *)br_state.next_input_byte;
|
||||||
ASSIGN_STATE(state, entropy->saved);
|
state = entropy->saved;
|
||||||
|
|
||||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||||
JBLOCKROW block = MCU_data ? MCU_data[blkn] : NULL;
|
JBLOCKROW block = MCU_data ? MCU_data[blkn] : NULL;
|
||||||
@@ -741,7 +723,7 @@ decode_mcu_fast(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
br_state.bytes_in_buffer -= (buffer - br_state.next_input_byte);
|
br_state.bytes_in_buffer -= (buffer - br_state.next_input_byte);
|
||||||
br_state.next_input_byte = buffer;
|
br_state.next_input_byte = buffer;
|
||||||
BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
|
BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
|
||||||
ASSIGN_STATE(entropy->saved, state);
|
entropy->saved = state;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
25
jdphuff.c
25
jdphuff.c
@@ -4,7 +4,7 @@
|
|||||||
* This file was part of the Independent JPEG Group's software:
|
* This file was part of the Independent JPEG Group's software:
|
||||||
* Copyright (C) 1995-1997, Thomas G. Lane.
|
* Copyright (C) 1995-1997, Thomas G. Lane.
|
||||||
* libjpeg-turbo Modifications:
|
* libjpeg-turbo Modifications:
|
||||||
* Copyright (C) 2015-2016, 2018, D. R. Commander.
|
* Copyright (C) 2015-2016, 2018-2019, D. R. Commander.
|
||||||
* For conditions of distribution and use, see the accompanying README.ijg
|
* For conditions of distribution and use, see the accompanying README.ijg
|
||||||
* file.
|
* file.
|
||||||
*
|
*
|
||||||
@@ -41,25 +41,6 @@ typedef struct {
|
|||||||
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
|
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
|
||||||
} savable_state;
|
} savable_state;
|
||||||
|
|
||||||
/* This macro is to work around compilers with missing or broken
|
|
||||||
* structure assignment. You'll need to fix this code if you have
|
|
||||||
* such a compiler and you change MAX_COMPS_IN_SCAN.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NO_STRUCT_ASSIGN
|
|
||||||
#define ASSIGN_STATE(dest, src) ((dest) = (src))
|
|
||||||
#else
|
|
||||||
#if MAX_COMPS_IN_SCAN == 4
|
|
||||||
#define ASSIGN_STATE(dest, src) \
|
|
||||||
((dest).EOBRUN = (src).EOBRUN, \
|
|
||||||
(dest).last_dc_val[0] = (src).last_dc_val[0], \
|
|
||||||
(dest).last_dc_val[1] = (src).last_dc_val[1], \
|
|
||||||
(dest).last_dc_val[2] = (src).last_dc_val[2], \
|
|
||||||
(dest).last_dc_val[3] = (src).last_dc_val[3])
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct jpeg_entropy_decoder pub; /* public fields */
|
struct jpeg_entropy_decoder pub; /* public fields */
|
||||||
|
|
||||||
@@ -323,7 +304,7 @@ decode_mcu_DC_first(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
|
|
||||||
/* Load up working state */
|
/* Load up working state */
|
||||||
BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
|
BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
|
||||||
ASSIGN_STATE(state, entropy->saved);
|
state = entropy->saved;
|
||||||
|
|
||||||
/* Outer loop handles each block in the MCU */
|
/* Outer loop handles each block in the MCU */
|
||||||
|
|
||||||
@@ -356,7 +337,7 @@ decode_mcu_DC_first(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
|
|
||||||
/* Completed MCU, so update state */
|
/* Completed MCU, so update state */
|
||||||
BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
|
BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
|
||||||
ASSIGN_STATE(entropy->saved, state);
|
entropy->saved = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Account for restart interval (no-op if not using restarts) */
|
/* Account for restart interval (no-op if not using restarts) */
|
||||||
|
|||||||
Reference in New Issue
Block a user