- [CMake](http://www.cmake.org) v2.8.12 or later
-- [NASM](http://www.nasm.us) or [YASM](http://yasm.tortall.net)
+- [NASM](http://www.nasm.us) or [Yasm](http://yasm.tortall.net)
(if building x86 or x86-64 SIMD extensions)
* If using NASM, 2.13 or later is required.
- * If using YASM, 1.2.0 or later is required.
- * If building on macOS, NASM or YASM can be obtained from
+ * If using Yasm, 1.2.0 or later is required.
+ * If building on macOS, NASM or Yasm can be obtained from
[MacPorts](http://www.macports.org/) or [Homebrew](http://brew.sh/).
- NOTE: Currently, if it is desirable to hide the SIMD function symbols in
Mac executables or shared libraries that statically link with
- libjpeg-turbo, then NASM 2.14 or later or YASM must be used when
+ libjpeg-turbo, then NASM 2.14 or later or Yasm must be used when
building libjpeg-turbo.
- * If building on Windows, **nasm.exe**/**yasm.exe** should be in your `PATH`.
- * 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.
-
- The binary RPMs released by the NASM project do not work on older Linux
- systems, such as Red Hat Enterprise Linux 5. On such systems, you can easily
- build and install NASM from a source RPM by downloading one of the SRPMs from
-
- <http://www.nasm.us/pub/nasm/releasebuilds>
-
- and executing the following as root:
-
- ARCH=`uname -m`
- rpmbuild --rebuild nasm-{version}.src.rpm
- rpm -Uvh /usr/src/redhat/RPMS/$ARCH/nasm-{version}.$ARCH.rpm
-
- NOTE: the NASM build will fail if texinfo is not installed.
-
+ * If NASM or Yasm is not in your `PATH`, then you can specify the full path
+ to the assembler by using either the `CMAKE_ASM_NASM_COMPILER` CMake
+ variable or the `ASM_NASM` environment variable. On Windows, use forward
+ 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 RHEL
+ derivatives, which is not enabled by default.
### Un*x Platforms (including Linux, Mac, FreeBSD, Solaris, and Cygwin)
* 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
------------------
Ninja
-----
-In all of the procedures and recipes below, replace `make` with `ninja` and
-`Unix Makefiles` with `Ninja` if using Ninja.
+If using Ninja, then replace `make` or `nmake` with `ninja`, and replace the
+CMake generator (specified with the `-G` option) with `Ninja`, in all of the
+procedures and recipes below.
Build Procedure
endif()
project(libjpeg-turbo C)
-set(VERSION 2.1.2)
+set(VERSION 2.1.4)
+set(COPYRIGHT_YEAR "1991-2022")
string(REPLACE "." ";" VERSION_TRIPLET ${VERSION})
list(GET VERSION_TRIPLET 0 VERSION_MAJOR)
list(GET VERSION_TRIPLET 1 VERSION_MINOR)
message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
+include(cmakescripts/PackageInfo.cmake)
+
# Detect CPU type and whether we're building 64-bit or 32-bit code
math(EXPR BITS "${CMAKE_SIZEOF_VOID_P} * 8")
string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} CMAKE_SYSTEM_PROCESSOR_LC)
# minor SO versions don't change. However, we increase the middle number (the
# SO "age") whenever functions are added to the API.
set(TURBOJPEG_SO_MAJOR_VERSION 0)
-set(TURBOJPEG_SO_VERSION 0.2.0)
+set(TURBOJPEG_SO_AGE 2)
+set(TURBOJPEG_SO_VERSION 0.${TURBOJPEG_SO_AGE}.0)
###############################################################################
endif()
endforeach()
endif()
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /wd4996")
+ add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
endif()
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
endif()
if(UNIX)
- # Check for headers
- check_include_files(locale.h HAVE_LOCALE_H)
- check_include_files(stddef.h HAVE_STDDEF_H)
- check_include_files(stdlib.h HAVE_STDLIB_H)
- check_include_files(sys/types.h NEED_SYS_TYPES_H)
-
- # Check for functions
- include(CheckSymbolExists)
- check_symbol_exists(memset string.h HAVE_MEMSET)
- check_symbol_exists(memcpy string.h HAVE_MEMCPY)
- if(NOT HAVE_MEMSET AND NOT HAVE_MEMCPY)
- set(NEED_BSD_STRINGS 1)
- endif()
-
- # Check for types
- check_type_size("unsigned char" UNSIGNED_CHAR)
- check_type_size("unsigned short" UNSIGNED_SHORT)
-
- # Check for compiler features
- check_c_source_compiles("int main(void) { typedef struct undefined_structure *undef_struct_ptr; undef_struct_ptr ptr = 0; return ptr != 0; }"
- INCOMPLETE_TYPES)
- if(INCOMPLETE_TYPES)
- message(STATUS "Compiler supports pointers to undefined structures.")
- else()
- set(INCOMPLETE_TYPES_BROKEN 1)
- message(STATUS "Compiler does not support pointers to undefined structures.")
- endif()
-
if(CMAKE_CROSSCOMPILING)
set(RIGHT_SHIFT_IS_UNSIGNED 0)
else()
configure_file(jconfig.h.in jconfig.h)
endif()
configure_file(jconfigint.h.in jconfigint.h)
+configure_file(jversion.h.in jversion.h)
if(UNIX)
configure_file(libjpeg.map.in libjpeg.map)
endif()
include_directories(${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
set(TJMAPFILE ${CMAKE_CURRENT_SOURCE_DIR}/turbojpeg-mapfile.jni)
endif()
+ if(MSVC)
+ configure_file(${CMAKE_SOURCE_DIR}/win/turbojpeg.rc.in
+ ${CMAKE_BINARY_DIR}/win/turbojpeg.rc)
+ set(TURBOJPEG_SOURCES ${TURBOJPEG_SOURCES}
+ ${CMAKE_BINARY_DIR}/win/turbojpeg.rc)
+ endif()
add_library(turbojpeg SHARED ${TURBOJPEG_SOURCES})
set_property(TARGET turbojpeg PROPERTY COMPILE_FLAGS
"-DBMP_SUPPORTED -DPPM_SUPPORTED")
add_subdirectory(fuzz)
endif()
+add_executable(strtest strtest.c)
+
add_subdirectory(md5)
if(MSVC_IDE OR XCODE)
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()
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
+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
+=====
+
+### Significant changes relative to 2.1.2
+
+1. Fixed a regression introduced by 2.0 beta1[7] whereby cjpeg compressed PGM
+input files into full-color JPEG images unless the `-grayscale` option was
+used.
+
+2. cjpeg now automatically compresses GIF and 8-bit BMP input files into
+grayscale JPEG images if the input files contain only shades of gray.
+
+3. The build system now enables the intrinsics implementation of the AArch64
+(Arm 64-bit) Neon SIMD extensions by default when using GCC 12 or later.
+
+4. Fixed a segfault that occurred while decompressing a 4:2:0 JPEG image using
+the merged (non-fancy) upsampling algorithms (that is, with
+`cinfo.do_fancy_upsampling` set to `FALSE`) along with `jpeg_crop_scanline()`.
+Specifically, the segfault occurred if the number of bytes remaining in the
+output buffer was less than the number of bytes required to represent one
+uncropped scanline of the output image. For that reason, the issue could only
+be reproduced using the libjpeg API, not using djpeg.
+
+
2.1.2
=====
now produces bitwise-identical results to the unmerged algorithms.
12. The SIMD function symbols for x86[-64]/ELF, MIPS/ELF, macOS/x86[-64] (if
-libjpeg-turbo is built with YASM), and iOS/Arm[64] builds are now private.
+libjpeg-turbo is built with Yasm), and iOS/Arm[64] builds are now private.
This prevents those symbols from being exposed in applications or shared
libraries that link statically with libjpeg-turbo.
### Significant changes relative to 1.2 beta1:
-1. Fixed build issue with YASM on Unix systems (the libjpeg-turbo build system
-was not adding the current directory to the assembler include path, so YASM
+1. Fixed build issue with Yasm on Unix systems (the libjpeg-turbo build system
+was not adding the current directory to the assembler include path, so Yasm
was not able to find jsimdcfg.inc.)
2. Fixed out-of-bounds read in SSE2 SIMD code that occurred when decompressing
8. All legacy VirtualGL code has been re-factored, and this has allowed
libjpeg-turbo, in its entirety, to be re-licensed under a BSD-style license.
-9. libjpeg-turbo can now be built with YASM.
+9. libjpeg-turbo can now be built with Yasm.
10. Added SIMD acceleration for ARM Linux and iOS platforms that support
NEON instructions.
The Modified (3-clause) BSD License
===================================
-Copyright (C)2009-2021 D. R. Commander. All Rights Reserved.<br>
+Copyright (C)2009-2022 D. R. Commander. All Rights Reserved.<br>
Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
Redistribution and use in source and binary forms, with or without
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane.
* libjpeg-turbo Modifications:
- * Copyright (C) 2019, D. R. Commander.
+ * Copyright (C) 2019, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
int scan_no = ((j_decompress_ptr)cinfo)->input_scan_number;
if (scan_no > (int)prog->max_scans) {
- fprintf(stderr, "Scan number %d exceeds maximum scans (%d)\n", scan_no,
+ fprintf(stderr, "Scan number %d exceeds maximum scans (%u)\n", scan_no,
prog->max_scans);
exit(EXIT_FAILURE);
}
-.TH CJPEG 1 "18 November 2021"
+.TH CJPEG 1 "30 November 2021"
.SH NAME
cjpeg \- compress an image file to a JPEG file
.SH SYNOPSIS
100 (best); default is 75. (See below for more info.)
.TP
.B \-grayscale
-Create monochrome JPEG file from color input. Be sure to use this switch when
-compressing a grayscale BMP or GIF file, because
-.B cjpeg
-isn't bright enough to notice whether a BMP or GIF file uses only shades of
-gray. By saying
+Create monochrome JPEG file from color input. By saying
.BR \-grayscale,
you'll get a smaller JPEG file that takes less time to process.
.TP
* Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2003-2011 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2010, 2013-2014, 2017, 2019-2021, D. R. Commander.
+ * Copyright (C) 2010, 2013-2014, 2017, 2019-2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
* works regardless of which command line style is used.
*/
+#ifdef _MSC_VER
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+
#ifdef CJPEG_FUZZER
#define JPEG_INTERNALS
#endif
#include "jversion.h" /* for version message */
#include "jconfigint.h"
-#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
-extern void *malloc(size_t size);
-extern void free(void *ptr);
-#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
-
/* Create the add-on message string table. */
longjmp(myerr->setjmp_buffer, 1);
}
-static void my_emit_message(j_common_ptr cinfo, int msg_level)
+static void my_emit_message_fuzzer(j_common_ptr cinfo, int msg_level)
{
if (msg_level < 0)
cinfo->err->num_warnings++;
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 */
#ifdef CJPEG_FUZZER
jerr.error_exit = my_error_exit;
- jerr.emit_message = my_emit_message;
+ jerr.emit_message = my_emit_message_fuzzer;
if (setjmp(myerr.setjmp_buffer))
HANDLE_ERROR()
#endif
# This file is included from the top-level CMakeLists.txt. We just store it
# here to avoid cluttering up that file.
-set(PKGNAME ${CMAKE_PROJECT_NAME} CACHE STRING
- "Distribution package name (default: ${CMAKE_PROJECT_NAME})")
-set(PKGVENDOR "The ${CMAKE_PROJECT_NAME} Project" CACHE STRING
- "Vendor name to be included in distribution package descriptions (default: The ${CMAKE_PROJECT_NAME} Project)")
-set(PKGURL "http://www.${CMAKE_PROJECT_NAME}.org" CACHE STRING
- "URL of project web site to be included in distribution package descriptions (default: http://www.${CMAKE_PROJECT_NAME}.org)")
-set(PKGEMAIL "information@${CMAKE_PROJECT_NAME}.org" CACHE STRING
- "E-mail of project maintainer to be included in distribution package descriptions (default: information@${CMAKE_PROJECT_NAME}.org")
-set(PKGID "com.${CMAKE_PROJECT_NAME}.${PKGNAME}" CACHE STRING
- "Globally unique package identifier (reverse DNS notation) (default: com.${CMAKE_PROJECT_NAME}.${PKGNAME})")
-
-
###############################################################################
# Linux RPM and DEB
###############################################################################
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
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(
--- /dev/null
+# This file is included from the top-level CMakeLists.txt. We just store it
+# here to avoid cluttering up that file.
+
+set(PKGNAME ${CMAKE_PROJECT_NAME} CACHE STRING
+ "Distribution package name (default: ${CMAKE_PROJECT_NAME})")
+set(PKGVENDOR "The ${CMAKE_PROJECT_NAME} Project" CACHE STRING
+ "Vendor name to be included in distribution package descriptions (default: The ${CMAKE_PROJECT_NAME} Project)")
+set(PKGURL "http://www.${CMAKE_PROJECT_NAME}.org" CACHE STRING
+ "URL of project web site to be included in distribution package descriptions (default: http://www.${CMAKE_PROJECT_NAME}.org)")
+set(PKGEMAIL "information@${CMAKE_PROJECT_NAME}.org" CACHE STRING
+ "E-mail of project maintainer to be included in distribution package descriptions (default: information@${CMAKE_PROJECT_NAME}.org")
+set(PKGID "com.${CMAKE_PROJECT_NAME}.${PKGNAME}" CACHE STRING
+ "Globally unique package identifier (reverse DNS notation) (default: com.${CMAKE_PROJECT_NAME}.${PKGNAME})")
* Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2013-2019 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2010-2011, 2013-2017, 2019-2020, D. R. Commander.
+ * Copyright (C) 2010-2011, 2013-2017, 2019-2020, 2022, D. R. Commander.
* Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
* works regardless of which command line style is used.
*/
+#ifdef _MSC_VER
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include "jversion.h" /* for version message */
#include "jconfigint.h"
-#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare free() */
-extern void free(void *ptr);
-#endif
-
#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. */
#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 */
fprintf(stderr, "%s: memory allocation failure\n", progname);
exit(EXIT_FAILURE);
}
- nbytes = JFREAD(input_file, &inbuffer[insize], INPUT_BUF_SIZE);
+ nbytes = fread(&inbuffer[insize], 1, INPUT_BUF_SIZE, input_file);
if (nbytes < INPUT_BUF_SIZE && ferror(input_file)) {
if (file_index < argc)
fprintf(stderr, "%s: can't read from %s\n", progname,
* that skip_start <= skip_end.
*/
if (skip_end > cinfo.output_height - 1) {
- fprintf(stderr, "%s: skip region exceeds image height %d\n", progname,
+ fprintf(stderr, "%s: skip region exceeds image height %u\n", progname,
cinfo.output_height);
exit(EXIT_FAILURE);
}
}
if ((tmp = jpeg_skip_scanlines(&cinfo, skip_end - skip_start + 1)) !=
skip_end - skip_start + 1) {
- fprintf(stderr, "%s: jpeg_skip_scanlines() returned %d rather than %d\n",
+ fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n",
progname, tmp, skip_end - skip_start + 1);
exit(EXIT_FAILURE);
}
*/
if (crop_x + crop_width > cinfo.output_width ||
crop_y + crop_height > cinfo.output_height) {
- fprintf(stderr, "%s: crop dimensions exceed image dimensions %d x %d\n",
+ fprintf(stderr, "%s: crop dimensions exceed image dimensions %u x %u\n",
progname, cinfo.output_width, cinfo.output_height);
exit(EXIT_FAILURE);
}
/* Process data */
if ((tmp = jpeg_skip_scanlines(&cinfo, crop_y)) != crop_y) {
- fprintf(stderr, "%s: jpeg_skip_scanlines() returned %d rather than %d\n",
+ fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n",
progname, tmp, crop_y);
exit(EXIT_FAILURE);
}
jpeg_skip_scanlines(&cinfo,
cinfo.output_height - crop_y - crop_height)) !=
cinfo.output_height - crop_y - crop_height) {
- fprintf(stderr, "%s: jpeg_skip_scanlines() returned %d rather than %d\n",
+ fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n",
progname, tmp, cinfo.output_height - crop_y - crop_height);
exit(EXIT_FAILURE);
}
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
-  <span id="projectnumber">2.1</span>
+  <span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
-  <span id="projectnumber">2.1</span>
+  <span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
-  <span id="projectnumber">2.1</span>
+  <span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
-  <span id="projectnumber">2.1</span>
+  <span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
-  <span id="projectnumber">2.1</span>
+  <span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>
<tr class="memdesc:ga52300eac3f3d9ef4bab303bc244f62d3"><td class="mdescLeft"> </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"> </td></tr>
<tr class="memitem:ga0595681096bba7199cc6f3533cb25f77"><td class="memItemLeft" align="right" valign="top">DLLEXPORT int </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"> </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"> </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"> </td></tr>
<tr class="memitem:gac3854476006b10787bd128f7ede48057"><td class="memItemLeft" align="right" valign="top">DLLEXPORT <a class="el" href="structtjscalingfactor.html">tjscalingfactor</a> * </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"> </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>
</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>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
-  <span id="projectnumber">2.1</span>
+  <span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
-  <span id="projectnumber">2.1</span>
+  <span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
-  <span id="projectnumber">2.1</span>
+  <span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
-  <span id="projectnumber">2.1</span>
+  <span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">TurboJPEG
-  <span id="projectnumber">2.1</span>
+  <span id="projectnumber">2.1.4</span>
</div>
</td>
</tr>
PROJECT_NAME = TurboJPEG
-PROJECT_NUMBER = 2.1
+PROJECT_NUMBER = 2.1.4
OUTPUT_DIRECTORY = doc/
USE_WINDOWS_ENCODING = NO
OPTIMIZE_OUTPUT_FOR_C = YES
* 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.
*/
"${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)
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
sigFig((double)(w * h * ps) /
(double)totalJpegSize, 4),
quiet == 2 ? "\n" : " ");
- } else if (quiet == 0) {
+ } else {
System.out.format("Transform --> Frame rate: %f fps\n",
1.0 / elapsed);
System.out.format(" Output image size: %d bytes\n",
</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>
<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[] jpegImage,
int 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>
<pre>public void setSourceImage(byte[] jpegImage,
int 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>
/*
- * 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
}
/**
- * 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.
- *
- * @param jpegImage JPEG image buffer. This buffer is not modified.
+ * 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 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)
*/
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1998, Thomas G. Lane.
* Modified 2003-2010 by Guido Vollbeding.
- * It was modified by The libjpeg-turbo Project to include only code relevant
- * to libjpeg-turbo.
+ * libjpeg-turbo Modifications:
+ * Copyright (C) 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
{
struct jpeg_error_mgr *err = cinfo->err;
void *client_data = cinfo->client_data; /* ignore Purify complaint here */
- MEMZERO(cinfo, sizeof(struct jpeg_compress_struct));
+ memset(cinfo, 0, sizeof(struct jpeg_compress_struct));
cinfo->err = err;
cinfo->client_data = client_data;
}
* This file was part of the Independent JPEG Group's software:
* Developed 1997-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2015, 2018, D. R. Commander.
+ * Copyright (C) 2015, 2018, 2021-2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
compptr = cinfo->cur_comp_info[ci];
/* DC needs no table for refinement scan */
if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
- MEMZERO(entropy->dc_stats[compptr->dc_tbl_no], DC_STAT_BINS);
+ memset(entropy->dc_stats[compptr->dc_tbl_no], 0, DC_STAT_BINS);
/* Reset DC predictions to 0 */
entropy->last_dc_val[ci] = 0;
entropy->dc_context[ci] = 0;
}
/* AC needs no table when not present */
if (cinfo->progressive_mode == 0 || cinfo->Se) {
- MEMZERO(entropy->ac_stats[compptr->ac_tbl_no], AC_STAT_BINS);
+ memset(entropy->ac_stats[compptr->ac_tbl_no], 0, AC_STAT_BINS);
}
}
* We are fully adaptive here and need no extra
* statistics gathering pass!
*/
- ERREXIT(cinfo, JERR_NOT_COMPILED);
+ ERREXIT(cinfo, JERR_NOTIMPL);
/* We assume jcmaster.c already validated the progressive scan parameters. */
if (entropy->dc_stats[tbl] == NULL)
entropy->dc_stats[tbl] = (unsigned char *)(*cinfo->mem->alloc_small)
((j_common_ptr)cinfo, JPOOL_IMAGE, DC_STAT_BINS);
- MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS);
+ memset(entropy->dc_stats[tbl], 0, DC_STAT_BINS);
/* Initialize DC predictions to 0 */
entropy->last_dc_val[ci] = 0;
entropy->dc_context[ci] = 0;
if (entropy->ac_stats[tbl] == NULL)
entropy->ac_stats[tbl] = (unsigned char *)(*cinfo->mem->alloc_small)
((j_common_ptr)cinfo, JPOOL_IMAGE, AC_STAT_BINS);
- MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS);
+ memset(entropy->ac_stats[tbl], 0, AC_STAT_BINS);
#ifdef CALCULATE_SPECTRAL_CONDITIONING
if (cinfo->progressive_mode)
/* Section G.1.3.2: Set appropriate arithmetic conditioning value Kx */
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane.
* libjpeg-turbo Modifications:
- * Copyright (C) 2009-2011, 2014-2016, 2018-2021, D. R. Commander.
+ * Copyright (C) 2009-2011, 2014-2016, 2018-2022, D. R. Commander.
* Copyright (C) 2015, Matthieu Darbois.
* Copyright (C) 2018, Matthias Räncker.
* Copyright (C) 2020, Arm Limited.
entropy->dc_count_ptrs[dctbl] = (long *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
257 * sizeof(long));
- MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * sizeof(long));
+ memset(entropy->dc_count_ptrs[dctbl], 0, 257 * sizeof(long));
if (entropy->ac_count_ptrs[actbl] == NULL)
entropy->ac_count_ptrs[actbl] = (long *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
257 * sizeof(long));
- MEMZERO(entropy->ac_count_ptrs[actbl], 257 * sizeof(long));
+ memset(entropy->ac_count_ptrs[actbl], 0, 257 * sizeof(long));
#endif
} else {
/* Compute derived values for Huffman tables */
* this lets us detect duplicate VAL entries here, and later
* allows emit_bits to detect any attempt to emit such symbols.
*/
- MEMZERO(dtbl->ehufco, sizeof(dtbl->ehufco));
- MEMZERO(dtbl->ehufsi, sizeof(dtbl->ehufsi));
+ memset(dtbl->ehufco, 0, sizeof(dtbl->ehufco));
+ memset(dtbl->ehufsi, 0, sizeof(dtbl->ehufsi));
/* This is also a convenient place to check for out-of-range
* and duplicated VAL entries. We allow 0..255 for AC symbols
buffer = _buffer; \
while (bytes > 0) { \
bytestocopy = MIN(bytes, state->free_in_buffer); \
- MEMCOPY(state->next_output_byte, buffer, bytestocopy); \
+ memcpy(state->next_output_byte, buffer, bytestocopy); \
state->next_output_byte += bytestocopy; \
buffer += bytestocopy; \
state->free_in_buffer -= bytestocopy; \
/* This algorithm is explained in section K.2 of the JPEG standard */
- MEMZERO(bits, sizeof(bits));
- MEMZERO(codesize, sizeof(codesize));
+ memset(bits, 0, sizeof(bits));
+ memset(codesize, 0, sizeof(codesize));
for (i = 0; i < 257; i++)
others[i] = -1; /* init links to empty */
bits[i]--;
/* Return final symbol counts (only for lengths 0..16) */
- MEMCOPY(htbl->bits, bits, sizeof(htbl->bits));
+ memcpy(htbl->bits, bits, sizeof(htbl->bits));
/* 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 important not to apply jpeg_gen_optimal_table more than once
* per table, because it clobbers the input frequency counts!
*/
- MEMZERO(did_dc, sizeof(did_dc));
- MEMZERO(did_ac, sizeof(did_ac));
+ memset(did_dc, 0, sizeof(did_dc));
+ memset(did_ac, 0, sizeof(did_ac));
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci];
#define BITS_IN_JSAMPLE @BITS_IN_JSAMPLE@ /* use 8 or 12 */
-/* Define to 1 if you have the <locale.h> header file. */
-#cmakedefine HAVE_LOCALE_H 1
-
-/* Define to 1 if you have the <stddef.h> header file. */
-#cmakedefine HAVE_STDDEF_H 1
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#cmakedefine HAVE_STDLIB_H 1
-
-/* Define if you need to include <sys/types.h> to get size_t. */
-#cmakedefine NEED_SYS_TYPES_H 1
-
-/* Define if you have BSD-like bzero and bcopy in <strings.h> rather than
- memset/memcpy in <string.h>. */
-#cmakedefine NEED_BSD_STRINGS 1
-
-/* Define to 1 if the system has the type `unsigned char'. */
-#cmakedefine HAVE_UNSIGNED_CHAR 1
-
-/* Define to 1 if the system has the type `unsigned short'. */
-#cmakedefine HAVE_UNSIGNED_SHORT 1
-
-/* Compiler does not support pointers to undefined structures. */
-#cmakedefine INCOMPLETE_TYPES_BROKEN 1
-
/* Define if your (broken) compiler shifts signed values as if they were
unsigned. */
#cmakedefine RIGHT_SHIFT_IS_UNSIGNED 1
-
-/* Define to empty if `const' does not conform to ANSI C. */
-/* #undef const */
-
-/* Define to `unsigned int' if <sys/types.h> does not define. */
-/* #undef size_t */
* #define the symbol if yes, #undef it if no.
*/
-/* Does your compiler support the declaration "unsigned char" ?
- * How about "unsigned short" ?
- */
-#define HAVE_UNSIGNED_CHAR
-#define HAVE_UNSIGNED_SHORT
-
-/* Define "void" as "char" if your compiler doesn't know about type void.
- * NOTE: be sure to define void such that "void *" represents the most general
- * pointer type, e.g., that returned by malloc().
- */
-/* #define void char */
-
-/* Define "const" as empty if your compiler doesn't know the "const" keyword.
- */
-/* #define const */
-
-/* Define this if your system has an ANSI-conforming <stddef.h> file.
- */
-#define HAVE_STDDEF_H
-
-/* Define this if your system has an ANSI-conforming <stdlib.h> file.
- */
-#define HAVE_STDLIB_H
-
-/* Define this if your system does not have an ANSI/SysV <string.h>,
- * but does have a BSD-style <strings.h>.
- */
-#undef NEED_BSD_STRINGS
-
-/* Define this if your system does not provide typedef size_t in any of the
- * ANSI-standard places (stddef.h, stdlib.h, or stdio.h), but places it in
- * <sys/types.h> instead.
- */
-#undef NEED_SYS_TYPES_H
-
-/* 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
- * and pseudo-ANSI compilers get confused. To keep one of these bozos happy,
- * define INCOMPLETE_TYPES_BROKEN. This is not recommended unless you
- * actually get "missing structure definition" warnings or errors while
- * compiling the JPEG code.
- */
-#undef INCOMPLETE_TYPES_BROKEN
-
/* Define "boolean" as unsigned char, not int, on Windows systems.
*/
#ifdef _WIN32
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1995-1997, Thomas G. Lane.
* libjpeg-turbo Modifications:
- * Copyright (C) 2011, 2015, 2018, 2021, D. R. Commander.
+ * Copyright (C) 2011, 2015, 2018, 2021-2022, D. R. Commander.
* Copyright (C) 2016, 2018, Matthieu Darbois.
* Copyright (C) 2020, Arm Limited.
* Copyright (C) 2021, Alex Richardson.
entropy->count_ptrs[tbl] = (long *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
257 * sizeof(long));
- MEMZERO(entropy->count_ptrs[tbl], 257 * sizeof(long));
+ memset(entropy->count_ptrs[tbl], 0, 257 * sizeof(long));
} else {
/* Compute derived values for Huffman table */
/* We may do this more than once for a table, but it's not expensive */
continue; \
/* For a negative coef, want temp2 = bitwise complement of abs(coef) */ \
temp2 ^= temp; \
- values[k] = temp; \
- values[k + DCTSIZE2] = temp2; \
+ values[k] = (JCOEF)temp; \
+ values[k + DCTSIZE2] = (JCOEF)temp2; \
zerobits |= ((size_t)1U) << k; \
} \
}
/* It's important not to apply jpeg_gen_optimal_table more than once
* per table, because it clobbers the input frequency counts!
*/
- MEMZERO(did, sizeof(did));
+ memset(did, 0, sizeof(did));
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci];
*
* This file is part of the Independent JPEG Group's software:
* Copyright (C) 1994-1996, Thomas G. Lane.
- * It was modified by The libjpeg-turbo Project to include only code relevant
- * to libjpeg-turbo.
+ * libjpeg-turbo Modifications:
+ * Copyright (C) 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
cinfo->max_h_samp_factor) / compptr->h_samp_factor),
(JDIMENSION)(3 * rgroup_height));
/* Copy true buffer row pointers into the middle of the fake row array */
- MEMCOPY(fake_buffer + rgroup_height, true_buffer,
- 3 * rgroup_height * sizeof(JSAMPROW));
+ memcpy(fake_buffer + rgroup_height, true_buffer,
+ 3 * rgroup_height * sizeof(JSAMPROW));
/* Fill in the above and below wraparound pointers */
for (i = 0; i < rgroup_height; i++) {
fake_buffer[i] = true_buffer[2 * rgroup_height + i];
* Copyright (C) 1995-1998, Thomas G. Lane.
* Modified 2000-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2020, D. R. Commander.
+ * Copyright (C) 2020, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
qtblptr = &dstinfo->quant_tbl_ptrs[tblno];
if (*qtblptr == NULL)
*qtblptr = jpeg_alloc_quant_table((j_common_ptr)dstinfo);
- MEMCOPY((*qtblptr)->quantval, srcinfo->quant_tbl_ptrs[tblno]->quantval,
- sizeof((*qtblptr)->quantval));
+ memcpy((*qtblptr)->quantval, srcinfo->quant_tbl_ptrs[tblno]->quantval,
+ sizeof((*qtblptr)->quantval));
(*qtblptr)->sent_table = FALSE;
}
}
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1998, Thomas G. Lane.
* libjpeg-turbo Modifications:
- * Copyright (C) 2016, D. R. Commander.
+ * Copyright (C) 2016, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
{
struct jpeg_error_mgr *err = cinfo->err;
void *client_data = cinfo->client_data; /* ignore Purify complaint here */
- MEMZERO(cinfo, sizeof(struct jpeg_decompress_struct));
+ memset(cinfo, 0, sizeof(struct jpeg_decompress_struct));
cinfo->err = err;
cinfo->client_data = client_data;
}
cinfo->master = (struct jpeg_decomp_master *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
sizeof(my_decomp_master));
- MEMZERO(cinfo->master, sizeof(my_decomp_master));
+ memset(cinfo->master, 0, sizeof(my_decomp_master));
}
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
- * Copyright (C) 2010, 2015-2020, D. R. Commander.
+ * Copyright (C) 2010, 2015-2020, 2022, D. R. Commander.
* Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
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)
*/
*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.
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;
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);
* 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;
* This file was part of the Independent JPEG Group's software:
* Developed 1997-2015 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2015-2020, D. R. Commander.
+ * Copyright (C) 2015-2020, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci];
if (!cinfo->progressive_mode || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
- MEMZERO(entropy->dc_stats[compptr->dc_tbl_no], DC_STAT_BINS);
+ memset(entropy->dc_stats[compptr->dc_tbl_no], 0, DC_STAT_BINS);
/* Reset DC predictions to 0 */
entropy->last_dc_val[ci] = 0;
entropy->dc_context[ci] = 0;
}
if (!cinfo->progressive_mode || cinfo->Ss) {
- MEMZERO(entropy->ac_stats[compptr->ac_tbl_no], AC_STAT_BINS);
+ memset(entropy->ac_stats[compptr->ac_tbl_no], 0, AC_STAT_BINS);
}
}
if (*thiscoef) { /* previously nonzero coef */
if (arith_decode(cinfo, st + 2)) {
if (*thiscoef < 0)
- *thiscoef += m1;
+ *thiscoef += (JCOEF)m1;
else
- *thiscoef += p1;
+ *thiscoef += (JCOEF)p1;
}
break;
}
if (arith_decode(cinfo, st + 1)) { /* newly nonzero coef */
if (arith_decode(cinfo, entropy->fixed_bin))
- *thiscoef = m1;
+ *thiscoef = (JCOEF)m1;
else
- *thiscoef = p1;
+ *thiscoef = (JCOEF)p1;
break;
}
st += 3; k++;
/* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.
* This ought to be an error condition, but we make it a warning.
*/
- if (cinfo->Ss != 0 || cinfo->Ah != 0 || cinfo->Al != 0 ||
- (cinfo->Se < DCTSIZE2 && cinfo->Se != DCTSIZE2 - 1))
+ if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2 - 1 ||
+ cinfo->Ah != 0 || cinfo->Al != 0)
WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
/* Select MCU decoding routine */
entropy->pub.decode_mcu = decode_mcu;
if (entropy->dc_stats[tbl] == NULL)
entropy->dc_stats[tbl] = (unsigned char *)(*cinfo->mem->alloc_small)
((j_common_ptr)cinfo, JPOOL_IMAGE, DC_STAT_BINS);
- MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS);
+ memset(entropy->dc_stats[tbl], 0, DC_STAT_BINS);
/* Initialize DC predictions to 0 */
entropy->last_dc_val[ci] = 0;
entropy->dc_context[ci] = 0;
if (entropy->ac_stats[tbl] == NULL)
entropy->ac_stats[tbl] = (unsigned char *)(*cinfo->mem->alloc_small)
((j_common_ptr)cinfo, JPOOL_IMAGE, AC_STAT_BINS);
- MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS);
+ memset(entropy->ac_stats[tbl], 0, AC_STAT_BINS);
}
}
* Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2009-2012 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2011, 2014, 2016, 2019, D. R. Commander.
+ * Copyright (C) 2011, 2014, 2016, 2019, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
#include "jpeglib.h"
#include "jerror.h"
-#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
-extern void *malloc(size_t size);
-extern void free(void *ptr);
-#endif
void jpeg_mem_dest_tj(j_compress_ptr cinfo, unsigned char **outbuffer,
unsigned long *outsize, boolean alloc);
if (nextbuffer == NULL)
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
- MEMCOPY(nextbuffer, dest->buffer, dest->bufsize);
+ memcpy(nextbuffer, dest->buffer, dest->bufsize);
free(dest->newbuffer);
* Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2009-2012 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2013, 2016, D. R. Commander.
+ * Copyright (C) 2013, 2016, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
#include "jpeglib.h"
#include "jerror.h"
-#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
-extern void *malloc(size_t size);
-extern void free(void *ptr);
-#endif
-
/* Expanded data destination object for stdio output */
{
my_dest_ptr dest = (my_dest_ptr)cinfo->dest;
- if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) !=
+ if (fwrite(dest->buffer, 1, OUTPUT_BUF_SIZE, dest->outfile) !=
(size_t)OUTPUT_BUF_SIZE)
ERREXIT(cinfo, JERR_FILE_WRITE);
if (nextbuffer == NULL)
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
- MEMCOPY(nextbuffer, dest->buffer, dest->bufsize);
+ memcpy(nextbuffer, dest->buffer, dest->bufsize);
free(dest->newbuffer);
/* Write any data remaining in the buffer */
if (datacount > 0) {
- if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
+ if (fwrite(dest->buffer, 1, datacount, dest->outfile) != datacount)
ERREXIT(cinfo, JERR_FILE_WRITE);
}
fflush(dest->outfile);
* Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2009-2011 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2013, 2016, D. R. Commander.
+ * Copyright (C) 2013, 2016, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
my_src_ptr src = (my_src_ptr)cinfo->src;
size_t nbytes;
- nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
+ nbytes = fread(src->buffer, 1, INPUT_BUF_SIZE, src->infile);
if (nbytes <= 0) {
if (src->start_of_file) /* Treat empty input file as fatal error */
* 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.
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) {
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
* Modified 2002-2010 by Guido Vollbeding.
* libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
- * Copyright (C) 2010, 2015, D. R. Commander.
+ * Copyright (C) 2010, 2015, 2022, D. R. Commander.
* Copyright (C) 2013, MIPS Technologies, Inc., California.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
compptr->dct_table =
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(multiplier_table));
- MEMZERO(compptr->dct_table, sizeof(multiplier_table));
+ memset(compptr->dct_table, 0, sizeof(multiplier_table));
/* Mark multiplier table not yet set up for any method */
idct->cur_method[ci] = -1;
}
#include "jpeglib.h"
#include "jerror.h"
-#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc() */
-extern void *malloc(size_t size);
-#endif
-
#define ICC_MARKER (JPEG_APP0 + 2) /* JPEG marker code for ICC */
#define ICC_OVERHEAD_LEN 14 /* size of non-profile data in APP2 */
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane.
* libjpeg-turbo Modifications:
- * Copyright (C) 2010, 2016, 2018, D. R. Commander.
+ * Copyright (C) 2010, 2016, 2018, 2022, D. R. Commander.
* Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
qtbl = (JQUANT_TBL *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(JQUANT_TBL));
- MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], sizeof(JQUANT_TBL));
+ memcpy(qtbl, cinfo->quant_tbl_ptrs[qtblno], sizeof(JQUANT_TBL));
compptr->quant_table = qtbl;
}
}
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1998, Thomas G. Lane.
* libjpeg-turbo Modifications:
- * Copyright (C) 2012, 2015, D. R. Commander.
+ * Copyright (C) 2012, 2015, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
for (i = 0; i < count; i++)
INPUT_BYTE(cinfo, huffval[i], return FALSE);
- MEMZERO(&huffval[count], (256 - count) * sizeof(UINT8));
+ memset(&huffval[count], 0, (256 - count) * sizeof(UINT8));
length -= count;
if (*htblptr == NULL)
*htblptr = jpeg_alloc_huff_table((j_common_ptr)cinfo);
- MEMCOPY((*htblptr)->bits, bits, sizeof((*htblptr)->bits));
- MEMCOPY((*htblptr)->huffval, huffval, sizeof((*htblptr)->huffval));
+ memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits));
+ memcpy((*htblptr)->huffval, huffval, sizeof((*htblptr)->huffval));
}
if (length != 0)
* Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2002-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2009-2011, 2016, 2019, D. R. Commander.
+ * Copyright (C) 2009-2011, 2016, 2019, 2022, D. R. Commander.
* Copyright (C) 2013, Linaro Limited.
* Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg
table += (MAXJSAMPLE + 1); /* allow negative subscripts of simple table */
cinfo->sample_range_limit = table;
/* First segment of "simple" table: limit[x] = 0 for x < 0 */
- MEMZERO(table - (MAXJSAMPLE + 1), (MAXJSAMPLE + 1) * sizeof(JSAMPLE));
+ memset(table - (MAXJSAMPLE + 1), 0, (MAXJSAMPLE + 1) * sizeof(JSAMPLE));
/* Main part of "simple" table: limit[x] = x */
for (i = 0; i <= MAXJSAMPLE; i++)
table[i] = (JSAMPLE)i;
for (i = CENTERJSAMPLE; i < 2 * (MAXJSAMPLE + 1); i++)
table[i] = MAXJSAMPLE;
/* Second half of post-IDCT table */
- MEMZERO(table + (2 * (MAXJSAMPLE + 1)),
- (2 * (MAXJSAMPLE + 1) - CENTERJSAMPLE) * sizeof(JSAMPLE));
- MEMCOPY(table + (4 * (MAXJSAMPLE + 1) - CENTERJSAMPLE),
- cinfo->sample_range_limit, CENTERJSAMPLE * sizeof(JSAMPLE));
+ memset(table + (2 * (MAXJSAMPLE + 1)), 0,
+ (2 * (MAXJSAMPLE + 1) - CENTERJSAMPLE) * sizeof(JSAMPLE));
+ memcpy(table + (4 * (MAXJSAMPLE + 1) - CENTERJSAMPLE),
+ cinfo->sample_range_limit, CENTERJSAMPLE * sizeof(JSAMPLE));
}
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1995-1997, Thomas G. Lane.
* libjpeg-turbo Modifications:
- * Copyright (C) 2015-2016, 2018-2021, D. R. Commander.
+ * Copyright (C) 2015-2016, 2018-2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
if (GET_BITS(1)) {
if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
if (*thiscoef >= 0)
- *thiscoef += p1;
+ *thiscoef += (JCOEF)p1;
else
- *thiscoef += m1;
+ *thiscoef += (JCOEF)m1;
}
}
} else {
if (GET_BITS(1)) {
if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
if (*thiscoef >= 0)
- *thiscoef += p1;
+ *thiscoef += (JCOEF)p1;
else
- *thiscoef += m1;
+ *thiscoef += (JCOEF)m1;
}
}
}
*
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1998, Thomas G. Lane.
- * It was modified by The libjpeg-turbo Project to include only code relevant
- * to libjpeg-turbo.
+ * libjpeg-turbo Modifications:
+ * Copyright (C) 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
/* Format the message into the passed buffer */
if (isstring)
- sprintf(buffer, msgtext, err->msg_parm.s);
+ SNPRINTF(buffer, JMSG_LENGTH_MAX, msgtext, err->msg_parm.s);
else
- sprintf(buffer, 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],
- err->msg_parm.i[6], err->msg_parm.i[7]);
+ 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],
+ err->msg_parm.i[6], err->msg_parm.i[7]);
}
* Copyright (C) 1994-1997, Thomas G. Lane.
* Modified 1997-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2014, 2017, D. R. Commander.
+ * Copyright (C) 2014, 2017, 2021-2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
"Cannot transcode due to multiple use of quantization table %d")
JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
-JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
+JMESSAGE(JERR_NOTIMPL, "Requested features are incompatible")
JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
#if JPEG_LIB_VERSION >= 70
JMESSAGE(JERR_NO_ARITH_TABLE, "Arithmetic table 0x%02x was not defined")
#define ERREXITS(cinfo, code, str) \
((cinfo)->err->msg_code = (code), \
strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
+ (cinfo)->err->msg_parm.s[JMSG_STR_PARM_MAX - 1] = '\0', \
(*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo)))
#define MAKESTMT(stuff) do { stuff } while (0)
#define TRACEMSS(cinfo, lvl, code, str) \
((cinfo)->err->msg_code = (code), \
strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
+ (cinfo)->err->msg_parm.s[JMSG_STR_PARM_MAX - 1] = '\0', \
(*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)))
#endif /* JERROR_H */
*
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1994, Thomas G. Lane.
- * It was modified by The libjpeg-turbo Project to include only code relevant
- * to libjpeg-turbo.
+ * libjpeg-turbo Modifications:
+ * Copyright (C) 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
* JPEG library. Most applications need only include jpeglib.h.
*/
+#ifndef __JINCLUDE_H__
+#define __JINCLUDE_H__
/* Include auto-config file to find out which system include files we need. */
#include "jconfig.h" /* auto configuration options */
+#include "jconfigint.h"
#define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
/*
- * We need the NULL macro and size_t typedef.
- * On an ANSI-conforming system it is sufficient to include <stddef.h>.
- * Otherwise, we get them from <stdlib.h> or <stdio.h>; we may have to
- * pull in <sys/types.h> as well.
* Note that the core JPEG library does not require <stdio.h>;
* only the default error handler and data source/destination modules do.
* But we must pull it in because of the references to FILE in jpeglib.h.
* You can remove those references if you want to compile without <stdio.h>.
*/
-#ifdef HAVE_STDDEF_H
#include <stddef.h>
-#endif
-
-#ifdef HAVE_STDLIB_H
#include <stdlib.h>
-#endif
-
-#ifdef NEED_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
#include <stdio.h>
+#include <string.h>
/*
- * We need memory copying and zeroing functions, plus strncpy().
- * ANSI and System V implementations declare these in <string.h>.
- * BSD doesn't have the mem() functions, but it does have bcopy()/bzero().
- * Some systems may declare memset and memcpy in <memory.h>.
- *
- * NOTE: we assume the size parameters to these functions are of type size_t.
- * Change the casts in these macros if not!
+ * These macros/inline functions facilitate using Microsoft's "safe string"
+ * functions with Visual Studio builds without the need to scatter #ifdefs
+ * throughout the code base.
*/
-#ifdef NEED_BSD_STRINGS
-#include <strings.h>
-#define MEMZERO(target, size) \
- bzero((void *)(target), (size_t)(size))
-#define MEMCOPY(dest, src, size) \
- bcopy((const void *)(src), (void *)(dest), (size_t)(size))
+#ifdef _MSC_VER
-#else /* not BSD, assume ANSI/SysV string lib */
+#define SNPRINTF(str, n, format, ...) \
+ _snprintf_s(str, n, _TRUNCATE, format, ##__VA_ARGS__)
-#include <string.h>
-#define MEMZERO(target, size) \
- memset((void *)(target), 0, (size_t)(size))
-#define MEMCOPY(dest, src, size) \
- memcpy((void *)(dest), (const void *)(src), (size_t)(size))
+#else
+
+#define SNPRINTF snprintf
#endif
-/*
- * The modules that use fread() and fwrite() always invoke them through
- * these macros. On some systems you may need to twiddle the argument casts.
- * CAUTION: argument order is different from underlying functions!
+
+#ifndef NO_GETENV
+
+#ifdef _MSC_VER
+
+static INLINE int GETENV_S(char *buffer, size_t buffer_size, const char *name)
+{
+ size_t required_size;
+
+ return (int)getenv_s(&required_size, buffer, buffer_size, name);
+}
+
+#else /* _MSC_VER */
+
+#include <errno.h>
+
+/* This provides a similar interface to the Microsoft/C11 getenv_s() function,
+ * but other than parameter validation, it has no advantages over getenv().
*/
-#define JFREAD(file, buf, sizeofbuf) \
- ((size_t)fread((void *)(buf), (size_t)1, (size_t)(sizeofbuf), (file)))
-#define JFWRITE(file, buf, sizeofbuf) \
- ((size_t)fwrite((const void *)(buf), (size_t)1, (size_t)(sizeofbuf), (file)))
+static INLINE int GETENV_S(char *buffer, size_t buffer_size, const char *name)
+{
+ char *env;
+
+ if (!buffer) {
+ if (buffer_size == 0)
+ return 0;
+ else
+ return (errno = EINVAL);
+ }
+ if (buffer_size == 0)
+ return (errno = EINVAL);
+ if (!name) {
+ *buffer = 0;
+ return 0;
+ }
+
+ env = getenv(name);
+ if (!env)
+ {
+ *buffer = 0;
+ return 0;
+ }
+
+ if (strlen(env) + 1 > buffer_size) {
+ *buffer = 0;
+ return ERANGE;
+ }
+
+ strncpy(buffer, env, buffer_size);
+
+ return 0;
+}
+
+#endif /* _MSC_VER */
+
+#endif /* NO_GETENV */
+
+
+#ifndef NO_PUTENV
+
+#ifdef _WIN32
+
+#define PUTENV_S(name, value) _putenv_s(name, value)
+
+#else
+
+/* This provides a similar interface to the Microsoft _putenv_s() function, but
+ * other than parameter validation, it has no advantages over setenv().
+ */
+
+static INLINE int PUTENV_S(const char *name, const char *value)
+{
+ if (!name || !value)
+ return (errno = EINVAL);
+
+ setenv(name, value, 1);
+
+ return errno;
+}
+
+#endif /* _WIN32 */
+
+#endif /* NO_PUTENV */
+
+
+#endif /* JINCLUDE_H */
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane.
* libjpeg-turbo Modifications:
- * Copyright (C) 2016, 2021, D. R. Commander.
+ * Copyright (C) 2016, 2021-2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
#endif
#include <limits.h>
-#ifndef NO_GETENV
-#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
-extern char *getenv(const char *name);
-#endif
-#endif
-
LOCAL(size_t)
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
#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
*/
#ifndef NO_GETENV
{
- char *memenv;
+ char memenv[30] = { 0 };
- if ((memenv = getenv("JPEGMEM")) != NULL) {
+ if (!GETENV_S(memenv, 30, "JPEGMEM") && strlen(memenv) > 0) {
char ch = 'x';
+#ifdef _MSC_VER
+ if (sscanf_s(memenv, "%ld%c", &max_to_use, &ch, 1) > 0) {
+#else
if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
+#endif
if (ch == 'm' || ch == 'M')
max_to_use *= 1000L;
mem->pub.max_memory_to_use = max_to_use * 1000L;
#include "jpeglib.h"
#include "jmemsys.h" /* import the system-dependent declarations */
-#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
-extern void *malloc(size_t size);
-extern void free(void *ptr);
-#endif
-
/*
* Memory allocation and freeing are controlled by the regular library
/* UINT16 must hold at least the values 0..65535. */
-#ifdef HAVE_UNSIGNED_SHORT
typedef unsigned short UINT16;
-#else /* not HAVE_UNSIGNED_SHORT */
-typedef unsigned int UINT16;
-#endif /* HAVE_UNSIGNED_SHORT */
/* INT16 must hold at least the values -32768..32767. */
/* Arithmetic coding probability estimation tables in jaricom.c */
extern const JLONG jpeg_aritab[];
-
-/* Suppress undefined-structure complaints if necessary. */
-
-#ifdef INCOMPLETE_TYPES_BROKEN
-#ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
-struct jvirt_sarray_control { long dummy; };
-struct jvirt_barray_control { long dummy; };
-#endif
-#endif /* INCOMPLETE_TYPES_BROKEN */
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1995-2019, Thomas G. Lane, Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2010, 2014, 2017, 2019-2021, D. R. Commander.
+ * Copyright (C) 2010, 2014, 2017, 2019-2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
* provides some lossless and sort-of-lossless transformations of JPEG data.
*/
+#ifdef _MSC_VER
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include "transupp.h" /* Support routines for jpegtran */
#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.
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 */
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1998, Thomas G. Lane.
* libjpeg-turbo Modifications:
- * Copyright (C) 2013, D. R. Commander.
+ * Copyright (C) 2013, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
return;
/* Copy the number-of-symbols-of-each-code-length counts */
- MEMCOPY((*htblptr)->bits, bits, sizeof((*htblptr)->bits));
+ memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits));
/* 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
if (nsymbols < 1 || nsymbols > 256)
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
- MEMCOPY((*htblptr)->huffval, val, nsymbols * sizeof(UINT8));
- MEMZERO(&((*htblptr)->huffval[nsymbols]), (256 - nsymbols) * sizeof(UINT8));
+ memcpy((*htblptr)->huffval, val, nsymbols * sizeof(UINT8));
+ memset(&((*htblptr)->huffval[nsymbols]), 0,
+ (256 - nsymbols) * sizeof(UINT8));
/* Initialize sent_table FALSE so table will be written to JPEG file. */
(*htblptr)->sent_table = FALSE;
*
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1996, Thomas G. Lane.
- * It was modified by The libjpeg-turbo Project to include only code
- * relevant to libjpeg-turbo.
+ * libjpeg-turbo Modifications:
+ * Copyright (C) 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
for (row = num_rows; row > 0; row--) {
inptr = *input_array++;
outptr = *output_array++;
- MEMCOPY(outptr, inptr, count);
+ memcpy(outptr, inptr, count);
}
}
JDIMENSION num_blocks)
/* Copy a row of coefficient blocks from one place to another. */
{
- MEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * sizeof(JCOEF)));
+ memcpy(output_row, input_row, num_blocks * (DCTSIZE2 * sizeof(JCOEF)));
}
/* Zero out a chunk of memory. */
/* This might be sample-array data, block-array data, or alloc_large data. */
{
- MEMZERO(target, bytestozero);
+ memset(target, 0, bytestozero);
}
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2010, 2012-2021, D. R. Commander.
+ * Copyright (C) 2010, 2012-2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
*/
#define JCOPYRIGHT \
- "Copyright (C) 2009-2021 D. R. Commander\n" \
+ "Copyright (C) 2009-2022 D. R. Commander\n" \
"Copyright (C) 2015, 2020 Google, Inc.\n" \
"Copyright (C) 2019-2020 Arm Limited\n" \
"Copyright (C) 2015-2016, 2018 Matthieu Darbois\n" \
"Copyright (C) 1991-2020 Thomas G. Lane, Guido Vollbeding"
#define JCOPYRIGHT_SHORT \
- "Copyright (C) 1991-2021 The libjpeg-turbo Project and many others"
+ "Copyright (C) @COPYRIGHT_YEAR@ The libjpeg-turbo Project and many others"
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.
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
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
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
* libjpeg-turbo Modifications:
- * Copyright (C)2016, 2018-2019 D. R. Commander. All Rights Reserved.
+ * Copyright (C)2016, 2018-2019, 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:
* ----------------------------------------------------------------------------
*/
+#ifdef _MSC_VER
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
* Modified 2009-2017 by Guido Vollbeding.
* libjpeg-turbo Modifications:
* Modified 2011 by Siarhei Siamashka.
- * Copyright (C) 2015, 2017-2018, 2021, D. R. Commander.
+ * Copyright (C) 2015, 2017-2018, 2021-2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
#define ReadOK(file, buffer, len) \
- (JFREAD(file, buffer, len) == ((size_t)(len)))
+ (fread(buffer, 1, len, file) == ((size_t)(len)))
static int alpha_index[JPEG_NUMCS] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
break;
}
- if (sinfo->cinfo->in_color_space == JCS_UNKNOWN && gray)
+ if ((sinfo->cinfo->in_color_space == JCS_UNKNOWN ||
+ sinfo->cinfo->in_color_space == JCS_RGB) && gray)
sinfo->cinfo->in_color_space = JCS_GRAYSCALE;
if (sinfo->cinfo->in_color_space == JCS_GRAYSCALE && !gray)
*/
outptr = source->pub.buffer[0];
if (cinfo->in_color_space == JCS_EXT_BGR) {
- MEMCOPY(outptr, inptr, source->row_width);
+ memcpy(outptr, inptr, source->row_width);
} else if (cinfo->in_color_space == JCS_CMYK) {
for (col = cinfo->image_width; col > 0; col--) {
JSAMPLE b = *inptr++, g = *inptr++, r = *inptr++;
outptr = source->pub.buffer[0];
if (cinfo->in_color_space == JCS_EXT_BGRX ||
cinfo->in_color_space == JCS_EXT_BGRA) {
- MEMCOPY(outptr, inptr, source->row_width);
+ memcpy(outptr, inptr, source->row_width);
} else if (cinfo->in_color_space == JCS_CMYK) {
for (col = cinfo->image_width; col > 0; col--) {
JSAMPLE b = *inptr++, g = *inptr++, r = *inptr++;
* Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2019 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2021, D. R. Commander.
+ * Copyright (C) 2021-2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
#define ReadOK(file, buffer, len) \
- (JFREAD(file, buffer, len) == ((size_t)(len)))
+ (fread(buffer, 1, len, file) == ((size_t)(len)))
#define MAXCOLORMAPSIZE 256 /* max # of colors in a GIF colormap */
ReadColorMap(gif_source_ptr sinfo, int cmaplen, JSAMPARRAY cmap)
/* Read a GIF colormap */
{
- int i;
+ int i, gray = 1;
for (i = 0; i < cmaplen; i++) {
#if BITS_IN_JSAMPLE == 8
cmap[CM_RED][i] = (JSAMPLE)UPSCALE(ReadByte(sinfo));
cmap[CM_GREEN][i] = (JSAMPLE)UPSCALE(ReadByte(sinfo));
cmap[CM_BLUE][i] = (JSAMPLE)UPSCALE(ReadByte(sinfo));
+ if (cmap[CM_RED][i] != cmap[CM_GREEN][i] ||
+ cmap[CM_GREEN][i] != cmap[CM_BLUE][i])
+ gray = 0;
+ }
+
+ if (sinfo->cinfo->in_color_space == JCS_RGB && gray) {
+ sinfo->cinfo->in_color_space = JCS_GRAYSCALE;
+ sinfo->cinfo->input_components = 1;
}
}
source->pub.get_pixel_rows = get_pixel_rows;
}
+ if (cinfo->in_color_space != JCS_GRAYSCALE) {
+ cinfo->in_color_space = JCS_RGB;
+ cinfo->input_components = NUMCOLORS;
+ }
+
/* Create compressor input buffer. */
source->pub.buffer = (*cinfo->mem->alloc_sarray)
- ((j_common_ptr)cinfo, JPOOL_IMAGE, (JDIMENSION)width * NUMCOLORS,
- (JDIMENSION)1);
+ ((j_common_ptr)cinfo, JPOOL_IMAGE,
+ (JDIMENSION)width * cinfo->input_components, (JDIMENSION)1);
source->pub.buffer_height = 1;
/* Pad colormap for safety. */
}
/* Return info about the image. */
- cinfo->in_color_space = JCS_RGB;
- cinfo->input_components = NUMCOLORS;
cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */
cinfo->image_width = width;
cinfo->image_height = height;
register JSAMPARRAY colormap = source->colormap;
ptr = source->pub.buffer[0];
- for (col = cinfo->image_width; col > 0; col--) {
- c = LZWReadByte(source);
- *ptr++ = colormap[CM_RED][c];
- *ptr++ = colormap[CM_GREEN][c];
- *ptr++ = colormap[CM_BLUE][c];
+ if (cinfo->in_color_space == JCS_GRAYSCALE) {
+ for (col = cinfo->image_width; col > 0; col--) {
+ c = LZWReadByte(source);
+ *ptr++ = colormap[CM_RED][c];
+ }
+ } else {
+ for (col = cinfo->image_width; col > 0; col--) {
+ c = LZWReadByte(source);
+ *ptr++ = colormap[CM_RED][c];
+ *ptr++ = colormap[CM_GREEN][c];
+ *ptr++ = colormap[CM_BLUE][c];
+ }
}
return 1;
}
FALSE);
/* Scan the row, expand colormap, and output */
ptr = source->pub.buffer[0];
- for (col = cinfo->image_width; col > 0; col--) {
- c = *sptr++;
- *ptr++ = colormap[CM_RED][c];
- *ptr++ = colormap[CM_GREEN][c];
- *ptr++ = colormap[CM_BLUE][c];
+ if (cinfo->in_color_space == JCS_GRAYSCALE) {
+ for (col = cinfo->image_width; col > 0; col--) {
+ c = *sptr++;
+ *ptr++ = colormap[CM_RED][c];
+ }
+ } else {
+ for (col = cinfo->image_width; col > 0; col--) {
+ c = *sptr++;
+ *ptr++ = colormap[CM_RED][c];
+ *ptr++ = colormap[CM_GREEN][c];
+ *ptr++ = colormap[CM_BLUE][c];
+ }
}
source->cur_row_number++; /* for next time */
return 1;
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1997, Thomas G. Lane.
* Modified 2009 by Bill Allombert, Guido Vollbeding.
- * It was modified by The libjpeg-turbo Project to include only code relevant
- * to libjpeg-turbo.
+ * libjpeg-turbo Modifications:
+ * Copyright (C) 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
* JPEG markers.
*/
+#ifdef _MSC_VER
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+
#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */
#include "jinclude.h" /* get auto-config symbols, <stdio.h> */
-#ifdef HAVE_LOCALE_H
#include <locale.h> /* Bill Allombert: use locale for isprint */
-#endif
#include <ctype.h> /* to declare isupper(), tolower() */
#ifdef USE_SETMODE
#include <fcntl.h> /* to declare setmode()'s parameter macros */
#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
int lastch = 0;
/* Bill Allombert: set locale properly for isprint */
-#ifdef HAVE_LOCALE_H
setlocale(LC_CTYPE, "");
-#endif
/* Get the marker parameter length count */
length = read_2_bytes();
} else if (isprint(ch)) {
putc(ch, stdout);
} else {
- printf("\\%03o", ch);
+ printf("\\%03o", (unsigned int)ch);
}
lastch = ch;
length--;
printf("\n");
/* Bill Allombert: revert to C locale */
-#ifdef HAVE_LOCALE_H
setlocale(LC_CTYPE, "C");
-#endif
}
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 */
* Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2009 by Bill Allombert, Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2015-2017, 2020-2021, D. R. Commander.
+ * Copyright (C) 2015-2017, 2020-2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
#define ReadOK(file, buffer, len) \
- (JFREAD(file, buffer, len) == ((size_t)(len)))
+ (fread(buffer, 1, len, file) == ((size_t)(len)))
static int alpha_index[JPEG_NUMCS] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
ptr = source->pub.buffer[0];
if (maxval == MAXJSAMPLE) {
if (aindex >= 0)
- GRAY_RGB_READ_LOOP(read_pbm_integer(cinfo, infile, maxval),
+ GRAY_RGB_READ_LOOP((JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
ptr[aindex] = 0xFF;)
else
- GRAY_RGB_READ_LOOP(read_pbm_integer(cinfo, infile, maxval),)
+ GRAY_RGB_READ_LOOP((JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
} else {
if (aindex >= 0)
GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
ptr[aindex] = 0xFF;)
else
- GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],)
+ GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
}
return 1;
}
ptr = source->pub.buffer[0];
if (maxval == MAXJSAMPLE) {
for (col = cinfo->image_width; col > 0; col--) {
- JSAMPLE gray = read_pbm_integer(cinfo, infile, maxval);
+ JSAMPLE gray = (JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
ptr = source->pub.buffer[0];
if (maxval == MAXJSAMPLE) {
if (aindex >= 0)
- RGB_READ_LOOP(read_pbm_integer(cinfo, infile, maxval),
+ RGB_READ_LOOP((JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
ptr[aindex] = 0xFF;)
else
- RGB_READ_LOOP(read_pbm_integer(cinfo, infile, maxval),)
+ RGB_READ_LOOP((JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
} else {
if (aindex >= 0)
RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
ptr[aindex] = 0xFF;)
else
- RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],)
+ RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
}
return 1;
}
ptr = source->pub.buffer[0];
if (maxval == MAXJSAMPLE) {
for (col = cinfo->image_width; col > 0; col--) {
- JSAMPLE r = read_pbm_integer(cinfo, infile, maxval);
- JSAMPLE g = read_pbm_integer(cinfo, infile, maxval);
- JSAMPLE b = read_pbm_integer(cinfo, infile, maxval);
+ JSAMPLE r = (JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
+ JSAMPLE g = (JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
+ JSAMPLE b = (JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
if (aindex >= 0)
GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = 0xFF;)
else
- GRAY_RGB_READ_LOOP(*bufferptr++,)
+ GRAY_RGB_READ_LOOP(*bufferptr++, {})
} else {
if (aindex >= 0)
GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], ptr[aindex] = 0xFF;)
else
- GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],)
+ GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
}
return 1;
}
if (aindex >= 0)
RGB_READ_LOOP(*bufferptr++, ptr[aindex] = 0xFF;)
else
- RGB_READ_LOOP(*bufferptr++,)
+ RGB_READ_LOOP(*bufferptr++, {})
} else {
if (aindex >= 0)
RGB_READ_LOOP(rescale[UCH(*bufferptr++)], ptr[aindex] = 0xFF;)
else
- RGB_READ_LOOP(rescale[UCH(*bufferptr++)],)
+ RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
}
return 1;
}
switch (c) {
case '2': /* it's a text-format PGM file */
- if (cinfo->in_color_space == JCS_UNKNOWN)
+ if (cinfo->in_color_space == JCS_UNKNOWN ||
+ cinfo->in_color_space == JCS_RGB)
cinfo->in_color_space = JCS_GRAYSCALE;
TRACEMS2(cinfo, 1, JTRC_PGM_TEXT, w, h);
if (cinfo->in_color_space == JCS_GRAYSCALE)
break;
case '5': /* it's a raw-format PGM file */
- if (cinfo->in_color_space == JCS_UNKNOWN)
+ if (cinfo->in_color_space == JCS_UNKNOWN ||
+ cinfo->in_color_space == JCS_RGB)
cinfo->in_color_space = JCS_GRAYSCALE;
TRACEMS2(cinfo, 1, JTRC_PGM, w, h);
if (maxval > 255) {
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(size_t)(((long)MAX(maxval, 255) + 1L) *
sizeof(JSAMPLE)));
- MEMZERO(source->rescale, (size_t)(((long)MAX(maxval, 255) + 1L) *
- sizeof(JSAMPLE)));
+ memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
+ sizeof(JSAMPLE)));
half_maxval = maxval / 2;
for (val = 0; val <= (long)maxval; val++) {
/* The multiplication here must be done in 32 bits to avoid overflow */
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
- * Copyright (C) 2010, 2018, D. R. Commander.
+ * Copyright (C) 2010, 2018, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
* -sample HxV[,HxV,...] Set component sampling factors
*/
+#ifdef _MSC_VER
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include <ctype.h> /* to declare isdigit(), isspace() */
scanptr = (jpeg_scan_info *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
scanno * sizeof(jpeg_scan_info));
- MEMCOPY(scanptr, scans, scanno * sizeof(jpeg_scan_info));
+ memcpy(scanptr, scans, scanno * sizeof(jpeg_scan_info));
cinfo->scan_info = scanptr;
cinfo->num_scans = scanno;
}
* Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2017 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2018, 2021, D. R. Commander.
+ * Copyright (C) 2018, 2021-2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
#define ReadOK(file, buffer, len) \
- (JFREAD(file, buffer, len) == ((size_t)(len)))
+ (fread(buffer, 1, len, file) == ((size_t)(len)))
/* Private version of data source object */
set(DEFFILE ../win/jpeg${SO_MAJOR_VERSION}.def)
endif()
endif()
+if(MSVC)
+ configure_file(${CMAKE_SOURCE_DIR}/win/jpeg.rc.in
+ ${CMAKE_BINARY_DIR}/win/jpeg.rc)
+ set(JPEG_SRCS ${JPEG_SRCS} ${CMAKE_BINARY_DIR}/win/jpeg.rc)
+endif()
add_library(jpeg SHARED ${JPEG_SRCS} ${DEFFILE} $<TARGET_OBJECTS:simd>
${SIMD_OBJS})
# environment variable. This should happen automatically, but unfortunately
# enable_language(ASM_NASM) doesn't parse the ASM_NASM environment variable
# until after CMAKE_ASM_NASM_COMPILER has been populated with the results of
-# searching for NASM or YASM in the PATH.
+# searching for NASM or Yasm in the PATH.
if(NOT DEFINED CMAKE_ASM_NASM_COMPILER AND DEFINED ENV{ASM_NASM})
set(CMAKE_ASM_NASM_COMPILER $ENV{ASM_NASM})
endif()
endif()
endif()
-include(CheckSymbolExists)
if(BITS EQUAL 32)
set(CMAKE_REQUIRED_FLAGS "-mfpu=neon ${SOFTFP_FLAG}")
check_c_source_compiles("
return()
endif()
endif()
-check_symbol_exists(vld1_s16_x3 arm_neon.h HAVE_VLD1_S16_X3)
-check_symbol_exists(vld1_u16_x2 arm_neon.h HAVE_VLD1_U16_X2)
-check_symbol_exists(vld1q_u8_x4 arm_neon.h HAVE_VLD1Q_U8_X4)
+check_c_source_compiles("
+ #include <arm_neon.h>
+ int main(int argc, char **argv) {
+ int16_t input[] = {
+ (int16_t)argc, (int16_t)argc, (int16_t)argc, (int16_t)argc,
+ (int16_t)argc, (int16_t)argc, (int16_t)argc, (int16_t)argc,
+ (int16_t)argc, (int16_t)argc, (int16_t)argc, (int16_t)argc
+ };
+ int16x4x3_t output = vld1_s16_x3(input);
+ vst3_s16(input, output);
+ return (int)input[0];
+ }" HAVE_VLD1_S16_X3)
+check_c_source_compiles("
+ #include <arm_neon.h>
+ int main(int argc, char **argv) {
+ uint16_t input[] = {
+ (uint16_t)argc, (uint16_t)argc, (uint16_t)argc, (uint16_t)argc,
+ (uint16_t)argc, (uint16_t)argc, (uint16_t)argc, (uint16_t)argc
+ };
+ uint16x4x2_t output = vld1_u16_x2(input);
+ vst2_u16(input, output);
+ return (int)input[0];
+ }" HAVE_VLD1_U16_X2)
+check_c_source_compiles("
+ #include <arm_neon.h>
+ int main(int argc, char **argv) {
+ uint8_t input[] = {
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc,
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc,
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc,
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc,
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc,
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc,
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc,
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc,
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc,
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc,
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc,
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc,
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc,
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc,
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc,
+ (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc
+ };
+ uint8x16x4_t output = vld1q_u8_x4(input);
+ vst4q_u8(input, output);
+ return (int)input[0];
+ }" HAVE_VLD1Q_U8_X4)
if(BITS EQUAL 32)
unset(CMAKE_REQUIRED_FLAGS)
endif()
configure_file(arm/neon-compat.h.in arm/neon-compat.h @ONLY)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/arm)
-# GCC (as of this writing) and some older versions of Clang do not have a full
-# or optimal set of Neon intrinsics, so for performance reasons, when using
-# those compilers, we default to using the older GAS implementation of the Neon
-# SIMD extensions for certain algorithms. The presence or absence of the three
-# intrinsics we tested above is a reasonable proxy for this. We always default
-# to using the full Neon intrinsics implementation when building for macOS or
-# iOS, to avoid the need for gas-preprocessor.
-if((HAVE_VLD1_S16_X3 AND HAVE_VLD1_U16_X2 AND HAVE_VLD1Q_U8_X4) OR APPLE)
+# GCC 11 and earlier and some older versions of Clang do not have a full or
+# optimal set of Neon intrinsics, so for performance reasons, when using those
+# compilers, we default to using the older GAS implementation of the Neon SIMD
+# extensions for certain algorithms. The presence or absence of the three
+# intrinsics we tested above is a reasonable proxy for this, except with GCC 10
+# and 11.
+if((HAVE_VLD1_S16_X3 AND HAVE_VLD1_U16_X2 AND HAVE_VLD1Q_U8_X4 AND
+ (NOT CMAKE_COMPILER_IS_GNUCC OR
+ CMAKE_C_COMPILER_VERSION VERSION_EQUAL 12.0.0 OR
+ CMAKE_C_COMPILER_VERSION VERSION_GREATER 12.0.0)))
set(DEFAULT_NEON_INTRINSICS 1)
else()
set(DEFAULT_NEON_INTRINSICS 0)
option(NEON_INTRINSICS
"Because GCC (as of this writing) and some older versions of Clang do not have a full or optimal set of Neon intrinsics, for performance reasons, the default when building libjpeg-turbo with those compilers is to continue using the older GAS implementation of the Neon SIMD extensions for certain algorithms. Setting this option forces the full Neon intrinsics implementation to be used with all compilers. Unsetting this option forces the hybrid GAS/intrinsics implementation to be used with all compilers."
${DEFAULT_NEON_INTRINSICS})
+if(NOT NEON_INTRINSICS)
+ enable_language(ASM)
+
+ set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ASM_FLAGS}")
+
+ # Test whether gas-preprocessor.pl would be needed to build the GAS
+ # implementation of the Neon SIMD extensions. If so, then automatically
+ # enable the full Neon intrinsics implementation.
+ if(CPU_TYPE STREQUAL "arm")
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gastest.S "
+ .text
+ .fpu neon
+ .arch armv7a
+ .object_arch armv4
+ .arm
+ pld [r0]
+ vmovn.u16 d0, q0")
+ else()
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gastest.S "
+ .text
+ MYVAR .req x0
+ movi v0.16b, #100
+ mov MYVAR, #100
+ .unreq MYVAR")
+ endif()
+ separate_arguments(CMAKE_ASM_FLAGS_SEP UNIX_COMMAND "${CMAKE_ASM_FLAGS}")
+ execute_process(COMMAND ${CMAKE_ASM_COMPILER} ${CMAKE_ASM_FLAGS_SEP}
+ -x assembler-with-cpp -c ${CMAKE_CURRENT_BINARY_DIR}/gastest.S
+ RESULT_VARIABLE RESULT OUTPUT_VARIABLE OUTPUT ERROR_VARIABLE ERROR)
+ if(NOT RESULT EQUAL 0)
+ message(WARNING "GAS appears to be broken. Using the full Neon SIMD intrinsics implementation.")
+ set(NEON_INTRINSICS 1 CACHE INTERNAL "" FORCE)
+ endif()
+endif()
boolean_number(NEON_INTRINSICS PARENT_SCOPE)
if(NEON_INTRINSICS)
add_definitions(-DNEON_INTRINSICS)
set_source_files_properties(${SIMD_SOURCES} COMPILE_FLAGS "-mfpu=neon ${SOFTFP_FLAG}")
endif()
if(NOT NEON_INTRINSICS)
- enable_language(ASM)
-
- set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ASM_FLAGS}")
-
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UC)
set(EFFECTIVE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${CMAKE_ASM_FLAGS_${CMAKE_BUILD_TYPE_UC}}")
message(STATUS "CMAKE_ASM_FLAGS = ${EFFECTIVE_ASM_FLAGS}")
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 (
*
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2011, Nokia Corporation and/or its subsidiary(-ies).
- * Copyright (C) 2009-2011, 2013-2014, 2016, 2018, D. R. Commander.
+ * Copyright (C) 2009-2011, 2013-2014, 2016, 2018, 2022, D. R. Commander.
* Copyright (C) 2015-2016, 2018, Matthieu Darbois.
* Copyright (C) 2019, Google LLC.
* Copyright (C) 2020, Arm Limited.
#include "../../../jsimddct.h"
#include "../../jsimd.h"
-#include <stdio.h>
-#include <string.h>
#include <ctype.h>
static unsigned int simd_support = ~0;
init_simd(void)
{
#ifndef NO_GETENV
- char *env = NULL;
+ char env[2] = { 0 };
#endif
#if !defined(__ARM_NEON__) && (defined(__linux__) || defined(ANDROID) || defined(__ANDROID__))
int bufsize = 1024; /* an initial guess for the line buffer size limit */
#ifndef NO_GETENV
/* Force different settings through environment variables */
- env = getenv("JSIMD_FORCENEON");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FORCENEON") && !strcmp(env, "1"))
simd_support = JSIMD_NEON;
- env = getenv("JSIMD_FORCENONE");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FORCENONE") && !strcmp(env, "1"))
simd_support = 0;
- env = getenv("JSIMD_NOHUFFENC");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_NOHUFFENC") && !strcmp(env, "1"))
simd_huffman = 0;
#endif
}
* jchuff-neon.c - Huffman entropy encoding (64-bit Arm Neon)
*
* Copyright (C) 2020-2021, Arm Limited. All Rights Reserved.
- * Copyright (C) 2020, D. R. Commander. All Rights Reserved.
+ * Copyright (C) 2020, 2022, D. R. Commander. All Rights Reserved.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
14, 15, 30, 31, 44, 45, 46, 47
};
+/* The AArch64 implementation of the FLUSH() macro triggers a UBSan misaligned
+ * address warning because the macro sometimes writes a 64-bit value to a
+ * non-64-bit-aligned address. That behavior is technically undefined per
+ * the C specification, but it is supported by the AArch64 architecture and
+ * compilers.
+ */
+#if defined(__has_feature)
+#if __has_feature(undefined_behavior_sanitizer)
+__attribute__((no_sanitize("alignment")))
+#endif
+#endif
JOCTET *jsimd_huff_encode_one_block_neon(void *state, JOCTET *buffer,
JCOEFPTR block, int last_dc_val,
c_derived_tbl *dctbl,
7), row6, 5);
/* DCT block is now in zig-zag order; start Huffman encoding process. */
- int16x8_t abs_row0 = vabsq_s16(row0);
- int16x8_t abs_row1 = vabsq_s16(row1);
- int16x8_t abs_row2 = vabsq_s16(row2);
- int16x8_t abs_row3 = vabsq_s16(row3);
- int16x8_t abs_row4 = vabsq_s16(row4);
- int16x8_t abs_row5 = vabsq_s16(row5);
- int16x8_t abs_row6 = vabsq_s16(row6);
- int16x8_t abs_row7 = vabsq_s16(row7);
-
- /* For negative coeffs: diff = abs(coeff) -1 = ~abs(coeff) */
- uint16x8_t row0_diff =
- vreinterpretq_u16_s16(veorq_s16(abs_row0, vshrq_n_s16(row0, 15)));
- uint16x8_t row1_diff =
- vreinterpretq_u16_s16(veorq_s16(abs_row1, vshrq_n_s16(row1, 15)));
- uint16x8_t row2_diff =
- vreinterpretq_u16_s16(veorq_s16(abs_row2, vshrq_n_s16(row2, 15)));
- uint16x8_t row3_diff =
- vreinterpretq_u16_s16(veorq_s16(abs_row3, vshrq_n_s16(row3, 15)));
- uint16x8_t row4_diff =
- vreinterpretq_u16_s16(veorq_s16(abs_row4, vshrq_n_s16(row4, 15)));
- uint16x8_t row5_diff =
- vreinterpretq_u16_s16(veorq_s16(abs_row5, vshrq_n_s16(row5, 15)));
- uint16x8_t row6_diff =
- vreinterpretq_u16_s16(veorq_s16(abs_row6, vshrq_n_s16(row6, 15)));
- uint16x8_t row7_diff =
- vreinterpretq_u16_s16(veorq_s16(abs_row7, vshrq_n_s16(row7, 15)));
/* Construct bitmap to accelerate encoding of AC coefficients. A set bit
* means that the corresponding coefficient != 0.
*/
- uint8x8_t abs_row0_gt0 = vmovn_u16(vcgtq_u16(vreinterpretq_u16_s16(abs_row0),
- vdupq_n_u16(0)));
- uint8x8_t abs_row1_gt0 = vmovn_u16(vcgtq_u16(vreinterpretq_u16_s16(abs_row1),
- vdupq_n_u16(0)));
- uint8x8_t abs_row2_gt0 = vmovn_u16(vcgtq_u16(vreinterpretq_u16_s16(abs_row2),
- vdupq_n_u16(0)));
- uint8x8_t abs_row3_gt0 = vmovn_u16(vcgtq_u16(vreinterpretq_u16_s16(abs_row3),
- vdupq_n_u16(0)));
- uint8x8_t abs_row4_gt0 = vmovn_u16(vcgtq_u16(vreinterpretq_u16_s16(abs_row4),
- vdupq_n_u16(0)));
- uint8x8_t abs_row5_gt0 = vmovn_u16(vcgtq_u16(vreinterpretq_u16_s16(abs_row5),
- vdupq_n_u16(0)));
- uint8x8_t abs_row6_gt0 = vmovn_u16(vcgtq_u16(vreinterpretq_u16_s16(abs_row6),
- vdupq_n_u16(0)));
- uint8x8_t abs_row7_gt0 = vmovn_u16(vcgtq_u16(vreinterpretq_u16_s16(abs_row7),
- vdupq_n_u16(0)));
+ uint16x8_t row0_ne_0 = vtstq_s16(row0, row0);
+ uint16x8_t row1_ne_0 = vtstq_s16(row1, row1);
+ uint16x8_t row2_ne_0 = vtstq_s16(row2, row2);
+ uint16x8_t row3_ne_0 = vtstq_s16(row3, row3);
+ uint16x8_t row4_ne_0 = vtstq_s16(row4, row4);
+ uint16x8_t row5_ne_0 = vtstq_s16(row5, row5);
+ uint16x8_t row6_ne_0 = vtstq_s16(row6, row6);
+ uint16x8_t row7_ne_0 = vtstq_s16(row7, row7);
+
+ uint8x16_t row10_ne_0 = vuzp1q_u8(vreinterpretq_u8_u16(row1_ne_0),
+ vreinterpretq_u8_u16(row0_ne_0));
+ uint8x16_t row32_ne_0 = vuzp1q_u8(vreinterpretq_u8_u16(row3_ne_0),
+ vreinterpretq_u8_u16(row2_ne_0));
+ uint8x16_t row54_ne_0 = vuzp1q_u8(vreinterpretq_u8_u16(row5_ne_0),
+ vreinterpretq_u8_u16(row4_ne_0));
+ uint8x16_t row76_ne_0 = vuzp1q_u8(vreinterpretq_u8_u16(row7_ne_0),
+ vreinterpretq_u8_u16(row6_ne_0));
/* { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 } */
- const uint8x8_t bitmap_mask =
- vreinterpret_u8_u64(vmov_n_u64(0x0102040810204080));
+ const uint8x16_t bitmap_mask =
+ vreinterpretq_u8_u64(vdupq_n_u64(0x0102040810204080));
- abs_row0_gt0 = vand_u8(abs_row0_gt0, bitmap_mask);
- abs_row1_gt0 = vand_u8(abs_row1_gt0, bitmap_mask);
- abs_row2_gt0 = vand_u8(abs_row2_gt0, bitmap_mask);
- abs_row3_gt0 = vand_u8(abs_row3_gt0, bitmap_mask);
- abs_row4_gt0 = vand_u8(abs_row4_gt0, bitmap_mask);
- abs_row5_gt0 = vand_u8(abs_row5_gt0, bitmap_mask);
- abs_row6_gt0 = vand_u8(abs_row6_gt0, bitmap_mask);
- abs_row7_gt0 = vand_u8(abs_row7_gt0, bitmap_mask);
+ uint8x16_t bitmap_rows_10 = vandq_u8(row10_ne_0, bitmap_mask);
+ uint8x16_t bitmap_rows_32 = vandq_u8(row32_ne_0, bitmap_mask);
+ uint8x16_t bitmap_rows_54 = vandq_u8(row54_ne_0, bitmap_mask);
+ uint8x16_t bitmap_rows_76 = vandq_u8(row76_ne_0, bitmap_mask);
- uint8x8_t bitmap_rows_10 = vpadd_u8(abs_row1_gt0, abs_row0_gt0);
- uint8x8_t bitmap_rows_32 = vpadd_u8(abs_row3_gt0, abs_row2_gt0);
- uint8x8_t bitmap_rows_54 = vpadd_u8(abs_row5_gt0, abs_row4_gt0);
- uint8x8_t bitmap_rows_76 = vpadd_u8(abs_row7_gt0, abs_row6_gt0);
- uint8x8_t bitmap_rows_3210 = vpadd_u8(bitmap_rows_32, bitmap_rows_10);
- uint8x8_t bitmap_rows_7654 = vpadd_u8(bitmap_rows_76, bitmap_rows_54);
- uint8x8_t bitmap_all = vpadd_u8(bitmap_rows_7654, bitmap_rows_3210);
+ uint8x16_t bitmap_rows_3210 = vpaddq_u8(bitmap_rows_32, bitmap_rows_10);
+ uint8x16_t bitmap_rows_7654 = vpaddq_u8(bitmap_rows_76, bitmap_rows_54);
+ uint8x16_t bitmap_rows_76543210 = vpaddq_u8(bitmap_rows_7654,
+ bitmap_rows_3210);
+ uint8x8_t bitmap_all = vpadd_u8(vget_low_u8(bitmap_rows_76543210),
+ vget_high_u8(bitmap_rows_76543210));
/* Shift left to remove DC bit. */
bitmap_all =
/* Encode DC coefficient. */
+ /* For negative coeffs: diff = abs(coeff) -1 = ~abs(coeff) */
+ int16x8_t abs_row0 = vabsq_s16(row0);
+ int16x8_t row0_lz = vclzq_s16(abs_row0);
+ uint16x8_t row0_mask = vshlq_u16(vcltzq_s16(row0), vnegq_s16(row0_lz));
+ uint16x8_t row0_diff = veorq_u16(vreinterpretq_u16_s16(abs_row0), row0_mask);
/* Find nbits required to specify sign and amplitude of coefficient. */
-#if defined(_MSC_VER) && !defined(__clang__)
- unsigned int lz = BUILTIN_CLZ(vgetq_lane_s16(abs_row0, 0));
-#else
- unsigned int lz;
- __asm__("clz %w0, %w1" : "=r"(lz) : "r"(vgetq_lane_s16(abs_row0, 0)));
-#endif
- unsigned int nbits = 32 - lz;
+ unsigned int lz = vgetq_lane_u16(vreinterpretq_u16_s16(row0_lz), 0);
+ unsigned int nbits = 16 - lz;
/* Emit Huffman-coded symbol and additional diff bits. */
- unsigned int diff = (unsigned int)(vgetq_lane_u16(row0_diff, 0) << lz) >> lz;
+ unsigned int diff = vgetq_lane_u16(row0_diff, 0);
PUT_CODE(dctbl->ehufco[nbits], dctbl->ehufsi[nbits], diff)
/* Encode AC coefficients. */
/* The most efficient method of computing nbits and diff depends on the
* number of non-zero coefficients. If the bitmap is not too sparse (> 8
- * non-zero AC coefficients), it is beneficial to use Neon; else we compute
- * nbits and diff on demand using scalar code.
+ * non-zero AC coefficients), it is beneficial to do all of the work using
+ * Neon; else we do some of the work using Neon and the rest on demand using
+ * scalar code.
*/
if (non_zero_coefficients > 8) {
uint8_t block_nbits[DCTSIZE2];
- int16x8_t row0_lz = vclzq_s16(abs_row0);
+ int16x8_t abs_row1 = vabsq_s16(row1);
+ int16x8_t abs_row2 = vabsq_s16(row2);
+ int16x8_t abs_row3 = vabsq_s16(row3);
+ int16x8_t abs_row4 = vabsq_s16(row4);
+ int16x8_t abs_row5 = vabsq_s16(row5);
+ int16x8_t abs_row6 = vabsq_s16(row6);
+ int16x8_t abs_row7 = vabsq_s16(row7);
int16x8_t row1_lz = vclzq_s16(abs_row1);
int16x8_t row2_lz = vclzq_s16(abs_row2);
int16x8_t row3_lz = vclzq_s16(abs_row3);
int16x8_t row5_lz = vclzq_s16(abs_row5);
int16x8_t row6_lz = vclzq_s16(abs_row6);
int16x8_t row7_lz = vclzq_s16(abs_row7);
+ /* Narrow leading zero count to 8 bits. */
+ uint8x16_t row01_lz = vuzp1q_u8(vreinterpretq_u8_s16(row0_lz),
+ vreinterpretq_u8_s16(row1_lz));
+ uint8x16_t row23_lz = vuzp1q_u8(vreinterpretq_u8_s16(row2_lz),
+ vreinterpretq_u8_s16(row3_lz));
+ uint8x16_t row45_lz = vuzp1q_u8(vreinterpretq_u8_s16(row4_lz),
+ vreinterpretq_u8_s16(row5_lz));
+ uint8x16_t row67_lz = vuzp1q_u8(vreinterpretq_u8_s16(row6_lz),
+ vreinterpretq_u8_s16(row7_lz));
/* Compute nbits needed to specify magnitude of each coefficient. */
- uint8x8_t row0_nbits = vsub_u8(vdup_n_u8(16),
- vmovn_u16(vreinterpretq_u16_s16(row0_lz)));
- uint8x8_t row1_nbits = vsub_u8(vdup_n_u8(16),
- vmovn_u16(vreinterpretq_u16_s16(row1_lz)));
- uint8x8_t row2_nbits = vsub_u8(vdup_n_u8(16),
- vmovn_u16(vreinterpretq_u16_s16(row2_lz)));
- uint8x8_t row3_nbits = vsub_u8(vdup_n_u8(16),
- vmovn_u16(vreinterpretq_u16_s16(row3_lz)));
- uint8x8_t row4_nbits = vsub_u8(vdup_n_u8(16),
- vmovn_u16(vreinterpretq_u16_s16(row4_lz)));
- uint8x8_t row5_nbits = vsub_u8(vdup_n_u8(16),
- vmovn_u16(vreinterpretq_u16_s16(row5_lz)));
- uint8x8_t row6_nbits = vsub_u8(vdup_n_u8(16),
- vmovn_u16(vreinterpretq_u16_s16(row6_lz)));
- uint8x8_t row7_nbits = vsub_u8(vdup_n_u8(16),
- vmovn_u16(vreinterpretq_u16_s16(row7_lz)));
+ uint8x16_t row01_nbits = vsubq_u8(vdupq_n_u8(16), row01_lz);
+ uint8x16_t row23_nbits = vsubq_u8(vdupq_n_u8(16), row23_lz);
+ uint8x16_t row45_nbits = vsubq_u8(vdupq_n_u8(16), row45_lz);
+ uint8x16_t row67_nbits = vsubq_u8(vdupq_n_u8(16), row67_lz);
/* Store nbits. */
- vst1_u8(block_nbits + 0 * DCTSIZE, row0_nbits);
- vst1_u8(block_nbits + 1 * DCTSIZE, row1_nbits);
- vst1_u8(block_nbits + 2 * DCTSIZE, row2_nbits);
- vst1_u8(block_nbits + 3 * DCTSIZE, row3_nbits);
- vst1_u8(block_nbits + 4 * DCTSIZE, row4_nbits);
- vst1_u8(block_nbits + 5 * DCTSIZE, row5_nbits);
- vst1_u8(block_nbits + 6 * DCTSIZE, row6_nbits);
- vst1_u8(block_nbits + 7 * DCTSIZE, row7_nbits);
+ vst1q_u8(block_nbits + 0 * DCTSIZE, row01_nbits);
+ vst1q_u8(block_nbits + 2 * DCTSIZE, row23_nbits);
+ vst1q_u8(block_nbits + 4 * DCTSIZE, row45_nbits);
+ vst1q_u8(block_nbits + 6 * DCTSIZE, row67_nbits);
/* Mask bits not required to specify sign and amplitude of diff. */
- row0_diff = vshlq_u16(row0_diff, row0_lz);
- row1_diff = vshlq_u16(row1_diff, row1_lz);
- row2_diff = vshlq_u16(row2_diff, row2_lz);
- row3_diff = vshlq_u16(row3_diff, row3_lz);
- row4_diff = vshlq_u16(row4_diff, row4_lz);
- row5_diff = vshlq_u16(row5_diff, row5_lz);
- row6_diff = vshlq_u16(row6_diff, row6_lz);
- row7_diff = vshlq_u16(row7_diff, row7_lz);
- row0_diff = vshlq_u16(row0_diff, vnegq_s16(row0_lz));
- row1_diff = vshlq_u16(row1_diff, vnegq_s16(row1_lz));
- row2_diff = vshlq_u16(row2_diff, vnegq_s16(row2_lz));
- row3_diff = vshlq_u16(row3_diff, vnegq_s16(row3_lz));
- row4_diff = vshlq_u16(row4_diff, vnegq_s16(row4_lz));
- row5_diff = vshlq_u16(row5_diff, vnegq_s16(row5_lz));
- row6_diff = vshlq_u16(row6_diff, vnegq_s16(row6_lz));
- row7_diff = vshlq_u16(row7_diff, vnegq_s16(row7_lz));
+ uint16x8_t row1_mask = vshlq_u16(vcltzq_s16(row1), vnegq_s16(row1_lz));
+ uint16x8_t row2_mask = vshlq_u16(vcltzq_s16(row2), vnegq_s16(row2_lz));
+ uint16x8_t row3_mask = vshlq_u16(vcltzq_s16(row3), vnegq_s16(row3_lz));
+ uint16x8_t row4_mask = vshlq_u16(vcltzq_s16(row4), vnegq_s16(row4_lz));
+ uint16x8_t row5_mask = vshlq_u16(vcltzq_s16(row5), vnegq_s16(row5_lz));
+ uint16x8_t row6_mask = vshlq_u16(vcltzq_s16(row6), vnegq_s16(row6_lz));
+ uint16x8_t row7_mask = vshlq_u16(vcltzq_s16(row7), vnegq_s16(row7_lz));
+ /* diff = abs(coeff) ^ sign(coeff) [no-op for positive coefficients] */
+ uint16x8_t row1_diff = veorq_u16(vreinterpretq_u16_s16(abs_row1),
+ row1_mask);
+ uint16x8_t row2_diff = veorq_u16(vreinterpretq_u16_s16(abs_row2),
+ row2_mask);
+ uint16x8_t row3_diff = veorq_u16(vreinterpretq_u16_s16(abs_row3),
+ row3_mask);
+ uint16x8_t row4_diff = veorq_u16(vreinterpretq_u16_s16(abs_row4),
+ row4_mask);
+ uint16x8_t row5_diff = veorq_u16(vreinterpretq_u16_s16(abs_row5),
+ row5_mask);
+ uint16x8_t row6_diff = veorq_u16(vreinterpretq_u16_s16(abs_row6),
+ row6_mask);
+ uint16x8_t row7_diff = veorq_u16(vreinterpretq_u16_s16(abs_row7),
+ row7_mask);
/* Store diff bits. */
vst1q_u16(block_diff + 0 * DCTSIZE, row0_diff);
vst1q_u16(block_diff + 1 * DCTSIZE, row1_diff);
}
} else if (bitmap != 0) {
uint16_t block_abs[DCTSIZE2];
- /* Store absolute value of coefficients. */
+ /* Compute and store absolute value of coefficients. */
+ int16x8_t abs_row1 = vabsq_s16(row1);
+ int16x8_t abs_row2 = vabsq_s16(row2);
+ int16x8_t abs_row3 = vabsq_s16(row3);
+ int16x8_t abs_row4 = vabsq_s16(row4);
+ int16x8_t abs_row5 = vabsq_s16(row5);
+ int16x8_t abs_row6 = vabsq_s16(row6);
+ int16x8_t abs_row7 = vabsq_s16(row7);
vst1q_u16(block_abs + 0 * DCTSIZE, vreinterpretq_u16_s16(abs_row0));
vst1q_u16(block_abs + 1 * DCTSIZE, vreinterpretq_u16_s16(abs_row1));
vst1q_u16(block_abs + 2 * DCTSIZE, vreinterpretq_u16_s16(abs_row2));
vst1q_u16(block_abs + 5 * DCTSIZE, vreinterpretq_u16_s16(abs_row5));
vst1q_u16(block_abs + 6 * DCTSIZE, vreinterpretq_u16_s16(abs_row6));
vst1q_u16(block_abs + 7 * DCTSIZE, vreinterpretq_u16_s16(abs_row7));
- /* Store diff bits. */
+ /* Compute diff bits (without nbits mask) and store. */
+ uint16x8_t row1_diff = veorq_u16(vreinterpretq_u16_s16(abs_row1),
+ vcltzq_s16(row1));
+ uint16x8_t row2_diff = veorq_u16(vreinterpretq_u16_s16(abs_row2),
+ vcltzq_s16(row2));
+ uint16x8_t row3_diff = veorq_u16(vreinterpretq_u16_s16(abs_row3),
+ vcltzq_s16(row3));
+ uint16x8_t row4_diff = veorq_u16(vreinterpretq_u16_s16(abs_row4),
+ vcltzq_s16(row4));
+ uint16x8_t row5_diff = veorq_u16(vreinterpretq_u16_s16(abs_row5),
+ vcltzq_s16(row5));
+ uint16x8_t row6_diff = veorq_u16(vreinterpretq_u16_s16(abs_row6),
+ vcltzq_s16(row6));
+ uint16x8_t row7_diff = veorq_u16(vreinterpretq_u16_s16(abs_row7),
+ vcltzq_s16(row7));
vst1q_u16(block_diff + 0 * DCTSIZE, row0_diff);
vst1q_u16(block_diff + 1 * DCTSIZE, row1_diff);
vst1q_u16(block_diff + 2 * DCTSIZE, row2_diff);
bitmap <<= r;
lz = BUILTIN_CLZ(block_abs[i]);
nbits = 32 - lz;
- diff = (unsigned int)(block_diff[i] << lz) >> lz;
+ diff = ((unsigned int)block_diff[i] << lz) >> lz;
while (r > 15) {
/* If run length > 15, emit special run-length-16 codes. */
PUT_BITS(code_0xf0, size_0xf0)
*
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2011, Nokia Corporation and/or its subsidiary(-ies).
- * Copyright (C) 2009-2011, 2013-2014, 2016, 2018, 2020, D. R. Commander.
+ * Copyright (C) 2009-2011, 2013-2014, 2016, 2018, 2020, 2022, D. R. Commander.
* Copyright (C) 2015-2016, 2018, Matthieu Darbois.
* Copyright (C) 2020, Arm Limited.
*
#include "../../jsimd.h"
#include "jconfigint.h"
-#include <stdio.h>
-#include <string.h>
#include <ctype.h>
#define JSIMD_FASTLD3 1
init_simd(void)
{
#ifndef NO_GETENV
- char *env = NULL;
+ char env[2] = { 0 };
#endif
#if defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
int bufsize = 1024; /* an initial guess for the line buffer size limit */
#ifndef NO_GETENV
/* Force different settings through environment variables */
- env = getenv("JSIMD_FORCENEON");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FORCENEON") && !strcmp(env, "1"))
simd_support = JSIMD_NEON;
- env = getenv("JSIMD_FORCENONE");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FORCENONE") && !strcmp(env, "1"))
simd_support = 0;
- env = getenv("JSIMD_NOHUFFENC");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_NOHUFFENC") && !strcmp(env, "1"))
simd_huffman = 0;
- env = getenv("JSIMD_FASTLD3");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FASTLD3") && !strcmp(env, "1"))
simd_features |= JSIMD_FASTLD3;
- if ((env != NULL) && (strcmp(env, "0") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FASTLD3") && !strcmp(env, "0"))
simd_features &= ~JSIMD_FASTLD3;
- env = getenv("JSIMD_FASTST3");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FASTST3") && !strcmp(env, "1"))
simd_features |= JSIMD_FASTST3;
- if ((env != NULL) && (strcmp(env, "0") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FASTST3") && !strcmp(env, "0"))
simd_features &= ~JSIMD_FASTST3;
#endif
}
/*
* jquanti-neon.c - sample data conversion and quantization (Arm Neon)
*
- * Copyright (C) 2020, Arm Limited. All Rights Reserved.
+ * Copyright (C) 2020-2021, Arm Limited. All Rights Reserved.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
DCTELEM *shift_ptr = divisors + 3 * DCTSIZE2;
int i;
+#if defined(__clang__) && (defined(__aarch64__) || defined(_M_ARM64))
+#pragma unroll
+#endif
for (i = 0; i < DCTSIZE; i += DCTSIZE / 2) {
/* Load DCT coefficients. */
int16x8_t row0 = vld1q_s16(workspace + (i + 0) * DCTSIZE);
* jsimd_i386.c
*
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
- * Copyright (C) 2009-2011, 2013-2014, 2016, 2018, D. R. Commander.
+ * Copyright (C) 2009-2011, 2013-2014, 2016, 2018, 2022, D. R. Commander.
* Copyright (C) 2015-2016, 2018, Matthieu Darbois.
*
* Based on the x86 SIMD extension for IJG JPEG library,
init_simd(void)
{
#ifndef NO_GETENV
- char *env = NULL;
+ char env[2] = { 0 };
#endif
if (simd_support != ~0U)
#ifndef NO_GETENV
/* Force different settings through environment variables */
- env = getenv("JSIMD_FORCEMMX");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FORCEMMX") && !strcmp(env, "1"))
simd_support &= JSIMD_MMX;
- env = getenv("JSIMD_FORCE3DNOW");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FORCE3DNOW") && !strcmp(env, "1"))
simd_support &= JSIMD_3DNOW | JSIMD_MMX;
- env = getenv("JSIMD_FORCESSE");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FORCESSE") && !strcmp(env, "1"))
simd_support &= JSIMD_SSE | JSIMD_MMX;
- env = getenv("JSIMD_FORCESSE2");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FORCESSE2") && !strcmp(env, "1"))
simd_support &= JSIMD_SSE2;
- env = getenv("JSIMD_FORCEAVX2");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FORCEAVX2") && !strcmp(env, "1"))
simd_support &= JSIMD_AVX2;
- env = getenv("JSIMD_FORCENONE");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FORCENONE") && !strcmp(env, "1"))
simd_support = 0;
- env = getenv("JSIMD_NOHUFFENC");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_NOHUFFENC") && !strcmp(env, "1"))
simd_huffman = 0;
#endif
}
#include "../../jsimddct.h"
#include "../jsimd.h"
-#include <stdio.h>
-#include <string.h>
#include <ctype.h>
static unsigned int simd_support = ~0;
#include "../../jsimddct.h"
#include "../jsimd.h"
-#include <stdio.h>
-#include <string.h>
#include <ctype.h>
static unsigned int simd_support = ~0;
#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>
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;
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)) {
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__)
* jsimd_x86_64.c
*
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
- * Copyright (C) 2009-2011, 2014, 2016, 2018, D. R. Commander.
+ * Copyright (C) 2009-2011, 2014, 2016, 2018, 2022, D. R. Commander.
* Copyright (C) 2015-2016, 2018, Matthieu Darbois.
*
* Based on the x86 SIMD extension for IJG JPEG library,
init_simd(void)
{
#ifndef NO_GETENV
- char *env = NULL;
+ char env[2] = { 0 };
#endif
if (simd_support != ~0U)
#ifndef NO_GETENV
/* Force different settings through environment variables */
- env = getenv("JSIMD_FORCESSE2");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FORCESSE2") && !strcmp(env, "1"))
simd_support &= JSIMD_SSE2;
- env = getenv("JSIMD_FORCEAVX2");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FORCEAVX2") && !strcmp(env, "1"))
simd_support &= JSIMD_AVX2;
- env = getenv("JSIMD_FORCENONE");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_FORCENONE") && !strcmp(env, "1"))
simd_support = 0;
- env = getenv("JSIMD_NOHUFFENC");
- if ((env != NULL) && (strcmp(env, "1") == 0))
+ if (!GETENV_S(env, 2, "JSIMD_NOHUFFENC") && !strcmp(env, "1"))
simd_huffman = 0;
#endif
}
--- /dev/null
+/*
+ * Copyright (C)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:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * - Neither the name of the libjpeg-turbo Project nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "jinclude.h"
+#include <errno.h>
+
+
+#define CHECK_VALUE(actual, expected, desc) \
+ if (actual != expected) { \
+ printf("ERROR in line %d: " desc " is %d, should be %d\n", \
+ __LINE__, actual, expected); \
+ return -1; \
+ }
+
+#define CHECK_ERRNO(errno_return, expected_errno) \
+ CHECK_VALUE(errno_return, expected_errno, "Return value") \
+ CHECK_VALUE(errno, expected_errno, "errno") \
+
+
+#ifdef _MSC_VER
+
+void invalid_parameter_handler(const wchar_t *expression,
+ const wchar_t *function, const wchar_t *file,
+ unsigned int line, uintptr_t pReserved)
+{
+}
+
+#endif
+
+
+int main(int argc, char **argv)
+{
+ int err;
+ char env[3];
+
+#ifdef _MSC_VER
+ _set_invalid_parameter_handler(invalid_parameter_handler);
+#endif
+
+ /***************************************************************************/
+
+#ifndef NO_PUTENV
+
+ printf("PUTENV_S():\n");
+
+ errno = 0;
+ err = PUTENV_S(NULL, "12");
+ CHECK_ERRNO(err, EINVAL);
+
+ errno = 0;
+ err = PUTENV_S("TESTENV", NULL);
+ CHECK_ERRNO(err, EINVAL);
+
+ errno = 0;
+ err = PUTENV_S("TESTENV", "12");
+ CHECK_ERRNO(err, 0);
+
+ printf("SUCCESS!\n\n");
+
+#endif
+
+ /***************************************************************************/
+
+#ifndef NO_GETENV
+
+ printf("GETENV_S():\n");
+
+ errno = 0;
+ env[0] = 1;
+ env[1] = 2;
+ env[2] = 3;
+ err = GETENV_S(env, 3, NULL);
+ CHECK_ERRNO(err, 0);
+ CHECK_VALUE(env[0], 0, "env[0]");
+ CHECK_VALUE(env[1], 2, "env[1]");
+ CHECK_VALUE(env[2], 3, "env[2]");
+
+ errno = 0;
+ env[0] = 1;
+ env[1] = 2;
+ env[2] = 3;
+ err = GETENV_S(env, 3, "TESTENV2");
+ CHECK_ERRNO(err, 0);
+ CHECK_VALUE(env[0], 0, "env[0]");
+ CHECK_VALUE(env[1], 2, "env[1]");
+ CHECK_VALUE(env[2], 3, "env[2]");
+
+ errno = 0;
+ err = GETENV_S(NULL, 3, "TESTENV");
+ CHECK_ERRNO(err, EINVAL);
+
+ errno = 0;
+ err = GETENV_S(NULL, 0, "TESTENV");
+ CHECK_ERRNO(err, 0);
+
+ errno = 0;
+ env[0] = 1;
+ err = GETENV_S(env, 0, "TESTENV");
+ CHECK_ERRNO(err, EINVAL);
+ CHECK_VALUE(env[0], 1, "env[0]");
+
+ errno = 0;
+ env[0] = 1;
+ env[1] = 2;
+ env[2] = 3;
+ err = GETENV_S(env, 1, "TESTENV");
+ CHECK_VALUE(err, ERANGE, "Return value");
+ CHECK_VALUE(errno, 0, "errno");
+ CHECK_VALUE(env[0], 0, "env[0]");
+ CHECK_VALUE(env[1], 2, "env[1]");
+ CHECK_VALUE(env[2], 3, "env[2]");
+
+ errno = 0;
+ env[0] = 1;
+ env[1] = 2;
+ env[2] = 3;
+ err = GETENV_S(env, 2, "TESTENV");
+ CHECK_VALUE(err, ERANGE, "Return value");
+ CHECK_VALUE(errno, 0, "errno");
+ CHECK_VALUE(env[0], 0, "env[0]");
+ CHECK_VALUE(env[1], 2, "env[1]");
+ CHECK_VALUE(env[2], 3, "env[2]");
+
+ errno = 0;
+ env[0] = 1;
+ env[1] = 2;
+ env[2] = 3;
+ err = GETENV_S(env, 3, "TESTENV");
+ CHECK_ERRNO(err, 0);
+ CHECK_VALUE(env[0], '1', "env[0]");
+ CHECK_VALUE(env[1], '2', "env[1]");
+ CHECK_VALUE(env[2], 0, "env[2]");
+
+ printf("SUCCESS!\n\n");
+
+#endif
+
+ /***************************************************************************/
+
+ return 0;
+}
/*
- * Copyright (C)2009-2019, 2021 D. R. Commander. All Rights Reserved.
+ * Copyright (C)2009-2019, 2021-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:
* POSSIBILITY OF SUCH DAMAGE.
*/
+#ifdef _MSC_VER
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
if (strncmp(tjErrorStr, _tjErrorStr, JMSG_LENGTH_MAX) || \
strncmp(tjErrorMsg, m, JMSG_LENGTH_MAX) || \
tjErrorCode != _tjErrorCode || tjErrorLine != __LINE__) { \
- strncpy(tjErrorStr, _tjErrorStr, JMSG_LENGTH_MAX - 1); \
- strncpy(tjErrorMsg, m, JMSG_LENGTH_MAX - 1); \
+ strncpy(tjErrorStr, _tjErrorStr, JMSG_LENGTH_MAX); \
+ tjErrorStr[JMSG_LENGTH_MAX - 1] = '\0'; \
+ strncpy(tjErrorMsg, m, JMSG_LENGTH_MAX); \
+ tjErrorMsg[JMSG_LENGTH_MAX - 1] = '\0'; \
tjErrorCode = _tjErrorCode; \
tjErrorLine = __LINE__; \
printf("WARNING in line %d while %s:\n%s\n", __LINE__, m, _tjErrorStr); \
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];
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;
}
unsigned char *dstPtr, *dstPtr2, *yuvBuf = NULL;
if (jpegQual > 0) {
- snprintf(qualStr, 13, "_Q%d", jpegQual);
+ SNPRINTF(qualStr, 13, "_Q%d", jpegQual);
qualStr[12] = 0;
}
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) {
if (y > 255) y = 255;
if (y < 0) y = 0;
- dstBuf[rindex] = abs(dstBuf[rindex] - y);
- dstBuf[gindex] = abs(dstBuf[gindex] - y);
- dstBuf[bindex] = abs(dstBuf[bindex] - y);
+ dstBuf[rindex] = (unsigned char)abs(dstBuf[rindex] - y);
+ dstBuf[gindex] = (unsigned char)abs(dstBuf[gindex] - y);
+ dstBuf[bindex] = (unsigned char)abs(dstBuf[bindex] - y);
}
}
} else {
for (row = 0; row < h; row++)
for (col = 0; col < w * ps; col++)
dstBuf[pitch * row + col] =
- abs(dstBuf[pitch * row + col] - srcBuf[pitch * row + col]);
+ (unsigned char)abs(dstBuf[pitch * row + col] -
+ srcBuf[pitch * row + col]);
}
if (tjSaveImage(tempStr, dstBuf, w, 0, h, pf, flags) == -1)
THROW_TJG("saving bitmap");
(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");
sigfig((double)(w * h * ps) / (double)totalJpegSize, 4,
tempStr2, 80),
quiet == 2 ? "\n" : " ");
- } else if (!quiet) {
+ } else {
printf("Transform --> Frame rate: %f fps\n",
1.0 / elapsed);
printf(" Output image size: %lu bytes\n",
/*
- * Copyright (C)2011-2012, 2014-2015, 2017, 2019, 2021 D. R. Commander.
- * All Rights Reserved.
+ * Copyright (C)2011-2012, 2014-2015, 2017, 2019, 2021-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:
* images using the TurboJPEG C API
*/
+#ifdef _MSC_VER
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
- * Copyright (C)2009-2014, 2017-2019 D. R. Commander. All Rights Reserved.
+ * Copyright (C)2009-2014, 2017-2019, 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:
* This program tests the various code paths in the TurboJPEG C Wrapper
*/
+#ifdef _MSC_VER
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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);
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);
/*
- * 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:
*/
#ifdef _WIN32
-#ifndef __MINGW32__
-#include <stdio.h>
-#define snprintf(str, n, format, ...) \
- _snprintf_s(str, n, _TRUNCATE, format, ##__VA_ARGS__)
-#endif
+#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))
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1997-2019, Thomas G. Lane, Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2010, 2017, 2021, D. R. Commander.
+ * Copyright (C) 2010, 2017, 2021-2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
}
} else {
for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
- MEMZERO(dst_buffer[offset_y] + x_drop_blocks,
- comp_width * sizeof(JBLOCK));
+ memset(dst_buffer[offset_y] + x_drop_blocks, 0,
+ comp_width * sizeof(JBLOCK));
}
}
}
if (dst_blk_y < y_crop_blocks ||
dst_blk_y >= y_crop_blocks + comp_height) {
for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
- MEMZERO(dst_buffer[offset_y],
- compptr->width_in_blocks * sizeof(JBLOCK));
+ memset(dst_buffer[offset_y], 0,
+ compptr->width_in_blocks * sizeof(JBLOCK));
}
continue;
}
for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
if (dstinfo->_jpeg_width > srcinfo->output_width) {
if (x_crop_blocks > 0) {
- MEMZERO(dst_buffer[offset_y], x_crop_blocks * sizeof(JBLOCK));
+ memset(dst_buffer[offset_y], 0, x_crop_blocks * sizeof(JBLOCK));
}
jcopy_block_row(src_buffer[offset_y],
dst_buffer[offset_y] + x_crop_blocks, comp_width);
if (compptr->width_in_blocks > x_crop_blocks + comp_width) {
- MEMZERO(dst_buffer[offset_y] + x_crop_blocks + comp_width,
- (compptr->width_in_blocks - x_crop_blocks - comp_width) *
- sizeof(JBLOCK));
+ memset(dst_buffer[offset_y] + x_crop_blocks + comp_width, 0,
+ (compptr->width_in_blocks - x_crop_blocks - comp_width) *
+ sizeof(JBLOCK));
}
} else {
jcopy_block_row(src_buffer[offset_y] + x_crop_blocks,
if (dst_blk_y < y_crop_blocks ||
dst_blk_y >= y_crop_blocks + comp_height) {
for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
- MEMZERO(dst_buffer[offset_y],
- compptr->width_in_blocks * sizeof(JBLOCK));
+ memset(dst_buffer[offset_y], 0,
+ compptr->width_in_blocks * sizeof(JBLOCK));
}
continue;
}
}
for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
if (x_crop_blocks > 0) {
- MEMZERO(dst_buffer[offset_y], x_crop_blocks * sizeof(JBLOCK));
+ memset(dst_buffer[offset_y], 0, x_crop_blocks * sizeof(JBLOCK));
dc = src_buffer[offset_y][0][0];
for (dst_blk_x = 0; dst_blk_x < x_crop_blocks; dst_blk_x++) {
dst_buffer[offset_y][dst_blk_x][0] = dc;
jcopy_block_row(src_buffer[offset_y],
dst_buffer[offset_y] + x_crop_blocks, comp_width);
if (compptr->width_in_blocks > x_crop_blocks + comp_width) {
- MEMZERO(dst_buffer[offset_y] + x_crop_blocks + comp_width,
- (compptr->width_in_blocks - x_crop_blocks - comp_width) *
- sizeof(JBLOCK));
+ memset(dst_buffer[offset_y] + x_crop_blocks + comp_width, 0,
+ (compptr->width_in_blocks - x_crop_blocks - comp_width) *
+ sizeof(JBLOCK));
dc = src_buffer[offset_y][comp_width - 1][0];
for (dst_blk_x = x_crop_blocks + comp_width;
dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
if (dst_blk_y < y_crop_blocks ||
dst_blk_y >= y_crop_blocks + comp_height) {
for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
- MEMZERO(dst_buffer[offset_y],
- compptr->width_in_blocks * sizeof(JBLOCK));
+ memset(dst_buffer[offset_y], 0,
+ compptr->width_in_blocks * sizeof(JBLOCK));
}
continue;
}
((j_common_ptr)srcinfo, src_coef_arrays[ci], y_wipe_blocks,
(JDIMENSION)compptr->v_samp_factor, TRUE);
for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
- MEMZERO(buffer[offset_y] + x_wipe_blocks, wipe_width * sizeof(JBLOCK));
+ memset(buffer[offset_y] + x_wipe_blocks, 0,
+ wipe_width * sizeof(JBLOCK));
}
}
}
((j_common_ptr)srcinfo, src_coef_arrays[ci], y_wipe_blocks,
(JDIMENSION)compptr->v_samp_factor, TRUE);
for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
- MEMZERO(buffer[offset_y] + x_wipe_blocks, wipe_width * sizeof(JBLOCK));
+ memset(buffer[offset_y] + x_wipe_blocks, 0,
+ wipe_width * sizeof(JBLOCK));
if (x_wipe_blocks > 0) {
dc_left_value = buffer[offset_y][x_wipe_blocks - 1][0];
if (wipe_right < compptr->width_in_blocks) {
}
}
} else {
- MEMZERO(buffer[offset_y] + x_wipe_blocks,
- wipe_width * sizeof(JBLOCK));
+ memset(buffer[offset_y] + x_wipe_blocks, 0,
+ wipe_width * sizeof(JBLOCK));
}
}
}
/*
- * Copyright (C)2011-2021 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:
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include <stdlib.h>
-#include <string.h>
#include "turbojpeg.h"
-#ifdef WIN32
-#include "tjutil.h"
-#endif
+#include "jinclude.h"
#include <jni.h>
#include "java/org_libjpegturbo_turbojpeg_TJCompressor.h"
#include "java/org_libjpegturbo_turbojpeg_TJDecompressor.h"
BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "handle", "J")); \
handle = (tjhandle)(size_t)(*env)->GetLongField(env, obj, _fid);
-#ifdef _WIN32
-#define setenv(envvar, value, dummy) _putenv_s(envvar, value)
-#endif
-
+#ifndef NO_PUTENV
#define PROP2ENV(property, envvar) { \
if ((jName = (*env)->NewStringUTF(env, property)) != NULL) { \
jboolean exception; \
exception = (*env)->ExceptionCheck(env); \
if (jValue && !exception && \
(value = (*env)->GetStringUTFChars(env, jValue, 0)) != NULL) { \
- setenv(envvar, value, 1); \
+ PUTENV_S(envvar, value); \
(*env)->ReleaseStringUTFChars(env, jValue, value); \
} \
} \
}
+#endif
#define SAFE_RELEASE(javaArray, cArray) { \
if (javaArray && cArray) \
BAILIF0(mid = (*env)->GetStaticMethodID(env, cls, "getProperty",
"(Ljava/lang/String;)Ljava/lang/String;"));
+#ifndef NO_PUTENV
PROP2ENV("turbojpeg.optimize", "TJ_OPTIMIZE");
PROP2ENV("turbojpeg.arithmetic", "TJ_ARITHMETIC");
PROP2ENV("turbojpeg.restart", "TJ_RESTART");
PROP2ENV("turbojpeg.progressive", "TJ_PROGRESSIVE");
+#endif
return 0;
bailout:
jbyteArray jSrcPlanes[3] = { NULL, NULL, NULL };
const unsigned char *srcPlanesTmp[3] = { NULL, NULL, NULL };
const unsigned char *srcPlanes[3] = { NULL, NULL, NULL };
+ jint srcOffsetsTmp[3] = { 0, 0, 0 }, srcStridesTmp[3] = { 0, 0, 0 };
int srcOffsets[3] = { 0, 0, 0 }, srcStrides[3] = { 0, 0, 0 };
unsigned char *jpegBuf = NULL;
int nc = (subsamp == org_libjpegturbo_turbojpeg_TJ_SAMP_GRAY ? 1 : 3), i;
if (ProcessSystemProperties(env) < 0) goto bailout;
- (*env)->GetIntArrayRegion(env, jSrcOffsets, 0, nc, srcOffsets);
+ (*env)->GetIntArrayRegion(env, jSrcOffsets, 0, nc, srcOffsetsTmp);
if ((*env)->ExceptionCheck(env)) goto bailout;
+ for (i = 0; i < 3; i++)
+ srcOffsets[i] = srcOffsetsTmp[i];
- (*env)->GetIntArrayRegion(env, jSrcStrides, 0, nc, srcStrides);
+ (*env)->GetIntArrayRegion(env, jSrcStrides, 0, nc, srcStridesTmp);
if ((*env)->ExceptionCheck(env)) goto bailout;
+ for (i = 0; i < 3; i++)
+ srcStrides[i] = srcStridesTmp[i];
for (i = 0; i < nc; i++) {
int planeSize = tjPlaneSizeYUV(i, width, srcStrides[i], height, subsamp);
jbyteArray jDstPlanes[3] = { NULL, NULL, NULL };
unsigned char *dstPlanesTmp[3] = { NULL, NULL, NULL };
unsigned char *dstPlanes[3] = { NULL, NULL, NULL };
+ jint dstOffsetsTmp[3] = { 0, 0, 0 }, dstStridesTmp[3] = { 0, 0, 0 };
int dstOffsets[3] = { 0, 0, 0 }, dstStrides[3] = { 0, 0, 0 };
int nc = (subsamp == org_libjpegturbo_turbojpeg_TJ_SAMP_GRAY ? 1 : 3), i;
if ((*env)->GetArrayLength(env, src) * srcElementSize < arraySize)
THROW_ARG("Source buffer is not large enough");
- (*env)->GetIntArrayRegion(env, jDstOffsets, 0, nc, dstOffsets);
+ (*env)->GetIntArrayRegion(env, jDstOffsets, 0, nc, dstOffsetsTmp);
if ((*env)->ExceptionCheck(env)) goto bailout;
+ for (i = 0; i < 3; i++)
+ dstOffsets[i] = dstOffsetsTmp[i];
- (*env)->GetIntArrayRegion(env, jDstStrides, 0, nc, dstStrides);
+ (*env)->GetIntArrayRegion(env, jDstStrides, 0, nc, dstStridesTmp);
if ((*env)->ExceptionCheck(env)) goto bailout;
+ for (i = 0; i < 3; i++)
+ dstStrides[i] = dstStridesTmp[i];
for (i = 0; i < nc; i++) {
int planeSize = tjPlaneSizeYUV(i, width, dstStrides[i], height, subsamp);
jbyteArray jDstPlanes[3] = { NULL, NULL, NULL };
unsigned char *dstPlanesTmp[3] = { NULL, NULL, NULL };
unsigned char *dstPlanes[3] = { NULL, NULL, NULL };
+ jint dstOffsetsTmp[3] = { 0, 0, 0 }, dstStridesTmp[3] = { 0, 0, 0 };
int dstOffsets[3] = { 0, 0, 0 }, dstStrides[3] = { 0, 0, 0 };
int jpegSubsamp = -1, jpegWidth = 0, jpegHeight = 0;
int nc = 0, i, width, height, scaledWidth, scaledHeight, nsf = 0;
if (i >= nsf)
THROW_ARG("Could not scale down to desired image dimensions");
- (*env)->GetIntArrayRegion(env, jDstOffsets, 0, nc, dstOffsets);
+ (*env)->GetIntArrayRegion(env, jDstOffsets, 0, nc, dstOffsetsTmp);
if ((*env)->ExceptionCheck(env)) goto bailout;
+ for (i = 0; i < 3; i++)
+ dstOffsets[i] = dstOffsetsTmp[i];
- (*env)->GetIntArrayRegion(env, jDstStrides, 0, nc, dstStrides);
+ (*env)->GetIntArrayRegion(env, jDstStrides, 0, nc, dstStridesTmp);
if ((*env)->ExceptionCheck(env)) goto bailout;
+ for (i = 0; i < 3; i++)
+ dstStrides[i] = dstStridesTmp[i];
for (i = 0; i < nc; i++) {
int planeSize = tjPlaneSizeYUV(i, scaledWidth, dstStrides[i], scaledHeight,
jbyteArray jSrcPlanes[3] = { NULL, NULL, NULL };
const unsigned char *srcPlanesTmp[3] = { NULL, NULL, NULL };
const unsigned char *srcPlanes[3] = { NULL, NULL, NULL };
+ jint srcOffsetsTmp[3] = { 0, 0, 0 }, srcStridesTmp[3] = { 0, 0, 0 };
int srcOffsets[3] = { 0, 0, 0 }, srcStrides[3] = { 0, 0, 0 };
unsigned char *dstBuf = NULL;
int nc = (subsamp == org_libjpegturbo_turbojpeg_TJ_SAMP_GRAY ? 1 : 3), i;
if ((*env)->GetArrayLength(env, dst) * dstElementSize < arraySize)
THROW_ARG("Destination buffer is not large enough");
- (*env)->GetIntArrayRegion(env, jSrcOffsets, 0, nc, srcOffsets);
+ (*env)->GetIntArrayRegion(env, jSrcOffsets, 0, nc, srcOffsetsTmp);
if ((*env)->ExceptionCheck(env)) goto bailout;
+ for (i = 0; i < 3; i++)
+ srcOffsets[i] = srcOffsetsTmp[i];
- (*env)->GetIntArrayRegion(env, jSrcStrides, 0, nc, srcStrides);
+ (*env)->GetIntArrayRegion(env, jSrcStrides, 0, nc, srcStridesTmp);
if ((*env)->ExceptionCheck(env)) goto bailout;
+ for (i = 0; i < 3; i++)
+ srcStrides[i] = srcStridesTmp[i];
for (i = 0; i < nc; i++) {
int planeSize = tjPlaneSizeYUV(i, width, srcStrides[i], height, subsamp);
/*
- * Copyright (C)2009-2021 D. R. Commander. All Rights Reserved.
+ * Copyright (C)2009-2022 D. R. Commander. All Rights Reserved.
* Copyright (C)2021 Alex Richardson. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
/* 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
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;
};
#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) { \
- snprintf(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, strerror(errno)); \
+ char strerrorBuf[80] = { 0 }; \
+ strerror_s(strerrorBuf, 80, errno); \
+ 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)); \
+ 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) \
}
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; \
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; \
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; \
int flags)
{
#ifndef NO_GETENV
- char *env = NULL;
+ char env[7] = { 0 };
#endif
cinfo->in_color_space = pf2cs[pixelFormat];
jpeg_set_defaults(cinfo);
#ifndef NO_GETENV
- if ((env = getenv("TJ_OPTIMIZE")) != NULL && strlen(env) > 0 &&
- !strcmp(env, "1"))
+ if (!GETENV_S(env, 7, "TJ_OPTIMIZE") && !strcmp(env, "1"))
cinfo->optimize_coding = TRUE;
- if ((env = getenv("TJ_ARITHMETIC")) != NULL && strlen(env) > 0 &&
- !strcmp(env, "1"))
+ if (!GETENV_S(env, 7, "TJ_ARITHMETIC") && !strcmp(env, "1"))
cinfo->arith_code = TRUE;
- if ((env = getenv("TJ_RESTART")) != NULL && strlen(env) > 0) {
+ if (!GETENV_S(env, 7, "TJ_RESTART") && strlen(env) > 0) {
int temp = -1;
char tempc = 0;
+#ifdef _MSC_VER
+ if (sscanf_s(env, "%d%c", &temp, &tempc, 1) >= 1 && temp >= 0 &&
+ temp <= 65535) {
+#else
if (sscanf(env, "%d%c", &temp, &tempc) >= 1 && temp >= 0 &&
temp <= 65535) {
+#endif
if (toupper(tempc) == 'B') {
cinfo->restart_interval = temp;
cinfo->restart_in_rows = 0;
if (flags & TJFLAG_PROGRESSIVE)
jpeg_simple_progression(cinfo);
#ifndef NO_GETENV
- else if ((env = getenv("TJ_PROGRESSIVE")) != NULL && strlen(env) > 0 &&
- !strcmp(env, "1"))
+ else if (!GETENV_S(env, 7, "TJ_PROGRESSIVE") && !strcmp(env, "1"))
jpeg_simple_progression(cinfo);
#endif
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;
}
- MEMZERO(this, sizeof(tjinstance));
- snprintf(this->errStr, JMSG_LENGTH_MAX, "No error");
+ memset(this, 0, sizeof(tjinstance));
+ SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "No error");
return _tjInitCompress(this);
}
unsigned char **jpegBuf, unsigned long *jpegSize,
int jpegSubsamp, int jpegQual, int flags)
{
- int i, retval = 0, alloc = 1;
+ int i, retval = 0;
+ boolean alloc = TRUE;
JSAMPROW *row_pointer = NULL;
GET_CINSTANCE(handle)
cinfo->image_height = height;
#ifndef NO_PUTENV
- if (flags & TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
- else if (flags & TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
- else if (flags & TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
+ if (flags & TJFLAG_FORCEMMX) PUTENV_S("JSIMD_FORCEMMX", "1");
+ else if (flags & TJFLAG_FORCESSE) PUTENV_S("JSIMD_FORCESSE", "1");
+ else if (flags & TJFLAG_FORCESSE2) PUTENV_S("JSIMD_FORCESSE2", "1");
#endif
if (flags & TJFLAG_NOREALLOC) {
- alloc = 0; *jpegSize = tjBufSize(width, height, jpegSubsamp);
+ alloc = FALSE; *jpegSize = tjBufSize(width, height, jpegSubsamp);
}
jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc);
setCompDefaults(cinfo, pixelFormat, jpegSubsamp, jpegQual, flags);
cinfo->image_height = height;
#ifndef NO_PUTENV
- if (flags & TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
- else if (flags & TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
- else if (flags & TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
+ if (flags & TJFLAG_FORCEMMX) PUTENV_S("JSIMD_FORCEMMX", "1");
+ else if (flags & TJFLAG_FORCESSE) PUTENV_S("JSIMD_FORCESSE", "1");
+ else if (flags & TJFLAG_FORCESSE2) PUTENV_S("JSIMD_FORCESSE2", "1");
#endif
setCompDefaults(cinfo, pixelFormat, subsamp, -1, flags);
unsigned long *jpegSize, int jpegQual,
int flags)
{
- int i, row, retval = 0, alloc = 1;
+ int i, row, retval = 0;
+ boolean alloc = TRUE;
int pw[MAX_COMPONENTS], ph[MAX_COMPONENTS], iw[MAX_COMPONENTS],
tmpbufsize = 0, usetmpbuf = 0, th[MAX_COMPONENTS];
JSAMPLE *_tmpbuf = NULL, *ptr;
cinfo->image_height = height;
#ifndef NO_PUTENV
- if (flags & TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
- else if (flags & TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
- else if (flags & TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
+ if (flags & TJFLAG_FORCEMMX) PUTENV_S("JSIMD_FORCEMMX", "1");
+ else if (flags & TJFLAG_FORCESSE) PUTENV_S("JSIMD_FORCESSE", "1");
+ else if (flags & TJFLAG_FORCESSE2) PUTENV_S("JSIMD_FORCESSE2", "1");
#endif
if (flags & TJFLAG_NOREALLOC) {
- alloc = 0; *jpegSize = tjBufSize(width, height, subsamp);
+ alloc = FALSE; *jpegSize = tjBufSize(width, height, subsamp);
}
jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc);
setCompDefaults(cinfo, TJPF_RGB, subsamp, jpegQual, flags);
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;
}
- MEMZERO(this, sizeof(tjinstance));
- snprintf(this->errStr, JMSG_LENGTH_MAX, "No error");
+ memset(this, 0, sizeof(tjinstance));
+ SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "No error");
return _tjInitDecompress(this);
}
}
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;
DLLEXPORT tjscalingfactor *tjGetScalingFactors(int *numscalingfactors)
{
if (numscalingfactors == NULL) {
- snprintf(errStr, JMSG_LENGTH_MAX,
+ SNPRINTF(errStr, JMSG_LENGTH_MAX,
"tjGetScalingFactors(): Invalid argument");
return NULL;
}
THROW("tjDecompress2(): Invalid argument");
#ifndef NO_PUTENV
- if (flags & TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
- else if (flags & TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
- else if (flags & TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
+ if (flags & TJFLAG_FORCEMMX) PUTENV_S("JSIMD_FORCEMMX", "1");
+ else if (flags & TJFLAG_FORCESSE) PUTENV_S("JSIMD_FORCESSE", "1");
+ else if (flags & TJFLAG_FORCESSE2) PUTENV_S("JSIMD_FORCESSE2", "1");
#endif
if (flags & TJFLAG_LIMITSCANS) {
- MEMZERO(&progress, sizeof(struct my_progress_mgr));
+ memset(&progress, 0, sizeof(struct my_progress_mgr));
progress.pub.progress_monitor = my_progress_monitor;
progress.this = this;
dinfo->progress = &progress.pub;
dinfo->image_height = height;
#ifndef NO_PUTENV
- if (flags & TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
- else if (flags & TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
- else if (flags & TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
+ if (flags & TJFLAG_FORCEMMX) PUTENV_S("JSIMD_FORCEMMX", "1");
+ else if (flags & TJFLAG_FORCESSE) PUTENV_S("JSIMD_FORCESSE", "1");
+ else if (flags & TJFLAG_FORCESSE2) PUTENV_S("JSIMD_FORCESSE2", "1");
#endif
dinfo->progressive_mode = dinfo->inputctl->has_multiple_scans = FALSE;
THROW("tjDecompressToYUVPlanes(): Invalid argument");
#ifndef NO_PUTENV
- if (flags & TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
- else if (flags & TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
- else if (flags & TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
+ if (flags & TJFLAG_FORCEMMX) PUTENV_S("JSIMD_FORCEMMX", "1");
+ else if (flags & TJFLAG_FORCESSE) PUTENV_S("JSIMD_FORCESSE", "1");
+ else if (flags & TJFLAG_FORCESSE2) PUTENV_S("JSIMD_FORCESSE2", "1");
#endif
if (flags & TJFLAG_LIMITSCANS) {
- MEMZERO(&progress, sizeof(struct my_progress_mgr));
+ memset(&progress, 0, sizeof(struct my_progress_mgr));
progress.pub.progress_monitor = my_progress_monitor;
progress.this = this;
dinfo->progress = &progress.pub;
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;
}
- MEMZERO(this, sizeof(tjinstance));
- snprintf(this->errStr, JMSG_LENGTH_MAX, "No error");
+ memset(this, 0, sizeof(tjinstance));
+ SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "No error");
handle = _tjInitCompress(this);
if (!handle) return NULL;
handle = _tjInitDecompress(this);
{
jpeg_transform_info *xinfo = NULL;
jvirt_barray_ptr *srccoefs, *dstcoefs;
- int retval = 0, alloc = 1, i, jpegSubsamp, saveMarkers = 0;
+ int retval = 0, i, jpegSubsamp, saveMarkers = 0;
+ boolean alloc = TRUE;
struct my_progress_mgr progress;
GET_INSTANCE(handle);
THROW("tjTransform(): Invalid argument");
#ifndef NO_PUTENV
- if (flags & TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
- else if (flags & TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
- else if (flags & TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
+ if (flags & TJFLAG_FORCEMMX) PUTENV_S("JSIMD_FORCEMMX", "1");
+ else if (flags & TJFLAG_FORCESSE) PUTENV_S("JSIMD_FORCESSE", "1");
+ else if (flags & TJFLAG_FORCESSE2) PUTENV_S("JSIMD_FORCESSE2", "1");
#endif
if (flags & TJFLAG_LIMITSCANS) {
- MEMZERO(&progress, sizeof(struct my_progress_mgr));
+ memset(&progress, 0, sizeof(struct my_progress_mgr));
progress.pub.progress_monitor = my_progress_monitor;
progress.this = this;
dinfo->progress = &progress.pub;
if ((xinfo =
(jpeg_transform_info *)malloc(sizeof(jpeg_transform_info) * n)) == NULL)
THROW("tjTransform(): Memory allocation failure");
- MEMZERO(xinfo, sizeof(jpeg_transform_info) * n);
+ memset(xinfo, 0, sizeof(jpeg_transform_info) * n);
if (setjmp(this->jerr.setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error. */
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]);
w = xinfo[i].crop_width; h = xinfo[i].crop_height;
}
if (flags & TJFLAG_NOREALLOC) {
- alloc = 0; dstSizes[i] = tjBufSize(w, h, jpegSubsamp);
+ alloc = FALSE; dstSizes[i] = tjBufSize(w, h, jpegSubsamp);
}
if (!(t[i].options & TJXOPT_NOOUTPUT))
jpeg_mem_dest_tj(cinfo, &dstBufs[i], &dstSizes[i], alloc);
for (ci = 0; ci < cinfo->num_components; ci++) {
jpeg_component_info *compptr = &cinfo->comp_info[ci];
- tjregion arrayRegion = {
- 0, 0, compptr->width_in_blocks * DCTSIZE, DCTSIZE
- };
- tjregion planeRegion = {
- 0, 0, compptr->width_in_blocks * DCTSIZE,
- compptr->height_in_blocks * DCTSIZE
- };
+ tjregion arrayRegion = { 0, 0, 0, 0 };
+ tjregion planeRegion = { 0, 0, 0, 0 };
+
+ arrayRegion.w = compptr->width_in_blocks * DCTSIZE;
+ arrayRegion.h = DCTSIZE;
+ planeRegion.w = compptr->width_in_blocks * DCTSIZE;
+ planeRegion.h = compptr->height_in_blocks * DCTSIZE;
for (by = 0; by < compptr->height_in_blocks;
by += compptr->v_samp_factor) {
this = (tjinstance *)handle;
cinfo = &this->cinfo;
+#ifdef _MSC_VER
+ if (fopen_s(&file, filename, "rb") || file == NULL)
+#else
if ((file = fopen(filename, "rb")) == NULL)
+#endif
THROW_UNIX("tjLoadImage(): Cannot open input file");
if ((tempc = getc(file)) < 0 || ungetc(tempc, file) == EOF)
this = (tjinstance *)handle;
dinfo = &this->dinfo;
+#ifdef _MSC_VER
+ if (fopen_s(&file, filename, "wb") || file == NULL)
+#else
if ((file = fopen(filename, "wb")) == NULL)
+#endif
THROW_UNIX("tjSaveImage(): Cannot open output file");
if (setjmp(this->jerr.setjmp_buffer)) {
* scalingFactor)</tt>.
*/
#define TJSCALED(dimension, scalingFactor) \
- ((dimension * scalingFactor.num + scalingFactor.denom - 1) / \
+ (((dimension) * scalingFactor.num + scalingFactor.denom - 1) / \
scalingFactor.denom)
/**
- * 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().)
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
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),
Quality is 0 (worst) to 100 (best); default is 75.
(See below for more info.)
- -grayscale Create monochrome JPEG file from color input.
- Be sure to use this switch when compressing a grayscale
- BMP or GIF file, because cjpeg isn't bright enough to
- notice whether a BMP or GIF file uses only shades of
- gray. By saying -grayscale, you'll get a smaller JPEG
- file that takes less time to process.
+ -grayscale Create monochrome JPEG file from color input. By
+ saying -grayscale, you'll get a smaller JPEG file that
+ takes less time to process.
-rgb Create RGB JPEG file.
Using this switch suppresses the conversion from RGB
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
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
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.
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.
#define BITS_IN_JSAMPLE @BITS_IN_JSAMPLE@ /* use 8 or 12 */
-#define HAVE_STDDEF_H
-#define HAVE_STDLIB_H
-#undef NEED_SYS_TYPES_H
-#undef NEED_BSD_STRINGS
-
-#define HAVE_UNSIGNED_CHAR
-#define HAVE_UNSIGNED_SHORT
-#undef INCOMPLETE_TYPES_BROKEN
#undef RIGHT_SHIFT_IS_UNSIGNED
/* Define "boolean" as unsigned char, not int, per Windows custom */
--- /dev/null
+#include "Winver.h"
+#include "winres.h"
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION @SO_MAJOR_VERSION@,@SO_AGE@,@SO_MINOR_VERSION@,0
+ PRODUCTVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_REVISION@,0
+ FILEFLAGSMASK 0x17L
+#ifndef NDEBUG
+ FILEFLAGS VS_FF_DEBUG
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS VOS_NT_WINDOWS32
+ FILETYPE VFT_DLL
+ FILESUBTYPE VFT2_UNKNOWN
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "CompanyName", "@PKGVENDOR@"
+ VALUE "FileDescription", "libjpeg API DLL"
+ VALUE "FileVersion", "@SO_MAJOR_VERSION@,@SO_AGE@,@SO_MINOR_VERSION@,0"
+ VALUE "ProductVersion", "@VERSION@"
+ VALUE "ProductName", "@CMAKE_PROJECT_NAME@"
+ VALUE "InternalName", "jpeg@SO_MAJOR_VERSION@"
+ VALUE "LegalCopyright", "Copyright \xA9 @COPYRIGHT_YEAR@ The libjpeg-turbo Project and many others"
+ VALUE "OriginalFilename", "jpeg@SO_MAJOR_VERSION@.dll"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
--- /dev/null
+#include "Winver.h"
+#include "winres.h"
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 0,@TURBOJPEG_SO_AGE@,0,0
+ PRODUCTVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_REVISION@,0
+ FILEFLAGSMASK 0x17L
+#ifndef NDEBUG
+ FILEFLAGS VS_FF_DEBUG
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS VOS_NT_WINDOWS32
+ FILETYPE VFT_DLL
+ FILESUBTYPE VFT2_UNKNOWN
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "CompanyName", "@PKGVENDOR@"
+ VALUE "FileDescription", "TurboJPEG API DLL"
+ VALUE "FileVersion", "0,@TURBOJPEG_SO_AGE@,0,0"
+ VALUE "ProductVersion", "@VERSION@"
+ VALUE "ProductName", "@CMAKE_PROJECT_NAME@"
+ VALUE "InternalName", "turbojpeg"
+ VALUE "LegalCopyright", "Copyright \xA9 @COPYRIGHT_YEAR@ The libjpeg-turbo Project and many others"
+ VALUE "OriginalFilename", "turbojpeg.dll"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
* Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2013, Linaro Limited.
- * Copyright (C) 2014-2015, 2017, 2019, D. R. Commander.
+ * Copyright (C) 2014-2015, 2017, 2019, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
inptr = dest->pub.buffer[0];
if (cinfo->out_color_space == JCS_EXT_BGR) {
- MEMCOPY(outptr, inptr, dest->row_width);
+ memcpy(outptr, inptr, dest->row_width);
outptr += cinfo->output_width * 3;
} else if (cinfo->out_color_space == JCS_RGB565) {
boolean big_endian = is_big_endian();
*outptr++ = 0;
if (!dest->use_inversion_array)
- (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->row_width);
+ fwrite(dest->iobuffer, 1, dest->row_width, dest->pub.output_file);
}
METHODDEF(void)
/* Transfer data. */
inptr = dest->pub.buffer[0];
- MEMCOPY(outptr, inptr, cinfo->output_width);
+ memcpy(outptr, inptr, cinfo->output_width);
outptr += cinfo->output_width;
/* Zero out the pad bytes. */
*outptr++ = 0;
if (!dest->use_inversion_array)
- (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->row_width);
+ fwrite(dest->iobuffer, 1, dest->row_width, dest->pub.output_file);
}
bfSize = headersize + (long)dest->row_width * (long)cinfo->output_height;
/* Set unused fields of header to 0 */
- MEMZERO(bmpfileheader, sizeof(bmpfileheader));
- MEMZERO(bmpinfoheader, sizeof(bmpinfoheader));
+ memset(bmpfileheader, 0, sizeof(bmpfileheader));
+ memset(bmpinfoheader, 0, sizeof(bmpinfoheader));
/* Fill the file header */
bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */
PUT_2B(bmpinfoheader, 32, cmap_entries); /* biClrUsed */
/* we leave biClrImportant = 0 */
- if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t)14)
+ if (fwrite(bmpfileheader, 1, 14, dest->pub.output_file) != (size_t)14)
ERREXIT(cinfo, JERR_FILE_WRITE);
- if (JFWRITE(dest->pub.output_file, bmpinfoheader, 40) != (size_t)40)
+ if (fwrite(bmpinfoheader, 1, 40, dest->pub.output_file) != (size_t)40)
ERREXIT(cinfo, JERR_FILE_WRITE);
if (cmap_entries > 0)
bfSize = headersize + (long)dest->row_width * (long)cinfo->output_height;
/* Set unused fields of header to 0 */
- MEMZERO(bmpfileheader, sizeof(bmpfileheader));
- MEMZERO(bmpcoreheader, sizeof(bmpcoreheader));
+ memset(bmpfileheader, 0, sizeof(bmpfileheader));
+ memset(bmpcoreheader, 0, sizeof(bmpcoreheader));
/* Fill the file header */
bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */
PUT_2B(bmpcoreheader, 8, 1); /* bcPlanes - must be 1 */
PUT_2B(bmpcoreheader, 10, bits_per_pixel); /* bcBitCount */
- if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t)14)
+ if (fwrite(bmpfileheader, 1, 14, dest->pub.output_file) != (size_t)14)
ERREXIT(cinfo, JERR_FILE_WRITE);
- if (JFWRITE(dest->pub.output_file, bmpcoreheader, 12) != (size_t)12)
+ if (fwrite(bmpcoreheader, 1, 12, dest->pub.output_file) != (size_t)12)
ERREXIT(cinfo, JERR_FILE_WRITE);
if (cmap_entries > 0)
((j_common_ptr)cinfo, dest->whole_image, row - 1, (JDIMENSION)1,
FALSE);
data_ptr = image_ptr[0];
- (void)JFWRITE(outfile, data_ptr, dest->row_width);
+ fwrite(data_ptr, 1, dest->row_width, outfile);
}
if (progress != NULL)
progress->completed_extra_passes++;
* Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2015-2019 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2015, 2017, D. R. Commander.
+ * Copyright (C) 2015, 2017, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
{
if (dinfo->bytesinpkt > 0) { /* never write zero-length packet */
dinfo->packetbuf[0] = (char)dinfo->bytesinpkt++;
- if (JFWRITE(dinfo->pub.output_file, dinfo->packetbuf, dinfo->bytesinpkt) !=
- (size_t)dinfo->bytesinpkt)
+ if (fwrite(dinfo->packetbuf, 1, dinfo->bytesinpkt,
+ dinfo->pub.output_file) != (size_t)dinfo->bytesinpkt)
ERREXIT(dinfo->cinfo, JERR_FILE_WRITE);
dinfo->bytesinpkt = 0;
}
/* Fill the hash table with empty entries */
{
/* It's sufficient to zero hash_code[] */
- MEMZERO(dinfo->hash_code, HSIZE * sizeof(code_int));
+ memset(dinfo->hash_code, 0, HSIZE * sizeof(code_int));
}
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1997, Thomas G. Lane.
* libjpeg-turbo Modifications:
- * Copyright (C) 2014, D. R. Commander.
+ * Copyright (C) 2014, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
* JPEG markers.
*/
+#ifdef _MSC_VER
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+
#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */
#include "jinclude.h" /* get auto-config symbols, <stdio.h> */
-#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc() */
-extern void *malloc();
-#endif
#include <ctype.h> /* to declare isupper(), tolower() */
#ifdef USE_SETMODE
#include <fcntl.h> /* to declare setmode()'s parameter macros */
#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"
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 */
* Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2009 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2017, 2019-2020, D. R. Commander.
+ * Copyright (C) 2017, 2019-2020, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
{
ppm_dest_ptr dest = (ppm_dest_ptr)dinfo;
- (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+ fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file);
}
ptr = dest->pub.buffer[0];
bufferptr = dest->iobuffer;
#if BITS_IN_JSAMPLE == 8
- MEMCOPY(bufferptr, ptr, dest->samples_per_row);
+ memcpy(bufferptr, ptr, dest->samples_per_row);
#else
for (col = dest->samples_per_row; col > 0; col--) {
PUTPPMSAMPLE(bufferptr, *ptr++);
}
#endif
- (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+ fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file);
}
PUTPPMSAMPLE(bufferptr, ptr[bindex]);
ptr += ps;
}
- (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+ fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file);
}
PUTPPMSAMPLE(bufferptr, g);
PUTPPMSAMPLE(bufferptr, b);
}
- (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+ fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file);
}
PUTPPMSAMPLE(bufferptr, color_map1[pixval]);
PUTPPMSAMPLE(bufferptr, color_map2[pixval]);
}
- (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+ fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file);
}
for (col = cinfo->output_width; col > 0; col--) {
PUTPPMSAMPLE(bufferptr, color_map[*ptr++]);
}
- (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+ fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file);
}
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
- * Copyright (C) 2017, 2019, D. R. Commander.
+ * Copyright (C) 2017, 2019, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
char targaheader[18];
/* Set unused fields of header to 0 */
- MEMZERO(targaheader, sizeof(targaheader));
+ memset(targaheader, 0, sizeof(targaheader));
if (num_colors > 0) {
targaheader[1] = 1; /* color map type 1 */
}
}
- if (JFWRITE(dinfo->output_file, targaheader, 18) != (size_t)18)
+ if (fwrite(targaheader, 1, 18, dinfo->output_file) != (size_t)18)
ERREXIT(cinfo, JERR_FILE_WRITE);
}
outptr[2] = inptr[0];
inptr += 3, outptr += 3;
}
- (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+ fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file);
}
METHODDEF(void)
inptr = dest->pub.buffer[0];
outptr = dest->iobuffer;
- MEMCOPY(outptr, inptr, cinfo->output_width);
- (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+ memcpy(outptr, inptr, cinfo->output_width);
+ fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file);
}
for (col = cinfo->output_width; col > 0; col--) {
*outptr++ = color_map0[*inptr++];
}
- (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
+ fwrite(dest->iobuffer, 1, dest->buffer_width, dest->pub.output_file);
}