Skip to content

Commit 00a5af4

Browse files
prraceslowhog
authored andcommitted
8248574: Improve jpeg processing
Reviewed-by: serb, jdv, mschoene, rhalade
1 parent 036da99 commit 00a5af4

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

src/java.desktop/share/native/libjavajpeg/jdhuff.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
121121
compptr = cinfo->cur_comp_info[ci];
122122
/* Precalculate which table to use for each block */
123123
entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
124-
entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
124+
entropy->ac_cur_tbls[blkn] = /* AC needs no table when not present */
125+
cinfo->lim_Se ? entropy->ac_derived_tbls[compptr->ac_tbl_no] : NULL;
125126
/* Decide whether we really care about the coefficient values */
126127
if (compptr->component_needed) {
127128
entropy->dc_needed[blkn] = TRUE;

src/java.desktop/share/native/libjavajpeg/jdinput.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,39 @@ initial_setup (j_decompress_ptr cinfo)
7474
compptr->v_samp_factor);
7575
}
7676

77+
/* Derive lim_Se */
78+
if (cinfo->is_baseline || (cinfo->progressive_mode &&
79+
cinfo->comps_in_scan)) { /* no pseudo SOS marker */
80+
cinfo->lim_Se = DCTSIZE2-1;
81+
} else {
82+
switch (cinfo->Se) {
83+
case (1*1-1):
84+
case (2*2-1):
85+
case (3*3-1):
86+
case (4*4-1):
87+
case (5*5-1):
88+
case (6*6-1):
89+
case (7*7-1):
90+
cinfo->lim_Se = cinfo->Se;
91+
break;
92+
case (8*8-1):
93+
case (9*9-1):
94+
case (10*10-1):
95+
case (11*11-1):
96+
case (12*12-1):
97+
case (13*13-1):
98+
case (14*14-1):
99+
case (15*15-1):
100+
case (16*16-1):
101+
cinfo->lim_Se = DCTSIZE2-1;
102+
break;
103+
default:
104+
ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
105+
cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
106+
break;
107+
}
108+
}
109+
77110
/* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE.
78111
* In the full decompressor, this will be overridden by jdmaster.c;
79112
* but in the transcoder, jdmaster.c is not used, so we must do it here.

src/java.desktop/share/native/libjavajpeg/jdmarker.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,15 @@ get_soi (j_decompress_ptr cinfo)
238238

239239

240240
LOCAL(boolean)
241-
get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
241+
get_sof (j_decompress_ptr cinfo, boolean is_baseline, boolean is_prog, boolean is_arith)
242242
/* Process a SOFn marker */
243243
{
244244
INT32 length;
245245
int c, ci;
246246
jpeg_component_info * compptr;
247247
INPUT_VARS(cinfo);
248248

249+
cinfo->is_baseline = is_baseline;
249250
cinfo->progressive_mode = is_prog;
250251
cinfo->arith_code = is_arith;
251252

@@ -998,23 +999,27 @@ read_markers (j_decompress_ptr cinfo)
998999
break;
9991000

10001001
case M_SOF0: /* Baseline */
1002+
if (! get_sof(cinfo, TRUE, FALSE, FALSE))
1003+
return JPEG_SUSPENDED;
1004+
break;
1005+
10011006
case M_SOF1: /* Extended sequential, Huffman */
1002-
if (! get_sof(cinfo, FALSE, FALSE))
1007+
if (! get_sof(cinfo, FALSE, FALSE, FALSE))
10031008
return JPEG_SUSPENDED;
10041009
break;
10051010

10061011
case M_SOF2: /* Progressive, Huffman */
1007-
if (! get_sof(cinfo, TRUE, FALSE))
1012+
if (! get_sof(cinfo, FALSE, TRUE, FALSE))
10081013
return JPEG_SUSPENDED;
10091014
break;
10101015

10111016
case M_SOF9: /* Extended sequential, arithmetic */
1012-
if (! get_sof(cinfo, FALSE, TRUE))
1017+
if (! get_sof(cinfo, FALSE, FALSE, TRUE))
10131018
return JPEG_SUSPENDED;
10141019
break;
10151020

10161021
case M_SOF10: /* Progressive, arithmetic */
1017-
if (! get_sof(cinfo, TRUE, TRUE))
1022+
if (! get_sof(cinfo, FALSE, TRUE, TRUE))
10181023
return JPEG_SUSPENDED;
10191024
break;
10201025

src/java.desktop/share/native/libjavajpeg/jmemnobs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,16 @@ jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
7070

7171
/*
7272
* This routine computes the total memory space available for allocation.
73-
* Here we always say, "we got all you want bud!"
7473
*/
7574

7675
GLOBAL(size_t)
7776
jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed,
7877
size_t max_bytes_needed, size_t already_allocated)
7978
{
79+
if (cinfo->mem->max_memory_to_use)
80+
return cinfo->mem->max_memory_to_use - already_allocated;
81+
82+
/* Here we say, "we got all you want bud!" */
8083
return max_bytes_needed;
8184
}
8285

src/java.desktop/share/native/libjavajpeg/jpeglib.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ struct jpeg_decompress_struct {
539539
jpeg_component_info * comp_info;
540540
/* comp_info[i] describes component that appears i'th in SOF */
541541

542+
boolean is_baseline; /* TRUE if Baseline SOF0 encountered */
542543
boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
543544
boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
544545

@@ -611,6 +612,8 @@ struct jpeg_decompress_struct {
611612

612613
int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
613614

615+
int lim_Se; /* min( Se, DCTSIZE2-1 ) for entropy decode */
616+
614617
/* This field is shared between entropy decoder and marker parser.
615618
* It is either zero or the code of a JPEG marker that has been
616619
* read from the data source, but has not yet been processed.

0 commit comments

Comments
 (0)