8248574: Improve jpeg processing

Thu, 02 Jul 2020 12:02:08 -0700

author
prr
date
Thu, 02 Jul 2020 12:02:08 -0700
changeset 14220
276130887f7b
parent 14219
0c138a67e647
child 14221
badfd40f15ac

8248574: Improve jpeg processing
Reviewed-by: serb, jdv, mschoene, rhalade

src/share/native/sun/awt/image/jpeg/jdhuff.c file | annotate | diff | comparison | revisions
src/share/native/sun/awt/image/jpeg/jdinput.c file | annotate | diff | comparison | revisions
src/share/native/sun/awt/image/jpeg/jdmarker.c file | annotate | diff | comparison | revisions
src/share/native/sun/awt/image/jpeg/jmemnobs.c file | annotate | diff | comparison | revisions
src/share/native/sun/awt/image/jpeg/jpeglib.h file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/native/sun/awt/image/jpeg/jdhuff.c	Sat Oct 17 02:55:07 2020 +0100
     1.2 +++ b/src/share/native/sun/awt/image/jpeg/jdhuff.c	Thu Jul 02 12:02:08 2020 -0700
     1.3 @@ -121,7 +121,8 @@
     1.4      compptr = cinfo->cur_comp_info[ci];
     1.5      /* Precalculate which table to use for each block */
     1.6      entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
     1.7 -    entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
     1.8 +    entropy->ac_cur_tbls[blkn] =    /* AC needs no table when not present */
     1.9 +      cinfo->lim_Se ? entropy->ac_derived_tbls[compptr->ac_tbl_no] : NULL;
    1.10      /* Decide whether we really care about the coefficient values */
    1.11      if (compptr->component_needed) {
    1.12        entropy->dc_needed[blkn] = TRUE;
     2.1 --- a/src/share/native/sun/awt/image/jpeg/jdinput.c	Sat Oct 17 02:55:07 2020 +0100
     2.2 +++ b/src/share/native/sun/awt/image/jpeg/jdinput.c	Thu Jul 02 12:02:08 2020 -0700
     2.3 @@ -74,6 +74,39 @@
     2.4                                     compptr->v_samp_factor);
     2.5    }
     2.6  
     2.7 +  /* Derive lim_Se */
     2.8 +  if (cinfo->is_baseline || (cinfo->progressive_mode &&
     2.9 +      cinfo->comps_in_scan)) { /* no pseudo SOS marker */
    2.10 +    cinfo->lim_Se = DCTSIZE2-1;
    2.11 +  } else {
    2.12 +    switch (cinfo->Se) {
    2.13 +    case (1*1-1):
    2.14 +    case (2*2-1):
    2.15 +    case (3*3-1):
    2.16 +    case (4*4-1):
    2.17 +    case (5*5-1):
    2.18 +    case (6*6-1):
    2.19 +    case (7*7-1):
    2.20 +         cinfo->lim_Se = cinfo->Se;
    2.21 +         break;
    2.22 +    case (8*8-1):
    2.23 +    case (9*9-1):
    2.24 +    case (10*10-1):
    2.25 +    case (11*11-1):
    2.26 +    case (12*12-1):
    2.27 +    case (13*13-1):
    2.28 +    case (14*14-1):
    2.29 +    case (15*15-1):
    2.30 +    case (16*16-1):
    2.31 +         cinfo->lim_Se = DCTSIZE2-1;
    2.32 +         break;
    2.33 +    default:
    2.34 +      ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
    2.35 +               cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
    2.36 +      break;
    2.37 +    }
    2.38 +  }
    2.39 +
    2.40    /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE.
    2.41     * In the full decompressor, this will be overridden by jdmaster.c;
    2.42     * but in the transcoder, jdmaster.c is not used, so we must do it here.
     3.1 --- a/src/share/native/sun/awt/image/jpeg/jdmarker.c	Sat Oct 17 02:55:07 2020 +0100
     3.2 +++ b/src/share/native/sun/awt/image/jpeg/jdmarker.c	Thu Jul 02 12:02:08 2020 -0700
     3.3 @@ -238,7 +238,7 @@
     3.4  
     3.5  
     3.6  LOCAL(boolean)
     3.7 -get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
     3.8 +get_sof (j_decompress_ptr cinfo, boolean is_baseline, boolean is_prog, boolean is_arith)
     3.9  /* Process a SOFn marker */
    3.10  {
    3.11    INT32 length;
    3.12 @@ -246,6 +246,7 @@
    3.13    jpeg_component_info * compptr;
    3.14    INPUT_VARS(cinfo);
    3.15  
    3.16 +  cinfo->is_baseline = is_baseline;
    3.17    cinfo->progressive_mode = is_prog;
    3.18    cinfo->arith_code = is_arith;
    3.19  
    3.20 @@ -998,23 +999,27 @@
    3.21        break;
    3.22  
    3.23      case M_SOF0:                /* Baseline */
    3.24 +      if (! get_sof(cinfo, TRUE, FALSE, FALSE))
    3.25 +        return JPEG_SUSPENDED;
    3.26 +      break;
    3.27 +
    3.28      case M_SOF1:                /* Extended sequential, Huffman */
    3.29 -      if (! get_sof(cinfo, FALSE, FALSE))
    3.30 +      if (! get_sof(cinfo, FALSE, FALSE, FALSE))
    3.31          return JPEG_SUSPENDED;
    3.32        break;
    3.33  
    3.34      case M_SOF2:                /* Progressive, Huffman */
    3.35 -      if (! get_sof(cinfo, TRUE, FALSE))
    3.36 +      if (! get_sof(cinfo, FALSE, TRUE, FALSE))
    3.37          return JPEG_SUSPENDED;
    3.38        break;
    3.39  
    3.40      case M_SOF9:                /* Extended sequential, arithmetic */
    3.41 -      if (! get_sof(cinfo, FALSE, TRUE))
    3.42 +      if (! get_sof(cinfo, FALSE, FALSE, TRUE))
    3.43          return JPEG_SUSPENDED;
    3.44        break;
    3.45  
    3.46      case M_SOF10:               /* Progressive, arithmetic */
    3.47 -      if (! get_sof(cinfo, TRUE, TRUE))
    3.48 +      if (! get_sof(cinfo, FALSE, TRUE, TRUE))
    3.49          return JPEG_SUSPENDED;
    3.50        break;
    3.51  
     4.1 --- a/src/share/native/sun/awt/image/jpeg/jmemnobs.c	Sat Oct 17 02:55:07 2020 +0100
     4.2 +++ b/src/share/native/sun/awt/image/jpeg/jmemnobs.c	Thu Jul 02 12:02:08 2020 -0700
     4.3 @@ -70,13 +70,16 @@
     4.4  
     4.5  /*
     4.6   * This routine computes the total memory space available for allocation.
     4.7 - * Here we always say, "we got all you want bud!"
     4.8   */
     4.9  
    4.10  GLOBAL(size_t)
    4.11  jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed,
    4.12                      size_t max_bytes_needed, size_t already_allocated)
    4.13  {
    4.14 +  if (cinfo->mem->max_memory_to_use)
    4.15 +    return cinfo->mem->max_memory_to_use - already_allocated;
    4.16 +
    4.17 +  /* Here we say, "we got all you want bud!" */
    4.18    return max_bytes_needed;
    4.19  }
    4.20  
     5.1 --- a/src/share/native/sun/awt/image/jpeg/jpeglib.h	Sat Oct 17 02:55:07 2020 +0100
     5.2 +++ b/src/share/native/sun/awt/image/jpeg/jpeglib.h	Thu Jul 02 12:02:08 2020 -0700
     5.3 @@ -539,6 +539,7 @@
     5.4    jpeg_component_info * comp_info;
     5.5    /* comp_info[i] describes component that appears i'th in SOF */
     5.6  
     5.7 +  boolean is_baseline;          /* TRUE if Baseline SOF0 encountered */
     5.8    boolean progressive_mode;     /* TRUE if SOFn specifies progressive mode */
     5.9    boolean arith_code;           /* TRUE=arithmetic coding, FALSE=Huffman */
    5.10  
    5.11 @@ -611,6 +612,8 @@
    5.12  
    5.13    int Ss, Se, Ah, Al;           /* progressive JPEG parameters for scan */
    5.14  
    5.15 +  int lim_Se;                   /* min( Se, DCTSIZE2-1 ) for entropy decode */
    5.16 +
    5.17    /* This field is shared between entropy decoder and marker parser.
    5.18     * It is either zero or the code of a JPEG marker that has been
    5.19     * read from the data source, but has not yet been processed.

mercurial