1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Graphics: Modify imported libjpeg sources for unity build compatibility

This commit is contained in:
Oli 2025-06-12 12:25:21 +01:00 committed by Oliver James
parent 34c8704a25
commit 8fd73d33a8
11 changed files with 200 additions and 101 deletions

View file

@ -6,10 +6,34 @@ If you want to get hold of the full version of libjpeg, it's freely available at
http://www.ijg.org/
Some source code changes were required to make this JUCE compatible, they are as follows:
* Some struct properties had to be renamed:
* jpegint.h: jpeg_entropy_decoder::decode_mcu
* jpegint.h: jpeg_entropy_decoder::start_pass
* jpegint.h: jpeg_entropy_decoder::finish_pass
References:
- jdarith.c
- jdhuff.c
- jdinput.c
- jdcoefct.c
* jpegint.h: jpeg_d_coef_controller::start_input_pass
References:
- jdcoefct.c
- jdinput.c
* jdmarker.c: Comment out duplicate JPEG_MARKER enum definition.
References:
- jcmarker.c
* jmemnobs.c: Comment out "jmemsys.h" include.
* jconfig.h: Comment out _WIN32 ifdef to force boolean to be unsigned char on all
platforms.
Please note that part of the IJG's license for libjpeg states that:
"If you use it in a program, you must acknowledge somewhere in
"If you use it in a program, you must acknowledge somewhere in
your documentation that you've used the IJG code".
..so if you release a JUCE program that reads JPEGs, you should probably give them a mention.

View file

@ -8,7 +8,7 @@
*
* This file contains master control logic for the JPEG compressor.
* These routines are concerned with parameter validation, initial setup,
* and inter-pass control (determining the number of passes and the work
* and inter-pass control (determining the number of passes and the work
* to be done in each pass).
*/
@ -201,7 +201,7 @@ validate_script (j_compress_ptr cinfo)
#ifdef C_PROGRESSIVE_SUPPORTED
cinfo->progressive_mode = TRUE;
last_bitpos_ptr = & last_bitpos[0][0];
for (ci = 0; ci < cinfo->num_components; ci++)
for (ci = 0; ci < cinfo->num_components; ci++)
for (coefi = 0; coefi < DCTSIZE2; coefi++)
*last_bitpos_ptr++ = -1;
#else
@ -209,7 +209,7 @@ validate_script (j_compress_ptr cinfo)
#endif
} else {
cinfo->progressive_mode = FALSE;
for (ci = 0; ci < cinfo->num_components; ci++)
for (ci = 0; ci < cinfo->num_components; ci++)
component_sent[ci] = FALSE;
}

View file

@ -94,7 +94,7 @@
/* Define "boolean" as unsigned char, not enum, on Windows systems.
*/
#ifdef _WIN32
//#ifdef _WIN32
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean;
#endif
@ -105,7 +105,7 @@ typedef unsigned char boolean;
#define TRUE 1
#endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
#endif
//#endif
/*

View file

@ -689,14 +689,14 @@ start_pass (j_decompress_ptr cinfo)
/* Select MCU decoding routine */
if (cinfo->Ah == 0) {
if (cinfo->Ss == 0)
entropy->pub.decode_mcu = decode_mcu_DC_first;
entropy->pub.decode_mcu_f = decode_mcu_DC_first;
else
entropy->pub.decode_mcu = decode_mcu_AC_first;
entropy->pub.decode_mcu_f = decode_mcu_AC_first;
} else {
if (cinfo->Ss == 0)
entropy->pub.decode_mcu = decode_mcu_DC_refine;
entropy->pub.decode_mcu_f = decode_mcu_DC_refine;
else
entropy->pub.decode_mcu = decode_mcu_AC_refine;
entropy->pub.decode_mcu_f = decode_mcu_AC_refine;
}
} else {
/* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.
@ -706,7 +706,7 @@ start_pass (j_decompress_ptr cinfo)
(cinfo->Se < DCTSIZE2 && cinfo->Se != cinfo->lim_Se))
WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
/* Select MCU decoding routine */
entropy->pub.decode_mcu = decode_mcu;
entropy->pub.decode_mcu_f = decode_mcu;
}
/* Allocate & initialize requested statistics areas */
@ -770,8 +770,8 @@ jinit_arith_decoder (j_decompress_ptr cinfo)
entropy = (arith_entropy_ptr) (*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(arith_entropy_decoder));
cinfo->entropy = &entropy->pub;
entropy->pub.start_pass = start_pass;
entropy->pub.finish_pass = finish_pass;
entropy->pub.start_pass_f = start_pass;
entropy->pub.finish_pass_f = finish_pass;
/* Mark tables unallocated */
for (i = 0; i < NUM_ARITH_TBLS; i++) {
@ -789,7 +789,7 @@ jinit_arith_decoder (j_decompress_ptr cinfo)
((j_common_ptr) cinfo, JPOOL_IMAGE,
cinfo->num_components * DCTSIZE2 * SIZEOF(int));
coef_bit_ptr = & cinfo->coef_bits[0][0];
for (ci = 0; ci < cinfo->num_components; ci++)
for (ci = 0; ci < cinfo->num_components; ci++)
for (i = 0; i < DCTSIZE2; i++)
*coef_bit_ptr++ = -1;
}

View file

@ -170,7 +170,7 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
/* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */
if (cinfo->lim_Se) /* can bypass in DC only case */
MEMZERO(blkp, cinfo->blocks_in_MCU * SIZEOF(JBLOCK));
if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
if (! (*cinfo->entropy->decode_mcu_f) (cinfo, coef->MCU_buffer)) {
/* Suspension forced; update state counters and exit */
coef->MCU_vert_offset = yoffset;
coef->MCU_ctr = MCU_col_num;
@ -287,7 +287,7 @@ consume_data (j_decompress_ptr cinfo)
}
}
/* Try to fetch the MCU. */
if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
if (! (*cinfo->entropy->decode_mcu_f) (cinfo, coef->MCU_buffer)) {
/* Suspension forced; update state counters and exit */
coef->MCU_vert_offset = yoffset;
coef->MCU_ctr = MCU_col_num;
@ -735,7 +735,7 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
}
coef->pub.start_input_pass = start_input_pass;
coef->pub.start_input_pass_f = start_input_pass;
coef->pub.start_output_pass = start_output_pass;
#ifdef BLOCK_SMOOTHING_SUPPORTED
coef->coef_bits_latch = NULL;

View file

@ -349,7 +349,7 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(d_derived_tbl));
dtbl = *pdtbl;
dtbl->pub = htbl; /* fill in back link */
/* Figure C.1: make table of Huffman code length for each symbol */
p = 0;
@ -362,10 +362,10 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
}
huffsize[p] = 0;
numsymbols = p;
/* Figure C.2: generate the codes themselves */
/* We also validate that the counts represent a legal Huffman code tree. */
code = 0;
si = huffsize[0];
p = 0;
@ -683,7 +683,7 @@ process_restart (j_decompress_ptr cinfo)
/*
* Huffman MCU decoding.
* Each of these routines decodes and returns one MCU's worth of
* Huffman-compressed coefficients.
* Huffman-compressed coefficients.
* The coefficients are reordered from zigzag order into natural array order,
* but are not dequantized.
*
@ -1380,14 +1380,14 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
/* Select MCU decoding routine */
if (cinfo->Ah == 0) {
if (cinfo->Ss == 0)
entropy->pub.decode_mcu = decode_mcu_DC_first;
entropy->pub.decode_mcu_f = decode_mcu_DC_first;
else
entropy->pub.decode_mcu = decode_mcu_AC_first;
entropy->pub.decode_mcu_f = decode_mcu_AC_first;
} else {
if (cinfo->Ss == 0)
entropy->pub.decode_mcu = decode_mcu_DC_refine;
entropy->pub.decode_mcu_f = decode_mcu_DC_refine;
else
entropy->pub.decode_mcu = decode_mcu_AC_refine;
entropy->pub.decode_mcu_f = decode_mcu_AC_refine;
}
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
@ -1432,9 +1432,9 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
* function.
*/
if (cinfo->lim_Se != DCTSIZE2-1)
entropy->pub.decode_mcu = decode_mcu_sub;
entropy->pub.decode_mcu_f = decode_mcu_sub;
else
entropy->pub.decode_mcu = decode_mcu;
entropy->pub.decode_mcu_f = decode_mcu;
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci];
@ -1532,8 +1532,8 @@ jinit_huff_decoder (j_decompress_ptr cinfo)
entropy = (huff_entropy_ptr) (*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(huff_entropy_decoder));
cinfo->entropy = &entropy->pub;
entropy->pub.start_pass = start_pass_huff_decoder;
entropy->pub.finish_pass = finish_pass_huff;
entropy->pub.start_pass_f = start_pass_huff_decoder;
entropy->pub.finish_pass_f = finish_pass_huff;
if (cinfo->progressive_mode) {
/* Create progression status table */

View file

@ -518,8 +518,8 @@ start_input_pass (j_decompress_ptr cinfo)
{
per_scan_setup(cinfo);
latch_quant_tables(cinfo);
(*cinfo->entropy->start_pass) (cinfo);
(*cinfo->coef->start_input_pass) (cinfo);
(*cinfo->entropy->start_pass_f) (cinfo);
(*cinfo->coef->start_input_pass_f) (cinfo);
cinfo->inputctl->consume_input = cinfo->coef->consume_data;
}
@ -533,7 +533,7 @@ start_input_pass (j_decompress_ptr cinfo)
METHODDEF(void)
finish_input_pass (j_decompress_ptr cinfo)
{
(*cinfo->entropy->finish_pass) (cinfo);
(*cinfo->entropy->finish_pass_f) (cinfo);
cinfo->inputctl->consume_input = consume_markers;
}

View file

@ -18,7 +18,7 @@
#include "jpeglib.h"
typedef enum { /* JPEG marker codes */
/*typedef enum {
M_SOF0 = 0xc0,
M_SOF1 = 0xc1,
M_SOF2 = 0xc2,
@ -84,7 +84,7 @@ typedef enum { /* JPEG marker codes */
M_TEM = 0x01,
M_ERROR = 0x100
} JPEG_MARKER;
} JPEG_MARKER;*/
/* Private state */
@ -200,7 +200,7 @@ get_soi (j_decompress_ptr cinfo)
/* Process an SOI marker */
{
int i;
TRACEMS(cinfo, 1, JTRC_SOI);
if (cinfo->marker->saw_SOI)
@ -419,7 +419,7 @@ get_dac (j_decompress_ptr cinfo)
INPUT_2BYTES(cinfo, length, return FALSE);
length -= 2;
while (length > 0) {
INPUT_BYTE(cinfo, index, return FALSE);
INPUT_BYTE(cinfo, val, return FALSE);
@ -468,12 +468,12 @@ get_dht (j_decompress_ptr cinfo)
INPUT_2BYTES(cinfo, length, return FALSE);
length -= 2;
while (length > 16) {
INPUT_BYTE(cinfo, index, return FALSE);
TRACEMS1(cinfo, 1, JTRC_DHT, index);
bits[0] = 0;
count = 0;
for (i = 1; i <= 16; i++) {
@ -513,7 +513,7 @@ get_dht (j_decompress_ptr cinfo)
if (*htblptr == NULL)
*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
if (count > 0)
MEMCOPY((*htblptr)->huffval, huffval, count * SIZEOF(UINT8));
@ -551,7 +551,7 @@ get_dqt (j_decompress_ptr cinfo)
if (n >= NUM_QUANT_TBLS)
ERREXIT1(cinfo, JERR_DQT_INDEX, n);
if (cinfo->quant_tbl_ptrs[n] == NULL)
cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
quant_ptr = cinfo->quant_tbl_ptrs[n];
@ -626,7 +626,7 @@ get_dri (j_decompress_ptr cinfo)
INPUT_VARS(cinfo);
INPUT_2BYTES(cinfo, length, return FALSE);
if (length != 4)
ERREXIT(cinfo, JERR_BAD_LENGTH);
@ -983,7 +983,7 @@ skip_variable (j_decompress_ptr cinfo)
INPUT_2BYTES(cinfo, length, return FALSE);
length -= 2;
TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
INPUT_SYNC(cinfo); /* do before skip_input_data */
@ -1339,10 +1339,10 @@ jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
{
int marker = cinfo->unread_marker;
int action = 1;
/* Always put up a warning. */
WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
/* Outer loop handles repeated decision after scanning forward. */
for (;;) {
if (marker < (int) M_SOF0)

View file

@ -19,7 +19,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglib.h"
#include "jmemsys.h" /* import the system-dependent declarations */
//#include "jmemsys.h" /* import the system-dependent declarations */
#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
extern void * malloc JPP((size_t size));

View file

@ -166,7 +166,7 @@ struct jpeg_d_main_controller {
/* Coefficient buffer control */
struct jpeg_d_coef_controller {
JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
JMETHOD(void, start_input_pass_f, (j_decompress_ptr cinfo));
JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
@ -209,9 +209,9 @@ struct jpeg_marker_reader {
/* Entropy decoding */
struct jpeg_entropy_decoder {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data));
JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
JMETHOD(void, start_pass_f, (j_decompress_ptr cinfo));
JMETHOD(boolean, decode_mcu_f, (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data));
JMETHOD(void, finish_pass_f, (j_decompress_ptr cinfo));
};
/* Inverse DCT (also performs dequantization) */

View file

@ -35,7 +35,7 @@
namespace juce
{
JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4365 6240 6326 6386 6385 28182 28183 6387 6011 6001)
JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4100 4127 4365 4996 5033 6240 6326 6386 6385 28182 28183 6387 6011 6001)
namespace jpeglibNamespace
{
@ -50,81 +50,156 @@ namespace jpeglibNamespace
"-Wimplicit-fallthrough",
"-Wzero-as-null-pointer-constant",
"-Wshift-negative-value",
"-Wcomma")
#define JPEG_INTERNALS
#undef FAR
#include "jpglib/jpeglib.h"
"-Wcomma",
"-Wunused-parameter",
"-Wregister",
"-Wredundant-decls")
#include "jpglib/jaricom.c"
#include "jpglib/jcapimin.c"
#include "jpglib/jcapistd.c"
#include "jpglib/jcarith.c"
#include "jpglib/jccoefct.c"
#include "jpglib/jccolor.c"
#undef FIX
#include "jpglib/jcdctmgr.c"
#undef CONST_BITS
#include "jpglib/jchuff.c"
#undef emit_byte
#include "jpglib/jcinit.c"
#include "jpglib/jcmainct.c"
#include "jpglib/jcmarker.c"
#include "jpglib/jcmaster.c"
#include "jpglib/jcomapi.c"
#include "jpglib/jcparam.c"
#include "jpglib/jcphuff.c"
#include "jpglib/jcprepct.c"
#include "jpglib/jcsample.c"
#include "jpglib/jctrans.c"
#include "jpglib/jdapistd.c"
#include "jpglib/jdapimin.c"
#include "jpglib/jdapistd.c"
#include "jpglib/jdatadst.c"
#include "jpglib/jdatasrc.c"
#include "jpglib/jdcoefct.c"
#undef FIX
#include "jpglib/jdcolor.c"
#undef FIX
#include "jpglib/jddctmgr.c"
#undef CONST_BITS
#undef ASSIGN_STATE
#include "jpglib/jdhuff.c"
#include "jpglib/jdinput.c"
#include "jpglib/jdmainct.c"
#include "jpglib/jdmarker.c"
#include "jpglib/jdmaster.c"
#undef FIX
#include "jpglib/jdmerge.c"
#undef ASSIGN_STATE
#include "jpglib/jdphuff.c"
#include "jpglib/jdpostct.c"
#undef FIX
#include "jpglib/jdsample.c"
#include "jpglib/jdtrans.c"
#include "jpglib/jfdctflt.c"
#include "jpglib/jfdctint.c"
#undef CONST_BITS
#undef MULTIPLY
#undef FIX_0_541196100
#include "jpglib/jfdctfst.c"
#undef FIX_0_541196100
#include "jpglib/jidctflt.c"
#undef CONST_BITS
#undef FIX_1_847759065
#undef MULTIPLY
#undef DEQUANTIZE
#undef DESCALE
#include "jpglib/jidctfst.c"
#undef CONST_BITS
#undef FIX_1_847759065
#undef MULTIPLY
#undef DEQUANTIZE
#include "jpglib/jidctint.c"
#include "jpglib/jidctred.c"
#include "jpglib/jmemmgr.c"
#include "jpglib/jmemnobs.c"
#include "jpglib/jquant1.c"
#include "jpglib/jquant2.c"
#include "jpglib/jutils.c"
#include "jpglib/transupp.c"
#undef FIX
#include "jpglib/jdtrans.c"
#include "jpglib/jerror.c"
#include "jpglib/jfdctflt.c"
#undef CONST_BITS
#include "jpglib/jfdctfst.c"
#undef CONST_BITS
#undef FIX_0_541196100
#undef MULTIPLY
#include "jpglib/jfdctint.c"
#include "jpglib/jidctflt.c"
#undef CONST_BITS
#undef FIX_1_847759065
#undef DEQUANTIZE
#undef MULTIPLY
#include "jpglib/jidctfst.c"
#undef CONST_BITS
#undef FIX_1_847759065
#undef DEQUANTIZE
#undef MULTIPLY
#include "jpglib/jidctint.c"
#include "jpglib/jquant1.c"
#include "jpglib/jutils.c"
#include "jpglib/jmemmgr.c"
#define savable_state savable_state_jchuff
#define huff_entropy_ptr huff_entropy_ptr_jchuff
#define encode_mcu_DC_first encode_mcu_DC_first_jchuff
#define encode_mcu_AC_first encode_mcu_AC_first_jchuff
#define encode_mcu_DC_refine encode_mcu_DC_refine_jchuff
#define encode_mcu_AC_refine encode_mcu_AC_refine_jchuff
#include "jpglib/jchuff.c"
#undef encode_mcu_DC_first
#undef encode_mcu_AC_first
#undef encode_mcu_DC_refine
#undef encode_mcu_AC_refine
#undef huff_entropy_ptr
#undef savable_state
#define arith_entropy_ptr arith_entropy_ptr_jdarith
#define process_restart process_restart_jdarith
#define start_pass start_pass_jdarith
#define decode_mcu decode_mcu_jdarith
#define decode_mcu_DC_first decode_mcu_DC_first_jdarith
#define decode_mcu_AC_first decode_mcu_AC_first_jdarith
#define decode_mcu_DC_refine decode_mcu_DC_refine_jdarith
#define decode_mcu_AC_refine decode_mcu_AC_refine_jdarith
#include "jpglib/jdarith.c"
#undef decode_mcu_AC_refine
#undef decode_mcu_DC_refine
#undef decode_mcu_AC_first
#undef decode_mcu_DC_first
#undef decode_mcu_AC_refine
#undef decode_mcu
#undef start_pass
#undef arith_entropy_ptr
#undef process_restart
#define my_coef_controller my_coef_controller_jctrans
#define my_coef_ptr my_coef_ptr_jctrans
#define start_iMCU_row start_iMCU_row_jctrans
#define start_pass_coef start_pass_coef_jctrans
#define compress_output compress_output_jctrans
#include "jpglib/jctrans.c"
#undef my_coef_controller
#undef my_coef_ptr
#undef start_iMCU_row
#undef start_pass_coef
#undef compress_output
#define my_coef_controller my_coef_controller_jdcoefct
#define my_coef_ptr my_coef_ptr_jdcoefct
#define start_input_pass start_input_pass_jdcoefct
#include "jpglib/jdcoefct.c"
#undef my_coef_controller
#undef my_coef_ptr
#undef start_input_pass
#undef FIX
#define my_cconvert_ptr my_cconvert_ptr_jdcolor
#define build_ycc_rgb_table build_ycc_rgb_table_jdcolor
#define build_bg_ycc_rgb_table build_bc_ycc_rgb_table_jdcolor
#include "jpglib/jdcolor.c"
#undef my_cconvert_ptr
#undef build_ycc_rgb_table
#undef build_bg_ycc_rgb_table
#define my_main_controller my_main_controller_jdmainct
#define my_main_ptr my_main_ptr_jdmainct
#include "jpglib/jdmainct.c"
#define my_master_ptr my_master_ptr_jdmainct
#include "jpglib/jdmaster.c"
#undef my_master_ptr
#define my_upsampler my_upsampler_jdsample
#define my_upsample_ptr my_upsampler_ptr_jdsample
#include "jpglib/jdsample.c"
#undef my_upsampler
#undef my_upsample_ptr
#define my_cquantizer my_cquantizer_jquant2
#define my_cquantize_ptr my_cquantize_ptr_jquant2
#include "jpglib/jquant2.c"
#undef my_cquantizer
#undef my_cquantize_ptr
#define my_marker_ptr my_marker_ptr_jdmarker
#include "jpglib/jdmarker.c"
#undef my_marker_ptr
#include "jpglib/jmemnobs.c"
JUCE_END_IGNORE_WARNINGS_GCC_LIKE
#else
#define JPEG_INTERNALS