* commit 'b8d044a666056d4d8d28d7a5d0805ac32b619b36': (58 commits) Big oops. wrjpgcom on Windows was being built using the rdjpgcom source. Prevent a buffer overrun if the comment begins with a literal quote character and the string exceeds 65k characters. Also prevent comments longer than 65k characters from being written, since this will produce an incorrect JPEG file. Remove VMS-specific code Our copyright string is longer than JMSG_LENGTH_MAX, and this was causing a buffer overrun if output_message() was called with msg_code set to JMSG_COPYRIGHT, or if format_message() was called with msg_code set to JMSG_COPYRIGHT and with a buffer of length JMSG_LENGTH_MAX. We don't support non-ANSI C compilers Allow for building the MIPS DSPr2 extensions if the host is mips-* as well as mipsel-*. The DSPr2 extensions are little endian, so we still have to check that the compiler defines __MIPSEL__ before enabling them. This paves the way for supporting big-endian MIPS, and in the near term, it allows the SIMD extensions to be built with Sourcery CodeBench. SIMD-accelerated int upsample routine for MIPS DSPr2 Fix MIPS build libjpeg-turbo has never supported non-ANSI compilers, so get rid of the crufty SIZEOF() macro. It was not being used consistently anyhow, so it would not have been possible to build prior releases of libjpeg-turbo using the broken compilers for which that macro was designed. Remove MS-DOS code and information, and adjust copyright headers to reflect the removal of features in r1307 and r1308. libjpeg-turbo has never supported MS-DOS, nor is it even possible for us to do so. Further copyright header cleanup Further copyright header cleanup Get rid of the HAVE_PROTOTYPES configuration option, as well as the related JMETHOD and JPP macros. libjpeg-turbo has never supported compilers that don't handle prototypes. Doing so requires ansi2knr, which isn't even supported in the IJG code anymore. Remove all of the NEED_SHORT_EXTERNAL_NAMES stuff. There is scant information available as to which linkers ever had a 15-character global symbol name limit. AFAICT, it might have been a VMS and/or a.out BSD thing, but none of those platforms have ever been supported by libjpeg-turbo (nor are such systems supported by other open source libraries of this nature.) Clean up code formatting in the SIMD interface functions SIMD-accelerated NULL convert routine for MIPS DSPr2 Fix build, which was broken by the checkin of the MIPS DSPr2 accelerated smooth downsampling routine. Until/unless other platforms include SIMD support for that function, it's just easier to #ifdef around it rather than adding stubs for the other platforms. Fix error in MIPS DSPr2 accelerated smooth downsample routine SIMD-accelerated h2v2 smooth downsampling routine for MIPS DSPr2 Minor tweak to improve code readability ... Conflicts: BUILDING.txt CMakeLists.txt Makefile.am cdjpeg.h cjpeg.1 cjpeg.c configure.ac djpeg.1 example.c jccoefct.c jcdctmgr.c jchuff.c jchuff.h jcinit.c jcmaster.c jcparam.c jcphuff.c jidctflt.c jpegint.h jpeglib.h jversion.h libjpeg.txt rdswitch.c simd/CMakeLists.txt tjbench.c turbojpeg.c usage.txt wrjpgcom.c
168 lines
6.0 KiB
C
168 lines
6.0 KiB
C
/*
|
|
* jcapistd.c
|
|
*
|
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
|
* This file is part of the Independent JPEG Group's software.
|
|
* mozjpeg Modifications:
|
|
* Copyright (C) 2014, Mozilla Corporation.
|
|
* For conditions of distribution and use, see the accompanying README file.
|
|
*
|
|
* This file contains application interface code for the compression half
|
|
* of the JPEG library. These are the "standard" API routines that are
|
|
* used in the normal full-compression case. They are not used by a
|
|
* transcoding-only application. Note that if an application links in
|
|
* jpeg_start_compress, it will end up linking in the entire compressor.
|
|
* We thus must separate this file from jcapimin.c to avoid linking the
|
|
* whole compression library into a transcoder.
|
|
*/
|
|
|
|
#define JPEG_INTERNALS
|
|
#include "jinclude.h"
|
|
#include "jpeglib.h"
|
|
|
|
|
|
/*
|
|
* Compression initialization.
|
|
* Before calling this, all parameters and a data destination must be set up.
|
|
*
|
|
* We require a write_all_tables parameter as a failsafe check when writing
|
|
* multiple datastreams from the same compression object. Since prior runs
|
|
* will have left all the tables marked sent_table=TRUE, a subsequent run
|
|
* would emit an abbreviated stream (no tables) by default. This may be what
|
|
* is wanted, but for safety's sake it should not be the default behavior:
|
|
* programmers should have to make a deliberate choice to emit abbreviated
|
|
* images. Therefore the documentation and examples should encourage people
|
|
* to pass write_all_tables=TRUE; then it will take active thought to do the
|
|
* wrong thing.
|
|
*/
|
|
|
|
GLOBAL(void)
|
|
jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
|
|
{
|
|
if (cinfo->global_state != CSTATE_START)
|
|
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
|
|
|
if (write_all_tables)
|
|
jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
|
|
|
|
/* setting up scan optimisation pattern failed, disable scan optimisation */
|
|
if (cinfo->num_scans_luma == 0 || cinfo->scan_info == NULL || cinfo->num_scans == 0)
|
|
cinfo->optimize_scans = FALSE;
|
|
|
|
/* (Re)initialize error mgr and destination modules */
|
|
(*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
|
|
(*cinfo->dest->init_destination) (cinfo);
|
|
/* Perform master selection of active modules */
|
|
jinit_compress_master(cinfo);
|
|
/* Set up for the first pass */
|
|
(*cinfo->master->prepare_for_pass) (cinfo);
|
|
/* Ready for application to drive first pass through jpeg_write_scanlines
|
|
* or jpeg_write_raw_data.
|
|
*/
|
|
cinfo->next_scanline = 0;
|
|
cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
|
|
}
|
|
|
|
|
|
/*
|
|
* Write some scanlines of data to the JPEG compressor.
|
|
*
|
|
* The return value will be the number of lines actually written.
|
|
* This should be less than the supplied num_lines only in case that
|
|
* the data destination module has requested suspension of the compressor,
|
|
* or if more than image_height scanlines are passed in.
|
|
*
|
|
* Note: we warn about excess calls to jpeg_write_scanlines() since
|
|
* this likely signals an application programmer error. However,
|
|
* excess scanlines passed in the last valid call are *silently* ignored,
|
|
* so that the application need not adjust num_lines for end-of-image
|
|
* when using a multiple-scanline buffer.
|
|
*/
|
|
|
|
GLOBAL(JDIMENSION)
|
|
jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
|
|
JDIMENSION num_lines)
|
|
{
|
|
JDIMENSION row_ctr, rows_left;
|
|
|
|
if (cinfo->global_state != CSTATE_SCANNING)
|
|
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
|
if (cinfo->next_scanline >= cinfo->image_height)
|
|
WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
|
|
|
|
/* Call progress monitor hook if present */
|
|
if (cinfo->progress != NULL) {
|
|
cinfo->progress->pass_counter = (long) cinfo->next_scanline;
|
|
cinfo->progress->pass_limit = (long) cinfo->image_height;
|
|
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
|
|
}
|
|
|
|
/* Give master control module another chance if this is first call to
|
|
* jpeg_write_scanlines. This lets output of the frame/scan headers be
|
|
* delayed so that application can write COM, etc, markers between
|
|
* jpeg_start_compress and jpeg_write_scanlines.
|
|
*/
|
|
if (cinfo->master->call_pass_startup)
|
|
(*cinfo->master->pass_startup) (cinfo);
|
|
|
|
/* Ignore any extra scanlines at bottom of image. */
|
|
rows_left = cinfo->image_height - cinfo->next_scanline;
|
|
if (num_lines > rows_left)
|
|
num_lines = rows_left;
|
|
|
|
row_ctr = 0;
|
|
(*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
|
|
cinfo->next_scanline += row_ctr;
|
|
return row_ctr;
|
|
}
|
|
|
|
|
|
/*
|
|
* Alternate entry point to write raw data.
|
|
* Processes exactly one iMCU row per call, unless suspended.
|
|
*/
|
|
|
|
GLOBAL(JDIMENSION)
|
|
jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
|
|
JDIMENSION num_lines)
|
|
{
|
|
JDIMENSION lines_per_iMCU_row;
|
|
|
|
if (cinfo->global_state != CSTATE_RAW_OK)
|
|
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
|
if (cinfo->next_scanline >= cinfo->image_height) {
|
|
WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
|
|
return 0;
|
|
}
|
|
|
|
/* Call progress monitor hook if present */
|
|
if (cinfo->progress != NULL) {
|
|
cinfo->progress->pass_counter = (long) cinfo->next_scanline;
|
|
cinfo->progress->pass_limit = (long) cinfo->image_height;
|
|
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
|
|
}
|
|
|
|
/* Give master control module another chance if this is first call to
|
|
* jpeg_write_raw_data. This lets output of the frame/scan headers be
|
|
* delayed so that application can write COM, etc, markers between
|
|
* jpeg_start_compress and jpeg_write_raw_data.
|
|
*/
|
|
if (cinfo->master->call_pass_startup)
|
|
(*cinfo->master->pass_startup) (cinfo);
|
|
|
|
/* Verify that at least one iMCU row has been passed. */
|
|
lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
|
|
if (num_lines < lines_per_iMCU_row)
|
|
ERREXIT(cinfo, JERR_BUFFER_SIZE);
|
|
|
|
/* Directly compress the row. */
|
|
if (! (*cinfo->coef->compress_data) (cinfo, data)) {
|
|
/* If compressor did not consume the whole row, suspend processing. */
|
|
return 0;
|
|
}
|
|
|
|
/* OK, we processed one iMCU row. */
|
|
cinfo->next_scanline += lines_per_iMCU_row;
|
|
return lines_per_iMCU_row;
|
|
}
|