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) */