mirror of
https://github.com/opencv/opencv.git
synced 2025-06-11 11:45:30 +08:00
Merge branch '4.x' into '5.x'
This commit is contained in:
commit
26ea34c4cb
10
3rdparty/ffmpeg/ffmpeg.cmake
vendored
10
3rdparty/ffmpeg/ffmpeg.cmake
vendored
@ -1,8 +1,8 @@
|
||||
# Binaries branch name: ffmpeg/4.x_20231225
|
||||
# Binaries were created for OpenCV: 62f1a7410d5e5e03d6cee5c95549bf61d5ee98db
|
||||
ocv_update(FFMPEG_BINARIES_COMMIT "fbac408a47977ee4265f39e7659d33f1dfef5216")
|
||||
ocv_update(FFMPEG_FILE_HASH_BIN32 "9b755ecbbade0a5b78332e9b4ef2dd1b")
|
||||
ocv_update(FFMPEG_FILE_HASH_BIN64 "cb4db51ee9a423e6168b9d08bee61efc")
|
||||
# Binaries branch name: ffmpeg/4.x_20240522
|
||||
# Binaries were created for OpenCV: 8393885a39dac1e650bf5d0aaff84c04ad8bcdd3
|
||||
ocv_update(FFMPEG_BINARIES_COMMIT "394dca6ceb3085c979415e6385996b6570e94153")
|
||||
ocv_update(FFMPEG_FILE_HASH_BIN32 "bdfbd1efb295f3e54c07d2cb7a843bf9")
|
||||
ocv_update(FFMPEG_FILE_HASH_BIN64 "bfef029900f788480a363d6dc05c4f0e")
|
||||
ocv_update(FFMPEG_FILE_HASH_CMAKE "8862c87496e2e8c375965e1277dee1c7")
|
||||
|
||||
function(download_win_ffmpeg script_var)
|
||||
|
9
3rdparty/hal_rvv/CMakeLists.txt
vendored
Normal file
9
3rdparty/hal_rvv/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
cmake_minimum_required(VERSION ${MIN_VER_CMAKE} FATAL_ERROR)
|
||||
|
||||
set(HAL_LIB_NAME "")
|
||||
|
||||
set(RVV_HAL_FOUND TRUE CACHE INTERNAL "")
|
||||
set(RVV_HAL_VERSION "0.0.1" CACHE INTERNAL "")
|
||||
set(RVV_HAL_LIBRARIES ${HAL_LIB_NAME} CACHE INTERNAL "")
|
||||
set(RVV_HAL_HEADERS "hal_rvv.hpp" CACHE INTERNAL "")
|
||||
set(RVV_HAL_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "")
|
24
3rdparty/hal_rvv/hal_rvv.hpp
vendored
Normal file
24
3rdparty/hal_rvv/hal_rvv.hpp
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#ifndef OPENCV_HAL_RVV_HPP_INCLUDED
|
||||
#define OPENCV_HAL_RVV_HPP_INCLUDED
|
||||
|
||||
#include <riscv_vector.h>
|
||||
|
||||
#include "opencv2/core/hal/interface.h"
|
||||
|
||||
#ifndef CV_HAL_RVV_071_ENABLED
|
||||
# if defined(__GNUC__) && __GNUC__ == 10 && __GNUC_MINOR__ == 4 && defined(__THEAD_VERSION__) && defined(__riscv_v) && __riscv_v == 7000
|
||||
# define CV_HAL_RVV_071_ENABLED 1
|
||||
# else
|
||||
# define CV_HAL_RVV_071_ENABLED 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if CV_HAL_RVV_071_ENABLED
|
||||
#include "version/hal_rvv_071.hpp"
|
||||
#endif
|
||||
|
||||
#endif
|
107
3rdparty/hal_rvv/version/hal_rvv_071.hpp
vendored
Normal file
107
3rdparty/hal_rvv/version/hal_rvv_071.hpp
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#ifndef OPENCV_HAL_RVV_071_HPP_INCLUDED
|
||||
#define OPENCV_HAL_RVV_071_HPP_INCLUDED
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace cv { namespace cv_hal_rvv {
|
||||
|
||||
#undef cv_hal_cvtBGRtoBGR
|
||||
#define cv_hal_cvtBGRtoBGR cv::cv_hal_rvv::cvtBGRtoBGR
|
||||
|
||||
static const unsigned char index_array_32 [32]
|
||||
{ 2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15, 18, 17, 16, 19, 22, 21, 20, 23, 26, 25, 24, 27, 30, 29, 28, 31 };
|
||||
|
||||
static const unsigned char index_array_24 [24]
|
||||
{ 2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, 9, 14, 13, 12, 17, 16, 15, 20, 19, 18, 23, 22, 21 };
|
||||
|
||||
static void vBGRtoBGR(const unsigned char* src, unsigned char * dst, const unsigned char * index, int n, int scn, int dcn, int vsize_pixels, const int vsize)
|
||||
{
|
||||
vuint8m2_t vec_index = vle8_v_u8m2(index, vsize);
|
||||
|
||||
int i = 0;
|
||||
|
||||
for ( ; i <= n-vsize; i += vsize_pixels, src += vsize, dst += vsize)
|
||||
{
|
||||
vuint8m2_t vec_src = vle8_v_u8m2(src, vsize);
|
||||
vuint8m2_t vec_dst = vrgather_vv_u8m2(vec_src, vec_index, vsize);
|
||||
vse8_v_u8m2(dst, vec_dst, vsize);
|
||||
}
|
||||
|
||||
for ( ; i < n; i++, src += scn, dst += dcn )
|
||||
{
|
||||
unsigned char t0 = src[0], t1 = src[1], t2 = src[2];
|
||||
dst[2] = t0;
|
||||
dst[1] = t1;
|
||||
dst[0] = t2;
|
||||
if(dcn == 4)
|
||||
{
|
||||
unsigned char d = src[3];
|
||||
dst[3] = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void sBGRtoBGR(const unsigned char* src, unsigned char * dst, int n, int scn, int dcn, int bi)
|
||||
{
|
||||
for (int i = 0; i < n; i++, src += scn, dst += dcn)
|
||||
{
|
||||
unsigned char t0 = src[0], t1 = src[1], t2 = src[2];
|
||||
dst[bi ] = t0;
|
||||
dst[1] = t1;
|
||||
dst[bi^2] = t2;
|
||||
if(dcn == 4)
|
||||
{
|
||||
unsigned char d = scn == 4 ? src[3] : std::numeric_limits<unsigned char>::max();
|
||||
dst[3] = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int cvtBGRtoBGR(const unsigned char * src_data, size_t src_step, unsigned char * dst_data, size_t dst_step, int width, int height, int depth, int scn, int dcn, bool swapBlue)
|
||||
{
|
||||
if (depth != CV_8U)
|
||||
{
|
||||
return CV_HAL_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
const int blueIdx = swapBlue ? 2 : 0;
|
||||
if (scn == dcn)
|
||||
{
|
||||
if (!swapBlue)
|
||||
{
|
||||
return CV_HAL_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
const int vsize_pixels = 8;
|
||||
|
||||
if (scn == 4)
|
||||
{
|
||||
for (int i = 0; i < height; i++, src_data += src_step, dst_data += dst_step)
|
||||
{
|
||||
vBGRtoBGR(src_data, dst_data, index_array_32, width, scn, dcn, vsize_pixels, 32);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < height; i++, src_data += src_step, dst_data += dst_step)
|
||||
{
|
||||
vBGRtoBGR(src_data, dst_data, index_array_24, width, scn, dcn, vsize_pixels, 24);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < height; i++, src_data += src_step, dst_data += dst_step)
|
||||
sBGRtoBGR(src_data, dst_data, width, scn, dcn, blueIdx);
|
||||
}
|
||||
|
||||
return CV_HAL_ERROR_OK;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
23
3rdparty/kleidicv/CMakeLists.txt
vendored
Normal file
23
3rdparty/kleidicv/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
project(kleidicv_hal)
|
||||
|
||||
set(KLEIDICV_SOURCE_PATH "" CACHE PATH "Directory containing KleidiCV sources")
|
||||
ocv_update(KLEIDICV_SRC_COMMIT "0.1.0")
|
||||
ocv_update(KLEIDICV_SRC_HASH "9388f28cf2fbe3338197b2b57d491468")
|
||||
|
||||
if(KLEIDICV_SOURCE_PATH)
|
||||
set(THE_ROOT "${KLEIDICV_SOURCE_PATH}")
|
||||
else()
|
||||
ocv_download(FILENAME "kleidicv-${KLEIDICV_SRC_COMMIT}.tar.gz"
|
||||
HASH ${KLEIDICV_SRC_HASH}
|
||||
URL
|
||||
"${OPENCV_KLEIDICV_URL}"
|
||||
"$ENV{OPENCV_KLEIDICV_URL}"
|
||||
"https://gitlab.arm.com/kleidi/kleidicv/-/archive/${KLEIDICV_SRC_COMMIT}/"
|
||||
DESTINATION_DIR "${OpenCV_BINARY_DIR}/3rdparty/kleidicv/"
|
||||
ID KLEIDICV
|
||||
STATUS res
|
||||
UNPACK RELATIVE_URL)
|
||||
set(THE_ROOT "${OpenCV_BINARY_DIR}/3rdparty/kleidicv/kleidicv-${KLEIDICV_SRC_COMMIT}")
|
||||
endif()
|
||||
|
||||
include("${THE_ROOT}/adapters/opencv/CMakeLists.txt")
|
111
3rdparty/libjpeg-turbo/CMakeLists.txt
vendored
111
3rdparty/libjpeg-turbo/CMakeLists.txt
vendored
@ -1,12 +1,43 @@
|
||||
project(${JPEG_LIBRARY} C)
|
||||
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter -Wsign-compare -Wshorten-64-to-32 -Wimplicit-fallthrough)
|
||||
macro(boolean_number var)
|
||||
if(${var})
|
||||
set(${var} 1 ${ARGN})
|
||||
else()
|
||||
set(${var} 0 ${ARGN})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
set(VERSION_MAJOR 2)
|
||||
set(VERSION_MINOR 1)
|
||||
set(VERSION_REVISION 3)
|
||||
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION})
|
||||
set(LIBJPEG_TURBO_VERSION_NUMBER 2001003)
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter -Wsign-compare -Wshorten-64-to-32 -Wimplicit-fallthrough)
|
||||
if(APPLE)
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-variable) # NEON flags are not used on Mac
|
||||
endif()
|
||||
|
||||
if(CV_GCC AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13)
|
||||
# src/jchuff.c:1042:22: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS -Wstringop-overflow)
|
||||
endif()
|
||||
|
||||
set(VERSION 3.0.3)
|
||||
set(COPYRIGHT_YEAR "1991-2024")
|
||||
string(REPLACE "." ";" VERSION_TRIPLET ${VERSION})
|
||||
list(GET VERSION_TRIPLET 0 VERSION_MAJOR)
|
||||
list(GET VERSION_TRIPLET 1 VERSION_MINOR)
|
||||
list(GET VERSION_TRIPLET 2 VERSION_REVISION)
|
||||
function(pad_number NUMBER OUTPUT_LEN)
|
||||
string(LENGTH "${${NUMBER}}" INPUT_LEN)
|
||||
if(INPUT_LEN LESS OUTPUT_LEN)
|
||||
math(EXPR ZEROES "${OUTPUT_LEN} - ${INPUT_LEN} - 1")
|
||||
set(NUM ${${NUMBER}})
|
||||
foreach(C RANGE ${ZEROES})
|
||||
set(NUM "0${NUM}")
|
||||
endforeach()
|
||||
set(${NUMBER} ${NUM} PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
pad_number(VERSION_MINOR 3)
|
||||
pad_number(VERSION_REVISION 3)
|
||||
set(LIBJPEG_TURBO_VERSION_NUMBER ${VERSION_MAJOR}${VERSION_MINOR}${VERSION_REVISION})
|
||||
|
||||
string(TIMESTAMP BUILD "opencv-${OPENCV_VERSION}-libjpeg-turbo")
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
@ -66,8 +97,8 @@ include(CheckCSourceCompiles)
|
||||
include(CheckIncludeFiles)
|
||||
include(CheckTypeSize)
|
||||
|
||||
check_type_size("size_t" SIZEOF_SIZE_T)
|
||||
check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG)
|
||||
check_type_size("size_t" SIZE_T)
|
||||
check_type_size("unsigned long" UNSIGNED_LONG)
|
||||
|
||||
if(SIZEOF_SIZE_T EQUAL SIZEOF_UNSIGNED_LONG)
|
||||
check_c_source_compiles("int main(int argc, char **argv) { unsigned long a = argc; return __builtin_ctzl(a); }"
|
||||
@ -103,33 +134,34 @@ if(WITH_ARITH_DEC)
|
||||
set(D_ARITH_CODING_SUPPORTED 1)
|
||||
endif()
|
||||
|
||||
set(JPEG_LIB_VERSION 62)
|
||||
set(JPEG_LIB_VERSION 70)
|
||||
|
||||
# OpenCV
|
||||
set(JPEG_LIB_VERSION "${VERSION}-${JPEG_LIB_VERSION}" PARENT_SCOPE)
|
||||
|
||||
set(THREAD_LOCAL "") # WITH_TURBOJPEG is not used
|
||||
|
||||
add_definitions(-DNO_GETENV -DNO_PUTENV)
|
||||
|
||||
if(MSVC)
|
||||
add_definitions(-W3 -wd4996 -wd4018)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
configure_file(jconfig.h.win.in jconfig.h)
|
||||
else()
|
||||
configure_file(jconfig.h.in jconfig.h)
|
||||
endif()
|
||||
configure_file(jconfigint.h.in jconfigint.h)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
|
||||
set(JPEG_SOURCES jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c
|
||||
jcicc.c jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c
|
||||
jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c jdatadst.c
|
||||
jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c jdicc.c jdinput.c
|
||||
jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c jdpostct.c jdsample.c
|
||||
jdtrans.c jerror.c jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c
|
||||
jidctint.c jidctred.c jquant1.c jquant2.c jutils.c jmemmgr.c jmemnobs.c)
|
||||
set(JPEG16_SOURCES jcapistd.c jccolor.c jcdiffct.c jclossls.c jcmainct.c
|
||||
jcprepct.c jcsample.c jdapistd.c jdcolor.c jddiffct.c jdlossls.c jdmainct.c
|
||||
jdpostct.c jdsample.c jutils.c)
|
||||
|
||||
set(JPEG12_SOURCES ${JPEG16_SOURCES} jccoefct.c jcdctmgr.c jdcoefct.c
|
||||
jddctmgr.c jdmerge.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c
|
||||
jidctred.c jquant1.c jquant2.c)
|
||||
|
||||
set(JPEG_SOURCES ${JPEG12_SOURCES} jcapimin.c jchuff.c jcicc.c jcinit.c
|
||||
jclhuff.c jcmarker.c jcmaster.c jcomapi.c jcparam.c jcphuff.c jctrans.c
|
||||
jdapimin.c jdatadst.c jdatasrc.c jdhuff.c jdicc.c jdinput.c jdlhuff.c
|
||||
jdmarker.c jdmaster.c jdphuff.c jdtrans.c jerror.c jfdctflt.c jmemmgr.c
|
||||
jmemnobs.c jpeg_nbits.c)
|
||||
|
||||
if(WITH_ARITH_ENC OR WITH_ARITH_DEC)
|
||||
set(JPEG_SOURCES ${JPEG_SOURCES} jaricom.c)
|
||||
@ -143,7 +175,7 @@ if(WITH_ARITH_DEC)
|
||||
set(JPEG_SOURCES ${JPEG_SOURCES} jdarith.c)
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
# Use the maximum optimization level for release builds
|
||||
foreach(var CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO)
|
||||
if(${var} MATCHES "-O2")
|
||||
@ -166,6 +198,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(CheckTypeSize)
|
||||
check_type_size("size_t" SIZE_T)
|
||||
check_type_size("unsigned long" UNSIGNED_LONG)
|
||||
|
||||
if(ENABLE_LIBJPEG_TURBO_SIMD)
|
||||
add_subdirectory(src/simd)
|
||||
if(NEON_INTRINSICS)
|
||||
@ -181,19 +217,28 @@ if(WITH_SIMD)
|
||||
if(MSVC_IDE OR XCODE)
|
||||
set_source_files_properties(${SIMD_OBJS} PROPERTIES GENERATED 1)
|
||||
endif()
|
||||
else()
|
||||
add_library(jsimd OBJECT src/jsimd_none.c)
|
||||
set_target_properties(jsimd PROPERTIES FOLDER "3rdparty")
|
||||
if(NOT WIN32 AND (CMAKE_POSITION_INDEPENDENT_CODE OR ENABLE_SHARED))
|
||||
set_target_properties(jsimd PROPERTIES POSITION_INDEPENDENT_CODE 1)
|
||||
endif()
|
||||
set(SIMD_TARGET_OBJECTS $<TARGET_OBJECTS:simd>)
|
||||
endif()
|
||||
|
||||
configure_file(jversion.h.in jversion.h)
|
||||
configure_file(jconfig.h.in jconfig.h)
|
||||
configure_file(jconfigint.h.in jconfigint.h)
|
||||
|
||||
ocv_list_add_prefix(JPEG16_SOURCES src/)
|
||||
ocv_list_add_prefix(JPEG12_SOURCES src/)
|
||||
ocv_list_add_prefix(JPEG_SOURCES src/)
|
||||
|
||||
set(JPEG_SOURCES ${JPEG_SOURCES} ${SIMD_OBJS})
|
||||
|
||||
add_library(${JPEG_LIBRARY} STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${JPEG_SOURCES} $<TARGET_OBJECTS:jsimd> ${SIMD_OBJS})
|
||||
add_library(jpeg12-static OBJECT ${JPEG12_SOURCES})
|
||||
set_property(TARGET jpeg12-static PROPERTY COMPILE_FLAGS
|
||||
"-DBITS_IN_JSAMPLE=12")
|
||||
add_library(jpeg16-static OBJECT ${JPEG16_SOURCES})
|
||||
set_property(TARGET jpeg16-static PROPERTY COMPILE_FLAGS
|
||||
"-DBITS_IN_JSAMPLE=16")
|
||||
add_library(${JPEG_LIBRARY} STATIC ${JPEG_SOURCES} ${SIMD_TARGET_OBJECTS}
|
||||
${SIMD_OBJS} $<TARGET_OBJECTS:jpeg12-static>
|
||||
$<TARGET_OBJECTS:jpeg16-static>)
|
||||
|
||||
set_target_properties(${JPEG_LIBRARY}
|
||||
PROPERTIES OUTPUT_NAME ${JPEG_LIBRARY}
|
||||
@ -204,7 +249,9 @@ set_target_properties(${JPEG_LIBRARY}
|
||||
)
|
||||
|
||||
if(ENABLE_SOLUTION_FOLDERS)
|
||||
set_target_properties(${JPEG_LIBRARY} PROPERTIES FOLDER "3rdparty")
|
||||
set_target_properties(${JPEG_LIBRARY} PROPERTIES FOLDER "3rdparty/jpeg")
|
||||
set_target_properties(jpeg12-static PROPERTIES FOLDER "3rdparty/jpeg")
|
||||
set_target_properties(jpeg16-static PROPERTIES FOLDER "3rdparty/jpeg")
|
||||
endif()
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
|
33
3rdparty/libjpeg-turbo/LICENSE.md
vendored
33
3rdparty/libjpeg-turbo/LICENSE.md
vendored
@ -1,30 +1,33 @@
|
||||
libjpeg-turbo Licenses
|
||||
======================
|
||||
|
||||
libjpeg-turbo is covered by three compatible BSD-style open source licenses:
|
||||
libjpeg-turbo is covered by two compatible BSD-style open source licenses:
|
||||
|
||||
- The IJG (Independent JPEG Group) License, which is listed in
|
||||
[README.ijg](README.ijg)
|
||||
|
||||
This license applies to the libjpeg API library and associated programs
|
||||
(any code inherited from libjpeg, and any modifications to that code.)
|
||||
This license applies to the libjpeg API library and associated programs,
|
||||
including any code inherited from libjpeg and any modifications to that
|
||||
code. Note that the libjpeg-turbo SIMD source code bears the
|
||||
[zlib License](https://opensource.org/licenses/Zlib), but in the context of
|
||||
the overall libjpeg API library, the terms of the zlib License are subsumed
|
||||
by the terms of the IJG License.
|
||||
|
||||
- The Modified (3-clause) BSD License, which is listed below
|
||||
|
||||
This license covers the TurboJPEG API library and associated programs, as
|
||||
well as the build system.
|
||||
|
||||
- The [zlib License](https://opensource.org/licenses/Zlib)
|
||||
|
||||
This license is a subset of the other two, and it covers the libjpeg-turbo
|
||||
SIMD extensions.
|
||||
This license applies to the TurboJPEG API library and associated programs, as
|
||||
well as the build system. Note that the TurboJPEG API library wraps the
|
||||
libjpeg API library, so in the context of the overall TurboJPEG API library,
|
||||
both the terms of the IJG License and the terms of the Modified (3-clause)
|
||||
BSD License apply.
|
||||
|
||||
|
||||
Complying with the libjpeg-turbo Licenses
|
||||
=========================================
|
||||
|
||||
This section provides a roll-up of the libjpeg-turbo licensing terms, to the
|
||||
best of our understanding.
|
||||
best of our understanding. This is not a license in and of itself. It is
|
||||
intended solely for clarification.
|
||||
|
||||
1. If you are distributing a modified version of the libjpeg-turbo source,
|
||||
then:
|
||||
@ -38,7 +41,7 @@ best of our understanding.
|
||||
- Clauses 1 and 3 of the zlib License
|
||||
|
||||
2. You must add your own copyright notice to the header of each source
|
||||
file you modified, so others can tell that you modified that file (if
|
||||
file you modified, so others can tell that you modified that file. (If
|
||||
there is not an existing copyright header in that file, then you can
|
||||
simply add a notice stating that you modified the file.)
|
||||
|
||||
@ -91,7 +94,7 @@ best of our understanding.
|
||||
The Modified (3-clause) BSD License
|
||||
===================================
|
||||
|
||||
Copyright (C)2009-2022 D. R. Commander. All Rights Reserved.<br>
|
||||
Copyright (C)2009-2023 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
|
||||
@ -119,8 +122,8 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Why Three Licenses?
|
||||
===================
|
||||
Why Two Licenses?
|
||||
=================
|
||||
|
||||
The zlib License could have been used instead of the Modified (3-clause) BSD
|
||||
License, and since the IJG License effectively subsumes the distribution
|
||||
|
24
3rdparty/libjpeg-turbo/README.ijg
vendored
24
3rdparty/libjpeg-turbo/README.ijg
vendored
@ -43,7 +43,7 @@ User documentation:
|
||||
change.log Version-to-version change highlights.
|
||||
Programmer and internal documentation:
|
||||
libjpeg.txt How to use the JPEG library in your own programs.
|
||||
example.txt Sample code for calling the JPEG library.
|
||||
example.c Sample code for calling the JPEG library.
|
||||
structure.txt Overview of the JPEG library's internal structure.
|
||||
coderules.txt Coding style rules --- please read if you contribute code.
|
||||
|
||||
@ -68,17 +68,17 @@ other abrupt features may not compress well with JPEG, and a higher JPEG
|
||||
quality may have to be used to avoid visible compression artifacts with such
|
||||
images.
|
||||
|
||||
JPEG is lossy, meaning that the output pixels are not necessarily identical to
|
||||
the input pixels. However, on photographic content and other "smooth" images,
|
||||
very good compression ratios can be obtained with no visible compression
|
||||
artifacts, and extremely high compression ratios are possible if you are
|
||||
willing to sacrifice image quality (by reducing the "quality" setting in the
|
||||
compressor.)
|
||||
JPEG is normally lossy, meaning that the output pixels are not necessarily
|
||||
identical to the input pixels. However, on photographic content and other
|
||||
"smooth" images, very good compression ratios can be obtained with no visible
|
||||
compression artifacts, and extremely high compression ratios are possible if
|
||||
you are willing to sacrifice image quality (by reducing the "quality" setting
|
||||
in the compressor.)
|
||||
|
||||
This software implements JPEG baseline, extended-sequential, and progressive
|
||||
compression processes. Provision is made for supporting all variants of these
|
||||
processes, although some uncommon parameter settings aren't implemented yet.
|
||||
We have made no provision for supporting the hierarchical or lossless
|
||||
This software implements JPEG baseline, extended-sequential, progressive, and
|
||||
lossless compression processes. Provision is made for supporting all variants
|
||||
of these processes, although some uncommon parameter settings aren't
|
||||
implemented yet. We have made no provision for supporting the hierarchical
|
||||
processes defined in the standard.
|
||||
|
||||
We provide a set of library routines for reading and writing JPEG image files,
|
||||
@ -241,7 +241,7 @@ This software implements ITU T.81 | ISO/IEC 10918 with some extensions from
|
||||
ITU T.871 | ISO/IEC 10918-5 (JPEG File Interchange Format-- see REFERENCES).
|
||||
Informally, the term "JPEG image" or "JPEG file" most often refers to JFIF or
|
||||
a subset thereof, but there are other formats containing the name "JPEG" that
|
||||
are incompatible with the DCT-based JPEG standard or with JFIF (for instance,
|
||||
are incompatible with the original JPEG standard or with JFIF (for instance,
|
||||
JPEG 2000 and JPEG XR). This software therefore does not support these
|
||||
formats. Indeed, one of the original reasons for developing this free software
|
||||
was to help force convergence on a common, interoperable format standard for
|
||||
|
78
3rdparty/libjpeg-turbo/README.md
vendored
78
3rdparty/libjpeg-turbo/README.md
vendored
@ -21,7 +21,26 @@ derivative of libjpeg v6b developed by Miyasaka Masaru. The TigerVNC and
|
||||
VirtualGL projects made numerous enhancements to the codec in 2009, and in
|
||||
early 2010, libjpeg-turbo spun off into an independent project, with the goal
|
||||
of making high-speed JPEG compression/decompression technology available to a
|
||||
broader range of users and developers.
|
||||
broader range of users and developers. libjpeg-turbo is an ISO/IEC and ITU-T
|
||||
reference implementation of the JPEG standard.
|
||||
|
||||
More information about libjpeg-turbo can be found at
|
||||
<https://libjpeg-turbo.org>.
|
||||
|
||||
|
||||
Funding
|
||||
=======
|
||||
|
||||
libjpeg-turbo is an independent open source project, but we rely on patronage
|
||||
and funded development in order to maintain that independence. The easiest way
|
||||
to ensure that libjpeg-turbo remains community-focused and free of any one
|
||||
organization's agenda is to
|
||||
[sponsor our project through GitHub](https://github.com/sponsors/libjpeg-turbo).
|
||||
All sponsorship money goes directly toward funding the labor necessary to
|
||||
maintain libjpeg-turbo, support the user community, and implement bug fixes and
|
||||
strategically important features.
|
||||
|
||||
[](https://github.com/sponsors/libjpeg-turbo)
|
||||
|
||||
|
||||
License
|
||||
@ -245,16 +264,6 @@ programs that need them, without breaking ABI compatibility for programs that
|
||||
don't, and it allows those functions to be provided in the "official"
|
||||
libjpeg-turbo binaries.
|
||||
|
||||
Those who are concerned about maintaining strict conformance with the libjpeg
|
||||
v6b or v7 API can pass an argument of `-DWITH_MEM_SRCDST=0` to `cmake` prior to
|
||||
building libjpeg-turbo. This will restore the pre-1.3 behavior, in which
|
||||
`jpeg_mem_src()` and `jpeg_mem_dest()` are only included when emulating the
|
||||
libjpeg v8 API/ABI.
|
||||
|
||||
On Un*x systems, including the in-memory source/destination managers changes
|
||||
the dynamic library version from 62.2.0 to 62.3.0 if using libjpeg v6b API/ABI
|
||||
emulation and from 7.2.0 to 7.3.0 if using libjpeg v7 API/ABI emulation.
|
||||
|
||||
Note that, on most Un*x systems, the dynamic linker will not look for a
|
||||
function in a library until that function is actually used. Thus, if a program
|
||||
is built against libjpeg-turbo 1.3+ and uses `jpeg_mem_src()` or
|
||||
@ -274,30 +283,35 @@ Mathematical Compatibility
|
||||
==========================
|
||||
|
||||
For the most part, libjpeg-turbo should produce identical output to libjpeg
|
||||
v6b. The one exception to this is when using the floating point DCT/IDCT, in
|
||||
which case the outputs of libjpeg v6b and libjpeg-turbo can differ for the
|
||||
following reasons:
|
||||
v6b. There are two exceptions:
|
||||
|
||||
- The SSE/SSE2 floating point DCT implementation in libjpeg-turbo is ever so
|
||||
slightly more accurate than the implementation in libjpeg v6b, but not by
|
||||
any amount perceptible to human vision (generally in the range of 0.01 to
|
||||
0.08 dB gain in PNSR.)
|
||||
1. When decompressing a JPEG image that uses 4:4:0 chrominance subsampling, the
|
||||
outputs of libjpeg v6b and libjpeg-turbo can differ because libjpeg-turbo
|
||||
implements a "fancy" (smooth) 4:4:0 upsampling algorithm and libjpeg did not.
|
||||
|
||||
- When not using the SIMD extensions, libjpeg-turbo uses the more accurate
|
||||
(and slightly faster) floating point IDCT algorithm introduced in libjpeg
|
||||
v8a as opposed to the algorithm used in libjpeg v6b. It should be noted,
|
||||
however, that this algorithm basically brings the accuracy of the floating
|
||||
point IDCT in line with the accuracy of the accurate integer IDCT. The
|
||||
floating point DCT/IDCT algorithms are mainly a legacy feature, and they do
|
||||
not produce significantly more accuracy than the accurate integer algorithms
|
||||
(to put numbers on this, the typical difference in PNSR between the two
|
||||
algorithms is less than 0.10 dB, whereas changing the quality level by 1 in
|
||||
the upper range of the quality scale is typically more like a 1.0 dB
|
||||
difference.)
|
||||
2. When using the floating point DCT/IDCT, the outputs of libjpeg v6b and
|
||||
libjpeg-turbo can differ for the following reasons:
|
||||
|
||||
- If the floating point algorithms in libjpeg-turbo are not implemented using
|
||||
SIMD instructions on a particular platform, then the accuracy of the
|
||||
floating point DCT/IDCT can depend on the compiler settings.
|
||||
- The SSE/SSE2 floating point DCT implementation in libjpeg-turbo is ever
|
||||
so slightly more accurate than the implementation in libjpeg v6b, but not
|
||||
by any amount perceptible to human vision (generally in the range of 0.01
|
||||
to 0.08 dB gain in PNSR.)
|
||||
|
||||
- When not using the SIMD extensions, libjpeg-turbo uses the more accurate
|
||||
(and slightly faster) floating point IDCT algorithm introduced in libjpeg
|
||||
v8a as opposed to the algorithm used in libjpeg v6b. It should be noted,
|
||||
however, that this algorithm basically brings the accuracy of the
|
||||
floating point IDCT in line with the accuracy of the accurate integer
|
||||
IDCT. The floating point DCT/IDCT algorithms are mainly a legacy
|
||||
feature, and they do not produce significantly more accuracy than the
|
||||
accurate integer algorithms. (To put numbers on this, the typical
|
||||
difference in PNSR between the two algorithms is less than 0.10 dB,
|
||||
whereas changing the quality level by 1 in the upper range of the quality
|
||||
scale is typically more like a 1.0 dB difference.)
|
||||
|
||||
- If the floating point algorithms in libjpeg-turbo are not implemented
|
||||
using SIMD instructions on a particular platform, then the accuracy of
|
||||
the floating point DCT/IDCT can depend on the compiler settings.
|
||||
|
||||
While libjpeg-turbo does emulate the libjpeg v8 API/ABI, under the hood it is
|
||||
still using the same algorithms as libjpeg v6b, so there are several specific
|
||||
|
68
3rdparty/libjpeg-turbo/jconfig.h.in
vendored
68
3rdparty/libjpeg-turbo/jconfig.h.in
vendored
@ -9,60 +9,52 @@
|
||||
/* libjpeg-turbo version in integer form */
|
||||
#define LIBJPEG_TURBO_VERSION_NUMBER @LIBJPEG_TURBO_VERSION_NUMBER@
|
||||
|
||||
/* Support arithmetic encoding */
|
||||
/* Support arithmetic encoding when using 8-bit samples */
|
||||
#cmakedefine C_ARITH_CODING_SUPPORTED 1
|
||||
|
||||
/* Support arithmetic decoding */
|
||||
/* Support arithmetic decoding when using 8-bit samples */
|
||||
#cmakedefine D_ARITH_CODING_SUPPORTED 1
|
||||
|
||||
/* Support in-memory source/destination managers */
|
||||
#cmakedefine MEM_SRCDST_SUPPORTED 1
|
||||
#define MEM_SRCDST_SUPPORTED 1
|
||||
|
||||
/* Use accelerated SIMD routines. */
|
||||
/* Use accelerated SIMD routines when using 8-bit samples */
|
||||
#cmakedefine WITH_SIMD 1
|
||||
|
||||
/*
|
||||
* Define BITS_IN_JSAMPLE as either
|
||||
* 8 for 8-bit sample values (the usual setting)
|
||||
* 12 for 12-bit sample values
|
||||
* Only 8 and 12 are legal data precisions for lossy JPEG according to the
|
||||
* JPEG standard, and the IJG code does not support anything else!
|
||||
* We do not support run-time selection of data precision, sorry.
|
||||
/* This version of libjpeg-turbo supports run-time selection of data precision,
|
||||
* so BITS_IN_JSAMPLE is no longer used to specify the data precision at build
|
||||
* time. However, some downstream software expects the macro to be defined.
|
||||
* Since 12-bit data precision is an opt-in feature that requires explicitly
|
||||
* calling 12-bit-specific libjpeg API functions and using 12-bit-specific data
|
||||
* types, the unmodified portion of the libjpeg API still behaves as if it were
|
||||
* built for 8-bit precision, and JSAMPLE is still literally an 8-bit data
|
||||
* type. Thus, it is correct to define BITS_IN_JSAMPLE to 8 here.
|
||||
*/
|
||||
#ifndef BITS_IN_JSAMPLE
|
||||
#define BITS_IN_JSAMPLE 8
|
||||
#endif
|
||||
|
||||
#define BITS_IN_JSAMPLE @BITS_IN_JSAMPLE@ /* use 8 or 12 */
|
||||
#ifdef _WIN32
|
||||
|
||||
/* Define to 1 if you have the <locale.h> header file. */
|
||||
#cmakedefine HAVE_LOCALE_H 1
|
||||
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||
|
||||
/* Define to 1 if you have the <stddef.h> header file. */
|
||||
#cmakedefine HAVE_STDDEF_H 1
|
||||
/* Define "boolean" as unsigned char, not int, per Windows custom */
|
||||
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
|
||||
typedef unsigned char boolean;
|
||||
#endif
|
||||
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#cmakedefine HAVE_STDLIB_H 1
|
||||
/* Define "INT32" as int, not long, per Windows custom */
|
||||
#if !(defined(_BASETSD_H_) || defined(_BASETSD_H)) /* don't conflict if basetsd.h already read */
|
||||
typedef short INT16;
|
||||
typedef signed int INT32;
|
||||
#endif
|
||||
#define XMD_H /* prevent jmorecfg.h from redefining it */
|
||||
|
||||
/* 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
|
||||
#else
|
||||
|
||||
/* 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 */
|
||||
#endif
|
||||
|
33
3rdparty/libjpeg-turbo/jconfig.h.win.in
vendored
33
3rdparty/libjpeg-turbo/jconfig.h.win.in
vendored
@ -1,33 +0,0 @@
|
||||
#define JPEG_LIB_VERSION @JPEG_LIB_VERSION@
|
||||
#define LIBJPEG_TURBO_VERSION @VERSION@
|
||||
#define LIBJPEG_TURBO_VERSION_NUMBER @LIBJPEG_TURBO_VERSION_NUMBER@
|
||||
|
||||
#cmakedefine C_ARITH_CODING_SUPPORTED
|
||||
#cmakedefine D_ARITH_CODING_SUPPORTED
|
||||
#cmakedefine MEM_SRCDST_SUPPORTED
|
||||
#cmakedefine WITH_SIMD
|
||||
|
||||
#define BITS_IN_JSAMPLE @BITS_IN_JSAMPLE@ /* use 8 or 12 */
|
||||
|
||||
#define HAVE_STDDEF_H
|
||||
#define HAVE_STDLIB_H
|
||||
#undef NEED_SYS_TYPES_H
|
||||
#undef NEED_BSD_STRINGS
|
||||
|
||||
#define HAVE_UNSIGNED_CHAR
|
||||
#define HAVE_UNSIGNED_SHORT
|
||||
#undef INCOMPLETE_TYPES_BROKEN
|
||||
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||
|
||||
/* Define "boolean" as unsigned char, not int, per Windows custom */
|
||||
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
|
||||
typedef unsigned char boolean;
|
||||
#endif
|
||||
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
|
||||
|
||||
/* Define "INT32" as int, not long, per Windows custom */
|
||||
#if !(defined(_BASETSD_H_) || defined(_BASETSD_H)) /* don't conflict if basetsd.h already read */
|
||||
typedef short INT16;
|
||||
typedef signed int INT32;
|
||||
#endif
|
||||
#define XMD_H /* prevent jmorecfg.h from redefining it */
|
44
3rdparty/libjpeg-turbo/jconfigint.h.in
vendored
44
3rdparty/libjpeg-turbo/jconfigint.h.in
vendored
@ -1,19 +1,14 @@
|
||||
/* libjpeg-turbo build number */
|
||||
#define BUILD "@BUILD@"
|
||||
|
||||
/* How to hide global symbols. */
|
||||
#define HIDDEN @HIDDEN@
|
||||
|
||||
/* Compiler's inline keyword */
|
||||
#undef inline
|
||||
|
||||
/* How to obtain function inlining. */
|
||||
#ifndef INLINE
|
||||
#if defined(__GNUC__)
|
||||
#define INLINE inline __attribute__((always_inline))
|
||||
#elif defined(_MSC_VER)
|
||||
#define INLINE __forceinline
|
||||
#else
|
||||
#define INLINE
|
||||
#endif
|
||||
#endif
|
||||
#define INLINE @INLINE@
|
||||
|
||||
/* How to obtain thread-local storage */
|
||||
#define THREAD_LOCAL @THREAD_LOCAL@
|
||||
@ -25,7 +20,7 @@
|
||||
#define VERSION "@VERSION@"
|
||||
|
||||
/* The size of `size_t', as computed by sizeof. */
|
||||
#define SIZEOF_SIZE_T @SIZEOF_SIZE_T@
|
||||
#define SIZEOF_SIZE_T @SIZE_T@
|
||||
|
||||
/* Define if your compiler has __builtin_ctzl() and sizeof(unsigned long) == sizeof(size_t). */
|
||||
#cmakedefine HAVE_BUILTIN_CTZL
|
||||
@ -50,3 +45,32 @@
|
||||
#else
|
||||
#define FALLTHROUGH
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Define BITS_IN_JSAMPLE as either
|
||||
* 8 for 8-bit sample values (the usual setting)
|
||||
* 12 for 12-bit sample values
|
||||
* Only 8 and 12 are legal data precisions for lossy JPEG according to the
|
||||
* JPEG standard, and the IJG code does not support anything else!
|
||||
*/
|
||||
|
||||
#ifndef BITS_IN_JSAMPLE
|
||||
#define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
|
||||
#endif
|
||||
|
||||
#undef C_ARITH_CODING_SUPPORTED
|
||||
#undef D_ARITH_CODING_SUPPORTED
|
||||
#undef WITH_SIMD
|
||||
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
|
||||
/* Support arithmetic encoding */
|
||||
#cmakedefine C_ARITH_CODING_SUPPORTED 1
|
||||
|
||||
/* Support arithmetic decoding */
|
||||
#cmakedefine D_ARITH_CODING_SUPPORTED 1
|
||||
|
||||
/* Use accelerated SIMD routines. */
|
||||
#cmakedefine WITH_SIMD 1
|
||||
|
||||
#endif
|
||||
|
@ -4,7 +4,7 @@
|
||||
* 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-2024, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -36,19 +36,21 @@
|
||||
* their code
|
||||
*/
|
||||
|
||||
#define JCOPYRIGHT \
|
||||
"Copyright (C) 2009-2021 D. R. Commander\n" \
|
||||
#define JCOPYRIGHT1 \
|
||||
"Copyright (C) 2009-2024 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) 2011-2016 Siarhei Siamashka\n" \
|
||||
"Copyright (C) 2015 Intel Corporation\n" \
|
||||
"Copyright (C) 2015 Intel Corporation\n"
|
||||
#define JCOPYRIGHT2 \
|
||||
"Copyright (C) 2013-2014 Linaro Limited\n" \
|
||||
"Copyright (C) 2013-2014 MIPS Technologies, Inc.\n" \
|
||||
"Copyright (C) 2009, 2012 Pierre Ossman for Cendio AB\n" \
|
||||
"Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)\n" \
|
||||
"Copyright (C) 1999-2006 MIYASAKA Masaru\n" \
|
||||
"Copyright (C) 1991-2020 Thomas G. Lane, Guido Vollbeding"
|
||||
"Copyright (C) 1999 Ken Murchison\n" \
|
||||
"Copyright (C) 1991-2020 Thomas G. Lane, Guido Vollbeding\n"
|
||||
|
||||
#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"
|
841
3rdparty/libjpeg-turbo/src/cjpeg.c
vendored
Normal file
841
3rdparty/libjpeg-turbo/src/cjpeg.c
vendored
Normal file
@ -0,0 +1,841 @@
|
||||
/*
|
||||
* cjpeg.c
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* Modified 2003-2011 by Guido Vollbeding.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2010, 2013-2014, 2017, 2019-2022, 2024, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file contains a command-line user interface for the JPEG compressor.
|
||||
* It should work on any system with Unix- or MS-DOS-style command lines.
|
||||
*
|
||||
* Two different command line styles are permitted, depending on the
|
||||
* compile-time switch TWO_FILE_COMMANDLINE:
|
||||
* cjpeg [options] inputfile outputfile
|
||||
* cjpeg [options] [inputfile]
|
||||
* In the second style, output is always to standard output, which you'd
|
||||
* normally redirect to a file or pipe to some other program. Input is
|
||||
* either from a named file or from standard input (typically redirected).
|
||||
* The second style is convenient on Unix but is unhelpful on systems that
|
||||
* don't support pipes. Also, you MUST use the first style if your system
|
||||
* doesn't do binary I/O to stdin/stdout.
|
||||
* To simplify script writing, the "-outfile" switch is provided. The syntax
|
||||
* cjpeg [options] -outfile outputfile inputfile
|
||||
* 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 "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
|
||||
#include "jversion.h" /* for version message */
|
||||
#include "jconfigint.h"
|
||||
|
||||
|
||||
/* Create the add-on message string table. */
|
||||
|
||||
#define JMESSAGE(code, string) string,
|
||||
|
||||
static const char * const cdjpeg_message_table[] = {
|
||||
#include "cderror.h"
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* This routine determines what format the input file is,
|
||||
* and selects the appropriate input-reading module.
|
||||
*
|
||||
* To determine which family of input formats the file belongs to,
|
||||
* we may look only at the first byte of the file, since C does not
|
||||
* guarantee that more than one character can be pushed back with ungetc.
|
||||
* Looking at additional bytes would require one of these approaches:
|
||||
* 1) assume we can fseek() the input file (fails for piped input);
|
||||
* 2) assume we can push back more than one character (works in
|
||||
* some C implementations, but unportable);
|
||||
* 3) provide our own buffering (breaks input readers that want to use
|
||||
* stdio directly);
|
||||
* or 4) don't put back the data, and modify the input_init methods to assume
|
||||
* they start reading after the start of file.
|
||||
* #1 is attractive for MS-DOS but is untenable on Unix.
|
||||
*
|
||||
* The most portable solution for file types that can't be identified by their
|
||||
* first byte is to make the user tell us what they are. This is also the
|
||||
* only approach for "raw" file types that contain only arbitrary values.
|
||||
* We presently apply this method for Targa files. Most of the time Targa
|
||||
* files start with 0x00, so we recognize that case. Potentially, however,
|
||||
* a Targa file could start with any byte value (byte 0 is the length of the
|
||||
* seldom-used ID field), so we provide a switch to force Targa input mode.
|
||||
*/
|
||||
|
||||
static boolean is_targa; /* records user -targa switch */
|
||||
|
||||
|
||||
LOCAL(cjpeg_source_ptr)
|
||||
select_file_type(j_compress_ptr cinfo, FILE *infile)
|
||||
{
|
||||
int c;
|
||||
|
||||
if (is_targa) {
|
||||
#ifdef TARGA_SUPPORTED
|
||||
return jinit_read_targa(cinfo);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_TGA_NOTCOMP);
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((c = getc(infile)) == EOF)
|
||||
ERREXIT(cinfo, JERR_INPUT_EMPTY);
|
||||
if (ungetc(c, infile) == EOF)
|
||||
ERREXIT(cinfo, JERR_UNGETC_FAILED);
|
||||
|
||||
switch (c) {
|
||||
#ifdef BMP_SUPPORTED
|
||||
case 'B':
|
||||
return jinit_read_bmp(cinfo, TRUE);
|
||||
#endif
|
||||
#ifdef GIF_SUPPORTED
|
||||
case 'G':
|
||||
if (cinfo->data_precision == 16) {
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
return j16init_read_gif(cinfo);
|
||||
#else
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
break;
|
||||
#endif
|
||||
} else if (cinfo->data_precision == 12)
|
||||
return j12init_read_gif(cinfo);
|
||||
else
|
||||
return jinit_read_gif(cinfo);
|
||||
#endif
|
||||
#ifdef PPM_SUPPORTED
|
||||
case 'P':
|
||||
if (cinfo->data_precision == 16) {
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
return j16init_read_ppm(cinfo);
|
||||
#else
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
break;
|
||||
#endif
|
||||
} else if (cinfo->data_precision == 12)
|
||||
return j12init_read_ppm(cinfo);
|
||||
else
|
||||
return jinit_read_ppm(cinfo);
|
||||
#endif
|
||||
#ifdef TARGA_SUPPORTED
|
||||
case 0x00:
|
||||
return jinit_read_targa(cinfo);
|
||||
#endif
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_UNKNOWN_FORMAT);
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL; /* suppress compiler warnings */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Argument-parsing code.
|
||||
* The switch parser is designed to be useful with DOS-style command line
|
||||
* syntax, ie, intermixed switches and file names, where only the switches
|
||||
* to the left of a given file name affect processing of that file.
|
||||
* The main program in this file doesn't actually use this capability...
|
||||
*/
|
||||
|
||||
|
||||
static const char *progname; /* program name for error messages */
|
||||
static char *icc_filename; /* for -icc switch */
|
||||
static char *outfilename; /* for -outfile switch */
|
||||
static boolean memdst; /* for -memdst switch */
|
||||
static boolean report; /* for -report switch */
|
||||
static boolean strict; /* for -strict switch */
|
||||
|
||||
|
||||
#ifdef CJPEG_FUZZER
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
struct my_error_mgr {
|
||||
struct jpeg_error_mgr pub;
|
||||
jmp_buf setjmp_buffer;
|
||||
};
|
||||
|
||||
void my_error_exit(j_common_ptr cinfo)
|
||||
{
|
||||
struct my_error_mgr *myerr = (struct my_error_mgr *)cinfo->err;
|
||||
|
||||
longjmp(myerr->setjmp_buffer, 1);
|
||||
}
|
||||
|
||||
static void my_emit_message_fuzzer(j_common_ptr cinfo, int msg_level)
|
||||
{
|
||||
if (msg_level < 0)
|
||||
cinfo->err->num_warnings++;
|
||||
}
|
||||
|
||||
#define HANDLE_ERROR() { \
|
||||
if (cinfo.global_state > CSTATE_START) { \
|
||||
if (memdst && outbuffer) \
|
||||
(*cinfo.dest->term_destination) (&cinfo); \
|
||||
jpeg_abort_compress(&cinfo); \
|
||||
} \
|
||||
jpeg_destroy_compress(&cinfo); \
|
||||
if (input_file != stdin && input_file != NULL) \
|
||||
fclose(input_file); \
|
||||
if (memdst) \
|
||||
free(outbuffer); \
|
||||
return EXIT_FAILURE; \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
usage(void)
|
||||
/* complain about bad command line */
|
||||
{
|
||||
fprintf(stderr, "usage: %s [switches] ", progname);
|
||||
#ifdef TWO_FILE_COMMANDLINE
|
||||
fprintf(stderr, "inputfile outputfile\n");
|
||||
#else
|
||||
fprintf(stderr, "[inputfile]\n");
|
||||
#endif
|
||||
|
||||
fprintf(stderr, "Switches (names may be abbreviated):\n");
|
||||
fprintf(stderr, " -quality N[,...] Compression quality (0..100; 5-95 is most useful range,\n");
|
||||
fprintf(stderr, " default is 75)\n");
|
||||
fprintf(stderr, " -grayscale Create monochrome JPEG file\n");
|
||||
fprintf(stderr, " -rgb Create RGB JPEG file\n");
|
||||
#ifdef ENTROPY_OPT_SUPPORTED
|
||||
fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n");
|
||||
#endif
|
||||
#ifdef C_PROGRESSIVE_SUPPORTED
|
||||
fprintf(stderr, " -progressive Create progressive JPEG file\n");
|
||||
#endif
|
||||
#ifdef TARGA_SUPPORTED
|
||||
fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n");
|
||||
#endif
|
||||
fprintf(stderr, "Switches for advanced users:\n");
|
||||
fprintf(stderr, " -precision N Create JPEG file with N-bit data precision\n");
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
fprintf(stderr, " (N is 8, 12, or 16; default is 8; if N is 16, then -lossless\n");
|
||||
fprintf(stderr, " must also be specified)\n");
|
||||
#else
|
||||
fprintf(stderr, " (N is 8 or 12; default is 8)\n");
|
||||
#endif
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
fprintf(stderr, " -lossless psv[,Pt] Create lossless JPEG file\n");
|
||||
#endif
|
||||
#ifdef C_ARITH_CODING_SUPPORTED
|
||||
fprintf(stderr, " -arithmetic Use arithmetic coding\n");
|
||||
#endif
|
||||
#ifdef DCT_ISLOW_SUPPORTED
|
||||
fprintf(stderr, " -dct int Use accurate integer DCT method%s\n",
|
||||
(JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
|
||||
#endif
|
||||
#ifdef DCT_IFAST_SUPPORTED
|
||||
fprintf(stderr, " -dct fast Use less accurate integer DCT method [legacy feature]%s\n",
|
||||
(JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
|
||||
#endif
|
||||
#ifdef DCT_FLOAT_SUPPORTED
|
||||
fprintf(stderr, " -dct float Use floating-point DCT method [legacy feature]%s\n",
|
||||
(JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
|
||||
#endif
|
||||
fprintf(stderr, " -icc FILE Embed ICC profile contained in FILE\n");
|
||||
fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
|
||||
#ifdef INPUT_SMOOTHING_SUPPORTED
|
||||
fprintf(stderr, " -smooth N Smooth dithered input (N=1..100 is strength)\n");
|
||||
#endif
|
||||
fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
|
||||
fprintf(stderr, " -outfile name Specify name for output file\n");
|
||||
fprintf(stderr, " -memdst Compress to memory instead of file (useful for benchmarking)\n");
|
||||
fprintf(stderr, " -report Report compression progress\n");
|
||||
fprintf(stderr, " -strict Treat all warnings as fatal\n");
|
||||
fprintf(stderr, " -verbose or -debug Emit debug output\n");
|
||||
fprintf(stderr, " -version Print version information and exit\n");
|
||||
fprintf(stderr, "Switches for wizards:\n");
|
||||
fprintf(stderr, " -baseline Force baseline quantization tables\n");
|
||||
fprintf(stderr, " -qtables FILE Use quantization tables given in FILE\n");
|
||||
fprintf(stderr, " -qslots N[,...] Set component quantization tables\n");
|
||||
fprintf(stderr, " -sample HxV[,...] Set component sampling factors\n");
|
||||
#ifdef C_MULTISCAN_FILES_SUPPORTED
|
||||
fprintf(stderr, " -scans FILE Create multi-scan JPEG per script FILE\n");
|
||||
#endif
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
LOCAL(int)
|
||||
parse_switches(j_compress_ptr cinfo, int argc, char **argv,
|
||||
int last_file_arg_seen, boolean for_real)
|
||||
/* Parse optional switches.
|
||||
* Returns argv[] index of first file-name argument (== argc if none).
|
||||
* Any file names with indexes <= last_file_arg_seen are ignored;
|
||||
* they have presumably been processed in a previous iteration.
|
||||
* (Pass 0 for last_file_arg_seen on the first or only iteration.)
|
||||
* for_real is FALSE on the first (dummy) pass; we may skip any expensive
|
||||
* processing.
|
||||
*/
|
||||
{
|
||||
int argn;
|
||||
char *arg;
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
int psv, pt = 0;
|
||||
#endif
|
||||
boolean force_baseline;
|
||||
boolean simple_progressive;
|
||||
char *qualityarg = NULL; /* saves -quality parm if any */
|
||||
char *qtablefile = NULL; /* saves -qtables filename if any */
|
||||
char *qslotsarg = NULL; /* saves -qslots parm if any */
|
||||
char *samplearg = NULL; /* saves -sample parm if any */
|
||||
char *scansarg = NULL; /* saves -scans parm if any */
|
||||
|
||||
/* Set up default JPEG parameters. */
|
||||
|
||||
force_baseline = FALSE; /* by default, allow 16-bit quantizers */
|
||||
simple_progressive = FALSE;
|
||||
is_targa = FALSE;
|
||||
icc_filename = NULL;
|
||||
outfilename = NULL;
|
||||
memdst = FALSE;
|
||||
report = FALSE;
|
||||
strict = FALSE;
|
||||
cinfo->err->trace_level = 0;
|
||||
|
||||
/* Scan command line options, adjust parameters */
|
||||
|
||||
for (argn = 1; argn < argc; argn++) {
|
||||
arg = argv[argn];
|
||||
if (*arg != '-') {
|
||||
/* Not a switch, must be a file name argument */
|
||||
if (argn <= last_file_arg_seen) {
|
||||
outfilename = NULL; /* -outfile applies to just one input file */
|
||||
continue; /* ignore this name if previously processed */
|
||||
}
|
||||
break; /* else done parsing switches */
|
||||
}
|
||||
arg++; /* advance past switch marker character */
|
||||
|
||||
if (keymatch(arg, "arithmetic", 1)) {
|
||||
/* Use arithmetic coding. */
|
||||
#ifdef C_ARITH_CODING_SUPPORTED
|
||||
cinfo->arith_code = TRUE;
|
||||
#else
|
||||
fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
|
||||
progname);
|
||||
exit(EXIT_FAILURE);
|
||||
#endif
|
||||
|
||||
} else if (keymatch(arg, "baseline", 1)) {
|
||||
/* Force baseline-compatible output (8-bit quantizer values). */
|
||||
force_baseline = TRUE;
|
||||
|
||||
} else if (keymatch(arg, "dct", 2)) {
|
||||
/* Select DCT algorithm. */
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
if (keymatch(argv[argn], "int", 1)) {
|
||||
cinfo->dct_method = JDCT_ISLOW;
|
||||
} else if (keymatch(argv[argn], "fast", 2)) {
|
||||
cinfo->dct_method = JDCT_IFAST;
|
||||
} else if (keymatch(argv[argn], "float", 2)) {
|
||||
cinfo->dct_method = JDCT_FLOAT;
|
||||
} else
|
||||
usage();
|
||||
|
||||
} else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
|
||||
/* Enable debug printouts. */
|
||||
/* On first -d, print version identification */
|
||||
static boolean printed_version = FALSE;
|
||||
|
||||
if (!printed_version) {
|
||||
fprintf(stderr, "%s version %s (build %s)\n",
|
||||
PACKAGE_NAME, VERSION, BUILD);
|
||||
fprintf(stderr, JCOPYRIGHT1);
|
||||
fprintf(stderr, JCOPYRIGHT2 "\n");
|
||||
fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
|
||||
JVERSION);
|
||||
printed_version = TRUE;
|
||||
}
|
||||
cinfo->err->trace_level++;
|
||||
|
||||
} else if (keymatch(arg, "version", 4)) {
|
||||
fprintf(stderr, "%s version %s (build %s)\n",
|
||||
PACKAGE_NAME, VERSION, BUILD);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
} else if (keymatch(arg, "grayscale", 2) ||
|
||||
keymatch(arg, "greyscale", 2)) {
|
||||
/* Force a monochrome JPEG file to be generated. */
|
||||
jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
|
||||
|
||||
} else if (keymatch(arg, "rgb", 3)) {
|
||||
/* Force an RGB JPEG file to be generated. */
|
||||
jpeg_set_colorspace(cinfo, JCS_RGB);
|
||||
|
||||
} else if (keymatch(arg, "icc", 1)) {
|
||||
/* Set ICC filename. */
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
icc_filename = argv[argn];
|
||||
|
||||
} else if (keymatch(arg, "lossless", 1)) {
|
||||
/* Enable lossless mode. */
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
char ch = ',', *ptr;
|
||||
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
if (sscanf(argv[argn], "%d%c", &psv, &ch) < 1 || ch != ',')
|
||||
usage();
|
||||
ptr = argv[argn];
|
||||
while (*ptr && *ptr++ != ','); /* advance to next segment of arg
|
||||
string */
|
||||
if (*ptr)
|
||||
sscanf(ptr, "%d", &pt);
|
||||
jpeg_enable_lossless(cinfo, psv, pt);
|
||||
#else
|
||||
fprintf(stderr, "%s: sorry, lossless output was not compiled\n",
|
||||
progname);
|
||||
exit(EXIT_FAILURE);
|
||||
#endif
|
||||
|
||||
} else if (keymatch(arg, "maxmemory", 3)) {
|
||||
/* Maximum memory in Kb (or Mb with 'm'). */
|
||||
long lval;
|
||||
char ch = 'x';
|
||||
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
|
||||
usage();
|
||||
if (ch == 'm' || ch == 'M')
|
||||
lval *= 1000L;
|
||||
cinfo->mem->max_memory_to_use = lval * 1000L;
|
||||
|
||||
} else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
|
||||
/* Enable entropy parm optimization. */
|
||||
#ifdef ENTROPY_OPT_SUPPORTED
|
||||
cinfo->optimize_coding = TRUE;
|
||||
#else
|
||||
fprintf(stderr, "%s: sorry, entropy optimization was not compiled in\n",
|
||||
progname);
|
||||
exit(EXIT_FAILURE);
|
||||
#endif
|
||||
|
||||
} else if (keymatch(arg, "outfile", 4)) {
|
||||
/* Set output file name. */
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
outfilename = argv[argn]; /* save it away for later use */
|
||||
|
||||
} else if (keymatch(arg, "precision", 3)) {
|
||||
/* Set data precision. */
|
||||
int val;
|
||||
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
if (sscanf(argv[argn], "%d", &val) != 1)
|
||||
usage();
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
if (val != 8 && val != 12 && val != 16)
|
||||
#else
|
||||
if (val != 8 && val != 12)
|
||||
#endif
|
||||
usage();
|
||||
cinfo->data_precision = val;
|
||||
|
||||
} else if (keymatch(arg, "progressive", 3)) {
|
||||
/* Select simple progressive mode. */
|
||||
#ifdef C_PROGRESSIVE_SUPPORTED
|
||||
simple_progressive = TRUE;
|
||||
/* We must postpone execution until num_components is known. */
|
||||
#else
|
||||
fprintf(stderr, "%s: sorry, progressive output was not compiled in\n",
|
||||
progname);
|
||||
exit(EXIT_FAILURE);
|
||||
#endif
|
||||
|
||||
} else if (keymatch(arg, "memdst", 2)) {
|
||||
/* Use in-memory destination manager */
|
||||
memdst = TRUE;
|
||||
|
||||
} else if (keymatch(arg, "quality", 1)) {
|
||||
/* Quality ratings (quantization table scaling factors). */
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
qualityarg = argv[argn];
|
||||
|
||||
} else if (keymatch(arg, "qslots", 2)) {
|
||||
/* Quantization table slot numbers. */
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
qslotsarg = argv[argn];
|
||||
/* Must delay setting qslots until after we have processed any
|
||||
* colorspace-determining switches, since jpeg_set_colorspace sets
|
||||
* default quant table numbers.
|
||||
*/
|
||||
|
||||
} else if (keymatch(arg, "qtables", 2)) {
|
||||
/* Quantization tables fetched from file. */
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
qtablefile = argv[argn];
|
||||
/* We postpone actually reading the file in case -quality comes later. */
|
||||
|
||||
} else if (keymatch(arg, "report", 3)) {
|
||||
report = TRUE;
|
||||
|
||||
} else if (keymatch(arg, "restart", 1)) {
|
||||
/* Restart interval in MCU rows (or in MCUs with 'b'). */
|
||||
long lval;
|
||||
char ch = 'x';
|
||||
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
|
||||
usage();
|
||||
if (lval < 0 || lval > 65535L)
|
||||
usage();
|
||||
if (ch == 'b' || ch == 'B') {
|
||||
cinfo->restart_interval = (unsigned int)lval;
|
||||
cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
|
||||
} else {
|
||||
cinfo->restart_in_rows = (int)lval;
|
||||
/* restart_interval will be computed during startup */
|
||||
}
|
||||
|
||||
} else if (keymatch(arg, "sample", 2)) {
|
||||
/* Set sampling factors. */
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
samplearg = argv[argn];
|
||||
/* Must delay setting sample factors until after we have processed any
|
||||
* colorspace-determining switches, since jpeg_set_colorspace sets
|
||||
* default sampling factors.
|
||||
*/
|
||||
|
||||
} else if (keymatch(arg, "scans", 4)) {
|
||||
/* Set scan script. */
|
||||
#ifdef C_MULTISCAN_FILES_SUPPORTED
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
scansarg = argv[argn];
|
||||
/* We must postpone reading the file in case -progressive appears. */
|
||||
#else
|
||||
fprintf(stderr, "%s: sorry, multi-scan output was not compiled in\n",
|
||||
progname);
|
||||
exit(EXIT_FAILURE);
|
||||
#endif
|
||||
|
||||
} else if (keymatch(arg, "smooth", 2)) {
|
||||
/* Set input smoothing factor. */
|
||||
int val;
|
||||
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
if (sscanf(argv[argn], "%d", &val) != 1)
|
||||
usage();
|
||||
if (val < 0 || val > 100)
|
||||
usage();
|
||||
cinfo->smoothing_factor = val;
|
||||
|
||||
} else if (keymatch(arg, "strict", 2)) {
|
||||
strict = TRUE;
|
||||
|
||||
} else if (keymatch(arg, "targa", 1)) {
|
||||
/* Input file is Targa format. */
|
||||
is_targa = TRUE;
|
||||
|
||||
} else {
|
||||
usage(); /* bogus switch */
|
||||
}
|
||||
}
|
||||
|
||||
/* Post-switch-scanning cleanup */
|
||||
|
||||
if (for_real) {
|
||||
|
||||
/* Set quantization tables for selected quality. */
|
||||
/* Some or all may be overridden if -qtables is present. */
|
||||
if (qualityarg != NULL) /* process -quality if it was present */
|
||||
if (!set_quality_ratings(cinfo, qualityarg, force_baseline))
|
||||
usage();
|
||||
|
||||
if (qtablefile != NULL) /* process -qtables if it was present */
|
||||
if (!read_quant_tables(cinfo, qtablefile, force_baseline))
|
||||
usage();
|
||||
|
||||
if (qslotsarg != NULL) /* process -qslots if it was present */
|
||||
if (!set_quant_slots(cinfo, qslotsarg))
|
||||
usage();
|
||||
|
||||
if (samplearg != NULL) /* process -sample if it was present */
|
||||
if (!set_sample_factors(cinfo, samplearg))
|
||||
usage();
|
||||
|
||||
#ifdef C_PROGRESSIVE_SUPPORTED
|
||||
if (simple_progressive) /* process -progressive; -scans can override */
|
||||
jpeg_simple_progression(cinfo);
|
||||
#endif
|
||||
|
||||
#ifdef C_MULTISCAN_FILES_SUPPORTED
|
||||
if (scansarg != NULL) /* process -scans if it was present */
|
||||
if (!read_scan_script(cinfo, scansarg))
|
||||
usage();
|
||||
#endif
|
||||
}
|
||||
|
||||
return argn; /* return index of next arg (file name) */
|
||||
}
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
my_emit_message(j_common_ptr cinfo, int msg_level)
|
||||
{
|
||||
if (msg_level < 0) {
|
||||
/* Treat warning as fatal */
|
||||
cinfo->err->error_exit(cinfo);
|
||||
} else {
|
||||
if (cinfo->err->trace_level >= msg_level)
|
||||
cinfo->err->output_message(cinfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The main program.
|
||||
*/
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct jpeg_compress_struct cinfo;
|
||||
#ifdef CJPEG_FUZZER
|
||||
struct my_error_mgr myerr;
|
||||
struct jpeg_error_mgr &jerr = myerr.pub;
|
||||
#else
|
||||
struct jpeg_error_mgr jerr;
|
||||
#endif
|
||||
struct cdjpeg_progress_mgr progress;
|
||||
int file_index;
|
||||
cjpeg_source_ptr src_mgr;
|
||||
FILE *input_file = NULL;
|
||||
FILE *icc_file;
|
||||
JOCTET *icc_profile = NULL;
|
||||
long icc_len = 0;
|
||||
FILE *output_file = NULL;
|
||||
unsigned char *outbuffer = NULL;
|
||||
unsigned long outsize = 0;
|
||||
JDIMENSION num_scanlines;
|
||||
|
||||
progname = argv[0];
|
||||
if (progname == NULL || progname[0] == 0)
|
||||
progname = "cjpeg"; /* in case C library doesn't provide it */
|
||||
|
||||
/* Initialize the JPEG compression object with default error handling. */
|
||||
cinfo.err = jpeg_std_error(&jerr);
|
||||
jpeg_create_compress(&cinfo);
|
||||
/* Add some application-specific error messages (from cderror.h) */
|
||||
jerr.addon_message_table = cdjpeg_message_table;
|
||||
jerr.first_addon_message = JMSG_FIRSTADDONCODE;
|
||||
jerr.last_addon_message = JMSG_LASTADDONCODE;
|
||||
|
||||
/* Initialize JPEG parameters.
|
||||
* Much of this may be overridden later.
|
||||
* In particular, we don't yet know the input file's color space,
|
||||
* but we need to provide some value for jpeg_set_defaults() to work.
|
||||
*/
|
||||
|
||||
cinfo.in_color_space = JCS_RGB; /* arbitrary guess */
|
||||
jpeg_set_defaults(&cinfo);
|
||||
|
||||
/* Scan command line to find file names.
|
||||
* It is convenient to use just one switch-parsing routine, but the switch
|
||||
* values read here are ignored; we will rescan the switches after opening
|
||||
* the input file.
|
||||
*/
|
||||
|
||||
file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
|
||||
|
||||
if (strict)
|
||||
jerr.emit_message = my_emit_message;
|
||||
|
||||
#ifdef TWO_FILE_COMMANDLINE
|
||||
if (!memdst) {
|
||||
/* Must have either -outfile switch or explicit output file name */
|
||||
if (outfilename == NULL) {
|
||||
if (file_index != argc - 2) {
|
||||
fprintf(stderr, "%s: must name one input and one output file\n",
|
||||
progname);
|
||||
usage();
|
||||
}
|
||||
outfilename = argv[file_index + 1];
|
||||
} else {
|
||||
if (file_index != argc - 1) {
|
||||
fprintf(stderr, "%s: must name one input and one output file\n",
|
||||
progname);
|
||||
usage();
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* Unix style: expect zero or one file name */
|
||||
if (file_index < argc - 1) {
|
||||
fprintf(stderr, "%s: only one input file\n", progname);
|
||||
usage();
|
||||
}
|
||||
#endif /* TWO_FILE_COMMANDLINE */
|
||||
|
||||
/* Open the input file. */
|
||||
if (file_index < argc) {
|
||||
if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
|
||||
fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
/* default input file is stdin */
|
||||
input_file = read_stdin();
|
||||
}
|
||||
|
||||
/* Open the output file. */
|
||||
if (outfilename != NULL) {
|
||||
if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
|
||||
fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else if (!memdst) {
|
||||
/* default output file is stdout */
|
||||
output_file = write_stdout();
|
||||
}
|
||||
|
||||
if (icc_filename != NULL) {
|
||||
if ((icc_file = fopen(icc_filename, READ_BINARY)) == NULL) {
|
||||
fprintf(stderr, "%s: can't open %s\n", progname, icc_filename);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (fseek(icc_file, 0, SEEK_END) < 0 ||
|
||||
(icc_len = ftell(icc_file)) < 1 ||
|
||||
fseek(icc_file, 0, SEEK_SET) < 0) {
|
||||
fprintf(stderr, "%s: can't determine size of %s\n", progname,
|
||||
icc_filename);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if ((icc_profile = (JOCTET *)malloc(icc_len)) == NULL) {
|
||||
fprintf(stderr, "%s: can't allocate memory for ICC profile\n", progname);
|
||||
fclose(icc_file);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (fread(icc_profile, icc_len, 1, icc_file) < 1) {
|
||||
fprintf(stderr, "%s: can't read ICC profile from %s\n", progname,
|
||||
icc_filename);
|
||||
free(icc_profile);
|
||||
fclose(icc_file);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
fclose(icc_file);
|
||||
}
|
||||
|
||||
#ifdef CJPEG_FUZZER
|
||||
jerr.error_exit = my_error_exit;
|
||||
jerr.emit_message = my_emit_message_fuzzer;
|
||||
if (setjmp(myerr.setjmp_buffer))
|
||||
HANDLE_ERROR()
|
||||
#endif
|
||||
|
||||
if (report) {
|
||||
start_progress_monitor((j_common_ptr)&cinfo, &progress);
|
||||
progress.report = report;
|
||||
}
|
||||
|
||||
/* Figure out the input file format, and set up to read it. */
|
||||
src_mgr = select_file_type(&cinfo, input_file);
|
||||
src_mgr->input_file = input_file;
|
||||
#ifdef CJPEG_FUZZER
|
||||
src_mgr->max_pixels = 1048576;
|
||||
#endif
|
||||
|
||||
/* Read the input file header to obtain file size & colorspace. */
|
||||
(*src_mgr->start_input) (&cinfo, src_mgr);
|
||||
|
||||
/* Now that we know input colorspace, fix colorspace-dependent defaults */
|
||||
jpeg_default_colorspace(&cinfo);
|
||||
|
||||
/* Adjust default compression parameters by re-parsing the options */
|
||||
file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
|
||||
|
||||
/* Specify data destination for compression */
|
||||
if (memdst)
|
||||
jpeg_mem_dest(&cinfo, &outbuffer, &outsize);
|
||||
else
|
||||
jpeg_stdio_dest(&cinfo, output_file);
|
||||
|
||||
#ifdef CJPEG_FUZZER
|
||||
if (setjmp(myerr.setjmp_buffer))
|
||||
HANDLE_ERROR()
|
||||
#endif
|
||||
|
||||
/* Start compressor */
|
||||
jpeg_start_compress(&cinfo, TRUE);
|
||||
|
||||
if (icc_profile != NULL)
|
||||
jpeg_write_icc_profile(&cinfo, icc_profile, (unsigned int)icc_len);
|
||||
|
||||
/* Process data */
|
||||
if (cinfo.data_precision == 16) {
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
while (cinfo.next_scanline < cinfo.image_height) {
|
||||
num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
|
||||
(void)jpeg16_write_scanlines(&cinfo, src_mgr->buffer16, num_scanlines);
|
||||
}
|
||||
#else
|
||||
ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision);
|
||||
#endif
|
||||
} else if (cinfo.data_precision == 12) {
|
||||
while (cinfo.next_scanline < cinfo.image_height) {
|
||||
num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
|
||||
(void)jpeg12_write_scanlines(&cinfo, src_mgr->buffer12, num_scanlines);
|
||||
}
|
||||
} else {
|
||||
while (cinfo.next_scanline < cinfo.image_height) {
|
||||
num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
|
||||
(void)jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
|
||||
}
|
||||
}
|
||||
|
||||
/* Finish compression and release memory */
|
||||
(*src_mgr->finish_input) (&cinfo, src_mgr);
|
||||
jpeg_finish_compress(&cinfo);
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
|
||||
/* Close files, if we opened them */
|
||||
if (input_file != stdin)
|
||||
fclose(input_file);
|
||||
if (output_file != stdout && output_file != NULL)
|
||||
fclose(output_file);
|
||||
|
||||
if (report)
|
||||
end_progress_monitor((j_common_ptr)&cinfo);
|
||||
|
||||
if (memdst) {
|
||||
#ifndef CJPEG_FUZZER
|
||||
fprintf(stderr, "Compressed size: %lu bytes\n", outsize);
|
||||
#endif
|
||||
free(outbuffer);
|
||||
}
|
||||
|
||||
free(icc_profile);
|
||||
|
||||
/* All done. */
|
||||
return (jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
|
||||
}
|
61
3rdparty/libjpeg-turbo/src/cmyk.h
vendored
Normal file
61
3rdparty/libjpeg-turbo/src/cmyk.h
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* cmyk.h
|
||||
*
|
||||
* Copyright (C) 2017-2018, 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file contains convenience functions for performing quick & dirty
|
||||
* CMYK<->RGB conversion. This algorithm is suitable for testing purposes
|
||||
* only. Properly converting between CMYK and RGB requires a color management
|
||||
* system.
|
||||
*/
|
||||
|
||||
#ifndef CMYK_H
|
||||
#define CMYK_H
|
||||
|
||||
#include <jinclude.h>
|
||||
#define JPEG_INTERNALS
|
||||
#include <jpeglib.h>
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
|
||||
/* Fully reversible */
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
rgb_to_cmyk(_JSAMPLE r, _JSAMPLE g, _JSAMPLE b,
|
||||
_JSAMPLE *c, _JSAMPLE *m, _JSAMPLE *y, _JSAMPLE *k)
|
||||
{
|
||||
double ctmp = 1.0 - ((double)r / (double)_MAXJSAMPLE);
|
||||
double mtmp = 1.0 - ((double)g / (double)_MAXJSAMPLE);
|
||||
double ytmp = 1.0 - ((double)b / (double)_MAXJSAMPLE);
|
||||
double ktmp = MIN(MIN(ctmp, mtmp), ytmp);
|
||||
|
||||
if (ktmp == 1.0) ctmp = mtmp = ytmp = 0.0;
|
||||
else {
|
||||
ctmp = (ctmp - ktmp) / (1.0 - ktmp);
|
||||
mtmp = (mtmp - ktmp) / (1.0 - ktmp);
|
||||
ytmp = (ytmp - ktmp) / (1.0 - ktmp);
|
||||
}
|
||||
*c = (_JSAMPLE)((double)_MAXJSAMPLE - ctmp * (double)_MAXJSAMPLE + 0.5);
|
||||
*m = (_JSAMPLE)((double)_MAXJSAMPLE - mtmp * (double)_MAXJSAMPLE + 0.5);
|
||||
*y = (_JSAMPLE)((double)_MAXJSAMPLE - ytmp * (double)_MAXJSAMPLE + 0.5);
|
||||
*k = (_JSAMPLE)((double)_MAXJSAMPLE - ktmp * (double)_MAXJSAMPLE + 0.5);
|
||||
}
|
||||
|
||||
|
||||
/* Fully reversible only for C/M/Y/K values generated with rgb_to_cmyk() */
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
cmyk_to_rgb(_JSAMPLE c, _JSAMPLE m, _JSAMPLE y, _JSAMPLE k,
|
||||
_JSAMPLE *r, _JSAMPLE *g, _JSAMPLE *b)
|
||||
{
|
||||
*r = (_JSAMPLE)((double)c * (double)k / (double)_MAXJSAMPLE + 0.5);
|
||||
*g = (_JSAMPLE)((double)m * (double)k / (double)_MAXJSAMPLE + 0.5);
|
||||
*b = (_JSAMPLE)((double)y * (double)k / (double)_MAXJSAMPLE + 0.5);
|
||||
}
|
||||
|
||||
|
||||
#endif /* CMYK_H */
|
932
3rdparty/libjpeg-turbo/src/djpeg.c
vendored
Normal file
932
3rdparty/libjpeg-turbo/src/djpeg.c
vendored
Normal file
@ -0,0 +1,932 @@
|
||||
/*
|
||||
* djpeg.c
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Modified 2013-2019 by Guido Vollbeding.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2010-2011, 2013-2017, 2019-2020, 2022-2024, D. R. Commander.
|
||||
* Copyright (C) 2015, Google, Inc.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file contains a command-line user interface for the JPEG decompressor.
|
||||
* It should work on any system with Unix- or MS-DOS-style command lines.
|
||||
*
|
||||
* Two different command line styles are permitted, depending on the
|
||||
* compile-time switch TWO_FILE_COMMANDLINE:
|
||||
* djpeg [options] inputfile outputfile
|
||||
* djpeg [options] [inputfile]
|
||||
* In the second style, output is always to standard output, which you'd
|
||||
* normally redirect to a file or pipe to some other program. Input is
|
||||
* either from a named file or from standard input (typically redirected).
|
||||
* The second style is convenient on Unix but is unhelpful on systems that
|
||||
* don't support pipes. Also, you MUST use the first style if your system
|
||||
* doesn't do binary I/O to stdin/stdout.
|
||||
* To simplify script writing, the "-outfile" switch is provided. The syntax
|
||||
* djpeg [options] -outfile outputfile inputfile
|
||||
* 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"
|
||||
|
||||
#include <ctype.h> /* to declare isprint() */
|
||||
|
||||
|
||||
/* Create the add-on message string table. */
|
||||
|
||||
#define JMESSAGE(code, string) string,
|
||||
|
||||
static const char * const cdjpeg_message_table[] = {
|
||||
#include "cderror.h"
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* This list defines the known output image formats
|
||||
* (not all of which need be supported by a given version).
|
||||
* You can change the default output format by defining DEFAULT_FMT;
|
||||
* indeed, you had better do so if you undefine PPM_SUPPORTED.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
FMT_BMP, /* BMP format (Windows flavor) */
|
||||
FMT_GIF, /* GIF format (LZW-compressed) */
|
||||
FMT_GIF0, /* GIF format (uncompressed) */
|
||||
FMT_OS2, /* BMP format (OS/2 flavor) */
|
||||
FMT_PPM, /* PPM/PGM (PBMPLUS formats) */
|
||||
FMT_TARGA, /* Targa format */
|
||||
FMT_TIFF /* TIFF format */
|
||||
} IMAGE_FORMATS;
|
||||
|
||||
#ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */
|
||||
#define DEFAULT_FMT FMT_PPM
|
||||
#endif
|
||||
|
||||
static IMAGE_FORMATS requested_fmt;
|
||||
|
||||
|
||||
/*
|
||||
* Argument-parsing code.
|
||||
* The switch parser is designed to be useful with DOS-style command line
|
||||
* syntax, ie, intermixed switches and file names, where only the switches
|
||||
* to the left of a given file name affect processing of that file.
|
||||
* The main program in this file doesn't actually use this capability...
|
||||
*/
|
||||
|
||||
|
||||
static const char *progname; /* program name for error messages */
|
||||
static char *icc_filename; /* for -icc switch */
|
||||
static JDIMENSION max_scans; /* for -maxscans switch */
|
||||
static char *outfilename; /* for -outfile switch */
|
||||
static boolean memsrc; /* for -memsrc switch */
|
||||
static boolean report; /* for -report switch */
|
||||
static boolean skip, crop;
|
||||
static JDIMENSION skip_start, skip_end;
|
||||
static JDIMENSION crop_x, crop_y, crop_width, crop_height;
|
||||
static boolean strict; /* for -strict switch */
|
||||
#define INPUT_BUF_SIZE 4096
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
usage(void)
|
||||
/* complain about bad command line */
|
||||
{
|
||||
fprintf(stderr, "usage: %s [switches] ", progname);
|
||||
#ifdef TWO_FILE_COMMANDLINE
|
||||
fprintf(stderr, "inputfile outputfile\n");
|
||||
#else
|
||||
fprintf(stderr, "[inputfile]\n");
|
||||
#endif
|
||||
|
||||
fprintf(stderr, "Switches (names may be abbreviated):\n");
|
||||
fprintf(stderr, " -colors N Reduce image to no more than N colors\n");
|
||||
fprintf(stderr, " -fast Fast, low-quality processing\n");
|
||||
fprintf(stderr, " -grayscale Force grayscale output\n");
|
||||
fprintf(stderr, " -rgb Force RGB output\n");
|
||||
fprintf(stderr, " -rgb565 Force RGB565 output\n");
|
||||
#ifdef IDCT_SCALING_SUPPORTED
|
||||
fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n");
|
||||
#endif
|
||||
#ifdef BMP_SUPPORTED
|
||||
fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n",
|
||||
(DEFAULT_FMT == FMT_BMP ? " (default)" : ""));
|
||||
#endif
|
||||
#ifdef GIF_SUPPORTED
|
||||
fprintf(stderr, " -gif Select GIF output format (LZW-compressed)%s\n",
|
||||
(DEFAULT_FMT == FMT_GIF ? " (default)" : ""));
|
||||
fprintf(stderr, " -gif0 Select GIF output format (uncompressed)%s\n",
|
||||
(DEFAULT_FMT == FMT_GIF0 ? " (default)" : ""));
|
||||
#endif
|
||||
#ifdef BMP_SUPPORTED
|
||||
fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n",
|
||||
(DEFAULT_FMT == FMT_OS2 ? " (default)" : ""));
|
||||
#endif
|
||||
#ifdef PPM_SUPPORTED
|
||||
fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n",
|
||||
(DEFAULT_FMT == FMT_PPM ? " (default)" : ""));
|
||||
#endif
|
||||
#ifdef TARGA_SUPPORTED
|
||||
fprintf(stderr, " -targa Select Targa output format%s\n",
|
||||
(DEFAULT_FMT == FMT_TARGA ? " (default)" : ""));
|
||||
#endif
|
||||
fprintf(stderr, "Switches for advanced users:\n");
|
||||
#ifdef DCT_ISLOW_SUPPORTED
|
||||
fprintf(stderr, " -dct int Use accurate integer DCT method%s\n",
|
||||
(JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
|
||||
#endif
|
||||
#ifdef DCT_IFAST_SUPPORTED
|
||||
fprintf(stderr, " -dct fast Use less accurate integer DCT method [legacy feature]%s\n",
|
||||
(JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
|
||||
#endif
|
||||
#ifdef DCT_FLOAT_SUPPORTED
|
||||
fprintf(stderr, " -dct float Use floating-point DCT method [legacy feature]%s\n",
|
||||
(JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
|
||||
#endif
|
||||
fprintf(stderr, " -dither fs Use F-S dithering (default)\n");
|
||||
fprintf(stderr, " -dither none Don't use dithering in quantization\n");
|
||||
fprintf(stderr, " -dither ordered Use ordered dither (medium speed, quality)\n");
|
||||
fprintf(stderr, " -icc FILE Extract ICC profile to FILE\n");
|
||||
#ifdef QUANT_2PASS_SUPPORTED
|
||||
fprintf(stderr, " -map FILE Map to colors used in named image file\n");
|
||||
#endif
|
||||
fprintf(stderr, " -nosmooth Don't use high-quality upsampling\n");
|
||||
#ifdef QUANT_1PASS_SUPPORTED
|
||||
fprintf(stderr, " -onepass Use 1-pass quantization (fast, low quality)\n");
|
||||
#endif
|
||||
fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
|
||||
fprintf(stderr, " -maxscans N Maximum number of scans to allow in input file\n");
|
||||
fprintf(stderr, " -outfile name Specify name for output file\n");
|
||||
fprintf(stderr, " -memsrc Load input file into memory before decompressing\n");
|
||||
fprintf(stderr, " -report Report decompression progress\n");
|
||||
fprintf(stderr, " -skip Y0,Y1 Decompress all rows except those between Y0 and Y1 (inclusive)\n");
|
||||
fprintf(stderr, " -crop WxH+X+Y Decompress only a rectangular subregion of the image\n");
|
||||
fprintf(stderr, " [requires PBMPLUS (PPM/PGM), GIF, or Targa output format]\n");
|
||||
fprintf(stderr, " -strict Treat all warnings as fatal\n");
|
||||
fprintf(stderr, " -verbose or -debug Emit debug output\n");
|
||||
fprintf(stderr, " -version Print version information and exit\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
LOCAL(int)
|
||||
parse_switches(j_decompress_ptr cinfo, int argc, char **argv,
|
||||
int last_file_arg_seen, boolean for_real)
|
||||
/* Parse optional switches.
|
||||
* Returns argv[] index of first file-name argument (== argc if none).
|
||||
* Any file names with indexes <= last_file_arg_seen are ignored;
|
||||
* they have presumably been processed in a previous iteration.
|
||||
* (Pass 0 for last_file_arg_seen on the first or only iteration.)
|
||||
* for_real is FALSE on the first (dummy) pass; we may skip any expensive
|
||||
* processing.
|
||||
*/
|
||||
{
|
||||
int argn;
|
||||
char *arg;
|
||||
|
||||
/* Set up default JPEG parameters. */
|
||||
requested_fmt = DEFAULT_FMT; /* set default output file format */
|
||||
icc_filename = NULL;
|
||||
max_scans = 0;
|
||||
outfilename = NULL;
|
||||
memsrc = FALSE;
|
||||
report = FALSE;
|
||||
skip = FALSE;
|
||||
crop = FALSE;
|
||||
strict = FALSE;
|
||||
cinfo->err->trace_level = 0;
|
||||
|
||||
/* Scan command line options, adjust parameters */
|
||||
|
||||
for (argn = 1; argn < argc; argn++) {
|
||||
arg = argv[argn];
|
||||
if (*arg != '-') {
|
||||
/* Not a switch, must be a file name argument */
|
||||
if (argn <= last_file_arg_seen) {
|
||||
outfilename = NULL; /* -outfile applies to just one input file */
|
||||
continue; /* ignore this name if previously processed */
|
||||
}
|
||||
break; /* else done parsing switches */
|
||||
}
|
||||
arg++; /* advance past switch marker character */
|
||||
|
||||
if (keymatch(arg, "bmp", 1)) {
|
||||
/* BMP output format (Windows flavor). */
|
||||
requested_fmt = FMT_BMP;
|
||||
|
||||
} else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) ||
|
||||
keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) {
|
||||
/* Do color quantization. */
|
||||
int val;
|
||||
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
if (sscanf(argv[argn], "%d", &val) != 1)
|
||||
usage();
|
||||
cinfo->desired_number_of_colors = val;
|
||||
cinfo->quantize_colors = TRUE;
|
||||
|
||||
} else if (keymatch(arg, "dct", 2)) {
|
||||
/* Select IDCT algorithm. */
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
if (keymatch(argv[argn], "int", 1)) {
|
||||
cinfo->dct_method = JDCT_ISLOW;
|
||||
} else if (keymatch(argv[argn], "fast", 2)) {
|
||||
cinfo->dct_method = JDCT_IFAST;
|
||||
} else if (keymatch(argv[argn], "float", 2)) {
|
||||
cinfo->dct_method = JDCT_FLOAT;
|
||||
} else
|
||||
usage();
|
||||
|
||||
} else if (keymatch(arg, "dither", 2)) {
|
||||
/* Select dithering algorithm. */
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
if (keymatch(argv[argn], "fs", 2)) {
|
||||
cinfo->dither_mode = JDITHER_FS;
|
||||
} else if (keymatch(argv[argn], "none", 2)) {
|
||||
cinfo->dither_mode = JDITHER_NONE;
|
||||
} else if (keymatch(argv[argn], "ordered", 2)) {
|
||||
cinfo->dither_mode = JDITHER_ORDERED;
|
||||
} else
|
||||
usage();
|
||||
|
||||
} else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
|
||||
/* Enable debug printouts. */
|
||||
/* On first -d, print version identification */
|
||||
static boolean printed_version = FALSE;
|
||||
|
||||
if (!printed_version) {
|
||||
fprintf(stderr, "%s version %s (build %s)\n",
|
||||
PACKAGE_NAME, VERSION, BUILD);
|
||||
fprintf(stderr, JCOPYRIGHT1);
|
||||
fprintf(stderr, JCOPYRIGHT2 "\n");
|
||||
fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
|
||||
JVERSION);
|
||||
printed_version = TRUE;
|
||||
}
|
||||
cinfo->err->trace_level++;
|
||||
|
||||
} else if (keymatch(arg, "version", 4)) {
|
||||
fprintf(stderr, "%s version %s (build %s)\n",
|
||||
PACKAGE_NAME, VERSION, BUILD);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
} else if (keymatch(arg, "fast", 1)) {
|
||||
/* Select recommended processing options for quick-and-dirty output. */
|
||||
cinfo->two_pass_quantize = FALSE;
|
||||
cinfo->dither_mode = JDITHER_ORDERED;
|
||||
if (!cinfo->quantize_colors) /* don't override an earlier -colors */
|
||||
cinfo->desired_number_of_colors = 216;
|
||||
cinfo->dct_method = JDCT_FASTEST;
|
||||
cinfo->do_fancy_upsampling = FALSE;
|
||||
|
||||
} else if (keymatch(arg, "gif", 1)) {
|
||||
/* GIF output format (LZW-compressed). */
|
||||
requested_fmt = FMT_GIF;
|
||||
|
||||
} else if (keymatch(arg, "gif0", 4)) {
|
||||
/* GIF output format (uncompressed). */
|
||||
requested_fmt = FMT_GIF0;
|
||||
|
||||
} else if (keymatch(arg, "grayscale", 2) ||
|
||||
keymatch(arg, "greyscale", 2)) {
|
||||
/* Force monochrome output. */
|
||||
cinfo->out_color_space = JCS_GRAYSCALE;
|
||||
|
||||
} else if (keymatch(arg, "rgb", 2)) {
|
||||
/* Force RGB output. */
|
||||
cinfo->out_color_space = JCS_RGB;
|
||||
|
||||
} else if (keymatch(arg, "rgb565", 2)) {
|
||||
/* Force RGB565 output. */
|
||||
cinfo->out_color_space = JCS_RGB565;
|
||||
|
||||
} else if (keymatch(arg, "icc", 1)) {
|
||||
/* Set ICC filename. */
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
icc_filename = argv[argn];
|
||||
#ifdef SAVE_MARKERS_SUPPORTED
|
||||
jpeg_save_markers(cinfo, JPEG_APP0 + 2, 0xFFFF);
|
||||
#endif
|
||||
|
||||
} else if (keymatch(arg, "map", 3)) {
|
||||
/* Quantize to a color map taken from an input file. */
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
if (for_real) { /* too expensive to do twice! */
|
||||
#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */
|
||||
FILE *mapfile;
|
||||
|
||||
if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) {
|
||||
fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (cinfo->data_precision == 12)
|
||||
read_color_map_12(cinfo, mapfile);
|
||||
else
|
||||
read_color_map(cinfo, mapfile);
|
||||
fclose(mapfile);
|
||||
cinfo->quantize_colors = TRUE;
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
}
|
||||
|
||||
} else if (keymatch(arg, "maxmemory", 3)) {
|
||||
/* Maximum memory in Kb (or Mb with 'm'). */
|
||||
long lval;
|
||||
char ch = 'x';
|
||||
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
|
||||
usage();
|
||||
if (ch == 'm' || ch == 'M')
|
||||
lval *= 1000L;
|
||||
cinfo->mem->max_memory_to_use = lval * 1000L;
|
||||
|
||||
} else if (keymatch(arg, "maxscans", 4)) {
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
if (sscanf(argv[argn], "%u", &max_scans) != 1)
|
||||
usage();
|
||||
|
||||
} else if (keymatch(arg, "nosmooth", 3)) {
|
||||
/* Suppress fancy upsampling */
|
||||
cinfo->do_fancy_upsampling = FALSE;
|
||||
|
||||
} else if (keymatch(arg, "onepass", 3)) {
|
||||
/* Use fast one-pass quantization. */
|
||||
cinfo->two_pass_quantize = FALSE;
|
||||
|
||||
} else if (keymatch(arg, "os2", 3)) {
|
||||
/* BMP output format (OS/2 flavor). */
|
||||
requested_fmt = FMT_OS2;
|
||||
|
||||
} else if (keymatch(arg, "outfile", 4)) {
|
||||
/* Set output file name. */
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
outfilename = argv[argn]; /* save it away for later use */
|
||||
|
||||
} else if (keymatch(arg, "memsrc", 2)) {
|
||||
/* Use in-memory source manager */
|
||||
memsrc = TRUE;
|
||||
|
||||
} else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) {
|
||||
/* PPM/PGM output format. */
|
||||
requested_fmt = FMT_PPM;
|
||||
|
||||
} else if (keymatch(arg, "report", 2)) {
|
||||
report = TRUE;
|
||||
|
||||
} else if (keymatch(arg, "scale", 2)) {
|
||||
/* Scale the output image by a fraction M/N. */
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage();
|
||||
if (sscanf(argv[argn], "%u/%u",
|
||||
&cinfo->scale_num, &cinfo->scale_denom) != 2)
|
||||
usage();
|
||||
|
||||
} else if (keymatch(arg, "skip", 2)) {
|
||||
if (++argn >= argc)
|
||||
usage();
|
||||
if (sscanf(argv[argn], "%u,%u", &skip_start, &skip_end) != 2 ||
|
||||
skip_start > skip_end)
|
||||
usage();
|
||||
skip = TRUE;
|
||||
|
||||
} else if (keymatch(arg, "crop", 2)) {
|
||||
char c;
|
||||
if (++argn >= argc)
|
||||
usage();
|
||||
if (sscanf(argv[argn], "%u%c%u+%u+%u", &crop_width, &c, &crop_height,
|
||||
&crop_x, &crop_y) != 5 ||
|
||||
(c != 'X' && c != 'x') || crop_width < 1 || crop_height < 1)
|
||||
usage();
|
||||
crop = TRUE;
|
||||
|
||||
} else if (keymatch(arg, "strict", 2)) {
|
||||
strict = TRUE;
|
||||
|
||||
} else if (keymatch(arg, "targa", 1)) {
|
||||
/* Targa output format. */
|
||||
requested_fmt = FMT_TARGA;
|
||||
|
||||
} else {
|
||||
usage(); /* bogus switch */
|
||||
}
|
||||
}
|
||||
|
||||
return argn; /* return index of next arg (file name) */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Marker processor for COM and interesting APPn markers.
|
||||
* This replaces the library's built-in processor, which just skips the marker.
|
||||
* We want to print out the marker as text, to the extent possible.
|
||||
* Note this code relies on a non-suspending data source.
|
||||
*/
|
||||
|
||||
LOCAL(unsigned int)
|
||||
jpeg_getc(j_decompress_ptr cinfo)
|
||||
/* Read next byte */
|
||||
{
|
||||
struct jpeg_source_mgr *datasrc = cinfo->src;
|
||||
|
||||
if (datasrc->bytes_in_buffer == 0) {
|
||||
if (!(*datasrc->fill_input_buffer) (cinfo))
|
||||
ERREXIT(cinfo, JERR_CANT_SUSPEND);
|
||||
}
|
||||
datasrc->bytes_in_buffer--;
|
||||
return *datasrc->next_input_byte++;
|
||||
}
|
||||
|
||||
|
||||
METHODDEF(boolean)
|
||||
print_text_marker(j_decompress_ptr cinfo)
|
||||
{
|
||||
boolean traceit = (cinfo->err->trace_level >= 1);
|
||||
long length;
|
||||
unsigned int ch;
|
||||
unsigned int lastch = 0;
|
||||
|
||||
length = jpeg_getc(cinfo) << 8;
|
||||
length += jpeg_getc(cinfo);
|
||||
length -= 2; /* discount the length word itself */
|
||||
|
||||
if (traceit) {
|
||||
if (cinfo->unread_marker == JPEG_COM)
|
||||
fprintf(stderr, "Comment, length %ld:\n", (long)length);
|
||||
else /* assume it is an APPn otherwise */
|
||||
fprintf(stderr, "APP%d, length %ld:\n",
|
||||
cinfo->unread_marker - JPEG_APP0, (long)length);
|
||||
}
|
||||
|
||||
while (--length >= 0) {
|
||||
ch = jpeg_getc(cinfo);
|
||||
if (traceit) {
|
||||
/* Emit the character in a readable form.
|
||||
* Nonprintables are converted to \nnn form,
|
||||
* while \ is converted to \\.
|
||||
* Newlines in CR, CR/LF, or LF form will be printed as one newline.
|
||||
*/
|
||||
if (ch == '\r') {
|
||||
fprintf(stderr, "\n");
|
||||
} else if (ch == '\n') {
|
||||
if (lastch != '\r')
|
||||
fprintf(stderr, "\n");
|
||||
} else if (ch == '\\') {
|
||||
fprintf(stderr, "\\\\");
|
||||
} else if (isprint(ch)) {
|
||||
putc(ch, stderr);
|
||||
} else {
|
||||
fprintf(stderr, "\\%03o", ch);
|
||||
}
|
||||
lastch = ch;
|
||||
}
|
||||
}
|
||||
|
||||
if (traceit)
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
my_emit_message(j_common_ptr cinfo, int msg_level)
|
||||
{
|
||||
if (msg_level < 0) {
|
||||
/* Treat warning as fatal */
|
||||
cinfo->err->error_exit(cinfo);
|
||||
} else {
|
||||
if (cinfo->err->trace_level >= msg_level)
|
||||
cinfo->err->output_message(cinfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The main program.
|
||||
*/
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct jpeg_error_mgr jerr;
|
||||
struct cdjpeg_progress_mgr progress;
|
||||
int file_index;
|
||||
djpeg_dest_ptr dest_mgr = NULL;
|
||||
FILE *input_file;
|
||||
FILE *output_file;
|
||||
unsigned char *inbuffer = NULL;
|
||||
unsigned long insize = 0;
|
||||
JDIMENSION num_scanlines;
|
||||
|
||||
progname = argv[0];
|
||||
if (progname == NULL || progname[0] == 0)
|
||||
progname = "djpeg"; /* in case C library doesn't provide it */
|
||||
|
||||
/* Initialize the JPEG decompression object with default error handling. */
|
||||
cinfo.err = jpeg_std_error(&jerr);
|
||||
jpeg_create_decompress(&cinfo);
|
||||
/* Add some application-specific error messages (from cderror.h) */
|
||||
jerr.addon_message_table = cdjpeg_message_table;
|
||||
jerr.first_addon_message = JMSG_FIRSTADDONCODE;
|
||||
jerr.last_addon_message = JMSG_LASTADDONCODE;
|
||||
|
||||
/* Insert custom marker processor for COM and APP12.
|
||||
* APP12 is used by some digital camera makers for textual info,
|
||||
* so we provide the ability to display it as text.
|
||||
* If you like, additional APPn marker types can be selected for display,
|
||||
* but don't try to override APP0 or APP14 this way (see libjpeg.txt).
|
||||
*/
|
||||
jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker);
|
||||
jpeg_set_marker_processor(&cinfo, JPEG_APP0 + 12, print_text_marker);
|
||||
|
||||
/* Scan command line to find file names. */
|
||||
/* It is convenient to use just one switch-parsing routine, but the switch
|
||||
* values read here are ignored; we will rescan the switches after opening
|
||||
* the input file.
|
||||
* (Exception: tracing level set here controls verbosity for COM markers
|
||||
* found during jpeg_read_header...)
|
||||
*/
|
||||
|
||||
file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
|
||||
|
||||
if (strict)
|
||||
jerr.emit_message = my_emit_message;
|
||||
|
||||
#ifdef TWO_FILE_COMMANDLINE
|
||||
/* Must have either -outfile switch or explicit output file name */
|
||||
if (outfilename == NULL) {
|
||||
if (file_index != argc - 2) {
|
||||
fprintf(stderr, "%s: must name one input and one output file\n",
|
||||
progname);
|
||||
usage();
|
||||
}
|
||||
outfilename = argv[file_index + 1];
|
||||
} else {
|
||||
if (file_index != argc - 1) {
|
||||
fprintf(stderr, "%s: must name one input and one output file\n",
|
||||
progname);
|
||||
usage();
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* Unix style: expect zero or one file name */
|
||||
if (file_index < argc - 1) {
|
||||
fprintf(stderr, "%s: only one input file\n", progname);
|
||||
usage();
|
||||
}
|
||||
#endif /* TWO_FILE_COMMANDLINE */
|
||||
|
||||
/* Open the input file. */
|
||||
if (file_index < argc) {
|
||||
if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
|
||||
fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
/* default input file is stdin */
|
||||
input_file = read_stdin();
|
||||
}
|
||||
|
||||
/* Open the output file. */
|
||||
if (outfilename != NULL) {
|
||||
if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
|
||||
fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
/* default output file is stdout */
|
||||
output_file = write_stdout();
|
||||
}
|
||||
|
||||
if (report || max_scans != 0) {
|
||||
start_progress_monitor((j_common_ptr)&cinfo, &progress);
|
||||
progress.report = report;
|
||||
progress.max_scans = max_scans;
|
||||
}
|
||||
|
||||
/* Specify data source for decompression */
|
||||
if (memsrc) {
|
||||
size_t nbytes;
|
||||
do {
|
||||
inbuffer = (unsigned char *)realloc(inbuffer, insize + INPUT_BUF_SIZE);
|
||||
if (inbuffer == NULL) {
|
||||
fprintf(stderr, "%s: memory allocation failure\n", progname);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
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,
|
||||
argv[file_index]);
|
||||
else
|
||||
fprintf(stderr, "%s: can't read from stdin\n", progname);
|
||||
}
|
||||
insize += (unsigned long)nbytes;
|
||||
} while (nbytes == INPUT_BUF_SIZE);
|
||||
fprintf(stderr, "Compressed size: %lu bytes\n", insize);
|
||||
jpeg_mem_src(&cinfo, inbuffer, insize);
|
||||
} else
|
||||
jpeg_stdio_src(&cinfo, input_file);
|
||||
|
||||
/* Read file header, set default decompression parameters */
|
||||
(void)jpeg_read_header(&cinfo, TRUE);
|
||||
|
||||
/* Adjust default decompression parameters by re-parsing the options */
|
||||
file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
|
||||
|
||||
/* Initialize the output module now to let it override any crucial
|
||||
* option settings (for instance, GIF wants to force color quantization).
|
||||
*/
|
||||
switch (requested_fmt) {
|
||||
#ifdef BMP_SUPPORTED
|
||||
case FMT_BMP:
|
||||
dest_mgr = jinit_write_bmp(&cinfo, FALSE, TRUE);
|
||||
break;
|
||||
case FMT_OS2:
|
||||
dest_mgr = jinit_write_bmp(&cinfo, TRUE, TRUE);
|
||||
break;
|
||||
#endif
|
||||
#ifdef GIF_SUPPORTED
|
||||
case FMT_GIF:
|
||||
if (cinfo.data_precision == 16)
|
||||
ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision);
|
||||
else if (cinfo.data_precision == 12)
|
||||
dest_mgr = j12init_write_gif(&cinfo, TRUE);
|
||||
else
|
||||
dest_mgr = jinit_write_gif(&cinfo, TRUE);
|
||||
break;
|
||||
case FMT_GIF0:
|
||||
dest_mgr = jinit_write_gif(&cinfo, FALSE);
|
||||
break;
|
||||
#endif
|
||||
#ifdef PPM_SUPPORTED
|
||||
case FMT_PPM:
|
||||
if (cinfo.data_precision == 16)
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
dest_mgr = j16init_write_ppm(&cinfo);
|
||||
#else
|
||||
ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision);
|
||||
#endif
|
||||
else if (cinfo.data_precision == 12)
|
||||
dest_mgr = j12init_write_ppm(&cinfo);
|
||||
else
|
||||
dest_mgr = jinit_write_ppm(&cinfo);
|
||||
break;
|
||||
#endif
|
||||
#ifdef TARGA_SUPPORTED
|
||||
case FMT_TARGA:
|
||||
dest_mgr = jinit_write_targa(&cinfo);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
|
||||
break;
|
||||
}
|
||||
dest_mgr->output_file = output_file;
|
||||
|
||||
/* Start decompressor */
|
||||
(void)jpeg_start_decompress(&cinfo);
|
||||
|
||||
/* Skip rows */
|
||||
if (skip) {
|
||||
JDIMENSION tmp;
|
||||
|
||||
/* Check for valid skip_end. We cannot check this value until after
|
||||
* jpeg_start_decompress() is called. Note that we have already verified
|
||||
* that skip_start <= skip_end.
|
||||
*/
|
||||
if (skip_end > cinfo.output_height - 1) {
|
||||
fprintf(stderr, "%s: skip region exceeds image height %u\n", progname,
|
||||
cinfo.output_height);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Write output file header. This is a hack to ensure that the destination
|
||||
* manager creates an output image of the proper size.
|
||||
*/
|
||||
tmp = cinfo.output_height;
|
||||
cinfo.output_height -= (skip_end - skip_start + 1);
|
||||
(*dest_mgr->start_output) (&cinfo, dest_mgr);
|
||||
cinfo.output_height = tmp;
|
||||
|
||||
if (cinfo.data_precision == 16)
|
||||
ERREXIT(&cinfo, JERR_NOTIMPL);
|
||||
else if (cinfo.data_precision == 12) {
|
||||
/* Process data */
|
||||
while (cinfo.output_scanline < skip_start) {
|
||||
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
|
||||
dest_mgr->buffer_height);
|
||||
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
|
||||
}
|
||||
if ((tmp = jpeg12_skip_scanlines(&cinfo, skip_end - skip_start + 1)) !=
|
||||
skip_end - skip_start + 1) {
|
||||
fprintf(stderr, "%s: jpeg12_skip_scanlines() returned %u rather than %u\n",
|
||||
progname, tmp, skip_end - skip_start + 1);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
while (cinfo.output_scanline < cinfo.output_height) {
|
||||
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
|
||||
dest_mgr->buffer_height);
|
||||
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
|
||||
}
|
||||
} else {
|
||||
/* Process data */
|
||||
while (cinfo.output_scanline < skip_start) {
|
||||
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
|
||||
dest_mgr->buffer_height);
|
||||
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
|
||||
}
|
||||
if ((tmp = jpeg_skip_scanlines(&cinfo, skip_end - skip_start + 1)) !=
|
||||
skip_end - skip_start + 1) {
|
||||
fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n",
|
||||
progname, tmp, skip_end - skip_start + 1);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
while (cinfo.output_scanline < cinfo.output_height) {
|
||||
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
|
||||
dest_mgr->buffer_height);
|
||||
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
|
||||
}
|
||||
}
|
||||
|
||||
/* Decompress a subregion */
|
||||
} else if (crop) {
|
||||
JDIMENSION tmp;
|
||||
|
||||
/* Check for valid crop dimensions. We cannot check these values until
|
||||
* after jpeg_start_decompress() is called.
|
||||
*/
|
||||
if (crop_x + crop_width > cinfo.output_width ||
|
||||
crop_y + crop_height > cinfo.output_height) {
|
||||
fprintf(stderr, "%s: crop dimensions exceed image dimensions %u x %u\n",
|
||||
progname, cinfo.output_width, cinfo.output_height);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (cinfo.data_precision == 16)
|
||||
ERREXIT(&cinfo, JERR_NOTIMPL);
|
||||
else if (cinfo.data_precision == 12)
|
||||
jpeg12_crop_scanline(&cinfo, &crop_x, &crop_width);
|
||||
else
|
||||
jpeg_crop_scanline(&cinfo, &crop_x, &crop_width);
|
||||
if (dest_mgr->calc_buffer_dimensions)
|
||||
(*dest_mgr->calc_buffer_dimensions) (&cinfo, dest_mgr);
|
||||
else
|
||||
ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
|
||||
|
||||
/* Write output file header. This is a hack to ensure that the destination
|
||||
* manager creates an output image of the proper size.
|
||||
*/
|
||||
tmp = cinfo.output_height;
|
||||
cinfo.output_height = crop_height;
|
||||
(*dest_mgr->start_output) (&cinfo, dest_mgr);
|
||||
cinfo.output_height = tmp;
|
||||
|
||||
if (cinfo.data_precision == 16)
|
||||
ERREXIT(&cinfo, JERR_NOTIMPL);
|
||||
else if (cinfo.data_precision == 12) {
|
||||
/* Process data */
|
||||
if ((tmp = jpeg12_skip_scanlines(&cinfo, crop_y)) != crop_y) {
|
||||
fprintf(stderr, "%s: jpeg12_skip_scanlines() returned %u rather than %u\n",
|
||||
progname, tmp, crop_y);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
while (cinfo.output_scanline < crop_y + crop_height) {
|
||||
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
|
||||
dest_mgr->buffer_height);
|
||||
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
|
||||
}
|
||||
if ((tmp =
|
||||
jpeg12_skip_scanlines(&cinfo, cinfo.output_height - crop_y -
|
||||
crop_height)) !=
|
||||
cinfo.output_height - crop_y - crop_height) {
|
||||
fprintf(stderr, "%s: jpeg12_skip_scanlines() returned %u rather than %u\n",
|
||||
progname, tmp, cinfo.output_height - crop_y - crop_height);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
/* Process data */
|
||||
if ((tmp = jpeg_skip_scanlines(&cinfo, crop_y)) != crop_y) {
|
||||
fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n",
|
||||
progname, tmp, crop_y);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
while (cinfo.output_scanline < crop_y + crop_height) {
|
||||
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
|
||||
dest_mgr->buffer_height);
|
||||
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
|
||||
}
|
||||
if ((tmp =
|
||||
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 %u rather than %u\n",
|
||||
progname, tmp, cinfo.output_height - crop_y - crop_height);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Normal full-image decompress */
|
||||
} else {
|
||||
/* Write output file header */
|
||||
(*dest_mgr->start_output) (&cinfo, dest_mgr);
|
||||
|
||||
if (cinfo.data_precision == 16) {
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
/* Process data */
|
||||
while (cinfo.output_scanline < cinfo.output_height) {
|
||||
num_scanlines = jpeg16_read_scanlines(&cinfo, dest_mgr->buffer16,
|
||||
dest_mgr->buffer_height);
|
||||
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
|
||||
}
|
||||
#else
|
||||
ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision);
|
||||
#endif
|
||||
} else if (cinfo.data_precision == 12) {
|
||||
/* Process data */
|
||||
while (cinfo.output_scanline < cinfo.output_height) {
|
||||
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
|
||||
dest_mgr->buffer_height);
|
||||
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
|
||||
}
|
||||
} else {
|
||||
/* Process data */
|
||||
while (cinfo.output_scanline < cinfo.output_height) {
|
||||
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
|
||||
dest_mgr->buffer_height);
|
||||
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Hack: count final pass as done in case finish_output does an extra pass.
|
||||
* The library won't have updated completed_passes.
|
||||
*/
|
||||
if (report || max_scans != 0)
|
||||
progress.pub.completed_passes = progress.pub.total_passes;
|
||||
|
||||
if (icc_filename != NULL) {
|
||||
FILE *icc_file;
|
||||
JOCTET *icc_profile;
|
||||
unsigned int icc_len;
|
||||
|
||||
if ((icc_file = fopen(icc_filename, WRITE_BINARY)) == NULL) {
|
||||
fprintf(stderr, "%s: can't open %s\n", progname, icc_filename);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (jpeg_read_icc_profile(&cinfo, &icc_profile, &icc_len)) {
|
||||
if (fwrite(icc_profile, icc_len, 1, icc_file) < 1) {
|
||||
fprintf(stderr, "%s: can't read ICC profile from %s\n", progname,
|
||||
icc_filename);
|
||||
free(icc_profile);
|
||||
fclose(icc_file);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
free(icc_profile);
|
||||
fclose(icc_file);
|
||||
} else if (cinfo.err->msg_code != JWRN_BOGUS_ICC)
|
||||
fprintf(stderr, "%s: no ICC profile data in JPEG file\n", progname);
|
||||
}
|
||||
|
||||
/* Finish decompression and release memory.
|
||||
* I must do it in this order because output module has allocated memory
|
||||
* of lifespan JPOOL_IMAGE; it needs to finish before releasing memory.
|
||||
*/
|
||||
(*dest_mgr->finish_output) (&cinfo, dest_mgr);
|
||||
(void)jpeg_finish_decompress(&cinfo);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
|
||||
/* Close files, if we opened them */
|
||||
if (input_file != stdin)
|
||||
fclose(input_file);
|
||||
if (output_file != stdout)
|
||||
fclose(output_file);
|
||||
|
||||
if (report || max_scans != 0)
|
||||
end_progress_monitor((j_common_ptr)&cinfo);
|
||||
|
||||
if (memsrc)
|
||||
free(inbuffer);
|
||||
|
||||
/* All done. */
|
||||
exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
|
||||
return 0; /* suppress no-return-value warnings */
|
||||
}
|
643
3rdparty/libjpeg-turbo/src/example.c
vendored
Normal file
643
3rdparty/libjpeg-turbo/src/example.c
vendored
Normal file
@ -0,0 +1,643 @@
|
||||
/*
|
||||
* example.c
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software.
|
||||
* Copyright (C) 1992-1996, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2017, 2019, 2022-2023, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file illustrates how to use the IJG code as a subroutine library
|
||||
* to read or write JPEG image files with 8-bit or 12-bit data precision. You
|
||||
* should look at this code in conjunction with the documentation file
|
||||
* libjpeg.txt.
|
||||
*
|
||||
* We present these routines in the same coding style used in the JPEG code
|
||||
* (ANSI function definitions, etc); but you are of course free to code your
|
||||
* routines in a different style if you prefer.
|
||||
*/
|
||||
|
||||
/* First-time users of libjpeg-turbo might be better served by looking at
|
||||
* tjexample.c, which uses the more straightforward TurboJPEG API. Note that
|
||||
* this example, like cjpeg and djpeg, interleaves disk I/O with JPEG
|
||||
* compression/decompression, so it is not suitable for benchmarking purposes.
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define strcasecmp stricmp
|
||||
#define strncasecmp strnicmp
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Include file for users of JPEG library.
|
||||
* You will need to have included system headers that define at least
|
||||
* the typedefs FILE and size_t before you can include jpeglib.h.
|
||||
* (stdio.h is sufficient on ANSI-conforming systems.)
|
||||
* You may also wish to include "jerror.h".
|
||||
*/
|
||||
|
||||
#include "jpeglib.h"
|
||||
#include "jerror.h"
|
||||
|
||||
/*
|
||||
* <setjmp.h> is used for the optional error recovery mechanism shown in
|
||||
* the second part of the example.
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
|
||||
|
||||
/******************** JPEG COMPRESSION SAMPLE INTERFACE *******************/
|
||||
|
||||
/* This half of the example shows how to feed data into the JPEG compressor.
|
||||
* We present a minimal version that does not worry about refinements such
|
||||
* as error recovery (the JPEG code will just exit() if it gets an error).
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* IMAGE DATA FORMATS:
|
||||
*
|
||||
* The standard input image format is a rectangular array of pixels, with
|
||||
* each pixel having the same number of "component" values (color channels).
|
||||
* Each pixel row is an array of JSAMPLEs (which typically are unsigned chars)
|
||||
* or J12SAMPLEs (which typically are shorts). If you are working with color
|
||||
* data, then the color values for each pixel must be adjacent in the row; for
|
||||
* example, R,G,B,R,G,B,R,G,B,... for 24-bit RGB color.
|
||||
*
|
||||
* For this example, we'll assume that this data structure matches the way
|
||||
* our application has stored the image in memory, so we can just pass a
|
||||
* pointer to our image buffer. In particular, let's say that the image is
|
||||
* RGB color and is described by:
|
||||
*/
|
||||
|
||||
#define WIDTH 640 /* Number of columns in image */
|
||||
#define HEIGHT 480 /* Number of rows in image */
|
||||
|
||||
|
||||
/*
|
||||
* Sample routine for JPEG compression. We assume that the target file name,
|
||||
* a compression quality factor, and a data precision are passed in.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
write_JPEG_file(char *filename, int quality, int data_precision)
|
||||
{
|
||||
/* This struct contains the JPEG compression parameters and pointers to
|
||||
* working space (which is allocated as needed by the JPEG library).
|
||||
* It is possible to have several such structures, representing multiple
|
||||
* compression/decompression processes, in existence at once. We refer
|
||||
* to any one struct (and its associated working data) as a "JPEG object".
|
||||
*/
|
||||
struct jpeg_compress_struct cinfo;
|
||||
/* This struct represents a JPEG error handler. It is declared separately
|
||||
* because applications often want to supply a specialized error handler
|
||||
* (see the second half of this file for an example). But here we just
|
||||
* take the easy way out and use the standard error handler, which will
|
||||
* print a message on stderr and call exit() if compression fails.
|
||||
* Note that this struct must live as long as the main JPEG parameter
|
||||
* struct, to avoid dangling-pointer problems.
|
||||
*/
|
||||
struct jpeg_error_mgr jerr;
|
||||
/* More stuff */
|
||||
FILE *outfile; /* target file */
|
||||
JSAMPARRAY image_buffer = NULL;
|
||||
/* Points to large array of R,G,B-order data */
|
||||
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
|
||||
J12SAMPARRAY image_buffer12 = NULL;
|
||||
/* Points to large array of R,G,B-order 12-bit
|
||||
data */
|
||||
J12SAMPROW row_pointer12[1]; /* pointer to J12SAMPLE row[s] */
|
||||
int row_stride; /* physical row width in image buffer */
|
||||
int row, col;
|
||||
|
||||
/* Step 1: allocate and initialize JPEG compression object */
|
||||
|
||||
/* We have to set up the error handler first, in case the initialization
|
||||
* step fails. (Unlikely, but it could happen if you are out of memory.)
|
||||
* This routine fills in the contents of struct jerr, and returns jerr's
|
||||
* address which we place into the link field in cinfo.
|
||||
*/
|
||||
cinfo.err = jpeg_std_error(&jerr);
|
||||
/* Now we can initialize the JPEG compression object. */
|
||||
jpeg_create_compress(&cinfo);
|
||||
|
||||
/* Step 2: specify data destination (eg, a file) */
|
||||
/* Note: steps 2 and 3 can be done in either order. */
|
||||
|
||||
/* Here we use the library-supplied code to send compressed data to a
|
||||
* stdio stream. You can also write your own code to do something else.
|
||||
* VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
|
||||
* requires it in order to write binary files.
|
||||
*/
|
||||
if ((outfile = fopen(filename, "wb")) == NULL)
|
||||
ERREXIT(&cinfo, JERR_FILE_WRITE);
|
||||
jpeg_stdio_dest(&cinfo, outfile);
|
||||
|
||||
/* Step 3: set parameters for compression */
|
||||
|
||||
/* First we supply a description of the input image.
|
||||
* Four fields of the cinfo struct must be filled in:
|
||||
*/
|
||||
cinfo.image_width = WIDTH; /* image width and height, in pixels */
|
||||
cinfo.image_height = HEIGHT;
|
||||
cinfo.input_components = 3; /* # of color components per pixel */
|
||||
cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
|
||||
cinfo.data_precision = data_precision; /* data precision of input image */
|
||||
/* Now use the library's routine to set default compression parameters.
|
||||
* (You must set at least cinfo.in_color_space before calling this,
|
||||
* since the defaults depend on the source color space.)
|
||||
*/
|
||||
jpeg_set_defaults(&cinfo);
|
||||
/* Now you can set any non-default parameters you wish to.
|
||||
* Here we just illustrate the use of quality (quantization table) scaling:
|
||||
*/
|
||||
jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
|
||||
/* Use 4:4:4 subsampling (default is 4:2:0) */
|
||||
cinfo.comp_info[0].h_samp_factor = cinfo.comp_info[0].v_samp_factor = 1;
|
||||
|
||||
/* Step 4: Start compressor */
|
||||
|
||||
/* TRUE ensures that we will write a complete interchange-JPEG file.
|
||||
* Pass TRUE unless you are very sure of what you're doing.
|
||||
*/
|
||||
jpeg_start_compress(&cinfo, TRUE);
|
||||
|
||||
/* Step 5: allocate and initialize image buffer */
|
||||
|
||||
row_stride = WIDTH * 3; /* J[12]SAMPLEs per row in image_buffer */
|
||||
/* Make a sample array that will go away when done with image. Note that,
|
||||
* for the purposes of this example, we could also create a one-row-high
|
||||
* sample array and initialize it for each successive scanline written in the
|
||||
* scanline loop below.
|
||||
*/
|
||||
if (cinfo.data_precision == 12) {
|
||||
image_buffer12 = (J12SAMPARRAY)(*cinfo.mem->alloc_sarray)
|
||||
((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, HEIGHT);
|
||||
|
||||
/* Initialize image buffer with a repeating pattern */
|
||||
for (row = 0; row < HEIGHT; row++) {
|
||||
for (col = 0; col < WIDTH; col++) {
|
||||
image_buffer12[row][col * 3] =
|
||||
(col * (MAXJ12SAMPLE + 1) / WIDTH) % (MAXJ12SAMPLE + 1);
|
||||
image_buffer12[row][col * 3 + 1] =
|
||||
(row * (MAXJ12SAMPLE + 1) / HEIGHT) % (MAXJ12SAMPLE + 1);
|
||||
image_buffer12[row][col * 3 + 2] =
|
||||
(row * (MAXJ12SAMPLE + 1) / HEIGHT +
|
||||
col * (MAXJ12SAMPLE + 1) / WIDTH) % (MAXJ12SAMPLE + 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
image_buffer = (*cinfo.mem->alloc_sarray)
|
||||
((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, HEIGHT);
|
||||
|
||||
for (row = 0; row < HEIGHT; row++) {
|
||||
for (col = 0; col < WIDTH; col++) {
|
||||
image_buffer[row][col * 3] =
|
||||
(col * (MAXJSAMPLE + 1) / WIDTH) % (MAXJSAMPLE + 1);
|
||||
image_buffer[row][col * 3 + 1] =
|
||||
(row * (MAXJSAMPLE + 1) / HEIGHT) % (MAXJSAMPLE + 1);
|
||||
image_buffer[row][col * 3 + 2] =
|
||||
(row * (MAXJSAMPLE + 1) / HEIGHT + col * (MAXJSAMPLE + 1) / WIDTH) %
|
||||
(MAXJSAMPLE + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Step 6: while (scan lines remain to be written) */
|
||||
/* jpeg_write_scanlines(...); */
|
||||
|
||||
/* Here we use the library's state variable cinfo.next_scanline as the
|
||||
* loop counter, so that we don't have to keep track ourselves.
|
||||
* To keep things simple, we pass one scanline per call; you can pass
|
||||
* more if you wish, though.
|
||||
*/
|
||||
if (cinfo.data_precision == 12) {
|
||||
while (cinfo.next_scanline < cinfo.image_height) {
|
||||
/* jpeg12_write_scanlines expects an array of pointers to scanlines.
|
||||
* Here the array is only one element long, but you could pass
|
||||
* more than one scanline at a time if that's more convenient.
|
||||
*/
|
||||
row_pointer12[0] = image_buffer12[cinfo.next_scanline];
|
||||
(void)jpeg12_write_scanlines(&cinfo, row_pointer12, 1);
|
||||
}
|
||||
} else {
|
||||
while (cinfo.next_scanline < cinfo.image_height) {
|
||||
/* jpeg_write_scanlines expects an array of pointers to scanlines.
|
||||
* Here the array is only one element long, but you could pass
|
||||
* more than one scanline at a time if that's more convenient.
|
||||
*/
|
||||
row_pointer[0] = image_buffer[cinfo.next_scanline];
|
||||
(void)jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Step 7: Finish compression */
|
||||
|
||||
jpeg_finish_compress(&cinfo);
|
||||
/* After finish_compress, we can close the output file. */
|
||||
fclose(outfile);
|
||||
|
||||
/* Step 8: release JPEG compression object */
|
||||
|
||||
/* This is an important step since it will release a good deal of memory. */
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
|
||||
/* And we're done! */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* SOME FINE POINTS:
|
||||
*
|
||||
* In the above loop, we ignored the return value of jpeg_write_scanlines,
|
||||
* which is the number of scanlines actually written. We could get away
|
||||
* with this because we were only relying on the value of cinfo.next_scanline,
|
||||
* which will be incremented correctly. If you maintain additional loop
|
||||
* variables then you should be careful to increment them properly.
|
||||
* Actually, for output to a stdio stream you needn't worry, because
|
||||
* then jpeg_write_scanlines will write all the lines passed (or else exit
|
||||
* with a fatal error). Partial writes can only occur if you use a data
|
||||
* destination module that can demand suspension of the compressor.
|
||||
* (If you don't know what that's for, you don't need it.)
|
||||
*
|
||||
* Scanlines MUST be supplied in top-to-bottom order if you want your JPEG
|
||||
* files to be compatible with everyone else's. If you cannot readily read
|
||||
* your data in that order, you'll need an intermediate array to hold the
|
||||
* image. See rdtarga.c or rdbmp.c for examples of handling bottom-to-top
|
||||
* source data using the JPEG code's internal virtual-array mechanisms.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/******************** JPEG DECOMPRESSION SAMPLE INTERFACE *******************/
|
||||
|
||||
/* This half of the example shows how to read data from the JPEG decompressor.
|
||||
* It's a bit more refined than the above, in that we show:
|
||||
* (a) how to modify the JPEG library's standard error-reporting behavior;
|
||||
* (b) how to allocate workspace using the library's memory manager.
|
||||
*
|
||||
* Just to make this example a little different from the first one, we'll
|
||||
* assume that we do not intend to put the whole image into an in-memory
|
||||
* buffer, but to send it line-by-line someplace else. We need a one-
|
||||
* scanline-high JSAMPLE or J12SAMPLE array as a work buffer, and we will let
|
||||
* the JPEG memory manager allocate it for us. This approach is actually quite
|
||||
* useful because we don't need to remember to deallocate the buffer
|
||||
* separately: it will go away automatically when the JPEG object is cleaned
|
||||
* up.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* ERROR HANDLING:
|
||||
*
|
||||
* The JPEG library's standard error handler (jerror.c) is divided into
|
||||
* several "methods" which you can override individually. This lets you
|
||||
* adjust the behavior without duplicating a lot of code, which you might
|
||||
* have to update with each future release.
|
||||
*
|
||||
* Our example here shows how to override the "error_exit" method so that
|
||||
* control is returned to the library's caller when a fatal error occurs,
|
||||
* rather than calling exit() as the standard error_exit method does.
|
||||
*
|
||||
* We use C's setjmp/longjmp facility to return control. This means that the
|
||||
* routine which calls the JPEG library must first execute a setjmp() call to
|
||||
* establish the return point. We want the replacement error_exit to do a
|
||||
* longjmp(). But we need to make the setjmp buffer accessible to the
|
||||
* error_exit routine. To do this, we make a private extension of the
|
||||
* standard JPEG error handler object. (If we were using C++, we'd say we
|
||||
* were making a subclass of the regular error handler.)
|
||||
*
|
||||
* Here's the extended error handler struct:
|
||||
*/
|
||||
|
||||
struct my_error_mgr {
|
||||
struct jpeg_error_mgr pub; /* "public" fields */
|
||||
|
||||
jmp_buf setjmp_buffer; /* for return to caller */
|
||||
};
|
||||
|
||||
typedef struct my_error_mgr *my_error_ptr;
|
||||
|
||||
/*
|
||||
* Here's the routine that will replace the standard error_exit method:
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
my_error_exit(j_common_ptr cinfo)
|
||||
{
|
||||
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
|
||||
my_error_ptr myerr = (my_error_ptr)cinfo->err;
|
||||
|
||||
/* Always display the message. */
|
||||
/* We could postpone this until after returning, if we chose. */
|
||||
(*cinfo->err->output_message) (cinfo);
|
||||
|
||||
/* Return control to the setjmp point */
|
||||
longjmp(myerr->setjmp_buffer, 1);
|
||||
}
|
||||
|
||||
|
||||
METHODDEF(int) do_read_JPEG_file(struct jpeg_decompress_struct *cinfo,
|
||||
char *infilename, char *outfilename);
|
||||
|
||||
/*
|
||||
* Sample routine for JPEG decompression. We assume that the source file name
|
||||
* is passed in. We want to return 1 on success, 0 on error.
|
||||
*/
|
||||
|
||||
METHODDEF(int)
|
||||
read_JPEG_file(char *infilename, char *outfilename)
|
||||
{
|
||||
/* This struct contains the JPEG decompression parameters and pointers to
|
||||
* working space (which is allocated as needed by the JPEG library).
|
||||
*/
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
|
||||
return do_read_JPEG_file(&cinfo, infilename, outfilename);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
* result in undefined behavior that may potentially overwrite all or part of
|
||||
* the structure.
|
||||
*/
|
||||
|
||||
METHODDEF(int)
|
||||
do_read_JPEG_file(struct jpeg_decompress_struct *cinfo, char *infilename,
|
||||
char *outfilename)
|
||||
{
|
||||
/* We use our private extension JPEG error handler.
|
||||
* Note that this struct must live as long as the main JPEG parameter
|
||||
* struct, to avoid dangling-pointer problems.
|
||||
*/
|
||||
struct my_error_mgr jerr;
|
||||
/* More stuff */
|
||||
FILE *infile; /* source file */
|
||||
FILE *outfile; /* output file */
|
||||
JSAMPARRAY buffer = NULL; /* Output row buffer */
|
||||
J12SAMPARRAY buffer12 = NULL; /* 12-bit output row buffer */
|
||||
int col;
|
||||
int row_stride; /* physical row width in output buffer */
|
||||
int little_endian = 1;
|
||||
|
||||
/* In this example we want to open the input and output files before doing
|
||||
* anything else, so that the setjmp() error recovery below can assume the
|
||||
* files are open.
|
||||
*
|
||||
* VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
|
||||
* requires it in order to read/write binary files.
|
||||
*/
|
||||
|
||||
if ((infile = fopen(infilename, "rb")) == NULL) {
|
||||
fprintf(stderr, "can't open %s\n", infilename);
|
||||
return 0;
|
||||
}
|
||||
if ((outfile = fopen(outfilename, "wb")) == NULL) {
|
||||
fprintf(stderr, "can't open %s\n", outfilename);
|
||||
fclose(infile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Step 1: allocate and initialize JPEG decompression object */
|
||||
|
||||
/* We set up the normal JPEG error routines, then override error_exit. */
|
||||
cinfo->err = jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = my_error_exit;
|
||||
/* Establish the setjmp return context for my_error_exit to use. */
|
||||
if (setjmp(jerr.setjmp_buffer)) {
|
||||
/* If we get here, the JPEG code has signaled an error.
|
||||
* We need to clean up the JPEG object, close the input file, and return.
|
||||
*/
|
||||
jpeg_destroy_decompress(cinfo);
|
||||
fclose(infile);
|
||||
fclose(outfile);
|
||||
return 0;
|
||||
}
|
||||
/* Now we can initialize the JPEG decompression object. */
|
||||
jpeg_create_decompress(cinfo);
|
||||
|
||||
/* Step 2: specify data source (eg, a file) */
|
||||
|
||||
jpeg_stdio_src(cinfo, infile);
|
||||
|
||||
/* Step 3: read file parameters with jpeg_read_header() */
|
||||
|
||||
(void)jpeg_read_header(cinfo, TRUE);
|
||||
/* We can ignore the return value from jpeg_read_header since
|
||||
* (a) suspension is not possible with the stdio data source, and
|
||||
* (b) we passed TRUE to reject a tables-only JPEG file as an error.
|
||||
* See libjpeg.txt for more info.
|
||||
*/
|
||||
|
||||
/* emit header for raw PPM format */
|
||||
fprintf(outfile, "P6\n%d %d\n%d\n", WIDTH, HEIGHT,
|
||||
cinfo->data_precision == 12 ? MAXJ12SAMPLE : MAXJSAMPLE);
|
||||
|
||||
/* Step 4: set parameters for decompression */
|
||||
|
||||
/* In this example, we don't need to change any of the defaults set by
|
||||
* jpeg_read_header(), so we do nothing here.
|
||||
*/
|
||||
|
||||
/* Step 5: Start decompressor */
|
||||
|
||||
(void)jpeg_start_decompress(cinfo);
|
||||
/* We can ignore the return value since suspension is not possible
|
||||
* with the stdio data source.
|
||||
*/
|
||||
|
||||
/* We may need to do some setup of our own at this point before reading
|
||||
* the data. After jpeg_start_decompress() we have the correct scaled
|
||||
* output image dimensions available, as well as the output colormap
|
||||
* if we asked for color quantization.
|
||||
* In this example, we need to make an output work buffer of the right size.
|
||||
*/
|
||||
/* Samples per row in output buffer */
|
||||
row_stride = cinfo->output_width * cinfo->output_components;
|
||||
/* Make a one-row-high sample array that will go away when done with image */
|
||||
if (cinfo->data_precision == 12)
|
||||
buffer12 = (J12SAMPARRAY)(*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE, row_stride, 1);
|
||||
else
|
||||
buffer = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE, row_stride, 1);
|
||||
|
||||
/* Step 6: while (scan lines remain to be read) */
|
||||
/* jpeg_read_scanlines(...); */
|
||||
|
||||
/* Here we use the library's state variable cinfo->output_scanline as the
|
||||
* loop counter, so that we don't have to keep track ourselves.
|
||||
*/
|
||||
if (cinfo->data_precision == 12) {
|
||||
while (cinfo->output_scanline < cinfo->output_height) {
|
||||
/* jpeg12_read_scanlines expects an array of pointers to scanlines.
|
||||
* Here the array is only one element long, but you could ask for
|
||||
* more than one scanline at a time if that's more convenient.
|
||||
*/
|
||||
(void)jpeg12_read_scanlines(cinfo, buffer12, 1);
|
||||
if (*(char *)&little_endian == 1) {
|
||||
/* Swap MSB and LSB in each sample */
|
||||
for (col = 0; col < row_stride; col++)
|
||||
buffer12[0][col] = ((buffer12[0][col] & 0xFF) << 8) |
|
||||
((buffer12[0][col] >> 8) & 0xFF);
|
||||
}
|
||||
fwrite(buffer12[0], 1, row_stride * sizeof(J12SAMPLE), outfile);
|
||||
}
|
||||
} else {
|
||||
while (cinfo->output_scanline < cinfo->output_height) {
|
||||
/* jpeg_read_scanlines expects an array of pointers to scanlines.
|
||||
* Here the array is only one element long, but you could ask for
|
||||
* more than one scanline at a time if that's more convenient.
|
||||
*/
|
||||
(void)jpeg_read_scanlines(cinfo, buffer, 1);
|
||||
fwrite(buffer[0], 1, row_stride, outfile);
|
||||
}
|
||||
}
|
||||
|
||||
/* Step 7: Finish decompression */
|
||||
|
||||
(void)jpeg_finish_decompress(cinfo);
|
||||
/* We can ignore the return value since suspension is not possible
|
||||
* with the stdio data source.
|
||||
*/
|
||||
|
||||
/* Step 8: Release JPEG decompression object */
|
||||
|
||||
/* This is an important step since it will release a good deal of memory. */
|
||||
jpeg_destroy_decompress(cinfo);
|
||||
|
||||
/* After finish_decompress, we can close the input and output files.
|
||||
* Here we postpone it until after no more JPEG errors are possible,
|
||||
* so as to simplify the setjmp error logic above. (Actually, I don't
|
||||
* think that jpeg_destroy can do an error exit, but why assume anything...)
|
||||
*/
|
||||
fclose(infile);
|
||||
fclose(outfile);
|
||||
|
||||
/* At this point you may want to check to see whether any corrupt-data
|
||||
* warnings occurred (test whether jerr.pub.num_warnings is nonzero).
|
||||
*/
|
||||
|
||||
/* And we're done! */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* SOME FINE POINTS:
|
||||
*
|
||||
* In the above code, we ignored the return value of jpeg_read_scanlines,
|
||||
* which is the number of scanlines actually read. We could get away with
|
||||
* this because we asked for only one line at a time and we weren't using
|
||||
* a suspending data source. See libjpeg.txt for more info.
|
||||
*
|
||||
* We cheated a bit by calling alloc_sarray() after jpeg_start_decompress();
|
||||
* we should have done it beforehand to ensure that the space would be
|
||||
* counted against the JPEG max_memory setting. In some systems the above
|
||||
* code would risk an out-of-memory error. However, in general we don't
|
||||
* know the output image dimensions before jpeg_start_decompress(), unless we
|
||||
* call jpeg_calc_output_dimensions(). See libjpeg.txt for more about this.
|
||||
*
|
||||
* Scanlines are returned in the same order as they appear in the JPEG file,
|
||||
* which is standardly top-to-bottom. If you must emit data bottom-to-top,
|
||||
* you can use one of the virtual arrays provided by the JPEG memory manager
|
||||
* to invert the data. See wrbmp.c for an example.
|
||||
*/
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
usage(const char *progname)
|
||||
{
|
||||
fprintf(stderr, "usage: %s compress [switches] outputfile[.jpg]\n",
|
||||
progname);
|
||||
fprintf(stderr, " %s decompress inputfile[.jpg] outputfile[.ppm]\n",
|
||||
progname);
|
||||
fprintf(stderr, "Switches (names may be abbreviated):\n");
|
||||
fprintf(stderr, " -precision N Create JPEG file with N-bit data precision\n");
|
||||
fprintf(stderr, " (N is 8 or 12; default is 8)\n");
|
||||
fprintf(stderr, " -quality N Compression quality (0..100; 5-95 is most useful range,\n");
|
||||
fprintf(stderr, " default is 75)\n");
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
typedef enum {
|
||||
COMPRESS,
|
||||
DECOMPRESS
|
||||
} EXAMPLE_MODE;
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int argn, quality = 75;
|
||||
int data_precision = 8;
|
||||
EXAMPLE_MODE mode = -1;
|
||||
char *arg, *filename = NULL;
|
||||
|
||||
if (argc < 3)
|
||||
usage(argv[0]);
|
||||
|
||||
if (!strcasecmp(argv[1], "compress"))
|
||||
mode = COMPRESS;
|
||||
else if (!strcasecmp(argv[1], "decompress"))
|
||||
mode = DECOMPRESS;
|
||||
else
|
||||
usage(argv[0]);
|
||||
|
||||
for (argn = 2; argn < argc; argn++) {
|
||||
arg = argv[argn];
|
||||
if (*arg != '-') {
|
||||
filename = arg;
|
||||
/* Not a switch, must be a file name argument */
|
||||
break; /* done parsing switches */
|
||||
}
|
||||
arg++; /* advance past switch marker character */
|
||||
|
||||
if (!strncasecmp(arg, "p", 1)) {
|
||||
/* Set data precision. */
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage(argv[0]);
|
||||
if (sscanf(argv[argn], "%d", &data_precision) < 1 ||
|
||||
(data_precision != 8 && data_precision != 12))
|
||||
usage(argv[0]);
|
||||
} else if (!strncasecmp(arg, "q", 1)) {
|
||||
/* Quality rating (quantization table scaling factor). */
|
||||
if (++argn >= argc) /* advance to next argument */
|
||||
usage(argv[0]);
|
||||
if (sscanf(argv[argn], "%d", &quality) < 1 || quality < 0 ||
|
||||
quality > 100)
|
||||
usage(argv[0]);
|
||||
if (quality < 1)
|
||||
quality = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!filename)
|
||||
usage(argv[0]);
|
||||
|
||||
if (mode == COMPRESS)
|
||||
write_JPEG_file(filename, quality, data_precision);
|
||||
else if (mode == DECOMPRESS) {
|
||||
if (argc - argn < 2)
|
||||
usage(argv[0]);
|
||||
|
||||
read_JPEG_file(argv[argn], argv[argn + 1]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
27
3rdparty/libjpeg-turbo/src/jcapimin.c
vendored
27
3rdparty/libjpeg-turbo/src/jcapimin.c
vendored
@ -23,6 +23,7 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jcmaster.h"
|
||||
|
||||
|
||||
/*
|
||||
@ -90,8 +91,18 @@ jpeg_CreateCompress(j_compress_ptr cinfo, int version, size_t structsize)
|
||||
|
||||
cinfo->input_gamma = 1.0; /* in case application forgets */
|
||||
|
||||
cinfo->data_precision = BITS_IN_JSAMPLE;
|
||||
|
||||
/* OK, I'm ready */
|
||||
cinfo->global_state = CSTATE_START;
|
||||
|
||||
/* The master struct is used to store extension parameters, so we allocate it
|
||||
* here.
|
||||
*/
|
||||
cinfo->master = (struct jpeg_comp_master *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
|
||||
sizeof(my_comp_master));
|
||||
memset(cinfo->master, 0, sizeof(my_comp_master));
|
||||
}
|
||||
|
||||
|
||||
@ -183,8 +194,20 @@ jpeg_finish_compress(j_compress_ptr cinfo)
|
||||
/* We bypass the main controller and invoke coef controller directly;
|
||||
* all work is being done from the coefficient buffer.
|
||||
*/
|
||||
if (!(*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE)NULL))
|
||||
ERREXIT(cinfo, JERR_CANT_SUSPEND);
|
||||
if (cinfo->data_precision == 16) {
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
if (!(*cinfo->coef->compress_data_16) (cinfo, (J16SAMPIMAGE)NULL))
|
||||
ERREXIT(cinfo, JERR_CANT_SUSPEND);
|
||||
#else
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
#endif
|
||||
} else if (cinfo->data_precision == 12) {
|
||||
if (!(*cinfo->coef->compress_data_12) (cinfo, (J12SAMPIMAGE)NULL))
|
||||
ERREXIT(cinfo, JERR_CANT_SUSPEND);
|
||||
} else {
|
||||
if (!(*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE)NULL))
|
||||
ERREXIT(cinfo, JERR_CANT_SUSPEND);
|
||||
}
|
||||
}
|
||||
(*cinfo->master->finish_pass) (cinfo);
|
||||
}
|
||||
|
53
3rdparty/libjpeg-turbo/src/jcapistd.c
vendored
53
3rdparty/libjpeg-turbo/src/jcapistd.c
vendored
@ -1,8 +1,10 @@
|
||||
/*
|
||||
* jcapistd.c
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -18,8 +20,11 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
|
||||
/*
|
||||
* Compression initialization.
|
||||
* Before calling this, all parameters and a data destination must be set up.
|
||||
@ -51,13 +56,15 @@ jpeg_start_compress(j_compress_ptr cinfo, boolean write_all_tables)
|
||||
jinit_compress_master(cinfo);
|
||||
/* Set up for the first pass */
|
||||
(*cinfo->master->prepare_for_pass) (cinfo);
|
||||
/* Ready for application to drive first pass through jpeg_write_scanlines
|
||||
* or jpeg_write_raw_data.
|
||||
/* Ready for application to drive first pass through _jpeg_write_scanlines
|
||||
* or _jpeg_write_raw_data.
|
||||
*/
|
||||
cinfo->next_scanline = 0;
|
||||
cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Write some scanlines of data to the JPEG compressor.
|
||||
@ -67,7 +74,7 @@ jpeg_start_compress(j_compress_ptr cinfo, boolean write_all_tables)
|
||||
* the data destination module has requested suspension of the compressor,
|
||||
* or if more than image_height scanlines are passed in.
|
||||
*
|
||||
* Note: we warn about excess calls to jpeg_write_scanlines() since
|
||||
* Note: we warn about excess calls to _jpeg_write_scanlines() since
|
||||
* this likely signals an application programmer error. However,
|
||||
* excess scanlines passed in the last valid call are *silently* ignored,
|
||||
* so that the application need not adjust num_lines for end-of-image
|
||||
@ -75,11 +82,15 @@ jpeg_start_compress(j_compress_ptr cinfo, boolean write_all_tables)
|
||||
*/
|
||||
|
||||
GLOBAL(JDIMENSION)
|
||||
jpeg_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines,
|
||||
JDIMENSION num_lines)
|
||||
_jpeg_write_scanlines(j_compress_ptr cinfo, _JSAMPARRAY scanlines,
|
||||
JDIMENSION num_lines)
|
||||
{
|
||||
#if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)
|
||||
JDIMENSION row_ctr, rows_left;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
if (cinfo->global_state != CSTATE_SCANNING)
|
||||
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
||||
if (cinfo->next_scanline >= cinfo->image_height)
|
||||
@ -93,9 +104,9 @@ jpeg_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines,
|
||||
}
|
||||
|
||||
/* Give master control module another chance if this is first call to
|
||||
* jpeg_write_scanlines. This lets output of the frame/scan headers be
|
||||
* _jpeg_write_scanlines. This lets output of the frame/scan headers be
|
||||
* delayed so that application can write COM, etc, markers between
|
||||
* jpeg_start_compress and jpeg_write_scanlines.
|
||||
* jpeg_start_compress and _jpeg_write_scanlines.
|
||||
*/
|
||||
if (cinfo->master->call_pass_startup)
|
||||
(*cinfo->master->pass_startup) (cinfo);
|
||||
@ -106,23 +117,35 @@ jpeg_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines,
|
||||
num_lines = rows_left;
|
||||
|
||||
row_ctr = 0;
|
||||
(*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
|
||||
(*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, num_lines);
|
||||
cinfo->next_scanline += row_ctr;
|
||||
return row_ctr;
|
||||
#else
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
|
||||
/*
|
||||
* Alternate entry point to write raw data.
|
||||
* Processes exactly one iMCU row per call, unless suspended.
|
||||
*/
|
||||
|
||||
GLOBAL(JDIMENSION)
|
||||
jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
|
||||
JDIMENSION num_lines)
|
||||
_jpeg_write_raw_data(j_compress_ptr cinfo, _JSAMPIMAGE data,
|
||||
JDIMENSION num_lines)
|
||||
{
|
||||
JDIMENSION lines_per_iMCU_row;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
if (cinfo->master->lossless)
|
||||
ERREXIT(cinfo, JERR_NOTIMPL);
|
||||
|
||||
if (cinfo->global_state != CSTATE_RAW_OK)
|
||||
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
||||
if (cinfo->next_scanline >= cinfo->image_height) {
|
||||
@ -138,9 +161,9 @@ jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
|
||||
}
|
||||
|
||||
/* Give master control module another chance if this is first call to
|
||||
* jpeg_write_raw_data. This lets output of the frame/scan headers be
|
||||
* _jpeg_write_raw_data. This lets output of the frame/scan headers be
|
||||
* delayed so that application can write COM, etc, markers between
|
||||
* jpeg_start_compress and jpeg_write_raw_data.
|
||||
* jpeg_start_compress and _jpeg_write_raw_data.
|
||||
*/
|
||||
if (cinfo->master->call_pass_startup)
|
||||
(*cinfo->master->pass_startup) (cinfo);
|
||||
@ -151,7 +174,7 @@ jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
|
||||
ERREXIT(cinfo, JERR_BUFFER_SIZE);
|
||||
|
||||
/* Directly compress the row. */
|
||||
if (!(*cinfo->coef->compress_data) (cinfo, data)) {
|
||||
if (!(*cinfo->coef->_compress_data) (cinfo, data)) {
|
||||
/* If compressor did not consume the whole row, suspend processing. */
|
||||
return 0;
|
||||
}
|
||||
@ -160,3 +183,5 @@ jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
|
||||
cinfo->next_scanline += lines_per_iMCU_row;
|
||||
return lines_per_iMCU_row;
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE != 16 */
|
||||
|
47
3rdparty/libjpeg-turbo/src/jccoefct.c
vendored
47
3rdparty/libjpeg-turbo/src/jccoefct.c
vendored
@ -3,19 +3,20 @@
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||
* It was modified by The libjpeg-turbo Project to include only code and
|
||||
* information relevant to libjpeg-turbo.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file contains the coefficient buffer controller for compression.
|
||||
* This controller is the top level of the JPEG compressor proper.
|
||||
* This controller is the top level of the lossy JPEG compressor proper.
|
||||
* The coefficient buffer lies between forward-DCT and entropy encoding steps.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
|
||||
/* We use a full-image coefficient buffer when doing Huffman optimization,
|
||||
@ -58,11 +59,12 @@ typedef my_coef_controller *my_coef_ptr;
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF(boolean) compress_data(j_compress_ptr cinfo, JSAMPIMAGE input_buf);
|
||||
METHODDEF(boolean) compress_data(j_compress_ptr cinfo, _JSAMPIMAGE input_buf);
|
||||
#ifdef FULL_COEF_BUFFER_SUPPORTED
|
||||
METHODDEF(boolean) compress_first_pass(j_compress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf);
|
||||
METHODDEF(boolean) compress_output(j_compress_ptr cinfo, JSAMPIMAGE input_buf);
|
||||
_JSAMPIMAGE input_buf);
|
||||
METHODDEF(boolean) compress_output(j_compress_ptr cinfo,
|
||||
_JSAMPIMAGE input_buf);
|
||||
#endif
|
||||
|
||||
|
||||
@ -106,18 +108,18 @@ start_pass_coef(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
case JBUF_PASS_THRU:
|
||||
if (coef->whole_image[0] != NULL)
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
coef->pub.compress_data = compress_data;
|
||||
coef->pub._compress_data = compress_data;
|
||||
break;
|
||||
#ifdef FULL_COEF_BUFFER_SUPPORTED
|
||||
case JBUF_SAVE_AND_PASS:
|
||||
if (coef->whole_image[0] == NULL)
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
coef->pub.compress_data = compress_first_pass;
|
||||
coef->pub._compress_data = compress_first_pass;
|
||||
break;
|
||||
case JBUF_CRANK_DEST:
|
||||
if (coef->whole_image[0] == NULL)
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
coef->pub.compress_data = compress_output;
|
||||
coef->pub._compress_data = compress_output;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
@ -138,7 +140,7 @@ start_pass_coef(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
compress_data(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
compress_data(j_compress_ptr cinfo, _JSAMPIMAGE input_buf)
|
||||
{
|
||||
my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
|
||||
JDIMENSION MCU_col_num; /* index of current MCU within row */
|
||||
@ -172,10 +174,10 @@ compress_data(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||
if (coef->iMCU_row_num < last_iMCU_row ||
|
||||
yoffset + yindex < compptr->last_row_height) {
|
||||
(*cinfo->fdct->forward_DCT) (cinfo, compptr,
|
||||
input_buf[compptr->component_index],
|
||||
coef->MCU_buffer[blkn],
|
||||
ypos, xpos, (JDIMENSION)blockcnt);
|
||||
(*cinfo->fdct->_forward_DCT) (cinfo, compptr,
|
||||
input_buf[compptr->component_index],
|
||||
coef->MCU_buffer[blkn],
|
||||
ypos, xpos, (JDIMENSION)blockcnt);
|
||||
if (blockcnt < compptr->MCU_width) {
|
||||
/* Create some dummy blocks at the right edge of the image. */
|
||||
jzero_far((void *)coef->MCU_buffer[blkn + blockcnt],
|
||||
@ -242,7 +244,7 @@ compress_data(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
compress_first_pass(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
compress_first_pass(j_compress_ptr cinfo, _JSAMPIMAGE input_buf)
|
||||
{
|
||||
my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
|
||||
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
|
||||
@ -279,10 +281,10 @@ compress_first_pass(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
*/
|
||||
for (block_row = 0; block_row < block_rows; block_row++) {
|
||||
thisblockrow = buffer[block_row];
|
||||
(*cinfo->fdct->forward_DCT) (cinfo, compptr,
|
||||
input_buf[ci], thisblockrow,
|
||||
(JDIMENSION)(block_row * DCTSIZE),
|
||||
(JDIMENSION)0, blocks_across);
|
||||
(*cinfo->fdct->_forward_DCT) (cinfo, compptr,
|
||||
input_buf[ci], thisblockrow,
|
||||
(JDIMENSION)(block_row * DCTSIZE),
|
||||
(JDIMENSION)0, blocks_across);
|
||||
if (ndummy > 0) {
|
||||
/* Create dummy blocks at the right edge of the image. */
|
||||
thisblockrow += blocks_across; /* => first dummy block */
|
||||
@ -338,7 +340,7 @@ compress_first_pass(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
compress_output(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
compress_output(j_compress_ptr cinfo, _JSAMPIMAGE input_buf)
|
||||
{
|
||||
my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
|
||||
JDIMENSION MCU_col_num; /* index of current MCU within row */
|
||||
@ -402,10 +404,13 @@ compress_output(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_c_coef_controller(j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
_jinit_c_coef_controller(j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_coef_ptr coef;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
coef = (my_coef_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_coef_controller));
|
||||
|
64
3rdparty/libjpeg-turbo/src/jccolext.c
vendored
64
3rdparty/libjpeg-turbo/src/jccolext.c
vendored
@ -4,7 +4,7 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2009-2012, 2015, D. R. Commander.
|
||||
* Copyright (C) 2009-2012, 2015, 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -29,15 +29,16 @@
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
rgb_ycc_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPIMAGE output_buf, JDIMENSION output_row,
|
||||
rgb_ycc_convert_internal(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPIMAGE output_buf, JDIMENSION output_row,
|
||||
int num_rows)
|
||||
{
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
|
||||
register int r, g, b;
|
||||
register JLONG *ctab = cconvert->rgb_ycc_tab;
|
||||
register JSAMPROW inptr;
|
||||
register JSAMPROW outptr0, outptr1, outptr2;
|
||||
register _JSAMPROW inptr;
|
||||
register _JSAMPROW outptr0, outptr1, outptr2;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->image_width;
|
||||
|
||||
@ -48,26 +49,29 @@ rgb_ycc_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
outptr2 = output_buf[2][output_row];
|
||||
output_row++;
|
||||
for (col = 0; col < num_cols; col++) {
|
||||
r = inptr[RGB_RED];
|
||||
g = inptr[RGB_GREEN];
|
||||
b = inptr[RGB_BLUE];
|
||||
r = RANGE_LIMIT(inptr[RGB_RED]);
|
||||
g = RANGE_LIMIT(inptr[RGB_GREEN]);
|
||||
b = RANGE_LIMIT(inptr[RGB_BLUE]);
|
||||
inptr += RGB_PIXELSIZE;
|
||||
/* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
|
||||
/* If the inputs are 0.._MAXJSAMPLE, the outputs of these equations
|
||||
* must be too; we do not need an explicit range-limiting operation.
|
||||
* Hence the value being shifted is never negative, and we don't
|
||||
* need the general RIGHT_SHIFT macro.
|
||||
*/
|
||||
/* Y */
|
||||
outptr0[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
|
||||
ctab[b + B_Y_OFF]) >> SCALEBITS);
|
||||
outptr0[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
|
||||
ctab[b + B_Y_OFF]) >> SCALEBITS);
|
||||
/* Cb */
|
||||
outptr1[col] = (JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
|
||||
ctab[b + B_CB_OFF]) >> SCALEBITS);
|
||||
outptr1[col] = (_JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
|
||||
ctab[b + B_CB_OFF]) >> SCALEBITS);
|
||||
/* Cr */
|
||||
outptr2[col] = (JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
|
||||
ctab[b + B_CR_OFF]) >> SCALEBITS);
|
||||
outptr2[col] = (_JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
|
||||
ctab[b + B_CR_OFF]) >> SCALEBITS);
|
||||
}
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -83,15 +87,16 @@ rgb_ycc_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
rgb_gray_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPIMAGE output_buf, JDIMENSION output_row,
|
||||
rgb_gray_convert_internal(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPIMAGE output_buf, JDIMENSION output_row,
|
||||
int num_rows)
|
||||
{
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
|
||||
register int r, g, b;
|
||||
register JLONG *ctab = cconvert->rgb_ycc_tab;
|
||||
register JSAMPROW inptr;
|
||||
register JSAMPROW outptr;
|
||||
register _JSAMPROW inptr;
|
||||
register _JSAMPROW outptr;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->image_width;
|
||||
|
||||
@ -100,15 +105,18 @@ rgb_gray_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
outptr = output_buf[0][output_row];
|
||||
output_row++;
|
||||
for (col = 0; col < num_cols; col++) {
|
||||
r = inptr[RGB_RED];
|
||||
g = inptr[RGB_GREEN];
|
||||
b = inptr[RGB_BLUE];
|
||||
r = RANGE_LIMIT(inptr[RGB_RED]);
|
||||
g = RANGE_LIMIT(inptr[RGB_GREEN]);
|
||||
b = RANGE_LIMIT(inptr[RGB_BLUE]);
|
||||
inptr += RGB_PIXELSIZE;
|
||||
/* Y */
|
||||
outptr[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
|
||||
ctab[b + B_Y_OFF]) >> SCALEBITS);
|
||||
outptr[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
|
||||
ctab[b + B_Y_OFF]) >> SCALEBITS);
|
||||
}
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -119,12 +127,12 @@ rgb_gray_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
rgb_rgb_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPIMAGE output_buf, JDIMENSION output_row,
|
||||
rgb_rgb_convert_internal(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPIMAGE output_buf, JDIMENSION output_row,
|
||||
int num_rows)
|
||||
{
|
||||
register JSAMPROW inptr;
|
||||
register JSAMPROW outptr0, outptr1, outptr2;
|
||||
register _JSAMPROW inptr;
|
||||
register _JSAMPROW outptr0, outptr1, outptr2;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->image_width;
|
||||
|
||||
|
248
3rdparty/libjpeg-turbo/src/jccolor.c
vendored
248
3rdparty/libjpeg-turbo/src/jccolor.c
vendored
@ -5,7 +5,7 @@
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
||||
* Copyright (C) 2009-2012, 2015, D. R. Commander.
|
||||
* Copyright (C) 2009-2012, 2015, 2022, D. R. Commander.
|
||||
* Copyright (C) 2014, MIPS Technologies, Inc., California.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
@ -17,16 +17,20 @@
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jsimd.h"
|
||||
#include "jconfigint.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)
|
||||
|
||||
/* Private subobject */
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_color_converter pub; /* public fields */
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
/* Private state for RGB->YCC conversion */
|
||||
JLONG *rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
|
||||
#endif
|
||||
} my_color_converter;
|
||||
|
||||
typedef my_color_converter *my_cconvert_ptr;
|
||||
@ -36,14 +40,14 @@ typedef my_color_converter *my_cconvert_ptr;
|
||||
|
||||
/*
|
||||
* YCbCr is defined per CCIR 601-1, except that Cb and Cr are
|
||||
* normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
|
||||
* normalized to the range 0.._MAXJSAMPLE rather than -0.5 .. 0.5.
|
||||
* The conversion equations to be implemented are therefore
|
||||
* Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
|
||||
* Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
|
||||
* Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
|
||||
* Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + _CENTERJSAMPLE
|
||||
* Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + _CENTERJSAMPLE
|
||||
* (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
|
||||
* Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,
|
||||
* rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and
|
||||
* Note: older versions of the IJG code used a zero offset of _MAXJSAMPLE/2,
|
||||
* rather than _CENTERJSAMPLE, for Cb and Cr. This gave equal positive and
|
||||
* negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0)
|
||||
* were not represented exactly. Now we sacrifice exact representation of
|
||||
* maximum red and maximum blue in order to get exact grayscales.
|
||||
@ -54,16 +58,16 @@ typedef my_color_converter *my_cconvert_ptr;
|
||||
*
|
||||
* For even more speed, we avoid doing any multiplications in the inner loop
|
||||
* by precalculating the constants times R,G,B for all possible values.
|
||||
* For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
|
||||
* For 8-bit samples this is very reasonable (only 256 entries per table);
|
||||
* for 12-bit samples it is still acceptable. It's not very reasonable for
|
||||
* 16-bit samples, but if you want lossless storage you shouldn't be changing
|
||||
* colorspace anyway.
|
||||
* The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
|
||||
* The _CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
|
||||
* in the tables to save adding them separately in the inner loop.
|
||||
*/
|
||||
|
||||
#define SCALEBITS 16 /* speediest right-shift on some machines */
|
||||
#define CBCR_OFFSET ((JLONG)CENTERJSAMPLE << SCALEBITS)
|
||||
#define CBCR_OFFSET ((JLONG)_CENTERJSAMPLE << SCALEBITS)
|
||||
#define ONE_HALF ((JLONG)1 << (SCALEBITS - 1))
|
||||
#define FIX(x) ((JLONG)((x) * (1L << SCALEBITS) + 0.5))
|
||||
|
||||
@ -74,15 +78,27 @@ typedef my_color_converter *my_cconvert_ptr;
|
||||
*/
|
||||
|
||||
#define R_Y_OFF 0 /* offset to R => Y section */
|
||||
#define G_Y_OFF (1 * (MAXJSAMPLE + 1)) /* offset to G => Y section */
|
||||
#define B_Y_OFF (2 * (MAXJSAMPLE + 1)) /* etc. */
|
||||
#define R_CB_OFF (3 * (MAXJSAMPLE + 1))
|
||||
#define G_CB_OFF (4 * (MAXJSAMPLE + 1))
|
||||
#define B_CB_OFF (5 * (MAXJSAMPLE + 1))
|
||||
#define G_Y_OFF (1 * (_MAXJSAMPLE + 1)) /* offset to G => Y section */
|
||||
#define B_Y_OFF (2 * (_MAXJSAMPLE + 1)) /* etc. */
|
||||
#define R_CB_OFF (3 * (_MAXJSAMPLE + 1))
|
||||
#define G_CB_OFF (4 * (_MAXJSAMPLE + 1))
|
||||
#define B_CB_OFF (5 * (_MAXJSAMPLE + 1))
|
||||
#define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
|
||||
#define G_CR_OFF (6 * (MAXJSAMPLE + 1))
|
||||
#define B_CR_OFF (7 * (MAXJSAMPLE + 1))
|
||||
#define TABLE_SIZE (8 * (MAXJSAMPLE + 1))
|
||||
#define G_CR_OFF (6 * (_MAXJSAMPLE + 1))
|
||||
#define B_CR_OFF (7 * (_MAXJSAMPLE + 1))
|
||||
#define TABLE_SIZE (8 * (_MAXJSAMPLE + 1))
|
||||
|
||||
/* 12-bit samples use a 16-bit data type, so it is possible to pass
|
||||
* out-of-range sample values (< 0 or > 4095) to jpeg_write_scanlines().
|
||||
* Thus, we mask the incoming 12-bit samples to guard against overrunning
|
||||
* or underrunning the conversion tables.
|
||||
*/
|
||||
|
||||
#if BITS_IN_JSAMPLE == 12
|
||||
#define RANGE_LIMIT(value) ((value) & 0xFFF)
|
||||
#else
|
||||
#define RANGE_LIMIT(value) (value)
|
||||
#endif
|
||||
|
||||
|
||||
/* Include inline routines for colorspace extensions */
|
||||
@ -197,6 +213,7 @@ typedef my_color_converter *my_cconvert_ptr;
|
||||
METHODDEF(void)
|
||||
rgb_ycc_start(j_compress_ptr cinfo)
|
||||
{
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
|
||||
JLONG *rgb_ycc_tab;
|
||||
JLONG i;
|
||||
@ -206,15 +223,15 @@ rgb_ycc_start(j_compress_ptr cinfo)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(TABLE_SIZE * sizeof(JLONG)));
|
||||
|
||||
for (i = 0; i <= MAXJSAMPLE; i++) {
|
||||
for (i = 0; i <= _MAXJSAMPLE; i++) {
|
||||
rgb_ycc_tab[i + R_Y_OFF] = FIX(0.29900) * i;
|
||||
rgb_ycc_tab[i + G_Y_OFF] = FIX(0.58700) * i;
|
||||
rgb_ycc_tab[i + B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
|
||||
rgb_ycc_tab[i + R_CB_OFF] = (-FIX(0.16874)) * i;
|
||||
rgb_ycc_tab[i + G_CB_OFF] = (-FIX(0.33126)) * i;
|
||||
/* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
|
||||
* This ensures that the maximum output will round to MAXJSAMPLE
|
||||
* not MAXJSAMPLE+1, and thus that we don't have to range-limit.
|
||||
* This ensures that the maximum output will round to _MAXJSAMPLE
|
||||
* not _MAXJSAMPLE+1, and thus that we don't have to range-limit.
|
||||
*/
|
||||
rgb_ycc_tab[i + B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF - 1;
|
||||
/* B=>Cb and R=>Cr tables are the same
|
||||
@ -223,6 +240,9 @@ rgb_ycc_start(j_compress_ptr cinfo)
|
||||
rgb_ycc_tab[i + G_CR_OFF] = (-FIX(0.41869)) * i;
|
||||
rgb_ycc_tab[i + B_CR_OFF] = (-FIX(0.08131)) * i;
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -231,8 +251,8 @@ rgb_ycc_start(j_compress_ptr cinfo)
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
|
||||
rgb_ycc_convert(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
|
||||
{
|
||||
switch (cinfo->in_color_space) {
|
||||
case JCS_EXT_RGB:
|
||||
@ -279,8 +299,8 @@ rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
|
||||
rgb_gray_convert(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
|
||||
{
|
||||
switch (cinfo->in_color_space) {
|
||||
case JCS_EXT_RGB:
|
||||
@ -324,8 +344,8 @@ rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
rgb_rgb_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
|
||||
rgb_rgb_convert(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
|
||||
{
|
||||
switch (cinfo->in_color_space) {
|
||||
case JCS_EXT_RGB:
|
||||
@ -373,14 +393,15 @@ rgb_rgb_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
cmyk_ycck_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
|
||||
cmyk_ycck_convert(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
|
||||
{
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
|
||||
register int r, g, b;
|
||||
register JLONG *ctab = cconvert->rgb_ycc_tab;
|
||||
register JSAMPROW inptr;
|
||||
register JSAMPROW outptr0, outptr1, outptr2, outptr3;
|
||||
register _JSAMPROW inptr;
|
||||
register _JSAMPROW outptr0, outptr1, outptr2, outptr3;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->image_width;
|
||||
|
||||
@ -392,28 +413,31 @@ cmyk_ycck_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
outptr3 = output_buf[3][output_row];
|
||||
output_row++;
|
||||
for (col = 0; col < num_cols; col++) {
|
||||
r = MAXJSAMPLE - inptr[0];
|
||||
g = MAXJSAMPLE - inptr[1];
|
||||
b = MAXJSAMPLE - inptr[2];
|
||||
r = _MAXJSAMPLE - RANGE_LIMIT(inptr[0]);
|
||||
g = _MAXJSAMPLE - RANGE_LIMIT(inptr[1]);
|
||||
b = _MAXJSAMPLE - RANGE_LIMIT(inptr[2]);
|
||||
/* K passes through as-is */
|
||||
outptr3[col] = inptr[3];
|
||||
inptr += 4;
|
||||
/* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
|
||||
/* If the inputs are 0.._MAXJSAMPLE, the outputs of these equations
|
||||
* must be too; we do not need an explicit range-limiting operation.
|
||||
* Hence the value being shifted is never negative, and we don't
|
||||
* need the general RIGHT_SHIFT macro.
|
||||
*/
|
||||
/* Y */
|
||||
outptr0[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
|
||||
ctab[b + B_Y_OFF]) >> SCALEBITS);
|
||||
outptr0[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
|
||||
ctab[b + B_Y_OFF]) >> SCALEBITS);
|
||||
/* Cb */
|
||||
outptr1[col] = (JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
|
||||
ctab[b + B_CB_OFF]) >> SCALEBITS);
|
||||
outptr1[col] = (_JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
|
||||
ctab[b + B_CB_OFF]) >> SCALEBITS);
|
||||
/* Cr */
|
||||
outptr2[col] = (JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
|
||||
ctab[b + B_CR_OFF]) >> SCALEBITS);
|
||||
outptr2[col] = (_JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
|
||||
ctab[b + B_CR_OFF]) >> SCALEBITS);
|
||||
}
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -424,11 +448,11 @@ cmyk_ycck_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
grayscale_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
|
||||
grayscale_convert(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
|
||||
{
|
||||
register JSAMPROW inptr;
|
||||
register JSAMPROW outptr;
|
||||
register _JSAMPROW inptr;
|
||||
register _JSAMPROW outptr;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->image_width;
|
||||
int instride = cinfo->input_components;
|
||||
@ -452,11 +476,11 @@ grayscale_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
null_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
null_convert(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
|
||||
{
|
||||
register JSAMPROW inptr;
|
||||
register JSAMPROW outptr, outptr0, outptr1, outptr2, outptr3;
|
||||
register _JSAMPROW inptr;
|
||||
register _JSAMPROW outptr, outptr0, outptr1, outptr2, outptr3;
|
||||
register JDIMENSION col;
|
||||
register int ci;
|
||||
int nc = cinfo->num_components;
|
||||
@ -524,10 +548,13 @@ null_method(j_compress_ptr cinfo)
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_color_converter(j_compress_ptr cinfo)
|
||||
_jinit_color_converter(j_compress_ptr cinfo)
|
||||
{
|
||||
my_cconvert_ptr cconvert;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
cconvert = (my_cconvert_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_color_converter));
|
||||
@ -574,123 +601,116 @@ jinit_color_converter(j_compress_ptr cinfo)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check num_components, set conversion method based on requested space */
|
||||
/* Check num_components, set conversion method based on requested space.
|
||||
* NOTE: We do not allow any lossy color conversion algorithms in lossless
|
||||
* mode.
|
||||
*/
|
||||
switch (cinfo->jpeg_color_space) {
|
||||
case JCS_GRAYSCALE:
|
||||
if (cinfo->master->lossless &&
|
||||
cinfo->in_color_space != cinfo->jpeg_color_space)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
if (cinfo->num_components != 1)
|
||||
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||
if (cinfo->in_color_space == JCS_GRAYSCALE)
|
||||
cconvert->pub.color_convert = grayscale_convert;
|
||||
else if (cinfo->in_color_space == JCS_RGB ||
|
||||
cinfo->in_color_space == JCS_EXT_RGB ||
|
||||
cinfo->in_color_space == JCS_EXT_RGBX ||
|
||||
cinfo->in_color_space == JCS_EXT_BGR ||
|
||||
cinfo->in_color_space == JCS_EXT_BGRX ||
|
||||
cinfo->in_color_space == JCS_EXT_XBGR ||
|
||||
cinfo->in_color_space == JCS_EXT_XRGB ||
|
||||
cinfo->in_color_space == JCS_EXT_RGBA ||
|
||||
cinfo->in_color_space == JCS_EXT_BGRA ||
|
||||
cinfo->in_color_space == JCS_EXT_ABGR ||
|
||||
cinfo->in_color_space == JCS_EXT_ARGB) {
|
||||
cconvert->pub._color_convert = grayscale_convert;
|
||||
else if (IsExtRGB(cinfo->in_color_space)) {
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_rgb_gray())
|
||||
cconvert->pub.color_convert = jsimd_rgb_gray_convert;
|
||||
else {
|
||||
cconvert->pub._color_convert = jsimd_rgb_gray_convert;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
cconvert->pub.start_pass = rgb_ycc_start;
|
||||
cconvert->pub.color_convert = rgb_gray_convert;
|
||||
cconvert->pub._color_convert = rgb_gray_convert;
|
||||
}
|
||||
} else if (cinfo->in_color_space == JCS_YCbCr)
|
||||
cconvert->pub.color_convert = grayscale_convert;
|
||||
cconvert->pub._color_convert = grayscale_convert;
|
||||
else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
break;
|
||||
|
||||
case JCS_RGB:
|
||||
if (cinfo->master->lossless && !IsExtRGB(cinfo->in_color_space))
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
if (cinfo->num_components != 3)
|
||||
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||
if (rgb_red[cinfo->in_color_space] == 0 &&
|
||||
rgb_green[cinfo->in_color_space] == 1 &&
|
||||
rgb_blue[cinfo->in_color_space] == 2 &&
|
||||
rgb_pixelsize[cinfo->in_color_space] == 3) {
|
||||
#if defined(__mips__)
|
||||
#if defined(WITH_SIMD) && defined(__mips__)
|
||||
if (jsimd_c_can_null_convert())
|
||||
cconvert->pub.color_convert = jsimd_c_null_convert;
|
||||
cconvert->pub._color_convert = jsimd_c_null_convert;
|
||||
else
|
||||
#endif
|
||||
cconvert->pub.color_convert = null_convert;
|
||||
} else if (cinfo->in_color_space == JCS_RGB ||
|
||||
cinfo->in_color_space == JCS_EXT_RGB ||
|
||||
cinfo->in_color_space == JCS_EXT_RGBX ||
|
||||
cinfo->in_color_space == JCS_EXT_BGR ||
|
||||
cinfo->in_color_space == JCS_EXT_BGRX ||
|
||||
cinfo->in_color_space == JCS_EXT_XBGR ||
|
||||
cinfo->in_color_space == JCS_EXT_XRGB ||
|
||||
cinfo->in_color_space == JCS_EXT_RGBA ||
|
||||
cinfo->in_color_space == JCS_EXT_BGRA ||
|
||||
cinfo->in_color_space == JCS_EXT_ABGR ||
|
||||
cinfo->in_color_space == JCS_EXT_ARGB)
|
||||
cconvert->pub.color_convert = rgb_rgb_convert;
|
||||
cconvert->pub._color_convert = null_convert;
|
||||
} else if (IsExtRGB(cinfo->in_color_space))
|
||||
cconvert->pub._color_convert = rgb_rgb_convert;
|
||||
else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
break;
|
||||
|
||||
case JCS_YCbCr:
|
||||
if (cinfo->master->lossless &&
|
||||
cinfo->in_color_space != cinfo->jpeg_color_space)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
if (cinfo->num_components != 3)
|
||||
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||
if (cinfo->in_color_space == JCS_RGB ||
|
||||
cinfo->in_color_space == JCS_EXT_RGB ||
|
||||
cinfo->in_color_space == JCS_EXT_RGBX ||
|
||||
cinfo->in_color_space == JCS_EXT_BGR ||
|
||||
cinfo->in_color_space == JCS_EXT_BGRX ||
|
||||
cinfo->in_color_space == JCS_EXT_XBGR ||
|
||||
cinfo->in_color_space == JCS_EXT_XRGB ||
|
||||
cinfo->in_color_space == JCS_EXT_RGBA ||
|
||||
cinfo->in_color_space == JCS_EXT_BGRA ||
|
||||
cinfo->in_color_space == JCS_EXT_ABGR ||
|
||||
cinfo->in_color_space == JCS_EXT_ARGB) {
|
||||
if (IsExtRGB(cinfo->in_color_space)) {
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_rgb_ycc())
|
||||
cconvert->pub.color_convert = jsimd_rgb_ycc_convert;
|
||||
else {
|
||||
cconvert->pub.start_pass = rgb_ycc_start;
|
||||
cconvert->pub.color_convert = rgb_ycc_convert;
|
||||
}
|
||||
} else if (cinfo->in_color_space == JCS_YCbCr) {
|
||||
#if defined(__mips__)
|
||||
if (jsimd_c_can_null_convert())
|
||||
cconvert->pub.color_convert = jsimd_c_null_convert;
|
||||
cconvert->pub._color_convert = jsimd_rgb_ycc_convert;
|
||||
else
|
||||
#endif
|
||||
cconvert->pub.color_convert = null_convert;
|
||||
{
|
||||
cconvert->pub.start_pass = rgb_ycc_start;
|
||||
cconvert->pub._color_convert = rgb_ycc_convert;
|
||||
}
|
||||
} else if (cinfo->in_color_space == JCS_YCbCr) {
|
||||
#if defined(WITH_SIMD) && defined(__mips__)
|
||||
if (jsimd_c_can_null_convert())
|
||||
cconvert->pub._color_convert = jsimd_c_null_convert;
|
||||
else
|
||||
#endif
|
||||
cconvert->pub._color_convert = null_convert;
|
||||
} else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
break;
|
||||
|
||||
case JCS_CMYK:
|
||||
if (cinfo->master->lossless &&
|
||||
cinfo->in_color_space != cinfo->jpeg_color_space)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
if (cinfo->num_components != 4)
|
||||
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||
if (cinfo->in_color_space == JCS_CMYK) {
|
||||
#if defined(__mips__)
|
||||
#if defined(WITH_SIMD) && defined(__mips__)
|
||||
if (jsimd_c_can_null_convert())
|
||||
cconvert->pub.color_convert = jsimd_c_null_convert;
|
||||
cconvert->pub._color_convert = jsimd_c_null_convert;
|
||||
else
|
||||
#endif
|
||||
cconvert->pub.color_convert = null_convert;
|
||||
cconvert->pub._color_convert = null_convert;
|
||||
} else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
break;
|
||||
|
||||
case JCS_YCCK:
|
||||
if (cinfo->master->lossless &&
|
||||
cinfo->in_color_space != cinfo->jpeg_color_space)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
if (cinfo->num_components != 4)
|
||||
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||
if (cinfo->in_color_space == JCS_CMYK) {
|
||||
cconvert->pub.start_pass = rgb_ycc_start;
|
||||
cconvert->pub.color_convert = cmyk_ycck_convert;
|
||||
cconvert->pub._color_convert = cmyk_ycck_convert;
|
||||
} else if (cinfo->in_color_space == JCS_YCCK) {
|
||||
#if defined(__mips__)
|
||||
#if defined(WITH_SIMD) && defined(__mips__)
|
||||
if (jsimd_c_can_null_convert())
|
||||
cconvert->pub.color_convert = jsimd_c_null_convert;
|
||||
cconvert->pub._color_convert = jsimd_c_null_convert;
|
||||
else
|
||||
#endif
|
||||
cconvert->pub.color_convert = null_convert;
|
||||
cconvert->pub._color_convert = null_convert;
|
||||
} else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
break;
|
||||
@ -699,12 +719,14 @@ jinit_color_converter(j_compress_ptr cinfo)
|
||||
if (cinfo->jpeg_color_space != cinfo->in_color_space ||
|
||||
cinfo->num_components != cinfo->input_components)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
#if defined(__mips__)
|
||||
#if defined(WITH_SIMD) && defined(__mips__)
|
||||
if (jsimd_c_can_null_convert())
|
||||
cconvert->pub.color_convert = jsimd_c_null_convert;
|
||||
cconvert->pub._color_convert = jsimd_c_null_convert;
|
||||
else
|
||||
#endif
|
||||
cconvert->pub.color_convert = null_convert;
|
||||
cconvert->pub._color_convert = null_convert;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */
|
||||
|
94
3rdparty/libjpeg-turbo/src/jcdctmgr.c
vendored
94
3rdparty/libjpeg-turbo/src/jcdctmgr.c
vendored
@ -6,7 +6,7 @@
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 1999-2006, MIYASAKA Masaru.
|
||||
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
||||
* Copyright (C) 2011, 2014-2015, D. R. Commander.
|
||||
* Copyright (C) 2011, 2014-2015, 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -28,10 +28,10 @@
|
||||
typedef void (*forward_DCT_method_ptr) (DCTELEM *data);
|
||||
typedef void (*float_DCT_method_ptr) (FAST_FLOAT *data);
|
||||
|
||||
typedef void (*convsamp_method_ptr) (JSAMPARRAY sample_data,
|
||||
typedef void (*convsamp_method_ptr) (_JSAMPARRAY sample_data,
|
||||
JDIMENSION start_col,
|
||||
DCTELEM *workspace);
|
||||
typedef void (*float_convsamp_method_ptr) (JSAMPARRAY sample_data,
|
||||
typedef void (*float_convsamp_method_ptr) (_JSAMPARRAY sample_data,
|
||||
JDIMENSION start_col,
|
||||
FAST_FLOAT *workspace);
|
||||
|
||||
@ -265,9 +265,13 @@ start_pass_fdctmgr(j_compress_ptr cinfo)
|
||||
dtbl = fdct->divisors[qtblno];
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
#ifdef WITH_SIMD
|
||||
if (!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]) &&
|
||||
fdct->quantize == jsimd_quantize)
|
||||
fdct->quantize = quantize;
|
||||
#else
|
||||
compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]);
|
||||
#endif
|
||||
#else
|
||||
dtbl[i] = ((DCTELEM)qtbl->quantval[i]) << 3;
|
||||
#endif
|
||||
@ -305,12 +309,19 @@ start_pass_fdctmgr(j_compress_ptr cinfo)
|
||||
dtbl = fdct->divisors[qtblno];
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
#ifdef WITH_SIMD
|
||||
if (!compute_reciprocal(
|
||||
DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
|
||||
(JLONG)aanscales[i]),
|
||||
CONST_BITS - 3), &dtbl[i]) &&
|
||||
fdct->quantize == jsimd_quantize)
|
||||
fdct->quantize = quantize;
|
||||
#else
|
||||
compute_reciprocal(
|
||||
DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
|
||||
(JLONG)aanscales[i]),
|
||||
CONST_BITS-3), &dtbl[i]);
|
||||
#endif
|
||||
#else
|
||||
dtbl[i] = (DCTELEM)
|
||||
DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
|
||||
@ -370,10 +381,10 @@ start_pass_fdctmgr(j_compress_ptr cinfo)
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
convsamp(JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM *workspace)
|
||||
convsamp(_JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM *workspace)
|
||||
{
|
||||
register DCTELEM *workspaceptr;
|
||||
register JSAMPROW elemptr;
|
||||
register _JSAMPROW elemptr;
|
||||
register int elemr;
|
||||
|
||||
workspaceptr = workspace;
|
||||
@ -381,19 +392,19 @@ convsamp(JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM *workspace)
|
||||
elemptr = sample_data[elemr] + start_col;
|
||||
|
||||
#if DCTSIZE == 8 /* unroll the inner loop */
|
||||
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
|
||||
#else
|
||||
{
|
||||
register int elemc;
|
||||
for (elemc = DCTSIZE; elemc > 0; elemc--)
|
||||
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -488,7 +499,7 @@ quantize(JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
|
||||
|
||||
METHODDEF(void)
|
||||
forward_DCT(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||
_JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||
JDIMENSION start_row, JDIMENSION start_col, JDIMENSION num_blocks)
|
||||
/* This version is used for integer DCT implementations. */
|
||||
{
|
||||
@ -522,30 +533,30 @@ forward_DCT(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
#ifdef DCT_FLOAT_SUPPORTED
|
||||
|
||||
METHODDEF(void)
|
||||
convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
|
||||
convsamp_float(_JSAMPARRAY sample_data, JDIMENSION start_col,
|
||||
FAST_FLOAT *workspace)
|
||||
{
|
||||
register FAST_FLOAT *workspaceptr;
|
||||
register JSAMPROW elemptr;
|
||||
register _JSAMPROW elemptr;
|
||||
register int elemr;
|
||||
|
||||
workspaceptr = workspace;
|
||||
for (elemr = 0; elemr < DCTSIZE; elemr++) {
|
||||
elemptr = sample_data[elemr] + start_col;
|
||||
#if DCTSIZE == 8 /* unroll the inner loop */
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
|
||||
#else
|
||||
{
|
||||
register int elemc;
|
||||
for (elemc = DCTSIZE; elemc > 0; elemc--)
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -577,7 +588,7 @@ quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
|
||||
|
||||
METHODDEF(void)
|
||||
forward_DCT_float(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||
_JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||
JDIMENSION start_row, JDIMENSION start_col,
|
||||
JDIMENSION num_blocks)
|
||||
/* This version is used for floating-point DCT implementations. */
|
||||
@ -617,11 +628,14 @@ forward_DCT_float(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_forward_dct(j_compress_ptr cinfo)
|
||||
_jinit_forward_dct(j_compress_ptr cinfo)
|
||||
{
|
||||
my_fdct_ptr fdct;
|
||||
int i;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
fdct = (my_fdct_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_fdct_controller));
|
||||
@ -632,28 +646,34 @@ jinit_forward_dct(j_compress_ptr cinfo)
|
||||
switch (cinfo->dct_method) {
|
||||
#ifdef DCT_ISLOW_SUPPORTED
|
||||
case JDCT_ISLOW:
|
||||
fdct->pub.forward_DCT = forward_DCT;
|
||||
fdct->pub._forward_DCT = forward_DCT;
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_fdct_islow())
|
||||
fdct->dct = jsimd_fdct_islow;
|
||||
else
|
||||
fdct->dct = jpeg_fdct_islow;
|
||||
#endif
|
||||
fdct->dct = _jpeg_fdct_islow;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DCT_IFAST_SUPPORTED
|
||||
case JDCT_IFAST:
|
||||
fdct->pub.forward_DCT = forward_DCT;
|
||||
fdct->pub._forward_DCT = forward_DCT;
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_fdct_ifast())
|
||||
fdct->dct = jsimd_fdct_ifast;
|
||||
else
|
||||
fdct->dct = jpeg_fdct_ifast;
|
||||
#endif
|
||||
fdct->dct = _jpeg_fdct_ifast;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DCT_FLOAT_SUPPORTED
|
||||
case JDCT_FLOAT:
|
||||
fdct->pub.forward_DCT = forward_DCT_float;
|
||||
fdct->pub._forward_DCT = forward_DCT_float;
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_fdct_float())
|
||||
fdct->float_dct = jsimd_fdct_float;
|
||||
else
|
||||
#endif
|
||||
fdct->float_dct = jpeg_fdct_float;
|
||||
break;
|
||||
#endif
|
||||
@ -671,25 +691,33 @@ jinit_forward_dct(j_compress_ptr cinfo)
|
||||
case JDCT_IFAST:
|
||||
#endif
|
||||
#if defined(DCT_ISLOW_SUPPORTED) || defined(DCT_IFAST_SUPPORTED)
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_convsamp())
|
||||
fdct->convsamp = jsimd_convsamp;
|
||||
else
|
||||
#endif
|
||||
fdct->convsamp = convsamp;
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_quantize())
|
||||
fdct->quantize = jsimd_quantize;
|
||||
else
|
||||
#endif
|
||||
fdct->quantize = quantize;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DCT_FLOAT_SUPPORTED
|
||||
case JDCT_FLOAT:
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_convsamp_float())
|
||||
fdct->float_convsamp = jsimd_convsamp_float;
|
||||
else
|
||||
#endif
|
||||
fdct->float_convsamp = convsamp_float;
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_quantize_float())
|
||||
fdct->float_quantize = jsimd_quantize_float;
|
||||
else
|
||||
#endif
|
||||
fdct->float_quantize = quantize_float;
|
||||
break;
|
||||
#endif
|
||||
|
411
3rdparty/libjpeg-turbo/src/jcdiffct.c
vendored
Normal file
411
3rdparty/libjpeg-turbo/src/jcdiffct.c
vendored
Normal file
@ -0,0 +1,411 @@
|
||||
/*
|
||||
* jcdiffct.c
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file contains the difference buffer controller for compression.
|
||||
* This controller is the top level of the lossless JPEG compressor proper.
|
||||
* The difference buffer lies between the prediction/differencing and entropy
|
||||
* encoding steps.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jlossls.h" /* Private declarations for lossless codec */
|
||||
|
||||
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
|
||||
/* We use a full-image sample buffer when doing Huffman optimization,
|
||||
* and also for writing multiple-scan JPEG files. In all cases, the
|
||||
* full-image buffer is filled during the first pass, and the scaling,
|
||||
* prediction and differencing steps are run during subsequent passes.
|
||||
*/
|
||||
#ifdef ENTROPY_OPT_SUPPORTED
|
||||
#define FULL_SAMP_BUFFER_SUPPORTED
|
||||
#else
|
||||
#ifdef C_MULTISCAN_FILES_SUPPORTED
|
||||
#define FULL_SAMP_BUFFER_SUPPORTED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Private buffer controller object */
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_c_coef_controller pub; /* public fields */
|
||||
|
||||
JDIMENSION iMCU_row_num; /* iMCU row # within image */
|
||||
JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
|
||||
int MCU_vert_offset; /* counts MCU rows within iMCU row */
|
||||
int MCU_rows_per_iMCU_row; /* number of such rows needed */
|
||||
|
||||
_JSAMPROW cur_row[MAX_COMPONENTS]; /* row of point-transformed samples */
|
||||
_JSAMPROW prev_row[MAX_COMPONENTS]; /* previous row of Pt'd samples */
|
||||
JDIFFARRAY diff_buf[MAX_COMPONENTS]; /* iMCU row of differences */
|
||||
|
||||
/* In multi-pass modes, we need a virtual sample array for each component. */
|
||||
jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
|
||||
} my_diff_controller;
|
||||
|
||||
typedef my_diff_controller *my_diff_ptr;
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF(boolean) compress_data(j_compress_ptr cinfo, _JSAMPIMAGE input_buf);
|
||||
#ifdef FULL_SAMP_BUFFER_SUPPORTED
|
||||
METHODDEF(boolean) compress_first_pass(j_compress_ptr cinfo,
|
||||
_JSAMPIMAGE input_buf);
|
||||
METHODDEF(boolean) compress_output(j_compress_ptr cinfo,
|
||||
_JSAMPIMAGE input_buf);
|
||||
#endif
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
start_iMCU_row(j_compress_ptr cinfo)
|
||||
/* Reset within-iMCU-row counters for a new row */
|
||||
{
|
||||
my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
|
||||
|
||||
/* In an interleaved scan, an MCU row is the same as an iMCU row.
|
||||
* In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
|
||||
* But at the bottom of the image, process only what's left.
|
||||
*/
|
||||
if (cinfo->comps_in_scan > 1) {
|
||||
diff->MCU_rows_per_iMCU_row = 1;
|
||||
} else {
|
||||
if (diff->iMCU_row_num < (cinfo->total_iMCU_rows-1))
|
||||
diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
|
||||
else
|
||||
diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
|
||||
}
|
||||
|
||||
diff->mcu_ctr = 0;
|
||||
diff->MCU_vert_offset = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize for a processing pass.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
start_pass_diff(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
{
|
||||
my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
|
||||
|
||||
/* Because it is hitching a ride on the jpeg_forward_dct struct,
|
||||
* start_pass_lossless() will be called at the start of the initial pass.
|
||||
* This ensures that it will be called at the start of the Huffman
|
||||
* optimization and output passes as well.
|
||||
*/
|
||||
if (pass_mode == JBUF_CRANK_DEST)
|
||||
(*cinfo->fdct->start_pass) (cinfo);
|
||||
|
||||
diff->iMCU_row_num = 0;
|
||||
start_iMCU_row(cinfo);
|
||||
|
||||
switch (pass_mode) {
|
||||
case JBUF_PASS_THRU:
|
||||
if (diff->whole_image[0] != NULL)
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
diff->pub._compress_data = compress_data;
|
||||
break;
|
||||
#ifdef FULL_SAMP_BUFFER_SUPPORTED
|
||||
case JBUF_SAVE_AND_PASS:
|
||||
if (diff->whole_image[0] == NULL)
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
diff->pub._compress_data = compress_first_pass;
|
||||
break;
|
||||
case JBUF_CRANK_DEST:
|
||||
if (diff->whole_image[0] == NULL)
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
diff->pub._compress_data = compress_output;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define SWAP_ROWS(rowa, rowb) { \
|
||||
_JSAMPROW temp = rowa; \
|
||||
rowa = rowb; rowb = temp; \
|
||||
}
|
||||
|
||||
/*
|
||||
* Process some data in the single-pass case.
|
||||
* We process the equivalent of one fully interleaved MCU row ("iMCU" row)
|
||||
* per call, ie, v_samp_factor rows for each component in the image.
|
||||
* Returns TRUE if the iMCU row is completed, FALSE if suspended.
|
||||
*
|
||||
* NB: input_buf contains a plane for each component in image,
|
||||
* which we index according to the component's SOF position.
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
compress_data(j_compress_ptr cinfo, _JSAMPIMAGE input_buf)
|
||||
{
|
||||
my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
|
||||
lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
|
||||
JDIMENSION MCU_col_num; /* index of current MCU within row */
|
||||
JDIMENSION MCU_count; /* number of MCUs encoded */
|
||||
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
|
||||
int ci, compi, yoffset, samp_row, samp_rows, samps_across;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
/* Loop to write as much as one whole iMCU row */
|
||||
for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
|
||||
yoffset++) {
|
||||
|
||||
MCU_col_num = diff->mcu_ctr;
|
||||
|
||||
/* Scale and predict each scanline of the MCU row separately.
|
||||
*
|
||||
* Note: We only do this if we are at the start of an MCU row, ie,
|
||||
* we don't want to reprocess a row suspended by the output.
|
||||
*/
|
||||
if (MCU_col_num == 0) {
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
compi = compptr->component_index;
|
||||
if (diff->iMCU_row_num < last_iMCU_row)
|
||||
samp_rows = compptr->v_samp_factor;
|
||||
else {
|
||||
/* NB: can't use last_row_height here, since may not be set! */
|
||||
samp_rows =
|
||||
(int)(compptr->height_in_blocks % compptr->v_samp_factor);
|
||||
if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
|
||||
else {
|
||||
/* Fill dummy difference rows at the bottom edge with zeros, which
|
||||
* will encode to the smallest amount of data.
|
||||
*/
|
||||
for (samp_row = samp_rows; samp_row < compptr->v_samp_factor;
|
||||
samp_row++)
|
||||
memset(diff->diff_buf[compi][samp_row], 0,
|
||||
jround_up((long)compptr->width_in_blocks,
|
||||
(long)compptr->h_samp_factor) * sizeof(JDIFF));
|
||||
}
|
||||
}
|
||||
samps_across = compptr->width_in_blocks;
|
||||
|
||||
for (samp_row = 0; samp_row < samp_rows; samp_row++) {
|
||||
(*losslessc->scaler_scale) (cinfo,
|
||||
input_buf[compi][samp_row],
|
||||
diff->cur_row[compi],
|
||||
samps_across);
|
||||
(*losslessc->predict_difference[compi])
|
||||
(cinfo, compi, diff->cur_row[compi], diff->prev_row[compi],
|
||||
diff->diff_buf[compi][samp_row], samps_across);
|
||||
SWAP_ROWS(diff->cur_row[compi], diff->prev_row[compi]);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Try to write the MCU row (or remaining portion of suspended MCU row). */
|
||||
MCU_count =
|
||||
(*cinfo->entropy->encode_mcus) (cinfo,
|
||||
diff->diff_buf, yoffset, MCU_col_num,
|
||||
cinfo->MCUs_per_row - MCU_col_num);
|
||||
if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
|
||||
/* Suspension forced; update state counters and exit */
|
||||
diff->MCU_vert_offset = yoffset;
|
||||
diff->mcu_ctr += MCU_col_num;
|
||||
return FALSE;
|
||||
}
|
||||
/* Completed an MCU row, but perhaps not an iMCU row */
|
||||
diff->mcu_ctr = 0;
|
||||
}
|
||||
/* Completed the iMCU row, advance counters for next one */
|
||||
diff->iMCU_row_num++;
|
||||
start_iMCU_row(cinfo);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
#ifdef FULL_SAMP_BUFFER_SUPPORTED
|
||||
|
||||
/*
|
||||
* Process some data in the first pass of a multi-pass case.
|
||||
* We process the equivalent of one fully interleaved MCU row ("iMCU" row)
|
||||
* per call, ie, v_samp_factor rows for each component in the image.
|
||||
* This amount of data is read from the source buffer and saved into the
|
||||
* virtual arrays.
|
||||
*
|
||||
* We must also emit the data to the compressor. This is conveniently
|
||||
* done by calling compress_output() after we've loaded the current strip
|
||||
* of the virtual arrays.
|
||||
*
|
||||
* NB: input_buf contains a plane for each component in image. All components
|
||||
* are loaded into the virtual arrays in this pass. However, it may be that
|
||||
* only a subset of the components are emitted to the compressor during
|
||||
* this first pass; be careful about looking at the scan-dependent variables
|
||||
* (MCU dimensions, etc).
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
compress_first_pass(j_compress_ptr cinfo, _JSAMPIMAGE input_buf)
|
||||
{
|
||||
my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
|
||||
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
|
||||
JDIMENSION samps_across;
|
||||
int ci, samp_row, samp_rows;
|
||||
_JSAMPARRAY buffer;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
/* Align the virtual buffer for this component. */
|
||||
buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr)cinfo, diff->whole_image[ci],
|
||||
diff->iMCU_row_num * compptr->v_samp_factor,
|
||||
(JDIMENSION)compptr->v_samp_factor, TRUE);
|
||||
|
||||
/* Count non-dummy sample rows in this iMCU row. */
|
||||
if (diff->iMCU_row_num < last_iMCU_row)
|
||||
samp_rows = compptr->v_samp_factor;
|
||||
else {
|
||||
/* NB: can't use last_row_height here, since may not be set! */
|
||||
samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
|
||||
if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
|
||||
}
|
||||
samps_across = compptr->width_in_blocks;
|
||||
|
||||
/* Perform point transform scaling and prediction/differencing for all
|
||||
* non-dummy rows in this iMCU row. Each call on these functions
|
||||
* processes a complete row of samples.
|
||||
*/
|
||||
for (samp_row = 0; samp_row < samp_rows; samp_row++) {
|
||||
memcpy(buffer[samp_row], input_buf[ci][samp_row],
|
||||
samps_across * sizeof(_JSAMPLE));
|
||||
}
|
||||
}
|
||||
/* NB: compress_output will increment iMCU_row_num if successful.
|
||||
* A suspension return will result in redoing all the work above next time.
|
||||
*/
|
||||
|
||||
/* Emit data to the compressor, sharing code with subsequent passes */
|
||||
return compress_output(cinfo, input_buf);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Process some data in subsequent passes of a multi-pass case.
|
||||
* We process the equivalent of one fully interleaved MCU row ("iMCU" row)
|
||||
* per call, ie, v_samp_factor rows for each component in the scan.
|
||||
* The data is obtained from the virtual arrays and fed to the compressor.
|
||||
* Returns TRUE if the iMCU row is completed, FALSE if suspended.
|
||||
*
|
||||
* NB: input_buf is ignored; it is likely to be a NULL pointer.
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
compress_output(j_compress_ptr cinfo, _JSAMPIMAGE input_buf)
|
||||
{
|
||||
my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
|
||||
int ci, compi;
|
||||
_JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
/* Align the virtual buffers for the components used in this scan.
|
||||
* NB: during first pass, this is safe only because the buffers will
|
||||
* already be aligned properly, so jmemmgr.c won't need to do any I/O.
|
||||
*/
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
compi = compptr->component_index;
|
||||
buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr)cinfo, diff->whole_image[compi],
|
||||
diff->iMCU_row_num * compptr->v_samp_factor,
|
||||
(JDIMENSION)compptr->v_samp_factor, FALSE);
|
||||
}
|
||||
|
||||
return compress_data(cinfo, buffer);
|
||||
}
|
||||
|
||||
#endif /* FULL_SAMP_BUFFER_SUPPORTED */
|
||||
|
||||
|
||||
/*
|
||||
* Initialize difference buffer controller.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
_jinit_c_diff_controller(j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_diff_ptr diff;
|
||||
int ci, row;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
diff = (my_diff_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_diff_controller));
|
||||
cinfo->coef = (struct jpeg_c_coef_controller *)diff;
|
||||
diff->pub.start_pass = start_pass_diff;
|
||||
|
||||
/* Create the prediction row buffers. */
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
diff->cur_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION)jround_up((long)compptr->width_in_blocks,
|
||||
(long)compptr->h_samp_factor),
|
||||
(JDIMENSION)1);
|
||||
diff->prev_row[ci] = *(_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION)jround_up((long)compptr->width_in_blocks,
|
||||
(long)compptr->h_samp_factor),
|
||||
(JDIMENSION)1);
|
||||
}
|
||||
|
||||
/* Create the difference buffer. */
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
diff->diff_buf[ci] =
|
||||
ALLOC_DARRAY(JPOOL_IMAGE,
|
||||
(JDIMENSION)jround_up((long)compptr->width_in_blocks,
|
||||
(long)compptr->h_samp_factor),
|
||||
(JDIMENSION)compptr->v_samp_factor);
|
||||
/* Prefill difference rows with zeros. We do this because only actual
|
||||
* data is placed in the buffers during prediction/differencing, leaving
|
||||
* any dummy differences at the right edge as zeros, which will encode
|
||||
* to the smallest amount of data.
|
||||
*/
|
||||
for (row = 0; row < compptr->v_samp_factor; row++)
|
||||
memset(diff->diff_buf[ci][row], 0,
|
||||
jround_up((long)compptr->width_in_blocks,
|
||||
(long)compptr->h_samp_factor) * sizeof(JDIFF));
|
||||
}
|
||||
|
||||
/* Create the sample buffer. */
|
||||
if (need_full_buffer) {
|
||||
#ifdef FULL_SAMP_BUFFER_SUPPORTED
|
||||
/* Allocate a full-image virtual array for each component, */
|
||||
/* padded to a multiple of samp_factor differences in each direction. */
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
|
||||
(JDIMENSION)jround_up((long)compptr->width_in_blocks,
|
||||
(long)compptr->h_samp_factor),
|
||||
(JDIMENSION)jround_up((long)compptr->height_in_blocks,
|
||||
(long)compptr->v_samp_factor),
|
||||
(JDIMENSION)compptr->v_samp_factor);
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
#endif
|
||||
} else
|
||||
diff->whole_image[0] = NULL; /* flag for no virtual arrays */
|
||||
}
|
||||
|
||||
#endif /* C_LOSSLESS_SUPPORTED */
|
202
3rdparty/libjpeg-turbo/src/jchuff.c
vendored
202
3rdparty/libjpeg-turbo/src/jchuff.c
vendored
@ -3,11 +3,14 @@
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2009-2011, 2014-2016, 2018-2022, D. R. Commander.
|
||||
* Copyright (C) 2009-2011, 2014-2016, 2018-2024, D. R. Commander.
|
||||
* Copyright (C) 2015, Matthieu Darbois.
|
||||
* Copyright (C) 2018, Matthias Räncker.
|
||||
* Copyright (C) 2020, Arm Limited.
|
||||
* Copyright (C) 2022, Felix Hanau.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -26,44 +29,13 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#ifdef WITH_SIMD
|
||||
#include "jsimd.h"
|
||||
#include "jconfigint.h"
|
||||
#else
|
||||
#include "jchuff.h" /* Declarations shared with jc*huff.c */
|
||||
#endif
|
||||
#include <limits.h>
|
||||
|
||||
/*
|
||||
* NOTE: If USE_CLZ_INTRINSIC is defined, then clz/bsr instructions will be
|
||||
* used for bit counting rather than the lookup table. This will reduce the
|
||||
* memory footprint by 64k, which is important for some mobile applications
|
||||
* that create many isolated instances of libjpeg-turbo (web browsers, for
|
||||
* instance.) This may improve performance on some mobile platforms as well.
|
||||
* This feature is enabled by default only on Arm processors, because some x86
|
||||
* chips have a slow implementation of bsr, and the use of clz/bsr cannot be
|
||||
* shown to have a significant performance impact even on the x86 chips that
|
||||
* have a fast implementation of it. When building for Armv6, you can
|
||||
* explicitly disable the use of clz/bsr by adding -mthumb to the compiler
|
||||
* flags (this defines __thumb__).
|
||||
*/
|
||||
|
||||
/* NOTE: Both GCC and Clang define __GNUC__ */
|
||||
#if (defined(__GNUC__) && (defined(__arm__) || defined(__aarch64__))) || \
|
||||
defined(_M_ARM) || defined(_M_ARM64)
|
||||
#if !defined(__thumb__) || defined(__thumb2__)
|
||||
#define USE_CLZ_INTRINSIC
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_CLZ_INTRINSIC
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#define JPEG_NBITS_NONZERO(x) (32 - _CountLeadingZeros(x))
|
||||
#else
|
||||
#define JPEG_NBITS_NONZERO(x) (32 - __builtin_clz(x))
|
||||
#endif
|
||||
#define JPEG_NBITS(x) (x ? JPEG_NBITS_NONZERO(x) : 0)
|
||||
#else
|
||||
#include "jpeg_nbits_table.h"
|
||||
#define JPEG_NBITS(x) (jpeg_nbits_table[x])
|
||||
#define JPEG_NBITS_NONZERO(x) JPEG_NBITS(x)
|
||||
#endif
|
||||
#include "jpeg_nbits.h"
|
||||
|
||||
|
||||
/* Expanded entropy encoder object for Huffman encoding.
|
||||
@ -102,7 +74,9 @@ typedef bit_buf_type simd_bit_buf_type;
|
||||
typedef struct {
|
||||
union {
|
||||
bit_buf_type c;
|
||||
#ifdef WITH_SIMD
|
||||
simd_bit_buf_type simd;
|
||||
#endif
|
||||
} put_buffer; /* current bit accumulation buffer */
|
||||
int free_bits; /* # of bits available in it */
|
||||
/* (Neon GAS: # of bits now in it) */
|
||||
@ -127,7 +101,9 @@ typedef struct {
|
||||
long *ac_count_ptrs[NUM_HUFF_TBLS];
|
||||
#endif
|
||||
|
||||
#ifdef WITH_SIMD
|
||||
int simd;
|
||||
#endif
|
||||
} huff_entropy_encoder;
|
||||
|
||||
typedef huff_entropy_encoder *huff_entropy_ptr;
|
||||
@ -141,7 +117,9 @@ typedef struct {
|
||||
size_t free_in_buffer; /* # of byte spaces remaining in buffer */
|
||||
savable_state cur; /* Current bit buffer & DC state */
|
||||
j_compress_ptr cinfo; /* dump_buffer needs access to this */
|
||||
#ifdef WITH_SIMD
|
||||
int simd;
|
||||
#endif
|
||||
} working_state;
|
||||
|
||||
|
||||
@ -180,7 +158,9 @@ start_pass_huff(j_compress_ptr cinfo, boolean gather_statistics)
|
||||
entropy->pub.finish_pass = finish_pass_huff;
|
||||
}
|
||||
|
||||
#ifdef WITH_SIMD
|
||||
entropy->simd = jsimd_can_huff_encode_one_block();
|
||||
#endif
|
||||
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
@ -220,6 +200,7 @@ start_pass_huff(j_compress_ptr cinfo, boolean gather_statistics)
|
||||
}
|
||||
|
||||
/* Initialize bit buffer to empty */
|
||||
#ifdef WITH_SIMD
|
||||
if (entropy->simd) {
|
||||
entropy->saved.put_buffer.simd = 0;
|
||||
#if defined(__aarch64__) && !defined(NEON_INTRINSICS)
|
||||
@ -227,7 +208,9 @@ start_pass_huff(j_compress_ptr cinfo, boolean gather_statistics)
|
||||
#else
|
||||
entropy->saved.free_bits = SIMD_BIT_BUF_SIZE;
|
||||
#endif
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
entropy->saved.put_buffer.c = 0;
|
||||
entropy->saved.free_bits = BIT_BUF_SIZE;
|
||||
}
|
||||
@ -242,7 +225,7 @@ start_pass_huff(j_compress_ptr cinfo, boolean gather_statistics)
|
||||
* Compute the derived values for a Huffman table.
|
||||
* This routine also performs some validation checks on the table.
|
||||
*
|
||||
* Note this is also used by jcphuff.c.
|
||||
* Note this is also used by jcphuff.c and jclhuff.c.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
@ -318,12 +301,12 @@ jpeg_make_c_derived_tbl(j_compress_ptr cinfo, boolean isDC, int tblno,
|
||||
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
|
||||
* but only 0..15 for DC. (We could constrain them further
|
||||
* based on data depth and mode, but this seems enough.)
|
||||
/* This is also a convenient place to check for out-of-range and duplicated
|
||||
* VAL entries. We allow 0..255 for AC symbols but only 0..15 for DC in
|
||||
* lossy mode and 0..16 for DC in lossless mode. (We could constrain them
|
||||
* further based on data depth and mode, but this seems enough.)
|
||||
*/
|
||||
maxsymbol = isDC ? 15 : 255;
|
||||
maxsymbol = isDC ? (cinfo->master->lossless ? 16 : 15) : 255;
|
||||
|
||||
for (p = 0; p < lastp; p++) {
|
||||
i = htbl->huffval[p];
|
||||
@ -500,6 +483,7 @@ flush_bits(working_state *state)
|
||||
simd_bit_buf_type put_buffer; int put_bits;
|
||||
int localbuf = 0;
|
||||
|
||||
#ifdef WITH_SIMD
|
||||
if (state->simd) {
|
||||
#if defined(__aarch64__) && !defined(NEON_INTRINSICS)
|
||||
put_bits = state->cur.free_bits;
|
||||
@ -507,7 +491,9 @@ flush_bits(working_state *state)
|
||||
put_bits = SIMD_BIT_BUF_SIZE - state->cur.free_bits;
|
||||
#endif
|
||||
put_buffer = state->cur.put_buffer.simd;
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
put_bits = BIT_BUF_SIZE - state->cur.free_bits;
|
||||
put_buffer = state->cur.put_buffer.c;
|
||||
}
|
||||
@ -525,6 +511,7 @@ flush_bits(working_state *state)
|
||||
EMIT_BYTE(temp)
|
||||
}
|
||||
|
||||
#ifdef WITH_SIMD
|
||||
if (state->simd) { /* and reset bit buffer to empty */
|
||||
state->cur.put_buffer.simd = 0;
|
||||
#if defined(__aarch64__) && !defined(NEON_INTRINSICS)
|
||||
@ -532,7 +519,9 @@ flush_bits(working_state *state)
|
||||
#else
|
||||
state->cur.free_bits = SIMD_BIT_BUF_SIZE;
|
||||
#endif
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
state->cur.put_buffer.c = 0;
|
||||
state->cur.free_bits = BIT_BUF_SIZE;
|
||||
}
|
||||
@ -542,6 +531,8 @@ flush_bits(working_state *state)
|
||||
}
|
||||
|
||||
|
||||
#ifdef WITH_SIMD
|
||||
|
||||
/* Encode a single block's worth of coefficients */
|
||||
|
||||
LOCAL(boolean)
|
||||
@ -561,6 +552,8 @@ encode_one_block_simd(working_state *state, JCOEFPTR block, int last_dc_val,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
LOCAL(boolean)
|
||||
encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val,
|
||||
c_derived_tbl *dctbl, c_derived_tbl *actbl)
|
||||
@ -569,6 +562,7 @@ encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val,
|
||||
bit_buf_type put_buffer;
|
||||
JOCTET _buffer[BUFSIZE], *buffer;
|
||||
int localbuf = 0;
|
||||
int max_coef_bits = state->cinfo->data_precision + 2;
|
||||
|
||||
free_bits = state->cur.free_bits;
|
||||
put_buffer = state->cur.put_buffer.c;
|
||||
@ -589,6 +583,11 @@ encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val,
|
||||
|
||||
/* Find the number of bits needed for the magnitude of the coefficient */
|
||||
nbits = JPEG_NBITS(nbits);
|
||||
/* Check for out-of-range coefficient values.
|
||||
* Since we're encoding a difference, the range limit is twice as much.
|
||||
*/
|
||||
if (nbits > max_coef_bits + 1)
|
||||
ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
|
||||
|
||||
/* Emit the Huffman-coded symbol for the number of bits.
|
||||
* Emit that number of bits of the value, if positive,
|
||||
@ -614,6 +613,9 @@ encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val,
|
||||
temp += nbits; \
|
||||
nbits ^= temp; \
|
||||
nbits = JPEG_NBITS_NONZERO(nbits); \
|
||||
/* Check for out-of-range coefficient values */ \
|
||||
if (nbits > max_coef_bits) \
|
||||
ERREXIT(state->cinfo, JERR_BAD_DCT_COEF); \
|
||||
/* if run length > 15, must emit special run-length-16 codes (0xF0) */ \
|
||||
while (r >= 16 * 16) { \
|
||||
r -= 16 * 16; \
|
||||
@ -695,7 +697,9 @@ encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
state.free_in_buffer = cinfo->dest->free_in_buffer;
|
||||
state.cur = entropy->saved;
|
||||
state.cinfo = cinfo;
|
||||
#ifdef WITH_SIMD
|
||||
state.simd = entropy->simd;
|
||||
#endif
|
||||
|
||||
/* Emit restart marker if needed */
|
||||
if (cinfo->restart_interval) {
|
||||
@ -705,6 +709,7 @@ encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
}
|
||||
|
||||
/* Encode the MCU data blocks */
|
||||
#ifdef WITH_SIMD
|
||||
if (entropy->simd) {
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
ci = cinfo->MCU_membership[blkn];
|
||||
@ -717,7 +722,9 @@ encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
/* Update last_dc_val */
|
||||
state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
ci = cinfo->MCU_membership[blkn];
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
@ -765,7 +772,9 @@ finish_pass_huff(j_compress_ptr cinfo)
|
||||
state.free_in_buffer = cinfo->dest->free_in_buffer;
|
||||
state.cur = entropy->saved;
|
||||
state.cinfo = cinfo;
|
||||
#ifdef WITH_SIMD
|
||||
state.simd = entropy->simd;
|
||||
#endif
|
||||
|
||||
/* Flush out the last data */
|
||||
if (!flush_bits(&state))
|
||||
@ -801,6 +810,7 @@ htest_one_block(j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
|
||||
register int temp;
|
||||
register int nbits;
|
||||
register int k, r;
|
||||
int max_coef_bits = cinfo->data_precision + 2;
|
||||
|
||||
/* Encode the DC coefficient difference per section F.1.2.1 */
|
||||
|
||||
@ -817,7 +827,7 @@ htest_one_block(j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
|
||||
/* Check for out-of-range coefficient values.
|
||||
* Since we're encoding a difference, the range limit is twice as much.
|
||||
*/
|
||||
if (nbits > MAX_COEF_BITS + 1)
|
||||
if (nbits > max_coef_bits + 1)
|
||||
ERREXIT(cinfo, JERR_BAD_DCT_COEF);
|
||||
|
||||
/* Count the Huffman symbol for the number of bits */
|
||||
@ -846,7 +856,7 @@ htest_one_block(j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
|
||||
while ((temp >>= 1))
|
||||
nbits++;
|
||||
/* Check for out-of-range coefficient values */
|
||||
if (nbits > MAX_COEF_BITS)
|
||||
if (nbits > max_coef_bits)
|
||||
ERREXIT(cinfo, JERR_BAD_DCT_COEF);
|
||||
|
||||
/* Count Huffman symbol for run length / number of bits */
|
||||
@ -901,7 +911,7 @@ encode_mcu_gather(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
|
||||
/*
|
||||
* Generate the best Huffman code table for the given counts, fill htbl.
|
||||
* Note this is also used by jcphuff.c.
|
||||
* Note this is also used by jcphuff.c and jclhuff.c.
|
||||
*
|
||||
* The JPEG standard requires that no symbol be assigned a codeword of all
|
||||
* one bits (so that padding bits added at the end of a compressed segment
|
||||
@ -933,11 +943,15 @@ jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
|
||||
{
|
||||
#define MAX_CLEN 32 /* assumed maximum initial code length */
|
||||
UINT8 bits[MAX_CLEN + 1]; /* bits[k] = # of symbols with code length k */
|
||||
int bit_pos[MAX_CLEN + 1]; /* # of symbols with smaller code length */
|
||||
int codesize[257]; /* codesize[k] = code length of symbol k */
|
||||
int nz_index[257]; /* index of nonzero symbol in the original freq
|
||||
array */
|
||||
int others[257]; /* next symbol in current branch of tree */
|
||||
int c1, c2;
|
||||
int p, i, j;
|
||||
long v;
|
||||
int num_nz_symbols;
|
||||
long v, v2;
|
||||
|
||||
/* This algorithm is explained in section K.2 of the JPEG standard */
|
||||
|
||||
@ -952,28 +966,41 @@ jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
|
||||
* will be placed last in the largest codeword category.
|
||||
*/
|
||||
|
||||
/* Group nonzero frequencies together so we can more easily find the
|
||||
* smallest.
|
||||
*/
|
||||
num_nz_symbols = 0;
|
||||
for (i = 0; i < 257; i++) {
|
||||
if (freq[i]) {
|
||||
nz_index[num_nz_symbols] = i;
|
||||
freq[num_nz_symbols] = freq[i];
|
||||
num_nz_symbols++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Huffman's basic algorithm to assign optimal code lengths to symbols */
|
||||
|
||||
for (;;) {
|
||||
/* Find the smallest nonzero frequency, set c1 = its symbol */
|
||||
/* In case of ties, take the larger symbol number */
|
||||
/* Find the two smallest nonzero frequencies; set c1, c2 = their symbols */
|
||||
/* In case of ties, take the larger symbol number. Since we have grouped
|
||||
* the nonzero symbols together, checking for zero symbols is not
|
||||
* necessary.
|
||||
*/
|
||||
c1 = -1;
|
||||
v = 1000000000L;
|
||||
for (i = 0; i <= 256; i++) {
|
||||
if (freq[i] && freq[i] <= v) {
|
||||
v = freq[i];
|
||||
c1 = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* Find the next smallest nonzero frequency, set c2 = its symbol */
|
||||
/* In case of ties, take the larger symbol number */
|
||||
c2 = -1;
|
||||
v = 1000000000L;
|
||||
for (i = 0; i <= 256; i++) {
|
||||
if (freq[i] && freq[i] <= v && i != c1) {
|
||||
v = freq[i];
|
||||
c2 = i;
|
||||
v2 = 1000000000L;
|
||||
for (i = 0; i < num_nz_symbols; i++) {
|
||||
if (freq[i] <= v2) {
|
||||
if (freq[i] <= v) {
|
||||
c2 = c1;
|
||||
v2 = v;
|
||||
v = freq[i];
|
||||
c1 = i;
|
||||
} else {
|
||||
v2 = freq[i];
|
||||
c2 = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -983,7 +1010,10 @@ jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
|
||||
|
||||
/* Else merge the two counts/trees */
|
||||
freq[c1] += freq[c2];
|
||||
freq[c2] = 0;
|
||||
/* Set the frequency to a very high value instead of zero, so we don't have
|
||||
* to check for zero values.
|
||||
*/
|
||||
freq[c2] = 1000000001L;
|
||||
|
||||
/* Increment the codesize of everything in c1's tree branch */
|
||||
codesize[c1]++;
|
||||
@ -1003,15 +1033,24 @@ jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
|
||||
}
|
||||
|
||||
/* Now count the number of symbols of each code length */
|
||||
for (i = 0; i <= 256; i++) {
|
||||
if (codesize[i]) {
|
||||
/* The JPEG standard seems to think that this can't happen, */
|
||||
/* but I'm paranoid... */
|
||||
if (codesize[i] > MAX_CLEN)
|
||||
ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
|
||||
for (i = 0; i < num_nz_symbols; i++) {
|
||||
/* The JPEG standard seems to think that this can't happen, */
|
||||
/* but I'm paranoid... */
|
||||
if (codesize[i] > MAX_CLEN)
|
||||
ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
|
||||
|
||||
bits[codesize[i]]++;
|
||||
}
|
||||
bits[codesize[i]]++;
|
||||
}
|
||||
|
||||
/* Count the number of symbols with a length smaller than i bits, so we can
|
||||
* construct the symbol table more efficiently. Note that this includes the
|
||||
* pseudo-symbol 256, but since it is the last symbol, it will not affect the
|
||||
* table.
|
||||
*/
|
||||
p = 0;
|
||||
for (i = 1; i <= MAX_CLEN; i++) {
|
||||
bit_pos[i] = p;
|
||||
p += bits[i];
|
||||
}
|
||||
|
||||
/* JPEG doesn't allow symbols with code lengths over 16 bits, so if the pure
|
||||
@ -1051,14 +1090,9 @@ jpeg_gen_optimal_table(j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
|
||||
* changes made above, but Rec. ITU-T T.81 | ISO/IEC 10918-1 seems to think
|
||||
* this works.
|
||||
*/
|
||||
p = 0;
|
||||
for (i = 1; i <= MAX_CLEN; i++) {
|
||||
for (j = 0; j <= 255; j++) {
|
||||
if (codesize[j] == i) {
|
||||
htbl->huffval[p] = (UINT8)j;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < num_nz_symbols - 1; i++) {
|
||||
htbl->huffval[bit_pos[codesize[i]]] = (UINT8)nz_index[i];
|
||||
bit_pos[codesize[i]]++;
|
||||
}
|
||||
|
||||
/* Set sent_table FALSE so updated table will be written to JPEG file. */
|
||||
|
16
3rdparty/libjpeg-turbo/src/jchuff.h
vendored
16
3rdparty/libjpeg-turbo/src/jchuff.h
vendored
@ -3,8 +3,8 @@
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1997, 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.
|
||||
*
|
||||
@ -19,11 +19,13 @@
|
||||
* Hence the magnitude should always fit in 10 or 14 bits respectively.
|
||||
*/
|
||||
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
#define MAX_COEF_BITS 10
|
||||
#else
|
||||
#define MAX_COEF_BITS 14
|
||||
#endif
|
||||
/* The progressive Huffman encoder uses an unsigned 16-bit data type to store
|
||||
* absolute values of coefficients, because it is possible to inject a
|
||||
* coefficient value of -32768 into the encoder by attempting to transform a
|
||||
* malformed 12-bit JPEG image, and the absolute value of -32768 would overflow
|
||||
* a signed 16-bit integer.
|
||||
*/
|
||||
typedef unsigned short UJCOEF;
|
||||
|
||||
/* Derived data constructed for each Huffman table */
|
||||
|
||||
|
121
3rdparty/libjpeg-turbo/src/jcinit.c
vendored
121
3rdparty/libjpeg-turbo/src/jcinit.c
vendored
@ -3,8 +3,10 @@
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* 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.
|
||||
*
|
||||
@ -21,7 +23,7 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jpegcomp.h"
|
||||
#include "jpegapicomp.h"
|
||||
|
||||
|
||||
/*
|
||||
@ -38,34 +40,101 @@ jinit_compress_master(j_compress_ptr cinfo)
|
||||
|
||||
/* Preprocessing */
|
||||
if (!cinfo->raw_data_in) {
|
||||
jinit_color_converter(cinfo);
|
||||
jinit_downsampler(cinfo);
|
||||
jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
|
||||
}
|
||||
/* Forward DCT */
|
||||
jinit_forward_dct(cinfo);
|
||||
/* Entropy encoding: either Huffman or arithmetic coding. */
|
||||
if (cinfo->arith_code) {
|
||||
#ifdef C_ARITH_CODING_SUPPORTED
|
||||
jinit_arith_encoder(cinfo);
|
||||
if (cinfo->data_precision == 16) {
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
j16init_color_converter(cinfo);
|
||||
j16init_downsampler(cinfo);
|
||||
j16init_c_prep_controller(cinfo,
|
||||
FALSE /* never need full buffer here */);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
#endif
|
||||
} else {
|
||||
if (cinfo->progressive_mode) {
|
||||
#ifdef C_PROGRESSIVE_SUPPORTED
|
||||
jinit_phuff_encoder(cinfo);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
} else
|
||||
jinit_huff_encoder(cinfo);
|
||||
} else if (cinfo->data_precision == 12) {
|
||||
j12init_color_converter(cinfo);
|
||||
j12init_downsampler(cinfo);
|
||||
j12init_c_prep_controller(cinfo,
|
||||
FALSE /* never need full buffer here */);
|
||||
} else {
|
||||
jinit_color_converter(cinfo);
|
||||
jinit_downsampler(cinfo);
|
||||
jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
|
||||
}
|
||||
}
|
||||
|
||||
/* Need a full-image coefficient buffer in any multi-pass mode. */
|
||||
jinit_c_coef_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
|
||||
cinfo->optimize_coding));
|
||||
jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
|
||||
if (cinfo->master->lossless) {
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
/* Prediction, sample differencing, and point transform */
|
||||
if (cinfo->data_precision == 16)
|
||||
j16init_lossless_compressor(cinfo);
|
||||
else if (cinfo->data_precision == 12)
|
||||
j12init_lossless_compressor(cinfo);
|
||||
else
|
||||
jinit_lossless_compressor(cinfo);
|
||||
/* Entropy encoding: either Huffman or arithmetic coding. */
|
||||
if (cinfo->arith_code) {
|
||||
ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
|
||||
} else {
|
||||
jinit_lhuff_encoder(cinfo);
|
||||
}
|
||||
|
||||
/* Need a full-image difference buffer in any multi-pass mode. */
|
||||
if (cinfo->data_precision == 16)
|
||||
j16init_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
|
||||
cinfo->optimize_coding));
|
||||
else if (cinfo->data_precision == 12)
|
||||
j12init_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
|
||||
cinfo->optimize_coding));
|
||||
else
|
||||
jinit_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
|
||||
cinfo->optimize_coding));
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
} else {
|
||||
if (cinfo->data_precision == 16)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
/* Forward DCT */
|
||||
if (cinfo->data_precision == 12)
|
||||
j12init_forward_dct(cinfo);
|
||||
else
|
||||
jinit_forward_dct(cinfo);
|
||||
/* Entropy encoding: either Huffman or arithmetic coding. */
|
||||
if (cinfo->arith_code) {
|
||||
#ifdef C_ARITH_CODING_SUPPORTED
|
||||
jinit_arith_encoder(cinfo);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
|
||||
#endif
|
||||
} else {
|
||||
if (cinfo->progressive_mode) {
|
||||
#ifdef C_PROGRESSIVE_SUPPORTED
|
||||
jinit_phuff_encoder(cinfo);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
} else
|
||||
jinit_huff_encoder(cinfo);
|
||||
}
|
||||
|
||||
/* Need a full-image coefficient buffer in any multi-pass mode. */
|
||||
if (cinfo->data_precision == 12)
|
||||
j12init_c_coef_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
|
||||
cinfo->optimize_coding));
|
||||
else
|
||||
jinit_c_coef_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
|
||||
cinfo->optimize_coding));
|
||||
}
|
||||
|
||||
if (cinfo->data_precision == 16)
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
j16init_c_main_controller(cinfo, FALSE /* never need full buffer here */);
|
||||
#else
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
#endif
|
||||
else if (cinfo->data_precision == 12)
|
||||
j12init_c_main_controller(cinfo, FALSE /* never need full buffer here */);
|
||||
else
|
||||
jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
|
||||
|
||||
jinit_marker_writer(cinfo);
|
||||
|
||||
|
587
3rdparty/libjpeg-turbo/src/jclhuff.c
vendored
Normal file
587
3rdparty/libjpeg-turbo/src/jclhuff.c
vendored
Normal file
@ -0,0 +1,587 @@
|
||||
/*
|
||||
* jclhuff.c
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file contains Huffman entropy encoding routines for lossless JPEG.
|
||||
*
|
||||
* Much of the complexity here has to do with supporting output suspension.
|
||||
* If the data destination module demands suspension, we want to be able to
|
||||
* back up to the start of the current MCU. To do this, we copy state
|
||||
* variables into local working storage, and update them back to the
|
||||
* permanent JPEG objects only upon successful completion of an MCU.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jlossls.h" /* Private declarations for lossless codec */
|
||||
#include "jchuff.h" /* Declarations shared with jc*huff.c */
|
||||
|
||||
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
|
||||
/* The legal range of a spatial difference is
|
||||
* -32767 .. +32768.
|
||||
* Hence the magnitude should always fit in 16 bits.
|
||||
*/
|
||||
|
||||
#define MAX_DIFF_BITS 16
|
||||
|
||||
|
||||
/* Expanded entropy encoder object for Huffman encoding in lossless mode.
|
||||
*
|
||||
* The savable_state subrecord contains fields that change within an MCU,
|
||||
* but must not be updated permanently until we complete the MCU.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
size_t put_buffer; /* current bit-accumulation buffer */
|
||||
int put_bits; /* # of bits now in it */
|
||||
} savable_state;
|
||||
|
||||
|
||||
typedef struct {
|
||||
int ci, yoffset, MCU_width;
|
||||
} lhe_input_ptr_info;
|
||||
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_entropy_encoder pub; /* public fields */
|
||||
|
||||
savable_state saved; /* Bit buffer at start of MCU */
|
||||
|
||||
/* These fields are NOT loaded into local working state. */
|
||||
unsigned int restarts_to_go; /* MCUs left in this restart interval */
|
||||
int next_restart_num; /* next restart number to write (0-7) */
|
||||
|
||||
/* Pointers to derived tables (these workspaces have image lifespan) */
|
||||
c_derived_tbl *derived_tbls[NUM_HUFF_TBLS];
|
||||
|
||||
/* Pointers to derived tables to be used for each data unit within an MCU */
|
||||
c_derived_tbl *cur_tbls[C_MAX_BLOCKS_IN_MCU];
|
||||
|
||||
#ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
|
||||
long *count_ptrs[NUM_HUFF_TBLS];
|
||||
|
||||
/* Pointers to stats tables to be used for each data unit within an MCU */
|
||||
long *cur_counts[C_MAX_BLOCKS_IN_MCU];
|
||||
#endif
|
||||
|
||||
/* Pointers to the proper input difference row for each group of data units
|
||||
* within an MCU. For each component, there are Vi groups of Hi data units.
|
||||
*/
|
||||
JDIFFROW input_ptr[C_MAX_BLOCKS_IN_MCU];
|
||||
|
||||
/* Number of input pointers in use for the current MCU. This is the sum
|
||||
* of all Vi in the MCU.
|
||||
*/
|
||||
int num_input_ptrs;
|
||||
|
||||
/* Information used for positioning the input pointers within the input
|
||||
* difference rows.
|
||||
*/
|
||||
lhe_input_ptr_info input_ptr_info[C_MAX_BLOCKS_IN_MCU];
|
||||
|
||||
/* Index of the proper input pointer for each data unit within an MCU */
|
||||
int input_ptr_index[C_MAX_BLOCKS_IN_MCU];
|
||||
|
||||
} lhuff_entropy_encoder;
|
||||
|
||||
typedef lhuff_entropy_encoder *lhuff_entropy_ptr;
|
||||
|
||||
/* Working state while writing an MCU.
|
||||
* This struct contains all the fields that are needed by subroutines.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
JOCTET *next_output_byte; /* => next byte to write in buffer */
|
||||
size_t free_in_buffer; /* # of byte spaces remaining in buffer */
|
||||
savable_state cur; /* Current bit buffer & DC state */
|
||||
j_compress_ptr cinfo; /* dump_buffer needs access to this */
|
||||
} working_state;
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF(JDIMENSION) encode_mcus_huff(j_compress_ptr cinfo,
|
||||
JDIFFIMAGE diff_buf,
|
||||
JDIMENSION MCU_row_num,
|
||||
JDIMENSION MCU_col_num,
|
||||
JDIMENSION nMCU);
|
||||
METHODDEF(void) finish_pass_huff(j_compress_ptr cinfo);
|
||||
#ifdef ENTROPY_OPT_SUPPORTED
|
||||
METHODDEF(JDIMENSION) encode_mcus_gather(j_compress_ptr cinfo,
|
||||
JDIFFIMAGE diff_buf,
|
||||
JDIMENSION MCU_row_num,
|
||||
JDIMENSION MCU_col_num,
|
||||
JDIMENSION nMCU);
|
||||
METHODDEF(void) finish_pass_gather(j_compress_ptr cinfo);
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Initialize for a Huffman-compressed scan.
|
||||
* If gather_statistics is TRUE, we do not output anything during the scan,
|
||||
* just count the Huffman symbols used and generate Huffman code tables.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
start_pass_lhuff(j_compress_ptr cinfo, boolean gather_statistics)
|
||||
{
|
||||
lhuff_entropy_ptr entropy = (lhuff_entropy_ptr)cinfo->entropy;
|
||||
int ci, dctbl, sampn, ptrn, yoffset, xoffset;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
if (gather_statistics) {
|
||||
#ifdef ENTROPY_OPT_SUPPORTED
|
||||
entropy->pub.encode_mcus = encode_mcus_gather;
|
||||
entropy->pub.finish_pass = finish_pass_gather;
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
} else {
|
||||
entropy->pub.encode_mcus = encode_mcus_huff;
|
||||
entropy->pub.finish_pass = finish_pass_huff;
|
||||
}
|
||||
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
dctbl = compptr->dc_tbl_no;
|
||||
if (gather_statistics) {
|
||||
#ifdef ENTROPY_OPT_SUPPORTED
|
||||
/* Check for invalid table indexes */
|
||||
/* (make_c_derived_tbl does this in the other path) */
|
||||
if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
|
||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
|
||||
/* Allocate and zero the statistics tables */
|
||||
/* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
|
||||
if (entropy->count_ptrs[dctbl] == NULL)
|
||||
entropy->count_ptrs[dctbl] = (long *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
257 * sizeof(long));
|
||||
memset(entropy->count_ptrs[dctbl], 0, 257 * sizeof(long));
|
||||
#endif
|
||||
} else {
|
||||
/* Compute derived values for Huffman tables */
|
||||
/* We may do this more than once for a table, but it's not expensive */
|
||||
jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
|
||||
&entropy->derived_tbls[dctbl]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Precalculate encoding info for each sample in an MCU of this scan */
|
||||
for (sampn = 0, ptrn = 0; sampn < cinfo->blocks_in_MCU;) {
|
||||
compptr = cinfo->cur_comp_info[cinfo->MCU_membership[sampn]];
|
||||
ci = compptr->component_index;
|
||||
for (yoffset = 0; yoffset < compptr->MCU_height; yoffset++, ptrn++) {
|
||||
/* Precalculate the setup info for each input pointer */
|
||||
entropy->input_ptr_info[ptrn].ci = ci;
|
||||
entropy->input_ptr_info[ptrn].yoffset = yoffset;
|
||||
entropy->input_ptr_info[ptrn].MCU_width = compptr->MCU_width;
|
||||
for (xoffset = 0; xoffset < compptr->MCU_width; xoffset++, sampn++) {
|
||||
/* Precalculate the input pointer index for each sample */
|
||||
entropy->input_ptr_index[sampn] = ptrn;
|
||||
/* Precalculate which tables to use for each sample */
|
||||
entropy->cur_tbls[sampn] = entropy->derived_tbls[compptr->dc_tbl_no];
|
||||
entropy->cur_counts[sampn] = entropy->count_ptrs[compptr->dc_tbl_no];
|
||||
}
|
||||
}
|
||||
}
|
||||
entropy->num_input_ptrs = ptrn;
|
||||
|
||||
/* Initialize bit buffer to empty */
|
||||
entropy->saved.put_buffer = 0;
|
||||
entropy->saved.put_bits = 0;
|
||||
|
||||
/* Initialize restart stuff */
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
entropy->next_restart_num = 0;
|
||||
}
|
||||
|
||||
|
||||
/* Outputting bytes to the file */
|
||||
|
||||
/* Emit a byte, taking 'action' if must suspend. */
|
||||
#define emit_byte(state, val, action) { \
|
||||
*(state)->next_output_byte++ = (JOCTET)(val); \
|
||||
if (--(state)->free_in_buffer == 0) \
|
||||
if (!dump_buffer(state)) \
|
||||
{ action; } \
|
||||
}
|
||||
|
||||
|
||||
LOCAL(boolean)
|
||||
dump_buffer(working_state *state)
|
||||
/* Empty the output buffer; return TRUE if successful, FALSE if must suspend */
|
||||
{
|
||||
struct jpeg_destination_mgr *dest = state->cinfo->dest;
|
||||
|
||||
if (!(*dest->empty_output_buffer) (state->cinfo))
|
||||
return FALSE;
|
||||
/* After a successful buffer dump, must reset buffer pointers */
|
||||
state->next_output_byte = dest->next_output_byte;
|
||||
state->free_in_buffer = dest->free_in_buffer;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* Outputting bits to the file */
|
||||
|
||||
/* Only the right 24 bits of put_buffer are used; the valid bits are
|
||||
* left-justified in this part. At most 16 bits can be passed to emit_bits
|
||||
* in one call, and we never retain more than 7 bits in put_buffer
|
||||
* between calls, so 24 bits are sufficient.
|
||||
*/
|
||||
|
||||
INLINE
|
||||
LOCAL(boolean)
|
||||
emit_bits(working_state *state, unsigned int code, int size)
|
||||
/* Emit some bits; return TRUE if successful, FALSE if must suspend */
|
||||
{
|
||||
/* This routine is heavily used, so it's worth coding tightly. */
|
||||
register size_t put_buffer = (size_t)code;
|
||||
register int put_bits = state->cur.put_bits;
|
||||
|
||||
/* if size is 0, caller used an invalid Huffman table entry */
|
||||
if (size == 0)
|
||||
ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
|
||||
|
||||
put_buffer &= (((size_t)1) << size) - 1; /* mask off any extra bits in code */
|
||||
|
||||
put_bits += size; /* new number of bits in buffer */
|
||||
|
||||
put_buffer <<= 24 - put_bits; /* align incoming bits */
|
||||
|
||||
put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
|
||||
|
||||
while (put_bits >= 8) {
|
||||
int c = (int)((put_buffer >> 16) & 0xFF);
|
||||
|
||||
emit_byte(state, c, return FALSE);
|
||||
if (c == 0xFF) { /* need to stuff a zero byte? */
|
||||
emit_byte(state, 0, return FALSE);
|
||||
}
|
||||
put_buffer <<= 8;
|
||||
put_bits -= 8;
|
||||
}
|
||||
|
||||
state->cur.put_buffer = put_buffer; /* update state variables */
|
||||
state->cur.put_bits = put_bits;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
LOCAL(boolean)
|
||||
flush_bits(working_state *state)
|
||||
{
|
||||
if (!emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
|
||||
return FALSE;
|
||||
state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
|
||||
state->cur.put_bits = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Emit a restart marker & resynchronize predictions.
|
||||
*/
|
||||
|
||||
LOCAL(boolean)
|
||||
emit_restart(working_state *state, int restart_num)
|
||||
{
|
||||
if (!flush_bits(state))
|
||||
return FALSE;
|
||||
|
||||
emit_byte(state, 0xFF, return FALSE);
|
||||
emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
|
||||
|
||||
/* The restart counter is not updated until we successfully write the MCU. */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Encode and output nMCU MCUs' worth of Huffman-compressed differences.
|
||||
*/
|
||||
|
||||
METHODDEF(JDIMENSION)
|
||||
encode_mcus_huff(j_compress_ptr cinfo, JDIFFIMAGE diff_buf,
|
||||
JDIMENSION MCU_row_num, JDIMENSION MCU_col_num,
|
||||
JDIMENSION nMCU)
|
||||
{
|
||||
lhuff_entropy_ptr entropy = (lhuff_entropy_ptr)cinfo->entropy;
|
||||
working_state state;
|
||||
int sampn, ci, yoffset, MCU_width, ptrn;
|
||||
JDIMENSION mcu_num;
|
||||
|
||||
/* Load up working state */
|
||||
state.next_output_byte = cinfo->dest->next_output_byte;
|
||||
state.free_in_buffer = cinfo->dest->free_in_buffer;
|
||||
state.cur = entropy->saved;
|
||||
state.cinfo = cinfo;
|
||||
|
||||
/* Emit restart marker if needed */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0)
|
||||
if (!emit_restart(&state, entropy->next_restart_num))
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set input pointer locations based on MCU_col_num */
|
||||
for (ptrn = 0; ptrn < entropy->num_input_ptrs; ptrn++) {
|
||||
ci = entropy->input_ptr_info[ptrn].ci;
|
||||
yoffset = entropy->input_ptr_info[ptrn].yoffset;
|
||||
MCU_width = entropy->input_ptr_info[ptrn].MCU_width;
|
||||
entropy->input_ptr[ptrn] =
|
||||
diff_buf[ci][MCU_row_num + yoffset] + (MCU_col_num * MCU_width);
|
||||
}
|
||||
|
||||
for (mcu_num = 0; mcu_num < nMCU; mcu_num++) {
|
||||
|
||||
/* Inner loop handles the samples in the MCU */
|
||||
for (sampn = 0; sampn < cinfo->blocks_in_MCU; sampn++) {
|
||||
register int temp, temp2;
|
||||
register int nbits;
|
||||
c_derived_tbl *dctbl = entropy->cur_tbls[sampn];
|
||||
|
||||
/* Encode the difference per section H.1.2.2 */
|
||||
|
||||
/* Input the sample difference */
|
||||
temp = *entropy->input_ptr[entropy->input_ptr_index[sampn]]++;
|
||||
|
||||
if (temp & 0x8000) { /* instead of temp < 0 */
|
||||
temp = (-temp) & 0x7FFF; /* absolute value, mod 2^16 */
|
||||
if (temp == 0) /* special case: magnitude = 32768 */
|
||||
temp2 = temp = 0x8000;
|
||||
temp2 = ~temp; /* one's complement of magnitude */
|
||||
} else {
|
||||
temp &= 0x7FFF; /* abs value mod 2^16 */
|
||||
temp2 = temp; /* magnitude */
|
||||
}
|
||||
|
||||
/* Find the number of bits needed for the magnitude of the difference */
|
||||
nbits = 0;
|
||||
while (temp) {
|
||||
nbits++;
|
||||
temp >>= 1;
|
||||
}
|
||||
/* Check for out-of-range difference values.
|
||||
*/
|
||||
if (nbits > MAX_DIFF_BITS)
|
||||
ERREXIT(cinfo, JERR_BAD_DCT_COEF);
|
||||
|
||||
/* Emit the Huffman-coded symbol for the number of bits */
|
||||
if (!emit_bits(&state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
|
||||
return mcu_num;
|
||||
|
||||
/* Emit that number of bits of the value, if positive, */
|
||||
/* or the complement of its magnitude, if negative. */
|
||||
if (nbits && /* emit_bits rejects calls with size 0 */
|
||||
nbits != 16) /* special case: no bits should be emitted */
|
||||
if (!emit_bits(&state, (unsigned int)temp2, nbits))
|
||||
return mcu_num;
|
||||
}
|
||||
|
||||
/* Completed MCU, so update state */
|
||||
cinfo->dest->next_output_byte = state.next_output_byte;
|
||||
cinfo->dest->free_in_buffer = state.free_in_buffer;
|
||||
entropy->saved = state.cur;
|
||||
|
||||
/* Update restart-interval state too */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0) {
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
entropy->next_restart_num++;
|
||||
entropy->next_restart_num &= 7;
|
||||
}
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nMCU;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Finish up at the end of a Huffman-compressed scan.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
finish_pass_huff(j_compress_ptr cinfo)
|
||||
{
|
||||
lhuff_entropy_ptr entropy = (lhuff_entropy_ptr)cinfo->entropy;
|
||||
working_state state;
|
||||
|
||||
/* Load up working state ... flush_bits needs it */
|
||||
state.next_output_byte = cinfo->dest->next_output_byte;
|
||||
state.free_in_buffer = cinfo->dest->free_in_buffer;
|
||||
state.cur = entropy->saved;
|
||||
state.cinfo = cinfo;
|
||||
|
||||
/* Flush out the last data */
|
||||
if (!flush_bits(&state))
|
||||
ERREXIT(cinfo, JERR_CANT_SUSPEND);
|
||||
|
||||
/* Update state */
|
||||
cinfo->dest->next_output_byte = state.next_output_byte;
|
||||
cinfo->dest->free_in_buffer = state.free_in_buffer;
|
||||
entropy->saved = state.cur;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Huffman coding optimization.
|
||||
*
|
||||
* We first scan the supplied data and count the number of uses of each symbol
|
||||
* that is to be Huffman-coded. (This process MUST agree with the code above.)
|
||||
* Then we build a Huffman coding tree for the observed counts.
|
||||
* Symbols which are not needed at all for the particular image are not
|
||||
* assigned any code, which saves space in the DHT marker as well as in
|
||||
* the compressed data.
|
||||
*/
|
||||
|
||||
#ifdef ENTROPY_OPT_SUPPORTED
|
||||
|
||||
/*
|
||||
* Trial-encode nMCU MCUs' worth of Huffman-compressed differences.
|
||||
* No data is actually output, so no suspension return is possible.
|
||||
*/
|
||||
|
||||
METHODDEF(JDIMENSION)
|
||||
encode_mcus_gather(j_compress_ptr cinfo, JDIFFIMAGE diff_buf,
|
||||
JDIMENSION MCU_row_num, JDIMENSION MCU_col_num,
|
||||
JDIMENSION nMCU)
|
||||
{
|
||||
lhuff_entropy_ptr entropy = (lhuff_entropy_ptr)cinfo->entropy;
|
||||
int sampn, ci, yoffset, MCU_width, ptrn;
|
||||
JDIMENSION mcu_num;
|
||||
|
||||
/* Take care of restart intervals if needed */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0) {
|
||||
/* Update restart state */
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
}
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
/* Set input pointer locations based on MCU_col_num */
|
||||
for (ptrn = 0; ptrn < entropy->num_input_ptrs; ptrn++) {
|
||||
ci = entropy->input_ptr_info[ptrn].ci;
|
||||
yoffset = entropy->input_ptr_info[ptrn].yoffset;
|
||||
MCU_width = entropy->input_ptr_info[ptrn].MCU_width;
|
||||
entropy->input_ptr[ptrn] =
|
||||
diff_buf[ci][MCU_row_num + yoffset] + (MCU_col_num * MCU_width);
|
||||
}
|
||||
|
||||
for (mcu_num = 0; mcu_num < nMCU; mcu_num++) {
|
||||
|
||||
/* Inner loop handles the samples in the MCU */
|
||||
for (sampn = 0; sampn < cinfo->blocks_in_MCU; sampn++) {
|
||||
register int temp;
|
||||
register int nbits;
|
||||
long *counts = entropy->cur_counts[sampn];
|
||||
|
||||
/* Encode the difference per section H.1.2.2 */
|
||||
|
||||
/* Input the sample difference */
|
||||
temp = *entropy->input_ptr[entropy->input_ptr_index[sampn]]++;
|
||||
|
||||
if (temp & 0x8000) { /* instead of temp < 0 */
|
||||
temp = (-temp) & 0x7FFF; /* absolute value, mod 2^16 */
|
||||
if (temp == 0) /* special case: magnitude = 32768 */
|
||||
temp = 0x8000;
|
||||
} else
|
||||
temp &= 0x7FFF; /* abs value mod 2^16 */
|
||||
|
||||
/* Find the number of bits needed for the magnitude of the difference */
|
||||
nbits = 0;
|
||||
while (temp) {
|
||||
nbits++;
|
||||
temp >>= 1;
|
||||
}
|
||||
/* Check for out-of-range difference values.
|
||||
*/
|
||||
if (nbits > MAX_DIFF_BITS)
|
||||
ERREXIT(cinfo, JERR_BAD_DCT_COEF);
|
||||
|
||||
/* Count the Huffman symbol for the number of bits */
|
||||
counts[nbits]++;
|
||||
}
|
||||
}
|
||||
|
||||
return nMCU;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Finish up a statistics-gathering pass and create the new Huffman tables.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
finish_pass_gather(j_compress_ptr cinfo)
|
||||
{
|
||||
lhuff_entropy_ptr entropy = (lhuff_entropy_ptr)cinfo->entropy;
|
||||
int ci, dctbl;
|
||||
jpeg_component_info *compptr;
|
||||
JHUFF_TBL **htblptr;
|
||||
boolean did_dc[NUM_HUFF_TBLS];
|
||||
|
||||
/* It's important not to apply jpeg_gen_optimal_table more than once
|
||||
* per table, because it clobbers the input frequency counts!
|
||||
*/
|
||||
memset(did_dc, 0, sizeof(did_dc));
|
||||
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
dctbl = compptr->dc_tbl_no;
|
||||
if (!did_dc[dctbl]) {
|
||||
htblptr = &cinfo->dc_huff_tbl_ptrs[dctbl];
|
||||
if (*htblptr == NULL)
|
||||
*htblptr = jpeg_alloc_huff_table((j_common_ptr)cinfo);
|
||||
jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[dctbl]);
|
||||
did_dc[dctbl] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* ENTROPY_OPT_SUPPORTED */
|
||||
|
||||
|
||||
/*
|
||||
* Module initialization routine for Huffman entropy encoding.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_lhuff_encoder(j_compress_ptr cinfo)
|
||||
{
|
||||
lhuff_entropy_ptr entropy;
|
||||
int i;
|
||||
|
||||
entropy = (lhuff_entropy_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(lhuff_entropy_encoder));
|
||||
cinfo->entropy = (struct jpeg_entropy_encoder *)entropy;
|
||||
entropy->pub.start_pass = start_pass_lhuff;
|
||||
|
||||
/* Mark tables unallocated */
|
||||
for (i = 0; i < NUM_HUFF_TBLS; i++) {
|
||||
entropy->derived_tbls[i] = NULL;
|
||||
#ifdef ENTROPY_OPT_SUPPORTED
|
||||
entropy->count_ptrs[i] = NULL;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* C_LOSSLESS_SUPPORTED */
|
319
3rdparty/libjpeg-turbo/src/jclossls.c
vendored
Normal file
319
3rdparty/libjpeg-turbo/src/jclossls.c
vendored
Normal file
@ -0,0 +1,319 @@
|
||||
/*
|
||||
* jclossls.c
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1998, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file contains prediction, sample differencing, and point transform
|
||||
* routines for the lossless JPEG compressor.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jlossls.h"
|
||||
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
|
||||
|
||||
/************************** Sample differencing **************************/
|
||||
|
||||
/*
|
||||
* In order to avoid a performance penalty for checking which predictor is
|
||||
* being used and which row is being processed for each call of the
|
||||
* undifferencer, and to promote optimization, we have separate differencing
|
||||
* functions for each predictor selection value.
|
||||
*
|
||||
* We are able to avoid duplicating source code by implementing the predictors
|
||||
* and differencers as macros. Each of the differencing functions is simply a
|
||||
* wrapper around a DIFFERENCE macro with the appropriate PREDICTOR macro
|
||||
* passed as an argument.
|
||||
*/
|
||||
|
||||
/* Forward declarations */
|
||||
LOCAL(void) reset_predictor(j_compress_ptr cinfo, int ci);
|
||||
|
||||
|
||||
/* Predictor for the first column of the first row: 2^(P-Pt-1) */
|
||||
#define INITIAL_PREDICTORx (1 << (cinfo->data_precision - cinfo->Al - 1))
|
||||
|
||||
/* Predictor for the first column of the remaining rows: Rb */
|
||||
#define INITIAL_PREDICTOR2 prev_row[0]
|
||||
|
||||
|
||||
/*
|
||||
* 1-Dimensional differencer routine.
|
||||
*
|
||||
* This macro implements the 1-D horizontal predictor (1). INITIAL_PREDICTOR
|
||||
* is used as the special case predictor for the first column, which must be
|
||||
* either INITIAL_PREDICTOR2 or INITIAL_PREDICTORx. The remaining samples
|
||||
* use PREDICTOR1.
|
||||
*/
|
||||
|
||||
#define DIFFERENCE_1D(INITIAL_PREDICTOR) \
|
||||
lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct; \
|
||||
boolean restart = FALSE; \
|
||||
int samp, Ra; \
|
||||
\
|
||||
samp = *input_buf++; \
|
||||
*diff_buf++ = samp - INITIAL_PREDICTOR; \
|
||||
\
|
||||
while (--width) { \
|
||||
Ra = samp; \
|
||||
samp = *input_buf++; \
|
||||
*diff_buf++ = samp - PREDICTOR1; \
|
||||
} \
|
||||
\
|
||||
/* Account for restart interval (no-op if not using restarts) */ \
|
||||
if (cinfo->restart_interval) { \
|
||||
if (--(losslessc->restart_rows_to_go[ci]) == 0) { \
|
||||
reset_predictor(cinfo, ci); \
|
||||
restart = TRUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 2-Dimensional differencer routine.
|
||||
*
|
||||
* This macro implements the 2-D horizontal predictors (#2-7). PREDICTOR2 is
|
||||
* used as the special case predictor for the first column. The remaining
|
||||
* samples use PREDICTOR, which is a function of Ra, Rb, and Rc.
|
||||
*
|
||||
* Because prev_row and output_buf may point to the same storage area (in an
|
||||
* interleaved image with Vi=1, for example), we must take care to buffer Rb/Rc
|
||||
* before writing the current reconstructed sample value into output_buf.
|
||||
*/
|
||||
|
||||
#define DIFFERENCE_2D(PREDICTOR) \
|
||||
lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct; \
|
||||
int samp, Ra, Rb, Rc; \
|
||||
\
|
||||
Rb = *prev_row++; \
|
||||
samp = *input_buf++; \
|
||||
*diff_buf++ = samp - PREDICTOR2; \
|
||||
\
|
||||
while (--width) { \
|
||||
Rc = Rb; \
|
||||
Rb = *prev_row++; \
|
||||
Ra = samp; \
|
||||
samp = *input_buf++; \
|
||||
*diff_buf++ = samp - PREDICTOR; \
|
||||
} \
|
||||
\
|
||||
/* Account for restart interval (no-op if not using restarts) */ \
|
||||
if (cinfo->restart_interval) { \
|
||||
if (--losslessc->restart_rows_to_go[ci] == 0) \
|
||||
reset_predictor(cinfo, ci); \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Differencers for the second and subsequent rows in a scan or restart
|
||||
* interval. The first sample in the row is differenced using the vertical
|
||||
* predictor (2). The rest of the samples are differenced using the predictor
|
||||
* specified in the scan header.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_difference1(j_compress_ptr cinfo, int ci,
|
||||
_JSAMPROW input_buf, _JSAMPROW prev_row,
|
||||
JDIFFROW diff_buf, JDIMENSION width)
|
||||
{
|
||||
DIFFERENCE_1D(INITIAL_PREDICTOR2);
|
||||
(void)(restart);
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_difference2(j_compress_ptr cinfo, int ci,
|
||||
_JSAMPROW input_buf, _JSAMPROW prev_row,
|
||||
JDIFFROW diff_buf, JDIMENSION width)
|
||||
{
|
||||
DIFFERENCE_2D(PREDICTOR2);
|
||||
(void)(Ra);
|
||||
(void)(Rc);
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_difference3(j_compress_ptr cinfo, int ci,
|
||||
_JSAMPROW input_buf, _JSAMPROW prev_row,
|
||||
JDIFFROW diff_buf, JDIMENSION width)
|
||||
{
|
||||
DIFFERENCE_2D(PREDICTOR3);
|
||||
(void)(Ra);
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_difference4(j_compress_ptr cinfo, int ci,
|
||||
_JSAMPROW input_buf, _JSAMPROW prev_row,
|
||||
JDIFFROW diff_buf, JDIMENSION width)
|
||||
{
|
||||
DIFFERENCE_2D(PREDICTOR4);
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_difference5(j_compress_ptr cinfo, int ci,
|
||||
_JSAMPROW input_buf, _JSAMPROW prev_row,
|
||||
JDIFFROW diff_buf, JDIMENSION width)
|
||||
{
|
||||
DIFFERENCE_2D(PREDICTOR5);
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_difference6(j_compress_ptr cinfo, int ci,
|
||||
_JSAMPROW input_buf, _JSAMPROW prev_row,
|
||||
JDIFFROW diff_buf, JDIMENSION width)
|
||||
{
|
||||
DIFFERENCE_2D(PREDICTOR6);
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_difference7(j_compress_ptr cinfo, int ci,
|
||||
_JSAMPROW input_buf, _JSAMPROW prev_row,
|
||||
JDIFFROW diff_buf, JDIMENSION width)
|
||||
{
|
||||
DIFFERENCE_2D(PREDICTOR7);
|
||||
(void)(Rc);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Differencer for the first row in a scan or restart interval. The first
|
||||
* sample in the row is differenced using the special predictor constant
|
||||
* x = 2 ^ (P-Pt-1). The rest of the samples are differenced using the
|
||||
* 1-D horizontal predictor (1).
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_difference_first_row(j_compress_ptr cinfo, int ci,
|
||||
_JSAMPROW input_buf, _JSAMPROW prev_row,
|
||||
JDIFFROW diff_buf, JDIMENSION width)
|
||||
{
|
||||
DIFFERENCE_1D(INITIAL_PREDICTORx);
|
||||
|
||||
/*
|
||||
* Now that we have differenced the first row, we want to use the
|
||||
* differencer that corresponds to the predictor specified in the
|
||||
* scan header.
|
||||
*
|
||||
* Note that we don't do this if we have just reset the predictor
|
||||
* for a new restart interval.
|
||||
*/
|
||||
if (!restart) {
|
||||
switch (cinfo->Ss) {
|
||||
case 1:
|
||||
losslessc->predict_difference[ci] = jpeg_difference1;
|
||||
break;
|
||||
case 2:
|
||||
losslessc->predict_difference[ci] = jpeg_difference2;
|
||||
break;
|
||||
case 3:
|
||||
losslessc->predict_difference[ci] = jpeg_difference3;
|
||||
break;
|
||||
case 4:
|
||||
losslessc->predict_difference[ci] = jpeg_difference4;
|
||||
break;
|
||||
case 5:
|
||||
losslessc->predict_difference[ci] = jpeg_difference5;
|
||||
break;
|
||||
case 6:
|
||||
losslessc->predict_difference[ci] = jpeg_difference6;
|
||||
break;
|
||||
case 7:
|
||||
losslessc->predict_difference[ci] = jpeg_difference7;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Reset predictor at the start of a pass or restart interval.
|
||||
*/
|
||||
|
||||
LOCAL(void)
|
||||
reset_predictor(j_compress_ptr cinfo, int ci)
|
||||
{
|
||||
lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
|
||||
|
||||
/* Initialize restart counter */
|
||||
losslessc->restart_rows_to_go[ci] =
|
||||
cinfo->restart_interval / cinfo->MCUs_per_row;
|
||||
|
||||
/* Set difference function to first row function */
|
||||
losslessc->predict_difference[ci] = jpeg_difference_first_row;
|
||||
}
|
||||
|
||||
|
||||
/********************** Sample downscaling by 2^Pt ***********************/
|
||||
|
||||
METHODDEF(void)
|
||||
simple_downscale(j_compress_ptr cinfo,
|
||||
_JSAMPROW input_buf, _JSAMPROW output_buf, JDIMENSION width)
|
||||
{
|
||||
do {
|
||||
*output_buf++ = (_JSAMPLE)RIGHT_SHIFT(*input_buf++, cinfo->Al);
|
||||
} while (--width);
|
||||
}
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
noscale(j_compress_ptr cinfo,
|
||||
_JSAMPROW input_buf, _JSAMPROW output_buf, JDIMENSION width)
|
||||
{
|
||||
memcpy(output_buf, input_buf, width * sizeof(_JSAMPLE));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize for a processing pass.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
start_pass_lossless(j_compress_ptr cinfo)
|
||||
{
|
||||
lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
|
||||
int ci;
|
||||
|
||||
/* Set scaler function based on Pt */
|
||||
if (cinfo->Al)
|
||||
losslessc->scaler_scale = simple_downscale;
|
||||
else
|
||||
losslessc->scaler_scale = noscale;
|
||||
|
||||
/* Check that the restart interval is an integer multiple of the number
|
||||
* of MCUs in an MCU row.
|
||||
*/
|
||||
if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
|
||||
ERREXIT2(cinfo, JERR_BAD_RESTART,
|
||||
cinfo->restart_interval, cinfo->MCUs_per_row);
|
||||
|
||||
/* Set predictors for start of pass */
|
||||
for (ci = 0; ci < cinfo->num_components; ci++)
|
||||
reset_predictor(cinfo, ci);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize the lossless compressor.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
_jinit_lossless_compressor(j_compress_ptr cinfo)
|
||||
{
|
||||
lossless_comp_ptr losslessc;
|
||||
|
||||
/* Create subobject in permanent pool */
|
||||
losslessc = (lossless_comp_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
|
||||
sizeof(jpeg_lossless_compressor));
|
||||
cinfo->fdct = (struct jpeg_forward_dct *)losslessc;
|
||||
losslessc->pub.start_pass = start_pass_lossless;
|
||||
}
|
||||
|
||||
#endif /* C_LOSSLESS_SUPPORTED */
|
45
3rdparty/libjpeg-turbo/src/jcmainct.c
vendored
45
3rdparty/libjpeg-turbo/src/jcmainct.c
vendored
@ -3,8 +3,10 @@
|
||||
*
|
||||
* This file was 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.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -16,8 +18,11 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)
|
||||
|
||||
/* Private buffer controller object */
|
||||
|
||||
typedef struct {
|
||||
@ -32,7 +37,7 @@ typedef struct {
|
||||
* (we allocate one for each component). In the full-image case, this
|
||||
* points to the currently accessible strips of the virtual arrays.
|
||||
*/
|
||||
JSAMPARRAY buffer[MAX_COMPONENTS];
|
||||
_JSAMPARRAY buffer[MAX_COMPONENTS];
|
||||
} my_main_controller;
|
||||
|
||||
typedef my_main_controller *my_main_ptr;
|
||||
@ -40,7 +45,7 @@ typedef my_main_controller *my_main_ptr;
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF(void) process_data_simple_main(j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf,
|
||||
_JSAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail);
|
||||
|
||||
@ -65,7 +70,7 @@ start_pass_main(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
main_ptr->rowgroup_ctr = 0;
|
||||
main_ptr->suspended = FALSE;
|
||||
main_ptr->pass_mode = pass_mode; /* save mode for use by process_data */
|
||||
main_ptr->pub.process_data = process_data_simple_main;
|
||||
main_ptr->pub._process_data = process_data_simple_main;
|
||||
}
|
||||
|
||||
|
||||
@ -76,28 +81,28 @@ start_pass_main(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
process_data_simple_main(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
process_data_simple_main(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail)
|
||||
{
|
||||
my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
|
||||
JDIMENSION data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
|
||||
while (main_ptr->cur_iMCU_row < cinfo->total_iMCU_rows) {
|
||||
/* Read input data if we haven't filled the main buffer yet */
|
||||
if (main_ptr->rowgroup_ctr < DCTSIZE)
|
||||
(*cinfo->prep->pre_process_data) (cinfo, input_buf, in_row_ctr,
|
||||
in_rows_avail, main_ptr->buffer,
|
||||
&main_ptr->rowgroup_ctr,
|
||||
(JDIMENSION)DCTSIZE);
|
||||
if (main_ptr->rowgroup_ctr < data_unit)
|
||||
(*cinfo->prep->_pre_process_data) (cinfo, input_buf, in_row_ctr,
|
||||
in_rows_avail, main_ptr->buffer,
|
||||
&main_ptr->rowgroup_ctr, data_unit);
|
||||
|
||||
/* If we don't have a full iMCU row buffered, return to application for
|
||||
* more data. Note that preprocessor will always pad to fill the iMCU row
|
||||
* at the bottom of the image.
|
||||
*/
|
||||
if (main_ptr->rowgroup_ctr != DCTSIZE)
|
||||
if (main_ptr->rowgroup_ctr != data_unit)
|
||||
return;
|
||||
|
||||
/* Send the completed row to the compressor */
|
||||
if (!(*cinfo->coef->compress_data) (cinfo, main_ptr->buffer)) {
|
||||
if (!(*cinfo->coef->_compress_data) (cinfo, main_ptr->buffer)) {
|
||||
/* If compressor did not consume the whole row, then we must need to
|
||||
* suspend processing and return to the application. In this situation
|
||||
* we pretend we didn't yet consume the last input row; otherwise, if
|
||||
@ -128,11 +133,15 @@ process_data_simple_main(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_c_main_controller(j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
_jinit_c_main_controller(j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_main_ptr main_ptr;
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
main_ptr = (my_main_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
@ -153,10 +162,12 @@ jinit_c_main_controller(j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
/* Allocate a strip buffer for each component */
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray)
|
||||
main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
compptr->width_in_blocks * DCTSIZE,
|
||||
(JDIMENSION)(compptr->v_samp_factor * DCTSIZE));
|
||||
compptr->width_in_blocks * data_unit,
|
||||
(JDIMENSION)(compptr->v_samp_factor * data_unit));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */
|
||||
|
36
3rdparty/libjpeg-turbo/src/jcmarker.c
vendored
36
3rdparty/libjpeg-turbo/src/jcmarker.c
vendored
@ -4,8 +4,10 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* Modified 2003-2010 by Guido Vollbeding.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2010, D. R. Commander.
|
||||
* Copyright (C) 2010, 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -15,7 +17,7 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jpegcomp.h"
|
||||
#include "jpegapicomp.h"
|
||||
|
||||
|
||||
typedef enum { /* JPEG marker codes */
|
||||
@ -497,25 +499,26 @@ write_file_header(j_compress_ptr cinfo)
|
||||
METHODDEF(void)
|
||||
write_frame_header(j_compress_ptr cinfo)
|
||||
{
|
||||
int ci, prec;
|
||||
int ci, prec = 0;
|
||||
boolean is_baseline;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
/* Emit DQT for each quantization table.
|
||||
* Note that emit_dqt() suppresses any duplicate tables.
|
||||
*/
|
||||
prec = 0;
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
prec += emit_dqt(cinfo, compptr->quant_tbl_no);
|
||||
if (!cinfo->master->lossless) {
|
||||
/* Emit DQT for each quantization table.
|
||||
* Note that emit_dqt() suppresses any duplicate tables.
|
||||
*/
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
prec += emit_dqt(cinfo, compptr->quant_tbl_no);
|
||||
}
|
||||
/* now prec is nonzero iff there are any 16-bit quant tables. */
|
||||
}
|
||||
/* now prec is nonzero iff there are any 16-bit quant tables. */
|
||||
|
||||
/* Check for a non-baseline specification.
|
||||
* Note we assume that Huffman table numbers won't be changed later.
|
||||
*/
|
||||
if (cinfo->arith_code || cinfo->progressive_mode ||
|
||||
cinfo->data_precision != 8) {
|
||||
cinfo->master->lossless || cinfo->data_precision != 8) {
|
||||
is_baseline = FALSE;
|
||||
} else {
|
||||
is_baseline = TRUE;
|
||||
@ -540,6 +543,8 @@ write_frame_header(j_compress_ptr cinfo)
|
||||
} else {
|
||||
if (cinfo->progressive_mode)
|
||||
emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
|
||||
else if (cinfo->master->lossless)
|
||||
emit_sof(cinfo, M_SOF3); /* SOF code for lossless Huffman */
|
||||
else if (is_baseline)
|
||||
emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
|
||||
else
|
||||
@ -574,10 +579,11 @@ write_scan_header(j_compress_ptr cinfo)
|
||||
for (i = 0; i < cinfo->comps_in_scan; i++) {
|
||||
compptr = cinfo->cur_comp_info[i];
|
||||
/* DC needs no table for refinement scan */
|
||||
if (cinfo->Ss == 0 && cinfo->Ah == 0)
|
||||
if ((cinfo->Ss == 0 && cinfo->Ah == 0) || cinfo->master->lossless)
|
||||
emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
|
||||
/* AC needs no table when not present */
|
||||
if (cinfo->Se)
|
||||
/* AC needs no table when not present, and lossless mode uses only DC
|
||||
tables. */
|
||||
if (cinfo->Se && !cinfo->master->lossless)
|
||||
emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
|
||||
}
|
||||
}
|
||||
|
312
3rdparty/libjpeg-turbo/src/jcmaster.c
vendored
312
3rdparty/libjpeg-turbo/src/jcmaster.c
vendored
@ -4,8 +4,10 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Modified 2003-2010 by Guido Vollbeding.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2010, 2016, 2018, D. R. Commander.
|
||||
* Copyright (C) 2010, 2016, 2018, 2022-2024, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -18,40 +20,8 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jpegcomp.h"
|
||||
#include "jconfigint.h"
|
||||
|
||||
|
||||
/* Private state */
|
||||
|
||||
typedef enum {
|
||||
main_pass, /* input data, also do first output step */
|
||||
huff_opt_pass, /* Huffman code optimization pass */
|
||||
output_pass /* data output pass */
|
||||
} c_pass_type;
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_comp_master pub; /* public fields */
|
||||
|
||||
c_pass_type pass_type; /* the type of the current pass */
|
||||
|
||||
int pass_number; /* # of passes completed */
|
||||
int total_passes; /* total # of passes needed */
|
||||
|
||||
int scan_number; /* current index in scan_info[] */
|
||||
|
||||
/*
|
||||
* This is here so we can add libjpeg-turbo version/build information to the
|
||||
* global string table without introducing a new global symbol. Adding this
|
||||
* information to the global string table allows one to examine a binary
|
||||
* object and determine which version of libjpeg-turbo it was built from or
|
||||
* linked against.
|
||||
*/
|
||||
const char *jpeg_version;
|
||||
|
||||
} my_comp_master;
|
||||
|
||||
typedef my_comp_master *my_master_ptr;
|
||||
#include "jpegapicomp.h"
|
||||
#include "jcmaster.h"
|
||||
|
||||
|
||||
/*
|
||||
@ -69,15 +39,124 @@ GLOBAL(void)
|
||||
jpeg_calc_jpeg_dimensions(j_compress_ptr cinfo)
|
||||
/* Do computations that are needed before master selection phase */
|
||||
{
|
||||
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
|
||||
/* Hardwire it to "no scaling" */
|
||||
cinfo->jpeg_width = cinfo->image_width;
|
||||
cinfo->jpeg_height = cinfo->image_height;
|
||||
cinfo->min_DCT_h_scaled_size = DCTSIZE;
|
||||
cinfo->min_DCT_v_scaled_size = DCTSIZE;
|
||||
cinfo->min_DCT_h_scaled_size = data_unit;
|
||||
cinfo->min_DCT_v_scaled_size = data_unit;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
LOCAL(boolean)
|
||||
using_std_huff_tables(j_compress_ptr cinfo)
|
||||
{
|
||||
int i;
|
||||
|
||||
static const UINT8 bits_dc_luminance[17] = {
|
||||
/* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
static const UINT8 val_dc_luminance[] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
|
||||
};
|
||||
|
||||
static const UINT8 bits_dc_chrominance[17] = {
|
||||
/* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
|
||||
};
|
||||
static const UINT8 val_dc_chrominance[] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
|
||||
};
|
||||
|
||||
static const UINT8 bits_ac_luminance[17] = {
|
||||
/* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d
|
||||
};
|
||||
static const UINT8 val_ac_luminance[] = {
|
||||
0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
|
||||
0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
|
||||
0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
|
||||
0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
|
||||
0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
|
||||
0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
|
||||
0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
|
||||
0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
|
||||
0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
|
||||
0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
|
||||
0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
|
||||
0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
|
||||
0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
|
||||
0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
||||
0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
|
||||
0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
|
||||
0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
|
||||
0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
|
||||
0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
|
||||
0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
|
||||
0xf9, 0xfa
|
||||
};
|
||||
|
||||
static const UINT8 bits_ac_chrominance[17] = {
|
||||
/* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77
|
||||
};
|
||||
static const UINT8 val_ac_chrominance[] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
|
||||
0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
|
||||
0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
|
||||
0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
|
||||
0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
|
||||
0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
|
||||
0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
|
||||
0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
|
||||
0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
|
||||
0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
|
||||
0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
|
||||
0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
|
||||
0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
|
||||
0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
|
||||
0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
|
||||
0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
|
||||
0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
|
||||
0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
|
||||
0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
|
||||
0xf9, 0xfa
|
||||
};
|
||||
|
||||
if (cinfo->dc_huff_tbl_ptrs[0] == NULL ||
|
||||
cinfo->ac_huff_tbl_ptrs[0] == NULL ||
|
||||
cinfo->dc_huff_tbl_ptrs[1] == NULL ||
|
||||
cinfo->ac_huff_tbl_ptrs[1] == NULL)
|
||||
return FALSE;
|
||||
|
||||
for (i = 2; i < NUM_HUFF_TBLS; i++) {
|
||||
if (cinfo->dc_huff_tbl_ptrs[i] != NULL ||
|
||||
cinfo->ac_huff_tbl_ptrs[i] != NULL)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (memcmp(cinfo->dc_huff_tbl_ptrs[0]->bits, bits_dc_luminance,
|
||||
sizeof(bits_dc_luminance)) ||
|
||||
memcmp(cinfo->dc_huff_tbl_ptrs[0]->huffval, val_dc_luminance,
|
||||
sizeof(val_dc_luminance)) ||
|
||||
memcmp(cinfo->ac_huff_tbl_ptrs[0]->bits, bits_ac_luminance,
|
||||
sizeof(bits_ac_luminance)) ||
|
||||
memcmp(cinfo->ac_huff_tbl_ptrs[0]->huffval, val_ac_luminance,
|
||||
sizeof(val_ac_luminance)) ||
|
||||
memcmp(cinfo->dc_huff_tbl_ptrs[1]->bits, bits_dc_chrominance,
|
||||
sizeof(bits_dc_chrominance)) ||
|
||||
memcmp(cinfo->dc_huff_tbl_ptrs[1]->huffval, val_dc_chrominance,
|
||||
sizeof(val_dc_chrominance)) ||
|
||||
memcmp(cinfo->ac_huff_tbl_ptrs[1]->bits, bits_ac_chrominance,
|
||||
sizeof(bits_ac_chrominance)) ||
|
||||
memcmp(cinfo->ac_huff_tbl_ptrs[1]->huffval, val_ac_chrominance,
|
||||
sizeof(val_ac_chrominance)))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
initial_setup(j_compress_ptr cinfo, boolean transcode_only)
|
||||
/* Do computations that are needed before master selection phase */
|
||||
@ -86,6 +165,7 @@ initial_setup(j_compress_ptr cinfo, boolean transcode_only)
|
||||
jpeg_component_info *compptr;
|
||||
long samplesperrow;
|
||||
JDIMENSION jd_samplesperrow;
|
||||
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
|
||||
#if JPEG_LIB_VERSION >= 70
|
||||
#if JPEG_LIB_VERSION >= 80
|
||||
@ -110,8 +190,12 @@ initial_setup(j_compress_ptr cinfo, boolean transcode_only)
|
||||
if ((long)jd_samplesperrow != samplesperrow)
|
||||
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
||||
|
||||
/* For now, precision must match compiled-in value... */
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
if (cinfo->data_precision != 8 && cinfo->data_precision != 12 &&
|
||||
cinfo->data_precision != 16)
|
||||
#else
|
||||
if (cinfo->data_precision != 8 && cinfo->data_precision != 12)
|
||||
#endif
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
/* Check that number of components won't exceed internal array sizes */
|
||||
@ -142,17 +226,17 @@ initial_setup(j_compress_ptr cinfo, boolean transcode_only)
|
||||
compptr->component_index = ci;
|
||||
/* For compression, we never do DCT scaling. */
|
||||
#if JPEG_LIB_VERSION >= 70
|
||||
compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = DCTSIZE;
|
||||
compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = data_unit;
|
||||
#else
|
||||
compptr->DCT_scaled_size = DCTSIZE;
|
||||
compptr->DCT_scaled_size = data_unit;
|
||||
#endif
|
||||
/* Size in DCT blocks */
|
||||
/* Size in data units */
|
||||
compptr->width_in_blocks = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->_jpeg_width * (long)compptr->h_samp_factor,
|
||||
(long)(cinfo->max_h_samp_factor * DCTSIZE));
|
||||
(long)(cinfo->max_h_samp_factor * data_unit));
|
||||
compptr->height_in_blocks = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->_jpeg_height * (long)compptr->v_samp_factor,
|
||||
(long)(cinfo->max_v_samp_factor * DCTSIZE));
|
||||
(long)(cinfo->max_v_samp_factor * data_unit));
|
||||
/* Size in samples */
|
||||
compptr->downsampled_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->_jpeg_width * (long)compptr->h_samp_factor,
|
||||
@ -165,15 +249,19 @@ initial_setup(j_compress_ptr cinfo, boolean transcode_only)
|
||||
}
|
||||
|
||||
/* Compute number of fully interleaved MCU rows (number of times that
|
||||
* main controller will call coefficient controller).
|
||||
* main controller will call coefficient or difference controller).
|
||||
*/
|
||||
cinfo->total_iMCU_rows = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->_jpeg_height,
|
||||
(long)(cinfo->max_v_samp_factor * DCTSIZE));
|
||||
(long)(cinfo->max_v_samp_factor * data_unit));
|
||||
}
|
||||
|
||||
|
||||
#ifdef C_MULTISCAN_FILES_SUPPORTED
|
||||
#if defined(C_MULTISCAN_FILES_SUPPORTED) || defined(C_LOSSLESS_SUPPORTED)
|
||||
#define NEED_SCAN_SCRIPT
|
||||
#endif
|
||||
|
||||
#ifdef NEED_SCAN_SCRIPT
|
||||
|
||||
LOCAL(void)
|
||||
validate_script(j_compress_ptr cinfo)
|
||||
@ -194,13 +282,29 @@ validate_script(j_compress_ptr cinfo)
|
||||
if (cinfo->num_scans <= 0)
|
||||
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
|
||||
|
||||
#ifndef C_MULTISCAN_FILES_SUPPORTED
|
||||
if (cinfo->num_scans > 1)
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
|
||||
scanptr = cinfo->scan_info;
|
||||
if (scanptr->Ss != 0 && scanptr->Se == 0) {
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
cinfo->master->lossless = TRUE;
|
||||
cinfo->progressive_mode = FALSE;
|
||||
for (ci = 0; ci < cinfo->num_components; ci++)
|
||||
component_sent[ci] = FALSE;
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
}
|
||||
/* For sequential JPEG, all scans must have Ss=0, Se=DCTSIZE2-1;
|
||||
* for progressive JPEG, no scan can have this.
|
||||
*/
|
||||
scanptr = cinfo->scan_info;
|
||||
if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2 - 1) {
|
||||
else if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2 - 1) {
|
||||
#ifdef C_PROGRESSIVE_SUPPORTED
|
||||
cinfo->progressive_mode = TRUE;
|
||||
cinfo->master->lossless = FALSE;
|
||||
last_bitpos_ptr = &last_bitpos[0][0];
|
||||
for (ci = 0; ci < cinfo->num_components; ci++)
|
||||
for (coefi = 0; coefi < DCTSIZE2; coefi++)
|
||||
@ -209,7 +313,7 @@ validate_script(j_compress_ptr cinfo)
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
} else {
|
||||
cinfo->progressive_mode = FALSE;
|
||||
cinfo->progressive_mode = cinfo->master->lossless = FALSE;
|
||||
for (ci = 0; ci < cinfo->num_components; ci++)
|
||||
component_sent[ci] = FALSE;
|
||||
}
|
||||
@ -241,13 +345,10 @@ validate_script(j_compress_ptr cinfo)
|
||||
* out-of-range reconstructed DC values during the first DC scan,
|
||||
* which might cause problems for some decoders.
|
||||
*/
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
#define MAX_AH_AL 10
|
||||
#else
|
||||
#define MAX_AH_AL 13
|
||||
#endif
|
||||
int max_Ah_Al = cinfo->data_precision == 12 ? 13 : 10;
|
||||
|
||||
if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
|
||||
Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
|
||||
Ah < 0 || Ah > max_Ah_Al || Al < 0 || Al > max_Ah_Al)
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
if (Ss == 0) {
|
||||
if (Se != 0) /* DC and AC together not OK */
|
||||
@ -275,9 +376,25 @@ validate_script(j_compress_ptr cinfo)
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
/* For sequential JPEG, all progression parameters must be these: */
|
||||
if (Ss != 0 || Se != DCTSIZE2 - 1 || Ah != 0 || Al != 0)
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
if (cinfo->master->lossless) {
|
||||
/* The JPEG spec simply gives the range 0..15 for Al (Pt), but that
|
||||
* seems wrong: the upper bound ought to depend on data precision.
|
||||
* Perhaps they really meant 0..N-1 for N-bit precision, which is what
|
||||
* we allow here. Values greater than or equal to the data precision
|
||||
* will result in a blank image.
|
||||
*/
|
||||
if (Ss < 1 || Ss > 7 || /* predictor selection value */
|
||||
Se != 0 || Ah != 0 ||
|
||||
Al < 0 || Al >= cinfo->data_precision) /* point transform */
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/* For sequential JPEG, all progression parameters must be these: */
|
||||
if (Ss != 0 || Se != DCTSIZE2 - 1 || Ah != 0 || Al != 0)
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
}
|
||||
/* Make sure components are not sent twice */
|
||||
for (ci = 0; ci < ncomps; ci++) {
|
||||
thisi = scanptr->component_index[ci];
|
||||
@ -309,7 +426,7 @@ validate_script(j_compress_ptr cinfo)
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* C_MULTISCAN_FILES_SUPPORTED */
|
||||
#endif /* NEED_SCAN_SCRIPT */
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
@ -318,7 +435,7 @@ select_scan_parameters(j_compress_ptr cinfo)
|
||||
{
|
||||
int ci;
|
||||
|
||||
#ifdef C_MULTISCAN_FILES_SUPPORTED
|
||||
#ifdef NEED_SCAN_SCRIPT
|
||||
if (cinfo->scan_info != NULL) {
|
||||
/* Prepare for current scan --- the script is already validated */
|
||||
my_master_ptr master = (my_master_ptr)cinfo->master;
|
||||
@ -344,10 +461,12 @@ select_scan_parameters(j_compress_ptr cinfo)
|
||||
for (ci = 0; ci < cinfo->num_components; ci++) {
|
||||
cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
|
||||
}
|
||||
cinfo->Ss = 0;
|
||||
cinfo->Se = DCTSIZE2 - 1;
|
||||
cinfo->Ah = 0;
|
||||
cinfo->Al = 0;
|
||||
if (!cinfo->master->lossless) {
|
||||
cinfo->Ss = 0;
|
||||
cinfo->Se = DCTSIZE2 - 1;
|
||||
cinfo->Ah = 0;
|
||||
cinfo->Al = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -359,6 +478,7 @@ per_scan_setup(j_compress_ptr cinfo)
|
||||
{
|
||||
int ci, mcublks, tmp;
|
||||
jpeg_component_info *compptr;
|
||||
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
|
||||
if (cinfo->comps_in_scan == 1) {
|
||||
|
||||
@ -373,7 +493,7 @@ per_scan_setup(j_compress_ptr cinfo)
|
||||
compptr->MCU_width = 1;
|
||||
compptr->MCU_height = 1;
|
||||
compptr->MCU_blocks = 1;
|
||||
compptr->MCU_sample_width = DCTSIZE;
|
||||
compptr->MCU_sample_width = data_unit;
|
||||
compptr->last_col_width = 1;
|
||||
/* For noninterleaved scans, it is convenient to define last_row_height
|
||||
* as the number of block rows present in the last iMCU row.
|
||||
@ -396,10 +516,10 @@ per_scan_setup(j_compress_ptr cinfo)
|
||||
/* Overall image size in MCUs */
|
||||
cinfo->MCUs_per_row = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->_jpeg_width,
|
||||
(long)(cinfo->max_h_samp_factor * DCTSIZE));
|
||||
(long)(cinfo->max_h_samp_factor * data_unit));
|
||||
cinfo->MCU_rows_in_scan = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->_jpeg_height,
|
||||
(long)(cinfo->max_v_samp_factor * DCTSIZE));
|
||||
(long)(cinfo->max_v_samp_factor * data_unit));
|
||||
|
||||
cinfo->blocks_in_MCU = 0;
|
||||
|
||||
@ -409,7 +529,7 @@ per_scan_setup(j_compress_ptr cinfo)
|
||||
compptr->MCU_width = compptr->h_samp_factor;
|
||||
compptr->MCU_height = compptr->v_samp_factor;
|
||||
compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
|
||||
compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
|
||||
compptr->MCU_sample_width = compptr->MCU_width * data_unit;
|
||||
/* Figure number of non-dummy blocks in last MCU column & row */
|
||||
tmp = (int)(compptr->width_in_blocks % compptr->MCU_width);
|
||||
if (tmp == 0) tmp = compptr->MCU_width;
|
||||
@ -481,7 +601,8 @@ prepare_for_pass(j_compress_ptr cinfo)
|
||||
/* Do Huffman optimization for a scan after the first one. */
|
||||
select_scan_parameters(cinfo);
|
||||
per_scan_setup(cinfo);
|
||||
if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
|
||||
if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code ||
|
||||
cinfo->master->lossless) {
|
||||
(*cinfo->entropy->start_pass) (cinfo, TRUE);
|
||||
(*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
|
||||
master->pub.call_pass_startup = FALSE;
|
||||
@ -590,22 +711,17 @@ finish_pass_master(j_compress_ptr cinfo)
|
||||
GLOBAL(void)
|
||||
jinit_c_master_control(j_compress_ptr cinfo, boolean transcode_only)
|
||||
{
|
||||
my_master_ptr master;
|
||||
my_master_ptr master = (my_master_ptr)cinfo->master;
|
||||
boolean empty_huff_tables = TRUE;
|
||||
int i;
|
||||
|
||||
master = (my_master_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_comp_master));
|
||||
cinfo->master = (struct jpeg_comp_master *)master;
|
||||
master->pub.prepare_for_pass = prepare_for_pass;
|
||||
master->pub.pass_startup = pass_startup;
|
||||
master->pub.finish_pass = finish_pass_master;
|
||||
master->pub.is_last_pass = FALSE;
|
||||
|
||||
/* Validate parameters, determine derived values */
|
||||
initial_setup(cinfo, transcode_only);
|
||||
|
||||
if (cinfo->scan_info != NULL) {
|
||||
#ifdef C_MULTISCAN_FILES_SUPPORTED
|
||||
#ifdef NEED_SCAN_SCRIPT
|
||||
validate_script(cinfo);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
@ -615,8 +731,42 @@ jinit_c_master_control(j_compress_ptr cinfo, boolean transcode_only)
|
||||
cinfo->num_scans = 1;
|
||||
}
|
||||
|
||||
if (cinfo->progressive_mode && !cinfo->arith_code) /* TEMPORARY HACK ??? */
|
||||
cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
|
||||
/* Disable smoothing and subsampling in lossless mode, since those are lossy
|
||||
* algorithms. Set the JPEG colorspace to the input colorspace. Disable raw
|
||||
* (downsampled) data input, because it isn't particularly useful without
|
||||
* subsampling and has not been tested in lossless mode.
|
||||
*/
|
||||
if (cinfo->master->lossless) {
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
cinfo->raw_data_in = FALSE;
|
||||
cinfo->smoothing_factor = 0;
|
||||
jpeg_default_colorspace(cinfo);
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++)
|
||||
compptr->h_samp_factor = compptr->v_samp_factor = 1;
|
||||
}
|
||||
|
||||
/* Validate parameters, determine derived values */
|
||||
initial_setup(cinfo, transcode_only);
|
||||
|
||||
if (cinfo->master->lossless || /* TEMPORARY HACK ??? */
|
||||
(cinfo->progressive_mode && !cinfo->arith_code))
|
||||
cinfo->optimize_coding = TRUE; /* assume default tables no good for
|
||||
progressive mode or lossless mode */
|
||||
for (i = 0; i < NUM_HUFF_TBLS; i++) {
|
||||
if (cinfo->dc_huff_tbl_ptrs[i] != NULL ||
|
||||
cinfo->ac_huff_tbl_ptrs[i] != NULL) {
|
||||
empty_huff_tables = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cinfo->data_precision == 12 && !cinfo->arith_code &&
|
||||
!cinfo->optimize_coding &&
|
||||
(empty_huff_tables || using_std_huff_tables(cinfo)))
|
||||
cinfo->optimize_coding = TRUE; /* assume default tables no good for 12-bit
|
||||
data precision */
|
||||
|
||||
/* Initialize my private state */
|
||||
if (transcode_only) {
|
||||
|
43
3rdparty/libjpeg-turbo/src/jcmaster.h
vendored
Normal file
43
3rdparty/libjpeg-turbo/src/jcmaster.h
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* jcmaster.h
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2016, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file contains master control structure for the JPEG compressor.
|
||||
*/
|
||||
|
||||
/* Private state */
|
||||
|
||||
typedef enum {
|
||||
main_pass, /* input data, also do first output step */
|
||||
huff_opt_pass, /* Huffman code optimization pass */
|
||||
output_pass /* data output pass */
|
||||
} c_pass_type;
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_comp_master pub; /* public fields */
|
||||
|
||||
c_pass_type pass_type; /* the type of the current pass */
|
||||
|
||||
int pass_number; /* # of passes completed */
|
||||
int total_passes; /* total # of passes needed */
|
||||
|
||||
int scan_number; /* current index in scan_info[] */
|
||||
|
||||
/*
|
||||
* This is here so we can add libjpeg-turbo version/build information to the
|
||||
* global string table without introducing a new global symbol. Adding this
|
||||
* information to the global string table allows one to examine a binary
|
||||
* object and determine which version of libjpeg-turbo it was built from or
|
||||
* linked against.
|
||||
*/
|
||||
const char *jpeg_version;
|
||||
|
||||
} my_comp_master;
|
||||
|
||||
typedef my_comp_master *my_master_ptr;
|
52
3rdparty/libjpeg-turbo/src/jcparam.c
vendored
52
3rdparty/libjpeg-turbo/src/jcparam.c
vendored
@ -4,8 +4,10 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* Modified 2003-2008 by Guido Vollbeding.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2009-2011, 2018, D. R. Commander.
|
||||
* Copyright (C) 2009-2011, 2018, 2023, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -202,7 +204,6 @@ jpeg_set_defaults(j_compress_ptr cinfo)
|
||||
cinfo->scale_num = 1; /* 1:1 scaling */
|
||||
cinfo->scale_denom = 1;
|
||||
#endif
|
||||
cinfo->data_precision = BITS_IN_JSAMPLE;
|
||||
/* Set up two quantization tables using default quality of 75 */
|
||||
jpeg_set_quality(cinfo, 75, TRUE);
|
||||
/* Set up two Huffman tables */
|
||||
@ -232,7 +233,7 @@ jpeg_set_defaults(j_compress_ptr cinfo)
|
||||
* tables will be computed. This test can be removed if default tables
|
||||
* are supplied that are valid for the desired precision.
|
||||
*/
|
||||
if (cinfo->data_precision > 8)
|
||||
if (cinfo->data_precision == 12 && !cinfo->arith_code)
|
||||
cinfo->optimize_coding = TRUE;
|
||||
|
||||
/* By default, use the simpler non-cosited sampling alignment */
|
||||
@ -296,7 +297,10 @@ jpeg_default_colorspace(j_compress_ptr cinfo)
|
||||
case JCS_EXT_BGRA:
|
||||
case JCS_EXT_ABGR:
|
||||
case JCS_EXT_ARGB:
|
||||
jpeg_set_colorspace(cinfo, JCS_YCbCr);
|
||||
if (cinfo->master->lossless)
|
||||
jpeg_set_colorspace(cinfo, JCS_RGB);
|
||||
else
|
||||
jpeg_set_colorspace(cinfo, JCS_YCbCr);
|
||||
break;
|
||||
case JCS_YCbCr:
|
||||
jpeg_set_colorspace(cinfo, JCS_YCbCr);
|
||||
@ -475,6 +479,11 @@ jpeg_simple_progression(j_compress_ptr cinfo)
|
||||
if (cinfo->global_state != CSTATE_START)
|
||||
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
||||
|
||||
if (cinfo->master->lossless) {
|
||||
cinfo->master->lossless = FALSE;
|
||||
jpeg_default_colorspace(cinfo);
|
||||
}
|
||||
|
||||
/* Figure space needed for script. Calculation must match code below! */
|
||||
if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
|
||||
/* Custom script for YCbCr color images. */
|
||||
@ -539,3 +548,38 @@ jpeg_simple_progression(j_compress_ptr cinfo)
|
||||
}
|
||||
|
||||
#endif /* C_PROGRESSIVE_SUPPORTED */
|
||||
|
||||
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
|
||||
/*
|
||||
* Enable lossless mode.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_enable_lossless(j_compress_ptr cinfo, int predictor_selection_value,
|
||||
int point_transform)
|
||||
{
|
||||
/* Safety check to ensure start_compress not called yet. */
|
||||
if (cinfo->global_state != CSTATE_START)
|
||||
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
||||
|
||||
cinfo->master->lossless = TRUE;
|
||||
cinfo->Ss = predictor_selection_value;
|
||||
cinfo->Se = 0;
|
||||
cinfo->Ah = 0;
|
||||
cinfo->Al = point_transform;
|
||||
|
||||
/* The JPEG spec simply gives the range 0..15 for Al (Pt), but that seems
|
||||
* wrong: the upper bound ought to depend on data precision. Perhaps they
|
||||
* really meant 0..N-1 for N-bit precision, which is what we allow here.
|
||||
* Values greater than or equal to the data precision will result in a blank
|
||||
* image.
|
||||
*/
|
||||
if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
|
||||
cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
|
||||
ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
|
||||
cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
|
||||
}
|
||||
|
||||
#endif /* C_LOSSLESS_SUPPORTED */
|
||||
|
90
3rdparty/libjpeg-turbo/src/jcphuff.c
vendored
90
3rdparty/libjpeg-turbo/src/jcphuff.c
vendored
@ -3,9 +3,11 @@
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1995-1997, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2011, 2015, 2018, 2021-2022, D. R. Commander.
|
||||
* Copyright (C) 2016, 2018, Matthieu Darbois.
|
||||
* Copyright (C) 2011, 2015, 2018, 2021-2022, 2024, D. R. Commander.
|
||||
* Copyright (C) 2016, 2018, 2022, Matthieu Darbois.
|
||||
* Copyright (C) 2020, Arm Limited.
|
||||
* Copyright (C) 2021, Alex Richardson.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
@ -21,8 +23,11 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#ifdef WITH_SIMD
|
||||
#include "jsimd.h"
|
||||
#include "jconfigint.h"
|
||||
#else
|
||||
#include "jchuff.h" /* Declarations shared with jc*huff.c */
|
||||
#endif
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef HAVE_INTRIN_H
|
||||
@ -39,40 +44,7 @@
|
||||
|
||||
#ifdef C_PROGRESSIVE_SUPPORTED
|
||||
|
||||
/*
|
||||
* NOTE: If USE_CLZ_INTRINSIC is defined, then clz/bsr instructions will be
|
||||
* used for bit counting rather than the lookup table. This will reduce the
|
||||
* memory footprint by 64k, which is important for some mobile applications
|
||||
* that create many isolated instances of libjpeg-turbo (web browsers, for
|
||||
* instance.) This may improve performance on some mobile platforms as well.
|
||||
* This feature is enabled by default only on Arm processors, because some x86
|
||||
* chips have a slow implementation of bsr, and the use of clz/bsr cannot be
|
||||
* shown to have a significant performance impact even on the x86 chips that
|
||||
* have a fast implementation of it. When building for Armv6, you can
|
||||
* explicitly disable the use of clz/bsr by adding -mthumb to the compiler
|
||||
* flags (this defines __thumb__).
|
||||
*/
|
||||
|
||||
/* NOTE: Both GCC and Clang define __GNUC__ */
|
||||
#if (defined(__GNUC__) && (defined(__arm__) || defined(__aarch64__))) || \
|
||||
defined(_M_ARM) || defined(_M_ARM64)
|
||||
#if !defined(__thumb__) || defined(__thumb2__)
|
||||
#define USE_CLZ_INTRINSIC
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_CLZ_INTRINSIC
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#define JPEG_NBITS_NONZERO(x) (32 - _CountLeadingZeros(x))
|
||||
#else
|
||||
#define JPEG_NBITS_NONZERO(x) (32 - __builtin_clz(x))
|
||||
#endif
|
||||
#define JPEG_NBITS(x) (x ? JPEG_NBITS_NONZERO(x) : 0)
|
||||
#else
|
||||
#include "jpeg_nbits_table.h"
|
||||
#define JPEG_NBITS(x) (jpeg_nbits_table[x])
|
||||
#define JPEG_NBITS_NONZERO(x) JPEG_NBITS(x)
|
||||
#endif
|
||||
#include "jpeg_nbits.h"
|
||||
|
||||
|
||||
/* Expanded entropy encoder object for progressive Huffman encoding. */
|
||||
@ -83,11 +55,11 @@ typedef struct {
|
||||
/* Pointer to routine to prepare data for encode_mcu_AC_first() */
|
||||
void (*AC_first_prepare) (const JCOEF *block,
|
||||
const int *jpeg_natural_order_start, int Sl,
|
||||
int Al, JCOEF *values, size_t *zerobits);
|
||||
int Al, UJCOEF *values, size_t *zerobits);
|
||||
/* Pointer to routine to prepare data for encode_mcu_AC_refine() */
|
||||
int (*AC_refine_prepare) (const JCOEF *block,
|
||||
const int *jpeg_natural_order_start, int Sl,
|
||||
int Al, JCOEF *absvalues, size_t *bits);
|
||||
int Al, UJCOEF *absvalues, size_t *bits);
|
||||
|
||||
/* Mode flag: TRUE for optimization, FALSE for actual data output */
|
||||
boolean gather_statistics;
|
||||
@ -157,14 +129,14 @@ METHODDEF(boolean) encode_mcu_DC_first(j_compress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data);
|
||||
METHODDEF(void) encode_mcu_AC_first_prepare
|
||||
(const JCOEF *block, const int *jpeg_natural_order_start, int Sl, int Al,
|
||||
JCOEF *values, size_t *zerobits);
|
||||
UJCOEF *values, size_t *zerobits);
|
||||
METHODDEF(boolean) encode_mcu_AC_first(j_compress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data);
|
||||
METHODDEF(boolean) encode_mcu_DC_refine(j_compress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data);
|
||||
METHODDEF(int) encode_mcu_AC_refine_prepare
|
||||
(const JCOEF *block, const int *jpeg_natural_order_start, int Sl, int Al,
|
||||
JCOEF *absvalues, size_t *bits);
|
||||
UJCOEF *absvalues, size_t *bits);
|
||||
METHODDEF(boolean) encode_mcu_AC_refine(j_compress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data);
|
||||
METHODDEF(void) finish_pass_phuff(j_compress_ptr cinfo);
|
||||
@ -224,18 +196,22 @@ start_pass_phuff(j_compress_ptr cinfo, boolean gather_statistics)
|
||||
entropy->pub.encode_mcu = encode_mcu_DC_first;
|
||||
else
|
||||
entropy->pub.encode_mcu = encode_mcu_AC_first;
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_encode_mcu_AC_first_prepare())
|
||||
entropy->AC_first_prepare = jsimd_encode_mcu_AC_first_prepare;
|
||||
else
|
||||
#endif
|
||||
entropy->AC_first_prepare = encode_mcu_AC_first_prepare;
|
||||
} else {
|
||||
if (is_DC_band)
|
||||
entropy->pub.encode_mcu = encode_mcu_DC_refine;
|
||||
else {
|
||||
entropy->pub.encode_mcu = encode_mcu_AC_refine;
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_encode_mcu_AC_refine_prepare())
|
||||
entropy->AC_refine_prepare = jsimd_encode_mcu_AC_refine_prepare;
|
||||
else
|
||||
#endif
|
||||
entropy->AC_refine_prepare = encode_mcu_AC_refine_prepare;
|
||||
/* AC refinement needs a correction bit buffer */
|
||||
if (entropy->bit_buffer == NULL)
|
||||
@ -490,6 +466,7 @@ encode_mcu_DC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
JBLOCKROW block;
|
||||
jpeg_component_info *compptr;
|
||||
ISHIFT_TEMPS
|
||||
int max_coef_bits = cinfo->data_precision + 2;
|
||||
|
||||
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
||||
entropy->free_in_buffer = cinfo->dest->free_in_buffer;
|
||||
@ -532,7 +509,7 @@ encode_mcu_DC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
/* Check for out-of-range coefficient values.
|
||||
* Since we're encoding a difference, the range limit is twice as much.
|
||||
*/
|
||||
if (nbits > MAX_COEF_BITS + 1)
|
||||
if (nbits > max_coef_bits + 1)
|
||||
ERREXIT(cinfo, JERR_BAD_DCT_COEF);
|
||||
|
||||
/* Count/emit the Huffman-coded symbol for the number of bits */
|
||||
@ -584,8 +561,8 @@ encode_mcu_DC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
continue; \
|
||||
/* For a negative coef, want temp2 = bitwise complement of abs(coef) */ \
|
||||
temp2 ^= temp; \
|
||||
values[k] = (JCOEF)temp; \
|
||||
values[k + DCTSIZE2] = (JCOEF)temp2; \
|
||||
values[k] = (UJCOEF)temp; \
|
||||
values[k + DCTSIZE2] = (UJCOEF)temp2; \
|
||||
zerobits |= ((size_t)1U) << k; \
|
||||
} \
|
||||
}
|
||||
@ -593,7 +570,7 @@ encode_mcu_DC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
METHODDEF(void)
|
||||
encode_mcu_AC_first_prepare(const JCOEF *block,
|
||||
const int *jpeg_natural_order_start, int Sl,
|
||||
int Al, JCOEF *values, size_t *bits)
|
||||
int Al, UJCOEF *values, size_t *bits)
|
||||
{
|
||||
register int k, temp, temp2;
|
||||
size_t zerobits = 0U;
|
||||
@ -643,7 +620,7 @@ label \
|
||||
/* Find the number of bits needed for the magnitude of the coefficient */ \
|
||||
nbits = JPEG_NBITS_NONZERO(temp); /* there must be at least one 1 bit */ \
|
||||
/* Check for out-of-range coefficient values */ \
|
||||
if (nbits > MAX_COEF_BITS) \
|
||||
if (nbits > max_coef_bits) \
|
||||
ERREXIT(cinfo, JERR_BAD_DCT_COEF); \
|
||||
\
|
||||
/* Count/emit Huffman symbol for run length / number of bits */ \
|
||||
@ -666,11 +643,12 @@ encode_mcu_AC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
register int nbits, r;
|
||||
int Sl = cinfo->Se - cinfo->Ss + 1;
|
||||
int Al = cinfo->Al;
|
||||
JCOEF values_unaligned[2 * DCTSIZE2 + 15];
|
||||
JCOEF *values;
|
||||
const JCOEF *cvalue;
|
||||
UJCOEF values_unaligned[2 * DCTSIZE2 + 15];
|
||||
UJCOEF *values;
|
||||
const UJCOEF *cvalue;
|
||||
size_t zerobits;
|
||||
size_t bits[8 / SIZEOF_SIZE_T];
|
||||
int max_coef_bits = cinfo->data_precision + 2;
|
||||
|
||||
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
||||
entropy->free_in_buffer = cinfo->dest->free_in_buffer;
|
||||
@ -681,7 +659,7 @@ encode_mcu_AC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
emit_restart(entropy, entropy->next_restart_num);
|
||||
|
||||
#ifdef WITH_SIMD
|
||||
cvalue = values = (JCOEF *)PAD((JUINTPTR)values_unaligned, 16);
|
||||
cvalue = values = (UJCOEF *)PAD((JUINTPTR)values_unaligned, 16);
|
||||
#else
|
||||
/* Not using SIMD, so alignment is not needed */
|
||||
cvalue = values = values_unaligned;
|
||||
@ -815,7 +793,7 @@ encode_mcu_DC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
zerobits |= ((size_t)1U) << k; \
|
||||
signbits |= ((size_t)(temp2 + 1)) << k; \
|
||||
} \
|
||||
absvalues[k] = (JCOEF)temp; /* save abs value for main pass */ \
|
||||
absvalues[k] = (UJCOEF)temp; /* save abs value for main pass */ \
|
||||
if (temp == 1) \
|
||||
EOB = k + koffset; /* EOB = index of last newly-nonzero coef */ \
|
||||
} \
|
||||
@ -824,7 +802,7 @@ encode_mcu_DC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
METHODDEF(int)
|
||||
encode_mcu_AC_refine_prepare(const JCOEF *block,
|
||||
const int *jpeg_natural_order_start, int Sl,
|
||||
int Al, JCOEF *absvalues, size_t *bits)
|
||||
int Al, UJCOEF *absvalues, size_t *bits)
|
||||
{
|
||||
register int k, temp, temp2;
|
||||
int EOB = 0;
|
||||
@ -931,9 +909,9 @@ encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
unsigned int BR;
|
||||
int Sl = cinfo->Se - cinfo->Ss + 1;
|
||||
int Al = cinfo->Al;
|
||||
JCOEF absvalues_unaligned[DCTSIZE2 + 15];
|
||||
JCOEF *absvalues;
|
||||
const JCOEF *cabsvalue, *EOBPTR;
|
||||
UJCOEF absvalues_unaligned[DCTSIZE2 + 15];
|
||||
UJCOEF *absvalues;
|
||||
const UJCOEF *cabsvalue, *EOBPTR;
|
||||
size_t zerobits, signbits;
|
||||
size_t bits[16 / SIZEOF_SIZE_T];
|
||||
|
||||
@ -946,7 +924,7 @@ encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
emit_restart(entropy, entropy->next_restart_num);
|
||||
|
||||
#ifdef WITH_SIMD
|
||||
cabsvalue = absvalues = (JCOEF *)PAD((JUINTPTR)absvalues_unaligned, 16);
|
||||
cabsvalue = absvalues = (UJCOEF *)PAD((JUINTPTR)absvalues_unaligned, 16);
|
||||
#else
|
||||
/* Not using SIMD, so alignment is not needed */
|
||||
cabsvalue = absvalues = absvalues_unaligned;
|
||||
|
88
3rdparty/libjpeg-turbo/src/jcprepct.c
vendored
88
3rdparty/libjpeg-turbo/src/jcprepct.c
vendored
@ -1,8 +1,10 @@
|
||||
/*
|
||||
* jcprepct.c
|
||||
*
|
||||
* This file is part of the Independent JPEG Group's software:
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
@ -20,8 +22,11 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)
|
||||
|
||||
/* At present, jcsample.c can request context rows only for smoothing.
|
||||
* In the future, we might also need context rows for CCIR601 sampling
|
||||
* or other more-complex downsampling procedures. The code to support
|
||||
@ -59,7 +64,7 @@ typedef struct {
|
||||
/* Downsampling input buffer. This buffer holds color-converted data
|
||||
* until we have enough to do a downsample step.
|
||||
*/
|
||||
JSAMPARRAY color_buf[MAX_COMPONENTS];
|
||||
_JSAMPARRAY color_buf[MAX_COMPONENTS];
|
||||
|
||||
JDIMENSION rows_to_go; /* counts rows remaining in source image */
|
||||
int next_buf_row; /* index of next row to store in color_buf */
|
||||
@ -106,14 +111,14 @@ start_pass_prep(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
*/
|
||||
|
||||
LOCAL(void)
|
||||
expand_bottom_edge(JSAMPARRAY image_data, JDIMENSION num_cols, int input_rows,
|
||||
expand_bottom_edge(_JSAMPARRAY image_data, JDIMENSION num_cols, int input_rows,
|
||||
int output_rows)
|
||||
{
|
||||
register int row;
|
||||
|
||||
for (row = input_rows; row < output_rows; row++) {
|
||||
jcopy_sample_rows(image_data, input_rows - 1, image_data, row, 1,
|
||||
num_cols);
|
||||
_jcopy_sample_rows(image_data, input_rows - 1, image_data, row, 1,
|
||||
num_cols);
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,15 +133,16 @@ expand_bottom_edge(JSAMPARRAY image_data, JDIMENSION num_cols, int input_rows,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
pre_process_data(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
pre_process_data(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail,
|
||||
JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
|
||||
_JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
|
||||
JDIMENSION out_row_groups_avail)
|
||||
{
|
||||
my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
|
||||
int numrows, ci;
|
||||
JDIMENSION inrows;
|
||||
jpeg_component_info *compptr;
|
||||
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
|
||||
while (*in_row_ctr < in_rows_avail &&
|
||||
*out_row_group_ctr < out_row_groups_avail) {
|
||||
@ -144,10 +150,10 @@ pre_process_data(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
inrows = in_rows_avail - *in_row_ctr;
|
||||
numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
|
||||
numrows = (int)MIN((JDIMENSION)numrows, inrows);
|
||||
(*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
|
||||
prep->color_buf,
|
||||
(JDIMENSION)prep->next_buf_row,
|
||||
numrows);
|
||||
(*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
|
||||
prep->color_buf,
|
||||
(JDIMENSION)prep->next_buf_row,
|
||||
numrows);
|
||||
*in_row_ctr += numrows;
|
||||
prep->next_buf_row += numrows;
|
||||
prep->rows_to_go -= numrows;
|
||||
@ -162,9 +168,9 @@ pre_process_data(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
}
|
||||
/* If we've filled the conversion buffer, empty it. */
|
||||
if (prep->next_buf_row == cinfo->max_v_samp_factor) {
|
||||
(*cinfo->downsample->downsample) (cinfo,
|
||||
prep->color_buf, (JDIMENSION)0,
|
||||
output_buf, *out_row_group_ctr);
|
||||
(*cinfo->downsample->_downsample) (cinfo,
|
||||
prep->color_buf, (JDIMENSION)0,
|
||||
output_buf, *out_row_group_ctr);
|
||||
prep->next_buf_row = 0;
|
||||
(*out_row_group_ctr)++;
|
||||
}
|
||||
@ -174,7 +180,8 @@ pre_process_data(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
if (prep->rows_to_go == 0 && *out_row_group_ctr < out_row_groups_avail) {
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
expand_bottom_edge(output_buf[ci], compptr->width_in_blocks * DCTSIZE,
|
||||
expand_bottom_edge(output_buf[ci],
|
||||
compptr->width_in_blocks * data_unit,
|
||||
(int)(*out_row_group_ctr * compptr->v_samp_factor),
|
||||
(int)(out_row_groups_avail * compptr->v_samp_factor));
|
||||
}
|
||||
@ -192,9 +199,9 @@ pre_process_data(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
pre_process_context(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
pre_process_context(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail,
|
||||
JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
|
||||
_JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
|
||||
JDIMENSION out_row_groups_avail)
|
||||
{
|
||||
my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
|
||||
@ -208,17 +215,17 @@ pre_process_context(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
inrows = in_rows_avail - *in_row_ctr;
|
||||
numrows = prep->next_buf_stop - prep->next_buf_row;
|
||||
numrows = (int)MIN((JDIMENSION)numrows, inrows);
|
||||
(*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
|
||||
prep->color_buf,
|
||||
(JDIMENSION)prep->next_buf_row,
|
||||
numrows);
|
||||
(*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
|
||||
prep->color_buf,
|
||||
(JDIMENSION)prep->next_buf_row,
|
||||
numrows);
|
||||
/* Pad at top of image, if first time through */
|
||||
if (prep->rows_to_go == cinfo->image_height) {
|
||||
for (ci = 0; ci < cinfo->num_components; ci++) {
|
||||
int row;
|
||||
for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
|
||||
jcopy_sample_rows(prep->color_buf[ci], 0, prep->color_buf[ci],
|
||||
-row, 1, cinfo->image_width);
|
||||
_jcopy_sample_rows(prep->color_buf[ci], 0, prep->color_buf[ci],
|
||||
-row, 1, cinfo->image_width);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -240,9 +247,9 @@ pre_process_context(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
}
|
||||
/* If we've gotten enough data, downsample a row group. */
|
||||
if (prep->next_buf_row == prep->next_buf_stop) {
|
||||
(*cinfo->downsample->downsample) (cinfo, prep->color_buf,
|
||||
(JDIMENSION)prep->this_row_group,
|
||||
output_buf, *out_row_group_ctr);
|
||||
(*cinfo->downsample->_downsample) (cinfo, prep->color_buf,
|
||||
(JDIMENSION)prep->this_row_group,
|
||||
output_buf, *out_row_group_ctr);
|
||||
(*out_row_group_ctr)++;
|
||||
/* Advance pointers with wraparound as necessary. */
|
||||
prep->this_row_group += cinfo->max_v_samp_factor;
|
||||
@ -267,15 +274,16 @@ create_context_buffer(j_compress_ptr cinfo)
|
||||
int rgroup_height = cinfo->max_v_samp_factor;
|
||||
int ci, i;
|
||||
jpeg_component_info *compptr;
|
||||
JSAMPARRAY true_buffer, fake_buffer;
|
||||
_JSAMPARRAY true_buffer, fake_buffer;
|
||||
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
|
||||
/* Grab enough space for fake row pointers for all the components;
|
||||
* we need five row groups' worth of pointers for each component.
|
||||
*/
|
||||
fake_buffer = (JSAMPARRAY)
|
||||
fake_buffer = (_JSAMPARRAY)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(cinfo->num_components * 5 * rgroup_height) *
|
||||
sizeof(JSAMPROW));
|
||||
sizeof(_JSAMPROW));
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
@ -283,14 +291,14 @@ create_context_buffer(j_compress_ptr cinfo)
|
||||
* We make the buffer wide enough to allow the downsampler to edge-expand
|
||||
* horizontally within the buffer, if it so chooses.
|
||||
*/
|
||||
true_buffer = (*cinfo->mem->alloc_sarray)
|
||||
true_buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION)(((long)compptr->width_in_blocks * DCTSIZE *
|
||||
(JDIMENSION)(((long)compptr->width_in_blocks * data_unit *
|
||||
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 */
|
||||
memcpy(fake_buffer + rgroup_height, true_buffer,
|
||||
3 * rgroup_height * sizeof(JSAMPROW));
|
||||
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];
|
||||
@ -309,11 +317,15 @@ create_context_buffer(j_compress_ptr cinfo)
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_c_prep_controller(j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
_jinit_c_prep_controller(j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_prep_ptr prep;
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
if (need_full_buffer) /* safety check */
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
@ -331,21 +343,23 @@ jinit_c_prep_controller(j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
if (cinfo->downsample->need_context_rows) {
|
||||
/* Set up to provide context rows */
|
||||
#ifdef CONTEXT_ROWS_SUPPORTED
|
||||
prep->pub.pre_process_data = pre_process_context;
|
||||
prep->pub._pre_process_data = pre_process_context;
|
||||
create_context_buffer(cinfo);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
} else {
|
||||
/* No context, just make it tall enough for one row group */
|
||||
prep->pub.pre_process_data = pre_process_data;
|
||||
prep->pub._pre_process_data = pre_process_data;
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
|
||||
prep->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION)(((long)compptr->width_in_blocks * DCTSIZE *
|
||||
(JDIMENSION)(((long)compptr->width_in_blocks * data_unit *
|
||||
cinfo->max_h_samp_factor) / compptr->h_samp_factor),
|
||||
(JDIMENSION)cinfo->max_v_samp_factor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */
|
||||
|
103
3rdparty/libjpeg-turbo/src/jcsample.c
vendored
103
3rdparty/libjpeg-turbo/src/jcsample.c
vendored
@ -3,10 +3,12 @@
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
||||
* Copyright (C) 2014, MIPS Technologies, Inc., California.
|
||||
* Copyright (C) 2015, 2019, D. R. Commander.
|
||||
* Copyright (C) 2015, 2019, 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -54,13 +56,16 @@
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jsimd.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)
|
||||
|
||||
/* Pointer to routine to downsample a single component */
|
||||
typedef void (*downsample1_ptr) (j_compress_ptr cinfo,
|
||||
jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data,
|
||||
JSAMPARRAY output_data);
|
||||
_JSAMPARRAY input_data,
|
||||
_JSAMPARRAY output_data);
|
||||
|
||||
/* Private subobject */
|
||||
|
||||
@ -91,11 +96,11 @@ start_pass_downsample(j_compress_ptr cinfo)
|
||||
*/
|
||||
|
||||
LOCAL(void)
|
||||
expand_right_edge(JSAMPARRAY image_data, int num_rows, JDIMENSION input_cols,
|
||||
expand_right_edge(_JSAMPARRAY image_data, int num_rows, JDIMENSION input_cols,
|
||||
JDIMENSION output_cols)
|
||||
{
|
||||
register JSAMPROW ptr;
|
||||
register JSAMPLE pixval;
|
||||
register _JSAMPROW ptr;
|
||||
register _JSAMPLE pixval;
|
||||
register int count;
|
||||
int row;
|
||||
int numcols = (int)(output_cols - input_cols);
|
||||
@ -118,14 +123,14 @@ expand_right_edge(JSAMPARRAY image_data, int num_rows, JDIMENSION input_cols,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
sep_downsample(j_compress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_index, JSAMPIMAGE output_buf,
|
||||
sep_downsample(j_compress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_index, _JSAMPIMAGE output_buf,
|
||||
JDIMENSION out_row_group_index)
|
||||
{
|
||||
my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample;
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
JSAMPARRAY in_ptr, out_ptr;
|
||||
_JSAMPARRAY in_ptr, out_ptr;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
@ -145,12 +150,13 @@ sep_downsample(j_compress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
METHODDEF(void)
|
||||
int_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
_JSAMPARRAY input_data, _JSAMPARRAY output_data)
|
||||
{
|
||||
int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
|
||||
JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
|
||||
JSAMPROW inptr, outptr;
|
||||
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
|
||||
_JSAMPROW inptr, outptr;
|
||||
JLONG outvalue;
|
||||
|
||||
h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
|
||||
@ -177,7 +183,7 @@ int_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
outvalue += (JLONG)(*inptr++);
|
||||
}
|
||||
}
|
||||
*outptr++ = (JSAMPLE)((outvalue + numpix2) / numpix);
|
||||
*outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix);
|
||||
}
|
||||
inrow += v_expand;
|
||||
}
|
||||
@ -192,14 +198,16 @@ int_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
fullsize_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
_JSAMPARRAY input_data, _JSAMPARRAY output_data)
|
||||
{
|
||||
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
|
||||
/* Copy the data */
|
||||
jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
|
||||
cinfo->image_width);
|
||||
_jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
|
||||
cinfo->image_width);
|
||||
/* Edge-expand */
|
||||
expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
|
||||
compptr->width_in_blocks * DCTSIZE);
|
||||
compptr->width_in_blocks * data_unit);
|
||||
}
|
||||
|
||||
|
||||
@ -217,12 +225,13 @@ fullsize_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
_JSAMPARRAY input_data, _JSAMPARRAY output_data)
|
||||
{
|
||||
int outrow;
|
||||
JDIMENSION outcol;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
|
||||
register JSAMPROW inptr, outptr;
|
||||
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
|
||||
register _JSAMPROW inptr, outptr;
|
||||
register int bias;
|
||||
|
||||
/* Expand input data enough to let all the output samples be generated
|
||||
@ -237,7 +246,7 @@ h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
inptr = input_data[outrow];
|
||||
bias = 0; /* bias = 0,1,0,1,... for successive samples */
|
||||
for (outcol = 0; outcol < output_cols; outcol++) {
|
||||
*outptr++ = (JSAMPLE)((inptr[0] + inptr[1] + bias) >> 1);
|
||||
*outptr++ = (_JSAMPLE)((inptr[0] + inptr[1] + bias) >> 1);
|
||||
bias ^= 1; /* 0=>1, 1=>0 */
|
||||
inptr += 2;
|
||||
}
|
||||
@ -253,12 +262,13 @@ h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
_JSAMPARRAY input_data, _JSAMPARRAY output_data)
|
||||
{
|
||||
int inrow, outrow;
|
||||
JDIMENSION outcol;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
|
||||
register JSAMPROW inptr0, inptr1, outptr;
|
||||
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
|
||||
register _JSAMPROW inptr0, inptr1, outptr;
|
||||
register int bias;
|
||||
|
||||
/* Expand input data enough to let all the output samples be generated
|
||||
@ -275,8 +285,8 @@ h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
inptr1 = input_data[inrow + 1];
|
||||
bias = 1; /* bias = 1,2,1,2,... for successive samples */
|
||||
for (outcol = 0; outcol < output_cols; outcol++) {
|
||||
*outptr++ =
|
||||
(JSAMPLE)((inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1] + bias) >> 2);
|
||||
*outptr++ = (_JSAMPLE)
|
||||
((inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1] + bias) >> 2);
|
||||
bias ^= 3; /* 1=>2, 2=>1 */
|
||||
inptr0 += 2; inptr1 += 2;
|
||||
}
|
||||
@ -295,12 +305,13 @@ h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
_JSAMPARRAY input_data, _JSAMPARRAY output_data)
|
||||
{
|
||||
int inrow, outrow;
|
||||
JDIMENSION colctr;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
|
||||
register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
|
||||
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
|
||||
register _JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
|
||||
JLONG membersum, neighsum, memberscale, neighscale;
|
||||
|
||||
/* Expand input data enough to let all the output samples be generated
|
||||
@ -341,7 +352,7 @@ h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
neighsum += neighsum;
|
||||
neighsum += above_ptr[0] + above_ptr[2] + below_ptr[0] + below_ptr[2];
|
||||
membersum = membersum * memberscale + neighsum * neighscale;
|
||||
*outptr++ = (JSAMPLE)((membersum + 32768) >> 16);
|
||||
*outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
|
||||
inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
|
||||
|
||||
for (colctr = output_cols - 2; colctr > 0; colctr--) {
|
||||
@ -357,7 +368,7 @@ h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
/* form final output scaled up by 2^16 */
|
||||
membersum = membersum * memberscale + neighsum * neighscale;
|
||||
/* round, descale and output it */
|
||||
*outptr++ = (JSAMPLE)((membersum + 32768) >> 16);
|
||||
*outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
|
||||
inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
|
||||
}
|
||||
|
||||
@ -368,7 +379,7 @@ h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
neighsum += neighsum;
|
||||
neighsum += above_ptr[-1] + above_ptr[1] + below_ptr[-1] + below_ptr[1];
|
||||
membersum = membersum * memberscale + neighsum * neighscale;
|
||||
*outptr = (JSAMPLE)((membersum + 32768) >> 16);
|
||||
*outptr = (_JSAMPLE)((membersum + 32768) >> 16);
|
||||
|
||||
inrow += 2;
|
||||
}
|
||||
@ -383,12 +394,13 @@ h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
_JSAMPARRAY input_data, _JSAMPARRAY output_data)
|
||||
{
|
||||
int outrow;
|
||||
JDIMENSION colctr;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
|
||||
register JSAMPROW inptr, above_ptr, below_ptr, outptr;
|
||||
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
|
||||
register _JSAMPROW inptr, above_ptr, below_ptr, outptr;
|
||||
JLONG membersum, neighsum, memberscale, neighscale;
|
||||
int colsum, lastcolsum, nextcolsum;
|
||||
|
||||
@ -420,7 +432,7 @@ fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
|
||||
neighsum = colsum + (colsum - membersum) + nextcolsum;
|
||||
membersum = membersum * memberscale + neighsum * neighscale;
|
||||
*outptr++ = (JSAMPLE)((membersum + 32768) >> 16);
|
||||
*outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
|
||||
lastcolsum = colsum; colsum = nextcolsum;
|
||||
|
||||
for (colctr = output_cols - 2; colctr > 0; colctr--) {
|
||||
@ -429,7 +441,7 @@ fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
|
||||
neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
|
||||
membersum = membersum * memberscale + neighsum * neighscale;
|
||||
*outptr++ = (JSAMPLE)((membersum + 32768) >> 16);
|
||||
*outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
|
||||
lastcolsum = colsum; colsum = nextcolsum;
|
||||
}
|
||||
|
||||
@ -437,7 +449,7 @@ fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
membersum = *inptr;
|
||||
neighsum = lastcolsum + (colsum - membersum) + colsum;
|
||||
membersum = membersum * memberscale + neighsum * neighscale;
|
||||
*outptr = (JSAMPLE)((membersum + 32768) >> 16);
|
||||
*outptr = (_JSAMPLE)((membersum + 32768) >> 16);
|
||||
|
||||
}
|
||||
}
|
||||
@ -451,19 +463,22 @@ fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_downsampler(j_compress_ptr cinfo)
|
||||
_jinit_downsampler(j_compress_ptr cinfo)
|
||||
{
|
||||
my_downsample_ptr downsample;
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
boolean smoothok = TRUE;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
downsample = (my_downsample_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_downsampler));
|
||||
cinfo->downsample = (struct jpeg_downsampler *)downsample;
|
||||
downsample->pub.start_pass = start_pass_downsample;
|
||||
downsample->pub.downsample = sep_downsample;
|
||||
downsample->pub._downsample = sep_downsample;
|
||||
downsample->pub.need_context_rows = FALSE;
|
||||
|
||||
if (cinfo->CCIR601_sampling)
|
||||
@ -484,15 +499,17 @@ jinit_downsampler(j_compress_ptr cinfo)
|
||||
} else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
|
||||
compptr->v_samp_factor == cinfo->max_v_samp_factor) {
|
||||
smoothok = FALSE;
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_h2v1_downsample())
|
||||
downsample->methods[ci] = jsimd_h2v1_downsample;
|
||||
else
|
||||
#endif
|
||||
downsample->methods[ci] = h2v1_downsample;
|
||||
} else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
|
||||
compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
|
||||
#ifdef INPUT_SMOOTHING_SUPPORTED
|
||||
if (cinfo->smoothing_factor) {
|
||||
#if defined(__mips__)
|
||||
#if defined(WITH_SIMD) && defined(__mips__)
|
||||
if (jsimd_can_h2v2_smooth_downsample())
|
||||
downsample->methods[ci] = jsimd_h2v2_smooth_downsample;
|
||||
else
|
||||
@ -502,9 +519,11 @@ jinit_downsampler(j_compress_ptr cinfo)
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_h2v2_downsample())
|
||||
downsample->methods[ci] = jsimd_h2v2_downsample;
|
||||
else
|
||||
#endif
|
||||
downsample->methods[ci] = h2v2_downsample;
|
||||
}
|
||||
} else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
|
||||
@ -520,3 +539,5 @@ jinit_downsampler(j_compress_ptr cinfo)
|
||||
TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */
|
||||
|
126
3rdparty/libjpeg-turbo/src/jcstest.c
vendored
Normal file
126
3rdparty/libjpeg-turbo/src/jcstest.c
vendored
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (C)2011 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.
|
||||
*/
|
||||
|
||||
/* This program demonstrates how to check for the colorspace extension
|
||||
capabilities of libjpeg-turbo at both compile time and run time. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <jpeglib.h>
|
||||
#include <jerror.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#ifndef JCS_EXTENSIONS
|
||||
#define JCS_EXT_RGB 6
|
||||
#endif
|
||||
#if !defined(JCS_EXTENSIONS) || !defined(JCS_ALPHA_EXTENSIONS)
|
||||
#define JCS_EXT_RGBA 12
|
||||
#endif
|
||||
|
||||
static char lasterror[JMSG_LENGTH_MAX] = "No error";
|
||||
|
||||
typedef struct _error_mgr {
|
||||
struct jpeg_error_mgr pub;
|
||||
jmp_buf jb;
|
||||
} error_mgr;
|
||||
|
||||
static void my_error_exit(j_common_ptr cinfo)
|
||||
{
|
||||
error_mgr *myerr = (error_mgr *)cinfo->err;
|
||||
(*cinfo->err->output_message) (cinfo);
|
||||
longjmp(myerr->jb, 1);
|
||||
}
|
||||
|
||||
static void my_output_message(j_common_ptr cinfo)
|
||||
{
|
||||
(*cinfo->err->format_message) (cinfo, lasterror);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int jcs_valid = -1, jcs_alpha_valid = -1;
|
||||
struct jpeg_compress_struct cinfo;
|
||||
error_mgr jerr;
|
||||
|
||||
printf("libjpeg-turbo colorspace extensions:\n");
|
||||
#if JCS_EXTENSIONS
|
||||
printf(" Present at compile time\n");
|
||||
#else
|
||||
printf(" Not present at compile time\n");
|
||||
#endif
|
||||
|
||||
cinfo.err = jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = my_error_exit;
|
||||
jerr.pub.output_message = my_output_message;
|
||||
|
||||
if (setjmp(jerr.jb)) {
|
||||
/* this will execute if libjpeg has an error */
|
||||
jcs_valid = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
jpeg_create_compress(&cinfo);
|
||||
cinfo.input_components = 3;
|
||||
jpeg_set_defaults(&cinfo);
|
||||
cinfo.in_color_space = JCS_EXT_RGB;
|
||||
jpeg_default_colorspace(&cinfo);
|
||||
jcs_valid = 1;
|
||||
|
||||
done:
|
||||
if (jcs_valid)
|
||||
printf(" Working properly\n");
|
||||
else
|
||||
printf(" Not working properly. Error returned was:\n %s\n",
|
||||
lasterror);
|
||||
|
||||
printf("libjpeg-turbo alpha colorspace extensions:\n");
|
||||
#if JCS_ALPHA_EXTENSIONS
|
||||
printf(" Present at compile time\n");
|
||||
#else
|
||||
printf(" Not present at compile time\n");
|
||||
#endif
|
||||
|
||||
if (setjmp(jerr.jb)) {
|
||||
/* this will execute if libjpeg has an error */
|
||||
jcs_alpha_valid = 0;
|
||||
goto done2;
|
||||
}
|
||||
|
||||
cinfo.in_color_space = JCS_EXT_RGBA;
|
||||
jpeg_default_colorspace(&cinfo);
|
||||
jcs_alpha_valid = 1;
|
||||
|
||||
done2:
|
||||
if (jcs_alpha_valid)
|
||||
printf(" Working properly\n");
|
||||
else
|
||||
printf(" Not working properly. Error returned was:\n %s\n",
|
||||
lasterror);
|
||||
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
return 0;
|
||||
}
|
16
3rdparty/libjpeg-turbo/src/jctrans.c
vendored
16
3rdparty/libjpeg-turbo/src/jctrans.c
vendored
@ -17,7 +17,7 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jpegcomp.h"
|
||||
#include "jpegapicomp.h"
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
@ -42,6 +42,9 @@ LOCAL(void) transencode_coef_controller(j_compress_ptr cinfo,
|
||||
GLOBAL(void)
|
||||
jpeg_write_coefficients(j_compress_ptr cinfo, jvirt_barray_ptr *coef_arrays)
|
||||
{
|
||||
if (cinfo->master->lossless)
|
||||
ERREXIT(cinfo, JERR_NOTIMPL);
|
||||
|
||||
if (cinfo->global_state != CSTATE_START)
|
||||
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
||||
/* Mark all tables to be written */
|
||||
@ -72,6 +75,9 @@ jpeg_copy_critical_parameters(j_decompress_ptr srcinfo, j_compress_ptr dstinfo)
|
||||
JQUANT_TBL *c_quant, *slot_quant;
|
||||
int tblno, ci, coefi;
|
||||
|
||||
if (srcinfo->master->lossless)
|
||||
ERREXIT(dstinfo, JERR_NOTIMPL);
|
||||
|
||||
/* Safety check to ensure start_compress not called yet. */
|
||||
if (dstinfo->global_state != CSTATE_START)
|
||||
ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
|
||||
@ -364,6 +370,13 @@ compress_output(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
}
|
||||
|
||||
|
||||
METHODDEF(boolean)
|
||||
compress_output_12(j_compress_ptr cinfo, J12SAMPIMAGE input_buf)
|
||||
{
|
||||
return compress_output(cinfo, (JSAMPIMAGE)input_buf);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize coefficient buffer controller.
|
||||
*
|
||||
@ -386,6 +399,7 @@ transencode_coef_controller(j_compress_ptr cinfo,
|
||||
cinfo->coef = (struct jpeg_c_coef_controller *)coef;
|
||||
coef->pub.start_pass = start_pass_coef;
|
||||
coef->pub.compress_data = compress_output;
|
||||
coef->pub.compress_data_12 = compress_output_12;
|
||||
|
||||
/* Save pointer to virtual arrays */
|
||||
coef->whole_image = coef_arrays;
|
||||
|
21
3rdparty/libjpeg-turbo/src/jdapimin.c
vendored
21
3rdparty/libjpeg-turbo/src/jdapimin.c
vendored
@ -3,8 +3,10 @@
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1998, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2016, 2022, D. R. Commander.
|
||||
* Copyright (C) 2016, 2022, 2024, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -23,7 +25,6 @@
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jdmaster.h"
|
||||
#include "jconfigint.h"
|
||||
|
||||
|
||||
/*
|
||||
@ -83,6 +84,8 @@ jpeg_CreateDecompress(j_decompress_ptr cinfo, int version, size_t structsize)
|
||||
/* And initialize the overall input controller. */
|
||||
jinit_input_controller(cinfo);
|
||||
|
||||
cinfo->data_precision = BITS_IN_JSAMPLE;
|
||||
|
||||
/* OK, I'm ready */
|
||||
cinfo->global_state = DSTATE_START;
|
||||
|
||||
@ -157,13 +160,19 @@ default_decompress_parms(j_decompress_ptr cinfo)
|
||||
int cid1 = cinfo->comp_info[1].component_id;
|
||||
int cid2 = cinfo->comp_info[2].component_id;
|
||||
|
||||
if (cid0 == 1 && cid1 == 2 && cid2 == 3)
|
||||
cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
|
||||
else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
|
||||
if (cid0 == 1 && cid1 == 2 && cid2 == 3) {
|
||||
if (cinfo->master->lossless)
|
||||
cinfo->jpeg_color_space = JCS_RGB; /* assume RGB w/out marker */
|
||||
else
|
||||
cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
|
||||
} else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
|
||||
cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
|
||||
else {
|
||||
TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
|
||||
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
|
||||
if (cinfo->master->lossless)
|
||||
cinfo->jpeg_color_space = JCS_RGB; /* assume it's RGB */
|
||||
else
|
||||
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
|
||||
}
|
||||
}
|
||||
/* Always guess RGB is proper output colorspace. */
|
||||
|
162
3rdparty/libjpeg-turbo/src/jdapistd.c
vendored
162
3rdparty/libjpeg-turbo/src/jdapistd.c
vendored
@ -4,7 +4,7 @@
|
||||
* 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, 2022, D. R. Commander.
|
||||
* Copyright (C) 2010, 2015-2020, 2022-2023, D. R. Commander.
|
||||
* Copyright (C) 2015, Google, Inc.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
@ -19,13 +19,20 @@
|
||||
*/
|
||||
|
||||
#include "jinclude.h"
|
||||
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
|
||||
#include "jdmainct.h"
|
||||
#include "jdcoefct.h"
|
||||
#else
|
||||
#define JPEG_INTERNALS
|
||||
#include "jpeglib.h"
|
||||
#endif
|
||||
#include "jdmaster.h"
|
||||
#include "jdmerge.h"
|
||||
#include "jdsample.h"
|
||||
#include "jmemsys.h"
|
||||
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
|
||||
/* Forward declarations */
|
||||
LOCAL(boolean) output_pass_setup(j_decompress_ptr cinfo);
|
||||
|
||||
@ -121,8 +128,20 @@ output_pass_setup(j_decompress_ptr cinfo)
|
||||
}
|
||||
/* Process some data */
|
||||
last_scanline = cinfo->output_scanline;
|
||||
(*cinfo->main->process_data) (cinfo, (JSAMPARRAY)NULL,
|
||||
&cinfo->output_scanline, (JDIMENSION)0);
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
if (cinfo->data_precision == 16)
|
||||
(*cinfo->main->process_data_16) (cinfo, (J16SAMPARRAY)NULL,
|
||||
&cinfo->output_scanline,
|
||||
(JDIMENSION)0);
|
||||
else
|
||||
#endif
|
||||
if (cinfo->data_precision == 12)
|
||||
(*cinfo->main->process_data_12) (cinfo, (J12SAMPARRAY)NULL,
|
||||
&cinfo->output_scanline,
|
||||
(JDIMENSION)0);
|
||||
else
|
||||
(*cinfo->main->process_data) (cinfo, (JSAMPARRAY)NULL,
|
||||
&cinfo->output_scanline, (JDIMENSION)0);
|
||||
if (cinfo->output_scanline == last_scanline)
|
||||
return FALSE; /* No progress made, must suspend */
|
||||
}
|
||||
@ -135,33 +154,46 @@ output_pass_setup(j_decompress_ptr cinfo)
|
||||
#endif /* QUANT_2PASS_SUPPORTED */
|
||||
}
|
||||
/* Ready for application to drive output pass through
|
||||
* jpeg_read_scanlines or jpeg_read_raw_data.
|
||||
* _jpeg_read_scanlines or _jpeg_read_raw_data.
|
||||
*/
|
||||
cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE == 8 */
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
|
||||
/*
|
||||
* Enable partial scanline decompression
|
||||
*
|
||||
* Must be called after jpeg_start_decompress() and before any calls to
|
||||
* jpeg_read_scanlines() or jpeg_skip_scanlines().
|
||||
* _jpeg_read_scanlines() or _jpeg_skip_scanlines().
|
||||
*
|
||||
* Refer to libjpeg.txt for more information.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
|
||||
JDIMENSION *width)
|
||||
_jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
|
||||
JDIMENSION *width)
|
||||
{
|
||||
int ci, align, orig_downsampled_width;
|
||||
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->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
if (cinfo->master->lossless)
|
||||
ERREXIT(cinfo, JERR_NOTIMPL);
|
||||
|
||||
if ((cinfo->global_state != DSTATE_SCANNING &&
|
||||
cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
|
||||
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
||||
|
||||
if (!xoffset || !width)
|
||||
@ -209,11 +241,13 @@ jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
|
||||
*/
|
||||
*width = *width + input_xoffset - *xoffset;
|
||||
cinfo->output_width = *width;
|
||||
#ifdef UPSAMPLE_MERGING_SUPPORTED
|
||||
if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
|
||||
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
|
||||
upsample->out_row_width =
|
||||
cinfo->output_width * cinfo->out_color_components;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set the first and last iMCU columns that we must decompress. These values
|
||||
* will be used in single-scan decompressions.
|
||||
@ -231,9 +265,11 @@ jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
|
||||
/* Set downsampled_width to the new output width. */
|
||||
orig_downsampled_width = compptr->downsampled_width;
|
||||
compptr->downsampled_width =
|
||||
(JDIMENSION)jdiv_round_up((long)(cinfo->output_width *
|
||||
compptr->h_samp_factor),
|
||||
(long)cinfo->max_h_samp_factor);
|
||||
(JDIMENSION)jdiv_round_up((long)cinfo->output_width *
|
||||
(long)(compptr->h_samp_factor *
|
||||
compptr->_DCT_scaled_size),
|
||||
(long)(cinfo->max_h_samp_factor *
|
||||
cinfo->_min_DCT_scaled_size));
|
||||
if (compptr->downsampled_width < 2 && orig_downsampled_width >= 2)
|
||||
reinit_upsampler = TRUE;
|
||||
|
||||
@ -249,11 +285,13 @@ jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
|
||||
|
||||
if (reinit_upsampler) {
|
||||
cinfo->master->jinit_upsampler_no_alloc = TRUE;
|
||||
jinit_upsampler(cinfo);
|
||||
_jinit_upsampler(cinfo);
|
||||
cinfo->master->jinit_upsampler_no_alloc = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE != 16 */
|
||||
|
||||
|
||||
/*
|
||||
* Read some scanlines of data from the JPEG decompressor.
|
||||
@ -263,17 +301,21 @@ jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
|
||||
* including bottom of image, data source suspension, and operating
|
||||
* modes that emit multiple scanlines at a time.
|
||||
*
|
||||
* Note: we warn about excess calls to jpeg_read_scanlines() since
|
||||
* Note: we warn about excess calls to _jpeg_read_scanlines() since
|
||||
* this likely signals an application programmer error. However,
|
||||
* an oversize buffer (max_lines > scanlines remaining) is not an error.
|
||||
*/
|
||||
|
||||
GLOBAL(JDIMENSION)
|
||||
jpeg_read_scanlines(j_decompress_ptr cinfo, JSAMPARRAY scanlines,
|
||||
JDIMENSION max_lines)
|
||||
_jpeg_read_scanlines(j_decompress_ptr cinfo, _JSAMPARRAY scanlines,
|
||||
JDIMENSION max_lines)
|
||||
{
|
||||
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
|
||||
JDIMENSION row_ctr;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
if (cinfo->global_state != DSTATE_SCANNING)
|
||||
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
||||
if (cinfo->output_scanline >= cinfo->output_height) {
|
||||
@ -290,30 +332,36 @@ jpeg_read_scanlines(j_decompress_ptr cinfo, JSAMPARRAY scanlines,
|
||||
|
||||
/* Process some data */
|
||||
row_ctr = 0;
|
||||
(*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
|
||||
(*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
|
||||
cinfo->output_scanline += row_ctr;
|
||||
return row_ctr;
|
||||
#else
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* Dummy color convert function used by jpeg_skip_scanlines() */
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
|
||||
/* Dummy color convert function used by _jpeg_skip_scanlines() */
|
||||
LOCAL(void)
|
||||
noop_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
|
||||
noop_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/* Dummy quantize function used by jpeg_skip_scanlines() */
|
||||
/* Dummy quantize function used by _jpeg_skip_scanlines() */
|
||||
LOCAL(void)
|
||||
noop_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
noop_quantize(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* In some cases, it is best to call jpeg_read_scanlines() and discard the
|
||||
* In some cases, it is best to call _jpeg_read_scanlines() and discard the
|
||||
* output, rather than skipping the scanlines, because this allows us to
|
||||
* maintain the internal state of the context-based upsampler. In these cases,
|
||||
* we set up and tear down a dummy color converter in order to avoid valgrind
|
||||
@ -324,49 +372,53 @@ LOCAL(void)
|
||||
read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
|
||||
{
|
||||
JDIMENSION n;
|
||||
#ifdef UPSAMPLE_MERGING_SUPPORTED
|
||||
my_master_ptr master = (my_master_ptr)cinfo->master;
|
||||
JSAMPLE dummy_sample[1] = { 0 };
|
||||
JSAMPROW dummy_row = dummy_sample;
|
||||
JSAMPARRAY scanlines = NULL;
|
||||
void (*color_convert) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf,
|
||||
#endif
|
||||
_JSAMPLE dummy_sample[1] = { 0 };
|
||||
_JSAMPROW dummy_row = dummy_sample;
|
||||
_JSAMPARRAY scanlines = NULL;
|
||||
void (*color_convert) (j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf,
|
||||
int num_rows) = NULL;
|
||||
void (*color_quantize) (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows) = NULL;
|
||||
void (*color_quantize) (j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPARRAY output_buf, int num_rows) = NULL;
|
||||
|
||||
if (cinfo->cconvert && cinfo->cconvert->color_convert) {
|
||||
color_convert = cinfo->cconvert->color_convert;
|
||||
cinfo->cconvert->color_convert = noop_convert;
|
||||
if (cinfo->cconvert && cinfo->cconvert->_color_convert) {
|
||||
color_convert = cinfo->cconvert->_color_convert;
|
||||
cinfo->cconvert->_color_convert = noop_convert;
|
||||
/* This just prevents UBSan from complaining about adding 0 to a NULL
|
||||
* pointer. The pointer isn't actually used.
|
||||
*/
|
||||
scanlines = &dummy_row;
|
||||
}
|
||||
|
||||
if (cinfo->cquantize && cinfo->cquantize->color_quantize) {
|
||||
color_quantize = cinfo->cquantize->color_quantize;
|
||||
cinfo->cquantize->color_quantize = noop_quantize;
|
||||
if (cinfo->cquantize && cinfo->cquantize->_color_quantize) {
|
||||
color_quantize = cinfo->cquantize->_color_quantize;
|
||||
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);
|
||||
_jpeg_read_scanlines(cinfo, scanlines, 1);
|
||||
|
||||
if (color_convert)
|
||||
cinfo->cconvert->color_convert = color_convert;
|
||||
cinfo->cconvert->_color_convert = color_convert;
|
||||
|
||||
if (color_quantize)
|
||||
cinfo->cquantize->color_quantize = color_quantize;
|
||||
cinfo->cquantize->_color_quantize = color_quantize;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Called by jpeg_skip_scanlines(). This partially skips a decompress block by
|
||||
* incrementing the rowgroup counter.
|
||||
* Called by _jpeg_skip_scanlines(). This partially skips a decompress block
|
||||
* by incrementing the rowgroup counter.
|
||||
*/
|
||||
|
||||
LOCAL(void)
|
||||
@ -405,7 +457,7 @@ increment_simple_rowgroup_ctr(j_decompress_ptr cinfo, JDIMENSION rows)
|
||||
*/
|
||||
|
||||
GLOBAL(JDIMENSION)
|
||||
jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
|
||||
_jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
|
||||
{
|
||||
my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
|
||||
my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
|
||||
@ -416,6 +468,12 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
|
||||
JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
|
||||
JDIMENSION lines_to_skip, lines_to_read;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
if (cinfo->master->lossless)
|
||||
ERREXIT(cinfo, JERR_NOTIMPL);
|
||||
|
||||
/* Two-pass color quantization is not supported. */
|
||||
if (cinfo->quantize_colors && cinfo->two_pass_quantize)
|
||||
ERREXIT(cinfo, JERR_NOTIMPL);
|
||||
@ -517,7 +575,7 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
|
||||
* all of the entropy decoding occurs in jpeg_start_decompress(), assuming
|
||||
* that the input data source is non-suspending. This makes skipping easy.
|
||||
*/
|
||||
if (cinfo->inputctl->has_multiple_scans) {
|
||||
if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) {
|
||||
if (cinfo->upsample->need_context_rows) {
|
||||
cinfo->output_scanline += lines_to_skip;
|
||||
cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
|
||||
@ -588,11 +646,17 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
|
||||
*/
|
||||
|
||||
GLOBAL(JDIMENSION)
|
||||
jpeg_read_raw_data(j_decompress_ptr cinfo, JSAMPIMAGE data,
|
||||
JDIMENSION max_lines)
|
||||
_jpeg_read_raw_data(j_decompress_ptr cinfo, _JSAMPIMAGE data,
|
||||
JDIMENSION max_lines)
|
||||
{
|
||||
JDIMENSION lines_per_iMCU_row;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
if (cinfo->master->lossless)
|
||||
ERREXIT(cinfo, JERR_NOTIMPL);
|
||||
|
||||
if (cinfo->global_state != DSTATE_RAW_OK)
|
||||
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
||||
if (cinfo->output_scanline >= cinfo->output_height) {
|
||||
@ -613,7 +677,7 @@ jpeg_read_raw_data(j_decompress_ptr cinfo, JSAMPIMAGE data,
|
||||
ERREXIT(cinfo, JERR_BUFFER_SIZE);
|
||||
|
||||
/* Decompress directly into user's buffer. */
|
||||
if (!(*cinfo->coef->decompress_data) (cinfo, data))
|
||||
if (!(*cinfo->coef->_decompress_data) (cinfo, data))
|
||||
return 0; /* suspension forced, can do nothing more */
|
||||
|
||||
/* OK, we processed one iMCU row. */
|
||||
@ -621,6 +685,10 @@ jpeg_read_raw_data(j_decompress_ptr cinfo, JSAMPIMAGE data,
|
||||
return lines_per_iMCU_row;
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE != 16 */
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
|
||||
/* Additional entry points for buffered-image mode. */
|
||||
|
||||
@ -678,3 +746,5 @@ jpeg_finish_output(j_decompress_ptr cinfo)
|
||||
}
|
||||
|
||||
#endif /* D_MULTISCAN_FILES_SUPPORTED */
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE == 8 */
|
||||
|
198
3rdparty/libjpeg-turbo/src/jdatadst-tj.c
vendored
Normal file
198
3rdparty/libjpeg-turbo/src/jdatadst-tj.c
vendored
Normal file
@ -0,0 +1,198 @@
|
||||
/*
|
||||
* jdatadst-tj.c
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* Modified 2009-2012 by Guido Vollbeding.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2011, 2014, 2016, 2019, 2022-2023, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file contains compression data destination routines for the case of
|
||||
* emitting JPEG data to memory or to a file (or any stdio stream).
|
||||
* While these routines are sufficient for most applications,
|
||||
* some will want to use a different destination manager.
|
||||
* IMPORTANT: we assume that fwrite() will correctly transcribe an array of
|
||||
* JOCTETs into 8-bit-wide elements on external storage. If char is wider
|
||||
* than 8 bits on your machine, you may need to do some tweaking.
|
||||
*/
|
||||
|
||||
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jerror.h"
|
||||
|
||||
void jpeg_mem_dest_tj(j_compress_ptr cinfo, unsigned char **outbuffer,
|
||||
size_t *outsize, boolean alloc);
|
||||
|
||||
|
||||
#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
|
||||
|
||||
|
||||
/* Expanded data destination object for memory output */
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_destination_mgr pub; /* public fields */
|
||||
|
||||
unsigned char **outbuffer; /* target buffer */
|
||||
size_t *outsize;
|
||||
unsigned char *newbuffer; /* newly allocated buffer */
|
||||
JOCTET *buffer; /* start of buffer */
|
||||
size_t bufsize;
|
||||
boolean alloc;
|
||||
} my_mem_destination_mgr;
|
||||
|
||||
typedef my_mem_destination_mgr *my_mem_dest_ptr;
|
||||
|
||||
|
||||
/*
|
||||
* Initialize destination --- called by jpeg_start_compress
|
||||
* before any data is actually written.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
init_mem_destination(j_compress_ptr cinfo)
|
||||
{
|
||||
/* no work necessary here */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Empty the output buffer --- called whenever buffer fills up.
|
||||
*
|
||||
* In typical applications, this should write the entire output buffer
|
||||
* (ignoring the current state of next_output_byte & free_in_buffer),
|
||||
* reset the pointer & count to the start of the buffer, and return TRUE
|
||||
* indicating that the buffer has been dumped.
|
||||
*
|
||||
* In applications that need to be able to suspend compression due to output
|
||||
* overrun, a FALSE return indicates that the buffer cannot be emptied now.
|
||||
* In this situation, the compressor will return to its caller (possibly with
|
||||
* an indication that it has not accepted all the supplied scanlines). The
|
||||
* application should resume compression after it has made more room in the
|
||||
* output buffer. Note that there are substantial restrictions on the use of
|
||||
* suspension --- see the documentation.
|
||||
*
|
||||
* When suspending, the compressor will back up to a convenient restart point
|
||||
* (typically the start of the current MCU). next_output_byte & free_in_buffer
|
||||
* indicate where the restart point will be if the current call returns FALSE.
|
||||
* Data beyond this point will be regenerated after resumption, so do not
|
||||
* write it out when emptying the buffer externally.
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
empty_mem_output_buffer(j_compress_ptr cinfo)
|
||||
{
|
||||
size_t nextsize;
|
||||
JOCTET *nextbuffer;
|
||||
my_mem_dest_ptr dest = (my_mem_dest_ptr)cinfo->dest;
|
||||
|
||||
if (!dest->alloc) ERREXIT(cinfo, JERR_BUFFER_SIZE);
|
||||
|
||||
/* Try to allocate new buffer with double size */
|
||||
nextsize = dest->bufsize * 2;
|
||||
nextbuffer = (JOCTET *)malloc(nextsize);
|
||||
|
||||
if (nextbuffer == NULL)
|
||||
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
|
||||
|
||||
memcpy(nextbuffer, dest->buffer, dest->bufsize);
|
||||
|
||||
free(dest->newbuffer);
|
||||
|
||||
dest->newbuffer = nextbuffer;
|
||||
|
||||
dest->pub.next_output_byte = nextbuffer + dest->bufsize;
|
||||
dest->pub.free_in_buffer = dest->bufsize;
|
||||
|
||||
dest->buffer = nextbuffer;
|
||||
dest->bufsize = nextsize;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Terminate destination --- called by jpeg_finish_compress
|
||||
* after all data has been written. Usually needs to flush buffer.
|
||||
*
|
||||
* NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
|
||||
* application must deal with any cleanup that should happen even
|
||||
* for error exit.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
term_mem_destination(j_compress_ptr cinfo)
|
||||
{
|
||||
my_mem_dest_ptr dest = (my_mem_dest_ptr)cinfo->dest;
|
||||
|
||||
if (dest->alloc) *dest->outbuffer = dest->buffer;
|
||||
*dest->outsize = dest->bufsize - dest->pub.free_in_buffer;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Prepare for output to a memory buffer.
|
||||
* The caller may supply an own initial buffer with appropriate size.
|
||||
* Otherwise, or when the actual data output exceeds the given size,
|
||||
* the library adapts the buffer size as necessary.
|
||||
* The standard library functions malloc/free are used for allocating
|
||||
* larger memory, so the buffer is available to the application after
|
||||
* finishing compression, and then the application is responsible for
|
||||
* freeing the requested memory.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_mem_dest_tj(j_compress_ptr cinfo, unsigned char **outbuffer,
|
||||
size_t *outsize, boolean alloc)
|
||||
{
|
||||
boolean reused = FALSE;
|
||||
my_mem_dest_ptr dest;
|
||||
|
||||
if (outbuffer == NULL || outsize == NULL) /* sanity check */
|
||||
ERREXIT(cinfo, JERR_BUFFER_SIZE);
|
||||
|
||||
/* The destination object is made permanent so that multiple JPEG images
|
||||
* can be written to the same buffer without re-executing jpeg_mem_dest.
|
||||
*/
|
||||
if (cinfo->dest == NULL) { /* first time for this JPEG object? */
|
||||
cinfo->dest = (struct jpeg_destination_mgr *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
|
||||
sizeof(my_mem_destination_mgr));
|
||||
dest = (my_mem_dest_ptr)cinfo->dest;
|
||||
dest->newbuffer = NULL;
|
||||
dest->buffer = NULL;
|
||||
} else if (cinfo->dest->init_destination != init_mem_destination) {
|
||||
/* It is unsafe to reuse the existing destination manager unless it was
|
||||
* created by this function.
|
||||
*/
|
||||
ERREXIT(cinfo, JERR_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
dest = (my_mem_dest_ptr)cinfo->dest;
|
||||
dest->pub.init_destination = init_mem_destination;
|
||||
dest->pub.empty_output_buffer = empty_mem_output_buffer;
|
||||
dest->pub.term_destination = term_mem_destination;
|
||||
if (dest->buffer == *outbuffer && *outbuffer != NULL && alloc)
|
||||
reused = TRUE;
|
||||
dest->outbuffer = outbuffer;
|
||||
dest->outsize = outsize;
|
||||
dest->alloc = alloc;
|
||||
|
||||
if (*outbuffer == NULL || *outsize == 0) {
|
||||
if (alloc) {
|
||||
/* Allocate initial buffer */
|
||||
dest->newbuffer = *outbuffer = (unsigned char *)malloc(OUTPUT_BUF_SIZE);
|
||||
if (dest->newbuffer == NULL)
|
||||
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
|
||||
*outsize = OUTPUT_BUF_SIZE;
|
||||
} else
|
||||
ERREXIT(cinfo, JERR_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
dest->pub.next_output_byte = dest->buffer = *outbuffer;
|
||||
if (!reused)
|
||||
dest->bufsize = *outsize;
|
||||
dest->pub.free_in_buffer = dest->bufsize;
|
||||
}
|
10
3rdparty/libjpeg-turbo/src/jdatadst.c
vendored
10
3rdparty/libjpeg-turbo/src/jdatadst.c
vendored
@ -38,7 +38,6 @@ typedef my_destination_mgr *my_dest_ptr;
|
||||
#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
|
||||
|
||||
|
||||
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
|
||||
/* Expanded data destination object for memory output */
|
||||
|
||||
typedef struct {
|
||||
@ -52,7 +51,6 @@ typedef struct {
|
||||
} my_mem_destination_mgr;
|
||||
|
||||
typedef my_mem_destination_mgr *my_mem_dest_ptr;
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
@ -74,13 +72,11 @@ init_destination(j_compress_ptr cinfo)
|
||||
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
|
||||
}
|
||||
|
||||
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
|
||||
METHODDEF(void)
|
||||
init_mem_destination(j_compress_ptr cinfo)
|
||||
{
|
||||
/* no work necessary here */
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
@ -121,7 +117,6 @@ empty_output_buffer(j_compress_ptr cinfo)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
|
||||
METHODDEF(boolean)
|
||||
empty_mem_output_buffer(j_compress_ptr cinfo)
|
||||
{
|
||||
@ -150,7 +145,6 @@ empty_mem_output_buffer(j_compress_ptr cinfo)
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
@ -179,7 +173,6 @@ term_destination(j_compress_ptr cinfo)
|
||||
ERREXIT(cinfo, JERR_FILE_WRITE);
|
||||
}
|
||||
|
||||
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
|
||||
METHODDEF(void)
|
||||
term_mem_destination(j_compress_ptr cinfo)
|
||||
{
|
||||
@ -188,7 +181,6 @@ term_mem_destination(j_compress_ptr cinfo)
|
||||
*dest->outbuffer = dest->buffer;
|
||||
*dest->outsize = (unsigned long)(dest->bufsize - dest->pub.free_in_buffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
@ -227,7 +219,6 @@ jpeg_stdio_dest(j_compress_ptr cinfo, FILE *outfile)
|
||||
}
|
||||
|
||||
|
||||
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
|
||||
/*
|
||||
* Prepare for output to a memory buffer.
|
||||
* The caller may supply an own initial buffer with appropriate size.
|
||||
@ -284,4 +275,3 @@ jpeg_mem_dest(j_compress_ptr cinfo, unsigned char **outbuffer,
|
||||
dest->pub.next_output_byte = dest->buffer = *outbuffer;
|
||||
dest->pub.free_in_buffer = dest->bufsize = *outsize;
|
||||
}
|
||||
#endif
|
||||
|
194
3rdparty/libjpeg-turbo/src/jdatasrc-tj.c
vendored
Normal file
194
3rdparty/libjpeg-turbo/src/jdatasrc-tj.c
vendored
Normal file
@ -0,0 +1,194 @@
|
||||
/*
|
||||
* jdatasrc-tj.c
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* Modified 2009-2011 by Guido Vollbeding.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2011, 2016, 2019, 2023, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file contains decompression data source routines for the case of
|
||||
* reading JPEG data from memory or from a file (or any stdio stream).
|
||||
* While these routines are sufficient for most applications,
|
||||
* some will want to use a different source manager.
|
||||
* IMPORTANT: we assume that fread() will correctly transcribe an array of
|
||||
* JOCTETs from 8-bit-wide elements on external storage. If char is wider
|
||||
* than 8 bits on your machine, you may need to do some tweaking.
|
||||
*/
|
||||
|
||||
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jerror.h"
|
||||
|
||||
void jpeg_mem_src_tj(j_decompress_ptr cinfo, const unsigned char *inbuffer,
|
||||
size_t insize);
|
||||
|
||||
|
||||
/*
|
||||
* Initialize source --- called by jpeg_read_header
|
||||
* before any data is actually read.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
init_mem_source(j_decompress_ptr cinfo)
|
||||
{
|
||||
/* no work necessary here */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Fill the input buffer --- called whenever buffer is emptied.
|
||||
*
|
||||
* In typical applications, this should read fresh data into the buffer
|
||||
* (ignoring the current state of next_input_byte & bytes_in_buffer),
|
||||
* reset the pointer & count to the start of the buffer, and return TRUE
|
||||
* indicating that the buffer has been reloaded. It is not necessary to
|
||||
* fill the buffer entirely, only to obtain at least one more byte.
|
||||
*
|
||||
* There is no such thing as an EOF return. If the end of the file has been
|
||||
* reached, the routine has a choice of ERREXIT() or inserting fake data into
|
||||
* the buffer. In most cases, generating a warning message and inserting a
|
||||
* fake EOI marker is the best course of action --- this will allow the
|
||||
* decompressor to output however much of the image is there. However,
|
||||
* the resulting error message is misleading if the real problem is an empty
|
||||
* input file, so we handle that case specially.
|
||||
*
|
||||
* In applications that need to be able to suspend compression due to input
|
||||
* not being available yet, a FALSE return indicates that no more data can be
|
||||
* obtained right now, but more may be forthcoming later. In this situation,
|
||||
* the decompressor will return to its caller (with an indication of the
|
||||
* number of scanlines it has read, if any). The application should resume
|
||||
* decompression after it has loaded more data into the input buffer. Note
|
||||
* that there are substantial restrictions on the use of suspension --- see
|
||||
* the documentation.
|
||||
*
|
||||
* When suspending, the decompressor will back up to a convenient restart point
|
||||
* (typically the start of the current MCU). next_input_byte & bytes_in_buffer
|
||||
* indicate where the restart point will be if the current call returns FALSE.
|
||||
* Data beyond this point must be rescanned after resumption, so move it to
|
||||
* the front of the buffer rather than discarding it.
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
fill_mem_input_buffer(j_decompress_ptr cinfo)
|
||||
{
|
||||
static const JOCTET mybuffer[4] = {
|
||||
(JOCTET)0xFF, (JOCTET)JPEG_EOI, 0, 0
|
||||
};
|
||||
|
||||
/* The whole JPEG data is expected to reside in the supplied memory
|
||||
* buffer, so any request for more data beyond the given buffer size
|
||||
* is treated as an error.
|
||||
*/
|
||||
WARNMS(cinfo, JWRN_JPEG_EOF);
|
||||
|
||||
/* Insert a fake EOI marker */
|
||||
|
||||
cinfo->src->next_input_byte = mybuffer;
|
||||
cinfo->src->bytes_in_buffer = 2;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Skip data --- used to skip over a potentially large amount of
|
||||
* uninteresting data (such as an APPn marker).
|
||||
*
|
||||
* Writers of suspendable-input applications must note that skip_input_data
|
||||
* is not granted the right to give a suspension return. If the skip extends
|
||||
* beyond the data currently in the buffer, the buffer can be marked empty so
|
||||
* that the next read will cause a fill_input_buffer call that can suspend.
|
||||
* Arranging for additional bytes to be discarded before reloading the input
|
||||
* buffer is the application writer's problem.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
skip_input_data(j_decompress_ptr cinfo, long num_bytes)
|
||||
{
|
||||
struct jpeg_source_mgr *src = cinfo->src;
|
||||
|
||||
/* Just a dumb implementation for now. Could use fseek() except
|
||||
* it doesn't work on pipes. Not clear that being smart is worth
|
||||
* any trouble anyway --- large skips are infrequent.
|
||||
*/
|
||||
if (num_bytes > 0) {
|
||||
while (num_bytes > (long)src->bytes_in_buffer) {
|
||||
num_bytes -= (long)src->bytes_in_buffer;
|
||||
(void)(*src->fill_input_buffer) (cinfo);
|
||||
/* note we assume that fill_input_buffer will never return FALSE,
|
||||
* so suspension need not be handled.
|
||||
*/
|
||||
}
|
||||
src->next_input_byte += (size_t)num_bytes;
|
||||
src->bytes_in_buffer -= (size_t)num_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* An additional method that can be provided by data source modules is the
|
||||
* resync_to_restart method for error recovery in the presence of RST markers.
|
||||
* For the moment, this source module just uses the default resync method
|
||||
* provided by the JPEG library. That method assumes that no backtracking
|
||||
* is possible.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Terminate source --- called by jpeg_finish_decompress
|
||||
* after all data has been read. Often a no-op.
|
||||
*
|
||||
* NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
|
||||
* application must deal with any cleanup that should happen even
|
||||
* for error exit.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
term_source(j_decompress_ptr cinfo)
|
||||
{
|
||||
/* no work necessary here */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Prepare for input from a supplied memory buffer.
|
||||
* The buffer must contain the whole JPEG data.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_mem_src_tj(j_decompress_ptr cinfo, const unsigned char *inbuffer,
|
||||
size_t insize)
|
||||
{
|
||||
struct jpeg_source_mgr *src;
|
||||
|
||||
if (inbuffer == NULL || insize == 0) /* Treat empty input as fatal error */
|
||||
ERREXIT(cinfo, JERR_INPUT_EMPTY);
|
||||
|
||||
/* The source object is made permanent so that a series of JPEG images
|
||||
* can be read from the same buffer by calling jpeg_mem_src only before
|
||||
* the first one.
|
||||
*/
|
||||
if (cinfo->src == NULL) { /* first time for this JPEG object? */
|
||||
cinfo->src = (struct jpeg_source_mgr *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
|
||||
sizeof(struct jpeg_source_mgr));
|
||||
} else if (cinfo->src->init_source != init_mem_source) {
|
||||
/* It is unsafe to reuse the existing source manager unless it was created
|
||||
* by this function.
|
||||
*/
|
||||
ERREXIT(cinfo, JERR_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
src = cinfo->src;
|
||||
src->init_source = init_mem_source;
|
||||
src->fill_input_buffer = fill_mem_input_buffer;
|
||||
src->skip_input_data = skip_input_data;
|
||||
src->resync_to_restart = jpeg_resync_to_restart; /* use default method */
|
||||
src->term_source = term_source;
|
||||
src->bytes_in_buffer = insize;
|
||||
src->next_input_byte = (const JOCTET *)inbuffer;
|
||||
}
|
6
3rdparty/libjpeg-turbo/src/jdatasrc.c
vendored
6
3rdparty/libjpeg-turbo/src/jdatasrc.c
vendored
@ -56,13 +56,11 @@ init_source(j_decompress_ptr cinfo)
|
||||
src->start_of_file = TRUE;
|
||||
}
|
||||
|
||||
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
|
||||
METHODDEF(void)
|
||||
init_mem_source(j_decompress_ptr cinfo)
|
||||
{
|
||||
/* no work necessary here */
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
@ -123,7 +121,6 @@ fill_input_buffer(j_decompress_ptr cinfo)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
|
||||
METHODDEF(boolean)
|
||||
fill_mem_input_buffer(j_decompress_ptr cinfo)
|
||||
{
|
||||
@ -144,7 +141,6 @@ fill_mem_input_buffer(j_decompress_ptr cinfo)
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
@ -253,7 +249,6 @@ jpeg_stdio_src(j_decompress_ptr cinfo, FILE *infile)
|
||||
}
|
||||
|
||||
|
||||
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
|
||||
/*
|
||||
* Prepare for input from a supplied memory buffer.
|
||||
* The buffer must contain the whole JPEG data.
|
||||
@ -292,4 +287,3 @@ jpeg_mem_src(j_decompress_ptr cinfo, const unsigned char *inbuffer,
|
||||
src->bytes_in_buffer = (size_t)insize;
|
||||
src->next_input_byte = (const JOCTET *)inbuffer;
|
||||
}
|
||||
#endif
|
||||
|
77
3rdparty/libjpeg-turbo/src/jdcoefct.c
vendored
77
3rdparty/libjpeg-turbo/src/jdcoefct.c
vendored
@ -5,13 +5,13 @@
|
||||
* 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-2023, D. R. Commander.
|
||||
* Copyright (C) 2015, 2020, Google, Inc.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file contains the coefficient buffer controller for decompression.
|
||||
* This controller is the top level of the JPEG decompressor proper.
|
||||
* This controller is the top level of the lossy JPEG decompressor proper.
|
||||
* The coefficient buffer lies between entropy decoding and inverse-DCT steps.
|
||||
*
|
||||
* In buffered-image mode, this controller is the interface between
|
||||
@ -21,19 +21,20 @@
|
||||
|
||||
#include "jinclude.h"
|
||||
#include "jdcoefct.h"
|
||||
#include "jpegcomp.h"
|
||||
#include "jpegapicomp.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF(int) decompress_onepass(j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE output_buf);
|
||||
_JSAMPIMAGE output_buf);
|
||||
#ifdef D_MULTISCAN_FILES_SUPPORTED
|
||||
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf);
|
||||
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
|
||||
#endif
|
||||
#ifdef BLOCK_SMOOTHING_SUPPORTED
|
||||
LOCAL(boolean) smoothing_ok(j_decompress_ptr cinfo);
|
||||
METHODDEF(int) decompress_smooth_data(j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE output_buf);
|
||||
_JSAMPIMAGE output_buf);
|
||||
#endif
|
||||
|
||||
|
||||
@ -62,9 +63,9 @@ start_output_pass(j_decompress_ptr cinfo)
|
||||
/* If multipass, check to see whether to use block smoothing on this pass */
|
||||
if (coef->pub.coef_arrays != NULL) {
|
||||
if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
|
||||
coef->pub.decompress_data = decompress_smooth_data;
|
||||
coef->pub._decompress_data = decompress_smooth_data;
|
||||
else
|
||||
coef->pub.decompress_data = decompress_data;
|
||||
coef->pub._decompress_data = decompress_data;
|
||||
}
|
||||
#endif
|
||||
cinfo->output_iMCU_row = 0;
|
||||
@ -82,17 +83,17 @@ start_output_pass(j_decompress_ptr cinfo)
|
||||
*/
|
||||
|
||||
METHODDEF(int)
|
||||
decompress_onepass(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
decompress_onepass(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
|
||||
{
|
||||
my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
|
||||
JDIMENSION MCU_col_num; /* index of current MCU within row */
|
||||
JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
|
||||
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
|
||||
int blkn, ci, xindex, yindex, yoffset, useful_width;
|
||||
JSAMPARRAY output_ptr;
|
||||
_JSAMPARRAY output_ptr;
|
||||
JDIMENSION start_col, output_col;
|
||||
jpeg_component_info *compptr;
|
||||
inverse_DCT_method_ptr inverse_DCT;
|
||||
_inverse_DCT_method_ptr inverse_DCT;
|
||||
|
||||
/* Loop to process as much as one whole iMCU row */
|
||||
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
|
||||
@ -129,7 +130,7 @@ decompress_onepass(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
blkn += compptr->MCU_blocks;
|
||||
continue;
|
||||
}
|
||||
inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
|
||||
inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
|
||||
useful_width = (MCU_col_num < last_MCU_col) ?
|
||||
compptr->MCU_width : compptr->last_col_width;
|
||||
output_ptr = output_buf[compptr->component_index] +
|
||||
@ -262,7 +263,7 @@ consume_data(j_decompress_ptr cinfo)
|
||||
*/
|
||||
|
||||
METHODDEF(int)
|
||||
decompress_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
|
||||
{
|
||||
my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
|
||||
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
|
||||
@ -270,10 +271,10 @@ decompress_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
int ci, block_row, block_rows;
|
||||
JBLOCKARRAY buffer;
|
||||
JBLOCKROW buffer_ptr;
|
||||
JSAMPARRAY output_ptr;
|
||||
_JSAMPARRAY output_ptr;
|
||||
JDIMENSION output_col;
|
||||
jpeg_component_info *compptr;
|
||||
inverse_DCT_method_ptr inverse_DCT;
|
||||
_inverse_DCT_method_ptr inverse_DCT;
|
||||
|
||||
/* Force some input to be done if we are getting ahead of the input. */
|
||||
while (cinfo->input_scan_number < cinfo->output_scan_number ||
|
||||
@ -302,7 +303,7 @@ decompress_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
|
||||
if (block_rows == 0) block_rows = compptr->v_samp_factor;
|
||||
}
|
||||
inverse_DCT = cinfo->idct->inverse_DCT[ci];
|
||||
inverse_DCT = cinfo->idct->_inverse_DCT[ci];
|
||||
output_ptr = output_buf[ci];
|
||||
/* Loop over all DCT blocks to be processed. */
|
||||
for (block_row = 0; block_row < block_rows; block_row++) {
|
||||
@ -425,19 +426,20 @@ smoothing_ok(j_decompress_ptr cinfo)
|
||||
*/
|
||||
|
||||
METHODDEF(int)
|
||||
decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
decompress_smooth_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
|
||||
{
|
||||
my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
|
||||
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
|
||||
JDIMENSION block_num, last_block_column;
|
||||
int ci, block_row, block_rows, access_rows;
|
||||
int ci, block_row, block_rows, access_rows, image_block_row,
|
||||
image_block_rows;
|
||||
JBLOCKARRAY buffer;
|
||||
JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
|
||||
JBLOCKROW next_block_row, next_next_block_row;
|
||||
JSAMPARRAY output_ptr;
|
||||
_JSAMPARRAY output_ptr;
|
||||
JDIMENSION output_col;
|
||||
jpeg_component_info *compptr;
|
||||
inverse_DCT_method_ptr inverse_DCT;
|
||||
_inverse_DCT_method_ptr inverse_DCT;
|
||||
boolean change_dc;
|
||||
JCOEF *workspace;
|
||||
int *coef_bits;
|
||||
@ -475,7 +477,7 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
if (!compptr->component_needed)
|
||||
continue;
|
||||
/* Count non-dummy DCT block rows in this iMCU row. */
|
||||
if (cinfo->output_iMCU_row < last_iMCU_row - 1) {
|
||||
if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
|
||||
block_rows = compptr->v_samp_factor;
|
||||
access_rows = block_rows * 3; /* this and next two iMCU rows */
|
||||
} else if (cinfo->output_iMCU_row < last_iMCU_row) {
|
||||
@ -496,6 +498,7 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
(JDIMENSION)access_rows, FALSE);
|
||||
buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
|
||||
} else if (cinfo->output_iMCU_row > 0) {
|
||||
access_rows += compptr->v_samp_factor; /* prior iMCU row too */
|
||||
buffer = (*cinfo->mem->access_virt_barray)
|
||||
((j_common_ptr)cinfo, coef->whole_image[ci],
|
||||
(cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
|
||||
@ -535,32 +538,33 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
Q21 = quanttbl->quantval[Q21_POS];
|
||||
Q30 = quanttbl->quantval[Q30_POS];
|
||||
}
|
||||
inverse_DCT = cinfo->idct->inverse_DCT[ci];
|
||||
inverse_DCT = cinfo->idct->_inverse_DCT[ci];
|
||||
output_ptr = output_buf[ci];
|
||||
/* Loop over all DCT blocks to be processed. */
|
||||
image_block_rows = block_rows * cinfo->total_iMCU_rows;
|
||||
for (block_row = 0; block_row < block_rows; block_row++) {
|
||||
image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
|
||||
buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
|
||||
|
||||
if (block_row > 0 || cinfo->output_iMCU_row > 0)
|
||||
if (image_block_row > 0)
|
||||
prev_block_row =
|
||||
buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
|
||||
else
|
||||
prev_block_row = buffer_ptr;
|
||||
|
||||
if (block_row > 1 || cinfo->output_iMCU_row > 1)
|
||||
if (image_block_row > 1)
|
||||
prev_prev_block_row =
|
||||
buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
|
||||
else
|
||||
prev_prev_block_row = prev_block_row;
|
||||
|
||||
if (block_row < block_rows - 1 || cinfo->output_iMCU_row < last_iMCU_row)
|
||||
if (image_block_row < image_block_rows - 1)
|
||||
next_block_row =
|
||||
buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
|
||||
else
|
||||
next_block_row = buffer_ptr;
|
||||
|
||||
if (block_row < block_rows - 2 ||
|
||||
cinfo->output_iMCU_row < last_iMCU_row - 1)
|
||||
if (image_block_row < image_block_rows - 2)
|
||||
next_next_block_row =
|
||||
buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
|
||||
else
|
||||
@ -583,11 +587,11 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
/* Update DC values */
|
||||
if (block_num == cinfo->master->first_MCU_col[ci] &&
|
||||
block_num < last_block_column) {
|
||||
DC04 = (int)prev_prev_block_row[1][0];
|
||||
DC09 = (int)prev_block_row[1][0];
|
||||
DC14 = (int)buffer_ptr[1][0];
|
||||
DC19 = (int)next_block_row[1][0];
|
||||
DC24 = (int)next_next_block_row[1][0];
|
||||
DC04 = DC05 = (int)prev_prev_block_row[1][0];
|
||||
DC09 = DC10 = (int)prev_block_row[1][0];
|
||||
DC14 = DC15 = (int)buffer_ptr[1][0];
|
||||
DC19 = DC20 = (int)next_block_row[1][0];
|
||||
DC24 = DC25 = (int)next_next_block_row[1][0];
|
||||
}
|
||||
if (block_num + 1 < last_block_column) {
|
||||
DC05 = (int)prev_prev_block_row[2][0];
|
||||
@ -810,10 +814,13 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
_jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_coef_ptr coef;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
coef = (my_coef_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_coef_controller));
|
||||
@ -850,7 +857,7 @@ jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
(JDIMENSION)access_rows);
|
||||
}
|
||||
coef->pub.consume_data = consume_data;
|
||||
coef->pub.decompress_data = decompress_data;
|
||||
coef->pub._decompress_data = decompress_data;
|
||||
coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
@ -867,7 +874,7 @@ jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
coef->MCU_buffer[i] = buffer + i;
|
||||
}
|
||||
coef->pub.consume_data = dummy_consume_data;
|
||||
coef->pub.decompress_data = decompress_onepass;
|
||||
coef->pub._decompress_data = decompress_onepass;
|
||||
coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
|
||||
}
|
||||
|
||||
|
5
3rdparty/libjpeg-turbo/src/jdcoefct.h
vendored
5
3rdparty/libjpeg-turbo/src/jdcoefct.h
vendored
@ -6,6 +6,7 @@
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
||||
* Copyright (C) 2020, Google, Inc.
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*/
|
||||
@ -14,6 +15,8 @@
|
||||
#include "jpeglib.h"
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
|
||||
|
||||
/* Block smoothing is only applicable for progressive JPEG, so: */
|
||||
#ifndef D_PROGRESSIVE_SUPPORTED
|
||||
#undef BLOCK_SMOOTHING_SUPPORTED
|
||||
@ -81,3 +84,5 @@ start_iMCU_row(j_decompress_ptr cinfo)
|
||||
coef->MCU_ctr = 0;
|
||||
coef->MCU_vert_offset = 0;
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */
|
||||
|
62
3rdparty/libjpeg-turbo/src/jdcol565.c
vendored
62
3rdparty/libjpeg-turbo/src/jdcol565.c
vendored
@ -5,7 +5,7 @@
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Modifications:
|
||||
* Copyright (C) 2013, Linaro Limited.
|
||||
* Copyright (C) 2014-2015, D. R. Commander.
|
||||
* Copyright (C) 2014-2015, 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -17,18 +17,19 @@
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
ycc_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf,
|
||||
ycc_rgb565_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf,
|
||||
int num_rows)
|
||||
{
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
|
||||
register int y, cb, cr;
|
||||
register JSAMPROW outptr;
|
||||
register JSAMPROW inptr0, inptr1, inptr2;
|
||||
register _JSAMPROW outptr;
|
||||
register _JSAMPROW inptr0, inptr1, inptr2;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->output_width;
|
||||
/* copy these pointers into registers if possible */
|
||||
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
|
||||
register int *Crrtab = cconvert->Cr_r_tab;
|
||||
register int *Cbbtab = cconvert->Cb_b_tab;
|
||||
register JLONG *Crgtab = cconvert->Cr_g_tab;
|
||||
@ -91,23 +92,27 @@ ycc_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
*(INT16 *)outptr = (INT16)rgb;
|
||||
}
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
ycc_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf,
|
||||
ycc_rgb565D_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf,
|
||||
int num_rows)
|
||||
{
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
|
||||
register int y, cb, cr;
|
||||
register JSAMPROW outptr;
|
||||
register JSAMPROW inptr0, inptr1, inptr2;
|
||||
register _JSAMPROW outptr;
|
||||
register _JSAMPROW inptr0, inptr1, inptr2;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->output_width;
|
||||
/* copy these pointers into registers if possible */
|
||||
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
|
||||
register int *Crrtab = cconvert->Cr_r_tab;
|
||||
register int *Cbbtab = cconvert->Cb_b_tab;
|
||||
register JLONG *Crgtab = cconvert->Cr_g_tab;
|
||||
@ -177,17 +182,20 @@ ycc_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
*(INT16 *)outptr = (INT16)rgb;
|
||||
}
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
rgb_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf,
|
||||
rgb_rgb565_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf,
|
||||
int num_rows)
|
||||
{
|
||||
register JSAMPROW outptr;
|
||||
register JSAMPROW inptr0, inptr1, inptr2;
|
||||
register _JSAMPROW outptr;
|
||||
register _JSAMPROW inptr0, inptr1, inptr2;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->output_width;
|
||||
SHIFT_TEMPS
|
||||
@ -237,14 +245,14 @@ rgb_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
rgb_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf,
|
||||
rgb_rgb565D_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf,
|
||||
int num_rows)
|
||||
{
|
||||
register JSAMPROW outptr;
|
||||
register JSAMPROW inptr0, inptr1, inptr2;
|
||||
register _JSAMPROW outptr;
|
||||
register _JSAMPROW inptr0, inptr1, inptr2;
|
||||
register JDIMENSION col;
|
||||
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
|
||||
JDIMENSION num_cols = cinfo->output_width;
|
||||
JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
|
||||
SHIFT_TEMPS
|
||||
@ -296,11 +304,11 @@ rgb_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
gray_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf,
|
||||
gray_rgb565_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf,
|
||||
int num_rows)
|
||||
{
|
||||
register JSAMPROW inptr, outptr;
|
||||
register _JSAMPROW inptr, outptr;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->output_width;
|
||||
|
||||
@ -336,13 +344,13 @@ gray_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
gray_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf,
|
||||
gray_rgb565D_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf,
|
||||
int num_rows)
|
||||
{
|
||||
register JSAMPROW inptr, outptr;
|
||||
register _JSAMPROW inptr, outptr;
|
||||
register JDIMENSION col;
|
||||
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
|
||||
JDIMENSION num_cols = cinfo->output_width;
|
||||
JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
|
||||
|
||||
|
48
3rdparty/libjpeg-turbo/src/jdcolext.c
vendored
48
3rdparty/libjpeg-turbo/src/jdcolext.c
vendored
@ -4,7 +4,7 @@
|
||||
* 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, 2015, D. R. Commander.
|
||||
* Copyright (C) 2009, 2011, 2015, 2022-2023, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -28,18 +28,19 @@
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
ycc_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf,
|
||||
ycc_rgb_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf,
|
||||
int num_rows)
|
||||
{
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
|
||||
register int y, cb, cr;
|
||||
register JSAMPROW outptr;
|
||||
register JSAMPROW inptr0, inptr1, inptr2;
|
||||
register _JSAMPROW outptr;
|
||||
register _JSAMPROW inptr0, inptr1, inptr2;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->output_width;
|
||||
/* copy these pointers into registers if possible */
|
||||
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
|
||||
register int *Crrtab = cconvert->Cr_r_tab;
|
||||
register int *Cbbtab = cconvert->Cb_b_tab;
|
||||
register JLONG *Crgtab = cconvert->Cr_g_tab;
|
||||
@ -62,14 +63,17 @@ ycc_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
|
||||
SCALEBITS))];
|
||||
outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
|
||||
/* Set unused byte to 0xFF so it can be interpreted as an opaque */
|
||||
/* alpha channel value */
|
||||
/* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
|
||||
/* opaque alpha channel value */
|
||||
#ifdef RGB_ALPHA
|
||||
outptr[RGB_ALPHA] = 0xFF;
|
||||
outptr[RGB_ALPHA] = _MAXJSAMPLE;
|
||||
#endif
|
||||
outptr += RGB_PIXELSIZE;
|
||||
}
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -81,11 +85,11 @@ ycc_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
gray_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf,
|
||||
gray_rgb_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf,
|
||||
int num_rows)
|
||||
{
|
||||
register JSAMPROW inptr, outptr;
|
||||
register _JSAMPROW inptr, outptr;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->output_width;
|
||||
|
||||
@ -94,10 +98,10 @@ gray_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
outptr = *output_buf++;
|
||||
for (col = 0; col < num_cols; col++) {
|
||||
outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
|
||||
/* Set unused byte to 0xFF so it can be interpreted as an opaque */
|
||||
/* alpha channel value */
|
||||
/* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
|
||||
/* opaque alpha channel value */
|
||||
#ifdef RGB_ALPHA
|
||||
outptr[RGB_ALPHA] = 0xFF;
|
||||
outptr[RGB_ALPHA] = _MAXJSAMPLE;
|
||||
#endif
|
||||
outptr += RGB_PIXELSIZE;
|
||||
}
|
||||
@ -111,12 +115,12 @@ gray_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
rgb_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf,
|
||||
rgb_rgb_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf,
|
||||
int num_rows)
|
||||
{
|
||||
register JSAMPROW inptr0, inptr1, inptr2;
|
||||
register JSAMPROW outptr;
|
||||
register _JSAMPROW inptr0, inptr1, inptr2;
|
||||
register _JSAMPROW outptr;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->output_width;
|
||||
|
||||
@ -130,10 +134,10 @@ rgb_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
outptr[RGB_RED] = inptr0[col];
|
||||
outptr[RGB_GREEN] = inptr1[col];
|
||||
outptr[RGB_BLUE] = inptr2[col];
|
||||
/* Set unused byte to 0xFF so it can be interpreted as an opaque */
|
||||
/* alpha channel value */
|
||||
/* Set unused byte to _MAXJSAMPLE so it can be interpreted as an */
|
||||
/* opaque alpha channel value */
|
||||
#ifdef RGB_ALPHA
|
||||
outptr[RGB_ALPHA] = 0xFF;
|
||||
outptr[RGB_ALPHA] = _MAXJSAMPLE;
|
||||
#endif
|
||||
outptr += RGB_PIXELSIZE;
|
||||
}
|
||||
|
193
3rdparty/libjpeg-turbo/src/jdcolor.c
vendored
193
3rdparty/libjpeg-turbo/src/jdcolor.c
vendored
@ -6,7 +6,7 @@
|
||||
* Modified 2011 by Guido Vollbeding.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
||||
* Copyright (C) 2009, 2011-2012, 2014-2015, D. R. Commander.
|
||||
* Copyright (C) 2009, 2011-2012, 2014-2015, 2022, D. R. Commander.
|
||||
* Copyright (C) 2013, Linaro Limited.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
@ -18,14 +18,17 @@
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jsimd.h"
|
||||
#include "jconfigint.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
|
||||
|
||||
/* Private subobject */
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_color_deconverter pub; /* public fields */
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
/* Private state for YCC->RGB conversion */
|
||||
int *Cr_r_tab; /* => table for Cr to R conversion */
|
||||
int *Cb_b_tab; /* => table for Cb to B conversion */
|
||||
@ -34,6 +37,7 @@ typedef struct {
|
||||
|
||||
/* Private state for RGB->Y conversion */
|
||||
JLONG *rgb_y_tab; /* => table for RGB to Y conversion */
|
||||
#endif
|
||||
} my_color_deconverter;
|
||||
|
||||
typedef my_color_deconverter *my_cconvert_ptr;
|
||||
@ -44,7 +48,7 @@ typedef my_color_deconverter *my_cconvert_ptr;
|
||||
|
||||
/*
|
||||
* YCbCr is defined per CCIR 601-1, except that Cb and Cr are
|
||||
* normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
|
||||
* normalized to the range 0.._MAXJSAMPLE rather than -0.5 .. 0.5.
|
||||
* The conversion equations to be implemented are therefore
|
||||
*
|
||||
* R = Y + 1.40200 * Cr
|
||||
@ -53,7 +57,7 @@ typedef my_color_deconverter *my_cconvert_ptr;
|
||||
*
|
||||
* Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
|
||||
*
|
||||
* where Cb and Cr represent the incoming values less CENTERJSAMPLE.
|
||||
* where Cb and Cr represent the incoming values less _CENTERJSAMPLE.
|
||||
* (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
|
||||
*
|
||||
* To avoid floating-point arithmetic, we represent the fractional constants
|
||||
@ -64,7 +68,7 @@ typedef my_color_deconverter *my_cconvert_ptr;
|
||||
*
|
||||
* For even more speed, we avoid doing any multiplications in the inner loop
|
||||
* by precalculating the constants times Cb and Cr for all possible values.
|
||||
* For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
|
||||
* For 8-bit samples this is very reasonable (only 256 entries per table);
|
||||
* for 12-bit samples it is still acceptable. It's not very reasonable for
|
||||
* 16-bit samples, but if you want lossless storage you shouldn't be changing
|
||||
* colorspace anyway.
|
||||
@ -85,9 +89,9 @@ typedef my_color_deconverter *my_cconvert_ptr;
|
||||
*/
|
||||
|
||||
#define R_Y_OFF 0 /* offset to R => Y section */
|
||||
#define G_Y_OFF (1 * (MAXJSAMPLE + 1)) /* offset to G => Y section */
|
||||
#define B_Y_OFF (2 * (MAXJSAMPLE + 1)) /* etc. */
|
||||
#define TABLE_SIZE (3 * (MAXJSAMPLE + 1))
|
||||
#define G_Y_OFF (1 * (_MAXJSAMPLE + 1)) /* offset to G => Y section */
|
||||
#define B_Y_OFF (2 * (_MAXJSAMPLE + 1)) /* etc. */
|
||||
#define TABLE_SIZE (3 * (_MAXJSAMPLE + 1))
|
||||
|
||||
|
||||
/* Include inline routines for colorspace extensions */
|
||||
@ -210,6 +214,7 @@ typedef my_color_deconverter *my_cconvert_ptr;
|
||||
LOCAL(void)
|
||||
build_ycc_rgb_table(j_decompress_ptr cinfo)
|
||||
{
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
|
||||
int i;
|
||||
JLONG x;
|
||||
@ -217,20 +222,20 @@ build_ycc_rgb_table(j_decompress_ptr cinfo)
|
||||
|
||||
cconvert->Cr_r_tab = (int *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE + 1) * sizeof(int));
|
||||
(_MAXJSAMPLE + 1) * sizeof(int));
|
||||
cconvert->Cb_b_tab = (int *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE + 1) * sizeof(int));
|
||||
(_MAXJSAMPLE + 1) * sizeof(int));
|
||||
cconvert->Cr_g_tab = (JLONG *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE + 1) * sizeof(JLONG));
|
||||
(_MAXJSAMPLE + 1) * sizeof(JLONG));
|
||||
cconvert->Cb_g_tab = (JLONG *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE + 1) * sizeof(JLONG));
|
||||
(_MAXJSAMPLE + 1) * sizeof(JLONG));
|
||||
|
||||
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
|
||||
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
|
||||
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
|
||||
for (i = 0, x = -_CENTERJSAMPLE; i <= _MAXJSAMPLE; i++, x++) {
|
||||
/* i is the actual input pixel value, in the range 0.._MAXJSAMPLE */
|
||||
/* The Cb or Cr value we are thinking of is x = i - _CENTERJSAMPLE */
|
||||
/* Cr=>R value is nearest int to 1.40200 * x */
|
||||
cconvert->Cr_r_tab[i] = (int)
|
||||
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
|
||||
@ -243,6 +248,9 @@ build_ycc_rgb_table(j_decompress_ptr cinfo)
|
||||
/* We also add in ONE_HALF so that need not do it in inner loop */
|
||||
cconvert->Cb_g_tab[i] = (-FIX(0.34414)) * x + ONE_HALF;
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -251,8 +259,8 @@ build_ycc_rgb_table(j_decompress_ptr cinfo)
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
|
||||
ycc_rgb_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
switch (cinfo->out_color_space) {
|
||||
case JCS_EXT_RGB:
|
||||
@ -301,6 +309,7 @@ ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
LOCAL(void)
|
||||
build_rgb_y_table(j_decompress_ptr cinfo)
|
||||
{
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
|
||||
JLONG *rgb_y_tab;
|
||||
JLONG i;
|
||||
@ -310,11 +319,14 @@ build_rgb_y_table(j_decompress_ptr cinfo)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(TABLE_SIZE * sizeof(JLONG)));
|
||||
|
||||
for (i = 0; i <= MAXJSAMPLE; i++) {
|
||||
for (i = 0; i <= _MAXJSAMPLE; i++) {
|
||||
rgb_y_tab[i + R_Y_OFF] = FIX(0.29900) * i;
|
||||
rgb_y_tab[i + G_Y_OFF] = FIX(0.58700) * i;
|
||||
rgb_y_tab[i + B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -323,14 +335,15 @@ build_rgb_y_table(j_decompress_ptr cinfo)
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
rgb_gray_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
|
||||
rgb_gray_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
|
||||
register int r, g, b;
|
||||
register JLONG *ctab = cconvert->rgb_y_tab;
|
||||
register JSAMPROW outptr;
|
||||
register JSAMPROW inptr0, inptr1, inptr2;
|
||||
register _JSAMPROW outptr;
|
||||
register _JSAMPROW inptr0, inptr1, inptr2;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->output_width;
|
||||
|
||||
@ -345,10 +358,13 @@ rgb_gray_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
g = inptr1[col];
|
||||
b = inptr2[col];
|
||||
/* Y */
|
||||
outptr[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
|
||||
ctab[b + B_Y_OFF]) >> SCALEBITS);
|
||||
outptr[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
|
||||
ctab[b + B_Y_OFF]) >> SCALEBITS);
|
||||
}
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -358,10 +374,10 @@ rgb_gray_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
null_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
|
||||
null_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
register JSAMPROW inptr, inptr0, inptr1, inptr2, inptr3, outptr;
|
||||
register _JSAMPROW inptr, inptr0, inptr1, inptr2, inptr3, outptr;
|
||||
register JDIMENSION col;
|
||||
register int num_components = cinfo->num_components;
|
||||
JDIMENSION num_cols = cinfo->output_width;
|
||||
@ -419,11 +435,11 @@ null_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
grayscale_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
|
||||
grayscale_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
jcopy_sample_rows(input_buf[0], (int)input_row, output_buf, 0, num_rows,
|
||||
cinfo->output_width);
|
||||
_jcopy_sample_rows(input_buf[0], (int)input_row, output_buf, 0, num_rows,
|
||||
cinfo->output_width);
|
||||
}
|
||||
|
||||
|
||||
@ -432,8 +448,8 @@ grayscale_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
gray_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
|
||||
gray_rgb_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
switch (cinfo->out_color_space) {
|
||||
case JCS_EXT_RGB:
|
||||
@ -477,8 +493,8 @@ gray_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
rgb_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
|
||||
rgb_rgb_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
switch (cinfo->out_color_space) {
|
||||
case JCS_EXT_RGB:
|
||||
@ -525,17 +541,18 @@ rgb_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
ycck_cmyk_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
|
||||
ycck_cmyk_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
|
||||
register int y, cb, cr;
|
||||
register JSAMPROW outptr;
|
||||
register JSAMPROW inptr0, inptr1, inptr2, inptr3;
|
||||
register _JSAMPROW outptr;
|
||||
register _JSAMPROW inptr0, inptr1, inptr2, inptr3;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->output_width;
|
||||
/* copy these pointers into registers if possible */
|
||||
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
|
||||
register int *Crrtab = cconvert->Cr_r_tab;
|
||||
register int *Cbbtab = cconvert->Cb_b_tab;
|
||||
register JLONG *Crgtab = cconvert->Cr_g_tab;
|
||||
@ -554,16 +571,19 @@ ycck_cmyk_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
cb = inptr1[col];
|
||||
cr = inptr2[col];
|
||||
/* Range-limiting is essential due to noise introduced by DCT losses. */
|
||||
outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
|
||||
outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
|
||||
outptr[0] = range_limit[_MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
|
||||
outptr[1] = range_limit[_MAXJSAMPLE - (y + /* green */
|
||||
((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
|
||||
SCALEBITS)))];
|
||||
outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
|
||||
outptr[2] = range_limit[_MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
|
||||
/* K passes through unchanged */
|
||||
outptr[3] = inptr3[col];
|
||||
outptr += 4;
|
||||
}
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -653,8 +673,8 @@ static INLINE boolean is_big_endian(void)
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
|
||||
ycc_rgb565_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
if (is_big_endian())
|
||||
ycc_rgb565_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
|
||||
@ -664,8 +684,8 @@ ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
ycc_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
|
||||
ycc_rgb565D_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
if (is_big_endian())
|
||||
ycc_rgb565D_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
|
||||
@ -675,8 +695,8 @@ ycc_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
rgb_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
|
||||
rgb_rgb565_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
if (is_big_endian())
|
||||
rgb_rgb565_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
|
||||
@ -686,8 +706,8 @@ rgb_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
rgb_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
|
||||
rgb_rgb565D_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
if (is_big_endian())
|
||||
rgb_rgb565D_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
|
||||
@ -697,8 +717,8 @@ rgb_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
gray_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
|
||||
gray_rgb565_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
if (is_big_endian())
|
||||
gray_rgb565_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
|
||||
@ -708,8 +728,8 @@ gray_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
gray_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
|
||||
gray_rgb565D_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
if (is_big_endian())
|
||||
gray_rgb565D_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
|
||||
@ -734,11 +754,14 @@ start_pass_dcolor(j_decompress_ptr cinfo)
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_color_deconverter(j_decompress_ptr cinfo)
|
||||
_jinit_color_deconverter(j_decompress_ptr cinfo)
|
||||
{
|
||||
my_cconvert_ptr cconvert;
|
||||
int ci;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
cconvert = (my_cconvert_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_color_deconverter));
|
||||
@ -773,19 +796,24 @@ jinit_color_deconverter(j_decompress_ptr cinfo)
|
||||
/* Set out_color_components and conversion method based on requested space.
|
||||
* Also clear the component_needed flags for any unused components,
|
||||
* so that earlier pipeline stages can avoid useless computation.
|
||||
* NOTE: We do not allow any lossy color conversion algorithms in lossless
|
||||
* mode.
|
||||
*/
|
||||
|
||||
switch (cinfo->out_color_space) {
|
||||
case JCS_GRAYSCALE:
|
||||
if (cinfo->master->lossless &&
|
||||
cinfo->jpeg_color_space != cinfo->out_color_space)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
cinfo->out_color_components = 1;
|
||||
if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
|
||||
cinfo->jpeg_color_space == JCS_YCbCr) {
|
||||
cconvert->pub.color_convert = grayscale_convert;
|
||||
cconvert->pub._color_convert = grayscale_convert;
|
||||
/* For color->grayscale conversion, only the Y (0) component is needed */
|
||||
for (ci = 1; ci < cinfo->num_components; ci++)
|
||||
cinfo->comp_info[ci].component_needed = FALSE;
|
||||
} else if (cinfo->jpeg_color_space == JCS_RGB) {
|
||||
cconvert->pub.color_convert = rgb_gray_convert;
|
||||
cconvert->pub._color_convert = rgb_gray_convert;
|
||||
build_rgb_y_table(cinfo);
|
||||
} else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
@ -802,65 +830,78 @@ jinit_color_deconverter(j_decompress_ptr cinfo)
|
||||
case JCS_EXT_BGRA:
|
||||
case JCS_EXT_ABGR:
|
||||
case JCS_EXT_ARGB:
|
||||
if (cinfo->master->lossless && cinfo->jpeg_color_space != JCS_RGB)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space];
|
||||
if (cinfo->jpeg_color_space == JCS_YCbCr) {
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_ycc_rgb())
|
||||
cconvert->pub.color_convert = jsimd_ycc_rgb_convert;
|
||||
else {
|
||||
cconvert->pub.color_convert = ycc_rgb_convert;
|
||||
cconvert->pub._color_convert = jsimd_ycc_rgb_convert;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
cconvert->pub._color_convert = ycc_rgb_convert;
|
||||
build_ycc_rgb_table(cinfo);
|
||||
}
|
||||
} else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
|
||||
cconvert->pub.color_convert = gray_rgb_convert;
|
||||
cconvert->pub._color_convert = gray_rgb_convert;
|
||||
} else if (cinfo->jpeg_color_space == JCS_RGB) {
|
||||
if (rgb_red[cinfo->out_color_space] == 0 &&
|
||||
rgb_green[cinfo->out_color_space] == 1 &&
|
||||
rgb_blue[cinfo->out_color_space] == 2 &&
|
||||
rgb_pixelsize[cinfo->out_color_space] == 3)
|
||||
cconvert->pub.color_convert = null_convert;
|
||||
cconvert->pub._color_convert = null_convert;
|
||||
else
|
||||
cconvert->pub.color_convert = rgb_rgb_convert;
|
||||
cconvert->pub._color_convert = rgb_rgb_convert;
|
||||
} else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
break;
|
||||
|
||||
case JCS_RGB565:
|
||||
if (cinfo->master->lossless)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
cinfo->out_color_components = 3;
|
||||
if (cinfo->dither_mode == JDITHER_NONE) {
|
||||
if (cinfo->jpeg_color_space == JCS_YCbCr) {
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_ycc_rgb565())
|
||||
cconvert->pub.color_convert = jsimd_ycc_rgb565_convert;
|
||||
else {
|
||||
cconvert->pub.color_convert = ycc_rgb565_convert;
|
||||
cconvert->pub._color_convert = jsimd_ycc_rgb565_convert;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
cconvert->pub._color_convert = ycc_rgb565_convert;
|
||||
build_ycc_rgb_table(cinfo);
|
||||
}
|
||||
} else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
|
||||
cconvert->pub.color_convert = gray_rgb565_convert;
|
||||
cconvert->pub._color_convert = gray_rgb565_convert;
|
||||
} else if (cinfo->jpeg_color_space == JCS_RGB) {
|
||||
cconvert->pub.color_convert = rgb_rgb565_convert;
|
||||
cconvert->pub._color_convert = rgb_rgb565_convert;
|
||||
} else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
} else {
|
||||
/* only ordered dithering is supported */
|
||||
if (cinfo->jpeg_color_space == JCS_YCbCr) {
|
||||
cconvert->pub.color_convert = ycc_rgb565D_convert;
|
||||
cconvert->pub._color_convert = ycc_rgb565D_convert;
|
||||
build_ycc_rgb_table(cinfo);
|
||||
} else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
|
||||
cconvert->pub.color_convert = gray_rgb565D_convert;
|
||||
cconvert->pub._color_convert = gray_rgb565D_convert;
|
||||
} else if (cinfo->jpeg_color_space == JCS_RGB) {
|
||||
cconvert->pub.color_convert = rgb_rgb565D_convert;
|
||||
cconvert->pub._color_convert = rgb_rgb565D_convert;
|
||||
} else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
}
|
||||
break;
|
||||
|
||||
case JCS_CMYK:
|
||||
if (cinfo->master->lossless &&
|
||||
cinfo->jpeg_color_space != cinfo->out_color_space)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
cinfo->out_color_components = 4;
|
||||
if (cinfo->jpeg_color_space == JCS_YCCK) {
|
||||
cconvert->pub.color_convert = ycck_cmyk_convert;
|
||||
cconvert->pub._color_convert = ycck_cmyk_convert;
|
||||
build_ycc_rgb_table(cinfo);
|
||||
} else if (cinfo->jpeg_color_space == JCS_CMYK) {
|
||||
cconvert->pub.color_convert = null_convert;
|
||||
cconvert->pub._color_convert = null_convert;
|
||||
} else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
break;
|
||||
@ -869,7 +910,7 @@ jinit_color_deconverter(j_decompress_ptr cinfo)
|
||||
/* Permit null conversion to same output space */
|
||||
if (cinfo->out_color_space == cinfo->jpeg_color_space) {
|
||||
cinfo->out_color_components = cinfo->num_components;
|
||||
cconvert->pub.color_convert = null_convert;
|
||||
cconvert->pub._color_convert = null_convert;
|
||||
} else /* unsupported non-null conversion */
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
break;
|
||||
@ -880,3 +921,5 @@ jinit_color_deconverter(j_decompress_ptr cinfo)
|
||||
else
|
||||
cinfo->output_components = cinfo->out_color_components;
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */
|
||||
|
135
3rdparty/libjpeg-turbo/src/jdct.h
vendored
135
3rdparty/libjpeg-turbo/src/jdct.h
vendored
@ -4,7 +4,7 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2015, D. R. Commander.
|
||||
* Copyright (C) 2015, 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -15,13 +15,15 @@
|
||||
* machine-dependent tuning (e.g., assembly coding).
|
||||
*/
|
||||
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
|
||||
/*
|
||||
* A forward DCT routine is given a pointer to a work area of type DCTELEM[];
|
||||
* the DCT is to be performed in-place in that buffer. Type DCTELEM is int
|
||||
* for 8-bit samples, JLONG for 12-bit samples. (NOTE: Floating-point DCT
|
||||
* implementations use an array of type FAST_FLOAT, instead.)
|
||||
* The DCT inputs are expected to be signed (range +-CENTERJSAMPLE).
|
||||
* The DCT inputs are expected to be signed (range +-_CENTERJSAMPLE).
|
||||
* The DCT outputs are returned scaled up by a factor of 8; they therefore
|
||||
* have a range of +-8K for 8-bit data, +-128K for 12-bit data. This
|
||||
* convention improves accuracy in integer implementations and saves some
|
||||
@ -76,78 +78,89 @@ typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
|
||||
|
||||
/*
|
||||
* Each IDCT routine is responsible for range-limiting its results and
|
||||
* converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
|
||||
* converting them to unsigned form (0.._MAXJSAMPLE). The raw outputs could
|
||||
* be quite far out of range if the input data is corrupt, so a bulletproof
|
||||
* range-limiting step is required. We use a mask-and-table-lookup method
|
||||
* to do the combined operations quickly. See the comments with
|
||||
* prepare_range_limit_table (in jdmaster.c) for more info.
|
||||
*/
|
||||
|
||||
#define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
|
||||
#define IDCT_range_limit(cinfo) \
|
||||
((_JSAMPLE *)((cinfo)->sample_range_limit) + _CENTERJSAMPLE)
|
||||
|
||||
#define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
|
||||
#define RANGE_MASK (_MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
|
||||
|
||||
|
||||
/* Extern declarations for the forward and inverse DCT routines. */
|
||||
|
||||
EXTERN(void) jpeg_fdct_islow(DCTELEM *data);
|
||||
EXTERN(void) jpeg_fdct_ifast(DCTELEM *data);
|
||||
EXTERN(void) _jpeg_fdct_islow(DCTELEM *data);
|
||||
EXTERN(void) _jpeg_fdct_ifast(DCTELEM *data);
|
||||
EXTERN(void) jpeg_fdct_float(FAST_FLOAT *data);
|
||||
|
||||
EXTERN(void) jpeg_idct_islow(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_ifast(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_float(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_7x7(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_6x6(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_5x5(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_4x4(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_3x3(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_2x2(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_1x1(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_9x9(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_10x10(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_11x11(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_12x12(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_13x13(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_14x14(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_15x15(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) jpeg_idct_16x16(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_islow(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_ifast(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_float(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_7x7(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
_JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_6x6(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
_JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_5x5(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
_JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_4x4(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
_JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_3x3(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
_JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_2x2(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
_JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_1x1(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
_JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_9x9(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr, JCOEFPTR coef_block,
|
||||
_JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_10x10(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_11x11(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_12x12(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_13x13(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_14x14(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_15x15(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col);
|
||||
EXTERN(void) _jpeg_idct_16x16(j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col);
|
||||
|
||||
|
||||
/*
|
||||
|
61
3rdparty/libjpeg-turbo/src/jddctmgr.c
vendored
61
3rdparty/libjpeg-turbo/src/jddctmgr.c
vendored
@ -26,7 +26,7 @@
|
||||
#include "jpeglib.h"
|
||||
#include "jdct.h" /* Private declarations for DCT subsystem */
|
||||
#include "jsimddct.h"
|
||||
#include "jpegcomp.h"
|
||||
#include "jpegapicomp.h"
|
||||
|
||||
|
||||
/*
|
||||
@ -100,7 +100,7 @@ start_pass(j_decompress_ptr cinfo)
|
||||
int ci, i;
|
||||
jpeg_component_info *compptr;
|
||||
int method = 0;
|
||||
inverse_DCT_method_ptr method_ptr = NULL;
|
||||
_inverse_DCT_method_ptr method_ptr = NULL;
|
||||
JQUANT_TBL *qtbl;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
@ -109,42 +109,46 @@ start_pass(j_decompress_ptr cinfo)
|
||||
switch (compptr->_DCT_scaled_size) {
|
||||
#ifdef IDCT_SCALING_SUPPORTED
|
||||
case 1:
|
||||
method_ptr = jpeg_idct_1x1;
|
||||
method_ptr = _jpeg_idct_1x1;
|
||||
method = JDCT_ISLOW; /* jidctred uses islow-style table */
|
||||
break;
|
||||
case 2:
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_idct_2x2())
|
||||
method_ptr = jsimd_idct_2x2;
|
||||
else
|
||||
method_ptr = jpeg_idct_2x2;
|
||||
#endif
|
||||
method_ptr = _jpeg_idct_2x2;
|
||||
method = JDCT_ISLOW; /* jidctred uses islow-style table */
|
||||
break;
|
||||
case 3:
|
||||
method_ptr = jpeg_idct_3x3;
|
||||
method_ptr = _jpeg_idct_3x3;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case 4:
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_idct_4x4())
|
||||
method_ptr = jsimd_idct_4x4;
|
||||
else
|
||||
method_ptr = jpeg_idct_4x4;
|
||||
#endif
|
||||
method_ptr = _jpeg_idct_4x4;
|
||||
method = JDCT_ISLOW; /* jidctred uses islow-style table */
|
||||
break;
|
||||
case 5:
|
||||
method_ptr = jpeg_idct_5x5;
|
||||
method_ptr = _jpeg_idct_5x5;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case 6:
|
||||
#if defined(__mips__)
|
||||
#if defined(WITH_SIMD) && defined(__mips__)
|
||||
if (jsimd_can_idct_6x6())
|
||||
method_ptr = jsimd_idct_6x6;
|
||||
else
|
||||
#endif
|
||||
method_ptr = jpeg_idct_6x6;
|
||||
method_ptr = _jpeg_idct_6x6;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case 7:
|
||||
method_ptr = jpeg_idct_7x7;
|
||||
method_ptr = _jpeg_idct_7x7;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
#endif
|
||||
@ -152,28 +156,34 @@ start_pass(j_decompress_ptr cinfo)
|
||||
switch (cinfo->dct_method) {
|
||||
#ifdef DCT_ISLOW_SUPPORTED
|
||||
case JDCT_ISLOW:
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_idct_islow())
|
||||
method_ptr = jsimd_idct_islow;
|
||||
else
|
||||
method_ptr = jpeg_idct_islow;
|
||||
#endif
|
||||
method_ptr = _jpeg_idct_islow;
|
||||
method = JDCT_ISLOW;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DCT_IFAST_SUPPORTED
|
||||
case JDCT_IFAST:
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_idct_ifast())
|
||||
method_ptr = jsimd_idct_ifast;
|
||||
else
|
||||
method_ptr = jpeg_idct_ifast;
|
||||
#endif
|
||||
method_ptr = _jpeg_idct_ifast;
|
||||
method = JDCT_IFAST;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DCT_FLOAT_SUPPORTED
|
||||
case JDCT_FLOAT:
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_idct_float())
|
||||
method_ptr = jsimd_idct_float;
|
||||
else
|
||||
method_ptr = jpeg_idct_float;
|
||||
#endif
|
||||
method_ptr = _jpeg_idct_float;
|
||||
method = JDCT_FLOAT;
|
||||
break;
|
||||
#endif
|
||||
@ -184,40 +194,40 @@ start_pass(j_decompress_ptr cinfo)
|
||||
break;
|
||||
#ifdef IDCT_SCALING_SUPPORTED
|
||||
case 9:
|
||||
method_ptr = jpeg_idct_9x9;
|
||||
method_ptr = _jpeg_idct_9x9;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case 10:
|
||||
method_ptr = jpeg_idct_10x10;
|
||||
method_ptr = _jpeg_idct_10x10;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case 11:
|
||||
method_ptr = jpeg_idct_11x11;
|
||||
method_ptr = _jpeg_idct_11x11;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case 12:
|
||||
#if defined(__mips__)
|
||||
#if defined(WITH_SIMD) && defined(__mips__)
|
||||
if (jsimd_can_idct_12x12())
|
||||
method_ptr = jsimd_idct_12x12;
|
||||
else
|
||||
#endif
|
||||
method_ptr = jpeg_idct_12x12;
|
||||
method_ptr = _jpeg_idct_12x12;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case 13:
|
||||
method_ptr = jpeg_idct_13x13;
|
||||
method_ptr = _jpeg_idct_13x13;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case 14:
|
||||
method_ptr = jpeg_idct_14x14;
|
||||
method_ptr = _jpeg_idct_14x14;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case 15:
|
||||
method_ptr = jpeg_idct_15x15;
|
||||
method_ptr = _jpeg_idct_15x15;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case 16:
|
||||
method_ptr = jpeg_idct_16x16;
|
||||
method_ptr = _jpeg_idct_16x16;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
#endif
|
||||
@ -225,7 +235,7 @@ start_pass(j_decompress_ptr cinfo)
|
||||
ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->_DCT_scaled_size);
|
||||
break;
|
||||
}
|
||||
idct->pub.inverse_DCT[ci] = method_ptr;
|
||||
idct->pub._inverse_DCT[ci] = method_ptr;
|
||||
/* Create multiplier table from quant table.
|
||||
* However, we can skip this if the component is uninteresting
|
||||
* or if we already built the table. Also, if no quant table
|
||||
@ -327,12 +337,15 @@ start_pass(j_decompress_ptr cinfo)
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_inverse_dct(j_decompress_ptr cinfo)
|
||||
_jinit_inverse_dct(j_decompress_ptr cinfo)
|
||||
{
|
||||
my_idct_ptr idct;
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
idct = (my_idct_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_idct_controller));
|
||||
|
403
3rdparty/libjpeg-turbo/src/jddiffct.c
vendored
Normal file
403
3rdparty/libjpeg-turbo/src/jddiffct.c
vendored
Normal file
@ -0,0 +1,403 @@
|
||||
/*
|
||||
* jddiffct.c
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file contains the [un]difference buffer controller for decompression.
|
||||
* This controller is the top level of the lossless JPEG decompressor proper.
|
||||
* The difference buffer lies between the entropy decoding and
|
||||
* prediction/undifferencing steps. The undifference buffer lies between the
|
||||
* prediction/undifferencing and scaling steps.
|
||||
*
|
||||
* In buffered-image mode, this controller is the interface between
|
||||
* input-oriented processing and output-oriented processing.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jlossls.h" /* Private declarations for lossless codec */
|
||||
|
||||
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
|
||||
/* Private buffer controller object */
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_d_coef_controller pub; /* public fields */
|
||||
|
||||
/* These variables keep track of the current location of the input side. */
|
||||
/* cinfo->input_iMCU_row is also used for this. */
|
||||
JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
|
||||
unsigned int restart_rows_to_go; /* MCU rows left in this restart
|
||||
interval */
|
||||
unsigned int MCU_vert_offset; /* counts MCU rows within iMCU row */
|
||||
unsigned int MCU_rows_per_iMCU_row; /* number of such rows needed */
|
||||
|
||||
/* The output side's location is represented by cinfo->output_iMCU_row. */
|
||||
|
||||
JDIFFARRAY diff_buf[MAX_COMPONENTS]; /* iMCU row of differences */
|
||||
JDIFFARRAY undiff_buf[MAX_COMPONENTS]; /* iMCU row of undiff'd samples */
|
||||
|
||||
#ifdef D_MULTISCAN_FILES_SUPPORTED
|
||||
/* In multi-pass modes, we need a virtual sample array for each component. */
|
||||
jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
|
||||
#endif
|
||||
} my_diff_controller;
|
||||
|
||||
typedef my_diff_controller *my_diff_ptr;
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
|
||||
#ifdef D_MULTISCAN_FILES_SUPPORTED
|
||||
METHODDEF(int) output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
|
||||
#endif
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
start_iMCU_row(j_decompress_ptr cinfo)
|
||||
/* Reset within-iMCU-row counters for a new row (input side) */
|
||||
{
|
||||
my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
|
||||
|
||||
/* In an interleaved scan, an MCU row is the same as an iMCU row.
|
||||
* In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
|
||||
* But at the bottom of the image, process only what's left.
|
||||
*/
|
||||
if (cinfo->comps_in_scan > 1) {
|
||||
diff->MCU_rows_per_iMCU_row = 1;
|
||||
} else {
|
||||
if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
|
||||
diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
|
||||
else
|
||||
diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
|
||||
}
|
||||
|
||||
diff->MCU_ctr = 0;
|
||||
diff->MCU_vert_offset = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize for an input processing pass.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
start_input_pass(j_decompress_ptr cinfo)
|
||||
{
|
||||
my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
|
||||
|
||||
/* Because it is hitching a ride on the jpeg_inverse_dct struct,
|
||||
* start_pass_lossless() will be called at the start of the output pass.
|
||||
* This ensures that it will be called at the start of the input pass as
|
||||
* well.
|
||||
*/
|
||||
(*cinfo->idct->start_pass) (cinfo);
|
||||
|
||||
/* Check that the restart interval is an integer multiple of the number
|
||||
* of MCUs in an MCU row.
|
||||
*/
|
||||
if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
|
||||
ERREXIT2(cinfo, JERR_BAD_RESTART,
|
||||
cinfo->restart_interval, cinfo->MCUs_per_row);
|
||||
|
||||
/* Initialize restart counter */
|
||||
diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
|
||||
|
||||
cinfo->input_iMCU_row = 0;
|
||||
start_iMCU_row(cinfo);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Check for a restart marker & resynchronize decoder, undifferencer.
|
||||
* Returns FALSE if must suspend.
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
process_restart(j_decompress_ptr cinfo)
|
||||
{
|
||||
my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
|
||||
|
||||
if (!(*cinfo->entropy->process_restart) (cinfo))
|
||||
return FALSE;
|
||||
|
||||
(*cinfo->idct->start_pass) (cinfo);
|
||||
|
||||
/* Reset restart counter */
|
||||
diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize for an output processing pass.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
start_output_pass(j_decompress_ptr cinfo)
|
||||
{
|
||||
cinfo->output_iMCU_row = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Decompress and return some data in the supplied buffer.
|
||||
* Always attempts to emit one fully interleaved MCU row ("iMCU" row).
|
||||
* Input and output must run in lockstep since we have only a one-MCU buffer.
|
||||
* Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
|
||||
*
|
||||
* NB: output_buf contains a plane for each component in image,
|
||||
* which we index according to the component's SOF position.
|
||||
*/
|
||||
|
||||
METHODDEF(int)
|
||||
decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
|
||||
{
|
||||
my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
|
||||
lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
|
||||
JDIMENSION MCU_col_num; /* index of current MCU within row */
|
||||
JDIMENSION MCU_count; /* number of MCUs decoded */
|
||||
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
|
||||
int ci, compi, row, prev_row;
|
||||
unsigned int yoffset;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
/* Loop to process as much as one whole iMCU row */
|
||||
for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
|
||||
yoffset++) {
|
||||
|
||||
/* Process restart marker if needed; may have to suspend */
|
||||
if (cinfo->restart_interval) {
|
||||
if (diff->restart_rows_to_go == 0)
|
||||
if (!process_restart(cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
}
|
||||
|
||||
MCU_col_num = diff->MCU_ctr;
|
||||
/* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
|
||||
MCU_count =
|
||||
(*cinfo->entropy->decode_mcus) (cinfo,
|
||||
diff->diff_buf, yoffset, MCU_col_num,
|
||||
cinfo->MCUs_per_row - MCU_col_num);
|
||||
if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
|
||||
/* Suspension forced; update state counters and exit */
|
||||
diff->MCU_vert_offset = yoffset;
|
||||
diff->MCU_ctr += MCU_count;
|
||||
return JPEG_SUSPENDED;
|
||||
}
|
||||
|
||||
/* Account for restart interval (no-op if not using restarts) */
|
||||
if (cinfo->restart_interval)
|
||||
diff->restart_rows_to_go--;
|
||||
|
||||
/* Completed an MCU row, but perhaps not an iMCU row */
|
||||
diff->MCU_ctr = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Undifference and scale each scanline of the disassembled MCU row
|
||||
* separately. We do not process dummy samples at the end of a scanline
|
||||
* or dummy rows at the end of the image.
|
||||
*/
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
compi = compptr->component_index;
|
||||
for (row = 0, prev_row = compptr->v_samp_factor - 1;
|
||||
row < (cinfo->input_iMCU_row == last_iMCU_row ?
|
||||
compptr->last_row_height : compptr->v_samp_factor);
|
||||
prev_row = row, row++) {
|
||||
(*losslessd->predict_undifference[compi])
|
||||
(cinfo, compi, diff->diff_buf[compi][row],
|
||||
diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
|
||||
compptr->width_in_blocks);
|
||||
(*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
|
||||
output_buf[compi][row],
|
||||
compptr->width_in_blocks);
|
||||
}
|
||||
}
|
||||
|
||||
/* Completed the iMCU row, advance counters for next one.
|
||||
*
|
||||
* NB: output_data will increment output_iMCU_row.
|
||||
* This counter is not needed for the single-pass case
|
||||
* or the input side of the multi-pass case.
|
||||
*/
|
||||
if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
|
||||
start_iMCU_row(cinfo);
|
||||
return JPEG_ROW_COMPLETED;
|
||||
}
|
||||
/* Completed the scan */
|
||||
(*cinfo->inputctl->finish_input_pass) (cinfo);
|
||||
return JPEG_SCAN_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Dummy consume-input routine for single-pass operation.
|
||||
*/
|
||||
|
||||
METHODDEF(int)
|
||||
dummy_consume_data(j_decompress_ptr cinfo)
|
||||
{
|
||||
return JPEG_SUSPENDED; /* Always indicate nothing was done */
|
||||
}
|
||||
|
||||
|
||||
#ifdef D_MULTISCAN_FILES_SUPPORTED
|
||||
|
||||
/*
|
||||
* Consume input data and store it in the full-image sample buffer.
|
||||
* We read as much as one fully interleaved MCU row ("iMCU" row) per call,
|
||||
* ie, v_samp_factor rows for each component in the scan.
|
||||
* Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
|
||||
*/
|
||||
|
||||
METHODDEF(int)
|
||||
consume_data(j_decompress_ptr cinfo)
|
||||
{
|
||||
my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
|
||||
int ci, compi;
|
||||
_JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
/* Align the virtual buffers for the components used in this scan. */
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
compi = compptr->component_index;
|
||||
buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr)cinfo, diff->whole_image[compi],
|
||||
cinfo->input_iMCU_row * compptr->v_samp_factor,
|
||||
(JDIMENSION)compptr->v_samp_factor, TRUE);
|
||||
}
|
||||
|
||||
return decompress_data(cinfo, buffer);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Output some data from the full-image sample buffer in the multi-pass case.
|
||||
* Always attempts to emit one fully interleaved MCU row ("iMCU" row).
|
||||
* Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
|
||||
*
|
||||
* NB: output_buf contains a plane for each component in image.
|
||||
*/
|
||||
|
||||
METHODDEF(int)
|
||||
output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
|
||||
{
|
||||
my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
|
||||
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
|
||||
int ci, samp_rows, row;
|
||||
_JSAMPARRAY buffer;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
/* Force some input to be done if we are getting ahead of the input. */
|
||||
while (cinfo->input_scan_number < cinfo->output_scan_number ||
|
||||
(cinfo->input_scan_number == cinfo->output_scan_number &&
|
||||
cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
|
||||
if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
|
||||
return JPEG_SUSPENDED;
|
||||
}
|
||||
|
||||
/* OK, output from the virtual arrays. */
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
/* Align the virtual buffer for this component. */
|
||||
buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr)cinfo, diff->whole_image[ci],
|
||||
cinfo->output_iMCU_row * compptr->v_samp_factor,
|
||||
(JDIMENSION)compptr->v_samp_factor, FALSE);
|
||||
|
||||
if (cinfo->output_iMCU_row < last_iMCU_row)
|
||||
samp_rows = compptr->v_samp_factor;
|
||||
else {
|
||||
/* NB: can't use last_row_height here; it is input-side-dependent! */
|
||||
samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
|
||||
if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
|
||||
}
|
||||
|
||||
for (row = 0; row < samp_rows; row++) {
|
||||
memcpy(output_buf[ci][row], buffer[row],
|
||||
compptr->width_in_blocks * sizeof(_JSAMPLE));
|
||||
}
|
||||
}
|
||||
|
||||
if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
|
||||
return JPEG_ROW_COMPLETED;
|
||||
return JPEG_SCAN_COMPLETED;
|
||||
}
|
||||
|
||||
#endif /* D_MULTISCAN_FILES_SUPPORTED */
|
||||
|
||||
|
||||
/*
|
||||
* Initialize difference buffer controller.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
_jinit_d_diff_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_diff_ptr diff;
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
diff = (my_diff_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_diff_controller));
|
||||
cinfo->coef = (struct jpeg_d_coef_controller *)diff;
|
||||
diff->pub.start_input_pass = start_input_pass;
|
||||
diff->pub.start_output_pass = start_output_pass;
|
||||
|
||||
/* Create the [un]difference buffers. */
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
diff->diff_buf[ci] =
|
||||
ALLOC_DARRAY(JPOOL_IMAGE,
|
||||
(JDIMENSION)jround_up((long)compptr->width_in_blocks,
|
||||
(long)compptr->h_samp_factor),
|
||||
(JDIMENSION)compptr->v_samp_factor);
|
||||
diff->undiff_buf[ci] =
|
||||
ALLOC_DARRAY(JPOOL_IMAGE,
|
||||
(JDIMENSION)jround_up((long)compptr->width_in_blocks,
|
||||
(long)compptr->h_samp_factor),
|
||||
(JDIMENSION)compptr->v_samp_factor);
|
||||
}
|
||||
|
||||
if (need_full_buffer) {
|
||||
#ifdef D_MULTISCAN_FILES_SUPPORTED
|
||||
/* Allocate a full-image virtual array for each component. */
|
||||
int access_rows;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
access_rows = compptr->v_samp_factor;
|
||||
diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
|
||||
(JDIMENSION)jround_up((long)compptr->width_in_blocks,
|
||||
(long)compptr->h_samp_factor),
|
||||
(JDIMENSION)jround_up((long)compptr->height_in_blocks,
|
||||
(long)compptr->v_samp_factor),
|
||||
(JDIMENSION)access_rows);
|
||||
}
|
||||
diff->pub.consume_data = consume_data;
|
||||
diff->pub._decompress_data = output_data;
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
} else {
|
||||
diff->pub.consume_data = dummy_consume_data;
|
||||
diff->pub._decompress_data = decompress_data;
|
||||
diff->whole_image[0] = NULL; /* flag for no virtual arrays */
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* D_LOSSLESS_SUPPORTED */
|
20
3rdparty/libjpeg-turbo/src/jdhuff.c
vendored
20
3rdparty/libjpeg-turbo/src/jdhuff.c
vendored
@ -3,8 +3,10 @@
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2009-2011, 2016, 2018-2019, D. R. Commander.
|
||||
* Copyright (C) 2009-2011, 2016, 2018-2019, 2022, D. R. Commander.
|
||||
* Copyright (C) 2018, Matthias Räncker.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
@ -24,8 +26,8 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jdhuff.h" /* Declarations shared with jdphuff.c */
|
||||
#include "jpegcomp.h"
|
||||
#include "jdhuff.h" /* Declarations shared with jd*huff.c */
|
||||
#include "jpegapicomp.h"
|
||||
#include "jstdhuff.c"
|
||||
|
||||
|
||||
@ -134,7 +136,7 @@ start_pass_huff_decoder(j_decompress_ptr cinfo)
|
||||
* Compute the derived values for a Huffman table.
|
||||
* This routine also performs some validation checks on the table.
|
||||
*
|
||||
* Note this is also used by jdphuff.c.
|
||||
* Note this is also used by jdphuff.c and jdlhuff.c.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
@ -245,14 +247,14 @@ jpeg_make_d_derived_tbl(j_decompress_ptr cinfo, boolean isDC, int tblno,
|
||||
|
||||
/* Validate symbols as being reasonable.
|
||||
* For AC tables, we make no check, but accept all byte values 0..255.
|
||||
* For DC tables, we require the symbols to be in range 0..15.
|
||||
* (Tighter bounds could be applied depending on the data depth and mode,
|
||||
* but this is sufficient to ensure safe decoding.)
|
||||
* For DC tables, we require the symbols to be in range 0..15 in lossy mode
|
||||
* and 0..16 in lossless mode. (Tighter bounds could be applied depending on
|
||||
* the data depth and mode, but this is sufficient to ensure safe decoding.)
|
||||
*/
|
||||
if (isDC) {
|
||||
for (i = 0; i < numsymbols; i++) {
|
||||
int sym = htbl->huffval[i];
|
||||
if (sym < 0 || sym > 15)
|
||||
if (sym < 0 || sym > (cinfo->master->lossless ? 16 : 15))
|
||||
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
|
||||
}
|
||||
}
|
||||
@ -260,7 +262,7 @@ jpeg_make_d_derived_tbl(j_decompress_ptr cinfo, boolean isDC, int tblno,
|
||||
|
||||
|
||||
/*
|
||||
* Out-of-line code for bit fetching (shared with jdphuff.c).
|
||||
* Out-of-line code for bit fetching (shared with jdphuff.c and jdlhuff.c).
|
||||
* See jdhuff.h for info about usage.
|
||||
* Note: current values of get_buffer and bits_left are passed as parameters,
|
||||
* but are returned in the corresponding fields of the state struct.
|
||||
|
7
3rdparty/libjpeg-turbo/src/jdhuff.h
vendored
7
3rdparty/libjpeg-turbo/src/jdhuff.h
vendored
@ -3,6 +3,8 @@
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2010-2011, 2015-2016, 2021, D. R. Commander.
|
||||
* Copyright (C) 2018, Matthias Räncker.
|
||||
@ -10,8 +12,9 @@
|
||||
* file.
|
||||
*
|
||||
* This file contains declarations for Huffman entropy decoding routines
|
||||
* that are shared between the sequential decoder (jdhuff.c) and the
|
||||
* progressive decoder (jdphuff.c). No other modules need to see these.
|
||||
* that are shared between the sequential decoder (jdhuff.c), the progressive
|
||||
* decoder (jdphuff.c), and the lossless decoder (jdlhuff.c). No other modules
|
||||
* need to see these.
|
||||
*/
|
||||
|
||||
#include "jconfigint.h"
|
||||
|
63
3rdparty/libjpeg-turbo/src/jdinput.c
vendored
63
3rdparty/libjpeg-turbo/src/jdinput.c
vendored
@ -3,6 +3,8 @@
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2010, 2016, 2018, 2022, D. R. Commander.
|
||||
* Copyright (C) 2015, Google, Inc.
|
||||
@ -11,14 +13,15 @@
|
||||
*
|
||||
* This file contains input control logic for the JPEG decompressor.
|
||||
* These routines are concerned with controlling the decompressor's input
|
||||
* processing (marker reading and coefficient decoding). The actual input
|
||||
* reading is done in jdmarker.c, jdhuff.c, and jdphuff.c.
|
||||
* processing (marker reading and coefficient/difference decoding).
|
||||
* The actual input reading is done in jdmarker.c, jdhuff.c, jdphuff.c,
|
||||
* and jdlhuff.c.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jpegcomp.h"
|
||||
#include "jpegapicomp.h"
|
||||
|
||||
|
||||
/* Private state */
|
||||
@ -46,6 +49,7 @@ initial_setup(j_decompress_ptr cinfo)
|
||||
{
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
|
||||
/* Make sure image isn't bigger than I can handle */
|
||||
if ((long)cinfo->image_height > (long)JPEG_MAX_DIMENSION ||
|
||||
@ -53,7 +57,12 @@ initial_setup(j_decompress_ptr cinfo)
|
||||
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int)JPEG_MAX_DIMENSION);
|
||||
|
||||
/* For now, precision must match compiled-in value... */
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
if (cinfo->data_precision != 8 && cinfo->data_precision != 12 &&
|
||||
cinfo->data_precision != 16)
|
||||
#else
|
||||
if (cinfo->data_precision != 8 && cinfo->data_precision != 12)
|
||||
#endif
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
/* Check that number of components won't exceed internal array sizes */
|
||||
@ -78,36 +87,36 @@ initial_setup(j_decompress_ptr cinfo)
|
||||
}
|
||||
|
||||
#if JPEG_LIB_VERSION >= 80
|
||||
cinfo->block_size = DCTSIZE;
|
||||
cinfo->block_size = data_unit;
|
||||
cinfo->natural_order = jpeg_natural_order;
|
||||
cinfo->lim_Se = DCTSIZE2 - 1;
|
||||
#endif
|
||||
|
||||
/* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE.
|
||||
* In the full decompressor, this will be overridden by jdmaster.c;
|
||||
/* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE in lossy
|
||||
* mode. In the full decompressor, this will be overridden by jdmaster.c;
|
||||
* but in the transcoder, jdmaster.c is not used, so we must do it here.
|
||||
*/
|
||||
#if JPEG_LIB_VERSION >= 70
|
||||
cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = DCTSIZE;
|
||||
cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = data_unit;
|
||||
#else
|
||||
cinfo->min_DCT_scaled_size = DCTSIZE;
|
||||
cinfo->min_DCT_scaled_size = data_unit;
|
||||
#endif
|
||||
|
||||
/* Compute dimensions of components */
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
#if JPEG_LIB_VERSION >= 70
|
||||
compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = DCTSIZE;
|
||||
compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = data_unit;
|
||||
#else
|
||||
compptr->DCT_scaled_size = DCTSIZE;
|
||||
compptr->DCT_scaled_size = data_unit;
|
||||
#endif
|
||||
/* Size in DCT blocks */
|
||||
/* Size in data units */
|
||||
compptr->width_in_blocks = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * (long)compptr->h_samp_factor,
|
||||
(long)(cinfo->max_h_samp_factor * DCTSIZE));
|
||||
(long)(cinfo->max_h_samp_factor * data_unit));
|
||||
compptr->height_in_blocks = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * (long)compptr->v_samp_factor,
|
||||
(long)(cinfo->max_v_samp_factor * DCTSIZE));
|
||||
(long)(cinfo->max_v_samp_factor * data_unit));
|
||||
/* Set the first and last MCU columns to decompress from multi-scan images.
|
||||
* By default, decompress all of the MCU columns.
|
||||
*/
|
||||
@ -133,7 +142,7 @@ initial_setup(j_decompress_ptr cinfo)
|
||||
/* Compute number of fully interleaved MCU rows. */
|
||||
cinfo->total_iMCU_rows = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height,
|
||||
(long)(cinfo->max_v_samp_factor * DCTSIZE));
|
||||
(long)(cinfo->max_v_samp_factor * data_unit));
|
||||
|
||||
/* Decide whether file contains multiple scans */
|
||||
if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
|
||||
@ -150,6 +159,7 @@ per_scan_setup(j_decompress_ptr cinfo)
|
||||
{
|
||||
int ci, mcublks, tmp;
|
||||
jpeg_component_info *compptr;
|
||||
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
|
||||
|
||||
if (cinfo->comps_in_scan == 1) {
|
||||
|
||||
@ -160,14 +170,14 @@ per_scan_setup(j_decompress_ptr cinfo)
|
||||
cinfo->MCUs_per_row = compptr->width_in_blocks;
|
||||
cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
|
||||
|
||||
/* For noninterleaved scan, always one block per MCU */
|
||||
/* For noninterleaved scan, always one data unit per MCU */
|
||||
compptr->MCU_width = 1;
|
||||
compptr->MCU_height = 1;
|
||||
compptr->MCU_blocks = 1;
|
||||
compptr->MCU_sample_width = compptr->_DCT_scaled_size;
|
||||
compptr->last_col_width = 1;
|
||||
/* For noninterleaved scans, it is convenient to define last_row_height
|
||||
* as the number of block rows present in the last iMCU row.
|
||||
* as the number of data unit rows present in the last iMCU row.
|
||||
*/
|
||||
tmp = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
|
||||
if (tmp == 0) tmp = compptr->v_samp_factor;
|
||||
@ -187,22 +197,22 @@ per_scan_setup(j_decompress_ptr cinfo)
|
||||
/* Overall image size in MCUs */
|
||||
cinfo->MCUs_per_row = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width,
|
||||
(long)(cinfo->max_h_samp_factor * DCTSIZE));
|
||||
(long)(cinfo->max_h_samp_factor * data_unit));
|
||||
cinfo->MCU_rows_in_scan = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height,
|
||||
(long)(cinfo->max_v_samp_factor * DCTSIZE));
|
||||
(long)(cinfo->max_v_samp_factor * data_unit));
|
||||
|
||||
cinfo->blocks_in_MCU = 0;
|
||||
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
/* Sampling factors give # of blocks of component in each MCU */
|
||||
/* Sampling factors give # of data units of component in each MCU */
|
||||
compptr->MCU_width = compptr->h_samp_factor;
|
||||
compptr->MCU_height = compptr->v_samp_factor;
|
||||
compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
|
||||
compptr->MCU_sample_width = compptr->MCU_width *
|
||||
compptr->_DCT_scaled_size;
|
||||
/* Figure number of non-dummy blocks in last MCU column & row */
|
||||
/* Figure number of non-dummy data units in last MCU column & row */
|
||||
tmp = (int)(compptr->width_in_blocks % compptr->MCU_width);
|
||||
if (tmp == 0) tmp = compptr->MCU_width;
|
||||
compptr->last_col_width = tmp;
|
||||
@ -281,7 +291,8 @@ METHODDEF(void)
|
||||
start_input_pass(j_decompress_ptr cinfo)
|
||||
{
|
||||
per_scan_setup(cinfo);
|
||||
latch_quant_tables(cinfo);
|
||||
if (!cinfo->master->lossless)
|
||||
latch_quant_tables(cinfo);
|
||||
(*cinfo->entropy->start_pass) (cinfo);
|
||||
(*cinfo->coef->start_input_pass) (cinfo);
|
||||
cinfo->inputctl->consume_input = cinfo->coef->consume_data;
|
||||
@ -290,8 +301,8 @@ start_input_pass(j_decompress_ptr cinfo)
|
||||
|
||||
/*
|
||||
* Finish up after inputting a compressed-data scan.
|
||||
* This is called by the coefficient controller after it's read all
|
||||
* the expected data of the scan.
|
||||
* This is called by the coefficient or difference controller after it's read
|
||||
* all the expected data of the scan.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
@ -307,8 +318,8 @@ finish_input_pass(j_decompress_ptr cinfo)
|
||||
* Return value is JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
|
||||
*
|
||||
* The consume_input method pointer points either here or to the
|
||||
* coefficient controller's consume_data routine, depending on whether
|
||||
* we are reading a compressed data segment or inter-segment markers.
|
||||
* coefficient or difference controller's consume_data routine, depending on
|
||||
* whether we are reading a compressed data segment or inter-segment markers.
|
||||
*/
|
||||
|
||||
METHODDEF(int)
|
||||
|
302
3rdparty/libjpeg-turbo/src/jdlhuff.c
vendored
Normal file
302
3rdparty/libjpeg-turbo/src/jdlhuff.c
vendored
Normal file
@ -0,0 +1,302 @@
|
||||
/*
|
||||
* jdlhuff.c
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file contains Huffman entropy decoding routines for lossless JPEG.
|
||||
*
|
||||
* Much of the complexity here has to do with supporting input suspension.
|
||||
* If the data source module demands suspension, we want to be able to back
|
||||
* up to the start of the current MCU. To do this, we copy state variables
|
||||
* into local working storage, and update them back to the permanent
|
||||
* storage only upon successful completion of an MCU.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jlossls.h" /* Private declarations for lossless codec */
|
||||
#include "jdhuff.h" /* Declarations shared with jd*huff.c */
|
||||
|
||||
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
|
||||
typedef struct {
|
||||
int ci, yoffset, MCU_width;
|
||||
} lhd_output_ptr_info;
|
||||
|
||||
/*
|
||||
* Expanded entropy decoder object for Huffman decoding in lossless mode.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_entropy_decoder pub; /* public fields */
|
||||
|
||||
/* These fields are loaded into local variables at start of each MCU.
|
||||
* In case of suspension, we exit WITHOUT updating them.
|
||||
*/
|
||||
bitread_perm_state bitstate; /* Bit buffer at start of MCU */
|
||||
|
||||
/* Pointers to derived tables (these workspaces have image lifespan) */
|
||||
d_derived_tbl *derived_tbls[NUM_HUFF_TBLS];
|
||||
|
||||
/* Precalculated info set up by start_pass for use in decode_mcus: */
|
||||
|
||||
/* Pointers to derived tables to be used for each data unit within an MCU */
|
||||
d_derived_tbl *cur_tbls[D_MAX_BLOCKS_IN_MCU];
|
||||
|
||||
/* Pointers to the proper output difference row for each group of data units
|
||||
* within an MCU. For each component, there are Vi groups of Hi data units.
|
||||
*/
|
||||
JDIFFROW output_ptr[D_MAX_BLOCKS_IN_MCU];
|
||||
|
||||
/* Number of output pointers in use for the current MCU. This is the sum
|
||||
* of all Vi in the MCU.
|
||||
*/
|
||||
int num_output_ptrs;
|
||||
|
||||
/* Information used for positioning the output pointers within the output
|
||||
* difference rows.
|
||||
*/
|
||||
lhd_output_ptr_info output_ptr_info[D_MAX_BLOCKS_IN_MCU];
|
||||
|
||||
/* Index of the proper output pointer for each data unit within an MCU */
|
||||
int output_ptr_index[D_MAX_BLOCKS_IN_MCU];
|
||||
|
||||
} lhuff_entropy_decoder;
|
||||
|
||||
typedef lhuff_entropy_decoder *lhuff_entropy_ptr;
|
||||
|
||||
|
||||
/*
|
||||
* Initialize for a Huffman-compressed scan.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
start_pass_lhuff_decoder(j_decompress_ptr cinfo)
|
||||
{
|
||||
lhuff_entropy_ptr entropy = (lhuff_entropy_ptr)cinfo->entropy;
|
||||
int ci, dctbl, sampn, ptrn, yoffset, xoffset;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
dctbl = compptr->dc_tbl_no;
|
||||
/* Make sure requested tables are present */
|
||||
if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS ||
|
||||
cinfo->dc_huff_tbl_ptrs[dctbl] == NULL)
|
||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
|
||||
/* Compute derived values for Huffman tables */
|
||||
/* We may do this more than once for a table, but it's not expensive */
|
||||
jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
|
||||
&entropy->derived_tbls[dctbl]);
|
||||
}
|
||||
|
||||
/* Precalculate decoding info for each sample in an MCU of this scan */
|
||||
for (sampn = 0, ptrn = 0; sampn < cinfo->blocks_in_MCU;) {
|
||||
compptr = cinfo->cur_comp_info[cinfo->MCU_membership[sampn]];
|
||||
ci = compptr->component_index;
|
||||
for (yoffset = 0; yoffset < compptr->MCU_height; yoffset++, ptrn++) {
|
||||
/* Precalculate the setup info for each output pointer */
|
||||
entropy->output_ptr_info[ptrn].ci = ci;
|
||||
entropy->output_ptr_info[ptrn].yoffset = yoffset;
|
||||
entropy->output_ptr_info[ptrn].MCU_width = compptr->MCU_width;
|
||||
for (xoffset = 0; xoffset < compptr->MCU_width; xoffset++, sampn++) {
|
||||
/* Precalculate the output pointer index for each sample */
|
||||
entropy->output_ptr_index[sampn] = ptrn;
|
||||
/* Precalculate which table to use for each sample */
|
||||
entropy->cur_tbls[sampn] = entropy->derived_tbls[compptr->dc_tbl_no];
|
||||
}
|
||||
}
|
||||
}
|
||||
entropy->num_output_ptrs = ptrn;
|
||||
|
||||
/* Initialize bitread state variables */
|
||||
entropy->bitstate.bits_left = 0;
|
||||
entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
|
||||
entropy->pub.insufficient_data = FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Figure F.12: extend sign bit.
|
||||
* On some machines, a shift and add will be faster than a table lookup.
|
||||
*/
|
||||
|
||||
#define AVOID_TABLES
|
||||
#ifdef AVOID_TABLES
|
||||
|
||||
#define NEG_1 ((unsigned int)-1)
|
||||
#define HUFF_EXTEND(x, s) \
|
||||
((x) + ((((x) - (1 << ((s) - 1))) >> 31) & (((NEG_1) << (s)) + 1)))
|
||||
|
||||
#else
|
||||
|
||||
#define HUFF_EXTEND(x, s) \
|
||||
((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
|
||||
|
||||
static const int extend_test[16] = { /* entry n is 2**(n-1) */
|
||||
0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
|
||||
0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000
|
||||
};
|
||||
|
||||
static const int extend_offset[16] = { /* entry n is (-1 << n) + 1 */
|
||||
0, ((-1) << 1) + 1, ((-1) << 2) + 1, ((-1) << 3) + 1, ((-1) << 4) + 1,
|
||||
((-1) << 5) + 1, ((-1) << 6) + 1, ((-1) << 7) + 1, ((-1) << 8) + 1,
|
||||
((-1) << 9) + 1, ((-1) << 10) + 1, ((-1) << 11) + 1, ((-1) << 12) + 1,
|
||||
((-1) << 13) + 1, ((-1) << 14) + 1, ((-1) << 15) + 1
|
||||
};
|
||||
|
||||
#endif /* AVOID_TABLES */
|
||||
|
||||
|
||||
/*
|
||||
* Check for a restart marker & resynchronize decoder.
|
||||
* Returns FALSE if must suspend.
|
||||
*/
|
||||
|
||||
LOCAL(boolean)
|
||||
process_restart(j_decompress_ptr cinfo)
|
||||
{
|
||||
lhuff_entropy_ptr entropy = (lhuff_entropy_ptr)cinfo->entropy;
|
||||
|
||||
/* Throw away any unused bits remaining in bit buffer; */
|
||||
/* include any full bytes in next_marker's count of discarded bytes */
|
||||
cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
|
||||
entropy->bitstate.bits_left = 0;
|
||||
|
||||
/* Advance past the RSTn marker */
|
||||
if (!(*cinfo->marker->read_restart_marker) (cinfo))
|
||||
return FALSE;
|
||||
|
||||
/* Reset out-of-data flag, unless read_restart_marker left us smack up
|
||||
* against a marker. In that case we will end up treating the next data
|
||||
* segment as empty, and we can avoid producing bogus output pixels by
|
||||
* leaving the flag set.
|
||||
*/
|
||||
if (cinfo->unread_marker == 0)
|
||||
entropy->pub.insufficient_data = FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Decode and return nMCU MCUs' worth of Huffman-compressed differences.
|
||||
* Each MCU is also disassembled and placed accordingly in diff_buf.
|
||||
*
|
||||
* MCU_col_num specifies the column of the first MCU being requested within
|
||||
* the MCU row. This tells us where to position the output row pointers in
|
||||
* diff_buf.
|
||||
*
|
||||
* Returns the number of MCUs decoded. This may be less than nMCU MCUs if
|
||||
* data source requested suspension. In that case no changes have been made
|
||||
* to permanent state. (Exception: some output differences may already have
|
||||
* been assigned. This is harmless for this module, since we'll just
|
||||
* re-assign them on the next call.)
|
||||
*/
|
||||
|
||||
METHODDEF(JDIMENSION)
|
||||
decode_mcus(j_decompress_ptr cinfo, JDIFFIMAGE diff_buf,
|
||||
JDIMENSION MCU_row_num, JDIMENSION MCU_col_num, JDIMENSION nMCU)
|
||||
{
|
||||
lhuff_entropy_ptr entropy = (lhuff_entropy_ptr)cinfo->entropy;
|
||||
int sampn, ci, yoffset, MCU_width, ptrn;
|
||||
JDIMENSION mcu_num;
|
||||
BITREAD_STATE_VARS;
|
||||
|
||||
/* Set output pointer locations based on MCU_col_num */
|
||||
for (ptrn = 0; ptrn < entropy->num_output_ptrs; ptrn++) {
|
||||
ci = entropy->output_ptr_info[ptrn].ci;
|
||||
yoffset = entropy->output_ptr_info[ptrn].yoffset;
|
||||
MCU_width = entropy->output_ptr_info[ptrn].MCU_width;
|
||||
entropy->output_ptr[ptrn] =
|
||||
diff_buf[ci][MCU_row_num + yoffset] + (MCU_col_num * MCU_width);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we've run out of data, zero out the buffers and return.
|
||||
* By resetting the undifferencer, the output samples will be CENTERJSAMPLE.
|
||||
*
|
||||
* NB: We should find a way to do this without interacting with the
|
||||
* undifferencer module directly.
|
||||
*/
|
||||
if (entropy->pub.insufficient_data) {
|
||||
for (ptrn = 0; ptrn < entropy->num_output_ptrs; ptrn++)
|
||||
jzero_far((void FAR *)entropy->output_ptr[ptrn],
|
||||
nMCU * entropy->output_ptr_info[ptrn].MCU_width *
|
||||
sizeof(JDIFF));
|
||||
|
||||
(*cinfo->idct->start_pass) (cinfo);
|
||||
|
||||
} else {
|
||||
|
||||
/* Load up working state */
|
||||
BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
|
||||
|
||||
/* Outer loop handles the number of MCUs requested */
|
||||
|
||||
for (mcu_num = 0; mcu_num < nMCU; mcu_num++) {
|
||||
|
||||
/* Inner loop handles the samples in the MCU */
|
||||
for (sampn = 0; sampn < cinfo->blocks_in_MCU; sampn++) {
|
||||
d_derived_tbl *dctbl = entropy->cur_tbls[sampn];
|
||||
register int s, r;
|
||||
|
||||
/* Section H.2.2: decode the sample difference */
|
||||
HUFF_DECODE(s, br_state, dctbl, return mcu_num, label1);
|
||||
if (s) {
|
||||
if (s == 16) /* special case: always output 32768 */
|
||||
s = 32768;
|
||||
else { /* normal case: fetch subsequent bits */
|
||||
CHECK_BIT_BUFFER(br_state, s, return mcu_num);
|
||||
r = GET_BITS(s);
|
||||
s = HUFF_EXTEND(r, s);
|
||||
}
|
||||
}
|
||||
|
||||
/* Output the sample difference */
|
||||
*entropy->output_ptr[entropy->output_ptr_index[sampn]]++ = (JDIFF)s;
|
||||
}
|
||||
|
||||
/* Completed MCU, so update state */
|
||||
BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
|
||||
}
|
||||
}
|
||||
|
||||
return nMCU;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Module initialization routine for lossless mode Huffman entropy decoding.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_lhuff_decoder(j_decompress_ptr cinfo)
|
||||
{
|
||||
lhuff_entropy_ptr entropy;
|
||||
int i;
|
||||
|
||||
entropy = (lhuff_entropy_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(lhuff_entropy_decoder));
|
||||
cinfo->entropy = (struct jpeg_entropy_decoder *)entropy;
|
||||
entropy->pub.start_pass = start_pass_lhuff_decoder;
|
||||
entropy->pub.decode_mcus = decode_mcus;
|
||||
entropy->pub.process_restart = process_restart;
|
||||
|
||||
/* Mark tables unallocated */
|
||||
for (i = 0; i < NUM_HUFF_TBLS; i++) {
|
||||
entropy->derived_tbls[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* D_LOSSLESS_SUPPORTED */
|
289
3rdparty/libjpeg-turbo/src/jdlossls.c
vendored
Normal file
289
3rdparty/libjpeg-turbo/src/jdlossls.c
vendored
Normal file
@ -0,0 +1,289 @@
|
||||
/*
|
||||
* jdlossls.c
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1998, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file contains prediction, sample undifferencing, point transform, and
|
||||
* sample scaling routines for the lossless JPEG decompressor.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jlossls.h"
|
||||
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
|
||||
|
||||
/**************** Sample undifferencing (reconstruction) *****************/
|
||||
|
||||
/*
|
||||
* In order to avoid a performance penalty for checking which predictor is
|
||||
* being used and which row is being processed for each call of the
|
||||
* undifferencer, and to promote optimization, we have separate undifferencing
|
||||
* functions for each predictor selection value.
|
||||
*
|
||||
* We are able to avoid duplicating source code by implementing the predictors
|
||||
* and undifferencers as macros. Each of the undifferencing functions is
|
||||
* simply a wrapper around an UNDIFFERENCE macro with the appropriate PREDICTOR
|
||||
* macro passed as an argument.
|
||||
*/
|
||||
|
||||
/* Predictor for the first column of the first row: 2^(P-Pt-1) */
|
||||
#define INITIAL_PREDICTORx (1 << (cinfo->data_precision - cinfo->Al - 1))
|
||||
|
||||
/* Predictor for the first column of the remaining rows: Rb */
|
||||
#define INITIAL_PREDICTOR2 prev_row[0]
|
||||
|
||||
|
||||
/*
|
||||
* 1-Dimensional undifferencer routine.
|
||||
*
|
||||
* This macro implements the 1-D horizontal predictor (1). INITIAL_PREDICTOR
|
||||
* is used as the special case predictor for the first column, which must be
|
||||
* either INITIAL_PREDICTOR2 or INITIAL_PREDICTORx. The remaining samples
|
||||
* use PREDICTOR1.
|
||||
*
|
||||
* The reconstructed sample is supposed to be calculated modulo 2^16, so we
|
||||
* logically AND the result with 0xFFFF.
|
||||
*/
|
||||
|
||||
#define UNDIFFERENCE_1D(INITIAL_PREDICTOR) \
|
||||
int Ra; \
|
||||
\
|
||||
Ra = (*diff_buf++ + INITIAL_PREDICTOR) & 0xFFFF; \
|
||||
*undiff_buf++ = Ra; \
|
||||
\
|
||||
while (--width) { \
|
||||
Ra = (*diff_buf++ + PREDICTOR1) & 0xFFFF; \
|
||||
*undiff_buf++ = Ra; \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 2-Dimensional undifferencer routine.
|
||||
*
|
||||
* This macro implements the 2-D horizontal predictors (#2-7). PREDICTOR2 is
|
||||
* used as the special case predictor for the first column. The remaining
|
||||
* samples use PREDICTOR, which is a function of Ra, Rb, and Rc.
|
||||
*
|
||||
* Because prev_row and output_buf may point to the same storage area (in an
|
||||
* interleaved image with Vi=1, for example), we must take care to buffer Rb/Rc
|
||||
* before writing the current reconstructed sample value into output_buf.
|
||||
*
|
||||
* The reconstructed sample is supposed to be calculated modulo 2^16, so we
|
||||
* logically AND the result with 0xFFFF.
|
||||
*/
|
||||
|
||||
#define UNDIFFERENCE_2D(PREDICTOR) \
|
||||
int Ra, Rb, Rc; \
|
||||
\
|
||||
Rb = *prev_row++; \
|
||||
Ra = (*diff_buf++ + PREDICTOR2) & 0xFFFF; \
|
||||
*undiff_buf++ = Ra; \
|
||||
\
|
||||
while (--width) { \
|
||||
Rc = Rb; \
|
||||
Rb = *prev_row++; \
|
||||
Ra = (*diff_buf++ + PREDICTOR) & 0xFFFF; \
|
||||
*undiff_buf++ = Ra; \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Undifferencers for the second and subsequent rows in a scan or restart
|
||||
* interval. The first sample in the row is undifferenced using the vertical
|
||||
* predictor (2). The rest of the samples are undifferenced using the
|
||||
* predictor specified in the scan header.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_undifference1(j_decompress_ptr cinfo, int comp_index,
|
||||
JDIFFROW diff_buf, JDIFFROW prev_row,
|
||||
JDIFFROW undiff_buf, JDIMENSION width)
|
||||
{
|
||||
UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_undifference2(j_decompress_ptr cinfo, int comp_index,
|
||||
JDIFFROW diff_buf, JDIFFROW prev_row,
|
||||
JDIFFROW undiff_buf, JDIMENSION width)
|
||||
{
|
||||
UNDIFFERENCE_2D(PREDICTOR2);
|
||||
(void)(Rc);
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_undifference3(j_decompress_ptr cinfo, int comp_index,
|
||||
JDIFFROW diff_buf, JDIFFROW prev_row,
|
||||
JDIFFROW undiff_buf, JDIMENSION width)
|
||||
{
|
||||
UNDIFFERENCE_2D(PREDICTOR3);
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_undifference4(j_decompress_ptr cinfo, int comp_index,
|
||||
JDIFFROW diff_buf, JDIFFROW prev_row,
|
||||
JDIFFROW undiff_buf, JDIMENSION width)
|
||||
{
|
||||
UNDIFFERENCE_2D(PREDICTOR4);
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_undifference5(j_decompress_ptr cinfo, int comp_index,
|
||||
JDIFFROW diff_buf, JDIFFROW prev_row,
|
||||
JDIFFROW undiff_buf, JDIMENSION width)
|
||||
{
|
||||
UNDIFFERENCE_2D(PREDICTOR5);
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_undifference6(j_decompress_ptr cinfo, int comp_index,
|
||||
JDIFFROW diff_buf, JDIFFROW prev_row,
|
||||
JDIFFROW undiff_buf, JDIMENSION width)
|
||||
{
|
||||
UNDIFFERENCE_2D(PREDICTOR6);
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_undifference7(j_decompress_ptr cinfo, int comp_index,
|
||||
JDIFFROW diff_buf, JDIFFROW prev_row,
|
||||
JDIFFROW undiff_buf, JDIMENSION width)
|
||||
{
|
||||
UNDIFFERENCE_2D(PREDICTOR7);
|
||||
(void)(Rc);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Undifferencer for the first row in a scan or restart interval. The first
|
||||
* sample in the row is undifferenced using the special predictor constant
|
||||
* x=2^(P-Pt-1). The rest of the samples are undifferenced using the
|
||||
* 1-D horizontal predictor (1).
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
jpeg_undifference_first_row(j_decompress_ptr cinfo, int comp_index,
|
||||
JDIFFROW diff_buf, JDIFFROW prev_row,
|
||||
JDIFFROW undiff_buf, JDIMENSION width)
|
||||
{
|
||||
lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
|
||||
|
||||
UNDIFFERENCE_1D(INITIAL_PREDICTORx);
|
||||
|
||||
/*
|
||||
* Now that we have undifferenced the first row, we want to use the
|
||||
* undifferencer that corresponds to the predictor specified in the
|
||||
* scan header.
|
||||
*/
|
||||
switch (cinfo->Ss) {
|
||||
case 1:
|
||||
losslessd->predict_undifference[comp_index] = jpeg_undifference1;
|
||||
break;
|
||||
case 2:
|
||||
losslessd->predict_undifference[comp_index] = jpeg_undifference2;
|
||||
break;
|
||||
case 3:
|
||||
losslessd->predict_undifference[comp_index] = jpeg_undifference3;
|
||||
break;
|
||||
case 4:
|
||||
losslessd->predict_undifference[comp_index] = jpeg_undifference4;
|
||||
break;
|
||||
case 5:
|
||||
losslessd->predict_undifference[comp_index] = jpeg_undifference5;
|
||||
break;
|
||||
case 6:
|
||||
losslessd->predict_undifference[comp_index] = jpeg_undifference6;
|
||||
break;
|
||||
case 7:
|
||||
losslessd->predict_undifference[comp_index] = jpeg_undifference7;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*********************** Sample upscaling by 2^Pt ************************/
|
||||
|
||||
METHODDEF(void)
|
||||
simple_upscale(j_decompress_ptr cinfo,
|
||||
JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
|
||||
{
|
||||
do {
|
||||
*output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
|
||||
} while (--width);
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
noscale(j_decompress_ptr cinfo,
|
||||
JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
|
||||
{
|
||||
do {
|
||||
*output_buf++ = (_JSAMPLE)(*diff_buf++);
|
||||
} while (--width);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize for an input processing pass.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
start_pass_lossless(j_decompress_ptr cinfo)
|
||||
{
|
||||
lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
|
||||
int ci;
|
||||
|
||||
/* Check that the scan parameters Ss, Se, Ah, Al are OK for lossless JPEG.
|
||||
*
|
||||
* Ss is the predictor selection value (psv). Legal values for sequential
|
||||
* lossless JPEG are: 1 <= psv <= 7.
|
||||
*
|
||||
* Se and Ah are not used and should be zero.
|
||||
*
|
||||
* Al specifies the point transform (Pt).
|
||||
* Legal values are: 0 <= Pt <= (data precision - 1).
|
||||
*/
|
||||
if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
|
||||
cinfo->Se != 0 || cinfo->Ah != 0 ||
|
||||
cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
|
||||
ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
|
||||
cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
|
||||
|
||||
/* Set undifference functions to first row function */
|
||||
for (ci = 0; ci < cinfo->num_components; ci++)
|
||||
losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
|
||||
|
||||
/* Set scaler function based on Pt */
|
||||
if (cinfo->Al)
|
||||
losslessd->scaler_scale = simple_upscale;
|
||||
else
|
||||
losslessd->scaler_scale = noscale;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize the lossless decompressor.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
_jinit_lossless_decompressor(j_decompress_ptr cinfo)
|
||||
{
|
||||
lossless_decomp_ptr losslessd;
|
||||
|
||||
/* Create subobject in permanent pool */
|
||||
losslessd = (lossless_decomp_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
|
||||
sizeof(jpeg_lossless_decompressor));
|
||||
cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
|
||||
losslessd->pub.start_pass = start_pass_lossless;
|
||||
}
|
||||
|
||||
#endif /* D_LOSSLESS_SUPPORTED */
|
112
3rdparty/libjpeg-turbo/src/jdmainct.c
vendored
112
3rdparty/libjpeg-turbo/src/jdmainct.c
vendored
@ -4,7 +4,7 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2010, 2016, D. R. Commander.
|
||||
* Copyright (C) 2010, 2016, 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -18,15 +18,17 @@
|
||||
|
||||
#include "jinclude.h"
|
||||
#include "jdmainct.h"
|
||||
#include "jconfigint.h"
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
|
||||
|
||||
/*
|
||||
* In the current system design, the main buffer need never be a full-image
|
||||
* buffer; any full-height buffers will be found inside the coefficient or
|
||||
* postprocessing controllers. Nonetheless, the main controller is not
|
||||
* trivial. Its responsibility is to provide context rows for upsampling/
|
||||
* rescaling, and doing this in an efficient fashion is a bit tricky.
|
||||
* buffer; any full-height buffers will be found inside the coefficient,
|
||||
* difference, or postprocessing controllers. Nonetheless, the main controller
|
||||
* is not trivial. Its responsibility is to provide context rows for
|
||||
* upsampling/rescaling, and doing this in an efficient fashion is a bit
|
||||
* tricky.
|
||||
*
|
||||
* Postprocessor input data is counted in "row groups". A row group
|
||||
* is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
|
||||
@ -38,20 +40,20 @@
|
||||
* row group (times any additional scale factor that the upsampler is
|
||||
* applying).
|
||||
*
|
||||
* The coefficient controller will deliver data to us one iMCU row at a time;
|
||||
* each iMCU row contains v_samp_factor * DCT_scaled_size sample rows, or
|
||||
* exactly min_DCT_scaled_size row groups. (This amount of data corresponds
|
||||
* to one row of MCUs when the image is fully interleaved.) Note that the
|
||||
* number of sample rows varies across components, but the number of row
|
||||
* groups does not. Some garbage sample rows may be included in the last iMCU
|
||||
* row at the bottom of the image.
|
||||
* The coefficient or difference controller will deliver data to us one iMCU
|
||||
* row at a time; each iMCU row contains v_samp_factor * DCT_scaled_size sample
|
||||
* rows, or exactly min_DCT_scaled_size row groups. (This amount of data
|
||||
* corresponds to one row of MCUs when the image is fully interleaved.) Note
|
||||
* that the number of sample rows varies across components, but the number of
|
||||
* row groups does not. Some garbage sample rows may be included in the last
|
||||
* iMCU row at the bottom of the image.
|
||||
*
|
||||
* Depending on the vertical scaling algorithm used, the upsampler may need
|
||||
* access to the sample row(s) above and below its current input row group.
|
||||
* The upsampler is required to set need_context_rows TRUE at global selection
|
||||
* time if so. When need_context_rows is FALSE, this controller can simply
|
||||
* obtain one iMCU row at a time from the coefficient controller and dole it
|
||||
* out as row groups to the postprocessor.
|
||||
* obtain one iMCU row at a time from the coefficient or difference controller
|
||||
* and dole it out as row groups to the postprocessor.
|
||||
*
|
||||
* When need_context_rows is TRUE, this controller guarantees that the buffer
|
||||
* passed to postprocessing contains at least one row group's worth of samples
|
||||
@ -114,16 +116,16 @@
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF(void) process_data_simple_main(j_decompress_ptr cinfo,
|
||||
JSAMPARRAY output_buf,
|
||||
_JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail);
|
||||
METHODDEF(void) process_data_context_main(j_decompress_ptr cinfo,
|
||||
JSAMPARRAY output_buf,
|
||||
_JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail);
|
||||
#ifdef QUANT_2PASS_SUPPORTED
|
||||
METHODDEF(void) process_data_crank_post(j_decompress_ptr cinfo,
|
||||
JSAMPARRAY output_buf,
|
||||
_JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail);
|
||||
#endif
|
||||
@ -139,14 +141,15 @@ alloc_funny_pointers(j_decompress_ptr cinfo)
|
||||
int ci, rgroup;
|
||||
int M = cinfo->_min_DCT_scaled_size;
|
||||
jpeg_component_info *compptr;
|
||||
JSAMPARRAY xbuf;
|
||||
_JSAMPARRAY xbuf;
|
||||
|
||||
/* Get top-level space for component array pointers.
|
||||
* We alloc both arrays with one call to save a few cycles.
|
||||
*/
|
||||
main_ptr->xbuffer[0] = (JSAMPIMAGE)
|
||||
main_ptr->xbuffer[0] = (_JSAMPIMAGE)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
cinfo->num_components * 2 * sizeof(JSAMPARRAY));
|
||||
cinfo->num_components * 2 *
|
||||
sizeof(_JSAMPARRAY));
|
||||
main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
@ -156,9 +159,9 @@ alloc_funny_pointers(j_decompress_ptr cinfo)
|
||||
/* Get space for pointer lists --- M+4 row groups in each list.
|
||||
* We alloc both pointer lists with one call to save a few cycles.
|
||||
*/
|
||||
xbuf = (JSAMPARRAY)
|
||||
xbuf = (_JSAMPARRAY)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
2 * (rgroup * (M + 4)) * sizeof(JSAMPROW));
|
||||
2 * (rgroup * (M + 4)) * sizeof(_JSAMPROW));
|
||||
xbuf += rgroup; /* want one row group at negative offsets */
|
||||
main_ptr->xbuffer[0][ci] = xbuf;
|
||||
xbuf += rgroup * (M + 4);
|
||||
@ -180,7 +183,7 @@ make_funny_pointers(j_decompress_ptr cinfo)
|
||||
int ci, i, rgroup;
|
||||
int M = cinfo->_min_DCT_scaled_size;
|
||||
jpeg_component_info *compptr;
|
||||
JSAMPARRAY buf, xbuf0, xbuf1;
|
||||
_JSAMPARRAY buf, xbuf0, xbuf1;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
@ -220,7 +223,7 @@ set_bottom_pointers(j_decompress_ptr cinfo)
|
||||
my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
|
||||
int ci, i, rgroup, iMCUheight, rows_left;
|
||||
jpeg_component_info *compptr;
|
||||
JSAMPARRAY xbuf;
|
||||
_JSAMPARRAY xbuf;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
@ -259,14 +262,14 @@ start_pass_main(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
switch (pass_mode) {
|
||||
case JBUF_PASS_THRU:
|
||||
if (cinfo->upsample->need_context_rows) {
|
||||
main_ptr->pub.process_data = process_data_context_main;
|
||||
main_ptr->pub._process_data = process_data_context_main;
|
||||
make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
|
||||
main_ptr->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
|
||||
main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
|
||||
main_ptr->iMCU_row_ctr = 0;
|
||||
} else {
|
||||
/* Simple case with no context needed */
|
||||
main_ptr->pub.process_data = process_data_simple_main;
|
||||
main_ptr->pub._process_data = process_data_simple_main;
|
||||
}
|
||||
main_ptr->buffer_full = FALSE; /* Mark buffer empty */
|
||||
main_ptr->rowgroup_ctr = 0;
|
||||
@ -274,7 +277,7 @@ start_pass_main(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
#ifdef QUANT_2PASS_SUPPORTED
|
||||
case JBUF_CRANK_DEST:
|
||||
/* For last pass of 2-pass quantization, just crank the postprocessor */
|
||||
main_ptr->pub.process_data = process_data_crank_post;
|
||||
main_ptr->pub._process_data = process_data_crank_post;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
@ -290,7 +293,7 @@ start_pass_main(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
process_data_simple_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
process_data_simple_main(j_decompress_ptr cinfo, _JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
|
||||
{
|
||||
my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
|
||||
@ -298,7 +301,7 @@ process_data_simple_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
|
||||
/* Read input data if we haven't filled the main buffer yet */
|
||||
if (!main_ptr->buffer_full) {
|
||||
if (!(*cinfo->coef->decompress_data) (cinfo, main_ptr->buffer))
|
||||
if (!(*cinfo->coef->_decompress_data) (cinfo, main_ptr->buffer))
|
||||
return; /* suspension forced, can do nothing more */
|
||||
main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
|
||||
}
|
||||
@ -311,9 +314,9 @@ process_data_simple_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
*/
|
||||
|
||||
/* Feed the postprocessor */
|
||||
(*cinfo->post->post_process_data) (cinfo, main_ptr->buffer,
|
||||
&main_ptr->rowgroup_ctr, rowgroups_avail,
|
||||
output_buf, out_row_ctr, out_rows_avail);
|
||||
(*cinfo->post->_post_process_data) (cinfo, main_ptr->buffer,
|
||||
&main_ptr->rowgroup_ctr, rowgroups_avail,
|
||||
output_buf, out_row_ctr, out_rows_avail);
|
||||
|
||||
/* Has postprocessor consumed all the data yet? If so, mark buffer empty */
|
||||
if (main_ptr->rowgroup_ctr >= rowgroups_avail) {
|
||||
@ -329,15 +332,15 @@ process_data_simple_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
process_data_context_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
process_data_context_main(j_decompress_ptr cinfo, _JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
|
||||
{
|
||||
my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
|
||||
|
||||
/* Read input data if we haven't filled the main buffer yet */
|
||||
if (!main_ptr->buffer_full) {
|
||||
if (!(*cinfo->coef->decompress_data) (cinfo,
|
||||
main_ptr->xbuffer[main_ptr->whichptr]))
|
||||
if (!(*cinfo->coef->_decompress_data) (cinfo,
|
||||
main_ptr->xbuffer[main_ptr->whichptr]))
|
||||
return; /* suspension forced, can do nothing more */
|
||||
main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
|
||||
main_ptr->iMCU_row_ctr++; /* count rows received */
|
||||
@ -351,11 +354,11 @@ process_data_context_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
switch (main_ptr->context_state) {
|
||||
case CTX_POSTPONED_ROW:
|
||||
/* Call postprocessor using previously set pointers for postponed row */
|
||||
(*cinfo->post->post_process_data) (cinfo,
|
||||
main_ptr->xbuffer[main_ptr->whichptr],
|
||||
&main_ptr->rowgroup_ctr,
|
||||
main_ptr->rowgroups_avail, output_buf,
|
||||
out_row_ctr, out_rows_avail);
|
||||
(*cinfo->post->_post_process_data) (cinfo,
|
||||
main_ptr->xbuffer[main_ptr->whichptr],
|
||||
&main_ptr->rowgroup_ctr,
|
||||
main_ptr->rowgroups_avail, output_buf,
|
||||
out_row_ctr, out_rows_avail);
|
||||
if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
|
||||
return; /* Need to suspend */
|
||||
main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
|
||||
@ -375,11 +378,11 @@ process_data_context_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
FALLTHROUGH /*FALLTHROUGH*/
|
||||
case CTX_PROCESS_IMCU:
|
||||
/* Call postprocessor using previously set pointers */
|
||||
(*cinfo->post->post_process_data) (cinfo,
|
||||
main_ptr->xbuffer[main_ptr->whichptr],
|
||||
&main_ptr->rowgroup_ctr,
|
||||
main_ptr->rowgroups_avail, output_buf,
|
||||
out_row_ctr, out_rows_avail);
|
||||
(*cinfo->post->_post_process_data) (cinfo,
|
||||
main_ptr->xbuffer[main_ptr->whichptr],
|
||||
&main_ptr->rowgroup_ctr,
|
||||
main_ptr->rowgroups_avail, output_buf,
|
||||
out_row_ctr, out_rows_avail);
|
||||
if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
|
||||
return; /* Need to suspend */
|
||||
/* After the first iMCU, change wraparound pointers to normal state */
|
||||
@ -406,12 +409,12 @@ process_data_context_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
#ifdef QUANT_2PASS_SUPPORTED
|
||||
|
||||
METHODDEF(void)
|
||||
process_data_crank_post(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
process_data_crank_post(j_decompress_ptr cinfo, _JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
|
||||
{
|
||||
(*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE)NULL,
|
||||
(JDIMENSION *)NULL, (JDIMENSION)0,
|
||||
output_buf, out_row_ctr, out_rows_avail);
|
||||
(*cinfo->post->_post_process_data) (cinfo, (_JSAMPIMAGE)NULL,
|
||||
(JDIMENSION *)NULL, (JDIMENSION)0,
|
||||
output_buf, out_row_ctr, out_rows_avail);
|
||||
}
|
||||
|
||||
#endif /* QUANT_2PASS_SUPPORTED */
|
||||
@ -422,12 +425,15 @@ process_data_crank_post(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_d_main_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
_jinit_d_main_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_main_ptr main_ptr;
|
||||
int ci, rgroup, ngroups;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
main_ptr = (my_main_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_main_controller));
|
||||
@ -453,9 +459,11 @@ jinit_d_main_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
ci++, compptr++) {
|
||||
rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
|
||||
cinfo->_min_DCT_scaled_size; /* height of a row group of component */
|
||||
main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray)
|
||||
main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
compptr->width_in_blocks * compptr->_DCT_scaled_size,
|
||||
(JDIMENSION)(rgroup * ngroups));
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */
|
||||
|
15
3rdparty/libjpeg-turbo/src/jdmainct.h
vendored
15
3rdparty/libjpeg-turbo/src/jdmainct.h
vendored
@ -3,22 +3,27 @@
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jpeglib.h"
|
||||
#include "jpegcomp.h"
|
||||
#include "jpegapicomp.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
|
||||
|
||||
/* Private buffer controller object */
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_d_main_controller pub; /* public fields */
|
||||
|
||||
/* Pointer to allocated workspace (M or M+2 row groups). */
|
||||
JSAMPARRAY buffer[MAX_COMPONENTS];
|
||||
_JSAMPARRAY buffer[MAX_COMPONENTS];
|
||||
|
||||
boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
|
||||
JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
|
||||
@ -26,7 +31,7 @@ typedef struct {
|
||||
/* Remaining fields are only used in the context case. */
|
||||
|
||||
/* These are the master pointers to the funny-order pointer lists. */
|
||||
JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
|
||||
_JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
|
||||
|
||||
int whichptr; /* indicates which pointer set is now in use */
|
||||
int context_state; /* process_data state machine status */
|
||||
@ -53,7 +58,7 @@ set_wraparound_pointers(j_decompress_ptr cinfo)
|
||||
int ci, i, rgroup;
|
||||
int M = cinfo->_min_DCT_scaled_size;
|
||||
jpeg_component_info *compptr;
|
||||
JSAMPARRAY xbuf0, xbuf1;
|
||||
_JSAMPARRAY xbuf0, xbuf1;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
@ -69,3 +74,5 @@ set_wraparound_pointers(j_decompress_ptr cinfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */
|
||||
|
26
3rdparty/libjpeg-turbo/src/jdmarker.c
vendored
26
3rdparty/libjpeg-turbo/src/jdmarker.c
vendored
@ -3,6 +3,8 @@
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2012, 2015, 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
@ -237,7 +239,8 @@ get_soi(j_decompress_ptr cinfo)
|
||||
|
||||
|
||||
LOCAL(boolean)
|
||||
get_sof(j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
|
||||
get_sof(j_decompress_ptr cinfo, boolean is_prog, boolean is_lossless,
|
||||
boolean is_arith)
|
||||
/* Process a SOFn marker */
|
||||
{
|
||||
JLONG length;
|
||||
@ -246,6 +249,7 @@ get_sof(j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
|
||||
INPUT_VARS(cinfo);
|
||||
|
||||
cinfo->progressive_mode = is_prog;
|
||||
cinfo->master->lossless = is_lossless;
|
||||
cinfo->arith_code = is_arith;
|
||||
|
||||
INPUT_2BYTES(cinfo, length, return FALSE);
|
||||
@ -990,32 +994,40 @@ read_markers(j_decompress_ptr cinfo)
|
||||
|
||||
case M_SOF0: /* Baseline */
|
||||
case M_SOF1: /* Extended sequential, Huffman */
|
||||
if (!get_sof(cinfo, FALSE, FALSE))
|
||||
if (!get_sof(cinfo, FALSE, FALSE, FALSE))
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_SOF2: /* Progressive, Huffman */
|
||||
if (!get_sof(cinfo, TRUE, FALSE))
|
||||
if (!get_sof(cinfo, TRUE, FALSE, FALSE))
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_SOF3: /* Lossless, Huffman */
|
||||
if (!get_sof(cinfo, FALSE, TRUE, FALSE))
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_SOF9: /* Extended sequential, arithmetic */
|
||||
if (!get_sof(cinfo, FALSE, TRUE))
|
||||
if (!get_sof(cinfo, FALSE, FALSE, TRUE))
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_SOF10: /* Progressive, arithmetic */
|
||||
if (!get_sof(cinfo, TRUE, TRUE))
|
||||
if (!get_sof(cinfo, TRUE, FALSE, TRUE))
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_SOF11: /* Lossless, arithmetic */
|
||||
if (!get_sof(cinfo, FALSE, TRUE, TRUE))
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
/* Currently unsupported SOFn types */
|
||||
case M_SOF3: /* Lossless, Huffman */
|
||||
case M_SOF5: /* Differential sequential, Huffman */
|
||||
case M_SOF6: /* Differential progressive, Huffman */
|
||||
case M_SOF7: /* Differential lossless, Huffman */
|
||||
case M_JPG: /* Reserved for JPEG extensions */
|
||||
case M_SOF11: /* Lossless, arithmetic */
|
||||
case M_SOF13: /* Differential sequential, arithmetic */
|
||||
case M_SOF14: /* Differential progressive, arithmetic */
|
||||
case M_SOF15: /* Differential lossless, arithmetic */
|
||||
|
643
3rdparty/libjpeg-turbo/src/jdmaster.c
vendored
643
3rdparty/libjpeg-turbo/src/jdmaster.c
vendored
@ -4,8 +4,10 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Modified 2002-2009 by Guido Vollbeding.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2009-2011, 2016, 2019, 2022, D. R. Commander.
|
||||
* Copyright (C) 2009-2011, 2016, 2019, 2022-2023, D. R. Commander.
|
||||
* Copyright (C) 2013, Linaro Limited.
|
||||
* Copyright (C) 2015, Google, Inc.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
@ -20,7 +22,7 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jpegcomp.h"
|
||||
#include "jpegapicomp.h"
|
||||
#include "jdmaster.h"
|
||||
|
||||
|
||||
@ -33,6 +35,9 @@ LOCAL(boolean)
|
||||
use_merged_upsample(j_decompress_ptr cinfo)
|
||||
{
|
||||
#ifdef UPSAMPLE_MERGING_SUPPORTED
|
||||
/* Colorspace conversion is not supported with lossless JPEG images */
|
||||
if (cinfo->master->lossless)
|
||||
return FALSE;
|
||||
/* Merging is the equivalent of plain box-filter upsampling */
|
||||
if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
|
||||
return FALSE;
|
||||
@ -97,154 +102,154 @@ jpeg_core_output_dimensions(j_decompress_ptr cinfo)
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
/* Compute actual output image dimensions and DCT scaling choices. */
|
||||
if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom) {
|
||||
/* Provide 1/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 1;
|
||||
cinfo->_min_DCT_v_scaled_size = 1;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 2) {
|
||||
/* Provide 2/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 2L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 2L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 2;
|
||||
cinfo->_min_DCT_v_scaled_size = 2;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 3) {
|
||||
/* Provide 3/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 3L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 3L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 3;
|
||||
cinfo->_min_DCT_v_scaled_size = 3;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 4) {
|
||||
/* Provide 4/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 4L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 4L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 4;
|
||||
cinfo->_min_DCT_v_scaled_size = 4;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 5) {
|
||||
/* Provide 5/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 5L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 5L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 5;
|
||||
cinfo->_min_DCT_v_scaled_size = 5;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 6) {
|
||||
/* Provide 6/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 6L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 6L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 6;
|
||||
cinfo->_min_DCT_v_scaled_size = 6;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 7) {
|
||||
/* Provide 7/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 7L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 7L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 7;
|
||||
cinfo->_min_DCT_v_scaled_size = 7;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 8) {
|
||||
/* Provide 8/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 8L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 8L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 8;
|
||||
cinfo->_min_DCT_v_scaled_size = 8;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 9) {
|
||||
/* Provide 9/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 9L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 9L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 9;
|
||||
cinfo->_min_DCT_v_scaled_size = 9;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 10) {
|
||||
/* Provide 10/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 10L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 10L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 10;
|
||||
cinfo->_min_DCT_v_scaled_size = 10;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 11) {
|
||||
/* Provide 11/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 11L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 11L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 11;
|
||||
cinfo->_min_DCT_v_scaled_size = 11;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 12) {
|
||||
/* Provide 12/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 12L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 12L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 12;
|
||||
cinfo->_min_DCT_v_scaled_size = 12;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 13) {
|
||||
/* Provide 13/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 13L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 13L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 13;
|
||||
cinfo->_min_DCT_v_scaled_size = 13;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 14) {
|
||||
/* Provide 14/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 14L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 14L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 14;
|
||||
cinfo->_min_DCT_v_scaled_size = 14;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 15) {
|
||||
/* Provide 15/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 15L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 15L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 15;
|
||||
cinfo->_min_DCT_v_scaled_size = 15;
|
||||
} else {
|
||||
/* Provide 16/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 16L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 16L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 16;
|
||||
cinfo->_min_DCT_v_scaled_size = 16;
|
||||
if (!cinfo->master->lossless) {
|
||||
/* Compute actual output image dimensions and DCT scaling choices. */
|
||||
if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom) {
|
||||
/* Provide 1/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 1;
|
||||
cinfo->_min_DCT_v_scaled_size = 1;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 2) {
|
||||
/* Provide 2/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 2L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 2L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 2;
|
||||
cinfo->_min_DCT_v_scaled_size = 2;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 3) {
|
||||
/* Provide 3/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 3L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 3L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 3;
|
||||
cinfo->_min_DCT_v_scaled_size = 3;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 4) {
|
||||
/* Provide 4/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 4L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 4L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 4;
|
||||
cinfo->_min_DCT_v_scaled_size = 4;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 5) {
|
||||
/* Provide 5/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 5L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 5L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 5;
|
||||
cinfo->_min_DCT_v_scaled_size = 5;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 6) {
|
||||
/* Provide 6/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 6L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 6L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 6;
|
||||
cinfo->_min_DCT_v_scaled_size = 6;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 7) {
|
||||
/* Provide 7/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 7L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 7L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 7;
|
||||
cinfo->_min_DCT_v_scaled_size = 7;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 8) {
|
||||
/* Provide 8/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 8L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 8L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 8;
|
||||
cinfo->_min_DCT_v_scaled_size = 8;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 9) {
|
||||
/* Provide 9/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 9L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 9L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 9;
|
||||
cinfo->_min_DCT_v_scaled_size = 9;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 10) {
|
||||
/* Provide 10/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 10L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 10L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 10;
|
||||
cinfo->_min_DCT_v_scaled_size = 10;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 11) {
|
||||
/* Provide 11/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 11L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 11L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 11;
|
||||
cinfo->_min_DCT_v_scaled_size = 11;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 12) {
|
||||
/* Provide 12/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 12L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 12L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 12;
|
||||
cinfo->_min_DCT_v_scaled_size = 12;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 13) {
|
||||
/* Provide 13/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 13L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 13L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 13;
|
||||
cinfo->_min_DCT_v_scaled_size = 13;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 14) {
|
||||
/* Provide 14/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 14L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 14L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 14;
|
||||
cinfo->_min_DCT_v_scaled_size = 14;
|
||||
} else if (cinfo->scale_num * DCTSIZE <= cinfo->scale_denom * 15) {
|
||||
/* Provide 15/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 15L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 15L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 15;
|
||||
cinfo->_min_DCT_v_scaled_size = 15;
|
||||
} else {
|
||||
/* Provide 16/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width * 16L, (long)DCTSIZE);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height * 16L, (long)DCTSIZE);
|
||||
cinfo->_min_DCT_h_scaled_size = 16;
|
||||
cinfo->_min_DCT_v_scaled_size = 16;
|
||||
}
|
||||
|
||||
/* Recompute dimensions of components */
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
compptr->_DCT_h_scaled_size = cinfo->_min_DCT_h_scaled_size;
|
||||
compptr->_DCT_v_scaled_size = cinfo->_min_DCT_v_scaled_size;
|
||||
}
|
||||
} else
|
||||
#endif /* !IDCT_SCALING_SUPPORTED */
|
||||
{
|
||||
/* Hardwire it to "no scaling" */
|
||||
cinfo->output_width = cinfo->image_width;
|
||||
cinfo->output_height = cinfo->image_height;
|
||||
/* jdinput.c has already initialized DCT_scaled_size,
|
||||
* and has computed unscaled downsampled_width and downsampled_height.
|
||||
*/
|
||||
}
|
||||
|
||||
/* Recompute dimensions of components */
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
compptr->_DCT_h_scaled_size = cinfo->_min_DCT_h_scaled_size;
|
||||
compptr->_DCT_v_scaled_size = cinfo->_min_DCT_v_scaled_size;
|
||||
}
|
||||
|
||||
#else /* !IDCT_SCALING_SUPPORTED */
|
||||
|
||||
/* Hardwire it to "no scaling" */
|
||||
cinfo->output_width = cinfo->image_width;
|
||||
cinfo->output_height = cinfo->image_height;
|
||||
/* jdinput.c has already initialized DCT_scaled_size,
|
||||
* and has computed unscaled downsampled_width and downsampled_height.
|
||||
*/
|
||||
|
||||
#endif /* IDCT_SCALING_SUPPORTED */
|
||||
}
|
||||
|
||||
|
||||
@ -273,54 +278,56 @@ jpeg_calc_output_dimensions(j_decompress_ptr cinfo)
|
||||
|
||||
#ifdef IDCT_SCALING_SUPPORTED
|
||||
|
||||
/* In selecting the actual DCT scaling for each component, we try to
|
||||
* scale up the chroma components via IDCT scaling rather than upsampling.
|
||||
* This saves time if the upsampler gets to use 1:1 scaling.
|
||||
* Note this code adapts subsampling ratios which are powers of 2.
|
||||
*/
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
int ssize = cinfo->_min_DCT_scaled_size;
|
||||
while (ssize < DCTSIZE &&
|
||||
((cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) %
|
||||
(compptr->h_samp_factor * ssize * 2) == 0) &&
|
||||
((cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size) %
|
||||
(compptr->v_samp_factor * ssize * 2) == 0)) {
|
||||
ssize = ssize * 2;
|
||||
}
|
||||
if (!cinfo->master->lossless) {
|
||||
/* In selecting the actual DCT scaling for each component, we try to
|
||||
* scale up the chroma components via IDCT scaling rather than upsampling.
|
||||
* This saves time if the upsampler gets to use 1:1 scaling.
|
||||
* Note this code adapts subsampling ratios which are powers of 2.
|
||||
*/
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
int ssize = cinfo->_min_DCT_scaled_size;
|
||||
while (ssize < DCTSIZE &&
|
||||
((cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) %
|
||||
(compptr->h_samp_factor * ssize * 2) == 0) &&
|
||||
((cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size) %
|
||||
(compptr->v_samp_factor * ssize * 2) == 0)) {
|
||||
ssize = ssize * 2;
|
||||
}
|
||||
#if JPEG_LIB_VERSION >= 70
|
||||
compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = ssize;
|
||||
compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = ssize;
|
||||
#else
|
||||
compptr->DCT_scaled_size = ssize;
|
||||
compptr->DCT_scaled_size = ssize;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Recompute downsampled dimensions of components;
|
||||
* application needs to know these if using raw downsampled data.
|
||||
*/
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
/* Size in samples, after IDCT scaling */
|
||||
compptr->downsampled_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width *
|
||||
(long)(compptr->h_samp_factor * compptr->_DCT_scaled_size),
|
||||
(long)(cinfo->max_h_samp_factor * DCTSIZE));
|
||||
compptr->downsampled_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height *
|
||||
(long)(compptr->v_samp_factor * compptr->_DCT_scaled_size),
|
||||
(long)(cinfo->max_v_samp_factor * DCTSIZE));
|
||||
}
|
||||
|
||||
#else /* !IDCT_SCALING_SUPPORTED */
|
||||
|
||||
/* Hardwire it to "no scaling" */
|
||||
cinfo->output_width = cinfo->image_width;
|
||||
cinfo->output_height = cinfo->image_height;
|
||||
/* jdinput.c has already initialized DCT_scaled_size to DCTSIZE,
|
||||
* and has computed unscaled downsampled_width and downsampled_height.
|
||||
*/
|
||||
}
|
||||
|
||||
/* Recompute downsampled dimensions of components;
|
||||
* application needs to know these if using raw downsampled data.
|
||||
*/
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
/* Size in samples, after IDCT scaling */
|
||||
compptr->downsampled_width = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_width *
|
||||
(long)(compptr->h_samp_factor *
|
||||
compptr->_DCT_scaled_size),
|
||||
(long)(cinfo->max_h_samp_factor * DCTSIZE));
|
||||
compptr->downsampled_height = (JDIMENSION)
|
||||
jdiv_round_up((long)cinfo->image_height *
|
||||
(long)(compptr->v_samp_factor *
|
||||
compptr->_DCT_scaled_size),
|
||||
(long)(cinfo->max_v_samp_factor * DCTSIZE));
|
||||
}
|
||||
} else
|
||||
#endif /* IDCT_SCALING_SUPPORTED */
|
||||
{
|
||||
/* Hardwire it to "no scaling" */
|
||||
cinfo->output_width = cinfo->image_width;
|
||||
cinfo->output_height = cinfo->image_height;
|
||||
/* jdinput.c has already initialized DCT_scaled_size to DCTSIZE,
|
||||
* and has computed unscaled downsampled_width and downsampled_height.
|
||||
*/
|
||||
}
|
||||
|
||||
/* Report number of components in selected colorspace. */
|
||||
/* Probably this should be in the color conversion module... */
|
||||
@ -409,27 +416,83 @@ prepare_range_limit_table(j_decompress_ptr cinfo)
|
||||
/* Allocate and fill in the sample_range_limit table */
|
||||
{
|
||||
JSAMPLE *table;
|
||||
J12SAMPLE *table12;
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
J16SAMPLE *table16;
|
||||
#endif
|
||||
int i;
|
||||
|
||||
table = (JSAMPLE *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(5 * (MAXJSAMPLE + 1) + CENTERJSAMPLE) * sizeof(JSAMPLE));
|
||||
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 */
|
||||
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;
|
||||
table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
|
||||
/* End of simple table, rest of first half of post-IDCT table */
|
||||
for (i = CENTERJSAMPLE; i < 2 * (MAXJSAMPLE + 1); i++)
|
||||
table[i] = MAXJSAMPLE;
|
||||
/* Second half of post-IDCT table */
|
||||
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));
|
||||
if (cinfo->data_precision == 16) {
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
table16 = (J16SAMPLE *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(5 * (MAXJ16SAMPLE + 1) + CENTERJ16SAMPLE) *
|
||||
sizeof(J16SAMPLE));
|
||||
table16 += (MAXJ16SAMPLE + 1); /* allow negative subscripts of simple
|
||||
table */
|
||||
cinfo->sample_range_limit = (JSAMPLE *)table16;
|
||||
/* First segment of "simple" table: limit[x] = 0 for x < 0 */
|
||||
memset(table16 - (MAXJ16SAMPLE + 1), 0,
|
||||
(MAXJ16SAMPLE + 1) * sizeof(J16SAMPLE));
|
||||
/* Main part of "simple" table: limit[x] = x */
|
||||
for (i = 0; i <= MAXJ16SAMPLE; i++)
|
||||
table16[i] = (J16SAMPLE)i;
|
||||
table16 += CENTERJ16SAMPLE; /* Point to where post-IDCT table starts */
|
||||
/* End of simple table, rest of first half of post-IDCT table */
|
||||
for (i = CENTERJ16SAMPLE; i < 2 * (MAXJ16SAMPLE + 1); i++)
|
||||
table16[i] = MAXJ16SAMPLE;
|
||||
/* Second half of post-IDCT table */
|
||||
memset(table16 + (2 * (MAXJ16SAMPLE + 1)), 0,
|
||||
(2 * (MAXJ16SAMPLE + 1) - CENTERJ16SAMPLE) * sizeof(J16SAMPLE));
|
||||
memcpy(table16 + (4 * (MAXJ16SAMPLE + 1) - CENTERJ16SAMPLE),
|
||||
cinfo->sample_range_limit, CENTERJ16SAMPLE * sizeof(J16SAMPLE));
|
||||
#else
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
#endif
|
||||
} else if (cinfo->data_precision == 12) {
|
||||
table12 = (J12SAMPLE *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(5 * (MAXJ12SAMPLE + 1) + CENTERJ12SAMPLE) *
|
||||
sizeof(J12SAMPLE));
|
||||
table12 += (MAXJ12SAMPLE + 1); /* allow negative subscripts of simple
|
||||
table */
|
||||
cinfo->sample_range_limit = (JSAMPLE *)table12;
|
||||
/* First segment of "simple" table: limit[x] = 0 for x < 0 */
|
||||
memset(table12 - (MAXJ12SAMPLE + 1), 0,
|
||||
(MAXJ12SAMPLE + 1) * sizeof(J12SAMPLE));
|
||||
/* Main part of "simple" table: limit[x] = x */
|
||||
for (i = 0; i <= MAXJ12SAMPLE; i++)
|
||||
table12[i] = (J12SAMPLE)i;
|
||||
table12 += CENTERJ12SAMPLE; /* Point to where post-IDCT table starts */
|
||||
/* End of simple table, rest of first half of post-IDCT table */
|
||||
for (i = CENTERJ12SAMPLE; i < 2 * (MAXJ12SAMPLE + 1); i++)
|
||||
table12[i] = MAXJ12SAMPLE;
|
||||
/* Second half of post-IDCT table */
|
||||
memset(table12 + (2 * (MAXJ12SAMPLE + 1)), 0,
|
||||
(2 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE) * sizeof(J12SAMPLE));
|
||||
memcpy(table12 + (4 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE),
|
||||
cinfo->sample_range_limit, CENTERJ12SAMPLE * sizeof(J12SAMPLE));
|
||||
} else {
|
||||
table = (JSAMPLE *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(5 * (MAXJSAMPLE + 1) + CENTERJSAMPLE) * sizeof(JSAMPLE));
|
||||
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 */
|
||||
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;
|
||||
table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
|
||||
/* End of simple table, rest of first half of post-IDCT table */
|
||||
for (i = CENTERJSAMPLE; i < 2 * (MAXJSAMPLE + 1); i++)
|
||||
table[i] = MAXJSAMPLE;
|
||||
/* Second half of post-IDCT table */
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -452,6 +515,17 @@ master_selection(j_decompress_ptr cinfo)
|
||||
long samplesperrow;
|
||||
JDIMENSION jd_samplesperrow;
|
||||
|
||||
/* Disable IDCT scaling and raw (downsampled) data output in lossless mode.
|
||||
* IDCT scaling is not useful in lossless mode, and it must be disabled in
|
||||
* order to properly calculate the output dimensions. Raw data output isn't
|
||||
* particularly useful without subsampling and has not been tested in
|
||||
* lossless mode.
|
||||
*/
|
||||
if (cinfo->master->lossless) {
|
||||
cinfo->raw_data_out = FALSE;
|
||||
cinfo->scale_num = cinfo->scale_denom = 1;
|
||||
}
|
||||
|
||||
/* Initialize dimensions and other stuff */
|
||||
jpeg_calc_output_dimensions(cinfo);
|
||||
prepare_range_limit_table(cinfo);
|
||||
@ -480,7 +554,8 @@ master_selection(j_decompress_ptr cinfo)
|
||||
if (cinfo->raw_data_out)
|
||||
ERREXIT(cinfo, JERR_NOTIMPL);
|
||||
/* 2-pass quantizer only works in 3-component color space. */
|
||||
if (cinfo->out_color_components != 3) {
|
||||
if (cinfo->out_color_components != 3 ||
|
||||
cinfo->out_color_space == JCS_RGB565) {
|
||||
cinfo->enable_1pass_quant = TRUE;
|
||||
cinfo->enable_external_quant = FALSE;
|
||||
cinfo->enable_2pass_quant = FALSE;
|
||||
@ -495,7 +570,12 @@ master_selection(j_decompress_ptr cinfo)
|
||||
|
||||
if (cinfo->enable_1pass_quant) {
|
||||
#ifdef QUANT_1PASS_SUPPORTED
|
||||
jinit_1pass_quantizer(cinfo);
|
||||
if (cinfo->data_precision == 16)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
else if (cinfo->data_precision == 12)
|
||||
j12init_1pass_quantizer(cinfo);
|
||||
else
|
||||
jinit_1pass_quantizer(cinfo);
|
||||
master->quantizer_1pass = cinfo->cquantize;
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
@ -505,7 +585,12 @@ master_selection(j_decompress_ptr cinfo)
|
||||
/* We use the 2-pass code to map to external colormaps. */
|
||||
if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
|
||||
#ifdef QUANT_2PASS_SUPPORTED
|
||||
jinit_2pass_quantizer(cinfo);
|
||||
if (cinfo->data_precision == 16)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
else if (cinfo->data_precision == 12)
|
||||
j12init_2pass_quantizer(cinfo);
|
||||
else
|
||||
jinit_2pass_quantizer(cinfo);
|
||||
master->quantizer_2pass = cinfo->cquantize;
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
@ -520,42 +605,122 @@ master_selection(j_decompress_ptr cinfo)
|
||||
if (!cinfo->raw_data_out) {
|
||||
if (master->using_merged_upsample) {
|
||||
#ifdef UPSAMPLE_MERGING_SUPPORTED
|
||||
jinit_merged_upsampler(cinfo); /* does color conversion too */
|
||||
if (cinfo->data_precision == 16)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
else if (cinfo->data_precision == 12)
|
||||
j12init_merged_upsampler(cinfo); /* does color conversion too */
|
||||
else
|
||||
jinit_merged_upsampler(cinfo); /* does color conversion too */
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
} else {
|
||||
jinit_color_deconverter(cinfo);
|
||||
jinit_upsampler(cinfo);
|
||||
}
|
||||
jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
|
||||
}
|
||||
/* Inverse DCT */
|
||||
jinit_inverse_dct(cinfo);
|
||||
/* Entropy decoding: either Huffman or arithmetic coding. */
|
||||
if (cinfo->arith_code) {
|
||||
#ifdef D_ARITH_CODING_SUPPORTED
|
||||
jinit_arith_decoder(cinfo);
|
||||
if (cinfo->data_precision == 16) {
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
j16init_color_deconverter(cinfo);
|
||||
j16init_upsampler(cinfo);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
#endif
|
||||
} else if (cinfo->data_precision == 12) {
|
||||
j12init_color_deconverter(cinfo);
|
||||
j12init_upsampler(cinfo);
|
||||
} else {
|
||||
jinit_color_deconverter(cinfo);
|
||||
jinit_upsampler(cinfo);
|
||||
}
|
||||
}
|
||||
if (cinfo->data_precision == 16)
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
j16init_d_post_controller(cinfo, cinfo->enable_2pass_quant);
|
||||
#else
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
#endif
|
||||
else if (cinfo->data_precision == 12)
|
||||
j12init_d_post_controller(cinfo, cinfo->enable_2pass_quant);
|
||||
else
|
||||
jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
|
||||
}
|
||||
|
||||
if (cinfo->master->lossless) {
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
/* Prediction, sample undifferencing, point transform, and sample size
|
||||
* scaling
|
||||
*/
|
||||
if (cinfo->data_precision == 16)
|
||||
j16init_lossless_decompressor(cinfo);
|
||||
else if (cinfo->data_precision == 12)
|
||||
j12init_lossless_decompressor(cinfo);
|
||||
else
|
||||
jinit_lossless_decompressor(cinfo);
|
||||
/* Entropy decoding: either Huffman or arithmetic coding. */
|
||||
if (cinfo->arith_code) {
|
||||
ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
|
||||
} else {
|
||||
jinit_lhuff_decoder(cinfo);
|
||||
}
|
||||
|
||||
/* Initialize principal buffer controllers. */
|
||||
use_c_buffer = cinfo->inputctl->has_multiple_scans ||
|
||||
cinfo->buffered_image;
|
||||
if (cinfo->data_precision == 16)
|
||||
j16init_d_diff_controller(cinfo, use_c_buffer);
|
||||
else if (cinfo->data_precision == 12)
|
||||
j12init_d_diff_controller(cinfo, use_c_buffer);
|
||||
else
|
||||
jinit_d_diff_controller(cinfo, use_c_buffer);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
} else {
|
||||
if (cinfo->progressive_mode) {
|
||||
#ifdef D_PROGRESSIVE_SUPPORTED
|
||||
jinit_phuff_decoder(cinfo);
|
||||
if (cinfo->data_precision == 16)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
/* Inverse DCT */
|
||||
if (cinfo->data_precision == 12)
|
||||
j12init_inverse_dct(cinfo);
|
||||
else
|
||||
jinit_inverse_dct(cinfo);
|
||||
/* Entropy decoding: either Huffman or arithmetic coding. */
|
||||
if (cinfo->arith_code) {
|
||||
#ifdef D_ARITH_CODING_SUPPORTED
|
||||
jinit_arith_decoder(cinfo);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
|
||||
#endif
|
||||
} else
|
||||
jinit_huff_decoder(cinfo);
|
||||
} else {
|
||||
if (cinfo->progressive_mode) {
|
||||
#ifdef D_PROGRESSIVE_SUPPORTED
|
||||
jinit_phuff_decoder(cinfo);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
} else
|
||||
jinit_huff_decoder(cinfo);
|
||||
}
|
||||
|
||||
/* Initialize principal buffer controllers. */
|
||||
use_c_buffer = cinfo->inputctl->has_multiple_scans ||
|
||||
cinfo->buffered_image;
|
||||
if (cinfo->data_precision == 12)
|
||||
j12init_d_coef_controller(cinfo, use_c_buffer);
|
||||
else
|
||||
jinit_d_coef_controller(cinfo, use_c_buffer);
|
||||
}
|
||||
|
||||
/* Initialize principal buffer controllers. */
|
||||
use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
|
||||
jinit_d_coef_controller(cinfo, use_c_buffer);
|
||||
|
||||
if (!cinfo->raw_data_out)
|
||||
jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
|
||||
if (!cinfo->raw_data_out) {
|
||||
if (cinfo->data_precision == 16)
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
j16init_d_main_controller(cinfo,
|
||||
FALSE /* never need full buffer here */);
|
||||
#else
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
#endif
|
||||
else if (cinfo->data_precision == 12)
|
||||
j12init_d_main_controller(cinfo,
|
||||
FALSE /* never need full buffer here */);
|
||||
else
|
||||
jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
|
||||
}
|
||||
|
||||
/* We can now tell the memory manager to allocate virtual arrays. */
|
||||
(*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo);
|
||||
|
72
3rdparty/libjpeg-turbo/src/jdmerge.c
vendored
72
3rdparty/libjpeg-turbo/src/jdmerge.c
vendored
@ -5,7 +5,7 @@
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
||||
* Copyright (C) 2009, 2011, 2014-2015, 2020, D. R. Commander.
|
||||
* Copyright (C) 2009, 2011, 2014-2015, 2020, 2022, D. R. Commander.
|
||||
* Copyright (C) 2013, Linaro Limited.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
@ -42,7 +42,6 @@
|
||||
#include "jpeglib.h"
|
||||
#include "jdmerge.h"
|
||||
#include "jsimd.h"
|
||||
#include "jconfigint.h"
|
||||
|
||||
#ifdef UPSAMPLE_MERGING_SUPPORTED
|
||||
|
||||
@ -168,20 +167,20 @@ build_ycc_rgb_table(j_decompress_ptr cinfo)
|
||||
|
||||
upsample->Cr_r_tab = (int *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE + 1) * sizeof(int));
|
||||
(_MAXJSAMPLE + 1) * sizeof(int));
|
||||
upsample->Cb_b_tab = (int *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE + 1) * sizeof(int));
|
||||
(_MAXJSAMPLE + 1) * sizeof(int));
|
||||
upsample->Cr_g_tab = (JLONG *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE + 1) * sizeof(JLONG));
|
||||
(_MAXJSAMPLE + 1) * sizeof(JLONG));
|
||||
upsample->Cb_g_tab = (JLONG *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE + 1) * sizeof(JLONG));
|
||||
(_MAXJSAMPLE + 1) * sizeof(JLONG));
|
||||
|
||||
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
|
||||
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
|
||||
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
|
||||
for (i = 0, x = -_CENTERJSAMPLE; i <= _MAXJSAMPLE; i++, x++) {
|
||||
/* i is the actual input pixel value, in the range 0.._MAXJSAMPLE */
|
||||
/* The Cb or Cr value we are thinking of is x = i - _CENTERJSAMPLE */
|
||||
/* Cr=>R value is nearest int to 1.40200 * x */
|
||||
upsample->Cr_r_tab[i] = (int)
|
||||
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
|
||||
@ -220,14 +219,14 @@ start_pass_merged_upsample(j_decompress_ptr cinfo)
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
merged_2v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
merged_2v_upsample(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
|
||||
JDIMENSION in_row_groups_avail, _JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
|
||||
/* 2:1 vertical sampling case: may need a spare row. */
|
||||
{
|
||||
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
|
||||
JSAMPROW work_ptrs[2];
|
||||
_JSAMPROW work_ptrs[2];
|
||||
JDIMENSION num_rows; /* number of rows returned to caller */
|
||||
|
||||
if (upsample->spare_full) {
|
||||
@ -235,8 +234,8 @@ merged_2v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION size = upsample->out_row_width;
|
||||
if (cinfo->out_color_space == JCS_RGB565)
|
||||
size = cinfo->output_width * 2;
|
||||
jcopy_sample_rows(&upsample->spare_row, 0, output_buf + *out_row_ctr, 0, 1,
|
||||
size);
|
||||
_jcopy_sample_rows(&upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
|
||||
1, size);
|
||||
num_rows = 1;
|
||||
upsample->spare_full = FALSE;
|
||||
} else {
|
||||
@ -271,9 +270,9 @@ merged_2v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
merged_1v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
merged_1v_upsample(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
|
||||
JDIMENSION in_row_groups_avail, _JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
|
||||
/* 1:1 vertical sampling case: much easier, never need a spare row. */
|
||||
{
|
||||
@ -303,8 +302,8 @@ merged_1v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
|
||||
h2v1_merged_upsample(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, _JSAMPARRAY output_buf)
|
||||
{
|
||||
switch (cinfo->out_color_space) {
|
||||
case JCS_EXT_RGB:
|
||||
@ -348,8 +347,8 @@ h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
|
||||
h2v2_merged_upsample(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, _JSAMPARRAY output_buf)
|
||||
{
|
||||
switch (cinfo->out_color_space) {
|
||||
case JCS_EXT_RGB:
|
||||
@ -475,8 +474,8 @@ static INLINE boolean is_big_endian(void)
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
h2v1_merged_upsample_565(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
|
||||
h2v1_merged_upsample_565(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, _JSAMPARRAY output_buf)
|
||||
{
|
||||
if (is_big_endian())
|
||||
h2v1_merged_upsample_565_be(cinfo, input_buf, in_row_group_ctr,
|
||||
@ -488,8 +487,8 @@ h2v1_merged_upsample_565(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
h2v1_merged_upsample_565D(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
|
||||
h2v1_merged_upsample_565D(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, _JSAMPARRAY output_buf)
|
||||
{
|
||||
if (is_big_endian())
|
||||
h2v1_merged_upsample_565D_be(cinfo, input_buf, in_row_group_ctr,
|
||||
@ -501,8 +500,8 @@ h2v1_merged_upsample_565D(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
h2v2_merged_upsample_565(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
|
||||
h2v2_merged_upsample_565(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, _JSAMPARRAY output_buf)
|
||||
{
|
||||
if (is_big_endian())
|
||||
h2v2_merged_upsample_565_be(cinfo, input_buf, in_row_group_ctr,
|
||||
@ -514,8 +513,8 @@ h2v2_merged_upsample_565(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
h2v2_merged_upsample_565D(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
|
||||
h2v2_merged_upsample_565D(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, _JSAMPARRAY output_buf)
|
||||
{
|
||||
if (is_big_endian())
|
||||
h2v2_merged_upsample_565D_be(cinfo, input_buf, in_row_group_ctr,
|
||||
@ -535,10 +534,13 @@ h2v2_merged_upsample_565D(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_merged_upsampler(j_decompress_ptr cinfo)
|
||||
_jinit_merged_upsampler(j_decompress_ptr cinfo)
|
||||
{
|
||||
my_merged_upsample_ptr upsample;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
upsample = (my_merged_upsample_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_merged_upsampler));
|
||||
@ -549,10 +551,12 @@ jinit_merged_upsampler(j_decompress_ptr cinfo)
|
||||
upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
|
||||
|
||||
if (cinfo->max_v_samp_factor == 2) {
|
||||
upsample->pub.upsample = merged_2v_upsample;
|
||||
upsample->pub._upsample = merged_2v_upsample;
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_h2v2_merged_upsample())
|
||||
upsample->upmethod = jsimd_h2v2_merged_upsample;
|
||||
else
|
||||
#endif
|
||||
upsample->upmethod = h2v2_merged_upsample;
|
||||
if (cinfo->out_color_space == JCS_RGB565) {
|
||||
if (cinfo->dither_mode != JDITHER_NONE) {
|
||||
@ -562,14 +566,16 @@ jinit_merged_upsampler(j_decompress_ptr cinfo)
|
||||
}
|
||||
}
|
||||
/* Allocate a spare row buffer */
|
||||
upsample->spare_row = (JSAMPROW)
|
||||
upsample->spare_row = (_JSAMPROW)
|
||||
(*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(size_t)(upsample->out_row_width * sizeof(JSAMPLE)));
|
||||
(size_t)(upsample->out_row_width * sizeof(_JSAMPLE)));
|
||||
} else {
|
||||
upsample->pub.upsample = merged_1v_upsample;
|
||||
upsample->pub._upsample = merged_1v_upsample;
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_h2v1_merged_upsample())
|
||||
upsample->upmethod = jsimd_h2v1_merged_upsample;
|
||||
else
|
||||
#endif
|
||||
upsample->upmethod = h2v1_merged_upsample;
|
||||
if (cinfo->out_color_space == JCS_RGB565) {
|
||||
if (cinfo->dither_mode != JDITHER_NONE) {
|
||||
|
9
3rdparty/libjpeg-turbo/src/jdmerge.h
vendored
9
3rdparty/libjpeg-turbo/src/jdmerge.h
vendored
@ -4,13 +4,14 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jpeglib.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
#ifdef UPSAMPLE_MERGING_SUPPORTED
|
||||
|
||||
@ -21,8 +22,8 @@ typedef struct {
|
||||
struct jpeg_upsampler pub; /* public fields */
|
||||
|
||||
/* Pointer to routine to do actual upsampling/conversion of one row group */
|
||||
void (*upmethod) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf);
|
||||
void (*upmethod) (j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, _JSAMPARRAY output_buf);
|
||||
|
||||
/* Private state for YCC->RGB conversion */
|
||||
int *Cr_r_tab; /* => table for Cr to R conversion */
|
||||
@ -35,7 +36,7 @@ typedef struct {
|
||||
* application provides just a one-row buffer; we also use the spare
|
||||
* to discard the dummy last row if the image height is odd.
|
||||
*/
|
||||
JSAMPROW spare_row;
|
||||
_JSAMPROW spare_row;
|
||||
boolean spare_full; /* T if spare buffer is occupied */
|
||||
|
||||
JDIMENSION out_row_width; /* samples per output row */
|
||||
|
43
3rdparty/libjpeg-turbo/src/jdmrg565.c
vendored
43
3rdparty/libjpeg-turbo/src/jdmrg565.c
vendored
@ -5,7 +5,7 @@
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2013, Linaro Limited.
|
||||
* Copyright (C) 2014-2015, 2018, 2020, D. R. Commander.
|
||||
* Copyright (C) 2014-2015, 2018, 2020, 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -15,18 +15,19 @@
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
h2v1_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
h2v1_merged_upsample_565_internal(j_decompress_ptr cinfo,
|
||||
_JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf)
|
||||
_JSAMPARRAY output_buf)
|
||||
{
|
||||
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
|
||||
register int y, cred, cgreen, cblue;
|
||||
int cb, cr;
|
||||
register JSAMPROW outptr;
|
||||
JSAMPROW inptr0, inptr1, inptr2;
|
||||
register _JSAMPROW outptr;
|
||||
_JSAMPROW inptr0, inptr1, inptr2;
|
||||
JDIMENSION col;
|
||||
/* copy these pointers into registers if possible */
|
||||
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
|
||||
int *Crrtab = upsample->Cr_r_tab;
|
||||
int *Cbbtab = upsample->Cb_b_tab;
|
||||
JLONG *Crgtab = upsample->Cr_g_tab;
|
||||
@ -86,18 +87,18 @@ h2v1_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
h2v1_merged_upsample_565D_internal(j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf,
|
||||
_JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf)
|
||||
_JSAMPARRAY output_buf)
|
||||
{
|
||||
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
|
||||
register int y, cred, cgreen, cblue;
|
||||
int cb, cr;
|
||||
register JSAMPROW outptr;
|
||||
JSAMPROW inptr0, inptr1, inptr2;
|
||||
register _JSAMPROW outptr;
|
||||
_JSAMPROW inptr0, inptr1, inptr2;
|
||||
JDIMENSION col;
|
||||
/* copy these pointers into registers if possible */
|
||||
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
|
||||
int *Crrtab = upsample->Cr_r_tab;
|
||||
int *Cbbtab = upsample->Cb_b_tab;
|
||||
JLONG *Crgtab = upsample->Cr_g_tab;
|
||||
@ -159,18 +160,18 @@ h2v1_merged_upsample_565D_internal(j_decompress_ptr cinfo,
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
h2v2_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
h2v2_merged_upsample_565_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf)
|
||||
_JSAMPARRAY output_buf)
|
||||
{
|
||||
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
|
||||
register int y, cred, cgreen, cblue;
|
||||
int cb, cr;
|
||||
register JSAMPROW outptr0, outptr1;
|
||||
JSAMPROW inptr00, inptr01, inptr1, inptr2;
|
||||
register _JSAMPROW outptr0, outptr1;
|
||||
_JSAMPROW inptr00, inptr01, inptr1, inptr2;
|
||||
JDIMENSION col;
|
||||
/* copy these pointers into registers if possible */
|
||||
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
|
||||
int *Crrtab = upsample->Cr_r_tab;
|
||||
int *Cbbtab = upsample->Cb_b_tab;
|
||||
JLONG *Crgtab = upsample->Cr_g_tab;
|
||||
@ -255,18 +256,18 @@ h2v2_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
h2v2_merged_upsample_565D_internal(j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf,
|
||||
_JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf)
|
||||
_JSAMPARRAY output_buf)
|
||||
{
|
||||
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
|
||||
register int y, cred, cgreen, cblue;
|
||||
int cb, cr;
|
||||
register JSAMPROW outptr0, outptr1;
|
||||
JSAMPROW inptr00, inptr01, inptr1, inptr2;
|
||||
register _JSAMPROW outptr0, outptr1;
|
||||
_JSAMPROW inptr00, inptr01, inptr1, inptr2;
|
||||
JDIMENSION col;
|
||||
/* copy these pointers into registers if possible */
|
||||
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
|
||||
int *Crrtab = upsample->Cr_r_tab;
|
||||
int *Cbbtab = upsample->Cb_b_tab;
|
||||
JLONG *Crgtab = upsample->Cr_g_tab;
|
||||
|
40
3rdparty/libjpeg-turbo/src/jdmrgext.c
vendored
40
3rdparty/libjpeg-turbo/src/jdmrgext.c
vendored
@ -4,7 +4,7 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2011, 2015, 2020, D. R. Commander.
|
||||
* Copyright (C) 2011, 2015, 2020, 2022-2023, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -21,18 +21,18 @@
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
h2v1_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
h2v1_merged_upsample_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf)
|
||||
_JSAMPARRAY output_buf)
|
||||
{
|
||||
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
|
||||
register int y, cred, cgreen, cblue;
|
||||
int cb, cr;
|
||||
register JSAMPROW outptr;
|
||||
JSAMPROW inptr0, inptr1, inptr2;
|
||||
register _JSAMPROW outptr;
|
||||
_JSAMPROW inptr0, inptr1, inptr2;
|
||||
JDIMENSION col;
|
||||
/* copy these pointers into registers if possible */
|
||||
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
|
||||
int *Crrtab = upsample->Cr_r_tab;
|
||||
int *Cbbtab = upsample->Cb_b_tab;
|
||||
JLONG *Crgtab = upsample->Cr_g_tab;
|
||||
@ -57,7 +57,7 @@ h2v1_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
outptr[RGB_GREEN] = range_limit[y + cgreen];
|
||||
outptr[RGB_BLUE] = range_limit[y + cblue];
|
||||
#ifdef RGB_ALPHA
|
||||
outptr[RGB_ALPHA] = 0xFF;
|
||||
outptr[RGB_ALPHA] = _MAXJSAMPLE;
|
||||
#endif
|
||||
outptr += RGB_PIXELSIZE;
|
||||
y = *inptr0++;
|
||||
@ -65,7 +65,7 @@ h2v1_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
outptr[RGB_GREEN] = range_limit[y + cgreen];
|
||||
outptr[RGB_BLUE] = range_limit[y + cblue];
|
||||
#ifdef RGB_ALPHA
|
||||
outptr[RGB_ALPHA] = 0xFF;
|
||||
outptr[RGB_ALPHA] = _MAXJSAMPLE;
|
||||
#endif
|
||||
outptr += RGB_PIXELSIZE;
|
||||
}
|
||||
@ -81,7 +81,7 @@ h2v1_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
outptr[RGB_GREEN] = range_limit[y + cgreen];
|
||||
outptr[RGB_BLUE] = range_limit[y + cblue];
|
||||
#ifdef RGB_ALPHA
|
||||
outptr[RGB_ALPHA] = 0xFF;
|
||||
outptr[RGB_ALPHA] = _MAXJSAMPLE;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -93,18 +93,18 @@ h2v1_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
h2v2_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
h2v2_merged_upsample_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf)
|
||||
_JSAMPARRAY output_buf)
|
||||
{
|
||||
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
|
||||
register int y, cred, cgreen, cblue;
|
||||
int cb, cr;
|
||||
register JSAMPROW outptr0, outptr1;
|
||||
JSAMPROW inptr00, inptr01, inptr1, inptr2;
|
||||
register _JSAMPROW outptr0, outptr1;
|
||||
_JSAMPROW inptr00, inptr01, inptr1, inptr2;
|
||||
JDIMENSION col;
|
||||
/* copy these pointers into registers if possible */
|
||||
register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
|
||||
int *Crrtab = upsample->Cr_r_tab;
|
||||
int *Cbbtab = upsample->Cb_b_tab;
|
||||
JLONG *Crgtab = upsample->Cr_g_tab;
|
||||
@ -131,7 +131,7 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
outptr0[RGB_GREEN] = range_limit[y + cgreen];
|
||||
outptr0[RGB_BLUE] = range_limit[y + cblue];
|
||||
#ifdef RGB_ALPHA
|
||||
outptr0[RGB_ALPHA] = 0xFF;
|
||||
outptr0[RGB_ALPHA] = _MAXJSAMPLE;
|
||||
#endif
|
||||
outptr0 += RGB_PIXELSIZE;
|
||||
y = *inptr00++;
|
||||
@ -139,7 +139,7 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
outptr0[RGB_GREEN] = range_limit[y + cgreen];
|
||||
outptr0[RGB_BLUE] = range_limit[y + cblue];
|
||||
#ifdef RGB_ALPHA
|
||||
outptr0[RGB_ALPHA] = 0xFF;
|
||||
outptr0[RGB_ALPHA] = _MAXJSAMPLE;
|
||||
#endif
|
||||
outptr0 += RGB_PIXELSIZE;
|
||||
y = *inptr01++;
|
||||
@ -147,7 +147,7 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
outptr1[RGB_GREEN] = range_limit[y + cgreen];
|
||||
outptr1[RGB_BLUE] = range_limit[y + cblue];
|
||||
#ifdef RGB_ALPHA
|
||||
outptr1[RGB_ALPHA] = 0xFF;
|
||||
outptr1[RGB_ALPHA] = _MAXJSAMPLE;
|
||||
#endif
|
||||
outptr1 += RGB_PIXELSIZE;
|
||||
y = *inptr01++;
|
||||
@ -155,7 +155,7 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
outptr1[RGB_GREEN] = range_limit[y + cgreen];
|
||||
outptr1[RGB_BLUE] = range_limit[y + cblue];
|
||||
#ifdef RGB_ALPHA
|
||||
outptr1[RGB_ALPHA] = 0xFF;
|
||||
outptr1[RGB_ALPHA] = _MAXJSAMPLE;
|
||||
#endif
|
||||
outptr1 += RGB_PIXELSIZE;
|
||||
}
|
||||
@ -171,14 +171,14 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
outptr0[RGB_GREEN] = range_limit[y + cgreen];
|
||||
outptr0[RGB_BLUE] = range_limit[y + cblue];
|
||||
#ifdef RGB_ALPHA
|
||||
outptr0[RGB_ALPHA] = 0xFF;
|
||||
outptr0[RGB_ALPHA] = _MAXJSAMPLE;
|
||||
#endif
|
||||
y = *inptr01;
|
||||
outptr1[RGB_RED] = range_limit[y + cred];
|
||||
outptr1[RGB_GREEN] = range_limit[y + cgreen];
|
||||
outptr1[RGB_BLUE] = range_limit[y + cblue];
|
||||
#ifdef RGB_ALPHA
|
||||
outptr1[RGB_ALPHA] = 0xFF;
|
||||
outptr1[RGB_ALPHA] = _MAXJSAMPLE;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
4
3rdparty/libjpeg-turbo/src/jdphuff.c
vendored
4
3rdparty/libjpeg-turbo/src/jdphuff.c
vendored
@ -3,6 +3,8 @@
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1995-1997, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2015-2016, 2018-2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
@ -23,7 +25,7 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jdhuff.h" /* Declarations shared with jdhuff.c */
|
||||
#include "jdhuff.h" /* Declarations shared with jd*huff.c */
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
|
109
3rdparty/libjpeg-turbo/src/jdpostct.c
vendored
109
3rdparty/libjpeg-turbo/src/jdpostct.c
vendored
@ -3,8 +3,8 @@
|
||||
*
|
||||
* This file was 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-2023, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -22,8 +22,11 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
|
||||
|
||||
/* Private buffer controller object */
|
||||
|
||||
typedef struct {
|
||||
@ -35,7 +38,7 @@ typedef struct {
|
||||
* for one-pass operation, a strip buffer is sufficient.
|
||||
*/
|
||||
jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
|
||||
JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
|
||||
_JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
|
||||
JDIMENSION strip_height; /* buffer size in rows */
|
||||
/* for two-pass mode only: */
|
||||
JDIMENSION starting_row; /* row # of first row in current strip */
|
||||
@ -46,26 +49,28 @@ typedef my_post_controller *my_post_ptr;
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
METHODDEF(void) post_process_1pass(j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf,
|
||||
_JSAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf,
|
||||
_JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail);
|
||||
#ifdef QUANT_2PASS_SUPPORTED
|
||||
#endif
|
||||
#if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16
|
||||
METHODDEF(void) post_process_prepass(j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf,
|
||||
_JSAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf,
|
||||
_JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail);
|
||||
METHODDEF(void) post_process_2pass(j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf,
|
||||
_JSAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf,
|
||||
_JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail);
|
||||
#endif
|
||||
@ -82,39 +87,42 @@ start_pass_dpost(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
|
||||
switch (pass_mode) {
|
||||
case JBUF_PASS_THRU:
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
if (cinfo->quantize_colors) {
|
||||
/* Single-pass processing with color quantization. */
|
||||
post->pub.post_process_data = post_process_1pass;
|
||||
post->pub._post_process_data = post_process_1pass;
|
||||
/* We could be doing buffered-image output before starting a 2-pass
|
||||
* color quantization; in that case, jinit_d_post_controller did not
|
||||
* allocate a strip buffer. Use the virtual-array buffer as workspace.
|
||||
*/
|
||||
if (post->buffer == NULL) {
|
||||
post->buffer = (*cinfo->mem->access_virt_sarray)
|
||||
post->buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr)cinfo, post->whole_image,
|
||||
(JDIMENSION)0, post->strip_height, TRUE);
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/* For single-pass processing without color quantization,
|
||||
* I have no work to do; just call the upsampler directly.
|
||||
*/
|
||||
post->pub.post_process_data = cinfo->upsample->upsample;
|
||||
post->pub._post_process_data = cinfo->upsample->_upsample;
|
||||
}
|
||||
break;
|
||||
#ifdef QUANT_2PASS_SUPPORTED
|
||||
#if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16
|
||||
case JBUF_SAVE_AND_PASS:
|
||||
/* First pass of 2-pass quantization */
|
||||
if (post->whole_image == NULL)
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
post->pub.post_process_data = post_process_prepass;
|
||||
post->pub._post_process_data = post_process_prepass;
|
||||
break;
|
||||
case JBUF_CRANK_DEST:
|
||||
/* Second pass of 2-pass quantization */
|
||||
if (post->whole_image == NULL)
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
post->pub.post_process_data = post_process_2pass;
|
||||
post->pub._post_process_data = post_process_2pass;
|
||||
break;
|
||||
#endif /* QUANT_2PASS_SUPPORTED */
|
||||
#endif /* defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
break;
|
||||
@ -128,10 +136,12 @@ start_pass_dpost(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
* This is used for color precision reduction as well as one-pass quantization.
|
||||
*/
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
|
||||
METHODDEF(void)
|
||||
post_process_1pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
post_process_1pass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
|
||||
JDIMENSION in_row_groups_avail, _JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
|
||||
{
|
||||
my_post_ptr post = (my_post_ptr)cinfo->post;
|
||||
@ -143,27 +153,29 @@ post_process_1pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
if (max_rows > post->strip_height)
|
||||
max_rows = post->strip_height;
|
||||
num_rows = 0;
|
||||
(*cinfo->upsample->upsample) (cinfo, input_buf, in_row_group_ctr,
|
||||
in_row_groups_avail, post->buffer, &num_rows,
|
||||
max_rows);
|
||||
(*cinfo->upsample->_upsample) (cinfo, input_buf, in_row_group_ctr,
|
||||
in_row_groups_avail, post->buffer, &num_rows,
|
||||
max_rows);
|
||||
/* Quantize and emit data. */
|
||||
(*cinfo->cquantize->color_quantize) (cinfo, post->buffer,
|
||||
output_buf + *out_row_ctr,
|
||||
(int)num_rows);
|
||||
(*cinfo->cquantize->_color_quantize) (cinfo, post->buffer,
|
||||
output_buf + *out_row_ctr,
|
||||
(int)num_rows);
|
||||
*out_row_ctr += num_rows;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef QUANT_2PASS_SUPPORTED
|
||||
|
||||
#if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16
|
||||
|
||||
/*
|
||||
* Process some data in the first pass of 2-pass quantization.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
post_process_prepass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
post_process_prepass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
|
||||
JDIMENSION in_row_groups_avail, _JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
|
||||
{
|
||||
my_post_ptr post = (my_post_ptr)cinfo->post;
|
||||
@ -171,23 +183,23 @@ post_process_prepass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
/* Reposition virtual buffer if at start of strip. */
|
||||
if (post->next_row == 0) {
|
||||
post->buffer = (*cinfo->mem->access_virt_sarray)
|
||||
post->buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr)cinfo, post->whole_image,
|
||||
post->starting_row, post->strip_height, TRUE);
|
||||
}
|
||||
|
||||
/* Upsample some data (up to a strip height's worth). */
|
||||
old_next_row = post->next_row;
|
||||
(*cinfo->upsample->upsample) (cinfo, input_buf, in_row_group_ctr,
|
||||
in_row_groups_avail, post->buffer,
|
||||
&post->next_row, post->strip_height);
|
||||
(*cinfo->upsample->_upsample) (cinfo, input_buf, in_row_group_ctr,
|
||||
in_row_groups_avail, post->buffer,
|
||||
&post->next_row, post->strip_height);
|
||||
|
||||
/* Allow quantizer to scan new data. No data is emitted, */
|
||||
/* but we advance out_row_ctr so outer loop can tell when we're done. */
|
||||
if (post->next_row > old_next_row) {
|
||||
num_rows = post->next_row - old_next_row;
|
||||
(*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
|
||||
(JSAMPARRAY)NULL, (int)num_rows);
|
||||
(*cinfo->cquantize->_color_quantize) (cinfo, post->buffer + old_next_row,
|
||||
(_JSAMPARRAY)NULL, (int)num_rows);
|
||||
*out_row_ctr += num_rows;
|
||||
}
|
||||
|
||||
@ -204,9 +216,9 @@ post_process_prepass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
post_process_2pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
post_process_2pass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
|
||||
JDIMENSION in_row_groups_avail, _JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
|
||||
{
|
||||
my_post_ptr post = (my_post_ptr)cinfo->post;
|
||||
@ -214,7 +226,7 @@ post_process_2pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
/* Reposition virtual buffer if at start of strip. */
|
||||
if (post->next_row == 0) {
|
||||
post->buffer = (*cinfo->mem->access_virt_sarray)
|
||||
post->buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr)cinfo, post->whole_image,
|
||||
post->starting_row, post->strip_height, FALSE);
|
||||
}
|
||||
@ -230,9 +242,9 @@ post_process_2pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
num_rows = max_rows;
|
||||
|
||||
/* Quantize and emit data. */
|
||||
(*cinfo->cquantize->color_quantize) (cinfo, post->buffer + post->next_row,
|
||||
output_buf + *out_row_ctr,
|
||||
(int)num_rows);
|
||||
(*cinfo->cquantize->_color_quantize) (cinfo, post->buffer + post->next_row,
|
||||
output_buf + *out_row_ctr,
|
||||
(int)num_rows);
|
||||
*out_row_ctr += num_rows;
|
||||
|
||||
/* Advance if we filled the strip. */
|
||||
@ -243,7 +255,7 @@ post_process_2pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* QUANT_2PASS_SUPPORTED */
|
||||
#endif /* defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */
|
||||
|
||||
|
||||
/*
|
||||
@ -251,10 +263,13 @@ post_process_2pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_d_post_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
_jinit_d_post_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_post_ptr post;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
post = (my_post_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_post_controller));
|
||||
@ -265,6 +280,7 @@ jinit_d_post_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
|
||||
/* Create the quantization buffer, if needed */
|
||||
if (cinfo->quantize_colors) {
|
||||
#if BITS_IN_JSAMPLE != 16
|
||||
/* The buffer strip height is max_v_samp_factor, which is typically
|
||||
* an efficient number of rows for upsampling to return.
|
||||
* (In the presence of output rescaling, we might want to be smarter?)
|
||||
@ -285,10 +301,15 @@ jinit_d_post_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
#endif /* QUANT_2PASS_SUPPORTED */
|
||||
} else {
|
||||
/* One-pass color quantization: just make a strip buffer. */
|
||||
post->buffer = (*cinfo->mem->alloc_sarray)
|
||||
post->buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
cinfo->output_width * cinfo->out_color_components,
|
||||
post->strip_height);
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOTIMPL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */
|
||||
|
128
3rdparty/libjpeg-turbo/src/jdsample.c
vendored
128
3rdparty/libjpeg-turbo/src/jdsample.c
vendored
@ -5,7 +5,7 @@
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
||||
* Copyright (C) 2010, 2015-2016, D. R. Commander.
|
||||
* Copyright (C) 2010, 2015-2016, 2022, D. R. Commander.
|
||||
* Copyright (C) 2014, MIPS Technologies, Inc., California.
|
||||
* Copyright (C) 2015, Google, Inc.
|
||||
* Copyright (C) 2019-2020, Arm Limited.
|
||||
@ -28,10 +28,12 @@
|
||||
#include "jinclude.h"
|
||||
#include "jdsample.h"
|
||||
#include "jsimd.h"
|
||||
#include "jpegcomp.h"
|
||||
#include "jpegapicomp.h"
|
||||
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
|
||||
|
||||
/*
|
||||
* Initialize for an upsampling pass.
|
||||
*/
|
||||
@ -57,9 +59,9 @@ start_pass_upsample(j_decompress_ptr cinfo)
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
sep_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
sep_upsample(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
_JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
{
|
||||
my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
|
||||
@ -95,9 +97,10 @@ sep_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
if (num_rows > out_rows_avail)
|
||||
num_rows = out_rows_avail;
|
||||
|
||||
(*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
|
||||
(JDIMENSION)upsample->next_row_out,
|
||||
output_buf + *out_row_ctr, (int)num_rows);
|
||||
(*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
|
||||
(JDIMENSION)upsample->next_row_out,
|
||||
output_buf + *out_row_ctr,
|
||||
(int)num_rows);
|
||||
|
||||
/* Adjust counts */
|
||||
*out_row_ctr += num_rows;
|
||||
@ -124,7 +127,7 @@ sep_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
|
||||
METHODDEF(void)
|
||||
fullsize_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
|
||||
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
|
||||
{
|
||||
*output_data_ptr = input_data;
|
||||
}
|
||||
@ -137,7 +140,7 @@ fullsize_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
noop_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
|
||||
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
|
||||
{
|
||||
*output_data_ptr = NULL; /* safety check */
|
||||
}
|
||||
@ -156,14 +159,14 @@ noop_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
|
||||
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
|
||||
{
|
||||
my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
|
||||
JSAMPARRAY output_data = *output_data_ptr;
|
||||
register JSAMPROW inptr, outptr;
|
||||
register JSAMPLE invalue;
|
||||
_JSAMPARRAY output_data = *output_data_ptr;
|
||||
register _JSAMPROW inptr, outptr;
|
||||
register _JSAMPLE invalue;
|
||||
register int h;
|
||||
JSAMPROW outend;
|
||||
_JSAMPROW outend;
|
||||
int h_expand, v_expand;
|
||||
int inrow, outrow;
|
||||
|
||||
@ -184,8 +187,8 @@ int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
}
|
||||
/* Generate any additional output rows by duplicating the first one */
|
||||
if (v_expand > 1) {
|
||||
jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
|
||||
v_expand - 1, cinfo->output_width);
|
||||
_jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
|
||||
v_expand - 1, cinfo->output_width);
|
||||
}
|
||||
inrow++;
|
||||
outrow += v_expand;
|
||||
@ -200,12 +203,12 @@ int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
|
||||
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
|
||||
{
|
||||
JSAMPARRAY output_data = *output_data_ptr;
|
||||
register JSAMPROW inptr, outptr;
|
||||
register JSAMPLE invalue;
|
||||
JSAMPROW outend;
|
||||
_JSAMPARRAY output_data = *output_data_ptr;
|
||||
register _JSAMPROW inptr, outptr;
|
||||
register _JSAMPLE invalue;
|
||||
_JSAMPROW outend;
|
||||
int inrow;
|
||||
|
||||
for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
|
||||
@ -228,12 +231,12 @@ h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
|
||||
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
|
||||
{
|
||||
JSAMPARRAY output_data = *output_data_ptr;
|
||||
register JSAMPROW inptr, outptr;
|
||||
register JSAMPLE invalue;
|
||||
JSAMPROW outend;
|
||||
_JSAMPARRAY output_data = *output_data_ptr;
|
||||
register _JSAMPROW inptr, outptr;
|
||||
register _JSAMPLE invalue;
|
||||
_JSAMPROW outend;
|
||||
int inrow, outrow;
|
||||
|
||||
inrow = outrow = 0;
|
||||
@ -246,8 +249,8 @@ h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*outptr++ = invalue;
|
||||
*outptr++ = invalue;
|
||||
}
|
||||
jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
|
||||
cinfo->output_width);
|
||||
_jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
|
||||
cinfo->output_width);
|
||||
inrow++;
|
||||
outrow += 2;
|
||||
}
|
||||
@ -271,10 +274,10 @@ h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
|
||||
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
|
||||
{
|
||||
JSAMPARRAY output_data = *output_data_ptr;
|
||||
register JSAMPROW inptr, outptr;
|
||||
_JSAMPARRAY output_data = *output_data_ptr;
|
||||
register _JSAMPROW inptr, outptr;
|
||||
register int invalue;
|
||||
register JDIMENSION colctr;
|
||||
int inrow;
|
||||
@ -284,20 +287,20 @@ h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
outptr = output_data[inrow];
|
||||
/* Special case for first column */
|
||||
invalue = *inptr++;
|
||||
*outptr++ = (JSAMPLE)invalue;
|
||||
*outptr++ = (JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
|
||||
*outptr++ = (_JSAMPLE)invalue;
|
||||
*outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
|
||||
|
||||
for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
|
||||
/* General case: 3/4 * nearer pixel + 1/4 * further pixel */
|
||||
invalue = (*inptr++) * 3;
|
||||
*outptr++ = (JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
|
||||
*outptr++ = (JSAMPLE)((invalue + inptr[0] + 2) >> 2);
|
||||
*outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
|
||||
*outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
|
||||
}
|
||||
|
||||
/* Special case for last column */
|
||||
invalue = *inptr;
|
||||
*outptr++ = (JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
|
||||
*outptr++ = (JSAMPLE)invalue;
|
||||
*outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
|
||||
*outptr++ = (_JSAMPLE)invalue;
|
||||
}
|
||||
}
|
||||
|
||||
@ -311,10 +314,10 @@ h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
|
||||
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
|
||||
{
|
||||
JSAMPARRAY output_data = *output_data_ptr;
|
||||
JSAMPROW inptr0, inptr1, outptr;
|
||||
_JSAMPARRAY output_data = *output_data_ptr;
|
||||
_JSAMPROW inptr0, inptr1, outptr;
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
int thiscolsum, bias;
|
||||
#else
|
||||
@ -339,7 +342,7 @@ h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
|
||||
for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
|
||||
thiscolsum = (*inptr0++) * 3 + (*inptr1++);
|
||||
*outptr++ = (JSAMPLE)((thiscolsum + bias) >> 2);
|
||||
*outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
|
||||
}
|
||||
}
|
||||
inrow++;
|
||||
@ -357,10 +360,10 @@ h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
|
||||
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
|
||||
{
|
||||
JSAMPARRAY output_data = *output_data_ptr;
|
||||
register JSAMPROW inptr0, inptr1, outptr;
|
||||
_JSAMPARRAY output_data = *output_data_ptr;
|
||||
register _JSAMPROW inptr0, inptr1, outptr;
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
register int thiscolsum, lastcolsum, nextcolsum;
|
||||
#else
|
||||
@ -383,22 +386,22 @@ h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
/* Special case for first column */
|
||||
thiscolsum = (*inptr0++) * 3 + (*inptr1++);
|
||||
nextcolsum = (*inptr0++) * 3 + (*inptr1++);
|
||||
*outptr++ = (JSAMPLE)((thiscolsum * 4 + 8) >> 4);
|
||||
*outptr++ = (JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
|
||||
*outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
|
||||
*outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
|
||||
lastcolsum = thiscolsum; thiscolsum = nextcolsum;
|
||||
|
||||
for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
|
||||
/* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
|
||||
/* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
|
||||
nextcolsum = (*inptr0++) * 3 + (*inptr1++);
|
||||
*outptr++ = (JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
|
||||
*outptr++ = (JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
|
||||
*outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
|
||||
*outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
|
||||
lastcolsum = thiscolsum; thiscolsum = nextcolsum;
|
||||
}
|
||||
|
||||
/* Special case for last column */
|
||||
*outptr++ = (JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
|
||||
*outptr++ = (JSAMPLE)((thiscolsum * 4 + 7) >> 4);
|
||||
*outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
|
||||
*outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
|
||||
}
|
||||
inrow++;
|
||||
}
|
||||
@ -410,7 +413,7 @@ h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_upsampler(j_decompress_ptr cinfo)
|
||||
_jinit_upsampler(j_decompress_ptr cinfo)
|
||||
{
|
||||
my_upsample_ptr upsample;
|
||||
int ci;
|
||||
@ -418,13 +421,16 @@ jinit_upsampler(j_decompress_ptr cinfo)
|
||||
boolean need_buffer, do_fancy;
|
||||
int h_in_group, v_in_group, h_out_group, v_out_group;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
if (!cinfo->master->jinit_upsampler_no_alloc) {
|
||||
upsample = (my_upsample_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_upsampler));
|
||||
cinfo->upsample = (struct jpeg_upsampler *)upsample;
|
||||
upsample->pub.start_pass = start_pass_upsample;
|
||||
upsample->pub.upsample = sep_upsample;
|
||||
upsample->pub._upsample = sep_upsample;
|
||||
upsample->pub.need_context_rows = FALSE; /* until we find out differently */
|
||||
} else
|
||||
upsample = (my_upsample_ptr)cinfo->upsample;
|
||||
@ -464,21 +470,25 @@ jinit_upsampler(j_decompress_ptr cinfo)
|
||||
} else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
|
||||
/* Special cases for 2h1v upsampling */
|
||||
if (do_fancy && compptr->downsampled_width > 2) {
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_h2v1_fancy_upsample())
|
||||
upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
|
||||
else
|
||||
#endif
|
||||
upsample->methods[ci] = h2v1_fancy_upsample;
|
||||
} else {
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_h2v1_upsample())
|
||||
upsample->methods[ci] = jsimd_h2v1_upsample;
|
||||
else
|
||||
#endif
|
||||
upsample->methods[ci] = h2v1_upsample;
|
||||
}
|
||||
} else if (h_in_group == h_out_group &&
|
||||
v_in_group * 2 == v_out_group && do_fancy) {
|
||||
/* Non-fancy upsampling is handled by the generic method */
|
||||
#if defined(__arm__) || defined(__aarch64__) || \
|
||||
defined(_M_ARM) || defined(_M_ARM64)
|
||||
#if defined(WITH_SIMD) && (defined(__arm__) || defined(__aarch64__) || \
|
||||
defined(_M_ARM) || defined(_M_ARM64))
|
||||
if (jsimd_can_h1v2_fancy_upsample())
|
||||
upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
|
||||
else
|
||||
@ -489,21 +499,25 @@ jinit_upsampler(j_decompress_ptr cinfo)
|
||||
v_in_group * 2 == v_out_group) {
|
||||
/* Special cases for 2h2v upsampling */
|
||||
if (do_fancy && compptr->downsampled_width > 2) {
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_h2v2_fancy_upsample())
|
||||
upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
|
||||
else
|
||||
#endif
|
||||
upsample->methods[ci] = h2v2_fancy_upsample;
|
||||
upsample->pub.need_context_rows = TRUE;
|
||||
} else {
|
||||
#ifdef WITH_SIMD
|
||||
if (jsimd_can_h2v2_upsample())
|
||||
upsample->methods[ci] = jsimd_h2v2_upsample;
|
||||
else
|
||||
#endif
|
||||
upsample->methods[ci] = h2v2_upsample;
|
||||
}
|
||||
} else if ((h_out_group % h_in_group) == 0 &&
|
||||
(v_out_group % v_in_group) == 0) {
|
||||
/* Generic integral-factors upsampling method */
|
||||
#if defined(__mips__)
|
||||
#if defined(WITH_SIMD) && defined(__mips__)
|
||||
if (jsimd_can_int_upsample())
|
||||
upsample->methods[ci] = jsimd_int_upsample;
|
||||
else
|
||||
@ -514,7 +528,7 @@ jinit_upsampler(j_decompress_ptr cinfo)
|
||||
} else
|
||||
ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
|
||||
if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
|
||||
upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
|
||||
upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION)jround_up((long)cinfo->output_width,
|
||||
(long)cinfo->max_h_samp_factor),
|
||||
@ -522,3 +536,5 @@ jinit_upsampler(j_decompress_ptr cinfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */
|
||||
|
9
3rdparty/libjpeg-turbo/src/jdsample.h
vendored
9
3rdparty/libjpeg-turbo/src/jdsample.h
vendored
@ -3,19 +3,22 @@
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jpeglib.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
|
||||
/* Pointer to routine to upsample a single component */
|
||||
typedef void (*upsample1_ptr) (j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data,
|
||||
JSAMPARRAY *output_data_ptr);
|
||||
_JSAMPARRAY input_data,
|
||||
_JSAMPARRAY *output_data_ptr);
|
||||
|
||||
/* Private subobject */
|
||||
|
||||
@ -29,7 +32,7 @@ typedef struct {
|
||||
* ie do not need rescaling. The corresponding entry of color_buf[] is
|
||||
* simply set to point to the input data array, thereby avoiding copying.
|
||||
*/
|
||||
JSAMPARRAY color_buf[MAX_COMPONENTS];
|
||||
_JSAMPARRAY color_buf[MAX_COMPONENTS];
|
||||
|
||||
/* Per-component upsampling method pointers */
|
||||
upsample1_ptr methods[MAX_COMPONENTS];
|
||||
|
12
3rdparty/libjpeg-turbo/src/jdtrans.c
vendored
12
3rdparty/libjpeg-turbo/src/jdtrans.c
vendored
@ -4,7 +4,7 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1995-1997, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -16,7 +16,7 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jpegcomp.h"
|
||||
#include "jpegapicomp.h"
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
@ -48,6 +48,9 @@ LOCAL(void) transdecode_master_selection(j_decompress_ptr cinfo);
|
||||
GLOBAL(jvirt_barray_ptr *)
|
||||
jpeg_read_coefficients(j_decompress_ptr cinfo)
|
||||
{
|
||||
if (cinfo->master->lossless)
|
||||
ERREXIT(cinfo, JERR_NOTIMPL);
|
||||
|
||||
if (cinfo->global_state == DSTATE_READY) {
|
||||
/* First call: initialize active modules */
|
||||
transdecode_master_selection(cinfo);
|
||||
@ -127,7 +130,10 @@ transdecode_master_selection(j_decompress_ptr cinfo)
|
||||
}
|
||||
|
||||
/* Always get a full-image coefficient buffer. */
|
||||
jinit_d_coef_controller(cinfo, TRUE);
|
||||
if (cinfo->data_precision == 12)
|
||||
j12init_d_coef_controller(cinfo, TRUE);
|
||||
else
|
||||
jinit_d_coef_controller(cinfo, TRUE);
|
||||
|
||||
/* We can now tell the memory manager to allocate virtual arrays. */
|
||||
(*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo);
|
||||
|
18
3rdparty/libjpeg-turbo/src/jerror.c
vendored
18
3rdparty/libjpeg-turbo/src/jerror.c
vendored
@ -4,7 +4,7 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* Copyright (C) 2022, 2024, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
#define JMESSAGE(code, string) string,
|
||||
|
||||
const char * const jpeg_std_message_table[] = {
|
||||
static const char * const jpeg_std_message_table[] = {
|
||||
#include "jerror.h"
|
||||
NULL
|
||||
};
|
||||
@ -189,9 +189,9 @@ format_message(j_common_ptr cinfo, char *buffer)
|
||||
|
||||
/* Format the message into the passed buffer */
|
||||
if (isstring)
|
||||
snprintf(buffer, JMSG_LENGTH_MAX, msgtext, err->msg_parm.s);
|
||||
SNPRINTF(buffer, JMSG_LENGTH_MAX, msgtext, err->msg_parm.s);
|
||||
else
|
||||
snprintf(buffer, JMSG_LENGTH_MAX, msgtext,
|
||||
SNPRINTF(buffer, JMSG_LENGTH_MAX, msgtext,
|
||||
err->msg_parm.i[0], err->msg_parm.i[1],
|
||||
err->msg_parm.i[2], err->msg_parm.i[3],
|
||||
err->msg_parm.i[4], err->msg_parm.i[5],
|
||||
@ -229,23 +229,17 @@ reset_error_mgr(j_common_ptr cinfo)
|
||||
GLOBAL(struct jpeg_error_mgr *)
|
||||
jpeg_std_error(struct jpeg_error_mgr *err)
|
||||
{
|
||||
memset(err, 0, sizeof(struct jpeg_error_mgr));
|
||||
|
||||
err->error_exit = error_exit;
|
||||
err->emit_message = emit_message;
|
||||
err->output_message = output_message;
|
||||
err->format_message = format_message;
|
||||
err->reset_error_mgr = reset_error_mgr;
|
||||
|
||||
err->trace_level = 0; /* default = no tracing */
|
||||
err->num_warnings = 0; /* no warnings emitted yet */
|
||||
err->msg_code = 0; /* may be useful as a flag for "no error" */
|
||||
|
||||
/* Initialize message table pointers */
|
||||
err->jpeg_message_table = jpeg_std_message_table;
|
||||
err->last_jpeg_message = (int)JMSG_LASTMSGCODE - 1;
|
||||
|
||||
err->addon_message_table = NULL;
|
||||
err->first_addon_message = 0; /* for safety */
|
||||
err->last_addon_message = 0;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
17
3rdparty/libjpeg-turbo/src/jerror.h
vendored
17
3rdparty/libjpeg-turbo/src/jerror.h
vendored
@ -4,8 +4,10 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||
* Modified 1997-2009 by Guido Vollbeding.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2014, 2017, 2021-2022, D. R. Commander.
|
||||
* Copyright (C) 2014, 2017, 2021-2023, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -53,7 +55,8 @@ JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
|
||||
#if JPEG_LIB_VERSION >= 70
|
||||
JMESSAGE(JERR_BAD_CROP_SPEC, "Invalid crop request")
|
||||
#endif
|
||||
JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
|
||||
JMESSAGE(JERR_BAD_DCT_COEF,
|
||||
"DCT coefficient (lossy) or spatial difference (lossless) out of range")
|
||||
JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
|
||||
#if JPEG_LIB_VERSION >= 70
|
||||
JMESSAGE(JERR_BAD_DROP_SAMPLING,
|
||||
@ -69,9 +72,9 @@ JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
|
||||
JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
|
||||
JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
|
||||
JMESSAGE(JERR_BAD_PROGRESSION,
|
||||
"Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
|
||||
"Invalid progressive/lossless parameters Ss=%d Se=%d Ah=%d Al=%d")
|
||||
JMESSAGE(JERR_BAD_PROG_SCRIPT,
|
||||
"Invalid progressive parameters at scan script entry %d")
|
||||
"Invalid progressive/lossless parameters at scan script entry %d")
|
||||
JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
|
||||
JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
|
||||
JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
|
||||
@ -108,7 +111,7 @@ 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")
|
||||
#endif
|
||||
JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
|
||||
JMESSAGE(JERR_NO_BACKING_STORE, "Memory limit exceeded")
|
||||
JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
|
||||
JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
|
||||
JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
|
||||
@ -180,7 +183,7 @@ JMESSAGE(JTRC_THUMB_PALETTE,
|
||||
JMESSAGE(JTRC_THUMB_RGB,
|
||||
"JFIF extension marker: RGB thumbnail image, length %u")
|
||||
JMESSAGE(JTRC_UNKNOWN_IDS,
|
||||
"Unrecognized component IDs %d %d %d, assuming YCbCr")
|
||||
"Unrecognized component IDs %d %d %d, assuming YCbCr (lossy) or RGB (lossless)")
|
||||
JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
|
||||
JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
|
||||
JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
|
||||
@ -211,6 +214,8 @@ JMESSAGE(JWRN_BOGUS_ICC, "Corrupt JPEG data: bad ICC marker")
|
||||
JMESSAGE(JERR_BAD_DROP_SAMPLING,
|
||||
"Component index %d: mismatching sampling ratio %d:%d, %d:%d, %c")
|
||||
#endif
|
||||
JMESSAGE(JERR_BAD_RESTART,
|
||||
"Invalid restart interval %d; must be an integer multiple of the number of MCUs in an MCU row (%d)")
|
||||
|
||||
#ifdef JMAKE_ENUM_LIST
|
||||
|
||||
|
2
3rdparty/libjpeg-turbo/src/jfdctfst.c
vendored
2
3rdparty/libjpeg-turbo/src/jfdctfst.c
vendored
@ -114,7 +114,7 @@
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_fdct_ifast(DCTELEM *data)
|
||||
_jpeg_fdct_ifast(DCTELEM *data)
|
||||
{
|
||||
DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
DCTELEM tmp10, tmp11, tmp12, tmp13;
|
||||
|
4
3rdparty/libjpeg-turbo/src/jfdctint.c
vendored
4
3rdparty/libjpeg-turbo/src/jfdctint.c
vendored
@ -4,7 +4,7 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -140,7 +140,7 @@
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_fdct_islow(DCTELEM *data)
|
||||
_jpeg_fdct_islow(DCTELEM *data)
|
||||
{
|
||||
JLONG tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
JLONG tmp10, tmp11, tmp12, tmp13;
|
||||
|
14
3rdparty/libjpeg-turbo/src/jidctflt.c
vendored
14
3rdparty/libjpeg-turbo/src/jidctflt.c
vendored
@ -5,7 +5,7 @@
|
||||
* Copyright (C) 1994-1998, Thomas G. Lane.
|
||||
* Modified 2010 by Guido Vollbeding.
|
||||
* 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.
|
||||
*
|
||||
@ -69,9 +69,9 @@
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
|
||||
@ -79,8 +79,8 @@ jpeg_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR inptr;
|
||||
FLOAT_MULT_TYPE *quantptr;
|
||||
FAST_FLOAT *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
|
||||
int ctr;
|
||||
FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
|
||||
#define _0_125 ((FLOAT_MULT_TYPE)0.125)
|
||||
@ -192,7 +192,7 @@ jpeg_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
/* Even part */
|
||||
|
||||
/* Apply signed->unsigned and prepare float->int conversion */
|
||||
z5 = wsptr[0] + ((FAST_FLOAT)CENTERJSAMPLE + (FAST_FLOAT)0.5);
|
||||
z5 = wsptr[0] + ((FAST_FLOAT)_CENTERJSAMPLE + (FAST_FLOAT)0.5);
|
||||
tmp10 = z5 + wsptr[4];
|
||||
tmp11 = z5 - wsptr[4];
|
||||
|
||||
|
18
3rdparty/libjpeg-turbo/src/jidctfst.c
vendored
18
3rdparty/libjpeg-turbo/src/jidctfst.c
vendored
@ -4,7 +4,7 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1998, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2015, D. R. Commander.
|
||||
* Copyright (C) 2015, 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -64,10 +64,10 @@
|
||||
* The dequantized coefficients are not integers because the AA&N scaling
|
||||
* factors have been incorporated. We represent them scaled up by PASS1_BITS,
|
||||
* so that the first and second IDCT rounds have the same input scaling.
|
||||
* For 8-bit JSAMPLEs, we choose IFAST_SCALE_BITS = PASS1_BITS so as to
|
||||
* For 8-bit samples, we choose IFAST_SCALE_BITS = PASS1_BITS so as to
|
||||
* avoid a descaling shift; this compromises accuracy rather drastically
|
||||
* for small quantization table entries, but it saves a lot of shifts.
|
||||
* For 12-bit JSAMPLEs, there's no hope of using 16x16 multiplies anyway,
|
||||
* For 12-bit samples, there's no hope of using 16x16 multiplies anyway,
|
||||
* so we use a much larger scaling factor to preserve accuracy.
|
||||
*
|
||||
* A final compromise is to represent the multiplicative constants to only
|
||||
@ -168,9 +168,9 @@
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
DCTELEM tmp10, tmp11, tmp12, tmp13;
|
||||
@ -178,8 +178,8 @@ jpeg_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR inptr;
|
||||
IFAST_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[DCTSIZE2]; /* buffers data between passes */
|
||||
SHIFT_TEMPS /* for DESCALE */
|
||||
@ -296,7 +296,7 @@ jpeg_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
|
||||
wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
|
||||
/* AC terms all zero */
|
||||
JSAMPLE dcval =
|
||||
_JSAMPLE dcval =
|
||||
range_limit[IDESCALE(wsptr[0], PASS1_BITS + 3) & RANGE_MASK];
|
||||
|
||||
outptr[0] = dcval;
|
||||
|
136
3rdparty/libjpeg-turbo/src/jidctint.c
vendored
136
3rdparty/libjpeg-turbo/src/jidctint.c
vendored
@ -5,7 +5,7 @@
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* Modification developed 2002-2018 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.
|
||||
*
|
||||
@ -170,9 +170,9 @@
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
JLONG tmp0, tmp1, tmp2, tmp3;
|
||||
JLONG tmp10, tmp11, tmp12, tmp13;
|
||||
@ -180,8 +180,8 @@ jpeg_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[DCTSIZE2]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
@ -314,8 +314,8 @@ jpeg_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
|
||||
wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
|
||||
/* AC terms all zero */
|
||||
JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
|
||||
PASS1_BITS + 3) & RANGE_MASK];
|
||||
_JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
|
||||
PASS1_BITS + 3) & RANGE_MASK];
|
||||
|
||||
outptr[0] = dcval;
|
||||
outptr[1] = dcval;
|
||||
@ -424,17 +424,17 @@ jpeg_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_7x7(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_7x7(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
JLONG tmp0, tmp1, tmp2, tmp10, tmp11, tmp12, tmp13;
|
||||
JLONG z1, z2, z3;
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[7 * 7]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
@ -573,17 +573,17 @@ jpeg_idct_7x7(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_6x6(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_6x6(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
JLONG tmp0, tmp1, tmp2, tmp10, tmp11, tmp12;
|
||||
JLONG z1, z2, z3;
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[6 * 6]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
@ -694,17 +694,17 @@ jpeg_idct_6x6(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_5x5(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_5x5(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
JLONG tmp0, tmp1, tmp10, tmp11, tmp12;
|
||||
JLONG z1, z2, z3;
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[5 * 5]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
@ -809,16 +809,16 @@ jpeg_idct_5x5(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_3x3(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_3x3(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
JLONG tmp0, tmp2, tmp10, tmp12;
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[3 * 3]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
@ -899,17 +899,17 @@ jpeg_idct_3x3(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_9x9(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_9x9(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
JLONG tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13, tmp14;
|
||||
JLONG z1, z2, z3, z4;
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[8 * 9]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
@ -1070,9 +1070,9 @@ jpeg_idct_9x9(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_10x10(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_10x10(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
JLONG tmp10, tmp11, tmp12, tmp13, tmp14;
|
||||
JLONG tmp20, tmp21, tmp22, tmp23, tmp24;
|
||||
@ -1080,8 +1080,8 @@ jpeg_idct_10x10(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[8 * 10]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
@ -1265,9 +1265,9 @@ jpeg_idct_10x10(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_11x11(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_11x11(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
JLONG tmp10, tmp11, tmp12, tmp13, tmp14;
|
||||
JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25;
|
||||
@ -1275,8 +1275,8 @@ jpeg_idct_11x11(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[8 * 11]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
@ -1459,9 +1459,9 @@ jpeg_idct_11x11(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_12x12(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_12x12(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
JLONG tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
|
||||
JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25;
|
||||
@ -1469,8 +1469,8 @@ jpeg_idct_12x12(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[8 * 12]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
@ -1675,9 +1675,9 @@ jpeg_idct_12x12(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_13x13(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_13x13(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
JLONG tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
|
||||
JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26;
|
||||
@ -1685,8 +1685,8 @@ jpeg_idct_13x13(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[8 * 13]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
@ -1903,9 +1903,9 @@ jpeg_idct_13x13(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_14x14(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_14x14(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
JLONG tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
|
||||
JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26;
|
||||
@ -1913,8 +1913,8 @@ jpeg_idct_14x14(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[8 * 14]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
@ -2129,9 +2129,9 @@ jpeg_idct_14x14(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_15x15(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_15x15(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
JLONG tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
|
||||
JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27;
|
||||
@ -2139,8 +2139,8 @@ jpeg_idct_15x15(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[8 * 15]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
@ -2371,9 +2371,9 @@ jpeg_idct_15x15(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_16x16(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_16x16(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
JLONG tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13;
|
||||
JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27;
|
||||
@ -2381,8 +2381,8 @@ jpeg_idct_16x16(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[8 * 16]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
|
38
3rdparty/libjpeg-turbo/src/jidctred.c
vendored
38
3rdparty/libjpeg-turbo/src/jidctred.c
vendored
@ -4,7 +4,7 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1998, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2015, D. R. Commander.
|
||||
* Copyright (C) 2015, 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -118,17 +118,17 @@
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
JLONG tmp0, tmp2, tmp10, tmp12;
|
||||
JLONG z1, z2, z3, z4;
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[DCTSIZE * 4]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
@ -210,8 +210,8 @@ jpeg_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
|
||||
wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
|
||||
/* AC terms all zero */
|
||||
JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
|
||||
PASS1_BITS + 3) & RANGE_MASK];
|
||||
_JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
|
||||
PASS1_BITS + 3) & RANGE_MASK];
|
||||
|
||||
outptr[0] = dcval;
|
||||
outptr[1] = dcval;
|
||||
@ -276,16 +276,16 @@ jpeg_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
JLONG tmp0, tmp10, z1;
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
int *wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPROW outptr;
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[DCTSIZE * 2]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
@ -345,8 +345,8 @@ jpeg_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
#ifndef NO_ZERO_ROW_TEST
|
||||
if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
|
||||
/* AC terms all zero */
|
||||
JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
|
||||
PASS1_BITS + 3) & RANGE_MASK];
|
||||
_JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
|
||||
PASS1_BITS + 3) & RANGE_MASK];
|
||||
|
||||
outptr[0] = dcval;
|
||||
outptr[1] = dcval;
|
||||
@ -387,13 +387,13 @@ jpeg_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_1x1(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
_jpeg_idct_1x1(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
int dcval;
|
||||
ISLOW_MULT_TYPE *quantptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
SHIFT_TEMPS
|
||||
|
||||
/* We hardly need an inverse DCT routine for this: just take the
|
||||
|
16
3rdparty/libjpeg-turbo/src/jinclude.h
vendored
16
3rdparty/libjpeg-turbo/src/jinclude.h
vendored
@ -4,7 +4,7 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1994, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* Copyright (C) 2022-2023, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -45,6 +45,18 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#define SNPRINTF(str, n, format, ...) \
|
||||
_snprintf_s(str, n, _TRUNCATE, format, ##__VA_ARGS__)
|
||||
|
||||
#else
|
||||
|
||||
#define SNPRINTF snprintf
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef NO_GETENV
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@ -111,6 +123,8 @@ static INLINE int GETENV_S(char *buffer, size_t buffer_size, const char *name)
|
||||
|
||||
#else
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/* This provides a similar interface to the Microsoft _putenv_s() function, but
|
||||
* other than parameter validation, it has no advantages over setenv().
|
||||
*/
|
||||
|
101
3rdparty/libjpeg-turbo/src/jlossls.h
vendored
Normal file
101
3rdparty/libjpeg-turbo/src/jlossls.h
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* jlossls.h
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1998, Thomas G. Lane.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This include file contains common declarations for the lossless JPEG
|
||||
* codec modules.
|
||||
*/
|
||||
|
||||
#ifndef JLOSSLS_H
|
||||
#define JLOSSLS_H
|
||||
|
||||
#if defined(C_LOSSLESS_SUPPORTED) || defined(D_LOSSLESS_SUPPORTED)
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jpeglib.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
|
||||
#define ALLOC_DARRAY(pool_id, diffsperrow, numrows) \
|
||||
(JDIFFARRAY)(*cinfo->mem->alloc_sarray) \
|
||||
((j_common_ptr)cinfo, pool_id, \
|
||||
(diffsperrow) * sizeof(JDIFF) / sizeof(_JSAMPLE), numrows)
|
||||
|
||||
|
||||
/*
|
||||
* Table H.1: Predictors for lossless coding.
|
||||
*/
|
||||
|
||||
#define PREDICTOR1 Ra
|
||||
#define PREDICTOR2 Rb
|
||||
#define PREDICTOR3 Rc
|
||||
#define PREDICTOR4 (int)((JLONG)Ra + (JLONG)Rb - (JLONG)Rc)
|
||||
#define PREDICTOR5 (int)((JLONG)Ra + RIGHT_SHIFT((JLONG)Rb - (JLONG)Rc, 1))
|
||||
#define PREDICTOR6 (int)((JLONG)Rb + RIGHT_SHIFT((JLONG)Ra - (JLONG)Rc, 1))
|
||||
#define PREDICTOR7 (int)RIGHT_SHIFT((JLONG)Ra + (JLONG)Rb, 1)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
|
||||
typedef void (*predict_difference_method_ptr) (j_compress_ptr cinfo, int ci,
|
||||
_JSAMPROW input_buf,
|
||||
_JSAMPROW prev_row,
|
||||
JDIFFROW diff_buf,
|
||||
JDIMENSION width);
|
||||
|
||||
/* Lossless compressor */
|
||||
typedef struct {
|
||||
struct jpeg_forward_dct pub; /* public fields */
|
||||
|
||||
/* It is useful to allow each component to have a separate diff method. */
|
||||
predict_difference_method_ptr predict_difference[MAX_COMPONENTS];
|
||||
|
||||
/* MCU rows left in the restart interval for each component */
|
||||
unsigned int restart_rows_to_go[MAX_COMPONENTS];
|
||||
|
||||
/* Sample scaling */
|
||||
void (*scaler_scale) (j_compress_ptr cinfo, _JSAMPROW input_buf,
|
||||
_JSAMPROW output_buf, JDIMENSION width);
|
||||
} jpeg_lossless_compressor;
|
||||
|
||||
typedef jpeg_lossless_compressor *lossless_comp_ptr;
|
||||
|
||||
#endif /* C_LOSSLESS_SUPPORTED */
|
||||
|
||||
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
|
||||
typedef void (*predict_undifference_method_ptr) (j_decompress_ptr cinfo,
|
||||
int comp_index,
|
||||
JDIFFROW diff_buf,
|
||||
JDIFFROW prev_row,
|
||||
JDIFFROW undiff_buf,
|
||||
JDIMENSION width);
|
||||
|
||||
/* Lossless decompressor */
|
||||
typedef struct {
|
||||
struct jpeg_inverse_dct pub; /* public fields */
|
||||
|
||||
/* It is useful to allow each component to have a separate undiff method. */
|
||||
predict_undifference_method_ptr predict_undifference[MAX_COMPONENTS];
|
||||
|
||||
/* Sample scaling */
|
||||
void (*scaler_scale) (j_decompress_ptr cinfo, JDIFFROW diff_buf,
|
||||
_JSAMPROW output_buf, JDIMENSION width);
|
||||
} jpeg_lossless_decompressor;
|
||||
|
||||
typedef jpeg_lossless_decompressor *lossless_decomp_ptr;
|
||||
|
||||
#endif /* D_LOSSLESS_SUPPORTED */
|
||||
|
||||
#endif /* JLOSSLS_H */
|
192
3rdparty/libjpeg-turbo/src/jmemmgr.c
vendored
192
3rdparty/libjpeg-turbo/src/jmemmgr.c
vendored
@ -68,10 +68,13 @@ round_up_pow2(size_t a, size_t b)
|
||||
* There isn't any really portable way to determine the worst-case alignment
|
||||
* requirement. This module assumes that the alignment requirement is
|
||||
* multiples of ALIGN_SIZE.
|
||||
* By default, we define ALIGN_SIZE as sizeof(double). This is necessary on
|
||||
* some workstations (where doubles really do need 8-byte alignment) and will
|
||||
* work fine on nearly everything. If your machine has lesser alignment needs,
|
||||
* you can save a few bytes by making ALIGN_SIZE smaller.
|
||||
* By default, we define ALIGN_SIZE as the maximum of sizeof(double) and
|
||||
* sizeof(void *). This is necessary on some workstations (where doubles
|
||||
* really do need 8-byte alignment) and will work fine on nearly everything.
|
||||
* We use the maximum of sizeof(double) and sizeof(void *) since sizeof(double)
|
||||
* may be insufficient, for example, on CHERI-enabled platforms with 16-byte
|
||||
* pointers and a 16-byte alignment requirement. If your machine has lesser
|
||||
* alignment needs, you can save a few bytes by making ALIGN_SIZE smaller.
|
||||
* The only place I know of where this will NOT work is certain Macintosh
|
||||
* 680x0 compilers that define double as a 10-byte IEEE extended float.
|
||||
* Doing 10-byte alignment is counterproductive because longwords won't be
|
||||
@ -81,7 +84,7 @@ round_up_pow2(size_t a, size_t b)
|
||||
|
||||
#ifndef ALIGN_SIZE /* so can override from jconfig.h */
|
||||
#ifndef WITH_SIMD
|
||||
#define ALIGN_SIZE sizeof(double)
|
||||
#define ALIGN_SIZE MAX(sizeof(void *), sizeof(double))
|
||||
#else
|
||||
#define ALIGN_SIZE 32 /* Most of the SIMD instructions we support require
|
||||
16-byte (128-bit) alignment, but AVX2 requires
|
||||
@ -152,7 +155,9 @@ typedef my_memory_mgr *my_mem_ptr;
|
||||
*/
|
||||
|
||||
struct jvirt_sarray_control {
|
||||
JSAMPARRAY mem_buffer; /* => the in-memory buffer */
|
||||
JSAMPARRAY mem_buffer; /* => the in-memory buffer (if
|
||||
cinfo->data_precision is 12, then this is
|
||||
actually a J12SAMPARRAY) */
|
||||
JDIMENSION rows_in_array; /* total virtual array height */
|
||||
JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
|
||||
JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
|
||||
@ -348,9 +353,10 @@ alloc_small(j_common_ptr cinfo, int pool_id, size_t sizeofobject)
|
||||
* request is large enough that it may as well be passed directly to
|
||||
* jpeg_get_large; the pool management just links everything together
|
||||
* so that we can free it all on demand.
|
||||
* Note: the major use of "large" objects is in JSAMPARRAY and JBLOCKARRAY
|
||||
* structures. The routines that create these structures (see below)
|
||||
* deliberately bunch rows together to ensure a large request size.
|
||||
* Note: the major use of "large" objects is in
|
||||
* JSAMPARRAY/J12SAMPARRAY/J16SAMPARRAY and JBLOCKARRAY structures. The
|
||||
* routines that create these structures (see below) deliberately bunch rows
|
||||
* together to ensure a large request size.
|
||||
*/
|
||||
|
||||
METHODDEF(void *)
|
||||
@ -434,9 +440,22 @@ alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow,
|
||||
JSAMPROW workspace;
|
||||
JDIMENSION rowsperchunk, currow, i;
|
||||
long ltemp;
|
||||
J12SAMPARRAY result12;
|
||||
J12SAMPROW workspace12;
|
||||
#if defined(C_LOSSLESS_SUPPORTED) || defined(D_LOSSLESS_SUPPORTED)
|
||||
J16SAMPARRAY result16;
|
||||
J16SAMPROW workspace16;
|
||||
#endif
|
||||
int data_precision = cinfo->is_decompressor ?
|
||||
((j_decompress_ptr)cinfo)->data_precision :
|
||||
((j_compress_ptr)cinfo)->data_precision;
|
||||
size_t sample_size = data_precision == 16 ?
|
||||
sizeof(J16SAMPLE) : (data_precision == 12 ?
|
||||
sizeof(J12SAMPLE) :
|
||||
sizeof(JSAMPLE));
|
||||
|
||||
/* Make sure each row is properly aligned */
|
||||
if ((ALIGN_SIZE % sizeof(JSAMPLE)) != 0)
|
||||
if ((ALIGN_SIZE % sample_size) != 0)
|
||||
out_of_memory(cinfo, 5); /* safety check */
|
||||
|
||||
if (samplesperrow > MAX_ALLOC_CHUNK) {
|
||||
@ -445,11 +464,11 @@ alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow,
|
||||
out_of_memory(cinfo, 9);
|
||||
}
|
||||
samplesperrow = (JDIMENSION)round_up_pow2(samplesperrow, (2 * ALIGN_SIZE) /
|
||||
sizeof(JSAMPLE));
|
||||
sample_size);
|
||||
|
||||
/* Calculate max # of rows allowed in one allocation chunk */
|
||||
ltemp = (MAX_ALLOC_CHUNK - sizeof(large_pool_hdr)) /
|
||||
((long)samplesperrow * sizeof(JSAMPLE));
|
||||
((long)samplesperrow * (long)sample_size);
|
||||
if (ltemp <= 0)
|
||||
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
||||
if (ltemp < (long)numrows)
|
||||
@ -458,24 +477,68 @@ alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow,
|
||||
rowsperchunk = numrows;
|
||||
mem->last_rowsperchunk = rowsperchunk;
|
||||
|
||||
/* Get space for row pointers (small object) */
|
||||
result = (JSAMPARRAY)alloc_small(cinfo, pool_id,
|
||||
(size_t)(numrows * sizeof(JSAMPROW)));
|
||||
if (data_precision == 16) {
|
||||
#if defined(C_LOSSLESS_SUPPORTED) || defined(D_LOSSLESS_SUPPORTED)
|
||||
/* Get space for row pointers (small object) */
|
||||
result16 = (J16SAMPARRAY)alloc_small(cinfo, pool_id,
|
||||
(size_t)(numrows *
|
||||
sizeof(J16SAMPROW)));
|
||||
|
||||
/* Get the rows themselves (large objects) */
|
||||
currow = 0;
|
||||
while (currow < numrows) {
|
||||
rowsperchunk = MIN(rowsperchunk, numrows - currow);
|
||||
workspace = (JSAMPROW)alloc_large(cinfo, pool_id,
|
||||
(size_t)((size_t)rowsperchunk * (size_t)samplesperrow *
|
||||
sizeof(JSAMPLE)));
|
||||
for (i = rowsperchunk; i > 0; i--) {
|
||||
result[currow++] = workspace;
|
||||
workspace += samplesperrow;
|
||||
/* Get the rows themselves (large objects) */
|
||||
currow = 0;
|
||||
while (currow < numrows) {
|
||||
rowsperchunk = MIN(rowsperchunk, numrows - currow);
|
||||
workspace16 = (J16SAMPROW)alloc_large(cinfo, pool_id,
|
||||
(size_t)((size_t)rowsperchunk * (size_t)samplesperrow * sample_size));
|
||||
for (i = rowsperchunk; i > 0; i--) {
|
||||
result16[currow++] = workspace16;
|
||||
workspace16 += samplesperrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return (JSAMPARRAY)result16;
|
||||
#else
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, data_precision);
|
||||
return NULL;
|
||||
#endif
|
||||
} else if (data_precision == 12) {
|
||||
/* Get space for row pointers (small object) */
|
||||
result12 = (J12SAMPARRAY)alloc_small(cinfo, pool_id,
|
||||
(size_t)(numrows *
|
||||
sizeof(J12SAMPROW)));
|
||||
|
||||
/* Get the rows themselves (large objects) */
|
||||
currow = 0;
|
||||
while (currow < numrows) {
|
||||
rowsperchunk = MIN(rowsperchunk, numrows - currow);
|
||||
workspace12 = (J12SAMPROW)alloc_large(cinfo, pool_id,
|
||||
(size_t)((size_t)rowsperchunk * (size_t)samplesperrow * sample_size));
|
||||
for (i = rowsperchunk; i > 0; i--) {
|
||||
result12[currow++] = workspace12;
|
||||
workspace12 += samplesperrow;
|
||||
}
|
||||
}
|
||||
|
||||
return (JSAMPARRAY)result12;
|
||||
} else {
|
||||
/* Get space for row pointers (small object) */
|
||||
result = (JSAMPARRAY)alloc_small(cinfo, pool_id,
|
||||
(size_t)(numrows * sizeof(JSAMPROW)));
|
||||
|
||||
/* Get the rows themselves (large objects) */
|
||||
currow = 0;
|
||||
while (currow < numrows) {
|
||||
rowsperchunk = MIN(rowsperchunk, numrows - currow);
|
||||
workspace = (JSAMPROW)alloc_large(cinfo, pool_id,
|
||||
(size_t)((size_t)rowsperchunk * (size_t)samplesperrow * sample_size));
|
||||
for (i = rowsperchunk; i > 0; i--) {
|
||||
result[currow++] = workspace;
|
||||
workspace += samplesperrow;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -637,6 +700,13 @@ realize_virt_arrays(j_common_ptr cinfo)
|
||||
size_t minheights, max_minheights;
|
||||
jvirt_sarray_ptr sptr;
|
||||
jvirt_barray_ptr bptr;
|
||||
int data_precision = cinfo->is_decompressor ?
|
||||
((j_decompress_ptr)cinfo)->data_precision :
|
||||
((j_compress_ptr)cinfo)->data_precision;
|
||||
size_t sample_size = data_precision == 16 ?
|
||||
sizeof(J16SAMPLE) : (data_precision == 12 ?
|
||||
sizeof(J12SAMPLE) :
|
||||
sizeof(JSAMPLE));
|
||||
|
||||
/* Compute the minimum space needed (maxaccess rows in each buffer)
|
||||
* and the maximum space needed (full image height in each buffer).
|
||||
@ -647,10 +717,10 @@ realize_virt_arrays(j_common_ptr cinfo)
|
||||
for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
|
||||
if (sptr->mem_buffer == NULL) { /* if not realized yet */
|
||||
size_t new_space = (long)sptr->rows_in_array *
|
||||
(long)sptr->samplesperrow * sizeof(JSAMPLE);
|
||||
(long)sptr->samplesperrow * sample_size;
|
||||
|
||||
space_per_minheight += (long)sptr->maxaccess *
|
||||
(long)sptr->samplesperrow * sizeof(JSAMPLE);
|
||||
(long)sptr->samplesperrow * sample_size;
|
||||
if (SIZE_MAX - maximum_space < new_space)
|
||||
out_of_memory(cinfo, 10);
|
||||
maximum_space += new_space;
|
||||
@ -705,7 +775,7 @@ realize_virt_arrays(j_common_ptr cinfo)
|
||||
jpeg_open_backing_store(cinfo, &sptr->b_s_info,
|
||||
(long)sptr->rows_in_array *
|
||||
(long)sptr->samplesperrow *
|
||||
(long)sizeof(JSAMPLE));
|
||||
(long)sample_size);
|
||||
sptr->b_s_open = TRUE;
|
||||
}
|
||||
sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
|
||||
@ -748,8 +818,15 @@ do_sarray_io(j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
|
||||
/* Do backing store read or write of a virtual sample array */
|
||||
{
|
||||
long bytesperrow, file_offset, byte_count, rows, thisrow, i;
|
||||
int data_precision = cinfo->is_decompressor ?
|
||||
((j_decompress_ptr)cinfo)->data_precision :
|
||||
((j_compress_ptr)cinfo)->data_precision;
|
||||
size_t sample_size = data_precision == 16 ?
|
||||
sizeof(J16SAMPLE) : (data_precision == 12 ?
|
||||
sizeof(J12SAMPLE) :
|
||||
sizeof(JSAMPLE));
|
||||
|
||||
bytesperrow = (long)ptr->samplesperrow * sizeof(JSAMPLE);
|
||||
bytesperrow = (long)ptr->samplesperrow * (long)sample_size;
|
||||
file_offset = ptr->cur_start_row * bytesperrow;
|
||||
/* Loop to read or write each allocation chunk in mem_buffer */
|
||||
for (i = 0; i < (long)ptr->rows_in_mem; i += ptr->rowsperchunk) {
|
||||
@ -763,14 +840,42 @@ do_sarray_io(j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
|
||||
if (rows <= 0) /* this chunk might be past end of file! */
|
||||
break;
|
||||
byte_count = rows * bytesperrow;
|
||||
if (writing)
|
||||
(*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info,
|
||||
(void *)ptr->mem_buffer[i],
|
||||
file_offset, byte_count);
|
||||
else
|
||||
(*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info,
|
||||
(void *)ptr->mem_buffer[i],
|
||||
file_offset, byte_count);
|
||||
if (data_precision == 16) {
|
||||
#if defined(C_LOSSLESS_SUPPORTED) || defined(D_LOSSLESS_SUPPORTED)
|
||||
J16SAMPARRAY mem_buffer16 = (J16SAMPARRAY)ptr->mem_buffer;
|
||||
|
||||
if (writing)
|
||||
(*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info,
|
||||
(void *)mem_buffer16[i],
|
||||
file_offset, byte_count);
|
||||
else
|
||||
(*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info,
|
||||
(void *)mem_buffer16[i],
|
||||
file_offset, byte_count);
|
||||
#else
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, data_precision);
|
||||
#endif
|
||||
} else if (data_precision == 12) {
|
||||
J12SAMPARRAY mem_buffer12 = (J12SAMPARRAY)ptr->mem_buffer;
|
||||
|
||||
if (writing)
|
||||
(*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info,
|
||||
(void *)mem_buffer12[i],
|
||||
file_offset, byte_count);
|
||||
else
|
||||
(*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info,
|
||||
(void *)mem_buffer12[i],
|
||||
file_offset, byte_count);
|
||||
} else {
|
||||
if (writing)
|
||||
(*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info,
|
||||
(void *)ptr->mem_buffer[i],
|
||||
file_offset, byte_count);
|
||||
else
|
||||
(*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info,
|
||||
(void *)ptr->mem_buffer[i],
|
||||
file_offset, byte_count);
|
||||
}
|
||||
file_offset += byte_count;
|
||||
}
|
||||
}
|
||||
@ -818,6 +923,13 @@ access_virt_sarray(j_common_ptr cinfo, jvirt_sarray_ptr ptr,
|
||||
{
|
||||
JDIMENSION end_row = start_row + num_rows;
|
||||
JDIMENSION undef_row;
|
||||
int data_precision = cinfo->is_decompressor ?
|
||||
((j_decompress_ptr)cinfo)->data_precision :
|
||||
((j_compress_ptr)cinfo)->data_precision;
|
||||
size_t sample_size = data_precision == 16 ?
|
||||
sizeof(J16SAMPLE) : (data_precision == 12 ?
|
||||
sizeof(J12SAMPLE) :
|
||||
sizeof(JSAMPLE));
|
||||
|
||||
/* debugging check */
|
||||
if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
|
||||
@ -873,7 +985,7 @@ access_virt_sarray(j_common_ptr cinfo, jvirt_sarray_ptr ptr,
|
||||
if (writable)
|
||||
ptr->first_undef_row = end_row;
|
||||
if (ptr->pre_zero) {
|
||||
size_t bytesperrow = (size_t)ptr->samplesperrow * sizeof(JSAMPLE);
|
||||
size_t bytesperrow = (size_t)ptr->samplesperrow * sample_size;
|
||||
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
|
||||
end_row -= ptr->cur_start_row;
|
||||
while (undef_row < end_row) {
|
||||
|
31
3rdparty/libjpeg-turbo/src/jmemsys.h
vendored
31
3rdparty/libjpeg-turbo/src/jmemsys.h
vendored
@ -99,24 +99,6 @@ EXTERN(size_t) jpeg_mem_available(j_common_ptr cinfo, size_t min_bytes_needed,
|
||||
#define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
|
||||
|
||||
|
||||
#ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
|
||||
|
||||
typedef unsigned short XMSH; /* type of extended-memory handles */
|
||||
typedef unsigned short EMSH; /* type of expanded-memory handles */
|
||||
|
||||
typedef union {
|
||||
short file_handle; /* DOS file handle if it's a temp file */
|
||||
XMSH xms_handle; /* handle if it's a chunk of XMS */
|
||||
EMSH ems_handle; /* handle if it's a chunk of EMS */
|
||||
} handle_union;
|
||||
|
||||
#endif /* USE_MSDOS_MEMMGR */
|
||||
|
||||
#ifdef USE_MAC_MEMMGR /* Mac-specific junk */
|
||||
#include <Files.h>
|
||||
#endif /* USE_MAC_MEMMGR */
|
||||
|
||||
|
||||
typedef struct backing_store_struct *backing_store_ptr;
|
||||
|
||||
typedef struct backing_store_struct {
|
||||
@ -130,22 +112,9 @@ typedef struct backing_store_struct {
|
||||
void (*close_backing_store) (j_common_ptr cinfo, backing_store_ptr info);
|
||||
|
||||
/* Private fields for system-dependent backing-store management */
|
||||
#ifdef USE_MSDOS_MEMMGR
|
||||
/* For the MS-DOS manager (jmemdos.c), we need: */
|
||||
handle_union handle; /* reference to backing-store storage object */
|
||||
char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
|
||||
#else
|
||||
#ifdef USE_MAC_MEMMGR
|
||||
/* For the Mac manager (jmemmac.c), we need: */
|
||||
short temp_file; /* file reference number to temp file */
|
||||
FSSpec tempSpec; /* the FSSpec for the temp file */
|
||||
char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
|
||||
#else
|
||||
/* For a typical implementation with temp files, we need: */
|
||||
FILE *temp_file; /* stdio reference to temp file */
|
||||
char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
|
||||
#endif
|
||||
#endif
|
||||
} backing_store_info;
|
||||
|
||||
|
||||
|
41
3rdparty/libjpeg-turbo/src/jmorecfg.h
vendored
41
3rdparty/libjpeg-turbo/src/jmorecfg.h
vendored
@ -4,8 +4,10 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Modified 1997-2009 by Guido Vollbeding.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2009, 2011, 2014-2015, 2018, 2020, D. R. Commander.
|
||||
* Copyright (C) 2009, 2011, 2014-2015, 2018, 2020, 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -41,31 +43,29 @@
|
||||
* arrays is very slow on your hardware, you might want to change these.
|
||||
*/
|
||||
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
/* JSAMPLE should be the smallest type that will hold the values 0..255.
|
||||
*/
|
||||
/* JSAMPLE should be the smallest type that will hold the values 0..255. */
|
||||
|
||||
typedef unsigned char JSAMPLE;
|
||||
#define GETJSAMPLE(value) ((int)(value))
|
||||
|
||||
#define MAXJSAMPLE 255
|
||||
#define CENTERJSAMPLE 128
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE == 8 */
|
||||
#define MAXJSAMPLE 255
|
||||
#define CENTERJSAMPLE 128
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE == 12
|
||||
/* JSAMPLE should be the smallest type that will hold the values 0..4095.
|
||||
* On nearly all machines "short" will do nicely.
|
||||
*/
|
||||
/* J12SAMPLE should be the smallest type that will hold the values 0..4095. */
|
||||
|
||||
typedef short JSAMPLE;
|
||||
#define GETJSAMPLE(value) ((int)(value))
|
||||
typedef short J12SAMPLE;
|
||||
|
||||
#define MAXJSAMPLE 4095
|
||||
#define CENTERJSAMPLE 2048
|
||||
#define MAXJ12SAMPLE 4095
|
||||
#define CENTERJ12SAMPLE 2048
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE == 12 */
|
||||
|
||||
/* J16SAMPLE should be the smallest type that will hold the values 0..65535. */
|
||||
|
||||
typedef unsigned short J16SAMPLE;
|
||||
|
||||
#define MAXJ16SAMPLE 65535
|
||||
#define CENTERJ16SAMPLE 32768
|
||||
|
||||
|
||||
/* Representation of a DCT frequency coefficient.
|
||||
@ -242,14 +242,16 @@ typedef int boolean;
|
||||
|
||||
#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
|
||||
#define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
|
||||
#define C_LOSSLESS_SUPPORTED /* Lossless JPEG? */
|
||||
#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
|
||||
/* Note: if you selected 12-bit data precision, it is dangerous to turn off
|
||||
* ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit
|
||||
* precision, so jchuff.c normally uses entropy optimization to compute
|
||||
* usable tables for higher precision. If you don't want to do optimization,
|
||||
* you'll have to supply different default Huffman tables.
|
||||
* The exact same statements apply for progressive JPEG: the default tables
|
||||
* don't work for progressive mode. (This may get fixed, however.)
|
||||
* The exact same statements apply for progressive and lossless JPEG:
|
||||
* the default tables don't work for progressive mode or lossless mode.
|
||||
* (This may get fixed, however.)
|
||||
*/
|
||||
#define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
|
||||
|
||||
@ -257,6 +259,7 @@ typedef int boolean;
|
||||
|
||||
#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
|
||||
#define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
|
||||
#define D_LOSSLESS_SUPPORTED /* Lossless JPEG? */
|
||||
#define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
|
||||
#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
|
||||
#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
|
||||
|
@ -1,4 +1,32 @@
|
||||
static const unsigned char jpeg_nbits_table[65536] = {
|
||||
/*
|
||||
* Copyright (C) 2024, D. R. Commander.
|
||||
*
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*/
|
||||
|
||||
#include "jpeg_nbits.h"
|
||||
#include "jconfigint.h"
|
||||
|
||||
|
||||
#ifndef USE_CLZ_INTRINSIC
|
||||
|
||||
#define INCLUDE_JPEG_NBITS_TABLE
|
||||
|
||||
/* When building for x86[-64] with the SIMD extensions enabled, the C Huffman
|
||||
* encoders can reuse jpeg_nbits_table from the SSE2 baseline Huffman encoder.
|
||||
*/
|
||||
#if (defined(__x86_64__) || defined(__i386__) || defined(_M_IX86) || \
|
||||
defined(_M_X64)) && defined(WITH_SIMD)
|
||||
#undef INCLUDE_JPEG_NBITS_TABLE
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef INCLUDE_JPEG_NBITS_TABLE
|
||||
|
||||
const unsigned char HIDDEN jpeg_nbits_table[65536] = {
|
||||
0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
@ -4096,3 +4124,11 @@ static const unsigned char jpeg_nbits_table[65536] = {
|
||||
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
/* Suppress compiler warnings about empty translation unit. */
|
||||
|
||||
typedef int dummy_jpeg_nbits_table;
|
||||
|
||||
#endif
|
43
3rdparty/libjpeg-turbo/src/jpeg_nbits.h
vendored
Normal file
43
3rdparty/libjpeg-turbo/src/jpeg_nbits.h
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2014, 2021, 2024, D. R. Commander.
|
||||
* Copyright (C) 2014, Olle Liljenzin.
|
||||
* Copyright (C) 2020, Arm Limited.
|
||||
*
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* NOTE: If USE_CLZ_INTRINSIC is defined, then clz/bsr instructions will be
|
||||
* used for bit counting rather than the lookup table. This will reduce the
|
||||
* memory footprint by 64k, which is important for some mobile applications
|
||||
* that create many isolated instances of libjpeg-turbo (web browsers, for
|
||||
* instance.) This may improve performance on some mobile platforms as well.
|
||||
* This feature is enabled by default only on Arm processors, because some x86
|
||||
* chips have a slow implementation of bsr, and the use of clz/bsr cannot be
|
||||
* shown to have a significant performance impact even on the x86 chips that
|
||||
* have a fast implementation of it. When building for Armv6, you can
|
||||
* explicitly disable the use of clz/bsr by adding -mthumb to the compiler
|
||||
* flags (this defines __thumb__).
|
||||
*/
|
||||
|
||||
/* NOTE: Both GCC and Clang define __GNUC__ */
|
||||
#if (defined(__GNUC__) && (defined(__arm__) || defined(__aarch64__))) || \
|
||||
defined(_M_ARM) || defined(_M_ARM64)
|
||||
#if !defined(__thumb__) || defined(__thumb2__)
|
||||
#define USE_CLZ_INTRINSIC
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_CLZ_INTRINSIC
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#define JPEG_NBITS_NONZERO(x) (32 - _CountLeadingZeros(x))
|
||||
#else
|
||||
#define JPEG_NBITS_NONZERO(x) (32 - __builtin_clz(x))
|
||||
#endif
|
||||
#define JPEG_NBITS(x) (x ? JPEG_NBITS_NONZERO(x) : 0)
|
||||
#else
|
||||
extern const unsigned char jpeg_nbits_table[65536];
|
||||
#define JPEG_NBITS(x) (jpeg_nbits_table[x])
|
||||
#define JPEG_NBITS_NONZERO(x) JPEG_NBITS(x)
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* jpegcomp.h
|
||||
* jpegapicomp.h
|
||||
*
|
||||
* Copyright (C) 2010, 2020, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
226
3rdparty/libjpeg-turbo/src/jpegint.h
vendored
226
3rdparty/libjpeg-turbo/src/jpegint.h
vendored
@ -4,8 +4,10 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Modified 1997-2009 by Guido Vollbeding.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2015-2016, 2019, 2021, D. R. Commander.
|
||||
* Copyright (C) 2015-2017, 2019, 2021-2022, D. R. Commander.
|
||||
* Copyright (C) 2015, Google, Inc.
|
||||
* Copyright (C) 2021, Alex Richardson.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
@ -17,6 +19,17 @@
|
||||
*/
|
||||
|
||||
|
||||
/* Representation of a spatial difference value.
|
||||
* This should be a signed value of at least 16 bits; int is usually OK.
|
||||
*/
|
||||
|
||||
typedef int JDIFF;
|
||||
|
||||
typedef JDIFF FAR *JDIFFROW; /* pointer to one row of difference values */
|
||||
typedef JDIFFROW *JDIFFARRAY; /* ptr to some rows (a 2-D diff array) */
|
||||
typedef JDIFFARRAY *JDIFFIMAGE; /* a 3-D diff array: top index is color */
|
||||
|
||||
|
||||
/* Declarations for both compression & decompression */
|
||||
|
||||
typedef enum { /* Operating modes for buffer controllers */
|
||||
@ -61,6 +74,9 @@ typedef __UINTPTR_TYPE__ JUINTPTR;
|
||||
typedef size_t JUINTPTR;
|
||||
#endif
|
||||
|
||||
#define IsExtRGB(cs) \
|
||||
(cs == JCS_RGB || (cs >= JCS_EXT_RGB && cs <= JCS_EXT_ARGB))
|
||||
|
||||
/*
|
||||
* Left shift macro that handles a negative operand without causing any
|
||||
* sanitizer warnings
|
||||
@ -80,6 +96,7 @@ struct jpeg_comp_master {
|
||||
/* State variables made visible to other modules */
|
||||
boolean call_pass_startup; /* True if pass_startup must be called */
|
||||
boolean is_last_pass; /* True during last pass */
|
||||
boolean lossless; /* True if lossless mode is enabled */
|
||||
};
|
||||
|
||||
/* Main buffer control (downsampled-data buffer) */
|
||||
@ -87,6 +104,12 @@ struct jpeg_c_main_controller {
|
||||
void (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode);
|
||||
void (*process_data) (j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail);
|
||||
void (*process_data_12) (j_compress_ptr cinfo, J12SAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail);
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
void (*process_data_16) (j_compress_ptr cinfo, J16SAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Compression preprocessing (downsampling input buffer control) */
|
||||
@ -97,12 +120,32 @@ struct jpeg_c_prep_controller {
|
||||
JSAMPIMAGE output_buf,
|
||||
JDIMENSION *out_row_group_ctr,
|
||||
JDIMENSION out_row_groups_avail);
|
||||
void (*pre_process_data_12) (j_compress_ptr cinfo, J12SAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail,
|
||||
J12SAMPIMAGE output_buf,
|
||||
JDIMENSION *out_row_group_ctr,
|
||||
JDIMENSION out_row_groups_avail);
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
void (*pre_process_data_16) (j_compress_ptr cinfo, J16SAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail,
|
||||
J16SAMPIMAGE output_buf,
|
||||
JDIMENSION *out_row_group_ctr,
|
||||
JDIMENSION out_row_groups_avail);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Coefficient buffer control */
|
||||
/* Lossy mode: Coefficient buffer control
|
||||
* Lossless mode: Difference buffer control
|
||||
*/
|
||||
struct jpeg_c_coef_controller {
|
||||
void (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode);
|
||||
boolean (*compress_data) (j_compress_ptr cinfo, JSAMPIMAGE input_buf);
|
||||
boolean (*compress_data_12) (j_compress_ptr cinfo, J12SAMPIMAGE input_buf);
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
boolean (*compress_data_16) (j_compress_ptr cinfo, J16SAMPIMAGE input_buf);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Colorspace conversion */
|
||||
@ -111,6 +154,14 @@ struct jpeg_color_converter {
|
||||
void (*color_convert) (j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPIMAGE output_buf, JDIMENSION output_row,
|
||||
int num_rows);
|
||||
void (*color_convert_12) (j_compress_ptr cinfo, J12SAMPARRAY input_buf,
|
||||
J12SAMPIMAGE output_buf, JDIMENSION output_row,
|
||||
int num_rows);
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
void (*color_convert_16) (j_compress_ptr cinfo, J16SAMPARRAY input_buf,
|
||||
J16SAMPIMAGE output_buf, JDIMENSION output_row,
|
||||
int num_rows);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Downsampling */
|
||||
@ -119,24 +170,47 @@ struct jpeg_downsampler {
|
||||
void (*downsample) (j_compress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_index, JSAMPIMAGE output_buf,
|
||||
JDIMENSION out_row_group_index);
|
||||
void (*downsample_12) (j_compress_ptr cinfo, J12SAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_index, J12SAMPIMAGE output_buf,
|
||||
JDIMENSION out_row_group_index);
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
void (*downsample_16) (j_compress_ptr cinfo, J16SAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_index, J16SAMPIMAGE output_buf,
|
||||
JDIMENSION out_row_group_index);
|
||||
#endif
|
||||
|
||||
boolean need_context_rows; /* TRUE if need rows above & below */
|
||||
};
|
||||
|
||||
/* Forward DCT (also controls coefficient quantization) */
|
||||
/* Lossy mode: Forward DCT (also controls coefficient quantization)
|
||||
* Lossless mode: Prediction, sample differencing, and point transform
|
||||
*/
|
||||
struct jpeg_forward_dct {
|
||||
void (*start_pass) (j_compress_ptr cinfo);
|
||||
|
||||
/* Lossy mode */
|
||||
/* perhaps this should be an array??? */
|
||||
void (*forward_DCT) (j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||
JDIMENSION start_row, JDIMENSION start_col,
|
||||
JDIMENSION num_blocks);
|
||||
void (*forward_DCT_12) (j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
J12SAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||
JDIMENSION start_row, JDIMENSION start_col,
|
||||
JDIMENSION num_blocks);
|
||||
};
|
||||
|
||||
/* Entropy encoding */
|
||||
struct jpeg_entropy_encoder {
|
||||
void (*start_pass) (j_compress_ptr cinfo, boolean gather_statistics);
|
||||
|
||||
/* Lossy mode */
|
||||
boolean (*encode_mcu) (j_compress_ptr cinfo, JBLOCKROW *MCU_data);
|
||||
/* Lossless mode */
|
||||
JDIMENSION (*encode_mcus) (j_compress_ptr cinfo, JDIFFIMAGE diff_buf,
|
||||
JDIMENSION MCU_row_num, JDIMENSION MCU_col_num,
|
||||
JDIMENSION nMCU);
|
||||
|
||||
void (*finish_pass) (j_compress_ptr cinfo);
|
||||
};
|
||||
|
||||
@ -164,6 +238,7 @@ struct jpeg_decomp_master {
|
||||
|
||||
/* State variables made visible to other modules */
|
||||
boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
|
||||
boolean lossless; /* True if decompressing a lossless image */
|
||||
|
||||
/* Partial decompression variables */
|
||||
JDIMENSION first_iMCU_col;
|
||||
@ -193,14 +268,36 @@ struct jpeg_d_main_controller {
|
||||
void (*start_pass) (j_decompress_ptr cinfo, J_BUF_MODE pass_mode);
|
||||
void (*process_data) (j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
|
||||
void (*process_data_12) (j_decompress_ptr cinfo, J12SAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
void (*process_data_16) (j_decompress_ptr cinfo, J16SAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Coefficient buffer control */
|
||||
/* Lossy mode: Coefficient buffer control
|
||||
* Lossless mode: Difference buffer control
|
||||
*/
|
||||
struct jpeg_d_coef_controller {
|
||||
void (*start_input_pass) (j_decompress_ptr cinfo);
|
||||
int (*consume_data) (j_decompress_ptr cinfo);
|
||||
void (*start_output_pass) (j_decompress_ptr cinfo);
|
||||
int (*decompress_data) (j_decompress_ptr cinfo, JSAMPIMAGE output_buf);
|
||||
int (*decompress_data_12) (j_decompress_ptr cinfo, J12SAMPIMAGE output_buf);
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
int (*decompress_data_16) (j_decompress_ptr cinfo, J16SAMPIMAGE output_buf);
|
||||
#endif
|
||||
|
||||
/* These variables keep track of the current location of the input side. */
|
||||
/* cinfo->input_iMCU_row is also used for this. */
|
||||
JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
|
||||
int MCU_vert_offset; /* counts MCU rows within iMCU row */
|
||||
int MCU_rows_per_iMCU_row; /* number of such rows needed */
|
||||
|
||||
/* The output side's location is represented by cinfo->output_iMCU_row. */
|
||||
|
||||
/* Lossy mode */
|
||||
/* Pointer to array of coefficient virtual arrays, or NULL if none */
|
||||
jvirt_barray_ptr *coef_arrays;
|
||||
};
|
||||
@ -213,6 +310,20 @@ struct jpeg_d_post_controller {
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail);
|
||||
void (*post_process_data_12) (j_decompress_ptr cinfo, J12SAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
J12SAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail);
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
void (*post_process_data_16) (j_decompress_ptr cinfo, J16SAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
J16SAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Marker reading & parsing */
|
||||
@ -238,24 +349,42 @@ struct jpeg_marker_reader {
|
||||
/* Entropy decoding */
|
||||
struct jpeg_entropy_decoder {
|
||||
void (*start_pass) (j_decompress_ptr cinfo);
|
||||
|
||||
/* Lossy mode */
|
||||
boolean (*decode_mcu) (j_decompress_ptr cinfo, JBLOCKROW *MCU_data);
|
||||
/* Lossless mode */
|
||||
JDIMENSION (*decode_mcus) (j_decompress_ptr cinfo, JDIFFIMAGE diff_buf,
|
||||
JDIMENSION MCU_row_num, JDIMENSION MCU_col_num,
|
||||
JDIMENSION nMCU);
|
||||
boolean (*process_restart) (j_decompress_ptr cinfo);
|
||||
|
||||
/* This is here to share code between baseline and progressive decoders; */
|
||||
/* other modules probably should not use it */
|
||||
boolean insufficient_data; /* set TRUE after emitting warning */
|
||||
};
|
||||
|
||||
/* Inverse DCT (also performs dequantization) */
|
||||
/* Lossy mode: Inverse DCT (also performs dequantization)
|
||||
* Lossless mode: Prediction, sample undifferencing, point transform, and
|
||||
* sample size scaling
|
||||
*/
|
||||
typedef void (*inverse_DCT_method_ptr) (j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col);
|
||||
typedef void (*inverse_DCT_12_method_ptr) (j_decompress_ptr cinfo,
|
||||
jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block,
|
||||
J12SAMPARRAY output_buf,
|
||||
JDIMENSION output_col);
|
||||
|
||||
struct jpeg_inverse_dct {
|
||||
void (*start_pass) (j_decompress_ptr cinfo);
|
||||
|
||||
/* Lossy mode */
|
||||
/* It is useful to allow each component to have a separate IDCT method. */
|
||||
inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
|
||||
inverse_DCT_12_method_ptr inverse_DCT_12[MAX_COMPONENTS];
|
||||
};
|
||||
|
||||
/* Upsampling (note that upsampler must also call color converter) */
|
||||
@ -265,6 +394,16 @@ struct jpeg_upsampler {
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
|
||||
void (*upsample_12) (j_decompress_ptr cinfo, J12SAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail, J12SAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
void (*upsample_16) (j_decompress_ptr cinfo, J16SAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail, J16SAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
|
||||
#endif
|
||||
|
||||
boolean need_context_rows; /* TRUE if need rows above & below */
|
||||
};
|
||||
@ -275,6 +414,14 @@ struct jpeg_color_deconverter {
|
||||
void (*color_convert) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf,
|
||||
int num_rows);
|
||||
void (*color_convert_12) (j_decompress_ptr cinfo, J12SAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, J12SAMPARRAY output_buf,
|
||||
int num_rows);
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
void (*color_convert_16) (j_decompress_ptr cinfo, J16SAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, J16SAMPARRAY output_buf,
|
||||
int num_rows);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Color quantization or color precision reduction */
|
||||
@ -282,6 +429,8 @@ struct jpeg_color_quantizer {
|
||||
void (*start_pass) (j_decompress_ptr cinfo, boolean is_pre_scan);
|
||||
void (*color_quantize) (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows);
|
||||
void (*color_quantize_12) (j_decompress_ptr cinfo, J12SAMPARRAY input_buf,
|
||||
J12SAMPARRAY output_buf, int num_rows);
|
||||
void (*finish_pass) (j_decompress_ptr cinfo);
|
||||
void (*new_color_map) (j_decompress_ptr cinfo);
|
||||
};
|
||||
@ -323,36 +472,95 @@ EXTERN(void) jinit_c_master_control(j_compress_ptr cinfo,
|
||||
boolean transcode_only);
|
||||
EXTERN(void) jinit_c_main_controller(j_compress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) j12init_c_main_controller(j_compress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) jinit_c_prep_controller(j_compress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) j12init_c_prep_controller(j_compress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) jinit_c_coef_controller(j_compress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) j12init_c_coef_controller(j_compress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) jinit_color_converter(j_compress_ptr cinfo);
|
||||
EXTERN(void) j12init_color_converter(j_compress_ptr cinfo);
|
||||
EXTERN(void) jinit_downsampler(j_compress_ptr cinfo);
|
||||
EXTERN(void) j12init_downsampler(j_compress_ptr cinfo);
|
||||
EXTERN(void) jinit_forward_dct(j_compress_ptr cinfo);
|
||||
EXTERN(void) j12init_forward_dct(j_compress_ptr cinfo);
|
||||
EXTERN(void) jinit_huff_encoder(j_compress_ptr cinfo);
|
||||
EXTERN(void) jinit_phuff_encoder(j_compress_ptr cinfo);
|
||||
EXTERN(void) jinit_arith_encoder(j_compress_ptr cinfo);
|
||||
EXTERN(void) jinit_marker_writer(j_compress_ptr cinfo);
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
EXTERN(void) j16init_c_main_controller(j_compress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) j16init_c_prep_controller(j_compress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) j16init_color_converter(j_compress_ptr cinfo);
|
||||
EXTERN(void) j16init_downsampler(j_compress_ptr cinfo);
|
||||
EXTERN(void) jinit_c_diff_controller(j_compress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) j12init_c_diff_controller(j_compress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) j16init_c_diff_controller(j_compress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) jinit_lhuff_encoder(j_compress_ptr cinfo);
|
||||
EXTERN(void) jinit_lossless_compressor(j_compress_ptr cinfo);
|
||||
EXTERN(void) j12init_lossless_compressor(j_compress_ptr cinfo);
|
||||
EXTERN(void) j16init_lossless_compressor(j_compress_ptr cinfo);
|
||||
#endif
|
||||
|
||||
/* Decompression module initialization routines */
|
||||
EXTERN(void) jinit_master_decompress(j_decompress_ptr cinfo);
|
||||
EXTERN(void) jinit_d_main_controller(j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) j12init_d_main_controller(j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) jinit_d_coef_controller(j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) j12init_d_coef_controller(j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) jinit_d_post_controller(j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) j12init_d_post_controller(j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) jinit_input_controller(j_decompress_ptr cinfo);
|
||||
EXTERN(void) jinit_marker_reader(j_decompress_ptr cinfo);
|
||||
EXTERN(void) jinit_huff_decoder(j_decompress_ptr cinfo);
|
||||
EXTERN(void) jinit_phuff_decoder(j_decompress_ptr cinfo);
|
||||
EXTERN(void) jinit_arith_decoder(j_decompress_ptr cinfo);
|
||||
EXTERN(void) jinit_inverse_dct(j_decompress_ptr cinfo);
|
||||
EXTERN(void) j12init_inverse_dct(j_decompress_ptr cinfo);
|
||||
EXTERN(void) jinit_upsampler(j_decompress_ptr cinfo);
|
||||
EXTERN(void) j12init_upsampler(j_decompress_ptr cinfo);
|
||||
EXTERN(void) jinit_color_deconverter(j_decompress_ptr cinfo);
|
||||
EXTERN(void) j12init_color_deconverter(j_decompress_ptr cinfo);
|
||||
EXTERN(void) jinit_1pass_quantizer(j_decompress_ptr cinfo);
|
||||
EXTERN(void) j12init_1pass_quantizer(j_decompress_ptr cinfo);
|
||||
EXTERN(void) jinit_2pass_quantizer(j_decompress_ptr cinfo);
|
||||
EXTERN(void) j12init_2pass_quantizer(j_decompress_ptr cinfo);
|
||||
EXTERN(void) jinit_merged_upsampler(j_decompress_ptr cinfo);
|
||||
EXTERN(void) j12init_merged_upsampler(j_decompress_ptr cinfo);
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
EXTERN(void) j16init_d_main_controller(j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) j16init_d_post_controller(j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) j16init_upsampler(j_decompress_ptr cinfo);
|
||||
EXTERN(void) j16init_color_deconverter(j_decompress_ptr cinfo);
|
||||
EXTERN(void) jinit_d_diff_controller(j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) j12init_d_diff_controller(j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) j16init_d_diff_controller(j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer);
|
||||
EXTERN(void) jinit_lhuff_decoder(j_decompress_ptr cinfo);
|
||||
EXTERN(void) jinit_lossless_decompressor(j_decompress_ptr cinfo);
|
||||
EXTERN(void) j12init_lossless_decompressor(j_decompress_ptr cinfo);
|
||||
EXTERN(void) j16init_lossless_decompressor(j_decompress_ptr cinfo);
|
||||
#endif
|
||||
|
||||
/* Memory manager initialization */
|
||||
EXTERN(void) jinit_memory_mgr(j_common_ptr cinfo);
|
||||
|
||||
@ -362,6 +570,14 @@ EXTERN(long) jround_up(long a, long b);
|
||||
EXTERN(void) jcopy_sample_rows(JSAMPARRAY input_array, int source_row,
|
||||
JSAMPARRAY output_array, int dest_row,
|
||||
int num_rows, JDIMENSION num_cols);
|
||||
EXTERN(void) j12copy_sample_rows(J12SAMPARRAY input_array, int source_row,
|
||||
J12SAMPARRAY output_array, int dest_row,
|
||||
int num_rows, JDIMENSION num_cols);
|
||||
#if defined(C_LOSSLESS_SUPPORTED) || defined(D_LOSSLESS_SUPPORTED)
|
||||
EXTERN(void) j16copy_sample_rows(J16SAMPARRAY input_array, int source_row,
|
||||
J16SAMPARRAY output_array, int dest_row,
|
||||
int num_rows, JDIMENSION num_cols);
|
||||
#endif
|
||||
EXTERN(void) jcopy_block_row(JBLOCKROW input_row, JBLOCKROW output_row,
|
||||
JDIMENSION num_blocks);
|
||||
EXTERN(void) jzero_far(void *target, size_t bytestozero);
|
||||
|
153
3rdparty/libjpeg-turbo/src/jpeglib.h
vendored
153
3rdparty/libjpeg-turbo/src/jpeglib.h
vendored
@ -4,8 +4,11 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* Modified 2002-2009 by Guido Vollbeding.
|
||||
* Lossless JPEG Modifications:
|
||||
* Copyright (C) 1999, Ken Murchison.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2009-2011, 2013-2014, 2016-2017, 2020, D. R. Commander.
|
||||
* Copyright (C) 2009-2011, 2013-2014, 2016-2017, 2020, 2022-2023,
|
||||
D. R. Commander.
|
||||
* Copyright (C) 2015, Google, Inc.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
@ -43,6 +46,13 @@ extern "C" {
|
||||
* if you want to be compatible.
|
||||
*/
|
||||
|
||||
/* NOTE: In lossless mode, an MCU contains one or more samples rather than one
|
||||
* or more 8x8 DCT blocks, so the term "data unit" is used to generically
|
||||
* describe a sample in lossless mode or an 8x8 DCT block in lossy mode. To
|
||||
* preserve backward API/ABI compatibility, the field and macro names retain
|
||||
* the "block" terminology.
|
||||
*/
|
||||
|
||||
#define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
|
||||
#define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
|
||||
#define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
|
||||
@ -57,9 +67,9 @@ extern "C" {
|
||||
* we strongly discourage changing C_MAX_BLOCKS_IN_MCU; just because Adobe
|
||||
* sometimes emits noncompliant files doesn't mean you should too.
|
||||
*/
|
||||
#define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
|
||||
#define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on data units/MCU */
|
||||
#ifndef D_MAX_BLOCKS_IN_MCU
|
||||
#define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
|
||||
#define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on data units/MCU */
|
||||
#endif
|
||||
|
||||
|
||||
@ -70,6 +80,20 @@ typedef JSAMPLE *JSAMPROW; /* ptr to one image row of pixel samples. */
|
||||
typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
|
||||
typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
|
||||
|
||||
typedef J12SAMPLE *J12SAMPROW; /* ptr to one image row of 12-bit pixel
|
||||
samples. */
|
||||
typedef J12SAMPROW *J12SAMPARRAY; /* ptr to some 12-bit sample rows (a 2-D
|
||||
12-bit sample array) */
|
||||
typedef J12SAMPARRAY *J12SAMPIMAGE; /* a 3-D 12-bit sample array: top index is
|
||||
color */
|
||||
|
||||
typedef J16SAMPLE *J16SAMPROW; /* ptr to one image row of 16-bit pixel
|
||||
samples. */
|
||||
typedef J16SAMPROW *J16SAMPARRAY; /* ptr to some 16-bit sample rows (a 2-D
|
||||
16-bit sample array) */
|
||||
typedef J16SAMPARRAY *J16SAMPIMAGE; /* a 3-D 16-bit sample array: top index is
|
||||
color */
|
||||
|
||||
typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
|
||||
typedef JBLOCK *JBLOCKROW; /* pointer to one row of coefficient blocks */
|
||||
typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
|
||||
@ -135,17 +159,20 @@ typedef struct {
|
||||
/* Remaining fields should be treated as private by applications. */
|
||||
|
||||
/* These values are computed during compression or decompression startup: */
|
||||
/* Component's size in DCT blocks.
|
||||
* Any dummy blocks added to complete an MCU are not counted; therefore
|
||||
* these values do not depend on whether a scan is interleaved or not.
|
||||
/* Component's size in data units.
|
||||
* In lossy mode, any dummy blocks added to complete an MCU are not counted;
|
||||
* therefore these values do not depend on whether a scan is interleaved or
|
||||
* not. In lossless mode, these are always equal to the image width and
|
||||
* height.
|
||||
*/
|
||||
JDIMENSION width_in_blocks;
|
||||
JDIMENSION height_in_blocks;
|
||||
/* Size of a DCT block in samples. Always DCTSIZE for compression.
|
||||
* For decompression this is the size of the output from one DCT block,
|
||||
/* Size of a data unit in samples. Always DCTSIZE for lossy compression.
|
||||
* For lossy decompression this is the size of the output from one DCT block,
|
||||
* reflecting any scaling we choose to apply during the IDCT step.
|
||||
* Values from 1 to 16 are supported.
|
||||
* Note that different components may receive different IDCT scalings.
|
||||
* Values from 1 to 16 are supported. Note that different components may
|
||||
* receive different IDCT scalings. In lossless mode, this is always equal
|
||||
* to 1.
|
||||
*/
|
||||
#if JPEG_LIB_VERSION >= 70
|
||||
int DCT_h_scaled_size;
|
||||
@ -156,8 +183,10 @@ typedef struct {
|
||||
/* The downsampled dimensions are the component's actual, unpadded number
|
||||
* of samples at the main buffer (preprocessing/compression interface), thus
|
||||
* downsampled_width = ceil(image_width * Hi/Hmax)
|
||||
* and similarly for height. For decompression, IDCT scaling is included, so
|
||||
* and similarly for height. For lossy decompression, IDCT scaling is
|
||||
* included, so
|
||||
* downsampled_width = ceil(image_width * Hi/Hmax * DCT_[h_]scaled_size/DCTSIZE)
|
||||
* In lossless mode, these are always equal to the image width and height.
|
||||
*/
|
||||
JDIMENSION downsampled_width; /* actual width in samples */
|
||||
JDIMENSION downsampled_height; /* actual height in samples */
|
||||
@ -169,12 +198,12 @@ typedef struct {
|
||||
|
||||
/* These values are computed before starting a scan of the component. */
|
||||
/* The decompressor output side may not use these variables. */
|
||||
int MCU_width; /* number of blocks per MCU, horizontally */
|
||||
int MCU_height; /* number of blocks per MCU, vertically */
|
||||
int MCU_width; /* number of data units per MCU, horizontally */
|
||||
int MCU_height; /* number of data units per MCU, vertically */
|
||||
int MCU_blocks; /* MCU_width * MCU_height */
|
||||
int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_[h_]scaled_size */
|
||||
int last_col_width; /* # of non-dummy blocks across in last MCU */
|
||||
int last_row_height; /* # of non-dummy blocks down in last MCU */
|
||||
int last_col_width; /* # of non-dummy data units across in last MCU */
|
||||
int last_row_height; /* # of non-dummy data units down in last MCU */
|
||||
|
||||
/* Saved quantization table for component; NULL if none yet saved.
|
||||
* See jdinput.c comments about the need for this information.
|
||||
@ -192,8 +221,12 @@ typedef struct {
|
||||
typedef struct {
|
||||
int comps_in_scan; /* number of components encoded in this scan */
|
||||
int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
|
||||
int Ss, Se; /* progressive JPEG spectral selection parms */
|
||||
int Ah, Al; /* progressive JPEG successive approx. parms */
|
||||
int Ss, Se; /* progressive JPEG spectral selection parms
|
||||
(Ss is the predictor selection value in
|
||||
lossless mode) */
|
||||
int Ah, Al; /* progressive JPEG successive approx. parms
|
||||
(Al is the point transform value in lossless
|
||||
mode) */
|
||||
} jpeg_scan_info;
|
||||
|
||||
/* The decompressor can save APPn and COM markers in a list of these: */
|
||||
@ -238,7 +271,8 @@ typedef enum {
|
||||
JCS_EXT_BGRA, /* blue/green/red/alpha */
|
||||
JCS_EXT_ABGR, /* alpha/blue/green/red */
|
||||
JCS_EXT_ARGB, /* alpha/red/green/blue */
|
||||
JCS_RGB565 /* 5-bit red/6-bit green/5-bit blue */
|
||||
JCS_RGB565 /* 5-bit red/6-bit green/5-bit blue
|
||||
[decompression only] */
|
||||
} J_COLOR_SPACE;
|
||||
|
||||
/* DCT/IDCT algorithm options. */
|
||||
@ -419,11 +453,13 @@ struct jpeg_compress_struct {
|
||||
int min_DCT_v_scaled_size; /* smallest DCT_v_scaled_size of any component */
|
||||
#endif
|
||||
|
||||
JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
|
||||
/* The coefficient controller receives data in units of MCU rows as defined
|
||||
* for fully interleaved scans (whether the JPEG file is interleaved or not).
|
||||
* There are v_samp_factor * DCTSIZE sample rows of each component in an
|
||||
* "iMCU" (interleaved MCU) row.
|
||||
JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coefficient or
|
||||
difference controller */
|
||||
/* The coefficient or difference controller receives data in units of MCU
|
||||
* rows as defined for fully interleaved scans (whether the JPEG file is
|
||||
* interleaved or not). In lossy mode, there are v_samp_factor * DCTSIZE
|
||||
* sample rows of each component in an "iMCU" (interleaved MCU) row. In
|
||||
* lossless mode, total_iMCU_rows is always equal to the image height.
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -437,12 +473,13 @@ struct jpeg_compress_struct {
|
||||
JDIMENSION MCUs_per_row; /* # of MCUs across the image */
|
||||
JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
|
||||
|
||||
int blocks_in_MCU; /* # of DCT blocks per MCU */
|
||||
int blocks_in_MCU; /* # of data units per MCU */
|
||||
int MCU_membership[C_MAX_BLOCKS_IN_MCU];
|
||||
/* MCU_membership[i] is index in cur_comp_info of component owning */
|
||||
/* i'th block in an MCU */
|
||||
/* i'th data unit in an MCU */
|
||||
|
||||
int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
|
||||
int Ss, Se, Ah, Al; /* progressive/lossless JPEG parameters for
|
||||
scan */
|
||||
|
||||
#if JPEG_LIB_VERSION >= 80
|
||||
int block_size; /* the basic DCT block size: 1..16 */
|
||||
@ -537,7 +574,12 @@ struct jpeg_decompress_struct {
|
||||
* The map has out_color_components rows and actual_number_of_colors columns.
|
||||
*/
|
||||
int actual_number_of_colors; /* number of entries in use */
|
||||
JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
|
||||
JSAMPARRAY colormap; /* The color map as a 2-D pixel array
|
||||
If data_precision is 12 or 16, then this is
|
||||
actually a J12SAMPARRAY or a J16SAMPARRAY,
|
||||
so callers must type-cast it in order to
|
||||
read/write 12-bit or 16-bit samples from/to
|
||||
the array. */
|
||||
|
||||
/* State variables: these variables indicate the progress of decompression.
|
||||
* The application may examine these but must not modify them.
|
||||
@ -647,15 +689,21 @@ struct jpeg_decompress_struct {
|
||||
#endif
|
||||
|
||||
JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
|
||||
/* The coefficient controller's input and output progress is measured in
|
||||
* units of "iMCU" (interleaved MCU) rows. These are the same as MCU rows
|
||||
* in fully interleaved JPEG scans, but are used whether the scan is
|
||||
* interleaved or not. We define an iMCU row as v_samp_factor DCT block
|
||||
* rows of each component. Therefore, the IDCT output contains
|
||||
/* The coefficient or difference controller's input and output progress is
|
||||
* measured in units of "iMCU" (interleaved MCU) rows. These are the same as
|
||||
* MCU rows in fully interleaved JPEG scans, but are used whether the scan is
|
||||
* interleaved or not. In lossy mode, we define an iMCU row as v_samp_factor
|
||||
* DCT block rows of each component. Therefore, the IDCT output contains
|
||||
* v_samp_factor*DCT_[v_]scaled_size sample rows of a component per iMCU row.
|
||||
* In lossless mode, total_iMCU_rows is always equal to the image height.
|
||||
*/
|
||||
|
||||
JSAMPLE *sample_range_limit; /* table for fast range-limiting */
|
||||
JSAMPLE *sample_range_limit; /* table for fast range-limiting
|
||||
If data_precision is 12 or 16, then this is
|
||||
actually a J12SAMPLE pointer or a J16SAMPLE
|
||||
pointer, so callers must type-cast it in
|
||||
order to read 12-bit or 16-bit samples from
|
||||
the array. */
|
||||
|
||||
/*
|
||||
* These fields are valid during any one scan.
|
||||
@ -669,12 +717,13 @@ struct jpeg_decompress_struct {
|
||||
JDIMENSION MCUs_per_row; /* # of MCUs across the image */
|
||||
JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
|
||||
|
||||
int blocks_in_MCU; /* # of DCT blocks per MCU */
|
||||
int blocks_in_MCU; /* # of data units per MCU */
|
||||
int MCU_membership[D_MAX_BLOCKS_IN_MCU];
|
||||
/* MCU_membership[i] is index in cur_comp_info of component owning */
|
||||
/* i'th block in an MCU */
|
||||
/* i'th data unit in an MCU */
|
||||
|
||||
int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
|
||||
int Ss, Se, Ah, Al; /* progressive/lossless JPEG parameters for
|
||||
scan */
|
||||
|
||||
#if JPEG_LIB_VERSION >= 80
|
||||
/* These fields are derived from Se of first SOS marker.
|
||||
@ -835,6 +884,11 @@ struct jpeg_memory_mgr {
|
||||
void *(*alloc_small) (j_common_ptr cinfo, int pool_id, size_t sizeofobject);
|
||||
void *(*alloc_large) (j_common_ptr cinfo, int pool_id,
|
||||
size_t sizeofobject);
|
||||
/* If cinfo->data_precision is 12 or 16, then this method and the
|
||||
* access_virt_sarray method actually return a J12SAMPARRAY or a
|
||||
* J16SAMPARRAY, so callers must type-cast the return value in order to
|
||||
* read/write 12-bit or 16-bit samples from/to the array.
|
||||
*/
|
||||
JSAMPARRAY (*alloc_sarray) (j_common_ptr cinfo, int pool_id,
|
||||
JDIMENSION samplesperrow, JDIMENSION numrows);
|
||||
JBLOCKARRAY (*alloc_barray) (j_common_ptr cinfo, int pool_id,
|
||||
@ -916,13 +970,11 @@ EXTERN(void) jpeg_destroy_decompress(j_decompress_ptr cinfo);
|
||||
EXTERN(void) jpeg_stdio_dest(j_compress_ptr cinfo, FILE *outfile);
|
||||
EXTERN(void) jpeg_stdio_src(j_decompress_ptr cinfo, FILE *infile);
|
||||
|
||||
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
|
||||
/* Data source and destination managers: memory buffers. */
|
||||
EXTERN(void) jpeg_mem_dest(j_compress_ptr cinfo, unsigned char **outbuffer,
|
||||
unsigned long *outsize);
|
||||
EXTERN(void) jpeg_mem_src(j_decompress_ptr cinfo,
|
||||
const unsigned char *inbuffer, unsigned long insize);
|
||||
#endif
|
||||
|
||||
/* Default parameter setup for compression */
|
||||
EXTERN(void) jpeg_set_defaults(j_compress_ptr cinfo);
|
||||
@ -942,6 +994,9 @@ EXTERN(void) jpeg_add_quant_table(j_compress_ptr cinfo, int which_tbl,
|
||||
const unsigned int *basic_table,
|
||||
int scale_factor, boolean force_baseline);
|
||||
EXTERN(int) jpeg_quality_scaling(int quality);
|
||||
EXTERN(void) jpeg_enable_lossless(j_compress_ptr cinfo,
|
||||
int predictor_selection_value,
|
||||
int point_transform);
|
||||
EXTERN(void) jpeg_simple_progression(j_compress_ptr cinfo);
|
||||
EXTERN(void) jpeg_suppress_tables(j_compress_ptr cinfo, boolean suppress);
|
||||
EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table(j_common_ptr cinfo);
|
||||
@ -953,6 +1008,12 @@ EXTERN(void) jpeg_start_compress(j_compress_ptr cinfo,
|
||||
EXTERN(JDIMENSION) jpeg_write_scanlines(j_compress_ptr cinfo,
|
||||
JSAMPARRAY scanlines,
|
||||
JDIMENSION num_lines);
|
||||
EXTERN(JDIMENSION) jpeg12_write_scanlines(j_compress_ptr cinfo,
|
||||
J12SAMPARRAY scanlines,
|
||||
JDIMENSION num_lines);
|
||||
EXTERN(JDIMENSION) jpeg16_write_scanlines(j_compress_ptr cinfo,
|
||||
J16SAMPARRAY scanlines,
|
||||
JDIMENSION num_lines);
|
||||
EXTERN(void) jpeg_finish_compress(j_compress_ptr cinfo);
|
||||
|
||||
#if JPEG_LIB_VERSION >= 70
|
||||
@ -963,6 +1024,9 @@ EXTERN(void) jpeg_calc_jpeg_dimensions(j_compress_ptr cinfo);
|
||||
/* Replaces jpeg_write_scanlines when writing raw downsampled data. */
|
||||
EXTERN(JDIMENSION) jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
|
||||
JDIMENSION num_lines);
|
||||
EXTERN(JDIMENSION) jpeg12_write_raw_data(j_compress_ptr cinfo,
|
||||
J12SAMPIMAGE data,
|
||||
JDIMENSION num_lines);
|
||||
|
||||
/* Write a special marker. See libjpeg.txt concerning safe usage. */
|
||||
EXTERN(void) jpeg_write_marker(j_compress_ptr cinfo, int marker,
|
||||
@ -998,15 +1062,28 @@ EXTERN(boolean) jpeg_start_decompress(j_decompress_ptr cinfo);
|
||||
EXTERN(JDIMENSION) jpeg_read_scanlines(j_decompress_ptr cinfo,
|
||||
JSAMPARRAY scanlines,
|
||||
JDIMENSION max_lines);
|
||||
EXTERN(JDIMENSION) jpeg12_read_scanlines(j_decompress_ptr cinfo,
|
||||
J12SAMPARRAY scanlines,
|
||||
JDIMENSION max_lines);
|
||||
EXTERN(JDIMENSION) jpeg16_read_scanlines(j_decompress_ptr cinfo,
|
||||
J16SAMPARRAY scanlines,
|
||||
JDIMENSION max_lines);
|
||||
EXTERN(JDIMENSION) jpeg_skip_scanlines(j_decompress_ptr cinfo,
|
||||
JDIMENSION num_lines);
|
||||
EXTERN(JDIMENSION) jpeg12_skip_scanlines(j_decompress_ptr cinfo,
|
||||
JDIMENSION num_lines);
|
||||
EXTERN(void) jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
|
||||
JDIMENSION *width);
|
||||
EXTERN(void) jpeg12_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
|
||||
JDIMENSION *width);
|
||||
EXTERN(boolean) jpeg_finish_decompress(j_decompress_ptr cinfo);
|
||||
|
||||
/* Replaces jpeg_read_scanlines when reading raw downsampled data. */
|
||||
EXTERN(JDIMENSION) jpeg_read_raw_data(j_decompress_ptr cinfo, JSAMPIMAGE data,
|
||||
JDIMENSION max_lines);
|
||||
EXTERN(JDIMENSION) jpeg12_read_raw_data(j_decompress_ptr cinfo,
|
||||
J12SAMPIMAGE data,
|
||||
JDIMENSION max_lines);
|
||||
|
||||
/* Additional entry points for buffered-image mode. */
|
||||
EXTERN(boolean) jpeg_has_multiple_scans(j_decompress_ptr cinfo);
|
||||
|
164
3rdparty/libjpeg-turbo/src/jquant1.c
vendored
164
3rdparty/libjpeg-turbo/src/jquant1.c
vendored
@ -4,7 +4,7 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2009, 2015, D. R. Commander.
|
||||
* Copyright (C) 2009, 2015, 2022-2023, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -16,8 +16,9 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
#ifdef QUANT_1PASS_SUPPORTED
|
||||
#if defined(QUANT_1PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16
|
||||
|
||||
|
||||
/*
|
||||
@ -66,7 +67,7 @@
|
||||
* worse, since the dither may be too much or too little at a given point.
|
||||
*
|
||||
* The normal calculation would be to form pixel value + dither, range-limit
|
||||
* this to 0..MAXJSAMPLE, and then index into the colorindex table as usual.
|
||||
* this to 0.._MAXJSAMPLE, and then index into the colorindex table as usual.
|
||||
* We can skip the separate range-limiting step by extending the colorindex
|
||||
* table in both directions.
|
||||
*/
|
||||
@ -144,13 +145,13 @@ typedef struct {
|
||||
struct jpeg_color_quantizer pub; /* public fields */
|
||||
|
||||
/* Initially allocated colormap is saved here */
|
||||
JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
|
||||
_JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
|
||||
int sv_actual; /* number of entries in use */
|
||||
|
||||
JSAMPARRAY colorindex; /* Precomputed mapping for speed */
|
||||
_JSAMPARRAY colorindex; /* Precomputed mapping for speed */
|
||||
/* colorindex[i][j] = index of color closest to pixel value j in component i,
|
||||
* premultiplied as described above. Since colormap indexes must fit into
|
||||
* JSAMPLEs, the entries of this array will too.
|
||||
* _JSAMPLEs, the entries of this array will too.
|
||||
*/
|
||||
boolean is_padded; /* is the colorindex padded for odither? */
|
||||
|
||||
@ -248,24 +249,24 @@ select_ncolors(j_decompress_ptr cinfo, int Ncolors[])
|
||||
LOCAL(int)
|
||||
output_value(j_decompress_ptr cinfo, int ci, int j, int maxj)
|
||||
/* Return j'th output value, where j will range from 0 to maxj */
|
||||
/* The output values must fall in 0..MAXJSAMPLE in increasing order */
|
||||
/* The output values must fall in 0.._MAXJSAMPLE in increasing order */
|
||||
{
|
||||
/* We always provide values 0 and MAXJSAMPLE for each component;
|
||||
/* We always provide values 0 and _MAXJSAMPLE for each component;
|
||||
* any additional values are equally spaced between these limits.
|
||||
* (Forcing the upper and lower values to the limits ensures that
|
||||
* dithering can't produce a color outside the selected gamut.)
|
||||
*/
|
||||
return (int)(((JLONG)j * MAXJSAMPLE + maxj / 2) / maxj);
|
||||
return (int)(((JLONG)j * _MAXJSAMPLE + maxj / 2) / maxj);
|
||||
}
|
||||
|
||||
|
||||
LOCAL(int)
|
||||
largest_input_value(j_decompress_ptr cinfo, int ci, int j, int maxj)
|
||||
/* Return largest input value that should map to j'th output value */
|
||||
/* Must have largest(j=0) >= 0, and largest(j=maxj) >= MAXJSAMPLE */
|
||||
/* Must have largest(j=0) >= 0, and largest(j=maxj) >= _MAXJSAMPLE */
|
||||
{
|
||||
/* Breakpoints are halfway between values returned by output_value */
|
||||
return (int)(((JLONG)(2 * j + 1) * MAXJSAMPLE + maxj) / (2 * maxj));
|
||||
return (int)(((JLONG)(2 * j + 1) * _MAXJSAMPLE + maxj) / (2 * maxj));
|
||||
}
|
||||
|
||||
|
||||
@ -277,7 +278,7 @@ LOCAL(void)
|
||||
create_colormap(j_decompress_ptr cinfo)
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
|
||||
JSAMPARRAY colormap; /* Created colormap */
|
||||
_JSAMPARRAY colormap; /* Created colormap */
|
||||
int total_colors; /* Number of distinct output colors */
|
||||
int i, j, k, nci, blksize, blkdist, ptr, val;
|
||||
|
||||
@ -296,7 +297,7 @@ create_colormap(j_decompress_ptr cinfo)
|
||||
/* The colors are ordered in the map in standard row-major order, */
|
||||
/* i.e. rightmost (highest-indexed) color changes most rapidly. */
|
||||
|
||||
colormap = (*cinfo->mem->alloc_sarray)
|
||||
colormap = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION)total_colors, (JDIMENSION)cinfo->out_color_components);
|
||||
|
||||
@ -315,7 +316,7 @@ create_colormap(j_decompress_ptr cinfo)
|
||||
for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
|
||||
/* fill in blksize entries beginning at ptr */
|
||||
for (k = 0; k < blksize; k++)
|
||||
colormap[i][ptr + k] = (JSAMPLE)val;
|
||||
colormap[i][ptr + k] = (_JSAMPLE)val;
|
||||
}
|
||||
}
|
||||
blkdist = blksize; /* blksize of this color is blkdist of next */
|
||||
@ -337,25 +338,25 @@ LOCAL(void)
|
||||
create_colorindex(j_decompress_ptr cinfo)
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
|
||||
JSAMPROW indexptr;
|
||||
_JSAMPROW indexptr;
|
||||
int i, j, k, nci, blksize, val, pad;
|
||||
|
||||
/* For ordered dither, we pad the color index tables by MAXJSAMPLE in
|
||||
* each direction (input index values can be -MAXJSAMPLE .. 2*MAXJSAMPLE).
|
||||
/* For ordered dither, we pad the color index tables by _MAXJSAMPLE in
|
||||
* each direction (input index values can be -_MAXJSAMPLE .. 2*_MAXJSAMPLE).
|
||||
* This is not necessary in the other dithering modes. However, we
|
||||
* flag whether it was done in case user changes dithering mode.
|
||||
*/
|
||||
if (cinfo->dither_mode == JDITHER_ORDERED) {
|
||||
pad = MAXJSAMPLE * 2;
|
||||
pad = _MAXJSAMPLE * 2;
|
||||
cquantize->is_padded = TRUE;
|
||||
} else {
|
||||
pad = 0;
|
||||
cquantize->is_padded = FALSE;
|
||||
}
|
||||
|
||||
cquantize->colorindex = (*cinfo->mem->alloc_sarray)
|
||||
cquantize->colorindex = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION)(MAXJSAMPLE + 1 + pad),
|
||||
(JDIMENSION)(_MAXJSAMPLE + 1 + pad),
|
||||
(JDIMENSION)cinfo->out_color_components);
|
||||
|
||||
/* blksize is number of adjacent repeated entries for a component */
|
||||
@ -368,24 +369,24 @@ create_colorindex(j_decompress_ptr cinfo)
|
||||
|
||||
/* adjust colorindex pointers to provide padding at negative indexes. */
|
||||
if (pad)
|
||||
cquantize->colorindex[i] += MAXJSAMPLE;
|
||||
cquantize->colorindex[i] += _MAXJSAMPLE;
|
||||
|
||||
/* in loop, val = index of current output value, */
|
||||
/* and k = largest j that maps to current val */
|
||||
indexptr = cquantize->colorindex[i];
|
||||
val = 0;
|
||||
k = largest_input_value(cinfo, i, 0, nci - 1);
|
||||
for (j = 0; j <= MAXJSAMPLE; j++) {
|
||||
for (j = 0; j <= _MAXJSAMPLE; j++) {
|
||||
while (j > k) /* advance val if past boundary */
|
||||
k = largest_input_value(cinfo, i, ++val, nci - 1);
|
||||
/* premultiply so that no multiplication needed in main processing */
|
||||
indexptr[j] = (JSAMPLE)(val * blksize);
|
||||
indexptr[j] = (_JSAMPLE)(val * blksize);
|
||||
}
|
||||
/* Pad at both ends if necessary */
|
||||
if (pad)
|
||||
for (j = 1; j <= MAXJSAMPLE; j++) {
|
||||
for (j = 1; j <= _MAXJSAMPLE; j++) {
|
||||
indexptr[-j] = indexptr[0];
|
||||
indexptr[MAXJSAMPLE + j] = indexptr[MAXJSAMPLE];
|
||||
indexptr[_MAXJSAMPLE + j] = indexptr[_MAXJSAMPLE];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -406,16 +407,16 @@ make_odither_array(j_decompress_ptr cinfo, int ncolors)
|
||||
odither = (ODITHER_MATRIX_PTR)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(ODITHER_MATRIX));
|
||||
/* The inter-value distance for this color is MAXJSAMPLE/(ncolors-1).
|
||||
/* The inter-value distance for this color is _MAXJSAMPLE/(ncolors-1).
|
||||
* Hence the dither value for the matrix cell with fill order f
|
||||
* (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1).
|
||||
* (f=0..N-1) should be (N-1-2*f)/(2*N) * _MAXJSAMPLE/(ncolors-1).
|
||||
* On 16-bit-int machine, be careful to avoid overflow.
|
||||
*/
|
||||
den = 2 * ODITHER_CELLS * ((JLONG)(ncolors - 1));
|
||||
for (j = 0; j < ODITHER_SIZE; j++) {
|
||||
for (k = 0; k < ODITHER_SIZE; k++) {
|
||||
num = ((JLONG)(ODITHER_CELLS - 1 -
|
||||
2 * ((int)base_dither_matrix[j][k]))) * MAXJSAMPLE;
|
||||
2 * ((int)base_dither_matrix[j][k]))) * _MAXJSAMPLE;
|
||||
/* Ensure round towards zero despite C's lack of consistency
|
||||
* about rounding negative values in integer division...
|
||||
*/
|
||||
@ -460,14 +461,14 @@ create_odither_tables(j_decompress_ptr cinfo)
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
color_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
color_quantize(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPARRAY output_buf, int num_rows)
|
||||
/* General case, no dithering */
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
|
||||
JSAMPARRAY colorindex = cquantize->colorindex;
|
||||
_JSAMPARRAY colorindex = cquantize->colorindex;
|
||||
register int pixcode, ci;
|
||||
register JSAMPROW ptrin, ptrout;
|
||||
register _JSAMPROW ptrin, ptrout;
|
||||
int row;
|
||||
JDIMENSION col;
|
||||
JDIMENSION width = cinfo->output_width;
|
||||
@ -481,23 +482,23 @@ color_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
for (ci = 0; ci < nc; ci++) {
|
||||
pixcode += colorindex[ci][*ptrin++];
|
||||
}
|
||||
*ptrout++ = (JSAMPLE)pixcode;
|
||||
*ptrout++ = (_JSAMPLE)pixcode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
color_quantize3(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
color_quantize3(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPARRAY output_buf, int num_rows)
|
||||
/* Fast path for out_color_components==3, no dithering */
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
|
||||
register int pixcode;
|
||||
register JSAMPROW ptrin, ptrout;
|
||||
JSAMPROW colorindex0 = cquantize->colorindex[0];
|
||||
JSAMPROW colorindex1 = cquantize->colorindex[1];
|
||||
JSAMPROW colorindex2 = cquantize->colorindex[2];
|
||||
register _JSAMPROW ptrin, ptrout;
|
||||
_JSAMPROW colorindex0 = cquantize->colorindex[0];
|
||||
_JSAMPROW colorindex1 = cquantize->colorindex[1];
|
||||
_JSAMPROW colorindex2 = cquantize->colorindex[2];
|
||||
int row;
|
||||
JDIMENSION col;
|
||||
JDIMENSION width = cinfo->output_width;
|
||||
@ -509,21 +510,21 @@ color_quantize3(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
pixcode = colorindex0[*ptrin++];
|
||||
pixcode += colorindex1[*ptrin++];
|
||||
pixcode += colorindex2[*ptrin++];
|
||||
*ptrout++ = (JSAMPLE)pixcode;
|
||||
*ptrout++ = (_JSAMPLE)pixcode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
quantize_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
quantize_ord_dither(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPARRAY output_buf, int num_rows)
|
||||
/* General case, with ordered dithering */
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
|
||||
register JSAMPROW input_ptr;
|
||||
register JSAMPROW output_ptr;
|
||||
JSAMPROW colorindex_ci;
|
||||
register _JSAMPROW input_ptr;
|
||||
register _JSAMPROW output_ptr;
|
||||
_JSAMPROW colorindex_ci;
|
||||
int *dither; /* points to active row of dither matrix */
|
||||
int row_index, col_index; /* current indexes into dither matrix */
|
||||
int nc = cinfo->out_color_components;
|
||||
@ -534,7 +535,7 @@ quantize_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
|
||||
for (row = 0; row < num_rows; row++) {
|
||||
/* Initialize output values to 0 so can process components separately */
|
||||
jzero_far((void *)output_buf[row], (size_t)(width * sizeof(JSAMPLE)));
|
||||
jzero_far((void *)output_buf[row], (size_t)(width * sizeof(_JSAMPLE)));
|
||||
row_index = cquantize->row_index;
|
||||
for (ci = 0; ci < nc; ci++) {
|
||||
input_ptr = input_buf[row] + ci;
|
||||
@ -544,11 +545,11 @@ quantize_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
col_index = 0;
|
||||
|
||||
for (col = width; col > 0; col--) {
|
||||
/* Form pixel value + dither, range-limit to 0..MAXJSAMPLE,
|
||||
/* Form pixel value + dither, range-limit to 0.._MAXJSAMPLE,
|
||||
* select output value, accumulate into output code for this pixel.
|
||||
* Range-limiting need not be done explicitly, as we have extended
|
||||
* the colorindex table to produce the right answers for out-of-range
|
||||
* inputs. The maximum dither is +- MAXJSAMPLE; this sets the
|
||||
* inputs. The maximum dither is +- _MAXJSAMPLE; this sets the
|
||||
* required amount of padding.
|
||||
*/
|
||||
*output_ptr +=
|
||||
@ -566,17 +567,17 @@ quantize_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
quantize3_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
quantize3_ord_dither(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPARRAY output_buf, int num_rows)
|
||||
/* Fast path for out_color_components==3, with ordered dithering */
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
|
||||
register int pixcode;
|
||||
register JSAMPROW input_ptr;
|
||||
register JSAMPROW output_ptr;
|
||||
JSAMPROW colorindex0 = cquantize->colorindex[0];
|
||||
JSAMPROW colorindex1 = cquantize->colorindex[1];
|
||||
JSAMPROW colorindex2 = cquantize->colorindex[2];
|
||||
register _JSAMPROW input_ptr;
|
||||
register _JSAMPROW output_ptr;
|
||||
_JSAMPROW colorindex0 = cquantize->colorindex[0];
|
||||
_JSAMPROW colorindex1 = cquantize->colorindex[1];
|
||||
_JSAMPROW colorindex2 = cquantize->colorindex[2];
|
||||
int *dither0; /* points to active row of dither matrix */
|
||||
int *dither1;
|
||||
int *dither2;
|
||||
@ -598,7 +599,7 @@ quantize3_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
pixcode = colorindex0[(*input_ptr++) + dither0[col_index]];
|
||||
pixcode += colorindex1[(*input_ptr++) + dither1[col_index]];
|
||||
pixcode += colorindex2[(*input_ptr++) + dither2[col_index]];
|
||||
*output_ptr++ = (JSAMPLE)pixcode;
|
||||
*output_ptr++ = (_JSAMPLE)pixcode;
|
||||
col_index = (col_index + 1) & ODITHER_MASK;
|
||||
}
|
||||
row_index = (row_index + 1) & ODITHER_MASK;
|
||||
@ -608,8 +609,8 @@ quantize3_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
quantize_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
quantize_fs_dither(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPARRAY output_buf, int num_rows)
|
||||
/* General case, with Floyd-Steinberg dithering */
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
|
||||
@ -619,10 +620,10 @@ quantize_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
LOCFSERROR bnexterr; /* error for below/next col */
|
||||
LOCFSERROR delta;
|
||||
register FSERRPTR errorptr; /* => fserrors[] at column before current */
|
||||
register JSAMPROW input_ptr;
|
||||
register JSAMPROW output_ptr;
|
||||
JSAMPROW colorindex_ci;
|
||||
JSAMPROW colormap_ci;
|
||||
register _JSAMPROW input_ptr;
|
||||
register _JSAMPROW output_ptr;
|
||||
_JSAMPROW colorindex_ci;
|
||||
_JSAMPROW colormap_ci;
|
||||
int pixcode;
|
||||
int nc = cinfo->out_color_components;
|
||||
int dir; /* 1 for left-to-right, -1 for right-to-left */
|
||||
@ -631,12 +632,12 @@ quantize_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
int row;
|
||||
JDIMENSION col;
|
||||
JDIMENSION width = cinfo->output_width;
|
||||
JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
_JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
|
||||
SHIFT_TEMPS
|
||||
|
||||
for (row = 0; row < num_rows; row++) {
|
||||
/* Initialize output values to 0 so can process components separately */
|
||||
jzero_far((void *)output_buf[row], (size_t)(width * sizeof(JSAMPLE)));
|
||||
jzero_far((void *)output_buf[row], (size_t)(width * sizeof(_JSAMPLE)));
|
||||
for (ci = 0; ci < nc; ci++) {
|
||||
input_ptr = input_buf[row] + ci;
|
||||
output_ptr = output_buf[row];
|
||||
@ -670,15 +671,15 @@ quantize_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
* Note: errorptr points to *previous* column's array entry.
|
||||
*/
|
||||
cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
|
||||
/* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.
|
||||
* The maximum error is +- MAXJSAMPLE; this sets the required size
|
||||
/* Form pixel value + error, and range-limit to 0.._MAXJSAMPLE.
|
||||
* The maximum error is +- _MAXJSAMPLE; this sets the required size
|
||||
* of the range_limit array.
|
||||
*/
|
||||
cur += *input_ptr;
|
||||
cur = range_limit[cur];
|
||||
/* Select output value, accumulate into output code for this pixel */
|
||||
pixcode = colorindex_ci[cur];
|
||||
*output_ptr += (JSAMPLE)pixcode;
|
||||
*output_ptr += (_JSAMPLE)pixcode;
|
||||
/* Compute actual representation error at this pixel */
|
||||
/* Note: we can do this even though we don't have the final */
|
||||
/* pixel code, because the colormap is orthogonal. */
|
||||
@ -745,22 +746,22 @@ start_pass_1_quant(j_decompress_ptr cinfo, boolean is_pre_scan)
|
||||
int i;
|
||||
|
||||
/* Install my colormap. */
|
||||
cinfo->colormap = cquantize->sv_colormap;
|
||||
cinfo->colormap = (JSAMPARRAY)cquantize->sv_colormap;
|
||||
cinfo->actual_number_of_colors = cquantize->sv_actual;
|
||||
|
||||
/* Initialize for desired dithering mode. */
|
||||
switch (cinfo->dither_mode) {
|
||||
case JDITHER_NONE:
|
||||
if (cinfo->out_color_components == 3)
|
||||
cquantize->pub.color_quantize = color_quantize3;
|
||||
cquantize->pub._color_quantize = color_quantize3;
|
||||
else
|
||||
cquantize->pub.color_quantize = color_quantize;
|
||||
cquantize->pub._color_quantize = color_quantize;
|
||||
break;
|
||||
case JDITHER_ORDERED:
|
||||
if (cinfo->out_color_components == 3)
|
||||
cquantize->pub.color_quantize = quantize3_ord_dither;
|
||||
cquantize->pub._color_quantize = quantize3_ord_dither;
|
||||
else
|
||||
cquantize->pub.color_quantize = quantize_ord_dither;
|
||||
cquantize->pub._color_quantize = quantize_ord_dither;
|
||||
cquantize->row_index = 0; /* initialize state for ordered dither */
|
||||
/* If user changed to ordered dither from another mode,
|
||||
* we must recreate the color index table with padding.
|
||||
@ -773,7 +774,7 @@ start_pass_1_quant(j_decompress_ptr cinfo, boolean is_pre_scan)
|
||||
create_odither_tables(cinfo);
|
||||
break;
|
||||
case JDITHER_FS:
|
||||
cquantize->pub.color_quantize = quantize_fs_dither;
|
||||
cquantize->pub._color_quantize = quantize_fs_dither;
|
||||
cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
|
||||
/* Allocate Floyd-Steinberg workspace if didn't already. */
|
||||
if (cquantize->fserrors[0] == NULL)
|
||||
@ -818,10 +819,17 @@ new_color_map_1_quant(j_decompress_ptr cinfo)
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_1pass_quantizer(j_decompress_ptr cinfo)
|
||||
_jinit_1pass_quantizer(j_decompress_ptr cinfo)
|
||||
{
|
||||
my_cquantize_ptr cquantize;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
/* Color quantization is not supported with lossless JPEG images */
|
||||
if (cinfo->master->lossless)
|
||||
ERREXIT(cinfo, JERR_NOTIMPL);
|
||||
|
||||
cquantize = (my_cquantize_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_cquantizer));
|
||||
@ -835,9 +843,9 @@ jinit_1pass_quantizer(j_decompress_ptr cinfo)
|
||||
/* Make sure my internal arrays won't overflow */
|
||||
if (cinfo->out_color_components > MAX_Q_COMPS)
|
||||
ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
|
||||
/* Make sure colormap indexes can be represented by JSAMPLEs */
|
||||
if (cinfo->desired_number_of_colors > (MAXJSAMPLE + 1))
|
||||
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE + 1);
|
||||
/* Make sure colormap indexes can be represented by _JSAMPLEs */
|
||||
if (cinfo->desired_number_of_colors > (_MAXJSAMPLE + 1))
|
||||
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, _MAXJSAMPLE + 1);
|
||||
|
||||
/* Create the colormap and color index table. */
|
||||
create_colormap(cinfo);
|
||||
@ -853,4 +861,4 @@ jinit_1pass_quantizer(j_decompress_ptr cinfo)
|
||||
alloc_fs_workspace(cinfo);
|
||||
}
|
||||
|
||||
#endif /* QUANT_1PASS_SUPPORTED */
|
||||
#endif /* defined(QUANT_1PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */
|
||||
|
130
3rdparty/libjpeg-turbo/src/jquant2.c
vendored
130
3rdparty/libjpeg-turbo/src/jquant2.c
vendored
@ -4,7 +4,7 @@
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2009, 2014-2015, 2020, D. R. Commander.
|
||||
* Copyright (C) 2009, 2014-2015, 2020, 2022-2023, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -23,8 +23,9 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
#ifdef QUANT_2PASS_SUPPORTED
|
||||
#if defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16
|
||||
|
||||
|
||||
/*
|
||||
@ -106,7 +107,7 @@ static const int c_scales[3] = { R_SCALE, G_SCALE, B_SCALE };
|
||||
* each 2-D array has 2^6*2^5 = 2048 or 2^6*2^6 = 4096 entries.
|
||||
*/
|
||||
|
||||
#define MAXNUMCOLORS (MAXJSAMPLE + 1) /* maximum size of colormap */
|
||||
#define MAXNUMCOLORS (_MAXJSAMPLE + 1) /* maximum size of colormap */
|
||||
|
||||
/* These will do the right thing for either R,G,B or B,G,R color order,
|
||||
* but you may not like the results for other color orders.
|
||||
@ -173,7 +174,7 @@ typedef struct {
|
||||
struct jpeg_color_quantizer pub; /* public fields */
|
||||
|
||||
/* Space for the eventually created colormap is stashed here */
|
||||
JSAMPARRAY sv_colormap; /* colormap allocated at init time */
|
||||
_JSAMPARRAY sv_colormap; /* colormap allocated at init time */
|
||||
int desired; /* desired # of colors = size of colormap */
|
||||
|
||||
/* Variables for accumulating image statistics */
|
||||
@ -200,11 +201,11 @@ typedef my_cquantizer *my_cquantize_ptr;
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
prescan_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
prescan_quantize(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
|
||||
register JSAMPROW ptr;
|
||||
register _JSAMPROW ptr;
|
||||
register histptr histp;
|
||||
register hist3d histogram = cquantize->histogram;
|
||||
int row;
|
||||
@ -377,7 +378,7 @@ have_c2max:
|
||||
* against making long narrow boxes, and it has the side benefit that
|
||||
* a box is splittable iff norm > 0.
|
||||
* Since the differences are expressed in histogram-cell units,
|
||||
* we have to shift back to JSAMPLE units to get consistent distances;
|
||||
* we have to shift back to _JSAMPLE units to get consistent distances;
|
||||
* after which, we scale according to the selected distance scale factors.
|
||||
*/
|
||||
dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
|
||||
@ -508,9 +509,12 @@ compute_color(j_decompress_ptr cinfo, boxptr boxp, int icolor)
|
||||
}
|
||||
}
|
||||
|
||||
cinfo->colormap[0][icolor] = (JSAMPLE)((c0total + (total >> 1)) / total);
|
||||
cinfo->colormap[1][icolor] = (JSAMPLE)((c1total + (total >> 1)) / total);
|
||||
cinfo->colormap[2][icolor] = (JSAMPLE)((c2total + (total >> 1)) / total);
|
||||
((_JSAMPARRAY)cinfo->colormap)[0][icolor] =
|
||||
(_JSAMPLE)((c0total + (total >> 1)) / total);
|
||||
((_JSAMPARRAY)cinfo->colormap)[1][icolor] =
|
||||
(_JSAMPLE)((c1total + (total >> 1)) / total);
|
||||
((_JSAMPARRAY)cinfo->colormap)[2][icolor] =
|
||||
(_JSAMPLE)((c2total + (total >> 1)) / total);
|
||||
}
|
||||
|
||||
|
||||
@ -528,11 +532,11 @@ select_colors(j_decompress_ptr cinfo, int desired_colors)
|
||||
/* Initialize one box containing whole space */
|
||||
numboxes = 1;
|
||||
boxlist[0].c0min = 0;
|
||||
boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
|
||||
boxlist[0].c0max = _MAXJSAMPLE >> C0_SHIFT;
|
||||
boxlist[0].c1min = 0;
|
||||
boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
|
||||
boxlist[0].c1max = _MAXJSAMPLE >> C1_SHIFT;
|
||||
boxlist[0].c2min = 0;
|
||||
boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
|
||||
boxlist[0].c2max = _MAXJSAMPLE >> C2_SHIFT;
|
||||
/* Shrink it to actually-used volume and set its statistics */
|
||||
update_box(cinfo, &boxlist[0]);
|
||||
/* Perform median-cut to produce final box list */
|
||||
@ -623,7 +627,7 @@ select_colors(j_decompress_ptr cinfo, int desired_colors)
|
||||
|
||||
LOCAL(int)
|
||||
find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
JSAMPLE colorlist[])
|
||||
_JSAMPLE colorlist[])
|
||||
/* Locate the colormap entries close enough to an update box to be candidates
|
||||
* for the nearest entry to some cell(s) in the update box. The update box
|
||||
* is specified by the center coordinates of its first cell. The number of
|
||||
@ -665,7 +669,7 @@ find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
|
||||
for (i = 0; i < numcolors; i++) {
|
||||
/* We compute the squared-c0-distance term, then add in the other two. */
|
||||
x = cinfo->colormap[0][i];
|
||||
x = ((_JSAMPARRAY)cinfo->colormap)[0][i];
|
||||
if (x < minc0) {
|
||||
tdist = (x - minc0) * C0_SCALE;
|
||||
min_dist = tdist * tdist;
|
||||
@ -688,7 +692,7 @@ find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
}
|
||||
}
|
||||
|
||||
x = cinfo->colormap[1][i];
|
||||
x = ((_JSAMPARRAY)cinfo->colormap)[1][i];
|
||||
if (x < minc1) {
|
||||
tdist = (x - minc1) * C1_SCALE;
|
||||
min_dist += tdist * tdist;
|
||||
@ -710,7 +714,7 @@ find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
}
|
||||
}
|
||||
|
||||
x = cinfo->colormap[2][i];
|
||||
x = ((_JSAMPARRAY)cinfo->colormap)[2][i];
|
||||
if (x < minc2) {
|
||||
tdist = (x - minc2) * C2_SCALE;
|
||||
min_dist += tdist * tdist;
|
||||
@ -744,7 +748,7 @@ find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
ncolors = 0;
|
||||
for (i = 0; i < numcolors; i++) {
|
||||
if (mindist[i] <= minmaxdist)
|
||||
colorlist[ncolors++] = (JSAMPLE)i;
|
||||
colorlist[ncolors++] = (_JSAMPLE)i;
|
||||
}
|
||||
return ncolors;
|
||||
}
|
||||
@ -752,7 +756,7 @@ find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
|
||||
LOCAL(void)
|
||||
find_best_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
|
||||
int numcolors, _JSAMPLE colorlist[], _JSAMPLE bestcolor[])
|
||||
/* Find the closest colormap entry for each cell in the update box,
|
||||
* given the list of candidate colors prepared by find_nearby_colors.
|
||||
* Return the indexes of the closest entries in the bestcolor[] array.
|
||||
@ -763,7 +767,7 @@ find_best_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
int ic0, ic1, ic2;
|
||||
int i, icolor;
|
||||
register JLONG *bptr; /* pointer into bestdist[] array */
|
||||
JSAMPLE *cptr; /* pointer into bestcolor[] array */
|
||||
_JSAMPLE *cptr; /* pointer into bestcolor[] array */
|
||||
JLONG dist0, dist1; /* initial distance values */
|
||||
register JLONG dist2; /* current distance in inner loop */
|
||||
JLONG xx0, xx1; /* distance increments */
|
||||
@ -790,11 +794,11 @@ find_best_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
for (i = 0; i < numcolors; i++) {
|
||||
icolor = colorlist[i];
|
||||
/* Compute (square of) distance from minc0/c1/c2 to this color */
|
||||
inc0 = (minc0 - cinfo->colormap[0][icolor]) * C0_SCALE;
|
||||
inc0 = (minc0 - ((_JSAMPARRAY)cinfo->colormap)[0][icolor]) * C0_SCALE;
|
||||
dist0 = inc0 * inc0;
|
||||
inc1 = (minc1 - cinfo->colormap[1][icolor]) * C1_SCALE;
|
||||
inc1 = (minc1 - ((_JSAMPARRAY)cinfo->colormap)[1][icolor]) * C1_SCALE;
|
||||
dist0 += inc1 * inc1;
|
||||
inc2 = (minc2 - cinfo->colormap[2][icolor]) * C2_SCALE;
|
||||
inc2 = (minc2 - ((_JSAMPARRAY)cinfo->colormap)[2][icolor]) * C2_SCALE;
|
||||
dist0 += inc2 * inc2;
|
||||
/* Form the initial difference increments */
|
||||
inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
|
||||
@ -813,7 +817,7 @@ find_best_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
for (ic2 = BOX_C2_ELEMS - 1; ic2 >= 0; ic2--) {
|
||||
if (dist2 < *bptr) {
|
||||
*bptr = dist2;
|
||||
*cptr = (JSAMPLE)icolor;
|
||||
*cptr = (_JSAMPLE)icolor;
|
||||
}
|
||||
dist2 += xx2;
|
||||
xx2 += 2 * STEP_C2 * STEP_C2;
|
||||
@ -840,13 +844,13 @@ fill_inverse_cmap(j_decompress_ptr cinfo, int c0, int c1, int c2)
|
||||
hist3d histogram = cquantize->histogram;
|
||||
int minc0, minc1, minc2; /* lower left corner of update box */
|
||||
int ic0, ic1, ic2;
|
||||
register JSAMPLE *cptr; /* pointer into bestcolor[] array */
|
||||
register _JSAMPLE *cptr; /* pointer into bestcolor[] array */
|
||||
register histptr cachep; /* pointer into main cache array */
|
||||
/* This array lists the candidate colormap indexes. */
|
||||
JSAMPLE colorlist[MAXNUMCOLORS];
|
||||
_JSAMPLE colorlist[MAXNUMCOLORS];
|
||||
int numcolors; /* number of candidate colors */
|
||||
/* This array holds the actually closest colormap index for each cell. */
|
||||
JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
|
||||
_JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
|
||||
|
||||
/* Convert cell coordinates to update box ID */
|
||||
c0 >>= BOX_C0_LOG;
|
||||
@ -891,13 +895,13 @@ fill_inverse_cmap(j_decompress_ptr cinfo, int c0, int c1, int c2)
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
pass2_no_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
pass2_no_dither(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPARRAY output_buf, int num_rows)
|
||||
/* This version performs no dithering */
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
|
||||
hist3d histogram = cquantize->histogram;
|
||||
register JSAMPROW inptr, outptr;
|
||||
register _JSAMPROW inptr, outptr;
|
||||
register histptr cachep;
|
||||
register int c0, c1, c2;
|
||||
int row;
|
||||
@ -918,15 +922,15 @@ pass2_no_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
if (*cachep == 0)
|
||||
fill_inverse_cmap(cinfo, c0, c1, c2);
|
||||
/* Now emit the colormap index for this cell */
|
||||
*outptr++ = (JSAMPLE)(*cachep - 1);
|
||||
*outptr++ = (_JSAMPLE)(*cachep - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
METHODDEF(void)
|
||||
pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
pass2_fs_dither(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
|
||||
_JSAMPARRAY output_buf, int num_rows)
|
||||
/* This version performs Floyd-Steinberg dithering */
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
|
||||
@ -935,19 +939,19 @@ pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
|
||||
LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
|
||||
register FSERRPTR errorptr; /* => fserrors[] at column before current */
|
||||
JSAMPROW inptr; /* => current input pixel */
|
||||
JSAMPROW outptr; /* => current output pixel */
|
||||
_JSAMPROW inptr; /* => current input pixel */
|
||||
_JSAMPROW outptr; /* => current output pixel */
|
||||
histptr cachep;
|
||||
int dir; /* +1 or -1 depending on direction */
|
||||
int dir3; /* 3*dir, for advancing inptr & errorptr */
|
||||
int row;
|
||||
JDIMENSION col;
|
||||
JDIMENSION width = cinfo->output_width;
|
||||
JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
_JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
|
||||
int *error_limit = cquantize->error_limiter;
|
||||
JSAMPROW colormap0 = cinfo->colormap[0];
|
||||
JSAMPROW colormap1 = cinfo->colormap[1];
|
||||
JSAMPROW colormap2 = cinfo->colormap[2];
|
||||
_JSAMPROW colormap0 = ((_JSAMPARRAY)cinfo->colormap)[0];
|
||||
_JSAMPROW colormap1 = ((_JSAMPARRAY)cinfo->colormap)[1];
|
||||
_JSAMPROW colormap2 = ((_JSAMPARRAY)cinfo->colormap)[2];
|
||||
SHIFT_TEMPS
|
||||
|
||||
for (row = 0; row < num_rows; row++) {
|
||||
@ -992,8 +996,8 @@ pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
cur0 = error_limit[cur0];
|
||||
cur1 = error_limit[cur1];
|
||||
cur2 = error_limit[cur2];
|
||||
/* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.
|
||||
* The maximum error is +- MAXJSAMPLE (or less with error limiting);
|
||||
/* Form pixel value + error, and range-limit to 0.._MAXJSAMPLE.
|
||||
* The maximum error is +- _MAXJSAMPLE (or less with error limiting);
|
||||
* this sets the required size of the range_limit array.
|
||||
*/
|
||||
cur0 += inptr[0];
|
||||
@ -1013,7 +1017,7 @@ pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
/* Now emit the colormap index for this cell */
|
||||
{
|
||||
register int pixcode = *cachep - 1;
|
||||
*outptr = (JSAMPLE)pixcode;
|
||||
*outptr = (_JSAMPLE)pixcode;
|
||||
/* Compute representation error for this pixel */
|
||||
cur0 -= colormap0[pixcode];
|
||||
cur1 -= colormap1[pixcode];
|
||||
@ -1064,7 +1068,7 @@ pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
/*
|
||||
* Initialize the error-limiting transfer function (lookup table).
|
||||
* The raw F-S error computation can potentially compute error values of up to
|
||||
* +- MAXJSAMPLE. But we want the maximum correction applied to a pixel to be
|
||||
* +- _MAXJSAMPLE. But we want the maximum correction applied to a pixel to be
|
||||
* much less, otherwise obviously wrong pixels will be created. (Typical
|
||||
* effects include weird fringes at color-area boundaries, isolated bright
|
||||
* pixels in a dark area, etc.) The standard advice for avoiding this problem
|
||||
@ -1073,7 +1077,7 @@ pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
* error buildup. However, that only prevents the error from getting
|
||||
* completely out of hand; Aaron Giles reports that error limiting improves
|
||||
* the results even with corner colors allocated.
|
||||
* A simple clamping of the error values to about +- MAXJSAMPLE/8 works pretty
|
||||
* A simple clamping of the error values to about +- _MAXJSAMPLE/8 works pretty
|
||||
* well, but the smoother transfer function used below is even better. Thanks
|
||||
* to Aaron Giles for this idea.
|
||||
*/
|
||||
@ -1087,22 +1091,22 @@ init_error_limit(j_decompress_ptr cinfo)
|
||||
int in, out;
|
||||
|
||||
table = (int *)(*cinfo->mem->alloc_small)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE, (MAXJSAMPLE * 2 + 1) * sizeof(int));
|
||||
table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE, (_MAXJSAMPLE * 2 + 1) * sizeof(int));
|
||||
table += _MAXJSAMPLE; /* so can index -_MAXJSAMPLE .. +_MAXJSAMPLE */
|
||||
cquantize->error_limiter = table;
|
||||
|
||||
#define STEPSIZE ((MAXJSAMPLE + 1) / 16)
|
||||
/* Map errors 1:1 up to +- MAXJSAMPLE/16 */
|
||||
#define STEPSIZE ((_MAXJSAMPLE + 1) / 16)
|
||||
/* Map errors 1:1 up to +- _MAXJSAMPLE/16 */
|
||||
out = 0;
|
||||
for (in = 0; in < STEPSIZE; in++, out++) {
|
||||
table[in] = out; table[-in] = -out;
|
||||
}
|
||||
/* Map errors 1:2 up to +- 3*MAXJSAMPLE/16 */
|
||||
/* Map errors 1:2 up to +- 3*_MAXJSAMPLE/16 */
|
||||
for (; in < STEPSIZE * 3; in++, out += (in & 1) ? 0 : 1) {
|
||||
table[in] = out; table[-in] = -out;
|
||||
}
|
||||
/* Clamp the rest to final out value (which is (MAXJSAMPLE+1)/8) */
|
||||
for (; in <= MAXJSAMPLE; in++) {
|
||||
/* Clamp the rest to final out value (which is (_MAXJSAMPLE+1)/8) */
|
||||
for (; in <= _MAXJSAMPLE; in++) {
|
||||
table[in] = out; table[-in] = -out;
|
||||
}
|
||||
#undef STEPSIZE
|
||||
@ -1119,7 +1123,7 @@ finish_pass1(j_decompress_ptr cinfo)
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
|
||||
|
||||
/* Select the representative colors and fill in cinfo->colormap */
|
||||
cinfo->colormap = cquantize->sv_colormap;
|
||||
cinfo->colormap = (JSAMPARRAY)cquantize->sv_colormap;
|
||||
select_colors(cinfo, cquantize->desired);
|
||||
/* Force next pass to zero the color index table */
|
||||
cquantize->needs_zeroed = TRUE;
|
||||
@ -1151,15 +1155,15 @@ start_pass_2_quant(j_decompress_ptr cinfo, boolean is_pre_scan)
|
||||
|
||||
if (is_pre_scan) {
|
||||
/* Set up method pointers */
|
||||
cquantize->pub.color_quantize = prescan_quantize;
|
||||
cquantize->pub._color_quantize = prescan_quantize;
|
||||
cquantize->pub.finish_pass = finish_pass1;
|
||||
cquantize->needs_zeroed = TRUE; /* Always zero histogram */
|
||||
} else {
|
||||
/* Set up method pointers */
|
||||
if (cinfo->dither_mode == JDITHER_FS)
|
||||
cquantize->pub.color_quantize = pass2_fs_dither;
|
||||
cquantize->pub._color_quantize = pass2_fs_dither;
|
||||
else
|
||||
cquantize->pub.color_quantize = pass2_no_dither;
|
||||
cquantize->pub._color_quantize = pass2_no_dither;
|
||||
cquantize->pub.finish_pass = finish_pass2;
|
||||
|
||||
/* Make sure color count is acceptable */
|
||||
@ -1215,11 +1219,14 @@ new_color_map_2_quant(j_decompress_ptr cinfo)
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_2pass_quantizer(j_decompress_ptr cinfo)
|
||||
_jinit_2pass_quantizer(j_decompress_ptr cinfo)
|
||||
{
|
||||
my_cquantize_ptr cquantize;
|
||||
int i;
|
||||
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
cquantize = (my_cquantize_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(my_cquantizer));
|
||||
@ -1230,7 +1237,8 @@ jinit_2pass_quantizer(j_decompress_ptr cinfo)
|
||||
cquantize->error_limiter = NULL;
|
||||
|
||||
/* Make sure jdmaster didn't give me a case I can't handle */
|
||||
if (cinfo->out_color_components != 3)
|
||||
if (cinfo->out_color_components != 3 ||
|
||||
cinfo->out_color_space == JCS_RGB565 || cinfo->master->lossless)
|
||||
ERREXIT(cinfo, JERR_NOTIMPL);
|
||||
|
||||
/* Allocate the histogram/inverse colormap storage */
|
||||
@ -1253,10 +1261,10 @@ jinit_2pass_quantizer(j_decompress_ptr cinfo)
|
||||
/* Lower bound on # of colors ... somewhat arbitrary as long as > 0 */
|
||||
if (desired < 8)
|
||||
ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
|
||||
/* Make sure colormap indexes can be represented by JSAMPLEs */
|
||||
/* Make sure colormap indexes can be represented by _JSAMPLEs */
|
||||
if (desired > MAXNUMCOLORS)
|
||||
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
|
||||
cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
|
||||
cquantize->sv_colormap = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE, (JDIMENSION)desired, (JDIMENSION)3);
|
||||
cquantize->desired = desired;
|
||||
} else
|
||||
@ -1282,4 +1290,4 @@ jinit_2pass_quantizer(j_decompress_ptr cinfo)
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* QUANT_2PASS_SUPPORTED */
|
||||
#endif /* defined(QUANT_2PASS_SUPPORTED) && BITS_IN_JSAMPLE != 16 */
|
||||
|
336
3rdparty/libjpeg-turbo/src/jsamplecomp.h
vendored
Normal file
336
3rdparty/libjpeg-turbo/src/jsamplecomp.h
vendored
Normal file
@ -0,0 +1,336 @@
|
||||
/*
|
||||
* jsamplecomp.h
|
||||
*
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*/
|
||||
|
||||
/* In source files that must be compiled for multiple data precisions, we
|
||||
* prefix all precision-dependent data types, macros, methods, fields, and
|
||||
* function names with an underscore. Including this file replaces those
|
||||
* precision-independent tokens with their precision-dependent equivalents,
|
||||
* based on the value of BITS_IN_JSAMPLE.
|
||||
*/
|
||||
|
||||
#ifndef JSAMPLECOMP_H
|
||||
#define JSAMPLECOMP_H
|
||||
|
||||
#if BITS_IN_JSAMPLE == 16
|
||||
|
||||
/* Sample data types and macros (jmorecfg.h) */
|
||||
#define _JSAMPLE J16SAMPLE
|
||||
|
||||
#define _MAXJSAMPLE MAXJ16SAMPLE
|
||||
#define _CENTERJSAMPLE CENTERJ16SAMPLE
|
||||
|
||||
#define _JSAMPROW J16SAMPROW
|
||||
#define _JSAMPARRAY J16SAMPARRAY
|
||||
#define _JSAMPIMAGE J16SAMPIMAGE
|
||||
|
||||
/* External functions (jpeglib.h) */
|
||||
#define _jpeg_write_scanlines jpeg16_write_scanlines
|
||||
#define _jpeg_read_scanlines jpeg16_read_scanlines
|
||||
|
||||
/* Internal methods (jpegint.h) */
|
||||
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
/* Use the 16-bit method in the jpeg_c_main_controller structure. */
|
||||
#define _process_data process_data_16
|
||||
/* Use the 16-bit method in the jpeg_c_prep_controller structure. */
|
||||
#define _pre_process_data pre_process_data_16
|
||||
/* Use the 16-bit method in the jpeg_c_coef_controller structure. */
|
||||
#define _compress_data compress_data_16
|
||||
/* Use the 16-bit method in the jpeg_color_converter structure. */
|
||||
#define _color_convert color_convert_16
|
||||
/* Use the 16-bit method in the jpeg_downsampler structure. */
|
||||
#define _downsample downsample_16
|
||||
#endif
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
/* Use the 16-bit method in the jpeg_d_main_controller structure. */
|
||||
#define _process_data process_data_16
|
||||
/* Use the 16-bit method in the jpeg_d_coef_controller structure. */
|
||||
#define _decompress_data decompress_data_16
|
||||
/* Use the 16-bit method in the jpeg_d_post_controller structure. */
|
||||
#define _post_process_data post_process_data_16
|
||||
/* Use the 16-bit method in the jpeg_upsampler structure. */
|
||||
#define _upsample upsample_16
|
||||
/* Use the 16-bit method in the jpeg_color_converter structure. */
|
||||
#define _color_convert color_convert_16
|
||||
#endif
|
||||
|
||||
/* Global internal functions (jpegint.h) */
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
#define _jinit_c_main_controller j16init_c_main_controller
|
||||
#define _jinit_c_prep_controller j16init_c_prep_controller
|
||||
#define _jinit_color_converter j16init_color_converter
|
||||
#define _jinit_downsampler j16init_downsampler
|
||||
#define _jinit_c_diff_controller j16init_c_diff_controller
|
||||
#define _jinit_lossless_compressor j16init_lossless_compressor
|
||||
#endif
|
||||
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
#define _jinit_d_main_controller j16init_d_main_controller
|
||||
#define _jinit_d_post_controller j16init_d_post_controller
|
||||
#define _jinit_upsampler j16init_upsampler
|
||||
#define _jinit_color_deconverter j16init_color_deconverter
|
||||
#define _jinit_merged_upsampler j16init_merged_upsampler
|
||||
#define _jinit_d_diff_controller j16init_d_diff_controller
|
||||
#define _jinit_lossless_decompressor j16init_lossless_decompressor
|
||||
#endif
|
||||
|
||||
#if defined(C_LOSSLESS_SUPPORTED) || defined(D_LOSSLESS_SUPPORTED)
|
||||
#define _jcopy_sample_rows j16copy_sample_rows
|
||||
#endif
|
||||
|
||||
/* Internal fields (cdjpeg.h) */
|
||||
|
||||
#if defined(C_LOSSLESS_SUPPORTED) || defined(D_LOSSLESS_SUPPORTED)
|
||||
/* Use the 16-bit buffer in the cjpeg_source_struct and djpeg_dest_struct
|
||||
structures. */
|
||||
#define _buffer buffer16
|
||||
#endif
|
||||
|
||||
/* Image I/O functions (cdjpeg.h) */
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
#define _jinit_read_gif j16init_read_gif
|
||||
#define _jinit_read_ppm j16init_read_ppm
|
||||
#endif
|
||||
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
#define _jinit_write_ppm j16init_write_ppm
|
||||
#endif
|
||||
|
||||
#elif BITS_IN_JSAMPLE == 12
|
||||
|
||||
/* Sample data types and macros (jmorecfg.h) */
|
||||
#define _JSAMPLE J12SAMPLE
|
||||
|
||||
#define _MAXJSAMPLE MAXJ12SAMPLE
|
||||
#define _CENTERJSAMPLE CENTERJ12SAMPLE
|
||||
|
||||
#define _JSAMPROW J12SAMPROW
|
||||
#define _JSAMPARRAY J12SAMPARRAY
|
||||
#define _JSAMPIMAGE J12SAMPIMAGE
|
||||
|
||||
/* External functions (jpeglib.h) */
|
||||
#define _jpeg_write_scanlines jpeg12_write_scanlines
|
||||
#define _jpeg_write_raw_data jpeg12_write_raw_data
|
||||
#define _jpeg_read_scanlines jpeg12_read_scanlines
|
||||
#define _jpeg_skip_scanlines jpeg12_skip_scanlines
|
||||
#define _jpeg_crop_scanline jpeg12_crop_scanline
|
||||
#define _jpeg_read_raw_data jpeg12_read_raw_data
|
||||
|
||||
/* Internal methods (jpegint.h) */
|
||||
|
||||
/* Use the 12-bit method in the jpeg_c_main_controller structure. */
|
||||
#define _process_data process_data_12
|
||||
/* Use the 12-bit method in the jpeg_c_prep_controller structure. */
|
||||
#define _pre_process_data pre_process_data_12
|
||||
/* Use the 12-bit method in the jpeg_c_coef_controller structure. */
|
||||
#define _compress_data compress_data_12
|
||||
/* Use the 12-bit method in the jpeg_color_converter structure. */
|
||||
#define _color_convert color_convert_12
|
||||
/* Use the 12-bit method in the jpeg_downsampler structure. */
|
||||
#define _downsample downsample_12
|
||||
/* Use the 12-bit method in the jpeg_forward_dct structure. */
|
||||
#define _forward_DCT forward_DCT_12
|
||||
/* Use the 12-bit method in the jpeg_d_main_controller structure. */
|
||||
#define _process_data process_data_12
|
||||
/* Use the 12-bit method in the jpeg_d_coef_controller structure. */
|
||||
#define _decompress_data decompress_data_12
|
||||
/* Use the 12-bit method in the jpeg_d_post_controller structure. */
|
||||
#define _post_process_data post_process_data_12
|
||||
/* Use the 12-bit method in the jpeg_inverse_dct structure. */
|
||||
#define _inverse_DCT_method_ptr inverse_DCT_12_method_ptr
|
||||
#define _inverse_DCT inverse_DCT_12
|
||||
/* Use the 12-bit method in the jpeg_upsampler structure. */
|
||||
#define _upsample upsample_12
|
||||
/* Use the 12-bit method in the jpeg_color_converter structure. */
|
||||
#define _color_convert color_convert_12
|
||||
/* Use the 12-bit method in the jpeg_color_quantizer structure. */
|
||||
#define _color_quantize color_quantize_12
|
||||
|
||||
/* Global internal functions (jpegint.h) */
|
||||
#define _jinit_c_main_controller j12init_c_main_controller
|
||||
#define _jinit_c_prep_controller j12init_c_prep_controller
|
||||
#define _jinit_c_coef_controller j12init_c_coef_controller
|
||||
#define _jinit_color_converter j12init_color_converter
|
||||
#define _jinit_downsampler j12init_downsampler
|
||||
#define _jinit_forward_dct j12init_forward_dct
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
#define _jinit_c_diff_controller j12init_c_diff_controller
|
||||
#define _jinit_lossless_compressor j12init_lossless_compressor
|
||||
#endif
|
||||
|
||||
#define _jinit_d_main_controller j12init_d_main_controller
|
||||
#define _jinit_d_coef_controller j12init_d_coef_controller
|
||||
#define _jinit_d_post_controller j12init_d_post_controller
|
||||
#define _jinit_inverse_dct j12init_inverse_dct
|
||||
#define _jinit_upsampler j12init_upsampler
|
||||
#define _jinit_color_deconverter j12init_color_deconverter
|
||||
#define _jinit_1pass_quantizer j12init_1pass_quantizer
|
||||
#define _jinit_2pass_quantizer j12init_2pass_quantizer
|
||||
#define _jinit_merged_upsampler j12init_merged_upsampler
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
#define _jinit_d_diff_controller j12init_d_diff_controller
|
||||
#define _jinit_lossless_decompressor j12init_lossless_decompressor
|
||||
#endif
|
||||
|
||||
#define _jcopy_sample_rows j12copy_sample_rows
|
||||
|
||||
/* Global internal functions (jdct.h) */
|
||||
#define _jpeg_fdct_islow jpeg12_fdct_islow
|
||||
#define _jpeg_fdct_ifast jpeg12_fdct_ifast
|
||||
|
||||
#define _jpeg_idct_islow jpeg12_idct_islow
|
||||
#define _jpeg_idct_ifast jpeg12_idct_ifast
|
||||
#define _jpeg_idct_float jpeg12_idct_float
|
||||
#define _jpeg_idct_7x7 jpeg12_idct_7x7
|
||||
#define _jpeg_idct_6x6 jpeg12_idct_6x6
|
||||
#define _jpeg_idct_5x5 jpeg12_idct_5x5
|
||||
#define _jpeg_idct_4x4 jpeg12_idct_4x4
|
||||
#define _jpeg_idct_3x3 jpeg12_idct_3x3
|
||||
#define _jpeg_idct_2x2 jpeg12_idct_2x2
|
||||
#define _jpeg_idct_1x1 jpeg12_idct_1x1
|
||||
#define _jpeg_idct_9x9 jpeg12_idct_9x9
|
||||
#define _jpeg_idct_10x10 jpeg12_idct_10x10
|
||||
#define _jpeg_idct_11x11 jpeg12_idct_11x11
|
||||
#define _jpeg_idct_12x12 jpeg12_idct_12x12
|
||||
#define _jpeg_idct_13x13 jpeg12_idct_13x13
|
||||
#define _jpeg_idct_14x14 jpeg12_idct_14x14
|
||||
#define _jpeg_idct_15x15 jpeg12_idct_15x15
|
||||
#define _jpeg_idct_16x16 jpeg12_idct_16x16
|
||||
|
||||
/* Internal fields (cdjpeg.h) */
|
||||
|
||||
/* Use the 12-bit buffer in the cjpeg_source_struct and djpeg_dest_struct
|
||||
structures. */
|
||||
#define _buffer buffer12
|
||||
|
||||
/* Image I/O functions (cdjpeg.h) */
|
||||
#define _jinit_read_gif j12init_read_gif
|
||||
#define _jinit_write_gif j12init_write_gif
|
||||
#define _jinit_read_ppm j12init_read_ppm
|
||||
#define _jinit_write_ppm j12init_write_ppm
|
||||
|
||||
#define _read_color_map read_color_map_12
|
||||
|
||||
#else /* BITS_IN_JSAMPLE */
|
||||
|
||||
/* Sample data types and macros (jmorecfg.h) */
|
||||
#define _JSAMPLE JSAMPLE
|
||||
|
||||
#define _MAXJSAMPLE MAXJSAMPLE
|
||||
#define _CENTERJSAMPLE CENTERJSAMPLE
|
||||
|
||||
#define _JSAMPROW JSAMPROW
|
||||
#define _JSAMPARRAY JSAMPARRAY
|
||||
#define _JSAMPIMAGE JSAMPIMAGE
|
||||
|
||||
/* External functions (jpeglib.h) */
|
||||
#define _jpeg_write_scanlines jpeg_write_scanlines
|
||||
#define _jpeg_write_raw_data jpeg_write_raw_data
|
||||
#define _jpeg_read_scanlines jpeg_read_scanlines
|
||||
#define _jpeg_skip_scanlines jpeg_skip_scanlines
|
||||
#define _jpeg_crop_scanline jpeg_crop_scanline
|
||||
#define _jpeg_read_raw_data jpeg_read_raw_data
|
||||
|
||||
/* Internal methods (jpegint.h) */
|
||||
|
||||
/* Use the 8-bit method in the jpeg_c_main_controller structure. */
|
||||
#define _process_data process_data
|
||||
/* Use the 8-bit method in the jpeg_c_prep_controller structure. */
|
||||
#define _pre_process_data pre_process_data
|
||||
/* Use the 8-bit method in the jpeg_c_coef_controller structure. */
|
||||
#define _compress_data compress_data
|
||||
/* Use the 8-bit method in the jpeg_color_converter structure. */
|
||||
#define _color_convert color_convert
|
||||
/* Use the 8-bit method in the jpeg_downsampler structure. */
|
||||
#define _downsample downsample
|
||||
/* Use the 8-bit method in the jpeg_forward_dct structure. */
|
||||
#define _forward_DCT forward_DCT
|
||||
/* Use the 8-bit method in the jpeg_d_main_controller structure. */
|
||||
#define _process_data process_data
|
||||
/* Use the 8-bit method in the jpeg_d_coef_controller structure. */
|
||||
#define _decompress_data decompress_data
|
||||
/* Use the 8-bit method in the jpeg_d_post_controller structure. */
|
||||
#define _post_process_data post_process_data
|
||||
/* Use the 8-bit method in the jpeg_inverse_dct structure. */
|
||||
#define _inverse_DCT_method_ptr inverse_DCT_method_ptr
|
||||
#define _inverse_DCT inverse_DCT
|
||||
/* Use the 8-bit method in the jpeg_upsampler structure. */
|
||||
#define _upsample upsample
|
||||
/* Use the 8-bit method in the jpeg_color_converter structure. */
|
||||
#define _color_convert color_convert
|
||||
/* Use the 8-bit method in the jpeg_color_quantizer structure. */
|
||||
#define _color_quantize color_quantize
|
||||
|
||||
/* Global internal functions (jpegint.h) */
|
||||
#define _jinit_c_main_controller jinit_c_main_controller
|
||||
#define _jinit_c_prep_controller jinit_c_prep_controller
|
||||
#define _jinit_c_coef_controller jinit_c_coef_controller
|
||||
#define _jinit_color_converter jinit_color_converter
|
||||
#define _jinit_downsampler jinit_downsampler
|
||||
#define _jinit_forward_dct jinit_forward_dct
|
||||
#ifdef C_LOSSLESS_SUPPORTED
|
||||
#define _jinit_c_diff_controller jinit_c_diff_controller
|
||||
#define _jinit_lossless_compressor jinit_lossless_compressor
|
||||
#endif
|
||||
|
||||
#define _jinit_d_main_controller jinit_d_main_controller
|
||||
#define _jinit_d_coef_controller jinit_d_coef_controller
|
||||
#define _jinit_d_post_controller jinit_d_post_controller
|
||||
#define _jinit_inverse_dct jinit_inverse_dct
|
||||
#define _jinit_upsampler jinit_upsampler
|
||||
#define _jinit_color_deconverter jinit_color_deconverter
|
||||
#define _jinit_1pass_quantizer jinit_1pass_quantizer
|
||||
#define _jinit_2pass_quantizer jinit_2pass_quantizer
|
||||
#define _jinit_merged_upsampler jinit_merged_upsampler
|
||||
#ifdef D_LOSSLESS_SUPPORTED
|
||||
#define _jinit_d_diff_controller jinit_d_diff_controller
|
||||
#define _jinit_lossless_decompressor jinit_lossless_decompressor
|
||||
#endif
|
||||
|
||||
#define _jcopy_sample_rows jcopy_sample_rows
|
||||
|
||||
/* Global internal functions (jdct.h) */
|
||||
#define _jpeg_fdct_islow jpeg_fdct_islow
|
||||
#define _jpeg_fdct_ifast jpeg_fdct_ifast
|
||||
|
||||
#define _jpeg_idct_islow jpeg_idct_islow
|
||||
#define _jpeg_idct_ifast jpeg_idct_ifast
|
||||
#define _jpeg_idct_float jpeg_idct_float
|
||||
#define _jpeg_idct_7x7 jpeg_idct_7x7
|
||||
#define _jpeg_idct_6x6 jpeg_idct_6x6
|
||||
#define _jpeg_idct_5x5 jpeg_idct_5x5
|
||||
#define _jpeg_idct_4x4 jpeg_idct_4x4
|
||||
#define _jpeg_idct_3x3 jpeg_idct_3x3
|
||||
#define _jpeg_idct_2x2 jpeg_idct_2x2
|
||||
#define _jpeg_idct_1x1 jpeg_idct_1x1
|
||||
#define _jpeg_idct_9x9 jpeg_idct_9x9
|
||||
#define _jpeg_idct_10x10 jpeg_idct_10x10
|
||||
#define _jpeg_idct_11x11 jpeg_idct_11x11
|
||||
#define _jpeg_idct_12x12 jpeg_idct_12x12
|
||||
#define _jpeg_idct_13x13 jpeg_idct_13x13
|
||||
#define _jpeg_idct_14x14 jpeg_idct_14x14
|
||||
#define _jpeg_idct_15x15 jpeg_idct_15x15
|
||||
#define _jpeg_idct_16x16 jpeg_idct_16x16
|
||||
|
||||
/* Internal fields (cdjpeg.h) */
|
||||
|
||||
/* Use the 8-bit buffer in the cjpeg_source_struct and djpeg_dest_struct
|
||||
structures. */
|
||||
#define _buffer buffer
|
||||
|
||||
/* Image I/O functions (cdjpeg.h) */
|
||||
#define _jinit_read_gif jinit_read_gif
|
||||
#define _jinit_write_gif jinit_write_gif
|
||||
#define _jinit_read_ppm jinit_read_ppm
|
||||
#define _jinit_write_ppm jinit_write_ppm
|
||||
|
||||
#define _read_color_map read_color_map
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE */
|
||||
|
||||
#endif /* JSAMPLECOMP_H */
|
12
3rdparty/libjpeg-turbo/src/jsimd.h
vendored
12
3rdparty/libjpeg-turbo/src/jsimd.h
vendored
@ -2,8 +2,8 @@
|
||||
* jsimd.h
|
||||
*
|
||||
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
||||
* Copyright (C) 2011, 2014, D. R. Commander.
|
||||
* Copyright (C) 2015-2016, 2018, Matthieu Darbois.
|
||||
* Copyright (C) 2011, 2014, 2022, D. R. Commander.
|
||||
* Copyright (C) 2015-2016, 2018, 2022, Matthieu Darbois.
|
||||
* Copyright (C) 2020, Arm Limited.
|
||||
*
|
||||
* Based on the x86 SIMD extension for IJG JPEG library,
|
||||
@ -12,6 +12,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef WITH_SIMD
|
||||
|
||||
#include "jchuff.h" /* Declarations shared with jcphuff.c */
|
||||
|
||||
EXTERN(int) jsimd_can_rgb_ycc(void);
|
||||
@ -114,10 +116,12 @@ EXTERN(int) jsimd_can_encode_mcu_AC_first_prepare(void);
|
||||
|
||||
EXTERN(void) jsimd_encode_mcu_AC_first_prepare
|
||||
(const JCOEF *block, const int *jpeg_natural_order_start, int Sl, int Al,
|
||||
JCOEF *values, size_t *zerobits);
|
||||
UJCOEF *values, size_t *zerobits);
|
||||
|
||||
EXTERN(int) jsimd_can_encode_mcu_AC_refine_prepare(void);
|
||||
|
||||
EXTERN(int) jsimd_encode_mcu_AC_refine_prepare
|
||||
(const JCOEF *block, const int *jpeg_natural_order_start, int Sl, int Al,
|
||||
JCOEF *absvalues, size_t *bits);
|
||||
UJCOEF *absvalues, size_t *bits);
|
||||
|
||||
#endif /* WITH_SIMD */
|
||||
|
431
3rdparty/libjpeg-turbo/src/jsimd_none.c
vendored
431
3rdparty/libjpeg-turbo/src/jsimd_none.c
vendored
@ -1,431 +0,0 @@
|
||||
/*
|
||||
* jsimd_none.c
|
||||
*
|
||||
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
||||
* Copyright (C) 2009-2011, 2014, D. R. Commander.
|
||||
* Copyright (C) 2015-2016, 2018, Matthieu Darbois.
|
||||
* Copyright (C) 2020, Arm Limited.
|
||||
*
|
||||
* Based on the x86 SIMD extension for IJG JPEG library,
|
||||
* Copyright (C) 1999-2006, MIYASAKA Masaru.
|
||||
* For conditions of distribution and use, see copyright notice in jsimdext.inc
|
||||
*
|
||||
* This file contains stubs for when there is no SIMD support available.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jsimd.h"
|
||||
#include "jdct.h"
|
||||
#include "jsimddct.h"
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_rgb_ycc(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_rgb_gray(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_ycc_rgb(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_ycc_rgb565(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_c_can_null_convert(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPIMAGE output_buf, JDIMENSION output_row,
|
||||
int num_rows)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPIMAGE output_buf, JDIMENSION output_row,
|
||||
int num_rows)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf,
|
||||
int num_rows)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION input_row, JSAMPARRAY output_buf,
|
||||
int num_rows)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_c_null_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPIMAGE output_buf, JDIMENSION output_row,
|
||||
int num_rows)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_h2v2_downsample(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_h2v1_downsample(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_h2v2_smooth_downsample(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_h2v2_smooth_downsample(j_compress_ptr cinfo,
|
||||
jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_h2v2_upsample(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_h2v1_upsample(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_int_upsample(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_h2v2_fancy_upsample(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_h2v1_fancy_upsample(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_h1v2_fancy_upsample(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_h2v2_merged_upsample(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_h2v1_merged_upsample(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
|
||||
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_convsamp(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_convsamp_float(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_convsamp(JSAMPARRAY sample_data, JDIMENSION start_col,
|
||||
DCTELEM *workspace)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
|
||||
FAST_FLOAT *workspace)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_fdct_islow(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_fdct_ifast(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_fdct_float(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_fdct_islow(DCTELEM *data)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_fdct_ifast(DCTELEM *data)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_fdct_float(FAST_FLOAT *data)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_quantize(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_quantize_float(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_quantize(JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
|
||||
FAST_FLOAT *workspace)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_idct_2x2(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_idct_4x4(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_idct_6x6(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_idct_12x12(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_idct_6x6(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_idct_12x12(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_idct_islow(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_idct_ifast(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_idct_float(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf,
|
||||
JDIMENSION output_col)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_huff_encode_one_block(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(JOCTET *)
|
||||
jsimd_huff_encode_one_block(void *state, JOCTET *buffer, JCOEFPTR block,
|
||||
int last_dc_val, c_derived_tbl *dctbl,
|
||||
c_derived_tbl *actbl)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_encode_mcu_AC_first_prepare(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jsimd_encode_mcu_AC_first_prepare(const JCOEF *block,
|
||||
const int *jpeg_natural_order_start, int Sl,
|
||||
int Al, JCOEF *values, size_t *zerobits)
|
||||
{
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_can_encode_mcu_AC_refine_prepare(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLOBAL(int)
|
||||
jsimd_encode_mcu_AC_refine_prepare(const JCOEF *block,
|
||||
const int *jpeg_natural_order_start, int Sl,
|
||||
int Al, JCOEF *absvalues, size_t *bits)
|
||||
{
|
||||
return 0;
|
||||
}
|
25
3rdparty/libjpeg-turbo/src/jutils.c
vendored
25
3rdparty/libjpeg-turbo/src/jutils.c
vendored
@ -17,8 +17,11 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
|
||||
/*
|
||||
* jpeg_zigzag_order[i] is the zigzag-order position of the i'th element
|
||||
* of a DCT block read in natural order (left to right, top to bottom).
|
||||
@ -89,19 +92,24 @@ jround_up(long a, long b)
|
||||
return a - (a % b);
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE == 8 */
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE != 16 || \
|
||||
defined(C_LOSSLESS_SUPPORTED) || defined(D_LOSSLESS_SUPPORTED)
|
||||
|
||||
GLOBAL(void)
|
||||
jcopy_sample_rows(JSAMPARRAY input_array, int source_row,
|
||||
JSAMPARRAY output_array, int dest_row, int num_rows,
|
||||
JDIMENSION num_cols)
|
||||
_jcopy_sample_rows(_JSAMPARRAY input_array, int source_row,
|
||||
_JSAMPARRAY output_array, int dest_row, int num_rows,
|
||||
JDIMENSION num_cols)
|
||||
/* Copy some rows of samples from one place to another.
|
||||
* num_rows rows are copied from input_array[source_row++]
|
||||
* to output_array[dest_row++]; these areas may overlap for duplication.
|
||||
* The source and destination arrays must be at least as wide as num_cols.
|
||||
*/
|
||||
{
|
||||
register JSAMPROW inptr, outptr;
|
||||
register size_t count = (size_t)(num_cols * sizeof(JSAMPLE));
|
||||
register _JSAMPROW inptr, outptr;
|
||||
register size_t count = (size_t)(num_cols * sizeof(_JSAMPLE));
|
||||
register int row;
|
||||
|
||||
input_array += source_row;
|
||||
@ -114,6 +122,11 @@ jcopy_sample_rows(JSAMPARRAY input_array, int source_row,
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE != 16 ||
|
||||
defined(C_LOSSLESS_SUPPORTED) || defined(D_LOSSLESS_SUPPORTED) */
|
||||
|
||||
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
|
||||
GLOBAL(void)
|
||||
jcopy_block_row(JBLOCKROW input_row, JBLOCKROW output_row,
|
||||
@ -131,3 +144,5 @@ jzero_far(void *target, size_t bytestozero)
|
||||
{
|
||||
memset(target, 0, bytestozero);
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE == 8 */
|
||||
|
12
3rdparty/libjpeg-turbo/src/jversion.h.in
vendored
12
3rdparty/libjpeg-turbo/src/jversion.h.in
vendored
@ -4,7 +4,7 @@
|
||||
* 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-2022, D. R. Commander.
|
||||
* Copyright (C) 2010, 2012-2024, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
@ -36,19 +36,21 @@
|
||||
* their code
|
||||
*/
|
||||
|
||||
#define JCOPYRIGHT \
|
||||
"Copyright (C) 2009-2022 D. R. Commander\n" \
|
||||
#define JCOPYRIGHT1 \
|
||||
"Copyright (C) 2009-2024 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) 2011-2016 Siarhei Siamashka\n" \
|
||||
"Copyright (C) 2015 Intel Corporation\n" \
|
||||
"Copyright (C) 2015 Intel Corporation\n"
|
||||
#define JCOPYRIGHT2 \
|
||||
"Copyright (C) 2013-2014 Linaro Limited\n" \
|
||||
"Copyright (C) 2013-2014 MIPS Technologies, Inc.\n" \
|
||||
"Copyright (C) 2009, 2012 Pierre Ossman for Cendio AB\n" \
|
||||
"Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)\n" \
|
||||
"Copyright (C) 1999-2006 MIYASAKA Masaru\n" \
|
||||
"Copyright (C) 1991-2020 Thomas G. Lane, Guido Vollbeding"
|
||||
"Copyright (C) 1999 Ken Murchison\n" \
|
||||
"Copyright (C) 1991-2020 Thomas G. Lane, Guido Vollbeding\n"
|
||||
|
||||
#define JCOPYRIGHT_SHORT \
|
||||
"Copyright (C) @COPYRIGHT_YEAR@ The libjpeg-turbo Project and many others"
|
||||
|
11
3rdparty/libjpeg-turbo/src/libjpeg.map.in
vendored
Normal file
11
3rdparty/libjpeg-turbo/src/libjpeg.map.in
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
LIBJPEGTURBO_@JPEG_LIB_VERSION_DECIMAL@ {
|
||||
@MEM_SRCDST_FUNCTIONS@
|
||||
local:
|
||||
jsimd_*;
|
||||
jconst_*;
|
||||
};
|
||||
|
||||
LIBJPEG_@JPEG_LIB_VERSION_DECIMAL@ {
|
||||
global:
|
||||
*;
|
||||
};
|
3282
3rdparty/libjpeg-turbo/src/libjpeg.txt
vendored
Normal file
3282
3rdparty/libjpeg-turbo/src/libjpeg.txt
vendored
Normal file
File diff suppressed because it is too large
Load Diff
689
3rdparty/libjpeg-turbo/src/rdbmp.c
vendored
Normal file
689
3rdparty/libjpeg-turbo/src/rdbmp.c
vendored
Normal file
@ -0,0 +1,689 @@
|
||||
/*
|
||||
* rdbmp.c
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* Modified 2009-2017 by Guido Vollbeding.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Modified 2011 by Siarhei Siamashka.
|
||||
* Copyright (C) 2015, 2017-2018, 2021-2023, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file contains routines to read input images in Microsoft "BMP"
|
||||
* format (MS Windows 3.x, OS/2 1.x, and OS/2 2.x flavors).
|
||||
* Currently, only 8-, 24-, and 32-bit images are supported, not 1-bit or
|
||||
* 4-bit (feeding such low-depth images into JPEG would be silly anyway).
|
||||
* Also, we don't support RLE-compressed files.
|
||||
*
|
||||
* These routines may need modification for non-Unix environments or
|
||||
* specialized applications. As they stand, they assume input from
|
||||
* an ordinary stdio stream. They further assume that reading begins
|
||||
* at the start of the file; start_input may need work if the
|
||||
* user interface has already read some data (e.g., to determine that
|
||||
* the file is indeed BMP format).
|
||||
*
|
||||
* This code contributed by James Arthur Boucher.
|
||||
*/
|
||||
|
||||
#include "cmyk.h"
|
||||
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
|
||||
|
||||
#ifdef BMP_SUPPORTED
|
||||
|
||||
|
||||
/* Macros to deal with unsigned chars as efficiently as compiler allows */
|
||||
|
||||
typedef unsigned char U_CHAR;
|
||||
#define UCH(x) ((int)(x))
|
||||
|
||||
|
||||
#define ReadOK(file, buffer, 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
|
||||
};
|
||||
|
||||
|
||||
/* Private version of data source object */
|
||||
|
||||
typedef struct _bmp_source_struct *bmp_source_ptr;
|
||||
|
||||
typedef struct _bmp_source_struct {
|
||||
struct cjpeg_source_struct pub; /* public fields */
|
||||
|
||||
j_compress_ptr cinfo; /* back link saves passing separate parm */
|
||||
|
||||
JSAMPARRAY colormap; /* BMP colormap (converted to my format) */
|
||||
|
||||
jvirt_sarray_ptr whole_image; /* Needed to reverse row order */
|
||||
JDIMENSION source_row; /* Current source row number */
|
||||
JDIMENSION row_width; /* Physical width of scanlines in file */
|
||||
|
||||
int bits_per_pixel; /* remembers 8-, 24-, or 32-bit format */
|
||||
int cmap_length; /* colormap length */
|
||||
|
||||
boolean use_inversion_array; /* TRUE = preload the whole image, which is
|
||||
stored in bottom-up order, and feed it to
|
||||
the calling program in top-down order
|
||||
|
||||
FALSE = the calling program will maintain
|
||||
its own image buffer and read the rows in
|
||||
bottom-up order */
|
||||
|
||||
U_CHAR *iobuffer; /* I/O buffer (used to buffer a single row from
|
||||
disk if use_inversion_array == FALSE) */
|
||||
} bmp_source_struct;
|
||||
|
||||
|
||||
LOCAL(int)
|
||||
read_byte(bmp_source_ptr sinfo)
|
||||
/* Read next byte from BMP file */
|
||||
{
|
||||
register FILE *infile = sinfo->pub.input_file;
|
||||
register int c;
|
||||
|
||||
if ((c = getc(infile)) == EOF)
|
||||
ERREXIT(sinfo->cinfo, JERR_INPUT_EOF);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
read_colormap(bmp_source_ptr sinfo, int cmaplen, int mapentrysize)
|
||||
/* Read the colormap from a BMP file */
|
||||
{
|
||||
int i, gray = 1;
|
||||
|
||||
switch (mapentrysize) {
|
||||
case 3:
|
||||
/* BGR format (occurs in OS/2 files) */
|
||||
for (i = 0; i < cmaplen; i++) {
|
||||
sinfo->colormap[2][i] = (JSAMPLE)read_byte(sinfo);
|
||||
sinfo->colormap[1][i] = (JSAMPLE)read_byte(sinfo);
|
||||
sinfo->colormap[0][i] = (JSAMPLE)read_byte(sinfo);
|
||||
if (sinfo->colormap[2][i] != sinfo->colormap[1][i] ||
|
||||
sinfo->colormap[1][i] != sinfo->colormap[0][i])
|
||||
gray = 0;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
/* BGR0 format (occurs in MS Windows files) */
|
||||
for (i = 0; i < cmaplen; i++) {
|
||||
sinfo->colormap[2][i] = (JSAMPLE)read_byte(sinfo);
|
||||
sinfo->colormap[1][i] = (JSAMPLE)read_byte(sinfo);
|
||||
sinfo->colormap[0][i] = (JSAMPLE)read_byte(sinfo);
|
||||
(void)read_byte(sinfo);
|
||||
if (sinfo->colormap[2][i] != sinfo->colormap[1][i] ||
|
||||
sinfo->colormap[1][i] != sinfo->colormap[0][i])
|
||||
gray = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ERREXIT(sinfo->cinfo, JERR_BMP_BADCMAP);
|
||||
break;
|
||||
}
|
||||
|
||||
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)
|
||||
ERREXIT(sinfo->cinfo, JERR_BAD_IN_COLORSPACE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Read one row of pixels.
|
||||
* The image has been read into the whole_image array, but is otherwise
|
||||
* unprocessed. We must read it out in top-to-bottom row order, and if
|
||||
* it is an 8-bit image, we must expand colormapped pixels to 24bit format.
|
||||
*/
|
||||
|
||||
METHODDEF(JDIMENSION)
|
||||
get_8bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
||||
/* This version is for reading 8-bit colormap indexes */
|
||||
{
|
||||
bmp_source_ptr source = (bmp_source_ptr)sinfo;
|
||||
register JSAMPARRAY colormap = source->colormap;
|
||||
int cmaplen = source->cmap_length;
|
||||
JSAMPARRAY image_ptr;
|
||||
register int t;
|
||||
register JSAMPROW inptr, outptr;
|
||||
register JDIMENSION col;
|
||||
|
||||
if (source->use_inversion_array) {
|
||||
/* Fetch next row from virtual array */
|
||||
source->source_row--;
|
||||
image_ptr = (*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr)cinfo, source->whole_image,
|
||||
source->source_row, (JDIMENSION)1, FALSE);
|
||||
inptr = image_ptr[0];
|
||||
} else {
|
||||
if (!ReadOK(source->pub.input_file, source->iobuffer, source->row_width))
|
||||
ERREXIT(cinfo, JERR_INPUT_EOF);
|
||||
inptr = source->iobuffer;
|
||||
}
|
||||
|
||||
/* Expand the colormap indexes to real data */
|
||||
outptr = source->pub.buffer[0];
|
||||
if (cinfo->in_color_space == JCS_GRAYSCALE) {
|
||||
for (col = cinfo->image_width; col > 0; col--) {
|
||||
t = *inptr++;
|
||||
if (t >= cmaplen)
|
||||
ERREXIT(cinfo, JERR_BMP_OUTOFRANGE);
|
||||
*outptr++ = colormap[0][t];
|
||||
}
|
||||
} else if (cinfo->in_color_space == JCS_CMYK) {
|
||||
for (col = cinfo->image_width; col > 0; col--) {
|
||||
t = *inptr++;
|
||||
if (t >= cmaplen)
|
||||
ERREXIT(cinfo, JERR_BMP_OUTOFRANGE);
|
||||
rgb_to_cmyk(colormap[0][t], colormap[1][t], colormap[2][t], outptr,
|
||||
outptr + 1, outptr + 2, outptr + 3);
|
||||
outptr += 4;
|
||||
}
|
||||
} else {
|
||||
register int rindex = rgb_red[cinfo->in_color_space];
|
||||
register int gindex = rgb_green[cinfo->in_color_space];
|
||||
register int bindex = rgb_blue[cinfo->in_color_space];
|
||||
register int aindex = alpha_index[cinfo->in_color_space];
|
||||
register int ps = rgb_pixelsize[cinfo->in_color_space];
|
||||
|
||||
if (aindex >= 0) {
|
||||
for (col = cinfo->image_width; col > 0; col--) {
|
||||
t = *inptr++;
|
||||
if (t >= cmaplen)
|
||||
ERREXIT(cinfo, JERR_BMP_OUTOFRANGE);
|
||||
outptr[rindex] = colormap[0][t];
|
||||
outptr[gindex] = colormap[1][t];
|
||||
outptr[bindex] = colormap[2][t];
|
||||
outptr[aindex] = 0xFF;
|
||||
outptr += ps;
|
||||
}
|
||||
} else {
|
||||
for (col = cinfo->image_width; col > 0; col--) {
|
||||
t = *inptr++;
|
||||
if (t >= cmaplen)
|
||||
ERREXIT(cinfo, JERR_BMP_OUTOFRANGE);
|
||||
outptr[rindex] = colormap[0][t];
|
||||
outptr[gindex] = colormap[1][t];
|
||||
outptr[bindex] = colormap[2][t];
|
||||
outptr += ps;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
METHODDEF(JDIMENSION)
|
||||
get_24bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
||||
/* This version is for reading 24-bit pixels */
|
||||
{
|
||||
bmp_source_ptr source = (bmp_source_ptr)sinfo;
|
||||
JSAMPARRAY image_ptr;
|
||||
register JSAMPROW inptr, outptr;
|
||||
register JDIMENSION col;
|
||||
|
||||
if (source->use_inversion_array) {
|
||||
/* Fetch next row from virtual array */
|
||||
source->source_row--;
|
||||
image_ptr = (*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr)cinfo, source->whole_image,
|
||||
source->source_row, (JDIMENSION)1, FALSE);
|
||||
inptr = image_ptr[0];
|
||||
} else {
|
||||
if (!ReadOK(source->pub.input_file, source->iobuffer, source->row_width))
|
||||
ERREXIT(cinfo, JERR_INPUT_EOF);
|
||||
inptr = source->iobuffer;
|
||||
}
|
||||
|
||||
/* Transfer data. Note source values are in BGR order
|
||||
* (even though Microsoft's own documents say the opposite).
|
||||
*/
|
||||
outptr = source->pub.buffer[0];
|
||||
if (cinfo->in_color_space == JCS_EXT_BGR) {
|
||||
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++;
|
||||
rgb_to_cmyk(r, g, b, outptr, outptr + 1, outptr + 2, outptr + 3);
|
||||
outptr += 4;
|
||||
}
|
||||
} else {
|
||||
register int rindex = rgb_red[cinfo->in_color_space];
|
||||
register int gindex = rgb_green[cinfo->in_color_space];
|
||||
register int bindex = rgb_blue[cinfo->in_color_space];
|
||||
register int aindex = alpha_index[cinfo->in_color_space];
|
||||
register int ps = rgb_pixelsize[cinfo->in_color_space];
|
||||
|
||||
if (aindex >= 0) {
|
||||
for (col = cinfo->image_width; col > 0; col--) {
|
||||
outptr[bindex] = *inptr++;
|
||||
outptr[gindex] = *inptr++;
|
||||
outptr[rindex] = *inptr++;
|
||||
outptr[aindex] = 0xFF;
|
||||
outptr += ps;
|
||||
}
|
||||
} else {
|
||||
for (col = cinfo->image_width; col > 0; col--) {
|
||||
outptr[bindex] = *inptr++;
|
||||
outptr[gindex] = *inptr++;
|
||||
outptr[rindex] = *inptr++;
|
||||
outptr += ps;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
METHODDEF(JDIMENSION)
|
||||
get_32bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
||||
/* This version is for reading 32-bit pixels */
|
||||
{
|
||||
bmp_source_ptr source = (bmp_source_ptr)sinfo;
|
||||
JSAMPARRAY image_ptr;
|
||||
register JSAMPROW inptr, outptr;
|
||||
register JDIMENSION col;
|
||||
|
||||
if (source->use_inversion_array) {
|
||||
/* Fetch next row from virtual array */
|
||||
source->source_row--;
|
||||
image_ptr = (*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr)cinfo, source->whole_image,
|
||||
source->source_row, (JDIMENSION)1, FALSE);
|
||||
inptr = image_ptr[0];
|
||||
} else {
|
||||
if (!ReadOK(source->pub.input_file, source->iobuffer, source->row_width))
|
||||
ERREXIT(cinfo, JERR_INPUT_EOF);
|
||||
inptr = source->iobuffer;
|
||||
}
|
||||
|
||||
/* Transfer data. Note source values are in BGR order
|
||||
* (even though Microsoft's own documents say the opposite).
|
||||
*/
|
||||
outptr = source->pub.buffer[0];
|
||||
if (cinfo->in_color_space == JCS_EXT_BGRX ||
|
||||
cinfo->in_color_space == JCS_EXT_BGRA) {
|
||||
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++;
|
||||
rgb_to_cmyk(r, g, b, outptr, outptr + 1, outptr + 2, outptr + 3);
|
||||
inptr++; /* skip the 4th byte (Alpha channel) */
|
||||
outptr += 4;
|
||||
}
|
||||
} else {
|
||||
register int rindex = rgb_red[cinfo->in_color_space];
|
||||
register int gindex = rgb_green[cinfo->in_color_space];
|
||||
register int bindex = rgb_blue[cinfo->in_color_space];
|
||||
register int aindex = alpha_index[cinfo->in_color_space];
|
||||
register int ps = rgb_pixelsize[cinfo->in_color_space];
|
||||
|
||||
if (aindex >= 0) {
|
||||
for (col = cinfo->image_width; col > 0; col--) {
|
||||
outptr[bindex] = *inptr++;
|
||||
outptr[gindex] = *inptr++;
|
||||
outptr[rindex] = *inptr++;
|
||||
outptr[aindex] = *inptr++;
|
||||
outptr += ps;
|
||||
}
|
||||
} else {
|
||||
for (col = cinfo->image_width; col > 0; col--) {
|
||||
outptr[bindex] = *inptr++;
|
||||
outptr[gindex] = *inptr++;
|
||||
outptr[rindex] = *inptr++;
|
||||
inptr++; /* skip the 4th byte (Alpha channel) */
|
||||
outptr += ps;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This method loads the image into whole_image during the first call on
|
||||
* get_pixel_rows. The get_pixel_rows pointer is then adjusted to call
|
||||
* get_8bit_row, get_24bit_row, or get_32bit_row on subsequent calls.
|
||||
*/
|
||||
|
||||
METHODDEF(JDIMENSION)
|
||||
preload_image(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
||||
{
|
||||
bmp_source_ptr source = (bmp_source_ptr)sinfo;
|
||||
register FILE *infile = source->pub.input_file;
|
||||
register JSAMPROW out_ptr;
|
||||
JSAMPARRAY image_ptr;
|
||||
JDIMENSION row;
|
||||
cd_progress_ptr progress = (cd_progress_ptr)cinfo->progress;
|
||||
|
||||
/* Read the data into a virtual array in input-file row order. */
|
||||
for (row = 0; row < cinfo->image_height; row++) {
|
||||
if (progress != NULL) {
|
||||
progress->pub.pass_counter = (long)row;
|
||||
progress->pub.pass_limit = (long)cinfo->image_height;
|
||||
(*progress->pub.progress_monitor) ((j_common_ptr)cinfo);
|
||||
}
|
||||
image_ptr = (*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr)cinfo, source->whole_image, row, (JDIMENSION)1, TRUE);
|
||||
out_ptr = image_ptr[0];
|
||||
if (fread(out_ptr, 1, source->row_width, infile) != source->row_width) {
|
||||
if (feof(infile))
|
||||
ERREXIT(cinfo, JERR_INPUT_EOF);
|
||||
else
|
||||
ERREXIT(cinfo, JERR_FILE_READ);
|
||||
}
|
||||
}
|
||||
if (progress != NULL)
|
||||
progress->completed_extra_passes++;
|
||||
|
||||
/* Set up to read from the virtual array in top-to-bottom order */
|
||||
switch (source->bits_per_pixel) {
|
||||
case 8:
|
||||
source->pub.get_pixel_rows = get_8bit_row;
|
||||
break;
|
||||
case 24:
|
||||
source->pub.get_pixel_rows = get_24bit_row;
|
||||
break;
|
||||
case 32:
|
||||
source->pub.get_pixel_rows = get_32bit_row;
|
||||
break;
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_BMP_BADDEPTH);
|
||||
}
|
||||
source->source_row = cinfo->image_height;
|
||||
|
||||
/* And read the first row */
|
||||
return (*source->pub.get_pixel_rows) (cinfo, sinfo);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Read the file header; return image size and component count.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
start_input_bmp(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
||||
{
|
||||
bmp_source_ptr source = (bmp_source_ptr)sinfo;
|
||||
U_CHAR bmpfileheader[14];
|
||||
U_CHAR bmpinfoheader[64];
|
||||
|
||||
#define GET_2B(array, offset) \
|
||||
((unsigned short)UCH(array[offset]) + \
|
||||
(((unsigned short)UCH(array[offset + 1])) << 8))
|
||||
#define GET_4B(array, offset) \
|
||||
((unsigned int)UCH(array[offset]) + \
|
||||
(((unsigned int)UCH(array[offset + 1])) << 8) + \
|
||||
(((unsigned int)UCH(array[offset + 2])) << 16) + \
|
||||
(((unsigned int)UCH(array[offset + 3])) << 24))
|
||||
|
||||
int bfOffBits;
|
||||
int headerSize;
|
||||
int biWidth;
|
||||
int biHeight;
|
||||
unsigned short biPlanes;
|
||||
unsigned int biCompression;
|
||||
int biXPelsPerMeter, biYPelsPerMeter;
|
||||
int biClrUsed = 0;
|
||||
int mapentrysize = 0; /* 0 indicates no colormap */
|
||||
int bPad;
|
||||
JDIMENSION row_width = 0;
|
||||
|
||||
/* Read and verify the bitmap file header */
|
||||
if (!ReadOK(source->pub.input_file, bmpfileheader, 14))
|
||||
ERREXIT(cinfo, JERR_INPUT_EOF);
|
||||
if (GET_2B(bmpfileheader, 0) != 0x4D42) /* 'BM' */
|
||||
ERREXIT(cinfo, JERR_BMP_NOT);
|
||||
bfOffBits = GET_4B(bmpfileheader, 10);
|
||||
/* We ignore the remaining fileheader fields */
|
||||
|
||||
/* The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows),
|
||||
* or 64 bytes (OS/2 2.x). Check the first 4 bytes to find out which.
|
||||
*/
|
||||
if (!ReadOK(source->pub.input_file, bmpinfoheader, 4))
|
||||
ERREXIT(cinfo, JERR_INPUT_EOF);
|
||||
headerSize = GET_4B(bmpinfoheader, 0);
|
||||
if (headerSize < 12 || headerSize > 64 || (headerSize + 14) > bfOffBits)
|
||||
ERREXIT(cinfo, JERR_BMP_BADHEADER);
|
||||
if (!ReadOK(source->pub.input_file, bmpinfoheader + 4, headerSize - 4))
|
||||
ERREXIT(cinfo, JERR_INPUT_EOF);
|
||||
|
||||
switch (headerSize) {
|
||||
case 12:
|
||||
/* Decode OS/2 1.x header (Microsoft calls this a BITMAPCOREHEADER) */
|
||||
biWidth = (int)GET_2B(bmpinfoheader, 4);
|
||||
biHeight = (int)GET_2B(bmpinfoheader, 6);
|
||||
biPlanes = GET_2B(bmpinfoheader, 8);
|
||||
source->bits_per_pixel = (int)GET_2B(bmpinfoheader, 10);
|
||||
|
||||
switch (source->bits_per_pixel) {
|
||||
case 8: /* colormapped image */
|
||||
mapentrysize = 3; /* OS/2 uses RGBTRIPLE colormap */
|
||||
TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, biWidth, biHeight);
|
||||
break;
|
||||
case 24: /* RGB image */
|
||||
case 32: /* RGB image + Alpha channel */
|
||||
TRACEMS3(cinfo, 1, JTRC_BMP_OS2, biWidth, biHeight,
|
||||
source->bits_per_pixel);
|
||||
break;
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_BMP_BADDEPTH);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 40:
|
||||
case 64:
|
||||
/* Decode Windows 3.x header (Microsoft calls this a BITMAPINFOHEADER) */
|
||||
/* or OS/2 2.x header, which has additional fields that we ignore */
|
||||
biWidth = (int)GET_4B(bmpinfoheader, 4);
|
||||
biHeight = (int)GET_4B(bmpinfoheader, 8);
|
||||
biPlanes = GET_2B(bmpinfoheader, 12);
|
||||
source->bits_per_pixel = (int)GET_2B(bmpinfoheader, 14);
|
||||
biCompression = GET_4B(bmpinfoheader, 16);
|
||||
biXPelsPerMeter = (int)GET_4B(bmpinfoheader, 24);
|
||||
biYPelsPerMeter = (int)GET_4B(bmpinfoheader, 28);
|
||||
biClrUsed = GET_4B(bmpinfoheader, 32);
|
||||
/* biSizeImage, biClrImportant fields are ignored */
|
||||
|
||||
switch (source->bits_per_pixel) {
|
||||
case 8: /* colormapped image */
|
||||
mapentrysize = 4; /* Windows uses RGBQUAD colormap */
|
||||
TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, biWidth, biHeight);
|
||||
break;
|
||||
case 24: /* RGB image */
|
||||
case 32: /* RGB image + Alpha channel */
|
||||
TRACEMS3(cinfo, 1, JTRC_BMP, biWidth, biHeight, source->bits_per_pixel);
|
||||
break;
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_BMP_BADDEPTH);
|
||||
break;
|
||||
}
|
||||
if (biCompression != 0)
|
||||
ERREXIT(cinfo, JERR_BMP_COMPRESSED);
|
||||
|
||||
if (biXPelsPerMeter > 0 && biYPelsPerMeter > 0) {
|
||||
/* Set JFIF density parameters from the BMP data */
|
||||
cinfo->X_density = (UINT16)(biXPelsPerMeter / 100); /* 100 cm per meter */
|
||||
cinfo->Y_density = (UINT16)(biYPelsPerMeter / 100);
|
||||
cinfo->density_unit = 2; /* dots/cm */
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_BMP_BADHEADER);
|
||||
return;
|
||||
}
|
||||
|
||||
if (biWidth <= 0 || biHeight <= 0)
|
||||
ERREXIT(cinfo, JERR_BMP_EMPTY);
|
||||
if (sinfo->max_pixels &&
|
||||
(unsigned long long)biWidth * biHeight > sinfo->max_pixels)
|
||||
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
|
||||
if (biPlanes != 1)
|
||||
ERREXIT(cinfo, JERR_BMP_BADPLANES);
|
||||
|
||||
/* Compute distance to bitmap data --- will adjust for colormap below */
|
||||
bPad = bfOffBits - (headerSize + 14);
|
||||
|
||||
/* Read the colormap, if any */
|
||||
if (mapentrysize > 0) {
|
||||
if (biClrUsed <= 0)
|
||||
biClrUsed = 256; /* assume it's 256 */
|
||||
else if (biClrUsed > 256)
|
||||
ERREXIT(cinfo, JERR_BMP_BADCMAP);
|
||||
/* Allocate space to store the colormap */
|
||||
source->colormap = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE, (JDIMENSION)biClrUsed, (JDIMENSION)3);
|
||||
source->cmap_length = (int)biClrUsed;
|
||||
/* and read it from the file */
|
||||
read_colormap(source, (int)biClrUsed, mapentrysize);
|
||||
/* account for size of colormap */
|
||||
bPad -= biClrUsed * mapentrysize;
|
||||
}
|
||||
|
||||
/* Skip any remaining pad bytes */
|
||||
if (bPad < 0) /* incorrect bfOffBits value? */
|
||||
ERREXIT(cinfo, JERR_BMP_BADHEADER);
|
||||
while (--bPad >= 0) {
|
||||
(void)read_byte(source);
|
||||
}
|
||||
|
||||
/* Compute row width in file, including padding to 4-byte boundary */
|
||||
switch (source->bits_per_pixel) {
|
||||
case 8:
|
||||
if (cinfo->in_color_space == JCS_UNKNOWN)
|
||||
cinfo->in_color_space = JCS_EXT_RGB;
|
||||
if (IsExtRGB(cinfo->in_color_space))
|
||||
cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
|
||||
else if (cinfo->in_color_space == JCS_GRAYSCALE)
|
||||
cinfo->input_components = 1;
|
||||
else if (cinfo->in_color_space == JCS_CMYK)
|
||||
cinfo->input_components = 4;
|
||||
else
|
||||
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
||||
row_width = (JDIMENSION)biWidth;
|
||||
break;
|
||||
case 24:
|
||||
if (cinfo->in_color_space == JCS_UNKNOWN)
|
||||
cinfo->in_color_space = JCS_EXT_BGR;
|
||||
if (IsExtRGB(cinfo->in_color_space))
|
||||
cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
|
||||
else if (cinfo->in_color_space == JCS_CMYK)
|
||||
cinfo->input_components = 4;
|
||||
else
|
||||
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
||||
if ((unsigned long long)biWidth * 3ULL > 0xFFFFFFFFULL)
|
||||
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
||||
row_width = (JDIMENSION)biWidth * 3;
|
||||
break;
|
||||
case 32:
|
||||
if (cinfo->in_color_space == JCS_UNKNOWN)
|
||||
cinfo->in_color_space = JCS_EXT_BGRA;
|
||||
if (IsExtRGB(cinfo->in_color_space))
|
||||
cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
|
||||
else if (cinfo->in_color_space == JCS_CMYK)
|
||||
cinfo->input_components = 4;
|
||||
else
|
||||
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
||||
if ((unsigned long long)biWidth * 4ULL > 0xFFFFFFFFULL)
|
||||
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
||||
row_width = (JDIMENSION)biWidth * 4;
|
||||
break;
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_BMP_BADDEPTH);
|
||||
}
|
||||
while ((row_width & 3) != 0) row_width++;
|
||||
source->row_width = row_width;
|
||||
|
||||
if (source->use_inversion_array) {
|
||||
/* Allocate space for inversion array, prepare for preload pass */
|
||||
source->whole_image = (*cinfo->mem->request_virt_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
|
||||
row_width, (JDIMENSION)biHeight, (JDIMENSION)1);
|
||||
source->pub.get_pixel_rows = preload_image;
|
||||
if (cinfo->progress != NULL) {
|
||||
cd_progress_ptr progress = (cd_progress_ptr)cinfo->progress;
|
||||
progress->total_extra_passes++; /* count file input as separate pass */
|
||||
}
|
||||
} else {
|
||||
source->iobuffer = (U_CHAR *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, row_width);
|
||||
switch (source->bits_per_pixel) {
|
||||
case 8:
|
||||
source->pub.get_pixel_rows = get_8bit_row;
|
||||
break;
|
||||
case 24:
|
||||
source->pub.get_pixel_rows = get_24bit_row;
|
||||
break;
|
||||
case 32:
|
||||
source->pub.get_pixel_rows = get_32bit_row;
|
||||
break;
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_BMP_BADDEPTH);
|
||||
}
|
||||
}
|
||||
|
||||
/* Ensure that biWidth * cinfo->input_components doesn't exceed the maximum
|
||||
value of the JDIMENSION type. This is only a danger with BMP files, since
|
||||
their width and height fields are 32-bit integers. */
|
||||
if ((unsigned long long)biWidth *
|
||||
(unsigned long long)cinfo->input_components > 0xFFFFFFFFULL)
|
||||
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
||||
/* Allocate one-row buffer for returned data */
|
||||
source->pub.buffer = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION)biWidth * (JDIMENSION)cinfo->input_components, (JDIMENSION)1);
|
||||
source->pub.buffer_height = 1;
|
||||
|
||||
cinfo->data_precision = 8;
|
||||
cinfo->image_width = (JDIMENSION)biWidth;
|
||||
cinfo->image_height = (JDIMENSION)biHeight;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Finish up at the end of the file.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
finish_input_bmp(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
||||
{
|
||||
/* no work */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The module selection routine for BMP format input.
|
||||
*/
|
||||
|
||||
GLOBAL(cjpeg_source_ptr)
|
||||
jinit_read_bmp(j_compress_ptr cinfo, boolean use_inversion_array)
|
||||
{
|
||||
bmp_source_ptr source;
|
||||
|
||||
if (cinfo->data_precision != 8)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
/* Create module interface object */
|
||||
source = (bmp_source_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
sizeof(bmp_source_struct));
|
||||
source->cinfo = cinfo; /* make back link for subroutines */
|
||||
/* Fill in method ptrs, except get_pixel_rows which start_input sets */
|
||||
source->pub.start_input = start_input_bmp;
|
||||
source->pub.finish_input = finish_input_bmp;
|
||||
source->pub.max_pixels = 0;
|
||||
|
||||
source->use_inversion_array = use_inversion_array;
|
||||
|
||||
return (cjpeg_source_ptr)source;
|
||||
}
|
||||
|
||||
#endif /* BMP_SUPPORTED */
|
261
3rdparty/libjpeg-turbo/src/rdcolmap.c
vendored
Normal file
261
3rdparty/libjpeg-turbo/src/rdcolmap.c
vendored
Normal file
@ -0,0 +1,261 @@
|
||||
/*
|
||||
* rdcolmap.c
|
||||
*
|
||||
* This file was part of the Independent JPEG Group's software:
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* libjpeg-turbo Modifications:
|
||||
* Copyright (C) 2022, D. R. Commander.
|
||||
* For conditions of distribution and use, see the accompanying README.ijg
|
||||
* file.
|
||||
*
|
||||
* This file implements djpeg's "-map file" switch. It reads a source image
|
||||
* and constructs a colormap to be supplied to the JPEG decompressor.
|
||||
*
|
||||
* Currently, these file formats are supported for the map file:
|
||||
* GIF: the contents of the GIF's global colormap are used.
|
||||
* PPM (either text or raw flavor): the entire file is read and
|
||||
* each unique pixel value is entered in the map.
|
||||
* Note that reading a large PPM file will be horrendously slow.
|
||||
* Typically, a PPM-format map file should contain just one pixel
|
||||
* of each desired color. Such a file can be extracted from an
|
||||
* ordinary image PPM file with ppmtomap(1).
|
||||
*
|
||||
* Rescaling a PPM that has a maxval unequal to _MAXJSAMPLE is not
|
||||
* currently implemented.
|
||||
*/
|
||||
|
||||
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
|
||||
#include "jsamplecomp.h"
|
||||
|
||||
#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */
|
||||
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
|
||||
|
||||
/* Portions of this code are based on the PBMPLUS library, which is:
|
||||
**
|
||||
** Copyright (C) 1988 by Jef Poskanzer.
|
||||
**
|
||||
** Permission to use, copy, modify, and distribute this software and its
|
||||
** documentation for any purpose and without fee is hereby granted, provided
|
||||
** that the above copyright notice appear in all copies and that both that
|
||||
** copyright notice and this permission notice appear in supporting
|
||||
** documentation. This software is provided "as is" without express or
|
||||
** implied warranty.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Add a (potentially) new color to the color map.
|
||||
*/
|
||||
|
||||
LOCAL(void)
|
||||
add_map_entry(j_decompress_ptr cinfo, int R, int G, int B)
|
||||
{
|
||||
_JSAMPROW colormap0 = ((_JSAMPARRAY)cinfo->colormap)[0];
|
||||
_JSAMPROW colormap1 = ((_JSAMPARRAY)cinfo->colormap)[1];
|
||||
_JSAMPROW colormap2 = ((_JSAMPARRAY)cinfo->colormap)[2];
|
||||
int ncolors = cinfo->actual_number_of_colors;
|
||||
int index;
|
||||
|
||||
/* Check for duplicate color. */
|
||||
for (index = 0; index < ncolors; index++) {
|
||||
if (colormap0[index] == R && colormap1[index] == G &&
|
||||
colormap2[index] == B)
|
||||
return; /* color is already in map */
|
||||
}
|
||||
|
||||
/* Check for map overflow. */
|
||||
if (ncolors >= (_MAXJSAMPLE + 1))
|
||||
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, (_MAXJSAMPLE + 1));
|
||||
|
||||
/* OK, add color to map. */
|
||||
colormap0[ncolors] = (_JSAMPLE)R;
|
||||
colormap1[ncolors] = (_JSAMPLE)G;
|
||||
colormap2[ncolors] = (_JSAMPLE)B;
|
||||
cinfo->actual_number_of_colors++;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Extract color map from a GIF file.
|
||||
*/
|
||||
|
||||
LOCAL(void)
|
||||
read_gif_map(j_decompress_ptr cinfo, FILE *infile)
|
||||
{
|
||||
int header[13];
|
||||
int i, colormaplen;
|
||||
int R, G, B;
|
||||
|
||||
/* Initial 'G' has already been read by read_color_map */
|
||||
/* Read the rest of the GIF header and logical screen descriptor */
|
||||
for (i = 1; i < 13; i++) {
|
||||
if ((header[i] = getc(infile)) == EOF)
|
||||
ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
|
||||
}
|
||||
|
||||
/* Verify GIF Header */
|
||||
if (header[1] != 'I' || header[2] != 'F')
|
||||
ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
|
||||
|
||||
/* There must be a global color map. */
|
||||
if ((header[10] & 0x80) == 0)
|
||||
ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
|
||||
|
||||
/* OK, fetch it. */
|
||||
colormaplen = 2 << (header[10] & 0x07);
|
||||
|
||||
for (i = 0; i < colormaplen; i++) {
|
||||
R = getc(infile);
|
||||
G = getc(infile);
|
||||
B = getc(infile);
|
||||
if (R == EOF || G == EOF || B == EOF)
|
||||
ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
|
||||
add_map_entry(cinfo,
|
||||
R << (BITS_IN_JSAMPLE - 8),
|
||||
G << (BITS_IN_JSAMPLE - 8),
|
||||
B << (BITS_IN_JSAMPLE - 8));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Support routines for reading PPM */
|
||||
|
||||
|
||||
LOCAL(int)
|
||||
pbm_getc(FILE *infile)
|
||||
/* Read next char, skipping over any comments */
|
||||
/* A comment/newline sequence is returned as a newline */
|
||||
{
|
||||
register int ch;
|
||||
|
||||
ch = getc(infile);
|
||||
if (ch == '#') {
|
||||
do {
|
||||
ch = getc(infile);
|
||||
} while (ch != '\n' && ch != EOF);
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
LOCAL(unsigned int)
|
||||
read_pbm_integer(j_decompress_ptr cinfo, FILE *infile)
|
||||
/* Read an unsigned decimal integer from the PPM file */
|
||||
/* Swallows one trailing character after the integer */
|
||||
/* Note that on a 16-bit-int machine, only values up to 64k can be read. */
|
||||
/* This should not be a problem in practice. */
|
||||
{
|
||||
register int ch;
|
||||
register unsigned int val;
|
||||
|
||||
/* Skip any leading whitespace */
|
||||
do {
|
||||
ch = pbm_getc(infile);
|
||||
if (ch == EOF)
|
||||
ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
|
||||
} while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
|
||||
|
||||
if (ch < '0' || ch > '9')
|
||||
ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
|
||||
|
||||
val = ch - '0';
|
||||
while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
|
||||
val *= 10;
|
||||
val += ch - '0';
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Extract color map from a PPM file.
|
||||
*/
|
||||
|
||||
LOCAL(void)
|
||||
read_ppm_map(j_decompress_ptr cinfo, FILE *infile)
|
||||
{
|
||||
int c;
|
||||
unsigned int w, h, maxval, row, col;
|
||||
int R, G, B;
|
||||
|
||||
/* Initial 'P' has already been read by read_color_map */
|
||||
c = getc(infile); /* save format discriminator for a sec */
|
||||
|
||||
/* while we fetch the remaining header info */
|
||||
w = read_pbm_integer(cinfo, infile);
|
||||
h = read_pbm_integer(cinfo, infile);
|
||||
maxval = read_pbm_integer(cinfo, infile);
|
||||
|
||||
if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
|
||||
ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
|
||||
|
||||
/* For now, we don't support rescaling from an unusual maxval. */
|
||||
if (maxval != (unsigned int)_MAXJSAMPLE)
|
||||
ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
|
||||
|
||||
switch (c) {
|
||||
case '3': /* it's a text-format PPM file */
|
||||
for (row = 0; row < h; row++) {
|
||||
for (col = 0; col < w; col++) {
|
||||
R = read_pbm_integer(cinfo, infile);
|
||||
G = read_pbm_integer(cinfo, infile);
|
||||
B = read_pbm_integer(cinfo, infile);
|
||||
add_map_entry(cinfo, R, G, B);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case '6': /* it's a raw-format PPM file */
|
||||
for (row = 0; row < h; row++) {
|
||||
for (col = 0; col < w; col++) {
|
||||
R = getc(infile);
|
||||
G = getc(infile);
|
||||
B = getc(infile);
|
||||
if (R == EOF || G == EOF || B == EOF)
|
||||
ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
|
||||
add_map_entry(cinfo, R, G, B);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Main entry point from djpeg.c.
|
||||
* Input: opened input file (from file name argument on command line).
|
||||
* Output: colormap and actual_number_of_colors fields are set in cinfo.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
_read_color_map(j_decompress_ptr cinfo, FILE *infile)
|
||||
{
|
||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||
|
||||
/* Allocate space for a color map of maximum supported size. */
|
||||
cinfo->colormap = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr)cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION)(_MAXJSAMPLE + 1), (JDIMENSION)3);
|
||||
cinfo->actual_number_of_colors = 0; /* initialize map to empty */
|
||||
|
||||
/* Read first byte to determine file format */
|
||||
switch (getc(infile)) {
|
||||
case 'G':
|
||||
read_gif_map(cinfo, infile);
|
||||
break;
|
||||
case 'P':
|
||||
read_ppm_map(cinfo, infile);
|
||||
break;
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */
|
||||
#endif /* QUANT_2PASS_SUPPORTED */
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user