Merge tag '2.0.0'

* tag '2.0.0': (160 commits)
  Clarify Android Windows build instructions
  Bump revision to 2.0.0
  Build: Don't use @rpath with OS X 10.4 builds
  Fix JPEG spec references per ISO/ITU-T suggestions
  Fix int overflow when decompr. corrupt prog. JPEG
  cjpeg: Fix OOB read caused by malformed 8-bit BMP
  Build: Preserve CMake exe suffix from cmd line
  Honor CMake exe suffix when inst. static builds
  README.ijg: Clarification regarding JPEG 2000/XR
  BUILDING.md: Correct iOS/Android examples
  Build: Detect whether compiler supports DSPr2
  Fix jpeg_skip_scanlines() segfault w/merged upsamp
  Fix infinite loop in partial image decompression
  tjLoadImage(): Fix FPE triggered by malformed BMP
  TurboJPEG: Handle JERR_BMP*,JERR_PPM* error codes
  Fix CVE-2018-11813
  Travis: Use SKS keyserver pool
  Additional code formatting tweaks
  Java: Further style refinements
  Java: Reformat code per checkstyle recommendations
  ...
This commit is contained in:
Kornel
2018-11-11 16:01:41 +00:00
442 changed files with 73298 additions and 54455 deletions

View File

@@ -3,16 +3,20 @@
*
* This file was part of the Independent JPEG Group's software:
* Developed 1997-2009 by Guido Vollbeding.
* It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file.
* libjpeg-turbo Modifications:
* Copyright (C) 2015, 2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
* This file contains portable arithmetic entropy encoding routines for JPEG
* (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81).
* (implementing Recommendation ITU-T T.81 | ISO/IEC 10918-1).
*
* Both sequential and progressive modes are supported in this single module.
*
* Suspension is not currently supported in this module.
*
* NOTE: All referenced figures are from
* Recommendation ITU-T T.81 (1992) | ISO/IEC 10918-1:1994.
*/
#define JPEG_INTERNALS
@@ -104,18 +108,18 @@ typedef arith_entropy_encoder *arith_entropy_ptr;
#ifdef RIGHT_SHIFT_IS_UNSIGNED
#define ISHIFT_TEMPS int ishift_temp;
#define IRIGHT_SHIFT(x,shft) \
#define IRIGHT_SHIFT(x, shft) \
((ishift_temp = (x)) < 0 ? \
(ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
(ishift_temp >> (shft)) | ((~0) << (16 - (shft))) : \
(ishift_temp >> (shft)))
#else
#define ISHIFT_TEMPS
#define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
#define IRIGHT_SHIFT(x, shft) ((x) >> (shft))
#endif
LOCAL(void)
emit_byte (int val, j_compress_ptr cinfo)
emit_byte(int val, j_compress_ptr cinfo)
/* Write next output byte; we do not support suspension in this module. */
{
struct jpeg_destination_mgr *dest = cinfo->dest;
@@ -126,7 +130,7 @@ emit_byte (int val, j_compress_ptr cinfo)
*dest->next_output_byte++ = (JOCTET) val;
if (--dest->free_in_buffer == 0)
if (! (*dest->empty_output_buffer) (cinfo))
if (!(*dest->empty_output_buffer) (cinfo))
ERREXIT(cinfo, JERR_CANT_SUSPEND);
}
@@ -136,22 +140,22 @@ emit_byte (int val, j_compress_ptr cinfo)
*/
METHODDEF(void)
finish_pass (j_compress_ptr cinfo)
finish_pass(j_compress_ptr cinfo)
{
arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy;
arith_entropy_ptr e = (arith_entropy_ptr)cinfo->entropy;
JLONG temp;
/* Section D.1.8: Termination of encoding */
/* Find the e->c in the coding interval with the largest
* number of trailing zero bits */
if ((temp = (e->a - 1 + e->c) & 0xFFFF0000L) < e->c)
if ((temp = (e->a - 1 + e->c) & 0xFFFF0000UL) < e->c)
e->c = temp + 0x8000L;
else
e->c = temp;
/* Send remaining bytes to output */
e->c <<= e->ct;
if (e->c & 0xF8000000L) {
if (e->c & 0xF8000000UL) {
/* One final overflow has to be handled */
if (e->buffer >= 0) {
if (e->zc)
@@ -222,9 +226,9 @@ finish_pass (j_compress_ptr cinfo)
*/
LOCAL(void)
arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
arith_encode(j_compress_ptr cinfo, unsigned char *st, int val)
{
register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy;
register arith_entropy_ptr e = (arith_entropy_ptr)cinfo->entropy;
register unsigned char nl, nm;
register JLONG qe, temp;
register int sv;
@@ -322,9 +326,9 @@ arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
*/
LOCAL(void)
emit_restart (j_compress_ptr cinfo, int restart_num)
emit_restart(j_compress_ptr cinfo, int restart_num)
{
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
int ci;
jpeg_component_info *compptr;
@@ -365,9 +369,9 @@ emit_restart (j_compress_ptr cinfo, int restart_num)
*/
METHODDEF(boolean)
encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
encode_mcu_DC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
JBLOCKROW block;
unsigned char *st;
int blkn, ci, tbl;
@@ -394,7 +398,7 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Compute the DC value after the required point transform by Al.
* This is simply an arithmetic right shift.
*/
m = IRIGHT_SHIFT((int) ((*block)[0]), cinfo->Al);
m = IRIGHT_SHIFT((int)((*block)[0]), cinfo->Al);
/* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */
@@ -435,9 +439,9 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
}
arith_encode(cinfo, st, 0);
/* Section F.1.4.4.1.2: Establish dc_context conditioning category */
if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))
if (m < (int)((1L << cinfo->arith_dc_L[tbl]) >> 1))
entropy->dc_context[ci] = 0; /* zero diff category */
else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))
else if (m > (int)((1L << cinfo->arith_dc_U[tbl]) >> 1))
entropy->dc_context[ci] += 8; /* large diff category */
/* Figure F.9: Encoding the magnitude bit pattern of v */
st += 14;
@@ -456,9 +460,9 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/
METHODDEF(boolean)
encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
encode_mcu_AC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
JBLOCKROW block;
unsigned char *st;
int tbl, k, ke;
@@ -555,9 +559,9 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/
METHODDEF(boolean)
encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
encode_mcu_DC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
unsigned char *st;
int Al, blkn;
@@ -590,9 +594,9 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/
METHODDEF(boolean)
encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
JBLOCKROW block;
unsigned char *st;
int tbl, k, ke, kex;
@@ -683,9 +687,9 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/
METHODDEF(boolean)
encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
encode_mcu(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
jpeg_component_info *compptr;
JBLOCKROW block;
unsigned char *st;
@@ -750,9 +754,9 @@ encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
}
arith_encode(cinfo, st, 0);
/* Section F.1.4.4.1.2: Establish dc_context conditioning category */
if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))
if (m < (int)((1L << cinfo->arith_dc_L[tbl]) >> 1))
entropy->dc_context[ci] = 0; /* zero diff category */
else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))
else if (m > (int)((1L << cinfo->arith_dc_U[tbl]) >> 1))
entropy->dc_context[ci] += 8; /* large diff category */
/* Figure F.9: Encoding the magnitude bit pattern of v */
st += 14;
@@ -825,9 +829,9 @@ encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/
METHODDEF(void)
start_pass (j_compress_ptr cinfo, boolean gather_statistics)
start_pass(j_compress_ptr cinfo, boolean gather_statistics)
{
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
int ci, tbl;
jpeg_component_info *compptr;
boolean progressive_mode;
@@ -870,8 +874,8 @@ start_pass (j_compress_ptr cinfo, boolean gather_statistics)
if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
if (entropy->dc_stats[tbl] == NULL)
entropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS);
entropy->dc_stats[tbl] = (unsigned char *)(*cinfo->mem->alloc_small)
((j_common_ptr)cinfo, JPOOL_IMAGE, DC_STAT_BINS);
MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS);
/* Initialize DC predictions to 0 */
entropy->last_dc_val[ci] = 0;
@@ -883,13 +887,14 @@ start_pass (j_compress_ptr cinfo, boolean gather_statistics)
if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
if (entropy->ac_stats[tbl] == NULL)
entropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS);
entropy->ac_stats[tbl] = (unsigned char *)(*cinfo->mem->alloc_small)
((j_common_ptr)cinfo, JPOOL_IMAGE, AC_STAT_BINS);
MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS);
#ifdef CALCULATE_SPECTRAL_CONDITIONING
if (progressive_mode)
/* Section G.1.3.2: Set appropriate arithmetic conditioning value Kx */
cinfo->arith_ac_K[tbl] = cinfo->Ss + ((8 + cinfo->Se - cinfo->Ss) >> 4);
cinfo->arith_ac_K[tbl] = cinfo->Ss +
((8 + cinfo->Se - cinfo->Ss) >> 4);
#endif
}
}
@@ -913,15 +918,15 @@ start_pass (j_compress_ptr cinfo, boolean gather_statistics)
*/
GLOBAL(void)
jinit_arith_encoder (j_compress_ptr cinfo)
jinit_arith_encoder(j_compress_ptr cinfo)
{
arith_entropy_ptr entropy;
int i;
entropy = (arith_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(arith_entropy_encoder));
cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
cinfo->entropy = (struct jpeg_entropy_encoder *)entropy;
entropy->pub.start_pass = start_pass;
entropy->pub.finish_pass = finish_pass;