Merge libjpeg-turbo r1325

* commit 'b8d044a666056d4d8d28d7a5d0805ac32b619b36': (58 commits)
  Big oops.  wrjpgcom on Windows was being built using the rdjpgcom source.
  Prevent a buffer overrun if the comment begins with a literal quote character and the string exceeds 65k characters.  Also prevent comments longer than 65k characters from being written, since this will produce an incorrect JPEG file.
  Remove VMS-specific code
  Our copyright string is longer than JMSG_LENGTH_MAX, and this was causing a buffer overrun if output_message() was called with msg_code set to JMSG_COPYRIGHT, or if format_message() was called with msg_code set to JMSG_COPYRIGHT and with a buffer of length JMSG_LENGTH_MAX.
  We don't support non-ANSI C compilers
  Allow for building the MIPS DSPr2 extensions if the host is mips-* as well as mipsel-*.  The DSPr2 extensions are little endian, so we still have to check that the compiler defines __MIPSEL__ before enabling them.  This paves the way for supporting big-endian MIPS, and in the near term, it allows the SIMD extensions to be built with Sourcery CodeBench.
  SIMD-accelerated int upsample routine for MIPS DSPr2
  Fix MIPS build
  libjpeg-turbo has never supported non-ANSI compilers, so get rid of the crufty SIZEOF() macro.  It was not being used consistently anyhow, so it would not have been possible to build prior releases of libjpeg-turbo using the broken compilers for which that macro was designed.
  Remove MS-DOS code and information, and adjust copyright headers to reflect the removal of features in r1307 and r1308.  libjpeg-turbo has never supported MS-DOS, nor is it even possible for us to do so.
  Further copyright header cleanup
  Further copyright header cleanup
  Get rid of the HAVE_PROTOTYPES configuration option, as well as the related JMETHOD and JPP macros.  libjpeg-turbo has never supported compilers that don't handle prototypes.  Doing so requires ansi2knr, which isn't even supported in the IJG code anymore.
  Remove all of the NEED_SHORT_EXTERNAL_NAMES stuff.  There is scant information available as to which linkers ever had a 15-character global symbol name limit.  AFAICT, it might have been a VMS and/or a.out BSD thing, but none of those platforms have ever been supported by libjpeg-turbo (nor are such systems supported by other open source libraries of this nature.)
  Clean up code formatting in the SIMD interface functions
  SIMD-accelerated NULL convert routine for MIPS DSPr2
  Fix build, which was broken by the checkin of the MIPS DSPr2 accelerated smooth downsampling routine.  Until/unless other platforms include SIMD support for that function, it's just easier to #ifdef around it rather than adding stubs for the other platforms.
  Fix error in MIPS DSPr2 accelerated smooth downsample routine
  SIMD-accelerated h2v2 smooth downsampling routine for MIPS DSPr2
  Minor tweak to improve code readability
  ...

Conflicts:
	BUILDING.txt
	CMakeLists.txt
	Makefile.am
	cdjpeg.h
	cjpeg.1
	cjpeg.c
	configure.ac
	djpeg.1
	example.c
	jccoefct.c
	jcdctmgr.c
	jchuff.c
	jchuff.h
	jcinit.c
	jcmaster.c
	jcparam.c
	jcphuff.c
	jidctflt.c
	jpegint.h
	jpeglib.h
	jversion.h
	libjpeg.txt
	rdswitch.c
	simd/CMakeLists.txt
	tjbench.c
	turbojpeg.c
	usage.txt
	wrjpgcom.c
This commit is contained in:
Kornel Lesiński
2014-09-07 16:59:11 +01:00
237 changed files with 33381 additions and 31501 deletions

View File

@@ -319,17 +319,15 @@ This release of libmozjpeg can use ARM NEON SIMD instructions to accelerate
JPEG compression/decompression by approximately 2-4x on ARMv7 and later JPEG compression/decompression by approximately 2-4x on ARMv7 and later
platforms. If libmozjpeg is configured on an ARM Linux platform, then the platforms. If libmozjpeg is configured on an ARM Linux platform, then the
build system will automatically include the NEON SIMD routines, if they are build system will automatically include the NEON SIMD routines, if they are
supported. supported. Build instructions for other ARM-based platforms follow.
Building libmozjpeg for iOS Building libmozjpeg for iOS
------------------------------ ------------------------------
iOS platforms, such as the iPhone and iPad, also use ARM processors, some of iOS platforms, such as the iPhone and iPad, use ARM processors, some of which
which support NEON instructions. Additional steps are required to build support NEON instructions. Additional steps are required in order to build
libmozjpeg for these platforms. The steps below assume iOS SDK v4.3. If libmozjpeg for these platforms.
you are using a different SDK version, then you will need to modify the
examples accordingly.
Additional build requirements: Additional build requirements:
@@ -395,6 +393,45 @@ described above. Otherwise, you may get a libtool error such as "unable to
infer tagged configuration." infer tagged configuration."
Building libjpeg-turbo for Android
----------------------------------
Building libjpeg-turbo for Android platforms requires the Android NDK
(https://developer.android.com/tools/sdk/ndk) and autotools. The following is
a general recipe script that can be modified for your specific needs.
# Set these variables to suit your needs
NDK_PATH={full path to the "ndk" directory-- for example, /opt/android/ndk}
BUILD_PLATFORM={the platform name for the NDK package you installed--
for example, "windows-x86" or "linux-x86_64"}
TOOLCHAIN_VERSION={"4.6", "4.8", etc. This corresponds to a toolchain
directory under ${NDK_PATH}/toolchains/.}
ANDROID_VERSION={The minimum version of Android to support-- for example,
"9", "19", etc.}
HOST=arm-linux-androideabi
TOOLCHAIN=${NDK_PATH}/toolchains/${HOST}-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}
SYSROOT=${NDK_PATH}/platforms/android-${ANDROID_VERSION}/arch-arm
ANDROID_INCLUDES="-I${SYSROOT}/usr/include -I${TOOLCHAIN}/include"
ANDROID_CFLAGS="-march=armv7-a -mfloat-abi=softfp -fprefetch-loop-arrays \
-fstrict-aliasing --sysroot=${SYSROOT}"
export CPP=${TOOLCHAIN}/bin/${HOST}-cpp
export AR=${TOOLCHAIN}/bin/${HOST}-ar
export AS=${TOOLCHAIN}/bin/${HOST}-as
export NM=${TOOLCHAIN}/bin/${HOST}-nm
export CC=${TOOLCHAIN}/bin/${HOST}-gcc
export LD=${TOOLCHAIN}/bin/${HOST}-ld
export RANLIB=${TOOLCHAIN}/bin/${HOST}-ranlib
export OBJDUMP=${TOOLCHAIN}/bin/${HOST}-objdump
export STRIP=${TOOLCHAIN}/bin/${HOST}-strip
cd {build_directory}
sh {source_directory}/configure --host=${HOST} \
CFLAGS="${ANDROID_INCLUDES} ${ANDROID_CFLAGS} -O3" \
CPPFLAGS="${ANDROID_INCLUDES} ${ANDROID_CFLAGS}" \
LDFLAGS="${ANDROID_CFLAGS}" --with-simd ${1+"$@"}
make
******************************************************************************* *******************************************************************************
** Building on Windows (Visual C++ or MinGW) ** Building on Windows (Visual C++ or MinGW)
******************************************************************************* *******************************************************************************
@@ -404,7 +441,7 @@ infer tagged configuration."
Build Requirements Build Requirements
================== ==================
-- CMake (http://www.cmake.org) v2.6 or later -- CMake (http://www.cmake.org) v2.8.8 or later
-- Microsoft Visual C++ 2005 or later -- Microsoft Visual C++ 2005 or later
@@ -416,8 +453,9 @@ Build Requirements
The Windows SDK includes both 32-bit and 64-bit Visual C++ compilers and The Windows SDK includes both 32-bit and 64-bit Visual C++ compilers and
everything necessary to build libmozjpeg. everything necessary to build libmozjpeg.
* For 32-bit builds, you can also use Microsoft Visual C++ Express * You can also use Microsoft Visual Studio Express Edition, which is a free
Edition. Visual C++ Express Edition is a free download. download. (NOTE: versions prior to 2012 can only be used to build 32-bit
code.)
* If you intend to build libmozjpeg from the command line, then add the * If you intend to build libmozjpeg from the command line, then add the
appropriate compiler and SDK directories to the INCLUDE, LIB, and PATH appropriate compiler and SDK directories to the INCLUDE, LIB, and PATH
environment variables. This is generally accomplished by executing environment variables. This is generally accomplished by executing
@@ -431,7 +469,11 @@ Build Requirements
-- MinGW -- MinGW
GCC v4.1 or later recommended for best performance MinGW-builds (http://sourceforge.net/projects/mingwbuilds/) or
tdm-gcc (http://tdm-gcc.tdragon.net/) recommended if building on a Windows
machine. Both distributions install a Start Menu link that can be used to
launch a command prompt with the appropriate compiler paths automatically
set.
-- NASM (http://www.nasm.us/) 0.98 or later (NASM 2.05 or later is required for -- NASM (http://www.nasm.us/) 0.98 or later (NASM 2.05 or later is required for
a 64-bit build) a 64-bit build)
@@ -496,7 +538,12 @@ Choose the appropriate CMake generator option for your version of Visual Studio
instance: instance:
cd {build_directory} cd {build_directory}
cmake -G "Visual Studio 9 2008" {source_directory} cmake -G "Visual Studio 10" {source_directory}
NOTE: Add "Win64" to the generator name (for example, "Visual Studio 10
Win64") to build a 64-bit version of libjpeg-turbo. Recent versions of CMake
no longer document that. A separate build directory must be used for 32-bit
and 64-bit builds.
You can then open ALL_BUILD.vcproj in Visual Studio and build one of the You can then open ALL_BUILD.vcproj in Visual Studio and build one of the
configurations in that project ("Debug", "Release", etc.) to generate a full configurations in that project ("Debug", "Release", etc.) to generate a full
@@ -525,9 +572,12 @@ depending on whether libjpeg v6b (default), v7, or v8 emulation is enabled.
MinGW MinGW
----- -----
NOTE: This assumes that you are building on a Windows machine. If you are
cross-compiling on a Linux/Unix machine, then see "Build Recipes" below.
cd {build_directory} cd {build_directory}
cmake -G "MSYS Makefiles" {source_directory} cmake -G "MinGW Makefiles" {source_directory}
make mingw32-make
This will generate the following files under {build_directory} This will generate the following files under {build_directory}
@@ -636,8 +686,8 @@ Build Recipes
cd {build_directory} cd {build_directory}
CC=/usr/bin/x86_64-w64-mingw32-gcc \ CC=/usr/bin/x86_64-w64-mingw32-gcc \
cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \ cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_AR=/usr/bin/x86_64-w64-mingw32-ar \ -DCMAKE_RC_COMPILER=/usr/bin/x86_64-w64-mingw32-windres.exe \
-DCMAKE_RANLIB=/usr/bin/x86_64-w64-mingw32-ranlib {source_directory} {source_directory}
make make
This produces a 64-bit build of libmozjpeg that does not depend on This produces a 64-bit build of libmozjpeg that does not depend on
@@ -651,8 +701,8 @@ mingw64-x86_64-gcc-g++ packages (and their dependencies) must be installed.
cd {build_directory} cd {build_directory}
CC=/usr/bin/i686-w64-mingw32-gcc \ CC=/usr/bin/i686-w64-mingw32-gcc \
cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \ cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \
-DDCMAKE_AR=/usr/bin/i686-w64-mingw32-ar \ -DCMAKE_RC_COMPILER=/usr/bin/i686-w64-mingw32-windres.exe \
-DCMAKE_RANLIB=/usr/bin/i686-w64-mingw32-ranlib {source_directory} {source_directory}
make make
This produces a 32-bit build of libmozjpeg that does not depend on This produces a 32-bit build of libmozjpeg that does not depend on
@@ -660,21 +710,6 @@ cygwin1.dll or other Cygwin DLL's. The mingw64-i686-gcc-core and
mingw64-i686-gcc-g++ packages (and their dependencies) must be installed. mingw64-i686-gcc-g++ packages (and their dependencies) must be installed.
MinGW-w64 Build on Windows
--------------------------
This produces a 64-bit build of libmozjpeg using the "native" MinGW-w64
toolchain (which is faster than the Cygwin version):
cd {build_directory}
CC={mingw-w64_binary_path}/x86_64-w64-mingw32-gcc \
cmake -G "MSYS Makefiles" \
-DCMAKE_AR={mingw-w64_binary_path}/x86_64-w64-mingw32-ar \
-DCMAKE_RANLIB={mingw-w64_binary_path}/x86_64-w64-mingw32-ranlib \
{source_directory}
make
MinGW Build on Linux MinGW Build on Linux
-------------------- --------------------

View File

@@ -3,12 +3,15 @@
# #
cmake_minimum_required(VERSION 2.8.8) cmake_minimum_required(VERSION 2.8.8)
cmake_policy(SET CMP0022 OLD) # Use LINK_INTERFACE_LIBRARIES instead of INTERFACE_LINK_LIBRARIES
if(POLICY CMP0022)
cmake_policy(SET CMP0022 OLD)
endif()
project(libmozjpeg C) project(libmozjpeg C)
set(VERSION 2.0.1) set(VERSION 2.0.1)
if(MINGW OR CYGWIN) if(CYGWIN OR NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD) execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD)
string(REGEX REPLACE "\n" "" BUILD "${BUILD}") string(REGEX REPLACE "\n" "" BUILD "${BUILD}")
elseif(WIN32) elseif(WIN32)
@@ -140,7 +143,7 @@ endif()
message(STATUS "Install directory = ${CMAKE_INSTALL_PREFIX}") message(STATUS "Install directory = ${CMAKE_INSTALL_PREFIX}")
configure_file(win/jconfig.h.in jconfig.h) configure_file(win/jconfig.h.in jconfig.h)
configure_file(win/config.h.in config.h) configure_file(win/jconfigint.h.in jconfigint.h)
include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_SOURCE_DIR}") include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_SOURCE_DIR}")
@@ -280,167 +283,397 @@ endif()
enable_testing() enable_testing()
set(MD5_JPEG_INT 9a68f56bc76e466aa7e52f415d0f4a5f) set(MD5_JPEG_RGB_ISLOW 768e970dd57b340ff1b83c9d3d47c77b)
set(MD5_JPEG_FAST 0e1502e7fa421835e376a314fac2a39f) set(MD5_PPM_RGB_ISLOW 00a257f5393fef8821f2b88ac7421291)
set(MD5_JPEG_FAST_100 7bf72a8e741d64eecb960c97323af77c) set(MD5_BMP_RGB_ISLOW_565 f07d2e75073e4bb10f6c6f4d36e2e3be)
set(MD5_JPEG_FLOAT d1623885ffafcd40c684af09e3d65cd5) set(MD5_BMP_RGB_ISLOW_565D 4cfa0928ef3e6bb626d7728c924cfda4)
set(MD5_JPEG_FLOAT_NOSIMD fb4884c35f8273f498cb32879de5c455) set(MD5_JPEG_422_IFAST_OPT 2540287b79d913f91665e660303ab2c8)
set(MD5_JPEG_INT_GRAY 72b51f894b8f4a10b3ee3066770aa38d) set(MD5_PPM_422_IFAST 35bd6b3f833bad23de82acea847129fa)
set(MD5_PPM_INT d1ed0d11f076b842525271647716aeb8) set(MD5_PPM_422M_IFAST 8dbc65323d62cca7c91ba02dd1cfa81d)
set(MD5_PPM_FAST 048298a2d2410261c0533cb97bcfef23) set(MD5_BMP_422M_IFAST_565 3294bd4d9a1f2b3d08ea6020d0db7065)
set(MD5_PPM_FLOAT 7f5b446ee36b2630e06785b8d42af15f) set(MD5_BMP_422M_IFAST_565D da98c9c7b6039511be4a79a878a9abc1)
set(MD5_PPM_FLOAT_NOSIMD 64072f1dbdc5b3a187777788604971a5) set(MD5_JPEG_420_IFAST_Q100_PROG 990cbe0329c882420a2094da7e5adade)
set(MD5_PPM_INT_2_1 9f9de8c0612f8d06869b960b05abf9c9) set(MD5_PPM_420_Q100_IFAST 5a732542015c278ff43635e473a8a294)
set(MD5_PPM_INT_15_8 b6875bc070720b899566cc06459b63b7) set(MD5_PPM_420M_Q100_IFAST ff692ee9323a3b424894862557c092f1)
set(MD5_PPM_INT_7_4 06a177eae05f164fac57f7a2c346ee87) set(MD5_JPEG_GRAY_ISLOW 72b51f894b8f4a10b3ee3066770aa38d)
set(MD5_PPM_INT_13_8 bc3452573c8152f6ae552939ee19f82f) set(MD5_PPM_GRAY_ISLOW 8d3596c56eace32f205deccc229aa5ed)
set(MD5_PPM_INT_3_2 f5a8b88a8a7f96016f04d259cf82ed67) set(MD5_PPM_GRAY_ISLOW_RGB 116424ac07b79e5e801f00508eab48ec)
set(MD5_PPM_INT_11_8 d8cc73c0aaacd4556569b59437ba00a5) set(MD5_BMP_GRAY_ISLOW_565 12f78118e56a2f48b966f792fedf23cc)
set(MD5_PPM_INT_5_4 32775dd9ad2ab90f4c5b219b53e0c86c) set(MD5_BMP_GRAY_ISLOW_565D bdbbd616441a24354c98553df5dc82db)
set(MD5_PPM_INT_9_8 d25e61bc7eac0002f5b393aa223747b6) set(MD5_JPEG_420S_IFAST_OPT 388708217ac46273ca33086b22827ed8)
set(MD5_PPM_INT_7_8 ddb564b7c74a09494016d6cd7502a946) if(WITH_SIMD)
set(MD5_PPM_INT_3_4 8ed8e68808c3fbc4ea764fc9d2968646) set(MD5_JPEG_3x2_FLOAT_PROG 343e3f8caf8af5986ebaf0bdc13b5c71)
set(MD5_PPM_INT_5_8 a3363274999da2366a024efae6d16c9b) set(MD5_PPM_3x2_FLOAT 1a75f36e5904d6fc3a85a43da9ad89bb)
set(MD5_PPM_INT_1_2 e692a315cea26b988c8e8b29a5dbcd81) else()
set(MD5_PPM_INT_3_8 79eca9175652ced755155c90e785a996) set(MD5_JPEG_3x2_FLOAT_PROG 9bca803d2042bd1eb03819e2bf92b3e5)
set(MD5_PPM_INT_1_4 79cd778f8bf1a117690052cacdd54eca) set(MD5_PPM_3x2_FLOAT f6bfab038438ed8f5522fbd33595dcdc)
set(MD5_PPM_INT_1_8 391b3d4aca640c8567d6f8745eb2142f) endif()
set(MD5_PPM_FAST_1_2 f30bcf6d32ccd44cbdd9aeaacbd9454f) set(MD5_JPEG_420_ISLOW_ARI e986fb0a637a8d833d96e8a6d6d84ea1)
set(MD5_BMP_256 4980185e3776e89bd931736e1cddeee6) set(MD5_JPEG_444_ISLOW_PROGARI 0a8f1c8f66e113c3cf635df0a475a617)
set(MD5_JPEG_ARI e986fb0a637a8d833d96e8a6d6d84ea1) set(MD5_PPM_420M_IFAST_ARI 72b59a99bcf1de24c5b27d151bde2437)
set(MD5_PPM_ARI 72b59a99bcf1de24c5b27d151bde2437) set(MD5_JPEG_420_ISLOW 9a68f56bc76e466aa7e52f415d0f4a5f)
set(MD5_JPEG_PROG 1c4afddc05c0a43489ee54438a482d92) set(MD5_PPM_420M_ISLOW_2_1 9f9de8c0612f8d06869b960b05abf9c9)
set(MD5_JPEG_PROG_ARI 0a8f1c8f66e113c3cf635df0a475a617) set(MD5_PPM_420M_ISLOW_15_8 b6875bc070720b899566cc06459b63b7)
set(MD5_PPM_420M_ISLOW_13_8 bc3452573c8152f6ae552939ee19f82f)
set(MD5_PPM_420M_ISLOW_11_8 d8cc73c0aaacd4556569b59437ba00a5)
set(MD5_PPM_420M_ISLOW_9_8 d25e61bc7eac0002f5b393aa223747b6)
set(MD5_PPM_420M_ISLOW_7_8 ddb564b7c74a09494016d6cd7502a946)
set(MD5_PPM_420M_ISLOW_3_4 8ed8e68808c3fbc4ea764fc9d2968646)
set(MD5_PPM_420M_ISLOW_5_8 a3363274999da2366a024efae6d16c9b)
set(MD5_PPM_420M_ISLOW_1_2 e692a315cea26b988c8e8b29a5dbcd81)
set(MD5_PPM_420M_ISLOW_3_8 79eca9175652ced755155c90e785a996)
set(MD5_PPM_420M_ISLOW_1_4 79cd778f8bf1a117690052cacdd54eca)
set(MD5_PPM_420M_ISLOW_1_8 391b3d4aca640c8567d6f8745eb2142f)
set(MD5_BMP_420_ISLOW_256 4980185e3776e89bd931736e1cddeee6)
set(MD5_BMP_420_ISLOW_565 bf9d13e16c4923b92e1faa604d7922cb)
set(MD5_BMP_420_ISLOW_565D 6bde71526acc44bcff76f696df8638d2)
set(MD5_BMP_420M_ISLOW_565 8dc0185245353cfa32ad97027342216f)
set(MD5_BMP_420M_ISLOW_565D d1be3a3339166255e76fa50a0d70d73e)
set(MD5_JPEG_CROP b4197f377e621c4e9b1d20471432610d) set(MD5_JPEG_CROP b4197f377e621c4e9b1d20471432610d)
if(WITH_JAVA) if(WITH_JAVA)
add_test(TJUnitTest ${JAVA_RUNTIME} -cp "java/${OBJDIR}turbojpeg.jar" "-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}" TJUnitTest) add_test(TJUnitTest
add_test(TJUnitTest-yuv ${JAVA_RUNTIME} -cp "java/${OBJDIR}turbojpeg.jar" "-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}" TJUnitTest -yuv) ${JAVA_RUNTIME} -cp java/${OBJDIR}turbojpeg.jar
add_test(TJUnitTest-yuv-nopad ${JAVA_RUNTIME} -cp "java/${OBJDIR}turbojpeg.jar" "-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}" TJUnitTest -yuv -noyuvpad) -Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
add_test(TJUnitTest-bi ${JAVA_RUNTIME} -cp "java/${OBJDIR}turbojpeg.jar" "-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}" TJUnitTest -bi) TJUnitTest)
add_test(TJUnitTest-bi-yuv ${JAVA_RUNTIME} -cp "java/${OBJDIR}turbojpeg.jar" "-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}" TJUnitTest -bi -yuv) add_test(TJUnitTest-yuv
add_test(TJUnitTest-bi-yuv-nopad ${JAVA_RUNTIME} -cp "java/${OBJDIR}turbojpeg.jar" "-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}" TJUnitTest -bi -yuv -noyuvpad) ${JAVA_RUNTIME} -cp java/${OBJDIR}turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -yuv)
add_test(TJUnitTest-yuv-nopad
${JAVA_RUNTIME} -cp java/${OBJDIR}turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -yuv -noyuvpad)
add_test(TJUnitTest-bi
${JAVA_RUNTIME} -cp java/${OBJDIR}turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -bi)
add_test(TJUnitTest-bi-yuv
${JAVA_RUNTIME} -cp java/${OBJDIR}turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -bi -yuv)
add_test(TJUnitTest-bi-yuv-nopad
${JAVA_RUNTIME} -cp java/${OBJDIR}turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -bi -yuv -noyuvpad)
endif() endif()
add_test(tjunittest tjunittest)
add_test(tjunittest-alloc tjunittest -alloc)
add_test(tjunittest-yuv tjunittest -yuv)
add_test(tjunittest-yuv-alloc tjunittest -yuv -alloc)
add_test(tjunittest-yuv-nopad tjunittest -yuv -noyuvpad)
add_test(cjpeg-int sharedlib/cjpeg -dct int -outfile testoutint.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm")
add_test(cjpeg-int-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_INT} -DFILE=testoutint.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(cjpeg-fast sharedlib/cjpeg -dct fast -opt -outfile testoutfst.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm")
add_test(cjpeg-fast-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_FAST} -DFILE=testoutfst.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(cjpeg-fast-100 sharedlib/cjpeg -dct fast -quality 100 -opt -outfile testoutfst100.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm")
add_test(cjpeg-fast-100-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_FAST_100} -DFILE=testoutfst100.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(cjpeg-float sharedlib/cjpeg -dct float -outfile testoutflt.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm")
if(WITH_SIMD)
add_test(cjpeg-float-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_FLOAT} -DFILE=testoutflt.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
else()
add_test(cjpeg-float-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_FLOAT_NOSIMD} -DFILE=testoutflt.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
endif()
add_test(cjpeg-int-gray sharedlib/cjpeg -dct int -grayscale -outfile testoutgray.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm")
add_test(cjpeg-int-gray-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_INT_GRAY} -DFILE=testoutgray.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(djpeg-int sharedlib/djpeg -dct int -fast -ppm -outfile testoutint.ppm "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg")
add_test(djpeg-int-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_INT} -DFILE=testoutint.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(djpeg-fast sharedlib/djpeg -dct fast -ppm -outfile testoutfst.ppm "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg")
add_test(djpeg-fast-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_FAST} -DFILE=testoutfst.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(djpeg-float sharedlib/djpeg -dct float -ppm -outfile testoutflt.ppm "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg")
if(WITH_SIMD)
add_test(djpeg-float-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_FLOAT} -DFILE=testoutflt.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
else()
add_test(djpeg-float-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_FLOAT_NOSIMD} -DFILE=testoutflt.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
endif()
foreach(scale 2_1 15_8 7_4 13_8 3_2 11_8 5_4 9_8 7_8 3_4 5_8 1_2 3_8 1_4 1_8)
string(REGEX REPLACE "_" "/" scalearg ${scale})
add_test(djpeg-int-${scale} sharedlib/djpeg -dct int -nosmooth -scale ${scalearg} -ppm -outfile testoutint${scale}.ppm "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg")
add_test(djpeg-int-${scale}-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_INT_${scale}} -DFILE=testoutint${scale}.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
endforeach()
add_test(djpeg-fast-1_2 sharedlib/djpeg -dct fast -scale 1/2 -ppm -outfile testoutfst1_2.ppm "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg")
add_test(djpeg-fast-1_2-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_FAST_1_2} -DFILE=testoutfst1_2.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(djpeg-256 sharedlib/djpeg -dct int -bmp -colors 256 -outfile testout.bmp "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg")
add_test(djpeg-256-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_BMP_256} -DFILE=testout.bmp -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(cjpeg-prog sharedlib/cjpeg -dct int -progressive -outfile testoutp.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm")
add_test(cjpeg-prog-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_PROG} -DFILE=testoutp.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(jpegtran-prog sharedlib/jpegtran -outfile testoutt.jpg testoutp.jpg")
add_test(jpegtran-prog-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_INT} -DFILE=testoutt.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
if(WITH_ARITH_ENC)
add_test(cjpeg-ari sharedlib/cjpeg -dct int -arithmetic -outfile testoutari.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm")
add_test(cjpeg-ari-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_ARI} -DFILE=testoutari.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(jpegtran-toari sharedlib/jpegtran -arithmetic -outfile testouta.jpg "${CMAKE_SOURCE_DIR}/testimages/testimgint.jpg")
add_test(jpegtran-toari-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_ARI} -DFILE=testouta.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(cjpeg-prog-ari sharedlib/cjpeg -dct int -progressive -arithmetic -sample 1x1 -outfile testoutpa.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm")
add_test(cjpeg-prog-ari-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_PROG_ARI} -DFILE=testoutpa.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
endif()
if(WITH_ARITH_DEC)
add_test(djpeg-ari sharedlib/djpeg -dct int -fast -ppm -outfile testoutari.ppm "${CMAKE_SOURCE_DIR}/testimages/testimgari.jpg")
add_test(djpeg-ari-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_ARI} -DFILE=testoutari.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(jpegtran-fromari sharedlib/jpegtran -outfile testouta.jpg "${CMAKE_SOURCE_DIR}/testimages/testimgari.jpg")
add_test(jpegtran-fromari-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_INT} -DFILE=testouta.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
endif()
add_test(jpegtran-crop sharedlib/jpegtran -crop 120x90+20+50 -transpose -perfect -outfile testoutcrop.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg")
add_test(jpegtran-crop-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_CROP} -DFILE=testoutcrop.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(tjunittest-static tjunittest-static) foreach(libtype shared static)
add_test(tjunittest-static-alloc tjunittest-static -alloc) if(libtype STREQUAL "shared")
add_test(tjunittest-static-yuv tjunittest-static -yuv) set(dir sharedlib/)
add_test(tjunittest-static-yuv-alloc tjunittest-static -yuv -alloc) else()
add_test(tjunittest-static-yuv-nopad tjunittest-static -yuv -noyuvpad) set(dir "")
add_test(cjpeg-static-int cjpeg-static -dct int -outfile testoutint.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm") set(suffix -static)
add_test(cjpeg-static-int-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_INT} -DFILE=testoutint.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") endif()
add_test(cjpeg-static-fast cjpeg-static -dct fast -opt -outfile testoutfst.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm") add_test(tjunittest${suffix} tjunittest${suffix})
add_test(cjpeg-static-fast-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_FAST} -DFILE=testoutfst.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") add_test(tjunittest${suffix}-alloc tjunittest${suffix} -alloc)
add_test(cjpeg-static-fast-100 cjpeg-static -dct fast -quality 100 -opt -outfile testoutfst100.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm") add_test(tjunittest${suffix}-yuv tjunittest${suffix} -yuv)
add_test(cjpeg-static-fast-100-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_FAST_100} -DFILE=testoutfst100.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") add_test(tjunittest${suffix}-yuv-alloc tjunittest${suffix} -yuv -alloc)
add_test(cjpeg-static-float cjpeg-static -dct float -outfile testoutflt.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm") add_test(tjunittest${suffix}-yuv-nopad tjunittest${suffix} -yuv -noyuvpad)
if(WITH_SIMD)
add_test(cjpeg-static-float-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_FLOAT} -DFILE=testoutflt.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
else()
add_test(cjpeg-static-float-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_FLOAT_NOSIMD} -DFILE=testoutflt.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
endif()
add_test(cjpeg-static-int-gray cjpeg-static -dct int -grayscale -outfile testoutgray.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm")
add_test(cjpeg-static-int-gray-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_INT_GRAY} -DFILE=testoutgray.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(djpeg-static-int djpeg-static -dct int -fast -ppm -outfile testoutint.ppm "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg")
add_test(djpeg-static-int-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_INT} -DFILE=testoutint.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(djpeg-static-fast djpeg-static -dct fast -ppm -outfile testoutfst.ppm "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg")
add_test(djpeg-static-fast-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_FAST} -DFILE=testoutfst.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(djpeg-static-float djpeg-static -dct float -ppm -outfile testoutflt.ppm "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg")
if(WITH_SIMD)
add_test(djpeg-static-float-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_FLOAT} -DFILE=testoutflt.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
else()
add_test(djpeg-static-float-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_FLOAT_NOSIMD} -DFILE=testoutflt.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
endif()
foreach(scale 2_1 15_8 7_4 13_8 3_2 11_8 5_4 9_8 7_8 3_4 5_8 1_2 3_8 1_4 1_8)
string(REGEX REPLACE "_" "/" scalearg ${scale})
add_test(djpeg-static-int-${scale} djpeg-static -dct int -nosmooth -scale ${scalearg} -ppm -outfile testoutint${scale}.ppm "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg")
add_test(djpeg-static-int-${scale}-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_INT_${scale}} -DFILE=testoutint${scale}.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
endforeach()
add_test(djpeg-static-fast-1_2 djpeg-static -dct fast -scale 1/2 -ppm -outfile testoutfst1_2.ppm "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg")
add_test(djpeg-static-fast-1_2-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_FAST_1_2} -DFILE=testoutfst1_2.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(djpeg-static-256 djpeg-static -dct int -bmp -colors 256 -outfile testout.bmp "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg")
add_test(djpeg-static-256-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_BMP_256} -DFILE=testout.bmp -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(cjpeg-static-prog cjpeg-static -dct int -progressive -outfile testoutp.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm")
add_test(cjpeg-static-prog-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_PROG} -DFILE=testoutp.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(jpegtran-static-prog jpegtran-static -outfile testoutt.jpg testoutp.jpg")
add_test(jpegtran-static-prog-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_INT} -DFILE=testoutt.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
if(WITH_ARITH_ENC)
add_test(cjpeg-static-ari cjpeg-static -dct int -arithmetic -outfile testoutari.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm")
add_test(cjpeg-static-ari-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_ARI} -DFILE=testoutari.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(jpegtran-static-toari jpegtran-static -arithmetic -outfile testouta.jpg "${CMAKE_SOURCE_DIR}/testimages/testimgint.jpg")
add_test(jpegtran-static-toari-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_ARI} -DFILE=testouta.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(cjpeg-static-prog-ari cjpeg-static -dct int -progressive -arithmetic -sample 1x1 -outfile testoutpa.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm")
add_test(cjpeg-static-prog-ari-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_PROG_ARI} -DFILE=testoutpa.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
endif()
if(WITH_ARITH_DEC)
add_test(djpeg-static-ari djpeg-static -dct int -fast -ppm -outfile testoutari.ppm "${CMAKE_SOURCE_DIR}/testimages/testimgari.jpg")
add_test(djpeg-static-ari-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_ARI} -DFILE=testoutari.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_test(jpegtran-static-fromari jpegtran-static -outfile testouta.jpg "${CMAKE_SOURCE_DIR}/testimages/testimgari.jpg")
add_test(jpegtran-static-fromari-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_INT} -DFILE=testouta.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
endif()
add_test(jpegtran-static-crop jpegtran-static -crop 120x90+20+50 -transpose -perfect -outfile testoutcrop.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg")
add_test(jpegtran-static-crop-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_CROP} -DFILE=testoutcrop.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake")
add_custom_target(testclean COMMAND "${CMAKE_COMMAND}" -P # These tests are carefully chosen to provide full coverage of as many of the
"${CMAKE_SOURCE_DIR}/cmakescripts/testclean.cmake" VERBATIM) # underlying algorithms as possible (including all of the SIMD-accelerated
# ones.)
# CC: null SAMP: fullsize FDCT: islow ENT: huff
add_test(cjpeg${suffix}-rgb-islow
${dir}cjpeg${suffix} -rgb -dct int -outfile testout_rgb_islow.jpg
${CMAKE_SOURCE_DIR}/testimages/testorig.ppm)
add_test(cjpeg${suffix}-rgb-islow-cmp
${CMAKE_COMMAND} -DMD5=${MD5_JPEG_RGB_ISLOW} -DFILE=testout_rgb_islow.jpg
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: null SAMP: fullsize IDCT: islow ENT: huff
add_test(djpeg${suffix}-rgb-islow
${dir}djpeg${suffix} -dct int -ppm -outfile testout_rgb_islow.ppm
testout_rgb_islow.jpg)
add_test(djpeg${suffix}-rgb-islow-cmp
${CMAKE_COMMAND} -DMD5=${MD5_PPM_RGB_ISLOW} -DFILE=testout_rgb_islow.ppm
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: RGB->RGB565 SAMP: fullsize IDCT: islow ENT: huff
add_test(djpeg${suffix}-rgb-islow-565
${dir}djpeg${suffix} -dct int -rgb565 -dither none -bmp
-outfile testout_rgb_islow_565.bmp testout_rgb_islow.jpg)
add_test(djpeg${suffix}-rgb-islow-565-cmp
${CMAKE_COMMAND} -DMD5=${MD5_BMP_RGB_ISLOW_565}
-DFILE=testout_rgb_islow_565.bmp
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: RGB->RGB565 (dithered) SAMP: fullsize IDCT: islow ENT: huff
add_test(djpeg${suffix}-rgb-islow-565D
${dir}djpeg${suffix} -dct int -rgb565 -bmp
-outfile testout_rgb_islow_565D.bmp testout_rgb_islow.jpg)
add_test(djpeg${suffix}-rgb-islow-565D-cmp
${CMAKE_COMMAND} -DMD5=${MD5_BMP_RGB_ISLOW_565D}
-DFILE=testout_rgb_islow_565D.bmp
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: RGB->YCC SAMP: fullsize/h2v1 FDCT: ifast ENT: 2-pass huff
add_test(cjpeg${suffix}-422-ifast-opt
${dir}cjpeg${suffix} -sample 2x1 -dct fast -opt
-outfile testout_422_ifast_opt.jpg
${CMAKE_SOURCE_DIR}/testimages/testorig.ppm)
add_test(cjpeg${suffix}-422-ifast-opt-cmp
${CMAKE_COMMAND} -DMD5=${MD5_JPEG_422_IFAST_OPT}
-DFILE=testout_422_ifast_opt.jpg
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: YCC->RGB SAMP: fullsize/h2v1 fancy IDCT: ifast ENT: huff
add_test(djpeg${suffix}-422-ifast
${dir}djpeg${suffix} -dct fast -outfile testout_422_ifast.ppm
testout_422_ifast_opt.jpg)
add_test(djpeg${suffix}-422-ifast-cmp
${CMAKE_COMMAND} -DMD5=${MD5_PPM_422_IFAST} -DFILE=testout_422_ifast.ppm
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: YCC->RGB SAMP: h2v1 merged IDCT: ifast ENT: huff
add_test(djpeg${suffix}-422m-ifast
${dir}djpeg${suffix} -dct fast -nosmooth -outfile testout_422m_ifast.ppm
testout_422_ifast_opt.jpg)
add_test(djpeg${suffix}-422m-ifast-cmp
${CMAKE_COMMAND} -DMD5=${MD5_PPM_422M_IFAST} -DFILE=testout_422m_ifast.ppm
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: YCC->RGB565 SAMP: h2v1 merged IDCT: ifast ENT: huff
add_test(djpeg${suffix}-422m-ifast-565
${dir}djpeg${suffix} -dct int -nosmooth -rgb565 -dither none -bmp
-outfile testout_422m_ifast_565.bmp testout_422_ifast_opt.jpg)
add_test(djpeg${suffix}-422m-ifast-565-cmp
${CMAKE_COMMAND} -DMD5=${MD5_BMP_422M_IFAST_565}
-DFILE=testout_422m_ifast_565.bmp
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: YCC->RGB565 (dithered) SAMP: h2v1 merged IDCT: ifast ENT: huff
add_test(djpeg${suffix}-422m-ifast-565D
${dir}djpeg${suffix} -dct int -nosmooth -rgb565 -bmp
-outfile testout_422m_ifast_565D.bmp testout_422_ifast_opt.jpg)
add_test(djpeg${suffix}-422m-ifast-565D-cmp
${CMAKE_COMMAND} -DMD5=${MD5_BMP_422M_IFAST_565D}
-DFILE=testout_422m_ifast_565D.bmp
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: RGB->YCC SAMP: fullsize/h2v2 FDCT: ifast ENT: prog huff
add_test(cjpeg${suffix}-420-q100-ifast-prog
${dir}cjpeg${suffix} -sample 2x2 -quality 100 -dct fast -prog
-outfile testout_420_q100_ifast_prog.jpg
${CMAKE_SOURCE_DIR}/testimages/testorig.ppm)
add_test(cjpeg${suffix}-420-q100-ifast-prog-cmp
${CMAKE_COMMAND} -DMD5=${MD5_JPEG_420_IFAST_Q100_PROG}
-DFILE=testout_420_q100_ifast_prog.jpg
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: YCC->RGB SAMP: fullsize/h2v2 fancy IDCT: ifast ENT: prog huff
add_test(djpeg${suffix}-420-q100-ifast-prog
${dir}djpeg${suffix} -dct fast -outfile testout_420_q100_ifast.ppm
testout_420_q100_ifast_prog.jpg)
add_test(djpeg${suffix}-420-q100-ifast-prog-cmp
${CMAKE_COMMAND} -DMD5=${MD5_PPM_420_Q100_IFAST}
-DFILE=testout_420_q100_ifast.ppm
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: YCC->RGB SAMP: h2v2 merged IDCT: ifast ENT: prog huff
add_test(djpeg${suffix}-420m-q100-ifast-prog
${dir}djpeg${suffix} -dct fast -nosmooth
-outfile testout_420m_q100_ifast.ppm testout_420_q100_ifast_prog.jpg)
add_test(djpeg${suffix}-420m-q100-ifast-prog-cmp
${CMAKE_COMMAND} -DMD5=${MD5_PPM_420M_Q100_IFAST}
-DFILE=testout_420m_q100_ifast.ppm
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: RGB->Gray SAMP: fullsize FDCT: islow ENT: huff
add_test(cjpeg${suffix}-gray-islow
${dir}cjpeg${suffix} -gray -dct int -outfile testout_gray_islow.jpg
${CMAKE_SOURCE_DIR}/testimages/testorig.ppm)
add_test(cjpeg${suffix}-gray-islow-cmp
${CMAKE_COMMAND} -DMD5=${MD5_JPEG_GRAY_ISLOW}
-DFILE=testout_gray_islow.jpg
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: Gray->Gray SAMP: fullsize IDCT: islow ENT: huff
add_test(djpeg${suffix}-gray-islow
${dir}djpeg${suffix} -dct int -outfile testout_gray_islow.ppm
testout_gray_islow.jpg)
add_test(djpeg${suffix}-gray-islow-cmp
${CMAKE_COMMAND} -DMD5=${MD5_PPM_GRAY_ISLOW}
-DFILE=testout_gray_islow.ppm
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: Gray->RGB SAMP: fullsize IDCT: islow ENT: huff
add_test(djpeg${suffix}-gray-islow-rgb
${dir}djpeg${suffix} -dct int -rgb -outfile testout_gray_islow_rgb.ppm
testout_gray_islow.jpg)
add_test(cjpeg${suffix}-gray-islow-rgb-cmp
${CMAKE_COMMAND} -DMD5=${MD5_PPM_GRAY_ISLOW_RGB}
-DFILE=testout_gray_islow_rgb.ppm
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: Gray->RGB565 SAMP: fullsize IDCT: islow ENT: huff
add_test(djpeg${suffix}-gray-islow-565
${dir}djpeg${suffix} -dct int -rgb565 -dither none -bmp
-outfile testout_gray_islow_565.bmp testout_gray_islow.jpg)
add_test(djpeg${suffix}-gray-islow-565-cmp
${CMAKE_COMMAND} -DMD5=${MD5_BMP_GRAY_ISLOW_565}
-DFILE=testout_gray_islow_565.bmp
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: Gray->RGB565 (dithered) SAMP: fullsize IDCT: islow ENT: huff
add_test(djpeg${suffix}-gray-islow-565D
${dir}djpeg${suffix} -dct int -rgb565 -bmp
-outfile testout_gray_islow_565D.bmp testout_gray_islow.jpg)
add_test(djpeg${suffix}-gray-islow-565D-cmp
${CMAKE_COMMAND} -DMD5=${MD5_BMP_GRAY_ISLOW_565D}
-DFILE=testout_gray_islow_565D.bmp
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: RGB->YCC SAMP: fullsize smooth/h2v2 smooth FDCT: islow
# ENT: 2-pass huff
add_test(cjpeg${suffix}-420s-ifast-opt
${dir}cjpeg${suffix} -sample 2x2 -smooth 1 -dct int -opt -outfile
testout_420s_ifast_opt.jpg ${CMAKE_SOURCE_DIR}/testimages/testorig.ppm)
add_test(cjpeg${suffix}-420s-ifast-opt-cmp
${CMAKE_COMMAND} -DMD5=${MD5_JPEG_420S_IFAST_OPT}
-DFILE=testout_420s_ifast_opt.jpg
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: RGB->YCC SAMP: fullsize/int FDCT: float ENT: prog huff
add_test(cjpeg${suffix}-3x2-float-prog
${dir}cjpeg${suffix} -sample 3x2 -dct float -prog
-outfile testout_3x2_float_prog.jpg
${CMAKE_SOURCE_DIR}/testimages/testorig.ppm)
add_test(cjpeg${suffix}-3x2-float-prog-cmp
${CMAKE_COMMAND} -DMD5=${MD5_JPEG_3x2_FLOAT_PROG}
-DFILE=testout_3x2_float_prog.jpg
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: YCC->RGB SAMP: fullsize/int IDCT: float ENT: prog huff
add_test(djpeg${suffix}-3x2-float-prog
${dir}djpeg${suffix} -dct float -outfile testout_3x2_float.ppm
testout_3x2_float_prog.jpg)
add_test(djpeg${suffix}-3x2-float-prog-cmp
${CMAKE_COMMAND} -DMD5=${MD5_PPM_3x2_FLOAT} -DFILE=testout_3x2_float.ppm
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
if(WITH_ARITH_ENC)
# CC: YCC->RGB SAMP: fullsize/h2v2 FDCT: islow ENT: arith
add_test(cjpeg${suffix}-420-islow-ari
${dir}cjpeg${suffix} -dct int -arithmetic
-outfile testout_420_islow_ari.jpg
${CMAKE_SOURCE_DIR}/testimages/testorig.ppm)
add_test(cjpeg${suffix}-420-islow-ari-cmp
${CMAKE_COMMAND} -DMD5=${MD5_JPEG_420_ISLOW_ARI}
-DFILE=testout_420_islow_ari.jpg
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
add_test(jpegtran${suffix}-420-islow-ari
${dir}jpegtran${suffix} -arithmetic
-outfile testout_420_islow_ari.jpg
${CMAKE_SOURCE_DIR}/testimages/testimgint.jpg)
add_test(jpegtran${suffix}-420-islow-ari-cmp
${CMAKE_COMMAND} -DMD5=${MD5_JPEG_420_ISLOW_ARI}
-DFILE=testout_420_islow_ari.jpg
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: YCC->RGB SAMP: fullsize FDCT: islow ENT: prog arith
add_test(cjpeg${suffix}-444-islow-progari
${dir}cjpeg${suffix} -sample 1x1 -dct int -progressive -arithmetic
-outfile testout_444_islow_progari.jpg
${CMAKE_SOURCE_DIR}/testimages/testorig.ppm)
add_test(cjpeg${suffix}-444-islow-progari-cmp
${CMAKE_COMMAND} -DMD5=${MD5_JPEG_444_ISLOW_PROGARI}
-DFILE=testout_444_islow_progari.jpg
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
endif()
if(WITH_ARITH_DEC)
# CC: RGB->YCC SAMP: h2v2 merged IDCT: ifast ENT: arith
add_test(cjpeg${suffix}-420m-ifast-ari
${dir}djpeg${suffix} -fast -ppm -outfile testout_420m_ifast_ari.ppm
${CMAKE_SOURCE_DIR}/testimages/testimgari.jpg)
add_test(cjpeg${suffix}-420m-ifast-ari-cmp
${CMAKE_COMMAND} -DMD5=${MD5_PPM_420M_IFAST_ARI}
-DFILE=testout_420m_ifast_ari.ppm
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
add_test(jpegtran${suffix}-420-islow
${dir}jpegtran${suffix} -outfile testout_420_islow.jpg
${CMAKE_SOURCE_DIR}/testimages/testimgari.jpg)
add_test(jpegtran${suffix}-420-islow-cmp
${CMAKE_COMMAND} -DMD5=${MD5_JPEG_420_ISLOW}
-DFILE=testout_420_islow.jpg
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
endif()
# 2/1-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 16x16 islow ENT: huff
# 15/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 15x15 islow ENT: huff
# 13/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 13x13 islow ENT: huff
# 11/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 11x11 islow ENT: huff
# 9/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 9x9 islow ENT: huff
# 7/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 7x7 islow/14x14 islow
# ENT: huff
# 3/4-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 6x6 islow/12x12 islow
# ENT: huff
# 5/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 5x5 islow/10x10 islow
# ENT: huff
# 1/2-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 4x4 islow/8x8 islow
# ENT: huff
# 3/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 3x3 islow/6x6 islow
# ENT: huff
# 1/4-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 2x2 islow/4x4 islow
# ENT: huff
# 1/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 1x1 islow/2x2 islow
# ENT: huff
foreach(scale 2_1 15_8 13_8 11_8 9_8 7_8 3_4 5_8 1_2 3_8 1_4 1_8)
string(REGEX REPLACE "_" "/" scalearg ${scale})
add_test(djpeg${suffix}-420m-islow-${scale}
${dir}djpeg${suffix} -dct int -scale ${scalearg} -nosmooth -ppm
-outfile testout_420m_islow_${scale}.ppm
${CMAKE_SOURCE_DIR}/testimages/testorig.jpg)
add_test(djpeg${suffix}-420m-islow-${scale}-cmp
${CMAKE_COMMAND} -DMD5=${MD5_PPM_420M_ISLOW_${scale}}
-DFILE=testout_420m_islow_${scale}.ppm
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
endforeach()
# CC: YCC->RGB (dithered) SAMP: h2v2 fancy IDCT: islow ENT: huff
add_test(djpeg${suffix}-420-islow-256
${dir}djpeg${suffix} -dct int -colors 256 -bmp
-outfile testout_420_islow_256.bmp
${CMAKE_SOURCE_DIR}/testimages/testorig.jpg)
add_test(djpeg${suffix}-420-islow-256-cmp
${CMAKE_COMMAND} -DMD5=${MD5_BMP_420_ISLOW_256}
-DFILE=testout_420_islow_256.bmp
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: YCC->RGB565 SAMP: h2v2 fancy IDCT: islow ENT: huff
add_test(djpeg${suffix}-420-islow-565
${dir}djpeg${suffix} -dct int -rgb565 -dither none -bmp
-outfile testout_420_islow_565.bmp
${CMAKE_SOURCE_DIR}/testimages/testorig.jpg)
add_test(djpeg${suffix}-420-islow-565-cmp
${CMAKE_COMMAND} -DMD5=${MD5_BMP_420_ISLOW_565}
-DFILE=testout_420_islow_565.bmp
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: YCC->RGB565 (dithered) SAMP: h2v2 fancy IDCT: islow ENT: huff
add_test(djpeg${suffix}-420-islow-565D
${dir}djpeg${suffix} -dct int -rgb565 -bmp
-outfile testout_420_islow_565D.bmp
${CMAKE_SOURCE_DIR}/testimages/testorig.jpg)
add_test(djpeg${suffix}-420-islow-565D-cmp
${CMAKE_COMMAND} -DMD5=${MD5_BMP_420_ISLOW_565D}
-DFILE=testout_420_islow_565D.bmp
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: YCC->RGB565 SAMP: h2v2 merged IDCT: islow ENT: huff
add_test(djpeg${suffix}-420m-islow-565
${dir}djpeg${suffix} -dct int -nosmooth -rgb565 -dither none -bmp
-outfile testout_420m_islow_565.bmp
${CMAKE_SOURCE_DIR}/testimages/testorig.jpg)
add_test(djpeg${suffix}-420m-islow-565-cmp
${CMAKE_COMMAND} -DMD5=${MD5_BMP_420M_ISLOW_565}
-DFILE=testout_420m_islow_565.bmp
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
# CC: YCC->RGB565 (dithered) SAMP: h2v2 merged IDCT: islow ENT: huff
add_test(djpeg${suffix}-420m-islow-565D
${dir}djpeg${suffix} -dct int -nosmooth -rgb565 -bmp
-outfile testout_420m_islow_565D.bmp
${CMAKE_SOURCE_DIR}/testimages/testorig.jpg)
add_test(djpeg${suffix}-420m-islow-565D-cmp
${CMAKE_COMMAND} -DMD5=${MD5_BMP_420M_ISLOW_565D}
-DFILE=testout_420m_islow_565D.bmp
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
add_test(jpegtran${suffix}-crop
${dir}jpegtran${suffix} -crop 120x90+20+50 -transpose -perfect
-outfile testout_crop.jpg ${CMAKE_SOURCE_DIR}/testimages/testorig.jpg)
add_test(jpegtran${suffix}-crop-cmp
${CMAKE_COMMAND} -DMD5=${MD5_JPEG_CROP} -DFILE=testout_crop.jpg
-P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
endforeach()
add_custom_target(testclean COMMAND ${CMAKE_COMMAND} -P
${CMAKE_SOURCE_DIR}/cmakescripts/testclean.cmake)
# #

View File

@@ -42,11 +42,43 @@ later. OS X 10.4 "Tiger" is no longer supported.
[5] The Huffman encoder now uses clz and bsr instructions for bit counting on [5] The Huffman encoder now uses clz and bsr instructions for bit counting on
ARM platforms rather than a lookup table. This reduces the memory footprint ARM platforms rather than a lookup table. This reduces the memory footprint
by 64k, which may be important for some mobile applications. Out of four by 64k, which may be important for some mobile applications. Out of four
Android devices that were tested, two demonstrated a small loss (~3-4% on Android devices that were tested, two demonstrated a small overall performance
average) with ARMv6 code and a small gain (also ~3-4%) with ARMv7 code when loss (~3-4% on average) with ARMv6 code and a small gain (also ~3-4%) with
enabling this new feature, but the other two devices demonstrated a ARMv7 code when enabling this new feature, but the other two devices
significant performance gain across the board (~10-20%.) Actual mileage may demonstrated a significant overall performance gain with both ARMv6 and ARMv7
vary. code (~10-20%.) Actual mileage may vary.
[6] Worked around an issue with Visual C++ 2010 and later that caused incorrect
pixels to be generated when decompressing a JPEG image to a 256-color bitmap,
if compiler optimization was enabled when libjpeg-turbo was built. This caused
the regression tests to fail when doing a release build under Visual C++ 2010
and later.
[7] Improved the accuracy and performance of the non-SIMD implementation of the
floating point inverse DCT (using code borrowed from libjpeg v8a and later.)
The accuracy of this implementation now matches the accuracy of the SSE/SSE2
implementation. Note, however, that the floating point DCT/IDCT algorithms are
mainly a legacy feature. They generally do not produce significantly better
accuracy than the slow integer DCT/IDCT algorithms, and they are quite a bit
slower.
[8] Added a new output colorspace (JCS_RGB565) to the libjpeg API that allows
for decompressing JPEG images into RGB565 (16-bit) pixels.
[9] Numerous obsolete features, such as support for compilers that can't
handle prototypes and support for the MS-DOS memory model, were removed from
the libjpeg code, greatly improving its readability and making it easier to
maintain and extend.
[10] Fixed a segfault that occurred when calling output_message() with msg_code
set to JMSG_COPYRIGHT.
[11] Fixed an issue whereby wrjpgcom was allowing comments longer than 65k
characters to be passed on the command line, which was causing it to generate
incorrect JPEG files.
[12] Fixed a bug in the build system that was causing the Windows version of
wrjpgcom to be built using the rdjpgcom code.
[7] Improved the accuracy and performance of the non-SIMD implementation of the [7] Improved the accuracy and performance of the non-SIMD implementation of the
floating point inverse DCT (using code borrowed from libjpeg v8a and later.) floating point inverse DCT (using code borrowed from libjpeg v8a and later.)

View File

@@ -12,7 +12,8 @@ nodist_include_HEADERS = jconfig.h
HDRS = jchuff.h jdct.h jdhuff.h jerror.h jinclude.h jmemsys.h jmorecfg.h \ HDRS = jchuff.h jdct.h jdhuff.h jerror.h jinclude.h jmemsys.h jmorecfg.h \
jpegint.h jpeglib.h jversion.h jsimd.h jsimddct.h jpegcomp.h jpegint.h jpeglib.h jversion.h jsimd.h jsimddct.h jpegcomp.h \
jpeg_nbits_table.h
libjpeg_la_SOURCES = $(HDRS) jcapimin.c jcapistd.c jccoefct.c jccolor.c \ libjpeg_la_SOURCES = $(HDRS) jcapimin.c jcapistd.c jccoefct.c jccolor.c \
jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \ jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \
@@ -162,7 +163,7 @@ dist_example_DATA = example.c
EXTRA_DIST = win release $(DOCS) testimages CMakeLists.txt \ EXTRA_DIST = win release $(DOCS) testimages CMakeLists.txt \
sharedlib/CMakeLists.txt cmakescripts libjpeg.map.in doc doxygen.config \ sharedlib/CMakeLists.txt cmakescripts libjpeg.map.in doc doxygen.config \
jccolext.c jdcolext.c jdmrgext.c jstdhuff.c jccolext.c jdcolext.c jdcol565.c jdmrgext.c jstdhuff.c
dist-hook: dist-hook:
rm -rf `find $(distdir) -name .svn` rm -rf `find $(distdir) -name .svn`
@@ -170,40 +171,57 @@ dist-hook:
SUBDIRS += md5 SUBDIRS += md5
MD5_JPEG_INT = 9a68f56bc76e466aa7e52f415d0f4a5f MD5_JPEG_RGB_ISLOW = 768e970dd57b340ff1b83c9d3d47c77b
MD5_JPEG_FAST = 0e1502e7fa421835e376a314fac2a39f MD5_PPM_RGB_ISLOW = 00a257f5393fef8821f2b88ac7421291
MD5_JPEG_FAST_100 = 7bf72a8e741d64eecb960c97323af77c MD5_BMP_RGB_ISLOW_565 = f07d2e75073e4bb10f6c6f4d36e2e3be
MD5_JPEG_FLOAT = d1623885ffafcd40c684af09e3d65cd5 MD5_BMP_RGB_ISLOW_565D = 4cfa0928ef3e6bb626d7728c924cfda4
MD5_JPEG_FLOAT_NOSIMD = fb4884c35f8273f498cb32879de5c455 MD5_JPEG_422_IFAST_OPT = 2540287b79d913f91665e660303ab2c8
MD5_JPEG_INT_GRAY = 72b51f894b8f4a10b3ee3066770aa38d MD5_PPM_422_IFAST = 35bd6b3f833bad23de82acea847129fa
MD5_PPM_INT = d1ed0d11f076b842525271647716aeb8 MD5_PPM_422M_IFAST = 8dbc65323d62cca7c91ba02dd1cfa81d
MD5_PPM_FAST = 048298a2d2410261c0533cb97bcfef23 MD5_BMP_422M_IFAST_565 = 3294bd4d9a1f2b3d08ea6020d0db7065
MD5_PPM_FLOAT = 7f5b446ee36b2630e06785b8d42af15f MD5_BMP_422M_IFAST_565D = da98c9c7b6039511be4a79a878a9abc1
MD5_PPM_FLOAT_NOSIMD = 64072f1dbdc5b3a187777788604971a5 MD5_JPEG_420_IFAST_Q100_PROG = 990cbe0329c882420a2094da7e5adade
MD5_PPM_INT_2_1 = 9f9de8c0612f8d06869b960b05abf9c9 MD5_PPM_420_Q100_IFAST = 5a732542015c278ff43635e473a8a294
MD5_PPM_INT_15_8 = b6875bc070720b899566cc06459b63b7 MD5_PPM_420M_Q100_IFAST = ff692ee9323a3b424894862557c092f1
MD5_PPM_INT_7_4 = 06a177eae05f164fac57f7a2c346ee87 MD5_JPEG_GRAY_ISLOW = 72b51f894b8f4a10b3ee3066770aa38d
MD5_PPM_INT_13_8 = bc3452573c8152f6ae552939ee19f82f MD5_PPM_GRAY_ISLOW = 8d3596c56eace32f205deccc229aa5ed
MD5_PPM_INT_3_2 = f5a8b88a8a7f96016f04d259cf82ed67 MD5_PPM_GRAY_ISLOW_RGB = 116424ac07b79e5e801f00508eab48ec
MD5_PPM_INT_11_8 = d8cc73c0aaacd4556569b59437ba00a5 MD5_BMP_GRAY_ISLOW_565 = 12f78118e56a2f48b966f792fedf23cc
MD5_PPM_INT_5_4 = 32775dd9ad2ab90f4c5b219b53e0c86c MD5_BMP_GRAY_ISLOW_565D = bdbbd616441a24354c98553df5dc82db
MD5_PPM_INT_9_8 = d25e61bc7eac0002f5b393aa223747b6 MD5_JPEG_420S_IFAST_OPT = 388708217ac46273ca33086b22827ed8
MD5_PPM_INT_7_8 = ddb564b7c74a09494016d6cd7502a946 # See README-turbo.txt for more details on why this next bit is necessary.
MD5_PPM_INT_3_4 = 8ed8e68808c3fbc4ea764fc9d2968646 if WITH_SSE_FLOAT_DCT
MD5_PPM_INT_5_8 = a3363274999da2366a024efae6d16c9b MD5_JPEG_3x2_FLOAT_PROG = 343e3f8caf8af5986ebaf0bdc13b5c71
MD5_PPM_INT_1_2 = e692a315cea26b988c8e8b29a5dbcd81 MD5_PPM_3x2_FLOAT = 1a75f36e5904d6fc3a85a43da9ad89bb
MD5_PPM_INT_3_8 = 79eca9175652ced755155c90e785a996 else
MD5_PPM_INT_1_4 = 79cd778f8bf1a117690052cacdd54eca MD5_JPEG_3x2_FLOAT_PROG = 9bca803d2042bd1eb03819e2bf92b3e5
MD5_PPM_INT_1_8 = 391b3d4aca640c8567d6f8745eb2142f MD5_PPM_3x2_FLOAT = f6bfab038438ed8f5522fbd33595dcdc
MD5_PPM_FAST_1_2 = f30bcf6d32ccd44cbdd9aeaacbd9454f endif
MD5_BMP_256 = 4980185e3776e89bd931736e1cddeee6 MD5_JPEG_420_ISLOW_ARI = e986fb0a637a8d833d96e8a6d6d84ea1
MD5_JPEG_ARI = e986fb0a637a8d833d96e8a6d6d84ea1 MD5_JPEG_444_ISLOW_PROGARI = 0a8f1c8f66e113c3cf635df0a475a617
MD5_PPM_ARI = 72b59a99bcf1de24c5b27d151bde2437 MD5_PPM_420M_IFAST_ARI = 72b59a99bcf1de24c5b27d151bde2437
MD5_JPEG_PROG = 1c4afddc05c0a43489ee54438a482d92 MD5_JPEG_420_ISLOW = 9a68f56bc76e466aa7e52f415d0f4a5f
MD5_JPEG_PROG_ARI = 0a8f1c8f66e113c3cf635df0a475a617 MD5_PPM_420M_ISLOW_2_1 = 9f9de8c0612f8d06869b960b05abf9c9
MD5_PPM_420M_ISLOW_15_8 = b6875bc070720b899566cc06459b63b7
MD5_PPM_420M_ISLOW_13_8 = bc3452573c8152f6ae552939ee19f82f
MD5_PPM_420M_ISLOW_11_8 = d8cc73c0aaacd4556569b59437ba00a5
MD5_PPM_420M_ISLOW_9_8 = d25e61bc7eac0002f5b393aa223747b6
MD5_PPM_420M_ISLOW_7_8 = ddb564b7c74a09494016d6cd7502a946
MD5_PPM_420M_ISLOW_3_4 = 8ed8e68808c3fbc4ea764fc9d2968646
MD5_PPM_420M_ISLOW_5_8 = a3363274999da2366a024efae6d16c9b
MD5_PPM_420M_ISLOW_1_2 = e692a315cea26b988c8e8b29a5dbcd81
MD5_PPM_420M_ISLOW_3_8 = 79eca9175652ced755155c90e785a996
MD5_PPM_420M_ISLOW_1_4 = 79cd778f8bf1a117690052cacdd54eca
MD5_PPM_420M_ISLOW_1_8 = 391b3d4aca640c8567d6f8745eb2142f
MD5_BMP_420_ISLOW_256 = 4980185e3776e89bd931736e1cddeee6
MD5_BMP_420_ISLOW_565 = bf9d13e16c4923b92e1faa604d7922cb
MD5_BMP_420_ISLOW_565D = 6bde71526acc44bcff76f696df8638d2
MD5_BMP_420M_ISLOW_565 = 8dc0185245353cfa32ad97027342216f
MD5_BMP_420M_ISLOW_565D =d1be3a3339166255e76fa50a0d70d73e
MD5_JPEG_CROP = b4197f377e621c4e9b1d20471432610d MD5_JPEG_CROP = b4197f377e621c4e9b1d20471432610d
test: testclean all test: testclean all
if WITH_TURBOJPEG if WITH_TURBOJPEG
if WITH_JAVA if WITH_JAVA
$(JAVA) -cp java/turbojpeg.jar -Djava.library.path=.libs TJUnitTest $(JAVA) -cp java/turbojpeg.jar -Djava.library.path=.libs TJUnitTest
@@ -219,84 +237,188 @@ endif
./tjunittest -yuv -alloc ./tjunittest -yuv -alloc
./tjunittest -yuv -noyuvpad ./tjunittest -yuv -noyuvpad
endif endif
./cjpeg -dct int -outfile testoutint.jpg $(srcdir)/testimages/testorig.ppm
md5/md5cmp $(MD5_JPEG_INT) testoutint.jpg # These tests are carefully crafted to provide full coverage of as many of the
./cjpeg -dct fast -opt -outfile testoutfst.jpg $(srcdir)/testimages/testorig.ppm # underlying algorithms as possible (including all of the SIMD-accelerated
md5/md5cmp $(MD5_JPEG_FAST) testoutfst.jpg # ones.)
./cjpeg -dct fast -quality 100 -opt -outfile testoutfst100.jpg $(srcdir)/testimages/testorig.ppm
md5/md5cmp $(MD5_JPEG_FAST_100) testoutfst100.jpg # CC: null SAMP: fullsize FDCT: islow ENT: huff
./cjpeg -dct float -outfile testoutflt.jpg $(srcdir)/testimages/testorig.ppm ./cjpeg -rgb -dct int -outfile testout_rgb_islow.jpg $(srcdir)/testimages/testorig.ppm
if WITH_SSE_FLOAT_DCT md5/md5cmp $(MD5_JPEG_RGB_ISLOW) testout_rgb_islow.jpg
md5/md5cmp $(MD5_JPEG_FLOAT) testoutflt.jpg # CC: null SAMP: fullsize IDCT: islow ENT: huff
else ./djpeg -dct int -ppm -outfile testout_rgb_islow.ppm testout_rgb_islow.jpg
md5/md5cmp $(MD5_JPEG_FLOAT_NOSIMD) testoutflt.jpg md5/md5cmp $(MD5_PPM_RGB_ISLOW) testout_rgb_islow.ppm
endif rm testout_rgb_islow.ppm
./cjpeg -dct int -grayscale -outfile testoutgray.jpg $(srcdir)/testimages/testorig.ppm # CC: RGB->RGB565 SAMP: fullsize IDCT: islow ENT: huff
md5/md5cmp $(MD5_JPEG_INT_GRAY) testoutgray.jpg ./djpeg -dct int -rgb565 -dither none -bmp -outfile testout_rgb_islow_565.bmp testout_rgb_islow.jpg
./djpeg -dct int -fast -ppm -outfile testoutint.ppm $(srcdir)/testimages/testorig.jpg md5/md5cmp $(MD5_BMP_RGB_ISLOW_565) testout_rgb_islow_565.bmp
md5/md5cmp $(MD5_PPM_INT) testoutint.ppm rm testout_rgb_islow_565.bmp
./djpeg -dct fast -ppm -outfile testoutfst.ppm $(srcdir)/testimages/testorig.jpg # CC: RGB->RGB565 (dithered) SAMP: fullsize IDCT: islow ENT: huff
md5/md5cmp $(MD5_PPM_FAST) testoutfst.ppm ./djpeg -dct int -rgb565 -bmp -outfile testout_rgb_islow_565D.bmp testout_rgb_islow.jpg
./djpeg -dct float -ppm -outfile testoutflt.ppm $(srcdir)/testimages/testorig.jpg md5/md5cmp $(MD5_BMP_RGB_ISLOW_565D) testout_rgb_islow_565D.bmp
if WITH_SSE_FLOAT_DCT rm testout_rgb_islow_565D.bmp testout_rgb_islow.jpg
md5/md5cmp $(MD5_PPM_FLOAT) testoutflt.ppm
else # CC: RGB->YCC SAMP: fullsize/h2v1 FDCT: ifast ENT: 2-pass huff
md5/md5cmp $(MD5_PPM_FLOAT_NOSIMD) testoutflt.ppm ./cjpeg -sample 2x1 -dct fast -opt -outfile testout_422_ifast_opt.jpg $(srcdir)/testimages/testorig.ppm
endif md5/md5cmp $(MD5_JPEG_422_IFAST_OPT) testout_422_ifast_opt.jpg
./djpeg -dct int -nosmooth -scale 2/1 -ppm -outfile testoutint2_1.ppm $(srcdir)/testimages/testorig.jpg; # CC: YCC->RGB SAMP: fullsize/h2v1 fancy IDCT: ifast ENT: huff
md5/md5cmp $(MD5_PPM_INT_2_1) testoutint2_1.ppm; ./djpeg -dct fast -outfile testout_422_ifast.ppm testout_422_ifast_opt.jpg
./djpeg -dct int -nosmooth -scale 15/8 -ppm -outfile testoutint15_8.ppm $(srcdir)/testimages/testorig.jpg; md5/md5cmp $(MD5_PPM_422_IFAST) testout_422_ifast.ppm
md5/md5cmp $(MD5_PPM_INT_15_8) testoutint15_8.ppm; rm testout_422_ifast.ppm
./djpeg -dct int -nosmooth -scale 7/4 -ppm -outfile testoutint7_4.ppm $(srcdir)/testimages/testorig.jpg; # CC: YCC->RGB SAMP: h2v1 merged IDCT: ifast ENT: huff
md5/md5cmp $(MD5_PPM_INT_7_4) testoutint7_4.ppm; ./djpeg -dct fast -nosmooth -outfile testout_422m_ifast.ppm testout_422_ifast_opt.jpg
./djpeg -dct int -nosmooth -scale 13/8 -ppm -outfile testoutint13_8.ppm $(srcdir)/testimages/testorig.jpg; md5/md5cmp $(MD5_PPM_422M_IFAST) testout_422m_ifast.ppm
md5/md5cmp $(MD5_PPM_INT_13_8) testoutint13_8.ppm; rm testout_422m_ifast.ppm
./djpeg -dct int -nosmooth -scale 3/2 -ppm -outfile testoutint3_2.ppm $(srcdir)/testimages/testorig.jpg; # CC: YCC->RGB565 SAMP: h2v1 merged IDCT: ifast ENT: huff
md5/md5cmp $(MD5_PPM_INT_3_2) testoutint3_2.ppm; ./djpeg -dct int -nosmooth -rgb565 -dither none -bmp -outfile testout_422m_ifast_565.bmp testout_422_ifast_opt.jpg
./djpeg -dct int -nosmooth -scale 11/8 -ppm -outfile testoutint11_8.ppm $(srcdir)/testimages/testorig.jpg; md5/md5cmp $(MD5_BMP_422M_IFAST_565) testout_422m_ifast_565.bmp
md5/md5cmp $(MD5_PPM_INT_11_8) testoutint11_8.ppm; rm testout_422m_ifast_565.bmp
./djpeg -dct int -nosmooth -scale 5/4 -ppm -outfile testoutint5_4.ppm $(srcdir)/testimages/testorig.jpg; # CC: YCC->RGB565 (dithered) SAMP: h2v1 merged IDCT: ifast ENT: huff
md5/md5cmp $(MD5_PPM_INT_5_4) testoutint5_4.ppm; ./djpeg -dct int -nosmooth -rgb565 -bmp -outfile testout_422m_ifast_565D.bmp testout_422_ifast_opt.jpg
./djpeg -dct int -nosmooth -scale 9/8 -ppm -outfile testoutint9_8.ppm $(srcdir)/testimages/testorig.jpg; md5/md5cmp $(MD5_BMP_422M_IFAST_565D) testout_422m_ifast_565D.bmp
md5/md5cmp $(MD5_PPM_INT_9_8) testoutint9_8.ppm; rm testout_422m_ifast_565D.bmp testout_422_ifast_opt.jpg
./djpeg -dct int -nosmooth -scale 7/8 -ppm -outfile testoutint7_8.ppm $(srcdir)/testimages/testorig.jpg;
md5/md5cmp $(MD5_PPM_INT_7_8) testoutint7_8.ppm; # CC: RGB->YCC SAMP: fullsize/h2v2 FDCT: ifast ENT: prog huff
./djpeg -dct int -nosmooth -scale 3/4 -ppm -outfile testoutint3_4.ppm $(srcdir)/testimages/testorig.jpg; ./cjpeg -sample 2x2 -quality 100 -dct fast -prog -outfile testout_420_q100_ifast_prog.jpg $(srcdir)/testimages/testorig.ppm
md5/md5cmp $(MD5_PPM_INT_3_4) testoutint3_4.ppm; md5/md5cmp $(MD5_JPEG_420_IFAST_Q100_PROG) testout_420_q100_ifast_prog.jpg
./djpeg -dct int -nosmooth -scale 5/8 -ppm -outfile testoutint5_8.ppm $(srcdir)/testimages/testorig.jpg; # CC: YCC->RGB SAMP: fullsize/h2v2 fancy IDCT: ifast ENT: prog huff
md5/md5cmp $(MD5_PPM_INT_5_8) testoutint5_8.ppm; ./djpeg -dct fast -outfile testout_420_q100_ifast.ppm testout_420_q100_ifast_prog.jpg
./djpeg -dct int -nosmooth -scale 1/2 -ppm -outfile testoutint1_2.ppm $(srcdir)/testimages/testorig.jpg; md5/md5cmp $(MD5_PPM_420_Q100_IFAST) testout_420_q100_ifast.ppm
md5/md5cmp $(MD5_PPM_INT_1_2) testoutint1_2.ppm; rm testout_420_q100_ifast.ppm
./djpeg -dct int -nosmooth -scale 3/8 -ppm -outfile testoutint3_8.ppm $(srcdir)/testimages/testorig.jpg; # CC: YCC->RGB SAMP: h2v2 merged IDCT: ifast ENT: prog huff
md5/md5cmp $(MD5_PPM_INT_3_8) testoutint3_8.ppm; ./djpeg -dct fast -nosmooth -outfile testout_420m_q100_ifast.ppm testout_420_q100_ifast_prog.jpg
./djpeg -dct int -nosmooth -scale 1/4 -ppm -outfile testoutint1_4.ppm $(srcdir)/testimages/testorig.jpg; md5/md5cmp $(MD5_PPM_420M_Q100_IFAST) testout_420m_q100_ifast.ppm
md5/md5cmp $(MD5_PPM_INT_1_4) testoutint1_4.ppm; rm testout_420m_q100_ifast.ppm testout_420_q100_ifast_prog.jpg
./djpeg -dct int -nosmooth -scale 1/8 -ppm -outfile testoutint1_8.ppm $(srcdir)/testimages/testorig.jpg;
md5/md5cmp $(MD5_PPM_INT_1_8) testoutint1_8.ppm; # CC: RGB->Gray SAMP: fullsize FDCT: islow ENT: huff
./djpeg -dct fast -scale 1/2 -ppm -outfile testoutfst1_2.ppm $(srcdir)/testimages/testorig.jpg ./cjpeg -gray -dct int -outfile testout_gray_islow.jpg $(srcdir)/testimages/testorig.ppm
md5/md5cmp $(MD5_PPM_FAST_1_2) testoutfst1_2.ppm md5/md5cmp $(MD5_JPEG_GRAY_ISLOW) testout_gray_islow.jpg
./djpeg -dct int -bmp -colors 256 -outfile testout.bmp $(srcdir)/testimages/testorig.jpg # CC: Gray->Gray SAMP: fullsize IDCT: islow ENT: huff
md5/md5cmp $(MD5_BMP_256) testout.bmp ./djpeg -dct int -outfile testout_gray_islow.ppm testout_gray_islow.jpg
md5/md5cmp $(MD5_PPM_GRAY_ISLOW) testout_gray_islow.ppm
rm testout_gray_islow.ppm
# CC: Gray->RGB SAMP: fullsize IDCT: islow ENT: huff
./djpeg -dct int -rgb -outfile testout_gray_islow_rgb.ppm testout_gray_islow.jpg
md5/md5cmp $(MD5_PPM_GRAY_ISLOW_RGB) testout_gray_islow_rgb.ppm
rm testout_gray_islow_rgb.ppm
# CC: Gray->RGB565 SAMP: fullsize IDCT: islow ENT: huff
./djpeg -dct int -rgb565 -dither none -bmp -outfile testout_gray_islow_565.bmp testout_gray_islow.jpg
md5/md5cmp $(MD5_BMP_GRAY_ISLOW_565) testout_gray_islow_565.bmp
rm testout_gray_islow_565.bmp
# CC: Gray->RGB565 (dithered) SAMP: fullsize IDCT: islow ENT: huff
./djpeg -dct int -rgb565 -bmp -outfile testout_gray_islow_565D.bmp testout_gray_islow.jpg
md5/md5cmp $(MD5_BMP_GRAY_ISLOW_565D) testout_gray_islow_565D.bmp
rm testout_gray_islow_565D.bmp testout_gray_islow.jpg
# CC: RGB->YCC SAMP: fullsize smooth/h2v2 smooth FDCT: islow
# ENT: 2-pass huff
./cjpeg -sample 2x2 -smooth 1 -dct int -opt -outfile testout_420s_ifast_opt.jpg $(srcdir)/testimages/testorig.ppm
md5/md5cmp $(MD5_JPEG_420S_IFAST_OPT) testout_420s_ifast_opt.jpg
rm testout_420s_ifast_opt.jpg
# CC: RGB->YCC SAMP: fullsize/int FDCT: float ENT: prog huff
./cjpeg -sample 3x2 -dct float -prog -outfile testout_3x2_float_prog.jpg $(srcdir)/testimages/testorig.ppm
md5/md5cmp $(MD5_JPEG_3x2_FLOAT_PROG) testout_3x2_float_prog.jpg
# CC: YCC->RGB SAMP: fullsize/int IDCT: float ENT: prog huff
./djpeg -dct float -outfile testout_3x2_float.ppm testout_3x2_float_prog.jpg
md5/md5cmp $(MD5_PPM_3x2_FLOAT) testout_3x2_float.ppm
rm testout_3x2_float.ppm testout_3x2_float_prog.jpg
if WITH_ARITH_ENC if WITH_ARITH_ENC
./cjpeg -dct int -arithmetic -outfile testoutari.jpg $(srcdir)/testimages/testorig.ppm # CC: YCC->RGB SAMP: fullsize/h2v2 FDCT: islow ENT: arith
md5/md5cmp $(MD5_JPEG_ARI) testoutari.jpg ./cjpeg -dct int -arithmetic -outfile testout_420_islow_ari.jpg $(srcdir)/testimages/testorig.ppm
./jpegtran -arithmetic -outfile testouta.jpg $(srcdir)/testimages/testimgint.jpg md5/md5cmp $(MD5_JPEG_420_ISLOW_ARI) testout_420_islow_ari.jpg
md5/md5cmp $(MD5_JPEG_ARI) testouta.jpg rm testout_420_islow_ari.jpg
./cjpeg -dct int -progressive -arithmetic -sample 1x1 -outfile testoutpa.jpg $(srcdir)/testimages/testorig.ppm ./jpegtran -arithmetic -outfile testout_420_islow_ari.jpg $(srcdir)/testimages/testimgint.jpg
md5/md5cmp $(MD5_JPEG_PROG_ARI) testoutpa.jpg md5/md5cmp $(MD5_JPEG_420_ISLOW_ARI) testout_420_islow_ari.jpg
rm testout_420_islow_ari.jpg
# CC: YCC->RGB SAMP: fullsize FDCT: islow ENT: prog arith
./cjpeg -sample 1x1 -dct int -progressive -arithmetic -outfile testout_444_islow_progari.jpg $(srcdir)/testimages/testorig.ppm
md5/md5cmp $(MD5_JPEG_444_ISLOW_PROGARI) testout_444_islow_progari.jpg
rm testout_444_islow_progari.jpg
endif endif
if WITH_ARITH_DEC if WITH_ARITH_DEC
./djpeg -dct int -fast -ppm -outfile testoutari.ppm $(srcdir)/testimages/testimgari.jpg # CC: RGB->YCC SAMP: h2v2 merged IDCT: ifast ENT: arith
md5/md5cmp $(MD5_PPM_ARI) testoutari.ppm ./djpeg -fast -ppm -outfile testout_420m_ifast_ari.ppm $(srcdir)/testimages/testimgari.jpg
./jpegtran -outfile testouta.jpg $(srcdir)/testimages/testimgari.jpg md5/md5cmp $(MD5_PPM_420M_IFAST_ARI) testout_420m_ifast_ari.ppm
md5/md5cmp $(MD5_JPEG_INT) testouta.jpg rm testout_420m_ifast_ari.ppm
./jpegtran -outfile testout_420_islow.jpg $(srcdir)/testimages/testimgari.jpg
md5/md5cmp $(MD5_JPEG_420_ISLOW) testout_420_islow.jpg
rm testout_420_islow.jpg
endif endif
./cjpeg -dct int -progressive -outfile testoutp.jpg $(srcdir)/testimages/testorig.ppm
md5/md5cmp $(MD5_JPEG_PROG) testoutp.jpg # CC: YCC->RGB SAMP: h2v2 merged IDCT: 16x16 islow ENT: huff
./jpegtran -outfile testoutt.jpg testoutp.jpg ./djpeg -dct int -scale 2/1 -nosmooth -ppm -outfile testout_420m_islow_2_1.ppm $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_JPEG_INT) testoutt.jpg md5/md5cmp $(MD5_PPM_420M_ISLOW_2_1) testout_420m_islow_2_1.ppm
./jpegtran -crop 120x90+20+50 -transpose -perfect -outfile testoutcrop.jpg $(srcdir)/testimages/testorig.jpg rm testout_420m_islow_2_1.ppm
md5/md5cmp $(MD5_JPEG_CROP) testoutcrop.jpg # CC: YCC->RGB SAMP: h2v2 merged IDCT: 15x15 islow ENT: huff
./djpeg -dct int -scale 15/8 -nosmooth -ppm -outfile testout_420m_islow_15_8.ppm $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_PPM_420M_ISLOW_15_8) testout_420m_islow_15_8.ppm
rm testout_420m_islow_15_8.ppm
# CC: YCC->RGB SAMP: h2v2 merged IDCT: 13x13 islow ENT: huff
./djpeg -dct int -scale 13/8 -nosmooth -ppm -outfile testout_420m_islow_13_8.ppm $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_PPM_420M_ISLOW_13_8) testout_420m_islow_13_8.ppm
rm testout_420m_islow_13_8.ppm
# CC: YCC->RGB SAMP: h2v2 merged IDCT: 11x11 islow ENT: huff
./djpeg -dct int -scale 11/8 -nosmooth -ppm -outfile testout_420m_islow_11_8.ppm $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_PPM_420M_ISLOW_11_8) testout_420m_islow_11_8.ppm
rm testout_420m_islow_11_8.ppm
# CC: YCC->RGB SAMP: h2v2 merged IDCT: 9x9 islow ENT: huff
./djpeg -dct int -scale 9/8 -nosmooth -ppm -outfile testout_420m_islow_9_8.ppm $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_PPM_420M_ISLOW_9_8) testout_420m_islow_9_8.ppm
rm testout_420m_islow_9_8.ppm
# CC: YCC->RGB SAMP: h2v2 merged IDCT: 7x7 islow/14x14 islow ENT: huff
./djpeg -dct int -scale 7/8 -nosmooth -ppm -outfile testout_420m_islow_7_8.ppm $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_PPM_420M_ISLOW_7_8) testout_420m_islow_7_8.ppm
rm testout_420m_islow_7_8.ppm
# CC: YCC->RGB SAMP: h2v2 merged IDCT: 6x6 islow/12x12 islow ENT: huff
./djpeg -dct int -scale 3/4 -nosmooth -ppm -outfile testout_420m_islow_3_4.ppm $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_PPM_420M_ISLOW_3_4) testout_420m_islow_3_4.ppm
rm testout_420m_islow_3_4.ppm
# CC: YCC->RGB SAMP: h2v2 merged IDCT: 5x5 islow/10x10 islow ENT: huff
./djpeg -dct int -scale 5/8 -nosmooth -ppm -outfile testout_420m_islow_5_8.ppm $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_PPM_420M_ISLOW_5_8) testout_420m_islow_5_8.ppm
rm testout_420m_islow_5_8.ppm
# CC: YCC->RGB SAMP: h2v2 merged IDCT: 4x4 islow/8x8 islow ENT: huff
./djpeg -dct int -scale 1/2 -nosmooth -ppm -outfile testout_420m_islow_1_2.ppm $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_PPM_420M_ISLOW_1_2) testout_420m_islow_1_2.ppm
rm testout_420m_islow_1_2.ppm
# CC: YCC->RGB SAMP: h2v2 merged IDCT: 3x3 islow/6x6 islow ENT: huff
./djpeg -dct int -scale 3/8 -nosmooth -ppm -outfile testout_420m_islow_3_8.ppm $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_PPM_420M_ISLOW_3_8) testout_420m_islow_3_8.ppm
rm testout_420m_islow_3_8.ppm
# CC: YCC->RGB SAMP: h2v2 merged IDCT: 2x2 islow/4x4 islow ENT: huff
./djpeg -dct int -scale 1/4 -nosmooth -ppm -outfile testout_420m_islow_1_4.ppm $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_PPM_420M_ISLOW_1_4) testout_420m_islow_1_4.ppm
rm testout_420m_islow_1_4.ppm
# CC: YCC->RGB SAMP: h2v2 merged IDCT: 1x1 islow/2x2 islow ENT: huff
./djpeg -dct int -scale 1/8 -nosmooth -ppm -outfile testout_420m_islow_1_8.ppm $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_PPM_420M_ISLOW_1_8) testout_420m_islow_1_8.ppm
rm testout_420m_islow_1_8.ppm
# CC: YCC->RGB (dithered) SAMP: h2v2 fancy IDCT: islow ENT: huff
./djpeg -dct int -colors 256 -bmp -outfile testout_420_islow_256.bmp $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_BMP_420_ISLOW_256) testout_420_islow_256.bmp
rm testout_420_islow_256.bmp
# CC: YCC->RGB565 SAMP: h2v2 fancy IDCT: islow ENT: huff
./djpeg -dct int -rgb565 -dither none -bmp -outfile testout_420_islow_565.bmp $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_BMP_420_ISLOW_565) testout_420_islow_565.bmp
rm testout_420_islow_565.bmp
# CC: YCC->RGB565 (dithered) SAMP: h2v2 fancy IDCT: islow ENT: huff
./djpeg -dct int -rgb565 -bmp -outfile testout_420_islow_565D.bmp $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_BMP_420_ISLOW_565D) testout_420_islow_565D.bmp
rm testout_420_islow_565D.bmp
# CC: YCC->RGB565 SAMP: h2v2 merged IDCT: islow ENT: huff
./djpeg -dct int -nosmooth -rgb565 -dither none -bmp -outfile testout_420m_islow_565.bmp $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_BMP_420M_ISLOW_565) testout_420m_islow_565.bmp
rm testout_420m_islow_565.bmp
# CC: YCC->RGB565 (dithered) SAMP: h2v2 merged IDCT: islow ENT: huff
./djpeg -dct int -nosmooth -rgb565 -bmp -outfile testout_420m_islow_565D.bmp $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_BMP_420M_ISLOW_565D) testout_420m_islow_565D.bmp
rm testout_420m_islow_565D.bmp
./jpegtran -crop 120x90+20+50 -transpose -perfect -outfile testout_crop.jpg $(srcdir)/testimages/testorig.jpg
md5/md5cmp $(MD5_JPEG_CROP) testout_crop.jpg
rm testout_crop.jpg
testclean: testclean:

2
README
View File

@@ -62,7 +62,7 @@ OVERVIEW
This package contains C software to implement JPEG image encoding, decoding, This package contains C software to implement JPEG image encoding, decoding,
and transcoding. JPEG (pronounced "jay-peg") is a standardized compression and transcoding. JPEG (pronounced "jay-peg") is a standardized compression
method for full-color and gray-scale images. JPEG's strong suit is compressing method for full-color and grayscale images. JPEG's strong suit is compressing
photographic images or other types of images that have smooth color and photographic images or other types of images that have smooth color and
brightness transitions between neighboring pixels. Images with sharp lines or brightness transitions between neighboring pixels. Images with sharp lines or
other abrupt features may not compress well with JPEG, and a higher JPEG other abrupt features may not compress well with JPEG, and a higher JPEG

View File

@@ -184,7 +184,7 @@ AC_DEFUN([AC_CHECK_COMPATIBLE_ARM_ASSEMBLER_IFELSE],[
# AC_CHECK_COMPATIBLE_MIPSEL_ASSEMBLER_IFELSE # AC_CHECK_COMPATIBLE_MIPSEL_ASSEMBLER_IFELSE
# -------------------------- # --------------------------
# Test whether the assembler is suitable and supports MIPS instructions # Test whether the assembler is suitable and supports MIPS instructions
AC_DEFUN([AC_CHECK_COMPATIBLE_MIPSEL_ASSEMBLER_IFELSE],[ AC_DEFUN([AC_CHECK_COMPATIBLE_MIPS_ASSEMBLER_IFELSE],[
have_mips_dspr2=no have_mips_dspr2=no
ac_save_CFLAGS="$CFLAGS" ac_save_CFLAGS="$CFLAGS"
CFLAGS="$CCASFLAGS -mdspr2" CFLAGS="$CCASFLAGS -mdspr2"

View File

@@ -33,7 +33,7 @@
typedef enum { typedef enum {
#define JMESSAGE(code,string) code , #define JMESSAGE(code,string) code ,
#endif /* JMAKE_ENUM_LIST */ #endif /* JMAKE_ENUM_LIST */
@@ -62,7 +62,7 @@ JMESSAGE(JERR_GIF_IMAGENOTFOUND, "Too few images in GIF file")
JMESSAGE(JERR_GIF_NOT, "Not a GIF file") JMESSAGE(JERR_GIF_NOT, "Not a GIF file")
JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image") JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image")
JMESSAGE(JTRC_GIF_BADVERSION, JMESSAGE(JTRC_GIF_BADVERSION,
"Warning: unexpected GIF version number '%c%c%c'") "Warning: unexpected GIF version number '%c%c%c'")
JMESSAGE(JTRC_GIF_EXTENSION, "Ignoring GIF extension block of type 0x%02x") JMESSAGE(JTRC_GIF_EXTENSION, "Ignoring GIF extension block of type 0x%02x")
JMESSAGE(JTRC_GIF_NONSQUARE, "Caution: nonsquare pixels in input") JMESSAGE(JTRC_GIF_NONSQUARE, "Caution: nonsquare pixels in input")
JMESSAGE(JWRN_GIF_BADDATA, "Corrupt data in GIF file") JMESSAGE(JWRN_GIF_BADDATA, "Corrupt data in GIF file")
@@ -110,13 +110,13 @@ JMESSAGE(JERR_TGA_NOTCOMP, "Targa support was not compiled")
#endif /* TARGA_SUPPORTED */ #endif /* TARGA_SUPPORTED */
JMESSAGE(JERR_BAD_CMAP_FILE, JMESSAGE(JERR_BAD_CMAP_FILE,
"Color map file is invalid or of unsupported format") "Color map file is invalid or of unsupported format")
JMESSAGE(JERR_TOO_MANY_COLORS, JMESSAGE(JERR_TOO_MANY_COLORS,
"Output file format cannot handle %d colormap entries") "Output file format cannot handle %d colormap entries")
JMESSAGE(JERR_UNGETC_FAILED, "ungetc failed") JMESSAGE(JERR_UNGETC_FAILED, "ungetc failed")
#ifdef TARGA_SUPPORTED #ifdef TARGA_SUPPORTED
JMESSAGE(JERR_UNKNOWN_FORMAT, JMESSAGE(JERR_UNKNOWN_FORMAT,
"Unrecognized input file format --- perhaps you need -targa") "Unrecognized input file format --- perhaps you need -targa")
#else #else
JMESSAGE(JERR_UNKNOWN_FORMAT, "Unrecognized input file format") JMESSAGE(JERR_UNKNOWN_FORMAT, "Unrecognized input file format")
#endif #endif

View File

@@ -1,60 +1,22 @@
/* /*
* cdjpeg.c * cdjpeg.c
* *
* 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.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains common support routines used by the IJG application * This file contains common support routines used by the IJG application
* programs (cjpeg, djpeg, jpegtran). * programs (cjpeg, djpeg, jpegtran).
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include <ctype.h> /* to declare isupper(), tolower() */ #include <ctype.h> /* to declare isupper(), tolower() */
#ifdef NEED_SIGNAL_CATCHER
#include <signal.h> /* to declare signal() */
#endif
#ifdef USE_SETMODE #ifdef USE_SETMODE
#include <fcntl.h> /* to declare setmode()'s parameter macros */ #include <fcntl.h> /* to declare setmode()'s parameter macros */
/* If you have setmode() but not <io.h>, just delete this line: */ /* If you have setmode() but not <io.h>, just delete this line: */
#include <io.h> /* to declare setmode() */ #include <io.h> /* to declare setmode() */
#endif
/*
* Signal catcher to ensure that temporary files are removed before aborting.
* NB: for Amiga Manx C this is actually a global routine named _abort();
* we put "#define signal_catcher _abort" in jconfig.h. Talk about bogus...
*/
#ifdef NEED_SIGNAL_CATCHER
static j_common_ptr sig_cinfo;
void /* must be global for Manx C */
signal_catcher (int signum)
{
if (sig_cinfo != NULL) {
if (sig_cinfo->err != NULL) /* turn off trace output */
sig_cinfo->err->trace_level = 0;
jpeg_destroy(sig_cinfo); /* clean up memory allocation & temp files */
}
exit(EXIT_FAILURE);
}
GLOBAL(void)
enable_signal_catcher (j_common_ptr cinfo)
{
sig_cinfo = cinfo;
#ifdef SIGINT /* not all systems have SIGINT */
signal(SIGINT, signal_catcher);
#endif
#ifdef SIGTERM /* not all systems have SIGTERM */
signal(SIGTERM, signal_catcher);
#endif
}
#endif #endif
@@ -75,8 +37,8 @@ progress_monitor (j_common_ptr cinfo)
prog->percent_done = percent_done; prog->percent_done = percent_done;
if (total_passes > 1) { if (total_passes > 1) {
fprintf(stderr, "\rPass %d/%d: %3d%% ", fprintf(stderr, "\rPass %d/%d: %3d%% ",
prog->pub.completed_passes + prog->completed_extra_passes + 1, prog->pub.completed_passes + prog->completed_extra_passes + 1,
total_passes, percent_done); total_passes, percent_done);
} else { } else {
fprintf(stderr, "\r %3d%% ", percent_done); fprintf(stderr, "\r %3d%% ", percent_done);
} }
@@ -126,17 +88,17 @@ keymatch (char * arg, const char * keyword, int minchars)
while ((ca = *arg++) != '\0') { while ((ca = *arg++) != '\0') {
if ((ck = *keyword++) == '\0') if ((ck = *keyword++) == '\0')
return FALSE; /* arg longer than keyword, no good */ return FALSE; /* arg longer than keyword, no good */
if (isupper(ca)) /* force arg to lcase (assume ck is already) */ if (isupper(ca)) /* force arg to lcase (assume ck is already) */
ca = tolower(ca); ca = tolower(ca);
if (ca != ck) if (ca != ck)
return FALSE; /* no good */ return FALSE; /* no good */
nmatched++; /* count matched characters */ nmatched++; /* count matched characters */
} }
/* reached end of argument; fail if it's too short for unique abbrev */ /* reached end of argument; fail if it's too short for unique abbrev */
if (nmatched < minchars) if (nmatched < minchars)
return FALSE; return FALSE;
return TRUE; /* A-OK */ return TRUE; /* A-OK */
} }
@@ -150,10 +112,10 @@ read_stdin (void)
{ {
FILE * input_file = stdin; FILE * input_file = stdin;
#ifdef USE_SETMODE /* need to hack file mode? */ #ifdef USE_SETMODE /* need to hack file mode? */
setmode(fileno(stdin), O_BINARY); setmode(fileno(stdin), O_BINARY);
#endif #endif
#ifdef USE_FDOPEN /* need to re-open in binary mode? */ #ifdef USE_FDOPEN /* need to re-open in binary mode? */
if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) { if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
fprintf(stderr, "Cannot reopen stdin\n"); fprintf(stderr, "Cannot reopen stdin\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@@ -168,10 +130,10 @@ write_stdout (void)
{ {
FILE * output_file = stdout; FILE * output_file = stdout;
#ifdef USE_SETMODE /* need to hack file mode? */ #ifdef USE_SETMODE /* need to hack file mode? */
setmode(fileno(stdout), O_BINARY); setmode(fileno(stdout), O_BINARY);
#endif #endif
#ifdef USE_FDOPEN /* need to re-open in binary mode? */ #ifdef USE_FDOPEN /* need to re-open in binary mode? */
if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) { if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {
fprintf(stderr, "Cannot reopen stdout\n"); fprintf(stderr, "Cannot reopen stdout\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

144
cdjpeg.h
View File

@@ -1,8 +1,10 @@
/* /*
* cdjpeg.h * cdjpeg.h
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1997, Thomas G. Lane. * Copyright (C) 1994-1997, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* mozjpeg Modifications: * mozjpeg Modifications:
* Copyright (C) 2014, Mozilla Corporation. * Copyright (C) 2014, Mozilla Corporation.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
@@ -11,12 +13,12 @@
* cjpeg and djpeg. It is NOT used by the core JPEG library. * cjpeg and djpeg. It is NOT used by the core JPEG library.
*/ */
#define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */ #define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */
#define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */ #define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jerror.h" /* get library error codes too */ #include "jerror.h" /* get library error codes too */
#include "cderror.h" /* get application-specific error codes */ #include "cderror.h" /* get application-specific error codes */
#define JPEG_RAW_READER 0 #define JPEG_RAW_READER 0
@@ -27,12 +29,9 @@
typedef struct cjpeg_source_struct * cjpeg_source_ptr; typedef struct cjpeg_source_struct * cjpeg_source_ptr;
struct cjpeg_source_struct { struct cjpeg_source_struct {
JMETHOD(void, start_input, (j_compress_ptr cinfo, void (*start_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
cjpeg_source_ptr sinfo)); JDIMENSION (*get_pixel_rows) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo, void (*finish_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
cjpeg_source_ptr sinfo));
JMETHOD(void, finish_input, (j_compress_ptr cinfo,
cjpeg_source_ptr sinfo));
FILE *input_file; FILE *input_file;
@@ -58,15 +57,12 @@ struct djpeg_dest_struct {
/* start_output is called after jpeg_start_decompress finishes. /* start_output is called after jpeg_start_decompress finishes.
* The color map will be ready at this time, if one is needed. * The color map will be ready at this time, if one is needed.
*/ */
JMETHOD(void, start_output, (j_decompress_ptr cinfo, void (*start_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo);
djpeg_dest_ptr dinfo));
/* Emit the specified number of pixel rows from the buffer. */ /* Emit the specified number of pixel rows from the buffer. */
JMETHOD(void, put_pixel_rows, (j_decompress_ptr cinfo, void (*put_pixel_rows) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
djpeg_dest_ptr dinfo, JDIMENSION rows_supplied);
JDIMENSION rows_supplied));
/* Finish up at the end of the image. */ /* Finish up at the end of the image. */
JMETHOD(void, finish_output, (j_decompress_ptr cinfo, void (*finish_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo);
djpeg_dest_ptr dinfo));
/* Target file spec; filled in by djpeg.c after object is created. */ /* Target file spec; filled in by djpeg.c after object is created. */
FILE * output_file; FILE * output_file;
@@ -89,9 +85,9 @@ struct djpeg_dest_struct {
*/ */
struct cdjpeg_progress_mgr { struct cdjpeg_progress_mgr {
struct jpeg_progress_mgr pub; /* fields known to JPEG library */ struct jpeg_progress_mgr pub; /* fields known to JPEG library */
int completed_extra_passes; /* extra passes completed */ int completed_extra_passes; /* extra passes completed */
int total_extra_passes; /* total extra */ int total_extra_passes; /* total extra */
/* last printed percentage stored here to avoid multiple printouts */ /* last printed percentage stored here to avoid multiple printouts */
int percent_done; int percent_done;
}; };
@@ -99,101 +95,61 @@ struct cdjpeg_progress_mgr {
typedef struct cdjpeg_progress_mgr * cd_progress_ptr; typedef struct cdjpeg_progress_mgr * cd_progress_ptr;
/* Short forms of external names for systems with brain-damaged linkers. */
#ifdef NEED_SHORT_EXTERNAL_NAMES
#define jinit_read_bmp jIRdBMP
#define jinit_write_bmp jIWrBMP
#define jinit_read_jpeg jIRdJPG
#define jinit_read_gif jIRdGIF
#define jinit_write_gif jIWrGIF
#define jinit_read_ppm jIRdPPM
#define jinit_write_ppm jIWrPPM
#define jinit_read_rle jIRdRLE
#define jinit_write_rle jIWrRLE
#define jinit_read_targa jIRdTarga
#define jinit_write_targa jIWrTarga
#define read_quant_tables RdQTables
#define read_scan_script RdScnScript
#define set_quality_ratings SetQRates
#define set_quant_slots SetQSlots
#define set_sample_factors SetSFacts
#define read_color_map RdCMap
#define enable_signal_catcher EnSigCatcher
#define start_progress_monitor StProgMon
#define end_progress_monitor EnProgMon
#define read_stdin RdStdin
#define write_stdout WrStdout
#endif /* NEED_SHORT_EXTERNAL_NAMES */
/* Module selection routines for I/O modules. */ /* Module selection routines for I/O modules. */
EXTERN(cjpeg_source_ptr) jinit_read_bmp JPP((j_compress_ptr cinfo)); EXTERN(cjpeg_source_ptr) jinit_read_bmp (j_compress_ptr cinfo);
EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo, EXTERN(djpeg_dest_ptr) jinit_write_bmp (j_decompress_ptr cinfo,
boolean is_os2)); boolean is_os2);
EXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo)); EXTERN(cjpeg_source_ptr) jinit_read_gif (j_compress_ptr cinfo);
EXTERN(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo)); EXTERN(djpeg_dest_ptr) jinit_write_gif (j_decompress_ptr cinfo);
EXTERN(cjpeg_source_ptr) jinit_read_jpeg JPP((j_compress_ptr cinfo)); EXTERN(cjpeg_source_ptr) jinit_read_jpeg (j_compress_ptr cinfo);
EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo)); EXTERN(cjpeg_source_ptr) jinit_read_ppm (j_compress_ptr cinfo);
EXTERN(djpeg_dest_ptr) jinit_write_ppm JPP((j_decompress_ptr cinfo)); EXTERN(djpeg_dest_ptr) jinit_write_ppm (j_decompress_ptr cinfo);
EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo)); EXTERN(cjpeg_source_ptr) jinit_read_rle (j_compress_ptr cinfo);
EXTERN(djpeg_dest_ptr) jinit_write_rle JPP((j_decompress_ptr cinfo)); EXTERN(djpeg_dest_ptr) jinit_write_rle (j_decompress_ptr cinfo);
EXTERN(cjpeg_source_ptr) jinit_read_targa JPP((j_compress_ptr cinfo)); EXTERN(cjpeg_source_ptr) jinit_read_targa (j_compress_ptr cinfo);
EXTERN(djpeg_dest_ptr) jinit_write_targa JPP((j_decompress_ptr cinfo)); EXTERN(djpeg_dest_ptr) jinit_write_targa (j_decompress_ptr cinfo);
/* cjpeg support routines (in rdswitch.c) */ /* cjpeg support routines (in rdswitch.c) */
EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename, EXTERN(boolean) read_quant_tables (j_compress_ptr cinfo, char * filename,
boolean force_baseline)); boolean force_baseline);
EXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename)); EXTERN(boolean) read_scan_script (j_compress_ptr cinfo, char * filename);
EXTERN(boolean) set_quality_ratings JPP((j_compress_ptr cinfo, char *arg, EXTERN(boolean) set_quality_ratings (j_compress_ptr cinfo, char *arg,
boolean force_baseline)); boolean force_baseline);
EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg)); EXTERN(boolean) set_quant_slots (j_compress_ptr cinfo, char *arg);
EXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg)); EXTERN(boolean) set_sample_factors (j_compress_ptr cinfo, char *arg);
/* djpeg support routines (in rdcolmap.c) */ /* djpeg support routines (in rdcolmap.c) */
EXTERN(void) read_color_map JPP((j_decompress_ptr cinfo, FILE * infile)); EXTERN(void) read_color_map (j_decompress_ptr cinfo, FILE * infile);
/* common support routines (in cdjpeg.c) */ /* common support routines (in cdjpeg.c) */
EXTERN(void) enable_signal_catcher JPP((j_common_ptr cinfo)); EXTERN(void) enable_signal_catcher (j_common_ptr cinfo);
EXTERN(void) start_progress_monitor JPP((j_common_ptr cinfo, EXTERN(void) start_progress_monitor (j_common_ptr cinfo,
cd_progress_ptr progress)); cd_progress_ptr progress);
EXTERN(void) end_progress_monitor JPP((j_common_ptr cinfo)); EXTERN(void) end_progress_monitor (j_common_ptr cinfo);
EXTERN(boolean) keymatch JPP((char * arg, const char * keyword, int minchars)); EXTERN(boolean) keymatch (char * arg, const char * keyword, int minchars);
EXTERN(FILE *) read_stdin JPP((void)); EXTERN(FILE *) read_stdin (void);
EXTERN(FILE *) write_stdout JPP((void)); EXTERN(FILE *) write_stdout (void);
/* miscellaneous useful macros */ /* miscellaneous useful macros */
#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
#define READ_BINARY "r" #define READ_BINARY "r"
#define WRITE_BINARY "w" #define WRITE_BINARY "w"
#else #else
#ifdef VMS /* VMS is very nonstandard */ #define READ_BINARY "rb"
#define READ_BINARY "rb", "ctx=stm" #define WRITE_BINARY "wb"
#define WRITE_BINARY "wb", "ctx=stm"
#else /* standard ANSI-compliant case */
#define READ_BINARY "rb"
#define WRITE_BINARY "wb"
#endif
#endif #endif
#ifndef EXIT_FAILURE /* define exit() codes if not provided */ #ifndef EXIT_FAILURE /* define exit() codes if not provided */
#define EXIT_FAILURE 1 #define EXIT_FAILURE 1
#endif #endif
#ifndef EXIT_SUCCESS #ifndef EXIT_SUCCESS
#ifdef VMS
#define EXIT_SUCCESS 1 /* VMS is very nonstandard */
#else
#define EXIT_SUCCESS 0 #define EXIT_SUCCESS 0
#endif #endif
#endif
#ifndef EXIT_WARNING #ifndef EXIT_WARNING
#ifdef VMS
#define EXIT_WARNING 1 /* VMS is very nonstandard */
#else
#define EXIT_WARNING 2 #define EXIT_WARNING 2
#endif #endif
#endif

View File

@@ -16,7 +16,7 @@ cjpeg \- compress an image file to a JPEG file
compresses the named image file, or the standard input if no file is compresses the named image file, or the standard input if no file is
named, and produces a JPEG/JFIF file on the standard output. named, and produces a JPEG/JFIF file on the standard output.
The currently supported input file formats are: PPM (PBMPLUS color The currently supported input file formats are: PPM (PBMPLUS color
format), PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster format), PGM (PBMPLUS grayscale format), BMP, Targa, and RLE (Utah Raster
Toolkit format). (RLE is supported only if the URT library is available.) Toolkit format). (RLE is supported only if the URT library is available.)
.SH OPTIONS .SH OPTIONS
All switch names may be abbreviated; for example, All switch names may be abbreviated; for example,
@@ -176,11 +176,13 @@ With quality=97, for instance, the fast method incurs generally about a 1-3 dB
loss (in PSNR) relative to the int method, but this can be larger for some loss (in PSNR) relative to the int method, but this can be larger for some
images. Do not use the fast method with quality levels above 97. The images. Do not use the fast method with quality levels above 97. The
algorithm often degenerates at quality=98 and above and can actually produce a algorithm often degenerates at quality=98 and above and can actually produce a
more lossy image than if lower quality levels had been used. more lossy image than if lower quality levels had been used. Also, in
libjpeg-turbo, the fast method is not fully accelerated for quality levels
above 97, so it will be slower than the int method.
.TP .TP
.B \-dct float .B \-dct float
Use floating-point DCT method. Use floating-point DCT method.
The float method is mostly a legacy feature. It does not produce significantly The float method is mainly a legacy feature. It does not produce significantly
more accurate results than the int method, and it is much slower. The float more accurate results than the int method, and it is much slower. The float
method may also give different results on different machines due to varying method may also give different results on different machines due to varying
roundoff behavior, whereas the integer methods should give the same results on roundoff behavior, whereas the integer methods should give the same results on

179
cjpeg.c
View File

@@ -15,8 +15,8 @@
* *
* Two different command line styles are permitted, depending on the * Two different command line styles are permitted, depending on the
* compile-time switch TWO_FILE_COMMANDLINE: * compile-time switch TWO_FILE_COMMANDLINE:
* cjpeg [options] inputfile outputfile * cjpeg [options] inputfile outputfile
* cjpeg [options] [inputfile] * cjpeg [options] [inputfile]
* In the second style, output is always to standard output, which you'd * In the second style, output is always to standard output, which you'd
* normally redirect to a file or pipe to some other program. Input is * normally redirect to a file or pipe to some other program. Input is
* either from a named file or from standard input (typically redirected). * either from a named file or from standard input (typically redirected).
@@ -24,28 +24,28 @@
* don't support pipes. Also, you MUST use the first style if your system * don't support pipes. Also, you MUST use the first style if your system
* doesn't do binary I/O to stdin/stdout. * doesn't do binary I/O to stdin/stdout.
* To simplify script writing, the "-outfile" switch is provided. The syntax * To simplify script writing, the "-outfile" switch is provided. The syntax
* cjpeg [options] -outfile outputfile inputfile * cjpeg [options] -outfile outputfile inputfile
* works regardless of which command line style is used. * works regardless of which command line style is used.
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include "jversion.h" /* for version message */ #include "jversion.h" /* for version message */
#include "config.h" #include "jconfigint.h"
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ #ifdef USE_CCOMMAND /* command-line reader for Macintosh */
#ifdef __MWERKS__ #ifdef __MWERKS__
#include <SIOUX.h> /* Metrowerks needs this */ #include <SIOUX.h> /* Metrowerks needs this */
#include <console.h> /* ... and this */ #include <console.h> /* ... and this */
#endif #endif
#ifdef THINK_C #ifdef THINK_C
#include <console.h> /* Think declares it here */ #include <console.h> /* Think declares it here */
#endif #endif
#endif #endif
/* Create the add-on message string table. */ /* Create the add-on message string table. */
#define JMESSAGE(code,string) string , #define JMESSAGE(code,string) string ,
static const char * const cdjpeg_message_table[] = { static const char * const cdjpeg_message_table[] = {
#include "cderror.h" #include "cderror.h"
@@ -79,7 +79,7 @@ static const char * const cdjpeg_message_table[] = {
* seldom-used ID field), so we provide a switch to force Targa input mode. * seldom-used ID field), so we provide a switch to force Targa input mode.
*/ */
static boolean is_targa; /* records user -targa switch */ static boolean is_targa; /* records user -targa switch */
static boolean is_jpeg; static boolean is_jpeg;
LOCAL(cjpeg_source_ptr) LOCAL(cjpeg_source_ptr)
@@ -129,7 +129,7 @@ select_file_type (j_compress_ptr cinfo, FILE * infile)
break; break;
} }
return NULL; /* suppress compiler warnings */ return NULL; /* suppress compiler warnings */
} }
@@ -142,8 +142,8 @@ select_file_type (j_compress_ptr cinfo, FILE * infile)
*/ */
static const char * progname; /* program name for error messages */ static const char * progname; /* program name for error messages */
static char * outfilename; /* for -outfile switch */ static char * outfilename; /* for -outfile switch */
boolean memdst; /* for -memdst switch */ boolean memdst; /* for -memdst switch */
@@ -185,15 +185,15 @@ usage (void)
#endif #endif
#ifdef DCT_ISLOW_SUPPORTED #ifdef DCT_ISLOW_SUPPORTED
fprintf(stderr, " -dct int Use integer DCT method%s\n", fprintf(stderr, " -dct int Use integer DCT method%s\n",
(JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
#endif #endif
#ifdef DCT_IFAST_SUPPORTED #ifdef DCT_IFAST_SUPPORTED
fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n", fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
(JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
#endif #endif
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
fprintf(stderr, " -dct float Use floating-point DCT method%s\n", fprintf(stderr, " -dct float Use floating-point DCT method%s\n",
(JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
#endif #endif
fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n"); fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
#ifdef INPUT_SMOOTHING_SUPPORTED #ifdef INPUT_SMOOTHING_SUPPORTED
@@ -219,7 +219,7 @@ usage (void)
LOCAL(int) LOCAL(int)
parse_switches (j_compress_ptr cinfo, int argc, char **argv, parse_switches (j_compress_ptr cinfo, int argc, char **argv,
int last_file_arg_seen, boolean for_real) int last_file_arg_seen, boolean for_real)
/* Parse optional switches. /* Parse optional switches.
* Returns argv[] index of first file-name argument (== argc if none). * Returns argv[] index of first file-name argument (== argc if none).
* Any file names with indexes <= last_file_arg_seen are ignored; * Any file names with indexes <= last_file_arg_seen are ignored;
@@ -233,15 +233,15 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
char * arg; char * arg;
boolean force_baseline; boolean force_baseline;
boolean simple_progressive; boolean simple_progressive;
char * qualityarg = NULL; /* saves -quality parm if any */ char * qualityarg = NULL; /* saves -quality parm if any */
char * qtablefile = NULL; /* saves -qtables filename if any */ char * qtablefile = NULL; /* saves -qtables filename if any */
char * qslotsarg = NULL; /* saves -qslots parm if any */ char * qslotsarg = NULL; /* saves -qslots parm if any */
char * samplearg = NULL; /* saves -sample parm if any */ char * samplearg = NULL; /* saves -sample parm if any */
char * scansarg = NULL; /* saves -scans parm if any */ char * scansarg = NULL; /* saves -scans parm if any */
/* Set up default JPEG parameters. */ /* Set up default JPEG parameters. */
force_baseline = FALSE; /* by default, allow 16-bit quantizers */ force_baseline = FALSE; /* by default, allow 16-bit quantizers */
#ifdef C_PROGRESSIVE_SUPPORTED #ifdef C_PROGRESSIVE_SUPPORTED
simple_progressive = cinfo->num_scans == 0 ? FALSE : TRUE; simple_progressive = cinfo->num_scans == 0 ? FALSE : TRUE;
#else #else
@@ -259,12 +259,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
if (*arg != '-') { if (*arg != '-') {
/* Not a switch, must be a file name argument */ /* Not a switch, must be a file name argument */
if (argn <= last_file_arg_seen) { if (argn <= last_file_arg_seen) {
outfilename = NULL; /* -outfile applies to just one input file */ outfilename = NULL; /* -outfile applies to just one input file */
continue; /* ignore this name if previously processed */ continue; /* ignore this name if previously processed */
} }
break; /* else done parsing switches */ break; /* else done parsing switches */
} }
arg++; /* advance past switch marker character */ arg++; /* advance past switch marker character */
if (keymatch(arg, "arithmetic", 1)) { if (keymatch(arg, "arithmetic", 1)) {
/* Use arithmetic coding. */ /* Use arithmetic coding. */
@@ -272,7 +272,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
cinfo->arith_code = TRUE; cinfo->arith_code = TRUE;
#else #else
fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
@@ -284,17 +284,17 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
/* Select DCT algorithm. */ /* Select DCT algorithm. */
if (++argn >= argc) { /* advance to next argument */ if (++argn >= argc) { /* advance to next argument */
fprintf(stderr, "%s: missing argument for dct\n", progname); fprintf(stderr, "%s: missing argument for dct\n", progname);
usage(); usage();
} }
if (keymatch(argv[argn], "int", 1)) { if (keymatch(argv[argn], "int", 1)) {
cinfo->dct_method = JDCT_ISLOW; cinfo->dct_method = JDCT_ISLOW;
} else if (keymatch(argv[argn], "fast", 2)) { } else if (keymatch(argv[argn], "fast", 2)) {
cinfo->dct_method = JDCT_IFAST; cinfo->dct_method = JDCT_IFAST;
} else if (keymatch(argv[argn], "float", 2)) { } else if (keymatch(argv[argn], "float", 2)) {
cinfo->dct_method = JDCT_FLOAT; cinfo->dct_method = JDCT_FLOAT;
} else } else
fprintf(stderr, "%s: invalid argument for dct\n", progname); fprintf(stderr, "%s: invalid argument for dct\n", progname);
usage(); usage();
} else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
/* Enable debug printouts. */ /* Enable debug printouts. */
@@ -302,12 +302,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
static boolean printed_version = FALSE; static boolean printed_version = FALSE;
if (! printed_version) { if (! printed_version) {
fprintf(stderr, "%s version %s (build %s)\n", fprintf(stderr, "%s version %s (build %s)\n",
PACKAGE_NAME, VERSION, BUILD); PACKAGE_NAME, VERSION, BUILD);
fprintf(stderr, "%s\n\n", JCOPYRIGHT); fprintf(stderr, "%s\n\n", JCOPYRIGHT);
fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n", fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
JVERSION); JVERSION);
printed_version = TRUE; printed_version = TRUE;
} }
cinfo->err->trace_level++; cinfo->err->trace_level++;
@@ -341,12 +341,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
long lval; long lval;
char ch = 'x'; char ch = 'x';
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
usage(); usage();
if (ch == 'm' || ch == 'M') if (ch == 'm' || ch == 'M')
lval *= 1000L; lval *= 1000L;
cinfo->mem->max_memory_to_use = lval * 1000L; cinfo->mem->max_memory_to_use = lval * 1000L;
} else if (keymatch(arg, "multidcscan", 3)) { } else if (keymatch(arg, "multidcscan", 3)) {
@@ -358,7 +358,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
cinfo->optimize_coding = TRUE; cinfo->optimize_coding = TRUE;
#else #else
fprintf(stderr, "%s: sorry, entropy optimization was not compiled in\n", fprintf(stderr, "%s: sorry, entropy optimization was not compiled in\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
@@ -366,9 +366,9 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
/* Set output file name. */ /* Set output file name. */
if (++argn >= argc) { /* advance to next argument */ if (++argn >= argc) { /* advance to next argument */
fprintf(stderr, "%s: missing argument for outfile\n", progname); fprintf(stderr, "%s: missing argument for outfile\n", progname);
usage(); usage();
} }
outfilename = argv[argn]; /* save it away for later use */ outfilename = argv[argn]; /* save it away for later use */
} else if (keymatch(arg, "progressive", 1)) { } else if (keymatch(arg, "progressive", 1)) {
/* Select simple progressive mode. */ /* Select simple progressive mode. */
@@ -377,7 +377,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
/* We must postpone execution until num_components is known. */ /* We must postpone execution until num_components is known. */
#else #else
fprintf(stderr, "%s: sorry, progressive output was not compiled in\n", fprintf(stderr, "%s: sorry, progressive output was not compiled in\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
@@ -395,14 +395,14 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
/* Quality ratings (quantization table scaling factors). */ /* Quality ratings (quantization table scaling factors). */
if (++argn >= argc) { /* advance to next argument */ if (++argn >= argc) { /* advance to next argument */
fprintf(stderr, "%s: missing argument for quality\n", progname); fprintf(stderr, "%s: missing argument for quality\n", progname);
usage(); usage();
} }
qualityarg = argv[argn]; qualityarg = argv[argn];
} else if (keymatch(arg, "qslots", 2)) { } else if (keymatch(arg, "qslots", 2)) {
/* Quantization table slot numbers. */ /* Quantization table slot numbers. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
qslotsarg = argv[argn]; qslotsarg = argv[argn];
/* Must delay setting qslots until after we have processed any /* Must delay setting qslots until after we have processed any
* colorspace-determining switches, since jpeg_set_colorspace sets * colorspace-determining switches, since jpeg_set_colorspace sets
@@ -411,8 +411,8 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "qtables", 2)) { } else if (keymatch(arg, "qtables", 2)) {
/* Quantization tables fetched from file. */ /* Quantization tables fetched from file. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
qtablefile = argv[argn]; qtablefile = argv[argn];
/* We postpone actually reading the file in case -quality comes later. */ /* We postpone actually reading the file in case -quality comes later. */
@@ -421,18 +421,18 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
long lval; long lval;
char ch = 'x'; char ch = 'x';
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
usage(); usage();
if (lval < 0 || lval > 65535L) if (lval < 0 || lval > 65535L)
usage(); usage();
if (ch == 'b' || ch == 'B') { if (ch == 'b' || ch == 'B') {
cinfo->restart_interval = (unsigned int) lval; cinfo->restart_interval = (unsigned int) lval;
cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
} else { } else {
cinfo->restart_in_rows = (int) lval; cinfo->restart_in_rows = (int) lval;
/* restart_interval will be computed during startup */ /* restart_interval will be computed during startup */
} }
} else if (keymatch(arg, "revert", 3)) { } else if (keymatch(arg, "revert", 3)) {
@@ -442,8 +442,8 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "sample", 2)) { } else if (keymatch(arg, "sample", 2)) {
/* Set sampling factors. */ /* Set sampling factors. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
samplearg = argv[argn]; samplearg = argv[argn];
/* Must delay setting sample factors until after we have processed any /* Must delay setting sample factors until after we have processed any
* colorspace-determining switches, since jpeg_set_colorspace sets * colorspace-determining switches, since jpeg_set_colorspace sets
@@ -453,13 +453,13 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "scans", 4)) { } else if (keymatch(arg, "scans", 4)) {
/* Set scan script. */ /* Set scan script. */
#ifdef C_MULTISCAN_FILES_SUPPORTED #ifdef C_MULTISCAN_FILES_SUPPORTED
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
scansarg = argv[argn]; scansarg = argv[argn];
/* We must postpone reading the file in case -progressive appears. */ /* We must postpone reading the file in case -progressive appears. */
#else #else
fprintf(stderr, "%s: sorry, multi-scan output was not compiled in\n", fprintf(stderr, "%s: sorry, multi-scan output was not compiled in\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
@@ -467,12 +467,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
/* Set input smoothing factor. */ /* Set input smoothing factor. */
int val; int val;
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%d", &val) != 1) if (sscanf(argv[argn], "%d", &val) != 1)
usage(); usage();
if (val < 0 || val > 100) if (val < 0 || val > 100)
usage(); usage();
cinfo->smoothing_factor = val; cinfo->smoothing_factor = val;
} else if (keymatch(arg, "targa", 1)) { } else if (keymatch(arg, "targa", 1)) {
@@ -513,7 +513,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
} else { } else {
fprintf(stderr, "%s: unknown option '%s'\n", progname, arg); fprintf(stderr, "%s: unknown option '%s'\n", progname, arg);
usage(); /* bogus switch */ usage(); /* bogus switch */
} }
} }
@@ -523,41 +523,41 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
/* Set quantization tables for selected quality. */ /* Set quantization tables for selected quality. */
/* Some or all may be overridden if -qtables is present. */ /* Some or all may be overridden if -qtables is present. */
if (qualityarg != NULL) /* process -quality if it was present */ if (qualityarg != NULL) /* process -quality if it was present */
if (! set_quality_ratings(cinfo, qualityarg, force_baseline)) { if (! set_quality_ratings(cinfo, qualityarg, force_baseline)) {
fprintf(stderr, "%s: can't set quality ratings\n", progname); fprintf(stderr, "%s: can't set quality ratings\n", progname);
usage(); usage();
} }
if (qtablefile != NULL) /* process -qtables if it was present */ if (qtablefile != NULL) /* process -qtables if it was present */
if (! read_quant_tables(cinfo, qtablefile, force_baseline)) { if (! read_quant_tables(cinfo, qtablefile, force_baseline)) {
fprintf(stderr, "%s: can't read qtable file\n", progname); fprintf(stderr, "%s: can't read qtable file\n", progname);
usage(); usage();
} }
if (qslotsarg != NULL) /* process -qslots if it was present */ if (qslotsarg != NULL) /* process -qslots if it was present */
if (! set_quant_slots(cinfo, qslotsarg)) if (! set_quant_slots(cinfo, qslotsarg))
usage(); usage();
if (samplearg != NULL) /* process -sample if it was present */ if (samplearg != NULL) /* process -sample if it was present */
if (! set_sample_factors(cinfo, samplearg)) { if (! set_sample_factors(cinfo, samplearg)) {
fprintf(stderr, "%s: can't set sample factors\n", progname); fprintf(stderr, "%s: can't set sample factors\n", progname);
usage(); usage();
} }
#ifdef C_PROGRESSIVE_SUPPORTED #ifdef C_PROGRESSIVE_SUPPORTED
if (simple_progressive) /* process -progressive; -scans can override */ if (simple_progressive) /* process -progressive; -scans can override */
jpeg_simple_progression(cinfo); jpeg_simple_progression(cinfo);
#endif #endif
#ifdef C_MULTISCAN_FILES_SUPPORTED #ifdef C_MULTISCAN_FILES_SUPPORTED
if (scansarg != NULL) /* process -scans if it was present */ if (scansarg != NULL) /* process -scans if it was present */
if (! read_scan_script(cinfo, scansarg)) if (! read_scan_script(cinfo, scansarg))
usage(); usage();
#endif #endif
} }
return argn; /* return index of next arg (file name) */ return argn; /* return index of next arg (file name) */
} }
@@ -588,7 +588,7 @@ main (int argc, char **argv)
progname = argv[0]; progname = argv[0];
if (progname == NULL || progname[0] == 0) if (progname == NULL || progname[0] == 0)
progname = "cjpeg"; /* in case C library doesn't provide it */ progname = "cjpeg"; /* in case C library doesn't provide it */
/* Initialize the JPEG compression object with default error handling. */ /* Initialize the JPEG compression object with default error handling. */
cinfo.err = jpeg_std_error(&jerr); cinfo.err = jpeg_std_error(&jerr);
@@ -598,11 +598,6 @@ main (int argc, char **argv)
jerr.first_addon_message = JMSG_FIRSTADDONCODE; jerr.first_addon_message = JMSG_FIRSTADDONCODE;
jerr.last_addon_message = JMSG_LASTADDONCODE; jerr.last_addon_message = JMSG_LASTADDONCODE;
/* Now safe to enable signal catcher. */
#ifdef NEED_SIGNAL_CATCHER
enable_signal_catcher((j_common_ptr) &cinfo);
#endif
/* Initialize JPEG parameters. /* Initialize JPEG parameters.
* Much of this may be overridden later. * Much of this may be overridden later.
* In particular, we don't yet know the input file's color space, * In particular, we don't yet know the input file's color space,
@@ -684,7 +679,7 @@ main (int argc, char **argv)
#if JPEG_RAW_READER #if JPEG_RAW_READER
if (!is_jpeg) if (!is_jpeg)
#endif #endif
jpeg_default_colorspace(&cinfo); jpeg_default_colorspace(&cinfo);
/* Adjust default compression parameters by re-parsing the options */ /* Adjust default compression parameters by re-parsing the options */
file_index = parse_switches(&cinfo, argc, argv, 0, TRUE); file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
@@ -740,7 +735,7 @@ main (int argc, char **argv)
(void) jpeg_write_raw_data(&cinfo, src_mgr->plane_pointer, num_scanlines); (void) jpeg_write_raw_data(&cinfo, src_mgr->plane_pointer, num_scanlines);
else else
#endif #endif
(void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines); (void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
} }
/* Finish compression and release memory */ /* Finish compression and release memory */
@@ -766,5 +761,5 @@ main (int argc, char **argv)
/* All done. */ /* All done. */
exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
return 0; /* suppress no-return-value warnings */ return 0; /* suppress no-return-value warnings */
} }

View File

@@ -1,7 +1,9 @@
IJG JPEG LIBRARY: CODING RULES IJG JPEG LIBRARY: CODING RULES
This file was part of the Independent JPEG Group's software:
Copyright (C) 1991-1996, Thomas G. Lane. Copyright (C) 1991-1996, Thomas G. Lane.
This file is part of the Independent JPEG Group's software. It was modified by The libjpeg-turbo Project to include only information
relevant to libjpeg-turbo.
For conditions of distribution and use, see the accompanying README file. For conditions of distribution and use, see the accompanying README file.
@@ -21,33 +23,18 @@ Block comments should be laid out thusly:
*/ */
We indent statements in K&R style, e.g., We indent statements in K&R style, e.g.,
if (test) { if (test) {
then-part; then-part;
} else { } else {
else-part; else-part;
} }
with two spaces per indentation level. (This indentation convention is with two spaces per indentation level. (This indentation convention is
handled automatically by GNU Emacs and many other text editors.) handled automatically by GNU Emacs and many other text editors.)
Multi-word names should be written in lower case with underscores, e.g., Multi-word names should be written in lower case with underscores, e.g.,
multi_word_name (not multiWordName). Preprocessor symbols and enum constants multi_word_name (not multiWordName). Preprocessor symbols and enum constants
are similar but upper case (MULTI_WORD_NAME). Names should be unique within are similar but upper case (MULTI_WORD_NAME). Names should be unique within
the first fifteen characters. (On some older systems, global names must be the first fifteen characters.
unique within six characters. We accommodate this without cluttering the
source code by using macros to substitute shorter names.)
We use function prototypes everywhere; we rely on automatic source code
transformation to feed prototype-less C compilers. Transformation is done
by the simple and portable tool 'ansi2knr.c' (courtesy of Ghostscript).
ansi2knr is not very bright, so it imposes a format requirement on function
declarations: the function name MUST BEGIN IN COLUMN 1. Thus all functions
should be written in the following style:
LOCAL(int *)
function_name (int a, char *b)
{
code...
}
Note that each function definition must begin with GLOBAL(type), LOCAL(type), Note that each function definition must begin with GLOBAL(type), LOCAL(type),
or METHODDEF(type). These macros expand to "static type" or just "type" as or METHODDEF(type). These macros expand to "static type" or just "type" as
@@ -55,32 +42,8 @@ appropriate. They provide a readable indication of the routine's usage and
can readily be changed for special needs. (For instance, special linkage can readily be changed for special needs. (For instance, special linkage
keywords can be inserted for use in Windows DLLs.) keywords can be inserted for use in Windows DLLs.)
ansi2knr does not transform method declarations (function pointers in A similar solution is used for external function declarations (see the EXTERN
structs). We handle these with a macro JMETHOD, defined as macro.)
#ifdef HAVE_PROTOTYPES
#define JMETHOD(type,methodname,arglist) type (*methodname) arglist
#else
#define JMETHOD(type,methodname,arglist) type (*methodname) ()
#endif
which is used like this:
struct function_pointers {
JMETHOD(void, init_entropy_encoder, (int somearg, jparms *jp));
JMETHOD(void, term_entropy_encoder, (void));
};
Note the set of parentheses surrounding the parameter list.
A similar solution is used for forward and external function declarations
(see the EXTERN and JPP macros).
If the code is to work on non-ANSI compilers, we cannot rely on a prototype
declaration to coerce actual parameters into the right types. Therefore, use
explicit casts on actual parameters whenever the actual parameter type is not
identical to the formal parameter. Beware of implicit conversions to "int".
It seems there are some non-ANSI compilers in which the sizeof() operator
is defined to return int, yet size_t is defined as long. Needless to say,
this is brain-damaged. Always use the SIZEOF() macro in place of sizeof(),
so that the result is guaranteed to be of type size_t.
The JPEG library is intended to be used within larger programs. Furthermore, The JPEG library is intended to be used within larger programs. Furthermore,
@@ -94,9 +57,7 @@ pass these through the common routines provided.
wherever possible. (Note that our method-based calling conventions help this wherever possible. (Note that our method-based calling conventions help this
a lot: in many modules only the initialization function will ever need to be a lot: in many modules only the initialization function will ever need to be
called directly, so only that function need be externally visible.) All called directly, so only that function need be externally visible.) All
global function names should begin with "jpeg_", and should have an global function names should begin with "jpeg_".
abbreviated name (unique in the first six characters) substituted by macro
when NEED_SHORT_EXTERNAL_NAMES is set.
3. Don't use global variables; anything that must be used in another module 3. Don't use global variables; anything that must be used in another module
should be in the common data structures. should be in the common data structures.
@@ -107,10 +68,9 @@ the system architecture document, structure.txt).
5. Source file names should begin with "j" for files that are part of the 5. Source file names should begin with "j" for files that are part of the
library proper; source files that are not part of the library, such as cjpeg.c library proper; source files that are not part of the library, such as cjpeg.c
and djpeg.c, do not begin with "j". Keep source file names to eight and djpeg.c, do not begin with "j". Keep compression and decompression code in
characters (plus ".c" or ".h", etc) to make life easy for MS-DOSers. Keep separate source files --- some applications may want only one half of the
compression and decompression code in separate source files --- some library.
applications may want only one half of the library.
Note: these rules (particularly #4) are not followed religiously in the Note: these rules (particularly #4) are not followed religiously in the
modules that are used in cjpeg/djpeg but are not part of the JPEG library modules that are used in cjpeg/djpeg but are not part of the JPEG library

View File

@@ -9,9 +9,6 @@ AM_INIT_AUTOMAKE([-Wall foreign dist-bzip2])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES(yes)]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES(yes)])
AC_PREFIX_DEFAULT(/opt/libmozjpeg) AC_PREFIX_DEFAULT(/opt/libmozjpeg)
# Always build with prototypes
AC_DEFINE([HAVE_PROTOTYPES], 1, [Define if your compiler supports prototypes])
# Checks for programs. # Checks for programs.
SAVED_CFLAGS=${CFLAGS} SAVED_CFLAGS=${CFLAGS}
SAVED_CPPFLAGS=${CPPFLAGS} SAVED_CPPFLAGS=${CPPFLAGS}
@@ -98,9 +95,9 @@ AC_CHECK_LIB([m],[pow])
# Checks for header files. # Checks for header files.
AC_HEADER_STDC AC_HEADER_STDC
AC_CHECK_HEADERS([stddef.h stdlib.h string.h]) AC_CHECK_HEADERS([stddef.h stdlib.h locale.h string.h])
AC_CHECK_HEADER([sys/types.h], AC_CHECK_HEADER([sys/types.h],
AC_DEFINE([NEED_SYS_TYPES_H], 1, [Define if you have sys/types.h])) AC_DEFINE([NEED_SYS_TYPES_H], 1, [Define if you need to include <sys/types.h> to get size_t.]))
# Checks for typedefs, structures, and compiler characteristics. # Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST AC_C_CONST
@@ -132,24 +129,15 @@ AC_TRY_RUN(
exit(is_shifting_signed(-0x7F7E80B1L)); exit(is_shifting_signed(-0x7F7E80B1L));
}], }],
[AC_MSG_RESULT(no) [AC_MSG_RESULT(no)
AC_DEFINE([RIGHT_SHIFT_IS_UNSIGNED], 1, [Define if shift is unsigned])], AC_DEFINE([RIGHT_SHIFT_IS_UNSIGNED], 1,
[Define if your (broken) compiler shifts signed values as if they were unsigned.])],
[AC_MSG_RESULT(yes)], [AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(Assuming that right shift is signed on target machine.)]) [AC_MSG_RESULT(Assuming that right shift is signed on target machine.)])
# test whether global names are unique to at least 15 chars
AC_MSG_CHECKING([for short external names])
AC_TRY_LINK(
[int possibly_duplicate_function () { return 0; }
int possibly_dupli_function () { return 1; }], [ ],
[AC_MSG_RESULT(ok)],
[AC_MSG_RESULT(short)
AC_DEFINE([NEED_SHORT_EXTERNAL_NAMES], 1,
[Define if you need short function names])])
# Checks for library functions. # Checks for library functions.
AC_CHECK_FUNCS([memset memcpy], [], AC_CHECK_FUNCS([memset memcpy], [],
[AC_DEFINE([NEED_BSD_STRINGS], 1, [AC_DEFINE([NEED_BSD_STRINGS], 1,
[Define if you have BSD-like bzero and bcopy])]) [Define if you have BSD-like bzero and bcopy in <strings.h> rather than memset/memcpy in <string.h>.])])
AC_MSG_CHECKING([libjpeg API version]) AC_MSG_CHECKING([libjpeg API version])
AC_ARG_VAR(JPEG_LIB_VERSION, [libjpeg API version (62, 70, or 80)]) AC_ARG_VAR(JPEG_LIB_VERSION, [libjpeg API version (62, 70, or 80)])
@@ -266,7 +254,7 @@ AC_SUBST(VERSION_SCRIPT_FLAG)
# Check for non-broken inline under various spellings # Check for non-broken inline under various spellings
AC_MSG_CHECKING(for inline) AC_MSG_CHECKING(for inline)
ljt_cv_inline="" ljt_cv_inline=""
AC_TRY_COMPILE(, [} __attribute__((always_inline)) int foo() { return 0; } AC_TRY_COMPILE(, [} inline __attribute__((always_inline)) int foo() { return 0; }
int bar() { return foo();], ljt_cv_inline="inline __attribute__((always_inline))", int bar() { return foo();], ljt_cv_inline="inline __attribute__((always_inline))",
AC_TRY_COMPILE(, [} __inline__ int foo() { return 0; } AC_TRY_COMPILE(, [} __inline__ int foo() { return 0; }
int bar() { return foo();], ljt_cv_inline="__inline__", int bar() { return foo();], ljt_cv_inline="__inline__",
@@ -454,12 +442,12 @@ if test "x${with_simd}" != "xno"; then
fi fi
fi fi
;; ;;
mipsel*) mips*)
AC_MSG_RESULT([yes (mipsel)]) AC_MSG_RESULT([yes (mips)])
AC_MSG_CHECKING([if the assembler is GNU-compatible and can be used]) AC_MSG_CHECKING([if the assembler is GNU-compatible and can be used])
AC_CHECK_COMPATIBLE_MIPSEL_ASSEMBLER_IFELSE( AC_CHECK_COMPATIBLE_MIPS_ASSEMBLER_IFELSE(
[AC_MSG_RESULT([yes]) [AC_MSG_RESULT([yes])
simd_arch=mipsel], simd_arch=mips],
[AC_MSG_RESULT([no]) [AC_MSG_RESULT([no])
with_simd=no]) with_simd=no])
if test "x${with_simd}" = "xno"; then if test "x${with_simd}" = "xno"; then
@@ -494,7 +482,7 @@ AM_CONDITIONAL([SIMD_I386], [test "x$simd_arch" = "xi386"])
AM_CONDITIONAL([SIMD_X86_64], [test "x$simd_arch" = "xx86_64"]) AM_CONDITIONAL([SIMD_X86_64], [test "x$simd_arch" = "xx86_64"])
AM_CONDITIONAL([SIMD_ARM], [test "x$simd_arch" = "xarm"]) AM_CONDITIONAL([SIMD_ARM], [test "x$simd_arch" = "xarm"])
AM_CONDITIONAL([SIMD_ARM_64], [test "x$simd_arch" = "xaarch64"]) AM_CONDITIONAL([SIMD_ARM_64], [test "x$simd_arch" = "xaarch64"])
AM_CONDITIONAL([SIMD_MIPSEL], [test "x$simd_arch" = "xmipsel"]) AM_CONDITIONAL([SIMD_MIPS], [test "x$simd_arch" = "xmips"])
AM_CONDITIONAL([X86_64], [test "x$host_cpu" = "xx86_64" -o "x$host_cpu" = "xamd64"]) AM_CONDITIONAL([X86_64], [test "x$host_cpu" = "xx86_64" -o "x$host_cpu" = "xamd64"])
AM_CONDITIONAL([WITH_TURBOJPEG], [test "x$with_turbojpeg" != "xno"]) AM_CONDITIONAL([WITH_TURBOJPEG], [test "x$with_turbojpeg" != "xno"])
@@ -519,14 +507,16 @@ AC_SUBST(RPMARCH)
AC_SUBST(RPM_CONFIG_ARGS) AC_SUBST(RPM_CONFIG_ARGS)
AC_SUBST(DEBARCH) AC_SUBST(DEBARCH)
AC_SUBST(BUILD) AC_SUBST(BUILD)
AC_DEFINE_UNQUOTED([BUILD], "$BUILD", [Build number]) AC_DEFINE_UNQUOTED([BUILD], "$BUILD", [libjpeg-turbo build number])
# jconfig.h is the file we use, but we have another before that to # NOTE: autoheader automatically modifies the input file of the first
# fool autoheader. the reason is that we include this header in our # invocation of AC_CONFIG_HEADERS, so we put config.h first to prevent
# API headers, which can screw things up for users of the lib. # jconfig.h.in from being clobbered. config.h is used only internally, whereas
# jconfig.h is a minimal version that allows this package to be built # jconfig.h contains macros that are relevant to external programs (macros that
# specify which features were built into the library.)
AC_CONFIG_HEADERS([config.h]) AC_CONFIG_HEADERS([config.h])
AC_CONFIG_HEADERS([jconfig.h]) AC_CONFIG_HEADERS([jconfig.h])
AC_CONFIG_HEADERS([jconfigint.h])
AC_CONFIG_FILES([pkgscripts/libmozjpeg.spec.tmpl:release/libmozjpeg.spec.in]) AC_CONFIG_FILES([pkgscripts/libmozjpeg.spec.tmpl:release/libmozjpeg.spec.in])
AC_CONFIG_FILES([pkgscripts/makecygwinpkg.tmpl:release/makecygwinpkg.in]) AC_CONFIG_FILES([pkgscripts/makecygwinpkg.tmpl:release/makecygwinpkg.in])
AC_CONFIG_FILES([pkgscripts/makedpkg.tmpl:release/makedpkg.in]) AC_CONFIG_FILES([pkgscripts/makedpkg.tmpl:release/makedpkg.in])

19
djpeg.1
View File

@@ -55,11 +55,14 @@ default options are chosen for highest quality output.) Currently, this is
equivalent to \fB\-dct fast \-nosmooth \-onepass \-dither ordered\fR. equivalent to \fB\-dct fast \-nosmooth \-onepass \-dither ordered\fR.
.TP .TP
.B \-grayscale .B \-grayscale
Force gray-scale output even if JPEG file is color. Useful for viewing on Force grayscale output even if JPEG file is color. Useful for viewing on
monochrome displays; also, monochrome displays; also,
.B djpeg .B djpeg
runs noticeably faster in this mode. runs noticeably faster in this mode.
.TP .TP
.B \-rgb
Force RGB output even if JPEG file is grayscale.
.TP
.BI \-scale " M/N" .BI \-scale " M/N"
Scale the output image by a factor M/N. Currently the scale factor must be Scale the output image by a factor M/N. Currently the scale factor must be
M/8, where M is an integer between 1 and 16 inclusive, or any reduced fraction M/8, where M is an integer between 1 and 16 inclusive, or any reduced fraction
@@ -74,7 +77,7 @@ emitted if
.B \-colors .B \-colors
or or
.B \-grayscale .B \-grayscale
is specified, or if the JPEG file is gray-scale; otherwise, 24-bit full-color is specified, or if the JPEG file is grayscale; otherwise, 24-bit full-color
format is emitted. format is emitted.
.TP .TP
.B \-gif .B \-gif
@@ -88,12 +91,12 @@ emitted if
.B \-colors .B \-colors
or or
.B \-grayscale .B \-grayscale
is specified, or if the JPEG file is gray-scale; otherwise, 24-bit full-color is specified, or if the JPEG file is grayscale; otherwise, 24-bit full-color
format is emitted. format is emitted.
.TP .TP
.B \-pnm .B \-pnm
Select PBMPLUS (PPM/PGM) output format (this is the default format). Select PBMPLUS (PPM/PGM) output format (this is the default format).
PGM is emitted if the JPEG file is gray-scale or if PGM is emitted if the JPEG file is grayscale or if
.B \-grayscale .B \-grayscale
is specified; otherwise PPM is emitted. is specified; otherwise PPM is emitted.
.TP .TP
@@ -101,8 +104,8 @@ is specified; otherwise PPM is emitted.
Select RLE output format. (Requires URT library.) Select RLE output format. (Requires URT library.)
.TP .TP
.B \-targa .B \-targa
Select Targa output format. Gray-scale format is emitted if the JPEG file is Select Targa output format. Grayscale format is emitted if the JPEG file is
gray-scale or if grayscale or if
.B \-grayscale .B \-grayscale
is specified; otherwise, colormapped format is emitted if is specified; otherwise, colormapped format is emitted if
.B \-colors .B \-colors
@@ -132,7 +135,7 @@ compressed using lower quality levels.
.TP .TP
.B \-dct float .B \-dct float
Use floating-point DCT method. Use floating-point DCT method.
The float method is mostly a legacy feature. It does not produce significantly The float method is mainly a legacy feature. It does not produce significantly
more accurate results than the int method, and it is much slower. The float more accurate results than the int method, and it is much slower. The float
method may also give different results on different machines due to varying method may also give different results on different machines due to varying
roundoff behavior, whereas the integer methods should give the same results on roundoff behavior, whereas the integer methods should give the same results on
@@ -174,7 +177,7 @@ faster and needs less memory, but it produces a lower-quality image.
is ignored unless you also say is ignored unless you also say
.B \-colors .B \-colors
.IR N . .IR N .
Also, the one-pass method is always used for gray-scale output (the two-pass Also, the one-pass method is always used for grayscale output (the two-pass
method is no improvement then). method is no improvement then).
.TP .TP
.BI \-maxmemory " N" .BI \-maxmemory " N"

212
djpeg.c
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-2011, 2013, D. R. Commander. * Copyright (C) 2010-2011, 2013-2014, D. R. Commander.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains a command-line user interface for the JPEG decompressor. * This file contains a command-line user interface for the JPEG decompressor.
@@ -12,8 +12,8 @@
* *
* Two different command line styles are permitted, depending on the * Two different command line styles are permitted, depending on the
* compile-time switch TWO_FILE_COMMANDLINE: * compile-time switch TWO_FILE_COMMANDLINE:
* djpeg [options] inputfile outputfile * djpeg [options] inputfile outputfile
* djpeg [options] [inputfile] * djpeg [options] [inputfile]
* In the second style, output is always to standard output, which you'd * In the second style, output is always to standard output, which you'd
* normally redirect to a file or pipe to some other program. Input is * normally redirect to a file or pipe to some other program. Input is
* either from a named file or from standard input (typically redirected). * either from a named file or from standard input (typically redirected).
@@ -21,30 +21,30 @@
* don't support pipes. Also, you MUST use the first style if your system * don't support pipes. Also, you MUST use the first style if your system
* doesn't do binary I/O to stdin/stdout. * doesn't do binary I/O to stdin/stdout.
* To simplify script writing, the "-outfile" switch is provided. The syntax * To simplify script writing, the "-outfile" switch is provided. The syntax
* djpeg [options] -outfile outputfile inputfile * djpeg [options] -outfile outputfile inputfile
* works regardless of which command line style is used. * works regardless of which command line style is used.
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include "jversion.h" /* for version message */ #include "jversion.h" /* for version message */
#include "config.h" #include "jconfigint.h"
#include <ctype.h> /* to declare isprint() */ #include <ctype.h> /* to declare isprint() */
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ #ifdef USE_CCOMMAND /* command-line reader for Macintosh */
#ifdef __MWERKS__ #ifdef __MWERKS__
#include <SIOUX.h> /* Metrowerks needs this */ #include <SIOUX.h> /* Metrowerks needs this */
#include <console.h> /* ... and this */ #include <console.h> /* ... and this */
#endif #endif
#ifdef THINK_C #ifdef THINK_C
#include <console.h> /* Think declares it here */ #include <console.h> /* Think declares it here */
#endif #endif
#endif #endif
/* Create the add-on message string table. */ /* Create the add-on message string table. */
#define JMESSAGE(code,string) string , #define JMESSAGE(code,string) string ,
static const char * const cdjpeg_message_table[] = { static const char * const cdjpeg_message_table[] = {
#include "cderror.h" #include "cderror.h"
@@ -60,17 +60,17 @@ static const char * const cdjpeg_message_table[] = {
*/ */
typedef enum { typedef enum {
FMT_BMP, /* BMP format (Windows flavor) */ FMT_BMP, /* BMP format (Windows flavor) */
FMT_GIF, /* GIF format */ FMT_GIF, /* GIF format */
FMT_OS2, /* BMP format (OS/2 flavor) */ FMT_OS2, /* BMP format (OS/2 flavor) */
FMT_PPM, /* PPM/PGM (PBMPLUS formats) */ FMT_PPM, /* PPM/PGM (PBMPLUS formats) */
FMT_RLE, /* RLE format */ FMT_RLE, /* RLE format */
FMT_TARGA, /* Targa format */ FMT_TARGA, /* Targa format */
FMT_TIFF /* TIFF format */ FMT_TIFF /* TIFF format */
} IMAGE_FORMATS; } IMAGE_FORMATS;
#ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */ #ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */
#define DEFAULT_FMT FMT_PPM #define DEFAULT_FMT FMT_PPM
#endif #endif
static IMAGE_FORMATS requested_fmt; static IMAGE_FORMATS requested_fmt;
@@ -85,8 +85,8 @@ static IMAGE_FORMATS requested_fmt;
*/ */
static const char * progname; /* program name for error messages */ static const char * progname; /* program name for error messages */
static char * outfilename; /* for -outfile switch */ static char * outfilename; /* for -outfile switch */
boolean memsrc; /* for -memsrc switch */ boolean memsrc; /* for -memsrc switch */
#define INPUT_BUF_SIZE 4096 #define INPUT_BUF_SIZE 4096
@@ -107,45 +107,46 @@ usage (void)
fprintf(stderr, " -fast Fast, low-quality processing\n"); fprintf(stderr, " -fast Fast, low-quality processing\n");
fprintf(stderr, " -grayscale Force grayscale output\n"); fprintf(stderr, " -grayscale Force grayscale output\n");
fprintf(stderr, " -rgb Force RGB output\n"); fprintf(stderr, " -rgb Force RGB output\n");
fprintf(stderr, " -rgb565 Force RGB565 output\n");
#ifdef IDCT_SCALING_SUPPORTED #ifdef IDCT_SCALING_SUPPORTED
fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n"); fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n");
#endif #endif
#ifdef BMP_SUPPORTED #ifdef BMP_SUPPORTED
fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n", fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n",
(DEFAULT_FMT == FMT_BMP ? " (default)" : "")); (DEFAULT_FMT == FMT_BMP ? " (default)" : ""));
#endif #endif
#ifdef GIF_SUPPORTED #ifdef GIF_SUPPORTED
fprintf(stderr, " -gif Select GIF output format%s\n", fprintf(stderr, " -gif Select GIF output format%s\n",
(DEFAULT_FMT == FMT_GIF ? " (default)" : "")); (DEFAULT_FMT == FMT_GIF ? " (default)" : ""));
#endif #endif
#ifdef BMP_SUPPORTED #ifdef BMP_SUPPORTED
fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n", fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n",
(DEFAULT_FMT == FMT_OS2 ? " (default)" : "")); (DEFAULT_FMT == FMT_OS2 ? " (default)" : ""));
#endif #endif
#ifdef PPM_SUPPORTED #ifdef PPM_SUPPORTED
fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n", fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n",
(DEFAULT_FMT == FMT_PPM ? " (default)" : "")); (DEFAULT_FMT == FMT_PPM ? " (default)" : ""));
#endif #endif
#ifdef RLE_SUPPORTED #ifdef RLE_SUPPORTED
fprintf(stderr, " -rle Select Utah RLE output format%s\n", fprintf(stderr, " -rle Select Utah RLE output format%s\n",
(DEFAULT_FMT == FMT_RLE ? " (default)" : "")); (DEFAULT_FMT == FMT_RLE ? " (default)" : ""));
#endif #endif
#ifdef TARGA_SUPPORTED #ifdef TARGA_SUPPORTED
fprintf(stderr, " -targa Select Targa output format%s\n", fprintf(stderr, " -targa Select Targa output format%s\n",
(DEFAULT_FMT == FMT_TARGA ? " (default)" : "")); (DEFAULT_FMT == FMT_TARGA ? " (default)" : ""));
#endif #endif
fprintf(stderr, "Switches for advanced users:\n"); fprintf(stderr, "Switches for advanced users:\n");
#ifdef DCT_ISLOW_SUPPORTED #ifdef DCT_ISLOW_SUPPORTED
fprintf(stderr, " -dct int Use integer DCT method%s\n", fprintf(stderr, " -dct int Use integer DCT method%s\n",
(JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
#endif #endif
#ifdef DCT_IFAST_SUPPORTED #ifdef DCT_IFAST_SUPPORTED
fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n", fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
(JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
#endif #endif
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
fprintf(stderr, " -dct float Use floating-point DCT method%s\n", fprintf(stderr, " -dct float Use floating-point DCT method%s\n",
(JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
#endif #endif
fprintf(stderr, " -dither fs Use F-S dithering (default)\n"); fprintf(stderr, " -dither fs Use F-S dithering (default)\n");
fprintf(stderr, " -dither none Don't use dithering in quantization\n"); fprintf(stderr, " -dither none Don't use dithering in quantization\n");
@@ -170,7 +171,7 @@ usage (void)
LOCAL(int) LOCAL(int)
parse_switches (j_decompress_ptr cinfo, int argc, char **argv, parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
int last_file_arg_seen, boolean for_real) int last_file_arg_seen, boolean for_real)
/* Parse optional switches. /* Parse optional switches.
* Returns argv[] index of first file-name argument (== argc if none). * Returns argv[] index of first file-name argument (== argc if none).
* Any file names with indexes <= last_file_arg_seen are ignored; * Any file names with indexes <= last_file_arg_seen are ignored;
@@ -184,7 +185,7 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
char * arg; char * arg;
/* Set up default JPEG parameters. */ /* Set up default JPEG parameters. */
requested_fmt = DEFAULT_FMT; /* set default output file format */ requested_fmt = DEFAULT_FMT; /* set default output file format */
outfilename = NULL; outfilename = NULL;
memsrc = FALSE; memsrc = FALSE;
cinfo->err->trace_level = 0; cinfo->err->trace_level = 0;
@@ -196,54 +197,54 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
if (*arg != '-') { if (*arg != '-') {
/* Not a switch, must be a file name argument */ /* Not a switch, must be a file name argument */
if (argn <= last_file_arg_seen) { if (argn <= last_file_arg_seen) {
outfilename = NULL; /* -outfile applies to just one input file */ outfilename = NULL; /* -outfile applies to just one input file */
continue; /* ignore this name if previously processed */ continue; /* ignore this name if previously processed */
} }
break; /* else done parsing switches */ break; /* else done parsing switches */
} }
arg++; /* advance past switch marker character */ arg++; /* advance past switch marker character */
if (keymatch(arg, "bmp", 1)) { if (keymatch(arg, "bmp", 1)) {
/* BMP output format. */ /* BMP output format. */
requested_fmt = FMT_BMP; requested_fmt = FMT_BMP;
} else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) || } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) ||
keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) { keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) {
/* Do color quantization. */ /* Do color quantization. */
int val; int val;
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%d", &val) != 1) if (sscanf(argv[argn], "%d", &val) != 1)
usage(); usage();
cinfo->desired_number_of_colors = val; cinfo->desired_number_of_colors = val;
cinfo->quantize_colors = TRUE; cinfo->quantize_colors = TRUE;
} else if (keymatch(arg, "dct", 2)) { } else if (keymatch(arg, "dct", 2)) {
/* Select IDCT algorithm. */ /* Select IDCT algorithm. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (keymatch(argv[argn], "int", 1)) { if (keymatch(argv[argn], "int", 1)) {
cinfo->dct_method = JDCT_ISLOW; cinfo->dct_method = JDCT_ISLOW;
} else if (keymatch(argv[argn], "fast", 2)) { } else if (keymatch(argv[argn], "fast", 2)) {
cinfo->dct_method = JDCT_IFAST; cinfo->dct_method = JDCT_IFAST;
} else if (keymatch(argv[argn], "float", 2)) { } else if (keymatch(argv[argn], "float", 2)) {
cinfo->dct_method = JDCT_FLOAT; cinfo->dct_method = JDCT_FLOAT;
} else } else
usage(); usage();
} else if (keymatch(arg, "dither", 2)) { } else if (keymatch(arg, "dither", 2)) {
/* Select dithering algorithm. */ /* Select dithering algorithm. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (keymatch(argv[argn], "fs", 2)) { if (keymatch(argv[argn], "fs", 2)) {
cinfo->dither_mode = JDITHER_FS; cinfo->dither_mode = JDITHER_FS;
} else if (keymatch(argv[argn], "none", 2)) { } else if (keymatch(argv[argn], "none", 2)) {
cinfo->dither_mode = JDITHER_NONE; cinfo->dither_mode = JDITHER_NONE;
} else if (keymatch(argv[argn], "ordered", 2)) { } else if (keymatch(argv[argn], "ordered", 2)) {
cinfo->dither_mode = JDITHER_ORDERED; cinfo->dither_mode = JDITHER_ORDERED;
} else } else
usage(); usage();
} else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
/* Enable debug printouts. */ /* Enable debug printouts. */
@@ -251,12 +252,12 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
static boolean printed_version = FALSE; static boolean printed_version = FALSE;
if (! printed_version) { if (! printed_version) {
fprintf(stderr, "%s version %s (build %s)\n", fprintf(stderr, "%s version %s (build %s)\n",
PACKAGE_NAME, VERSION, BUILD); PACKAGE_NAME, VERSION, BUILD);
fprintf(stderr, "%s\n\n", JCOPYRIGHT); fprintf(stderr, "%s\n\n", JCOPYRIGHT);
fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n", fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
JVERSION); JVERSION);
printed_version = TRUE; printed_version = TRUE;
} }
cinfo->err->trace_level++; cinfo->err->trace_level++;
@@ -265,7 +266,7 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
cinfo->two_pass_quantize = FALSE; cinfo->two_pass_quantize = FALSE;
cinfo->dither_mode = JDITHER_ORDERED; cinfo->dither_mode = JDITHER_ORDERED;
if (! cinfo->quantize_colors) /* don't override an earlier -colors */ if (! cinfo->quantize_colors) /* don't override an earlier -colors */
cinfo->desired_number_of_colors = 216; cinfo->desired_number_of_colors = 216;
cinfo->dct_method = JDCT_FASTEST; cinfo->dct_method = JDCT_FASTEST;
cinfo->do_fancy_upsampling = FALSE; cinfo->do_fancy_upsampling = FALSE;
@@ -281,23 +282,27 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
/* Force RGB output. */ /* Force RGB output. */
cinfo->out_color_space = JCS_RGB; cinfo->out_color_space = JCS_RGB;
} else if (keymatch(arg, "rgb565", 2)) {
/* Force RGB565 output. */
cinfo->out_color_space = JCS_RGB565;
} else if (keymatch(arg, "map", 3)) { } else if (keymatch(arg, "map", 3)) {
/* Quantize to a color map taken from an input file. */ /* Quantize to a color map taken from an input file. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (for_real) { /* too expensive to do twice! */ if (for_real) { /* too expensive to do twice! */
#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ #ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */
FILE * mapfile; FILE * mapfile;
if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) { if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) {
fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
read_color_map(cinfo, mapfile); read_color_map(cinfo, mapfile);
fclose(mapfile); fclose(mapfile);
cinfo->quantize_colors = TRUE; cinfo->quantize_colors = TRUE;
#else #else
ERREXIT(cinfo, JERR_NOT_COMPILED); ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif #endif
} }
@@ -306,12 +311,12 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
long lval; long lval;
char ch = 'x'; char ch = 'x';
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
usage(); usage();
if (ch == 'm' || ch == 'M') if (ch == 'm' || ch == 'M')
lval *= 1000L; lval *= 1000L;
cinfo->mem->max_memory_to_use = lval * 1000L; cinfo->mem->max_memory_to_use = lval * 1000L;
} else if (keymatch(arg, "nosmooth", 3)) { } else if (keymatch(arg, "nosmooth", 3)) {
@@ -328,9 +333,9 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "outfile", 4)) { } else if (keymatch(arg, "outfile", 4)) {
/* Set output file name. */ /* Set output file name. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
outfilename = argv[argn]; /* save it away for later use */ outfilename = argv[argn]; /* save it away for later use */
} else if (keymatch(arg, "memsrc", 2)) { } else if (keymatch(arg, "memsrc", 2)) {
/* Use in-memory source manager */ /* Use in-memory source manager */
@@ -352,22 +357,22 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "scale", 1)) { } else if (keymatch(arg, "scale", 1)) {
/* Scale the output image by a fraction M/N. */ /* Scale the output image by a fraction M/N. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%d/%d", if (sscanf(argv[argn], "%d/%d",
&cinfo->scale_num, &cinfo->scale_denom) != 2) &cinfo->scale_num, &cinfo->scale_denom) != 2)
usage(); usage();
} else if (keymatch(arg, "targa", 1)) { } else if (keymatch(arg, "targa", 1)) {
/* Targa output format. */ /* Targa output format. */
requested_fmt = FMT_TARGA; requested_fmt = FMT_TARGA;
} else { } else {
usage(); /* bogus switch */ usage(); /* bogus switch */
} }
} }
return argn; /* return index of next arg (file name) */ return argn; /* return index of next arg (file name) */
} }
@@ -403,14 +408,14 @@ print_text_marker (j_decompress_ptr cinfo)
length = jpeg_getc(cinfo) << 8; length = jpeg_getc(cinfo) << 8;
length += jpeg_getc(cinfo); length += jpeg_getc(cinfo);
length -= 2; /* discount the length word itself */ length -= 2; /* discount the length word itself */
if (traceit) { if (traceit) {
if (cinfo->unread_marker == JPEG_COM) if (cinfo->unread_marker == JPEG_COM)
fprintf(stderr, "Comment, length %ld:\n", (long) length); fprintf(stderr, "Comment, length %ld:\n", (long) length);
else /* assume it is an APPn otherwise */ else /* assume it is an APPn otherwise */
fprintf(stderr, "APP%d, length %ld:\n", fprintf(stderr, "APP%d, length %ld:\n",
cinfo->unread_marker - JPEG_APP0, (long) length); cinfo->unread_marker - JPEG_APP0, (long) length);
} }
while (--length >= 0) { while (--length >= 0) {
@@ -422,16 +427,16 @@ print_text_marker (j_decompress_ptr cinfo)
* Newlines in CR, CR/LF, or LF form will be printed as one newline. * Newlines in CR, CR/LF, or LF form will be printed as one newline.
*/ */
if (ch == '\r') { if (ch == '\r') {
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} else if (ch == '\n') { } else if (ch == '\n') {
if (lastch != '\r') if (lastch != '\r')
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} else if (ch == '\\') { } else if (ch == '\\') {
fprintf(stderr, "\\\\"); fprintf(stderr, "\\\\");
} else if (isprint(ch)) { } else if (isprint(ch)) {
putc(ch, stderr); putc(ch, stderr);
} else { } else {
fprintf(stderr, "\\%03o", ch); fprintf(stderr, "\\%03o", ch);
} }
lastch = ch; lastch = ch;
} }
@@ -471,7 +476,7 @@ main (int argc, char **argv)
progname = argv[0]; progname = argv[0];
if (progname == NULL || progname[0] == 0) if (progname == NULL || progname[0] == 0)
progname = "djpeg"; /* in case C library doesn't provide it */ progname = "djpeg"; /* in case C library doesn't provide it */
/* Initialize the JPEG decompression object with default error handling. */ /* Initialize the JPEG decompression object with default error handling. */
cinfo.err = jpeg_std_error(&jerr); cinfo.err = jpeg_std_error(&jerr);
@@ -490,11 +495,6 @@ main (int argc, char **argv)
jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker); jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker);
jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker); jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker);
/* Now safe to enable signal catcher. */
#ifdef NEED_SIGNAL_CATCHER
enable_signal_catcher((j_common_ptr) &cinfo);
#endif
/* Scan command line to find file names. */ /* Scan command line to find file names. */
/* It is convenient to use just one switch-parsing routine, but the switch /* It is convenient to use just one switch-parsing routine, but the switch
* values read here are ignored; we will rescan the switches after opening * values read here are ignored; we will rescan the switches after opening
@@ -510,14 +510,14 @@ main (int argc, char **argv)
if (outfilename == NULL) { if (outfilename == NULL) {
if (file_index != argc-2) { if (file_index != argc-2) {
fprintf(stderr, "%s: must name one input and one output file\n", fprintf(stderr, "%s: must name one input and one output file\n",
progname); progname);
usage(); usage();
} }
outfilename = argv[file_index+1]; outfilename = argv[file_index+1];
} else { } else {
if (file_index != argc-1) { if (file_index != argc-1) {
fprintf(stderr, "%s: must name one input and one output file\n", fprintf(stderr, "%s: must name one input and one output file\n",
progname); progname);
usage(); usage();
} }
} }
@@ -634,7 +634,7 @@ main (int argc, char **argv)
/* Process data */ /* Process data */
while (cinfo.output_scanline < cinfo.output_height) { while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer, num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
dest_mgr->buffer_height); dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
} }
@@ -668,5 +668,5 @@ main (int argc, char **argv)
/* All done. */ /* All done. */
exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
return 0; /* suppress no-return-value warnings */ return 0; /* suppress no-return-value warnings */
} }

View File

@@ -58,9 +58,9 @@
* RGB color and is described by: * RGB color and is described by:
*/ */
extern JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */ extern JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */
extern int image_height; /* Number of rows in image */ extern int image_height; /* Number of rows in image */
extern int image_width; /* Number of columns in image */ extern int image_width; /* Number of columns in image */
/* /*
@@ -88,9 +88,9 @@ write_JPEG_file (char * filename, int quality)
*/ */
struct jpeg_error_mgr jerr; struct jpeg_error_mgr jerr;
/* More stuff */ /* More stuff */
FILE * outfile; /* target file */ FILE * outfile; /* target file */
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
int row_stride; /* physical row width in image buffer */ int row_stride; /* physical row width in image buffer */
/* Step 1: allocate and initialize JPEG compression object */ /* Step 1: allocate and initialize JPEG compression object */
@@ -122,10 +122,10 @@ write_JPEG_file (char * filename, int quality)
/* First we supply a description of the input image. /* First we supply a description of the input image.
* Four fields of the cinfo struct must be filled in: * Four fields of the cinfo struct must be filled in:
*/ */
cinfo.image_width = image_width; /* image width and height, in pixels */ cinfo.image_width = image_width; /* image width and height, in pixels */
cinfo.image_height = image_height; cinfo.image_height = image_height;
cinfo.input_components = 3; /* # of color components per pixel */ cinfo.input_components = 3; /* # of color components per pixel */
cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
cinfo.use_moz_defaults = TRUE; /* use Mozilla defaults for improved compression */ cinfo.use_moz_defaults = TRUE; /* use Mozilla defaults for improved compression */
/* Now use the library's routine to set default compression parameters. /* Now use the library's routine to set default compression parameters.
@@ -153,7 +153,7 @@ write_JPEG_file (char * filename, int quality)
* To keep things simple, we pass one scanline per call; you can pass * To keep things simple, we pass one scanline per call; you can pass
* more if you wish, though. * more if you wish, though.
*/ */
row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */ row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */
while (cinfo.next_scanline < cinfo.image_height) { while (cinfo.next_scanline < cinfo.image_height) {
/* jpeg_write_scanlines expects an array of pointers to scanlines. /* jpeg_write_scanlines expects an array of pointers to scanlines.
@@ -250,9 +250,9 @@ write_JPEG_file (char * filename, int quality)
*/ */
struct my_error_mgr { struct my_error_mgr {
struct jpeg_error_mgr pub; /* "public" fields */ struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */ jmp_buf setjmp_buffer; /* for return to caller */
}; };
typedef struct my_error_mgr * my_error_ptr; typedef struct my_error_mgr * my_error_ptr;
@@ -295,9 +295,9 @@ read_JPEG_file (char * filename)
*/ */
struct my_error_mgr jerr; struct my_error_mgr jerr;
/* More stuff */ /* More stuff */
FILE * infile; /* source file */ FILE * infile; /* source file */
JSAMPARRAY buffer; /* Output row buffer */ JSAMPARRAY buffer; /* Output row buffer */
int row_stride; /* physical row width in output buffer */ int row_stride; /* physical row width in output buffer */
/* In this example we want to open the input file before doing anything else, /* In this example we want to open the input file before doing anything else,
* so that the setjmp() error recovery below can assume the file is open. * so that the setjmp() error recovery below can assume the file is open.
@@ -363,7 +363,7 @@ read_JPEG_file (char * filename)
row_stride = cinfo.output_width * cinfo.output_components; row_stride = cinfo.output_width * cinfo.output_components;
/* Make a one-row-high sample array that will go away when done with image */ /* Make a one-row-high sample array that will go away when done with image */
buffer = (*cinfo.mem->alloc_sarray) buffer = (*cinfo.mem->alloc_sarray)
((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
/* Step 6: while (scan lines remain to be read) */ /* Step 6: while (scan lines remain to be read) */
/* jpeg_read_scanlines(...); */ /* jpeg_read_scanlines(...); */

View File

@@ -673,7 +673,7 @@ public class TJUnitTest {
tjc.setSubsamp(subsamp); tjc.setSubsamp(subsamp);
tjc.setJPEGQuality(jpegQual); tjc.setJPEGQuality(jpegQual);
if (doYUV) { if (doYUV) {
System.out.format("%s %s -> YUV %s ... ", pfStrLong, buStrLong, System.out.format("%s %s -> YUV %s ... ", pfStrLong, buStrLong,
subNameLong[subsamp]); subNameLong[subsamp]);
YUVImage yuvImage = tjc.encodeYUV(pad, flags); YUVImage yuvImage = tjc.encodeYUV(pad, flags);
if (checkBufYUV(yuvImage.getBuf(), yuvImage.getSize(), w, h, subsamp, if (checkBufYUV(yuvImage.getBuf(), yuvImage.getSize(), w, h, subsamp,

View File

@@ -1,9 +1,11 @@
/* /*
* jcapimin.c * jcapimin.c
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1998, Thomas G. Lane. * Copyright (C) 1994-1998, Thomas G. Lane.
* Modified 2003-2010 by Guido Vollbeding. * Modified 2003-2010 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains application interface code for the compression half * This file contains application interface code for the compression half
@@ -33,12 +35,12 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
int i; int i;
/* Guard against version mismatches between library and caller. */ /* Guard against version mismatches between library and caller. */
cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
if (version != JPEG_LIB_VERSION) if (version != JPEG_LIB_VERSION)
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
@@ -49,7 +51,7 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
{ {
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_compress_struct)); MEMZERO(cinfo, sizeof(struct jpeg_compress_struct));
cinfo->err = err; cinfo->err = err;
cinfo->client_data = client_data; cinfo->client_data = client_data;
} }
@@ -85,7 +87,7 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
cinfo->script_space = NULL; cinfo->script_space = NULL;
cinfo->input_gamma = 1.0; /* in case application forgets */ cinfo->input_gamma = 1.0; /* in case application forgets */
/* OK, I'm ready */ /* OK, I'm ready */
cinfo->global_state = CSTATE_START; cinfo->global_state = CSTATE_START;
@@ -173,15 +175,15 @@ jpeg_finish_compress (j_compress_ptr cinfo)
(*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);
} }
@@ -202,9 +204,9 @@ 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, unsigned int datalen) const JOCTET *dataptr, unsigned int datalen)
{ {
JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val)); void (*write_marker_byte) (j_compress_ptr info, int val);
if (cinfo->next_scanline != 0 || if (cinfo->next_scanline != 0 ||
(cinfo->global_state != CSTATE_SCANNING && (cinfo->global_state != CSTATE_SCANNING &&
@@ -213,7 +215,7 @@ jpeg_write_marker (j_compress_ptr cinfo, int marker,
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
(*cinfo->marker->write_marker_header) (cinfo, marker, datalen); (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */ write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
while (datalen--) { while (datalen--) {
(*write_marker_byte) (cinfo, *dataptr); (*write_marker_byte) (cinfo, *dataptr);
dataptr++; dataptr++;
@@ -248,14 +250,14 @@ jpeg_write_m_byte (j_compress_ptr cinfo, int val)
* To produce a pair of files containing abbreviated tables and abbreviated * To produce a pair of files containing abbreviated tables and abbreviated
* image data, one would proceed as follows: * image data, one would proceed as follows:
* *
* initialize JPEG object * initialize JPEG object
* set JPEG parameters * set JPEG parameters
* set destination to table file * set destination to table file
* jpeg_write_tables(cinfo); * jpeg_write_tables(cinfo);
* set destination to image file * set destination to image file
* jpeg_start_compress(cinfo, FALSE); * jpeg_start_compress(cinfo, FALSE);
* write data... * write data...
* jpeg_finish_compress(cinfo); * jpeg_finish_compress(cinfo);
* *
* jpeg_write_tables has the side effect of marking all tables written * jpeg_write_tables has the side effect of marking all tables written
* (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress * (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress

View File

@@ -43,7 +43,7 @@ jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
if (write_all_tables) if (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 */
/* setting up scan optimisation pattern failed, disable scan optimisation */ /* setting up scan optimisation pattern failed, disable scan optimisation */
if (cinfo->num_scans_luma == 0 || cinfo->scan_info == NULL || cinfo->num_scans == 0) if (cinfo->num_scans_luma == 0 || cinfo->scan_info == NULL || cinfo->num_scans == 0)
@@ -81,7 +81,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;
@@ -124,7 +124,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;

348
jcarith.c
View File

@@ -1,8 +1,10 @@
/* /*
* jcarith.c * jcarith.c
* *
* This file was part of the Independent JPEG Group's software:
* Developed 1997-2009 by Guido Vollbeding. * Developed 1997-2009 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains portable arithmetic entropy encoding routines for JPEG * This file contains portable arithmetic entropy encoding routines for JPEG
@@ -34,8 +36,8 @@ typedef struct {
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */ int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */
unsigned int restarts_to_go; /* MCUs left in this restart interval */ unsigned int restarts_to_go; /* MCUs left in this restart interval */
int next_restart_num; /* next restart number to write (0-7) */ int next_restart_num; /* next restart number to write (0-7) */
/* Pointers to statistics areas (these workspaces have image lifespan) */ /* Pointers to statistics areas (these workspaces have image lifespan) */
unsigned char * dc_stats[NUM_ARITH_TBLS]; unsigned char * dc_stats[NUM_ARITH_TBLS];
@@ -101,14 +103,14 @@ 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
@@ -149,11 +151,11 @@ finish_pass (j_compress_ptr cinfo)
/* 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)
do emit_byte(0x00, cinfo); do emit_byte(0x00, cinfo);
while (--e->zc); while (--e->zc);
emit_byte(e->buffer + 1, cinfo); emit_byte(e->buffer + 1, cinfo);
if (e->buffer + 1 == 0xFF) if (e->buffer + 1 == 0xFF)
emit_byte(0x00, cinfo); emit_byte(0x00, cinfo);
} }
e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */ e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */
e->sc = 0; e->sc = 0;
@@ -162,17 +164,17 @@ finish_pass (j_compress_ptr cinfo)
++e->zc; ++e->zc;
else if (e->buffer >= 0) { else if (e->buffer >= 0) {
if (e->zc) if (e->zc)
do emit_byte(0x00, cinfo); do emit_byte(0x00, cinfo);
while (--e->zc); while (--e->zc);
emit_byte(e->buffer, cinfo); emit_byte(e->buffer, cinfo);
} }
if (e->sc) { if (e->sc) {
if (e->zc) if (e->zc)
do emit_byte(0x00, cinfo); do emit_byte(0x00, cinfo);
while (--e->zc); while (--e->zc);
do { do {
emit_byte(0xFF, cinfo); emit_byte(0xFF, cinfo);
emit_byte(0x00, cinfo); emit_byte(0x00, cinfo);
} while (--e->sc); } while (--e->sc);
} }
} }
@@ -187,7 +189,7 @@ finish_pass (j_compress_ptr cinfo)
if (e->c & 0x7F800L) { if (e->c & 0x7F800L) {
emit_byte((e->c >> 11) & 0xFF, cinfo); emit_byte((e->c >> 11) & 0xFF, cinfo);
if (((e->c >> 11) & 0xFF) == 0xFF) if (((e->c >> 11) & 0xFF) == 0xFF)
emit_byte(0x00, cinfo); emit_byte(0x00, cinfo);
} }
} }
} }
@@ -227,9 +229,9 @@ arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
* Qe values and probability estimation state machine * Qe values and probability estimation state machine
*/ */
sv = *st; sv = *st;
qe = jpeg_aritab[sv & 0x7F]; /* => Qe_Value */ qe = jpeg_aritab[sv & 0x7F]; /* => Qe_Value */
nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */ nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */
nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */ nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */
/* Encode & estimation procedures per sections D.1.4 & D.1.5 */ /* Encode & estimation procedures per sections D.1.4 & D.1.5 */
e->a -= qe; e->a -= qe;
@@ -243,7 +245,7 @@ arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
e->c += e->a; e->c += e->a;
e->a = qe; e->a = qe;
} }
*st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */ *st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */
} else { } else {
/* Encode the more probable symbol */ /* Encode the more probable symbol */
if (e->a >= 0x8000L) if (e->a >= 0x8000L)
@@ -255,7 +257,7 @@ arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
e->c += e->a; e->c += e->a;
e->a = qe; e->a = qe;
} }
*st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */ *st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */
} }
/* Renormalization & data output per section D.1.6 */ /* Renormalization & data output per section D.1.6 */
@@ -266,43 +268,43 @@ arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
/* Another byte is ready for output */ /* Another byte is ready for output */
temp = e->c >> 19; temp = e->c >> 19;
if (temp > 0xFF) { if (temp > 0xFF) {
/* Handle overflow over all stacked 0xFF bytes */ /* Handle overflow over all stacked 0xFF bytes */
if (e->buffer >= 0) { if (e->buffer >= 0) {
if (e->zc) if (e->zc)
do emit_byte(0x00, cinfo); do emit_byte(0x00, cinfo);
while (--e->zc); while (--e->zc);
emit_byte(e->buffer + 1, cinfo); emit_byte(e->buffer + 1, cinfo);
if (e->buffer + 1 == 0xFF) if (e->buffer + 1 == 0xFF)
emit_byte(0x00, cinfo); emit_byte(0x00, cinfo);
} }
e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */ e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */
e->sc = 0; e->sc = 0;
/* Note: The 3 spacer bits in the C register guarantee /* Note: The 3 spacer bits in the C register guarantee
* that the new buffer byte can't be 0xFF here * that the new buffer byte can't be 0xFF here
* (see page 160 in the P&M JPEG book). */ * (see page 160 in the P&M JPEG book). */
e->buffer = temp & 0xFF; /* new output byte, might overflow later */ e->buffer = temp & 0xFF; /* new output byte, might overflow later */
} else if (temp == 0xFF) { } else if (temp == 0xFF) {
++e->sc; /* stack 0xFF byte (which might overflow later) */ ++e->sc; /* stack 0xFF byte (which might overflow later) */
} else { } else {
/* Output all stacked 0xFF bytes, they will not overflow any more */ /* Output all stacked 0xFF bytes, they will not overflow any more */
if (e->buffer == 0) if (e->buffer == 0)
++e->zc; ++e->zc;
else if (e->buffer >= 0) { else if (e->buffer >= 0) {
if (e->zc) if (e->zc)
do emit_byte(0x00, cinfo); do emit_byte(0x00, cinfo);
while (--e->zc); while (--e->zc);
emit_byte(e->buffer, cinfo); emit_byte(e->buffer, cinfo);
} }
if (e->sc) { if (e->sc) {
if (e->zc) if (e->zc)
do emit_byte(0x00, cinfo); do emit_byte(0x00, cinfo);
while (--e->zc); while (--e->zc);
do { do {
emit_byte(0xFF, cinfo); emit_byte(0xFF, cinfo);
emit_byte(0x00, cinfo); emit_byte(0x00, cinfo);
} while (--e->sc); } while (--e->sc);
} }
e->buffer = temp & 0xFF; /* new output byte (can still overflow) */ e->buffer = temp & 0xFF; /* new output byte (can still overflow) */
} }
e->c &= 0x7FFFFL; e->c &= 0x7FFFFL;
e->ct += 8; e->ct += 8;
@@ -398,45 +400,45 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Figure F.4: Encode_DC_DIFF */ /* Figure F.4: Encode_DC_DIFF */
if ((v = m - entropy->last_dc_val[ci]) == 0) { if ((v = m - entropy->last_dc_val[ci]) == 0) {
arith_encode(cinfo, st, 0); arith_encode(cinfo, st, 0);
entropy->dc_context[ci] = 0; /* zero diff category */ entropy->dc_context[ci] = 0; /* zero diff category */
} else { } else {
entropy->last_dc_val[ci] = m; entropy->last_dc_val[ci] = m;
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
/* Figure F.6: Encoding nonzero value v */ /* Figure F.6: Encoding nonzero value v */
/* Figure F.7: Encoding the sign of v */ /* Figure F.7: Encoding the sign of v */
if (v > 0) { if (v > 0) {
arith_encode(cinfo, st + 1, 0); /* Table F.4: SS = S0 + 1 */ arith_encode(cinfo, st + 1, 0); /* Table F.4: SS = S0 + 1 */
st += 2; /* Table F.4: SP = S0 + 2 */ st += 2; /* Table F.4: SP = S0 + 2 */
entropy->dc_context[ci] = 4; /* small positive diff category */ entropy->dc_context[ci] = 4; /* small positive diff category */
} else { } else {
v = -v; v = -v;
arith_encode(cinfo, st + 1, 1); /* Table F.4: SS = S0 + 1 */ arith_encode(cinfo, st + 1, 1); /* Table F.4: SS = S0 + 1 */
st += 3; /* Table F.4: SN = S0 + 3 */ st += 3; /* Table F.4: SN = S0 + 3 */
entropy->dc_context[ci] = 8; /* small negative diff category */ entropy->dc_context[ci] = 8; /* small negative diff category */
} }
/* Figure F.8: Encoding the magnitude category of v */ /* Figure F.8: Encoding the magnitude category of v */
m = 0; m = 0;
if (v -= 1) { if (v -= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m = 1; m = 1;
v2 = v; v2 = v;
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
while (v2 >>= 1) { while (v2 >>= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m <<= 1; m <<= 1;
st += 1; st += 1;
} }
} }
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;
while (m >>= 1) while (m >>= 1)
arith_encode(cinfo, st, (m & v) ? 1 : 0); arith_encode(cinfo, st, (m & v) ? 1 : 0);
} }
} }
@@ -491,21 +493,21 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Figure F.5: Encode_AC_Coefficients */ /* Figure F.5: Encode_AC_Coefficients */
for (k = cinfo->Ss; k <= ke; k++) { for (k = cinfo->Ss; k <= ke; k++) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * (k - 1);
arith_encode(cinfo, st, 0); /* EOB decision */ arith_encode(cinfo, st, 0); /* EOB decision */
for (;;) { for (;;) {
if ((v = (*block)[jpeg_natural_order[k]]) >= 0) { if ((v = (*block)[jpeg_natural_order[k]]) >= 0) {
if (v >>= cinfo->Al) { if (v >>= cinfo->Al) {
arith_encode(cinfo, st + 1, 1); arith_encode(cinfo, st + 1, 1);
arith_encode(cinfo, entropy->fixed_bin, 0); arith_encode(cinfo, entropy->fixed_bin, 0);
break; break;
} }
} else { } else {
v = -v; v = -v;
if (v >>= cinfo->Al) { if (v >>= cinfo->Al) {
arith_encode(cinfo, st + 1, 1); arith_encode(cinfo, st + 1, 1);
arith_encode(cinfo, entropy->fixed_bin, 1); arith_encode(cinfo, entropy->fixed_bin, 1);
break; break;
} }
} }
arith_encode(cinfo, st + 1, 0); st += 3; k++; arith_encode(cinfo, st + 1, 0); st += 3; k++;
} }
@@ -517,15 +519,15 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
m = 1; m = 1;
v2 = v; v2 = v;
if (v2 >>= 1) { if (v2 >>= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m <<= 1; m <<= 1;
st = entropy->ac_stats[tbl] + st = entropy->ac_stats[tbl] +
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217); (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
while (v2 >>= 1) { while (v2 >>= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m <<= 1; m <<= 1;
st += 1; st += 1;
} }
} }
} }
arith_encode(cinfo, st, 0); arith_encode(cinfo, st, 0);
@@ -566,7 +568,7 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
entropy->restarts_to_go--; entropy->restarts_to_go--;
} }
st = entropy->fixed_bin; /* use fixed probability estimation */ st = entropy->fixed_bin; /* use fixed probability estimation */
Al = cinfo->Al; Al = cinfo->Al;
/* Encode the MCU data blocks */ /* Encode the MCU data blocks */
@@ -635,29 +637,29 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
for (k = cinfo->Ss; k <= ke; k++) { for (k = cinfo->Ss; k <= ke; k++) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * (k - 1);
if (k > kex) if (k > kex)
arith_encode(cinfo, st, 0); /* EOB decision */ arith_encode(cinfo, st, 0); /* EOB decision */
for (;;) { for (;;) {
if ((v = (*block)[jpeg_natural_order[k]]) >= 0) { if ((v = (*block)[jpeg_natural_order[k]]) >= 0) {
if (v >>= cinfo->Al) { if (v >>= cinfo->Al) {
if (v >> 1) /* previously nonzero coef */ if (v >> 1) /* previously nonzero coef */
arith_encode(cinfo, st + 2, (v & 1)); arith_encode(cinfo, st + 2, (v & 1));
else { /* newly nonzero coef */ else { /* newly nonzero coef */
arith_encode(cinfo, st + 1, 1); arith_encode(cinfo, st + 1, 1);
arith_encode(cinfo, entropy->fixed_bin, 0); arith_encode(cinfo, entropy->fixed_bin, 0);
} }
break; break;
} }
} else { } else {
v = -v; v = -v;
if (v >>= cinfo->Al) { if (v >>= cinfo->Al) {
if (v >> 1) /* previously nonzero coef */ if (v >> 1) /* previously nonzero coef */
arith_encode(cinfo, st + 2, (v & 1)); arith_encode(cinfo, st + 2, (v & 1));
else { /* newly nonzero coef */ else { /* newly nonzero coef */
arith_encode(cinfo, st + 1, 1); arith_encode(cinfo, st + 1, 1);
arith_encode(cinfo, entropy->fixed_bin, 1); arith_encode(cinfo, entropy->fixed_bin, 1);
} }
break; break;
} }
} }
arith_encode(cinfo, st + 1, 0); st += 3; k++; arith_encode(cinfo, st + 1, 0); st += 3; k++;
} }
@@ -713,45 +715,45 @@ encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Figure F.4: Encode_DC_DIFF */ /* Figure F.4: Encode_DC_DIFF */
if ((v = (*block)[0] - entropy->last_dc_val[ci]) == 0) { if ((v = (*block)[0] - entropy->last_dc_val[ci]) == 0) {
arith_encode(cinfo, st, 0); arith_encode(cinfo, st, 0);
entropy->dc_context[ci] = 0; /* zero diff category */ entropy->dc_context[ci] = 0; /* zero diff category */
} else { } else {
entropy->last_dc_val[ci] = (*block)[0]; entropy->last_dc_val[ci] = (*block)[0];
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
/* Figure F.6: Encoding nonzero value v */ /* Figure F.6: Encoding nonzero value v */
/* Figure F.7: Encoding the sign of v */ /* Figure F.7: Encoding the sign of v */
if (v > 0) { if (v > 0) {
arith_encode(cinfo, st + 1, 0); /* Table F.4: SS = S0 + 1 */ arith_encode(cinfo, st + 1, 0); /* Table F.4: SS = S0 + 1 */
st += 2; /* Table F.4: SP = S0 + 2 */ st += 2; /* Table F.4: SP = S0 + 2 */
entropy->dc_context[ci] = 4; /* small positive diff category */ entropy->dc_context[ci] = 4; /* small positive diff category */
} else { } else {
v = -v; v = -v;
arith_encode(cinfo, st + 1, 1); /* Table F.4: SS = S0 + 1 */ arith_encode(cinfo, st + 1, 1); /* Table F.4: SS = S0 + 1 */
st += 3; /* Table F.4: SN = S0 + 3 */ st += 3; /* Table F.4: SN = S0 + 3 */
entropy->dc_context[ci] = 8; /* small negative diff category */ entropy->dc_context[ci] = 8; /* small negative diff category */
} }
/* Figure F.8: Encoding the magnitude category of v */ /* Figure F.8: Encoding the magnitude category of v */
m = 0; m = 0;
if (v -= 1) { if (v -= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m = 1; m = 1;
v2 = v; v2 = v;
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
while (v2 >>= 1) { while (v2 >>= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m <<= 1; m <<= 1;
st += 1; st += 1;
} }
} }
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;
while (m >>= 1) while (m >>= 1)
arith_encode(cinfo, st, (m & v) ? 1 : 0); arith_encode(cinfo, st, (m & v) ? 1 : 0);
} }
/* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */ /* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */
@@ -765,43 +767,43 @@ encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Figure F.5: Encode_AC_Coefficients */ /* Figure F.5: Encode_AC_Coefficients */
for (k = 1; k <= ke; k++) { for (k = 1; k <= ke; k++) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * (k - 1);
arith_encode(cinfo, st, 0); /* EOB decision */ arith_encode(cinfo, st, 0); /* EOB decision */
while ((v = (*block)[jpeg_natural_order[k]]) == 0) { while ((v = (*block)[jpeg_natural_order[k]]) == 0) {
arith_encode(cinfo, st + 1, 0); st += 3; k++; arith_encode(cinfo, st + 1, 0); st += 3; k++;
} }
arith_encode(cinfo, st + 1, 1); arith_encode(cinfo, st + 1, 1);
/* Figure F.6: Encoding nonzero value v */ /* Figure F.6: Encoding nonzero value v */
/* Figure F.7: Encoding the sign of v */ /* Figure F.7: Encoding the sign of v */
if (v > 0) { if (v > 0) {
arith_encode(cinfo, entropy->fixed_bin, 0); arith_encode(cinfo, entropy->fixed_bin, 0);
} else { } else {
v = -v; v = -v;
arith_encode(cinfo, entropy->fixed_bin, 1); arith_encode(cinfo, entropy->fixed_bin, 1);
} }
st += 2; st += 2;
/* Figure F.8: Encoding the magnitude category of v */ /* Figure F.8: Encoding the magnitude category of v */
m = 0; m = 0;
if (v -= 1) { if (v -= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m = 1; m = 1;
v2 = v; v2 = v;
if (v2 >>= 1) { if (v2 >>= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m <<= 1; m <<= 1;
st = entropy->ac_stats[tbl] + st = entropy->ac_stats[tbl] +
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217); (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
while (v2 >>= 1) { while (v2 >>= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m <<= 1; m <<= 1;
st += 1; st += 1;
} }
} }
} }
arith_encode(cinfo, st, 0); arith_encode(cinfo, st, 0);
/* Figure F.9: Encoding the magnitude bit pattern of v */ /* Figure F.9: Encoding the magnitude bit pattern of v */
st += 14; st += 14;
while (m >>= 1) while (m >>= 1)
arith_encode(cinfo, st, (m & v) ? 1 : 0); arith_encode(cinfo, st, (m & v) ? 1 : 0);
} }
/* Encode EOB decision only if k <= DCTSIZE2 - 1 */ /* Encode EOB decision only if k <= DCTSIZE2 - 1 */
if (k <= DCTSIZE2 - 1) { if (k <= DCTSIZE2 - 1) {
@@ -838,14 +840,14 @@ start_pass (j_compress_ptr cinfo, boolean gather_statistics)
if (cinfo->progressive_mode) { if (cinfo->progressive_mode) {
if (cinfo->Ah == 0) { if (cinfo->Ah == 0) {
if (cinfo->Ss == 0) if (cinfo->Ss == 0)
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;
} else { } else {
if (cinfo->Ss == 0) if (cinfo->Ss == 0)
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;
} }
} else } else
entropy->pub.encode_mcu = encode_mcu; entropy->pub.encode_mcu = encode_mcu;
@@ -857,10 +859,10 @@ start_pass (j_compress_ptr cinfo, boolean gather_statistics)
if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) { if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
tbl = compptr->dc_tbl_no; tbl = compptr->dc_tbl_no;
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;
@@ -870,15 +872,15 @@ start_pass (j_compress_ptr cinfo, boolean gather_statistics)
if (cinfo->progressive_mode == 0 || cinfo->Se) { if (cinfo->progressive_mode == 0 || cinfo->Se) {
tbl = compptr->ac_tbl_no; tbl = compptr->ac_tbl_no;
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
} }
} }
@@ -909,7 +911,7 @@ jinit_arith_encoder (j_compress_ptr cinfo)
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

@@ -1,10 +1,12 @@
/* /*
* jccoefct.c * jccoefct.c
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1997, Thomas G. Lane. * Copyright (C) 1994-1997, Thomas G. Lane.
* It was modified by The libjpeg-turbo Project to include only code and
* information relevant to libjpeg-turbo.
* mozjpeg Modifications: * mozjpeg Modifications:
* Copyright (C) 2014, Mozilla Corporation. * Copyright (C) 2014, Mozilla Corporation.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains the coefficient buffer controller for compression. * This file contains the coefficient buffer controller for compression.
@@ -36,19 +38,16 @@
typedef struct { typedef struct {
struct jpeg_c_coef_controller pub; /* public fields */ struct jpeg_c_coef_controller pub; /* public fields */
JDIMENSION iMCU_row_num; /* iMCU row # within image */ JDIMENSION iMCU_row_num; /* iMCU row # within image */
JDIMENSION mcu_ctr; /* counts MCUs processed in current row */ JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
int MCU_vert_offset; /* counts MCU rows within iMCU row */ int MCU_vert_offset; /* counts MCU rows within iMCU row */
int MCU_rows_per_iMCU_row; /* number of such rows needed */ int MCU_rows_per_iMCU_row; /* number of such rows needed */
/* For single-pass compression, it's sufficient to buffer just one MCU /* For single-pass compression, it's sufficient to buffer just one MCU
* (although this may prove a bit slow in practice). We allocate a * (although this may prove a bit slow in practice). We allocate a
* workspace of C_MAX_BLOCKS_IN_MCU coefficient blocks, and reuse it for each * workspace of C_MAX_BLOCKS_IN_MCU coefficient blocks, and reuse it for each
* MCU constructed and sent. (On 80x86, the workspace is FAR even though * MCU constructed and sent. In multi-pass modes, this array points to the
* it's not really very big; this is to keep the module interfaces unchanged * current MCU's blocks within the virtual arrays.
* when a large coefficient buffer is necessary.)
* In multi-pass modes, this array points to the current MCU's blocks
* within the virtual arrays.
*/ */
JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU]; JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
@@ -65,15 +64,15 @@ typedef my_coef_controller * my_coef_ptr;
/* Forward declarations */ /* Forward declarations */
METHODDEF(boolean) compress_data METHODDEF(boolean) compress_data
JPP((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
JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf)); (j_compress_ptr cinfo, JSAMPIMAGE input_buf);
METHODDEF(boolean) compress_output METHODDEF(boolean) compress_output
JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf)); (j_compress_ptr cinfo, JSAMPIMAGE input_buf);
#endif #endif
METHODDEF(boolean) compress_trellis_pass METHODDEF(boolean) compress_trellis_pass
JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf)); (j_compress_ptr cinfo, JSAMPIMAGE input_buf);
LOCAL(void) LOCAL(void)
@@ -157,7 +156,7 @@ 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;
int blkn, bi, ci, yindex, yoffset, blockcnt; int blkn, bi, ci, yindex, yoffset, blockcnt;
@@ -168,7 +167,7 @@ compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
yoffset++) { yoffset++) {
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++) {
/* Determine where data comes from in input_buf and do the DCT thing. /* Determine where data comes from in input_buf and do the DCT thing.
* Each call on forward_DCT processes a horizontal row of DCT blocks * Each call on forward_DCT processes a horizontal row of DCT blocks
* as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks * as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks
@@ -180,46 +179,46 @@ 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, NULL); ypos, xpos, (JDIMENSION) blockcnt, NULL);
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 FAR *) 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 FAR *) 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;
ypos += DCTSIZE; ypos += DCTSIZE;
} }
} }
/* 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;
return FALSE; return FALSE;
} }
} }
/* Completed an MCU row, but perhaps not an iMCU row */ /* Completed an MCU row, but perhaps not an iMCU row */
@@ -301,17 +300,17 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
for (block_row = 0; block_row < block_rows; block_row++) { for (block_row = 0; block_row < block_rows; block_row++) {
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, buffer_dst[block_row]); (JDIMENSION) 0, blocks_across, buffer_dst[block_row]);
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 FAR *) 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;
} }
} }
} }
/* If at end of image, create dummy block rows as needed. /* If at end of image, create dummy block rows as needed.
@@ -320,22 +319,22 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
* This squeezes a few more bytes out of the resulting file... * This squeezes a few more bytes out of the resulting file...
*/ */
if (coef->iMCU_row_num == last_iMCU_row) { if (coef->iMCU_row_num == last_iMCU_row) {
blocks_across += ndummy; /* include lower right corner */ blocks_across += ndummy; /* include lower right corner */
MCUs_across = blocks_across / h_samp_factor; MCUs_across = blocks_across / h_samp_factor;
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 FAR *) 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;
} }
thisblockrow += h_samp_factor; /* advance to next MCU in row */ thisblockrow += h_samp_factor; /* advance to next MCU in row */
lastblockrow += h_samp_factor; lastblockrow += h_samp_factor;
} }
} }
} }
} }
@@ -402,7 +401,7 @@ compress_trellis_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
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 FAR *) 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;
@@ -421,8 +420,8 @@ compress_trellis_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
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 FAR *) 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++) {
@@ -457,7 +456,7 @@ 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;
JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
@@ -480,26 +479,26 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
yoffset++) { yoffset++) {
for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row; for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
MCU_col_num++) { MCU_col_num++) {
/* Construct list of pointers to DCT blocks belonging to this MCU */ /* Construct list of pointers to DCT blocks belonging to this MCU */
blkn = 0; /* index of current DCT block within MCU */ blkn = 0; /* index of current DCT block within MCU */
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;
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;
return FALSE; return FALSE;
} }
} }
/* Completed an MCU row, but perhaps not an iMCU row */ /* Completed an MCU row, but perhaps not an iMCU row */
@@ -525,7 +524,7 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
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;
@@ -538,14 +537,14 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
jpeg_component_info *compptr; jpeg_component_info *compptr;
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);
coef->whole_image_uq[ci] = (*cinfo->mem->request_virt_barray) coef->whole_image_uq[ci] = (*cinfo->mem->request_virt_barray)
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
@@ -565,7 +564,7 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
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

@@ -58,16 +58,16 @@ rgb_ycc_convert_internal (j_compress_ptr cinfo,
*/ */
/* Y */ /* Y */
outptr0[col] = (JSAMPLE) outptr0[col] = (JSAMPLE)
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) ((ctab[r+R_Y_OFF] + ctab[g+G_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[b+B_CB_OFF]) ((ctab[r+R_CB_OFF] + ctab[g+G_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[b+B_CR_OFF]) ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
>> SCALEBITS); >> SCALEBITS);
} }
} }
} }
@@ -108,8 +108,8 @@ rgb_gray_convert_internal (j_compress_ptr cinfo,
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[b+B_Y_OFF]) ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
>> SCALEBITS); >> SCALEBITS);
} }
} }
} }

164
jccolor.c
View File

@@ -6,6 +6,7 @@
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2009-2012, D. R. Commander. * Copyright (C) 2009-2012, D. R. Commander.
* Copyright (C) 2014, MIPS Technologies, Inc., California
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains input colorspace conversion routines. * This file contains input colorspace conversion routines.
@@ -15,7 +16,7 @@
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jsimd.h" #include "jsimd.h"
#include "config.h" #include "jconfigint.h"
/* Private subobject */ /* Private subobject */
@@ -24,7 +25,7 @@ typedef struct {
struct jpeg_color_converter pub; /* public fields */ struct jpeg_color_converter pub; /* public fields */
/* Private state for RGB->YCC conversion */ /* Private state for RGB->YCC conversion */
INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */ INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
} my_color_converter; } my_color_converter;
typedef my_color_converter * my_cconvert_ptr; typedef my_color_converter * my_cconvert_ptr;
@@ -36,9 +37,9 @@ typedef my_color_converter * my_cconvert_ptr;
* YCbCr is defined per CCIR 601-1, except that Cb and Cr are * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
* normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
* The conversion equations to be implemented are therefore * The conversion equations to be implemented are therefore
* Y = 0.29900 * R + 0.58700 * G + 0.11400 * B * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
* Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE * Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
* Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE * Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
* (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
* Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2, * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,
* rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and * rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and
@@ -60,10 +61,10 @@ typedef my_color_converter * my_cconvert_ptr;
* in the tables to save adding them separately in the inner loop. * in the tables to save adding them separately in the inner loop.
*/ */
#define SCALEBITS 16 /* speediest right-shift on some machines */ #define SCALEBITS 16 /* speediest right-shift on some machines */
#define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS) #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
#define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) #define FIX(x) ((INT32) ((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
@@ -71,16 +72,16 @@ typedef my_color_converter * my_cconvert_ptr;
* machines (more than can hold all eight addresses, anyway). * machines (more than can hold all eight addresses, anyway).
*/ */
#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 */
@@ -202,7 +203,7 @@ rgb_ycc_start (j_compress_ptr cinfo)
/* Allocate and fill in the conversion tables. */ /* Allocate and fill in the conversion tables. */
cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *) cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(TABLE_SIZE * SIZEOF(INT32))); (TABLE_SIZE * sizeof(INT32)));
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;
@@ -230,8 +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, JSAMPIMAGE output_buf, JSAMPARRAY input_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:
@@ -279,8 +280,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, JSAMPIMAGE output_buf, JSAMPARRAY input_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:
@@ -325,8 +326,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, JSAMPIMAGE output_buf, JSAMPARRAY input_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:
@@ -375,8 +376,8 @@ 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, JSAMPIMAGE output_buf, JSAMPARRAY input_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;
@@ -398,7 +399,7 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
g = MAXJSAMPLE - GETJSAMPLE(inptr[1]); g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
b = MAXJSAMPLE - GETJSAMPLE(inptr[2]); b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
/* K passes through as-is */ /* K passes through as-is */
outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */ outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
inptr += 4; inptr += 4;
/* If the inputs are 0..MAXJSAMPLE, the outputs of these equations /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
* must be too; we do not need an explicit range-limiting operation. * must be too; we do not need an explicit range-limiting operation.
@@ -407,16 +408,16 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
*/ */
/* Y */ /* Y */
outptr0[col] = (JSAMPLE) outptr0[col] = (JSAMPLE)
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) ((ctab[r+R_Y_OFF] + ctab[g+G_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[b+B_CB_OFF]) ((ctab[r+R_CB_OFF] + ctab[g+G_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[b+B_CR_OFF]) ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
>> SCALEBITS); >> SCALEBITS);
} }
} }
} }
@@ -430,8 +431,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, 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;
register JSAMPROW outptr; register JSAMPROW outptr;
@@ -444,7 +445,7 @@ grayscale_convert (j_compress_ptr cinfo,
outptr = output_buf[0][output_row]; outptr = output_buf[0][output_row];
output_row++; output_row++;
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */ outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
inptr += instride; inptr += instride;
} }
} }
@@ -459,8 +460,8 @@ 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;
register JSAMPROW outptr; register JSAMPROW outptr;
@@ -475,8 +476,8 @@ null_convert (j_compress_ptr cinfo,
inptr = *input_buf; inptr = *input_buf;
outptr = output_buf[ci][output_row]; outptr = output_buf[ci][output_row];
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */ outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
inptr += nc; inptr += nc;
} }
} }
input_buf++; input_buf++;
@@ -507,7 +508,7 @@ jinit_color_converter (j_compress_ptr cinfo)
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;
@@ -545,7 +546,7 @@ jinit_color_converter (j_compress_ptr cinfo)
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
break; break;
default: /* JCS_UNKNOWN can be anything */ default: /* JCS_UNKNOWN can be anything */
if (cinfo->input_components < 1) if (cinfo->input_components < 1)
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
break; break;
@@ -587,19 +588,24 @@ jinit_color_converter (j_compress_ptr cinfo)
if (rgb_red[cinfo->in_color_space] == 0 && if (rgb_red[cinfo->in_color_space] == 0 &&
rgb_green[cinfo->in_color_space] == 1 && rgb_green[cinfo->in_color_space] == 1 &&
rgb_blue[cinfo->in_color_space] == 2 && rgb_blue[cinfo->in_color_space] == 2 &&
rgb_pixelsize[cinfo->in_color_space] == 3) rgb_pixelsize[cinfo->in_color_space] == 3) {
cconvert->pub.color_convert = null_convert; #if defined(__mips__)
else if (cinfo->in_color_space == JCS_RGB || if (jsimd_c_can_null_convert())
cinfo->in_color_space == JCS_EXT_RGB || cconvert->pub.color_convert = jsimd_c_null_convert;
cinfo->in_color_space == JCS_EXT_RGBX || else
cinfo->in_color_space == JCS_EXT_BGR || #endif
cinfo->in_color_space == JCS_EXT_BGRX || cconvert->pub.color_convert = null_convert;
cinfo->in_color_space == JCS_EXT_XBGR || } else if (cinfo->in_color_space == JCS_RGB ||
cinfo->in_color_space == JCS_EXT_XRGB || cinfo->in_color_space == JCS_EXT_RGB ||
cinfo->in_color_space == JCS_EXT_RGBA || cinfo->in_color_space == JCS_EXT_RGBX ||
cinfo->in_color_space == JCS_EXT_BGRA || cinfo->in_color_space == JCS_EXT_BGR ||
cinfo->in_color_space == JCS_EXT_ABGR || cinfo->in_color_space == JCS_EXT_BGRX ||
cinfo->in_color_space == JCS_EXT_ARGB) cinfo->in_color_space == JCS_EXT_XBGR ||
cinfo->in_color_space == JCS_EXT_XRGB ||
cinfo->in_color_space == JCS_EXT_RGBA ||
cinfo->in_color_space == JCS_EXT_BGRA ||
cinfo->in_color_space == JCS_EXT_ABGR ||
cinfo->in_color_space == JCS_EXT_ARGB)
cconvert->pub.color_convert = rgb_rgb_convert; cconvert->pub.color_convert = rgb_rgb_convert;
else else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
@@ -625,18 +631,28 @@ jinit_color_converter (j_compress_ptr cinfo)
cconvert->pub.start_pass = rgb_ycc_start; cconvert->pub.start_pass = rgb_ycc_start;
cconvert->pub.color_convert = rgb_ycc_convert; cconvert->pub.color_convert = rgb_ycc_convert;
} }
} else if (cinfo->in_color_space == JCS_YCbCr) } else if (cinfo->in_color_space == JCS_YCbCr) {
cconvert->pub.color_convert = null_convert; #if defined(__mips__)
else if (jsimd_c_can_null_convert())
cconvert->pub.color_convert = jsimd_c_null_convert;
else
#endif
cconvert->pub.color_convert = null_convert;
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break; break;
case JCS_CMYK: case JCS_CMYK:
if (cinfo->num_components != 4) if (cinfo->num_components != 4)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
if (cinfo->in_color_space == JCS_CMYK) if (cinfo->in_color_space == JCS_CMYK) {
cconvert->pub.color_convert = null_convert; #if defined(__mips__)
else if (jsimd_c_can_null_convert())
cconvert->pub.color_convert = jsimd_c_null_convert;
else
#endif
cconvert->pub.color_convert = null_convert;
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break; break;
@@ -646,17 +662,27 @@ jinit_color_converter (j_compress_ptr cinfo)
if (cinfo->in_color_space == JCS_CMYK) { if (cinfo->in_color_space == JCS_CMYK) {
cconvert->pub.start_pass = rgb_ycc_start; cconvert->pub.start_pass = rgb_ycc_start;
cconvert->pub.color_convert = cmyk_ycck_convert; cconvert->pub.color_convert = cmyk_ycck_convert;
} else if (cinfo->in_color_space == JCS_YCCK) } else if (cinfo->in_color_space == JCS_YCCK) {
cconvert->pub.color_convert = null_convert; #if defined(__mips__)
else if (jsimd_c_can_null_convert())
cconvert->pub.color_convert = jsimd_c_null_convert;
else
#endif
cconvert->pub.color_convert = null_convert;
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break; break;
default: /* allow null conversion of JCS_UNKNOWN */ default: /* allow null conversion of JCS_UNKNOWN */
if (cinfo->jpeg_color_space != cinfo->in_color_space || if (cinfo->jpeg_color_space != cinfo->in_color_space ||
cinfo->num_components != cinfo->input_components) cinfo->num_components != cinfo->input_components)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
cconvert->pub.color_convert = null_convert; #if defined(__mips__)
if (jsimd_c_can_null_convert())
cconvert->pub.color_convert = jsimd_c_null_convert;
else
#endif
cconvert->pub.color_convert = null_convert;
break; break;
} }
} }

View File

@@ -20,34 +20,33 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#include "jsimddct.h" #include "jsimddct.h"
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
/* Private subobject for this module */ /* Private subobject for this module */
typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data)); typedef void (*forward_DCT_method_ptr) (DCTELEM * data);
typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data)); typedef void (*float_DCT_method_ptr) (FAST_FLOAT * data);
typedef JMETHOD(void, convsamp_method_ptr, typedef void (*convsamp_method_ptr) (JSAMPARRAY sample_data,
(JSAMPARRAY sample_data, JDIMENSION start_col, JDIMENSION start_col,
DCTELEM * workspace)); DCTELEM * workspace);
typedef JMETHOD(void, float_convsamp_method_ptr, typedef void (*float_convsamp_method_ptr) (JSAMPARRAY sample_data,
(JSAMPARRAY sample_data, JDIMENSION start_col, JDIMENSION start_col,
FAST_FLOAT *workspace)); FAST_FLOAT *workspace);
typedef JMETHOD(void, quantize_method_ptr, typedef void (*quantize_method_ptr) (JCOEFPTR coef_block, DCTELEM * divisors,
(JCOEFPTR coef_block, DCTELEM * divisors, DCTELEM * workspace);
DCTELEM * workspace)); typedef void (*float_quantize_method_ptr) (JCOEFPTR coef_block,
typedef JMETHOD(void, float_quantize_method_ptr, FAST_FLOAT * divisors,
(JCOEFPTR coef_block, 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 */
/* Pointer to the DCT routine actually in use */ /* Pointer to the DCT routine actually in use */
forward_DCT_method_ptr dct; forward_DCT_method_ptr dct;
@@ -224,7 +223,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
qtblno = compptr->quant_tbl_no; qtblno = compptr->quant_tbl_no;
/* Make sure specified quantization table is present */ /* Make sure specified quantization table is present */
if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
cinfo->quant_tbl_ptrs[qtblno] == NULL) cinfo->quant_tbl_ptrs[qtblno] == NULL)
ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
qtbl = cinfo->quant_tbl_ptrs[qtblno]; qtbl = cinfo->quant_tbl_ptrs[qtblno];
/* Compute divisors for this quant table */ /* Compute divisors for this quant table */
@@ -236,91 +235,91 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
* coefficients multiplied by 8 (to counteract scaling). * coefficients multiplied by 8 (to counteract scaling).
*/ */
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(!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]) if(!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i])
&& fdct->quantize == jsimd_quantize) && fdct->quantize == jsimd_quantize)
fdct->quantize = quantize; fdct->quantize = quantize;
} }
break; break;
#endif #endif
#ifdef DCT_IFAST_SUPPORTED #ifdef DCT_IFAST_SUPPORTED
case JDCT_IFAST: case JDCT_IFAST:
{ {
/* For AA&N IDCT method, divisors are equal to quantization /* For AA&N IDCT method, divisors are equal to quantization
* coefficients scaled by scalefactor[row]*scalefactor[col], where * coefficients scaled by scalefactor[row]*scalefactor[col], where
* 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
* We apply a further scale factor of 8. * We apply a further scale factor of 8.
*/ */
#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 */
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
}; };
SHIFT_TEMPS SHIFT_TEMPS
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(!compute_reciprocal( if(!compute_reciprocal(
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
(INT32) aanscales[i]), (INT32) 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;
} }
} }
break; break;
#endif #endif
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
case JDCT_FLOAT: case JDCT_FLOAT:
{ {
/* For float AA&N IDCT method, divisors are equal to quantization /* For float AA&N IDCT method, divisors are equal to quantization
* coefficients scaled by scalefactor[row]*scalefactor[col], where * coefficients scaled by scalefactor[row]*scalefactor[col], where
* 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
* We apply a further scale factor of 8. * We apply a further scale factor of 8.
* What's actually stored is 1/divisor so that the inner loop can * What's actually stored is 1/divisor so that the inner loop can
* use a multiplication rather than a division. * use a multiplication rather than a division.
*/ */
FAST_FLOAT * fdtbl; FAST_FLOAT * fdtbl;
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,
1.0, 0.785694958, 0.541196100, 0.275899379 1.0, 0.785694958, 0.541196100, 0.275899379
}; };
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];
i = 0; i = 0;
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++;
} }
} }
} }
break; break;
#endif #endif
@@ -347,7 +346,7 @@ convsamp (JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM * workspace)
for (elemr = 0; elemr < DCTSIZE; elemr++) { for (elemr = 0; elemr < DCTSIZE; elemr++) {
elemptr = sample_data[elemr] + start_col; elemptr = sample_data[elemr] + start_col;
#if DCTSIZE == 8 /* unroll the inner loop */ #if DCTSIZE == 8 /* unroll the inner loop */
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
@@ -413,8 +412,8 @@ 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, JBLOCKROW dst) JDIMENSION num_blocks, JBLOCKROW dst)
/* This version is used for integer DCT implementations. */ /* This version is used for integer DCT implementations. */
{ {
@@ -430,7 +429,7 @@ forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
quantize_method_ptr do_quantize = fdct->quantize; quantize_method_ptr do_quantize = fdct->quantize;
workspace = fdct->workspace; workspace = fdct->workspace;
sample_data += start_row; /* fold in the vertical offset once */ sample_data += start_row; /* fold in the vertical offset once */
for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) { for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
/* Load data into workspace, applying unsigned->signed conversion */ /* Load data into workspace, applying unsigned->signed conversion */
@@ -488,7 +487,7 @@ convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col, FAST_FLOAT * works
workspaceptr = workspace; workspaceptr = workspace;
for (elemr = 0; elemr < DCTSIZE; elemr++) { for (elemr = 0; elemr < DCTSIZE; elemr++) {
elemptr = sample_data[elemr] + start_col; elemptr = sample_data[elemr] + start_col;
#if DCTSIZE == 8 /* unroll the inner loop */ #if DCTSIZE == 8 /* unroll the inner loop */
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
@@ -533,8 +532,8 @@ quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors, FAST_FLOAT * workspa
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, JBLOCKROW dst) JDIMENSION num_blocks, JBLOCKROW dst)
/* This version is used for floating-point DCT implementations. */ /* This version is used for floating-point DCT implementations. */
{ {
@@ -553,7 +552,7 @@ forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
float_quantize_method_ptr do_quantize = fdct->float_quantize; float_quantize_method_ptr do_quantize = fdct->float_quantize;
workspace = fdct->float_workspace; workspace = fdct->float_workspace;
sample_data += start_row; /* fold in the vertical offset once */ sample_data += start_row; /* fold in the vertical offset once */
for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) { for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
/* Load data into workspace, applying unsigned->signed conversion */ /* Load data into workspace, applying unsigned->signed conversion */
@@ -649,10 +648,10 @@ quantize_trellis(j_compress_ptr cinfo, c_derived_tbl *actbl, JBLOCKROW coef_bloc
if (Se < Ss) if (Se < Ss)
return; return;
if (cinfo->trellis_eob_opt) { if (cinfo->trellis_eob_opt) {
accumulated_zero_block_cost = (float *)malloc((num_blocks + 1) * SIZEOF(float)); accumulated_zero_block_cost = (float *)malloc((num_blocks + 1) * sizeof(float));
accumulated_block_cost = (float *)malloc((num_blocks + 1) * SIZEOF(float)); accumulated_block_cost = (float *)malloc((num_blocks + 1) * sizeof(float));
block_run_start = (int *)malloc(num_blocks * SIZEOF(int)); block_run_start = (int *)malloc(num_blocks * sizeof(int));
requires_eob = (int *)malloc((num_blocks + 1) * SIZEOF(int)); requires_eob = (int *)malloc((num_blocks + 1) * sizeof(int));
accumulated_zero_block_cost[0] = 0; accumulated_zero_block_cost[0] = 0;
accumulated_block_cost[0] = 0; accumulated_block_cost[0] = 0;
requires_eob[0] = 0; requires_eob[0] = 0;
@@ -879,7 +878,7 @@ jinit_forward_dct (j_compress_ptr cinfo)
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;
@@ -958,12 +957,12 @@ jinit_forward_dct (j_compress_ptr cinfo)
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 */
for (i = 0; i < NUM_QUANT_TBLS; i++) { for (i = 0; i < NUM_QUANT_TBLS; i++) {

181
jchuff.c
View File

@@ -19,7 +19,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jchuff.h" /* Declarations shared with jcphuff.c */ #include "jchuff.h" /* Declarations shared with jcphuff.c */
#include <limits.h> #include <limits.h>
/* /*
@@ -47,9 +47,9 @@
#define JPEG_NBITS_NONZERO(x) (32 - __builtin_clz(x)) #define JPEG_NBITS_NONZERO(x) (32 - __builtin_clz(x))
#define JPEG_NBITS(x) (x ? JPEG_NBITS_NONZERO(x) : 0) #define JPEG_NBITS(x) (x ? JPEG_NBITS_NONZERO(x) : 0)
#else #else
#include "jpeg_nbits_table.h"
#define JPEG_NBITS(x) (jpeg_nbits_table[x]) #define JPEG_NBITS(x) (jpeg_nbits_table[x])
#define JPEG_NBITS_NONZERO(x) JPEG_NBITS(x) #define JPEG_NBITS_NONZERO(x) JPEG_NBITS(x)
#include "jpeg_nbits_table.h"
#endif #endif
#ifndef min #ifndef min
@@ -64,8 +64,8 @@
*/ */
typedef struct { typedef struct {
size_t put_buffer; /* current bit-accumulation buffer */ size_t put_buffer; /* current bit-accumulation buffer */
int put_bits; /* # of bits now in it */ int put_bits; /* # of bits now in it */
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
} savable_state; } savable_state;
@@ -79,12 +79,12 @@ typedef struct {
#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], \
(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], \
(dest).last_dc_val[3] = (src).last_dc_val[3]) (dest).last_dc_val[3] = (src).last_dc_val[3])
#endif #endif
#endif #endif
@@ -92,17 +92,17 @@ typedef struct {
typedef struct { typedef struct {
struct jpeg_entropy_encoder pub; /* public fields */ struct jpeg_entropy_encoder pub; /* public fields */
savable_state saved; /* Bit buffer & DC state at start of MCU */ savable_state saved; /* Bit buffer & DC state at start of MCU */
/* These fields are NOT loaded into local working state. */ /* These fields are NOT loaded into local working state. */
unsigned int restarts_to_go; /* MCUs left in this restart interval */ unsigned int restarts_to_go; /* MCUs left in this restart interval */
int next_restart_num; /* next restart number to write (0-7) */ int next_restart_num; /* next restart number to write (0-7) */
/* Pointers to derived tables (these workspaces have image lifespan) */ /* Pointers to derived tables (these workspaces have image lifespan) */
c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]; c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS]; c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
#ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */ #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
long * dc_count_ptrs[NUM_HUFF_TBLS]; long * dc_count_ptrs[NUM_HUFF_TBLS];
long * ac_count_ptrs[NUM_HUFF_TBLS]; long * ac_count_ptrs[NUM_HUFF_TBLS];
#endif #endif
@@ -115,21 +115,20 @@ typedef huff_entropy_encoder * huff_entropy_ptr;
*/ */
typedef struct { typedef struct {
JOCTET * next_output_byte; /* => next byte to write in buffer */ JOCTET * next_output_byte; /* => next byte to write in buffer */
size_t free_in_buffer; /* # of byte spaces remaining in buffer */ size_t free_in_buffer; /* # of byte spaces remaining in buffer */
savable_state cur; /* Current bit buffer & DC state */ savable_state cur; /* Current bit buffer & DC state */
j_compress_ptr cinfo; /* dump_buffer needs access to this */ j_compress_ptr cinfo; /* dump_buffer needs access to this */
} working_state; } working_state;
/* Forward declarations */ /* Forward declarations */
METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo, METHODDEF(boolean) encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data);
JBLOCKROW *MCU_data)); METHODDEF(void) finish_pass_huff (j_compress_ptr cinfo);
METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
#ifdef ENTROPY_OPT_SUPPORTED #ifdef ENTROPY_OPT_SUPPORTED
METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo, METHODDEF(boolean) encode_mcu_gather (j_compress_ptr cinfo,
JBLOCKROW *MCU_data)); JBLOCKROW *MCU_data);
METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo)); METHODDEF(void) finish_pass_gather (j_compress_ptr cinfo);
#endif #endif
@@ -167,29 +166,29 @@ start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
/* Check for invalid table indexes */ /* Check for invalid table indexes */
/* (make_c_derived_tbl does this in the other path) */ /* (make_c_derived_tbl does this in the other path) */
if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS) if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl); ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
if (actbl < 0 || actbl >= NUM_HUFF_TBLS) if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl); ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
/* Allocate and zero the statistics tables */ /* Allocate and zero the statistics tables */
/* 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
} else { } else {
/* 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;
@@ -214,7 +213,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;
c_derived_tbl *dtbl; c_derived_tbl *dtbl;
@@ -239,7 +238,7 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
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;
/* Figure C.1: make table of Huffman code length for each symbol */ /* Figure C.1: make table of Huffman code length for each symbol */
@@ -247,7 +246,7 @@ 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;
@@ -282,7 +281,7 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
* this lets us detect duplicate VAL entries here, and later * this lets us detect duplicate VAL entries here, and later
* allows emit_bits to detect any attempt to emit such symbols. * allows emit_bits to detect any attempt to emit such symbols.
*/ */
MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi)); MEMZERO(dtbl->ehufsi, sizeof(dtbl->ehufsi));
/* This is also a convenient place to check for out-of-range /* This is also a convenient place to check for out-of-range
* and duplicated VAL entries. We allow 0..255 for AC symbols * and duplicated VAL entries. We allow 0..255 for AC symbols
@@ -305,10 +304,10 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
/* 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)
@@ -456,7 +455,7 @@ flush_bits (working_state * state)
PUT_BITS(0x7F, 7) PUT_BITS(0x7F, 7)
while (put_bits >= 8) EMIT_BYTE() while (put_bits >= 8) EMIT_BYTE()
state->cur.put_buffer = 0; /* and reset bit-buffer to empty */ state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
state->cur.put_bits = 0; state->cur.put_bits = 0;
STORE_BUFFER() STORE_BUFFER()
@@ -468,7 +467,7 @@ flush_bits (working_state * state)
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;
int nbits; int nbits;
@@ -518,7 +517,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
/* Encode the AC coefficients per section F.1.2.2 */ /* Encode the AC coefficients per section F.1.2.2 */
r = 0; /* r = run length of zeros */ r = 0; /* r = run length of zeros */
/* Manually unroll the k loop to eliminate the counter variable. This /* Manually unroll the k loop to eliminate the counter variable. This
* improves performance greatly on systems with a limited number of * improves performance greatly on systems with a limited number of
@@ -624,7 +623,7 @@ encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
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;
} }
/* Encode the MCU data blocks */ /* Encode the MCU data blocks */
@@ -632,9 +631,9 @@ encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
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]))
return FALSE; return FALSE;
/* Update last_dc_val */ /* Update last_dc_val */
state.cur.last_dc_val[ci] = MCU_data[blkn][0][0]; state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
@@ -704,7 +703,7 @@ finish_pass_huff (j_compress_ptr cinfo)
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;
register int nbits; register int nbits;
@@ -733,7 +732,7 @@ htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
/* Encode the AC coefficients per section F.1.2.2 */ /* Encode the AC coefficients per section F.1.2.2 */
r = 0; /* r = run length of zeros */ r = 0; /* r = run length of zeros */
for (k = 1; k < DCTSIZE2; k++) { for (k = 1; k < DCTSIZE2; k++) {
if ((temp = block[jpeg_natural_order[k]]) == 0) { if ((temp = block[jpeg_natural_order[k]]) == 0) {
@@ -741,21 +740,21 @@ htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
} else { } else {
/* if run length > 15, must emit special run-length-16 codes (0xF0) */ /* if run length > 15, must emit special run-length-16 codes (0xF0) */
while (r > 15) { while (r > 15) {
ac_counts[0xF0]++; ac_counts[0xF0]++;
r -= 16; r -= 16;
} }
/* Find the number of bits needed for the magnitude of the coefficient */ /* Find the number of bits needed for the magnitude of the coefficient */
if (temp < 0) if (temp < 0)
temp = -temp; temp = -temp;
/* 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 = 1; /* there must be at least one 1 bit */ nbits = 1; /* there must be at least one 1 bit */
while ((temp >>= 1)) while ((temp >>= 1))
nbits++; nbits++;
/* Check for out-of-range coefficient values */ /* Check for out-of-range coefficient values */
if (nbits > MAX_COEF_BITS) if (nbits > MAX_COEF_BITS)
ERREXIT(cinfo, JERR_BAD_DCT_COEF); ERREXIT(cinfo, JERR_BAD_DCT_COEF);
/* Count Huffman symbol for run length / number of bits */ /* Count Huffman symbol for run length / number of bits */
ac_counts[(r << 4) + nbits]++; ac_counts[(r << 4) + nbits]++;
@@ -787,7 +786,7 @@ encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
if (entropy->restarts_to_go == 0) { if (entropy->restarts_to_go == 0) {
/* Re-initialize DC predictions to 0 */ /* Re-initialize DC predictions to 0 */
for (ci = 0; ci < cinfo->comps_in_scan; ci++) for (ci = 0; ci < cinfo->comps_in_scan; ci++)
entropy->saved.last_dc_val[ci] = 0; entropy->saved.last_dc_val[ci] = 0;
/* Update restart state */ /* Update restart state */
entropy->restarts_to_go = cinfo->restart_interval; entropy->restarts_to_go = cinfo->restart_interval;
} }
@@ -798,8 +797,8 @@ encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
ci = cinfo->MCU_membership[blkn]; ci = cinfo->MCU_membership[blkn];
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci], htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
entropy->dc_count_ptrs[compptr->dc_tbl_no], entropy->dc_count_ptrs[compptr->dc_tbl_no],
entropy->ac_count_ptrs[compptr->ac_tbl_no]); entropy->ac_count_ptrs[compptr->ac_tbl_no]);
entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0]; entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
} }
@@ -838,22 +837,22 @@ 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;
int p, i, j; int p, i, j;
long v; long v;
/* This algorithm is explained in section K.2 of the JPEG standard */ /* This algorithm is explained in section K.2 of the JPEG standard */
MEMZERO(bits, SIZEOF(bits)); MEMZERO(bits, sizeof(bits));
MEMZERO(codesize, SIZEOF(codesize)); MEMZERO(codesize, sizeof(codesize));
for (i = 0; i < 257; i++) for (i = 0; i < 257; i++)
others[i] = -1; /* init links to empty */ others[i] = -1; /* init links to empty */
freq[256] = 1; /* make sure 256 has a nonzero count */ freq[256] = 1; /* make sure 256 has a nonzero count */
/* Including the pseudo-symbol 256 in the Huffman procedure guarantees /* Including the pseudo-symbol 256 in the Huffman procedure guarantees
* that no real symbol is given code-value of all ones, because 256 * that no real symbol is given code-value of all ones, because 256
* will be placed last in the largest codeword category. * will be placed last in the largest codeword category.
@@ -868,8 +867,8 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
v = 1000000000L; v = 1000000000L;
for (i = 0; i <= 256; i++) { for (i = 0; i <= 256; i++) {
if (freq[i] && freq[i] <= v) { if (freq[i] && freq[i] <= v) {
v = freq[i]; v = freq[i];
c1 = i; c1 = i;
} }
} }
@@ -879,8 +878,8 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
v = 1000000000L; v = 1000000000L;
for (i = 0; i <= 256; i++) { for (i = 0; i <= 256; i++) {
if (freq[i] && freq[i] <= v && i != c1) { if (freq[i] && freq[i] <= v && i != c1) {
v = freq[i]; v = freq[i];
c2 = i; c2 = i;
} }
} }
@@ -899,7 +898,7 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
codesize[c1]++; codesize[c1]++;
} }
others[c1] = c2; /* chain c2 onto c1's tree branch */ others[c1] = c2; /* chain c2 onto c1's tree branch */
/* Increment the codesize of everything in c2's tree branch */ /* Increment the codesize of everything in c2's tree branch */
codesize[c2]++; codesize[c2]++;
@@ -915,7 +914,7 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
/* The JPEG standard seems to think that this can't happen, */ /* The JPEG standard seems to think that this can't happen, */
/* but I'm paranoid... */ /* but I'm paranoid... */
if (codesize[i] > MAX_CLEN) if (codesize[i] > MAX_CLEN)
ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW); ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
bits[codesize[i]]++; bits[codesize[i]]++;
} }
@@ -934,24 +933,24 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
for (i = MAX_CLEN; i > 16; i--) { for (i = MAX_CLEN; i > 16; i--) {
while (bits[i] > 0) { while (bits[i] > 0) {
j = i - 2; /* find length of new prefix to be used */ j = i - 2; /* find length of new prefix to be used */
while (bits[j] == 0) while (bits[j] == 0)
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 */
} }
} }
/* Remove the count for the pseudo-symbol 256 from the largest codelength */ /* Remove the count for the pseudo-symbol 256 from the largest codelength */
while (bits[i] == 0) /* find largest codelength still in use */ while (bits[i] == 0) /* find largest codelength still in use */
i--; i--;
bits[i]--; bits[i]--;
/* Return final symbol counts (only for lengths 0..16) */ /* Return final symbol counts (only for lengths 0..16) */
MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits)); MEMCOPY(htbl->bits, bits, sizeof(htbl->bits));
/* 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
@@ -961,8 +960,8 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
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++;
} }
} }
} }
@@ -989,8 +988,8 @@ finish_pass_gather (j_compress_ptr cinfo)
/* It's important not to apply jpeg_gen_optimal_table more than once /* It's important not to apply jpeg_gen_optimal_table more than once
* per table, because it clobbers the input frequency counts! * per table, because it clobbers the input frequency counts!
*/ */
MEMZERO(did_dc, SIZEOF(did_dc)); MEMZERO(did_dc, sizeof(did_dc));
MEMZERO(did_ac, SIZEOF(did_ac)); MEMZERO(did_ac, sizeof(did_ac));
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];
@@ -999,14 +998,14 @@ finish_pass_gather (j_compress_ptr cinfo)
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;
} }
@@ -1029,7 +1028,7 @@ jinit_huff_encoder (j_compress_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_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;

View File

@@ -1,10 +1,12 @@
/* /*
* jchuff.h * jchuff.h
* *
* 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.
* It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* mozjpeg Modifications: * mozjpeg Modifications:
* Copyright (C) 2014, Mozilla Corporation. * Copyright (C) 2014, Mozilla Corporation.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains declarations for Huffman entropy encoding routines * This file contains declarations for Huffman entropy encoding routines
@@ -27,27 +29,20 @@
/* Derived data constructed for each Huffman table */ /* Derived data constructed for each Huffman table */
typedef struct { typedef struct {
unsigned int ehufco[256]; /* code for each symbol */ unsigned int ehufco[256]; /* code for each symbol */
char ehufsi[256]; /* length of code for each symbol */ char ehufsi[256]; /* length of code for each symbol */
/* If no code has been allocated for a symbol S, ehufsi[S] contains 0 */ /* If no code has been allocated for a symbol S, ehufsi[S] contains 0 */
} c_derived_tbl; } c_derived_tbl;
/* Short forms of external names for systems with brain-damaged linkers. */
#ifdef NEED_SHORT_EXTERNAL_NAMES
#define jpeg_make_c_derived_tbl jMkCDerived
#define jpeg_gen_optimal_table jGenOptTbl
#endif /* NEED_SHORT_EXTERNAL_NAMES */
/* 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
JPP((j_compress_ptr cinfo, boolean isDC, int tblno, (j_compress_ptr cinfo, boolean isDC, 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
JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])); (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]);
EXTERN(void) quantize_trellis EXTERN(void) quantize_trellis
JPP((j_compress_ptr cinfo, c_derived_tbl *actbl, JBLOCKROW coef_blocks, JBLOCKROW src, JDIMENSION num_blocks, (j_compress_ptr cinfo, c_derived_tbl *actbl, JBLOCKROW coef_blocks, JBLOCKROW src, JDIMENSION num_blocks,
JQUANT_TBL * qtbl, double *norm_src, double *norm_coef)); JQUANT_TBL * qtbl, double *norm_src, double *norm_coef);

View File

@@ -1,8 +1,10 @@
/* /*
* jcmainct.c * jcmainct.c
* *
* 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.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains the main buffer controller for compression. * This file contains the main buffer controller for compression.
@@ -28,10 +30,10 @@
typedef struct { typedef struct {
struct jpeg_c_main_controller pub; /* public fields */ struct jpeg_c_main_controller pub; /* public fields */
JDIMENSION cur_iMCU_row; /* number of current iMCU row */ JDIMENSION cur_iMCU_row; /* number of current iMCU row */
JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */ JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
boolean suspended; /* remember if we suspended output */ boolean suspended; /* remember if we suspended output */
J_BUF_MODE pass_mode; /* current operating mode */ J_BUF_MODE pass_mode; /* current operating mode */
/* If using just a strip buffer, this points to the entire set of buffers /* If using just a strip buffer, this points to the entire set of buffers
* (we allocate one for each component). In the full-image case, this * (we allocate one for each component). In the full-image case, this
@@ -52,12 +54,12 @@ typedef my_main_controller * my_main_ptr;
/* Forward declarations */ /* Forward declarations */
METHODDEF(void) process_data_simple_main METHODDEF(void) process_data_simple_main
JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf, (j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail)); JDIMENSION in_rows_avail);
#ifdef FULL_MAIN_BUFFER_SUPPORTED #ifdef FULL_MAIN_BUFFER_SUPPORTED
METHODDEF(void) process_data_buffer_main METHODDEF(void) process_data_buffer_main
JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf, (j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail)); JDIMENSION in_rows_avail);
#endif #endif
@@ -74,10 +76,10 @@ start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
if (cinfo->raw_data_in) if (cinfo->raw_data_in)
return; return;
main_ptr->cur_iMCU_row = 0; /* initialize counters */ main_ptr->cur_iMCU_row = 0; /* initialize counters */
main_ptr->rowgroup_ctr = 0; main_ptr->rowgroup_ctr = 0;
main_ptr->suspended = FALSE; main_ptr->suspended = FALSE;
main_ptr->pass_mode = pass_mode; /* save mode for use by process_data */ main_ptr->pass_mode = pass_mode; /* save mode for use by process_data */
switch (pass_mode) { switch (pass_mode) {
case JBUF_PASS_THRU: case JBUF_PASS_THRU:
@@ -111,8 +113,8 @@ 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, JDIMENSION *in_row_ctr, JSAMPARRAY input_buf, 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;
@@ -120,9 +122,9 @@ process_data_simple_main (j_compress_ptr cinfo,
/* 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, in_rows_avail, input_buf, in_row_ctr, in_rows_avail,
main_ptr->buffer, &main_ptr->rowgroup_ctr, main_ptr->buffer, &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
@@ -140,8 +142,8 @@ process_data_simple_main (j_compress_ptr cinfo,
* 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;
} }
return; return;
} }
@@ -167,8 +169,8 @@ process_data_simple_main (j_compress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
process_data_buffer_main (j_compress_ptr cinfo, process_data_buffer_main (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)
{ {
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
int ci; int ci;
@@ -179,16 +181,16 @@ process_data_buffer_main (j_compress_ptr cinfo,
/* Realign the virtual buffers if at the start of an iMCU row. */ /* Realign the virtual buffers if at the start of an iMCU row. */
if (main_ptr->rowgroup_ctr == 0) { if (main_ptr->rowgroup_ctr == 0) {
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->access_virt_sarray) main_ptr->buffer[ci] = (*cinfo->mem->access_virt_sarray)
((j_common_ptr) cinfo, main_ptr->whole_image[ci], ((j_common_ptr) cinfo, main_ptr->whole_image[ci],
main_ptr->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE), main_ptr->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
(JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing); (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
} }
/* In a read pass, pretend we just read some source data. */ /* In a read pass, pretend we just read some source data. */
if (! writing) { if (! writing) {
*in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE; *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
main_ptr->rowgroup_ctr = DCTSIZE; main_ptr->rowgroup_ctr = DCTSIZE;
} }
} }
@@ -196,35 +198,35 @@ process_data_buffer_main (j_compress_ptr cinfo,
/* Note: preprocessor will pad if necessary to fill the last iMCU row. */ /* Note: preprocessor will pad if necessary to fill the last iMCU row. */
if (writing) { if (writing) {
(*cinfo->prep->pre_process_data) (cinfo, (*cinfo->prep->pre_process_data) (cinfo,
input_buf, in_row_ctr, in_rows_avail, input_buf, in_row_ctr, in_rows_avail,
main_ptr->buffer, &main_ptr->rowgroup_ctr, main_ptr->buffer, &main_ptr->rowgroup_ctr,
(JDIMENSION) DCTSIZE); (JDIMENSION) DCTSIZE);
/* Return to application if we need more data to fill the iMCU row. */ /* Return to application if we need more data to fill the iMCU row. */
if (main_ptr->rowgroup_ctr < DCTSIZE) if (main_ptr->rowgroup_ctr < DCTSIZE)
return; return;
} }
/* Emit data, unless this is a sink-only pass. */ /* Emit data, unless this is a sink-only pass. */
if (main_ptr->pass_mode != JBUF_SAVE_SOURCE) { if (main_ptr->pass_mode != JBUF_SAVE_SOURCE) {
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;
} }
return; return;
} }
/* We did finish the row. Undo our little suspension hack if a previous /* We did finish the row. Undo our little suspension hack if a previous
* call suspended; then mark the main buffer empty. * call suspended; then mark the main buffer empty.
*/ */
if (main_ptr->suspended) { if (main_ptr->suspended) {
(*in_row_ctr)++; (*in_row_ctr)++;
main_ptr->suspended = FALSE; main_ptr->suspended = FALSE;
} }
} }
@@ -250,7 +252,7 @@ jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
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;
@@ -266,13 +268,13 @@ jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
/* Allocate a full-image virtual array for each component */ /* Allocate a full-image virtual array for each component */
/* Note we pad the bottom to a multiple of the iMCU height */ /* Note we pad the bottom to a multiple of the iMCU height */
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->whole_image[ci] = (*cinfo->mem->request_virt_sarray) main_ptr->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
compptr->width_in_blocks * DCTSIZE, compptr->width_in_blocks * DCTSIZE,
(JDIMENSION) jround_up((long) compptr->height_in_blocks, (JDIMENSION) jround_up((long) compptr->height_in_blocks,
(long) compptr->v_samp_factor) * DCTSIZE, (long) compptr->v_samp_factor) * DCTSIZE,
(JDIMENSION) (compptr->v_samp_factor * DCTSIZE)); (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
} }
#else #else
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
@@ -283,11 +285,11 @@ jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
#endif #endif
/* Allocate a strip buffer for each component */ /* Allocate a strip buffer for each component */
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

@@ -17,7 +17,7 @@
#include "jpegcomp.h" #include "jpegcomp.h"
typedef enum { /* JPEG marker codes */ typedef enum { /* JPEG marker codes */
M_SOF0 = 0xc0, M_SOF0 = 0xc0,
M_SOF1 = 0xc1, M_SOF1 = 0xc1,
M_SOF2 = 0xc2, M_SOF2 = 0xc2,
@@ -173,7 +173,7 @@ emit_dqt (j_compress_ptr cinfo, int index)
/* 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));
} }
@@ -193,7 +193,7 @@ emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
if (is_ac) { if (is_ac) {
htbl = cinfo->ac_huff_tbl_ptrs[index]; htbl = cinfo->ac_huff_tbl_ptrs[index];
index += 0x10; /* output index has AC bit set */ index += 0x10; /* output index has AC bit set */
} else { } else {
htbl = cinfo->dc_huff_tbl_ptrs[index]; htbl = cinfo->dc_huff_tbl_ptrs[index];
} }
@@ -258,12 +258,12 @@ emit_dac (j_compress_ptr cinfo)
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);
emit_byte(cinfo, cinfo->arith_ac_K[i]); emit_byte(cinfo, cinfo->arith_ac_K[i]);
} }
} }
} }
@@ -277,7 +277,7 @@ emit_dri (j_compress_ptr cinfo)
{ {
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);
} }
@@ -354,22 +354,22 @@ emit_jfif_app0 (j_compress_ptr cinfo)
/* Emit a JFIF-compliant APP0 marker */ /* Emit a JFIF-compliant APP0 marker */
{ {
/* /*
* Length of APP0 block (2 bytes) * Length of APP0 block (2 bytes)
* Block ID (4 bytes - ASCII "JFIF") * Block ID (4 bytes - ASCII "JFIF")
* Zero byte (1 byte to terminate the ID string) * Zero byte (1 byte to terminate the ID string)
* Version Major, Minor (2 bytes - major first) * Version Major, Minor (2 bytes - major first)
* Units (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm) * Units (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm)
* Xdpu (2 bytes - dots per unit horizontal) * Xdpu (2 bytes - dots per unit horizontal)
* Ydpu (2 bytes - dots per unit vertical) * Ydpu (2 bytes - dots per unit vertical)
* Thumbnail X size (1 byte) * Thumbnail X size (1 byte)
* Thumbnail Y size (1 byte) * Thumbnail Y size (1 byte)
*/ */
emit_marker(cinfo, M_APP0); emit_marker(cinfo, M_APP0);
emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */ emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */ emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
emit_byte(cinfo, 0x46); emit_byte(cinfo, 0x46);
emit_byte(cinfo, 0x49); emit_byte(cinfo, 0x49);
emit_byte(cinfo, 0x46); emit_byte(cinfo, 0x46);
@@ -379,7 +379,7 @@ emit_jfif_app0 (j_compress_ptr cinfo)
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);
} }
@@ -389,12 +389,12 @@ emit_adobe_app14 (j_compress_ptr cinfo)
/* Emit an Adobe APP14 marker */ /* Emit an Adobe APP14 marker */
{ {
/* /*
* Length of APP14 block (2 bytes) * Length of APP14 block (2 bytes)
* Block ID (5 bytes - ASCII "Adobe") * Block ID (5 bytes - ASCII "Adobe")
* Version Number (2 bytes - currently 100) * Version Number (2 bytes - currently 100)
* Flags0 (2 bytes - currently 0) * Flags0 (2 bytes - currently 0)
* Flags1 (2 bytes - currently 0) * Flags1 (2 bytes - currently 0)
* Color transform (1 byte) * Color transform (1 byte)
* *
* Although Adobe TN 5116 mentions Version = 101, all the Adobe files * Although Adobe TN 5116 mentions Version = 101, all the Adobe files
* now in circulation seem to use Version = 100, so that's what we write. * now in circulation seem to use Version = 100, so that's what we write.
@@ -408,23 +408,23 @@ emit_adobe_app14 (j_compress_ptr cinfo)
emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */ emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */ emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
emit_byte(cinfo, 0x64); emit_byte(cinfo, 0x64);
emit_byte(cinfo, 0x6F); emit_byte(cinfo, 0x6F);
emit_byte(cinfo, 0x62); emit_byte(cinfo, 0x62);
emit_byte(cinfo, 0x65); emit_byte(cinfo, 0x65);
emit_2bytes(cinfo, 100); /* Version */ emit_2bytes(cinfo, 100); /* Version */
emit_2bytes(cinfo, 0); /* Flags0 */ emit_2bytes(cinfo, 0); /* Flags0 */
emit_2bytes(cinfo, 0); /* Flags1 */ emit_2bytes(cinfo, 0); /* Flags1 */
switch (cinfo->jpeg_color_space) { switch (cinfo->jpeg_color_space) {
case JCS_YCbCr: case JCS_YCbCr:
emit_byte(cinfo, 1); /* Color transform = 1 */ emit_byte(cinfo, 1); /* Color transform = 1 */
break; break;
case JCS_YCCK: case JCS_YCCK:
emit_byte(cinfo, 2); /* Color transform = 2 */ emit_byte(cinfo, 2); /* Color transform = 2 */
break; break;
default: default:
emit_byte(cinfo, 0); /* Color transform = 0 */ emit_byte(cinfo, 0); /* Color transform = 0 */
break; break;
} }
} }
@@ -442,12 +442,12 @@ 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)
@@ -474,12 +474,12 @@ 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 */
/* SOI is defined to reset restart interval to 0 */ /* SOI is defined to reset restart interval to 0 */
marker->last_restart_interval = 0; marker->last_restart_interval = 0;
if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */ if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
emit_jfif_app0(cinfo); emit_jfif_app0(cinfo);
if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */ if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
emit_adobe_app14(cinfo); emit_adobe_app14(cinfo);
@@ -520,9 +520,9 @@ write_frame_header (j_compress_ptr cinfo)
} else { } else {
is_baseline = TRUE; is_baseline = TRUE;
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->dc_tbl_no > 1 || compptr->ac_tbl_no > 1) if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
is_baseline = FALSE; is_baseline = FALSE;
} }
if (prec && is_baseline) { if (prec && is_baseline) {
is_baseline = FALSE; is_baseline = FALSE;
@@ -539,11 +539,11 @@ write_frame_header (j_compress_ptr cinfo)
emit_sof(cinfo, M_SOF9); /* SOF code for sequential arithmetic */ emit_sof(cinfo, M_SOF9); /* SOF code for sequential arithmetic */
} else { } else {
if (cinfo->progressive_mode) if (cinfo->progressive_mode)
emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */ emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
else if (is_baseline) else if (is_baseline)
emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */ emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
else else
emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */ emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
} }
} }
@@ -575,10 +575,10 @@ write_scan_header (j_compress_ptr cinfo)
compptr = cinfo->cur_comp_info[i]; compptr = cinfo->cur_comp_info[i];
/* DC needs no table for refinement scan */ /* DC needs no table for refinement scan */
if (cinfo->Ss == 0 && cinfo->Ah == 0) if (cinfo->Ss == 0 && cinfo->Ah == 0)
emit_dht(cinfo, compptr->dc_tbl_no, FALSE); emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
/* AC needs no table when not present */ /* AC needs no table when not present */
if (cinfo->Se) if (cinfo->Se)
emit_dht(cinfo, compptr->ac_tbl_no, TRUE); emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
} }
} }
@@ -627,9 +627,9 @@ write_tables_only (j_compress_ptr cinfo)
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);
if (cinfo->ac_huff_tbl_ptrs[i] != NULL) if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
emit_dht(cinfo, i, TRUE); emit_dht(cinfo, i, TRUE);
} }
} }
@@ -649,7 +649,7 @@ jinit_marker_writer (j_compress_ptr cinfo)
/* 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;

View File

@@ -25,21 +25,21 @@
/* Private state */ /* Private state */
typedef enum { typedef enum {
main_pass, /* input data, also do first output step */ main_pass, /* input data, also do first output step */
huff_opt_pass, /* Huffman code optimization pass */ huff_opt_pass, /* Huffman code optimization pass */
output_pass, /* data output pass */ output_pass, /* data output pass */
trellis_pass /* trellis quantization pass */ trellis_pass /* trellis quantization pass */
} c_pass_type; } c_pass_type;
typedef struct { typedef struct {
struct jpeg_comp_master pub; /* public fields */ struct jpeg_comp_master pub; /* public fields */
c_pass_type pass_type; /* the type of the current pass */ c_pass_type pass_type; /* the type of the current pass */
int pass_number; /* # of passes completed */ int pass_number; /* # of passes completed */
int total_passes; /* total # of passes needed */ int total_passes; /* total # of passes needed */
int scan_number; /* current index in scan_info[] */ int scan_number; /* current index in scan_info[] */
/* fields for scan optimisation */ /* fields for scan optimisation */
int pass_number_scan_opt_base; /* pass number where scan optimization begins */ int pass_number_scan_opt_base; /* pass number where scan optimization begins */
@@ -120,7 +120,7 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
/* Check that number of components won't exceed internal array sizes */ /* Check that number of components won't exceed internal array sizes */
if (cinfo->num_components > MAX_COMPONENTS) if (cinfo->num_components > MAX_COMPONENTS)
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
MAX_COMPONENTS); MAX_COMPONENTS);
/* Compute maximum sampling factors; check factor validity */ /* Compute maximum sampling factors; check factor validity */
cinfo->max_h_samp_factor = 1; cinfo->max_h_samp_factor = 1;
@@ -128,12 +128,12 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
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->h_samp_factor>MAX_SAMP_FACTOR ||
compptr->v_samp_factor<=0 || compptr->v_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);
cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
compptr->v_samp_factor); compptr->v_samp_factor);
} }
/* Compute dimensions of components */ /* Compute dimensions of components */
@@ -150,17 +150,17 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
/* 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;
} }
@@ -170,7 +170,7 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
*/ */
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));
} }
@@ -213,7 +213,7 @@ validate_script (j_compress_ptr cinfo)
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;
#else #else
ERREXIT(cinfo, JERR_NOT_COMPILED); ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif #endif
@@ -231,10 +231,10 @@ validate_script (j_compress_ptr cinfo)
for (ci = 0; ci < ncomps; ci++) { for (ci = 0; ci < ncomps; ci++) {
thisi = scanptr->component_index[ci]; thisi = scanptr->component_index[ci];
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 */
Ss = scanptr->Ss; Ss = scanptr->Ss;
@@ -256,43 +256,43 @@ validate_script (j_compress_ptr cinfo)
#define MAX_AH_AL 13 #define MAX_AH_AL 13
#endif #endif
if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 || if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL) Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
if (Ss == 0) { if (Ss == 0) {
if (Se != 0) /* DC and AC together not OK */ if (Se != 0) /* DC and AC together not OK */
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
} else { } else {
if (ncomps != 1) /* AC scans must be for only one component */ if (ncomps != 1) /* AC scans must be for only one component */
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++) {
if (last_bitpos_ptr[coefi] < 0) { if (last_bitpos_ptr[coefi] < 0) {
/* first scan of this coefficient */ /* first scan of this coefficient */
if (Ah != 0) if (Ah != 0)
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;
} }
} }
#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++) {
thisi = scanptr->component_index[ci]; thisi = scanptr->component_index[ci];
if (component_sent[thisi]) if (component_sent[thisi])
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
component_sent[thisi] = TRUE; component_sent[thisi] = TRUE;
} }
} }
} }
@@ -307,13 +307,13 @@ validate_script (j_compress_ptr cinfo)
*/ */
for (ci = 0; ci < cinfo->num_components; ci++) { for (ci = 0; ci < cinfo->num_components; ci++) {
if (last_bitpos[ci][0] < 0) if (last_bitpos[ci][0] < 0)
ERREXIT(cinfo, JERR_MISSING_DATA); ERREXIT(cinfo, JERR_MISSING_DATA);
} }
#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);
} }
} }
} }
@@ -348,7 +348,7 @@ select_scan_parameters (j_compress_ptr cinfo)
cinfo->comps_in_scan = scanptr->comps_in_scan; cinfo->comps_in_scan = scanptr->comps_in_scan;
for (ci = 0; ci < scanptr->comps_in_scan; ci++) { for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
cinfo->cur_comp_info[ci] = cinfo->cur_comp_info[ci] =
&cinfo->comp_info[scanptr->component_index[ci]]; &cinfo->comp_info[scanptr->component_index[ci]];
} }
cinfo->Ss = scanptr->Ss; cinfo->Ss = scanptr->Ss;
cinfo->Se = scanptr->Se; cinfo->Se = scanptr->Se;
@@ -363,7 +363,7 @@ select_scan_parameters (j_compress_ptr cinfo)
if (master->scan_number >= cinfo->num_scans_luma+cinfo->num_scans_chroma_dc+(6*cinfo->Al_max_chroma+4) && if (master->scan_number >= cinfo->num_scans_luma+cinfo->num_scans_chroma_dc+(6*cinfo->Al_max_chroma+4) &&
master->scan_number < cinfo->num_scans) master->scan_number < cinfo->num_scans)
cinfo->Al = master->best_Al_chroma; cinfo->Al = master->best_Al_chroma;
} }
} }
else else
#endif #endif
@@ -371,7 +371,7 @@ select_scan_parameters (j_compress_ptr cinfo)
/* Prepare for single sequential-JPEG scan containing all components */ /* Prepare for single sequential-JPEG scan containing all components */
if (cinfo->num_components > MAX_COMPS_IN_SCAN) if (cinfo->num_components > MAX_COMPS_IN_SCAN)
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
MAX_COMPS_IN_SCAN); MAX_COMPS_IN_SCAN);
cinfo->comps_in_scan = cinfo->num_components; cinfo->comps_in_scan = cinfo->num_components;
for (ci = 0; ci < cinfo->num_components; ci++) { for (ci = 0; ci < cinfo->num_components; ci++) {
cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci]; cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
@@ -423,15 +423,15 @@ per_scan_setup (j_compress_ptr cinfo)
/* Interleaved (multi-component) scan */ /* Interleaved (multi-component) scan */
if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN) if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan, ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
MAX_COMPS_IN_SCAN); MAX_COMPS_IN_SCAN);
/* 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;
@@ -452,9 +452,9 @@ per_scan_setup (j_compress_ptr cinfo)
/* Prepare array describing MCU composition */ /* Prepare array describing MCU composition */
mcublks = compptr->MCU_blocks; mcublks = compptr->MCU_blocks;
if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU) if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
ERREXIT(cinfo, JERR_BAD_MCU_SIZE); ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
while (mcublks-- > 0) { while (mcublks-- > 0) {
cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci; cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
} }
} }
@@ -498,8 +498,8 @@ prepare_for_pass (j_compress_ptr cinfo)
(*cinfo->fdct->start_pass) (cinfo); (*cinfo->fdct->start_pass) (cinfo);
(*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding); (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
(*cinfo->coef->start_pass) (cinfo, (*cinfo->coef->start_pass) (cinfo,
(master->total_passes > 1 ? (master->total_passes > 1 ?
JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
(*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU); (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
if (cinfo->optimize_coding) { if (cinfo->optimize_coding) {
/* No immediate data output; postpone writing frame/scan headers */ /* No immediate data output; postpone writing frame/scan headers */
@@ -835,9 +835,9 @@ finish_pass_master (j_compress_ptr cinfo)
if (cinfo->trellis_quant) if (cinfo->trellis_quant)
master->pass_type = trellis_pass; master->pass_type = trellis_pass;
else { else {
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:
@@ -869,7 +869,7 @@ finish_pass_master (j_compress_ptr cinfo)
if (q > 254) q = 254; if (q > 254) q = 254;
if (q < 1) q = 1; if (q < 1) q = 1;
cinfo->quant_tbl_ptrs[i]->quantval[j] = q; cinfo->quant_tbl_ptrs[i]->quantval[j] = q;
} }
} }
} }
} }
@@ -891,7 +891,7 @@ jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
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;
@@ -912,7 +912,7 @@ jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
cinfo->num_scans = 1; cinfo->num_scans = 1;
} }
if (cinfo->progressive_mode && !cinfo->arith_code) /* TEMPORARY HACK ??? */ if (cinfo->progressive_mode && !cinfo->arith_code) /* TEMPORARY HACK ??? */
cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */ cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
/* Initialize my private state */ /* Initialize my private state */
@@ -942,7 +942,7 @@ jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
for (i = 0; i < cinfo->num_scans; i++) for (i = 0; i < cinfo->num_scans; i++)
master->scan_buffer[i] = NULL; master->scan_buffer[i] = NULL;
} }
if (cinfo->trellis_quant) if (cinfo->trellis_quant)
master->pass_number_scan_opt_base = ((cinfo->use_scans_in_trellis) ? 4 : 2) * cinfo->num_components * cinfo->trellis_num_loops; master->pass_number_scan_opt_base = ((cinfo->use_scans_in_trellis) ? 4 : 2) * cinfo->num_components * cinfo->trellis_num_loops;

View File

@@ -1,8 +1,10 @@
/* /*
* jcomapi.c * jcomapi.c
* *
* Copyright (C) 1994-1997, Thomas G. Lane. * This file was part of the Independent JPEG Group's software:
* This file is part of the Independent JPEG Group's software. * Copyright (C) 1994-1997, Thomas G. Lane.0
* It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains application interface routines that are used for both * This file contains application interface routines that are used for both
@@ -72,8 +74,8 @@ jpeg_destroy (j_common_ptr cinfo)
/* NB: mem pointer is NULL if memory mgr failed to initialize. */ /* NB: mem pointer is NULL if memory mgr failed to initialize. */
if (cinfo->mem != NULL) if (cinfo->mem != NULL)
(*cinfo->mem->self_destruct) (cinfo); (*cinfo->mem->self_destruct) (cinfo);
cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */ cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
cinfo->global_state = 0; /* mark it destroyed */ cinfo->global_state = 0; /* mark it destroyed */
} }
@@ -88,8 +90,8 @@ jpeg_alloc_quant_table (j_common_ptr cinfo)
JQUANT_TBL *tbl; JQUANT_TBL *tbl;
tbl = (JQUANT_TBL *) tbl = (JQUANT_TBL *)
(*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL)); (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, sizeof(JQUANT_TBL));
tbl->sent_table = FALSE; /* make sure this is false in any new table */ tbl->sent_table = FALSE; /* make sure this is false in any new table */
return tbl; return tbl;
} }
@@ -100,7 +102,7 @@ jpeg_alloc_huff_table (j_common_ptr cinfo)
JHUFF_TBL *tbl; JHUFF_TBL *tbl;
tbl = (JHUFF_TBL *) tbl = (JHUFF_TBL *)
(*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL)); (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, sizeof(JHUFF_TBL));
tbl->sent_table = FALSE; /* make sure this is false in any new table */ tbl->sent_table = FALSE; /* make sure this is false in any new table */
return tbl; return tbl;
} }

View File

@@ -12,11 +12,8 @@
/* Support arithmetic decoding */ /* Support arithmetic decoding */
#undef D_ARITH_CODING_SUPPORTED #undef D_ARITH_CODING_SUPPORTED
/* Support in-memory source/destination managers */ /* Define to 1 if you have the <locale.h> header file. */
#undef MEM_SRCDST_SUPPORTED #undef HAVE_LOCALE_H
/* Compiler supports function prototypes. */
#undef HAVE_PROTOTYPES
/* Define to 1 if you have the <stddef.h> header file. */ /* Define to 1 if you have the <stddef.h> header file. */
#undef HAVE_STDDEF_H #undef HAVE_STDDEF_H
@@ -24,25 +21,27 @@
/* Define to 1 if you have the <stdlib.h> header file. */ /* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H #undef HAVE_STDLIB_H
/* Compiler supports 'unsigned char'. */ /* Define to 1 if the system has the type `unsigned char'. */
#undef HAVE_UNSIGNED_CHAR #undef HAVE_UNSIGNED_CHAR
/* Compiler supports 'unsigned short'. */ /* Define to 1 if the system has the type `unsigned short'. */
#undef HAVE_UNSIGNED_SHORT #undef HAVE_UNSIGNED_SHORT
/* Compiler does not support pointers to unspecified structures. */ /* Compiler does not support pointers to undefined structures. */
#undef INCOMPLETE_TYPES_BROKEN #undef INCOMPLETE_TYPES_BROKEN
/* Compiler has <strings.h> rather than standard <string.h>. */ /* Support in-memory source/destination managers */
#undef MEM_SRCDST_SUPPORTED
/* Define if you have BSD-like bzero and bcopy in <strings.h> rather than
memset/memcpy in <string.h>. */
#undef NEED_BSD_STRINGS #undef NEED_BSD_STRINGS
/* Linker requires that global names be unique in first 15 characters. */ /* Define if you need to include <sys/types.h> to get size_t. */
#undef NEED_SHORT_EXTERNAL_NAMES
/* Need to include <sys/types.h> in order to obtain size_t. */
#undef NEED_SYS_TYPES_H #undef NEED_SYS_TYPES_H
/* Broken compiler shifts signed values as an unsigned shift. */ /* Define if your (broken) compiler shifts signed values as if they were
unsigned. */
#undef RIGHT_SHIFT_IS_UNSIGNED #undef RIGHT_SHIFT_IS_UNSIGNED
/* Use accelerated SIMD routines. */ /* Use accelerated SIMD routines. */

View File

@@ -1,8 +1,10 @@
/* /*
* jconfig.txt * jconfig.txt
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1994, Thomas G. Lane. * Copyright (C) 1991-1994, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file documents the configuration options that are required to * This file documents the configuration options that are required to
@@ -23,11 +25,6 @@
* #define the symbol if yes, #undef it if no. * #define the symbol if yes, #undef it if no.
*/ */
/* Does your compiler support function prototypes?
* (If not, you also need to use ansi2knr, see install.txt)
*/
#define HAVE_PROTOTYPES
/* Does your compiler support the declaration "unsigned char" ? /* Does your compiler support the declaration "unsigned char" ?
* How about "unsigned short" ? * How about "unsigned short" ?
*/ */
@@ -48,7 +45,7 @@
* If you're not sure, leaving it undefined will work at some cost in speed. * If you're not sure, leaving it undefined will work at some cost in speed.
* If you defined HAVE_UNSIGNED_CHAR then the speed difference is minimal. * If you defined HAVE_UNSIGNED_CHAR then the speed difference is minimal.
*/ */
#undef CHAR_IS_UNSIGNED #undef __CHAR_UNSIGNED__
/* Define this if your system has an ANSI-conforming <stddef.h> file. /* Define this if your system has an ANSI-conforming <stddef.h> file.
*/ */
@@ -69,19 +66,6 @@
*/ */
#undef NEED_SYS_TYPES_H #undef NEED_SYS_TYPES_H
/* For 80x86 machines, you need to define NEED_FAR_POINTERS,
* unless you are using a large-data memory model or 80386 flat-memory mode.
* On less brain-damaged CPUs this symbol must not be defined.
* (Defining this symbol causes large data structures to be referenced through
* "far" pointers and to be allocated with a special version of malloc.)
*/
#undef NEED_FAR_POINTERS
/* Define this if your linker needs global names to be unique in less
* than the first 15 characters.
*/
#undef NEED_SHORT_EXTERNAL_NAMES
/* Although a real ANSI C compiler can deal perfectly well with pointers to /* Although a real ANSI C compiler can deal perfectly well with pointers to
* unspecified structures (see "incomplete types" in the spec), a few pre-ANSI * unspecified structures (see "incomplete types" in the spec), a few pre-ANSI
* and pseudo-ANSI compilers get confused. To keep one of these bozos happy, * and pseudo-ANSI compilers get confused. To keep one of these bozos happy,
@@ -94,10 +78,10 @@
/* Define "boolean" as unsigned char, not int, on Windows systems. /* Define "boolean" as unsigned char, not int, on Windows systems.
*/ */
#ifdef _WIN32 #ifdef _WIN32
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean; typedef unsigned char boolean;
#endif #endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
#endif #endif
@@ -130,11 +114,11 @@ typedef unsigned char boolean;
/* These defines indicate which image (non-JPEG) file formats are allowed. */ /* These defines indicate which image (non-JPEG) file formats are allowed. */
#define BMP_SUPPORTED /* BMP image file format */ #define BMP_SUPPORTED /* BMP image file format */
#define GIF_SUPPORTED /* GIF image file format */ #define GIF_SUPPORTED /* GIF image file format */
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
#undef RLE_SUPPORTED /* Utah RLE image file format */ #undef RLE_SUPPORTED /* Utah RLE image file format */
#define TARGA_SUPPORTED /* Targa image file format */ #define TARGA_SUPPORTED /* Targa image file format */
/* Define this if you want to name both input and output files on the command /* Define this if you want to name both input and output files on the command
* line, rather than using stdout and optionally stdin. You MUST do this if * line, rather than using stdout and optionally stdin. You MUST do this if
@@ -143,12 +127,6 @@ typedef unsigned char boolean;
*/ */
#undef TWO_FILE_COMMANDLINE #undef TWO_FILE_COMMANDLINE
/* Define this if your system needs explicit cleanup of temporary files.
* This is crucial under MS-DOS, where the temporary "files" may be areas
* of extended memory; on most other systems it's not as important.
*/
#undef NEED_SIGNAL_CATCHER
/* By default, we open image files with fopen(...,"rb") or fopen(...,"wb"). /* By default, we open image files with fopen(...,"rb") or fopen(...,"wb").
* This is necessary on systems that distinguish text files from binary files, * This is necessary on systems that distinguish text files from binary files,
* and is harmless on most systems that don't. If you have one of the rare * and is harmless on most systems that don't. If you have one of the rare

11
jconfigint.h.in Normal file
View File

@@ -0,0 +1,11 @@
/* libjpeg-turbo build number */
#undef BUILD
/* How to obtain function inlining. */
#undef INLINE
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Version number of package */
#undef VERSION

122
jcparam.c
View File

@@ -27,8 +27,8 @@
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, boolean force_baseline) int scale_factor, 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
@@ -57,7 +57,7 @@ jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
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;
} }
@@ -117,18 +117,18 @@ jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline)
jpeg_add_quant_table(cinfo, 1, flat_quant_tbl, jpeg_add_quant_table(cinfo, 1, flat_quant_tbl,
cinfo->q_scale_factor[1], force_baseline); cinfo->q_scale_factor[1], force_baseline);
} else { } else {
jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
cinfo->q_scale_factor[0], force_baseline); cinfo->q_scale_factor[0], force_baseline);
jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
cinfo->q_scale_factor[1], force_baseline); cinfo->q_scale_factor[1], force_baseline);
} }
} }
#endif #endif
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
* to use jpeg_set_quality (below); this entry point is provided for * to use jpeg_set_quality (below); this entry point is provided for
@@ -142,11 +142,11 @@ jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
jpeg_add_quant_table(cinfo, 1, flat_quant_tbl, jpeg_add_quant_table(cinfo, 1, flat_quant_tbl,
scale_factor, force_baseline); scale_factor, force_baseline);
} else { } else {
jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
scale_factor, force_baseline); scale_factor, force_baseline);
jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
scale_factor, force_baseline); scale_factor, force_baseline);
} }
} }
@@ -218,12 +218,12 @@ 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 */
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
cinfo->scale_num = 1; /* 1:1 scaling */ cinfo->scale_num = 1; /* 1:1 scaling */
cinfo->scale_denom = 1; cinfo->scale_denom = 1;
#endif #endif
cinfo->data_precision = BITS_IN_JSAMPLE; cinfo->data_precision = BITS_IN_JSAMPLE;
@@ -243,9 +243,9 @@ jpeg_set_defaults (j_compress_ptr cinfo)
cinfo->scan_info = NULL; cinfo->scan_info = NULL;
cinfo->num_scans = 0; cinfo->num_scans = 0;
if (!cinfo->use_moz_defaults) { if (!cinfo->use_moz_defaults) {
/* Default is no multiple-scan output */ /* Default is no multiple-scan output */
cinfo->scan_info = NULL; cinfo->scan_info = NULL;
cinfo->num_scans = 0; cinfo->num_scans = 0;
} }
#else #else
/* Default is no multiple-scan output */ /* Default is no multiple-scan output */
@@ -264,8 +264,8 @@ jpeg_set_defaults (j_compress_ptr cinfo)
/* By default, do extra passes to optimize entropy coding */ /* By default, do extra passes to optimize entropy coding */
cinfo->optimize_coding = TRUE; cinfo->optimize_coding = TRUE;
else else
/* By default, don't do extra passes to optimize entropy coding */ /* By default, don't do extra passes to optimize entropy coding */
cinfo->optimize_coding = FALSE; cinfo->optimize_coding = FALSE;
#else #else
/* By default, don't do extra passes to optimize entropy coding */ /* By default, don't do extra passes to optimize entropy coding */
cinfo->optimize_coding = FALSE; cinfo->optimize_coding = FALSE;
@@ -308,8 +308,8 @@ jpeg_set_defaults (j_compress_ptr cinfo)
*/ */
cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */ cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
cinfo->JFIF_minor_version = 1; cinfo->JFIF_minor_version = 1;
cinfo->density_unit = 0; /* Pixel size is unknown by default */ cinfo->density_unit = 0; /* Pixel size is unknown by default */
cinfo->X_density = 1; /* Pixel aspect ratio is square by default */ cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
cinfo->Y_density = 1; cinfo->Y_density = 1;
/* Choose JPEG colorspace based on input space, set defaults accordingly */ /* Choose JPEG colorspace based on input space, set defaults accordingly */
@@ -455,7 +455,7 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
cinfo->num_components = cinfo->input_components; cinfo->num_components = cinfo->input_components;
if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS) if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
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);
} }
@@ -470,7 +470,7 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
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;
@@ -501,7 +501,7 @@ fill_a_scan_pair (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;
@@ -582,7 +582,7 @@ jpeg_search_progression (j_compress_ptr cinfo)
cinfo->script_space_size = MAX(nscans, 64); cinfo->script_space_size = MAX(nscans, 64);
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;
cinfo->scan_info = scanptr; cinfo->scan_info = scanptr;
@@ -694,16 +694,16 @@ jpeg_simple_progression (j_compress_ptr cinfo)
} else { } else {
/* All-purpose script for other color spaces. */ /* All-purpose script for other color spaces. */
if (cinfo->use_moz_defaults == TRUE) { if (cinfo->use_moz_defaults == TRUE) {
if (ncomps > MAX_COMPS_IN_SCAN) if (ncomps > MAX_COMPS_IN_SCAN)
nscans = 5 * ncomps; /* 2 DC + 4 AC scans per component */ nscans = 5 * ncomps; /* 2 DC + 4 AC scans per component */
else else
nscans = 1 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */ nscans = 1 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
} else { } else {
if (ncomps > MAX_COMPS_IN_SCAN) if (ncomps > MAX_COMPS_IN_SCAN)
nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */ nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
else else
nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */ nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
} }
} }
/* Allocate space for script. /* Allocate space for script.
@@ -717,7 +717,7 @@ jpeg_simple_progression (j_compress_ptr cinfo)
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;
cinfo->scan_info = scanptr; cinfo->scan_info = scanptr;
@@ -727,7 +727,7 @@ jpeg_simple_progression (j_compress_ptr cinfo)
/* Custom script for YCbCr color images. */ /* Custom script for YCbCr color images. */
if (cinfo->use_moz_defaults == TRUE) { if (cinfo->use_moz_defaults == TRUE) {
/* scan defined in jpeg_scan_rgb.txt in jpgcrush */ /* scan defined in jpeg_scan_rgb.txt in jpgcrush */
/* Initial DC scan */ /* Initial DC scan */
if (cinfo->one_dc_scan) if (cinfo->one_dc_scan)
scanptr = fill_dc_scans(scanptr, ncomps, 0, 0); scanptr = fill_dc_scans(scanptr, ncomps, 0, 0);
else { else {
@@ -748,23 +748,23 @@ jpeg_simple_progression (j_compress_ptr cinfo)
scanptr = fill_a_scan(scanptr, 2, 9, 63, 0, 0); scanptr = fill_a_scan(scanptr, 2, 9, 63, 0, 0);
} else { } else {
/* Initial DC scan */ /* Initial DC scan */
scanptr = fill_dc_scans(scanptr, ncomps, 0, 1); scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
/* Initial AC scan: get some luma data out in a hurry */ /* Initial AC scan: get some luma data out in a hurry */
scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2); scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
/* Chroma data is too small to be worth expending many scans on */ /* Chroma data is too small to be worth expending many scans on */
scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1); scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1); scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
/* Complete spectral selection for luma AC */ /* Complete spectral selection for luma AC */
scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2); scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
/* Refine next bit of luma AC */ /* Refine next bit of luma AC */
scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1); scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
/* Finish DC successive approximation */ /* Finish DC successive approximation */
scanptr = fill_dc_scans(scanptr, ncomps, 1, 0); scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
/* Finish AC successive approximation */ /* Finish AC successive approximation */
scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0); scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0); scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
/* Luma bottom bit comes last since it's usually largest scan */ /* Luma bottom bit comes last since it's usually largest scan */
scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0); scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
} }
} else { } else {
/* All-purpose script for other color spaces. */ /* All-purpose script for other color spaces. */
@@ -772,7 +772,7 @@ jpeg_simple_progression (j_compress_ptr cinfo)
/* scan defined in jpeg_scan_bw.txt in jpgcrush */ /* scan defined in jpeg_scan_bw.txt in jpgcrush */
/* DC component, no successive approximation */ /* DC component, no successive approximation */
scanptr = fill_dc_scans(scanptr, ncomps, 0, 0); scanptr = fill_dc_scans(scanptr, ncomps, 0, 0);
/* Successive approximation first pass */ /* Successive approximation first pass */
scanptr = fill_scans(scanptr, ncomps, 1, 8, 0, 2); scanptr = fill_scans(scanptr, ncomps, 1, 8, 0, 2);
scanptr = fill_scans(scanptr, ncomps, 9, 63, 0, 2); scanptr = fill_scans(scanptr, ncomps, 9, 63, 0, 2);
/* Successive approximation second pass */ /* Successive approximation second pass */
@@ -781,17 +781,17 @@ jpeg_simple_progression (j_compress_ptr cinfo)
scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0); scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
} else { } else {
/* Successive approximation first pass */ /* Successive approximation first pass */
scanptr = fill_dc_scans(scanptr, ncomps, 0, 1); scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2); scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2); scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
/* Successive approximation second pass */ /* Successive approximation second pass */
scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1); scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
/* Successive approximation final pass */ /* Successive approximation final pass */
scanptr = fill_dc_scans(scanptr, ncomps, 1, 0); scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0); scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
}
} }
} }
}
#endif /* C_PROGRESSIVE_SUPPORTED */ #endif /* C_PROGRESSIVE_SUPPORTED */

144
jcphuff.c
View File

@@ -1,10 +1,12 @@
/* /*
* jcphuff.c * jcphuff.c
* *
* 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.
* It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* mozjpeg Modifications: * mozjpeg Modifications:
* Copyright (C) 2014, Mozilla Corporation. * Copyright (C) 2014, Mozilla Corporation.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains Huffman entropy encoding routines for progressive JPEG. * This file contains Huffman entropy encoding routines for progressive JPEG.
@@ -17,7 +19,7 @@
#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 "jchuff.h" /* Declarations shared with jchuff.c */
#ifdef C_PROGRESSIVE_SUPPORTED #ifdef C_PROGRESSIVE_SUPPORTED
@@ -32,24 +34,24 @@ typedef struct {
/* Bit-level coding status. /* Bit-level coding status.
* next_output_byte/free_in_buffer are local copies of cinfo->dest fields. * next_output_byte/free_in_buffer are local copies of cinfo->dest fields.
*/ */
JOCTET * next_output_byte; /* => next byte to write in buffer */ JOCTET * next_output_byte; /* => next byte to write in buffer */
size_t free_in_buffer; /* # of byte spaces remaining in buffer */ size_t free_in_buffer; /* # of byte spaces remaining in buffer */
INT32 put_buffer; /* current bit-accumulation buffer */ INT32 put_buffer; /* current bit-accumulation buffer */
int put_bits; /* # of bits now in it */ int put_bits; /* # of bits now in it */
j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */ j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
/* Coding status for DC components */ /* Coding status for DC components */
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
/* Coding status for AC components */ /* Coding status for AC components */
int ac_tbl_no; /* the table number of the single component */ int ac_tbl_no; /* the table number of the single component */
unsigned int EOBRUN; /* run length of EOBs */ unsigned int EOBRUN; /* run length of EOBs */
unsigned int BE; /* # of buffered correction bits before MCU */ unsigned int BE; /* # of buffered correction bits before MCU */
char * bit_buffer; /* buffer for correction bits (1 per char) */ char * bit_buffer; /* buffer for correction bits (1 per char) */
/* packing correction bits tightly would save some space but cost time... */ /* packing correction bits tightly would save some space but cost time... */
unsigned int restarts_to_go; /* MCUs left in this restart interval */ unsigned int restarts_to_go; /* MCUs left in this restart interval */
int next_restart_num; /* next restart number to write (0-7) */ int next_restart_num; /* next restart number to write (0-7) */
/* Pointers to derived tables (these workspaces have image lifespan). /* Pointers to derived tables (these workspaces have image lifespan).
* Since any one scan codes only DC or only AC, we only need one set * Since any one scan codes only DC or only AC, we only need one set
@@ -69,7 +71,7 @@ typedef phuff_entropy_encoder * phuff_entropy_ptr;
* The minimum safe size is 64 bits. * The minimum safe size is 64 bits.
*/ */
#define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */ #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
/* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int rather than INT32. /* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int rather than INT32.
* We assume that int right shift is unsigned if INT32 right shift is, * We assume that int right shift is unsigned if INT32 right shift is,
@@ -77,27 +79,27 @@ 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
/* Forward declarations */ /* Forward declarations */
METHODDEF(boolean) encode_mcu_DC_first JPP((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 JPP((j_compress_ptr cinfo, METHODDEF(boolean) encode_mcu_AC_first (j_compress_ptr cinfo,
JBLOCKROW *MCU_data)); JBLOCKROW *MCU_data);
METHODDEF(boolean) encode_mcu_DC_refine JPP((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 JPP((j_compress_ptr cinfo, METHODDEF(boolean) encode_mcu_AC_refine (j_compress_ptr cinfo,
JBLOCKROW *MCU_data)); JBLOCKROW *MCU_data);
METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo)); METHODDEF(void) finish_pass_phuff (j_compress_ptr cinfo);
METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo)); METHODDEF(void) finish_pass_gather_phuff (j_compress_ptr cinfo);
/* /*
@@ -132,9 +134,9 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
entropy->pub.encode_mcu = encode_mcu_AC_refine; entropy->pub.encode_mcu = encode_mcu_AC_refine;
/* 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));
} }
} }
if (gather_statistics) if (gather_statistics)
@@ -151,8 +153,8 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
entropy->last_dc_val[ci] = 0; entropy->last_dc_val[ci] = 0;
/* Get table index */ /* Get table index */
if (is_DC_band) { if (is_DC_band) {
if (cinfo->Ah != 0) /* DC refinement needs no table */ if (cinfo->Ah != 0) /* DC refinement needs no table */
continue; continue;
tbl = compptr->dc_tbl_no; tbl = compptr->dc_tbl_no;
} else { } else {
entropy->ac_tbl_no = tbl = compptr->ac_tbl_no; entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
@@ -165,10 +167,10 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
/* Allocate and zero the statistics tables */ /* Allocate and zero the statistics tables */
/* 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));
if (cinfo->trellis_passes) { if (cinfo->trellis_passes) {
/* When generating tables for trellis passes, make sure that all */ /* When generating tables for trellis passes, make sure that all */
/* codewords have an assigned length */ /* codewords have an assigned length */
@@ -181,7 +183,7 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
/* 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]);
} }
} }
@@ -206,9 +208,9 @@ 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)
@@ -246,11 +248,11 @@ emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size)
ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE); ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
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 &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */ put_buffer &= (((INT32) 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 */
put_buffer <<= 24 - put_bits; /* align incoming bits */ put_buffer <<= 24 - put_bits; /* align incoming bits */
@@ -260,7 +262,7 @@ emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size)
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? */
emit_byte(entropy, 0); emit_byte(entropy, 0);
} }
put_buffer <<= 8; put_buffer <<= 8;
@@ -303,10 +305,10 @@ 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);
@@ -325,7 +327,7 @@ 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 = 0;
while ((temp >>= 1)) while ((temp >>= 1))
@@ -419,7 +421,7 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Encode the DC coefficient difference per section G.1.2.1 */ /* Encode the DC coefficient difference per section G.1.2.1 */
temp2 = temp; temp2 = temp;
if (temp < 0) { if (temp < 0) {
temp = -temp; /* temp is abs value of input */ temp = -temp; /* 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 */ /* This code assumes we are on a two's complement machine */
temp2--; temp2--;
@@ -442,7 +444,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);
} }
@@ -494,7 +496,7 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* 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 */ r = 0; /* r = run length of zeros */
for (k = cinfo->Ss; k <= Se; k++) { for (k = cinfo->Ss; k <= Se; k++) {
temp = (*block)[jpeg_natural_order[k]]; temp = (*block)[jpeg_natural_order[k]];
@@ -526,7 +528,7 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/* 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 = 1; /* there must be at least one 1 bit */ nbits = 1; /* there must be at least one 1 bit */
while ((temp >>= 1)) while ((temp >>= 1))
nbits++; nbits++;
/* Check for out-of-range coefficient values */ /* Check for out-of-range coefficient values */
@@ -540,13 +542,13 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* or the complement of its magnitude, if negative. */ /* or the complement of its magnitude, if negative. */
emit_bits(entropy, (unsigned int) temp2, nbits); emit_bits(entropy, (unsigned int) temp2, nbits);
r = 0; /* reset zero run length */ r = 0; /* reset zero run length */
} }
if (r > 0) { /* If there are trailing zeroes, */ 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 */
} }
cinfo->dest->next_output_byte = entropy->next_output_byte; cinfo->dest->next_output_byte = entropy->next_output_byte;
@@ -655,17 +657,17 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
* in C, we shift after obtaining the absolute value. * in C, we shift after obtaining the absolute value.
*/ */
if (temp < 0) if (temp < 0)
temp = -temp; /* temp is abs value of input */ temp = -temp; /* temp is abs value of input */
temp >>= Al; /* apply the point transform */ temp >>= Al; /* apply the point transform */
absvalues[k] = temp; /* save abs value for main pass */ absvalues[k] = temp; /* save abs value for main pass */
if (temp == 1) if (temp == 1)
EOB = k; /* EOB = index of last newly-nonzero coef */ 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 */
r = 0; /* r = run length of zeros */ r = 0; /* r = run length of zeros */
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++) { for (k = cinfo->Ss; k <= Se; k++) {
@@ -712,12 +714,12 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
emit_buffered_bits(entropy, BR_buffer, BR); emit_buffered_bits(entropy, BR_buffer, BR);
BR_buffer = entropy->bit_buffer; /* BE bits are gone now */ BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
BR = 0; BR = 0;
r = 0; /* reset zero run length */ 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 */
entropy->BE += BR; /* concat my correction bits to older ones */ entropy->BE += BR; /* concat my correction bits to older ones */
/* We force out the EOB if we risk either: /* We force out the EOB if we risk either:
* 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.
@@ -786,13 +788,13 @@ finish_pass_gather_phuff (j_compress_ptr cinfo)
/* It's important not to apply jpeg_gen_optimal_table more than once /* It's important not to apply jpeg_gen_optimal_table more than once
* per table, because it clobbers the input frequency counts! * per table, because it clobbers the input frequency counts!
*/ */
MEMZERO(did, SIZEOF(did)); MEMZERO(did, sizeof(did));
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];
if (is_DC_band) { if (is_DC_band) {
if (cinfo->Ah != 0) /* DC refinement needs no table */ if (cinfo->Ah != 0) /* DC refinement needs no table */
continue; continue;
tbl = compptr->dc_tbl_no; tbl = compptr->dc_tbl_no;
} else { } else {
tbl = compptr->ac_tbl_no; tbl = compptr->ac_tbl_no;
@@ -823,7 +825,7 @@ jinit_phuff_encoder (j_compress_ptr cinfo)
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;
@@ -832,7 +834,7 @@ jinit_phuff_encoder (j_compress_ptr cinfo)
entropy->derived_tbls[i] = NULL; entropy->derived_tbls[i] = NULL;
entropy->count_ptrs[i] = NULL; entropy->count_ptrs[i] = NULL;
} }
entropy->bit_buffer = NULL; /* needed only in AC refinement scan */ entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
} }
#endif /* C_PROGRESSIVE_SUPPORTED */ #endif /* C_PROGRESSIVE_SUPPORTED */

View File

@@ -1,8 +1,10 @@
/* /*
* jcprepct.c * jcprepct.c
* *
* This file is part of the Independent JPEG Group's software:
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains the compression preprocessing controller. * This file contains the compression preprocessing controller.
@@ -58,12 +60,12 @@ typedef struct {
*/ */
JSAMPARRAY color_buf[MAX_COMPONENTS]; JSAMPARRAY color_buf[MAX_COMPONENTS];
JDIMENSION rows_to_go; /* counts rows remaining in source image */ JDIMENSION rows_to_go; /* counts rows remaining in source image */
int next_buf_row; /* index of next row to store in color_buf */ int next_buf_row; /* index of next row to store in color_buf */
#ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */ #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
int this_row_group; /* starting row index of group to process */ int this_row_group; /* starting row index of group to process */
int next_buf_stop; /* downsample when we reach this index */ int next_buf_stop; /* downsample when we reach this index */
#endif #endif
} my_prep_controller; } my_prep_controller;
@@ -104,13 +106,13 @@ 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 output_rows) int input_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, num_cols); 1, num_cols);
} }
} }
@@ -126,10 +128,10 @@ 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, JDIMENSION *in_row_ctr, JSAMPARRAY input_buf, 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;
@@ -137,32 +139,32 @@ pre_process_data (j_compress_ptr cinfo,
jpeg_component_info * compptr; jpeg_component_info * compptr;
while (*in_row_ctr < in_rows_avail && while (*in_row_ctr < in_rows_avail &&
*out_row_group_ctr < out_row_groups_avail) { *out_row_group_ctr < out_row_groups_avail) {
/* 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;
prep->rows_to_go -= numrows; prep->rows_to_go -= numrows;
/* If at bottom of image, pad to fill the conversion buffer. */ /* If at bottom of image, pad to fill the conversion buffer. */
if (prep->rows_to_go == 0 && if (prep->rows_to_go == 0 &&
prep->next_buf_row < cinfo->max_v_samp_factor) { prep->next_buf_row < cinfo->max_v_samp_factor) {
for (ci = 0; ci < cinfo->num_components; ci++) { for (ci = 0; ci < cinfo->num_components; ci++) {
expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
prep->next_buf_row, cinfo->max_v_samp_factor); prep->next_buf_row, cinfo->max_v_samp_factor);
} }
prep->next_buf_row = cinfo->max_v_samp_factor; prep->next_buf_row = cinfo->max_v_samp_factor;
} }
/* 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)++;
} }
@@ -170,16 +172,16 @@ pre_process_data (j_compress_ptr cinfo,
* 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 */
} }
} }
} }
@@ -193,10 +195,10 @@ 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, JDIMENSION *in_row_ctr, JSAMPARRAY input_buf, 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;
@@ -210,19 +212,19 @@ pre_process_context (j_compress_ptr cinfo,
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], -row, prep->color_buf[ci], -row,
1, cinfo->image_width); 1, cinfo->image_width);
} }
} }
} }
*in_row_ctr += numrows; *in_row_ctr += numrows;
prep->next_buf_row += numrows; prep->next_buf_row += numrows;
@@ -230,29 +232,29 @@ pre_process_context (j_compress_ptr cinfo,
} else { } else {
/* Return for more data, unless we are at the bottom of the image. */ /* Return for more data, unless we are at the bottom of the image. */
if (prep->rows_to_go != 0) if (prep->rows_to_go != 0)
break; break;
/* When at bottom of image, pad to fill the conversion buffer. */ /* When at bottom of image, pad to fill the conversion buffer. */
if (prep->next_buf_row < prep->next_buf_stop) { if (prep->next_buf_row < prep->next_buf_stop) {
for (ci = 0; ci < cinfo->num_components; ci++) { for (ci = 0; ci < cinfo->num_components; ci++) {
expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
prep->next_buf_row, prep->next_buf_stop); prep->next_buf_row, prep->next_buf_stop);
} }
prep->next_buf_row = prep->next_buf_stop; prep->next_buf_row = prep->next_buf_stop;
} }
} }
/* 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. */
prep->this_row_group += cinfo->max_v_samp_factor; prep->this_row_group += cinfo->max_v_samp_factor;
if (prep->this_row_group >= buf_height) if (prep->this_row_group >= buf_height)
prep->this_row_group = 0; prep->this_row_group = 0;
if (prep->next_buf_row >= buf_height) if (prep->next_buf_row >= buf_height)
prep->next_buf_row = 0; prep->next_buf_row = 0;
prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor; prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
} }
} }
@@ -277,8 +279,8 @@ create_context_buffer (j_compress_ptr cinfo)
*/ */
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));
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++) {
@@ -289,11 +291,11 @@ create_context_buffer (j_compress_ptr cinfo)
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));
/* Fill in the above and below wraparound pointers */ /* Fill in the above and below wraparound pointers */
for (i = 0; i < rgroup_height; i++) { for (i = 0; i < rgroup_height; i++) {
fake_buffer[i] = true_buffer[2 * rgroup_height + i]; fake_buffer[i] = true_buffer[2 * rgroup_height + i];
@@ -318,12 +320,12 @@ jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
int ci; int ci;
jpeg_component_info * compptr; jpeg_component_info * compptr;
if (need_full_buffer) /* safety check */ if (need_full_buffer) /* safety check */
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
prep = (my_prep_ptr) prep = (my_prep_ptr)
(*cinfo->mem->alloc_small) ((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;
@@ -343,12 +345,12 @@ jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
/* No context, just make it tall enough for one row group */ /* No context, just make it tall enough for one row group */
prep->pub.pre_process_data = pre_process_data; prep->pub.pre_process_data = pre_process_data;
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

@@ -1,9 +1,11 @@
/* /*
* jcsample.c * jcsample.c
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* This file is part of the Independent JPEG Group's software. * Copyright (C) 2014, MIPS Technologies, Inc., California
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains downsampling routines. * This file contains downsampling routines.
@@ -53,14 +55,15 @@
/* Pointer to routine to downsample a single component */ /* Pointer to routine to downsample a single component */
typedef JMETHOD(void, downsample1_ptr, typedef void (*downsample1_ptr) (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);
/* Private subobject */ /* Private subobject */
typedef struct { typedef struct {
struct jpeg_downsampler pub; /* public fields */ struct jpeg_downsampler pub; /* public fields */
/* Downsampling method pointers, one per component */ /* Downsampling method pointers, one per component */
downsample1_ptr methods[MAX_COMPONENTS]; downsample1_ptr methods[MAX_COMPONENTS];
@@ -87,7 +90,7 @@ 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 output_cols) JDIMENSION input_cols, JDIMENSION output_cols)
{ {
register JSAMPROW ptr; register JSAMPROW ptr;
register JSAMPLE pixval; register JSAMPLE pixval;
@@ -98,9 +101,9 @@ expand_right_edge (JSAMPARRAY image_data, int num_rows,
if (numcols > 0) { if (numcols > 0) {
for (row = 0; row < num_rows; row++) { for (row = 0; row < num_rows; row++) {
ptr = image_data[row] + input_cols; ptr = image_data[row] + input_cols;
pixval = ptr[-1]; /* don't need GETJSAMPLE() here */ pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
for (count = numcols; count > 0; count--) for (count = numcols; count > 0; count--)
*ptr++ = pixval; *ptr++ = pixval;
} }
} }
} }
@@ -114,8 +117,8 @@ 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, JDIMENSION in_row_index, JSAMPIMAGE input_buf, JDIMENSION in_row_index,
JSAMPIMAGE output_buf, JDIMENSION out_row_group_index) JSAMPIMAGE output_buf, 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;
@@ -140,10 +143,10 @@ 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;
JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */ JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
JSAMPROW inptr, outptr; JSAMPROW inptr, outptr;
INT32 outvalue; INT32 outvalue;
@@ -158,19 +161,19 @@ int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
* 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, output_cols * h_expand); cinfo->image_width, 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++) {
outptr = output_data[outrow]; outptr = output_data[outrow];
for (outcol = 0, outcol_h = 0; outcol < output_cols; for (outcol = 0, outcol_h = 0; outcol < output_cols;
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 += (INT32) GETJSAMPLE(*inptr++); outvalue += (INT32) GETJSAMPLE(*inptr++);
} }
} }
*outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix); *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
} }
@@ -187,14 +190,14 @@ 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->image_width); cinfo->max_v_samp_factor, 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, compptr->width_in_blocks * DCTSIZE); cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
} }
@@ -212,7 +215,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;
JDIMENSION outcol; JDIMENSION outcol;
@@ -225,16 +228,16 @@ h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
* 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, output_cols * 2); cinfo->image_width, 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++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
+ bias) >> 1); + bias) >> 1);
bias ^= 1; /* 0=>1, 1=>0 */ bias ^= 1; /* 0=>1, 1=>0 */
inptr += 2; inptr += 2;
} }
} }
@@ -249,7 +252,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;
JDIMENSION outcol; JDIMENSION outcol;
@@ -262,19 +265,19 @@ h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
* 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, output_cols * 2); cinfo->image_width, 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++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]) GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
+ bias) >> 2); + bias) >> 2);
bias ^= 3; /* 1=>2, 2=>1 */ bias ^= 3; /* 1=>2, 2=>1 */
inptr0 += 2; inptr1 += 2; inptr0 += 2; inptr1 += 2;
} }
inrow += 2; inrow += 2;
@@ -292,7 +295,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;
JDIMENSION colctr; JDIMENSION colctr;
@@ -305,7 +308,7 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
* efficient. * efficient.
*/ */
expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
cinfo->image_width, output_cols * 2); cinfo->image_width, output_cols * 2);
/* We don't bother to form the individual "smoothed" input pixel values; /* We don't bother to form the individual "smoothed" input pixel values;
* we can directly compute the output which is the average of the four * we can directly compute the output which is the average of the four
@@ -333,14 +336,14 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
/* 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]) +
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) + GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]); GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
neighsum += neighsum; neighsum += neighsum;
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;
@@ -348,17 +351,17 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
for (colctr = output_cols - 2; colctr > 0; colctr--) { for (colctr = output_cols - 2; colctr > 0; colctr--) {
/* sum of pixels directly mapped to this output element */ /* sum of pixels directly mapped to this output element */
membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
/* sum of edge-neighbor pixels */ /* sum of edge-neighbor pixels */
neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) + GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]); GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
/* The edge-neighbors count twice as much as corner-neighbors */ /* The edge-neighbors count twice as much as corner-neighbors */
neighsum += neighsum; neighsum += neighsum;
/* Add in the corner-neighbors */ /* Add in the corner-neighbors */
neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) + neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]); GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
/* 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 */
@@ -368,14 +371,14 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
/* Special case for last column */ /* Special case for last column */
membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) + GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]); GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
neighsum += neighsum; neighsum += neighsum;
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);
@@ -392,7 +395,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;
JDIMENSION colctr; JDIMENSION colctr;
@@ -406,7 +409,7 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
* efficient. * efficient.
*/ */
expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
cinfo->image_width, output_cols); cinfo->image_width, output_cols);
/* Each of the eight neighbor pixels contributes a fraction SF to the /* Each of the eight neighbor pixels contributes a fraction SF to the
* smoothed pixel, while the main pixel contributes (1-8*SF). In order * smoothed pixel, while the main pixel contributes (1-8*SF). In order
@@ -425,10 +428,10 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
/* Special case for first column */ /* Special case for first column */
colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) + colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
GETJSAMPLE(*inptr); GETJSAMPLE(*inptr);
membersum = GETJSAMPLE(*inptr++); membersum = GETJSAMPLE(*inptr++);
nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) + nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
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);
@@ -438,7 +441,7 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
membersum = GETJSAMPLE(*inptr++); membersum = GETJSAMPLE(*inptr++);
above_ptr++; below_ptr++; above_ptr++; below_ptr++;
nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) + nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
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);
@@ -472,7 +475,7 @@ jinit_downsampler (j_compress_ptr cinfo)
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;
@@ -485,35 +488,41 @@ jinit_downsampler (j_compress_ptr cinfo)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
if (compptr->h_samp_factor == cinfo->max_h_samp_factor && if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
compptr->v_samp_factor == cinfo->max_v_samp_factor) { compptr->v_samp_factor == cinfo->max_v_samp_factor) {
#ifdef INPUT_SMOOTHING_SUPPORTED #ifdef INPUT_SMOOTHING_SUPPORTED
if (cinfo->smoothing_factor) { if (cinfo->smoothing_factor) {
downsample->methods[ci] = fullsize_smooth_downsample; downsample->methods[ci] = fullsize_smooth_downsample;
downsample->pub.need_context_rows = TRUE; downsample->pub.need_context_rows = TRUE;
} else } else
#endif #endif
downsample->methods[ci] = fullsize_downsample; downsample->methods[ci] = fullsize_downsample;
} else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
compptr->v_samp_factor == cinfo->max_v_samp_factor) { compptr->v_samp_factor == cinfo->max_v_samp_factor) {
smoothok = FALSE; smoothok = FALSE;
if (jsimd_can_h2v1_downsample()) if (jsimd_can_h2v1_downsample())
downsample->methods[ci] = jsimd_h2v1_downsample; downsample->methods[ci] = jsimd_h2v1_downsample;
else else
downsample->methods[ci] = h2v1_downsample; downsample->methods[ci] = h2v1_downsample;
} else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) { compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
#ifdef INPUT_SMOOTHING_SUPPORTED #ifdef INPUT_SMOOTHING_SUPPORTED
if (cinfo->smoothing_factor) { if (cinfo->smoothing_factor) {
downsample->methods[ci] = h2v2_smooth_downsample; #if defined(__mips__)
downsample->pub.need_context_rows = TRUE; if (jsimd_can_h2v2_smooth_downsample())
} else downsample->methods[ci] = jsimd_h2v2_smooth_downsample;
else
#endif #endif
if (jsimd_can_h2v2_downsample()) downsample->methods[ci] = h2v2_smooth_downsample;
downsample->methods[ci] = jsimd_h2v2_downsample; downsample->pub.need_context_rows = TRUE;
else } else {
downsample->methods[ci] = h2v2_downsample; #endif
if (jsimd_can_h2v2_downsample())
downsample->methods[ci] = jsimd_h2v2_downsample;
else
downsample->methods[ci] = h2v2_downsample;
}
} else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 && } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
(cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) { (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
smoothok = FALSE; smoothok = FALSE;
downsample->methods[ci] = int_downsample; downsample->methods[ci] = int_downsample;
} else } else

112
jctrans.c
View File

@@ -1,9 +1,11 @@
/* /*
* jctrans.c * jctrans.c
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1995-1998, Thomas G. Lane. * Copyright (C) 1995-1998, Thomas G. Lane.
* Modified 2000-2009 by Guido Vollbeding. * Modified 2000-2009 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains library routines for transcoding compression, * This file contains library routines for transcoding compression,
@@ -18,9 +20,9 @@
/* Forward declarations */ /* Forward declarations */
LOCAL(void) transencode_master_selection LOCAL(void) transencode_master_selection
JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)); (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays);
LOCAL(void) transencode_coef_controller LOCAL(void) transencode_coef_controller
JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)); (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays);
/* /*
@@ -52,7 +54,7 @@ jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
/* Perform master selection of active modules */ /* Perform master selection of active modules */
transencode_master_selection(cinfo, coef_arrays); transencode_master_selection(cinfo, coef_arrays);
/* Wait for jpeg_finish_compress() call */ /* Wait for jpeg_finish_compress() call */
cinfo->next_scanline = 0; /* so jpeg_write_marker works */ cinfo->next_scanline = 0; /* so jpeg_write_marker works */
cinfo->global_state = CSTATE_WRCOEFS; cinfo->global_state = CSTATE_WRCOEFS;
} }
@@ -66,7 +68,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;
@@ -102,10 +104,10 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
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;
} }
} }
@@ -115,7 +117,7 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
dstinfo->num_components = srcinfo->num_components; dstinfo->num_components = srcinfo->num_components;
if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS) if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components, ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
MAX_COMPONENTS); MAX_COMPONENTS);
for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info; for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
ci < dstinfo->num_components; ci++, incomp++, outcomp++) { ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
outcomp->component_id = incomp->component_id; outcomp->component_id = incomp->component_id;
@@ -128,14 +130,14 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
*/ */
tblno = outcomp->quant_tbl_no; tblno = outcomp->quant_tbl_no;
if (tblno < 0 || tblno >= NUM_QUANT_TBLS || if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
srcinfo->quant_tbl_ptrs[tblno] == NULL) srcinfo->quant_tbl_ptrs[tblno] == NULL)
ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno); ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
slot_quant = srcinfo->quant_tbl_ptrs[tblno]; slot_quant = srcinfo->quant_tbl_ptrs[tblno];
c_quant = incomp->quant_table; c_quant = incomp->quant_table;
if (c_quant != NULL) { if (c_quant != NULL) {
for (coefi = 0; coefi < DCTSIZE2; coefi++) { for (coefi = 0; coefi < DCTSIZE2; coefi++) {
if (c_quant->quantval[coefi] != slot_quant->quantval[coefi]) if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno); ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
} }
} }
/* Note: we do not copy the source's Huffman table assignments; /* Note: we do not copy the source's Huffman table assignments;
@@ -169,7 +171,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,
* jcmaster.c's initial_setup will complain if input_components is 0. * jcmaster.c's initial_setup will complain if input_components is 0.
@@ -225,10 +227,10 @@ transencode_master_selection (j_compress_ptr cinfo,
typedef struct { typedef struct {
struct jpeg_c_coef_controller pub; /* public fields */ struct jpeg_c_coef_controller pub; /* public fields */
JDIMENSION iMCU_row_num; /* iMCU row # within image */ JDIMENSION iMCU_row_num; /* iMCU row # within image */
JDIMENSION mcu_ctr; /* counts MCUs processed in current row */ JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
int MCU_vert_offset; /* counts MCU rows within iMCU row */ int MCU_vert_offset; /* counts MCU rows within iMCU row */
int MCU_rows_per_iMCU_row; /* number of such rows needed */ int MCU_rows_per_iMCU_row; /* number of such rows needed */
/* Virtual block array for each component. */ /* Virtual block array for each component. */
jvirt_barray_ptr * whole_image; jvirt_barray_ptr * whole_image;
@@ -295,7 +297,7 @@ 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;
int blkn, ci, xindex, yindex, yoffset, blockcnt; int blkn, ci, xindex, yindex, yoffset, blockcnt;
@@ -318,44 +320,44 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
yoffset++) { yoffset++) {
for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row; for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
MCU_col_num++) { MCU_col_num++) {
/* Construct list of pointers to DCT blocks belonging to this MCU */ /* Construct list of pointers to DCT blocks belonging to this MCU */
blkn = 0; /* index of current DCT block within MCU */ blkn = 0; /* index of current DCT block within MCU */
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 {
/* At bottom of image, need a whole row of dummy blocks */ /* At bottom of image, need a whole row of dummy blocks */
xindex = 0; xindex = 0;
} }
/* Fill in any dummy blocks needed in this row. /* Fill in any dummy blocks needed in this row.
* Dummy blocks are filled in the same way as in jccoefct.c: * Dummy blocks are filled in the same way as in jccoefct.c:
* all zeroes in the AC entries, DC entries equal to previous * all zeroes in the AC entries, DC entries equal to previous
* block's DC value. The init routine has already zeroed the * block's DC value. The init routine has already zeroed the
* AC entries, so we need only set the DC entries correctly. * AC entries, so we need only set the DC entries correctly.
*/ */
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;
return FALSE; return FALSE;
} }
} }
/* Completed an MCU row, but perhaps not an iMCU row */ /* Completed an MCU row, but perhaps not an iMCU row */
@@ -378,7 +380,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;
JBLOCKROW buffer; JBLOCKROW buffer;
@@ -386,7 +388,7 @@ transencode_coef_controller (j_compress_ptr cinfo,
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;
@@ -397,8 +399,8 @@ 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 FAR *) 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

@@ -1,8 +1,10 @@
/* /*
* jdapimin.c * jdapimin.c
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1998, Thomas G. Lane. * Copyright (C) 1994-1998, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains application interface code for the decompression half * This file contains application interface code for the decompression half
@@ -32,12 +34,12 @@ jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
int i; int i;
/* Guard against version mismatches between library and caller. */ /* Guard against version mismatches between library and caller. */
cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
if (version != JPEG_LIB_VERSION) if (version != JPEG_LIB_VERSION)
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
@@ -48,7 +50,7 @@ jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
{ {
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;
} }
@@ -128,15 +130,15 @@ default_decompress_parms (j_decompress_ptr cinfo)
} else if (cinfo->saw_Adobe_marker) { } else if (cinfo->saw_Adobe_marker) {
switch (cinfo->Adobe_transform) { switch (cinfo->Adobe_transform) {
case 0: case 0:
cinfo->jpeg_color_space = JCS_RGB; cinfo->jpeg_color_space = JCS_RGB;
break; break;
case 1: case 1:
cinfo->jpeg_color_space = JCS_YCbCr; cinfo->jpeg_color_space = JCS_YCbCr;
break; break;
default: default:
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
break; break;
} }
} else { } else {
/* Saw no special markers, try to guess from the component IDs */ /* Saw no special markers, try to guess from the component IDs */
@@ -145,12 +147,12 @@ default_decompress_parms (j_decompress_ptr cinfo)
int cid2 = cinfo->comp_info[2].component_id; int cid2 = cinfo->comp_info[2].component_id;
if (cid0 == 1 && cid1 == 2 && cid2 == 3) if (cid0 == 1 && cid1 == 2 && cid2 == 3)
cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */ cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
else if (cid0 == 82 && cid1 == 71 && cid2 == 66) else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */ cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
else { else {
TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2); TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
} }
} }
/* Always guess RGB is proper output colorspace. */ /* Always guess RGB is proper output colorspace. */
@@ -161,15 +163,15 @@ default_decompress_parms (j_decompress_ptr cinfo)
if (cinfo->saw_Adobe_marker) { if (cinfo->saw_Adobe_marker) {
switch (cinfo->Adobe_transform) { switch (cinfo->Adobe_transform) {
case 0: case 0:
cinfo->jpeg_color_space = JCS_CMYK; cinfo->jpeg_color_space = JCS_CMYK;
break; break;
case 2: case 2:
cinfo->jpeg_color_space = JCS_YCCK; cinfo->jpeg_color_space = JCS_YCCK;
break; break;
default: default:
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */ cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
break; break;
} }
} else { } else {
/* No special markers, assume straight CMYK. */ /* No special markers, assume straight CMYK. */
@@ -185,7 +187,7 @@ default_decompress_parms (j_decompress_ptr cinfo)
} }
/* Set defaults for other decompression parameters. */ /* Set defaults for other decompression parameters. */
cinfo->scale_num = 1; /* 1:1 scaling */ cinfo->scale_num = 1; /* 1:1 scaling */
cinfo->scale_denom = 1; cinfo->scale_denom = 1;
cinfo->output_gamma = 1.0; cinfo->output_gamma = 1.0;
cinfo->buffered_image = FALSE; cinfo->buffered_image = FALSE;
@@ -253,7 +255,7 @@ jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
retcode = JPEG_HEADER_OK; retcode = JPEG_HEADER_OK;
break; break;
case JPEG_REACHED_EOI: case JPEG_REACHED_EOI:
if (require_image) /* Complain if application wanted an image */ if (require_image) /* Complain if application wanted an image */
ERREXIT(cinfo, JERR_NO_IMAGE); ERREXIT(cinfo, JERR_NO_IMAGE);
/* Reset to start state; it would be safer to require the application to /* Reset to start state; it would be safer to require the application to
* 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.
@@ -385,7 +387,7 @@ jpeg_finish_decompress (j_decompress_ptr cinfo)
/* 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);

View File

@@ -23,7 +23,7 @@
/* Forward declarations */ /* Forward declarations */
LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo)); LOCAL(boolean) output_pass_setup (j_decompress_ptr cinfo);
/* /*
@@ -55,24 +55,24 @@ jpeg_start_decompress (j_decompress_ptr cinfo)
if (cinfo->inputctl->has_multiple_scans) { if (cinfo->inputctl->has_multiple_scans) {
#ifdef D_MULTISCAN_FILES_SUPPORTED #ifdef D_MULTISCAN_FILES_SUPPORTED
for (;;) { for (;;) {
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)
return FALSE; return FALSE;
if (retcode == JPEG_REACHED_EOI) if (retcode == JPEG_REACHED_EOI)
break; break;
/* Advance progress counter if appropriate */ /* Advance progress counter if appropriate */
if (cinfo->progress != NULL && if (cinfo->progress != NULL &&
(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;
} }
} }
} }
#else #else
ERREXIT(cinfo, JERR_NOT_COMPILED); ERREXIT(cinfo, JERR_NOT_COMPILED);
@@ -111,16 +111,16 @@ 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 */
} }
/* Finish up dummy pass, and set up for another one */ /* Finish up dummy pass, and set up for another one */
(*cinfo->master->finish_output_pass) (cinfo); (*cinfo->master->finish_output_pass) (cinfo);
@@ -153,7 +153,7 @@ output_pass_setup (j_decompress_ptr cinfo)
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;
@@ -186,7 +186,7 @@ jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
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;
@@ -211,7 +211,7 @@ jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
/* 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. */
cinfo->output_scanline += lines_per_iMCU_row; cinfo->output_scanline += lines_per_iMCU_row;
@@ -267,9 +267,9 @@ 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 */
} }
cinfo->global_state = DSTATE_BUFIMAGE; cinfo->global_state = DSTATE_BUFIMAGE;
return TRUE; return TRUE;

300
jdarith.c
View File

@@ -1,8 +1,10 @@
/* /*
* jdarith.c * jdarith.c
* *
* This file was part of the Independent JPEG Group's software:
* Developed 1997-2009 by Guido Vollbeding. * Developed 1997-2009 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains portable arithmetic entropy decoding routines for JPEG * This file contains portable arithmetic entropy decoding routines for JPEG
@@ -32,7 +34,7 @@ typedef struct {
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */ int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */
unsigned int restarts_to_go; /* MCUs left in this restart interval */ unsigned int restarts_to_go; /* MCUs left in this restart interval */
/* Pointers to statistics areas (these workspaces have image lifespan) */ /* Pointers to statistics areas (these workspaces have image lifespan) */
unsigned char * dc_stats[NUM_ARITH_TBLS]; unsigned char * dc_stats[NUM_ARITH_TBLS];
@@ -115,32 +117,32 @@ arith_decode (j_decompress_ptr cinfo, unsigned char *st)
if (--e->ct < 0) { if (--e->ct < 0) {
/* Need to fetch next data byte */ /* Need to fetch next data byte */
if (cinfo->unread_marker) if (cinfo->unread_marker)
data = 0; /* stuff zero data */ data = 0; /* stuff zero data */
else { else {
data = get_byte(cinfo); /* read next input byte */ data = get_byte(cinfo); /* read next input byte */
if (data == 0xFF) { /* zero stuff or marker code */ if (data == 0xFF) { /* zero stuff or marker code */
do data = get_byte(cinfo); do data = get_byte(cinfo);
while (data == 0xFF); /* swallow extra 0xFF bytes */ while (data == 0xFF); /* swallow extra 0xFF bytes */
if (data == 0) if (data == 0)
data = 0xFF; /* discard stuffed zero byte */ data = 0xFF; /* discard stuffed zero byte */
else { else {
/* Note: Different from the Huffman decoder, hitting /* Note: Different from the Huffman decoder, hitting
* a marker while processing the compressed data * a marker while processing the compressed data
* segment is legal in arithmetic coding. * segment is legal in arithmetic coding.
* The convention is to supply zero data * The convention is to supply zero data
* then until decoding is complete. * then until decoding is complete.
*/ */
cinfo->unread_marker = data; cinfo->unread_marker = data;
data = 0; data = 0;
} }
} }
} }
e->c = (e->c << 8) | data; /* insert data into C register */ e->c = (e->c << 8) | data; /* insert data into C register */
if ((e->ct += 8) < 0) /* update bit shift counter */ if ((e->ct += 8) < 0) /* update bit shift counter */
/* Need more initial bytes */ /* Need more initial bytes */
if (++e->ct == 0) if (++e->ct == 0)
/* Got 2 initial bytes -> re-init A and exit loop */ /* Got 2 initial bytes -> re-init A and exit loop */
e->a = 0x8000L; /* => e->a = 0x10000L after loop exit */ e->a = 0x8000L; /* => e->a = 0x10000L after loop exit */
} }
e->a <<= 1; e->a <<= 1;
} }
@@ -149,9 +151,9 @@ arith_decode (j_decompress_ptr cinfo, unsigned char *st)
* Qe values and probability estimation state machine * Qe values and probability estimation state machine
*/ */
sv = *st; sv = *st;
qe = jpeg_aritab[sv & 0x7F]; /* => Qe_Value */ qe = jpeg_aritab[sv & 0x7F]; /* => Qe_Value */
nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */ nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */
nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */ nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */
/* Decode & estimation procedures per sections D.2.4 & D.2.5 */ /* Decode & estimation procedures per sections D.2.4 & D.2.5 */
temp = e->a - qe; temp = e->a - qe;
@@ -162,19 +164,19 @@ arith_decode (j_decompress_ptr cinfo, unsigned char *st)
/* Conditional LPS (less probable symbol) exchange */ /* Conditional LPS (less probable symbol) exchange */
if (e->a < qe) { if (e->a < qe) {
e->a = qe; e->a = qe;
*st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */ *st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */
} else { } else {
e->a = qe; e->a = qe;
*st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */ *st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */
sv ^= 0x80; /* Exchange LPS/MPS */ sv ^= 0x80; /* Exchange LPS/MPS */
} }
} else if (e->a < 0x8000L) { } else if (e->a < 0x8000L) {
/* Conditional MPS (more probable symbol) exchange */ /* Conditional MPS (more probable symbol) exchange */
if (e->a < qe) { if (e->a < qe) {
*st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */ *st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */
sv ^= 0x80; /* Exchange LPS/MPS */ sv ^= 0x80; /* Exchange LPS/MPS */
} else { } else {
*st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */ *st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */
} }
} }
@@ -214,7 +216,7 @@ process_restart (j_decompress_ptr cinfo)
/* Reset arithmetic decoding variables */ /* Reset arithmetic decoding variables */
entropy->c = 0; entropy->c = 0;
entropy->a = 0; entropy->a = 0;
entropy->ct = -16; /* force reading 2 initial bytes to fill C */ entropy->ct = -16; /* force reading 2 initial bytes to fill C */
/* Reset restart counter */ /* Reset restart counter */
entropy->restarts_to_go = cinfo->restart_interval; entropy->restarts_to_go = cinfo->restart_interval;
@@ -253,7 +255,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
entropy->restarts_to_go--; entropy->restarts_to_go--;
} }
if (entropy->ct == -1) return TRUE; /* if error do nothing */ if (entropy->ct == -1) return TRUE; /* if error do nothing */
/* Outer loop handles each block in the MCU */ /* Outer loop handles each block in the MCU */
@@ -277,28 +279,28 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
st += 2; st += sign; st += 2; st += sign;
/* Figure F.23: Decoding the magnitude category of v */ /* Figure F.23: Decoding the magnitude category of v */
if ((m = arith_decode(cinfo, st)) != 0) { if ((m = arith_decode(cinfo, st)) != 0) {
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
while (arith_decode(cinfo, st)) { while (arith_decode(cinfo, st)) {
if ((m <<= 1) == 0x8000) { if ((m <<= 1) == 0x8000) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* magnitude overflow */ entropy->ct = -1; /* magnitude overflow */
return TRUE; return TRUE;
} }
st += 1; st += 1;
} }
} }
/* 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 */
v = m; v = m;
/* Figure F.24: Decoding the magnitude bit pattern of v */ /* Figure F.24: Decoding the magnitude bit pattern of v */
st += 14; st += 14;
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] += v;
} }
@@ -332,7 +334,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
entropy->restarts_to_go--; entropy->restarts_to_go--;
} }
if (entropy->ct == -1) return TRUE; /* if error do nothing */ if (entropy->ct == -1) return TRUE; /* if error do nothing */
/* There is always only one block per MCU */ /* There is always only one block per MCU */
block = MCU_data[0]; block = MCU_data[0];
@@ -343,13 +345,13 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Figure F.20: Decode_AC_coefficients */ /* Figure F.20: Decode_AC_coefficients */
for (k = cinfo->Ss; k <= cinfo->Se; k++) { for (k = cinfo->Ss; k <= cinfo->Se; k++) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * (k - 1);
if (arith_decode(cinfo, st)) break; /* EOB flag */ if (arith_decode(cinfo, st)) break; /* EOB flag */
while (arith_decode(cinfo, st + 1) == 0) { while (arith_decode(cinfo, st + 1) == 0) {
st += 3; k++; st += 3; k++;
if (k > cinfo->Se) { if (k > cinfo->Se) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* spectral overflow */ entropy->ct = -1; /* spectral overflow */
return TRUE; return TRUE;
} }
} }
/* Figure F.21: Decoding nonzero value v */ /* Figure F.21: Decoding nonzero value v */
@@ -359,17 +361,17 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Figure F.23: Decoding the magnitude category of v */ /* Figure F.23: Decoding the magnitude category of v */
if ((m = arith_decode(cinfo, st)) != 0) { if ((m = arith_decode(cinfo, st)) != 0) {
if (arith_decode(cinfo, st)) { if (arith_decode(cinfo, st)) {
m <<= 1; m <<= 1;
st = entropy->ac_stats[tbl] + st = entropy->ac_stats[tbl] +
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217); (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
while (arith_decode(cinfo, st)) { while (arith_decode(cinfo, st)) {
if ((m <<= 1) == 0x8000) { if ((m <<= 1) == 0x8000) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* magnitude overflow */ entropy->ct = -1; /* magnitude overflow */
return TRUE; return TRUE;
} }
st += 1; st += 1;
} }
} }
} }
v = m; v = m;
@@ -404,8 +406,8 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
entropy->restarts_to_go--; entropy->restarts_to_go--;
} }
st = entropy->fixed_bin; /* use fixed probability estimation */ st = entropy->fixed_bin; /* use fixed probability estimation */
p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
/* Outer loop handles each block in the MCU */ /* Outer loop handles each block in the MCU */
@@ -440,14 +442,14 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
entropy->restarts_to_go--; entropy->restarts_to_go--;
} }
if (entropy->ct == -1) return TRUE; /* if error do nothing */ if (entropy->ct == -1) return TRUE; /* if error do nothing */
/* There is always only one block per MCU */ /* There is always only one block per MCU */
block = MCU_data[0]; block = MCU_data[0];
tbl = cinfo->cur_comp_info[0]->ac_tbl_no; tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */ m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
/* Establish EOBx (previous stage end-of-block) index */ /* Establish EOBx (previous stage end-of-block) index */
for (kex = cinfo->Se; kex > 0; kex--) for (kex = cinfo->Se; kex > 0; kex--)
@@ -456,30 +458,30 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
for (k = cinfo->Ss; k <= cinfo->Se; k++) { for (k = cinfo->Ss; k <= cinfo->Se; k++) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * (k - 1);
if (k > kex) if (k > kex)
if (arith_decode(cinfo, st)) break; /* EOB flag */ if (arith_decode(cinfo, st)) break; /* EOB flag */
for (;;) { for (;;) {
thiscoef = *block + jpeg_natural_order[k]; thiscoef = *block + jpeg_natural_order[k];
if (*thiscoef) { /* previously nonzero coef */ if (*thiscoef) { /* previously nonzero coef */
if (arith_decode(cinfo, st + 2)) { if (arith_decode(cinfo, st + 2)) {
if (*thiscoef < 0) if (*thiscoef < 0)
*thiscoef += m1; *thiscoef += m1;
else else
*thiscoef += p1; *thiscoef += p1;
} }
break; break;
} }
if (arith_decode(cinfo, st + 1)) { /* newly nonzero coef */ if (arith_decode(cinfo, st + 1)) { /* newly nonzero coef */
if (arith_decode(cinfo, entropy->fixed_bin)) if (arith_decode(cinfo, entropy->fixed_bin))
*thiscoef = m1; *thiscoef = m1;
else else
*thiscoef = p1; *thiscoef = p1;
break; break;
} }
st += 3; k++; st += 3; k++;
if (k > cinfo->Se) { if (k > cinfo->Se) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* spectral overflow */ entropy->ct = -1; /* spectral overflow */
return TRUE; return TRUE;
} }
} }
} }
@@ -509,7 +511,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
entropy->restarts_to_go--; entropy->restarts_to_go--;
} }
if (entropy->ct == -1) return TRUE; /* if error do nothing */ if (entropy->ct == -1) return TRUE; /* if error do nothing */
/* Outer loop handles each block in the MCU */ /* Outer loop handles each block in the MCU */
@@ -535,28 +537,28 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
st += 2; st += sign; st += 2; st += sign;
/* Figure F.23: Decoding the magnitude category of v */ /* Figure F.23: Decoding the magnitude category of v */
if ((m = arith_decode(cinfo, st)) != 0) { if ((m = arith_decode(cinfo, st)) != 0) {
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
while (arith_decode(cinfo, st)) { while (arith_decode(cinfo, st)) {
if ((m <<= 1) == 0x8000) { if ((m <<= 1) == 0x8000) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* magnitude overflow */ entropy->ct = -1; /* magnitude overflow */
return TRUE; return TRUE;
} }
st += 1; st += 1;
} }
} }
/* 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 */
v = m; v = m;
/* Figure F.24: Decoding the magnitude bit pattern of v */ /* Figure F.24: Decoding the magnitude bit pattern of v */
st += 14; st += 14;
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] += v;
} }
@@ -570,14 +572,14 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Figure F.20: Decode_AC_coefficients */ /* Figure F.20: Decode_AC_coefficients */
for (k = 1; k <= DCTSIZE2 - 1; k++) { for (k = 1; k <= DCTSIZE2 - 1; k++) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * (k - 1);
if (arith_decode(cinfo, st)) break; /* EOB flag */ if (arith_decode(cinfo, st)) break; /* EOB flag */
while (arith_decode(cinfo, st + 1) == 0) { while (arith_decode(cinfo, st + 1) == 0) {
st += 3; k++; st += 3; k++;
if (k > DCTSIZE2 - 1) { if (k > DCTSIZE2 - 1) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* spectral overflow */ entropy->ct = -1; /* spectral overflow */
return TRUE; return TRUE;
} }
} }
/* Figure F.21: Decoding nonzero value v */ /* Figure F.21: Decoding nonzero value v */
/* Figure F.22: Decoding the sign of v */ /* Figure F.22: Decoding the sign of v */
@@ -585,25 +587,25 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
st += 2; st += 2;
/* Figure F.23: Decoding the magnitude category of v */ /* Figure F.23: Decoding the magnitude category of v */
if ((m = arith_decode(cinfo, st)) != 0) { if ((m = arith_decode(cinfo, st)) != 0) {
if (arith_decode(cinfo, st)) { if (arith_decode(cinfo, st)) {
m <<= 1; m <<= 1;
st = entropy->ac_stats[tbl] + st = entropy->ac_stats[tbl] +
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217); (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
while (arith_decode(cinfo, st)) { while (arith_decode(cinfo, st)) {
if ((m <<= 1) == 0x8000) { if ((m <<= 1) == 0x8000) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* magnitude overflow */ entropy->ct = -1; /* magnitude overflow */
return TRUE; return TRUE;
} }
st += 1; st += 1;
} }
} }
} }
v = m; v = m;
/* Figure F.24: Decoding the magnitude bit pattern of v */ /* Figure F.24: Decoding the magnitude bit pattern of v */
st += 14; st += 14;
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;
(*block)[jpeg_natural_order[k]] = (JCOEF) v; (*block)[jpeg_natural_order[k]] = (JCOEF) v;
} }
@@ -628,24 +630,24 @@ start_pass (j_decompress_ptr cinfo)
/* Validate progressive scan parameters */ /* Validate progressive scan parameters */
if (cinfo->Ss == 0) { if (cinfo->Ss == 0) {
if (cinfo->Se != 0) if (cinfo->Se != 0)
goto bad; goto bad;
} else { } else {
/* need not check Ss/Se < 0 since they came from unsigned bytes */ /* need not check Ss/Se < 0 since they came from unsigned bytes */
if (cinfo->Se < cinfo->Ss || cinfo->Se > DCTSIZE2 - 1) if (cinfo->Se < cinfo->Ss || cinfo->Se > DCTSIZE2 - 1)
goto bad; goto bad;
/* AC scans may have only one component */ /* AC scans may have only one component */
if (cinfo->comps_in_scan != 1) if (cinfo->comps_in_scan != 1)
goto bad; goto bad;
} }
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);
} }
/* Update progression status, and verify that scan order is legal. /* Update progression status, and verify that scan order is legal.
* Note that inter-scan inconsistencies are treated as warnings * Note that inter-scan inconsistencies are treated as warnings
@@ -655,32 +657,32 @@ start_pass (j_decompress_ptr cinfo)
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++) {
int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi]; int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
if (cinfo->Ah != expected) if (cinfo->Ah != expected)
WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi); WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
coef_bit_ptr[coefi] = cinfo->Al; coef_bit_ptr[coefi] = cinfo->Al;
} }
} }
/* Select MCU decoding routine */ /* Select MCU decoding routine */
if (cinfo->Ah == 0) { if (cinfo->Ah == 0) {
if (cinfo->Ss == 0) if (cinfo->Ss == 0)
entropy->pub.decode_mcu = decode_mcu_DC_first; entropy->pub.decode_mcu = decode_mcu_DC_first;
else else
entropy->pub.decode_mcu = decode_mcu_AC_first; entropy->pub.decode_mcu = decode_mcu_AC_first;
} else { } else {
if (cinfo->Ss == 0) if (cinfo->Ss == 0)
entropy->pub.decode_mcu = decode_mcu_DC_refine; entropy->pub.decode_mcu = decode_mcu_DC_refine;
else else
entropy->pub.decode_mcu = decode_mcu_AC_refine; entropy->pub.decode_mcu = decode_mcu_AC_refine;
} }
} else { } else {
/* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG. /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.
* This ought to be an error condition, but we make it a warning. * This ought to be an error condition, but we make it a warning.
*/ */
if (cinfo->Ss != 0 || cinfo->Ah != 0 || cinfo->Al != 0 || if (cinfo->Ss != 0 || cinfo->Ah != 0 || cinfo->Al != 0 ||
(cinfo->Se < DCTSIZE2 && cinfo->Se != DCTSIZE2 - 1)) (cinfo->Se < DCTSIZE2 && cinfo->Se != DCTSIZE2 - 1))
WARNMS(cinfo, JWRN_NOT_SEQUENTIAL); WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
/* Select MCU decoding routine */ /* Select MCU decoding routine */
entropy->pub.decode_mcu = decode_mcu; entropy->pub.decode_mcu = decode_mcu;
@@ -692,10 +694,10 @@ start_pass (j_decompress_ptr cinfo)
if (! cinfo->progressive_mode || (cinfo->Ss == 0 && cinfo->Ah == 0)) { if (! cinfo->progressive_mode || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
tbl = compptr->dc_tbl_no; tbl = compptr->dc_tbl_no;
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;
@@ -704,10 +706,10 @@ start_pass (j_decompress_ptr cinfo)
if (! cinfo->progressive_mode || cinfo->Ss) { if (! cinfo->progressive_mode || cinfo->Ss) {
tbl = compptr->ac_tbl_no; tbl = compptr->ac_tbl_no;
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);
} }
} }
@@ -715,7 +717,7 @@ start_pass (j_decompress_ptr cinfo)
/* Initialize arithmetic decoding variables */ /* Initialize arithmetic decoding variables */
entropy->c = 0; entropy->c = 0;
entropy->a = 0; entropy->a = 0;
entropy->ct = -16; /* force reading 2 initial bytes to fill C */ entropy->ct = -16; /* force reading 2 initial bytes to fill C */
/* Initialize restart counter */ /* Initialize restart counter */
entropy->restarts_to_go = cinfo->restart_interval; entropy->restarts_to_go = cinfo->restart_interval;
@@ -734,7 +736,7 @@ jinit_arith_decoder (j_decompress_ptr cinfo)
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;
@@ -752,10 +754,10 @@ jinit_arith_decoder (j_decompress_ptr cinfo)
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*sizeof(int));
coef_bit_ptr = & cinfo->coef_bits[0][0]; 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

@@ -22,13 +22,13 @@
#include "jpeglib.h" #include "jpeglib.h"
#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 JPP((size_t size)); extern void * malloc (size_t size);
extern void free JPP((void *ptr)); extern void free (void *ptr);
#endif #endif
#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */ #define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
/* Expanded data destination object for memory output */ /* Expanded data destination object for memory output */
@@ -36,10 +36,10 @@ extern void free JPP((void *ptr));
typedef struct { typedef struct {
struct jpeg_destination_mgr pub; /* public fields */ struct jpeg_destination_mgr pub; /* public fields */
unsigned char ** outbuffer; /* target buffer */ unsigned char ** outbuffer; /* target buffer */
unsigned long * outsize; unsigned long * outsize;
unsigned char * newbuffer; /* newly allocated buffer */ unsigned char * newbuffer; /* newly allocated buffer */
JOCTET * buffer; /* start of buffer */ JOCTET * buffer; /* start of buffer */
size_t bufsize; size_t bufsize;
boolean alloc; boolean alloc;
} my_mem_destination_mgr; } my_mem_destination_mgr;
@@ -147,21 +147,21 @@ term_mem_destination (j_compress_ptr cinfo)
GLOBAL(void) GLOBAL(void)
jpeg_mem_dest_tj (j_compress_ptr cinfo, jpeg_mem_dest_tj (j_compress_ptr cinfo,
unsigned char ** outbuffer, unsigned long * outsize, unsigned char ** outbuffer, unsigned long * outsize,
boolean alloc) boolean alloc)
{ {
my_mem_dest_ptr dest; my_mem_dest_ptr dest;
if (outbuffer == NULL || outsize == NULL) /* sanity check */ if (outbuffer == NULL || outsize == NULL) /* sanity check */
ERREXIT(cinfo, JERR_BUFFER_SIZE); ERREXIT(cinfo, JERR_BUFFER_SIZE);
/* The destination object is made permanent so that multiple JPEG images /* The destination object is made permanent so that multiple JPEG images
* can be written to the same buffer without re-executing jpeg_mem_dest. * can be written to the same buffer without re-executing jpeg_mem_dest.
*/ */
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));
dest = (my_mem_dest_ptr) cinfo->dest; dest = (my_mem_dest_ptr) cinfo->dest;
dest->newbuffer = NULL; dest->newbuffer = NULL;
} }

View File

@@ -22,9 +22,9 @@
#include "jpeglib.h" #include "jpeglib.h"
#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 JPP((size_t size)); extern void * malloc (size_t size);
extern void free JPP((void *ptr)); extern void free (void *ptr);
#endif #endif
@@ -33,13 +33,13 @@ extern void free JPP((void *ptr));
typedef struct { typedef struct {
struct jpeg_destination_mgr pub; /* public fields */ struct jpeg_destination_mgr pub; /* public fields */
FILE * outfile; /* target stream */ FILE * outfile; /* target stream */
JOCTET * buffer; /* start of buffer */ JOCTET * buffer; /* start of buffer */
} my_destination_mgr; } my_destination_mgr;
typedef my_destination_mgr * my_dest_ptr; typedef my_destination_mgr * my_dest_ptr;
#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */ #define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED) #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
@@ -48,10 +48,10 @@ typedef my_destination_mgr * my_dest_ptr;
typedef struct { typedef struct {
struct jpeg_destination_mgr pub; /* public fields */ struct jpeg_destination_mgr pub; /* public fields */
unsigned char ** outbuffer; /* target buffer */ unsigned char ** outbuffer; /* target buffer */
unsigned long * outsize; unsigned long * outsize;
unsigned char * newbuffer; /* newly allocated buffer */ unsigned char * newbuffer; /* newly allocated buffer */
JOCTET * buffer; /* start of buffer */ JOCTET * buffer; /* start of buffer */
size_t bufsize; size_t bufsize;
} my_mem_destination_mgr; } my_mem_destination_mgr;
@@ -72,7 +72,7 @@ init_destination (j_compress_ptr cinfo)
/* 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;
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
@@ -213,10 +213,10 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
* manager serially with the same JPEG object, because their private object * manager serially with the same JPEG object, because their private object
* sizes may be different. Caveat programmer. * sizes may be different. Caveat programmer.
*/ */
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));
} }
dest = (my_dest_ptr) cinfo->dest; dest = (my_dest_ptr) cinfo->dest;
@@ -241,20 +241,20 @@ 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 long * outsize) unsigned char ** outbuffer, unsigned long * outsize)
{ {
my_mem_dest_ptr dest; my_mem_dest_ptr dest;
if (outbuffer == NULL || outsize == NULL) /* sanity check */ if (outbuffer == NULL || outsize == NULL) /* sanity check */
ERREXIT(cinfo, JERR_BUFFER_SIZE); ERREXIT(cinfo, JERR_BUFFER_SIZE);
/* The destination object is made permanent so that multiple JPEG images /* The destination object is made permanent so that multiple JPEG images
* can be written to the same buffer without re-executing jpeg_mem_dest. * can be written to the same buffer without re-executing jpeg_mem_dest.
*/ */
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));
} }
dest = (my_mem_dest_ptr) cinfo->dest; dest = (my_mem_dest_ptr) cinfo->dest;

View File

@@ -157,21 +157,21 @@ term_source (j_decompress_ptr cinfo)
GLOBAL(void) GLOBAL(void)
jpeg_mem_src_tj (j_decompress_ptr cinfo, jpeg_mem_src_tj (j_decompress_ptr cinfo,
unsigned char * inbuffer, unsigned long insize) unsigned char * inbuffer, unsigned long insize)
{ {
struct jpeg_source_mgr * src; struct jpeg_source_mgr * src;
if (inbuffer == NULL || insize == 0) /* Treat empty input as fatal error */ if (inbuffer == NULL || insize == 0) /* Treat empty input as fatal error */
ERREXIT(cinfo, JERR_INPUT_EMPTY); ERREXIT(cinfo, JERR_INPUT_EMPTY);
/* The source object is made permanent so that a series of JPEG images /* The source object is made permanent so that a series of JPEG images
* can be read from the same buffer by calling jpeg_mem_src only before * can be read from the same buffer by calling jpeg_mem_src only before
* the first one. * the first one.
*/ */
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));
} }
src = cinfo->src; src = cinfo->src;

View File

@@ -26,16 +26,16 @@
/* Expanded data source object for stdio input */ /* Expanded data source object for stdio input */
typedef struct { typedef struct {
struct jpeg_source_mgr pub; /* public fields */ struct jpeg_source_mgr pub; /* public fields */
FILE * infile; /* source stream */ FILE * infile; /* source stream */
JOCTET * buffer; /* start of buffer */ JOCTET * buffer; /* start of buffer */
boolean start_of_file; /* have we gotten any data yet? */ boolean start_of_file; /* have we gotten any data yet? */
} my_source_mgr; } my_source_mgr;
typedef my_source_mgr * my_src_ptr; typedef my_source_mgr * my_src_ptr;
#define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */ #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
/* /*
@@ -106,7 +106,7 @@ fill_input_buffer (j_decompress_ptr cinfo)
nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE); nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
if (nbytes <= 0) { if (nbytes <= 0) {
if (src->start_of_file) /* Treat empty input file as fatal error */ if (src->start_of_file) /* Treat empty input file as fatal error */
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 */
@@ -224,14 +224,14 @@ jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
* This makes it unsafe to use this manager and a different source * This makes it unsafe to use this manager and a different source
* manager serially with the same JPEG object. Caveat programmer. * manager serially with the same JPEG object. Caveat programmer.
*/ */
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));
} }
src = (my_src_ptr) cinfo->src; src = (my_src_ptr) cinfo->src;
@@ -254,21 +254,21 @@ 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,
unsigned char * inbuffer, unsigned long insize) unsigned char * inbuffer, unsigned long insize)
{ {
struct jpeg_source_mgr * src; struct jpeg_source_mgr * src;
if (inbuffer == NULL || insize == 0) /* Treat empty input as fatal error */ if (inbuffer == NULL || insize == 0) /* Treat empty input as fatal error */
ERREXIT(cinfo, JERR_INPUT_EMPTY); ERREXIT(cinfo, JERR_INPUT_EMPTY);
/* The source object is made permanent so that a series of JPEG images /* The source object is made permanent so that a series of JPEG images
* can be read from the same buffer by calling jpeg_mem_src only before * can be read from the same buffer by calling jpeg_mem_src only before
* the first one. * the first one.
*/ */
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));
} }
src = cinfo->src; src = cinfo->src;

View File

@@ -33,18 +33,15 @@ typedef struct {
/* These variables keep track of the current location of the input side. */ /* These variables keep track of the current location of the input side. */
/* cinfo->input_iMCU_row is also used for this. */ /* cinfo->input_iMCU_row is also used for this. */
JDIMENSION MCU_ctr; /* counts MCUs processed in current row */ JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
int MCU_vert_offset; /* counts MCU rows within iMCU row */ int MCU_vert_offset; /* counts MCU rows within iMCU row */
int MCU_rows_per_iMCU_row; /* number of such rows needed */ int MCU_rows_per_iMCU_row; /* number of such rows needed */
/* The output side's location is represented by cinfo->output_iMCU_row. */ /* The output side's location is represented by cinfo->output_iMCU_row. */
/* In single-pass modes, it's sufficient to buffer just one MCU. /* In single-pass modes, it's sufficient to buffer just one MCU.
* We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks, * We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks,
* and let the entropy decoder write into that workspace each time. * and let the entropy decoder write into that workspace each time.
* (On 80x86, the workspace is FAR even though it's not really very big;
* this is to keep the module interfaces unchanged when a large coefficient
* buffer is necessary.)
* In multi-pass modes, this array points to the current MCU's blocks * In multi-pass modes, this array points to the current MCU's blocks
* within the virtual arrays; it is used only by the input side. * within the virtual arrays; it is used only by the input side.
*/ */
@@ -61,7 +58,7 @@ typedef struct {
#ifdef BLOCK_SMOOTHING_SUPPORTED #ifdef BLOCK_SMOOTHING_SUPPORTED
/* When doing block smoothing, we latch coefficient Al values here */ /* When doing block smoothing, we latch coefficient Al values here */
int * coef_bits_latch; int * coef_bits_latch;
#define SAVED_COEFS 6 /* we save coef_bits[0..5] */ #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
#endif #endif
} my_coef_controller; } my_coef_controller;
@@ -69,15 +66,15 @@ typedef my_coef_controller * my_coef_ptr;
/* Forward declarations */ /* Forward declarations */
METHODDEF(int) decompress_onepass METHODDEF(int) decompress_onepass
JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf)); (j_decompress_ptr cinfo, JSAMPIMAGE output_buf);
#ifdef D_MULTISCAN_FILES_SUPPORTED #ifdef D_MULTISCAN_FILES_SUPPORTED
METHODDEF(int) decompress_data METHODDEF(int) decompress_data
JPP((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 JPP((j_decompress_ptr cinfo)); LOCAL(boolean) smoothing_ok (j_decompress_ptr cinfo);
METHODDEF(int) decompress_smooth_data METHODDEF(int) decompress_smooth_data
JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf)); (j_decompress_ptr cinfo, JSAMPIMAGE output_buf);
#endif #endif
@@ -153,7 +150,7 @@ 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;
int blkn, ci, xindex, yindex, yoffset, useful_width; int blkn, ci, xindex, yindex, yoffset, useful_width;
@@ -166,49 +163,49 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
yoffset++) { yoffset++) {
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 FAR *) 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;
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
} }
/* Determine where data should go in output_buf and do the IDCT thing. /* Determine where data should go in output_buf and do the IDCT thing.
* We skip dummy blocks at the right and bottom edges (but blkn gets * We skip dummy blocks at the right and bottom edges (but blkn gets
* incremented past them!). Note the inner loop relies on having * incremented past them!). Note the inner loop relies on having
* allocated the MCU_buffer[] blocks sequentially. * allocated the MCU_buffer[] blocks sequentially.
*/ */
blkn = 0; /* index of current DCT block within MCU */ blkn = 0; /* index of current DCT block within MCU */
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->MCU_width
: compptr->last_col_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 * compptr->MCU_sample_width; start_col = MCU_col_num * 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;
} }
} }
blkn += compptr->MCU_width; blkn += compptr->MCU_width;
output_ptr += compptr->_DCT_scaled_size; output_ptr += compptr->_DCT_scaled_size;
} }
} }
} }
/* Completed an MCU row, but perhaps not an iMCU row */ /* Completed an MCU row, but perhaps not an iMCU row */
@@ -233,7 +230,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 */
} }
@@ -250,7 +247,7 @@ 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;
JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
@@ -274,25 +271,25 @@ consume_data (j_decompress_ptr cinfo)
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
yoffset++) { yoffset++) {
for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row; for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
MCU_col_num++) { MCU_col_num++) {
/* Construct list of pointers to DCT blocks belonging to this MCU */ /* Construct list of pointers to DCT blocks belonging to this MCU */
blkn = 0; /* index of current DCT block within MCU */ blkn = 0; /* index of current DCT block within MCU */
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;
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;
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
} }
} }
/* Completed an MCU row, but perhaps not an iMCU row */ /* Completed an MCU row, but perhaps not an iMCU row */
@@ -333,8 +330,8 @@ decompress_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->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;
} }
@@ -365,10 +362,10 @@ decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
buffer_ptr = buffer[block_row]; buffer_ptr = buffer[block_row];
output_col = 0; output_col = 0;
for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) { for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr, (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
output_ptr, output_col); output_ptr, output_col);
buffer_ptr++; buffer_ptr++;
output_col += compptr->_DCT_scaled_size; output_col += compptr->_DCT_scaled_size;
} }
output_ptr += compptr->_DCT_scaled_size; output_ptr += compptr->_DCT_scaled_size;
} }
@@ -425,8 +422,8 @@ smoothing_ok (j_decompress_ptr cinfo)
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;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
@@ -436,11 +433,11 @@ smoothing_ok (j_decompress_ptr cinfo)
return FALSE; return FALSE;
/* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */ /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */
if (qtable->quantval[0] == 0 || if (qtable->quantval[0] == 0 ||
qtable->quantval[Q01_POS] == 0 || qtable->quantval[Q01_POS] == 0 ||
qtable->quantval[Q10_POS] == 0 || qtable->quantval[Q10_POS] == 0 ||
qtable->quantval[Q20_POS] == 0 || qtable->quantval[Q20_POS] == 0 ||
qtable->quantval[Q11_POS] == 0 || qtable->quantval[Q11_POS] == 0 ||
qtable->quantval[Q02_POS] == 0) qtable->quantval[Q02_POS] == 0)
return FALSE; return FALSE;
/* DC values must be at least partly known for all components. */ /* DC values must be at least partly known for all components. */
coef_bits = cinfo->coef_bits[ci]; coef_bits = cinfo->coef_bits[ci];
@@ -450,7 +447,7 @@ smoothing_ok (j_decompress_ptr cinfo)
for (coefi = 1; coefi <= 5; coefi++) { for (coefi = 1; coefi <= 5; coefi++) {
coef_bits_latch[coefi] = coef_bits[coefi]; coef_bits_latch[coefi] = coef_bits[coefi];
if (coef_bits[coefi] != 0) if (coef_bits[coefi] != 0)
smoothing_useful = TRUE; smoothing_useful = TRUE;
} }
coef_bits_latch += SAVED_COEFS; coef_bits_latch += SAVED_COEFS;
} }
@@ -489,7 +486,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,
@@ -498,7 +495,7 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
*/ */
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;
@@ -526,15 +523,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 */
@@ -552,13 +549,13 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
for (block_row = 0; block_row < block_rows; block_row++) { for (block_row = 0; block_row < block_rows; block_row++) {
buffer_ptr = buffer[block_row]; buffer_ptr = buffer[block_row];
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.
*/ */
@@ -568,102 +565,102 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
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 = 0; block_num <= last_block_column; block_num++) { for (block_num = 0; block_num <= last_block_column; 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_col); output_ptr, 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;
DC7 = DC8; DC8 = DC9; DC7 = DC8; DC8 = DC9;
buffer_ptr++, prev_block_row++, next_block_row++; buffer_ptr++, prev_block_row++, next_block_row++;
output_col += compptr->_DCT_scaled_size; output_col += compptr->_DCT_scaled_size;
} }
output_ptr += compptr->_DCT_scaled_size; output_ptr += compptr->_DCT_scaled_size;
} }
@@ -688,7 +685,7 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
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;
@@ -706,20 +703,20 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
jpeg_component_info *compptr; jpeg_component_info *compptr;
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++) {
access_rows = compptr->v_samp_factor; access_rows = compptr->v_samp_factor;
#ifdef BLOCK_SMOOTHING_SUPPORTED #ifdef BLOCK_SMOOTHING_SUPPORTED
/* If block smoothing could be used, need a bigger window */ /* If block smoothing could be used, need a bigger window */
if (cinfo->progressive_mode) if (cinfo->progressive_mode)
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;
@@ -734,7 +731,7 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
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;
} }
@@ -746,5 +743,5 @@ 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);
} }

408
jdcol565.c Normal file
View File

@@ -0,0 +1,408 @@
/*
* jdcol565.c
*
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane.
* Modifications:
* Copyright (C) 2013, Linaro Limited.
* For conditions of distribution and use, see the accompanying README file.
*
* This file contains output colorspace conversion routines.
*/
/* This file is included by jdcolor.c */
#define PACK_SHORT_565(r, g, b) ((((r) << 8) & 0xf800) | \
(((g) << 3) & 0x7E0) | ((b) >> 3))
#define PACK_TWO_PIXELS(l, r) ((r << 16) | l)
#define PACK_NEED_ALIGNMENT(ptr) (((size_t)(ptr)) & 3)
#define WRITE_TWO_PIXELS(addr, pixels) { \
((INT16*)(addr))[0] = (pixels); \
((INT16*)(addr))[1] = (pixels) >> 16; \
}
#define WRITE_TWO_ALIGNED_PIXELS(addr, pixels) ((*(INT32 *)(addr)) = pixels)
#define DITHER_565_R(r, dither) ((r) + ((dither) & 0xFF))
#define DITHER_565_G(g, dither) ((g) + (((dither) & 0xFF) >> 1))
#define DITHER_565_B(b, dither) ((b) + ((dither) & 0xFF))
/* Declarations for ordered dithering
*
* We use a 4x4 ordered dither array packed into 32 bits. This array is
* sufficent for dithering RGB888 to RGB565.
*/
#define DITHER_MASK 0x3
#define DITHER_ROTATE(x) (((x) << 24) | (((x) >> 8) & 0x00FFFFFF))
static const INT32 dither_matrix[4] = {
0x0008020A,
0x0C040E06,
0x030B0109,
0x0F070D05
};
METHODDEF(void)
ycc_rgb565_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int y, cb, cr;
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
/* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit;
register int * Crrtab = cconvert->Cr_r_tab;
register int * Cbbtab = cconvert->Cb_b_tab;
register INT32 * Crgtab = cconvert->Cr_g_tab;
register INT32 * Cbgtab = cconvert->Cb_g_tab;
SHIFT_TEMPS
while (--num_rows >= 0) {
INT32 rgb;
unsigned int r, g, b;
inptr0 = input_buf[0][input_row];
inptr1 = input_buf[1][input_row];
inptr2 = input_buf[2][input_row];
input_row++;
outptr = *output_buf++;
if (PACK_NEED_ALIGNMENT(outptr)) {
y = GETJSAMPLE(*inptr0++);
cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++);
r = range_limit[y + Crrtab[cr]];
g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS))];
b = range_limit[y + Cbbtab[cb]];
rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = rgb;
outptr += 2;
num_cols--;
}
for (col = 0; col < (num_cols >> 1); col++) {
y = GETJSAMPLE(*inptr0++);
cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++);
r = range_limit[y + Crrtab[cr]];
g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS))];
b = range_limit[y + Cbbtab[cb]];
rgb = PACK_SHORT_565(r, g, b);
y = GETJSAMPLE(*inptr0++);
cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++);
r = range_limit[y + Crrtab[cr]];
g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS))];
b = range_limit[y + Cbbtab[cb]];
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
outptr += 4;
}
if (num_cols & 1) {
y = GETJSAMPLE(*inptr0);
cb = GETJSAMPLE(*inptr1);
cr = GETJSAMPLE(*inptr2);
r = range_limit[y + Crrtab[cr]];
g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS))];
b = range_limit[y + Cbbtab[cb]];
rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = rgb;
}
}
}
METHODDEF(void)
ycc_rgb565D_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int y, cb, cr;
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
/* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit;
register int * Crrtab = cconvert->Cr_r_tab;
register int * Cbbtab = cconvert->Cb_b_tab;
register INT32 * Crgtab = cconvert->Cr_g_tab;
register INT32 * Cbgtab = cconvert->Cb_g_tab;
INT32 d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
SHIFT_TEMPS
while (--num_rows >= 0) {
INT32 rgb;
unsigned int r, g, b;
inptr0 = input_buf[0][input_row];
inptr1 = input_buf[1][input_row];
inptr2 = input_buf[2][input_row];
input_row++;
outptr = *output_buf++;
if (PACK_NEED_ALIGNMENT(outptr)) {
y = GETJSAMPLE(*inptr0++);
cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++);
r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
g = range_limit[DITHER_565_G(y +
((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS)), d0)];
b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = rgb;
outptr += 2;
num_cols--;
}
for (col = 0; col < (num_cols >> 1); col++) {
y = GETJSAMPLE(*inptr0++);
cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++);
r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
g = range_limit[DITHER_565_G(y +
((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS)), d0)];
b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
d0 = DITHER_ROTATE(d0);
rgb = PACK_SHORT_565(r, g, b);
y = GETJSAMPLE(*inptr0++);
cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++);
r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
g = range_limit[DITHER_565_G(y +
((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS)), d0)];
b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
d0 = DITHER_ROTATE(d0);
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
outptr += 4;
}
if (num_cols & 1) {
y = GETJSAMPLE(*inptr0);
cb = GETJSAMPLE(*inptr1);
cr = GETJSAMPLE(*inptr2);
r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
g = range_limit[DITHER_565_G(y +
((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS)), d0)];
b = range_limit[DITHER_565_B(y + Cbbtab[cb], d0)];
rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = rgb;
}
}
}
METHODDEF(void)
rgb_rgb565_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
SHIFT_TEMPS
while (--num_rows >= 0) {
INT32 rgb;
unsigned int r, g, b;
inptr0 = input_buf[0][input_row];
inptr1 = input_buf[1][input_row];
inptr2 = input_buf[2][input_row];
input_row++;
outptr = *output_buf++;
if (PACK_NEED_ALIGNMENT(outptr)) {
r = GETJSAMPLE(*inptr0++);
g = GETJSAMPLE(*inptr1++);
b = GETJSAMPLE(*inptr2++);
rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = rgb;
outptr += 2;
num_cols--;
}
for (col = 0; col < (num_cols >> 1); col++) {
r = GETJSAMPLE(*inptr0++);
g = GETJSAMPLE(*inptr1++);
b = GETJSAMPLE(*inptr2++);
rgb = PACK_SHORT_565(r, g, b);
r = GETJSAMPLE(*inptr0++);
g = GETJSAMPLE(*inptr1++);
b = GETJSAMPLE(*inptr2++);
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
outptr += 4;
}
if (num_cols & 1) {
r = GETJSAMPLE(*inptr0);
g = GETJSAMPLE(*inptr1);
b = GETJSAMPLE(*inptr2);
rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = rgb;
}
}
}
METHODDEF(void)
rgb_rgb565D_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
register JSAMPLE * range_limit = cinfo->sample_range_limit;
JDIMENSION num_cols = cinfo->output_width;
INT32 d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
SHIFT_TEMPS
while (--num_rows >= 0) {
INT32 rgb;
unsigned int r, g, b;
inptr0 = input_buf[0][input_row];
inptr1 = input_buf[1][input_row];
inptr2 = input_buf[2][input_row];
input_row++;
outptr = *output_buf++;
if (PACK_NEED_ALIGNMENT(outptr)) {
r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0++), d0)];
g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1++), d0)];
b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2++), d0)];
rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = rgb;
outptr += 2;
num_cols--;
}
for (col = 0; col < (num_cols >> 1); col++) {
r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0++), d0)];
g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1++), d0)];
b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2++), d0)];
d0 = DITHER_ROTATE(d0);
rgb = PACK_SHORT_565(r, g, b);
r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0++), d0)];
g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1++), d0)];
b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2++), d0)];
d0 = DITHER_ROTATE(d0);
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
outptr += 4;
}
if (num_cols & 1) {
r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0), d0)];
g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1), d0)];
b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2), d0)];
rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = rgb;
}
}
}
METHODDEF(void)
gray_rgb565_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
register JSAMPROW inptr, outptr;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
while (--num_rows >= 0) {
INT32 rgb;
unsigned int g;
inptr = input_buf[0][input_row++];
outptr = *output_buf++;
if (PACK_NEED_ALIGNMENT(outptr)) {
g = *inptr++;
rgb = PACK_SHORT_565(g, g, g);
*(INT16*)outptr = rgb;
outptr += 2;
num_cols--;
}
for (col = 0; col < (num_cols >> 1); col++) {
g = *inptr++;
rgb = PACK_SHORT_565(g, g, g);
g = *inptr++;
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(g, g, g));
WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
outptr += 4;
}
if (num_cols & 1) {
g = *inptr;
rgb = PACK_SHORT_565(g, g, g);
*(INT16*)outptr = rgb;
}
}
}
METHODDEF(void)
gray_rgb565D_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
register JSAMPROW inptr, outptr;
register JDIMENSION col;
register JSAMPLE * range_limit = cinfo->sample_range_limit;
JDIMENSION num_cols = cinfo->output_width;
INT32 d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
while (--num_rows >= 0) {
INT32 rgb;
unsigned int g;
inptr = input_buf[0][input_row++];
outptr = *output_buf++;
if (PACK_NEED_ALIGNMENT(outptr)) {
g = *inptr++;
g = range_limit[DITHER_565_R(g, d0)];
rgb = PACK_SHORT_565(g, g, g);
*(INT16*)outptr = rgb;
outptr += 2;
num_cols--;
}
for (col = 0; col < (num_cols >> 1); col++) {
g = *inptr++;
g = range_limit[DITHER_565_R(g, d0)];
rgb = PACK_SHORT_565(g, g, g);
d0 = DITHER_ROTATE(d0);
g = *inptr++;
g = range_limit[DITHER_565_R(g, d0)];
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(g, g, g));
d0 = DITHER_ROTATE(d0);
WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
outptr += 4;
}
if (num_cols & 1) {
g = *inptr;
g = range_limit[DITHER_565_R(g, d0)];
rgb = PACK_SHORT_565(g, g, g);
*(INT16*)outptr = rgb;
}
}
}

View File

@@ -58,8 +58,8 @@ 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 */
/* alpha channel value */ /* alpha channel value */

138
jdcolor.c
View File

@@ -7,6 +7,7 @@
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2009, 2011-2012, D. R. Commander. * Copyright (C) 2009, 2011-2012, D. R. Commander.
* Copyright (C) 2013, Linaro Limited.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains output colorspace conversion routines. * This file contains output colorspace conversion routines.
@@ -16,7 +17,7 @@
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jsimd.h" #include "jsimd.h"
#include "config.h" #include "jconfigint.h"
/* Private subobject */ /* Private subobject */
@@ -25,13 +26,13 @@ typedef struct {
struct jpeg_color_deconverter pub; /* public fields */ struct jpeg_color_deconverter pub; /* public fields */
/* Private state for YCC->RGB conversion */ /* Private state for YCC->RGB conversion */
int * Cr_r_tab; /* => table for Cr to R conversion */ int * Cr_r_tab; /* => table for Cr to R conversion */
int * Cb_b_tab; /* => table for Cb to B conversion */ int * Cb_b_tab; /* => table for Cb to B conversion */
INT32 * Cr_g_tab; /* => table for Cr to G conversion */ INT32 * Cr_g_tab; /* => table for Cr to G conversion */
INT32 * Cb_g_tab; /* => table for Cb to G conversion */ INT32 * Cb_g_tab; /* => table for Cb to G conversion */
/* Private state for RGB->Y conversion */ /* Private state for RGB->Y conversion */
INT32 * rgb_y_tab; /* => table for RGB to Y conversion */ INT32 * rgb_y_tab; /* => table for RGB to Y conversion */
} my_color_deconverter; } my_color_deconverter;
typedef my_color_deconverter * my_cconvert_ptr; typedef my_color_deconverter * my_cconvert_ptr;
@@ -45,11 +46,11 @@ typedef my_color_deconverter * my_cconvert_ptr;
* normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
* The conversion equations to be implemented are therefore * The conversion equations to be implemented are therefore
* *
* R = Y + 1.40200 * Cr * R = Y + 1.40200 * Cr
* G = Y - 0.34414 * Cb - 0.71414 * Cr * G = Y - 0.34414 * Cb - 0.71414 * Cr
* B = Y + 1.77200 * Cb * B = Y + 1.77200 * Cb
* *
* Y = 0.29900 * R + 0.58700 * G + 0.11400 * B * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
* *
* where Cb and Cr represent the incoming values less CENTERJSAMPLE. * where Cb and Cr represent the incoming values less CENTERJSAMPLE.
* (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
@@ -71,9 +72,9 @@ typedef my_color_deconverter * my_cconvert_ptr;
* together before rounding. * together before rounding.
*/ */
#define SCALEBITS 16 /* speediest right-shift on some machines */ #define SCALEBITS 16 /* speediest right-shift on some machines */
#define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) #define FIX(x) ((INT32) ((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
@@ -82,10 +83,10 @@ typedef my_color_deconverter * my_cconvert_ptr;
* anyway). * anyway).
*/ */
#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 */
@@ -215,26 +216,26 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
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 = (INT32 *) cconvert->Cr_g_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32)); (MAXJSAMPLE+1) * sizeof(INT32));
cconvert->Cb_g_tab = (INT32 *) cconvert->Cb_g_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32)); (MAXJSAMPLE+1) * sizeof(INT32));
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 */
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
/* Cr=>R value is nearest int to 1.40200 * x */ /* Cr=>R value is nearest int to 1.40200 * x */
cconvert->Cr_r_tab[i] = (int) cconvert->Cr_r_tab[i] = (int)
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
/* Cb=>B value is nearest int to 1.77200 * x */ /* Cb=>B value is nearest int to 1.77200 * x */
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 */
@@ -250,8 +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, JDIMENSION input_row, JSAMPIMAGE input_buf, 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:
@@ -307,7 +308,7 @@ build_rgb_y_table (j_decompress_ptr cinfo)
/* Allocate and fill in the conversion tables. */ /* Allocate and fill in the conversion tables. */
cconvert->rgb_y_tab = rgb_y_tab = (INT32 *) cconvert->rgb_y_tab = rgb_y_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(TABLE_SIZE * SIZEOF(INT32))); (TABLE_SIZE * sizeof(INT32)));
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;
@@ -323,8 +324,8 @@ 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, JDIMENSION input_row, JSAMPIMAGE input_buf, 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;
@@ -346,8 +347,8 @@ rgb_gray_convert (j_decompress_ptr cinfo,
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[b+B_Y_OFF]) ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
>> SCALEBITS); >> SCALEBITS);
} }
} }
} }
@@ -360,8 +361,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, JDIMENSION input_row, JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
register JDIMENSION count; register JDIMENSION count;
@@ -374,8 +375,8 @@ null_convert (j_decompress_ptr cinfo,
inptr = input_buf[ci][input_row]; inptr = input_buf[ci][input_row];
outptr = output_buf[0] + ci; outptr = output_buf[0] + ci;
for (count = num_cols; count > 0; count--) { for (count = num_cols; count > 0; count--) {
*outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */ *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
outptr += num_components; outptr += num_components;
} }
} }
input_row++; input_row++;
@@ -392,11 +393,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, JDIMENSION input_row, JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0, jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
num_rows, cinfo->output_width); num_rows, cinfo->output_width);
} }
@@ -406,8 +407,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, JDIMENSION input_row, JSAMPIMAGE input_buf, 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:
@@ -452,8 +453,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, JDIMENSION input_row, JSAMPIMAGE input_buf, 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:
@@ -501,8 +502,8 @@ 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, JDIMENSION input_row, JSAMPIMAGE input_buf, 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;
@@ -530,19 +531,22 @@ ycck_cmyk_convert (j_decompress_ptr cinfo,
cb = GETJSAMPLE(inptr1[col]); cb = GETJSAMPLE(inptr1[col]);
cr = GETJSAMPLE(inptr2[col]); cr = GETJSAMPLE(inptr2[col]);
/* 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 */
outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */ outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
outptr += 4; outptr += 4;
} }
} }
} }
#include "jdcol565.c"
/* /*
* Empty method for start_pass. * Empty method for start_pass.
*/ */
@@ -566,7 +570,7 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
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;
@@ -589,7 +593,7 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
break; break;
default: /* JCS_UNKNOWN can be anything */ default: /* JCS_UNKNOWN can be anything */
if (cinfo->num_components < 1) if (cinfo->num_components < 1)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
break; break;
@@ -604,11 +608,11 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
case JCS_GRAYSCALE: case JCS_GRAYSCALE:
cinfo->out_color_components = 1; cinfo->out_color_components = 1;
if (cinfo->jpeg_color_space == JCS_GRAYSCALE || if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
cinfo->jpeg_color_space == JCS_YCbCr) { cinfo->jpeg_color_space == JCS_YCbCr) {
cconvert->pub.color_convert = grayscale_convert; cconvert->pub.color_convert = grayscale_convert;
/* For color->grayscale conversion, only the Y (0) component is needed */ /* For color->grayscale conversion, only the Y (0) component is needed */
for (ci = 1; ci < cinfo->num_components; ci++) for (ci = 1; ci < cinfo->num_components; ci++)
cinfo->comp_info[ci].component_needed = FALSE; cinfo->comp_info[ci].component_needed = FALSE;
} else if (cinfo->jpeg_color_space == JCS_RGB) { } else if (cinfo->jpeg_color_space == JCS_RGB) {
cconvert->pub.color_convert = rgb_gray_convert; cconvert->pub.color_convert = rgb_gray_convert;
build_rgb_y_table(cinfo); build_rgb_y_table(cinfo);
@@ -649,6 +653,32 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break; break;
case JCS_RGB565:
cinfo->out_color_components = 3;
if (cinfo->dither_mode == JDITHER_NONE) {
if (cinfo->jpeg_color_space == JCS_YCbCr) {
cconvert->pub.color_convert = ycc_rgb565_convert;
build_ycc_rgb_table(cinfo);
} else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
cconvert->pub.color_convert = gray_rgb565_convert;
} else if (cinfo->jpeg_color_space == JCS_RGB) {
cconvert->pub.color_convert = rgb_rgb565_convert;
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
} else {
/* only ordered dithering is supported */
if (cinfo->jpeg_color_space == JCS_YCbCr) {
cconvert->pub.color_convert = ycc_rgb565D_convert;
build_ycc_rgb_table(cinfo);
} else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
cconvert->pub.color_convert = gray_rgb565D_convert;
} else if (cinfo->jpeg_color_space == JCS_RGB) {
cconvert->pub.color_convert = rgb_rgb565D_convert;
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
break;
case JCS_CMYK: case JCS_CMYK:
cinfo->out_color_components = 4; cinfo->out_color_components = 4;
if (cinfo->jpeg_color_space == JCS_YCCK) { if (cinfo->jpeg_color_space == JCS_YCCK) {
@@ -665,7 +695,7 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
if (cinfo->out_color_space == cinfo->jpeg_color_space) { if (cinfo->out_color_space == cinfo->jpeg_color_space) {
cinfo->out_color_components = cinfo->num_components; cinfo->out_color_components = cinfo->num_components;
cconvert->pub.color_convert = null_convert; cconvert->pub.color_convert = null_convert;
} else /* unsupported non-null conversion */ } else /* unsupported non-null conversion */
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break; break;
} }

132
jdct.h
View File

@@ -1,8 +1,10 @@
/* /*
* jdct.h * jdct.h
* *
* 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.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This include file contains common declarations for the forward and * This include file contains common declarations for the forward and
@@ -29,7 +31,7 @@
#if BITS_IN_JSAMPLE == 8 #if BITS_IN_JSAMPLE == 8
#ifndef WITH_SIMD #ifndef WITH_SIMD
typedef int DCTELEM; /* 16 or 32 bits is fine */ typedef int DCTELEM; /* 16 or 32 bits is fine */
typedef unsigned int UDCTELEM; typedef unsigned int UDCTELEM;
typedef unsigned long long UDCTELEM2; typedef unsigned long long UDCTELEM2;
#else #else
@@ -38,7 +40,7 @@ typedef unsigned short UDCTELEM;
typedef unsigned int UDCTELEM2; typedef unsigned int UDCTELEM2;
#endif #endif
#else #else
typedef INT32 DCTELEM; /* must have 32 bits */ typedef INT32 DCTELEM; /* must have 32 bits */
typedef UINT32 UDCTELEM; typedef UINT32 UDCTELEM;
typedef unsigned long long UDCTELEM2; typedef unsigned long long UDCTELEM2;
#endif #endif
@@ -64,10 +66,10 @@ typedef unsigned long long UDCTELEM2;
typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */ typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
#if BITS_IN_JSAMPLE == 8 #if BITS_IN_JSAMPLE == 8
typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */ typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
#define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */ #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
#else #else
typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */ typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
#define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */ #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
#endif #endif
typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */ typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
@@ -86,92 +88,66 @@ typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
#define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */ #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
/* Short forms of external names for systems with brain-damaged linkers. */
#ifdef NEED_SHORT_EXTERNAL_NAMES
#define jpeg_fdct_islow jFDislow
#define jpeg_fdct_ifast jFDifast
#define jpeg_fdct_float jFDfloat
#define jpeg_idct_islow jRDislow
#define jpeg_idct_ifast jRDifast
#define jpeg_idct_float jRDfloat
#define jpeg_idct_7x7 jRD7x7
#define jpeg_idct_6x6 jRD6x6
#define jpeg_idct_5x5 jRD5x5
#define jpeg_idct_4x4 jRD4x4
#define jpeg_idct_3x3 jRD3x3
#define jpeg_idct_2x2 jRD2x2
#define jpeg_idct_1x1 jRD1x1
#define jpeg_idct_9x9 jRD9x9
#define jpeg_idct_10x10 jRD10x10
#define jpeg_idct_11x11 jRD11x11
#define jpeg_idct_12x12 jRD12x12
#define jpeg_idct_13x13 jRD13x13
#define jpeg_idct_14x14 jRD14x14
#define jpeg_idct_15x15 jRD15x15
#define jpeg_idct_16x16 jRD16x16
#endif /* NEED_SHORT_EXTERNAL_NAMES */
/* Extern declarations for the forward and inverse DCT routines. */ /* Extern declarations for the forward and inverse DCT routines. */
EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data)); EXTERN(void) jpeg_fdct_islow (DCTELEM * data);
EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data)); EXTERN(void) jpeg_fdct_ifast (DCTELEM * data);
EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data)); EXTERN(void) jpeg_fdct_float (FAST_FLOAT * data);
EXTERN(void) jpeg_idct_islow EXTERN(void) jpeg_idct_islow
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_ifast EXTERN(void) jpeg_idct_ifast
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_float EXTERN(void) jpeg_idct_float
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_7x7 EXTERN(void) jpeg_idct_7x7
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_6x6 EXTERN(void) jpeg_idct_6x6
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_5x5 EXTERN(void) jpeg_idct_5x5
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_4x4 EXTERN(void) jpeg_idct_4x4
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_3x3 EXTERN(void) jpeg_idct_3x3
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_2x2 EXTERN(void) jpeg_idct_2x2
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_1x1 EXTERN(void) jpeg_idct_1x1
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_9x9 EXTERN(void) jpeg_idct_9x9
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_10x10 EXTERN(void) jpeg_idct_10x10
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_11x11 EXTERN(void) jpeg_idct_11x11
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_12x12 EXTERN(void) jpeg_idct_12x12
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_13x13 EXTERN(void) jpeg_idct_13x13
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_14x14 EXTERN(void) jpeg_idct_14x14
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_15x15 EXTERN(void) jpeg_idct_15x15
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_16x16 EXTERN(void) jpeg_idct_16x16
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
/* /*
@@ -184,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 ((INT32) 1) #define ONE ((INT32) 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.
@@ -192,7 +168,7 @@ 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) ((INT32) ((x) * CONST_SCALE + 0.5)) #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
/* Descale and correctly round an INT32 value that's scaled by N bits. /* Descale and correctly round an INT32 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
@@ -210,23 +186,23 @@ EXTERN(void) jpeg_idct_16x16
* correct combination of casts. * correct combination of casts.
*/ */
#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)) * ((INT32) (const))) #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (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

@@ -7,6 +7,7 @@
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2010, D. R. Commander. * Copyright (C) 2010, D. R. Commander.
* Copyright (C) 2013, MIPS Technologies, Inc., California
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains the inverse-DCT management logic. * This file contains the inverse-DCT management logic.
@@ -22,7 +23,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#include "jsimddct.h" #include "jsimddct.h"
#include "jpegcomp.h" #include "jpegcomp.h"
@@ -47,7 +48,7 @@
/* Private subobject for this module */ /* Private subobject for this module */
typedef struct { typedef struct {
struct jpeg_inverse_dct pub; /* public fields */ struct jpeg_inverse_dct pub; /* public fields */
/* This array contains the IDCT method code that each multiplier table /* This array contains the IDCT method code that each multiplier table
* is currently set up for, or -1 if it's not yet set up. * is currently set up for, or -1 if it's not yet set up.
@@ -108,29 +109,29 @@ start_pass (j_decompress_ptr cinfo)
#ifdef IDCT_SCALING_SUPPORTED #ifdef IDCT_SCALING_SUPPORTED
case 1: case 1:
method_ptr = jpeg_idct_1x1; method_ptr = jpeg_idct_1x1;
method = JDCT_ISLOW; /* jidctred uses islow-style table */ method = JDCT_ISLOW; /* jidctred uses islow-style table */
break; break;
case 2: case 2:
if (jsimd_can_idct_2x2()) if (jsimd_can_idct_2x2())
method_ptr = jsimd_idct_2x2; method_ptr = jsimd_idct_2x2;
else else
method_ptr = jpeg_idct_2x2; method_ptr = jpeg_idct_2x2;
method = JDCT_ISLOW; /* jidctred uses islow-style table */ method = JDCT_ISLOW; /* jidctred uses islow-style table */
break; break;
case 3: case 3:
method_ptr = jpeg_idct_3x3; method_ptr = jpeg_idct_3x3;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 4: case 4:
if (jsimd_can_idct_4x4()) if (jsimd_can_idct_4x4())
method_ptr = jsimd_idct_4x4; method_ptr = jsimd_idct_4x4;
else else
method_ptr = jpeg_idct_4x4; method_ptr = jpeg_idct_4x4;
method = JDCT_ISLOW; /* jidctred uses islow-style table */ method = JDCT_ISLOW; /* jidctred uses islow-style table */
break; break;
case 5: case 5:
method_ptr = jpeg_idct_5x5; method_ptr = jpeg_idct_5x5;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 6: case 6:
#if defined(__mips__) #if defined(__mips__)
@@ -139,58 +140,58 @@ start_pass (j_decompress_ptr cinfo)
else else
#endif #endif
method_ptr = jpeg_idct_6x6; method_ptr = jpeg_idct_6x6;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 7: case 7:
method_ptr = jpeg_idct_7x7; method_ptr = jpeg_idct_7x7;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
#endif #endif
case DCTSIZE: case DCTSIZE:
switch (cinfo->dct_method) { switch (cinfo->dct_method) {
#ifdef DCT_ISLOW_SUPPORTED #ifdef DCT_ISLOW_SUPPORTED
case JDCT_ISLOW: case JDCT_ISLOW:
if (jsimd_can_idct_islow()) if (jsimd_can_idct_islow())
method_ptr = jsimd_idct_islow; method_ptr = jsimd_idct_islow;
else else
method_ptr = jpeg_idct_islow; method_ptr = jpeg_idct_islow;
method = JDCT_ISLOW; method = JDCT_ISLOW;
break; break;
#endif #endif
#ifdef DCT_IFAST_SUPPORTED #ifdef DCT_IFAST_SUPPORTED
case JDCT_IFAST: case JDCT_IFAST:
if (jsimd_can_idct_ifast()) if (jsimd_can_idct_ifast())
method_ptr = jsimd_idct_ifast; method_ptr = jsimd_idct_ifast;
else else
method_ptr = jpeg_idct_ifast; method_ptr = jpeg_idct_ifast;
method = JDCT_IFAST; method = JDCT_IFAST;
break; break;
#endif #endif
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
case JDCT_FLOAT: case JDCT_FLOAT:
if (jsimd_can_idct_float()) if (jsimd_can_idct_float())
method_ptr = jsimd_idct_float; method_ptr = jsimd_idct_float;
else else
method_ptr = jpeg_idct_float; method_ptr = jpeg_idct_float;
method = JDCT_FLOAT; method = JDCT_FLOAT;
break; break;
#endif #endif
default: default:
ERREXIT(cinfo, JERR_NOT_COMPILED); ERREXIT(cinfo, JERR_NOT_COMPILED);
break; break;
} }
break; break;
case 9: case 9:
method_ptr = jpeg_idct_9x9; method_ptr = jpeg_idct_9x9;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 10: case 10:
method_ptr = jpeg_idct_10x10; method_ptr = jpeg_idct_10x10;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 11: case 11:
method_ptr = jpeg_idct_11x11; method_ptr = jpeg_idct_11x11;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 12: case 12:
#if defined(__mips__) #if defined(__mips__)
@@ -199,23 +200,23 @@ start_pass (j_decompress_ptr cinfo)
else else
#endif #endif
method_ptr = jpeg_idct_12x12; method_ptr = jpeg_idct_12x12;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 13: case 13:
method_ptr = jpeg_idct_13x13; method_ptr = jpeg_idct_13x13;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 14: case 14:
method_ptr = jpeg_idct_14x14; method_ptr = jpeg_idct_14x14;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 15: case 15:
method_ptr = jpeg_idct_15x15; method_ptr = jpeg_idct_15x15;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 16: case 16:
method_ptr = jpeg_idct_16x16; method_ptr = jpeg_idct_16x16;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
default: default:
ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->_DCT_scaled_size); ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->_DCT_scaled_size);
@@ -232,81 +233,81 @@ start_pass (j_decompress_ptr cinfo)
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 */
continue; continue;
idct->cur_method[ci] = method; idct->cur_method[ci] = method;
switch (method) { switch (method) {
#ifdef PROVIDE_ISLOW_TABLES #ifdef PROVIDE_ISLOW_TABLES
case JDCT_ISLOW: case JDCT_ISLOW:
{ {
/* 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;
#endif #endif
#ifdef DCT_IFAST_SUPPORTED #ifdef DCT_IFAST_SUPPORTED
case JDCT_IFAST: case JDCT_IFAST:
{ {
/* For AA&N IDCT method, multipliers are equal to quantization /* For AA&N IDCT method, multipliers are equal to quantization
* coefficients scaled by scalefactor[row]*scalefactor[col], where * coefficients scaled by scalefactor[row]*scalefactor[col], where
* 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
* 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 */
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
}; };
SHIFT_TEMPS SHIFT_TEMPS
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
ifmtbl[i] = (IFAST_MULT_TYPE) ifmtbl[i] = (IFAST_MULT_TYPE)
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
(INT32) aanscales[i]), (INT32) aanscales[i]),
CONST_BITS-IFAST_SCALE_BITS); CONST_BITS-IFAST_SCALE_BITS);
} }
} }
break; break;
#endif #endif
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
case JDCT_FLOAT: case JDCT_FLOAT:
{ {
/* For float AA&N IDCT method, multipliers are equal to quantization /* For float AA&N IDCT method, multipliers are equal to quantization
* coefficients scaled by scalefactor[row]*scalefactor[col], where * coefficients scaled by scalefactor[row]*scalefactor[col], where
* 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,
1.0, 0.785694958, 0.541196100, 0.275899379 1.0, 0.785694958, 0.541196100, 0.275899379
}; };
i = 0; i = 0;
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++;
} }
} }
} }
break; break;
#endif #endif
@@ -331,7 +332,7 @@ jinit_inverse_dct (j_decompress_ptr cinfo)
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;
@@ -340,8 +341,8 @@ jinit_inverse_dct (j_decompress_ptr cinfo)
/* 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 */
idct->cur_method[ci] = -1; idct->cur_method[ci] = -1;
} }

128
jdhuff.c
View File

@@ -19,7 +19,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdhuff.h" /* Declarations shared with jdphuff.c */ #include "jdhuff.h" /* Declarations shared with jdphuff.c */
#include "jpegcomp.h" #include "jpegcomp.h"
#include "jstdhuff.c" #include "jstdhuff.c"
@@ -45,10 +45,10 @@ typedef struct {
#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], \
(dest).last_dc_val[3] = (src).last_dc_val[3]) (dest).last_dc_val[3] = (src).last_dc_val[3])
#endif #endif
#endif #endif
@@ -59,11 +59,11 @@ typedef struct {
/* These fields are loaded into local variables at start of each MCU. /* These fields are loaded into local variables at start of each MCU.
* In case of suspension, we exit WITHOUT updating them. * In case of suspension, we exit WITHOUT updating them.
*/ */
bitread_perm_state bitstate; /* Bit buffer at start of MCU */ bitread_perm_state bitstate; /* Bit buffer at start of MCU */
savable_state saved; /* Other state at start of MCU */ savable_state saved; /* Other state at start of MCU */
/* These fields are NOT loaded into local working state. */ /* These fields are NOT loaded into local working state. */
unsigned int restarts_to_go; /* MCUs left in this restart interval */ unsigned int restarts_to_go; /* MCUs left in this restart interval */
/* Pointers to derived tables (these workspaces have image lifespan) */ /* Pointers to derived tables (these workspaces have image lifespan) */
d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]; d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
@@ -108,9 +108,9 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
/* 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_d_derived_tbl(cinfo, TRUE, dctbl, jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
& entropy->dc_derived_tbls[dctbl]); & entropy->dc_derived_tbls[dctbl]);
jpeg_make_d_derived_tbl(cinfo, FALSE, actbl, jpeg_make_d_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;
} }
@@ -151,7 +151,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;
d_derived_tbl *dtbl; d_derived_tbl *dtbl;
@@ -177,16 +177,16 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
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 */
/* Figure C.1: make table of Huffman code length for each symbol */ /* Figure C.1: make table of Huffman code length for each symbol */
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;
@@ -226,7 +226,7 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
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 */
} }
} }
dtbl->valoffset[17] = 0; dtbl->valoffset[17] = 0;
@@ -249,8 +249,8 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
/* 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++;
} }
} }
} }
@@ -265,7 +265,7 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
for (i = 0; i < numsymbols; i++) { for (i = 0; i < numsymbols; i++) {
int sym = htbl->huffval[i]; int sym = htbl->huffval[i];
if (sym < 0 || sym > 15) if (sym < 0 || sym > 15)
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
} }
} }
} }
@@ -287,7 +287,7 @@ 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
@@ -295,8 +295,8 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
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 */
{ {
/* Copy heavily used state fields into locals (hopefully registers) */ /* Copy heavily used state fields into locals (hopefully registers) */
@@ -308,54 +308,54 @@ jpeg_fill_bit_buffer (bitread_working_state * state,
/* (It is assumed that no request will be for more than that many bits.) */ /* (It is assumed that no request will be for more than that many bits.) */
/* We fail to do so only if we hit a marker or are forced to suspend. */ /* We fail to do so only if we hit a marker or are forced to suspend. */
if (cinfo->unread_marker == 0) { /* cannot advance past a marker */ if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
while (bits_left < MIN_GET_BITS) { while (bits_left < MIN_GET_BITS) {
register int c; register int c;
/* 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;
} }
bytes_in_buffer--; bytes_in_buffer--;
c = GETJOCTET(*next_input_byte++); c = GETJOCTET(*next_input_byte++);
/* If it's 0xFF, check and discard stuffed zero byte */ /* If it's 0xFF, check and discard stuffed zero byte */
if (c == 0xFF) { if (c == 0xFF) {
/* Loop here to discard any padding FF's on terminating marker, /* Loop here to discard any padding FF's on terminating marker,
* so that we can save a valid unread_marker value. NOTE: we will * so that we can save a valid unread_marker value. NOTE: we will
* accept multiple FF's followed by a 0 as meaning a single FF data * accept multiple FF's followed by a 0 as meaning a single FF data
* byte. This data pattern is not valid according to the standard. * byte. This data pattern is not valid according to the standard.
*/ */
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;
} }
bytes_in_buffer--; bytes_in_buffer--;
c = GETJOCTET(*next_input_byte++); c = GETJOCTET(*next_input_byte++);
} while (c == 0xFF); } while (c == 0xFF);
if (c == 0) { if (c == 0) {
/* Found FF/00, which represents an FF data byte */ /* Found FF/00, which represents an FF data byte */
c = 0xFF; c = 0xFF;
} else { } else {
/* Oops, it's actually a marker indicating end of compressed data. /* Oops, it's actually a marker indicating end of compressed data.
* Save the marker code for later use. * Save the marker code for later use.
* Fine point: it might appear that we should save the marker into * Fine point: it might appear that we should save the marker into
* bitread working state, not straight into permanent state. But * bitread working state, not straight into permanent state. But
* once we have hit a marker, we cannot need to suspend within the * once we have hit a marker, we cannot need to suspend within the
* current MCU, because we will read no more bytes from the data * current MCU, because we will read no more bytes from the data
* source. So it is OK to update permanent state right away. * source. So it is OK to update permanent state right away.
*/ */
cinfo->unread_marker = c; cinfo->unread_marker = c;
/* See if we need to insert some fake zero bits. */ /* See if we need to insert some fake zero bits. */
goto no_more_bytes; goto no_more_bytes;
} }
} }
/* OK, load c into get_buffer */ /* OK, load c into get_buffer */
@@ -375,8 +375,8 @@ jpeg_fill_bit_buffer (bitread_working_state * state,
* 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;
} }
/* Fill the buffer with zero bits */ /* Fill the buffer with zero bits */
get_buffer <<= MIN_GET_BITS - bits_left; get_buffer <<= MIN_GET_BITS - bits_left;
@@ -445,8 +445,8 @@ 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)
{ {
register int l = min_bits; register int l = min_bits;
register INT32 code; register INT32 code;
@@ -475,7 +475,7 @@ jpeg_huff_decode (bitread_working_state * state,
if (l > 16) { if (l > 16) {
WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE); WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
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]) ];
@@ -756,7 +756,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
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;
} }
@@ -804,7 +804,7 @@ jinit_huff_decoder (j_decompress_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;

104
jdhuff.h
View File

@@ -3,7 +3,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.
* Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2010-2011, D. R. Commander. * Copyright (C) 2010-2011, D. R. Commander.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -12,24 +12,16 @@
* progressive decoder (jdphuff.c). No other modules need to see these. * progressive decoder (jdphuff.c). No other modules need to see these.
*/ */
/* Short forms of external names for systems with brain-damaged linkers. */
#ifdef NEED_SHORT_EXTERNAL_NAMES
#define jpeg_make_d_derived_tbl jMkDDerived
#define jpeg_fill_bit_buffer jFilBitBuf
#define jpeg_huff_decode jHufDecode
#endif /* NEED_SHORT_EXTERNAL_NAMES */
/* Derived data constructed for each Huffman table */ /* Derived data constructed for each Huffman table */
#define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */ #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
typedef struct { typedef struct {
/* Basic tables: (element [0] of each array is unused) */ /* Basic tables: (element [0] of each array is unused) */
INT32 maxcode[18]; /* largest code of length k (-1 if none) */ INT32 maxcode[18]; /* largest code of length k (-1 if none) */
/* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */ /* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */
INT32 valoffset[18]; /* huffval[] offset for codes of length k */ INT32 valoffset[18]; /* huffval[] offset for codes of length k */
/* valoffset[k] = huffval[] index of 1st symbol of code length k, less /* valoffset[k] = huffval[] index of 1st symbol of code length k, less
* the smallest code of length k; so given a code of length k, the * the smallest code of length k; so given a code of length k, the
* corresponding symbol is huffval[code + valoffset[k]] * corresponding symbol is huffval[code + valoffset[k]]
@@ -53,8 +45,8 @@ typedef struct {
/* 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
JPP((j_decompress_ptr cinfo, boolean isDC, int tblno, (j_decompress_ptr cinfo, boolean isDC, int tblno,
d_derived_tbl ** pdtbl)); d_derived_tbl ** pdtbl);
/* /*
@@ -77,13 +69,13 @@ EXTERN(void) jpeg_make_d_derived_tbl
#if __WORDSIZE == 64 || defined(_WIN64) #if __WORDSIZE == 64 || 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 */
#else #else
typedef INT32 bit_buf_type; /* type of bit-extraction buffer */ typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
#define BIT_BUF_SIZE 32 /* size of buffer in bits */ #define BIT_BUF_SIZE 32 /* size of buffer in bits */
#endif #endif
@@ -94,43 +86,43 @@ typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
* because not all machines measure sizeof in 8-bit bytes. * because not all machines measure sizeof in 8-bit bytes.
*/ */
typedef struct { /* Bitreading state saved across MCUs */ typedef struct { /* Bitreading state saved across MCUs */
bit_buf_type get_buffer; /* current bit-extraction buffer */ bit_buf_type get_buffer; /* current bit-extraction buffer */
int bits_left; /* # of unused bits in it */ int bits_left; /* # of unused bits in it */
} bitread_perm_state; } bitread_perm_state;
typedef struct { /* Bitreading working state within an MCU */ typedef struct { /* Bitreading working state within an MCU */
/* Current data source location */ /* Current data source location */
/* We need a copy, rather than munging the original, in case of suspension */ /* We need a copy, rather than munging the original, in case of suspension */
const JOCTET * next_input_byte; /* => next byte to read from source */ const JOCTET * next_input_byte; /* => next byte to read from source */
size_t bytes_in_buffer; /* # of bytes remaining in source buffer */ size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
/* Bit input buffer --- note these values are kept in register variables, /* Bit input buffer --- note these values are kept in register variables,
* not in this struct, inside the inner loops. * not in this struct, inside the inner loops.
*/ */
bit_buf_type get_buffer; /* current bit-extraction buffer */ bit_buf_type get_buffer; /* current bit-extraction buffer */
int bits_left; /* # of unused bits in it */ int bits_left; /* # of unused bits in it */
/* Pointer needed by jpeg_fill_bit_buffer. */ /* Pointer needed by jpeg_fill_bit_buffer. */
j_decompress_ptr cinfo; /* back link to decompress master record */ j_decompress_ptr cinfo; /* back link to decompress master record */
} bitread_working_state; } bitread_working_state;
/* Macros to declare and load/save bitread local variables. */ /* Macros to declare and load/save bitread local variables. */
#define BITREAD_STATE_VARS \ #define BITREAD_STATE_VARS \
register bit_buf_type get_buffer; \ register bit_buf_type get_buffer; \
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; \
permstate.bits_left = bits_left permstate.bits_left = bits_left
/* /*
* These macros provide the in-line portion of bit fetching. * These macros provide the in-line portion of bit fetching.
@@ -138,37 +130,37 @@ 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.
* val = PEEK_BITS(n); * val = PEEK_BITS(n);
* Fetch next N bits without removing them from the buffer. * Fetch next N bits without removing them from the buffer.
* DROP_BITS(n); * DROP_BITS(n);
* Discard next N bits. * Discard next N bits.
* The value N should be a simple variable, not an expression, because it * The value N should be a simple variable, not an expression, because it
* 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
JPP((bitread_working_state * state, register bit_buf_type get_buffer, (bitread_working_state * state, register bit_buf_type get_buffer,
register int bits_left, int nbits)); register int bits_left, int nbits);
/* /*
@@ -204,7 +196,7 @@ EXTERN(boolean) jpeg_fill_bit_buffer
} 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; \
} \ } \
} }
@@ -231,5 +223,5 @@ slowlabel: \
/* 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
JPP((bitread_working_state * state, register bit_buf_type get_buffer, (bitread_working_state * state, 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

@@ -24,14 +24,14 @@
typedef struct { typedef struct {
struct jpeg_input_controller pub; /* public fields */ struct jpeg_input_controller pub; /* public fields */
boolean inheaders; /* TRUE until first SOS is reached */ boolean inheaders; /* TRUE until first SOS is reached */
} my_input_controller; } my_input_controller;
typedef my_input_controller * my_inputctl_ptr; typedef my_input_controller * my_inputctl_ptr;
/* Forward declarations */ /* Forward declarations */
METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo)); METHODDEF(int) consume_markers (j_decompress_ptr cinfo);
/* /*
@@ -57,7 +57,7 @@ initial_setup (j_decompress_ptr cinfo)
/* Check that number of components won't exceed internal array sizes */ /* Check that number of components won't exceed internal array sizes */
if (cinfo->num_components > MAX_COMPONENTS) if (cinfo->num_components > MAX_COMPONENTS)
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
MAX_COMPONENTS); MAX_COMPONENTS);
/* Compute maximum sampling factors; check factor validity */ /* Compute maximum sampling factors; check factor validity */
cinfo->max_h_samp_factor = 1; cinfo->max_h_samp_factor = 1;
@@ -65,12 +65,12 @@ initial_setup (j_decompress_ptr cinfo)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
compptr->v_samp_factor<=0 || compptr->v_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);
cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
compptr->v_samp_factor); compptr->v_samp_factor);
} }
#if JPEG_LIB_VERSION >=80 #if JPEG_LIB_VERSION >=80
@@ -100,10 +100,10 @@ initial_setup (j_decompress_ptr cinfo)
/* 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));
/* downsampled_width and downsampled_height will also be overridden by /* downsampled_width and downsampled_height will also be overridden by
* jdmaster.c if we are doing full decompression. The transcoder library * jdmaster.c if we are doing full decompression. The transcoder library
* doesn't use these values, but the calling application might. * doesn't use these values, but the calling application might.
@@ -111,10 +111,10 @@ 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 */
@@ -124,7 +124,7 @@ 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)
@@ -173,15 +173,15 @@ per_scan_setup (j_decompress_ptr cinfo)
/* Interleaved (multi-component) scan */ /* Interleaved (multi-component) scan */
if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN) if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan, ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
MAX_COMPS_IN_SCAN); MAX_COMPS_IN_SCAN);
/* 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;
@@ -202,9 +202,9 @@ per_scan_setup (j_decompress_ptr cinfo)
/* Prepare array describing MCU composition */ /* Prepare array describing MCU composition */
mcublks = compptr->MCU_blocks; mcublks = compptr->MCU_blocks;
if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU) if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
ERREXIT(cinfo, JERR_BAD_MCU_SIZE); ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
while (mcublks-- > 0) { while (mcublks-- > 0) {
cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci; cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
} }
} }
@@ -248,13 +248,13 @@ latch_quant_tables (j_decompress_ptr cinfo)
/* Make sure specified quantization table is present */ /* Make sure specified quantization table is present */
qtblno = compptr->quant_tbl_no; qtblno = compptr->quant_tbl_no;
if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
cinfo->quant_tbl_ptrs[qtblno] == NULL) cinfo->quant_tbl_ptrs[qtblno] == NULL)
ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
/* OK, save away the quantization table */ /* OK, save away the quantization table */
qtbl = (JQUANT_TBL *) qtbl = (JQUANT_TBL *)
(*cinfo->mem->alloc_small) ((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;
} }
} }
@@ -313,31 +313,31 @@ consume_markers (j_decompress_ptr cinfo)
val = (*cinfo->marker->read_markers) (cinfo); val = (*cinfo->marker->read_markers) (cinfo);
switch (val) { switch (val) {
case JPEG_REACHED_SOS: /* Found SOS */ case JPEG_REACHED_SOS: /* Found SOS */
if (inputctl->inheaders) { /* 1st SOS */ if (inputctl->inheaders) { /* 1st SOS */
initial_setup(cinfo); initial_setup(cinfo);
inputctl->inheaders = FALSE; inputctl->inheaders = FALSE;
/* Note: start_input_pass must be called by jdmaster.c /* Note: start_input_pass must be called by jdmaster.c
* before any more input can be consumed. jdapimin.c is * before any more input can be consumed. jdapimin.c is
* 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);
} }
break; break;
case JPEG_REACHED_EOI: /* Found EOI */ case JPEG_REACHED_EOI: /* Found EOI */
inputctl->pub.eoi_reached = TRUE; inputctl->pub.eoi_reached = TRUE;
if (inputctl->inheaders) { /* Tables-only datastream, apparently */ if (inputctl->inheaders) { /* Tables-only datastream, apparently */
if (cinfo->marker->saw_SOF) if (cinfo->marker->saw_SOF)
ERREXIT(cinfo, JERR_SOF_NO_SOS); ERREXIT(cinfo, JERR_SOF_NO_SOS);
} else { } else {
/* Prevent infinite loop in coef ctlr's decompress_data routine /* Prevent infinite loop in coef ctlr's decompress_data routine
* if user set output_scan_number larger than number of scans. * if user set output_scan_number larger than number of scans.
*/ */
if (cinfo->output_scan_number > cinfo->input_scan_number) if (cinfo->output_scan_number > cinfo->input_scan_number)
cinfo->output_scan_number = cinfo->input_scan_number; cinfo->output_scan_number = cinfo->input_scan_number;
} }
break; break;
case JPEG_SUSPENDED: case JPEG_SUSPENDED:
@@ -382,7 +382,7 @@ jinit_input_controller (j_decompress_ptr cinfo)
/* 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;

View File

@@ -120,39 +120,39 @@ typedef struct {
/* Pointer to allocated workspace (M or M+2 row groups). */ /* Pointer to allocated workspace (M or M+2 row groups). */
JSAMPARRAY buffer[MAX_COMPONENTS]; JSAMPARRAY buffer[MAX_COMPONENTS];
boolean buffer_full; /* Have we gotten an iMCU row from decoder? */ boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */ JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
/* Remaining fields are only used in the context case. */ /* Remaining fields are only used in the context case. */
/* These are the master pointers to the funny-order pointer lists. */ /* These are the master pointers to the funny-order pointer lists. */
JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */ JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
int whichptr; /* indicates which pointer set is now in use */ int whichptr; /* indicates which pointer set is now in use */
int context_state; /* process_data state machine status */ int context_state; /* process_data state machine status */
JDIMENSION rowgroups_avail; /* row groups available to postprocessor */ JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */ JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
} my_main_controller; } my_main_controller;
typedef my_main_controller * my_main_ptr; typedef my_main_controller * my_main_ptr;
/* context_state values: */ /* context_state values: */
#define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */ #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
#define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */ #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
#define CTX_POSTPONED_ROW 2 /* feeding postponed row group */ #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
/* Forward declarations */ /* Forward declarations */
METHODDEF(void) process_data_simple_main METHODDEF(void) process_data_simple_main
JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, (j_decompress_ptr cinfo, JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
METHODDEF(void) process_data_context_main METHODDEF(void) process_data_context_main
JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, (j_decompress_ptr cinfo, JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); 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
JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, (j_decompress_ptr cinfo, JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
#endif #endif
@@ -173,7 +173,7 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
*/ */
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;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
@@ -185,8 +185,8 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
*/ */
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;
xbuf += rgroup * (M + 4); xbuf += rgroup * (M + 4);
main_ptr->xbuffer[1][ci] = xbuf; main_ptr->xbuffer[1][ci] = xbuf;
@@ -316,14 +316,14 @@ start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
if (cinfo->upsample->need_context_rows) { if (cinfo->upsample->need_context_rows) {
main_ptr->pub.process_data = process_data_context_main; main_ptr->pub.process_data = process_data_context_main;
make_funny_pointers(cinfo); /* Create the xbuffer[] lists */ make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
main_ptr->whichptr = 0; /* Read first iMCU row into xbuffer[0] */ main_ptr->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
main_ptr->context_state = CTX_PREPARE_FOR_IMCU; main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
main_ptr->iMCU_row_ctr = 0; main_ptr->iMCU_row_ctr = 0;
} else { } else {
/* Simple case with no context needed */ /* Simple case with no context needed */
main_ptr->pub.process_data = process_data_simple_main; main_ptr->pub.process_data = process_data_simple_main;
} }
main_ptr->buffer_full = FALSE; /* Mark buffer empty */ main_ptr->buffer_full = FALSE; /* Mark buffer empty */
main_ptr->rowgroup_ctr = 0; main_ptr->rowgroup_ctr = 0;
break; break;
#ifdef QUANT_2PASS_SUPPORTED #ifdef QUANT_2PASS_SUPPORTED
@@ -346,8 +346,8 @@ start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
METHODDEF(void) METHODDEF(void)
process_data_simple_main (j_decompress_ptr cinfo, process_data_simple_main (j_decompress_ptr cinfo,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, 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;
@@ -355,8 +355,8 @@ process_data_simple_main (j_decompress_ptr cinfo,
/* 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. */
@@ -368,8 +368,8 @@ process_data_simple_main (j_decompress_ptr cinfo,
/* Feed the postprocessor */ /* Feed the postprocessor */
(*cinfo->post->post_process_data) (cinfo, main_ptr->buffer, (*cinfo->post->post_process_data) (cinfo, main_ptr->buffer,
&main_ptr->rowgroup_ctr, rowgroups_avail, &main_ptr->rowgroup_ctr, rowgroups_avail,
output_buf, out_row_ctr, out_rows_avail); output_buf, out_row_ctr, out_rows_avail);
/* Has postprocessor consumed all the data yet? If so, mark buffer empty */ /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
if (main_ptr->rowgroup_ctr >= rowgroups_avail) { if (main_ptr->rowgroup_ctr >= rowgroups_avail) {
@@ -386,18 +386,18 @@ 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, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, 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 */
main_ptr->iMCU_row_ctr++; /* count rows received */ main_ptr->iMCU_row_ctr++; /* count rows received */
} }
/* Postprocessor typically will not swallow all the input data it is handed /* Postprocessor typically will not swallow all the input data it is handed
@@ -409,13 +409,13 @@ process_data_context_main (j_decompress_ptr cinfo,
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->xbuffer[main_ptr->whichptr],
&main_ptr->rowgroup_ctr, main_ptr->rowgroups_avail, &main_ptr->rowgroup_ctr, main_ptr->rowgroups_avail,
output_buf, out_row_ctr, out_rows_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;
if (*out_row_ctr >= out_rows_avail) if (*out_row_ctr >= out_rows_avail)
return; /* Postprocessor exactly filled output buf */ return; /* Postprocessor exactly filled output buf */
/*FALLTHROUGH*/ /*FALLTHROUGH*/
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 */
@@ -431,15 +431,15 @@ process_data_context_main (j_decompress_ptr cinfo,
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->xbuffer[main_ptr->whichptr],
&main_ptr->rowgroup_ctr, main_ptr->rowgroups_avail, &main_ptr->rowgroup_ctr, main_ptr->rowgroups_avail,
output_buf, out_row_ctr, out_rows_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 */
if (main_ptr->iMCU_row_ctr == 1) if (main_ptr->iMCU_row_ctr == 1)
set_wraparound_pointers(cinfo); set_wraparound_pointers(cinfo);
/* Prepare to load new iMCU row using other xbuffer list */ /* Prepare to load new iMCU row using other xbuffer list */
main_ptr->whichptr ^= 1; /* 0=>1 or 1=>0 */ main_ptr->whichptr ^= 1; /* 0=>1 or 1=>0 */
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 */
@@ -460,12 +460,12 @@ process_data_context_main (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
process_data_crank_post (j_decompress_ptr cinfo, process_data_crank_post (j_decompress_ptr cinfo,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, 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);
} }
#endif /* QUANT_2PASS_SUPPORTED */ #endif /* QUANT_2PASS_SUPPORTED */
@@ -484,11 +484,11 @@ jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
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 */
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
/* Allocate the workspace. /* Allocate the workspace.
@@ -508,8 +508,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

@@ -19,7 +19,7 @@
#include "jpeglib.h" #include "jpeglib.h"
typedef enum { /* JPEG marker codes */ typedef enum { /* JPEG marker codes */
M_SOF0 = 0xc0, M_SOF0 = 0xc0,
M_SOF1 = 0xc1, M_SOF1 = 0xc1,
M_SOF2 = 0xc2, M_SOF2 = 0xc2,
@@ -101,8 +101,8 @@ typedef struct {
unsigned int length_limit_APPn[16]; unsigned int length_limit_APPn[16];
/* Status of COM/APPn marker saving */ /* Status of COM/APPn marker saving */
jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */ jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
unsigned int bytes_read; /* data bytes read so far in marker */ unsigned int bytes_read; /* data bytes read so far in marker */
/* Note: cur_marker is not linked into marker_list until it's all read. */ /* Note: cur_marker is not linked into marker_list until it's all read. */
} my_marker_reader; } my_marker_reader;
@@ -119,49 +119,49 @@ typedef my_marker_reader * my_marker_ptr;
/* Declare and initialize local copies of input pointer/count */ /* Declare and initialize local copies of input pointer/count */
#define INPUT_VARS(cinfo) \ #define INPUT_VARS(cinfo) \
struct jpeg_source_mgr * datasrc = (cinfo)->src; \ struct jpeg_source_mgr * datasrc = (cinfo)->src; \
const JOCTET * next_input_byte = datasrc->next_input_byte; \ const JOCTET * next_input_byte = datasrc->next_input_byte; \
size_t bytes_in_buffer = datasrc->bytes_in_buffer size_t bytes_in_buffer = datasrc->bytes_in_buffer
/* Unload the local copies --- do this only at a restart boundary */ /* Unload the local copies --- do this only at a restart boundary */
#define INPUT_SYNC(cinfo) \ #define INPUT_SYNC(cinfo) \
( datasrc->next_input_byte = next_input_byte, \ ( datasrc->next_input_byte = next_input_byte, \
datasrc->bytes_in_buffer = bytes_in_buffer ) datasrc->bytes_in_buffer = bytes_in_buffer )
/* Reload the local copies --- used only in MAKE_BYTE_AVAIL */ /* Reload the local copies --- used only in MAKE_BYTE_AVAIL */
#define INPUT_RELOAD(cinfo) \ #define INPUT_RELOAD(cinfo) \
( next_input_byte = datasrc->next_input_byte, \ ( next_input_byte = datasrc->next_input_byte, \
bytes_in_buffer = datasrc->bytes_in_buffer ) bytes_in_buffer = datasrc->bytes_in_buffer )
/* Internal macro for INPUT_BYTE and INPUT_2BYTES: make a byte available. /* Internal macro for INPUT_BYTE and INPUT_2BYTES: make a byte available.
* 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); \
} }
/* 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 INT32. * V should be declared unsigned int or perhaps INT32.
*/ */
#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++); )
/* /*
@@ -257,8 +257,8 @@ 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)
ERREXIT(cinfo, JERR_SOF_DUPLICATE); ERREXIT(cinfo, JERR_SOF_DUPLICATE);
@@ -273,10 +273,10 @@ get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
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;
ci++, compptr++) { ci++, compptr++) {
@@ -288,8 +288,8 @@ get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE); INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT, TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
compptr->component_id, compptr->h_samp_factor, compptr->component_id, compptr->h_samp_factor,
compptr->v_samp_factor, compptr->quant_tbl_no); compptr->v_samp_factor, compptr->quant_tbl_no);
} }
cinfo->marker->saw_SOF = TRUE; cinfo->marker->saw_SOF = TRUE;
@@ -332,10 +332,10 @@ get_sos (j_decompress_ptr cinfo)
INPUT_BYTE(cinfo, c, return FALSE); INPUT_BYTE(cinfo, c, return FALSE);
for (ci = 0, compptr = cinfo->comp_info; for (ci = 0, compptr = cinfo->comp_info;
ci < cinfo->num_components && ci < MAX_COMPS_IN_SCAN; ci < cinfo->num_components && ci < MAX_COMPS_IN_SCAN;
ci++, compptr++) { ci++, compptr++) {
if (cc == compptr->component_id && !cinfo->cur_comp_info[ci]) if (cc == compptr->component_id && !cinfo->cur_comp_info[ci])
goto id_found; goto id_found;
} }
ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc); ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
@@ -347,7 +347,7 @@ get_sos (j_decompress_ptr cinfo)
compptr->ac_tbl_no = (c ) & 15; compptr->ac_tbl_no = (c ) & 15;
TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc, TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
compptr->dc_tbl_no, compptr->ac_tbl_no); compptr->dc_tbl_no, compptr->ac_tbl_no);
/* This CSi (cc) should differ from the previous CSi */ /* This CSi (cc) should differ from the previous CSi */
for (pi = 0; pi < i; pi++) { for (pi = 0; pi < i; pi++) {
@@ -367,7 +367,7 @@ get_sos (j_decompress_ptr cinfo)
cinfo->Al = (c ) & 15; cinfo->Al = (c ) & 15;
TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se, TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
cinfo->Ah, cinfo->Al); cinfo->Ah, cinfo->Al);
/* Prepare to scan data & restart markers */ /* Prepare to scan data & restart markers */
cinfo->marker->next_restart_num = 0; cinfo->marker->next_restart_num = 0;
@@ -406,11 +406,11 @@ get_dac (j_decompress_ptr cinfo)
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);
} }
} }
@@ -457,11 +457,11 @@ get_dht (j_decompress_ptr cinfo)
length -= 1 + 16; length -= 1 + 16;
TRACEMS8(cinfo, 2, JTRC_HUFFBITS, TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
bits[1], bits[2], bits[3], bits[4], bits[1], bits[2], bits[3], bits[4],
bits[5], bits[6], bits[7], bits[8]); bits[5], bits[6], bits[7], bits[8]);
TRACEMS8(cinfo, 2, JTRC_HUFFBITS, TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
bits[9], bits[10], bits[11], bits[12], bits[9], bits[10], bits[11], bits[12],
bits[13], bits[14], bits[15], bits[16]); bits[13], bits[14], bits[15], bits[16]);
/* 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.
@@ -472,16 +472,16 @@ get_dht (j_decompress_ptr cinfo)
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
INPUT_BYTE(cinfo, huffval[i], return FALSE); INPUT_BYTE(cinfo, huffval[i], return FALSE);
MEMZERO(&huffval[count], (256 - count) * SIZEOF(UINT8)); MEMZERO(&huffval[count], (256 - count) * sizeof(UINT8));
length -= count; length -= count;
if (index & 0x10) { /* AC table definition */ if (index & 0x10) { /* AC table definition */
index -= 0x10; index -= 0x10;
if (index < 0 || index >= NUM_HUFF_TBLS) if (index < 0 || index >= NUM_HUFF_TBLS)
ERREXIT1(cinfo, JERR_DHT_INDEX, index); ERREXIT1(cinfo, JERR_DHT_INDEX, index);
htblptr = &cinfo->ac_huff_tbl_ptrs[index]; htblptr = &cinfo->ac_huff_tbl_ptrs[index];
} else { /* DC table definition */ } else { /* DC table definition */
if (index < 0 || index >= NUM_HUFF_TBLS) if (index < 0 || index >= NUM_HUFF_TBLS)
ERREXIT1(cinfo, JERR_DHT_INDEX, index); ERREXIT1(cinfo, JERR_DHT_INDEX, index);
htblptr = &cinfo->dc_huff_tbl_ptrs[index]; htblptr = &cinfo->dc_huff_tbl_ptrs[index];
@@ -490,8 +490,8 @@ 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));
} }
if (length != 0) if (length != 0)
@@ -531,20 +531,20 @@ get_dqt (j_decompress_ptr cinfo)
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
if (prec) if (prec)
INPUT_2BYTES(cinfo, tmp, return FALSE); INPUT_2BYTES(cinfo, tmp, return FALSE);
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]);
} }
} }
@@ -591,14 +591,14 @@ get_dri (j_decompress_ptr cinfo)
* JFIF and Adobe markers, respectively. * JFIF and Adobe markers, respectively.
*/ */
#define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */ #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
#define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */ #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
#define APPN_DATA_LEN 14 /* Must be the largest of the above!! */ #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
LOCAL(void) LOCAL(void)
examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data, examine_app0 (j_decompress_ptr cinfo, JOCTET * data,
unsigned int datalen, INT32 remaining) unsigned int datalen, INT32 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.
@@ -627,18 +627,18 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
*/ */
if (cinfo->JFIF_major_version != 1) if (cinfo->JFIF_major_version != 1)
WARNMS2(cinfo, JWRN_JFIF_MAJOR, WARNMS2(cinfo, JWRN_JFIF_MAJOR,
cinfo->JFIF_major_version, cinfo->JFIF_minor_version); cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
/* Generate trace messages */ /* Generate trace messages */
TRACEMS5(cinfo, 1, JTRC_JFIF, TRACEMS5(cinfo, 1, JTRC_JFIF,
cinfo->JFIF_major_version, cinfo->JFIF_minor_version, cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
cinfo->X_density, cinfo->Y_density, cinfo->density_unit); cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
/* Validate thumbnail dimensions and issue appropriate messages */ /* Validate thumbnail dimensions and issue appropriate messages */
if (GETJOCTET(data[12]) | GETJOCTET(data[13])) if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL, TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
GETJOCTET(data[12]), GETJOCTET(data[13])); GETJOCTET(data[12]), GETJOCTET(data[13]));
totallen -= APP0_DATA_LEN; totallen -= APP0_DATA_LEN;
if (totallen != if (totallen !=
((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3)) ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 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 &&
@@ -662,7 +662,7 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
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 {
@@ -673,8 +673,8 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
LOCAL(void) LOCAL(void)
examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data, examine_app14 (j_decompress_ptr cinfo, JOCTET * data,
unsigned int datalen, INT32 remaining) unsigned int datalen, INT32 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.
@@ -729,10 +729,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 FAR *) b, numtoread, length); examine_app0(cinfo, (JOCTET *) b, numtoread, length);
break; break;
case M_APP14: case M_APP14:
examine_app14(cinfo, (JOCTET FAR *) 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 */
@@ -758,7 +758,7 @@ save_marker (j_decompress_ptr cinfo)
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 FAR * data; JOCTET * data;
INT32 length = 0; INT32 length = 0;
INPUT_VARS(cinfo); INPUT_VARS(cinfo);
@@ -766,25 +766,25 @@ save_marker (j_decompress_ptr cinfo)
/* begin reading a marker */ /* begin reading a marker */
INPUT_2BYTES(cinfo, length, return FALSE); INPUT_2BYTES(cinfo, length, return FALSE);
length -= 2; length -= 2;
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 FAR *) (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;
@@ -802,7 +802,7 @@ save_marker (j_decompress_ptr cinfo)
} }
while (bytes_read < data_length) { while (bytes_read < data_length) {
INPUT_SYNC(cinfo); /* move the restart point to here */ INPUT_SYNC(cinfo); /* move the restart point to here */
marker->bytes_read = bytes_read; marker->bytes_read = bytes_read;
/* If there's not at least one byte in buffer, suspend */ /* If there's not at least one byte in buffer, suspend */
MAKE_BYTE_AVAIL(cinfo, return FALSE); MAKE_BYTE_AVAIL(cinfo, return FALSE);
@@ -815,14 +815,14 @@ save_marker (j_decompress_ptr cinfo)
} }
/* Done reading what we want to read */ /* Done reading what we want to read */
if (cur_marker != NULL) { /* will be NULL if bogus length word */ if (cur_marker != NULL) { /* will be NULL if bogus length word */
/* Add new marker to end of list */ /* Add new marker to end of list */
if (cinfo->marker_list == NULL) { if (cinfo->marker_list == NULL) {
cinfo->marker_list = cur_marker; cinfo->marker_list = cur_marker;
} else { } else {
jpeg_saved_marker_ptr prev = cinfo->marker_list; jpeg_saved_marker_ptr prev = cinfo->marker_list;
while (prev->next != NULL) while (prev->next != NULL)
prev = prev->next; prev = prev->next;
prev->next = cur_marker; prev->next = cur_marker;
} }
/* Reset pointer & calc remaining data length */ /* Reset pointer & calc remaining data length */
@@ -842,12 +842,12 @@ 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);
@@ -869,7 +869,7 @@ skip_variable (j_decompress_ptr cinfo)
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);
@@ -913,7 +913,7 @@ next_marker (j_decompress_ptr cinfo)
INPUT_BYTE(cinfo, c, return FALSE); INPUT_BYTE(cinfo, c, return FALSE);
} while (c == 0xFF); } while (c == 0xFF);
if (c != 0) if (c != 0)
break; /* found a valid marker, exit loop */ break; /* found a valid marker, exit loop */
/* Reach here if we found a stuffed-zero data sequence (FF/00). /* Reach here if we found a stuffed-zero data sequence (FF/00).
* Discard it and loop back to try again. * Discard it and loop back to try again.
*/ */
@@ -973,11 +973,11 @@ read_markers (j_decompress_ptr cinfo)
/* 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;
} }
} }
/* At this point cinfo->unread_marker contains the marker code and the /* At this point cinfo->unread_marker contains the marker code and the
@@ -987,72 +987,72 @@ 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;
/* Currently unsupported SOFn types */ /* Currently unsupported SOFn types */
case M_SOF3: /* Lossless, Huffman */ case M_SOF3: /* Lossless, Huffman */
case M_SOF5: /* Differential sequential, Huffman */ case M_SOF5: /* Differential sequential, Huffman */
case M_SOF6: /* Differential progressive, Huffman */ case M_SOF6: /* Differential progressive, Huffman */
case M_SOF7: /* Differential lossless, Huffman */ case M_SOF7: /* Differential lossless, Huffman */
case M_JPG: /* Reserved for JPEG extensions */ case M_JPG: /* Reserved for JPEG extensions */
case M_SOF11: /* Lossless, arithmetic */ case M_SOF11: /* Lossless, arithmetic */
case M_SOF13: /* Differential sequential, arithmetic */ case M_SOF13: /* Differential sequential, arithmetic */
case M_SOF14: /* Differential progressive, arithmetic */ case M_SOF14: /* Differential progressive, arithmetic */
case M_SOF15: /* Differential lossless, arithmetic */ case M_SOF15: /* Differential lossless, arithmetic */
ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker); ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
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;
case M_EOI: case M_EOI:
TRACEMS(cinfo, 1, JTRC_EOI); TRACEMS(cinfo, 1, JTRC_EOI);
cinfo->unread_marker = 0; /* processed the marker */ cinfo->unread_marker = 0; /* processed the marker */
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;
case M_APP0: case M_APP0:
@@ -1072,16 +1072,16 @@ read_markers (j_decompress_ptr cinfo)
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;
case M_RST0: /* these are all parameterless */ case M_RST0: /* these are all parameterless */
case M_RST1: case M_RST1:
case M_RST2: case M_RST2:
case M_RST3: case M_RST3:
@@ -1093,12 +1093,12 @@ read_markers (j_decompress_ptr cinfo)
TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker); TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
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;
default: /* must be DHP, EXP, JPGn, or RESn */ default: /* must be DHP, EXP, JPGn, or RESn */
/* For now, we treat the reserved markers as fatal errors since they are /* For now, we treat the reserved markers as fatal errors since they are
* likely to be used to signal incompatible JPEG Part 3 extensions. * likely to be used to signal incompatible JPEG Part 3 extensions.
* Once the JPEG 3 version-number marker is well defined, this code * Once the JPEG 3 version-number marker is well defined, this code
@@ -1144,7 +1144,7 @@ read_restart_marker (j_decompress_ptr cinfo)
/* 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;
} }
@@ -1216,18 +1216,18 @@ 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 */
} }
TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action); TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
switch (action) { switch (action) {
@@ -1238,7 +1238,7 @@ jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
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;
case 3: case 3:
@@ -1259,10 +1259,10 @@ 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 */
cinfo->unread_marker = 0; /* no pending marker */ cinfo->unread_marker = 0; /* no pending marker */
marker->pub.saw_SOI = FALSE; /* set internal state too */ marker->pub.saw_SOI = FALSE; /* set internal state too */
marker->pub.saw_SOF = FALSE; marker->pub.saw_SOF = FALSE;
marker->pub.discarded_bytes = 0; marker->pub.discarded_bytes = 0;
marker->cur_marker = NULL; marker->cur_marker = NULL;
@@ -1283,7 +1283,7 @@ jinit_marker_reader (j_decompress_ptr cinfo)
/* 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;
@@ -1314,7 +1314,7 @@ jinit_marker_reader (j_decompress_ptr cinfo)
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;
@@ -1323,7 +1323,7 @@ jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
/* Length limit mustn't be larger than what we can allocate /* Length limit mustn't be larger than what we can allocate
* (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;
@@ -1363,7 +1363,7 @@ 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;

View File

@@ -6,6 +6,7 @@
* Modified 2002-2009 by Guido Vollbeding. * Modified 2002-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009-2011, D. R. Commander. * Copyright (C) 2009-2011, D. R. Commander.
* Copyright (C) 2013, Linaro Limited.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains master control logic for the JPEG decompressor. * This file contains master control logic for the JPEG decompressor.
@@ -25,7 +26,7 @@
typedef struct { typedef struct {
struct jpeg_decomp_master pub; /* public fields */ struct jpeg_decomp_master pub; /* public fields */
int pass_number; /* # of passes completed */ int pass_number; /* # of passes completed */
boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */ boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
@@ -51,9 +52,10 @@ use_merged_upsample (j_decompress_ptr cinfo)
/* Merging is the equivalent of plain box-filter upsampling */ /* Merging is the equivalent of plain box-filter upsampling */
if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling) if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
return FALSE; return FALSE;
/* jdmerge.c only supports YCC=>RGB color conversion */ /* jdmerge.c only supports YCC=>RGB and YCC=>RGB565 color conversion */
if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 || if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
(cinfo->out_color_space != JCS_RGB && (cinfo->out_color_space != JCS_RGB &&
cinfo->out_color_space != JCS_RGB565 &&
cinfo->out_color_space != JCS_EXT_RGB && cinfo->out_color_space != JCS_EXT_RGB &&
cinfo->out_color_space != JCS_EXT_RGBX && cinfo->out_color_space != JCS_EXT_RGBX &&
cinfo->out_color_space != JCS_EXT_BGR && cinfo->out_color_space != JCS_EXT_BGR &&
@@ -63,8 +65,12 @@ use_merged_upsample (j_decompress_ptr cinfo)
cinfo->out_color_space != JCS_EXT_RGBA && cinfo->out_color_space != JCS_EXT_RGBA &&
cinfo->out_color_space != JCS_EXT_BGRA && cinfo->out_color_space != JCS_EXT_BGRA &&
cinfo->out_color_space != JCS_EXT_ABGR && cinfo->out_color_space != JCS_EXT_ABGR &&
cinfo->out_color_space != JCS_EXT_ARGB) || cinfo->out_color_space != JCS_EXT_ARGB))
cinfo->out_color_components != rgb_pixelsize[cinfo->out_color_space]) return FALSE;
if ((cinfo->out_color_space == JCS_RGB565 &&
cinfo->out_color_components != 3) ||
(cinfo->out_color_space != JCS_RGB565 &&
cinfo->out_color_components != rgb_pixelsize[cinfo->out_color_space]))
return FALSE; return FALSE;
/* and it only handles 2h1v or 2h2v sampling ratios */ /* and it only handles 2h1v or 2h2v sampling ratios */
if (cinfo->comp_info[0].h_samp_factor != 2 || if (cinfo->comp_info[0].h_samp_factor != 2 ||
@@ -80,7 +86,7 @@ use_merged_upsample (j_decompress_ptr cinfo)
cinfo->comp_info[2]._DCT_scaled_size != cinfo->_min_DCT_scaled_size) cinfo->comp_info[2]._DCT_scaled_size != cinfo->_min_DCT_scaled_size)
return FALSE; return FALSE;
/* ??? also need to test for upsample-time rescaling, when & if supported */ /* ??? also need to test for upsample-time rescaling, when & if supported */
return TRUE; /* by golly, it'll work... */ return TRUE; /* by golly, it'll work... */
#else #else
return FALSE; return FALSE;
#endif #endif
@@ -292,10 +298,10 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
ci++, compptr++) { ci++, compptr++) {
int ssize = cinfo->_min_DCT_scaled_size; int ssize = cinfo->_min_DCT_scaled_size;
while (ssize < DCTSIZE && while (ssize < DCTSIZE &&
((cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) % ((cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) %
(compptr->h_samp_factor * ssize * 2) == 0) && (compptr->h_samp_factor * ssize * 2) == 0) &&
((cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size) % ((cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size) %
(compptr->v_samp_factor * ssize * 2) == 0)) { (compptr->v_samp_factor * ssize * 2) == 0)) {
ssize = ssize * 2; ssize = ssize * 2;
} }
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
@@ -313,12 +319,12 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
/* 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 */
@@ -352,18 +358,19 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space]; cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space];
break; break;
case JCS_YCbCr: case JCS_YCbCr:
case JCS_RGB565:
cinfo->out_color_components = 3; cinfo->out_color_components = 3;
break; break;
case JCS_CMYK: case JCS_CMYK:
case JCS_YCCK: case JCS_YCCK:
cinfo->out_color_components = 4; cinfo->out_color_components = 4;
break; break;
default: /* else must be same colorspace as in file */ default: /* else must be same colorspace as in file */
cinfo->out_color_components = cinfo->num_components; cinfo->out_color_components = cinfo->num_components;
break; break;
} }
cinfo->output_components = (cinfo->quantize_colors ? 1 : cinfo->output_components = (cinfo->quantize_colors ? 1 :
cinfo->out_color_components); cinfo->out_color_components);
/* See if upsampler will want to emit more than one row at a time */ /* See if upsampler will want to emit more than one row at a time */
if (use_merged_upsample(cinfo)) if (use_merged_upsample(cinfo))
@@ -380,10 +387,10 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
* processes are inner loops and need to be as fast as possible. On most * processes are inner loops and need to be as fast as possible. On most
* machines, particularly CPUs with pipelines or instruction prefetch, * machines, particularly CPUs with pipelines or instruction prefetch,
* a (subscript-check-less) C table lookup * a (subscript-check-less) C table lookup
* x = sample_range_limit[x]; * x = sample_range_limit[x];
* is faster than explicit tests * is faster than explicit tests
* if (x < 0) x = 0; * if (x < 0) x = 0;
* else if (x > MAXJSAMPLE) x = MAXJSAMPLE; * else if (x > MAXJSAMPLE) x = MAXJSAMPLE;
* These processes all use a common table prepared by the routine below. * These processes all use a common table prepared by the routine below.
* *
* For most steps we can mathematically guarantee that the initial value * For most steps we can mathematically guarantee that the initial value
@@ -393,7 +400,7 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
* possible if the input data is corrupt. To avoid any chance of indexing * possible if the input data is corrupt. To avoid any chance of indexing
* off the end of memory and getting a bad-pointer trap, we perform the * off the end of memory and getting a bad-pointer trap, we perform the
* post-IDCT limiting thus: * post-IDCT limiting thus:
* x = range_limit[x & MASK]; * x = range_limit[x & MASK];
* where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit * where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit
* samples. Under normal circumstances this is more than enough range and * samples. Under normal circumstances this is more than enough range and
* a correct output will be generated; with bogus input data the mask will * a correct output will be generated; with bogus input data the mask will
@@ -411,9 +418,6 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
* We can save some space by overlapping the start of the post-IDCT table * We can save some space by overlapping the start of the post-IDCT table
* with the simpler range limiting table. The post-IDCT table begins at * with the simpler range limiting table. The post-IDCT table begins at
* sample_range_limit + CENTERJSAMPLE. * sample_range_limit + CENTERJSAMPLE.
*
* Note that the table is allocated in near data space on PCs; it's small
* enough and used often enough to justify this.
*/ */
LOCAL(void) LOCAL(void)
@@ -425,23 +429,23 @@ prepare_range_limit_table (j_decompress_ptr cinfo)
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));
} }
@@ -629,24 +633,24 @@ prepare_for_output_pass (j_decompress_ptr cinfo)
if (cinfo->quantize_colors && cinfo->colormap == NULL) { if (cinfo->quantize_colors && cinfo->colormap == NULL) {
/* Select new quantization method */ /* Select new quantization method */
if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) { if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
cinfo->cquantize = master->quantizer_2pass; cinfo->cquantize = master->quantizer_2pass;
master->pub.is_dummy_pass = TRUE; master->pub.is_dummy_pass = TRUE;
} else if (cinfo->enable_1pass_quant) { } else if (cinfo->enable_1pass_quant) {
cinfo->cquantize = master->quantizer_1pass; cinfo->cquantize = master->quantizer_1pass;
} else { } else {
ERREXIT(cinfo, JERR_MODE_CHANGE); ERREXIT(cinfo, JERR_MODE_CHANGE);
} }
} }
(*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)
(*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass); (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
(*cinfo->post->start_pass) (cinfo, (*cinfo->post->start_pass) (cinfo,
(master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
(*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU); (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
} }
} }
@@ -655,7 +659,7 @@ prepare_for_output_pass (j_decompress_ptr cinfo)
if (cinfo->progress != NULL) { if (cinfo->progress != NULL) {
cinfo->progress->completed_passes = master->pass_number; cinfo->progress->completed_passes = master->pass_number;
cinfo->progress->total_passes = master->pass_number + cinfo->progress->total_passes = master->pass_number +
(master->pub.is_dummy_pass ? 2 : 1); (master->pub.is_dummy_pass ? 2 : 1);
/* 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.
*/ */
@@ -722,7 +726,7 @@ jinit_master_decompress (j_decompress_ptr cinfo)
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_decomp_master)); sizeof(my_decomp_master));
cinfo->master = (struct jpeg_decomp_master *) master; cinfo->master = (struct jpeg_decomp_master *) 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;

474
jdmerge.c
View File

@@ -6,6 +6,7 @@
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009, 2011, D. R. Commander. * Copyright (C) 2009, 2011, D. R. Commander.
* Copyright (C) 2013, Linaro Limited.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains code for merged upsampling/color conversion. * This file contains code for merged upsampling/color conversion.
@@ -17,19 +18,19 @@
* (ie, box filtering), we can save some work in color conversion by * (ie, box filtering), we can save some work in color conversion by
* calculating all the output pixels corresponding to a pair of chroma * calculating all the output pixels corresponding to a pair of chroma
* samples at one time. In the conversion equations * samples at one time. In the conversion equations
* R = Y + K1 * Cr * R = Y + K1 * Cr
* G = Y + K2 * Cb + K3 * Cr * G = Y + K2 * Cb + K3 * Cr
* B = Y + K4 * Cb * B = Y + K4 * Cb
* only the Y term varies among the group of pixels corresponding to a pair * only the Y term varies among the group of pixels corresponding to a pair
* of chroma samples, so the rest of the terms can be calculated just once. * of chroma samples, so the rest of the terms can be calculated just once.
* At typical sampling ratios, this eliminates half or three-quarters of the * At typical sampling ratios, this eliminates half or three-quarters of the
* multiplications needed for color conversion. * multiplications needed for color conversion.
* *
* This file currently provides implementations for the following cases: * This file currently provides implementations for the following cases:
* YCbCr => RGB color conversion only. * YCbCr => RGB color conversion only.
* Sampling ratios of 2h1v or 2h2v. * Sampling ratios of 2h1v or 2h2v.
* No scaling needed at upsample time. * No scaling needed at upsample time.
* Corner-aligned (non-CCIR601) sampling alignment. * Corner-aligned (non-CCIR601) sampling alignment.
* Other special cases could be added, but in most applications these are * Other special cases could be added, but in most applications these are
* the only common cases. (For uncommon cases we fall back on the more * the only common cases. (For uncommon cases we fall back on the more
* general code in jdsample.c and jdcolor.c.) * general code in jdsample.c and jdcolor.c.)
@@ -39,26 +40,57 @@
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jsimd.h" #include "jsimd.h"
#include "config.h" #include "jconfigint.h"
#ifdef UPSAMPLE_MERGING_SUPPORTED #ifdef UPSAMPLE_MERGING_SUPPORTED
#define PACK_SHORT_565(r, g, b) ((((r) << 8) & 0xf800) | \
(((g) << 3) & 0x7E0) | ((b) >> 3))
#define PACK_TWO_PIXELS(l, r) ((r << 16) | l)
#define PACK_NEED_ALIGNMENT(ptr) (((size_t)(ptr)) & 3)
#define WRITE_TWO_PIXELS(addr, pixels) { \
((INT16*)(addr))[0] = (pixels); \
((INT16*)(addr))[1] = (pixels) >> 16; \
}
#define WRITE_TWO_ALIGNED_PIXELS(addr, pixels) ((*(INT32 *)(addr)) = pixels)
#define DITHER_565_R(r, dither) ((r) + ((dither) & 0xFF))
#define DITHER_565_G(g, dither) ((g) + (((dither) & 0xFF) >> 1))
#define DITHER_565_B(b, dither) ((b) + ((dither) & 0xFF))
/* Declarations for ordered dithering
*
* We use a 4x4 ordered dither array packed into 32 bits. This array is
* sufficent for dithering RGB888 to RGB565.
*/
#define DITHER_MASK 0x3
#define DITHER_ROTATE(x) (((x) << 24) | (((x) >> 8) & 0x00FFFFFF))
static const INT32 dither_matrix[4] = {
0x0008020A,
0x0C040E06,
0x030B0109,
0x0F070D05
};
/* Private subobject */ /* Private subobject */
typedef struct { typedef struct {
struct jpeg_upsampler pub; /* public fields */ struct jpeg_upsampler pub; /* public fields */
/* Pointer to routine to do actual upsampling/conversion of one row group */ /* Pointer to routine to do actual upsampling/conversion of one row group */
JMETHOD(void, upmethod, (j_decompress_ptr cinfo, void (*upmethod) (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));
/* Private state for YCC->RGB conversion */ /* Private state for YCC->RGB conversion */
int * Cr_r_tab; /* => table for Cr to R conversion */ int * Cr_r_tab; /* => table for Cr to R conversion */
int * Cb_b_tab; /* => table for Cb to B conversion */ int * Cb_b_tab; /* => table for Cb to B conversion */
INT32 * Cr_g_tab; /* => table for Cr to G conversion */ INT32 * Cr_g_tab; /* => table for Cr to G conversion */
INT32 * Cb_g_tab; /* => table for Cb to G conversion */ INT32 * Cb_g_tab; /* => table for Cb to G conversion */
/* For 2:1 vertical sampling, we produce two output rows at a time. /* For 2:1 vertical sampling, we produce two output rows at a time.
* We need a "spare" row buffer to hold the second output row if the * We need a "spare" row buffer to hold the second output row if the
@@ -66,17 +98,17 @@ typedef struct {
* to discard the dummy last row if the image height is odd. * to discard the dummy last row if the image height is odd.
*/ */
JSAMPROW spare_row; JSAMPROW spare_row;
boolean spare_full; /* T if spare buffer is occupied */ boolean spare_full; /* T if spare buffer is occupied */
JDIMENSION out_row_width; /* samples per output row */ JDIMENSION out_row_width; /* samples per output row */
JDIMENSION rows_to_go; /* counts rows remaining in image */ JDIMENSION rows_to_go; /* counts rows remaining in image */
} my_upsampler; } my_upsampler;
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 ((INT32) 1 << (SCALEBITS-1)) #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
/* Include inline routines for colorspace extensions */ /* Include inline routines for colorspace extensions */
@@ -195,26 +227,26 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
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 = (INT32 *) upsample->Cr_g_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32)); (MAXJSAMPLE+1) * sizeof(INT32));
upsample->Cb_g_tab = (INT32 *) upsample->Cb_g_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32)); (MAXJSAMPLE+1) * sizeof(INT32));
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 */
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
/* Cr=>R value is nearest int to 1.40200 * x */ /* Cr=>R value is nearest int to 1.40200 * x */
upsample->Cr_r_tab[i] = (int) upsample->Cr_r_tab[i] = (int)
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
/* Cb=>B value is nearest int to 1.77200 * x */ /* Cb=>B value is nearest int to 1.77200 * x */
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 */
@@ -248,20 +280,23 @@ 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, JDIMENSION *in_row_group_ctr, JSAMPIMAGE input_buf, 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)
/* 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 */
if (upsample->spare_full) { if (upsample->spare_full) {
/* If we have a spare row saved from a previous cycle, just return it. */ /* If we have a spare row saved from a previous cycle, just return it. */
JDIMENSION size = upsample->out_row_width;
if (cinfo->out_color_space == JCS_RGB565)
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, upsample->out_row_width); 1, size);
num_rows = 1; num_rows = 1;
upsample->spare_full = FALSE; upsample->spare_full = FALSE;
} else { } else {
@@ -297,17 +332,17 @@ merged_2v_upsample (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
merged_1v_upsample (j_decompress_ptr cinfo, merged_1v_upsample (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JSAMPIMAGE input_buf, 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)
/* 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,
output_buf + *out_row_ctr); output_buf + *out_row_ctr);
/* Adjust counts */ /* Adjust counts */
(*out_row_ctr)++; (*out_row_ctr)++;
(*in_row_group_ctr)++; (*in_row_group_ctr)++;
@@ -330,8 +365,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, JDIMENSION in_row_group_ctr, JSAMPIMAGE input_buf, 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:
@@ -376,8 +411,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, JDIMENSION in_row_group_ctr, JSAMPIMAGE input_buf, 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:
@@ -416,6 +451,341 @@ h2v2_merged_upsample (j_decompress_ptr cinfo,
} }
METHODDEF(void)
h2v1_merged_upsample_565 (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
{
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
register int y, cred, cgreen, cblue;
int cb, cr;
register JSAMPROW outptr;
JSAMPROW inptr0, inptr1, inptr2;
JDIMENSION col;
/* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit;
int * Crrtab = upsample->Cr_r_tab;
int * Cbbtab = upsample->Cb_b_tab;
INT32 * Crgtab = upsample->Cr_g_tab;
INT32 * Cbgtab = upsample->Cb_g_tab;
unsigned int r, g, b;
INT32 rgb;
SHIFT_TEMPS
inptr0 = input_buf[0][in_row_group_ctr];
inptr1 = input_buf[1][in_row_group_ctr];
inptr2 = input_buf[2][in_row_group_ctr];
outptr = output_buf[0];
/* Loop for each pair of output pixels */
for (col = cinfo->output_width >> 1; col > 0; col--) {
/* Do the chroma part of the calculation */
cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb];
/* Fetch 2 Y values and emit 2 pixels */
y = GETJSAMPLE(*inptr0++);
r = range_limit[y + cred];
g = range_limit[y + cgreen];
b = range_limit[y + cblue];
rgb = PACK_SHORT_565(r, g, b);
y = GETJSAMPLE(*inptr0++);
r = range_limit[y + cred];
g = range_limit[y + cgreen];
b = range_limit[y + cblue];
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
WRITE_TWO_PIXELS(outptr, rgb);
outptr += 4;
}
/* If image width is odd, do the last output column separately */
if (cinfo->output_width & 1) {
cb = GETJSAMPLE(*inptr1);
cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb];
y = GETJSAMPLE(*inptr0);
r = range_limit[y + cred];
g = range_limit[y + cgreen];
b = range_limit[y + cblue];
rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = rgb;
}
}
METHODDEF(void)
h2v1_merged_upsample_565D (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
{
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
register int y, cred, cgreen, cblue;
int cb, cr;
register JSAMPROW outptr;
JSAMPROW inptr0, inptr1, inptr2;
JDIMENSION col;
/* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit;
int * Crrtab = upsample->Cr_r_tab;
int * Cbbtab = upsample->Cb_b_tab;
INT32 * Crgtab = upsample->Cr_g_tab;
INT32 * Cbgtab = upsample->Cb_g_tab;
INT32 d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
unsigned int r, g, b;
INT32 rgb;
SHIFT_TEMPS
inptr0 = input_buf[0][in_row_group_ctr];
inptr1 = input_buf[1][in_row_group_ctr];
inptr2 = input_buf[2][in_row_group_ctr];
outptr = output_buf[0];
/* Loop for each pair of output pixels */
for (col = cinfo->output_width >> 1; col > 0; col--) {
/* Do the chroma part of the calculation */
cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb];
/* Fetch 2 Y values and emit 2 pixels */
y = GETJSAMPLE(*inptr0++);
r = range_limit[DITHER_565_R(y + cred, d0)];
g = range_limit[DITHER_565_G(y + cgreen, d0)];
b = range_limit[DITHER_565_B(y + cblue, d0)];
d0 = DITHER_ROTATE(d0);
rgb = PACK_SHORT_565(r, g, b);
y = GETJSAMPLE(*inptr0++);
r = range_limit[DITHER_565_R(y + cred, d0)];
g = range_limit[DITHER_565_G(y + cgreen, d0)];
b = range_limit[DITHER_565_B(y + cblue, d0)];
d0 = DITHER_ROTATE(d0);
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
WRITE_TWO_PIXELS(outptr, rgb);
outptr += 4;
}
/* If image width is odd, do the last output column separately */
if (cinfo->output_width & 1) {
cb = GETJSAMPLE(*inptr1);
cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb];
y = GETJSAMPLE(*inptr0);
r = range_limit[DITHER_565_R(y + cred, d0)];
g = range_limit[DITHER_565_G(y + cgreen, d0)];
b = range_limit[DITHER_565_B(y + cblue, d0)];
rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr = rgb;
}
}
METHODDEF(void)
h2v2_merged_upsample_565 (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
{
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
register int y, cred, cgreen, cblue;
int cb, cr;
register JSAMPROW outptr0, outptr1;
JSAMPROW inptr00, inptr01, inptr1, inptr2;
JDIMENSION col;
/* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit;
int * Crrtab = upsample->Cr_r_tab;
int * Cbbtab = upsample->Cb_b_tab;
INT32 * Crgtab = upsample->Cr_g_tab;
INT32 * Cbgtab = upsample->Cb_g_tab;
unsigned int r, g, b;
INT32 rgb;
SHIFT_TEMPS
inptr00 = input_buf[0][in_row_group_ctr * 2];
inptr01 = input_buf[0][in_row_group_ctr * 2 + 1];
inptr1 = input_buf[1][in_row_group_ctr];
inptr2 = input_buf[2][in_row_group_ctr];
outptr0 = output_buf[0];
outptr1 = output_buf[1];
/* Loop for each group of output pixels */
for (col = cinfo->output_width >> 1; col > 0; col--) {
/* Do the chroma part of the calculation */
cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb];
/* Fetch 4 Y values and emit 4 pixels */
y = GETJSAMPLE(*inptr00++);
r = range_limit[y + cred];
g = range_limit[y + cgreen];
b = range_limit[y + cblue];
rgb = PACK_SHORT_565(r, g, b);
y = GETJSAMPLE(*inptr00++);
r = range_limit[y + cred];
g = range_limit[y + cgreen];
b = range_limit[y + cblue];
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
WRITE_TWO_PIXELS(outptr0, rgb);
outptr0 += 4;
y = GETJSAMPLE(*inptr01++);
r = range_limit[y + cred];
g = range_limit[y + cgreen];
b = range_limit[y + cblue];
rgb = PACK_SHORT_565(r, g, b);
y = GETJSAMPLE(*inptr01++);
r = range_limit[y + cred];
g = range_limit[y + cgreen];
b = range_limit[y + cblue];
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
WRITE_TWO_PIXELS(outptr1, rgb);
outptr1 += 4;
}
/* If image width is odd, do the last output column separately */
if (cinfo->output_width & 1) {
cb = GETJSAMPLE(*inptr1);
cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb];
y = GETJSAMPLE(*inptr00);
r = range_limit[y + cred];
g = range_limit[y + cgreen];
b = range_limit[y + cblue];
rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr0 = rgb;
y = GETJSAMPLE(*inptr01);
r = range_limit[y + cred];
g = range_limit[y + cgreen];
b = range_limit[y + cblue];
rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr1 = rgb;
}
}
METHODDEF(void)
h2v2_merged_upsample_565D (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
{
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
register int y, cred, cgreen, cblue;
int cb, cr;
register JSAMPROW outptr0, outptr1;
JSAMPROW inptr00, inptr01, inptr1, inptr2;
JDIMENSION col;
/* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit;
int * Crrtab = upsample->Cr_r_tab;
int * Cbbtab = upsample->Cb_b_tab;
INT32 * Crgtab = upsample->Cr_g_tab;
INT32 * Cbgtab = upsample->Cb_g_tab;
INT32 d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
INT32 d1 = dither_matrix[(cinfo->output_scanline+1) & DITHER_MASK];
unsigned int r, g, b;
INT32 rgb;
SHIFT_TEMPS
inptr00 = input_buf[0][in_row_group_ctr*2];
inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
inptr1 = input_buf[1][in_row_group_ctr];
inptr2 = input_buf[2][in_row_group_ctr];
outptr0 = output_buf[0];
outptr1 = output_buf[1];
/* Loop for each group of output pixels */
for (col = cinfo->output_width >> 1; col > 0; col--) {
/* Do the chroma part of the calculation */
cb = GETJSAMPLE(*inptr1++);
cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb];
/* Fetch 4 Y values and emit 4 pixels */
y = GETJSAMPLE(*inptr00++);
r = range_limit[DITHER_565_R(y + cred, d0)];
g = range_limit[DITHER_565_G(y + cgreen, d0)];
b = range_limit[DITHER_565_B(y + cblue, d0)];
d0 = DITHER_ROTATE(d0);
rgb = PACK_SHORT_565(r, g, b);
y = GETJSAMPLE(*inptr00++);
r = range_limit[DITHER_565_R(y + cred, d1)];
g = range_limit[DITHER_565_G(y + cgreen, d1)];
b = range_limit[DITHER_565_B(y + cblue, d1)];
d1 = DITHER_ROTATE(d1);
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
WRITE_TWO_PIXELS(outptr0, rgb);
outptr0 += 4;
y = GETJSAMPLE(*inptr01++);
r = range_limit[DITHER_565_R(y + cred, d0)];
g = range_limit[DITHER_565_G(y + cgreen, d0)];
b = range_limit[DITHER_565_B(y + cblue, d0)];
d0 = DITHER_ROTATE(d0);
rgb = PACK_SHORT_565(r, g, b);
y = GETJSAMPLE(*inptr01++);
r = range_limit[DITHER_565_R(y + cred, d1)];
g = range_limit[DITHER_565_G(y + cgreen, d1)];
b = range_limit[DITHER_565_B(y + cblue, d1)];
d1 = DITHER_ROTATE(d1);
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
WRITE_TWO_PIXELS(outptr1, rgb);
outptr1 += 4;
}
/* If image width is odd, do the last output column separately */
if (cinfo->output_width & 1) {
cb = GETJSAMPLE(*inptr1);
cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr];
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb];
y = GETJSAMPLE(*inptr00);
r = range_limit[DITHER_565_R(y + cred, d0)];
g = range_limit[DITHER_565_G(y + cgreen, d0)];
b = range_limit[DITHER_565_B(y + cblue, d0)];
rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr0 = rgb;
y = GETJSAMPLE(*inptr01);
r = range_limit[DITHER_565_R(y + cred, d1)];
g = range_limit[DITHER_565_G(y + cgreen, d1)];
b = range_limit[DITHER_565_B(y + cblue, d1)];
rgb = PACK_SHORT_565(r, g, b);
*(INT16*)outptr1 = rgb;
}
}
/* /*
* Module initialization routine for merged upsampling/color conversion. * Module initialization routine for merged upsampling/color conversion.
* *
@@ -431,7 +801,7 @@ jinit_merged_upsampler (j_decompress_ptr cinfo)
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;
@@ -444,16 +814,30 @@ jinit_merged_upsampler (j_decompress_ptr cinfo)
upsample->upmethod = jsimd_h2v2_merged_upsample; upsample->upmethod = jsimd_h2v2_merged_upsample;
else else
upsample->upmethod = h2v2_merged_upsample; upsample->upmethod = h2v2_merged_upsample;
if (cinfo->out_color_space == JCS_RGB565) {
if (cinfo->dither_mode != JDITHER_NONE) {
upsample->upmethod = h2v2_merged_upsample_565D;
} else {
upsample->upmethod = h2v2_merged_upsample_565;
}
}
/* 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())
upsample->upmethod = jsimd_h2v1_merged_upsample; upsample->upmethod = jsimd_h2v1_merged_upsample;
else else
upsample->upmethod = h2v1_merged_upsample; upsample->upmethod = h2v1_merged_upsample;
if (cinfo->out_color_space == JCS_RGB565) {
if (cinfo->dither_mode != JDITHER_NONE) {
upsample->upmethod = h2v1_merged_upsample_565D;
} else {
upsample->upmethod = h2v1_merged_upsample_565;
}
}
/* No spare row needed */ /* No spare row needed */
upsample->spare_row = NULL; upsample->spare_row = NULL;
} }

266
jdphuff.c
View File

@@ -1,8 +1,10 @@
/* /*
* jdphuff.c * jdphuff.c
* *
* 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.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains Huffman entropy decoding routines for progressive JPEG. * This file contains Huffman entropy decoding routines for progressive JPEG.
@@ -17,7 +19,7 @@
#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 */
#ifdef D_PROGRESSIVE_SUPPORTED #ifdef D_PROGRESSIVE_SUPPORTED
@@ -30,8 +32,8 @@
*/ */
typedef struct { typedef struct {
unsigned int EOBRUN; /* remaining EOBs in EOBRUN */ unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
} savable_state; } savable_state;
/* This macro is to work around compilers with missing or broken /* This macro is to work around compilers with missing or broken
@@ -44,11 +46,11 @@ typedef struct {
#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], \
(dest).last_dc_val[2] = (src).last_dc_val[2], \ (dest).last_dc_val[2] = (src).last_dc_val[2], \
(dest).last_dc_val[3] = (src).last_dc_val[3]) (dest).last_dc_val[3] = (src).last_dc_val[3])
#endif #endif
#endif #endif
@@ -59,11 +61,11 @@ typedef struct {
/* These fields are loaded into local variables at start of each MCU. /* These fields are loaded into local variables at start of each MCU.
* In case of suspension, we exit WITHOUT updating them. * In case of suspension, we exit WITHOUT updating them.
*/ */
bitread_perm_state bitstate; /* Bit buffer at start of MCU */ bitread_perm_state bitstate; /* Bit buffer at start of MCU */
savable_state saved; /* Other state at start of MCU */ savable_state saved; /* Other state at start of MCU */
/* These fields are NOT loaded into local working state. */ /* These fields are NOT loaded into local working state. */
unsigned int restarts_to_go; /* MCUs left in this restart interval */ unsigned int restarts_to_go; /* MCUs left in this restart interval */
/* Pointers to derived tables (these workspaces have image lifespan) */ /* Pointers to derived tables (these workspaces have image lifespan) */
d_derived_tbl * derived_tbls[NUM_HUFF_TBLS]; d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
@@ -74,14 +76,14 @@ 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 JPP((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 JPP((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 JPP((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 JPP((j_decompress_ptr cinfo, METHODDEF(boolean) decode_mcu_AC_refine (j_decompress_ptr cinfo,
JBLOCKROW *MCU_data)); JBLOCKROW *MCU_data);
/* /*
@@ -117,7 +119,7 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo)
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 */
bad = TRUE; bad = TRUE;
/* Arguably the maximum Al value should be less than 13 for 8-bit precision, /* Arguably the maximum Al value should be less than 13 for 8-bit precision,
* but the spec doesn't say so, and we try to be liberal about what we * but the spec doesn't say so, and we try to be liberal about what we
@@ -127,7 +129,7 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo)
*/ */
if (bad) if (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);
/* Update progression status, and verify that scan order is legal. /* Update progression status, and verify that scan order is legal.
* Note that inter-scan inconsistencies are treated as warnings * Note that inter-scan inconsistencies are treated as warnings
* not fatal errors ... not clear if this is right way to behave. * not fatal errors ... not clear if this is right way to behave.
@@ -140,7 +142,7 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo)
for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) { for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi]; int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
if (cinfo->Ah != expected) if (cinfo->Ah != expected)
WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi); WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
coef_bit_ptr[coefi] = cinfo->Al; coef_bit_ptr[coefi] = cinfo->Al;
} }
} }
@@ -164,15 +166,15 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo)
* We may build same derived table more than once, but it's not expensive. * We may build same derived table more than once, but it's not expensive.
*/ */
if (is_DC_band) { if (is_DC_band) {
if (cinfo->Ah == 0) { /* DC refinement needs no table */ if (cinfo->Ah == 0) { /* DC refinement needs no table */
tbl = compptr->dc_tbl_no; tbl = compptr->dc_tbl_no;
jpeg_make_d_derived_tbl(cinfo, TRUE, tbl, jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
& entropy->derived_tbls[tbl]); & entropy->derived_tbls[tbl]);
} }
} else { } else {
tbl = compptr->ac_tbl_no; tbl = compptr->ac_tbl_no;
jpeg_make_d_derived_tbl(cinfo, FALSE, tbl, jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
& entropy->derived_tbls[tbl]); & entropy->derived_tbls[tbl]);
/* remember the single active table */ /* remember the single active table */
entropy->ac_derived_tbl = entropy->derived_tbls[tbl]; entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
} }
@@ -300,7 +302,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
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.
@@ -325,9 +327,9 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Section F.2.2.1: decode the DC coefficient difference */ /* Section F.2.2.1: decode the DC coefficient difference */
HUFF_DECODE(s, br_state, tbl, return FALSE, label1); HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
if (s) { if (s) {
CHECK_BIT_BUFFER(br_state, s, return FALSE); CHECK_BIT_BUFFER(br_state, s, return FALSE);
r = GET_BITS(s); r = GET_BITS(s);
s = HUFF_EXTEND(r, s); s = HUFF_EXTEND(r, s);
} }
/* Convert DC difference to actual value, update last_dc_val */ /* Convert DC difference to actual value, update last_dc_val */
@@ -370,7 +372,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
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.
@@ -381,49 +383,49 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_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.
*/ */
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 */
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;
for (k = cinfo->Ss; k <= Se; k++) { for (k = cinfo->Ss; k <= Se; k++) {
HUFF_DECODE(s, br_state, tbl, return FALSE, label2); HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
r = s >> 4; r = s >> 4;
s &= 15; s &= 15;
if (s) { if (s) {
k += r; k += r;
CHECK_BIT_BUFFER(br_state, s, return FALSE); CHECK_BIT_BUFFER(br_state, s, return FALSE);
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) (s << Al); (*block)[jpeg_natural_order[k]] = (JCOEF) (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 */
} else { /* EOBr, run length is 2^r + appended bits */ } else { /* EOBr, run length is 2^r + appended bits */
EOBRUN = 1 << r; EOBRUN = 1 << r;
if (r) { /* EOBr, r > 0 */ if (r) { /* EOBr, r > 0 */
CHECK_BIT_BUFFER(br_state, r, return FALSE); CHECK_BIT_BUFFER(br_state, r, return FALSE);
r = GET_BITS(r); r = GET_BITS(r);
EOBRUN += r; EOBRUN += r;
} }
EOBRUN--; /* this band is processed at this moment */ EOBRUN--; /* this band is processed at this moment */
break; /* force end-of-band */ break; /* force end-of-band */
} }
} }
} }
BITREAD_SAVE_STATE(cinfo,entropy->bitstate); BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
} }
/* Completed MCU, so update state */ /* Completed MCU, so update state */
entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */ entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
} }
/* Account for restart interval (no-op if not using restarts) */ /* Account for restart interval (no-op if not using restarts) */
@@ -443,7 +445,7 @@ 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;
BITREAD_STATE_VARS; BITREAD_STATE_VARS;
@@ -452,7 +454,7 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
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;
} }
/* Not worth the cycles to check insufficient_data here, /* Not worth the cycles to check insufficient_data here,
@@ -493,8 +495,8 @@ 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 = (-1) << cinfo->Al; /* -1 in the bit position being coded */ int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
register int s, k, r; register int s, k, r;
unsigned int EOBRUN; unsigned int EOBRUN;
JBLOCKROW block; JBLOCKROW block;
@@ -508,7 +510,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
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.
@@ -536,58 +538,58 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (EOBRUN == 0) { if (EOBRUN == 0) {
for (; k <= Se; k++) { for (; k <= Se; k++) {
HUFF_DECODE(s, br_state, tbl, goto undoit, label3); HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
r = s >> 4; r = s >> 4;
s &= 15; s &= 15;
if (s) { if (s) {
if (s != 1) /* size of new coef should always be 1 */ if (s != 1) /* size of new coef should always be 1 */
WARNMS(cinfo, JWRN_HUFF_BAD_CODE); WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
CHECK_BIT_BUFFER(br_state, 1, goto undoit); CHECK_BIT_BUFFER(br_state, 1, goto undoit);
if (GET_BITS(1)) if (GET_BITS(1))
s = p1; /* newly nonzero coef is positive */ s = p1; /* newly nonzero coef is positive */
else else
s = m1; /* newly nonzero coef is negative */ s = m1; /* newly nonzero coef is negative */
} else { } else {
if (r != 15) { if (r != 15) {
EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */ EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
if (r) { if (r) {
CHECK_BIT_BUFFER(br_state, r, goto undoit); CHECK_BIT_BUFFER(br_state, r, goto undoit);
r = GET_BITS(r); r = GET_BITS(r);
EOBRUN += r; EOBRUN += r;
} }
break; /* rest of block is handled by EOB logic */ break; /* rest of block is handled by EOB logic */
} }
/* note s = 0 for processing ZRL */ /* note s = 0 for processing ZRL */
} }
/* Advance over already-nonzero coefs and r still-zero coefs, /* Advance over already-nonzero coefs and r still-zero coefs,
* appending correction bits to the nonzeroes. A correction bit is 1 * appending correction bits to the nonzeroes. A correction bit is 1
* if the absolute value of the coefficient must be increased. * if the absolute value of the coefficient must be increased.
*/ */
do { do {
thiscoef = *block + jpeg_natural_order[k]; thiscoef = *block + jpeg_natural_order[k];
if (*thiscoef != 0) { if (*thiscoef != 0) {
CHECK_BIT_BUFFER(br_state, 1, goto undoit); CHECK_BIT_BUFFER(br_state, 1, goto undoit);
if (GET_BITS(1)) { if (GET_BITS(1)) {
if ((*thiscoef & p1) == 0) { /* do nothing if already set it */ if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
if (*thiscoef >= 0) if (*thiscoef >= 0)
*thiscoef += p1; *thiscoef += p1;
else else
*thiscoef += m1; *thiscoef += m1;
} }
} }
} else { } else {
if (--r < 0) if (--r < 0)
break; /* reached target zero coefficient */ break; /* reached target zero coefficient */
} }
k++; k++;
} while (k <= Se); } while (k <= Se);
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;
} }
} }
} }
@@ -598,18 +600,18 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
* if the absolute value of the coefficient must be increased. * if the absolute value of the coefficient must be increased.
*/ */
for (; k <= Se; k++) { for (; k <= Se; k++) {
thiscoef = *block + jpeg_natural_order[k]; thiscoef = *block + jpeg_natural_order[k];
if (*thiscoef != 0) { if (*thiscoef != 0) {
CHECK_BIT_BUFFER(br_state, 1, goto undoit); CHECK_BIT_BUFFER(br_state, 1, goto undoit);
if (GET_BITS(1)) { if (GET_BITS(1)) {
if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */ if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
if (*thiscoef >= 0) if (*thiscoef >= 0)
*thiscoef += p1; *thiscoef += p1;
else else
*thiscoef += m1; *thiscoef += m1;
} }
} }
} }
} }
/* Count one block completed in EOB run */ /* Count one block completed in EOB run */
EOBRUN--; EOBRUN--;
@@ -647,7 +649,7 @@ jinit_phuff_decoder (j_decompress_ptr cinfo)
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;
@@ -659,7 +661,7 @@ 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*sizeof(int));
coef_bit_ptr = & cinfo->coef_bits[0][0]; 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++)

View File

@@ -1,8 +1,10 @@
/* /*
* jdpostct.c * jdpostct.c
* *
* 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.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains the decompression postprocessing controller. * This file contains the decompression postprocessing controller.
@@ -31,12 +33,12 @@ typedef struct {
* For two-pass color quantization, we need a full-image buffer; * For two-pass color quantization, we need a full-image buffer;
* for one-pass operation, a strip buffer is sufficient. * for one-pass operation, a strip buffer is sufficient.
*/ */
jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */ jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */ JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
JDIMENSION strip_height; /* buffer size in rows */ JDIMENSION strip_height; /* buffer size in rows */
/* for two-pass mode only: */ /* for two-pass mode only: */
JDIMENSION starting_row; /* row # of first row in current strip */ JDIMENSION starting_row; /* row # of first row in current strip */
JDIMENSION next_row; /* index of next row to fill/empty in strip */ JDIMENSION next_row; /* index of next row to fill/empty in strip */
} my_post_controller; } my_post_controller;
typedef my_post_controller * my_post_ptr; typedef my_post_controller * my_post_ptr;
@@ -44,24 +46,21 @@ typedef my_post_controller * my_post_ptr;
/* Forward declarations */ /* Forward declarations */
METHODDEF(void) post_process_1pass METHODDEF(void) post_process_1pass
JPP((j_decompress_ptr cinfo, (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));
#ifdef QUANT_2PASS_SUPPORTED #ifdef QUANT_2PASS_SUPPORTED
METHODDEF(void) post_process_prepass METHODDEF(void) post_process_prepass
JPP((j_decompress_ptr cinfo, (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));
METHODDEF(void) post_process_2pass METHODDEF(void) post_process_2pass
JPP((j_decompress_ptr cinfo, (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));
#endif #endif
@@ -84,9 +83,9 @@ start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
* allocate a strip buffer. Use the virtual-array buffer as workspace. * allocate a strip buffer. Use the virtual-array buffer as workspace.
*/ */
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,
@@ -124,10 +123,10 @@ 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, JDIMENSION *in_row_group_ctr, JSAMPIMAGE input_buf, 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_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;
@@ -139,11 +138,11 @@ post_process_1pass (j_decompress_ptr cinfo,
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, in_row_groups_avail, input_buf, in_row_group_ctr, in_row_groups_avail,
post->buffer, &num_rows, max_rows); post->buffer, &num_rows, max_rows);
/* Quantize and emit data. */ /* Quantize and emit data. */
(*cinfo->cquantize->color_quantize) (cinfo, (*cinfo->cquantize->color_quantize) (cinfo,
post->buffer, output_buf + *out_row_ctr, (int) num_rows); post->buffer, output_buf + *out_row_ctr, (int) num_rows);
*out_row_ctr += num_rows; *out_row_ctr += num_rows;
} }
@@ -156,10 +155,10 @@ 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, JDIMENSION *in_row_group_ctr, JSAMPIMAGE input_buf, 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_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;
@@ -167,22 +166,22 @@ post_process_prepass (j_decompress_ptr cinfo,
/* 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, in_row_groups_avail, input_buf, in_row_group_ctr, in_row_groups_avail,
post->buffer, &post->next_row, post->strip_height); post->buffer, &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;
} }
@@ -200,10 +199,10 @@ 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, JDIMENSION *in_row_group_ctr, JSAMPIMAGE input_buf, 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_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;
@@ -211,8 +210,8 @@ post_process_2pass (j_decompress_ptr cinfo,
/* 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);
} }
/* Determine number of rows to emit. */ /* Determine number of rows to emit. */
@@ -227,8 +226,8 @@ post_process_2pass (j_decompress_ptr cinfo,
/* Quantize and emit data. */ /* Quantize and emit data. */
(*cinfo->cquantize->color_quantize) (cinfo, (*cinfo->cquantize->color_quantize) (cinfo,
post->buffer + post->next_row, output_buf + *out_row_ctr, post->buffer + post->next_row, 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. */
@@ -253,11 +252,11 @@ jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
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 */
/* Create the quantization buffer, if needed */ /* Create the quantization buffer, if needed */
if (cinfo->quantize_colors) { if (cinfo->quantize_colors) {
@@ -271,20 +270,20 @@ jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
/* 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);
#endif /* QUANT_2PASS_SUPPORTED */ #endif /* QUANT_2PASS_SUPPORTED */
} 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

@@ -6,6 +6,7 @@
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2010, D. R. Commander. * Copyright (C) 2010, D. R. Commander.
* Copyright (C) 2014, MIPS Technologies, Inc., California
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains upsampling routines. * This file contains upsampling routines.
@@ -29,14 +30,15 @@
/* Pointer to routine to upsample a single component */ /* Pointer to routine to upsample a single component */
typedef JMETHOD(void, upsample1_ptr, typedef void (*upsample1_ptr) (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,
JSAMPARRAY * output_data_ptr);
/* Private subobject */ /* Private subobject */
typedef struct { typedef struct {
struct jpeg_upsampler pub; /* public fields */ struct jpeg_upsampler pub; /* public fields */
/* Color conversion buffer. When using separate upsampling and color /* Color conversion buffer. When using separate upsampling and color
* conversion steps, this buffer holds one upsampled row group until it * conversion steps, this buffer holds one upsampled row group until it
@@ -50,8 +52,8 @@ typedef struct {
/* Per-component upsampling method pointers */ /* Per-component upsampling method pointers */
upsample1_ptr methods[MAX_COMPONENTS]; upsample1_ptr methods[MAX_COMPONENTS];
int next_row_out; /* counts rows emitted from color_buf */ int next_row_out; /* counts rows emitted from color_buf */
JDIMENSION rows_to_go; /* counts rows remaining in image */ JDIMENSION rows_to_go; /* counts rows remaining in image */
/* Height of an input row group for each component. */ /* Height of an input row group for each component. */
int rowgroup_height[MAX_COMPONENTS]; int rowgroup_height[MAX_COMPONENTS];
@@ -92,10 +94,10 @@ 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, JDIMENSION *in_row_group_ctr, JSAMPIMAGE input_buf, 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;
@@ -105,13 +107,13 @@ sep_upsample (j_decompress_ptr cinfo,
/* Fill the conversion buffer, if it's empty */ /* Fill the conversion buffer, if it's empty */
if (upsample->next_row_out >= cinfo->max_v_samp_factor) { if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
/* Invoke per-component upsample method. Notice we pass a POINTER /* Invoke per-component upsample method. Notice we pass a POINTER
* to color_buf[ci], so that fullsize_upsample can change it. * to color_buf[ci], so that fullsize_upsample can change it.
*/ */
(*upsample->methods[ci]) (cinfo, compptr, (*upsample->methods[ci]) (cinfo, compptr,
input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]), input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
upsample->color_buf + ci); upsample->color_buf + ci);
} }
upsample->next_row_out = 0; upsample->next_row_out = 0;
} }
@@ -131,9 +133,9 @@ 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;
@@ -160,7 +162,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;
} }
@@ -173,9 +175,9 @@ 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 */
} }
@@ -192,7 +194,7 @@ 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;
@@ -213,15 +215,15 @@ int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
outptr = output_data[outrow]; outptr = output_data[outrow];
outend = outptr + cinfo->output_width; outend = outptr + cinfo->output_width;
while (outptr < outend) { while (outptr < outend) {
invalue = *inptr++; /* don't need GETJSAMPLE() here */ invalue = *inptr++; /* don't need GETJSAMPLE() here */
for (h = h_expand; h > 0; h--) { for (h = h_expand; h > 0; h--) {
*outptr++ = invalue; *outptr++ = invalue;
} }
} }
/* 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;
@@ -236,7 +238,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;
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
@@ -249,7 +251,7 @@ h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
outptr = output_data[inrow]; outptr = output_data[inrow];
outend = outptr + cinfo->output_width; outend = outptr + cinfo->output_width;
while (outptr < outend) { while (outptr < outend) {
invalue = *inptr++; /* don't need GETJSAMPLE() here */ invalue = *inptr++; /* don't need GETJSAMPLE() here */
*outptr++ = invalue; *outptr++ = invalue;
*outptr++ = invalue; *outptr++ = invalue;
} }
@@ -264,7 +266,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;
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
@@ -278,12 +280,12 @@ h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
outptr = output_data[outrow]; outptr = output_data[outrow];
outend = outptr + cinfo->output_width; outend = outptr + cinfo->output_width;
while (outptr < outend) { while (outptr < outend) {
invalue = *inptr++; /* don't need GETJSAMPLE() here */ invalue = *inptr++; /* don't need GETJSAMPLE() here */
*outptr++ = invalue; *outptr++ = invalue;
*outptr++ = invalue; *outptr++ = invalue;
} }
jcopy_sample_rows(output_data, outrow, output_data, outrow+1, jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
1, cinfo->output_width); 1, cinfo->output_width);
inrow++; inrow++;
outrow += 2; outrow += 2;
} }
@@ -307,7 +309,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;
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
@@ -348,7 +350,7 @@ h2v1_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;
register JSAMPROW inptr0, inptr1, outptr; register JSAMPROW inptr0, inptr1, outptr;
@@ -365,10 +367,10 @@ h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
for (v = 0; v < 2; v++) { for (v = 0; v < 2; v++) {
/* 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 */
@@ -379,12 +381,12 @@ h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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 */
@@ -411,13 +413,13 @@ jinit_upsampler (j_decompress_ptr cinfo)
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 */
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);
/* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
@@ -434,9 +436,9 @@ jinit_upsampler (j_decompress_ptr cinfo)
* are to be converted to max_h_samp_factor * max_v_samp_factor pixels. * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
*/ */
h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) / h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
cinfo->_min_DCT_scaled_size; cinfo->_min_DCT_scaled_size;
v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
cinfo->_min_DCT_scaled_size; cinfo->_min_DCT_scaled_size;
h_out_group = cinfo->max_h_samp_factor; h_out_group = cinfo->max_h_samp_factor;
v_out_group = cinfo->max_v_samp_factor; v_out_group = cinfo->max_v_samp_factor;
upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
@@ -450,48 +452,53 @@ jinit_upsampler (j_decompress_ptr cinfo)
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())
upsample->methods[ci] = jsimd_h2v1_fancy_upsample; upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
else else
upsample->methods[ci] = h2v1_fancy_upsample; upsample->methods[ci] = h2v1_fancy_upsample;
} else { } else {
if (jsimd_can_h2v1_upsample()) if (jsimd_can_h2v1_upsample())
upsample->methods[ci] = jsimd_h2v1_upsample; upsample->methods[ci] = jsimd_h2v1_upsample;
else else
upsample->methods[ci] = h2v1_upsample; upsample->methods[ci] = h2v1_upsample;
} }
} else if (h_in_group * 2 == h_out_group && } else if (h_in_group * 2 == h_out_group &&
v_in_group * 2 == v_out_group) { v_in_group * 2 == v_out_group) {
/* Special cases for 2h2v upsampling */ /* Special cases for 2h2v upsampling */
if (do_fancy && compptr->downsampled_width > 2) { if (do_fancy && compptr->downsampled_width > 2) {
if (jsimd_can_h2v2_fancy_upsample()) if (jsimd_can_h2v2_fancy_upsample())
upsample->methods[ci] = jsimd_h2v2_fancy_upsample; upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
else else
upsample->methods[ci] = h2v2_fancy_upsample; upsample->methods[ci] = h2v2_fancy_upsample;
upsample->pub.need_context_rows = TRUE; upsample->pub.need_context_rows = TRUE;
} else { } else {
if (jsimd_can_h2v2_upsample()) if (jsimd_can_h2v2_upsample())
upsample->methods[ci] = jsimd_h2v2_upsample; upsample->methods[ci] = jsimd_h2v2_upsample;
else else
upsample->methods[ci] = h2v2_upsample; upsample->methods[ci] = h2v2_upsample;
} }
} else if ((h_out_group % h_in_group) == 0 && } else if ((h_out_group % h_in_group) == 0 &&
(v_out_group % v_in_group) == 0) { (v_out_group % v_in_group) == 0) {
/* Generic integral-factors upsampling method */ /* Generic integral-factors upsampling method */
upsample->methods[ci] = int_upsample; #if defined(__mips__)
if (jsimd_can_int_upsample())
upsample->methods[ci] = jsimd_int_upsample;
else
#endif
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) { if (need_buffer) {
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

@@ -1,8 +1,10 @@
/* /*
* jdtrans.c * jdtrans.c
* *
* 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.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains library routines for transcoding decompression, * This file contains library routines for transcoding decompression,
@@ -16,7 +18,7 @@
/* Forward declarations */ /* Forward declarations */
LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo)); LOCAL(void) transdecode_master_selection (j_decompress_ptr cinfo);
/* /*
@@ -55,20 +57,20 @@ 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)
return NULL; return NULL;
if (retcode == JPEG_REACHED_EOI) if (retcode == JPEG_REACHED_EOI)
break; break;
/* Advance progress counter if appropriate */ /* Advance progress counter if appropriate */
if (cinfo->progress != NULL && if (cinfo->progress != NULL &&
(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;
} }
} }
} }
/* Set state so that jpeg_finish_decompress does the right thing */ /* Set state so that jpeg_finish_decompress does the right thing */
@@ -84,7 +86,7 @@ jpeg_read_coefficients (j_decompress_ptr cinfo)
} }
/* Oops, improper usage */ /* Oops, improper usage */
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
return NULL; /* keep compiler happy */ return NULL; /* keep compiler happy */
} }

View File

@@ -1,8 +1,10 @@
/* /*
* jerror.c * jerror.c
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains simple error-reporting and trace-message routines. * This file contains simple error-reporting and trace-message routines.
@@ -28,7 +30,7 @@
#include <windows.h> #include <windows.h>
#endif #endif
#ifndef EXIT_FAILURE /* define exit() codes if not provided */ #ifndef EXIT_FAILURE /* define exit() codes if not provided */
#define EXIT_FAILURE 1 #define EXIT_FAILURE 1
#endif #endif
@@ -41,11 +43,7 @@
* want to refer to it directly. * want to refer to it directly.
*/ */
#ifdef NEED_SHORT_EXTERNAL_NAMES #define JMESSAGE(code,string) string ,
#define jpeg_std_message_table jMsgTable
#endif
#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"
@@ -105,7 +103,7 @@ output_message (j_common_ptr cinfo)
#ifdef USE_WINDOWS_MESSAGEBOX #ifdef USE_WINDOWS_MESSAGEBOX
/* Display it in a message dialog box */ /* Display it in a message dialog box */
MessageBox(GetActiveWindow(), buffer, "JPEG Library Error", MessageBox(GetActiveWindow(), buffer, "JPEG Library Error",
MB_OK | MB_ICONERROR); MB_OK | MB_ICONERROR);
#else #else
/* Send it to stderr, adding a newline */ /* Send it to stderr, adding a newline */
fprintf(stderr, "%s\n", buffer); fprintf(stderr, "%s\n", buffer);
@@ -167,8 +165,8 @@ format_message (j_common_ptr cinfo, char * buffer)
if (msg_code > 0 && msg_code <= err->last_jpeg_message) { if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
msgtext = err->jpeg_message_table[msg_code]; msgtext = err->jpeg_message_table[msg_code];
} else if (err->addon_message_table != NULL && } else if (err->addon_message_table != NULL &&
msg_code >= err->first_addon_message && msg_code >= err->first_addon_message &&
msg_code <= err->last_addon_message) { msg_code <= err->last_addon_message) {
msgtext = err->addon_message_table[msg_code - err->first_addon_message]; msgtext = err->addon_message_table[msg_code - err->first_addon_message];
} }
@@ -193,10 +191,10 @@ format_message (j_common_ptr cinfo, char * buffer)
sprintf(buffer, msgtext, err->msg_parm.s); sprintf(buffer, msgtext, err->msg_parm.s);
else else
sprintf(buffer, msgtext, sprintf(buffer, msgtext,
err->msg_parm.i[0], err->msg_parm.i[1], err->msg_parm.i[0], err->msg_parm.i[1],
err->msg_parm.i[2], err->msg_parm.i[3], err->msg_parm.i[2], err->msg_parm.i[3],
err->msg_parm.i[4], err->msg_parm.i[5], err->msg_parm.i[4], err->msg_parm.i[5],
err->msg_parm.i[6], err->msg_parm.i[7]); err->msg_parm.i[6], err->msg_parm.i[7]);
} }
@@ -213,17 +211,17 @@ 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 */
cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */ cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */
} }
/* /*
* Fill in the standard error-handling methods in a jpeg_error_mgr object. * Fill in the standard error-handling methods in a jpeg_error_mgr object.
* Typical call is: * Typical call is:
* struct jpeg_compress_struct cinfo; * struct jpeg_compress_struct cinfo;
* struct jpeg_error_mgr err; * struct jpeg_error_mgr err;
* *
* cinfo.err = jpeg_std_error(&err); * cinfo.err = jpeg_std_error(&err);
* after which the application may override some of the methods. * after which the application may override some of the methods.
*/ */
@@ -236,16 +234,16 @@ jpeg_std_error (struct jpeg_error_mgr * err)
err->format_message = format_message; err->format_message = format_message;
err->reset_error_mgr = reset_error_mgr; err->reset_error_mgr = reset_error_mgr;
err->trace_level = 0; /* default = no tracing */ err->trace_level = 0; /* default = no tracing */
err->num_warnings = 0; /* no warnings emitted yet */ err->num_warnings = 0; /* no warnings emitted yet */
err->msg_code = 0; /* may be useful as a flag for "no error" */ err->msg_code = 0; /* may be useful as a flag for "no error" */
/* 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 */
err->last_addon_message = 0; err->last_addon_message = 0;
return err; return err;

View File

@@ -1,9 +1,11 @@
/* /*
* jerror.h * jerror.h
* *
* This file was part of the Independent JPEG Group's software:
* 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.
* This file is part of the Independent JPEG Group's software. * libjpeg-turbo Modifications:
* Copyright (C) 2014, D. R. Commander.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file defines the error and message codes for the JPEG library. * This file defines the error and message codes for the JPEG library.
@@ -33,7 +35,7 @@
typedef enum { typedef enum {
#define JMESSAGE(code,string) code , #define JMESSAGE(code,string) code ,
#endif /* JMAKE_ENUM_LIST */ #endif /* JMAKE_ENUM_LIST */
@@ -42,7 +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")
@@ -55,26 +57,26 @@ JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported") JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
JMESSAGE(JERR_BAD_DROP_SAMPLING, JMESSAGE(JERR_BAD_DROP_SAMPLING,
"Component index %d: mismatching sampling ratio %d:%d, %d:%d, %c") "Component index %d: mismatching sampling ratio %d:%d, %d:%d, %c")
#endif #endif
JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition") JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace") JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace") JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length") JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
JMESSAGE(JERR_BAD_LIB_VERSION, JMESSAGE(JERR_BAD_LIB_VERSION,
"Wrong JPEG library version: library is %d, caller expects %d") "Wrong JPEG library version: library is %d, caller expects %d")
JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan") JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d") JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d") JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
JMESSAGE(JERR_BAD_PROGRESSION, JMESSAGE(JERR_BAD_PROGRESSION,
"Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d") "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
JMESSAGE(JERR_BAD_PROG_SCRIPT, JMESSAGE(JERR_BAD_PROG_SCRIPT,
"Invalid progressive parameters at scan script entry %d") "Invalid progressive parameters at scan script entry %d")
JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors") JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d") JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d") JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
JMESSAGE(JERR_BAD_STRUCT_SIZE, JMESSAGE(JERR_BAD_STRUCT_SIZE,
"JPEG parameter struct mismatch: library thinks size is %u, caller expects %u") "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access") JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small") JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here") JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
@@ -98,7 +100,7 @@ JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
JMESSAGE(JERR_INPUT_EMPTY, "Empty input file") JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
JMESSAGE(JERR_INPUT_EOF, "Premature end of input file") JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
JMESSAGE(JERR_MISMATCHED_QUANT_TABLE, JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
"Cannot transcode due to multiple use of quantization table %d") "Cannot transcode due to multiple use of quantization table %d")
JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data") JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change") JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
JMESSAGE(JERR_NOTIMPL, "Not implemented yet") JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
@@ -113,7 +115,7 @@ JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x") JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)") JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
JMESSAGE(JERR_QUANT_COMPONENTS, JMESSAGE(JERR_QUANT_COMPONENTS,
"Cannot quantize more than %d color components") "Cannot quantize more than %d color components")
JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors") JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors") JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers") JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
@@ -125,19 +127,19 @@ JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file") JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file") JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
JMESSAGE(JERR_TFILE_WRITE, JMESSAGE(JERR_TFILE_WRITE,
"Write failed on temporary file --- out of disk space?") "Write failed on temporary file --- out of disk space?")
JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines") JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x") JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up") JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation") JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
JMESSAGE(JERR_XMS_READ, "Read from XMS failed") JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed") JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT) JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT_SHORT)
JMESSAGE(JMSG_VERSION, JVERSION) JMESSAGE(JMSG_VERSION, JVERSION)
JMESSAGE(JTRC_16BIT_TABLES, JMESSAGE(JTRC_16BIT_TABLES,
"Caution: quantization tables are too coarse for baseline JPEG") "Caution: quantization tables are too coarse for baseline JPEG")
JMESSAGE(JTRC_ADOBE, JMESSAGE(JTRC_ADOBE,
"Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d") "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u") JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u") JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x") JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
@@ -150,9 +152,9 @@ JMESSAGE(JTRC_EOI, "End Of Image")
JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d") 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")
@@ -163,7 +165,7 @@ JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d") JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
JMESSAGE(JTRC_RST, "RST%d") JMESSAGE(JTRC_RST, "RST%d")
JMESSAGE(JTRC_SMOOTH_NOTIMPL, JMESSAGE(JTRC_SMOOTH_NOTIMPL,
"Smoothing not supported with nonstandard sampling ratios") "Smoothing not supported with nonstandard sampling ratios")
JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d") JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d") JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
JMESSAGE(JTRC_SOI, "Start of Image") JMESSAGE(JTRC_SOI, "Start of Image")
@@ -173,13 +175,13 @@ JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s") JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s") JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
JMESSAGE(JTRC_THUMB_JPEG, JMESSAGE(JTRC_THUMB_JPEG,
"JFIF extension marker: JPEG-compressed thumbnail image, length %u") "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
JMESSAGE(JTRC_THUMB_PALETTE, JMESSAGE(JTRC_THUMB_PALETTE,
"JFIF extension marker: palette thumbnail image, length %u") "JFIF extension marker: palette thumbnail image, length %u")
JMESSAGE(JTRC_THUMB_RGB, JMESSAGE(JTRC_THUMB_RGB,
"JFIF extension marker: RGB thumbnail image, length %u") "JFIF extension marker: RGB thumbnail image, length %u")
JMESSAGE(JTRC_UNKNOWN_IDS, JMESSAGE(JTRC_UNKNOWN_IDS,
"Unrecognized component IDs %d %d %d, assuming YCbCr") "Unrecognized component IDs %d %d %d, assuming YCbCr")
JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u") JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u") JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d") JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
@@ -187,15 +189,15 @@ JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code") JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code")
#endif #endif
JMESSAGE(JWRN_BOGUS_PROGRESSION, JMESSAGE(JWRN_BOGUS_PROGRESSION,
"Inconsistent progression sequence for component %d coefficient %d") "Inconsistent progression sequence for component %d coefficient %d")
JMESSAGE(JWRN_EXTRANEOUS_DATA, JMESSAGE(JWRN_EXTRANEOUS_DATA,
"Corrupt JPEG data: %u extraneous bytes before marker 0x%02x") "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment") JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code") JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d") JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file") JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
JMESSAGE(JWRN_MUST_RESYNC, JMESSAGE(JWRN_MUST_RESYNC,
"Corrupt JPEG data: found marker 0x%02x instead of RST%d") "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG") JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines") JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
#if JPEG_LIB_VERSION < 70 #if JPEG_LIB_VERSION < 70
@@ -255,7 +257,7 @@ JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic 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) \
@@ -286,26 +288,26 @@ JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code")
(*(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), \

View File

@@ -37,7 +37,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
@@ -79,7 +79,7 @@ jpeg_fdct_float (FAST_FLOAT * data)
/* Even part */ /* Even part */
tmp10 = tmp0 + tmp3; /* phase 2 */ tmp10 = tmp0 + tmp3; /* phase 2 */
tmp13 = tmp0 - tmp3; tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2; tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2; tmp12 = tmp1 - tmp2;
@@ -88,12 +88,12 @@ jpeg_fdct_float (FAST_FLOAT * data)
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;
/* Odd part */ /* Odd part */
tmp10 = tmp4 + tmp5; /* phase 2 */ tmp10 = tmp4 + tmp5; /* phase 2 */
tmp11 = tmp5 + tmp6; tmp11 = tmp5 + tmp6;
tmp12 = tmp6 + tmp7; tmp12 = tmp6 + tmp7;
@@ -103,15 +103,15 @@ jpeg_fdct_float (FAST_FLOAT * data)
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[5] = z13 + z2; /* phase 6 */ dataptr[5] = z13 + z2; /* phase 6 */
dataptr[3] = z13 - z2; dataptr[3] = z13 - z2;
dataptr[1] = z11 + z4; dataptr[1] = z11 + z4;
dataptr[7] = z11 - z4; dataptr[7] = z11 - z4;
dataptr += DCTSIZE; /* advance pointer to next row */ dataptr += DCTSIZE; /* advance pointer to next row */
} }
/* Pass 2: process columns. */ /* Pass 2: process columns. */
@@ -129,7 +129,7 @@ jpeg_fdct_float (FAST_FLOAT * data)
/* Even part */ /* Even part */
tmp10 = tmp0 + tmp3; /* phase 2 */ tmp10 = tmp0 + tmp3; /* phase 2 */
tmp13 = tmp0 - tmp3; tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2; tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2; tmp12 = tmp1 - tmp2;
@@ -143,7 +143,7 @@ jpeg_fdct_float (FAST_FLOAT * data)
/* Odd part */ /* Odd part */
tmp10 = tmp4 + tmp5; /* phase 2 */ tmp10 = tmp4 + tmp5; /* phase 2 */
tmp11 = tmp5 + tmp6; tmp11 = tmp5 + tmp6;
tmp12 = tmp6 + tmp7; tmp12 = tmp6 + tmp7;
@@ -153,7 +153,7 @@ jpeg_fdct_float (FAST_FLOAT * data)
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 */
@@ -161,7 +161,7 @@ jpeg_fdct_float (FAST_FLOAT * data)
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

@@ -33,7 +33,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_IFAST_SUPPORTED #ifdef DCT_IFAST_SUPPORTED
@@ -76,10 +76,10 @@
*/ */
#if CONST_BITS == 8 #if CONST_BITS == 8
#define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */ #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
#define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */ #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
#define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */ #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
#define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */ #define FIX_1_306562965 ((INT32) 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)
@@ -135,7 +135,7 @@ jpeg_fdct_ifast (DCTELEM * data)
/* Even part */ /* Even part */
tmp10 = tmp0 + tmp3; /* phase 2 */ tmp10 = tmp0 + tmp3; /* phase 2 */
tmp13 = tmp0 - tmp3; tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2; tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2; tmp12 = tmp1 - tmp2;
@@ -144,12 +144,12 @@ jpeg_fdct_ifast (DCTELEM * data)
dataptr[4] = tmp10 - tmp11; dataptr[4] = tmp10 - tmp11;
z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
dataptr[2] = tmp13 + z1; /* phase 5 */ dataptr[2] = tmp13 + z1; /* phase 5 */
dataptr[6] = tmp13 - z1; dataptr[6] = tmp13 - z1;
/* Odd part */ /* Odd part */
tmp10 = tmp4 + tmp5; /* phase 2 */ tmp10 = tmp4 + tmp5; /* phase 2 */
tmp11 = tmp5 + tmp6; tmp11 = tmp5 + tmp6;
tmp12 = tmp6 + tmp7; tmp12 = tmp6 + tmp7;
@@ -159,15 +159,15 @@ jpeg_fdct_ifast (DCTELEM * data)
z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */ z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */ z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
z11 = tmp7 + z3; /* phase 5 */ z11 = tmp7 + z3; /* phase 5 */
z13 = tmp7 - z3; z13 = tmp7 - z3;
dataptr[5] = z13 + z2; /* phase 6 */ dataptr[5] = z13 + z2; /* phase 6 */
dataptr[3] = z13 - z2; dataptr[3] = z13 - z2;
dataptr[1] = z11 + z4; dataptr[1] = z11 + z4;
dataptr[7] = z11 - z4; dataptr[7] = z11 - z4;
dataptr += DCTSIZE; /* advance pointer to next row */ dataptr += DCTSIZE; /* advance pointer to next row */
} }
/* Pass 2: process columns. */ /* Pass 2: process columns. */
@@ -185,7 +185,7 @@ jpeg_fdct_ifast (DCTELEM * data)
/* Even part */ /* Even part */
tmp10 = tmp0 + tmp3; /* phase 2 */ tmp10 = tmp0 + tmp3; /* phase 2 */
tmp13 = tmp0 - tmp3; tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2; tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2; tmp12 = tmp1 - tmp2;
@@ -199,7 +199,7 @@ jpeg_fdct_ifast (DCTELEM * data)
/* Odd part */ /* Odd part */
tmp10 = tmp4 + tmp5; /* phase 2 */ tmp10 = tmp4 + tmp5; /* phase 2 */
tmp11 = tmp5 + tmp6; tmp11 = tmp5 + tmp6;
tmp12 = tmp6 + tmp7; tmp12 = tmp6 + tmp7;
@@ -209,7 +209,7 @@ jpeg_fdct_ifast (DCTELEM * data)
z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */ z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */ z3 = MULTIPLY(tmp11, FIX_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 */
@@ -217,7 +217,7 @@ jpeg_fdct_ifast (DCTELEM * data)
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

@@ -26,7 +26,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_ISLOW_SUPPORTED #ifdef DCT_ISLOW_SUPPORTED
@@ -79,7 +79,7 @@
#define PASS1_BITS 2 #define PASS1_BITS 2
#else #else
#define CONST_BITS 13 #define CONST_BITS 13
#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
#endif #endif
/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
@@ -90,18 +90,18 @@
*/ */
#if CONST_BITS == 13 #if CONST_BITS == 13
#define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */ #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
#define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */ #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
#define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */ #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */ #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */ #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
#define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */ #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
#define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */ #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */ #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
#define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */ #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
#define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */ #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */ #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
#define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */ #define FIX_3_072711026 ((INT32) 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)
@@ -175,9 +175,9 @@ jpeg_fdct_islow (DCTELEM * data)
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).
@@ -207,7 +207,7 @@ jpeg_fdct_islow (DCTELEM * data)
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 */
} }
/* Pass 2: process columns. /* Pass 2: process columns.
@@ -240,9 +240,9 @@ jpeg_fdct_islow (DCTELEM * data)
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] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
CONST_BITS+PASS1_BITS); CONST_BITS+PASS1_BITS);
dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), dataptr[DCTSIZE*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).
@@ -268,15 +268,15 @@ jpeg_fdct_islow (DCTELEM * data)
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

@@ -42,7 +42,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
@@ -69,8 +69,8 @@
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, JDIMENSION output_col) JSAMPARRAY output_buf, 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;
@@ -100,9 +100,9 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
*/ */
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);
@@ -116,7 +116,7 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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++;
wsptr++; wsptr++;
continue; continue;
@@ -129,13 +129,13 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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;
tmp1 = tmp11 + tmp12; tmp1 = tmp11 + tmp12;
tmp2 = tmp11 - tmp12; tmp2 = tmp11 - tmp12;
@@ -147,19 +147,19 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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;
z11 = tmp4 + tmp7; z11 = tmp4 + tmp7;
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;
@@ -172,7 +172,7 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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++;
wsptr++; wsptr++;
} }
@@ -232,7 +232,7 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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

@@ -35,7 +35,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_IFAST_SUPPORTED #ifdef DCT_IFAST_SUPPORTED
@@ -78,7 +78,7 @@
#define PASS1_BITS 2 #define PASS1_BITS 2
#else #else
#define CONST_BITS 8 #define CONST_BITS 8
#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
#endif #endif
/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
@@ -89,10 +89,10 @@
*/ */
#if CONST_BITS == 8 #if CONST_BITS == 8
#define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */ #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
#define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */ #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
#define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */ #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
#define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */ #define FIX_2_613125930 ((INT32) 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)
@@ -129,7 +129,7 @@
#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
@@ -138,11 +138,11 @@
*/ */
#ifdef RIGHT_SHIFT_IS_UNSIGNED #ifdef RIGHT_SHIFT_IS_UNSIGNED
#define ISHIFT_TEMPS DCTELEM ishift_temp; #define ISHIFT_TEMPS DCTELEM ishift_temp;
#if BITS_IN_JSAMPLE == 8 #if BITS_IN_JSAMPLE == 8
#define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */ #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
#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 ? \
@@ -150,7 +150,7 @@
(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
@@ -166,8 +166,8 @@
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, JDIMENSION output_col) JSAMPARRAY output_buf, 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;
@@ -178,9 +178,9 @@ jpeg_idct_ifast (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[DCTSIZE2]; /* buffers data between passes */ int workspace[DCTSIZE2]; /* buffers data between passes */
SHIFT_TEMPS /* for DESCALE */ SHIFT_TEMPS /* for DESCALE */
ISHIFT_TEMPS /* for IDESCALE */ ISHIFT_TEMPS /* for IDESCALE */
/* Pass 1: process columns from input, store into work array. */ /* Pass 1: process columns from input, store into work array. */
@@ -198,9 +198,9 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
*/ */
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]);
@@ -213,7 +213,7 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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++;
wsptr++; wsptr++;
continue; continue;
@@ -226,13 +226,13 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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;
tmp13 = tmp1 + tmp3; /* phases 5-3 */ tmp13 = tmp1 + tmp3; /* phases 5-3 */
tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */ tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
tmp0 = tmp10 + tmp13; /* phase 2 */ tmp0 = tmp10 + tmp13; /* phase 2 */
tmp3 = tmp10 - tmp13; tmp3 = tmp10 - tmp13;
tmp1 = tmp11 + tmp12; tmp1 = tmp11 + tmp12;
tmp2 = tmp11 - tmp12; tmp2 = tmp11 - tmp12;
@@ -244,19 +244,19 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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;
z11 = tmp4 + tmp7; z11 = tmp4 + tmp7;
z12 = tmp4 - tmp7; z12 = tmp4 - tmp7;
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;
tmp4 = tmp10 + tmp5; tmp4 = tmp10 + tmp5;
@@ -269,7 +269,7 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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++;
wsptr++; wsptr++;
} }
@@ -291,10 +291,10 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
#ifndef NO_ZERO_ROW_TEST #ifndef NO_ZERO_ROW_TEST
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_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[0] = dcval; outptr[0] = dcval;
outptr[1] = dcval; outptr[1] = dcval;
@@ -305,7 +305,7 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
outptr[6] = dcval; outptr[6] = dcval;
outptr[7] = dcval; outptr[7] = dcval;
wsptr += DCTSIZE; /* advance pointer to next row */ wsptr += DCTSIZE; /* advance pointer to next row */
continue; continue;
} }
#endif #endif
@@ -317,7 +317,7 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
- tmp13; - tmp13;
tmp0 = tmp10 + tmp13; tmp0 = tmp10 + tmp13;
tmp3 = tmp10 - tmp13; tmp3 = tmp10 - tmp13;
@@ -331,37 +331,37 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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;
tmp4 = tmp10 + tmp5; tmp4 = tmp10 + tmp5;
/* 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_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3) outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3) outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3) outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3) outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3) outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3) outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3) outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
& RANGE_MASK]; & 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

@@ -23,7 +23,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef IDCT_SCALING_SUPPORTED #ifdef IDCT_SCALING_SUPPORTED
@@ -44,7 +44,7 @@
#define PASS1_BITS 2 #define PASS1_BITS 2
#else #else
#define CONST_BITS 13 #define CONST_BITS 13
#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
#endif #endif
/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
@@ -55,20 +55,20 @@
*/ */
#if CONST_BITS == 13 #if CONST_BITS == 13
#define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */ #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
#define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */ #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
#define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */ #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
#define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */ #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */ #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
#define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */ #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */ #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
#define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */ #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
#define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */ #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
#define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */ #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */ #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
#define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */ #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */ #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
#define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */ #define FIX_3_624509785 ((INT32) 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)
@@ -116,8 +116,8 @@
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, JDIMENSION output_col) JSAMPARRAY output_buf, JDIMENSION output_col)
{ {
INT32 tmp0, tmp2, tmp10, tmp12; INT32 tmp0, tmp2, tmp10, tmp12;
INT32 z1, z2, z3, z4; INT32 z1, z2, z3, z4;
@@ -127,7 +127,7 @@ 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. */
@@ -140,8 +140,8 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
@@ -174,14 +174,14 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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 */
@@ -200,17 +200,17 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
#ifndef NO_ZERO_ROW_TEST #ifndef NO_ZERO_ROW_TEST
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((INT32) wsptr[0], PASS1_BITS+3) JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[0] = dcval; outptr[0] = dcval;
outptr[1] = dcval; outptr[1] = dcval;
outptr[2] = dcval; outptr[2] = dcval;
outptr[3] = dcval; outptr[3] = dcval;
wsptr += DCTSIZE; /* advance pointer to next row */ wsptr += DCTSIZE; /* advance pointer to next row */
continue; continue;
} }
#endif #endif
@@ -220,7 +220,7 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1); tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065) tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
+ MULTIPLY((INT32) wsptr[6], - FIX_0_765366865); + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
tmp10 = tmp0 + tmp2; tmp10 = tmp0 + tmp2;
tmp12 = tmp0 - tmp2; tmp12 = tmp0 - tmp2;
@@ -233,31 +233,31 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
z4 = (INT32) wsptr[1]; z4 = (INT32) 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 */
} }
} }
@@ -269,8 +269,8 @@ 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, JDIMENSION output_col) JSAMPARRAY output_buf, JDIMENSION output_col)
{ {
INT32 tmp0, tmp10, z1; INT32 tmp0, tmp10, z1;
JCOEFPTR inptr; JCOEFPTR inptr;
@@ -279,7 +279,7 @@ 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. */
@@ -292,7 +292,7 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
@@ -335,12 +335,12 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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((INT32) wsptr[0], PASS1_BITS+3) JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[0] = dcval; outptr[0] = dcval;
outptr[1] = dcval; outptr[1] = dcval;
wsptr += DCTSIZE; /* advance pointer to next row */ wsptr += DCTSIZE; /* advance pointer to next row */
continue; continue;
} }
#endif #endif
@@ -352,20 +352,20 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Odd part */ /* Odd part */
tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */ tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
+ MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */ + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
+ MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */ + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
+ MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */ + MULTIPLY((INT32) 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 */
} }
} }
@@ -377,8 +377,8 @@ 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, JDIMENSION output_col) JSAMPARRAY output_buf, JDIMENSION output_col)
{ {
int dcval; int dcval;
ISLOW_MULT_TYPE * quantptr; ISLOW_MULT_TYPE * quantptr;

View File

@@ -1,8 +1,10 @@
/* /*
* jinclude.h * jinclude.h
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1994, Thomas G. Lane. * Copyright (C) 1991-1994, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file exists to provide a single place to fix any problems with * This file exists to provide a single place to fix any problems with
@@ -17,8 +19,8 @@
/* Include auto-config file to find out which system include files we need. */ /* Include auto-config file to find out which system include files we need. */
#include "jconfig.h" /* auto configuration options */ #include "jconfig.h" /* auto configuration options */
#define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */ #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
/* /*
* We need the NULL macro and size_t typedef. * We need the NULL macro and size_t typedef.
@@ -58,27 +60,17 @@
#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) bzero((void *)(target), (size_t)(size))
#define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (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) memset((void *)(target), 0, (size_t)(size))
#define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size)) #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
#endif #endif
/*
* In ANSI C, and indeed any rational implementation, size_t is also the
* type returned by sizeof(). However, it seems there are some irrational
* implementations out there, in which sizeof() returns an int even though
* size_t is defined as long or unsigned long. To ensure consistent results
* we always use this SIZEOF() macro in place of using sizeof() directly.
*/
#define SIZEOF(object) ((size_t) sizeof(object))
/* /*
* The modules that use fread() and fwrite() always invoke them through * The modules that use fread() and fwrite() always invoke them through
* these macros. On some systems you may need to twiddle the argument casts. * these macros. On some systems you may need to twiddle the argument casts.

385
jmemmgr.c
View File

@@ -1,8 +1,10 @@
/* /*
* jmemmgr.c * jmemmgr.c
* *
* 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.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code and
* information relevant to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains the JPEG system-independent memory management * This file contains the JPEG system-independent memory management
@@ -25,14 +27,14 @@
*/ */
#define JPEG_INTERNALS #define JPEG_INTERNALS
#define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */ #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
#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 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 JPP((const char * name)); extern char * getenv (const char * name);
#endif #endif
#endif #endif
@@ -78,9 +80,9 @@ round_up_pow2 (size_t a, size_t b)
* such a compiler. * such a compiler.
*/ */
#ifndef ALIGN_SIZE /* so can override from jconfig.h */ #ifndef ALIGN_SIZE /* so can override from jconfig.h */
#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 16 /* Most SIMD implementations require this */
#endif #endif
@@ -91,24 +93,23 @@ round_up_pow2 (size_t a, size_t b)
* request to jpeg_get_small() or jpeg_get_large(). There is no per-object * request to jpeg_get_small() or jpeg_get_large(). There is no per-object
* overhead within a pool, except for alignment padding. Each pool has a * overhead within a pool, except for alignment padding. Each pool has a
* header with a link to the next pool of the same class. * header with a link to the next pool of the same class.
* Small and large pool headers are identical except that the latter's * Small and large pool headers are identical.
* link pointer must be FAR on 80x86 machines.
*/ */
typedef struct small_pool_struct * small_pool_ptr; typedef struct small_pool_struct * small_pool_ptr;
typedef struct small_pool_struct { typedef struct small_pool_struct {
small_pool_ptr next; /* next in list of pools */ small_pool_ptr next; /* next in list of pools */
size_t bytes_used; /* how many bytes already used within pool */ size_t bytes_used; /* how many bytes already used within pool */
size_t bytes_left; /* bytes still available in this pool */ size_t bytes_left; /* bytes still available in this pool */
} small_pool_hdr; } small_pool_hdr;
typedef struct large_pool_struct FAR * large_pool_ptr; typedef struct large_pool_struct * large_pool_ptr;
typedef struct large_pool_struct { typedef struct large_pool_struct {
large_pool_ptr next; /* next in list of pools */ large_pool_ptr next; /* next in list of pools */
size_t bytes_used; /* how many bytes already used within pool */ size_t bytes_used; /* how many bytes already used within pool */
size_t bytes_left; /* bytes still available in this pool */ size_t bytes_left; /* bytes still available in this pool */
} large_pool_hdr; } large_pool_hdr;
/* /*
@@ -116,7 +117,7 @@ typedef struct large_pool_struct {
*/ */
typedef struct { typedef struct {
struct jpeg_memory_mgr pub; /* public fields */ struct jpeg_memory_mgr pub; /* public fields */
/* Each pool identifier (lifetime class) names a linked list of pools. */ /* Each pool identifier (lifetime class) names a linked list of pools. */
small_pool_ptr small_list[JPOOL_NUMPOOLS]; small_pool_ptr small_list[JPOOL_NUMPOOLS];
@@ -136,7 +137,7 @@ typedef struct {
/* alloc_sarray and alloc_barray set this value for use by virtual /* alloc_sarray and alloc_barray set this value for use by virtual
* array routines. * array routines.
*/ */
JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */ JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
} my_memory_mgr; } my_memory_mgr;
typedef my_memory_mgr * my_mem_ptr; typedef my_memory_mgr * my_mem_ptr;
@@ -150,39 +151,39 @@ typedef my_memory_mgr * my_mem_ptr;
*/ */
struct jvirt_sarray_control { struct jvirt_sarray_control {
JSAMPARRAY mem_buffer; /* => the in-memory buffer */ JSAMPARRAY mem_buffer; /* => the in-memory buffer */
JDIMENSION rows_in_array; /* total virtual array height */ JDIMENSION rows_in_array; /* total virtual array height */
JDIMENSION samplesperrow; /* width of array (and of memory buffer) */ JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */ JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
JDIMENSION rows_in_mem; /* height of memory buffer */ JDIMENSION rows_in_mem; /* height of memory buffer */
JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */ JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
JDIMENSION cur_start_row; /* first logical row # in the buffer */ JDIMENSION cur_start_row; /* first logical row # in the buffer */
JDIMENSION first_undef_row; /* row # of first uninitialized row */ JDIMENSION first_undef_row; /* row # of first uninitialized row */
boolean pre_zero; /* pre-zero mode requested? */ boolean pre_zero; /* pre-zero mode requested? */
boolean dirty; /* do current buffer contents need written? */ boolean dirty; /* do current buffer contents need written? */
boolean b_s_open; /* is backing-store data valid? */ boolean b_s_open; /* is backing-store data valid? */
jvirt_sarray_ptr next; /* link to next virtual sarray control block */ jvirt_sarray_ptr next; /* link to next virtual sarray control block */
backing_store_info b_s_info; /* System-dependent control info */ backing_store_info b_s_info; /* System-dependent control info */
}; };
struct jvirt_barray_control { struct jvirt_barray_control {
JBLOCKARRAY mem_buffer; /* => the in-memory buffer */ JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
JDIMENSION rows_in_array; /* total virtual array height */ JDIMENSION rows_in_array; /* total virtual array height */
JDIMENSION blocksperrow; /* width of array (and of memory buffer) */ JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */ JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
JDIMENSION rows_in_mem; /* height of memory buffer */ JDIMENSION rows_in_mem; /* height of memory buffer */
JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */ JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
JDIMENSION cur_start_row; /* first logical row # in the buffer */ JDIMENSION cur_start_row; /* first logical row # in the buffer */
JDIMENSION first_undef_row; /* row # of first uninitialized row */ JDIMENSION first_undef_row; /* row # of first uninitialized row */
boolean pre_zero; /* pre-zero mode requested? */ boolean pre_zero; /* pre-zero mode requested? */
boolean dirty; /* do current buffer contents need written? */ boolean dirty; /* do current buffer contents need written? */
boolean b_s_open; /* is backing-store data valid? */ boolean b_s_open; /* is backing-store data valid? */
jvirt_barray_ptr next; /* link to next virtual barray control block */ jvirt_barray_ptr next; /* link to next virtual barray control block */
backing_store_info b_s_info; /* System-dependent control info */ backing_store_info b_s_info; /* System-dependent control info */
}; };
#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)
@@ -196,19 +197,19 @@ print_mem_stats (j_common_ptr cinfo, int pool_id)
* This is helpful because message parm array can't handle longs. * This is helpful because message parm array can't handle longs.
*/ */
fprintf(stderr, "Freeing pool %d, total space = %ld\n", fprintf(stderr, "Freeing pool %d, total space = %ld\n",
pool_id, mem->total_space_allocated); pool_id, mem->total_space_allocated);
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);
} }
} }
@@ -221,7 +222,7 @@ out_of_memory (j_common_ptr cinfo, int which)
/* If we compiled MEM_STATS support, report alloc requests before dying */ /* If we compiled MEM_STATS support, report alloc requests before dying */
{ {
#ifdef MEM_STATS #ifdef MEM_STATS
cinfo->err->trace_level = 2; /* force self_destruct to report stats */ cinfo->err->trace_level = 2; /* force self_destruct to report stats */
#endif #endif
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which); ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
} }
@@ -246,17 +247,17 @@ out_of_memory (j_common_ptr cinfo, int which)
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 */
}; };
#define MIN_SLOP 50 /* greater than 0 to avoid futile looping */ #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
METHODDEF(void *) METHODDEF(void *)
@@ -277,17 +278,17 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
sizeofobject = round_up_pow2(sizeofobject, ALIGN_SIZE); sizeofobject = round_up_pow2(sizeofobject, ALIGN_SIZE);
/* Check for unsatisfiable request (do now to ensure no overflow below) */ /* Check for unsatisfiable request (do now to ensure no overflow below) */
if ((SIZEOF(small_pool_hdr) + sizeofobject + ALIGN_SIZE - 1) > MAX_ALLOC_CHUNK) if ((sizeof(small_pool_hdr) + sizeofobject + ALIGN_SIZE - 1) > MAX_ALLOC_CHUNK)
out_of_memory(cinfo, 1); /* request exceeds malloc's ability */ out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
/* See if space is available in any existing pool */ /* See if space is available in any existing pool */
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 */
prev_hdr_ptr = NULL; prev_hdr_ptr = NULL;
hdr_ptr = mem->small_list[pool_id]; hdr_ptr = mem->small_list[pool_id];
while (hdr_ptr != NULL) { while (hdr_ptr != NULL) {
if (hdr_ptr->bytes_left >= sizeofobject) if (hdr_ptr->bytes_left >= sizeofobject)
break; /* found pool with enough space */ break; /* found pool with enough space */
prev_hdr_ptr = hdr_ptr; prev_hdr_ptr = hdr_ptr;
hdr_ptr = hdr_ptr->next; hdr_ptr = hdr_ptr->next;
} }
@@ -295,8 +296,8 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
/* Time to make a new pool? */ /* Time to make a new pool? */
if (hdr_ptr == NULL) { if (hdr_ptr == NULL) {
/* min_request is what we need now, slop is what will be leftover */ /* min_request is what we need now, slop is what will be leftover */
min_request = SIZEOF(small_pool_hdr) + sizeofobject + ALIGN_SIZE - 1; min_request = sizeof(small_pool_hdr) + sizeofobject + ALIGN_SIZE - 1;
if (prev_hdr_ptr == NULL) /* first pool in class? */ if (prev_hdr_ptr == NULL) /* first pool in class? */
slop = first_pool_slop[pool_id]; slop = first_pool_slop[pool_id];
else else
slop = extra_pool_slop[pool_id]; slop = extra_pool_slop[pool_id];
@@ -307,17 +308,17 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
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;
if (slop < MIN_SLOP) /* give up when it gets real small */ if (slop < MIN_SLOP) /* give up when it gets real small */
out_of_memory(cinfo, 2); /* jpeg_get_small failed */ out_of_memory(cinfo, 2); /* jpeg_get_small failed */
} }
mem->total_space_allocated += min_request + slop; mem->total_space_allocated += min_request + slop;
/* Success, initialize the new pool header and add to end of list */ /* Success, initialize the new pool header and add to end of list */
hdr_ptr->next = NULL; hdr_ptr->next = NULL;
hdr_ptr->bytes_used = 0; hdr_ptr->bytes_used = 0;
hdr_ptr->bytes_left = sizeofobject + slop; hdr_ptr->bytes_left = sizeofobject + slop;
if (prev_hdr_ptr == NULL) /* first pool in class? */ if (prev_hdr_ptr == NULL) /* first pool in class? */
mem->small_list[pool_id] = hdr_ptr; mem->small_list[pool_id] = hdr_ptr;
else else
prev_hdr_ptr->next = hdr_ptr; prev_hdr_ptr->next = hdr_ptr;
@@ -325,7 +326,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;
data_ptr += hdr_ptr->bytes_used; /* point to place for object */ data_ptr += hdr_ptr->bytes_used; /* point to place for object */
@@ -339,9 +340,8 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
/* /*
* Allocation of "large" objects. * Allocation of "large" objects.
* *
* The external semantics of these are the same as "small" objects, * The external semantics of these are the same as "small" objects. However,
* except that FAR pointers are used on 80x86. However the pool * the pool management heuristics are quite different. We assume that each
* management heuristics are quite different. We assume that each
* request is large enough that it may as well be passed directly to * request is large enough that it may as well be passed directly to
* jpeg_get_large; the pool management just links everything together * jpeg_get_large; the pool management just links everything together
* so that we can free it all on demand. * so that we can free it all on demand.
@@ -350,13 +350,13 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
* deliberately bunch rows together to ensure a large request size. * deliberately bunch rows together to ensure a large request size.
*/ */
METHODDEF(void FAR *) 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 FAR * data_ptr; char * data_ptr;
/* /*
* Round up the requested size to a multiple of ALIGN_SIZE so that * Round up the requested size to a multiple of ALIGN_SIZE so that
@@ -366,19 +366,19 @@ alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
sizeofobject = round_up_pow2(sizeofobject, ALIGN_SIZE); sizeofobject = round_up_pow2(sizeofobject, ALIGN_SIZE);
/* Check for unsatisfiable request (do now to ensure no overflow below) */ /* Check for unsatisfiable request (do now to ensure no overflow below) */
if ((SIZEOF(large_pool_hdr) + sizeofobject + ALIGN_SIZE - 1) > MAX_ALLOC_CHUNK) if ((sizeof(large_pool_hdr) + sizeofobject + ALIGN_SIZE - 1) > MAX_ALLOC_CHUNK)
out_of_memory(cinfo, 3); /* request exceeds malloc's ability */ out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
/* Always make a new pool */ /* Always make a new pool */
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)
out_of_memory(cinfo, 4); /* jpeg_get_large failed */ out_of_memory(cinfo, 4); /* jpeg_get_large failed */
mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr) + ALIGN_SIZE - 1; mem->total_space_allocated += sizeofobject + sizeof(large_pool_hdr) + ALIGN_SIZE - 1;
/* Success, initialize the new pool header and add to list */ /* Success, initialize the new pool header and add to list */
hdr_ptr->next = mem->large_list[pool_id]; hdr_ptr->next = mem->large_list[pool_id];
@@ -390,17 +390,16 @@ alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
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 FAR *) data_ptr; return (void *) data_ptr;
} }
/* /*
* Creation of 2-D sample arrays. * Creation of 2-D sample arrays.
* The pointers are in near heap, the samples themselves in FAR heap.
* *
* To minimize allocation overhead and to allow I/O of large contiguous * To minimize allocation overhead and to allow I/O of large contiguous
* blocks, we allocate the sample rows in groups of as many rows as possible * blocks, we allocate the sample rows in groups of as many rows as possible
@@ -417,7 +416,7 @@ 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 numrows) JDIMENSION samplesperrow, 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;
@@ -427,13 +426,13 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
long ltemp; long ltemp;
/* Make sure each row is properly aligned */ /* Make sure each row is properly aligned */
if ((ALIGN_SIZE % SIZEOF(JSAMPLE)) != 0) if ((ALIGN_SIZE % sizeof(JSAMPLE)) != 0)
out_of_memory(cinfo, 5); /* safety check */ out_of_memory(cinfo, 5); /* safety check */
samplesperrow = (JDIMENSION)round_up_pow2(samplesperrow, (2 * ALIGN_SIZE) / SIZEOF(JSAMPLE)); samplesperrow = (JDIMENSION)round_up_pow2(samplesperrow, (2 * ALIGN_SIZE) / 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)
@@ -444,15 +443,15 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
/* 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;
@@ -470,7 +469,7 @@ 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 numrows) JDIMENSION blocksperrow, 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;
@@ -480,12 +479,12 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
long ltemp; long ltemp;
/* Make sure each row is properly aligned */ /* Make sure each row is properly aligned */
if ((SIZEOF(JBLOCK) % ALIGN_SIZE) != 0) if ((sizeof(JBLOCK) % ALIGN_SIZE) != 0)
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)
@@ -496,15 +495,15 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
/* 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;
@@ -554,8 +553,8 @@ 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;
@@ -563,18 +562,18 @@ request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
/* Only IMAGE-lifetime virtual arrays are currently supported */ /* Only IMAGE-lifetime virtual arrays are currently supported */
if (pool_id != JPOOL_IMAGE) if (pool_id != JPOOL_IMAGE)
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 */
result->rows_in_array = numrows; result->rows_in_array = numrows;
result->samplesperrow = samplesperrow; result->samplesperrow = samplesperrow;
result->maxaccess = maxaccess; result->maxaccess = maxaccess;
result->pre_zero = pre_zero; result->pre_zero = pre_zero;
result->b_s_open = FALSE; /* no associated backing-store object */ result->b_s_open = FALSE; /* no associated backing-store object */
result->next = mem->virt_sarray_list; /* add to list of virtual arrays */ result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
mem->virt_sarray_list = result; mem->virt_sarray_list = result;
@@ -584,8 +583,8 @@ 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;
@@ -593,18 +592,18 @@ request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
/* Only IMAGE-lifetime virtual arrays are currently supported */ /* Only IMAGE-lifetime virtual arrays are currently supported */
if (pool_id != JPOOL_IMAGE) if (pool_id != JPOOL_IMAGE)
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 */
result->rows_in_array = numrows; result->rows_in_array = numrows;
result->blocksperrow = blocksperrow; result->blocksperrow = blocksperrow;
result->maxaccess = maxaccess; result->maxaccess = maxaccess;
result->pre_zero = pre_zero; result->pre_zero = pre_zero;
result->b_s_open = FALSE; /* no associated backing-store object */ result->b_s_open = FALSE; /* no associated backing-store object */
result->next = mem->virt_barray_list; /* add to list of virtual arrays */ result->next = mem->virt_barray_list; /* add to list of virtual arrays */
mem->virt_barray_list = result; mem->virt_barray_list = result;
@@ -631,26 +630,26 @@ 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 */
space_per_minheight += (long) sptr->maxaccess * space_per_minheight += (long) sptr->maxaccess *
(long) sptr->samplesperrow * SIZEOF(JSAMPLE); (long) sptr->samplesperrow * sizeof(JSAMPLE);
maximum_space += (long) sptr->rows_in_array * maximum_space += (long) sptr->rows_in_array *
(long) sptr->samplesperrow * SIZEOF(JSAMPLE); (long) sptr->samplesperrow * sizeof(JSAMPLE);
} }
} }
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 */
space_per_minheight += (long) bptr->maxaccess * space_per_minheight += (long) bptr->maxaccess *
(long) bptr->blocksperrow * SIZEOF(JBLOCK); (long) bptr->blocksperrow * sizeof(JBLOCK);
maximum_space += (long) bptr->rows_in_array * maximum_space += (long) bptr->rows_in_array *
(long) bptr->blocksperrow * SIZEOF(JBLOCK); (long) bptr->blocksperrow * sizeof(JBLOCK);
} }
} }
if (space_per_minheight <= 0) if (space_per_minheight <= 0)
return; /* no unrealized arrays, no work */ return; /* no unrealized arrays, no work */
/* Determine amount of memory to actually use; this is system-dependent. */ /* Determine amount of memory to actually use; this is system-dependent. */
avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space, avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
mem->total_space_allocated); mem->total_space_allocated);
/* If the maximum space needed is available, make all the buffers full /* If the maximum space needed is available, make all the buffers full
* height; otherwise parcel it out with the same number of minheights * height; otherwise parcel it out with the same number of minheights
@@ -673,19 +672,19 @@ realize_virt_arrays (j_common_ptr cinfo)
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,
sptr->samplesperrow, sptr->rows_in_mem); sptr->samplesperrow, sptr->rows_in_mem);
sptr->rowsperchunk = mem->last_rowsperchunk; sptr->rowsperchunk = mem->last_rowsperchunk;
sptr->cur_start_row = 0; sptr->cur_start_row = 0;
sptr->first_undef_row = 0; sptr->first_undef_row = 0;
@@ -697,19 +696,19 @@ realize_virt_arrays (j_common_ptr cinfo)
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,
bptr->blocksperrow, bptr->rows_in_mem); bptr->blocksperrow, bptr->rows_in_mem);
bptr->rowsperchunk = mem->last_rowsperchunk; bptr->rowsperchunk = mem->last_rowsperchunk;
bptr->cur_start_row = 0; bptr->cur_start_row = 0;
bptr->first_undef_row = 0; bptr->first_undef_row = 0;
@@ -725,7 +724,7 @@ do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
{ {
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) {
@@ -736,17 +735,17 @@ do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
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 FAR *) 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 FAR *) 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;
} }
} }
@@ -758,7 +757,7 @@ do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
{ {
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) {
@@ -769,17 +768,17 @@ do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
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 FAR *) 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 FAR *) 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;
} }
} }
@@ -787,8 +786,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. */
@@ -826,7 +825,7 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
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.
@@ -841,25 +840,25 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
*/ */
if (ptr->first_undef_row < end_row) { if (ptr->first_undef_row < end_row) {
if (ptr->first_undef_row < start_row) { if (ptr->first_undef_row < start_row) {
if (writable) /* writer skipped over a section of array */ if (writable) /* writer skipped over a section of array */
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
undef_row = start_row; /* but reader is allowed to read ahead */ undef_row = start_row; /* but reader is allowed to read ahead */
} else { } else {
undef_row = ptr->first_undef_row; undef_row = ptr->first_undef_row;
} }
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 FAR *) 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);
} }
} }
/* Flag the buffer dirty if caller will write in it */ /* Flag the buffer dirty if caller will write in it */
@@ -872,8 +871,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. */
@@ -911,7 +910,7 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
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.
@@ -926,25 +925,25 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
*/ */
if (ptr->first_undef_row < end_row) { if (ptr->first_undef_row < end_row) {
if (ptr->first_undef_row < start_row) { if (ptr->first_undef_row < start_row) {
if (writable) /* writer skipped over a section of array */ if (writable) /* writer skipped over a section of array */
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
undef_row = start_row; /* but reader is allowed to read ahead */ undef_row = start_row; /* but reader is allowed to read ahead */
} else { } else {
undef_row = ptr->first_undef_row; undef_row = ptr->first_undef_row;
} }
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 FAR *) 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);
} }
} }
/* Flag the buffer dirty if caller will write in it */ /* Flag the buffer dirty if caller will write in it */
@@ -968,7 +967,7 @@ free_pool (j_common_ptr cinfo, int pool_id)
size_t space_freed; size_t space_freed;
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 */
#ifdef MEM_STATS #ifdef MEM_STATS
if (cinfo->err->trace_level > 1) if (cinfo->err->trace_level > 1)
@@ -981,16 +980,16 @@ free_pool (j_common_ptr cinfo, int pool_id)
jvirt_barray_ptr bptr; jvirt_barray_ptr bptr;
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;
@@ -1003,9 +1002,9 @@ free_pool (j_common_ptr cinfo, int pool_id)
while (lhdr_ptr != NULL) { while (lhdr_ptr != NULL) {
large_pool_ptr next_lhdr_ptr = lhdr_ptr->next; large_pool_ptr next_lhdr_ptr = lhdr_ptr->next;
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 FAR *) 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;
} }
@@ -1017,8 +1016,8 @@ 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;
@@ -1045,10 +1044,10 @@ self_destruct (j_common_ptr cinfo)
} }
/* 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 */
} }
@@ -1065,10 +1064,10 @@ jinit_memory_mgr (j_common_ptr cinfo)
int pool; int pool;
size_t test_mac; size_t test_mac;
cinfo->mem = NULL; /* for safety if init fails */ cinfo->mem = NULL; /* for safety if init fails */
/* Check for configuration errors. /* Check for configuration errors.
* SIZEOF(ALIGN_TYPE) should be a power of 2; otherwise, it probably * sizeof(ALIGN_TYPE) should be a power of 2; otherwise, it probably
* doesn't reflect any real hardware alignment requirement. * doesn't reflect any real hardware alignment requirement.
* The test is a little tricky: for X>0, X and X-1 have no one-bits * The test is a little tricky: for X>0, X and X-1 have no one-bits
* 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.
@@ -1089,10 +1088,10 @@ jinit_memory_mgr (j_common_ptr cinfo)
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 */
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0); ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
} }
@@ -1122,7 +1121,7 @@ jinit_memory_mgr (j_common_ptr cinfo)
mem->virt_sarray_list = NULL; mem->virt_sarray_list = NULL;
mem->virt_barray_list = NULL; mem->virt_barray_list = NULL;
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;
@@ -1140,9 +1139,9 @@ jinit_memory_mgr (j_common_ptr cinfo)
char ch = 'x'; char ch = 'x';
if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) { if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
if (ch == 'm' || ch == 'M') if (ch == 'm' || ch == 'M')
max_to_use *= 1000L; max_to_use *= 1000L;
mem->pub.max_memory_to_use = max_to_use * 1000L; mem->pub.max_memory_to_use = max_to_use * 1000L;
} }
} }
} }

View File

@@ -1,8 +1,10 @@
/* /*
* jmemnobs.c * jmemnobs.c
* *
* 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.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code and
* information relevant to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file provides a really simple implementation of the system- * This file provides a really simple implementation of the system-
@@ -18,11 +20,11 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#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 HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */ #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
extern void * malloc JPP((size_t size)); extern void * malloc (size_t size);
extern void free JPP((void *ptr)); extern void free (void *ptr);
#endif #endif
@@ -46,19 +48,16 @@ jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
/* /*
* "Large" objects are treated the same as "small" ones. * "Large" objects are treated the same as "small" ones.
* NB: although we include FAR keywords in the routine declarations,
* this file won't actually work in 80x86 small/medium model; at least,
* you probably won't be able to process useful-size images in only 64KB.
*/ */
GLOBAL(void FAR *) GLOBAL(void *)
jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
{ {
return (void FAR *) malloc(sizeofobject); return (void *) malloc(sizeofobject);
} }
GLOBAL(void) GLOBAL(void)
jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) jpeg_free_large (j_common_ptr cinfo, void * object, size_t sizeofobject)
{ {
free(object); free(object);
} }
@@ -71,7 +70,7 @@ jpeg_free_large (j_common_ptr cinfo, void FAR * 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)
{ {
return max_bytes_needed; return max_bytes_needed;
} }
@@ -85,7 +84,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);
} }
@@ -99,7 +98,7 @@ 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)

107
jmemsys.h
View File

@@ -1,8 +1,10 @@
/* /*
* jmemsys.h * jmemsys.h
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1992-1997, Thomas G. Lane. * Copyright (C) 1992-1997, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code and
* information relevant to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This include file defines the interface between the system-independent * This include file defines the interface between the system-independent
@@ -14,25 +16,10 @@
* in the IJG distribution. You may need to modify it if you write a * in the IJG distribution. You may need to modify it if you write a
* custom memory manager. If system-dependent changes are needed in * custom memory manager. If system-dependent changes are needed in
* this file, the best method is to #ifdef them based on a configuration * this file, the best method is to #ifdef them based on a configuration
* symbol supplied in jconfig.h, as we have done with USE_MSDOS_MEMMGR * symbol supplied in jconfig.h.
* and USE_MAC_MEMMGR.
*/ */
/* Short forms of external names for systems with brain-damaged linkers. */
#ifdef NEED_SHORT_EXTERNAL_NAMES
#define jpeg_get_small jGetSmall
#define jpeg_free_small jFreeSmall
#define jpeg_get_large jGetLarge
#define jpeg_free_large jFreeLarge
#define jpeg_mem_available jMemAvail
#define jpeg_open_backing_store jOpenBackStore
#define jpeg_mem_init jMemInit
#define jpeg_mem_term jMemTerm
#endif /* NEED_SHORT_EXTERNAL_NAMES */
/* /*
* These two functions are used to allocate and release small chunks of * These two functions are used to allocate and release small chunks of
* memory. (Typically the total amount requested through jpeg_get_small is * memory. (Typically the total amount requested through jpeg_get_small is
@@ -41,40 +28,36 @@
* and free; in particular, jpeg_get_small must return NULL on failure. * and free; in particular, jpeg_get_small must return NULL on failure.
* On most systems, these ARE malloc and free. jpeg_free_small is passed the * On most systems, these ARE malloc and free. jpeg_free_small is passed the
* size of the object being freed, just in case it's needed. * size of the object being freed, just in case it's needed.
* On an 80x86 machine using small-data memory model, these manage near heap.
*/ */
EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject)); EXTERN(void *) jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject);
EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object, EXTERN(void) jpeg_free_small (j_common_ptr cinfo, void * object,
size_t sizeofobject)); size_t sizeofobject);
/* /*
* These two functions are used to allocate and release large chunks of * These two functions are used to allocate and release large chunks of
* memory (up to the total free space designated by jpeg_mem_available). * memory (up to the total free space designated by jpeg_mem_available).
* The interface is the same as above, except that on an 80x86 machine, * These are identical to the jpeg_get/free_small routines; but we keep them
* far pointers are used. On most other machines these are identical to * separate anyway, in case a different allocation strategy is desirable for
* the jpeg_get/free_small routines; but we keep them separate anyway, * large chunks.
* in case a different allocation strategy is desirable for large chunks.
*/ */
EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo, EXTERN(void *) jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject);
size_t sizeofobject)); EXTERN(void) jpeg_free_large (j_common_ptr cinfo, void * object,
EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object, size_t sizeofobject);
size_t sizeofobject));
/* /*
* The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may * The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
* be requested in a single call to jpeg_get_large (and jpeg_get_small for that * be requested in a single call to jpeg_get_large (and jpeg_get_small for that
* matter, but that case should never come into play). This macro is needed * matter, but that case should never come into play). This macro was needed
* to model the 64Kb-segment-size limit of far addressing on 80x86 machines. * to model the 64Kb-segment-size limit of far addressing on 80x86 machines.
* On those machines, we expect that jconfig.h will provide a proper value. * On machines with flat address spaces, any large constant may be used.
* On machines with 32-bit flat address spaces, any large constant may be used.
* *
* NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type * NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type
* size_t and will be a multiple of sizeof(align_type). * size_t and will be a multiple of sizeof(align_type).
*/ */
#ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */ #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
#define MAX_ALLOC_CHUNK 1000000000L #define MAX_ALLOC_CHUNK 1000000000L
#endif #endif
@@ -100,10 +83,9 @@ EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * 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 JPP((j_common_ptr cinfo, EXTERN(size_t) jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed,
size_t min_bytes_needed, size_t max_bytes_needed,
size_t max_bytes_needed, size_t already_allocated);
size_t already_allocated));
/* /*
@@ -113,23 +95,23 @@ EXTERN(size_t) jpeg_mem_available JPP((j_common_ptr cinfo,
* are private to the system-dependent backing store routines. * are private to the system-dependent backing store routines.
*/ */
#define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */ #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
#ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */ #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
typedef unsigned short XMSH; /* type of extended-memory handles */ typedef unsigned short XMSH; /* type of extended-memory handles */
typedef unsigned short EMSH; /* type of expanded-memory handles */ typedef unsigned short EMSH; /* type of expanded-memory handles */
typedef union { typedef union {
short file_handle; /* DOS file handle if it's a temp file */ short file_handle; /* DOS file handle if it's a temp file */
XMSH xms_handle; /* handle if it's a chunk of XMS */ XMSH xms_handle; /* handle if it's a chunk of XMS */
EMSH ems_handle; /* handle if it's a chunk of EMS */ EMSH ems_handle; /* handle if it's a chunk of EMS */
} handle_union; } handle_union;
#endif /* USE_MSDOS_MEMMGR */ #endif /* USE_MSDOS_MEMMGR */
#ifdef USE_MAC_MEMMGR /* Mac-specific junk */ #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
#include <Files.h> #include <Files.h>
#endif /* USE_MAC_MEMMGR */ #endif /* USE_MAC_MEMMGR */
@@ -138,31 +120,28 @@ typedef struct backing_store_struct * backing_store_ptr;
typedef struct backing_store_struct { typedef struct backing_store_struct {
/* Methods for reading/writing/closing this backing-store object */ /* Methods for reading/writing/closing this backing-store object */
JMETHOD(void, read_backing_store, (j_common_ptr cinfo, void (*read_backing_store) (j_common_ptr cinfo, backing_store_ptr info,
backing_store_ptr info, void * buffer_address, long file_offset,
void FAR * buffer_address, long byte_count);
long file_offset, long byte_count)); void (*write_backing_store) (j_common_ptr cinfo, backing_store_ptr info,
JMETHOD(void, write_backing_store, (j_common_ptr cinfo, void * buffer_address, long file_offset,
backing_store_ptr info, long byte_count);
void FAR * buffer_address, void (*close_backing_store) (j_common_ptr cinfo, backing_store_ptr info);
long file_offset, long byte_count));
JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
backing_store_ptr info));
/* Private fields for system-dependent backing-store management */ /* Private fields for system-dependent backing-store management */
#ifdef USE_MSDOS_MEMMGR #ifdef USE_MSDOS_MEMMGR
/* For the MS-DOS manager (jmemdos.c), we need: */ /* For the MS-DOS manager (jmemdos.c), we need: */
handle_union handle; /* reference to backing-store storage object */ handle_union handle; /* reference to backing-store storage object */
char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */ char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
#else #else
#ifdef USE_MAC_MEMMGR #ifdef USE_MAC_MEMMGR
/* For the Mac manager (jmemmac.c), we need: */ /* For the Mac manager (jmemmac.c), we need: */
short temp_file; /* file reference number to temp file */ short temp_file; /* file reference number to temp file */
FSSpec tempSpec; /* the FSSpec for the temp file */ FSSpec tempSpec; /* the FSSpec for the temp file */
char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */ char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
#else #else
/* For a typical implementation with temp files, we need: */ /* For a typical implementation with temp files, we need: */
FILE * temp_file; /* stdio reference to temp file */ FILE * temp_file; /* stdio reference to temp file */
char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */ char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
#endif #endif
#endif #endif
@@ -177,9 +156,9 @@ typedef struct backing_store_struct {
* just take an error exit.) * just take an error exit.)
*/ */
EXTERN(void) jpeg_open_backing_store JPP((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);
/* /*
@@ -194,5 +173,5 @@ EXTERN(void) jpeg_open_backing_store JPP((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 JPP((j_common_ptr cinfo)); EXTERN(long) jpeg_mem_init (j_common_ptr cinfo);
EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo)); EXTERN(void) jpeg_mem_term (j_common_ptr cinfo);

View File

@@ -3,8 +3,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) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009, 2011, D. R. Commander. * Copyright (C) 2009, 2011, 2014, D. R. Commander.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains additional configuration options that customize the * This file contains additional configuration options that customize the
@@ -22,7 +22,7 @@
* We do not support run-time selection of data precision, sorry. * We do not support run-time selection of data precision, sorry.
*/ */
#define BITS_IN_JSAMPLE 8 /* use 8 or 12 */ #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
/* /*
@@ -34,7 +34,7 @@
* bytes of storage, whether actually used in an image or not.) * bytes of storage, whether actually used in an image or not.)
*/ */
#define MAX_COMPONENTS 10 /* maximum number of image components */ #define MAX_COMPONENTS 10 /* maximum number of image components */
/* /*
@@ -72,8 +72,8 @@ typedef char JSAMPLE;
#endif /* HAVE_UNSIGNED_CHAR */ #endif /* HAVE_UNSIGNED_CHAR */
#define MAXJSAMPLE 255 #define MAXJSAMPLE 255
#define CENTERJSAMPLE 128 #define CENTERJSAMPLE 128
#endif /* BITS_IN_JSAMPLE == 8 */ #endif /* BITS_IN_JSAMPLE == 8 */
@@ -86,8 +86,8 @@ 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
#endif /* BITS_IN_JSAMPLE == 12 */ #endif /* BITS_IN_JSAMPLE == 12 */
@@ -153,13 +153,13 @@ typedef unsigned int UINT16;
/* INT16 must hold at least the values -32768..32767. */ /* INT16 must hold at least the values -32768..32767. */
#ifndef XMD_H /* X11/xmd.h correctly defines INT16 */ #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
typedef short INT16; typedef short INT16;
#endif #endif
/* INT32 must hold at least signed 32-bit values. */ /* INT32 must hold at least signed 32-bit values. */
#ifndef XMD_H /* X11/xmd.h correctly defines INT32 */ #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
typedef long INT32; typedef long INT32;
#endif #endif
@@ -183,42 +183,13 @@ typedef unsigned int JDIMENSION;
*/ */
/* a function called through method pointers: */ /* a function called through method pointers: */
#define METHODDEF(type) static type #define METHODDEF(type) static type
/* a function used only in its module: */ /* a function used only in its module: */
#define LOCAL(type) static type #define LOCAL(type) static type
/* a function referenced thru EXTERNs: */ /* a function referenced thru EXTERNs: */
#define GLOBAL(type) type #define GLOBAL(type) type
/* a reference to a GLOBAL function: */ /* a reference to a GLOBAL function: */
#define EXTERN(type) extern type #define EXTERN(type) extern type
/* This macro is used to declare a "method", that is, a function pointer.
* We want to supply prototype parameters if the compiler can cope.
* Note that the arglist parameter must be parenthesized!
* Again, you can customize this if you need special linkage keywords.
*/
#ifdef HAVE_PROTOTYPES
#define JMETHOD(type,methodname,arglist) type (*methodname) arglist
#else
#define JMETHOD(type,methodname,arglist) type (*methodname) ()
#endif
/* Here is the pseudo-keyword for declaring pointers that must be "far"
* on 80x86 machines. Most of the specialized coding for 80x86 is handled
* by just saying "FAR *" where such a pointer is needed. In a few places
* explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
*/
#ifdef NEED_FAR_POINTERS
#ifndef FAR
#define FAR far
#endif
#else
#undef FAR
#define FAR
#endif
/* /*
@@ -231,11 +202,11 @@ typedef unsigned int JDIMENSION;
#ifndef HAVE_BOOLEAN #ifndef HAVE_BOOLEAN
typedef int boolean; typedef int boolean;
#endif #endif
#ifndef FALSE /* in case these macros already exist */ #ifndef FALSE /* in case these macros already exist */
#define FALSE 0 /* values of boolean */ #define FALSE 0 /* values of boolean */
#endif #endif
#ifndef TRUE #ifndef TRUE
#define TRUE 1 #define TRUE 1
#endif #endif
@@ -263,15 +234,15 @@ typedef int boolean;
/* Capability options common to encoder and decoder: */ /* Capability options common to encoder and decoder: */
#define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */ #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
#define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */ #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
#define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */ #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
/* Encoder capability options: */ /* Encoder capability options: */
#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
#define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */ #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
/* Note: if you selected 12-bit data precision, it is dangerous to turn off /* Note: if you selected 12-bit data precision, it is dangerous to turn off
* ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit * ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit
* precision, so jchuff.c normally uses entropy optimization to compute * precision, so jchuff.c normally uses entropy optimization to compute
@@ -285,39 +256,45 @@ typedef int boolean;
/* Decoder capability options: */ /* Decoder capability options: */
#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
#define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
#define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */ #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */ #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */ #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
#undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */ #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
#define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */ #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
#define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */ #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
#define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */ #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
/* more capability options later, no doubt */ /* more capability options later, no doubt */
/* /*
* Ordering of RGB data in scanlines passed to or from the application. * The RGB_RED, RGB_GREEN, RGB_BLUE, and RGB_PIXELSIZE macros are a vestigial
* If your application wants to deal with data in the order B,G,R, just * feature of libjpeg. The idea was that, if an application developer needed
* change these macros. You can also deal with formats such as R,G,B,X * to compress from/decompress to a BGR/BGRX/RGBX/XBGR/XRGB buffer, they could
* (one extra byte per pixel) by changing RGB_PIXELSIZE. Note that changing * change these macros, rebuild libjpeg, and link their application statically
* the offsets will also change the order in which colormap data is organized. * with it. In reality, few people ever did this, because there were some
* RESTRICTIONS: * severe restrictions involved (cjpeg and djpeg no longer worked properly,
* 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats. * compressing/decompressing RGB JPEGs no longer worked properly, and the color
* 2. These macros only affect RGB<=>YCbCr color conversion, so they are not * quantizer wouldn't work with pixel sizes other than 3.) Further, since all
* useful if you are using JPEG color spaces other than YCbCr or grayscale. * of the O/S-supplied versions of libjpeg were built with the default values
* 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE * of RGB_RED, RGB_GREEN, RGB_BLUE, and RGB_PIXELSIZE, many applications have
* is not 3 (they don't understand about dummy color components!). So you * come to regard these values as immutable.
* can't use color quantization if you change that value. *
* The libjpeg-turbo colorspace extensions provide a much cleaner way of
* compressing from/decompressing to buffers with arbitrary component orders
* and pixel sizes. Thus, we do not support changing the values of RGB_RED,
* RGB_GREEN, RGB_BLUE, or RGB_PIXELSIZE. In addition to the restrictions
* listed above, changing these values will also break the SIMD extensions and
* the regression tests.
*/ */
#define RGB_RED 0 /* Offset of Red in an RGB scanline element */ #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
#define RGB_GREEN 1 /* Offset of Green */ #define RGB_GREEN 1 /* Offset of Green */
#define RGB_BLUE 2 /* Offset of Blue */ #define RGB_BLUE 2 /* Offset of Blue */
#define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */ #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
#define JPEG_NUMCS 16 #define JPEG_NUMCS 17
#define EXT_RGB_RED 0 #define EXT_RGB_RED 0
#define EXT_RGB_GREEN 1 #define EXT_RGB_GREEN 1
@@ -352,25 +329,29 @@ typedef int boolean;
static const int rgb_red[JPEG_NUMCS] = { static const int rgb_red[JPEG_NUMCS] = {
-1, -1, RGB_RED, -1, -1, -1, EXT_RGB_RED, EXT_RGBX_RED, -1, -1, RGB_RED, -1, -1, -1, EXT_RGB_RED, EXT_RGBX_RED,
EXT_BGR_RED, EXT_BGRX_RED, EXT_XBGR_RED, EXT_XRGB_RED, EXT_BGR_RED, EXT_BGRX_RED, EXT_XBGR_RED, EXT_XRGB_RED,
EXT_RGBX_RED, EXT_BGRX_RED, EXT_XBGR_RED, EXT_XRGB_RED EXT_RGBX_RED, EXT_BGRX_RED, EXT_XBGR_RED, EXT_XRGB_RED,
-1
}; };
static const int rgb_green[JPEG_NUMCS] = { static const int rgb_green[JPEG_NUMCS] = {
-1, -1, RGB_GREEN, -1, -1, -1, EXT_RGB_GREEN, EXT_RGBX_GREEN, -1, -1, RGB_GREEN, -1, -1, -1, EXT_RGB_GREEN, EXT_RGBX_GREEN,
EXT_BGR_GREEN, EXT_BGRX_GREEN, EXT_XBGR_GREEN, EXT_XRGB_GREEN, EXT_BGR_GREEN, EXT_BGRX_GREEN, EXT_XBGR_GREEN, EXT_XRGB_GREEN,
EXT_RGBX_GREEN, EXT_BGRX_GREEN, EXT_XBGR_GREEN, EXT_XRGB_GREEN EXT_RGBX_GREEN, EXT_BGRX_GREEN, EXT_XBGR_GREEN, EXT_XRGB_GREEN,
-1
}; };
static const int rgb_blue[JPEG_NUMCS] = { static const int rgb_blue[JPEG_NUMCS] = {
-1, -1, RGB_BLUE, -1, -1, -1, EXT_RGB_BLUE, EXT_RGBX_BLUE, -1, -1, RGB_BLUE, -1, -1, -1, EXT_RGB_BLUE, EXT_RGBX_BLUE,
EXT_BGR_BLUE, EXT_BGRX_BLUE, EXT_XBGR_BLUE, EXT_XRGB_BLUE, EXT_BGR_BLUE, EXT_BGRX_BLUE, EXT_XBGR_BLUE, EXT_XRGB_BLUE,
EXT_RGBX_BLUE, EXT_BGRX_BLUE, EXT_XBGR_BLUE, EXT_XRGB_BLUE EXT_RGBX_BLUE, EXT_BGRX_BLUE, EXT_XBGR_BLUE, EXT_XRGB_BLUE,
-1
}; };
static const int rgb_pixelsize[JPEG_NUMCS] = { static const int rgb_pixelsize[JPEG_NUMCS] = {
-1, -1, RGB_PIXELSIZE, -1, -1, -1, EXT_RGB_PIXELSIZE, EXT_RGBX_PIXELSIZE, -1, -1, RGB_PIXELSIZE, -1, -1, -1, EXT_RGB_PIXELSIZE, EXT_RGBX_PIXELSIZE,
EXT_BGR_PIXELSIZE, EXT_BGRX_PIXELSIZE, EXT_XBGR_PIXELSIZE, EXT_XRGB_PIXELSIZE, EXT_BGR_PIXELSIZE, EXT_BGRX_PIXELSIZE, EXT_XBGR_PIXELSIZE, EXT_XRGB_PIXELSIZE,
EXT_RGBX_PIXELSIZE, EXT_BGRX_PIXELSIZE, EXT_XBGR_PIXELSIZE, EXT_XRGB_PIXELSIZE EXT_RGBX_PIXELSIZE, EXT_BGRX_PIXELSIZE, EXT_XBGR_PIXELSIZE, EXT_XRGB_PIXELSIZE,
-1
}; };
/* Definitions for speed-related optimizations. */ /* Definitions for speed-related optimizations. */
@@ -382,7 +363,7 @@ static const int rgb_pixelsize[JPEG_NUMCS] = {
#ifndef MULTIPLIER #ifndef MULTIPLIER
#ifndef WITH_SIMD #ifndef WITH_SIMD
#define MULTIPLIER int /* type for fastest integer multiply */ #define MULTIPLIER int /* type for fastest integer multiply */
#else #else
#define MULTIPLIER short /* prefer 16-bit with SIMD for parellelism */ #define MULTIPLIER short /* prefer 16-bit with SIMD for parellelism */
#endif #endif
@@ -392,17 +373,10 @@ static const int rgb_pixelsize[JPEG_NUMCS] = {
/* FAST_FLOAT should be either float or double, whichever is done faster /* FAST_FLOAT should be either float or double, whichever is done faster
* by your compiler. (Note that this type is only used in the floating point * by your compiler. (Note that this type is only used in the floating point
* DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.) * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.)
* Typically, float is faster in ANSI C compilers, while double is faster in
* pre-ANSI compilers (because they insist on converting to double anyway).
* The code below therefore chooses float if we have ANSI-style prototypes.
*/ */
#ifndef FAST_FLOAT #ifndef FAST_FLOAT
#ifdef HAVE_PROTOTYPES
#define FAST_FLOAT float #define FAST_FLOAT float
#else
#define FAST_FLOAT double
#endif
#endif #endif
#endif /* JPEG_INTERNAL_OPTIONS */ #endif /* JPEG_INTERNAL_OPTIONS */

390
jpegint.h
View File

@@ -1,11 +1,13 @@
/* /*
* jpegint.h * jpegint.h
* *
* 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.
* Modified 1997-2009 by Guido Vollbeding. * Modified 1997-2009 by Guido Vollbeding.
* It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* mozjpeg Modifications: * mozjpeg Modifications:
* Copyright (C) 2014, Mozilla Corporation. * Copyright (C) 2014, Mozilla Corporation.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file provides common declarations for the various JPEG modules. * This file provides common declarations for the various JPEG modules.
@@ -16,123 +18,117 @@
/* Declarations for both compression & decompression */ /* Declarations for both compression & decompression */
typedef enum { /* Operating modes for buffer controllers */ typedef enum { /* Operating modes for buffer controllers */
JBUF_PASS_THRU, /* Plain stripwise operation */ JBUF_PASS_THRU, /* Plain stripwise operation */
/* Remaining modes require a full-image buffer to have been created */ /* Remaining modes require a full-image buffer to have been created */
JBUF_SAVE_SOURCE, /* Run source subobject only, save output */ JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */ JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
JBUF_SAVE_AND_PASS, /* Run both subobjects, save output */ JBUF_SAVE_AND_PASS, /* Run both subobjects, save output */
JBUF_REQUANT /* Requantize */ JBUF_REQUANT /* Requantize */
} J_BUF_MODE; } J_BUF_MODE;
/* Values of global_state field (jdapi.c has some dependencies on ordering!) */ /* Values of global_state field (jdapi.c has some dependencies on ordering!) */
#define CSTATE_START 100 /* after create_compress */ #define CSTATE_START 100 /* after create_compress */
#define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */ #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
#define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */ #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
#define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */ #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
#define DSTATE_START 200 /* after create_decompress */ #define DSTATE_START 200 /* after create_decompress */
#define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */ #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
#define DSTATE_READY 202 /* found SOS, ready for start_decompress */ #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
#define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/ #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
#define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */ #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
#define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */ #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
#define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */ #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
#define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */ #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
#define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */ #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
#define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */ #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
#define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */ #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
/* Declarations for compression modules */ /* Declarations for compression modules */
/* Master control module */ /* Master control module */
struct jpeg_comp_master { struct jpeg_comp_master {
JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo)); void (*prepare_for_pass) (j_compress_ptr cinfo);
JMETHOD(void, pass_startup, (j_compress_ptr cinfo)); void (*pass_startup) (j_compress_ptr cinfo);
JMETHOD(void, finish_pass, (j_compress_ptr cinfo)); void (*finish_pass) (j_compress_ptr cinfo);
/* State variables made visible to other modules */ /* State variables made visible to other modules */
boolean call_pass_startup; /* True if pass_startup must be called */ boolean call_pass_startup; /* True if pass_startup must be called */
boolean is_last_pass; /* True during last pass */ boolean is_last_pass; /* True during last pass */
}; };
/* Main buffer control (downsampled-data buffer) */ /* Main buffer control (downsampled-data buffer) */
struct jpeg_c_main_controller { struct jpeg_c_main_controller {
JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); void (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode);
JMETHOD(void, process_data, (j_compress_ptr cinfo, void (*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));
}; };
/* Compression preprocessing (downsampling input buffer control) */ /* Compression preprocessing (downsampling input buffer control) */
struct jpeg_c_prep_controller { struct jpeg_c_prep_controller {
JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); void (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode);
JMETHOD(void, pre_process_data, (j_compress_ptr cinfo, void (*pre_process_data) (j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail,
JDIMENSION *in_row_ctr, JSAMPIMAGE output_buf,
JDIMENSION in_rows_avail, JDIMENSION *out_row_group_ctr,
JSAMPIMAGE output_buf, JDIMENSION out_row_groups_avail);
JDIMENSION *out_row_group_ctr,
JDIMENSION out_row_groups_avail));
}; };
/* Coefficient buffer control */ /* Coefficient buffer control */
struct jpeg_c_coef_controller { struct jpeg_c_coef_controller {
JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); void (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode);
JMETHOD(boolean, compress_data, (j_compress_ptr cinfo, boolean (*compress_data) (j_compress_ptr cinfo, JSAMPIMAGE input_buf);
JSAMPIMAGE input_buf));
}; };
/* Colorspace conversion */ /* Colorspace conversion */
struct jpeg_color_converter { struct jpeg_color_converter {
JMETHOD(void, start_pass, (j_compress_ptr cinfo)); void (*start_pass) (j_compress_ptr cinfo);
JMETHOD(void, color_convert, (j_compress_ptr cinfo, void (*color_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);
}; };
/* Downsampling */ /* Downsampling */
struct jpeg_downsampler { struct jpeg_downsampler {
JMETHOD(void, start_pass, (j_compress_ptr cinfo)); void (*start_pass) (j_compress_ptr cinfo);
JMETHOD(void, downsample, (j_compress_ptr cinfo, void (*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));
boolean need_context_rows; /* TRUE if need rows above & below */ boolean need_context_rows; /* TRUE if need rows above & below */
}; };
/* Forward DCT (also controls coefficient quantization) */ /* Forward DCT (also controls coefficient quantization) */
struct jpeg_forward_dct { struct jpeg_forward_dct {
JMETHOD(void, start_pass, (j_compress_ptr cinfo)); void (*start_pass) (j_compress_ptr cinfo);
/* perhaps this should be an array??? */ /* perhaps this should be an array??? */
JMETHOD(void, forward_DCT, (j_compress_ptr cinfo, void (*forward_DCT) (j_compress_ptr cinfo, jpeg_component_info * compptr,
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, JBLOCKROW dst);
JDIMENSION num_blocks, JBLOCKROW dst));
}; };
/* Entropy encoding */ /* Entropy encoding */
struct jpeg_entropy_encoder { struct jpeg_entropy_encoder {
JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics)); void (*start_pass) (j_compress_ptr cinfo, boolean gather_statistics);
JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data)); boolean (*encode_mcu) (j_compress_ptr cinfo, JBLOCKROW *MCU_data);
JMETHOD(void, finish_pass, (j_compress_ptr cinfo)); void (*finish_pass) (j_compress_ptr cinfo);
}; };
/* Marker writing */ /* Marker writing */
struct jpeg_marker_writer { struct jpeg_marker_writer {
JMETHOD(void, write_file_header, (j_compress_ptr cinfo)); void (*write_file_header) (j_compress_ptr cinfo);
JMETHOD(void, write_frame_header, (j_compress_ptr cinfo)); void (*write_frame_header) (j_compress_ptr cinfo);
JMETHOD(void, write_scan_header, (j_compress_ptr cinfo)); void (*write_scan_header) (j_compress_ptr cinfo);
JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo)); void (*write_file_trailer) (j_compress_ptr cinfo);
JMETHOD(void, write_tables_only, (j_compress_ptr cinfo)); void (*write_tables_only) (j_compress_ptr cinfo);
/* These routines are exported to allow insertion of extra markers */ /* These routines are exported to allow insertion of extra markers */
/* Probably only COM and APPn markers should be written this way */ /* Probably only COM and APPn markers should be written this way */
JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker, void (*write_marker_header) (j_compress_ptr cinfo, int marker,
unsigned int datalen)); unsigned int datalen);
JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val)); void (*write_marker_byte) (j_compress_ptr cinfo, int val);
}; };
@@ -140,138 +136,130 @@ struct jpeg_marker_writer {
/* Master control module */ /* Master control module */
struct jpeg_decomp_master { struct jpeg_decomp_master {
JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo)); void (*prepare_for_output_pass) (j_decompress_ptr cinfo);
JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo)); void (*finish_output_pass) (j_decompress_ptr cinfo);
/* State variables made visible to other modules */ /* State variables made visible to other modules */
boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */ boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
}; };
/* Input control module */ /* Input control module */
struct jpeg_input_controller { struct jpeg_input_controller {
JMETHOD(int, consume_input, (j_decompress_ptr cinfo)); int (*consume_input) (j_decompress_ptr cinfo);
JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo)); void (*reset_input_controller) (j_decompress_ptr cinfo);
JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo)); void (*start_input_pass) (j_decompress_ptr cinfo);
JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo)); void (*finish_input_pass) (j_decompress_ptr cinfo);
/* State variables made visible to other modules */ /* State variables made visible to other modules */
boolean has_multiple_scans; /* True if file has multiple scans */ boolean has_multiple_scans; /* True if file has multiple scans */
boolean eoi_reached; /* True when EOI has been consumed */ boolean eoi_reached; /* True when EOI has been consumed */
}; };
/* Main buffer control (downsampled-data buffer) */ /* Main buffer control (downsampled-data buffer) */
struct jpeg_d_main_controller { struct jpeg_d_main_controller {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); void (*start_pass) (j_decompress_ptr cinfo, J_BUF_MODE pass_mode);
JMETHOD(void, process_data, (j_decompress_ptr cinfo, void (*process_data) (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));
}; };
/* Coefficient buffer control */ /* Coefficient buffer control */
struct jpeg_d_coef_controller { struct jpeg_d_coef_controller {
JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo)); void (*start_input_pass) (j_decompress_ptr cinfo);
JMETHOD(int, consume_data, (j_decompress_ptr cinfo)); int (*consume_data) (j_decompress_ptr cinfo);
JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo)); void (*start_output_pass) (j_decompress_ptr cinfo);
JMETHOD(int, decompress_data, (j_decompress_ptr cinfo, int (*decompress_data) (j_decompress_ptr cinfo, JSAMPIMAGE output_buf);
JSAMPIMAGE output_buf));
/* Pointer to array of coefficient virtual arrays, or NULL if none */ /* Pointer to array of coefficient virtual arrays, or NULL if none */
jvirt_barray_ptr *coef_arrays; jvirt_barray_ptr *coef_arrays;
}; };
/* Decompression postprocessing (color quantization buffer control) */ /* Decompression postprocessing (color quantization buffer control) */
struct jpeg_d_post_controller { struct jpeg_d_post_controller {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); void (*start_pass) (j_decompress_ptr cinfo, J_BUF_MODE pass_mode);
JMETHOD(void, post_process_data, (j_decompress_ptr cinfo, void (*post_process_data) (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_rows_avail);
JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail));
}; };
/* Marker reading & parsing */ /* Marker reading & parsing */
struct jpeg_marker_reader { struct jpeg_marker_reader {
JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo)); void (*reset_marker_reader) (j_decompress_ptr cinfo);
/* Read markers until SOS or EOI. /* Read markers until SOS or EOI.
* Returns same codes as are defined for jpeg_consume_input: * Returns same codes as are defined for jpeg_consume_input:
* JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
*/ */
JMETHOD(int, read_markers, (j_decompress_ptr cinfo)); int (*read_markers) (j_decompress_ptr cinfo);
/* Read a restart marker --- exported for use by entropy decoder only */ /* Read a restart marker --- exported for use by entropy decoder only */
jpeg_marker_parser_method read_restart_marker; jpeg_marker_parser_method read_restart_marker;
/* State of marker reader --- nominally internal, but applications /* State of marker reader --- nominally internal, but applications
* supplying COM or APPn handlers might like to know the state. * supplying COM or APPn handlers might like to know the state.
*/ */
boolean saw_SOI; /* found SOI? */ boolean saw_SOI; /* found SOI? */
boolean saw_SOF; /* found SOF? */ boolean saw_SOF; /* found SOF? */
int next_restart_num; /* next restart number expected (0-7) */ int next_restart_num; /* next restart number expected (0-7) */
unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */ unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
}; };
/* Entropy decoding */ /* Entropy decoding */
struct jpeg_entropy_decoder { struct jpeg_entropy_decoder {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); void (*start_pass) (j_decompress_ptr cinfo);
JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, boolean (*decode_mcu) (j_decompress_ptr cinfo, JBLOCKROW *MCU_data);
JBLOCKROW *MCU_data));
/* This is here to share code between baseline and progressive decoders; */ /* This is here to share code between baseline and progressive decoders; */
/* other modules probably should not use it */ /* other modules probably should not use it */
boolean insufficient_data; /* set TRUE after emitting warning */ boolean insufficient_data; /* set TRUE after emitting warning */
}; };
/* Inverse DCT (also performs dequantization) */ /* Inverse DCT (also performs dequantization) */
typedef JMETHOD(void, inverse_DCT_method_ptr, typedef void (*inverse_DCT_method_ptr) (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);
struct jpeg_inverse_dct { struct jpeg_inverse_dct {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); void (*start_pass) (j_decompress_ptr cinfo);
/* It is useful to allow each component to have a separate IDCT method. */ /* It is useful to allow each component to have a separate IDCT method. */
inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS]; inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
}; };
/* Upsampling (note that upsampler must also call color converter) */ /* Upsampling (note that upsampler must also call color converter) */
struct jpeg_upsampler { struct jpeg_upsampler {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); void (*start_pass) (j_decompress_ptr cinfo);
JMETHOD(void, upsample, (j_decompress_ptr cinfo, void (*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, JSAMPARRAY output_buf,
JDIMENSION in_row_groups_avail, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail));
boolean need_context_rows; /* TRUE if need rows above & below */ boolean need_context_rows; /* TRUE if need rows above & below */
}; };
/* Colorspace conversion */ /* Colorspace conversion */
struct jpeg_color_deconverter { struct jpeg_color_deconverter {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); void (*start_pass) (j_decompress_ptr cinfo);
JMETHOD(void, color_convert, (j_decompress_ptr cinfo, void (*color_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);
}; };
/* Color quantization or color precision reduction */ /* Color quantization or color precision reduction */
struct jpeg_color_quantizer { struct jpeg_color_quantizer {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan)); void (*start_pass) (j_decompress_ptr cinfo, boolean is_pre_scan);
JMETHOD(void, color_quantize, (j_decompress_ptr cinfo, void (*color_quantize) (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY input_buf, JSAMPARRAY output_buf, JSAMPARRAY output_buf, int num_rows);
int num_rows)); void (*finish_pass) (j_decompress_ptr cinfo);
JMETHOD(void, finish_pass, (j_decompress_ptr cinfo)); void (*new_color_map) (j_decompress_ptr cinfo);
JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
}; };
/* 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
@@ -285,109 +273,67 @@ struct jpeg_color_quantizer {
*/ */
#ifdef RIGHT_SHIFT_IS_UNSIGNED #ifdef RIGHT_SHIFT_IS_UNSIGNED
#define SHIFT_TEMPS INT32 shift_temp; #define SHIFT_TEMPS INT32 shift_temp;
#define RIGHT_SHIFT(x,shft) \ #define RIGHT_SHIFT(x,shft) \
((shift_temp = (x)) < 0 ? \ ((shift_temp = (x)) < 0 ? \
(shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \ (shift_temp >> (shft)) | ((~((INT32) 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
/* Short forms of external names for systems with brain-damaged linkers. */
#ifdef NEED_SHORT_EXTERNAL_NAMES
#define jinit_compress_master jICompress
#define jinit_c_master_control jICMaster
#define jinit_c_main_controller jICMainC
#define jinit_c_prep_controller jICPrepC
#define jinit_c_coef_controller jICCoefC
#define jinit_color_converter jICColor
#define jinit_downsampler jIDownsampler
#define jinit_forward_dct jIFDCT
#define jinit_huff_encoder jIHEncoder
#define jinit_phuff_encoder jIPHEncoder
#define jinit_arith_encoder jIAEncoder
#define jinit_marker_writer jIMWriter
#define jinit_master_decompress jIDMaster
#define jinit_d_main_controller jIDMainC
#define jinit_d_coef_controller jIDCoefC
#define jinit_d_post_controller jIDPostC
#define jinit_input_controller jIInCtlr
#define jinit_marker_reader jIMReader
#define jinit_huff_decoder jIHDecoder
#define jinit_phuff_decoder jIPHDecoder
#define jinit_arith_decoder jIADecoder
#define jinit_inverse_dct jIIDCT
#define jinit_upsampler jIUpsampler
#define jinit_color_deconverter jIDColor
#define jinit_1pass_quantizer jI1Quant
#define jinit_2pass_quantizer jI2Quant
#define jinit_merged_upsampler jIMUpsampler
#define jinit_memory_mgr jIMemMgr
#define jdiv_round_up jDivRound
#define jround_up jRound
#define jcopy_sample_rows jCopySamples
#define jcopy_block_row jCopyBlocks
#define jzero_far jZeroFar
#define jpeg_zigzag_order jZIGTable
#define jpeg_natural_order jZAGTable
#define jpeg_aritab jAriTab
#endif /* NEED_SHORT_EXTERNAL_NAMES */
/* Compression module initialization routines */ /* Compression module initialization routines */
EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo)); EXTERN(void) jinit_compress_master (j_compress_ptr cinfo);
EXTERN(void) jinit_c_master_control JPP((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 JPP((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 JPP((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 JPP((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 JPP((j_compress_ptr cinfo)); EXTERN(void) jinit_color_converter (j_compress_ptr cinfo);
EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo)); EXTERN(void) jinit_downsampler (j_compress_ptr cinfo);
EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo)); EXTERN(void) jinit_forward_dct (j_compress_ptr cinfo);
EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo)); EXTERN(void) jinit_huff_encoder (j_compress_ptr cinfo);
EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo)); EXTERN(void) jinit_phuff_encoder (j_compress_ptr cinfo);
EXTERN(void) jinit_arith_encoder JPP((j_compress_ptr cinfo)); EXTERN(void) jinit_arith_encoder (j_compress_ptr cinfo);
EXTERN(void) jinit_marker_writer JPP((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 JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_master_decompress (j_decompress_ptr cinfo);
EXTERN(void) jinit_d_main_controller JPP((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 JPP((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 JPP((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 JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_input_controller (j_decompress_ptr cinfo);
EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_marker_reader (j_decompress_ptr cinfo);
EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_huff_decoder (j_decompress_ptr cinfo);
EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_phuff_decoder (j_decompress_ptr cinfo);
EXTERN(void) jinit_arith_decoder JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_arith_decoder (j_decompress_ptr cinfo);
EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_inverse_dct (j_decompress_ptr cinfo);
EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_upsampler (j_decompress_ptr cinfo);
EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_color_deconverter (j_decompress_ptr cinfo);
EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_1pass_quantizer (j_decompress_ptr cinfo);
EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_2pass_quantizer (j_decompress_ptr cinfo);
EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_merged_upsampler (j_decompress_ptr cinfo);
/* Memory manager initialization */ /* Memory manager initialization */
EXTERN(void) jinit_memory_mgr JPP((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 JPP((long a, long b)); EXTERN(long) jdiv_round_up (long a, long b);
EXTERN(long) jround_up JPP((long a, long b)); EXTERN(long) jround_up (long a, long b);
EXTERN(void) jcopy_sample_rows JPP((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 JPP((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 JPP((void FAR * 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 */
#endif #endif
extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */ extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
@@ -398,7 +344,7 @@ extern const INT32 jpeg_aritab[];
/* Suppress undefined-structure complaints if necessary. */ /* Suppress undefined-structure complaints if necessary. */
#ifdef INCOMPLETE_TYPES_BROKEN #ifdef INCOMPLETE_TYPES_BROKEN
#ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */ #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
struct jvirt_sarray_control { long dummy; }; struct jvirt_sarray_control { long dummy; };
struct jvirt_barray_control { long dummy; }; struct jvirt_barray_control { long dummy; };
#endif #endif

775
jpeglib.h

File diff suppressed because it is too large Load Diff

View File

@@ -15,18 +15,18 @@
* provides some lossless and sort-of-lossless transformations of JPEG data. * provides some lossless and sort-of-lossless transformations of JPEG data.
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include "transupp.h" /* Support routines for jpegtran */ #include "transupp.h" /* Support routines for jpegtran */
#include "jversion.h" /* for version message */ #include "jversion.h" /* for version message */
#include "config.h" #include "jconfigint.h"
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ #ifdef USE_CCOMMAND /* command-line reader for Macintosh */
#ifdef __MWERKS__ #ifdef __MWERKS__
#include <SIOUX.h> /* Metrowerks needs this */ #include <SIOUX.h> /* Metrowerks needs this */
#include <console.h> /* ... and this */ #include <console.h> /* ... and this */
#endif #endif
#ifdef THINK_C #ifdef THINK_C
#include <console.h> /* Think declares it here */ #include <console.h> /* Think declares it here */
#endif #endif
#endif #endif
@@ -40,9 +40,9 @@
*/ */
static const char * progname; /* program name for error messages */ static const char * progname; /* program name for error messages */
static char * outfilename; /* for -outfile switch */ static char * outfilename; /* for -outfile switch */
static JCOPY_OPTION copyoption; /* -copy switch */ static JCOPY_OPTION copyoption; /* -copy switch */
static jpeg_transform_info transformoption; /* image transformation options */ static jpeg_transform_info transformoption; /* image transformation options */
boolean memsrc; /* for -memsrc switch */ boolean memsrc; /* for -memsrc switch */
#define INPUT_BUF_SIZE 4096 #define INPUT_BUF_SIZE 4096
@@ -112,12 +112,12 @@ select_transform (JXFORM_CODE transform)
transformoption.transform = transform; transformoption.transform = transform;
} else { } else {
fprintf(stderr, "%s: can only do one image transformation at a time\n", fprintf(stderr, "%s: can only do one image transformation at a time\n",
progname); progname);
usage(); usage();
} }
#else #else
fprintf(stderr, "%s: sorry, image transformation was not compiled\n", fprintf(stderr, "%s: sorry, image transformation was not compiled\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
} }
@@ -125,7 +125,7 @@ select_transform (JXFORM_CODE transform)
LOCAL(int) LOCAL(int)
parse_switches (j_compress_ptr cinfo, int argc, char **argv, parse_switches (j_compress_ptr cinfo, int argc, char **argv,
int last_file_arg_seen, boolean for_real) int last_file_arg_seen, boolean for_real)
/* Parse optional switches. /* Parse optional switches.
* Returns argv[] index of first file-name argument (== argc if none). * Returns argv[] index of first file-name argument (== argc if none).
* Any file names with indexes <= last_file_arg_seen are ignored; * Any file names with indexes <= last_file_arg_seen are ignored;
@@ -138,7 +138,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
int argn; int argn;
char * arg; char * arg;
boolean simple_progressive; boolean simple_progressive;
char * scansarg = NULL; /* saves -scans parm if any */ char * scansarg = NULL; /* saves -scans parm if any */
/* Set up default JPEG parameters. */ /* Set up default JPEG parameters. */
#ifdef C_PROGRESSIVE_SUPPORTED #ifdef C_PROGRESSIVE_SUPPORTED
@@ -163,12 +163,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
if (*arg != '-') { if (*arg != '-') {
/* Not a switch, must be a file name argument */ /* Not a switch, must be a file name argument */
if (argn <= last_file_arg_seen) { if (argn <= last_file_arg_seen) {
outfilename = NULL; /* -outfile applies to just one input file */ outfilename = NULL; /* -outfile applies to just one input file */
continue; /* ignore this name if previously processed */ continue; /* ignore this name if previously processed */
} }
break; /* else done parsing switches */ break; /* else done parsing switches */
} }
arg++; /* advance past switch marker character */ arg++; /* advance past switch marker character */
if (keymatch(arg, "arithmetic", 1)) { if (keymatch(arg, "arithmetic", 1)) {
/* Use arithmetic coding. */ /* Use arithmetic coding. */
@@ -176,35 +176,35 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
cinfo->arith_code = TRUE; cinfo->arith_code = TRUE;
#else #else
fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
} else if (keymatch(arg, "copy", 2)) { } else if (keymatch(arg, "copy", 2)) {
/* Select which extra markers to copy. */ /* Select which extra markers to copy. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (keymatch(argv[argn], "none", 1)) { if (keymatch(argv[argn], "none", 1)) {
copyoption = JCOPYOPT_NONE; copyoption = JCOPYOPT_NONE;
} else if (keymatch(argv[argn], "comments", 1)) { } else if (keymatch(argv[argn], "comments", 1)) {
copyoption = JCOPYOPT_COMMENTS; copyoption = JCOPYOPT_COMMENTS;
} else if (keymatch(argv[argn], "all", 1)) { } else if (keymatch(argv[argn], "all", 1)) {
copyoption = JCOPYOPT_ALL; copyoption = JCOPYOPT_ALL;
} else } else
usage(); usage();
} else if (keymatch(arg, "crop", 2)) { } else if (keymatch(arg, "crop", 2)) {
/* Perform lossless cropping. */ /* Perform lossless cropping. */
#if TRANSFORMS_SUPPORTED #if TRANSFORMS_SUPPORTED
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (! jtransform_parse_crop_spec(&transformoption, argv[argn])) { if (! jtransform_parse_crop_spec(&transformoption, argv[argn])) {
fprintf(stderr, "%s: bogus -crop argument '%s'\n", fprintf(stderr, "%s: bogus -crop argument '%s'\n",
progname, argv[argn]); progname, argv[argn]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#else #else
select_transform(JXFORM_NONE); /* force an error */ select_transform(JXFORM_NONE); /* force an error */
#endif #endif
} else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
@@ -213,25 +213,25 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
static boolean printed_version = FALSE; static boolean printed_version = FALSE;
if (! printed_version) { if (! printed_version) {
fprintf(stderr, "%s version %s (build %s)\n", fprintf(stderr, "%s version %s (build %s)\n",
PACKAGE_NAME, VERSION, BUILD); PACKAGE_NAME, VERSION, BUILD);
fprintf(stderr, "%s\n\n", JCOPYRIGHT); fprintf(stderr, "%s\n\n", JCOPYRIGHT);
fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n", fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
JVERSION); JVERSION);
printed_version = TRUE; printed_version = TRUE;
} }
cinfo->err->trace_level++; cinfo->err->trace_level++;
} else if (keymatch(arg, "flip", 1)) { } else if (keymatch(arg, "flip", 1)) {
/* Mirror left-right or top-bottom. */ /* Mirror left-right or top-bottom. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (keymatch(argv[argn], "horizontal", 1)) if (keymatch(argv[argn], "horizontal", 1))
select_transform(JXFORM_FLIP_H); select_transform(JXFORM_FLIP_H);
else if (keymatch(argv[argn], "vertical", 1)) else if (keymatch(argv[argn], "vertical", 1))
select_transform(JXFORM_FLIP_V); select_transform(JXFORM_FLIP_V);
else else
usage(); usage();
} else if (keymatch(arg, "fastcrush", 4)) { } else if (keymatch(arg, "fastcrush", 4)) {
cinfo->optimize_scans = FALSE; cinfo->optimize_scans = FALSE;
@@ -241,7 +241,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
#if TRANSFORMS_SUPPORTED #if TRANSFORMS_SUPPORTED
transformoption.force_grayscale = TRUE; transformoption.force_grayscale = TRUE;
#else #else
select_transform(JXFORM_NONE); /* force an error */ select_transform(JXFORM_NONE); /* force an error */
#endif #endif
} else if (keymatch(arg, "maxmemory", 3)) { } else if (keymatch(arg, "maxmemory", 3)) {
@@ -249,12 +249,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
long lval; long lval;
char ch = 'x'; char ch = 'x';
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
usage(); usage();
if (ch == 'm' || ch == 'M') if (ch == 'm' || ch == 'M')
lval *= 1000L; lval *= 1000L;
cinfo->mem->max_memory_to_use = lval * 1000L; cinfo->mem->max_memory_to_use = lval * 1000L;
} else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
@@ -263,15 +263,15 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
cinfo->optimize_coding = TRUE; cinfo->optimize_coding = TRUE;
#else #else
fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n", fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
} else if (keymatch(arg, "outfile", 4)) { } else if (keymatch(arg, "outfile", 4)) {
/* Set output file name. */ /* Set output file name. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
outfilename = argv[argn]; /* save it away for later use */ outfilename = argv[argn]; /* save it away for later use */
} else if (keymatch(arg, "perfect", 2)) { } else if (keymatch(arg, "perfect", 2)) {
/* Fail if there is any partial edge MCUs that the transform can't /* Fail if there is any partial edge MCUs that the transform can't
@@ -285,7 +285,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
/* We must postpone execution until num_components is known. */ /* We must postpone execution until num_components is known. */
#else #else
fprintf(stderr, "%s: sorry, progressive output was not compiled\n", fprintf(stderr, "%s: sorry, progressive output was not compiled\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
@@ -294,18 +294,18 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
long lval; long lval;
char ch = 'x'; char ch = 'x';
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
usage(); usage();
if (lval < 0 || lval > 65535L) if (lval < 0 || lval > 65535L)
usage(); usage();
if (ch == 'b' || ch == 'B') { if (ch == 'b' || ch == 'B') {
cinfo->restart_interval = (unsigned int) lval; cinfo->restart_interval = (unsigned int) lval;
cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
} else { } else {
cinfo->restart_in_rows = (int) lval; cinfo->restart_in_rows = (int) lval;
/* restart_interval will be computed during startup */ /* restart_interval will be computed during startup */
} }
} else if (keymatch(arg, "revert", 3)) { } else if (keymatch(arg, "revert", 3)) {
@@ -314,27 +314,27 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "rotate", 2)) { } else if (keymatch(arg, "rotate", 2)) {
/* Rotate 90, 180, or 270 degrees (measured clockwise). */ /* Rotate 90, 180, or 270 degrees (measured clockwise). */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (keymatch(argv[argn], "90", 2)) if (keymatch(argv[argn], "90", 2))
select_transform(JXFORM_ROT_90); select_transform(JXFORM_ROT_90);
else if (keymatch(argv[argn], "180", 3)) else if (keymatch(argv[argn], "180", 3))
select_transform(JXFORM_ROT_180); select_transform(JXFORM_ROT_180);
else if (keymatch(argv[argn], "270", 3)) else if (keymatch(argv[argn], "270", 3))
select_transform(JXFORM_ROT_270); select_transform(JXFORM_ROT_270);
else else
usage(); usage();
} else if (keymatch(arg, "scans", 1)) { } else if (keymatch(arg, "scans", 1)) {
/* Set scan script. */ /* Set scan script. */
#ifdef C_MULTISCAN_FILES_SUPPORTED #ifdef C_MULTISCAN_FILES_SUPPORTED
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
scansarg = argv[argn]; scansarg = argv[argn];
/* We must postpone reading the file in case -progressive appears. */ /* We must postpone reading the file in case -progressive appears. */
#else #else
fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n", fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
@@ -351,7 +351,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
transformoption.trim = TRUE; transformoption.trim = TRUE;
} else { } else {
usage(); /* bogus switch */ usage(); /* bogus switch */
} }
} }
@@ -360,18 +360,18 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
if (for_real) { if (for_real) {
#ifdef C_PROGRESSIVE_SUPPORTED #ifdef C_PROGRESSIVE_SUPPORTED
if (simple_progressive) /* process -progressive; -scans can override */ if (simple_progressive) /* process -progressive; -scans can override */
jpeg_simple_progression(cinfo); jpeg_simple_progression(cinfo);
#endif #endif
#ifdef C_MULTISCAN_FILES_SUPPORTED #ifdef C_MULTISCAN_FILES_SUPPORTED
if (scansarg != NULL) /* process -scans if it was present */ if (scansarg != NULL) /* process -scans if it was present */
if (! read_scan_script(cinfo, scansarg)) if (! read_scan_script(cinfo, scansarg))
usage(); usage();
#endif #endif
} }
return argn; /* return index of next arg (file name) */ return argn; /* return index of next arg (file name) */
} }
@@ -407,7 +407,7 @@ main (int argc, char **argv)
progname = argv[0]; progname = argv[0];
if (progname == NULL || progname[0] == 0) if (progname == NULL || progname[0] == 0)
progname = "jpegtran"; /* in case C library doesn't provide it */ progname = "jpegtran"; /* in case C library doesn't provide it */
/* Initialize the JPEG decompression object with default error handling. */ /* Initialize the JPEG decompression object with default error handling. */
srcinfo.err = jpeg_std_error(&jsrcerr); srcinfo.err = jpeg_std_error(&jsrcerr);
@@ -417,13 +417,6 @@ main (int argc, char **argv)
jpeg_create_compress(&dstinfo); jpeg_create_compress(&dstinfo);
dstinfo.use_moz_defaults = TRUE; dstinfo.use_moz_defaults = TRUE;
/* Now safe to enable signal catcher.
* Note: we assume only the decompression object will have virtual arrays.
*/
#ifdef NEED_SIGNAL_CATCHER
enable_signal_catcher((j_common_ptr) &srcinfo);
#endif
/* Scan command line to find file names. /* Scan command line to find file names.
* It is convenient to use just one switch-parsing routine, but the switch * It is convenient to use just one switch-parsing routine, but the switch
* values read here are mostly ignored; we will rescan the switches after * values read here are mostly ignored; we will rescan the switches after
@@ -441,14 +434,14 @@ main (int argc, char **argv)
if (outfilename == NULL) { if (outfilename == NULL) {
if (file_index != argc-2) { if (file_index != argc-2) {
fprintf(stderr, "%s: must name one input and one output file\n", fprintf(stderr, "%s: must name one input and one output file\n",
progname); progname);
usage(); usage();
} }
outfilename = argv[file_index+1]; outfilename = argv[file_index+1];
} else { } else {
if (file_index != argc-1) { if (file_index != argc-1) {
fprintf(stderr, "%s: must name one input and one output file\n", fprintf(stderr, "%s: must name one input and one output file\n",
progname); progname);
usage(); usage();
} }
} }
@@ -530,8 +523,8 @@ main (int argc, char **argv)
*/ */
#if TRANSFORMS_SUPPORTED #if TRANSFORMS_SUPPORTED
dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo, dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo,
src_coef_arrays, src_coef_arrays,
&transformoption); &transformoption);
#else #else
dst_coef_arrays = src_coef_arrays; dst_coef_arrays = src_coef_arrays;
#endif #endif
@@ -577,8 +570,8 @@ main (int argc, char **argv)
/* Execute image transformation, if any */ /* Execute image transformation, if any */
#if TRANSFORMS_SUPPORTED #if TRANSFORMS_SUPPORTED
jtransform_execute_transformation(&srcinfo, &dstinfo, jtransform_execute_transformation(&srcinfo, &dstinfo,
src_coef_arrays, src_coef_arrays,
&transformoption); &transformoption);
#endif #endif
/* Finish compression and release memory */ /* Finish compression and release memory */
@@ -618,5 +611,5 @@ main (int argc, char **argv)
/* All done. */ /* All done. */
exit(jsrcerr.num_warnings + jdsterr.num_warnings ?EXIT_WARNING:EXIT_SUCCESS); exit(jsrcerr.num_warnings + jdsterr.num_warnings ?EXIT_WARNING:EXIT_SUCCESS);
return 0; /* suppress no-return-value warnings */ return 0; /* suppress no-return-value warnings */
} }

273
jquant1.c
View File

@@ -70,9 +70,9 @@
* table in both directions. * table in both directions.
*/ */
#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];
@@ -107,8 +107,8 @@ static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
* Errors are accumulated into the array fserrors[], at a resolution of * Errors are accumulated into the array fserrors[], at a resolution of
* 1/16th of a pixel count. The error at a given pixel is propagated * 1/16th of a pixel count. The error at a given pixel is propagated
* to its not-yet-processed neighbors using the standard F-S fractions, * to its not-yet-processed neighbors using the standard F-S fractions,
* ... (here) 7/16 * ... (here) 7/16
* 3/16 5/16 1/16 * 3/16 5/16 1/16
* We work left-to-right on even rows, right-to-left on odd rows. * We work left-to-right on even rows, right-to-left on odd rows.
* *
* We can get away with a single array (holding one row's worth of errors) * We can get away with a single array (holding one row's worth of errors)
@@ -121,49 +121,46 @@ static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
* The fserrors[] array is indexed [component#][position]. * The fserrors[] array is indexed [component#][position].
* We provide (#columns + 2) entries per component; the extra entry at each * We provide (#columns + 2) entries per component; the extra entry at each
* end saves us from special-casing the first and last pixels. * end saves us from special-casing the first and last pixels.
*
* Note: on a wide image, we might not have enough room in a PC's near data
* segment to hold the error array; so it is allocated with alloc_large.
*/ */
#if BITS_IN_JSAMPLE == 8 #if BITS_IN_JSAMPLE == 8
typedef INT16 FSERROR; /* 16 bits should be enough */ typedef INT16 FSERROR; /* 16 bits should be enough */
typedef int LOCFSERROR; /* use 'int' for calculation temps */ typedef int LOCFSERROR; /* use 'int' for calculation temps */
#else #else
typedef INT32 FSERROR; /* may need more than 16 bits */ typedef INT32 FSERROR; /* may need more than 16 bits */
typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */ typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
#endif #endif
typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */ typedef FSERROR *FSERRPTR; /* pointer to error array */
/* Private subobject */ /* Private subobject */
#define MAX_Q_COMPS 4 /* max components I can handle */ #define MAX_Q_COMPS 4 /* max components I can handle */
typedef struct { typedef struct {
struct jpeg_color_quantizer pub; /* public fields */ struct jpeg_color_quantizer pub; /* public fields */
/* Initially allocated colormap is saved here */ /* Initially allocated colormap is saved here */
JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */ JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
int sv_actual; /* number of entries in use */ int sv_actual; /* number of entries in use */
JSAMPARRAY colorindex; /* Precomputed mapping for speed */ JSAMPARRAY colorindex; /* Precomputed mapping for speed */
/* colorindex[i][j] = index of color closest to pixel value j in component i, /* colorindex[i][j] = index of color closest to pixel value j in component i,
* premultiplied as described above. Since colormap indexes must fit into * premultiplied as described above. Since colormap indexes must fit into
* JSAMPLEs, the entries of this array will too. * JSAMPLEs, the entries of this array will too.
*/ */
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 alloced 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 */
ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */ ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
/* Variables for Floyd-Steinberg dithering */ /* Variables for Floyd-Steinberg dithering */
FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */ FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
boolean on_odd_row; /* flag to remember which row we are on */ boolean on_odd_row; /* flag to remember which row we are on */
} my_cquantizer; } my_cquantizer;
typedef my_cquantizer * my_cquantize_ptr; typedef my_cquantizer * my_cquantize_ptr;
@@ -205,11 +202,11 @@ select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
iroot = 1; iroot = 1;
do { do {
iroot++; iroot++;
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)
@@ -233,10 +230,10 @@ 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;
} }
@@ -278,8 +275,8 @@ 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 */
@@ -288,8 +285,8 @@ create_colormap (j_decompress_ptr cinfo)
/* 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, cquantize->Ncolors[0], total_colors, cquantize->Ncolors[0],
cquantize->Ncolors[1], cquantize->Ncolors[2]); cquantize->Ncolors[1], cquantize->Ncolors[2]);
else else
TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors); TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
@@ -314,12 +311,12 @@ create_colormap (j_decompress_ptr cinfo)
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 */
} }
/* Save the colormap in private storage, /* Save the colormap in private storage,
@@ -377,16 +374,16 @@ create_colorindex (j_decompress_ptr cinfo)
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];
} }
} }
} }
@@ -406,7 +403,7 @@ make_odither_array (j_decompress_ptr cinfo, int ncolors)
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).
@@ -416,7 +413,7 @@ make_odither_array (j_decompress_ptr cinfo, int ncolors)
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 = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k]))) num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
* MAXJSAMPLE; * 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...
*/ */
@@ -442,14 +439,14 @@ create_odither_tables (j_decompress_ptr cinfo)
for (i = 0; i < cinfo->out_color_components; i++) { for (i = 0; i < cinfo->out_color_components; i++) {
nci = cquantize->Ncolors[i]; /* # of distinct values for this color */ nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
odither = NULL; /* search for matching prior component */ odither = NULL; /* search for matching prior component */
for (j = 0; j < i; j++) { for (j = 0; j < i; j++) {
if (nci == cquantize->Ncolors[j]) { if (nci == cquantize->Ncolors[j]) {
odither = cquantize->odither[j]; odither = cquantize->odither[j];
break; break;
} }
} }
if (odither == NULL) /* need a new table? */ if (odither == NULL) /* need a new table? */
odither = make_odither_array(cinfo, nci); odither = make_odither_array(cinfo, nci);
cquantize->odither[i] = odither; cquantize->odither[i] = odither;
} }
@@ -462,7 +459,7 @@ 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;
@@ -480,7 +477,7 @@ color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (col = width; col > 0; col--) { for (col = width; col > 0; col--) {
pixcode = 0; pixcode = 0;
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;
} }
@@ -490,7 +487,7 @@ color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
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;
@@ -518,15 +515,15 @@ color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
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;
int * dither; /* points to active row of dither matrix */ int * dither; /* points to active row of dither matrix */
int row_index, col_index; /* current indexes into dither matrix */ int row_index, col_index; /* current indexes into dither matrix */
int nc = cinfo->out_color_components; int nc = cinfo->out_color_components;
int ci; int ci;
int row; int row;
@@ -535,8 +532,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 FAR *) output_buf[row], jzero_far((void *) output_buf[row], (size_t) (width * sizeof(JSAMPLE)));
(size_t) (width * SIZEOF(JSAMPLE)));
row_index = cquantize->row_index; row_index = cquantize->row_index;
for (ci = 0; ci < nc; ci++) { for (ci = 0; ci < nc; ci++) {
input_ptr = input_buf[row] + ci; input_ptr = input_buf[row] + ci;
@@ -546,17 +542,17 @@ quantize_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--) {
/* Form pixel value + dither, range-limit to 0..MAXJSAMPLE, /* Form pixel value + dither, range-limit to 0..MAXJSAMPLE,
* select output value, accumulate into output code for this pixel. * select output value, accumulate into output code for this pixel.
* Range-limiting need not be done explicitly, as we have extended * Range-limiting need not be done explicitly, as we have extended
* the colorindex table to produce the right answers for out-of-range * the colorindex table to produce the right answers for out-of-range
* 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;
} }
} }
/* Advance row index for next row */ /* Advance row index for next row */
@@ -568,7 +564,7 @@ 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;
@@ -578,10 +574,10 @@ quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPROW colorindex0 = cquantize->colorindex[0]; JSAMPROW colorindex0 = cquantize->colorindex[0];
JSAMPROW colorindex1 = cquantize->colorindex[1]; JSAMPROW colorindex1 = cquantize->colorindex[1];
JSAMPROW colorindex2 = cquantize->colorindex[2]; JSAMPROW colorindex2 = cquantize->colorindex[2];
int * dither0; /* points to active row of dither matrix */ int * dither0; /* points to active row of dither matrix */
int * dither1; int * dither1;
int * dither2; int * dither2;
int row_index, col_index; /* current indexes into dither matrix */ int row_index, col_index; /* current indexes into dither matrix */
int row; int row;
JDIMENSION col; JDIMENSION col;
JDIMENSION width = cinfo->output_width; JDIMENSION width = cinfo->output_width;
@@ -597,11 +593,11 @@ quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (col = width; col > 0; col--) { for (col = width; col > 0; col--) {
pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) + pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
dither0[col_index]]); dither0[col_index]]);
pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) + pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
dither1[col_index]]); dither1[col_index]]);
pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) + pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
dither2[col_index]]); 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;
} }
@@ -613,24 +609,24 @@ 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 */
LOCFSERROR bnexterr; /* error for below/next col */ LOCFSERROR bnexterr; /* error for below/next col */
LOCFSERROR delta; LOCFSERROR delta;
register FSERRPTR errorptr; /* => fserrors[] at column before current */ register FSERRPTR errorptr; /* => fserrors[] at column before current */
register JSAMPROW input_ptr; register JSAMPROW input_ptr;
register JSAMPROW output_ptr; register JSAMPROW output_ptr;
JSAMPROW colorindex_ci; JSAMPROW colorindex_ci;
JSAMPROW colormap_ci; JSAMPROW colormap_ci;
int pixcode; int pixcode;
int nc = cinfo->out_color_components; int nc = cinfo->out_color_components;
int dir; /* 1 for left-to-right, -1 for right-to-left */ int dir; /* 1 for left-to-right, -1 for right-to-left */
int dirnc; /* dir * nc */ int dirnc; /* dir * nc */
int ci; int ci;
int row; int row;
JDIMENSION col; JDIMENSION col;
@@ -640,23 +636,22 @@ 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 FAR *) output_buf[row], jzero_far((void *) output_buf[row], (size_t) (width * sizeof(JSAMPLE)));
(size_t) (width * SIZEOF(JSAMPLE)));
for (ci = 0; ci < nc; ci++) { for (ci = 0; ci < nc; ci++) {
input_ptr = input_buf[row] + ci; input_ptr = input_buf[row] + ci;
output_ptr = output_buf[row]; output_ptr = output_buf[row];
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;
dirnc = nc; dirnc = nc;
errorptr = cquantize->fserrors[ci]; /* => entry before first column */ errorptr = cquantize->fserrors[ci]; /* => entry before first column */
} }
colorindex_ci = cquantize->colorindex[ci]; colorindex_ci = cquantize->colorindex[ci];
colormap_ci = cquantize->sv_colormap[ci]; colormap_ci = cquantize->sv_colormap[ci];
@@ -666,47 +661,47 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
belowerr = bpreverr = 0; belowerr = bpreverr = 0;
for (col = width; col > 0; col--) { for (col = width; col > 0; col--) {
/* cur holds the error propagated from the previous pixel on the /* cur holds the error propagated from the previous pixel on the
* current line. Add the error propagated from the previous line * current line. Add the error propagated from the previous line
* to form the complete error correction term for this pixel, and * to form the complete error correction term for this pixel, and
* round the error term (which is expressed * 16) to an integer. * round the error term (which is expressed * 16) to an integer.
* RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct * RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct
* 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.
*/ */
cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4); cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
/* Form pixel value + error, and range-limit to 0..MAXJSAMPLE. /* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.
* The maximum error is +- MAXJSAMPLE; this sets the required size * The maximum error is +- MAXJSAMPLE; this sets the required size
* of the range_limit array. * of the range_limit array.
*/ */
cur += GETJSAMPLE(*input_ptr); cur += GETJSAMPLE(*input_ptr);
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. */
cur -= GETJSAMPLE(colormap_ci[pixcode]); cur -= GETJSAMPLE(colormap_ci[pixcode]);
/* Compute error fractions to be propagated to adjacent pixels. /* Compute error fractions to be propagated to adjacent pixels.
* 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.
*/ */
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;
cur += delta; /* form error * 7 */ cur += delta; /* form error * 7 */
/* At this point cur contains the 7/16 error value to be propagated /* At this point cur contains the 7/16 error value to be propagated
* to the next pixel on the current line, and all the errors for the * to the next pixel on the current line, and all the errors for the
* next line have been shifted over. We are therefore ready to move on. * next line have been shifted over. We are therefore ready to move on.
*/ */
input_ptr += dirnc; /* advance input ptr to next column */ input_ptr += dirnc; /* advance input ptr to next column */
output_ptr += dir; /* advance output ptr to next column */ output_ptr += dir; /* advance output ptr to next column */
errorptr += dir; /* advance errorptr to current column */ errorptr += dir; /* advance errorptr to current column */
} }
/* Post-loop cleanup: we must unload the final error value into the /* Post-loop cleanup: we must unload the final error value into the
* final fserrors[] entry. Note we need not unload belowerr because * final fserrors[] entry. Note we need not unload belowerr because
@@ -730,7 +725,7 @@ alloc_fs_workspace (j_decompress_ptr cinfo)
size_t arraysize; size_t arraysize;
int i; int i;
arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR)); arraysize = (size_t) ((cinfo->output_width + 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);
@@ -766,7 +761,7 @@ start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
cquantize->pub.color_quantize = quantize3_ord_dither; cquantize->pub.color_quantize = quantize3_ord_dither;
else else
cquantize->pub.color_quantize = quantize_ord_dither; cquantize->pub.color_quantize = quantize_ord_dither;
cquantize->row_index = 0; /* initialize state for ordered dither */ cquantize->row_index = 0; /* initialize state for ordered dither */
/* If user changed to ordered dither from another mode, /* If user changed to ordered dither from another mode,
* 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.
@@ -784,9 +779,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 FAR *) 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);
@@ -829,13 +824,13 @@ jinit_1pass_quantizer (j_decompress_ptr cinfo)
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;
cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */ cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */ cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
/* Make sure my internal arrays won't overflow */ /* Make sure my internal arrays won't overflow */
if (cinfo->out_color_components > MAX_Q_COMPS) if (cinfo->out_color_components > MAX_Q_COMPS)
@@ -849,10 +844,10 @@ jinit_1pass_quantizer (j_decompress_ptr cinfo)
create_colorindex(cinfo); create_colorindex(cinfo);
/* Allocate Floyd-Steinberg workspace now if requested. /* Allocate Floyd-Steinberg workspace now if requested.
* We do this now since it is FAR storage and may affect the memory * We do this now since it may affect the memory manager's space
* manager's space calculations. If the user changes to FS dither * calculations. If the user changes to FS dither mode in a later pass, we
* mode in a later pass, we will allocate the space then, and will * will allocate the space then, and will possibly overrun the
* possibly overrun the max_memory_to_use setting. * max_memory_to_use setting.
*/ */
if (cinfo->dither_mode == JDITHER_FS) if (cinfo->dither_mode == JDITHER_FS)
alloc_fs_workspace(cinfo); alloc_fs_workspace(cinfo);

365
jquant2.c
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-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009, D. R. Commander. * Copyright (C) 2009, 2014, D. R. Commander.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains 2-pass color quantization (color mapping) routines. * This file contains 2-pass color quantization (color mapping) routines.
@@ -72,9 +72,9 @@
* probably need to change these scale factors. * probably need to change these scale factors.
*/ */
#define R_SCALE 2 /* scale R distances by this much */ #define R_SCALE 2 /* scale R distances by this much */
#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]]
@@ -102,9 +102,7 @@ static const int c_scales[3]={R_SCALE, G_SCALE, B_SCALE};
* machines, we can't just allocate the histogram in one chunk. Instead * machines, we can't just allocate the histogram in one chunk. Instead
* of a true 3-D array, we use a row of pointers to 2-D arrays. Each * of a true 3-D array, we use a row of pointers to 2-D arrays. Each
* pointer corresponds to a C0 value (typically 2^5 = 32 pointers) and * pointer corresponds to a C0 value (typically 2^5 = 32 pointers) and
* each 2-D array has 2^6*2^5 = 2048 or 2^6*2^6 = 4096 entries. Note that * each 2-D array has 2^6*2^5 = 2048 or 2^6*2^6 = 4096 entries.
* on 80x86 machines, the pointer row is in near memory but the actual
* arrays are in far memory (same arrangement as we use for image arrays).
*/ */
#define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */ #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
@@ -112,9 +110,9 @@ static const int c_scales[3]={R_SCALE, G_SCALE, B_SCALE};
/* 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.
*/ */
#define HIST_C0_BITS 5 /* bits of precision in R/B histogram */ #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
#define HIST_C1_BITS 6 /* bits of precision in G histogram */ #define HIST_C1_BITS 6 /* bits of precision in G histogram */
#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)
@@ -127,13 +125,13 @@ static const int c_scales[3]={R_SCALE, G_SCALE, B_SCALE};
#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 */
typedef histcell FAR * histptr; /* for pointers to histogram cells */ typedef histcell * histptr; /* for pointers to histogram cells */
typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */ typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */ typedef hist1d * hist2d; /* type for the 2nd-level pointers */
typedef hist2d * hist3d; /* type for top-level pointer */ typedef hist2d * hist3d; /* type for top-level pointer */
/* Declarations for Floyd-Steinberg dithering. /* Declarations for Floyd-Steinberg dithering.
@@ -141,8 +139,8 @@ typedef hist2d * hist3d; /* type for top-level pointer */
* Errors are accumulated into the array fserrors[], at a resolution of * Errors are accumulated into the array fserrors[], at a resolution of
* 1/16th of a pixel count. The error at a given pixel is propagated * 1/16th of a pixel count. The error at a given pixel is propagated
* to its not-yet-processed neighbors using the standard F-S fractions, * to its not-yet-processed neighbors using the standard F-S fractions,
* ... (here) 7/16 * ... (here) 7/16
* 3/16 5/16 1/16 * 3/16 5/16 1/16
* We work left-to-right on even rows, right-to-left on odd rows. * We work left-to-right on even rows, right-to-left on odd rows.
* *
* We can get away with a single array (holding one row's worth of errors) * We can get away with a single array (holding one row's worth of errors)
@@ -155,20 +153,17 @@ typedef hist2d * hist3d; /* type for top-level pointer */
* The fserrors[] array has (#columns + 2) entries; the extra entry at * The fserrors[] array has (#columns + 2) entries; the extra entry at
* each end saves us from special-casing the first and last pixels. * each end saves us from special-casing the first and last pixels.
* Each entry is three values long, one value for each color component. * Each entry is three values long, one value for each color component.
*
* Note: on a wide image, we might not have enough room in a PC's near data
* segment to hold the error array; so it is allocated with alloc_large.
*/ */
#if BITS_IN_JSAMPLE == 8 #if BITS_IN_JSAMPLE == 8
typedef INT16 FSERROR; /* 16 bits should be enough */ typedef INT16 FSERROR; /* 16 bits should be enough */
typedef int LOCFSERROR; /* use 'int' for calculation temps */ typedef int LOCFSERROR; /* use 'int' for calculation temps */
#else #else
typedef INT32 FSERROR; /* may need more than 16 bits */ typedef INT32 FSERROR; /* may need more than 16 bits */
typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */ typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
#endif #endif
typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */ typedef FSERROR *FSERRPTR; /* pointer to error array */
/* Private subobject */ /* Private subobject */
@@ -177,18 +172,18 @@ typedef struct {
struct jpeg_color_quantizer pub; /* public fields */ struct jpeg_color_quantizer pub; /* public fields */
/* Space for the eventually created colormap is stashed here */ /* Space for the eventually created colormap is stashed here */
JSAMPARRAY sv_colormap; /* colormap allocated at init time */ JSAMPARRAY sv_colormap; /* colormap allocated at init time */
int desired; /* desired # of colors = size of colormap */ int desired; /* desired # of colors = size of colormap */
/* Variables for accumulating image statistics */ /* Variables for accumulating image statistics */
hist3d histogram; /* pointer to the histogram */ hist3d histogram; /* pointer to the histogram */
boolean needs_zeroed; /* TRUE if next pass must zero histogram */ boolean needs_zeroed; /* TRUE if next pass must zero histogram */
/* Variables for Floyd-Steinberg dithering */ /* Variables for Floyd-Steinberg dithering */
FSERRPTR fserrors; /* accumulated errors */ FSERRPTR fserrors; /* accumulated errors */
boolean on_odd_row; /* flag to remember which row we are on */ boolean on_odd_row; /* flag to remember which row we are on */
int * error_limiter; /* table for clamping the applied error */ int * error_limiter; /* table for clamping the applied error */
} my_cquantizer; } my_cquantizer;
typedef my_cquantizer * my_cquantize_ptr; typedef my_cquantizer * my_cquantize_ptr;
@@ -205,7 +200,7 @@ 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;
@@ -220,11 +215,11 @@ prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
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. */
if (++(*histp) <= 0) if (++(*histp) <= 0)
(*histp)--; (*histp)--;
ptr += 3; ptr += 3;
} }
} }
@@ -312,67 +307,67 @@ 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:
@@ -395,9 +390,9 @@ update_box (j_decompress_ptr cinfo, boxptr boxp)
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++;
} }
} }
boxp->colorcount = ccount; boxp->colorcount = ccount;
} }
@@ -405,7 +400,7 @@ 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;
@@ -421,9 +416,9 @@ median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
} else { } else {
b1 = find_biggest_volume(boxlist, numboxes); b1 = find_biggest_volume(boxlist, numboxes);
} }
if (b1 == NULL) /* no splittable boxes left! */ if (b1 == NULL) /* no splittable boxes left! */
break; break;
b2 = &boxlist[numboxes]; /* where new box will go */ b2 = &boxlist[numboxes]; /* where new box will go */
/* Copy the color bounds to the new box. */ /* Copy the color bounds to the new box. */
b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max; b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min; b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
@@ -504,12 +499,12 @@ compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
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;
} }
} }
} }
@@ -529,7 +524,7 @@ select_colors (j_decompress_ptr cinfo, int desired_colors)
/* 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;
@@ -628,7 +623,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
* is specified by the center coordinates of its first cell. The number of * is specified by the center coordinates of its first cell. The number of
@@ -643,7 +638,7 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
int centerc0, centerc1, centerc2; int centerc0, centerc1, centerc2;
int i, x, ncolors; int i, x, ncolors;
INT32 minmaxdist, min_dist, max_dist, tdist; INT32 minmaxdist, min_dist, max_dist, tdist;
INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */ INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
/* Compute true coordinates of update box's upper corner and center. /* Compute true coordinates of update box's upper corner and center.
* Actually we compute the coordinates of the center of the upper-corner * Actually we compute the coordinates of the center of the upper-corner
@@ -685,11 +680,11 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
/* 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;
} }
} }
@@ -707,11 +702,11 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
} 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;
} }
} }
@@ -729,15 +724,15 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
} 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;
} }
} }
mindist[i] = min_dist; /* save away the results */ mindist[i] = min_dist; /* save away the results */
if (max_dist < minmaxdist) if (max_dist < minmaxdist)
minmaxdist = max_dist; minmaxdist = max_dist;
} }
@@ -757,7 +752,7 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
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.
* Return the indexes of the closest entries in the bestcolor[] array. * Return the indexes of the closest entries in the bestcolor[] array.
@@ -767,13 +762,13 @@ find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
{ {
int ic0, ic1, ic2; int ic0, ic1, ic2;
int i, icolor; int i, icolor;
register INT32 * bptr; /* pointer into bestdist[] array */ register INT32 * bptr; /* pointer into bestdist[] array */
JSAMPLE * cptr; /* pointer into bestcolor[] array */ JSAMPLE * cptr; /* pointer into bestcolor[] array */
INT32 dist0, dist1; /* initial distance values */ INT32 dist0, dist1; /* initial distance values */
register INT32 dist2; /* current distance in inner loop */ register INT32 dist2; /* current distance in inner loop */
INT32 xx0, xx1; /* distance increments */ INT32 xx0, xx1; /* distance increments */
register INT32 xx2; register INT32 xx2;
INT32 inc0, inc1, inc2; /* initial values for increments */ INT32 inc0, inc1, inc2; /* initial values for increments */
/* This array holds the distance to the nearest-so-far color for each cell */ /* This array holds the distance to the nearest-so-far color for each cell */
INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS]; INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
@@ -813,20 +808,20 @@ find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
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;
bptr++; bptr++;
cptr++; cptr++;
} }
dist1 += xx1; dist1 += xx1;
xx1 += 2 * STEP_C1 * STEP_C1; xx1 += 2 * STEP_C1 * STEP_C1;
} }
dist0 += xx0; dist0 += xx0;
xx0 += 2 * STEP_C0 * STEP_C0; xx0 += 2 * STEP_C0 * STEP_C0;
@@ -843,13 +838,13 @@ fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
{ {
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;
register JSAMPLE * cptr; /* pointer into bestcolor[] array */ register JSAMPLE * cptr; /* pointer into bestcolor[] array */
register histptr cachep; /* pointer into main cache array */ register histptr cachep; /* pointer into main cache array */
/* This array lists the candidate colormap indexes. */ /* This array lists the candidate colormap indexes. */
JSAMPLE colorlist[MAXNUMCOLORS]; JSAMPLE colorlist[MAXNUMCOLORS];
int numcolors; /* number of candidate colors */ int numcolors; /* number of candidate colors */
/* This array holds the actually closest colormap index for each cell. */ /* This array holds the actually closest colormap index for each cell. */
JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS]; JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
@@ -873,10 +868,10 @@ fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
/* Determine the actually nearest colors. */ /* Determine the actually nearest colors. */
find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist, find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
bestcolor); bestcolor);
/* Save the best color numbers (plus 1) in the main cache array */ /* Save the best color numbers (plus 1) in the main cache array */
c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */ c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
c1 <<= BOX_C1_LOG; c1 <<= BOX_C1_LOG;
c2 <<= BOX_C2_LOG; c2 <<= BOX_C2_LOG;
cptr = bestcolor; cptr = bestcolor;
@@ -884,7 +879,7 @@ fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
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);
} }
} }
} }
@@ -897,7 +892,7 @@ 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 output_buf, int num_rows) JSAMPARRAY input_buf, 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;
@@ -921,7 +916,7 @@ pass2_no_dither (j_decompress_ptr cinfo,
/* 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);
} }
@@ -931,20 +926,20 @@ pass2_no_dither (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
pass2_fs_dither (j_decompress_ptr cinfo, pass2_fs_dither (j_decompress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows) JSAMPARRAY input_buf, 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 */
LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */ LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
register FSERRPTR errorptr; /* => fserrors[] at column before current */ register FSERRPTR errorptr; /* => fserrors[] at column before current */
JSAMPROW inptr; /* => current input pixel */ JSAMPROW inptr; /* => current input pixel */
JSAMPROW outptr; /* => current output pixel */ JSAMPROW outptr; /* => current output pixel */
histptr cachep; histptr cachep;
int dir; /* +1 or -1 depending on direction */ int dir; /* +1 or -1 depending on direction */
int dir3; /* 3*dir, for advancing inptr & errorptr */ int dir3; /* 3*dir, for advancing inptr & errorptr */
int row; int row;
JDIMENSION col; JDIMENSION col;
JDIMENSION width = cinfo->output_width; JDIMENSION width = cinfo->output_width;
@@ -960,7 +955,7 @@ 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;
@@ -1012,53 +1007,44 @@ pass2_fs_dither (j_decompress_ptr cinfo,
/* 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; { register int pixcode = *cachep - 1;
*outptr = (JSAMPLE) pixcode; *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]);
cur2 -= GETJSAMPLE(colormap2[pixcode]); cur2 -= GETJSAMPLE(colormap2[pixcode]);
} }
/* Compute error fractions to be propagated to adjacent pixels. /* Compute error fractions to be propagated to adjacent pixels.
* 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, delta; { register LOCFSERROR bnexterr;
bnexterr = cur0; /* Process component 0 */ bnexterr = cur0; /* Process component 0 */
delta = cur0 * 2; errorptr[0] = (FSERROR) (bpreverr0 + cur0 * 3);
cur0 += delta; /* form error * 3 */ bpreverr0 = belowerr0 + cur0 * 5;
errorptr[0] = (FSERROR) (bpreverr0 + cur0); belowerr0 = bnexterr;
cur0 += delta; /* form error * 5 */ cur0 *= 7;
bpreverr0 = belowerr0 + cur0; bnexterr = cur1; /* Process component 1 */
belowerr0 = bnexterr; errorptr[1] = (FSERROR) (bpreverr1 + cur1 * 3);
cur0 += delta; /* form error * 7 */ bpreverr1 = belowerr1 + cur1 * 5;
bnexterr = cur1; /* Process component 1 */ belowerr1 = bnexterr;
delta = cur1 * 2; cur1 *= 7;
cur1 += delta; /* form error * 3 */ bnexterr = cur2; /* Process component 2 */
errorptr[1] = (FSERROR) (bpreverr1 + cur1); errorptr[2] = (FSERROR) (bpreverr2 + cur2 * 3);
cur1 += delta; /* form error * 5 */ bpreverr2 = belowerr2 + cur2 * 5;
bpreverr1 = belowerr1 + cur1; belowerr2 = bnexterr;
belowerr1 = bnexterr; cur2 *= 7;
cur1 += delta; /* form error * 7 */
bnexterr = cur2; /* Process component 2 */
delta = cur2 * 2;
cur2 += delta; /* form error * 3 */
errorptr[2] = (FSERROR) (bpreverr2 + cur2);
cur2 += delta; /* form error * 5 */
bpreverr2 = belowerr2 + cur2;
belowerr2 = bnexterr;
cur2 += delta; /* form error * 7 */
} }
/* At this point curN contains the 7/16 error value to be propagated /* At this point curN contains the 7/16 error value to be propagated
* to the next pixel on the current line, and all the errors for the * to the next pixel on the current line, and all the errors for the
* next line have been shifted over. We are therefore ready to move on. * next line have been shifted over. We are therefore ready to move on.
*/ */
inptr += dir3; /* Advance pixel pointers to next column */ inptr += dir3; /* Advance pixel pointers to next column */
outptr += dir; outptr += dir;
errorptr += dir3; /* advance errorptr to current column */ errorptr += dir3; /* advance errorptr to current column */
} }
/* Post-loop cleanup: we must unload the final error values into the /* Post-loop cleanup: we must unload the final error values into the
* final fserrors[] entry. Note we need not unload belowerrN because * final fserrors[] entry. Note we need not unload belowerrN because
@@ -1097,8 +1083,8 @@ init_error_limit (j_decompress_ptr cinfo)
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)
@@ -1181,16 +1167,16 @@ start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
if (cinfo->dither_mode == JDITHER_FS) { if (cinfo->dither_mode == JDITHER_FS) {
size_t arraysize = (size_t) ((cinfo->output_width + 2) * size_t arraysize = (size_t) ((cinfo->output_width + 2) *
(3 * SIZEOF(FSERROR))); (3 * sizeof(FSERROR)));
/* Allocate Floyd-Steinberg workspace if we didn't already. */ /* Allocate Floyd-Steinberg workspace if we didn't already. */
if (cquantize->fserrors == NULL) if (cquantize->fserrors == NULL)
cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large) cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
((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 FAR *) 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);
cquantize->on_odd_row = FALSE; cquantize->on_odd_row = FALSE;
} }
@@ -1198,8 +1184,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 FAR *) 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;
} }
@@ -1232,11 +1218,11 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo)
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 */
cquantize->error_limiter = NULL; cquantize->error_limiter = NULL;
/* Make sure jdmaster didn't give me a case I can't handle */ /* Make sure jdmaster didn't give me a case I can't handle */
@@ -1245,17 +1231,17 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo)
/* 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 */
/* Allocate storage for the completed colormap, if required. /* Allocate storage for the completed colormap, if required.
* We do this now since it is FAR storage and may affect * We do this now since it may affect the memory manager's space
* the memory manager's space calculations. * calculations.
*/ */
if (cinfo->enable_2pass_quant) { if (cinfo->enable_2pass_quant) {
/* Make sure color count is acceptable */ /* Make sure color count is acceptable */
@@ -1278,14 +1264,15 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo)
cinfo->dither_mode = JDITHER_FS; cinfo->dither_mode = JDITHER_FS;
/* Allocate Floyd-Steinberg workspace if necessary. /* Allocate Floyd-Steinberg workspace if necessary.
* This isn't really needed until pass 2, but again it is FAR storage. * This isn't really needed until pass 2, but again it may affect the memory
* Although we will cope with a later change in dither_mode, * manager's space calculations. Although we will cope with a later change
* we do not promise to honor max_memory_to_use if dither_mode changes. * in dither_mode, we do not promise to honor max_memory_to_use if
* 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);
} }

116
jsimd.h
View File

@@ -10,89 +10,71 @@
* *
*/ */
/* Short forms of external names for systems with brain-damaged linkers. */ EXTERN(int) jsimd_can_rgb_ycc (void);
EXTERN(int) jsimd_can_rgb_gray (void);
#ifdef NEED_SHORT_EXTERNAL_NAMES EXTERN(int) jsimd_can_ycc_rgb (void);
#define jsimd_can_rgb_ycc jSCanRgbYcc EXTERN(int) jsimd_c_can_null_convert (void);
#define jsimd_can_rgb_gray jSCanRgbGry
#define jsimd_can_ycc_rgb jSCanYccRgb
#define jsimd_rgb_ycc_convert jSRgbYccConv
#define jsimd_rgb_gray_convert jSRgbGryConv
#define jsimd_ycc_rgb_convert jSYccRgbConv
#define jsimd_can_h2v2_downsample jSCanH2V2Down
#define jsimd_can_h2v1_downsample jSCanH2V1Down
#define jsimd_h2v2_downsample jSH2V2Down
#define jsimd_h2v1_downsample jSH2V1Down
#define jsimd_can_h2v2_upsample jSCanH2V2Up
#define jsimd_can_h2v1_upsample jSCanH2V1Up
#define jsimd_h2v2_upsample jSH2V2Up
#define jsimd_h2v1_upsample jSH2V1Up
#define jsimd_can_h2v2_fancy_upsample jSCanH2V2FUp
#define jsimd_can_h2v1_fancy_upsample jSCanH2V1FUp
#define jsimd_h2v2_fancy_upsample jSH2V2FUp
#define jsimd_h2v1_fancy_upsample jSH2V1FUp
#define jsimd_can_h2v2_merged_upsample jSCanH2V2MUp
#define jsimd_can_h2v1_merged_upsample jSCanH2V1MUp
#define jsimd_h2v2_merged_upsample jSH2V2MUp
#define jsimd_h2v1_merged_upsample jSH2V1MUp
#endif /* NEED_SHORT_EXTERNAL_NAMES */
EXTERN(int) jsimd_can_rgb_ycc JPP((void));
EXTERN(int) jsimd_can_rgb_gray JPP((void));
EXTERN(int) jsimd_can_ycc_rgb JPP((void));
EXTERN(void) jsimd_rgb_ycc_convert EXTERN(void) jsimd_rgb_ycc_convert
JPP((j_compress_ptr cinfo, (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));
EXTERN(void) jsimd_rgb_gray_convert EXTERN(void) jsimd_rgb_gray_convert
JPP((j_compress_ptr cinfo, (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));
EXTERN(void) jsimd_ycc_rgb_convert EXTERN(void) jsimd_ycc_rgb_convert
JPP((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
(j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows);
EXTERN(int) jsimd_can_h2v2_downsample JPP((void)); EXTERN(int) jsimd_can_h2v2_downsample (void);
EXTERN(int) jsimd_can_h2v1_downsample JPP((void)); EXTERN(int) jsimd_can_h2v1_downsample (void);
EXTERN(void) jsimd_h2v2_downsample EXTERN(void) jsimd_h2v2_downsample
JPP((j_compress_ptr cinfo, jpeg_component_info * compptr, (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)); JSAMPARRAY input_data, JSAMPARRAY output_data);
EXTERN(void) jsimd_h2v1_downsample
JPP((j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data));
EXTERN(int) jsimd_can_h2v2_upsample JPP((void)); EXTERN(int) jsimd_can_h2v2_smooth_downsample (void);
EXTERN(int) jsimd_can_h2v1_upsample JPP((void));
EXTERN(void) jsimd_h2v2_smooth_downsample
(j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data);
EXTERN(void) jsimd_h2v1_downsample
(j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data);
EXTERN(int) jsimd_can_h2v2_upsample (void);
EXTERN(int) jsimd_can_h2v1_upsample (void);
EXTERN(int) jsimd_can_int_upsample (void);
EXTERN(void) jsimd_h2v2_upsample EXTERN(void) jsimd_h2v2_upsample
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr);
EXTERN(void) jsimd_h2v1_upsample EXTERN(void) jsimd_h2v1_upsample
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); JSAMPARRAY input_data, 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 JPP((void)); EXTERN(int) jsimd_can_h2v2_fancy_upsample (void);
EXTERN(int) jsimd_can_h2v1_fancy_upsample JPP((void)); EXTERN(int) jsimd_can_h2v1_fancy_upsample (void);
EXTERN(void) jsimd_h2v2_fancy_upsample EXTERN(void) jsimd_h2v2_fancy_upsample
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr);
EXTERN(void) jsimd_h2v1_fancy_upsample EXTERN(void) jsimd_h2v1_fancy_upsample
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr);
EXTERN(int) jsimd_can_h2v2_merged_upsample JPP((void)); EXTERN(int) jsimd_can_h2v2_merged_upsample (void);
EXTERN(int) jsimd_can_h2v1_merged_upsample JPP((void)); EXTERN(int) jsimd_can_h2v1_merged_upsample (void);
EXTERN(void) jsimd_h2v2_merged_upsample EXTERN(void) jsimd_h2v2_merged_upsample
JPP((j_decompress_ptr cinfo, (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));
EXTERN(void) jsimd_h2v1_merged_upsample EXTERN(void) jsimd_h2v1_merged_upsample
JPP((j_decompress_ptr cinfo, (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));

View File

@@ -36,6 +36,12 @@ jsimd_can_ycc_rgb (void)
return 0; return 0;
} }
GLOBAL(int)
jsimd_c_can_null_convert (void)
{
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, JSAMPIMAGE output_buf, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
@@ -57,6 +63,13 @@ jsimd_ycc_rgb_convert (j_decompress_ptr cinfo,
{ {
} }
GLOBAL(void)
jsimd_c_null_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows)
{
}
GLOBAL(int) GLOBAL(int)
jsimd_can_h2v2_downsample (void) jsimd_can_h2v2_downsample (void)
{ {
@@ -69,12 +82,24 @@ jsimd_can_h2v1_downsample (void)
return 0; return 0;
} }
GLOBAL(int)
jsimd_can_h2v2_smooth_downsample (void)
{
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)
jsimd_h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
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)
@@ -93,6 +118,18 @@ jsimd_can_h2v1_upsample (void)
return 0; return 0;
} }
GLOBAL(int)
jsimd_can_int_upsample (void)
{
return 0;
}
GLOBAL(void)
jsimd_int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
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,
@@ -318,22 +355,22 @@ jsimd_can_idct_float (void)
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)
{ {
} }

View File

@@ -9,106 +9,66 @@
* *
*/ */
/* Short forms of external names for systems with brain-damaged linkers. */ EXTERN(int) jsimd_can_convsamp (void);
EXTERN(int) jsimd_can_convsamp_float (void);
#ifdef NEED_SHORT_EXTERNAL_NAMES EXTERN(void) jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col,
#define jsimd_can_convsamp jSCanConv DCTELEM * workspace);
#define jsimd_can_convsamp_float jSCanConvF EXTERN(void) jsimd_convsamp_float (JSAMPARRAY sample_data,
#define jsimd_convsamp jSConv JDIMENSION start_col,
#define jsimd_convsamp_float jSConvF FAST_FLOAT * workspace);
#define jsimd_can_fdct_islow jSCanFDCTIS
#define jsimd_can_fdct_ifast jSCanFDCTIF
#define jsimd_can_fdct_float jSCanFDCTFl
#define jsimd_fdct_islow jSFDCTIS
#define jsimd_fdct_ifast jSFDCTIF
#define jsimd_fdct_float jSFDCTFl
#define jsimd_can_quantize jSCanQuant
#define jsimd_can_quantize_float jSCanQuantF
#define jsimd_quantize jSQuant
#define jsimd_quantize_float jSQuantF
#define jsimd_can_idct_2x2 jSCanIDCT22
#define jsimd_can_idct_4x4 jSCanIDCT44
#define jsimd_idct_2x2 jSIDCT22
#define jsimd_idct_4x4 jSIDCT44
#define jsimd_can_idct_islow jSCanIDCTIS
#define jsimd_can_idct_ifast jSCanIDCTIF
#define jsimd_can_idct_float jSCanIDCTFl
#define jsimd_idct_islow jSIDCTIS
#define jsimd_idct_ifast jSIDCTIF
#define jsimd_idct_float jSIDCTFl
#endif /* NEED_SHORT_EXTERNAL_NAMES */
EXTERN(int) jsimd_can_convsamp JPP((void)); EXTERN(int) jsimd_can_fdct_islow (void);
EXTERN(int) jsimd_can_convsamp_float JPP((void)); EXTERN(int) jsimd_can_fdct_ifast (void);
EXTERN(int) jsimd_can_fdct_float (void);
EXTERN(void) jsimd_convsamp JPP((JSAMPARRAY sample_data, EXTERN(void) jsimd_fdct_islow (DCTELEM * data);
JDIMENSION start_col, EXTERN(void) jsimd_fdct_ifast (DCTELEM * data);
DCTELEM * workspace)); EXTERN(void) jsimd_fdct_float (FAST_FLOAT * data);
EXTERN(void) jsimd_convsamp_float JPP((JSAMPARRAY sample_data,
JDIMENSION start_col,
FAST_FLOAT * workspace));
EXTERN(int) jsimd_can_fdct_islow JPP((void)); EXTERN(int) jsimd_can_quantize (void);
EXTERN(int) jsimd_can_fdct_ifast JPP((void)); EXTERN(int) jsimd_can_quantize_float (void);
EXTERN(int) jsimd_can_fdct_float JPP((void));
EXTERN(void) jsimd_fdct_islow JPP((DCTELEM * data)); EXTERN(void) jsimd_quantize (JCOEFPTR coef_block, DCTELEM * divisors,
EXTERN(void) jsimd_fdct_ifast JPP((DCTELEM * data)); DCTELEM * workspace);
EXTERN(void) jsimd_fdct_float JPP((FAST_FLOAT * data)); EXTERN(void) jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors,
FAST_FLOAT * workspace);
EXTERN(int) jsimd_can_quantize JPP((void)); EXTERN(int) jsimd_can_idct_2x2 (void);
EXTERN(int) jsimd_can_quantize_float JPP((void)); EXTERN(int) jsimd_can_idct_4x4 (void);
EXTERN(int) jsimd_can_idct_6x6 (void);
EXTERN(int) jsimd_can_idct_12x12 (void);
EXTERN(void) jsimd_quantize JPP((JCOEFPTR coef_block, EXTERN(void) jsimd_idct_2x2 (j_decompress_ptr cinfo,
DCTELEM * divisors, jpeg_component_info * compptr,
DCTELEM * workspace)); JCOEFPTR coef_block, JSAMPARRAY output_buf,
EXTERN(void) jsimd_quantize_float JPP((JCOEFPTR coef_block, JDIMENSION output_col);
FAST_FLOAT * divisors, EXTERN(void) jsimd_idct_4x4 (j_decompress_ptr cinfo,
FAST_FLOAT * workspace)); jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col);
EXTERN(void) jsimd_idct_6x6 (j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col);
EXTERN(void) jsimd_idct_12x12 (j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col);
EXTERN(int) jsimd_can_idct_2x2 JPP((void)); EXTERN(int) jsimd_can_idct_islow (void);
EXTERN(int) jsimd_can_idct_4x4 JPP((void)); EXTERN(int) jsimd_can_idct_ifast (void);
EXTERN(int) jsimd_can_idct_6x6 JPP((void)); EXTERN(int) jsimd_can_idct_float (void);
EXTERN(int) jsimd_can_idct_12x12 JPP((void));
EXTERN(void) jsimd_idct_2x2 JPP((j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JCOEFPTR coef_block,
JSAMPARRAY output_buf,
JDIMENSION output_col));
EXTERN(void) jsimd_idct_4x4 JPP((j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JCOEFPTR coef_block,
JSAMPARRAY output_buf,
JDIMENSION output_col));
EXTERN(void) jsimd_idct_6x6 JPP((j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JCOEFPTR coef_block,
JSAMPARRAY output_buf,
JDIMENSION output_col));
EXTERN(void) jsimd_idct_12x12 JPP((j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JCOEFPTR coef_block,
JSAMPARRAY output_buf,
JDIMENSION output_col));
EXTERN(int) jsimd_can_idct_islow JPP((void));
EXTERN(int) jsimd_can_idct_ifast JPP((void));
EXTERN(int) jsimd_can_idct_float JPP((void));
EXTERN(void) jsimd_idct_islow JPP((j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JCOEFPTR coef_block,
JSAMPARRAY output_buf,
JDIMENSION output_col));
EXTERN(void) jsimd_idct_ifast JPP((j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JCOEFPTR coef_block,
JSAMPARRAY output_buf,
JDIMENSION output_col));
EXTERN(void) jsimd_idct_float JPP((j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JCOEFPTR coef_block,
JSAMPARRAY output_buf,
JDIMENSION output_col));
EXTERN(void) jsimd_idct_islow (j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col);
EXTERN(void) jsimd_idct_ifast (j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col);
EXTERN(void) jsimd_idct_float (j_decompress_ptr cinfo,
jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col);

View File

@@ -17,7 +17,7 @@
LOCAL(void) LOCAL(void)
add_huff_table (j_common_ptr cinfo, add_huff_table (j_common_ptr cinfo,
JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val) JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
/* Define a Huffman table */ /* Define a Huffman table */
{ {
int nsymbols, len; int nsymbols, len;
@@ -28,7 +28,7 @@ add_huff_table (j_common_ptr cinfo,
return; return;
/* Copy the number-of-symbols-of-each-code-length counts */ /* Copy the number-of-symbols-of-each-code-length counts */
MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits)); MEMCOPY((*htblptr)->bits, bits, sizeof((*htblptr)->bits));
/* Validate the counts. We do this here mainly so we can copy the right /* Validate the counts. We do this here mainly so we can copy the right
* number of symbols from the val[] array, without risking marching off * number of symbols from the val[] array, without risking marching off
@@ -40,7 +40,7 @@ add_huff_table (j_common_ptr cinfo,
if (nsymbols < 1 || nsymbols > 256) if (nsymbols < 1 || nsymbols > 256)
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8)); MEMCOPY((*htblptr)->huffval, val, nsymbols * sizeof(UINT8));
/* Initialize sent_table FALSE so table will be written to JPEG file. */ /* Initialize sent_table FALSE so table will be written to JPEG file. */
(*htblptr)->sent_table = FALSE; (*htblptr)->sent_table = FALSE;

View File

@@ -1,8 +1,10 @@
/* /*
* jutils.c * jutils.c
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code
* relevant to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains tables and miscellaneous utility routines needed * This file contains tables and miscellaneous utility routines needed
@@ -21,7 +23,7 @@
* of a DCT block read in natural order (left to right, top to bottom). * of a DCT block read in natural order (left to right, top to bottom).
*/ */
#if 0 /* This table is not actually needed in v6a */ #if 0 /* This table is not actually needed in v6a */
const int jpeg_zigzag_order[DCTSIZE2] = { const int jpeg_zigzag_order[DCTSIZE2] = {
0, 1, 5, 6, 14, 15, 27, 28, 0, 1, 5, 6, 14, 15, 27, 28,
@@ -87,30 +89,10 @@ jround_up (long a, long b)
} }
/* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
* and coefficient-block arrays. This won't work on 80x86 because the arrays
* are FAR and we're assuming a small-pointer memory model. However, some
* DOS compilers provide far-pointer versions of memcpy() and memset() even
* in the small-model libraries. These will be used if USE_FMEM is defined.
* Otherwise, the routines below do it the hard way. (The performance cost
* is not all that great, because these routines aren't very heavily used.)
*/
#ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
#define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
#define FMEMZERO(target,size) MEMZERO(target,size)
#else /* 80x86 case, define if we can */
#ifdef USE_FMEM
#define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
#define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
#endif
#endif
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, JDIMENSION num_cols) int num_rows, JDIMENSION num_cols)
/* Copy some rows of samples from one place to another. /* Copy some rows of samples from one place to another.
* num_rows rows are copied from input_array[source_row++] * num_rows rows are copied from input_array[source_row++]
* to output_array[dest_row++]; these areas may overlap for duplication. * to output_array[dest_row++]; these areas may overlap for duplication.
@@ -118,11 +100,7 @@ jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
*/ */
{ {
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
#ifdef FMEMCOPY register size_t count = (size_t) (num_cols * sizeof(JSAMPLE));
register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
#else
register JDIMENSION count;
#endif
register int row; register int row;
input_array += source_row; input_array += source_row;
@@ -131,49 +109,24 @@ jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
for (row = num_rows; row > 0; row--) { for (row = num_rows; row > 0; row--) {
inptr = *input_array++; inptr = *input_array++;
outptr = *output_array++; outptr = *output_array++;
#ifdef FMEMCOPY MEMCOPY(outptr, inptr, count);
FMEMCOPY(outptr, inptr, count);
#else
for (count = num_cols; count > 0; count--)
*outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
#endif
} }
} }
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. */
{ {
#ifdef FMEMCOPY MEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * sizeof(JCOEF)));
FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
#else
register JCOEFPTR inptr, outptr;
register long count;
inptr = (JCOEFPTR) input_row;
outptr = (JCOEFPTR) output_row;
for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
*outptr++ = *inptr++;
}
#endif
} }
GLOBAL(void) GLOBAL(void)
jzero_far (void FAR * target, size_t bytestozero) jzero_far (void * target, size_t bytestozero)
/* Zero out a chunk of FAR 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. */
{ {
#ifdef FMEMZERO MEMZERO(target, bytestozero);
FMEMZERO(target, bytestozero);
#else
register char FAR * ptr = (char FAR *) target;
register size_t count;
for (count = bytestozero; count > 0; count--) {
*ptr++ = 0;
}
#endif
} }

View File

@@ -3,7 +3,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.
* Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2010, 2012-2014, D. R. Commander. * Copyright (C) 2010, 2012-2014, D. R. Commander.
* mozjpeg Modifications: * mozjpeg Modifications:
* Copyright (C) 2014, Mozilla Corporation. * Copyright (C) 2014, Mozilla Corporation.
@@ -15,23 +15,25 @@
#if JPEG_LIB_VERSION >= 80 #if JPEG_LIB_VERSION >= 80
#define JVERSION "8d 15-Jan-2012" #define JVERSION "8d 15-Jan-2012"
#elif JPEG_LIB_VERSION >= 70 #elif JPEG_LIB_VERSION >= 70
#define JVERSION "7 27-Jun-2009" #define JVERSION "7 27-Jun-2009"
#else #else
#define JVERSION "6b 27-Mar-1998" #define JVERSION "6b 27-Mar-1998"
#endif #endif
#define JCOPYRIGHT "Copyright (C) 1991-2012 Thomas G. Lane, Guido Vollbeding\n" \ #define JCOPYRIGHT "Copyright (C) 1991-2012 Thomas G. Lane, Guido Vollbeding\n" \
"Copyright (C) 1999-2006 MIYASAKA Masaru\n" \ "Copyright (C) 1999-2006 MIYASAKA Masaru\n" \
"Copyright (C) 2009 Pierre Ossman for Cendio AB\n" \ "Copyright (C) 2009 Pierre Ossman for Cendio AB\n" \
"Copyright (C) 2009-2014 D. R. Commander\n" \ "Copyright (C) 2009-2014 D. R. Commander\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) 2014 Mozilla Corporation\n" \ "Copyright (C) 2014 Mozilla Corporation\n" \
"Copyright (C) 2013 MIPS Technologies, Inc.\n" \ "Copyright (C) 2013-2014 MIPS Technologies, Inc.\n" \
"Copyright (C) 2013 Linaro Limited" "Copyright (C) 2013 Linaro Limited"
#define JCOPYRIGHT_SHORT "Copyright (C) 1991-2014 The libjpeg-turbo Project and many others"

File diff suppressed because it is too large Load Diff

66
rdbmp.c
View File

@@ -24,7 +24,7 @@
* This code contributed by James Arthur Boucher. * This code contributed by James Arthur Boucher.
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#ifdef BMP_SUPPORTED #ifdef BMP_SUPPORTED
@@ -33,19 +33,19 @@
#ifdef HAVE_UNSIGNED_CHAR #ifdef HAVE_UNSIGNED_CHAR
typedef unsigned char U_CHAR; typedef unsigned char U_CHAR;
#define UCH(x) ((int) (x)) #define UCH(x) ((int) (x))
#else /* !HAVE_UNSIGNED_CHAR */ #else /* !HAVE_UNSIGNED_CHAR */
#ifdef CHAR_IS_UNSIGNED #ifdef __CHAR_UNSIGNED__
typedef char U_CHAR; typedef char U_CHAR;
#define UCH(x) ((int) (x)) #define UCH(x) ((int) (x))
#else #else
typedef char U_CHAR; typedef char U_CHAR;
#define UCH(x) ((int) (x) & 0xFF) #define UCH(x) ((int) (x) & 0xFF)
#endif #endif
#endif /* HAVE_UNSIGNED_CHAR */ #endif /* HAVE_UNSIGNED_CHAR */
#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) #define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
/* Private version of data source object */ /* Private version of data source object */
@@ -55,15 +55,15 @@ typedef struct _bmp_source_struct * bmp_source_ptr;
typedef struct _bmp_source_struct { typedef struct _bmp_source_struct {
struct cjpeg_source_struct pub; /* public fields */ struct cjpeg_source_struct pub; /* public fields */
j_compress_ptr cinfo; /* back link saves passing separate parm */ j_compress_ptr cinfo; /* back link saves passing separate parm */
JSAMPARRAY colormap; /* BMP colormap (converted to my format) */ JSAMPARRAY colormap; /* BMP colormap (converted to my format) */
jvirt_sarray_ptr whole_image; /* Needed to reverse row order */ jvirt_sarray_ptr whole_image; /* Needed to reverse row order */
JDIMENSION source_row; /* Current source row number */ JDIMENSION source_row; /* Current source row number */
JDIMENSION row_width; /* Physical width of scanlines in file */ JDIMENSION row_width; /* Physical width of scanlines in file */
int bits_per_pixel; /* remembers 8- or 24-bit format */ int bits_per_pixel; /* remembers 8- or 24-bit format */
} bmp_source_struct; } bmp_source_struct;
@@ -140,7 +140,7 @@ get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
outptr = source->pub.buffer[0]; outptr = source->pub.buffer[0];
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
t = GETJSAMPLE(*inptr++); t = GETJSAMPLE(*inptr++);
*outptr++ = colormap[0][t]; /* can omit GETJSAMPLE() safely */ *outptr++ = colormap[0][t]; /* can omit GETJSAMPLE() safely */
*outptr++ = colormap[1][t]; *outptr++ = colormap[1][t];
*outptr++ = colormap[2][t]; *outptr++ = colormap[2][t];
} }
@@ -170,7 +170,7 @@ get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
inptr = image_ptr[0]; inptr = image_ptr[0];
outptr = source->pub.buffer[0]; outptr = source->pub.buffer[0];
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */ outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */
outptr[1] = *inptr++; outptr[1] = *inptr++;
outptr[0] = *inptr++; outptr[0] = *inptr++;
outptr += 3; outptr += 3;
@@ -200,10 +200,10 @@ get_32bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
inptr = image_ptr[0]; inptr = image_ptr[0];
outptr = source->pub.buffer[0]; outptr = source->pub.buffer[0];
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */ outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */
outptr[1] = *inptr++; outptr[1] = *inptr++;
outptr[0] = *inptr++; outptr[0] = *inptr++;
inptr++; /* skip the 4th byte (Alpha channel) */ inptr++; /* skip the 4th byte (Alpha channel) */
outptr += 3; outptr += 3;
} }
@@ -280,11 +280,11 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
U_CHAR bmpfileheader[14]; U_CHAR bmpfileheader[14];
U_CHAR bmpinfoheader[64]; U_CHAR bmpinfoheader[64];
#define GET_2B(array,offset) ((unsigned int) UCH(array[offset]) + \ #define GET_2B(array,offset) ((unsigned int) UCH(array[offset]) + \
(((unsigned int) UCH(array[offset+1])) << 8)) (((unsigned int) UCH(array[offset+1])) << 8))
#define GET_4B(array,offset) ((INT32) UCH(array[offset]) + \ #define GET_4B(array,offset) ((INT32) UCH(array[offset]) + \
(((INT32) UCH(array[offset+1])) << 8) + \ (((INT32) UCH(array[offset+1])) << 8) + \
(((INT32) UCH(array[offset+2])) << 16) + \ (((INT32) UCH(array[offset+2])) << 16) + \
(((INT32) UCH(array[offset+3])) << 24)) (((INT32) UCH(array[offset+3])) << 24))
INT32 bfOffBits; INT32 bfOffBits;
INT32 headerSize; INT32 headerSize;
INT32 biWidth; INT32 biWidth;
@@ -293,7 +293,7 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
INT32 biCompression; INT32 biCompression;
INT32 biXPelsPerMeter,biYPelsPerMeter; INT32 biXPelsPerMeter,biYPelsPerMeter;
INT32 biClrUsed = 0; INT32 biClrUsed = 0;
int mapentrysize = 0; /* 0 indicates no colormap */ int mapentrysize = 0; /* 0 indicates no colormap */
INT32 bPad; INT32 bPad;
JDIMENSION row_width; JDIMENSION row_width;
@@ -325,11 +325,11 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
source->bits_per_pixel = (int) GET_2B(bmpinfoheader,10); source->bits_per_pixel = (int) GET_2B(bmpinfoheader,10);
switch (source->bits_per_pixel) { switch (source->bits_per_pixel) {
case 8: /* colormapped image */ case 8: /* colormapped image */
mapentrysize = 3; /* OS/2 uses RGBTRIPLE colormap */ mapentrysize = 3; /* OS/2 uses RGBTRIPLE colormap */
TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, (int) biWidth, (int) biHeight); TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, (int) biWidth, (int) biHeight);
break; break;
case 24: /* RGB image */ case 24: /* RGB image */
TRACEMS2(cinfo, 1, JTRC_BMP_OS2, (int) biWidth, (int) biHeight); TRACEMS2(cinfo, 1, JTRC_BMP_OS2, (int) biWidth, (int) biHeight);
break; break;
default: default:
@@ -352,14 +352,14 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* biSizeImage, biClrImportant fields are ignored */ /* biSizeImage, biClrImportant fields are ignored */
switch (source->bits_per_pixel) { switch (source->bits_per_pixel) {
case 8: /* colormapped image */ case 8: /* colormapped image */
mapentrysize = 4; /* Windows uses RGBQUAD colormap */ mapentrysize = 4; /* Windows uses RGBQUAD colormap */
TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, (int) biWidth, (int) biHeight); TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, (int) biWidth, (int) biHeight);
break; break;
case 24: /* RGB image */ case 24: /* RGB image */
TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight); TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight);
break; break;
case 32: /* RGB image + Alpha channel */ case 32: /* RGB image + Alpha channel */
TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight); TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight);
break; break;
default: default:
@@ -373,7 +373,7 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* Set JFIF density parameters from the BMP data */ /* Set JFIF density parameters from the BMP data */
cinfo->X_density = (UINT16) (biXPelsPerMeter/100); /* 100 cm per meter */ cinfo->X_density = (UINT16) (biXPelsPerMeter/100); /* 100 cm per meter */
cinfo->Y_density = (UINT16) (biYPelsPerMeter/100); cinfo->Y_density = (UINT16) (biYPelsPerMeter/100);
cinfo->density_unit = 2; /* dots/cm */ cinfo->density_unit = 2; /* dots/cm */
} }
break; break;
default: default:
@@ -392,7 +392,7 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* Read the colormap, if any */ /* Read the colormap, if any */
if (mapentrysize > 0) { if (mapentrysize > 0) {
if (biClrUsed <= 0) if (biClrUsed <= 0)
biClrUsed = 256; /* assume it's 256 */ biClrUsed = 256; /* assume it's 256 */
else if (biClrUsed > 256) else if (biClrUsed > 256)
ERREXIT(cinfo, JERR_BMP_BADCMAP); ERREXIT(cinfo, JERR_BMP_BADCMAP);
/* Allocate space to store the colormap */ /* Allocate space to store the colormap */
@@ -406,7 +406,7 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
} }
/* Skip any remaining pad bytes */ /* Skip any remaining pad bytes */
if (bPad < 0) /* incorrect bfOffBits value? */ if (bPad < 0) /* incorrect bfOffBits value? */
ERREXIT(cinfo, JERR_BMP_BADHEADER); ERREXIT(cinfo, JERR_BMP_BADHEADER);
while (--bPad >= 0) { while (--bPad >= 0) {
(void) read_byte(source); (void) read_byte(source);
@@ -469,8 +469,8 @@ jinit_read_bmp (j_compress_ptr cinfo)
/* Create module interface object */ /* Create module interface object */
source = (bmp_source_ptr) source = (bmp_source_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(bmp_source_struct)); sizeof(bmp_source_struct));
source->cinfo = cinfo; /* make back link for subroutines */ source->cinfo = cinfo; /* make back link for subroutines */
/* Fill in method ptrs, except get_pixel_rows which start_input sets */ /* Fill in method ptrs, except get_pixel_rows which start_input sets */
source->pub.start_input = start_input_bmp; source->pub.start_input = start_input_bmp;
source->pub.finish_input = finish_input_bmp; source->pub.finish_input = finish_input_bmp;

View File

@@ -21,9 +21,9 @@
* currently implemented. * currently implemented.
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ #ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */
/* Portions of this code are based on the PBMPLUS library, which is: /* Portions of this code are based on the PBMPLUS library, which is:
** **
@@ -54,9 +54,9 @@ add_map_entry (j_decompress_ptr cinfo, int R, int G, int B)
/* Check for duplicate color. */ /* Check for duplicate color. */
for (index = 0; index < ncolors; index++) { for (index = 0; index < ncolors; index++) {
if (GETJSAMPLE(colormap0[index]) == R && if (GETJSAMPLE(colormap0[index]) == R &&
GETJSAMPLE(colormap1[index]) == G && GETJSAMPLE(colormap1[index]) == G &&
GETJSAMPLE(colormap2[index]) == B) GETJSAMPLE(colormap2[index]) == B)
return; /* color is already in map */ return; /* color is already in map */
} }
/* Check for map overflow. */ /* Check for map overflow. */
@@ -107,9 +107,9 @@ read_gif_map (j_decompress_ptr cinfo, FILE * infile)
if (R == EOF || G == EOF || B == EOF) if (R == EOF || G == EOF || B == EOF)
ERREXIT(cinfo, JERR_BAD_CMAP_FILE); ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
add_map_entry(cinfo, add_map_entry(cinfo,
R << (BITS_IN_JSAMPLE-8), R << (BITS_IN_JSAMPLE-8),
G << (BITS_IN_JSAMPLE-8), G << (BITS_IN_JSAMPLE-8),
B << (BITS_IN_JSAMPLE-8)); B << (BITS_IN_JSAMPLE-8));
} }
} }
@@ -175,7 +175,7 @@ read_ppm_map (j_decompress_ptr cinfo, FILE * infile)
int R, G, B; int R, G, B;
/* Initial 'P' has already been read by read_color_map */ /* Initial 'P' has already been read by read_color_map */
c = getc(infile); /* save format discriminator for a sec */ c = getc(infile); /* save format discriminator for a sec */
/* while we fetch the remaining header info */ /* while we fetch the remaining header info */
w = read_pbm_integer(cinfo, infile); w = read_pbm_integer(cinfo, infile);
@@ -190,26 +190,26 @@ read_ppm_map (j_decompress_ptr cinfo, FILE * infile)
ERREXIT(cinfo, JERR_BAD_CMAP_FILE); ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
switch (c) { switch (c) {
case '3': /* it's a text-format PPM file */ case '3': /* it's a text-format PPM file */
for (row = 0; row < h; row++) { for (row = 0; row < h; row++) {
for (col = 0; col < w; col++) { for (col = 0; col < w; col++) {
R = read_pbm_integer(cinfo, infile); R = read_pbm_integer(cinfo, infile);
G = read_pbm_integer(cinfo, infile); G = read_pbm_integer(cinfo, infile);
B = read_pbm_integer(cinfo, infile); B = read_pbm_integer(cinfo, infile);
add_map_entry(cinfo, R, G, B); add_map_entry(cinfo, R, G, B);
} }
} }
break; break;
case '6': /* it's a raw-format PPM file */ case '6': /* it's a raw-format PPM file */
for (row = 0; row < h; row++) { for (row = 0; row < h; row++) {
for (col = 0; col < w; col++) { for (col = 0; col < w; col++) {
R = getc(infile); R = getc(infile);
G = getc(infile); G = getc(infile);
B = getc(infile); B = getc(infile);
if (R == EOF || G == EOF || B == EOF) if (R == EOF || G == EOF || B == EOF)
ERREXIT(cinfo, JERR_BAD_CMAP_FILE); ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
add_map_entry(cinfo, R, G, B); add_map_entry(cinfo, R, G, B);
} }
} }
break; break;

View File

@@ -19,7 +19,7 @@
* CompuServe Incorporated." * CompuServe Incorporated."
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#ifdef GIF_SUPPORTED #ifdef GIF_SUPPORTED
@@ -32,7 +32,7 @@ jinit_read_gif (j_compress_ptr cinfo)
{ {
fprintf(stderr, "GIF input is unsupported for legal reasons. Sorry.\n"); fprintf(stderr, "GIF input is unsupported for legal reasons. Sorry.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
return NULL; /* keep compiler happy */ return NULL; /* keep compiler happy */
} }
#endif /* GIF_SUPPORTED */ #endif /* GIF_SUPPORTED */

View File

@@ -150,7 +150,7 @@ jinit_read_jpeg (j_compress_ptr cinfo)
/* Create module interface object */ /* Create module interface object */
source = (jpeg_source_ptr) source = (jpeg_source_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(jpeg_source_struct)); sizeof(jpeg_source_struct));
source->cinfo = cinfo; /* make back link for subroutines */ source->cinfo = cinfo; /* make back link for subroutines */
/* Fill in method ptrs, except get_pixel_rows which start_input sets */ /* Fill in method ptrs, except get_pixel_rows which start_input sets */
source->pub.start_input = start_input_jpeg; source->pub.start_input = start_input_jpeg;

View File

@@ -1,9 +1,11 @@
/* /*
* rdjpgcom.c * rdjpgcom.c
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1997, Thomas G. Lane. * Copyright (C) 1994-1997, Thomas G. Lane.
* Modified 2009 by Bill Allombert, Guido Vollbeding. * Modified 2009 by Bill Allombert, Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains a very simple stand-alone application that displays * This file contains a very simple stand-alone application that displays
@@ -12,49 +14,41 @@
* JPEG markers. * JPEG markers.
*/ */
#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */ #define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */
#include "jinclude.h" /* get auto-config symbols, <stdio.h> */ #include "jinclude.h" /* get auto-config symbols, <stdio.h> */
#ifdef HAVE_LOCALE_H #ifdef HAVE_LOCALE_H
#include <locale.h> /* Bill Allombert: use locale for isprint */ #include <locale.h> /* Bill Allombert: use locale for isprint */
#endif #endif
#include <ctype.h> /* to declare isupper(), tolower() */ #include <ctype.h> /* to declare isupper(), tolower() */
#ifdef USE_SETMODE #ifdef USE_SETMODE
#include <fcntl.h> /* to declare setmode()'s parameter macros */ #include <fcntl.h> /* to declare setmode()'s parameter macros */
/* If you have setmode() but not <io.h>, just delete this line: */ /* If you have setmode() but not <io.h>, just delete this line: */
#include <io.h> /* to declare setmode() */ #include <io.h> /* to declare setmode() */
#endif #endif
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ #ifdef USE_CCOMMAND /* command-line reader for Macintosh */
#ifdef __MWERKS__ #ifdef __MWERKS__
#include <SIOUX.h> /* Metrowerks needs this */ #include <SIOUX.h> /* Metrowerks needs this */
#include <console.h> /* ... and this */ #include <console.h> /* ... and this */
#endif #endif
#ifdef THINK_C #ifdef THINK_C
#include <console.h> /* Think declares it here */ #include <console.h> /* Think declares it here */
#endif #endif
#endif #endif
#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
#define READ_BINARY "r" #define READ_BINARY "r"
#else #else
#ifdef VMS /* VMS is very nonstandard */ #define READ_BINARY "rb"
#define READ_BINARY "rb", "ctx=stm"
#else /* standard ANSI-compliant case */
#define READ_BINARY "rb"
#endif
#endif #endif
#ifndef EXIT_FAILURE /* define exit() codes if not provided */ #ifndef EXIT_FAILURE /* define exit() codes if not provided */
#define EXIT_FAILURE 1 #define EXIT_FAILURE 1
#endif #endif
#ifndef EXIT_SUCCESS #ifndef EXIT_SUCCESS
#ifdef VMS
#define EXIT_SUCCESS 1 /* VMS is very nonstandard */
#else
#define EXIT_SUCCESS 0 #define EXIT_SUCCESS 0
#endif #endif
#endif
/* /*
@@ -62,7 +56,7 @@
* To reuse this code in another application, you might need to change these. * To reuse this code in another application, you might need to change these.
*/ */
static FILE * infile; /* input JPEG file */ static FILE * infile; /* input JPEG file */
/* Return next input byte, or EOF if no more */ /* Return next input byte, or EOF if no more */
#define NEXTBYTE() getc(infile) #define NEXTBYTE() getc(infile)
@@ -107,11 +101,11 @@ read_2_bytes (void)
* in this program. (See jdmarker.c for a more complete list.) * in this program. (See jdmarker.c for a more complete list.)
*/ */
#define M_SOF0 0xC0 /* Start Of Frame N */ #define M_SOF0 0xC0 /* Start Of Frame N */
#define M_SOF1 0xC1 /* N indicates which compression process */ #define M_SOF1 0xC1 /* N indicates which compression process */
#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */ #define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
#define M_SOF3 0xC3 #define M_SOF3 0xC3
#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */ #define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
#define M_SOF6 0xC6 #define M_SOF6 0xC6
#define M_SOF7 0xC7 #define M_SOF7 0xC7
#define M_SOF9 0xC9 #define M_SOF9 0xC9
@@ -120,12 +114,12 @@ read_2_bytes (void)
#define M_SOF13 0xCD #define M_SOF13 0xCD
#define M_SOF14 0xCE #define M_SOF14 0xCE
#define M_SOF15 0xCF #define M_SOF15 0xCF
#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */ #define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */
#define M_EOI 0xD9 /* End Of Image (end of datastream) */ #define M_EOI 0xD9 /* End Of Image (end of datastream) */
#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */ #define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
#define M_APP0 0xE0 /* Application-specific marker, type N */ #define M_APP0 0xE0 /* Application-specific marker, type N */
#define M_APP12 0xEC /* (we don't bother to list all 16 APPn's) */ #define M_APP12 0xEC /* (we don't bother to list all 16 APPn's) */
#define M_COM 0xFE /* COMment */ #define M_COM 0xFE /* COMment */
/* /*
@@ -253,7 +247,7 @@ process_COM (int raw)
printf("\n"); printf("\n");
} else if (ch == '\n') { } else if (ch == '\n') {
if (lastch != '\r') if (lastch != '\r')
printf("\n"); printf("\n");
} else if (ch == '\\') { } else if (ch == '\\') {
printf("\\\\"); printf("\\\\");
} else if (isprint(ch)) { } else if (isprint(ch)) {
@@ -287,7 +281,7 @@ process_SOFn (int marker)
const char * process; const char * process;
int ci; int ci;
length = read_2_bytes(); /* usual parameter length count */ length = read_2_bytes(); /* usual parameter length count */
data_precision = read_1_byte(); data_precision = read_1_byte();
image_height = read_2_bytes(); image_height = read_2_bytes();
@@ -295,33 +289,33 @@ process_SOFn (int marker)
num_components = read_1_byte(); num_components = read_1_byte();
switch (marker) { switch (marker) {
case M_SOF0: process = "Baseline"; break; case M_SOF0: process = "Baseline"; break;
case M_SOF1: process = "Extended sequential"; break; case M_SOF1: process = "Extended sequential"; break;
case M_SOF2: process = "Progressive"; break; case M_SOF2: process = "Progressive"; break;
case M_SOF3: process = "Lossless"; break; case M_SOF3: process = "Lossless"; break;
case M_SOF5: process = "Differential sequential"; break; case M_SOF5: process = "Differential sequential"; break;
case M_SOF6: process = "Differential progressive"; break; case M_SOF6: process = "Differential progressive"; break;
case M_SOF7: process = "Differential lossless"; break; case M_SOF7: process = "Differential lossless"; break;
case M_SOF9: process = "Extended sequential, arithmetic coding"; break; case M_SOF9: process = "Extended sequential, arithmetic coding"; break;
case M_SOF10: process = "Progressive, arithmetic coding"; break; case M_SOF10: process = "Progressive, arithmetic coding"; break;
case M_SOF11: process = "Lossless, arithmetic coding"; break; case M_SOF11: process = "Lossless, arithmetic coding"; break;
case M_SOF13: process = "Differential sequential, arithmetic coding"; break; case M_SOF13: process = "Differential sequential, arithmetic coding"; break;
case M_SOF14: process = "Differential progressive, arithmetic coding"; break; case M_SOF14: process = "Differential progressive, arithmetic coding"; break;
case M_SOF15: process = "Differential lossless, arithmetic coding"; break; case M_SOF15: process = "Differential lossless, arithmetic coding"; break;
default: process = "Unknown"; break; default: process = "Unknown"; break;
} }
printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n", printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n",
image_width, image_height, num_components, data_precision); image_width, image_height, num_components, data_precision);
printf("JPEG process: %s\n", process); printf("JPEG process: %s\n", process);
if (length != (unsigned int) (8 + num_components * 3)) if (length != (unsigned int) (8 + num_components * 3))
ERREXIT("Bogus SOF marker length"); ERREXIT("Bogus SOF marker length");
for (ci = 0; ci < num_components; ci++) { for (ci = 0; ci < num_components; ci++) {
(void) read_1_byte(); /* Component ID code */ (void) read_1_byte(); /* Component ID code */
(void) read_1_byte(); /* H, V sampling factors */ (void) read_1_byte(); /* H, V sampling factors */
(void) read_1_byte(); /* Quantization table number */ (void) read_1_byte(); /* Quantization table number */
} }
} }
@@ -352,29 +346,29 @@ scan_JPEG_header (int verbose, int raw)
/* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be, /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be,
* treated as SOFn. C4 in particular is actually DHT. * treated as SOFn. C4 in particular is actually DHT.
*/ */
case M_SOF0: /* Baseline */ case M_SOF0: /* Baseline */
case M_SOF1: /* Extended sequential, Huffman */ case M_SOF1: /* Extended sequential, Huffman */
case M_SOF2: /* Progressive, Huffman */ case M_SOF2: /* Progressive, Huffman */
case M_SOF3: /* Lossless, Huffman */ case M_SOF3: /* Lossless, Huffman */
case M_SOF5: /* Differential sequential, Huffman */ case M_SOF5: /* Differential sequential, Huffman */
case M_SOF6: /* Differential progressive, Huffman */ case M_SOF6: /* Differential progressive, Huffman */
case M_SOF7: /* Differential lossless, Huffman */ case M_SOF7: /* Differential lossless, Huffman */
case M_SOF9: /* Extended sequential, arithmetic */ case M_SOF9: /* Extended sequential, arithmetic */
case M_SOF10: /* Progressive, arithmetic */ case M_SOF10: /* Progressive, arithmetic */
case M_SOF11: /* Lossless, arithmetic */ case M_SOF11: /* Lossless, arithmetic */
case M_SOF13: /* Differential sequential, arithmetic */ case M_SOF13: /* Differential sequential, arithmetic */
case M_SOF14: /* Differential progressive, arithmetic */ case M_SOF14: /* Differential progressive, arithmetic */
case M_SOF15: /* Differential lossless, arithmetic */ case M_SOF15: /* Differential lossless, arithmetic */
if (verbose) if (verbose)
process_SOFn(marker); process_SOFn(marker);
else else
skip_variable(); skip_variable();
break; break;
case M_SOS: /* stop before hitting compressed data */ case M_SOS: /* stop before hitting compressed data */
return marker; return marker;
case M_EOI: /* in case it's a tables-only JPEG stream */ case M_EOI: /* in case it's a tables-only JPEG stream */
return marker; return marker;
case M_COM: case M_COM:
@@ -386,14 +380,14 @@ scan_JPEG_header (int verbose, int raw)
* APP12 markers, so we print those out too when in -verbose mode. * APP12 markers, so we print those out too when in -verbose mode.
*/ */
if (verbose) { if (verbose) {
printf("APP12 contains:\n"); printf("APP12 contains:\n");
process_COM(raw); process_COM(raw);
} else } else
skip_variable(); skip_variable();
break; break;
default: /* Anything else just gets skipped */ default: /* Anything else just gets skipped */
skip_variable(); /* we assume it has a parameter count... */ skip_variable(); /* we assume it has a parameter count... */
break; break;
} }
} /* end loop */ } /* end loop */
@@ -402,7 +396,7 @@ scan_JPEG_header (int verbose, int raw)
/* Command line parsing code */ /* Command line parsing code */
static const char * progname; /* program name for error messages */ static const char * progname; /* program name for error messages */
static void static void
@@ -432,17 +426,17 @@ keymatch (char * arg, const char * keyword, int minchars)
while ((ca = *arg++) != '\0') { while ((ca = *arg++) != '\0') {
if ((ck = *keyword++) == '\0') if ((ck = *keyword++) == '\0')
return 0; /* arg longer than keyword, no good */ return 0; /* arg longer than keyword, no good */
if (isupper(ca)) /* force arg to lcase (assume ck is already) */ if (isupper(ca)) /* force arg to lcase (assume ck is already) */
ca = tolower(ca); ca = tolower(ca);
if (ca != ck) if (ca != ck)
return 0; /* no good */ return 0; /* no good */
nmatched++; /* count matched characters */ nmatched++; /* count matched characters */
} }
/* reached end of argument; fail if it's too short for unique abbrev */ /* reached end of argument; fail if it's too short for unique abbrev */
if (nmatched < minchars) if (nmatched < minchars)
return 0; return 0;
return 1; /* A-OK */ return 1; /* A-OK */
} }
@@ -464,14 +458,14 @@ main (int argc, char **argv)
progname = argv[0]; progname = argv[0];
if (progname == NULL || progname[0] == 0) if (progname == NULL || progname[0] == 0)
progname = "rdjpgcom"; /* in case C library doesn't provide it */ progname = "rdjpgcom"; /* in case C library doesn't provide it */
/* Parse switches, if any */ /* Parse switches, if any */
for (argn = 1; argn < argc; argn++) { for (argn = 1; argn < argc; argn++) {
arg = argv[argn]; arg = argv[argn];
if (arg[0] != '-') if (arg[0] != '-')
break; /* not switch, must be file name */ break; /* not switch, must be file name */
arg++; /* advance over '-' */ arg++; /* advance over '-' */
if (keymatch(arg, "verbose", 1)) { if (keymatch(arg, "verbose", 1)) {
verbose++; verbose++;
} else if (keymatch(arg, "raw", 1)) { } else if (keymatch(arg, "raw", 1)) {
@@ -493,10 +487,10 @@ main (int argc, char **argv)
} }
} else { } else {
/* default input file is stdin */ /* default input file is stdin */
#ifdef USE_SETMODE /* need to hack file mode? */ #ifdef USE_SETMODE /* need to hack file mode? */
setmode(fileno(stdin), O_BINARY); setmode(fileno(stdin), O_BINARY);
#endif #endif
#ifdef USE_FDOPEN /* need to re-open in binary mode? */ #ifdef USE_FDOPEN /* need to re-open in binary mode? */
if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) { if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
fprintf(stderr, "%s: can't open stdin\n", progname); fprintf(stderr, "%s: can't open stdin\n", progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@@ -511,5 +505,5 @@ main (int argc, char **argv)
/* All done. */ /* All done. */
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
return 0; /* suppress no-return-value warnings */ return 0; /* suppress no-return-value warnings */
} }

71
rdppm.c
View File

@@ -1,9 +1,11 @@
/* /*
* rdppm.c * rdppm.c
* *
* 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.
* Modified 2009 by Bill Allombert, Guido Vollbeding. * Modified 2009 by Bill Allombert, Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code and
* information relevant to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains routines to read input images in PPM/PGM format. * This file contains routines to read input images in PPM/PGM format.
@@ -19,7 +21,7 @@
* the file is indeed PPM format). * the file is indeed PPM format).
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#ifdef PPM_SUPPORTED #ifdef PPM_SUPPORTED
@@ -41,30 +43,19 @@
#ifdef HAVE_UNSIGNED_CHAR #ifdef HAVE_UNSIGNED_CHAR
typedef unsigned char U_CHAR; typedef unsigned char U_CHAR;
#define UCH(x) ((int) (x)) #define UCH(x) ((int) (x))
#else /* !HAVE_UNSIGNED_CHAR */ #else /* !HAVE_UNSIGNED_CHAR */
#ifdef CHAR_IS_UNSIGNED #ifdef __CHAR_UNSIGNED__
typedef char U_CHAR; typedef char U_CHAR;
#define UCH(x) ((int) (x)) #define UCH(x) ((int) (x))
#else #else
typedef char U_CHAR; typedef char U_CHAR;
#define UCH(x) ((int) (x) & 0xFF) #define UCH(x) ((int) (x) & 0xFF)
#endif #endif
#endif /* HAVE_UNSIGNED_CHAR */ #endif /* HAVE_UNSIGNED_CHAR */
#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) #define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
/*
* On most systems, reading individual bytes with getc() is drastically less
* efficient than buffering a row at a time with fread(). On PCs, we must
* allocate the buffer in near data space, because we are assuming small-data
* memory model, wherein fread() can't reach far memory. If you need to
* process very wide images on a PC, you might have to compile in large-memory
* model, or else replace fread() with a getc() loop --- which will be much
* slower.
*/
/* Private version of data source object */ /* Private version of data source object */
@@ -72,10 +63,11 @@ typedef char U_CHAR;
typedef struct { typedef struct {
struct cjpeg_source_struct pub; /* public fields */ struct cjpeg_source_struct pub; /* public fields */
U_CHAR *iobuffer; /* non-FAR pointer to I/O buffer */ /* Usually these two pointers point to the same place: */
JSAMPROW pixrow; /* FAR pointer to same */ U_CHAR *iobuffer; /* fread's I/O buffer */
size_t buffer_width; /* width of I/O buffer */ JSAMPROW pixrow; /* compressor input buffer */
JSAMPLE *rescale; /* => maxval-remapping array, or NULL */ size_t buffer_width; /* width of I/O buffer */
JSAMPLE *rescale; /* => maxval-remapping array, or NULL */
} ppm_source_struct; } ppm_source_struct;
typedef ppm_source_struct * ppm_source_ptr; typedef ppm_source_struct * ppm_source_ptr;
@@ -308,10 +300,10 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* detect unsupported variants (ie, PBM) before trying to read header */ /* detect unsupported variants (ie, PBM) before trying to read header */
switch (c) { switch (c) {
case '2': /* it's a text-format PGM file */ case '2': /* it's a text-format PGM file */
case '3': /* it's a text-format PPM file */ case '3': /* it's a text-format PPM file */
case '5': /* it's a raw-format PGM file */ case '5': /* it's a raw-format PGM file */
case '6': /* it's a raw-format PPM file */ case '6': /* it's a raw-format PPM file */
break; break;
default: default:
ERREXIT(cinfo, JERR_PPM_NOT); ERREXIT(cinfo, JERR_PPM_NOT);
@@ -331,12 +323,12 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
cinfo->image_height = (JDIMENSION) h; cinfo->image_height = (JDIMENSION) h;
/* initialize flags to most common settings */ /* initialize flags to most common settings */
need_iobuffer = TRUE; /* do we need an I/O buffer? */ need_iobuffer = TRUE; /* do we need an I/O buffer? */
use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */
need_rescale = TRUE; /* do we need a rescale array? */ need_rescale = TRUE; /* do we need a rescale array? */
switch (c) { switch (c) {
case '2': /* it's a text-format PGM file */ case '2': /* it's a text-format PGM file */
cinfo->input_components = 1; cinfo->input_components = 1;
cinfo->in_color_space = JCS_GRAYSCALE; cinfo->in_color_space = JCS_GRAYSCALE;
TRACEMS2(cinfo, 1, JTRC_PGM_TEXT, w, h); TRACEMS2(cinfo, 1, JTRC_PGM_TEXT, w, h);
@@ -344,7 +336,7 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
need_iobuffer = FALSE; need_iobuffer = FALSE;
break; break;
case '3': /* it's a text-format PPM file */ case '3': /* it's a text-format PPM file */
cinfo->input_components = 3; cinfo->input_components = 3;
cinfo->in_color_space = JCS_RGB; cinfo->in_color_space = JCS_RGB;
TRACEMS2(cinfo, 1, JTRC_PPM_TEXT, w, h); TRACEMS2(cinfo, 1, JTRC_PPM_TEXT, w, h);
@@ -352,13 +344,13 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
need_iobuffer = FALSE; need_iobuffer = FALSE;
break; break;
case '5': /* it's a raw-format PGM file */ case '5': /* it's a raw-format PGM file */
cinfo->input_components = 1; cinfo->input_components = 1;
cinfo->in_color_space = JCS_GRAYSCALE; cinfo->in_color_space = JCS_GRAYSCALE;
TRACEMS2(cinfo, 1, JTRC_PGM, w, h); TRACEMS2(cinfo, 1, JTRC_PGM, w, h);
if (maxval > 255) { if (maxval > 255) {
source->pub.get_pixel_rows = get_word_gray_row; source->pub.get_pixel_rows = get_word_gray_row;
} else if (maxval == MAXJSAMPLE && SIZEOF(JSAMPLE) == SIZEOF(U_CHAR)) { } else if (maxval == MAXJSAMPLE && sizeof(JSAMPLE) == sizeof(U_CHAR)) {
source->pub.get_pixel_rows = get_raw_row; source->pub.get_pixel_rows = get_raw_row;
use_raw_buffer = TRUE; use_raw_buffer = TRUE;
need_rescale = FALSE; need_rescale = FALSE;
@@ -367,13 +359,13 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
} }
break; break;
case '6': /* it's a raw-format PPM file */ case '6': /* it's a raw-format PPM file */
cinfo->input_components = 3; cinfo->input_components = 3;
cinfo->in_color_space = JCS_RGB; cinfo->in_color_space = JCS_RGB;
TRACEMS2(cinfo, 1, JTRC_PPM, w, h); TRACEMS2(cinfo, 1, JTRC_PPM, w, h);
if (maxval > 255) { if (maxval > 255) {
source->pub.get_pixel_rows = get_word_rgb_row; source->pub.get_pixel_rows = get_word_rgb_row;
} else if (maxval == MAXJSAMPLE && SIZEOF(JSAMPLE) == SIZEOF(U_CHAR)) { } else if (maxval == MAXJSAMPLE && sizeof(JSAMPLE) == sizeof(U_CHAR)) {
source->pub.get_pixel_rows = get_raw_row; source->pub.get_pixel_rows = get_raw_row;
use_raw_buffer = TRUE; use_raw_buffer = TRUE;
need_rescale = FALSE; need_rescale = FALSE;
@@ -386,17 +378,16 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
if (need_iobuffer) { if (need_iobuffer) {
source->buffer_width = (size_t) w * cinfo->input_components * source->buffer_width = (size_t) w * cinfo->input_components *
((maxval<=255) ? SIZEOF(U_CHAR) : (2*SIZEOF(U_CHAR))); ((maxval<=255) ? sizeof(U_CHAR) : (2*sizeof(U_CHAR)));
source->iobuffer = (U_CHAR *) source->iobuffer = (U_CHAR *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
source->buffer_width); source->buffer_width);
} }
/* Create compressor input buffer. */ /* Create compressor input buffer. */
if (use_raw_buffer) { if (use_raw_buffer) {
/* For unscaled raw-input case, we can just map it onto the I/O buffer. */ /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
/* Synthesize a JSAMPARRAY pointer structure */ /* Synthesize a JSAMPARRAY pointer structure */
/* Cast here implies near->far pointer conversion on PCs */
source->pixrow = (JSAMPROW) source->iobuffer; source->pixrow = (JSAMPROW) source->iobuffer;
source->pub.buffer = & source->pixrow; source->pub.buffer = & source->pixrow;
source->pub.buffer_height = 1; source->pub.buffer_height = 1;
@@ -415,7 +406,7 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* On 16-bit-int machines we have to be careful of maxval = 65535 */ /* On 16-bit-int machines we have to be careful of maxval = 65535 */
source->rescale = (JSAMPLE *) source->rescale = (JSAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(size_t) (((long) maxval + 1L) * SIZEOF(JSAMPLE))); (size_t) (((long) maxval + 1L) * sizeof(JSAMPLE)));
half_maxval = maxval / 2; half_maxval = maxval / 2;
for (val = 0; val <= (INT32) maxval; val++) { for (val = 0; val <= (INT32) maxval; val++) {
/* The multiplication here must be done in 32 bits to avoid overflow */ /* The multiplication here must be done in 32 bits to avoid overflow */
@@ -448,7 +439,7 @@ jinit_read_ppm (j_compress_ptr cinfo)
/* Create module interface object */ /* Create module interface object */
source = (ppm_source_ptr) source = (ppm_source_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(ppm_source_struct)); sizeof(ppm_source_struct));
/* Fill in method ptrs, except get_pixel_rows which start_input sets */ /* Fill in method ptrs, except get_pixel_rows which start_input sets */
source->pub.start_input = start_input_ppm; source->pub.start_input = start_input_ppm;
source->pub.finish_input = finish_input_ppm; source->pub.finish_input = finish_input_ppm;

19
rdrle.c
View File

@@ -1,8 +1,10 @@
/* /*
* rdrle.c * rdrle.c
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code and
* information relevant to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains routines to read input images in Utah RLE format. * This file contains routines to read input images in Utah RLE format.
@@ -19,7 +21,7 @@
* with updates from Robert Hutchinson. * with updates from Robert Hutchinson.
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#ifdef RLE_SUPPORTED #ifdef RLE_SUPPORTED
@@ -66,7 +68,7 @@ typedef struct _rle_source_struct {
rle_kind visual; /* actual type of input file */ rle_kind visual; /* actual type of input file */
jvirt_sarray_ptr image; /* virtual array to hold the image */ jvirt_sarray_ptr image; /* virtual array to hold the image */
JDIMENSION row; /* current row # in the virtual array */ JDIMENSION row; /* current row # in the virtual array */
rle_hdr header; /* Input file information */ rle_hdr header; /* Input file information */
rle_pixel** rle_row; /* holds a row returned by rle_getrow() */ rle_pixel** rle_row; /* holds a row returned by rle_getrow() */
@@ -114,7 +116,7 @@ start_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
width = source->header.xmax - source->header.xmin + 1; width = source->header.xmax - source->header.xmin + 1;
height = source->header.ymax - source->header.ymin + 1; height = source->header.ymax - source->header.ymin + 1;
source->header.xmin = 0; /* realign horizontally */ source->header.xmin = 0; /* realign horizontally */
source->header.xmax = width-1; source->header.xmax = width-1;
cinfo->image_width = width; cinfo->image_width = width;
@@ -131,11 +133,11 @@ start_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
} else if (source->header.ncolors == 1 && source->header.ncmap == 3) { } else if (source->header.ncolors == 1 && source->header.ncmap == 3) {
source->visual = PSEUDOCOLOR; source->visual = PSEUDOCOLOR;
TRACEMS3(cinfo, 1, JTRC_RLE_MAPPED, width, height, TRACEMS3(cinfo, 1, JTRC_RLE_MAPPED, width, height,
1 << source->header.cmaplen); 1 << source->header.cmaplen);
} else if (source->header.ncolors == 3 && source->header.ncmap == 3) { } else if (source->header.ncolors == 3 && source->header.ncmap == 3) {
source->visual = TRUECOLOR; source->visual = TRUECOLOR;
TRACEMS3(cinfo, 1, JTRC_RLE_FULLMAP, width, height, TRACEMS3(cinfo, 1, JTRC_RLE_FULLMAP, width, height,
1 << source->header.cmaplen); 1 << source->header.cmaplen);
} else if (source->header.ncolors == 3 && source->header.ncmap == 0) { } else if (source->header.ncolors == 3 && source->header.ncmap == 0) {
source->visual = DIRECTCOLOR; source->visual = DIRECTCOLOR;
TRACEMS2(cinfo, 1, JTRC_RLE, width, height); TRACEMS2(cinfo, 1, JTRC_RLE, width, height);
@@ -254,8 +256,7 @@ load_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
rle_row = source->rle_row; rle_row = source->rle_row;
/* Read the RLE data into our virtual array. /* Read the RLE data into our virtual array.
* We assume here that (a) rle_pixel is represented the same as JSAMPLE, * We assume here that rle_pixel is represented the same as JSAMPLE.
* and (b) we are not on a machine where FAR pointers differ from regular.
*/ */
RLE_CLR_BIT(source->header, RLE_ALPHA); /* don't read the alpha channel */ RLE_CLR_BIT(source->header, RLE_ALPHA); /* don't read the alpha channel */
@@ -375,7 +376,7 @@ jinit_read_rle (j_compress_ptr cinfo)
/* Create module interface object */ /* Create module interface object */
source = (rle_source_ptr) source = (rle_source_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(rle_source_struct)); sizeof(rle_source_struct));
/* Fill in method ptrs */ /* Fill in method ptrs */
source->pub.start_input = start_input_rle; source->pub.start_input = start_input_rle;
source->pub.finish_input = finish_input_rle; source->pub.finish_input = finish_input_rle;

View File

@@ -9,15 +9,15 @@
* *
* This file contains routines to process some of cjpeg's more complicated * This file contains routines to process some of cjpeg's more complicated
* command-line switches. Switches processed here are: * command-line switches. Switches processed here are:
* -qtables file Read quantization tables from text file * -qtables file Read quantization tables from text file
* -scans file Read scan script from text file * -scans file Read scan script from text file
* -quality N[,N,...] Set quality ratings * -quality N[,N,...] Set quality ratings
* -qslots N[,N,...] Set component quantization table selectors * -qslots N[,N,...] Set component quantization table selectors
* -sample HxV[,HxV,...] Set component sampling factors * -sample HxV[,HxV,...] Set component sampling factors
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include <ctype.h> /* to declare isdigit(), isspace() */ #include <ctype.h> /* to declare isdigit(), isspace() */
LOCAL(int) LOCAL(int)
@@ -108,15 +108,15 @@ read_quant_tables (j_compress_ptr cinfo, char * filename, boolean force_baseline
table[0] = (unsigned int) val; table[0] = (unsigned int) val;
for (i = 1; i < DCTSIZE2; i++) { for (i = 1; i < DCTSIZE2; i++) {
if (! read_text_integer(fp, &val, &termchar)) { if (! read_text_integer(fp, &val, &termchar)) {
fprintf(stderr, "Invalid table data in file %s\n", filename); fprintf(stderr, "Invalid table data in file %s\n", filename);
fclose(fp); fclose(fp);
return FALSE; return FALSE;
} }
table[i] = (unsigned int) val; table[i] = (unsigned int) val;
} }
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno], jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno],
force_baseline); force_baseline);
#else #else
jpeg_add_quant_table(cinfo, tblno, table, q_scale_factor[tblno], jpeg_add_quant_table(cinfo, tblno, table, q_scale_factor[tblno],
force_baseline); force_baseline);
@@ -150,7 +150,7 @@ read_scan_integer (FILE * file, long * result, int * termchar)
ch = *termchar; ch = *termchar;
while (ch != EOF && isspace(ch)) while (ch != EOF && isspace(ch))
ch = text_getc(file); ch = text_getc(file);
if (isdigit(ch)) { /* oops, put it back */ if (isdigit(ch)) { /* oops, put it back */
if (ungetc(ch, file) == EOF) if (ungetc(ch, file) == EOF)
return FALSE; return FALSE;
ch = ' '; ch = ' ';
@@ -188,7 +188,7 @@ read_scan_script (j_compress_ptr cinfo, char * filename)
int scanno, ncomps, termchar; int scanno, ncomps, termchar;
long val; long val;
jpeg_scan_info * scanptr; jpeg_scan_info * scanptr;
#define MAX_SCANS 100 /* quite arbitrary limit */ #define MAX_SCANS 100 /* quite arbitrary limit */
jpeg_scan_info scans[MAX_SCANS]; jpeg_scan_info scans[MAX_SCANS];
if ((fp = fopen(filename, "r")) == NULL) { if ((fp = fopen(filename, "r")) == NULL) {
@@ -208,29 +208,29 @@ read_scan_script (j_compress_ptr cinfo, char * filename)
ncomps = 1; ncomps = 1;
while (termchar == ' ') { while (termchar == ' ') {
if (ncomps >= MAX_COMPS_IN_SCAN) { if (ncomps >= MAX_COMPS_IN_SCAN) {
fprintf(stderr, "Too many components in one scan in file %s\n", fprintf(stderr, "Too many components in one scan in file %s\n",
filename); filename);
fclose(fp); fclose(fp);
return FALSE; return FALSE;
} }
if (! read_scan_integer(fp, &val, &termchar)) if (! read_scan_integer(fp, &val, &termchar))
goto bogus; goto bogus;
scanptr->component_index[ncomps] = (int) val; scanptr->component_index[ncomps] = (int) val;
ncomps++; ncomps++;
} }
scanptr->comps_in_scan = ncomps; scanptr->comps_in_scan = ncomps;
if (termchar == ':') { if (termchar == ':') {
if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
goto bogus; goto bogus;
scanptr->Ss = (int) val; scanptr->Ss = (int) val;
if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
goto bogus; goto bogus;
scanptr->Se = (int) val; scanptr->Se = (int) val;
if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
goto bogus; goto bogus;
scanptr->Ah = (int) val; scanptr->Ah = (int) val;
if (! read_scan_integer(fp, &val, &termchar)) if (! read_scan_integer(fp, &val, &termchar))
goto bogus; goto bogus;
scanptr->Al = (int) val; scanptr->Al = (int) val;
} else { } else {
/* set non-progressive parameters */ /* set non-progressive parameters */
@@ -261,8 +261,8 @@ bogus:
*/ */
scanptr = (jpeg_scan_info *) scanptr = (jpeg_scan_info *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
scanno * SIZEOF(jpeg_scan_info)); scanno * sizeof(jpeg_scan_info));
MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info)); MEMCOPY(scanptr, scans, scanno * sizeof(jpeg_scan_info));
cinfo->scan_info = scanptr; cinfo->scan_info = scanptr;
cinfo->num_scans = scanno; cinfo->num_scans = scanno;
} }
@@ -320,11 +320,11 @@ jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline)
jpeg_add_quant_table(cinfo, 1, flat_quant_tbl, jpeg_add_quant_table(cinfo, 1, flat_quant_tbl,
q_scale_factor[1], force_baseline); q_scale_factor[1], force_baseline);
} else { } else {
jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
q_scale_factor[0], force_baseline); q_scale_factor[0], force_baseline);
jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
q_scale_factor[1], force_baseline); q_scale_factor[1], force_baseline);
} }
} }
#endif #endif
@@ -336,17 +336,17 @@ set_quality_ratings (j_compress_ptr cinfo, char *arg, boolean force_baseline)
* If there are more q-table slots than parameters, the last value is replicated. * If there are more q-table slots than parameters, the last value is replicated.
*/ */
{ {
int val = 75; /* default value */ int val = 75; /* default value */
int tblno; int tblno;
char ch; char ch;
for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
if (*arg) { if (*arg) {
ch = ','; /* if not set by sscanf, will be ',' */ ch = ','; /* if not set by sscanf, will be ',' */
if (sscanf(arg, "%d%c", &val, &ch) < 1) if (sscanf(arg, "%d%c", &val, &ch) < 1)
return FALSE; return FALSE;
if (ch != ',') /* syntax check */ if (ch != ',') /* syntax check */
return FALSE; return FALSE;
/* Convert user 0-100 rating to percentage scaling */ /* Convert user 0-100 rating to percentage scaling */
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val);
@@ -354,7 +354,7 @@ set_quality_ratings (j_compress_ptr cinfo, char *arg, boolean force_baseline)
q_scale_factor[tblno] = jpeg_quality_scaling(val); q_scale_factor[tblno] = jpeg_quality_scaling(val);
#endif #endif
while (*arg && *arg++ != ',') /* advance to next segment of arg string */ while (*arg && *arg++ != ',') /* advance to next segment of arg string */
; ;
} else { } else {
/* reached end of parameter, set remaining factors to last value */ /* reached end of parameter, set remaining factors to last value */
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
@@ -376,25 +376,25 @@ set_quant_slots (j_compress_ptr cinfo, char *arg)
* If there are more components than parameters, the last value is replicated. * If there are more components than parameters, the last value is replicated.
*/ */
{ {
int val = 0; /* default table # */ int val = 0; /* default table # */
int ci; int ci;
char ch; char ch;
for (ci = 0; ci < MAX_COMPONENTS; ci++) { for (ci = 0; ci < MAX_COMPONENTS; ci++) {
if (*arg) { if (*arg) {
ch = ','; /* if not set by sscanf, will be ',' */ ch = ','; /* if not set by sscanf, will be ',' */
if (sscanf(arg, "%d%c", &val, &ch) < 1) if (sscanf(arg, "%d%c", &val, &ch) < 1)
return FALSE; return FALSE;
if (ch != ',') /* syntax check */ if (ch != ',') /* syntax check */
return FALSE; return FALSE;
if (val < 0 || val >= NUM_QUANT_TBLS) { if (val < 0 || val >= NUM_QUANT_TBLS) {
fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n", fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n",
NUM_QUANT_TBLS-1); NUM_QUANT_TBLS-1);
return FALSE; return FALSE;
} }
cinfo->comp_info[ci].quant_tbl_no = val; cinfo->comp_info[ci].quant_tbl_no = val;
while (*arg && *arg++ != ',') /* advance to next segment of arg string */ while (*arg && *arg++ != ',') /* advance to next segment of arg string */
; ;
} else { } else {
/* reached end of parameter, set remaining components to last table */ /* reached end of parameter, set remaining components to last table */
cinfo->comp_info[ci].quant_tbl_no = val; cinfo->comp_info[ci].quant_tbl_no = val;
@@ -416,19 +416,19 @@ set_sample_factors (j_compress_ptr cinfo, char *arg)
for (ci = 0; ci < MAX_COMPONENTS; ci++) { for (ci = 0; ci < MAX_COMPONENTS; ci++) {
if (*arg) { if (*arg) {
ch2 = ','; /* if not set by sscanf, will be ',' */ ch2 = ','; /* if not set by sscanf, will be ',' */
if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3) if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3)
return FALSE; return FALSE;
if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */ if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */
return FALSE; return FALSE;
if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) { if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) {
fprintf(stderr, "JPEG sampling factors must be 1..4\n"); fprintf(stderr, "JPEG sampling factors must be 1..4\n");
return FALSE; return FALSE;
} }
cinfo->comp_info[ci].h_samp_factor = val1; cinfo->comp_info[ci].h_samp_factor = val1;
cinfo->comp_info[ci].v_samp_factor = val2; cinfo->comp_info[ci].v_samp_factor = val2;
while (*arg && *arg++ != ',') /* advance to next segment of arg string */ while (*arg && *arg++ != ',') /* advance to next segment of arg string */
; ;
} else { } else {
/* reached end of parameter, set remaining components to 1x1 sampling */ /* reached end of parameter, set remaining components to 1x1 sampling */
cinfo->comp_info[ci].h_samp_factor = 1; cinfo->comp_info[ci].h_samp_factor = 1;

View File

@@ -1,8 +1,10 @@
/* /*
* rdtarga.c * rdtarga.c
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software. * It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains routines to read input images in Targa format. * This file contains routines to read input images in Targa format.
@@ -17,7 +19,7 @@
* Based on code contributed by Lee Daniel Crocker. * Based on code contributed by Lee Daniel Crocker.
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#ifdef TARGA_SUPPORTED #ifdef TARGA_SUPPORTED
@@ -26,19 +28,19 @@
#ifdef HAVE_UNSIGNED_CHAR #ifdef HAVE_UNSIGNED_CHAR
typedef unsigned char U_CHAR; typedef unsigned char U_CHAR;
#define UCH(x) ((int) (x)) #define UCH(x) ((int) (x))
#else /* !HAVE_UNSIGNED_CHAR */ #else /* !HAVE_UNSIGNED_CHAR */
#ifdef CHAR_IS_UNSIGNED #ifdef __CHAR_UNSIGNED__
typedef char U_CHAR; typedef char U_CHAR;
#define UCH(x) ((int) (x)) #define UCH(x) ((int) (x))
#else #else
typedef char U_CHAR; typedef char U_CHAR;
#define UCH(x) ((int) (x) & 0xFF) #define UCH(x) ((int) (x) & 0xFF)
#endif #endif
#endif /* HAVE_UNSIGNED_CHAR */ #endif /* HAVE_UNSIGNED_CHAR */
#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) #define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
/* Private version of data source object */ /* Private version of data source object */
@@ -48,28 +50,27 @@ typedef struct _tga_source_struct * tga_source_ptr;
typedef struct _tga_source_struct { typedef struct _tga_source_struct {
struct cjpeg_source_struct pub; /* public fields */ struct cjpeg_source_struct pub; /* public fields */
j_compress_ptr cinfo; /* back link saves passing separate parm */ j_compress_ptr cinfo; /* back link saves passing separate parm */
JSAMPARRAY colormap; /* Targa colormap (converted to my format) */ JSAMPARRAY colormap; /* Targa colormap (converted to my format) */
jvirt_sarray_ptr whole_image; /* Needed if funny input row order */ jvirt_sarray_ptr whole_image; /* Needed if funny input row order */
JDIMENSION current_row; /* Current logical row number to read */ JDIMENSION current_row; /* Current logical row number to read */
/* Pointer to routine to extract next Targa pixel from input file */ /* Pointer to routine to extract next Targa pixel from input file */
JMETHOD(void, read_pixel, (tga_source_ptr sinfo)); void (*read_pixel) (tga_source_ptr sinfo);
/* Result of read_pixel is delivered here: */ /* Result of read_pixel is delivered here: */
U_CHAR tga_pixel[4]; U_CHAR tga_pixel[4];
int pixel_size; /* Bytes per Targa pixel (1 to 4) */ int pixel_size; /* Bytes per Targa pixel (1 to 4) */
/* State info for reading RLE-coded pixels; both counts must be init to 0 */ /* State info for reading RLE-coded pixels; both counts must be init to 0 */
int block_count; /* # of pixels remaining in RLE block */ int block_count; /* # of pixels remaining in RLE block */
int dup_pixel_count; /* # of times to duplicate previous pixel */ int dup_pixel_count; /* # of times to duplicate previous pixel */
/* This saves the correct pixel-row-expansion method for preload_image */ /* This saves the correct pixel-row-expansion method for preload_image */
JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo, JDIMENSION (*get_pixel_rows) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
cjpeg_source_ptr sinfo));
} tga_source_struct; } tga_source_struct;
@@ -148,9 +149,9 @@ read_rle_pixel (tga_source_ptr sinfo)
/* Time to read RLE block header? */ /* Time to read RLE block header? */
if (--sinfo->block_count < 0) { /* decrement pixels remaining in block */ if (--sinfo->block_count < 0) { /* decrement pixels remaining in block */
i = read_byte(sinfo); i = read_byte(sinfo);
if (i & 0x80) { /* Start of duplicate-pixel block? */ if (i & 0x80) { /* Start of duplicate-pixel block? */
sinfo->dup_pixel_count = i & 0x7F; /* number of dups after this one */ sinfo->dup_pixel_count = i & 0x7F; /* number of dups after this one */
sinfo->block_count = 0; /* then read new block header */ sinfo->block_count = 0; /* then read new block header */
} else { } else {
sinfo->block_count = i & 0x7F; /* number of pixels after this one */ sinfo->block_count = i & 0x7F; /* number of pixels after this one */
} }
@@ -338,8 +339,8 @@ start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
unsigned int width, height, maplen; unsigned int width, height, maplen;
boolean is_bottom_up; boolean is_bottom_up;
#define GET_2B(offset) ((unsigned int) UCH(targaheader[offset]) + \ #define GET_2B(offset) ((unsigned int) UCH(targaheader[offset]) + \
(((unsigned int) UCH(targaheader[offset+1])) << 8)) (((unsigned int) UCH(targaheader[offset+1])) << 8))
if (! ReadOK(source->pub.input_file, targaheader, 18)) if (! ReadOK(source->pub.input_file, targaheader, 18))
ERREXIT(cinfo, JERR_INPUT_EOF); ERREXIT(cinfo, JERR_INPUT_EOF);
@@ -355,15 +356,15 @@ start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
width = GET_2B(12); width = GET_2B(12);
height = GET_2B(14); height = GET_2B(14);
source->pixel_size = UCH(targaheader[16]) >> 3; source->pixel_size = UCH(targaheader[16]) >> 3;
flags = UCH(targaheader[17]); /* Image Descriptor byte */ flags = UCH(targaheader[17]); /* Image Descriptor byte */
is_bottom_up = ((flags & 0x20) == 0); /* bit 5 set => top-down */ is_bottom_up = ((flags & 0x20) == 0); /* bit 5 set => top-down */
interlace_type = flags >> 6; /* bits 6/7 are interlace code */ interlace_type = flags >> 6; /* bits 6/7 are interlace code */
if (cmaptype > 1 || /* cmaptype must be 0 or 1 */ if (cmaptype > 1 || /* cmaptype must be 0 or 1 */
source->pixel_size < 1 || source->pixel_size > 4 || source->pixel_size < 1 || source->pixel_size > 4 ||
(UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */ (UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */
interlace_type != 0) /* currently don't allow interlaced image */ interlace_type != 0) /* currently don't allow interlaced image */
ERREXIT(cinfo, JERR_TGA_BADPARMS); ERREXIT(cinfo, JERR_TGA_BADPARMS);
if (subtype > 8) { if (subtype > 8) {
@@ -377,18 +378,18 @@ start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
} }
/* Now should have subtype 1, 2, or 3 */ /* Now should have subtype 1, 2, or 3 */
components = 3; /* until proven different */ components = 3; /* until proven different */
cinfo->in_color_space = JCS_RGB; cinfo->in_color_space = JCS_RGB;
switch (subtype) { switch (subtype) {
case 1: /* Colormapped image */ case 1: /* Colormapped image */
if (source->pixel_size == 1 && cmaptype == 1) if (source->pixel_size == 1 && cmaptype == 1)
source->get_pixel_rows = get_8bit_row; source->get_pixel_rows = get_8bit_row;
else else
ERREXIT(cinfo, JERR_TGA_BADPARMS); ERREXIT(cinfo, JERR_TGA_BADPARMS);
TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height); TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height);
break; break;
case 2: /* RGB image */ case 2: /* RGB image */
switch (source->pixel_size) { switch (source->pixel_size) {
case 2: case 2:
source->get_pixel_rows = get_16bit_row; source->get_pixel_rows = get_16bit_row;
@@ -405,7 +406,7 @@ start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
} }
TRACEMS2(cinfo, 1, JTRC_TGA, width, height); TRACEMS2(cinfo, 1, JTRC_TGA, width, height);
break; break;
case 3: /* Grayscale image */ case 3: /* Grayscale image */
components = 1; components = 1;
cinfo->in_color_space = JCS_GRAYSCALE; cinfo->in_color_space = JCS_GRAYSCALE;
if (source->pixel_size == 1) if (source->pixel_size == 1)
@@ -441,7 +442,7 @@ start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
source->pub.get_pixel_rows = source->get_pixel_rows; source->pub.get_pixel_rows = source->get_pixel_rows;
} }
while (idlen--) /* Throw away ID field */ while (idlen--) /* Throw away ID field */
(void) read_byte(source); (void) read_byte(source);
if (maplen > 0) { if (maplen > 0) {
@@ -453,7 +454,7 @@ start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* and read it from the file */ /* and read it from the file */
read_colormap(source, (int) maplen, UCH(targaheader[7])); read_colormap(source, (int) maplen, UCH(targaheader[7]));
} else { } else {
if (cmaptype) /* but you promised a cmap! */ if (cmaptype) /* but you promised a cmap! */
ERREXIT(cinfo, JERR_TGA_BADPARMS); ERREXIT(cinfo, JERR_TGA_BADPARMS);
source->colormap = NULL; source->colormap = NULL;
} }
@@ -488,8 +489,8 @@ jinit_read_targa (j_compress_ptr cinfo)
/* Create module interface object */ /* Create module interface object */
source = (tga_source_ptr) source = (tga_source_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(tga_source_struct)); sizeof(tga_source_struct));
source->cinfo = cinfo; /* make back link for subroutines */ source->cinfo = cinfo; /* make back link for subroutines */
/* Fill in method ptrs, except get_pixel_rows which start_input sets */ /* Fill in method ptrs, except get_pixel_rows which start_input sets */
source->pub.start_input = start_input_tga; source->pub.start_input = start_input_tga;
source->pub.finish_input = finish_input_tga; source->pub.finish_input = finish_input_tga;

View File

@@ -18,16 +18,18 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug"
endif() endif()
if(SIMD_X86_64) if(SIMD_X86_64)
set(SIMD_BASENAMES jfsseflt-64 jccolss2-64 jdcolss2-64 jcgrass2-64 set(SIMD_BASENAMES jfdctflt-sse-64 jccolor-sse2-64 jcgray-sse2-64
jcsamss2-64 jdsamss2-64 jdmerss2-64 jcqnts2i-64 jfss2fst-64 jfss2int-64 jcsample-sse2-64 jdcolor-sse2-64 jdmerge-sse2-64 jdsample-sse2-64
jiss2red-64 jiss2int-64 jiss2fst-64 jcqnts2f-64 jiss2flt-64) jfdctfst-sse2-64 jfdctint-sse2-64 jidctflt-sse2-64 jidctfst-sse2-64
jidctint-sse2-64 jidctred-sse2-64 jquantf-sse2-64 jquanti-sse2-64)
message(STATUS "Building x86_64 SIMD extensions") message(STATUS "Building x86_64 SIMD extensions")
else() else()
set(SIMD_BASENAMES jsimdcpu jccolmmx jcgrammx jdcolmmx jcsammmx jdsammmx set(SIMD_BASENAMES jsimdcpu jfdctflt-3dn jidctflt-3dn jquant-3dn jccolor-mmx
jdmermmx jcqntmmx jfmmxfst jfmmxint jimmxred jimmxint jimmxfst jcqnt3dn jcgray-mmx jcsample-mmx jdcolor-mmx jdmerge-mmx jdsample-mmx jfdctfst-mmx
jf3dnflt ji3dnflt jcqntsse jfsseflt jisseflt jccolss2 jcgrass2 jdcolss2 jfdctint-mmx jidctfst-mmx jidctint-mmx jidctred-mmx jquant-mmx jfdctflt-sse
jcsamss2 jdsamss2 jdmerss2 jcqnts2i jfss2fst jfss2int jiss2red jiss2int jidctflt-sse jquant-sse jccolor-sse2 jcgray-sse2 jcsample-sse2 jdcolor-sse2
jiss2fst jcqnts2f jiss2flt) jdmerge-sse2 jdsample-sse2 jfdctfst-sse2 jfdctint-sse2 jidctflt-sse2
jidctfst-sse2 jidctint-sse2 jidctred-sse2 jquantf-sse2 jquanti-sse2)
message(STATUS "Building i386 SIMD extensions") message(STATUS "Building i386 SIMD extensions")
endif() endif()
@@ -41,28 +43,32 @@ file(GLOB INC_FILES *.inc)
foreach(file ${SIMD_BASENAMES}) foreach(file ${SIMD_BASENAMES})
set(DEPFILE "") set(DEPFILE "")
set(SIMD_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${file}.asm") set(SIMD_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${file}.asm)
if("${file}" MATCHES col) if(${file} MATCHES jccolor)
set(DEPFILE "${file}") set(DEPFILE ${file})
string(REGEX REPLACE "col" "clr" DEPFILE "${DEPFILE}") string(REGEX REPLACE "jccolor" "jccolext" DEPFILE ${DEPFILE})
set(DEPFILE "${CMAKE_CURRENT_SOURCE_DIR}/${DEPFILE}.asm") set(DEPFILE ${CMAKE_CURRENT_SOURCE_DIR}/${DEPFILE}.asm)
endif() endif()
if("${file}" MATCHES mer) if(${file} MATCHES jcgray)
set(DEPFILE "${file}") set(DEPFILE ${file})
string(REGEX REPLACE "mer" "mrg" DEPFILE "${DEPFILE}") string(REGEX REPLACE "jcgray" "jcgryext" DEPFILE ${DEPFILE})
set(DEPFILE "${CMAKE_CURRENT_SOURCE_DIR}/${DEPFILE}.asm") set(DEPFILE ${CMAKE_CURRENT_SOURCE_DIR}/${DEPFILE}.asm)
endif() endif()
if("${file}" MATCHES gra) if(${file} MATCHES jdcolor)
set(DEPFILE "${file}") set(DEPFILE ${file})
string(REGEX REPLACE "gra" "gry" DEPFILE "${DEPFILE}") string(REGEX REPLACE "jdcolor" "jdcolext" DEPFILE ${DEPFILE})
set(DEPFILE "${CMAKE_CURRENT_SOURCE_DIR}/${DEPFILE}.asm") set(DEPFILE ${CMAKE_CURRENT_SOURCE_DIR}/${DEPFILE}.asm)
endif() endif()
set(SIMD_OBJ "${OBJDIR}/${file}.obj") if(${file} MATCHES jdmerge)
add_custom_command(OUTPUT "${SIMD_OBJ}" set(DEPFILE ${file})
DEPENDS "${SIMD_SRC}" "${DEPFILE}" ${INC_FILES} string(REGEX REPLACE "jdmerge" "jdmrgext" DEPFILE ${DEPFILE})
COMMAND "${NASM}" ${NAFLAGS} "${SIMD_SRC}" "-o${SIMD_OBJ}" set(DEPFILE ${CMAKE_CURRENT_SOURCE_DIR}/${DEPFILE}.asm)
VERBATIM) endif()
list(APPEND SIMD_OBJS "${SIMD_OBJ}") set(SIMD_OBJ ${OBJDIR}/${file}.obj)
add_custom_command(OUTPUT ${SIMD_OBJ}
DEPENDS ${SIMD_SRC} ${DEPFILE} ${INC_FILES}
COMMAND ${NASM} ${NAFLAGS} ${SIMD_SRC} -o${SIMD_OBJ})
set(SIMD_OBJS ${SIMD_OBJS} ${SIMD_OBJ})
endforeach() endforeach()
set(SIMD_OBJS ${SIMD_OBJS} PARENT_SCOPE) set(SIMD_OBJS ${SIMD_OBJS} PARENT_SCOPE)

View File

@@ -2,54 +2,54 @@ noinst_LTLIBRARIES = libsimd.la
BUILT_SOURCES = jsimdcfg.inc BUILT_SOURCES = jsimdcfg.inc
EXTRA_DIST = nasm_lt.sh jcclrmmx.asm jcclrss2.asm jdclrmmx.asm jdclrss2.asm \ EXTRA_DIST = nasm_lt.sh CMakeLists.txt \
jdmrgmmx.asm jdmrgss2.asm jcclrss2-64.asm jdclrss2-64.asm \ jccolext-mmx.asm jcgryext-mmx.asm jdcolext-mmx.asm jdmrgext-mmx.asm \
jdmrgss2-64.asm jcgryss2-64.asm jcgrymmx.asm jcgryss2.asm CMakeLists.txt jccolext-sse2.asm jcgryext-sse2.asm jdcolext-sse2.asm jdmrgext-sse2.asm \
jccolext-sse2-64.asm jcgryext-sse2-64.asm jdcolext-sse2-64.asm \
jdmrgext-sse2-64.asm
if SIMD_X86_64 if SIMD_X86_64
libsimd_la_SOURCES = jsimd_x86_64.c \ libsimd_la_SOURCES = jsimd_x86_64.c jsimd.h jsimdcfg.inc.h jsimdext.inc \
jsimd.h jsimdcfg.inc.h \ jcolsamp.inc jdct.inc jfdctflt-sse-64.asm \
jsimdext.inc jcolsamp.inc jdct.inc \ jccolor-sse2-64.asm jcgray-sse2-64.asm jcsample-sse2-64.asm \
jfsseflt-64.asm jcgrass2-64.asm \ jdcolor-sse2-64.asm jdmerge-sse2-64.asm jdsample-sse2-64.asm \
jccolss2-64.asm jdcolss2-64.asm \ jfdctfst-sse2-64.asm jfdctint-sse2-64.asm jidctflt-sse2-64.asm \
jcsamss2-64.asm jdsamss2-64.asm jdmerss2-64.asm \ jidctfst-sse2-64.asm jidctint-sse2-64.asm jidctred-sse2-64.asm \
jcqnts2i-64.asm jfss2fst-64.asm jfss2int-64.asm \ jquantf-sse2-64.asm jquanti-sse2-64.asm
jiss2red-64.asm jiss2int-64.asm jiss2fst-64.asm \
jcqnts2f-64.asm jiss2flt-64.asm jccolor-sse2-64.lo: jccolext-sse2-64.asm
jcgray-sse2-64.lo: jcgryext-sse2-64.asm
jdcolor-sse2-64.lo: jdcolext-sse2-64.asm
jdmerge-sse2-64.lo: jdmrgext-sse2-64.asm
jccolss2-64.lo: jcclrss2-64.asm
jdcolss2-64.lo: jdclrss2-64.asm
jcgrass2-64.lo: jcgryss2-64.asm
jdmerss2-64.lo: jdmrgss2-64.asm
endif endif
if SIMD_I386 if SIMD_I386
libsimd_la_SOURCES = jsimd_i386.c \ libsimd_la_SOURCES = jsimd_i386.c jsimd.h jsimdcfg.inc.h jsimdext.inc \
jsimd.h jsimdcfg.inc.h \ jcolsamp.inc jdct.inc jsimdcpu.asm \
jsimdext.inc jcolsamp.inc jdct.inc \ jfdctflt-3dn.asm jidctflt-3dn.asm jquant-3dn.asm \
jsimdcpu.asm \ jccolor-mmx.asm jcgray-mmx.asm jcsample-mmx.asm \
jccolmmx.asm jdcolmmx.asm jcgrammx.asm \ jdcolor-mmx.asm jdmerge-mmx.asm jdsample-mmx.asm \
jcsammmx.asm jdsammmx.asm jdmermmx.asm \ jfdctfst-mmx.asm jfdctint-mmx.asm jidctfst-mmx.asm \
jcqntmmx.asm jfmmxfst.asm jfmmxint.asm \ jidctint-mmx.asm jidctred-mmx.asm jquant-mmx.asm \
jimmxred.asm jimmxint.asm jimmxfst.asm \ jfdctflt-sse.asm jidctflt-sse.asm jquant-sse.asm \
jcqnt3dn.asm jf3dnflt.asm ji3dnflt.asm \ jccolor-sse2.asm jcgray-sse2.asm jcsample-sse2.asm \
jcqntsse.asm jfsseflt.asm jisseflt.asm \ jdcolor-sse2.asm jdmerge-sse2.asm jdsample-sse2.asm \
jccolss2.asm jdcolss2.asm jcgrass2.asm \ jfdctfst-sse2.asm jfdctint-sse2.asm jidctflt-sse2.asm \
jcsamss2.asm jdsamss2.asm jdmerss2.asm \ jidctfst-sse2.asm jidctint-sse2.asm jidctred-sse2.asm \
jcqnts2i.asm jfss2fst.asm jfss2int.asm \ jquantf-sse2.asm jquanti-sse2.asm
jiss2red.asm jiss2int.asm jiss2fst.asm \
jcqnts2f.asm jiss2flt.asm jccolor-mmx.lo: jccolext-mmx.asm
jcgray.-mmx.lo: jcgryext-mmx.asm
jdcolor-mmx.lo: jdcolext-mmx.asm
jdmerge-mmx.lo: jdmrgext-mmx.asm
jccolor-sse2.lo: jccolext-sse2.asm
jcgray-sse2.lo: jcgryext-sse2.asm
jdcolor-sse2.lo: jdcolext-sse2.asm
jdmerge-sse2.lo: jdmrgext-sse2.asm
jccolmmx.lo: jcclrmmx.asm
jcgrammx.lo: jcgrymmx.asm
jccolss2.lo: jcclrss2.asm
jcgrass2.lo: jcgryss2.asm
jdcolmmx.lo: jdclrmmx.asm
jdcolss2.lo: jdclrss2.asm
jdmermmx.lo: jdmrgmmx.asm
jdmerss2.lo: jdmrgss2.asm
endif endif
if SIMD_ARM if SIMD_ARM
@@ -64,7 +64,7 @@ libsimd_la_SOURCES = jsimd_arm64.c jsimd_arm_neon_64.S
endif endif
if SIMD_MIPSEL if SIMD_MIPS
libsimd_la_SOURCES = jsimd_mips.c jsimd_mips_dspr2_asm.h jsimd_mips_dspr2.S libsimd_la_SOURCES = jsimd_mips.c jsimd_mips_dspr2_asm.h jsimd_mips_dspr2.S

View File

@@ -1,477 +0,0 @@
;
; jcclrmmx.asm - colorspace conversion (MMX)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
;
; Based on
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jcolsamp.inc"
; --------------------------------------------------------------------------
;
; Convert some rows of samples to the output colorspace.
;
; GLOBAL(void)
; jsimd_rgb_ycc_convert_mmx (JDIMENSION img_width,
; JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
; JDIMENSION output_row, int num_rows);
;
%define img_width(b) (b)+8 ; JDIMENSION img_width
%define input_buf(b) (b)+12 ; JSAMPARRAY input_buf
%define output_buf(b) (b)+16 ; JSAMPIMAGE output_buf
%define output_row(b) (b)+20 ; JDIMENSION output_row
%define num_rows(b) (b)+24 ; int num_rows
%define original_ebp ebp+0
%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM]
%define WK_NUM 8
%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr
align 16
global EXTN(jsimd_rgb_ycc_convert_mmx)
EXTN(jsimd_rgb_ycc_convert_mmx):
push ebp
mov eax,esp ; eax = original ebp
sub esp, byte 4
and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits
mov [esp],eax
mov ebp,esp ; ebp = aligned ebp
lea esp, [wk(0)]
pushpic eax ; make a room for GOT address
push ebx
; push ecx ; need not be preserved
; push edx ; need not be preserved
push esi
push edi
get_GOT ebx ; get GOT address
movpic POINTER [gotptr], ebx ; save GOT address
mov ecx, JDIMENSION [img_width(eax)] ; num_cols
test ecx,ecx
jz near .return
push ecx
mov esi, JSAMPIMAGE [output_buf(eax)]
mov ecx, JDIMENSION [output_row(eax)]
mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY]
mov ebx, JSAMPARRAY [esi+1*SIZEOF_JSAMPARRAY]
mov edx, JSAMPARRAY [esi+2*SIZEOF_JSAMPARRAY]
lea edi, [edi+ecx*SIZEOF_JSAMPROW]
lea ebx, [ebx+ecx*SIZEOF_JSAMPROW]
lea edx, [edx+ecx*SIZEOF_JSAMPROW]
pop ecx
mov esi, JSAMPARRAY [input_buf(eax)]
mov eax, INT [num_rows(eax)]
test eax,eax
jle near .return
alignx 16,7
.rowloop:
pushpic eax
push edx
push ebx
push edi
push esi
push ecx ; col
mov esi, JSAMPROW [esi] ; inptr
mov edi, JSAMPROW [edi] ; outptr0
mov ebx, JSAMPROW [ebx] ; outptr1
mov edx, JSAMPROW [edx] ; outptr2
movpic eax, POINTER [gotptr] ; load GOT address (eax)
cmp ecx, byte SIZEOF_MMWORD
jae short .columnloop
alignx 16,7
%if RGB_PIXELSIZE == 3 ; ---------------
.column_ld1:
push eax
push edx
lea ecx,[ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE
test cl, SIZEOF_BYTE
jz short .column_ld2
sub ecx, byte SIZEOF_BYTE
xor eax,eax
mov al, BYTE [esi+ecx]
.column_ld2:
test cl, SIZEOF_WORD
jz short .column_ld4
sub ecx, byte SIZEOF_WORD
xor edx,edx
mov dx, WORD [esi+ecx]
shl eax, WORD_BIT
or eax,edx
.column_ld4:
movd mmA,eax
pop edx
pop eax
test cl, SIZEOF_DWORD
jz short .column_ld8
sub ecx, byte SIZEOF_DWORD
movd mmG, DWORD [esi+ecx]
psllq mmA, DWORD_BIT
por mmA,mmG
.column_ld8:
test cl, SIZEOF_MMWORD
jz short .column_ld16
movq mmG,mmA
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
mov ecx, SIZEOF_MMWORD
jmp short .rgb_ycc_cnv
.column_ld16:
test cl, 2*SIZEOF_MMWORD
mov ecx, SIZEOF_MMWORD
jz short .rgb_ycc_cnv
movq mmF,mmA
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmG, MMWORD [esi+1*SIZEOF_MMWORD]
jmp short .rgb_ycc_cnv
alignx 16,7
.columnloop:
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmG, MMWORD [esi+1*SIZEOF_MMWORD]
movq mmF, MMWORD [esi+2*SIZEOF_MMWORD]
.rgb_ycc_cnv:
; mmA=(00 10 20 01 11 21 02 12)
; mmG=(22 03 13 23 04 14 24 05)
; mmF=(15 25 06 16 26 07 17 27)
movq mmD,mmA
psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 10 20 01)
psrlq mmD,4*BYTE_BIT ; mmD=(11 21 02 12 -- -- -- --)
punpckhbw mmA,mmG ; mmA=(00 04 10 14 20 24 01 05)
psllq mmG,4*BYTE_BIT ; mmG=(-- -- -- -- 22 03 13 23)
punpcklbw mmD,mmF ; mmD=(11 15 21 25 02 06 12 16)
punpckhbw mmG,mmF ; mmG=(22 26 03 07 13 17 23 27)
movq mmE,mmA
psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 04 10 14)
psrlq mmE,4*BYTE_BIT ; mmE=(20 24 01 05 -- -- -- --)
punpckhbw mmA,mmD ; mmA=(00 02 04 06 10 12 14 16)
psllq mmD,4*BYTE_BIT ; mmD=(-- -- -- -- 11 15 21 25)
punpcklbw mmE,mmG ; mmE=(20 22 24 26 01 03 05 07)
punpckhbw mmD,mmG ; mmD=(11 13 15 17 21 23 25 27)
pxor mmH,mmH
movq mmC,mmA
punpcklbw mmA,mmH ; mmA=(00 02 04 06)
punpckhbw mmC,mmH ; mmC=(10 12 14 16)
movq mmB,mmE
punpcklbw mmE,mmH ; mmE=(20 22 24 26)
punpckhbw mmB,mmH ; mmB=(01 03 05 07)
movq mmF,mmD
punpcklbw mmD,mmH ; mmD=(11 13 15 17)
punpckhbw mmF,mmH ; mmF=(21 23 25 27)
%else ; RGB_PIXELSIZE == 4 ; -----------
.column_ld1:
test cl, SIZEOF_MMWORD/8
jz short .column_ld2
sub ecx, byte SIZEOF_MMWORD/8
movd mmA, DWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld2:
test cl, SIZEOF_MMWORD/4
jz short .column_ld4
sub ecx, byte SIZEOF_MMWORD/4
movq mmF,mmA
movq mmA, MMWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld4:
test cl, SIZEOF_MMWORD/2
mov ecx, SIZEOF_MMWORD
jz short .rgb_ycc_cnv
movq mmD,mmA
movq mmC,mmF
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmF, MMWORD [esi+1*SIZEOF_MMWORD]
jmp short .rgb_ycc_cnv
alignx 16,7
.columnloop:
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmF, MMWORD [esi+1*SIZEOF_MMWORD]
movq mmD, MMWORD [esi+2*SIZEOF_MMWORD]
movq mmC, MMWORD [esi+3*SIZEOF_MMWORD]
.rgb_ycc_cnv:
; mmA=(00 10 20 30 01 11 21 31)
; mmF=(02 12 22 32 03 13 23 33)
; mmD=(04 14 24 34 05 15 25 35)
; mmC=(06 16 26 36 07 17 27 37)
movq mmB,mmA
punpcklbw mmA,mmF ; mmA=(00 02 10 12 20 22 30 32)
punpckhbw mmB,mmF ; mmB=(01 03 11 13 21 23 31 33)
movq mmG,mmD
punpcklbw mmD,mmC ; mmD=(04 06 14 16 24 26 34 36)
punpckhbw mmG,mmC ; mmG=(05 07 15 17 25 27 35 37)
movq mmE,mmA
punpcklwd mmA,mmD ; mmA=(00 02 04 06 10 12 14 16)
punpckhwd mmE,mmD ; mmE=(20 22 24 26 30 32 34 36)
movq mmH,mmB
punpcklwd mmB,mmG ; mmB=(01 03 05 07 11 13 15 17)
punpckhwd mmH,mmG ; mmH=(21 23 25 27 31 33 35 37)
pxor mmF,mmF
movq mmC,mmA
punpcklbw mmA,mmF ; mmA=(00 02 04 06)
punpckhbw mmC,mmF ; mmC=(10 12 14 16)
movq mmD,mmB
punpcklbw mmB,mmF ; mmB=(01 03 05 07)
punpckhbw mmD,mmF ; mmD=(11 13 15 17)
movq mmG,mmE
punpcklbw mmE,mmF ; mmE=(20 22 24 26)
punpckhbw mmG,mmF ; mmG=(30 32 34 36)
punpcklbw mmF,mmH
punpckhbw mmH,mmH
psrlw mmF,BYTE_BIT ; mmF=(21 23 25 27)
psrlw mmH,BYTE_BIT ; mmH=(31 33 35 37)
%endif ; RGB_PIXELSIZE ; ---------------
; mm0=(R0 R2 R4 R6)=RE, mm2=(G0 G2 G4 G6)=GE, mm4=(B0 B2 B4 B6)=BE
; mm1=(R1 R3 R5 R7)=RO, mm3=(G1 G3 G5 G7)=GO, mm5=(B1 B3 B5 B7)=BO
; (Original)
; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
;
; (This implementation)
; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
movq MMWORD [wk(0)], mm0 ; wk(0)=RE
movq MMWORD [wk(1)], mm1 ; wk(1)=RO
movq MMWORD [wk(2)], mm4 ; wk(2)=BE
movq MMWORD [wk(3)], mm5 ; wk(3)=BO
movq mm6,mm1
punpcklwd mm1,mm3
punpckhwd mm6,mm3
movq mm7,mm1
movq mm4,mm6
pmaddwd mm1,[GOTOFF(eax,PW_F0299_F0337)] ; mm1=ROL*FIX(0.299)+GOL*FIX(0.337)
pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=ROH*FIX(0.299)+GOH*FIX(0.337)
pmaddwd mm7,[GOTOFF(eax,PW_MF016_MF033)] ; mm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
pmaddwd mm4,[GOTOFF(eax,PW_MF016_MF033)] ; mm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
movq MMWORD [wk(4)], mm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
movq MMWORD [wk(5)], mm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
pxor mm1,mm1
pxor mm6,mm6
punpcklwd mm1,mm5 ; mm1=BOL
punpckhwd mm6,mm5 ; mm6=BOH
psrld mm1,1 ; mm1=BOL*FIX(0.500)
psrld mm6,1 ; mm6=BOH*FIX(0.500)
movq mm5,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm5=[PD_ONEHALFM1_CJ]
paddd mm7,mm1
paddd mm4,mm6
paddd mm7,mm5
paddd mm4,mm5
psrld mm7,SCALEBITS ; mm7=CbOL
psrld mm4,SCALEBITS ; mm4=CbOH
packssdw mm7,mm4 ; mm7=CbO
movq mm1, MMWORD [wk(2)] ; mm1=BE
movq mm6,mm0
punpcklwd mm0,mm2
punpckhwd mm6,mm2
movq mm5,mm0
movq mm4,mm6
pmaddwd mm0,[GOTOFF(eax,PW_F0299_F0337)] ; mm0=REL*FIX(0.299)+GEL*FIX(0.337)
pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=REH*FIX(0.299)+GEH*FIX(0.337)
pmaddwd mm5,[GOTOFF(eax,PW_MF016_MF033)] ; mm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
pmaddwd mm4,[GOTOFF(eax,PW_MF016_MF033)] ; mm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
movq MMWORD [wk(6)], mm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
movq MMWORD [wk(7)], mm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
pxor mm0,mm0
pxor mm6,mm6
punpcklwd mm0,mm1 ; mm0=BEL
punpckhwd mm6,mm1 ; mm6=BEH
psrld mm0,1 ; mm0=BEL*FIX(0.500)
psrld mm6,1 ; mm6=BEH*FIX(0.500)
movq mm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm1=[PD_ONEHALFM1_CJ]
paddd mm5,mm0
paddd mm4,mm6
paddd mm5,mm1
paddd mm4,mm1
psrld mm5,SCALEBITS ; mm5=CbEL
psrld mm4,SCALEBITS ; mm4=CbEH
packssdw mm5,mm4 ; mm5=CbE
psllw mm7,BYTE_BIT
por mm5,mm7 ; mm5=Cb
movq MMWORD [ebx], mm5 ; Save Cb
movq mm0, MMWORD [wk(3)] ; mm0=BO
movq mm6, MMWORD [wk(2)] ; mm6=BE
movq mm1, MMWORD [wk(1)] ; mm1=RO
movq mm4,mm0
punpcklwd mm0,mm3
punpckhwd mm4,mm3
movq mm7,mm0
movq mm5,mm4
pmaddwd mm0,[GOTOFF(eax,PW_F0114_F0250)] ; mm0=BOL*FIX(0.114)+GOL*FIX(0.250)
pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BOH*FIX(0.114)+GOH*FIX(0.250)
pmaddwd mm7,[GOTOFF(eax,PW_MF008_MF041)] ; mm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
pmaddwd mm5,[GOTOFF(eax,PW_MF008_MF041)] ; mm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
movq mm3,[GOTOFF(eax,PD_ONEHALF)] ; mm3=[PD_ONEHALF]
paddd mm0, MMWORD [wk(4)]
paddd mm4, MMWORD [wk(5)]
paddd mm0,mm3
paddd mm4,mm3
psrld mm0,SCALEBITS ; mm0=YOL
psrld mm4,SCALEBITS ; mm4=YOH
packssdw mm0,mm4 ; mm0=YO
pxor mm3,mm3
pxor mm4,mm4
punpcklwd mm3,mm1 ; mm3=ROL
punpckhwd mm4,mm1 ; mm4=ROH
psrld mm3,1 ; mm3=ROL*FIX(0.500)
psrld mm4,1 ; mm4=ROH*FIX(0.500)
movq mm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm1=[PD_ONEHALFM1_CJ]
paddd mm7,mm3
paddd mm5,mm4
paddd mm7,mm1
paddd mm5,mm1
psrld mm7,SCALEBITS ; mm7=CrOL
psrld mm5,SCALEBITS ; mm5=CrOH
packssdw mm7,mm5 ; mm7=CrO
movq mm3, MMWORD [wk(0)] ; mm3=RE
movq mm4,mm6
punpcklwd mm6,mm2
punpckhwd mm4,mm2
movq mm1,mm6
movq mm5,mm4
pmaddwd mm6,[GOTOFF(eax,PW_F0114_F0250)] ; mm6=BEL*FIX(0.114)+GEL*FIX(0.250)
pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BEH*FIX(0.114)+GEH*FIX(0.250)
pmaddwd mm1,[GOTOFF(eax,PW_MF008_MF041)] ; mm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
pmaddwd mm5,[GOTOFF(eax,PW_MF008_MF041)] ; mm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
movq mm2,[GOTOFF(eax,PD_ONEHALF)] ; mm2=[PD_ONEHALF]
paddd mm6, MMWORD [wk(6)]
paddd mm4, MMWORD [wk(7)]
paddd mm6,mm2
paddd mm4,mm2
psrld mm6,SCALEBITS ; mm6=YEL
psrld mm4,SCALEBITS ; mm4=YEH
packssdw mm6,mm4 ; mm6=YE
psllw mm0,BYTE_BIT
por mm6,mm0 ; mm6=Y
movq MMWORD [edi], mm6 ; Save Y
pxor mm2,mm2
pxor mm4,mm4
punpcklwd mm2,mm3 ; mm2=REL
punpckhwd mm4,mm3 ; mm4=REH
psrld mm2,1 ; mm2=REL*FIX(0.500)
psrld mm4,1 ; mm4=REH*FIX(0.500)
movq mm0,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm0=[PD_ONEHALFM1_CJ]
paddd mm1,mm2
paddd mm5,mm4
paddd mm1,mm0
paddd mm5,mm0
psrld mm1,SCALEBITS ; mm1=CrEL
psrld mm5,SCALEBITS ; mm5=CrEH
packssdw mm1,mm5 ; mm1=CrE
psllw mm7,BYTE_BIT
por mm1,mm7 ; mm1=Cr
movq MMWORD [edx], mm1 ; Save Cr
sub ecx, byte SIZEOF_MMWORD
add esi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; inptr
add edi, byte SIZEOF_MMWORD ; outptr0
add ebx, byte SIZEOF_MMWORD ; outptr1
add edx, byte SIZEOF_MMWORD ; outptr2
cmp ecx, byte SIZEOF_MMWORD
jae near .columnloop
test ecx,ecx
jnz near .column_ld1
pop ecx ; col
pop esi
pop edi
pop ebx
pop edx
poppic eax
add esi, byte SIZEOF_JSAMPROW ; input_buf
add edi, byte SIZEOF_JSAMPROW
add ebx, byte SIZEOF_JSAMPROW
add edx, byte SIZEOF_JSAMPROW
dec eax ; num_rows
jg near .rowloop
emms ; empty MMX state
.return:
pop edi
pop esi
; pop edx ; need not be preserved
; pop ecx ; need not be preserved
pop ebx
mov esp,ebp ; esp <- aligned ebp
pop esp ; esp <- original ebp
pop ebp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16

Some files were not shown because too many files have changed in this diff Show More