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)
# Use LINK_INTERFACE_LIBRARIES instead of INTERFACE_LINK_LIBRARIES
if(POLICY CMP0022)
cmake_policy(SET CMP0022 OLD) 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) foreach(libtype shared static)
add_test(tjunittest-yuv tjunittest -yuv) if(libtype STREQUAL "shared")
add_test(tjunittest-yuv-alloc tjunittest -yuv -alloc) set(dir sharedlib/)
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() else()
add_test(cjpeg-float-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_FLOAT_NOSIMD} -DFILE=testoutflt.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") set(dir "")
set(suffix -static)
endif() endif()
add_test(cjpeg-int-gray sharedlib/cjpeg -dct int -grayscale -outfile testoutgray.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm") add_test(tjunittest${suffix} tjunittest${suffix})
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(tjunittest${suffix}-alloc tjunittest${suffix} -alloc)
add_test(djpeg-int sharedlib/djpeg -dct int -fast -ppm -outfile testoutint.ppm "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg") add_test(tjunittest${suffix}-yuv tjunittest${suffix} -yuv)
add_test(djpeg-int-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_INT} -DFILE=testoutint.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") add_test(tjunittest${suffix}-yuv-alloc tjunittest${suffix} -yuv -alloc)
add_test(djpeg-fast sharedlib/djpeg -dct fast -ppm -outfile testoutfst.ppm "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg") add_test(tjunittest${suffix}-yuv-nopad tjunittest${suffix} -yuv -noyuvpad)
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") # These tests are carefully chosen to provide full coverage of as many of the
if(WITH_SIMD) # underlying algorithms as possible (including all of the SIMD-accelerated
add_test(djpeg-float-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_FLOAT} -DFILE=testoutflt.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") # ones.)
else()
add_test(djpeg-float-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_FLOAT_NOSIMD} -DFILE=testoutflt.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") # CC: null SAMP: fullsize FDCT: islow ENT: huff
endif() add_test(cjpeg${suffix}-rgb-islow
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) ${dir}cjpeg${suffix} -rgb -dct int -outfile testout_rgb_islow.jpg
string(REGEX REPLACE "_" "/" scalearg ${scale}) ${CMAKE_SOURCE_DIR}/testimages/testorig.ppm)
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(cjpeg${suffix}-rgb-islow-cmp
add_test(djpeg-int-${scale}-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_INT_${scale}} -DFILE=testoutint${scale}.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") ${CMAKE_COMMAND} -DMD5=${MD5_JPEG_RGB_ISLOW} -DFILE=testout_rgb_islow.jpg
endforeach() -P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
add_test(djpeg-fast-1_2 sharedlib/djpeg -dct fast -scale 1/2 -ppm -outfile testoutfst1_2.ppm "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg") # CC: null SAMP: fullsize IDCT: islow ENT: huff
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${suffix}-rgb-islow
add_test(djpeg-256 sharedlib/djpeg -dct int -bmp -colors 256 -outfile testout.bmp "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg") ${dir}djpeg${suffix} -dct int -ppm -outfile testout_rgb_islow.ppm
add_test(djpeg-256-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_BMP_256} -DFILE=testout.bmp -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") testout_rgb_islow.jpg)
add_test(cjpeg-prog sharedlib/cjpeg -dct int -progressive -outfile testoutp.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm") add_test(djpeg${suffix}-rgb-islow-cmp
add_test(cjpeg-prog-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_PROG} -DFILE=testoutp.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") ${CMAKE_COMMAND} -DMD5=${MD5_PPM_RGB_ISLOW} -DFILE=testout_rgb_islow.ppm
add_test(jpegtran-prog sharedlib/jpegtran -outfile testoutt.jpg testoutp.jpg") -P ${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake)
add_test(jpegtran-prog-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_INT} -DFILE=testoutt.jpg -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) if(WITH_ARITH_ENC)
add_test(cjpeg-ari sharedlib/cjpeg -dct int -arithmetic -outfile testoutari.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm") # CC: YCC->RGB SAMP: fullsize/h2v2 FDCT: islow ENT: arith
add_test(cjpeg-ari-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_ARI} -DFILE=testoutari.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") add_test(cjpeg${suffix}-420-islow-ari
add_test(jpegtran-toari sharedlib/jpegtran -arithmetic -outfile testouta.jpg "${CMAKE_SOURCE_DIR}/testimages/testimgint.jpg") ${dir}cjpeg${suffix} -dct int -arithmetic
add_test(jpegtran-toari-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_ARI} -DFILE=testouta.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") -outfile testout_420_islow_ari.jpg
add_test(cjpeg-prog-ari sharedlib/cjpeg -dct int -progressive -arithmetic -sample 1x1 -outfile testoutpa.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm") ${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") 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() endif()
if(WITH_ARITH_DEC) if(WITH_ARITH_DEC)
add_test(djpeg-ari sharedlib/djpeg -dct int -fast -ppm -outfile testoutari.ppm "${CMAKE_SOURCE_DIR}/testimages/testimgari.jpg") # CC: RGB->YCC SAMP: h2v2 merged IDCT: ifast ENT: arith
add_test(djpeg-ari-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_PPM_ARI} -DFILE=testoutari.ppm -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") add_test(cjpeg${suffix}-420m-ifast-ari
add_test(jpegtran-fromari sharedlib/jpegtran -outfile testouta.jpg "${CMAKE_SOURCE_DIR}/testimages/testimgari.jpg") ${dir}djpeg${suffix} -fast -ppm -outfile testout_420m_ifast_ari.ppm
add_test(jpegtran-fromari-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_INT} -DFILE=testouta.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") ${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() 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) # 2/1-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 16x16 islow ENT: huff
add_test(tjunittest-static-alloc tjunittest-static -alloc) # 15/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 15x15 islow ENT: huff
add_test(tjunittest-static-yuv tjunittest-static -yuv) # 13/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 13x13 islow ENT: huff
add_test(tjunittest-static-yuv-alloc tjunittest-static -yuv -alloc) # 11/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 11x11 islow ENT: huff
add_test(tjunittest-static-yuv-nopad tjunittest-static -yuv -noyuvpad) # 9/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 9x9 islow ENT: huff
add_test(cjpeg-static-int cjpeg-static -dct int -outfile testoutint.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm") # 7/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 7x7 islow/14x14 islow
add_test(cjpeg-static-int-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_INT} -DFILE=testoutint.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") # ENT: huff
add_test(cjpeg-static-fast cjpeg-static -dct fast -opt -outfile testoutfst.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm") # 3/4-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 6x6 islow/12x12 islow
add_test(cjpeg-static-fast-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_FAST} -DFILE=testoutfst.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") # ENT: huff
add_test(cjpeg-static-fast-100 cjpeg-static -dct fast -quality 100 -opt -outfile testoutfst100.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm") # 5/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 5x5 islow/10x10 islow
add_test(cjpeg-static-fast-100-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_FAST_100} -DFILE=testoutfst100.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") # ENT: huff
add_test(cjpeg-static-float cjpeg-static -dct float -outfile testoutflt.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm") # 1/2-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 4x4 islow/8x8 islow
if(WITH_SIMD) # ENT: huff
add_test(cjpeg-static-float-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_FLOAT} -DFILE=testoutflt.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") # 3/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 3x3 islow/6x6 islow
else() # ENT: huff
add_test(cjpeg-static-float-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_FLOAT_NOSIMD} -DFILE=testoutflt.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") # 1/4-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 2x2 islow/4x4 islow
endif() # ENT: huff
add_test(cjpeg-static-int-gray cjpeg-static -dct int -grayscale -outfile testoutgray.jpg "${CMAKE_SOURCE_DIR}/testimages/testorig.ppm") # 1/8-- CC: YCC->RGB SAMP: h2v2 merged IDCT: 1x1 islow/2x2 islow
add_test(cjpeg-static-int-gray-cmp "${CMAKE_COMMAND}" -DMD5=${MD5_JPEG_INT_GRAY} -DFILE=testoutgray.jpg -P "${CMAKE_SOURCE_DIR}/cmakescripts/md5cmp.cmake") # ENT: huff
add_test(djpeg-static-int djpeg-static -dct int -fast -ppm -outfile testoutint.ppm "${CMAKE_SOURCE_DIR}/testimages/testorig.jpg") 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)
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}) 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${suffix}-420m-islow-${scale}
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") ${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() 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 # CC: YCC->RGB (dithered) SAMP: h2v2 fancy IDCT: islow ENT: huff
"${CMAKE_SOURCE_DIR}/cmakescripts/testclean.cmake" VERBATIM) 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

@@ -1,8 +1,10 @@
/* /*
* 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
@@ -11,9 +13,6 @@
#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: */
@@ -21,43 +20,6 @@
#endif #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
/* /*
* Optional progress monitor: display a percent-done figure on stderr. * Optional progress monitor: display a percent-done figure on stderr.
*/ */

118
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.
@@ -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;
@@ -99,71 +95,44 @@ 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 */
@@ -171,29 +140,16 @@ EXTERN(FILE *) write_stdout JPP((void));
#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", "ctx=stm"
#define WRITE_BINARY "wb", "ctx=stm"
#else /* standard ANSI-compliant case */
#define READ_BINARY "rb" #define READ_BINARY "rb"
#define WRITE_BINARY "wb" #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

View File

@@ -30,7 +30,7 @@
#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__
@@ -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,

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.
@@ -32,22 +34,7 @@ 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"

14
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.
@@ -27,7 +27,7 @@
#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() */
@@ -107,6 +107,7 @@ 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
@@ -281,6 +282,10 @@ 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 */
@@ -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

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
@@ -36,9 +38,9 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
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;
} }
@@ -204,7 +206,7 @@ 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 &&

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
@@ -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.
@@ -44,11 +46,8 @@ typedef struct {
/* 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)
@@ -194,16 +193,16 @@ compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
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];
} }
@@ -307,7 +306,7 @@ compress_first_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;
@@ -326,8 +325,8 @@ compress_first_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++) {
@@ -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++) {
@@ -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;
@@ -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

@@ -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 */
@@ -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;
@@ -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;
@@ -587,9 +588,14 @@ 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) {
#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; cconvert->pub.color_convert = null_convert;
else if (cinfo->in_color_space == JCS_RGB || } else if (cinfo->in_color_space == JCS_RGB ||
cinfo->in_color_space == JCS_EXT_RGB || cinfo->in_color_space == JCS_EXT_RGB ||
cinfo->in_color_space == JCS_EXT_RGBX || cinfo->in_color_space == JCS_EXT_RGBX ||
cinfo->in_color_space == JCS_EXT_BGR || cinfo->in_color_space == JCS_EXT_BGR ||
@@ -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__)
if (jsimd_c_can_null_convert())
cconvert->pub.color_convert = jsimd_c_null_convert;
else 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__)
if (jsimd_c_can_null_convert())
cconvert->pub.color_convert = jsimd_c_null_convert;
else else
#endif
cconvert->pub.color_convert = null_convert;
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break; break;
@@ -646,9 +662,14 @@ 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__)
if (jsimd_c_can_null_convert())
cconvert->pub.color_convert = jsimd_c_null_convert;
else else
#endif
cconvert->pub.color_convert = null_convert;
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break; break;
@@ -656,6 +677,11 @@ jinit_color_converter (j_compress_ptr cinfo)
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);
#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; cconvert->pub.color_convert = null_convert;
break; break;
} }

View File

@@ -27,22 +27,21 @@
/* 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 *);
@@ -238,7 +237,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
if (fdct->divisors[qtblno] == NULL) { if (fdct->divisors[qtblno] == NULL) {
fdct->divisors[qtblno] = (DCTELEM *) fdct->divisors[qtblno] = (DCTELEM *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(DCTSIZE2 * 4) * SIZEOF(DCTELEM)); (DCTSIZE2 * 4) * sizeof(DCTELEM));
} }
dtbl = fdct->divisors[qtblno]; dtbl = fdct->divisors[qtblno];
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
@@ -274,7 +273,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
if (fdct->divisors[qtblno] == NULL) { if (fdct->divisors[qtblno] == NULL) {
fdct->divisors[qtblno] = (DCTELEM *) fdct->divisors[qtblno] = (DCTELEM *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(DCTSIZE2 * 4) * SIZEOF(DCTELEM)); (DCTSIZE2 * 4) * sizeof(DCTELEM));
} }
dtbl = fdct->divisors[qtblno]; dtbl = fdct->divisors[qtblno];
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
@@ -309,7 +308,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
if (fdct->float_divisors[qtblno] == NULL) { if (fdct->float_divisors[qtblno] == NULL) {
fdct->float_divisors[qtblno] = (FAST_FLOAT *) fdct->float_divisors[qtblno] = (FAST_FLOAT *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
DCTSIZE2 * SIZEOF(FAST_FLOAT)); DCTSIZE2 * sizeof(FAST_FLOAT));
} }
fdtbl = fdct->float_divisors[qtblno]; fdtbl = fdct->float_divisors[qtblno];
i = 0; i = 0;
@@ -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++) {

View File

@@ -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
@@ -123,13 +123,12 @@ typedef struct {
/* 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
@@ -175,13 +174,13 @@ start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
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 */
@@ -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 */
@@ -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
@@ -848,8 +847,8 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
/* 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 */
@@ -951,7 +950,7 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
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
@@ -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];
@@ -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
@@ -32,22 +34,15 @@ typedef struct {
/* 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.
@@ -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
@@ -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;

View File

@@ -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

@@ -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;

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
@@ -88,7 +90,7 @@ 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,
@@ -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

View File

@@ -218,7 +218,7 @@ jpeg_set_defaults (j_compress_ptr cinfo)
if (cinfo->comp_info == NULL) if (cinfo->comp_info == NULL)
cinfo->comp_info = (jpeg_component_info *) cinfo->comp_info = (jpeg_component_info *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
MAX_COMPONENTS * SIZEOF(jpeg_component_info)); MAX_COMPONENTS * sizeof(jpeg_component_info));
/* Initialize everything not dependent on the color space */ /* Initialize everything not dependent on the color space */
@@ -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;
@@ -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;

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.
@@ -88,16 +90,16 @@ typedef phuff_entropy_encoder * phuff_entropy_ptr;
#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);
/* /*
@@ -134,7 +136,7 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
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)
@@ -167,8 +169,8 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
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 */
@@ -786,7 +788,7 @@ 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];
@@ -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;

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.
@@ -278,7 +280,7 @@ 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++) {
@@ -293,7 +295,7 @@ create_context_buffer (j_compress_ptr cinfo)
(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];
@@ -323,7 +325,7 @@ jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
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;

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,9 +55,10 @@
/* 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 */
@@ -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;
@@ -504,14 +507,20 @@ jinit_downsampler (j_compress_ptr cinfo)
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) {
#if defined(__mips__)
if (jsimd_can_h2v2_smooth_downsample())
downsample->methods[ci] = jsimd_h2v2_smooth_downsample;
else
#endif
downsample->methods[ci] = h2v2_smooth_downsample; downsample->methods[ci] = h2v2_smooth_downsample;
downsample->pub.need_context_rows = TRUE; downsample->pub.need_context_rows = TRUE;
} else } else {
#endif #endif
if (jsimd_can_h2v2_downsample()) if (jsimd_can_h2v2_downsample())
downsample->methods[ci] = jsimd_h2v2_downsample; downsample->methods[ci] = jsimd_h2v2_downsample;
else else
downsample->methods[ci] = h2v2_downsample; 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;

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);
/* /*
@@ -105,7 +107,7 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
*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;
} }
} }
@@ -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
@@ -35,9 +37,9 @@ jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
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;
} }

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);
/* /*

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
@@ -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,7 +754,7 @@ 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++)

View File

@@ -23,8 +23,8 @@
#include "jerror.h" #include "jerror.h"
#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */ #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
extern void * malloc JPP((size_t size)); extern void * malloc (size_t size);
extern void free JPP((void *ptr)); extern void free (void *ptr);
#endif #endif
@@ -161,7 +161,7 @@ jpeg_mem_dest_tj (j_compress_ptr cinfo,
if (cinfo->dest == NULL) { /* first time for this JPEG object? */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */
cinfo->dest = (struct jpeg_destination_mgr *) cinfo->dest = (struct jpeg_destination_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(my_mem_destination_mgr)); sizeof(my_mem_destination_mgr));
dest = (my_mem_dest_ptr) cinfo->dest; dest = (my_mem_dest_ptr) cinfo->dest;
dest->newbuffer = NULL; dest->newbuffer = NULL;
} }

View File

@@ -23,8 +23,8 @@
#include "jerror.h" #include "jerror.h"
#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */ #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
extern void * malloc JPP((size_t size)); extern void * malloc (size_t size);
extern void free JPP((void *ptr)); extern void free (void *ptr);
#endif #endif
@@ -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;
@@ -216,7 +216,7 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
if (cinfo->dest == NULL) { /* first time for this JPEG object? */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */
cinfo->dest = (struct jpeg_destination_mgr *) cinfo->dest = (struct jpeg_destination_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(my_destination_mgr)); sizeof(my_destination_mgr));
} }
dest = (my_dest_ptr) cinfo->dest; dest = (my_dest_ptr) cinfo->dest;
@@ -254,7 +254,7 @@ jpeg_mem_dest (j_compress_ptr cinfo,
if (cinfo->dest == NULL) { /* first time for this JPEG object? */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */
cinfo->dest = (struct jpeg_destination_mgr *) cinfo->dest = (struct jpeg_destination_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(my_mem_destination_mgr)); sizeof(my_mem_destination_mgr));
} }
dest = (my_mem_dest_ptr) cinfo->dest; dest = (my_mem_dest_ptr) cinfo->dest;

View File

@@ -171,7 +171,7 @@ jpeg_mem_src_tj (j_decompress_ptr cinfo,
if (cinfo->src == NULL) { /* first time for this JPEG object? */ if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *) cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(struct jpeg_source_mgr)); sizeof(struct jpeg_source_mgr));
} }
src = cinfo->src; src = cinfo->src;

View File

@@ -227,11 +227,11 @@ jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
if (cinfo->src == NULL) { /* first time for this JPEG object? */ if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *) cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(my_source_mgr)); sizeof(my_source_mgr));
src = (my_src_ptr) cinfo->src; src = (my_src_ptr) cinfo->src;
src->buffer = (JOCTET *) src->buffer = (JOCTET *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
INPUT_BUF_SIZE * SIZEOF(JOCTET)); INPUT_BUF_SIZE * sizeof(JOCTET));
} }
src = (my_src_ptr) cinfo->src; src = (my_src_ptr) cinfo->src;
@@ -268,7 +268,7 @@ jpeg_mem_src (j_decompress_ptr cinfo,
if (cinfo->src == NULL) { /* first time for this JPEG object? */ if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *) cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(struct jpeg_source_mgr)); sizeof(struct jpeg_source_mgr));
} }
src = cinfo->src; src = cinfo->src;

View File

@@ -42,9 +42,6 @@ typedef struct {
/* 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.
*/ */
@@ -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
@@ -168,8 +165,8 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col; for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
MCU_col_num++) { MCU_col_num++) {
/* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */
jzero_far((void 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;
@@ -426,7 +423,7 @@ smoothing_ok (j_decompress_ptr cinfo)
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;
@@ -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;
@@ -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

@@ -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 */
@@ -215,16 +216,16 @@ 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 */
@@ -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;
@@ -543,6 +544,9 @@ ycck_cmyk_convert (j_decompress_ptr cinfo,
} }
#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;
@@ -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) {

108
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
@@ -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);
/* /*

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.
@@ -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;
} }

View File

@@ -177,7 +177,7 @@ 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 */
@@ -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;

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,14 +12,6 @@
* 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 */
@@ -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);
/* /*
@@ -167,8 +159,8 @@ typedef struct { /* Bitreading working state within an MCU */
/* 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);
/* /*
@@ -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

@@ -31,7 +31,7 @@ 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);
/* /*
@@ -253,8 +253,8 @@ latch_quant_tables (j_decompress_ptr cinfo)
/* 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;
} }
} }
@@ -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

@@ -144,15 +144,15 @@ 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_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,7 +185,7 @@ 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);
@@ -484,7 +484,7 @@ 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;

View File

@@ -276,7 +276,7 @@ get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
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++) {
@@ -472,7 +472,7 @@ 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;
@@ -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)
@@ -597,7 +597,7 @@ get_dri (j_decompress_ptr cinfo)
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.
@@ -673,7 +673,7 @@ 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.
@@ -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);
@@ -778,13 +778,13 @@ save_marker (j_decompress_ptr cinfo)
/* 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;
@@ -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;
@@ -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;

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.
@@ -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 ||
@@ -352,6 +358,7 @@ 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:
@@ -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,11 +429,11 @@ 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;
@@ -439,9 +443,9 @@ prepare_range_limit_table (j_decompress_ptr cinfo)
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));
} }
@@ -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;

406
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.
@@ -39,20 +40,51 @@
#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 */
@@ -195,16 +227,16 @@ 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 */
@@ -260,8 +292,11 @@ merged_2v_upsample (j_decompress_ptr cinfo,
if (upsample->spare_full) { if (upsample->spare_full) {
/* If we have a spare row saved from a previous cycle, just return it. */ /* If we have a spare row saved from a previous cycle, just return it. */
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 {
@@ -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;
} }

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.
@@ -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);
/* /*
@@ -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.
@@ -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
@@ -253,7 +252,7 @@ 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 */

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,9 +30,10 @@
/* 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 */
@@ -411,7 +413,7 @@ 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;
@@ -481,6 +483,11 @@ jinit_upsampler (j_decompress_ptr cinfo)
} 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 */
#if defined(__mips__)
if (jsimd_can_int_upsample())
upsample->methods[ci] = jsimd_int_upsample;
else
#endif
upsample->methods[ci] = int_upsample; upsample->methods[ci] = int_upsample;
upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group); upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group); upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);

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);
/* /*

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.
@@ -41,10 +43,6 @@
* want to refer to it directly. * want to refer to it directly.
*/ */
#ifdef NEED_SHORT_EXTERNAL_NAMES
#define jpeg_std_message_table jMsgTable
#endif
#define JMESSAGE(code,string) string , #define JMESSAGE(code,string) string ,
const char * const jpeg_std_message_table[] = { const char * const jpeg_std_message_table[] = {

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.
@@ -132,7 +134,7 @@ 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")

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
@@ -69,16 +71,6 @@
#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.

111
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
@@ -32,7 +34,7 @@
#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
@@ -80,7 +82,7 @@ round_up_pow2 (size_t a, size_t b)
#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,8 +93,7 @@ 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;
@@ -103,7 +104,7 @@ typedef struct small_pool_struct {
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 */
@@ -277,7 +278,7 @@ 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 */
@@ -295,7 +296,7 @@ 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
@@ -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,7 +366,7 @@ 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 */
@@ -374,11 +374,11 @@ alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
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
@@ -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,7 +443,7 @@ 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;
@@ -452,7 +451,7 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
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;
@@ -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,7 +495,7 @@ 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;
@@ -504,7 +503,7 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
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;
@@ -567,7 +566,7 @@ request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
/* 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;
@@ -597,7 +596,7 @@ request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
/* 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;
@@ -631,17 +630,17 @@ realize_virt_arrays (j_common_ptr cinfo)
for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) { for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
if (sptr->mem_buffer == NULL) { /* if not realized yet */ if (sptr->mem_buffer == NULL) { /* if not realized yet */
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);
} }
} }
@@ -681,7 +680,7 @@ realize_virt_arrays (j_common_ptr cinfo)
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,
@@ -705,7 +704,7 @@ realize_virt_arrays (j_common_ptr cinfo)
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,
@@ -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) {
@@ -741,11 +740,11 @@ do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
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) {
@@ -774,11 +773,11 @@ do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
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;
} }
@@ -850,11 +849,11 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
if (writable) if (writable)
ptr->first_undef_row = end_row; ptr->first_undef_row = end_row;
if (ptr->pre_zero) { if (ptr->pre_zero) {
size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE); size_t bytesperrow = (size_t) ptr->samplesperrow * sizeof(JSAMPLE);
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */ undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
end_row -= ptr->cur_start_row; end_row -= ptr->cur_start_row;
while (undef_row < end_row) { while (undef_row < end_row) {
jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow); jzero_far((void *) ptr->mem_buffer[undef_row], bytesperrow);
undef_row++; undef_row++;
} }
} else { } else {
@@ -935,11 +934,11 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
if (writable) if (writable)
ptr->first_undef_row = end_row; ptr->first_undef_row = end_row;
if (ptr->pre_zero) { if (ptr->pre_zero) {
size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK); size_t bytesperrow = (size_t) ptr->blocksperrow * sizeof(JBLOCK);
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */ undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
end_row -= ptr->cur_start_row; end_row -= ptr->cur_start_row;
while (undef_row < end_row) { while (undef_row < end_row) {
jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow); jzero_far((void *) ptr->mem_buffer[undef_row], bytesperrow);
undef_row++; undef_row++;
} }
} else { } else {
@@ -1004,8 +1003,8 @@ free_pool (j_common_ptr cinfo, int pool_id)
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;
} }
@@ -1018,7 +1017,7 @@ free_pool (j_common_ptr cinfo, int pool_id)
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,7 +1044,7 @@ 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 */
@@ -1068,7 +1067,7 @@ jinit_memory_mgr (j_common_ptr cinfo)
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,7 +1088,7 @@ 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 */
@@ -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;

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-
@@ -21,8 +23,8 @@
#include "jmemsys.h" /* import the system-dependent declarations */ #include "jmemsys.h" /* import the system-dependent declarations */
#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */ #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
extern void * malloc 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);
} }

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,34 +28,30 @@
* 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).
@@ -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);
/* /*
@@ -138,16 +120,13 @@ 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
@@ -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
@@ -192,35 +192,6 @@ typedef unsigned int JDIMENSION;
#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
/* /*
* On a few systems, type boolean and/or its values FALSE, TRUE may appear * On a few systems, type boolean and/or its values FALSE, TRUE may appear
* in standard header files. Or you may have conflicts with application- * in standard header files. Or you may have conflicts with application-
@@ -298,18 +269,24 @@ typedef int boolean;
/* /*
* 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 */
@@ -317,7 +294,7 @@ typedef int boolean;
#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. */
@@ -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 */

290
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.
@@ -48,9 +50,9 @@ typedef enum { /* Operating modes for buffer controllers */
/* 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 */
@@ -59,80 +61,74 @@ struct jpeg_comp_master {
/* 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,
JDIMENSION in_rows_avail,
JSAMPIMAGE output_buf, JSAMPIMAGE output_buf,
JDIMENSION *out_row_group_ctr, JDIMENSION *out_row_group_ctr,
JDIMENSION out_row_groups_avail)); 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,8 +136,8 @@ 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 */
@@ -149,10 +145,10 @@ struct jpeg_decomp_master {
/* 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 */
@@ -161,43 +157,39 @@ struct jpeg_input_controller {
/* 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, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
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;
@@ -212,9 +204,8 @@ struct jpeg_marker_reader {
/* 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 */
@@ -222,47 +213,44 @@ struct jpeg_entropy_decoder {
}; };
/* 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, JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
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));
}; };
@@ -296,96 +284,54 @@ struct jpeg_color_quantizer {
#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 */

365
jpeglib.h
View File

@@ -4,8 +4,8 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2002-2009 by Guido Vollbeding. * Modified 2002-2009 by Guido Vollbeding.
* Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009-2011, 2013, D. R. Commander. * Copyright (C) 2009-2011, 2013-2014, D. R. Commander.
* 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.
@@ -64,20 +64,18 @@ extern "C" {
/* Data structures for images (arrays of samples and of DCT coefficients). /* Data structures for images (arrays of samples and of DCT coefficients).
* On 80x86 machines, the image arrays are too big for near pointers,
* but the pointer arrays can fit in near memory.
*/ */
typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */ typedef JSAMPLE *JSAMPROW; /* ptr to one image row of pixel samples. */
typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */ typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */ typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */ typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */ typedef JBLOCK *JBLOCKROW; /* pointer to one row of coefficient blocks */
typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */ typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */ typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */ typedef JCOEF *JCOEFPTR; /* useful in a couple of places */
/* Types for JPEG compression parameters and working tables. */ /* Types for JPEG compression parameters and working tables. */
@@ -146,8 +144,8 @@ typedef struct {
/* Size of a DCT block in samples. Always DCTSIZE for compression. /* Size of a DCT block in samples. Always DCTSIZE for compression.
* For decompression this is the size of the output from one DCT block, * For decompression this is the size of the output from one DCT block,
* reflecting any scaling we choose to apply during the IDCT step. * reflecting any scaling we choose to apply during the IDCT step.
* Values of 1,2,4,8 are likely to be supported. Note that different * Values from 1 to 16 are supported.
* components may receive different IDCT scalings. * Note that different components may receive different IDCT scalings.
*/ */
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
int DCT_h_scaled_size; int DCT_h_scaled_size;
@@ -200,14 +198,14 @@ typedef struct {
/* The decompressor can save APPn and COM markers in a list of these: */ /* The decompressor can save APPn and COM markers in a list of these: */
typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr; typedef struct jpeg_marker_struct * jpeg_saved_marker_ptr;
struct jpeg_marker_struct { struct jpeg_marker_struct {
jpeg_saved_marker_ptr next; /* next in list, or NULL */ jpeg_saved_marker_ptr next; /* next in list, or NULL */
UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */ UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
unsigned int original_length; /* # bytes of data in the file */ unsigned int original_length; /* # bytes of data in the file */
unsigned int data_length; /* # bytes of data saved at data[] */ unsigned int data_length; /* # bytes of data saved at data[] */
JOCTET FAR * data; /* the data contained in the marker */ JOCTET * data; /* the data contained in the marker */
/* the marker length word is not counted in data_length or original_length */ /* the marker length word is not counted in data_length or original_length */
}; };
@@ -219,8 +217,8 @@ struct jpeg_marker_struct {
typedef enum { typedef enum {
JCS_UNKNOWN, /* error/unspecified */ JCS_UNKNOWN, /* error/unspecified */
JCS_GRAYSCALE, /* monochrome */ JCS_GRAYSCALE, /* monochrome */
JCS_RGB, /* red/green/blue as specified by the RGB_RED, RGB_GREEN, JCS_RGB, /* red/green/blue as specified by the RGB_RED,
RGB_BLUE, and RGB_PIXELSIZE macros */ RGB_GREEN, RGB_BLUE, and RGB_PIXELSIZE macros */
JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */ JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
JCS_CMYK, /* C/M/Y/K */ JCS_CMYK, /* C/M/Y/K */
JCS_YCCK, /* Y/Cb/Cr/K */ JCS_YCCK, /* Y/Cb/Cr/K */
@@ -230,17 +228,17 @@ typedef enum {
JCS_EXT_BGRX, /* blue/green/red/x */ JCS_EXT_BGRX, /* blue/green/red/x */
JCS_EXT_XBGR, /* x/blue/green/red */ JCS_EXT_XBGR, /* x/blue/green/red */
JCS_EXT_XRGB, /* x/red/green/blue */ JCS_EXT_XRGB, /* x/red/green/blue */
/* When out_color_space it set to JCS_EXT_RGBX, JCS_EXT_BGRX, /* When out_color_space it set to JCS_EXT_RGBX, JCS_EXT_BGRX, JCS_EXT_XBGR,
JCS_EXT_XBGR, or JCS_EXT_XRGB during decompression, the X byte is or JCS_EXT_XRGB during decompression, the X byte is undefined, and in
undefined, and in order to ensure the best performance, order to ensure the best performance, libjpeg-turbo can set that byte to
libjpeg-turbo can set that byte to whatever value it wishes. Use whatever value it wishes. Use the following colorspace constants to
the following colorspace constants to ensure that the X byte is set ensure that the X byte is set to 0xFF, so that it can be interpreted as an
to 0xFF, so that it can be interpreted as an opaque alpha opaque alpha channel. */
channel. */
JCS_EXT_RGBA, /* red/green/blue/alpha */ JCS_EXT_RGBA, /* red/green/blue/alpha */
JCS_EXT_BGRA, /* blue/green/red/alpha */ JCS_EXT_BGRA, /* blue/green/red/alpha */
JCS_EXT_ABGR, /* alpha/blue/green/red */ JCS_EXT_ABGR, /* alpha/blue/green/red */
JCS_EXT_ARGB /* alpha/red/green/blue */ JCS_EXT_ARGB, /* alpha/red/green/blue */
JCS_RGB565 /* 5-bit red/6-bit green/5-bit blue */
} J_COLOR_SPACE; } J_COLOR_SPACE;
/* DCT/IDCT algorithm options. */ /* DCT/IDCT algorithm options. */
@@ -749,16 +747,16 @@ struct jpeg_decompress_struct {
struct jpeg_error_mgr { struct jpeg_error_mgr {
/* Error exit handler: does not return to caller */ /* Error exit handler: does not return to caller */
JMETHOD(void, error_exit, (j_common_ptr cinfo)); void (*error_exit) (j_common_ptr cinfo);
/* Conditionally emit a trace or warning message */ /* Conditionally emit a trace or warning message */
JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level)); void (*emit_message) (j_common_ptr cinfo, int msg_level);
/* Routine that actually outputs a trace or error message */ /* Routine that actually outputs a trace or error message */
JMETHOD(void, output_message, (j_common_ptr cinfo)); void (*output_message) (j_common_ptr cinfo);
/* Format a message string for the most recent JPEG error or message */ /* Format a message string for the most recent JPEG error or message */
JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer)); void (*format_message) (j_common_ptr cinfo, char * buffer);
#define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */ #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
/* Reset error state variables at start of a new image */ /* Reset error state variables at start of a new image */
JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo)); void (*reset_error_mgr) (j_common_ptr cinfo);
/* The message ID code and any parameters are saved here. /* The message ID code and any parameters are saved here.
* A message can have one string parameter or up to 8 int parameters. * A message can have one string parameter or up to 8 int parameters.
@@ -806,7 +804,7 @@ struct jpeg_error_mgr {
/* Progress monitor object */ /* Progress monitor object */
struct jpeg_progress_mgr { struct jpeg_progress_mgr {
JMETHOD(void, progress_monitor, (j_common_ptr cinfo)); void (*progress_monitor) (j_common_ptr cinfo);
long pass_counter; /* work units completed in this pass */ long pass_counter; /* work units completed in this pass */
long pass_limit; /* total number of work units in this pass */ long pass_limit; /* total number of work units in this pass */
@@ -821,9 +819,9 @@ struct jpeg_destination_mgr {
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 */
JMETHOD(void, init_destination, (j_compress_ptr cinfo)); void (*init_destination) (j_compress_ptr cinfo);
JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo)); boolean (*empty_output_buffer) (j_compress_ptr cinfo);
JMETHOD(void, term_destination, (j_compress_ptr cinfo)); void (*term_destination) (j_compress_ptr cinfo);
}; };
@@ -833,11 +831,11 @@ struct jpeg_source_mgr {
const JOCTET * next_input_byte; /* => next byte to read from buffer */ const JOCTET * next_input_byte; /* => next byte to read from buffer */
size_t bytes_in_buffer; /* # of bytes remaining in buffer */ size_t bytes_in_buffer; /* # of bytes remaining in buffer */
JMETHOD(void, init_source, (j_decompress_ptr cinfo)); void (*init_source) (j_decompress_ptr cinfo);
JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo)); boolean (*fill_input_buffer) (j_decompress_ptr cinfo);
JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes)); void (*skip_input_data) (j_decompress_ptr cinfo, long num_bytes);
JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired)); boolean (*resync_to_restart) (j_decompress_ptr cinfo, int desired);
JMETHOD(void, term_source, (j_decompress_ptr cinfo)); void (*term_source) (j_decompress_ptr cinfo);
}; };
@@ -862,41 +860,32 @@ typedef struct jvirt_barray_control * jvirt_barray_ptr;
struct jpeg_memory_mgr { struct jpeg_memory_mgr {
/* Method pointers */ /* Method pointers */
JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id, void * (*alloc_small) (j_common_ptr cinfo, int pool_id, size_t sizeofobject);
size_t sizeofobject)); void * (*alloc_large) (j_common_ptr cinfo, int pool_id,
JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id, size_t sizeofobject);
size_t sizeofobject)); JSAMPARRAY (*alloc_sarray) (j_common_ptr cinfo, int pool_id,
JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow, JDIMENSION numrows);
JDIMENSION samplesperrow, JBLOCKARRAY (*alloc_barray) (j_common_ptr cinfo, int pool_id,
JDIMENSION numrows)); JDIMENSION blocksperrow, JDIMENSION numrows);
JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id, jvirt_sarray_ptr (*request_virt_sarray) (j_common_ptr cinfo, int pool_id,
JDIMENSION blocksperrow,
JDIMENSION numrows));
JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
int pool_id,
boolean pre_zero, boolean pre_zero,
JDIMENSION samplesperrow, JDIMENSION samplesperrow,
JDIMENSION numrows, JDIMENSION numrows,
JDIMENSION maxaccess)); JDIMENSION maxaccess);
JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo, jvirt_barray_ptr (*request_virt_barray) (j_common_ptr cinfo, int pool_id,
int pool_id,
boolean pre_zero, boolean pre_zero,
JDIMENSION blocksperrow, JDIMENSION blocksperrow,
JDIMENSION numrows, JDIMENSION numrows,
JDIMENSION maxaccess)); JDIMENSION maxaccess);
JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo)); void (*realize_virt_arrays) (j_common_ptr cinfo);
JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo, JSAMPARRAY (*access_virt_sarray) (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
jvirt_sarray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows,
JDIMENSION start_row, boolean writable);
JDIMENSION num_rows, JBLOCKARRAY (*access_virt_barray) (j_common_ptr cinfo, jvirt_barray_ptr ptr,
boolean writable)); JDIMENSION start_row, JDIMENSION num_rows,
JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo, boolean writable);
jvirt_barray_ptr ptr, void (*free_pool) (j_common_ptr cinfo, int pool_id);
JDIMENSION start_row, void (*self_destruct) (j_common_ptr cinfo);
JDIMENSION num_rows,
boolean writable));
JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
JMETHOD(void, self_destruct, (j_common_ptr cinfo));
/* Limit on memory allocation for this JPEG object. (Note that this is /* Limit on memory allocation for this JPEG object. (Note that this is
* merely advisory, not a guaranteed maximum; it only affects the space * merely advisory, not a guaranteed maximum; it only affects the space
@@ -913,96 +902,11 @@ struct jpeg_memory_mgr {
/* Routine signature for application-supplied marker processing methods. /* Routine signature for application-supplied marker processing methods.
* Need not pass marker code since it is stored in cinfo->unread_marker. * Need not pass marker code since it is stored in cinfo->unread_marker.
*/ */
typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo)); typedef boolean (*jpeg_marker_parser_method) (j_decompress_ptr cinfo);
/* Declarations for routines called by application.
* The JPP macro hides prototype parameters from compilers that can't cope.
* Note JPP requires double parentheses.
*/
#ifdef HAVE_PROTOTYPES
#define JPP(arglist) arglist
#else
#define JPP(arglist) ()
#endif
/* Short forms of external names for systems with brain-damaged linkers.
* We shorten external names to be unique in the first six letters, which
* is good enough for all known systems.
* (If your compiler itself needs names to be unique in less than 15
* characters, you are out of luck. Get a better compiler.)
*/
#ifdef NEED_SHORT_EXTERNAL_NAMES
#define jpeg_std_error jStdError
#define jpeg_CreateCompress jCreaCompress
#define jpeg_CreateDecompress jCreaDecompress
#define jpeg_destroy_compress jDestCompress
#define jpeg_destroy_decompress jDestDecompress
#define jpeg_stdio_dest jStdDest
#define jpeg_stdio_src jStdSrc
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
#define jpeg_mem_dest jMemDest
#define jpeg_mem_src jMemSrc
#endif
#define jpeg_set_defaults jSetDefaults
#define jpeg_set_colorspace jSetColorspace
#define jpeg_default_colorspace jDefColorspace
#define jpeg_set_quality jSetQuality
#define jpeg_set_linear_quality jSetLQuality
#if JPEG_LIB_VERSION >= 70
#define jpeg_default_qtables jDefQTables
#endif
#define jpeg_add_quant_table jAddQuantTable
#define jpeg_quality_scaling jQualityScaling
#define jpeg_simple_progression jSimProgress
#define jpeg_suppress_tables jSuppressTables
#define jpeg_alloc_quant_table jAlcQTable
#define jpeg_alloc_huff_table jAlcHTable
#define jpeg_start_compress jStrtCompress
#define jpeg_write_scanlines jWrtScanlines
#define jpeg_finish_compress jFinCompress
#if JPEG_LIB_VERSION >= 70
#define jpeg_calc_jpeg_dimensions jCjpegDimensions
#endif
#define jpeg_write_raw_data jWrtRawData
#define jpeg_write_marker jWrtMarker
#define jpeg_write_m_header jWrtMHeader
#define jpeg_write_m_byte jWrtMByte
#define jpeg_write_tables jWrtTables
#define jpeg_read_header jReadHeader
#define jpeg_start_decompress jStrtDecompress
#define jpeg_read_scanlines jReadScanlines
#define jpeg_finish_decompress jFinDecompress
#define jpeg_read_raw_data jReadRawData
#define jpeg_has_multiple_scans jHasMultScn
#define jpeg_start_output jStrtOutput
#define jpeg_finish_output jFinOutput
#define jpeg_input_complete jInComplete
#define jpeg_new_colormap jNewCMap
#define jpeg_consume_input jConsumeInput
#if JPEG_LIB_VERSION >= 80
#define jpeg_core_output_dimensions jCoreDimensions
#endif
#define jpeg_calc_output_dimensions jCalcDimensions
#define jpeg_save_markers jSaveMarkers
#define jpeg_set_marker_processor jSetMarker
#define jpeg_read_coefficients jReadCoefs
#define jpeg_write_coefficients jWrtCoefs
#define jpeg_copy_critical_parameters jCopyCrit
#define jpeg_abort_compress jAbrtCompress
#define jpeg_abort_decompress jAbrtDecompress
#define jpeg_abort jAbort
#define jpeg_destroy jDestroy
#define jpeg_resync_to_restart jResyncRestart
#endif /* NEED_SHORT_EXTERNAL_NAMES */
/* Default error-management setup */ /* Default error-management setup */
EXTERN(struct jpeg_error_mgr *) jpeg_std_error EXTERN(struct jpeg_error_mgr *) jpeg_std_error (struct jpeg_error_mgr * err);
JPP((struct jpeg_error_mgr * err));
/* Initialization of JPEG compression objects. /* Initialization of JPEG compression objects.
* jpeg_create_compress() and jpeg_create_decompress() are the exported * jpeg_create_compress() and jpeg_create_decompress() are the exported
@@ -1017,89 +921,80 @@ EXTERN(struct jpeg_error_mgr *) jpeg_std_error
#define jpeg_create_decompress(cinfo) \ #define jpeg_create_decompress(cinfo) \
jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \ jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
(size_t) sizeof(struct jpeg_decompress_struct)) (size_t) sizeof(struct jpeg_decompress_struct))
EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo, EXTERN(void) jpeg_CreateCompress (j_compress_ptr cinfo, int version,
int version, size_t structsize)); size_t structsize);
EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo, EXTERN(void) jpeg_CreateDecompress (j_decompress_ptr cinfo, int version,
int version, size_t structsize)); size_t structsize);
/* Destruction of JPEG compression objects */ /* Destruction of JPEG compression objects */
EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo)); EXTERN(void) jpeg_destroy_compress (j_compress_ptr cinfo);
EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo)); EXTERN(void) jpeg_destroy_decompress (j_decompress_ptr cinfo);
/* Standard data source and destination managers: stdio streams. */ /* Standard data source and destination managers: stdio streams. */
/* Caller is responsible for opening the file before and closing after. */ /* Caller is responsible for opening the file before and closing after. */
EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile)); EXTERN(void) jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile);
EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile)); EXTERN(void) jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile);
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED) #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
/* Data source and destination managers: memory buffers. */ /* Data source and destination managers: memory buffers. */
EXTERN(void) jpeg_mem_dest JPP((j_compress_ptr cinfo, EXTERN(void) jpeg_mem_dest (j_compress_ptr cinfo, unsigned char ** outbuffer,
unsigned char ** outbuffer, unsigned long * outsize);
unsigned long * outsize)); EXTERN(void) jpeg_mem_src (j_decompress_ptr cinfo, unsigned char * inbuffer,
EXTERN(void) jpeg_mem_src JPP((j_decompress_ptr cinfo, unsigned long insize);
unsigned char * inbuffer,
unsigned long insize));
#endif #endif
/* Default parameter setup for compression */ /* Default parameter setup for compression */
EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo)); EXTERN(void) jpeg_set_defaults (j_compress_ptr cinfo);
/* Compression parameter setup aids */ /* Compression parameter setup aids */
EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo, EXTERN(void) jpeg_set_colorspace (j_compress_ptr cinfo,
J_COLOR_SPACE colorspace)); J_COLOR_SPACE colorspace);
EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo)); EXTERN(void) jpeg_default_colorspace (j_compress_ptr cinfo);
EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality, EXTERN(void) jpeg_set_quality (j_compress_ptr cinfo, int quality,
boolean force_baseline)); boolean force_baseline);
EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo, EXTERN(void) jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
int scale_factor, boolean force_baseline);
boolean force_baseline));
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
EXTERN(void) jpeg_default_qtables JPP((j_compress_ptr cinfo, EXTERN(void) jpeg_default_qtables (j_compress_ptr cinfo,
boolean force_baseline)); boolean force_baseline);
#endif #endif
EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl, EXTERN(void) jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
const unsigned int *basic_table, const unsigned int *basic_table,
int scale_factor, int scale_factor, boolean force_baseline);
boolean force_baseline)); EXTERN(int) jpeg_quality_scaling (int quality);
EXTERN(int) jpeg_quality_scaling JPP((int quality)); EXTERN(void) jpeg_simple_progression (j_compress_ptr cinfo);
EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo)); EXTERN(void) jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress);
EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo, EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table (j_common_ptr cinfo);
boolean suppress)); EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table (j_common_ptr cinfo);
EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
/* Main entry points for compression */ /* Main entry points for compression */
EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo, EXTERN(void) jpeg_start_compress (j_compress_ptr cinfo,
boolean write_all_tables)); boolean write_all_tables);
EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo, EXTERN(JDIMENSION) jpeg_write_scanlines (j_compress_ptr cinfo,
JSAMPARRAY scanlines, JSAMPARRAY scanlines,
JDIMENSION num_lines)); JDIMENSION num_lines);
EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo)); EXTERN(void) jpeg_finish_compress (j_compress_ptr cinfo);
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
/* Precalculate JPEG dimensions for current compression parameters. */ /* Precalculate JPEG dimensions for current compression parameters. */
EXTERN(void) jpeg_calc_jpeg_dimensions JPP((j_compress_ptr cinfo)); EXTERN(void) jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo);
#endif #endif
/* Replaces jpeg_write_scanlines when writing raw downsampled data. */ /* Replaces jpeg_write_scanlines when writing raw downsampled data. */
EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo, EXTERN(JDIMENSION) jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
JSAMPIMAGE data, JDIMENSION num_lines);
JDIMENSION num_lines));
/* Write a special marker. See libjpeg.txt concerning safe usage. */ /* Write a special marker. See libjpeg.txt concerning safe usage. */
EXTERN(void) jpeg_write_marker EXTERN(void) jpeg_write_marker (j_compress_ptr cinfo, int marker,
JPP((j_compress_ptr cinfo, int marker, const JOCTET * dataptr, unsigned int datalen);
const JOCTET * dataptr, unsigned int datalen));
/* Same, but piecemeal. */ /* Same, but piecemeal. */
EXTERN(void) jpeg_write_m_header EXTERN(void) jpeg_write_m_header (j_compress_ptr cinfo, int marker,
JPP((j_compress_ptr cinfo, int marker, unsigned int datalen)); unsigned int datalen);
EXTERN(void) jpeg_write_m_byte EXTERN(void) jpeg_write_m_byte (j_compress_ptr cinfo, int val);
JPP((j_compress_ptr cinfo, int val));
/* Alternate compression function: just write an abbreviated table file */ /* Alternate compression function: just write an abbreviated table file */
EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo)); EXTERN(void) jpeg_write_tables (j_compress_ptr cinfo);
/* Decompression startup: read start of JPEG datastream to see what's there */ /* Decompression startup: read start of JPEG datastream to see what's there */
EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo, EXTERN(int) jpeg_read_header (j_decompress_ptr cinfo, boolean require_image);
boolean require_image));
/* Return value is one of: */ /* Return value is one of: */
#define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */ #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
#define JPEG_HEADER_OK 1 /* Found valid image datastream */ #define JPEG_HEADER_OK 1 /* Found valid image datastream */
@@ -1111,25 +1006,23 @@ EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
*/ */
/* Main entry points for decompression */ /* Main entry points for decompression */
EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo)); EXTERN(boolean) jpeg_start_decompress (j_decompress_ptr cinfo);
EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo, EXTERN(JDIMENSION) jpeg_read_scanlines (j_decompress_ptr cinfo,
JSAMPARRAY scanlines, JSAMPARRAY scanlines,
JDIMENSION max_lines)); JDIMENSION max_lines);
EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo)); EXTERN(boolean) jpeg_finish_decompress (j_decompress_ptr cinfo);
/* Replaces jpeg_read_scanlines when reading raw downsampled data. */ /* Replaces jpeg_read_scanlines when reading raw downsampled data. */
EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo, EXTERN(JDIMENSION) jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
JSAMPIMAGE data, JDIMENSION max_lines);
JDIMENSION max_lines));
/* Additional entry points for buffered-image mode. */ /* Additional entry points for buffered-image mode. */
EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo)); EXTERN(boolean) jpeg_has_multiple_scans (j_decompress_ptr cinfo);
EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo, EXTERN(boolean) jpeg_start_output (j_decompress_ptr cinfo, int scan_number);
int scan_number)); EXTERN(boolean) jpeg_finish_output (j_decompress_ptr cinfo);
EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo)); EXTERN(boolean) jpeg_input_complete (j_decompress_ptr cinfo);
EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo)); EXTERN(void) jpeg_new_colormap (j_decompress_ptr cinfo);
EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo)); EXTERN(int) jpeg_consume_input (j_decompress_ptr cinfo);
EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
/* Return value is one of: */ /* Return value is one of: */
/* #define JPEG_SUSPENDED 0 Suspended due to lack of input data */ /* #define JPEG_SUSPENDED 0 Suspended due to lack of input data */
#define JPEG_REACHED_SOS 1 /* Reached start of new scan */ #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
@@ -1139,26 +1032,25 @@ EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
/* Precalculate output dimensions for current decompression parameters. */ /* Precalculate output dimensions for current decompression parameters. */
#if JPEG_LIB_VERSION >= 80 #if JPEG_LIB_VERSION >= 80
EXTERN(void) jpeg_core_output_dimensions JPP((j_decompress_ptr cinfo)); EXTERN(void) jpeg_core_output_dimensions (j_decompress_ptr cinfo);
#endif #endif
EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo)); EXTERN(void) jpeg_calc_output_dimensions (j_decompress_ptr cinfo);
/* Control saving of COM and APPn markers into marker_list. */ /* Control saving of COM and APPn markers into marker_list. */
EXTERN(void) jpeg_save_markers EXTERN(void) jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
JPP((j_decompress_ptr cinfo, int marker_code, unsigned int length_limit);
unsigned int length_limit));
/* Install a special processing method for COM or APPn markers. */ /* Install a special processing method for COM or APPn markers. */
EXTERN(void) jpeg_set_marker_processor EXTERN(void) jpeg_set_marker_processor (j_decompress_ptr cinfo,
JPP((j_decompress_ptr cinfo, int marker_code, int marker_code,
jpeg_marker_parser_method routine)); jpeg_marker_parser_method routine);
/* Read or write raw DCT coefficients --- useful for lossless transcoding. */ /* Read or write raw DCT coefficients --- useful for lossless transcoding. */
EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo)); EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients (j_decompress_ptr cinfo);
EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo, EXTERN(void) jpeg_write_coefficients (j_compress_ptr cinfo,
jvirt_barray_ptr * coef_arrays)); jvirt_barray_ptr * coef_arrays);
EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo, EXTERN(void) jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
j_compress_ptr dstinfo)); j_compress_ptr dstinfo);
/* If you choose to abort compression or decompression before completing /* If you choose to abort compression or decompression before completing
* jpeg_finish_(de)compress, then you need to clean up to release memory, * jpeg_finish_(de)compress, then you need to clean up to release memory,
@@ -1166,18 +1058,17 @@ EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
* if you're done with the JPEG object, but if you want to clean it up and * if you're done with the JPEG object, but if you want to clean it up and
* reuse it, call this: * reuse it, call this:
*/ */
EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo)); EXTERN(void) jpeg_abort_compress (j_compress_ptr cinfo);
EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo)); EXTERN(void) jpeg_abort_decompress (j_decompress_ptr cinfo);
/* Generic versions of jpeg_abort and jpeg_destroy that work on either /* Generic versions of jpeg_abort and jpeg_destroy that work on either
* flavor of JPEG object. These may be more convenient in some places. * flavor of JPEG object. These may be more convenient in some places.
*/ */
EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo)); EXTERN(void) jpeg_abort (j_common_ptr cinfo);
EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo)); EXTERN(void) jpeg_destroy (j_common_ptr cinfo);
/* Default restart-marker-resync procedure for use by data source modules */ /* Default restart-marker-resync procedure for use by data source modules */
EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo, EXTERN(boolean) jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired);
int desired));
/* These marker codes are exported since applications and data source modules /* These marker codes are exported since applications and data source modules

View File

@@ -18,7 +18,7 @@
#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__
@@ -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

View File

@@ -121,9 +121,6 @@ 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
@@ -134,7 +131,7 @@ 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 */
@@ -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).
@@ -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;
@@ -640,8 +636,7 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (row = 0; row < num_rows; row++) { for (row = 0; row < num_rows; row++) {
/* Initialize output values to 0 so can process components separately */ /* Initialize output values to 0 so can process components separately */
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];
@@ -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);
@@ -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,7 +824,7 @@ 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;
@@ -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);

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.
@@ -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 */
@@ -129,10 +127,10 @@ static const int c_scales[3]={R_SCALE, G_SCALE, B_SCALE};
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 */
@@ -155,9 +153,6 @@ 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
@@ -168,7 +163,7 @@ 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 */
@@ -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;
@@ -1025,32 +1020,23 @@ pass2_fs_dither (j_decompress_ptr cinfo,
* Add these into the running sums, and simultaneously shift the * Add these into the running sums, and simultaneously shift the
* next-line error sums left by 1 column. * next-line error sums left by 1 column.
*/ */
{ register LOCFSERROR bnexterr, 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);
cur0 += delta; /* form error * 5 */
bpreverr0 = belowerr0 + cur0;
belowerr0 = bnexterr; belowerr0 = bnexterr;
cur0 += delta; /* form error * 7 */ cur0 *= 7;
bnexterr = cur1; /* Process component 1 */ bnexterr = cur1; /* Process component 1 */
delta = cur1 * 2; errorptr[1] = (FSERROR) (bpreverr1 + cur1 * 3);
cur1 += delta; /* form error * 3 */ bpreverr1 = belowerr1 + cur1 * 5;
errorptr[1] = (FSERROR) (bpreverr1 + cur1);
cur1 += delta; /* form error * 5 */
bpreverr1 = belowerr1 + cur1;
belowerr1 = bnexterr; belowerr1 = bnexterr;
cur1 += delta; /* form error * 7 */ cur1 *= 7;
bnexterr = cur2; /* Process component 2 */ bnexterr = cur2; /* Process component 2 */
delta = cur2 * 2; errorptr[2] = (FSERROR) (bpreverr2 + cur2 * 3);
cur2 += delta; /* form error * 3 */ bpreverr2 = belowerr2 + cur2 * 5;
errorptr[2] = (FSERROR) (bpreverr2 + cur2);
cur2 += delta; /* form error * 5 */
bpreverr2 = belowerr2 + cur2;
belowerr2 = bnexterr; belowerr2 = bnexterr;
cur2 += delta; /* form error * 7 */ cur2 *= 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
@@ -1097,7 +1083,7 @@ 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;
@@ -1181,13 +1167,13 @@ 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);
@@ -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,7 +1218,7 @@ 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;
@@ -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,

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
#define jsimd_convsamp_float jSConvF
#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_convsamp_float JPP((void));
EXTERN(void) jsimd_convsamp JPP((JSAMPARRAY sample_data,
JDIMENSION start_col, JDIMENSION start_col,
DCTELEM * workspace)); FAST_FLOAT * workspace);
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_fdct_islow (void);
EXTERN(int) jsimd_can_fdct_ifast JPP((void)); EXTERN(int) jsimd_can_fdct_ifast (void);
EXTERN(int) jsimd_can_fdct_float JPP((void)); EXTERN(int) jsimd_can_fdct_float (void);
EXTERN(void) jsimd_fdct_islow JPP((DCTELEM * data)); EXTERN(void) jsimd_fdct_islow (DCTELEM * data);
EXTERN(void) jsimd_fdct_ifast JPP((DCTELEM * data)); EXTERN(void) jsimd_fdct_ifast (DCTELEM * data);
EXTERN(void) jsimd_fdct_float JPP((FAST_FLOAT * data)); EXTERN(void) jsimd_fdct_float (FAST_FLOAT * data);
EXTERN(int) jsimd_can_quantize JPP((void)); EXTERN(int) jsimd_can_quantize (void);
EXTERN(int) jsimd_can_quantize_float JPP((void)); EXTERN(int) jsimd_can_quantize_float (void);
EXTERN(void) jsimd_quantize JPP((JCOEFPTR coef_block, EXTERN(void) jsimd_quantize (JCOEFPTR coef_block, DCTELEM * divisors,
DCTELEM * divisors, DCTELEM * workspace);
DCTELEM * workspace)); EXTERN(void) jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors,
EXTERN(void) jsimd_quantize_float JPP((JCOEFPTR coef_block, FAST_FLOAT * workspace);
FAST_FLOAT * divisors,
FAST_FLOAT * workspace));
EXTERN(int) jsimd_can_idct_2x2 JPP((void)); EXTERN(int) jsimd_can_idct_2x2 (void);
EXTERN(int) jsimd_can_idct_4x4 JPP((void)); EXTERN(int) jsimd_can_idct_4x4 (void);
EXTERN(int) jsimd_can_idct_6x6 JPP((void)); EXTERN(int) jsimd_can_idct_6x6 (void);
EXTERN(int) jsimd_can_idct_12x12 JPP((void)); EXTERN(int) jsimd_can_idct_12x12 (void);
EXTERN(void) jsimd_idct_2x2 JPP((j_decompress_ptr cinfo, EXTERN(void) jsimd_idct_2x2 (j_decompress_ptr cinfo,
jpeg_component_info * compptr, jpeg_component_info * compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION output_col);
JDIMENSION output_col)); EXTERN(void) jsimd_idct_4x4 (j_decompress_ptr cinfo,
EXTERN(void) jsimd_idct_4x4 JPP((j_decompress_ptr cinfo,
jpeg_component_info * compptr, jpeg_component_info * compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION output_col);
JDIMENSION output_col)); EXTERN(void) jsimd_idct_6x6 (j_decompress_ptr cinfo,
EXTERN(void) jsimd_idct_6x6 JPP((j_decompress_ptr cinfo,
jpeg_component_info * compptr, jpeg_component_info * compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION output_col);
JDIMENSION output_col)); EXTERN(void) jsimd_idct_12x12 (j_decompress_ptr cinfo,
EXTERN(void) jsimd_idct_12x12 JPP((j_decompress_ptr cinfo,
jpeg_component_info * compptr, jpeg_component_info * compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION output_col);
JDIMENSION output_col));
EXTERN(int) jsimd_can_idct_islow JPP((void)); EXTERN(int) jsimd_can_idct_islow (void);
EXTERN(int) jsimd_can_idct_ifast JPP((void)); EXTERN(int) jsimd_can_idct_ifast (void);
EXTERN(int) jsimd_can_idct_float JPP((void)); EXTERN(int) jsimd_can_idct_float (void);
EXTERN(void) jsimd_idct_islow JPP((j_decompress_ptr cinfo, EXTERN(void) jsimd_idct_islow (j_decompress_ptr cinfo,
jpeg_component_info * compptr, jpeg_component_info * compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION output_col);
JDIMENSION output_col)); EXTERN(void) jsimd_idct_ifast (j_decompress_ptr cinfo,
EXTERN(void) jsimd_idct_ifast JPP((j_decompress_ptr cinfo,
jpeg_component_info * compptr, jpeg_component_info * compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION output_col);
JDIMENSION output_col)); EXTERN(void) jsimd_idct_float (j_decompress_ptr cinfo,
EXTERN(void) jsimd_idct_float JPP((j_decompress_ptr cinfo,
jpeg_component_info * compptr, jpeg_component_info * compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block, JSAMPARRAY output_buf,
JSAMPARRAY output_buf, JDIMENSION output_col);
JDIMENSION output_col));

View File

@@ -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
@@ -87,26 +89,6 @@ 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,
@@ -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,12 +109,7 @@ 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
} }
} }
@@ -146,34 +119,14 @@ 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.
@@ -33,5 +33,7 @@
"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"

View File

@@ -2,7 +2,7 @@ USING THE IJG JPEG LIBRARY
This file was part of the Independent JPEG Group's software: This file was part of the Independent JPEG Group's software:
Copyright (C) 1994-2011, Thomas G. Lane, Guido Vollbeding. Copyright (C) 1994-2011, Thomas G. Lane, Guido Vollbeding.
Modifications: libjpeg-turbo Modifications:
Copyright (C) 2010, 2014, D. R. Commander. Copyright (C) 2010, 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.
@@ -52,7 +52,6 @@ Advanced features:
Memory usage Memory usage
Library compile-time options Library compile-time options
Portability considerations Portability considerations
Notes for MS-DOS implementors
You should read at least the overview and basic usage sections before trying You should read at least the overview and basic usage sections before trying
to program with the library. The sections on advanced features can be read to program with the library. The sections on advanced features can be read
@@ -764,12 +763,6 @@ compatible across versions; we only try to ensure source-code compatibility.
applications and introduce a ton of access functions instead. Too late now, applications and introduce a ton of access functions instead. Too late now,
however.) however.)
On some systems your application may need to set up a signal handler to ensure
that temporary files are deleted if the program is interrupted. This is most
critical if you are on MS-DOS and use the jmemdos.c memory manager back end;
it will try to grab extended memory for temp files, and that space will NOT be
freed automatically. See cjpeg.c or djpeg.c for an example signal handler.
It may be worth pointing out that the core JPEG library does not actually It may be worth pointing out that the core JPEG library does not actually
require the stdio library: only the default source/destination managers and require the stdio library: only the default source/destination managers and
error handler need it. You can use the library in a stdio-less environment error handler need it. You can use the library in a stdio-less environment
@@ -897,12 +890,14 @@ J_DCT_METHOD dct_method
JDCT_ISLOW, but this can be larger for some images. Do not use JDCT_ISLOW, but this can be larger for some images. Do not use
JDCT_IFAST with quality levels above 97. The algorithm often JDCT_IFAST with quality levels above 97. The algorithm often
degenerates at quality=98 and above and can actually produce a more degenerates at quality=98 and above and can actually produce a more
lossy image than if lower quality levels had been used. JDCT_FLOAT is lossy image than if lower quality levels had been used. Also, in
mostly a legacy feature. It does not produce significantly more libjpeg-turbo, JDCT_IFAST is not fully accelerated for quality levels
accurate results than the ISLOW method, and it is much slower. The above 97, so it will be slower than JDCT_ISLOW. JDCT_FLOAT is mainly a
FLOAT method may also give different results on different machines due legacy feature. It does not produce significantly more accurate
to varying roundoff behavior, whereas the integer methods should give results than the ISLOW method, and it is much slower. The FLOAT method
the same results on all machines. may also give different results on different machines due to varying
roundoff behavior, whereas the integer methods should give the same
results on all machines.
J_COLOR_SPACE jpeg_color_space J_COLOR_SPACE jpeg_color_space
int num_components int num_components
@@ -1199,7 +1194,7 @@ J_DCT_METHOD dct_method
when decompressing images that were compressed using quality levels when decompressing images that were compressed using quality levels
above 97. The algorithm often degenerates for such images and can above 97. The algorithm often degenerates for such images and can
actually produce a more lossy output image than if the JPEG image had actually produce a more lossy output image than if the JPEG image had
been compressed using lower quality levels. JDCT_FLOAT is mostly a been compressed using lower quality levels. JDCT_FLOAT is mainly a
legacy feature. It does not produce significantly more accurate legacy feature. It does not produce significantly more accurate
results than the ISLOW method, and it is much slower. The FLOAT method results than the ISLOW method, and it is much slower. The FLOAT method
may also give different results on different machines due to varying may also give different results on different machines due to varying
@@ -2875,18 +2870,6 @@ that space allocated with alloc_small() is ignored, on the assumption that
it's too small to be worth worrying about; so a reasonable safety margin it's too small to be worth worrying about; so a reasonable safety margin
should be left when setting max_memory_to_use. should be left when setting max_memory_to_use.
If you use the jmemname.c or jmemdos.c memory manager back end, it is
important to clean up the JPEG object properly to ensure that the temporary
files get deleted. (This is especially crucial with jmemdos.c, where the
"temporary files" may be extended-memory segments; if they are not freed,
DOS will require a reboot to recover the memory.) Thus, with these memory
managers, it's a good idea to provide a signal handler that will trap any
early exit from your program. The handler should call either jpeg_abort()
or jpeg_destroy() for any active JPEG objects. A handler is not needed with
jmemnobs.c, and shouldn't be necessary with jmemansi.c or jmemmac.c either,
since the C library is supposed to take care of deleting files made with
tmpfile().
Memory usage Memory usage
------------ ------------
@@ -2947,11 +2930,7 @@ The sample applications cjpeg and djpeg can support 12-bit mode only for PPM
and GIF file formats; you must disable the other file formats to compile a and GIF file formats; you must disable the other file formats to compile a
12-bit cjpeg or djpeg. (install.txt has more information about that.) 12-bit cjpeg or djpeg. (install.txt has more information about that.)
At present, a 12-bit library can handle *only* 12-bit images, not both At present, a 12-bit library can handle *only* 12-bit images, not both
precisions. (If you need to include both 8- and 12-bit libraries in a single precisions.
application, you could probably do it by defining NEED_SHORT_EXTERNAL_NAMES
for just one of the copies. You'd have to access the 8-bit and 12-bit copies
from separate application source files. This is untested ... if you try it,
we'd like to hear whether it works!)
Note that a 12-bit library always compresses in Huffman optimization mode, Note that a 12-bit library always compresses in Huffman optimization mode,
in order to generate valid Huffman tables. This is necessary because our in order to generate valid Huffman tables. This is necessary because our
@@ -2996,9 +2975,8 @@ the design goals in this area. (If you encounter any bugs that cause the
library to be less portable than is claimed here, we'd appreciate hearing library to be less portable than is claimed here, we'd appreciate hearing
about them.) about them.)
The code works fine on ANSI C, C++, and pre-ANSI C compilers, using any of The code works fine on ANSI C and C++ compilers, using any of the popular
the popular system include file setups, and some not-so-popular ones too. system include file setups, and some not-so-popular ones too.
See install.txt for configuration procedures.
The code is not dependent on the exact sizes of the C data types. As The code is not dependent on the exact sizes of the C data types. As
distributed, we make the assumptions that distributed, we make the assumptions that
@@ -3033,52 +3011,5 @@ heavily dependent on stdio.) malloc and free are called only from the memory
manager "back end" module, so you can use a different memory allocator by manager "back end" module, so you can use a different memory allocator by
replacing that one file. replacing that one file.
The code generally assumes that C names must be unique in the first 15
characters. However, global function names can be made unique in the
first 6 characters by defining NEED_SHORT_EXTERNAL_NAMES.
More info about porting the code may be gleaned by reading jconfig.txt, More info about porting the code may be gleaned by reading jconfig.txt,
jmorecfg.h, and jinclude.h. jmorecfg.h, and jinclude.h.
Notes for MS-DOS implementors
-----------------------------
The IJG code is designed to work efficiently in 80x86 "small" or "medium"
memory models (i.e., data pointers are 16 bits unless explicitly declared
"far"; code pointers can be either size). You may be able to use small
model to compile cjpeg or djpeg by itself, but you will probably have to use
medium model for any larger application. This won't make much difference in
performance. You *will* take a noticeable performance hit if you use a
large-data memory model (perhaps 10%-25%), and you should avoid "huge" model
if at all possible.
The JPEG library typically needs 2Kb-3Kb of stack space. It will also
malloc about 20K-30K of near heap space while executing (and lots of far
heap, but that doesn't count in this calculation). This figure will vary
depending on selected operating mode, and to a lesser extent on image size.
There is also about 5Kb-6Kb of constant data which will be allocated in the
near data segment (about 4Kb of this is the error message table).
Thus you have perhaps 20K available for other modules' static data and near
heap space before you need to go to a larger memory model. The C library's
static data will account for several K of this, but that still leaves a good
deal for your needs. (If you are tight on space, you could reduce the sizes
of the I/O buffers allocated by jdatasrc.c and jdatadst.c, say from 4K to
1K. Another possibility is to move the error message table to far memory;
this should be doable with only localized hacking on jerror.c.)
About 2K of the near heap space is "permanent" memory that will not be
released until you destroy the JPEG object. This is only an issue if you
save a JPEG object between compression or decompression operations.
Far data space may also be a tight resource when you are dealing with large
images. The most memory-intensive case is decompression with two-pass color
quantization, or single-pass quantization to an externally supplied color
map. This requires a 128Kb color lookup table plus strip buffers amounting
to about 40 bytes per column for typical sampling ratios (eg, about 25600
bytes for a 640-pixel-wide image). You may not be able to process wide
images if you have large data structures of your own.
Of course, all of these concerns vanish if you use a 32-bit flat-memory-model
compiler, such as DJGPP or Watcom C. We highly recommend flat model if you
can use it; the JPEG library is significantly faster in flat model.

View File

@@ -35,7 +35,7 @@
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
@@ -469,7 +469,7 @@ 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;

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
@@ -38,23 +40,15 @@
#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", "ctx=stm"
#else /* standard ANSI-compliant case */
#define READ_BINARY "rb" #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
/* /*

33
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.
@@ -43,7 +45,7 @@
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
@@ -56,24 +58,14 @@ typedef char U_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 */
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 */
JSAMPROW pixrow; /* compressor input buffer */
size_t buffer_width; /* width of I/O buffer */ size_t buffer_width; /* width of I/O buffer */
JSAMPLE *rescale; /* => maxval-remapping array, or NULL */ JSAMPLE *rescale; /* => maxval-remapping array, or NULL */
} ppm_source_struct; } ppm_source_struct;
@@ -358,7 +350,7 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
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;
@@ -373,7 +365,7 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
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,7 +378,7 @@ 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);
@@ -396,7 +388,6 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
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;

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.
@@ -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

@@ -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;
} }

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.
@@ -28,7 +30,7 @@
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
@@ -56,7 +58,7 @@ typedef struct _tga_source_struct {
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];
@@ -68,8 +70,7 @@ typedef struct _tga_source_struct {
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;
@@ -488,7 +489,7 @@ 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;

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

View File

@@ -1,485 +0,0 @@
;
; jcclrss2-64.asm - colorspace conversion (64-bit SSE2)
;
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; Copyright (C) 2009, D. R. Commander.
; 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_sse2 (JDIMENSION img_width,
; JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
; JDIMENSION output_row, int num_rows);
;
; r10 = JDIMENSION img_width
; r11 = JSAMPARRAY input_buf
; r12 = JSAMPIMAGE output_buf
; r13 = JDIMENSION output_row
; r14 = int num_rows
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 8
align 16
global EXTN(jsimd_rgb_ycc_convert_sse2)
EXTN(jsimd_rgb_ycc_convert_sse2):
push rbp
mov rax,rsp ; rax = original rbp
sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)]
collect_args
push rbx
mov rcx, r10
test rcx,rcx
jz near .return
push rcx
mov rsi, r12
mov rcx, r13
mov rdi, JSAMPARRAY [rsi+0*SIZEOF_JSAMPARRAY]
mov rbx, JSAMPARRAY [rsi+1*SIZEOF_JSAMPARRAY]
mov rdx, JSAMPARRAY [rsi+2*SIZEOF_JSAMPARRAY]
lea rdi, [rdi+rcx*SIZEOF_JSAMPROW]
lea rbx, [rbx+rcx*SIZEOF_JSAMPROW]
lea rdx, [rdx+rcx*SIZEOF_JSAMPROW]
pop rcx
mov rsi, r11
mov eax, r14d
test rax,rax
jle near .return
.rowloop:
push rdx
push rbx
push rdi
push rsi
push rcx ; col
mov rsi, JSAMPROW [rsi] ; inptr
mov rdi, JSAMPROW [rdi] ; outptr0
mov rbx, JSAMPROW [rbx] ; outptr1
mov rdx, JSAMPROW [rdx] ; outptr2
cmp rcx, byte SIZEOF_XMMWORD
jae near .columnloop
%if RGB_PIXELSIZE == 3 ; ---------------
.column_ld1:
push rax
push rdx
lea rcx,[rcx+rcx*2] ; imul ecx,RGB_PIXELSIZE
test cl, SIZEOF_BYTE
jz short .column_ld2
sub rcx, byte SIZEOF_BYTE
movzx rax, BYTE [rsi+rcx]
.column_ld2:
test cl, SIZEOF_WORD
jz short .column_ld4
sub rcx, byte SIZEOF_WORD
movzx rdx, WORD [rsi+rcx]
shl rax, WORD_BIT
or rax,rdx
.column_ld4:
movd xmmA,eax
pop rdx
pop rax
test cl, SIZEOF_DWORD
jz short .column_ld8
sub rcx, byte SIZEOF_DWORD
movd xmmF, XMM_DWORD [rsi+rcx]
pslldq xmmA, SIZEOF_DWORD
por xmmA,xmmF
.column_ld8:
test cl, SIZEOF_MMWORD
jz short .column_ld16
sub rcx, byte SIZEOF_MMWORD
movq xmmB, XMM_MMWORD [rsi+rcx]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmB
.column_ld16:
test cl, SIZEOF_XMMWORD
jz short .column_ld32
movdqa xmmF,xmmA
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
mov rcx, SIZEOF_XMMWORD
jmp short .rgb_ycc_cnv
.column_ld32:
test cl, 2*SIZEOF_XMMWORD
mov rcx, SIZEOF_XMMWORD
jz short .rgb_ycc_cnv
movdqa xmmB,xmmA
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
jmp short .rgb_ycc_cnv
.columnloop:
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqu xmmB, XMMWORD [rsi+2*SIZEOF_XMMWORD]
.rgb_ycc_cnv:
; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
movdqa xmmG,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
movdqa xmmD,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
movdqa xmmE,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
pxor xmmH,xmmH
movdqa xmmC,xmmA
punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmB,xmmE
punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F)
movdqa xmmF,xmmD
punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F)
punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F)
%else ; RGB_PIXELSIZE == 4 ; -----------
.column_ld1:
test cl, SIZEOF_XMMWORD/16
jz short .column_ld2
sub rcx, byte SIZEOF_XMMWORD/16
movd xmmA, XMM_DWORD [rsi+rcx*RGB_PIXELSIZE]
.column_ld2:
test cl, SIZEOF_XMMWORD/8
jz short .column_ld4
sub rcx, byte SIZEOF_XMMWORD/8
movq xmmE, XMM_MMWORD [rsi+rcx*RGB_PIXELSIZE]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmE
.column_ld4:
test cl, SIZEOF_XMMWORD/4
jz short .column_ld8
sub rcx, byte SIZEOF_XMMWORD/4
movdqa xmmE,xmmA
movdqu xmmA, XMMWORD [rsi+rcx*RGB_PIXELSIZE]
.column_ld8:
test cl, SIZEOF_XMMWORD/2
mov rcx, SIZEOF_XMMWORD
jz short .rgb_ycc_cnv
movdqa xmmF,xmmA
movdqa xmmH,xmmE
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
jmp short .rgb_ycc_cnv
.columnloop:
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+2*SIZEOF_XMMWORD]
movdqu xmmH, XMMWORD [rsi+3*SIZEOF_XMMWORD]
.rgb_ycc_cnv:
; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
movdqa xmmD,xmmA
punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
movdqa xmmC,xmmF
punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
movdqa xmmB,xmmA
punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
movdqa xmmG,xmmD
punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
movdqa xmmE,xmmA
punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
movdqa xmmH,xmmB
punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
pxor xmmF,xmmF
movdqa xmmC,xmmA
punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmD,xmmB
punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F)
movdqa xmmG,xmmE
punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E)
punpcklbw xmmF,xmmH
punpckhbw xmmH,xmmH
psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F)
psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F)
%endif ; RGB_PIXELSIZE ; ---------------
; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=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
movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=RE
movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=RO
movdqa XMMWORD [wk(2)], xmm4 ; wk(2)=BE
movdqa XMMWORD [wk(3)], xmm5 ; wk(3)=BO
movdqa xmm6,xmm1
punpcklwd xmm1,xmm3
punpckhwd xmm6,xmm3
movdqa xmm7,xmm1
movdqa xmm4,xmm6
pmaddwd xmm1,[rel PW_F0299_F0337] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
pmaddwd xmm7,[rel PW_MF016_MF033] ; xmm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
pmaddwd xmm4,[rel PW_MF016_MF033] ; xmm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
movdqa XMMWORD [wk(4)], xmm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
movdqa XMMWORD [wk(5)], xmm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
pxor xmm1,xmm1
pxor xmm6,xmm6
punpcklwd xmm1,xmm5 ; xmm1=BOL
punpckhwd xmm6,xmm5 ; xmm6=BOH
psrld xmm1,1 ; xmm1=BOL*FIX(0.500)
psrld xmm6,1 ; xmm6=BOH*FIX(0.500)
movdqa xmm5,[rel PD_ONEHALFM1_CJ] ; xmm5=[PD_ONEHALFM1_CJ]
paddd xmm7,xmm1
paddd xmm4,xmm6
paddd xmm7,xmm5
paddd xmm4,xmm5
psrld xmm7,SCALEBITS ; xmm7=CbOL
psrld xmm4,SCALEBITS ; xmm4=CbOH
packssdw xmm7,xmm4 ; xmm7=CbO
movdqa xmm1, XMMWORD [wk(2)] ; xmm1=BE
movdqa xmm6,xmm0
punpcklwd xmm0,xmm2
punpckhwd xmm6,xmm2
movdqa xmm5,xmm0
movdqa xmm4,xmm6
pmaddwd xmm0,[rel PW_F0299_F0337] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
pmaddwd xmm5,[rel PW_MF016_MF033] ; xmm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
pmaddwd xmm4,[rel PW_MF016_MF033] ; xmm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
movdqa XMMWORD [wk(7)], xmm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
pxor xmm0,xmm0
pxor xmm6,xmm6
punpcklwd xmm0,xmm1 ; xmm0=BEL
punpckhwd xmm6,xmm1 ; xmm6=BEH
psrld xmm0,1 ; xmm0=BEL*FIX(0.500)
psrld xmm6,1 ; xmm6=BEH*FIX(0.500)
movdqa xmm1,[rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ]
paddd xmm5,xmm0
paddd xmm4,xmm6
paddd xmm5,xmm1
paddd xmm4,xmm1
psrld xmm5,SCALEBITS ; xmm5=CbEL
psrld xmm4,SCALEBITS ; xmm4=CbEH
packssdw xmm5,xmm4 ; xmm5=CbE
psllw xmm7,BYTE_BIT
por xmm5,xmm7 ; xmm5=Cb
movdqa XMMWORD [rbx], xmm5 ; Save Cb
movdqa xmm0, XMMWORD [wk(3)] ; xmm0=BO
movdqa xmm6, XMMWORD [wk(2)] ; xmm6=BE
movdqa xmm1, XMMWORD [wk(1)] ; xmm1=RO
movdqa xmm4,xmm0
punpcklwd xmm0,xmm3
punpckhwd xmm4,xmm3
movdqa xmm7,xmm0
movdqa xmm5,xmm4
pmaddwd xmm0,[rel PW_F0114_F0250] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
pmaddwd xmm7,[rel PW_MF008_MF041] ; xmm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
pmaddwd xmm5,[rel PW_MF008_MF041] ; xmm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
movdqa xmm3,[rel PD_ONEHALF] ; xmm3=[PD_ONEHALF]
paddd xmm0, XMMWORD [wk(4)]
paddd xmm4, XMMWORD [wk(5)]
paddd xmm0,xmm3
paddd xmm4,xmm3
psrld xmm0,SCALEBITS ; xmm0=YOL
psrld xmm4,SCALEBITS ; xmm4=YOH
packssdw xmm0,xmm4 ; xmm0=YO
pxor xmm3,xmm3
pxor xmm4,xmm4
punpcklwd xmm3,xmm1 ; xmm3=ROL
punpckhwd xmm4,xmm1 ; xmm4=ROH
psrld xmm3,1 ; xmm3=ROL*FIX(0.500)
psrld xmm4,1 ; xmm4=ROH*FIX(0.500)
movdqa xmm1,[rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ]
paddd xmm7,xmm3
paddd xmm5,xmm4
paddd xmm7,xmm1
paddd xmm5,xmm1
psrld xmm7,SCALEBITS ; xmm7=CrOL
psrld xmm5,SCALEBITS ; xmm5=CrOH
packssdw xmm7,xmm5 ; xmm7=CrO
movdqa xmm3, XMMWORD [wk(0)] ; xmm3=RE
movdqa xmm4,xmm6
punpcklwd xmm6,xmm2
punpckhwd xmm4,xmm2
movdqa xmm1,xmm6
movdqa xmm5,xmm4
pmaddwd xmm6,[rel PW_F0114_F0250] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
pmaddwd xmm1,[rel PW_MF008_MF041] ; xmm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
pmaddwd xmm5,[rel PW_MF008_MF041] ; xmm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
movdqa xmm2,[rel PD_ONEHALF] ; xmm2=[PD_ONEHALF]
paddd xmm6, XMMWORD [wk(6)]
paddd xmm4, XMMWORD [wk(7)]
paddd xmm6,xmm2
paddd xmm4,xmm2
psrld xmm6,SCALEBITS ; xmm6=YEL
psrld xmm4,SCALEBITS ; xmm4=YEH
packssdw xmm6,xmm4 ; xmm6=YE
psllw xmm0,BYTE_BIT
por xmm6,xmm0 ; xmm6=Y
movdqa XMMWORD [rdi], xmm6 ; Save Y
pxor xmm2,xmm2
pxor xmm4,xmm4
punpcklwd xmm2,xmm3 ; xmm2=REL
punpckhwd xmm4,xmm3 ; xmm4=REH
psrld xmm2,1 ; xmm2=REL*FIX(0.500)
psrld xmm4,1 ; xmm4=REH*FIX(0.500)
movdqa xmm0,[rel PD_ONEHALFM1_CJ] ; xmm0=[PD_ONEHALFM1_CJ]
paddd xmm1,xmm2
paddd xmm5,xmm4
paddd xmm1,xmm0
paddd xmm5,xmm0
psrld xmm1,SCALEBITS ; xmm1=CrEL
psrld xmm5,SCALEBITS ; xmm5=CrEH
packssdw xmm1,xmm5 ; xmm1=CrE
psllw xmm7,BYTE_BIT
por xmm1,xmm7 ; xmm1=Cr
movdqa XMMWORD [rdx], xmm1 ; Save Cr
sub rcx, byte SIZEOF_XMMWORD
add rsi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr
add rdi, byte SIZEOF_XMMWORD ; outptr0
add rbx, byte SIZEOF_XMMWORD ; outptr1
add rdx, byte SIZEOF_XMMWORD ; outptr2
cmp rcx, byte SIZEOF_XMMWORD
jae near .columnloop
test rcx,rcx
jnz near .column_ld1
pop rcx ; col
pop rsi
pop rdi
pop rbx
pop rdx
add rsi, byte SIZEOF_JSAMPROW ; input_buf
add rdi, byte SIZEOF_JSAMPROW
add rbx, byte SIZEOF_JSAMPROW
add rdx, byte SIZEOF_JSAMPROW
dec rax ; num_rows
jg near .rowloop
.return:
pop rbx
uncollect_args
mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16

View File

@@ -1,503 +0,0 @@
;
; jcclrss2.asm - colorspace conversion (SSE2)
;
; 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_sse2 (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_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 8
%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr
align 16
global EXTN(jsimd_rgb_ycc_convert_sse2)
EXTN(jsimd_rgb_ycc_convert_sse2):
push ebp
mov eax,esp ; eax = original ebp
sub esp, byte 4
and esp, byte (-SIZEOF_XMMWORD) ; align to 128 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)]
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_XMMWORD
jae near .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
movzx eax, BYTE [esi+ecx]
.column_ld2:
test cl, SIZEOF_WORD
jz short .column_ld4
sub ecx, byte SIZEOF_WORD
movzx edx, WORD [esi+ecx]
shl eax, WORD_BIT
or eax,edx
.column_ld4:
movd xmmA,eax
pop edx
pop eax
test cl, SIZEOF_DWORD
jz short .column_ld8
sub ecx, byte SIZEOF_DWORD
movd xmmF, XMM_DWORD [esi+ecx]
pslldq xmmA, SIZEOF_DWORD
por xmmA,xmmF
.column_ld8:
test cl, SIZEOF_MMWORD
jz short .column_ld16
sub ecx, byte SIZEOF_MMWORD
movq xmmB, XMM_MMWORD [esi+ecx]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmB
.column_ld16:
test cl, SIZEOF_XMMWORD
jz short .column_ld32
movdqa xmmF,xmmA
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
mov ecx, SIZEOF_XMMWORD
jmp short .rgb_ycc_cnv
.column_ld32:
test cl, 2*SIZEOF_XMMWORD
mov ecx, SIZEOF_XMMWORD
jz short .rgb_ycc_cnv
movdqa xmmB,xmmA
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD]
jmp short .rgb_ycc_cnv
alignx 16,7
.columnloop:
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD]
movdqu xmmB, XMMWORD [esi+2*SIZEOF_XMMWORD]
.rgb_ycc_cnv:
; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
movdqa xmmG,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
movdqa xmmD,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
movdqa xmmE,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
pxor xmmH,xmmH
movdqa xmmC,xmmA
punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmB,xmmE
punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F)
movdqa xmmF,xmmD
punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F)
punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F)
%else ; RGB_PIXELSIZE == 4 ; -----------
.column_ld1:
test cl, SIZEOF_XMMWORD/16
jz short .column_ld2
sub ecx, byte SIZEOF_XMMWORD/16
movd xmmA, XMM_DWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld2:
test cl, SIZEOF_XMMWORD/8
jz short .column_ld4
sub ecx, byte SIZEOF_XMMWORD/8
movq xmmE, XMM_MMWORD [esi+ecx*RGB_PIXELSIZE]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmE
.column_ld4:
test cl, SIZEOF_XMMWORD/4
jz short .column_ld8
sub ecx, byte SIZEOF_XMMWORD/4
movdqa xmmE,xmmA
movdqu xmmA, XMMWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld8:
test cl, SIZEOF_XMMWORD/2
mov ecx, SIZEOF_XMMWORD
jz short .rgb_ycc_cnv
movdqa xmmF,xmmA
movdqa xmmH,xmmE
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD]
jmp short .rgb_ycc_cnv
alignx 16,7
.columnloop:
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [esi+2*SIZEOF_XMMWORD]
movdqu xmmH, XMMWORD [esi+3*SIZEOF_XMMWORD]
.rgb_ycc_cnv:
; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
movdqa xmmD,xmmA
punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
movdqa xmmC,xmmF
punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
movdqa xmmB,xmmA
punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
movdqa xmmG,xmmD
punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
movdqa xmmE,xmmA
punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
movdqa xmmH,xmmB
punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
pxor xmmF,xmmF
movdqa xmmC,xmmA
punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmD,xmmB
punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F)
movdqa xmmG,xmmE
punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E)
punpcklbw xmmF,xmmH
punpckhbw xmmH,xmmH
psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F)
psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F)
%endif ; RGB_PIXELSIZE ; ---------------
; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=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
movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=RE
movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=RO
movdqa XMMWORD [wk(2)], xmm4 ; wk(2)=BE
movdqa XMMWORD [wk(3)], xmm5 ; wk(3)=BO
movdqa xmm6,xmm1
punpcklwd xmm1,xmm3
punpckhwd xmm6,xmm3
movdqa xmm7,xmm1
movdqa xmm4,xmm6
pmaddwd xmm1,[GOTOFF(eax,PW_F0299_F0337)] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
pmaddwd xmm7,[GOTOFF(eax,PW_MF016_MF033)] ; xmm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
pmaddwd xmm4,[GOTOFF(eax,PW_MF016_MF033)] ; xmm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
movdqa XMMWORD [wk(4)], xmm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
movdqa XMMWORD [wk(5)], xmm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
pxor xmm1,xmm1
pxor xmm6,xmm6
punpcklwd xmm1,xmm5 ; xmm1=BOL
punpckhwd xmm6,xmm5 ; xmm6=BOH
psrld xmm1,1 ; xmm1=BOL*FIX(0.500)
psrld xmm6,1 ; xmm6=BOH*FIX(0.500)
movdqa xmm5,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm5=[PD_ONEHALFM1_CJ]
paddd xmm7,xmm1
paddd xmm4,xmm6
paddd xmm7,xmm5
paddd xmm4,xmm5
psrld xmm7,SCALEBITS ; xmm7=CbOL
psrld xmm4,SCALEBITS ; xmm4=CbOH
packssdw xmm7,xmm4 ; xmm7=CbO
movdqa xmm1, XMMWORD [wk(2)] ; xmm1=BE
movdqa xmm6,xmm0
punpcklwd xmm0,xmm2
punpckhwd xmm6,xmm2
movdqa xmm5,xmm0
movdqa xmm4,xmm6
pmaddwd xmm0,[GOTOFF(eax,PW_F0299_F0337)] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
pmaddwd xmm5,[GOTOFF(eax,PW_MF016_MF033)] ; xmm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
pmaddwd xmm4,[GOTOFF(eax,PW_MF016_MF033)] ; xmm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
movdqa XMMWORD [wk(7)], xmm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
pxor xmm0,xmm0
pxor xmm6,xmm6
punpcklwd xmm0,xmm1 ; xmm0=BEL
punpckhwd xmm6,xmm1 ; xmm6=BEH
psrld xmm0,1 ; xmm0=BEL*FIX(0.500)
psrld xmm6,1 ; xmm6=BEH*FIX(0.500)
movdqa xmm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm1=[PD_ONEHALFM1_CJ]
paddd xmm5,xmm0
paddd xmm4,xmm6
paddd xmm5,xmm1
paddd xmm4,xmm1
psrld xmm5,SCALEBITS ; xmm5=CbEL
psrld xmm4,SCALEBITS ; xmm4=CbEH
packssdw xmm5,xmm4 ; xmm5=CbE
psllw xmm7,BYTE_BIT
por xmm5,xmm7 ; xmm5=Cb
movdqa XMMWORD [ebx], xmm5 ; Save Cb
movdqa xmm0, XMMWORD [wk(3)] ; xmm0=BO
movdqa xmm6, XMMWORD [wk(2)] ; xmm6=BE
movdqa xmm1, XMMWORD [wk(1)] ; xmm1=RO
movdqa xmm4,xmm0
punpcklwd xmm0,xmm3
punpckhwd xmm4,xmm3
movdqa xmm7,xmm0
movdqa xmm5,xmm4
pmaddwd xmm0,[GOTOFF(eax,PW_F0114_F0250)] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
pmaddwd xmm7,[GOTOFF(eax,PW_MF008_MF041)] ; xmm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
pmaddwd xmm5,[GOTOFF(eax,PW_MF008_MF041)] ; xmm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
movdqa xmm3,[GOTOFF(eax,PD_ONEHALF)] ; xmm3=[PD_ONEHALF]
paddd xmm0, XMMWORD [wk(4)]
paddd xmm4, XMMWORD [wk(5)]
paddd xmm0,xmm3
paddd xmm4,xmm3
psrld xmm0,SCALEBITS ; xmm0=YOL
psrld xmm4,SCALEBITS ; xmm4=YOH
packssdw xmm0,xmm4 ; xmm0=YO
pxor xmm3,xmm3
pxor xmm4,xmm4
punpcklwd xmm3,xmm1 ; xmm3=ROL
punpckhwd xmm4,xmm1 ; xmm4=ROH
psrld xmm3,1 ; xmm3=ROL*FIX(0.500)
psrld xmm4,1 ; xmm4=ROH*FIX(0.500)
movdqa xmm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm1=[PD_ONEHALFM1_CJ]
paddd xmm7,xmm3
paddd xmm5,xmm4
paddd xmm7,xmm1
paddd xmm5,xmm1
psrld xmm7,SCALEBITS ; xmm7=CrOL
psrld xmm5,SCALEBITS ; xmm5=CrOH
packssdw xmm7,xmm5 ; xmm7=CrO
movdqa xmm3, XMMWORD [wk(0)] ; xmm3=RE
movdqa xmm4,xmm6
punpcklwd xmm6,xmm2
punpckhwd xmm4,xmm2
movdqa xmm1,xmm6
movdqa xmm5,xmm4
pmaddwd xmm6,[GOTOFF(eax,PW_F0114_F0250)] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
pmaddwd xmm1,[GOTOFF(eax,PW_MF008_MF041)] ; xmm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
pmaddwd xmm5,[GOTOFF(eax,PW_MF008_MF041)] ; xmm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
movdqa xmm2,[GOTOFF(eax,PD_ONEHALF)] ; xmm2=[PD_ONEHALF]
paddd xmm6, XMMWORD [wk(6)]
paddd xmm4, XMMWORD [wk(7)]
paddd xmm6,xmm2
paddd xmm4,xmm2
psrld xmm6,SCALEBITS ; xmm6=YEL
psrld xmm4,SCALEBITS ; xmm4=YEH
packssdw xmm6,xmm4 ; xmm6=YE
psllw xmm0,BYTE_BIT
por xmm6,xmm0 ; xmm6=Y
movdqa XMMWORD [edi], xmm6 ; Save Y
pxor xmm2,xmm2
pxor xmm4,xmm4
punpcklwd xmm2,xmm3 ; xmm2=REL
punpckhwd xmm4,xmm3 ; xmm4=REH
psrld xmm2,1 ; xmm2=REL*FIX(0.500)
psrld xmm4,1 ; xmm4=REH*FIX(0.500)
movdqa xmm0,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm0=[PD_ONEHALFM1_CJ]
paddd xmm1,xmm2
paddd xmm5,xmm4
paddd xmm1,xmm0
paddd xmm5,xmm0
psrld xmm1,SCALEBITS ; xmm1=CrEL
psrld xmm5,SCALEBITS ; xmm5=CrEH
packssdw xmm1,xmm5 ; xmm1=CrE
psllw xmm7,BYTE_BIT
por xmm1,xmm7 ; xmm1=Cr
movdqa XMMWORD [edx], xmm1 ; Save Cr
sub ecx, byte SIZEOF_XMMWORD
add esi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr
add edi, byte SIZEOF_XMMWORD ; outptr0
add ebx, byte SIZEOF_XMMWORD ; outptr1
add edx, byte SIZEOF_XMMWORD ; outptr2
cmp ecx, byte SIZEOF_XMMWORD
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
.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

477
simd/jccolext-mmx.asm Normal file
View File

@@ -0,0 +1,477 @@
;
; jccolext.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

485
simd/jccolext-sse2-64.asm Normal file
View File

@@ -0,0 +1,485 @@
;
; jccolext.asm - colorspace conversion (64-bit SSE2)
;
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; Copyright (C) 2009, D. R. Commander.
; 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_sse2 (JDIMENSION img_width,
; JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
; JDIMENSION output_row, int num_rows);
;
; r10 = JDIMENSION img_width
; r11 = JSAMPARRAY input_buf
; r12 = JSAMPIMAGE output_buf
; r13 = JDIMENSION output_row
; r14 = int num_rows
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 8
align 16
global EXTN(jsimd_rgb_ycc_convert_sse2)
EXTN(jsimd_rgb_ycc_convert_sse2):
push rbp
mov rax,rsp ; rax = original rbp
sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)]
collect_args
push rbx
mov rcx, r10
test rcx,rcx
jz near .return
push rcx
mov rsi, r12
mov rcx, r13
mov rdi, JSAMPARRAY [rsi+0*SIZEOF_JSAMPARRAY]
mov rbx, JSAMPARRAY [rsi+1*SIZEOF_JSAMPARRAY]
mov rdx, JSAMPARRAY [rsi+2*SIZEOF_JSAMPARRAY]
lea rdi, [rdi+rcx*SIZEOF_JSAMPROW]
lea rbx, [rbx+rcx*SIZEOF_JSAMPROW]
lea rdx, [rdx+rcx*SIZEOF_JSAMPROW]
pop rcx
mov rsi, r11
mov eax, r14d
test rax,rax
jle near .return
.rowloop:
push rdx
push rbx
push rdi
push rsi
push rcx ; col
mov rsi, JSAMPROW [rsi] ; inptr
mov rdi, JSAMPROW [rdi] ; outptr0
mov rbx, JSAMPROW [rbx] ; outptr1
mov rdx, JSAMPROW [rdx] ; outptr2
cmp rcx, byte SIZEOF_XMMWORD
jae near .columnloop
%if RGB_PIXELSIZE == 3 ; ---------------
.column_ld1:
push rax
push rdx
lea rcx,[rcx+rcx*2] ; imul ecx,RGB_PIXELSIZE
test cl, SIZEOF_BYTE
jz short .column_ld2
sub rcx, byte SIZEOF_BYTE
movzx rax, BYTE [rsi+rcx]
.column_ld2:
test cl, SIZEOF_WORD
jz short .column_ld4
sub rcx, byte SIZEOF_WORD
movzx rdx, WORD [rsi+rcx]
shl rax, WORD_BIT
or rax,rdx
.column_ld4:
movd xmmA,eax
pop rdx
pop rax
test cl, SIZEOF_DWORD
jz short .column_ld8
sub rcx, byte SIZEOF_DWORD
movd xmmF, XMM_DWORD [rsi+rcx]
pslldq xmmA, SIZEOF_DWORD
por xmmA,xmmF
.column_ld8:
test cl, SIZEOF_MMWORD
jz short .column_ld16
sub rcx, byte SIZEOF_MMWORD
movq xmmB, XMM_MMWORD [rsi+rcx]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmB
.column_ld16:
test cl, SIZEOF_XMMWORD
jz short .column_ld32
movdqa xmmF,xmmA
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
mov rcx, SIZEOF_XMMWORD
jmp short .rgb_ycc_cnv
.column_ld32:
test cl, 2*SIZEOF_XMMWORD
mov rcx, SIZEOF_XMMWORD
jz short .rgb_ycc_cnv
movdqa xmmB,xmmA
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
jmp short .rgb_ycc_cnv
.columnloop:
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqu xmmB, XMMWORD [rsi+2*SIZEOF_XMMWORD]
.rgb_ycc_cnv:
; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
movdqa xmmG,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
movdqa xmmD,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
movdqa xmmE,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
pxor xmmH,xmmH
movdqa xmmC,xmmA
punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmB,xmmE
punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F)
movdqa xmmF,xmmD
punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F)
punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F)
%else ; RGB_PIXELSIZE == 4 ; -----------
.column_ld1:
test cl, SIZEOF_XMMWORD/16
jz short .column_ld2
sub rcx, byte SIZEOF_XMMWORD/16
movd xmmA, XMM_DWORD [rsi+rcx*RGB_PIXELSIZE]
.column_ld2:
test cl, SIZEOF_XMMWORD/8
jz short .column_ld4
sub rcx, byte SIZEOF_XMMWORD/8
movq xmmE, XMM_MMWORD [rsi+rcx*RGB_PIXELSIZE]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmE
.column_ld4:
test cl, SIZEOF_XMMWORD/4
jz short .column_ld8
sub rcx, byte SIZEOF_XMMWORD/4
movdqa xmmE,xmmA
movdqu xmmA, XMMWORD [rsi+rcx*RGB_PIXELSIZE]
.column_ld8:
test cl, SIZEOF_XMMWORD/2
mov rcx, SIZEOF_XMMWORD
jz short .rgb_ycc_cnv
movdqa xmmF,xmmA
movdqa xmmH,xmmE
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
jmp short .rgb_ycc_cnv
.columnloop:
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+2*SIZEOF_XMMWORD]
movdqu xmmH, XMMWORD [rsi+3*SIZEOF_XMMWORD]
.rgb_ycc_cnv:
; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
movdqa xmmD,xmmA
punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
movdqa xmmC,xmmF
punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
movdqa xmmB,xmmA
punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
movdqa xmmG,xmmD
punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
movdqa xmmE,xmmA
punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
movdqa xmmH,xmmB
punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
pxor xmmF,xmmF
movdqa xmmC,xmmA
punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmD,xmmB
punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F)
movdqa xmmG,xmmE
punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E)
punpcklbw xmmF,xmmH
punpckhbw xmmH,xmmH
psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F)
psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F)
%endif ; RGB_PIXELSIZE ; ---------------
; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=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
movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=RE
movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=RO
movdqa XMMWORD [wk(2)], xmm4 ; wk(2)=BE
movdqa XMMWORD [wk(3)], xmm5 ; wk(3)=BO
movdqa xmm6,xmm1
punpcklwd xmm1,xmm3
punpckhwd xmm6,xmm3
movdqa xmm7,xmm1
movdqa xmm4,xmm6
pmaddwd xmm1,[rel PW_F0299_F0337] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
pmaddwd xmm7,[rel PW_MF016_MF033] ; xmm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
pmaddwd xmm4,[rel PW_MF016_MF033] ; xmm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
movdqa XMMWORD [wk(4)], xmm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
movdqa XMMWORD [wk(5)], xmm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
pxor xmm1,xmm1
pxor xmm6,xmm6
punpcklwd xmm1,xmm5 ; xmm1=BOL
punpckhwd xmm6,xmm5 ; xmm6=BOH
psrld xmm1,1 ; xmm1=BOL*FIX(0.500)
psrld xmm6,1 ; xmm6=BOH*FIX(0.500)
movdqa xmm5,[rel PD_ONEHALFM1_CJ] ; xmm5=[PD_ONEHALFM1_CJ]
paddd xmm7,xmm1
paddd xmm4,xmm6
paddd xmm7,xmm5
paddd xmm4,xmm5
psrld xmm7,SCALEBITS ; xmm7=CbOL
psrld xmm4,SCALEBITS ; xmm4=CbOH
packssdw xmm7,xmm4 ; xmm7=CbO
movdqa xmm1, XMMWORD [wk(2)] ; xmm1=BE
movdqa xmm6,xmm0
punpcklwd xmm0,xmm2
punpckhwd xmm6,xmm2
movdqa xmm5,xmm0
movdqa xmm4,xmm6
pmaddwd xmm0,[rel PW_F0299_F0337] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
pmaddwd xmm5,[rel PW_MF016_MF033] ; xmm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
pmaddwd xmm4,[rel PW_MF016_MF033] ; xmm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
movdqa XMMWORD [wk(7)], xmm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
pxor xmm0,xmm0
pxor xmm6,xmm6
punpcklwd xmm0,xmm1 ; xmm0=BEL
punpckhwd xmm6,xmm1 ; xmm6=BEH
psrld xmm0,1 ; xmm0=BEL*FIX(0.500)
psrld xmm6,1 ; xmm6=BEH*FIX(0.500)
movdqa xmm1,[rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ]
paddd xmm5,xmm0
paddd xmm4,xmm6
paddd xmm5,xmm1
paddd xmm4,xmm1
psrld xmm5,SCALEBITS ; xmm5=CbEL
psrld xmm4,SCALEBITS ; xmm4=CbEH
packssdw xmm5,xmm4 ; xmm5=CbE
psllw xmm7,BYTE_BIT
por xmm5,xmm7 ; xmm5=Cb
movdqa XMMWORD [rbx], xmm5 ; Save Cb
movdqa xmm0, XMMWORD [wk(3)] ; xmm0=BO
movdqa xmm6, XMMWORD [wk(2)] ; xmm6=BE
movdqa xmm1, XMMWORD [wk(1)] ; xmm1=RO
movdqa xmm4,xmm0
punpcklwd xmm0,xmm3
punpckhwd xmm4,xmm3
movdqa xmm7,xmm0
movdqa xmm5,xmm4
pmaddwd xmm0,[rel PW_F0114_F0250] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
pmaddwd xmm7,[rel PW_MF008_MF041] ; xmm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
pmaddwd xmm5,[rel PW_MF008_MF041] ; xmm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
movdqa xmm3,[rel PD_ONEHALF] ; xmm3=[PD_ONEHALF]
paddd xmm0, XMMWORD [wk(4)]
paddd xmm4, XMMWORD [wk(5)]
paddd xmm0,xmm3
paddd xmm4,xmm3
psrld xmm0,SCALEBITS ; xmm0=YOL
psrld xmm4,SCALEBITS ; xmm4=YOH
packssdw xmm0,xmm4 ; xmm0=YO
pxor xmm3,xmm3
pxor xmm4,xmm4
punpcklwd xmm3,xmm1 ; xmm3=ROL
punpckhwd xmm4,xmm1 ; xmm4=ROH
psrld xmm3,1 ; xmm3=ROL*FIX(0.500)
psrld xmm4,1 ; xmm4=ROH*FIX(0.500)
movdqa xmm1,[rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ]
paddd xmm7,xmm3
paddd xmm5,xmm4
paddd xmm7,xmm1
paddd xmm5,xmm1
psrld xmm7,SCALEBITS ; xmm7=CrOL
psrld xmm5,SCALEBITS ; xmm5=CrOH
packssdw xmm7,xmm5 ; xmm7=CrO
movdqa xmm3, XMMWORD [wk(0)] ; xmm3=RE
movdqa xmm4,xmm6
punpcklwd xmm6,xmm2
punpckhwd xmm4,xmm2
movdqa xmm1,xmm6
movdqa xmm5,xmm4
pmaddwd xmm6,[rel PW_F0114_F0250] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
pmaddwd xmm1,[rel PW_MF008_MF041] ; xmm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
pmaddwd xmm5,[rel PW_MF008_MF041] ; xmm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
movdqa xmm2,[rel PD_ONEHALF] ; xmm2=[PD_ONEHALF]
paddd xmm6, XMMWORD [wk(6)]
paddd xmm4, XMMWORD [wk(7)]
paddd xmm6,xmm2
paddd xmm4,xmm2
psrld xmm6,SCALEBITS ; xmm6=YEL
psrld xmm4,SCALEBITS ; xmm4=YEH
packssdw xmm6,xmm4 ; xmm6=YE
psllw xmm0,BYTE_BIT
por xmm6,xmm0 ; xmm6=Y
movdqa XMMWORD [rdi], xmm6 ; Save Y
pxor xmm2,xmm2
pxor xmm4,xmm4
punpcklwd xmm2,xmm3 ; xmm2=REL
punpckhwd xmm4,xmm3 ; xmm4=REH
psrld xmm2,1 ; xmm2=REL*FIX(0.500)
psrld xmm4,1 ; xmm4=REH*FIX(0.500)
movdqa xmm0,[rel PD_ONEHALFM1_CJ] ; xmm0=[PD_ONEHALFM1_CJ]
paddd xmm1,xmm2
paddd xmm5,xmm4
paddd xmm1,xmm0
paddd xmm5,xmm0
psrld xmm1,SCALEBITS ; xmm1=CrEL
psrld xmm5,SCALEBITS ; xmm5=CrEH
packssdw xmm1,xmm5 ; xmm1=CrE
psllw xmm7,BYTE_BIT
por xmm1,xmm7 ; xmm1=Cr
movdqa XMMWORD [rdx], xmm1 ; Save Cr
sub rcx, byte SIZEOF_XMMWORD
add rsi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr
add rdi, byte SIZEOF_XMMWORD ; outptr0
add rbx, byte SIZEOF_XMMWORD ; outptr1
add rdx, byte SIZEOF_XMMWORD ; outptr2
cmp rcx, byte SIZEOF_XMMWORD
jae near .columnloop
test rcx,rcx
jnz near .column_ld1
pop rcx ; col
pop rsi
pop rdi
pop rbx
pop rdx
add rsi, byte SIZEOF_JSAMPROW ; input_buf
add rdi, byte SIZEOF_JSAMPROW
add rbx, byte SIZEOF_JSAMPROW
add rdx, byte SIZEOF_JSAMPROW
dec rax ; num_rows
jg near .rowloop
.return:
pop rbx
uncollect_args
mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16

503
simd/jccolext-sse2.asm Normal file
View File

@@ -0,0 +1,503 @@
;
; jccolext.asm - colorspace conversion (SSE2)
;
; 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_sse2 (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_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 8
%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr
align 16
global EXTN(jsimd_rgb_ycc_convert_sse2)
EXTN(jsimd_rgb_ycc_convert_sse2):
push ebp
mov eax,esp ; eax = original ebp
sub esp, byte 4
and esp, byte (-SIZEOF_XMMWORD) ; align to 128 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)]
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_XMMWORD
jae near .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
movzx eax, BYTE [esi+ecx]
.column_ld2:
test cl, SIZEOF_WORD
jz short .column_ld4
sub ecx, byte SIZEOF_WORD
movzx edx, WORD [esi+ecx]
shl eax, WORD_BIT
or eax,edx
.column_ld4:
movd xmmA,eax
pop edx
pop eax
test cl, SIZEOF_DWORD
jz short .column_ld8
sub ecx, byte SIZEOF_DWORD
movd xmmF, XMM_DWORD [esi+ecx]
pslldq xmmA, SIZEOF_DWORD
por xmmA,xmmF
.column_ld8:
test cl, SIZEOF_MMWORD
jz short .column_ld16
sub ecx, byte SIZEOF_MMWORD
movq xmmB, XMM_MMWORD [esi+ecx]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmB
.column_ld16:
test cl, SIZEOF_XMMWORD
jz short .column_ld32
movdqa xmmF,xmmA
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
mov ecx, SIZEOF_XMMWORD
jmp short .rgb_ycc_cnv
.column_ld32:
test cl, 2*SIZEOF_XMMWORD
mov ecx, SIZEOF_XMMWORD
jz short .rgb_ycc_cnv
movdqa xmmB,xmmA
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD]
jmp short .rgb_ycc_cnv
alignx 16,7
.columnloop:
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD]
movdqu xmmB, XMMWORD [esi+2*SIZEOF_XMMWORD]
.rgb_ycc_cnv:
; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
movdqa xmmG,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
movdqa xmmD,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
movdqa xmmE,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
pxor xmmH,xmmH
movdqa xmmC,xmmA
punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmB,xmmE
punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F)
movdqa xmmF,xmmD
punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F)
punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F)
%else ; RGB_PIXELSIZE == 4 ; -----------
.column_ld1:
test cl, SIZEOF_XMMWORD/16
jz short .column_ld2
sub ecx, byte SIZEOF_XMMWORD/16
movd xmmA, XMM_DWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld2:
test cl, SIZEOF_XMMWORD/8
jz short .column_ld4
sub ecx, byte SIZEOF_XMMWORD/8
movq xmmE, XMM_MMWORD [esi+ecx*RGB_PIXELSIZE]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmE
.column_ld4:
test cl, SIZEOF_XMMWORD/4
jz short .column_ld8
sub ecx, byte SIZEOF_XMMWORD/4
movdqa xmmE,xmmA
movdqu xmmA, XMMWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld8:
test cl, SIZEOF_XMMWORD/2
mov ecx, SIZEOF_XMMWORD
jz short .rgb_ycc_cnv
movdqa xmmF,xmmA
movdqa xmmH,xmmE
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD]
jmp short .rgb_ycc_cnv
alignx 16,7
.columnloop:
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [esi+2*SIZEOF_XMMWORD]
movdqu xmmH, XMMWORD [esi+3*SIZEOF_XMMWORD]
.rgb_ycc_cnv:
; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
movdqa xmmD,xmmA
punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
movdqa xmmC,xmmF
punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
movdqa xmmB,xmmA
punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
movdqa xmmG,xmmD
punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
movdqa xmmE,xmmA
punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
movdqa xmmH,xmmB
punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
pxor xmmF,xmmF
movdqa xmmC,xmmA
punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmD,xmmB
punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F)
movdqa xmmG,xmmE
punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E)
punpcklbw xmmF,xmmH
punpckhbw xmmH,xmmH
psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F)
psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F)
%endif ; RGB_PIXELSIZE ; ---------------
; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=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
movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=RE
movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=RO
movdqa XMMWORD [wk(2)], xmm4 ; wk(2)=BE
movdqa XMMWORD [wk(3)], xmm5 ; wk(3)=BO
movdqa xmm6,xmm1
punpcklwd xmm1,xmm3
punpckhwd xmm6,xmm3
movdqa xmm7,xmm1
movdqa xmm4,xmm6
pmaddwd xmm1,[GOTOFF(eax,PW_F0299_F0337)] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
pmaddwd xmm7,[GOTOFF(eax,PW_MF016_MF033)] ; xmm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
pmaddwd xmm4,[GOTOFF(eax,PW_MF016_MF033)] ; xmm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
movdqa XMMWORD [wk(4)], xmm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
movdqa XMMWORD [wk(5)], xmm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
pxor xmm1,xmm1
pxor xmm6,xmm6
punpcklwd xmm1,xmm5 ; xmm1=BOL
punpckhwd xmm6,xmm5 ; xmm6=BOH
psrld xmm1,1 ; xmm1=BOL*FIX(0.500)
psrld xmm6,1 ; xmm6=BOH*FIX(0.500)
movdqa xmm5,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm5=[PD_ONEHALFM1_CJ]
paddd xmm7,xmm1
paddd xmm4,xmm6
paddd xmm7,xmm5
paddd xmm4,xmm5
psrld xmm7,SCALEBITS ; xmm7=CbOL
psrld xmm4,SCALEBITS ; xmm4=CbOH
packssdw xmm7,xmm4 ; xmm7=CbO
movdqa xmm1, XMMWORD [wk(2)] ; xmm1=BE
movdqa xmm6,xmm0
punpcklwd xmm0,xmm2
punpckhwd xmm6,xmm2
movdqa xmm5,xmm0
movdqa xmm4,xmm6
pmaddwd xmm0,[GOTOFF(eax,PW_F0299_F0337)] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
pmaddwd xmm5,[GOTOFF(eax,PW_MF016_MF033)] ; xmm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
pmaddwd xmm4,[GOTOFF(eax,PW_MF016_MF033)] ; xmm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
movdqa XMMWORD [wk(7)], xmm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
pxor xmm0,xmm0
pxor xmm6,xmm6
punpcklwd xmm0,xmm1 ; xmm0=BEL
punpckhwd xmm6,xmm1 ; xmm6=BEH
psrld xmm0,1 ; xmm0=BEL*FIX(0.500)
psrld xmm6,1 ; xmm6=BEH*FIX(0.500)
movdqa xmm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm1=[PD_ONEHALFM1_CJ]
paddd xmm5,xmm0
paddd xmm4,xmm6
paddd xmm5,xmm1
paddd xmm4,xmm1
psrld xmm5,SCALEBITS ; xmm5=CbEL
psrld xmm4,SCALEBITS ; xmm4=CbEH
packssdw xmm5,xmm4 ; xmm5=CbE
psllw xmm7,BYTE_BIT
por xmm5,xmm7 ; xmm5=Cb
movdqa XMMWORD [ebx], xmm5 ; Save Cb
movdqa xmm0, XMMWORD [wk(3)] ; xmm0=BO
movdqa xmm6, XMMWORD [wk(2)] ; xmm6=BE
movdqa xmm1, XMMWORD [wk(1)] ; xmm1=RO
movdqa xmm4,xmm0
punpcklwd xmm0,xmm3
punpckhwd xmm4,xmm3
movdqa xmm7,xmm0
movdqa xmm5,xmm4
pmaddwd xmm0,[GOTOFF(eax,PW_F0114_F0250)] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
pmaddwd xmm7,[GOTOFF(eax,PW_MF008_MF041)] ; xmm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
pmaddwd xmm5,[GOTOFF(eax,PW_MF008_MF041)] ; xmm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
movdqa xmm3,[GOTOFF(eax,PD_ONEHALF)] ; xmm3=[PD_ONEHALF]
paddd xmm0, XMMWORD [wk(4)]
paddd xmm4, XMMWORD [wk(5)]
paddd xmm0,xmm3
paddd xmm4,xmm3
psrld xmm0,SCALEBITS ; xmm0=YOL
psrld xmm4,SCALEBITS ; xmm4=YOH
packssdw xmm0,xmm4 ; xmm0=YO
pxor xmm3,xmm3
pxor xmm4,xmm4
punpcklwd xmm3,xmm1 ; xmm3=ROL
punpckhwd xmm4,xmm1 ; xmm4=ROH
psrld xmm3,1 ; xmm3=ROL*FIX(0.500)
psrld xmm4,1 ; xmm4=ROH*FIX(0.500)
movdqa xmm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm1=[PD_ONEHALFM1_CJ]
paddd xmm7,xmm3
paddd xmm5,xmm4
paddd xmm7,xmm1
paddd xmm5,xmm1
psrld xmm7,SCALEBITS ; xmm7=CrOL
psrld xmm5,SCALEBITS ; xmm5=CrOH
packssdw xmm7,xmm5 ; xmm7=CrO
movdqa xmm3, XMMWORD [wk(0)] ; xmm3=RE
movdqa xmm4,xmm6
punpcklwd xmm6,xmm2
punpckhwd xmm4,xmm2
movdqa xmm1,xmm6
movdqa xmm5,xmm4
pmaddwd xmm6,[GOTOFF(eax,PW_F0114_F0250)] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
pmaddwd xmm1,[GOTOFF(eax,PW_MF008_MF041)] ; xmm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
pmaddwd xmm5,[GOTOFF(eax,PW_MF008_MF041)] ; xmm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
movdqa xmm2,[GOTOFF(eax,PD_ONEHALF)] ; xmm2=[PD_ONEHALF]
paddd xmm6, XMMWORD [wk(6)]
paddd xmm4, XMMWORD [wk(7)]
paddd xmm6,xmm2
paddd xmm4,xmm2
psrld xmm6,SCALEBITS ; xmm6=YEL
psrld xmm4,SCALEBITS ; xmm4=YEH
packssdw xmm6,xmm4 ; xmm6=YE
psllw xmm0,BYTE_BIT
por xmm6,xmm0 ; xmm6=Y
movdqa XMMWORD [edi], xmm6 ; Save Y
pxor xmm2,xmm2
pxor xmm4,xmm4
punpcklwd xmm2,xmm3 ; xmm2=REL
punpckhwd xmm4,xmm3 ; xmm4=REH
psrld xmm2,1 ; xmm2=REL*FIX(0.500)
psrld xmm4,1 ; xmm4=REH*FIX(0.500)
movdqa xmm0,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm0=[PD_ONEHALFM1_CJ]
paddd xmm1,xmm2
paddd xmm5,xmm4
paddd xmm1,xmm0
paddd xmm5,xmm0
psrld xmm1,SCALEBITS ; xmm1=CrEL
psrld xmm5,SCALEBITS ; xmm5=CrEH
packssdw xmm1,xmm5 ; xmm1=CrE
psllw xmm7,BYTE_BIT
por xmm1,xmm7 ; xmm1=Cr
movdqa XMMWORD [edx], xmm1 ; Save Cr
sub ecx, byte SIZEOF_XMMWORD
add esi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr
add edi, byte SIZEOF_XMMWORD ; outptr0
add ebx, byte SIZEOF_XMMWORD ; outptr1
add edx, byte SIZEOF_XMMWORD ; outptr2
cmp ecx, byte SIZEOF_XMMWORD
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
.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

View File

@@ -1,5 +1,5 @@
; ;
; jccolmmx.asm - colorspace conversion (MMX) ; jccolor.asm - colorspace conversion (MMX)
; ;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2009 D. R. Commander ; Copyright 2009 D. R. Commander
@@ -54,7 +54,7 @@ PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
SECTION SEG_TEXT SECTION SEG_TEXT
BITS 32 BITS 32
%include "jcclrmmx.asm" %include "jccolext-mmx.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -65,7 +65,7 @@ PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_RGB_BLUE %define RGB_BLUE EXT_RGB_BLUE
%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE %define RGB_PIXELSIZE EXT_RGB_PIXELSIZE
%define jsimd_rgb_ycc_convert_mmx jsimd_extrgb_ycc_convert_mmx %define jsimd_rgb_ycc_convert_mmx jsimd_extrgb_ycc_convert_mmx
%include "jcclrmmx.asm" %include "jccolext-mmx.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -76,7 +76,7 @@ PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_RGBX_BLUE %define RGB_BLUE EXT_RGBX_BLUE
%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE %define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE
%define jsimd_rgb_ycc_convert_mmx jsimd_extrgbx_ycc_convert_mmx %define jsimd_rgb_ycc_convert_mmx jsimd_extrgbx_ycc_convert_mmx
%include "jcclrmmx.asm" %include "jccolext-mmx.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -87,7 +87,7 @@ PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_BGR_BLUE %define RGB_BLUE EXT_BGR_BLUE
%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE %define RGB_PIXELSIZE EXT_BGR_PIXELSIZE
%define jsimd_rgb_ycc_convert_mmx jsimd_extbgr_ycc_convert_mmx %define jsimd_rgb_ycc_convert_mmx jsimd_extbgr_ycc_convert_mmx
%include "jcclrmmx.asm" %include "jccolext-mmx.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -98,7 +98,7 @@ PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_BGRX_BLUE %define RGB_BLUE EXT_BGRX_BLUE
%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE %define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE
%define jsimd_rgb_ycc_convert_mmx jsimd_extbgrx_ycc_convert_mmx %define jsimd_rgb_ycc_convert_mmx jsimd_extbgrx_ycc_convert_mmx
%include "jcclrmmx.asm" %include "jccolext-mmx.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -109,7 +109,7 @@ PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_XBGR_BLUE %define RGB_BLUE EXT_XBGR_BLUE
%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE %define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE
%define jsimd_rgb_ycc_convert_mmx jsimd_extxbgr_ycc_convert_mmx %define jsimd_rgb_ycc_convert_mmx jsimd_extxbgr_ycc_convert_mmx
%include "jcclrmmx.asm" %include "jccolext-mmx.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -120,4 +120,4 @@ PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_XRGB_BLUE %define RGB_BLUE EXT_XRGB_BLUE
%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE %define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE
%define jsimd_rgb_ycc_convert_mmx jsimd_extxrgb_ycc_convert_mmx %define jsimd_rgb_ycc_convert_mmx jsimd_extxrgb_ycc_convert_mmx
%include "jcclrmmx.asm" %include "jccolext-mmx.asm"

View File

@@ -1,5 +1,5 @@
; ;
; jccolss2.asm - colorspace conversion (SSE2) ; jccolor.asm - colorspace conversion (64-bit SSE2)
; ;
; x86 SIMD extension for IJG JPEG library ; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru. ; Copyright (C) 1999-2006, MIYASAKA Masaru.
@@ -49,9 +49,9 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_TEXT SECTION SEG_TEXT
BITS 32 BITS 64
%include "jcclrss2.asm" %include "jccolext-sse2-64.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -62,7 +62,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_RGB_BLUE %define RGB_BLUE EXT_RGB_BLUE
%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE %define RGB_PIXELSIZE EXT_RGB_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgb_ycc_convert_sse2 %define jsimd_rgb_ycc_convert_sse2 jsimd_extrgb_ycc_convert_sse2
%include "jcclrss2.asm" %include "jccolext-sse2-64.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -73,7 +73,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_RGBX_BLUE %define RGB_BLUE EXT_RGBX_BLUE
%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE %define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgbx_ycc_convert_sse2 %define jsimd_rgb_ycc_convert_sse2 jsimd_extrgbx_ycc_convert_sse2
%include "jcclrss2.asm" %include "jccolext-sse2-64.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -84,7 +84,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_BGR_BLUE %define RGB_BLUE EXT_BGR_BLUE
%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE %define RGB_PIXELSIZE EXT_BGR_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgr_ycc_convert_sse2 %define jsimd_rgb_ycc_convert_sse2 jsimd_extbgr_ycc_convert_sse2
%include "jcclrss2.asm" %include "jccolext-sse2-64.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -95,7 +95,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_BGRX_BLUE %define RGB_BLUE EXT_BGRX_BLUE
%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE %define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgrx_ycc_convert_sse2 %define jsimd_rgb_ycc_convert_sse2 jsimd_extbgrx_ycc_convert_sse2
%include "jcclrss2.asm" %include "jccolext-sse2-64.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -106,7 +106,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_XBGR_BLUE %define RGB_BLUE EXT_XBGR_BLUE
%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE %define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extxbgr_ycc_convert_sse2 %define jsimd_rgb_ycc_convert_sse2 jsimd_extxbgr_ycc_convert_sse2
%include "jcclrss2.asm" %include "jccolext-sse2-64.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -117,4 +117,4 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_XRGB_BLUE %define RGB_BLUE EXT_XRGB_BLUE
%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE %define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extxrgb_ycc_convert_sse2 %define jsimd_rgb_ycc_convert_sse2 jsimd_extxrgb_ycc_convert_sse2
%include "jcclrss2.asm" %include "jccolext-sse2-64.asm"

View File

@@ -1,5 +1,5 @@
; ;
; jccolss2-64.asm - colorspace conversion (64-bit SSE2) ; jccolor.asm - colorspace conversion (SSE2)
; ;
; x86 SIMD extension for IJG JPEG library ; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru. ; Copyright (C) 1999-2006, MIYASAKA Masaru.
@@ -49,9 +49,9 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_TEXT SECTION SEG_TEXT
BITS 64 BITS 32
%include "jcclrss2-64.asm" %include "jccolext-sse2.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -62,7 +62,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_RGB_BLUE %define RGB_BLUE EXT_RGB_BLUE
%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE %define RGB_PIXELSIZE EXT_RGB_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgb_ycc_convert_sse2 %define jsimd_rgb_ycc_convert_sse2 jsimd_extrgb_ycc_convert_sse2
%include "jcclrss2-64.asm" %include "jccolext-sse2.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -73,7 +73,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_RGBX_BLUE %define RGB_BLUE EXT_RGBX_BLUE
%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE %define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgbx_ycc_convert_sse2 %define jsimd_rgb_ycc_convert_sse2 jsimd_extrgbx_ycc_convert_sse2
%include "jcclrss2-64.asm" %include "jccolext-sse2.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -84,7 +84,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_BGR_BLUE %define RGB_BLUE EXT_BGR_BLUE
%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE %define RGB_PIXELSIZE EXT_BGR_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgr_ycc_convert_sse2 %define jsimd_rgb_ycc_convert_sse2 jsimd_extbgr_ycc_convert_sse2
%include "jcclrss2-64.asm" %include "jccolext-sse2.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -95,7 +95,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_BGRX_BLUE %define RGB_BLUE EXT_BGRX_BLUE
%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE %define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgrx_ycc_convert_sse2 %define jsimd_rgb_ycc_convert_sse2 jsimd_extbgrx_ycc_convert_sse2
%include "jcclrss2-64.asm" %include "jccolext-sse2.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -106,7 +106,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_XBGR_BLUE %define RGB_BLUE EXT_XBGR_BLUE
%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE %define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extxbgr_ycc_convert_sse2 %define jsimd_rgb_ycc_convert_sse2 jsimd_extxbgr_ycc_convert_sse2
%include "jcclrss2-64.asm" %include "jccolext-sse2.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -117,4 +117,4 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_XRGB_BLUE %define RGB_BLUE EXT_XRGB_BLUE
%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE %define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extxrgb_ycc_convert_sse2 %define jsimd_rgb_ycc_convert_sse2 jsimd_extxrgb_ycc_convert_sse2
%include "jcclrss2-64.asm" %include "jccolext-sse2.asm"

View File

@@ -1,5 +1,5 @@
; ;
; jcgrammx.asm - grayscale colorspace conversion (MMX) ; jcgray.asm - grayscale colorspace conversion (MMX)
; ;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2011 D. R. Commander ; Copyright 2011 D. R. Commander
@@ -47,7 +47,7 @@ PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
SECTION SEG_TEXT SECTION SEG_TEXT
BITS 32 BITS 32
%include "jcgrymmx.asm" %include "jcgryext-mmx.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -58,7 +58,7 @@ PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_RGB_BLUE %define RGB_BLUE EXT_RGB_BLUE
%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE %define RGB_PIXELSIZE EXT_RGB_PIXELSIZE
%define jsimd_rgb_gray_convert_mmx jsimd_extrgb_gray_convert_mmx %define jsimd_rgb_gray_convert_mmx jsimd_extrgb_gray_convert_mmx
%include "jcgrymmx.asm" %include "jcgryext-mmx.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -69,7 +69,7 @@ PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_RGBX_BLUE %define RGB_BLUE EXT_RGBX_BLUE
%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE %define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE
%define jsimd_rgb_gray_convert_mmx jsimd_extrgbx_gray_convert_mmx %define jsimd_rgb_gray_convert_mmx jsimd_extrgbx_gray_convert_mmx
%include "jcgrymmx.asm" %include "jcgryext-mmx.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -80,7 +80,7 @@ PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_BGR_BLUE %define RGB_BLUE EXT_BGR_BLUE
%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE %define RGB_PIXELSIZE EXT_BGR_PIXELSIZE
%define jsimd_rgb_gray_convert_mmx jsimd_extbgr_gray_convert_mmx %define jsimd_rgb_gray_convert_mmx jsimd_extbgr_gray_convert_mmx
%include "jcgrymmx.asm" %include "jcgryext-mmx.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -91,7 +91,7 @@ PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_BGRX_BLUE %define RGB_BLUE EXT_BGRX_BLUE
%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE %define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE
%define jsimd_rgb_gray_convert_mmx jsimd_extbgrx_gray_convert_mmx %define jsimd_rgb_gray_convert_mmx jsimd_extbgrx_gray_convert_mmx
%include "jcgrymmx.asm" %include "jcgryext-mmx.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -102,7 +102,7 @@ PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_XBGR_BLUE %define RGB_BLUE EXT_XBGR_BLUE
%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE %define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE
%define jsimd_rgb_gray_convert_mmx jsimd_extxbgr_gray_convert_mmx %define jsimd_rgb_gray_convert_mmx jsimd_extxbgr_gray_convert_mmx
%include "jcgrymmx.asm" %include "jcgryext-mmx.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -113,4 +113,4 @@ PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_XRGB_BLUE %define RGB_BLUE EXT_XRGB_BLUE
%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE %define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE
%define jsimd_rgb_gray_convert_mmx jsimd_extxrgb_gray_convert_mmx %define jsimd_rgb_gray_convert_mmx jsimd_extxrgb_gray_convert_mmx
%include "jcgrymmx.asm" %include "jcgryext-mmx.asm"

View File

@@ -1,5 +1,5 @@
; ;
; jcgrass2-64.asm - grayscale colorspace conversion (64-bit SSE2) ; jcgray.asm - grayscale colorspace conversion (64-bit SSE2)
; ;
; x86 SIMD extension for IJG JPEG library ; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru. ; Copyright (C) 1999-2006, MIYASAKA Masaru.
@@ -44,7 +44,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
SECTION SEG_TEXT SECTION SEG_TEXT
BITS 64 BITS 64
%include "jcgryss2-64.asm" %include "jcgryext-sse2-64.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -55,7 +55,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_RGB_BLUE %define RGB_BLUE EXT_RGB_BLUE
%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE %define RGB_PIXELSIZE EXT_RGB_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extrgb_gray_convert_sse2 %define jsimd_rgb_gray_convert_sse2 jsimd_extrgb_gray_convert_sse2
%include "jcgryss2-64.asm" %include "jcgryext-sse2-64.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -66,7 +66,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_RGBX_BLUE %define RGB_BLUE EXT_RGBX_BLUE
%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE %define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extrgbx_gray_convert_sse2 %define jsimd_rgb_gray_convert_sse2 jsimd_extrgbx_gray_convert_sse2
%include "jcgryss2-64.asm" %include "jcgryext-sse2-64.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -77,7 +77,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_BGR_BLUE %define RGB_BLUE EXT_BGR_BLUE
%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE %define RGB_PIXELSIZE EXT_BGR_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extbgr_gray_convert_sse2 %define jsimd_rgb_gray_convert_sse2 jsimd_extbgr_gray_convert_sse2
%include "jcgryss2-64.asm" %include "jcgryext-sse2-64.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -88,7 +88,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_BGRX_BLUE %define RGB_BLUE EXT_BGRX_BLUE
%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE %define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extbgrx_gray_convert_sse2 %define jsimd_rgb_gray_convert_sse2 jsimd_extbgrx_gray_convert_sse2
%include "jcgryss2-64.asm" %include "jcgryext-sse2-64.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -99,7 +99,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_XBGR_BLUE %define RGB_BLUE EXT_XBGR_BLUE
%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE %define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extxbgr_gray_convert_sse2 %define jsimd_rgb_gray_convert_sse2 jsimd_extxbgr_gray_convert_sse2
%include "jcgryss2-64.asm" %include "jcgryext-sse2-64.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -110,4 +110,4 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_XRGB_BLUE %define RGB_BLUE EXT_XRGB_BLUE
%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE %define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extxrgb_gray_convert_sse2 %define jsimd_rgb_gray_convert_sse2 jsimd_extxrgb_gray_convert_sse2
%include "jcgryss2-64.asm" %include "jcgryext-sse2-64.asm"

View File

@@ -1,5 +1,5 @@
; ;
; jcgrass2.asm - grayscale colorspace conversion (SSE2) ; jcgray.asm - grayscale colorspace conversion (SSE2)
; ;
; x86 SIMD extension for IJG JPEG library ; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru. ; Copyright (C) 1999-2006, MIYASAKA Masaru.
@@ -44,7 +44,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
SECTION SEG_TEXT SECTION SEG_TEXT
BITS 32 BITS 32
%include "jcgryss2.asm" %include "jcgryext-sse2.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -55,7 +55,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_RGB_BLUE %define RGB_BLUE EXT_RGB_BLUE
%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE %define RGB_PIXELSIZE EXT_RGB_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extrgb_gray_convert_sse2 %define jsimd_rgb_gray_convert_sse2 jsimd_extrgb_gray_convert_sse2
%include "jcgryss2.asm" %include "jcgryext-sse2.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -66,7 +66,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_RGBX_BLUE %define RGB_BLUE EXT_RGBX_BLUE
%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE %define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extrgbx_gray_convert_sse2 %define jsimd_rgb_gray_convert_sse2 jsimd_extrgbx_gray_convert_sse2
%include "jcgryss2.asm" %include "jcgryext-sse2.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -77,7 +77,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_BGR_BLUE %define RGB_BLUE EXT_BGR_BLUE
%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE %define RGB_PIXELSIZE EXT_BGR_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extbgr_gray_convert_sse2 %define jsimd_rgb_gray_convert_sse2 jsimd_extbgr_gray_convert_sse2
%include "jcgryss2.asm" %include "jcgryext-sse2.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -88,7 +88,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_BGRX_BLUE %define RGB_BLUE EXT_BGRX_BLUE
%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE %define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extbgrx_gray_convert_sse2 %define jsimd_rgb_gray_convert_sse2 jsimd_extbgrx_gray_convert_sse2
%include "jcgryss2.asm" %include "jcgryext-sse2.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -99,7 +99,7 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_XBGR_BLUE %define RGB_BLUE EXT_XBGR_BLUE
%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE %define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extxbgr_gray_convert_sse2 %define jsimd_rgb_gray_convert_sse2 jsimd_extxbgr_gray_convert_sse2
%include "jcgryss2.asm" %include "jcgryext-sse2.asm"
%undef RGB_RED %undef RGB_RED
%undef RGB_GREEN %undef RGB_GREEN
@@ -110,4 +110,4 @@ PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
%define RGB_BLUE EXT_XRGB_BLUE %define RGB_BLUE EXT_XRGB_BLUE
%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE %define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE
%define jsimd_rgb_gray_convert_sse2 jsimd_extxrgb_gray_convert_sse2 %define jsimd_rgb_gray_convert_sse2 jsimd_extxrgb_gray_convert_sse2
%include "jcgryss2.asm" %include "jcgryext-sse2.asm"

357
simd/jcgryext-mmx.asm Normal file
View File

@@ -0,0 +1,357 @@
;
; jcgryext.asm - grayscale colorspace conversion (MMX)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2011 D. R. Commander
;
; 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_gray_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 2
%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr
align 16
global EXTN(jsimd_rgb_gray_convert_mmx)
EXTN(jsimd_rgb_gray_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]
lea edi, [edi+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 edi
push esi
push ecx ; col
mov esi, JSAMPROW [esi] ; inptr
mov edi, JSAMPROW [edi] ; outptr0
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_gray_cnv
.column_ld16:
test cl, 2*SIZEOF_MMWORD
mov ecx, SIZEOF_MMWORD
jz short .rgb_gray_cnv
movq mmF,mmA
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmG, MMWORD [esi+1*SIZEOF_MMWORD]
jmp short .rgb_gray_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_gray_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_gray_cnv
movq mmD,mmA
movq mmC,mmF
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmF, MMWORD [esi+1*SIZEOF_MMWORD]
jmp short .rgb_gray_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_gray_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
;
; (This implementation)
; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
movq mm6,mm1
punpcklwd mm1,mm3
punpckhwd mm6,mm3
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)
movq mm7, mm6 ; mm7=ROH*FIX(0.299)+GOH*FIX(0.337)
movq mm6,mm0
punpcklwd mm0,mm2
punpckhwd mm6,mm2
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)
movq MMWORD [wk(0)], mm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337)
movq MMWORD [wk(1)], mm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337)
movq mm0, mm5 ; mm0=BO
movq mm6, mm4 ; mm6=BE
movq mm4,mm0
punpcklwd mm0,mm3
punpckhwd mm4,mm3
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)
movq mm3,[GOTOFF(eax,PD_ONEHALF)] ; mm3=[PD_ONEHALF]
paddd mm0, mm1
paddd mm4, mm7
paddd mm0,mm3
paddd mm4,mm3
psrld mm0,SCALEBITS ; mm0=YOL
psrld mm4,SCALEBITS ; mm4=YOH
packssdw mm0,mm4 ; mm0=YO
movq mm4,mm6
punpcklwd mm6,mm2
punpckhwd mm4,mm2
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)
movq mm2,[GOTOFF(eax,PD_ONEHALF)] ; mm2=[PD_ONEHALF]
paddd mm6, MMWORD [wk(0)]
paddd mm4, MMWORD [wk(1)]
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
sub ecx, byte SIZEOF_MMWORD
add esi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; inptr
add edi, byte SIZEOF_MMWORD ; outptr0
cmp ecx, byte SIZEOF_MMWORD
jae near .columnloop
test ecx,ecx
jnz near .column_ld1
pop ecx ; col
pop esi
pop edi
poppic eax
add esi, byte SIZEOF_JSAMPROW ; input_buf
add edi, 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

364
simd/jcgryext-sse2-64.asm Normal file
View File

@@ -0,0 +1,364 @@
;
; jcgryext.asm - grayscale colorspace conversion (64-bit SSE2)
;
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; Copyright (C) 2011, D. R. Commander.
; 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_gray_convert_sse2 (JDIMENSION img_width,
; JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
; JDIMENSION output_row, int num_rows);
;
; r10 = JDIMENSION img_width
; r11 = JSAMPARRAY input_buf
; r12 = JSAMPIMAGE output_buf
; r13 = JDIMENSION output_row
; r14 = int num_rows
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 2
align 16
global EXTN(jsimd_rgb_gray_convert_sse2)
EXTN(jsimd_rgb_gray_convert_sse2):
push rbp
mov rax,rsp ; rax = original rbp
sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)]
collect_args
push rbx
mov rcx, r10
test rcx,rcx
jz near .return
push rcx
mov rsi, r12
mov rcx, r13
mov rdi, JSAMPARRAY [rsi+0*SIZEOF_JSAMPARRAY]
lea rdi, [rdi+rcx*SIZEOF_JSAMPROW]
pop rcx
mov rsi, r11
mov eax, r14d
test rax,rax
jle near .return
.rowloop:
push rdi
push rsi
push rcx ; col
mov rsi, JSAMPROW [rsi] ; inptr
mov rdi, JSAMPROW [rdi] ; outptr0
cmp rcx, byte SIZEOF_XMMWORD
jae near .columnloop
%if RGB_PIXELSIZE == 3 ; ---------------
.column_ld1:
push rax
push rdx
lea rcx,[rcx+rcx*2] ; imul ecx,RGB_PIXELSIZE
test cl, SIZEOF_BYTE
jz short .column_ld2
sub rcx, byte SIZEOF_BYTE
movzx rax, BYTE [rsi+rcx]
.column_ld2:
test cl, SIZEOF_WORD
jz short .column_ld4
sub rcx, byte SIZEOF_WORD
movzx rdx, WORD [rsi+rcx]
shl rax, WORD_BIT
or rax,rdx
.column_ld4:
movd xmmA,eax
pop rdx
pop rax
test cl, SIZEOF_DWORD
jz short .column_ld8
sub rcx, byte SIZEOF_DWORD
movd xmmF, XMM_DWORD [rsi+rcx]
pslldq xmmA, SIZEOF_DWORD
por xmmA,xmmF
.column_ld8:
test cl, SIZEOF_MMWORD
jz short .column_ld16
sub rcx, byte SIZEOF_MMWORD
movq xmmB, XMM_MMWORD [rsi+rcx]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmB
.column_ld16:
test cl, SIZEOF_XMMWORD
jz short .column_ld32
movdqa xmmF,xmmA
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
mov rcx, SIZEOF_XMMWORD
jmp short .rgb_gray_cnv
.column_ld32:
test cl, 2*SIZEOF_XMMWORD
mov rcx, SIZEOF_XMMWORD
jz short .rgb_gray_cnv
movdqa xmmB,xmmA
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
jmp short .rgb_gray_cnv
.columnloop:
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqu xmmB, XMMWORD [rsi+2*SIZEOF_XMMWORD]
.rgb_gray_cnv:
; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
movdqa xmmG,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
movdqa xmmD,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
movdqa xmmE,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
pxor xmmH,xmmH
movdqa xmmC,xmmA
punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmB,xmmE
punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F)
movdqa xmmF,xmmD
punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F)
punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F)
%else ; RGB_PIXELSIZE == 4 ; -----------
.column_ld1:
test cl, SIZEOF_XMMWORD/16
jz short .column_ld2
sub rcx, byte SIZEOF_XMMWORD/16
movd xmmA, XMM_DWORD [rsi+rcx*RGB_PIXELSIZE]
.column_ld2:
test cl, SIZEOF_XMMWORD/8
jz short .column_ld4
sub rcx, byte SIZEOF_XMMWORD/8
movq xmmE, XMM_MMWORD [rsi+rcx*RGB_PIXELSIZE]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmE
.column_ld4:
test cl, SIZEOF_XMMWORD/4
jz short .column_ld8
sub rcx, byte SIZEOF_XMMWORD/4
movdqa xmmE,xmmA
movdqu xmmA, XMMWORD [rsi+rcx*RGB_PIXELSIZE]
.column_ld8:
test cl, SIZEOF_XMMWORD/2
mov rcx, SIZEOF_XMMWORD
jz short .rgb_gray_cnv
movdqa xmmF,xmmA
movdqa xmmH,xmmE
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
jmp short .rgb_gray_cnv
.columnloop:
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+2*SIZEOF_XMMWORD]
movdqu xmmH, XMMWORD [rsi+3*SIZEOF_XMMWORD]
.rgb_gray_cnv:
; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
movdqa xmmD,xmmA
punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
movdqa xmmC,xmmF
punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
movdqa xmmB,xmmA
punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
movdqa xmmG,xmmD
punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
movdqa xmmE,xmmA
punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
movdqa xmmH,xmmB
punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
pxor xmmF,xmmF
movdqa xmmC,xmmA
punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmD,xmmB
punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F)
movdqa xmmG,xmmE
punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E)
punpcklbw xmmF,xmmH
punpckhbw xmmH,xmmH
psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F)
psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F)
%endif ; RGB_PIXELSIZE ; ---------------
; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO
; (Original)
; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
;
; (This implementation)
; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
movdqa xmm6,xmm1
punpcklwd xmm1,xmm3
punpckhwd xmm6,xmm3
pmaddwd xmm1,[rel PW_F0299_F0337] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
movdqa xmm7, xmm6 ; xmm7=ROH*FIX(0.299)+GOH*FIX(0.337)
movdqa xmm6,xmm0
punpcklwd xmm0,xmm2
punpckhwd xmm6,xmm2
pmaddwd xmm0,[rel PW_F0299_F0337] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337)
movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337)
movdqa xmm0, xmm5 ; xmm0=BO
movdqa xmm6, xmm4 ; xmm6=BE
movdqa xmm4,xmm0
punpcklwd xmm0,xmm3
punpckhwd xmm4,xmm3
pmaddwd xmm0,[rel PW_F0114_F0250] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
movdqa xmm3,[rel PD_ONEHALF] ; xmm3=[PD_ONEHALF]
paddd xmm0, xmm1
paddd xmm4, xmm7
paddd xmm0,xmm3
paddd xmm4,xmm3
psrld xmm0,SCALEBITS ; xmm0=YOL
psrld xmm4,SCALEBITS ; xmm4=YOH
packssdw xmm0,xmm4 ; xmm0=YO
movdqa xmm4,xmm6
punpcklwd xmm6,xmm2
punpckhwd xmm4,xmm2
pmaddwd xmm6,[rel PW_F0114_F0250] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
movdqa xmm2,[rel PD_ONEHALF] ; xmm2=[PD_ONEHALF]
paddd xmm6, XMMWORD [wk(0)]
paddd xmm4, XMMWORD [wk(1)]
paddd xmm6,xmm2
paddd xmm4,xmm2
psrld xmm6,SCALEBITS ; xmm6=YEL
psrld xmm4,SCALEBITS ; xmm4=YEH
packssdw xmm6,xmm4 ; xmm6=YE
psllw xmm0,BYTE_BIT
por xmm6,xmm0 ; xmm6=Y
movdqa XMMWORD [rdi], xmm6 ; Save Y
sub rcx, byte SIZEOF_XMMWORD
add rsi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr
add rdi, byte SIZEOF_XMMWORD ; outptr0
cmp rcx, byte SIZEOF_XMMWORD
jae near .columnloop
test rcx,rcx
jnz near .column_ld1
pop rcx ; col
pop rsi
pop rdi
add rsi, byte SIZEOF_JSAMPROW ; input_buf
add rdi, byte SIZEOF_JSAMPROW
dec rax ; num_rows
jg near .rowloop
.return:
pop rbx
uncollect_args
mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp
pop rbp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 16

383
simd/jcgryext-sse2.asm Normal file
View File

@@ -0,0 +1,383 @@
;
; jcgryext.asm - grayscale colorspace conversion (SSE2)
;
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; Copyright (C) 2011, D. R. Commander.
; 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_gray_convert_sse2 (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_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 2
%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr
align 16
global EXTN(jsimd_rgb_gray_convert_sse2)
EXTN(jsimd_rgb_gray_convert_sse2):
push ebp
mov eax,esp ; eax = original ebp
sub esp, byte 4
and esp, byte (-SIZEOF_XMMWORD) ; align to 128 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)]
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]
lea edi, [edi+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 edi
push esi
push ecx ; col
mov esi, JSAMPROW [esi] ; inptr
mov edi, JSAMPROW [edi] ; outptr0
movpic eax, POINTER [gotptr] ; load GOT address (eax)
cmp ecx, byte SIZEOF_XMMWORD
jae near .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
movzx eax, BYTE [esi+ecx]
.column_ld2:
test cl, SIZEOF_WORD
jz short .column_ld4
sub ecx, byte SIZEOF_WORD
movzx edx, WORD [esi+ecx]
shl eax, WORD_BIT
or eax,edx
.column_ld4:
movd xmmA,eax
pop edx
pop eax
test cl, SIZEOF_DWORD
jz short .column_ld8
sub ecx, byte SIZEOF_DWORD
movd xmmF, XMM_DWORD [esi+ecx]
pslldq xmmA, SIZEOF_DWORD
por xmmA,xmmF
.column_ld8:
test cl, SIZEOF_MMWORD
jz short .column_ld16
sub ecx, byte SIZEOF_MMWORD
movq xmmB, XMM_MMWORD [esi+ecx]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmB
.column_ld16:
test cl, SIZEOF_XMMWORD
jz short .column_ld32
movdqa xmmF,xmmA
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
mov ecx, SIZEOF_XMMWORD
jmp short .rgb_gray_cnv
.column_ld32:
test cl, 2*SIZEOF_XMMWORD
mov ecx, SIZEOF_XMMWORD
jz short .rgb_gray_cnv
movdqa xmmB,xmmA
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD]
jmp short .rgb_gray_cnv
alignx 16,7
.columnloop:
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD]
movdqu xmmB, XMMWORD [esi+2*SIZEOF_XMMWORD]
.rgb_gray_cnv:
; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
movdqa xmmG,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
movdqa xmmD,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
movdqa xmmE,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
pxor xmmH,xmmH
movdqa xmmC,xmmA
punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmB,xmmE
punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F)
movdqa xmmF,xmmD
punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F)
punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F)
%else ; RGB_PIXELSIZE == 4 ; -----------
.column_ld1:
test cl, SIZEOF_XMMWORD/16
jz short .column_ld2
sub ecx, byte SIZEOF_XMMWORD/16
movd xmmA, XMM_DWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld2:
test cl, SIZEOF_XMMWORD/8
jz short .column_ld4
sub ecx, byte SIZEOF_XMMWORD/8
movq xmmE, XMM_MMWORD [esi+ecx*RGB_PIXELSIZE]
pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmE
.column_ld4:
test cl, SIZEOF_XMMWORD/4
jz short .column_ld8
sub ecx, byte SIZEOF_XMMWORD/4
movdqa xmmE,xmmA
movdqu xmmA, XMMWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld8:
test cl, SIZEOF_XMMWORD/2
mov ecx, SIZEOF_XMMWORD
jz short .rgb_gray_cnv
movdqa xmmF,xmmA
movdqa xmmH,xmmE
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD]
jmp short .rgb_gray_cnv
alignx 16,7
.columnloop:
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [esi+2*SIZEOF_XMMWORD]
movdqu xmmH, XMMWORD [esi+3*SIZEOF_XMMWORD]
.rgb_gray_cnv:
; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
movdqa xmmD,xmmA
punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
movdqa xmmC,xmmF
punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
movdqa xmmB,xmmA
punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
movdqa xmmG,xmmD
punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
movdqa xmmE,xmmA
punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
movdqa xmmH,xmmB
punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
pxor xmmF,xmmF
movdqa xmmC,xmmA
punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmD,xmmB
punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F)
movdqa xmmG,xmmE
punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E)
punpcklbw xmmF,xmmH
punpckhbw xmmH,xmmH
psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F)
psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F)
%endif ; RGB_PIXELSIZE ; ---------------
; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO
; (Original)
; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
;
; (This implementation)
; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
movdqa xmm6,xmm1
punpcklwd xmm1,xmm3
punpckhwd xmm6,xmm3
pmaddwd xmm1,[GOTOFF(eax,PW_F0299_F0337)] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
movdqa xmm7, xmm6 ; xmm7=ROH*FIX(0.299)+GOH*FIX(0.337)
movdqa xmm6,xmm0
punpcklwd xmm0,xmm2
punpckhwd xmm6,xmm2
pmaddwd xmm0,[GOTOFF(eax,PW_F0299_F0337)] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337)
movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337)
movdqa xmm0, xmm5 ; xmm0=BO
movdqa xmm6, xmm4 ; xmm6=BE
movdqa xmm4,xmm0
punpcklwd xmm0,xmm3
punpckhwd xmm4,xmm3
pmaddwd xmm0,[GOTOFF(eax,PW_F0114_F0250)] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
movdqa xmm3,[GOTOFF(eax,PD_ONEHALF)] ; xmm3=[PD_ONEHALF]
paddd xmm0, xmm1
paddd xmm4, xmm7
paddd xmm0,xmm3
paddd xmm4,xmm3
psrld xmm0,SCALEBITS ; xmm0=YOL
psrld xmm4,SCALEBITS ; xmm4=YOH
packssdw xmm0,xmm4 ; xmm0=YO
movdqa xmm4,xmm6
punpcklwd xmm6,xmm2
punpckhwd xmm4,xmm2
pmaddwd xmm6,[GOTOFF(eax,PW_F0114_F0250)] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
movdqa xmm2,[GOTOFF(eax,PD_ONEHALF)] ; xmm2=[PD_ONEHALF]
paddd xmm6, XMMWORD [wk(0)]
paddd xmm4, XMMWORD [wk(1)]
paddd xmm6,xmm2
paddd xmm4,xmm2
psrld xmm6,SCALEBITS ; xmm6=YEL
psrld xmm4,SCALEBITS ; xmm4=YEH
packssdw xmm6,xmm4 ; xmm6=YE
psllw xmm0,BYTE_BIT
por xmm6,xmm0 ; xmm6=Y
movdqa XMMWORD [edi], xmm6 ; Save Y
sub ecx, byte SIZEOF_XMMWORD
add esi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr
add edi, byte SIZEOF_XMMWORD ; outptr0
cmp ecx, byte SIZEOF_XMMWORD
jae near .columnloop
test ecx,ecx
jnz near .column_ld1
pop ecx ; col
pop esi
pop edi
poppic eax
add esi, byte SIZEOF_JSAMPROW ; input_buf
add edi, byte SIZEOF_JSAMPROW
dec eax ; num_rows
jg near .rowloop
.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

View File

@@ -1,357 +0,0 @@
;
; jcgrymmx.asm - grayscale colorspace conversion (MMX)
;
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
; Copyright 2011 D. R. Commander
;
; 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_gray_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 2
%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr
align 16
global EXTN(jsimd_rgb_gray_convert_mmx)
EXTN(jsimd_rgb_gray_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]
lea edi, [edi+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 edi
push esi
push ecx ; col
mov esi, JSAMPROW [esi] ; inptr
mov edi, JSAMPROW [edi] ; outptr0
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_gray_cnv
.column_ld16:
test cl, 2*SIZEOF_MMWORD
mov ecx, SIZEOF_MMWORD
jz short .rgb_gray_cnv
movq mmF,mmA
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmG, MMWORD [esi+1*SIZEOF_MMWORD]
jmp short .rgb_gray_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_gray_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_gray_cnv
movq mmD,mmA
movq mmC,mmF
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmF, MMWORD [esi+1*SIZEOF_MMWORD]
jmp short .rgb_gray_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_gray_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
;
; (This implementation)
; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
movq mm6,mm1
punpcklwd mm1,mm3
punpckhwd mm6,mm3
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)
movq mm7, mm6 ; mm7=ROH*FIX(0.299)+GOH*FIX(0.337)
movq mm6,mm0
punpcklwd mm0,mm2
punpckhwd mm6,mm2
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)
movq MMWORD [wk(0)], mm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337)
movq MMWORD [wk(1)], mm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337)
movq mm0, mm5 ; mm0=BO
movq mm6, mm4 ; mm6=BE
movq mm4,mm0
punpcklwd mm0,mm3
punpckhwd mm4,mm3
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)
movq mm3,[GOTOFF(eax,PD_ONEHALF)] ; mm3=[PD_ONEHALF]
paddd mm0, mm1
paddd mm4, mm7
paddd mm0,mm3
paddd mm4,mm3
psrld mm0,SCALEBITS ; mm0=YOL
psrld mm4,SCALEBITS ; mm4=YOH
packssdw mm0,mm4 ; mm0=YO
movq mm4,mm6
punpcklwd mm6,mm2
punpckhwd mm4,mm2
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)
movq mm2,[GOTOFF(eax,PD_ONEHALF)] ; mm2=[PD_ONEHALF]
paddd mm6, MMWORD [wk(0)]
paddd mm4, MMWORD [wk(1)]
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
sub ecx, byte SIZEOF_MMWORD
add esi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; inptr
add edi, byte SIZEOF_MMWORD ; outptr0
cmp ecx, byte SIZEOF_MMWORD
jae near .columnloop
test ecx,ecx
jnz near .column_ld1
pop ecx ; col
pop esi
pop edi
poppic eax
add esi, byte SIZEOF_JSAMPROW ; input_buf
add edi, 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