Update libjpeg-turbo from 1.5.3 to 2.0.2

This commit is contained in:
Juha Reunanen 2019-02-23 18:30:49 +02:00 committed by Alexander Alekhin
parent 5421d0866b
commit 30cf5e0164
78 changed files with 5548 additions and 5149 deletions

View File

@ -2,11 +2,11 @@ project(${JPEG_LIBRARY} C)
ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter -Wsign-compare -Wshorten-64-to-32 -Wimplicit-fallthrough) ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter -Wsign-compare -Wshorten-64-to-32 -Wimplicit-fallthrough)
set(VERSION_MAJOR 1) set(VERSION_MAJOR 2)
set(VERSION_MINOR 5) set(VERSION_MINOR 0)
set(VERSION_REVISION 3) set(VERSION_REVISION 2)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}) set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION})
set(LIBJPEG_TURBO_VERSION_NUMBER 1005003) set(LIBJPEG_TURBO_VERSION_NUMBER 2000002)
string(TIMESTAMP BUILD "opencv-${OPENCV_VERSION}-libjpeg-turbo") string(TIMESTAMP BUILD "opencv-${OPENCV_VERSION}-libjpeg-turbo")
if(CMAKE_BUILD_TYPE STREQUAL "Debug") if(CMAKE_BUILD_TYPE STREQUAL "Debug")

View File

@ -11,9 +11,10 @@ libjpeg-turbo is covered by three compatible BSD-style open source licenses:
- The Modified (3-clause) BSD License, which is listed below - The Modified (3-clause) BSD License, which is listed below
This license covers the TurboJPEG API library and associated programs. This license covers the TurboJPEG API library and associated programs, as
well as the build system.
- The zlib License, which is listed below - The [zlib License](https://opensource.org/licenses/Zlib)
This license is a subset of the other two, and it covers the libjpeg-turbo This license is a subset of the other two, and it covers the libjpeg-turbo
SIMD extensions. SIMD extensions.
@ -65,7 +66,7 @@ best of our understanding.
2. If your binary distribution includes or uses the TurboJPEG API, then 2. If your binary distribution includes or uses the TurboJPEG API, then
your product documentation must include the text of the Modified BSD your product documentation must include the text of the Modified BSD
License. License (see below.)
**Origin** **Origin**
- Clause 2 of the Modified BSD License - Clause 2 of the Modified BSD License
@ -90,7 +91,8 @@ best of our understanding.
The Modified (3-clause) BSD License The Modified (3-clause) BSD License
=================================== ===================================
Copyright (C)\<YEAR\> \<AUTHOR\>. All Rights Reserved. Copyright (C)2009-2019 D. R. Commander. All Rights Reserved.
Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
@ -117,23 +119,14 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
The zlib License Why Three Licenses?
================ ===================
Copyright (C) \<YEAR\>, \<AUTHOR\>. The zlib License could have been used instead of the Modified (3-clause) BSD
License, and since the IJG License effectively subsumes the distribution
This software is provided 'as-is', without any express or implied conditions of the zlib License, this would have effectively placed
warranty. In no event will the authors be held liable for any damages libjpeg-turbo binary distributions under the IJG License. However, the IJG
arising from the use of this software. License specifically refers to the Independent JPEG Group and does not extend
attribution and endorsement protections to other entities. Thus, it was
Permission is granted to anyone to use this software for any purpose, desirable to choose a license that granted us the same protections for new code
including commercial applications, and to alter it and redistribute it that were granted to the IJG for code derived from their software.
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

View File

@ -43,7 +43,7 @@ User documentation:
change.log Version-to-version change highlights. change.log Version-to-version change highlights.
Programmer and internal documentation: Programmer and internal documentation:
libjpeg.txt How to use the JPEG library in your own programs. libjpeg.txt How to use the JPEG library in your own programs.
example.c Sample code for calling the JPEG library. example.txt Sample code for calling the JPEG library.
structure.txt Overview of the JPEG library's internal structure. structure.txt Overview of the JPEG library's internal structure.
coderules.txt Coding style rules --- please read if you contribute code. coderules.txt Coding style rules --- please read if you contribute code.
@ -159,12 +159,6 @@ commercial products, provided that all warranty or liability claims are
assumed by the product vendor. assumed by the product vendor.
The Unix configuration script "configure" was produced with GNU Autoconf.
It is copyright by the Free Software Foundation but is freely distributable.
The same holds for its supporting scripts (config.guess, config.sub,
ltmain.sh). Another support script, install-sh, is copyright by X Consortium
but is also freely distributable.
The IJG distribution formerly included code to read and write GIF files. The IJG distribution formerly included code to read and write GIF files.
To avoid entanglement with the Unisys LZW patent (now expired), GIF reading To avoid entanglement with the Unisys LZW patent (now expired), GIF reading
support has been removed altogether, and the GIF writer has been simplified support has been removed altogether, and the GIF writer has been simplified
@ -220,14 +214,14 @@ Continuous-tone Still Images, Part 2: Compliance testing" and has document
numbers ISO/IEC IS 10918-2, ITU-T T.83. numbers ISO/IEC IS 10918-2, ITU-T T.83.
The JPEG standard does not specify all details of an interchangeable file The JPEG standard does not specify all details of an interchangeable file
format. For the omitted details we follow the "JFIF" conventions, revision format. For the omitted details, we follow the "JFIF" conventions, revision
1.02. JFIF 1.02 has been adopted as an Ecma International Technical Report 1.02. JFIF version 1 has been adopted as ISO/IEC 10918-5 (05/2013) and
and thus received a formal publication status. It is available as a free Recommendation ITU-T T.871 (05/2011): Information technology - Digital
download in PDF format from compression and coding of continuous-tone still images: JPEG File Interchange
http://www.ecma-international.org/publications/techreports/E-TR-098.htm. Format (JFIF). It is available as a free download in PDF file format from
A PostScript version of the JFIF document is available at https://www.iso.org/standard/54989.html and http://www.itu.int/rec/T-REC-T.871.
http://www.ijg.org/files/jfif.ps.gz. There is also a plain text version at A PDF file of the older JFIF 1.02 specification is available at
http://www.ijg.org/files/jfif.txt.gz, but it is missing the figures. http://www.w3.org/Graphics/JPEG/jfif3.pdf.
The TIFF 6.0 file format specification can be obtained by FTP from The TIFF 6.0 file format specification can be obtained by FTP from
ftp://ftp.sgi.com/graphics/tiff/TIFF6.ps.gz. The JPEG incorporation scheme ftp://ftp.sgi.com/graphics/tiff/TIFF6.ps.gz. The JPEG incorporation scheme
@ -259,18 +253,22 @@ with body
send usenet/news.answers/jpeg-faq/part2 send usenet/news.answers/jpeg-faq/part2
FILE FORMAT WARS FILE FORMAT COMPATIBILITY
================ =========================
The ISO/IEC JTC1/SC29/WG1 standards committee (also known as JPEG, together This software implements ITU T.81 | ISO/IEC 10918 with some extensions from
with ITU-T SG16) currently promotes different formats containing the name ITU T.871 | ISO/IEC 10918-5 (JPEG File Interchange Format-- see REFERENCES).
"JPEG" which are incompatible with original DCT-based JPEG. IJG therefore does Informally, the term "JPEG image" or "JPEG file" most often refers to JFIF or
not support these formats (see REFERENCES). Indeed, one of the original a subset thereof, but there are other formats containing the name "JPEG" that
reasons for developing this free software was to help force convergence on are incompatible with the DCT-based JPEG standard or with JFIF (for instance,
common, interoperable format standards for JPEG files. JPEG 2000 and JPEG XR). This software therefore does not support these
Don't use an incompatible file format! formats. Indeed, one of the original reasons for developing this free software
(In any case, our decoder will remain capable of reading existing JPEG was to help force convergence on a common, interoperable format standard for
image files indefinitely.) JPEG files.
JFIF is a minimal or "low end" representation. TIFF/JPEG (TIFF revision 6.0 as
modified by TIFF Technical Note #2) can be used for "high end" applications
that need to record a lot of additional data about an image.
TO DO TO DO

View File

@ -2,8 +2,9 @@ Background
========== ==========
libjpeg-turbo is a JPEG image codec that uses SIMD instructions (MMX, SSE2, libjpeg-turbo is a JPEG image codec that uses SIMD instructions (MMX, SSE2,
NEON, AltiVec) to accelerate baseline JPEG compression and decompression on AVX2, NEON, AltiVec) to accelerate baseline JPEG compression and decompression
x86, x86-64, ARM, and PowerPC systems. On such systems, libjpeg-turbo is on x86, x86-64, ARM, and PowerPC systems, as well as progressive JPEG
compression on x86 and x86-64 systems. On such systems, libjpeg-turbo is
generally 2-6x as fast as libjpeg, all else being equal. On other types of generally 2-6x as fast as libjpeg, all else being equal. On other types of
systems, libjpeg-turbo can still outperform libjpeg by a significant amount, by systems, libjpeg-turbo can still outperform libjpeg by a significant amount, by
virtue of its highly-optimized Huffman coding routines. In many cases, the virtue of its highly-optimized Huffman coding routines. In many cases, the
@ -48,7 +49,10 @@ JPEG images:
straightforward to achieve using the underlying libjpeg API, such as straightforward to achieve using the underlying libjpeg API, such as
generating planar YUV images and performing multiple simultaneous lossless generating planar YUV images and performing multiple simultaneous lossless
transforms on an image. The Java interface for libjpeg-turbo is written on transforms on an image. The Java interface for libjpeg-turbo is written on
top of the TurboJPEG API. top of the TurboJPEG API. The TurboJPEG API is recommended for first-time
users of libjpeg-turbo. Refer to [tjexample.c](tjexample.c) and
[TJExample.java](java/TJExample.java) for examples of its usage and to
<http://libjpeg-turbo.org/Documentation/Documentation> for API documentation.
- **libjpeg API**<br> - **libjpeg API**<br>
This is the de facto industry-standard API for compressing and decompressing This is the de facto industry-standard API for compressing and decompressing
@ -56,7 +60,8 @@ JPEG images:
more powerful. The libjpeg API implementation in libjpeg-turbo is both more powerful. The libjpeg API implementation in libjpeg-turbo is both
API/ABI-compatible and mathematically compatible with libjpeg v6b. It can API/ABI-compatible and mathematically compatible with libjpeg v6b. It can
also optionally be configured to be API/ABI-compatible with libjpeg v7 and v8 also optionally be configured to be API/ABI-compatible with libjpeg v7 and v8
(see below.) (see below.) Refer to [cjpeg.c](cjpeg.c) and [djpeg.c](djpeg.c) for examples
of its usage and to [libjpeg.txt](libjpeg.txt) for API documentation.
There is no significant performance advantage to either API when both are used There is no significant performance advantage to either API when both are used
to perform similar operations. to perform similar operations.

View File

@ -1,12 +1,25 @@
/* jconfig.vc --- jconfig.h for Microsoft Visual C++ on Windows 95 or NT. */ /* Version ID for the JPEG library.
/* see jconfig.txt for explanations */ * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
*/
#define JPEG_LIB_VERSION @JPEG_LIB_VERSION@ #define JPEG_LIB_VERSION @JPEG_LIB_VERSION@
/* libjpeg-turbo version */
#define LIBJPEG_TURBO_VERSION @VERSION@ #define LIBJPEG_TURBO_VERSION @VERSION@
/* libjpeg-turbo version in integer form */
#define LIBJPEG_TURBO_VERSION_NUMBER @LIBJPEG_TURBO_VERSION_NUMBER@ #define LIBJPEG_TURBO_VERSION_NUMBER @LIBJPEG_TURBO_VERSION_NUMBER@
#cmakedefine C_ARITH_CODING_SUPPORTED
#cmakedefine D_ARITH_CODING_SUPPORTED /* Support arithmetic encoding */
#cmakedefine MEM_SRCDST_SUPPORTED #cmakedefine C_ARITH_CODING_SUPPORTED 1
/* Support arithmetic decoding */
#cmakedefine D_ARITH_CODING_SUPPORTED 1
/* Support in-memory source/destination managers */
#cmakedefine MEM_SRCDST_SUPPORTED 1
/* Use accelerated SIMD routines. */
#cmakedefine WITH_SIMD 1
/* /*
* Define BITS_IN_JSAMPLE as either * Define BITS_IN_JSAMPLE as either
@ -19,35 +32,42 @@
#define BITS_IN_JSAMPLE @BITS_IN_JSAMPLE@ /* use 8 or 12 */ #define BITS_IN_JSAMPLE @BITS_IN_JSAMPLE@ /* use 8 or 12 */
#define HAVE_UNSIGNED_CHAR /* Define to 1 if you have the <locale.h> header file. */
#define HAVE_UNSIGNED_SHORT #cmakedefine HAVE_LOCALE_H 1
/* #define void char */
/* #define const */
#undef __CHAR_UNSIGNED__
#define HAVE_STDDEF_H
#define HAVE_STDLIB_H
#undef NEED_BSD_STRINGS
#undef NEED_SYS_TYPES_H
#undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
#undef INCOMPLETE_TYPES_BROKEN
/* Define "boolean" as unsigned char, not int, per Windows custom */ /* Define to 1 if you have the <stddef.h> header file. */
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ #cmakedefine HAVE_STDDEF_H 1
typedef unsigned char boolean;
/* Define to 1 if you have the <stdlib.h> header file. */
#cmakedefine HAVE_STDLIB_H 1
/* Define if you need to include <sys/types.h> to get size_t. */
#cmakedefine NEED_SYS_TYPES_H 1
/* Define if you have BSD-like bzero and bcopy in <strings.h> rather than
memset/memcpy in <string.h>. */
#cmakedefine NEED_BSD_STRINGS 1
/* Define to 1 if the system has the type `unsigned char'. */
#cmakedefine HAVE_UNSIGNED_CHAR 1
/* Define to 1 if the system has the type `unsigned short'. */
#cmakedefine HAVE_UNSIGNED_SHORT 1
/* Compiler does not support pointers to undefined structures. */
#cmakedefine INCOMPLETE_TYPES_BROKEN 1
/* Define if your (broken) compiler shifts signed values as if they were
unsigned. */
#cmakedefine RIGHT_SHIFT_IS_UNSIGNED 1
/* Define to 1 if type `char' is unsigned and you are not using gcc. */
#ifndef __CHAR_UNSIGNED__
#cmakedefine __CHAR_UNSIGNED__ 1
#endif #endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
/* Define "INT32" as int, not long, per Windows custom */ /* Define to empty if `const' does not conform to ANSI C. */
#if !(defined(_BASETSD_H_) || defined(_BASETSD_H)) /* don't conflict if basetsd.h already read */ /* #undef const */
typedef short INT16;
typedef signed int INT32;
#endif
#define XMD_H /* prevent jmorecfg.h from redefining it */
#ifdef JPEG_INTERNALS /* Define to `unsigned int' if <sys/types.h> does not define. */
/* #undef size_t */
#undef RIGHT_SHIFT_IS_UNSIGNED
#define SIZEOF_SIZE_T @SIZEOF_SIZE_T@
#endif /* JPEG_INTERNALS */

34
3rdparty/libjpeg-turbo/jconfig.h.win.in vendored Normal file
View File

@ -0,0 +1,34 @@
#define JPEG_LIB_VERSION @JPEG_LIB_VERSION@
#define LIBJPEG_TURBO_VERSION @VERSION@
#define LIBJPEG_TURBO_VERSION_NUMBER @LIBJPEG_TURBO_VERSION_NUMBER@
#cmakedefine C_ARITH_CODING_SUPPORTED
#cmakedefine D_ARITH_CODING_SUPPORTED
#cmakedefine MEM_SRCDST_SUPPORTED
#cmakedefine WITH_SIMD
#define BITS_IN_JSAMPLE @BITS_IN_JSAMPLE@ /* use 8 or 12 */
#define HAVE_STDDEF_H
#define HAVE_STDLIB_H
#undef NEED_SYS_TYPES_H
#undef NEED_BSD_STRINGS
#define HAVE_UNSIGNED_CHAR
#define HAVE_UNSIGNED_SHORT
#undef INCOMPLETE_TYPES_BROKEN
#undef RIGHT_SHIFT_IS_UNSIGNED
#undef __CHAR_UNSIGNED__
/* Define "boolean" as unsigned char, not int, per Windows custom */
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean;
#endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
/* Define "INT32" as int, not long, per Windows custom */
#if !(defined(_BASETSD_H_) || defined(_BASETSD_H)) /* don't conflict if basetsd.h already read */
typedef short INT16;
typedef signed int INT32;
#endif
#define XMD_H /* prevent jmorecfg.h from redefining it */

View File

@ -1,13 +1,31 @@
#define VERSION "@VERSION@" /* libjpeg-turbo build number */
#define BUILD "@BUILD@" #define BUILD "@BUILD@"
/* Compiler's inline keyword */
#undef inline
/* How to obtain function inlining. */
#define INLINE @INLINE@
/* Define to the full name of this package. */
#define PACKAGE_NAME "@CMAKE_PROJECT_NAME@" #define PACKAGE_NAME "@CMAKE_PROJECT_NAME@"
#ifndef INLINE /* Version number of package */
#if defined(__GNUC__) #define VERSION "@VERSION@"
#define INLINE inline __attribute__((always_inline))
#elif defined(_MSC_VER) /* The size of `size_t', as computed by sizeof. */
#define INLINE __forceinline #define SIZEOF_SIZE_T @SIZE_T@
#else
#define INLINE /* Define if your compiler has __builtin_ctzl() and sizeof(unsigned long) == sizeof(size_t). */
#cmakedefine HAVE_BUILTIN_CTZL
/* Define to 1 if you have the <intrin.h> header file. */
#cmakedefine HAVE_INTRIN_H
#if defined(_MSC_VER) && defined(HAVE_INTRIN_H)
#if (SIZEOF_SIZE_T == 8)
#define HAVE_BITSCANFORWARD64
#elif (SIZEOF_SIZE_T == 4)
#define HAVE_BITSCANFORWARD
#endif #endif
#endif #endif

View File

@ -4,16 +4,16 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Developed 1997-2009 by Guido Vollbeding. * Developed 1997-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2015, D. R. Commander. * Copyright (C) 2015, 2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
* This file contains probability estimation tables for common use in * This file contains probability estimation tables for common use in
* arithmetic entropy encoding and decoding routines. * arithmetic entropy encoding and decoding routines.
* *
* This data represents Table D.2 in the JPEG spec (ISO/IEC IS 10918-1 * This data represents Table D.2 in
* and CCITT Recommendation ITU-T T.81) and Table 24 in the JBIG spec * Recommendation ITU-T T.81 (1992) | ISO/IEC 10918-1:1994 and Table 24 in
* (ISO/IEC IS 11544 and CCITT Recommendation ITU-T T.82). * Recommendation ITU-T T.82 (1993) | ISO/IEC 11544:1993.
*/ */
#define JPEG_INTERNALS #define JPEG_INTERNALS
@ -29,9 +29,10 @@
* implementation (jbig_tab.c). * implementation (jbig_tab.c).
*/ */
#define V(i,a,b,c,d) (((JLONG)a << 16) | ((JLONG)c << 8) | ((JLONG)d << 7) | b) #define V(i, a, b, c, d) \
(((JLONG)a << 16) | ((JLONG)c << 8) | ((JLONG)d << 7) | b)
const JLONG jpeg_aritab[113+1] = { const JLONG jpeg_aritab[113 + 1] = {
/* /*
* Index, Qe_Value, Next_Index_LPS, Next_Index_MPS, Switch_MPS * Index, Qe_Value, Next_Index_LPS, Next_Index_MPS, Switch_MPS
*/ */

View File

@ -31,7 +31,7 @@
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize) jpeg_CreateCompress(j_compress_ptr cinfo, int version, size_t structsize)
{ {
int i; int i;
@ -41,7 +41,7 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
if (structsize != sizeof(struct jpeg_compress_struct)) if (structsize != sizeof(struct jpeg_compress_struct))
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
(int) sizeof(struct jpeg_compress_struct), (int) structsize); (int)sizeof(struct jpeg_compress_struct), (int)structsize);
/* For debugging purposes, we zero the whole master structure. /* For debugging purposes, we zero the whole master structure.
* But the application has already set the err pointer, and may have set * But the application has already set the err pointer, and may have set
@ -59,7 +59,7 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
cinfo->is_decompressor = FALSE; cinfo->is_decompressor = FALSE;
/* Initialize a memory manager instance for this object */ /* Initialize a memory manager instance for this object */
jinit_memory_mgr((j_common_ptr) cinfo); jinit_memory_mgr((j_common_ptr)cinfo);
/* Zero out pointers to permanent structures. */ /* Zero out pointers to permanent structures. */
cinfo->progress = NULL; cinfo->progress = NULL;
@ -83,7 +83,7 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
/* Must do it here for emit_dqt in case jpeg_write_tables is used */ /* Must do it here for emit_dqt in case jpeg_write_tables is used */
cinfo->block_size = DCTSIZE; cinfo->block_size = DCTSIZE;
cinfo->natural_order = jpeg_natural_order; cinfo->natural_order = jpeg_natural_order;
cinfo->lim_Se = DCTSIZE2-1; cinfo->lim_Se = DCTSIZE2 - 1;
#endif #endif
cinfo->script_space = NULL; cinfo->script_space = NULL;
@ -100,9 +100,9 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_destroy_compress (j_compress_ptr cinfo) jpeg_destroy_compress(j_compress_ptr cinfo)
{ {
jpeg_destroy((j_common_ptr) cinfo); /* use common routine */ jpeg_destroy((j_common_ptr)cinfo); /* use common routine */
} }
@ -112,9 +112,9 @@ jpeg_destroy_compress (j_compress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_abort_compress (j_compress_ptr cinfo) jpeg_abort_compress(j_compress_ptr cinfo)
{ {
jpeg_abort((j_common_ptr) cinfo); /* use common routine */ jpeg_abort((j_common_ptr)cinfo); /* use common routine */
} }
@ -131,7 +131,7 @@ jpeg_abort_compress (j_compress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress) jpeg_suppress_tables(j_compress_ptr cinfo, boolean suppress)
{ {
int i; int i;
JQUANT_TBL *qtbl; JQUANT_TBL *qtbl;
@ -159,7 +159,7 @@ jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_finish_compress (j_compress_ptr cinfo) jpeg_finish_compress(j_compress_ptr cinfo)
{ {
JDIMENSION iMCU_row; JDIMENSION iMCU_row;
@ -172,18 +172,18 @@ jpeg_finish_compress (j_compress_ptr cinfo)
} else if (cinfo->global_state != CSTATE_WRCOEFS) } else if (cinfo->global_state != CSTATE_WRCOEFS)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
/* Perform any remaining passes */ /* Perform any remaining passes */
while (! cinfo->master->is_last_pass) { while (!cinfo->master->is_last_pass) {
(*cinfo->master->prepare_for_pass) (cinfo); (*cinfo->master->prepare_for_pass) (cinfo);
for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) { for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
if (cinfo->progress != NULL) { if (cinfo->progress != NULL) {
cinfo->progress->pass_counter = (long) iMCU_row; cinfo->progress->pass_counter = (long)iMCU_row;
cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows; cinfo->progress->pass_limit = (long)cinfo->total_iMCU_rows;
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
} }
/* We bypass the main controller and invoke coef controller directly; /* We bypass the main controller and invoke coef controller directly;
* all work is being done from the coefficient buffer. * all work is being done from the coefficient buffer.
*/ */
if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL)) if (!(*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE)NULL))
ERREXIT(cinfo, JERR_CANT_SUSPEND); ERREXIT(cinfo, JERR_CANT_SUSPEND);
} }
(*cinfo->master->finish_pass) (cinfo); (*cinfo->master->finish_pass) (cinfo);
@ -192,7 +192,7 @@ jpeg_finish_compress (j_compress_ptr cinfo)
(*cinfo->marker->write_file_trailer) (cinfo); (*cinfo->marker->write_file_trailer) (cinfo);
(*cinfo->dest->term_destination) (cinfo); (*cinfo->dest->term_destination) (cinfo);
/* We can use jpeg_abort to release memory and reset global_state */ /* We can use jpeg_abort to release memory and reset global_state */
jpeg_abort((j_common_ptr) cinfo); jpeg_abort((j_common_ptr)cinfo);
} }
@ -204,8 +204,8 @@ jpeg_finish_compress (j_compress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_write_marker (j_compress_ptr cinfo, int marker, jpeg_write_marker(j_compress_ptr cinfo, int marker, const JOCTET *dataptr,
const JOCTET *dataptr, unsigned int datalen) unsigned int datalen)
{ {
void (*write_marker_byte) (j_compress_ptr info, int val); void (*write_marker_byte) (j_compress_ptr info, int val);
@ -226,7 +226,7 @@ jpeg_write_marker (j_compress_ptr cinfo, int marker,
/* Same, but piecemeal. */ /* Same, but piecemeal. */
GLOBAL(void) GLOBAL(void)
jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen) jpeg_write_m_header(j_compress_ptr cinfo, int marker, unsigned int datalen)
{ {
if (cinfo->next_scanline != 0 || if (cinfo->next_scanline != 0 ||
(cinfo->global_state != CSTATE_SCANNING && (cinfo->global_state != CSTATE_SCANNING &&
@ -238,7 +238,7 @@ jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
} }
GLOBAL(void) GLOBAL(void)
jpeg_write_m_byte (j_compress_ptr cinfo, int val) jpeg_write_m_byte(j_compress_ptr cinfo, int val)
{ {
(*cinfo->marker->write_marker_byte) (cinfo, val); (*cinfo->marker->write_marker_byte) (cinfo, val);
} }
@ -266,13 +266,13 @@ jpeg_write_m_byte (j_compress_ptr cinfo, int val)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_write_tables (j_compress_ptr cinfo) jpeg_write_tables(j_compress_ptr cinfo)
{ {
if (cinfo->global_state != CSTATE_START) if (cinfo->global_state != CSTATE_START)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
/* (Re)initialize error mgr and destination modules */ /* (Re)initialize error mgr and destination modules */
(*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); (*cinfo->err->reset_error_mgr) ((j_common_ptr)cinfo);
(*cinfo->dest->init_destination) (cinfo); (*cinfo->dest->init_destination) (cinfo);
/* Initialize the marker writer ... bit of a crock to do it here. */ /* Initialize the marker writer ... bit of a crock to do it here. */
jinit_marker_writer(cinfo); jinit_marker_writer(cinfo);

View File

@ -36,7 +36,7 @@
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables) jpeg_start_compress(j_compress_ptr cinfo, boolean write_all_tables)
{ {
if (cinfo->global_state != CSTATE_START) if (cinfo->global_state != CSTATE_START)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
@ -45,7 +45,7 @@ jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */ jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
/* (Re)initialize error mgr and destination modules */ /* (Re)initialize error mgr and destination modules */
(*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); (*cinfo->err->reset_error_mgr) ((j_common_ptr)cinfo);
(*cinfo->dest->init_destination) (cinfo); (*cinfo->dest->init_destination) (cinfo);
/* Perform master selection of active modules */ /* Perform master selection of active modules */
jinit_compress_master(cinfo); jinit_compress_master(cinfo);
@ -75,7 +75,7 @@ jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
*/ */
GLOBAL(JDIMENSION) GLOBAL(JDIMENSION)
jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines, jpeg_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines,
JDIMENSION num_lines) JDIMENSION num_lines)
{ {
JDIMENSION row_ctr, rows_left; JDIMENSION row_ctr, rows_left;
@ -87,9 +87,9 @@ jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
/* Call progress monitor hook if present */ /* Call progress monitor hook if present */
if (cinfo->progress != NULL) { if (cinfo->progress != NULL) {
cinfo->progress->pass_counter = (long) cinfo->next_scanline; cinfo->progress->pass_counter = (long)cinfo->next_scanline;
cinfo->progress->pass_limit = (long) cinfo->image_height; cinfo->progress->pass_limit = (long)cinfo->image_height;
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
} }
/* Give master control module another chance if this is first call to /* Give master control module another chance if this is first call to
@ -118,7 +118,7 @@ jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
*/ */
GLOBAL(JDIMENSION) GLOBAL(JDIMENSION)
jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data, jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
JDIMENSION num_lines) JDIMENSION num_lines)
{ {
JDIMENSION lines_per_iMCU_row; JDIMENSION lines_per_iMCU_row;
@ -132,9 +132,9 @@ jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
/* Call progress monitor hook if present */ /* Call progress monitor hook if present */
if (cinfo->progress != NULL) { if (cinfo->progress != NULL) {
cinfo->progress->pass_counter = (long) cinfo->next_scanline; cinfo->progress->pass_counter = (long)cinfo->next_scanline;
cinfo->progress->pass_limit = (long) cinfo->image_height; cinfo->progress->pass_limit = (long)cinfo->image_height;
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
} }
/* Give master control module another chance if this is first call to /* Give master control module another chance if this is first call to
@ -151,7 +151,7 @@ jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
ERREXIT(cinfo, JERR_BUFFER_SIZE); ERREXIT(cinfo, JERR_BUFFER_SIZE);
/* Directly compress the row. */ /* Directly compress the row. */
if (! (*cinfo->coef->compress_data) (cinfo, data)) { if (!(*cinfo->coef->compress_data) (cinfo, data)) {
/* If compressor did not consume the whole row, suspend processing. */ /* If compressor did not consume the whole row, suspend processing. */
return 0; return 0;
} }

View File

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

View File

@ -58,21 +58,19 @@ typedef my_coef_controller *my_coef_ptr;
/* Forward declarations */ /* Forward declarations */
METHODDEF(boolean) compress_data METHODDEF(boolean) compress_data(j_compress_ptr cinfo, JSAMPIMAGE input_buf);
(j_compress_ptr cinfo, JSAMPIMAGE input_buf);
#ifdef FULL_COEF_BUFFER_SUPPORTED #ifdef FULL_COEF_BUFFER_SUPPORTED
METHODDEF(boolean) compress_first_pass METHODDEF(boolean) compress_first_pass(j_compress_ptr cinfo,
(j_compress_ptr cinfo, JSAMPIMAGE input_buf); JSAMPIMAGE input_buf);
METHODDEF(boolean) compress_output METHODDEF(boolean) compress_output(j_compress_ptr cinfo, JSAMPIMAGE input_buf);
(j_compress_ptr cinfo, JSAMPIMAGE input_buf);
#endif #endif
LOCAL(void) LOCAL(void)
start_iMCU_row (j_compress_ptr cinfo) start_iMCU_row(j_compress_ptr cinfo)
/* Reset within-iMCU-row counters for a new row */ /* Reset within-iMCU-row counters for a new row */
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
/* In an interleaved scan, an MCU row is the same as an iMCU row. /* In an interleaved scan, an MCU row is the same as an iMCU row.
* In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
@ -81,7 +79,7 @@ start_iMCU_row (j_compress_ptr cinfo)
if (cinfo->comps_in_scan > 1) { if (cinfo->comps_in_scan > 1) {
coef->MCU_rows_per_iMCU_row = 1; coef->MCU_rows_per_iMCU_row = 1;
} else { } else {
if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1)) if (coef->iMCU_row_num < (cinfo->total_iMCU_rows - 1))
coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
else else
coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
@ -97,9 +95,9 @@ start_iMCU_row (j_compress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode) start_pass_coef(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
coef->iMCU_row_num = 0; coef->iMCU_row_num = 0;
start_iMCU_row(cinfo); start_iMCU_row(cinfo);
@ -140,9 +138,9 @@ start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf) compress_data(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
JDIMENSION MCU_col_num; /* index of current MCU within row */ JDIMENSION MCU_col_num; /* index of current MCU within row */
JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
@ -167,31 +165,33 @@ compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
blkn = 0; blkn = 0;
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width :
: compptr->last_col_width; compptr->last_col_width;
xpos = MCU_col_num * compptr->MCU_sample_width; xpos = MCU_col_num * compptr->MCU_sample_width;
ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */ ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
for (yindex = 0; yindex < compptr->MCU_height; yindex++) { for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
if (coef->iMCU_row_num < last_iMCU_row || if (coef->iMCU_row_num < last_iMCU_row ||
yoffset+yindex < compptr->last_row_height) { yoffset + yindex < compptr->last_row_height) {
(*cinfo->fdct->forward_DCT) (cinfo, compptr, (*cinfo->fdct->forward_DCT) (cinfo, compptr,
input_buf[compptr->component_index], input_buf[compptr->component_index],
coef->MCU_buffer[blkn], coef->MCU_buffer[blkn],
ypos, xpos, (JDIMENSION) blockcnt); ypos, xpos, (JDIMENSION)blockcnt);
if (blockcnt < compptr->MCU_width) { if (blockcnt < compptr->MCU_width) {
/* Create some dummy blocks at the right edge of the image. */ /* Create some dummy blocks at the right edge of the image. */
jzero_far((void *) coef->MCU_buffer[blkn + blockcnt], jzero_far((void *)coef->MCU_buffer[blkn + blockcnt],
(compptr->MCU_width - blockcnt) * sizeof(JBLOCK)); (compptr->MCU_width - blockcnt) * sizeof(JBLOCK));
for (bi = blockcnt; bi < compptr->MCU_width; bi++) { for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0]; coef->MCU_buffer[blkn + bi][0][0] =
coef->MCU_buffer[blkn + bi - 1][0][0];
} }
} }
} else { } else {
/* Create a row of dummy blocks at the bottom of the image. */ /* Create a row of dummy blocks at the bottom of the image. */
jzero_far((void *) coef->MCU_buffer[blkn], jzero_far((void *)coef->MCU_buffer[blkn],
compptr->MCU_width * sizeof(JBLOCK)); compptr->MCU_width * sizeof(JBLOCK));
for (bi = 0; bi < compptr->MCU_width; bi++) { for (bi = 0; bi < compptr->MCU_width; bi++) {
coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0]; coef->MCU_buffer[blkn + bi][0][0] =
coef->MCU_buffer[blkn - 1][0][0];
} }
} }
blkn += compptr->MCU_width; blkn += compptr->MCU_width;
@ -201,7 +201,7 @@ compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
/* Try to write the MCU. In event of a suspension failure, we will /* Try to write the MCU. In event of a suspension failure, we will
* re-DCT the MCU on restart (a bit inefficient, could be fixed...) * re-DCT the MCU on restart (a bit inefficient, could be fixed...)
*/ */
if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) { if (!(*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
/* Suspension forced; update state counters and exit */ /* Suspension forced; update state counters and exit */
coef->MCU_vert_offset = yoffset; coef->MCU_vert_offset = yoffset;
coef->mcu_ctr = MCU_col_num; coef->mcu_ctr = MCU_col_num;
@ -242,9 +242,9 @@ compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf) compress_first_pass(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
JDIMENSION blocks_across, MCUs_across, MCUindex; JDIMENSION blocks_across, MCUs_across, MCUindex;
int bi, ci, h_samp_factor, block_row, block_rows, ndummy; int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
@ -257,21 +257,21 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
ci++, compptr++) { ci++, compptr++) {
/* Align the virtual buffer for this component. */ /* Align the virtual buffer for this component. */
buffer = (*cinfo->mem->access_virt_barray) buffer = (*cinfo->mem->access_virt_barray)
((j_common_ptr) cinfo, coef->whole_image[ci], ((j_common_ptr)cinfo, coef->whole_image[ci],
coef->iMCU_row_num * compptr->v_samp_factor, coef->iMCU_row_num * compptr->v_samp_factor,
(JDIMENSION) compptr->v_samp_factor, TRUE); (JDIMENSION)compptr->v_samp_factor, TRUE);
/* Count non-dummy DCT block rows in this iMCU row. */ /* Count non-dummy DCT block rows in this iMCU row. */
if (coef->iMCU_row_num < last_iMCU_row) if (coef->iMCU_row_num < last_iMCU_row)
block_rows = compptr->v_samp_factor; block_rows = compptr->v_samp_factor;
else { else {
/* NB: can't use last_row_height here, since may not be set! */ /* NB: can't use last_row_height here, since may not be set! */
block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
if (block_rows == 0) block_rows = compptr->v_samp_factor; if (block_rows == 0) block_rows = compptr->v_samp_factor;
} }
blocks_across = compptr->width_in_blocks; blocks_across = compptr->width_in_blocks;
h_samp_factor = compptr->h_samp_factor; h_samp_factor = compptr->h_samp_factor;
/* Count number of dummy blocks to be added at the right margin. */ /* Count number of dummy blocks to be added at the right margin. */
ndummy = (int) (blocks_across % h_samp_factor); ndummy = (int)(blocks_across % h_samp_factor);
if (ndummy > 0) if (ndummy > 0)
ndummy = h_samp_factor - ndummy; ndummy = h_samp_factor - ndummy;
/* Perform DCT for all non-dummy blocks in this iMCU row. Each call /* Perform DCT for all non-dummy blocks in this iMCU row. Each call
@ -281,12 +281,12 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
thisblockrow = buffer[block_row]; thisblockrow = buffer[block_row];
(*cinfo->fdct->forward_DCT) (cinfo, compptr, (*cinfo->fdct->forward_DCT) (cinfo, compptr,
input_buf[ci], thisblockrow, input_buf[ci], thisblockrow,
(JDIMENSION) (block_row * DCTSIZE), (JDIMENSION)(block_row * DCTSIZE),
(JDIMENSION) 0, blocks_across); (JDIMENSION)0, blocks_across);
if (ndummy > 0) { if (ndummy > 0) {
/* Create dummy blocks at the right edge of the image. */ /* Create dummy blocks at the right edge of the image. */
thisblockrow += blocks_across; /* => first dummy block */ thisblockrow += blocks_across; /* => first dummy block */
jzero_far((void *) thisblockrow, ndummy * sizeof(JBLOCK)); jzero_far((void *)thisblockrow, ndummy * sizeof(JBLOCK));
lastDC = thisblockrow[-1][0]; lastDC = thisblockrow[-1][0];
for (bi = 0; bi < ndummy; bi++) { for (bi = 0; bi < ndummy; bi++) {
thisblockrow[bi][0] = lastDC; thisblockrow[bi][0] = lastDC;
@ -304,11 +304,11 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
for (block_row = block_rows; block_row < compptr->v_samp_factor; for (block_row = block_rows; block_row < compptr->v_samp_factor;
block_row++) { block_row++) {
thisblockrow = buffer[block_row]; thisblockrow = buffer[block_row];
lastblockrow = buffer[block_row-1]; lastblockrow = buffer[block_row - 1];
jzero_far((void *) thisblockrow, jzero_far((void *)thisblockrow,
(size_t) (blocks_across * sizeof(JBLOCK))); (size_t)(blocks_across * sizeof(JBLOCK)));
for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) { for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
lastDC = lastblockrow[h_samp_factor-1][0]; lastDC = lastblockrow[h_samp_factor - 1][0];
for (bi = 0; bi < h_samp_factor; bi++) { for (bi = 0; bi < h_samp_factor; bi++) {
thisblockrow[bi][0] = lastDC; thisblockrow[bi][0] = lastDC;
} }
@ -338,9 +338,9 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf) compress_output(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
JDIMENSION MCU_col_num; /* index of current MCU within row */ JDIMENSION MCU_col_num; /* index of current MCU within row */
int blkn, ci, xindex, yindex, yoffset; int blkn, ci, xindex, yindex, yoffset;
JDIMENSION start_col; JDIMENSION start_col;
@ -355,9 +355,9 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
buffer[ci] = (*cinfo->mem->access_virt_barray) buffer[ci] = (*cinfo->mem->access_virt_barray)
((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
coef->iMCU_row_num * compptr->v_samp_factor, coef->iMCU_row_num * compptr->v_samp_factor,
(JDIMENSION) compptr->v_samp_factor, FALSE); (JDIMENSION)compptr->v_samp_factor, FALSE);
} }
/* Loop to process one whole iMCU row */ /* Loop to process one whole iMCU row */
@ -371,14 +371,14 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
start_col = MCU_col_num * compptr->MCU_width; start_col = MCU_col_num * compptr->MCU_width;
for (yindex = 0; yindex < compptr->MCU_height; yindex++) { for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
buffer_ptr = buffer[ci][yindex+yoffset] + start_col; buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
for (xindex = 0; xindex < compptr->MCU_width; xindex++) { for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
coef->MCU_buffer[blkn++] = buffer_ptr++; coef->MCU_buffer[blkn++] = buffer_ptr++;
} }
} }
} }
/* Try to write the MCU. */ /* Try to write the MCU. */
if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) { if (!(*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
/* Suspension forced; update state counters and exit */ /* Suspension forced; update state counters and exit */
coef->MCU_vert_offset = yoffset; coef->MCU_vert_offset = yoffset;
coef->mcu_ctr = MCU_col_num; coef->mcu_ctr = MCU_col_num;
@ -402,14 +402,14 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer) jinit_c_coef_controller(j_compress_ptr cinfo, boolean need_full_buffer)
{ {
my_coef_ptr coef; my_coef_ptr coef;
coef = (my_coef_ptr) coef = (my_coef_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_coef_controller)); sizeof(my_coef_controller));
cinfo->coef = (struct jpeg_c_coef_controller *) coef; cinfo->coef = (struct jpeg_c_coef_controller *)coef;
coef->pub.start_pass = start_pass_coef; coef->pub.start_pass = start_pass_coef;
/* Create the coefficient buffer. */ /* Create the coefficient buffer. */
@ -423,12 +423,12 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
(JDIMENSION) jround_up((long) compptr->width_in_blocks, (JDIMENSION)jround_up((long)compptr->width_in_blocks,
(long) compptr->h_samp_factor), (long)compptr->h_samp_factor),
(JDIMENSION) jround_up((long) compptr->height_in_blocks, (JDIMENSION)jround_up((long)compptr->height_in_blocks,
(long) compptr->v_samp_factor), (long)compptr->v_samp_factor),
(JDIMENSION) compptr->v_samp_factor); (JDIMENSION)compptr->v_samp_factor);
} }
#else #else
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
@ -439,7 +439,7 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
int i; int i;
buffer = (JBLOCKROW) buffer = (JBLOCKROW)
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
C_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK)); C_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) { for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
coef->MCU_buffer[i] = buffer + i; coef->MCU_buffer[i] = buffer + i;

View File

@ -29,13 +29,13 @@
INLINE INLINE
LOCAL(void) LOCAL(void)
rgb_ycc_convert_internal (j_compress_ptr cinfo, rgb_ycc_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPIMAGE output_buf, JDIMENSION output_row,
JDIMENSION output_row, int num_rows) int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int r, g, b; register int r, g, b;
register JLONG * ctab = cconvert->rgb_ycc_tab; register JLONG *ctab = cconvert->rgb_ycc_tab;
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr0, outptr1, outptr2; register JSAMPROW outptr0, outptr1, outptr2;
register JDIMENSION col; register JDIMENSION col;
@ -58,17 +58,14 @@ rgb_ycc_convert_internal (j_compress_ptr cinfo,
* need the general RIGHT_SHIFT macro. * need the general RIGHT_SHIFT macro.
*/ */
/* Y */ /* Y */
outptr0[col] = (JSAMPLE) outptr0[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) ctab[b + B_Y_OFF]) >> SCALEBITS);
>> SCALEBITS);
/* Cb */ /* Cb */
outptr1[col] = (JSAMPLE) outptr1[col] = (JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF]) ctab[b + B_CB_OFF]) >> SCALEBITS);
>> SCALEBITS);
/* Cr */ /* Cr */
outptr2[col] = (JSAMPLE) outptr2[col] = (JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) ctab[b + B_CR_OFF]) >> SCALEBITS);
>> SCALEBITS);
} }
} }
} }
@ -86,13 +83,13 @@ rgb_ycc_convert_internal (j_compress_ptr cinfo,
INLINE INLINE
LOCAL(void) LOCAL(void)
rgb_gray_convert_internal (j_compress_ptr cinfo, rgb_gray_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPIMAGE output_buf, JDIMENSION output_row,
JDIMENSION output_row, int num_rows) int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int r, g, b; register int r, g, b;
register JLONG * ctab = cconvert->rgb_ycc_tab; register JLONG *ctab = cconvert->rgb_ycc_tab;
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr; register JSAMPROW outptr;
register JDIMENSION col; register JDIMENSION col;
@ -108,9 +105,8 @@ rgb_gray_convert_internal (j_compress_ptr cinfo,
b = GETJSAMPLE(inptr[RGB_BLUE]); b = GETJSAMPLE(inptr[RGB_BLUE]);
inptr += RGB_PIXELSIZE; inptr += RGB_PIXELSIZE;
/* Y */ /* Y */
outptr[col] = (JSAMPLE) outptr[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) ctab[b + B_Y_OFF]) >> SCALEBITS);
>> SCALEBITS);
} }
} }
} }
@ -123,9 +119,9 @@ rgb_gray_convert_internal (j_compress_ptr cinfo,
INLINE INLINE
LOCAL(void) LOCAL(void)
rgb_rgb_convert_internal (j_compress_ptr cinfo, rgb_rgb_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPIMAGE output_buf, JDIMENSION output_row,
JDIMENSION output_row, int num_rows) int num_rows)
{ {
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr0, outptr1, outptr2; register JSAMPROW outptr0, outptr1, outptr2;

View File

@ -63,9 +63,9 @@ typedef my_color_converter *my_cconvert_ptr;
*/ */
#define SCALEBITS 16 /* speediest right-shift on some machines */ #define SCALEBITS 16 /* speediest right-shift on some machines */
#define CBCR_OFFSET ((JLONG) CENTERJSAMPLE << SCALEBITS) #define CBCR_OFFSET ((JLONG)CENTERJSAMPLE << SCALEBITS)
#define ONE_HALF ((JLONG) 1 << (SCALEBITS-1)) #define ONE_HALF ((JLONG)1 << (SCALEBITS - 1))
#define FIX(x) ((JLONG) ((x) * (1L<<SCALEBITS) + 0.5)) #define FIX(x) ((JLONG)((x) * (1L << SCALEBITS) + 0.5))
/* We allocate one big table and divide it up into eight parts, instead of /* We allocate one big table and divide it up into eight parts, instead of
* doing eight alloc_small requests. This lets us use a single table base * doing eight alloc_small requests. This lets us use a single table base
@ -74,15 +74,15 @@ typedef my_color_converter *my_cconvert_ptr;
*/ */
#define R_Y_OFF 0 /* offset to R => Y section */ #define R_Y_OFF 0 /* offset to R => Y section */
#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */ #define G_Y_OFF (1 * (MAXJSAMPLE + 1)) /* offset to G => Y section */
#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */ #define B_Y_OFF (2 * (MAXJSAMPLE + 1)) /* etc. */
#define R_CB_OFF (3*(MAXJSAMPLE+1)) #define R_CB_OFF (3 * (MAXJSAMPLE + 1))
#define G_CB_OFF (4*(MAXJSAMPLE+1)) #define G_CB_OFF (4 * (MAXJSAMPLE + 1))
#define B_CB_OFF (5*(MAXJSAMPLE+1)) #define B_CB_OFF (5 * (MAXJSAMPLE + 1))
#define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */ #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
#define G_CR_OFF (6*(MAXJSAMPLE+1)) #define G_CR_OFF (6 * (MAXJSAMPLE + 1))
#define B_CR_OFF (7*(MAXJSAMPLE+1)) #define B_CR_OFF (7 * (MAXJSAMPLE + 1))
#define TABLE_SIZE (8*(MAXJSAMPLE+1)) #define TABLE_SIZE (8 * (MAXJSAMPLE + 1))
/* Include inline routines for colorspace extensions */ /* Include inline routines for colorspace extensions */
@ -195,33 +195,33 @@ typedef my_color_converter *my_cconvert_ptr;
*/ */
METHODDEF(void) METHODDEF(void)
rgb_ycc_start (j_compress_ptr cinfo) rgb_ycc_start(j_compress_ptr cinfo)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
JLONG *rgb_ycc_tab; JLONG *rgb_ycc_tab;
JLONG i; JLONG i;
/* Allocate and fill in the conversion tables. */ /* Allocate and fill in the conversion tables. */
cconvert->rgb_ycc_tab = rgb_ycc_tab = (JLONG *) cconvert->rgb_ycc_tab = rgb_ycc_tab = (JLONG *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(TABLE_SIZE * sizeof(JLONG))); (TABLE_SIZE * sizeof(JLONG)));
for (i = 0; i <= MAXJSAMPLE; i++) { for (i = 0; i <= MAXJSAMPLE; i++) {
rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i; rgb_ycc_tab[i + R_Y_OFF] = FIX(0.29900) * i;
rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i; rgb_ycc_tab[i + G_Y_OFF] = FIX(0.58700) * i;
rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF; rgb_ycc_tab[i + B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i; rgb_ycc_tab[i + R_CB_OFF] = (-FIX(0.16874)) * i;
rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i; rgb_ycc_tab[i + G_CB_OFF] = (-FIX(0.33126)) * i;
/* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr. /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
* This ensures that the maximum output will round to MAXJSAMPLE * This ensures that the maximum output will round to MAXJSAMPLE
* not MAXJSAMPLE+1, and thus that we don't have to range-limit. * not MAXJSAMPLE+1, and thus that we don't have to range-limit.
*/ */
rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; rgb_ycc_tab[i + B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF - 1;
/* B=>Cb and R=>Cr tables are the same /* B=>Cb and R=>Cr tables are the same
rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; rgb_ycc_tab[i + R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF - 1;
*/ */
rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i; rgb_ycc_tab[i + G_CR_OFF] = (-FIX(0.41869)) * i;
rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i; rgb_ycc_tab[i + B_CR_OFF] = (-FIX(0.08131)) * i;
} }
} }
@ -231,9 +231,8 @@ rgb_ycc_start (j_compress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
rgb_ycc_convert (j_compress_ptr cinfo, rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
JDIMENSION output_row, int num_rows)
{ {
switch (cinfo->in_color_space) { switch (cinfo->in_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@ -280,9 +279,8 @@ rgb_ycc_convert (j_compress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
rgb_gray_convert (j_compress_ptr cinfo, rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
JDIMENSION output_row, int num_rows)
{ {
switch (cinfo->in_color_space) { switch (cinfo->in_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@ -326,9 +324,8 @@ rgb_gray_convert (j_compress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
rgb_rgb_convert (j_compress_ptr cinfo, rgb_rgb_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
JDIMENSION output_row, int num_rows)
{ {
switch (cinfo->in_color_space) { switch (cinfo->in_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@ -376,11 +373,10 @@ rgb_rgb_convert (j_compress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
cmyk_ycck_convert (j_compress_ptr cinfo, cmyk_ycck_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
JDIMENSION output_row, int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int r, g, b; register int r, g, b;
register JLONG *ctab = cconvert->rgb_ycc_tab; register JLONG *ctab = cconvert->rgb_ycc_tab;
register JSAMPROW inptr; register JSAMPROW inptr;
@ -408,17 +404,14 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
* need the general RIGHT_SHIFT macro. * need the general RIGHT_SHIFT macro.
*/ */
/* Y */ /* Y */
outptr0[col] = (JSAMPLE) outptr0[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) ctab[b + B_Y_OFF]) >> SCALEBITS);
>> SCALEBITS);
/* Cb */ /* Cb */
outptr1[col] = (JSAMPLE) outptr1[col] = (JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF]) ctab[b + B_CB_OFF]) >> SCALEBITS);
>> SCALEBITS);
/* Cr */ /* Cr */
outptr2[col] = (JSAMPLE) outptr2[col] = (JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) ctab[b + B_CR_OFF]) >> SCALEBITS);
>> SCALEBITS);
} }
} }
} }
@ -431,9 +424,8 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
grayscale_convert (j_compress_ptr cinfo, grayscale_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
JDIMENSION output_row, int num_rows)
{ {
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr; register JSAMPROW outptr;
@ -460,8 +452,7 @@ grayscale_convert (j_compress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
null_convert (j_compress_ptr cinfo, null_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
register JSAMPROW inptr; register JSAMPROW inptr;
@ -522,7 +513,7 @@ null_convert (j_compress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
null_method (j_compress_ptr cinfo) null_method(j_compress_ptr cinfo)
{ {
/* no work needed */ /* no work needed */
} }
@ -533,14 +524,14 @@ null_method (j_compress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_color_converter (j_compress_ptr cinfo) jinit_color_converter(j_compress_ptr cinfo)
{ {
my_cconvert_ptr cconvert; my_cconvert_ptr cconvert;
cconvert = (my_cconvert_ptr) cconvert = (my_cconvert_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_color_converter)); sizeof(my_color_converter));
cinfo->cconvert = (struct jpeg_color_converter *) cconvert; cinfo->cconvert = (struct jpeg_color_converter *)cconvert;
/* set start_pass to null method until we find out differently */ /* set start_pass to null method until we find out differently */
cconvert->pub.start_pass = null_method; cconvert->pub.start_pass = null_method;

View File

@ -41,7 +41,7 @@ typedef void (*float_quantize_method_ptr) (JCOEFPTR coef_block,
FAST_FLOAT *divisors, FAST_FLOAT *divisors,
FAST_FLOAT *workspace); FAST_FLOAT *workspace);
METHODDEF(void) quantize (JCOEFPTR, DCTELEM *, DCTELEM *); METHODDEF(void) quantize(JCOEFPTR, DCTELEM *, DCTELEM *);
typedef struct { typedef struct {
struct jpeg_forward_dct pub; /* public fields */ struct jpeg_forward_dct pub; /* public fields */
@ -80,7 +80,7 @@ typedef my_fdct_controller *my_fdct_ptr;
*/ */
LOCAL(int) LOCAL(int)
flss (UINT16 val) flss(UINT16 val)
{ {
int bit; int bit;
@ -170,7 +170,7 @@ flss (UINT16 val)
*/ */
LOCAL(int) LOCAL(int)
compute_reciprocal (UINT16 divisor, DCTELEM *dtbl) compute_reciprocal(UINT16 divisor, DCTELEM *dtbl)
{ {
UDCTELEM2 fq, fr; UDCTELEM2 fq, fr;
UDCTELEM c; UDCTELEM c;
@ -182,10 +182,10 @@ compute_reciprocal (UINT16 divisor, DCTELEM *dtbl)
* identity function. Since only the C quantization algorithm is used in * identity function. Since only the C quantization algorithm is used in
* these cases, the scale value is irrelevant. * these cases, the scale value is irrelevant.
*/ */
dtbl[DCTSIZE2 * 0] = (DCTELEM) 1; /* reciprocal */ dtbl[DCTSIZE2 * 0] = (DCTELEM)1; /* reciprocal */
dtbl[DCTSIZE2 * 1] = (DCTELEM) 0; /* correction */ dtbl[DCTSIZE2 * 1] = (DCTELEM)0; /* correction */
dtbl[DCTSIZE2 * 2] = (DCTELEM) 1; /* scale */ dtbl[DCTSIZE2 * 2] = (DCTELEM)1; /* scale */
dtbl[DCTSIZE2 * 3] = -(DCTELEM) (sizeof(DCTELEM) * 8); /* shift */ dtbl[DCTSIZE2 * 3] = -(DCTELEM)(sizeof(DCTELEM) * 8); /* shift */
return 0; return 0;
} }
@ -207,14 +207,14 @@ compute_reciprocal (UINT16 divisor, DCTELEM *dtbl)
fq++; fq++;
} }
dtbl[DCTSIZE2 * 0] = (DCTELEM) fq; /* reciprocal */ dtbl[DCTSIZE2 * 0] = (DCTELEM)fq; /* reciprocal */
dtbl[DCTSIZE2 * 1] = (DCTELEM) c; /* correction + roundfactor */ dtbl[DCTSIZE2 * 1] = (DCTELEM)c; /* correction + roundfactor */
#ifdef WITH_SIMD #ifdef WITH_SIMD
dtbl[DCTSIZE2 * 2] = (DCTELEM) (1 << (sizeof(DCTELEM)*8*2 - r)); /* scale */ dtbl[DCTSIZE2 * 2] = (DCTELEM)(1 << (sizeof(DCTELEM) * 8 * 2 - r)); /* scale */
#else #else
dtbl[DCTSIZE2 * 2] = 1; dtbl[DCTSIZE2 * 2] = 1;
#endif #endif
dtbl[DCTSIZE2 * 3] = (DCTELEM) r - sizeof(DCTELEM)*8; /* shift */ dtbl[DCTSIZE2 * 3] = (DCTELEM)r - sizeof(DCTELEM) * 8; /* shift */
if (r <= 16) return 0; if (r <= 16) return 0;
else return 1; else return 1;
@ -233,9 +233,9 @@ compute_reciprocal (UINT16 divisor, DCTELEM *dtbl)
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_fdctmgr (j_compress_ptr cinfo) start_pass_fdctmgr(j_compress_ptr cinfo)
{ {
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; my_fdct_ptr fdct = (my_fdct_ptr)cinfo->fdct;
int ci, qtblno, i; int ci, qtblno, i;
jpeg_component_info *compptr; jpeg_component_info *compptr;
JQUANT_TBL *qtbl; JQUANT_TBL *qtbl;
@ -259,7 +259,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
*/ */
if (fdct->divisors[qtblno] == NULL) { if (fdct->divisors[qtblno] == NULL) {
fdct->divisors[qtblno] = (DCTELEM *) fdct->divisors[qtblno] = (DCTELEM *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(DCTSIZE2 * 4) * sizeof(DCTELEM)); (DCTSIZE2 * 4) * sizeof(DCTELEM));
} }
dtbl = fdct->divisors[qtblno]; dtbl = fdct->divisors[qtblno];
@ -269,7 +269,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
fdct->quantize == jsimd_quantize) fdct->quantize == jsimd_quantize)
fdct->quantize = quantize; fdct->quantize = quantize;
#else #else
dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3; dtbl[i] = ((DCTELEM)qtbl->quantval[i]) << 3;
#endif #endif
} }
break; break;
@ -299,23 +299,23 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
if (fdct->divisors[qtblno] == NULL) { if (fdct->divisors[qtblno] == NULL) {
fdct->divisors[qtblno] = (DCTELEM *) fdct->divisors[qtblno] = (DCTELEM *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(DCTSIZE2 * 4) * sizeof(DCTELEM)); (DCTSIZE2 * 4) * sizeof(DCTELEM));
} }
dtbl = fdct->divisors[qtblno]; dtbl = fdct->divisors[qtblno];
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
#if BITS_IN_JSAMPLE == 8 #if BITS_IN_JSAMPLE == 8
if (!compute_reciprocal( if (!compute_reciprocal(
DESCALE(MULTIPLY16V16((JLONG) qtbl->quantval[i], DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
(JLONG) aanscales[i]), (JLONG)aanscales[i]),
CONST_BITS-3), &dtbl[i]) && CONST_BITS - 3), &dtbl[i]) &&
fdct->quantize == jsimd_quantize) fdct->quantize == jsimd_quantize)
fdct->quantize = quantize; fdct->quantize = quantize;
#else #else
dtbl[i] = (DCTELEM) dtbl[i] = (DCTELEM)
DESCALE(MULTIPLY16V16((JLONG) qtbl->quantval[i], DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
(JLONG) aanscales[i]), (JLONG)aanscales[i]),
CONST_BITS-3); CONST_BITS - 3);
#endif #endif
} }
} }
@ -341,7 +341,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
if (fdct->float_divisors[qtblno] == NULL) { if (fdct->float_divisors[qtblno] == NULL) {
fdct->float_divisors[qtblno] = (FAST_FLOAT *) fdct->float_divisors[qtblno] = (FAST_FLOAT *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
DCTSIZE2 * sizeof(FAST_FLOAT)); DCTSIZE2 * sizeof(FAST_FLOAT));
} }
fdtbl = fdct->float_divisors[qtblno]; fdtbl = fdct->float_divisors[qtblno];
@ -349,7 +349,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
for (row = 0; row < DCTSIZE; row++) { for (row = 0; row < DCTSIZE; row++) {
for (col = 0; col < DCTSIZE; col++) { for (col = 0; col < DCTSIZE; col++) {
fdtbl[i] = (FAST_FLOAT) fdtbl[i] = (FAST_FLOAT)
(1.0 / (((double) qtbl->quantval[i] * (1.0 / (((double)qtbl->quantval[i] *
aanscalefactor[row] * aanscalefactor[col] * 8.0))); aanscalefactor[row] * aanscalefactor[col] * 8.0)));
i++; i++;
} }
@ -370,7 +370,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
convsamp (JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM *workspace) convsamp(JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM *workspace)
{ {
register DCTELEM *workspaceptr; register DCTELEM *workspaceptr;
register JSAMPROW elemptr; register JSAMPROW elemptr;
@ -405,7 +405,7 @@ convsamp (JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM *workspace)
*/ */
METHODDEF(void) METHODDEF(void)
quantize (JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace) quantize(JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
{ {
int i; int i;
DCTELEM temp; DCTELEM temp;
@ -426,15 +426,15 @@ quantize (JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
if (temp < 0) { if (temp < 0) {
temp = -temp; temp = -temp;
product = (UDCTELEM2)(temp + corr) * recip; product = (UDCTELEM2)(temp + corr) * recip;
product >>= shift + sizeof(DCTELEM)*8; product >>= shift + sizeof(DCTELEM) * 8;
temp = (DCTELEM)product; temp = (DCTELEM)product;
temp = -temp; temp = -temp;
} else { } else {
product = (UDCTELEM2)(temp + corr) * recip; product = (UDCTELEM2)(temp + corr) * recip;
product >>= shift + sizeof(DCTELEM)*8; product >>= shift + sizeof(DCTELEM) * 8;
temp = (DCTELEM)product; temp = (DCTELEM)product;
} }
output_ptr[i] = (JCOEF) temp; output_ptr[i] = (JCOEF)temp;
} }
#else #else
@ -457,20 +457,20 @@ quantize (JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
* If your machine's division is fast enough, define FAST_DIVIDE. * If your machine's division is fast enough, define FAST_DIVIDE.
*/ */
#ifdef FAST_DIVIDE #ifdef FAST_DIVIDE
#define DIVIDE_BY(a,b) a /= b #define DIVIDE_BY(a, b) a /= b
#else #else
#define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0 #define DIVIDE_BY(a, b) if (a >= b) a /= b; else a = 0
#endif #endif
if (temp < 0) { if (temp < 0) {
temp = -temp; temp = -temp;
temp += qval>>1; /* for rounding */ temp += qval >> 1; /* for rounding */
DIVIDE_BY(temp, qval); DIVIDE_BY(temp, qval);
temp = -temp; temp = -temp;
} else { } else {
temp += qval>>1; /* for rounding */ temp += qval >> 1; /* for rounding */
DIVIDE_BY(temp, qval); DIVIDE_BY(temp, qval);
} }
output_ptr[i] = (JCOEF) temp; output_ptr[i] = (JCOEF)temp;
} }
#endif #endif
@ -487,14 +487,13 @@ quantize (JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
*/ */
METHODDEF(void) METHODDEF(void)
forward_DCT (j_compress_ptr cinfo, jpeg_component_info *compptr, forward_DCT(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY sample_data, JBLOCKROW coef_blocks, JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
JDIMENSION start_row, JDIMENSION start_col, JDIMENSION start_row, JDIMENSION start_col, JDIMENSION num_blocks)
JDIMENSION num_blocks)
/* This version is used for integer DCT implementations. */ /* This version is used for integer DCT implementations. */
{ {
/* This routine is heavily used, so it's worth coding it tightly. */ /* This routine is heavily used, so it's worth coding it tightly. */
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; my_fdct_ptr fdct = (my_fdct_ptr)cinfo->fdct;
DCTELEM *divisors = fdct->divisors[compptr->quant_tbl_no]; DCTELEM *divisors = fdct->divisors[compptr->quant_tbl_no];
DCTELEM *workspace; DCTELEM *workspace;
JDIMENSION bi; JDIMENSION bi;
@ -522,9 +521,9 @@ forward_DCT (j_compress_ptr cinfo, jpeg_component_info *compptr,
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
METHODDEF(void) METHODDEF(void)
convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col, FAST_FLOAT *workspace) convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
FAST_FLOAT *workspace)
{ {
register FAST_FLOAT *workspaceptr; register FAST_FLOAT *workspaceptr;
register JSAMPROW elemptr; register JSAMPROW elemptr;
@ -555,7 +554,8 @@ convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col, FAST_FLOAT *worksp
METHODDEF(void) METHODDEF(void)
quantize_float (JCOEFPTR coef_block, FAST_FLOAT *divisors, FAST_FLOAT *workspace) quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
FAST_FLOAT *workspace)
{ {
register FAST_FLOAT temp; register FAST_FLOAT temp;
register int i; register int i;
@ -571,20 +571,20 @@ quantize_float (JCOEFPTR coef_block, FAST_FLOAT *divisors, FAST_FLOAT *workspace
* The maximum coefficient size is +-16K (for 12-bit data), so this * The maximum coefficient size is +-16K (for 12-bit data), so this
* code should work for either 16-bit or 32-bit ints. * code should work for either 16-bit or 32-bit ints.
*/ */
output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384); output_ptr[i] = (JCOEF)((int)(temp + (FAST_FLOAT)16384.5) - 16384);
} }
} }
METHODDEF(void) METHODDEF(void)
forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info *compptr, forward_DCT_float(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY sample_data, JBLOCKROW coef_blocks, JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
JDIMENSION start_row, JDIMENSION start_col, JDIMENSION start_row, JDIMENSION start_col,
JDIMENSION num_blocks) JDIMENSION num_blocks)
/* This version is used for floating-point DCT implementations. */ /* This version is used for floating-point DCT implementations. */
{ {
/* This routine is heavily used, so it's worth coding it tightly. */ /* This routine is heavily used, so it's worth coding it tightly. */
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; my_fdct_ptr fdct = (my_fdct_ptr)cinfo->fdct;
FAST_FLOAT *divisors = fdct->float_divisors[compptr->quant_tbl_no]; FAST_FLOAT *divisors = fdct->float_divisors[compptr->quant_tbl_no];
FAST_FLOAT *workspace; FAST_FLOAT *workspace;
JDIMENSION bi; JDIMENSION bi;
@ -618,15 +618,15 @@ forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info *compptr,
*/ */
GLOBAL(void) GLOBAL(void)
jinit_forward_dct (j_compress_ptr cinfo) jinit_forward_dct(j_compress_ptr cinfo)
{ {
my_fdct_ptr fdct; my_fdct_ptr fdct;
int i; int i;
fdct = (my_fdct_ptr) fdct = (my_fdct_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_fdct_controller)); sizeof(my_fdct_controller));
cinfo->fdct = (struct jpeg_forward_dct *) fdct; cinfo->fdct = (struct jpeg_forward_dct *)fdct;
fdct->pub.start_pass = start_pass_fdctmgr; fdct->pub.start_pass = start_pass_fdctmgr;
/* First determine the DCT... */ /* First determine the DCT... */
@ -703,12 +703,12 @@ jinit_forward_dct (j_compress_ptr cinfo)
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
if (cinfo->dct_method == JDCT_FLOAT) if (cinfo->dct_method == JDCT_FLOAT)
fdct->float_workspace = (FAST_FLOAT *) fdct->float_workspace = (FAST_FLOAT *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(FAST_FLOAT) * DCTSIZE2); sizeof(FAST_FLOAT) * DCTSIZE2);
else else
#endif #endif
fdct->workspace = (DCTELEM *) fdct->workspace = (DCTELEM *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(DCTELEM) * DCTSIZE2); sizeof(DCTELEM) * DCTSIZE2);
/* Mark divisor tables unallocated */ /* Mark divisor tables unallocated */

View File

@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009-2011, 2014-2016, D. R. Commander. * Copyright (C) 2009-2011, 2014-2016, 2018, D. R. Commander.
* Copyright (C) 2015, Matthieu Darbois. * Copyright (C) 2015, Matthieu Darbois.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
@ -16,6 +16,9 @@
* back up to the start of the current MCU. To do this, we copy state * back up to the start of the current MCU. To do this, we copy state
* variables into local working storage, and update them back to the * variables into local working storage, and update them back to the
* permanent JPEG objects only upon successful completion of an MCU. * permanent JPEG objects only upon successful completion of an MCU.
*
* NOTE: All referenced figures are from
* Recommendation ITU-T T.81 (1992) | ISO/IEC 10918-1:1994.
*/ */
#define JPEG_INTERNALS #define JPEG_INTERNALS
@ -55,10 +58,6 @@
#define JPEG_NBITS_NONZERO(x) JPEG_NBITS(x) #define JPEG_NBITS_NONZERO(x) JPEG_NBITS(x)
#endif #endif
#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#endif
/* Expanded entropy encoder object for Huffman encoding. /* Expanded entropy encoder object for Huffman encoding.
* *
@ -78,10 +77,10 @@ typedef struct {
*/ */
#ifndef NO_STRUCT_ASSIGN #ifndef NO_STRUCT_ASSIGN
#define ASSIGN_STATE(dest,src) ((dest) = (src)) #define ASSIGN_STATE(dest, src) ((dest) = (src))
#else #else
#if MAX_COMPS_IN_SCAN == 4 #if MAX_COMPS_IN_SCAN == 4
#define ASSIGN_STATE(dest,src) \ #define ASSIGN_STATE(dest, src) \
((dest).put_buffer = (src).put_buffer, \ ((dest).put_buffer = (src).put_buffer, \
(dest).put_bits = (src).put_bits, \ (dest).put_bits = (src).put_bits, \
(dest).last_dc_val[0] = (src).last_dc_val[0], \ (dest).last_dc_val[0] = (src).last_dc_val[0], \
@ -128,12 +127,12 @@ typedef struct {
/* Forward declarations */ /* Forward declarations */
METHODDEF(boolean) encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data); METHODDEF(boolean) encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data);
METHODDEF(void) finish_pass_huff (j_compress_ptr cinfo); METHODDEF(void) finish_pass_huff(j_compress_ptr cinfo);
#ifdef ENTROPY_OPT_SUPPORTED #ifdef ENTROPY_OPT_SUPPORTED
METHODDEF(boolean) encode_mcu_gather (j_compress_ptr cinfo, METHODDEF(boolean) encode_mcu_gather(j_compress_ptr cinfo,
JBLOCKROW *MCU_data); JBLOCKROW *MCU_data);
METHODDEF(void) finish_pass_gather (j_compress_ptr cinfo); METHODDEF(void) finish_pass_gather(j_compress_ptr cinfo);
#endif #endif
@ -144,9 +143,9 @@ METHODDEF(void) finish_pass_gather (j_compress_ptr cinfo);
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics) start_pass_huff(j_compress_ptr cinfo, boolean gather_statistics)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
int ci, dctbl, actbl; int ci, dctbl, actbl;
jpeg_component_info *compptr; jpeg_component_info *compptr;
@ -180,12 +179,12 @@ start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
/* Note that jpeg_gen_optimal_table expects 257 entries in each table! */ /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
if (entropy->dc_count_ptrs[dctbl] == NULL) if (entropy->dc_count_ptrs[dctbl] == NULL)
entropy->dc_count_ptrs[dctbl] = (long *) entropy->dc_count_ptrs[dctbl] = (long *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
257 * sizeof(long)); 257 * sizeof(long));
MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * sizeof(long)); MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * sizeof(long));
if (entropy->ac_count_ptrs[actbl] == NULL) if (entropy->ac_count_ptrs[actbl] == NULL)
entropy->ac_count_ptrs[actbl] = (long *) entropy->ac_count_ptrs[actbl] = (long *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
257 * sizeof(long)); 257 * sizeof(long));
MEMZERO(entropy->ac_count_ptrs[actbl], 257 * sizeof(long)); MEMZERO(entropy->ac_count_ptrs[actbl], 257 * sizeof(long));
#endif #endif
@ -193,9 +192,9 @@ start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
/* Compute derived values for Huffman tables */ /* Compute derived values for Huffman tables */
/* We may do this more than once for a table, but it's not expensive */ /* We may do this more than once for a table, but it's not expensive */
jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl, jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
& entropy->dc_derived_tbls[dctbl]); &entropy->dc_derived_tbls[dctbl]);
jpeg_make_c_derived_tbl(cinfo, FALSE, actbl, jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
& entropy->ac_derived_tbls[actbl]); &entropy->ac_derived_tbls[actbl]);
} }
/* Initialize DC predictions to 0 */ /* Initialize DC predictions to 0 */
entropy->saved.last_dc_val[ci] = 0; entropy->saved.last_dc_val[ci] = 0;
@ -219,7 +218,7 @@ start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno, jpeg_make_c_derived_tbl(j_compress_ptr cinfo, boolean isDC, int tblno,
c_derived_tbl **pdtbl) c_derived_tbl **pdtbl)
{ {
JHUFF_TBL *htbl; JHUFF_TBL *htbl;
@ -244,7 +243,7 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
/* Allocate a workspace if we haven't already done so. */ /* Allocate a workspace if we haven't already done so. */
if (*pdtbl == NULL) if (*pdtbl == NULL)
*pdtbl = (c_derived_tbl *) *pdtbl = (c_derived_tbl *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(c_derived_tbl)); sizeof(c_derived_tbl));
dtbl = *pdtbl; dtbl = *pdtbl;
@ -252,11 +251,11 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
p = 0; p = 0;
for (l = 1; l <= 16; l++) { for (l = 1; l <= 16; l++) {
i = (int) htbl->bits[l]; i = (int)htbl->bits[l];
if (i < 0 || p + i > 256) /* protect against table overrun */ if (i < 0 || p + i > 256) /* protect against table overrun */
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
while (i--) while (i--)
huffsize[p++] = (char) l; huffsize[p++] = (char)l;
} }
huffsize[p] = 0; huffsize[p] = 0;
lastp = p; lastp = p;
@ -268,14 +267,14 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
si = huffsize[0]; si = huffsize[0];
p = 0; p = 0;
while (huffsize[p]) { while (huffsize[p]) {
while (((int) huffsize[p]) == si) { while (((int)huffsize[p]) == si) {
huffcode[p++] = code; huffcode[p++] = code;
code++; code++;
} }
/* code is now 1 more than the last code used for codelength si; but /* code is now 1 more than the last code used for codelength si; but
* it must still fit in si bits, since no code is allowed to be all ones. * it must still fit in si bits, since no code is allowed to be all ones.
*/ */
if (((JLONG) code) >= (((JLONG) 1) << si)) if (((JLONG)code) >= (((JLONG)1) << si))
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
code <<= 1; code <<= 1;
si++; si++;
@ -310,20 +309,21 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
/* Outputting bytes to the file */ /* Outputting bytes to the file */
/* Emit a byte, taking 'action' if must suspend. */ /* Emit a byte, taking 'action' if must suspend. */
#define emit_byte(state,val,action) \ #define emit_byte(state, val, action) { \
{ *(state)->next_output_byte++ = (JOCTET) (val); \ *(state)->next_output_byte++ = (JOCTET)(val); \
if (--(state)->free_in_buffer == 0) \ if (--(state)->free_in_buffer == 0) \
if (! dump_buffer(state)) \ if (!dump_buffer(state)) \
{ action; } } { action; } \
}
LOCAL(boolean) LOCAL(boolean)
dump_buffer (working_state *state) dump_buffer(working_state *state)
/* Empty the output buffer; return TRUE if successful, FALSE if must suspend */ /* Empty the output buffer; return TRUE if successful, FALSE if must suspend */
{ {
struct jpeg_destination_mgr *dest = state->cinfo->dest; struct jpeg_destination_mgr *dest = state->cinfo->dest;
if (! (*dest->empty_output_buffer) (state->cinfo)) if (!(*dest->empty_output_buffer) (state->cinfo))
return FALSE; return FALSE;
/* After a successful buffer dump, must reset buffer pointers */ /* After a successful buffer dump, must reset buffer pointers */
state->next_output_byte = dest->next_output_byte; state->next_output_byte = dest->next_output_byte;
@ -349,7 +349,7 @@ dump_buffer (working_state *state)
*buffer++ = c; \ *buffer++ = c; \
if (c == 0xFF) /* need to stuff a zero byte? */ \ if (c == 0xFF) /* need to stuff a zero byte? */ \
*buffer++ = 0; \ *buffer++ = 0; \
} }
#define PUT_BITS(code, size) { \ #define PUT_BITS(code, size) { \
put_bits += size; \ put_bits += size; \
@ -387,7 +387,7 @@ dump_buffer (working_state *state)
#error Cannot determine word size #error Cannot determine word size
#endif #endif
#if SIZEOF_SIZE_T==8 || defined(_WIN64) #if SIZEOF_SIZE_T == 8 || defined(_WIN64)
#define EMIT_BITS(code, size) { \ #define EMIT_BITS(code, size) { \
CHECKBUF47() \ CHECKBUF47() \
@ -395,11 +395,11 @@ dump_buffer (working_state *state)
} }
#define EMIT_CODE(code, size) { \ #define EMIT_CODE(code, size) { \
temp2 &= (((JLONG) 1)<<nbits) - 1; \ temp2 &= (((JLONG)1) << nbits) - 1; \
CHECKBUF31() \ CHECKBUF31() \
PUT_BITS(code, size) \ PUT_BITS(code, size) \
PUT_BITS(temp2, nbits) \ PUT_BITS(temp2, nbits) \
} }
#else #else
@ -409,12 +409,12 @@ dump_buffer (working_state *state)
} }
#define EMIT_CODE(code, size) { \ #define EMIT_CODE(code, size) { \
temp2 &= (((JLONG) 1)<<nbits) - 1; \ temp2 &= (((JLONG)1) << nbits) - 1; \
PUT_BITS(code, size) \ PUT_BITS(code, size) \
CHECKBUF15() \ CHECKBUF15() \
PUT_BITS(temp2, nbits) \ PUT_BITS(temp2, nbits) \
CHECKBUF15() \ CHECKBUF15() \
} }
#endif #endif
@ -434,34 +434,33 @@ dump_buffer (working_state *state)
if (state->free_in_buffer < BUFSIZE) { \ if (state->free_in_buffer < BUFSIZE) { \
localbuf = 1; \ localbuf = 1; \
buffer = _buffer; \ buffer = _buffer; \
} \ } else \
else buffer = state->next_output_byte; \ buffer = state->next_output_byte; \
} }
#define STORE_BUFFER() { \ #define STORE_BUFFER() { \
if (localbuf) { \ if (localbuf) { \
bytes = buffer - _buffer; \ bytes = buffer - _buffer; \
buffer = _buffer; \ buffer = _buffer; \
while (bytes > 0) { \ while (bytes > 0) { \
bytestocopy = min(bytes, state->free_in_buffer); \ bytestocopy = MIN(bytes, state->free_in_buffer); \
MEMCOPY(state->next_output_byte, buffer, bytestocopy); \ MEMCOPY(state->next_output_byte, buffer, bytestocopy); \
state->next_output_byte += bytestocopy; \ state->next_output_byte += bytestocopy; \
buffer += bytestocopy; \ buffer += bytestocopy; \
state->free_in_buffer -= bytestocopy; \ state->free_in_buffer -= bytestocopy; \
if (state->free_in_buffer == 0) \ if (state->free_in_buffer == 0) \
if (! dump_buffer(state)) return FALSE; \ if (!dump_buffer(state)) return FALSE; \
bytes -= bytestocopy; \ bytes -= bytestocopy; \
} \ } \
} \ } else { \
else { \
state->free_in_buffer -= (buffer - state->next_output_byte); \ state->free_in_buffer -= (buffer - state->next_output_byte); \
state->next_output_byte = buffer; \ state->next_output_byte = buffer; \
} \ } \
} }
LOCAL(boolean) LOCAL(boolean)
flush_bits (working_state *state) flush_bits(working_state *state)
{ {
JOCTET _buffer[BUFSIZE], *buffer; JOCTET _buffer[BUFSIZE], *buffer;
size_t put_buffer; int put_bits; size_t put_buffer; int put_bits;
@ -486,7 +485,7 @@ flush_bits (working_state *state)
/* Encode a single block's worth of coefficients */ /* Encode a single block's worth of coefficients */
LOCAL(boolean) LOCAL(boolean)
encode_one_block_simd (working_state *state, JCOEFPTR block, int last_dc_val, encode_one_block_simd(working_state *state, JCOEFPTR block, int last_dc_val,
c_derived_tbl *dctbl, c_derived_tbl *actbl) c_derived_tbl *dctbl, c_derived_tbl *actbl)
{ {
JOCTET _buffer[BUFSIZE], *buffer; JOCTET _buffer[BUFSIZE], *buffer;
@ -503,7 +502,7 @@ encode_one_block_simd (working_state *state, JCOEFPTR block, int last_dc_val,
} }
LOCAL(boolean) LOCAL(boolean)
encode_one_block (working_state *state, JCOEFPTR block, int last_dc_val, encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val,
c_derived_tbl *dctbl, c_derived_tbl *actbl) c_derived_tbl *dctbl, c_derived_tbl *actbl)
{ {
int temp, temp2, temp3; int temp, temp2, temp3;
@ -544,7 +543,7 @@ encode_one_block (working_state *state, JCOEFPTR block, int last_dc_val,
EMIT_BITS(code, size) EMIT_BITS(code, size)
/* Mask off any extra bits in code */ /* Mask off any extra bits in code */
temp2 &= (((JLONG) 1)<<nbits) - 1; temp2 &= (((JLONG)1) << nbits) - 1;
/* Emit that number of bits of the value, if positive, */ /* Emit that number of bits of the value, if positive, */
/* or the complement of its magnitude, if negative. */ /* or the complement of its magnitude, if negative. */
@ -616,11 +615,11 @@ encode_one_block (working_state *state, JCOEFPTR block, int last_dc_val,
*/ */
LOCAL(boolean) LOCAL(boolean)
emit_restart (working_state *state, int restart_num) emit_restart(working_state *state, int restart_num)
{ {
int ci; int ci;
if (! flush_bits(state)) if (!flush_bits(state))
return FALSE; return FALSE;
emit_byte(state, 0xFF, return FALSE); emit_byte(state, 0xFF, return FALSE);
@ -641,9 +640,9 @@ emit_restart (working_state *state, int restart_num)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
working_state state; working_state state;
int blkn, ci; int blkn, ci;
jpeg_component_info *compptr; jpeg_component_info *compptr;
@ -657,7 +656,7 @@ encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Emit restart marker if needed */ /* Emit restart marker if needed */
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
if (entropy->restarts_to_go == 0) if (entropy->restarts_to_go == 0)
if (! emit_restart(&state, entropy->next_restart_num)) if (!emit_restart(&state, entropy->next_restart_num))
return FALSE; return FALSE;
} }
@ -666,7 +665,7 @@ encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
ci = cinfo->MCU_membership[blkn]; ci = cinfo->MCU_membership[blkn];
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
if (! encode_one_block_simd(&state, if (!encode_one_block_simd(&state,
MCU_data[blkn][0], state.cur.last_dc_val[ci], MCU_data[blkn][0], state.cur.last_dc_val[ci],
entropy->dc_derived_tbls[compptr->dc_tbl_no], entropy->dc_derived_tbls[compptr->dc_tbl_no],
entropy->ac_derived_tbls[compptr->ac_tbl_no])) entropy->ac_derived_tbls[compptr->ac_tbl_no]))
@ -678,7 +677,7 @@ encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
ci = cinfo->MCU_membership[blkn]; ci = cinfo->MCU_membership[blkn];
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
if (! encode_one_block(&state, if (!encode_one_block(&state,
MCU_data[blkn][0], state.cur.last_dc_val[ci], MCU_data[blkn][0], state.cur.last_dc_val[ci],
entropy->dc_derived_tbls[compptr->dc_tbl_no], entropy->dc_derived_tbls[compptr->dc_tbl_no],
entropy->ac_derived_tbls[compptr->ac_tbl_no])) entropy->ac_derived_tbls[compptr->ac_tbl_no]))
@ -712,9 +711,9 @@ encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(void) METHODDEF(void)
finish_pass_huff (j_compress_ptr cinfo) finish_pass_huff(j_compress_ptr cinfo)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
working_state state; working_state state;
/* Load up working state ... flush_bits needs it */ /* Load up working state ... flush_bits needs it */
@ -724,7 +723,7 @@ finish_pass_huff (j_compress_ptr cinfo)
state.cinfo = cinfo; state.cinfo = cinfo;
/* Flush out the last data */ /* Flush out the last data */
if (! flush_bits(&state)) if (!flush_bits(&state))
ERREXIT(cinfo, JERR_CANT_SUSPEND); ERREXIT(cinfo, JERR_CANT_SUSPEND);
/* Update state */ /* Update state */
@ -751,7 +750,7 @@ finish_pass_huff (j_compress_ptr cinfo)
/* Process a single block's worth of coefficients */ /* Process a single block's worth of coefficients */
LOCAL(void) LOCAL(void)
htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val, htest_one_block(j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
long dc_counts[], long ac_counts[]) long dc_counts[], long ac_counts[])
{ {
register int temp; register int temp;
@ -773,7 +772,7 @@ htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
/* Check for out-of-range coefficient values. /* Check for out-of-range coefficient values.
* Since we're encoding a difference, the range limit is twice as much. * Since we're encoding a difference, the range limit is twice as much.
*/ */
if (nbits > MAX_COEF_BITS+1) if (nbits > MAX_COEF_BITS + 1)
ERREXIT(cinfo, JERR_BAD_DCT_COEF); ERREXIT(cinfo, JERR_BAD_DCT_COEF);
/* Count the Huffman symbol for the number of bits */ /* Count the Huffman symbol for the number of bits */
@ -824,9 +823,9 @@ htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_gather(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
int blkn, ci; int blkn, ci;
jpeg_component_info *compptr; jpeg_component_info *compptr;
@ -863,13 +862,14 @@ encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
* one bits (so that padding bits added at the end of a compressed segment * one bits (so that padding bits added at the end of a compressed segment
* can't look like a valid code). Because of the canonical ordering of * can't look like a valid code). Because of the canonical ordering of
* codewords, this just means that there must be an unused slot in the * codewords, this just means that there must be an unused slot in the
* longest codeword length category. Section K.2 of the JPEG spec suggests * longest codeword length category. Annex K (Clause K.2) of
* reserving such a slot by pretending that symbol 256 is a valid symbol * Rec. ITU-T T.81 (1992) | ISO/IEC 10918-1:1994 suggests reserving such a slot
* with count 1. In theory that's not optimal; giving it count zero but * by pretending that symbol 256 is a valid symbol with count 1. In theory
* including it in the symbol set anyway should give a better Huffman code. * that's not optimal; giving it count zero but including it in the symbol set
* But the theoretically better code actually seems to come out worse in * anyway should give a better Huffman code. But the theoretically better code
* practice, because it produces more all-ones bytes (which incur stuffed * actually seems to come out worse in practice, because it produces more
* zero bytes in the final file). In any case the difference is tiny. * all-ones bytes (which incur stuffed zero bytes in the final file). In any
* case the difference is tiny.
* *
* The JPEG standard requires Huffman codes to be no more than 16 bits long. * The JPEG standard requires Huffman codes to be no more than 16 bits long.
* If some symbols have a very small but nonzero probability, the Huffman tree * If some symbols have a very small but nonzero probability, the Huffman tree
@ -884,10 +884,10 @@ encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[]) jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
{ {
#define MAX_CLEN 32 /* assumed maximum initial code length */ #define MAX_CLEN 32 /* assumed maximum initial code length */
UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */ UINT8 bits[MAX_CLEN + 1]; /* bits[k] = # of symbols with code length k */
int codesize[257]; /* codesize[k] = code length of symbol k */ int codesize[257]; /* codesize[k] = code length of symbol k */
int others[257]; /* next symbol in current branch of tree */ int others[257]; /* next symbol in current branch of tree */
int c1, c2; int c1, c2;
@ -971,13 +971,13 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
/* JPEG doesn't allow symbols with code lengths over 16 bits, so if the pure /* JPEG doesn't allow symbols with code lengths over 16 bits, so if the pure
* Huffman procedure assigned any such lengths, we must adjust the coding. * Huffman procedure assigned any such lengths, we must adjust the coding.
* Here is what the JPEG spec says about how this next bit works: * Here is what Rec. ITU-T T.81 | ISO/IEC 10918-1 says about how this next
* Since symbols are paired for the longest Huffman code, the symbols are * bit works: Since symbols are paired for the longest Huffman code, the
* removed from this length category two at a time. The prefix for the pair * symbols are removed from this length category two at a time. The prefix
* (which is one bit shorter) is allocated to one of the pair; then, * for the pair (which is one bit shorter) is allocated to one of the pair;
* skipping the BITS entry for that prefix length, a code word from the next * then, skipping the BITS entry for that prefix length, a code word from the
* shortest nonzero BITS entry is converted into a prefix for two code words * next shortest nonzero BITS entry is converted into a prefix for two code
* one bit longer. * words one bit longer.
*/ */
for (i = MAX_CLEN; i > 16; i--) { for (i = MAX_CLEN; i > 16; i--) {
@ -987,8 +987,8 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
j--; j--;
bits[i] -= 2; /* remove two symbols */ bits[i] -= 2; /* remove two symbols */
bits[i-1]++; /* one goes in this length */ bits[i - 1]++; /* one goes in this length */
bits[j+1] += 2; /* two new symbols in this length */ bits[j + 1] += 2; /* two new symbols in this length */
bits[j]--; /* symbol of this length is now a prefix */ bits[j]--; /* symbol of this length is now a prefix */
} }
} }
@ -1003,13 +1003,14 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
/* Return a list of the symbols sorted by code length */ /* Return a list of the symbols sorted by code length */
/* It's not real clear to me why we don't need to consider the codelength /* It's not real clear to me why we don't need to consider the codelength
* changes made above, but the JPEG spec seems to think this works. * changes made above, but Rec. ITU-T T.81 | ISO/IEC 10918-1 seems to think
* this works.
*/ */
p = 0; p = 0;
for (i = 1; i <= MAX_CLEN; i++) { for (i = 1; i <= MAX_CLEN; i++) {
for (j = 0; j <= 255; j++) { for (j = 0; j <= 255; j++) {
if (codesize[j] == i) { if (codesize[j] == i) {
htbl->huffval[p] = (UINT8) j; htbl->huffval[p] = (UINT8)j;
p++; p++;
} }
} }
@ -1025,9 +1026,9 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
*/ */
METHODDEF(void) METHODDEF(void)
finish_pass_gather (j_compress_ptr cinfo) finish_pass_gather(j_compress_ptr cinfo)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
int ci, dctbl, actbl; int ci, dctbl, actbl;
jpeg_component_info *compptr; jpeg_component_info *compptr;
JHUFF_TBL **htblptr; JHUFF_TBL **htblptr;
@ -1044,17 +1045,17 @@ finish_pass_gather (j_compress_ptr cinfo)
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
dctbl = compptr->dc_tbl_no; dctbl = compptr->dc_tbl_no;
actbl = compptr->ac_tbl_no; actbl = compptr->ac_tbl_no;
if (! did_dc[dctbl]) { if (!did_dc[dctbl]) {
htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl]; htblptr = &cinfo->dc_huff_tbl_ptrs[dctbl];
if (*htblptr == NULL) if (*htblptr == NULL)
*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); *htblptr = jpeg_alloc_huff_table((j_common_ptr)cinfo);
jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]); jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
did_dc[dctbl] = TRUE; did_dc[dctbl] = TRUE;
} }
if (! did_ac[actbl]) { if (!did_ac[actbl]) {
htblptr = & cinfo->ac_huff_tbl_ptrs[actbl]; htblptr = &cinfo->ac_huff_tbl_ptrs[actbl];
if (*htblptr == NULL) if (*htblptr == NULL)
*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); *htblptr = jpeg_alloc_huff_table((j_common_ptr)cinfo);
jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]); jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
did_ac[actbl] = TRUE; did_ac[actbl] = TRUE;
} }
@ -1070,15 +1071,15 @@ finish_pass_gather (j_compress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_huff_encoder (j_compress_ptr cinfo) jinit_huff_encoder(j_compress_ptr cinfo)
{ {
huff_entropy_ptr entropy; huff_entropy_ptr entropy;
int i; int i;
entropy = (huff_entropy_ptr) entropy = (huff_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(huff_entropy_encoder)); sizeof(huff_entropy_encoder));
cinfo->entropy = (struct jpeg_entropy_encoder *) entropy; cinfo->entropy = (struct jpeg_entropy_encoder *)entropy;
entropy->pub.start_pass = start_pass_huff; entropy->pub.start_pass = start_pass_huff;
/* Mark tables unallocated */ /* Mark tables unallocated */

View File

@ -34,10 +34,9 @@ typedef struct {
} c_derived_tbl; } c_derived_tbl;
/* Expand a Huffman table definition into the derived format */ /* Expand a Huffman table definition into the derived format */
EXTERN(void) jpeg_make_c_derived_tbl EXTERN(void) jpeg_make_c_derived_tbl(j_compress_ptr cinfo, boolean isDC,
(j_compress_ptr cinfo, boolean isDC, int tblno, int tblno, c_derived_tbl **pdtbl);
c_derived_tbl ** pdtbl);
/* Generate an optimal table definition given the specified counts */ /* Generate an optimal table definition given the specified counts */
EXTERN(void) jpeg_gen_optimal_table EXTERN(void) jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl,
(j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[]); long freq[]);

View File

@ -28,13 +28,13 @@
*/ */
GLOBAL(void) GLOBAL(void)
jinit_compress_master (j_compress_ptr cinfo) jinit_compress_master(j_compress_ptr 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 */);
/* Preprocessing */ /* Preprocessing */
if (! cinfo->raw_data_in) { if (!cinfo->raw_data_in) {
jinit_color_converter(cinfo); jinit_color_converter(cinfo);
jinit_downsampler(cinfo); jinit_downsampler(cinfo);
jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */); jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
@ -60,14 +60,14 @@ jinit_compress_master (j_compress_ptr cinfo)
} }
/* Need a full-image coefficient buffer in any multi-pass mode. */ /* Need a full-image coefficient buffer in any multi-pass mode. */
jinit_c_coef_controller(cinfo, jinit_c_coef_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
(boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding)); cinfo->optimize_coding));
jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */); jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
jinit_marker_writer(cinfo); jinit_marker_writer(cinfo);
/* We can now tell the memory manager to allocate virtual arrays. */ /* We can now tell the memory manager to allocate virtual arrays. */
(*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); (*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo);
/* Write the datastream header (SOI) immediately. /* Write the datastream header (SOI) immediately.
* Frame and scan headers are postponed till later. * Frame and scan headers are postponed till later.

View File

@ -39,8 +39,9 @@ typedef my_main_controller *my_main_ptr;
/* Forward declarations */ /* Forward declarations */
METHODDEF(void) process_data_simple_main METHODDEF(void) process_data_simple_main(j_compress_ptr cinfo,
(j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JSAMPARRAY input_buf,
JDIMENSION *in_row_ctr,
JDIMENSION in_rows_avail); JDIMENSION in_rows_avail);
@ -49,9 +50,9 @@ METHODDEF(void) process_data_simple_main
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode) start_pass_main(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
{ {
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
/* Do nothing in raw-data mode. */ /* Do nothing in raw-data mode. */
if (cinfo->raw_data_in) if (cinfo->raw_data_in)
@ -75,19 +76,18 @@ start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
*/ */
METHODDEF(void) METHODDEF(void)
process_data_simple_main (j_compress_ptr cinfo, process_data_simple_main(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail)
JDIMENSION in_rows_avail)
{ {
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
while (main_ptr->cur_iMCU_row < cinfo->total_iMCU_rows) { while (main_ptr->cur_iMCU_row < cinfo->total_iMCU_rows) {
/* 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 (main_ptr->rowgroup_ctr < DCTSIZE) if (main_ptr->rowgroup_ctr < DCTSIZE)
(*cinfo->prep->pre_process_data) (cinfo, (*cinfo->prep->pre_process_data) (cinfo, input_buf, in_row_ctr,
input_buf, in_row_ctr, in_rows_avail, in_rows_avail, main_ptr->buffer,
main_ptr->buffer, &main_ptr->rowgroup_ctr, &main_ptr->rowgroup_ctr,
(JDIMENSION) DCTSIZE); (JDIMENSION)DCTSIZE);
/* If we don't have a full iMCU row buffered, return to application for /* If we don't have a full iMCU row buffered, return to application for
* more data. Note that preprocessor will always pad to fill the iMCU row * more data. Note that preprocessor will always pad to fill the iMCU row
@ -97,14 +97,14 @@ process_data_simple_main (j_compress_ptr cinfo,
return; return;
/* Send the completed row to the compressor */ /* Send the completed row to the compressor */
if (! (*cinfo->coef->compress_data) (cinfo, main_ptr->buffer)) { if (!(*cinfo->coef->compress_data) (cinfo, main_ptr->buffer)) {
/* If compressor did not consume the whole row, then we must need to /* If compressor did not consume the whole row, then we must need to
* suspend processing and return to the application. In this situation * suspend processing and return to the application. In this situation
* we pretend we didn't yet consume the last input row; otherwise, if * we pretend we didn't yet consume the last input row; otherwise, if
* it happened to be the last row of the image, the application would * it happened to be the last row of the image, the application would
* think we were done. * think we were done.
*/ */
if (! main_ptr->suspended) { if (!main_ptr->suspended) {
(*in_row_ctr)--; (*in_row_ctr)--;
main_ptr->suspended = TRUE; main_ptr->suspended = TRUE;
} }
@ -128,16 +128,16 @@ process_data_simple_main (j_compress_ptr cinfo,
*/ */
GLOBAL(void) GLOBAL(void)
jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer) jinit_c_main_controller(j_compress_ptr cinfo, boolean need_full_buffer)
{ {
my_main_ptr main_ptr; my_main_ptr main_ptr;
int ci; int ci;
jpeg_component_info *compptr; jpeg_component_info *compptr;
main_ptr = (my_main_ptr) main_ptr = (my_main_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_main_controller)); sizeof(my_main_controller));
cinfo->main = (struct jpeg_c_main_controller *) main_ptr; cinfo->main = (struct jpeg_c_main_controller *)main_ptr;
main_ptr->pub.start_pass = start_pass_main; main_ptr->pub.start_pass = start_pass_main;
/* We don't need to create a buffer in raw-data mode. */ /* We don't need to create a buffer in raw-data mode. */
@ -154,9 +154,9 @@ jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray) main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr)cinfo, JPOOL_IMAGE,
compptr->width_in_blocks * DCTSIZE, compptr->width_in_blocks * DCTSIZE,
(JDIMENSION) (compptr->v_samp_factor * DCTSIZE)); (JDIMENSION)(compptr->v_samp_factor * DCTSIZE));
} }
} }
} }

View File

@ -110,30 +110,30 @@ typedef my_marker_writer *my_marker_ptr;
*/ */
LOCAL(void) LOCAL(void)
emit_byte (j_compress_ptr cinfo, int val) emit_byte(j_compress_ptr cinfo, int val)
/* Emit a byte */ /* Emit a byte */
{ {
struct jpeg_destination_mgr *dest = cinfo->dest; struct jpeg_destination_mgr *dest = cinfo->dest;
*(dest->next_output_byte)++ = (JOCTET) val; *(dest->next_output_byte)++ = (JOCTET)val;
if (--dest->free_in_buffer == 0) { if (--dest->free_in_buffer == 0) {
if (! (*dest->empty_output_buffer) (cinfo)) if (!(*dest->empty_output_buffer) (cinfo))
ERREXIT(cinfo, JERR_CANT_SUSPEND); ERREXIT(cinfo, JERR_CANT_SUSPEND);
} }
} }
LOCAL(void) LOCAL(void)
emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark) emit_marker(j_compress_ptr cinfo, JPEG_MARKER mark)
/* Emit a marker code */ /* Emit a marker code */
{ {
emit_byte(cinfo, 0xFF); emit_byte(cinfo, 0xFF);
emit_byte(cinfo, (int) mark); emit_byte(cinfo, (int)mark);
} }
LOCAL(void) LOCAL(void)
emit_2bytes (j_compress_ptr cinfo, int value) emit_2bytes(j_compress_ptr cinfo, int value)
/* Emit a 2-byte integer; these are always MSB first in JPEG files */ /* Emit a 2-byte integer; these are always MSB first in JPEG files */
{ {
emit_byte(cinfo, (value >> 8) & 0xFF); emit_byte(cinfo, (value >> 8) & 0xFF);
@ -146,7 +146,7 @@ emit_2bytes (j_compress_ptr cinfo, int value)
*/ */
LOCAL(int) LOCAL(int)
emit_dqt (j_compress_ptr cinfo, int index) emit_dqt(j_compress_ptr cinfo, int index)
/* Emit a DQT marker */ /* Emit a DQT marker */
/* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */ /* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */
{ {
@ -163,19 +163,19 @@ emit_dqt (j_compress_ptr cinfo, int index)
prec = 1; prec = 1;
} }
if (! qtbl->sent_table) { if (!qtbl->sent_table) {
emit_marker(cinfo, M_DQT); emit_marker(cinfo, M_DQT);
emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2); emit_2bytes(cinfo, prec ? DCTSIZE2 * 2 + 1 + 2 : DCTSIZE2 + 1 + 2);
emit_byte(cinfo, index + (prec<<4)); emit_byte(cinfo, index + (prec << 4));
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
/* The table entries must be emitted in zigzag order. */ /* The table entries must be emitted in zigzag order. */
unsigned int qval = qtbl->quantval[jpeg_natural_order[i]]; unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
if (prec) if (prec)
emit_byte(cinfo, (int) (qval >> 8)); emit_byte(cinfo, (int)(qval >> 8));
emit_byte(cinfo, (int) (qval & 0xFF)); emit_byte(cinfo, (int)(qval & 0xFF));
} }
qtbl->sent_table = TRUE; qtbl->sent_table = TRUE;
@ -186,7 +186,7 @@ emit_dqt (j_compress_ptr cinfo, int index)
LOCAL(void) LOCAL(void)
emit_dht (j_compress_ptr cinfo, int index, boolean is_ac) emit_dht(j_compress_ptr cinfo, int index, boolean is_ac)
/* Emit a DHT marker */ /* Emit a DHT marker */
{ {
JHUFF_TBL *htbl; JHUFF_TBL *htbl;
@ -202,7 +202,7 @@ emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
if (htbl == NULL) if (htbl == NULL)
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index); ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
if (! htbl->sent_table) { if (!htbl->sent_table) {
emit_marker(cinfo, M_DHT); emit_marker(cinfo, M_DHT);
length = 0; length = 0;
@ -224,7 +224,7 @@ emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
LOCAL(void) LOCAL(void)
emit_dac (j_compress_ptr cinfo) emit_dac(j_compress_ptr cinfo)
/* Emit a DAC marker */ /* Emit a DAC marker */
/* Since the useful info is so small, we want to emit all the tables in */ /* Since the useful info is so small, we want to emit all the tables in */
/* one DAC marker. Therefore this routine does its own scan of the table. */ /* one DAC marker. Therefore this routine does its own scan of the table. */
@ -255,12 +255,12 @@ emit_dac (j_compress_ptr cinfo)
if (length) { if (length) {
emit_marker(cinfo, M_DAC); emit_marker(cinfo, M_DAC);
emit_2bytes(cinfo, length*2 + 2); emit_2bytes(cinfo, length * 2 + 2);
for (i = 0; i < NUM_ARITH_TBLS; i++) { for (i = 0; i < NUM_ARITH_TBLS; i++) {
if (dc_in_use[i]) { if (dc_in_use[i]) {
emit_byte(cinfo, i); emit_byte(cinfo, i);
emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4)); emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i] << 4));
} }
if (ac_in_use[i]) { if (ac_in_use[i]) {
emit_byte(cinfo, i + 0x10); emit_byte(cinfo, i + 0x10);
@ -273,19 +273,19 @@ emit_dac (j_compress_ptr cinfo)
LOCAL(void) LOCAL(void)
emit_dri (j_compress_ptr cinfo) emit_dri(j_compress_ptr cinfo)
/* Emit a DRI marker */ /* Emit a DRI marker */
{ {
emit_marker(cinfo, M_DRI); emit_marker(cinfo, M_DRI);
emit_2bytes(cinfo, 4); /* fixed length */ emit_2bytes(cinfo, 4); /* fixed length */
emit_2bytes(cinfo, (int) cinfo->restart_interval); emit_2bytes(cinfo, (int)cinfo->restart_interval);
} }
LOCAL(void) LOCAL(void)
emit_sof (j_compress_ptr cinfo, JPEG_MARKER code) emit_sof(j_compress_ptr cinfo, JPEG_MARKER code)
/* Emit a SOF marker */ /* Emit a SOF marker */
{ {
int ci; int ci;
@ -296,13 +296,12 @@ emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */ emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
/* Make sure image isn't bigger than SOF field can handle */ /* Make sure image isn't bigger than SOF field can handle */
if ((long) cinfo->_jpeg_height > 65535L || if ((long)cinfo->_jpeg_height > 65535L || (long)cinfo->_jpeg_width > 65535L)
(long) cinfo->_jpeg_width > 65535L) ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int)65535);
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
emit_byte(cinfo, cinfo->data_precision); emit_byte(cinfo, cinfo->data_precision);
emit_2bytes(cinfo, (int) cinfo->_jpeg_height); emit_2bytes(cinfo, (int)cinfo->_jpeg_height);
emit_2bytes(cinfo, (int) cinfo->_jpeg_width); emit_2bytes(cinfo, (int)cinfo->_jpeg_width);
emit_byte(cinfo, cinfo->num_components); emit_byte(cinfo, cinfo->num_components);
@ -316,7 +315,7 @@ emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
LOCAL(void) LOCAL(void)
emit_sos (j_compress_ptr cinfo) emit_sos(j_compress_ptr cinfo)
/* Emit a SOS marker */ /* Emit a SOS marker */
{ {
int i, td, ta; int i, td, ta;
@ -351,7 +350,7 @@ emit_sos (j_compress_ptr cinfo)
LOCAL(void) LOCAL(void)
emit_jfif_app0 (j_compress_ptr cinfo) emit_jfif_app0(j_compress_ptr cinfo)
/* Emit a JFIF-compliant APP0 marker */ /* Emit a JFIF-compliant APP0 marker */
{ {
/* /*
@ -378,15 +377,15 @@ emit_jfif_app0 (j_compress_ptr cinfo)
emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */ emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
emit_byte(cinfo, cinfo->JFIF_minor_version); emit_byte(cinfo, cinfo->JFIF_minor_version);
emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */ emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
emit_2bytes(cinfo, (int) cinfo->X_density); emit_2bytes(cinfo, (int)cinfo->X_density);
emit_2bytes(cinfo, (int) cinfo->Y_density); emit_2bytes(cinfo, (int)cinfo->Y_density);
emit_byte(cinfo, 0); /* No thumbnail image */ emit_byte(cinfo, 0); /* No thumbnail image */
emit_byte(cinfo, 0); emit_byte(cinfo, 0);
} }
LOCAL(void) LOCAL(void)
emit_adobe_app14 (j_compress_ptr cinfo) emit_adobe_app14(j_compress_ptr cinfo)
/* Emit an Adobe APP14 marker */ /* Emit an Adobe APP14 marker */
{ {
/* /*
@ -440,19 +439,19 @@ emit_adobe_app14 (j_compress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen) write_marker_header(j_compress_ptr cinfo, int marker, unsigned int datalen)
/* Emit an arbitrary marker header */ /* Emit an arbitrary marker header */
{ {
if (datalen > (unsigned int) 65533) /* safety check */ if (datalen > (unsigned int)65533) /* safety check */
ERREXIT(cinfo, JERR_BAD_LENGTH); ERREXIT(cinfo, JERR_BAD_LENGTH);
emit_marker(cinfo, (JPEG_MARKER) marker); emit_marker(cinfo, (JPEG_MARKER)marker);
emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */ emit_2bytes(cinfo, (int)(datalen + 2)); /* total length */
} }
METHODDEF(void) METHODDEF(void)
write_marker_byte (j_compress_ptr cinfo, int val) write_marker_byte(j_compress_ptr cinfo, int val)
/* Emit one byte of marker parameters following write_marker_header */ /* Emit one byte of marker parameters following write_marker_header */
{ {
emit_byte(cinfo, val); emit_byte(cinfo, val);
@ -471,9 +470,9 @@ write_marker_byte (j_compress_ptr cinfo, int val)
*/ */
METHODDEF(void) METHODDEF(void)
write_file_header (j_compress_ptr cinfo) write_file_header(j_compress_ptr cinfo)
{ {
my_marker_ptr marker = (my_marker_ptr) cinfo->marker; my_marker_ptr marker = (my_marker_ptr)cinfo->marker;
emit_marker(cinfo, M_SOI); /* first the SOI */ emit_marker(cinfo, M_SOI); /* first the SOI */
@ -496,7 +495,7 @@ write_file_header (j_compress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
write_frame_header (j_compress_ptr cinfo) write_frame_header(j_compress_ptr cinfo)
{ {
int ci, prec; int ci, prec;
boolean is_baseline; boolean is_baseline;
@ -556,9 +555,9 @@ write_frame_header (j_compress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
write_scan_header (j_compress_ptr cinfo) write_scan_header(j_compress_ptr cinfo)
{ {
my_marker_ptr marker = (my_marker_ptr) cinfo->marker; my_marker_ptr marker = (my_marker_ptr)cinfo->marker;
int i; int i;
jpeg_component_info *compptr; jpeg_component_info *compptr;
@ -600,7 +599,7 @@ write_scan_header (j_compress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
write_file_trailer (j_compress_ptr cinfo) write_file_trailer(j_compress_ptr cinfo)
{ {
emit_marker(cinfo, M_EOI); emit_marker(cinfo, M_EOI);
} }
@ -614,7 +613,7 @@ write_file_trailer (j_compress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
write_tables_only (j_compress_ptr cinfo) write_tables_only(j_compress_ptr cinfo)
{ {
int i; int i;
@ -622,10 +621,10 @@ write_tables_only (j_compress_ptr cinfo)
for (i = 0; i < NUM_QUANT_TBLS; i++) { for (i = 0; i < NUM_QUANT_TBLS; i++) {
if (cinfo->quant_tbl_ptrs[i] != NULL) if (cinfo->quant_tbl_ptrs[i] != NULL)
(void) emit_dqt(cinfo, i); (void)emit_dqt(cinfo, i);
} }
if (! cinfo->arith_code) { if (!cinfo->arith_code) {
for (i = 0; i < NUM_HUFF_TBLS; i++) { for (i = 0; i < NUM_HUFF_TBLS; i++) {
if (cinfo->dc_huff_tbl_ptrs[i] != NULL) if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
emit_dht(cinfo, i, FALSE); emit_dht(cinfo, i, FALSE);
@ -643,15 +642,15 @@ write_tables_only (j_compress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_marker_writer (j_compress_ptr cinfo) jinit_marker_writer(j_compress_ptr cinfo)
{ {
my_marker_ptr marker; my_marker_ptr marker;
/* Create the subobject */ /* Create the subobject */
marker = (my_marker_ptr) marker = (my_marker_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_marker_writer)); sizeof(my_marker_writer));
cinfo->marker = (struct jpeg_marker_writer *) marker; cinfo->marker = (struct jpeg_marker_writer *)marker;
/* Initialize method pointers */ /* Initialize method pointers */
marker->pub.write_file_header = write_file_header; marker->pub.write_file_header = write_file_header;
marker->pub.write_frame_header = write_frame_header; marker->pub.write_frame_header = write_frame_header;

View File

@ -5,7 +5,7 @@
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2003-2010 by Guido Vollbeding. * Modified 2003-2010 by Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2010, 2016, D. R. Commander. * Copyright (C) 2010, 2016, 2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@ -66,7 +66,7 @@ typedef my_comp_master *my_master_ptr;
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo) jpeg_calc_jpeg_dimensions(j_compress_ptr cinfo)
/* Do computations that are needed before master selection phase */ /* Do computations that are needed before master selection phase */
{ {
/* Hardwire it to "no scaling" */ /* Hardwire it to "no scaling" */
@ -79,7 +79,7 @@ jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo)
LOCAL(void) LOCAL(void)
initial_setup (j_compress_ptr cinfo, boolean transcode_only) 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; int ci;
@ -95,19 +95,19 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
#endif #endif
/* Sanity check on image dimensions */ /* Sanity check on image dimensions */
if (cinfo->_jpeg_height <= 0 || cinfo->_jpeg_width <= 0 if (cinfo->_jpeg_height <= 0 || cinfo->_jpeg_width <= 0 ||
|| cinfo->num_components <= 0 || cinfo->input_components <= 0) cinfo->num_components <= 0 || cinfo->input_components <= 0)
ERREXIT(cinfo, JERR_EMPTY_IMAGE); ERREXIT(cinfo, JERR_EMPTY_IMAGE);
/* Make sure image isn't bigger than I can handle */ /* Make sure image isn't bigger than I can handle */
if ((long) cinfo->_jpeg_height > (long) JPEG_MAX_DIMENSION || if ((long)cinfo->_jpeg_height > (long)JPEG_MAX_DIMENSION ||
(long) cinfo->_jpeg_width > (long) JPEG_MAX_DIMENSION) (long)cinfo->_jpeg_width > (long)JPEG_MAX_DIMENSION)
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int)JPEG_MAX_DIMENSION);
/* Width of an input scanline must be representable as JDIMENSION. */ /* Width of an input scanline must be representable as JDIMENSION. */
samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components; samplesperrow = (long)cinfo->image_width * (long)cinfo->input_components;
jd_samplesperrow = (JDIMENSION) samplesperrow; jd_samplesperrow = (JDIMENSION)samplesperrow;
if ((long) jd_samplesperrow != samplesperrow) if ((long)jd_samplesperrow != samplesperrow)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
/* For now, precision must match compiled-in value... */ /* For now, precision must match compiled-in value... */
@ -124,8 +124,10 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
cinfo->max_v_samp_factor = 1; cinfo->max_v_samp_factor = 1;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || if (compptr->h_samp_factor <= 0 ||
compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) compptr->h_samp_factor > MAX_SAMP_FACTOR ||
compptr->v_samp_factor <= 0 ||
compptr->v_samp_factor > MAX_SAMP_FACTOR)
ERREXIT(cinfo, JERR_BAD_SAMPLING); ERREXIT(cinfo, JERR_BAD_SAMPLING);
cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
compptr->h_samp_factor); compptr->h_samp_factor);
@ -146,18 +148,18 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
#endif #endif
/* Size in DCT blocks */ /* Size in DCT blocks */
compptr->width_in_blocks = (JDIMENSION) compptr->width_in_blocks = (JDIMENSION)
jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor, jdiv_round_up((long)cinfo->_jpeg_width * (long)compptr->h_samp_factor,
(long) (cinfo->max_h_samp_factor * DCTSIZE)); (long)(cinfo->max_h_samp_factor * DCTSIZE));
compptr->height_in_blocks = (JDIMENSION) compptr->height_in_blocks = (JDIMENSION)
jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor, jdiv_round_up((long)cinfo->_jpeg_height * (long)compptr->v_samp_factor,
(long) (cinfo->max_v_samp_factor * DCTSIZE)); (long)(cinfo->max_v_samp_factor * DCTSIZE));
/* Size in samples */ /* Size in samples */
compptr->downsampled_width = (JDIMENSION) compptr->downsampled_width = (JDIMENSION)
jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor, jdiv_round_up((long)cinfo->_jpeg_width * (long)compptr->h_samp_factor,
(long) cinfo->max_h_samp_factor); (long)cinfo->max_h_samp_factor);
compptr->downsampled_height = (JDIMENSION) compptr->downsampled_height = (JDIMENSION)
jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor, jdiv_round_up((long)cinfo->_jpeg_height * (long)compptr->v_samp_factor,
(long) cinfo->max_v_samp_factor); (long)cinfo->max_v_samp_factor);
/* Mark component needed (this flag isn't actually used for compression) */ /* Mark component needed (this flag isn't actually used for compression) */
compptr->component_needed = TRUE; compptr->component_needed = TRUE;
} }
@ -166,15 +168,15 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
* main controller will call coefficient controller). * main controller will call coefficient controller).
*/ */
cinfo->total_iMCU_rows = (JDIMENSION) cinfo->total_iMCU_rows = (JDIMENSION)
jdiv_round_up((long) cinfo->_jpeg_height, jdiv_round_up((long)cinfo->_jpeg_height,
(long) (cinfo->max_v_samp_factor*DCTSIZE)); (long)(cinfo->max_v_samp_factor * DCTSIZE));
} }
#ifdef C_MULTISCAN_FILES_SUPPORTED #ifdef C_MULTISCAN_FILES_SUPPORTED
LOCAL(void) LOCAL(void)
validate_script (j_compress_ptr cinfo) validate_script(j_compress_ptr cinfo)
/* Verify that the scan script in cinfo->scan_info[] is valid; also /* Verify that the scan script in cinfo->scan_info[] is valid; also
* determine whether it uses progressive JPEG, and set cinfo->progressive_mode. * determine whether it uses progressive JPEG, and set cinfo->progressive_mode.
*/ */
@ -196,10 +198,10 @@ validate_script (j_compress_ptr cinfo)
* for progressive JPEG, no scan can have this. * for progressive JPEG, no scan can have this.
*/ */
scanptr = cinfo->scan_info; scanptr = cinfo->scan_info;
if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) { if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2 - 1) {
#ifdef C_PROGRESSIVE_SUPPORTED #ifdef C_PROGRESSIVE_SUPPORTED
cinfo->progressive_mode = TRUE; cinfo->progressive_mode = TRUE;
last_bitpos_ptr = & last_bitpos[0][0]; last_bitpos_ptr = &last_bitpos[0][0];
for (ci = 0; ci < cinfo->num_components; ci++) for (ci = 0; ci < cinfo->num_components; ci++)
for (coefi = 0; coefi < DCTSIZE2; coefi++) for (coefi = 0; coefi < DCTSIZE2; coefi++)
*last_bitpos_ptr++ = -1; *last_bitpos_ptr++ = -1;
@ -222,7 +224,7 @@ validate_script (j_compress_ptr cinfo)
if (thisi < 0 || thisi >= cinfo->num_components) if (thisi < 0 || thisi >= cinfo->num_components)
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
/* Components must appear in SOF order within each scan */ /* Components must appear in SOF order within each scan */
if (ci > 0 && thisi <= scanptr->component_index[ci-1]) if (ci > 0 && thisi <= scanptr->component_index[ci - 1])
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
} }
/* Validate progression parameters */ /* Validate progression parameters */
@ -232,9 +234,9 @@ validate_script (j_compress_ptr cinfo)
Al = scanptr->Al; Al = scanptr->Al;
if (cinfo->progressive_mode) { if (cinfo->progressive_mode) {
#ifdef C_PROGRESSIVE_SUPPORTED #ifdef C_PROGRESSIVE_SUPPORTED
/* The JPEG spec simply gives the ranges 0..13 for Ah and Al, but that /* Rec. ITU-T T.81 | ISO/IEC 10918-1 simply gives the ranges 0..13 for Ah
* seems wrong: the upper bound ought to depend on data precision. * and Al, but that seems wrong: the upper bound ought to depend on data
* Perhaps they really meant 0..N+1 for N-bit precision. * precision. Perhaps they really meant 0..N+1 for N-bit precision.
* Here we allow 0..10 for 8-bit data; Al larger than 10 results in * Here we allow 0..10 for 8-bit data; Al larger than 10 results in
* 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.
@ -255,7 +257,7 @@ validate_script (j_compress_ptr cinfo)
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
} }
for (ci = 0; ci < ncomps; ci++) { for (ci = 0; ci < ncomps; ci++) {
last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0]; last_bitpos_ptr = &last_bitpos[scanptr->component_index[ci]][0];
if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */ if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
for (coefi = Ss; coefi <= Se; coefi++) { for (coefi = Ss; coefi <= Se; coefi++) {
@ -265,7 +267,7 @@ validate_script (j_compress_ptr cinfo)
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
} else { } else {
/* not first scan */ /* not first scan */
if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1) if (Ah != last_bitpos_ptr[coefi] || Al != Ah - 1)
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
} }
last_bitpos_ptr[coefi] = Al; last_bitpos_ptr[coefi] = Al;
@ -274,7 +276,7 @@ validate_script (j_compress_ptr cinfo)
#endif #endif
} else { } else {
/* For sequential JPEG, all progression parameters must be these: */ /* For sequential JPEG, all progression parameters must be these: */
if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0) if (Ss != 0 || Se != DCTSIZE2 - 1 || Ah != 0 || Al != 0)
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
/* Make sure components are not sent twice */ /* Make sure components are not sent twice */
for (ci = 0; ci < ncomps; ci++) { for (ci = 0; ci < ncomps; ci++) {
@ -301,7 +303,7 @@ validate_script (j_compress_ptr cinfo)
#endif #endif
} else { } else {
for (ci = 0; ci < cinfo->num_components; ci++) { for (ci = 0; ci < cinfo->num_components; ci++) {
if (! component_sent[ci]) if (!component_sent[ci])
ERREXIT(cinfo, JERR_MISSING_DATA); ERREXIT(cinfo, JERR_MISSING_DATA);
} }
} }
@ -311,7 +313,7 @@ validate_script (j_compress_ptr cinfo)
LOCAL(void) LOCAL(void)
select_scan_parameters (j_compress_ptr cinfo) select_scan_parameters(j_compress_ptr cinfo)
/* Set up the scan parameters for the current scan */ /* Set up the scan parameters for the current scan */
{ {
int ci; int ci;
@ -319,7 +321,7 @@ select_scan_parameters (j_compress_ptr cinfo)
#ifdef C_MULTISCAN_FILES_SUPPORTED #ifdef C_MULTISCAN_FILES_SUPPORTED
if (cinfo->scan_info != NULL) { if (cinfo->scan_info != NULL) {
/* Prepare for current scan --- the script is already validated */ /* Prepare for current scan --- the script is already validated */
my_master_ptr master = (my_master_ptr) cinfo->master; my_master_ptr master = (my_master_ptr)cinfo->master;
const jpeg_scan_info *scanptr = cinfo->scan_info + master->scan_number; const jpeg_scan_info *scanptr = cinfo->scan_info + master->scan_number;
cinfo->comps_in_scan = scanptr->comps_in_scan; cinfo->comps_in_scan = scanptr->comps_in_scan;
@ -331,8 +333,7 @@ select_scan_parameters (j_compress_ptr cinfo)
cinfo->Se = scanptr->Se; cinfo->Se = scanptr->Se;
cinfo->Ah = scanptr->Ah; cinfo->Ah = scanptr->Ah;
cinfo->Al = scanptr->Al; cinfo->Al = scanptr->Al;
} } else
else
#endif #endif
{ {
/* Prepare for single sequential-JPEG scan containing all components */ /* Prepare for single sequential-JPEG scan containing all components */
@ -344,7 +345,7 @@ select_scan_parameters (j_compress_ptr cinfo)
cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci]; cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
} }
cinfo->Ss = 0; cinfo->Ss = 0;
cinfo->Se = DCTSIZE2-1; cinfo->Se = DCTSIZE2 - 1;
cinfo->Ah = 0; cinfo->Ah = 0;
cinfo->Al = 0; cinfo->Al = 0;
} }
@ -352,7 +353,7 @@ select_scan_parameters (j_compress_ptr cinfo)
LOCAL(void) LOCAL(void)
per_scan_setup (j_compress_ptr cinfo) per_scan_setup(j_compress_ptr cinfo)
/* Do computations that are needed before processing a JPEG scan */ /* Do computations that are needed before processing a JPEG scan */
/* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */ /* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */
{ {
@ -377,7 +378,7 @@ per_scan_setup (j_compress_ptr cinfo)
/* For noninterleaved scans, it is convenient to define last_row_height /* For noninterleaved scans, it is convenient to define last_row_height
* as the number of block rows present in the last iMCU row. * as the number of block rows present in the last iMCU row.
*/ */
tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); tmp = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
if (tmp == 0) tmp = compptr->v_samp_factor; if (tmp == 0) tmp = compptr->v_samp_factor;
compptr->last_row_height = tmp; compptr->last_row_height = tmp;
@ -394,11 +395,11 @@ per_scan_setup (j_compress_ptr cinfo)
/* Overall image size in MCUs */ /* Overall image size in MCUs */
cinfo->MCUs_per_row = (JDIMENSION) cinfo->MCUs_per_row = (JDIMENSION)
jdiv_round_up((long) cinfo->_jpeg_width, jdiv_round_up((long)cinfo->_jpeg_width,
(long) (cinfo->max_h_samp_factor*DCTSIZE)); (long)(cinfo->max_h_samp_factor * DCTSIZE));
cinfo->MCU_rows_in_scan = (JDIMENSION) cinfo->MCU_rows_in_scan = (JDIMENSION)
jdiv_round_up((long) cinfo->_jpeg_height, jdiv_round_up((long)cinfo->_jpeg_height,
(long) (cinfo->max_v_samp_factor*DCTSIZE)); (long)(cinfo->max_v_samp_factor * DCTSIZE));
cinfo->blocks_in_MCU = 0; cinfo->blocks_in_MCU = 0;
@ -410,10 +411,10 @@ per_scan_setup (j_compress_ptr cinfo)
compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE; compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
/* Figure number of non-dummy blocks in last MCU column & row */ /* Figure number of non-dummy blocks in last MCU column & row */
tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); tmp = (int)(compptr->width_in_blocks % compptr->MCU_width);
if (tmp == 0) tmp = compptr->MCU_width; if (tmp == 0) tmp = compptr->MCU_width;
compptr->last_col_width = tmp; compptr->last_col_width = tmp;
tmp = (int) (compptr->height_in_blocks % compptr->MCU_height); tmp = (int)(compptr->height_in_blocks % compptr->MCU_height);
if (tmp == 0) tmp = compptr->MCU_height; if (tmp == 0) tmp = compptr->MCU_height;
compptr->last_row_height = tmp; compptr->last_row_height = tmp;
/* Prepare array describing MCU composition */ /* Prepare array describing MCU composition */
@ -430,8 +431,8 @@ per_scan_setup (j_compress_ptr cinfo)
/* Convert restart specified in rows to actual MCU count. */ /* Convert restart specified in rows to actual MCU count. */
/* Note that count must fit in 16 bits, so we provide limiting. */ /* Note that count must fit in 16 bits, so we provide limiting. */
if (cinfo->restart_in_rows > 0) { if (cinfo->restart_in_rows > 0) {
long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row; long nominal = (long)cinfo->restart_in_rows * (long)cinfo->MCUs_per_row;
cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L); cinfo->restart_interval = (unsigned int)MIN(nominal, 65535L);
} }
} }
@ -445,9 +446,9 @@ per_scan_setup (j_compress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
prepare_for_pass (j_compress_ptr cinfo) prepare_for_pass(j_compress_ptr cinfo)
{ {
my_master_ptr master = (my_master_ptr) cinfo->master; my_master_ptr master = (my_master_ptr)cinfo->master;
switch (master->pass_type) { switch (master->pass_type) {
case main_pass: case main_pass:
@ -456,7 +457,7 @@ prepare_for_pass (j_compress_ptr cinfo)
*/ */
select_scan_parameters(cinfo); select_scan_parameters(cinfo);
per_scan_setup(cinfo); per_scan_setup(cinfo);
if (! cinfo->raw_data_in) { if (!cinfo->raw_data_in) {
(*cinfo->cconvert->start_pass) (cinfo); (*cinfo->cconvert->start_pass) (cinfo);
(*cinfo->downsample->start_pass) (cinfo); (*cinfo->downsample->start_pass) (cinfo);
(*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU); (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
@ -496,7 +497,7 @@ prepare_for_pass (j_compress_ptr cinfo)
case output_pass: case output_pass:
/* Do a data-output pass. */ /* Do a data-output pass. */
/* We need not repeat per-scan setup if prior optimization pass did it. */ /* We need not repeat per-scan setup if prior optimization pass did it. */
if (! cinfo->optimize_coding) { if (!cinfo->optimize_coding) {
select_scan_parameters(cinfo); select_scan_parameters(cinfo);
per_scan_setup(cinfo); per_scan_setup(cinfo);
} }
@ -512,7 +513,7 @@ prepare_for_pass (j_compress_ptr cinfo)
ERREXIT(cinfo, JERR_NOT_COMPILED); ERREXIT(cinfo, JERR_NOT_COMPILED);
} }
master->pub.is_last_pass = (master->pass_number == master->total_passes-1); master->pub.is_last_pass = (master->pass_number == master->total_passes - 1);
/* Set up progress monitor's pass info if present */ /* Set up progress monitor's pass info if present */
if (cinfo->progress != NULL) { if (cinfo->progress != NULL) {
@ -533,7 +534,7 @@ prepare_for_pass (j_compress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
pass_startup (j_compress_ptr cinfo) pass_startup(j_compress_ptr cinfo)
{ {
cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */ cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
@ -547,9 +548,9 @@ pass_startup (j_compress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
finish_pass_master (j_compress_ptr cinfo) finish_pass_master(j_compress_ptr cinfo)
{ {
my_master_ptr master = (my_master_ptr) cinfo->master; my_master_ptr master = (my_master_ptr)cinfo->master;
/* The entropy coder always needs an end-of-pass call, /* The entropy coder always needs an end-of-pass call,
* either to analyze statistics or to flush its output buffer. * either to analyze statistics or to flush its output buffer.
@ -563,7 +564,7 @@ finish_pass_master (j_compress_ptr cinfo)
* or output of scan 1 (if no optimization). * or output of scan 1 (if no optimization).
*/ */
master->pass_type = output_pass; master->pass_type = output_pass;
if (! cinfo->optimize_coding) if (!cinfo->optimize_coding)
master->scan_number++; master->scan_number++;
break; break;
case huff_opt_pass: case huff_opt_pass:
@ -587,14 +588,14 @@ finish_pass_master (j_compress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only) jinit_c_master_control(j_compress_ptr cinfo, boolean transcode_only)
{ {
my_master_ptr master; my_master_ptr master;
master = (my_master_ptr) master = (my_master_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_comp_master)); sizeof(my_comp_master));
cinfo->master = (struct jpeg_comp_master *) master; cinfo->master = (struct jpeg_comp_master *)master;
master->pub.prepare_for_pass = prepare_for_pass; master->pub.prepare_for_pass = prepare_for_pass;
master->pub.pass_startup = pass_startup; master->pub.pass_startup = pass_startup;
master->pub.finish_pass = finish_pass_master; master->pub.finish_pass = finish_pass_master;

View File

@ -29,7 +29,7 @@
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_abort (j_common_ptr cinfo) jpeg_abort(j_common_ptr cinfo)
{ {
int pool; int pool;
@ -40,7 +40,7 @@ jpeg_abort (j_common_ptr cinfo)
/* Releasing pools in reverse order might help avoid fragmentation /* Releasing pools in reverse order might help avoid fragmentation
* with some (brain-damaged) malloc libraries. * with some (brain-damaged) malloc libraries.
*/ */
for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) { for (pool = JPOOL_NUMPOOLS - 1; pool > JPOOL_PERMANENT; pool--) {
(*cinfo->mem->free_pool) (cinfo, pool); (*cinfo->mem->free_pool) (cinfo, pool);
} }
@ -50,7 +50,7 @@ jpeg_abort (j_common_ptr cinfo)
/* Try to keep application from accessing now-deleted marker list. /* Try to keep application from accessing now-deleted marker list.
* A bit kludgy to do it here, but this is the most central place. * A bit kludgy to do it here, but this is the most central place.
*/ */
((j_decompress_ptr) cinfo)->marker_list = NULL; ((j_decompress_ptr)cinfo)->marker_list = NULL;
} else { } else {
cinfo->global_state = CSTATE_START; cinfo->global_state = CSTATE_START;
} }
@ -69,7 +69,7 @@ jpeg_abort (j_common_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_destroy (j_common_ptr cinfo) jpeg_destroy(j_common_ptr cinfo)
{ {
/* We need only tell the memory manager to release everything. */ /* We need only tell the memory manager to release everything. */
/* NB: mem pointer is NULL if memory mgr failed to initialize. */ /* NB: mem pointer is NULL if memory mgr failed to initialize. */
@ -86,7 +86,7 @@ jpeg_destroy (j_common_ptr cinfo)
*/ */
GLOBAL(JQUANT_TBL *) GLOBAL(JQUANT_TBL *)
jpeg_alloc_quant_table (j_common_ptr cinfo) jpeg_alloc_quant_table(j_common_ptr cinfo)
{ {
JQUANT_TBL *tbl; JQUANT_TBL *tbl;
@ -98,7 +98,7 @@ jpeg_alloc_quant_table (j_common_ptr cinfo)
GLOBAL(JHUFF_TBL *) GLOBAL(JHUFF_TBL *)
jpeg_alloc_huff_table (j_common_ptr cinfo) jpeg_alloc_huff_table(j_common_ptr cinfo)
{ {
JHUFF_TBL *tbl; JHUFF_TBL *tbl;

View File

@ -5,7 +5,7 @@
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2003-2008 by Guido Vollbeding. * Modified 2003-2008 by Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009-2011, D. R. Commander. * Copyright (C) 2009-2011, 2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@ -25,9 +25,9 @@
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl, jpeg_add_quant_table(j_compress_ptr cinfo, int which_tbl,
const unsigned int *basic_table, const unsigned int *basic_table, int scale_factor,
int scale_factor, boolean force_baseline) boolean force_baseline)
/* Define a quantization table equal to the basic_table times /* Define a quantization table equal to the basic_table times
* a scale factor (given as a percentage). * a scale factor (given as a percentage).
* If force_baseline is TRUE, the computed quantization table entries * If force_baseline is TRUE, the computed quantization table entries
@ -45,19 +45,19 @@ jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS) if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl); ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
qtblptr = & cinfo->quant_tbl_ptrs[which_tbl]; qtblptr = &cinfo->quant_tbl_ptrs[which_tbl];
if (*qtblptr == NULL) if (*qtblptr == NULL)
*qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo); *qtblptr = jpeg_alloc_quant_table((j_common_ptr)cinfo);
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
temp = ((long) basic_table[i] * scale_factor + 50L) / 100L; temp = ((long)basic_table[i] * scale_factor + 50L) / 100L;
/* limit the values to the valid range */ /* limit the values to the valid range */
if (temp <= 0L) temp = 1L; if (temp <= 0L) temp = 1L;
if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */ if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
if (force_baseline && temp > 255L) if (force_baseline && temp > 255L)
temp = 255L; /* limit to baseline range if requested */ temp = 255L; /* limit to baseline range if requested */
(*qtblptr)->quantval[i] = (UINT16) temp; (*qtblptr)->quantval[i] = (UINT16)temp;
} }
/* Initialize sent_table FALSE so table will be written to JPEG file. */ /* Initialize sent_table FALSE so table will be written to JPEG file. */
@ -65,7 +65,8 @@ jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
} }
/* These are the sample quantization tables given in JPEG spec section K.1. /* These are the sample quantization tables given in Annex K (Clause K.1) of
* Recommendation ITU-T T.81 (1992) | ISO/IEC 10918-1:1994.
* The spec says that the values given produce "good" quality, and * The spec says that the values given produce "good" quality, and
* when divided by 2, "very good" quality. * when divided by 2, "very good" quality.
*/ */
@ -93,7 +94,7 @@ static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
GLOBAL(void) GLOBAL(void)
jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline) jpeg_default_qtables(j_compress_ptr cinfo, boolean force_baseline)
/* Set or change the 'quality' (quantization) setting, using default tables /* Set or change the 'quality' (quantization) setting, using default tables
* and straight percentage-scaling quality scales. * and straight percentage-scaling quality scales.
* This entry point allows different scalings for luminance and chrominance. * This entry point allows different scalings for luminance and chrominance.
@ -109,7 +110,7 @@ jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline)
GLOBAL(void) GLOBAL(void)
jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, jpeg_set_linear_quality(j_compress_ptr cinfo, int scale_factor,
boolean force_baseline) boolean force_baseline)
/* Set or change the 'quality' (quantization) setting, using default tables /* Set or change the 'quality' (quantization) setting, using default tables
* and a straight percentage-scaling quality scale. In most cases it's better * and a straight percentage-scaling quality scale. In most cases it's better
@ -126,7 +127,7 @@ jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
GLOBAL(int) GLOBAL(int)
jpeg_quality_scaling (int quality) jpeg_quality_scaling(int quality)
/* Convert a user-specified quality rating to a percentage scaling factor /* Convert a user-specified quality rating to a percentage scaling factor
* for an underlying quantization table, using our recommended scaling curve. * for an underlying quantization table, using our recommended scaling curve.
* The input 'quality' factor should be 0 (terrible) to 100 (very good). * The input 'quality' factor should be 0 (terrible) to 100 (very good).
@ -145,14 +146,14 @@ jpeg_quality_scaling (int quality)
if (quality < 50) if (quality < 50)
quality = 5000 / quality; quality = 5000 / quality;
else else
quality = 200 - quality*2; quality = 200 - quality * 2;
return quality; return quality;
} }
GLOBAL(void) GLOBAL(void)
jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline) jpeg_set_quality(j_compress_ptr cinfo, int quality, boolean force_baseline)
/* Set or change the 'quality' (quantization) setting, using default tables. /* Set or change the 'quality' (quantization) setting, using default tables.
* This is the standard quality-adjusting entry point for typical user * This is the standard quality-adjusting entry point for typical user
* interfaces; only those who want detailed control over quantization tables * interfaces; only those who want detailed control over quantization tables
@ -178,7 +179,7 @@ jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_set_defaults (j_compress_ptr cinfo) jpeg_set_defaults(j_compress_ptr cinfo)
{ {
int i; int i;
@ -192,7 +193,7 @@ jpeg_set_defaults (j_compress_ptr cinfo)
*/ */
if (cinfo->comp_info == NULL) if (cinfo->comp_info == NULL)
cinfo->comp_info = (jpeg_component_info *) cinfo->comp_info = (jpeg_component_info *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
MAX_COMPONENTS * sizeof(jpeg_component_info)); MAX_COMPONENTS * sizeof(jpeg_component_info));
/* Initialize everything not dependent on the color space */ /* Initialize everything not dependent on the color space */
@ -205,7 +206,7 @@ jpeg_set_defaults (j_compress_ptr cinfo)
/* Set up two quantization tables using default quality of 75 */ /* Set up two quantization tables using default quality of 75 */
jpeg_set_quality(cinfo, 75, TRUE); jpeg_set_quality(cinfo, 75, TRUE);
/* Set up two Huffman tables */ /* Set up two Huffman tables */
std_huff_tables((j_common_ptr) cinfo); std_huff_tables((j_common_ptr)cinfo);
/* Initialize default arithmetic coding conditioning */ /* Initialize default arithmetic coding conditioning */
for (i = 0; i < NUM_ARITH_TBLS; i++) { for (i = 0; i < NUM_ARITH_TBLS; i++) {
@ -278,7 +279,7 @@ jpeg_set_defaults (j_compress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_default_colorspace (j_compress_ptr cinfo) jpeg_default_colorspace(j_compress_ptr cinfo)
{ {
switch (cinfo->in_color_space) { switch (cinfo->in_color_space) {
case JCS_GRAYSCALE: case JCS_GRAYSCALE:
@ -320,12 +321,12 @@ jpeg_default_colorspace (j_compress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace) jpeg_set_colorspace(j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
{ {
jpeg_component_info *compptr; jpeg_component_info *compptr;
int ci; int ci;
#define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \ #define SET_COMP(index, id, hsamp, vsamp, quant, dctbl, actbl) \
(compptr = &cinfo->comp_info[index], \ (compptr = &cinfo->comp_info[index], \
compptr->component_id = (id), \ compptr->component_id = (id), \
compptr->h_samp_factor = (hsamp), \ compptr->h_samp_factor = (hsamp), \
@ -352,39 +353,39 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
cinfo->num_components = 1; cinfo->num_components = 1;
/* JFIF specifies component ID 1 */ /* JFIF specifies component ID 1 */
SET_COMP(0, 1, 1,1, 0, 0,0); SET_COMP(0, 1, 1, 1, 0, 0, 0);
break; break;
case JCS_RGB: case JCS_RGB:
cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */ cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
cinfo->num_components = 3; cinfo->num_components = 3;
SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0); SET_COMP(0, 0x52 /* 'R' */, 1, 1, 0, 0, 0);
SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0); SET_COMP(1, 0x47 /* 'G' */, 1, 1, 0, 0, 0);
SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0); SET_COMP(2, 0x42 /* 'B' */, 1, 1, 0, 0, 0);
break; break;
case JCS_YCbCr: case JCS_YCbCr:
cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
cinfo->num_components = 3; cinfo->num_components = 3;
/* JFIF specifies component IDs 1,2,3 */ /* JFIF specifies component IDs 1,2,3 */
/* We default to 2x2 subsamples of chrominance */ /* We default to 2x2 subsamples of chrominance */
SET_COMP(0, 1, 2,2, 0, 0,0); SET_COMP(0, 1, 2, 2, 0, 0, 0);
SET_COMP(1, 2, 1,1, 1, 1,1); SET_COMP(1, 2, 1, 1, 1, 1, 1);
SET_COMP(2, 3, 1,1, 1, 1,1); SET_COMP(2, 3, 1, 1, 1, 1, 1);
break; break;
case JCS_CMYK: case JCS_CMYK:
cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */ cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
cinfo->num_components = 4; cinfo->num_components = 4;
SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0); SET_COMP(0, 0x43 /* 'C' */, 1, 1, 0, 0, 0);
SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0); SET_COMP(1, 0x4D /* 'M' */, 1, 1, 0, 0, 0);
SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0); SET_COMP(2, 0x59 /* 'Y' */, 1, 1, 0, 0, 0);
SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0); SET_COMP(3, 0x4B /* 'K' */, 1, 1, 0, 0, 0);
break; break;
case JCS_YCCK: case JCS_YCCK:
cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */ cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
cinfo->num_components = 4; cinfo->num_components = 4;
SET_COMP(0, 1, 2,2, 0, 0,0); SET_COMP(0, 1, 2, 2, 0, 0, 0);
SET_COMP(1, 2, 1,1, 1, 1,1); SET_COMP(1, 2, 1, 1, 1, 1, 1);
SET_COMP(2, 3, 1,1, 1, 1,1); SET_COMP(2, 3, 1, 1, 1, 1, 1);
SET_COMP(3, 4, 2,2, 0, 0,0); SET_COMP(3, 4, 2, 2, 0, 0, 0);
break; break;
case JCS_UNKNOWN: case JCS_UNKNOWN:
cinfo->num_components = cinfo->input_components; cinfo->num_components = cinfo->input_components;
@ -392,7 +393,7 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
MAX_COMPONENTS); MAX_COMPONENTS);
for (ci = 0; ci < cinfo->num_components; ci++) { for (ci = 0; ci < cinfo->num_components; ci++) {
SET_COMP(ci, ci, 1,1, 0, 0,0); SET_COMP(ci, ci, 1, 1, 0, 0, 0);
} }
break; break;
default: default:
@ -404,8 +405,7 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
#ifdef C_PROGRESSIVE_SUPPORTED #ifdef C_PROGRESSIVE_SUPPORTED
LOCAL(jpeg_scan_info *) LOCAL(jpeg_scan_info *)
fill_a_scan (jpeg_scan_info *scanptr, int ci, fill_a_scan(jpeg_scan_info *scanptr, int ci, int Ss, int Se, int Ah, int Al)
int Ss, int Se, int Ah, int Al)
/* Support routine: generate one scan for specified component */ /* Support routine: generate one scan for specified component */
{ {
scanptr->comps_in_scan = 1; scanptr->comps_in_scan = 1;
@ -419,8 +419,7 @@ fill_a_scan (jpeg_scan_info *scanptr, int ci,
} }
LOCAL(jpeg_scan_info *) LOCAL(jpeg_scan_info *)
fill_scans (jpeg_scan_info *scanptr, int ncomps, fill_scans(jpeg_scan_info *scanptr, int ncomps, int Ss, int Se, int Ah, int Al)
int Ss, int Se, int Ah, int Al)
/* Support routine: generate one scan for each component */ /* Support routine: generate one scan for each component */
{ {
int ci; int ci;
@ -438,7 +437,7 @@ fill_scans (jpeg_scan_info *scanptr, int ncomps,
} }
LOCAL(jpeg_scan_info *) LOCAL(jpeg_scan_info *)
fill_dc_scans (jpeg_scan_info *scanptr, int ncomps, int Ah, int Al) fill_dc_scans(jpeg_scan_info *scanptr, int ncomps, int Ah, int Al)
/* Support routine: generate interleaved DC scan if possible, else N scans */ /* Support routine: generate interleaved DC scan if possible, else N scans */
{ {
int ci; int ci;
@ -466,7 +465,7 @@ fill_dc_scans (jpeg_scan_info *scanptr, int ncomps, int Ah, int Al)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_simple_progression (j_compress_ptr cinfo) jpeg_simple_progression(j_compress_ptr cinfo)
{ {
int ncomps = cinfo->num_components; int ncomps = cinfo->num_components;
int nscans; int nscans;
@ -498,7 +497,7 @@ jpeg_simple_progression (j_compress_ptr cinfo)
if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) { if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
cinfo->script_space_size = MAX(nscans, 10); cinfo->script_space_size = MAX(nscans, 10);
cinfo->script_space = (jpeg_scan_info *) cinfo->script_space = (jpeg_scan_info *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
cinfo->script_space_size * sizeof(jpeg_scan_info)); cinfo->script_space_size * sizeof(jpeg_scan_info));
} }
scanptr = cinfo->script_space; scanptr = cinfo->script_space;

View File

@ -4,7 +4,8 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1995-1997, Thomas G. Lane. * Copyright (C) 1995-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2015, D. R. Commander. * Copyright (C) 2011, 2015, 2018, D. R. Commander.
* Copyright (C) 2016, 2018, Matthieu Darbois.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@ -18,15 +19,69 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jchuff.h" /* Declarations shared with jchuff.c */ #include "jsimd.h"
#include "jconfigint.h"
#include <limits.h>
#ifdef HAVE_INTRIN_H
#include <intrin.h>
#ifdef _MSC_VER
#ifdef HAVE_BITSCANFORWARD64
#pragma intrinsic(_BitScanForward64)
#endif
#ifdef HAVE_BITSCANFORWARD
#pragma intrinsic(_BitScanForward)
#endif
#endif
#endif
#ifdef C_PROGRESSIVE_SUPPORTED #ifdef C_PROGRESSIVE_SUPPORTED
/*
* NOTE: If USE_CLZ_INTRINSIC is defined, then clz/bsr instructions will be
* used for bit counting rather than the lookup table. This will reduce the
* memory footprint by 64k, which is important for some mobile applications
* that create many isolated instances of libjpeg-turbo (web browsers, for
* instance.) This may improve performance on some mobile platforms as well.
* This feature is enabled by default only on ARM processors, because some x86
* chips have a slow implementation of bsr, and the use of clz/bsr cannot be
* shown to have a significant performance impact even on the x86 chips that
* have a fast implementation of it. When building for ARMv6, you can
* explicitly disable the use of clz/bsr by adding -mthumb to the compiler
* flags (this defines __thumb__).
*/
/* NOTE: Both GCC and Clang define __GNUC__ */
#if defined __GNUC__ && (defined __arm__ || defined __aarch64__)
#if !defined __thumb__ || defined __thumb2__
#define USE_CLZ_INTRINSIC
#endif
#endif
#ifdef USE_CLZ_INTRINSIC
#define JPEG_NBITS_NONZERO(x) (32 - __builtin_clz(x))
#define JPEG_NBITS(x) (x ? JPEG_NBITS_NONZERO(x) : 0)
#else
#include "jpeg_nbits_table.h"
#define JPEG_NBITS(x) (jpeg_nbits_table[x])
#define JPEG_NBITS_NONZERO(x) JPEG_NBITS(x)
#endif
/* Expanded entropy encoder object for progressive Huffman encoding. */ /* Expanded entropy encoder object for progressive Huffman encoding. */
typedef struct { typedef struct {
struct jpeg_entropy_encoder pub; /* public fields */ struct jpeg_entropy_encoder pub; /* public fields */
/* Pointer to routine to prepare data for encode_mcu_AC_first() */
void (*AC_first_prepare) (const JCOEF *block,
const int *jpeg_natural_order_start, int Sl,
int Al, JCOEF *values, size_t *zerobits);
/* Pointer to routine to prepare data for encode_mcu_AC_refine() */
int (*AC_refine_prepare) (const JCOEF *block,
const int *jpeg_natural_order_start, int Sl,
int Al, JCOEF *absvalues, size_t *bits);
/* Mode flag: TRUE for optimization, FALSE for actual data output */ /* Mode flag: TRUE for optimization, FALSE for actual data output */
boolean gather_statistics; boolean gather_statistics;
@ -79,26 +134,60 @@ typedef phuff_entropy_encoder *phuff_entropy_ptr;
#ifdef RIGHT_SHIFT_IS_UNSIGNED #ifdef RIGHT_SHIFT_IS_UNSIGNED
#define ISHIFT_TEMPS int ishift_temp; #define ISHIFT_TEMPS int ishift_temp;
#define IRIGHT_SHIFT(x,shft) \ #define IRIGHT_SHIFT(x, shft) \
((ishift_temp = (x)) < 0 ? \ ((ishift_temp = (x)) < 0 ? \
(ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \ (ishift_temp >> (shft)) | ((~0) << (16 - (shft))) : \
(ishift_temp >> (shft))) (ishift_temp >> (shft)))
#else #else
#define ISHIFT_TEMPS #define ISHIFT_TEMPS
#define IRIGHT_SHIFT(x,shft) ((x) >> (shft)) #define IRIGHT_SHIFT(x, shft) ((x) >> (shft))
#endif #endif
#define PAD(v, p) ((v + (p) - 1) & (~((p) - 1)))
/* Forward declarations */ /* Forward declarations */
METHODDEF(boolean) encode_mcu_DC_first (j_compress_ptr cinfo, METHODDEF(boolean) encode_mcu_DC_first(j_compress_ptr cinfo,
JBLOCKROW *MCU_data); JBLOCKROW *MCU_data);
METHODDEF(boolean) encode_mcu_AC_first (j_compress_ptr cinfo, METHODDEF(void) encode_mcu_AC_first_prepare
(const JCOEF *block, const int *jpeg_natural_order_start, int Sl, int Al,
JCOEF *values, size_t *zerobits);
METHODDEF(boolean) encode_mcu_AC_first(j_compress_ptr cinfo,
JBLOCKROW *MCU_data); JBLOCKROW *MCU_data);
METHODDEF(boolean) encode_mcu_DC_refine (j_compress_ptr cinfo, METHODDEF(boolean) encode_mcu_DC_refine(j_compress_ptr cinfo,
JBLOCKROW *MCU_data); JBLOCKROW *MCU_data);
METHODDEF(boolean) encode_mcu_AC_refine (j_compress_ptr cinfo, METHODDEF(int) encode_mcu_AC_refine_prepare
(const JCOEF *block, const int *jpeg_natural_order_start, int Sl, int Al,
JCOEF *absvalues, size_t *bits);
METHODDEF(boolean) encode_mcu_AC_refine(j_compress_ptr cinfo,
JBLOCKROW *MCU_data); JBLOCKROW *MCU_data);
METHODDEF(void) finish_pass_phuff (j_compress_ptr cinfo); METHODDEF(void) finish_pass_phuff(j_compress_ptr cinfo);
METHODDEF(void) finish_pass_gather_phuff (j_compress_ptr cinfo); METHODDEF(void) finish_pass_gather_phuff(j_compress_ptr cinfo);
/* Count bit loop zeroes */
INLINE
METHODDEF(int)
count_zeroes(size_t *x)
{
int result;
#if defined(HAVE_BUILTIN_CTZL)
result = __builtin_ctzl(*x);
*x >>= result;
#elif defined(HAVE_BITSCANFORWARD64)
_BitScanForward64(&result, *x);
*x >>= result;
#elif defined(HAVE_BITSCANFORWARD)
_BitScanForward(&result, *x);
*x >>= result;
#else
result = 0;
while ((*x & 1) == 0) {
++result;
*x >>= 1;
}
#endif
return result;
}
/* /*
@ -106,9 +195,9 @@ METHODDEF(void) finish_pass_gather_phuff (j_compress_ptr cinfo);
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics) start_pass_phuff(j_compress_ptr cinfo, boolean gather_statistics)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy;
boolean is_DC_band; boolean is_DC_band;
int ci, tbl; int ci, tbl;
jpeg_component_info *compptr; jpeg_component_info *compptr;
@ -126,15 +215,23 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
entropy->pub.encode_mcu = encode_mcu_DC_first; entropy->pub.encode_mcu = encode_mcu_DC_first;
else else
entropy->pub.encode_mcu = encode_mcu_AC_first; entropy->pub.encode_mcu = encode_mcu_AC_first;
if (jsimd_can_encode_mcu_AC_first_prepare())
entropy->AC_first_prepare = jsimd_encode_mcu_AC_first_prepare;
else
entropy->AC_first_prepare = encode_mcu_AC_first_prepare;
} else { } else {
if (is_DC_band) if (is_DC_band)
entropy->pub.encode_mcu = encode_mcu_DC_refine; entropy->pub.encode_mcu = encode_mcu_DC_refine;
else { else {
entropy->pub.encode_mcu = encode_mcu_AC_refine; entropy->pub.encode_mcu = encode_mcu_AC_refine;
if (jsimd_can_encode_mcu_AC_refine_prepare())
entropy->AC_refine_prepare = jsimd_encode_mcu_AC_refine_prepare;
else
entropy->AC_refine_prepare = encode_mcu_AC_refine_prepare;
/* AC refinement needs a correction bit buffer */ /* AC refinement needs a correction bit buffer */
if (entropy->bit_buffer == NULL) if (entropy->bit_buffer == NULL)
entropy->bit_buffer = (char *) entropy->bit_buffer = (char *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
MAX_CORR_BITS * sizeof(char)); MAX_CORR_BITS * sizeof(char));
} }
} }
@ -167,14 +264,14 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
/* Note that jpeg_gen_optimal_table expects 257 entries in each table! */ /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
if (entropy->count_ptrs[tbl] == NULL) if (entropy->count_ptrs[tbl] == NULL)
entropy->count_ptrs[tbl] = (long *) entropy->count_ptrs[tbl] = (long *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
257 * sizeof(long)); 257 * sizeof(long));
MEMZERO(entropy->count_ptrs[tbl], 257 * sizeof(long)); MEMZERO(entropy->count_ptrs[tbl], 257 * sizeof(long));
} else { } else {
/* Compute derived values for Huffman table */ /* Compute derived values for Huffman table */
/* We may do this more than once for a table, but it's not expensive */ /* We may do this more than once for a table, but it's not expensive */
jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl, jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
& entropy->derived_tbls[tbl]); &entropy->derived_tbls[tbl]);
} }
} }
@ -198,19 +295,20 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
*/ */
/* Emit a byte */ /* Emit a byte */
#define emit_byte(entropy,val) \ #define emit_byte(entropy, val) { \
{ *(entropy)->next_output_byte++ = (JOCTET) (val); \ *(entropy)->next_output_byte++ = (JOCTET)(val); \
if (--(entropy)->free_in_buffer == 0) \ if (--(entropy)->free_in_buffer == 0) \
dump_buffer(entropy); } dump_buffer(entropy); \
}
LOCAL(void) LOCAL(void)
dump_buffer (phuff_entropy_ptr entropy) dump_buffer(phuff_entropy_ptr entropy)
/* Empty the output buffer; we do not support suspension in this module. */ /* Empty the output buffer; we do not support suspension in this module. */
{ {
struct jpeg_destination_mgr *dest = entropy->cinfo->dest; struct jpeg_destination_mgr *dest = entropy->cinfo->dest;
if (! (*dest->empty_output_buffer) (entropy->cinfo)) if (!(*dest->empty_output_buffer) (entropy->cinfo))
ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND); ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
/* After a successful buffer dump, must reset buffer pointers */ /* After a successful buffer dump, must reset buffer pointers */
entropy->next_output_byte = dest->next_output_byte; entropy->next_output_byte = dest->next_output_byte;
@ -227,11 +325,11 @@ dump_buffer (phuff_entropy_ptr entropy)
*/ */
LOCAL(void) LOCAL(void)
emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size) emit_bits(phuff_entropy_ptr entropy, unsigned int code, int size)
/* Emit some bits, unless we are in gather mode */ /* Emit some bits, unless we are in gather mode */
{ {
/* This routine is heavily used, so it's worth coding tightly. */ /* This routine is heavily used, so it's worth coding tightly. */
register size_t put_buffer = (size_t) code; register size_t put_buffer = (size_t)code;
register int put_bits = entropy->put_bits; register int put_bits = entropy->put_bits;
/* if size is 0, caller used an invalid Huffman table entry */ /* if size is 0, caller used an invalid Huffman table entry */
@ -241,7 +339,7 @@ emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size)
if (entropy->gather_statistics) if (entropy->gather_statistics)
return; /* do nothing if we're only getting stats */ return; /* do nothing if we're only getting stats */
put_buffer &= (((size_t) 1)<<size) - 1; /* mask off any extra bits in code */ put_buffer &= (((size_t)1) << size) - 1; /* mask off any extra bits in code */
put_bits += size; /* new number of bits in buffer */ put_bits += size; /* new number of bits in buffer */
@ -250,7 +348,7 @@ emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size)
put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */ put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
while (put_bits >= 8) { while (put_bits >= 8) {
int c = (int) ((put_buffer >> 16) & 0xFF); int c = (int)((put_buffer >> 16) & 0xFF);
emit_byte(entropy, c); emit_byte(entropy, c);
if (c == 0xFF) { /* need to stuff a zero byte? */ if (c == 0xFF) { /* need to stuff a zero byte? */
@ -266,7 +364,7 @@ emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size)
LOCAL(void) LOCAL(void)
flush_bits (phuff_entropy_ptr entropy) flush_bits(phuff_entropy_ptr entropy)
{ {
emit_bits(entropy, 0x7F, 7); /* fill any partial byte with ones */ emit_bits(entropy, 0x7F, 7); /* fill any partial byte with ones */
entropy->put_buffer = 0; /* and reset bit-buffer to empty */ entropy->put_buffer = 0; /* and reset bit-buffer to empty */
@ -279,7 +377,7 @@ flush_bits (phuff_entropy_ptr entropy)
*/ */
LOCAL(void) LOCAL(void)
emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol) emit_symbol(phuff_entropy_ptr entropy, int tbl_no, int symbol)
{ {
if (entropy->gather_statistics) if (entropy->gather_statistics)
entropy->count_ptrs[tbl_no][symbol]++; entropy->count_ptrs[tbl_no][symbol]++;
@ -295,14 +393,14 @@ emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
*/ */
LOCAL(void) LOCAL(void)
emit_buffered_bits (phuff_entropy_ptr entropy, char *bufstart, emit_buffered_bits(phuff_entropy_ptr entropy, char *bufstart,
unsigned int nbits) unsigned int nbits)
{ {
if (entropy->gather_statistics) if (entropy->gather_statistics)
return; /* no real work */ return; /* no real work */
while (nbits > 0) { while (nbits > 0) {
emit_bits(entropy, (unsigned int) (*bufstart), 1); emit_bits(entropy, (unsigned int)(*bufstart), 1);
bufstart++; bufstart++;
nbits--; nbits--;
} }
@ -314,15 +412,13 @@ emit_buffered_bits (phuff_entropy_ptr entropy, char *bufstart,
*/ */
LOCAL(void) LOCAL(void)
emit_eobrun (phuff_entropy_ptr entropy) emit_eobrun(phuff_entropy_ptr entropy)
{ {
register int temp, nbits; register int temp, nbits;
if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */ if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
temp = entropy->EOBRUN; temp = entropy->EOBRUN;
nbits = 0; nbits = JPEG_NBITS_NONZERO(temp) - 1;
while ((temp >>= 1))
nbits++;
/* safety check: shouldn't happen given limited correction-bit buffer */ /* safety check: shouldn't happen given limited correction-bit buffer */
if (nbits > 14) if (nbits > 14)
ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE); ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
@ -345,13 +441,13 @@ emit_eobrun (phuff_entropy_ptr entropy)
*/ */
LOCAL(void) LOCAL(void)
emit_restart (phuff_entropy_ptr entropy, int restart_num) emit_restart(phuff_entropy_ptr entropy, int restart_num)
{ {
int ci; int ci;
emit_eobrun(entropy); emit_eobrun(entropy);
if (! entropy->gather_statistics) { if (!entropy->gather_statistics) {
flush_bits(entropy); flush_bits(entropy);
emit_byte(entropy, 0xFF); emit_byte(entropy, 0xFF);
emit_byte(entropy, JPEG_RST0 + restart_num); emit_byte(entropy, JPEG_RST0 + restart_num);
@ -375,10 +471,10 @@ emit_restart (phuff_entropy_ptr entropy, int restart_num)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_DC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy;
register int temp, temp2; register int temp, temp2, temp3;
register int nbits; register int nbits;
int blkn, ci; int blkn, ci;
int Al = cinfo->Al; int Al = cinfo->Al;
@ -403,31 +499,31 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Compute the DC value after the required point transform by Al. /* Compute the DC value after the required point transform by Al.
* This is simply an arithmetic right shift. * This is simply an arithmetic right shift.
*/ */
temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al); temp2 = IRIGHT_SHIFT((int)((*block)[0]), Al);
/* DC differences are figured on the point-transformed values. */ /* DC differences are figured on the point-transformed values. */
temp = temp2 - entropy->last_dc_val[ci]; temp = temp2 - entropy->last_dc_val[ci];
entropy->last_dc_val[ci] = temp2; entropy->last_dc_val[ci] = temp2;
/* Encode the DC coefficient difference per section G.1.2.1 */ /* Encode the DC coefficient difference per section G.1.2.1 */
temp2 = temp;
if (temp < 0) { /* This is a well-known technique for obtaining the absolute value without
temp = -temp; /* temp is abs value of input */ * a branch. It is derived from an assembly language technique presented
* in "How to Optimize for the Pentium Processors", Copyright (c) 1996,
* 1997 by Agner Fog.
*/
temp3 = temp >> (CHAR_BIT * sizeof(int) - 1);
temp ^= temp3;
temp -= temp3; /* temp is abs value of input */
/* For a negative input, want temp2 = bitwise complement of abs(input) */ /* For a negative input, want temp2 = bitwise complement of abs(input) */
/* This code assumes we are on a two's complement machine */ temp2 = temp ^ temp3;
temp2--;
}
/* Find the number of bits needed for the magnitude of the coefficient */ /* Find the number of bits needed for the magnitude of the coefficient */
nbits = 0; nbits = JPEG_NBITS(temp);
while (temp) {
nbits++;
temp >>= 1;
}
/* Check for out-of-range coefficient values. /* Check for out-of-range coefficient values.
* Since we're encoding a difference, the range limit is twice as much. * Since we're encoding a difference, the range limit is twice as much.
*/ */
if (nbits > MAX_COEF_BITS+1) if (nbits > MAX_COEF_BITS + 1)
ERREXIT(cinfo, JERR_BAD_DCT_COEF); ERREXIT(cinfo, JERR_BAD_DCT_COEF);
/* Count/emit the Huffman-coded symbol for the number of bits */ /* Count/emit the Huffman-coded symbol for the number of bits */
@ -436,7 +532,7 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Emit that number of bits of the value, if positive, */ /* Emit that number of bits of the value, if positive, */
/* or the complement of its magnitude, if negative. */ /* or the complement of its magnitude, if negative. */
if (nbits) /* emit_bits rejects calls with size 0 */ if (nbits) /* emit_bits rejects calls with size 0 */
emit_bits(entropy, (unsigned int) temp2, nbits); emit_bits(entropy, (unsigned int)temp2, nbits);
} }
cinfo->dest->next_output_byte = entropy->next_output_byte; cinfo->dest->next_output_byte = entropy->next_output_byte;
@ -456,21 +552,116 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/*
* Data preparation for encode_mcu_AC_first().
*/
#define COMPUTE_ABSVALUES_AC_FIRST(Sl) { \
for (k = 0; k < Sl; k++) { \
temp = block[jpeg_natural_order_start[k]]; \
if (temp == 0) \
continue; \
/* We must apply the point transform by Al. For AC coefficients this \
* is an integer division with rounding towards 0. To do this portably \
* in C, we shift after obtaining the absolute value; so the code is \
* interwoven with finding the abs value (temp) and output bits (temp2). \
*/ \
temp2 = temp >> (CHAR_BIT * sizeof(int) - 1); \
temp ^= temp2; \
temp -= temp2; /* temp is abs value of input */ \
temp >>= Al; /* apply the point transform */ \
/* Watch out for case that nonzero coef is zero after point transform */ \
if (temp == 0) \
continue; \
/* For a negative coef, want temp2 = bitwise complement of abs(coef) */ \
temp2 ^= temp; \
values[k] = temp; \
values[k + DCTSIZE2] = temp2; \
zerobits |= ((size_t)1U) << k; \
} \
}
METHODDEF(void)
encode_mcu_AC_first_prepare(const JCOEF *block,
const int *jpeg_natural_order_start, int Sl,
int Al, JCOEF *values, size_t *bits)
{
register int k, temp, temp2;
size_t zerobits = 0U;
int Sl0 = Sl;
#if SIZEOF_SIZE_T == 4
if (Sl0 > 32)
Sl0 = 32;
#endif
COMPUTE_ABSVALUES_AC_FIRST(Sl0);
bits[0] = zerobits;
#if SIZEOF_SIZE_T == 4
zerobits = 0U;
if (Sl > 32) {
Sl -= 32;
jpeg_natural_order_start += 32;
values += 32;
COMPUTE_ABSVALUES_AC_FIRST(Sl);
}
bits[1] = zerobits;
#endif
}
/* /*
* MCU encoding for AC initial scan (either spectral selection, * MCU encoding for AC initial scan (either spectral selection,
* or first pass of successive approximation). * or first pass of successive approximation).
*/ */
#define ENCODE_COEFS_AC_FIRST(label) { \
while (zerobits) { \
r = count_zeroes(&zerobits); \
cvalue += r; \
label \
temp = cvalue[0]; \
temp2 = cvalue[DCTSIZE2]; \
\
/* if run length > 15, must emit special run-length-16 codes (0xF0) */ \
while (r > 15) { \
emit_symbol(entropy, entropy->ac_tbl_no, 0xF0); \
r -= 16; \
} \
\
/* Find the number of bits needed for the magnitude of the coefficient */ \
nbits = JPEG_NBITS_NONZERO(temp); /* there must be at least one 1 bit */ \
/* Check for out-of-range coefficient values */ \
if (nbits > MAX_COEF_BITS) \
ERREXIT(cinfo, JERR_BAD_DCT_COEF); \
\
/* Count/emit Huffman symbol for run length / number of bits */ \
emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits); \
\
/* Emit that number of bits of the value, if positive, */ \
/* or the complement of its magnitude, if negative. */ \
emit_bits(entropy, (unsigned int)temp2, nbits); \
\
cvalue++; \
zerobits >>= 1; \
} \
}
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_AC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy;
register int temp, temp2; register int temp, temp2;
register int nbits; register int nbits, r;
register int r, k; int Sl = cinfo->Se - cinfo->Ss + 1;
int Se = cinfo->Se;
int Al = cinfo->Al; int Al = cinfo->Al;
JBLOCKROW block; JCOEF values_unaligned[2 * DCTSIZE2 + 15];
JCOEF *values;
const JCOEF *cvalue;
size_t zerobits;
size_t bits[8 / SIZEOF_SIZE_T];
entropy->next_output_byte = cinfo->dest->next_output_byte; entropy->next_output_byte = cinfo->dest->next_output_byte;
entropy->free_in_buffer = cinfo->dest->free_in_buffer; entropy->free_in_buffer = cinfo->dest->free_in_buffer;
@ -480,66 +671,48 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
if (entropy->restarts_to_go == 0) if (entropy->restarts_to_go == 0)
emit_restart(entropy, entropy->next_restart_num); emit_restart(entropy, entropy->next_restart_num);
/* Encode the MCU data block */ #ifdef WITH_SIMD
block = MCU_data[0]; cvalue = values = (JCOEF *)PAD((size_t)values_unaligned, 16);
#else
/* Not using SIMD, so alignment is not needed */
cvalue = values = values_unaligned;
#endif
/* Prepare data */
entropy->AC_first_prepare(MCU_data[0][0], jpeg_natural_order + cinfo->Ss,
Sl, Al, values, bits);
zerobits = bits[0];
#if SIZEOF_SIZE_T == 4
zerobits |= bits[1];
#endif
/* Emit any pending EOBRUN */
if (zerobits && (entropy->EOBRUN > 0))
emit_eobrun(entropy);
#if SIZEOF_SIZE_T == 4
zerobits = bits[0];
#endif
/* Encode the AC coefficients per section G.1.2.2, fig. G.3 */ /* Encode the AC coefficients per section G.1.2.2, fig. G.3 */
r = 0; /* r = run length of zeros */ ENCODE_COEFS_AC_FIRST((void)0;);
for (k = cinfo->Ss; k <= Se; k++) { #if SIZEOF_SIZE_T == 4
if ((temp = (*block)[jpeg_natural_order[k]]) == 0) { zerobits = bits[1];
r++; if (zerobits) {
continue; int diff = ((values + DCTSIZE2 / 2) - cvalue);
} r = count_zeroes(&zerobits);
/* We must apply the point transform by Al. For AC coefficients this r += diff;
* is an integer division with rounding towards 0. To do this portably cvalue += r;
* in C, we shift after obtaining the absolute value; so the code is goto first_iter_ac_first;
* interwoven with finding the abs value (temp) and output bits (temp2).
*/
if (temp < 0) {
temp = -temp; /* temp is abs value of input */
temp >>= Al; /* apply the point transform */
/* For a negative coef, want temp2 = bitwise complement of abs(coef) */
temp2 = ~temp;
} else {
temp >>= Al; /* apply the point transform */
temp2 = temp;
}
/* Watch out for case that nonzero coef is zero after point transform */
if (temp == 0) {
r++;
continue;
} }
/* Emit any pending EOBRUN */ ENCODE_COEFS_AC_FIRST(first_iter_ac_first:);
if (entropy->EOBRUN > 0) #endif
emit_eobrun(entropy);
/* if run length > 15, must emit special run-length-16 codes (0xF0) */
while (r > 15) {
emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
r -= 16;
}
/* Find the number of bits needed for the magnitude of the coefficient */ if (cvalue < (values + Sl)) { /* If there are trailing zeroes, */
nbits = 1; /* there must be at least one 1 bit */
while ((temp >>= 1))
nbits++;
/* Check for out-of-range coefficient values */
if (nbits > MAX_COEF_BITS)
ERREXIT(cinfo, JERR_BAD_DCT_COEF);
/* Count/emit Huffman symbol for run length / number of bits */
emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
/* Emit that number of bits of the value, if positive, */
/* or the complement of its magnitude, if negative. */
emit_bits(entropy, (unsigned int) temp2, nbits);
r = 0; /* reset zero run length */
}
if (r > 0) { /* If there are trailing zeroes, */
entropy->EOBRUN++; /* count an EOB */ entropy->EOBRUN++; /* count an EOB */
if (entropy->EOBRUN == 0x7FFF) if (entropy->EOBRUN == 0x7FFF)
emit_eobrun(entropy); /* force it out to avoid overflow */ emit_eobrun(entropy); /* force it out to avoid overflow */
@ -569,9 +742,9 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_DC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy;
register int temp; register int temp;
int blkn; int blkn;
int Al = cinfo->Al; int Al = cinfo->Al;
@ -591,7 +764,7 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* We simply emit the Al'th bit of the DC coefficient value. */ /* We simply emit the Al'th bit of the DC coefficient value. */
temp = (*block)[0]; temp = (*block)[0];
emit_bits(entropy, (unsigned int) (temp >> Al), 1); emit_bits(entropy, (unsigned int)(temp >> Al), 1);
} }
cinfo->dest->next_output_byte = entropy->next_output_byte; cinfo->dest->next_output_byte = entropy->next_output_byte;
@ -611,23 +784,149 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/*
* Data preparation for encode_mcu_AC_refine().
*/
#define COMPUTE_ABSVALUES_AC_REFINE(Sl, koffset) { \
/* It is convenient to make a pre-pass to determine the transformed \
* coefficients' absolute values and the EOB position. \
*/ \
for (k = 0; k < Sl; k++) { \
temp = block[jpeg_natural_order_start[k]]; \
/* We must apply the point transform by Al. For AC coefficients this \
* is an integer division with rounding towards 0. To do this portably \
* in C, we shift after obtaining the absolute value. \
*/ \
temp2 = temp >> (CHAR_BIT * sizeof(int) - 1); \
temp ^= temp2; \
temp -= temp2; /* temp is abs value of input */ \
temp >>= Al; /* apply the point transform */ \
if (temp != 0) { \
zerobits |= ((size_t)1U) << k; \
signbits |= ((size_t)(temp2 + 1)) << k; \
} \
absvalues[k] = (JCOEF)temp; /* save abs value for main pass */ \
if (temp == 1) \
EOB = k + koffset; /* EOB = index of last newly-nonzero coef */ \
} \
}
METHODDEF(int)
encode_mcu_AC_refine_prepare(const JCOEF *block,
const int *jpeg_natural_order_start, int Sl,
int Al, JCOEF *absvalues, size_t *bits)
{
register int k, temp, temp2;
int EOB = 0;
size_t zerobits = 0U, signbits = 0U;
int Sl0 = Sl;
#if SIZEOF_SIZE_T == 4
if (Sl0 > 32)
Sl0 = 32;
#endif
COMPUTE_ABSVALUES_AC_REFINE(Sl0, 0);
bits[0] = zerobits;
#if SIZEOF_SIZE_T == 8
bits[1] = signbits;
#else
bits[2] = signbits;
zerobits = 0U;
signbits = 0U;
if (Sl > 32) {
Sl -= 32;
jpeg_natural_order_start += 32;
absvalues += 32;
COMPUTE_ABSVALUES_AC_REFINE(Sl, 32);
}
bits[1] = zerobits;
bits[3] = signbits;
#endif
return EOB;
}
/* /*
* MCU encoding for AC successive approximation refinement scan. * MCU encoding for AC successive approximation refinement scan.
*/ */
#define ENCODE_COEFS_AC_REFINE(label) { \
while (zerobits) { \
int idx = count_zeroes(&zerobits); \
r += idx; \
cabsvalue += idx; \
signbits >>= idx; \
label \
/* Emit any required ZRLs, but not if they can be folded into EOB */ \
while (r > 15 && (cabsvalue <= EOBPTR)) { \
/* emit any pending EOBRUN and the BE correction bits */ \
emit_eobrun(entropy); \
/* Emit ZRL */ \
emit_symbol(entropy, entropy->ac_tbl_no, 0xF0); \
r -= 16; \
/* Emit buffered correction bits that must be associated with ZRL */ \
emit_buffered_bits(entropy, BR_buffer, BR); \
BR_buffer = entropy->bit_buffer; /* BE bits are gone now */ \
BR = 0; \
} \
\
temp = *cabsvalue++; \
\
/* If the coef was previously nonzero, it only needs a correction bit. \
* NOTE: a straight translation of the spec's figure G.7 would suggest \
* that we also need to test r > 15. But if r > 15, we can only get here \
* if k > EOB, which implies that this coefficient is not 1. \
*/ \
if (temp > 1) { \
/* The correction bit is the next bit of the absolute value. */ \
BR_buffer[BR++] = (char)(temp & 1); \
signbits >>= 1; \
zerobits >>= 1; \
continue; \
} \
\
/* Emit any pending EOBRUN and the BE correction bits */ \
emit_eobrun(entropy); \
\
/* Count/emit Huffman symbol for run length / number of bits */ \
emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1); \
\
/* Emit output bit for newly-nonzero coef */ \
temp = signbits & 1; /* ((*block)[jpeg_natural_order_start[k]] < 0) ? 0 : 1 */ \
emit_bits(entropy, (unsigned int)temp, 1); \
\
/* Emit buffered correction bits that must be associated with this code */ \
emit_buffered_bits(entropy, BR_buffer, BR); \
BR_buffer = entropy->bit_buffer; /* BE bits are gone now */ \
BR = 0; \
r = 0; /* reset zero run length */ \
signbits >>= 1; \
zerobits >>= 1; \
} \
}
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy;
register int temp; register int temp, r;
register int r, k;
int EOB;
char *BR_buffer; char *BR_buffer;
unsigned int BR; unsigned int BR;
int Se = cinfo->Se; int Sl = cinfo->Se - cinfo->Ss + 1;
int Al = cinfo->Al; int Al = cinfo->Al;
JBLOCKROW block; JCOEF absvalues_unaligned[DCTSIZE2 + 15];
int absvalues[DCTSIZE2]; JCOEF *absvalues;
const JCOEF *cabsvalue, *EOBPTR;
size_t zerobits, signbits;
size_t bits[16 / SIZEOF_SIZE_T];
entropy->next_output_byte = cinfo->dest->next_output_byte; entropy->next_output_byte = cinfo->dest->next_output_byte;
entropy->free_in_buffer = cinfo->dest->free_in_buffer; entropy->free_in_buffer = cinfo->dest->free_in_buffer;
@ -637,26 +936,17 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
if (entropy->restarts_to_go == 0) if (entropy->restarts_to_go == 0)
emit_restart(entropy, entropy->next_restart_num); emit_restart(entropy, entropy->next_restart_num);
/* Encode the MCU data block */ #ifdef WITH_SIMD
block = MCU_data[0]; cabsvalue = absvalues = (JCOEF *)PAD((size_t)absvalues_unaligned, 16);
#else
/* Not using SIMD, so alignment is not needed */
cabsvalue = absvalues = absvalues_unaligned;
#endif
/* It is convenient to make a pre-pass to determine the transformed /* Prepare data */
* coefficients' absolute values and the EOB position. EOBPTR = absvalues +
*/ entropy->AC_refine_prepare(MCU_data[0][0], jpeg_natural_order + cinfo->Ss,
EOB = 0; Sl, Al, absvalues, bits);
for (k = cinfo->Ss; k <= Se; k++) {
temp = (*block)[jpeg_natural_order[k]];
/* We must apply the point transform by Al. For AC coefficients this
* is an integer division with rounding towards 0. To do this portably
* in C, we shift after obtaining the absolute value.
*/
if (temp < 0)
temp = -temp; /* temp is abs value of input */
temp >>= Al; /* apply the point transform */
absvalues[k] = temp; /* save abs value for main pass */
if (temp == 1)
EOB = k; /* EOB = index of last newly-nonzero coef */
}
/* Encode the AC coefficients per section G.1.2.3, fig. G.7 */ /* Encode the AC coefficients per section G.1.2.3, fig. G.7 */
@ -664,52 +954,32 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
BR = 0; /* BR = count of buffered bits added now */ BR = 0; /* BR = count of buffered bits added now */
BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */ BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
for (k = cinfo->Ss; k <= Se; k++) { zerobits = bits[0];
if ((temp = absvalues[k]) == 0) { #if SIZEOF_SIZE_T == 8
r++; signbits = bits[1];
continue; #else
signbits = bits[2];
#endif
ENCODE_COEFS_AC_REFINE((void)0;);
#if SIZEOF_SIZE_T == 4
zerobits = bits[1];
signbits = bits[3];
if (zerobits) {
int diff = ((absvalues + DCTSIZE2 / 2) - cabsvalue);
int idx = count_zeroes(&zerobits);
signbits >>= idx;
idx += diff;
r += idx;
cabsvalue += idx;
goto first_iter_ac_refine;
} }
/* Emit any required ZRLs, but not if they can be folded into EOB */ ENCODE_COEFS_AC_REFINE(first_iter_ac_refine:);
while (r > 15 && k <= EOB) { #endif
/* emit any pending EOBRUN and the BE correction bits */
emit_eobrun(entropy);
/* Emit ZRL */
emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
r -= 16;
/* Emit buffered correction bits that must be associated with ZRL */
emit_buffered_bits(entropy, BR_buffer, BR);
BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
BR = 0;
}
/* If the coef was previously nonzero, it only needs a correction bit. r |= (int)((absvalues + Sl) - cabsvalue);
* NOTE: a straight translation of the spec's figure G.7 would suggest
* that we also need to test r > 15. But if r > 15, we can only get here
* if k > EOB, which implies that this coefficient is not 1.
*/
if (temp > 1) {
/* The correction bit is the next bit of the absolute value. */
BR_buffer[BR++] = (char) (temp & 1);
continue;
}
/* Emit any pending EOBRUN and the BE correction bits */
emit_eobrun(entropy);
/* Count/emit Huffman symbol for run length / number of bits */
emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
/* Emit output bit for newly-nonzero coef */
temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
emit_bits(entropy, (unsigned int) temp, 1);
/* Emit buffered correction bits that must be associated with this code */
emit_buffered_bits(entropy, BR_buffer, BR);
BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
BR = 0;
r = 0; /* reset zero run length */
}
if (r > 0 || BR > 0) { /* If there are trailing zeroes, */ if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
entropy->EOBRUN++; /* count an EOB */ entropy->EOBRUN++; /* count an EOB */
@ -718,7 +988,8 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
* 1. overflow of the EOB counter; * 1. overflow of the EOB counter;
* 2. overflow of the correction bit buffer during the next MCU. * 2. overflow of the correction bit buffer during the next MCU.
*/ */
if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1)) if (entropy->EOBRUN == 0x7FFF ||
entropy->BE > (MAX_CORR_BITS - DCTSIZE2 + 1))
emit_eobrun(entropy); emit_eobrun(entropy);
} }
@ -744,9 +1015,9 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(void) METHODDEF(void)
finish_pass_phuff (j_compress_ptr cinfo) finish_pass_phuff(j_compress_ptr cinfo)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy;
entropy->next_output_byte = cinfo->dest->next_output_byte; entropy->next_output_byte = cinfo->dest->next_output_byte;
entropy->free_in_buffer = cinfo->dest->free_in_buffer; entropy->free_in_buffer = cinfo->dest->free_in_buffer;
@ -765,9 +1036,9 @@ finish_pass_phuff (j_compress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
finish_pass_gather_phuff (j_compress_ptr cinfo) finish_pass_gather_phuff(j_compress_ptr cinfo)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy;
boolean is_DC_band; boolean is_DC_band;
int ci, tbl; int ci, tbl;
jpeg_component_info *compptr; jpeg_component_info *compptr;
@ -793,13 +1064,13 @@ finish_pass_gather_phuff (j_compress_ptr cinfo)
} else { } else {
tbl = compptr->ac_tbl_no; tbl = compptr->ac_tbl_no;
} }
if (! did[tbl]) { if (!did[tbl]) {
if (is_DC_band) if (is_DC_band)
htblptr = & cinfo->dc_huff_tbl_ptrs[tbl]; htblptr = &cinfo->dc_huff_tbl_ptrs[tbl];
else else
htblptr = & cinfo->ac_huff_tbl_ptrs[tbl]; htblptr = &cinfo->ac_huff_tbl_ptrs[tbl];
if (*htblptr == NULL) if (*htblptr == NULL)
*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); *htblptr = jpeg_alloc_huff_table((j_common_ptr)cinfo);
jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]); jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
did[tbl] = TRUE; did[tbl] = TRUE;
} }
@ -812,15 +1083,15 @@ finish_pass_gather_phuff (j_compress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_phuff_encoder (j_compress_ptr cinfo) jinit_phuff_encoder(j_compress_ptr cinfo)
{ {
phuff_entropy_ptr entropy; phuff_entropy_ptr entropy;
int i; int i;
entropy = (phuff_entropy_ptr) entropy = (phuff_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(phuff_entropy_encoder)); sizeof(phuff_entropy_encoder));
cinfo->entropy = (struct jpeg_entropy_encoder *) entropy; cinfo->entropy = (struct jpeg_entropy_encoder *)entropy;
entropy->pub.start_pass = start_pass_phuff; entropy->pub.start_pass = start_pass_phuff;
/* Mark tables unallocated */ /* Mark tables unallocated */

View File

@ -78,9 +78,9 @@ typedef my_prep_controller *my_prep_ptr;
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode) start_pass_prep(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
{ {
my_prep_ptr prep = (my_prep_ptr) cinfo->prep; my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
if (pass_mode != JBUF_PASS_THRU) if (pass_mode != JBUF_PASS_THRU)
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
@ -106,14 +106,14 @@ start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
*/ */
LOCAL(void) LOCAL(void)
expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols, expand_bottom_edge(JSAMPARRAY image_data, JDIMENSION num_cols, int input_rows,
int input_rows, int output_rows) int output_rows)
{ {
register int row; register int row;
for (row = input_rows; row < output_rows; row++) { for (row = input_rows; row < output_rows; row++) {
jcopy_sample_rows(image_data, input_rows-1, image_data, row, jcopy_sample_rows(image_data, input_rows - 1, image_data, row, 1,
1, num_cols); num_cols);
} }
} }
@ -128,13 +128,12 @@ expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
*/ */
METHODDEF(void) METHODDEF(void)
pre_process_data (j_compress_ptr cinfo, pre_process_data(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail,
JDIMENSION in_rows_avail,
JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
JDIMENSION out_row_groups_avail) JDIMENSION out_row_groups_avail)
{ {
my_prep_ptr prep = (my_prep_ptr) cinfo->prep; my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
int numrows, ci; int numrows, ci;
JDIMENSION inrows; JDIMENSION inrows;
jpeg_component_info *compptr; jpeg_component_info *compptr;
@ -144,10 +143,10 @@ pre_process_data (j_compress_ptr cinfo,
/* Do color conversion to fill the conversion buffer. */ /* Do color conversion to fill the conversion buffer. */
inrows = in_rows_avail - *in_row_ctr; inrows = in_rows_avail - *in_row_ctr;
numrows = cinfo->max_v_samp_factor - prep->next_buf_row; numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
numrows = (int) MIN((JDIMENSION) numrows, inrows); numrows = (int)MIN((JDIMENSION)numrows, inrows);
(*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
prep->color_buf, prep->color_buf,
(JDIMENSION) prep->next_buf_row, (JDIMENSION)prep->next_buf_row,
numrows); numrows);
*in_row_ctr += numrows; *in_row_ctr += numrows;
prep->next_buf_row += numrows; prep->next_buf_row += numrows;
@ -164,7 +163,7 @@ pre_process_data (j_compress_ptr cinfo,
/* If we've filled the conversion buffer, empty it. */ /* If we've filled the conversion buffer, empty it. */
if (prep->next_buf_row == cinfo->max_v_samp_factor) { if (prep->next_buf_row == cinfo->max_v_samp_factor) {
(*cinfo->downsample->downsample) (cinfo, (*cinfo->downsample->downsample) (cinfo,
prep->color_buf, (JDIMENSION) 0, prep->color_buf, (JDIMENSION)0,
output_buf, *out_row_group_ctr); output_buf, *out_row_group_ctr);
prep->next_buf_row = 0; prep->next_buf_row = 0;
(*out_row_group_ctr)++; (*out_row_group_ctr)++;
@ -172,14 +171,12 @@ pre_process_data (j_compress_ptr cinfo,
/* If at bottom of image, pad the output to a full iMCU height. /* If at bottom of image, pad the output to a full iMCU height.
* Note we assume the caller is providing a one-iMCU-height output buffer! * Note we assume the caller is providing a one-iMCU-height output buffer!
*/ */
if (prep->rows_to_go == 0 && if (prep->rows_to_go == 0 && *out_row_group_ctr < out_row_groups_avail) {
*out_row_group_ctr < out_row_groups_avail) {
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
expand_bottom_edge(output_buf[ci], expand_bottom_edge(output_buf[ci], compptr->width_in_blocks * DCTSIZE,
compptr->width_in_blocks * DCTSIZE, (int)(*out_row_group_ctr * compptr->v_samp_factor),
(int) (*out_row_group_ctr * compptr->v_samp_factor), (int)(out_row_groups_avail * compptr->v_samp_factor));
(int) (out_row_groups_avail * compptr->v_samp_factor));
} }
*out_row_group_ctr = out_row_groups_avail; *out_row_group_ctr = out_row_groups_avail;
break; /* can exit outer loop without test */ break; /* can exit outer loop without test */
@ -195,13 +192,12 @@ pre_process_data (j_compress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
pre_process_context (j_compress_ptr cinfo, pre_process_context(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail,
JDIMENSION in_rows_avail,
JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
JDIMENSION out_row_groups_avail) JDIMENSION out_row_groups_avail)
{ {
my_prep_ptr prep = (my_prep_ptr) cinfo->prep; my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
int numrows, ci; int numrows, ci;
int buf_height = cinfo->max_v_samp_factor * 3; int buf_height = cinfo->max_v_samp_factor * 3;
JDIMENSION inrows; JDIMENSION inrows;
@ -211,19 +207,18 @@ pre_process_context (j_compress_ptr cinfo,
/* Do color conversion to fill the conversion buffer. */ /* Do color conversion to fill the conversion buffer. */
inrows = in_rows_avail - *in_row_ctr; inrows = in_rows_avail - *in_row_ctr;
numrows = prep->next_buf_stop - prep->next_buf_row; numrows = prep->next_buf_stop - prep->next_buf_row;
numrows = (int) MIN((JDIMENSION) numrows, inrows); numrows = (int)MIN((JDIMENSION)numrows, inrows);
(*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
prep->color_buf, prep->color_buf,
(JDIMENSION) prep->next_buf_row, (JDIMENSION)prep->next_buf_row,
numrows); numrows);
/* Pad at top of image, if first time through */ /* Pad at top of image, if first time through */
if (prep->rows_to_go == cinfo->image_height) { if (prep->rows_to_go == cinfo->image_height) {
for (ci = 0; ci < cinfo->num_components; ci++) { for (ci = 0; ci < cinfo->num_components; ci++) {
int row; int row;
for (row = 1; row <= cinfo->max_v_samp_factor; row++) { for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
jcopy_sample_rows(prep->color_buf[ci], 0, jcopy_sample_rows(prep->color_buf[ci], 0, prep->color_buf[ci],
prep->color_buf[ci], -row, -row, 1, cinfo->image_width);
1, cinfo->image_width);
} }
} }
} }
@ -245,9 +240,8 @@ pre_process_context (j_compress_ptr cinfo,
} }
/* If we've gotten enough data, downsample a row group. */ /* If we've gotten enough data, downsample a row group. */
if (prep->next_buf_row == prep->next_buf_stop) { if (prep->next_buf_row == prep->next_buf_stop) {
(*cinfo->downsample->downsample) (cinfo, (*cinfo->downsample->downsample) (cinfo, prep->color_buf,
prep->color_buf, (JDIMENSION)prep->this_row_group,
(JDIMENSION) prep->this_row_group,
output_buf, *out_row_group_ctr); output_buf, *out_row_group_ctr);
(*out_row_group_ctr)++; (*out_row_group_ctr)++;
/* Advance pointers with wraparound as necessary. */ /* Advance pointers with wraparound as necessary. */
@ -267,9 +261,9 @@ pre_process_context (j_compress_ptr cinfo,
*/ */
LOCAL(void) LOCAL(void)
create_context_buffer (j_compress_ptr cinfo) create_context_buffer(j_compress_ptr cinfo)
{ {
my_prep_ptr prep = (my_prep_ptr) cinfo->prep; my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
int rgroup_height = cinfo->max_v_samp_factor; int rgroup_height = cinfo->max_v_samp_factor;
int ci, i; int ci, i;
jpeg_component_info *compptr; jpeg_component_info *compptr;
@ -279,7 +273,7 @@ create_context_buffer (j_compress_ptr cinfo)
* we need five row groups' worth of pointers for each component. * we need five row groups' worth of pointers for each component.
*/ */
fake_buffer = (JSAMPARRAY) fake_buffer = (JSAMPARRAY)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(cinfo->num_components * 5 * rgroup_height) * (cinfo->num_components * 5 * rgroup_height) *
sizeof(JSAMPROW)); sizeof(JSAMPROW));
@ -290,10 +284,10 @@ create_context_buffer (j_compress_ptr cinfo)
* horizontally within the buffer, if it so chooses. * horizontally within the buffer, if it so chooses.
*/ */
true_buffer = (*cinfo->mem->alloc_sarray) true_buffer = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr)cinfo, JPOOL_IMAGE,
(JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE * (JDIMENSION)(((long)compptr->width_in_blocks * DCTSIZE *
cinfo->max_h_samp_factor) / compptr->h_samp_factor), cinfo->max_h_samp_factor) / compptr->h_samp_factor),
(JDIMENSION) (3 * rgroup_height)); (JDIMENSION)(3 * rgroup_height));
/* Copy true buffer row pointers into the middle of the fake row array */ /* Copy true buffer row pointers into the middle of the fake row array */
MEMCOPY(fake_buffer + rgroup_height, true_buffer, MEMCOPY(fake_buffer + rgroup_height, true_buffer,
3 * rgroup_height * sizeof(JSAMPROW)); 3 * rgroup_height * sizeof(JSAMPROW));
@ -315,7 +309,7 @@ create_context_buffer (j_compress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer) jinit_c_prep_controller(j_compress_ptr cinfo, boolean need_full_buffer)
{ {
my_prep_ptr prep; my_prep_ptr prep;
int ci; int ci;
@ -325,9 +319,9 @@ jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
prep = (my_prep_ptr) prep = (my_prep_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_prep_controller)); sizeof(my_prep_controller));
cinfo->prep = (struct jpeg_c_prep_controller *) prep; cinfo->prep = (struct jpeg_c_prep_controller *)prep;
prep->pub.start_pass = start_pass_prep; prep->pub.start_pass = start_pass_prep;
/* Allocate the color conversion buffer. /* Allocate the color conversion buffer.
@ -348,10 +342,10 @@ jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
prep->color_buf[ci] = (*cinfo->mem->alloc_sarray) prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr)cinfo, JPOOL_IMAGE,
(JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE * (JDIMENSION)(((long)compptr->width_in_blocks * DCTSIZE *
cinfo->max_h_samp_factor) / compptr->h_samp_factor), cinfo->max_h_samp_factor) / compptr->h_samp_factor),
(JDIMENSION) cinfo->max_v_samp_factor); (JDIMENSION)cinfo->max_v_samp_factor);
} }
} }
} }

View File

@ -79,7 +79,7 @@ typedef my_downsampler *my_downsample_ptr;
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_downsample (j_compress_ptr cinfo) start_pass_downsample(j_compress_ptr cinfo)
{ {
/* no work for now */ /* no work for now */
} }
@ -91,14 +91,14 @@ start_pass_downsample (j_compress_ptr cinfo)
*/ */
LOCAL(void) LOCAL(void)
expand_right_edge (JSAMPARRAY image_data, int num_rows, expand_right_edge(JSAMPARRAY image_data, int num_rows, JDIMENSION input_cols,
JDIMENSION input_cols, JDIMENSION output_cols) JDIMENSION output_cols)
{ {
register JSAMPROW ptr; register JSAMPROW ptr;
register JSAMPLE pixval; register JSAMPLE pixval;
register int count; register int count;
int row; int row;
int numcols = (int) (output_cols - input_cols); int numcols = (int)(output_cols - input_cols);
if (numcols > 0) { if (numcols > 0) {
for (row = 0; row < num_rows; row++) { for (row = 0; row < num_rows; row++) {
@ -118,11 +118,11 @@ expand_right_edge (JSAMPARRAY image_data, int num_rows,
*/ */
METHODDEF(void) METHODDEF(void)
sep_downsample (j_compress_ptr cinfo, sep_downsample(j_compress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION in_row_index, JDIMENSION in_row_index, JSAMPIMAGE output_buf,
JSAMPIMAGE output_buf, JDIMENSION out_row_group_index) JDIMENSION out_row_group_index)
{ {
my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample; my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample;
int ci; int ci;
jpeg_component_info *compptr; jpeg_component_info *compptr;
JSAMPARRAY in_ptr, out_ptr; JSAMPARRAY in_ptr, out_ptr;
@ -144,7 +144,7 @@ sep_downsample (j_compress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
int_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr, int_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v; int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
@ -156,14 +156,14 @@ int_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor; h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor; v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
numpix = h_expand * v_expand; numpix = h_expand * v_expand;
numpix2 = numpix/2; numpix2 = numpix / 2;
/* Expand input data enough to let all the output samples be generated /* Expand input data enough to let all the output samples be generated
* by the standard loop. Special-casing padded output would be more * by the standard loop. Special-casing padded output would be more
* efficient. * efficient.
*/ */
expand_right_edge(input_data, cinfo->max_v_samp_factor, expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
cinfo->image_width, output_cols * h_expand); output_cols * h_expand);
inrow = 0; inrow = 0;
for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
@ -172,12 +172,12 @@ int_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
outcol++, outcol_h += h_expand) { outcol++, outcol_h += h_expand) {
outvalue = 0; outvalue = 0;
for (v = 0; v < v_expand; v++) { for (v = 0; v < v_expand; v++) {
inptr = input_data[inrow+v] + outcol_h; inptr = input_data[inrow + v] + outcol_h;
for (h = 0; h < h_expand; h++) { for (h = 0; h < h_expand; h++) {
outvalue += (JLONG) GETJSAMPLE(*inptr++); outvalue += (JLONG)GETJSAMPLE(*inptr++);
} }
} }
*outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix); *outptr++ = (JSAMPLE)((outvalue + numpix2) / numpix);
} }
inrow += v_expand; inrow += v_expand;
} }
@ -191,15 +191,15 @@ int_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
*/ */
METHODDEF(void) METHODDEF(void)
fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr, fullsize_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
/* Copy the data */ /* Copy the data */
jcopy_sample_rows(input_data, 0, output_data, 0, jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
cinfo->max_v_samp_factor, cinfo->image_width); cinfo->image_width);
/* Edge-expand */ /* Edge-expand */
expand_right_edge(output_data, cinfo->max_v_samp_factor, expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
cinfo->image_width, compptr->width_in_blocks * DCTSIZE); compptr->width_in_blocks * DCTSIZE);
} }
@ -216,7 +216,7 @@ fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
*/ */
METHODDEF(void) METHODDEF(void)
h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr, h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
int outrow; int outrow;
@ -229,16 +229,16 @@ h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
* by the standard loop. Special-casing padded output would be more * by the standard loop. Special-casing padded output would be more
* efficient. * efficient.
*/ */
expand_right_edge(input_data, cinfo->max_v_samp_factor, expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
cinfo->image_width, output_cols * 2); output_cols * 2);
for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
outptr = output_data[outrow]; outptr = output_data[outrow];
inptr = input_data[outrow]; inptr = input_data[outrow];
bias = 0; /* bias = 0,1,0,1,... for successive samples */ bias = 0; /* bias = 0,1,0,1,... for successive samples */
for (outcol = 0; outcol < output_cols; outcol++) { for (outcol = 0; outcol < output_cols; outcol++) {
*outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1]) *outptr++ =
+ bias) >> 1); (JSAMPLE)((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1]) + bias) >> 1);
bias ^= 1; /* 0=>1, 1=>0 */ bias ^= 1; /* 0=>1, 1=>0 */
inptr += 2; inptr += 2;
} }
@ -253,7 +253,7 @@ h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
*/ */
METHODDEF(void) METHODDEF(void)
h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr, h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
int inrow, outrow; int inrow, outrow;
@ -266,19 +266,19 @@ h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
* by the standard loop. Special-casing padded output would be more * by the standard loop. Special-casing padded output would be more
* efficient. * efficient.
*/ */
expand_right_edge(input_data, cinfo->max_v_samp_factor, expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
cinfo->image_width, output_cols * 2); output_cols * 2);
inrow = 0; inrow = 0;
for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
outptr = output_data[outrow]; outptr = output_data[outrow];
inptr0 = input_data[inrow]; inptr0 = input_data[inrow];
inptr1 = input_data[inrow+1]; inptr1 = input_data[inrow + 1];
bias = 1; /* bias = 1,2,1,2,... for successive samples */ bias = 1; /* bias = 1,2,1,2,... for successive samples */
for (outcol = 0; outcol < output_cols; outcol++) { for (outcol = 0; outcol < output_cols; outcol++) {
*outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + *outptr++ =
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]) (JSAMPLE)((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
+ bias) >> 2); GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]) + bias) >> 2);
bias ^= 3; /* 1=>2, 2=>1 */ bias ^= 3; /* 1=>2, 2=>1 */
inptr0 += 2; inptr1 += 2; inptr0 += 2; inptr1 += 2;
} }
@ -296,7 +296,7 @@ h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
*/ */
METHODDEF(void) METHODDEF(void)
h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr, h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
int inrow, outrow; int inrow, outrow;
@ -332,9 +332,9 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
outptr = output_data[outrow]; outptr = output_data[outrow];
inptr0 = input_data[inrow]; inptr0 = input_data[inrow];
inptr1 = input_data[inrow+1]; inptr1 = input_data[inrow + 1];
above_ptr = input_data[inrow-1]; above_ptr = input_data[inrow - 1];
below_ptr = input_data[inrow+2]; below_ptr = input_data[inrow + 2];
/* Special case for first column: pretend column -1 is same as column 0 */ /* Special case for first column: pretend column -1 is same as column 0 */
membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
@ -347,7 +347,7 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) + neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]); GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
*outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); *outptr++ = (JSAMPLE)((membersum + 32768) >> 16);
inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
for (colctr = output_cols - 2; colctr > 0; colctr--) { for (colctr = output_cols - 2; colctr > 0; colctr--) {
@ -367,7 +367,7 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
/* form final output scaled up by 2^16 */ /* form final output scaled up by 2^16 */
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
/* round, descale and output it */ /* round, descale and output it */
*outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); *outptr++ = (JSAMPLE)((membersum + 32768) >> 16);
inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
} }
@ -382,7 +382,7 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) + neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]); GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
*outptr = (JSAMPLE) ((membersum + 32768) >> 16); *outptr = (JSAMPLE)((membersum + 32768) >> 16);
inrow += 2; inrow += 2;
} }
@ -396,7 +396,7 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
*/ */
METHODDEF(void) METHODDEF(void)
fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr, fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
int outrow; int outrow;
@ -425,8 +425,8 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
outptr = output_data[outrow]; outptr = output_data[outrow];
inptr = input_data[outrow]; inptr = input_data[outrow];
above_ptr = input_data[outrow-1]; above_ptr = input_data[outrow - 1];
below_ptr = input_data[outrow+1]; below_ptr = input_data[outrow + 1];
/* Special case for first column */ /* Special case for first column */
colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) + colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
@ -436,7 +436,7 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
GETJSAMPLE(*inptr); GETJSAMPLE(*inptr);
neighsum = colsum + (colsum - membersum) + nextcolsum; neighsum = colsum + (colsum - membersum) + nextcolsum;
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
*outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); *outptr++ = (JSAMPLE)((membersum + 32768) >> 16);
lastcolsum = colsum; colsum = nextcolsum; lastcolsum = colsum; colsum = nextcolsum;
for (colctr = output_cols - 2; colctr > 0; colctr--) { for (colctr = output_cols - 2; colctr > 0; colctr--) {
@ -446,7 +446,7 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
GETJSAMPLE(*inptr); GETJSAMPLE(*inptr);
neighsum = lastcolsum + (colsum - membersum) + nextcolsum; neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
*outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); *outptr++ = (JSAMPLE)((membersum + 32768) >> 16);
lastcolsum = colsum; colsum = nextcolsum; lastcolsum = colsum; colsum = nextcolsum;
} }
@ -454,7 +454,7 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
membersum = GETJSAMPLE(*inptr); membersum = GETJSAMPLE(*inptr);
neighsum = lastcolsum + (colsum - membersum) + colsum; neighsum = lastcolsum + (colsum - membersum) + colsum;
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
*outptr = (JSAMPLE) ((membersum + 32768) >> 16); *outptr = (JSAMPLE)((membersum + 32768) >> 16);
} }
} }
@ -468,7 +468,7 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
*/ */
GLOBAL(void) GLOBAL(void)
jinit_downsampler (j_compress_ptr cinfo) jinit_downsampler(j_compress_ptr cinfo)
{ {
my_downsample_ptr downsample; my_downsample_ptr downsample;
int ci; int ci;
@ -476,9 +476,9 @@ jinit_downsampler (j_compress_ptr cinfo)
boolean smoothok = TRUE; boolean smoothok = TRUE;
downsample = (my_downsample_ptr) downsample = (my_downsample_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_downsampler)); sizeof(my_downsampler));
cinfo->downsample = (struct jpeg_downsampler *) downsample; cinfo->downsample = (struct jpeg_downsampler *)downsample;
downsample->pub.start_pass = start_pass_downsample; downsample->pub.start_pass = start_pass_downsample;
downsample->pub.downsample = sep_downsample; downsample->pub.downsample = sep_downsample;
downsample->pub.need_context_rows = FALSE; downsample->pub.need_context_rows = FALSE;

View File

@ -20,10 +20,10 @@
/* Forward declarations */ /* Forward declarations */
LOCAL(void) transencode_master_selection LOCAL(void) transencode_master_selection(j_compress_ptr cinfo,
(j_compress_ptr cinfo, jvirt_barray_ptr *coef_arrays); jvirt_barray_ptr *coef_arrays);
LOCAL(void) transencode_coef_controller LOCAL(void) transencode_coef_controller(j_compress_ptr cinfo,
(j_compress_ptr cinfo, jvirt_barray_ptr *coef_arrays); jvirt_barray_ptr *coef_arrays);
/* /*
@ -39,14 +39,14 @@ LOCAL(void) transencode_coef_controller
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr *coef_arrays) jpeg_write_coefficients(j_compress_ptr cinfo, jvirt_barray_ptr *coef_arrays)
{ {
if (cinfo->global_state != CSTATE_START) if (cinfo->global_state != CSTATE_START)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
/* Mark all tables to be written */ /* Mark all tables to be written */
jpeg_suppress_tables(cinfo, FALSE); jpeg_suppress_tables(cinfo, FALSE);
/* (Re)initialize error mgr and destination modules */ /* (Re)initialize error mgr and destination modules */
(*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); (*cinfo->err->reset_error_mgr) ((j_common_ptr)cinfo);
(*cinfo->dest->init_destination) (cinfo); (*cinfo->dest->init_destination) (cinfo);
/* Perform master selection of active modules */ /* Perform master selection of active modules */
transencode_master_selection(cinfo, coef_arrays); transencode_master_selection(cinfo, coef_arrays);
@ -64,8 +64,7 @@ jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr *coef_arrays)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_copy_critical_parameters (j_decompress_ptr srcinfo, jpeg_copy_critical_parameters(j_decompress_ptr srcinfo, j_compress_ptr dstinfo)
j_compress_ptr dstinfo)
{ {
JQUANT_TBL **qtblptr; JQUANT_TBL **qtblptr;
jpeg_component_info *incomp, *outcomp; jpeg_component_info *incomp, *outcomp;
@ -97,11 +96,10 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
/* 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++) {
if (srcinfo->quant_tbl_ptrs[tblno] != NULL) { if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
qtblptr = & dstinfo->quant_tbl_ptrs[tblno]; qtblptr = &dstinfo->quant_tbl_ptrs[tblno];
if (*qtblptr == NULL) if (*qtblptr == NULL)
*qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo); *qtblptr = jpeg_alloc_quant_table((j_common_ptr)dstinfo);
MEMCOPY((*qtblptr)->quantval, MEMCOPY((*qtblptr)->quantval, srcinfo->quant_tbl_ptrs[tblno]->quantval,
srcinfo->quant_tbl_ptrs[tblno]->quantval,
sizeof((*qtblptr)->quantval)); sizeof((*qtblptr)->quantval));
(*qtblptr)->sent_table = FALSE; (*qtblptr)->sent_table = FALSE;
} }
@ -165,7 +163,7 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
*/ */
LOCAL(void) 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)
{ {
/* Although we don't actually use input_components for transcoding, /* Although we don't actually use input_components for transcoding,
@ -199,7 +197,7 @@ transencode_master_selection (j_compress_ptr cinfo,
jinit_marker_writer(cinfo); jinit_marker_writer(cinfo);
/* We can now tell the memory manager to allocate virtual arrays. */ /* We can now tell the memory manager to allocate virtual arrays. */
(*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); (*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo);
/* Write the datastream header (SOI, JFIF) immediately. /* Write the datastream header (SOI, JFIF) immediately.
* Frame and scan headers are postponed till later. * Frame and scan headers are postponed till later.
@ -238,10 +236,10 @@ typedef my_coef_controller *my_coef_ptr;
LOCAL(void) LOCAL(void)
start_iMCU_row (j_compress_ptr cinfo) start_iMCU_row(j_compress_ptr cinfo)
/* Reset within-iMCU-row counters for a new row */ /* Reset within-iMCU-row counters for a new row */
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
/* In an interleaved scan, an MCU row is the same as an iMCU row. /* In an interleaved scan, an MCU row is the same as an iMCU row.
* In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
@ -250,7 +248,7 @@ start_iMCU_row (j_compress_ptr cinfo)
if (cinfo->comps_in_scan > 1) { if (cinfo->comps_in_scan > 1) {
coef->MCU_rows_per_iMCU_row = 1; coef->MCU_rows_per_iMCU_row = 1;
} else { } else {
if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1)) if (coef->iMCU_row_num < (cinfo->total_iMCU_rows - 1))
coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
else else
coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
@ -266,9 +264,9 @@ start_iMCU_row (j_compress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode) start_pass_coef(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
if (pass_mode != JBUF_CRANK_DEST) if (pass_mode != JBUF_CRANK_DEST)
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
@ -289,9 +287,9 @@ start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf) compress_output(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
JDIMENSION MCU_col_num; /* index of current MCU within row */ JDIMENSION MCU_col_num; /* index of current MCU within row */
JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
@ -306,9 +304,9 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
buffer[ci] = (*cinfo->mem->access_virt_barray) buffer[ci] = (*cinfo->mem->access_virt_barray)
((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
coef->iMCU_row_num * compptr->v_samp_factor, coef->iMCU_row_num * compptr->v_samp_factor,
(JDIMENSION) compptr->v_samp_factor, FALSE); (JDIMENSION)compptr->v_samp_factor, FALSE);
} }
/* Loop to process one whole iMCU row */ /* Loop to process one whole iMCU row */
@ -321,13 +319,13 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
start_col = MCU_col_num * compptr->MCU_width; start_col = MCU_col_num * compptr->MCU_width;
blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width :
: compptr->last_col_width; compptr->last_col_width;
for (yindex = 0; yindex < compptr->MCU_height; yindex++) { for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
if (coef->iMCU_row_num < last_iMCU_row || if (coef->iMCU_row_num < last_iMCU_row ||
yindex+yoffset < compptr->last_row_height) { yindex + yoffset < compptr->last_row_height) {
/* Fill in pointers to real blocks in this row */ /* Fill in pointers to real blocks in this row */
buffer_ptr = buffer[ci][yindex+yoffset] + start_col; buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
for (xindex = 0; xindex < blockcnt; xindex++) for (xindex = 0; xindex < blockcnt; xindex++)
MCU_buffer[blkn++] = buffer_ptr++; MCU_buffer[blkn++] = buffer_ptr++;
} else { } else {
@ -342,13 +340,13 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
*/ */
for (; xindex < compptr->MCU_width; xindex++) { for (; xindex < compptr->MCU_width; xindex++) {
MCU_buffer[blkn] = coef->dummy_buffer[blkn]; MCU_buffer[blkn] = coef->dummy_buffer[blkn];
MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0]; MCU_buffer[blkn][0][0] = MCU_buffer[blkn - 1][0][0];
blkn++; blkn++;
} }
} }
} }
/* Try to write the MCU. */ /* Try to write the MCU. */
if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) { if (!(*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
/* Suspension forced; update state counters and exit */ /* Suspension forced; update state counters and exit */
coef->MCU_vert_offset = yoffset; coef->MCU_vert_offset = yoffset;
coef->mcu_ctr = MCU_col_num; coef->mcu_ctr = MCU_col_num;
@ -374,7 +372,7 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
*/ */
LOCAL(void) LOCAL(void)
transencode_coef_controller (j_compress_ptr cinfo, transencode_coef_controller(j_compress_ptr cinfo,
jvirt_barray_ptr *coef_arrays) jvirt_barray_ptr *coef_arrays)
{ {
my_coef_ptr coef; my_coef_ptr coef;
@ -382,9 +380,9 @@ transencode_coef_controller (j_compress_ptr cinfo,
int i; int i;
coef = (my_coef_ptr) coef = (my_coef_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_coef_controller)); sizeof(my_coef_controller));
cinfo->coef = (struct jpeg_c_coef_controller *) coef; cinfo->coef = (struct jpeg_c_coef_controller *)coef;
coef->pub.start_pass = start_pass_coef; coef->pub.start_pass = start_pass_coef;
coef->pub.compress_data = compress_output; coef->pub.compress_data = compress_output;
@ -393,9 +391,9 @@ transencode_coef_controller (j_compress_ptr cinfo,
/* Allocate and pre-zero space for dummy DCT blocks. */ /* Allocate and pre-zero space for dummy DCT blocks. */
buffer = (JBLOCKROW) buffer = (JBLOCKROW)
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
C_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK)); C_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
jzero_far((void *) buffer, C_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK)); jzero_far((void *)buffer, C_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) { for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
coef->dummy_buffer[i] = buffer + i; coef->dummy_buffer[i] = buffer + i;
} }

View File

@ -31,7 +31,7 @@
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize) jpeg_CreateDecompress(j_decompress_ptr cinfo, int version, size_t structsize)
{ {
int i; int i;
@ -41,7 +41,7 @@ jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
if (structsize != sizeof(struct jpeg_decompress_struct)) if (structsize != sizeof(struct jpeg_decompress_struct))
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
(int) sizeof(struct jpeg_decompress_struct), (int) structsize); (int)sizeof(struct jpeg_decompress_struct), (int)structsize);
/* For debugging purposes, we zero the whole master structure. /* For debugging purposes, we zero the whole master structure.
* But the application has already set the err pointer, and may have set * But the application has already set the err pointer, and may have set
@ -50,8 +50,8 @@ jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
* complain here. * complain here.
*/ */
{ {
struct jpeg_error_mgr * err = cinfo->err; struct jpeg_error_mgr *err = cinfo->err;
void * client_data = cinfo->client_data; /* ignore Purify complaint here */ void *client_data = cinfo->client_data; /* ignore Purify complaint here */
MEMZERO(cinfo, sizeof(struct jpeg_decompress_struct)); MEMZERO(cinfo, sizeof(struct jpeg_decompress_struct));
cinfo->err = err; cinfo->err = err;
cinfo->client_data = client_data; cinfo->client_data = client_data;
@ -59,7 +59,7 @@ jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
cinfo->is_decompressor = TRUE; cinfo->is_decompressor = TRUE;
/* Initialize a memory manager instance for this object */ /* Initialize a memory manager instance for this object */
jinit_memory_mgr((j_common_ptr) cinfo); jinit_memory_mgr((j_common_ptr)cinfo);
/* Zero out pointers to permanent structures. */ /* Zero out pointers to permanent structures. */
cinfo->progress = NULL; cinfo->progress = NULL;
@ -89,7 +89,7 @@ jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
* here. * here.
*/ */
cinfo->master = (struct jpeg_decomp_master *) cinfo->master = (struct jpeg_decomp_master *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
sizeof(my_decomp_master)); sizeof(my_decomp_master));
MEMZERO(cinfo->master, sizeof(my_decomp_master)); MEMZERO(cinfo->master, sizeof(my_decomp_master));
} }
@ -100,9 +100,9 @@ jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_destroy_decompress (j_decompress_ptr cinfo) jpeg_destroy_decompress(j_decompress_ptr cinfo)
{ {
jpeg_destroy((j_common_ptr) cinfo); /* use common routine */ jpeg_destroy((j_common_ptr)cinfo); /* use common routine */
} }
@ -112,9 +112,9 @@ jpeg_destroy_decompress (j_decompress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_abort_decompress (j_decompress_ptr cinfo) jpeg_abort_decompress(j_decompress_ptr cinfo)
{ {
jpeg_abort((j_common_ptr) cinfo); /* use common routine */ jpeg_abort((j_common_ptr)cinfo); /* use common routine */
} }
@ -123,7 +123,7 @@ jpeg_abort_decompress (j_decompress_ptr cinfo)
*/ */
LOCAL(void) LOCAL(void)
default_decompress_parms (j_decompress_ptr cinfo) default_decompress_parms(j_decompress_ptr cinfo)
{ {
/* Guess the input colorspace, and set output colorspace accordingly. */ /* Guess the input colorspace, and set output colorspace accordingly. */
/* (Wish JPEG committee had provided a real way to specify this...) */ /* (Wish JPEG committee had provided a real way to specify this...) */
@ -250,7 +250,7 @@ default_decompress_parms (j_decompress_ptr cinfo)
*/ */
GLOBAL(int) GLOBAL(int)
jpeg_read_header (j_decompress_ptr cinfo, boolean require_image) jpeg_read_header(j_decompress_ptr cinfo, boolean require_image)
{ {
int retcode; int retcode;
@ -271,7 +271,7 @@ jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
* call jpeg_abort, but we can't change it now for compatibility reasons. * call jpeg_abort, but we can't change it now for compatibility reasons.
* A side effect is to free any temporary memory (there shouldn't be any). * A side effect is to free any temporary memory (there shouldn't be any).
*/ */
jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */ jpeg_abort((j_common_ptr)cinfo); /* sets state = DSTATE_START */
retcode = JPEG_HEADER_TABLES_ONLY; retcode = JPEG_HEADER_TABLES_ONLY;
break; break;
case JPEG_SUSPENDED: case JPEG_SUSPENDED:
@ -296,7 +296,7 @@ jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
*/ */
GLOBAL(int) GLOBAL(int)
jpeg_consume_input (j_decompress_ptr cinfo) jpeg_consume_input(j_decompress_ptr cinfo)
{ {
int retcode = JPEG_SUSPENDED; int retcode = JPEG_SUSPENDED;
@ -343,7 +343,7 @@ jpeg_consume_input (j_decompress_ptr cinfo)
*/ */
GLOBAL(boolean) GLOBAL(boolean)
jpeg_input_complete (j_decompress_ptr cinfo) jpeg_input_complete(j_decompress_ptr cinfo)
{ {
/* Check for valid jpeg object */ /* Check for valid jpeg object */
if (cinfo->global_state < DSTATE_START || if (cinfo->global_state < DSTATE_START ||
@ -358,7 +358,7 @@ jpeg_input_complete (j_decompress_ptr cinfo)
*/ */
GLOBAL(boolean) GLOBAL(boolean)
jpeg_has_multiple_scans (j_decompress_ptr cinfo) jpeg_has_multiple_scans(j_decompress_ptr cinfo)
{ {
/* Only valid after jpeg_read_header completes */ /* Only valid after jpeg_read_header completes */
if (cinfo->global_state < DSTATE_READY || if (cinfo->global_state < DSTATE_READY ||
@ -378,10 +378,10 @@ jpeg_has_multiple_scans (j_decompress_ptr cinfo)
*/ */
GLOBAL(boolean) GLOBAL(boolean)
jpeg_finish_decompress (j_decompress_ptr cinfo) jpeg_finish_decompress(j_decompress_ptr cinfo)
{ {
if ((cinfo->global_state == DSTATE_SCANNING || if ((cinfo->global_state == DSTATE_SCANNING ||
cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) { cinfo->global_state == DSTATE_RAW_OK) && !cinfo->buffered_image) {
/* Terminate final pass of non-buffered mode */ /* Terminate final pass of non-buffered mode */
if (cinfo->output_scanline < cinfo->output_height) if (cinfo->output_scanline < cinfo->output_height)
ERREXIT(cinfo, JERR_TOO_LITTLE_DATA); ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
@ -395,13 +395,13 @@ jpeg_finish_decompress (j_decompress_ptr cinfo)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
} }
/* Read until EOI */ /* Read until EOI */
while (! cinfo->inputctl->eoi_reached) { while (!cinfo->inputctl->eoi_reached) {
if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
return FALSE; /* Suspend, come back later */ return FALSE; /* Suspend, come back later */
} }
/* Do final cleanup */ /* Do final cleanup */
(*cinfo->src->term_source) (cinfo); (*cinfo->src->term_source) (cinfo);
/* We can use jpeg_abort to release memory and reset global_state */ /* We can use jpeg_abort to release memory and reset global_state */
jpeg_abort((j_common_ptr) cinfo); jpeg_abort((j_common_ptr)cinfo);
return TRUE; return TRUE;
} }

View File

@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2010, 2015-2017, D. R. Commander. * Copyright (C) 2010, 2015-2018, D. R. Commander.
* Copyright (C) 2015, Google, Inc. * Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
@ -25,7 +25,7 @@
#include "jmemsys.h" #include "jmemsys.h"
/* Forward declarations */ /* Forward declarations */
LOCAL(boolean) output_pass_setup (j_decompress_ptr cinfo); LOCAL(boolean) output_pass_setup(j_decompress_ptr cinfo);
/* /*
@ -40,7 +40,7 @@ LOCAL(boolean) output_pass_setup (j_decompress_ptr cinfo);
*/ */
GLOBAL(boolean) GLOBAL(boolean)
jpeg_start_decompress (j_decompress_ptr cinfo) jpeg_start_decompress(j_decompress_ptr cinfo)
{ {
if (cinfo->global_state == DSTATE_READY) { if (cinfo->global_state == DSTATE_READY) {
/* First call: initialize master control, select active modules */ /* First call: initialize master control, select active modules */
@ -60,7 +60,7 @@ jpeg_start_decompress (j_decompress_ptr cinfo)
int retcode; int retcode;
/* Call progress monitor hook if present */ /* Call progress monitor hook if present */
if (cinfo->progress != NULL) if (cinfo->progress != NULL)
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
/* Absorb some more input */ /* Absorb some more input */
retcode = (*cinfo->inputctl->consume_input) (cinfo); retcode = (*cinfo->inputctl->consume_input) (cinfo);
if (retcode == JPEG_SUSPENDED) if (retcode == JPEG_SUSPENDED)
@ -72,7 +72,7 @@ jpeg_start_decompress (j_decompress_ptr cinfo)
(retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) { (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) { if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
/* jdmaster underestimated number of scans; ratchet up one scan */ /* jdmaster underestimated number of scans; ratchet up one scan */
cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows; cinfo->progress->pass_limit += (long)cinfo->total_iMCU_rows;
} }
} }
} }
@ -97,7 +97,7 @@ jpeg_start_decompress (j_decompress_ptr cinfo)
*/ */
LOCAL(boolean) LOCAL(boolean)
output_pass_setup (j_decompress_ptr cinfo) output_pass_setup(j_decompress_ptr cinfo)
{ {
if (cinfo->global_state != DSTATE_PRESCAN) { if (cinfo->global_state != DSTATE_PRESCAN) {
/* First call: do pass setup */ /* First call: do pass setup */
@ -113,14 +113,14 @@ output_pass_setup (j_decompress_ptr cinfo)
JDIMENSION last_scanline; JDIMENSION last_scanline;
/* Call progress monitor hook if present */ /* Call progress monitor hook if present */
if (cinfo->progress != NULL) { if (cinfo->progress != NULL) {
cinfo->progress->pass_counter = (long) cinfo->output_scanline; cinfo->progress->pass_counter = (long)cinfo->output_scanline;
cinfo->progress->pass_limit = (long) cinfo->output_height; cinfo->progress->pass_limit = (long)cinfo->output_height;
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
} }
/* Process some data */ /* Process some data */
last_scanline = cinfo->output_scanline; last_scanline = cinfo->output_scanline;
(*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL, (*cinfo->main->process_data) (cinfo, (JSAMPARRAY)NULL,
&cinfo->output_scanline, (JDIMENSION) 0); &cinfo->output_scanline, (JDIMENSION)0);
if (cinfo->output_scanline == last_scanline) if (cinfo->output_scanline == last_scanline)
return FALSE; /* No progress made, must suspend */ return FALSE; /* No progress made, must suspend */
} }
@ -150,7 +150,7 @@ output_pass_setup (j_decompress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_crop_scanline (j_decompress_ptr cinfo, JDIMENSION *xoffset, jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
JDIMENSION *width) JDIMENSION *width)
{ {
int ci, align, orig_downsampled_width; int ci, align, orig_downsampled_width;
@ -210,11 +210,10 @@ jpeg_crop_scanline (j_decompress_ptr cinfo, JDIMENSION *xoffset,
/* Set the first and last iMCU columns that we must decompress. These values /* Set the first and last iMCU columns that we must decompress. These values
* will be used in single-scan decompressions. * will be used in single-scan decompressions.
*/ */
cinfo->master->first_iMCU_col = cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align;
(JDIMENSION) (long) (*xoffset) / (long) align;
cinfo->master->last_iMCU_col = cinfo->master->last_iMCU_col =
(JDIMENSION) jdiv_round_up((long) (*xoffset + cinfo->output_width), (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width),
(long) align) - 1; (long)align) - 1;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
@ -224,9 +223,9 @@ jpeg_crop_scanline (j_decompress_ptr cinfo, JDIMENSION *xoffset,
/* Set downsampled_width to the new output width. */ /* Set downsampled_width to the new output width. */
orig_downsampled_width = compptr->downsampled_width; orig_downsampled_width = compptr->downsampled_width;
compptr->downsampled_width = compptr->downsampled_width =
(JDIMENSION) jdiv_round_up((long) (cinfo->output_width * (JDIMENSION)jdiv_round_up((long)(cinfo->output_width *
compptr->h_samp_factor), compptr->h_samp_factor),
(long) cinfo->max_h_samp_factor); (long)cinfo->max_h_samp_factor);
if (compptr->downsampled_width < 2 && orig_downsampled_width >= 2) if (compptr->downsampled_width < 2 && orig_downsampled_width >= 2)
reinit_upsampler = TRUE; reinit_upsampler = TRUE;
@ -234,11 +233,10 @@ jpeg_crop_scanline (j_decompress_ptr cinfo, JDIMENSION *xoffset,
* values will be used in multi-scan decompressions. * values will be used in multi-scan decompressions.
*/ */
cinfo->master->first_MCU_col[ci] = cinfo->master->first_MCU_col[ci] =
(JDIMENSION) (long) (*xoffset * hsf) / (long) align; (JDIMENSION)(long)(*xoffset * hsf) / (long)align;
cinfo->master->last_MCU_col[ci] = cinfo->master->last_MCU_col[ci] =
(JDIMENSION) jdiv_round_up((long) ((*xoffset + cinfo->output_width) * (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf),
hsf), (long)align) - 1;
(long) align) - 1;
} }
if (reinit_upsampler) { if (reinit_upsampler) {
@ -263,7 +261,7 @@ jpeg_crop_scanline (j_decompress_ptr cinfo, JDIMENSION *xoffset,
*/ */
GLOBAL(JDIMENSION) GLOBAL(JDIMENSION)
jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines, jpeg_read_scanlines(j_decompress_ptr cinfo, JSAMPARRAY scanlines,
JDIMENSION max_lines) JDIMENSION max_lines)
{ {
JDIMENSION row_ctr; JDIMENSION row_ctr;
@ -277,9 +275,9 @@ jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
/* Call progress monitor hook if present */ /* Call progress monitor hook if present */
if (cinfo->progress != NULL) { if (cinfo->progress != NULL) {
cinfo->progress->pass_counter = (long) cinfo->output_scanline; cinfo->progress->pass_counter = (long)cinfo->output_scanline;
cinfo->progress->pass_limit = (long) cinfo->output_height; cinfo->progress->pass_limit = (long)cinfo->output_height;
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
} }
/* Process some data */ /* Process some data */
@ -292,7 +290,7 @@ jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
/* Dummy color convert function used by jpeg_skip_scanlines() */ /* Dummy color convert function used by jpeg_skip_scanlines() */
LOCAL(void) LOCAL(void)
noop_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, noop_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows) JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
{ {
} }
@ -300,7 +298,7 @@ noop_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
/* Dummy quantize function used by jpeg_skip_scanlines() */ /* Dummy quantize function used by jpeg_skip_scanlines() */
LOCAL(void) LOCAL(void)
noop_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf, noop_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
} }
@ -315,17 +313,20 @@ noop_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
*/ */
LOCAL(void) LOCAL(void)
read_and_discard_scanlines (j_decompress_ptr cinfo, JDIMENSION num_lines) read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
{ {
JDIMENSION n; JDIMENSION n;
void (*color_convert) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, void (*color_convert) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, JDIMENSION input_row, JSAMPARRAY output_buf,
int num_rows); int num_rows) = NULL;
void (*color_quantize) (j_decompress_ptr cinfo, JSAMPARRAY input_buf, void (*color_quantize) (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) = NULL; JSAMPARRAY output_buf, int num_rows) = NULL;
if (cinfo->cconvert && cinfo->cconvert->color_convert) {
color_convert = cinfo->cconvert->color_convert; color_convert = cinfo->cconvert->color_convert;
cinfo->cconvert->color_convert = noop_convert; cinfo->cconvert->color_convert = noop_convert;
}
if (cinfo->cquantize && cinfo->cquantize->color_quantize) { if (cinfo->cquantize && cinfo->cquantize->color_quantize) {
color_quantize = cinfo->cquantize->color_quantize; color_quantize = cinfo->cquantize->color_quantize;
cinfo->cquantize->color_quantize = noop_quantize; cinfo->cquantize->color_quantize = noop_quantize;
@ -334,7 +335,9 @@ read_and_discard_scanlines (j_decompress_ptr cinfo, JDIMENSION num_lines)
for (n = 0; n < num_lines; n++) for (n = 0; n < num_lines; n++)
jpeg_read_scanlines(cinfo, NULL, 1); jpeg_read_scanlines(cinfo, NULL, 1);
if (color_convert)
cinfo->cconvert->color_convert = color_convert; cinfo->cconvert->color_convert = color_convert;
if (color_quantize) if (color_quantize)
cinfo->cquantize->color_quantize = color_quantize; cinfo->cquantize->color_quantize = color_quantize;
} }
@ -346,10 +349,10 @@ read_and_discard_scanlines (j_decompress_ptr cinfo, JDIMENSION num_lines)
*/ */
LOCAL(void) LOCAL(void)
increment_simple_rowgroup_ctr (j_decompress_ptr cinfo, JDIMENSION rows) increment_simple_rowgroup_ctr(j_decompress_ptr cinfo, JDIMENSION rows)
{ {
JDIMENSION rows_left; JDIMENSION rows_left;
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
/* Increment the counter to the next row group after the skipped rows. */ /* Increment the counter to the next row group after the skipped rows. */
main_ptr->rowgroup_ctr += rows / cinfo->max_v_samp_factor; main_ptr->rowgroup_ctr += rows / cinfo->max_v_samp_factor;
@ -375,11 +378,11 @@ increment_simple_rowgroup_ctr (j_decompress_ptr cinfo, JDIMENSION rows)
*/ */
GLOBAL(JDIMENSION) GLOBAL(JDIMENSION)
jpeg_skip_scanlines (j_decompress_ptr cinfo, JDIMENSION num_lines) jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
{ {
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
JDIMENSION i, x; JDIMENSION i, x;
int y; int y;
JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row; JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
@ -481,7 +484,7 @@ jpeg_skip_scanlines (j_decompress_ptr cinfo, JDIMENSION num_lines)
if (cinfo->upsample->need_context_rows) { if (cinfo->upsample->need_context_rows) {
cinfo->output_scanline += lines_to_skip; cinfo->output_scanline += lines_to_skip;
cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row; cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
main_ptr->iMCU_row_ctr += lines_after_iMCU_row / lines_per_iMCU_row; main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
/* It is complex to properly move to the middle of a context block, so /* It is complex to properly move to the middle of a context block, so
* read the remaining lines instead of skipping them. * read the remaining lines instead of skipping them.
*/ */
@ -544,7 +547,7 @@ jpeg_skip_scanlines (j_decompress_ptr cinfo, JDIMENSION num_lines)
*/ */
GLOBAL(JDIMENSION) GLOBAL(JDIMENSION)
jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data, jpeg_read_raw_data(j_decompress_ptr cinfo, JSAMPIMAGE data,
JDIMENSION max_lines) JDIMENSION max_lines)
{ {
JDIMENSION lines_per_iMCU_row; JDIMENSION lines_per_iMCU_row;
@ -558,9 +561,9 @@ jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
/* Call progress monitor hook if present */ /* Call progress monitor hook if present */
if (cinfo->progress != NULL) { if (cinfo->progress != NULL) {
cinfo->progress->pass_counter = (long) cinfo->output_scanline; cinfo->progress->pass_counter = (long)cinfo->output_scanline;
cinfo->progress->pass_limit = (long) cinfo->output_height; cinfo->progress->pass_limit = (long)cinfo->output_height;
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
} }
/* Verify that at least one iMCU row can be returned. */ /* Verify that at least one iMCU row can be returned. */
@ -569,7 +572,7 @@ jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
ERREXIT(cinfo, JERR_BUFFER_SIZE); ERREXIT(cinfo, JERR_BUFFER_SIZE);
/* Decompress directly into user's buffer. */ /* Decompress directly into user's buffer. */
if (! (*cinfo->coef->decompress_data) (cinfo, data)) if (!(*cinfo->coef->decompress_data) (cinfo, data))
return 0; /* suspension forced, can do nothing more */ return 0; /* suspension forced, can do nothing more */
/* OK, we processed one iMCU row. */ /* OK, we processed one iMCU row. */
@ -587,7 +590,7 @@ jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
*/ */
GLOBAL(boolean) GLOBAL(boolean)
jpeg_start_output (j_decompress_ptr cinfo, int scan_number) jpeg_start_output(j_decompress_ptr cinfo, int scan_number)
{ {
if (cinfo->global_state != DSTATE_BUFIMAGE && if (cinfo->global_state != DSTATE_BUFIMAGE &&
cinfo->global_state != DSTATE_PRESCAN) cinfo->global_state != DSTATE_PRESCAN)
@ -595,8 +598,7 @@ jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
/* Limit scan number to valid range */ /* Limit scan number to valid range */
if (scan_number <= 0) if (scan_number <= 0)
scan_number = 1; scan_number = 1;
if (cinfo->inputctl->eoi_reached && if (cinfo->inputctl->eoi_reached && scan_number > cinfo->input_scan_number)
scan_number > cinfo->input_scan_number)
scan_number = cinfo->input_scan_number; scan_number = cinfo->input_scan_number;
cinfo->output_scan_number = scan_number; cinfo->output_scan_number = scan_number;
/* Perform any dummy output passes, and set up for the real pass */ /* Perform any dummy output passes, and set up for the real pass */
@ -612,7 +614,7 @@ jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
*/ */
GLOBAL(boolean) GLOBAL(boolean)
jpeg_finish_output (j_decompress_ptr cinfo) jpeg_finish_output(j_decompress_ptr cinfo)
{ {
if ((cinfo->global_state == DSTATE_SCANNING || if ((cinfo->global_state == DSTATE_SCANNING ||
cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) { cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
@ -626,7 +628,7 @@ jpeg_finish_output (j_decompress_ptr cinfo)
} }
/* Read markers looking for SOS or EOI */ /* Read markers looking for SOS or EOI */
while (cinfo->input_scan_number <= cinfo->output_scan_number && while (cinfo->input_scan_number <= cinfo->output_scan_number &&
! cinfo->inputctl->eoi_reached) { !cinfo->inputctl->eoi_reached) {
if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
return FALSE; /* Suspend, come back later */ return FALSE; /* Suspend, come back later */
} }

View File

@ -4,16 +4,19 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Developed 1997-2015 by Guido Vollbeding. * Developed 1997-2015 by Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2015-2016, D. R. Commander. * Copyright (C) 2015-2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
* This file contains portable arithmetic entropy decoding routines for JPEG * This file contains portable arithmetic entropy encoding routines for JPEG
* (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81). * (implementing Recommendation ITU-T T.81 | ISO/IEC 10918-1).
* *
* Both sequential and progressive modes are supported in this single module. * Both sequential and progressive modes are supported in this single module.
* *
* Suspension is not currently supported in this module. * Suspension is not currently supported in this module.
*
* NOTE: All referenced figures are from
* Recommendation ITU-T T.81 (1992) | ISO/IEC 10918-1:1994.
*/ */
#define JPEG_INTERNALS #define JPEG_INTERNALS
@ -68,13 +71,13 @@ typedef arith_entropy_decoder *arith_entropy_ptr;
LOCAL(int) LOCAL(int)
get_byte (j_decompress_ptr cinfo) get_byte(j_decompress_ptr cinfo)
/* Read next input byte; we do not support suspension in this module. */ /* Read next input byte; we do not support suspension in this module. */
{ {
struct jpeg_source_mgr *src = cinfo->src; struct jpeg_source_mgr *src = cinfo->src;
if (src->bytes_in_buffer == 0) if (src->bytes_in_buffer == 0)
if (! (*src->fill_input_buffer) (cinfo)) if (!(*src->fill_input_buffer) (cinfo))
ERREXIT(cinfo, JERR_CANT_SUSPEND); ERREXIT(cinfo, JERR_CANT_SUSPEND);
src->bytes_in_buffer--; src->bytes_in_buffer--;
return GETJOCTET(*src->next_input_byte++); return GETJOCTET(*src->next_input_byte++);
@ -109,9 +112,9 @@ get_byte (j_decompress_ptr cinfo)
*/ */
LOCAL(int) LOCAL(int)
arith_decode (j_decompress_ptr cinfo, unsigned char *st) arith_decode(j_decompress_ptr cinfo, unsigned char *st)
{ {
register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy; register arith_entropy_ptr e = (arith_entropy_ptr)cinfo->entropy;
register unsigned char nl, nm; register unsigned char nl, nm;
register JLONG qe, temp; register JLONG qe, temp;
register int sv, data; register int sv, data;
@ -193,14 +196,14 @@ arith_decode (j_decompress_ptr cinfo, unsigned char *st)
*/ */
LOCAL(void) LOCAL(void)
process_restart (j_decompress_ptr cinfo) process_restart(j_decompress_ptr cinfo)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
int ci; int ci;
jpeg_component_info *compptr; jpeg_component_info *compptr;
/* Advance past the RSTn marker */ /* Advance past the RSTn marker */
if (! (*cinfo->marker->read_restart_marker) (cinfo)) if (!(*cinfo->marker->read_restart_marker) (cinfo))
ERREXIT(cinfo, JERR_CANT_SUSPEND); ERREXIT(cinfo, JERR_CANT_SUSPEND);
/* Re-initialize statistics areas */ /* Re-initialize statistics areas */
@ -244,9 +247,9 @@ process_restart (j_decompress_ptr cinfo)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_DC_first(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
JBLOCKROW block; JBLOCKROW block;
unsigned char *st; unsigned char *st;
int blkn, ci, tbl, sign; int blkn, ci, tbl, sign;
@ -294,9 +297,9 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
} }
/* Section F.1.4.4.1.2: Establish dc_context conditioning category */ /* Section F.1.4.4.1.2: Establish dc_context conditioning category */
if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1)) if (m < (int)((1L << cinfo->arith_dc_L[tbl]) >> 1))
entropy->dc_context[ci] = 0; /* zero diff category */ entropy->dc_context[ci] = 0; /* zero diff category */
else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1)) else if (m > (int)((1L << cinfo->arith_dc_U[tbl]) >> 1))
entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */ entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */
else else
entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */ entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */
@ -306,11 +309,11 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
while (m >>= 1) while (m >>= 1)
if (arith_decode(cinfo, st)) v |= m; if (arith_decode(cinfo, st)) v |= m;
v += 1; if (sign) v = -v; v += 1; if (sign) v = -v;
entropy->last_dc_val[ci] += v; entropy->last_dc_val[ci] = (entropy->last_dc_val[ci] + v) & 0xffff;
} }
/* Scale and output the DC coefficient (assumes jpeg_natural_order[0]=0) */ /* Scale and output the DC coefficient (assumes jpeg_natural_order[0]=0) */
(*block)[0] = (JCOEF) LEFT_SHIFT(entropy->last_dc_val[ci], cinfo->Al); (*block)[0] = (JCOEF)LEFT_SHIFT(entropy->last_dc_val[ci], cinfo->Al);
} }
return TRUE; return TRUE;
@ -323,9 +326,9 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_AC_first(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
JBLOCKROW block; JBLOCKROW block;
unsigned char *st; unsigned char *st;
int tbl, sign, k; int tbl, sign, k;
@ -385,7 +388,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (arith_decode(cinfo, st)) v |= m; if (arith_decode(cinfo, st)) v |= m;
v += 1; if (sign) v = -v; v += 1; if (sign) v = -v;
/* Scale and output coefficient in natural (dezigzagged) order */ /* Scale and output coefficient in natural (dezigzagged) order */
(*block)[jpeg_natural_order[k]] = (JCOEF) ((unsigned)v << cinfo->Al); (*block)[jpeg_natural_order[k]] = (JCOEF)((unsigned)v << cinfo->Al);
} }
return TRUE; return TRUE;
@ -397,9 +400,9 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_DC_refine(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
unsigned char *st; unsigned char *st;
int p1, blkn; int p1, blkn;
@ -430,9 +433,9 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_AC_refine(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
JBLOCKROW block; JBLOCKROW block;
JCOEFPTR thiscoef; JCOEFPTR thiscoef;
unsigned char *st; unsigned char *st;
@ -499,9 +502,9 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
jpeg_component_info *compptr; jpeg_component_info *compptr;
JBLOCKROW block; JBLOCKROW block;
unsigned char *st; unsigned char *st;
@ -552,9 +555,9 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
} }
/* Section F.1.4.4.1.2: Establish dc_context conditioning category */ /* Section F.1.4.4.1.2: Establish dc_context conditioning category */
if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1)) if (m < (int)((1L << cinfo->arith_dc_L[tbl]) >> 1))
entropy->dc_context[ci] = 0; /* zero diff category */ entropy->dc_context[ci] = 0; /* zero diff category */
else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1)) else if (m > (int)((1L << cinfo->arith_dc_U[tbl]) >> 1))
entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */ entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */
else else
entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */ entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */
@ -564,11 +567,11 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
while (m >>= 1) while (m >>= 1)
if (arith_decode(cinfo, st)) v |= m; if (arith_decode(cinfo, st)) v |= m;
v += 1; if (sign) v = -v; v += 1; if (sign) v = -v;
entropy->last_dc_val[ci] += v; entropy->last_dc_val[ci] = (entropy->last_dc_val[ci] + v) & 0xffff;
} }
if (block) if (block)
(*block)[0] = (JCOEF) entropy->last_dc_val[ci]; (*block)[0] = (JCOEF)entropy->last_dc_val[ci];
/* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */ /* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */
@ -613,7 +616,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (arith_decode(cinfo, st)) v |= m; if (arith_decode(cinfo, st)) v |= m;
v += 1; if (sign) v = -v; v += 1; if (sign) v = -v;
if (block) if (block)
(*block)[jpeg_natural_order[k]] = (JCOEF) v; (*block)[jpeg_natural_order[k]] = (JCOEF)v;
} }
} }
@ -626,9 +629,9 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(void) METHODDEF(void)
start_pass (j_decompress_ptr cinfo) start_pass(j_decompress_ptr cinfo)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr)cinfo->entropy;
int ci, tbl; int ci, tbl;
jpeg_component_info *compptr; jpeg_component_info *compptr;
@ -647,11 +650,11 @@ start_pass (j_decompress_ptr cinfo)
} }
if (cinfo->Ah != 0) { if (cinfo->Ah != 0) {
/* Successive approximation refinement scan: must have Al = Ah-1. */ /* Successive approximation refinement scan: must have Al = Ah-1. */
if (cinfo->Ah-1 != cinfo->Al) if (cinfo->Ah - 1 != cinfo->Al)
goto bad; goto bad;
} }
if (cinfo->Al > 13) { /* need not check for < 0 */ if (cinfo->Al > 13) { /* need not check for < 0 */
bad: bad:
ERREXIT4(cinfo, JERR_BAD_PROGRESSION, ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al); cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
} }
@ -661,7 +664,7 @@ start_pass (j_decompress_ptr cinfo)
*/ */
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
int coefi, cindex = cinfo->cur_comp_info[ci]->component_index; int coefi, cindex = cinfo->cur_comp_info[ci]->component_index;
int *coef_bit_ptr = & cinfo->coef_bits[cindex][0]; int *coef_bit_ptr = &cinfo->coef_bits[cindex][0];
if (cinfo->Ss && coef_bit_ptr[0] < 0) /* AC without prior DC scan */ if (cinfo->Ss && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0); WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) { for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
@ -702,8 +705,8 @@ start_pass (j_decompress_ptr cinfo)
if (tbl < 0 || tbl >= NUM_ARITH_TBLS) if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl); ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
if (entropy->dc_stats[tbl] == NULL) if (entropy->dc_stats[tbl] == NULL)
entropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small) entropy->dc_stats[tbl] = (unsigned char *)(*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS); ((j_common_ptr)cinfo, JPOOL_IMAGE, DC_STAT_BINS);
MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS); MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS);
/* Initialize DC predictions to 0 */ /* Initialize DC predictions to 0 */
entropy->last_dc_val[ci] = 0; entropy->last_dc_val[ci] = 0;
@ -714,8 +717,8 @@ start_pass (j_decompress_ptr cinfo)
if (tbl < 0 || tbl >= NUM_ARITH_TBLS) if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl); ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
if (entropy->ac_stats[tbl] == NULL) if (entropy->ac_stats[tbl] == NULL)
entropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small) entropy->ac_stats[tbl] = (unsigned char *)(*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS); ((j_common_ptr)cinfo, JPOOL_IMAGE, AC_STAT_BINS);
MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS); MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS);
} }
} }
@ -735,15 +738,15 @@ start_pass (j_decompress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_arith_decoder (j_decompress_ptr cinfo) jinit_arith_decoder(j_decompress_ptr cinfo)
{ {
arith_entropy_ptr entropy; arith_entropy_ptr entropy;
int i; int i;
entropy = (arith_entropy_ptr) entropy = (arith_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(arith_entropy_decoder)); sizeof(arith_entropy_decoder));
cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; cinfo->entropy = (struct jpeg_entropy_decoder *)entropy;
entropy->pub.start_pass = start_pass; entropy->pub.start_pass = start_pass;
/* Mark tables unallocated */ /* Mark tables unallocated */
@ -759,9 +762,10 @@ jinit_arith_decoder (j_decompress_ptr cinfo)
/* Create progression status table */ /* Create progression status table */
int *coef_bit_ptr, ci; int *coef_bit_ptr, ci;
cinfo->coef_bits = (int (*)[DCTSIZE2]) cinfo->coef_bits = (int (*)[DCTSIZE2])
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
cinfo->num_components*DCTSIZE2*sizeof(int)); cinfo->num_components * DCTSIZE2 *
coef_bit_ptr = & cinfo->coef_bits[0][0]; sizeof(int));
coef_bit_ptr = &cinfo->coef_bits[0][0];
for (ci = 0; ci < cinfo->num_components; ci++) for (ci = 0; ci < cinfo->num_components; ci++)
for (i = 0; i < DCTSIZE2; i++) for (i = 0; i < DCTSIZE2; i++)
*coef_bit_ptr++ = -1; *coef_bit_ptr++ = -1;

View File

@ -24,8 +24,8 @@
#include "jerror.h" #include "jerror.h"
#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */ #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
extern void *malloc (size_t size); extern void *malloc(size_t size);
extern void free (void *ptr); extern void free(void *ptr);
#endif #endif
@ -66,13 +66,13 @@ typedef my_mem_destination_mgr *my_mem_dest_ptr;
*/ */
METHODDEF(void) METHODDEF(void)
init_destination (j_compress_ptr cinfo) init_destination(j_compress_ptr cinfo)
{ {
my_dest_ptr dest = (my_dest_ptr) cinfo->dest; my_dest_ptr dest = (my_dest_ptr)cinfo->dest;
/* Allocate the output buffer --- it will be released when done with image */ /* Allocate the output buffer --- it will be released when done with image */
dest->buffer = (JOCTET *) dest->buffer = (JOCTET *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
OUTPUT_BUF_SIZE * sizeof(JOCTET)); OUTPUT_BUF_SIZE * sizeof(JOCTET));
dest->pub.next_output_byte = dest->buffer; dest->pub.next_output_byte = dest->buffer;
@ -81,7 +81,7 @@ init_destination (j_compress_ptr cinfo)
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED) #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
METHODDEF(void) METHODDEF(void)
init_mem_destination (j_compress_ptr cinfo) init_mem_destination(j_compress_ptr cinfo)
{ {
/* no work necessary here */ /* no work necessary here */
} }
@ -112,12 +112,12 @@ init_mem_destination (j_compress_ptr cinfo)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
empty_output_buffer (j_compress_ptr cinfo) empty_output_buffer(j_compress_ptr cinfo)
{ {
my_dest_ptr dest = (my_dest_ptr) cinfo->dest; my_dest_ptr dest = (my_dest_ptr)cinfo->dest;
if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) != if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) !=
(size_t) OUTPUT_BUF_SIZE) (size_t)OUTPUT_BUF_SIZE)
ERREXIT(cinfo, JERR_FILE_WRITE); ERREXIT(cinfo, JERR_FILE_WRITE);
dest->pub.next_output_byte = dest->buffer; dest->pub.next_output_byte = dest->buffer;
@ -128,15 +128,15 @@ empty_output_buffer (j_compress_ptr cinfo)
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED) #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
METHODDEF(boolean) METHODDEF(boolean)
empty_mem_output_buffer (j_compress_ptr cinfo) empty_mem_output_buffer(j_compress_ptr cinfo)
{ {
size_t nextsize; size_t nextsize;
JOCTET *nextbuffer; JOCTET *nextbuffer;
my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest; my_mem_dest_ptr dest = (my_mem_dest_ptr)cinfo->dest;
/* Try to allocate new buffer with double size */ /* Try to allocate new buffer with double size */
nextsize = dest->bufsize * 2; nextsize = dest->bufsize * 2;
nextbuffer = (JOCTET *) malloc(nextsize); nextbuffer = (JOCTET *)malloc(nextsize);
if (nextbuffer == NULL) if (nextbuffer == NULL)
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
@ -169,9 +169,9 @@ empty_mem_output_buffer (j_compress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
term_destination (j_compress_ptr cinfo) term_destination(j_compress_ptr cinfo)
{ {
my_dest_ptr dest = (my_dest_ptr) cinfo->dest; my_dest_ptr dest = (my_dest_ptr)cinfo->dest;
size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer; size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
/* Write any data remaining in the buffer */ /* Write any data remaining in the buffer */
@ -187,9 +187,9 @@ term_destination (j_compress_ptr cinfo)
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED) #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
METHODDEF(void) METHODDEF(void)
term_mem_destination (j_compress_ptr cinfo) term_mem_destination(j_compress_ptr cinfo)
{ {
my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest; my_mem_dest_ptr dest = (my_mem_dest_ptr)cinfo->dest;
*dest->outbuffer = dest->buffer; *dest->outbuffer = dest->buffer;
*dest->outsize = (unsigned long)(dest->bufsize - dest->pub.free_in_buffer); *dest->outsize = (unsigned long)(dest->bufsize - dest->pub.free_in_buffer);
@ -204,7 +204,7 @@ term_mem_destination (j_compress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_stdio_dest (j_compress_ptr cinfo, FILE *outfile) jpeg_stdio_dest(j_compress_ptr cinfo, FILE *outfile)
{ {
my_dest_ptr dest; my_dest_ptr dest;
@ -213,7 +213,7 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE *outfile)
*/ */
if (cinfo->dest == NULL) { /* first time for this JPEG object? */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */
cinfo->dest = (struct jpeg_destination_mgr *) cinfo->dest = (struct jpeg_destination_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
sizeof(my_destination_mgr)); sizeof(my_destination_mgr));
} else if (cinfo->dest->init_destination != init_destination) { } else if (cinfo->dest->init_destination != init_destination) {
/* It is unsafe to reuse the existing destination manager unless it was /* It is unsafe to reuse the existing destination manager unless it was
@ -225,7 +225,7 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE *outfile)
ERREXIT(cinfo, JERR_BUFFER_SIZE); ERREXIT(cinfo, JERR_BUFFER_SIZE);
} }
dest = (my_dest_ptr) cinfo->dest; dest = (my_dest_ptr)cinfo->dest;
dest->pub.init_destination = init_destination; dest->pub.init_destination = init_destination;
dest->pub.empty_output_buffer = empty_output_buffer; dest->pub.empty_output_buffer = empty_output_buffer;
dest->pub.term_destination = term_destination; dest->pub.term_destination = term_destination;
@ -249,8 +249,8 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE *outfile)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_mem_dest (j_compress_ptr cinfo, jpeg_mem_dest(j_compress_ptr cinfo, unsigned char **outbuffer,
unsigned char **outbuffer, unsigned long *outsize) unsigned long *outsize)
{ {
my_mem_dest_ptr dest; my_mem_dest_ptr dest;
@ -262,7 +262,7 @@ jpeg_mem_dest (j_compress_ptr cinfo,
*/ */
if (cinfo->dest == NULL) { /* first time for this JPEG object? */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */
cinfo->dest = (struct jpeg_destination_mgr *) cinfo->dest = (struct jpeg_destination_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
sizeof(my_mem_destination_mgr)); sizeof(my_mem_destination_mgr));
} else if (cinfo->dest->init_destination != init_mem_destination) { } else if (cinfo->dest->init_destination != init_mem_destination) {
/* It is unsafe to reuse the existing destination manager unless it was /* It is unsafe to reuse the existing destination manager unless it was
@ -271,7 +271,7 @@ jpeg_mem_dest (j_compress_ptr cinfo,
ERREXIT(cinfo, JERR_BUFFER_SIZE); ERREXIT(cinfo, JERR_BUFFER_SIZE);
} }
dest = (my_mem_dest_ptr) cinfo->dest; dest = (my_mem_dest_ptr)cinfo->dest;
dest->pub.init_destination = init_mem_destination; dest->pub.init_destination = init_mem_destination;
dest->pub.empty_output_buffer = empty_mem_output_buffer; dest->pub.empty_output_buffer = empty_mem_output_buffer;
dest->pub.term_destination = term_mem_destination; dest->pub.term_destination = term_mem_destination;
@ -281,7 +281,7 @@ jpeg_mem_dest (j_compress_ptr cinfo,
if (*outbuffer == NULL || *outsize == 0) { if (*outbuffer == NULL || *outsize == 0) {
/* Allocate initial buffer */ /* Allocate initial buffer */
dest->newbuffer = *outbuffer = (unsigned char *) malloc(OUTPUT_BUF_SIZE); dest->newbuffer = *outbuffer = (unsigned char *)malloc(OUTPUT_BUF_SIZE);
if (dest->newbuffer == NULL) if (dest->newbuffer == NULL)
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
*outsize = OUTPUT_BUF_SIZE; *outsize = OUTPUT_BUF_SIZE;

View File

@ -45,9 +45,9 @@ typedef my_source_mgr *my_src_ptr;
*/ */
METHODDEF(void) METHODDEF(void)
init_source (j_decompress_ptr cinfo) init_source(j_decompress_ptr cinfo)
{ {
my_src_ptr src = (my_src_ptr) cinfo->src; my_src_ptr src = (my_src_ptr)cinfo->src;
/* We reset the empty-input-file flag for each image, /* We reset the empty-input-file flag for each image,
* but we don't clear the input buffer. * but we don't clear the input buffer.
@ -58,7 +58,7 @@ init_source (j_decompress_ptr cinfo)
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED) #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
METHODDEF(void) METHODDEF(void)
init_mem_source (j_decompress_ptr cinfo) init_mem_source(j_decompress_ptr cinfo)
{ {
/* no work necessary here */ /* no work necessary here */
} }
@ -99,9 +99,9 @@ init_mem_source (j_decompress_ptr cinfo)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
fill_input_buffer (j_decompress_ptr cinfo) fill_input_buffer(j_decompress_ptr cinfo)
{ {
my_src_ptr src = (my_src_ptr) cinfo->src; my_src_ptr src = (my_src_ptr)cinfo->src;
size_t nbytes; size_t nbytes;
nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE); nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
@ -111,8 +111,8 @@ fill_input_buffer (j_decompress_ptr cinfo)
ERREXIT(cinfo, JERR_INPUT_EMPTY); ERREXIT(cinfo, JERR_INPUT_EMPTY);
WARNMS(cinfo, JWRN_JPEG_EOF); WARNMS(cinfo, JWRN_JPEG_EOF);
/* Insert a fake EOI marker */ /* Insert a fake EOI marker */
src->buffer[0] = (JOCTET) 0xFF; src->buffer[0] = (JOCTET)0xFF;
src->buffer[1] = (JOCTET) JPEG_EOI; src->buffer[1] = (JOCTET)JPEG_EOI;
nbytes = 2; nbytes = 2;
} }
@ -125,10 +125,10 @@ fill_input_buffer (j_decompress_ptr cinfo)
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED) #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
METHODDEF(boolean) METHODDEF(boolean)
fill_mem_input_buffer (j_decompress_ptr cinfo) fill_mem_input_buffer(j_decompress_ptr cinfo)
{ {
static const JOCTET mybuffer[4] = { static const JOCTET mybuffer[4] = {
(JOCTET) 0xFF, (JOCTET) JPEG_EOI, 0, 0 (JOCTET)0xFF, (JOCTET)JPEG_EOI, 0, 0
}; };
/* The whole JPEG data is expected to reside in the supplied memory /* The whole JPEG data is expected to reside in the supplied memory
@ -160,7 +160,7 @@ fill_mem_input_buffer (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
skip_input_data (j_decompress_ptr cinfo, long num_bytes) skip_input_data(j_decompress_ptr cinfo, long num_bytes)
{ {
struct jpeg_source_mgr *src = cinfo->src; struct jpeg_source_mgr *src = cinfo->src;
@ -169,15 +169,15 @@ skip_input_data (j_decompress_ptr cinfo, long num_bytes)
* any trouble anyway --- large skips are infrequent. * any trouble anyway --- large skips are infrequent.
*/ */
if (num_bytes > 0) { if (num_bytes > 0) {
while (num_bytes > (long) src->bytes_in_buffer) { while (num_bytes > (long)src->bytes_in_buffer) {
num_bytes -= (long) src->bytes_in_buffer; num_bytes -= (long)src->bytes_in_buffer;
(void) (*src->fill_input_buffer) (cinfo); (void)(*src->fill_input_buffer) (cinfo);
/* note we assume that fill_input_buffer will never return FALSE, /* note we assume that fill_input_buffer will never return FALSE,
* so suspension need not be handled. * so suspension need not be handled.
*/ */
} }
src->next_input_byte += (size_t) num_bytes; src->next_input_byte += (size_t)num_bytes;
src->bytes_in_buffer -= (size_t) num_bytes; src->bytes_in_buffer -= (size_t)num_bytes;
} }
} }
@ -201,7 +201,7 @@ skip_input_data (j_decompress_ptr cinfo, long num_bytes)
*/ */
METHODDEF(void) METHODDEF(void)
term_source (j_decompress_ptr cinfo) term_source(j_decompress_ptr cinfo)
{ {
/* no work necessary here */ /* no work necessary here */
} }
@ -214,7 +214,7 @@ term_source (j_decompress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_stdio_src (j_decompress_ptr cinfo, FILE *infile) jpeg_stdio_src(j_decompress_ptr cinfo, FILE *infile)
{ {
my_src_ptr src; my_src_ptr src;
@ -225,11 +225,11 @@ jpeg_stdio_src (j_decompress_ptr cinfo, FILE *infile)
*/ */
if (cinfo->src == NULL) { /* first time for this JPEG object? */ if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *) cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
sizeof(my_source_mgr)); sizeof(my_source_mgr));
src = (my_src_ptr) cinfo->src; src = (my_src_ptr)cinfo->src;
src->buffer = (JOCTET *) src->buffer = (JOCTET *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
INPUT_BUF_SIZE * sizeof(JOCTET)); INPUT_BUF_SIZE * sizeof(JOCTET));
} else if (cinfo->src->init_source != init_source) { } else if (cinfo->src->init_source != init_source) {
/* It is unsafe to reuse the existing source manager unless it was created /* It is unsafe to reuse the existing source manager unless it was created
@ -241,7 +241,7 @@ jpeg_stdio_src (j_decompress_ptr cinfo, FILE *infile)
ERREXIT(cinfo, JERR_BUFFER_SIZE); ERREXIT(cinfo, JERR_BUFFER_SIZE);
} }
src = (my_src_ptr) cinfo->src; src = (my_src_ptr)cinfo->src;
src->pub.init_source = init_source; src->pub.init_source = init_source;
src->pub.fill_input_buffer = fill_input_buffer; src->pub.fill_input_buffer = fill_input_buffer;
src->pub.skip_input_data = skip_input_data; src->pub.skip_input_data = skip_input_data;
@ -260,8 +260,8 @@ jpeg_stdio_src (j_decompress_ptr cinfo, FILE *infile)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_mem_src (j_decompress_ptr cinfo, jpeg_mem_src(j_decompress_ptr cinfo, const unsigned char *inbuffer,
const unsigned char *inbuffer, unsigned long insize) unsigned long insize)
{ {
struct jpeg_source_mgr *src; struct jpeg_source_mgr *src;
@ -274,7 +274,7 @@ jpeg_mem_src (j_decompress_ptr cinfo,
*/ */
if (cinfo->src == NULL) { /* first time for this JPEG object? */ if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *) cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
sizeof(struct jpeg_source_mgr)); sizeof(struct jpeg_source_mgr));
} else if (cinfo->src->init_source != init_mem_source) { } else if (cinfo->src->init_source != init_mem_source) {
/* It is unsafe to reuse the existing source manager unless it was created /* It is unsafe to reuse the existing source manager unless it was created
@ -289,7 +289,7 @@ jpeg_mem_src (j_decompress_ptr cinfo,
src->skip_input_data = skip_input_data; src->skip_input_data = skip_input_data;
src->resync_to_restart = jpeg_resync_to_restart; /* use default method */ src->resync_to_restart = jpeg_resync_to_restart; /* use default method */
src->term_source = term_source; src->term_source = term_source;
src->bytes_in_buffer = (size_t) insize; src->bytes_in_buffer = (size_t)insize;
src->next_input_byte = (const JOCTET *) inbuffer; src->next_input_byte = (const JOCTET *)inbuffer;
} }
#endif #endif

View File

@ -25,16 +25,15 @@
/* Forward declarations */ /* Forward declarations */
METHODDEF(int) decompress_onepass METHODDEF(int) decompress_onepass(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, JSAMPIMAGE output_buf); JSAMPIMAGE output_buf);
#ifdef D_MULTISCAN_FILES_SUPPORTED #ifdef D_MULTISCAN_FILES_SUPPORTED
METHODDEF(int) decompress_data METHODDEF(int) decompress_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf);
(j_decompress_ptr cinfo, JSAMPIMAGE output_buf);
#endif #endif
#ifdef BLOCK_SMOOTHING_SUPPORTED #ifdef BLOCK_SMOOTHING_SUPPORTED
LOCAL(boolean) smoothing_ok (j_decompress_ptr cinfo); LOCAL(boolean) smoothing_ok(j_decompress_ptr cinfo);
METHODDEF(int) decompress_smooth_data METHODDEF(int) decompress_smooth_data(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, JSAMPIMAGE output_buf); JSAMPIMAGE output_buf);
#endif #endif
@ -43,7 +42,7 @@ METHODDEF(int) decompress_smooth_data
*/ */
METHODDEF(void) METHODDEF(void)
start_input_pass (j_decompress_ptr cinfo) start_input_pass(j_decompress_ptr cinfo)
{ {
cinfo->input_iMCU_row = 0; cinfo->input_iMCU_row = 0;
start_iMCU_row(cinfo); start_iMCU_row(cinfo);
@ -55,10 +54,10 @@ start_input_pass (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
start_output_pass (j_decompress_ptr cinfo) start_output_pass(j_decompress_ptr cinfo)
{ {
#ifdef BLOCK_SMOOTHING_SUPPORTED #ifdef BLOCK_SMOOTHING_SUPPORTED
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
/* If multipass, check to see whether to use block smoothing on this pass */ /* If multipass, check to see whether to use block smoothing on this pass */
if (coef->pub.coef_arrays != NULL) { if (coef->pub.coef_arrays != NULL) {
@ -83,9 +82,9 @@ start_output_pass (j_decompress_ptr cinfo)
*/ */
METHODDEF(int) METHODDEF(int)
decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) decompress_onepass(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
JDIMENSION MCU_col_num; /* index of current MCU within row */ JDIMENSION MCU_col_num; /* index of current MCU within row */
JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
@ -101,9 +100,9 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col; for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
MCU_col_num++) { MCU_col_num++) {
/* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */
jzero_far((void *) coef->MCU_buffer[0], jzero_far((void *)coef->MCU_buffer[0],
(size_t) (cinfo->blocks_in_MCU * sizeof(JBLOCK))); (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
/* Suspension forced; update state counters and exit */ /* Suspension forced; update state counters and exit */
coef->MCU_vert_offset = yoffset; coef->MCU_vert_offset = yoffset;
coef->MCU_ctr = MCU_col_num; coef->MCU_ctr = MCU_col_num;
@ -124,24 +123,24 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
/* Don't bother to IDCT an uninteresting component. */ /* Don't bother to IDCT an uninteresting component. */
if (! compptr->component_needed) { if (!compptr->component_needed) {
blkn += compptr->MCU_blocks; blkn += compptr->MCU_blocks;
continue; continue;
} }
inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index]; inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width useful_width = (MCU_col_num < last_MCU_col) ?
: compptr->last_col_width; compptr->MCU_width : compptr->last_col_width;
output_ptr = output_buf[compptr->component_index] + output_ptr = output_buf[compptr->component_index] +
yoffset * compptr->_DCT_scaled_size; yoffset * compptr->_DCT_scaled_size;
start_col = (MCU_col_num - cinfo->master->first_iMCU_col) * start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
compptr->MCU_sample_width; compptr->MCU_sample_width;
for (yindex = 0; yindex < compptr->MCU_height; yindex++) { for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
if (cinfo->input_iMCU_row < last_iMCU_row || if (cinfo->input_iMCU_row < last_iMCU_row ||
yoffset+yindex < compptr->last_row_height) { yoffset + yindex < compptr->last_row_height) {
output_col = start_col; output_col = start_col;
for (xindex = 0; xindex < useful_width; xindex++) { for (xindex = 0; xindex < useful_width; xindex++) {
(*inverse_DCT) (cinfo, compptr, (*inverse_DCT) (cinfo, compptr,
(JCOEFPTR) coef->MCU_buffer[blkn+xindex], (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
output_ptr, output_col); output_ptr, output_col);
output_col += compptr->_DCT_scaled_size; output_col += compptr->_DCT_scaled_size;
} }
@ -172,7 +171,7 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
*/ */
METHODDEF(int) METHODDEF(int)
dummy_consume_data (j_decompress_ptr cinfo) dummy_consume_data(j_decompress_ptr cinfo)
{ {
return JPEG_SUSPENDED; /* Always indicate nothing was done */ return JPEG_SUSPENDED; /* Always indicate nothing was done */
} }
@ -188,9 +187,9 @@ dummy_consume_data (j_decompress_ptr cinfo)
*/ */
METHODDEF(int) METHODDEF(int)
consume_data (j_decompress_ptr cinfo) consume_data(j_decompress_ptr cinfo)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
JDIMENSION MCU_col_num; /* index of current MCU within row */ JDIMENSION MCU_col_num; /* index of current MCU within row */
int blkn, ci, xindex, yindex, yoffset; int blkn, ci, xindex, yindex, yoffset;
JDIMENSION start_col; JDIMENSION start_col;
@ -202,9 +201,9 @@ consume_data (j_decompress_ptr cinfo)
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
buffer[ci] = (*cinfo->mem->access_virt_barray) buffer[ci] = (*cinfo->mem->access_virt_barray)
((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
cinfo->input_iMCU_row * compptr->v_samp_factor, cinfo->input_iMCU_row * compptr->v_samp_factor,
(JDIMENSION) compptr->v_samp_factor, TRUE); (JDIMENSION)compptr->v_samp_factor, TRUE);
/* Note: entropy decoder expects buffer to be zeroed, /* Note: entropy decoder expects buffer to be zeroed,
* but this is handled automatically by the memory manager * but this is handled automatically by the memory manager
* because we requested a pre-zeroed array. * because we requested a pre-zeroed array.
@ -222,14 +221,14 @@ consume_data (j_decompress_ptr cinfo)
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
start_col = MCU_col_num * compptr->MCU_width; start_col = MCU_col_num * compptr->MCU_width;
for (yindex = 0; yindex < compptr->MCU_height; yindex++) { for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
buffer_ptr = buffer[ci][yindex+yoffset] + start_col; buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
for (xindex = 0; xindex < compptr->MCU_width; xindex++) { for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
coef->MCU_buffer[blkn++] = buffer_ptr++; coef->MCU_buffer[blkn++] = buffer_ptr++;
} }
} }
} }
/* Try to fetch the MCU. */ /* Try to fetch the MCU. */
if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
/* Suspension forced; update state counters and exit */ /* Suspension forced; update state counters and exit */
coef->MCU_vert_offset = yoffset; coef->MCU_vert_offset = yoffset;
coef->MCU_ctr = MCU_col_num; coef->MCU_ctr = MCU_col_num;
@ -259,9 +258,9 @@ consume_data (j_decompress_ptr cinfo)
*/ */
METHODDEF(int) METHODDEF(int)
decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) decompress_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
JDIMENSION block_num; JDIMENSION block_num;
int ci, block_row, block_rows; int ci, block_row, block_rows;
@ -276,7 +275,7 @@ decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
while (cinfo->input_scan_number < cinfo->output_scan_number || while (cinfo->input_scan_number < cinfo->output_scan_number ||
(cinfo->input_scan_number == cinfo->output_scan_number && (cinfo->input_scan_number == cinfo->output_scan_number &&
cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED) if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
} }
@ -284,19 +283,19 @@ decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
/* Don't bother to IDCT an uninteresting component. */ /* Don't bother to IDCT an uninteresting component. */
if (! compptr->component_needed) if (!compptr->component_needed)
continue; continue;
/* Align the virtual buffer for this component. */ /* Align the virtual buffer for this component. */
buffer = (*cinfo->mem->access_virt_barray) buffer = (*cinfo->mem->access_virt_barray)
((j_common_ptr) cinfo, coef->whole_image[ci], ((j_common_ptr)cinfo, coef->whole_image[ci],
cinfo->output_iMCU_row * compptr->v_samp_factor, cinfo->output_iMCU_row * compptr->v_samp_factor,
(JDIMENSION) compptr->v_samp_factor, FALSE); (JDIMENSION)compptr->v_samp_factor, FALSE);
/* Count non-dummy DCT block rows in this iMCU row. */ /* Count non-dummy DCT block rows in this iMCU row. */
if (cinfo->output_iMCU_row < last_iMCU_row) if (cinfo->output_iMCU_row < last_iMCU_row)
block_rows = compptr->v_samp_factor; block_rows = compptr->v_samp_factor;
else { else {
/* NB: can't use last_row_height here; it is input-side-dependent! */ /* NB: can't use last_row_height here; it is input-side-dependent! */
block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
if (block_rows == 0) block_rows = compptr->v_samp_factor; if (block_rows == 0) block_rows = compptr->v_samp_factor;
} }
inverse_DCT = cinfo->idct->inverse_DCT[ci]; inverse_DCT = cinfo->idct->inverse_DCT[ci];
@ -307,8 +306,8 @@ decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
output_col = 0; output_col = 0;
for (block_num = cinfo->master->first_MCU_col[ci]; for (block_num = cinfo->master->first_MCU_col[ci];
block_num <= cinfo->master->last_MCU_col[ci]; block_num++) { block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr, (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
output_ptr, output_col); output_col);
buffer_ptr++; buffer_ptr++;
output_col += compptr->_DCT_scaled_size; output_col += compptr->_DCT_scaled_size;
} }
@ -350,9 +349,9 @@ decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
*/ */
LOCAL(boolean) LOCAL(boolean)
smoothing_ok (j_decompress_ptr cinfo) smoothing_ok(j_decompress_ptr cinfo)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
boolean smoothing_useful = FALSE; boolean smoothing_useful = FALSE;
int ci, coefi; int ci, coefi;
jpeg_component_info *compptr; jpeg_component_info *compptr;
@ -360,13 +359,13 @@ smoothing_ok (j_decompress_ptr cinfo)
int *coef_bits; int *coef_bits;
int *coef_bits_latch; int *coef_bits_latch;
if (! cinfo->progressive_mode || cinfo->coef_bits == NULL) if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
return FALSE; return FALSE;
/* Allocate latch area if not already done */ /* Allocate latch area if not already done */
if (coef->coef_bits_latch == NULL) if (coef->coef_bits_latch == NULL)
coef->coef_bits_latch = (int *) coef->coef_bits_latch = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
cinfo->num_components * cinfo->num_components *
(SAVED_COEFS * sizeof(int))); (SAVED_COEFS * sizeof(int)));
coef_bits_latch = coef->coef_bits_latch; coef_bits_latch = coef->coef_bits_latch;
@ -406,9 +405,9 @@ smoothing_ok (j_decompress_ptr cinfo)
*/ */
METHODDEF(int) METHODDEF(int)
decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
JDIMENSION block_num, last_block_column; JDIMENSION block_num, last_block_column;
int ci, block_row, block_rows, access_rows; int ci, block_row, block_rows, access_rows;
@ -422,8 +421,8 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
JCOEF *workspace; JCOEF *workspace;
int *coef_bits; int *coef_bits;
JQUANT_TBL *quanttbl; JQUANT_TBL *quanttbl;
JLONG Q00,Q01,Q02,Q10,Q11,Q20, num; JLONG Q00, Q01, Q02, Q10, Q11, Q20, num;
int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9; int DC1, DC2, DC3, DC4, DC5, DC6, DC7, DC8, DC9;
int Al, pred; int Al, pred;
/* Keep a local variable to avoid looking it up more than once */ /* Keep a local variable to avoid looking it up more than once */
@ -431,7 +430,7 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
/* Force some input to be done if we are getting ahead of the input. */ /* Force some input to be done if we are getting ahead of the input. */
while (cinfo->input_scan_number <= cinfo->output_scan_number && while (cinfo->input_scan_number <= cinfo->output_scan_number &&
! cinfo->inputctl->eoi_reached) { !cinfo->inputctl->eoi_reached) {
if (cinfo->input_scan_number == cinfo->output_scan_number) { if (cinfo->input_scan_number == cinfo->output_scan_number) {
/* If input is working on current scan, we ordinarily want it to /* If input is working on current scan, we ordinarily want it to
* have completed the current row. But if input scan is DC, * have completed the current row. But if input scan is DC,
@ -439,10 +438,10 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
* values are up to date. * values are up to date.
*/ */
JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0; JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta) if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
break; break;
} }
if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED) if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
} }
@ -450,7 +449,7 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
/* Don't bother to IDCT an uninteresting component. */ /* Don't bother to IDCT an uninteresting component. */
if (! compptr->component_needed) if (!compptr->component_needed)
continue; continue;
/* Count non-dummy DCT block rows in this iMCU row. */ /* Count non-dummy DCT block rows in this iMCU row. */
if (cinfo->output_iMCU_row < last_iMCU_row) { if (cinfo->output_iMCU_row < last_iMCU_row) {
@ -459,7 +458,7 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
last_row = FALSE; last_row = FALSE;
} else { } else {
/* NB: can't use last_row_height here; it is input-side-dependent! */ /* NB: can't use last_row_height here; it is input-side-dependent! */
block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
if (block_rows == 0) block_rows = compptr->v_samp_factor; if (block_rows == 0) block_rows = compptr->v_samp_factor;
access_rows = block_rows; /* this iMCU row only */ access_rows = block_rows; /* this iMCU row only */
last_row = TRUE; last_row = TRUE;
@ -468,15 +467,15 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
if (cinfo->output_iMCU_row > 0) { if (cinfo->output_iMCU_row > 0) {
access_rows += compptr->v_samp_factor; /* prior iMCU row too */ access_rows += compptr->v_samp_factor; /* prior iMCU row too */
buffer = (*cinfo->mem->access_virt_barray) buffer = (*cinfo->mem->access_virt_barray)
((j_common_ptr) cinfo, coef->whole_image[ci], ((j_common_ptr)cinfo, coef->whole_image[ci],
(cinfo->output_iMCU_row - 1) * compptr->v_samp_factor, (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
(JDIMENSION) access_rows, FALSE); (JDIMENSION)access_rows, FALSE);
buffer += compptr->v_samp_factor; /* point to current iMCU row */ buffer += compptr->v_samp_factor; /* point to current iMCU row */
first_row = FALSE; first_row = FALSE;
} else { } else {
buffer = (*cinfo->mem->access_virt_barray) buffer = (*cinfo->mem->access_virt_barray)
((j_common_ptr) cinfo, coef->whole_image[ci], ((j_common_ptr)cinfo, coef->whole_image[ci],
(JDIMENSION) 0, (JDIMENSION) access_rows, FALSE); (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
first_row = TRUE; first_row = TRUE;
} }
/* Fetch component-dependent info */ /* Fetch component-dependent info */
@ -496,111 +495,111 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
if (first_row && block_row == 0) if (first_row && block_row == 0)
prev_block_row = buffer_ptr; prev_block_row = buffer_ptr;
else else
prev_block_row = buffer[block_row-1]; prev_block_row = buffer[block_row - 1];
if (last_row && block_row == block_rows-1) if (last_row && block_row == block_rows - 1)
next_block_row = buffer_ptr; next_block_row = buffer_ptr;
else else
next_block_row = buffer[block_row+1]; next_block_row = buffer[block_row + 1];
/* We fetch the surrounding DC values using a sliding-register approach. /* We fetch the surrounding DC values using a sliding-register approach.
* Initialize all nine here so as to do the right thing on narrow pics. * Initialize all nine here so as to do the right thing on narrow pics.
*/ */
DC1 = DC2 = DC3 = (int) prev_block_row[0][0]; DC1 = DC2 = DC3 = (int)prev_block_row[0][0];
DC4 = DC5 = DC6 = (int) buffer_ptr[0][0]; DC4 = DC5 = DC6 = (int)buffer_ptr[0][0];
DC7 = DC8 = DC9 = (int) next_block_row[0][0]; DC7 = DC8 = DC9 = (int)next_block_row[0][0];
output_col = 0; output_col = 0;
last_block_column = compptr->width_in_blocks - 1; last_block_column = compptr->width_in_blocks - 1;
for (block_num = cinfo->master->first_MCU_col[ci]; for (block_num = cinfo->master->first_MCU_col[ci];
block_num <= cinfo->master->last_MCU_col[ci]; block_num++) { block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
/* Fetch current DCT block into workspace so we can modify it. */ /* Fetch current DCT block into workspace so we can modify it. */
jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1); jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
/* Update DC values */ /* Update DC values */
if (block_num < last_block_column) { if (block_num < last_block_column) {
DC3 = (int) prev_block_row[1][0]; DC3 = (int)prev_block_row[1][0];
DC6 = (int) buffer_ptr[1][0]; DC6 = (int)buffer_ptr[1][0];
DC9 = (int) next_block_row[1][0]; DC9 = (int)next_block_row[1][0];
} }
/* Compute coefficient estimates per K.8. /* Compute coefficient estimates per K.8.
* An estimate is applied only if coefficient is still zero, * An estimate is applied only if coefficient is still zero,
* and is not known to be fully accurate. * and is not known to be fully accurate.
*/ */
/* AC01 */ /* AC01 */
if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) { if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
num = 36 * Q00 * (DC4 - DC6); num = 36 * Q00 * (DC4 - DC6);
if (num >= 0) { if (num >= 0) {
pred = (int) (((Q01<<7) + num) / (Q01<<8)); pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1 << Al))
pred = (1<<Al)-1; pred = (1 << Al) - 1;
} else { } else {
pred = (int) (((Q01<<7) - num) / (Q01<<8)); pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1 << Al))
pred = (1<<Al)-1; pred = (1 << Al) - 1;
pred = -pred; pred = -pred;
} }
workspace[1] = (JCOEF) pred; workspace[1] = (JCOEF)pred;
} }
/* AC10 */ /* AC10 */
if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) { if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
num = 36 * Q00 * (DC2 - DC8); num = 36 * Q00 * (DC2 - DC8);
if (num >= 0) { if (num >= 0) {
pred = (int) (((Q10<<7) + num) / (Q10<<8)); pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1 << Al))
pred = (1<<Al)-1; pred = (1 << Al) - 1;
} else { } else {
pred = (int) (((Q10<<7) - num) / (Q10<<8)); pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1 << Al))
pred = (1<<Al)-1; pred = (1 << Al) - 1;
pred = -pred; pred = -pred;
} }
workspace[8] = (JCOEF) pred; workspace[8] = (JCOEF)pred;
} }
/* AC20 */ /* AC20 */
if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) { if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
num = 9 * Q00 * (DC2 + DC8 - 2*DC5); num = 9 * Q00 * (DC2 + DC8 - 2 * DC5);
if (num >= 0) { if (num >= 0) {
pred = (int) (((Q20<<7) + num) / (Q20<<8)); pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1 << Al))
pred = (1<<Al)-1; pred = (1 << Al) - 1;
} else { } else {
pred = (int) (((Q20<<7) - num) / (Q20<<8)); pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1 << Al))
pred = (1<<Al)-1; pred = (1 << Al) - 1;
pred = -pred; pred = -pred;
} }
workspace[16] = (JCOEF) pred; workspace[16] = (JCOEF)pred;
} }
/* AC11 */ /* AC11 */
if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) { if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9); num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
if (num >= 0) { if (num >= 0) {
pred = (int) (((Q11<<7) + num) / (Q11<<8)); pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1 << Al))
pred = (1<<Al)-1; pred = (1 << Al) - 1;
} else { } else {
pred = (int) (((Q11<<7) - num) / (Q11<<8)); pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1 << Al))
pred = (1<<Al)-1; pred = (1 << Al) - 1;
pred = -pred; pred = -pred;
} }
workspace[9] = (JCOEF) pred; workspace[9] = (JCOEF)pred;
} }
/* AC02 */ /* AC02 */
if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) { if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
num = 9 * Q00 * (DC4 + DC6 - 2*DC5); num = 9 * Q00 * (DC4 + DC6 - 2 * DC5);
if (num >= 0) { if (num >= 0) {
pred = (int) (((Q02<<7) + num) / (Q02<<8)); pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1 << Al))
pred = (1<<Al)-1; pred = (1 << Al) - 1;
} else { } else {
pred = (int) (((Q02<<7) - num) / (Q02<<8)); pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1 << Al))
pred = (1<<Al)-1; pred = (1 << Al) - 1;
pred = -pred; pred = -pred;
} }
workspace[2] = (JCOEF) pred; workspace[2] = (JCOEF)pred;
} }
/* OK, do the IDCT */ /* OK, do the IDCT */
(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace, (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
output_ptr, output_col); output_col);
/* Advance for next column */ /* Advance for next column */
DC1 = DC2; DC2 = DC3; DC1 = DC2; DC2 = DC3;
DC4 = DC5; DC5 = DC6; DC4 = DC5; DC5 = DC6;
@ -625,14 +624,14 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer) jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
{ {
my_coef_ptr coef; my_coef_ptr coef;
coef = (my_coef_ptr) coef = (my_coef_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_coef_controller)); sizeof(my_coef_controller));
cinfo->coef = (struct jpeg_d_coef_controller *) coef; cinfo->coef = (struct jpeg_d_coef_controller *)coef;
coef->pub.start_input_pass = start_input_pass; coef->pub.start_input_pass = start_input_pass;
coef->pub.start_output_pass = start_output_pass; coef->pub.start_output_pass = start_output_pass;
#ifdef BLOCK_SMOOTHING_SUPPORTED #ifdef BLOCK_SMOOTHING_SUPPORTED
@ -657,12 +656,12 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
access_rows *= 3; access_rows *= 3;
#endif #endif
coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE, ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
(JDIMENSION) jround_up((long) compptr->width_in_blocks, (JDIMENSION)jround_up((long)compptr->width_in_blocks,
(long) compptr->h_samp_factor), (long)compptr->h_samp_factor),
(JDIMENSION) jround_up((long) compptr->height_in_blocks, (JDIMENSION)jround_up((long)compptr->height_in_blocks,
(long) compptr->v_samp_factor), (long)compptr->v_samp_factor),
(JDIMENSION) access_rows); (JDIMENSION)access_rows);
} }
coef->pub.consume_data = consume_data; coef->pub.consume_data = consume_data;
coef->pub.decompress_data = decompress_data; coef->pub.decompress_data = decompress_data;
@ -676,7 +675,7 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
int i; int i;
buffer = (JBLOCKROW) buffer = (JBLOCKROW)
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK)); D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) { for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
coef->MCU_buffer[i] = buffer + i; coef->MCU_buffer[i] = buffer + i;
@ -688,6 +687,6 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
/* Allocate the workspace buffer */ /* Allocate the workspace buffer */
coef->workspace = (JCOEF *) coef->workspace = (JCOEF *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(JCOEF) * DCTSIZE2); sizeof(JCOEF) * DCTSIZE2);
} }

View File

@ -59,10 +59,10 @@ typedef my_coef_controller *my_coef_ptr;
LOCAL(void) LOCAL(void)
start_iMCU_row (j_decompress_ptr cinfo) start_iMCU_row(j_decompress_ptr cinfo)
/* Reset within-iMCU-row counters for a new row (input side) */ /* Reset within-iMCU-row counters for a new row (input side) */
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
/* In an interleaved scan, an MCU row is the same as an iMCU row. /* In an interleaved scan, an MCU row is the same as an iMCU row.
* In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
@ -71,7 +71,7 @@ start_iMCU_row (j_decompress_ptr cinfo)
if (cinfo->comps_in_scan > 1) { if (cinfo->comps_in_scan > 1) {
coef->MCU_rows_per_iMCU_row = 1; coef->MCU_rows_per_iMCU_row = 1;
} else { } else {
if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1)) if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows - 1))
coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
else else
coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;

View File

@ -17,22 +17,22 @@
INLINE INLINE
LOCAL(void) LOCAL(void)
ycc_rgb565_convert_internal (j_decompress_ptr cinfo, ycc_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, int num_rows) int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int y, cb, cr; register int y, cb, cr;
register JSAMPROW outptr; register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2; register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col; register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width; JDIMENSION num_cols = cinfo->output_width;
/* copy these pointers into registers if possible */ /* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit; register JSAMPLE *range_limit = cinfo->sample_range_limit;
register int * Crrtab = cconvert->Cr_r_tab; register int *Crrtab = cconvert->Cr_r_tab;
register int * Cbbtab = cconvert->Cb_b_tab; register int *Cbbtab = cconvert->Cb_b_tab;
register JLONG * Crgtab = cconvert->Cr_g_tab; register JLONG *Crgtab = cconvert->Cr_g_tab;
register JLONG * Cbgtab = cconvert->Cb_g_tab; register JLONG *Cbgtab = cconvert->Cb_g_tab;
SHIFT_TEMPS SHIFT_TEMPS
while (--num_rows >= 0) { while (--num_rows >= 0) {
@ -53,7 +53,7 @@ ycc_rgb565_convert_internal (j_decompress_ptr cinfo,
SCALEBITS))]; SCALEBITS))];
b = range_limit[y + Cbbtab[cb]]; b = range_limit[y + Cbbtab[cb]];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
outptr += 2; outptr += 2;
num_cols--; num_cols--;
} }
@ -88,7 +88,7 @@ ycc_rgb565_convert_internal (j_decompress_ptr cinfo,
SCALEBITS))]; SCALEBITS))];
b = range_limit[y + Cbbtab[cb]]; b = range_limit[y + Cbbtab[cb]];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
} }
} }
} }
@ -96,22 +96,22 @@ ycc_rgb565_convert_internal (j_decompress_ptr cinfo,
INLINE INLINE
LOCAL(void) LOCAL(void)
ycc_rgb565D_convert_internal (j_decompress_ptr cinfo, ycc_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, int num_rows) int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int y, cb, cr; register int y, cb, cr;
register JSAMPROW outptr; register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2; register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col; register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width; JDIMENSION num_cols = cinfo->output_width;
/* copy these pointers into registers if possible */ /* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit; register JSAMPLE *range_limit = cinfo->sample_range_limit;
register int * Crrtab = cconvert->Cr_r_tab; register int *Crrtab = cconvert->Cr_r_tab;
register int * Cbbtab = cconvert->Cb_b_tab; register int *Cbbtab = cconvert->Cb_b_tab;
register JLONG * Crgtab = cconvert->Cr_g_tab; register JLONG *Crgtab = cconvert->Cr_g_tab;
register JLONG * Cbgtab = cconvert->Cb_g_tab; register JLONG *Cbgtab = cconvert->Cb_g_tab;
JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK]; JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
SHIFT_TEMPS SHIFT_TEMPS
@ -134,7 +134,7 @@ ycc_rgb565D_convert_internal (j_decompress_ptr cinfo,
SCALEBITS)), d0)]; SCALEBITS)), d0)];
b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)]; b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
outptr += 2; outptr += 2;
num_cols--; num_cols--;
} }
@ -174,7 +174,7 @@ ycc_rgb565D_convert_internal (j_decompress_ptr cinfo,
SCALEBITS)), d0)]; SCALEBITS)), d0)];
b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)]; b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
} }
} }
} }
@ -182,9 +182,9 @@ ycc_rgb565D_convert_internal (j_decompress_ptr cinfo,
INLINE INLINE
LOCAL(void) LOCAL(void)
rgb_rgb565_convert_internal (j_decompress_ptr cinfo, rgb_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, int num_rows) int num_rows)
{ {
register JSAMPROW outptr; register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2; register JSAMPROW inptr0, inptr1, inptr2;
@ -206,7 +206,7 @@ rgb_rgb565_convert_internal (j_decompress_ptr cinfo,
g = GETJSAMPLE(*inptr1++); g = GETJSAMPLE(*inptr1++);
b = GETJSAMPLE(*inptr2++); b = GETJSAMPLE(*inptr2++);
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
outptr += 2; outptr += 2;
num_cols--; num_cols--;
} }
@ -229,7 +229,7 @@ rgb_rgb565_convert_internal (j_decompress_ptr cinfo,
g = GETJSAMPLE(*inptr1); g = GETJSAMPLE(*inptr1);
b = GETJSAMPLE(*inptr2); b = GETJSAMPLE(*inptr2);
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
} }
} }
} }
@ -237,14 +237,14 @@ rgb_rgb565_convert_internal (j_decompress_ptr cinfo,
INLINE INLINE
LOCAL(void) LOCAL(void)
rgb_rgb565D_convert_internal (j_decompress_ptr cinfo, rgb_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, int num_rows) int num_rows)
{ {
register JSAMPROW outptr; register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2; register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col; register JDIMENSION col;
register JSAMPLE * range_limit = cinfo->sample_range_limit; register JSAMPLE *range_limit = cinfo->sample_range_limit;
JDIMENSION num_cols = cinfo->output_width; JDIMENSION num_cols = cinfo->output_width;
JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK]; JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
SHIFT_TEMPS SHIFT_TEMPS
@ -263,7 +263,7 @@ rgb_rgb565D_convert_internal (j_decompress_ptr cinfo,
g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1++), d0)]; g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1++), d0)];
b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2++), d0)]; b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2++), d0)];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
outptr += 2; outptr += 2;
num_cols--; num_cols--;
} }
@ -288,7 +288,7 @@ rgb_rgb565D_convert_internal (j_decompress_ptr cinfo,
g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1), d0)]; g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1), d0)];
b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2), d0)]; b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2), d0)];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
} }
} }
} }
@ -296,9 +296,9 @@ rgb_rgb565D_convert_internal (j_decompress_ptr cinfo,
INLINE INLINE
LOCAL(void) LOCAL(void)
gray_rgb565_convert_internal (j_decompress_ptr cinfo, gray_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, int num_rows) int num_rows)
{ {
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
register JDIMENSION col; register JDIMENSION col;
@ -313,7 +313,7 @@ gray_rgb565_convert_internal (j_decompress_ptr cinfo,
if (PACK_NEED_ALIGNMENT(outptr)) { if (PACK_NEED_ALIGNMENT(outptr)) {
g = *inptr++; g = *inptr++;
rgb = PACK_SHORT_565(g, g, g); rgb = PACK_SHORT_565(g, g, g);
*(INT16*)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
outptr += 2; outptr += 2;
num_cols--; num_cols--;
} }
@ -328,7 +328,7 @@ gray_rgb565_convert_internal (j_decompress_ptr cinfo,
if (num_cols & 1) { if (num_cols & 1) {
g = *inptr; g = *inptr;
rgb = PACK_SHORT_565(g, g, g); rgb = PACK_SHORT_565(g, g, g);
*(INT16*)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
} }
} }
} }
@ -336,13 +336,13 @@ gray_rgb565_convert_internal (j_decompress_ptr cinfo,
INLINE INLINE
LOCAL(void) LOCAL(void)
gray_rgb565D_convert_internal (j_decompress_ptr cinfo, gray_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, int num_rows) int num_rows)
{ {
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
register JDIMENSION col; register JDIMENSION col;
register JSAMPLE * range_limit = cinfo->sample_range_limit; register JSAMPLE *range_limit = cinfo->sample_range_limit;
JDIMENSION num_cols = cinfo->output_width; JDIMENSION num_cols = cinfo->output_width;
JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK]; JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
@ -356,7 +356,7 @@ gray_rgb565D_convert_internal (j_decompress_ptr cinfo,
g = *inptr++; g = *inptr++;
g = range_limit[DITHER_565_R(g, d0)]; g = range_limit[DITHER_565_R(g, d0)];
rgb = PACK_SHORT_565(g, g, g); rgb = PACK_SHORT_565(g, g, g);
*(INT16*)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
outptr += 2; outptr += 2;
num_cols--; num_cols--;
} }
@ -378,7 +378,7 @@ gray_rgb565D_convert_internal (j_decompress_ptr cinfo,
g = *inptr; g = *inptr;
g = range_limit[DITHER_565_R(g, d0)]; g = range_limit[DITHER_565_R(g, d0)];
rgb = PACK_SHORT_565(g, g, g); rgb = PACK_SHORT_565(g, g, g);
*(INT16*)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
} }
} }
} }

View File

@ -28,22 +28,22 @@
INLINE INLINE
LOCAL(void) LOCAL(void)
ycc_rgb_convert_internal (j_decompress_ptr cinfo, ycc_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, int num_rows) int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int y, cb, cr; register int y, cb, cr;
register JSAMPROW outptr; register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2; register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col; register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width; JDIMENSION num_cols = cinfo->output_width;
/* copy these pointers into registers if possible */ /* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit; register JSAMPLE *range_limit = cinfo->sample_range_limit;
register int * Crrtab = cconvert->Cr_r_tab; register int *Crrtab = cconvert->Cr_r_tab;
register int * Cbbtab = cconvert->Cb_b_tab; register int *Cbbtab = cconvert->Cb_b_tab;
register JLONG * Crgtab = cconvert->Cr_g_tab; register JLONG *Crgtab = cconvert->Cr_g_tab;
register JLONG * Cbgtab = cconvert->Cb_g_tab; register JLONG *Cbgtab = cconvert->Cb_g_tab;
SHIFT_TEMPS SHIFT_TEMPS
while (--num_rows >= 0) { while (--num_rows >= 0) {
@ -59,7 +59,7 @@ ycc_rgb_convert_internal (j_decompress_ptr cinfo,
/* Range-limiting is essential due to noise introduced by DCT losses. */ /* Range-limiting is essential due to noise introduced by DCT losses. */
outptr[RGB_RED] = range_limit[y + Crrtab[cr]]; outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
outptr[RGB_GREEN] = range_limit[y + outptr[RGB_GREEN] = range_limit[y +
((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS))]; SCALEBITS))];
outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]]; outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
/* Set unused byte to 0xFF so it can be interpreted as an opaque */ /* Set unused byte to 0xFF so it can be interpreted as an opaque */
@ -81,9 +81,9 @@ ycc_rgb_convert_internal (j_decompress_ptr cinfo,
INLINE INLINE
LOCAL(void) LOCAL(void)
gray_rgb_convert_internal (j_decompress_ptr cinfo, gray_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, int num_rows) int num_rows)
{ {
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
register JDIMENSION col; register JDIMENSION col;
@ -112,9 +112,9 @@ gray_rgb_convert_internal (j_decompress_ptr cinfo,
INLINE INLINE
LOCAL(void) LOCAL(void)
rgb_rgb_convert_internal (j_decompress_ptr cinfo, rgb_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, int num_rows) int num_rows)
{ {
register JSAMPROW inptr0, inptr1, inptr2; register JSAMPROW inptr0, inptr1, inptr2;
register JSAMPROW outptr; register JSAMPROW outptr;

View File

@ -74,8 +74,8 @@ typedef my_color_deconverter *my_cconvert_ptr;
*/ */
#define SCALEBITS 16 /* speediest right-shift on some machines */ #define SCALEBITS 16 /* speediest right-shift on some machines */
#define ONE_HALF ((JLONG) 1 << (SCALEBITS-1)) #define ONE_HALF ((JLONG)1 << (SCALEBITS - 1))
#define FIX(x) ((JLONG) ((x) * (1L<<SCALEBITS) + 0.5)) #define FIX(x) ((JLONG)((x) * (1L << SCALEBITS) + 0.5))
/* We allocate one big table for RGB->Y conversion and divide it up into /* We allocate one big table for RGB->Y conversion and divide it up into
* three parts, instead of doing three alloc_small requests. This lets us * three parts, instead of doing three alloc_small requests. This lets us
@ -85,9 +85,9 @@ typedef my_color_deconverter *my_cconvert_ptr;
*/ */
#define R_Y_OFF 0 /* offset to R => Y section */ #define R_Y_OFF 0 /* offset to R => Y section */
#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */ #define G_Y_OFF (1 * (MAXJSAMPLE + 1)) /* offset to G => Y section */
#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */ #define B_Y_OFF (2 * (MAXJSAMPLE + 1)) /* etc. */
#define TABLE_SIZE (3*(MAXJSAMPLE+1)) #define TABLE_SIZE (3 * (MAXJSAMPLE + 1))
/* Include inline routines for colorspace extensions */ /* Include inline routines for colorspace extensions */
@ -208,25 +208,25 @@ typedef my_color_deconverter *my_cconvert_ptr;
*/ */
LOCAL(void) LOCAL(void)
build_ycc_rgb_table (j_decompress_ptr cinfo) build_ycc_rgb_table(j_decompress_ptr cinfo)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
int i; int i;
JLONG x; JLONG x;
SHIFT_TEMPS SHIFT_TEMPS
cconvert->Cr_r_tab = (int *) cconvert->Cr_r_tab = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * sizeof(int)); (MAXJSAMPLE + 1) * sizeof(int));
cconvert->Cb_b_tab = (int *) cconvert->Cb_b_tab = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * sizeof(int)); (MAXJSAMPLE + 1) * sizeof(int));
cconvert->Cr_g_tab = (JLONG *) cconvert->Cr_g_tab = (JLONG *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * sizeof(JLONG)); (MAXJSAMPLE + 1) * sizeof(JLONG));
cconvert->Cb_g_tab = (JLONG *) cconvert->Cb_g_tab = (JLONG *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * sizeof(JLONG)); (MAXJSAMPLE + 1) * sizeof(JLONG));
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
@ -238,10 +238,10 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
cconvert->Cb_b_tab[i] = (int) cconvert->Cb_b_tab[i] = (int)
RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
/* Cr=>G value is scaled-up -0.71414 * x */ /* Cr=>G value is scaled-up -0.71414 * x */
cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x; cconvert->Cr_g_tab[i] = (-FIX(0.71414)) * x;
/* Cb=>G value is scaled-up -0.34414 * x */ /* Cb=>G value is scaled-up -0.34414 * x */
/* We also add in ONE_HALF so that need not do it in inner loop */ /* We also add in ONE_HALF so that need not do it in inner loop */
cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; cconvert->Cb_g_tab[i] = (-FIX(0.34414)) * x + ONE_HALF;
} }
} }
@ -251,9 +251,8 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
ycc_rgb_convert (j_decompress_ptr cinfo, ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
JSAMPARRAY output_buf, int num_rows)
{ {
switch (cinfo->out_color_space) { switch (cinfo->out_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@ -300,21 +299,21 @@ ycc_rgb_convert (j_decompress_ptr cinfo,
*/ */
LOCAL(void) LOCAL(void)
build_rgb_y_table (j_decompress_ptr cinfo) build_rgb_y_table(j_decompress_ptr cinfo)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
JLONG *rgb_y_tab; JLONG *rgb_y_tab;
JLONG i; JLONG i;
/* Allocate and fill in the conversion tables. */ /* Allocate and fill in the conversion tables. */
cconvert->rgb_y_tab = rgb_y_tab = (JLONG *) cconvert->rgb_y_tab = rgb_y_tab = (JLONG *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(TABLE_SIZE * sizeof(JLONG))); (TABLE_SIZE * sizeof(JLONG)));
for (i = 0; i <= MAXJSAMPLE; i++) { for (i = 0; i <= MAXJSAMPLE; i++) {
rgb_y_tab[i+R_Y_OFF] = FIX(0.29900) * i; rgb_y_tab[i + R_Y_OFF] = FIX(0.29900) * i;
rgb_y_tab[i+G_Y_OFF] = FIX(0.58700) * i; rgb_y_tab[i + G_Y_OFF] = FIX(0.58700) * i;
rgb_y_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF; rgb_y_tab[i + B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
} }
} }
@ -324,11 +323,10 @@ build_rgb_y_table (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
rgb_gray_convert (j_decompress_ptr cinfo, rgb_gray_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
JSAMPARRAY output_buf, int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int r, g, b; register int r, g, b;
register JLONG *ctab = cconvert->rgb_y_tab; register JLONG *ctab = cconvert->rgb_y_tab;
register JSAMPROW outptr; register JSAMPROW outptr;
@ -347,9 +345,8 @@ rgb_gray_convert (j_decompress_ptr cinfo,
g = GETJSAMPLE(inptr1[col]); g = GETJSAMPLE(inptr1[col]);
b = GETJSAMPLE(inptr2[col]); b = GETJSAMPLE(inptr2[col]);
/* Y */ /* Y */
outptr[col] = (JSAMPLE) outptr[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) ctab[b + B_Y_OFF]) >> SCALEBITS);
>> SCALEBITS);
} }
} }
} }
@ -361,9 +358,8 @@ rgb_gray_convert (j_decompress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
null_convert (j_decompress_ptr cinfo, null_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
JSAMPARRAY output_buf, int num_rows)
{ {
register JSAMPROW inptr, inptr0, inptr1, inptr2, inptr3, outptr; register JSAMPROW inptr, inptr0, inptr1, inptr2, inptr3, outptr;
register JDIMENSION col; register JDIMENSION col;
@ -423,12 +419,11 @@ null_convert (j_decompress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
grayscale_convert (j_decompress_ptr cinfo, grayscale_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
JSAMPARRAY output_buf, int num_rows)
{ {
jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0, jcopy_sample_rows(input_buf[0], (int)input_row, output_buf, 0, num_rows,
num_rows, cinfo->output_width); cinfo->output_width);
} }
@ -437,9 +432,8 @@ grayscale_convert (j_decompress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
gray_rgb_convert (j_decompress_ptr cinfo, gray_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
JSAMPARRAY output_buf, int num_rows)
{ {
switch (cinfo->out_color_space) { switch (cinfo->out_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@ -483,9 +477,8 @@ gray_rgb_convert (j_decompress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
rgb_rgb_convert (j_decompress_ptr cinfo, rgb_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
JSAMPARRAY output_buf, int num_rows)
{ {
switch (cinfo->out_color_space) { switch (cinfo->out_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@ -532,11 +525,10 @@ rgb_rgb_convert (j_decompress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
ycck_cmyk_convert (j_decompress_ptr cinfo, ycck_cmyk_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
JSAMPARRAY output_buf, int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int y, cb, cr; register int y, cb, cr;
register JSAMPROW outptr; register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2, inptr3; register JSAMPROW inptr0, inptr1, inptr2, inptr3;
@ -564,7 +556,7 @@ ycck_cmyk_convert (j_decompress_ptr cinfo,
/* Range-limiting is essential due to noise introduced by DCT losses. */ /* Range-limiting is essential due to noise introduced by DCT losses. */
outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */ outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */ outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS)))]; SCALEBITS)))];
outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */ outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
/* K passes through unchanged */ /* K passes through unchanged */
@ -600,7 +592,7 @@ ycck_cmyk_convert (j_decompress_ptr cinfo,
/* Declarations for ordered dithering /* Declarations for ordered dithering
* *
* We use a 4x4 ordered dither array packed into 32 bits. This array is * We use a 4x4 ordered dither array packed into 32 bits. This array is
* sufficent for dithering RGB888 to RGB565. * sufficient for dithering RGB888 to RGB565.
*/ */
#define DITHER_MASK 0x3 #define DITHER_MASK 0x3
@ -662,9 +654,8 @@ static INLINE boolean is_big_endian(void)
METHODDEF(void) METHODDEF(void)
ycc_rgb565_convert (j_decompress_ptr cinfo, ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
JSAMPARRAY output_buf, int num_rows)
{ {
if (is_big_endian()) if (is_big_endian())
ycc_rgb565_convert_be(cinfo, input_buf, input_row, output_buf, num_rows); ycc_rgb565_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
@ -674,9 +665,8 @@ ycc_rgb565_convert (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
ycc_rgb565D_convert (j_decompress_ptr cinfo, ycc_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
JSAMPARRAY output_buf, int num_rows)
{ {
if (is_big_endian()) if (is_big_endian())
ycc_rgb565D_convert_be(cinfo, input_buf, input_row, output_buf, num_rows); ycc_rgb565D_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
@ -686,9 +676,8 @@ ycc_rgb565D_convert (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
rgb_rgb565_convert (j_decompress_ptr cinfo, rgb_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
JSAMPARRAY output_buf, int num_rows)
{ {
if (is_big_endian()) if (is_big_endian())
rgb_rgb565_convert_be(cinfo, input_buf, input_row, output_buf, num_rows); rgb_rgb565_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
@ -698,9 +687,8 @@ rgb_rgb565_convert (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
rgb_rgb565D_convert (j_decompress_ptr cinfo, rgb_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
JSAMPARRAY output_buf, int num_rows)
{ {
if (is_big_endian()) if (is_big_endian())
rgb_rgb565D_convert_be(cinfo, input_buf, input_row, output_buf, num_rows); rgb_rgb565D_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
@ -710,9 +698,8 @@ rgb_rgb565D_convert (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
gray_rgb565_convert (j_decompress_ptr cinfo, gray_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
JSAMPARRAY output_buf, int num_rows)
{ {
if (is_big_endian()) if (is_big_endian())
gray_rgb565_convert_be(cinfo, input_buf, input_row, output_buf, num_rows); gray_rgb565_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
@ -722,9 +709,8 @@ gray_rgb565_convert (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
gray_rgb565D_convert (j_decompress_ptr cinfo, gray_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
JSAMPARRAY output_buf, int num_rows)
{ {
if (is_big_endian()) if (is_big_endian())
gray_rgb565D_convert_be(cinfo, input_buf, input_row, output_buf, num_rows); gray_rgb565D_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
@ -738,7 +724,7 @@ gray_rgb565D_convert (j_decompress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_dcolor (j_decompress_ptr cinfo) start_pass_dcolor(j_decompress_ptr cinfo)
{ {
/* no work needed */ /* no work needed */
} }
@ -749,15 +735,15 @@ start_pass_dcolor (j_decompress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_color_deconverter (j_decompress_ptr cinfo) jinit_color_deconverter(j_decompress_ptr cinfo)
{ {
my_cconvert_ptr cconvert; my_cconvert_ptr cconvert;
int ci; int ci;
cconvert = (my_cconvert_ptr) cconvert = (my_cconvert_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_color_deconverter)); sizeof(my_color_deconverter));
cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert; cinfo->cconvert = (struct jpeg_color_deconverter *)cconvert;
cconvert->pub.start_pass = start_pass_dcolor; cconvert->pub.start_pass = start_pass_dcolor;
/* Make sure num_components agrees with jpeg_color_space */ /* Make sure num_components agrees with jpeg_color_space */

View File

@ -90,64 +90,64 @@ typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
/* Extern declarations for the forward and inverse DCT routines. */ /* Extern declarations for the forward and inverse DCT routines. */
EXTERN(void) jpeg_fdct_islow (DCTELEM *data); EXTERN(void) jpeg_fdct_islow(DCTELEM *data);
EXTERN(void) jpeg_fdct_ifast (DCTELEM *data); EXTERN(void) jpeg_fdct_ifast(DCTELEM *data);
EXTERN(void) jpeg_fdct_float (FAST_FLOAT *data); EXTERN(void) jpeg_fdct_float(FAST_FLOAT *data);
EXTERN(void) jpeg_idct_islow EXTERN(void) jpeg_idct_islow(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_ifast EXTERN(void) jpeg_idct_ifast(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_float EXTERN(void) jpeg_idct_float(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_7x7 EXTERN(void) jpeg_idct_7x7(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_6x6 EXTERN(void) jpeg_idct_6x6(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_5x5 EXTERN(void) jpeg_idct_5x5(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_4x4 EXTERN(void) jpeg_idct_4x4(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_3x3 EXTERN(void) jpeg_idct_3x3(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_2x2 EXTERN(void) jpeg_idct_2x2(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_1x1 EXTERN(void) jpeg_idct_1x1(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_9x9 EXTERN(void) jpeg_idct_9x9(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_10x10 EXTERN(void) jpeg_idct_10x10(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_11x11 EXTERN(void) jpeg_idct_11x11(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_12x12 EXTERN(void) jpeg_idct_12x12(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_13x13 EXTERN(void) jpeg_idct_13x13(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_14x14 EXTERN(void) jpeg_idct_14x14(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_15x15 EXTERN(void) jpeg_idct_15x15(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_16x16 EXTERN(void) jpeg_idct_16x16(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col); JSAMPARRAY output_buf, JDIMENSION output_col);
/* /*
@ -160,7 +160,7 @@ EXTERN(void) jpeg_idct_16x16
* and may differ from one module to the next. * and may differ from one module to the next.
*/ */
#define ONE ((JLONG) 1) #define ONE ((JLONG)1)
#define CONST_SCALE (ONE << CONST_BITS) #define CONST_SCALE (ONE << CONST_BITS)
/* Convert a positive real constant to an integer scaled by CONST_SCALE. /* Convert a positive real constant to an integer scaled by CONST_SCALE.
@ -168,14 +168,14 @@ EXTERN(void) jpeg_idct_16x16
* thus causing a lot of useless floating-point operations at run time. * thus causing a lot of useless floating-point operations at run time.
*/ */
#define FIX(x) ((JLONG) ((x) * CONST_SCALE + 0.5)) #define FIX(x) ((JLONG)((x) * CONST_SCALE + 0.5))
/* Descale and correctly round a JLONG value that's scaled by N bits. /* Descale and correctly round a JLONG value that's scaled by N bits.
* We assume RIGHT_SHIFT rounds towards minus infinity, so adding * We assume RIGHT_SHIFT rounds towards minus infinity, so adding
* the fudge factor is correct for either sign of X. * the fudge factor is correct for either sign of X.
*/ */
#define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) #define DESCALE(x, n) RIGHT_SHIFT((x) + (ONE << ((n) - 1)), n)
/* Multiply a JLONG variable by a JLONG constant to yield a JLONG result. /* Multiply a JLONG variable by a JLONG constant to yield a JLONG result.
* This macro is used only when the two inputs will actually be no more than * This macro is used only when the two inputs will actually be no more than
@ -187,22 +187,22 @@ EXTERN(void) jpeg_idct_16x16
*/ */
#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
#define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const))) #define MULTIPLY16C16(var, const) (((INT16)(var)) * ((INT16)(const)))
#endif #endif
#ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */ #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
#define MULTIPLY16C16(var,const) (((INT16) (var)) * ((JLONG) (const))) #define MULTIPLY16C16(var, const) (((INT16)(var)) * ((JLONG)(const)))
#endif #endif
#ifndef MULTIPLY16C16 /* default definition */ #ifndef MULTIPLY16C16 /* default definition */
#define MULTIPLY16C16(var,const) ((var) * (const)) #define MULTIPLY16C16(var, const) ((var) * (const))
#endif #endif
/* Same except both inputs are variables. */ /* Same except both inputs are variables. */
#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
#define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2))) #define MULTIPLY16V16(var1, var2) (((INT16)(var1)) * ((INT16)(var2)))
#endif #endif
#ifndef MULTIPLY16V16 /* default definition */ #ifndef MULTIPLY16V16 /* default definition */
#define MULTIPLY16V16(var1,var2) ((var1) * (var2)) #define MULTIPLY16V16(var1, var2) ((var1) * (var2))
#endif #endif

View File

@ -94,9 +94,9 @@ typedef union {
*/ */
METHODDEF(void) METHODDEF(void)
start_pass (j_decompress_ptr cinfo) start_pass(j_decompress_ptr cinfo)
{ {
my_idct_ptr idct = (my_idct_ptr) cinfo->idct; my_idct_ptr idct = (my_idct_ptr)cinfo->idct;
int ci, i; int ci, i;
jpeg_component_info *compptr; jpeg_component_info *compptr;
int method = 0; int method = 0;
@ -233,7 +233,7 @@ start_pass (j_decompress_ptr cinfo)
* multiplier table all-zero; we'll be reading zeroes from the * multiplier table all-zero; we'll be reading zeroes from the
* coefficient controller's buffer anyway. * coefficient controller's buffer anyway.
*/ */
if (! compptr->component_needed || idct->cur_method[ci] == method) if (!compptr->component_needed || idct->cur_method[ci] == method)
continue; continue;
qtbl = compptr->quant_table; qtbl = compptr->quant_table;
if (qtbl == NULL) /* happens if no data yet for component */ if (qtbl == NULL) /* happens if no data yet for component */
@ -246,9 +246,9 @@ start_pass (j_decompress_ptr cinfo)
/* For LL&M IDCT method, multipliers are equal to raw quantization /* For LL&M IDCT method, multipliers are equal to raw quantization
* coefficients, but are stored as ints to ensure access efficiency. * coefficients, but are stored as ints to ensure access efficiency.
*/ */
ISLOW_MULT_TYPE *ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table; ISLOW_MULT_TYPE *ismtbl = (ISLOW_MULT_TYPE *)compptr->dct_table;
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i]; ismtbl[i] = (ISLOW_MULT_TYPE)qtbl->quantval[i];
} }
} }
break; break;
@ -263,7 +263,7 @@ start_pass (j_decompress_ptr cinfo)
* For integer operation, the multiplier table is to be scaled by * For integer operation, the multiplier table is to be scaled by
* IFAST_SCALE_BITS. * IFAST_SCALE_BITS.
*/ */
IFAST_MULT_TYPE *ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table; IFAST_MULT_TYPE *ifmtbl = (IFAST_MULT_TYPE *)compptr->dct_table;
#define CONST_BITS 14 #define CONST_BITS 14
static const INT16 aanscales[DCTSIZE2] = { static const INT16 aanscales[DCTSIZE2] = {
/* precomputed values scaled up by 14 bits */ /* precomputed values scaled up by 14 bits */
@ -280,9 +280,9 @@ start_pass (j_decompress_ptr cinfo)
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
ifmtbl[i] = (IFAST_MULT_TYPE) ifmtbl[i] = (IFAST_MULT_TYPE)
DESCALE(MULTIPLY16V16((JLONG) qtbl->quantval[i], DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
(JLONG) aanscales[i]), (JLONG)aanscales[i]),
CONST_BITS-IFAST_SCALE_BITS); CONST_BITS - IFAST_SCALE_BITS);
} }
} }
break; break;
@ -295,7 +295,7 @@ start_pass (j_decompress_ptr cinfo)
* scalefactor[0] = 1 * scalefactor[0] = 1
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
*/ */
FLOAT_MULT_TYPE *fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table; FLOAT_MULT_TYPE *fmtbl = (FLOAT_MULT_TYPE *)compptr->dct_table;
int row, col; int row, col;
static const double aanscalefactor[DCTSIZE] = { static const double aanscalefactor[DCTSIZE] = {
1.0, 1.387039845, 1.306562965, 1.175875602, 1.0, 1.387039845, 1.306562965, 1.175875602,
@ -306,7 +306,7 @@ start_pass (j_decompress_ptr cinfo)
for (row = 0; row < DCTSIZE; row++) { for (row = 0; row < DCTSIZE; row++) {
for (col = 0; col < DCTSIZE; col++) { for (col = 0; col < DCTSIZE; col++) {
fmtbl[i] = (FLOAT_MULT_TYPE) fmtbl[i] = (FLOAT_MULT_TYPE)
((double) qtbl->quantval[i] * ((double)qtbl->quantval[i] *
aanscalefactor[row] * aanscalefactor[col]); aanscalefactor[row] * aanscalefactor[col]);
i++; i++;
} }
@ -327,23 +327,23 @@ start_pass (j_decompress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_inverse_dct (j_decompress_ptr cinfo) jinit_inverse_dct(j_decompress_ptr cinfo)
{ {
my_idct_ptr idct; my_idct_ptr idct;
int ci; int ci;
jpeg_component_info *compptr; jpeg_component_info *compptr;
idct = (my_idct_ptr) idct = (my_idct_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_idct_controller)); sizeof(my_idct_controller));
cinfo->idct = (struct jpeg_inverse_dct *) idct; cinfo->idct = (struct jpeg_inverse_dct *)idct;
idct->pub.start_pass = start_pass; idct->pub.start_pass = start_pass;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
/* Allocate and pre-zero a multiplier table for each component */ /* Allocate and pre-zero a multiplier table for each component */
compptr->dct_table = compptr->dct_table =
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(multiplier_table)); sizeof(multiplier_table));
MEMZERO(compptr->dct_table, sizeof(multiplier_table)); MEMZERO(compptr->dct_table, sizeof(multiplier_table));
/* Mark multiplier table not yet set up for any method */ /* Mark multiplier table not yet set up for any method */

View File

@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009-2011, 2016, D. R. Commander. * Copyright (C) 2009-2011, 2016, 2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@ -15,6 +15,9 @@
* up to the start of the current MCU. To do this, we copy state variables * up to the start of the current MCU. To do this, we copy state variables
* into local working storage, and update them back to the permanent * into local working storage, and update them back to the permanent
* storage only upon successful completion of an MCU. * storage only upon successful completion of an MCU.
*
* NOTE: All referenced figures are from
* Recommendation ITU-T T.81 (1992) | ISO/IEC 10918-1:1994.
*/ */
#define JPEG_INTERNALS #define JPEG_INTERNALS
@ -42,10 +45,10 @@ typedef struct {
*/ */
#ifndef NO_STRUCT_ASSIGN #ifndef NO_STRUCT_ASSIGN
#define ASSIGN_STATE(dest,src) ((dest) = (src)) #define ASSIGN_STATE(dest, src) ((dest) = (src))
#else #else
#if MAX_COMPS_IN_SCAN == 4 #if MAX_COMPS_IN_SCAN == 4
#define ASSIGN_STATE(dest,src) \ #define ASSIGN_STATE(dest, src) \
((dest).last_dc_val[0] = (src).last_dc_val[0], \ ((dest).last_dc_val[0] = (src).last_dc_val[0], \
(dest).last_dc_val[1] = (src).last_dc_val[1], \ (dest).last_dc_val[1] = (src).last_dc_val[1], \
(dest).last_dc_val[2] = (src).last_dc_val[2], \ (dest).last_dc_val[2] = (src).last_dc_val[2], \
@ -88,9 +91,9 @@ typedef huff_entropy_decoder *huff_entropy_ptr;
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_huff_decoder (j_decompress_ptr cinfo) start_pass_huff_decoder(j_decompress_ptr cinfo)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
int ci, blkn, dctbl, actbl; int ci, blkn, dctbl, actbl;
d_derived_tbl **pdtbl; d_derived_tbl **pdtbl;
jpeg_component_info *compptr; jpeg_component_info *compptr;
@ -99,7 +102,7 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
* This ought to be an error condition, but we make it a warning because * This ought to be an error condition, but we make it a warning because
* there are some baseline files out there with all zeroes in these bytes. * there are some baseline files out there with all zeroes in these bytes.
*/ */
if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 || if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2 - 1 ||
cinfo->Ah != 0 || cinfo->Al != 0) cinfo->Ah != 0 || cinfo->Al != 0)
WARNMS(cinfo, JWRN_NOT_SEQUENTIAL); WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
@ -152,7 +155,7 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno, jpeg_make_d_derived_tbl(j_decompress_ptr cinfo, boolean isDC, int tblno,
d_derived_tbl **pdtbl) d_derived_tbl **pdtbl)
{ {
JHUFF_TBL *htbl; JHUFF_TBL *htbl;
@ -178,7 +181,7 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
/* Allocate a workspace if we haven't already done so. */ /* Allocate a workspace if we haven't already done so. */
if (*pdtbl == NULL) if (*pdtbl == NULL)
*pdtbl = (d_derived_tbl *) *pdtbl = (d_derived_tbl *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(d_derived_tbl)); sizeof(d_derived_tbl));
dtbl = *pdtbl; dtbl = *pdtbl;
dtbl->pub = htbl; /* fill in back link */ dtbl->pub = htbl; /* fill in back link */
@ -187,11 +190,11 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
p = 0; p = 0;
for (l = 1; l <= 16; l++) { for (l = 1; l <= 16; l++) {
i = (int) htbl->bits[l]; i = (int)htbl->bits[l];
if (i < 0 || p + i > 256) /* protect against table overrun */ if (i < 0 || p + i > 256) /* protect against table overrun */
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
while (i--) while (i--)
huffsize[p++] = (char) l; huffsize[p++] = (char)l;
} }
huffsize[p] = 0; huffsize[p] = 0;
numsymbols = p; numsymbols = p;
@ -203,14 +206,14 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
si = huffsize[0]; si = huffsize[0];
p = 0; p = 0;
while (huffsize[p]) { while (huffsize[p]) {
while (((int) huffsize[p]) == si) { while (((int)huffsize[p]) == si) {
huffcode[p++] = code; huffcode[p++] = code;
code++; code++;
} }
/* code is now 1 more than the last code used for codelength si; but /* code is now 1 more than the last code used for codelength si; but
* it must still fit in si bits, since no code is allowed to be all ones. * it must still fit in si bits, since no code is allowed to be all ones.
*/ */
if (((JLONG) code) >= (((JLONG) 1) << si)) if (((JLONG)code) >= (((JLONG)1) << si))
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
code <<= 1; code <<= 1;
si++; si++;
@ -224,9 +227,9 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
/* valoffset[l] = huffval[] index of 1st symbol of code length l, /* valoffset[l] = huffval[] index of 1st symbol of code length l,
* minus the minimum code of length l * minus the minimum code of length l
*/ */
dtbl->valoffset[l] = (JLONG) p - (JLONG) huffcode[p]; dtbl->valoffset[l] = (JLONG)p - (JLONG)huffcode[p];
p += htbl->bits[l]; p += htbl->bits[l];
dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */ dtbl->maxcode[l] = huffcode[p - 1]; /* maximum code of length l */
} else { } else {
dtbl->maxcode[l] = -1; /* -1 if no codes of this length */ dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
} }
@ -246,11 +249,11 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
p = 0; p = 0;
for (l = 1; l <= HUFF_LOOKAHEAD; l++) { for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
for (i = 1; i <= (int) htbl->bits[l]; i++, p++) { for (i = 1; i <= (int)htbl->bits[l]; i++, p++) {
/* l = current code's length, p = its index in huffcode[] & huffval[]. */ /* l = current code's length, p = its index in huffcode[] & huffval[]. */
/* Generate left-justified code followed by all possible bit sequences */ /* Generate left-justified code followed by all possible bit sequences */
lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l); lookbits = huffcode[p] << (HUFF_LOOKAHEAD - l);
for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) { for (ctr = 1 << (HUFF_LOOKAHEAD - l); ctr > 0; ctr--) {
dtbl->lookup[lookbits] = (l << HUFF_LOOKAHEAD) | htbl->huffval[p]; dtbl->lookup[lookbits] = (l << HUFF_LOOKAHEAD) | htbl->huffval[p];
lookbits++; lookbits++;
} }
@ -291,12 +294,12 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
#ifdef SLOW_SHIFT_32 #ifdef SLOW_SHIFT_32
#define MIN_GET_BITS 15 /* minimum allowable value */ #define MIN_GET_BITS 15 /* minimum allowable value */
#else #else
#define MIN_GET_BITS (BIT_BUF_SIZE-7) #define MIN_GET_BITS (BIT_BUF_SIZE - 7)
#endif #endif
GLOBAL(boolean) GLOBAL(boolean)
jpeg_fill_bit_buffer (bitread_working_state *state, jpeg_fill_bit_buffer(bitread_working_state *state,
register bit_buf_type get_buffer, register int bits_left, register bit_buf_type get_buffer, register int bits_left,
int nbits) int nbits)
/* Load up the bit buffer to a depth of at least nbits */ /* Load up the bit buffer to a depth of at least nbits */
@ -316,7 +319,7 @@ jpeg_fill_bit_buffer (bitread_working_state *state,
/* Attempt to read a byte */ /* Attempt to read a byte */
if (bytes_in_buffer == 0) { if (bytes_in_buffer == 0) {
if (! (*cinfo->src->fill_input_buffer) (cinfo)) if (!(*cinfo->src->fill_input_buffer) (cinfo))
return FALSE; return FALSE;
next_input_byte = cinfo->src->next_input_byte; next_input_byte = cinfo->src->next_input_byte;
bytes_in_buffer = cinfo->src->bytes_in_buffer; bytes_in_buffer = cinfo->src->bytes_in_buffer;
@ -333,7 +336,7 @@ jpeg_fill_bit_buffer (bitread_working_state *state,
*/ */
do { do {
if (bytes_in_buffer == 0) { if (bytes_in_buffer == 0) {
if (! (*cinfo->src->fill_input_buffer) (cinfo)) if (!(*cinfo->src->fill_input_buffer) (cinfo))
return FALSE; return FALSE;
next_input_byte = cinfo->src->next_input_byte; next_input_byte = cinfo->src->next_input_byte;
bytes_in_buffer = cinfo->src->bytes_in_buffer; bytes_in_buffer = cinfo->src->bytes_in_buffer;
@ -365,7 +368,7 @@ jpeg_fill_bit_buffer (bitread_working_state *state,
bits_left += 8; bits_left += 8;
} /* end while */ } /* end while */
} else { } else {
no_more_bytes: no_more_bytes:
/* We get here if we've read the marker that terminates the compressed /* We get here if we've read the marker that terminates the compressed
* data segment. There should be enough bits in the buffer register * data segment. There should be enough bits in the buffer register
* to satisfy the request; if so, no problem. * to satisfy the request; if so, no problem.
@ -376,7 +379,7 @@ jpeg_fill_bit_buffer (bitread_working_state *state,
* We use a nonvolatile flag to ensure that only one warning message * We use a nonvolatile flag to ensure that only one warning message
* appears per data segment. * appears per data segment.
*/ */
if (! cinfo->entropy->insufficient_data) { if (!cinfo->entropy->insufficient_data) {
WARNMS(cinfo, JWRN_HIT_MARKER); WARNMS(cinfo, JWRN_HIT_MARKER);
cinfo->entropy->insufficient_data = TRUE; cinfo->entropy->insufficient_data = TRUE;
} }
@ -400,8 +403,7 @@ jpeg_fill_bit_buffer (bitread_working_state *state,
handle markers. We have to hand off any blocks with markers to the handle markers. We have to hand off any blocks with markers to the
slower routines. */ slower routines. */
#define GET_BYTE \ #define GET_BYTE { \
{ \
register int c0, c1; \ register int c0, c1; \
c0 = GETJOCTET(*buffer++); \ c0 = GETJOCTET(*buffer++); \
c1 = GETJOCTET(*buffer); \ c1 = GETJOCTET(*buffer); \
@ -421,7 +423,7 @@ jpeg_fill_bit_buffer (bitread_working_state *state,
} \ } \
} }
#if SIZEOF_SIZE_T==8 || defined(_WIN64) #if SIZEOF_SIZE_T == 8 || defined(_WIN64)
/* Pre-fetch 48 bytes, because the holding register is 64-bit */ /* Pre-fetch 48 bytes, because the holding register is 64-bit */
#define FILL_BIT_BUFFER_FAST \ #define FILL_BIT_BUFFER_FAST \
@ -446,7 +448,7 @@ jpeg_fill_bit_buffer (bitread_working_state *state,
*/ */
GLOBAL(int) GLOBAL(int)
jpeg_huff_decode (bitread_working_state *state, jpeg_huff_decode(bitread_working_state *state,
register bit_buf_type get_buffer, register int bits_left, register bit_buf_type get_buffer, register int bits_left,
d_derived_tbl *htbl, int min_bits) d_derived_tbl *htbl, int min_bits)
{ {
@ -460,7 +462,7 @@ jpeg_huff_decode (bitread_working_state *state,
code = GET_BITS(l); code = GET_BITS(l);
/* Collect the rest of the Huffman code one bit at a time. */ /* Collect the rest of the Huffman code one bit at a time. */
/* This is per Figure F.16 in the JPEG spec. */ /* This is per Figure F.16. */
while (code > htbl->maxcode[l]) { while (code > htbl->maxcode[l]) {
code <<= 1; code <<= 1;
@ -480,7 +482,7 @@ jpeg_huff_decode (bitread_working_state *state,
return 0; /* fake a zero as the safest result */ return 0; /* fake a zero as the safest result */
} }
return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ]; return htbl->pub->huffval[(int)(code + htbl->valoffset[l])];
} }
@ -493,21 +495,25 @@ jpeg_huff_decode (bitread_working_state *state,
#ifdef AVOID_TABLES #ifdef AVOID_TABLES
#define NEG_1 ((unsigned int)-1) #define NEG_1 ((unsigned int)-1)
#define HUFF_EXTEND(x,s) ((x) + ((((x) - (1<<((s)-1))) >> 31) & (((NEG_1)<<(s)) + 1))) #define HUFF_EXTEND(x, s) \
((x) + ((((x) - (1 << ((s) - 1))) >> 31) & (((NEG_1) << (s)) + 1)))
#else #else
#define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x)) #define HUFF_EXTEND(x, s) \
((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
static const int extend_test[16] = /* entry n is 2**(n-1) */ static const int extend_test[16] = { /* entry n is 2**(n-1) */
{ 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 }; 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000
};
static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */ static const int extend_offset[16] = { /* entry n is (-1 << n) + 1 */
{ 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, 0, ((-1) << 1) + 1, ((-1) << 2) + 1, ((-1) << 3) + 1, ((-1) << 4) + 1,
((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, ((-1) << 5) + 1, ((-1) << 6) + 1, ((-1) << 7) + 1, ((-1) << 8) + 1,
((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, ((-1) << 9) + 1, ((-1) << 10) + 1, ((-1) << 11) + 1, ((-1) << 12) + 1,
((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 }; ((-1) << 13) + 1, ((-1) << 14) + 1, ((-1) << 15) + 1
};
#endif /* AVOID_TABLES */ #endif /* AVOID_TABLES */
@ -518,9 +524,9 @@ static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
*/ */
LOCAL(boolean) LOCAL(boolean)
process_restart (j_decompress_ptr cinfo) process_restart(j_decompress_ptr cinfo)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
int ci; int ci;
/* Throw away any unused bits remaining in bit buffer; */ /* Throw away any unused bits remaining in bit buffer; */
@ -529,7 +535,7 @@ process_restart (j_decompress_ptr cinfo)
entropy->bitstate.bits_left = 0; entropy->bitstate.bits_left = 0;
/* Advance past the RSTn marker */ /* Advance past the RSTn marker */
if (! (*cinfo->marker->read_restart_marker) (cinfo)) if (!(*cinfo->marker->read_restart_marker) (cinfo))
return FALSE; return FALSE;
/* Re-initialize DC predictions to 0 */ /* Re-initialize DC predictions to 0 */
@ -552,16 +558,16 @@ process_restart (j_decompress_ptr cinfo)
LOCAL(boolean) LOCAL(boolean)
decode_mcu_slow (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_slow(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
BITREAD_STATE_VARS; BITREAD_STATE_VARS;
int blkn; int blkn;
savable_state state; savable_state state;
/* Outer loop handles each block in the MCU */ /* Outer loop handles each block in the MCU */
/* Load up working state */ /* Load up working state */
BITREAD_LOAD_STATE(cinfo,entropy->bitstate); BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
ASSIGN_STATE(state, entropy->saved); ASSIGN_STATE(state, entropy->saved);
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
@ -587,7 +593,7 @@ decode_mcu_slow (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
state.last_dc_val[ci] = s; state.last_dc_val[ci] = s;
if (block) { if (block) {
/* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */ /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */
(*block)[0] = (JCOEF) s; (*block)[0] = (JCOEF)s;
} }
} }
@ -610,7 +616,7 @@ decode_mcu_slow (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
* Note: the extra entries in jpeg_natural_order[] will save us * Note: the extra entries in jpeg_natural_order[] will save us
* if k >= DCTSIZE2, which could happen if the data is corrupted. * if k >= DCTSIZE2, which could happen if the data is corrupted.
*/ */
(*block)[jpeg_natural_order[k]] = (JCOEF) s; (*block)[jpeg_natural_order[k]] = (JCOEF)s;
} else { } else {
if (r != 15) if (r != 15)
break; break;
@ -642,16 +648,16 @@ decode_mcu_slow (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/* Completed MCU, so update state */ /* Completed MCU, so update state */
BITREAD_SAVE_STATE(cinfo,entropy->bitstate); BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
ASSIGN_STATE(entropy->saved, state); ASSIGN_STATE(entropy->saved, state);
return TRUE; return TRUE;
} }
LOCAL(boolean) LOCAL(boolean)
decode_mcu_fast (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_fast(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
BITREAD_STATE_VARS; BITREAD_STATE_VARS;
JOCTET *buffer; JOCTET *buffer;
int blkn; int blkn;
@ -659,8 +665,8 @@ decode_mcu_fast (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Outer loop handles each block in the MCU */ /* Outer loop handles each block in the MCU */
/* Load up working state */ /* Load up working state */
BITREAD_LOAD_STATE(cinfo,entropy->bitstate); BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
buffer = (JOCTET *) br_state.next_input_byte; buffer = (JOCTET *)br_state.next_input_byte;
ASSIGN_STATE(state, entropy->saved); ASSIGN_STATE(state, entropy->saved);
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
@ -681,7 +687,7 @@ decode_mcu_fast (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
s += state.last_dc_val[ci]; s += state.last_dc_val[ci];
state.last_dc_val[ci] = s; state.last_dc_val[ci] = s;
if (block) if (block)
(*block)[0] = (JCOEF) s; (*block)[0] = (JCOEF)s;
} }
if (entropy->ac_needed[blkn] && block) { if (entropy->ac_needed[blkn] && block) {
@ -696,7 +702,7 @@ decode_mcu_fast (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
FILL_BIT_BUFFER_FAST FILL_BIT_BUFFER_FAST
r = GET_BITS(s); r = GET_BITS(s);
s = HUFF_EXTEND(r, s); s = HUFF_EXTEND(r, s);
(*block)[jpeg_natural_order[k]] = (JCOEF) s; (*block)[jpeg_natural_order[k]] = (JCOEF)s;
} else { } else {
if (r != 15) break; if (r != 15) break;
k += 15; k += 15;
@ -729,7 +735,7 @@ decode_mcu_fast (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
br_state.bytes_in_buffer -= (buffer - br_state.next_input_byte); br_state.bytes_in_buffer -= (buffer - br_state.next_input_byte);
br_state.next_input_byte = buffer; br_state.next_input_byte = buffer;
BITREAD_SAVE_STATE(cinfo,entropy->bitstate); BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
ASSIGN_STATE(entropy->saved, state); ASSIGN_STATE(entropy->saved, state);
return TRUE; return TRUE;
} }
@ -753,33 +759,32 @@ decode_mcu_fast (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
#define BUFSIZE (DCTSIZE2 * 8) #define BUFSIZE (DCTSIZE2 * 8)
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr)cinfo->entropy;
int usefast = 1; int usefast = 1;
/* Process restart marker if needed; may have to suspend */ /* Process restart marker if needed; may have to suspend */
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
if (entropy->restarts_to_go == 0) if (entropy->restarts_to_go == 0)
if (! process_restart(cinfo)) if (!process_restart(cinfo))
return FALSE; return FALSE;
usefast = 0; usefast = 0;
} }
if (cinfo->src->bytes_in_buffer < BUFSIZE * (size_t)cinfo->blocks_in_MCU if (cinfo->src->bytes_in_buffer < BUFSIZE * (size_t)cinfo->blocks_in_MCU ||
|| cinfo->unread_marker != 0) cinfo->unread_marker != 0)
usefast = 0; usefast = 0;
/* If we've run out of data, just leave the MCU set to zeroes. /* If we've run out of data, just leave the MCU set to zeroes.
* This way, we return uniform gray for the remainder of the segment. * This way, we return uniform gray for the remainder of the segment.
*/ */
if (! entropy->pub.insufficient_data) { if (!entropy->pub.insufficient_data) {
if (usefast) { if (usefast) {
if (!decode_mcu_fast(cinfo, MCU_data)) goto use_slow; if (!decode_mcu_fast(cinfo, MCU_data)) goto use_slow;
} } else {
else { use_slow:
use_slow:
if (!decode_mcu_slow(cinfo, MCU_data)) return FALSE; if (!decode_mcu_slow(cinfo, MCU_data)) return FALSE;
} }
@ -797,7 +802,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_huff_decoder (j_decompress_ptr cinfo) jinit_huff_decoder(j_decompress_ptr cinfo)
{ {
huff_entropy_ptr entropy; huff_entropy_ptr entropy;
int i; int i;
@ -806,12 +811,12 @@ jinit_huff_decoder (j_decompress_ptr cinfo)
are the default tables. Thus, if the tables are not set by the time are the default tables. Thus, if the tables are not set by the time
the Huffman decoder is initialized (usually within the body of the Huffman decoder is initialized (usually within the body of
jpeg_start_decompress()), we set them to default values. */ jpeg_start_decompress()), we set them to default values. */
std_huff_tables((j_common_ptr) cinfo); std_huff_tables((j_common_ptr)cinfo);
entropy = (huff_entropy_ptr) entropy = (huff_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(huff_entropy_decoder)); sizeof(huff_entropy_decoder));
cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; cinfo->entropy = (struct jpeg_entropy_decoder *)entropy;
entropy->pub.start_pass = start_pass_huff_decoder; entropy->pub.start_pass = start_pass_huff_decoder;
entropy->pub.decode_mcu = decode_mcu; entropy->pub.decode_mcu = decode_mcu;

View File

@ -43,13 +43,12 @@ typedef struct {
* if too long. The next 8 bits of each entry contain the * if too long. The next 8 bits of each entry contain the
* symbol. * symbol.
*/ */
int lookup[1<<HUFF_LOOKAHEAD]; int lookup[1 << HUFF_LOOKAHEAD];
} d_derived_tbl; } d_derived_tbl;
/* Expand a Huffman table definition into the derived format */ /* Expand a Huffman table definition into the derived format */
EXTERN(void) jpeg_make_d_derived_tbl EXTERN(void) jpeg_make_d_derived_tbl(j_decompress_ptr cinfo, boolean isDC,
(j_decompress_ptr cinfo, boolean isDC, int tblno, int tblno, d_derived_tbl **pdtbl);
d_derived_tbl ** pdtbl);
/* /*
@ -74,7 +73,7 @@ EXTERN(void) jpeg_make_d_derived_tbl
#error Cannot determine word size #error Cannot determine word size
#endif #endif
#if SIZEOF_SIZE_T==8 || defined(_WIN64) #if SIZEOF_SIZE_T == 8 || defined(_WIN64)
typedef size_t bit_buf_type; /* type of bit-extraction buffer */ typedef size_t bit_buf_type; /* type of bit-extraction buffer */
#define BIT_BUF_SIZE 64 /* size of buffer in bits */ #define BIT_BUF_SIZE 64 /* size of buffer in bits */
@ -118,14 +117,14 @@ typedef struct { /* Bitreading working state within an MCU */
register int bits_left; \ register int bits_left; \
bitread_working_state br_state bitread_working_state br_state
#define BITREAD_LOAD_STATE(cinfop,permstate) \ #define BITREAD_LOAD_STATE(cinfop, permstate) \
br_state.cinfo = cinfop; \ br_state.cinfo = cinfop; \
br_state.next_input_byte = cinfop->src->next_input_byte; \ br_state.next_input_byte = cinfop->src->next_input_byte; \
br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \ br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
get_buffer = permstate.get_buffer; \ get_buffer = permstate.get_buffer; \
bits_left = permstate.bits_left; bits_left = permstate.bits_left;
#define BITREAD_SAVE_STATE(cinfop,permstate) \ #define BITREAD_SAVE_STATE(cinfop, permstate) \
cinfop->src->next_input_byte = br_state.next_input_byte; \ cinfop->src->next_input_byte = br_state.next_input_byte; \
cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \ cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
permstate.get_buffer = get_buffer; \ permstate.get_buffer = get_buffer; \
@ -137,7 +136,7 @@ typedef struct { /* Bitreading working state within an MCU */
* before using GET_BITS, PEEK_BITS, or DROP_BITS. * before using GET_BITS, PEEK_BITS, or DROP_BITS.
* The variables get_buffer and bits_left are assumed to be locals, * The variables get_buffer and bits_left are assumed to be locals,
* but the state struct might not be (jpeg_huff_decode needs this). * but the state struct might not be (jpeg_huff_decode needs this).
* CHECK_BIT_BUFFER(state,n,action); * CHECK_BIT_BUFFER(state, n, action);
* Ensure there are N bits in get_buffer; if suspend, take action. * Ensure there are N bits in get_buffer; if suspend, take action.
* val = GET_BITS(n); * val = GET_BITS(n);
* Fetch next N bits. * Fetch next N bits.
@ -149,24 +148,26 @@ typedef struct { /* Bitreading working state within an MCU */
* is evaluated multiple times. * is evaluated multiple times.
*/ */
#define CHECK_BIT_BUFFER(state,nbits,action) \ #define CHECK_BIT_BUFFER(state, nbits, action) { \
{ if (bits_left < (nbits)) { \ if (bits_left < (nbits)) { \
if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \ if (!jpeg_fill_bit_buffer(&(state), get_buffer, bits_left, nbits)) \
{ action; } \ { action; } \
get_buffer = (state).get_buffer; bits_left = (state).bits_left; } } get_buffer = (state).get_buffer; bits_left = (state).bits_left; \
} \
}
#define GET_BITS(nbits) \ #define GET_BITS(nbits) \
(((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1)) (((int)(get_buffer >> (bits_left -= (nbits)))) & ((1 << (nbits)) - 1))
#define PEEK_BITS(nbits) \ #define PEEK_BITS(nbits) \
(((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1)) (((int)(get_buffer >> (bits_left - (nbits)))) & ((1 << (nbits)) - 1))
#define DROP_BITS(nbits) \ #define DROP_BITS(nbits) \
(bits_left -= (nbits)) (bits_left -= (nbits))
/* Load up the bit buffer to a depth of at least nbits */ /* Load up the bit buffer to a depth of at least nbits */
EXTERN(boolean) jpeg_fill_bit_buffer EXTERN(boolean) jpeg_fill_bit_buffer(bitread_working_state *state,
(bitread_working_state *state, register bit_buf_type get_buffer, register bit_buf_type get_buffer,
register int bits_left, int nbits); register int bits_left, int nbits);
@ -187,10 +188,11 @@ EXTERN(boolean) jpeg_fill_bit_buffer
* 3. jpeg_huff_decode returns -1 if forced to suspend. * 3. jpeg_huff_decode returns -1 if forced to suspend.
*/ */
#define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \ #define HUFF_DECODE(result, state, htbl, failaction, slowlabel) { \
{ register int nb, look; \ register int nb, look; \
if (bits_left < HUFF_LOOKAHEAD) { \ if (bits_left < HUFF_LOOKAHEAD) { \
if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \ if (!jpeg_fill_bit_buffer(&state, get_buffer, bits_left, 0)) \
{ failaction; } \
get_buffer = state.get_buffer; bits_left = state.bits_left; \ get_buffer = state.get_buffer; bits_left = state.bits_left; \
if (bits_left < HUFF_LOOKAHEAD) { \ if (bits_left < HUFF_LOOKAHEAD) { \
nb = 1; goto slowlabel; \ nb = 1; goto slowlabel; \
@ -202,13 +204,14 @@ EXTERN(boolean) jpeg_fill_bit_buffer
result = htbl->lookup[look] & ((1 << HUFF_LOOKAHEAD) - 1); \ result = htbl->lookup[look] & ((1 << HUFF_LOOKAHEAD) - 1); \
} else { \ } else { \
slowlabel: \ slowlabel: \
if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \ if ((result = \
jpeg_huff_decode(&state, get_buffer, bits_left, htbl, nb)) < 0) \
{ failaction; } \ { failaction; } \
get_buffer = state.get_buffer; bits_left = state.bits_left; \ get_buffer = state.get_buffer; bits_left = state.bits_left; \
} \ } \
} }
#define HUFF_DECODE_FAST(s,nb,htbl) \ #define HUFF_DECODE_FAST(s, nb, htbl) \
FILL_BIT_BUFFER_FAST; \ FILL_BIT_BUFFER_FAST; \
s = PEEK_BITS(HUFF_LOOKAHEAD); \ s = PEEK_BITS(HUFF_LOOKAHEAD); \
s = htbl->lookup[s]; \ s = htbl->lookup[s]; \
@ -225,10 +228,11 @@ slowlabel: \
s |= GET_BITS(1); \ s |= GET_BITS(1); \
nb++; \ nb++; \
} \ } \
s = htbl->pub->huffval[ (int) (s + htbl->valoffset[nb]) & 0xFF ]; \ s = htbl->pub->huffval[(int)(s + htbl->valoffset[nb]) & 0xFF]; \
} }
/* Out-of-line case for Huffman code fetching */ /* Out-of-line case for Huffman code fetching */
EXTERN(int) jpeg_huff_decode EXTERN(int) jpeg_huff_decode(bitread_working_state *state,
(bitread_working_state *state, register bit_buf_type get_buffer, register bit_buf_type get_buffer,
register int bits_left, d_derived_tbl *htbl, int min_bits); register int bits_left, d_derived_tbl *htbl,
int min_bits);

View File

@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2010, 2016, D. R. Commander. * Copyright (C) 2010, 2016, 2018, D. R. Commander.
* Copyright (C) 2015, Google, Inc. * Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
@ -33,7 +33,7 @@ typedef my_input_controller *my_inputctl_ptr;
/* Forward declarations */ /* Forward declarations */
METHODDEF(int) consume_markers (j_decompress_ptr cinfo); METHODDEF(int) consume_markers(j_decompress_ptr cinfo);
/* /*
@ -41,16 +41,16 @@ METHODDEF(int) consume_markers (j_decompress_ptr cinfo);
*/ */
LOCAL(void) LOCAL(void)
initial_setup (j_decompress_ptr cinfo) initial_setup(j_decompress_ptr cinfo)
/* Called once, when first SOS marker is reached */ /* Called once, when first SOS marker is reached */
{ {
int ci; int ci;
jpeg_component_info *compptr; jpeg_component_info *compptr;
/* Make sure image isn't bigger than I can handle */ /* Make sure image isn't bigger than I can handle */
if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION || if ((long)cinfo->image_height > (long)JPEG_MAX_DIMENSION ||
(long) cinfo->image_width > (long) JPEG_MAX_DIMENSION) (long)cinfo->image_width > (long)JPEG_MAX_DIMENSION)
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int)JPEG_MAX_DIMENSION);
/* For now, precision must match compiled-in value... */ /* For now, precision must match compiled-in value... */
if (cinfo->data_precision != BITS_IN_JSAMPLE) if (cinfo->data_precision != BITS_IN_JSAMPLE)
@ -66,8 +66,10 @@ initial_setup (j_decompress_ptr cinfo)
cinfo->max_v_samp_factor = 1; cinfo->max_v_samp_factor = 1;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || if (compptr->h_samp_factor <= 0 ||
compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) compptr->h_samp_factor > MAX_SAMP_FACTOR ||
compptr->v_samp_factor <= 0 ||
compptr->v_samp_factor > MAX_SAMP_FACTOR)
ERREXIT(cinfo, JERR_BAD_SAMPLING); ERREXIT(cinfo, JERR_BAD_SAMPLING);
cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
compptr->h_samp_factor); compptr->h_samp_factor);
@ -75,10 +77,10 @@ initial_setup (j_decompress_ptr cinfo)
compptr->v_samp_factor); compptr->v_samp_factor);
} }
#if JPEG_LIB_VERSION >=80 #if JPEG_LIB_VERSION >= 80
cinfo->block_size = DCTSIZE; cinfo->block_size = DCTSIZE;
cinfo->natural_order = jpeg_natural_order; cinfo->natural_order = jpeg_natural_order;
cinfo->lim_Se = DCTSIZE2-1; cinfo->lim_Se = DCTSIZE2 - 1;
#endif #endif
/* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE. /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE.
@ -101,11 +103,11 @@ initial_setup (j_decompress_ptr cinfo)
#endif #endif
/* Size in DCT blocks */ /* Size in DCT blocks */
compptr->width_in_blocks = (JDIMENSION) compptr->width_in_blocks = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, jdiv_round_up((long)cinfo->image_width * (long)compptr->h_samp_factor,
(long) (cinfo->max_h_samp_factor * DCTSIZE)); (long)(cinfo->max_h_samp_factor * DCTSIZE));
compptr->height_in_blocks = (JDIMENSION) compptr->height_in_blocks = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, jdiv_round_up((long)cinfo->image_height * (long)compptr->v_samp_factor,
(long) (cinfo->max_v_samp_factor * DCTSIZE)); (long)(cinfo->max_v_samp_factor * DCTSIZE));
/* Set the first and last MCU columns to decompress from multi-scan images. /* Set the first and last MCU columns to decompress from multi-scan images.
* By default, decompress all of the MCU columns. * By default, decompress all of the MCU columns.
*/ */
@ -117,11 +119,11 @@ initial_setup (j_decompress_ptr cinfo)
*/ */
/* Size in samples */ /* Size in samples */
compptr->downsampled_width = (JDIMENSION) compptr->downsampled_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, jdiv_round_up((long)cinfo->image_width * (long)compptr->h_samp_factor,
(long) cinfo->max_h_samp_factor); (long)cinfo->max_h_samp_factor);
compptr->downsampled_height = (JDIMENSION) compptr->downsampled_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, jdiv_round_up((long)cinfo->image_height * (long)compptr->v_samp_factor,
(long) cinfo->max_v_samp_factor); (long)cinfo->max_v_samp_factor);
/* Mark component needed, until color conversion says otherwise */ /* Mark component needed, until color conversion says otherwise */
compptr->component_needed = TRUE; compptr->component_needed = TRUE;
/* Mark no quantization table yet saved for component */ /* Mark no quantization table yet saved for component */
@ -130,8 +132,8 @@ initial_setup (j_decompress_ptr cinfo)
/* Compute number of fully interleaved MCU rows. */ /* Compute number of fully interleaved MCU rows. */
cinfo->total_iMCU_rows = (JDIMENSION) cinfo->total_iMCU_rows = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height, jdiv_round_up((long)cinfo->image_height,
(long) (cinfo->max_v_samp_factor*DCTSIZE)); (long)(cinfo->max_v_samp_factor * DCTSIZE));
/* Decide whether file contains multiple scans */ /* Decide whether file contains multiple scans */
if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode) if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
@ -142,7 +144,7 @@ initial_setup (j_decompress_ptr cinfo)
LOCAL(void) LOCAL(void)
per_scan_setup (j_decompress_ptr cinfo) per_scan_setup(j_decompress_ptr cinfo)
/* Do computations that are needed before processing a JPEG scan */ /* Do computations that are needed before processing a JPEG scan */
/* cinfo->comps_in_scan and cinfo->cur_comp_info[] were set from SOS marker */ /* cinfo->comps_in_scan and cinfo->cur_comp_info[] were set from SOS marker */
{ {
@ -167,7 +169,7 @@ per_scan_setup (j_decompress_ptr cinfo)
/* For noninterleaved scans, it is convenient to define last_row_height /* For noninterleaved scans, it is convenient to define last_row_height
* as the number of block rows present in the last iMCU row. * as the number of block rows present in the last iMCU row.
*/ */
tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); tmp = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
if (tmp == 0) tmp = compptr->v_samp_factor; if (tmp == 0) tmp = compptr->v_samp_factor;
compptr->last_row_height = tmp; compptr->last_row_height = tmp;
@ -184,11 +186,11 @@ per_scan_setup (j_decompress_ptr cinfo)
/* Overall image size in MCUs */ /* Overall image size in MCUs */
cinfo->MCUs_per_row = (JDIMENSION) cinfo->MCUs_per_row = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width, jdiv_round_up((long)cinfo->image_width,
(long) (cinfo->max_h_samp_factor*DCTSIZE)); (long)(cinfo->max_h_samp_factor * DCTSIZE));
cinfo->MCU_rows_in_scan = (JDIMENSION) cinfo->MCU_rows_in_scan = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height, jdiv_round_up((long)cinfo->image_height,
(long) (cinfo->max_v_samp_factor*DCTSIZE)); (long)(cinfo->max_v_samp_factor * DCTSIZE));
cinfo->blocks_in_MCU = 0; cinfo->blocks_in_MCU = 0;
@ -198,12 +200,13 @@ per_scan_setup (j_decompress_ptr cinfo)
compptr->MCU_width = compptr->h_samp_factor; compptr->MCU_width = compptr->h_samp_factor;
compptr->MCU_height = compptr->v_samp_factor; compptr->MCU_height = compptr->v_samp_factor;
compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
compptr->MCU_sample_width = compptr->MCU_width * compptr->_DCT_scaled_size; compptr->MCU_sample_width = compptr->MCU_width *
compptr->_DCT_scaled_size;
/* Figure number of non-dummy blocks in last MCU column & row */ /* Figure number of non-dummy blocks in last MCU column & row */
tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); tmp = (int)(compptr->width_in_blocks % compptr->MCU_width);
if (tmp == 0) tmp = compptr->MCU_width; if (tmp == 0) tmp = compptr->MCU_width;
compptr->last_col_width = tmp; compptr->last_col_width = tmp;
tmp = (int) (compptr->height_in_blocks % compptr->MCU_height); tmp = (int)(compptr->height_in_blocks % compptr->MCU_height);
if (tmp == 0) tmp = compptr->MCU_height; if (tmp == 0) tmp = compptr->MCU_height;
compptr->last_row_height = tmp; compptr->last_row_height = tmp;
/* Prepare array describing MCU composition */ /* Prepare array describing MCU composition */
@ -231,17 +234,17 @@ per_scan_setup (j_decompress_ptr cinfo)
* means that we have to save away the table actually used for each component. * means that we have to save away the table actually used for each component.
* We do this by copying the table at the start of the first scan containing * We do this by copying the table at the start of the first scan containing
* the component. * the component.
* The JPEG spec prohibits the encoder from changing the contents of a Q-table * Rec. ITU-T T.81 | ISO/IEC 10918-1 prohibits the encoder from changing the
* slot between scans of a component using that slot. If the encoder does so * contents of a Q-table slot between scans of a component using that slot. If
* anyway, this decoder will simply use the Q-table values that were current * the encoder does so anyway, this decoder will simply use the Q-table values
* at the start of the first scan for the component. * that were current at the start of the first scan for the component.
* *
* The decompressor output side looks only at the saved quant tables, * The decompressor output side looks only at the saved quant tables,
* not at the current Q-table slots. * not at the current Q-table slots.
*/ */
LOCAL(void) LOCAL(void)
latch_quant_tables (j_decompress_ptr cinfo) latch_quant_tables(j_decompress_ptr cinfo)
{ {
int ci, qtblno; int ci, qtblno;
jpeg_component_info *compptr; jpeg_component_info *compptr;
@ -259,7 +262,7 @@ latch_quant_tables (j_decompress_ptr cinfo)
ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
/* OK, save away the quantization table */ /* OK, save away the quantization table */
qtbl = (JQUANT_TBL *) qtbl = (JQUANT_TBL *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(JQUANT_TBL)); sizeof(JQUANT_TBL));
MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], sizeof(JQUANT_TBL)); MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], sizeof(JQUANT_TBL));
compptr->quant_table = qtbl; compptr->quant_table = qtbl;
@ -275,7 +278,7 @@ latch_quant_tables (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
start_input_pass (j_decompress_ptr cinfo) start_input_pass(j_decompress_ptr cinfo)
{ {
per_scan_setup(cinfo); per_scan_setup(cinfo);
latch_quant_tables(cinfo); latch_quant_tables(cinfo);
@ -292,7 +295,7 @@ start_input_pass (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
finish_input_pass (j_decompress_ptr cinfo) finish_input_pass(j_decompress_ptr cinfo)
{ {
cinfo->inputctl->consume_input = consume_markers; cinfo->inputctl->consume_input = consume_markers;
} }
@ -309,9 +312,9 @@ finish_input_pass (j_decompress_ptr cinfo)
*/ */
METHODDEF(int) METHODDEF(int)
consume_markers (j_decompress_ptr cinfo) consume_markers(j_decompress_ptr cinfo)
{ {
my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl; my_inputctl_ptr inputctl = (my_inputctl_ptr)cinfo->inputctl;
int val; int val;
if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */ if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
@ -329,7 +332,7 @@ consume_markers (j_decompress_ptr cinfo)
* responsible for enforcing this sequencing. * responsible for enforcing this sequencing.
*/ */
} else { /* 2nd or later SOS marker */ } else { /* 2nd or later SOS marker */
if (! inputctl->pub.has_multiple_scans) if (!inputctl->pub.has_multiple_scans)
ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */ ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
start_input_pass(cinfo); start_input_pass(cinfo);
} }
@ -360,16 +363,16 @@ consume_markers (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
reset_input_controller (j_decompress_ptr cinfo) reset_input_controller(j_decompress_ptr cinfo)
{ {
my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl; my_inputctl_ptr inputctl = (my_inputctl_ptr)cinfo->inputctl;
inputctl->pub.consume_input = consume_markers; inputctl->pub.consume_input = consume_markers;
inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */ inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
inputctl->pub.eoi_reached = FALSE; inputctl->pub.eoi_reached = FALSE;
inputctl->inheaders = TRUE; inputctl->inheaders = TRUE;
/* Reset other modules */ /* Reset other modules */
(*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); (*cinfo->err->reset_error_mgr) ((j_common_ptr)cinfo);
(*cinfo->marker->reset_marker_reader) (cinfo); (*cinfo->marker->reset_marker_reader) (cinfo);
/* Reset progression state -- would be cleaner if entropy decoder did this */ /* Reset progression state -- would be cleaner if entropy decoder did this */
cinfo->coef_bits = NULL; cinfo->coef_bits = NULL;
@ -382,15 +385,15 @@ reset_input_controller (j_decompress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_input_controller (j_decompress_ptr cinfo) jinit_input_controller(j_decompress_ptr cinfo)
{ {
my_inputctl_ptr inputctl; my_inputctl_ptr inputctl;
/* Create subobject in permanent pool */ /* Create subobject in permanent pool */
inputctl = (my_inputctl_ptr) inputctl = (my_inputctl_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
sizeof(my_input_controller)); sizeof(my_input_controller));
cinfo->inputctl = (struct jpeg_input_controller *) inputctl; cinfo->inputctl = (struct jpeg_input_controller *)inputctl;
/* Initialize method pointers */ /* Initialize method pointers */
inputctl->pub.consume_input = consume_markers; inputctl->pub.consume_input = consume_markers;
inputctl->pub.reset_input_controller = reset_input_controller; inputctl->pub.reset_input_controller = reset_input_controller;

View File

@ -112,26 +112,29 @@
/* Forward declarations */ /* Forward declarations */
METHODDEF(void) process_data_simple_main METHODDEF(void) process_data_simple_main(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, JSAMPARRAY output_buf, JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail); JDIMENSION *out_row_ctr,
METHODDEF(void) process_data_context_main JDIMENSION out_rows_avail);
(j_decompress_ptr cinfo, JSAMPARRAY output_buf, METHODDEF(void) process_data_context_main(j_decompress_ptr cinfo,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail); JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail);
#ifdef QUANT_2PASS_SUPPORTED #ifdef QUANT_2PASS_SUPPORTED
METHODDEF(void) process_data_crank_post METHODDEF(void) process_data_crank_post(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, JSAMPARRAY output_buf, JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail); JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail);
#endif #endif
LOCAL(void) LOCAL(void)
alloc_funny_pointers (j_decompress_ptr cinfo) alloc_funny_pointers(j_decompress_ptr cinfo)
/* Allocate space for the funny pointer lists. /* Allocate space for the funny pointer lists.
* This is done only once, not once per pass. * This is done only once, not once per pass.
*/ */
{ {
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
int ci, rgroup; int ci, rgroup;
int M = cinfo->_min_DCT_scaled_size; int M = cinfo->_min_DCT_scaled_size;
jpeg_component_info *compptr; jpeg_component_info *compptr;
@ -141,7 +144,7 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
* We alloc both arrays with one call to save a few cycles. * We alloc both arrays with one call to save a few cycles.
*/ */
main_ptr->xbuffer[0] = (JSAMPIMAGE) main_ptr->xbuffer[0] = (JSAMPIMAGE)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
cinfo->num_components * 2 * sizeof(JSAMPARRAY)); cinfo->num_components * 2 * sizeof(JSAMPARRAY));
main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components; main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components;
@ -153,7 +156,7 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
* We alloc both pointer lists with one call to save a few cycles. * We alloc both pointer lists with one call to save a few cycles.
*/ */
xbuf = (JSAMPARRAY) xbuf = (JSAMPARRAY)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
2 * (rgroup * (M + 4)) * sizeof(JSAMPROW)); 2 * (rgroup * (M + 4)) * sizeof(JSAMPROW));
xbuf += rgroup; /* want one row group at negative offsets */ xbuf += rgroup; /* want one row group at negative offsets */
main_ptr->xbuffer[0][ci] = xbuf; main_ptr->xbuffer[0][ci] = xbuf;
@ -164,7 +167,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_ptr->buffer), * The actual workspace is already allocated (in main_ptr->buffer),
* and the space for the pointer lists is allocated too. * and the space for the pointer lists is allocated too.
@ -172,7 +175,7 @@ make_funny_pointers (j_decompress_ptr cinfo)
* This will be repeated at the beginning of each pass. * This will be repeated at the beginning of each pass.
*/ */
{ {
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
int ci, i, rgroup; int ci, i, rgroup;
int M = cinfo->_min_DCT_scaled_size; int M = cinfo->_min_DCT_scaled_size;
jpeg_component_info *compptr; jpeg_component_info *compptr;
@ -191,8 +194,8 @@ make_funny_pointers (j_decompress_ptr cinfo)
} }
/* In the second list, put the last four row groups in swapped order */ /* In the second list, put the last four row groups in swapped order */
for (i = 0; i < rgroup * 2; i++) { for (i = 0; i < rgroup * 2; i++) {
xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i]; xbuf1[rgroup * (M - 2) + i] = buf[rgroup * M + i];
xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i]; xbuf1[rgroup * M + i] = buf[rgroup * (M - 2) + i];
} }
/* The wraparound pointers at top and bottom will be filled later /* The wraparound pointers at top and bottom will be filled later
* (see set_wraparound_pointers, below). Initially we want the "above" * (see set_wraparound_pointers, below). Initially we want the "above"
@ -207,13 +210,13 @@ make_funny_pointers (j_decompress_ptr cinfo)
LOCAL(void) LOCAL(void)
set_bottom_pointers (j_decompress_ptr cinfo) set_bottom_pointers(j_decompress_ptr cinfo)
/* Change the pointer lists to duplicate the last sample row at the bottom /* Change the pointer lists to duplicate the last sample row at the bottom
* of the image. whichptr indicates which xbuffer holds the final iMCU row. * of the image. whichptr indicates which xbuffer holds the final iMCU row.
* Also sets rowgroups_avail to indicate number of nondummy row groups in row. * Also sets rowgroups_avail to indicate number of nondummy row groups in row.
*/ */
{ {
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
int ci, i, rgroup, iMCUheight, rows_left; int ci, i, rgroup, iMCUheight, rows_left;
jpeg_component_info *compptr; jpeg_component_info *compptr;
JSAMPARRAY xbuf; JSAMPARRAY xbuf;
@ -224,20 +227,20 @@ set_bottom_pointers (j_decompress_ptr cinfo)
iMCUheight = compptr->v_samp_factor * compptr->_DCT_scaled_size; iMCUheight = compptr->v_samp_factor * compptr->_DCT_scaled_size;
rgroup = iMCUheight / cinfo->_min_DCT_scaled_size; rgroup = iMCUheight / cinfo->_min_DCT_scaled_size;
/* Count nondummy sample rows remaining for this component */ /* Count nondummy sample rows remaining for this component */
rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight); rows_left = (int)(compptr->downsampled_height % (JDIMENSION)iMCUheight);
if (rows_left == 0) rows_left = iMCUheight; if (rows_left == 0) rows_left = iMCUheight;
/* Count nondummy row groups. Should get same answer for each component, /* Count nondummy row groups. Should get same answer for each component,
* so we need only do it once. * so we need only do it once.
*/ */
if (ci == 0) { if (ci == 0) {
main_ptr->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1); main_ptr->rowgroups_avail = (JDIMENSION)((rows_left - 1) / rgroup + 1);
} }
/* Duplicate the last real sample row rgroup*2 times; this pads out the /* Duplicate the last real sample row rgroup*2 times; this pads out the
* last partial rowgroup and ensures at least one full rowgroup of context. * last partial rowgroup and ensures at least one full rowgroup of context.
*/ */
xbuf = main_ptr->xbuffer[main_ptr->whichptr][ci]; xbuf = main_ptr->xbuffer[main_ptr->whichptr][ci];
for (i = 0; i < rgroup * 2; i++) { for (i = 0; i < rgroup * 2; i++) {
xbuf[rows_left + i] = xbuf[rows_left-1]; xbuf[rows_left + i] = xbuf[rows_left - 1];
} }
} }
} }
@ -248,9 +251,9 @@ set_bottom_pointers (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode) start_pass_main(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
{ {
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
switch (pass_mode) { switch (pass_mode) {
case JBUF_PASS_THRU: case JBUF_PASS_THRU:
@ -286,22 +289,21 @@ start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
*/ */
METHODDEF(void) METHODDEF(void)
process_data_simple_main (j_decompress_ptr cinfo, process_data_simple_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
JDIMENSION out_rows_avail)
{ {
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
JDIMENSION rowgroups_avail; 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 (! main_ptr->buffer_full) { if (!main_ptr->buffer_full) {
if (! (*cinfo->coef->decompress_data) (cinfo, main_ptr->buffer)) if (!(*cinfo->coef->decompress_data) (cinfo, main_ptr->buffer))
return; /* suspension forced, can do nothing more */ return; /* suspension forced, can do nothing more */
main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */ main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
} }
/* There are always min_DCT_scaled_size row groups in an iMCU row. */ /* There are always min_DCT_scaled_size row groups in an iMCU row. */
rowgroups_avail = (JDIMENSION) cinfo->_min_DCT_scaled_size; rowgroups_avail = (JDIMENSION)cinfo->_min_DCT_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.
@ -326,15 +328,14 @@ process_data_simple_main (j_decompress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
process_data_context_main (j_decompress_ptr cinfo, process_data_context_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
JDIMENSION out_rows_avail)
{ {
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
/* 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 (! main_ptr->buffer_full) { if (!main_ptr->buffer_full) {
if (! (*cinfo->coef->decompress_data) (cinfo, if (!(*cinfo->coef->decompress_data) (cinfo,
main_ptr->xbuffer[main_ptr->whichptr])) main_ptr->xbuffer[main_ptr->whichptr]))
return; /* suspension forced, can do nothing more */ return; /* suspension forced, can do nothing more */
main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */ main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
@ -349,9 +350,11 @@ process_data_context_main (j_decompress_ptr cinfo,
switch (main_ptr->context_state) { switch (main_ptr->context_state) {
case CTX_POSTPONED_ROW: case CTX_POSTPONED_ROW:
/* Call postprocessor using previously set pointers for postponed row */ /* Call postprocessor using previously set pointers for postponed row */
(*cinfo->post->post_process_data) (cinfo, main_ptr->xbuffer[main_ptr->whichptr], (*cinfo->post->post_process_data) (cinfo,
&main_ptr->rowgroup_ctr, main_ptr->rowgroups_avail, main_ptr->xbuffer[main_ptr->whichptr],
output_buf, out_row_ctr, out_rows_avail); &main_ptr->rowgroup_ctr,
main_ptr->rowgroups_avail, output_buf,
out_row_ctr, out_rows_avail);
if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail) if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
return; /* Need to suspend */ return; /* Need to suspend */
main_ptr->context_state = CTX_PREPARE_FOR_IMCU; main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
@ -361,7 +364,7 @@ process_data_context_main (j_decompress_ptr cinfo,
case CTX_PREPARE_FOR_IMCU: case CTX_PREPARE_FOR_IMCU:
/* Prepare to process first M-1 row groups of this iMCU row */ /* Prepare to process first M-1 row groups of this iMCU row */
main_ptr->rowgroup_ctr = 0; main_ptr->rowgroup_ctr = 0;
main_ptr->rowgroups_avail = (JDIMENSION) (cinfo->_min_DCT_scaled_size - 1); main_ptr->rowgroups_avail = (JDIMENSION)(cinfo->_min_DCT_scaled_size - 1);
/* Check for bottom of image: if so, tweak pointers to "duplicate" /* Check for bottom of image: if so, tweak pointers to "duplicate"
* the last sample row, and adjust rowgroups_avail to ignore padding rows. * the last sample row, and adjust rowgroups_avail to ignore padding rows.
*/ */
@ -371,9 +374,11 @@ process_data_context_main (j_decompress_ptr cinfo,
/*FALLTHROUGH*/ /*FALLTHROUGH*/
case CTX_PROCESS_IMCU: case CTX_PROCESS_IMCU:
/* Call postprocessor using previously set pointers */ /* Call postprocessor using previously set pointers */
(*cinfo->post->post_process_data) (cinfo, main_ptr->xbuffer[main_ptr->whichptr], (*cinfo->post->post_process_data) (cinfo,
&main_ptr->rowgroup_ctr, main_ptr->rowgroups_avail, main_ptr->xbuffer[main_ptr->whichptr],
output_buf, out_row_ctr, out_rows_avail); &main_ptr->rowgroup_ctr,
main_ptr->rowgroups_avail, output_buf,
out_row_ctr, out_rows_avail);
if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail) if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
return; /* Need to suspend */ return; /* Need to suspend */
/* After the first iMCU, change wraparound pointers to normal state */ /* After the first iMCU, change wraparound pointers to normal state */
@ -384,8 +389,8 @@ process_data_context_main (j_decompress_ptr cinfo,
main_ptr->buffer_full = FALSE; main_ptr->buffer_full = FALSE;
/* Still need to process last row group of this iMCU row, */ /* Still need to process last row group of this iMCU row, */
/* which is saved at index M+1 of the other xbuffer */ /* which is saved at index M+1 of the other xbuffer */
main_ptr->rowgroup_ctr = (JDIMENSION) (cinfo->_min_DCT_scaled_size + 1); main_ptr->rowgroup_ctr = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 1);
main_ptr->rowgroups_avail = (JDIMENSION) (cinfo->_min_DCT_scaled_size + 2); main_ptr->rowgroups_avail = (JDIMENSION)(cinfo->_min_DCT_scaled_size + 2);
main_ptr->context_state = CTX_POSTPONED_ROW; main_ptr->context_state = CTX_POSTPONED_ROW;
} }
} }
@ -400,12 +405,11 @@ process_data_context_main (j_decompress_ptr cinfo,
#ifdef QUANT_2PASS_SUPPORTED #ifdef QUANT_2PASS_SUPPORTED
METHODDEF(void) METHODDEF(void)
process_data_crank_post (j_decompress_ptr cinfo, process_data_crank_post(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
JDIMENSION out_rows_avail)
{ {
(*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL, (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE)NULL,
(JDIMENSION *) NULL, (JDIMENSION) 0, (JDIMENSION *)NULL, (JDIMENSION)0,
output_buf, out_row_ctr, out_rows_avail); output_buf, out_row_ctr, out_rows_avail);
} }
@ -417,16 +421,16 @@ process_data_crank_post (j_decompress_ptr cinfo,
*/ */
GLOBAL(void) GLOBAL(void)
jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer) jinit_d_main_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
{ {
my_main_ptr main_ptr; my_main_ptr main_ptr;
int ci, rgroup, ngroups; int ci, rgroup, ngroups;
jpeg_component_info *compptr; jpeg_component_info *compptr;
main_ptr = (my_main_ptr) main_ptr = (my_main_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_main_controller)); sizeof(my_main_controller));
cinfo->main = (struct jpeg_d_main_controller *) main_ptr; cinfo->main = (struct jpeg_d_main_controller *)main_ptr;
main_ptr->pub.start_pass = start_pass_main; main_ptr->pub.start_pass = start_pass_main;
if (need_full_buffer) /* shouldn't happen */ if (need_full_buffer) /* shouldn't happen */
@ -449,8 +453,8 @@ jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
cinfo->_min_DCT_scaled_size; /* height of a row group of component */ cinfo->_min_DCT_scaled_size; /* height of a row group of component */
main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray) main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr)cinfo, JPOOL_IMAGE,
compptr->width_in_blocks * compptr->_DCT_scaled_size, compptr->width_in_blocks * compptr->_DCT_scaled_size,
(JDIMENSION) (rgroup * ngroups)); (JDIMENSION)(rgroup * ngroups));
} }
} }

View File

@ -44,12 +44,12 @@ typedef my_main_controller *my_main_ptr;
LOCAL(void) LOCAL(void)
set_wraparound_pointers (j_decompress_ptr cinfo) set_wraparound_pointers(j_decompress_ptr cinfo)
/* Set up the "wraparound" pointers at top and bottom of the pointer lists. /* Set up the "wraparound" pointers at top and bottom of the pointer lists.
* This changes the pointer list state from top-of-image to the normal state. * This changes the pointer list state from top-of-image to the normal state.
*/ */
{ {
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
int ci, i, rgroup; int ci, i, rgroup;
int M = cinfo->_min_DCT_scaled_size; int M = cinfo->_min_DCT_scaled_size;
jpeg_component_info *compptr; jpeg_component_info *compptr;
@ -62,10 +62,10 @@ set_wraparound_pointers (j_decompress_ptr cinfo)
xbuf0 = main_ptr->xbuffer[0][ci]; xbuf0 = main_ptr->xbuffer[0][ci];
xbuf1 = main_ptr->xbuffer[1][ci]; xbuf1 = main_ptr->xbuffer[1][ci];
for (i = 0; i < rgroup; i++) { for (i = 0; i < rgroup; i++) {
xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i]; xbuf0[i - rgroup] = xbuf0[rgroup * (M + 1) + i];
xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i]; xbuf1[i - rgroup] = xbuf1[rgroup * (M + 1) + i];
xbuf0[rgroup*(M+2) + i] = xbuf0[i]; xbuf0[rgroup * (M + 2) + i] = xbuf0[i];
xbuf1[rgroup*(M+2) + i] = xbuf1[i]; xbuf1[rgroup * (M + 2) + i] = xbuf1[i];
} }
} }
} }

View File

@ -138,9 +138,9 @@ typedef my_marker_reader *my_marker_ptr;
* Note we do *not* do INPUT_SYNC before calling fill_input_buffer, * Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
* but we must reload the local copies after a successful fill. * but we must reload the local copies after a successful fill.
*/ */
#define MAKE_BYTE_AVAIL(cinfo,action) \ #define MAKE_BYTE_AVAIL(cinfo, action) \
if (bytes_in_buffer == 0) { \ if (bytes_in_buffer == 0) { \
if (! (*datasrc->fill_input_buffer) (cinfo)) \ if (!(*datasrc->fill_input_buffer) (cinfo)) \
{ action; } \ { action; } \
INPUT_RELOAD(cinfo); \ INPUT_RELOAD(cinfo); \
} }
@ -148,19 +148,19 @@ typedef my_marker_reader *my_marker_ptr;
/* Read a byte into variable V. /* Read a byte into variable V.
* If must suspend, take the specified action (typically "return FALSE"). * If must suspend, take the specified action (typically "return FALSE").
*/ */
#define INPUT_BYTE(cinfo,V,action) \ #define INPUT_BYTE(cinfo, V, action) \
MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \ MAKESTMT( MAKE_BYTE_AVAIL(cinfo, action); \
bytes_in_buffer--; \ bytes_in_buffer--; \
V = GETJOCTET(*next_input_byte++); ) V = GETJOCTET(*next_input_byte++); )
/* As above, but read two bytes interpreted as an unsigned 16-bit integer. /* As above, but read two bytes interpreted as an unsigned 16-bit integer.
* V should be declared unsigned int or perhaps JLONG. * V should be declared unsigned int or perhaps JLONG.
*/ */
#define INPUT_2BYTES(cinfo,V,action) \ #define INPUT_2BYTES(cinfo, V, action) \
MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \ MAKESTMT( MAKE_BYTE_AVAIL(cinfo, action); \
bytes_in_buffer--; \ bytes_in_buffer--; \
V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \ V = ((unsigned int)GETJOCTET(*next_input_byte++)) << 8; \
MAKE_BYTE_AVAIL(cinfo,action); \ MAKE_BYTE_AVAIL(cinfo, action); \
bytes_in_buffer--; \ bytes_in_buffer--; \
V += GETJOCTET(*next_input_byte++); ) V += GETJOCTET(*next_input_byte++); )
@ -197,7 +197,7 @@ typedef my_marker_reader *my_marker_ptr;
LOCAL(boolean) LOCAL(boolean)
get_soi (j_decompress_ptr cinfo) get_soi(j_decompress_ptr cinfo)
/* Process an SOI marker */ /* Process an SOI marker */
{ {
int i; int i;
@ -237,7 +237,7 @@ get_soi (j_decompress_ptr cinfo)
LOCAL(boolean) LOCAL(boolean)
get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith) get_sof(j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
/* Process a SOFn marker */ /* Process a SOFn marker */
{ {
JLONG length; JLONG length;
@ -258,7 +258,7 @@ get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
length -= 8; length -= 8;
TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker, TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
(int) cinfo->image_width, (int) cinfo->image_height, (int)cinfo->image_width, (int)cinfo->image_height,
cinfo->num_components); cinfo->num_components);
if (cinfo->marker->saw_SOF) if (cinfo->marker->saw_SOF)
@ -267,16 +267,16 @@ get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
/* We don't support files in which the image height is initially specified */ /* We don't support files in which the image height is initially specified */
/* as 0 and is later redefined by DNL. As long as we have to check that, */ /* as 0 and is later redefined by DNL. As long as we have to check that, */
/* might as well have a general sanity check. */ /* might as well have a general sanity check. */
if (cinfo->image_height <= 0 || cinfo->image_width <= 0 if (cinfo->image_height <= 0 || cinfo->image_width <= 0 ||
|| cinfo->num_components <= 0) cinfo->num_components <= 0)
ERREXIT(cinfo, JERR_EMPTY_IMAGE); ERREXIT(cinfo, JERR_EMPTY_IMAGE);
if (length != (cinfo->num_components * 3)) if (length != (cinfo->num_components * 3))
ERREXIT(cinfo, JERR_BAD_LENGTH); ERREXIT(cinfo, JERR_BAD_LENGTH);
if (cinfo->comp_info == NULL) /* do only once, even if suspend */ if (cinfo->comp_info == NULL) /* do only once, even if suspend */
cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small) cinfo->comp_info = (jpeg_component_info *)(*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr)cinfo, JPOOL_IMAGE,
cinfo->num_components * sizeof(jpeg_component_info)); cinfo->num_components * sizeof(jpeg_component_info));
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
@ -301,7 +301,7 @@ get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
LOCAL(boolean) LOCAL(boolean)
get_sos (j_decompress_ptr cinfo) get_sos(j_decompress_ptr cinfo)
/* Process a SOS marker */ /* Process a SOS marker */
{ {
JLONG length; JLONG length;
@ -309,7 +309,7 @@ get_sos (j_decompress_ptr cinfo)
jpeg_component_info *compptr; jpeg_component_info *compptr;
INPUT_VARS(cinfo); INPUT_VARS(cinfo);
if (! cinfo->marker->saw_SOF) if (!cinfo->marker->saw_SOF)
ERREXIT(cinfo, JERR_SOS_NO_SOF); ERREXIT(cinfo, JERR_SOS_NO_SOF);
INPUT_2BYTES(cinfo, length, return FALSE); INPUT_2BYTES(cinfo, length, return FALSE);
@ -341,7 +341,7 @@ get_sos (j_decompress_ptr cinfo)
ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc); ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
id_found: id_found:
cinfo->cur_comp_info[i] = compptr; cinfo->cur_comp_info[i] = compptr;
compptr->dc_tbl_no = (c >> 4) & 15; compptr->dc_tbl_no = (c >> 4) & 15;
@ -384,7 +384,7 @@ get_sos (j_decompress_ptr cinfo)
#ifdef D_ARITH_CODING_SUPPORTED #ifdef D_ARITH_CODING_SUPPORTED
LOCAL(boolean) LOCAL(boolean)
get_dac (j_decompress_ptr cinfo) get_dac(j_decompress_ptr cinfo)
/* Process a DAC marker */ /* Process a DAC marker */
{ {
JLONG length; JLONG length;
@ -402,14 +402,14 @@ get_dac (j_decompress_ptr cinfo)
TRACEMS2(cinfo, 1, JTRC_DAC, index, val); TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
if (index < 0 || index >= (2*NUM_ARITH_TBLS)) if (index < 0 || index >= (2 * NUM_ARITH_TBLS))
ERREXIT1(cinfo, JERR_DAC_INDEX, index); ERREXIT1(cinfo, JERR_DAC_INDEX, index);
if (index >= NUM_ARITH_TBLS) { /* define AC table */ if (index >= NUM_ARITH_TBLS) { /* define AC table */
cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val; cinfo->arith_ac_K[index - NUM_ARITH_TBLS] = (UINT8)val;
} else { /* define DC table */ } else { /* define DC table */
cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F); cinfo->arith_dc_L[index] = (UINT8)(val & 0x0F);
cinfo->arith_dc_U[index] = (UINT8) (val >> 4); cinfo->arith_dc_U[index] = (UINT8)(val >> 4);
if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index]) if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
ERREXIT1(cinfo, JERR_DAC_VALUE, val); ERREXIT1(cinfo, JERR_DAC_VALUE, val);
} }
@ -422,7 +422,7 @@ get_dac (j_decompress_ptr cinfo)
return TRUE; return TRUE;
} }
#else /* ! D_ARITH_CODING_SUPPORTED */ #else /* !D_ARITH_CODING_SUPPORTED */
#define get_dac(cinfo) skip_variable(cinfo) #define get_dac(cinfo) skip_variable(cinfo)
@ -430,7 +430,7 @@ get_dac (j_decompress_ptr cinfo)
LOCAL(boolean) LOCAL(boolean)
get_dht (j_decompress_ptr cinfo) get_dht(j_decompress_ptr cinfo)
/* Process a DHT marker */ /* Process a DHT marker */
{ {
JLONG length; JLONG length;
@ -467,7 +467,7 @@ get_dht (j_decompress_ptr cinfo)
/* Here we just do minimal validation of the counts to avoid walking /* Here we just do minimal validation of the counts to avoid walking
* off the end of our table space. jdhuff.c will check more carefully. * off the end of our table space. jdhuff.c will check more carefully.
*/ */
if (count > 256 || ((JLONG) count) > length) if (count > 256 || ((JLONG)count) > length)
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
@ -489,7 +489,7 @@ get_dht (j_decompress_ptr cinfo)
} }
if (*htblptr == NULL) if (*htblptr == NULL)
*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); *htblptr = jpeg_alloc_huff_table((j_common_ptr)cinfo);
MEMCOPY((*htblptr)->bits, bits, sizeof((*htblptr)->bits)); MEMCOPY((*htblptr)->bits, bits, sizeof((*htblptr)->bits));
MEMCOPY((*htblptr)->huffval, huffval, sizeof((*htblptr)->huffval)); MEMCOPY((*htblptr)->huffval, huffval, sizeof((*htblptr)->huffval));
@ -504,7 +504,7 @@ get_dht (j_decompress_ptr cinfo)
LOCAL(boolean) LOCAL(boolean)
get_dqt (j_decompress_ptr cinfo) get_dqt(j_decompress_ptr cinfo)
/* Process a DQT marker */ /* Process a DQT marker */
{ {
JLONG length; JLONG length;
@ -527,7 +527,7 @@ get_dqt (j_decompress_ptr cinfo)
ERREXIT1(cinfo, JERR_DQT_INDEX, n); ERREXIT1(cinfo, JERR_DQT_INDEX, n);
if (cinfo->quant_tbl_ptrs[n] == NULL) if (cinfo->quant_tbl_ptrs[n] == NULL)
cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo); cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr)cinfo);
quant_ptr = cinfo->quant_tbl_ptrs[n]; quant_ptr = cinfo->quant_tbl_ptrs[n];
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
@ -536,20 +536,20 @@ get_dqt (j_decompress_ptr cinfo)
else else
INPUT_BYTE(cinfo, tmp, return FALSE); INPUT_BYTE(cinfo, tmp, return FALSE);
/* We convert the zigzag-order table to natural array order. */ /* We convert the zigzag-order table to natural array order. */
quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp; quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16)tmp;
} }
if (cinfo->err->trace_level >= 2) { if (cinfo->err->trace_level >= 2) {
for (i = 0; i < DCTSIZE2; i += 8) { for (i = 0; i < DCTSIZE2; i += 8) {
TRACEMS8(cinfo, 2, JTRC_QUANTVALS, TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
quant_ptr->quantval[i], quant_ptr->quantval[i+1], quant_ptr->quantval[i], quant_ptr->quantval[i + 1],
quant_ptr->quantval[i+2], quant_ptr->quantval[i+3], quant_ptr->quantval[i + 2], quant_ptr->quantval[i + 3],
quant_ptr->quantval[i+4], quant_ptr->quantval[i+5], quant_ptr->quantval[i + 4], quant_ptr->quantval[i + 5],
quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]); quant_ptr->quantval[i + 6], quant_ptr->quantval[i + 7]);
} }
} }
length -= DCTSIZE2+1; length -= DCTSIZE2 + 1;
if (prec) length -= DCTSIZE2; if (prec) length -= DCTSIZE2;
} }
@ -562,7 +562,7 @@ get_dqt (j_decompress_ptr cinfo)
LOCAL(boolean) LOCAL(boolean)
get_dri (j_decompress_ptr cinfo) get_dri(j_decompress_ptr cinfo)
/* Process a DRI marker */ /* Process a DRI marker */
{ {
JLONG length; JLONG length;
@ -598,14 +598,14 @@ get_dri (j_decompress_ptr cinfo)
LOCAL(void) LOCAL(void)
examine_app0 (j_decompress_ptr cinfo, JOCTET *data, examine_app0(j_decompress_ptr cinfo, JOCTET *data, unsigned int datalen,
unsigned int datalen, JLONG remaining) JLONG remaining)
/* Examine first few bytes from an APP0. /* Examine first few bytes from an APP0.
* Take appropriate action if it is a JFIF marker. * Take appropriate action if it is a JFIF marker.
* datalen is # of bytes at data[], remaining is length of rest of marker data. * datalen is # of bytes at data[], remaining is length of rest of marker data.
*/ */
{ {
JLONG totallen = (JLONG) datalen + remaining; JLONG totallen = (JLONG)datalen + remaining;
if (datalen >= APP0_DATA_LEN && if (datalen >= APP0_DATA_LEN &&
GETJOCTET(data[0]) == 0x4A && GETJOCTET(data[0]) == 0x4A &&
@ -639,8 +639,8 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET *data,
GETJOCTET(data[12]), GETJOCTET(data[13])); GETJOCTET(data[12]), GETJOCTET(data[13]));
totallen -= APP0_DATA_LEN; totallen -= APP0_DATA_LEN;
if (totallen != if (totallen !=
((JLONG)GETJOCTET(data[12]) * (JLONG)GETJOCTET(data[13]) * (JLONG) 3)) ((JLONG)GETJOCTET(data[12]) * (JLONG)GETJOCTET(data[13]) * (JLONG)3))
TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen); TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int)totallen);
} else if (datalen >= 6 && } else if (datalen >= 6 &&
GETJOCTET(data[0]) == 0x4A && GETJOCTET(data[0]) == 0x4A &&
GETJOCTET(data[1]) == 0x46 && GETJOCTET(data[1]) == 0x46 &&
@ -653,29 +653,29 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET *data,
*/ */
switch (GETJOCTET(data[5])) { switch (GETJOCTET(data[5])) {
case 0x10: case 0x10:
TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen); TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int)totallen);
break; break;
case 0x11: case 0x11:
TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen); TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int)totallen);
break; break;
case 0x13: case 0x13:
TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen); TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int)totallen);
break; break;
default: default:
TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION, TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
GETJOCTET(data[5]), (int) totallen); GETJOCTET(data[5]), (int)totallen);
break; break;
} }
} else { } else {
/* Start of APP0 does not match "JFIF" or "JFXX", or too short */ /* Start of APP0 does not match "JFIF" or "JFXX", or too short */
TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen); TRACEMS1(cinfo, 1, JTRC_APP0, (int)totallen);
} }
} }
LOCAL(void) LOCAL(void)
examine_app14 (j_decompress_ptr cinfo, JOCTET *data, examine_app14(j_decompress_ptr cinfo, JOCTET *data, unsigned int datalen,
unsigned int datalen, JLONG remaining) JLONG remaining)
/* Examine first few bytes from an APP14. /* Examine first few bytes from an APP14.
* Take appropriate action if it is an Adobe marker. * Take appropriate action if it is an Adobe marker.
* datalen is # of bytes at data[], remaining is length of rest of marker data. * datalen is # of bytes at data[], remaining is length of rest of marker data.
@ -696,16 +696,16 @@ examine_app14 (j_decompress_ptr cinfo, JOCTET *data,
transform = GETJOCTET(data[11]); transform = GETJOCTET(data[11]);
TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform); TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
cinfo->saw_Adobe_marker = TRUE; cinfo->saw_Adobe_marker = TRUE;
cinfo->Adobe_transform = (UINT8) transform; cinfo->Adobe_transform = (UINT8)transform;
} else { } else {
/* Start of APP14 does not match "Adobe", or too short */ /* Start of APP14 does not match "Adobe", or too short */
TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining)); TRACEMS1(cinfo, 1, JTRC_APP14, (int)(datalen + remaining));
} }
} }
METHODDEF(boolean) METHODDEF(boolean)
get_interesting_appn (j_decompress_ptr cinfo) get_interesting_appn(j_decompress_ptr cinfo)
/* Process an APP0 or APP14 marker without saving it */ /* Process an APP0 or APP14 marker without saving it */
{ {
JLONG length; JLONG length;
@ -720,7 +720,7 @@ get_interesting_appn (j_decompress_ptr cinfo)
if (length >= APPN_DATA_LEN) if (length >= APPN_DATA_LEN)
numtoread = APPN_DATA_LEN; numtoread = APPN_DATA_LEN;
else if (length > 0) else if (length > 0)
numtoread = (unsigned int) length; numtoread = (unsigned int)length;
else else
numtoread = 0; numtoread = 0;
for (i = 0; i < numtoread; i++) for (i = 0; i < numtoread; i++)
@ -730,10 +730,10 @@ get_interesting_appn (j_decompress_ptr cinfo)
/* process it */ /* process it */
switch (cinfo->unread_marker) { switch (cinfo->unread_marker) {
case M_APP0: case M_APP0:
examine_app0(cinfo, (JOCTET *) b, numtoread, length); examine_app0(cinfo, (JOCTET *)b, numtoread, length);
break; break;
case M_APP14: case M_APP14:
examine_app14(cinfo, (JOCTET *) b, numtoread, length); examine_app14(cinfo, (JOCTET *)b, numtoread, length);
break; break;
default: default:
/* can't get here unless jpeg_save_markers chooses wrong processor */ /* can't get here unless jpeg_save_markers chooses wrong processor */
@ -744,7 +744,7 @@ get_interesting_appn (j_decompress_ptr cinfo)
/* skip any remaining data -- could be lots */ /* skip any remaining data -- could be lots */
INPUT_SYNC(cinfo); INPUT_SYNC(cinfo);
if (length > 0) if (length > 0)
(*cinfo->src->skip_input_data) (cinfo, (long) length); (*cinfo->src->skip_input_data) (cinfo, (long)length);
return TRUE; return TRUE;
} }
@ -753,10 +753,10 @@ get_interesting_appn (j_decompress_ptr cinfo)
#ifdef SAVE_MARKERS_SUPPORTED #ifdef SAVE_MARKERS_SUPPORTED
METHODDEF(boolean) METHODDEF(boolean)
save_marker (j_decompress_ptr cinfo) save_marker(j_decompress_ptr cinfo)
/* Save an APPn or COM marker into the marker list */ /* Save an APPn or COM marker into the marker list */
{ {
my_marker_ptr marker = (my_marker_ptr) cinfo->marker; my_marker_ptr marker = (my_marker_ptr)cinfo->marker;
jpeg_saved_marker_ptr cur_marker = marker->cur_marker; jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
unsigned int bytes_read, data_length; unsigned int bytes_read, data_length;
JOCTET *data; JOCTET *data;
@ -770,22 +770,22 @@ save_marker (j_decompress_ptr cinfo)
if (length >= 0) { /* watch out for bogus length word */ if (length >= 0) { /* watch out for bogus length word */
/* figure out how much we want to save */ /* figure out how much we want to save */
unsigned int limit; unsigned int limit;
if (cinfo->unread_marker == (int) M_COM) if (cinfo->unread_marker == (int)M_COM)
limit = marker->length_limit_COM; limit = marker->length_limit_COM;
else else
limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0]; limit = marker->length_limit_APPn[cinfo->unread_marker - (int)M_APP0];
if ((unsigned int) length < limit) if ((unsigned int)length < limit)
limit = (unsigned int) length; limit = (unsigned int)length;
/* allocate and initialize the marker item */ /* allocate and initialize the marker item */
cur_marker = (jpeg_saved_marker_ptr) cur_marker = (jpeg_saved_marker_ptr)
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(struct jpeg_marker_struct) + limit); sizeof(struct jpeg_marker_struct) + limit);
cur_marker->next = NULL; cur_marker->next = NULL;
cur_marker->marker = (UINT8) cinfo->unread_marker; cur_marker->marker = (UINT8)cinfo->unread_marker;
cur_marker->original_length = (unsigned int) length; cur_marker->original_length = (unsigned int)length;
cur_marker->data_length = limit; cur_marker->data_length = limit;
/* data area is just beyond the jpeg_marker_struct */ /* data area is just beyond the jpeg_marker_struct */
data = cur_marker->data = (JOCTET *) (cur_marker + 1); data = cur_marker->data = (JOCTET *)(cur_marker + 1);
marker->cur_marker = cur_marker; marker->cur_marker = cur_marker;
marker->bytes_read = 0; marker->bytes_read = 0;
bytes_read = 0; bytes_read = 0;
@ -843,14 +843,14 @@ save_marker (j_decompress_ptr cinfo)
break; break;
default: default:
TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
(int) (data_length + length)); (int)(data_length + length));
break; break;
} }
/* skip any remaining data -- could be lots */ /* skip any remaining data -- could be lots */
INPUT_SYNC(cinfo); /* do before skip_input_data */ INPUT_SYNC(cinfo); /* do before skip_input_data */
if (length > 0) if (length > 0)
(*cinfo->src->skip_input_data) (cinfo, (long) length); (*cinfo->src->skip_input_data) (cinfo, (long)length);
return TRUE; return TRUE;
} }
@ -859,7 +859,7 @@ save_marker (j_decompress_ptr cinfo)
METHODDEF(boolean) METHODDEF(boolean)
skip_variable (j_decompress_ptr cinfo) skip_variable(j_decompress_ptr cinfo)
/* Skip over an unknown or uninteresting variable-length marker */ /* Skip over an unknown or uninteresting variable-length marker */
{ {
JLONG length; JLONG length;
@ -868,11 +868,11 @@ skip_variable (j_decompress_ptr cinfo)
INPUT_2BYTES(cinfo, length, return FALSE); INPUT_2BYTES(cinfo, length, return FALSE);
length -= 2; length -= 2;
TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length); TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int)length);
INPUT_SYNC(cinfo); /* do before skip_input_data */ INPUT_SYNC(cinfo); /* do before skip_input_data */
if (length > 0) if (length > 0)
(*cinfo->src->skip_input_data) (cinfo, (long) length); (*cinfo->src->skip_input_data) (cinfo, (long)length);
return TRUE; return TRUE;
} }
@ -888,7 +888,7 @@ skip_variable (j_decompress_ptr cinfo)
*/ */
LOCAL(boolean) LOCAL(boolean)
next_marker (j_decompress_ptr cinfo) next_marker(j_decompress_ptr cinfo)
{ {
int c; int c;
INPUT_VARS(cinfo); INPUT_VARS(cinfo);
@ -935,7 +935,7 @@ next_marker (j_decompress_ptr cinfo)
LOCAL(boolean) LOCAL(boolean)
first_marker (j_decompress_ptr cinfo) first_marker(j_decompress_ptr cinfo)
/* Like next_marker, but used to obtain the initial SOI marker. */ /* Like next_marker, but used to obtain the initial SOI marker. */
/* For this marker, we do not allow preceding garbage or fill; otherwise, /* For this marker, we do not allow preceding garbage or fill; otherwise,
* we might well scan an entire input file before realizing it ain't JPEG. * we might well scan an entire input file before realizing it ain't JPEG.
@ -948,7 +948,7 @@ first_marker (j_decompress_ptr cinfo)
INPUT_BYTE(cinfo, c, return FALSE); INPUT_BYTE(cinfo, c, return FALSE);
INPUT_BYTE(cinfo, c2, return FALSE); INPUT_BYTE(cinfo, c2, return FALSE);
if (c != 0xFF || c2 != (int) M_SOI) if (c != 0xFF || c2 != (int)M_SOI)
ERREXIT2(cinfo, JERR_NO_SOI, c, c2); ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
cinfo->unread_marker = c2; cinfo->unread_marker = c2;
@ -966,18 +966,18 @@ first_marker (j_decompress_ptr cinfo)
*/ */
METHODDEF(int) METHODDEF(int)
read_markers (j_decompress_ptr cinfo) read_markers(j_decompress_ptr cinfo)
{ {
/* Outer loop repeats once for each marker. */ /* Outer loop repeats once for each marker. */
for (;;) { for (;;) {
/* Collect the marker proper, unless we already did. */ /* Collect the marker proper, unless we already did. */
/* NB: first_marker() enforces the requirement that SOI appear first. */ /* NB: first_marker() enforces the requirement that SOI appear first. */
if (cinfo->unread_marker == 0) { if (cinfo->unread_marker == 0) {
if (! cinfo->marker->saw_SOI) { if (!cinfo->marker->saw_SOI) {
if (! first_marker(cinfo)) if (!first_marker(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
} else { } else {
if (! next_marker(cinfo)) if (!next_marker(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
} }
} }
@ -987,28 +987,28 @@ read_markers (j_decompress_ptr cinfo)
*/ */
switch (cinfo->unread_marker) { switch (cinfo->unread_marker) {
case M_SOI: case M_SOI:
if (! get_soi(cinfo)) if (!get_soi(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_SOF0: /* Baseline */ case M_SOF0: /* Baseline */
case M_SOF1: /* Extended sequential, Huffman */ case M_SOF1: /* Extended sequential, Huffman */
if (! get_sof(cinfo, FALSE, FALSE)) if (!get_sof(cinfo, FALSE, FALSE))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_SOF2: /* Progressive, Huffman */ case M_SOF2: /* Progressive, Huffman */
if (! get_sof(cinfo, TRUE, FALSE)) if (!get_sof(cinfo, TRUE, FALSE))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_SOF9: /* Extended sequential, arithmetic */ case M_SOF9: /* Extended sequential, arithmetic */
if (! get_sof(cinfo, FALSE, TRUE)) if (!get_sof(cinfo, FALSE, TRUE))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_SOF10: /* Progressive, arithmetic */ case M_SOF10: /* Progressive, arithmetic */
if (! get_sof(cinfo, TRUE, TRUE)) if (!get_sof(cinfo, TRUE, TRUE))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
@ -1026,7 +1026,7 @@ read_markers (j_decompress_ptr cinfo)
break; break;
case M_SOS: case M_SOS:
if (! get_sos(cinfo)) if (!get_sos(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
cinfo->unread_marker = 0; /* processed the marker */ cinfo->unread_marker = 0; /* processed the marker */
return JPEG_REACHED_SOS; return JPEG_REACHED_SOS;
@ -1037,22 +1037,22 @@ read_markers (j_decompress_ptr cinfo)
return JPEG_REACHED_EOI; return JPEG_REACHED_EOI;
case M_DAC: case M_DAC:
if (! get_dac(cinfo)) if (!get_dac(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_DHT: case M_DHT:
if (! get_dht(cinfo)) if (!get_dht(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_DQT: case M_DQT:
if (! get_dqt(cinfo)) if (!get_dqt(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_DRI: case M_DRI:
if (! get_dri(cinfo)) if (!get_dri(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
@ -1072,13 +1072,13 @@ read_markers (j_decompress_ptr cinfo)
case M_APP13: case M_APP13:
case M_APP14: case M_APP14:
case M_APP15: case M_APP15:
if (! (*((my_marker_ptr) cinfo->marker)->process_APPn[ if (!(*((my_marker_ptr)cinfo->marker)->process_APPn[
cinfo->unread_marker - (int) M_APP0]) (cinfo)) cinfo->unread_marker - (int)M_APP0]) (cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_COM: case M_COM:
if (! (*((my_marker_ptr) cinfo->marker)->process_COM) (cinfo)) if (!(*((my_marker_ptr)cinfo->marker)->process_COM) (cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
@ -1095,7 +1095,7 @@ read_markers (j_decompress_ptr cinfo)
break; break;
case M_DNL: /* Ignore DNL ... perhaps the wrong thing */ case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
if (! skip_variable(cinfo)) if (!skip_variable(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
@ -1127,24 +1127,24 @@ read_markers (j_decompress_ptr cinfo)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
read_restart_marker (j_decompress_ptr cinfo) read_restart_marker(j_decompress_ptr cinfo)
{ {
/* Obtain a marker unless we already did. */ /* Obtain a marker unless we already did. */
/* Note that next_marker will complain if it skips any data. */ /* Note that next_marker will complain if it skips any data. */
if (cinfo->unread_marker == 0) { if (cinfo->unread_marker == 0) {
if (! next_marker(cinfo)) if (!next_marker(cinfo))
return FALSE; return FALSE;
} }
if (cinfo->unread_marker == if (cinfo->unread_marker ==
((int) M_RST0 + cinfo->marker->next_restart_num)) { ((int)M_RST0 + cinfo->marker->next_restart_num)) {
/* Normal case --- swallow the marker and let entropy decoder continue */ /* Normal case --- swallow the marker and let entropy decoder continue */
TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num); TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
cinfo->unread_marker = 0; cinfo->unread_marker = 0;
} else { } else {
/* Uh-oh, the restart markers have been messed up. */ /* Uh-oh, the restart markers have been messed up. */
/* Let the data source manager determine how to resync. */ /* Let the data source manager determine how to resync. */
if (! (*cinfo->src->resync_to_restart) (cinfo, if (!(*cinfo->src->resync_to_restart) (cinfo,
cinfo->marker->next_restart_num)) cinfo->marker->next_restart_num))
return FALSE; return FALSE;
} }
@ -1206,7 +1206,7 @@ read_restart_marker (j_decompress_ptr cinfo)
*/ */
GLOBAL(boolean) GLOBAL(boolean)
jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired) jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired)
{ {
int marker = cinfo->unread_marker; int marker = cinfo->unread_marker;
int action = 1; int action = 1;
@ -1216,16 +1216,16 @@ jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
/* Outer loop handles repeated decision after scanning forward. */ /* Outer loop handles repeated decision after scanning forward. */
for (;;) { for (;;) {
if (marker < (int) M_SOF0) if (marker < (int)M_SOF0)
action = 2; /* invalid marker */ action = 2; /* invalid marker */
else if (marker < (int) M_RST0 || marker > (int) M_RST7) else if (marker < (int)M_RST0 || marker > (int)M_RST7)
action = 3; /* valid non-restart marker */ action = 3; /* valid non-restart marker */
else { else {
if (marker == ((int) M_RST0 + ((desired+1) & 7)) || if (marker == ((int)M_RST0 + ((desired + 1) & 7)) ||
marker == ((int) M_RST0 + ((desired+2) & 7))) marker == ((int)M_RST0 + ((desired + 2) & 7)))
action = 3; /* one of the next two expected restarts */ action = 3; /* one of the next two expected restarts */
else if (marker == ((int) M_RST0 + ((desired-1) & 7)) || else if (marker == ((int)M_RST0 + ((desired - 1) & 7)) ||
marker == ((int) M_RST0 + ((desired-2) & 7))) marker == ((int)M_RST0 + ((desired - 2) & 7)))
action = 2; /* a prior restart, so advance */ action = 2; /* a prior restart, so advance */
else else
action = 1; /* desired restart or too far away */ action = 1; /* desired restart or too far away */
@ -1238,7 +1238,7 @@ jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
return TRUE; return TRUE;
case 2: case 2:
/* Scan to the next marker, and repeat the decision loop. */ /* Scan to the next marker, and repeat the decision loop. */
if (! next_marker(cinfo)) if (!next_marker(cinfo))
return FALSE; return FALSE;
marker = cinfo->unread_marker; marker = cinfo->unread_marker;
break; break;
@ -1256,9 +1256,9 @@ jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
*/ */
METHODDEF(void) METHODDEF(void)
reset_marker_reader (j_decompress_ptr cinfo) reset_marker_reader(j_decompress_ptr cinfo)
{ {
my_marker_ptr marker = (my_marker_ptr) cinfo->marker; my_marker_ptr marker = (my_marker_ptr)cinfo->marker;
cinfo->comp_info = NULL; /* until allocated by get_sof */ cinfo->comp_info = NULL; /* until allocated by get_sof */
cinfo->input_scan_number = 0; /* no SOS seen yet */ cinfo->input_scan_number = 0; /* no SOS seen yet */
@ -1276,16 +1276,16 @@ reset_marker_reader (j_decompress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_marker_reader (j_decompress_ptr cinfo) jinit_marker_reader(j_decompress_ptr cinfo)
{ {
my_marker_ptr marker; my_marker_ptr marker;
int i; int i;
/* Create subobject in permanent pool */ /* Create subobject in permanent pool */
marker = (my_marker_ptr) marker = (my_marker_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
sizeof(my_marker_reader)); sizeof(my_marker_reader));
cinfo->marker = (struct jpeg_marker_reader *) marker; cinfo->marker = (struct jpeg_marker_reader *)marker;
/* Initialize public method pointers */ /* Initialize public method pointers */
marker->pub.reset_marker_reader = reset_marker_reader; marker->pub.reset_marker_reader = reset_marker_reader;
marker->pub.read_markers = read_markers; marker->pub.read_markers = read_markers;
@ -1314,10 +1314,10 @@ jinit_marker_reader (j_decompress_ptr cinfo)
#ifdef SAVE_MARKERS_SUPPORTED #ifdef SAVE_MARKERS_SUPPORTED
GLOBAL(void) GLOBAL(void)
jpeg_save_markers (j_decompress_ptr cinfo, int marker_code, jpeg_save_markers(j_decompress_ptr cinfo, int marker_code,
unsigned int length_limit) unsigned int length_limit)
{ {
my_marker_ptr marker = (my_marker_ptr) cinfo->marker; my_marker_ptr marker = (my_marker_ptr)cinfo->marker;
long maxlength; long maxlength;
jpeg_marker_parser_method processor; jpeg_marker_parser_method processor;
@ -1325,8 +1325,8 @@ jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
* (should only be a concern in a 16-bit environment). * (should only be a concern in a 16-bit environment).
*/ */
maxlength = cinfo->mem->max_alloc_chunk - sizeof(struct jpeg_marker_struct); maxlength = cinfo->mem->max_alloc_chunk - sizeof(struct jpeg_marker_struct);
if (((long) length_limit) > maxlength) if (((long)length_limit) > maxlength)
length_limit = (unsigned int) maxlength; length_limit = (unsigned int)maxlength;
/* Choose processor routine to use. /* Choose processor routine to use.
* APP0/APP14 have special requirements. * APP0/APP14 have special requirements.
@ -1334,23 +1334,23 @@ jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
if (length_limit) { if (length_limit) {
processor = save_marker; processor = save_marker;
/* If saving APP0/APP14, save at least enough for our internal use. */ /* If saving APP0/APP14, save at least enough for our internal use. */
if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN) if (marker_code == (int)M_APP0 && length_limit < APP0_DATA_LEN)
length_limit = APP0_DATA_LEN; length_limit = APP0_DATA_LEN;
else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN) else if (marker_code == (int)M_APP14 && length_limit < APP14_DATA_LEN)
length_limit = APP14_DATA_LEN; length_limit = APP14_DATA_LEN;
} else { } else {
processor = skip_variable; processor = skip_variable;
/* If discarding APP0/APP14, use our regular on-the-fly processor. */ /* If discarding APP0/APP14, use our regular on-the-fly processor. */
if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14) if (marker_code == (int)M_APP0 || marker_code == (int)M_APP14)
processor = get_interesting_appn; processor = get_interesting_appn;
} }
if (marker_code == (int) M_COM) { if (marker_code == (int)M_COM) {
marker->process_COM = processor; marker->process_COM = processor;
marker->length_limit_COM = length_limit; marker->length_limit_COM = length_limit;
} else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) { } else if (marker_code >= (int)M_APP0 && marker_code <= (int)M_APP15) {
marker->process_APPn[marker_code - (int) M_APP0] = processor; marker->process_APPn[marker_code - (int)M_APP0] = processor;
marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit; marker->length_limit_APPn[marker_code - (int)M_APP0] = length_limit;
} else } else
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code); ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
} }
@ -1363,15 +1363,15 @@ jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code, jpeg_set_marker_processor(j_decompress_ptr cinfo, int marker_code,
jpeg_marker_parser_method routine) jpeg_marker_parser_method routine)
{ {
my_marker_ptr marker = (my_marker_ptr) cinfo->marker; my_marker_ptr marker = (my_marker_ptr)cinfo->marker;
if (marker_code == (int) M_COM) if (marker_code == (int)M_COM)
marker->process_COM = routine; marker->process_COM = routine;
else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) else if (marker_code >= (int)M_APP0 && marker_code <= (int)M_APP15)
marker->process_APPn[marker_code - (int) M_APP0] = routine; marker->process_APPn[marker_code - (int)M_APP0] = routine;
else else
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code); ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
} }

View File

@ -31,7 +31,7 @@
*/ */
LOCAL(boolean) LOCAL(boolean)
use_merged_upsample (j_decompress_ptr cinfo) use_merged_upsample(j_decompress_ptr cinfo)
{ {
#ifdef UPSAMPLE_MERGING_SUPPORTED #ifdef UPSAMPLE_MERGING_SUPPORTED
/* Merging is the equivalent of plain box-filter upsampling */ /* Merging is the equivalent of plain box-filter upsampling */
@ -100,7 +100,7 @@ GLOBAL(void)
#else #else
LOCAL(void) LOCAL(void)
#endif #endif
jpeg_core_output_dimensions (j_decompress_ptr cinfo) jpeg_core_output_dimensions(j_decompress_ptr cinfo)
/* Do computations that are needed before master selection phase. /* Do computations that are needed before master selection phase.
* This function is used for transcoding and full decompression. * This function is used for transcoding and full decompression.
*/ */
@ -113,129 +113,129 @@ jpeg_core_output_dimensions (j_decompress_ptr cinfo)
if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom) { if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom) {
/* Provide 1/block_size scaling */ /* Provide 1/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 1; cinfo->_min_DCT_h_scaled_size = 1;
cinfo->_min_DCT_v_scaled_size = 1; cinfo->_min_DCT_v_scaled_size = 1;
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 2) { } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 2) {
/* Provide 2/block_size scaling */ /* Provide 2/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * 2L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width * 2L, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * 2L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height * 2L, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 2; cinfo->_min_DCT_h_scaled_size = 2;
cinfo->_min_DCT_v_scaled_size = 2; cinfo->_min_DCT_v_scaled_size = 2;
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 3) { } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 3) {
/* Provide 3/block_size scaling */ /* Provide 3/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * 3L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width * 3L, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * 3L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height * 3L, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 3; cinfo->_min_DCT_h_scaled_size = 3;
cinfo->_min_DCT_v_scaled_size = 3; cinfo->_min_DCT_v_scaled_size = 3;
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 4) { } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 4) {
/* Provide 4/block_size scaling */ /* Provide 4/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * 4L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width * 4L, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * 4L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height * 4L, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 4; cinfo->_min_DCT_h_scaled_size = 4;
cinfo->_min_DCT_v_scaled_size = 4; cinfo->_min_DCT_v_scaled_size = 4;
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 5) { } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 5) {
/* Provide 5/block_size scaling */ /* Provide 5/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * 5L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width * 5L, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * 5L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height * 5L, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 5; cinfo->_min_DCT_h_scaled_size = 5;
cinfo->_min_DCT_v_scaled_size = 5; cinfo->_min_DCT_v_scaled_size = 5;
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 6) { } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 6) {
/* Provide 6/block_size scaling */ /* Provide 6/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * 6L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width * 6L, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * 6L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height * 6L, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 6; cinfo->_min_DCT_h_scaled_size = 6;
cinfo->_min_DCT_v_scaled_size = 6; cinfo->_min_DCT_v_scaled_size = 6;
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 7) { } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 7) {
/* Provide 7/block_size scaling */ /* Provide 7/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * 7L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width * 7L, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * 7L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height * 7L, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 7; cinfo->_min_DCT_h_scaled_size = 7;
cinfo->_min_DCT_v_scaled_size = 7; cinfo->_min_DCT_v_scaled_size = 7;
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 8) { } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 8) {
/* Provide 8/block_size scaling */ /* Provide 8/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * 8L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width * 8L, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * 8L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height * 8L, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 8; cinfo->_min_DCT_h_scaled_size = 8;
cinfo->_min_DCT_v_scaled_size = 8; cinfo->_min_DCT_v_scaled_size = 8;
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 9) { } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 9) {
/* Provide 9/block_size scaling */ /* Provide 9/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * 9L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width * 9L, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * 9L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height * 9L, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 9; cinfo->_min_DCT_h_scaled_size = 9;
cinfo->_min_DCT_v_scaled_size = 9; cinfo->_min_DCT_v_scaled_size = 9;
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 10) { } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 10) {
/* Provide 10/block_size scaling */ /* Provide 10/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * 10L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width * 10L, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * 10L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height * 10L, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 10; cinfo->_min_DCT_h_scaled_size = 10;
cinfo->_min_DCT_v_scaled_size = 10; cinfo->_min_DCT_v_scaled_size = 10;
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 11) { } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 11) {
/* Provide 11/block_size scaling */ /* Provide 11/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * 11L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width * 11L, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * 11L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height * 11L, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 11; cinfo->_min_DCT_h_scaled_size = 11;
cinfo->_min_DCT_v_scaled_size = 11; cinfo->_min_DCT_v_scaled_size = 11;
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 12) { } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 12) {
/* Provide 12/block_size scaling */ /* Provide 12/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * 12L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width * 12L, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * 12L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height * 12L, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 12; cinfo->_min_DCT_h_scaled_size = 12;
cinfo->_min_DCT_v_scaled_size = 12; cinfo->_min_DCT_v_scaled_size = 12;
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 13) { } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 13) {
/* Provide 13/block_size scaling */ /* Provide 13/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * 13L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width * 13L, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * 13L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height * 13L, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 13; cinfo->_min_DCT_h_scaled_size = 13;
cinfo->_min_DCT_v_scaled_size = 13; cinfo->_min_DCT_v_scaled_size = 13;
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 14) { } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 14) {
/* Provide 14/block_size scaling */ /* Provide 14/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * 14L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width * 14L, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * 14L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height * 14L, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 14; cinfo->_min_DCT_h_scaled_size = 14;
cinfo->_min_DCT_v_scaled_size = 14; cinfo->_min_DCT_v_scaled_size = 14;
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 15) { } else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 15) {
/* Provide 15/block_size scaling */ /* Provide 15/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * 15L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width * 15L, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * 15L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height * 15L, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 15; cinfo->_min_DCT_h_scaled_size = 15;
cinfo->_min_DCT_v_scaled_size = 15; cinfo->_min_DCT_v_scaled_size = 15;
} else { } else {
/* Provide 16/block_size scaling */ /* Provide 16/block_size scaling */
cinfo->output_width = (JDIMENSION) cinfo->output_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * 16L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_width * 16L, (long)DCTSIZE);
cinfo->output_height = (JDIMENSION) cinfo->output_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * 16L, (long) DCTSIZE); jdiv_round_up((long)cinfo->image_height * 16L, (long)DCTSIZE);
cinfo->_min_DCT_h_scaled_size = 16; cinfo->_min_DCT_h_scaled_size = 16;
cinfo->_min_DCT_v_scaled_size = 16; cinfo->_min_DCT_v_scaled_size = 16;
} }
@ -268,7 +268,7 @@ jpeg_core_output_dimensions (j_decompress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_calc_output_dimensions (j_decompress_ptr cinfo) jpeg_calc_output_dimensions(j_decompress_ptr cinfo)
/* Do computations that are needed before master selection phase */ /* Do computations that are needed before master selection phase */
{ {
#ifdef IDCT_SCALING_SUPPORTED #ifdef IDCT_SCALING_SUPPORTED
@ -314,13 +314,13 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
ci++, compptr++) { ci++, compptr++) {
/* Size in samples, after IDCT scaling */ /* Size in samples, after IDCT scaling */
compptr->downsampled_width = (JDIMENSION) compptr->downsampled_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * jdiv_round_up((long)cinfo->image_width *
(long) (compptr->h_samp_factor * compptr->_DCT_scaled_size), (long)(compptr->h_samp_factor * compptr->_DCT_scaled_size),
(long) (cinfo->max_h_samp_factor * DCTSIZE)); (long)(cinfo->max_h_samp_factor * DCTSIZE));
compptr->downsampled_height = (JDIMENSION) compptr->downsampled_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * jdiv_round_up((long)cinfo->image_height *
(long) (compptr->v_samp_factor * compptr->_DCT_scaled_size), (long)(compptr->v_samp_factor * compptr->_DCT_scaled_size),
(long) (cinfo->max_v_samp_factor * DCTSIZE)); (long)(cinfo->max_v_samp_factor * DCTSIZE));
} }
#else /* !IDCT_SCALING_SUPPORTED */ #else /* !IDCT_SCALING_SUPPORTED */
@ -417,30 +417,30 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
*/ */
LOCAL(void) LOCAL(void)
prepare_range_limit_table (j_decompress_ptr cinfo) prepare_range_limit_table(j_decompress_ptr cinfo)
/* Allocate and fill in the sample_range_limit table */ /* Allocate and fill in the sample_range_limit table */
{ {
JSAMPLE *table; JSAMPLE *table;
int i; int i;
table = (JSAMPLE *) table = (JSAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * sizeof(JSAMPLE)); (5 * (MAXJSAMPLE + 1) + CENTERJSAMPLE) * sizeof(JSAMPLE));
table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */ table += (MAXJSAMPLE + 1); /* allow negative subscripts of simple table */
cinfo->sample_range_limit = table; cinfo->sample_range_limit = table;
/* First segment of "simple" table: limit[x] = 0 for x < 0 */ /* First segment of "simple" table: limit[x] = 0 for x < 0 */
MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * sizeof(JSAMPLE)); MEMZERO(table - (MAXJSAMPLE + 1), (MAXJSAMPLE + 1) * sizeof(JSAMPLE));
/* Main part of "simple" table: limit[x] = x */ /* Main part of "simple" table: limit[x] = x */
for (i = 0; i <= MAXJSAMPLE; i++) for (i = 0; i <= MAXJSAMPLE; i++)
table[i] = (JSAMPLE) i; table[i] = (JSAMPLE)i;
table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */ table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
/* End of simple table, rest of first half of post-IDCT table */ /* End of simple table, rest of first half of post-IDCT table */
for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++) for (i = CENTERJSAMPLE; i < 2 * (MAXJSAMPLE + 1); i++)
table[i] = MAXJSAMPLE; table[i] = MAXJSAMPLE;
/* Second half of post-IDCT table */ /* Second half of post-IDCT table */
MEMZERO(table + (2 * (MAXJSAMPLE+1)), MEMZERO(table + (2 * (MAXJSAMPLE + 1)),
(2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * sizeof(JSAMPLE)); (2 * (MAXJSAMPLE + 1) - CENTERJSAMPLE) * sizeof(JSAMPLE));
MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE), MEMCOPY(table + (4 * (MAXJSAMPLE + 1) - CENTERJSAMPLE),
cinfo->sample_range_limit, CENTERJSAMPLE * sizeof(JSAMPLE)); cinfo->sample_range_limit, CENTERJSAMPLE * sizeof(JSAMPLE));
} }
@ -457,9 +457,9 @@ prepare_range_limit_table (j_decompress_ptr cinfo)
*/ */
LOCAL(void) LOCAL(void)
master_selection (j_decompress_ptr cinfo) master_selection(j_decompress_ptr cinfo)
{ {
my_master_ptr master = (my_master_ptr) cinfo->master; my_master_ptr master = (my_master_ptr)cinfo->master;
boolean use_c_buffer; boolean use_c_buffer;
long samplesperrow; long samplesperrow;
JDIMENSION jd_samplesperrow; JDIMENSION jd_samplesperrow;
@ -469,9 +469,10 @@ master_selection (j_decompress_ptr cinfo)
prepare_range_limit_table(cinfo); prepare_range_limit_table(cinfo);
/* Width of an output scanline must be representable as JDIMENSION. */ /* Width of an output scanline must be representable as JDIMENSION. */
samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components; samplesperrow = (long)cinfo->output_width *
jd_samplesperrow = (JDIMENSION) samplesperrow; (long)cinfo->out_color_components;
if ((long) jd_samplesperrow != samplesperrow) jd_samplesperrow = (JDIMENSION)samplesperrow;
if ((long)jd_samplesperrow != samplesperrow)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
/* Initialize my private state */ /* Initialize my private state */
@ -482,7 +483,7 @@ master_selection (j_decompress_ptr cinfo)
master->quantizer_1pass = NULL; master->quantizer_1pass = NULL;
master->quantizer_2pass = NULL; master->quantizer_2pass = NULL;
/* No mode changes if not using buffered-image mode. */ /* No mode changes if not using buffered-image mode. */
if (! cinfo->quantize_colors || ! cinfo->buffered_image) { if (!cinfo->quantize_colors || !cinfo->buffered_image) {
cinfo->enable_1pass_quant = FALSE; cinfo->enable_1pass_quant = FALSE;
cinfo->enable_external_quant = FALSE; cinfo->enable_external_quant = FALSE;
cinfo->enable_2pass_quant = FALSE; cinfo->enable_2pass_quant = FALSE;
@ -528,7 +529,7 @@ master_selection (j_decompress_ptr cinfo)
} }
/* Post-processing: in particular, color conversion first */ /* Post-processing: in particular, color conversion first */
if (! cinfo->raw_data_out) { if (!cinfo->raw_data_out) {
if (master->using_merged_upsample) { if (master->using_merged_upsample) {
#ifdef UPSAMPLE_MERGING_SUPPORTED #ifdef UPSAMPLE_MERGING_SUPPORTED
jinit_merged_upsampler(cinfo); /* does color conversion too */ jinit_merged_upsampler(cinfo); /* does color conversion too */
@ -565,11 +566,11 @@ master_selection (j_decompress_ptr cinfo)
use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image; use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
jinit_d_coef_controller(cinfo, use_c_buffer); jinit_d_coef_controller(cinfo, use_c_buffer);
if (! cinfo->raw_data_out) if (!cinfo->raw_data_out)
jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */); jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
/* We can now tell the memory manager to allocate virtual arrays. */ /* We can now tell the memory manager to allocate virtual arrays. */
(*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); (*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo);
/* Initialize input side of decompressor to consume first scan. */ /* Initialize input side of decompressor to consume first scan. */
(*cinfo->inputctl->start_input_pass) (cinfo); (*cinfo->inputctl->start_input_pass) (cinfo);
@ -585,7 +586,7 @@ master_selection (j_decompress_ptr cinfo)
* progress monitoring appropriately. The input step is counted * progress monitoring appropriately. The input step is counted
* as one pass. * as one pass.
*/ */
if (cinfo->progress != NULL && ! cinfo->buffered_image && if (cinfo->progress != NULL && !cinfo->buffered_image &&
cinfo->inputctl->has_multiple_scans) { cinfo->inputctl->has_multiple_scans) {
int nscans; int nscans;
/* Estimate number of scans to set pass_limit. */ /* Estimate number of scans to set pass_limit. */
@ -597,7 +598,7 @@ master_selection (j_decompress_ptr cinfo)
nscans = cinfo->num_components; nscans = cinfo->num_components;
} }
cinfo->progress->pass_counter = 0L; cinfo->progress->pass_counter = 0L;
cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans; cinfo->progress->pass_limit = (long)cinfo->total_iMCU_rows * nscans;
cinfo->progress->completed_passes = 0; cinfo->progress->completed_passes = 0;
cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2); cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
/* Count the input pass as done */ /* Count the input pass as done */
@ -617,9 +618,9 @@ master_selection (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
prepare_for_output_pass (j_decompress_ptr cinfo) prepare_for_output_pass(j_decompress_ptr cinfo)
{ {
my_master_ptr master = (my_master_ptr) cinfo->master; my_master_ptr master = (my_master_ptr)cinfo->master;
if (master->pub.is_dummy_pass) { if (master->pub.is_dummy_pass) {
#ifdef QUANT_2PASS_SUPPORTED #ifdef QUANT_2PASS_SUPPORTED
@ -645,8 +646,8 @@ prepare_for_output_pass (j_decompress_ptr cinfo)
} }
(*cinfo->idct->start_pass) (cinfo); (*cinfo->idct->start_pass) (cinfo);
(*cinfo->coef->start_output_pass) (cinfo); (*cinfo->coef->start_output_pass) (cinfo);
if (! cinfo->raw_data_out) { if (!cinfo->raw_data_out) {
if (! master->using_merged_upsample) if (!master->using_merged_upsample)
(*cinfo->cconvert->start_pass) (cinfo); (*cinfo->cconvert->start_pass) (cinfo);
(*cinfo->upsample->start_pass) (cinfo); (*cinfo->upsample->start_pass) (cinfo);
if (cinfo->quantize_colors) if (cinfo->quantize_colors)
@ -665,7 +666,7 @@ prepare_for_output_pass (j_decompress_ptr cinfo)
/* In buffered-image mode, we assume one more output pass if EOI not /* In buffered-image mode, we assume one more output pass if EOI not
* yet reached, but no more passes if EOI has been reached. * yet reached, but no more passes if EOI has been reached.
*/ */
if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) { if (cinfo->buffered_image && !cinfo->inputctl->eoi_reached) {
cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1); cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
} }
} }
@ -677,9 +678,9 @@ prepare_for_output_pass (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
finish_output_pass (j_decompress_ptr cinfo) finish_output_pass(j_decompress_ptr cinfo)
{ {
my_master_ptr master = (my_master_ptr) cinfo->master; my_master_ptr master = (my_master_ptr)cinfo->master;
if (cinfo->quantize_colors) if (cinfo->quantize_colors)
(*cinfo->cquantize->finish_pass) (cinfo); (*cinfo->cquantize->finish_pass) (cinfo);
@ -694,9 +695,9 @@ finish_output_pass (j_decompress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_new_colormap (j_decompress_ptr cinfo) jpeg_new_colormap(j_decompress_ptr cinfo)
{ {
my_master_ptr master = (my_master_ptr) cinfo->master; my_master_ptr master = (my_master_ptr)cinfo->master;
/* Prevent application from calling me at wrong times */ /* Prevent application from calling me at wrong times */
if (cinfo->global_state != DSTATE_BUFIMAGE) if (cinfo->global_state != DSTATE_BUFIMAGE)
@ -722,9 +723,9 @@ jpeg_new_colormap (j_decompress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_master_decompress (j_decompress_ptr cinfo) jinit_master_decompress(j_decompress_ptr cinfo)
{ {
my_master_ptr master = (my_master_ptr) cinfo->master; my_master_ptr master = (my_master_ptr)cinfo->master;
master->pub.prepare_for_output_pass = prepare_for_output_pass; master->pub.prepare_for_output_pass = prepare_for_output_pass;
master->pub.finish_output_pass = finish_output_pass; master->pub.finish_output_pass = finish_output_pass;

View File

@ -76,8 +76,8 @@ typedef struct {
typedef my_upsampler *my_upsample_ptr; typedef my_upsampler *my_upsample_ptr;
#define SCALEBITS 16 /* speediest right-shift on some machines */ #define SCALEBITS 16 /* speediest right-shift on some machines */
#define ONE_HALF ((JLONG) 1 << (SCALEBITS-1)) #define ONE_HALF ((JLONG)1 << (SCALEBITS - 1))
#define FIX(x) ((JLONG) ((x) * (1L<<SCALEBITS) + 0.5)) #define FIX(x) ((JLONG)((x) * (1L << SCALEBITS) + 0.5))
/* Include inline routines for colorspace extensions */ /* Include inline routines for colorspace extensions */
@ -187,25 +187,25 @@ typedef my_upsampler *my_upsample_ptr;
*/ */
LOCAL(void) LOCAL(void)
build_ycc_rgb_table (j_decompress_ptr cinfo) build_ycc_rgb_table(j_decompress_ptr cinfo)
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
int i; int i;
JLONG x; JLONG x;
SHIFT_TEMPS SHIFT_TEMPS
upsample->Cr_r_tab = (int *) upsample->Cr_r_tab = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * sizeof(int)); (MAXJSAMPLE + 1) * sizeof(int));
upsample->Cb_b_tab = (int *) upsample->Cb_b_tab = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * sizeof(int)); (MAXJSAMPLE + 1) * sizeof(int));
upsample->Cr_g_tab = (JLONG *) upsample->Cr_g_tab = (JLONG *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * sizeof(JLONG)); (MAXJSAMPLE + 1) * sizeof(JLONG));
upsample->Cb_g_tab = (JLONG *) upsample->Cb_g_tab = (JLONG *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * sizeof(JLONG)); (MAXJSAMPLE + 1) * sizeof(JLONG));
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
@ -217,10 +217,10 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
upsample->Cb_b_tab[i] = (int) upsample->Cb_b_tab[i] = (int)
RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
/* Cr=>G value is scaled-up -0.71414 * x */ /* Cr=>G value is scaled-up -0.71414 * x */
upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x; upsample->Cr_g_tab[i] = (-FIX(0.71414)) * x;
/* Cb=>G value is scaled-up -0.34414 * x */ /* Cb=>G value is scaled-up -0.34414 * x */
/* We also add in ONE_HALF so that need not do it in inner loop */ /* We also add in ONE_HALF so that need not do it in inner loop */
upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; upsample->Cb_g_tab[i] = (-FIX(0.34414)) * x + ONE_HALF;
} }
} }
@ -230,9 +230,9 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_merged_upsample (j_decompress_ptr cinfo) start_pass_merged_upsample(j_decompress_ptr cinfo)
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
/* Mark the spare buffer empty */ /* Mark the spare buffer empty */
upsample->spare_full = FALSE; upsample->spare_full = FALSE;
@ -248,14 +248,13 @@ start_pass_merged_upsample (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
merged_2v_upsample (j_decompress_ptr cinfo, merged_2v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
JDIMENSION out_rows_avail)
/* 2:1 vertical sampling case: may need a spare row. */ /* 2:1 vertical sampling case: may need a spare row. */
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
JSAMPROW work_ptrs[2]; JSAMPROW work_ptrs[2];
JDIMENSION num_rows; /* number of rows returned to caller */ JDIMENSION num_rows; /* number of rows returned to caller */
@ -264,8 +263,8 @@ merged_2v_upsample (j_decompress_ptr cinfo,
JDIMENSION size = upsample->out_row_width; JDIMENSION size = upsample->out_row_width;
if (cinfo->out_color_space == JCS_RGB565) if (cinfo->out_color_space == JCS_RGB565)
size = cinfo->output_width * 2; size = cinfo->output_width * 2;
jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0, jcopy_sample_rows(&upsample->spare_row, 0, output_buf + *out_row_ctr, 0, 1,
1, size); size);
num_rows = 1; num_rows = 1;
upsample->spare_full = FALSE; upsample->spare_full = FALSE;
} else { } else {
@ -294,20 +293,19 @@ merged_2v_upsample (j_decompress_ptr cinfo,
*out_row_ctr += num_rows; *out_row_ctr += num_rows;
upsample->rows_to_go -= num_rows; upsample->rows_to_go -= num_rows;
/* When the buffer is emptied, declare this input row group consumed */ /* When the buffer is emptied, declare this input row group consumed */
if (! upsample->spare_full) if (!upsample->spare_full)
(*in_row_group_ctr)++; (*in_row_group_ctr)++;
} }
METHODDEF(void) METHODDEF(void)
merged_1v_upsample (j_decompress_ptr cinfo, merged_1v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
JDIMENSION out_rows_avail)
/* 1:1 vertical sampling case: much easier, never need a spare row. */ /* 1:1 vertical sampling case: much easier, never need a spare row. */
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
/* Just do the upsampling. */ /* Just do the upsampling. */
(*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
@ -333,9 +331,8 @@ merged_1v_upsample (j_decompress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
h2v1_merged_upsample (j_decompress_ptr cinfo, h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
JSAMPARRAY output_buf)
{ {
switch (cinfo->out_color_space) { switch (cinfo->out_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@ -379,9 +376,8 @@ h2v1_merged_upsample (j_decompress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
h2v2_merged_upsample (j_decompress_ptr cinfo, h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
JSAMPARRAY output_buf)
{ {
switch (cinfo->out_color_space) { switch (cinfo->out_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@ -436,12 +432,12 @@ h2v2_merged_upsample (j_decompress_ptr cinfo,
#define PACK_NEED_ALIGNMENT(ptr) (((size_t)(ptr)) & 3) #define PACK_NEED_ALIGNMENT(ptr) (((size_t)(ptr)) & 3)
#define WRITE_TWO_PIXELS_LE(addr, pixels) { \ #define WRITE_TWO_PIXELS_LE(addr, pixels) { \
((INT16*)(addr))[0] = (INT16)(pixels); \ ((INT16 *)(addr))[0] = (INT16)(pixels); \
((INT16*)(addr))[1] = (INT16)((pixels) >> 16); \ ((INT16 *)(addr))[1] = (INT16)((pixels) >> 16); \
} }
#define WRITE_TWO_PIXELS_BE(addr, pixels) { \ #define WRITE_TWO_PIXELS_BE(addr, pixels) { \
((INT16*)(addr))[1] = (INT16)(pixels); \ ((INT16 *)(addr))[1] = (INT16)(pixels); \
((INT16*)(addr))[0] = (INT16)((pixels) >> 16); \ ((INT16 *)(addr))[0] = (INT16)((pixels) >> 16); \
} }
#define DITHER_565_R(r, dither) ((r) + ((dither) & 0xFF)) #define DITHER_565_R(r, dither) ((r) + ((dither) & 0xFF))
@ -452,7 +448,7 @@ h2v2_merged_upsample (j_decompress_ptr cinfo,
/* Declarations for ordered dithering /* Declarations for ordered dithering
* *
* We use a 4x4 ordered dither array packed into 32 bits. This array is * We use a 4x4 ordered dither array packed into 32 bits. This array is
* sufficent for dithering RGB888 to RGB565. * sufficient for dithering RGB888 to RGB565.
*/ */
#define DITHER_MASK 0x3 #define DITHER_MASK 0x3
@ -510,9 +506,8 @@ static INLINE boolean is_big_endian(void)
METHODDEF(void) METHODDEF(void)
h2v1_merged_upsample_565 (j_decompress_ptr cinfo, h2v1_merged_upsample_565(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
JSAMPARRAY output_buf)
{ {
if (is_big_endian()) if (is_big_endian())
h2v1_merged_upsample_565_be(cinfo, input_buf, in_row_group_ctr, h2v1_merged_upsample_565_be(cinfo, input_buf, in_row_group_ctr,
@ -520,13 +515,12 @@ h2v1_merged_upsample_565 (j_decompress_ptr cinfo,
else else
h2v1_merged_upsample_565_le(cinfo, input_buf, in_row_group_ctr, h2v1_merged_upsample_565_le(cinfo, input_buf, in_row_group_ctr,
output_buf); output_buf);
} }
METHODDEF(void) METHODDEF(void)
h2v1_merged_upsample_565D (j_decompress_ptr cinfo, h2v1_merged_upsample_565D(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
JSAMPARRAY output_buf)
{ {
if (is_big_endian()) if (is_big_endian())
h2v1_merged_upsample_565D_be(cinfo, input_buf, in_row_group_ctr, h2v1_merged_upsample_565D_be(cinfo, input_buf, in_row_group_ctr,
@ -538,9 +532,8 @@ h2v1_merged_upsample_565D (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
h2v2_merged_upsample_565 (j_decompress_ptr cinfo, h2v2_merged_upsample_565(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
JSAMPARRAY output_buf)
{ {
if (is_big_endian()) if (is_big_endian())
h2v2_merged_upsample_565_be(cinfo, input_buf, in_row_group_ctr, h2v2_merged_upsample_565_be(cinfo, input_buf, in_row_group_ctr,
@ -552,9 +545,8 @@ h2v2_merged_upsample_565 (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
h2v2_merged_upsample_565D (j_decompress_ptr cinfo, h2v2_merged_upsample_565D(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
JSAMPARRAY output_buf)
{ {
if (is_big_endian()) if (is_big_endian())
h2v2_merged_upsample_565D_be(cinfo, input_buf, in_row_group_ctr, h2v2_merged_upsample_565D_be(cinfo, input_buf, in_row_group_ctr,
@ -574,14 +566,14 @@ h2v2_merged_upsample_565D (j_decompress_ptr cinfo,
*/ */
GLOBAL(void) GLOBAL(void)
jinit_merged_upsampler (j_decompress_ptr cinfo) jinit_merged_upsampler(j_decompress_ptr cinfo)
{ {
my_upsample_ptr upsample; my_upsample_ptr upsample;
upsample = (my_upsample_ptr) upsample = (my_upsample_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_upsampler)); sizeof(my_upsampler));
cinfo->upsample = (struct jpeg_upsampler *) upsample; cinfo->upsample = (struct jpeg_upsampler *)upsample;
upsample->pub.start_pass = start_pass_merged_upsample; upsample->pub.start_pass = start_pass_merged_upsample;
upsample->pub.need_context_rows = FALSE; upsample->pub.need_context_rows = FALSE;
@ -602,8 +594,8 @@ jinit_merged_upsampler (j_decompress_ptr cinfo)
} }
/* Allocate a spare row buffer */ /* Allocate a spare row buffer */
upsample->spare_row = (JSAMPROW) upsample->spare_row = (JSAMPROW)
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(size_t) (upsample->out_row_width * sizeof(JSAMPLE))); (size_t)(upsample->out_row_width * sizeof(JSAMPLE)));
} else { } else {
upsample->pub.upsample = merged_1v_upsample; upsample->pub.upsample = merged_1v_upsample;
if (jsimd_can_h2v1_merged_upsample()) if (jsimd_can_h2v1_merged_upsample())

View File

@ -5,7 +5,7 @@
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2013, Linaro Limited. * Copyright (C) 2013, Linaro Limited.
* Copyright (C) 2014-2015, D. R. Commander. * Copyright (C) 2014-2015, 2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@ -15,23 +15,22 @@
INLINE INLINE
LOCAL(void) LOCAL(void)
h2v1_merged_upsample_565_internal (j_decompress_ptr cinfo, h2v1_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf) JSAMPARRAY output_buf)
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue; register int y, cred, cgreen, cblue;
int cb, cr; int cb, cr;
register JSAMPROW outptr; register JSAMPROW outptr;
JSAMPROW inptr0, inptr1, inptr2; JSAMPROW inptr0, inptr1, inptr2;
JDIMENSION col; JDIMENSION col;
/* copy these pointers into registers if possible */ /* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit; register JSAMPLE *range_limit = cinfo->sample_range_limit;
int * Crrtab = upsample->Cr_r_tab; int *Crrtab = upsample->Cr_r_tab;
int * Cbbtab = upsample->Cb_b_tab; int *Cbbtab = upsample->Cb_b_tab;
JLONG * Crgtab = upsample->Cr_g_tab; JLONG *Crgtab = upsample->Cr_g_tab;
JLONG * Cbgtab = upsample->Cb_g_tab; JLONG *Cbgtab = upsample->Cb_g_tab;
unsigned int r, g, b; unsigned int r, g, b;
JLONG rgb; JLONG rgb;
SHIFT_TEMPS SHIFT_TEMPS
@ -47,7 +46,7 @@ h2v1_merged_upsample_565_internal (j_decompress_ptr cinfo,
cb = GETJSAMPLE(*inptr1++); cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++); cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
/* Fetch 2 Y values and emit 2 pixels */ /* Fetch 2 Y values and emit 2 pixels */
@ -72,37 +71,37 @@ h2v1_merged_upsample_565_internal (j_decompress_ptr cinfo,
cb = GETJSAMPLE(*inptr1); cb = GETJSAMPLE(*inptr1);
cr = GETJSAMPLE(*inptr2); cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
y = GETJSAMPLE(*inptr0); y = GETJSAMPLE(*inptr0);
r = range_limit[y + cred]; r = range_limit[y + cred];
g = range_limit[y + cgreen]; g = range_limit[y + cgreen];
b = range_limit[y + cblue]; b = range_limit[y + cblue];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
}
} }
}
INLINE INLINE
LOCAL(void) LOCAL(void)
h2v1_merged_upsample_565D_internal (j_decompress_ptr cinfo, h2v1_merged_upsample_565D_internal(j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf) JSAMPARRAY output_buf)
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue; register int y, cred, cgreen, cblue;
int cb, cr; int cb, cr;
register JSAMPROW outptr; register JSAMPROW outptr;
JSAMPROW inptr0, inptr1, inptr2; JSAMPROW inptr0, inptr1, inptr2;
JDIMENSION col; JDIMENSION col;
/* copy these pointers into registers if possible */ /* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit; register JSAMPLE *range_limit = cinfo->sample_range_limit;
int * Crrtab = upsample->Cr_r_tab; int *Crrtab = upsample->Cr_r_tab;
int * Cbbtab = upsample->Cb_b_tab; int *Cbbtab = upsample->Cb_b_tab;
JLONG * Crgtab = upsample->Cr_g_tab; JLONG *Crgtab = upsample->Cr_g_tab;
JLONG * Cbgtab = upsample->Cb_g_tab; JLONG *Cbgtab = upsample->Cb_g_tab;
JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK]; JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
unsigned int r, g, b; unsigned int r, g, b;
JLONG rgb; JLONG rgb;
@ -119,7 +118,7 @@ h2v1_merged_upsample_565D_internal (j_decompress_ptr cinfo,
cb = GETJSAMPLE(*inptr1++); cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++); cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
/* Fetch 2 Y values and emit 2 pixels */ /* Fetch 2 Y values and emit 2 pixels */
@ -146,37 +145,36 @@ h2v1_merged_upsample_565D_internal (j_decompress_ptr cinfo,
cb = GETJSAMPLE(*inptr1); cb = GETJSAMPLE(*inptr1);
cr = GETJSAMPLE(*inptr2); cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
y = GETJSAMPLE(*inptr0); y = GETJSAMPLE(*inptr0);
r = range_limit[DITHER_565_R(y + cred, d0)]; r = range_limit[DITHER_565_R(y + cred, d0)];
g = range_limit[DITHER_565_G(y + cgreen, d0)]; g = range_limit[DITHER_565_G(y + cgreen, d0)];
b = range_limit[DITHER_565_B(y + cblue, d0)]; b = range_limit[DITHER_565_B(y + cblue, d0)];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
} }
} }
INLINE INLINE
LOCAL(void) LOCAL(void)
h2v2_merged_upsample_565_internal (j_decompress_ptr cinfo, h2v2_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf) JSAMPARRAY output_buf)
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue; register int y, cred, cgreen, cblue;
int cb, cr; int cb, cr;
register JSAMPROW outptr0, outptr1; register JSAMPROW outptr0, outptr1;
JSAMPROW inptr00, inptr01, inptr1, inptr2; JSAMPROW inptr00, inptr01, inptr1, inptr2;
JDIMENSION col; JDIMENSION col;
/* copy these pointers into registers if possible */ /* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit; register JSAMPLE *range_limit = cinfo->sample_range_limit;
int * Crrtab = upsample->Cr_r_tab; int *Crrtab = upsample->Cr_r_tab;
int * Cbbtab = upsample->Cb_b_tab; int *Cbbtab = upsample->Cb_b_tab;
JLONG * Crgtab = upsample->Cr_g_tab; JLONG *Crgtab = upsample->Cr_g_tab;
JLONG * Cbgtab = upsample->Cb_g_tab; JLONG *Cbgtab = upsample->Cb_g_tab;
unsigned int r, g, b; unsigned int r, g, b;
JLONG rgb; JLONG rgb;
SHIFT_TEMPS SHIFT_TEMPS
@ -194,7 +192,7 @@ h2v2_merged_upsample_565_internal (j_decompress_ptr cinfo,
cb = GETJSAMPLE(*inptr1++); cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++); cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
/* Fetch 4 Y values and emit 4 pixels */ /* Fetch 4 Y values and emit 4 pixels */
@ -234,7 +232,7 @@ h2v2_merged_upsample_565_internal (j_decompress_ptr cinfo,
cb = GETJSAMPLE(*inptr1); cb = GETJSAMPLE(*inptr1);
cr = GETJSAMPLE(*inptr2); cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
y = GETJSAMPLE(*inptr00); y = GETJSAMPLE(*inptr00);
@ -242,45 +240,45 @@ h2v2_merged_upsample_565_internal (j_decompress_ptr cinfo,
g = range_limit[y + cgreen]; g = range_limit[y + cgreen];
b = range_limit[y + cblue]; b = range_limit[y + cblue];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr0 = (INT16)rgb; *(INT16 *)outptr0 = (INT16)rgb;
y = GETJSAMPLE(*inptr01); y = GETJSAMPLE(*inptr01);
r = range_limit[y + cred]; r = range_limit[y + cred];
g = range_limit[y + cgreen]; g = range_limit[y + cgreen];
b = range_limit[y + cblue]; b = range_limit[y + cblue];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr1 = (INT16)rgb; *(INT16 *)outptr1 = (INT16)rgb;
} }
} }
INLINE INLINE
LOCAL(void) LOCAL(void)
h2v2_merged_upsample_565D_internal (j_decompress_ptr cinfo, h2v2_merged_upsample_565D_internal(j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf) JSAMPARRAY output_buf)
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue; register int y, cred, cgreen, cblue;
int cb, cr; int cb, cr;
register JSAMPROW outptr0, outptr1; register JSAMPROW outptr0, outptr1;
JSAMPROW inptr00, inptr01, inptr1, inptr2; JSAMPROW inptr00, inptr01, inptr1, inptr2;
JDIMENSION col; JDIMENSION col;
/* copy these pointers into registers if possible */ /* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit; register JSAMPLE *range_limit = cinfo->sample_range_limit;
int * Crrtab = upsample->Cr_r_tab; int *Crrtab = upsample->Cr_r_tab;
int * Cbbtab = upsample->Cb_b_tab; int *Cbbtab = upsample->Cb_b_tab;
JLONG * Crgtab = upsample->Cr_g_tab; JLONG *Crgtab = upsample->Cr_g_tab;
JLONG * Cbgtab = upsample->Cb_g_tab; JLONG *Cbgtab = upsample->Cb_g_tab;
JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK]; JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
JLONG d1 = dither_matrix[(cinfo->output_scanline+1) & DITHER_MASK]; JLONG d1 = dither_matrix[(cinfo->output_scanline + 1) & DITHER_MASK];
unsigned int r, g, b; unsigned int r, g, b;
JLONG rgb; JLONG rgb;
SHIFT_TEMPS SHIFT_TEMPS
inptr00 = input_buf[0][in_row_group_ctr*2]; inptr00 = input_buf[0][in_row_group_ctr * 2];
inptr01 = input_buf[0][in_row_group_ctr*2 + 1]; inptr01 = input_buf[0][in_row_group_ctr * 2 + 1];
inptr1 = input_buf[1][in_row_group_ctr]; inptr1 = input_buf[1][in_row_group_ctr];
inptr2 = input_buf[2][in_row_group_ctr]; inptr2 = input_buf[2][in_row_group_ctr];
outptr0 = output_buf[0]; outptr0 = output_buf[0];
@ -292,7 +290,7 @@ h2v2_merged_upsample_565D_internal (j_decompress_ptr cinfo,
cb = GETJSAMPLE(*inptr1++); cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++); cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
/* Fetch 4 Y values and emit 4 pixels */ /* Fetch 4 Y values and emit 4 pixels */
@ -304,20 +302,20 @@ h2v2_merged_upsample_565D_internal (j_decompress_ptr cinfo,
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
y = GETJSAMPLE(*inptr00++); y = GETJSAMPLE(*inptr00++);
r = range_limit[DITHER_565_R(y + cred, d1)]; r = range_limit[DITHER_565_R(y + cred, d0)];
g = range_limit[DITHER_565_G(y + cgreen, d1)]; g = range_limit[DITHER_565_G(y + cgreen, d0)];
b = range_limit[DITHER_565_B(y + cblue, d1)]; b = range_limit[DITHER_565_B(y + cblue, d0)];
d1 = DITHER_ROTATE(d1); d0 = DITHER_ROTATE(d0);
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b)); rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
WRITE_TWO_PIXELS(outptr0, rgb); WRITE_TWO_PIXELS(outptr0, rgb);
outptr0 += 4; outptr0 += 4;
y = GETJSAMPLE(*inptr01++); y = GETJSAMPLE(*inptr01++);
r = range_limit[DITHER_565_R(y + cred, d0)]; r = range_limit[DITHER_565_R(y + cred, d1)];
g = range_limit[DITHER_565_G(y + cgreen, d0)]; g = range_limit[DITHER_565_G(y + cgreen, d1)];
b = range_limit[DITHER_565_B(y + cblue, d0)]; b = range_limit[DITHER_565_B(y + cblue, d1)];
d0 = DITHER_ROTATE(d0); d1 = DITHER_ROTATE(d1);
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
y = GETJSAMPLE(*inptr01++); y = GETJSAMPLE(*inptr01++);
@ -336,7 +334,7 @@ h2v2_merged_upsample_565D_internal (j_decompress_ptr cinfo,
cb = GETJSAMPLE(*inptr1); cb = GETJSAMPLE(*inptr1);
cr = GETJSAMPLE(*inptr2); cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
y = GETJSAMPLE(*inptr00); y = GETJSAMPLE(*inptr00);
@ -344,13 +342,13 @@ h2v2_merged_upsample_565D_internal (j_decompress_ptr cinfo,
g = range_limit[DITHER_565_G(y + cgreen, d0)]; g = range_limit[DITHER_565_G(y + cgreen, d0)];
b = range_limit[DITHER_565_B(y + cblue, d0)]; b = range_limit[DITHER_565_B(y + cblue, d0)];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr0 = (INT16)rgb; *(INT16 *)outptr0 = (INT16)rgb;
y = GETJSAMPLE(*inptr01); y = GETJSAMPLE(*inptr01);
r = range_limit[DITHER_565_R(y + cred, d1)]; r = range_limit[DITHER_565_R(y + cred, d1)];
g = range_limit[DITHER_565_G(y + cgreen, d1)]; g = range_limit[DITHER_565_G(y + cgreen, d1)];
b = range_limit[DITHER_565_B(y + cblue, d1)]; b = range_limit[DITHER_565_B(y + cblue, d1)];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr1 = (INT16)rgb; *(INT16 *)outptr1 = (INT16)rgb;
} }
} }

View File

@ -21,23 +21,22 @@
INLINE INLINE
LOCAL(void) LOCAL(void)
h2v1_merged_upsample_internal (j_decompress_ptr cinfo, h2v1_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf) JSAMPARRAY output_buf)
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue; register int y, cred, cgreen, cblue;
int cb, cr; int cb, cr;
register JSAMPROW outptr; register JSAMPROW outptr;
JSAMPROW inptr0, inptr1, inptr2; JSAMPROW inptr0, inptr1, inptr2;
JDIMENSION col; JDIMENSION col;
/* copy these pointers into registers if possible */ /* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit; register JSAMPLE *range_limit = cinfo->sample_range_limit;
int * Crrtab = upsample->Cr_r_tab; int *Crrtab = upsample->Cr_r_tab;
int * Cbbtab = upsample->Cb_b_tab; int *Cbbtab = upsample->Cb_b_tab;
JLONG * Crgtab = upsample->Cr_g_tab; JLONG *Crgtab = upsample->Cr_g_tab;
JLONG * Cbgtab = upsample->Cb_g_tab; JLONG *Cbgtab = upsample->Cb_g_tab;
SHIFT_TEMPS SHIFT_TEMPS
inptr0 = input_buf[0][in_row_group_ctr]; inptr0 = input_buf[0][in_row_group_ctr];
@ -50,7 +49,7 @@ h2v1_merged_upsample_internal (j_decompress_ptr cinfo,
cb = GETJSAMPLE(*inptr1++); cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++); cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
/* Fetch 2 Y values and emit 2 pixels */ /* Fetch 2 Y values and emit 2 pixels */
y = GETJSAMPLE(*inptr0++); y = GETJSAMPLE(*inptr0++);
@ -75,7 +74,7 @@ h2v1_merged_upsample_internal (j_decompress_ptr cinfo,
cb = GETJSAMPLE(*inptr1); cb = GETJSAMPLE(*inptr1);
cr = GETJSAMPLE(*inptr2); cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
y = GETJSAMPLE(*inptr0); y = GETJSAMPLE(*inptr0);
outptr[RGB_RED] = range_limit[y + cred]; outptr[RGB_RED] = range_limit[y + cred];
@ -94,27 +93,26 @@ h2v1_merged_upsample_internal (j_decompress_ptr cinfo,
INLINE INLINE
LOCAL(void) LOCAL(void)
h2v2_merged_upsample_internal (j_decompress_ptr cinfo, h2v2_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf) JSAMPARRAY output_buf)
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue; register int y, cred, cgreen, cblue;
int cb, cr; int cb, cr;
register JSAMPROW outptr0, outptr1; register JSAMPROW outptr0, outptr1;
JSAMPROW inptr00, inptr01, inptr1, inptr2; JSAMPROW inptr00, inptr01, inptr1, inptr2;
JDIMENSION col; JDIMENSION col;
/* copy these pointers into registers if possible */ /* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit; register JSAMPLE *range_limit = cinfo->sample_range_limit;
int * Crrtab = upsample->Cr_r_tab; int *Crrtab = upsample->Cr_r_tab;
int * Cbbtab = upsample->Cb_b_tab; int *Cbbtab = upsample->Cb_b_tab;
JLONG * Crgtab = upsample->Cr_g_tab; JLONG *Crgtab = upsample->Cr_g_tab;
JLONG * Cbgtab = upsample->Cb_g_tab; JLONG *Cbgtab = upsample->Cb_g_tab;
SHIFT_TEMPS SHIFT_TEMPS
inptr00 = input_buf[0][in_row_group_ctr*2]; inptr00 = input_buf[0][in_row_group_ctr * 2];
inptr01 = input_buf[0][in_row_group_ctr*2 + 1]; inptr01 = input_buf[0][in_row_group_ctr * 2 + 1];
inptr1 = input_buf[1][in_row_group_ctr]; inptr1 = input_buf[1][in_row_group_ctr];
inptr2 = input_buf[2][in_row_group_ctr]; inptr2 = input_buf[2][in_row_group_ctr];
outptr0 = output_buf[0]; outptr0 = output_buf[0];
@ -125,7 +123,7 @@ h2v2_merged_upsample_internal (j_decompress_ptr cinfo,
cb = GETJSAMPLE(*inptr1++); cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++); cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
/* Fetch 4 Y values and emit 4 pixels */ /* Fetch 4 Y values and emit 4 pixels */
y = GETJSAMPLE(*inptr00++); y = GETJSAMPLE(*inptr00++);
@ -166,7 +164,7 @@ h2v2_merged_upsample_internal (j_decompress_ptr cinfo,
cb = GETJSAMPLE(*inptr1); cb = GETJSAMPLE(*inptr1);
cr = GETJSAMPLE(*inptr2); cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
y = GETJSAMPLE(*inptr00); y = GETJSAMPLE(*inptr00);
outptr0[RGB_RED] = range_limit[y + cred]; outptr0[RGB_RED] = range_limit[y + cred];

View File

@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1995-1997, Thomas G. Lane. * Copyright (C) 1995-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2015-2016, D. R. Commander. * Copyright (C) 2015-2016, 2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@ -15,12 +15,16 @@
* up to the start of the current MCU. To do this, we copy state variables * up to the start of the current MCU. To do this, we copy state variables
* into local working storage, and update them back to the permanent * into local working storage, and update them back to the permanent
* storage only upon successful completion of an MCU. * storage only upon successful completion of an MCU.
*
* NOTE: All referenced figures are from
* Recommendation ITU-T T.81 (1992) | ISO/IEC 10918-1:1994.
*/ */
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdhuff.h" /* Declarations shared with jdhuff.c */ #include "jdhuff.h" /* Declarations shared with jdhuff.c */
#include <limits.h>
#ifdef D_PROGRESSIVE_SUPPORTED #ifdef D_PROGRESSIVE_SUPPORTED
@ -43,10 +47,10 @@ typedef struct {
*/ */
#ifndef NO_STRUCT_ASSIGN #ifndef NO_STRUCT_ASSIGN
#define ASSIGN_STATE(dest,src) ((dest) = (src)) #define ASSIGN_STATE(dest, src) ((dest) = (src))
#else #else
#if MAX_COMPS_IN_SCAN == 4 #if MAX_COMPS_IN_SCAN == 4
#define ASSIGN_STATE(dest,src) \ #define ASSIGN_STATE(dest, src) \
((dest).EOBRUN = (src).EOBRUN, \ ((dest).EOBRUN = (src).EOBRUN, \
(dest).last_dc_val[0] = (src).last_dc_val[0], \ (dest).last_dc_val[0] = (src).last_dc_val[0], \
(dest).last_dc_val[1] = (src).last_dc_val[1], \ (dest).last_dc_val[1] = (src).last_dc_val[1], \
@ -77,13 +81,13 @@ typedef struct {
typedef phuff_entropy_decoder *phuff_entropy_ptr; typedef phuff_entropy_decoder *phuff_entropy_ptr;
/* Forward declarations */ /* Forward declarations */
METHODDEF(boolean) decode_mcu_DC_first (j_decompress_ptr cinfo, METHODDEF(boolean) decode_mcu_DC_first(j_decompress_ptr cinfo,
JBLOCKROW *MCU_data); JBLOCKROW *MCU_data);
METHODDEF(boolean) decode_mcu_AC_first (j_decompress_ptr cinfo, METHODDEF(boolean) decode_mcu_AC_first(j_decompress_ptr cinfo,
JBLOCKROW *MCU_data); JBLOCKROW *MCU_data);
METHODDEF(boolean) decode_mcu_DC_refine (j_decompress_ptr cinfo, METHODDEF(boolean) decode_mcu_DC_refine(j_decompress_ptr cinfo,
JBLOCKROW *MCU_data); JBLOCKROW *MCU_data);
METHODDEF(boolean) decode_mcu_AC_refine (j_decompress_ptr cinfo, METHODDEF(boolean) decode_mcu_AC_refine(j_decompress_ptr cinfo,
JBLOCKROW *MCU_data); JBLOCKROW *MCU_data);
@ -92,9 +96,9 @@ METHODDEF(boolean) decode_mcu_AC_refine (j_decompress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_phuff_decoder (j_decompress_ptr cinfo) start_pass_phuff_decoder(j_decompress_ptr cinfo)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy;
boolean is_DC_band, bad; boolean is_DC_band, bad;
int ci, coefi, tbl; int ci, coefi, tbl;
d_derived_tbl **pdtbl; d_derived_tbl **pdtbl;
@ -118,7 +122,7 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo)
} }
if (cinfo->Ah != 0) { if (cinfo->Ah != 0) {
/* Successive approximation refinement scan: must have Al = Ah-1. */ /* Successive approximation refinement scan: must have Al = Ah-1. */
if (cinfo->Al != cinfo->Ah-1) if (cinfo->Al != cinfo->Ah - 1)
bad = TRUE; bad = TRUE;
} }
if (cinfo->Al > 13) /* need not check for < 0 */ if (cinfo->Al > 13) /* need not check for < 0 */
@ -138,7 +142,7 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo)
*/ */
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
int cindex = cinfo->cur_comp_info[ci]->component_index; int cindex = cinfo->cur_comp_info[ci]->component_index;
coef_bit_ptr = & cinfo->coef_bits[cindex][0]; coef_bit_ptr = &cinfo->coef_bits[cindex][0];
if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */ if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0); WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) { for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
@ -206,21 +210,25 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo)
#ifdef AVOID_TABLES #ifdef AVOID_TABLES
#define NEG_1 ((unsigned)-1) #define NEG_1 ((unsigned)-1)
#define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((NEG_1)<<(s)) + 1) : (x)) #define HUFF_EXTEND(x, s) \
((x) < (1 << ((s) - 1)) ? (x) + (((NEG_1) << (s)) + 1) : (x))
#else #else
#define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x)) #define HUFF_EXTEND(x, s) \
((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
static const int extend_test[16] = /* entry n is 2**(n-1) */ static const int extend_test[16] = { /* entry n is 2**(n-1) */
{ 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 }; 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000
};
static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */ static const int extend_offset[16] = { /* entry n is (-1 << n) + 1 */
{ 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, 0, ((-1) << 1) + 1, ((-1) << 2) + 1, ((-1) << 3) + 1, ((-1) << 4) + 1,
((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, ((-1) << 5) + 1, ((-1) << 6) + 1, ((-1) << 7) + 1, ((-1) << 8) + 1,
((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, ((-1) << 9) + 1, ((-1) << 10) + 1, ((-1) << 11) + 1, ((-1) << 12) + 1,
((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 }; ((-1) << 13) + 1, ((-1) << 14) + 1, ((-1) << 15) + 1
};
#endif /* AVOID_TABLES */ #endif /* AVOID_TABLES */
@ -231,9 +239,9 @@ static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
*/ */
LOCAL(boolean) LOCAL(boolean)
process_restart (j_decompress_ptr cinfo) process_restart(j_decompress_ptr cinfo)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy;
int ci; int ci;
/* Throw away any unused bits remaining in bit buffer; */ /* Throw away any unused bits remaining in bit buffer; */
@ -242,7 +250,7 @@ process_restart (j_decompress_ptr cinfo)
entropy->bitstate.bits_left = 0; entropy->bitstate.bits_left = 0;
/* Advance past the RSTn marker */ /* Advance past the RSTn marker */
if (! (*cinfo->marker->read_restart_marker) (cinfo)) if (!(*cinfo->marker->read_restart_marker) (cinfo))
return FALSE; return FALSE;
/* Re-initialize DC predictions to 0 */ /* Re-initialize DC predictions to 0 */
@ -289,9 +297,9 @@ process_restart (j_decompress_ptr cinfo)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_DC_first(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy;
int Al = cinfo->Al; int Al = cinfo->Al;
register int s, r; register int s, r;
int blkn, ci; int blkn, ci;
@ -304,17 +312,17 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Process restart marker if needed; may have to suspend */ /* Process restart marker if needed; may have to suspend */
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
if (entropy->restarts_to_go == 0) if (entropy->restarts_to_go == 0)
if (! process_restart(cinfo)) if (!process_restart(cinfo))
return FALSE; return FALSE;
} }
/* If we've run out of data, just leave the MCU set to zeroes. /* If we've run out of data, just leave the MCU set to zeroes.
* This way, we return uniform gray for the remainder of the segment. * This way, we return uniform gray for the remainder of the segment.
*/ */
if (! entropy->pub.insufficient_data) { if (!entropy->pub.insufficient_data) {
/* Load up working state */ /* Load up working state */
BITREAD_LOAD_STATE(cinfo,entropy->bitstate); BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
ASSIGN_STATE(state, entropy->saved); ASSIGN_STATE(state, entropy->saved);
/* Outer loop handles each block in the MCU */ /* Outer loop handles each block in the MCU */
@ -336,14 +344,18 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/* Convert DC difference to actual value, update last_dc_val */ /* Convert DC difference to actual value, update last_dc_val */
if ((state.last_dc_val[ci] >= 0 &&
s > INT_MAX - state.last_dc_val[ci]) ||
(state.last_dc_val[ci] < 0 && s < INT_MIN - state.last_dc_val[ci]))
ERREXIT(cinfo, JERR_BAD_DCT_COEF);
s += state.last_dc_val[ci]; s += state.last_dc_val[ci];
state.last_dc_val[ci] = s; state.last_dc_val[ci] = s;
/* Scale and output the coefficient (assumes jpeg_natural_order[0]=0) */ /* Scale and output the coefficient (assumes jpeg_natural_order[0]=0) */
(*block)[0] = (JCOEF) LEFT_SHIFT(s, Al); (*block)[0] = (JCOEF)LEFT_SHIFT(s, Al);
} }
/* Completed MCU, so update state */ /* Completed MCU, so update state */
BITREAD_SAVE_STATE(cinfo,entropy->bitstate); BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
ASSIGN_STATE(entropy->saved, state); ASSIGN_STATE(entropy->saved, state);
} }
@ -360,9 +372,9 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_AC_first(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy;
int Se = cinfo->Se; int Se = cinfo->Se;
int Al = cinfo->Al; int Al = cinfo->Al;
register int s, k, r; register int s, k, r;
@ -374,14 +386,14 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Process restart marker if needed; may have to suspend */ /* Process restart marker if needed; may have to suspend */
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
if (entropy->restarts_to_go == 0) if (entropy->restarts_to_go == 0)
if (! process_restart(cinfo)) if (!process_restart(cinfo))
return FALSE; return FALSE;
} }
/* If we've run out of data, just leave the MCU set to zeroes. /* If we've run out of data, just leave the MCU set to zeroes.
* This way, we return uniform gray for the remainder of the segment. * This way, we return uniform gray for the remainder of the segment.
*/ */
if (! entropy->pub.insufficient_data) { if (!entropy->pub.insufficient_data) {
/* 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.
@ -393,7 +405,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (EOBRUN > 0) /* if it's a band of zeroes... */ if (EOBRUN > 0) /* if it's a band of zeroes... */
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);
block = MCU_data[0]; block = MCU_data[0];
tbl = entropy->ac_derived_tbl; tbl = entropy->ac_derived_tbl;
@ -407,7 +419,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
r = GET_BITS(s); r = GET_BITS(s);
s = HUFF_EXTEND(r, s); s = HUFF_EXTEND(r, s);
/* Scale and output coefficient in natural (dezigzagged) order */ /* Scale and output coefficient in natural (dezigzagged) order */
(*block)[jpeg_natural_order[k]] = (JCOEF) LEFT_SHIFT(s, Al); (*block)[jpeg_natural_order[k]] = (JCOEF)LEFT_SHIFT(s, Al);
} else { } else {
if (r == 15) { /* ZRL */ if (r == 15) { /* ZRL */
k += 15; /* skip 15 zeroes in band */ k += 15; /* skip 15 zeroes in band */
@ -424,7 +436,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
} }
BITREAD_SAVE_STATE(cinfo,entropy->bitstate); BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
} }
/* Completed MCU, so update state */ /* Completed MCU, so update state */
@ -445,9 +457,9 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_DC_refine(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy;
int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
int blkn; int blkn;
JBLOCKROW block; JBLOCKROW block;
@ -456,7 +468,7 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Process restart marker if needed; may have to suspend */ /* Process restart marker if needed; may have to suspend */
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
if (entropy->restarts_to_go == 0) if (entropy->restarts_to_go == 0)
if (! process_restart(cinfo)) if (!process_restart(cinfo))
return FALSE; return FALSE;
} }
@ -465,7 +477,7 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
/* Load up working state */ /* Load up working state */
BITREAD_LOAD_STATE(cinfo,entropy->bitstate); BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
/* Outer loop handles each block in the MCU */ /* Outer loop handles each block in the MCU */
@ -480,7 +492,7 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/* Completed MCU, so update state */ /* Completed MCU, so update state */
BITREAD_SAVE_STATE(cinfo,entropy->bitstate); BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
/* Account for restart interval (no-op if not using restarts) */ /* Account for restart interval (no-op if not using restarts) */
entropy->restarts_to_go--; entropy->restarts_to_go--;
@ -494,9 +506,9 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_AC_refine(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy;
int Se = cinfo->Se; int Se = cinfo->Se;
int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
int m1 = (NEG_1) << cinfo->Al; /* -1 in the bit position being coded */ int m1 = (NEG_1) << cinfo->Al; /* -1 in the bit position being coded */
@ -512,16 +524,16 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Process restart marker if needed; may have to suspend */ /* Process restart marker if needed; may have to suspend */
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
if (entropy->restarts_to_go == 0) if (entropy->restarts_to_go == 0)
if (! process_restart(cinfo)) if (!process_restart(cinfo))
return FALSE; return FALSE;
} }
/* If we've run out of data, don't modify the MCU. /* If we've run out of data, don't modify the MCU.
*/ */
if (! entropy->pub.insufficient_data) { if (!entropy->pub.insufficient_data) {
/* Load up working state */ /* Load up working state */
BITREAD_LOAD_STATE(cinfo,entropy->bitstate); BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */ EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
/* There is always only one block per MCU */ /* There is always only one block per MCU */
@ -589,7 +601,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (s) { if (s) {
int pos = jpeg_natural_order[k]; int pos = jpeg_natural_order[k];
/* Output newly nonzero coefficient */ /* Output newly nonzero coefficient */
(*block)[pos] = (JCOEF) s; (*block)[pos] = (JCOEF)s;
/* Remember its position in case we have to suspend */ /* Remember its position in case we have to suspend */
newnz_pos[num_newnz++] = pos; newnz_pos[num_newnz++] = pos;
} }
@ -621,7 +633,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/* Completed MCU, so update state */ /* Completed MCU, so update state */
BITREAD_SAVE_STATE(cinfo,entropy->bitstate); BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */ entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
} }
@ -644,16 +656,16 @@ undoit:
*/ */
GLOBAL(void) GLOBAL(void)
jinit_phuff_decoder (j_decompress_ptr cinfo) jinit_phuff_decoder(j_decompress_ptr cinfo)
{ {
phuff_entropy_ptr entropy; phuff_entropy_ptr entropy;
int *coef_bit_ptr; int *coef_bit_ptr;
int ci, i; int ci, i;
entropy = (phuff_entropy_ptr) entropy = (phuff_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(phuff_entropy_decoder)); sizeof(phuff_entropy_decoder));
cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; cinfo->entropy = (struct jpeg_entropy_decoder *)entropy;
entropy->pub.start_pass = start_pass_phuff_decoder; entropy->pub.start_pass = start_pass_phuff_decoder;
/* Mark derived tables unallocated */ /* Mark derived tables unallocated */
@ -663,9 +675,10 @@ jinit_phuff_decoder (j_decompress_ptr cinfo)
/* Create progression status table */ /* Create progression status table */
cinfo->coef_bits = (int (*)[DCTSIZE2]) cinfo->coef_bits = (int (*)[DCTSIZE2])
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
cinfo->num_components*DCTSIZE2*sizeof(int)); cinfo->num_components * DCTSIZE2 *
coef_bit_ptr = & cinfo->coef_bits[0][0]; sizeof(int));
coef_bit_ptr = &cinfo->coef_bits[0][0];
for (ci = 0; ci < cinfo->num_components; ci++) for (ci = 0; ci < cinfo->num_components; ci++)
for (i = 0; i < DCTSIZE2; i++) for (i = 0; i < DCTSIZE2; i++)
*coef_bit_ptr++ = -1; *coef_bit_ptr++ = -1;

View File

@ -46,21 +46,27 @@ typedef my_post_controller *my_post_ptr;
/* Forward declarations */ /* Forward declarations */
METHODDEF(void) post_process_1pass METHODDEF(void) post_process_1pass(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail, JDIMENSION *in_row_group_ctr,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail); JDIMENSION out_rows_avail);
#ifdef QUANT_2PASS_SUPPORTED #ifdef QUANT_2PASS_SUPPORTED
METHODDEF(void) post_process_prepass METHODDEF(void) post_process_prepass(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail, JDIMENSION *in_row_group_ctr,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail); JDIMENSION out_rows_avail);
METHODDEF(void) post_process_2pass METHODDEF(void) post_process_2pass(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail, JDIMENSION *in_row_group_ctr,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail); JDIMENSION out_rows_avail);
#endif #endif
@ -70,9 +76,9 @@ METHODDEF(void) post_process_2pass
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode) start_pass_dpost(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
{ {
my_post_ptr post = (my_post_ptr) cinfo->post; my_post_ptr post = (my_post_ptr)cinfo->post;
switch (pass_mode) { switch (pass_mode) {
case JBUF_PASS_THRU: case JBUF_PASS_THRU:
@ -85,8 +91,8 @@ start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
*/ */
if (post->buffer == NULL) { if (post->buffer == NULL) {
post->buffer = (*cinfo->mem->access_virt_sarray) post->buffer = (*cinfo->mem->access_virt_sarray)
((j_common_ptr) cinfo, post->whole_image, ((j_common_ptr)cinfo, post->whole_image,
(JDIMENSION) 0, post->strip_height, TRUE); (JDIMENSION)0, post->strip_height, TRUE);
} }
} else { } else {
/* For single-pass processing without color quantization, /* For single-pass processing without color quantization,
@ -123,13 +129,12 @@ start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
*/ */
METHODDEF(void) METHODDEF(void)
post_process_1pass (j_decompress_ptr cinfo, post_process_1pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
JDIMENSION out_rows_avail)
{ {
my_post_ptr post = (my_post_ptr) cinfo->post; my_post_ptr post = (my_post_ptr)cinfo->post;
JDIMENSION num_rows, max_rows; JDIMENSION num_rows, max_rows;
/* Fill the buffer, but not more than what we can dump out in one go. */ /* Fill the buffer, but not more than what we can dump out in one go. */
@ -138,12 +143,13 @@ post_process_1pass (j_decompress_ptr cinfo,
if (max_rows > post->strip_height) if (max_rows > post->strip_height)
max_rows = post->strip_height; max_rows = post->strip_height;
num_rows = 0; num_rows = 0;
(*cinfo->upsample->upsample) (cinfo, (*cinfo->upsample->upsample) (cinfo, input_buf, in_row_group_ctr,
input_buf, in_row_group_ctr, in_row_groups_avail, in_row_groups_avail, post->buffer, &num_rows,
post->buffer, &num_rows, max_rows); max_rows);
/* Quantize and emit data. */ /* Quantize and emit data. */
(*cinfo->cquantize->color_quantize) (cinfo, (*cinfo->cquantize->color_quantize) (cinfo, post->buffer,
post->buffer, output_buf + *out_row_ctr, (int) num_rows); output_buf + *out_row_ctr,
(int)num_rows);
*out_row_ctr += num_rows; *out_row_ctr += num_rows;
} }
@ -155,34 +161,33 @@ post_process_1pass (j_decompress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
post_process_prepass (j_decompress_ptr cinfo, post_process_prepass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
JDIMENSION out_rows_avail)
{ {
my_post_ptr post = (my_post_ptr) cinfo->post; my_post_ptr post = (my_post_ptr)cinfo->post;
JDIMENSION old_next_row, num_rows; JDIMENSION old_next_row, num_rows;
/* Reposition virtual buffer if at start of strip. */ /* Reposition virtual buffer if at start of strip. */
if (post->next_row == 0) { if (post->next_row == 0) {
post->buffer = (*cinfo->mem->access_virt_sarray) post->buffer = (*cinfo->mem->access_virt_sarray)
((j_common_ptr) cinfo, post->whole_image, ((j_common_ptr)cinfo, post->whole_image,
post->starting_row, post->strip_height, TRUE); post->starting_row, post->strip_height, TRUE);
} }
/* Upsample some data (up to a strip height's worth). */ /* Upsample some data (up to a strip height's worth). */
old_next_row = post->next_row; old_next_row = post->next_row;
(*cinfo->upsample->upsample) (cinfo, (*cinfo->upsample->upsample) (cinfo, input_buf, in_row_group_ctr,
input_buf, in_row_group_ctr, in_row_groups_avail, in_row_groups_avail, post->buffer,
post->buffer, &post->next_row, post->strip_height); &post->next_row, post->strip_height);
/* Allow quantizer to scan new data. No data is emitted, */ /* Allow quantizer to scan new data. No data is emitted, */
/* but we advance out_row_ctr so outer loop can tell when we're done. */ /* but we advance out_row_ctr so outer loop can tell when we're done. */
if (post->next_row > old_next_row) { if (post->next_row > old_next_row) {
num_rows = post->next_row - old_next_row; num_rows = post->next_row - old_next_row;
(*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row, (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
(JSAMPARRAY) NULL, (int) num_rows); (JSAMPARRAY)NULL, (int)num_rows);
*out_row_ctr += num_rows; *out_row_ctr += num_rows;
} }
@ -199,19 +204,18 @@ post_process_prepass (j_decompress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
post_process_2pass (j_decompress_ptr cinfo, post_process_2pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
JDIMENSION out_rows_avail)
{ {
my_post_ptr post = (my_post_ptr) cinfo->post; my_post_ptr post = (my_post_ptr)cinfo->post;
JDIMENSION num_rows, max_rows; JDIMENSION num_rows, max_rows;
/* Reposition virtual buffer if at start of strip. */ /* Reposition virtual buffer if at start of strip. */
if (post->next_row == 0) { if (post->next_row == 0) {
post->buffer = (*cinfo->mem->access_virt_sarray) post->buffer = (*cinfo->mem->access_virt_sarray)
((j_common_ptr) cinfo, post->whole_image, ((j_common_ptr)cinfo, post->whole_image,
post->starting_row, post->strip_height, FALSE); post->starting_row, post->strip_height, FALSE);
} }
@ -226,9 +230,9 @@ post_process_2pass (j_decompress_ptr cinfo,
num_rows = max_rows; num_rows = max_rows;
/* Quantize and emit data. */ /* Quantize and emit data. */
(*cinfo->cquantize->color_quantize) (cinfo, (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + post->next_row,
post->buffer + post->next_row, output_buf + *out_row_ctr, output_buf + *out_row_ctr,
(int) num_rows); (int)num_rows);
*out_row_ctr += num_rows; *out_row_ctr += num_rows;
/* Advance if we filled the strip. */ /* Advance if we filled the strip. */
@ -247,14 +251,14 @@ post_process_2pass (j_decompress_ptr cinfo,
*/ */
GLOBAL(void) GLOBAL(void)
jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer) jinit_d_post_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
{ {
my_post_ptr post; my_post_ptr post;
post = (my_post_ptr) post = (my_post_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_post_controller)); sizeof(my_post_controller));
cinfo->post = (struct jpeg_d_post_controller *) post; cinfo->post = (struct jpeg_d_post_controller *)post;
post->pub.start_pass = start_pass_dpost; post->pub.start_pass = start_pass_dpost;
post->whole_image = NULL; /* flag for no virtual arrays */ post->whole_image = NULL; /* flag for no virtual arrays */
post->buffer = NULL; /* flag for no strip buffer */ post->buffer = NULL; /* flag for no strip buffer */
@ -265,16 +269,16 @@ jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
* an efficient number of rows for upsampling to return. * an efficient number of rows for upsampling to return.
* (In the presence of output rescaling, we might want to be smarter?) * (In the presence of output rescaling, we might want to be smarter?)
*/ */
post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor; post->strip_height = (JDIMENSION)cinfo->max_v_samp_factor;
if (need_full_buffer) { if (need_full_buffer) {
/* Two-pass color quantization: need full-image storage. */ /* Two-pass color quantization: need full-image storage. */
/* We round up the number of rows to a multiple of the strip height. */ /* We round up the number of rows to a multiple of the strip height. */
#ifdef QUANT_2PASS_SUPPORTED #ifdef QUANT_2PASS_SUPPORTED
post->whole_image = (*cinfo->mem->request_virt_sarray) post->whole_image = (*cinfo->mem->request_virt_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
cinfo->output_width * cinfo->out_color_components, cinfo->output_width * cinfo->out_color_components,
(JDIMENSION) jround_up((long) cinfo->output_height, (JDIMENSION)jround_up((long)cinfo->output_height,
(long) post->strip_height), (long)post->strip_height),
post->strip_height); post->strip_height);
#else #else
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
@ -282,7 +286,7 @@ jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
} else { } else {
/* One-pass color quantization: just make a strip buffer. */ /* One-pass color quantization: just make a strip buffer. */
post->buffer = (*cinfo->mem->alloc_sarray) post->buffer = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr)cinfo, JPOOL_IMAGE,
cinfo->output_width * cinfo->out_color_components, cinfo->output_width * cinfo->out_color_components,
post->strip_height); post->strip_height);
} }

View File

@ -36,9 +36,9 @@
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_upsample (j_decompress_ptr cinfo) start_pass_upsample(j_decompress_ptr cinfo)
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
/* Mark the conversion buffer empty */ /* Mark the conversion buffer empty */
upsample->next_row_out = cinfo->max_v_samp_factor; upsample->next_row_out = cinfo->max_v_samp_factor;
@ -56,13 +56,12 @@ start_pass_upsample (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
sep_upsample (j_decompress_ptr cinfo, sep_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail,
JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail) JDIMENSION out_rows_avail)
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
int ci; int ci;
jpeg_component_info *compptr; jpeg_component_info *compptr;
JDIMENSION num_rows; JDIMENSION num_rows;
@ -84,7 +83,7 @@ sep_upsample (j_decompress_ptr cinfo,
/* Color-convert and emit rows */ /* Color-convert and emit rows */
/* How many we have in the buffer: */ /* How many we have in the buffer: */
num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out); num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
/* Not more than the distance to the end of the image. Need this test /* Not more than the distance to the end of the image. Need this test
* in case the image height is not a multiple of max_v_samp_factor: * in case the image height is not a multiple of max_v_samp_factor:
*/ */
@ -96,9 +95,8 @@ sep_upsample (j_decompress_ptr cinfo,
num_rows = out_rows_avail; num_rows = out_rows_avail;
(*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf, (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
(JDIMENSION) upsample->next_row_out, (JDIMENSION)upsample->next_row_out,
output_buf + *out_row_ctr, output_buf + *out_row_ctr, (int)num_rows);
(int) num_rows);
/* Adjust counts */ /* Adjust counts */
*out_row_ctr += num_rows; *out_row_ctr += num_rows;
@ -124,7 +122,7 @@ sep_upsample (j_decompress_ptr cinfo,
*/ */
METHODDEF(void) METHODDEF(void)
fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, fullsize_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{ {
*output_data_ptr = input_data; *output_data_ptr = input_data;
@ -137,7 +135,7 @@ fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/ */
METHODDEF(void) METHODDEF(void)
noop_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, noop_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{ {
*output_data_ptr = NULL; /* safety check */ *output_data_ptr = NULL; /* safety check */
@ -156,10 +154,10 @@ noop_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/ */
METHODDEF(void) METHODDEF(void)
int_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
JSAMPARRAY output_data = *output_data_ptr; JSAMPARRAY output_data = *output_data_ptr;
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
register JSAMPLE invalue; register JSAMPLE invalue;
@ -185,8 +183,8 @@ int_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr,
} }
/* Generate any additional output rows by duplicating the first one */ /* Generate any additional output rows by duplicating the first one */
if (v_expand > 1) { if (v_expand > 1) {
jcopy_sample_rows(output_data, outrow, output_data, outrow+1, jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
v_expand-1, cinfo->output_width); v_expand - 1, cinfo->output_width);
} }
inrow++; inrow++;
outrow += v_expand; outrow += v_expand;
@ -200,7 +198,7 @@ int_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/ */
METHODDEF(void) METHODDEF(void)
h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{ {
JSAMPARRAY output_data = *output_data_ptr; JSAMPARRAY output_data = *output_data_ptr;
@ -228,7 +226,7 @@ h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/ */
METHODDEF(void) METHODDEF(void)
h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{ {
JSAMPARRAY output_data = *output_data_ptr; JSAMPARRAY output_data = *output_data_ptr;
@ -247,8 +245,8 @@ h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr,
*outptr++ = invalue; *outptr++ = invalue;
*outptr++ = invalue; *outptr++ = invalue;
} }
jcopy_sample_rows(output_data, outrow, output_data, outrow+1, jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
1, cinfo->output_width); cinfo->output_width);
inrow++; inrow++;
outrow += 2; outrow += 2;
} }
@ -271,7 +269,7 @@ h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/ */
METHODDEF(void) METHODDEF(void)
h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{ {
JSAMPARRAY output_data = *output_data_ptr; JSAMPARRAY output_data = *output_data_ptr;
@ -285,20 +283,20 @@ h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr,
outptr = output_data[inrow]; outptr = output_data[inrow];
/* Special case for first column */ /* Special case for first column */
invalue = GETJSAMPLE(*inptr++); invalue = GETJSAMPLE(*inptr++);
*outptr++ = (JSAMPLE) invalue; *outptr++ = (JSAMPLE)invalue;
*outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2); *outptr++ = (JSAMPLE)((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) { for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
/* General case: 3/4 * nearer pixel + 1/4 * further pixel */ /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
invalue = GETJSAMPLE(*inptr++) * 3; invalue = GETJSAMPLE(*inptr++) * 3;
*outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2); *outptr++ = (JSAMPLE)((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
*outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2); *outptr++ = (JSAMPLE)((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
} }
/* Special case for last column */ /* Special case for last column */
invalue = GETJSAMPLE(*inptr); invalue = GETJSAMPLE(*inptr);
*outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2); *outptr++ = (JSAMPLE)((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
*outptr++ = (JSAMPLE) invalue; *outptr++ = (JSAMPLE)invalue;
} }
} }
@ -311,7 +309,7 @@ h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/ */
METHODDEF(void) METHODDEF(void)
h1v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{ {
JSAMPARRAY output_data = *output_data_ptr; JSAMPARRAY output_data = *output_data_ptr;
@ -330,14 +328,14 @@ h1v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* inptr0 points to nearest input row, inptr1 points to next nearest */ /* inptr0 points to nearest input row, inptr1 points to next nearest */
inptr0 = input_data[inrow]; inptr0 = input_data[inrow];
if (v == 0) /* next nearest is row above */ if (v == 0) /* next nearest is row above */
inptr1 = input_data[inrow-1]; inptr1 = input_data[inrow - 1];
else /* next nearest is row below */ else /* next nearest is row below */
inptr1 = input_data[inrow+1]; inptr1 = input_data[inrow + 1];
outptr = output_data[outrow++]; outptr = output_data[outrow++];
for(colctr = 0; colctr < compptr->downsampled_width; colctr++) { for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++); thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
*outptr++ = (JSAMPLE) ((thiscolsum + 1) >> 2); *outptr++ = (JSAMPLE)((thiscolsum + 1) >> 2);
} }
} }
inrow++; inrow++;
@ -354,7 +352,7 @@ h1v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/ */
METHODDEF(void) METHODDEF(void)
h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{ {
JSAMPARRAY output_data = *output_data_ptr; JSAMPARRAY output_data = *output_data_ptr;
@ -373,30 +371,30 @@ h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* inptr0 points to nearest input row, inptr1 points to next nearest */ /* inptr0 points to nearest input row, inptr1 points to next nearest */
inptr0 = input_data[inrow]; inptr0 = input_data[inrow];
if (v == 0) /* next nearest is row above */ if (v == 0) /* next nearest is row above */
inptr1 = input_data[inrow-1]; inptr1 = input_data[inrow - 1];
else /* next nearest is row below */ else /* next nearest is row below */
inptr1 = input_data[inrow+1]; inptr1 = input_data[inrow + 1];
outptr = output_data[outrow++]; outptr = output_data[outrow++];
/* Special case for first column */ /* Special case for first column */
thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++); thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++); nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
*outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4); *outptr++ = (JSAMPLE)((thiscolsum * 4 + 8) >> 4);
*outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4); *outptr++ = (JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
lastcolsum = thiscolsum; thiscolsum = nextcolsum; lastcolsum = thiscolsum; thiscolsum = nextcolsum;
for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) { for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
/* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */ /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
/* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */ /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++); nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
*outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4); *outptr++ = (JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
*outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4); *outptr++ = (JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
lastcolsum = thiscolsum; thiscolsum = nextcolsum; lastcolsum = thiscolsum; thiscolsum = nextcolsum;
} }
/* Special case for last column */ /* Special case for last column */
*outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4); *outptr++ = (JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
*outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4); *outptr++ = (JSAMPLE)((thiscolsum * 4 + 7) >> 4);
} }
inrow++; inrow++;
} }
@ -408,7 +406,7 @@ h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/ */
GLOBAL(void) GLOBAL(void)
jinit_upsampler (j_decompress_ptr cinfo) jinit_upsampler(j_decompress_ptr cinfo)
{ {
my_upsample_ptr upsample; my_upsample_ptr upsample;
int ci; int ci;
@ -418,14 +416,14 @@ jinit_upsampler (j_decompress_ptr cinfo)
if (!cinfo->master->jinit_upsampler_no_alloc) { if (!cinfo->master->jinit_upsampler_no_alloc) {
upsample = (my_upsample_ptr) upsample = (my_upsample_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_upsampler)); sizeof(my_upsampler));
cinfo->upsample = (struct jpeg_upsampler *) upsample; cinfo->upsample = (struct jpeg_upsampler *)upsample;
upsample->pub.start_pass = start_pass_upsample; upsample->pub.start_pass = start_pass_upsample;
upsample->pub.upsample = sep_upsample; upsample->pub.upsample = sep_upsample;
upsample->pub.need_context_rows = FALSE; /* until we find out differently */ upsample->pub.need_context_rows = FALSE; /* until we find out differently */
} else } else
upsample = (my_upsample_ptr) cinfo->upsample; upsample = (my_upsample_ptr)cinfo->upsample;
if (cinfo->CCIR601_sampling) /* this isn't supported */ if (cinfo->CCIR601_sampling) /* this isn't supported */
ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
@ -451,7 +449,7 @@ jinit_upsampler (j_decompress_ptr cinfo)
v_out_group = cinfo->max_v_samp_factor; v_out_group = cinfo->max_v_samp_factor;
upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
need_buffer = TRUE; need_buffer = TRUE;
if (! compptr->component_needed) { if (!compptr->component_needed) {
/* Don't bother to upsample an uninteresting component. */ /* Don't bother to upsample an uninteresting component. */
upsample->methods[ci] = noop_upsample; upsample->methods[ci] = noop_upsample;
need_buffer = FALSE; need_buffer = FALSE;
@ -459,8 +457,7 @@ jinit_upsampler (j_decompress_ptr cinfo)
/* Fullsize components can be processed without any work. */ /* Fullsize components can be processed without any work. */
upsample->methods[ci] = fullsize_upsample; upsample->methods[ci] = fullsize_upsample;
need_buffer = FALSE; need_buffer = FALSE;
} else if (h_in_group * 2 == h_out_group && } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
v_in_group == v_out_group) {
/* Special cases for 2h1v upsampling */ /* Special cases for 2h1v upsampling */
if (do_fancy && compptr->downsampled_width > 2) { if (do_fancy && compptr->downsampled_width > 2) {
if (jsimd_can_h2v1_fancy_upsample()) if (jsimd_can_h2v1_fancy_upsample())
@ -502,16 +499,16 @@ jinit_upsampler (j_decompress_ptr cinfo)
else else
#endif #endif
upsample->methods[ci] = int_upsample; upsample->methods[ci] = int_upsample;
upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group); upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group); upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
} else } else
ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) { if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray) upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr)cinfo, JPOOL_IMAGE,
(JDIMENSION) jround_up((long) cinfo->output_width, (JDIMENSION)jround_up((long)cinfo->output_width,
(long) cinfo->max_h_samp_factor), (long)cinfo->max_h_samp_factor),
(JDIMENSION) cinfo->max_v_samp_factor); (JDIMENSION)cinfo->max_v_samp_factor);
} }
} }
} }

View File

@ -19,7 +19,7 @@
/* Forward declarations */ /* Forward declarations */
LOCAL(void) transdecode_master_selection (j_decompress_ptr cinfo); LOCAL(void) transdecode_master_selection(j_decompress_ptr cinfo);
/* /*
@ -45,7 +45,7 @@ LOCAL(void) transdecode_master_selection (j_decompress_ptr cinfo);
*/ */
GLOBAL(jvirt_barray_ptr *) GLOBAL(jvirt_barray_ptr *)
jpeg_read_coefficients (j_decompress_ptr cinfo) jpeg_read_coefficients(j_decompress_ptr cinfo)
{ {
if (cinfo->global_state == DSTATE_READY) { if (cinfo->global_state == DSTATE_READY) {
/* First call: initialize active modules */ /* First call: initialize active modules */
@ -58,7 +58,7 @@ jpeg_read_coefficients (j_decompress_ptr cinfo)
int retcode; int retcode;
/* Call progress monitor hook if present */ /* Call progress monitor hook if present */
if (cinfo->progress != NULL) if (cinfo->progress != NULL)
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
/* Absorb some more input */ /* Absorb some more input */
retcode = (*cinfo->inputctl->consume_input) (cinfo); retcode = (*cinfo->inputctl->consume_input) (cinfo);
if (retcode == JPEG_SUSPENDED) if (retcode == JPEG_SUSPENDED)
@ -70,7 +70,7 @@ jpeg_read_coefficients (j_decompress_ptr cinfo)
(retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) { (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) { if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
/* startup underestimated number of scans; ratchet up one scan */ /* startup underestimated number of scans; ratchet up one scan */
cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows; cinfo->progress->pass_limit += (long)cinfo->total_iMCU_rows;
} }
} }
} }
@ -97,7 +97,7 @@ jpeg_read_coefficients (j_decompress_ptr cinfo)
*/ */
LOCAL(void) LOCAL(void)
transdecode_master_selection (j_decompress_ptr cinfo) transdecode_master_selection(j_decompress_ptr cinfo)
{ {
/* This is effectively a buffered-image operation. */ /* This is effectively a buffered-image operation. */
cinfo->buffered_image = TRUE; cinfo->buffered_image = TRUE;
@ -129,7 +129,7 @@ transdecode_master_selection (j_decompress_ptr cinfo)
jinit_d_coef_controller(cinfo, TRUE); jinit_d_coef_controller(cinfo, TRUE);
/* We can now tell the memory manager to allocate virtual arrays. */ /* We can now tell the memory manager to allocate virtual arrays. */
(*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); (*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo);
/* Initialize input side of decompressor to consume first scan. */ /* Initialize input side of decompressor to consume first scan. */
(*cinfo->inputctl->start_input_pass) (cinfo); (*cinfo->inputctl->start_input_pass) (cinfo);
@ -148,7 +148,7 @@ transdecode_master_selection (j_decompress_ptr cinfo)
nscans = 1; nscans = 1;
} }
cinfo->progress->pass_counter = 0L; cinfo->progress->pass_counter = 0L;
cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans; cinfo->progress->pass_limit = (long)cinfo->total_iMCU_rows * nscans;
cinfo->progress->completed_passes = 0; cinfo->progress->completed_passes = 0;
cinfo->progress->total_passes = 1; cinfo->progress->total_passes = 1;
} }

View File

@ -44,7 +44,7 @@
* want to refer to it directly. * want to refer to it directly.
*/ */
#define JMESSAGE(code,string) string , #define JMESSAGE(code, string) string,
const char * const jpeg_std_message_table[] = { const char * const jpeg_std_message_table[] = {
#include "jerror.h" #include "jerror.h"
@ -66,7 +66,7 @@ const char * const jpeg_std_message_table[] = {
*/ */
METHODDEF(void) METHODDEF(void)
error_exit (j_common_ptr cinfo) error_exit(j_common_ptr cinfo)
{ {
/* Always display the message */ /* Always display the message */
(*cinfo->err->output_message) (cinfo); (*cinfo->err->output_message) (cinfo);
@ -94,7 +94,7 @@ error_exit (j_common_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
output_message (j_common_ptr cinfo) output_message(j_common_ptr cinfo)
{ {
char buffer[JMSG_LENGTH_MAX]; char buffer[JMSG_LENGTH_MAX];
@ -124,7 +124,7 @@ output_message (j_common_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
emit_message (j_common_ptr cinfo, int msg_level) emit_message(j_common_ptr cinfo, int msg_level)
{ {
struct jpeg_error_mgr *err = cinfo->err; struct jpeg_error_mgr *err = cinfo->err;
@ -153,7 +153,7 @@ emit_message (j_common_ptr cinfo, int msg_level)
*/ */
METHODDEF(void) METHODDEF(void)
format_message (j_common_ptr cinfo, char *buffer) format_message(j_common_ptr cinfo, char *buffer)
{ {
struct jpeg_error_mgr *err = cinfo->err; struct jpeg_error_mgr *err = cinfo->err;
int msg_code = err->msg_code; int msg_code = err->msg_code;
@ -208,7 +208,7 @@ format_message (j_common_ptr cinfo, char *buffer)
*/ */
METHODDEF(void) METHODDEF(void)
reset_error_mgr (j_common_ptr cinfo) reset_error_mgr(j_common_ptr cinfo)
{ {
cinfo->err->num_warnings = 0; cinfo->err->num_warnings = 0;
/* trace_level is not reset since it is an application-supplied parameter */ /* trace_level is not reset since it is an application-supplied parameter */
@ -227,7 +227,7 @@ reset_error_mgr (j_common_ptr cinfo)
*/ */
GLOBAL(struct jpeg_error_mgr *) GLOBAL(struct jpeg_error_mgr *)
jpeg_std_error (struct jpeg_error_mgr *err) jpeg_std_error(struct jpeg_error_mgr *err)
{ {
err->error_exit = error_exit; err->error_exit = error_exit;
err->emit_message = emit_message; err->emit_message = emit_message;
@ -241,7 +241,7 @@ jpeg_std_error (struct jpeg_error_mgr *err)
/* Initialize message table pointers */ /* Initialize message table pointers */
err->jpeg_message_table = jpeg_std_message_table; err->jpeg_message_table = jpeg_std_message_table;
err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1; err->last_jpeg_message = (int)JMSG_LASTMSGCODE - 1;
err->addon_message_table = NULL; err->addon_message_table = NULL;
err->first_addon_message = 0; /* for safety */ err->first_addon_message = 0; /* for safety */

View File

@ -5,7 +5,7 @@
* Copyright (C) 1994-1997, Thomas G. Lane. * Copyright (C) 1994-1997, Thomas G. Lane.
* Modified 1997-2009 by Guido Vollbeding. * Modified 1997-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2014, D. R. Commander. * Copyright (C) 2014, 2017, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@ -28,7 +28,7 @@
#define JMAKE_ENUM_LIST #define JMAKE_ENUM_LIST
#else #else
/* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */ /* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */
#define JMESSAGE(code,string) #define JMESSAGE(code, string)
#endif /* JERROR_H */ #endif /* JERROR_H */
#endif /* JMESSAGE */ #endif /* JMESSAGE */
@ -36,7 +36,7 @@
typedef enum { typedef enum {
#define JMESSAGE(code,string) code , #define JMESSAGE(code, string) code,
#endif /* JMAKE_ENUM_LIST */ #endif /* JMAKE_ENUM_LIST */
@ -44,8 +44,7 @@ JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
/* For maintenance convenience, list is alphabetical by message code name */ /* For maintenance convenience, list is alphabetical by message code name */
#if JPEG_LIB_VERSION < 70 #if JPEG_LIB_VERSION < 70
JMESSAGE(JERR_ARITH_NOTIMPL, JMESSAGE(JERR_ARITH_NOTIMPL, "Sorry, arithmetic coding is not implemented")
"Sorry, arithmetic coding is not implemented")
#endif #endif
JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix") JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix") JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
@ -154,8 +153,7 @@ JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d") JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE, JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
"Warning: thumbnail image size does not match data length %u") "Warning: thumbnail image size does not match data length %u")
JMESSAGE(JTRC_JFIF_EXTENSION, JMESSAGE(JTRC_JFIF_EXTENSION, "JFIF extension marker: type 0x%02x, length %u")
"JFIF extension marker: type 0x%02x, length %u")
JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image") JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u") JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x") JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
@ -208,6 +206,7 @@ JMESSAGE(JERR_NO_ARITH_TABLE, "Arithmetic table 0x%02x was not defined")
JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code") JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code")
#endif #endif
#endif #endif
JMESSAGE(JWRN_BOGUS_ICC, "Corrupt JPEG data: bad ICC marker")
#ifdef JMAKE_ENUM_LIST #ifdef JMAKE_ENUM_LIST
@ -228,90 +227,90 @@ JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code")
/* The first parameter is either type of cinfo pointer */ /* The first parameter is either type of cinfo pointer */
/* Fatal errors (print message and exit) */ /* Fatal errors (print message and exit) */
#define ERREXIT(cinfo,code) \ #define ERREXIT(cinfo, code) \
((cinfo)->err->msg_code = (code), \ ((cinfo)->err->msg_code = (code), \
(*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) (*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo)))
#define ERREXIT1(cinfo,code,p1) \ #define ERREXIT1(cinfo, code, p1) \
((cinfo)->err->msg_code = (code), \ ((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[0] = (p1), \ (cinfo)->err->msg_parm.i[0] = (p1), \
(*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) (*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo)))
#define ERREXIT2(cinfo,code,p1,p2) \ #define ERREXIT2(cinfo, code, p1, p2) \
((cinfo)->err->msg_code = (code), \ ((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[0] = (p1), \ (cinfo)->err->msg_parm.i[0] = (p1), \
(cinfo)->err->msg_parm.i[1] = (p2), \ (cinfo)->err->msg_parm.i[1] = (p2), \
(*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) (*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo)))
#define ERREXIT3(cinfo,code,p1,p2,p3) \ #define ERREXIT3(cinfo, code, p1, p2, p3) \
((cinfo)->err->msg_code = (code), \ ((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[0] = (p1), \ (cinfo)->err->msg_parm.i[0] = (p1), \
(cinfo)->err->msg_parm.i[1] = (p2), \ (cinfo)->err->msg_parm.i[1] = (p2), \
(cinfo)->err->msg_parm.i[2] = (p3), \ (cinfo)->err->msg_parm.i[2] = (p3), \
(*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) (*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo)))
#define ERREXIT4(cinfo,code,p1,p2,p3,p4) \ #define ERREXIT4(cinfo, code, p1, p2, p3, p4) \
((cinfo)->err->msg_code = (code), \ ((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[0] = (p1), \ (cinfo)->err->msg_parm.i[0] = (p1), \
(cinfo)->err->msg_parm.i[1] = (p2), \ (cinfo)->err->msg_parm.i[1] = (p2), \
(cinfo)->err->msg_parm.i[2] = (p3), \ (cinfo)->err->msg_parm.i[2] = (p3), \
(cinfo)->err->msg_parm.i[3] = (p4), \ (cinfo)->err->msg_parm.i[3] = (p4), \
(*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) (*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo)))
#define ERREXITS(cinfo,code,str) \ #define ERREXITS(cinfo, code, str) \
((cinfo)->err->msg_code = (code), \ ((cinfo)->err->msg_code = (code), \
strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
(*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) (*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo)))
#define MAKESTMT(stuff) do { stuff } while (0) #define MAKESTMT(stuff) do { stuff } while (0)
/* Nonfatal errors (we can keep going, but the data is probably corrupt) */ /* Nonfatal errors (we can keep going, but the data is probably corrupt) */
#define WARNMS(cinfo,code) \ #define WARNMS(cinfo, code) \
((cinfo)->err->msg_code = (code), \ ((cinfo)->err->msg_code = (code), \
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), -1))
#define WARNMS1(cinfo,code,p1) \ #define WARNMS1(cinfo, code, p1) \
((cinfo)->err->msg_code = (code), \ ((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[0] = (p1), \ (cinfo)->err->msg_parm.i[0] = (p1), \
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), -1))
#define WARNMS2(cinfo,code,p1,p2) \ #define WARNMS2(cinfo, code, p1, p2) \
((cinfo)->err->msg_code = (code), \ ((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[0] = (p1), \ (cinfo)->err->msg_parm.i[0] = (p1), \
(cinfo)->err->msg_parm.i[1] = (p2), \ (cinfo)->err->msg_parm.i[1] = (p2), \
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), -1))
/* Informational/debugging messages */ /* Informational/debugging messages */
#define TRACEMS(cinfo,lvl,code) \ #define TRACEMS(cinfo, lvl, code) \
((cinfo)->err->msg_code = (code), \ ((cinfo)->err->msg_code = (code), \
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)))
#define TRACEMS1(cinfo,lvl,code,p1) \ #define TRACEMS1(cinfo, lvl, code, p1) \
((cinfo)->err->msg_code = (code), \ ((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[0] = (p1), \ (cinfo)->err->msg_parm.i[0] = (p1), \
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)))
#define TRACEMS2(cinfo,lvl,code,p1,p2) \ #define TRACEMS2(cinfo, lvl, code, p1, p2) \
((cinfo)->err->msg_code = (code), \ ((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[0] = (p1), \ (cinfo)->err->msg_parm.i[0] = (p1), \
(cinfo)->err->msg_parm.i[1] = (p2), \ (cinfo)->err->msg_parm.i[1] = (p2), \
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)))
#define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \ #define TRACEMS3(cinfo, lvl, code, p1, p2, p3) \
MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ MAKESTMT(int *_mp = (cinfo)->err->msg_parm.i; \
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \ _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
(cinfo)->err->msg_code = (code); \ (cinfo)->err->msg_code = (code); \
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)); )
#define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \ #define TRACEMS4(cinfo, lvl, code, p1, p2, p3, p4) \
MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ MAKESTMT(int *_mp = (cinfo)->err->msg_parm.i; \
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
(cinfo)->err->msg_code = (code); \ (cinfo)->err->msg_code = (code); \
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)); )
#define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \ #define TRACEMS5(cinfo, lvl, code, p1, p2, p3, p4, p5) \
MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ MAKESTMT(int *_mp = (cinfo)->err->msg_parm.i; \
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
_mp[4] = (p5); \ _mp[4] = (p5); \
(cinfo)->err->msg_code = (code); \ (cinfo)->err->msg_code = (code); \
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)); )
#define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \ #define TRACEMS8(cinfo, lvl, code, p1, p2, p3, p4, p5, p6, p7, p8) \
MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ MAKESTMT(int *_mp = (cinfo)->err->msg_parm.i; \
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
_mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \ _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
(cinfo)->err->msg_code = (code); \ (cinfo)->err->msg_code = (code); \
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)); )
#define TRACEMSS(cinfo,lvl,code,str) \ #define TRACEMSS(cinfo, lvl, code, str) \
((cinfo)->err->msg_code = (code), \ ((cinfo)->err->msg_code = (code), \
strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)))
#endif /* JERROR_H */ #endif /* JERROR_H */

View File

@ -57,7 +57,7 @@
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_fdct_float (FAST_FLOAT *data) jpeg_fdct_float(FAST_FLOAT *data)
{ {
FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
FAST_FLOAT tmp10, tmp11, tmp12, tmp13; FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
@ -68,7 +68,7 @@ jpeg_fdct_float (FAST_FLOAT *data)
/* Pass 1: process rows. */ /* Pass 1: process rows. */
dataptr = data; dataptr = data;
for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { for (ctr = DCTSIZE - 1; ctr >= 0; ctr--) {
tmp0 = dataptr[0] + dataptr[7]; tmp0 = dataptr[0] + dataptr[7];
tmp7 = dataptr[0] - dataptr[7]; tmp7 = dataptr[0] - dataptr[7];
tmp1 = dataptr[1] + dataptr[6]; tmp1 = dataptr[1] + dataptr[6];
@ -88,7 +88,7 @@ jpeg_fdct_float (FAST_FLOAT *data)
dataptr[0] = tmp10 + tmp11; /* phase 3 */ dataptr[0] = tmp10 + tmp11; /* phase 3 */
dataptr[4] = tmp10 - tmp11; dataptr[4] = tmp10 - tmp11;
z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */ z1 = (tmp12 + tmp13) * ((FAST_FLOAT)0.707106781); /* c4 */
dataptr[2] = tmp13 + z1; /* phase 5 */ dataptr[2] = tmp13 + z1; /* phase 5 */
dataptr[6] = tmp13 - z1; dataptr[6] = tmp13 - z1;
@ -99,10 +99,10 @@ jpeg_fdct_float (FAST_FLOAT *data)
tmp12 = tmp6 + tmp7; tmp12 = tmp6 + tmp7;
/* The rotator is modified from fig 4-8 to avoid extra negations. */ /* The rotator is modified from fig 4-8 to avoid extra negations. */
z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */ z5 = (tmp10 - tmp12) * ((FAST_FLOAT)0.382683433); /* c6 */
z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */ z2 = ((FAST_FLOAT)0.541196100) * tmp10 + z5; /* c2-c6 */
z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */ z4 = ((FAST_FLOAT)1.306562965) * tmp12 + z5; /* c2+c6 */
z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */ z3 = tmp11 * ((FAST_FLOAT)0.707106781); /* c4 */
z11 = tmp7 + z3; /* phase 5 */ z11 = tmp7 + z3; /* phase 5 */
z13 = tmp7 - z3; z13 = tmp7 - z3;
@ -118,15 +118,15 @@ jpeg_fdct_float (FAST_FLOAT *data)
/* Pass 2: process columns. */ /* Pass 2: process columns. */
dataptr = data; dataptr = data;
for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { for (ctr = DCTSIZE - 1; ctr >= 0; ctr--) {
tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; tmp0 = dataptr[DCTSIZE * 0] + dataptr[DCTSIZE * 7];
tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; tmp7 = dataptr[DCTSIZE * 0] - dataptr[DCTSIZE * 7];
tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; tmp1 = dataptr[DCTSIZE * 1] + dataptr[DCTSIZE * 6];
tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; tmp6 = dataptr[DCTSIZE * 1] - dataptr[DCTSIZE * 6];
tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; tmp2 = dataptr[DCTSIZE * 2] + dataptr[DCTSIZE * 5];
tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; tmp5 = dataptr[DCTSIZE * 2] - dataptr[DCTSIZE * 5];
tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; tmp3 = dataptr[DCTSIZE * 3] + dataptr[DCTSIZE * 4];
tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; tmp4 = dataptr[DCTSIZE * 3] - dataptr[DCTSIZE * 4];
/* Even part */ /* Even part */
@ -135,12 +135,12 @@ jpeg_fdct_float (FAST_FLOAT *data)
tmp11 = tmp1 + tmp2; tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2; tmp12 = tmp1 - tmp2;
dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */ dataptr[DCTSIZE * 0] = tmp10 + tmp11; /* phase 3 */
dataptr[DCTSIZE*4] = tmp10 - tmp11; dataptr[DCTSIZE * 4] = tmp10 - tmp11;
z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */ z1 = (tmp12 + tmp13) * ((FAST_FLOAT)0.707106781); /* c4 */
dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */ dataptr[DCTSIZE * 2] = tmp13 + z1; /* phase 5 */
dataptr[DCTSIZE*6] = tmp13 - z1; dataptr[DCTSIZE * 6] = tmp13 - z1;
/* Odd part */ /* Odd part */
@ -149,18 +149,18 @@ jpeg_fdct_float (FAST_FLOAT *data)
tmp12 = tmp6 + tmp7; tmp12 = tmp6 + tmp7;
/* The rotator is modified from fig 4-8 to avoid extra negations. */ /* The rotator is modified from fig 4-8 to avoid extra negations. */
z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */ z5 = (tmp10 - tmp12) * ((FAST_FLOAT)0.382683433); /* c6 */
z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */ z2 = ((FAST_FLOAT)0.541196100) * tmp10 + z5; /* c2-c6 */
z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */ z4 = ((FAST_FLOAT)1.306562965) * tmp12 + z5; /* c2+c6 */
z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */ z3 = tmp11 * ((FAST_FLOAT)0.707106781); /* c4 */
z11 = tmp7 + z3; /* phase 5 */ z11 = tmp7 + z3; /* phase 5 */
z13 = tmp7 - z3; z13 = tmp7 - z3;
dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */ dataptr[DCTSIZE * 5] = z13 + z2; /* phase 6 */
dataptr[DCTSIZE*3] = z13 - z2; dataptr[DCTSIZE * 3] = z13 - z2;
dataptr[DCTSIZE*1] = z11 + z4; dataptr[DCTSIZE * 1] = z11 + z4;
dataptr[DCTSIZE*7] = z11 - z4; dataptr[DCTSIZE * 7] = z11 - z4;
dataptr++; /* advance pointer to next column */ dataptr++; /* advance pointer to next column */
} }

View File

@ -79,10 +79,10 @@
*/ */
#if CONST_BITS == 8 #if CONST_BITS == 8
#define FIX_0_382683433 ((JLONG) 98) /* FIX(0.382683433) */ #define FIX_0_382683433 ((JLONG)98) /* FIX(0.382683433) */
#define FIX_0_541196100 ((JLONG) 139) /* FIX(0.541196100) */ #define FIX_0_541196100 ((JLONG)139) /* FIX(0.541196100) */
#define FIX_0_707106781 ((JLONG) 181) /* FIX(0.707106781) */ #define FIX_0_707106781 ((JLONG)181) /* FIX(0.707106781) */
#define FIX_1_306562965 ((JLONG) 334) /* FIX(1.306562965) */ #define FIX_1_306562965 ((JLONG)334) /* FIX(1.306562965) */
#else #else
#define FIX_0_382683433 FIX(0.382683433) #define FIX_0_382683433 FIX(0.382683433)
#define FIX_0_541196100 FIX(0.541196100) #define FIX_0_541196100 FIX(0.541196100)
@ -98,7 +98,7 @@
#ifndef USE_ACCURATE_ROUNDING #ifndef USE_ACCURATE_ROUNDING
#undef DESCALE #undef DESCALE
#define DESCALE(x,n) RIGHT_SHIFT(x, n) #define DESCALE(x, n) RIGHT_SHIFT(x, n)
#endif #endif
@ -106,7 +106,7 @@
* descale to yield a DCTELEM result. * descale to yield a DCTELEM result.
*/ */
#define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS)) #define MULTIPLY(var, const) ((DCTELEM)DESCALE((var) * (const), CONST_BITS))
/* /*
@ -114,7 +114,7 @@
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_fdct_ifast (DCTELEM *data) jpeg_fdct_ifast(DCTELEM *data)
{ {
DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
DCTELEM tmp10, tmp11, tmp12, tmp13; DCTELEM tmp10, tmp11, tmp12, tmp13;
@ -126,7 +126,7 @@ jpeg_fdct_ifast (DCTELEM *data)
/* Pass 1: process rows. */ /* Pass 1: process rows. */
dataptr = data; dataptr = data;
for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { for (ctr = DCTSIZE - 1; ctr >= 0; ctr--) {
tmp0 = dataptr[0] + dataptr[7]; tmp0 = dataptr[0] + dataptr[7];
tmp7 = dataptr[0] - dataptr[7]; tmp7 = dataptr[0] - dataptr[7];
tmp1 = dataptr[1] + dataptr[6]; tmp1 = dataptr[1] + dataptr[6];
@ -176,15 +176,15 @@ jpeg_fdct_ifast (DCTELEM *data)
/* Pass 2: process columns. */ /* Pass 2: process columns. */
dataptr = data; dataptr = data;
for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { for (ctr = DCTSIZE - 1; ctr >= 0; ctr--) {
tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; tmp0 = dataptr[DCTSIZE * 0] + dataptr[DCTSIZE * 7];
tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; tmp7 = dataptr[DCTSIZE * 0] - dataptr[DCTSIZE * 7];
tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; tmp1 = dataptr[DCTSIZE * 1] + dataptr[DCTSIZE * 6];
tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; tmp6 = dataptr[DCTSIZE * 1] - dataptr[DCTSIZE * 6];
tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; tmp2 = dataptr[DCTSIZE * 2] + dataptr[DCTSIZE * 5];
tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; tmp5 = dataptr[DCTSIZE * 2] - dataptr[DCTSIZE * 5];
tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; tmp3 = dataptr[DCTSIZE * 3] + dataptr[DCTSIZE * 4];
tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; tmp4 = dataptr[DCTSIZE * 3] - dataptr[DCTSIZE * 4];
/* Even part */ /* Even part */
@ -193,12 +193,12 @@ jpeg_fdct_ifast (DCTELEM *data)
tmp11 = tmp1 + tmp2; tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2; tmp12 = tmp1 - tmp2;
dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */ dataptr[DCTSIZE * 0] = tmp10 + tmp11; /* phase 3 */
dataptr[DCTSIZE*4] = tmp10 - tmp11; dataptr[DCTSIZE * 4] = tmp10 - tmp11;
z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */ dataptr[DCTSIZE * 2] = tmp13 + z1; /* phase 5 */
dataptr[DCTSIZE*6] = tmp13 - z1; dataptr[DCTSIZE * 6] = tmp13 - z1;
/* Odd part */ /* Odd part */
@ -215,10 +215,10 @@ jpeg_fdct_ifast (DCTELEM *data)
z11 = tmp7 + z3; /* phase 5 */ z11 = tmp7 + z3; /* phase 5 */
z13 = tmp7 - z3; z13 = tmp7 - z3;
dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */ dataptr[DCTSIZE * 5] = z13 + z2; /* phase 6 */
dataptr[DCTSIZE*3] = z13 - z2; dataptr[DCTSIZE * 3] = z13 - z2;
dataptr[DCTSIZE*1] = z11 + z4; dataptr[DCTSIZE * 1] = z11 + z4;
dataptr[DCTSIZE*7] = z11 - z4; dataptr[DCTSIZE * 7] = z11 - z4;
dataptr++; /* advance pointer to next column */ dataptr++; /* advance pointer to next column */
} }

View File

@ -93,18 +93,18 @@
*/ */
#if CONST_BITS == 13 #if CONST_BITS == 13
#define FIX_0_298631336 ((JLONG) 2446) /* FIX(0.298631336) */ #define FIX_0_298631336 ((JLONG)2446) /* FIX(0.298631336) */
#define FIX_0_390180644 ((JLONG) 3196) /* FIX(0.390180644) */ #define FIX_0_390180644 ((JLONG)3196) /* FIX(0.390180644) */
#define FIX_0_541196100 ((JLONG) 4433) /* FIX(0.541196100) */ #define FIX_0_541196100 ((JLONG)4433) /* FIX(0.541196100) */
#define FIX_0_765366865 ((JLONG) 6270) /* FIX(0.765366865) */ #define FIX_0_765366865 ((JLONG)6270) /* FIX(0.765366865) */
#define FIX_0_899976223 ((JLONG) 7373) /* FIX(0.899976223) */ #define FIX_0_899976223 ((JLONG)7373) /* FIX(0.899976223) */
#define FIX_1_175875602 ((JLONG) 9633) /* FIX(1.175875602) */ #define FIX_1_175875602 ((JLONG)9633) /* FIX(1.175875602) */
#define FIX_1_501321110 ((JLONG) 12299) /* FIX(1.501321110) */ #define FIX_1_501321110 ((JLONG)12299) /* FIX(1.501321110) */
#define FIX_1_847759065 ((JLONG) 15137) /* FIX(1.847759065) */ #define FIX_1_847759065 ((JLONG)15137) /* FIX(1.847759065) */
#define FIX_1_961570560 ((JLONG) 16069) /* FIX(1.961570560) */ #define FIX_1_961570560 ((JLONG)16069) /* FIX(1.961570560) */
#define FIX_2_053119869 ((JLONG) 16819) /* FIX(2.053119869) */ #define FIX_2_053119869 ((JLONG)16819) /* FIX(2.053119869) */
#define FIX_2_562915447 ((JLONG) 20995) /* FIX(2.562915447) */ #define FIX_2_562915447 ((JLONG)20995) /* FIX(2.562915447) */
#define FIX_3_072711026 ((JLONG) 25172) /* FIX(3.072711026) */ #define FIX_3_072711026 ((JLONG)25172) /* FIX(3.072711026) */
#else #else
#define FIX_0_298631336 FIX(0.298631336) #define FIX_0_298631336 FIX(0.298631336)
#define FIX_0_390180644 FIX(0.390180644) #define FIX_0_390180644 FIX(0.390180644)
@ -129,9 +129,9 @@
*/ */
#if BITS_IN_JSAMPLE == 8 #if BITS_IN_JSAMPLE == 8
#define MULTIPLY(var,const) MULTIPLY16C16(var,const) #define MULTIPLY(var, const) MULTIPLY16C16(var, const)
#else #else
#define MULTIPLY(var,const) ((var) * (const)) #define MULTIPLY(var, const) ((var) * (const))
#endif #endif
@ -140,7 +140,7 @@
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_fdct_islow (DCTELEM *data) jpeg_fdct_islow(DCTELEM *data)
{ {
JLONG tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; JLONG tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
JLONG tmp10, tmp11, tmp12, tmp13; JLONG tmp10, tmp11, tmp12, tmp13;
@ -154,7 +154,7 @@ jpeg_fdct_islow (DCTELEM *data)
/* furthermore, we scale the results by 2**PASS1_BITS. */ /* furthermore, we scale the results by 2**PASS1_BITS. */
dataptr = data; dataptr = data;
for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { for (ctr = DCTSIZE - 1; ctr >= 0; ctr--) {
tmp0 = dataptr[0] + dataptr[7]; tmp0 = dataptr[0] + dataptr[7];
tmp7 = dataptr[0] - dataptr[7]; tmp7 = dataptr[0] - dataptr[7];
tmp1 = dataptr[1] + dataptr[6]; tmp1 = dataptr[1] + dataptr[6];
@ -173,14 +173,14 @@ jpeg_fdct_islow (DCTELEM *data)
tmp11 = tmp1 + tmp2; tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2; tmp12 = tmp1 - tmp2;
dataptr[0] = (DCTELEM) LEFT_SHIFT(tmp10 + tmp11, PASS1_BITS); dataptr[0] = (DCTELEM)LEFT_SHIFT(tmp10 + tmp11, PASS1_BITS);
dataptr[4] = (DCTELEM) LEFT_SHIFT(tmp10 - tmp11, PASS1_BITS); dataptr[4] = (DCTELEM)LEFT_SHIFT(tmp10 - tmp11, PASS1_BITS);
z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), dataptr[2] = (DCTELEM)DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
CONST_BITS-PASS1_BITS); CONST_BITS - PASS1_BITS);
dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), dataptr[6] = (DCTELEM)DESCALE(z1 + MULTIPLY(tmp12, -FIX_1_847759065),
CONST_BITS-PASS1_BITS); CONST_BITS - PASS1_BITS);
/* Odd part per figure 8 --- note paper omits factor of sqrt(2). /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
* cK represents cos(K*pi/16). * cK represents cos(K*pi/16).
@ -197,18 +197,18 @@ jpeg_fdct_islow (DCTELEM *data)
tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ z1 = MULTIPLY(z1, -FIX_0_899976223); /* sqrt(2) * ( c7-c3) */
z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ z2 = MULTIPLY(z2, -FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ z3 = MULTIPLY(z3, -FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ z4 = MULTIPLY(z4, -FIX_0_390180644); /* sqrt(2) * ( c5-c3) */
z3 += z5; z3 += z5;
z4 += z5; z4 += z5;
dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS); dataptr[7] = (DCTELEM)DESCALE(tmp4 + z1 + z3, CONST_BITS - PASS1_BITS);
dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS); dataptr[5] = (DCTELEM)DESCALE(tmp5 + z2 + z4, CONST_BITS - PASS1_BITS);
dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS); dataptr[3] = (DCTELEM)DESCALE(tmp6 + z2 + z3, CONST_BITS - PASS1_BITS);
dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS); dataptr[1] = (DCTELEM)DESCALE(tmp7 + z1 + z4, CONST_BITS - PASS1_BITS);
dataptr += DCTSIZE; /* advance pointer to next row */ dataptr += DCTSIZE; /* advance pointer to next row */
} }
@ -219,15 +219,15 @@ jpeg_fdct_islow (DCTELEM *data)
*/ */
dataptr = data; dataptr = data;
for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { for (ctr = DCTSIZE - 1; ctr >= 0; ctr--) {
tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; tmp0 = dataptr[DCTSIZE * 0] + dataptr[DCTSIZE * 7];
tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; tmp7 = dataptr[DCTSIZE * 0] - dataptr[DCTSIZE * 7];
tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; tmp1 = dataptr[DCTSIZE * 1] + dataptr[DCTSIZE * 6];
tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; tmp6 = dataptr[DCTSIZE * 1] - dataptr[DCTSIZE * 6];
tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; tmp2 = dataptr[DCTSIZE * 2] + dataptr[DCTSIZE * 5];
tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; tmp5 = dataptr[DCTSIZE * 2] - dataptr[DCTSIZE * 5];
tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; tmp3 = dataptr[DCTSIZE * 3] + dataptr[DCTSIZE * 4];
tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; tmp4 = dataptr[DCTSIZE * 3] - dataptr[DCTSIZE * 4];
/* Even part per LL&M figure 1 --- note that published figure is faulty; /* Even part per LL&M figure 1 --- note that published figure is faulty;
* rotator "sqrt(2)*c1" should be "sqrt(2)*c6". * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
@ -238,14 +238,16 @@ jpeg_fdct_islow (DCTELEM *data)
tmp11 = tmp1 + tmp2; tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2; tmp12 = tmp1 - tmp2;
dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS); dataptr[DCTSIZE * 0] = (DCTELEM)DESCALE(tmp10 + tmp11, PASS1_BITS);
dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS); dataptr[DCTSIZE * 4] = (DCTELEM)DESCALE(tmp10 - tmp11, PASS1_BITS);
z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), dataptr[DCTSIZE * 2] =
CONST_BITS+PASS1_BITS); (DCTELEM)DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), CONST_BITS + PASS1_BITS);
CONST_BITS+PASS1_BITS); dataptr[DCTSIZE * 6] =
(DCTELEM)DESCALE(z1 + MULTIPLY(tmp12, -FIX_1_847759065),
CONST_BITS + PASS1_BITS);
/* Odd part per figure 8 --- note paper omits factor of sqrt(2). /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
* cK represents cos(K*pi/16). * cK represents cos(K*pi/16).
@ -262,22 +264,22 @@ jpeg_fdct_islow (DCTELEM *data)
tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ z1 = MULTIPLY(z1, -FIX_0_899976223); /* sqrt(2) * ( c7-c3) */
z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ z2 = MULTIPLY(z2, -FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ z3 = MULTIPLY(z3, -FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ z4 = MULTIPLY(z4, -FIX_0_390180644); /* sqrt(2) * ( c5-c3) */
z3 += z5; z3 += z5;
z4 += z5; z4 += z5;
dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, dataptr[DCTSIZE * 7] = (DCTELEM)DESCALE(tmp4 + z1 + z3,
CONST_BITS+PASS1_BITS); CONST_BITS + PASS1_BITS);
dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, dataptr[DCTSIZE * 5] = (DCTELEM)DESCALE(tmp5 + z2 + z4,
CONST_BITS+PASS1_BITS); CONST_BITS + PASS1_BITS);
dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, dataptr[DCTSIZE * 3] = (DCTELEM)DESCALE(tmp6 + z2 + z3,
CONST_BITS+PASS1_BITS); CONST_BITS + PASS1_BITS);
dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, dataptr[DCTSIZE * 1] = (DCTELEM)DESCALE(tmp7 + z1 + z4,
CONST_BITS+PASS1_BITS); CONST_BITS + PASS1_BITS);
dataptr++; /* advance pointer to next column */ dataptr++; /* advance pointer to next column */
} }

View File

@ -61,7 +61,7 @@
* entry; produce a float result. * entry; produce a float result.
*/ */
#define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval)) #define DEQUANTIZE(coef, quantval) (((FAST_FLOAT)(coef)) * (quantval))
/* /*
@ -69,9 +69,9 @@
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION output_col) JDIMENSION output_col)
{ {
FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
FAST_FLOAT tmp10, tmp11, tmp12, tmp13; FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
@ -83,12 +83,12 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPLE *range_limit = cinfo->sample_range_limit; JSAMPLE *range_limit = cinfo->sample_range_limit;
int ctr; int ctr;
FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */ FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
#define _0_125 ((FLOAT_MULT_TYPE)0.125) #define _0_125 ((FLOAT_MULT_TYPE)0.125)
/* Pass 1: process columns from input, store into work array. */ /* Pass 1: process columns from input, store into work array. */
inptr = coef_block; inptr = coef_block;
quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table; quantptr = (FLOAT_MULT_TYPE *)compptr->dct_table;
wsptr = workspace; wsptr = workspace;
for (ctr = DCTSIZE; ctr > 0; ctr--) { for (ctr = DCTSIZE; ctr > 0; ctr--) {
/* Due to quantization, we will usually find that many of the input /* Due to quantization, we will usually find that many of the input
@ -100,22 +100,22 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info *compptr,
* column DCT calculations can be simplified this way. * column DCT calculations can be simplified this way.
*/ */
if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && if (inptr[DCTSIZE * 1] == 0 && inptr[DCTSIZE * 2] == 0 &&
inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && inptr[DCTSIZE * 3] == 0 && inptr[DCTSIZE * 4] == 0 &&
inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE * 5] == 0 && inptr[DCTSIZE * 6] == 0 &&
inptr[DCTSIZE*7] == 0) { inptr[DCTSIZE * 7] == 0) {
/* AC terms all zero */ /* AC terms all zero */
FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE * 0],
quantptr[DCTSIZE*0] * _0_125); quantptr[DCTSIZE * 0] * _0_125);
wsptr[DCTSIZE*0] = dcval; wsptr[DCTSIZE * 0] = dcval;
wsptr[DCTSIZE*1] = dcval; wsptr[DCTSIZE * 1] = dcval;
wsptr[DCTSIZE*2] = dcval; wsptr[DCTSIZE * 2] = dcval;
wsptr[DCTSIZE*3] = dcval; wsptr[DCTSIZE * 3] = dcval;
wsptr[DCTSIZE*4] = dcval; wsptr[DCTSIZE * 4] = dcval;
wsptr[DCTSIZE*5] = dcval; wsptr[DCTSIZE * 5] = dcval;
wsptr[DCTSIZE*6] = dcval; wsptr[DCTSIZE * 6] = dcval;
wsptr[DCTSIZE*7] = dcval; wsptr[DCTSIZE * 7] = dcval;
inptr++; /* advance pointers to next column */ inptr++; /* advance pointers to next column */
quantptr++; quantptr++;
@ -125,16 +125,16 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* Even part */ /* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0] * _0_125); tmp0 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0] * _0_125);
tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2] * _0_125); tmp1 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2] * _0_125);
tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4] * _0_125); tmp2 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4] * _0_125);
tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6] * _0_125); tmp3 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6] * _0_125);
tmp10 = tmp0 + tmp2; /* phase 3 */ tmp10 = tmp0 + tmp2; /* phase 3 */
tmp11 = tmp0 - tmp2; tmp11 = tmp0 - tmp2;
tmp13 = tmp1 + tmp3; /* phases 5-3 */ tmp13 = tmp1 + tmp3; /* phases 5-3 */
tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */ tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT)1.414213562) - tmp13; /* 2*c4 */
tmp0 = tmp10 + tmp13; /* phase 2 */ tmp0 = tmp10 + tmp13; /* phase 2 */
tmp3 = tmp10 - tmp13; tmp3 = tmp10 - tmp13;
@ -143,10 +143,10 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* Odd part */ /* Odd part */
tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1] * _0_125); tmp4 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1] * _0_125);
tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3] * _0_125); tmp5 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3] * _0_125);
tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5] * _0_125); tmp6 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5] * _0_125);
tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7] * _0_125); tmp7 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7] * _0_125);
z13 = tmp6 + tmp5; /* phase 6 */ z13 = tmp6 + tmp5; /* phase 6 */
z10 = tmp6 - tmp5; z10 = tmp6 - tmp5;
@ -154,24 +154,24 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info *compptr,
z12 = tmp4 - tmp7; z12 = tmp4 - tmp7;
tmp7 = z11 + z13; /* phase 5 */ tmp7 = z11 + z13; /* phase 5 */
tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */ tmp11 = (z11 - z13) * ((FAST_FLOAT)1.414213562); /* 2*c4 */
z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */ z5 = (z10 + z12) * ((FAST_FLOAT)1.847759065); /* 2*c2 */
tmp10 = z5 - z12 * ((FAST_FLOAT) 1.082392200); /* 2*(c2-c6) */ tmp10 = z5 - z12 * ((FAST_FLOAT)1.082392200); /* 2*(c2-c6) */
tmp12 = z5 - z10 * ((FAST_FLOAT) 2.613125930); /* 2*(c2+c6) */ tmp12 = z5 - z10 * ((FAST_FLOAT)2.613125930); /* 2*(c2+c6) */
tmp6 = tmp12 - tmp7; /* phase 2 */ tmp6 = tmp12 - tmp7; /* phase 2 */
tmp5 = tmp11 - tmp6; tmp5 = tmp11 - tmp6;
tmp4 = tmp10 - tmp5; tmp4 = tmp10 - tmp5;
wsptr[DCTSIZE*0] = tmp0 + tmp7; wsptr[DCTSIZE * 0] = tmp0 + tmp7;
wsptr[DCTSIZE*7] = tmp0 - tmp7; wsptr[DCTSIZE * 7] = tmp0 - tmp7;
wsptr[DCTSIZE*1] = tmp1 + tmp6; wsptr[DCTSIZE * 1] = tmp1 + tmp6;
wsptr[DCTSIZE*6] = tmp1 - tmp6; wsptr[DCTSIZE * 6] = tmp1 - tmp6;
wsptr[DCTSIZE*2] = tmp2 + tmp5; wsptr[DCTSIZE * 2] = tmp2 + tmp5;
wsptr[DCTSIZE*5] = tmp2 - tmp5; wsptr[DCTSIZE * 5] = tmp2 - tmp5;
wsptr[DCTSIZE*3] = tmp3 + tmp4; wsptr[DCTSIZE * 3] = tmp3 + tmp4;
wsptr[DCTSIZE*4] = tmp3 - tmp4; wsptr[DCTSIZE * 4] = tmp3 - tmp4;
inptr++; /* advance pointers to next column */ inptr++; /* advance pointers to next column */
quantptr++; quantptr++;
@ -192,12 +192,12 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* Even part */ /* Even part */
/* Apply signed->unsigned and prepare float->int conversion */ /* Apply signed->unsigned and prepare float->int conversion */
z5 = wsptr[0] + ((FAST_FLOAT) CENTERJSAMPLE + (FAST_FLOAT) 0.5); z5 = wsptr[0] + ((FAST_FLOAT)CENTERJSAMPLE + (FAST_FLOAT)0.5);
tmp10 = z5 + wsptr[4]; tmp10 = z5 + wsptr[4];
tmp11 = z5 - wsptr[4]; tmp11 = z5 - wsptr[4];
tmp13 = wsptr[2] + wsptr[6]; tmp13 = wsptr[2] + wsptr[6];
tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13; tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT)1.414213562) - tmp13;
tmp0 = tmp10 + tmp13; tmp0 = tmp10 + tmp13;
tmp3 = tmp10 - tmp13; tmp3 = tmp10 - tmp13;
@ -212,11 +212,11 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info *compptr,
z12 = wsptr[1] - wsptr[7]; z12 = wsptr[1] - wsptr[7];
tmp7 = z11 + z13; tmp7 = z11 + z13;
tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); tmp11 = (z11 - z13) * ((FAST_FLOAT)1.414213562);
z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */ z5 = (z10 + z12) * ((FAST_FLOAT)1.847759065); /* 2*c2 */
tmp10 = z5 - z12 * ((FAST_FLOAT) 1.082392200); /* 2*(c2-c6) */ tmp10 = z5 - z12 * ((FAST_FLOAT)1.082392200); /* 2*(c2-c6) */
tmp12 = z5 - z10 * ((FAST_FLOAT) 2.613125930); /* 2*(c2+c6) */ tmp12 = z5 - z10 * ((FAST_FLOAT)2.613125930); /* 2*(c2+c6) */
tmp6 = tmp12 - tmp7; tmp6 = tmp12 - tmp7;
tmp5 = tmp11 - tmp6; tmp5 = tmp11 - tmp6;
@ -224,14 +224,14 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* Final output stage: float->int conversion and range-limit */ /* Final output stage: float->int conversion and range-limit */
outptr[0] = range_limit[((int) (tmp0 + tmp7)) & RANGE_MASK]; outptr[0] = range_limit[((int)(tmp0 + tmp7)) & RANGE_MASK];
outptr[7] = range_limit[((int) (tmp0 - tmp7)) & RANGE_MASK]; outptr[7] = range_limit[((int)(tmp0 - tmp7)) & RANGE_MASK];
outptr[1] = range_limit[((int) (tmp1 + tmp6)) & RANGE_MASK]; outptr[1] = range_limit[((int)(tmp1 + tmp6)) & RANGE_MASK];
outptr[6] = range_limit[((int) (tmp1 - tmp6)) & RANGE_MASK]; outptr[6] = range_limit[((int)(tmp1 - tmp6)) & RANGE_MASK];
outptr[2] = range_limit[((int) (tmp2 + tmp5)) & RANGE_MASK]; outptr[2] = range_limit[((int)(tmp2 + tmp5)) & RANGE_MASK];
outptr[5] = range_limit[((int) (tmp2 - tmp5)) & RANGE_MASK]; outptr[5] = range_limit[((int)(tmp2 - tmp5)) & RANGE_MASK];
outptr[3] = range_limit[((int) (tmp3 + tmp4)) & RANGE_MASK]; outptr[3] = range_limit[((int)(tmp3 + tmp4)) & RANGE_MASK];
outptr[4] = range_limit[((int) (tmp3 - tmp4)) & RANGE_MASK]; outptr[4] = range_limit[((int)(tmp3 - tmp4)) & RANGE_MASK];
wsptr += DCTSIZE; /* advance pointer to next row */ wsptr += DCTSIZE; /* advance pointer to next row */
} }

View File

@ -92,10 +92,10 @@
*/ */
#if CONST_BITS == 8 #if CONST_BITS == 8
#define FIX_1_082392200 ((JLONG) 277) /* FIX(1.082392200) */ #define FIX_1_082392200 ((JLONG)277) /* FIX(1.082392200) */
#define FIX_1_414213562 ((JLONG) 362) /* FIX(1.414213562) */ #define FIX_1_414213562 ((JLONG)362) /* FIX(1.414213562) */
#define FIX_1_847759065 ((JLONG) 473) /* FIX(1.847759065) */ #define FIX_1_847759065 ((JLONG)473) /* FIX(1.847759065) */
#define FIX_2_613125930 ((JLONG) 669) /* FIX(2.613125930) */ #define FIX_2_613125930 ((JLONG)669) /* FIX(2.613125930) */
#else #else
#define FIX_1_082392200 FIX(1.082392200) #define FIX_1_082392200 FIX(1.082392200)
#define FIX_1_414213562 FIX(1.414213562) #define FIX_1_414213562 FIX(1.414213562)
@ -111,7 +111,7 @@
#ifndef USE_ACCURATE_ROUNDING #ifndef USE_ACCURATE_ROUNDING
#undef DESCALE #undef DESCALE
#define DESCALE(x,n) RIGHT_SHIFT(x, n) #define DESCALE(x, n) RIGHT_SHIFT(x, n)
#endif #endif
@ -119,7 +119,7 @@
* descale to yield a DCTELEM result. * descale to yield a DCTELEM result.
*/ */
#define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS)) #define MULTIPLY(var, const) ((DCTELEM)DESCALE((var) * (const), CONST_BITS))
/* Dequantize a coefficient by multiplying it by the multiplier-table /* Dequantize a coefficient by multiplying it by the multiplier-table
@ -129,10 +129,10 @@
*/ */
#if BITS_IN_JSAMPLE == 8 #if BITS_IN_JSAMPLE == 8
#define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval)) #define DEQUANTIZE(coef, quantval) (((IFAST_MULT_TYPE)(coef)) * (quantval))
#else #else
#define DEQUANTIZE(coef,quantval) \ #define DEQUANTIZE(coef, quantval) \
DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS) DESCALE((coef) * (quantval), IFAST_SCALE_BITS - PASS1_BITS)
#endif #endif
@ -147,19 +147,19 @@
#else #else
#define DCTELEMBITS 32 /* DCTELEM must be 32 bits */ #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
#endif #endif
#define IRIGHT_SHIFT(x,shft) \ #define IRIGHT_SHIFT(x, shft) \
((ishift_temp = (x)) < 0 ? \ ((ishift_temp = (x)) < 0 ? \
(ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \ (ishift_temp >> (shft)) | ((~((DCTELEM)0)) << (DCTELEMBITS - (shft))) : \
(ishift_temp >> (shft))) (ishift_temp >> (shft)))
#else #else
#define ISHIFT_TEMPS #define ISHIFT_TEMPS
#define IRIGHT_SHIFT(x,shft) ((x) >> (shft)) #define IRIGHT_SHIFT(x, shft) ((x) >> (shft))
#endif #endif
#ifdef USE_ACCURATE_ROUNDING #ifdef USE_ACCURATE_ROUNDING
#define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n)) #define IDESCALE(x, n) ((int)IRIGHT_SHIFT((x) + (1 << ((n) - 1)), n))
#else #else
#define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n)) #define IDESCALE(x, n) ((int)IRIGHT_SHIFT(x, n))
#endif #endif
@ -168,9 +168,9 @@
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION output_col) JDIMENSION output_col)
{ {
DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
DCTELEM tmp10, tmp11, tmp12, tmp13; DCTELEM tmp10, tmp11, tmp12, tmp13;
@ -188,7 +188,7 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* Pass 1: process columns from input, store into work array. */ /* Pass 1: process columns from input, store into work array. */
inptr = coef_block; inptr = coef_block;
quantptr = (IFAST_MULT_TYPE *) compptr->dct_table; quantptr = (IFAST_MULT_TYPE *)compptr->dct_table;
wsptr = workspace; wsptr = workspace;
for (ctr = DCTSIZE; ctr > 0; ctr--) { for (ctr = DCTSIZE; ctr > 0; ctr--) {
/* Due to quantization, we will usually find that many of the input /* Due to quantization, we will usually find that many of the input
@ -200,21 +200,21 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info *compptr,
* column DCT calculations can be simplified this way. * column DCT calculations can be simplified this way.
*/ */
if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && if (inptr[DCTSIZE * 1] == 0 && inptr[DCTSIZE * 2] == 0 &&
inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && inptr[DCTSIZE * 3] == 0 && inptr[DCTSIZE * 4] == 0 &&
inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE * 5] == 0 && inptr[DCTSIZE * 6] == 0 &&
inptr[DCTSIZE*7] == 0) { inptr[DCTSIZE * 7] == 0) {
/* AC terms all zero */ /* AC terms all zero */
int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); int dcval = (int)DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
wsptr[DCTSIZE*0] = dcval; wsptr[DCTSIZE * 0] = dcval;
wsptr[DCTSIZE*1] = dcval; wsptr[DCTSIZE * 1] = dcval;
wsptr[DCTSIZE*2] = dcval; wsptr[DCTSIZE * 2] = dcval;
wsptr[DCTSIZE*3] = dcval; wsptr[DCTSIZE * 3] = dcval;
wsptr[DCTSIZE*4] = dcval; wsptr[DCTSIZE * 4] = dcval;
wsptr[DCTSIZE*5] = dcval; wsptr[DCTSIZE * 5] = dcval;
wsptr[DCTSIZE*6] = dcval; wsptr[DCTSIZE * 6] = dcval;
wsptr[DCTSIZE*7] = dcval; wsptr[DCTSIZE * 7] = dcval;
inptr++; /* advance pointers to next column */ inptr++; /* advance pointers to next column */
quantptr++; quantptr++;
@ -224,10 +224,10 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* Even part */ /* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); tmp0 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); tmp1 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); tmp2 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]);
tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); tmp3 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6]);
tmp10 = tmp0 + tmp2; /* phase 3 */ tmp10 = tmp0 + tmp2; /* phase 3 */
tmp11 = tmp0 - tmp2; tmp11 = tmp0 - tmp2;
@ -242,10 +242,10 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* Odd part */ /* Odd part */
tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); tmp4 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); tmp5 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); tmp6 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); tmp7 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
z13 = tmp6 + tmp5; /* phase 6 */ z13 = tmp6 + tmp5; /* phase 6 */
z10 = tmp6 - tmp5; z10 = tmp6 - tmp5;
@ -257,20 +257,20 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info *compptr,
z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */ tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */ tmp12 = MULTIPLY(z10, -FIX_2_613125930) + z5; /* -2*(c2+c6) */
tmp6 = tmp12 - tmp7; /* phase 2 */ tmp6 = tmp12 - tmp7; /* phase 2 */
tmp5 = tmp11 - tmp6; tmp5 = tmp11 - tmp6;
tmp4 = tmp10 + tmp5; tmp4 = tmp10 + tmp5;
wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7); wsptr[DCTSIZE * 0] = (int)(tmp0 + tmp7);
wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7); wsptr[DCTSIZE * 7] = (int)(tmp0 - tmp7);
wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6); wsptr[DCTSIZE * 1] = (int)(tmp1 + tmp6);
wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6); wsptr[DCTSIZE * 6] = (int)(tmp1 - tmp6);
wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5); wsptr[DCTSIZE * 2] = (int)(tmp2 + tmp5);
wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5); wsptr[DCTSIZE * 5] = (int)(tmp2 - tmp5);
wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4); wsptr[DCTSIZE * 4] = (int)(tmp3 + tmp4);
wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4); wsptr[DCTSIZE * 3] = (int)(tmp3 - tmp4);
inptr++; /* advance pointers to next column */ inptr++; /* advance pointers to next column */
quantptr++; quantptr++;
@ -296,8 +296,8 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info *compptr,
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 && if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
/* AC terms all zero */ /* AC terms all zero */
JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3) JSAMPLE dcval =
& RANGE_MASK]; range_limit[IDESCALE(wsptr[0], PASS1_BITS + 3) & RANGE_MASK];
outptr[0] = dcval; outptr[0] = dcval;
outptr[1] = dcval; outptr[1] = dcval;
@ -315,12 +315,12 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* Even part */ /* Even part */
tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]); tmp10 = ((DCTELEM)wsptr[0] + (DCTELEM)wsptr[4]);
tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]); tmp11 = ((DCTELEM)wsptr[0] - (DCTELEM)wsptr[4]);
tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]); tmp13 = ((DCTELEM)wsptr[2] + (DCTELEM)wsptr[6]);
tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562) tmp12 =
- tmp13; MULTIPLY((DCTELEM)wsptr[2] - (DCTELEM)wsptr[6], FIX_1_414213562) - tmp13;
tmp0 = tmp10 + tmp13; tmp0 = tmp10 + tmp13;
tmp3 = tmp10 - tmp13; tmp3 = tmp10 - tmp13;
@ -329,17 +329,17 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* Odd part */ /* Odd part */
z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3]; z13 = (DCTELEM)wsptr[5] + (DCTELEM)wsptr[3];
z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3]; z10 = (DCTELEM)wsptr[5] - (DCTELEM)wsptr[3];
z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7]; z11 = (DCTELEM)wsptr[1] + (DCTELEM)wsptr[7];
z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7]; z12 = (DCTELEM)wsptr[1] - (DCTELEM)wsptr[7];
tmp7 = z11 + z13; /* phase 5 */ tmp7 = z11 + z13; /* phase 5 */
tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */ tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */ tmp12 = MULTIPLY(z10, -FIX_2_613125930) + z5; /* -2*(c2+c6) */
tmp6 = tmp12 - tmp7; /* phase 2 */ tmp6 = tmp12 - tmp7; /* phase 2 */
tmp5 = tmp11 - tmp6; tmp5 = tmp11 - tmp6;
@ -347,22 +347,22 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* Final output stage: scale down by a factor of 8 and range-limit */ /* Final output stage: scale down by a factor of 8 and range-limit */
outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3) outptr[0] =
& RANGE_MASK]; range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS + 3) & RANGE_MASK];
outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3) outptr[7] =
& RANGE_MASK]; range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS + 3) & RANGE_MASK];
outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3) outptr[1] =
& RANGE_MASK]; range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS + 3) & RANGE_MASK];
outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3) outptr[6] =
& RANGE_MASK]; range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS + 3) & RANGE_MASK];
outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3) outptr[2] =
& RANGE_MASK]; range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS + 3) & RANGE_MASK];
outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3) outptr[5] =
& RANGE_MASK]; range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS + 3) & RANGE_MASK];
outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3) outptr[4] =
& RANGE_MASK]; range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS + 3) & RANGE_MASK];
outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3) outptr[3] =
& RANGE_MASK]; range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS + 3) & RANGE_MASK];
wsptr += DCTSIZE; /* advance pointer to next row */ wsptr += DCTSIZE; /* advance pointer to next row */
} }

File diff suppressed because it is too large Load Diff

View File

@ -58,20 +58,20 @@
*/ */
#if CONST_BITS == 13 #if CONST_BITS == 13
#define FIX_0_211164243 ((JLONG) 1730) /* FIX(0.211164243) */ #define FIX_0_211164243 ((JLONG)1730) /* FIX(0.211164243) */
#define FIX_0_509795579 ((JLONG) 4176) /* FIX(0.509795579) */ #define FIX_0_509795579 ((JLONG)4176) /* FIX(0.509795579) */
#define FIX_0_601344887 ((JLONG) 4926) /* FIX(0.601344887) */ #define FIX_0_601344887 ((JLONG)4926) /* FIX(0.601344887) */
#define FIX_0_720959822 ((JLONG) 5906) /* FIX(0.720959822) */ #define FIX_0_720959822 ((JLONG)5906) /* FIX(0.720959822) */
#define FIX_0_765366865 ((JLONG) 6270) /* FIX(0.765366865) */ #define FIX_0_765366865 ((JLONG)6270) /* FIX(0.765366865) */
#define FIX_0_850430095 ((JLONG) 6967) /* FIX(0.850430095) */ #define FIX_0_850430095 ((JLONG)6967) /* FIX(0.850430095) */
#define FIX_0_899976223 ((JLONG) 7373) /* FIX(0.899976223) */ #define FIX_0_899976223 ((JLONG)7373) /* FIX(0.899976223) */
#define FIX_1_061594337 ((JLONG) 8697) /* FIX(1.061594337) */ #define FIX_1_061594337 ((JLONG)8697) /* FIX(1.061594337) */
#define FIX_1_272758580 ((JLONG) 10426) /* FIX(1.272758580) */ #define FIX_1_272758580 ((JLONG)10426) /* FIX(1.272758580) */
#define FIX_1_451774981 ((JLONG) 11893) /* FIX(1.451774981) */ #define FIX_1_451774981 ((JLONG)11893) /* FIX(1.451774981) */
#define FIX_1_847759065 ((JLONG) 15137) /* FIX(1.847759065) */ #define FIX_1_847759065 ((JLONG)15137) /* FIX(1.847759065) */
#define FIX_2_172734803 ((JLONG) 17799) /* FIX(2.172734803) */ #define FIX_2_172734803 ((JLONG)17799) /* FIX(2.172734803) */
#define FIX_2_562915447 ((JLONG) 20995) /* FIX(2.562915447) */ #define FIX_2_562915447 ((JLONG)20995) /* FIX(2.562915447) */
#define FIX_3_624509785 ((JLONG) 29692) /* FIX(3.624509785) */ #define FIX_3_624509785 ((JLONG)29692) /* FIX(3.624509785) */
#else #else
#define FIX_0_211164243 FIX(0.211164243) #define FIX_0_211164243 FIX(0.211164243)
#define FIX_0_509795579 FIX(0.509795579) #define FIX_0_509795579 FIX(0.509795579)
@ -98,9 +98,9 @@
*/ */
#if BITS_IN_JSAMPLE == 8 #if BITS_IN_JSAMPLE == 8
#define MULTIPLY(var,const) MULTIPLY16C16(var,const) #define MULTIPLY(var, const) MULTIPLY16C16(var, const)
#else #else
#define MULTIPLY(var,const) ((var) * (const)) #define MULTIPLY(var, const) ((var) * (const))
#endif #endif
@ -109,7 +109,7 @@
* are 16 bits or less, so either int or short multiply will work. * are 16 bits or less, so either int or short multiply will work.
*/ */
#define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval)) #define DEQUANTIZE(coef, quantval) (((ISLOW_MULT_TYPE)(coef)) * (quantval))
/* /*
@ -118,9 +118,9 @@
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION output_col) JDIMENSION output_col)
{ {
JLONG tmp0, tmp2, tmp10, tmp12; JLONG tmp0, tmp2, tmp10, tmp12;
JLONG z1, z2, z3, z4; JLONG z1, z2, z3, z4;
@ -130,69 +130,73 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPROW outptr; JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo); JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr; int ctr;
int workspace[DCTSIZE*4]; /* buffers data between passes */ int workspace[DCTSIZE * 4]; /* buffers data between passes */
SHIFT_TEMPS SHIFT_TEMPS
/* Pass 1: process columns from input, store into work array. */ /* Pass 1: process columns from input, store into work array. */
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
wsptr = workspace; wsptr = workspace;
for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) { for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
/* Don't bother to process column 4, because second pass won't use it */ /* Don't bother to process column 4, because second pass won't use it */
if (ctr == DCTSIZE-4) if (ctr == DCTSIZE - 4)
continue; continue;
if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && if (inptr[DCTSIZE * 1] == 0 && inptr[DCTSIZE * 2] == 0 &&
inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE * 3] == 0 && inptr[DCTSIZE * 5] == 0 &&
inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) { inptr[DCTSIZE * 6] == 0 && inptr[DCTSIZE * 7] == 0) {
/* AC terms all zero; we need not examine term 4 for 4x4 output */ /* AC terms all zero; we need not examine term 4 for 4x4 output */
int dcval = LEFT_SHIFT(DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]), int dcval = LEFT_SHIFT(DEQUANTIZE(inptr[DCTSIZE * 0],
PASS1_BITS); quantptr[DCTSIZE * 0]), PASS1_BITS);
wsptr[DCTSIZE*0] = dcval; wsptr[DCTSIZE * 0] = dcval;
wsptr[DCTSIZE*1] = dcval; wsptr[DCTSIZE * 1] = dcval;
wsptr[DCTSIZE*2] = dcval; wsptr[DCTSIZE * 2] = dcval;
wsptr[DCTSIZE*3] = dcval; wsptr[DCTSIZE * 3] = dcval;
continue; continue;
} }
/* Even part */ /* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); tmp0 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
tmp0 = LEFT_SHIFT(tmp0, CONST_BITS+1); tmp0 = LEFT_SHIFT(tmp0, CONST_BITS + 1);
z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); z2 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); z3 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6]);
tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865); tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, -FIX_0_765366865);
tmp10 = tmp0 + tmp2; tmp10 = tmp0 + tmp2;
tmp12 = tmp0 - tmp2; tmp12 = tmp0 - tmp2;
/* Odd part */ /* Odd part */
z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); z1 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); z2 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); z3 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); z4 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */ tmp0 = MULTIPLY(z1, -FIX_0_211164243) + /* sqrt(2) * ( c3-c1) */
+ MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */ MULTIPLY(z2, FIX_1_451774981) + /* sqrt(2) * ( c3+c7) */
+ MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */ MULTIPLY(z3, -FIX_2_172734803) + /* sqrt(2) * (-c1-c5) */
+ MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */ MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * ( c5+c7) */
tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */ tmp2 = MULTIPLY(z1, -FIX_0_509795579) + /* sqrt(2) * (c7-c5) */
+ MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */ MULTIPLY(z2, -FIX_0_601344887) + /* sqrt(2) * (c5-c1) */
+ MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */ MULTIPLY(z3, FIX_0_899976223) + /* sqrt(2) * (c3-c7) */
+ MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */ MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
/* Final output stage */ /* Final output stage */
wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1); wsptr[DCTSIZE * 0] =
wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1); (int)DESCALE(tmp10 + tmp2, CONST_BITS - PASS1_BITS + 1);
wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1); wsptr[DCTSIZE * 3] =
wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1); (int)DESCALE(tmp10 - tmp2, CONST_BITS - PASS1_BITS + 1);
wsptr[DCTSIZE * 1] =
(int)DESCALE(tmp12 + tmp0, CONST_BITS - PASS1_BITS + 1);
wsptr[DCTSIZE * 2] =
(int)DESCALE(tmp12 - tmp0, CONST_BITS - PASS1_BITS + 1);
} }
/* Pass 2: process 4 rows from work array, store into output array. */ /* Pass 2: process 4 rows from work array, store into output array. */
@ -206,8 +210,8 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info *compptr,
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
/* AC terms all zero */ /* AC terms all zero */
JSAMPLE dcval = range_limit[(int) DESCALE((JLONG) wsptr[0], PASS1_BITS+3) JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
& RANGE_MASK]; PASS1_BITS + 3) & RANGE_MASK];
outptr[0] = dcval; outptr[0] = dcval;
outptr[1] = dcval; outptr[1] = dcval;
@ -221,45 +225,45 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* Even part */ /* Even part */
tmp0 = LEFT_SHIFT((JLONG) wsptr[0], CONST_BITS+1); tmp0 = LEFT_SHIFT((JLONG)wsptr[0], CONST_BITS + 1);
tmp2 = MULTIPLY((JLONG) wsptr[2], FIX_1_847759065) tmp2 = MULTIPLY((JLONG)wsptr[2], FIX_1_847759065) +
+ MULTIPLY((JLONG) wsptr[6], - FIX_0_765366865); MULTIPLY((JLONG)wsptr[6], -FIX_0_765366865);
tmp10 = tmp0 + tmp2; tmp10 = tmp0 + tmp2;
tmp12 = tmp0 - tmp2; tmp12 = tmp0 - tmp2;
/* Odd part */ /* Odd part */
z1 = (JLONG) wsptr[7]; z1 = (JLONG)wsptr[7];
z2 = (JLONG) wsptr[5]; z2 = (JLONG)wsptr[5];
z3 = (JLONG) wsptr[3]; z3 = (JLONG)wsptr[3];
z4 = (JLONG) wsptr[1]; z4 = (JLONG)wsptr[1];
tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */ tmp0 = MULTIPLY(z1, -FIX_0_211164243) + /* sqrt(2) * ( c3-c1) */
+ MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */ MULTIPLY(z2, FIX_1_451774981) + /* sqrt(2) * ( c3+c7) */
+ MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */ MULTIPLY(z3, -FIX_2_172734803) + /* sqrt(2) * (-c1-c5) */
+ MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */ MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * ( c5+c7) */
tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */ tmp2 = MULTIPLY(z1, -FIX_0_509795579) + /* sqrt(2) * (c7-c5) */
+ MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */ MULTIPLY(z2, -FIX_0_601344887) + /* sqrt(2) * (c5-c1) */
+ MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */ MULTIPLY(z3, FIX_0_899976223) + /* sqrt(2) * (c3-c7) */
+ MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */ MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
/* Final output stage */ /* Final output stage */
outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2, outptr[0] = range_limit[(int)DESCALE(tmp10 + tmp2,
CONST_BITS+PASS1_BITS+3+1) CONST_BITS + PASS1_BITS + 3 + 1) &
& RANGE_MASK]; RANGE_MASK];
outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2, outptr[3] = range_limit[(int)DESCALE(tmp10 - tmp2,
CONST_BITS+PASS1_BITS+3+1) CONST_BITS + PASS1_BITS + 3 + 1) &
& RANGE_MASK]; RANGE_MASK];
outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0, outptr[1] = range_limit[(int)DESCALE(tmp12 + tmp0,
CONST_BITS+PASS1_BITS+3+1) CONST_BITS + PASS1_BITS + 3 + 1) &
& RANGE_MASK]; RANGE_MASK];
outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0, outptr[2] = range_limit[(int)DESCALE(tmp12 - tmp0,
CONST_BITS+PASS1_BITS+3+1) CONST_BITS + PASS1_BITS + 3 + 1) &
& RANGE_MASK]; RANGE_MASK];
wsptr += DCTSIZE; /* advance pointer to next row */ wsptr += DCTSIZE; /* advance pointer to next row */
} }
@ -272,9 +276,9 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION output_col) JDIMENSION output_col)
{ {
JLONG tmp0, tmp10, z1; JLONG tmp0, tmp10, z1;
JCOEFPTR inptr; JCOEFPTR inptr;
@ -283,50 +287,52 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPROW outptr; JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo); JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr; int ctr;
int workspace[DCTSIZE*2]; /* buffers data between passes */ int workspace[DCTSIZE * 2]; /* buffers data between passes */
SHIFT_TEMPS SHIFT_TEMPS
/* Pass 1: process columns from input, store into work array. */ /* Pass 1: process columns from input, store into work array. */
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
wsptr = workspace; wsptr = workspace;
for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) { for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
/* Don't bother to process columns 2,4,6 */ /* Don't bother to process columns 2,4,6 */
if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6) if (ctr == DCTSIZE - 2 || ctr == DCTSIZE - 4 || ctr == DCTSIZE - 6)
continue; continue;
if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 && if (inptr[DCTSIZE * 1] == 0 && inptr[DCTSIZE * 3] == 0 &&
inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) { inptr[DCTSIZE * 5] == 0 && inptr[DCTSIZE * 7] == 0) {
/* AC terms all zero; we need not examine terms 2,4,6 for 2x2 output */ /* AC terms all zero; we need not examine terms 2,4,6 for 2x2 output */
int dcval = LEFT_SHIFT(DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]), int dcval = LEFT_SHIFT(DEQUANTIZE(inptr[DCTSIZE * 0],
PASS1_BITS); quantptr[DCTSIZE * 0]), PASS1_BITS);
wsptr[DCTSIZE*0] = dcval; wsptr[DCTSIZE * 0] = dcval;
wsptr[DCTSIZE*1] = dcval; wsptr[DCTSIZE * 1] = dcval;
continue; continue;
} }
/* Even part */ /* Even part */
z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); z1 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
tmp10 = LEFT_SHIFT(z1, CONST_BITS+2); tmp10 = LEFT_SHIFT(z1, CONST_BITS + 2);
/* Odd part */ /* Odd part */
z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); z1 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */ tmp0 = MULTIPLY(z1, -FIX_0_720959822); /* sqrt(2) * ( c7-c5+c3-c1) */
z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); z1 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */ tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); z1 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */ tmp0 += MULTIPLY(z1, -FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); z1 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */ tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * ( c1+c3+c5+c7) */
/* Final output stage */ /* Final output stage */
wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2); wsptr[DCTSIZE * 0] =
wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2); (int)DESCALE(tmp10 + tmp0, CONST_BITS - PASS1_BITS + 2);
wsptr[DCTSIZE * 1] =
(int)DESCALE(tmp10 - tmp0, CONST_BITS - PASS1_BITS + 2);
} }
/* Pass 2: process 2 rows from work array, store into output array. */ /* Pass 2: process 2 rows from work array, store into output array. */
@ -339,8 +345,8 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info *compptr,
#ifndef NO_ZERO_ROW_TEST #ifndef NO_ZERO_ROW_TEST
if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) { if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
/* AC terms all zero */ /* AC terms all zero */
JSAMPLE dcval = range_limit[(int) DESCALE((JLONG) wsptr[0], PASS1_BITS+3) JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
& RANGE_MASK]; PASS1_BITS + 3) & RANGE_MASK];
outptr[0] = dcval; outptr[0] = dcval;
outptr[1] = dcval; outptr[1] = dcval;
@ -352,23 +358,23 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* Even part */ /* Even part */
tmp10 = LEFT_SHIFT((JLONG) wsptr[0], CONST_BITS+2); tmp10 = LEFT_SHIFT((JLONG)wsptr[0], CONST_BITS + 2);
/* Odd part */ /* Odd part */
tmp0 = MULTIPLY((JLONG) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */ tmp0 = MULTIPLY((JLONG)wsptr[7], -FIX_0_720959822) + /* sqrt(2) * ( c7-c5+c3-c1) */
+ MULTIPLY((JLONG) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */ MULTIPLY((JLONG)wsptr[5], FIX_0_850430095) + /* sqrt(2) * (-c1+c3+c5+c7) */
+ MULTIPLY((JLONG) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */ MULTIPLY((JLONG)wsptr[3], -FIX_1_272758580) + /* sqrt(2) * (-c1+c3-c5-c7) */
+ MULTIPLY((JLONG) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */ MULTIPLY((JLONG)wsptr[1], FIX_3_624509785); /* sqrt(2) * ( c1+c3+c5+c7) */
/* Final output stage */ /* Final output stage */
outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0, outptr[0] = range_limit[(int)DESCALE(tmp10 + tmp0,
CONST_BITS+PASS1_BITS+3+2) CONST_BITS + PASS1_BITS + 3 + 2) &
& RANGE_MASK]; RANGE_MASK];
outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0, outptr[1] = range_limit[(int)DESCALE(tmp10 - tmp0,
CONST_BITS+PASS1_BITS+3+2) CONST_BITS + PASS1_BITS + 3 + 2) &
& RANGE_MASK]; RANGE_MASK];
wsptr += DCTSIZE; /* advance pointer to next row */ wsptr += DCTSIZE; /* advance pointer to next row */
} }
@ -381,9 +387,9 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_idct_1x1(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION output_col) JDIMENSION output_col)
{ {
int dcval; int dcval;
ISLOW_MULT_TYPE *quantptr; ISLOW_MULT_TYPE *quantptr;
@ -393,9 +399,9 @@ jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* We hardly need an inverse DCT routine for this: just take the /* We hardly need an inverse DCT routine for this: just take the
* average pixel value, which is one-eighth of the DC coefficient. * average pixel value, which is one-eighth of the DC coefficient.
*/ */
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *)compptr->dct_table;
dcval = DEQUANTIZE(coef_block[0], quantptr[0]); dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
dcval = (int) DESCALE((JLONG) dcval, 3); dcval = (int)DESCALE((JLONG)dcval, 3);
output_buf[0][output_col] = range_limit[dcval & RANGE_MASK]; output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
} }

View File

@ -61,14 +61,18 @@
#ifdef NEED_BSD_STRINGS #ifdef NEED_BSD_STRINGS
#include <strings.h> #include <strings.h>
#define MEMZERO(target,size) bzero((void *)(target), (size_t)(size)) #define MEMZERO(target, size) \
#define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size)) bzero((void *)(target), (size_t)(size))
#define MEMCOPY(dest, src, size) \
bcopy((const void *)(src), (void *)(dest), (size_t)(size))
#else /* not BSD, assume ANSI/SysV string lib */ #else /* not BSD, assume ANSI/SysV string lib */
#include <string.h> #include <string.h>
#define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size)) #define MEMZERO(target, size) \
#define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size)) memset((void *)(target), 0, (size_t)(size))
#define MEMCOPY(dest, src, size) \
memcpy((void *)(dest), (const void *)(src), (size_t)(size))
#endif #endif
@ -78,7 +82,7 @@
* CAUTION: argument order is different from underlying functions! * CAUTION: argument order is different from underlying functions!
*/ */
#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)))

View File

@ -32,20 +32,20 @@
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jmemsys.h" /* import the system-dependent declarations */ #include "jmemsys.h" /* import the system-dependent declarations */
#ifndef _WIN32 #if !defined(_MSC_VER) || _MSC_VER > 1600
#include <stdint.h> #include <stdint.h>
#endif #endif
#include <limits.h> #include <limits.h>
#ifndef NO_GETENV #ifndef NO_GETENV
#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */ #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
extern char *getenv (const char *name); extern char *getenv(const char *name);
#endif #endif
#endif #endif
LOCAL(size_t) LOCAL(size_t)
round_up_pow2 (size_t a, size_t b) round_up_pow2(size_t a, size_t b)
/* a rounded up to the next multiple of b, i.e. ceil(a/b)*b */ /* a rounded up to the next multiple of b, i.e. ceil(a/b)*b */
/* Assumes a >= 0, b > 0, and b is a power of 2 */ /* Assumes a >= 0, b > 0, and b is a power of 2 */
{ {
@ -89,7 +89,9 @@ round_up_pow2 (size_t a, size_t b)
#ifndef WITH_SIMD #ifndef WITH_SIMD
#define ALIGN_SIZE sizeof(double) #define ALIGN_SIZE sizeof(double)
#else #else
#define ALIGN_SIZE 16 /* Most SIMD implementations require this */ #define ALIGN_SIZE 32 /* Most of the SIMD instructions we support require
16-byte (128-bit) alignment, but AVX2 requires
32-byte alignment. */
#endif #endif
#endif #endif
@ -191,9 +193,9 @@ struct jvirt_barray_control {
#ifdef MEM_STATS /* optional extra stuff for statistics */ #ifdef MEM_STATS /* optional extra stuff for statistics */
LOCAL(void) LOCAL(void)
print_mem_stats (j_common_ptr cinfo, int pool_id) print_mem_stats(j_common_ptr cinfo, int pool_id)
{ {
my_mem_ptr mem = (my_mem_ptr) cinfo->mem; my_mem_ptr mem = (my_mem_ptr)cinfo->mem;
small_pool_ptr shdr_ptr; small_pool_ptr shdr_ptr;
large_pool_ptr lhdr_ptr; large_pool_ptr lhdr_ptr;
@ -206,15 +208,13 @@ print_mem_stats (j_common_ptr cinfo, int pool_id)
for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL; for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
lhdr_ptr = lhdr_ptr->next) { lhdr_ptr = lhdr_ptr->next) {
fprintf(stderr, " Large chunk used %ld\n", fprintf(stderr, " Large chunk used %ld\n", (long)lhdr_ptr->bytes_used);
(long) lhdr_ptr->bytes_used);
} }
for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL; for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
shdr_ptr = shdr_ptr->next) { shdr_ptr = shdr_ptr->next) {
fprintf(stderr, " Small chunk used %ld free %ld\n", fprintf(stderr, " Small chunk used %ld free %ld\n",
(long) shdr_ptr->bytes_used, (long)shdr_ptr->bytes_used, (long)shdr_ptr->bytes_left);
(long) shdr_ptr->bytes_left);
} }
} }
@ -222,7 +222,7 @@ print_mem_stats (j_common_ptr cinfo, int pool_id)
LOCAL(void) LOCAL(void)
out_of_memory (j_common_ptr cinfo, int which) out_of_memory(j_common_ptr cinfo, int which)
/* Report an out-of-memory error and stop execution */ /* Report an out-of-memory error and stop execution */
/* If we compiled MEM_STATS support, report alloc requests before dying */ /* If we compiled MEM_STATS support, report alloc requests before dying */
{ {
@ -250,14 +250,12 @@ out_of_memory (j_common_ptr cinfo, int which)
* adjustment. * adjustment.
*/ */
static const size_t first_pool_slop[JPOOL_NUMPOOLS] = static const size_t first_pool_slop[JPOOL_NUMPOOLS] = {
{
1600, /* first PERMANENT pool */ 1600, /* first PERMANENT pool */
16000 /* first IMAGE pool */ 16000 /* first IMAGE pool */
}; };
static const size_t extra_pool_slop[JPOOL_NUMPOOLS] = static const size_t extra_pool_slop[JPOOL_NUMPOOLS] = {
{
0, /* additional PERMANENT pools */ 0, /* additional PERMANENT pools */
5000 /* additional IMAGE pools */ 5000 /* additional IMAGE pools */
}; };
@ -266,10 +264,10 @@ static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
METHODDEF(void *) METHODDEF(void *)
alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject) alloc_small(j_common_ptr cinfo, int pool_id, size_t sizeofobject)
/* Allocate a "small" object */ /* Allocate a "small" object */
{ {
my_mem_ptr mem = (my_mem_ptr) cinfo->mem; my_mem_ptr mem = (my_mem_ptr)cinfo->mem;
small_pool_ptr hdr_ptr, prev_hdr_ptr; small_pool_ptr hdr_ptr, prev_hdr_ptr;
char *data_ptr; char *data_ptr;
size_t min_request, slop; size_t min_request, slop;
@ -313,11 +311,11 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
else else
slop = extra_pool_slop[pool_id]; slop = extra_pool_slop[pool_id];
/* Don't ask for more than MAX_ALLOC_CHUNK */ /* Don't ask for more than MAX_ALLOC_CHUNK */
if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request)) if (slop > (size_t)(MAX_ALLOC_CHUNK - min_request))
slop = (size_t) (MAX_ALLOC_CHUNK-min_request); slop = (size_t)(MAX_ALLOC_CHUNK - min_request);
/* Try to get space, if fail reduce slop and try again */ /* Try to get space, if fail reduce slop and try again */
for (;;) { for (;;) {
hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop); hdr_ptr = (small_pool_ptr)jpeg_get_small(cinfo, min_request + slop);
if (hdr_ptr != NULL) if (hdr_ptr != NULL)
break; break;
slop /= 2; slop /= 2;
@ -336,7 +334,7 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
} }
/* OK, allocate the object from the current pool */ /* OK, allocate the object from the current pool */
data_ptr = (char *) hdr_ptr; /* point to first data byte in pool... */ data_ptr = (char *)hdr_ptr; /* point to first data byte in pool... */
data_ptr += sizeof(small_pool_hdr); /* ...by skipping the header... */ data_ptr += sizeof(small_pool_hdr); /* ...by skipping the header... */
if ((size_t)data_ptr % ALIGN_SIZE) /* ...and adjust for alignment */ if ((size_t)data_ptr % ALIGN_SIZE) /* ...and adjust for alignment */
data_ptr += ALIGN_SIZE - (size_t)data_ptr % ALIGN_SIZE; data_ptr += ALIGN_SIZE - (size_t)data_ptr % ALIGN_SIZE;
@ -344,7 +342,7 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
hdr_ptr->bytes_used += sizeofobject; hdr_ptr->bytes_used += sizeofobject;
hdr_ptr->bytes_left -= sizeofobject; hdr_ptr->bytes_left -= sizeofobject;
return (void *) data_ptr; return (void *)data_ptr;
} }
@ -362,10 +360,10 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
*/ */
METHODDEF(void *) METHODDEF(void *)
alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject) alloc_large(j_common_ptr cinfo, int pool_id, size_t sizeofobject)
/* Allocate a "large" object */ /* Allocate a "large" object */
{ {
my_mem_ptr mem = (my_mem_ptr) cinfo->mem; my_mem_ptr mem = (my_mem_ptr)cinfo->mem;
large_pool_ptr hdr_ptr; large_pool_ptr hdr_ptr;
char *data_ptr; char *data_ptr;
@ -390,7 +388,7 @@ alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS) if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject + hdr_ptr = (large_pool_ptr)jpeg_get_large(cinfo, sizeofobject +
sizeof(large_pool_hdr) + sizeof(large_pool_hdr) +
ALIGN_SIZE - 1); ALIGN_SIZE - 1);
if (hdr_ptr == NULL) if (hdr_ptr == NULL)
@ -407,12 +405,12 @@ alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
hdr_ptr->bytes_left = 0; hdr_ptr->bytes_left = 0;
mem->large_list[pool_id] = hdr_ptr; mem->large_list[pool_id] = hdr_ptr;
data_ptr = (char *) hdr_ptr; /* point to first data byte in pool... */ data_ptr = (char *)hdr_ptr; /* point to first data byte in pool... */
data_ptr += sizeof(small_pool_hdr); /* ...by skipping the header... */ data_ptr += sizeof(small_pool_hdr); /* ...by skipping the header... */
if ((size_t)data_ptr % ALIGN_SIZE) /* ...and adjust for alignment */ if ((size_t)data_ptr % ALIGN_SIZE) /* ...and adjust for alignment */
data_ptr += ALIGN_SIZE - (size_t)data_ptr % ALIGN_SIZE; data_ptr += ALIGN_SIZE - (size_t)data_ptr % ALIGN_SIZE;
return (void *) data_ptr; return (void *)data_ptr;
} }
@ -433,11 +431,11 @@ alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
*/ */
METHODDEF(JSAMPARRAY) METHODDEF(JSAMPARRAY)
alloc_sarray (j_common_ptr cinfo, int pool_id, alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow,
JDIMENSION samplesperrow, JDIMENSION numrows) JDIMENSION numrows)
/* Allocate a 2-D sample array */ /* Allocate a 2-D sample array */
{ {
my_mem_ptr mem = (my_mem_ptr) cinfo->mem; my_mem_ptr mem = (my_mem_ptr)cinfo->mem;
JSAMPARRAY result; JSAMPARRAY result;
JSAMPROW workspace; JSAMPROW workspace;
JDIMENSION rowsperchunk, currow, i; JDIMENSION rowsperchunk, currow, i;
@ -456,27 +454,27 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
sizeof(JSAMPLE)); sizeof(JSAMPLE));
/* Calculate max # of rows allowed in one allocation chunk */ /* Calculate max # of rows allowed in one allocation chunk */
ltemp = (MAX_ALLOC_CHUNK-sizeof(large_pool_hdr)) / ltemp = (MAX_ALLOC_CHUNK - sizeof(large_pool_hdr)) /
((long) samplesperrow * sizeof(JSAMPLE)); ((long)samplesperrow * sizeof(JSAMPLE));
if (ltemp <= 0) if (ltemp <= 0)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
if (ltemp < (long) numrows) if (ltemp < (long)numrows)
rowsperchunk = (JDIMENSION) ltemp; rowsperchunk = (JDIMENSION)ltemp;
else else
rowsperchunk = numrows; rowsperchunk = numrows;
mem->last_rowsperchunk = rowsperchunk; mem->last_rowsperchunk = rowsperchunk;
/* Get space for row pointers (small object) */ /* Get space for row pointers (small object) */
result = (JSAMPARRAY) alloc_small(cinfo, pool_id, result = (JSAMPARRAY)alloc_small(cinfo, pool_id,
(size_t) (numrows * sizeof(JSAMPROW))); (size_t)(numrows * sizeof(JSAMPROW)));
/* Get the rows themselves (large objects) */ /* Get the rows themselves (large objects) */
currow = 0; currow = 0;
while (currow < numrows) { while (currow < numrows) {
rowsperchunk = MIN(rowsperchunk, numrows - currow); rowsperchunk = MIN(rowsperchunk, numrows - currow);
workspace = (JSAMPROW) alloc_large(cinfo, pool_id, workspace = (JSAMPROW)alloc_large(cinfo, pool_id,
(size_t) ((size_t) rowsperchunk * (size_t) samplesperrow (size_t)((size_t)rowsperchunk * (size_t)samplesperrow *
* sizeof(JSAMPLE))); sizeof(JSAMPLE)));
for (i = rowsperchunk; i > 0; i--) { for (i = rowsperchunk; i > 0; i--) {
result[currow++] = workspace; result[currow++] = workspace;
workspace += samplesperrow; workspace += samplesperrow;
@ -493,11 +491,11 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
*/ */
METHODDEF(JBLOCKARRAY) METHODDEF(JBLOCKARRAY)
alloc_barray (j_common_ptr cinfo, int pool_id, alloc_barray(j_common_ptr cinfo, int pool_id, JDIMENSION blocksperrow,
JDIMENSION blocksperrow, JDIMENSION numrows) JDIMENSION numrows)
/* Allocate a 2-D coefficient-block array */ /* Allocate a 2-D coefficient-block array */
{ {
my_mem_ptr mem = (my_mem_ptr) cinfo->mem; my_mem_ptr mem = (my_mem_ptr)cinfo->mem;
JBLOCKARRAY result; JBLOCKARRAY result;
JBLOCKROW workspace; JBLOCKROW workspace;
JDIMENSION rowsperchunk, currow, i; JDIMENSION rowsperchunk, currow, i;
@ -508,27 +506,27 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
out_of_memory(cinfo, 6); /* safety check */ out_of_memory(cinfo, 6); /* safety check */
/* Calculate max # of rows allowed in one allocation chunk */ /* Calculate max # of rows allowed in one allocation chunk */
ltemp = (MAX_ALLOC_CHUNK-sizeof(large_pool_hdr)) / ltemp = (MAX_ALLOC_CHUNK - sizeof(large_pool_hdr)) /
((long) blocksperrow * sizeof(JBLOCK)); ((long)blocksperrow * sizeof(JBLOCK));
if (ltemp <= 0) if (ltemp <= 0)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
if (ltemp < (long) numrows) if (ltemp < (long)numrows)
rowsperchunk = (JDIMENSION) ltemp; rowsperchunk = (JDIMENSION)ltemp;
else else
rowsperchunk = numrows; rowsperchunk = numrows;
mem->last_rowsperchunk = rowsperchunk; mem->last_rowsperchunk = rowsperchunk;
/* Get space for row pointers (small object) */ /* Get space for row pointers (small object) */
result = (JBLOCKARRAY) alloc_small(cinfo, pool_id, result = (JBLOCKARRAY)alloc_small(cinfo, pool_id,
(size_t) (numrows * sizeof(JBLOCKROW))); (size_t)(numrows * sizeof(JBLOCKROW)));
/* Get the rows themselves (large objects) */ /* Get the rows themselves (large objects) */
currow = 0; currow = 0;
while (currow < numrows) { while (currow < numrows) {
rowsperchunk = MIN(rowsperchunk, numrows - currow); rowsperchunk = MIN(rowsperchunk, numrows - currow);
workspace = (JBLOCKROW) alloc_large(cinfo, pool_id, workspace = (JBLOCKROW)alloc_large(cinfo, pool_id,
(size_t) ((size_t) rowsperchunk * (size_t) blocksperrow (size_t)((size_t)rowsperchunk * (size_t)blocksperrow *
* sizeof(JBLOCK))); sizeof(JBLOCK)));
for (i = rowsperchunk; i > 0; i--) { for (i = rowsperchunk; i > 0; i--) {
result[currow++] = workspace; result[currow++] = workspace;
workspace += blocksperrow; workspace += blocksperrow;
@ -577,12 +575,12 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
METHODDEF(jvirt_sarray_ptr) METHODDEF(jvirt_sarray_ptr)
request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero, request_virt_sarray(j_common_ptr cinfo, int pool_id, boolean pre_zero,
JDIMENSION samplesperrow, JDIMENSION numrows, JDIMENSION samplesperrow, JDIMENSION numrows,
JDIMENSION maxaccess) JDIMENSION maxaccess)
/* Request a virtual 2-D sample array */ /* Request a virtual 2-D sample array */
{ {
my_mem_ptr mem = (my_mem_ptr) cinfo->mem; my_mem_ptr mem = (my_mem_ptr)cinfo->mem;
jvirt_sarray_ptr result; jvirt_sarray_ptr result;
/* Only IMAGE-lifetime virtual arrays are currently supported */ /* Only IMAGE-lifetime virtual arrays are currently supported */
@ -590,7 +588,7 @@ request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
/* get control block */ /* get control block */
result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id, result = (jvirt_sarray_ptr)alloc_small(cinfo, pool_id,
sizeof(struct jvirt_sarray_control)); sizeof(struct jvirt_sarray_control));
result->mem_buffer = NULL; /* marks array not yet realized */ result->mem_buffer = NULL; /* marks array not yet realized */
@ -607,12 +605,12 @@ request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
METHODDEF(jvirt_barray_ptr) METHODDEF(jvirt_barray_ptr)
request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero, request_virt_barray(j_common_ptr cinfo, int pool_id, boolean pre_zero,
JDIMENSION blocksperrow, JDIMENSION numrows, JDIMENSION blocksperrow, JDIMENSION numrows,
JDIMENSION maxaccess) JDIMENSION maxaccess)
/* Request a virtual 2-D coefficient-block array */ /* Request a virtual 2-D coefficient-block array */
{ {
my_mem_ptr mem = (my_mem_ptr) cinfo->mem; my_mem_ptr mem = (my_mem_ptr)cinfo->mem;
jvirt_barray_ptr result; jvirt_barray_ptr result;
/* Only IMAGE-lifetime virtual arrays are currently supported */ /* Only IMAGE-lifetime virtual arrays are currently supported */
@ -620,7 +618,7 @@ request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
/* get control block */ /* get control block */
result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id, result = (jvirt_barray_ptr)alloc_small(cinfo, pool_id,
sizeof(struct jvirt_barray_control)); sizeof(struct jvirt_barray_control));
result->mem_buffer = NULL; /* marks array not yet realized */ result->mem_buffer = NULL; /* marks array not yet realized */
@ -637,10 +635,10 @@ request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
METHODDEF(void) METHODDEF(void)
realize_virt_arrays (j_common_ptr cinfo) realize_virt_arrays(j_common_ptr cinfo)
/* Allocate the in-memory buffers for any unrealized virtual arrays */ /* Allocate the in-memory buffers for any unrealized virtual arrays */
{ {
my_mem_ptr mem = (my_mem_ptr) cinfo->mem; my_mem_ptr mem = (my_mem_ptr)cinfo->mem;
size_t space_per_minheight, maximum_space, avail_mem; size_t space_per_minheight, maximum_space, avail_mem;
size_t minheights, max_minheights; size_t minheights, max_minheights;
jvirt_sarray_ptr sptr; jvirt_sarray_ptr sptr;
@ -654,11 +652,11 @@ realize_virt_arrays (j_common_ptr cinfo)
maximum_space = 0; maximum_space = 0;
for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) { for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
if (sptr->mem_buffer == NULL) { /* if not realized yet */ if (sptr->mem_buffer == NULL) { /* if not realized yet */
size_t new_space = (long) sptr->rows_in_array * size_t new_space = (long)sptr->rows_in_array *
(long) sptr->samplesperrow * sizeof(JSAMPLE); (long)sptr->samplesperrow * sizeof(JSAMPLE);
space_per_minheight += (long) sptr->maxaccess * space_per_minheight += (long)sptr->maxaccess *
(long) sptr->samplesperrow * sizeof(JSAMPLE); (long)sptr->samplesperrow * sizeof(JSAMPLE);
if (SIZE_MAX - maximum_space < new_space) if (SIZE_MAX - maximum_space < new_space)
out_of_memory(cinfo, 10); out_of_memory(cinfo, 10);
maximum_space += new_space; maximum_space += new_space;
@ -666,11 +664,11 @@ realize_virt_arrays (j_common_ptr cinfo)
} }
for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) { for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
if (bptr->mem_buffer == NULL) { /* if not realized yet */ if (bptr->mem_buffer == NULL) { /* if not realized yet */
size_t new_space = (long) bptr->rows_in_array * size_t new_space = (long)bptr->rows_in_array *
(long) bptr->blocksperrow * sizeof(JBLOCK); (long)bptr->blocksperrow * sizeof(JBLOCK);
space_per_minheight += (long) bptr->maxaccess * space_per_minheight += (long)bptr->maxaccess *
(long) bptr->blocksperrow * sizeof(JBLOCK); (long)bptr->blocksperrow * sizeof(JBLOCK);
if (SIZE_MAX - maximum_space < new_space) if (SIZE_MAX - maximum_space < new_space)
out_of_memory(cinfo, 11); out_of_memory(cinfo, 11);
maximum_space += new_space; maximum_space += new_space;
@ -703,17 +701,17 @@ realize_virt_arrays (j_common_ptr cinfo)
for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) { for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
if (sptr->mem_buffer == NULL) { /* if not realized yet */ if (sptr->mem_buffer == NULL) { /* if not realized yet */
minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L; minheights = ((long)sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
if (minheights <= max_minheights) { if (minheights <= max_minheights) {
/* This buffer fits in memory */ /* This buffer fits in memory */
sptr->rows_in_mem = sptr->rows_in_array; sptr->rows_in_mem = sptr->rows_in_array;
} else { } else {
/* It doesn't fit in memory, create backing store. */ /* It doesn't fit in memory, create backing store. */
sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess); sptr->rows_in_mem = (JDIMENSION)(max_minheights * sptr->maxaccess);
jpeg_open_backing_store(cinfo, & sptr->b_s_info, jpeg_open_backing_store(cinfo, &sptr->b_s_info,
(long) sptr->rows_in_array * (long)sptr->rows_in_array *
(long) sptr->samplesperrow * (long)sptr->samplesperrow *
(long) sizeof(JSAMPLE)); (long)sizeof(JSAMPLE));
sptr->b_s_open = TRUE; sptr->b_s_open = TRUE;
} }
sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE, sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
@ -727,17 +725,17 @@ realize_virt_arrays (j_common_ptr cinfo)
for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) { for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
if (bptr->mem_buffer == NULL) { /* if not realized yet */ if (bptr->mem_buffer == NULL) { /* if not realized yet */
minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L; minheights = ((long)bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
if (minheights <= max_minheights) { if (minheights <= max_minheights) {
/* This buffer fits in memory */ /* This buffer fits in memory */
bptr->rows_in_mem = bptr->rows_in_array; bptr->rows_in_mem = bptr->rows_in_array;
} else { } else {
/* It doesn't fit in memory, create backing store. */ /* It doesn't fit in memory, create backing store. */
bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess); bptr->rows_in_mem = (JDIMENSION)(max_minheights * bptr->maxaccess);
jpeg_open_backing_store(cinfo, & bptr->b_s_info, jpeg_open_backing_store(cinfo, &bptr->b_s_info,
(long) bptr->rows_in_array * (long)bptr->rows_in_array *
(long) bptr->blocksperrow * (long)bptr->blocksperrow *
(long) sizeof(JBLOCK)); (long)sizeof(JBLOCK));
bptr->b_s_open = TRUE; bptr->b_s_open = TRUE;
} }
bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE, bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
@ -752,32 +750,32 @@ realize_virt_arrays (j_common_ptr cinfo)
LOCAL(void) LOCAL(void)
do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing) do_sarray_io(j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
/* Do backing store read or write of a virtual sample array */ /* Do backing store read or write of a virtual sample array */
{ {
long bytesperrow, file_offset, byte_count, rows, thisrow, i; long bytesperrow, file_offset, byte_count, rows, thisrow, i;
bytesperrow = (long) ptr->samplesperrow * sizeof(JSAMPLE); bytesperrow = (long)ptr->samplesperrow * sizeof(JSAMPLE);
file_offset = ptr->cur_start_row * bytesperrow; file_offset = ptr->cur_start_row * bytesperrow;
/* Loop to read or write each allocation chunk in mem_buffer */ /* Loop to read or write each allocation chunk in mem_buffer */
for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) { for (i = 0; i < (long)ptr->rows_in_mem; i += ptr->rowsperchunk) {
/* One chunk, but check for short chunk at end of buffer */ /* One chunk, but check for short chunk at end of buffer */
rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i); rows = MIN((long)ptr->rowsperchunk, (long)ptr->rows_in_mem - i);
/* Transfer no more than is currently defined */ /* Transfer no more than is currently defined */
thisrow = (long) ptr->cur_start_row + i; thisrow = (long)ptr->cur_start_row + i;
rows = MIN(rows, (long) ptr->first_undef_row - thisrow); rows = MIN(rows, (long)ptr->first_undef_row - thisrow);
/* Transfer no more than fits in file */ /* Transfer no more than fits in file */
rows = MIN(rows, (long) ptr->rows_in_array - thisrow); rows = MIN(rows, (long)ptr->rows_in_array - thisrow);
if (rows <= 0) /* this chunk might be past end of file! */ if (rows <= 0) /* this chunk might be past end of file! */
break; break;
byte_count = rows * bytesperrow; byte_count = rows * bytesperrow;
if (writing) if (writing)
(*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info, (*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info,
(void *) ptr->mem_buffer[i], (void *)ptr->mem_buffer[i],
file_offset, byte_count); file_offset, byte_count);
else else
(*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info, (*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info,
(void *) ptr->mem_buffer[i], (void *)ptr->mem_buffer[i],
file_offset, byte_count); file_offset, byte_count);
file_offset += byte_count; file_offset += byte_count;
} }
@ -785,32 +783,32 @@ do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
LOCAL(void) LOCAL(void)
do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing) do_barray_io(j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
/* Do backing store read or write of a virtual coefficient-block array */ /* Do backing store read or write of a virtual coefficient-block array */
{ {
long bytesperrow, file_offset, byte_count, rows, thisrow, i; long bytesperrow, file_offset, byte_count, rows, thisrow, i;
bytesperrow = (long) ptr->blocksperrow * sizeof(JBLOCK); bytesperrow = (long)ptr->blocksperrow * sizeof(JBLOCK);
file_offset = ptr->cur_start_row * bytesperrow; file_offset = ptr->cur_start_row * bytesperrow;
/* Loop to read or write each allocation chunk in mem_buffer */ /* Loop to read or write each allocation chunk in mem_buffer */
for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) { for (i = 0; i < (long)ptr->rows_in_mem; i += ptr->rowsperchunk) {
/* One chunk, but check for short chunk at end of buffer */ /* One chunk, but check for short chunk at end of buffer */
rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i); rows = MIN((long)ptr->rowsperchunk, (long)ptr->rows_in_mem - i);
/* Transfer no more than is currently defined */ /* Transfer no more than is currently defined */
thisrow = (long) ptr->cur_start_row + i; thisrow = (long)ptr->cur_start_row + i;
rows = MIN(rows, (long) ptr->first_undef_row - thisrow); rows = MIN(rows, (long)ptr->first_undef_row - thisrow);
/* Transfer no more than fits in file */ /* Transfer no more than fits in file */
rows = MIN(rows, (long) ptr->rows_in_array - thisrow); rows = MIN(rows, (long)ptr->rows_in_array - thisrow);
if (rows <= 0) /* this chunk might be past end of file! */ if (rows <= 0) /* this chunk might be past end of file! */
break; break;
byte_count = rows * bytesperrow; byte_count = rows * bytesperrow;
if (writing) if (writing)
(*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info, (*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info,
(void *) ptr->mem_buffer[i], (void *)ptr->mem_buffer[i],
file_offset, byte_count); file_offset, byte_count);
else else
(*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info, (*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info,
(void *) ptr->mem_buffer[i], (void *)ptr->mem_buffer[i],
file_offset, byte_count); file_offset, byte_count);
file_offset += byte_count; file_offset += byte_count;
} }
@ -818,9 +816,8 @@ do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
METHODDEF(JSAMPARRAY) METHODDEF(JSAMPARRAY)
access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr, access_virt_sarray(j_common_ptr cinfo, jvirt_sarray_ptr ptr,
JDIMENSION start_row, JDIMENSION num_rows, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)
boolean writable)
/* Access the part of a virtual sample array starting at start_row */ /* Access the part of a virtual sample array starting at start_row */
/* and extending for num_rows rows. writable is true if */ /* and extending for num_rows rows. writable is true if */
/* caller intends to modify the accessed area. */ /* caller intends to modify the accessed area. */
@ -835,8 +832,8 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
/* Make the desired part of the virtual array accessible */ /* Make the desired part of the virtual array accessible */
if (start_row < ptr->cur_start_row || if (start_row < ptr->cur_start_row ||
end_row > ptr->cur_start_row+ptr->rows_in_mem) { end_row > ptr->cur_start_row + ptr->rows_in_mem) {
if (! ptr->b_s_open) if (!ptr->b_s_open)
ERREXIT(cinfo, JERR_VIRTUAL_BUG); ERREXIT(cinfo, JERR_VIRTUAL_BUG);
/* Flush old buffer contents if necessary */ /* Flush old buffer contents if necessary */
if (ptr->dirty) { if (ptr->dirty) {
@ -856,10 +853,10 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
/* use long arithmetic here to avoid overflow & unsigned problems */ /* use long arithmetic here to avoid overflow & unsigned problems */
long ltemp; long ltemp;
ltemp = (long) end_row - (long) ptr->rows_in_mem; ltemp = (long)end_row - (long)ptr->rows_in_mem;
if (ltemp < 0) if (ltemp < 0)
ltemp = 0; /* don't fall off front end of file */ ltemp = 0; /* don't fall off front end of file */
ptr->cur_start_row = (JDIMENSION) ltemp; ptr->cur_start_row = (JDIMENSION)ltemp;
} }
/* Read in the selected part of the array. /* Read in the selected part of the array.
* During the initial write pass, we will do no actual read * During the initial write pass, we will do no actual read
@ -882,15 +879,15 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
if (writable) if (writable)
ptr->first_undef_row = end_row; ptr->first_undef_row = end_row;
if (ptr->pre_zero) { if (ptr->pre_zero) {
size_t bytesperrow = (size_t) ptr->samplesperrow * sizeof(JSAMPLE); size_t bytesperrow = (size_t)ptr->samplesperrow * sizeof(JSAMPLE);
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */ undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
end_row -= ptr->cur_start_row; end_row -= ptr->cur_start_row;
while (undef_row < end_row) { while (undef_row < end_row) {
jzero_far((void *) ptr->mem_buffer[undef_row], bytesperrow); jzero_far((void *)ptr->mem_buffer[undef_row], bytesperrow);
undef_row++; undef_row++;
} }
} else { } else {
if (! writable) /* reader looking at undefined data */ if (!writable) /* reader looking at undefined data */
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
} }
} }
@ -903,9 +900,8 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
METHODDEF(JBLOCKARRAY) METHODDEF(JBLOCKARRAY)
access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr, access_virt_barray(j_common_ptr cinfo, jvirt_barray_ptr ptr,
JDIMENSION start_row, JDIMENSION num_rows, JDIMENSION start_row, JDIMENSION num_rows, boolean writable)
boolean writable)
/* Access the part of a virtual block array starting at start_row */ /* Access the part of a virtual block array starting at start_row */
/* and extending for num_rows rows. writable is true if */ /* and extending for num_rows rows. writable is true if */
/* caller intends to modify the accessed area. */ /* caller intends to modify the accessed area. */
@ -920,8 +916,8 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
/* Make the desired part of the virtual array accessible */ /* Make the desired part of the virtual array accessible */
if (start_row < ptr->cur_start_row || if (start_row < ptr->cur_start_row ||
end_row > ptr->cur_start_row+ptr->rows_in_mem) { end_row > ptr->cur_start_row + ptr->rows_in_mem) {
if (! ptr->b_s_open) if (!ptr->b_s_open)
ERREXIT(cinfo, JERR_VIRTUAL_BUG); ERREXIT(cinfo, JERR_VIRTUAL_BUG);
/* Flush old buffer contents if necessary */ /* Flush old buffer contents if necessary */
if (ptr->dirty) { if (ptr->dirty) {
@ -941,10 +937,10 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
/* use long arithmetic here to avoid overflow & unsigned problems */ /* use long arithmetic here to avoid overflow & unsigned problems */
long ltemp; long ltemp;
ltemp = (long) end_row - (long) ptr->rows_in_mem; ltemp = (long)end_row - (long)ptr->rows_in_mem;
if (ltemp < 0) if (ltemp < 0)
ltemp = 0; /* don't fall off front end of file */ ltemp = 0; /* don't fall off front end of file */
ptr->cur_start_row = (JDIMENSION) ltemp; ptr->cur_start_row = (JDIMENSION)ltemp;
} }
/* Read in the selected part of the array. /* Read in the selected part of the array.
* During the initial write pass, we will do no actual read * During the initial write pass, we will do no actual read
@ -967,15 +963,15 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
if (writable) if (writable)
ptr->first_undef_row = end_row; ptr->first_undef_row = end_row;
if (ptr->pre_zero) { if (ptr->pre_zero) {
size_t bytesperrow = (size_t) ptr->blocksperrow * sizeof(JBLOCK); size_t bytesperrow = (size_t)ptr->blocksperrow * sizeof(JBLOCK);
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */ undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
end_row -= ptr->cur_start_row; end_row -= ptr->cur_start_row;
while (undef_row < end_row) { while (undef_row < end_row) {
jzero_far((void *) ptr->mem_buffer[undef_row], bytesperrow); jzero_far((void *)ptr->mem_buffer[undef_row], bytesperrow);
undef_row++; undef_row++;
} }
} else { } else {
if (! writable) /* reader looking at undefined data */ if (!writable) /* reader looking at undefined data */
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
} }
} }
@ -992,9 +988,9 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
*/ */
METHODDEF(void) METHODDEF(void)
free_pool (j_common_ptr cinfo, int pool_id) free_pool(j_common_ptr cinfo, int pool_id)
{ {
my_mem_ptr mem = (my_mem_ptr) cinfo->mem; my_mem_ptr mem = (my_mem_ptr)cinfo->mem;
small_pool_ptr shdr_ptr; small_pool_ptr shdr_ptr;
large_pool_ptr lhdr_ptr; large_pool_ptr lhdr_ptr;
size_t space_freed; size_t space_freed;
@ -1015,14 +1011,14 @@ free_pool (j_common_ptr cinfo, int pool_id)
for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) { for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
if (sptr->b_s_open) { /* there may be no backing store */ if (sptr->b_s_open) { /* there may be no backing store */
sptr->b_s_open = FALSE; /* prevent recursive close if error */ sptr->b_s_open = FALSE; /* prevent recursive close if error */
(*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info); (*sptr->b_s_info.close_backing_store) (cinfo, &sptr->b_s_info);
} }
} }
mem->virt_sarray_list = NULL; mem->virt_sarray_list = NULL;
for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) { for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
if (bptr->b_s_open) { /* there may be no backing store */ if (bptr->b_s_open) { /* there may be no backing store */
bptr->b_s_open = FALSE; /* prevent recursive close if error */ bptr->b_s_open = FALSE; /* prevent recursive close if error */
(*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info); (*bptr->b_s_info.close_backing_store) (cinfo, &bptr->b_s_info);
} }
} }
mem->virt_barray_list = NULL; mem->virt_barray_list = NULL;
@ -1037,7 +1033,7 @@ free_pool (j_common_ptr cinfo, int pool_id)
space_freed = lhdr_ptr->bytes_used + space_freed = lhdr_ptr->bytes_used +
lhdr_ptr->bytes_left + lhdr_ptr->bytes_left +
sizeof(large_pool_hdr); sizeof(large_pool_hdr);
jpeg_free_large(cinfo, (void *) lhdr_ptr, space_freed); jpeg_free_large(cinfo, (void *)lhdr_ptr, space_freed);
mem->total_space_allocated -= space_freed; mem->total_space_allocated -= space_freed;
lhdr_ptr = next_lhdr_ptr; lhdr_ptr = next_lhdr_ptr;
} }
@ -1048,10 +1044,9 @@ free_pool (j_common_ptr cinfo, int pool_id)
while (shdr_ptr != NULL) { while (shdr_ptr != NULL) {
small_pool_ptr next_shdr_ptr = shdr_ptr->next; small_pool_ptr next_shdr_ptr = shdr_ptr->next;
space_freed = shdr_ptr->bytes_used + space_freed = shdr_ptr->bytes_used + shdr_ptr->bytes_left +
shdr_ptr->bytes_left +
sizeof(small_pool_hdr); sizeof(small_pool_hdr);
jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed); jpeg_free_small(cinfo, (void *)shdr_ptr, space_freed);
mem->total_space_allocated -= space_freed; mem->total_space_allocated -= space_freed;
shdr_ptr = next_shdr_ptr; shdr_ptr = next_shdr_ptr;
} }
@ -1064,7 +1059,7 @@ free_pool (j_common_ptr cinfo, int pool_id)
*/ */
METHODDEF(void) METHODDEF(void)
self_destruct (j_common_ptr cinfo) self_destruct(j_common_ptr cinfo)
{ {
int pool; int pool;
@ -1072,12 +1067,12 @@ self_destruct (j_common_ptr cinfo)
* Releasing pools in reverse order might help avoid fragmentation * Releasing pools in reverse order might help avoid fragmentation
* with some (brain-damaged) malloc libraries. * with some (brain-damaged) malloc libraries.
*/ */
for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) { for (pool = JPOOL_NUMPOOLS - 1; pool >= JPOOL_PERMANENT; pool--) {
free_pool(cinfo, pool); free_pool(cinfo, pool);
} }
/* Release the memory manager control block too. */ /* Release the memory manager control block too. */
jpeg_free_small(cinfo, (void *) cinfo->mem, sizeof(my_memory_mgr)); jpeg_free_small(cinfo, (void *)cinfo->mem, sizeof(my_memory_mgr));
cinfo->mem = NULL; /* ensures I will be called only once */ cinfo->mem = NULL; /* ensures I will be called only once */
jpeg_mem_term(cinfo); /* system-dependent cleanup */ jpeg_mem_term(cinfo); /* system-dependent cleanup */
@ -1090,7 +1085,7 @@ self_destruct (j_common_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_memory_mgr (j_common_ptr cinfo) jinit_memory_mgr(j_common_ptr cinfo)
{ {
my_mem_ptr mem; my_mem_ptr mem;
long max_to_use; long max_to_use;
@ -1106,22 +1101,22 @@ jinit_memory_mgr (j_common_ptr cinfo)
* in common if and only if X is a power of 2, ie has only one one-bit. * in common if and only if X is a power of 2, ie has only one one-bit.
* Some compilers may give an "unreachable code" warning here; ignore it. * Some compilers may give an "unreachable code" warning here; ignore it.
*/ */
if ((ALIGN_SIZE & (ALIGN_SIZE-1)) != 0) if ((ALIGN_SIZE & (ALIGN_SIZE - 1)) != 0)
ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE); ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
/* MAX_ALLOC_CHUNK must be representable as type size_t, and must be /* MAX_ALLOC_CHUNK must be representable as type size_t, and must be
* a multiple of ALIGN_SIZE. * a multiple of ALIGN_SIZE.
* Again, an "unreachable code" warning may be ignored here. * Again, an "unreachable code" warning may be ignored here.
* But a "constant too large" warning means you need to fix MAX_ALLOC_CHUNK. * But a "constant too large" warning means you need to fix MAX_ALLOC_CHUNK.
*/ */
test_mac = (size_t) MAX_ALLOC_CHUNK; test_mac = (size_t)MAX_ALLOC_CHUNK;
if ((long) test_mac != MAX_ALLOC_CHUNK || if ((long)test_mac != MAX_ALLOC_CHUNK ||
(MAX_ALLOC_CHUNK % ALIGN_SIZE) != 0) (MAX_ALLOC_CHUNK % ALIGN_SIZE) != 0)
ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK); ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */ max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
/* Attempt to allocate memory manager's control block */ /* Attempt to allocate memory manager's control block */
mem = (my_mem_ptr) jpeg_get_small(cinfo, sizeof(my_memory_mgr)); mem = (my_mem_ptr)jpeg_get_small(cinfo, sizeof(my_memory_mgr));
if (mem == NULL) { if (mem == NULL) {
jpeg_mem_term(cinfo); /* system-dependent cleanup */ jpeg_mem_term(cinfo); /* system-dependent cleanup */
@ -1147,7 +1142,7 @@ jinit_memory_mgr (j_common_ptr cinfo)
/* Initialize working state */ /* Initialize working state */
mem->pub.max_memory_to_use = max_to_use; mem->pub.max_memory_to_use = max_to_use;
for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) { for (pool = JPOOL_NUMPOOLS - 1; pool >= JPOOL_PERMANENT; pool--) {
mem->small_list[pool] = NULL; mem->small_list[pool] = NULL;
mem->large_list[pool] = NULL; mem->large_list[pool] = NULL;
} }
@ -1157,7 +1152,7 @@ jinit_memory_mgr (j_common_ptr cinfo)
mem->total_space_allocated = sizeof(my_memory_mgr); mem->total_space_allocated = sizeof(my_memory_mgr);
/* Declare ourselves open for business */ /* Declare ourselves open for business */
cinfo->mem = & mem->pub; cinfo->mem = &mem->pub;
/* Check for an environment variable JPEGMEM; if found, override the /* Check for an environment variable JPEGMEM; if found, override the
* default max_memory setting from jpeg_mem_init. Note that the * default max_memory setting from jpeg_mem_init. Note that the
@ -1166,7 +1161,8 @@ jinit_memory_mgr (j_common_ptr cinfo)
* this feature. * this feature.
*/ */
#ifndef NO_GETENV #ifndef NO_GETENV
{ char *memenv; {
char *memenv;
if ((memenv = getenv("JPEGMEM")) != NULL) { if ((memenv = getenv("JPEGMEM")) != NULL) {
char ch = 'x'; char ch = 'x';

View File

@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1992-1996, Thomas G. Lane. * Copyright (C) 1992-1996, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2017, D. R. Commander. * Copyright (C) 2017-2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@ -23,8 +23,8 @@
#include "jmemsys.h" /* import the system-dependent declarations */ #include "jmemsys.h" /* import the system-dependent declarations */
#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */ #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
extern void *malloc (size_t size); extern void *malloc(size_t size);
extern void free (void *ptr); extern void free(void *ptr);
#endif #endif
@ -34,13 +34,13 @@ extern void free (void *ptr);
*/ */
GLOBAL(void *) GLOBAL(void *)
jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) jpeg_get_small(j_common_ptr cinfo, size_t sizeofobject)
{ {
return (void *) malloc(sizeofobject); return (void *)malloc(sizeofobject);
} }
GLOBAL(void) GLOBAL(void)
jpeg_free_small (j_common_ptr cinfo, void *object, size_t sizeofobject) jpeg_free_small(j_common_ptr cinfo, void *object, size_t sizeofobject)
{ {
free(object); free(object);
} }
@ -51,13 +51,13 @@ jpeg_free_small (j_common_ptr cinfo, void *object, size_t sizeofobject)
*/ */
GLOBAL(void *) GLOBAL(void *)
jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) jpeg_get_large(j_common_ptr cinfo, size_t sizeofobject)
{ {
return (void *) malloc(sizeofobject); return (void *)malloc(sizeofobject);
} }
GLOBAL(void) GLOBAL(void)
jpeg_free_large (j_common_ptr cinfo, void *object, size_t sizeofobject) jpeg_free_large(j_common_ptr cinfo, void *object, size_t sizeofobject)
{ {
free(object); free(object);
} }
@ -68,11 +68,11 @@ jpeg_free_large (j_common_ptr cinfo, void *object, size_t sizeofobject)
*/ */
GLOBAL(size_t) GLOBAL(size_t)
jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed, jpeg_mem_available(j_common_ptr cinfo, size_t min_bytes_needed,
size_t max_bytes_needed, size_t already_allocated) size_t max_bytes_needed, size_t already_allocated)
{ {
if (cinfo->mem->max_memory_to_use) { if (cinfo->mem->max_memory_to_use) {
if (cinfo->mem->max_memory_to_use > already_allocated) if ((size_t)cinfo->mem->max_memory_to_use > already_allocated)
return cinfo->mem->max_memory_to_use - already_allocated; return cinfo->mem->max_memory_to_use - already_allocated;
else else
return 0; return 0;
@ -90,7 +90,7 @@ jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed,
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, jpeg_open_backing_store(j_common_ptr cinfo, backing_store_ptr info,
long total_bytes_needed) long total_bytes_needed)
{ {
ERREXIT(cinfo, JERR_NO_BACKING_STORE); ERREXIT(cinfo, JERR_NO_BACKING_STORE);
@ -103,13 +103,13 @@ jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
*/ */
GLOBAL(long) GLOBAL(long)
jpeg_mem_init (j_common_ptr cinfo) jpeg_mem_init(j_common_ptr cinfo)
{ {
return 0; /* just set max_memory_to_use to 0 */ return 0; /* just set max_memory_to_use to 0 */
} }
GLOBAL(void) GLOBAL(void)
jpeg_mem_term (j_common_ptr cinfo) jpeg_mem_term(j_common_ptr cinfo)
{ {
/* no work */ /* no work */
} }

View File

@ -31,8 +31,8 @@
* size of the object being freed, just in case it's needed. * size of the object being freed, just in case it's needed.
*/ */
EXTERN(void *) jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject); EXTERN(void *) jpeg_get_small(j_common_ptr cinfo, size_t sizeofobject);
EXTERN(void) jpeg_free_small (j_common_ptr cinfo, void *object, EXTERN(void) jpeg_free_small(j_common_ptr cinfo, void *object,
size_t sizeofobject); size_t sizeofobject);
/* /*
@ -43,8 +43,8 @@ EXTERN(void) jpeg_free_small (j_common_ptr cinfo, void *object,
* large chunks. * large chunks.
*/ */
EXTERN(void *) jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject); EXTERN(void *) jpeg_get_large(j_common_ptr cinfo, size_t sizeofobject);
EXTERN(void) jpeg_free_large (j_common_ptr cinfo, void *object, EXTERN(void) jpeg_free_large(j_common_ptr cinfo, void *object,
size_t sizeofobject); size_t sizeofobject);
/* /*
@ -84,7 +84,7 @@ EXTERN(void) jpeg_free_large (j_common_ptr cinfo, void *object,
* Conversely, zero may be returned to always use the minimum amount of memory. * Conversely, zero may be returned to always use the minimum amount of memory.
*/ */
EXTERN(size_t) jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed, EXTERN(size_t) jpeg_mem_available(j_common_ptr cinfo, size_t min_bytes_needed,
size_t max_bytes_needed, size_t max_bytes_needed,
size_t already_allocated); size_t already_allocated);
@ -157,7 +157,7 @@ typedef struct backing_store_struct {
* just take an error exit.) * just take an error exit.)
*/ */
EXTERN(void) jpeg_open_backing_store (j_common_ptr cinfo, EXTERN(void) jpeg_open_backing_store(j_common_ptr cinfo,
backing_store_ptr info, backing_store_ptr info,
long total_bytes_needed); long total_bytes_needed);
@ -174,5 +174,5 @@ EXTERN(void) jpeg_open_backing_store (j_common_ptr cinfo,
* all opened backing-store objects have been closed. * all opened backing-store objects have been closed.
*/ */
EXTERN(long) jpeg_mem_init (j_common_ptr cinfo); EXTERN(long) jpeg_mem_init(j_common_ptr cinfo);
EXTERN(void) jpeg_mem_term (j_common_ptr cinfo); EXTERN(void) jpeg_mem_term(j_common_ptr cinfo);

View File

@ -5,7 +5,7 @@
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 1997-2009 by Guido Vollbeding. * Modified 1997-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009, 2011, 2014-2015, D. R. Commander. * Copyright (C) 2009, 2011, 2014-2015, 2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@ -17,9 +17,9 @@
/* /*
* Maximum number of components (color channels) allowed in JPEG image. * Maximum number of components (color channels) allowed in JPEG image.
* To meet the letter of the JPEG spec, set this to 255. However, darn * To meet the letter of Rec. ITU-T T.81 | ISO/IEC 10918-1, set this to 255.
* few applications need more than 4 channels (maybe 5 for CMYK + alpha * However, darn few applications need more than 4 channels (maybe 5 for CMYK +
* mask). We recommend 10 as a reasonable compromise; use 4 if you are * alpha mask). We recommend 10 as a reasonable compromise; use 4 if you are
* really short on memory. (Each allowed component costs a hundred or so * really short on memory. (Each allowed component costs a hundred or so
* bytes of storage, whether actually used in an image or not.) * bytes of storage, whether actually used in an image or not.)
*/ */
@ -49,15 +49,15 @@
#ifdef HAVE_UNSIGNED_CHAR #ifdef HAVE_UNSIGNED_CHAR
typedef unsigned char JSAMPLE; typedef unsigned char JSAMPLE;
#define GETJSAMPLE(value) ((int) (value)) #define GETJSAMPLE(value) ((int)(value))
#else /* not HAVE_UNSIGNED_CHAR */ #else /* not HAVE_UNSIGNED_CHAR */
typedef char JSAMPLE; typedef char JSAMPLE;
#ifdef __CHAR_UNSIGNED__ #ifdef __CHAR_UNSIGNED__
#define GETJSAMPLE(value) ((int) (value)) #define GETJSAMPLE(value) ((int)(value))
#else #else
#define GETJSAMPLE(value) ((int) (value) & 0xFF) #define GETJSAMPLE(value) ((int)(value) & 0xFF)
#endif /* __CHAR_UNSIGNED__ */ #endif /* __CHAR_UNSIGNED__ */
#endif /* HAVE_UNSIGNED_CHAR */ #endif /* HAVE_UNSIGNED_CHAR */
@ -74,7 +74,7 @@ typedef char JSAMPLE;
*/ */
typedef short JSAMPLE; typedef short JSAMPLE;
#define GETJSAMPLE(value) ((int) (value)) #define GETJSAMPLE(value) ((int)(value))
#define MAXJSAMPLE 4095 #define MAXJSAMPLE 4095
#define CENTERJSAMPLE 2048 #define CENTERJSAMPLE 2048
@ -220,7 +220,7 @@ typedef unsigned int JDIMENSION;
* software out there that uses it. * software out there that uses it.
*/ */
#define JMETHOD(type,methodname,arglist) type (*methodname) arglist #define JMETHOD(type, methodname, arglist) type (*methodname) arglist
/* libjpeg-turbo no longer supports platforms that have far symbols (MS-DOS), /* libjpeg-turbo no longer supports platforms that have far symbols (MS-DOS),
@ -315,10 +315,10 @@ typedef int boolean;
* with it. In reality, few people ever did this, because there were some * with it. In reality, few people ever did this, because there were some
* severe restrictions involved (cjpeg and djpeg no longer worked properly, * severe restrictions involved (cjpeg and djpeg no longer worked properly,
* compressing/decompressing RGB JPEGs no longer worked properly, and the color * compressing/decompressing RGB JPEGs no longer worked properly, and the color
* quantizer wouldn't work with pixel sizes other than 3.) Further, since all * quantizer wouldn't work with pixel sizes other than 3.) Furthermore, since
* of the O/S-supplied versions of libjpeg were built with the default values * all of the O/S-supplied versions of libjpeg were built with the default
* of RGB_RED, RGB_GREEN, RGB_BLUE, and RGB_PIXELSIZE, many applications have * values of RGB_RED, RGB_GREEN, RGB_BLUE, and RGB_PIXELSIZE, many applications
* come to regard these values as immutable. * have come to regard these values as immutable.
* *
* The libjpeg-turbo colorspace extensions provide a much cleaner way of * The libjpeg-turbo colorspace extensions provide a much cleaner way of
* compressing from/decompressing to buffers with arbitrary component orders * compressing from/decompressing to buffers with arbitrary component orders

View File

@ -274,9 +274,9 @@ struct jpeg_color_quantizer {
/* Miscellaneous useful macros */ /* Miscellaneous useful macros */
#undef MAX #undef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b))
#undef MIN #undef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b))
/* We assume that right shift corresponds to signed division by 2 with /* We assume that right shift corresponds to signed division by 2 with
@ -291,64 +291,64 @@ struct jpeg_color_quantizer {
#ifdef RIGHT_SHIFT_IS_UNSIGNED #ifdef RIGHT_SHIFT_IS_UNSIGNED
#define SHIFT_TEMPS JLONG shift_temp; #define SHIFT_TEMPS JLONG shift_temp;
#define RIGHT_SHIFT(x,shft) \ #define RIGHT_SHIFT(x, shft) \
((shift_temp = (x)) < 0 ? \ ((shift_temp = (x)) < 0 ? \
(shift_temp >> (shft)) | ((~((JLONG) 0)) << (32-(shft))) : \ (shift_temp >> (shft)) | ((~((JLONG)0)) << (32 - (shft))) : \
(shift_temp >> (shft))) (shift_temp >> (shft)))
#else #else
#define SHIFT_TEMPS #define SHIFT_TEMPS
#define RIGHT_SHIFT(x,shft) ((x) >> (shft)) #define RIGHT_SHIFT(x, shft) ((x) >> (shft))
#endif #endif
/* Compression module initialization routines */ /* Compression module initialization routines */
EXTERN(void) jinit_compress_master (j_compress_ptr cinfo); EXTERN(void) jinit_compress_master(j_compress_ptr cinfo);
EXTERN(void) jinit_c_master_control (j_compress_ptr cinfo, EXTERN(void) jinit_c_master_control(j_compress_ptr cinfo,
boolean transcode_only); boolean transcode_only);
EXTERN(void) jinit_c_main_controller (j_compress_ptr cinfo, EXTERN(void) jinit_c_main_controller(j_compress_ptr cinfo,
boolean need_full_buffer); boolean need_full_buffer);
EXTERN(void) jinit_c_prep_controller (j_compress_ptr cinfo, EXTERN(void) jinit_c_prep_controller(j_compress_ptr cinfo,
boolean need_full_buffer); boolean need_full_buffer);
EXTERN(void) jinit_c_coef_controller (j_compress_ptr cinfo, EXTERN(void) jinit_c_coef_controller(j_compress_ptr cinfo,
boolean need_full_buffer); boolean need_full_buffer);
EXTERN(void) jinit_color_converter (j_compress_ptr cinfo); EXTERN(void) jinit_color_converter(j_compress_ptr cinfo);
EXTERN(void) jinit_downsampler (j_compress_ptr cinfo); EXTERN(void) jinit_downsampler(j_compress_ptr cinfo);
EXTERN(void) jinit_forward_dct (j_compress_ptr cinfo); EXTERN(void) jinit_forward_dct(j_compress_ptr cinfo);
EXTERN(void) jinit_huff_encoder (j_compress_ptr cinfo); EXTERN(void) jinit_huff_encoder(j_compress_ptr cinfo);
EXTERN(void) jinit_phuff_encoder (j_compress_ptr cinfo); EXTERN(void) jinit_phuff_encoder(j_compress_ptr cinfo);
EXTERN(void) jinit_arith_encoder (j_compress_ptr cinfo); EXTERN(void) jinit_arith_encoder(j_compress_ptr cinfo);
EXTERN(void) jinit_marker_writer (j_compress_ptr cinfo); EXTERN(void) jinit_marker_writer(j_compress_ptr cinfo);
/* Decompression module initialization routines */ /* Decompression module initialization routines */
EXTERN(void) jinit_master_decompress (j_decompress_ptr cinfo); EXTERN(void) jinit_master_decompress(j_decompress_ptr cinfo);
EXTERN(void) jinit_d_main_controller (j_decompress_ptr cinfo, EXTERN(void) jinit_d_main_controller(j_decompress_ptr cinfo,
boolean need_full_buffer); boolean need_full_buffer);
EXTERN(void) jinit_d_coef_controller (j_decompress_ptr cinfo, EXTERN(void) jinit_d_coef_controller(j_decompress_ptr cinfo,
boolean need_full_buffer); boolean need_full_buffer);
EXTERN(void) jinit_d_post_controller (j_decompress_ptr cinfo, EXTERN(void) jinit_d_post_controller(j_decompress_ptr cinfo,
boolean need_full_buffer); boolean need_full_buffer);
EXTERN(void) jinit_input_controller (j_decompress_ptr cinfo); EXTERN(void) jinit_input_controller(j_decompress_ptr cinfo);
EXTERN(void) jinit_marker_reader (j_decompress_ptr cinfo); EXTERN(void) jinit_marker_reader(j_decompress_ptr cinfo);
EXTERN(void) jinit_huff_decoder (j_decompress_ptr cinfo); EXTERN(void) jinit_huff_decoder(j_decompress_ptr cinfo);
EXTERN(void) jinit_phuff_decoder (j_decompress_ptr cinfo); EXTERN(void) jinit_phuff_decoder(j_decompress_ptr cinfo);
EXTERN(void) jinit_arith_decoder (j_decompress_ptr cinfo); EXTERN(void) jinit_arith_decoder(j_decompress_ptr cinfo);
EXTERN(void) jinit_inverse_dct (j_decompress_ptr cinfo); EXTERN(void) jinit_inverse_dct(j_decompress_ptr cinfo);
EXTERN(void) jinit_upsampler (j_decompress_ptr cinfo); EXTERN(void) jinit_upsampler(j_decompress_ptr cinfo);
EXTERN(void) jinit_color_deconverter (j_decompress_ptr cinfo); EXTERN(void) jinit_color_deconverter(j_decompress_ptr cinfo);
EXTERN(void) jinit_1pass_quantizer (j_decompress_ptr cinfo); EXTERN(void) jinit_1pass_quantizer(j_decompress_ptr cinfo);
EXTERN(void) jinit_2pass_quantizer (j_decompress_ptr cinfo); EXTERN(void) jinit_2pass_quantizer(j_decompress_ptr cinfo);
EXTERN(void) jinit_merged_upsampler (j_decompress_ptr cinfo); EXTERN(void) jinit_merged_upsampler(j_decompress_ptr cinfo);
/* Memory manager initialization */ /* Memory manager initialization */
EXTERN(void) jinit_memory_mgr (j_common_ptr cinfo); EXTERN(void) jinit_memory_mgr(j_common_ptr cinfo);
/* Utility routines in jutils.c */ /* Utility routines in jutils.c */
EXTERN(long) jdiv_round_up (long a, long b); EXTERN(long) jdiv_round_up(long a, long b);
EXTERN(long) jround_up (long a, long b); EXTERN(long) jround_up(long a, long b);
EXTERN(void) jcopy_sample_rows (JSAMPARRAY input_array, int source_row, EXTERN(void) jcopy_sample_rows(JSAMPARRAY input_array, int source_row,
JSAMPARRAY output_array, int dest_row, JSAMPARRAY output_array, int dest_row,
int num_rows, JDIMENSION num_cols); int num_rows, JDIMENSION num_cols);
EXTERN(void) jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, EXTERN(void) jcopy_block_row(JBLOCKROW input_row, JBLOCKROW output_row,
JDIMENSION num_blocks); JDIMENSION num_blocks);
EXTERN(void) jzero_far (void *target, size_t bytestozero); EXTERN(void) jzero_far(void *target, size_t bytestozero);
/* Constant tables in jutils.c */ /* Constant tables in jutils.c */
#if 0 /* This table is not actually needed in v6a */ #if 0 /* This table is not actually needed in v6a */
extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */ extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */

View File

@ -5,7 +5,7 @@
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2002-2009 by Guido Vollbeding. * Modified 2002-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009-2011, 2013-2014, 2016, D. R. Commander. * Copyright (C) 2009-2011, 2013-2014, 2016-2017, D. R. Commander.
* Copyright (C) 2015, Google, Inc. * Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
@ -268,11 +268,11 @@ typedef enum {
/* Common fields between JPEG compression and decompression master structs. */ /* Common fields between JPEG compression and decompression master structs. */
#define jpeg_common_fields \ #define jpeg_common_fields \
struct jpeg_error_mgr *err; /* Error handler module */\ struct jpeg_error_mgr *err; /* Error handler module */ \
struct jpeg_memory_mgr *mem; /* Memory manager module */\ struct jpeg_memory_mgr *mem; /* Memory manager module */ \
struct jpeg_progress_mgr *progress; /* Progress monitor, or NULL if none */\ struct jpeg_progress_mgr *progress; /* Progress monitor, or NULL if none */ \
void *client_data; /* Available for use by application */\ void *client_data; /* Available for use by application */ \
boolean is_decompressor; /* So common code can tell which is which */\ boolean is_decompressor; /* So common code can tell which is which */ \
int global_state /* For checking call sequence validity */ int global_state /* For checking call sequence validity */
/* Routines that are to be used by both halves of the library are declared /* Routines that are to be used by both halves of the library are declared
@ -888,7 +888,7 @@ typedef boolean (*jpeg_marker_parser_method) (j_decompress_ptr cinfo);
/* Default error-management setup */ /* Default error-management setup */
EXTERN(struct jpeg_error_mgr *) jpeg_std_error (struct jpeg_error_mgr *err); EXTERN(struct jpeg_error_mgr *) jpeg_std_error(struct jpeg_error_mgr *err);
/* Initialization of JPEG compression objects. /* Initialization of JPEG compression objects.
* jpeg_create_compress() and jpeg_create_decompress() are the exported * jpeg_create_compress() and jpeg_create_decompress() are the exported
@ -899,85 +899,90 @@ EXTERN(struct jpeg_error_mgr *) jpeg_std_error (struct jpeg_error_mgr *err);
*/ */
#define jpeg_create_compress(cinfo) \ #define jpeg_create_compress(cinfo) \
jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \ jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
(size_t) sizeof(struct jpeg_compress_struct)) (size_t)sizeof(struct jpeg_compress_struct))
#define jpeg_create_decompress(cinfo) \ #define jpeg_create_decompress(cinfo) \
jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \ jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
(size_t) sizeof(struct jpeg_decompress_struct)) (size_t)sizeof(struct jpeg_decompress_struct))
EXTERN(void) jpeg_CreateCompress (j_compress_ptr cinfo, int version, EXTERN(void) jpeg_CreateCompress(j_compress_ptr cinfo, int version,
size_t structsize); size_t structsize);
EXTERN(void) jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, EXTERN(void) jpeg_CreateDecompress(j_decompress_ptr cinfo, int version,
size_t structsize); size_t structsize);
/* Destruction of JPEG compression objects */ /* Destruction of JPEG compression objects */
EXTERN(void) jpeg_destroy_compress (j_compress_ptr cinfo); EXTERN(void) jpeg_destroy_compress(j_compress_ptr cinfo);
EXTERN(void) jpeg_destroy_decompress (j_decompress_ptr cinfo); EXTERN(void) jpeg_destroy_decompress(j_decompress_ptr cinfo);
/* Standard data source and destination managers: stdio streams. */ /* Standard data source and destination managers: stdio streams. */
/* Caller is responsible for opening the file before and closing after. */ /* Caller is responsible for opening the file before and closing after. */
EXTERN(void) jpeg_stdio_dest (j_compress_ptr cinfo, FILE *outfile); EXTERN(void) jpeg_stdio_dest(j_compress_ptr cinfo, FILE *outfile);
EXTERN(void) jpeg_stdio_src (j_decompress_ptr cinfo, FILE *infile); EXTERN(void) jpeg_stdio_src(j_decompress_ptr cinfo, FILE *infile);
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED) #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
/* Data source and destination managers: memory buffers. */ /* Data source and destination managers: memory buffers. */
EXTERN(void) jpeg_mem_dest (j_compress_ptr cinfo, unsigned char **outbuffer, EXTERN(void) jpeg_mem_dest(j_compress_ptr cinfo, unsigned char **outbuffer,
unsigned long *outsize); unsigned long *outsize);
EXTERN(void) jpeg_mem_src (j_decompress_ptr cinfo, EXTERN(void) jpeg_mem_src(j_decompress_ptr cinfo,
const unsigned char *inbuffer, const unsigned char *inbuffer, unsigned long insize);
unsigned long insize);
#endif #endif
/* Default parameter setup for compression */ /* Default parameter setup for compression */
EXTERN(void) jpeg_set_defaults (j_compress_ptr cinfo); EXTERN(void) jpeg_set_defaults(j_compress_ptr cinfo);
/* Compression parameter setup aids */ /* Compression parameter setup aids */
EXTERN(void) jpeg_set_colorspace (j_compress_ptr cinfo, EXTERN(void) jpeg_set_colorspace(j_compress_ptr cinfo,
J_COLOR_SPACE colorspace); J_COLOR_SPACE colorspace);
EXTERN(void) jpeg_default_colorspace (j_compress_ptr cinfo); EXTERN(void) jpeg_default_colorspace(j_compress_ptr cinfo);
EXTERN(void) jpeg_set_quality (j_compress_ptr cinfo, int quality, EXTERN(void) jpeg_set_quality(j_compress_ptr cinfo, int quality,
boolean force_baseline); boolean force_baseline);
EXTERN(void) jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, EXTERN(void) jpeg_set_linear_quality(j_compress_ptr cinfo, int scale_factor,
boolean force_baseline); boolean force_baseline);
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
EXTERN(void) jpeg_default_qtables (j_compress_ptr cinfo, EXTERN(void) jpeg_default_qtables(j_compress_ptr cinfo,
boolean force_baseline); boolean force_baseline);
#endif #endif
EXTERN(void) jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl, EXTERN(void) jpeg_add_quant_table(j_compress_ptr cinfo, int which_tbl,
const unsigned int *basic_table, const unsigned int *basic_table,
int scale_factor, boolean force_baseline); int scale_factor, boolean force_baseline);
EXTERN(int) jpeg_quality_scaling (int quality); EXTERN(int) jpeg_quality_scaling(int quality);
EXTERN(void) jpeg_simple_progression (j_compress_ptr cinfo); EXTERN(void) jpeg_simple_progression(j_compress_ptr cinfo);
EXTERN(void) jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress); EXTERN(void) jpeg_suppress_tables(j_compress_ptr cinfo, boolean suppress);
EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table (j_common_ptr cinfo); EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table(j_common_ptr cinfo);
EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table (j_common_ptr cinfo); EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table(j_common_ptr cinfo);
/* Main entry points for compression */ /* Main entry points for compression */
EXTERN(void) jpeg_start_compress (j_compress_ptr cinfo, EXTERN(void) jpeg_start_compress(j_compress_ptr cinfo,
boolean write_all_tables); boolean write_all_tables);
EXTERN(JDIMENSION) jpeg_write_scanlines (j_compress_ptr cinfo, EXTERN(JDIMENSION) jpeg_write_scanlines(j_compress_ptr cinfo,
JSAMPARRAY scanlines, JSAMPARRAY scanlines,
JDIMENSION num_lines); JDIMENSION num_lines);
EXTERN(void) jpeg_finish_compress (j_compress_ptr cinfo); EXTERN(void) jpeg_finish_compress(j_compress_ptr cinfo);
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
/* Precalculate JPEG dimensions for current compression parameters. */ /* Precalculate JPEG dimensions for current compression parameters. */
EXTERN(void) jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo); EXTERN(void) jpeg_calc_jpeg_dimensions(j_compress_ptr cinfo);
#endif #endif
/* Replaces jpeg_write_scanlines when writing raw downsampled data. */ /* Replaces jpeg_write_scanlines when writing raw downsampled data. */
EXTERN(JDIMENSION) jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data, EXTERN(JDIMENSION) jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
JDIMENSION num_lines); JDIMENSION num_lines);
/* Write a special marker. See libjpeg.txt concerning safe usage. */ /* Write a special marker. See libjpeg.txt concerning safe usage. */
EXTERN(void) jpeg_write_marker (j_compress_ptr cinfo, int marker, EXTERN(void) jpeg_write_marker(j_compress_ptr cinfo, int marker,
const JOCTET *dataptr, unsigned int datalen); const JOCTET *dataptr, unsigned int datalen);
/* Same, but piecemeal. */ /* Same, but piecemeal. */
EXTERN(void) jpeg_write_m_header (j_compress_ptr cinfo, int marker, EXTERN(void) jpeg_write_m_header(j_compress_ptr cinfo, int marker,
unsigned int datalen); unsigned int datalen);
EXTERN(void) jpeg_write_m_byte (j_compress_ptr cinfo, int val); EXTERN(void) jpeg_write_m_byte(j_compress_ptr cinfo, int val);
/* Alternate compression function: just write an abbreviated table file */ /* Alternate compression function: just write an abbreviated table file */
EXTERN(void) jpeg_write_tables (j_compress_ptr cinfo); EXTERN(void) jpeg_write_tables(j_compress_ptr cinfo);
/* Write ICC profile. See libjpeg.txt for usage information. */
EXTERN(void) jpeg_write_icc_profile(j_compress_ptr cinfo,
const JOCTET *icc_data_ptr,
unsigned int icc_data_len);
/* Decompression startup: read start of JPEG datastream to see what's there */ /* Decompression startup: read start of JPEG datastream to see what's there */
EXTERN(int) jpeg_read_header (j_decompress_ptr cinfo, boolean require_image); EXTERN(int) jpeg_read_header(j_decompress_ptr cinfo, boolean require_image);
/* Return value is one of: */ /* Return value is one of: */
#define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */ #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
#define JPEG_HEADER_OK 1 /* Found valid image datastream */ #define JPEG_HEADER_OK 1 /* Found valid image datastream */
@ -989,27 +994,27 @@ EXTERN(int) jpeg_read_header (j_decompress_ptr cinfo, boolean require_image);
*/ */
/* Main entry points for decompression */ /* Main entry points for decompression */
EXTERN(boolean) jpeg_start_decompress (j_decompress_ptr cinfo); EXTERN(boolean) jpeg_start_decompress(j_decompress_ptr cinfo);
EXTERN(JDIMENSION) jpeg_read_scanlines (j_decompress_ptr cinfo, EXTERN(JDIMENSION) jpeg_read_scanlines(j_decompress_ptr cinfo,
JSAMPARRAY scanlines, JSAMPARRAY scanlines,
JDIMENSION max_lines); JDIMENSION max_lines);
EXTERN(JDIMENSION) jpeg_skip_scanlines (j_decompress_ptr cinfo, EXTERN(JDIMENSION) jpeg_skip_scanlines(j_decompress_ptr cinfo,
JDIMENSION num_lines); JDIMENSION num_lines);
EXTERN(void) jpeg_crop_scanline (j_decompress_ptr cinfo, JDIMENSION *xoffset, EXTERN(void) jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
JDIMENSION *width); JDIMENSION *width);
EXTERN(boolean) jpeg_finish_decompress (j_decompress_ptr cinfo); EXTERN(boolean) jpeg_finish_decompress(j_decompress_ptr cinfo);
/* Replaces jpeg_read_scanlines when reading raw downsampled data. */ /* Replaces jpeg_read_scanlines when reading raw downsampled data. */
EXTERN(JDIMENSION) jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data, EXTERN(JDIMENSION) jpeg_read_raw_data(j_decompress_ptr cinfo, JSAMPIMAGE data,
JDIMENSION max_lines); JDIMENSION max_lines);
/* Additional entry points for buffered-image mode. */ /* Additional entry points for buffered-image mode. */
EXTERN(boolean) jpeg_has_multiple_scans (j_decompress_ptr cinfo); EXTERN(boolean) jpeg_has_multiple_scans(j_decompress_ptr cinfo);
EXTERN(boolean) jpeg_start_output (j_decompress_ptr cinfo, int scan_number); EXTERN(boolean) jpeg_start_output(j_decompress_ptr cinfo, int scan_number);
EXTERN(boolean) jpeg_finish_output (j_decompress_ptr cinfo); EXTERN(boolean) jpeg_finish_output(j_decompress_ptr cinfo);
EXTERN(boolean) jpeg_input_complete (j_decompress_ptr cinfo); EXTERN(boolean) jpeg_input_complete(j_decompress_ptr cinfo);
EXTERN(void) jpeg_new_colormap (j_decompress_ptr cinfo); EXTERN(void) jpeg_new_colormap(j_decompress_ptr cinfo);
EXTERN(int) jpeg_consume_input (j_decompress_ptr cinfo); EXTERN(int) jpeg_consume_input(j_decompress_ptr cinfo);
/* Return value is one of: */ /* Return value is one of: */
/* #define JPEG_SUSPENDED 0 Suspended due to lack of input data */ /* #define JPEG_SUSPENDED 0 Suspended due to lack of input data */
#define JPEG_REACHED_SOS 1 /* Reached start of new scan */ #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
@ -1019,24 +1024,24 @@ EXTERN(int) jpeg_consume_input (j_decompress_ptr cinfo);
/* Precalculate output dimensions for current decompression parameters. */ /* Precalculate output dimensions for current decompression parameters. */
#if JPEG_LIB_VERSION >= 80 #if JPEG_LIB_VERSION >= 80
EXTERN(void) jpeg_core_output_dimensions (j_decompress_ptr cinfo); EXTERN(void) jpeg_core_output_dimensions(j_decompress_ptr cinfo);
#endif #endif
EXTERN(void) jpeg_calc_output_dimensions (j_decompress_ptr cinfo); EXTERN(void) jpeg_calc_output_dimensions(j_decompress_ptr cinfo);
/* Control saving of COM and APPn markers into marker_list. */ /* Control saving of COM and APPn markers into marker_list. */
EXTERN(void) jpeg_save_markers (j_decompress_ptr cinfo, int marker_code, EXTERN(void) jpeg_save_markers(j_decompress_ptr cinfo, int marker_code,
unsigned int length_limit); unsigned int length_limit);
/* Install a special processing method for COM or APPn markers. */ /* Install a special processing method for COM or APPn markers. */
EXTERN(void) jpeg_set_marker_processor (j_decompress_ptr cinfo, EXTERN(void) jpeg_set_marker_processor(j_decompress_ptr cinfo,
int marker_code, int marker_code,
jpeg_marker_parser_method routine); jpeg_marker_parser_method routine);
/* Read or write raw DCT coefficients --- useful for lossless transcoding. */ /* Read or write raw DCT coefficients --- useful for lossless transcoding. */
EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients (j_decompress_ptr cinfo); EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients(j_decompress_ptr cinfo);
EXTERN(void) jpeg_write_coefficients (j_compress_ptr cinfo, EXTERN(void) jpeg_write_coefficients(j_compress_ptr cinfo,
jvirt_barray_ptr *coef_arrays); jvirt_barray_ptr *coef_arrays);
EXTERN(void) jpeg_copy_critical_parameters (j_decompress_ptr srcinfo, EXTERN(void) jpeg_copy_critical_parameters(j_decompress_ptr srcinfo,
j_compress_ptr dstinfo); j_compress_ptr dstinfo);
/* If you choose to abort compression or decompression before completing /* If you choose to abort compression or decompression before completing
@ -1045,17 +1050,22 @@ EXTERN(void) jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
* if you're done with the JPEG object, but if you want to clean it up and * if you're done with the JPEG object, but if you want to clean it up and
* reuse it, call this: * reuse it, call this:
*/ */
EXTERN(void) jpeg_abort_compress (j_compress_ptr cinfo); EXTERN(void) jpeg_abort_compress(j_compress_ptr cinfo);
EXTERN(void) jpeg_abort_decompress (j_decompress_ptr cinfo); EXTERN(void) jpeg_abort_decompress(j_decompress_ptr cinfo);
/* Generic versions of jpeg_abort and jpeg_destroy that work on either /* Generic versions of jpeg_abort and jpeg_destroy that work on either
* flavor of JPEG object. These may be more convenient in some places. * flavor of JPEG object. These may be more convenient in some places.
*/ */
EXTERN(void) jpeg_abort (j_common_ptr cinfo); EXTERN(void) jpeg_abort(j_common_ptr cinfo);
EXTERN(void) jpeg_destroy (j_common_ptr cinfo); EXTERN(void) jpeg_destroy(j_common_ptr cinfo);
/* Default restart-marker-resync procedure for use by data source modules */ /* Default restart-marker-resync procedure for use by data source modules */
EXTERN(boolean) jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired); EXTERN(boolean) jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired);
/* Read ICC profile. See libjpeg.txt for usage information. */
EXTERN(boolean) jpeg_read_icc_profile(j_decompress_ptr cinfo,
JOCTET **icc_data_ptr,
unsigned int *icc_data_len);
/* These marker codes are exported since applications and data source modules /* These marker codes are exported since applications and data source modules

View File

@ -73,8 +73,9 @@
#define ODITHER_SIZE 16 /* dimension of dither matrix */ #define ODITHER_SIZE 16 /* dimension of dither matrix */
/* NB: if ODITHER_SIZE is not a power of 2, ODITHER_MASK uses will break */ /* NB: if ODITHER_SIZE is not a power of 2, ODITHER_MASK uses will break */
#define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */ #define ODITHER_CELLS (ODITHER_SIZE * ODITHER_SIZE) /* # cells in matrix */
#define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */ #define ODITHER_MASK (ODITHER_SIZE - 1) /* mask for wrapping around
counters */
typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE]; typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE]; typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
@ -153,7 +154,7 @@ typedef struct {
*/ */
boolean is_padded; /* is the colorindex padded for odither? */ boolean is_padded; /* is the colorindex padded for odither? */
int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */ int Ncolors[MAX_Q_COMPS]; /* # of values allocated to each component */
/* Variables for ordered dithering */ /* Variables for ordered dithering */
int row_index; /* cur row's vertical index in dither matrix */ int row_index; /* cur row's vertical index in dither matrix */
@ -183,7 +184,7 @@ typedef my_cquantizer *my_cquantize_ptr;
LOCAL(int) LOCAL(int)
select_ncolors (j_decompress_ptr cinfo, int Ncolors[]) select_ncolors(j_decompress_ptr cinfo, int Ncolors[])
/* Determine allocation of desired colors to components, */ /* Determine allocation of desired colors to components, */
/* and fill in Ncolors[] array to indicate choice. */ /* and fill in Ncolors[] array to indicate choice. */
/* Return value is total number of colors (product of Ncolors[] values). */ /* Return value is total number of colors (product of Ncolors[] values). */
@ -206,12 +207,12 @@ select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
temp = iroot; /* set temp = iroot ** nc */ temp = iroot; /* set temp = iroot ** nc */
for (i = 1; i < nc; i++) for (i = 1; i < nc; i++)
temp *= iroot; temp *= iroot;
} while (temp <= (long) max_colors); /* repeat till iroot exceeds root */ } while (temp <= (long)max_colors); /* repeat till iroot exceeds root */
iroot--; /* now iroot = floor(root) */ iroot--; /* now iroot = floor(root) */
/* Must have at least 2 color values per component */ /* Must have at least 2 color values per component */
if (iroot < 2) if (iroot < 2)
ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp); ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int)temp);
/* Initialize to iroot color values for each component */ /* Initialize to iroot color values for each component */
total_colors = 1; total_colors = 1;
@ -231,11 +232,11 @@ select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i); j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
/* calculate new total_colors if Ncolors[j] is incremented */ /* calculate new total_colors if Ncolors[j] is incremented */
temp = total_colors / Ncolors[j]; temp = total_colors / Ncolors[j];
temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */ temp *= Ncolors[j] + 1; /* done in long arith to avoid oflo */
if (temp > (long) max_colors) if (temp > (long)max_colors)
break; /* won't fit, done with this pass */ break; /* won't fit, done with this pass */
Ncolors[j]++; /* OK, apply the increment */ Ncolors[j]++; /* OK, apply the increment */
total_colors = (int) temp; total_colors = (int)temp;
changed = TRUE; changed = TRUE;
} }
} while (changed); } while (changed);
@ -245,7 +246,7 @@ select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
LOCAL(int) LOCAL(int)
output_value (j_decompress_ptr cinfo, int ci, int j, int maxj) output_value(j_decompress_ptr cinfo, int ci, int j, int maxj)
/* Return j'th output value, where j will range from 0 to maxj */ /* Return j'th output value, where j will range from 0 to maxj */
/* The output values must fall in 0..MAXJSAMPLE in increasing order */ /* The output values must fall in 0..MAXJSAMPLE in increasing order */
{ {
@ -254,17 +255,17 @@ output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
* (Forcing the upper and lower values to the limits ensures that * (Forcing the upper and lower values to the limits ensures that
* dithering can't produce a color outside the selected gamut.) * dithering can't produce a color outside the selected gamut.)
*/ */
return (int) (((JLONG) j * MAXJSAMPLE + maxj/2) / maxj); return (int)(((JLONG)j * MAXJSAMPLE + maxj / 2) / maxj);
} }
LOCAL(int) LOCAL(int)
largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj) largest_input_value(j_decompress_ptr cinfo, int ci, int j, int maxj)
/* Return largest input value that should map to j'th output value */ /* Return largest input value that should map to j'th output value */
/* Must have largest(j=0) >= 0, and largest(j=maxj) >= MAXJSAMPLE */ /* Must have largest(j=0) >= 0, and largest(j=maxj) >= MAXJSAMPLE */
{ {
/* Breakpoints are halfway between values returned by output_value */ /* Breakpoints are halfway between values returned by output_value */
return (int) (((JLONG) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj)); return (int)(((JLONG)(2 * j + 1) * MAXJSAMPLE + maxj) / (2 * maxj));
} }
@ -273,21 +274,21 @@ largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
*/ */
LOCAL(void) LOCAL(void)
create_colormap (j_decompress_ptr cinfo) create_colormap(j_decompress_ptr cinfo)
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
JSAMPARRAY colormap; /* Created colormap */ JSAMPARRAY colormap; /* Created colormap */
int total_colors; /* Number of distinct output colors */ int total_colors; /* Number of distinct output colors */
int i,j,k, nci, blksize, blkdist, ptr, val; int i, j, k, nci, blksize, blkdist, ptr, val;
/* Select number of colors for each component */ /* Select number of colors for each component */
total_colors = select_ncolors(cinfo, cquantize->Ncolors); total_colors = select_ncolors(cinfo, cquantize->Ncolors);
/* Report selected color counts */ /* Report selected color counts */
if (cinfo->out_color_components == 3) if (cinfo->out_color_components == 3)
TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS, TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS, total_colors,
total_colors, cquantize->Ncolors[0], cquantize->Ncolors[0], cquantize->Ncolors[1],
cquantize->Ncolors[1], cquantize->Ncolors[2]); cquantize->Ncolors[2]);
else else
TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors); TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
@ -296,8 +297,8 @@ create_colormap (j_decompress_ptr cinfo)
/* i.e. rightmost (highest-indexed) color changes most rapidly. */ /* i.e. rightmost (highest-indexed) color changes most rapidly. */
colormap = (*cinfo->mem->alloc_sarray) colormap = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr)cinfo, JPOOL_IMAGE,
(JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components); (JDIMENSION)total_colors, (JDIMENSION)cinfo->out_color_components);
/* blksize is number of adjacent repeated entries for a component */ /* blksize is number of adjacent repeated entries for a component */
/* blkdist is distance between groups of identical entries for a component */ /* blkdist is distance between groups of identical entries for a component */
@ -309,12 +310,12 @@ create_colormap (j_decompress_ptr cinfo)
blksize = blkdist / nci; blksize = blkdist / nci;
for (j = 0; j < nci; j++) { for (j = 0; j < nci; j++) {
/* Compute j'th output value (out of nci) for component */ /* Compute j'th output value (out of nci) for component */
val = output_value(cinfo, i, j, nci-1); val = output_value(cinfo, i, j, nci - 1);
/* Fill in all colormap entries that have this value of this component */ /* Fill in all colormap entries that have this value of this component */
for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) { for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
/* fill in blksize entries beginning at ptr */ /* fill in blksize entries beginning at ptr */
for (k = 0; k < blksize; k++) for (k = 0; k < blksize; k++)
colormap[i][ptr+k] = (JSAMPLE) val; colormap[i][ptr + k] = (JSAMPLE)val;
} }
} }
blkdist = blksize; /* blksize of this color is blkdist of next */ blkdist = blksize; /* blksize of this color is blkdist of next */
@ -333,11 +334,11 @@ create_colormap (j_decompress_ptr cinfo)
*/ */
LOCAL(void) LOCAL(void)
create_colorindex (j_decompress_ptr cinfo) create_colorindex(j_decompress_ptr cinfo)
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
JSAMPROW indexptr; JSAMPROW indexptr;
int i,j,k, nci, blksize, val, pad; int i, j, k, nci, blksize, val, pad;
/* For ordered dither, we pad the color index tables by MAXJSAMPLE in /* For ordered dither, we pad the color index tables by MAXJSAMPLE in
* each direction (input index values can be -MAXJSAMPLE .. 2*MAXJSAMPLE). * each direction (input index values can be -MAXJSAMPLE .. 2*MAXJSAMPLE).
@ -345,7 +346,7 @@ create_colorindex (j_decompress_ptr cinfo)
* flag whether it was done in case user changes dithering mode. * flag whether it was done in case user changes dithering mode.
*/ */
if (cinfo->dither_mode == JDITHER_ORDERED) { if (cinfo->dither_mode == JDITHER_ORDERED) {
pad = MAXJSAMPLE*2; pad = MAXJSAMPLE * 2;
cquantize->is_padded = TRUE; cquantize->is_padded = TRUE;
} else { } else {
pad = 0; pad = 0;
@ -353,9 +354,9 @@ create_colorindex (j_decompress_ptr cinfo)
} }
cquantize->colorindex = (*cinfo->mem->alloc_sarray) cquantize->colorindex = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr)cinfo, JPOOL_IMAGE,
(JDIMENSION) (MAXJSAMPLE+1 + pad), (JDIMENSION)(MAXJSAMPLE + 1 + pad),
(JDIMENSION) cinfo->out_color_components); (JDIMENSION)cinfo->out_color_components);
/* blksize is number of adjacent repeated entries for a component */ /* blksize is number of adjacent repeated entries for a component */
blksize = cquantize->sv_actual; blksize = cquantize->sv_actual;
@ -373,18 +374,18 @@ create_colorindex (j_decompress_ptr cinfo)
/* and k = largest j that maps to current val */ /* and k = largest j that maps to current val */
indexptr = cquantize->colorindex[i]; indexptr = cquantize->colorindex[i];
val = 0; val = 0;
k = largest_input_value(cinfo, i, 0, nci-1); k = largest_input_value(cinfo, i, 0, nci - 1);
for (j = 0; j <= MAXJSAMPLE; j++) { for (j = 0; j <= MAXJSAMPLE; j++) {
while (j > k) /* advance val if past boundary */ while (j > k) /* advance val if past boundary */
k = largest_input_value(cinfo, i, ++val, nci-1); k = largest_input_value(cinfo, i, ++val, nci - 1);
/* premultiply so that no multiplication needed in main processing */ /* premultiply so that no multiplication needed in main processing */
indexptr[j] = (JSAMPLE) (val * blksize); indexptr[j] = (JSAMPLE)(val * blksize);
} }
/* Pad at both ends if necessary */ /* Pad at both ends if necessary */
if (pad) if (pad)
for (j = 1; j <= MAXJSAMPLE; j++) { for (j = 1; j <= MAXJSAMPLE; j++) {
indexptr[-j] = indexptr[0]; indexptr[-j] = indexptr[0];
indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE]; indexptr[MAXJSAMPLE + j] = indexptr[MAXJSAMPLE];
} }
} }
} }
@ -396,29 +397,29 @@ create_colorindex (j_decompress_ptr cinfo)
*/ */
LOCAL(ODITHER_MATRIX_PTR) LOCAL(ODITHER_MATRIX_PTR)
make_odither_array (j_decompress_ptr cinfo, int ncolors) make_odither_array(j_decompress_ptr cinfo, int ncolors)
{ {
ODITHER_MATRIX_PTR odither; ODITHER_MATRIX_PTR odither;
int j,k; int j, k;
JLONG num,den; JLONG num, den;
odither = (ODITHER_MATRIX_PTR) odither = (ODITHER_MATRIX_PTR)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(ODITHER_MATRIX)); sizeof(ODITHER_MATRIX));
/* The inter-value distance for this color is MAXJSAMPLE/(ncolors-1). /* The inter-value distance for this color is MAXJSAMPLE/(ncolors-1).
* Hence the dither value for the matrix cell with fill order f * Hence the dither value for the matrix cell with fill order f
* (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1). * (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1).
* On 16-bit-int machine, be careful to avoid overflow. * On 16-bit-int machine, be careful to avoid overflow.
*/ */
den = 2 * ODITHER_CELLS * ((JLONG) (ncolors - 1)); den = 2 * ODITHER_CELLS * ((JLONG)(ncolors - 1));
for (j = 0; j < ODITHER_SIZE; j++) { for (j = 0; j < ODITHER_SIZE; j++) {
for (k = 0; k < ODITHER_SIZE; k++) { for (k = 0; k < ODITHER_SIZE; k++) {
num = ((JLONG) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k]))) num = ((JLONG)(ODITHER_CELLS - 1 -
* MAXJSAMPLE; 2 * ((int)base_dither_matrix[j][k]))) * MAXJSAMPLE;
/* Ensure round towards zero despite C's lack of consistency /* Ensure round towards zero despite C's lack of consistency
* about rounding negative values in integer division... * about rounding negative values in integer division...
*/ */
odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den); odither[j][k] = (int)(num < 0 ? -((-num) / den) : num / den);
} }
} }
return odither; return odither;
@ -432,9 +433,9 @@ make_odither_array (j_decompress_ptr cinfo, int ncolors)
*/ */
LOCAL(void) LOCAL(void)
create_odither_tables (j_decompress_ptr cinfo) create_odither_tables(j_decompress_ptr cinfo)
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
ODITHER_MATRIX_PTR odither; ODITHER_MATRIX_PTR odither;
int i, j, nci; int i, j, nci;
@ -459,11 +460,11 @@ create_odither_tables (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf, color_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
/* General case, no dithering */ /* General case, no dithering */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
JSAMPARRAY colorindex = cquantize->colorindex; JSAMPARRAY colorindex = cquantize->colorindex;
register int pixcode, ci; register int pixcode, ci;
register JSAMPROW ptrin, ptrout; register JSAMPROW ptrin, ptrout;
@ -480,18 +481,18 @@ color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (ci = 0; ci < nc; ci++) { for (ci = 0; ci < nc; ci++) {
pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]); pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
} }
*ptrout++ = (JSAMPLE) pixcode; *ptrout++ = (JSAMPLE)pixcode;
} }
} }
} }
METHODDEF(void) METHODDEF(void)
color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf, color_quantize3(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
/* Fast path for out_color_components==3, no dithering */ /* Fast path for out_color_components==3, no dithering */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
register int pixcode; register int pixcode;
register JSAMPROW ptrin, ptrout; register JSAMPROW ptrin, ptrout;
JSAMPROW colorindex0 = cquantize->colorindex[0]; JSAMPROW colorindex0 = cquantize->colorindex[0];
@ -508,18 +509,18 @@ color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]); pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]); pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]); pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
*ptrout++ = (JSAMPLE) pixcode; *ptrout++ = (JSAMPLE)pixcode;
} }
} }
} }
METHODDEF(void) METHODDEF(void)
quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, quantize_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
/* General case, with ordered dithering */ /* General case, with ordered dithering */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
register JSAMPROW input_ptr; register JSAMPROW input_ptr;
register JSAMPROW output_ptr; register JSAMPROW output_ptr;
JSAMPROW colorindex_ci; JSAMPROW colorindex_ci;
@ -533,7 +534,7 @@ quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (row = 0; row < num_rows; row++) { for (row = 0; row < num_rows; row++) {
/* Initialize output values to 0 so can process components separately */ /* Initialize output values to 0 so can process components separately */
jzero_far((void *) output_buf[row], (size_t) (width * sizeof(JSAMPLE))); jzero_far((void *)output_buf[row], (size_t)(width * sizeof(JSAMPLE)));
row_index = cquantize->row_index; row_index = cquantize->row_index;
for (ci = 0; ci < nc; ci++) { for (ci = 0; ci < nc; ci++) {
input_ptr = input_buf[row] + ci; input_ptr = input_buf[row] + ci;
@ -550,7 +551,8 @@ quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
* inputs. The maximum dither is +- MAXJSAMPLE; this sets the * inputs. The maximum dither is +- MAXJSAMPLE; this sets the
* required amount of padding. * required amount of padding.
*/ */
*output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]]; *output_ptr +=
colorindex_ci[GETJSAMPLE(*input_ptr) + dither[col_index]];
input_ptr += nc; input_ptr += nc;
output_ptr++; output_ptr++;
col_index = (col_index + 1) & ODITHER_MASK; col_index = (col_index + 1) & ODITHER_MASK;
@ -564,11 +566,11 @@ quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
METHODDEF(void) METHODDEF(void)
quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, quantize3_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
/* Fast path for out_color_components==3, with ordered dithering */ /* Fast path for out_color_components==3, with ordered dithering */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
register int pixcode; register int pixcode;
register JSAMPROW input_ptr; register JSAMPROW input_ptr;
register JSAMPROW output_ptr; register JSAMPROW output_ptr;
@ -593,13 +595,13 @@ quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
col_index = 0; col_index = 0;
for (col = width; col > 0; col--) { for (col = width; col > 0; col--) {
pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) + pixcode =
dither0[col_index]]); GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) + dither0[col_index]]);
pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) + pixcode +=
dither1[col_index]]); GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) + dither1[col_index]]);
pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) + pixcode +=
dither2[col_index]]); GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) + dither2[col_index]]);
*output_ptr++ = (JSAMPLE) pixcode; *output_ptr++ = (JSAMPLE)pixcode;
col_index = (col_index + 1) & ODITHER_MASK; col_index = (col_index + 1) & ODITHER_MASK;
} }
row_index = (row_index + 1) & ODITHER_MASK; row_index = (row_index + 1) & ODITHER_MASK;
@ -609,11 +611,11 @@ quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
METHODDEF(void) METHODDEF(void)
quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, quantize_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
/* General case, with Floyd-Steinberg dithering */ /* General case, with Floyd-Steinberg dithering */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
register LOCFSERROR cur; /* current error or pixel value */ register LOCFSERROR cur; /* current error or pixel value */
LOCFSERROR belowerr; /* error for pixel below cur */ LOCFSERROR belowerr; /* error for pixel below cur */
LOCFSERROR bpreverr; /* error for below/prev col */ LOCFSERROR bpreverr; /* error for below/prev col */
@ -637,17 +639,17 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (row = 0; row < num_rows; row++) { for (row = 0; row < num_rows; row++) {
/* Initialize output values to 0 so can process components separately */ /* Initialize output values to 0 so can process components separately */
jzero_far((void *) output_buf[row], (size_t) (width * sizeof(JSAMPLE))); jzero_far((void *)output_buf[row], (size_t)(width * sizeof(JSAMPLE)));
for (ci = 0; ci < nc; ci++) { for (ci = 0; ci < nc; ci++) {
input_ptr = input_buf[row] + ci; input_ptr = input_buf[row] + ci;
output_ptr = output_buf[row]; output_ptr = output_buf[row];
if (cquantize->on_odd_row) { if (cquantize->on_odd_row) {
/* work right to left in this row */ /* work right to left in this row */
input_ptr += (width-1) * nc; /* so point to rightmost pixel */ input_ptr += (width - 1) * nc; /* so point to rightmost pixel */
output_ptr += width-1; output_ptr += width - 1;
dir = -1; dir = -1;
dirnc = -nc; dirnc = -nc;
errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */ errorptr = cquantize->fserrors[ci] + (width + 1); /* => entry after last column */
} else { } else {
/* work left to right in this row */ /* work left to right in this row */
dir = 1; dir = 1;
@ -679,7 +681,7 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
cur = GETJSAMPLE(range_limit[cur]); cur = GETJSAMPLE(range_limit[cur]);
/* Select output value, accumulate into output code for this pixel */ /* Select output value, accumulate into output code for this pixel */
pixcode = GETJSAMPLE(colorindex_ci[cur]); pixcode = GETJSAMPLE(colorindex_ci[cur]);
*output_ptr += (JSAMPLE) pixcode; *output_ptr += (JSAMPLE)pixcode;
/* Compute actual representation error at this pixel */ /* Compute actual representation error at this pixel */
/* Note: we can do this even though we don't have the final */ /* Note: we can do this even though we don't have the final */
/* pixel code, because the colormap is orthogonal. */ /* pixel code, because the colormap is orthogonal. */
@ -691,7 +693,7 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
bnexterr = cur; bnexterr = cur;
delta = cur * 2; delta = cur * 2;
cur += delta; /* form error * 3 */ cur += delta; /* form error * 3 */
errorptr[0] = (FSERROR) (bpreverr + cur); errorptr[0] = (FSERROR)(bpreverr + cur);
cur += delta; /* form error * 5 */ cur += delta; /* form error * 5 */
bpreverr = belowerr + cur; bpreverr = belowerr + cur;
belowerr = bnexterr; belowerr = bnexterr;
@ -708,7 +710,7 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
* final fserrors[] entry. Note we need not unload belowerr because * final fserrors[] entry. Note we need not unload belowerr because
* it is for the dummy column before or after the actual array. * it is for the dummy column before or after the actual array.
*/ */
errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */ errorptr[0] = (FSERROR)bpreverr; /* unload prev err into array */
} }
cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE); cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
} }
@ -720,16 +722,16 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
*/ */
LOCAL(void) LOCAL(void)
alloc_fs_workspace (j_decompress_ptr cinfo) alloc_fs_workspace(j_decompress_ptr cinfo)
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
size_t arraysize; size_t arraysize;
int i; int i;
arraysize = (size_t) ((cinfo->output_width + 2) * sizeof(FSERROR)); arraysize = (size_t)((cinfo->output_width + 2) * sizeof(FSERROR));
for (i = 0; i < cinfo->out_color_components; i++) { for (i = 0; i < cinfo->out_color_components; i++) {
cquantize->fserrors[i] = (FSERRPTR) cquantize->fserrors[i] = (FSERRPTR)
(*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize); (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE, arraysize);
} }
} }
@ -739,9 +741,9 @@ alloc_fs_workspace (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan) start_pass_1_quant(j_decompress_ptr cinfo, boolean is_pre_scan)
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
size_t arraysize; size_t arraysize;
int i; int i;
@ -767,7 +769,7 @@ start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
* we must recreate the color index table with padding. * we must recreate the color index table with padding.
* This will cost extra space, but probably isn't very likely. * This will cost extra space, but probably isn't very likely.
*/ */
if (! cquantize->is_padded) if (!cquantize->is_padded)
create_colorindex(cinfo); create_colorindex(cinfo);
/* Create ordered-dither tables if we didn't already. */ /* Create ordered-dither tables if we didn't already. */
if (cquantize->odither[0] == NULL) if (cquantize->odither[0] == NULL)
@ -780,9 +782,9 @@ start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
if (cquantize->fserrors[0] == NULL) if (cquantize->fserrors[0] == NULL)
alloc_fs_workspace(cinfo); alloc_fs_workspace(cinfo);
/* Initialize the propagated errors to zero. */ /* Initialize the propagated errors to zero. */
arraysize = (size_t) ((cinfo->output_width + 2) * sizeof(FSERROR)); arraysize = (size_t)((cinfo->output_width + 2) * sizeof(FSERROR));
for (i = 0; i < cinfo->out_color_components; i++) for (i = 0; i < cinfo->out_color_components; i++)
jzero_far((void *) cquantize->fserrors[i], arraysize); jzero_far((void *)cquantize->fserrors[i], arraysize);
break; break;
default: default:
ERREXIT(cinfo, JERR_NOT_COMPILED); ERREXIT(cinfo, JERR_NOT_COMPILED);
@ -796,7 +798,7 @@ start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
*/ */
METHODDEF(void) METHODDEF(void)
finish_pass_1_quant (j_decompress_ptr cinfo) finish_pass_1_quant(j_decompress_ptr cinfo)
{ {
/* no work in 1-pass case */ /* no work in 1-pass case */
} }
@ -808,7 +810,7 @@ finish_pass_1_quant (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
new_color_map_1_quant (j_decompress_ptr cinfo) new_color_map_1_quant(j_decompress_ptr cinfo)
{ {
ERREXIT(cinfo, JERR_MODE_CHANGE); ERREXIT(cinfo, JERR_MODE_CHANGE);
} }
@ -819,14 +821,14 @@ new_color_map_1_quant (j_decompress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_1pass_quantizer (j_decompress_ptr cinfo) jinit_1pass_quantizer(j_decompress_ptr cinfo)
{ {
my_cquantize_ptr cquantize; my_cquantize_ptr cquantize;
cquantize = (my_cquantize_ptr) cquantize = (my_cquantize_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_cquantizer)); sizeof(my_cquantizer));
cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize; cinfo->cquantize = (struct jpeg_color_quantizer *)cquantize;
cquantize->pub.start_pass = start_pass_1_quant; cquantize->pub.start_pass = start_pass_1_quant;
cquantize->pub.finish_pass = finish_pass_1_quant; cquantize->pub.finish_pass = finish_pass_1_quant;
cquantize->pub.new_color_map = new_color_map_1_quant; cquantize->pub.new_color_map = new_color_map_1_quant;
@ -837,8 +839,8 @@ jinit_1pass_quantizer (j_decompress_ptr cinfo)
if (cinfo->out_color_components > MAX_Q_COMPS) if (cinfo->out_color_components > MAX_Q_COMPS)
ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS); ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
/* Make sure colormap indexes can be represented by JSAMPLEs */ /* Make sure colormap indexes can be represented by JSAMPLEs */
if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1)) if (cinfo->desired_number_of_colors > (MAXJSAMPLE + 1))
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1); ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE + 1);
/* Create the colormap and color index table. */ /* Create the colormap and color index table. */
create_colormap(cinfo); create_colormap(cinfo);

View File

@ -77,7 +77,7 @@
#define G_SCALE 3 /* scale G distances by this much */ #define G_SCALE 3 /* scale G distances by this much */
#define B_SCALE 1 /* and B by this much */ #define B_SCALE 1 /* and B by this much */
static const int c_scales[3]={R_SCALE, G_SCALE, B_SCALE}; static const int c_scales[3] = { R_SCALE, G_SCALE, B_SCALE };
#define C0_SCALE c_scales[rgb_red[cinfo->out_color_space]] #define C0_SCALE c_scales[rgb_red[cinfo->out_color_space]]
#define C1_SCALE c_scales[rgb_green[cinfo->out_color_space]] #define C1_SCALE c_scales[rgb_green[cinfo->out_color_space]]
#define C2_SCALE c_scales[rgb_blue[cinfo->out_color_space]] #define C2_SCALE c_scales[rgb_blue[cinfo->out_color_space]]
@ -106,7 +106,7 @@ static const int c_scales[3]={R_SCALE, G_SCALE, B_SCALE};
* each 2-D array has 2^6*2^5 = 2048 or 2^6*2^6 = 4096 entries. * each 2-D array has 2^6*2^5 = 2048 or 2^6*2^6 = 4096 entries.
*/ */
#define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */ #define MAXNUMCOLORS (MAXJSAMPLE + 1) /* maximum size of colormap */
/* These will do the right thing for either R,G,B or B,G,R color order, /* These will do the right thing for either R,G,B or B,G,R color order,
* but you may not like the results for other color orders. * but you may not like the results for other color orders.
@ -116,14 +116,14 @@ static const int c_scales[3]={R_SCALE, G_SCALE, B_SCALE};
#define HIST_C2_BITS 5 /* bits of precision in B/R histogram */ #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
/* Number of elements along histogram axes. */ /* Number of elements along histogram axes. */
#define HIST_C0_ELEMS (1<<HIST_C0_BITS) #define HIST_C0_ELEMS (1 << HIST_C0_BITS)
#define HIST_C1_ELEMS (1<<HIST_C1_BITS) #define HIST_C1_ELEMS (1 << HIST_C1_BITS)
#define HIST_C2_ELEMS (1<<HIST_C2_BITS) #define HIST_C2_ELEMS (1 << HIST_C2_BITS)
/* These are the amounts to shift an input value to get a histogram index. */ /* These are the amounts to shift an input value to get a histogram index. */
#define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS) #define C0_SHIFT (BITS_IN_JSAMPLE - HIST_C0_BITS)
#define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS) #define C1_SHIFT (BITS_IN_JSAMPLE - HIST_C1_BITS)
#define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS) #define C2_SHIFT (BITS_IN_JSAMPLE - HIST_C2_BITS)
typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */ typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
@ -200,10 +200,10 @@ typedef my_cquantizer *my_cquantize_ptr;
*/ */
METHODDEF(void) METHODDEF(void)
prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf, prescan_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
register JSAMPROW ptr; register JSAMPROW ptr;
register histptr histp; register histptr histp;
register hist3d histogram = cquantize->histogram; register hist3d histogram = cquantize->histogram;
@ -215,7 +215,7 @@ prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
ptr = input_buf[row]; ptr = input_buf[row];
for (col = width; col > 0; col--) { for (col = width; col > 0; col--) {
/* get pixel value and index into the histogram */ /* get pixel value and index into the histogram */
histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT] histp = &histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
[GETJSAMPLE(ptr[1]) >> C1_SHIFT] [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
[GETJSAMPLE(ptr[2]) >> C2_SHIFT]; [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
/* increment, check for overflow and undo increment if so. */ /* increment, check for overflow and undo increment if so. */
@ -249,7 +249,7 @@ typedef box *boxptr;
LOCAL(boxptr) LOCAL(boxptr)
find_biggest_color_pop (boxptr boxlist, int numboxes) find_biggest_color_pop(boxptr boxlist, int numboxes)
/* Find the splittable box with the largest color population */ /* Find the splittable box with the largest color population */
/* Returns NULL if no splittable boxes remain */ /* Returns NULL if no splittable boxes remain */
{ {
@ -269,7 +269,7 @@ find_biggest_color_pop (boxptr boxlist, int numboxes)
LOCAL(boxptr) LOCAL(boxptr)
find_biggest_volume (boxptr boxlist, int numboxes) find_biggest_volume(boxptr boxlist, int numboxes)
/* Find the splittable box with the largest (scaled) volume */ /* Find the splittable box with the largest (scaled) volume */
/* Returns NULL if no splittable boxes remain */ /* Returns NULL if no splittable boxes remain */
{ {
@ -289,16 +289,16 @@ find_biggest_volume (boxptr boxlist, int numboxes)
LOCAL(void) LOCAL(void)
update_box (j_decompress_ptr cinfo, boxptr boxp) update_box(j_decompress_ptr cinfo, boxptr boxp)
/* Shrink the min/max bounds of a box to enclose only nonzero elements, */ /* Shrink the min/max bounds of a box to enclose only nonzero elements, */
/* and recompute its volume and population */ /* and recompute its volume and population */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
hist3d histogram = cquantize->histogram; hist3d histogram = cquantize->histogram;
histptr histp; histptr histp;
int c0,c1,c2; int c0, c1, c2;
int c0min,c0max,c1min,c1max,c2min,c2max; int c0min, c0max, c1min, c1max, c2min, c2max;
JLONG dist0,dist1,dist2; JLONG dist0, dist1, dist2;
long ccount; long ccount;
c0min = boxp->c0min; c0max = boxp->c0max; c0min = boxp->c0min; c0max = boxp->c0max;
@ -308,69 +308,69 @@ update_box (j_decompress_ptr cinfo, boxptr boxp)
if (c0max > c0min) if (c0max > c0min)
for (c0 = c0min; c0 <= c0max; c0++) for (c0 = c0min; c0 <= c0max; c0++)
for (c1 = c1min; c1 <= c1max; c1++) { for (c1 = c1min; c1 <= c1max; c1++) {
histp = & histogram[c0][c1][c2min]; histp = &histogram[c0][c1][c2min];
for (c2 = c2min; c2 <= c2max; c2++) for (c2 = c2min; c2 <= c2max; c2++)
if (*histp++ != 0) { if (*histp++ != 0) {
boxp->c0min = c0min = c0; boxp->c0min = c0min = c0;
goto have_c0min; goto have_c0min;
} }
} }
have_c0min: have_c0min:
if (c0max > c0min) if (c0max > c0min)
for (c0 = c0max; c0 >= c0min; c0--) for (c0 = c0max; c0 >= c0min; c0--)
for (c1 = c1min; c1 <= c1max; c1++) { for (c1 = c1min; c1 <= c1max; c1++) {
histp = & histogram[c0][c1][c2min]; histp = &histogram[c0][c1][c2min];
for (c2 = c2min; c2 <= c2max; c2++) for (c2 = c2min; c2 <= c2max; c2++)
if (*histp++ != 0) { if (*histp++ != 0) {
boxp->c0max = c0max = c0; boxp->c0max = c0max = c0;
goto have_c0max; goto have_c0max;
} }
} }
have_c0max: have_c0max:
if (c1max > c1min) if (c1max > c1min)
for (c1 = c1min; c1 <= c1max; c1++) for (c1 = c1min; c1 <= c1max; c1++)
for (c0 = c0min; c0 <= c0max; c0++) { for (c0 = c0min; c0 <= c0max; c0++) {
histp = & histogram[c0][c1][c2min]; histp = &histogram[c0][c1][c2min];
for (c2 = c2min; c2 <= c2max; c2++) for (c2 = c2min; c2 <= c2max; c2++)
if (*histp++ != 0) { if (*histp++ != 0) {
boxp->c1min = c1min = c1; boxp->c1min = c1min = c1;
goto have_c1min; goto have_c1min;
} }
} }
have_c1min: have_c1min:
if (c1max > c1min) if (c1max > c1min)
for (c1 = c1max; c1 >= c1min; c1--) for (c1 = c1max; c1 >= c1min; c1--)
for (c0 = c0min; c0 <= c0max; c0++) { for (c0 = c0min; c0 <= c0max; c0++) {
histp = & histogram[c0][c1][c2min]; histp = &histogram[c0][c1][c2min];
for (c2 = c2min; c2 <= c2max; c2++) for (c2 = c2min; c2 <= c2max; c2++)
if (*histp++ != 0) { if (*histp++ != 0) {
boxp->c1max = c1max = c1; boxp->c1max = c1max = c1;
goto have_c1max; goto have_c1max;
} }
} }
have_c1max: have_c1max:
if (c2max > c2min) if (c2max > c2min)
for (c2 = c2min; c2 <= c2max; c2++) for (c2 = c2min; c2 <= c2max; c2++)
for (c0 = c0min; c0 <= c0max; c0++) { for (c0 = c0min; c0 <= c0max; c0++) {
histp = & histogram[c0][c1min][c2]; histp = &histogram[c0][c1min][c2];
for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS) for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
if (*histp != 0) { if (*histp != 0) {
boxp->c2min = c2min = c2; boxp->c2min = c2min = c2;
goto have_c2min; goto have_c2min;
} }
} }
have_c2min: have_c2min:
if (c2max > c2min) if (c2max > c2min)
for (c2 = c2max; c2 >= c2min; c2--) for (c2 = c2max; c2 >= c2min; c2--)
for (c0 = c0min; c0 <= c0max; c0++) { for (c0 = c0min; c0 <= c0max; c0++) {
histp = & histogram[c0][c1min][c2]; histp = &histogram[c0][c1min][c2];
for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS) for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
if (*histp != 0) { if (*histp != 0) {
boxp->c2max = c2max = c2; boxp->c2max = c2max = c2;
goto have_c2max; goto have_c2max;
} }
} }
have_c2max: have_c2max:
/* Update box volume. /* Update box volume.
* We use 2-norm rather than real volume here; this biases the method * We use 2-norm rather than real volume here; this biases the method
@ -383,13 +383,13 @@ update_box (j_decompress_ptr cinfo, boxptr boxp)
dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE; dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE; dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE; dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2; boxp->volume = dist0 * dist0 + dist1 * dist1 + dist2 * dist2;
/* Now scan remaining volume of box and compute population */ /* Now scan remaining volume of box and compute population */
ccount = 0; ccount = 0;
for (c0 = c0min; c0 <= c0max; c0++) for (c0 = c0min; c0 <= c0max; c0++)
for (c1 = c1min; c1 <= c1max; c1++) { for (c1 = c1min; c1 <= c1max; c1++) {
histp = & histogram[c0][c1][c2min]; histp = &histogram[c0][c1][c2min];
for (c2 = c2min; c2 <= c2max; c2++, histp++) for (c2 = c2min; c2 <= c2max; c2++, histp++)
if (*histp != 0) { if (*histp != 0) {
ccount++; ccount++;
@ -400,19 +400,19 @@ update_box (j_decompress_ptr cinfo, boxptr boxp)
LOCAL(int) LOCAL(int)
median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes, median_cut(j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
int desired_colors) int desired_colors)
/* Repeatedly select and split the largest box until we have enough boxes */ /* Repeatedly select and split the largest box until we have enough boxes */
{ {
int n,lb; int n, lb;
int c0,c1,c2,cmax; int c0, c1, c2, cmax;
register boxptr b1,b2; register boxptr b1, b2;
while (numboxes < desired_colors) { while (numboxes < desired_colors) {
/* Select box to split. /* Select box to split.
* Current algorithm: by population for first half, then by volume. * Current algorithm: by population for first half, then by volume.
*/ */
if (numboxes*2 <= desired_colors) { if (numboxes * 2 <= desired_colors) {
b1 = find_biggest_color_pop(boxlist, numboxes); b1 = find_biggest_color_pop(boxlist, numboxes);
} else { } else {
b1 = find_biggest_volume(boxlist, numboxes); b1 = find_biggest_volume(boxlist, numboxes);
@ -437,8 +437,7 @@ median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
cmax = c1; n = 1; cmax = c1; n = 1;
if (c0 > cmax) { cmax = c0; n = 0; } if (c0 > cmax) { cmax = c0; n = 0; }
if (c2 > cmax) { n = 2; } if (c2 > cmax) { n = 2; }
} } else {
else {
cmax = c1; n = 1; cmax = c1; n = 1;
if (c2 > cmax) { cmax = c2; n = 2; } if (c2 > cmax) { cmax = c2; n = 2; }
if (c0 > cmax) { n = 0; } if (c0 > cmax) { n = 0; }
@ -453,17 +452,17 @@ median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
case 0: case 0:
lb = (b1->c0max + b1->c0min) / 2; lb = (b1->c0max + b1->c0min) / 2;
b1->c0max = lb; b1->c0max = lb;
b2->c0min = lb+1; b2->c0min = lb + 1;
break; break;
case 1: case 1:
lb = (b1->c1max + b1->c1min) / 2; lb = (b1->c1max + b1->c1min) / 2;
b1->c1max = lb; b1->c1max = lb;
b2->c1min = lb+1; b2->c1min = lb + 1;
break; break;
case 2: case 2:
lb = (b1->c2max + b1->c2min) / 2; lb = (b1->c2max + b1->c2min) / 2;
b1->c2max = lb; b1->c2max = lb;
b2->c2min = lb+1; b2->c2min = lb + 1;
break; break;
} }
/* Update stats for boxes */ /* Update stats for boxes */
@ -476,16 +475,16 @@ median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
LOCAL(void) LOCAL(void)
compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor) compute_color(j_decompress_ptr cinfo, boxptr boxp, int icolor)
/* Compute representative color for a box, put it in colormap[icolor] */ /* Compute representative color for a box, put it in colormap[icolor] */
{ {
/* Current algorithm: mean weighted by pixels (not colors) */ /* Current algorithm: mean weighted by pixels (not colors) */
/* Note it is important to get the rounding correct! */ /* Note it is important to get the rounding correct! */
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
hist3d histogram = cquantize->histogram; hist3d histogram = cquantize->histogram;
histptr histp; histptr histp;
int c0,c1,c2; int c0, c1, c2;
int c0min,c0max,c1min,c1max,c2min,c2max; int c0min, c0max, c1min, c1max, c2min, c2max;
long count; long count;
long total = 0; long total = 0;
long c0total = 0; long c0total = 0;
@ -498,25 +497,25 @@ compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
for (c0 = c0min; c0 <= c0max; c0++) for (c0 = c0min; c0 <= c0max; c0++)
for (c1 = c1min; c1 <= c1max; c1++) { for (c1 = c1min; c1 <= c1max; c1++) {
histp = & histogram[c0][c1][c2min]; histp = &histogram[c0][c1][c2min];
for (c2 = c2min; c2 <= c2max; c2++) { for (c2 = c2min; c2 <= c2max; c2++) {
if ((count = *histp++) != 0) { if ((count = *histp++) != 0) {
total += count; total += count;
c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count; c0total += ((c0 << C0_SHIFT) + ((1 << C0_SHIFT) >> 1)) * count;
c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count; c1total += ((c1 << C1_SHIFT) + ((1 << C1_SHIFT) >> 1)) * count;
c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count; c2total += ((c2 << C2_SHIFT) + ((1 << C2_SHIFT) >> 1)) * count;
} }
} }
} }
cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total); cinfo->colormap[0][icolor] = (JSAMPLE)((c0total + (total >> 1)) / total);
cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total); cinfo->colormap[1][icolor] = (JSAMPLE)((c1total + (total >> 1)) / total);
cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total); cinfo->colormap[2][icolor] = (JSAMPLE)((c2total + (total >> 1)) / total);
} }
LOCAL(void) LOCAL(void)
select_colors (j_decompress_ptr cinfo, int desired_colors) select_colors(j_decompress_ptr cinfo, int desired_colors)
/* Master routine for color selection */ /* Master routine for color selection */
{ {
boxptr boxlist; boxptr boxlist;
@ -524,8 +523,8 @@ select_colors (j_decompress_ptr cinfo, int desired_colors)
int i; int i;
/* Allocate workspace for box list */ /* Allocate workspace for box list */
boxlist = (boxptr) (*cinfo->mem->alloc_small) boxlist = (boxptr)(*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * sizeof(box)); ((j_common_ptr)cinfo, JPOOL_IMAGE, desired_colors * sizeof(box));
/* Initialize one box containing whole space */ /* Initialize one box containing whole space */
numboxes = 1; numboxes = 1;
boxlist[0].c0min = 0; boxlist[0].c0min = 0;
@ -535,12 +534,12 @@ select_colors (j_decompress_ptr cinfo, int desired_colors)
boxlist[0].c2min = 0; boxlist[0].c2min = 0;
boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT; boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
/* Shrink it to actually-used volume and set its statistics */ /* Shrink it to actually-used volume and set its statistics */
update_box(cinfo, & boxlist[0]); update_box(cinfo, &boxlist[0]);
/* Perform median-cut to produce final box list */ /* Perform median-cut to produce final box list */
numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors); numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
/* Compute the representative color for each box, fill colormap */ /* Compute the representative color for each box, fill colormap */
for (i = 0; i < numboxes; i++) for (i = 0; i < numboxes; i++)
compute_color(cinfo, & boxlist[i], i); compute_color(cinfo, &boxlist[i], i);
cinfo->actual_number_of_colors = numboxes; cinfo->actual_number_of_colors = numboxes;
TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes); TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
} }
@ -601,13 +600,13 @@ select_colors (j_decompress_ptr cinfo, int desired_colors)
/* log2(histogram cells in update box) for each axis; this can be adjusted */ /* log2(histogram cells in update box) for each axis; this can be adjusted */
#define BOX_C0_LOG (HIST_C0_BITS-3) #define BOX_C0_LOG (HIST_C0_BITS - 3)
#define BOX_C1_LOG (HIST_C1_BITS-3) #define BOX_C1_LOG (HIST_C1_BITS - 3)
#define BOX_C2_LOG (HIST_C2_BITS-3) #define BOX_C2_LOG (HIST_C2_BITS - 3)
#define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */ #define BOX_C0_ELEMS (1 << BOX_C0_LOG) /* # of hist cells in update box */
#define BOX_C1_ELEMS (1<<BOX_C1_LOG) #define BOX_C1_ELEMS (1 << BOX_C1_LOG)
#define BOX_C2_ELEMS (1<<BOX_C2_LOG) #define BOX_C2_ELEMS (1 << BOX_C2_LOG)
#define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG) #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
#define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG) #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
@ -623,7 +622,7 @@ select_colors (j_decompress_ptr cinfo, int desired_colors)
*/ */
LOCAL(int) LOCAL(int)
find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2, find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
JSAMPLE colorlist[]) JSAMPLE colorlist[])
/* Locate the colormap entries close enough to an update box to be candidates /* Locate the colormap entries close enough to an update box to be candidates
* for the nearest entry to some cell(s) in the update box. The update box * for the nearest entry to some cell(s) in the update box. The update box
@ -669,67 +668,67 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
x = GETJSAMPLE(cinfo->colormap[0][i]); x = GETJSAMPLE(cinfo->colormap[0][i]);
if (x < minc0) { if (x < minc0) {
tdist = (x - minc0) * C0_SCALE; tdist = (x - minc0) * C0_SCALE;
min_dist = tdist*tdist; min_dist = tdist * tdist;
tdist = (x - maxc0) * C0_SCALE; tdist = (x - maxc0) * C0_SCALE;
max_dist = tdist*tdist; max_dist = tdist * tdist;
} else if (x > maxc0) { } else if (x > maxc0) {
tdist = (x - maxc0) * C0_SCALE; tdist = (x - maxc0) * C0_SCALE;
min_dist = tdist*tdist; min_dist = tdist * tdist;
tdist = (x - minc0) * C0_SCALE; tdist = (x - minc0) * C0_SCALE;
max_dist = tdist*tdist; max_dist = tdist * tdist;
} else { } else {
/* within cell range so no contribution to min_dist */ /* within cell range so no contribution to min_dist */
min_dist = 0; min_dist = 0;
if (x <= centerc0) { if (x <= centerc0) {
tdist = (x - maxc0) * C0_SCALE; tdist = (x - maxc0) * C0_SCALE;
max_dist = tdist*tdist; max_dist = tdist * tdist;
} else { } else {
tdist = (x - minc0) * C0_SCALE; tdist = (x - minc0) * C0_SCALE;
max_dist = tdist*tdist; max_dist = tdist * tdist;
} }
} }
x = GETJSAMPLE(cinfo->colormap[1][i]); x = GETJSAMPLE(cinfo->colormap[1][i]);
if (x < minc1) { if (x < minc1) {
tdist = (x - minc1) * C1_SCALE; tdist = (x - minc1) * C1_SCALE;
min_dist += tdist*tdist; min_dist += tdist * tdist;
tdist = (x - maxc1) * C1_SCALE; tdist = (x - maxc1) * C1_SCALE;
max_dist += tdist*tdist; max_dist += tdist * tdist;
} else if (x > maxc1) { } else if (x > maxc1) {
tdist = (x - maxc1) * C1_SCALE; tdist = (x - maxc1) * C1_SCALE;
min_dist += tdist*tdist; min_dist += tdist * tdist;
tdist = (x - minc1) * C1_SCALE; tdist = (x - minc1) * C1_SCALE;
max_dist += tdist*tdist; max_dist += tdist * tdist;
} else { } else {
/* within cell range so no contribution to min_dist */ /* within cell range so no contribution to min_dist */
if (x <= centerc1) { if (x <= centerc1) {
tdist = (x - maxc1) * C1_SCALE; tdist = (x - maxc1) * C1_SCALE;
max_dist += tdist*tdist; max_dist += tdist * tdist;
} else { } else {
tdist = (x - minc1) * C1_SCALE; tdist = (x - minc1) * C1_SCALE;
max_dist += tdist*tdist; max_dist += tdist * tdist;
} }
} }
x = GETJSAMPLE(cinfo->colormap[2][i]); x = GETJSAMPLE(cinfo->colormap[2][i]);
if (x < minc2) { if (x < minc2) {
tdist = (x - minc2) * C2_SCALE; tdist = (x - minc2) * C2_SCALE;
min_dist += tdist*tdist; min_dist += tdist * tdist;
tdist = (x - maxc2) * C2_SCALE; tdist = (x - maxc2) * C2_SCALE;
max_dist += tdist*tdist; max_dist += tdist * tdist;
} else if (x > maxc2) { } else if (x > maxc2) {
tdist = (x - maxc2) * C2_SCALE; tdist = (x - maxc2) * C2_SCALE;
min_dist += tdist*tdist; min_dist += tdist * tdist;
tdist = (x - minc2) * C2_SCALE; tdist = (x - minc2) * C2_SCALE;
max_dist += tdist*tdist; max_dist += tdist * tdist;
} else { } else {
/* within cell range so no contribution to min_dist */ /* within cell range so no contribution to min_dist */
if (x <= centerc2) { if (x <= centerc2) {
tdist = (x - maxc2) * C2_SCALE; tdist = (x - maxc2) * C2_SCALE;
max_dist += tdist*tdist; max_dist += tdist * tdist;
} else { } else {
tdist = (x - minc2) * C2_SCALE; tdist = (x - minc2) * C2_SCALE;
max_dist += tdist*tdist; max_dist += tdist * tdist;
} }
} }
@ -745,14 +744,14 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
ncolors = 0; ncolors = 0;
for (i = 0; i < numcolors; i++) { for (i = 0; i < numcolors; i++) {
if (mindist[i] <= minmaxdist) if (mindist[i] <= minmaxdist)
colorlist[ncolors++] = (JSAMPLE) i; colorlist[ncolors++] = (JSAMPLE)i;
} }
return ncolors; return ncolors;
} }
LOCAL(void) LOCAL(void)
find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2, find_best_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[]) int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
/* Find the closest colormap entry for each cell in the update box, /* Find the closest colormap entry for each cell in the update box,
* given the list of candidate colors prepared by find_nearby_colors. * given the list of candidate colors prepared by find_nearby_colors.
@ -775,7 +774,7 @@ find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
/* Initialize best-distance for each cell of the update box */ /* Initialize best-distance for each cell of the update box */
bptr = bestdist; bptr = bestdist;
for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--) for (i = BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS - 1; i >= 0; i--)
*bptr++ = 0x7FFFFFFFL; *bptr++ = 0x7FFFFFFFL;
/* For each color selected by find_nearby_colors, /* For each color selected by find_nearby_colors,
@ -792,11 +791,11 @@ find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
icolor = GETJSAMPLE(colorlist[i]); icolor = GETJSAMPLE(colorlist[i]);
/* Compute (square of) distance from minc0/c1/c2 to this color */ /* Compute (square of) distance from minc0/c1/c2 to this color */
inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE; inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
dist0 = inc0*inc0; dist0 = inc0 * inc0;
inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE; inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
dist0 += inc1*inc1; dist0 += inc1 * inc1;
inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE; inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
dist0 += inc2*inc2; dist0 += inc2 * inc2;
/* Form the initial difference increments */ /* Form the initial difference increments */
inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0; inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1; inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
@ -805,16 +804,16 @@ find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
bptr = bestdist; bptr = bestdist;
cptr = bestcolor; cptr = bestcolor;
xx0 = inc0; xx0 = inc0;
for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) { for (ic0 = BOX_C0_ELEMS - 1; ic0 >= 0; ic0--) {
dist1 = dist0; dist1 = dist0;
xx1 = inc1; xx1 = inc1;
for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) { for (ic1 = BOX_C1_ELEMS - 1; ic1 >= 0; ic1--) {
dist2 = dist1; dist2 = dist1;
xx2 = inc2; xx2 = inc2;
for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) { for (ic2 = BOX_C2_ELEMS - 1; ic2 >= 0; ic2--) {
if (dist2 < *bptr) { if (dist2 < *bptr) {
*bptr = dist2; *bptr = dist2;
*cptr = (JSAMPLE) icolor; *cptr = (JSAMPLE)icolor;
} }
dist2 += xx2; dist2 += xx2;
xx2 += 2 * STEP_C2 * STEP_C2; xx2 += 2 * STEP_C2 * STEP_C2;
@ -832,12 +831,12 @@ find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
LOCAL(void) LOCAL(void)
fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2) fill_inverse_cmap(j_decompress_ptr cinfo, int c0, int c1, int c2)
/* Fill the inverse-colormap entries in the update box that contains */ /* Fill the inverse-colormap entries in the update box that contains */
/* histogram cell c0/c1/c2. (Only that one cell MUST be filled, but */ /* histogram cell c0/c1/c2. (Only that one cell MUST be filled, but */
/* we can fill as many others as we wish.) */ /* we can fill as many others as we wish.) */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
hist3d histogram = cquantize->histogram; hist3d histogram = cquantize->histogram;
int minc0, minc1, minc2; /* lower left corner of update box */ int minc0, minc1, minc2; /* lower left corner of update box */
int ic0, ic1, ic2; int ic0, ic1, ic2;
@ -878,9 +877,9 @@ fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
cptr = bestcolor; cptr = bestcolor;
for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) { for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) { for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
cachep = & histogram[c0+ic0][c1+ic1][c2]; cachep = &histogram[c0 + ic0][c1 + ic1][c2];
for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) { for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
*cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1); *cachep++ = (histcell)(GETJSAMPLE(*cptr++) + 1);
} }
} }
} }
@ -892,11 +891,11 @@ fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
*/ */
METHODDEF(void) METHODDEF(void)
pass2_no_dither (j_decompress_ptr cinfo, pass2_no_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
/* This version performs no dithering */ /* This version performs no dithering */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
hist3d histogram = cquantize->histogram; hist3d histogram = cquantize->histogram;
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
register histptr cachep; register histptr cachep;
@ -913,24 +912,24 @@ pass2_no_dither (j_decompress_ptr cinfo,
c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT; c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT; c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT; c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
cachep = & histogram[c0][c1][c2]; cachep = &histogram[c0][c1][c2];
/* If we have not seen this color before, find nearest colormap entry */ /* If we have not seen this color before, find nearest colormap entry */
/* and update the cache */ /* and update the cache */
if (*cachep == 0) if (*cachep == 0)
fill_inverse_cmap(cinfo, c0,c1,c2); fill_inverse_cmap(cinfo, c0, c1, c2);
/* Now emit the colormap index for this cell */ /* Now emit the colormap index for this cell */
*outptr++ = (JSAMPLE) (*cachep - 1); *outptr++ = (JSAMPLE)(*cachep - 1);
} }
} }
} }
METHODDEF(void) METHODDEF(void)
pass2_fs_dither (j_decompress_ptr cinfo, pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
/* This version performs Floyd-Steinberg dithering */ /* This version performs Floyd-Steinberg dithering */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
hist3d histogram = cquantize->histogram; hist3d histogram = cquantize->histogram;
register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */ register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */ LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
@ -956,11 +955,11 @@ pass2_fs_dither (j_decompress_ptr cinfo,
outptr = output_buf[row]; outptr = output_buf[row];
if (cquantize->on_odd_row) { if (cquantize->on_odd_row) {
/* work right to left in this row */ /* work right to left in this row */
inptr += (width-1) * 3; /* so point to rightmost pixel */ inptr += (width - 1) * 3; /* so point to rightmost pixel */
outptr += width-1; outptr += width - 1;
dir = -1; dir = -1;
dir3 = -3; dir3 = -3;
errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */ errorptr = cquantize->fserrors + (width + 1) * 3; /* => entry after last column */
cquantize->on_odd_row = FALSE; /* flip for next time */ cquantize->on_odd_row = FALSE; /* flip for next time */
} else { } else {
/* work left to right in this row */ /* work left to right in this row */
@ -984,9 +983,9 @@ pass2_fs_dither (j_decompress_ptr cinfo,
* for either sign of the error value. * for either sign of the error value.
* Note: errorptr points to *previous* column's array entry. * Note: errorptr points to *previous* column's array entry.
*/ */
cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4); cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3 + 0] + 8, 4);
cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4); cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3 + 1] + 8, 4);
cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4); cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3 + 2] + 8, 4);
/* Limit the error using transfer function set by init_error_limit. /* Limit the error using transfer function set by init_error_limit.
* See comments with init_error_limit for rationale. * See comments with init_error_limit for rationale.
*/ */
@ -1004,14 +1003,17 @@ pass2_fs_dither (j_decompress_ptr cinfo,
cur1 = GETJSAMPLE(range_limit[cur1]); cur1 = GETJSAMPLE(range_limit[cur1]);
cur2 = GETJSAMPLE(range_limit[cur2]); cur2 = GETJSAMPLE(range_limit[cur2]);
/* Index into the cache with adjusted pixel value */ /* Index into the cache with adjusted pixel value */
cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT]; cachep =
&histogram[cur0 >> C0_SHIFT][cur1 >> C1_SHIFT][cur2 >> C2_SHIFT];
/* If we have not seen this color before, find nearest colormap */ /* If we have not seen this color before, find nearest colormap */
/* entry and update the cache */ /* entry and update the cache */
if (*cachep == 0) if (*cachep == 0)
fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT); fill_inverse_cmap(cinfo, cur0 >> C0_SHIFT, cur1 >> C1_SHIFT,
cur2 >> C2_SHIFT);
/* Now emit the colormap index for this cell */ /* Now emit the colormap index for this cell */
{ register int pixcode = *cachep - 1; {
*outptr = (JSAMPLE) pixcode; register int pixcode = *cachep - 1;
*outptr = (JSAMPLE)pixcode;
/* Compute representation error for this pixel */ /* Compute representation error for this pixel */
cur0 -= GETJSAMPLE(colormap0[pixcode]); cur0 -= GETJSAMPLE(colormap0[pixcode]);
cur1 -= GETJSAMPLE(colormap1[pixcode]); cur1 -= GETJSAMPLE(colormap1[pixcode]);
@ -1021,20 +1023,21 @@ pass2_fs_dither (j_decompress_ptr cinfo,
* Add these into the running sums, and simultaneously shift the * Add these into the running sums, and simultaneously shift the
* next-line error sums left by 1 column. * next-line error sums left by 1 column.
*/ */
{ register LOCFSERROR bnexterr; {
register LOCFSERROR bnexterr;
bnexterr = cur0; /* Process component 0 */ bnexterr = cur0; /* Process component 0 */
errorptr[0] = (FSERROR) (bpreverr0 + cur0 * 3); errorptr[0] = (FSERROR)(bpreverr0 + cur0 * 3);
bpreverr0 = belowerr0 + cur0 * 5; bpreverr0 = belowerr0 + cur0 * 5;
belowerr0 = bnexterr; belowerr0 = bnexterr;
cur0 *= 7; cur0 *= 7;
bnexterr = cur1; /* Process component 1 */ bnexterr = cur1; /* Process component 1 */
errorptr[1] = (FSERROR) (bpreverr1 + cur1 * 3); errorptr[1] = (FSERROR)(bpreverr1 + cur1 * 3);
bpreverr1 = belowerr1 + cur1 * 5; bpreverr1 = belowerr1 + cur1 * 5;
belowerr1 = bnexterr; belowerr1 = bnexterr;
cur1 *= 7; cur1 *= 7;
bnexterr = cur2; /* Process component 2 */ bnexterr = cur2; /* Process component 2 */
errorptr[2] = (FSERROR) (bpreverr2 + cur2 * 3); errorptr[2] = (FSERROR)(bpreverr2 + cur2 * 3);
bpreverr2 = belowerr2 + cur2 * 5; bpreverr2 = belowerr2 + cur2 * 5;
belowerr2 = bnexterr; belowerr2 = bnexterr;
cur2 *= 7; cur2 *= 7;
@ -1051,9 +1054,9 @@ pass2_fs_dither (j_decompress_ptr cinfo,
* final fserrors[] entry. Note we need not unload belowerrN because * final fserrors[] entry. Note we need not unload belowerrN because
* it is for the dummy column before or after the actual array. * it is for the dummy column before or after the actual array.
*/ */
errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */ errorptr[0] = (FSERROR)bpreverr0; /* unload prev errs into array */
errorptr[1] = (FSERROR) bpreverr1; errorptr[1] = (FSERROR)bpreverr1;
errorptr[2] = (FSERROR) bpreverr2; errorptr[2] = (FSERROR)bpreverr2;
} }
} }
@ -1076,26 +1079,26 @@ pass2_fs_dither (j_decompress_ptr cinfo,
*/ */
LOCAL(void) LOCAL(void)
init_error_limit (j_decompress_ptr cinfo) init_error_limit(j_decompress_ptr cinfo)
/* Allocate and fill in the error_limiter table */ /* Allocate and fill in the error_limiter table */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
int *table; int *table;
int in, out; int in, out;
table = (int *) (*cinfo->mem->alloc_small) table = (int *)(*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * sizeof(int)); ((j_common_ptr)cinfo, JPOOL_IMAGE, (MAXJSAMPLE * 2 + 1) * sizeof(int));
table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */ table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
cquantize->error_limiter = table; cquantize->error_limiter = table;
#define STEPSIZE ((MAXJSAMPLE+1)/16) #define STEPSIZE ((MAXJSAMPLE + 1) / 16)
/* Map errors 1:1 up to +- MAXJSAMPLE/16 */ /* Map errors 1:1 up to +- MAXJSAMPLE/16 */
out = 0; out = 0;
for (in = 0; in < STEPSIZE; in++, out++) { for (in = 0; in < STEPSIZE; in++, out++) {
table[in] = out; table[-in] = -out; table[in] = out; table[-in] = -out;
} }
/* Map errors 1:2 up to +- 3*MAXJSAMPLE/16 */ /* Map errors 1:2 up to +- 3*MAXJSAMPLE/16 */
for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) { for (; in < STEPSIZE * 3; in++, out += (in & 1) ? 0 : 1) {
table[in] = out; table[-in] = -out; table[in] = out; table[-in] = -out;
} }
/* Clamp the rest to final out value (which is (MAXJSAMPLE+1)/8) */ /* Clamp the rest to final out value (which is (MAXJSAMPLE+1)/8) */
@ -1111,9 +1114,9 @@ init_error_limit (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
finish_pass1 (j_decompress_ptr cinfo) finish_pass1(j_decompress_ptr cinfo)
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
/* Select the representative colors and fill in cinfo->colormap */ /* Select the representative colors and fill in cinfo->colormap */
cinfo->colormap = cquantize->sv_colormap; cinfo->colormap = cquantize->sv_colormap;
@ -1124,7 +1127,7 @@ finish_pass1 (j_decompress_ptr cinfo)
METHODDEF(void) METHODDEF(void)
finish_pass2 (j_decompress_ptr cinfo) finish_pass2(j_decompress_ptr cinfo)
{ {
/* no work */ /* no work */
} }
@ -1135,9 +1138,9 @@ finish_pass2 (j_decompress_ptr cinfo)
*/ */
METHODDEF(void) METHODDEF(void)
start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan) start_pass_2_quant(j_decompress_ptr cinfo, boolean is_pre_scan)
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
hist3d histogram = cquantize->histogram; hist3d histogram = cquantize->histogram;
int i; int i;
@ -1167,14 +1170,14 @@ start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS); ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
if (cinfo->dither_mode == JDITHER_FS) { if (cinfo->dither_mode == JDITHER_FS) {
size_t arraysize = (size_t) ((cinfo->output_width + 2) * size_t arraysize =
(3 * sizeof(FSERROR))); (size_t)((cinfo->output_width + 2) * (3 * sizeof(FSERROR)));
/* Allocate Floyd-Steinberg workspace if we didn't already. */ /* Allocate Floyd-Steinberg workspace if we didn't already. */
if (cquantize->fserrors == NULL) if (cquantize->fserrors == NULL)
cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large) cquantize->fserrors = (FSERRPTR)(*cinfo->mem->alloc_large)
((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize); ((j_common_ptr)cinfo, JPOOL_IMAGE, arraysize);
/* Initialize the propagated errors to zero. */ /* Initialize the propagated errors to zero. */
jzero_far((void *) cquantize->fserrors, arraysize); jzero_far((void *)cquantize->fserrors, arraysize);
/* Make the error-limit table if we didn't already. */ /* Make the error-limit table if we didn't already. */
if (cquantize->error_limiter == NULL) if (cquantize->error_limiter == NULL)
init_error_limit(cinfo); init_error_limit(cinfo);
@ -1185,8 +1188,8 @@ start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
/* Zero the histogram or inverse color map, if necessary */ /* Zero the histogram or inverse color map, if necessary */
if (cquantize->needs_zeroed) { if (cquantize->needs_zeroed) {
for (i = 0; i < HIST_C0_ELEMS; i++) { for (i = 0; i < HIST_C0_ELEMS; i++) {
jzero_far((void *) histogram[i], jzero_far((void *)histogram[i],
HIST_C1_ELEMS*HIST_C2_ELEMS * sizeof(histcell)); HIST_C1_ELEMS * HIST_C2_ELEMS * sizeof(histcell));
} }
cquantize->needs_zeroed = FALSE; cquantize->needs_zeroed = FALSE;
} }
@ -1198,9 +1201,9 @@ start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
*/ */
METHODDEF(void) METHODDEF(void)
new_color_map_2_quant (j_decompress_ptr cinfo) new_color_map_2_quant(j_decompress_ptr cinfo)
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
/* Reset the inverse color map */ /* Reset the inverse color map */
cquantize->needs_zeroed = TRUE; cquantize->needs_zeroed = TRUE;
@ -1212,15 +1215,15 @@ new_color_map_2_quant (j_decompress_ptr cinfo)
*/ */
GLOBAL(void) GLOBAL(void)
jinit_2pass_quantizer (j_decompress_ptr cinfo) jinit_2pass_quantizer(j_decompress_ptr cinfo)
{ {
my_cquantize_ptr cquantize; my_cquantize_ptr cquantize;
int i; int i;
cquantize = (my_cquantize_ptr) cquantize = (my_cquantize_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_cquantizer)); sizeof(my_cquantizer));
cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize; cinfo->cquantize = (struct jpeg_color_quantizer *)cquantize;
cquantize->pub.start_pass = start_pass_2_quant; cquantize->pub.start_pass = start_pass_2_quant;
cquantize->pub.new_color_map = new_color_map_2_quant; cquantize->pub.new_color_map = new_color_map_2_quant;
cquantize->fserrors = NULL; /* flag optional arrays not allocated */ cquantize->fserrors = NULL; /* flag optional arrays not allocated */
@ -1231,12 +1234,12 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo)
ERREXIT(cinfo, JERR_NOTIMPL); ERREXIT(cinfo, JERR_NOTIMPL);
/* Allocate the histogram/inverse colormap storage */ /* Allocate the histogram/inverse colormap storage */
cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small) cquantize->histogram = (hist3d)(*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * sizeof(hist2d)); ((j_common_ptr)cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * sizeof(hist2d));
for (i = 0; i < HIST_C0_ELEMS; i++) { for (i = 0; i < HIST_C0_ELEMS; i++) {
cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large) cquantize->histogram[i] = (hist2d)(*cinfo->mem->alloc_large)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr)cinfo, JPOOL_IMAGE,
HIST_C1_ELEMS*HIST_C2_ELEMS * sizeof(histcell)); HIST_C1_ELEMS * HIST_C2_ELEMS * sizeof(histcell));
} }
cquantize->needs_zeroed = TRUE; /* histogram is garbage now */ cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
@ -1254,7 +1257,7 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo)
if (desired > MAXNUMCOLORS) if (desired > MAXNUMCOLORS)
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS); ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
cquantize->sv_colormap = (*cinfo->mem->alloc_sarray) cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3); ((j_common_ptr)cinfo, JPOOL_IMAGE, (JDIMENSION)desired, (JDIMENSION)3);
cquantize->desired = desired; cquantize->desired = desired;
} else } else
cquantize->sv_colormap = NULL; cquantize->sv_colormap = NULL;
@ -1271,9 +1274,9 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo)
* dither_mode changes. * dither_mode changes.
*/ */
if (cinfo->dither_mode == JDITHER_FS) { if (cinfo->dither_mode == JDITHER_FS) {
cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large) cquantize->fserrors = (FSERRPTR)(*cinfo->mem->alloc_large)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr)cinfo, JPOOL_IMAGE,
(size_t) ((cinfo->output_width + 2) * (3 * sizeof(FSERROR)))); (size_t)((cinfo->output_width + 2) * (3 * sizeof(FSERROR))));
/* Might as well create the error-limiting table too. */ /* Might as well create the error-limiting table too. */
init_error_limit(cinfo); init_error_limit(cinfo);
} }

View File

@ -3,7 +3,7 @@
* *
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2011, 2014, D. R. Commander. * Copyright (C) 2011, 2014, D. R. Commander.
* Copyright (C) 2015, Matthieu Darbois. * Copyright (C) 2015-2016, 2018, Matthieu Darbois.
* *
* Based on the x86 SIMD extension for IJG JPEG library, * Based on the x86 SIMD extension for IJG JPEG library,
* Copyright (C) 1999-2006, MIYASAKA Masaru. * Copyright (C) 1999-2006, MIYASAKA Masaru.
@ -13,81 +13,105 @@
#include "jchuff.h" /* Declarations shared with jcphuff.c */ #include "jchuff.h" /* Declarations shared with jcphuff.c */
EXTERN(int) jsimd_can_rgb_ycc (void); EXTERN(int) jsimd_can_rgb_ycc(void);
EXTERN(int) jsimd_can_rgb_gray (void); EXTERN(int) jsimd_can_rgb_gray(void);
EXTERN(int) jsimd_can_ycc_rgb (void); EXTERN(int) jsimd_can_ycc_rgb(void);
EXTERN(int) jsimd_can_ycc_rgb565 (void); EXTERN(int) jsimd_can_ycc_rgb565(void);
EXTERN(int) jsimd_c_can_null_convert (void); EXTERN(int) jsimd_c_can_null_convert(void);
EXTERN(void) jsimd_rgb_ycc_convert EXTERN(void) jsimd_rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
(j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows); JDIMENSION output_row, int num_rows);
EXTERN(void) jsimd_rgb_gray_convert EXTERN(void) jsimd_rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
(j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows); JDIMENSION output_row, int num_rows);
EXTERN(void) jsimd_ycc_rgb_convert EXTERN(void) jsimd_ycc_rgb_convert(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows); JSAMPARRAY output_buf, int num_rows);
EXTERN(void) jsimd_ycc_rgb565_convert EXTERN(void) jsimd_ycc_rgb565_convert(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPIMAGE input_buf,
JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows); JSAMPARRAY output_buf, int num_rows);
EXTERN(void) jsimd_c_null_convert EXTERN(void) jsimd_c_null_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
(j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPIMAGE output_buf, JDIMENSION output_row,
JDIMENSION output_row, int num_rows); int num_rows);
EXTERN(int) jsimd_can_h2v2_downsample (void); EXTERN(int) jsimd_can_h2v2_downsample(void);
EXTERN(int) jsimd_can_h2v1_downsample (void); EXTERN(int) jsimd_can_h2v1_downsample(void);
EXTERN(void) jsimd_h2v2_downsample EXTERN(void) jsimd_h2v2_downsample(j_compress_ptr cinfo,
(j_compress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data); JSAMPARRAY input_data,
JSAMPARRAY output_data);
EXTERN(int) jsimd_can_h2v2_smooth_downsample (void); EXTERN(int) jsimd_can_h2v2_smooth_downsample(void);
EXTERN(void) jsimd_h2v2_smooth_downsample EXTERN(void) jsimd_h2v2_smooth_downsample(j_compress_ptr cinfo,
(j_compress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data); JSAMPARRAY input_data,
JSAMPARRAY output_data);
EXTERN(void) jsimd_h2v1_downsample EXTERN(void) jsimd_h2v1_downsample(j_compress_ptr cinfo,
(j_compress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data); JSAMPARRAY input_data,
JSAMPARRAY output_data);
EXTERN(int) jsimd_can_h2v2_upsample (void); EXTERN(int) jsimd_can_h2v2_upsample(void);
EXTERN(int) jsimd_can_h2v1_upsample (void); EXTERN(int) jsimd_can_h2v1_upsample(void);
EXTERN(int) jsimd_can_int_upsample (void); EXTERN(int) jsimd_can_int_upsample(void);
EXTERN(void) jsimd_h2v2_upsample EXTERN(void) jsimd_h2v2_upsample(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr); JSAMPARRAY input_data,
EXTERN(void) jsimd_h2v1_upsample JSAMPARRAY *output_data_ptr);
(j_decompress_ptr cinfo, jpeg_component_info *compptr, EXTERN(void) jsimd_h2v1_upsample(j_decompress_ptr cinfo,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr); jpeg_component_info *compptr,
EXTERN(void) jsimd_int_upsample JSAMPARRAY input_data,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY *output_data_ptr);
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr); EXTERN(void) jsimd_int_upsample(j_decompress_ptr cinfo,
jpeg_component_info *compptr,
JSAMPARRAY input_data,
JSAMPARRAY *output_data_ptr);
EXTERN(int) jsimd_can_h2v2_fancy_upsample (void); EXTERN(int) jsimd_can_h2v2_fancy_upsample(void);
EXTERN(int) jsimd_can_h2v1_fancy_upsample (void); EXTERN(int) jsimd_can_h2v1_fancy_upsample(void);
EXTERN(void) jsimd_h2v2_fancy_upsample EXTERN(void) jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr); JSAMPARRAY input_data,
EXTERN(void) jsimd_h2v1_fancy_upsample JSAMPARRAY *output_data_ptr);
(j_decompress_ptr cinfo, jpeg_component_info *compptr, EXTERN(void) jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr); jpeg_component_info *compptr,
JSAMPARRAY input_data,
JSAMPARRAY *output_data_ptr);
EXTERN(int) jsimd_can_h2v2_merged_upsample (void); EXTERN(int) jsimd_can_h2v2_merged_upsample(void);
EXTERN(int) jsimd_can_h2v1_merged_upsample (void); EXTERN(int) jsimd_can_h2v1_merged_upsample(void);
EXTERN(void) jsimd_h2v2_merged_upsample EXTERN(void) jsimd_h2v2_merged_upsample(j_decompress_ptr cinfo,
(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf); JDIMENSION in_row_group_ctr,
EXTERN(void) jsimd_h2v1_merged_upsample JSAMPARRAY output_buf);
(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, EXTERN(void) jsimd_h2v1_merged_upsample(j_decompress_ptr cinfo,
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf); JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf);
EXTERN(int) jsimd_can_huff_encode_one_block (void); EXTERN(int) jsimd_can_huff_encode_one_block(void);
EXTERN(JOCTET*) jsimd_huff_encode_one_block EXTERN(JOCTET *) jsimd_huff_encode_one_block(void *state, JOCTET *buffer,
(void *state, JOCTET *buffer, JCOEFPTR block, int last_dc_val, JCOEFPTR block, int last_dc_val,
c_derived_tbl *dctbl, c_derived_tbl *actbl); c_derived_tbl *dctbl,
c_derived_tbl *actbl);
EXTERN(int) jsimd_can_encode_mcu_AC_first_prepare(void);
EXTERN(void) jsimd_encode_mcu_AC_first_prepare
(const JCOEF *block, const int *jpeg_natural_order_start, int Sl, int Al,
JCOEF *values, size_t *zerobits);
EXTERN(int) jsimd_can_encode_mcu_AC_refine_prepare(void);
EXTERN(int) jsimd_encode_mcu_AC_refine_prepare
(const JCOEF *block, const int *jpeg_natural_order_start, int Sl, int Al,
JCOEF *absvalues, size_t *bits);

View File

@ -3,7 +3,7 @@
* *
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2009-2011, 2014, D. R. Commander. * Copyright (C) 2009-2011, 2014, D. R. Commander.
* Copyright (C) 2015, Matthieu Darbois. * Copyright (C) 2015-2016, 2018, Matthieu Darbois.
* *
* Based on the x86 SIMD extension for IJG JPEG library, * Based on the x86 SIMD extension for IJG JPEG library,
* Copyright (C) 1999-2006, MIYASAKA Masaru. * Copyright (C) 1999-2006, MIYASAKA Masaru.
@ -20,385 +20,399 @@
#include "jsimddct.h" #include "jsimddct.h"
GLOBAL(int) GLOBAL(int)
jsimd_can_rgb_ycc (void) jsimd_can_rgb_ycc(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_rgb_gray (void) jsimd_can_rgb_gray(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_ycc_rgb (void) jsimd_can_ycc_rgb(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_ycc_rgb565 (void) jsimd_can_ycc_rgb565(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_c_can_null_convert (void) jsimd_c_can_null_convert(void)
{ {
return 0; return 0;
} }
GLOBAL(void) GLOBAL(void)
jsimd_rgb_ycc_convert (j_compress_ptr cinfo, jsimd_rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPIMAGE output_buf, JDIMENSION output_row,
JDIMENSION output_row, int num_rows) int num_rows)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_rgb_gray_convert (j_compress_ptr cinfo, jsimd_rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPIMAGE output_buf, JDIMENSION output_row,
JDIMENSION output_row, int num_rows) int num_rows)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_ycc_rgb_convert (j_decompress_ptr cinfo, jsimd_ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, int num_rows) int num_rows)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_ycc_rgb565_convert (j_decompress_ptr cinfo, jsimd_ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION input_row, JDIMENSION input_row, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, int num_rows) int num_rows)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_c_null_convert (j_compress_ptr cinfo, jsimd_c_null_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPIMAGE output_buf, JDIMENSION output_row,
JDIMENSION output_row, int num_rows) int num_rows)
{ {
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_h2v2_downsample (void) jsimd_can_h2v2_downsample(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_h2v1_downsample (void) jsimd_can_h2v1_downsample(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_h2v2_smooth_downsample (void) jsimd_can_h2v2_smooth_downsample(void)
{ {
return 0; return 0;
} }
GLOBAL(void) GLOBAL(void)
jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr, jsimd_h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_h2v2_smooth_downsample (j_compress_ptr cinfo, jsimd_h2v2_smooth_downsample(j_compress_ptr cinfo,
jpeg_component_info *compptr, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr, jsimd_h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_h2v2_upsample (void) jsimd_can_h2v2_upsample(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_h2v1_upsample (void) jsimd_can_h2v1_upsample(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_int_upsample (void) jsimd_can_int_upsample(void)
{ {
return 0; return 0;
} }
GLOBAL(void) GLOBAL(void)
jsimd_int_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, jsimd_int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_h2v2_upsample (j_decompress_ptr cinfo, jsimd_h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
jpeg_component_info *compptr, JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
JSAMPARRAY input_data,
JSAMPARRAY *output_data_ptr)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_h2v1_upsample (j_decompress_ptr cinfo, jsimd_h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
jpeg_component_info *compptr, JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
JSAMPARRAY input_data,
JSAMPARRAY *output_data_ptr)
{ {
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_h2v2_fancy_upsample (void) jsimd_can_h2v2_fancy_upsample(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_h2v1_fancy_upsample (void) jsimd_can_h2v1_fancy_upsample(void)
{ {
return 0; return 0;
} }
GLOBAL(void) GLOBAL(void)
jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo, jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
jpeg_component_info *compptr, JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
JSAMPARRAY input_data,
JSAMPARRAY *output_data_ptr)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo, jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
jpeg_component_info *compptr, JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
JSAMPARRAY input_data,
JSAMPARRAY *output_data_ptr)
{ {
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_h2v2_merged_upsample (void) jsimd_can_h2v2_merged_upsample(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_h2v1_merged_upsample (void) jsimd_can_h2v1_merged_upsample(void)
{ {
return 0; return 0;
} }
GLOBAL(void) GLOBAL(void)
jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo, jsimd_h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo, jsimd_h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
{ {
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_convsamp (void) jsimd_can_convsamp(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_convsamp_float (void) jsimd_can_convsamp_float(void)
{ {
return 0; return 0;
} }
GLOBAL(void) GLOBAL(void)
jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col, jsimd_convsamp(JSAMPARRAY sample_data, JDIMENSION start_col,
DCTELEM *workspace) DCTELEM *workspace)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col, jsimd_convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
FAST_FLOAT *workspace) FAST_FLOAT *workspace)
{ {
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_fdct_islow (void) jsimd_can_fdct_islow(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_fdct_ifast (void) jsimd_can_fdct_ifast(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_fdct_float (void) jsimd_can_fdct_float(void)
{ {
return 0; return 0;
} }
GLOBAL(void) GLOBAL(void)
jsimd_fdct_islow (DCTELEM *data) jsimd_fdct_islow(DCTELEM *data)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_fdct_ifast (DCTELEM *data) jsimd_fdct_ifast(DCTELEM *data)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_fdct_float (FAST_FLOAT *data) jsimd_fdct_float(FAST_FLOAT *data)
{ {
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_quantize (void) jsimd_can_quantize(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_quantize_float (void) jsimd_can_quantize_float(void)
{ {
return 0; return 0;
} }
GLOBAL(void) GLOBAL(void)
jsimd_quantize (JCOEFPTR coef_block, DCTELEM *divisors, jsimd_quantize(JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
DCTELEM *workspace)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT *divisors, jsimd_quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
FAST_FLOAT *workspace) FAST_FLOAT *workspace)
{ {
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_idct_2x2 (void) jsimd_can_idct_2x2(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_idct_4x4 (void) jsimd_can_idct_4x4(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_idct_6x6 (void) jsimd_can_idct_6x6(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_idct_12x12 (void) jsimd_can_idct_12x12(void)
{ {
return 0; return 0;
} }
GLOBAL(void) GLOBAL(void)
jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info *compptr, jsimd_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col) JDIMENSION output_col)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info *compptr, jsimd_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col) JDIMENSION output_col)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_idct_6x6 (j_decompress_ptr cinfo, jpeg_component_info *compptr, jsimd_idct_6x6(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col) JDIMENSION output_col)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_idct_12x12 (j_decompress_ptr cinfo, jpeg_component_info *compptr, jsimd_idct_12x12(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col) JDIMENSION output_col)
{ {
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_idct_islow (void) jsimd_can_idct_islow(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_idct_ifast (void) jsimd_can_idct_ifast(void)
{ {
return 0; return 0;
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_idct_float (void) jsimd_can_idct_float(void)
{ {
return 0; return 0;
} }
GLOBAL(void) GLOBAL(void)
jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info *compptr, jsimd_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col) JDIMENSION output_col)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info *compptr, jsimd_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col) JDIMENSION output_col)
{ {
} }
GLOBAL(void) GLOBAL(void)
jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info *compptr, jsimd_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col) JDIMENSION output_col)
{ {
} }
GLOBAL(int) GLOBAL(int)
jsimd_can_huff_encode_one_block (void) jsimd_can_huff_encode_one_block(void)
{ {
return 0; return 0;
} }
GLOBAL(JOCTET*) GLOBAL(JOCTET *)
jsimd_huff_encode_one_block (void *state, JOCTET *buffer, JCOEFPTR block, jsimd_huff_encode_one_block(void *state, JOCTET *buffer, JCOEFPTR block,
int last_dc_val, c_derived_tbl *dctbl, int last_dc_val, c_derived_tbl *dctbl,
c_derived_tbl *actbl) c_derived_tbl *actbl)
{ {
return NULL; return NULL;
} }
GLOBAL(int)
jsimd_can_encode_mcu_AC_first_prepare(void)
{
return 0;
}
GLOBAL(void)
jsimd_encode_mcu_AC_first_prepare(const JCOEF *block,
const int *jpeg_natural_order_start, int Sl,
int Al, JCOEF *values, size_t *zerobits)
{
}
GLOBAL(int)
jsimd_can_encode_mcu_AC_refine_prepare(void)
{
return 0;
}
GLOBAL(int)
jsimd_encode_mcu_AC_refine_prepare(const JCOEF *block,
const int *jpeg_natural_order_start, int Sl,
int Al, JCOEF *absvalues, size_t *bits)
{
return 0;
}

View File

@ -9,66 +9,62 @@
* *
*/ */
EXTERN(int) jsimd_can_convsamp (void); EXTERN(int) jsimd_can_convsamp(void);
EXTERN(int) jsimd_can_convsamp_float (void); EXTERN(int) jsimd_can_convsamp_float(void);
EXTERN(void) jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col, EXTERN(void) jsimd_convsamp(JSAMPARRAY sample_data, JDIMENSION start_col,
DCTELEM *workspace); DCTELEM *workspace);
EXTERN(void) jsimd_convsamp_float (JSAMPARRAY sample_data, EXTERN(void) jsimd_convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
JDIMENSION start_col,
FAST_FLOAT *workspace); FAST_FLOAT *workspace);
EXTERN(int) jsimd_can_fdct_islow (void); EXTERN(int) jsimd_can_fdct_islow(void);
EXTERN(int) jsimd_can_fdct_ifast (void); EXTERN(int) jsimd_can_fdct_ifast(void);
EXTERN(int) jsimd_can_fdct_float (void); EXTERN(int) jsimd_can_fdct_float(void);
EXTERN(void) jsimd_fdct_islow (DCTELEM *data); EXTERN(void) jsimd_fdct_islow(DCTELEM *data);
EXTERN(void) jsimd_fdct_ifast (DCTELEM *data); EXTERN(void) jsimd_fdct_ifast(DCTELEM *data);
EXTERN(void) jsimd_fdct_float (FAST_FLOAT *data); EXTERN(void) jsimd_fdct_float(FAST_FLOAT *data);
EXTERN(int) jsimd_can_quantize (void); EXTERN(int) jsimd_can_quantize(void);
EXTERN(int) jsimd_can_quantize_float (void); EXTERN(int) jsimd_can_quantize_float(void);
EXTERN(void) jsimd_quantize (JCOEFPTR coef_block, DCTELEM *divisors, EXTERN(void) jsimd_quantize(JCOEFPTR coef_block, DCTELEM *divisors,
DCTELEM *workspace); DCTELEM *workspace);
EXTERN(void) jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT *divisors, EXTERN(void) jsimd_quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
FAST_FLOAT *workspace); FAST_FLOAT *workspace);
EXTERN(int) jsimd_can_idct_2x2 (void); EXTERN(int) jsimd_can_idct_2x2(void);
EXTERN(int) jsimd_can_idct_4x4 (void); EXTERN(int) jsimd_can_idct_4x4(void);
EXTERN(int) jsimd_can_idct_6x6 (void); EXTERN(int) jsimd_can_idct_6x6(void);
EXTERN(int) jsimd_can_idct_12x12 (void); EXTERN(int) jsimd_can_idct_12x12(void);
EXTERN(void) jsimd_idct_2x2 (j_decompress_ptr cinfo, EXTERN(void) jsimd_idct_2x2(j_decompress_ptr cinfo,
jpeg_component_info *compptr, jpeg_component_info *compptr, JCOEFPTR coef_block,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JSAMPARRAY output_buf, JDIMENSION output_col);
JDIMENSION output_col); EXTERN(void) jsimd_idct_4x4(j_decompress_ptr cinfo,
EXTERN(void) jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info *compptr, JCOEFPTR coef_block,
jpeg_component_info *compptr, JSAMPARRAY output_buf, JDIMENSION output_col);
JCOEFPTR coef_block, JSAMPARRAY output_buf, EXTERN(void) jsimd_idct_6x6(j_decompress_ptr cinfo,
JDIMENSION output_col); jpeg_component_info *compptr, JCOEFPTR coef_block,
EXTERN(void) jsimd_idct_6x6 (j_decompress_ptr cinfo, JSAMPARRAY output_buf, JDIMENSION output_col);
jpeg_component_info *compptr, EXTERN(void) jsimd_idct_12x12(j_decompress_ptr cinfo,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col);
EXTERN(void) jsimd_idct_12x12 (j_decompress_ptr cinfo,
jpeg_component_info *compptr, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col); JDIMENSION output_col);
EXTERN(int) jsimd_can_idct_islow (void); EXTERN(int) jsimd_can_idct_islow(void);
EXTERN(int) jsimd_can_idct_ifast (void); EXTERN(int) jsimd_can_idct_ifast(void);
EXTERN(int) jsimd_can_idct_float (void); EXTERN(int) jsimd_can_idct_float(void);
EXTERN(void) jsimd_idct_islow (j_decompress_ptr cinfo, EXTERN(void) jsimd_idct_islow(j_decompress_ptr cinfo,
jpeg_component_info *compptr, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col); JDIMENSION output_col);
EXTERN(void) jsimd_idct_ifast (j_decompress_ptr cinfo, EXTERN(void) jsimd_idct_ifast(j_decompress_ptr cinfo,
jpeg_component_info *compptr, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col); JDIMENSION output_col);
EXTERN(void) jsimd_idct_float (j_decompress_ptr cinfo, EXTERN(void) jsimd_idct_float(j_decompress_ptr cinfo,
jpeg_component_info *compptr, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col); JDIMENSION output_col);

View File

@ -17,8 +17,8 @@
*/ */
LOCAL(void) LOCAL(void)
add_huff_table (j_common_ptr cinfo, add_huff_table(j_common_ptr cinfo, JHUFF_TBL **htblptr, const UINT8 *bits,
JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val) const UINT8 *val)
/* Define a Huffman table */ /* Define a Huffman table */
{ {
int nsymbols, len; int nsymbols, len;
@ -50,26 +50,31 @@ add_huff_table (j_common_ptr cinfo,
LOCAL(void) LOCAL(void)
std_huff_tables (j_common_ptr cinfo) std_huff_tables(j_common_ptr cinfo)
/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */ /* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
/* IMPORTANT: these are only valid for 8-bit data precision! */ /* IMPORTANT: these are only valid for 8-bit data precision! */
{ {
JHUFF_TBL **dc_huff_tbl_ptrs, **ac_huff_tbl_ptrs; JHUFF_TBL **dc_huff_tbl_ptrs, **ac_huff_tbl_ptrs;
static const UINT8 bits_dc_luminance[17] = static const UINT8 bits_dc_luminance[17] = {
{ /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0
static const UINT8 val_dc_luminance[] = };
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; static const UINT8 val_dc_luminance[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
};
static const UINT8 bits_dc_chrominance[17] = static const UINT8 bits_dc_chrominance[17] = {
{ /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
static const UINT8 val_dc_chrominance[] = };
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; static const UINT8 val_dc_chrominance[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
};
static const UINT8 bits_ac_luminance[17] = static const UINT8 bits_ac_luminance[17] = {
{ /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d }; /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d
static const UINT8 val_ac_luminance[] = };
{ 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, static const UINT8 val_ac_luminance[] = {
0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
@ -89,12 +94,14 @@ std_huff_tables (j_common_ptr cinfo)
0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
0xf9, 0xfa }; 0xf9, 0xfa
};
static const UINT8 bits_ac_chrominance[17] = static const UINT8 bits_ac_chrominance[17] = {
{ /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 }; /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77
static const UINT8 val_ac_chrominance[] = };
{ 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, static const UINT8 val_ac_chrominance[] = {
0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
@ -114,7 +121,8 @@ std_huff_tables (j_common_ptr cinfo)
0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
0xf9, 0xfa }; 0xf9, 0xfa
};
if (cinfo->is_decompressor) { if (cinfo->is_decompressor) {
dc_huff_tbl_ptrs = ((j_decompress_ptr)cinfo)->dc_huff_tbl_ptrs; dc_huff_tbl_ptrs = ((j_decompress_ptr)cinfo)->dc_huff_tbl_ptrs;

View File

@ -53,7 +53,7 @@ const int jpeg_zigzag_order[DCTSIZE2] = {
* fake entries. * fake entries.
*/ */
const int jpeg_natural_order[DCTSIZE2+16] = { const int jpeg_natural_order[DCTSIZE2 + 16] = {
0, 1, 8, 16, 9, 2, 3, 10, 0, 1, 8, 16, 9, 2, 3, 10,
17, 24, 32, 25, 18, 11, 4, 5, 17, 24, 32, 25, 18, 11, 4, 5,
12, 19, 26, 33, 40, 48, 41, 34, 12, 19, 26, 33, 40, 48, 41, 34,
@ -72,7 +72,7 @@ const int jpeg_natural_order[DCTSIZE2+16] = {
*/ */
GLOBAL(long) GLOBAL(long)
jdiv_round_up (long a, long b) jdiv_round_up(long a, long b)
/* Compute a/b rounded up to next integer, ie, ceil(a/b) */ /* Compute a/b rounded up to next integer, ie, ceil(a/b) */
/* Assumes a >= 0, b > 0 */ /* Assumes a >= 0, b > 0 */
{ {
@ -81,7 +81,7 @@ jdiv_round_up (long a, long b)
GLOBAL(long) GLOBAL(long)
jround_up (long a, long b) jround_up(long a, long b)
/* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */ /* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */
/* Assumes a >= 0, b > 0 */ /* Assumes a >= 0, b > 0 */
{ {
@ -91,9 +91,9 @@ jround_up (long a, long b)
GLOBAL(void) GLOBAL(void)
jcopy_sample_rows (JSAMPARRAY input_array, int source_row, jcopy_sample_rows(JSAMPARRAY input_array, int source_row,
JSAMPARRAY output_array, int dest_row, JSAMPARRAY output_array, int dest_row, int num_rows,
int num_rows, JDIMENSION num_cols) JDIMENSION num_cols)
/* Copy some rows of samples from one place to another. /* Copy some rows of samples from one place to another.
* num_rows rows are copied from input_array[source_row++] * num_rows rows are copied from input_array[source_row++]
* to output_array[dest_row++]; these areas may overlap for duplication. * to output_array[dest_row++]; these areas may overlap for duplication.
@ -101,7 +101,7 @@ jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
*/ */
{ {
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
register size_t count = (size_t) (num_cols * sizeof(JSAMPLE)); register size_t count = (size_t)(num_cols * sizeof(JSAMPLE));
register int row; register int row;
input_array += source_row; input_array += source_row;
@ -116,7 +116,7 @@ jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
GLOBAL(void) GLOBAL(void)
jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, jcopy_block_row(JBLOCKROW input_row, JBLOCKROW output_row,
JDIMENSION num_blocks) JDIMENSION num_blocks)
/* Copy a row of coefficient blocks from one place to another. */ /* Copy a row of coefficient blocks from one place to another. */
{ {
@ -125,7 +125,7 @@ jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
GLOBAL(void) GLOBAL(void)
jzero_far (void *target, size_t bytestozero) jzero_far(void *target, size_t bytestozero)
/* Zero out a chunk of memory. */ /* Zero out a chunk of memory. */
/* This might be sample-array data, block-array data, or alloc_large data. */ /* This might be sample-array data, block-array data, or alloc_large data. */
{ {

View File

@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding. * Copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2010, 2012-2017, D. R. Commander. * Copyright (C) 2010, 2012-2019, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@ -35,15 +35,18 @@
* their code * their code
*/ */
#define JCOPYRIGHT "Copyright (C) 2009-2017 D. R. Commander\n" \ #define JCOPYRIGHT \
"Copyright (C) 2009-2019 D. R. Commander\n" \
"Copyright (C) 2011-2016 Siarhei Siamashka\n" \ "Copyright (C) 2011-2016 Siarhei Siamashka\n" \
"Copyright (C) 2015-2016 Matthieu Darbois\n" \ "Copyright (C) 2015-2016, 2018 Matthieu Darbois\n" \
"Copyright (C) 2015 Intel Corporation\n" \
"Copyright (C) 2015 Google, Inc.\n" \ "Copyright (C) 2015 Google, Inc.\n" \
"Copyright (C) 2013-2014 MIPS Technologies, Inc.\n" \ "Copyright (C) 2013-2014 MIPS Technologies, Inc.\n" \
"Copyright (C) 2013 Linaro Limited\n" \ "Copyright (C) 2013 Linaro Limited\n" \
"Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)\n" \ "Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)\n" \
"Copyright (C) 2009 Pierre Ossman for Cendio AB\n" \ "Copyright (C) 2009 Pierre Ossman for Cendio AB\n" \
"Copyright (C) 1999-2006 MIYASAKA Masaru\n" \ "Copyright (C) 1999-2006 MIYASAKA Masaru\n" \
"Copyright (C) 1991-2016 Thomas G. Lane, Guido Vollbeding" \ "Copyright (C) 1991-2016 Thomas G. Lane, Guido Vollbeding"
#define JCOPYRIGHT_SHORT "Copyright (C) 1991-2017 The libjpeg-turbo Project and many others" #define JCOPYRIGHT_SHORT \
"Copyright (C) 1991-2019 The libjpeg-turbo Project and many others"