Updated libjpeg to version 9c

jconfig.h was generated with these lines:
./configure --disable-shared --enable-static --host=powerpc-eabi --prefix=$DEVKITPRO/portlibs/ppc
This commit is contained in:
Crayon2000 2018-05-11 18:16:12 -04:00
parent 5cb05ac6c4
commit 560bd04719
32 changed files with 540 additions and 375 deletions

View file

@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
## [Unreleased] ## [Unreleased]
- libpng was updated to version 1.6.34 - libpng was updated to version 1.6.34
- zlib was updated to version 1.2.11 - zlib was updated to version 1.2.11
- libjpeg was updated to version 9b (17-Jan-2016) - libjpeg was updated to version 9c
- FreeType updated to version 2.4.12 - FreeType updated to version 2.4.12
- Fully compatible with devkitPPC release 29 - Fully compatible with devkitPPC release 29

View file

@ -1,7 +1,7 @@
The Independent JPEG Group's JPEG software The Independent JPEG Group's JPEG software
========================================== ==========================================
README for release 9b of 17-Jan-2016 README for release 9c of 14-Jan-2018
==================================== ====================================
This distribution contains the ninth public release of the Independent JPEG This distribution contains the ninth public release of the Independent JPEG
@ -115,7 +115,7 @@ with respect to this software, its quality, accuracy, merchantability, or
fitness for a particular purpose. This software is provided "AS IS", and you, fitness for a particular purpose. This software is provided "AS IS", and you,
its user, assume the entire risk as to its quality and accuracy. its user, assume the entire risk as to its quality and accuracy.
This software is copyright (C) 1991-2016, Thomas G. Lane, Guido Vollbeding. This software is copyright (C) 1991-2018, Thomas G. Lane, Guido Vollbeding.
All Rights Reserved except as specified below. All Rights Reserved except as specified below.
Permission is hereby granted to use, copy, modify, and distribute this Permission is hereby granted to use, copy, modify, and distribute this
@ -246,8 +246,8 @@ ARCHIVE LOCATIONS
The "official" archive site for this software is www.ijg.org. The "official" archive site for this software is www.ijg.org.
The most recent released version can always be found there in The most recent released version can always be found there in
directory "files". This particular version will be archived as directory "files". This particular version will be archived as
http://www.ijg.org/files/jpegsrc.v9b.tar.gz, and in Windows-compatible http://www.ijg.org/files/jpegsrc.v9c.tar.gz, and in Windows-compatible
"zip" archive format as http://www.ijg.org/files/jpegsr9b.zip. "zip" archive format as http://www.ijg.org/files/jpegsr9c.zip.
The JPEG FAQ (Frequently Asked Questions) article is a source of some The JPEG FAQ (Frequently Asked Questions) article is a source of some
general information about JPEG. general information about JPEG.
@ -293,8 +293,11 @@ communication about JPEG configuration in Sigma Photo Pro software.
Thank to Andrew Finkenstadt for hosting the ijg.org site. Thank to Andrew Finkenstadt for hosting the ijg.org site.
Last but not least special thank to Thomas G. Lane for the original Thank to Thomas G. Lane for the original design and development of
design and development of this singular software package. this singular software package.
Thank to Lars Goehler, Andreas Heinecke, Sebastian Fuss, Yvonne Roebert,
Andrej Werner, and Ulf-Dietrich Braumann for support and public relations.
FILE FORMAT WARS FILE FORMAT WARS

View file

@ -2,7 +2,7 @@
* cderror.h * cderror.h
* *
* Copyright (C) 1994-1997, Thomas G. Lane. * Copyright (C) 1994-1997, Thomas G. Lane.
* Modified 2009 by Guido Vollbeding. * Modified 2009-2017 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.
* *
@ -41,16 +41,16 @@ JMESSAGE(JMSG_FIRSTADDONCODE=1000, NULL) /* Must be first entry! */
#ifdef BMP_SUPPORTED #ifdef BMP_SUPPORTED
JMESSAGE(JERR_BMP_BADCMAP, "Unsupported BMP colormap format") JMESSAGE(JERR_BMP_BADCMAP, "Unsupported BMP colormap format")
JMESSAGE(JERR_BMP_BADDEPTH, "Only 8- and 24-bit BMP files are supported") JMESSAGE(JERR_BMP_BADDEPTH, "Only 8-, 24-, and 32-bit BMP files are supported")
JMESSAGE(JERR_BMP_BADHEADER, "Invalid BMP file: bad header length") JMESSAGE(JERR_BMP_BADHEADER, "Invalid BMP file: bad header length")
JMESSAGE(JERR_BMP_BADPLANES, "Invalid BMP file: biPlanes not equal to 1") JMESSAGE(JERR_BMP_BADPLANES, "Invalid BMP file: biPlanes not equal to 1")
JMESSAGE(JERR_BMP_COLORSPACE, "BMP output must be grayscale or RGB") JMESSAGE(JERR_BMP_COLORSPACE, "BMP output must be grayscale or RGB")
JMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported") JMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported")
JMESSAGE(JERR_BMP_EMPTY, "Empty BMP image")
JMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM") JMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM")
JMESSAGE(JTRC_BMP, "%ux%u 24-bit BMP image") JMESSAGE(JERR_BMP_OUTOFRANGE, "Numeric value out of range in BMP file")
JMESSAGE(JTRC_BMP, "%ux%u %d-bit BMP image")
JMESSAGE(JTRC_BMP_MAPPED, "%ux%u 8-bit colormapped BMP image") JMESSAGE(JTRC_BMP_MAPPED, "%ux%u 8-bit colormapped BMP image")
JMESSAGE(JTRC_BMP_OS2, "%ux%u 24-bit OS2 BMP image") JMESSAGE(JTRC_BMP_OS2, "%ux%u %d-bit OS2 BMP image")
JMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image") JMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image")
#endif /* BMP_SUPPORTED */ #endif /* BMP_SUPPORTED */
@ -75,6 +75,7 @@ JMESSAGE(JWRN_GIF_NOMOREDATA, "Ran out of GIF bits")
JMESSAGE(JERR_PPM_COLORSPACE, "PPM output must be grayscale or RGB") JMESSAGE(JERR_PPM_COLORSPACE, "PPM output must be grayscale or RGB")
JMESSAGE(JERR_PPM_NONNUMERIC, "Nonnumeric data in PPM file") JMESSAGE(JERR_PPM_NONNUMERIC, "Nonnumeric data in PPM file")
JMESSAGE(JERR_PPM_NOT, "Not a PPM/PGM file") JMESSAGE(JERR_PPM_NOT, "Not a PPM/PGM file")
JMESSAGE(JERR_PPM_OUTOFRANGE, "Numeric value out of range in PPM file")
JMESSAGE(JTRC_PGM, "%ux%u PGM image") JMESSAGE(JTRC_PGM, "%ux%u PGM image")
JMESSAGE(JTRC_PGM_TEXT, "%ux%u text PGM image") JMESSAGE(JTRC_PGM_TEXT, "%ux%u text PGM image")
JMESSAGE(JTRC_PPM, "%ux%u PPM image") JMESSAGE(JTRC_PPM, "%ux%u PPM image")

View file

@ -2,7 +2,7 @@
* jcinit.c * jcinit.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2003-2013 by Guido Vollbeding. * Modified 2003-2017 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.
* *
@ -21,6 +21,168 @@
#include "jpeglib.h" #include "jpeglib.h"
/*
* Compute JPEG image dimensions and related values.
* NOTE: this is exported for possible use by application.
* Hence it mustn't do anything that can't be done twice.
*/
GLOBAL(void)
jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo)
/* Do computations that are needed before master selection phase */
{
/* Sanity check on input image dimensions to prevent overflow in
* following calculations.
* We do check jpeg_width and jpeg_height in initial_setup in jcmaster.c,
* but image_width and image_height can come from arbitrary data,
* and we need some space for multiplication by block_size.
*/
if (((long) cinfo->image_width >> 24) || ((long) cinfo->image_height >> 24))
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
#ifdef DCT_SCALING_SUPPORTED
/* Compute actual JPEG image dimensions and DCT scaling choices. */
if (cinfo->scale_num >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/1 scaling */
cinfo->jpeg_width = cinfo->image_width * cinfo->block_size;
cinfo->jpeg_height = cinfo->image_height * cinfo->block_size;
cinfo->min_DCT_h_scaled_size = 1;
cinfo->min_DCT_v_scaled_size = 1;
} else if (cinfo->scale_num * 2 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/2 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 2L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 2L);
cinfo->min_DCT_h_scaled_size = 2;
cinfo->min_DCT_v_scaled_size = 2;
} else if (cinfo->scale_num * 3 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/3 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 3L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 3L);
cinfo->min_DCT_h_scaled_size = 3;
cinfo->min_DCT_v_scaled_size = 3;
} else if (cinfo->scale_num * 4 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/4 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 4L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 4L);
cinfo->min_DCT_h_scaled_size = 4;
cinfo->min_DCT_v_scaled_size = 4;
} else if (cinfo->scale_num * 5 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/5 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 5L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 5L);
cinfo->min_DCT_h_scaled_size = 5;
cinfo->min_DCT_v_scaled_size = 5;
} else if (cinfo->scale_num * 6 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/6 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 6L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 6L);
cinfo->min_DCT_h_scaled_size = 6;
cinfo->min_DCT_v_scaled_size = 6;
} else if (cinfo->scale_num * 7 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/7 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 7L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 7L);
cinfo->min_DCT_h_scaled_size = 7;
cinfo->min_DCT_v_scaled_size = 7;
} else if (cinfo->scale_num * 8 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/8 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 8L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 8L);
cinfo->min_DCT_h_scaled_size = 8;
cinfo->min_DCT_v_scaled_size = 8;
} else if (cinfo->scale_num * 9 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/9 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 9L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 9L);
cinfo->min_DCT_h_scaled_size = 9;
cinfo->min_DCT_v_scaled_size = 9;
} else if (cinfo->scale_num * 10 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/10 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 10L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 10L);
cinfo->min_DCT_h_scaled_size = 10;
cinfo->min_DCT_v_scaled_size = 10;
} else if (cinfo->scale_num * 11 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/11 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 11L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 11L);
cinfo->min_DCT_h_scaled_size = 11;
cinfo->min_DCT_v_scaled_size = 11;
} else if (cinfo->scale_num * 12 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/12 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 12L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 12L);
cinfo->min_DCT_h_scaled_size = 12;
cinfo->min_DCT_v_scaled_size = 12;
} else if (cinfo->scale_num * 13 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/13 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 13L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 13L);
cinfo->min_DCT_h_scaled_size = 13;
cinfo->min_DCT_v_scaled_size = 13;
} else if (cinfo->scale_num * 14 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/14 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 14L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 14L);
cinfo->min_DCT_h_scaled_size = 14;
cinfo->min_DCT_v_scaled_size = 14;
} else if (cinfo->scale_num * 15 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/15 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 15L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 15L);
cinfo->min_DCT_h_scaled_size = 15;
cinfo->min_DCT_v_scaled_size = 15;
} else {
/* Provide block_size/16 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 16L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 16L);
cinfo->min_DCT_h_scaled_size = 16;
cinfo->min_DCT_v_scaled_size = 16;
}
#else /* !DCT_SCALING_SUPPORTED */
/* Hardwire it to "no scaling" */
cinfo->jpeg_width = cinfo->image_width;
cinfo->jpeg_height = cinfo->image_height;
cinfo->min_DCT_h_scaled_size = DCTSIZE;
cinfo->min_DCT_v_scaled_size = DCTSIZE;
#endif /* DCT_SCALING_SUPPORTED */
}
/* /*
* Master selection of compression modules. * Master selection of compression modules.
* This is done once at the start of processing an image. We determine * This is done once at the start of processing an image. We determine
@ -37,7 +199,7 @@ jinit_compress_master (j_compress_ptr cinfo)
if (cinfo->data_precision != BITS_IN_JSAMPLE) if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Sanity check on image dimensions */ /* Sanity check on input image dimensions */
if (cinfo->image_height <= 0 || cinfo->image_width <= 0 || if (cinfo->image_height <= 0 || cinfo->image_width <= 0 ||
cinfo->input_components <= 0) cinfo->input_components <= 0)
ERREXIT(cinfo, JERR_EMPTY_IMAGE); ERREXIT(cinfo, JERR_EMPTY_IMAGE);
@ -48,6 +210,9 @@ jinit_compress_master (j_compress_ptr cinfo)
if ((long) jd_samplesperrow != samplesperrow) if ((long) jd_samplesperrow != samplesperrow)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
/* Compute JPEG image dimensions and related values. */
jpeg_calc_jpeg_dimensions(cinfo);
/* Initialize master control (includes parameter checking/processing) */ /* Initialize master control (includes parameter checking/processing) */
jinit_c_master_control(cinfo, FALSE /* full compression */); jinit_c_master_control(cinfo, FALSE /* full compression */);

View file

@ -2,7 +2,7 @@
* jcmaster.c * jcmaster.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2003-2013 by Guido Vollbeding. * Modified 2003-2017 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.
* *
@ -43,191 +43,13 @@ typedef my_comp_master * my_master_ptr;
* Support routines that do various essential calculations. * Support routines that do various essential calculations.
*/ */
/*
* Compute JPEG image dimensions and related values.
* NOTE: this is exported for possible use by application.
* Hence it mustn't do anything that can't be done twice.
*/
GLOBAL(void)
jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo)
/* Do computations that are needed before master selection phase */
{
#ifdef DCT_SCALING_SUPPORTED
/* Sanity check on input image dimensions to prevent overflow in
* following calculation.
* We do check jpeg_width and jpeg_height in initial_setup below,
* but image_width and image_height can come from arbitrary data,
* and we need some space for multiplication by block_size.
*/
if (((long) cinfo->image_width >> 24) || ((long) cinfo->image_height >> 24))
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
/* Compute actual JPEG image dimensions and DCT scaling choices. */
if (cinfo->scale_num >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/1 scaling */
cinfo->jpeg_width = cinfo->image_width * cinfo->block_size;
cinfo->jpeg_height = cinfo->image_height * cinfo->block_size;
cinfo->min_DCT_h_scaled_size = 1;
cinfo->min_DCT_v_scaled_size = 1;
} else if (cinfo->scale_num * 2 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/2 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 2L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 2L);
cinfo->min_DCT_h_scaled_size = 2;
cinfo->min_DCT_v_scaled_size = 2;
} else if (cinfo->scale_num * 3 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/3 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 3L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 3L);
cinfo->min_DCT_h_scaled_size = 3;
cinfo->min_DCT_v_scaled_size = 3;
} else if (cinfo->scale_num * 4 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/4 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 4L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 4L);
cinfo->min_DCT_h_scaled_size = 4;
cinfo->min_DCT_v_scaled_size = 4;
} else if (cinfo->scale_num * 5 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/5 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 5L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 5L);
cinfo->min_DCT_h_scaled_size = 5;
cinfo->min_DCT_v_scaled_size = 5;
} else if (cinfo->scale_num * 6 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/6 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 6L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 6L);
cinfo->min_DCT_h_scaled_size = 6;
cinfo->min_DCT_v_scaled_size = 6;
} else if (cinfo->scale_num * 7 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/7 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 7L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 7L);
cinfo->min_DCT_h_scaled_size = 7;
cinfo->min_DCT_v_scaled_size = 7;
} else if (cinfo->scale_num * 8 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/8 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 8L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 8L);
cinfo->min_DCT_h_scaled_size = 8;
cinfo->min_DCT_v_scaled_size = 8;
} else if (cinfo->scale_num * 9 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/9 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 9L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 9L);
cinfo->min_DCT_h_scaled_size = 9;
cinfo->min_DCT_v_scaled_size = 9;
} else if (cinfo->scale_num * 10 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/10 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 10L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 10L);
cinfo->min_DCT_h_scaled_size = 10;
cinfo->min_DCT_v_scaled_size = 10;
} else if (cinfo->scale_num * 11 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/11 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 11L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 11L);
cinfo->min_DCT_h_scaled_size = 11;
cinfo->min_DCT_v_scaled_size = 11;
} else if (cinfo->scale_num * 12 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/12 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 12L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 12L);
cinfo->min_DCT_h_scaled_size = 12;
cinfo->min_DCT_v_scaled_size = 12;
} else if (cinfo->scale_num * 13 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/13 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 13L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 13L);
cinfo->min_DCT_h_scaled_size = 13;
cinfo->min_DCT_v_scaled_size = 13;
} else if (cinfo->scale_num * 14 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/14 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 14L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 14L);
cinfo->min_DCT_h_scaled_size = 14;
cinfo->min_DCT_v_scaled_size = 14;
} else if (cinfo->scale_num * 15 >= cinfo->scale_denom * cinfo->block_size) {
/* Provide block_size/15 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 15L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 15L);
cinfo->min_DCT_h_scaled_size = 15;
cinfo->min_DCT_v_scaled_size = 15;
} else {
/* Provide block_size/16 scaling */
cinfo->jpeg_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 16L);
cinfo->jpeg_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 16L);
cinfo->min_DCT_h_scaled_size = 16;
cinfo->min_DCT_v_scaled_size = 16;
}
#else /* !DCT_SCALING_SUPPORTED */
/* Hardwire it to "no scaling" */
cinfo->jpeg_width = cinfo->image_width;
cinfo->jpeg_height = cinfo->image_height;
cinfo->min_DCT_h_scaled_size = DCTSIZE;
cinfo->min_DCT_v_scaled_size = DCTSIZE;
#endif /* DCT_SCALING_SUPPORTED */
}
LOCAL(void) LOCAL(void)
jpeg_calc_trans_dimensions (j_compress_ptr cinfo) initial_setup (j_compress_ptr cinfo)
{
if (cinfo->min_DCT_h_scaled_size != cinfo->min_DCT_v_scaled_size)
ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
cinfo->min_DCT_h_scaled_size, cinfo->min_DCT_v_scaled_size);
cinfo->block_size = cinfo->min_DCT_h_scaled_size;
}
LOCAL(void)
initial_setup (j_compress_ptr cinfo, boolean transcode_only)
/* Do computations that are needed before master selection phase */ /* Do computations that are needed before master selection phase */
{ {
int ci, ssize; int ci, ssize;
jpeg_component_info *compptr; jpeg_component_info *compptr;
if (transcode_only)
jpeg_calc_trans_dimensions(cinfo);
else
jpeg_calc_jpeg_dimensions(cinfo);
/* Sanity check on block_size */ /* Sanity check on block_size */
if (cinfo->block_size < 1 || cinfo->block_size > 16) if (cinfo->block_size < 1 || cinfo->block_size > 16)
ERREXIT2(cinfo, JERR_BAD_DCTSIZE, cinfo->block_size, cinfo->block_size); ERREXIT2(cinfo, JERR_BAD_DCTSIZE, cinfo->block_size, cinfo->block_size);
@ -414,13 +236,9 @@ validate_script (j_compress_ptr cinfo)
* out-of-range reconstructed DC values during the first DC scan, * out-of-range reconstructed DC values during the first DC scan,
* which might cause problems for some decoders. * which might cause problems for some decoders.
*/ */
#if BITS_IN_JSAMPLE == 8
#define MAX_AH_AL 10
#else
#define MAX_AH_AL 13
#endif
if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 || if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL) Ah < 0 || Ah > (cinfo->data_precision > 8 ? 13 : 10) ||
Al < 0 || Al > (cinfo->data_precision > 8 ? 13 : 10))
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
if (Ss == 0) { if (Ss == 0) {
if (Se != 0) /* DC and AC together not OK */ if (Se != 0) /* DC and AC together not OK */
@ -812,7 +630,7 @@ jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
master->pub.is_last_pass = FALSE; master->pub.is_last_pass = FALSE;
/* Validate parameters, determine derived values */ /* Validate parameters, determine derived values */
initial_setup(cinfo, transcode_only); initial_setup(cinfo);
if (cinfo->scan_info != NULL) { if (cinfo->scan_info != NULL) {
#ifdef C_MULTISCAN_FILES_SUPPORTED #ifdef C_MULTISCAN_FILES_SUPPORTED

View file

@ -18,6 +18,20 @@
/* Define this if you get warnings about undefined structures. */ /* Define this if you get warnings about undefined structures. */
/* #undef INCOMPLETE_TYPES_BROKEN */ /* #undef INCOMPLETE_TYPES_BROKEN */
/* Define "boolean" as unsigned char, not enum, on Windows systems. */
#ifdef _WIN32
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean;
#endif
#ifndef FALSE /* in case these macros already exist */
#define FALSE 0 /* values of boolean */
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
#endif
#ifdef JPEG_INTERNALS #ifdef JPEG_INTERNALS
/* #undef RIGHT_SHIFT_IS_UNSIGNED */ /* #undef RIGHT_SHIFT_IS_UNSIGNED */

View file

@ -2,7 +2,7 @@
* jctrans.c * jctrans.c
* *
* Copyright (C) 1995-1998, Thomas G. Lane. * Copyright (C) 1995-1998, Thomas G. Lane.
* Modified 2000-2013 by Guido Vollbeding. * Modified 2000-2017 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.
* *
@ -85,12 +85,15 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
jpeg_set_defaults(dstinfo); jpeg_set_defaults(dstinfo);
/* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB. /* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB.
* Fix it to get the right header markers for the image colorspace. * Fix it to get the right header markers for the image colorspace.
* Note: Entropy table assignment in jpeg_set_colorspace depends * Note: Entropy table assignment in jpeg_set_colorspace
* on color_transform. * depends on color_transform.
* Adaption is also required for setting the appropriate
* entropy coding mode dependent on image data precision.
*/ */
dstinfo->color_transform = srcinfo->color_transform; dstinfo->color_transform = srcinfo->color_transform;
jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space); jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
dstinfo->data_precision = srcinfo->data_precision; dstinfo->data_precision = srcinfo->data_precision;
dstinfo->arith_code = srcinfo->data_precision > 8 ? TRUE : FALSE;
dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling; dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
/* Copy the source's quantization tables. */ /* Copy the source's quantization tables. */
for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
@ -157,6 +160,18 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
} }
LOCAL(void)
jpeg_calc_trans_dimensions (j_compress_ptr cinfo)
/* Do computations that are needed before master selection phase */
{
if (cinfo->min_DCT_h_scaled_size != cinfo->min_DCT_v_scaled_size)
ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
cinfo->min_DCT_h_scaled_size, cinfo->min_DCT_v_scaled_size);
cinfo->block_size = cinfo->min_DCT_h_scaled_size;
}
/* /*
* Master selection of compression modules for transcoding. * Master selection of compression modules for transcoding.
* This substitutes for jcinit.c's initialization of the full compressor. * This substitutes for jcinit.c's initialization of the full compressor.
@ -166,6 +181,9 @@ LOCAL(void)
transencode_master_selection (j_compress_ptr cinfo, transencode_master_selection (j_compress_ptr cinfo,
jvirt_barray_ptr * coef_arrays) jvirt_barray_ptr * coef_arrays)
{ {
/* Do computations that are needed before master selection phase */
jpeg_calc_trans_dimensions(cinfo);
/* Initialize master control (includes parameter checking/processing) */ /* Initialize master control (includes parameter checking/processing) */
jinit_c_master_control(cinfo, TRUE /* transcode only */); jinit_c_master_control(cinfo, TRUE /* transcode only */);

View file

@ -2,7 +2,7 @@
* jdatadst.c * jdatadst.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2009-2012 by Guido Vollbeding. * Modified 2009-2017 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,9 +170,9 @@ term_destination (j_compress_ptr cinfo)
if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount) if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
ERREXIT(cinfo, JERR_FILE_WRITE); ERREXIT(cinfo, JERR_FILE_WRITE);
} }
fflush(dest->outfile); JFFLUSH(dest->outfile);
/* Make sure we wrote the output file OK */ /* Make sure we wrote the output file OK */
if (ferror(dest->outfile)) if (JFERROR(dest->outfile))
ERREXIT(cinfo, JERR_FILE_WRITE); ERREXIT(cinfo, JERR_FILE_WRITE);
} }

View file

@ -2,7 +2,7 @@
* jdcolor.c * jdcolor.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2011-2015 by Guido Vollbeding. * Modified 2011-2017 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.
* *
@ -14,6 +14,12 @@
#include "jpeglib.h" #include "jpeglib.h"
#if RANGE_BITS < 2
/* Deliberate syntax err */
Sorry, this code requires 2 or more range extension bits.
#endif
/* Private subobject */ /* Private subobject */
typedef struct { typedef struct {

View file

@ -2,7 +2,7 @@
* jdct.h * jdct.h
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2002-2015 by Guido Vollbeding. * Modified 2002-2017 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.
* *
@ -79,13 +79,12 @@ typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
* converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could * converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
* be quite far out of range if the input data is corrupt, so a bulletproof * be quite far out of range if the input data is corrupt, so a bulletproof
* range-limiting step is required. We use a mask-and-table-lookup method * range-limiting step is required. We use a mask-and-table-lookup method
* to do the combined operations quickly, assuming that MAXJSAMPLE+1 * to do the combined operations quickly, assuming that RANGE_CENTER
* is a power of 2. See the comments with prepare_range_limit_table * (defined in jpegint.h) is a power of 2. See the comments with
* (in jdmaster.c) for more info. * prepare_range_limit_table (in jdmaster.c) for more info.
*/ */
#define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */ #define RANGE_MASK (RANGE_CENTER * 2 - 1)
#define RANGE_CENTER (MAXJSAMPLE * 2 + 2)
#define RANGE_SUBSET (RANGE_CENTER - CENTERJSAMPLE) #define RANGE_SUBSET (RANGE_CENTER - CENTERJSAMPLE)
#define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit - RANGE_SUBSET) #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit - RANGE_SUBSET)

View file

@ -2,7 +2,7 @@
* jdhuff.c * jdhuff.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2006-2013 by Guido Vollbeding. * Modified 2006-2016 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.
* *
@ -799,10 +799,6 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
if (! entropy->insufficient_data) { if (! entropy->insufficient_data) {
Se = cinfo->Se;
Al = cinfo->Al;
natural_order = cinfo->natural_order;
/* Load up working state. /* Load up working state.
* We can avoid loading/saving bitread state if in an EOB run. * We can avoid loading/saving bitread state if in an EOB run.
*/ */
@ -814,6 +810,9 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
EOBRUN--; /* ...process it now (we do nothing) */ EOBRUN--; /* ...process it now (we do nothing) */
else { else {
BITREAD_LOAD_STATE(cinfo,entropy->bitstate); BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
Se = cinfo->Se;
Al = cinfo->Al;
natural_order = cinfo->natural_order;
block = MCU_data[0]; block = MCU_data[0];
tbl = entropy->ac_derived_tbl; tbl = entropy->ac_derived_tbl;

View file

@ -2,7 +2,7 @@
* jdmainct.c * jdmainct.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2002-2012 by Guido Vollbeding. * Modified 2002-2016 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.
* *
@ -26,8 +26,8 @@
* trivial. Its responsibility is to provide context rows for upsampling/ * trivial. Its responsibility is to provide context rows for upsampling/
* rescaling, and doing this in an efficient fashion is a bit tricky. * rescaling, and doing this in an efficient fashion is a bit tricky.
* *
* Postprocessor input data is counted in "row groups". A row group * Postprocessor input data is counted in "row groups". A row group is
* is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size) * defined to be (v_samp_factor * DCT_v_scaled_size / min_DCT_v_scaled_size)
* sample rows of each component. (We require DCT_scaled_size values to be * sample rows of each component. (We require DCT_scaled_size values to be
* chosen such that these numbers are integers. In practice DCT_scaled_size * chosen such that these numbers are integers. In practice DCT_scaled_size
* values will likely be powers of two, so we actually have the stronger * values will likely be powers of two, so we actually have the stronger
@ -37,8 +37,8 @@
* applying). * applying).
* *
* The coefficient controller will deliver data to us one iMCU row at a time; * The coefficient controller will deliver data to us one iMCU row at a time;
* each iMCU row contains v_samp_factor * DCT_scaled_size sample rows, or * each iMCU row contains v_samp_factor * DCT_v_scaled_size sample rows, or
* exactly min_DCT_scaled_size row groups. (This amount of data corresponds * exactly min_DCT_v_scaled_size row groups. (This amount of data corresponds
* to one row of MCUs when the image is fully interleaved.) Note that the * to one row of MCUs when the image is fully interleaved.) Note that the
* number of sample rows varies across components, but the number of row * number of sample rows varies across components, but the number of row
* groups does not. Some garbage sample rows may be included in the last iMCU * groups does not. Some garbage sample rows may be included in the last iMCU
@ -75,7 +75,7 @@
* We could do this most simply by copying data around in our buffer, but * We could do this most simply by copying data around in our buffer, but
* that'd be very slow. We can avoid copying any data by creating a rather * that'd be very slow. We can avoid copying any data by creating a rather
* strange pointer structure. Here's how it works. We allocate a workspace * strange pointer structure. Here's how it works. We allocate a workspace
* consisting of M+2 row groups (where M = min_DCT_scaled_size is the number * consisting of M+2 row groups (where M = min_DCT_v_scaled_size is the number
* of row groups per iMCU row). We create two sets of redundant pointers to * of row groups per iMCU row). We create two sets of redundant pointers to
* the workspace. Labeling the physical row groups 0 to M+1, the synthesized * the workspace. Labeling the physical row groups 0 to M+1, the synthesized
* pointer lists look like this: * pointer lists look like this:
@ -100,11 +100,11 @@
* the first or last sample row as necessary (this is cheaper than copying * the first or last sample row as necessary (this is cheaper than copying
* sample rows around). * sample rows around).
* *
* This scheme breaks down if M < 2, ie, min_DCT_scaled_size is 1. In that * This scheme breaks down if M < 2, ie, min_DCT_v_scaled_size is 1. In that
* situation each iMCU row provides only one row group so the buffering logic * situation each iMCU row provides only one row group so the buffering logic
* must be different (eg, we must read two iMCU rows before we can emit the * must be different (eg, we must read two iMCU rows before we can emit the
* first row group). For now, we simply do not support providing context * first row group). For now, we simply do not support providing context
* rows when min_DCT_scaled_size is 1. That combination seems unlikely to * rows when min_DCT_v_scaled_size is 1. That combination seems unlikely to
* be worth providing --- if someone wants a 1/8th-size preview, they probably * be worth providing --- if someone wants a 1/8th-size preview, they probably
* want it quick and dirty, so a context-free upsampler is sufficient. * want it quick and dirty, so a context-free upsampler is sufficient.
*/ */
@ -118,17 +118,18 @@ typedef struct {
/* Pointer to allocated workspace (M or M+2 row groups). */ /* Pointer to allocated workspace (M or M+2 row groups). */
JSAMPARRAY buffer[MAX_COMPONENTS]; JSAMPARRAY buffer[MAX_COMPONENTS];
boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */ JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
/* Remaining fields are only used in the context case. */ /* Remaining fields are only used in the context case. */
boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
/* These are the master pointers to the funny-order pointer lists. */ /* These are the master pointers to the funny-order pointer lists. */
JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */ JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
int whichptr; /* indicates which pointer set is now in use */ int whichptr; /* indicates which pointer set is now in use */
int context_state; /* process_data state machine status */ int context_state; /* process_data state machine status */
JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */ JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
} my_main_controller; } my_main_controller;
@ -195,7 +196,7 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
LOCAL(void) LOCAL(void)
make_funny_pointers (j_decompress_ptr cinfo) make_funny_pointers (j_decompress_ptr cinfo)
/* Create the funny pointer lists discussed in the comments above. /* Create the funny pointer lists discussed in the comments above.
* The actual workspace is already allocated (in main->buffer), * The actual workspace is already allocated (in mainp->buffer),
* and the space for the pointer lists is allocated too. * and the space for the pointer lists is allocated too.
* This routine just fills in the curiously ordered lists. * This routine just fills in the curiously ordered lists.
* This will be repeated at the beginning of each pass. * This will be repeated at the beginning of each pass.
@ -317,12 +318,12 @@ start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
mainp->whichptr = 0; /* Read first iMCU row into xbuffer[0] */ mainp->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
mainp->context_state = CTX_PREPARE_FOR_IMCU; mainp->context_state = CTX_PREPARE_FOR_IMCU;
mainp->iMCU_row_ctr = 0; mainp->iMCU_row_ctr = 0;
mainp->buffer_full = FALSE; /* Mark buffer empty */
} else { } else {
/* Simple case with no context needed */ /* Simple case with no context needed */
mainp->pub.process_data = process_data_simple_main; mainp->pub.process_data = process_data_simple_main;
mainp->rowgroup_ctr = mainp->rowgroups_avail; /* Mark buffer empty */
} }
mainp->buffer_full = FALSE; /* Mark buffer empty */
mainp->rowgroup_ctr = 0;
break; break;
#ifdef QUANT_2PASS_SUPPORTED #ifdef QUANT_2PASS_SUPPORTED
case JBUF_CRANK_DEST: case JBUF_CRANK_DEST:
@ -348,17 +349,14 @@ process_data_simple_main (j_decompress_ptr cinfo,
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;
JDIMENSION rowgroups_avail;
/* Read input data if we haven't filled the main buffer yet */ /* Read input data if we haven't filled the main buffer yet */
if (! mainp->buffer_full) { if (mainp->rowgroup_ctr >= mainp->rowgroups_avail) {
if (! (*cinfo->coef->decompress_data) (cinfo, mainp->buffer)) if (! (*cinfo->coef->decompress_data) (cinfo, mainp->buffer))
return; /* suspension forced, can do nothing more */ return; /* suspension forced, can do nothing more */
mainp->buffer_full = TRUE; /* OK, we have an iMCU row to work with */ mainp->rowgroup_ctr = 0; /* OK, we have an iMCU row to work with */
} }
/* There are always min_DCT_scaled_size row groups in an iMCU row. */
rowgroups_avail = (JDIMENSION) cinfo->min_DCT_v_scaled_size;
/* Note: at the bottom of the image, we may pass extra garbage row groups /* Note: at the bottom of the image, we may pass extra garbage row groups
* to the postprocessor. The postprocessor has to check for bottom * to the postprocessor. The postprocessor has to check for bottom
* of image anyway (at row resolution), so no point in us doing it too. * of image anyway (at row resolution), so no point in us doing it too.
@ -366,14 +364,8 @@ process_data_simple_main (j_decompress_ptr cinfo,
/* Feed the postprocessor */ /* Feed the postprocessor */
(*cinfo->post->post_process_data) (cinfo, mainp->buffer, (*cinfo->post->post_process_data) (cinfo, mainp->buffer,
&mainp->rowgroup_ctr, rowgroups_avail, &mainp->rowgroup_ctr, mainp->rowgroups_avail,
output_buf, out_row_ctr, out_rows_avail); output_buf, out_row_ctr, out_rows_avail);
/* Has postprocessor consumed all the data yet? If so, mark buffer empty */
if (mainp->rowgroup_ctr >= rowgroups_avail) {
mainp->buffer_full = FALSE;
mainp->rowgroup_ctr = 0;
}
} }
@ -498,7 +490,9 @@ jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */ alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
ngroups = cinfo->min_DCT_v_scaled_size + 2; ngroups = cinfo->min_DCT_v_scaled_size + 2;
} else { } else {
/* There are always min_DCT_v_scaled_size row groups in an iMCU row. */
ngroups = cinfo->min_DCT_v_scaled_size; ngroups = cinfo->min_DCT_v_scaled_size;
mainp->rowgroups_avail = (JDIMENSION) ngroups;
} }
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;

View file

@ -2,7 +2,7 @@
* jdmaster.c * jdmaster.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2002-2015 by Guido Vollbeding. * Modified 2002-2017 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.
* *
@ -237,18 +237,17 @@ prepare_range_limit_table (j_decompress_ptr cinfo)
JSAMPLE * table; JSAMPLE * table;
int i; int i;
table = (JSAMPLE *) table = (JSAMPLE *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, JPOOL_IMAGE, (RANGE_CENTER * 2 + MAXJSAMPLE + 1) * SIZEOF(JSAMPLE));
5 * (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
/* First segment of range limit table: limit[x] = 0 for x < 0 */ /* First segment of range limit table: limit[x] = 0 for x < 0 */
MEMZERO(table, 2 * (MAXJSAMPLE+1) * SIZEOF(JSAMPLE)); MEMZERO(table, RANGE_CENTER * SIZEOF(JSAMPLE));
table += 2 * (MAXJSAMPLE+1); /* allow negative subscripts of table */ table += RANGE_CENTER; /* allow negative subscripts of table */
cinfo->sample_range_limit = table; cinfo->sample_range_limit = table;
/* Main part of range limit table: limit[x] = x */ /* Main part of range limit table: limit[x] = x */
for (i = 0; i <= MAXJSAMPLE; i++) for (i = 0; i <= MAXJSAMPLE; i++)
table[i] = (JSAMPLE) i; table[i] = (JSAMPLE) i;
/* End of range limit table: limit[x] = MAXJSAMPLE for x > MAXJSAMPLE */ /* End of range limit table: limit[x] = MAXJSAMPLE for x > MAXJSAMPLE */
for (; i < 3 * (MAXJSAMPLE+1); i++) for (; i <= MAXJSAMPLE + RANGE_CENTER; i++)
table[i] = MAXJSAMPLE; table[i] = MAXJSAMPLE;
} }

View file

@ -2,7 +2,7 @@
* jdmerge.c * jdmerge.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2013-2015 by Guido Vollbeding. * Modified 2013-2017 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.
* *
@ -40,6 +40,12 @@
#ifdef UPSAMPLE_MERGING_SUPPORTED #ifdef UPSAMPLE_MERGING_SUPPORTED
#if RANGE_BITS < 2
/* Deliberate syntax err */
Sorry, this code requires 2 or more range extension bits.
#endif
/* Private subobject */ /* Private subobject */
typedef struct { typedef struct {

View file

@ -2,7 +2,7 @@
* jfdctflt.c * jfdctflt.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2003-2015 by Guido Vollbeding. * Modified 2003-2017 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.
* *
@ -48,7 +48,7 @@
*/ */
#if DCTSIZE != 8 #if DCTSIZE != 8
Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ Sorry, this code only copes with 8x8 DCT blocks. /* deliberate syntax err */
#endif #endif

View file

@ -2,7 +2,7 @@
* jfdctfst.c * jfdctfst.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2003-2015 by Guido Vollbeding. * Modified 2003-2017 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.
* *
@ -44,7 +44,7 @@
*/ */
#if DCTSIZE != 8 #if DCTSIZE != 8
Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ Sorry, this code only copes with 8x8 DCT blocks. /* deliberate syntax err */
#endif #endif

View file

@ -2,7 +2,7 @@
* jidctflt.c * jidctflt.c
* *
* Copyright (C) 1994-1998, Thomas G. Lane. * Copyright (C) 1994-1998, Thomas G. Lane.
* Modified 2010-2015 by Guido Vollbeding. * Modified 2010-2017 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.
* *
@ -50,7 +50,7 @@
*/ */
#if DCTSIZE != 8 #if DCTSIZE != 8
Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ Sorry, this code only copes with 8x8 DCT blocks. /* deliberate syntax err */
#endif #endif

View file

@ -2,7 +2,7 @@
* jidctfst.c * jidctfst.c
* *
* Copyright (C) 1994-1998, Thomas G. Lane. * Copyright (C) 1994-1998, Thomas G. Lane.
* Modified 2015 by Guido Vollbeding. * Modified 2015-2017 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.
* *
@ -46,7 +46,7 @@
*/ */
#if DCTSIZE != 8 #if DCTSIZE != 8
Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ Sorry, this code only copes with 8x8 DCT blocks. /* deliberate syntax err */
#endif #endif

View file

@ -2,7 +2,7 @@
* jidctint.c * jidctint.c
* *
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modification developed 2002-2015 by Guido Vollbeding. * Modification developed 2002-2016 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.
* *
@ -166,6 +166,7 @@
/* /*
* Perform dequantization and inverse DCT on one block of coefficients. * Perform dequantization and inverse DCT on one block of coefficients.
* *
* Optimized algorithm with 12 multiplications in the 1-D kernel.
* cK represents sqrt(2) * cos(K*pi/16). * cK represents sqrt(2) * cos(K*pi/16).
*/ */
@ -428,7 +429,7 @@ jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* /*
* Perform dequantization and inverse DCT on one block of coefficients, * Perform dequantization and inverse DCT on one block of coefficients,
* producing a 7x7 output block. * producing a reduced-size 7x7 output block.
* *
* Optimized algorithm with 12 multiplications in the 1-D kernel. * Optimized algorithm with 12 multiplications in the 1-D kernel.
* cK represents sqrt(2) * cos(K*pi/14). * cK represents sqrt(2) * cos(K*pi/14).
@ -2623,7 +2624,7 @@ jpeg_idct_16x16 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
tmp0 <<= CONST_BITS; tmp0 <<= CONST_BITS;
/* Add fudge factor here for final descale. */ /* Add fudge factor here for final descale. */
tmp0 += 1 << (CONST_BITS-PASS1_BITS-1); tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);
z1 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); z1 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
tmp1 = MULTIPLY(z1, FIX(1.306562965)); /* c4[16] = c2[8] */ tmp1 = MULTIPLY(z1, FIX(1.306562965)); /* c4[16] = c2[8] */
@ -2920,13 +2921,6 @@ jpeg_idct_16x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
* The rotator is c(-6). * The rotator is c(-6).
*/ */
z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
z2 <<= CONST_BITS; z2 <<= CONST_BITS;
@ -2937,6 +2931,13 @@ jpeg_idct_16x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp0 = z2 + z3; tmp0 = z2 + z3;
tmp1 = z2 - z3; tmp1 = z2 - z3;
z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
tmp10 = tmp0 + tmp2; tmp10 = tmp0 + tmp2;
tmp13 = tmp0 - tmp2; tmp13 = tmp0 - tmp2;
tmp11 = tmp1 + tmp3; tmp11 = tmp1 + tmp3;
@ -4883,13 +4884,6 @@ jpeg_idct_4x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
* The rotator is c(-6). * The rotator is c(-6).
*/ */
z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
z2 <<= CONST_BITS; z2 <<= CONST_BITS;
@ -4900,6 +4894,13 @@ jpeg_idct_4x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp0 = z2 + z3; tmp0 = z2 + z3;
tmp1 = z2 - z3; tmp1 = z2 - z3;
z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
tmp10 = tmp0 + tmp2; tmp10 = tmp0 + tmp2;
tmp13 = tmp0 - tmp2; tmp13 = tmp0 - tmp2;
tmp11 = tmp1 + tmp3; tmp11 = tmp1 + tmp3;

View file

@ -2,6 +2,7 @@
* jinclude.h * jinclude.h
* *
* Copyright (C) 1991-1994, Thomas G. Lane. * Copyright (C) 1991-1994, Thomas G. Lane.
* Modified 2017 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.
* *
@ -83,9 +84,14 @@
* The modules that use fread() and fwrite() always invoke them through * The modules that use fread() and fwrite() always invoke them through
* these macros. On some systems you may need to twiddle the argument casts. * these macros. On some systems you may need to twiddle the argument casts.
* CAUTION: argument order is different from underlying functions! * CAUTION: argument order is different from underlying functions!
*
* Furthermore, macros are provided for fflush() and ferror() in order
* to facilitate adaption by applications using an own FILE class.
*/ */
#define JFREAD(file,buf,sizeofbuf) \ #define JFREAD(file,buf,sizeofbuf) \
((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
#define JFWRITE(file,buf,sizeofbuf) \ #define JFWRITE(file,buf,sizeofbuf) \
((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
#define JFFLUSH(file) fflush(file)
#define JFERROR(file) ferror(file)

View file

@ -2,7 +2,7 @@
* jpegint.h * jpegint.h
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 1997-2013 by Guido Vollbeding. * Modified 1997-2017 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.
* *
@ -260,6 +260,19 @@ struct jpeg_color_quantizer {
}; };
/* Definition of range extension bits for decompression processes.
* See the comments with prepare_range_limit_table (in jdmaster.c)
* for more info.
* The recommended default value for normal applications is 2.
* Applications with special requirements may use a different value.
* For example, Ghostscript wants to use 3 for proper handling of
* wacky images with oversize coefficient values.
*/
#define RANGE_BITS 2
#define RANGE_CENTER (CENTERJSAMPLE << RANGE_BITS)
/* Miscellaneous useful macros */ /* Miscellaneous useful macros */
#undef MAX #undef MAX

View file

@ -2,7 +2,7 @@
* jpeglib.h * jpeglib.h
* *
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2002-2015 by Guido Vollbeding. * Modified 2002-2017 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" {
#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 2 #define JPEG_LIB_VERSION_MINOR 3
/* Various constants determining the sizes of things. /* Various constants determining the sizes of things.
@ -411,8 +411,8 @@ struct jpeg_compress_struct {
JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */ JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
/* The coefficient controller receives data in units of MCU rows as defined /* The coefficient controller receives data in units of MCU rows as defined
* for fully interleaved scans (whether the JPEG file is interleaved or not). * for fully interleaved scans (whether the JPEG file is interleaved or not).
* There are v_samp_factor * DCTSIZE sample rows of each component in an * There are v_samp_factor * DCT_v_scaled_size sample rows of each component
* "iMCU" (interleaved MCU) row. * in an "iMCU" (interleaved MCU) row.
*/ */
/* /*

View file

@ -1,7 +1,7 @@
/* /*
* jversion.h * jversion.h
* *
* Copyright (C) 1991-2016, Thomas G. Lane, Guido Vollbeding. * Copyright (C) 1991-2018, 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 @@
*/ */
#define JVERSION "9b 17-Jan-2016" #define JVERSION "9c 14-Jan-2018"
#define JCOPYRIGHT "Copyright (C) 2016, Thomas G. Lane, Guido Vollbeding" #define JCOPYRIGHT "Copyright (C) 2018, Thomas G. Lane, Guido Vollbeding"

View file

@ -2,13 +2,13 @@
* rdbmp.c * rdbmp.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2009-2010 by Guido Vollbeding. * Modified 2009-2017 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.
* *
* This file contains routines to read input images in Microsoft "BMP" * This file contains routines to read input images in Microsoft "BMP"
* format (MS Windows 3.x, OS/2 1.x, and OS/2 2.x flavors). * format (MS Windows 3.x, OS/2 1.x, and OS/2 2.x flavors).
* Currently, only 8-bit and 24-bit images are supported, not 1-bit or * Currently, only 8-, 24-, and 32-bit images are supported, not 1-bit or
* 4-bit (feeding such low-depth images into JPEG would be silly anyway). * 4-bit (feeding such low-depth images into JPEG would be silly anyway).
* Also, we don't support RLE-compressed files. * Also, we don't support RLE-compressed files.
* *
@ -61,7 +61,8 @@ typedef struct _bmp_source_struct {
JDIMENSION source_row; /* Current source row number */ JDIMENSION source_row; /* Current source row number */
JDIMENSION row_width; /* Physical width of scanlines in file */ JDIMENSION row_width; /* Physical width of scanlines in file */
int bits_per_pixel; /* remembers 8- or 24-bit format */ int bits_per_pixel; /* remembers 8-, 24-, or 32-bit format */
int cmap_length; /* colormap length */
} bmp_source_struct; } bmp_source_struct;
@ -121,11 +122,12 @@ get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* This version is for reading 8-bit colormap indexes */ /* This version is for reading 8-bit colormap indexes */
{ {
bmp_source_ptr source = (bmp_source_ptr) sinfo; bmp_source_ptr source = (bmp_source_ptr) sinfo;
register JSAMPARRAY colormap = source->colormap;
JSAMPARRAY image_ptr; JSAMPARRAY image_ptr;
register int t;
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
register JSAMPARRAY colormap;
register JDIMENSION col; register JDIMENSION col;
register int t;
int cmaplen;
/* Fetch next row from virtual array */ /* Fetch next row from virtual array */
source->source_row--; source->source_row--;
@ -136,8 +138,12 @@ get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* Expand the colormap indexes to real data */ /* Expand the colormap indexes to real data */
inptr = image_ptr[0]; inptr = image_ptr[0];
outptr = source->pub.buffer[0]; outptr = source->pub.buffer[0];
colormap = source->colormap;
cmaplen = source->cmap_length;
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
t = GETJSAMPLE(*inptr++); t = GETJSAMPLE(*inptr++);
if (t >= cmaplen)
ERREXIT(cinfo, JERR_BMP_OUTOFRANGE);
*outptr++ = colormap[0][t]; /* can omit GETJSAMPLE() safely */ *outptr++ = colormap[0][t]; /* can omit GETJSAMPLE() safely */
*outptr++ = colormap[1][t]; *outptr++ = colormap[1][t];
*outptr++ = colormap[2][t]; *outptr++ = colormap[2][t];
@ -192,6 +198,7 @@ get_32bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
image_ptr = (*cinfo->mem->access_virt_sarray) image_ptr = (*cinfo->mem->access_virt_sarray)
((j_common_ptr) cinfo, source->whole_image, ((j_common_ptr) cinfo, source->whole_image,
source->source_row, (JDIMENSION) 1, FALSE); source->source_row, (JDIMENSION) 1, FALSE);
/* Transfer data. Note source values are in BGR order /* Transfer data. Note source values are in BGR order
* (even though Microsoft's own documents say the opposite). * (even though Microsoft's own documents say the opposite).
*/ */
@ -301,7 +308,7 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
ERREXIT(cinfo, JERR_INPUT_EOF); ERREXIT(cinfo, JERR_INPUT_EOF);
if (GET_2B(bmpfileheader,0) != 0x4D42) /* 'BM' */ if (GET_2B(bmpfileheader,0) != 0x4D42) /* 'BM' */
ERREXIT(cinfo, JERR_BMP_NOT); ERREXIT(cinfo, JERR_BMP_NOT);
bfOffBits = (INT32) GET_4B(bmpfileheader,10); bfOffBits = GET_4B(bmpfileheader,10);
/* We ignore the remaining fileheader fields */ /* We ignore the remaining fileheader fields */
/* The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows), /* The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows),
@ -309,7 +316,7 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
*/ */
if (! ReadOK(source->pub.input_file, bmpinfoheader, 4)) if (! ReadOK(source->pub.input_file, bmpinfoheader, 4))
ERREXIT(cinfo, JERR_INPUT_EOF); ERREXIT(cinfo, JERR_INPUT_EOF);
headerSize = (INT32) GET_4B(bmpinfoheader,0); headerSize = GET_4B(bmpinfoheader,0);
if (headerSize < 12 || headerSize > 64) if (headerSize < 12 || headerSize > 64)
ERREXIT(cinfo, JERR_BMP_BADHEADER); ERREXIT(cinfo, JERR_BMP_BADHEADER);
if (! ReadOK(source->pub.input_file, bmpinfoheader+4, headerSize-4)) if (! ReadOK(source->pub.input_file, bmpinfoheader+4, headerSize-4))
@ -329,7 +336,9 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, (int) biWidth, (int) biHeight); TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, (int) biWidth, (int) biHeight);
break; break;
case 24: /* RGB image */ case 24: /* RGB image */
TRACEMS2(cinfo, 1, JTRC_BMP_OS2, (int) biWidth, (int) biHeight); case 32: /* RGB image + Alpha channel */
TRACEMS3(cinfo, 1, JTRC_BMP_OS2, (int) biWidth, (int) biHeight,
source->bits_per_pixel);
break; break;
default: default:
ERREXIT(cinfo, JERR_BMP_BADDEPTH); ERREXIT(cinfo, JERR_BMP_BADDEPTH);
@ -356,10 +365,9 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, (int) biWidth, (int) biHeight); TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, (int) biWidth, (int) biHeight);
break; break;
case 24: /* RGB image */ case 24: /* RGB image */
TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight);
break;
case 32: /* RGB image + Alpha channel */ case 32: /* RGB image + Alpha channel */
TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight); TRACEMS3(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight,
source->bits_per_pixel);
break; break;
default: default:
ERREXIT(cinfo, JERR_BMP_BADDEPTH); ERREXIT(cinfo, JERR_BMP_BADDEPTH);
@ -377,13 +385,14 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
break; break;
default: default:
ERREXIT(cinfo, JERR_BMP_BADHEADER); ERREXIT(cinfo, JERR_BMP_BADHEADER);
return; return; /* avoid compiler warnings for uninitialized variables */
} }
if (biWidth <= 0 || biHeight <= 0)
ERREXIT(cinfo, JERR_BMP_EMPTY);
if (biPlanes != 1) if (biPlanes != 1)
ERREXIT(cinfo, JERR_BMP_BADPLANES); ERREXIT(cinfo, JERR_BMP_BADPLANES);
/* Sanity check for buffer allocation below */
if (biWidth <= 0 || biHeight <= 0 || (biWidth >> 24) || (biHeight >> 24))
ERREXIT(cinfo, JERR_BMP_OUTOFRANGE);
/* Compute distance to bitmap data --- will adjust for colormap below */ /* Compute distance to bitmap data --- will adjust for colormap below */
bPad = bfOffBits - (headerSize + 14); bPad = bfOffBits - (headerSize + 14);
@ -398,6 +407,7 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
source->colormap = (*cinfo->mem->alloc_sarray) source->colormap = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE,
(JDIMENSION) biClrUsed, (JDIMENSION) 3); (JDIMENSION) biClrUsed, (JDIMENSION) 3);
source->cmap_length = (int) biClrUsed;
/* and read it from the file */ /* and read it from the file */
read_colormap(source, (int) biClrUsed, mapentrysize); read_colormap(source, (int) biClrUsed, mapentrysize);
/* account for size of colormap */ /* account for size of colormap */
@ -474,7 +484,7 @@ jinit_read_bmp (j_compress_ptr cinfo)
source->pub.start_input = start_input_bmp; source->pub.start_input = start_input_bmp;
source->pub.finish_input = finish_input_bmp; source->pub.finish_input = finish_input_bmp;
return (cjpeg_source_ptr) source; return &source->pub;
} }
#endif /* BMP_SUPPORTED */ #endif /* BMP_SUPPORTED */

View file

@ -2,7 +2,7 @@
* rdppm.c * rdppm.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2009 by Bill Allombert, Guido Vollbeding. * Modified 2009-2017 by Bill Allombert, 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.
* *
@ -76,6 +76,7 @@ typedef struct {
JSAMPROW pixrow; /* FAR pointer to same */ JSAMPROW pixrow; /* FAR pointer to same */
size_t buffer_width; /* width of I/O buffer */ size_t buffer_width; /* width of I/O buffer */
JSAMPLE *rescale; /* => maxval-remapping array, or NULL */ JSAMPLE *rescale; /* => maxval-remapping array, or NULL */
unsigned int maxval;
} ppm_source_struct; } ppm_source_struct;
typedef ppm_source_struct * ppm_source_ptr; typedef ppm_source_struct * ppm_source_ptr;
@ -146,11 +147,16 @@ get_text_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
FILE * infile = source->pub.input_file; FILE * infile = source->pub.input_file;
register JSAMPROW ptr; register JSAMPROW ptr;
register JSAMPLE *rescale = source->rescale; register JSAMPLE *rescale = source->rescale;
unsigned int maxval = source->maxval;
JDIMENSION col; JDIMENSION col;
ptr = source->pub.buffer[0]; ptr = source->pub.buffer[0];
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
*ptr++ = rescale[read_pbm_integer(cinfo, infile)]; register unsigned int temp;
temp = read_pbm_integer(cinfo, infile);
if (temp > maxval)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
*ptr++ = rescale[temp];
} }
return 1; return 1;
} }
@ -164,13 +170,24 @@ get_text_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
FILE * infile = source->pub.input_file; FILE * infile = source->pub.input_file;
register JSAMPROW ptr; register JSAMPROW ptr;
register JSAMPLE *rescale = source->rescale; register JSAMPLE *rescale = source->rescale;
unsigned int maxval = source->maxval;
JDIMENSION col; JDIMENSION col;
ptr = source->pub.buffer[0]; ptr = source->pub.buffer[0];
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
*ptr++ = rescale[read_pbm_integer(cinfo, infile)]; register unsigned int temp;
*ptr++ = rescale[read_pbm_integer(cinfo, infile)]; temp = read_pbm_integer(cinfo, infile);
*ptr++ = rescale[read_pbm_integer(cinfo, infile)]; if (temp > maxval)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
*ptr++ = rescale[temp];
temp = read_pbm_integer(cinfo, infile);
if (temp > maxval)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
*ptr++ = rescale[temp];
temp = read_pbm_integer(cinfo, infile);
if (temp > maxval)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
*ptr++ = rescale[temp];
} }
return 1; return 1;
} }
@ -184,6 +201,7 @@ get_scaled_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
register JSAMPROW ptr; register JSAMPROW ptr;
register U_CHAR * bufferptr; register U_CHAR * bufferptr;
register JSAMPLE *rescale = source->rescale; register JSAMPLE *rescale = source->rescale;
unsigned int maxval = source->maxval;
JDIMENSION col; JDIMENSION col;
if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
@ -191,7 +209,11 @@ get_scaled_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
ptr = source->pub.buffer[0]; ptr = source->pub.buffer[0];
bufferptr = source->iobuffer; bufferptr = source->iobuffer;
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
*ptr++ = rescale[UCH(*bufferptr++)]; register unsigned int temp;
temp = (unsigned int) UCH(*bufferptr++);
if (temp > maxval)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
*ptr++ = rescale[temp];
} }
return 1; return 1;
} }
@ -205,6 +227,7 @@ get_scaled_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
register JSAMPROW ptr; register JSAMPROW ptr;
register U_CHAR * bufferptr; register U_CHAR * bufferptr;
register JSAMPLE *rescale = source->rescale; register JSAMPLE *rescale = source->rescale;
unsigned int maxval = source->maxval;
JDIMENSION col; JDIMENSION col;
if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
@ -212,9 +235,19 @@ get_scaled_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
ptr = source->pub.buffer[0]; ptr = source->pub.buffer[0];
bufferptr = source->iobuffer; bufferptr = source->iobuffer;
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
*ptr++ = rescale[UCH(*bufferptr++)]; register unsigned int temp;
*ptr++ = rescale[UCH(*bufferptr++)]; temp = (unsigned int) UCH(*bufferptr++);
*ptr++ = rescale[UCH(*bufferptr++)]; if (temp > maxval)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
*ptr++ = rescale[temp];
temp = (unsigned int) UCH(*bufferptr++);
if (temp > maxval)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
*ptr++ = rescale[temp];
temp = (unsigned int) UCH(*bufferptr++);
if (temp > maxval)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
*ptr++ = rescale[temp];
} }
return 1; return 1;
} }
@ -243,6 +276,7 @@ get_word_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
register JSAMPROW ptr; register JSAMPROW ptr;
register U_CHAR * bufferptr; register U_CHAR * bufferptr;
register JSAMPLE *rescale = source->rescale; register JSAMPLE *rescale = source->rescale;
unsigned int maxval = source->maxval;
JDIMENSION col; JDIMENSION col;
if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
@ -250,9 +284,11 @@ get_word_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
ptr = source->pub.buffer[0]; ptr = source->pub.buffer[0];
bufferptr = source->iobuffer; bufferptr = source->iobuffer;
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
register int temp; register unsigned int temp;
temp = UCH(*bufferptr++) << 8; temp = ((unsigned int) UCH(*bufferptr++)) << 8;
temp |= UCH(*bufferptr++); temp |= (unsigned int) UCH(*bufferptr++);
if (temp > maxval)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
*ptr++ = rescale[temp]; *ptr++ = rescale[temp];
} }
return 1; return 1;
@ -267,6 +303,7 @@ get_word_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
register JSAMPROW ptr; register JSAMPROW ptr;
register U_CHAR * bufferptr; register U_CHAR * bufferptr;
register JSAMPLE *rescale = source->rescale; register JSAMPLE *rescale = source->rescale;
unsigned int maxval = source->maxval;
JDIMENSION col; JDIMENSION col;
if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
@ -274,15 +311,21 @@ get_word_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
ptr = source->pub.buffer[0]; ptr = source->pub.buffer[0];
bufferptr = source->iobuffer; bufferptr = source->iobuffer;
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
register int temp; register unsigned int temp;
temp = UCH(*bufferptr++) << 8; temp = ((unsigned int) UCH(*bufferptr++)) << 8;
temp |= UCH(*bufferptr++); temp |= (unsigned int) UCH(*bufferptr++);
if (temp > maxval)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
*ptr++ = rescale[temp]; *ptr++ = rescale[temp];
temp = UCH(*bufferptr++) << 8; temp = ((unsigned int) UCH(*bufferptr++)) << 8;
temp |= UCH(*bufferptr++); temp |= (unsigned int) UCH(*bufferptr++);
if (temp > maxval)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
*ptr++ = rescale[temp]; *ptr++ = rescale[temp];
temp = UCH(*bufferptr++) << 8; temp = ((unsigned int) UCH(*bufferptr++)) << 8;
temp |= UCH(*bufferptr++); temp |= (unsigned int) UCH(*bufferptr++);
if (temp > maxval)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
*ptr++ = rescale[temp]; *ptr++ = rescale[temp];
} }
return 1; return 1;
@ -326,9 +369,14 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
ERREXIT(cinfo, JERR_PPM_NOT); ERREXIT(cinfo, JERR_PPM_NOT);
if (((long) w >> 24) || /* sanity check for buffer allocation below */
((long) maxval >> 16)) /* support max 16-bit (2-byte) sample values */
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */ cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */
cinfo->image_width = (JDIMENSION) w; cinfo->image_width = (JDIMENSION) w;
cinfo->image_height = (JDIMENSION) h; cinfo->image_height = (JDIMENSION) h;
source->maxval = maxval;
/* initialize flags to most common settings */ /* initialize flags to most common settings */
need_iobuffer = TRUE; /* do we need an I/O buffer? */ need_iobuffer = TRUE; /* do we need an I/O buffer? */
@ -387,9 +435,8 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
if (need_iobuffer) { if (need_iobuffer) {
source->buffer_width = (size_t) w * cinfo->input_components * source->buffer_width = (size_t) w * cinfo->input_components *
((maxval <= 255) ? SIZEOF(U_CHAR) : (2 * SIZEOF(U_CHAR))); ((maxval <= 255) ? SIZEOF(U_CHAR) : (2 * SIZEOF(U_CHAR)));
source->iobuffer = (U_CHAR *) source->iobuffer = (U_CHAR *) (*cinfo->mem->alloc_small)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE, source->buffer_width);
source->buffer_width);
} }
/* Create compressor input buffer. */ /* Create compressor input buffer. */
@ -413,9 +460,8 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
INT32 val, half_maxval; INT32 val, half_maxval;
/* On 16-bit-int machines we have to be careful of maxval = 65535 */ /* On 16-bit-int machines we have to be careful of maxval = 65535 */
source->rescale = (JSAMPLE *) source->rescale = (JSAMPLE *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, JPOOL_IMAGE, (size_t) (((long) maxval + 1L) * SIZEOF(JSAMPLE)));
(size_t) (((long) maxval + 1L) * SIZEOF(JSAMPLE)));
half_maxval = maxval / 2; half_maxval = maxval / 2;
for (val = 0; val <= (INT32) maxval; val++) { for (val = 0; val <= (INT32) maxval; val++) {
/* The multiplication here must be done in 32 bits to avoid overflow */ /* The multiplication here must be done in 32 bits to avoid overflow */
@ -453,7 +499,7 @@ jinit_read_ppm (j_compress_ptr cinfo)
source->pub.start_input = start_input_ppm; source->pub.start_input = start_input_ppm;
source->pub.finish_input = finish_input_ppm; source->pub.finish_input = finish_input_ppm;
return (cjpeg_source_ptr) source; return &source->pub;
} }
#endif /* PPM_SUPPORTED */ #endif /* PPM_SUPPORTED */

View file

@ -2,6 +2,7 @@
* rdtarga.c * rdtarga.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2017 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,6 +63,7 @@ typedef struct _tga_source_struct {
U_CHAR tga_pixel[4]; U_CHAR tga_pixel[4];
int pixel_size; /* Bytes per Targa pixel (1 to 4) */ int pixel_size; /* Bytes per Targa pixel (1 to 4) */
int cmap_length; /* colormap length */
/* State info for reading RLE-coded pixels; both counts must be init to 0 */ /* State info for reading RLE-coded pixels; both counts must be init to 0 */
int block_count; /* # of pixels remaining in RLE block */ int block_count; /* # of pixels remaining in RLE block */
@ -191,15 +193,20 @@ get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* This version is for reading 8-bit colormap indexes */ /* This version is for reading 8-bit colormap indexes */
{ {
tga_source_ptr source = (tga_source_ptr) sinfo; tga_source_ptr source = (tga_source_ptr) sinfo;
register int t;
register JSAMPROW ptr; register JSAMPROW ptr;
register JSAMPARRAY colormap;
register JDIMENSION col; register JDIMENSION col;
register JSAMPARRAY colormap = source->colormap; register int t;
int cmaplen;
ptr = source->pub.buffer[0]; ptr = source->pub.buffer[0];
colormap = source->colormap;
cmaplen = source->cmap_length;
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
(*source->read_pixel) (source); /* Load next pixel into tga_pixel */ (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
t = UCH(source->tga_pixel[0]); t = UCH(source->tga_pixel[0]);
if (t >= cmaplen)
ERREXIT(cinfo, JERR_TGA_BADPARMS);
*ptr++ = colormap[0][t]; *ptr++ = colormap[0][t];
*ptr++ = colormap[1][t]; *ptr++ = colormap[1][t];
*ptr++ = colormap[2][t]; *ptr++ = colormap[2][t];
@ -361,6 +368,7 @@ start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
interlace_type = flags >> 6; /* bits 6/7 are interlace code */ interlace_type = flags >> 6; /* bits 6/7 are interlace code */
if (cmaptype > 1 || /* cmaptype must be 0 or 1 */ if (cmaptype > 1 || /* cmaptype must be 0 or 1 */
width <= 0 || height <= 0 ||
source->pixel_size < 1 || source->pixel_size > 4 || source->pixel_size < 1 || source->pixel_size > 4 ||
(UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */ (UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */
interlace_type != 0) /* currently don't allow interlaced image */ interlace_type != 0) /* currently don't allow interlaced image */
@ -450,12 +458,14 @@ start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* Allocate space to store the colormap */ /* Allocate space to store the colormap */
source->colormap = (*cinfo->mem->alloc_sarray) source->colormap = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, (JDIMENSION) maplen, (JDIMENSION) 3); ((j_common_ptr) cinfo, JPOOL_IMAGE, (JDIMENSION) maplen, (JDIMENSION) 3);
source->cmap_length = (int) maplen;
/* and read it from the file */ /* and read it from the file */
read_colormap(source, (int) maplen, UCH(targaheader[7])); read_colormap(source, (int) maplen, UCH(targaheader[7]));
} else { } else {
if (cmaptype) /* but you promised a cmap! */ if (cmaptype) /* but you promised a cmap! */
ERREXIT(cinfo, JERR_TGA_BADPARMS); ERREXIT(cinfo, JERR_TGA_BADPARMS);
source->colormap = NULL; source->colormap = NULL;
source->cmap_length = 0;
} }
cinfo->input_components = components; cinfo->input_components = components;
@ -494,7 +504,7 @@ jinit_read_targa (j_compress_ptr cinfo)
source->pub.start_input = start_input_tga; source->pub.start_input = start_input_tga;
source->pub.finish_input = finish_input_tga; source->pub.finish_input = finish_input_tga;
return (cjpeg_source_ptr) source; return &source->pub;
} }
#endif /* TARGA_SUPPORTED */ #endif /* TARGA_SUPPORTED */

View file

@ -1,7 +1,7 @@
/* /*
* transupp.c * transupp.c
* *
* Copyright (C) 1997-2013, Thomas G. Lane, Guido Vollbeding. * Copyright (C) 1997-2017, 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.
* *
@ -198,25 +198,76 @@ do_wipe (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
JDIMENSION drop_width, JDIMENSION drop_height) JDIMENSION drop_width, JDIMENSION drop_height)
/* Wipe - drop content of specified area, fill with zero (neutral gray) */ /* Wipe - drop content of specified area, fill with zero (neutral gray) */
{ {
JDIMENSION comp_width, comp_height; JDIMENSION x_wipe_blocks, wipe_width;
JDIMENSION blk_y, x_wipe_blocks, y_wipe_blocks; JDIMENSION y_wipe_blocks, wipe_bottom;
int ci, offset_y; int ci, offset_y;
JBLOCKARRAY buffer; JBLOCKARRAY buffer;
jpeg_component_info *compptr; jpeg_component_info *compptr;
for (ci = 0; ci < dstinfo->num_components; ci++) { for (ci = 0; ci < dstinfo->num_components; ci++) {
compptr = dstinfo->comp_info + ci; compptr = dstinfo->comp_info + ci;
comp_width = drop_width * compptr->h_samp_factor;
comp_height = drop_height * compptr->v_samp_factor;
x_wipe_blocks = x_crop_offset * compptr->h_samp_factor; x_wipe_blocks = x_crop_offset * compptr->h_samp_factor;
wipe_width = drop_width * compptr->h_samp_factor;
y_wipe_blocks = y_crop_offset * compptr->v_samp_factor; y_wipe_blocks = y_crop_offset * compptr->v_samp_factor;
for (blk_y = 0; blk_y < comp_height; blk_y += compptr->v_samp_factor) { wipe_bottom = drop_height * compptr->v_samp_factor + y_wipe_blocks;
for (; y_wipe_blocks < wipe_bottom;
y_wipe_blocks += compptr->v_samp_factor) {
buffer = (*srcinfo->mem->access_virt_barray) buffer = (*srcinfo->mem->access_virt_barray)
((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y + y_wipe_blocks, ((j_common_ptr) srcinfo, src_coef_arrays[ci], y_wipe_blocks,
(JDIMENSION) compptr->v_samp_factor, TRUE); (JDIMENSION) compptr->v_samp_factor, TRUE);
for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
FMEMZERO(buffer[offset_y] + x_wipe_blocks, FMEMZERO(buffer[offset_y] + x_wipe_blocks,
comp_width * SIZEOF(JBLOCK)); wipe_width * SIZEOF(JBLOCK));
}
}
}
}
LOCAL(void)
do_flatten (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
jvirt_barray_ptr *src_coef_arrays,
JDIMENSION drop_width, JDIMENSION drop_height)
/* Flatten - drop content of specified area, similar to wipe,
* but fill with average of adjacent blocks, instead of zero.
*/
{
JDIMENSION x_wipe_blocks, wipe_width, wipe_right;
JDIMENSION y_wipe_blocks, wipe_bottom, blk_x;
int ci, offset_y, dc_left_value, dc_right_value, average;
JBLOCKARRAY buffer;
jpeg_component_info *compptr;
for (ci = 0; ci < dstinfo->num_components; ci++) {
compptr = dstinfo->comp_info + ci;
x_wipe_blocks = x_crop_offset * compptr->h_samp_factor;
wipe_width = drop_width * compptr->h_samp_factor;
wipe_right = wipe_width + x_wipe_blocks;
y_wipe_blocks = y_crop_offset * compptr->v_samp_factor;
wipe_bottom = drop_height * compptr->v_samp_factor + y_wipe_blocks;
for (; y_wipe_blocks < wipe_bottom;
y_wipe_blocks += compptr->v_samp_factor) {
buffer = (*srcinfo->mem->access_virt_barray)
((j_common_ptr) srcinfo, src_coef_arrays[ci], y_wipe_blocks,
(JDIMENSION) compptr->v_samp_factor, TRUE);
for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
FMEMZERO(buffer[offset_y] + x_wipe_blocks,
wipe_width * SIZEOF(JBLOCK));
if (x_wipe_blocks > 0) {
dc_left_value = buffer[offset_y][x_wipe_blocks - 1][0];
if (wipe_right < compptr->width_in_blocks) {
dc_right_value = buffer[offset_y][wipe_right][0];
average = (dc_left_value + dc_right_value) >> 1;
} else {
average = dc_left_value;
}
} else if (wipe_right < compptr->width_in_blocks) {
average = buffer[offset_y][wipe_right][0];
} else continue;
for (blk_x = x_wipe_blocks; blk_x < wipe_right; blk_x++) {
buffer[offset_y][blk_x][0] = (JCOEF) average;
}
} }
} }
} }
@ -1626,8 +1677,12 @@ jtransform_execute_transform (j_decompress_ptr srcinfo,
src_coef_arrays, dst_coef_arrays); src_coef_arrays, dst_coef_arrays);
break; break;
case JXFORM_WIPE: case JXFORM_WIPE:
if (info->crop_width_set != JCROP_FORCE)
do_wipe(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, do_wipe(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
src_coef_arrays, info->drop_width, info->drop_height); src_coef_arrays, info->drop_width, info->drop_height);
else
do_flatten(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
src_coef_arrays, info->drop_width, info->drop_height);
break; break;
} }
} }

View file

@ -2,6 +2,7 @@
* wrbmp.c * wrbmp.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2017 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.
* *
@ -376,8 +377,8 @@ finish_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
progress->completed_extra_passes++; progress->completed_extra_passes++;
/* Make sure we wrote the output file OK */ /* Make sure we wrote the output file OK */
fflush(outfile); JFFLUSH(outfile);
if (ferror(outfile)) if (JFERROR(outfile))
ERREXIT(cinfo, JERR_FILE_WRITE); ERREXIT(cinfo, JERR_FILE_WRITE);
} }
@ -436,7 +437,7 @@ jinit_write_bmp (j_decompress_ptr cinfo, boolean is_os2)
((j_common_ptr) cinfo, JPOOL_IMAGE, row_width, (JDIMENSION) 1); ((j_common_ptr) cinfo, JPOOL_IMAGE, row_width, (JDIMENSION) 1);
dest->pub.buffer_height = 1; dest->pub.buffer_height = 1;
return (djpeg_dest_ptr) dest; return &dest->pub;
} }
#endif /* BMP_SUPPORTED */ #endif /* BMP_SUPPORTED */

View file

@ -2,7 +2,7 @@
* wrgif.c * wrgif.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2015 by Guido Vollbeding. * Modified 2015-2017 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.
* *
@ -347,8 +347,8 @@ finish_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
/* Write the GIF terminator mark */ /* Write the GIF terminator mark */
putc(';', dest->pub.output_file); putc(';', dest->pub.output_file);
/* Make sure we wrote the output file OK */ /* Make sure we wrote the output file OK */
fflush(dest->pub.output_file); JFFLUSH(dest->pub.output_file);
if (ferror(dest->pub.output_file)) if (JFERROR(dest->pub.output_file))
ERREXIT(cinfo, JERR_FILE_WRITE); ERREXIT(cinfo, JERR_FILE_WRITE);
} }

View file

@ -2,7 +2,7 @@
* wrppm.c * wrppm.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2009 by Guido Vollbeding. * Modified 2009-2017 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.
* *
@ -206,8 +206,8 @@ METHODDEF(void)
finish_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) finish_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
{ {
/* Make sure we wrote the output file OK */ /* Make sure we wrote the output file OK */
fflush(dinfo->output_file); JFFLUSH(dinfo->output_file);
if (ferror(dinfo->output_file)) if (JFERROR(dinfo->output_file))
ERREXIT(cinfo, JERR_FILE_WRITE); ERREXIT(cinfo, JERR_FILE_WRITE);
} }
@ -263,7 +263,7 @@ jinit_write_ppm (j_decompress_ptr cinfo)
dest->pub.put_pixel_rows = put_pixel_rows; dest->pub.put_pixel_rows = put_pixel_rows;
} }
return (djpeg_dest_ptr) dest; return &dest->pub;
} }
#endif /* PPM_SUPPORTED */ #endif /* PPM_SUPPORTED */

View file

@ -2,6 +2,7 @@
* wrrle.c * wrrle.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2017 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.
* *
@ -263,8 +264,8 @@ finish_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
/* Emit file trailer */ /* Emit file trailer */
rle_puteof(&header); rle_puteof(&header);
fflush(dest->pub.output_file); JFFLUSH(dest->pub.output_file);
if (ferror(dest->pub.output_file)) if (JFERROR(dest->pub.output_file))
ERREXIT(cinfo, JERR_FILE_WRITE); ERREXIT(cinfo, JERR_FILE_WRITE);
} }
@ -299,7 +300,7 @@ jinit_write_rle (j_decompress_ptr cinfo)
(JDIMENSION) (cinfo->output_width * cinfo->output_components), (JDIMENSION) (cinfo->output_width * cinfo->output_components),
cinfo->output_height, (JDIMENSION) 1); cinfo->output_height, (JDIMENSION) 1);
return (djpeg_dest_ptr) dest; return &dest->pub;
} }
#endif /* RLE_SUPPORTED */ #endif /* RLE_SUPPORTED */

View file

@ -2,7 +2,7 @@
* wrtarga.c * wrtarga.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2015 by Guido Vollbeding. * Modified 2015-2017 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.
* *
@ -212,8 +212,8 @@ METHODDEF(void)
finish_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) finish_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
{ {
/* Make sure we wrote the output file OK */ /* Make sure we wrote the output file OK */
fflush(dinfo->output_file); JFFLUSH(dinfo->output_file);
if (ferror(dinfo->output_file)) if (JFERROR(dinfo->output_file))
ERREXIT(cinfo, JERR_FILE_WRITE); ERREXIT(cinfo, JERR_FILE_WRITE);
} }