Commit 058fb976 authored by Alexandre Julliard's avatar Alexandre Julliard

jpeg: Import upstream release 9e.

parent 727a7b0b
/* /*
* jcarith.c * jcarith.c
* *
* Developed 1997-2019 by Guido Vollbeding. * Developed 1997-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -361,7 +361,7 @@ emit_restart (j_compress_ptr cinfo, int restart_num) ...@@ -361,7 +361,7 @@ emit_restart (j_compress_ptr cinfo, int restart_num)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
unsigned char *st; unsigned char *st;
...@@ -450,7 +450,7 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) ...@@ -450,7 +450,7 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
const int * natural_order; const int * natural_order;
...@@ -557,7 +557,7 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) ...@@ -557,7 +557,7 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
unsigned char *st; unsigned char *st;
...@@ -592,7 +592,7 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) ...@@ -592,7 +592,7 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
const int * natural_order; const int * natural_order;
...@@ -691,7 +691,7 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) ...@@ -691,7 +691,7 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
const int * natural_order; const int * natural_order;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jcdctmgr.c * jcdctmgr.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2003-2013 by Guido Vollbeding. * Modified 2003-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -66,15 +66,14 @@ typedef union { ...@@ -66,15 +66,14 @@ typedef union {
* Perform forward DCT on one or more blocks of a component. * Perform forward DCT on one or more blocks of a component.
* *
* The input samples are taken from the sample_data[] array starting at * The input samples are taken from the sample_data[] array starting at
* position start_row/start_col, and moving to the right for any additional * position start_col, and moving to the right for any additional blocks.
* blocks. The quantized coefficients are returned in coef_blocks[]. * The quantized coefficients are returned in coef_blocks[].
*/ */
METHODDEF(void) METHODDEF(void)
forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr, forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY sample_data, JBLOCKROW coef_blocks, JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
JDIMENSION start_row, JDIMENSION start_col, JDIMENSION start_col, JDIMENSION num_blocks)
JDIMENSION num_blocks)
/* This version is used for integer DCT implementations. */ /* This version is used for integer DCT implementations. */
{ {
/* This routine is heavily used, so it's worth coding it tightly. */ /* This routine is heavily used, so it's worth coding it tightly. */
...@@ -84,8 +83,6 @@ forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr, ...@@ -84,8 +83,6 @@ forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */ DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
JDIMENSION bi; JDIMENSION bi;
sample_data += start_row; /* fold in the vertical offset once */
for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) { for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) {
/* Perform the DCT */ /* Perform the DCT */
(*do_dct) (workspace, sample_data, start_col); (*do_dct) (workspace, sample_data, start_col);
...@@ -136,8 +133,7 @@ forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr, ...@@ -136,8 +133,7 @@ forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
METHODDEF(void) METHODDEF(void)
forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr, forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY sample_data, JBLOCKROW coef_blocks, JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
JDIMENSION start_row, JDIMENSION start_col, JDIMENSION start_col, JDIMENSION num_blocks)
JDIMENSION num_blocks)
/* This version is used for floating-point DCT implementations. */ /* This version is used for floating-point DCT implementations. */
{ {
/* This routine is heavily used, so it's worth coding it tightly. */ /* This routine is heavily used, so it's worth coding it tightly. */
...@@ -147,8 +143,6 @@ forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr, ...@@ -147,8 +143,6 @@ forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */ FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
JDIMENSION bi; JDIMENSION bi;
sample_data += start_row; /* fold in the vertical offset once */
for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) { for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) {
/* Perform the DCT */ /* Perform the DCT */
(*do_dct) (workspace, sample_data, start_col); (*do_dct) (workspace, sample_data, start_col);
...@@ -347,13 +341,11 @@ start_pass_fdctmgr (j_compress_ptr cinfo) ...@@ -347,13 +341,11 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
#endif #endif
default: default:
ERREXIT(cinfo, JERR_NOT_COMPILED); ERREXIT(cinfo, JERR_NOT_COMPILED);
break;
} }
break; break;
default: default:
ERREXIT2(cinfo, JERR_BAD_DCTSIZE, ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
compptr->DCT_h_scaled_size, compptr->DCT_v_scaled_size); compptr->DCT_h_scaled_size, compptr->DCT_v_scaled_size);
break;
} }
qtblno = compptr->quant_tbl_no; qtblno = compptr->quant_tbl_no;
/* Make sure specified quantization table is present */ /* Make sure specified quantization table is present */
...@@ -444,7 +436,6 @@ start_pass_fdctmgr (j_compress_ptr cinfo) ...@@ -444,7 +436,6 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
#endif #endif
default: default:
ERREXIT(cinfo, JERR_NOT_COMPILED); ERREXIT(cinfo, JERR_NOT_COMPILED);
break;
} }
} }
} }
...@@ -461,17 +452,15 @@ jinit_forward_dct (j_compress_ptr cinfo) ...@@ -461,17 +452,15 @@ jinit_forward_dct (j_compress_ptr cinfo)
int ci; int ci;
jpeg_component_info *compptr; jpeg_component_info *compptr;
fdct = (my_fdct_ptr) fdct = (my_fdct_ptr) (*cinfo->mem->alloc_small)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_fdct_controller));
SIZEOF(my_fdct_controller));
cinfo->fdct = &fdct->pub; cinfo->fdct = &fdct->pub;
fdct->pub.start_pass = start_pass_fdctmgr; fdct->pub.start_pass = start_pass_fdctmgr;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
/* Allocate a divisor table for each component */ /* Allocate a divisor table for each component */
compptr->dct_table = compptr->dct_table = (*cinfo->mem->alloc_small)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(divisor_table));
SIZEOF(divisor_table));
} }
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jchuff.c * jchuff.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2006-2019 by Guido Vollbeding. * Modified 2006-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -542,7 +542,7 @@ emit_restart_e (huff_entropy_ptr entropy, int restart_num) ...@@ -542,7 +542,7 @@ emit_restart_e (huff_entropy_ptr entropy, int restart_num)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
register int temp, temp2; register int temp, temp2;
...@@ -625,7 +625,7 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) ...@@ -625,7 +625,7 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
const int * natural_order; const int * natural_order;
...@@ -736,7 +736,7 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) ...@@ -736,7 +736,7 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
int Al, blkn; int Al, blkn;
...@@ -779,7 +779,7 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) ...@@ -779,7 +779,7 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
const int * natural_order; const int * natural_order;
...@@ -1009,7 +1009,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val, ...@@ -1009,7 +1009,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_huff (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
working_state state; working_state state;
...@@ -1190,7 +1190,7 @@ htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val, ...@@ -1190,7 +1190,7 @@ htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_gather (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
int blkn, ci; int blkn, ci;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jcmaster.c * jcmaster.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2003-2019 by Guido Vollbeding. * Modified 2003-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -429,9 +429,7 @@ per_scan_setup (j_compress_ptr cinfo) ...@@ -429,9 +429,7 @@ per_scan_setup (j_compress_ptr cinfo)
cinfo->MCUs_per_row = (JDIMENSION) cinfo->MCUs_per_row = (JDIMENSION)
jdiv_round_up((long) cinfo->jpeg_width, jdiv_round_up((long) cinfo->jpeg_width,
(long) (cinfo->max_h_samp_factor * cinfo->block_size)); (long) (cinfo->max_h_samp_factor * cinfo->block_size));
cinfo->MCU_rows_in_scan = (JDIMENSION) cinfo->MCU_rows_in_scan = cinfo->total_iMCU_rows;
jdiv_round_up((long) cinfo->jpeg_height,
(long) (cinfo->max_v_samp_factor * cinfo->block_size));
cinfo->blocks_in_MCU = 0; cinfo->blocks_in_MCU = 0;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jcparam.c * jcparam.c
* *
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2003-2019 by Guido Vollbeding. * Modified 2003-2022 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -62,8 +62,9 @@ jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl, ...@@ -62,8 +62,9 @@ jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
/* These are the sample quantization tables given in JPEG spec section K.1. /* These are the sample quantization tables given in JPEG spec section K.1.
* The spec says that the values given produce "good" quality, and * NOTE: chrominance DC value is changed from 17 to 16 for lossless support.
* when divided by 2, "very good" quality. * The spec says that the values given produce "good" quality,
* and when divided by 2, "very good" quality.
*/ */
static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = { static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
16, 11, 10, 16, 24, 40, 51, 61, 16, 11, 10, 16, 24, 40, 51, 61,
...@@ -76,7 +77,7 @@ static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = { ...@@ -76,7 +77,7 @@ static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
72, 92, 95, 98, 112, 100, 103, 99 72, 92, 95, 98, 112, 100, 103, 99
}; };
static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = { static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
17, 18, 24, 47, 99, 99, 99, 99, 16, 18, 24, 47, 99, 99, 99, 99,
18, 21, 26, 66, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99,
24, 26, 56, 99, 99, 99, 99, 99, 24, 26, 56, 99, 99, 99, 99, 99,
47, 66, 99, 99, 99, 99, 99, 99, 47, 66, 99, 99, 99, 99, 99, 99,
...@@ -379,11 +380,13 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace) ...@@ -379,11 +380,13 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
case JCS_RGB: case JCS_RGB:
cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */ cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
cinfo->num_components = 3; cinfo->num_components = 3;
SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, SET_COMP(0, 0x52 /* 'R' */, 1,1,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0, cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0); cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);
SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0); SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, SET_COMP(2, 0x42 /* 'B' */, 1,1,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0, cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0); cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);
break; break;
...@@ -417,11 +420,13 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace) ...@@ -417,11 +420,13 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
cinfo->JFIF_major_version = 2; /* Set JFIF major version = 2 */ cinfo->JFIF_major_version = 2; /* Set JFIF major version = 2 */
cinfo->num_components = 3; cinfo->num_components = 3;
/* Add offset 0x20 to the normal R/G/B component IDs */ /* Add offset 0x20 to the normal R/G/B component IDs */
SET_COMP(0, 0x72 /* 'r' */, 1,1, 0, SET_COMP(0, 0x72 /* 'r' */, 1,1,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0, cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0); cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);
SET_COMP(1, 0x67 /* 'g' */, 1,1, 0, 0,0); SET_COMP(1, 0x67 /* 'g' */, 1,1, 0, 0,0);
SET_COMP(2, 0x62 /* 'b' */, 1,1, 0, SET_COMP(2, 0x62 /* 'b' */, 1,1,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0, cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0); cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);
break; break;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* jcprepct.c * jcprepct.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2003-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -109,7 +110,8 @@ expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols, ...@@ -109,7 +110,8 @@ expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
register int row; register int row;
for (row = input_rows; row < output_rows; row++) { for (row = input_rows; row < output_rows; row++) {
jcopy_sample_rows(image_data, input_rows-1, image_data, row, jcopy_sample_rows(image_data + input_rows - 1,
image_data + row,
1, num_cols); 1, num_cols);
} }
} }
...@@ -220,8 +222,8 @@ pre_process_context (j_compress_ptr cinfo, ...@@ -220,8 +222,8 @@ pre_process_context (j_compress_ptr cinfo,
for (ci = 0; ci < cinfo->num_components; ci++) { for (ci = 0; ci < cinfo->num_components; ci++) {
int row; int row;
for (row = 1; row <= cinfo->max_v_samp_factor; row++) { for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
jcopy_sample_rows(prep->color_buf[ci], 0, jcopy_sample_rows(prep->color_buf[ci],
prep->color_buf[ci], -row, prep->color_buf[ci] - row,
1, cinfo->image_width); 1, cinfo->image_width);
} }
} }
...@@ -277,10 +279,9 @@ create_context_buffer (j_compress_ptr cinfo) ...@@ -277,10 +279,9 @@ create_context_buffer (j_compress_ptr cinfo)
/* Grab enough space for fake row pointers for all the components; /* Grab enough space for fake row pointers for all the components;
* we need five row groups' worth of pointers for each component. * we need five row groups' worth of pointers for each component.
*/ */
fake_buffer = (JSAMPARRAY) fake_buffer = (JSAMPARRAY) (*cinfo->mem->alloc_small)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE,
(cinfo->num_components * 5 * rgroup_height) * (cinfo->num_components * 5 * rgroup_height) * SIZEOF(JSAMPROW));
SIZEOF(JSAMPROW));
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
...@@ -324,10 +325,9 @@ jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer) ...@@ -324,10 +325,9 @@ jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
if (need_full_buffer) /* safety check */ if (need_full_buffer) /* safety check */
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
prep = (my_prep_ptr) prep = (my_prep_ptr) (*cinfo->mem->alloc_small)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_prep_controller));
SIZEOF(my_prep_controller)); cinfo->prep = &prep->pub;
cinfo->prep = (struct jpeg_c_prep_controller *) prep;
prep->pub.start_pass = start_pass_prep; prep->pub.start_pass = start_pass_prep;
/* Allocate the color conversion buffer. /* Allocate the color conversion buffer.
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* jcsample.c * jcsample.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2003-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -200,7 +201,7 @@ fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, ...@@ -200,7 +201,7 @@ fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
/* Copy the data */ /* Copy the data */
jcopy_sample_rows(input_data, 0, output_data, 0, jcopy_sample_rows(input_data, output_data,
cinfo->max_v_samp_factor, cinfo->image_width); cinfo->max_v_samp_factor, cinfo->image_width);
/* Edge-expand */ /* Edge-expand */
expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width, expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
...@@ -483,10 +484,9 @@ jinit_downsampler (j_compress_ptr cinfo) ...@@ -483,10 +484,9 @@ jinit_downsampler (j_compress_ptr cinfo)
boolean smoothok = TRUE; boolean smoothok = TRUE;
int h_in_group, v_in_group, h_out_group, v_out_group; int h_in_group, v_in_group, h_out_group, v_out_group;
downsample = (my_downsample_ptr) downsample = (my_downsample_ptr) (*cinfo->mem->alloc_small)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_downsampler));
SIZEOF(my_downsampler)); cinfo->downsample = &downsample->pub;
cinfo->downsample = (struct jpeg_downsampler *) downsample;
downsample->pub.start_pass = start_pass_downsample; downsample->pub.start_pass = start_pass_downsample;
downsample->pub.downsample = sep_downsample; downsample->pub.downsample = sep_downsample;
downsample->pub.need_context_rows = FALSE; downsample->pub.need_context_rows = FALSE;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jdapimin.c * jdapimin.c
* *
* Copyright (C) 1994-1998, Thomas G. Lane. * Copyright (C) 1994-1998, Thomas G. Lane.
* Modified 2009-2013 by Guido Vollbeding. * Modified 2009-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -114,7 +114,7 @@ jpeg_abort_decompress (j_decompress_ptr cinfo) ...@@ -114,7 +114,7 @@ jpeg_abort_decompress (j_decompress_ptr cinfo)
LOCAL(void) LOCAL(void)
default_decompress_parms (j_decompress_ptr cinfo) default_decompress_parms (j_decompress_ptr cinfo)
{ {
int cid0, cid1, cid2; int cid0, cid1, cid2, cid3;
/* Guess the input colorspace, and set output colorspace accordingly. */ /* Guess the input colorspace, and set output colorspace accordingly. */
/* Note application may override our guesses. */ /* Note application may override our guesses. */
...@@ -129,7 +129,10 @@ default_decompress_parms (j_decompress_ptr cinfo) ...@@ -129,7 +129,10 @@ default_decompress_parms (j_decompress_ptr cinfo)
cid1 = cinfo->comp_info[1].component_id; cid1 = cinfo->comp_info[1].component_id;
cid2 = cinfo->comp_info[2].component_id; cid2 = cinfo->comp_info[2].component_id;
/* First try to guess from the component IDs */ /* For robust detection of standard colorspaces
* regardless of the presence of special markers,
* check component IDs from SOF marker first.
*/
if (cid0 == 0x01 && cid1 == 0x02 && cid2 == 0x03) if (cid0 == 0x01 && cid1 == 0x02 && cid2 == 0x03)
cinfo->jpeg_color_space = JCS_YCbCr; cinfo->jpeg_color_space = JCS_YCbCr;
else if (cid0 == 0x01 && cid1 == 0x22 && cid2 == 0x23) else if (cid0 == 0x01 && cid1 == 0x22 && cid2 == 0x23)
...@@ -151,7 +154,6 @@ default_decompress_parms (j_decompress_ptr cinfo) ...@@ -151,7 +154,6 @@ default_decompress_parms (j_decompress_ptr cinfo)
default: default:
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
break;
} }
} else { } else {
TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2); TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
...@@ -162,7 +164,20 @@ default_decompress_parms (j_decompress_ptr cinfo) ...@@ -162,7 +164,20 @@ default_decompress_parms (j_decompress_ptr cinfo)
break; break;
case 4: case 4:
if (cinfo->saw_Adobe_marker) { cid0 = cinfo->comp_info[0].component_id;
cid1 = cinfo->comp_info[1].component_id;
cid2 = cinfo->comp_info[2].component_id;
cid3 = cinfo->comp_info[3].component_id;
/* For robust detection of standard colorspaces
* regardless of the presence of special markers,
* check component IDs from SOF marker first.
*/
if (cid0 == 0x01 && cid1 == 0x02 && cid2 == 0x03 && cid3 == 0x04)
cinfo->jpeg_color_space = JCS_YCCK;
else if (cid0 == 0x43 && cid1 == 0x4D && cid2 == 0x59 && cid3 == 0x4B)
cinfo->jpeg_color_space = JCS_CMYK; /* ASCII 'C', 'M', 'Y', 'K' */
else if (cinfo->saw_Adobe_marker) {
switch (cinfo->Adobe_transform) { switch (cinfo->Adobe_transform) {
case 0: case 0:
cinfo->jpeg_color_space = JCS_CMYK; cinfo->jpeg_color_space = JCS_CMYK;
...@@ -173,10 +188,9 @@ default_decompress_parms (j_decompress_ptr cinfo) ...@@ -173,10 +188,9 @@ default_decompress_parms (j_decompress_ptr cinfo)
default: default:
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */ cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
break;
} }
} else { } else {
/* No special markers, assume straight CMYK. */ /* Unknown IDs and no special markers, assume straight CMYK. */
cinfo->jpeg_color_space = JCS_CMYK; cinfo->jpeg_color_space = JCS_CMYK;
} }
cinfo->out_color_space = JCS_CMYK; cinfo->out_color_space = JCS_CMYK;
...@@ -185,7 +199,6 @@ default_decompress_parms (j_decompress_ptr cinfo) ...@@ -185,7 +199,6 @@ default_decompress_parms (j_decompress_ptr cinfo)
default: default:
cinfo->jpeg_color_space = JCS_UNKNOWN; cinfo->jpeg_color_space = JCS_UNKNOWN;
cinfo->out_color_space = JCS_UNKNOWN; cinfo->out_color_space = JCS_UNKNOWN;
break;
} }
/* Set defaults for other decompression parameters. */ /* Set defaults for other decompression parameters. */
......
/* /*
* jdarith.c * jdarith.c
* *
* Developed 1997-2019 by Guido Vollbeding. * Developed 1997-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -239,7 +239,7 @@ process_restart (j_decompress_ptr cinfo) ...@@ -239,7 +239,7 @@ process_restart (j_decompress_ptr cinfo)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
JBLOCKROW block; JBLOCKROW block;
...@@ -318,7 +318,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) ...@@ -318,7 +318,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
JBLOCKROW block; JBLOCKROW block;
...@@ -400,7 +400,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) ...@@ -400,7 +400,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
unsigned char *st; unsigned char *st;
...@@ -434,7 +434,7 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) ...@@ -434,7 +434,7 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
JBLOCKROW block; JBLOCKROW block;
...@@ -509,7 +509,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) ...@@ -509,7 +509,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
jpeg_component_info * compptr; jpeg_component_info * compptr;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jdcolor.c * jdcolor.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2011-2019 by Guido Vollbeding. * Modified 2011-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -420,7 +420,7 @@ rgb_convert (j_decompress_ptr cinfo, ...@@ -420,7 +420,7 @@ rgb_convert (j_decompress_ptr cinfo,
/* /*
* Color conversion for no colorspace change: just copy the data, * Color conversion for no colorspace change: just copy the data,
* converting from separate-planes to interleaved representation. * converting from separate-planes to interleaved representation.
* We assume out_color_components == num_components. * Note: Omit uninteresting components in output buffer.
*/ */
METHODDEF(void) METHODDEF(void)
...@@ -431,22 +431,27 @@ null_convert (j_decompress_ptr cinfo, ...@@ -431,22 +431,27 @@ null_convert (j_decompress_ptr cinfo,
register JSAMPROW outptr; register JSAMPROW outptr;
register JSAMPROW inptr; register JSAMPROW inptr;
register JDIMENSION count; register JDIMENSION count;
register int num_comps = cinfo->num_components; register int out_comps = cinfo->out_color_components;
JDIMENSION num_cols = cinfo->output_width; JDIMENSION num_cols = cinfo->output_width;
JSAMPROW startptr;
int ci; int ci;
jpeg_component_info *compptr;
while (--num_rows >= 0) { while (--num_rows >= 0) {
/* It seems fastest to make a separate pass for each component. */ /* It seems fastest to make a separate pass for each component. */
for (ci = 0; ci < num_comps; ci++) { startptr = *output_buf++;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) {
if (! compptr->component_needed)
continue; /* skip uninteresting component */
inptr = input_buf[ci][input_row]; inptr = input_buf[ci][input_row];
outptr = output_buf[0] + ci; outptr = startptr++;
for (count = num_cols; count > 0; count--) { for (count = num_cols; count > 0; count--) {
*outptr = *inptr++; /* don't need GETJSAMPLE() here */ *outptr = *inptr++; /* don't need GETJSAMPLE() here */
outptr += num_comps; outptr += out_comps;
} }
} }
input_row++; input_row++;
output_buf++;
} }
} }
...@@ -462,7 +467,7 @@ grayscale_convert (j_decompress_ptr cinfo, ...@@ -462,7 +467,7 @@ grayscale_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0, jcopy_sample_rows(input_buf[0] + input_row, output_buf,
num_rows, cinfo->output_width); num_rows, cinfo->output_width);
} }
...@@ -550,6 +555,47 @@ ycck_cmyk_convert (j_decompress_ptr cinfo, ...@@ -550,6 +555,47 @@ ycck_cmyk_convert (j_decompress_ptr cinfo,
/* /*
* Convert CMYK to YK part of YCCK for colorless output.
* We assume build_rgb_y_table has been called.
*/
METHODDEF(void)
cmyk_yk_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int r, g, b;
register INT32 * ctab = cconvert->rgb_y_tab;
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2, inptr3;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
while (--num_rows >= 0) {
inptr0 = input_buf[0][input_row];
inptr1 = input_buf[1][input_row];
inptr2 = input_buf[2][input_row];
inptr3 = input_buf[3][input_row];
input_row++;
outptr = *output_buf++;
for (col = 0; col < num_cols; col++) {
r = MAXJSAMPLE - GETJSAMPLE(inptr0[col]);
g = MAXJSAMPLE - GETJSAMPLE(inptr1[col]);
b = MAXJSAMPLE - GETJSAMPLE(inptr2[col]);
/* Y */
outptr[0] = (JSAMPLE)
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
>> SCALEBITS);
/* K passes through unchanged */
outptr[1] = inptr3[col]; /* don't need GETJSAMPLE here */
outptr += 2;
}
}
}
/*
* Empty method for start_pass. * Empty method for start_pass.
*/ */
...@@ -568,7 +614,7 @@ GLOBAL(void) ...@@ -568,7 +614,7 @@ GLOBAL(void)
jinit_color_deconverter (j_decompress_ptr cinfo) jinit_color_deconverter (j_decompress_ptr cinfo)
{ {
my_cconvert_ptr cconvert; my_cconvert_ptr cconvert;
int ci; int ci, i;
cconvert = (my_cconvert_ptr) (*cinfo->mem->alloc_small) cconvert = (my_cconvert_ptr) (*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_color_deconverter)); ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_color_deconverter));
...@@ -608,7 +654,7 @@ jinit_color_deconverter (j_decompress_ptr cinfo) ...@@ -608,7 +654,7 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
/* Set out_color_components and conversion method based on requested space. /* Set out_color_components and conversion method based on requested space.
* Also clear the component_needed flags for any unused components, * Also adjust the component_needed flags for any unused components,
* so that earlier pipeline stages can avoid useless computation. * so that earlier pipeline stages can avoid useless computation.
*/ */
...@@ -674,9 +720,9 @@ jinit_color_deconverter (j_decompress_ptr cinfo) ...@@ -674,9 +720,9 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
break; break;
case JCS_BG_RGB: case JCS_BG_RGB:
cinfo->out_color_components = RGB_PIXELSIZE;
if (cinfo->jpeg_color_space != JCS_BG_RGB) if (cinfo->jpeg_color_space != JCS_BG_RGB)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
cinfo->out_color_components = RGB_PIXELSIZE;
switch (cinfo->color_transform) { switch (cinfo->color_transform) {
case JCT_NONE: case JCT_NONE:
cconvert->pub.color_convert = rgb_convert; cconvert->pub.color_convert = rgb_convert;
...@@ -690,25 +736,38 @@ jinit_color_deconverter (j_decompress_ptr cinfo) ...@@ -690,25 +736,38 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
break; break;
case JCS_CMYK: case JCS_CMYK:
if (cinfo->jpeg_color_space != JCS_YCCK)
goto def_label;
cinfo->out_color_components = 4; cinfo->out_color_components = 4;
switch (cinfo->jpeg_color_space) {
case JCS_YCCK:
cconvert->pub.color_convert = ycck_cmyk_convert; cconvert->pub.color_convert = ycck_cmyk_convert;
build_ycc_rgb_table(cinfo); build_ycc_rgb_table(cinfo);
break; break;
case JCS_CMYK:
cconvert->pub.color_convert = null_convert; case JCS_YCCK:
break; if (cinfo->jpeg_color_space != JCS_CMYK ||
default: /* Support only YK part of YCCK for colorless output */
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ! cinfo->comp_info[0].component_needed ||
} cinfo->comp_info[1].component_needed ||
cinfo->comp_info[2].component_needed ||
! cinfo->comp_info[3].component_needed)
goto def_label;
cinfo->out_color_components = 2;
/* Need all components on input side */
cinfo->comp_info[1].component_needed = TRUE;
cinfo->comp_info[2].component_needed = TRUE;
cconvert->pub.color_convert = cmyk_yk_convert;
build_rgb_y_table(cinfo);
break; break;
default: /* permit null conversion to same output space */ default: def_label: /* permit null conversion to same output space */
if (cinfo->out_color_space != cinfo->jpeg_color_space) if (cinfo->out_color_space != cinfo->jpeg_color_space)
/* unsupported non-null conversion */ /* unsupported non-null conversion */
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
cinfo->out_color_components = cinfo->num_components; i = 0;
for (ci = 0; ci < cinfo->num_components; ci++)
if (cinfo->comp_info[ci].component_needed)
i++; /* count output color components */
cinfo->out_color_components = i;
cconvert->pub.color_convert = null_convert; cconvert->pub.color_convert = null_convert;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jdhuff.c * jdhuff.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2006-2019 by Guido Vollbeding. * Modified 2006-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -704,7 +704,7 @@ process_restart (j_decompress_ptr cinfo) ...@@ -704,7 +704,7 @@ process_restart (j_decompress_ptr cinfo)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
int Al = cinfo->Al; int Al = cinfo->Al;
...@@ -776,7 +776,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) ...@@ -776,7 +776,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
register int s, k, r; register int s, k, r;
...@@ -864,7 +864,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) ...@@ -864,7 +864,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
JCOEF p1; JCOEF p1;
...@@ -913,7 +913,7 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) ...@@ -913,7 +913,7 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
register int s, k, r; register int s, k, r;
...@@ -1072,7 +1072,7 @@ undoit: ...@@ -1072,7 +1072,7 @@ undoit:
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_sub (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_sub (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
const int * natural_order; const int * natural_order;
...@@ -1201,7 +1201,7 @@ decode_mcu_sub (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) ...@@ -1201,7 +1201,7 @@ decode_mcu_sub (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
int blkn; int blkn;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jdinput.c * jdinput.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2002-2013 by Guido Vollbeding. * Modified 2002-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -330,7 +330,6 @@ initial_setup (j_decompress_ptr cinfo) ...@@ -330,7 +330,6 @@ initial_setup (j_decompress_ptr cinfo)
default: default:
ERREXIT4(cinfo, JERR_BAD_PROGRESSION, ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al); cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
break;
} }
/* We initialize DCT_scaled_size and min_DCT_scaled_size to block_size. /* We initialize DCT_scaled_size and min_DCT_scaled_size to block_size.
...@@ -429,9 +428,7 @@ per_scan_setup (j_decompress_ptr cinfo) ...@@ -429,9 +428,7 @@ per_scan_setup (j_decompress_ptr cinfo)
cinfo->MCUs_per_row = (JDIMENSION) cinfo->MCUs_per_row = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width, jdiv_round_up((long) cinfo->image_width,
(long) (cinfo->max_h_samp_factor * cinfo->block_size)); (long) (cinfo->max_h_samp_factor * cinfo->block_size));
cinfo->MCU_rows_in_scan = (JDIMENSION) cinfo->MCU_rows_in_scan = cinfo->total_iMCU_rows;
jdiv_round_up((long) cinfo->image_height,
(long) (cinfo->max_v_samp_factor * cinfo->block_size));
cinfo->blocks_in_MCU = 0; cinfo->blocks_in_MCU = 0;
...@@ -501,9 +498,8 @@ latch_quant_tables (j_decompress_ptr cinfo) ...@@ -501,9 +498,8 @@ latch_quant_tables (j_decompress_ptr cinfo)
cinfo->quant_tbl_ptrs[qtblno] == NULL) cinfo->quant_tbl_ptrs[qtblno] == NULL)
ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
/* OK, save away the quantization table */ /* OK, save away the quantization table */
qtbl = (JQUANT_TBL *) qtbl = (JQUANT_TBL *) (*cinfo->mem->alloc_small)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(JQUANT_TBL));
SIZEOF(JQUANT_TBL));
MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL)); MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
compptr->quant_table = qtbl; compptr->quant_table = qtbl;
} }
...@@ -644,9 +640,8 @@ jinit_input_controller (j_decompress_ptr cinfo) ...@@ -644,9 +640,8 @@ jinit_input_controller (j_decompress_ptr cinfo)
my_inputctl_ptr inputctl; my_inputctl_ptr inputctl;
/* Create subobject in permanent pool */ /* Create subobject in permanent pool */
inputctl = (my_inputctl_ptr) inputctl = (my_inputctl_ptr) (*cinfo->mem->alloc_small)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, ((j_common_ptr) cinfo, JPOOL_PERMANENT, SIZEOF(my_input_controller));
SIZEOF(my_input_controller));
cinfo->inputctl = &inputctl->pub; cinfo->inputctl = &inputctl->pub;
/* Initialize method pointers */ /* Initialize method pointers */
inputctl->pub.consume_input = consume_markers; inputctl->pub.consume_input = consume_markers;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jdmainct.c * jdmainct.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2002-2016 by Guido Vollbeding. * Modified 2002-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -170,21 +170,22 @@ alloc_funny_pointers (j_decompress_ptr cinfo) ...@@ -170,21 +170,22 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
/* Get top-level space for component array pointers. /* Get top-level space for component array pointers.
* We alloc both arrays with one call to save a few cycles. * We alloc both arrays with one call to save a few cycles.
*/ */
mainp->xbuffer[0] = (JSAMPIMAGE) mainp->xbuffer[0] = (JSAMPIMAGE) (*cinfo->mem->alloc_small)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE,
cinfo->num_components * 2 * SIZEOF(JSAMPARRAY)); cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
mainp->xbuffer[1] = mainp->xbuffer[0] + cinfo->num_components; mainp->xbuffer[1] = mainp->xbuffer[0] + cinfo->num_components;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
if (! compptr->component_needed)
continue; /* skip uninteresting component */
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) / rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */ cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
/* Get space for pointer lists --- M+4 row groups in each list. /* Get space for pointer lists --- M+4 row groups in each list.
* We alloc both pointer lists with one call to save a few cycles. * We alloc both pointer lists with one call to save a few cycles.
*/ */
xbuf = (JSAMPARRAY) xbuf = (JSAMPARRAY) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, JPOOL_IMAGE, 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
xbuf += rgroup; /* want one row group at negative offsets */ xbuf += rgroup; /* want one row group at negative offsets */
mainp->xbuffer[0][ci] = xbuf; mainp->xbuffer[0][ci] = xbuf;
xbuf += rgroup * (M + 4); xbuf += rgroup * (M + 4);
...@@ -210,6 +211,8 @@ make_funny_pointers (j_decompress_ptr cinfo) ...@@ -210,6 +211,8 @@ make_funny_pointers (j_decompress_ptr cinfo)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
if (! compptr->component_needed)
continue; /* skip uninteresting component */
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) / rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */ cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
xbuf0 = mainp->xbuffer[0][ci]; xbuf0 = mainp->xbuffer[0][ci];
...@@ -250,6 +253,8 @@ set_wraparound_pointers (j_decompress_ptr cinfo) ...@@ -250,6 +253,8 @@ set_wraparound_pointers (j_decompress_ptr cinfo)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
if (! compptr->component_needed)
continue; /* skip uninteresting component */
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) / rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */ cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
xbuf0 = mainp->xbuffer[0][ci]; xbuf0 = mainp->xbuffer[0][ci];
...@@ -278,6 +283,8 @@ set_bottom_pointers (j_decompress_ptr cinfo) ...@@ -278,6 +283,8 @@ set_bottom_pointers (j_decompress_ptr cinfo)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
if (! compptr->component_needed)
continue; /* skip uninteresting component */
/* Count sample rows in one iMCU row and in one row group */ /* Count sample rows in one iMCU row and in one row group */
iMCUheight = compptr->v_samp_factor * compptr->DCT_v_scaled_size; iMCUheight = compptr->v_samp_factor * compptr->DCT_v_scaled_size;
rgroup = iMCUheight / cinfo->min_DCT_v_scaled_size; rgroup = iMCUheight / cinfo->min_DCT_v_scaled_size;
...@@ -333,7 +340,6 @@ start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode) ...@@ -333,7 +340,6 @@ start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
#endif #endif
default: default:
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
break;
} }
} }
...@@ -344,9 +350,8 @@ start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode) ...@@ -344,9 +350,8 @@ start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
*/ */
METHODDEF(void) METHODDEF(void)
process_data_simple_main (j_decompress_ptr cinfo, process_data_simple_main (j_decompress_ptr cinfo, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
JDIMENSION out_rows_avail)
{ {
my_main_ptr mainp = (my_main_ptr) cinfo->main; my_main_ptr mainp = (my_main_ptr) cinfo->main;
...@@ -375,9 +380,8 @@ process_data_simple_main (j_decompress_ptr cinfo, ...@@ -375,9 +380,8 @@ process_data_simple_main (j_decompress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
process_data_context_main (j_decompress_ptr cinfo, process_data_context_main (j_decompress_ptr cinfo, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
JDIMENSION out_rows_avail)
{ {
my_main_ptr mainp = (my_main_ptr) cinfo->main; my_main_ptr mainp = (my_main_ptr) cinfo->main;
...@@ -449,9 +453,8 @@ process_data_context_main (j_decompress_ptr cinfo, ...@@ -449,9 +453,8 @@ process_data_context_main (j_decompress_ptr cinfo,
#ifdef QUANT_2PASS_SUPPORTED #ifdef QUANT_2PASS_SUPPORTED
METHODDEF(void) METHODDEF(void)
process_data_crank_post (j_decompress_ptr cinfo, process_data_crank_post (j_decompress_ptr cinfo, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
JDIMENSION out_rows_avail)
{ {
(*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL, (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
(JDIMENSION *) NULL, (JDIMENSION) 0, (JDIMENSION *) NULL, (JDIMENSION) 0,
...@@ -472,9 +475,8 @@ jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer) ...@@ -472,9 +475,8 @@ jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
int ci, rgroup, ngroups; int ci, rgroup, ngroups;
jpeg_component_info *compptr; jpeg_component_info *compptr;
mainp = (my_main_ptr) mainp = (my_main_ptr) (*cinfo->mem->alloc_small)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_main_controller));
SIZEOF(my_main_controller));
cinfo->main = &mainp->pub; cinfo->main = &mainp->pub;
mainp->pub.start_pass = start_pass_main; mainp->pub.start_pass = start_pass_main;
...@@ -497,6 +499,8 @@ jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer) ...@@ -497,6 +499,8 @@ jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
if (! compptr->component_needed)
continue; /* skip uninteresting component */
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) / rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */ cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
mainp->buffer[ci] = (*cinfo->mem->alloc_sarray) mainp->buffer[ci] = (*cinfo->mem->alloc_sarray)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jdmaster.c * jdmaster.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2002-2019 by Guido Vollbeding. * Modified 2002-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -103,10 +103,8 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo) ...@@ -103,10 +103,8 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
* This function is used for full decompression. * This function is used for full decompression.
*/ */
{ {
#ifdef IDCT_SCALING_SUPPORTED int ci, i;
int ci, ssize;
jpeg_component_info *compptr; jpeg_component_info *compptr;
#endif
/* Prevent application from calling me at wrong times */ /* Prevent application from calling me at wrong times */
if (cinfo->global_state != DSTATE_READY) if (cinfo->global_state != DSTATE_READY)
...@@ -124,7 +122,7 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo) ...@@ -124,7 +122,7 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
*/ */
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
ssize = 1; int ssize = 1;
if (! cinfo->raw_data_out) if (! cinfo->raw_data_out)
while (cinfo->min_DCT_h_scaled_size * ssize <= while (cinfo->min_DCT_h_scaled_size * ssize <=
(cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) && (cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
...@@ -166,27 +164,22 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo) ...@@ -166,27 +164,22 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
#endif /* IDCT_SCALING_SUPPORTED */ #endif /* IDCT_SCALING_SUPPORTED */
/* Report number of components in selected colorspace. */ /* Report number of components in selected colorspace. */
/* Probably this should be in the color conversion module... */ /* This should correspond to the actual code in the color conversion module. */
switch (cinfo->out_color_space) { switch (cinfo->out_color_space) {
case JCS_GRAYSCALE: case JCS_GRAYSCALE:
cinfo->out_color_components = 1; cinfo->out_color_components = 1;
break; break;
case JCS_RGB: case JCS_RGB:
case JCS_BG_RGB: case JCS_BG_RGB:
#if RGB_PIXELSIZE != 3
cinfo->out_color_components = RGB_PIXELSIZE; cinfo->out_color_components = RGB_PIXELSIZE;
break; break;
#endif /* else share code with YCbCr */ default: /* YCCK <=> CMYK conversion or same colorspace as in file */
case JCS_YCbCr: i = 0;
case JCS_BG_YCC: for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
cinfo->out_color_components = 3; ci++, compptr++)
break; if (compptr->component_needed)
case JCS_CMYK: i++; /* count output color components */
case JCS_YCCK: cinfo->out_color_components = i;
cinfo->out_color_components = 4;
break;
default: /* else must be same colorspace as in file */
cinfo->out_color_components = cinfo->num_components;
} }
cinfo->output_components = (cinfo->quantize_colors ? 1 : cinfo->output_components = (cinfo->quantize_colors ? 1 :
cinfo->out_color_components); cinfo->out_color_components);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jdmerge.c * jdmerge.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2013-2019 by Guido Vollbeding. * Modified 2013-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -190,7 +190,7 @@ merged_2v_upsample (j_decompress_ptr cinfo, ...@@ -190,7 +190,7 @@ merged_2v_upsample (j_decompress_ptr cinfo,
if (upsample->spare_full) { if (upsample->spare_full) {
/* If we have a spare row saved from a previous cycle, just return it. */ /* If we have a spare row saved from a previous cycle, just return it. */
jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0, jcopy_sample_rows(& upsample->spare_row, output_buf + *out_row_ctr,
1, upsample->out_row_width); 1, upsample->out_row_width);
num_rows = 1; num_rows = 1;
upsample->spare_full = FALSE; upsample->spare_full = FALSE;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jdsample.c * jdsample.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2002-2015 by Guido Vollbeding. * Modified 2002-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
/* Pointer to routine to upsample a single component */ /* Pointer to routine to upsample a single component */
typedef JMETHOD(void, upsample1_ptr, typedef JMETHOD(void, upsample1_ptr,
(j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); JSAMPARRAY input_data, JSAMPIMAGE output_data_ptr));
/* Private subobject */ /* Private subobject */
...@@ -102,6 +102,9 @@ sep_upsample (j_decompress_ptr cinfo, ...@@ -102,6 +102,9 @@ sep_upsample (j_decompress_ptr cinfo,
if (upsample->next_row_out >= cinfo->max_v_samp_factor) { if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
/* Don't bother to upsample an uninteresting component. */
if (! compptr->component_needed)
continue;
/* Invoke per-component upsample method. Notice we pass a POINTER /* Invoke per-component upsample method. Notice we pass a POINTER
* to color_buf[ci], so that fullsize_upsample can change it. * to color_buf[ci], so that fullsize_upsample can change it.
*/ */
...@@ -156,26 +159,13 @@ sep_upsample (j_decompress_ptr cinfo, ...@@ -156,26 +159,13 @@ sep_upsample (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) JSAMPARRAY input_data, JSAMPIMAGE output_data_ptr)
{ {
*output_data_ptr = input_data; *output_data_ptr = input_data;
} }
/* /*
* This is a no-op version used for "uninteresting" components.
* These components will not be referenced by color conversion.
*/
METHODDEF(void)
noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
{
*output_data_ptr = NULL; /* safety check */
}
/*
* This version handles any integral sampling ratios. * This version handles any integral sampling ratios.
* This is not used for typical JPEG files, so it need not be fast. * This is not used for typical JPEG files, so it need not be fast.
* Nor, for that matter, is it particularly accurate: the algorithm is * Nor, for that matter, is it particularly accurate: the algorithm is
...@@ -188,25 +178,25 @@ noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, ...@@ -188,25 +178,25 @@ noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
METHODDEF(void) METHODDEF(void)
int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) JSAMPARRAY input_data, JSAMPIMAGE output_data_ptr)
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
JSAMPARRAY output_data = *output_data_ptr; JSAMPARRAY output_data, output_end;
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
register JSAMPLE invalue; register JSAMPLE invalue;
register int h; register int h;
JSAMPROW outend; JSAMPROW outend;
int h_expand, v_expand; int h_expand, v_expand;
int inrow, outrow;
h_expand = upsample->h_expand[compptr->component_index]; h_expand = upsample->h_expand[compptr->component_index];
v_expand = upsample->v_expand[compptr->component_index]; v_expand = upsample->v_expand[compptr->component_index];
inrow = outrow = 0; output_data = *output_data_ptr;
while (outrow < cinfo->max_v_samp_factor) { output_end = output_data + cinfo->max_v_samp_factor;
for (; output_data < output_end; output_data += v_expand) {
/* Generate one output row with proper horizontal expansion */ /* Generate one output row with proper horizontal expansion */
inptr = input_data[inrow]; inptr = *input_data++;
outptr = output_data[outrow]; outptr = *output_data;
outend = outptr + cinfo->output_width; outend = outptr + cinfo->output_width;
while (outptr < outend) { while (outptr < outend) {
invalue = *inptr++; /* don't need GETJSAMPLE() here */ invalue = *inptr++; /* don't need GETJSAMPLE() here */
...@@ -216,11 +206,9 @@ int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, ...@@ -216,11 +206,9 @@ int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
} }
/* Generate any additional output rows by duplicating the first one */ /* Generate any additional output rows by duplicating the first one */
if (v_expand > 1) { if (v_expand > 1) {
jcopy_sample_rows(output_data, outrow, output_data, outrow+1, jcopy_sample_rows(output_data, output_data + 1,
v_expand-1, cinfo->output_width); v_expand - 1, cinfo->output_width);
} }
inrow++;
outrow += v_expand;
} }
} }
...@@ -232,7 +220,7 @@ int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, ...@@ -232,7 +220,7 @@ int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
METHODDEF(void) METHODDEF(void)
h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) JSAMPARRAY input_data, JSAMPIMAGE output_data_ptr)
{ {
JSAMPARRAY output_data = *output_data_ptr; JSAMPARRAY output_data = *output_data_ptr;
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
...@@ -260,28 +248,26 @@ h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, ...@@ -260,28 +248,26 @@ h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
METHODDEF(void) METHODDEF(void)
h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) JSAMPARRAY input_data, JSAMPIMAGE output_data_ptr)
{ {
JSAMPARRAY output_data = *output_data_ptr; JSAMPARRAY output_data, output_end;
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
register JSAMPLE invalue; register JSAMPLE invalue;
JSAMPROW outend; JSAMPROW outend;
int inrow, outrow;
inrow = outrow = 0; output_data = *output_data_ptr;
while (outrow < cinfo->max_v_samp_factor) { output_end = output_data + cinfo->max_v_samp_factor;
inptr = input_data[inrow]; for (; output_data < output_end; output_data += 2) {
outptr = output_data[outrow]; inptr = *input_data++;
outptr = *output_data;
outend = outptr + cinfo->output_width; outend = outptr + cinfo->output_width;
while (outptr < outend) { while (outptr < outend) {
invalue = *inptr++; /* don't need GETJSAMPLE() here */ invalue = *inptr++; /* don't need GETJSAMPLE() here */
*outptr++ = invalue; *outptr++ = invalue;
*outptr++ = invalue; *outptr++ = invalue;
} }
jcopy_sample_rows(output_data, outrow, output_data, outrow+1, jcopy_sample_rows(output_data, output_data + 1,
1, cinfo->output_width); 1, cinfo->output_width);
inrow++;
outrow += 2;
} }
} }
...@@ -298,9 +284,8 @@ jinit_upsampler (j_decompress_ptr cinfo) ...@@ -298,9 +284,8 @@ jinit_upsampler (j_decompress_ptr cinfo)
jpeg_component_info * compptr; jpeg_component_info * compptr;
int h_in_group, v_in_group, h_out_group, v_out_group; int h_in_group, v_in_group, h_out_group, v_out_group;
upsample = (my_upsample_ptr) upsample = (my_upsample_ptr) (*cinfo->mem->alloc_small)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_upsampler));
SIZEOF(my_upsampler));
cinfo->upsample = &upsample->pub; cinfo->upsample = &upsample->pub;
upsample->pub.start_pass = start_pass_upsample; upsample->pub.start_pass = start_pass_upsample;
upsample->pub.upsample = sep_upsample; upsample->pub.upsample = sep_upsample;
...@@ -314,6 +299,9 @@ jinit_upsampler (j_decompress_ptr cinfo) ...@@ -314,6 +299,9 @@ jinit_upsampler (j_decompress_ptr cinfo)
*/ */
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
/* Don't bother to upsample an uninteresting component. */
if (! compptr->component_needed)
continue;
/* Compute size of an "input group" after IDCT scaling. This many samples /* Compute size of an "input group" after IDCT scaling. This many samples
* are to be converted to max_h_samp_factor * max_v_samp_factor pixels. * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
*/ */
...@@ -324,11 +312,6 @@ jinit_upsampler (j_decompress_ptr cinfo) ...@@ -324,11 +312,6 @@ jinit_upsampler (j_decompress_ptr cinfo)
h_out_group = cinfo->max_h_samp_factor; h_out_group = cinfo->max_h_samp_factor;
v_out_group = cinfo->max_v_samp_factor; v_out_group = cinfo->max_v_samp_factor;
upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
if (! compptr->component_needed) {
/* Don't bother to upsample an uninteresting component. */
upsample->methods[ci] = noop_upsample;
continue; /* don't need to allocate buffer */
}
if (h_in_group == h_out_group && v_in_group == v_out_group) { if (h_in_group == h_out_group && v_in_group == v_out_group) {
/* Fullsize components can be processed without any work. */ /* Fullsize components can be processed without any work. */
upsample->methods[ci] = fullsize_upsample; upsample->methods[ci] = fullsize_upsample;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jpegint.h * jpegint.h
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 1997-2019 by Guido Vollbeding. * Modified 1997-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -103,8 +103,7 @@ struct jpeg_downsampler { ...@@ -103,8 +103,7 @@ struct jpeg_downsampler {
typedef JMETHOD(void, forward_DCT_ptr, typedef JMETHOD(void, forward_DCT_ptr,
(j_compress_ptr cinfo, jpeg_component_info * compptr, (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY sample_data, JBLOCKROW coef_blocks, JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
JDIMENSION start_row, JDIMENSION start_col, JDIMENSION start_col, JDIMENSION num_blocks));
JDIMENSION num_blocks));
struct jpeg_forward_dct { struct jpeg_forward_dct {
JMETHOD(void, start_pass, (j_compress_ptr cinfo)); JMETHOD(void, start_pass, (j_compress_ptr cinfo));
...@@ -115,7 +114,7 @@ struct jpeg_forward_dct { ...@@ -115,7 +114,7 @@ struct jpeg_forward_dct {
/* Entropy encoding */ /* Entropy encoding */
struct jpeg_entropy_encoder { struct jpeg_entropy_encoder {
JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics)); JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data)); JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKARRAY MCU_data));
JMETHOD(void, finish_pass, (j_compress_ptr cinfo)); JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
}; };
...@@ -211,7 +210,7 @@ struct jpeg_marker_reader { ...@@ -211,7 +210,7 @@ struct jpeg_marker_reader {
/* Entropy decoding */ /* Entropy decoding */
struct jpeg_entropy_decoder { struct jpeg_entropy_decoder {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)); JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data));
JMETHOD(void, finish_pass, (j_decompress_ptr cinfo)); JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
}; };
...@@ -416,8 +415,8 @@ EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo)); ...@@ -416,8 +415,8 @@ EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
/* Utility routines in jutils.c */ /* Utility routines in jutils.c */
EXTERN(long) jdiv_round_up JPP((long a, long b)); EXTERN(long) jdiv_round_up JPP((long a, long b));
EXTERN(long) jround_up JPP((long a, long b)); EXTERN(long) jround_up JPP((long a, long b));
EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row, EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array,
JSAMPARRAY output_array, int dest_row, JSAMPARRAY output_array,
int num_rows, JDIMENSION num_cols)); int num_rows, JDIMENSION num_cols));
EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row, EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
JDIMENSION num_blocks)); JDIMENSION num_blocks));
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jpeglib.h * jpeglib.h
* *
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2002-2019 by Guido Vollbeding. * Modified 2002-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -39,7 +39,7 @@ extern "C" { ...@@ -39,7 +39,7 @@ extern "C" {
#define JPEG_LIB_VERSION 90 /* Compatibility version 9.0 */ #define JPEG_LIB_VERSION 90 /* Compatibility version 9.0 */
#define JPEG_LIB_VERSION_MAJOR 9 #define JPEG_LIB_VERSION_MAJOR 9
#define JPEG_LIB_VERSION_MINOR 4 #define JPEG_LIB_VERSION_MINOR 5
/* Various constants determining the sizes of things. /* Various constants determining the sizes of things.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jquant1.c * jquant1.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2011 by Guido Vollbeding. * Modified 2011-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -293,8 +293,7 @@ create_colormap (j_decompress_ptr cinfo) ...@@ -293,8 +293,7 @@ create_colormap (j_decompress_ptr cinfo)
/* The colors are ordered in the map in standard row-major order, */ /* The colors are ordered in the map in standard row-major order, */
/* i.e. rightmost (highest-indexed) color changes most rapidly. */ /* i.e. rightmost (highest-indexed) color changes most rapidly. */
colormap = (*cinfo->mem->alloc_sarray) colormap = (*cinfo->mem->alloc_sarray) ((j_common_ptr) cinfo, JPOOL_IMAGE,
((j_common_ptr) cinfo, JPOOL_IMAGE,
(JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components); (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
/* blksize is number of adjacent repeated entries for a component */ /* blksize is number of adjacent repeated entries for a component */
...@@ -400,9 +399,8 @@ make_odither_array (j_decompress_ptr cinfo, int ncolors) ...@@ -400,9 +399,8 @@ make_odither_array (j_decompress_ptr cinfo, int ncolors)
int j,k; int j,k;
INT32 num,den; INT32 num,den;
odither = (ODITHER_MATRIX_PTR) odither = (ODITHER_MATRIX_PTR) (*cinfo->mem->alloc_small)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(ODITHER_MATRIX));
SIZEOF(ODITHER_MATRIX));
/* The inter-value distance for this color is MAXJSAMPLE/(ncolors-1). /* The inter-value distance for this color is MAXJSAMPLE/(ncolors-1).
* Hence the dither value for the matrix cell with fill order f * Hence the dither value for the matrix cell with fill order f
* (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1). * (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1).
...@@ -531,8 +529,7 @@ quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, ...@@ -531,8 +529,7 @@ quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (row = 0; row < num_rows; row++) { for (row = 0; row < num_rows; row++) {
/* Initialize output values to 0 so can process components separately */ /* Initialize output values to 0 so can process components separately */
FMEMZERO((void FAR *) output_buf[row], FMEMZERO((void FAR *) output_buf[row], (size_t) width * SIZEOF(JSAMPLE));
(size_t) (width * SIZEOF(JSAMPLE)));
row_index = cquantize->row_index; row_index = cquantize->row_index;
for (ci = 0; ci < nc; ci++) { for (ci = 0; ci < nc; ci++) {
input_ptr = input_buf[row] + ci; input_ptr = input_buf[row] + ci;
...@@ -636,8 +633,7 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, ...@@ -636,8 +633,7 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (row = 0; row < num_rows; row++) { for (row = 0; row < num_rows; row++) {
/* Initialize output values to 0 so can process components separately */ /* Initialize output values to 0 so can process components separately */
FMEMZERO((void FAR *) output_buf[row], FMEMZERO((void FAR *) output_buf[row], (size_t) width * SIZEOF(JSAMPLE));
(size_t) (width * SIZEOF(JSAMPLE)));
for (ci = 0; ci < nc; ci++) { for (ci = 0; ci < nc; ci++) {
input_ptr = input_buf[row] + ci; input_ptr = input_buf[row] + ci;
output_ptr = output_buf[row]; output_ptr = output_buf[row];
...@@ -726,10 +722,10 @@ alloc_fs_workspace (j_decompress_ptr cinfo) ...@@ -726,10 +722,10 @@ alloc_fs_workspace (j_decompress_ptr cinfo)
size_t arraysize; size_t arraysize;
int i; int i;
arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR)); arraysize = ((size_t) cinfo->output_width + (size_t) 2) * SIZEOF(FSERROR);
for (i = 0; i < cinfo->out_color_components; i++) { for (i = 0; i < cinfo->out_color_components; i++) {
cquantize->fserrors[i] = (FSERRPTR) cquantize->fserrors[i] = (FSERRPTR) (*cinfo->mem->alloc_large)
(*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize); ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
} }
} }
...@@ -780,13 +776,12 @@ start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan) ...@@ -780,13 +776,12 @@ start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
if (cquantize->fserrors[0] == NULL) if (cquantize->fserrors[0] == NULL)
alloc_fs_workspace(cinfo); alloc_fs_workspace(cinfo);
/* Initialize the propagated errors to zero. */ /* Initialize the propagated errors to zero. */
arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR)); arraysize = ((size_t) cinfo->output_width + (size_t) 2) * SIZEOF(FSERROR);
for (i = 0; i < cinfo->out_color_components; i++) for (i = 0; i < cinfo->out_color_components; i++)
FMEMZERO((void FAR *) cquantize->fserrors[i], arraysize); FMEMZERO((void FAR *) cquantize->fserrors[i], arraysize);
break; break;
default: default:
ERREXIT(cinfo, JERR_NOT_COMPILED); ERREXIT(cinfo, JERR_NOT_COMPILED);
break;
} }
} }
...@@ -823,10 +818,9 @@ jinit_1pass_quantizer (j_decompress_ptr cinfo) ...@@ -823,10 +818,9 @@ jinit_1pass_quantizer (j_decompress_ptr cinfo)
{ {
my_cquantize_ptr cquantize; my_cquantize_ptr cquantize;
cquantize = (my_cquantize_ptr) cquantize = (my_cquantize_ptr) (*cinfo->mem->alloc_small)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_cquantizer));
SIZEOF(my_cquantizer)); cinfo->cquantize = &cquantize->pub;
cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
cquantize->pub.start_pass = start_pass_1_quant; cquantize->pub.start_pass = start_pass_1_quant;
cquantize->pub.finish_pass = finish_pass_1_quant; cquantize->pub.finish_pass = finish_pass_1_quant;
cquantize->pub.new_color_map = new_color_map_1_quant; cquantize->pub.new_color_map = new_color_map_1_quant;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jquant2.c * jquant2.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2011 by Guido Vollbeding. * Modified 2011-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -1197,8 +1197,8 @@ start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan) ...@@ -1197,8 +1197,8 @@ start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS); ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
if (cinfo->dither_mode == JDITHER_FS) { if (cinfo->dither_mode == JDITHER_FS) {
size_t arraysize = (size_t) ((cinfo->output_width + 2) * size_t arraysize = ((size_t) cinfo->output_width + (size_t) 2)
(3 * SIZEOF(FSERROR))); * (3 * SIZEOF(FSERROR));
/* Allocate Floyd-Steinberg workspace if we didn't already. */ /* Allocate Floyd-Steinberg workspace if we didn't already. */
if (cquantize->fserrors == NULL) if (cquantize->fserrors == NULL)
cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large) cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
...@@ -1247,10 +1247,9 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo) ...@@ -1247,10 +1247,9 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo)
my_cquantize_ptr cquantize; my_cquantize_ptr cquantize;
int i; int i;
cquantize = (my_cquantize_ptr) cquantize = (my_cquantize_ptr) (*cinfo->mem->alloc_small)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_cquantizer));
SIZEOF(my_cquantizer)); cinfo->cquantize = &cquantize->pub;
cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
cquantize->pub.start_pass = start_pass_2_quant; cquantize->pub.start_pass = start_pass_2_quant;
cquantize->pub.new_color_map = new_color_map_2_quant; cquantize->pub.new_color_map = new_color_map_2_quant;
cquantize->fserrors = NULL; /* flag optional arrays not allocated */ cquantize->fserrors = NULL; /* flag optional arrays not allocated */
...@@ -1284,7 +1283,8 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo) ...@@ -1284,7 +1283,8 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo)
if (desired > MAXNUMCOLORS) if (desired > MAXNUMCOLORS)
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS); ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
cquantize->sv_colormap = (*cinfo->mem->alloc_sarray) cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3); ((j_common_ptr) cinfo, JPOOL_IMAGE,
(JDIMENSION) desired, (JDIMENSION) 3);
cquantize->desired = desired; cquantize->desired = desired;
} else } else
cquantize->sv_colormap = NULL; cquantize->sv_colormap = NULL;
...@@ -1302,7 +1302,7 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo) ...@@ -1302,7 +1302,7 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo)
if (cinfo->dither_mode == JDITHER_FS) { if (cinfo->dither_mode == JDITHER_FS) {
cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large) cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE,
(size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR)))); ((size_t) cinfo->output_width + (size_t) 2) * (3 * SIZEOF(FSERROR)));
/* Might as well create the error-limiting table too. */ /* Might as well create the error-limiting table too. */
init_error_limit(cinfo); init_error_limit(cinfo);
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* jutils.c * jutils.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2009-2019 by Guido Vollbeding. * Modified 2009-2020 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -174,12 +174,12 @@ jzero_far (void FAR * target, size_t bytestozero) ...@@ -174,12 +174,12 @@ jzero_far (void FAR * target, size_t bytestozero)
GLOBAL(void) GLOBAL(void)
jcopy_sample_rows (JSAMPARRAY input_array, int source_row, jcopy_sample_rows (JSAMPARRAY input_array,
JSAMPARRAY output_array, int dest_row, JSAMPARRAY output_array,
int num_rows, JDIMENSION num_cols) int num_rows, JDIMENSION num_cols)
/* Copy some rows of samples from one place to another. /* Copy some rows of samples from one place to another.
* num_rows rows are copied from input_array[source_row++] * num_rows rows are copied from *input_array++ to *output_array++;
* to output_array[dest_row++]; these areas may overlap for duplication. * these areas may overlap for duplication.
* The source and destination arrays must be at least as wide as num_cols. * The source and destination arrays must be at least as wide as num_cols.
*/ */
{ {
...@@ -191,9 +191,6 @@ jcopy_sample_rows (JSAMPARRAY input_array, int source_row, ...@@ -191,9 +191,6 @@ jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
#endif #endif
register int row; register int row;
input_array += source_row;
output_array += dest_row;
for (row = num_rows; row > 0; row--) { for (row = num_rows; row > 0; row--) {
inptr = *input_array++; inptr = *input_array++;
outptr = *output_array++; outptr = *output_array++;
......
/* /*
* jversion.h * jversion.h
* *
* Copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding. * Copyright (C) 1991-2022, Thomas G. Lane, Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
...@@ -9,6 +9,6 @@ ...@@ -9,6 +9,6 @@
*/ */
#define JVERSION "9d 12-Jan-2020" #define JVERSION "9e 16-Jan-2022"
#define JCOPYRIGHT "Copyright (C) 2020, Thomas G. Lane, Guido Vollbeding" #define JCOPYRIGHT "Copyright (C) 2022, Thomas G. Lane, Guido Vollbeding"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment