Merge commit '8162eddf041e0be26f5c671bb6528723c55fed9d'

* commit '8162eddf041e0be26f5c671bb6528723c55fed9d': (24 commits)
  Fix issues w/ partial img decompr + buf img mode
  Re-fix buf img mode decompr err w/short prog JPEGs
  jdcoefct.c: Fix signed/unsigned mismatch VC++ wrng
  Fix buf image mode decompr err w/ short prog JPEGs
  PowerPC: Detect AltiVec support on OS X
  tjDecompressHeader3(): Accept tables-only streams
  Fix build if UPSAMPLE_MERGING_SUPPORTED undefined
  Build: Don't enable Loongson MMI with MIPS R6+
  MinGW: Fix str*casecmp() macro redef. warning
  OSS-Fuzz: '.' --> '_' in fuzzer suffix
  Don't install libturbojpeg.pc if WITH_TURBOJPEG=0
  Fix non-SIMD alignment if void* bigger than double
  OSS-Fuzz: Allow fuzzer suffix to be specified
  CI: Un-integrate CIFuzz
  BUILDING.md: Generify PowerTools repo advice
  Build: Don't set DEFAULT_FLOATTEST for x86 MSVC
  Build/Win: Fix CMake warning when WITH_TURBOJPEG=0
  Win: Fix build with Visual Studio 2010
  Link Sponsor button to GitHub Sponsors ...
  example.txt: Fix a typo
  ...
This commit is contained in:
Kornel 2022-08-15 02:46:09 +01:00
Родитель a2d2907ff0 8162eddf04
Коммит fd56921259
46 изменённых файлов: 273 добавлений и 229 удалений

Просмотреть файл

@ -26,8 +26,8 @@ Build Requirements
slashes rather than backslashes in the path (for example,
**c:/nasm/nasm.exe**).
* NASM and Yasm are located in the CRB (Code Ready Builder) repository on
Red Hat Enterprise Linux 8 and in the PowerTools repository on CentOS 8,
which is not enabled by default.
Red Hat Enterprise Linux 8 and in the PowerTools repository on RHEL
derivatives, which is not enabled by default.
### Un*x Platforms (including Linux, Mac, FreeBSD, Solaris, and Cygwin)
@ -97,6 +97,14 @@ Build Requirements
* If using JDK 11 or later, CMake 3.10.x or later must also be used.
Sub-Project Builds
------------------
The libjpeg-turbo build system does not support being included as a sub-project
using the CMake `add_subdirectory()` function. Use the CMake
`ExternalProject_Add()` function instead.
Out-of-Tree Builds
------------------

Просмотреть файл

@ -10,7 +10,8 @@ if(CMAKE_EXECUTABLE_SUFFIX)
endif()
project(mozjpeg C)
set(VERSION 4.1.1)
set(VERSION 4.1.2)
set(COPYRIGHT_YEAR "1991-2022")
string(REPLACE "." ";" VERSION_TRIPLET ${VERSION})
list(GET VERSION_TRIPLET 0 VERSION_MAJOR)
list(GET VERSION_TRIPLET 1 VERSION_MINOR)
@ -956,10 +957,8 @@ if(CPU_TYPE STREQUAL "x86_64" OR CPU_TYPE STREQUAL "i386")
set(DEFAULT_FLOATTEST sse)
elseif(CPU_TYPE STREQUAL "x86_64")
set(DEFAULT_FLOATTEST no-fp-contract)
elseif(CPU_TYPE STREQUAL "i386" AND MSVC)
set(DEFAULT_FLOATTEST msvc)
# else we can't really set an intelligent default for i386. The appropriate
# value could be 387, no-fp-contract, or fp-contract, depending on the
# value could be no-fp-contract, fp-contract, 387, or msvc, depending on the
# compiler and compiler options. We leave it to the user to set FLOATTEST
# manually.
endif()
@ -1510,8 +1509,11 @@ if(UNIX OR MINGW)
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
endif()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgscripts/libjpeg.pc
${CMAKE_CURRENT_BINARY_DIR}/pkgscripts/libturbojpeg.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
if(WITH_TURBOJPEG)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgscripts/libturbojpeg.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/pkgscripts/${CMAKE_PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/pkgscripts/${CMAKE_PROJECT_NAME}ConfigVersion.cmake

Просмотреть файл

@ -1,3 +1,38 @@
2.1.4
=====
### Significant changes relative to 2.1.3
1. Fixed a regression introduced in 2.1.3 that caused build failures with
Visual Studio 2010.
2. The `tjDecompressHeader3()` function in the TurboJPEG C API and the
`TJDecompressor.setSourceImage()` method in the TurboJPEG Java API now accept
"abbreviated table specification" (AKA "tables-only") datastreams, which can be
used to prime the decompressor with quantization and Huffman tables that can be
used when decompressing subsequent "abbreviated image" datastreams.
3. libjpeg-turbo now performs run-time detection of AltiVec instructions on
OS X/PowerPC systems if AltiVec instructions are not enabled at compile time.
This allows both AltiVec-equipped (PowerPC G4 and G5) and non-AltiVec-equipped
(PowerPC G3) CPUs to be supported using the same build of libjpeg-turbo.
4. Fixed an error ("Bogus virtual array access") that occurred when attempting
to decompress a progressive JPEG image with a height less than or equal to one
iMCU (8 * the vertical sampling factor) using buffered-image mode with
interblock smoothing enabled. This was a regression introduced by
2.1 beta1[6(b)].
5. Fixed two issues that prevented partial image decompression from working
properly with buffered-image mode:
- Attempting to call `jpeg_crop_scanline()` after
`jpeg_start_decompress()` but before `jpeg_start_output()` resulted in an error
("Improper call to JPEG library in state 207".)
- Attempting to use `jpeg_skip_scanlines()` resulted in an error ("Bogus
virtual array access") under certain circumstances.
2.1.3
=====

15
cjpeg.c
Просмотреть файл

@ -39,16 +39,6 @@
#include "jversion.h" /* for version message */
#include "jconfigint.h"
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
#ifdef __MWERKS__
#include <SIOUX.h> /* Metrowerks needs this */
#include <console.h> /* ... and this */
#endif
#ifdef THINK_C
#include <console.h> /* Think declares it here */
#endif
#endif
/* Create the add-on message string table. */
@ -743,11 +733,6 @@ main(int argc, char **argv)
unsigned long outsize = 0;
JDIMENSION num_scanlines;
/* On Mac, fetch a command line. */
#ifdef USE_CCOMMAND
argc = ccommand(&argv);
#endif
progname = argv[0];
if (progname == NULL || progname[0] == 0)
progname = "cjpeg"; /* in case C library doesn't provide it */

Просмотреть файл

@ -109,10 +109,13 @@ configure_file(win/${INST_ID}/projectTargets-release.cmake.in
if(WITH_JAVA)
set(JAVA_DEPEND turbojpeg-java)
endif()
if(WITH_TURBOJPEG)
set(TURBOJPEG_DEPEND turbojpeg turbojpeg-static tjbench)
endif()
add_custom_target(installer
makensis -nocd ${INST_DEFS} installer.nsi
DEPENDS jpeg jpeg-static turbojpeg turbojpeg-static rdjpgcom wrjpgcom
cjpeg djpeg jpegtran tjbench ${JAVA_DEPEND}
DEPENDS jpeg jpeg-static rdjpgcom wrjpgcom cjpeg djpeg jpegtran
${JAVA_DEPEND} ${TURBOJPEG_DEPEND}
SOURCES installer.nsi)
endif() # WIN32
@ -159,7 +162,9 @@ add_custom_target(tarball pkgscripts/maketarball
configure_file(release/libjpeg.pc.in pkgscripts/libjpeg.pc @ONLY)
configure_file(release/libturbojpeg.pc.in pkgscripts/libturbojpeg.pc @ONLY)
if(WITH_TURBOJPEG)
configure_file(release/libturbojpeg.pc.in pkgscripts/libturbojpeg.pc @ONLY)
endif()
include(CMakePackageConfigHelpers)
write_basic_package_version_file(

15
djpeg.c
Просмотреть файл

@ -38,16 +38,6 @@
#include <ctype.h> /* to declare isprint() */
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
#ifdef __MWERKS__
#include <SIOUX.h> /* Metrowerks needs this */
#include <console.h> /* ... and this */
#endif
#ifdef THINK_C
#include <console.h> /* Think declares it here */
#endif
#endif
/* Create the add-on message string table. */
@ -550,11 +540,6 @@ main(int argc, char **argv)
#endif
JDIMENSION num_scanlines;
/* On Mac, fetch a command line. */
#ifdef USE_CCOMMAND
argc = ccommand(&argv);
#endif
progname = argv[0];
if (progname == NULL || progname[0] == 0)
progname = "djpeg"; /* in case C library doesn't provide it */

Просмотреть файл

@ -23,7 +23,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
&#160;<span id="projectnumber">2.1</span>
&#160;<span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>

Просмотреть файл

@ -23,7 +23,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
&#160;<span id="projectnumber">2.1</span>
&#160;<span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>

Просмотреть файл

@ -23,7 +23,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
&#160;<span id="projectnumber">2.1</span>
&#160;<span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>

Просмотреть файл

@ -23,7 +23,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
&#160;<span id="projectnumber">2.1</span>
&#160;<span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>

Просмотреть файл

@ -23,7 +23,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
&#160;<span id="projectnumber">2.1</span>
&#160;<span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>
@ -273,7 +273,7 @@ Functions</h2></td></tr>
<tr class="memdesc:ga52300eac3f3d9ef4bab303bc244f62d3"><td class="mdescLeft">&#160;</td><td class="mdescRight">Create a TurboJPEG decompressor instance. <a href="group___turbo_j_p_e_g.html#ga52300eac3f3d9ef4bab303bc244f62d3">More...</a><br /></td></tr>
<tr class="separator:ga52300eac3f3d9ef4bab303bc244f62d3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga0595681096bba7199cc6f3533cb25f77"><td class="memItemLeft" align="right" valign="top">DLLEXPORT int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga0595681096bba7199cc6f3533cb25f77">tjDecompressHeader3</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle, const unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height, int *jpegSubsamp, int *jpegColorspace)</td></tr>
<tr class="memdesc:ga0595681096bba7199cc6f3533cb25f77"><td class="mdescLeft">&#160;</td><td class="mdescRight">Retrieve information about a JPEG image without decompressing it. <a href="group___turbo_j_p_e_g.html#ga0595681096bba7199cc6f3533cb25f77">More...</a><br /></td></tr>
<tr class="memdesc:ga0595681096bba7199cc6f3533cb25f77"><td class="mdescLeft">&#160;</td><td class="mdescRight">Retrieve information about a JPEG image without decompressing it, or prime the decompressor with quantization and Huffman tables. <a href="group___turbo_j_p_e_g.html#ga0595681096bba7199cc6f3533cb25f77">More...</a><br /></td></tr>
<tr class="separator:ga0595681096bba7199cc6f3533cb25f77"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gac3854476006b10787bd128f7ede48057"><td class="memItemLeft" align="right" valign="top">DLLEXPORT <a class="el" href="structtjscalingfactor.html">tjscalingfactor</a> *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#gac3854476006b10787bd128f7ede48057">tjGetScalingFactors</a> (int *numscalingfactors)</td></tr>
<tr class="memdesc:gac3854476006b10787bd128f7ede48057"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a list of fractional scaling factors that the JPEG decompressor in this implementation of TurboJPEG supports. <a href="group___turbo_j_p_e_g.html#gac3854476006b10787bd128f7ede48057">More...</a><br /></td></tr>
@ -1725,16 +1725,16 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
</table>
</div><div class="memdoc">
<p>Retrieve information about a JPEG image without decompressing it. </p>
<p>Retrieve information about a JPEG image without decompressing it, or prime the decompressor with quantization and Huffman tables. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">handle</td><td>a handle to a TurboJPEG decompressor or transformer instance</td></tr>
<tr><td class="paramname">jpegBuf</td><td>pointer to a buffer containing a JPEG image</td></tr>
<tr><td class="paramname">jpegSize</td><td>size of the JPEG image (in bytes)</td></tr>
<tr><td class="paramname">width</td><td>pointer to an integer variable that will receive the width (in pixels) of the JPEG image</td></tr>
<tr><td class="paramname">height</td><td>pointer to an integer variable that will receive the height (in pixels) of the JPEG image</td></tr>
<tr><td class="paramname">jpegSubsamp</td><td>pointer to an integer variable that will receive the level of chrominance subsampling used when the JPEG image was compressed (see <a class="el" href="group___turbo_j_p_e_g.html#ga1d047060ea80bb9820d540bb928e9074">Chrominance subsampling options</a>.)</td></tr>
<tr><td class="paramname">jpegColorspace</td><td>pointer to an integer variable that will receive one of the JPEG colorspace constants, indicating the colorspace of the JPEG image (see <a class="el" href="group___turbo_j_p_e_g.html#ga4f83ad3368e0e29d1957be0efa7c3720">JPEG colorspaces</a>.)</td></tr>
<tr><td class="paramname">jpegBuf</td><td>pointer to a buffer containing a JPEG image or an "abbreviated table specification" (AKA "tables-only") datastream. Passing a tables-only datastream to this function primes the decompressor with quantization and Huffman tables that can be used when decompressing subsequent "abbreviated image" datastreams. This is useful, for instance, when decompressing video streams in which all frames share the same quantization and Huffman tables.</td></tr>
<tr><td class="paramname">jpegSize</td><td>size of the JPEG image or tables-only datastream (in bytes)</td></tr>
<tr><td class="paramname">width</td><td>pointer to an integer variable that will receive the width (in pixels) of the JPEG image. If <code>jpegBuf</code> points to a tables-only datastream, then <code>width</code> is ignored.</td></tr>
<tr><td class="paramname">height</td><td>pointer to an integer variable that will receive the height (in pixels) of the JPEG image. If <code>jpegBuf</code> points to a tables-only datastream, then <code>height</code> is ignored.</td></tr>
<tr><td class="paramname">jpegSubsamp</td><td>pointer to an integer variable that will receive the level of chrominance subsampling used when the JPEG image was compressed (see <a class="el" href="group___turbo_j_p_e_g.html#ga1d047060ea80bb9820d540bb928e9074">Chrominance subsampling options</a>.) If <code>jpegBuf</code> points to a tables-only datastream, then <code>jpegSubsamp</code> is ignored.</td></tr>
<tr><td class="paramname">jpegColorspace</td><td>pointer to an integer variable that will receive one of the JPEG colorspace constants, indicating the colorspace of the JPEG image (see <a class="el" href="group___turbo_j_p_e_g.html#ga4f83ad3368e0e29d1957be0efa7c3720">JPEG colorspaces</a>.) If <code>jpegBuf</code> points to a tables-only datastream, then <code>jpegColorspace</code> is ignored.</td></tr>
</table>
</dd>
</dl>

Просмотреть файл

@ -23,7 +23,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
&#160;<span id="projectnumber">2.1</span>
&#160;<span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>

Просмотреть файл

@ -23,7 +23,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
&#160;<span id="projectnumber">2.1</span>
&#160;<span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>

Просмотреть файл

@ -23,7 +23,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
&#160;<span id="projectnumber">2.1</span>
&#160;<span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>

Просмотреть файл

@ -23,7 +23,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
&#160;<span id="projectnumber">2.1</span>
&#160;<span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>

Просмотреть файл

@ -23,7 +23,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
&#160;<span id="projectnumber">2.1</span>
&#160;<span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>

Просмотреть файл

@ -1,5 +1,5 @@
PROJECT_NAME = TurboJPEG
PROJECT_NUMBER = 2.1
PROJECT_NUMBER = 2.1.4
OUTPUT_DIRECTORY = doc/
USE_WINDOWS_ENCODING = NO
OPTIMIZE_OUTPUT_FOR_C = YES

Просмотреть файл

@ -311,7 +311,7 @@ read_JPEG_file(char *filename)
* We call the libjpeg API from within a separate function, because modifying
* the local non-volatile jpeg_decompress_struct instance below the setjmp()
* return point and then accessing the instance after setjmp() returns would
* return in undefined behavior that may potentially overwrite all or part of
* result in undefined behavior that may potentially overwrite all or part of
* the structure.
*/

Просмотреть файл

@ -25,16 +25,20 @@ set(EFFECTIVE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UC}}")
message(STATUS "C++ Compiler flags = ${EFFECTIVE_CXX_FLAGS}")
add_executable(cjpeg_fuzzer cjpeg.cc ../cdjpeg.c ../rdbmp.c ../rdgif.c
../rdppm.c ../rdswitch.c ../rdtarga.c)
set_property(TARGET cjpeg_fuzzer PROPERTY COMPILE_FLAGS ${COMPILE_FLAGS})
target_link_libraries(cjpeg_fuzzer ${FUZZ_LIBRARY} jpeg-static)
install(TARGETS cjpeg_fuzzer RUNTIME DESTINATION ${FUZZ_BINDIR})
add_executable(cjpeg_fuzzer${FUZZER_SUFFIX} cjpeg.cc ../cdjpeg.c ../rdbmp.c
../rdgif.c ../rdppm.c ../rdswitch.c ../rdtarga.c)
set_property(TARGET cjpeg_fuzzer${FUZZER_SUFFIX} PROPERTY COMPILE_FLAGS
${COMPILE_FLAGS})
target_link_libraries(cjpeg_fuzzer${FUZZER_SUFFIX} ${FUZZ_LIBRARY} jpeg-static)
install(TARGETS cjpeg_fuzzer${FUZZER_SUFFIX} RUNTIME DESTINATION
${FUZZ_BINDIR})
macro(add_fuzz_target target source_file)
add_executable(${target}_fuzzer ${source_file})
target_link_libraries(${target}_fuzzer ${FUZZ_LIBRARY} turbojpeg-static)
install(TARGETS ${target}_fuzzer RUNTIME DESTINATION ${FUZZ_BINDIR})
add_executable(${target}_fuzzer${FUZZER_SUFFIX} ${source_file})
target_link_libraries(${target}_fuzzer${FUZZER_SUFFIX} ${FUZZ_LIBRARY}
turbojpeg-static)
install(TARGETS ${target}_fuzzer${FUZZER_SUFFIX} RUNTIME DESTINATION
${FUZZ_BINDIR})
endmacro()
add_fuzz_target(compress compress.cc)

Просмотреть файл

@ -3,16 +3,23 @@
set -u
set -e
FUZZER_SUFFIX=
if [ $# -ge 1 ]; then
FUZZER_SUFFIX="$1"
FUZZER_SUFFIX="`echo $1 | sed 's/\./_/g'`"
fi
cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_STATIC=1 -DENABLE_SHARED=0 \
-DCMAKE_C_FLAGS_RELWITHDEBINFO="-g -DNDEBUG" \
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-g -DNDEBUG" -DCMAKE_INSTALL_PREFIX=$WORK \
-DWITH_FUZZ=1 -DFUZZ_BINDIR=$OUT -DFUZZ_LIBRARY=$LIB_FUZZING_ENGINE
-DWITH_FUZZ=1 -DFUZZ_BINDIR=$OUT -DFUZZ_LIBRARY=$LIB_FUZZING_ENGINE \
-DFUZZER_SUFFIX="$FUZZER_SUFFIX"
make "-j$(nproc)" "--load-average=$(nproc)"
make install
cp $SRC/compress_fuzzer_seed_corpus.zip $OUT/cjpeg_fuzzer_seed_corpus.zip
cp $SRC/compress_fuzzer_seed_corpus.zip $OUT/compress_fuzzer_seed_corpus.zip
cp $SRC/compress_fuzzer_seed_corpus.zip $OUT/compress_yuv_fuzzer_seed_corpus.zip
cp $SRC/decompress_fuzzer_seed_corpus.zip $OUT/libjpeg_turbo_fuzzer_seed_corpus.zip
cp $SRC/decompress_fuzzer_seed_corpus.zip $OUT/decompress_yuv_fuzzer_seed_corpus.zip
cp $SRC/decompress_fuzzer_seed_corpus.zip $OUT/transform_fuzzer_seed_corpus.zip
cp $SRC/compress_fuzzer_seed_corpus.zip $OUT/cjpeg_fuzzer${FUZZER_SUFFIX}_seed_corpus.zip
cp $SRC/compress_fuzzer_seed_corpus.zip $OUT/compress_fuzzer${FUZZER_SUFFIX}_seed_corpus.zip
cp $SRC/compress_fuzzer_seed_corpus.zip $OUT/compress_yuv_fuzzer${FUZZER_SUFFIX}_seed_corpus.zip
cp $SRC/decompress_fuzzer_seed_corpus.zip $OUT/libjpeg_turbo_fuzzer${FUZZER_SUFFIX}_seed_corpus.zip
cp $SRC/decompress_fuzzer_seed_corpus.zip $OUT/decompress_yuv_fuzzer${FUZZER_SUFFIX}_seed_corpus.zip
cp $SRC/decompress_fuzzer_seed_corpus.zip $OUT/transform_fuzzer${FUZZER_SUFFIX}_seed_corpus.zip

Просмотреть файл

@ -792,7 +792,8 @@
</dd>
<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html#setSourceImage(byte[],%20int)">setSourceImage(byte[], int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>
<dd>
<div class="block">Associate the JPEG image of length <code>imageSize</code> bytes stored in
<div class="block">Associate the JPEG image or "abbreviated table specification" (AKA
"tables-only") datastream of length <code>imageSize</code> bytes stored in
<code>jpegImage</code> with this decompressor instance.</div>
</dd>
<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html#setSourceImage(org.libjpegturbo.turbojpeg.YUVImage)">setSourceImage(YUVImage)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>

Просмотреть файл

@ -418,7 +418,8 @@ implements java.io.Closeable</pre>
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJDecompressor.html#setSourceImage(byte[],%20int)">setSourceImage</a></strong>(byte[]&nbsp;jpegImage,
int&nbsp;imageSize)</code>
<div class="block">Associate the JPEG image of length <code>imageSize</code> bytes stored in
<div class="block">Associate the JPEG image or "abbreviated table specification" (AKA
"tables-only") datastream of length <code>imageSize</code> bytes stored in
<code>jpegImage</code> with this decompressor instance.</div>
</td>
</tr>
@ -611,10 +612,19 @@ implements java.io.Closeable</pre>
<pre>public&nbsp;void&nbsp;setSourceImage(byte[]&nbsp;jpegImage,
int&nbsp;imageSize)
throws <a href="../../../org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Associate the JPEG image of length <code>imageSize</code> bytes stored in
<code>jpegImage</code> with this decompressor instance. This image will
be used as the source image for subsequent decompress operations.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>jpegImage</code> - JPEG image buffer. This buffer is not modified.</dd><dd><code>imageSize</code> - size of the JPEG image (in bytes)</dd>
<div class="block">Associate the JPEG image or "abbreviated table specification" (AKA
"tables-only") datastream of length <code>imageSize</code> bytes stored in
<code>jpegImage</code> with this decompressor instance. If
<code>jpegImage</code> contains a JPEG image, then this image will be used
as the source image for subsequent decompress operations. Passing a
tables-only datastream to this method primes the decompressor with
quantization and Huffman tables that can be used when decompressing
subsequent "abbreviated image" datastreams. This is useful, for instance,
when decompressing video streams in which all frames share the same
quantization and Huffman tables.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>jpegImage</code> - buffer containing a JPEG image or an "abbreviated table
specification" (AKA "tables-only") datastream. This buffer is not
modified.</dd><dd><code>imageSize</code> - size of the JPEG image (in bytes)</dd>
<dt><span class="strong">Throws:</span></dt>
<dd><code><a href="../../../org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></code></dd></dl>
</li>

Просмотреть файл

@ -1,5 +1,5 @@
/*
* Copyright (C)2011-2015, 2018 D. R. Commander. All Rights Reserved.
* Copyright (C)2011-2015, 2018, 2022 D. R. Commander. All Rights Reserved.
* Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -89,11 +89,20 @@ public class TJDecompressor implements Closeable {
}
/**
* Associate the JPEG image of length <code>imageSize</code> bytes stored in
* <code>jpegImage</code> with this decompressor instance. This image will
* be used as the source image for subsequent decompress operations.
* Associate the JPEG image or "abbreviated table specification" (AKA
* "tables-only") datastream of length <code>imageSize</code> bytes stored in
* <code>jpegImage</code> with this decompressor instance. If
* <code>jpegImage</code> contains a JPEG image, then this image will be used
* as the source image for subsequent decompress operations. Passing a
* tables-only datastream to this method primes the decompressor with
* quantization and Huffman tables that can be used when decompressing
* subsequent "abbreviated image" datastreams. This is useful, for instance,
* when decompressing video streams in which all frames share the same
* quantization and Huffman tables.
*
* @param jpegImage JPEG image buffer. This buffer is not modified.
* @param jpegImage buffer containing a JPEG image or an "abbreviated table
* specification" (AKA "tables-only") datastream. This buffer is not
* modified.
*
* @param imageSize size of the JPEG image (in bytes)
*/

Просмотреть файл

@ -159,9 +159,12 @@ jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
JDIMENSION input_xoffset;
boolean reinit_upsampler = FALSE;
jpeg_component_info *compptr;
#ifdef UPSAMPLE_MERGING_SUPPORTED
my_master_ptr master = (my_master_ptr)cinfo->master;
#endif
if (cinfo->global_state != DSTATE_SCANNING || cinfo->output_scanline != 0)
if ((cinfo->global_state != DSTATE_SCANNING &&
cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
if (!xoffset || !width)
@ -209,11 +212,13 @@ jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
*/
*width = *width + input_xoffset - *xoffset;
cinfo->output_width = *width;
#ifdef UPSAMPLE_MERGING_SUPPORTED
if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
upsample->out_row_width =
cinfo->output_width * cinfo->out_color_components;
}
#endif
/* Set the first and last iMCU columns that we must decompress. These values
* will be used in single-scan decompressions.
@ -324,7 +329,9 @@ LOCAL(void)
read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
{
JDIMENSION n;
#ifdef UPSAMPLE_MERGING_SUPPORTED
my_master_ptr master = (my_master_ptr)cinfo->master;
#endif
JSAMPLE dummy_sample[1] = { 0 };
JSAMPROW dummy_row = dummy_sample;
JSAMPARRAY scanlines = NULL;
@ -348,10 +355,12 @@ read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
cinfo->cquantize->color_quantize = noop_quantize;
}
#ifdef UPSAMPLE_MERGING_SUPPORTED
if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
scanlines = &upsample->spare_row;
}
#endif
for (n = 0; n < num_lines; n++)
jpeg_read_scanlines(cinfo, scanlines, 1);
@ -517,7 +526,7 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
* all of the entropy decoding occurs in jpeg_start_decompress(), assuming
* that the input data source is non-suspending. This makes skipping easy.
*/
if (cinfo->inputctl->has_multiple_scans) {
if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) {
if (cinfo->upsample->need_context_rows) {
cinfo->output_scanline += lines_to_skip;
cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;

Просмотреть файл

@ -5,7 +5,7 @@
* Copyright (C) 1994-1997, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2010, 2015-2016, 2019-2020, D. R. Commander.
* Copyright (C) 2010, 2015-2016, 2019-2020, 2022, D. R. Commander.
* Copyright (C) 2015, 2020, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
@ -475,7 +475,7 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
if (!compptr->component_needed)
continue;
/* Count non-dummy DCT block rows in this iMCU row. */
if (cinfo->output_iMCU_row < last_iMCU_row - 1) {
if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
block_rows = compptr->v_samp_factor;
access_rows = block_rows * 3; /* this and next two iMCU rows */
} else if (cinfo->output_iMCU_row < last_iMCU_row) {
@ -560,7 +560,7 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
next_block_row = buffer_ptr;
if (block_row < block_rows - 2 ||
cinfo->output_iMCU_row < last_iMCU_row - 1)
cinfo->output_iMCU_row + 1 < last_iMCU_row)
next_next_block_row =
buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
else

Просмотреть файл

@ -189,9 +189,9 @@ format_message(j_common_ptr cinfo, char *buffer)
/* Format the message into the passed buffer */
if (isstring)
snprintf(buffer, JMSG_LENGTH_MAX, msgtext, err->msg_parm.s);
SNPRINTF(buffer, JMSG_LENGTH_MAX, msgtext, err->msg_parm.s);
else
snprintf(buffer, JMSG_LENGTH_MAX, msgtext,
SNPRINTF(buffer, JMSG_LENGTH_MAX, msgtext,
err->msg_parm.i[0], err->msg_parm.i[1],
err->msg_parm.i[2], err->msg_parm.i[3],
err->msg_parm.i[4], err->msg_parm.i[5],

Просмотреть файл

@ -45,6 +45,18 @@
*/
#ifdef _MSC_VER
#define SNPRINTF(str, n, format, ...) \
_snprintf_s(str, n, _TRUNCATE, format, ##__VA_ARGS__)
#else
#define SNPRINTF snprintf
#endif
#ifndef NO_GETENV
#ifdef _MSC_VER

Просмотреть файл

@ -68,10 +68,13 @@ round_up_pow2(size_t a, size_t b)
* There isn't any really portable way to determine the worst-case alignment
* requirement. This module assumes that the alignment requirement is
* multiples of ALIGN_SIZE.
* By default, we define ALIGN_SIZE as sizeof(double). This is necessary on
* some workstations (where doubles really do need 8-byte alignment) and will
* work fine on nearly everything. If your machine has lesser alignment needs,
* you can save a few bytes by making ALIGN_SIZE smaller.
* By default, we define ALIGN_SIZE as the maximum of sizeof(double) and
* sizeof(void *). This is necessary on some workstations (where doubles
* really do need 8-byte alignment) and will work fine on nearly everything.
* We use the maximum of sizeof(double) and sizeof(void *) since sizeof(double)
* may be insufficient, for example, on CHERI-enabled platforms with 16-byte
* pointers and a 16-byte alignment requirement. If your machine has lesser
* alignment needs, you can save a few bytes by making ALIGN_SIZE smaller.
* The only place I know of where this will NOT work is certain Macintosh
* 680x0 compilers that define double as a 10-byte IEEE extended float.
* Doing 10-byte alignment is counterproductive because longwords won't be
@ -81,7 +84,7 @@ round_up_pow2(size_t a, size_t b)
#ifndef ALIGN_SIZE /* so can override from jconfig.h */
#ifndef WITH_SIMD
#define ALIGN_SIZE sizeof(double)
#define ALIGN_SIZE MAX(sizeof(void *), sizeof(double))
#else
#define ALIGN_SIZE 32 /* Most of the SIMD instructions we support require
16-byte (128-bit) alignment, but AVX2 requires

Просмотреть файл

@ -24,16 +24,6 @@
#include "jversion.h" /* for version message */
#include "jconfigint.h"
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
#ifdef __MWERKS__
#include <SIOUX.h> /* Metrowerks needs this */
#include <console.h> /* ... and this */
#endif
#ifdef THINK_C
#include <console.h> /* Think declares it here */
#endif
#endif
/*
* Argument-parsing code.
@ -520,11 +510,6 @@ main(int argc, char **argv)
JOCTET *icc_profile = NULL;
long icc_len = 0;
/* On Mac, fetch a command line. */
#ifdef USE_CCOMMAND
argc = ccommand(&argv);
#endif
progname = argv[0];
if (progname == NULL || progname[0] == 0)
progname = "jpegtran"; /* in case C library doesn't provide it */

Просмотреть файл

@ -3,7 +3,7 @@ USING THE IJG JPEG LIBRARY
This file was part of the Independent JPEG Group's software:
Copyright (C) 1994-2013, Thomas G. Lane, Guido Vollbeding.
libjpeg-turbo Modifications:
Copyright (C) 2010, 2014-2018, 2020, D. R. Commander.
Copyright (C) 2010, 2014-2018, 2020, 2022, D. R. Commander.
Copyright (C) 2015, Google, Inc.
For conditions of distribution and use, see the accompanying README.ijg file.
@ -840,18 +840,7 @@ is to prepare a library file ("libjpeg.a", or a corresponding name on non-Unix
machines) and reference it at your link step. If you use only half of the
library (only compression or only decompression), only that much code will be
included from the library, unless your linker is hopelessly brain-damaged.
The supplied makefiles build libjpeg.a automatically (see install.txt).
While you can build the JPEG library as a shared library if the whim strikes
you, we don't really recommend it. The trouble with shared libraries is that
at some point you'll probably try to substitute a new version of the library
without recompiling the calling applications. That generally doesn't work
because the parameter struct declarations usually change with each new
version. In other words, the library's API is *not* guaranteed binary
compatible across versions; we only try to ensure source-code compatibility.
(In hindsight, it might have been smarter to hide the parameter structs from
applications and introduce a ton of access functions instead. Too late now,
however.)
The supplied build system builds libjpeg.a automatically.
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
@ -3075,9 +3064,8 @@ BITS_IN_JSAMPLE as 12 rather than 8. Note that this causes JSAMPLE to be
larger than a char, so it affects the surrounding application's image data.
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
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
precisions.
12-bit cjpeg or djpeg. At present, a 12-bit library can handle *only* 12-bit
images, not both precisions.
Note that a 12-bit library always compresses in Huffman optimization mode,
in order to generate valid Huffman tables. This is necessary because our

Просмотреть файл

@ -30,16 +30,6 @@
#include <io.h> /* to declare setmode() */
#endif
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
#ifdef __MWERKS__
#include <SIOUX.h> /* Metrowerks needs this */
#include <console.h> /* ... and this */
#endif
#ifdef THINK_C
#include <console.h> /* Think declares it here */
#endif
#endif
#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
#define READ_BINARY "r"
#else
@ -451,11 +441,6 @@ main(int argc, char **argv)
char *arg;
int verbose = 0, raw = 0;
/* On Mac, fetch a command line. */
#ifdef USE_CCOMMAND
argc = ccommand(&argv);
#endif
progname = argv[0];
if (progname == NULL || progname[0] == 0)
progname = "rdjpgcom"; /* in case C library doesn't provide it */

Просмотреть файл

@ -449,6 +449,9 @@ elseif(CPU_TYPE STREQUAL "loongson" OR CPU_TYPE MATCHES "^mips64")
set(CMAKE_REQUIRED_FLAGS -Wa,-mloongson-mmi,-mloongson-ext)
check_c_source_compiles("
#if !(defined(__mips__) && __mips_isa_rev < 6)
#error Loongson MMI can't work with MIPS Release 6+
#endif
int main(void) {
int c = 0, a = 0, b = 0;
asm (

Просмотреть файл

@ -25,8 +25,6 @@
#include "../../../jsimddct.h"
#include "../../jsimd.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
static unsigned int simd_support = ~0;

Просмотреть файл

@ -25,8 +25,6 @@
#include "../../jsimd.h"
#include "jconfigint.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define JSIMD_FASTLD3 1

Просмотреть файл

@ -23,8 +23,6 @@
#include "../../jsimddct.h"
#include "../jsimd.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
static unsigned int simd_support = ~0;

Просмотреть файл

@ -24,8 +24,6 @@
#include "../../jsimddct.h"
#include "../jsimd.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
static unsigned int simd_support = ~0;

Просмотреть файл

@ -27,11 +27,12 @@
#include "../../jsimddct.h"
#include "../jsimd.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#if defined(__OpenBSD__)
#if defined(__APPLE__)
#include <sys/types.h>
#include <sys/sysctl.h>
#elif defined(__OpenBSD__)
#include <sys/param.h>
#include <sys/sysctl.h>
#include <machine/cpu.h>
@ -121,6 +122,10 @@ init_simd(void)
int bufsize = 1024; /* an initial guess for the line buffer size limit */
#elif defined(__amigaos4__)
uint32 altivec = 0;
#elif defined(__APPLE__)
int mib[2] = { CTL_HW, HW_VECTORUNIT };
int altivec;
size_t len = sizeof(altivec);
#elif defined(__OpenBSD__)
int mib[2] = { CTL_MACHDEP, CPU_ALTIVEC };
int altivec;
@ -134,7 +139,7 @@ init_simd(void)
simd_support = 0;
#if defined(__ALTIVEC__) || defined(__APPLE__)
#if defined(__ALTIVEC__)
simd_support |= JSIMD_ALTIVEC;
#elif defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
while (!parse_proc_cpuinfo(bufsize)) {
@ -146,7 +151,7 @@ init_simd(void)
IExec->GetCPUInfoTags(GCIT_VectorUnit, &altivec, TAG_DONE);
if (altivec == VECTORTYPE_ALTIVEC)
simd_support |= JSIMD_ALTIVEC;
#elif defined(__OpenBSD__)
#elif defined(__APPLE__) || defined(__OpenBSD__)
if (sysctl(mib, 2, &altivec, &len, NULL, 0) == 0 && altivec != 0)
simd_support |= JSIMD_ALTIVEC;
#elif defined(__FreeBSD__)

Просмотреть файл

@ -27,6 +27,7 @@
*/
#include "jinclude.h"
#include <errno.h>
#define CHECK_VALUE(actual, expected, desc) \

Просмотреть файл

@ -107,7 +107,7 @@ static char *formatName(int subsamp, int cs, char *buf)
if (cs == TJCS_YCbCr)
return (char *)subNameLong[subsamp];
else if (cs == TJCS_YCCK || cs == TJCS_CMYK) {
snprintf(buf, 80, "%s %s", csName[cs], subNameLong[subsamp]);
SNPRINTF(buf, 80, "%s %s", csName[cs], subNameLong[subsamp]);
return buf;
} else
return (char *)csName[cs];
@ -120,10 +120,10 @@ static char *sigfig(double val, int figs, char *buf, int len)
int digitsAfterDecimal = figs - (int)ceil(log10(fabs(val)));
if (digitsAfterDecimal < 1)
snprintf(format, 80, "%%.0f");
SNPRINTF(format, 80, "%%.0f");
else
snprintf(format, 80, "%%.%df", digitsAfterDecimal);
snprintf(buf, len, format, val);
SNPRINTF(format, 80, "%%.%df", digitsAfterDecimal);
SNPRINTF(buf, len, format, val);
return buf;
}
@ -160,7 +160,7 @@ static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
unsigned char *dstPtr, *dstPtr2, *yuvBuf = NULL;
if (jpegQual > 0) {
snprintf(qualStr, 13, "_Q%d", jpegQual);
SNPRINTF(qualStr, 13, "_Q%d", jpegQual);
qualStr[12] = 0;
}
@ -262,20 +262,20 @@ static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
if (!doWrite) goto bailout;
if (sf.num != 1 || sf.denom != 1)
snprintf(sizeStr, 24, "%d_%d", sf.num, sf.denom);
SNPRINTF(sizeStr, 24, "%d_%d", sf.num, sf.denom);
else if (tilew != w || tileh != h)
snprintf(sizeStr, 24, "%dx%d", tilew, tileh);
else snprintf(sizeStr, 24, "full");
SNPRINTF(sizeStr, 24, "%dx%d", tilew, tileh);
else SNPRINTF(sizeStr, 24, "full");
if (decompOnly)
snprintf(tempStr, 1024, "%s_%s.%s", fileName, sizeStr, ext);
SNPRINTF(tempStr, 1024, "%s_%s.%s", fileName, sizeStr, ext);
else
snprintf(tempStr, 1024, "%s_%s%s_%s.%s", fileName, subName[subsamp],
SNPRINTF(tempStr, 1024, "%s_%s%s_%s.%s", fileName, subName[subsamp],
qualStr, sizeStr, ext);
if (tjSaveImage(tempStr, dstBuf, scaledw, 0, scaledh, pf, flags) == -1)
THROW_TJG("saving bitmap");
ptr = strrchr(tempStr, '.');
snprintf(ptr, 1024 - (ptr - tempStr), "-err.%s", ext);
SNPRINTF(ptr, 1024 - (ptr - tempStr), "-err.%s", ext);
if (srcBuf && sf.num == 1 && sf.denom == 1) {
if (!quiet) printf("Compression error written to %s.\n", tempStr);
if (subsamp == TJ_GRAYSCALE) {
@ -478,7 +478,7 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
(double)totalJpegSize * 8. / 1000000. * (double)iter / elapsed);
}
if (tilew == w && tileh == h && doWrite) {
snprintf(tempStr, 1024, "%s_%s_Q%d.jpg", fileName, subName[subsamp],
SNPRINTF(tempStr, 1024, "%s_%s_Q%d.jpg", fileName, subName[subsamp],
jpegQual);
if ((file = fopen(tempStr, "wb")) == NULL)
THROW_UNIX("opening reference image");

Просмотреть файл

@ -409,7 +409,7 @@ static void compTest(tjhandle handle, unsigned char **dstBuf,
jpegQual, flags));
}
snprintf(tempStr, 1024, "%s_enc_%s_%s_%s_Q%d.jpg", basename, pfStr, buStr,
SNPRINTF(tempStr, 1024, "%s_enc_%s_%s_%s_Q%d.jpg", basename, pfStr, buStr,
subName[subsamp], jpegQual);
writeJPEG(*dstBuf, *dstSize, tempStr);
printf("Done.\n Result in %s\n", tempStr);
@ -782,7 +782,7 @@ static int doBmpTest(const char *ext, int width, int align, int height, int pf,
THROW("Could not allocate memory");
initBitmap(buf, width, pitch, height, pf, flags);
snprintf(filename, 80, "test_bmp_%s_%d_%s.%s", pixFormatStr[pf], align,
SNPRINTF(filename, 80, "test_bmp_%s_%d_%s.%s", pixFormatStr[pf], align,
(flags & TJFLAG_BOTTOMUP) ? "bu" : "td", ext);
TRY_TJ(tjSaveImage(filename, buf, width, pitch, height, pf, flags));
md5sum = MD5File(filename, md5buf);

Просмотреть файл

@ -1,5 +1,5 @@
/*
* Copyright (C)2011 D. R. Commander. All Rights Reserved.
* Copyright (C)2011, 2022 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -27,9 +27,20 @@
*/
#ifdef _WIN32
#ifndef strcasecmp
#define strcasecmp stricmp
#endif
#ifndef strncasecmp
#define strncasecmp strnicmp
#endif
#endif
#ifdef _MSC_VER
#define SNPRINTF(str, n, format, ...) \
_snprintf_s(str, n, _TRUNCATE, format, ##__VA_ARGS__)
#else
#define SNPRINTF snprintf
#endif
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))

Просмотреть файл

@ -26,8 +26,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <string.h>
#include "turbojpeg.h"
#include "jinclude.h"
#include <jni.h>

Просмотреть файл

@ -32,8 +32,6 @@
/* TurboJPEG/LJT: this implements the TurboJPEG API using libjpeg or
libjpeg-turbo */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <jinclude.h>
#define JPEG_INTERNALS
@ -130,9 +128,9 @@ static void my_progress_monitor(j_common_ptr dinfo)
int scan_no = ((j_decompress_ptr)dinfo)->input_scan_number;
if (scan_no > 500) {
snprintf(myprog->this->errStr, JMSG_LENGTH_MAX,
SNPRINTF(myprog->this->errStr, JMSG_LENGTH_MAX,
"Progressive JPEG image has more than 500 scans");
snprintf(errStr, JMSG_LENGTH_MAX,
SNPRINTF(errStr, JMSG_LENGTH_MAX,
"Progressive JPEG image has more than 500 scans");
myprog->this->isInstanceError = TRUE;
myerr->warning = FALSE;
@ -195,24 +193,24 @@ static int cs2pf[JPEG_NUMCS] = {
};
#define THROWG(m) { \
snprintf(errStr, JMSG_LENGTH_MAX, "%s", m); \
SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s", m); \
retval = -1; goto bailout; \
}
#ifdef _MSC_VER
#define THROW_UNIX(m) { \
char strerrorBuf[80] = { 0 }; \
strerror_s(strerrorBuf, 80, errno); \
snprintf(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, strerrorBuf); \
SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, strerrorBuf); \
retval = -1; goto bailout; \
}
#else
#define THROW_UNIX(m) { \
snprintf(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, strerror(errno)); \
SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, strerror(errno)); \
retval = -1; goto bailout; \
}
#endif
#define THROW(m) { \
snprintf(this->errStr, JMSG_LENGTH_MAX, "%s", m); \
SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "%s", m); \
this->isInstanceError = TRUE; THROWG(m) \
}
@ -227,7 +225,7 @@ static int cs2pf[JPEG_NUMCS] = {
j_decompress_ptr dinfo = NULL; \
\
if (!this) { \
snprintf(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
SNPRINTF(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
return -1; \
} \
cinfo = &this->cinfo; dinfo = &this->dinfo; \
@ -239,7 +237,7 @@ static int cs2pf[JPEG_NUMCS] = {
j_compress_ptr cinfo = NULL; \
\
if (!this) { \
snprintf(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
SNPRINTF(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
return -1; \
} \
cinfo = &this->cinfo; \
@ -251,7 +249,7 @@ static int cs2pf[JPEG_NUMCS] = {
j_decompress_ptr dinfo = NULL; \
\
if (!this) { \
snprintf(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
SNPRINTF(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
return -1; \
} \
dinfo = &this->dinfo; \
@ -539,12 +537,12 @@ DLLEXPORT tjhandle tjInitCompress(void)
tjinstance *this = NULL;
if ((this = (tjinstance *)malloc(sizeof(tjinstance))) == NULL) {
snprintf(errStr, JMSG_LENGTH_MAX,
SNPRINTF(errStr, JMSG_LENGTH_MAX,
"tjInitCompress(): Memory allocation failure");
return NULL;
}
memset(this, 0, sizeof(tjinstance));
snprintf(this->errStr, JMSG_LENGTH_MAX, "No error");
SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "No error");
return _tjInitCompress(this);
}
@ -1213,12 +1211,12 @@ DLLEXPORT tjhandle tjInitDecompress(void)
tjinstance *this;
if ((this = (tjinstance *)malloc(sizeof(tjinstance))) == NULL) {
snprintf(errStr, JMSG_LENGTH_MAX,
SNPRINTF(errStr, JMSG_LENGTH_MAX,
"tjInitDecompress(): Memory allocation failure");
return NULL;
}
memset(this, 0, sizeof(tjinstance));
snprintf(this->errStr, JMSG_LENGTH_MAX, "No error");
SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "No error");
return _tjInitDecompress(this);
}
@ -1245,7 +1243,13 @@ DLLEXPORT int tjDecompressHeader3(tjhandle handle,
}
jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize);
jpeg_read_header(dinfo, TRUE);
/* jpeg_read_header() calls jpeg_abort() and returns JPEG_HEADER_TABLES_ONLY
if the datastream is a tables-only datastream. Since we aren't using a
suspending data source, the only other value it can return is
JPEG_HEADER_OK. */
if (jpeg_read_header(dinfo, FALSE) == JPEG_HEADER_TABLES_ONLY)
return 0;
*width = dinfo->image_width;
*height = dinfo->image_height;
@ -1297,7 +1301,7 @@ DLLEXPORT int tjDecompressHeader(tjhandle handle, unsigned char *jpegBuf,
DLLEXPORT tjscalingfactor *tjGetScalingFactors(int *numscalingfactors)
{
if (numscalingfactors == NULL) {
snprintf(errStr, JMSG_LENGTH_MAX,
SNPRINTF(errStr, JMSG_LENGTH_MAX,
"tjGetScalingFactors(): Invalid argument");
return NULL;
}
@ -1904,12 +1908,12 @@ DLLEXPORT tjhandle tjInitTransform(void)
tjhandle handle = NULL;
if ((this = (tjinstance *)malloc(sizeof(tjinstance))) == NULL) {
snprintf(errStr, JMSG_LENGTH_MAX,
SNPRINTF(errStr, JMSG_LENGTH_MAX,
"tjInitTransform(): Memory allocation failure");
return NULL;
}
memset(this, 0, sizeof(tjinstance));
snprintf(this->errStr, JMSG_LENGTH_MAX, "No error");
SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "No error");
handle = _tjInitCompress(this);
if (!handle) return NULL;
handle = _tjInitDecompress(this);
@ -2000,7 +2004,7 @@ DLLEXPORT int tjTransform(tjhandle handle, const unsigned char *jpegBuf,
if (xinfo[i].crop) {
if ((t[i].r.x % tjMCUWidth[jpegSubsamp]) != 0 ||
(t[i].r.y % tjMCUHeight[jpegSubsamp]) != 0) {
snprintf(this->errStr, JMSG_LENGTH_MAX,
SNPRINTF(this->errStr, JMSG_LENGTH_MAX,
"To crop this JPEG image, x must be a multiple of %d\n"
"and y must be a multiple of %d.\n",
tjMCUWidth[jpegSubsamp], tjMCUHeight[jpegSubsamp]);

Просмотреть файл

@ -1129,27 +1129,38 @@ DLLEXPORT tjhandle tjInitDecompress(void);
/**
* Retrieve information about a JPEG image without decompressing it.
* Retrieve information about a JPEG image without decompressing it, or prime
* the decompressor with quantization and Huffman tables.
*
* @param handle a handle to a TurboJPEG decompressor or transformer instance
*
* @param jpegBuf pointer to a buffer containing a JPEG image
* @param jpegBuf pointer to a buffer containing a JPEG image or an
* "abbreviated table specification" (AKA "tables-only") datastream. Passing a
* tables-only datastream to this function primes the decompressor with
* quantization and Huffman tables that can be used when decompressing
* subsequent "abbreviated image" datastreams. This is useful, for instance,
* when decompressing video streams in which all frames share the same
* quantization and Huffman tables.
*
* @param jpegSize size of the JPEG image (in bytes)
* @param jpegSize size of the JPEG image or tables-only datastream (in bytes)
*
* @param width pointer to an integer variable that will receive the width (in
* pixels) of the JPEG image
* pixels) of the JPEG image. If <tt>jpegBuf</tt> points to a tables-only
* datastream, then <tt>width</tt> is ignored.
*
* @param height pointer to an integer variable that will receive the height
* (in pixels) of the JPEG image
* (in pixels) of the JPEG image. If <tt>jpegBuf</tt> points to a tables-only
* datastream, then <tt>height</tt> is ignored.
*
* @param jpegSubsamp pointer to an integer variable that will receive the
* level of chrominance subsampling used when the JPEG image was compressed
* (see @ref TJSAMP "Chrominance subsampling options".)
* (see @ref TJSAMP "Chrominance subsampling options".) If <tt>jpegBuf</tt>
* points to a tables-only datastream, then <tt>jpegSubsamp</tt> is ignored.
*
* @param jpegColorspace pointer to an integer variable that will receive one
* of the JPEG colorspace constants, indicating the colorspace of the JPEG
* image (see @ref TJCS "JPEG colorspaces".)
* image (see @ref TJCS "JPEG colorspaces".) If <tt>jpegBuf</tt>
* points to a tables-only datastream, then <tt>jpegColorspace</tt> is ignored.
*
* @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
* and #tjGetErrorCode().)

Просмотреть файл

@ -25,7 +25,7 @@ GENERAL USAGE
We provide two programs, cjpeg to compress an image file into JPEG format,
and djpeg to decompress a JPEG file back into a conventional image format.
On Unix-like systems, you say:
On most systems, you say:
cjpeg [switches] [imagefile] >jpegfile
or
djpeg [switches] [jpegfile] >imagefile
@ -34,19 +34,19 @@ named. They always write to standard output (with trace/error messages to
standard error). These conventions are handy for piping images between
programs.
On most non-Unix systems, you say:
If you defined TWO_FILE_COMMANDLINE when compiling the programs, you can
instead say:
cjpeg [switches] imagefile jpegfile
or
djpeg [switches] jpegfile imagefile
i.e., both the input and output files are named on the command line. This
style is a little more foolproof, and it loses no functionality if you don't
have pipes. (You can get this style on Unix too, if you prefer, by defining
TWO_FILE_COMMANDLINE when you compile the programs; see install.txt.)
have pipes.
You can also say:
cjpeg [switches] -outfile jpegfile imagefile
or
djpeg [switches] -outfile imagefile jpegfile
djpeg [switches] -outfile imagefile jpegfile
This syntax works on all systems, so it is useful for scripts.
The currently supported image file formats are: PPM (PBMPLUS color format),
@ -143,8 +143,8 @@ customized) quantization tables can be set with the -qtables option and
assigned to components with the -qslots option (see the "wizard" switches
below.)
JPEG files generated with separate luminance and chrominance quality are
fully compliant with standard JPEG decoders.
JPEG files generated with separate luminance and chrominance quality are fully
compliant with standard JPEG decoders.
CAUTION: For this setting to be useful, be sure to pass an argument of
-sample 1x1 to cjpeg to disable chrominance subsampling. Otherwise, the
@ -218,7 +218,7 @@ Switches for advanced users:
space is needed, an error will occur.
-verbose Enable debug printout. More -v's give more printout.
or -debug Also, version information is printed at startup.
or -debug Also, version information is printed at startup.
The -restart option inserts extra markers that allow a JPEG decoder to
resynchronize after a transmission error. Without restart markers, any damage
@ -462,9 +462,10 @@ quality. However, while the image data is losslessly transformed, metadata
can be removed. See the -copy option for specifics.
jpegtran uses a command line syntax similar to cjpeg or djpeg.
On Unix-like systems, you say:
On most systems, you say:
jpegtran [switches] [inputfile] >outputfile
On most non-Unix systems, you say:
If you defined TWO_FILE_COMMANDLINE when compiling the program, you can instead
say:
jpegtran [switches] inputfile outputfile
where both the input and output files are JPEG files.
@ -644,13 +645,13 @@ file; it does not modify the input file. DO NOT try to overwrite the input
file by directing wrjpgcom's output back into it; on most systems this will
just destroy your file.
The command line syntax for wrjpgcom is similar to cjpeg's. On Unix-like
systems, it is
The command line syntax for wrjpgcom is similar to cjpeg's. On most systems,
it is
wrjpgcom [switches] [inputfilename]
The output file is written to standard output. The input file comes from
the named file, or from standard input if no input file is named.
On most non-Unix systems, the syntax is
If you defined TWO_FILE_COMMANDLINE when compiling the program, the syntax is:
wrjpgcom [switches] inputfilename outputfilename
where both input and output file names must be given explicitly.

Просмотреть файл

@ -28,16 +28,6 @@
#include <io.h> /* to declare setmode() */
#endif
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
#ifdef __MWERKS__
#include <SIOUX.h> /* Metrowerks needs this */
#include <console.h> /* ... and this */
#endif
#ifdef THINK_C
#include <console.h> /* Think declares it here */
#endif
#endif
#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
#define READ_BINARY "r"
#define WRITE_BINARY "w"
@ -415,11 +405,6 @@ main(int argc, char **argv)
unsigned int comment_length = 0;
int marker;
/* On Mac, fetch a command line. */
#ifdef USE_CCOMMAND
argc = ccommand(&argv);
#endif
progname = argv[0];
if (progname == NULL || progname[0] == 0)
progname = "wrjpgcom"; /* in case C library doesn't provide it */