1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Compare commits

..

14 Commits

Author SHA1 Message Date
Alexander Alekhin 4de7015cfd dnn: prevent unloading of InferenceEngine plugins 2020-01-22 18:46:00 +03:00
Liubov Batanina d42d34e2ee Support lrn with SPATIAL_NRM 2020-01-21 12:49:58 +03:00
Dmitry Kurtaev 04d4af1a6d MVN support through nGraph 2020-01-17 12:11:45 +03:00
Dmitry Kurtaev cb64fdabb5 Different way to reset Myriad device 2020-01-15 20:01:53 +03:00
Dmitry Kurtaev 8cb0a37336 Wrap custom OpenCV layers to try-catch 2020-01-15 17:52:24 +03:00
Dmitry Kurtaev aae15a4efa Fix uninitialized value 2020-01-15 13:01:33 +03:00
Alexander Alekhin b61b146f0e dnn: use OpenVINO 2020.1 defines 2020-01-14 16:44:17 +03:00
Dmitry Kurtaev 905c551b7b ONNX graphs simplifier 2020-01-14 16:44:17 +03:00
Alexander Alekhin 7c4398a0f6 copyright: 2020 2020-01-14 16:22:30 +03:00
Liubov Batanina b3eb24cd07 Enable acrossSpatial normalizeL2 on Myriad 2020-01-14 16:22:30 +03:00
Dmitry Kurtaev 5b5c2093bb AddV2 from TensorFlow 2020-01-14 16:22:30 +03:00
Dmitry Kurtaev 010cc2e58a Sort text TensorFlow graphs 2020-01-14 16:22:30 +03:00
Dmitry Kurtaev 2f23737e66 Disable some tests for Myriad target of nGraph
Add lightweight IE hardware targets checks

nGraph: Concat with paddings

Enable more nGraph tests

Restore FP32->FP16 for GPU plugin of IE

try to fix buildbot

Use lightweight IE targets check only starts from R4
2020-01-14 16:22:30 +03:00
Alexander Alekhin 43cb28bdb5 OpenCV version '-openvino' 2020-01-14 16:22:30 +03:00
2575 changed files with 39233 additions and 261922 deletions
+11 -42
View File
@@ -1,15 +1,23 @@
<!-- <!--
If you have a question rather than reporting a bug please go to https://forum.opencv.org where you get much faster responses. If you have a question rather than reporting a bug please go to http://answers.opencv.org where you get much faster responses.
If you need further assistance please read [How To Contribute](https://github.com/opencv/opencv/wiki/How_to_contribute). If you need further assistance please read [How To Contribute](https://github.com/opencv/opencv/wiki/How_to_contribute).
Please:
* Read the documentation to test with the latest developer build.
* Check if other person has already created the same issue to avoid duplicates. You can comment on it if there already is an issue.
* Try to be as detailed as possible in your report.
* Report only one problem per created issue.
This is a template helping you to create an issue which can be processed as quickly as possible. This is the bug reporting section for the OpenCV library. This is a template helping you to create an issue which can be processed as quickly as possible. This is the bug reporting section for the OpenCV library.
--> -->
##### System information (version) ##### System information (version)
<!-- Example <!-- Example
- OpenCV => 4.2 - OpenCV => 3.1
- Operating System / Platform => Windows 64 Bit - Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2017 - Compiler => Visual Studio 2015
--> -->
- OpenCV => :grey_question: - OpenCV => :grey_question:
@@ -28,42 +36,3 @@ This is a template helping you to create an issue which can be processed as quic
``` ```
or attach as .txt or .zip file or attach as .txt or .zip file
--> -->
##### Issue submission checklist
- [ ] I report the issue, it's not a question
<!--
OpenCV team works with forum.opencv.org, Stack Overflow and other communities
to discuss problems. Tickets with question without real issue statement will be
closed.
-->
- [ ] I checked the problem with documentation, FAQ, open issues,
forum.opencv.org, Stack Overflow, etc and have not found solution
<!--
Places to check:
* OpenCV documentation: https://docs.opencv.org
* FAQ page: https://github.com/opencv/opencv/wiki/FAQ
* OpenCV forum: https://forum.opencv.org
* OpenCV issue tracker: https://github.com/opencv/opencv/issues?q=is%3Aissue
* Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
-->
- [ ] I updated to latest OpenCV version and the issue is still there
<!--
master branch for OpenCV 4.x and 3.4 branch for OpenCV 3.x releases.
OpenCV team supports only latest release for each branch.
The ticket is closed, if the problem is not reproduced with modern version.
-->
- [ ] There is reproducer code and related data files: videos, images, onnx, etc
<!--
The best reproducer -- test case for OpenCV that we can add to the library.
Recommendations for media files and binary files:
* Try to reproduce the issue with images and videos in opencv_extra repository
to reduce attachment size
* Use PNG for images, if you report some CV related bug, but not image reader
issue
* Attach the image as archive to the ticket, if you report some reader issue.
Image hosting services compress images and it breaks the repro code.
* Provide ONNX file for some public model or ONNX file with with random weights,
if you report ONNX parsing or handling issue. Architecture details diagram
from netron tool can be very useful too. See https://lutzroeder.github.io/netron/
-->
+7 -9
View File
@@ -1,11 +1,9 @@
### Pull Request Readiness Checklist <!-- Please use this line to close one or multiple issues when this pullrequest gets merged
You can add another line right under the first one:
resolves #1234
resolves #1235
-->
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request ### This pullrequest changes
- [ ] I agree to contribute to the project under Apache 2 License. <!-- Please describe what your pullrequest is changing -->
- [ ] To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
- [ ] The PR is proposed to proper branch
- [ ] There is reference to original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
-47
View File
@@ -1,47 +0,0 @@
name: arm64 build checks
on: workflow_dispatch
jobs:
build:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Install dependency packages
run: |
sudo sed -i -E 's|^deb ([^ ]+) (.*)$|deb [arch=amd64] \1 \2\ndeb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ \2|' /etc/apt/sources.list
sudo dpkg --add-architecture arm64
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
crossbuild-essential-arm64 \
git \
cmake \
libpython-dev:arm64 \
libpython3-dev:arm64 \
python-numpy \
python3-numpy
- name: Fetch opencv_contrib
run: |
git clone --depth 1 https://github.com/opencv/opencv_contrib.git ../opencv_contrib
- name: Configure
run: |
mkdir build
cd build
cmake -DPYTHON2_INCLUDE_PATH=/usr/include/python2.7/ \
-DPYTHON2_LIBRARIES=/usr/lib/aarch64-linux-gnu/libpython2.7.so \
-DPYTHON2_NUMPY_INCLUDE_DIRS=/usr/lib/python2.7/dist-packages/numpy/core/include \
-DPYTHON3_INCLUDE_PATH=/usr/include/python3.6m/ \
-DPYTHON3_LIBRARIES=/usr/lib/aarch64-linux-gnu/libpython3.6m.so \
-DPYTHON3_NUMPY_INCLUDE_DIRS=/usr/lib/python3/dist-packages/numpy/core/include \
-DCMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake \
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
../
- name: Build
run: |
cd build
make -j$(nproc --all)
-2
View File
@@ -23,5 +23,3 @@ bin/
*.tlog *.tlog
build build
node_modules node_modules
CMakeSettings.json
xcuserdata/
+4 -8
View File
@@ -20,14 +20,11 @@ if(CMAKE_COMPILER_IS_GNUCC)
# - matchTemplate about 5-10% # - matchTemplate about 5-10%
# - goodFeaturesToTrack 10-20% # - goodFeaturesToTrack 10-20%
# - cornerHarris 30% for some cases # - cornerHarris 30% for some cases
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0.0")
set_source_files_properties(${carotene_sources} COMPILE_FLAGS "--param ipcp-unit-growth=100000 --param inline-unit-growth=100000 --param large-stack-frame-growth=5000") set_source_files_properties(${carotene_sources} COMPILE_FLAGS "--param ipcp-unit-growth=100000 --param inline-unit-growth=100000 --param large-stack-frame-growth=5000")
else()
set_source_files_properties(${carotene_sources} COMPILE_FLAGS "--param ipa-cp-unit-growth=100000 --param inline-unit-growth=100000 --param large-stack-frame-growth=5000")
endif()
endif() endif()
add_library(carotene_objs OBJECT EXCLUDE_FROM_ALL add_library(carotene_objs OBJECT
${carotene_headers} ${carotene_headers}
${carotene_sources} ${carotene_sources}
) )
@@ -40,5 +37,4 @@ if(WITH_NEON)
target_compile_definitions(carotene_objs PRIVATE "-DWITH_NEON") target_compile_definitions(carotene_objs PRIVATE "-DWITH_NEON")
endif() endif()
# we add dummy file to fix XCode build add_library(carotene STATIC EXCLUDE_FROM_ALL "$<TARGET_OBJECTS:carotene_objs>")
add_library(carotene STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} "$<TARGET_OBJECTS:carotene_objs>" "${CAROTENE_SOURCE_DIR}/dummy.cpp")
+18 -7
View File
@@ -60,6 +60,22 @@ function(compile_carotene)
endif() endif()
add_subdirectory("${CAROTENE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/carotene") add_subdirectory("${CAROTENE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/carotene")
if(ARM OR AARCH64)
if(CMAKE_BUILD_TYPE)
set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
endif()
check_cxx_compiler_flag("-mfpu=neon" CXX_HAS_MFPU_NEON)
check_c_compiler_flag("-mfpu=neon" C_HAS_MFPU_NEON)
if(${CXX_HAS_MFPU_NEON} AND ${C_HAS_MFPU_NEON} AND NOT "${CMAKE_CXX_FLAGS} " MATCHES "-mfpu=neon[^ ]*")
get_target_property(old_flags "carotene_objs" COMPILE_FLAGS)
if(old_flags)
set_target_properties("carotene_objs" PROPERTIES COMPILE_FLAGS "${old_flags} -mfpu=neon")
else()
set_target_properties("carotene_objs" PROPERTIES COMPILE_FLAGS "-mfpu=neon")
endif()
endif()
endif()
endfunction() endfunction()
compile_carotene() compile_carotene()
@@ -74,16 +90,11 @@ set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS ${carotene_defs})
# matchTemplate about 5-10% # matchTemplate about 5-10%
# goodFeaturesToTrack 10-20% # goodFeaturesToTrack 10-20%
# cornerHarris 30% for some cases # cornerHarris 30% for some cases
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0.0") set_source_files_properties(impl.cpp $<TARGET_OBJECTS:carotene_objs> COMPILE_FLAGS "--param ipcp-unit-growth=100000 --param inline-unit-growth=100000 --param large-stack-frame-growth=5000")
set_source_files_properties(impl.cpp $<TARGET_OBJECTS:carotene_objs> COMPILE_FLAGS "--param ipcp-unit-growth=100000 --param inline-unit-growth=100000 --param large-stack-frame-growth=5000")
else()
set_source_files_properties(impl.cpp $<TARGET_OBJECTS:carotene_objs> COMPILE_FLAGS "--param ipa-cp-unit-growth=100000 --param inline-unit-growth=100000 --param large-stack-frame-growth=5000")
endif()
# set_source_files_properties(impl.cpp $<TARGET_OBJECTS:carotene_objs> COMPILE_FLAGS "--param ipcp-unit-growth=100000 --param inline-unit-growth=100000 --param large-stack-frame-growth=5000") # set_source_files_properties(impl.cpp $<TARGET_OBJECTS:carotene_objs> COMPILE_FLAGS "--param ipcp-unit-growth=100000 --param inline-unit-growth=100000 --param large-stack-frame-growth=5000")
endif() endif()
# we add dummy file to fix XCode build add_library(tegra_hal STATIC $<TARGET_OBJECTS:carotene_objs>)
add_library(tegra_hal STATIC $<TARGET_OBJECTS:carotene_objs> "dummy.cpp")
set_target_properties(tegra_hal PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH}) set_target_properties(tegra_hal PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH})
set(OPENCV_SRC_DIR "${CMAKE_SOURCE_DIR}") set(OPENCV_SRC_DIR "${CMAKE_SOURCE_DIR}")
if(NOT BUILD_SHARED_LIBS) if(NOT BUILD_SHARED_LIBS)
-2
View File
@@ -1,2 +0,0 @@
// This file is needed for compilation on some platforms e.g. with XCode generator
// Related issue: https://gitlab.kitware.com/cmake/cmake/-/issues/17457
-2
View File
@@ -1,2 +0,0 @@
// This file is needed for compilation on some platforms e.g. with XCode generator
// Related issue: https://gitlab.kitware.com/cmake/cmake/-/issues/17457
+1 -1
View File
@@ -758,7 +758,7 @@ inline void resizeAreaRounding(const Size2D &ssize, const Size2D &dsize,
} }
else if (channels == 3) else if (channels == 3)
{ {
if ((wr == 2.0f) && (hr == 2.0f)) if ((wr == 2.0f) && (wr == 2.0f))
{ {
#ifndef __ANDROID__ #ifndef __ANDROID__
size_t roiw16 = dsize.width >= 15 ? (dsize.width - 15) * 3 : 0; size_t roiw16 = dsize.width >= 15 ? (dsize.width - 15) * 3 : 0;
+2 -2
View File
@@ -14,7 +14,7 @@ if(NOT DEFINED CPUFEATURES_SOURCES)
endif() endif()
include_directories(${CPUFEATURES_INCLUDE_DIRS}) include_directories(${CPUFEATURES_INCLUDE_DIRS})
add_library(${OPENCV_CPUFEATURES_TARGET_NAME} STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${CPUFEATURES_SOURCES}) add_library(${OPENCV_CPUFEATURES_TARGET_NAME} STATIC ${CPUFEATURES_SOURCES})
set_target_properties(${OPENCV_CPUFEATURES_TARGET_NAME} set_target_properties(${OPENCV_CPUFEATURES_TARGET_NAME}
PROPERTIES OUTPUT_NAME cpufeatures PROPERTIES OUTPUT_NAME cpufeatures
@@ -29,7 +29,7 @@ if(ENABLE_SOLUTION_FOLDERS)
endif() endif()
if(NOT BUILD_SHARED_LIBS) if(NOT BUILD_SHARED_LIBS)
ocv_install_target(${OPENCV_CPUFEATURES_TARGET_NAME} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev OPTIONAL) ocv_install_target(${OPENCV_CPUFEATURES_TARGET_NAME} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif() endif()
ocv_install_3rdparty_licenses(cpufeatures LICENSE README.md) ocv_install_3rdparty_licenses(cpufeatures LICENSE README.md)
+6 -6
View File
@@ -1,9 +1,9 @@
# Binaries branch name: ffmpeg/master_20210608 # Binaries branch name: ffmpeg/master_20191119
# Binaries were created for OpenCV: eaa9228a4fdfb9c2465aea65a50ce2d16b55dce0 # Binaries were created for OpenCV: 318cba4ce37319ba0b0870aab384d5dc066bb124
ocv_update(FFMPEG_BINARIES_COMMIT "213fcd5d4897319a83207406036c4a5957fba010") ocv_update(FFMPEG_BINARIES_COMMIT "a66a24e9f410ae05da4baeeb8b451912664ce49c")
ocv_update(FFMPEG_FILE_HASH_BIN32 "bab661341c30862fa88627130219c0a5") ocv_update(FFMPEG_FILE_HASH_BIN32 "5de6044cad9398549e57bc46fc13908d")
ocv_update(FFMPEG_FILE_HASH_BIN64 "ac99f9767a83103c31709628af685924") ocv_update(FFMPEG_FILE_HASH_BIN64 "55c0bc8ad27db00116fabf06508de196")
ocv_update(FFMPEG_FILE_HASH_CMAKE "8862c87496e2e8c375965e1277dee1c7") ocv_update(FFMPEG_FILE_HASH_CMAKE "ad57c038ba34b868277ccbe6dd0f9602")
function(download_win_ffmpeg script_var) function(download_win_ffmpeg script_var)
set(${script_var} "" PARENT_SCOPE) set(${script_var} "" PARENT_SCOPE)
@@ -1,160 +0,0 @@
/*******************************************************************************
* Copyright (c) 2008-2020 The Khronos Group Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
/*****************************************************************************\
Copyright (c) 2013-2019 Intel Corporation All Rights Reserved.
THESE MATERIALS ARE 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 INTEL OR ITS
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 THESE
MATERIALS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: cl_va_api_media_sharing_intel.h
Abstract:
Notes:
\*****************************************************************************/
#ifndef __OPENCL_CL_VA_API_MEDIA_SHARING_INTEL_H
#define __OPENCL_CL_VA_API_MEDIA_SHARING_INTEL_H
#include <CL/cl.h>
#include <CL/cl_platform.h>
#include <va/va.h>
#ifdef __cplusplus
extern "C" {
#endif
/******************************************
* cl_intel_va_api_media_sharing extension *
*******************************************/
#define cl_intel_va_api_media_sharing 1
/* error codes */
#define CL_INVALID_VA_API_MEDIA_ADAPTER_INTEL -1098
#define CL_INVALID_VA_API_MEDIA_SURFACE_INTEL -1099
#define CL_VA_API_MEDIA_SURFACE_ALREADY_ACQUIRED_INTEL -1100
#define CL_VA_API_MEDIA_SURFACE_NOT_ACQUIRED_INTEL -1101
/* cl_va_api_device_source_intel */
#define CL_VA_API_DISPLAY_INTEL 0x4094
/* cl_va_api_device_set_intel */
#define CL_PREFERRED_DEVICES_FOR_VA_API_INTEL 0x4095
#define CL_ALL_DEVICES_FOR_VA_API_INTEL 0x4096
/* cl_context_info */
#define CL_CONTEXT_VA_API_DISPLAY_INTEL 0x4097
/* cl_mem_info */
#define CL_MEM_VA_API_MEDIA_SURFACE_INTEL 0x4098
/* cl_image_info */
#define CL_IMAGE_VA_API_PLANE_INTEL 0x4099
/* cl_command_type */
#define CL_COMMAND_ACQUIRE_VA_API_MEDIA_SURFACES_INTEL 0x409A
#define CL_COMMAND_RELEASE_VA_API_MEDIA_SURFACES_INTEL 0x409B
typedef cl_uint cl_va_api_device_source_intel;
typedef cl_uint cl_va_api_device_set_intel;
extern CL_API_ENTRY cl_int CL_API_CALL
clGetDeviceIDsFromVA_APIMediaAdapterINTEL(
cl_platform_id platform,
cl_va_api_device_source_intel media_adapter_type,
void* media_adapter,
cl_va_api_device_set_intel media_adapter_set,
cl_uint num_entries,
cl_device_id* devices,
cl_uint* num_devices) CL_EXT_SUFFIX__VERSION_1_2;
typedef CL_API_ENTRY cl_int (CL_API_CALL * clGetDeviceIDsFromVA_APIMediaAdapterINTEL_fn)(
cl_platform_id platform,
cl_va_api_device_source_intel media_adapter_type,
void* media_adapter,
cl_va_api_device_set_intel media_adapter_set,
cl_uint num_entries,
cl_device_id* devices,
cl_uint* num_devices) CL_EXT_SUFFIX__VERSION_1_2;
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromVA_APIMediaSurfaceINTEL(
cl_context context,
cl_mem_flags flags,
VASurfaceID* surface,
cl_uint plane,
cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2;
typedef CL_API_ENTRY cl_mem (CL_API_CALL * clCreateFromVA_APIMediaSurfaceINTEL_fn)(
cl_context context,
cl_mem_flags flags,
VASurfaceID* surface,
cl_uint plane,
cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2;
extern CL_API_ENTRY cl_int CL_API_CALL
clEnqueueAcquireVA_APIMediaSurfacesINTEL(
cl_command_queue command_queue,
cl_uint num_objects,
const cl_mem* mem_objects,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event) CL_EXT_SUFFIX__VERSION_1_2;
typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireVA_APIMediaSurfacesINTEL_fn)(
cl_command_queue command_queue,
cl_uint num_objects,
const cl_mem* mem_objects,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event) CL_EXT_SUFFIX__VERSION_1_2;
extern CL_API_ENTRY cl_int CL_API_CALL
clEnqueueReleaseVA_APIMediaSurfacesINTEL(
cl_command_queue command_queue,
cl_uint num_objects,
const cl_mem* mem_objects,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event) CL_EXT_SUFFIX__VERSION_1_2;
typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseVA_APIMediaSurfacesINTEL_fn)(
cl_command_queue command_queue,
cl_uint num_objects,
const cl_mem* mem_objects,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event) CL_EXT_SUFFIX__VERSION_1_2;
#ifdef __cplusplus
}
#endif
#endif /* __OPENCL_CL_VA_API_MEDIA_SHARING_INTEL_H */
+2 -2
View File
@@ -17,7 +17,7 @@ file(GLOB lib_hdrs ${IPP_IW_PATH}/include/*.h ${IPP_IW_PATH}/include/iw/*.h ${IP
# Define the library target: # Define the library target:
# ---------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------
add_library(${IPP_IW_LIBRARY} STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${lib_srcs} ${lib_hdrs}) add_library(${IPP_IW_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs})
if(UNIX) if(UNIX)
if(CV_GCC OR CV_CLANG OR CV_ICC) if(CV_GCC OR CV_CLANG OR CV_ICC)
@@ -41,5 +41,5 @@ if(ENABLE_SOLUTION_FOLDERS)
endif() endif()
if(NOT BUILD_SHARED_LIBS) if(NOT BUILD_SHARED_LIBS)
ocv_install_target(${IPP_IW_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev OPTIONAL) ocv_install_target(${IPP_IW_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif() endif()
+16 -11
View File
@@ -2,32 +2,37 @@ function(download_ippicv root_var)
set(${root_var} "" PARENT_SCOPE) set(${root_var} "" PARENT_SCOPE)
# Commit SHA in the opencv_3rdparty repo # Commit SHA in the opencv_3rdparty repo
set(IPPICV_COMMIT "a56b6ac6f030c312b2dce17430eef13aed9af274") set(IPPICV_COMMIT "32e315a5b106a7b89dbed51c28f8120a48b368b4")
# Define actual ICV versions # Define actual ICV versions
if(APPLE) if(APPLE)
set(OPENCV_ICV_PLATFORM "macosx") set(OPENCV_ICV_PLATFORM "macosx")
set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_mac") set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_mac")
set(OPENCV_ICV_NAME "ippicv_2020_mac_intel64_20191018_general.tgz") if(X86_64)
set(OPENCV_ICV_HASH "1c3d675c2a2395d094d523024896e01b") set(OPENCV_ICV_NAME "ippicv_2019_mac_intel64_general_20180723.tgz")
set(OPENCV_ICV_HASH "fe6b2bb75ae0e3f19ad3ae1a31dfa4a2")
else()
set(OPENCV_ICV_NAME "ippicv_2019_mac_ia32_general_20180723.tgz")
set(OPENCV_ICV_HASH "b5dfa78c87eb75c64470cbe5ec876f4f")
endif()
elseif((UNIX AND NOT ANDROID) OR (UNIX AND ANDROID_ABI MATCHES "x86")) elseif((UNIX AND NOT ANDROID) OR (UNIX AND ANDROID_ABI MATCHES "x86"))
set(OPENCV_ICV_PLATFORM "linux") set(OPENCV_ICV_PLATFORM "linux")
set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_lnx") set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_lnx")
if(X86_64) if(X86_64)
set(OPENCV_ICV_NAME "ippicv_2020_lnx_intel64_20191018_general.tgz") set(OPENCV_ICV_NAME "ippicv_2019_lnx_intel64_general_20180723.tgz")
set(OPENCV_ICV_HASH "7421de0095c7a39162ae13a6098782f9") set(OPENCV_ICV_HASH "c0bd78adb4156bbf552c1dfe90599607")
else() else()
set(OPENCV_ICV_NAME "ippicv_2020_lnx_ia32_20191018_general.tgz") set(OPENCV_ICV_NAME "ippicv_2019_lnx_ia32_general_20180723.tgz")
set(OPENCV_ICV_HASH "ad189a940fb60eb71f291321322fe3e8") set(OPENCV_ICV_HASH "4f38432c30bfd6423164b7a24bbc98a0")
endif() endif()
elseif(WIN32 AND NOT ARM) elseif(WIN32 AND NOT ARM)
set(OPENCV_ICV_PLATFORM "windows") set(OPENCV_ICV_PLATFORM "windows")
set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_win") set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_win")
if(X86_64) if(X86_64)
set(OPENCV_ICV_NAME "ippicv_2020_win_intel64_20191018_general.zip") set(OPENCV_ICV_NAME "ippicv_2019_win_intel64_20180723_general.zip")
set(OPENCV_ICV_HASH "879741a7946b814455eee6c6ffde2984") set(OPENCV_ICV_HASH "1d222685246896fe089f88b8858e4b2f")
else() else()
set(OPENCV_ICV_NAME "ippicv_2020_win_ia32_20191018_general.zip") set(OPENCV_ICV_NAME "ippicv_2019_win_ia32_20180723_general.zip")
set(OPENCV_ICV_HASH "cd39bdf0c2e1cac9a61101dad7a2413e") set(OPENCV_ICV_HASH "0157251a2eb9cd63a3ebc7eed0f3e59e")
endif() endif()
else() else()
return() return()
+2 -2
View File
@@ -37,7 +37,7 @@ set(ITT_SRCS
src/ittnotify/jitprofiling.c src/ittnotify/jitprofiling.c
) )
add_library(${ITT_LIBRARY} STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${ITT_SRCS} ${ITT_PUBLIC_HDRS} ${ITT_PRIVATE_HDRS}) add_library(${ITT_LIBRARY} STATIC ${ITT_SRCS} ${ITT_PUBLIC_HDRS} ${ITT_PRIVATE_HDRS})
if(NOT WIN32) if(NOT WIN32)
if(HAVE_DL_LIBRARY) if(HAVE_DL_LIBRARY)
@@ -60,7 +60,7 @@ if(ENABLE_SOLUTION_FOLDERS)
endif() endif()
if(NOT BUILD_SHARED_LIBS) if(NOT BUILD_SHARED_LIBS)
ocv_install_target(${ITT_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev OPTIONAL) ocv_install_target(${ITT_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif() endif()
ocv_install_3rdparty_licenses(ittnotify src/ittnotify/LICENSE.BSD src/ittnotify/LICENSE.GPL) ocv_install_3rdparty_licenses(ittnotify src/ittnotify/LICENSE.BSD src/ittnotify/LICENSE.GPL)
+2 -2
View File
@@ -17,7 +17,7 @@ file(GLOB lib_ext_hdrs jasper/*.h)
# Define the library target: # Define the library target:
# ---------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------
add_library(${JASPER_LIBRARY} STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${lib_srcs} ${lib_hdrs} ${lib_ext_hdrs}) add_library(${JASPER_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs} ${lib_ext_hdrs})
if(WIN32 AND NOT MINGW) if(WIN32 AND NOT MINGW)
add_definitions(-DJAS_WIN_MSVC_BUILD) add_definitions(-DJAS_WIN_MSVC_BUILD)
@@ -46,7 +46,7 @@ if(ENABLE_SOLUTION_FOLDERS)
endif() endif()
if(NOT BUILD_SHARED_LIBS) if(NOT BUILD_SHARED_LIBS)
ocv_install_target(${JASPER_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev OPTIONAL) ocv_install_target(${JASPER_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif() endif()
ocv_install_3rdparty_licenses(jasper LICENSE README copyright) ocv_install_3rdparty_licenses(jasper LICENSE README copyright)
+6 -7
View File
@@ -3,10 +3,10 @@ project(${JPEG_LIBRARY} C)
ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter -Wsign-compare -Wshorten-64-to-32 -Wimplicit-fallthrough) ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter -Wsign-compare -Wshorten-64-to-32 -Wimplicit-fallthrough)
set(VERSION_MAJOR 2) set(VERSION_MAJOR 2)
set(VERSION_MINOR 1) set(VERSION_MINOR 0)
set(VERSION_REVISION 0) set(VERSION_REVISION 2)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}) set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION})
set(LIBJPEG_TURBO_VERSION_NUMBER 2001000) set(LIBJPEG_TURBO_VERSION_NUMBER 2000002)
string(TIMESTAMP BUILD "opencv-${OPENCV_VERSION}-libjpeg-turbo") string(TIMESTAMP BUILD "opencv-${OPENCV_VERSION}-libjpeg-turbo")
if(CMAKE_BUILD_TYPE STREQUAL "Debug") if(CMAKE_BUILD_TYPE STREQUAL "Debug")
@@ -46,6 +46,7 @@ if(UNIX)
ocv_update(HAVE_UNSIGNED_SHORT 1) ocv_update(HAVE_UNSIGNED_SHORT 1)
# undef INCOMPLETE_TYPES_BROKEN # undef INCOMPLETE_TYPES_BROKEN
ocv_update(RIGHT_SHIFT_IS_UNSIGNED 0) ocv_update(RIGHT_SHIFT_IS_UNSIGNED 0)
ocv_update(__CHAR_UNSIGNED__ 0)
endif() endif()
@@ -64,8 +65,6 @@ set(JPEG_LIB_VERSION 62)
# OpenCV # OpenCV
set(JPEG_LIB_VERSION "${VERSION}-${JPEG_LIB_VERSION}" PARENT_SCOPE) set(JPEG_LIB_VERSION "${VERSION}-${JPEG_LIB_VERSION}" PARENT_SCOPE)
set(THREAD_LOCAL "") # WITH_TURBOJPEG is not used
if(MSVC) if(MSVC)
add_definitions(-W3 -wd4996 -wd4018) add_definitions(-W3 -wd4996 -wd4018)
endif() endif()
@@ -105,7 +104,7 @@ set(JPEG_SOURCES ${JPEG_SOURCES} jsimd_none.c)
ocv_list_add_prefix(JPEG_SOURCES src/) ocv_list_add_prefix(JPEG_SOURCES src/)
add_library(${JPEG_LIBRARY} STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${JPEG_SOURCES} ${SIMD_OBJS}) add_library(${JPEG_LIBRARY} STATIC ${JPEG_SOURCES} ${SIMD_OBJS})
set_target_properties(${JPEG_LIBRARY} set_target_properties(${JPEG_LIBRARY}
PROPERTIES OUTPUT_NAME ${JPEG_LIBRARY} PROPERTIES OUTPUT_NAME ${JPEG_LIBRARY}
@@ -120,7 +119,7 @@ if(ENABLE_SOLUTION_FOLDERS)
endif() endif()
if(NOT BUILD_SHARED_LIBS) if(NOT BUILD_SHARED_LIBS)
ocv_install_target(${JPEG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev OPTIONAL) ocv_install_target(${JPEG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif() endif()
ocv_install_3rdparty_licenses(libjpeg-turbo README.md LICENSE.md README.ijg) ocv_install_3rdparty_licenses(libjpeg-turbo README.md LICENSE.md README.ijg)
+1 -1
View File
@@ -91,7 +91,7 @@ best of our understanding.
The Modified (3-clause) BSD License The Modified (3-clause) BSD License
=================================== ===================================
Copyright (C)2009-2021 D. R. Commander. All Rights Reserved.<br> Copyright (C)2009-2019 D. R. Commander. All Rights Reserved.
Copyright (C)2015 Viktor Szathmáry. All Rights Reserved. Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
+28 -9
View File
@@ -128,7 +128,7 @@ with respect to this software, its quality, accuracy, merchantability, or
fitness for a particular purpose. This software is provided "AS IS", and you, fitness for a particular purpose. This software is provided "AS IS", and you,
its user, assume the entire risk as to its quality and accuracy. its user, assume the entire risk as to its quality and accuracy.
This software is copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding. This software is copyright (C) 1991-2016, Thomas G. Lane, Guido Vollbeding.
All Rights Reserved except as specified below. All Rights Reserved except as specified below.
Permission is hereby granted to use, copy, modify, and distribute this Permission is hereby granted to use, copy, modify, and distribute this
@@ -159,6 +159,19 @@ commercial products, provided that all warranty or liability claims are
assumed by the product vendor. assumed by the product vendor.
The IJG distribution formerly included code to read and write GIF files.
To avoid entanglement with the Unisys LZW patent (now expired), GIF reading
support has been removed altogether, and the GIF writer has been simplified
to produce "uncompressed GIFs". This technique does not use the LZW
algorithm; the resulting GIF files are larger than usual, but are readable
by all standard GIF decoders.
We are required to state that
"The Graphics Interchange Format(c) is the Copyright property of
CompuServe Incorporated. GIF(sm) is a Service Mark property of
CompuServe Incorporated."
REFERENCES REFERENCES
========== ==========
@@ -210,12 +223,12 @@ https://www.iso.org/standard/54989.html and http://www.itu.int/rec/T-REC-T.871.
A PDF file of the older JFIF 1.02 specification is available at A PDF file of the older JFIF 1.02 specification is available at
http://www.w3.org/Graphics/JPEG/jfif3.pdf. http://www.w3.org/Graphics/JPEG/jfif3.pdf.
The TIFF 6.0 file format specification can be obtained from The TIFF 6.0 file format specification can be obtained by FTP from
http://mirrors.ctan.org/graphics/tiff/TIFF6.ps.gz. The JPEG incorporation ftp://ftp.sgi.com/graphics/tiff/TIFF6.ps.gz. The JPEG incorporation scheme
scheme found in the TIFF 6.0 spec of 3-June-92 has a number of serious found in the TIFF 6.0 spec of 3-June-92 has a number of serious problems.
problems. IJG does not recommend use of the TIFF 6.0 design (TIFF Compression IJG does not recommend use of the TIFF 6.0 design (TIFF Compression tag 6).
tag 6). Instead, we recommend the JPEG design proposed by TIFF Technical Note Instead, we recommend the JPEG design proposed by TIFF Technical Note #2
#2 (Compression tag 7). Copies of this Note can be obtained from (Compression tag 7). Copies of this Note can be obtained from
http://www.ijg.org/files/. It is expected that the next revision http://www.ijg.org/files/. It is expected that the next revision
of the TIFF spec will replace the 6.0 JPEG design with the Note's design. of the TIFF spec will replace the 6.0 JPEG design with the Note's design.
Although IJG's own code does not support TIFF/JPEG, the free libtiff library Although IJG's own code does not support TIFF/JPEG, the free libtiff library
@@ -230,8 +243,14 @@ The most recent released version can always be found there in
directory "files". directory "files".
The JPEG FAQ (Frequently Asked Questions) article is a source of some The JPEG FAQ (Frequently Asked Questions) article is a source of some
general information about JPEG. It is available at general information about JPEG.
http://www.faqs.org/faqs/jpeg-faq. It is available on the World Wide Web at http://www.faqs.org/faqs/jpeg-faq/
and other news.answers archive sites, including the official news.answers
archive at rtfm.mit.edu: ftp://rtfm.mit.edu/pub/usenet/news.answers/jpeg-faq/.
If you don't have Web or FTP access, send e-mail to mail-server@rtfm.mit.edu
with body
send usenet/news.answers/jpeg-faq/part1
send usenet/news.answers/jpeg-faq/part2
FILE FORMAT COMPATIBILITY FILE FORMAT COMPATIBILITY
+35 -46
View File
@@ -1,14 +1,14 @@
Background Background
========== ==========
libjpeg-turbo is a JPEG image codec that uses SIMD instructions to accelerate libjpeg-turbo is a JPEG image codec that uses SIMD instructions (MMX, SSE2,
baseline JPEG compression and decompression on x86, x86-64, Arm, PowerPC, and AVX2, NEON, AltiVec) to accelerate baseline JPEG compression and decompression
MIPS systems, as well as progressive JPEG compression on x86, x86-64, and Arm on x86, x86-64, ARM, and PowerPC systems, as well as progressive JPEG
systems. On such systems, libjpeg-turbo is generally 2-6x as fast as libjpeg, compression on x86 and x86-64 systems. On such systems, libjpeg-turbo is
all else being equal. On other types of systems, libjpeg-turbo can still generally 2-6x as fast as libjpeg, all else being equal. On other types of
outperform libjpeg by a significant amount, by virtue of its highly-optimized systems, libjpeg-turbo can still outperform libjpeg by a significant amount, by
Huffman coding routines. In many cases, the performance of libjpeg-turbo virtue of its highly-optimized Huffman coding routines. In many cases, the
rivals that of proprietary high-speed JPEG codecs. performance of libjpeg-turbo rivals that of proprietary high-speed JPEG codecs.
libjpeg-turbo implements both the traditional libjpeg API as well as the less libjpeg-turbo implements both the traditional libjpeg API as well as the less
powerful but more straightforward TurboJPEG API. libjpeg-turbo also features powerful but more straightforward TurboJPEG API. libjpeg-turbo also features
@@ -135,24 +135,25 @@ without recompiling. libjpeg-turbo does not claim to support all of the
libjpeg v7+ features, nor to produce identical output to libjpeg v7+ in all libjpeg v7+ features, nor to produce identical output to libjpeg v7+ in all
cases (see below.) cases (see below.)
By passing an argument of `-DWITH_JPEG7=1` or `-DWITH_JPEG8=1` to `cmake`, you By passing an argument of `--with-jpeg7` or `--with-jpeg8` to `configure`, or
can build a version of libjpeg-turbo that emulates the libjpeg v7 or v8 ABI, so an argument of `-DWITH_JPEG7=1` or `-DWITH_JPEG8=1` to `cmake`, you can build a
that programs that are built against libjpeg v7 or v8 can be run with version of libjpeg-turbo that emulates the libjpeg v7 or v8 ABI, so that
libjpeg-turbo. The following section describes which libjpeg v7+ features are programs that are built against libjpeg v7 or v8 can be run with libjpeg-turbo.
supported and which aren't. The following section describes which libjpeg v7+ features are supported and
which aren't.
### Support for libjpeg v7 and v8 Features ### Support for libjpeg v7 and v8 Features
#### Fully supported #### Fully supported
- **libjpeg API: IDCT scaling extensions in decompressor**<br> - **libjpeg: IDCT scaling extensions in decompressor**<br>
libjpeg-turbo supports IDCT scaling with scaling factors of 1/8, 1/4, 3/8, libjpeg-turbo supports IDCT scaling with scaling factors of 1/8, 1/4, 3/8,
1/2, 5/8, 3/4, 7/8, 9/8, 5/4, 11/8, 3/2, 13/8, 7/4, 15/8, and 2/1 (only 1/4 1/2, 5/8, 3/4, 7/8, 9/8, 5/4, 11/8, 3/2, 13/8, 7/4, 15/8, and 2/1 (only 1/4
and 1/2 are SIMD-accelerated.) and 1/2 are SIMD-accelerated.)
- **libjpeg API: Arithmetic coding** - **libjpeg: Arithmetic coding**
- **libjpeg API: In-memory source and destination managers**<br> - **libjpeg: In-memory source and destination managers**<br>
See notes below. See notes below.
- **cjpeg: Separate quality settings for luminance and chrominance**<br> - **cjpeg: Separate quality settings for luminance and chrominance**<br>
@@ -179,19 +180,19 @@ supported and which aren't.
NOTE: As of this writing, extensive research has been conducted into the NOTE: As of this writing, extensive research has been conducted into the
usefulness of DCT scaling as a means of data reduction and SmartScale as a usefulness of DCT scaling as a means of data reduction and SmartScale as a
means of quality improvement. Readers are invited to peruse the research at means of quality improvement. The reader is invited to peruse the research at
<http://www.libjpeg-turbo.org/About/SmartScale> and draw their own conclusions, <http://www.libjpeg-turbo.org/About/SmartScale> and draw his/her own conclusions,
but it is the general belief of our project that these features have not but it is the general belief of our project that these features have not
demonstrated sufficient usefulness to justify inclusion in libjpeg-turbo. demonstrated sufficient usefulness to justify inclusion in libjpeg-turbo.
- **libjpeg API: DCT scaling in compressor**<br> - **libjpeg: DCT scaling in compressor**<br>
`cinfo.scale_num` and `cinfo.scale_denom` are silently ignored. `cinfo.scale_num` and `cinfo.scale_denom` are silently ignored.
There is no technical reason why DCT scaling could not be supported when There is no technical reason why DCT scaling could not be supported when
emulating the libjpeg v7+ API/ABI, but without the SmartScale extension (see emulating the libjpeg v7+ API/ABI, but without the SmartScale extension (see
below), only scaling factors of 1/2, 8/15, 4/7, 8/13, 2/3, 8/11, 4/5, and below), only scaling factors of 1/2, 8/15, 4/7, 8/13, 2/3, 8/11, 4/5, and
8/9 would be available, which is of limited usefulness. 8/9 would be available, which is of limited usefulness.
- **libjpeg API: SmartScale**<br> - **libjpeg: SmartScale**<br>
`cinfo.block_size` is silently ignored. `cinfo.block_size` is silently ignored.
SmartScale is an extension to the JPEG format that allows for DCT block SmartScale is an extension to the JPEG format that allows for DCT block
sizes other than 8x8. Providing support for this new format would be sizes other than 8x8. Providing support for this new format would be
@@ -204,7 +205,7 @@ demonstrated sufficient usefulness to justify inclusion in libjpeg-turbo.
interest in providing this feature would be as a means of supporting interest in providing this feature would be as a means of supporting
additional DCT scaling factors. additional DCT scaling factors.
- **libjpeg API: Fancy downsampling in compressor**<br> - **libjpeg: Fancy downsampling in compressor**<br>
`cinfo.do_fancy_downsampling` is silently ignored. `cinfo.do_fancy_downsampling` is silently ignored.
This requires the DCT scaling feature, which is not supported. This requires the DCT scaling feature, which is not supported.
@@ -246,14 +247,15 @@ don't, and it allows those functions to be provided in the "official"
libjpeg-turbo binaries. libjpeg-turbo binaries.
Those who are concerned about maintaining strict conformance with the libjpeg 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 v6b or v7 API can pass an argument of `--without-mem-srcdst` to `configure` or
building libjpeg-turbo. This will restore the pre-1.3 behavior, in which 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 `jpeg_mem_src()` and `jpeg_mem_dest()` are only included when emulating the
libjpeg v8 API/ABI. libjpeg v8 API/ABI.
On Un*x systems, including the in-memory source/destination managers changes 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 the dynamic library version from 62.1.0 to 62.2.0 if using libjpeg v6b API/ABI
emulation and from 7.2.0 to 7.3.0 if using libjpeg v7 API/ABI emulation. emulation and from 7.1.0 to 7.2.0 if using libjpeg v7 API/ABI emulation.
Note that, on most Un*x systems, the dynamic linker will not look for a 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 function in a library until that function is actually used. Thus, if a program
@@ -287,13 +289,12 @@ following reasons:
(and slightly faster) floating point IDCT algorithm introduced in libjpeg (and slightly faster) floating point IDCT algorithm introduced in libjpeg
v8a as opposed to the algorithm used in libjpeg v6b. It should be noted, 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 however, that this algorithm basically brings the accuracy of the floating
point IDCT in line with the accuracy of the accurate integer IDCT. The point IDCT in line with the accuracy of the slow integer IDCT. The floating
floating point DCT/IDCT algorithms are mainly a legacy feature, and they do point DCT/IDCT algorithms are mainly a legacy feature, and they do not
not produce significantly more accuracy than the accurate integer algorithms produce significantly more accuracy than the slow integer algorithms (to put
(to put numbers on this, the typical difference in PNSR between the two numbers on this, the typical difference in PNSR between the two algorithms
algorithms is less than 0.10 dB, whereas changing the quality level by 1 in is less than 0.10 dB, whereas changing the quality level by 1 in the upper
the upper range of the quality scale is typically more like a 1.0 dB range of the quality scale is typically more like a 1.0 dB difference.)
difference.)
- If the floating point algorithms in libjpeg-turbo are not implemented using - If the floating point algorithms in libjpeg-turbo are not implemented using
SIMD instructions on a particular platform, then the accuracy of the SIMD instructions on a particular platform, then the accuracy of the
@@ -330,7 +331,7 @@ in a way that makes the rest of the libjpeg infrastructure happy, so it is
necessary to use the slow Huffman decoder when decompressing a JPEG image that necessary to use the slow Huffman decoder when decompressing a JPEG image that
has restart markers. This can cause the decompression performance to drop by has restart markers. This can cause the decompression performance to drop by
as much as 20%, but the performance will still be much greater than that of as much as 20%, but the performance will still be much greater than that of
libjpeg. Many consumer packages, such as Photoshop, use restart markers when libjpeg. Many consumer packages, such as PhotoShop, use restart markers when
generating JPEG images, so images generated by those programs will experience generating JPEG images, so images generated by those programs will experience
this issue. this issue.
@@ -341,17 +342,5 @@ The algorithm used by the SIMD-accelerated quantization function cannot produce
correct results whenever the fast integer forward DCT is used along with a JPEG correct results whenever the fast integer forward DCT is used along with a JPEG
quality of 98-100. Thus, libjpeg-turbo must use the non-SIMD quantization quality of 98-100. Thus, libjpeg-turbo must use the non-SIMD quantization
function in those cases. This causes performance to drop by as much as 40%. function in those cases. This causes performance to drop by as much as 40%.
It is therefore strongly advised that you use the accurate integer forward DCT It is therefore strongly advised that you use the slow integer forward DCT
whenever encoding images with a JPEG quality of 98 or higher. whenever encoding images with a JPEG quality of 98 or higher.
Memory Debugger Pitfalls
========================
Valgrind and Memory Sanitizer (MSan) can generate false positives
(specifically, incorrect reports of uninitialized memory accesses) when used
with libjpeg-turbo's SIMD extensions. It is generally recommended that the
SIMD extensions be disabled, either by passing an argument of `-DWITH_SIMD=0`
to `cmake` when configuring the build or by setting the environment variable
`JSIMD_FORCENONE` to `1` at run time, when testing libjpeg-turbo with Valgrind,
MSan, or other memory debuggers.
+5
View File
@@ -61,6 +61,11 @@
unsigned. */ unsigned. */
#cmakedefine RIGHT_SHIFT_IS_UNSIGNED 1 #cmakedefine RIGHT_SHIFT_IS_UNSIGNED 1
/* Define to 1 if type `char' is unsigned and you are not using gcc. */
#ifndef __CHAR_UNSIGNED__
#cmakedefine __CHAR_UNSIGNED__ 1
#endif
/* Define to empty if `const' does not conform to ANSI C. */ /* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */ /* #undef const */
+1
View File
@@ -18,6 +18,7 @@
#define HAVE_UNSIGNED_SHORT #define HAVE_UNSIGNED_SHORT
#undef INCOMPLETE_TYPES_BROKEN #undef INCOMPLETE_TYPES_BROKEN
#undef RIGHT_SHIFT_IS_UNSIGNED #undef RIGHT_SHIFT_IS_UNSIGNED
#undef __CHAR_UNSIGNED__
/* Define "boolean" as unsigned char, not int, per Windows custom */ /* Define "boolean" as unsigned char, not int, per Windows custom */
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
-3
View File
@@ -15,9 +15,6 @@
#endif #endif
#endif #endif
/* How to obtain thread-local storage */
#define THREAD_LOCAL @THREAD_LOCAL@
/* Define to the full name of this package. */ /* Define to the full name of this package. */
#define PACKAGE_NAME "@CMAKE_PROJECT_NAME@" #define PACKAGE_NAME "@CMAKE_PROJECT_NAME@"
+9 -9
View File
@@ -48,9 +48,9 @@ rgb_ycc_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
outptr2 = output_buf[2][output_row]; outptr2 = output_buf[2][output_row];
output_row++; output_row++;
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
r = inptr[RGB_RED]; r = GETJSAMPLE(inptr[RGB_RED]);
g = inptr[RGB_GREEN]; g = GETJSAMPLE(inptr[RGB_GREEN]);
b = inptr[RGB_BLUE]; b = GETJSAMPLE(inptr[RGB_BLUE]);
inptr += RGB_PIXELSIZE; 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. * must be too; we do not need an explicit range-limiting operation.
@@ -100,9 +100,9 @@ rgb_gray_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
outptr = output_buf[0][output_row]; outptr = output_buf[0][output_row];
output_row++; output_row++;
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
r = inptr[RGB_RED]; r = GETJSAMPLE(inptr[RGB_RED]);
g = inptr[RGB_GREEN]; g = GETJSAMPLE(inptr[RGB_GREEN]);
b = inptr[RGB_BLUE]; b = GETJSAMPLE(inptr[RGB_BLUE]);
inptr += RGB_PIXELSIZE; inptr += RGB_PIXELSIZE;
/* Y */ /* Y */
outptr[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] + outptr[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
@@ -135,9 +135,9 @@ rgb_rgb_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
outptr2 = output_buf[2][output_row]; outptr2 = output_buf[2][output_row];
output_row++; output_row++;
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
outptr0[col] = inptr[RGB_RED]; outptr0[col] = GETJSAMPLE(inptr[RGB_RED]);
outptr1[col] = inptr[RGB_GREEN]; outptr1[col] = GETJSAMPLE(inptr[RGB_GREEN]);
outptr2[col] = inptr[RGB_BLUE]; outptr2[col] = GETJSAMPLE(inptr[RGB_BLUE]);
inptr += RGB_PIXELSIZE; inptr += RGB_PIXELSIZE;
} }
} }
+6 -6
View File
@@ -392,11 +392,11 @@ cmyk_ycck_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
outptr3 = output_buf[3][output_row]; outptr3 = output_buf[3][output_row];
output_row++; output_row++;
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
r = MAXJSAMPLE - inptr[0]; r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
g = MAXJSAMPLE - inptr[1]; g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
b = MAXJSAMPLE - inptr[2]; b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
/* K passes through as-is */ /* K passes through as-is */
outptr3[col] = inptr[3]; outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
inptr += 4; inptr += 4;
/* If the inputs are 0..MAXJSAMPLE, the outputs of these equations /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
* must be too; we do not need an explicit range-limiting operation. * must be too; we do not need an explicit range-limiting operation.
@@ -438,7 +438,7 @@ grayscale_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
outptr = output_buf[0][output_row]; outptr = output_buf[0][output_row];
output_row++; output_row++;
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
outptr[col] = inptr[0]; outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
inptr += instride; inptr += instride;
} }
} }
@@ -497,7 +497,7 @@ null_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
inptr = *input_buf; inptr = *input_buf;
outptr = output_buf[ci][output_row]; outptr = output_buf[ci][output_row];
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
outptr[col] = inptr[ci]; outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
inptr += nc; inptr += nc;
} }
} }
+19 -18
View File
@@ -381,19 +381,19 @@ convsamp(JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM *workspace)
elemptr = sample_data[elemr] + start_col; elemptr = sample_data[elemr] + start_col;
#if DCTSIZE == 8 /* unroll the inner loop */ #if DCTSIZE == 8 /* unroll the inner loop */
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE; *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE; *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE; *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE; *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE; *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE; *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE; *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE; *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
#else #else
{ {
register int elemc; register int elemc;
for (elemc = DCTSIZE; elemc > 0; elemc--) for (elemc = DCTSIZE; elemc > 0; elemc--)
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE; *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
} }
#endif #endif
} }
@@ -533,19 +533,20 @@ convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
for (elemr = 0; elemr < DCTSIZE; elemr++) { for (elemr = 0; elemr < DCTSIZE; elemr++) {
elemptr = sample_data[elemr] + start_col; elemptr = sample_data[elemr] + start_col;
#if DCTSIZE == 8 /* unroll the inner loop */ #if DCTSIZE == 8 /* unroll the inner loop */
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE); *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE); *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE); *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE); *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE); *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE); *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE); *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE); *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
#else #else
{ {
register int elemc; register int elemc;
for (elemc = DCTSIZE; elemc > 0; elemc--) for (elemc = DCTSIZE; elemc > 0; elemc--)
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE); *workspaceptr++ = (FAST_FLOAT)
(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
} }
#endif #endif
} }
+180 -224
View File
@@ -4,10 +4,8 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009-2011, 2014-2016, 2018-2021, D. R. Commander. * Copyright (C) 2009-2011, 2014-2016, 2018, D. R. Commander.
* Copyright (C) 2015, Matthieu Darbois. * Copyright (C) 2015, Matthieu Darbois.
* Copyright (C) 2018, Matthias Räncker.
* Copyright (C) 2020, Arm Limited.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -36,27 +34,23 @@
* memory footprint by 64k, which is important for some mobile applications * memory footprint by 64k, which is important for some mobile applications
* that create many isolated instances of libjpeg-turbo (web browsers, for * that create many isolated instances of libjpeg-turbo (web browsers, for
* instance.) This may improve performance on some mobile platforms as well. * instance.) This may improve performance on some mobile platforms as well.
* This feature is enabled by default only on Arm processors, because some x86 * 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 * 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 * 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 * 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 * explicitly disable the use of clz/bsr by adding -mthumb to the compiler
* flags (this defines __thumb__). * flags (this defines __thumb__).
*/ */
#if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) || \ /* NOTE: Both GCC and Clang define __GNUC__ */
defined(_M_ARM64) #if defined __GNUC__ && (defined __arm__ || defined __aarch64__)
#if !defined(__thumb__) || defined(__thumb2__) #if !defined __thumb__ || defined __thumb2__
#define USE_CLZ_INTRINSIC #define USE_CLZ_INTRINSIC
#endif #endif
#endif #endif
#ifdef USE_CLZ_INTRINSIC #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)) #define JPEG_NBITS_NONZERO(x) (32 - __builtin_clz(x))
#endif
#define JPEG_NBITS(x) (x ? JPEG_NBITS_NONZERO(x) : 0) #define JPEG_NBITS(x) (x ? JPEG_NBITS_NONZERO(x) : 0)
#else #else
#include "jpeg_nbits_table.h" #include "jpeg_nbits_table.h"
@@ -71,43 +65,32 @@
* but must not be updated permanently until we complete the MCU. * but must not be updated permanently until we complete the MCU.
*/ */
#if defined(__x86_64__) && defined(__ILP32__)
typedef unsigned long long bit_buf_type;
#else
typedef size_t bit_buf_type;
#endif
/* NOTE: The more optimal Huffman encoding algorithm is only used by the
* intrinsics implementation of the Arm Neon SIMD extensions, which is why we
* retain the old Huffman encoder behavior when using the GAS implementation.
*/
#if defined(WITH_SIMD) && !(defined(__arm__) || defined(__aarch64__) || \
defined(_M_ARM) || defined(_M_ARM64))
typedef unsigned long long simd_bit_buf_type;
#else
typedef bit_buf_type simd_bit_buf_type;
#endif
#if (defined(SIZEOF_SIZE_T) && SIZEOF_SIZE_T == 8) || defined(_WIN64) || \
(defined(__x86_64__) && defined(__ILP32__))
#define BIT_BUF_SIZE 64
#elif (defined(SIZEOF_SIZE_T) && SIZEOF_SIZE_T == 4) || defined(_WIN32)
#define BIT_BUF_SIZE 32
#else
#error Cannot determine word size
#endif
#define SIMD_BIT_BUF_SIZE (sizeof(simd_bit_buf_type) * 8)
typedef struct { typedef struct {
union { size_t put_buffer; /* current bit-accumulation buffer */
bit_buf_type c; int put_bits; /* # of bits now in it */
simd_bit_buf_type simd;
} put_buffer; /* current bit accumulation buffer */
int free_bits; /* # of bits available in it */
/* (Neon GAS: # of bits now in it) */
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
} savable_state; } savable_state;
/* This macro is to work around compilers with missing or broken
* structure assignment. You'll need to fix this code if you have
* such a compiler and you change MAX_COMPS_IN_SCAN.
*/
#ifndef NO_STRUCT_ASSIGN
#define ASSIGN_STATE(dest, src) ((dest) = (src))
#else
#if MAX_COMPS_IN_SCAN == 4
#define ASSIGN_STATE(dest, src) \
((dest).put_buffer = (src).put_buffer, \
(dest).put_bits = (src).put_bits, \
(dest).last_dc_val[0] = (src).last_dc_val[0], \
(dest).last_dc_val[1] = (src).last_dc_val[1], \
(dest).last_dc_val[2] = (src).last_dc_val[2], \
(dest).last_dc_val[3] = (src).last_dc_val[3])
#endif
#endif
typedef struct { typedef struct {
struct jpeg_entropy_encoder pub; /* public fields */ struct jpeg_entropy_encoder pub; /* public fields */
@@ -140,7 +123,6 @@ typedef struct {
size_t free_in_buffer; /* # of byte spaces remaining in buffer */ size_t free_in_buffer; /* # of byte spaces remaining in buffer */
savable_state cur; /* Current bit buffer & DC state */ savable_state cur; /* Current bit buffer & DC state */
j_compress_ptr cinfo; /* dump_buffer needs access to this */ j_compress_ptr cinfo; /* dump_buffer needs access to this */
int simd;
} working_state; } working_state;
@@ -219,17 +201,8 @@ start_pass_huff(j_compress_ptr cinfo, boolean gather_statistics)
} }
/* Initialize bit buffer to empty */ /* Initialize bit buffer to empty */
if (entropy->simd) { entropy->saved.put_buffer = 0;
entropy->saved.put_buffer.simd = 0; entropy->saved.put_bits = 0;
#if defined(__aarch64__) && !defined(NEON_INTRINSICS)
entropy->saved.free_bits = 0;
#else
entropy->saved.free_bits = SIMD_BIT_BUF_SIZE;
#endif
} else {
entropy->saved.put_buffer.c = 0;
entropy->saved.free_bits = BIT_BUF_SIZE;
}
/* Initialize restart stuff */ /* Initialize restart stuff */
entropy->restarts_to_go = cinfo->restart_interval; entropy->restarts_to_go = cinfo->restart_interval;
@@ -314,7 +287,6 @@ jpeg_make_c_derived_tbl(j_compress_ptr cinfo, boolean isDC, int tblno,
* this lets us detect duplicate VAL entries here, and later * this lets us detect duplicate VAL entries here, and later
* allows emit_bits to detect any attempt to emit such symbols. * allows emit_bits to detect any attempt to emit such symbols.
*/ */
MEMZERO(dtbl->ehufco, sizeof(dtbl->ehufco));
MEMZERO(dtbl->ehufsi, sizeof(dtbl->ehufsi)); MEMZERO(dtbl->ehufsi, sizeof(dtbl->ehufsi));
/* This is also a convenient place to check for out-of-range /* This is also a convenient place to check for out-of-range
@@ -362,94 +334,90 @@ dump_buffer(working_state *state)
/* Outputting bits to the file */ /* Outputting bits to the file */
/* Output byte b and, speculatively, an additional 0 byte. 0xFF must be /* These macros perform the same task as the emit_bits() function in the
* encoded as 0xFF 0x00, so the output buffer pointer is advanced by 2 if the * original libjpeg code. In addition to reducing overhead by explicitly
* byte is 0xFF. Otherwise, the output buffer pointer is advanced by 1, and * inlining the code, additional performance is achieved by taking into
* the speculative 0 byte will be overwritten by the next byte. * account the size of the bit buffer and waiting until it is almost full
* before emptying it. This mostly benefits 64-bit platforms, since 6
* bytes can be stored in a 64-bit bit buffer before it has to be emptied.
*/ */
#define EMIT_BYTE(b) { \
buffer[0] = (JOCTET)(b); \ #define EMIT_BYTE() { \
buffer[1] = 0; \ JOCTET c; \
buffer -= -2 + ((JOCTET)(b) < 0xFF); \ put_bits -= 8; \
c = (JOCTET)GETJOCTET(put_buffer >> put_bits); \
*buffer++ = c; \
if (c == 0xFF) /* need to stuff a zero byte? */ \
*buffer++ = 0; \
} }
/* Output the entire bit buffer. If there are no 0xFF bytes in it, then write #define PUT_BITS(code, size) { \
* directly to the output buffer. Otherwise, use the EMIT_BYTE() macro to put_bits += size; \
* encode 0xFF as 0xFF 0x00. put_buffer = (put_buffer << size) | code; \
*/ }
#if BIT_BUF_SIZE == 64
#define FLUSH() { \ #define CHECKBUF15() { \
if (put_buffer & 0x8080808080808080 & ~(put_buffer + 0x0101010101010101)) { \ if (put_bits > 15) { \
EMIT_BYTE(put_buffer >> 56) \ EMIT_BYTE() \
EMIT_BYTE(put_buffer >> 48) \ EMIT_BYTE() \
EMIT_BYTE(put_buffer >> 40) \
EMIT_BYTE(put_buffer >> 32) \
EMIT_BYTE(put_buffer >> 24) \
EMIT_BYTE(put_buffer >> 16) \
EMIT_BYTE(put_buffer >> 8) \
EMIT_BYTE(put_buffer ) \
} else { \
buffer[0] = (JOCTET)(put_buffer >> 56); \
buffer[1] = (JOCTET)(put_buffer >> 48); \
buffer[2] = (JOCTET)(put_buffer >> 40); \
buffer[3] = (JOCTET)(put_buffer >> 32); \
buffer[4] = (JOCTET)(put_buffer >> 24); \
buffer[5] = (JOCTET)(put_buffer >> 16); \
buffer[6] = (JOCTET)(put_buffer >> 8); \
buffer[7] = (JOCTET)(put_buffer); \
buffer += 8; \
} \ } \
} }
#define CHECKBUF31() { \
if (put_bits > 31) { \
EMIT_BYTE() \
EMIT_BYTE() \
EMIT_BYTE() \
EMIT_BYTE() \
} \
}
#define CHECKBUF47() { \
if (put_bits > 47) { \
EMIT_BYTE() \
EMIT_BYTE() \
EMIT_BYTE() \
EMIT_BYTE() \
EMIT_BYTE() \
EMIT_BYTE() \
} \
}
#if !defined(_WIN32) && !defined(SIZEOF_SIZE_T)
#error Cannot determine word size
#endif
#if SIZEOF_SIZE_T == 8 || defined(_WIN64)
#define EMIT_BITS(code, size) { \
CHECKBUF47() \
PUT_BITS(code, size) \
}
#define EMIT_CODE(code, size) { \
temp2 &= (((JLONG)1) << nbits) - 1; \
CHECKBUF31() \
PUT_BITS(code, size) \
PUT_BITS(temp2, nbits) \
}
#else #else
#define FLUSH() { \ #define EMIT_BITS(code, size) { \
if (put_buffer & 0x80808080 & ~(put_buffer + 0x01010101)) { \ PUT_BITS(code, size) \
EMIT_BYTE(put_buffer >> 24) \ CHECKBUF15() \
EMIT_BYTE(put_buffer >> 16) \ }
EMIT_BYTE(put_buffer >> 8) \
EMIT_BYTE(put_buffer ) \ #define EMIT_CODE(code, size) { \
} else { \ temp2 &= (((JLONG)1) << nbits) - 1; \
buffer[0] = (JOCTET)(put_buffer >> 24); \ PUT_BITS(code, size) \
buffer[1] = (JOCTET)(put_buffer >> 16); \ CHECKBUF15() \
buffer[2] = (JOCTET)(put_buffer >> 8); \ PUT_BITS(temp2, nbits) \
buffer[3] = (JOCTET)(put_buffer); \ CHECKBUF15() \
buffer += 4; \
} \
} }
#endif #endif
/* Fill the bit buffer to capacity with the leading bits from code, then output
* the bit buffer and put the remaining bits from code into the bit buffer.
*/
#define PUT_AND_FLUSH(code, size) { \
put_buffer = (put_buffer << (size + free_bits)) | (code >> -free_bits); \
FLUSH() \
free_bits += BIT_BUF_SIZE; \
put_buffer = code; \
}
/* Insert code into the bit buffer and output the bit buffer if needed.
* NOTE: We can't flush with free_bits == 0, since the left shift in
* PUT_AND_FLUSH() would have undefined behavior.
*/
#define PUT_BITS(code, size) { \
free_bits -= size; \
if (free_bits < 0) \
PUT_AND_FLUSH(code, size) \
else \
put_buffer = (put_buffer << size) | code; \
}
#define PUT_CODE(code, size) { \
temp &= (((JLONG)1) << nbits) - 1; \
temp |= code << nbits; \
nbits += size; \
PUT_BITS(temp, nbits) \
}
/* Although it is exceedingly rare, it is possible for a Huffman-encoded /* Although it is exceedingly rare, it is possible for a Huffman-encoded
* coefficient block to be larger than the 128-byte unencoded block. For each * coefficient block to be larger than the 128-byte unencoded block. For each
@@ -460,7 +428,7 @@ dump_buffer(working_state *state)
* scanning order-- 1, 8, 16, etc.), then this will produce an encoded block * scanning order-- 1, 8, 16, etc.), then this will produce an encoded block
* larger than 200 bytes. * larger than 200 bytes.
*/ */
#define BUFSIZE (DCTSIZE2 * 8) #define BUFSIZE (DCTSIZE2 * 4)
#define LOAD_BUFFER() { \ #define LOAD_BUFFER() { \
if (state->free_in_buffer < BUFSIZE) { \ if (state->free_in_buffer < BUFSIZE) { \
@@ -472,7 +440,6 @@ dump_buffer(working_state *state)
#define STORE_BUFFER() { \ #define STORE_BUFFER() { \
if (localbuf) { \ if (localbuf) { \
size_t bytes, bytestocopy; \
bytes = buffer - _buffer; \ bytes = buffer - _buffer; \
buffer = _buffer; \ buffer = _buffer; \
while (bytes > 0) { \ while (bytes > 0) { \
@@ -495,46 +462,20 @@ dump_buffer(working_state *state)
LOCAL(boolean) LOCAL(boolean)
flush_bits(working_state *state) flush_bits(working_state *state)
{ {
JOCTET _buffer[BUFSIZE], *buffer, temp; JOCTET _buffer[BUFSIZE], *buffer;
simd_bit_buf_type put_buffer; int put_bits; size_t put_buffer; int put_bits;
int localbuf = 0; size_t bytes, bytestocopy; int localbuf = 0;
if (state->simd) {
#if defined(__aarch64__) && !defined(NEON_INTRINSICS)
put_bits = state->cur.free_bits;
#else
put_bits = SIMD_BIT_BUF_SIZE - state->cur.free_bits;
#endif
put_buffer = state->cur.put_buffer.simd;
} else {
put_bits = BIT_BUF_SIZE - state->cur.free_bits;
put_buffer = state->cur.put_buffer.c;
}
put_buffer = state->cur.put_buffer;
put_bits = state->cur.put_bits;
LOAD_BUFFER() LOAD_BUFFER()
while (put_bits >= 8) { /* fill any partial byte with ones */
put_bits -= 8; PUT_BITS(0x7F, 7)
temp = (JOCTET)(put_buffer >> put_bits); while (put_bits >= 8) EMIT_BYTE()
EMIT_BYTE(temp)
}
if (put_bits) {
/* fill partial byte with ones */
temp = (JOCTET)((put_buffer << (8 - put_bits)) | (0xFF >> put_bits));
EMIT_BYTE(temp)
}
if (state->simd) { /* and reset bit buffer to empty */ state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
state->cur.put_buffer.simd = 0; state->cur.put_bits = 0;
#if defined(__aarch64__) && !defined(NEON_INTRINSICS)
state->cur.free_bits = 0;
#else
state->cur.free_bits = SIMD_BIT_BUF_SIZE;
#endif
} else {
state->cur.put_buffer.c = 0;
state->cur.free_bits = BIT_BUF_SIZE;
}
STORE_BUFFER() STORE_BUFFER()
return TRUE; return TRUE;
@@ -548,7 +489,7 @@ encode_one_block_simd(working_state *state, JCOEFPTR block, int last_dc_val,
c_derived_tbl *dctbl, c_derived_tbl *actbl) c_derived_tbl *dctbl, c_derived_tbl *actbl)
{ {
JOCTET _buffer[BUFSIZE], *buffer; JOCTET _buffer[BUFSIZE], *buffer;
int localbuf = 0; size_t bytes, bytestocopy; int localbuf = 0;
LOAD_BUFFER() LOAD_BUFFER()
@@ -564,41 +505,53 @@ LOCAL(boolean)
encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val, encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val,
c_derived_tbl *dctbl, c_derived_tbl *actbl) c_derived_tbl *dctbl, c_derived_tbl *actbl)
{ {
int temp, nbits, free_bits; int temp, temp2, temp3;
bit_buf_type put_buffer; int nbits;
int r, code, size;
JOCTET _buffer[BUFSIZE], *buffer; JOCTET _buffer[BUFSIZE], *buffer;
int localbuf = 0; size_t put_buffer; int put_bits;
int code_0xf0 = actbl->ehufco[0xf0], size_0xf0 = actbl->ehufsi[0xf0];
size_t bytes, bytestocopy; int localbuf = 0;
free_bits = state->cur.free_bits; put_buffer = state->cur.put_buffer;
put_buffer = state->cur.put_buffer.c; put_bits = state->cur.put_bits;
LOAD_BUFFER() LOAD_BUFFER()
/* Encode the DC coefficient difference per section F.1.2.1 */ /* Encode the DC coefficient difference per section F.1.2.1 */
temp = block[0] - last_dc_val; temp = temp2 = block[0] - last_dc_val;
/* This is a well-known technique for obtaining the absolute value without a /* This is a well-known technique for obtaining the absolute value without a
* branch. It is derived from an assembly language technique presented in * branch. It is derived from an assembly language technique presented in
* "How to Optimize for the Pentium Processors", Copyright (c) 1996, 1997 by * "How to Optimize for the Pentium Processors", Copyright (c) 1996, 1997 by
* Agner Fog. This code assumes we are on a two's complement machine. * Agner Fog.
*/ */
nbits = temp >> (CHAR_BIT * sizeof(int) - 1); temp3 = temp >> (CHAR_BIT * sizeof(int) - 1);
temp += nbits; temp ^= temp3;
nbits ^= temp; temp -= temp3;
/* For a negative input, want temp2 = bitwise complement of abs(input) */
/* This code assumes we are on a two's complement machine */
temp2 += temp3;
/* Find the number of bits needed for the magnitude of the coefficient */ /* Find the number of bits needed for the magnitude of the coefficient */
nbits = JPEG_NBITS(nbits); nbits = JPEG_NBITS(temp);
/* Emit the Huffman-coded symbol for the number of bits. /* Emit the Huffman-coded symbol for the number of bits */
* Emit that number of bits of the value, if positive, code = dctbl->ehufco[nbits];
* or the complement of its magnitude, if negative. size = dctbl->ehufsi[nbits];
*/ EMIT_BITS(code, size)
PUT_CODE(dctbl->ehufco[nbits], dctbl->ehufsi[nbits])
/* Mask off any extra bits in code */
temp2 &= (((JLONG)1) << nbits) - 1;
/* Emit that number of bits of the value, if positive, */
/* or the complement of its magnitude, if negative. */
EMIT_BITS(temp2, nbits)
/* Encode the AC coefficients per section F.1.2.2 */ /* Encode the AC coefficients per section F.1.2.2 */
{ r = 0; /* r = run length of zeros */
int r = 0; /* r = run length of zeros */
/* Manually unroll the k loop to eliminate the counter variable. This /* Manually unroll the k loop to eliminate the counter variable. This
* improves performance greatly on systems with a limited number of * improves performance greatly on systems with a limited number of
@@ -606,46 +559,51 @@ encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val,
*/ */
#define kloop(jpeg_natural_order_of_k) { \ #define kloop(jpeg_natural_order_of_k) { \
if ((temp = block[jpeg_natural_order_of_k]) == 0) { \ if ((temp = block[jpeg_natural_order_of_k]) == 0) { \
r += 16; \ r++; \
} else { \ } else { \
temp2 = temp; \
/* Branch-less absolute value, bitwise complement, etc., same as above */ \ /* Branch-less absolute value, bitwise complement, etc., same as above */ \
nbits = temp >> (CHAR_BIT * sizeof(int) - 1); \ temp3 = temp >> (CHAR_BIT * sizeof(int) - 1); \
temp += nbits; \ temp ^= temp3; \
nbits ^= temp; \ temp -= temp3; \
nbits = JPEG_NBITS_NONZERO(nbits); \ temp2 += temp3; \
nbits = JPEG_NBITS_NONZERO(temp); \
/* if run length > 15, must emit special run-length-16 codes (0xF0) */ \ /* if run length > 15, must emit special run-length-16 codes (0xF0) */ \
while (r >= 16 * 16) { \ while (r > 15) { \
r -= 16 * 16; \ EMIT_BITS(code_0xf0, size_0xf0) \
PUT_BITS(actbl->ehufco[0xf0], actbl->ehufsi[0xf0]) \ r -= 16; \
} \ } \
/* Emit Huffman symbol for run length / number of bits */ \ /* Emit Huffman symbol for run length / number of bits */ \
r += nbits; \ temp3 = (r << 4) + nbits; \
PUT_CODE(actbl->ehufco[r], actbl->ehufsi[r]) \ code = actbl->ehufco[temp3]; \
size = actbl->ehufsi[temp3]; \
EMIT_CODE(code, size) \
r = 0; \ r = 0; \
} \ } \
} }
/* One iteration for each value in jpeg_natural_order[] */ /* One iteration for each value in jpeg_natural_order[] */
kloop(1); kloop(8); kloop(16); kloop(9); kloop(2); kloop(3); kloop(1); kloop(8); kloop(16); kloop(9); kloop(2); kloop(3);
kloop(10); kloop(17); kloop(24); kloop(32); kloop(25); kloop(18); kloop(10); kloop(17); kloop(24); kloop(32); kloop(25); kloop(18);
kloop(11); kloop(4); kloop(5); kloop(12); kloop(19); kloop(26); kloop(11); kloop(4); kloop(5); kloop(12); kloop(19); kloop(26);
kloop(33); kloop(40); kloop(48); kloop(41); kloop(34); kloop(27); kloop(33); kloop(40); kloop(48); kloop(41); kloop(34); kloop(27);
kloop(20); kloop(13); kloop(6); kloop(7); kloop(14); kloop(21); kloop(20); kloop(13); kloop(6); kloop(7); kloop(14); kloop(21);
kloop(28); kloop(35); kloop(42); kloop(49); kloop(56); kloop(57); kloop(28); kloop(35); kloop(42); kloop(49); kloop(56); kloop(57);
kloop(50); kloop(43); kloop(36); kloop(29); kloop(22); kloop(15); kloop(50); kloop(43); kloop(36); kloop(29); kloop(22); kloop(15);
kloop(23); kloop(30); kloop(37); kloop(44); kloop(51); kloop(58); kloop(23); kloop(30); kloop(37); kloop(44); kloop(51); kloop(58);
kloop(59); kloop(52); kloop(45); kloop(38); kloop(31); kloop(39); kloop(59); kloop(52); kloop(45); kloop(38); kloop(31); kloop(39);
kloop(46); kloop(53); kloop(60); kloop(61); kloop(54); kloop(47); kloop(46); kloop(53); kloop(60); kloop(61); kloop(54); kloop(47);
kloop(55); kloop(62); kloop(63); kloop(55); kloop(62); kloop(63);
/* If the last coef(s) were zero, emit an end-of-block code */ /* If the last coef(s) were zero, emit an end-of-block code */
if (r > 0) { if (r > 0) {
PUT_BITS(actbl->ehufco[0], actbl->ehufsi[0]) code = actbl->ehufco[0];
} size = actbl->ehufsi[0];
EMIT_BITS(code, size)
} }
state->cur.put_buffer.c = put_buffer; state->cur.put_buffer = put_buffer;
state->cur.free_bits = free_bits; state->cur.put_bits = put_bits;
STORE_BUFFER() STORE_BUFFER()
return TRUE; return TRUE;
@@ -692,9 +650,8 @@ encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Load up working state */ /* Load up working state */
state.next_output_byte = cinfo->dest->next_output_byte; state.next_output_byte = cinfo->dest->next_output_byte;
state.free_in_buffer = cinfo->dest->free_in_buffer; state.free_in_buffer = cinfo->dest->free_in_buffer;
state.cur = entropy->saved; ASSIGN_STATE(state.cur, entropy->saved);
state.cinfo = cinfo; state.cinfo = cinfo;
state.simd = entropy->simd;
/* Emit restart marker if needed */ /* Emit restart marker if needed */
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
@@ -733,7 +690,7 @@ encode_mcu_huff(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Completed MCU, so update state */ /* Completed MCU, so update state */
cinfo->dest->next_output_byte = state.next_output_byte; cinfo->dest->next_output_byte = state.next_output_byte;
cinfo->dest->free_in_buffer = state.free_in_buffer; cinfo->dest->free_in_buffer = state.free_in_buffer;
entropy->saved = state.cur; ASSIGN_STATE(entropy->saved, state.cur);
/* Update restart-interval state too */ /* Update restart-interval state too */
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
@@ -762,9 +719,8 @@ finish_pass_huff(j_compress_ptr cinfo)
/* Load up working state ... flush_bits needs it */ /* Load up working state ... flush_bits needs it */
state.next_output_byte = cinfo->dest->next_output_byte; state.next_output_byte = cinfo->dest->next_output_byte;
state.free_in_buffer = cinfo->dest->free_in_buffer; state.free_in_buffer = cinfo->dest->free_in_buffer;
state.cur = entropy->saved; ASSIGN_STATE(state.cur, entropy->saved);
state.cinfo = cinfo; state.cinfo = cinfo;
state.simd = entropy->simd;
/* Flush out the last data */ /* Flush out the last data */
if (!flush_bits(&state)) if (!flush_bits(&state))
@@ -773,7 +729,7 @@ finish_pass_huff(j_compress_ptr cinfo)
/* Update state */ /* Update state */
cinfo->dest->next_output_byte = state.next_output_byte; cinfo->dest->next_output_byte = state.next_output_byte;
cinfo->dest->free_in_buffer = state.free_in_buffer; cinfo->dest->free_in_buffer = state.free_in_buffer;
entropy->saved = state.cur; ASSIGN_STATE(entropy->saved, state.cur);
} }
+1 -4
View File
@@ -1,10 +1,8 @@
/* /*
* jcinit.c * jcinit.c
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * This file is part of the Independent JPEG Group's software.
* Copyright (C) 2020, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -21,7 +19,6 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jpegcomp.h"
/* /*
+1 -1
View File
@@ -492,8 +492,8 @@ prepare_for_pass(j_compress_ptr cinfo)
*/ */
master->pass_type = output_pass; master->pass_type = output_pass;
master->pass_number++; master->pass_number++;
#endif
/*FALLTHROUGH*/ /*FALLTHROUGH*/
#endif
case output_pass: case output_pass:
/* Do a data-output pass. */ /* Do a data-output pass. */
/* We need not repeat per-scan setup if prior optimization pass did it. */ /* We need not repeat per-scan setup if prior optimization pass did it. */
+12 -19
View File
@@ -4,9 +4,8 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1995-1997, Thomas G. Lane. * Copyright (C) 1995-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2011, 2015, 2018, 2021, D. R. Commander. * Copyright (C) 2011, 2015, 2018, D. R. Commander.
* Copyright (C) 2016, 2018, Matthieu Darbois. * Copyright (C) 2016, 2018, Matthieu Darbois.
* Copyright (C) 2020, Arm Limited.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -44,27 +43,23 @@
* memory footprint by 64k, which is important for some mobile applications * memory footprint by 64k, which is important for some mobile applications
* that create many isolated instances of libjpeg-turbo (web browsers, for * that create many isolated instances of libjpeg-turbo (web browsers, for
* instance.) This may improve performance on some mobile platforms as well. * instance.) This may improve performance on some mobile platforms as well.
* This feature is enabled by default only on Arm processors, because some x86 * 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 * 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 * 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 * 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 * explicitly disable the use of clz/bsr by adding -mthumb to the compiler
* flags (this defines __thumb__). * flags (this defines __thumb__).
*/ */
#if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) || \ /* NOTE: Both GCC and Clang define __GNUC__ */
defined(_M_ARM64) #if defined __GNUC__ && (defined __arm__ || defined __aarch64__)
#if !defined(__thumb__) || defined(__thumb2__) #if !defined __thumb__ || defined __thumb2__
#define USE_CLZ_INTRINSIC #define USE_CLZ_INTRINSIC
#endif #endif
#endif #endif
#ifdef USE_CLZ_INTRINSIC #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)) #define JPEG_NBITS_NONZERO(x) (32 - __builtin_clz(x))
#endif
#define JPEG_NBITS(x) (x ? JPEG_NBITS_NONZERO(x) : 0) #define JPEG_NBITS(x) (x ? JPEG_NBITS_NONZERO(x) : 0)
#else #else
#include "jpeg_nbits_table.h" #include "jpeg_nbits_table.h"
@@ -174,26 +169,24 @@ INLINE
METHODDEF(int) METHODDEF(int)
count_zeroes(size_t *x) count_zeroes(size_t *x)
{ {
#if defined(HAVE_BUILTIN_CTZL)
int result; int result;
#if defined(HAVE_BUILTIN_CTZL)
result = __builtin_ctzl(*x); result = __builtin_ctzl(*x);
*x >>= result; *x >>= result;
#elif defined(HAVE_BITSCANFORWARD64) #elif defined(HAVE_BITSCANFORWARD64)
unsigned long result;
_BitScanForward64(&result, *x); _BitScanForward64(&result, *x);
*x >>= result; *x >>= result;
#elif defined(HAVE_BITSCANFORWARD) #elif defined(HAVE_BITSCANFORWARD)
unsigned long result;
_BitScanForward(&result, *x); _BitScanForward(&result, *x);
*x >>= result; *x >>= result;
#else #else
int result = 0; result = 0;
while ((*x & 1) == 0) { while ((*x & 1) == 0) {
++result; ++result;
*x >>= 1; *x >>= 1;
} }
#endif #endif
return (int)result; return result;
} }
@@ -867,7 +860,7 @@ encode_mcu_AC_refine_prepare(const JCOEF *block,
#define ENCODE_COEFS_AC_REFINE(label) { \ #define ENCODE_COEFS_AC_REFINE(label) { \
while (zerobits) { \ while (zerobits) { \
idx = count_zeroes(&zerobits); \ int idx = count_zeroes(&zerobits); \
r += idx; \ r += idx; \
cabsvalue += idx; \ cabsvalue += idx; \
signbits >>= idx; \ signbits >>= idx; \
@@ -924,7 +917,7 @@ METHODDEF(boolean)
encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr)cinfo->entropy;
register int temp, r, idx; register int temp, r;
char *BR_buffer; char *BR_buffer;
unsigned int BR; unsigned int BR;
int Sl = cinfo->Se - cinfo->Ss + 1; int Sl = cinfo->Se - cinfo->Ss + 1;
@@ -975,7 +968,7 @@ encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
if (zerobits) { if (zerobits) {
int diff = ((absvalues + DCTSIZE2 / 2) - cabsvalue); int diff = ((absvalues + DCTSIZE2 / 2) - cabsvalue);
idx = count_zeroes(&zerobits); int idx = count_zeroes(&zerobits);
signbits >>= idx; signbits >>= idx;
idx += diff; idx += diff;
r += idx; r += idx;
+40 -23
View File
@@ -6,7 +6,7 @@
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2014, MIPS Technologies, Inc., California. * Copyright (C) 2014, MIPS Technologies, Inc., California.
* Copyright (C) 2015, 2019, D. R. Commander. * Copyright (C) 2015, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -103,7 +103,7 @@ expand_right_edge(JSAMPARRAY image_data, int num_rows, JDIMENSION input_cols,
if (numcols > 0) { if (numcols > 0) {
for (row = 0; row < num_rows; row++) { for (row = 0; row < num_rows; row++) {
ptr = image_data[row] + input_cols; ptr = image_data[row] + input_cols;
pixval = ptr[-1]; pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
for (count = numcols; count > 0; count--) for (count = numcols; count > 0; count--)
*ptr++ = pixval; *ptr++ = pixval;
} }
@@ -174,7 +174,7 @@ int_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
for (v = 0; v < v_expand; v++) { for (v = 0; v < v_expand; v++) {
inptr = input_data[inrow + v] + outcol_h; inptr = input_data[inrow + v] + outcol_h;
for (h = 0; h < h_expand; h++) { for (h = 0; h < h_expand; h++) {
outvalue += (JLONG)(*inptr++); outvalue += (JLONG)GETJSAMPLE(*inptr++);
} }
} }
*outptr++ = (JSAMPLE)((outvalue + numpix2) / numpix); *outptr++ = (JSAMPLE)((outvalue + numpix2) / numpix);
@@ -237,7 +237,8 @@ h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
inptr = input_data[outrow]; inptr = input_data[outrow];
bias = 0; /* bias = 0,1,0,1,... for successive samples */ bias = 0; /* bias = 0,1,0,1,... for successive samples */
for (outcol = 0; outcol < output_cols; outcol++) { for (outcol = 0; outcol < output_cols; outcol++) {
*outptr++ = (JSAMPLE)((inptr[0] + inptr[1] + bias) >> 1); *outptr++ =
(JSAMPLE)((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1]) + bias) >> 1);
bias ^= 1; /* 0=>1, 1=>0 */ bias ^= 1; /* 0=>1, 1=>0 */
inptr += 2; inptr += 2;
} }
@@ -276,7 +277,8 @@ h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
bias = 1; /* bias = 1,2,1,2,... for successive samples */ bias = 1; /* bias = 1,2,1,2,... for successive samples */
for (outcol = 0; outcol < output_cols; outcol++) { for (outcol = 0; outcol < output_cols; outcol++) {
*outptr++ = *outptr++ =
(JSAMPLE)((inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1] + bias) >> 2); (JSAMPLE)((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]) + bias) >> 2);
bias ^= 3; /* 1=>2, 2=>1 */ bias ^= 3; /* 1=>2, 2=>1 */
inptr0 += 2; inptr1 += 2; inptr0 += 2; inptr1 += 2;
} }
@@ -335,25 +337,33 @@ h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
below_ptr = input_data[inrow + 2]; below_ptr = input_data[inrow + 2];
/* Special case for first column: pretend column -1 is same as column 0 */ /* Special case for first column: pretend column -1 is same as column 0 */
membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1]; membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
inptr0[0] + inptr0[2] + inptr1[0] + inptr1[2]; neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
neighsum += neighsum; neighsum += neighsum;
neighsum += above_ptr[0] + above_ptr[2] + below_ptr[0] + below_ptr[2]; neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
*outptr++ = (JSAMPLE)((membersum + 32768) >> 16); *outptr++ = (JSAMPLE)((membersum + 32768) >> 16);
inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
for (colctr = output_cols - 2; colctr > 0; colctr--) { for (colctr = output_cols - 2; colctr > 0; colctr--) {
/* sum of pixels directly mapped to this output element */ /* sum of pixels directly mapped to this output element */
membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1]; membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
/* sum of edge-neighbor pixels */ /* sum of edge-neighbor pixels */
neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
inptr0[-1] + inptr0[2] + inptr1[-1] + inptr1[2]; GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
/* The edge-neighbors count twice as much as corner-neighbors */ /* The edge-neighbors count twice as much as corner-neighbors */
neighsum += neighsum; neighsum += neighsum;
/* Add in the corner-neighbors */ /* Add in the corner-neighbors */
neighsum += above_ptr[-1] + above_ptr[2] + below_ptr[-1] + below_ptr[2]; neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
/* form final output scaled up by 2^16 */ /* form final output scaled up by 2^16 */
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
/* round, descale and output it */ /* round, descale and output it */
@@ -362,11 +372,15 @@ h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
} }
/* Special case for last column */ /* Special case for last column */
membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1]; membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
inptr0[-1] + inptr0[1] + inptr1[-1] + inptr1[1]; neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
neighsum += neighsum; neighsum += neighsum;
neighsum += above_ptr[-1] + above_ptr[1] + below_ptr[-1] + below_ptr[1]; neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
*outptr = (JSAMPLE)((membersum + 32768) >> 16); *outptr = (JSAMPLE)((membersum + 32768) >> 16);
@@ -415,18 +429,21 @@ fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
below_ptr = input_data[outrow + 1]; below_ptr = input_data[outrow + 1];
/* Special case for first column */ /* Special case for first column */
colsum = (*above_ptr++) + (*below_ptr++) + inptr[0]; colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
membersum = *inptr++; GETJSAMPLE(*inptr);
nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0]; membersum = GETJSAMPLE(*inptr++);
nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
GETJSAMPLE(*inptr);
neighsum = colsum + (colsum - membersum) + nextcolsum; neighsum = colsum + (colsum - membersum) + nextcolsum;
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
*outptr++ = (JSAMPLE)((membersum + 32768) >> 16); *outptr++ = (JSAMPLE)((membersum + 32768) >> 16);
lastcolsum = colsum; colsum = nextcolsum; lastcolsum = colsum; colsum = nextcolsum;
for (colctr = output_cols - 2; colctr > 0; colctr--) { for (colctr = output_cols - 2; colctr > 0; colctr--) {
membersum = *inptr++; membersum = GETJSAMPLE(*inptr++);
above_ptr++; below_ptr++; above_ptr++; below_ptr++;
nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0]; nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
GETJSAMPLE(*inptr);
neighsum = lastcolsum + (colsum - membersum) + nextcolsum; neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
*outptr++ = (JSAMPLE)((membersum + 32768) >> 16); *outptr++ = (JSAMPLE)((membersum + 32768) >> 16);
@@ -434,7 +451,7 @@ fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
} }
/* Special case for last column */ /* Special case for last column */
membersum = *inptr; membersum = GETJSAMPLE(*inptr);
neighsum = lastcolsum + (colsum - membersum) + colsum; neighsum = lastcolsum + (colsum - membersum) + colsum;
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
*outptr = (JSAMPLE)((membersum + 32768) >> 16); *outptr = (JSAMPLE)((membersum + 32768) >> 16);
+2 -3
View File
@@ -4,8 +4,8 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1995-1998, Thomas G. Lane. * Copyright (C) 1995-1998, Thomas G. Lane.
* Modified 2000-2009 by Guido Vollbeding. * Modified 2000-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications: * It was modified by The libjpeg-turbo Project to include only code relevant
* Copyright (C) 2020, D. R. Commander. * to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -17,7 +17,6 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jpegcomp.h"
/* Forward declarations */ /* Forward declarations */
+9 -44
View File
@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2010, 2015-2020, D. R. Commander. * Copyright (C) 2010, 2015-2018, D. R. Commander.
* Copyright (C) 2015, Google, Inc. * Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
@@ -21,8 +21,6 @@
#include "jinclude.h" #include "jinclude.h"
#include "jdmainct.h" #include "jdmainct.h"
#include "jdcoefct.h" #include "jdcoefct.h"
#include "jdmaster.h"
#include "jdmerge.h"
#include "jdsample.h" #include "jdsample.h"
#include "jmemsys.h" #include "jmemsys.h"
@@ -318,10 +316,6 @@ LOCAL(void)
read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines) read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
{ {
JDIMENSION n; JDIMENSION n;
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, void (*color_convert) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, JDIMENSION input_row, JSAMPARRAY output_buf,
int num_rows) = NULL; int num_rows) = NULL;
@@ -331,10 +325,6 @@ read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
if (cinfo->cconvert && cinfo->cconvert->color_convert) { if (cinfo->cconvert && cinfo->cconvert->color_convert) {
color_convert = cinfo->cconvert->color_convert; color_convert = cinfo->cconvert->color_convert;
cinfo->cconvert->color_convert = noop_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) { if (cinfo->cquantize && cinfo->cquantize->color_quantize) {
@@ -342,13 +332,8 @@ read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
cinfo->cquantize->color_quantize = noop_quantize; cinfo->cquantize->color_quantize = noop_quantize;
} }
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;
}
for (n = 0; n < num_lines; n++) for (n = 0; n < num_lines; n++)
jpeg_read_scanlines(cinfo, scanlines, 1); jpeg_read_scanlines(cinfo, NULL, 1);
if (color_convert) if (color_convert)
cinfo->cconvert->color_convert = color_convert; cinfo->cconvert->color_convert = color_convert;
@@ -368,12 +353,6 @@ increment_simple_rowgroup_ctr(j_decompress_ptr cinfo, JDIMENSION rows)
{ {
JDIMENSION rows_left; JDIMENSION rows_left;
my_main_ptr main_ptr = (my_main_ptr)cinfo->main; my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
my_master_ptr master = (my_master_ptr)cinfo->master;
if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
read_and_discard_scanlines(cinfo, rows);
return;
}
/* Increment the counter to the next row group after the skipped rows. */ /* Increment the counter to the next row group after the skipped rows. */
main_ptr->rowgroup_ctr += rows / cinfo->max_v_samp_factor; main_ptr->rowgroup_ctr += rows / cinfo->max_v_samp_factor;
@@ -403,27 +382,21 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
{ {
my_main_ptr main_ptr = (my_main_ptr)cinfo->main; my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
my_coef_ptr coef = (my_coef_ptr)cinfo->coef; my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
my_master_ptr master = (my_master_ptr)cinfo->master;
my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
JDIMENSION i, x; JDIMENSION i, x;
int y; int y;
JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row; JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
JDIMENSION lines_to_skip, lines_to_read; JDIMENSION lines_to_skip, lines_to_read;
/* Two-pass color quantization is not supported. */
if (cinfo->quantize_colors && cinfo->two_pass_quantize)
ERREXIT(cinfo, JERR_NOTIMPL);
if (cinfo->global_state != DSTATE_SCANNING) if (cinfo->global_state != DSTATE_SCANNING)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
/* Do not skip past the bottom of the image. */ /* Do not skip past the bottom of the image. */
if (cinfo->output_scanline + num_lines >= cinfo->output_height) { if (cinfo->output_scanline + num_lines >= cinfo->output_height) {
num_lines = cinfo->output_height - cinfo->output_scanline;
cinfo->output_scanline = cinfo->output_height; cinfo->output_scanline = cinfo->output_height;
(*cinfo->inputctl->finish_input_pass) (cinfo); (*cinfo->inputctl->finish_input_pass) (cinfo);
cinfo->inputctl->eoi_reached = TRUE; cinfo->inputctl->eoi_reached = TRUE;
return num_lines; return cinfo->output_height - cinfo->output_scanline;
} }
if (num_lines == 0) if (num_lines == 0)
@@ -472,10 +445,8 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
main_ptr->buffer_full = FALSE; main_ptr->buffer_full = FALSE;
main_ptr->rowgroup_ctr = 0; main_ptr->rowgroup_ctr = 0;
main_ptr->context_state = CTX_PREPARE_FOR_IMCU; main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
if (!master->using_merged_upsample) { upsample->next_row_out = cinfo->max_v_samp_factor;
upsample->next_row_out = cinfo->max_v_samp_factor; upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
}
} }
/* Skipping is much simpler when context rows are not required. */ /* Skipping is much simpler when context rows are not required. */
@@ -487,10 +458,8 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
cinfo->output_scanline += lines_left_in_iMCU_row; cinfo->output_scanline += lines_left_in_iMCU_row;
main_ptr->buffer_full = FALSE; main_ptr->buffer_full = FALSE;
main_ptr->rowgroup_ctr = 0; main_ptr->rowgroup_ctr = 0;
if (!master->using_merged_upsample) { upsample->next_row_out = cinfo->max_v_samp_factor;
upsample->next_row_out = cinfo->max_v_samp_factor; upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
}
} }
} }
@@ -525,8 +494,7 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row; cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
increment_simple_rowgroup_ctr(cinfo, lines_to_read); increment_simple_rowgroup_ctr(cinfo, lines_to_read);
} }
if (!master->using_merged_upsample) upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
return num_lines; return num_lines;
} }
@@ -538,8 +506,6 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
* decoded coefficients. This is ~5% faster for large subsets, but * decoded coefficients. This is ~5% faster for large subsets, but
* it's tough to tell a difference for smaller images. * it's tough to tell a difference for smaller images.
*/ */
if (!cinfo->entropy->insufficient_data)
cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
(*cinfo->entropy->decode_mcu) (cinfo, NULL); (*cinfo->entropy->decode_mcu) (cinfo, NULL);
} }
} }
@@ -569,8 +535,7 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
* bit odd, since "rows_to_go" seems to be redundantly keeping track of * bit odd, since "rows_to_go" seems to be redundantly keeping track of
* output_scanline. * output_scanline.
*/ */
if (!master->using_merged_upsample) upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
/* Always skip the requested number of lines. */ /* Always skip the requested number of lines. */
return num_lines; return num_lines;
+3 -12
View File
@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Developed 1997-2015 by Guido Vollbeding. * Developed 1997-2015 by Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2015-2020, D. R. Commander. * Copyright (C) 2015-2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -80,7 +80,7 @@ get_byte(j_decompress_ptr cinfo)
if (!(*src->fill_input_buffer) (cinfo)) if (!(*src->fill_input_buffer) (cinfo))
ERREXIT(cinfo, JERR_CANT_SUSPEND); ERREXIT(cinfo, JERR_CANT_SUSPEND);
src->bytes_in_buffer--; src->bytes_in_buffer--;
return *src->next_input_byte++; return GETJOCTET(*src->next_input_byte++);
} }
@@ -665,16 +665,8 @@ bad:
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
int coefi, cindex = cinfo->cur_comp_info[ci]->component_index; int coefi, cindex = cinfo->cur_comp_info[ci]->component_index;
int *coef_bit_ptr = &cinfo->coef_bits[cindex][0]; int *coef_bit_ptr = &cinfo->coef_bits[cindex][0];
int *prev_coef_bit_ptr =
&cinfo->coef_bits[cindex + cinfo->num_components][0];
if (cinfo->Ss && coef_bit_ptr[0] < 0) /* AC without prior DC scan */ if (cinfo->Ss && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0); WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
for (coefi = MIN(cinfo->Ss, 1); coefi <= MAX(cinfo->Se, 9); coefi++) {
if (cinfo->input_scan_number > 1)
prev_coef_bit_ptr[coefi] = coef_bit_ptr[coefi];
else
prev_coef_bit_ptr[coefi] = 0;
}
for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) { for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi]; int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
if (cinfo->Ah != expected) if (cinfo->Ah != expected)
@@ -735,7 +727,6 @@ bad:
entropy->c = 0; entropy->c = 0;
entropy->a = 0; entropy->a = 0;
entropy->ct = -16; /* force reading 2 initial bytes to fill C */ entropy->ct = -16; /* force reading 2 initial bytes to fill C */
entropy->pub.insufficient_data = FALSE;
/* Initialize restart counter */ /* Initialize restart counter */
entropy->restarts_to_go = cinfo->restart_interval; entropy->restarts_to_go = cinfo->restart_interval;
@@ -772,7 +763,7 @@ jinit_arith_decoder(j_decompress_ptr cinfo)
int *coef_bit_ptr, ci; int *coef_bit_ptr, ci;
cinfo->coef_bits = (int (*)[DCTSIZE2]) cinfo->coef_bits = (int (*)[DCTSIZE2])
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
cinfo->num_components * 2 * DCTSIZE2 * cinfo->num_components * DCTSIZE2 *
sizeof(int)); sizeof(int));
coef_bit_ptr = &cinfo->coef_bits[0][0]; coef_bit_ptr = &cinfo->coef_bits[0][0];
for (ci = 0; ci < cinfo->num_components; ci++) for (ci = 0; ci < cinfo->num_components; ci++)
+2 -1
View File
@@ -143,7 +143,8 @@ empty_mem_output_buffer(j_compress_ptr cinfo)
MEMCOPY(nextbuffer, dest->buffer, dest->bufsize); MEMCOPY(nextbuffer, dest->buffer, dest->bufsize);
free(dest->newbuffer); if (dest->newbuffer != NULL)
free(dest->newbuffer);
dest->newbuffer = nextbuffer; dest->newbuffer = nextbuffer;
+52 -238
View File
@@ -5,8 +5,8 @@
* Copyright (C) 1994-1997, Thomas G. Lane. * Copyright (C) 1994-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2010, 2015-2016, 2019-2020, D. R. Commander. * Copyright (C) 2010, 2015-2016, D. R. Commander.
* Copyright (C) 2015, 2020, Google, Inc. * Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -102,8 +102,6 @@ decompress_onepass(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
/* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */
jzero_far((void *)coef->MCU_buffer[0], jzero_far((void *)coef->MCU_buffer[0],
(size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK))); (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
if (!cinfo->entropy->insufficient_data)
cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
/* Suspension forced; update state counters and exit */ /* Suspension forced; update state counters and exit */
coef->MCU_vert_offset = yoffset; coef->MCU_vert_offset = yoffset;
@@ -229,8 +227,6 @@ consume_data(j_decompress_ptr cinfo)
} }
} }
} }
if (!cinfo->entropy->insufficient_data)
cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
/* Try to fetch the MCU. */ /* Try to fetch the MCU. */
if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
/* Suspension forced; update state counters and exit */ /* Suspension forced; update state counters and exit */
@@ -330,22 +326,19 @@ decompress_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
#ifdef BLOCK_SMOOTHING_SUPPORTED #ifdef BLOCK_SMOOTHING_SUPPORTED
/* /*
* This code applies interblock smoothing; the first 9 AC coefficients are * This code applies interblock smoothing as described by section K.8
* estimated from the DC values of a DCT block and its 24 neighboring blocks. * of the JPEG standard: the first 5 AC coefficients are estimated from
* the DC values of a DCT block and its 8 neighboring blocks.
* We apply smoothing only for progressive JPEG decoding, and only if * We apply smoothing only for progressive JPEG decoding, and only if
* the coefficients it can estimate are not yet known to full precision. * the coefficients it can estimate are not yet known to full precision.
*/ */
/* Natural-order array positions of the first 9 zigzag-order coefficients */ /* Natural-order array positions of the first 5 zigzag-order coefficients */
#define Q01_POS 1 #define Q01_POS 1
#define Q10_POS 8 #define Q10_POS 8
#define Q20_POS 16 #define Q20_POS 16
#define Q11_POS 9 #define Q11_POS 9
#define Q02_POS 2 #define Q02_POS 2
#define Q03_POS 3
#define Q12_POS 10
#define Q21_POS 17
#define Q30_POS 24
/* /*
* Determine whether block smoothing is applicable and safe. * Determine whether block smoothing is applicable and safe.
@@ -363,8 +356,8 @@ smoothing_ok(j_decompress_ptr cinfo)
int ci, coefi; int ci, coefi;
jpeg_component_info *compptr; jpeg_component_info *compptr;
JQUANT_TBL *qtable; JQUANT_TBL *qtable;
int *coef_bits, *prev_coef_bits; int *coef_bits;
int *coef_bits_latch, *prev_coef_bits_latch; int *coef_bits_latch;
if (!cinfo->progressive_mode || cinfo->coef_bits == NULL) if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
return FALSE; return FALSE;
@@ -373,47 +366,34 @@ smoothing_ok(j_decompress_ptr cinfo)
if (coef->coef_bits_latch == NULL) if (coef->coef_bits_latch == NULL)
coef->coef_bits_latch = (int *) coef->coef_bits_latch = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
cinfo->num_components * 2 * cinfo->num_components *
(SAVED_COEFS * sizeof(int))); (SAVED_COEFS * sizeof(int)));
coef_bits_latch = coef->coef_bits_latch; coef_bits_latch = coef->coef_bits_latch;
prev_coef_bits_latch =
&coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
/* All components' quantization values must already be latched. */ /* All components' quantization values must already be latched. */
if ((qtable = compptr->quant_table) == NULL) if ((qtable = compptr->quant_table) == NULL)
return FALSE; return FALSE;
/* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */ /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */
if (qtable->quantval[0] == 0 || if (qtable->quantval[0] == 0 ||
qtable->quantval[Q01_POS] == 0 || qtable->quantval[Q01_POS] == 0 ||
qtable->quantval[Q10_POS] == 0 || qtable->quantval[Q10_POS] == 0 ||
qtable->quantval[Q20_POS] == 0 || qtable->quantval[Q20_POS] == 0 ||
qtable->quantval[Q11_POS] == 0 || qtable->quantval[Q11_POS] == 0 ||
qtable->quantval[Q02_POS] == 0 || qtable->quantval[Q02_POS] == 0)
qtable->quantval[Q03_POS] == 0 ||
qtable->quantval[Q12_POS] == 0 ||
qtable->quantval[Q21_POS] == 0 ||
qtable->quantval[Q30_POS] == 0)
return FALSE; return FALSE;
/* DC values must be at least partly known for all components. */ /* DC values must be at least partly known for all components. */
coef_bits = cinfo->coef_bits[ci]; coef_bits = cinfo->coef_bits[ci];
prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
if (coef_bits[0] < 0) if (coef_bits[0] < 0)
return FALSE; return FALSE;
coef_bits_latch[0] = coef_bits[0];
/* Block smoothing is helpful if some AC coefficients remain inaccurate. */ /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
for (coefi = 1; coefi < SAVED_COEFS; coefi++) { for (coefi = 1; coefi <= 5; coefi++) {
if (cinfo->input_scan_number > 1)
prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
else
prev_coef_bits_latch[coefi] = -1;
coef_bits_latch[coefi] = coef_bits[coefi]; coef_bits_latch[coefi] = coef_bits[coefi];
if (coef_bits[coefi] != 0) if (coef_bits[coefi] != 0)
smoothing_useful = TRUE; smoothing_useful = TRUE;
} }
coef_bits_latch += SAVED_COEFS; coef_bits_latch += SAVED_COEFS;
prev_coef_bits_latch += SAVED_COEFS;
} }
return smoothing_useful; return smoothing_useful;
@@ -432,20 +412,17 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
JDIMENSION block_num, last_block_column; JDIMENSION block_num, last_block_column;
int ci, block_row, block_rows, access_rows; int ci, block_row, block_rows, access_rows;
JBLOCKARRAY buffer; JBLOCKARRAY buffer;
JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row; JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
JBLOCKROW next_block_row, next_next_block_row;
JSAMPARRAY output_ptr; JSAMPARRAY output_ptr;
JDIMENSION output_col; JDIMENSION output_col;
jpeg_component_info *compptr; jpeg_component_info *compptr;
inverse_DCT_method_ptr inverse_DCT; inverse_DCT_method_ptr inverse_DCT;
boolean change_dc; boolean first_row, last_row;
JCOEF *workspace; JCOEF *workspace;
int *coef_bits; int *coef_bits;
JQUANT_TBL *quanttbl; JQUANT_TBL *quanttbl;
JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num; JLONG Q00, Q01, Q02, Q10, Q11, Q20, num;
int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12, int DC1, DC2, DC3, DC4, DC5, DC6, DC7, DC8, DC9;
DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
DC25;
int Al, pred; int Al, pred;
/* Keep a local variable to avoid looking it up more than once */ /* Keep a local variable to avoid looking it up more than once */
@@ -457,10 +434,10 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
if (cinfo->input_scan_number == cinfo->output_scan_number) { if (cinfo->input_scan_number == cinfo->output_scan_number) {
/* If input is working on current scan, we ordinarily want it to /* If input is working on current scan, we ordinarily want it to
* have completed the current row. But if input scan is DC, * have completed the current row. But if input scan is DC,
* we want it to keep two rows ahead so that next two block rows' DC * we want it to keep one row ahead so that next block row's DC
* values are up to date. * values are up to date.
*/ */
JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0; JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta) if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
break; break;
} }
@@ -475,53 +452,34 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
if (!compptr->component_needed) if (!compptr->component_needed)
continue; continue;
/* Count non-dummy DCT block rows in this iMCU row. */ /* Count non-dummy DCT block rows in this iMCU row. */
if (cinfo->output_iMCU_row < last_iMCU_row - 1) { if (cinfo->output_iMCU_row < 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) {
block_rows = compptr->v_samp_factor; block_rows = compptr->v_samp_factor;
access_rows = block_rows * 2; /* this and next iMCU row */ access_rows = block_rows * 2; /* this and next iMCU row */
last_row = FALSE;
} else { } else {
/* NB: can't use last_row_height here; it is input-side-dependent! */ /* NB: can't use last_row_height here; it is input-side-dependent! */
block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
if (block_rows == 0) block_rows = compptr->v_samp_factor; if (block_rows == 0) block_rows = compptr->v_samp_factor;
access_rows = block_rows; /* this iMCU row only */ access_rows = block_rows; /* this iMCU row only */
last_row = TRUE;
} }
/* Align the virtual buffer for this component. */ /* Align the virtual buffer for this component. */
if (cinfo->output_iMCU_row > 1) { if (cinfo->output_iMCU_row > 0) {
access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */ 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 - 2) * compptr->v_samp_factor,
(JDIMENSION)access_rows, FALSE);
buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
} else if (cinfo->output_iMCU_row > 0) {
buffer = (*cinfo->mem->access_virt_barray) buffer = (*cinfo->mem->access_virt_barray)
((j_common_ptr)cinfo, coef->whole_image[ci], ((j_common_ptr)cinfo, coef->whole_image[ci],
(cinfo->output_iMCU_row - 1) * compptr->v_samp_factor, (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
(JDIMENSION)access_rows, FALSE); (JDIMENSION)access_rows, FALSE);
buffer += compptr->v_samp_factor; /* point to current iMCU row */ buffer += compptr->v_samp_factor; /* point to current iMCU row */
first_row = FALSE;
} else { } else {
buffer = (*cinfo->mem->access_virt_barray) buffer = (*cinfo->mem->access_virt_barray)
((j_common_ptr)cinfo, coef->whole_image[ci], ((j_common_ptr)cinfo, coef->whole_image[ci],
(JDIMENSION)0, (JDIMENSION)access_rows, FALSE); (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
first_row = TRUE;
} }
/* Fetch component-dependent info. /* Fetch component-dependent info */
* If the current scan is incomplete, then we use the component-dependent coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
* info from the previous scan.
*/
if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
coef_bits =
coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
else
coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
/* We only do DC interpolation if no AC coefficient data is available. */
change_dc =
coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
quanttbl = compptr->quant_table; quanttbl = compptr->quant_table;
Q00 = quanttbl->quantval[0]; Q00 = quanttbl->quantval[0];
Q01 = quanttbl->quantval[Q01_POS]; Q01 = quanttbl->quantval[Q01_POS];
@@ -529,51 +487,25 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
Q20 = quanttbl->quantval[Q20_POS]; Q20 = quanttbl->quantval[Q20_POS];
Q11 = quanttbl->quantval[Q11_POS]; Q11 = quanttbl->quantval[Q11_POS];
Q02 = quanttbl->quantval[Q02_POS]; Q02 = quanttbl->quantval[Q02_POS];
if (change_dc) {
Q03 = quanttbl->quantval[Q03_POS];
Q12 = quanttbl->quantval[Q12_POS];
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]; output_ptr = output_buf[ci];
/* Loop over all DCT blocks to be processed. */ /* Loop over all DCT blocks to be processed. */
for (block_row = 0; block_row < block_rows; block_row++) { for (block_row = 0; block_row < block_rows; block_row++) {
buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci]; buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
if (first_row && block_row == 0)
if (block_row > 0 || cinfo->output_iMCU_row > 0)
prev_block_row =
buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
else
prev_block_row = buffer_ptr; prev_block_row = buffer_ptr;
if (block_row > 1 || cinfo->output_iMCU_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)
next_block_row =
buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
else else
prev_block_row = buffer[block_row - 1];
if (last_row && block_row == block_rows - 1)
next_block_row = buffer_ptr; next_block_row = buffer_ptr;
if (block_row < block_rows - 2 ||
cinfo->output_iMCU_row < last_iMCU_row - 1)
next_next_block_row =
buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
else else
next_next_block_row = next_block_row; next_block_row = buffer[block_row + 1];
/* We fetch the surrounding DC values using a sliding-register approach. /* We fetch the surrounding DC values using a sliding-register approach.
* Initialize all 25 here so as to do the right thing on narrow pics. * Initialize all nine here so as to do the right thing on narrow pics.
*/ */
DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0]; DC1 = DC2 = DC3 = (int)prev_block_row[0][0];
DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0]; DC4 = DC5 = DC6 = (int)buffer_ptr[0][0];
DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0]; DC7 = DC8 = DC9 = (int)next_block_row[0][0];
DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
output_col = 0; output_col = 0;
last_block_column = compptr->width_in_blocks - 1; last_block_column = compptr->width_in_blocks - 1;
for (block_num = cinfo->master->first_MCU_col[ci]; for (block_num = cinfo->master->first_MCU_col[ci];
@@ -581,39 +513,18 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
/* Fetch current DCT block into workspace so we can modify it. */ /* Fetch current DCT block into workspace so we can modify it. */
jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1); jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
/* Update DC values */ /* Update DC values */
if (block_num == cinfo->master->first_MCU_col[ci] && if (block_num < last_block_column) {
block_num < last_block_column) { DC3 = (int)prev_block_row[1][0];
DC04 = (int)prev_prev_block_row[1][0]; DC6 = (int)buffer_ptr[1][0];
DC09 = (int)prev_block_row[1][0]; DC9 = (int)next_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];
} }
if (block_num + 1 < last_block_column) { /* Compute coefficient estimates per K.8.
DC05 = (int)prev_prev_block_row[2][0]; * An estimate is applied only if coefficient is still zero,
DC10 = (int)prev_block_row[2][0]; * and is not known to be fully accurate.
DC15 = (int)buffer_ptr[2][0];
DC20 = (int)next_block_row[2][0];
DC25 = (int)next_next_block_row[2][0];
}
/* If DC interpolation is enabled, compute coefficient estimates using
* a Gaussian-like kernel, keeping the averages of the DC values.
*
* If DC interpolation is disabled, compute coefficient estimates using
* an algorithm similar to the one described in Section K.8 of the JPEG
* standard, except applied to a 5x5 window rather than a 3x3 window.
*
* An estimate is applied only if the coefficient is still zero and is
* not known to be fully accurate.
*/ */
/* AC01 */ /* AC01 */
if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) { if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
num = Q00 * (change_dc ? num = 36 * Q00 * (DC4 - DC6);
(-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
DC21 - DC22 + DC24 + DC25) :
(-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
if (num >= 0) { if (num >= 0) {
pred = (int)(((Q01 << 7) + num) / (Q01 << 8)); pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
if (Al > 0 && pred >= (1 << Al)) if (Al > 0 && pred >= (1 << Al))
@@ -628,12 +539,7 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
} }
/* AC10 */ /* AC10 */
if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) { if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
num = Q00 * (change_dc ? num = 36 * Q00 * (DC2 - DC8);
(-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
(-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
if (num >= 0) { if (num >= 0) {
pred = (int)(((Q10 << 7) + num) / (Q10 << 8)); pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
if (Al > 0 && pred >= (1 << Al)) if (Al > 0 && pred >= (1 << Al))
@@ -648,10 +554,7 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
} }
/* AC20 */ /* AC20 */
if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) { if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
num = Q00 * (change_dc ? num = 9 * Q00 * (DC2 + DC8 - 2 * DC5);
(DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
(-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
if (num >= 0) { if (num >= 0) {
pred = (int)(((Q20 << 7) + num) / (Q20 << 8)); pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
if (Al > 0 && pred >= (1 << Al)) if (Al > 0 && pred >= (1 << Al))
@@ -666,11 +569,7 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
} }
/* AC11 */ /* AC11 */
if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) { if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
num = Q00 * (change_dc ? num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
(-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
9 * DC19 + DC21 - DC25) :
(DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
if (num >= 0) { if (num >= 0) {
pred = (int)(((Q11 << 7) + num) / (Q11 << 8)); pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
if (Al > 0 && pred >= (1 << Al)) if (Al > 0 && pred >= (1 << Al))
@@ -685,10 +584,7 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
} }
/* AC02 */ /* AC02 */
if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) { if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
num = Q00 * (change_dc ? num = 9 * Q00 * (DC4 + DC6 - 2 * DC5);
(2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
(-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
if (num >= 0) { if (num >= 0) {
pred = (int)(((Q02 << 7) + num) / (Q02 << 8)); pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
if (Al > 0 && pred >= (1 << Al)) if (Al > 0 && pred >= (1 << Al))
@@ -701,96 +597,14 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
} }
workspace[2] = (JCOEF)pred; workspace[2] = (JCOEF)pred;
} }
if (change_dc) {
/* AC03 */
if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
if (num >= 0) {
pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
if (Al > 0 && pred >= (1 << Al))
pred = (1 << Al) - 1;
} else {
pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
if (Al > 0 && pred >= (1 << Al))
pred = (1 << Al) - 1;
pred = -pred;
}
workspace[3] = (JCOEF)pred;
}
/* AC12 */
if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
if (num >= 0) {
pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
if (Al > 0 && pred >= (1 << Al))
pred = (1 << Al) - 1;
} else {
pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
if (Al > 0 && pred >= (1 << Al))
pred = (1 << Al) - 1;
pred = -pred;
}
workspace[10] = (JCOEF)pred;
}
/* AC21 */
if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
if (num >= 0) {
pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
if (Al > 0 && pred >= (1 << Al))
pred = (1 << Al) - 1;
} else {
pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
if (Al > 0 && pred >= (1 << Al))
pred = (1 << Al) - 1;
pred = -pred;
}
workspace[17] = (JCOEF)pred;
}
/* AC30 */
if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
if (num >= 0) {
pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
if (Al > 0 && pred >= (1 << Al))
pred = (1 << Al) - 1;
} else {
pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
if (Al > 0 && pred >= (1 << Al))
pred = (1 << Al) - 1;
pred = -pred;
}
workspace[24] = (JCOEF)pred;
}
/* coef_bits[0] is non-negative. Otherwise this function would not
* be called.
*/
num = Q00 *
(-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
if (num >= 0) {
pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
} else {
pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
pred = -pred;
}
workspace[0] = (JCOEF)pred;
} /* change_dc */
/* OK, do the IDCT */ /* OK, do the IDCT */
(*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr, (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
output_col); output_col);
/* Advance for next column */ /* Advance for next column */
DC01 = DC02; DC02 = DC03; DC03 = DC04; DC04 = DC05; DC1 = DC2; DC2 = DC3;
DC06 = DC07; DC07 = DC08; DC08 = DC09; DC09 = DC10; DC4 = DC5; DC5 = DC6;
DC11 = DC12; DC12 = DC13; DC13 = DC14; DC14 = DC15; DC7 = DC8; DC8 = DC9;
DC16 = DC17; DC17 = DC18; DC18 = DC19; DC19 = DC20; buffer_ptr++, prev_block_row++, next_block_row++;
DC21 = DC22; DC22 = DC23; DC23 = DC24; DC24 = DC25;
buffer_ptr++, prev_block_row++, next_block_row++,
prev_prev_block_row++, next_next_block_row++;
output_col += compptr->_DCT_scaled_size; output_col += compptr->_DCT_scaled_size;
} }
output_ptr += compptr->_DCT_scaled_size; output_ptr += compptr->_DCT_scaled_size;
@@ -839,7 +653,7 @@ jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
#ifdef BLOCK_SMOOTHING_SUPPORTED #ifdef BLOCK_SMOOTHING_SUPPORTED
/* If block smoothing could be used, need a bigger window */ /* If block smoothing could be used, need a bigger window */
if (cinfo->progressive_mode) if (cinfo->progressive_mode)
access_rows *= 5; access_rows *= 3;
#endif #endif
coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE, ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
+1 -2
View File
@@ -5,7 +5,6 @@
* Copyright (C) 1994-1997, Thomas G. Lane. * Copyright (C) 1994-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2020, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
*/ */
@@ -52,7 +51,7 @@ typedef struct {
#ifdef BLOCK_SMOOTHING_SUPPORTED #ifdef BLOCK_SMOOTHING_SUPPORTED
/* When doing block smoothing, we latch coefficient Al values here */ /* When doing block smoothing, we latch coefficient Al values here */
int *coef_bits_latch; int *coef_bits_latch;
#define SAVED_COEFS 10 /* we save coef_bits[0..9] */ #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
#endif #endif
} my_coef_controller; } my_coef_controller;
+48 -48
View File
@@ -45,9 +45,9 @@ ycc_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
outptr = *output_buf++; outptr = *output_buf++;
if (PACK_NEED_ALIGNMENT(outptr)) { if (PACK_NEED_ALIGNMENT(outptr)) {
y = *inptr0++; y = GETJSAMPLE(*inptr0++);
cb = *inptr1++; cb = GETJSAMPLE(*inptr1++);
cr = *inptr2++; cr = GETJSAMPLE(*inptr2++);
r = range_limit[y + Crrtab[cr]]; r = range_limit[y + Crrtab[cr]];
g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS))]; SCALEBITS))];
@@ -58,18 +58,18 @@ ycc_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
num_cols--; num_cols--;
} }
for (col = 0; col < (num_cols >> 1); col++) { for (col = 0; col < (num_cols >> 1); col++) {
y = *inptr0++; y = GETJSAMPLE(*inptr0++);
cb = *inptr1++; cb = GETJSAMPLE(*inptr1++);
cr = *inptr2++; cr = GETJSAMPLE(*inptr2++);
r = range_limit[y + Crrtab[cr]]; r = range_limit[y + Crrtab[cr]];
g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS))]; SCALEBITS))];
b = range_limit[y + Cbbtab[cb]]; b = range_limit[y + Cbbtab[cb]];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
y = *inptr0++; y = GETJSAMPLE(*inptr0++);
cb = *inptr1++; cb = GETJSAMPLE(*inptr1++);
cr = *inptr2++; cr = GETJSAMPLE(*inptr2++);
r = range_limit[y + Crrtab[cr]]; r = range_limit[y + Crrtab[cr]];
g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS))]; SCALEBITS))];
@@ -80,9 +80,9 @@ ycc_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
outptr += 4; outptr += 4;
} }
if (num_cols & 1) { if (num_cols & 1) {
y = *inptr0; y = GETJSAMPLE(*inptr0);
cb = *inptr1; cb = GETJSAMPLE(*inptr1);
cr = *inptr2; cr = GETJSAMPLE(*inptr2);
r = range_limit[y + Crrtab[cr]]; r = range_limit[y + Crrtab[cr]];
g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], g = range_limit[y + ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS))]; SCALEBITS))];
@@ -125,9 +125,9 @@ ycc_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
input_row++; input_row++;
outptr = *output_buf++; outptr = *output_buf++;
if (PACK_NEED_ALIGNMENT(outptr)) { if (PACK_NEED_ALIGNMENT(outptr)) {
y = *inptr0++; y = GETJSAMPLE(*inptr0++);
cb = *inptr1++; cb = GETJSAMPLE(*inptr1++);
cr = *inptr2++; cr = GETJSAMPLE(*inptr2++);
r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)]; r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
g = range_limit[DITHER_565_G(y + g = range_limit[DITHER_565_G(y +
((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
@@ -139,9 +139,9 @@ ycc_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
num_cols--; num_cols--;
} }
for (col = 0; col < (num_cols >> 1); col++) { for (col = 0; col < (num_cols >> 1); col++) {
y = *inptr0++; y = GETJSAMPLE(*inptr0++);
cb = *inptr1++; cb = GETJSAMPLE(*inptr1++);
cr = *inptr2++; cr = GETJSAMPLE(*inptr2++);
r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)]; r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
g = range_limit[DITHER_565_G(y + g = range_limit[DITHER_565_G(y +
((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
@@ -150,9 +150,9 @@ ycc_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
d0 = DITHER_ROTATE(d0); d0 = DITHER_ROTATE(d0);
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
y = *inptr0++; y = GETJSAMPLE(*inptr0++);
cb = *inptr1++; cb = GETJSAMPLE(*inptr1++);
cr = *inptr2++; cr = GETJSAMPLE(*inptr2++);
r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)]; r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
g = range_limit[DITHER_565_G(y + g = range_limit[DITHER_565_G(y +
((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
@@ -165,9 +165,9 @@ ycc_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
outptr += 4; outptr += 4;
} }
if (num_cols & 1) { if (num_cols & 1) {
y = *inptr0; y = GETJSAMPLE(*inptr0);
cb = *inptr1; cb = GETJSAMPLE(*inptr1);
cr = *inptr2; cr = GETJSAMPLE(*inptr2);
r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)]; r = range_limit[DITHER_565_R(y + Crrtab[cr], d0)];
g = range_limit[DITHER_565_G(y + g = range_limit[DITHER_565_G(y +
((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], ((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
@@ -202,32 +202,32 @@ rgb_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
input_row++; input_row++;
outptr = *output_buf++; outptr = *output_buf++;
if (PACK_NEED_ALIGNMENT(outptr)) { if (PACK_NEED_ALIGNMENT(outptr)) {
r = *inptr0++; r = GETJSAMPLE(*inptr0++);
g = *inptr1++; g = GETJSAMPLE(*inptr1++);
b = *inptr2++; b = GETJSAMPLE(*inptr2++);
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16 *)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
outptr += 2; outptr += 2;
num_cols--; num_cols--;
} }
for (col = 0; col < (num_cols >> 1); col++) { for (col = 0; col < (num_cols >> 1); col++) {
r = *inptr0++; r = GETJSAMPLE(*inptr0++);
g = *inptr1++; g = GETJSAMPLE(*inptr1++);
b = *inptr2++; b = GETJSAMPLE(*inptr2++);
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
r = *inptr0++; r = GETJSAMPLE(*inptr0++);
g = *inptr1++; g = GETJSAMPLE(*inptr1++);
b = *inptr2++; b = GETJSAMPLE(*inptr2++);
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b)); rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
WRITE_TWO_ALIGNED_PIXELS(outptr, rgb); WRITE_TWO_ALIGNED_PIXELS(outptr, rgb);
outptr += 4; outptr += 4;
} }
if (num_cols & 1) { if (num_cols & 1) {
r = *inptr0; r = GETJSAMPLE(*inptr0);
g = *inptr1; g = GETJSAMPLE(*inptr1);
b = *inptr2; b = GETJSAMPLE(*inptr2);
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16 *)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
} }
@@ -259,24 +259,24 @@ rgb_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
input_row++; input_row++;
outptr = *output_buf++; outptr = *output_buf++;
if (PACK_NEED_ALIGNMENT(outptr)) { if (PACK_NEED_ALIGNMENT(outptr)) {
r = range_limit[DITHER_565_R(*inptr0++, d0)]; r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0++), d0)];
g = range_limit[DITHER_565_G(*inptr1++, d0)]; g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1++), d0)];
b = range_limit[DITHER_565_B(*inptr2++, d0)]; b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2++), d0)];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16 *)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
outptr += 2; outptr += 2;
num_cols--; num_cols--;
} }
for (col = 0; col < (num_cols >> 1); col++) { for (col = 0; col < (num_cols >> 1); col++) {
r = range_limit[DITHER_565_R(*inptr0++, d0)]; r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0++), d0)];
g = range_limit[DITHER_565_G(*inptr1++, d0)]; g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1++), d0)];
b = range_limit[DITHER_565_B(*inptr2++, d0)]; b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2++), d0)];
d0 = DITHER_ROTATE(d0); d0 = DITHER_ROTATE(d0);
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
r = range_limit[DITHER_565_R(*inptr0++, d0)]; r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0++), d0)];
g = range_limit[DITHER_565_G(*inptr1++, d0)]; g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1++), d0)];
b = range_limit[DITHER_565_B(*inptr2++, d0)]; b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2++), d0)];
d0 = DITHER_ROTATE(d0); d0 = DITHER_ROTATE(d0);
rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b)); rgb = PACK_TWO_PIXELS(rgb, PACK_SHORT_565(r, g, b));
@@ -284,9 +284,9 @@ rgb_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
outptr += 4; outptr += 4;
} }
if (num_cols & 1) { if (num_cols & 1) {
r = range_limit[DITHER_565_R(*inptr0, d0)]; r = range_limit[DITHER_565_R(GETJSAMPLE(*inptr0), d0)];
g = range_limit[DITHER_565_G(*inptr1, d0)]; g = range_limit[DITHER_565_G(GETJSAMPLE(*inptr1), d0)];
b = range_limit[DITHER_565_B(*inptr2, d0)]; b = range_limit[DITHER_565_B(GETJSAMPLE(*inptr2), d0)];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16 *)outptr = (INT16)rgb; *(INT16 *)outptr = (INT16)rgb;
} }
+5 -3
View File
@@ -53,9 +53,9 @@ ycc_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
input_row++; input_row++;
outptr = *output_buf++; outptr = *output_buf++;
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
y = inptr0[col]; y = GETJSAMPLE(inptr0[col]);
cb = inptr1[col]; cb = GETJSAMPLE(inptr1[col]);
cr = inptr2[col]; cr = GETJSAMPLE(inptr2[col]);
/* Range-limiting is essential due to noise introduced by DCT losses. */ /* Range-limiting is essential due to noise introduced by DCT losses. */
outptr[RGB_RED] = range_limit[y + Crrtab[cr]]; outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
outptr[RGB_GREEN] = range_limit[y + outptr[RGB_GREEN] = range_limit[y +
@@ -93,6 +93,7 @@ gray_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
inptr = input_buf[0][input_row++]; inptr = input_buf[0][input_row++];
outptr = *output_buf++; outptr = *output_buf++;
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
/* We can dispense with GETJSAMPLE() here */
outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[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 */ /* Set unused byte to 0xFF so it can be interpreted as an opaque */
/* alpha channel value */ /* alpha channel value */
@@ -127,6 +128,7 @@ rgb_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
input_row++; input_row++;
outptr = *output_buf++; outptr = *output_buf++;
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
/* We can dispense with GETJSAMPLE() here */
outptr[RGB_RED] = inptr0[col]; outptr[RGB_RED] = inptr0[col];
outptr[RGB_GREEN] = inptr1[col]; outptr[RGB_GREEN] = inptr1[col];
outptr[RGB_BLUE] = inptr2[col]; outptr[RGB_BLUE] = inptr2[col];
+12 -11
View File
@@ -341,9 +341,9 @@ rgb_gray_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
input_row++; input_row++;
outptr = *output_buf++; outptr = *output_buf++;
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
r = inptr0[col]; r = GETJSAMPLE(inptr0[col]);
g = inptr1[col]; g = GETJSAMPLE(inptr1[col]);
b = inptr2[col]; b = GETJSAMPLE(inptr2[col]);
/* Y */ /* Y */
outptr[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] + outptr[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
ctab[b + B_Y_OFF]) >> SCALEBITS); ctab[b + B_Y_OFF]) >> SCALEBITS);
@@ -550,9 +550,9 @@ ycck_cmyk_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
input_row++; input_row++;
outptr = *output_buf++; outptr = *output_buf++;
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
y = inptr0[col]; y = GETJSAMPLE(inptr0[col]);
cb = inptr1[col]; cb = GETJSAMPLE(inptr1[col]);
cr = inptr2[col]; cr = GETJSAMPLE(inptr2[col]);
/* Range-limiting is essential due to noise introduced by DCT losses. */ /* Range-limiting is essential due to noise introduced by DCT losses. */
outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */ outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */ outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
@@ -560,7 +560,7 @@ ycck_cmyk_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
SCALEBITS)))]; SCALEBITS)))];
outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */ outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
/* K passes through unchanged */ /* K passes through unchanged */
outptr[3] = inptr3[col]; outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
outptr += 4; outptr += 4;
} }
} }
@@ -571,10 +571,11 @@ ycck_cmyk_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
* RGB565 conversion * RGB565 conversion
*/ */
#define PACK_SHORT_565_LE(r, g, b) \ #define PACK_SHORT_565_LE(r, g, b) ((((r) << 8) & 0xF800) | \
((((r) << 8) & 0xF800) | (((g) << 3) & 0x7E0) | ((b) >> 3)) (((g) << 3) & 0x7E0) | ((b) >> 3))
#define PACK_SHORT_565_BE(r, g, b) \ #define PACK_SHORT_565_BE(r, g, b) (((r) & 0xF8) | ((g) >> 5) | \
(((r) & 0xF8) | ((g) >> 5) | (((g) << 11) & 0xE000) | (((b) << 5) & 0x1F00)) (((g) << 11) & 0xE000) | \
(((b) << 5) & 0x1F00))
#define PACK_TWO_PIXELS_LE(l, r) ((r << 16) | l) #define PACK_TWO_PIXELS_LE(l, r) ((r << 16) | l)
#define PACK_TWO_PIXELS_BE(l, r) ((l << 16) | r) #define PACK_TWO_PIXELS_BE(l, r) ((l << 16) | r)
+29 -27
View File
@@ -4,8 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009-2011, 2016, 2018-2019, D. R. Commander. * Copyright (C) 2009-2011, 2016, 2018, D. R. Commander.
* Copyright (C) 2018, Matthias Räncker.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -40,6 +39,24 @@ typedef struct {
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
} savable_state; } savable_state;
/* This macro is to work around compilers with missing or broken
* structure assignment. You'll need to fix this code if you have
* such a compiler and you change MAX_COMPS_IN_SCAN.
*/
#ifndef NO_STRUCT_ASSIGN
#define ASSIGN_STATE(dest, src) ((dest) = (src))
#else
#if MAX_COMPS_IN_SCAN == 4
#define ASSIGN_STATE(dest, src) \
((dest).last_dc_val[0] = (src).last_dc_val[0], \
(dest).last_dc_val[1] = (src).last_dc_val[1], \
(dest).last_dc_val[2] = (src).last_dc_val[2], \
(dest).last_dc_val[3] = (src).last_dc_val[3])
#endif
#endif
typedef struct { typedef struct {
struct jpeg_entropy_decoder pub; /* public fields */ struct jpeg_entropy_decoder pub; /* public fields */
@@ -308,7 +325,7 @@ jpeg_fill_bit_buffer(bitread_working_state *state,
bytes_in_buffer = cinfo->src->bytes_in_buffer; bytes_in_buffer = cinfo->src->bytes_in_buffer;
} }
bytes_in_buffer--; bytes_in_buffer--;
c = *next_input_byte++; c = GETJOCTET(*next_input_byte++);
/* If it's 0xFF, check and discard stuffed zero byte */ /* If it's 0xFF, check and discard stuffed zero byte */
if (c == 0xFF) { if (c == 0xFF) {
@@ -325,7 +342,7 @@ jpeg_fill_bit_buffer(bitread_working_state *state,
bytes_in_buffer = cinfo->src->bytes_in_buffer; bytes_in_buffer = cinfo->src->bytes_in_buffer;
} }
bytes_in_buffer--; bytes_in_buffer--;
c = *next_input_byte++; c = GETJOCTET(*next_input_byte++);
} while (c == 0xFF); } while (c == 0xFF);
if (c == 0) { if (c == 0) {
@@ -388,8 +405,8 @@ no_more_bytes:
#define GET_BYTE { \ #define GET_BYTE { \
register int c0, c1; \ register int c0, c1; \
c0 = *buffer++; \ c0 = GETJOCTET(*buffer++); \
c1 = *buffer; \ c1 = GETJOCTET(*buffer); \
/* Pre-execute most common case */ \ /* Pre-execute most common case */ \
get_buffer = (get_buffer << 8) | c0; \ get_buffer = (get_buffer << 8) | c0; \
bits_left += 8; \ bits_left += 8; \
@@ -406,7 +423,7 @@ no_more_bytes:
} \ } \
} }
#if SIZEOF_SIZE_T == 8 || defined(_WIN64) || (defined(__x86_64__) && defined(__ILP32__)) #if SIZEOF_SIZE_T == 8 || defined(_WIN64)
/* Pre-fetch 48 bytes, because the holding register is 64-bit */ /* Pre-fetch 48 bytes, because the holding register is 64-bit */
#define FILL_BIT_BUFFER_FAST \ #define FILL_BIT_BUFFER_FAST \
@@ -540,12 +557,6 @@ process_restart(j_decompress_ptr cinfo)
} }
#if defined(__has_feature)
#if __has_feature(undefined_behavior_sanitizer)
__attribute__((no_sanitize("signed-integer-overflow"),
no_sanitize("unsigned-integer-overflow")))
#endif
#endif
LOCAL(boolean) LOCAL(boolean)
decode_mcu_slow(j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_slow(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
@@ -557,7 +568,7 @@ decode_mcu_slow(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Load up working state */ /* Load up working state */
BITREAD_LOAD_STATE(cinfo, entropy->bitstate); BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
state = entropy->saved; ASSIGN_STATE(state, entropy->saved);
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
JBLOCKROW block = MCU_data ? MCU_data[blkn] : NULL; JBLOCKROW block = MCU_data ? MCU_data[blkn] : NULL;
@@ -578,14 +589,6 @@ decode_mcu_slow(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (entropy->dc_needed[blkn]) { if (entropy->dc_needed[blkn]) {
/* Convert DC difference to actual value, update last_dc_val */ /* Convert DC difference to actual value, update last_dc_val */
int ci = cinfo->MCU_membership[blkn]; int ci = cinfo->MCU_membership[blkn];
/* Certain malformed JPEG images produce repeated DC coefficient
* differences of 2047 or -2047, which causes state.last_dc_val[ci] to
* grow until it overflows or underflows a 32-bit signed integer. This
* behavior is, to the best of our understanding, innocuous, and it is
* unclear how to work around it without potentially affecting
* performance. Thus, we (hopefully temporarily) suppress UBSan integer
* overflow errors for this function.
*/
s += state.last_dc_val[ci]; s += state.last_dc_val[ci];
state.last_dc_val[ci] = s; state.last_dc_val[ci] = s;
if (block) { if (block) {
@@ -646,7 +649,7 @@ decode_mcu_slow(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Completed MCU, so update state */ /* Completed MCU, so update state */
BITREAD_SAVE_STATE(cinfo, entropy->bitstate); BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
entropy->saved = state; ASSIGN_STATE(entropy->saved, state);
return TRUE; return TRUE;
} }
@@ -664,7 +667,7 @@ decode_mcu_fast(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Load up working state */ /* Load up working state */
BITREAD_LOAD_STATE(cinfo, entropy->bitstate); BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
buffer = (JOCTET *)br_state.next_input_byte; buffer = (JOCTET *)br_state.next_input_byte;
state = entropy->saved; ASSIGN_STATE(state, entropy->saved);
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
JBLOCKROW block = MCU_data ? MCU_data[blkn] : NULL; JBLOCKROW block = MCU_data ? MCU_data[blkn] : NULL;
@@ -733,7 +736,7 @@ decode_mcu_fast(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
br_state.bytes_in_buffer -= (buffer - br_state.next_input_byte); br_state.bytes_in_buffer -= (buffer - br_state.next_input_byte);
br_state.next_input_byte = buffer; br_state.next_input_byte = buffer;
BITREAD_SAVE_STATE(cinfo, entropy->bitstate); BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
entropy->saved = state; ASSIGN_STATE(entropy->saved, state);
return TRUE; return TRUE;
} }
@@ -788,8 +791,7 @@ use_slow:
} }
/* Account for restart interval (no-op if not using restarts) */ /* Account for restart interval (no-op if not using restarts) */
if (cinfo->restart_interval) entropy->restarts_to_go--;
entropy->restarts_to_go--;
return TRUE; return TRUE;
} }
+2 -11
View File
@@ -4,8 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2010-2011, 2015-2016, 2021, D. R. Commander. * Copyright (C) 2010-2011, 2015-2016, D. R. Commander.
* Copyright (C) 2018, Matthias Räncker.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -79,11 +78,6 @@ EXTERN(void) jpeg_make_d_derived_tbl(j_decompress_ptr cinfo, boolean isDC,
typedef size_t bit_buf_type; /* type of bit-extraction buffer */ typedef size_t bit_buf_type; /* type of bit-extraction buffer */
#define BIT_BUF_SIZE 64 /* size of buffer in bits */ #define BIT_BUF_SIZE 64 /* size of buffer in bits */
#elif defined(__x86_64__) && defined(__ILP32__)
typedef unsigned long long bit_buf_type; /* type of bit-extraction buffer */
#define BIT_BUF_SIZE 64 /* size of buffer in bits */
#else #else
typedef unsigned long bit_buf_type; /* type of bit-extraction buffer */ typedef unsigned long bit_buf_type; /* type of bit-extraction buffer */
@@ -234,10 +228,7 @@ slowlabel: \
s |= GET_BITS(1); \ s |= GET_BITS(1); \
nb++; \ nb++; \
} \ } \
if (nb > 16) \ s = htbl->pub->huffval[(int)(s + htbl->valoffset[nb]) & 0xFF]; \
s = 0; \
else \
s = htbl->pub->huffval[(int)(s + htbl->valoffset[nb]) & 0xFF]; \
} }
/* Out-of-line case for Huffman code fetching */ /* Out-of-line case for Huffman code fetching */
+16 -16
View File
@@ -38,18 +38,18 @@ marker_is_icc(jpeg_saved_marker_ptr marker)
marker->marker == ICC_MARKER && marker->marker == ICC_MARKER &&
marker->data_length >= ICC_OVERHEAD_LEN && marker->data_length >= ICC_OVERHEAD_LEN &&
/* verify the identifying string */ /* verify the identifying string */
marker->data[0] == 0x49 && GETJOCTET(marker->data[0]) == 0x49 &&
marker->data[1] == 0x43 && GETJOCTET(marker->data[1]) == 0x43 &&
marker->data[2] == 0x43 && GETJOCTET(marker->data[2]) == 0x43 &&
marker->data[3] == 0x5F && GETJOCTET(marker->data[3]) == 0x5F &&
marker->data[4] == 0x50 && GETJOCTET(marker->data[4]) == 0x50 &&
marker->data[5] == 0x52 && GETJOCTET(marker->data[5]) == 0x52 &&
marker->data[6] == 0x4F && GETJOCTET(marker->data[6]) == 0x4F &&
marker->data[7] == 0x46 && GETJOCTET(marker->data[7]) == 0x46 &&
marker->data[8] == 0x49 && GETJOCTET(marker->data[8]) == 0x49 &&
marker->data[9] == 0x4C && GETJOCTET(marker->data[9]) == 0x4C &&
marker->data[10] == 0x45 && GETJOCTET(marker->data[10]) == 0x45 &&
marker->data[11] == 0x0; GETJOCTET(marker->data[11]) == 0x0;
} }
@@ -102,12 +102,12 @@ jpeg_read_icc_profile(j_decompress_ptr cinfo, JOCTET **icc_data_ptr,
for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) { for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) {
if (marker_is_icc(marker)) { if (marker_is_icc(marker)) {
if (num_markers == 0) if (num_markers == 0)
num_markers = marker->data[13]; num_markers = GETJOCTET(marker->data[13]);
else if (num_markers != marker->data[13]) { else if (num_markers != GETJOCTET(marker->data[13])) {
WARNMS(cinfo, JWRN_BOGUS_ICC); /* inconsistent num_markers fields */ WARNMS(cinfo, JWRN_BOGUS_ICC); /* inconsistent num_markers fields */
return FALSE; return FALSE;
} }
seq_no = marker->data[12]; seq_no = GETJOCTET(marker->data[12]);
if (seq_no <= 0 || seq_no > num_markers) { if (seq_no <= 0 || seq_no > num_markers) {
WARNMS(cinfo, JWRN_BOGUS_ICC); /* bogus sequence number */ WARNMS(cinfo, JWRN_BOGUS_ICC); /* bogus sequence number */
return FALSE; return FALSE;
@@ -154,7 +154,7 @@ jpeg_read_icc_profile(j_decompress_ptr cinfo, JOCTET **icc_data_ptr,
JOCTET FAR *src_ptr; JOCTET FAR *src_ptr;
JOCTET *dst_ptr; JOCTET *dst_ptr;
unsigned int length; unsigned int length;
seq_no = marker->data[12]; seq_no = GETJOCTET(marker->data[12]);
dst_ptr = icc_data + data_offset[seq_no]; dst_ptr = icc_data + data_offset[seq_no];
src_ptr = marker->data + ICC_OVERHEAD_LEN; src_ptr = marker->data + ICC_OVERHEAD_LEN;
length = data_length[seq_no]; length = data_length[seq_no];
+35 -32
View File
@@ -151,7 +151,7 @@ typedef my_marker_reader *my_marker_ptr;
#define INPUT_BYTE(cinfo, V, action) \ #define INPUT_BYTE(cinfo, V, action) \
MAKESTMT( MAKE_BYTE_AVAIL(cinfo, action); \ MAKESTMT( MAKE_BYTE_AVAIL(cinfo, action); \
bytes_in_buffer--; \ bytes_in_buffer--; \
V = *next_input_byte++; ) V = GETJOCTET(*next_input_byte++); )
/* As above, but read two bytes interpreted as an unsigned 16-bit integer. /* As above, but read two bytes interpreted as an unsigned 16-bit integer.
* V should be declared unsigned int or perhaps JLONG. * V should be declared unsigned int or perhaps JLONG.
@@ -159,10 +159,10 @@ typedef my_marker_reader *my_marker_ptr;
#define INPUT_2BYTES(cinfo, V, action) \ #define INPUT_2BYTES(cinfo, V, action) \
MAKESTMT( MAKE_BYTE_AVAIL(cinfo, action); \ MAKESTMT( MAKE_BYTE_AVAIL(cinfo, action); \
bytes_in_buffer--; \ bytes_in_buffer--; \
V = ((unsigned int)(*next_input_byte++)) << 8; \ V = ((unsigned int)GETJOCTET(*next_input_byte++)) << 8; \
MAKE_BYTE_AVAIL(cinfo, action); \ MAKE_BYTE_AVAIL(cinfo, action); \
bytes_in_buffer--; \ bytes_in_buffer--; \
V += *next_input_byte++; ) V += GETJOCTET(*next_input_byte++); )
/* /*
@@ -608,18 +608,18 @@ examine_app0(j_decompress_ptr cinfo, JOCTET *data, unsigned int datalen,
JLONG totallen = (JLONG)datalen + remaining; JLONG totallen = (JLONG)datalen + remaining;
if (datalen >= APP0_DATA_LEN && if (datalen >= APP0_DATA_LEN &&
data[0] == 0x4A && GETJOCTET(data[0]) == 0x4A &&
data[1] == 0x46 && GETJOCTET(data[1]) == 0x46 &&
data[2] == 0x49 && GETJOCTET(data[2]) == 0x49 &&
data[3] == 0x46 && GETJOCTET(data[3]) == 0x46 &&
data[4] == 0) { GETJOCTET(data[4]) == 0) {
/* Found JFIF APP0 marker: save info */ /* Found JFIF APP0 marker: save info */
cinfo->saw_JFIF_marker = TRUE; cinfo->saw_JFIF_marker = TRUE;
cinfo->JFIF_major_version = data[5]; cinfo->JFIF_major_version = GETJOCTET(data[5]);
cinfo->JFIF_minor_version = data[6]; cinfo->JFIF_minor_version = GETJOCTET(data[6]);
cinfo->density_unit = data[7]; cinfo->density_unit = GETJOCTET(data[7]);
cinfo->X_density = (data[8] << 8) + data[9]; cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
cinfo->Y_density = (data[10] << 8) + data[11]; cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
/* Check version. /* Check version.
* Major version must be 1, anything else signals an incompatible change. * Major version must be 1, anything else signals an incompatible change.
* (We used to treat this as an error, but now it's a nonfatal warning, * (We used to treat this as an error, but now it's a nonfatal warning,
@@ -634,22 +634,24 @@ examine_app0(j_decompress_ptr cinfo, JOCTET *data, unsigned int datalen,
cinfo->JFIF_major_version, cinfo->JFIF_minor_version, cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
cinfo->X_density, cinfo->Y_density, cinfo->density_unit); cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
/* Validate thumbnail dimensions and issue appropriate messages */ /* Validate thumbnail dimensions and issue appropriate messages */
if (data[12] | data[13]) if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL, data[12], data[13]); TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
GETJOCTET(data[12]), GETJOCTET(data[13]));
totallen -= APP0_DATA_LEN; totallen -= APP0_DATA_LEN;
if (totallen != ((JLONG)data[12] * (JLONG)data[13] * (JLONG)3)) if (totallen !=
((JLONG)GETJOCTET(data[12]) * (JLONG)GETJOCTET(data[13]) * (JLONG)3))
TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int)totallen); TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int)totallen);
} else if (datalen >= 6 && } else if (datalen >= 6 &&
data[0] == 0x4A && GETJOCTET(data[0]) == 0x4A &&
data[1] == 0x46 && GETJOCTET(data[1]) == 0x46 &&
data[2] == 0x58 && GETJOCTET(data[2]) == 0x58 &&
data[3] == 0x58 && GETJOCTET(data[3]) == 0x58 &&
data[4] == 0) { GETJOCTET(data[4]) == 0) {
/* Found JFIF "JFXX" extension APP0 marker */ /* Found JFIF "JFXX" extension APP0 marker */
/* The library doesn't actually do anything with these, /* The library doesn't actually do anything with these,
* but we try to produce a helpful trace message. * but we try to produce a helpful trace message.
*/ */
switch (data[5]) { switch (GETJOCTET(data[5])) {
case 0x10: case 0x10:
TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int)totallen); TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int)totallen);
break; break;
@@ -660,7 +662,8 @@ examine_app0(j_decompress_ptr cinfo, JOCTET *data, unsigned int datalen,
TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int)totallen); TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int)totallen);
break; break;
default: default:
TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION, data[5], (int)totallen); TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
GETJOCTET(data[5]), (int)totallen);
break; break;
} }
} else { } else {
@@ -681,16 +684,16 @@ examine_app14(j_decompress_ptr cinfo, JOCTET *data, unsigned int datalen,
unsigned int version, flags0, flags1, transform; unsigned int version, flags0, flags1, transform;
if (datalen >= APP14_DATA_LEN && if (datalen >= APP14_DATA_LEN &&
data[0] == 0x41 && GETJOCTET(data[0]) == 0x41 &&
data[1] == 0x64 && GETJOCTET(data[1]) == 0x64 &&
data[2] == 0x6F && GETJOCTET(data[2]) == 0x6F &&
data[3] == 0x62 && GETJOCTET(data[3]) == 0x62 &&
data[4] == 0x65) { GETJOCTET(data[4]) == 0x65) {
/* Found Adobe APP14 marker */ /* Found Adobe APP14 marker */
version = (data[5] << 8) + data[6]; version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
flags0 = (data[7] << 8) + data[8]; flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
flags1 = (data[9] << 8) + data[10]; flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
transform = data[11]; transform = GETJOCTET(data[11]);
TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform); TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
cinfo->saw_Adobe_marker = TRUE; cinfo->saw_Adobe_marker = TRUE;
cinfo->Adobe_transform = (UINT8)transform; cinfo->Adobe_transform = (UINT8)transform;
+13 -2
View File
@@ -5,7 +5,7 @@
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2002-2009 by Guido Vollbeding. * Modified 2002-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009-2011, 2016, 2019, D. R. Commander. * Copyright (C) 2009-2011, 2016, D. R. Commander.
* Copyright (C) 2013, Linaro Limited. * Copyright (C) 2013, Linaro Limited.
* Copyright (C) 2015, Google, Inc. * Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
@@ -22,6 +22,7 @@
#include "jpeglib.h" #include "jpeglib.h"
#include "jpegcomp.h" #include "jpegcomp.h"
#include "jdmaster.h" #include "jdmaster.h"
#include "jsimd.h"
/* /*
@@ -69,6 +70,17 @@ use_merged_upsample(j_decompress_ptr cinfo)
cinfo->comp_info[1]._DCT_scaled_size != cinfo->_min_DCT_scaled_size || cinfo->comp_info[1]._DCT_scaled_size != cinfo->_min_DCT_scaled_size ||
cinfo->comp_info[2]._DCT_scaled_size != cinfo->_min_DCT_scaled_size) cinfo->comp_info[2]._DCT_scaled_size != cinfo->_min_DCT_scaled_size)
return FALSE; return FALSE;
#ifdef WITH_SIMD
/* If YCbCr-to-RGB color conversion is SIMD-accelerated but merged upsampling
isn't, then disabling merged upsampling is likely to be faster when
decompressing YCbCr JPEG images. */
if (!jsimd_can_h2v2_merged_upsample() && !jsimd_can_h2v1_merged_upsample() &&
jsimd_can_ycc_rgb() && cinfo->jpeg_color_space == JCS_YCbCr &&
(cinfo->out_color_space == JCS_RGB ||
(cinfo->out_color_space >= JCS_EXT_RGB &&
cinfo->out_color_space <= JCS_EXT_ARGB)))
return FALSE;
#endif
/* ??? also need to test for upsample-time rescaling, when & if supported */ /* ??? also need to test for upsample-time rescaling, when & if supported */
return TRUE; /* by golly, it'll work... */ return TRUE; /* by golly, it'll work... */
#else #else
@@ -568,7 +580,6 @@ master_selection(j_decompress_ptr cinfo)
*/ */
cinfo->master->first_iMCU_col = 0; cinfo->master->first_iMCU_col = 0;
cinfo->master->last_iMCU_col = cinfo->MCUs_per_row - 1; cinfo->master->last_iMCU_col = cinfo->MCUs_per_row - 1;
cinfo->master->last_good_iMCU_row = 0;
#ifdef D_MULTISCAN_FILES_SUPPORTED #ifdef D_MULTISCAN_FILES_SUPPORTED
/* If jpeg_start_decompress will read the whole file, initialize /* If jpeg_start_decompress will read the whole file, initialize
+44 -13
View File
@@ -5,7 +5,7 @@
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2009, 2011, 2014-2015, 2020, D. R. Commander. * Copyright (C) 2009, 2011, 2014-2015, D. R. Commander.
* Copyright (C) 2013, Linaro Limited. * Copyright (C) 2013, Linaro Limited.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
@@ -40,13 +40,41 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdmerge.h"
#include "jsimd.h" #include "jsimd.h"
#include "jconfigint.h" #include "jconfigint.h"
#ifdef UPSAMPLE_MERGING_SUPPORTED #ifdef UPSAMPLE_MERGING_SUPPORTED
/* Private subobject */
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);
/* 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 */
JLONG *Cr_g_tab; /* => table for Cr to G conversion */
JLONG *Cb_g_tab; /* => table for Cb to G conversion */
/* For 2:1 vertical sampling, we produce two output rows at a time.
* We need a "spare" row buffer to hold the second output row if the
* 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;
boolean spare_full; /* T if spare buffer is occupied */
JDIMENSION out_row_width; /* samples per output row */
JDIMENSION rows_to_go; /* counts rows remaining in image */
} my_upsampler;
typedef my_upsampler *my_upsample_ptr;
#define SCALEBITS 16 /* speediest right-shift on some machines */ #define SCALEBITS 16 /* speediest right-shift on some machines */
#define ONE_HALF ((JLONG)1 << (SCALEBITS - 1)) #define ONE_HALF ((JLONG)1 << (SCALEBITS - 1))
#define FIX(x) ((JLONG)((x) * (1L << SCALEBITS) + 0.5)) #define FIX(x) ((JLONG)((x) * (1L << SCALEBITS) + 0.5))
@@ -161,7 +189,7 @@
LOCAL(void) LOCAL(void)
build_ycc_rgb_table(j_decompress_ptr cinfo) build_ycc_rgb_table(j_decompress_ptr cinfo)
{ {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
int i; int i;
JLONG x; JLONG x;
SHIFT_TEMPS SHIFT_TEMPS
@@ -204,7 +232,7 @@ build_ycc_rgb_table(j_decompress_ptr cinfo)
METHODDEF(void) METHODDEF(void)
start_pass_merged_upsample(j_decompress_ptr cinfo) start_pass_merged_upsample(j_decompress_ptr cinfo)
{ {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
/* Mark the spare buffer empty */ /* Mark the spare buffer empty */
upsample->spare_full = FALSE; upsample->spare_full = FALSE;
@@ -226,7 +254,7 @@ merged_2v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail) JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
/* 2:1 vertical sampling case: may need a spare row. */ /* 2:1 vertical sampling case: may need a spare row. */
{ {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
JSAMPROW work_ptrs[2]; JSAMPROW work_ptrs[2];
JDIMENSION num_rows; /* number of rows returned to caller */ JDIMENSION num_rows; /* number of rows returned to caller */
@@ -277,7 +305,7 @@ merged_1v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail) JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
/* 1:1 vertical sampling case: much easier, never need a spare row. */ /* 1:1 vertical sampling case: much easier, never need a spare row. */
{ {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
/* Just do the upsampling. */ /* Just do the upsampling. */
(*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
@@ -392,14 +420,17 @@ h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
* RGB565 conversion * RGB565 conversion
*/ */
#define PACK_SHORT_565_LE(r, g, b) \ #define PACK_SHORT_565_LE(r, g, b) ((((r) << 8) & 0xF800) | \
((((r) << 8) & 0xF800) | (((g) << 3) & 0x7E0) | ((b) >> 3)) (((g) << 3) & 0x7E0) | ((b) >> 3))
#define PACK_SHORT_565_BE(r, g, b) \ #define PACK_SHORT_565_BE(r, g, b) (((r) & 0xF8) | ((g) >> 5) | \
(((r) & 0xF8) | ((g) >> 5) | (((g) << 11) & 0xE000) | (((b) << 5) & 0x1F00)) (((g) << 11) & 0xE000) | \
(((b) << 5) & 0x1F00))
#define PACK_TWO_PIXELS_LE(l, r) ((r << 16) | l) #define PACK_TWO_PIXELS_LE(l, r) ((r << 16) | l)
#define PACK_TWO_PIXELS_BE(l, r) ((l << 16) | r) #define PACK_TWO_PIXELS_BE(l, r) ((l << 16) | r)
#define PACK_NEED_ALIGNMENT(ptr) (((size_t)(ptr)) & 3)
#define WRITE_TWO_PIXELS_LE(addr, pixels) { \ #define WRITE_TWO_PIXELS_LE(addr, pixels) { \
((INT16 *)(addr))[0] = (INT16)(pixels); \ ((INT16 *)(addr))[0] = (INT16)(pixels); \
((INT16 *)(addr))[1] = (INT16)((pixels) >> 16); \ ((INT16 *)(addr))[1] = (INT16)((pixels) >> 16); \
@@ -537,11 +568,11 @@ h2v2_merged_upsample_565D(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
GLOBAL(void) GLOBAL(void)
jinit_merged_upsampler(j_decompress_ptr cinfo) jinit_merged_upsampler(j_decompress_ptr cinfo)
{ {
my_merged_upsample_ptr upsample; my_upsample_ptr upsample;
upsample = (my_merged_upsample_ptr) upsample = (my_upsample_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_merged_upsampler)); sizeof(my_upsampler));
cinfo->upsample = (struct jpeg_upsampler *)upsample; cinfo->upsample = (struct jpeg_upsampler *)upsample;
upsample->pub.start_pass = start_pass_merged_upsample; upsample->pub.start_pass = start_pass_merged_upsample;
upsample->pub.need_context_rows = FALSE; upsample->pub.need_context_rows = FALSE;
-47
View File
@@ -1,47 +0,0 @@
/*
* jdmerge.h
*
* 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.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*/
#define JPEG_INTERNALS
#include "jpeglib.h"
#ifdef UPSAMPLE_MERGING_SUPPORTED
/* Private subobject */
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);
/* 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 */
JLONG *Cr_g_tab; /* => table for Cr to G conversion */
JLONG *Cb_g_tab; /* => table for Cb to G conversion */
/* For 2:1 vertical sampling, we produce two output rows at a time.
* We need a "spare" row buffer to hold the second output row if the
* 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;
boolean spare_full; /* T if spare buffer is occupied */
JDIMENSION out_row_width; /* samples per output row */
JDIMENSION rows_to_go; /* counts rows remaining in image */
} my_merged_upsampler;
typedef my_merged_upsampler *my_merged_upsample_ptr;
#endif /* UPSAMPLE_MERGING_SUPPORTED */
+39 -39
View File
@@ -5,7 +5,7 @@
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2013, Linaro Limited. * Copyright (C) 2013, Linaro Limited.
* Copyright (C) 2014-2015, 2018, 2020, D. R. Commander. * Copyright (C) 2014-2015, 2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -19,7 +19,7 @@ h2v1_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf) JSAMPARRAY output_buf)
{ {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue; register int y, cred, cgreen, cblue;
int cb, cr; int cb, cr;
register JSAMPROW outptr; register JSAMPROW outptr;
@@ -43,20 +43,20 @@ h2v1_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
/* Loop for each pair of output pixels */ /* Loop for each pair of output pixels */
for (col = cinfo->output_width >> 1; col > 0; col--) { for (col = cinfo->output_width >> 1; col > 0; col--) {
/* Do the chroma part of the calculation */ /* Do the chroma part of the calculation */
cb = *inptr1++; cb = GETJSAMPLE(*inptr1++);
cr = *inptr2++; cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
/* Fetch 2 Y values and emit 2 pixels */ /* Fetch 2 Y values and emit 2 pixels */
y = *inptr0++; y = GETJSAMPLE(*inptr0++);
r = range_limit[y + cred]; r = range_limit[y + cred];
g = range_limit[y + cgreen]; g = range_limit[y + cgreen];
b = range_limit[y + cblue]; b = range_limit[y + cblue];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
y = *inptr0++; y = GETJSAMPLE(*inptr0++);
r = range_limit[y + cred]; r = range_limit[y + cred];
g = range_limit[y + cgreen]; g = range_limit[y + cgreen];
b = range_limit[y + cblue]; b = range_limit[y + cblue];
@@ -68,12 +68,12 @@ h2v1_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
/* If image width is odd, do the last output column separately */ /* If image width is odd, do the last output column separately */
if (cinfo->output_width & 1) { if (cinfo->output_width & 1) {
cb = *inptr1; cb = GETJSAMPLE(*inptr1);
cr = *inptr2; cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
y = *inptr0; y = GETJSAMPLE(*inptr0);
r = range_limit[y + cred]; r = range_limit[y + cred];
g = range_limit[y + cgreen]; g = range_limit[y + cgreen];
b = range_limit[y + cblue]; b = range_limit[y + cblue];
@@ -90,7 +90,7 @@ h2v1_merged_upsample_565D_internal(j_decompress_ptr cinfo,
JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf) JSAMPARRAY output_buf)
{ {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue; register int y, cred, cgreen, cblue;
int cb, cr; int cb, cr;
register JSAMPROW outptr; register JSAMPROW outptr;
@@ -115,21 +115,21 @@ h2v1_merged_upsample_565D_internal(j_decompress_ptr cinfo,
/* Loop for each pair of output pixels */ /* Loop for each pair of output pixels */
for (col = cinfo->output_width >> 1; col > 0; col--) { for (col = cinfo->output_width >> 1; col > 0; col--) {
/* Do the chroma part of the calculation */ /* Do the chroma part of the calculation */
cb = *inptr1++; cb = GETJSAMPLE(*inptr1++);
cr = *inptr2++; cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
/* Fetch 2 Y values and emit 2 pixels */ /* Fetch 2 Y values and emit 2 pixels */
y = *inptr0++; y = GETJSAMPLE(*inptr0++);
r = range_limit[DITHER_565_R(y + cred, d0)]; r = range_limit[DITHER_565_R(y + cred, d0)];
g = range_limit[DITHER_565_G(y + cgreen, d0)]; g = range_limit[DITHER_565_G(y + cgreen, d0)];
b = range_limit[DITHER_565_B(y + cblue, d0)]; b = range_limit[DITHER_565_B(y + cblue, d0)];
d0 = DITHER_ROTATE(d0); d0 = DITHER_ROTATE(d0);
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
y = *inptr0++; y = GETJSAMPLE(*inptr0++);
r = range_limit[DITHER_565_R(y + cred, d0)]; r = range_limit[DITHER_565_R(y + cred, d0)];
g = range_limit[DITHER_565_G(y + cgreen, d0)]; g = range_limit[DITHER_565_G(y + cgreen, d0)];
b = range_limit[DITHER_565_B(y + cblue, d0)]; b = range_limit[DITHER_565_B(y + cblue, d0)];
@@ -142,12 +142,12 @@ h2v1_merged_upsample_565D_internal(j_decompress_ptr cinfo,
/* If image width is odd, do the last output column separately */ /* If image width is odd, do the last output column separately */
if (cinfo->output_width & 1) { if (cinfo->output_width & 1) {
cb = *inptr1; cb = GETJSAMPLE(*inptr1);
cr = *inptr2; cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
y = *inptr0; y = GETJSAMPLE(*inptr0);
r = range_limit[DITHER_565_R(y + cred, d0)]; r = range_limit[DITHER_565_R(y + cred, d0)];
g = range_limit[DITHER_565_G(y + cgreen, d0)]; g = range_limit[DITHER_565_G(y + cgreen, d0)];
b = range_limit[DITHER_565_B(y + cblue, d0)]; b = range_limit[DITHER_565_B(y + cblue, d0)];
@@ -163,7 +163,7 @@ h2v2_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf) JSAMPARRAY output_buf)
{ {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue; register int y, cred, cgreen, cblue;
int cb, cr; int cb, cr;
register JSAMPROW outptr0, outptr1; register JSAMPROW outptr0, outptr1;
@@ -189,20 +189,20 @@ h2v2_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
/* Loop for each group of output pixels */ /* Loop for each group of output pixels */
for (col = cinfo->output_width >> 1; col > 0; col--) { for (col = cinfo->output_width >> 1; col > 0; col--) {
/* Do the chroma part of the calculation */ /* Do the chroma part of the calculation */
cb = *inptr1++; cb = GETJSAMPLE(*inptr1++);
cr = *inptr2++; cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
/* Fetch 4 Y values and emit 4 pixels */ /* Fetch 4 Y values and emit 4 pixels */
y = *inptr00++; y = GETJSAMPLE(*inptr00++);
r = range_limit[y + cred]; r = range_limit[y + cred];
g = range_limit[y + cgreen]; g = range_limit[y + cgreen];
b = range_limit[y + cblue]; b = range_limit[y + cblue];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
y = *inptr00++; y = GETJSAMPLE(*inptr00++);
r = range_limit[y + cred]; r = range_limit[y + cred];
g = range_limit[y + cgreen]; g = range_limit[y + cgreen];
b = range_limit[y + cblue]; b = range_limit[y + cblue];
@@ -211,13 +211,13 @@ h2v2_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
WRITE_TWO_PIXELS(outptr0, rgb); WRITE_TWO_PIXELS(outptr0, rgb);
outptr0 += 4; outptr0 += 4;
y = *inptr01++; y = GETJSAMPLE(*inptr01++);
r = range_limit[y + cred]; r = range_limit[y + cred];
g = range_limit[y + cgreen]; g = range_limit[y + cgreen];
b = range_limit[y + cblue]; b = range_limit[y + cblue];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
y = *inptr01++; y = GETJSAMPLE(*inptr01++);
r = range_limit[y + cred]; r = range_limit[y + cred];
g = range_limit[y + cgreen]; g = range_limit[y + cgreen];
b = range_limit[y + cblue]; b = range_limit[y + cblue];
@@ -229,20 +229,20 @@ h2v2_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
/* If image width is odd, do the last output column separately */ /* If image width is odd, do the last output column separately */
if (cinfo->output_width & 1) { if (cinfo->output_width & 1) {
cb = *inptr1; cb = GETJSAMPLE(*inptr1);
cr = *inptr2; cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
y = *inptr00; y = GETJSAMPLE(*inptr00);
r = range_limit[y + cred]; r = range_limit[y + cred];
g = range_limit[y + cgreen]; g = range_limit[y + cgreen];
b = range_limit[y + cblue]; b = range_limit[y + cblue];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16 *)outptr0 = (INT16)rgb; *(INT16 *)outptr0 = (INT16)rgb;
y = *inptr01; y = GETJSAMPLE(*inptr01);
r = range_limit[y + cred]; r = range_limit[y + cred];
g = range_limit[y + cgreen]; g = range_limit[y + cgreen];
b = range_limit[y + cblue]; b = range_limit[y + cblue];
@@ -259,7 +259,7 @@ h2v2_merged_upsample_565D_internal(j_decompress_ptr cinfo,
JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf) JSAMPARRAY output_buf)
{ {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue; register int y, cred, cgreen, cblue;
int cb, cr; int cb, cr;
register JSAMPROW outptr0, outptr1; register JSAMPROW outptr0, outptr1;
@@ -287,21 +287,21 @@ h2v2_merged_upsample_565D_internal(j_decompress_ptr cinfo,
/* Loop for each group of output pixels */ /* Loop for each group of output pixels */
for (col = cinfo->output_width >> 1; col > 0; col--) { for (col = cinfo->output_width >> 1; col > 0; col--) {
/* Do the chroma part of the calculation */ /* Do the chroma part of the calculation */
cb = *inptr1++; cb = GETJSAMPLE(*inptr1++);
cr = *inptr2++; cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
/* Fetch 4 Y values and emit 4 pixels */ /* Fetch 4 Y values and emit 4 pixels */
y = *inptr00++; y = GETJSAMPLE(*inptr00++);
r = range_limit[DITHER_565_R(y + cred, d0)]; r = range_limit[DITHER_565_R(y + cred, d0)];
g = range_limit[DITHER_565_G(y + cgreen, d0)]; g = range_limit[DITHER_565_G(y + cgreen, d0)];
b = range_limit[DITHER_565_B(y + cblue, d0)]; b = range_limit[DITHER_565_B(y + cblue, d0)];
d0 = DITHER_ROTATE(d0); d0 = DITHER_ROTATE(d0);
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
y = *inptr00++; y = GETJSAMPLE(*inptr00++);
r = range_limit[DITHER_565_R(y + cred, d0)]; r = range_limit[DITHER_565_R(y + cred, d0)];
g = range_limit[DITHER_565_G(y + cgreen, d0)]; g = range_limit[DITHER_565_G(y + cgreen, d0)];
b = range_limit[DITHER_565_B(y + cblue, d0)]; b = range_limit[DITHER_565_B(y + cblue, d0)];
@@ -311,14 +311,14 @@ h2v2_merged_upsample_565D_internal(j_decompress_ptr cinfo,
WRITE_TWO_PIXELS(outptr0, rgb); WRITE_TWO_PIXELS(outptr0, rgb);
outptr0 += 4; outptr0 += 4;
y = *inptr01++; y = GETJSAMPLE(*inptr01++);
r = range_limit[DITHER_565_R(y + cred, d1)]; r = range_limit[DITHER_565_R(y + cred, d1)];
g = range_limit[DITHER_565_G(y + cgreen, d1)]; g = range_limit[DITHER_565_G(y + cgreen, d1)];
b = range_limit[DITHER_565_B(y + cblue, d1)]; b = range_limit[DITHER_565_B(y + cblue, d1)];
d1 = DITHER_ROTATE(d1); d1 = DITHER_ROTATE(d1);
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
y = *inptr01++; y = GETJSAMPLE(*inptr01++);
r = range_limit[DITHER_565_R(y + cred, d1)]; r = range_limit[DITHER_565_R(y + cred, d1)];
g = range_limit[DITHER_565_G(y + cgreen, d1)]; g = range_limit[DITHER_565_G(y + cgreen, d1)];
b = range_limit[DITHER_565_B(y + cblue, d1)]; b = range_limit[DITHER_565_B(y + cblue, d1)];
@@ -331,20 +331,20 @@ h2v2_merged_upsample_565D_internal(j_decompress_ptr cinfo,
/* If image width is odd, do the last output column separately */ /* If image width is odd, do the last output column separately */
if (cinfo->output_width & 1) { if (cinfo->output_width & 1) {
cb = *inptr1; cb = GETJSAMPLE(*inptr1);
cr = *inptr2; cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
y = *inptr00; y = GETJSAMPLE(*inptr00);
r = range_limit[DITHER_565_R(y + cred, d0)]; r = range_limit[DITHER_565_R(y + cred, d0)];
g = range_limit[DITHER_565_G(y + cgreen, d0)]; g = range_limit[DITHER_565_G(y + cgreen, d0)];
b = range_limit[DITHER_565_B(y + cblue, d0)]; b = range_limit[DITHER_565_B(y + cblue, d0)];
rgb = PACK_SHORT_565(r, g, b); rgb = PACK_SHORT_565(r, g, b);
*(INT16 *)outptr0 = (INT16)rgb; *(INT16 *)outptr0 = (INT16)rgb;
y = *inptr01; y = GETJSAMPLE(*inptr01);
r = range_limit[DITHER_565_R(y + cred, d1)]; r = range_limit[DITHER_565_R(y + cred, d1)];
g = range_limit[DITHER_565_G(y + cgreen, d1)]; g = range_limit[DITHER_565_G(y + cgreen, d1)];
b = range_limit[DITHER_565_B(y + cblue, d1)]; b = range_limit[DITHER_565_B(y + cblue, d1)];
+20 -20
View File
@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2011, 2015, 2020, D. R. Commander. * Copyright (C) 2011, 2015, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -25,7 +25,7 @@ h2v1_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf) JSAMPARRAY output_buf)
{ {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue; register int y, cred, cgreen, cblue;
int cb, cr; int cb, cr;
register JSAMPROW outptr; register JSAMPROW outptr;
@@ -46,13 +46,13 @@ h2v1_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
/* Loop for each pair of output pixels */ /* Loop for each pair of output pixels */
for (col = cinfo->output_width >> 1; col > 0; col--) { for (col = cinfo->output_width >> 1; col > 0; col--) {
/* Do the chroma part of the calculation */ /* Do the chroma part of the calculation */
cb = *inptr1++; cb = GETJSAMPLE(*inptr1++);
cr = *inptr2++; cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
/* Fetch 2 Y values and emit 2 pixels */ /* Fetch 2 Y values and emit 2 pixels */
y = *inptr0++; y = GETJSAMPLE(*inptr0++);
outptr[RGB_RED] = range_limit[y + cred]; outptr[RGB_RED] = range_limit[y + cred];
outptr[RGB_GREEN] = range_limit[y + cgreen]; outptr[RGB_GREEN] = range_limit[y + cgreen];
outptr[RGB_BLUE] = range_limit[y + cblue]; outptr[RGB_BLUE] = range_limit[y + cblue];
@@ -60,7 +60,7 @@ h2v1_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
outptr[RGB_ALPHA] = 0xFF; outptr[RGB_ALPHA] = 0xFF;
#endif #endif
outptr += RGB_PIXELSIZE; outptr += RGB_PIXELSIZE;
y = *inptr0++; y = GETJSAMPLE(*inptr0++);
outptr[RGB_RED] = range_limit[y + cred]; outptr[RGB_RED] = range_limit[y + cred];
outptr[RGB_GREEN] = range_limit[y + cgreen]; outptr[RGB_GREEN] = range_limit[y + cgreen];
outptr[RGB_BLUE] = range_limit[y + cblue]; outptr[RGB_BLUE] = range_limit[y + cblue];
@@ -71,12 +71,12 @@ h2v1_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
} }
/* If image width is odd, do the last output column separately */ /* If image width is odd, do the last output column separately */
if (cinfo->output_width & 1) { if (cinfo->output_width & 1) {
cb = *inptr1; cb = GETJSAMPLE(*inptr1);
cr = *inptr2; cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
y = *inptr0; y = GETJSAMPLE(*inptr0);
outptr[RGB_RED] = range_limit[y + cred]; outptr[RGB_RED] = range_limit[y + cred];
outptr[RGB_GREEN] = range_limit[y + cgreen]; outptr[RGB_GREEN] = range_limit[y + cgreen];
outptr[RGB_BLUE] = range_limit[y + cblue]; outptr[RGB_BLUE] = range_limit[y + cblue];
@@ -97,7 +97,7 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf) JSAMPARRAY output_buf)
{ {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue; register int y, cred, cgreen, cblue;
int cb, cr; int cb, cr;
register JSAMPROW outptr0, outptr1; register JSAMPROW outptr0, outptr1;
@@ -120,13 +120,13 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
/* Loop for each group of output pixels */ /* Loop for each group of output pixels */
for (col = cinfo->output_width >> 1; col > 0; col--) { for (col = cinfo->output_width >> 1; col > 0; col--) {
/* Do the chroma part of the calculation */ /* Do the chroma part of the calculation */
cb = *inptr1++; cb = GETJSAMPLE(*inptr1++);
cr = *inptr2++; cr = GETJSAMPLE(*inptr2++);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
/* Fetch 4 Y values and emit 4 pixels */ /* Fetch 4 Y values and emit 4 pixels */
y = *inptr00++; y = GETJSAMPLE(*inptr00++);
outptr0[RGB_RED] = range_limit[y + cred]; outptr0[RGB_RED] = range_limit[y + cred];
outptr0[RGB_GREEN] = range_limit[y + cgreen]; outptr0[RGB_GREEN] = range_limit[y + cgreen];
outptr0[RGB_BLUE] = range_limit[y + cblue]; outptr0[RGB_BLUE] = range_limit[y + cblue];
@@ -134,7 +134,7 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
outptr0[RGB_ALPHA] = 0xFF; outptr0[RGB_ALPHA] = 0xFF;
#endif #endif
outptr0 += RGB_PIXELSIZE; outptr0 += RGB_PIXELSIZE;
y = *inptr00++; y = GETJSAMPLE(*inptr00++);
outptr0[RGB_RED] = range_limit[y + cred]; outptr0[RGB_RED] = range_limit[y + cred];
outptr0[RGB_GREEN] = range_limit[y + cgreen]; outptr0[RGB_GREEN] = range_limit[y + cgreen];
outptr0[RGB_BLUE] = range_limit[y + cblue]; outptr0[RGB_BLUE] = range_limit[y + cblue];
@@ -142,7 +142,7 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
outptr0[RGB_ALPHA] = 0xFF; outptr0[RGB_ALPHA] = 0xFF;
#endif #endif
outptr0 += RGB_PIXELSIZE; outptr0 += RGB_PIXELSIZE;
y = *inptr01++; y = GETJSAMPLE(*inptr01++);
outptr1[RGB_RED] = range_limit[y + cred]; outptr1[RGB_RED] = range_limit[y + cred];
outptr1[RGB_GREEN] = range_limit[y + cgreen]; outptr1[RGB_GREEN] = range_limit[y + cgreen];
outptr1[RGB_BLUE] = range_limit[y + cblue]; outptr1[RGB_BLUE] = range_limit[y + cblue];
@@ -150,7 +150,7 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
outptr1[RGB_ALPHA] = 0xFF; outptr1[RGB_ALPHA] = 0xFF;
#endif #endif
outptr1 += RGB_PIXELSIZE; outptr1 += RGB_PIXELSIZE;
y = *inptr01++; y = GETJSAMPLE(*inptr01++);
outptr1[RGB_RED] = range_limit[y + cred]; outptr1[RGB_RED] = range_limit[y + cred];
outptr1[RGB_GREEN] = range_limit[y + cgreen]; outptr1[RGB_GREEN] = range_limit[y + cgreen];
outptr1[RGB_BLUE] = range_limit[y + cblue]; outptr1[RGB_BLUE] = range_limit[y + cblue];
@@ -161,19 +161,19 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
} }
/* If image width is odd, do the last output column separately */ /* If image width is odd, do the last output column separately */
if (cinfo->output_width & 1) { if (cinfo->output_width & 1) {
cb = *inptr1; cb = GETJSAMPLE(*inptr1);
cr = *inptr2; cr = GETJSAMPLE(*inptr2);
cred = Crrtab[cr]; cred = Crrtab[cr];
cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
cblue = Cbbtab[cb]; cblue = Cbbtab[cb];
y = *inptr00; y = GETJSAMPLE(*inptr00);
outptr0[RGB_RED] = range_limit[y + cred]; outptr0[RGB_RED] = range_limit[y + cred];
outptr0[RGB_GREEN] = range_limit[y + cgreen]; outptr0[RGB_GREEN] = range_limit[y + cgreen];
outptr0[RGB_BLUE] = range_limit[y + cblue]; outptr0[RGB_BLUE] = range_limit[y + cblue];
#ifdef RGB_ALPHA #ifdef RGB_ALPHA
outptr0[RGB_ALPHA] = 0xFF; outptr0[RGB_ALPHA] = 0xFF;
#endif #endif
y = *inptr01; y = GETJSAMPLE(*inptr01);
outptr1[RGB_RED] = range_limit[y + cred]; outptr1[RGB_RED] = range_limit[y + cred];
outptr1[RGB_GREEN] = range_limit[y + cgreen]; outptr1[RGB_GREEN] = range_limit[y + cgreen];
outptr1[RGB_BLUE] = range_limit[y + cblue]; outptr1[RGB_BLUE] = range_limit[y + cblue];
+28 -20
View File
@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1995-1997, Thomas G. Lane. * Copyright (C) 1995-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2015-2016, 2018-2021, D. R. Commander. * Copyright (C) 2015-2016, 2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -41,6 +41,25 @@ typedef struct {
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
} savable_state; } savable_state;
/* This macro is to work around compilers with missing or broken
* structure assignment. You'll need to fix this code if you have
* such a compiler and you change MAX_COMPS_IN_SCAN.
*/
#ifndef NO_STRUCT_ASSIGN
#define ASSIGN_STATE(dest, src) ((dest) = (src))
#else
#if MAX_COMPS_IN_SCAN == 4
#define ASSIGN_STATE(dest, src) \
((dest).EOBRUN = (src).EOBRUN, \
(dest).last_dc_val[0] = (src).last_dc_val[0], \
(dest).last_dc_val[1] = (src).last_dc_val[1], \
(dest).last_dc_val[2] = (src).last_dc_val[2], \
(dest).last_dc_val[3] = (src).last_dc_val[3])
#endif
#endif
typedef struct { typedef struct {
struct jpeg_entropy_decoder pub; /* public fields */ struct jpeg_entropy_decoder pub; /* public fields */
@@ -83,7 +102,7 @@ start_pass_phuff_decoder(j_decompress_ptr cinfo)
boolean is_DC_band, bad; boolean is_DC_band, bad;
int ci, coefi, tbl; int ci, coefi, tbl;
d_derived_tbl **pdtbl; d_derived_tbl **pdtbl;
int *coef_bit_ptr, *prev_coef_bit_ptr; int *coef_bit_ptr;
jpeg_component_info *compptr; jpeg_component_info *compptr;
is_DC_band = (cinfo->Ss == 0); is_DC_band = (cinfo->Ss == 0);
@@ -124,15 +143,8 @@ start_pass_phuff_decoder(j_decompress_ptr cinfo)
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
int cindex = cinfo->cur_comp_info[ci]->component_index; int cindex = cinfo->cur_comp_info[ci]->component_index;
coef_bit_ptr = &cinfo->coef_bits[cindex][0]; coef_bit_ptr = &cinfo->coef_bits[cindex][0];
prev_coef_bit_ptr = &cinfo->coef_bits[cindex + cinfo->num_components][0];
if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */ if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0); WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
for (coefi = MIN(cinfo->Ss, 1); coefi <= MAX(cinfo->Se, 9); coefi++) {
if (cinfo->input_scan_number > 1)
prev_coef_bit_ptr[coefi] = coef_bit_ptr[coefi];
else
prev_coef_bit_ptr[coefi] = 0;
}
for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) { for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi]; int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
if (cinfo->Ah != expected) if (cinfo->Ah != expected)
@@ -311,7 +323,7 @@ decode_mcu_DC_first(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Load up working state */ /* Load up working state */
BITREAD_LOAD_STATE(cinfo, entropy->bitstate); BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
state = entropy->saved; ASSIGN_STATE(state, entropy->saved);
/* Outer loop handles each block in the MCU */ /* Outer loop handles each block in the MCU */
@@ -344,12 +356,11 @@ decode_mcu_DC_first(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Completed MCU, so update state */ /* Completed MCU, so update state */
BITREAD_SAVE_STATE(cinfo, entropy->bitstate); BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
entropy->saved = state; ASSIGN_STATE(entropy->saved, state);
} }
/* Account for restart interval (no-op if not using restarts) */ /* Account for restart interval (no-op if not using restarts) */
if (cinfo->restart_interval) entropy->restarts_to_go--;
entropy->restarts_to_go--;
return TRUE; return TRUE;
} }
@@ -433,8 +444,7 @@ decode_mcu_AC_first(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/* Account for restart interval (no-op if not using restarts) */ /* Account for restart interval (no-op if not using restarts) */
if (cinfo->restart_interval) entropy->restarts_to_go--;
entropy->restarts_to_go--;
return TRUE; return TRUE;
} }
@@ -485,8 +495,7 @@ decode_mcu_DC_refine(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
BITREAD_SAVE_STATE(cinfo, entropy->bitstate); BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
/* Account for restart interval (no-op if not using restarts) */ /* Account for restart interval (no-op if not using restarts) */
if (cinfo->restart_interval) entropy->restarts_to_go--;
entropy->restarts_to_go--;
return TRUE; return TRUE;
} }
@@ -629,8 +638,7 @@ decode_mcu_AC_refine(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/* Account for restart interval (no-op if not using restarts) */ /* Account for restart interval (no-op if not using restarts) */
if (cinfo->restart_interval) entropy->restarts_to_go--;
entropy->restarts_to_go--;
return TRUE; return TRUE;
@@ -668,7 +676,7 @@ jinit_phuff_decoder(j_decompress_ptr cinfo)
/* Create progression status table */ /* Create progression status table */
cinfo->coef_bits = (int (*)[DCTSIZE2]) cinfo->coef_bits = (int (*)[DCTSIZE2])
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
cinfo->num_components * 2 * DCTSIZE2 * cinfo->num_components * DCTSIZE2 *
sizeof(int)); sizeof(int));
coef_bit_ptr = &cinfo->coef_bits[0][0]; coef_bit_ptr = &cinfo->coef_bits[0][0];
for (ci = 0; ci < cinfo->num_components; ci++) for (ci = 0; ci < cinfo->num_components; ci++)
+20 -30
View File
@@ -8,7 +8,6 @@
* Copyright (C) 2010, 2015-2016, D. R. Commander. * Copyright (C) 2010, 2015-2016, D. R. Commander.
* Copyright (C) 2014, MIPS Technologies, Inc., California. * Copyright (C) 2014, MIPS Technologies, Inc., California.
* Copyright (C) 2015, Google, Inc. * Copyright (C) 2015, Google, Inc.
* Copyright (C) 2019-2020, Arm Limited.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -177,7 +176,7 @@ int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
outptr = output_data[outrow]; outptr = output_data[outrow];
outend = outptr + cinfo->output_width; outend = outptr + cinfo->output_width;
while (outptr < outend) { while (outptr < outend) {
invalue = *inptr++; invalue = *inptr++; /* don't need GETJSAMPLE() here */
for (h = h_expand; h > 0; h--) { for (h = h_expand; h > 0; h--) {
*outptr++ = invalue; *outptr++ = invalue;
} }
@@ -213,7 +212,7 @@ h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
outptr = output_data[inrow]; outptr = output_data[inrow];
outend = outptr + cinfo->output_width; outend = outptr + cinfo->output_width;
while (outptr < outend) { while (outptr < outend) {
invalue = *inptr++; invalue = *inptr++; /* don't need GETJSAMPLE() here */
*outptr++ = invalue; *outptr++ = invalue;
*outptr++ = invalue; *outptr++ = invalue;
} }
@@ -242,7 +241,7 @@ h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
outptr = output_data[outrow]; outptr = output_data[outrow];
outend = outptr + cinfo->output_width; outend = outptr + cinfo->output_width;
while (outptr < outend) { while (outptr < outend) {
invalue = *inptr++; invalue = *inptr++; /* don't need GETJSAMPLE() here */
*outptr++ = invalue; *outptr++ = invalue;
*outptr++ = invalue; *outptr++ = invalue;
} }
@@ -283,20 +282,20 @@ h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
inptr = input_data[inrow]; inptr = input_data[inrow];
outptr = output_data[inrow]; outptr = output_data[inrow];
/* Special case for first column */ /* Special case for first column */
invalue = *inptr++; invalue = GETJSAMPLE(*inptr++);
*outptr++ = (JSAMPLE)invalue; *outptr++ = (JSAMPLE)invalue;
*outptr++ = (JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2); *outptr++ = (JSAMPLE)((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) { for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
/* General case: 3/4 * nearer pixel + 1/4 * further pixel */ /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
invalue = (*inptr++) * 3; invalue = GETJSAMPLE(*inptr++) * 3;
*outptr++ = (JSAMPLE)((invalue + inptr[-2] + 1) >> 2); *outptr++ = (JSAMPLE)((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
*outptr++ = (JSAMPLE)((invalue + inptr[0] + 2) >> 2); *outptr++ = (JSAMPLE)((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
} }
/* Special case for last column */ /* Special case for last column */
invalue = *inptr; invalue = GETJSAMPLE(*inptr);
*outptr++ = (JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2); *outptr++ = (JSAMPLE)((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
*outptr++ = (JSAMPLE)invalue; *outptr++ = (JSAMPLE)invalue;
} }
} }
@@ -316,9 +315,9 @@ h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY output_data = *output_data_ptr; JSAMPARRAY output_data = *output_data_ptr;
JSAMPROW inptr0, inptr1, outptr; JSAMPROW inptr0, inptr1, outptr;
#if BITS_IN_JSAMPLE == 8 #if BITS_IN_JSAMPLE == 8
int thiscolsum, bias; int thiscolsum;
#else #else
JLONG thiscolsum, bias; JLONG thiscolsum;
#endif #endif
JDIMENSION colctr; JDIMENSION colctr;
int inrow, outrow, v; int inrow, outrow, v;
@@ -328,18 +327,15 @@ h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
for (v = 0; v < 2; v++) { for (v = 0; v < 2; v++) {
/* inptr0 points to nearest input row, inptr1 points to next nearest */ /* inptr0 points to nearest input row, inptr1 points to next nearest */
inptr0 = input_data[inrow]; inptr0 = input_data[inrow];
if (v == 0) { /* next nearest is row above */ if (v == 0) /* next nearest is row above */
inptr1 = input_data[inrow - 1]; inptr1 = input_data[inrow - 1];
bias = 1; else /* next nearest is row below */
} else { /* next nearest is row below */
inptr1 = input_data[inrow + 1]; inptr1 = input_data[inrow + 1];
bias = 2;
}
outptr = output_data[outrow++]; outptr = output_data[outrow++];
for (colctr = 0; colctr < compptr->downsampled_width; colctr++) { for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
thiscolsum = (*inptr0++) * 3 + (*inptr1++); thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
*outptr++ = (JSAMPLE)((thiscolsum + bias) >> 2); *outptr++ = (JSAMPLE)((thiscolsum + 1) >> 2);
} }
} }
inrow++; inrow++;
@@ -381,8 +377,8 @@ h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
outptr = output_data[outrow++]; outptr = output_data[outrow++];
/* Special case for first column */ /* Special case for first column */
thiscolsum = (*inptr0++) * 3 + (*inptr1++); thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
nextcolsum = (*inptr0++) * 3 + (*inptr1++); nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
*outptr++ = (JSAMPLE)((thiscolsum * 4 + 8) >> 4); *outptr++ = (JSAMPLE)((thiscolsum * 4 + 8) >> 4);
*outptr++ = (JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4); *outptr++ = (JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
lastcolsum = thiscolsum; thiscolsum = nextcolsum; lastcolsum = thiscolsum; thiscolsum = nextcolsum;
@@ -390,7 +386,7 @@ h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) { for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
/* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */ /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
/* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */ /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
nextcolsum = (*inptr0++) * 3 + (*inptr1++); nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
*outptr++ = (JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4); *outptr++ = (JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
*outptr++ = (JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4); *outptr++ = (JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
lastcolsum = thiscolsum; thiscolsum = nextcolsum; lastcolsum = thiscolsum; thiscolsum = nextcolsum;
@@ -477,13 +473,7 @@ jinit_upsampler(j_decompress_ptr cinfo)
} else if (h_in_group == h_out_group && } else if (h_in_group == h_out_group &&
v_in_group * 2 == v_out_group && do_fancy) { v_in_group * 2 == v_out_group && do_fancy) {
/* Non-fancy upsampling is handled by the generic method */ /* Non-fancy upsampling is handled by the generic method */
#if defined(__arm__) || defined(__aarch64__) || \ upsample->methods[ci] = h1v2_fancy_upsample;
defined(_M_ARM) || defined(_M_ARM64)
if (jsimd_can_h1v2_fancy_upsample())
upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
else
#endif
upsample->methods[ci] = h1v2_fancy_upsample;
upsample->pub.need_context_rows = TRUE; upsample->pub.need_context_rows = TRUE;
} else if (h_in_group * 2 == h_out_group && } else if (h_in_group * 2 == h_out_group &&
v_in_group * 2 == v_out_group) { v_in_group * 2 == v_out_group) {
+2 -3
View File
@@ -3,8 +3,8 @@
* *
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1995-1997, Thomas G. Lane. * Copyright (C) 1995-1997, Thomas G. Lane.
* libjpeg-turbo Modifications: * It was modified by The libjpeg-turbo Project to include only code relevant
* Copyright (C) 2020, D. R. Commander. * to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -16,7 +16,6 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jpegcomp.h"
/* Forward declarations */ /* Forward declarations */
-13
View File
@@ -207,10 +207,6 @@ JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code")
#endif #endif
#endif #endif
JMESSAGE(JWRN_BOGUS_ICC, "Corrupt JPEG data: bad ICC marker") JMESSAGE(JWRN_BOGUS_ICC, "Corrupt JPEG data: bad ICC marker")
#if JPEG_LIB_VERSION < 70
JMESSAGE(JERR_BAD_DROP_SAMPLING,
"Component index %d: mismatching sampling ratio %d:%d, %d:%d, %c")
#endif
#ifdef JMAKE_ENUM_LIST #ifdef JMAKE_ENUM_LIST
@@ -256,15 +252,6 @@ JMESSAGE(JERR_BAD_DROP_SAMPLING,
(cinfo)->err->msg_parm.i[2] = (p3), \ (cinfo)->err->msg_parm.i[2] = (p3), \
(cinfo)->err->msg_parm.i[3] = (p4), \ (cinfo)->err->msg_parm.i[3] = (p4), \
(*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo))) (*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo)))
#define ERREXIT6(cinfo, code, p1, p2, p3, p4, p5, p6) \
((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[0] = (p1), \
(cinfo)->err->msg_parm.i[1] = (p2), \
(cinfo)->err->msg_parm.i[2] = (p3), \
(cinfo)->err->msg_parm.i[3] = (p4), \
(cinfo)->err->msg_parm.i[4] = (p5), \
(cinfo)->err->msg_parm.i[5] = (p6), \
(*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo)))
#define ERREXITS(cinfo, code, str) \ #define ERREXITS(cinfo, code, str) \
((cinfo)->err->msg_code = (code), \ ((cinfo)->err->msg_code = (code), \
strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
+3 -3
View File
@@ -1,14 +1,14 @@
/* /*
* jfdctint.c * jfdctint.c
* *
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software.
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2015, 2020, D. R. Commander. * Copyright (C) 2015, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
* This file contains a slower but more accurate integer implementation of the * This file contains a slow-but-accurate integer implementation of the
* forward DCT (Discrete Cosine Transform). * forward DCT (Discrete Cosine Transform).
* *
* A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
+7 -7
View File
@@ -1,15 +1,15 @@
/* /*
* jidctint.c * jidctint.c
* *
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software.
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modification developed 2002-2018 by Guido Vollbeding. * Modification developed 2002-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2015, 2020, D. R. Commander. * Copyright (C) 2015, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
* This file contains a slower but more accurate integer implementation of the * This file contains a slow-but-accurate integer implementation of the
* inverse DCT (Discrete Cosine Transform). In the IJG code, this routine * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
* must also perform dequantization of the input coefficients. * must also perform dequantization of the input coefficients.
* *
@@ -417,7 +417,7 @@ jpeg_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* /*
* Perform dequantization and inverse DCT on one block of coefficients, * Perform dequantization and inverse DCT on one block of coefficients,
* producing a reduced-size 7x7 output block. * producing a 7x7 output block.
* *
* Optimized algorithm with 12 multiplications in the 1-D kernel. * Optimized algorithm with 12 multiplications in the 1-D kernel.
* cK represents sqrt(2) * cos(K*pi/14). * cK represents sqrt(2) * cos(K*pi/14).
@@ -1258,7 +1258,7 @@ jpeg_idct_10x10(j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* /*
* Perform dequantization and inverse DCT on one block of coefficients, * Perform dequantization and inverse DCT on one block of coefficients,
* producing an 11x11 output block. * producing a 11x11 output block.
* *
* Optimized algorithm with 24 multiplications in the 1-D kernel. * Optimized algorithm with 24 multiplications in the 1-D kernel.
* cK represents sqrt(2) * cos(K*pi/22). * cK represents sqrt(2) * cos(K*pi/22).
@@ -2398,7 +2398,7 @@ jpeg_idct_16x16(j_decompress_ptr cinfo, jpeg_component_info *compptr,
tmp0 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]); tmp0 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
tmp0 = LEFT_SHIFT(tmp0, CONST_BITS); tmp0 = LEFT_SHIFT(tmp0, CONST_BITS);
/* Add fudge factor here for final descale. */ /* Add fudge factor here for final descale. */
tmp0 += ONE << (CONST_BITS - PASS1_BITS - 1); tmp0 += 1 << (CONST_BITS - PASS1_BITS - 1);
z1 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]); z1 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]);
tmp1 = MULTIPLY(z1, FIX(1.306562965)); /* c4[16] = c2[8] */ tmp1 = MULTIPLY(z1, FIX(1.306562965)); /* c4[16] = c2[8] */
+1 -1
View File
@@ -1,7 +1,7 @@
/* /*
* jidctred.c * jidctred.c
* *
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software.
* Copyright (C) 1994-1998, Thomas G. Lane. * Copyright (C) 1994-1998, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2015, D. R. Commander. * Copyright (C) 2015, D. R. Commander.
+39 -4
View File
@@ -5,7 +5,7 @@
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 1997-2009 by Guido Vollbeding. * Modified 1997-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009, 2011, 2014-2015, 2018, 2020, D. R. Commander. * Copyright (C) 2009, 2011, 2014-2015, 2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -43,11 +43,25 @@
#if BITS_IN_JSAMPLE == 8 #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.
* You can use a signed char by having GETJSAMPLE mask it with 0xFF.
*/ */
#ifdef HAVE_UNSIGNED_CHAR
typedef unsigned char JSAMPLE; typedef unsigned char JSAMPLE;
#define GETJSAMPLE(value) ((int)(value)) #define GETJSAMPLE(value) ((int)(value))
#else /* not HAVE_UNSIGNED_CHAR */
typedef char JSAMPLE;
#ifdef __CHAR_UNSIGNED__
#define GETJSAMPLE(value) ((int)(value))
#else
#define GETJSAMPLE(value) ((int)(value) & 0xFF)
#endif /* __CHAR_UNSIGNED__ */
#endif /* HAVE_UNSIGNED_CHAR */
#define MAXJSAMPLE 255 #define MAXJSAMPLE 255
#define CENTERJSAMPLE 128 #define CENTERJSAMPLE 128
@@ -83,9 +97,22 @@ typedef short JCOEF;
* managers, this is also the data type passed to fread/fwrite. * managers, this is also the data type passed to fread/fwrite.
*/ */
#ifdef HAVE_UNSIGNED_CHAR
typedef unsigned char JOCTET; typedef unsigned char JOCTET;
#define GETJOCTET(value) (value) #define GETJOCTET(value) (value)
#else /* not HAVE_UNSIGNED_CHAR */
typedef char JOCTET;
#ifdef __CHAR_UNSIGNED__
#define GETJOCTET(value) (value)
#else
#define GETJOCTET(value) ((value) & 0xFF)
#endif /* __CHAR_UNSIGNED__ */
#endif /* HAVE_UNSIGNED_CHAR */
/* These typedefs are used for various table entries and so forth. /* These typedefs are used for various table entries and so forth.
* They must be at least as wide as specified; but making them too big * They must be at least as wide as specified; but making them too big
@@ -96,7 +123,15 @@ typedef unsigned char JOCTET;
/* UINT8 must hold at least the values 0..255. */ /* UINT8 must hold at least the values 0..255. */
#ifdef HAVE_UNSIGNED_CHAR
typedef unsigned char UINT8; typedef unsigned char UINT8;
#else /* not HAVE_UNSIGNED_CHAR */
#ifdef __CHAR_UNSIGNED__
typedef char UINT8;
#else /* not __CHAR_UNSIGNED__ */
typedef short UINT8;
#endif /* __CHAR_UNSIGNED__ */
#endif /* HAVE_UNSIGNED_CHAR */
/* UINT16 must hold at least the values 0..65535. */ /* UINT16 must hold at least the values 0..65535. */
@@ -238,9 +273,9 @@ typedef int boolean;
/* Capability options common to encoder and decoder: */ /* Capability options common to encoder and decoder: */
#define DCT_ISLOW_SUPPORTED /* accurate integer method */ #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
#define DCT_IFAST_SUPPORTED /* less accurate int method [legacy feature] */ #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
#define DCT_FLOAT_SUPPORTED /* floating-point method [legacy feature] */ #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
/* Encoder capability options: */ /* Encoder capability options: */
+1 -2
View File
@@ -1,7 +1,7 @@
/* /*
* jpegcomp.h * jpegcomp.h
* *
* Copyright (C) 2010, 2020, D. R. Commander. * Copyright (C) 2010, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -19,7 +19,6 @@
#define _min_DCT_v_scaled_size min_DCT_v_scaled_size #define _min_DCT_v_scaled_size min_DCT_v_scaled_size
#define _jpeg_width jpeg_width #define _jpeg_width jpeg_width
#define _jpeg_height jpeg_height #define _jpeg_height jpeg_height
#define JERR_ARITH_NOTIMPL JERR_NOT_COMPILED
#else #else
#define _DCT_scaled_size DCT_scaled_size #define _DCT_scaled_size DCT_scaled_size
#define _DCT_h_scaled_size DCT_scaled_size #define _DCT_h_scaled_size DCT_scaled_size
+1 -4
View File
@@ -5,7 +5,7 @@
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 1997-2009 by Guido Vollbeding. * Modified 1997-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2015-2016, 2019, D. R. Commander. * Copyright (C) 2015-2016, D. R. Commander.
* Copyright (C) 2015, Google, Inc. * Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
@@ -158,9 +158,6 @@ struct jpeg_decomp_master {
JDIMENSION first_MCU_col[MAX_COMPONENTS]; JDIMENSION first_MCU_col[MAX_COMPONENTS];
JDIMENSION last_MCU_col[MAX_COMPONENTS]; JDIMENSION last_MCU_col[MAX_COMPONENTS];
boolean jinit_upsampler_no_alloc; boolean jinit_upsampler_no_alloc;
/* Last iMCU row that was successfully decoded */
JDIMENSION last_good_iMCU_row;
}; };
/* Input control module */ /* Input control module */
+4 -4
View File
@@ -5,7 +5,7 @@
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2002-2009 by Guido Vollbeding. * Modified 2002-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009-2011, 2013-2014, 2016-2017, 2020, D. R. Commander. * Copyright (C) 2009-2011, 2013-2014, 2016-2017, D. R. Commander.
* Copyright (C) 2015, Google, Inc. * Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
@@ -244,9 +244,9 @@ typedef enum {
/* DCT/IDCT algorithm options. */ /* DCT/IDCT algorithm options. */
typedef enum { typedef enum {
JDCT_ISLOW, /* accurate integer method */ JDCT_ISLOW, /* slow but accurate integer algorithm */
JDCT_IFAST, /* less accurate integer method [legacy feature] */ JDCT_IFAST, /* faster, less accurate integer method */
JDCT_FLOAT /* floating-point method [legacy feature] */ JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
} J_DCT_METHOD; } J_DCT_METHOD;
#ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */ #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
+15 -12
View File
@@ -479,7 +479,7 @@ color_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (col = width; col > 0; col--) { for (col = width; col > 0; col--) {
pixcode = 0; pixcode = 0;
for (ci = 0; ci < nc; ci++) { for (ci = 0; ci < nc; ci++) {
pixcode += colorindex[ci][*ptrin++]; pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
} }
*ptrout++ = (JSAMPLE)pixcode; *ptrout++ = (JSAMPLE)pixcode;
} }
@@ -506,9 +506,9 @@ color_quantize3(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
ptrin = input_buf[row]; ptrin = input_buf[row];
ptrout = output_buf[row]; ptrout = output_buf[row];
for (col = width; col > 0; col--) { for (col = width; col > 0; col--) {
pixcode = colorindex0[*ptrin++]; pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
pixcode += colorindex1[*ptrin++]; pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
pixcode += colorindex2[*ptrin++]; pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
*ptrout++ = (JSAMPLE)pixcode; *ptrout++ = (JSAMPLE)pixcode;
} }
} }
@@ -552,7 +552,7 @@ quantize_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
* required amount of padding. * required amount of padding.
*/ */
*output_ptr += *output_ptr +=
colorindex_ci[*input_ptr + dither[col_index]]; colorindex_ci[GETJSAMPLE(*input_ptr) + dither[col_index]];
input_ptr += nc; input_ptr += nc;
output_ptr++; output_ptr++;
col_index = (col_index + 1) & ODITHER_MASK; col_index = (col_index + 1) & ODITHER_MASK;
@@ -595,9 +595,12 @@ quantize3_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
col_index = 0; col_index = 0;
for (col = width; col > 0; col--) { for (col = width; col > 0; col--) {
pixcode = colorindex0[(*input_ptr++) + dither0[col_index]]; pixcode =
pixcode += colorindex1[(*input_ptr++) + dither1[col_index]]; GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) + dither0[col_index]]);
pixcode += colorindex2[(*input_ptr++) + dither2[col_index]]; pixcode +=
GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) + dither1[col_index]]);
pixcode +=
GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) + dither2[col_index]]);
*output_ptr++ = (JSAMPLE)pixcode; *output_ptr++ = (JSAMPLE)pixcode;
col_index = (col_index + 1) & ODITHER_MASK; col_index = (col_index + 1) & ODITHER_MASK;
} }
@@ -674,15 +677,15 @@ quantize_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
* The maximum error is +- MAXJSAMPLE; this sets the required size * The maximum error is +- MAXJSAMPLE; this sets the required size
* of the range_limit array. * of the range_limit array.
*/ */
cur += *input_ptr; cur += GETJSAMPLE(*input_ptr);
cur = range_limit[cur]; cur = GETJSAMPLE(range_limit[cur]);
/* Select output value, accumulate into output code for this pixel */ /* Select output value, accumulate into output code for this pixel */
pixcode = colorindex_ci[cur]; pixcode = GETJSAMPLE(colorindex_ci[cur]);
*output_ptr += (JSAMPLE)pixcode; *output_ptr += (JSAMPLE)pixcode;
/* Compute actual representation error at this pixel */ /* Compute actual representation error at this pixel */
/* Note: we can do this even though we don't have the final */ /* Note: we can do this even though we don't have the final */
/* pixel code, because the colormap is orthogonal. */ /* pixel code, because the colormap is orthogonal. */
cur -= colormap_ci[pixcode]; cur -= GETJSAMPLE(colormap_ci[pixcode]);
/* Compute error fractions to be propagated to adjacent pixels. /* Compute error fractions to be propagated to adjacent pixels.
* Add these into the running sums, and simultaneously shift the * Add these into the running sums, and simultaneously shift the
* next-line error sums left by 1 column. * next-line error sums left by 1 column.
+26 -26
View File
@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2009, 2014-2015, 2020, D. R. Commander. * Copyright (C) 2009, 2014-2015, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -215,9 +215,9 @@ prescan_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
ptr = input_buf[row]; ptr = input_buf[row];
for (col = width; col > 0; col--) { for (col = width; col > 0; col--) {
/* get pixel value and index into the histogram */ /* get pixel value and index into the histogram */
histp = &histogram[ptr[0] >> C0_SHIFT] histp = &histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
[ptr[1] >> C1_SHIFT] [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
[ptr[2] >> C2_SHIFT]; [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
/* increment, check for overflow and undo increment if so. */ /* increment, check for overflow and undo increment if so. */
if (++(*histp) <= 0) if (++(*histp) <= 0)
(*histp)--; (*histp)--;
@@ -665,7 +665,7 @@ find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
for (i = 0; i < numcolors; i++) { for (i = 0; i < numcolors; i++) {
/* We compute the squared-c0-distance term, then add in the other two. */ /* We compute the squared-c0-distance term, then add in the other two. */
x = cinfo->colormap[0][i]; x = GETJSAMPLE(cinfo->colormap[0][i]);
if (x < minc0) { if (x < minc0) {
tdist = (x - minc0) * C0_SCALE; tdist = (x - minc0) * C0_SCALE;
min_dist = tdist * tdist; min_dist = tdist * tdist;
@@ -688,7 +688,7 @@ find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
} }
} }
x = cinfo->colormap[1][i]; x = GETJSAMPLE(cinfo->colormap[1][i]);
if (x < minc1) { if (x < minc1) {
tdist = (x - minc1) * C1_SCALE; tdist = (x - minc1) * C1_SCALE;
min_dist += tdist * tdist; min_dist += tdist * tdist;
@@ -710,7 +710,7 @@ find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
} }
} }
x = cinfo->colormap[2][i]; x = GETJSAMPLE(cinfo->colormap[2][i]);
if (x < minc2) { if (x < minc2) {
tdist = (x - minc2) * C2_SCALE; tdist = (x - minc2) * C2_SCALE;
min_dist += tdist * tdist; min_dist += tdist * tdist;
@@ -788,13 +788,13 @@ find_best_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
#define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE) #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
for (i = 0; i < numcolors; i++) { for (i = 0; i < numcolors; i++) {
icolor = colorlist[i]; icolor = GETJSAMPLE(colorlist[i]);
/* Compute (square of) distance from minc0/c1/c2 to this color */ /* Compute (square of) distance from minc0/c1/c2 to this color */
inc0 = (minc0 - cinfo->colormap[0][icolor]) * C0_SCALE; inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
dist0 = inc0 * inc0; dist0 = inc0 * inc0;
inc1 = (minc1 - cinfo->colormap[1][icolor]) * C1_SCALE; inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
dist0 += inc1 * inc1; dist0 += inc1 * inc1;
inc2 = (minc2 - cinfo->colormap[2][icolor]) * C2_SCALE; inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
dist0 += inc2 * inc2; dist0 += inc2 * inc2;
/* Form the initial difference increments */ /* Form the initial difference increments */
inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0; inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
@@ -879,7 +879,7 @@ fill_inverse_cmap(j_decompress_ptr cinfo, int c0, int c1, int c2)
for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) { for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
cachep = &histogram[c0 + ic0][c1 + ic1][c2]; cachep = &histogram[c0 + ic0][c1 + ic1][c2];
for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) { for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
*cachep++ = (histcell)((*cptr++) + 1); *cachep++ = (histcell)(GETJSAMPLE(*cptr++) + 1);
} }
} }
} }
@@ -909,9 +909,9 @@ pass2_no_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
outptr = output_buf[row]; outptr = output_buf[row];
for (col = width; col > 0; col--) { for (col = width; col > 0; col--) {
/* get pixel value and index into the cache */ /* get pixel value and index into the cache */
c0 = (*inptr++) >> C0_SHIFT; c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
c1 = (*inptr++) >> C1_SHIFT; c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
c2 = (*inptr++) >> C2_SHIFT; c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
cachep = &histogram[c0][c1][c2]; cachep = &histogram[c0][c1][c2];
/* If we have not seen this color before, find nearest colormap entry */ /* If we have not seen this color before, find nearest colormap entry */
/* and update the cache */ /* and update the cache */
@@ -996,12 +996,12 @@ pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
* The maximum error is +- MAXJSAMPLE (or less with error limiting); * The maximum error is +- MAXJSAMPLE (or less with error limiting);
* this sets the required size of the range_limit array. * this sets the required size of the range_limit array.
*/ */
cur0 += inptr[0]; cur0 += GETJSAMPLE(inptr[0]);
cur1 += inptr[1]; cur1 += GETJSAMPLE(inptr[1]);
cur2 += inptr[2]; cur2 += GETJSAMPLE(inptr[2]);
cur0 = range_limit[cur0]; cur0 = GETJSAMPLE(range_limit[cur0]);
cur1 = range_limit[cur1]; cur1 = GETJSAMPLE(range_limit[cur1]);
cur2 = range_limit[cur2]; cur2 = GETJSAMPLE(range_limit[cur2]);
/* Index into the cache with adjusted pixel value */ /* Index into the cache with adjusted pixel value */
cachep = cachep =
&histogram[cur0 >> C0_SHIFT][cur1 >> C1_SHIFT][cur2 >> C2_SHIFT]; &histogram[cur0 >> C0_SHIFT][cur1 >> C1_SHIFT][cur2 >> C2_SHIFT];
@@ -1015,9 +1015,9 @@ pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
register int pixcode = *cachep - 1; register int pixcode = *cachep - 1;
*outptr = (JSAMPLE)pixcode; *outptr = (JSAMPLE)pixcode;
/* Compute representation error for this pixel */ /* Compute representation error for this pixel */
cur0 -= colormap0[pixcode]; cur0 -= GETJSAMPLE(colormap0[pixcode]);
cur1 -= colormap1[pixcode]; cur1 -= GETJSAMPLE(colormap1[pixcode]);
cur2 -= colormap2[pixcode]; cur2 -= GETJSAMPLE(colormap2[pixcode]);
} }
/* Compute error fractions to be propagated to adjacent pixels. /* Compute error fractions to be propagated to adjacent pixels.
* Add these into the running sums, and simultaneously shift the * Add these into the running sums, and simultaneously shift the
@@ -1145,7 +1145,7 @@ start_pass_2_quant(j_decompress_ptr cinfo, boolean is_pre_scan)
int i; int i;
/* Only F-S dithering or no dithering is supported. */ /* Only F-S dithering or no dithering is supported. */
/* If user asks for ordered dither, give them F-S. */ /* If user asks for ordered dither, give him F-S. */
if (cinfo->dither_mode != JDITHER_NONE) if (cinfo->dither_mode != JDITHER_NONE)
cinfo->dither_mode = JDITHER_FS; cinfo->dither_mode = JDITHER_FS;
@@ -1263,7 +1263,7 @@ jinit_2pass_quantizer(j_decompress_ptr cinfo)
cquantize->sv_colormap = NULL; cquantize->sv_colormap = NULL;
/* Only F-S dithering or no dithering is supported. */ /* Only F-S dithering or no dithering is supported. */
/* If user asks for ordered dither, give them F-S. */ /* If user asks for ordered dither, give him F-S. */
if (cinfo->dither_mode != JDITHER_NONE) if (cinfo->dither_mode != JDITHER_NONE)
cinfo->dither_mode = JDITHER_FS; cinfo->dither_mode = JDITHER_FS;
-6
View File
@@ -4,7 +4,6 @@
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2011, 2014, D. R. Commander. * Copyright (C) 2011, 2014, D. R. Commander.
* Copyright (C) 2015-2016, 2018, Matthieu Darbois. * Copyright (C) 2015-2016, 2018, Matthieu Darbois.
* Copyright (C) 2020, Arm Limited.
* *
* Based on the x86 SIMD extension for IJG JPEG library, * Based on the x86 SIMD extension for IJG JPEG library,
* Copyright (C) 1999-2006, MIYASAKA Masaru. * Copyright (C) 1999-2006, MIYASAKA Masaru.
@@ -76,7 +75,6 @@ EXTERN(void) jsimd_int_upsample(j_decompress_ptr cinfo,
EXTERN(int) jsimd_can_h2v2_fancy_upsample(void); EXTERN(int) jsimd_can_h2v2_fancy_upsample(void);
EXTERN(int) jsimd_can_h2v1_fancy_upsample(void); EXTERN(int) jsimd_can_h2v1_fancy_upsample(void);
EXTERN(int) jsimd_can_h1v2_fancy_upsample(void);
EXTERN(void) jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo, EXTERN(void) jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo,
jpeg_component_info *compptr, jpeg_component_info *compptr,
@@ -86,10 +84,6 @@ EXTERN(void) jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo,
jpeg_component_info *compptr, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY input_data,
JSAMPARRAY *output_data_ptr); JSAMPARRAY *output_data_ptr);
EXTERN(void) jsimd_h1v2_fancy_upsample(j_decompress_ptr cinfo,
jpeg_component_info *compptr,
JSAMPARRAY input_data,
JSAMPARRAY *output_data_ptr);
EXTERN(int) jsimd_can_h2v2_merged_upsample(void); EXTERN(int) jsimd_can_h2v2_merged_upsample(void);
EXTERN(int) jsimd_can_h2v1_merged_upsample(void); EXTERN(int) jsimd_can_h2v1_merged_upsample(void);
-13
View File
@@ -4,7 +4,6 @@
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2009-2011, 2014, D. R. Commander. * Copyright (C) 2009-2011, 2014, D. R. Commander.
* Copyright (C) 2015-2016, 2018, Matthieu Darbois. * Copyright (C) 2015-2016, 2018, Matthieu Darbois.
* Copyright (C) 2020, Arm Limited.
* *
* Based on the x86 SIMD extension for IJG JPEG library, * Based on the x86 SIMD extension for IJG JPEG library,
* Copyright (C) 1999-2006, MIYASAKA Masaru. * Copyright (C) 1999-2006, MIYASAKA Masaru.
@@ -170,12 +169,6 @@ jsimd_can_h2v1_fancy_upsample(void)
return 0; return 0;
} }
GLOBAL(int)
jsimd_can_h1v2_fancy_upsample(void)
{
return 0;
}
GLOBAL(void) GLOBAL(void)
jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr, jsimd_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)
@@ -188,12 +181,6 @@ jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
{ {
} }
GLOBAL(void)
jsimd_h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{
}
GLOBAL(int) GLOBAL(int)
jsimd_can_h2v2_merged_upsample(void) jsimd_can_h2v2_merged_upsample(void)
{ {
+10 -12
View File
@@ -2,9 +2,9 @@
* jversion.h * jversion.h
* *
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding. * Copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2010, 2012-2021, D. R. Commander. * Copyright (C) 2010, 2012-2019, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -30,25 +30,23 @@
* NOTE: It is our convention to place the authors in the following order: * NOTE: It is our convention to place the authors in the following order:
* - libjpeg-turbo authors (2009-) in descending order of the date of their * - libjpeg-turbo authors (2009-) in descending order of the date of their
* most recent contribution to the project, then in ascending order of the * most recent contribution to the project, then in ascending order of the
* date of their first contribution to the project, then in alphabetical * date of their first contribution to the project
* order
* - Upstream authors in descending order of the date of the first inclusion of * - Upstream authors in descending order of the date of the first inclusion of
* their code * their code
*/ */
#define JCOPYRIGHT \ #define JCOPYRIGHT \
"Copyright (C) 2009-2021 D. R. Commander\n" \ "Copyright (C) 2009-2019 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) 2011-2016 Siarhei Siamashka\n" \
"Copyright (C) 2015-2016, 2018 Matthieu Darbois\n" \
"Copyright (C) 2015 Intel Corporation\n" \ "Copyright (C) 2015 Intel Corporation\n" \
"Copyright (C) 2013-2014 Linaro Limited\n" \ "Copyright (C) 2015 Google, Inc.\n" \
"Copyright (C) 2013-2014 MIPS Technologies, Inc.\n" \ "Copyright (C) 2013-2014 MIPS Technologies, Inc.\n" \
"Copyright (C) 2009, 2012 Pierre Ossman for Cendio AB\n" \ "Copyright (C) 2013 Linaro Limited\n" \
"Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)\n" \ "Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)\n" \
"Copyright (C) 2009 Pierre Ossman for Cendio AB\n" \
"Copyright (C) 1999-2006 MIYASAKA Masaru\n" \ "Copyright (C) 1999-2006 MIYASAKA Masaru\n" \
"Copyright (C) 1991-2020 Thomas G. Lane, Guido Vollbeding" "Copyright (C) 1991-2016 Thomas G. Lane, Guido Vollbeding"
#define JCOPYRIGHT_SHORT \ #define JCOPYRIGHT_SHORT \
"Copyright (C) 1991-2021 The libjpeg-turbo Project and many others" "Copyright (C) 1991-2019 The libjpeg-turbo Project and many others"
+2 -2
View File
@@ -19,7 +19,7 @@ endif()
# Define the library target: # Define the library target:
# ---------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------
add_library(${JPEG_LIBRARY} STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${lib_srcs} ${lib_hdrs}) add_library(${JPEG_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs})
if(CV_GCC OR CV_CLANG) if(CV_GCC OR CV_CLANG)
set_source_files_properties(jcdctmgr.c PROPERTIES COMPILE_FLAGS "-O1") set_source_files_properties(jcdctmgr.c PROPERTIES COMPILE_FLAGS "-O1")
@@ -42,7 +42,7 @@ if(ENABLE_SOLUTION_FOLDERS)
endif() endif()
if(NOT BUILD_SHARED_LIBS) if(NOT BUILD_SHARED_LIBS)
ocv_install_target(${JPEG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev OPTIONAL) ocv_install_target(${JPEG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif() endif()
ocv_install_3rdparty_licenses(libjpeg README) ocv_install_3rdparty_licenses(libjpeg README)
+13 -6
View File
@@ -1,7 +1,7 @@
The Independent JPEG Group's JPEG software The Independent JPEG Group's JPEG software
========================================== ==========================================
README for release 9d of 12-Jan-2020 README for release 9c of 14-Jan-2018
==================================== ====================================
This distribution contains the ninth public release of the Independent JPEG This distribution contains the ninth public release of the Independent JPEG
@@ -10,8 +10,8 @@ to use it for any purpose, subject to the conditions under LEGAL ISSUES, below.
This software is the work of Tom Lane, Guido Vollbeding, Philip Gladstone, This software is the work of Tom Lane, Guido Vollbeding, Philip Gladstone,
Bill Allombert, Jim Boucher, Lee Crocker, Bob Friesenhahn, Ben Jackson, Bill Allombert, Jim Boucher, Lee Crocker, Bob Friesenhahn, Ben Jackson,
John Korejwa, Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi, Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi, Ge' Weijers,
Ge' Weijers, and other members of the Independent JPEG Group. and other members of the Independent JPEG Group.
IJG is not affiliated with the ISO/IEC JTC1/SC29/WG1 standards committee IJG is not affiliated with the ISO/IEC JTC1/SC29/WG1 standards committee
(previously known as JPEG, together with ITU-T SG16). (previously known as JPEG, together with ITU-T SG16).
@@ -115,7 +115,7 @@ with respect to this software, its quality, accuracy, merchantability, or
fitness for a particular purpose. This software is provided "AS IS", and you, fitness for a particular purpose. This software is provided "AS IS", and you,
its user, assume the entire risk as to its quality and accuracy. its user, assume the entire risk as to its quality and accuracy.
This software is copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding. This software is copyright (C) 1991-2018, Thomas G. Lane, Guido Vollbeding.
All Rights Reserved except as specified below. All Rights Reserved except as specified below.
Permission is hereby granted to use, copy, modify, and distribute this Permission is hereby granted to use, copy, modify, and distribute this
@@ -152,6 +152,13 @@ The same holds for its supporting scripts (config.guess, config.sub,
ltmain.sh). Another support script, install-sh, is copyright by X Consortium ltmain.sh). Another support script, install-sh, is copyright by X Consortium
but is also freely distributable. but is also freely distributable.
The IJG distribution formerly included code to read and write GIF files.
To avoid entanglement with the Unisys LZW patent (now expired), GIF reading
support has been removed altogether, and the GIF writer has been simplified
to produce "uncompressed GIFs". This technique does not use the LZW
algorithm; the resulting GIF files are larger than usual, but are readable
by all standard GIF decoders.
REFERENCES REFERENCES
========== ==========
@@ -239,8 +246,8 @@ ARCHIVE LOCATIONS
The "official" archive site for this software is www.ijg.org. The "official" archive site for this software is www.ijg.org.
The most recent released version can always be found there in The most recent released version can always be found there in
directory "files". This particular version will be archived as directory "files". This particular version will be archived as
http://www.ijg.org/files/jpegsrc.v9d.tar.gz, and in Windows-compatible http://www.ijg.org/files/jpegsrc.v9c.tar.gz, and in Windows-compatible
"zip" archive format as http://www.ijg.org/files/jpegsr9d.zip. "zip" archive format as http://www.ijg.org/files/jpegsr9c.zip.
The JPEG FAQ (Frequently Asked Questions) article is a source of some The JPEG FAQ (Frequently Asked Questions) article is a source of some
general information about JPEG. general information about JPEG.
-49
View File
@@ -1,55 +1,6 @@
CHANGE LOG for Independent JPEG Group's JPEG software CHANGE LOG for Independent JPEG Group's JPEG software
Version 9d 12-Jan-2020
-----------------------
Optimize the optimal Huffman code table generation to produce
slightly smaller files. Thank to John Korejwa for suggestion.
Note: Requires rebuild of testimgp.jpg.
Decoding Huffman: Use default tables if tables are not defined.
Thank to Simone Azzalin for report (Motion JPEG),
and to Martin Strunz for hint.
Add sanity check in optimal Huffman code table generation.
Thank to Adam Farley for suggestion.
rdtarga.c: use read_byte(), with EOF check, instead of getc()
in read_*_pixel().
Thank to Chijin Zhou for cjpeg potential vulnerability report.
jmemnobs.c: respect the max_memory_to_use setting in
jpeg_mem_available() computation. Thank to Sheng Shu and
Dongdong She for djpeg potential vulnerability report.
jdarith.c, jdhuff.c: avoid left shift of negative value
compiler warning in decode_mcu_AC_refine().
Thank to Indu Bhagat for suggestion.
Add x64 (64-bit) platform support, avoid compiler warnings.
Thank to Jonathan Potter, Feiyun Wang, and Sheng Shu for suggestion.
Adjust libjpeg version specification for pkg-config file.
Thank to Chen Chen for suggestion.
Restore GIF read and write support from libjpeg version 6a.
Thank to Wolfgang Werner (W.W.) Heinz for suggestion.
Improve consistency in raw (downsampled) image data processing mode.
Thank to Zhongyuan Zhou for hint.
Avoid out of bounds array read (AC derived table pointers)
in start pass in jdhuff.c. Thank to Peng Li for report.
Improve code sanity (jdhuff.c).
Thank to Reza Mirzazade farkhani for reports.
Add jpegtran -drop option; add options to the crop extension and wipe
to fill the extra area with content from the source image region,
instead of gray out.
Version 9c 14-Jan-2018 Version 9c 14-Jan-2018
----------------------- -----------------------
+8 -9
View File
@@ -1,7 +1,7 @@
/* /*
* jcarith.c * jcarith.c
* *
* Developed 1997-2019 by Guido Vollbeding. * Developed 1997-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -181,11 +181,11 @@ finish_pass (j_compress_ptr cinfo)
if (e->zc) /* output final pending zero bytes */ if (e->zc) /* output final pending zero bytes */
do emit_byte(0x00, cinfo); do emit_byte(0x00, cinfo);
while (--e->zc); while (--e->zc);
emit_byte((int) ((e->c >> 19) & 0xFF), cinfo); emit_byte((e->c >> 19) & 0xFF, cinfo);
if (((e->c >> 19) & 0xFF) == 0xFF) if (((e->c >> 19) & 0xFF) == 0xFF)
emit_byte(0x00, cinfo); emit_byte(0x00, cinfo);
if (e->c & 0x7F800L) { if (e->c & 0x7F800L) {
emit_byte((int) ((e->c >> 11) & 0xFF), cinfo); emit_byte((e->c >> 11) & 0xFF, cinfo);
if (((e->c >> 11) & 0xFF) == 0xFF) if (((e->c >> 11) & 0xFF) == 0xFF)
emit_byte(0x00, cinfo); emit_byte(0x00, cinfo);
} }
@@ -280,8 +280,7 @@ arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
/* Note: The 3 spacer bits in the C register guarantee /* Note: The 3 spacer bits in the C register guarantee
* that the new buffer byte can't be 0xFF here * that the new buffer byte can't be 0xFF here
* (see page 160 in the P&M JPEG book). */ * (see page 160 in the P&M JPEG book). */
/* New output byte, might overflow later */ e->buffer = temp & 0xFF; /* new output byte, might overflow later */
e->buffer = (int) (temp & 0xFF);
} else if (temp == 0xFF) { } else if (temp == 0xFF) {
++e->sc; /* stack 0xFF byte (which might overflow later) */ ++e->sc; /* stack 0xFF byte (which might overflow later) */
} else { } else {
@@ -303,8 +302,7 @@ arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
emit_byte(0x00, cinfo); emit_byte(0x00, cinfo);
} while (--e->sc); } while (--e->sc);
} }
/* New output byte (can still overflow) */ e->buffer = temp & 0xFF; /* new output byte (can still overflow) */
e->buffer = (int) (temp & 0xFF);
} }
e->c &= 0x7FFFFL; e->c &= 0x7FFFFL;
e->ct += 8; e->ct += 8;
@@ -928,8 +926,9 @@ jinit_arith_encoder (j_compress_ptr cinfo)
arith_entropy_ptr entropy; arith_entropy_ptr entropy;
int i; int i;
entropy = (arith_entropy_ptr) (*cinfo->mem->alloc_small) entropy = (arith_entropy_ptr)
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(arith_entropy_encoder)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(arith_entropy_encoder));
cinfo->entropy = &entropy->pub; cinfo->entropy = &entropy->pub;
entropy->pub.start_pass = start_pass; entropy->pub.start_pass = start_pass;
entropy->pub.finish_pass = finish_pass; entropy->pub.finish_pass = finish_pass;
+50 -47
View File
@@ -2,7 +2,7 @@
* jccolor.c * jccolor.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2011-2019 by Guido Vollbeding. * Modified 2011-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -105,14 +105,14 @@ rgb_ycc_start (j_compress_ptr cinfo)
/* Allocate and fill in the conversion tables. */ /* Allocate and fill in the conversion tables. */
cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *) cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
TABLE_SIZE * SIZEOF(INT32)); (TABLE_SIZE * SIZEOF(INT32)));
for (i = 0; i <= MAXJSAMPLE; i++) { for (i = 0; i <= MAXJSAMPLE; i++) {
rgb_ycc_tab[i+R_Y_OFF] = FIX(0.299) * i; rgb_ycc_tab[i+R_Y_OFF] = FIX(0.299) * i;
rgb_ycc_tab[i+G_Y_OFF] = FIX(0.587) * i; rgb_ycc_tab[i+G_Y_OFF] = FIX(0.587) * i;
rgb_ycc_tab[i+B_Y_OFF] = FIX(0.114) * i + ONE_HALF; rgb_ycc_tab[i+B_Y_OFF] = FIX(0.114) * i + ONE_HALF;
rgb_ycc_tab[i+R_CB_OFF] = (- FIX(0.168735892)) * i; rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.168735892)) * i;
rgb_ycc_tab[i+G_CB_OFF] = (- FIX(0.331264108)) * i; rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.331264108)) * i;
/* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr. /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
* This ensures that the maximum output will round to MAXJSAMPLE * This ensures that the maximum output will round to MAXJSAMPLE
* not MAXJSAMPLE+1, and thus that we don't have to range-limit. * not MAXJSAMPLE+1, and thus that we don't have to range-limit.
@@ -121,8 +121,8 @@ rgb_ycc_start (j_compress_ptr cinfo)
/* B=>Cb and R=>Cr tables are the same /* B=>Cb and R=>Cr tables are the same
rgb_ycc_tab[i+R_CR_OFF] = FIX(0.5) * i + CBCR_OFFSET + ONE_HALF-1; rgb_ycc_tab[i+R_CR_OFF] = FIX(0.5) * i + CBCR_OFFSET + ONE_HALF-1;
*/ */
rgb_ycc_tab[i+G_CR_OFF] = (- FIX(0.418687589)) * i; rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.418687589)) * i;
rgb_ycc_tab[i+B_CR_OFF] = (- FIX(0.081312411)) * i; rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.081312411)) * i;
} }
} }
@@ -131,12 +131,12 @@ rgb_ycc_start (j_compress_ptr cinfo)
* Convert some rows of samples to the JPEG colorspace. * Convert some rows of samples to the JPEG colorspace.
* *
* Note that we change from the application's interleaved-pixel format * Note that we change from the application's interleaved-pixel format
* to our internal noninterleaved, one-plane-per-component format. The * to our internal noninterleaved, one-plane-per-component format.
* input buffer is therefore three times as wide as the output buffer. * The input buffer is therefore three times as wide as the output buffer.
* *
* A starting row offset is provided only for the output buffer. The * A starting row offset is provided only for the output buffer. The caller
* caller can easily adjust the passed input_buf value to accommodate * can easily adjust the passed input_buf value to accommodate any row
* any row offset required on that side. * offset required on that side.
*/ */
METHODDEF(void) METHODDEF(void)
@@ -145,8 +145,8 @@ rgb_ycc_convert (j_compress_ptr cinfo,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int r, g, b;
register INT32 * ctab = cconvert->rgb_ycc_tab; register INT32 * ctab = cconvert->rgb_ycc_tab;
register int r, g, b;
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr0, outptr1, outptr2; register JSAMPROW outptr0, outptr1, outptr2;
register JDIMENSION col; register JDIMENSION col;
@@ -162,7 +162,6 @@ rgb_ycc_convert (j_compress_ptr cinfo,
r = GETJSAMPLE(inptr[RGB_RED]); r = GETJSAMPLE(inptr[RGB_RED]);
g = GETJSAMPLE(inptr[RGB_GREEN]); g = GETJSAMPLE(inptr[RGB_GREEN]);
b = GETJSAMPLE(inptr[RGB_BLUE]); b = GETJSAMPLE(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. * must be too; we do not need an explicit range-limiting operation.
* Hence the value being shifted is never negative, and we don't * Hence the value being shifted is never negative, and we don't
@@ -180,6 +179,7 @@ rgb_ycc_convert (j_compress_ptr cinfo,
outptr2[col] = (JSAMPLE) outptr2[col] = (JSAMPLE)
((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
>> SCALEBITS); >> SCALEBITS);
inptr += RGB_PIXELSIZE;
} }
} }
} }
@@ -201,8 +201,8 @@ rgb_gray_convert (j_compress_ptr cinfo,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int r, g, b;
register INT32 * ctab = cconvert->rgb_ycc_tab; register INT32 * ctab = cconvert->rgb_ycc_tab;
register int r, g, b;
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr; register JSAMPROW outptr;
register JDIMENSION col; register JDIMENSION col;
@@ -215,11 +215,11 @@ rgb_gray_convert (j_compress_ptr cinfo,
r = GETJSAMPLE(inptr[RGB_RED]); r = GETJSAMPLE(inptr[RGB_RED]);
g = GETJSAMPLE(inptr[RGB_GREEN]); g = GETJSAMPLE(inptr[RGB_GREEN]);
b = GETJSAMPLE(inptr[RGB_BLUE]); b = GETJSAMPLE(inptr[RGB_BLUE]);
inptr += RGB_PIXELSIZE;
/* Y */ /* Y */
outptr[col] = (JSAMPLE) outptr[col] = (JSAMPLE)
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
>> SCALEBITS); >> SCALEBITS);
inptr += RGB_PIXELSIZE;
} }
} }
} }
@@ -228,8 +228,8 @@ rgb_gray_convert (j_compress_ptr cinfo,
/* /*
* Convert some rows of samples to the JPEG colorspace. * Convert some rows of samples to the JPEG colorspace.
* This version handles Adobe-style CMYK->YCCK conversion, * This version handles Adobe-style CMYK->YCCK conversion,
* where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same
* same conversion as above, while passing K (black) unchanged. * conversion as above, while passing K (black) unchanged.
* We assume rgb_ycc_start has been called. * We assume rgb_ycc_start has been called.
*/ */
@@ -239,8 +239,8 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int r, g, b;
register INT32 * ctab = cconvert->rgb_ycc_tab; register INT32 * ctab = cconvert->rgb_ycc_tab;
register int r, g, b;
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr0, outptr1, outptr2, outptr3; register JSAMPROW outptr0, outptr1, outptr2, outptr3;
register JDIMENSION col; register JDIMENSION col;
@@ -259,7 +259,6 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
b = MAXJSAMPLE - GETJSAMPLE(inptr[2]); b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
/* K passes through as-is */ /* K passes through as-is */
outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */ outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
inptr += 4;
/* If the inputs are 0..MAXJSAMPLE, the outputs of these equations /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
* must be too; we do not need an explicit range-limiting operation. * must be too; we do not need an explicit range-limiting operation.
* Hence the value being shifted is never negative, and we don't * Hence the value being shifted is never negative, and we don't
@@ -277,6 +276,7 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
outptr2[col] = (JSAMPLE) outptr2[col] = (JSAMPLE)
((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
>> SCALEBITS); >> SCALEBITS);
inptr += 4;
} }
} }
} }
@@ -312,13 +312,13 @@ rgb_rgb1_convert (j_compress_ptr cinfo,
r = GETJSAMPLE(inptr[RGB_RED]); r = GETJSAMPLE(inptr[RGB_RED]);
g = GETJSAMPLE(inptr[RGB_GREEN]); g = GETJSAMPLE(inptr[RGB_GREEN]);
b = GETJSAMPLE(inptr[RGB_BLUE]); b = GETJSAMPLE(inptr[RGB_BLUE]);
inptr += RGB_PIXELSIZE;
/* Assume that MAXJSAMPLE+1 is a power of 2, so that the MOD /* Assume that MAXJSAMPLE+1 is a power of 2, so that the MOD
* (modulo) operator is equivalent to the bitmask operator AND. * (modulo) operator is equivalent to the bitmask operator AND.
*/ */
outptr0[col] = (JSAMPLE) ((r - g + CENTERJSAMPLE) & MAXJSAMPLE); outptr0[col] = (JSAMPLE) ((r - g + CENTERJSAMPLE) & MAXJSAMPLE);
outptr1[col] = (JSAMPLE) g; outptr1[col] = (JSAMPLE) g;
outptr2[col] = (JSAMPLE) ((b - g + CENTERJSAMPLE) & MAXJSAMPLE); outptr2[col] = (JSAMPLE) ((b - g + CENTERJSAMPLE) & MAXJSAMPLE);
inptr += RGB_PIXELSIZE;
} }
} }
} }
@@ -335,17 +335,17 @@ grayscale_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
int instride = cinfo->input_components;
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr; register JSAMPROW outptr;
register JDIMENSION count; register JDIMENSION col;
register int instride = cinfo->input_components;
JDIMENSION num_cols = cinfo->image_width; JDIMENSION num_cols = cinfo->image_width;
while (--num_rows >= 0) { while (--num_rows >= 0) {
inptr = *input_buf++; inptr = *input_buf++;
outptr = output_buf[0][output_row++]; outptr = output_buf[0][output_row++];
for (count = num_cols; count > 0; count--) { for (col = 0; col < num_cols; col++) {
*outptr++ = *inptr; /* don't need GETJSAMPLE() here */ outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
inptr += instride; inptr += instride;
} }
} }
@@ -396,21 +396,21 @@ null_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
int ci;
register int nc = cinfo->num_components;
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr; register JSAMPROW outptr;
register JDIMENSION count; register JDIMENSION col;
register int num_comps = cinfo->num_components;
JDIMENSION num_cols = cinfo->image_width; JDIMENSION num_cols = cinfo->image_width;
int ci;
while (--num_rows >= 0) { while (--num_rows >= 0) {
/* It seems fastest to make a separate pass for each component. */ /* It seems fastest to make a separate pass for each component. */
for (ci = 0; ci < num_comps; ci++) { for (ci = 0; ci < nc; ci++) {
inptr = input_buf[0] + ci; inptr = input_buf[0] + ci;
outptr = output_buf[ci][output_row]; outptr = output_buf[ci][output_row];
for (count = num_cols; count > 0; count--) { for (col = 0; col < num_cols; col++) {
*outptr++ = *inptr; /* don't need GETJSAMPLE() here */ *outptr++ = *inptr; /* don't need GETJSAMPLE() here */
inptr += num_comps; inptr += nc;
} }
} }
input_buf++; input_buf++;
@@ -439,8 +439,9 @@ jinit_color_converter (j_compress_ptr cinfo)
{ {
my_cconvert_ptr cconvert; my_cconvert_ptr cconvert;
cconvert = (my_cconvert_ptr) (*cinfo->mem->alloc_small) cconvert = (my_cconvert_ptr)
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_color_converter)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_color_converter));
cinfo->cconvert = &cconvert->pub; cinfo->cconvert = &cconvert->pub;
/* set start_pass to null method until we find out differently */ /* set start_pass to null method until we find out differently */
cconvert->pub.start_pass = null_method; cconvert->pub.start_pass = null_method;
@@ -454,11 +455,9 @@ jinit_color_converter (j_compress_ptr cinfo)
case JCS_RGB: case JCS_RGB:
case JCS_BG_RGB: case JCS_BG_RGB:
#if RGB_PIXELSIZE != 3
if (cinfo->input_components != RGB_PIXELSIZE) if (cinfo->input_components != RGB_PIXELSIZE)
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
break; break;
#endif /* else share code with YCbCr */
case JCS_YCbCr: case JCS_YCbCr:
case JCS_BG_YCC: case JCS_BG_YCC:
@@ -475,6 +474,7 @@ jinit_color_converter (j_compress_ptr cinfo)
default: /* JCS_UNKNOWN can be anything */ default: /* JCS_UNKNOWN can be anything */
if (cinfo->input_components < 1) if (cinfo->input_components < 1)
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
break;
} }
/* Support color transform only for RGB colorspaces */ /* Support color transform only for RGB colorspaces */
@@ -507,18 +507,19 @@ jinit_color_converter (j_compress_ptr cinfo)
case JCS_BG_RGB: case JCS_BG_RGB:
if (cinfo->num_components != 3) if (cinfo->num_components != 3)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
if (cinfo->in_color_space != cinfo->jpeg_color_space) if (cinfo->in_color_space == cinfo->jpeg_color_space) {
switch (cinfo->color_transform) {
case JCT_NONE:
cconvert->pub.color_convert = rgb_convert;
break;
case JCT_SUBTRACT_GREEN:
cconvert->pub.color_convert = rgb_rgb1_convert;
break;
default:
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
switch (cinfo->color_transform) {
case JCT_NONE:
cconvert->pub.color_convert = rgb_convert;
break;
case JCT_SUBTRACT_GREEN:
cconvert->pub.color_convert = rgb_rgb1_convert;
break;
default:
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
break; break;
case JCS_YCbCr: case JCS_YCbCr:
@@ -571,9 +572,10 @@ jinit_color_converter (j_compress_ptr cinfo)
case JCS_CMYK: case JCS_CMYK:
if (cinfo->num_components != 4) if (cinfo->num_components != 4)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
if (cinfo->in_color_space != JCS_CMYK) if (cinfo->in_color_space == JCS_CMYK)
cconvert->pub.color_convert = null_convert;
else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
cconvert->pub.color_convert = null_convert;
break; break;
case JCS_YCCK: case JCS_YCCK:
@@ -597,5 +599,6 @@ jinit_color_converter (j_compress_ptr cinfo)
cinfo->num_components != cinfo->input_components) cinfo->num_components != cinfo->input_components)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
cconvert->pub.color_convert = null_convert; cconvert->pub.color_convert = null_convert;
break;
} }
} }
+42 -109
View File
@@ -2,7 +2,7 @@
* jchuff.c * jchuff.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2006-2019 by Guido Vollbeding. * Modified 2006-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -178,12 +178,13 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
htbl = htbl =
isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno]; isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
if (htbl == NULL) if (htbl == NULL)
htbl = jpeg_std_huff_table((j_common_ptr) cinfo, isDC, tblno); ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
/* Allocate a workspace if we haven't already done so. */ /* Allocate a workspace if we haven't already done so. */
if (*pdtbl == NULL) if (*pdtbl == NULL)
*pdtbl = (c_derived_tbl *) (*cinfo->mem->alloc_small) *pdtbl = (c_derived_tbl *)
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(c_derived_tbl)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(c_derived_tbl));
dtbl = *pdtbl; dtbl = *pdtbl;
/* Figure C.1: make table of Huffman code length for each symbol */ /* Figure C.1: make table of Huffman code length for each symbol */
@@ -1255,88 +1256,22 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */ UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
int codesize[257]; /* codesize[k] = code length of symbol k */ int codesize[257]; /* codesize[k] = code length of symbol k */
int others[257]; /* next symbol in current branch of tree */ int others[257]; /* next symbol in current branch of tree */
int c1, c2, i, j; int c1, c2;
UINT8 *p; int p, i, j;
long v; long v;
freq[256] = 1; /* make sure 256 has a nonzero count */
/* Including the pseudo-symbol 256 in the Huffman procedure guarantees
* that no real symbol is given code-value of all ones, because 256
* will be placed last in the largest codeword category.
* In the symbol list build procedure this element serves as sentinel
* for the zero run loop.
*/
#ifndef DONT_USE_FANCY_HUFF_OPT
/* Build list of symbols sorted in order of descending frequency */
/* This approach has several benefits (thank to John Korejwa for the idea):
* 1.
* If a codelength category is split during the length limiting procedure
* below, the feature that more frequent symbols are assigned shorter
* codewords remains valid for the adjusted code.
* 2.
* To reduce consecutive ones in a Huffman data stream (thus reducing the
* number of stuff bytes in JPEG) it is preferable to follow 0 branches
* (and avoid 1 branches) as much as possible. This is easily done by
* assigning symbols to leaves of the Huffman tree in order of decreasing
* frequency, with no secondary sort based on codelengths.
* 3.
* The symbol list can be built independently from the assignment of code
* lengths by the Huffman procedure below.
* Note: The symbol list build procedure must be performed first, because
* the Huffman procedure assigning the codelengths clobbers the frequency
* counts!
*/
/* Here we use the others array as a linked list of nonzero frequencies
* to be sorted. Already sorted elements are removed from the list.
*/
/* Building list */
/* This item does not correspond to a valid symbol frequency and is used
* as starting index.
*/
j = 256;
for (i = 0;; i++) {
if (freq[i] == 0) /* skip zero frequencies */
continue;
if (i > 255)
break;
others[j] = i; /* this symbol value */
j = i; /* previous symbol value */
}
others[j] = -1; /* mark end of list */
/* Sorting list */
p = htbl->huffval;
while ((c1 = others[256]) >= 0) {
v = freq[c1];
i = c1; /* first symbol value */
j = 256; /* pseudo symbol value for starting index */
while ((c2 = others[c1]) >= 0) {
if (freq[c2] > v) {
v = freq[c2];
i = c2; /* this symbol value */
j = c1; /* previous symbol value */
}
c1 = c2;
}
others[j] = others[i]; /* remove this symbol i from list */
*p++ = (UINT8) i;
}
#endif /* DONT_USE_FANCY_HUFF_OPT */
/* This algorithm is explained in section K.2 of the JPEG standard */ /* This algorithm is explained in section K.2 of the JPEG standard */
MEMZERO(bits, SIZEOF(bits)); MEMZERO(bits, SIZEOF(bits));
MEMZERO(codesize, SIZEOF(codesize)); MEMZERO(codesize, SIZEOF(codesize));
for (i = 0; i < 257; i++) for (i = 0; i < 257; i++)
others[i] = -1; /* init links to empty */ others[i] = -1; /* init links to empty */
freq[256] = 1; /* make sure 256 has a nonzero count */
/* Including the pseudo-symbol 256 in the Huffman procedure guarantees
* that no real symbol is given code-value of all ones, because 256
* will be placed last in the largest codeword category.
*/
/* Huffman's basic algorithm to assign optimal code lengths to symbols */ /* Huffman's basic algorithm to assign optimal code lengths to symbols */
@@ -1366,7 +1301,7 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
/* Done if we've merged everything into one frequency */ /* Done if we've merged everything into one frequency */
if (c2 < 0) if (c2 < 0)
break; break;
/* Else merge the two counts/trees */ /* Else merge the two counts/trees */
freq[c1] += freq[c2]; freq[c1] += freq[c2];
freq[c2] = 0; freq[c2] = 0;
@@ -1377,9 +1312,9 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
c1 = others[c1]; c1 = others[c1];
codesize[c1]++; codesize[c1]++;
} }
others[c1] = c2; /* chain c2 onto c1's tree branch */ others[c1] = c2; /* chain c2 onto c1's tree branch */
/* Increment the codesize of everything in c2's tree branch */ /* Increment the codesize of everything in c2's tree branch */
codesize[c2]++; codesize[c2]++;
while (others[c2] >= 0) { while (others[c2] >= 0) {
@@ -1394,7 +1329,7 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
/* The JPEG standard seems to think that this can't happen, */ /* The JPEG standard seems to think that this can't happen, */
/* but I'm paranoid... */ /* but I'm paranoid... */
if (codesize[i] > MAX_CLEN) if (codesize[i] > MAX_CLEN)
ERREXIT(cinfo, JERR_HUFF_CLEN_OUTOFBOUNDS); ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
bits[codesize[i]]++; bits[codesize[i]]++;
} }
@@ -1410,16 +1345,13 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
* shortest nonzero BITS entry is converted into a prefix for two code words * shortest nonzero BITS entry is converted into a prefix for two code words
* one bit longer. * one bit longer.
*/ */
for (i = MAX_CLEN; i > 16; i--) { for (i = MAX_CLEN; i > 16; i--) {
while (bits[i] > 0) { while (bits[i] > 0) {
j = i - 2; /* find length of new prefix to be used */ j = i - 2; /* find length of new prefix to be used */
while (bits[j] == 0) { while (bits[j] == 0)
if (j == 0)
ERREXIT(cinfo, JERR_HUFF_CLEN_OUTOFBOUNDS);
j--; j--;
}
bits[i] -= 2; /* remove two symbols */ bits[i] -= 2; /* remove two symbols */
bits[i-1]++; /* one goes in this length */ bits[i-1]++; /* one goes in this length */
bits[j+1] += 2; /* two new symbols in this length */ bits[j+1] += 2; /* two new symbols in this length */
@@ -1431,27 +1363,24 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
while (bits[i] == 0) /* find largest codelength still in use */ while (bits[i] == 0) /* find largest codelength still in use */
i--; i--;
bits[i]--; bits[i]--;
/* Return final symbol counts (only for lengths 0..16) */ /* Return final symbol counts (only for lengths 0..16) */
MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits)); MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
#ifdef DONT_USE_FANCY_HUFF_OPT
/* Return a list of the symbols sorted by code length */ /* Return a list of the symbols sorted by code length */
/* Note: Due to the codelength changes made above, it can happen /* It's not real clear to me why we don't need to consider the codelength
* that more frequent symbols are assigned longer codewords. * changes made above, but the JPEG spec seems to think this works.
*/ */
p = htbl->huffval; p = 0;
for (i = 1; i <= MAX_CLEN; i++) { for (i = 1; i <= MAX_CLEN; i++) {
for (j = 0; j <= 255; j++) { for (j = 0; j <= 255; j++) {
if (codesize[j] == i) { if (codesize[j] == i) {
*p++ = (UINT8) j; htbl->huffval[p] = (UINT8) j;
p++;
} }
} }
} }
#endif /* DONT_USE_FANCY_HUFF_OPT */
/* Set sent_table FALSE so updated table will be written to JPEG file. */ /* Set sent_table FALSE so updated table will be written to JPEG file. */
htbl->sent_table = FALSE; htbl->sent_table = FALSE;
} }
@@ -1471,13 +1400,13 @@ finish_pass_gather (j_compress_ptr cinfo)
boolean did_dc[NUM_HUFF_TBLS]; boolean did_dc[NUM_HUFF_TBLS];
boolean did_ac[NUM_HUFF_TBLS]; boolean did_ac[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!
*/
if (cinfo->progressive_mode) if (cinfo->progressive_mode)
/* Flush out buffered data (all we care about is counting the EOB symbol) */ /* Flush out buffered data (all we care about is counting the EOB symbol) */
emit_eobrun(entropy); emit_eobrun(entropy);
/* It's important not to apply jpeg_gen_optimal_table more than once
* per table, because it clobbers the input frequency counts!
*/
MEMZERO(did_dc, SIZEOF(did_dc)); MEMZERO(did_dc, SIZEOF(did_dc));
MEMZERO(did_ac, SIZEOF(did_ac)); MEMZERO(did_ac, SIZEOF(did_ac));
@@ -1546,8 +1475,9 @@ start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
entropy->pub.encode_mcu = encode_mcu_AC_refine; entropy->pub.encode_mcu = encode_mcu_AC_refine;
/* AC refinement needs a correction bit buffer */ /* AC refinement needs a correction bit buffer */
if (entropy->bit_buffer == NULL) if (entropy->bit_buffer == NULL)
entropy->bit_buffer = (char *) (*cinfo->mem->alloc_small) entropy->bit_buffer = (char *)
((j_common_ptr) cinfo, JPOOL_IMAGE, MAX_CORR_BITS * SIZEOF(char)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
MAX_CORR_BITS * SIZEOF(char));
} }
} }
@@ -1575,8 +1505,9 @@ start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
/* Allocate and zero the statistics tables */ /* Allocate and zero the statistics tables */
/* Note that jpeg_gen_optimal_table expects 257 entries in each table! */ /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
if (entropy->dc_count_ptrs[tbl] == NULL) if (entropy->dc_count_ptrs[tbl] == NULL)
entropy->dc_count_ptrs[tbl] = (long *) (*cinfo->mem->alloc_small) entropy->dc_count_ptrs[tbl] = (long *)
((j_common_ptr) cinfo, JPOOL_IMAGE, 257 * SIZEOF(long)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
257 * SIZEOF(long));
MEMZERO(entropy->dc_count_ptrs[tbl], 257 * SIZEOF(long)); MEMZERO(entropy->dc_count_ptrs[tbl], 257 * SIZEOF(long));
} else { } else {
/* Compute derived values for Huffman tables */ /* Compute derived values for Huffman tables */
@@ -1594,8 +1525,9 @@ start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
if (tbl < 0 || tbl >= NUM_HUFF_TBLS) if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl); ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
if (entropy->ac_count_ptrs[tbl] == NULL) if (entropy->ac_count_ptrs[tbl] == NULL)
entropy->ac_count_ptrs[tbl] = (long *) (*cinfo->mem->alloc_small) entropy->ac_count_ptrs[tbl] = (long *)
((j_common_ptr) cinfo, JPOOL_IMAGE, 257 * SIZEOF(long)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
257 * SIZEOF(long));
MEMZERO(entropy->ac_count_ptrs[tbl], 257 * SIZEOF(long)); MEMZERO(entropy->ac_count_ptrs[tbl], 257 * SIZEOF(long));
} else { } else {
jpeg_make_c_derived_tbl(cinfo, FALSE, tbl, jpeg_make_c_derived_tbl(cinfo, FALSE, tbl,
@@ -1624,8 +1556,9 @@ jinit_huff_encoder (j_compress_ptr cinfo)
huff_entropy_ptr entropy; huff_entropy_ptr entropy;
int i; int i;
entropy = (huff_entropy_ptr) (*cinfo->mem->alloc_small) entropy = (huff_entropy_ptr)
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(huff_entropy_encoder)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(huff_entropy_encoder));
cinfo->entropy = &entropy->pub; cinfo->entropy = &entropy->pub;
entropy->pub.start_pass = start_pass_huff; entropy->pub.start_pass = start_pass_huff;
+5 -3
View File
@@ -2,7 +2,7 @@
* jcmarker.c * jcmarker.c
* *
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2003-2019 by Guido Vollbeding. * Modified 2003-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -471,6 +471,7 @@ emit_adobe_app14 (j_compress_ptr cinfo)
break; break;
default: default:
emit_byte(cinfo, 0); /* Color transform = 0 */ emit_byte(cinfo, 0); /* Color transform = 0 */
break;
} }
} }
@@ -701,8 +702,9 @@ jinit_marker_writer (j_compress_ptr cinfo)
my_marker_ptr marker; my_marker_ptr marker;
/* Create the subobject */ /* Create the subobject */
marker = (my_marker_ptr) (*cinfo->mem->alloc_small) marker = (my_marker_ptr)
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_marker_writer)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_marker_writer));
cinfo->marker = &marker->pub; cinfo->marker = &marker->pub;
/* Initialize method pointers */ /* Initialize method pointers */
marker->pub.write_file_header = write_file_header; marker->pub.write_file_header = write_file_header;
+15 -18
View File
@@ -2,7 +2,7 @@
* jcmaster.c * jcmaster.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2003-2019 by Guido Vollbeding. * Modified 2003-2017 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -62,7 +62,7 @@ initial_setup (j_compress_ptr cinfo)
case 5: cinfo->natural_order = jpeg_natural_order5; break; case 5: cinfo->natural_order = jpeg_natural_order5; break;
case 6: cinfo->natural_order = jpeg_natural_order6; break; case 6: cinfo->natural_order = jpeg_natural_order6; break;
case 7: cinfo->natural_order = jpeg_natural_order7; break; case 7: cinfo->natural_order = jpeg_natural_order7; break;
default: cinfo->natural_order = jpeg_natural_order; default: cinfo->natural_order = jpeg_natural_order; break;
} }
/* Derive lim_Se from block_size */ /* Derive lim_Se from block_size */
@@ -114,24 +114,20 @@ initial_setup (j_compress_ptr cinfo)
*/ */
ssize = 1; ssize = 1;
#ifdef DCT_SCALING_SUPPORTED #ifdef DCT_SCALING_SUPPORTED
if (! cinfo->raw_data_in) while (cinfo->min_DCT_h_scaled_size * ssize <=
while (cinfo->min_DCT_h_scaled_size * ssize <= (cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) &&
(cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) && (cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) {
(cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == ssize = ssize * 2;
0) { }
ssize = ssize * 2;
}
#endif #endif
compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize; compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize;
ssize = 1; ssize = 1;
#ifdef DCT_SCALING_SUPPORTED #ifdef DCT_SCALING_SUPPORTED
if (! cinfo->raw_data_in) while (cinfo->min_DCT_v_scaled_size * ssize <=
while (cinfo->min_DCT_v_scaled_size * ssize <= (cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) &&
(cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) && (cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) {
(cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == ssize = ssize * 2;
0) { }
ssize = ssize * 2;
}
#endif #endif
compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize; compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize;
@@ -624,8 +620,9 @@ jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
{ {
my_master_ptr master; my_master_ptr master;
master = (my_master_ptr) (*cinfo->mem->alloc_small) master = (my_master_ptr)
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_comp_master)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_comp_master));
cinfo->master = &master->pub; cinfo->master = &master->pub;
master->pub.prepare_for_pass = prepare_for_pass; master->pub.prepare_for_pass = prepare_for_pass;
master->pub.pass_startup = pass_startup; master->pub.pass_startup = pass_startup;
-138
View File
@@ -2,7 +2,6 @@
* jcomapi.c * jcomapi.c
* *
* Copyright (C) 1994-1997, Thomas G. Lane. * Copyright (C) 1994-1997, Thomas G. Lane.
* Modified 2019 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -105,140 +104,3 @@ jpeg_alloc_huff_table (j_common_ptr cinfo)
tbl->sent_table = FALSE; /* make sure this is false in any new table */ tbl->sent_table = FALSE; /* make sure this is false in any new table */
return tbl; return tbl;
} }
/*
* Set up the standard Huffman tables (cf. JPEG standard section K.3).
* IMPORTANT: these are only valid for 8-bit data precision!
* (Would jutils.c be a more reasonable place to put this?)
*/
GLOBAL(JHUFF_TBL *)
jpeg_std_huff_table (j_common_ptr cinfo, boolean isDC, int tblno)
{
JHUFF_TBL **htblptr, *htbl;
const UINT8 *bits, *val;
int nsymbols, len;
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->is_decompressor) {
if (isDC)
htblptr = ((j_decompress_ptr) cinfo)->dc_huff_tbl_ptrs;
else
htblptr = ((j_decompress_ptr) cinfo)->ac_huff_tbl_ptrs;
} else {
if (isDC)
htblptr = ((j_compress_ptr) cinfo)->dc_huff_tbl_ptrs;
else
htblptr = ((j_compress_ptr) cinfo)->ac_huff_tbl_ptrs;
}
switch (tblno) {
case 0:
if (isDC) {
bits = bits_dc_luminance;
val = val_dc_luminance;
} else {
bits = bits_ac_luminance;
val = val_ac_luminance;
}
break;
case 1:
if (isDC) {
bits = bits_dc_chrominance;
val = val_dc_chrominance;
} else {
bits = bits_ac_chrominance;
val = val_ac_chrominance;
}
break;
default:
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
return NULL; /* avoid compiler warnings for uninitialized variables */
}
if (htblptr[tblno] == NULL)
htblptr[tblno] = jpeg_alloc_huff_table(cinfo);
htbl = htblptr[tblno];
/* Copy the number-of-symbols-of-each-code-length counts */
MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
/* Validate the counts. We do this here mainly so we can copy the right
* number of symbols from the val[] array, without risking marching off
* the end of memory. jxhuff.c will do a more thorough test later.
*/
nsymbols = 0;
for (len = 1; len <= 16; len++)
nsymbols += bits[len];
if (nsymbols > 256)
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
if (nsymbols > 0)
MEMCOPY(htbl->huffval, val, nsymbols * SIZEOF(UINT8));
/* Initialize sent_table FALSE so table will be written to JPEG file. */
htbl->sent_table = FALSE;
return htbl;
}
+101 -12
View File
@@ -2,7 +2,7 @@
* jcparam.c * jcparam.c
* *
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2003-2019 by Guido Vollbeding. * Modified 2003-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -162,23 +162,112 @@ jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
/* /*
* Reset standard Huffman tables * Huffman table setup routines
*/ */
LOCAL(void) LOCAL(void)
std_huff_tables (j_compress_ptr cinfo) add_huff_table (j_compress_ptr cinfo,
JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
/* Define a Huffman table */
{ {
if (cinfo->dc_huff_tbl_ptrs[0] != NULL) int nsymbols, len;
(void) jpeg_std_huff_table((j_common_ptr) cinfo, TRUE, 0);
if (cinfo->ac_huff_tbl_ptrs[0] != NULL) if (*htblptr == NULL)
(void) jpeg_std_huff_table((j_common_ptr) cinfo, FALSE, 0); *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
if (cinfo->dc_huff_tbl_ptrs[1] != NULL) /* Copy the number-of-symbols-of-each-code-length counts */
(void) jpeg_std_huff_table((j_common_ptr) cinfo, TRUE, 1); MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
if (cinfo->ac_huff_tbl_ptrs[1] != NULL) /* Validate the counts. We do this here mainly so we can copy the right
(void) jpeg_std_huff_table((j_common_ptr) cinfo, FALSE, 1); * number of symbols from the val[] array, without risking marching off
* the end of memory. jchuff.c will do a more thorough test later.
*/
nsymbols = 0;
for (len = 1; len <= 16; len++)
nsymbols += bits[len];
if (nsymbols < 1 || nsymbols > 256)
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
/* Initialize sent_table FALSE so table will be written to JPEG file. */
(*htblptr)->sent_table = FALSE;
}
LOCAL(void)
std_huff_tables (j_compress_ptr cinfo)
/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
/* IMPORTANT: these are only valid for 8-bit data precision! */
{
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 };
add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
bits_dc_luminance, val_dc_luminance);
add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
bits_ac_luminance, val_ac_luminance);
add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
bits_dc_chrominance, val_dc_chrominance);
add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
bits_ac_chrominance, val_ac_chrominance);
} }
@@ -217,7 +306,7 @@ jpeg_set_defaults (j_compress_ptr cinfo)
cinfo->data_precision = BITS_IN_JSAMPLE; cinfo->data_precision = BITS_IN_JSAMPLE;
/* Set up two quantization tables using default quality of 75 */ /* Set up two quantization tables using default quality of 75 */
jpeg_set_quality(cinfo, 75, TRUE); jpeg_set_quality(cinfo, 75, TRUE);
/* Reset standard Huffman tables */ /* Set up two Huffman tables */
std_huff_tables(cinfo); std_huff_tables(cinfo);
/* Initialize default arithmetic coding conditioning */ /* Initialize default arithmetic coding conditioning */
+14 -14
View File
@@ -1,7 +1,7 @@
/* /*
* jdarith.c * jdarith.c
* *
* Developed 1997-2019 by Guido Vollbeding. * Developed 1997-2015 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -280,7 +280,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if ((m = arith_decode(cinfo, st)) != 0) { if ((m = arith_decode(cinfo, st)) != 0) {
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
while (arith_decode(cinfo, st)) { while (arith_decode(cinfo, st)) {
if ((m <<= 1) == (int) 0x8000U) { if ((m <<= 1) == 0x8000) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* magnitude overflow */ entropy->ct = -1; /* magnitude overflow */
return TRUE; return TRUE;
@@ -370,7 +370,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
st = entropy->ac_stats[tbl] + st = entropy->ac_stats[tbl] +
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217); (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
while (arith_decode(cinfo, st)) { while (arith_decode(cinfo, st)) {
if ((m <<= 1) == (int) 0x8000U) { if ((m <<= 1) == 0x8000) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* magnitude overflow */ entropy->ct = -1; /* magnitude overflow */
return TRUE; return TRUE;
@@ -404,8 +404,7 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
unsigned char *st; unsigned char *st;
JCOEF p1; int p1, blkn;
int blkn;
/* Process restart marker if needed */ /* Process restart marker if needed */
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
@@ -441,7 +440,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
JCOEFPTR thiscoef; JCOEFPTR thiscoef;
unsigned char *st; unsigned char *st;
int tbl, k, kex; int tbl, k, kex;
JCOEF p1, m1; int p1, m1;
const int * natural_order; const int * natural_order;
/* Process restart marker if needed */ /* Process restart marker if needed */
@@ -460,7 +459,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
tbl = cinfo->cur_comp_info[0]->ac_tbl_no; tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
m1 = -p1; /* -1 in the bit position being coded */ m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
/* Establish EOBx (previous stage end-of-block) index */ /* Establish EOBx (previous stage end-of-block) index */
kex = cinfo->Se; kex = cinfo->Se;
@@ -556,7 +555,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if ((m = arith_decode(cinfo, st)) != 0) { if ((m = arith_decode(cinfo, st)) != 0) {
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
while (arith_decode(cinfo, st)) { while (arith_decode(cinfo, st)) {
if ((m <<= 1) == (int) 0x8000U) { if ((m <<= 1) == 0x8000) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* magnitude overflow */ entropy->ct = -1; /* magnitude overflow */
return TRUE; return TRUE;
@@ -613,7 +612,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
st = entropy->ac_stats[tbl] + st = entropy->ac_stats[tbl] +
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217); (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
while (arith_decode(cinfo, st)) { while (arith_decode(cinfo, st)) {
if ((m <<= 1) == (int) 0x8000U) { if ((m <<= 1) == 0x8000) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* magnitude overflow */ entropy->ct = -1; /* magnitude overflow */
return TRUE; return TRUE;
@@ -767,8 +766,9 @@ jinit_arith_decoder (j_decompress_ptr cinfo)
arith_entropy_ptr entropy; arith_entropy_ptr entropy;
int i; int i;
entropy = (arith_entropy_ptr) (*cinfo->mem->alloc_small) entropy = (arith_entropy_ptr)
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(arith_entropy_decoder)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(arith_entropy_decoder));
cinfo->entropy = &entropy->pub; cinfo->entropy = &entropy->pub;
entropy->pub.start_pass = start_pass; entropy->pub.start_pass = start_pass;
entropy->pub.finish_pass = finish_pass; entropy->pub.finish_pass = finish_pass;
@@ -785,9 +785,9 @@ jinit_arith_decoder (j_decompress_ptr cinfo)
if (cinfo->progressive_mode) { if (cinfo->progressive_mode) {
/* Create progression status table */ /* Create progression status table */
int *coef_bit_ptr, ci; int *coef_bit_ptr, ci;
cinfo->coef_bits = (int (*)[DCTSIZE2]) (*cinfo->mem->alloc_small) cinfo->coef_bits = (int (*)[DCTSIZE2])
((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
cinfo->num_components * DCTSIZE2 * SIZEOF(int)); cinfo->num_components*DCTSIZE2*SIZEOF(int));
coef_bit_ptr = & cinfo->coef_bits[0][0]; coef_bit_ptr = & cinfo->coef_bits[0][0];
for (ci = 0; ci < cinfo->num_components; ci++) for (ci = 0; ci < cinfo->num_components; ci++)
for (i = 0; i < DCTSIZE2; i++) for (i = 0; i < DCTSIZE2; i++)
+13 -10
View File
@@ -2,7 +2,7 @@
* jdatadst.c * jdatadst.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2009-2019 by Guido Vollbeding. * Modified 2009-2017 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -46,7 +46,7 @@ typedef struct {
struct jpeg_destination_mgr pub; /* public fields */ struct jpeg_destination_mgr pub; /* public fields */
unsigned char ** outbuffer; /* target buffer */ unsigned char ** outbuffer; /* target buffer */
size_t * outsize; unsigned long * outsize;
unsigned char * newbuffer; /* newly allocated buffer */ unsigned char * newbuffer; /* newly allocated buffer */
JOCTET * buffer; /* start of buffer */ JOCTET * buffer; /* start of buffer */
size_t bufsize; size_t bufsize;
@@ -66,8 +66,9 @@ init_destination (j_compress_ptr cinfo)
my_dest_ptr dest = (my_dest_ptr) cinfo->dest; my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
/* Allocate the output buffer --- it will be released when done with image */ /* Allocate the output buffer --- it will be released when done with image */
dest->buffer = (JOCTET *) (*cinfo->mem->alloc_small) dest->buffer = (JOCTET *)
((j_common_ptr) cinfo, JPOOL_IMAGE, OUTPUT_BUF_SIZE * SIZEOF(JOCTET)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
OUTPUT_BUF_SIZE * SIZEOF(JOCTET));
dest->pub.next_output_byte = dest->buffer; dest->pub.next_output_byte = dest->buffer;
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
@@ -130,7 +131,7 @@ empty_mem_output_buffer (j_compress_ptr cinfo)
nextbuffer = (JOCTET *) malloc(nextsize); nextbuffer = (JOCTET *) malloc(nextsize);
if (nextbuffer == NULL) if (nextbuffer == NULL)
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 11); ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
MEMCOPY(nextbuffer, dest->buffer, dest->bufsize); MEMCOPY(nextbuffer, dest->buffer, dest->bufsize);
@@ -203,8 +204,9 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
* sizes may be different. Caveat programmer. * sizes may be different. Caveat programmer.
*/ */
if (cinfo->dest == NULL) { /* first time for this JPEG object? */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */
cinfo->dest = (struct jpeg_destination_mgr *) (*cinfo->mem->alloc_small) cinfo->dest = (struct jpeg_destination_mgr *)
((j_common_ptr) cinfo, JPOOL_PERMANENT, SIZEOF(my_destination_mgr)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(my_destination_mgr));
} }
dest = (my_dest_ptr) cinfo->dest; dest = (my_dest_ptr) cinfo->dest;
@@ -231,7 +233,7 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
GLOBAL(void) GLOBAL(void)
jpeg_mem_dest (j_compress_ptr cinfo, jpeg_mem_dest (j_compress_ptr cinfo,
unsigned char ** outbuffer, size_t * outsize) unsigned char ** outbuffer, unsigned long * outsize)
{ {
my_mem_dest_ptr dest; my_mem_dest_ptr dest;
@@ -242,8 +244,9 @@ jpeg_mem_dest (j_compress_ptr cinfo,
* can be written to the same buffer without re-executing jpeg_mem_dest. * can be written to the same buffer without re-executing jpeg_mem_dest.
*/ */
if (cinfo->dest == NULL) { /* first time for this JPEG object? */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */
cinfo->dest = (struct jpeg_destination_mgr *) (*cinfo->mem->alloc_small) cinfo->dest = (struct jpeg_destination_mgr *)
((j_common_ptr) cinfo, JPOOL_PERMANENT, SIZEOF(my_mem_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 = (my_mem_dest_ptr) cinfo->dest;
+16 -15
View File
@@ -2,7 +2,7 @@
* jdatasrc.c * jdatasrc.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2009-2019 by Guido Vollbeding. * Modified 2009-2015 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -156,23 +156,21 @@ METHODDEF(void)
skip_input_data (j_decompress_ptr cinfo, long num_bytes) skip_input_data (j_decompress_ptr cinfo, long num_bytes)
{ {
struct jpeg_source_mgr * src = cinfo->src; struct jpeg_source_mgr * src = cinfo->src;
size_t nbytes;
/* Just a dumb implementation for now. Could use fseek() except /* Just a dumb implementation for now. Could use fseek() except
* it doesn't work on pipes. Not clear that being smart is worth * it doesn't work on pipes. Not clear that being smart is worth
* any trouble anyway --- large skips are infrequent. * any trouble anyway --- large skips are infrequent.
*/ */
if (num_bytes > 0) { if (num_bytes > 0) {
nbytes = (size_t) num_bytes; while (num_bytes > (long) src->bytes_in_buffer) {
while (nbytes > src->bytes_in_buffer) { num_bytes -= (long) src->bytes_in_buffer;
nbytes -= src->bytes_in_buffer;
(void) (*src->fill_input_buffer) (cinfo); (void) (*src->fill_input_buffer) (cinfo);
/* note we assume that fill_input_buffer will never return FALSE, /* note we assume that fill_input_buffer will never return FALSE,
* so suspension need not be handled. * so suspension need not be handled.
*/ */
} }
src->next_input_byte += nbytes; src->next_input_byte += (size_t) num_bytes;
src->bytes_in_buffer -= nbytes; src->bytes_in_buffer -= (size_t) num_bytes;
} }
} }
@@ -221,11 +219,13 @@ jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
* manager serially with the same JPEG object. Caveat programmer. * manager serially with the same JPEG object. Caveat programmer.
*/ */
if (cinfo->src == NULL) { /* first time for this JPEG object? */ if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *) (*cinfo->mem->alloc_small) cinfo->src = (struct jpeg_source_mgr *)
((j_common_ptr) cinfo, JPOOL_PERMANENT, SIZEOF(my_source_mgr)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(my_source_mgr));
src = (my_src_ptr) cinfo->src; src = (my_src_ptr) cinfo->src;
src->buffer = (JOCTET *) (*cinfo->mem->alloc_small) src->buffer = (JOCTET *)
((j_common_ptr) cinfo, JPOOL_PERMANENT, INPUT_BUF_SIZE * SIZEOF(JOCTET)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
INPUT_BUF_SIZE * SIZEOF(JOCTET));
} }
src = (my_src_ptr) cinfo->src; src = (my_src_ptr) cinfo->src;
@@ -247,7 +247,7 @@ jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
GLOBAL(void) GLOBAL(void)
jpeg_mem_src (j_decompress_ptr cinfo, jpeg_mem_src (j_decompress_ptr cinfo,
const unsigned char * inbuffer, size_t insize) const unsigned char * inbuffer, unsigned long insize)
{ {
struct jpeg_source_mgr * src; struct jpeg_source_mgr * src;
@@ -259,8 +259,9 @@ jpeg_mem_src (j_decompress_ptr cinfo,
* the first one. * the first one.
*/ */
if (cinfo->src == NULL) { /* first time for this JPEG object? */ if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *) (*cinfo->mem->alloc_small) cinfo->src = (struct jpeg_source_mgr *)
((j_common_ptr) cinfo, JPOOL_PERMANENT, SIZEOF(struct jpeg_source_mgr)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(struct jpeg_source_mgr));
} }
src = cinfo->src; src = cinfo->src;
@@ -269,6 +270,6 @@ jpeg_mem_src (j_decompress_ptr cinfo,
src->skip_input_data = skip_input_data; src->skip_input_data = skip_input_data;
src->resync_to_restart = jpeg_resync_to_restart; /* use default method */ src->resync_to_restart = jpeg_resync_to_restart; /* use default method */
src->term_source = term_source; src->term_source = term_source;
src->bytes_in_buffer = insize; src->bytes_in_buffer = (size_t) insize;
src->next_input_byte = (const JOCTET *) inbuffer; src->next_input_byte = (const JOCTET *) inbuffer;
} }
+71 -59
View File
@@ -2,7 +2,7 @@
* jdcolor.c * jdcolor.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2011-2019 by Guido Vollbeding. * Modified 2011-2017 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -124,22 +124,28 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
INT32 x; INT32 x;
SHIFT_TEMPS SHIFT_TEMPS
cconvert->Cr_r_tab = (int *) (*cinfo->mem->alloc_small) cconvert->Cr_r_tab = (int *)
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
cconvert->Cb_b_tab = (int *) (*cinfo->mem->alloc_small) (MAXJSAMPLE+1) * SIZEOF(int));
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int)); cconvert->Cb_b_tab = (int *)
cconvert->Cr_g_tab = (INT32 *) (*cinfo->mem->alloc_small) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32)); (MAXJSAMPLE+1) * SIZEOF(int));
cconvert->Cb_g_tab = (INT32 *) (*cinfo->mem->alloc_small) cconvert->Cr_g_tab = (INT32 *)
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32));
cconvert->Cb_g_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32));
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
/* Cr=>R value is nearest int to 1.402 * x */ /* Cr=>R value is nearest int to 1.402 * x */
cconvert->Cr_r_tab[i] = (int) DESCALE(FIX(1.402) * x, SCALEBITS); cconvert->Cr_r_tab[i] = (int)
RIGHT_SHIFT(FIX(1.402) * x + ONE_HALF, SCALEBITS);
/* Cb=>B value is nearest int to 1.772 * x */ /* Cb=>B value is nearest int to 1.772 * x */
cconvert->Cb_b_tab[i] = (int) DESCALE(FIX(1.772) * x, SCALEBITS); cconvert->Cb_b_tab[i] = (int)
RIGHT_SHIFT(FIX(1.772) * x + ONE_HALF, SCALEBITS);
/* Cr=>G value is scaled-up -0.714136286 * x */ /* Cr=>G value is scaled-up -0.714136286 * x */
cconvert->Cr_g_tab[i] = (- FIX(0.714136286)) * x; cconvert->Cr_g_tab[i] = (- FIX(0.714136286)) * x;
/* Cb=>G value is scaled-up -0.344136286 * x */ /* Cb=>G value is scaled-up -0.344136286 * x */
@@ -158,22 +164,28 @@ build_bg_ycc_rgb_table (j_decompress_ptr cinfo)
INT32 x; INT32 x;
SHIFT_TEMPS SHIFT_TEMPS
cconvert->Cr_r_tab = (int *) (*cinfo->mem->alloc_small) cconvert->Cr_r_tab = (int *)
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
cconvert->Cb_b_tab = (int *) (*cinfo->mem->alloc_small) (MAXJSAMPLE+1) * SIZEOF(int));
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int)); cconvert->Cb_b_tab = (int *)
cconvert->Cr_g_tab = (INT32 *) (*cinfo->mem->alloc_small) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32)); (MAXJSAMPLE+1) * SIZEOF(int));
cconvert->Cb_g_tab = (INT32 *) (*cinfo->mem->alloc_small) cconvert->Cr_g_tab = (INT32 *)
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32));
cconvert->Cb_g_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32));
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
/* Cr=>R value is nearest int to 2.804 * x */ /* Cr=>R value is nearest int to 2.804 * x */
cconvert->Cr_r_tab[i] = (int) DESCALE(FIX(2.804) * x, SCALEBITS); cconvert->Cr_r_tab[i] = (int)
RIGHT_SHIFT(FIX(2.804) * x + ONE_HALF, SCALEBITS);
/* Cb=>B value is nearest int to 3.544 * x */ /* Cb=>B value is nearest int to 3.544 * x */
cconvert->Cb_b_tab[i] = (int) DESCALE(FIX(3.544) * x, SCALEBITS); cconvert->Cb_b_tab[i] = (int)
RIGHT_SHIFT(FIX(3.544) * x + ONE_HALF, SCALEBITS);
/* Cr=>G value is scaled-up -1.428272572 * x */ /* Cr=>G value is scaled-up -1.428272572 * x */
cconvert->Cr_g_tab[i] = (- FIX(1.428272572)) * x; cconvert->Cr_g_tab[i] = (- FIX(1.428272572)) * x;
/* Cb=>G value is scaled-up -0.688272572 * x */ /* Cb=>G value is scaled-up -0.688272572 * x */
@@ -189,7 +201,6 @@ build_bg_ycc_rgb_table (j_decompress_ptr cinfo)
* Note that we change from noninterleaved, one-plane-per-component format * Note that we change from noninterleaved, one-plane-per-component format
* to interleaved-pixel format. The output buffer is therefore three times * to interleaved-pixel format. The output buffer is therefore three times
* as wide as the input buffer. * as wide as the input buffer.
*
* A starting row offset is provided only for the input buffer. The caller * A starting row offset is provided only for the input buffer. The caller
* can easily adjust the passed output_buf value to accommodate any row * can easily adjust the passed output_buf value to accommodate any row
* offset required on that side. * offset required on that side.
@@ -253,8 +264,9 @@ build_rgb_y_table (j_decompress_ptr cinfo)
INT32 i; INT32 i;
/* Allocate and fill in the conversion tables. */ /* Allocate and fill in the conversion tables. */
cconvert->rgb_y_tab = rgb_y_tab = (INT32 *) (*cinfo->mem->alloc_small) cconvert->rgb_y_tab = rgb_y_tab = (INT32 *)
((j_common_ptr) cinfo, JPOOL_IMAGE, TABLE_SIZE * SIZEOF(INT32)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(TABLE_SIZE * SIZEOF(INT32)));
for (i = 0; i <= MAXJSAMPLE; i++) { for (i = 0; i <= MAXJSAMPLE; i++) {
rgb_y_tab[i+R_Y_OFF] = FIX(0.299) * i; rgb_y_tab[i+R_Y_OFF] = FIX(0.299) * i;
@@ -274,8 +286,8 @@ rgb_gray_convert (j_decompress_ptr cinfo,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int r, g, b;
register INT32 * ctab = cconvert->rgb_y_tab; register INT32 * ctab = cconvert->rgb_y_tab;
register int r, g, b;
register JSAMPROW outptr; register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2; register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col; register JDIMENSION col;
@@ -301,7 +313,6 @@ rgb_gray_convert (j_decompress_ptr cinfo,
/* /*
* Convert some rows of samples to the output colorspace.
* [R-G,G,B-G] to [R,G,B] conversion with modulo calculation * [R-G,G,B-G] to [R,G,B] conversion with modulo calculation
* (inverse color transform). * (inverse color transform).
* This can be seen as an adaption of the general YCbCr->RGB * This can be seen as an adaption of the general YCbCr->RGB
@@ -353,8 +364,8 @@ rgb1_gray_convert (j_decompress_ptr cinfo,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int r, g, b;
register INT32 * ctab = cconvert->rgb_y_tab; register INT32 * ctab = cconvert->rgb_y_tab;
register int r, g, b;
register JSAMPROW outptr; register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2; register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col; register JDIMENSION col;
@@ -385,7 +396,6 @@ rgb1_gray_convert (j_decompress_ptr cinfo,
/* /*
* Convert some rows of samples to the output colorspace.
* No colorspace change, but conversion from separate-planes * No colorspace change, but conversion from separate-planes
* to interleaved representation. * to interleaved representation.
*/ */
@@ -420,7 +430,6 @@ rgb_convert (j_decompress_ptr cinfo,
/* /*
* Color conversion for no colorspace change: just copy the data, * Color conversion for no colorspace change: just copy the data,
* converting from separate-planes to interleaved representation. * converting from separate-planes to interleaved representation.
* We assume out_color_components == num_components.
*/ */
METHODDEF(void) METHODDEF(void)
@@ -428,21 +437,20 @@ null_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
int ci;
register int nc = cinfo->num_components;
register JSAMPROW outptr; register JSAMPROW outptr;
register JSAMPROW inptr; register JSAMPROW inptr;
register JDIMENSION count; register JDIMENSION col;
register int num_comps = cinfo->num_components;
JDIMENSION num_cols = cinfo->output_width; JDIMENSION num_cols = cinfo->output_width;
int ci;
while (--num_rows >= 0) { while (--num_rows >= 0) {
/* It seems fastest to make a separate pass for each component. */ for (ci = 0; ci < nc; ci++) {
for (ci = 0; ci < num_comps; ci++) {
inptr = input_buf[ci][input_row]; inptr = input_buf[ci][input_row];
outptr = output_buf[0] + ci; outptr = output_buf[0] + ci;
for (count = num_cols; count > 0; count--) { for (col = 0; col < num_cols; col++) {
*outptr = *inptr++; /* don't need GETJSAMPLE() here */ *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
outptr += num_comps; outptr += nc;
} }
} }
input_row++; input_row++;
@@ -496,10 +504,9 @@ gray_rgb_convert (j_decompress_ptr cinfo,
/* /*
* Convert some rows of samples to the output colorspace. * Adobe-style YCCK->CMYK conversion.
* This version handles Adobe-style YCCK->CMYK conversion, * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same
* where we convert YCbCr to R=1-C, G=1-M, and B=1-Y using the * conversion as above, while passing K (black) unchanged.
* same conversion as above, while passing K (black) unchanged.
* We assume build_ycc_rgb_table has been called. * We assume build_ycc_rgb_table has been called.
*/ */
@@ -570,8 +577,9 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
my_cconvert_ptr cconvert; my_cconvert_ptr cconvert;
int ci; int ci;
cconvert = (my_cconvert_ptr) (*cinfo->mem->alloc_small) cconvert = (my_cconvert_ptr)
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_color_deconverter)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_color_deconverter));
cinfo->cconvert = &cconvert->pub; cinfo->cconvert = &cconvert->pub;
cconvert->pub.start_pass = start_pass_dcolor; cconvert->pub.start_pass = start_pass_dcolor;
@@ -599,6 +607,7 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
default: /* JCS_UNKNOWN can be anything */ default: /* JCS_UNKNOWN can be anything */
if (cinfo->num_components < 1) if (cinfo->num_components < 1)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
break;
} }
/* Support color transform only for RGB colorspaces */ /* Support color transform only for RGB colorspaces */
@@ -675,18 +684,19 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
case JCS_BG_RGB: case JCS_BG_RGB:
cinfo->out_color_components = RGB_PIXELSIZE; cinfo->out_color_components = RGB_PIXELSIZE;
if (cinfo->jpeg_color_space != JCS_BG_RGB) if (cinfo->jpeg_color_space == JCS_BG_RGB) {
switch (cinfo->color_transform) {
case JCT_NONE:
cconvert->pub.color_convert = rgb_convert;
break;
case JCT_SUBTRACT_GREEN:
cconvert->pub.color_convert = rgb1_rgb_convert;
break;
default:
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
switch (cinfo->color_transform) {
case JCT_NONE:
cconvert->pub.color_convert = rgb_convert;
break;
case JCT_SUBTRACT_GREEN:
cconvert->pub.color_convert = rgb1_rgb_convert;
break;
default:
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
break; break;
case JCS_CMYK: case JCS_CMYK:
@@ -704,12 +714,14 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
} }
break; break;
default: /* permit null conversion to same output space */ default:
if (cinfo->out_color_space != cinfo->jpeg_color_space) /* Permit null conversion to same output space */
/* unsupported non-null conversion */ if (cinfo->out_color_space == cinfo->jpeg_color_space) {
cinfo->out_color_components = cinfo->num_components;
cconvert->pub.color_convert = null_convert;
} else /* unsupported non-null conversion */
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
cinfo->out_color_components = cinfo->num_components; break;
cconvert->pub.color_convert = null_convert;
} }
if (cinfo->quantize_colors) if (cinfo->quantize_colors)
+8 -1
View File
@@ -2,7 +2,7 @@
* jdct.h * jdct.h
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2002-2019 by Guido Vollbeding. * Modified 2002-2017 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -358,6 +358,13 @@ EXTERN(void) jpeg_idct_1x2
#define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5)) #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
/* Descale and correctly round an INT32 value that's scaled by N bits.
* We assume RIGHT_SHIFT rounds towards minus infinity, so adding
* the fudge factor is correct for either sign of X.
*/
#define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
* This macro is used only when the two inputs will actually be no more than * This macro is used only when the two inputs will actually be no more than
* 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a * 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a
+50 -56
View File
@@ -2,7 +2,7 @@
* jdhuff.c * jdhuff.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2006-2019 by Guido Vollbeding. * Modified 2006-2016 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -341,12 +341,13 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
htbl = htbl =
isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno]; isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
if (htbl == NULL) if (htbl == NULL)
htbl = jpeg_std_huff_table((j_common_ptr) cinfo, isDC, tblno); ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
/* Allocate a workspace if we haven't already done so. */ /* Allocate a workspace if we haven't already done so. */
if (*pdtbl == NULL) if (*pdtbl == NULL)
*pdtbl = (d_derived_tbl *) (*cinfo->mem->alloc_small) *pdtbl = (d_derived_tbl *)
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(d_derived_tbl)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(d_derived_tbl));
dtbl = *pdtbl; dtbl = *pdtbl;
dtbl->pub = htbl; /* fill in back link */ dtbl->pub = htbl; /* fill in back link */
@@ -705,7 +706,7 @@ process_restart (j_decompress_ptr cinfo)
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
int Al = cinfo->Al; int Al = cinfo->Al;
register int s, r; register int s, r;
@@ -729,7 +730,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (! entropy->insufficient_data) { if (! entropy->insufficient_data) {
/* Load up working state */ /* Load up working state */
BITREAD_LOAD_STATE(cinfo, entropy->bitstate); BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
ASSIGN_STATE(state, entropy->saved); ASSIGN_STATE(state, entropy->saved);
/* Outer loop handles each block in the MCU */ /* Outer loop handles each block in the MCU */
@@ -758,13 +759,12 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/* Completed MCU, so update state */ /* Completed MCU, so update state */
BITREAD_SAVE_STATE(cinfo, entropy->bitstate); BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
ASSIGN_STATE(entropy->saved, state); ASSIGN_STATE(entropy->saved, state);
} }
/* Account for restart interval if using restarts */ /* Account for restart interval (no-op if not using restarts) */
if (cinfo->restart_interval) entropy->restarts_to_go--;
entropy->restarts_to_go--;
return TRUE; return TRUE;
} }
@@ -777,7 +777,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
register int s, k, r; register int s, k, r;
unsigned int EOBRUN; unsigned int EOBRUN;
@@ -809,7 +809,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (EOBRUN) /* if it's a band of zeroes... */ if (EOBRUN) /* if it's a band of zeroes... */
EOBRUN--; /* ...process it now (we do nothing) */ EOBRUN--; /* ...process it now (we do nothing) */
else { else {
BITREAD_LOAD_STATE(cinfo, entropy->bitstate); BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
Se = cinfo->Se; Se = cinfo->Se;
Al = cinfo->Al; Al = cinfo->Al;
natural_order = cinfo->natural_order; natural_order = cinfo->natural_order;
@@ -842,16 +842,15 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
} }
BITREAD_SAVE_STATE(cinfo, entropy->bitstate); BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
} }
/* Completed MCU, so update state */ /* Completed MCU, so update state */
entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */ entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
} }
/* Account for restart interval if using restarts */ /* Account for restart interval (no-op if not using restarts) */
if (cinfo->restart_interval) entropy->restarts_to_go--;
entropy->restarts_to_go--;
return TRUE; return TRUE;
} }
@@ -865,10 +864,9 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
JCOEF p1; int p1, blkn;
int blkn;
BITREAD_STATE_VARS; BITREAD_STATE_VARS;
/* Process restart marker if needed; may have to suspend */ /* Process restart marker if needed; may have to suspend */
@@ -883,7 +881,7 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
/* Load up working state */ /* Load up working state */
BITREAD_LOAD_STATE(cinfo, entropy->bitstate); BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
@@ -898,11 +896,10 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/* Completed MCU, so update state */ /* Completed MCU, so update state */
BITREAD_SAVE_STATE(cinfo, entropy->bitstate); BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
/* Account for restart interval if using restarts */ /* Account for restart interval (no-op if not using restarts) */
if (cinfo->restart_interval) entropy->restarts_to_go--;
entropy->restarts_to_go--;
return TRUE; return TRUE;
} }
@@ -914,12 +911,11 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
register int s, k, r; register int s, k, r;
unsigned int EOBRUN; unsigned int EOBRUN;
int Se; int Se, p1, m1;
JCOEF p1, m1;
const int * natural_order; const int * natural_order;
JBLOCKROW block; JBLOCKROW block;
JCOEFPTR thiscoef; JCOEFPTR thiscoef;
@@ -941,11 +937,11 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
Se = cinfo->Se; Se = cinfo->Se;
p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
m1 = -p1; /* -1 in the bit position being coded */ m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
natural_order = cinfo->natural_order; natural_order = cinfo->natural_order;
/* Load up working state */ /* Load up working state */
BITREAD_LOAD_STATE(cinfo, entropy->bitstate); BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */ EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
/* There is always only one block per MCU */ /* There is always only one block per MCU */
@@ -1047,13 +1043,12 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/* Completed MCU, so update state */ /* Completed MCU, so update state */
BITREAD_SAVE_STATE(cinfo, entropy->bitstate); BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */ entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
} }
/* Account for restart interval if using restarts */ /* Account for restart interval (no-op if not using restarts) */
if (cinfo->restart_interval) entropy->restarts_to_go--;
entropy->restarts_to_go--;
return TRUE; return TRUE;
@@ -1096,7 +1091,7 @@ decode_mcu_sub (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
Se = cinfo->lim_Se; Se = cinfo->lim_Se;
/* Load up working state */ /* Load up working state */
BITREAD_LOAD_STATE(cinfo, entropy->bitstate); BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
ASSIGN_STATE(state, entropy->saved); ASSIGN_STATE(state, entropy->saved);
/* Outer loop handles each block in the MCU */ /* Outer loop handles each block in the MCU */
@@ -1183,13 +1178,12 @@ decode_mcu_sub (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/* Completed MCU, so update state */ /* Completed MCU, so update state */
BITREAD_SAVE_STATE(cinfo, entropy->bitstate); BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
ASSIGN_STATE(entropy->saved, state); ASSIGN_STATE(entropy->saved, state);
} }
/* Account for restart interval if using restarts */ /* Account for restart interval (no-op if not using restarts) */
if (cinfo->restart_interval) entropy->restarts_to_go--;
entropy->restarts_to_go--;
return TRUE; return TRUE;
} }
@@ -1221,7 +1215,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (! entropy->insufficient_data) { if (! entropy->insufficient_data) {
/* Load up working state */ /* Load up working state */
BITREAD_LOAD_STATE(cinfo, entropy->bitstate); BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
ASSIGN_STATE(state, entropy->saved); ASSIGN_STATE(state, entropy->saved);
/* Outer loop handles each block in the MCU */ /* Outer loop handles each block in the MCU */
@@ -1308,13 +1302,12 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/* Completed MCU, so update state */ /* Completed MCU, so update state */
BITREAD_SAVE_STATE(cinfo, entropy->bitstate); BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
ASSIGN_STATE(entropy->saved, state); ASSIGN_STATE(entropy->saved, state);
} }
/* Account for restart interval if using restarts */ /* Account for restart interval (no-op if not using restarts) */
if (cinfo->restart_interval) entropy->restarts_to_go--;
entropy->restarts_to_go--;
return TRUE; return TRUE;
} }
@@ -1350,11 +1343,11 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
goto bad; goto bad;
} }
if (cinfo->Al > 13) { /* need not check for < 0 */ if (cinfo->Al > 13) { /* need not check for < 0 */
/* Arguably the maximum Al value should be less than 13 for 8-bit /* Arguably the maximum Al value should be less than 13 for 8-bit precision,
* precision, but the spec doesn't say so, and we try to be liberal * but the spec doesn't say so, and we try to be liberal about what we
* about what we accept. Note: large Al values could result in * accept. Note: large Al values could result in out-of-range DC
* out-of-range DC coefficients during early scans, leading to bizarre * coefficients during early scans, leading to bizarre displays due to
* displays due to overflows in the IDCT math. But we won't crash. * overflows in the IDCT math. But we won't crash.
*/ */
bad: bad:
ERREXIT4(cinfo, JERR_BAD_PROGRESSION, ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
@@ -1458,8 +1451,7 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
/* Precalculate which table to use for each block */ /* Precalculate which table to use for each block */
entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no]; entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
entropy->ac_cur_tbls[blkn] = /* AC needs no table when not present */ entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
cinfo->lim_Se ? entropy->ac_derived_tbls[compptr->ac_tbl_no] : NULL;
/* Decide whether we really care about the coefficient values */ /* Decide whether we really care about the coefficient values */
if (compptr->component_needed) { if (compptr->component_needed) {
ci = compptr->DCT_v_scaled_size; ci = compptr->DCT_v_scaled_size;
@@ -1502,6 +1494,7 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
if (ci <= 0 || ci > 8) ci = 8; if (ci <= 0 || ci > 8) ci = 8;
if (i <= 0 || i > 8) i = 8; if (i <= 0 || i > 8) i = 8;
entropy->coef_limit[blkn] = 1 + jpeg_zigzag_order[ci - 1][i - 1]; entropy->coef_limit[blkn] = 1 + jpeg_zigzag_order[ci - 1][i - 1];
break;
} }
} else { } else {
entropy->coef_limit[blkn] = 0; entropy->coef_limit[blkn] = 0;
@@ -1529,8 +1522,9 @@ jinit_huff_decoder (j_decompress_ptr cinfo)
huff_entropy_ptr entropy; huff_entropy_ptr entropy;
int i; int i;
entropy = (huff_entropy_ptr) (*cinfo->mem->alloc_small) entropy = (huff_entropy_ptr)
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(huff_entropy_decoder)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(huff_entropy_decoder));
cinfo->entropy = &entropy->pub; cinfo->entropy = &entropy->pub;
entropy->pub.start_pass = start_pass_huff_decoder; entropy->pub.start_pass = start_pass_huff_decoder;
entropy->pub.finish_pass = finish_pass_huff; entropy->pub.finish_pass = finish_pass_huff;
@@ -1538,9 +1532,9 @@ jinit_huff_decoder (j_decompress_ptr cinfo)
if (cinfo->progressive_mode) { if (cinfo->progressive_mode) {
/* Create progression status table */ /* Create progression status table */
int *coef_bit_ptr, ci; int *coef_bit_ptr, ci;
cinfo->coef_bits = (int (*)[DCTSIZE2]) (*cinfo->mem->alloc_small) cinfo->coef_bits = (int (*)[DCTSIZE2])
((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
cinfo->num_components * DCTSIZE2 * SIZEOF(int)); cinfo->num_components*DCTSIZE2*SIZEOF(int));
coef_bit_ptr = & cinfo->coef_bits[0][0]; coef_bit_ptr = & cinfo->coef_bits[0][0];
for (ci = 0; ci < cinfo->num_components; ci++) for (ci = 0; ci < cinfo->num_components; ci++)
for (i = 0; i < DCTSIZE2; i++) for (i = 0; i < DCTSIZE2; i++)
@@ -1551,7 +1545,7 @@ jinit_huff_decoder (j_decompress_ptr cinfo)
entropy->derived_tbls[i] = NULL; entropy->derived_tbls[i] = NULL;
} }
} else { } else {
/* Mark derived tables unallocated */ /* Mark tables unallocated */
for (i = 0; i < NUM_HUFF_TBLS; i++) { for (i = 0; i < NUM_HUFF_TBLS; i++) {
entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL; entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
} }
+13 -7
View File
@@ -2,7 +2,7 @@
* jdmarker.c * jdmarker.c
* *
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2009-2019 by Guido Vollbeding. * Modified 2009-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -496,6 +496,8 @@ get_dht (j_decompress_ptr cinfo)
if (count > 256 || ((INT32) count) > length) if (count > 256 || ((INT32) count) > length)
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
MEMZERO(huffval, SIZEOF(huffval)); /* pre-zero array for later copy */
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
INPUT_BYTE(cinfo, huffval[i], return FALSE); INPUT_BYTE(cinfo, huffval[i], return FALSE);
@@ -515,8 +517,7 @@ get_dht (j_decompress_ptr cinfo)
*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits)); MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
if (count > 0) MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
MEMCOPY((*htblptr)->huffval, huffval, count * SIZEOF(UINT8));
} }
if (length != 0) if (length != 0)
@@ -576,14 +577,14 @@ get_dqt (j_decompress_ptr cinfo)
count = DCTSIZE2; count = DCTSIZE2;
} }
switch ((int) count) { switch (count) {
case (2*2): natural_order = jpeg_natural_order2; break; case (2*2): natural_order = jpeg_natural_order2; break;
case (3*3): natural_order = jpeg_natural_order3; break; case (3*3): natural_order = jpeg_natural_order3; break;
case (4*4): natural_order = jpeg_natural_order4; break; case (4*4): natural_order = jpeg_natural_order4; break;
case (5*5): natural_order = jpeg_natural_order5; break; case (5*5): natural_order = jpeg_natural_order5; break;
case (6*6): natural_order = jpeg_natural_order6; break; case (6*6): natural_order = jpeg_natural_order6; break;
case (7*7): natural_order = jpeg_natural_order7; break; case (7*7): natural_order = jpeg_natural_order7; break;
default: natural_order = jpeg_natural_order; default: natural_order = jpeg_natural_order; break;
} }
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
@@ -783,6 +784,7 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
default: default:
TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION, TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
GETJOCTET(data[5]), (int) totallen); GETJOCTET(data[5]), (int) totallen);
break;
} }
} else { } else {
/* Start of APP0 does not match "JFIF" or "JFXX", or too short */ /* Start of APP0 does not match "JFIF" or "JFXX", or too short */
@@ -856,6 +858,7 @@ get_interesting_appn (j_decompress_ptr cinfo)
default: default:
/* can't get here unless jpeg_save_markers chooses wrong processor */ /* can't get here unless jpeg_save_markers chooses wrong processor */
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker); ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
break;
} }
/* skip any remaining data -- could be lots */ /* skip any remaining data -- could be lots */
@@ -961,6 +964,7 @@ save_marker (j_decompress_ptr cinfo)
default: default:
TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
(int) (data_length + length)); (int) (data_length + length));
break;
} }
/* skip any remaining data -- could be lots */ /* skip any remaining data -- could be lots */
@@ -1236,6 +1240,7 @@ read_markers (j_decompress_ptr cinfo)
* ought to change! * ought to change!
*/ */
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker); ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
break;
} }
/* Successfully processed marker, so reset state variable */ /* Successfully processed marker, so reset state variable */
cinfo->unread_marker = 0; cinfo->unread_marker = 0;
@@ -1411,8 +1416,9 @@ jinit_marker_reader (j_decompress_ptr cinfo)
int i; int i;
/* Create subobject in permanent pool */ /* Create subobject in permanent pool */
marker = (my_marker_ptr) (*cinfo->mem->alloc_small) marker = (my_marker_ptr)
((j_common_ptr) cinfo, JPOOL_PERMANENT, SIZEOF(my_marker_reader)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(my_marker_reader));
cinfo->marker = &marker->pub; cinfo->marker = &marker->pub;
/* Initialize public method pointers */ /* Initialize public method pointers */
marker->pub.reset_marker_reader = reset_marker_reader; marker->pub.reset_marker_reader = reset_marker_reader;
+23 -24
View File
@@ -2,7 +2,7 @@
* jdmaster.c * jdmaster.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2002-2019 by Guido Vollbeding. * Modified 2002-2017 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -104,7 +104,7 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
*/ */
{ {
#ifdef IDCT_SCALING_SUPPORTED #ifdef IDCT_SCALING_SUPPORTED
int ci, ssize; int ci;
jpeg_component_info *compptr; jpeg_component_info *compptr;
#endif #endif
@@ -124,23 +124,19 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
*/ */
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
ssize = 1; int ssize = 1;
if (! cinfo->raw_data_out) while (cinfo->min_DCT_h_scaled_size * ssize <=
while (cinfo->min_DCT_h_scaled_size * ssize <= (cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
(cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) && (cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) {
(cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == ssize = ssize * 2;
0) { }
ssize = ssize * 2;
}
compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize; compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize;
ssize = 1; ssize = 1;
if (! cinfo->raw_data_out) while (cinfo->min_DCT_v_scaled_size * ssize <=
while (cinfo->min_DCT_v_scaled_size * ssize <= (cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
(cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) && (cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) {
(cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == ssize = ssize * 2;
0) { }
ssize = ssize * 2;
}
compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize; compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize;
/* We don't support IDCT ratios larger than 2. */ /* We don't support IDCT ratios larger than 2. */
@@ -148,10 +144,13 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2; compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2;
else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2) else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2)
compptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2; compptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2;
}
/* Recompute downsampled dimensions of components; /* Recompute downsampled dimensions of components;
* application needs to know these if using raw downsampled data. * 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 */ /* Size in samples, after IDCT scaling */
compptr->downsampled_width = (JDIMENSION) compptr->downsampled_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * jdiv_round_up((long) cinfo->image_width *
@@ -173,10 +172,8 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
break; break;
case JCS_RGB: case JCS_RGB:
case JCS_BG_RGB: case JCS_BG_RGB:
#if RGB_PIXELSIZE != 3
cinfo->out_color_components = RGB_PIXELSIZE; cinfo->out_color_components = RGB_PIXELSIZE;
break; break;
#endif /* else share code with YCbCr */
case JCS_YCbCr: case JCS_YCbCr:
case JCS_BG_YCC: case JCS_BG_YCC:
cinfo->out_color_components = 3; cinfo->out_color_components = 3;
@@ -187,6 +184,7 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
break; break;
default: /* else must be same colorspace as in file */ default: /* else must be same colorspace as in file */
cinfo->out_color_components = cinfo->num_components; cinfo->out_color_components = cinfo->num_components;
break;
} }
cinfo->output_components = (cinfo->quantize_colors ? 1 : cinfo->output_components = (cinfo->quantize_colors ? 1 :
cinfo->out_color_components); cinfo->out_color_components);
@@ -527,8 +525,9 @@ jinit_master_decompress (j_decompress_ptr cinfo)
{ {
my_master_ptr master; my_master_ptr master;
master = (my_master_ptr) (*cinfo->mem->alloc_small) master = (my_master_ptr)
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_decomp_master)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_decomp_master));
cinfo->master = &master->pub; cinfo->master = &master->pub;
master->pub.prepare_for_output_pass = prepare_for_output_pass; master->pub.prepare_for_output_pass = prepare_for_output_pass;
master->pub.finish_output_pass = finish_output_pass; master->pub.finish_output_pass = finish_output_pass;
+39 -26
View File
@@ -2,7 +2,7 @@
* jdmerge.c * jdmerge.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2013-2019 by Guido Vollbeding. * Modified 2013-2017 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -95,22 +95,28 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
INT32 x; INT32 x;
SHIFT_TEMPS SHIFT_TEMPS
upsample->Cr_r_tab = (int *) (*cinfo->mem->alloc_small) upsample->Cr_r_tab = (int *)
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
upsample->Cb_b_tab = (int *) (*cinfo->mem->alloc_small) (MAXJSAMPLE+1) * SIZEOF(int));
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int)); upsample->Cb_b_tab = (int *)
upsample->Cr_g_tab = (INT32 *) (*cinfo->mem->alloc_small) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32)); (MAXJSAMPLE+1) * SIZEOF(int));
upsample->Cb_g_tab = (INT32 *) (*cinfo->mem->alloc_small) upsample->Cr_g_tab = (INT32 *)
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32));
upsample->Cb_g_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32));
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
/* Cr=>R value is nearest int to 1.402 * x */ /* Cr=>R value is nearest int to 1.402 * x */
upsample->Cr_r_tab[i] = (int) DESCALE(FIX(1.402) * x, SCALEBITS); upsample->Cr_r_tab[i] = (int)
RIGHT_SHIFT(FIX(1.402) * x + ONE_HALF, SCALEBITS);
/* Cb=>B value is nearest int to 1.772 * x */ /* Cb=>B value is nearest int to 1.772 * x */
upsample->Cb_b_tab[i] = (int) DESCALE(FIX(1.772) * x, SCALEBITS); upsample->Cb_b_tab[i] = (int)
RIGHT_SHIFT(FIX(1.772) * x + ONE_HALF, SCALEBITS);
/* Cr=>G value is scaled-up -0.714136286 * x */ /* Cr=>G value is scaled-up -0.714136286 * x */
upsample->Cr_g_tab[i] = (- FIX(0.714136286)) * x; upsample->Cr_g_tab[i] = (- FIX(0.714136286)) * x;
/* Cb=>G value is scaled-up -0.344136286 * x */ /* Cb=>G value is scaled-up -0.344136286 * x */
@@ -129,22 +135,28 @@ build_bg_ycc_rgb_table (j_decompress_ptr cinfo)
INT32 x; INT32 x;
SHIFT_TEMPS SHIFT_TEMPS
upsample->Cr_r_tab = (int *) (*cinfo->mem->alloc_small) upsample->Cr_r_tab = (int *)
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
upsample->Cb_b_tab = (int *) (*cinfo->mem->alloc_small) (MAXJSAMPLE+1) * SIZEOF(int));
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int)); upsample->Cb_b_tab = (int *)
upsample->Cr_g_tab = (INT32 *) (*cinfo->mem->alloc_small) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32)); (MAXJSAMPLE+1) * SIZEOF(int));
upsample->Cb_g_tab = (INT32 *) (*cinfo->mem->alloc_small) upsample->Cr_g_tab = (INT32 *)
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32));
upsample->Cb_g_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32));
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
/* Cr=>R value is nearest int to 2.804 * x */ /* Cr=>R value is nearest int to 2.804 * x */
upsample->Cr_r_tab[i] = (int) DESCALE(FIX(2.804) * x, SCALEBITS); upsample->Cr_r_tab[i] = (int)
RIGHT_SHIFT(FIX(2.804) * x + ONE_HALF, SCALEBITS);
/* Cb=>B value is nearest int to 3.544 * x */ /* Cb=>B value is nearest int to 3.544 * x */
upsample->Cb_b_tab[i] = (int) DESCALE(FIX(3.544) * x, SCALEBITS); upsample->Cb_b_tab[i] = (int)
RIGHT_SHIFT(FIX(3.544) * x + ONE_HALF, SCALEBITS);
/* Cr=>G value is scaled-up -1.428272572 * x */ /* Cr=>G value is scaled-up -1.428272572 * x */
upsample->Cr_g_tab[i] = (- FIX(1.428272572)) * x; upsample->Cr_g_tab[i] = (- FIX(1.428272572)) * x;
/* Cb=>G value is scaled-up -0.688272572 * x */ /* Cb=>G value is scaled-up -0.688272572 * x */
@@ -407,8 +419,9 @@ jinit_merged_upsampler (j_decompress_ptr cinfo)
{ {
my_upsample_ptr upsample; my_upsample_ptr upsample;
upsample = (my_upsample_ptr) (*cinfo->mem->alloc_small) upsample = (my_upsample_ptr)
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_upsampler)); (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_upsampler));
cinfo->upsample = &upsample->pub; cinfo->upsample = &upsample->pub;
upsample->pub.start_pass = start_pass_merged_upsample; upsample->pub.start_pass = start_pass_merged_upsample;
upsample->pub.need_context_rows = FALSE; upsample->pub.need_context_rows = FALSE;
@@ -419,9 +432,9 @@ jinit_merged_upsampler (j_decompress_ptr cinfo)
upsample->pub.upsample = merged_2v_upsample; upsample->pub.upsample = merged_2v_upsample;
upsample->upmethod = h2v2_merged_upsample; upsample->upmethod = h2v2_merged_upsample;
/* Allocate a spare row buffer */ /* Allocate a spare row buffer */
upsample->spare_row = (JSAMPROW) (*cinfo->mem->alloc_large) upsample->spare_row = (JSAMPROW)
((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(size_t) upsample->out_row_width * SIZEOF(JSAMPLE)); (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
} else { } else {
upsample->pub.upsample = merged_1v_upsample; upsample->pub.upsample = merged_1v_upsample;
upsample->upmethod = h2v1_merged_upsample; upsample->upmethod = h2v1_merged_upsample;
+2 -2
View File
@@ -2,7 +2,7 @@
* jerror.h * jerror.h
* *
* Copyright (C) 1994-1997, Thomas G. Lane. * Copyright (C) 1994-1997, Thomas G. Lane.
* Modified 1997-2018 by Guido Vollbeding. * Modified 1997-2012 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -84,7 +84,7 @@ JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
JMESSAGE(JERR_FILE_READ, "Input file read error") JMESSAGE(JERR_FILE_READ, "Input file read error")
JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?") JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet") JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
JMESSAGE(JERR_HUFF_CLEN_OUTOFBOUNDS, "Huffman code size table out of bounds") JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry") JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels") JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
JMESSAGE(JERR_INPUT_EMPTY, "Empty input file") JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
+55 -61
View File
@@ -2,7 +2,7 @@
* jfdctint.c * jfdctint.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modification developed 2003-2018 by Guido Vollbeding. * Modification developed 2003-2015 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -3261,84 +3261,78 @@ jpeg_fdct_6x3 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
GLOBAL(void) GLOBAL(void)
jpeg_fdct_4x2 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col) jpeg_fdct_4x2 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
{ {
DCTELEM tmp0, tmp2, tmp10, tmp12, tmp4, tmp5; INT32 tmp0, tmp1;
INT32 tmp1, tmp3, tmp11, tmp13; INT32 tmp10, tmp11;
INT32 z1, z2, z3; DCTELEM *dataptr;
JSAMPROW elemptr; JSAMPROW elemptr;
int ctr;
SHIFT_TEMPS SHIFT_TEMPS
/* Pre-zero output coefficient block. */ /* Pre-zero output coefficient block. */
MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2); MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
/* Pass 1: process rows. /* Pass 1: process rows.
* Note results are scaled up by sqrt(8) compared to a true DCT. * Note results are scaled up by sqrt(8) compared to a true DCT;
* furthermore, we scale the results by 2**PASS1_BITS.
* We must also scale the output by (8/4)*(8/2) = 2**3, which we add here.
* 4-point FDCT kernel, * 4-point FDCT kernel,
* cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT]. * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].
*/ */
/* Row 0 */ dataptr = data;
elemptr = sample_data[0] + start_col; for (ctr = 0; ctr < 2; ctr++) {
elemptr = sample_data[ctr] + start_col;
/* Even part */ /* Even part */
tmp4 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[3]); tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[3]);
tmp5 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[2]); tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[2]);
tmp0 = tmp4 + tmp5; tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[3]);
tmp2 = tmp4 - tmp5; tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[2]);
/* Odd part */ /* Apply unsigned->signed conversion. */
dataptr[0] = (DCTELEM)
((tmp0 + tmp1 - 4 * CENTERJSAMPLE) << (PASS1_BITS+3));
dataptr[2] = (DCTELEM) ((tmp0 - tmp1) << (PASS1_BITS+3));
z2 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[3]); /* Odd part */
z3 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[2]);
z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */ tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100); /* c6 */
/* Add fudge factor here for final descale. */ /* Add fudge factor here for final descale. */
z1 += ONE << (CONST_BITS-3-1); tmp0 += ONE << (CONST_BITS-PASS1_BITS-4);
tmp1 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
/* Row 1 */ dataptr[1] = (DCTELEM)
elemptr = sample_data[1] + start_col; RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */
CONST_BITS-PASS1_BITS-3);
dataptr[3] = (DCTELEM)
RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */
CONST_BITS-PASS1_BITS-3);
/* Even part */ dataptr += DCTSIZE; /* advance pointer to next row */
}
tmp4 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[3]);
tmp5 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[2]);
tmp10 = tmp4 + tmp5;
tmp12 = tmp4 - tmp5;
/* Odd part */
z2 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[3]);
z3 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[2]);
z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
tmp11 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
tmp13 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
/* Pass 2: process columns. /* Pass 2: process columns.
* We leave the results scaled up by an overall factor of 8. * We remove the PASS1_BITS scaling, but leave the results scaled up
* We must also scale the output by (8/4)*(8/2) = 2**3. * by an overall factor of 8.
*/ */
/* Column 0 */ dataptr = data;
/* Apply unsigned->signed conversion. */ for (ctr = 0; ctr < 4; ctr++) {
data[DCTSIZE*0] = (tmp0 + tmp10 - 8 * CENTERJSAMPLE) << 3; /* Even part */
data[DCTSIZE*1] = (tmp0 - tmp10) << 3;
/* Column 1 */ /* Add fudge factor here for final descale. */
data[DCTSIZE*0+1] = (DCTELEM) RIGHT_SHIFT(tmp1 + tmp11, CONST_BITS-3); tmp0 = dataptr[DCTSIZE*0] + (ONE << (PASS1_BITS-1));
data[DCTSIZE*1+1] = (DCTELEM) RIGHT_SHIFT(tmp1 - tmp11, CONST_BITS-3); tmp1 = dataptr[DCTSIZE*1];
/* Column 2 */ dataptr[DCTSIZE*0] = (DCTELEM) RIGHT_SHIFT(tmp0 + tmp1, PASS1_BITS);
data[DCTSIZE*0+2] = (tmp2 + tmp12) << 3;
data[DCTSIZE*1+2] = (tmp2 - tmp12) << 3;
/* Column 3 */ /* Odd part */
data[DCTSIZE*0+3] = (DCTELEM) RIGHT_SHIFT(tmp3 + tmp13, CONST_BITS-3);
data[DCTSIZE*1+3] = (DCTELEM) RIGHT_SHIFT(tmp3 - tmp13, CONST_BITS-3); dataptr[DCTSIZE*1] = (DCTELEM) RIGHT_SHIFT(tmp0 - tmp1, PASS1_BITS);
dataptr++; /* advance pointer to next column */
}
} }
@@ -4318,6 +4312,7 @@ jpeg_fdct_2x4 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
/* Pass 1: process rows. /* Pass 1: process rows.
* Note results are scaled up by sqrt(8) compared to a true DCT. * Note results are scaled up by sqrt(8) compared to a true DCT.
* We must also scale the output by (8/2)*(8/4) = 2**3, which we add here.
*/ */
dataptr = data; dataptr = data;
@@ -4330,18 +4325,17 @@ jpeg_fdct_2x4 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
tmp1 = GETJSAMPLE(elemptr[1]); tmp1 = GETJSAMPLE(elemptr[1]);
/* Apply unsigned->signed conversion. */ /* Apply unsigned->signed conversion. */
dataptr[0] = (DCTELEM) (tmp0 + tmp1 - 2 * CENTERJSAMPLE); dataptr[0] = (DCTELEM) ((tmp0 + tmp1 - 2 * CENTERJSAMPLE) << 3);
/* Odd part */ /* Odd part */
dataptr[1] = (DCTELEM) (tmp0 - tmp1); dataptr[1] = (DCTELEM) ((tmp0 - tmp1) << 3);
dataptr += DCTSIZE; /* advance pointer to next row */ dataptr += DCTSIZE; /* advance pointer to next row */
} }
/* Pass 2: process columns. /* Pass 2: process columns.
* We leave the results scaled up by an overall factor of 8. * We leave the results scaled up by an overall factor of 8.
* We must also scale the output by (8/2)*(8/4) = 2**3.
* 4-point FDCT kernel, * 4-point FDCT kernel,
* cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT]. * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].
*/ */
@@ -4356,21 +4350,21 @@ jpeg_fdct_2x4 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*3]; tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*3];
tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*2]; tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*2];
dataptr[DCTSIZE*0] = (DCTELEM) ((tmp0 + tmp1) << 3); dataptr[DCTSIZE*0] = (DCTELEM) (tmp0 + tmp1);
dataptr[DCTSIZE*2] = (DCTELEM) ((tmp0 - tmp1) << 3); dataptr[DCTSIZE*2] = (DCTELEM) (tmp0 - tmp1);
/* Odd part */ /* Odd part */
tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100); /* c6 */ tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100); /* c6 */
/* Add fudge factor here for final descale. */ /* Add fudge factor here for final descale. */
tmp0 += ONE << (CONST_BITS-3-1); tmp0 += ONE << (CONST_BITS-1);
dataptr[DCTSIZE*1] = (DCTELEM) dataptr[DCTSIZE*1] = (DCTELEM)
RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */ RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */
CONST_BITS-3); CONST_BITS);
dataptr[DCTSIZE*3] = (DCTELEM) dataptr[DCTSIZE*3] = (DCTELEM)
RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */ RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */
CONST_BITS-3); CONST_BITS);
dataptr++; /* advance pointer to next column */ dataptr++; /* advance pointer to next column */
} }
+6 -6
View File
@@ -2,7 +2,7 @@
* jidctint.c * jidctint.c
* *
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modification developed 2002-2018 by Guido Vollbeding. * Modification developed 2002-2016 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -1474,7 +1474,7 @@ jpeg_idct_10x10 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* /*
* Perform dequantization and inverse DCT on one block of coefficients, * Perform dequantization and inverse DCT on one block of coefficients,
* producing an 11x11 output block. * producing a 11x11 output block.
* *
* Optimized algorithm with 24 multiplications in the 1-D kernel. * Optimized algorithm with 24 multiplications in the 1-D kernel.
* cK represents sqrt(2) * cos(K*pi/22). * cK represents sqrt(2) * cos(K*pi/22).
@@ -3675,7 +3675,7 @@ jpeg_idct_10x5 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* /*
* Perform dequantization and inverse DCT on one block of coefficients, * Perform dequantization and inverse DCT on one block of coefficients,
* producing an 8x4 output block. * producing a 8x4 output block.
* *
* 4-point IDCT in pass 1 (columns), 8-point in pass 2 (rows). * 4-point IDCT in pass 1 (columns), 8-point in pass 2 (rows).
*/ */
@@ -3835,7 +3835,7 @@ jpeg_idct_8x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* /*
* Perform dequantization and inverse DCT on one block of coefficients, * Perform dequantization and inverse DCT on one block of coefficients,
* producing a 6x3 output block. * producing a reduced-size 6x3 output block.
* *
* 3-point IDCT in pass 1 (columns), 6-point in pass 2 (rows). * 3-point IDCT in pass 1 (columns), 6-point in pass 2 (rows).
*/ */
@@ -4082,7 +4082,7 @@ jpeg_idct_2x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* /*
* Perform dequantization and inverse DCT on one block of coefficients, * Perform dequantization and inverse DCT on one block of coefficients,
* producing an 8x16 output block. * producing a 8x16 output block.
* *
* 16-point IDCT in pass 1 (columns), 8-point in pass 2 (rows). * 16-point IDCT in pass 1 (columns), 8-point in pass 2 (rows).
*/ */
@@ -5004,7 +5004,7 @@ jpeg_idct_4x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* /*
* Perform dequantization and inverse DCT on one block of coefficients, * Perform dequantization and inverse DCT on one block of coefficients,
* producing a 3x6 output block. * producing a reduced-size 3x6 output block.
* *
* 6-point IDCT in pass 1 (columns), 3-point in pass 2 (rows). * 6-point IDCT in pass 1 (columns), 3-point in pass 2 (rows).
*/ */
+32 -28
View File
@@ -2,7 +2,7 @@
* jmemmgr.c * jmemmgr.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2011-2019 by Guido Vollbeding. * Modified 2011-2012 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -130,7 +130,7 @@ typedef struct {
jvirt_barray_ptr virt_barray_list; jvirt_barray_ptr virt_barray_list;
/* This counts total space obtained from jpeg_get_small/large */ /* This counts total space obtained from jpeg_get_small/large */
size_t total_space_allocated; long total_space_allocated;
/* alloc_sarray and alloc_barray set this value for use by virtual /* alloc_sarray and alloc_barray set this value for use by virtual
* array routines. * array routines.
@@ -195,7 +195,7 @@ print_mem_stats (j_common_ptr cinfo, int pool_id)
* This is helpful because message parm array can't handle longs. * This is helpful because message parm array can't handle longs.
*/ */
fprintf(stderr, "Freeing pool %d, total space = %ld\n", fprintf(stderr, "Freeing pool %d, total space = %ld\n",
pool_id, (long) mem->total_space_allocated); pool_id, mem->total_space_allocated);
for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL; for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
lhdr_ptr = lhdr_ptr->hdr.next) { lhdr_ptr = lhdr_ptr->hdr.next) {
@@ -260,11 +260,11 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
{ {
my_mem_ptr mem = (my_mem_ptr) cinfo->mem; my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
small_pool_ptr hdr_ptr, prev_hdr_ptr; small_pool_ptr hdr_ptr, prev_hdr_ptr;
size_t odd_bytes, min_request, slop;
char * data_ptr; char * data_ptr;
size_t odd_bytes, min_request, slop;
/* Check for unsatisfiable request (do now to ensure no overflow below) */ /* Check for unsatisfiable request (do now to ensure no overflow below) */
if (sizeofobject > (size_t) MAX_ALLOC_CHUNK - SIZEOF(small_pool_hdr)) if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
out_of_memory(cinfo, 1); /* request exceeds malloc's ability */ out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
/* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */ /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
@@ -293,8 +293,8 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
else else
slop = extra_pool_slop[pool_id]; slop = extra_pool_slop[pool_id];
/* Don't ask for more than MAX_ALLOC_CHUNK */ /* Don't ask for more than MAX_ALLOC_CHUNK */
if (slop > (size_t) MAX_ALLOC_CHUNK - min_request) if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
slop = (size_t) MAX_ALLOC_CHUNK - min_request; slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
/* Try to get space, if fail reduce slop and try again */ /* Try to get space, if fail reduce slop and try again */
for (;;) { for (;;) {
hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop); hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
@@ -348,7 +348,7 @@ alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
size_t odd_bytes; size_t odd_bytes;
/* Check for unsatisfiable request (do now to ensure no overflow below) */ /* Check for unsatisfiable request (do now to ensure no overflow below) */
if (sizeofobject > (size_t) MAX_ALLOC_CHUNK - SIZEOF(large_pool_hdr)) if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
out_of_memory(cinfo, 3); /* request exceeds malloc's ability */ out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
/* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */ /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
@@ -404,7 +404,7 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
long ltemp; long ltemp;
/* Calculate max # of rows allowed in one allocation chunk */ /* Calculate max # of rows allowed in one allocation chunk */
ltemp = (MAX_ALLOC_CHUNK - SIZEOF(large_pool_hdr)) / ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
((long) samplesperrow * SIZEOF(JSAMPLE)); ((long) samplesperrow * SIZEOF(JSAMPLE));
if (ltemp <= 0) if (ltemp <= 0)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
@@ -416,14 +416,15 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
/* Get space for row pointers (small object) */ /* Get space for row pointers (small object) */
result = (JSAMPARRAY) alloc_small(cinfo, pool_id, result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
(size_t) numrows * SIZEOF(JSAMPROW)); (size_t) (numrows * SIZEOF(JSAMPROW)));
/* Get the rows themselves (large objects) */ /* Get the rows themselves (large objects) */
currow = 0; currow = 0;
while (currow < numrows) { while (currow < numrows) {
rowsperchunk = MIN(rowsperchunk, numrows - currow); rowsperchunk = MIN(rowsperchunk, numrows - currow);
workspace = (JSAMPROW) alloc_large(cinfo, pool_id, workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
(size_t) rowsperchunk * (size_t) samplesperrow * SIZEOF(JSAMPLE)); (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
* SIZEOF(JSAMPLE)));
for (i = rowsperchunk; i > 0; i--) { for (i = rowsperchunk; i > 0; i--) {
result[currow++] = workspace; result[currow++] = workspace;
workspace += samplesperrow; workspace += samplesperrow;
@@ -451,7 +452,7 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
long ltemp; long ltemp;
/* Calculate max # of rows allowed in one allocation chunk */ /* Calculate max # of rows allowed in one allocation chunk */
ltemp = (MAX_ALLOC_CHUNK - SIZEOF(large_pool_hdr)) / ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
((long) blocksperrow * SIZEOF(JBLOCK)); ((long) blocksperrow * SIZEOF(JBLOCK));
if (ltemp <= 0) if (ltemp <= 0)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
@@ -463,14 +464,15 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
/* Get space for row pointers (small object) */ /* Get space for row pointers (small object) */
result = (JBLOCKARRAY) alloc_small(cinfo, pool_id, result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
(size_t) numrows * SIZEOF(JBLOCKROW)); (size_t) (numrows * SIZEOF(JBLOCKROW)));
/* Get the rows themselves (large objects) */ /* Get the rows themselves (large objects) */
currow = 0; currow = 0;
while (currow < numrows) { while (currow < numrows) {
rowsperchunk = MIN(rowsperchunk, numrows - currow); rowsperchunk = MIN(rowsperchunk, numrows - currow);
workspace = (JBLOCKROW) alloc_large(cinfo, pool_id, workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
(size_t) rowsperchunk * (size_t) blocksperrow * SIZEOF(JBLOCK)); (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
* SIZEOF(JBLOCK)));
for (i = rowsperchunk; i > 0; i--) { for (i = rowsperchunk; i > 0; i--) {
result[currow++] = workspace; result[currow++] = workspace;
workspace += blocksperrow; workspace += blocksperrow;
@@ -583,8 +585,8 @@ realize_virt_arrays (j_common_ptr cinfo)
/* Allocate the in-memory buffers for any unrealized virtual arrays */ /* Allocate the in-memory buffers for any unrealized virtual arrays */
{ {
my_mem_ptr mem = (my_mem_ptr) cinfo->mem; my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
long bytesperrow, space_per_minheight, maximum_space; long space_per_minheight, maximum_space, avail_mem;
long avail_mem, minheights, max_minheights; long minheights, max_minheights;
jvirt_sarray_ptr sptr; jvirt_sarray_ptr sptr;
jvirt_barray_ptr bptr; jvirt_barray_ptr bptr;
@@ -596,16 +598,18 @@ realize_virt_arrays (j_common_ptr cinfo)
maximum_space = 0; maximum_space = 0;
for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) { for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
if (sptr->mem_buffer == NULL) { /* if not realized yet */ if (sptr->mem_buffer == NULL) { /* if not realized yet */
bytesperrow = (long) sptr->samplesperrow * SIZEOF(JSAMPLE); space_per_minheight += (long) sptr->maxaccess *
space_per_minheight += (long) sptr->maxaccess * bytesperrow; (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
maximum_space += (long) sptr->rows_in_array * bytesperrow; maximum_space += (long) sptr->rows_in_array *
(long) sptr->samplesperrow * SIZEOF(JSAMPLE);
} }
} }
for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) { for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
if (bptr->mem_buffer == NULL) { /* if not realized yet */ if (bptr->mem_buffer == NULL) { /* if not realized yet */
bytesperrow = (long) bptr->blocksperrow * SIZEOF(JBLOCK); space_per_minheight += (long) bptr->maxaccess *
space_per_minheight += (long) bptr->maxaccess * bytesperrow; (long) bptr->blocksperrow * SIZEOF(JBLOCK);
maximum_space += (long) bptr->rows_in_array * bytesperrow; maximum_space += (long) bptr->rows_in_array *
(long) bptr->blocksperrow * SIZEOF(JBLOCK);
} }
} }
@@ -614,7 +618,7 @@ realize_virt_arrays (j_common_ptr cinfo)
/* Determine amount of memory to actually use; this is system-dependent. */ /* Determine amount of memory to actually use; this is system-dependent. */
avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space, avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
(long) mem->total_space_allocated); mem->total_space_allocated);
/* If the maximum space needed is available, make all the buffers full /* If the maximum space needed is available, make all the buffers full
* height; otherwise parcel it out with the same number of minheights * height; otherwise parcel it out with the same number of minheights
@@ -690,7 +694,7 @@ do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
long bytesperrow, file_offset, byte_count, rows, thisrow, i; long bytesperrow, file_offset, byte_count, rows, thisrow, i;
bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE); bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
file_offset = (long) ptr->cur_start_row * bytesperrow; file_offset = ptr->cur_start_row * bytesperrow;
/* Loop to read or write each allocation chunk in mem_buffer */ /* Loop to read or write each allocation chunk in mem_buffer */
for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) { for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
/* One chunk, but check for short chunk at end of buffer */ /* One chunk, but check for short chunk at end of buffer */
@@ -723,7 +727,7 @@ do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
long bytesperrow, file_offset, byte_count, rows, thisrow, i; long bytesperrow, file_offset, byte_count, rows, thisrow, i;
bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK); bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
file_offset = (long) ptr->cur_start_row * bytesperrow; file_offset = ptr->cur_start_row * bytesperrow;
/* Loop to read or write each allocation chunk in mem_buffer */ /* Loop to read or write each allocation chunk in mem_buffer */
for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) { for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
/* One chunk, but check for short chunk at end of buffer */ /* One chunk, but check for short chunk at end of buffer */
@@ -767,7 +771,7 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
/* Make the desired part of the virtual array accessible */ /* Make the desired part of the virtual array accessible */
if (start_row < ptr->cur_start_row || if (start_row < ptr->cur_start_row ||
end_row > ptr->cur_start_row + ptr->rows_in_mem) { end_row > ptr->cur_start_row+ptr->rows_in_mem) {
if (! ptr->b_s_open) if (! ptr->b_s_open)
ERREXIT(cinfo, JERR_VIRTUAL_BUG); ERREXIT(cinfo, JERR_VIRTUAL_BUG);
/* Flush old buffer contents if necessary */ /* Flush old buffer contents if necessary */
@@ -852,7 +856,7 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
/* Make the desired part of the virtual array accessible */ /* Make the desired part of the virtual array accessible */
if (start_row < ptr->cur_start_row || if (start_row < ptr->cur_start_row ||
end_row > ptr->cur_start_row + ptr->rows_in_mem) { end_row > ptr->cur_start_row+ptr->rows_in_mem) {
if (! ptr->b_s_open) if (! ptr->b_s_open)
ERREXIT(cinfo, JERR_VIRTUAL_BUG); ERREXIT(cinfo, JERR_VIRTUAL_BUG);
/* Flush old buffer contents if necessary */ /* Flush old buffer contents if necessary */
@@ -1089,7 +1093,7 @@ jinit_memory_mgr (j_common_ptr cinfo)
mem->total_space_allocated = SIZEOF(my_memory_mgr); mem->total_space_allocated = SIZEOF(my_memory_mgr);
/* Declare ourselves open for business */ /* Declare ourselves open for business */
cinfo->mem = &mem->pub; cinfo->mem = & mem->pub;
/* Check for an environment variable JPEGMEM; if found, override the /* Check for an environment variable JPEGMEM; if found, override the
* default max_memory setting from jpeg_mem_init. Note that the * default max_memory setting from jpeg_mem_init. Note that the
+2 -6
View File
@@ -2,7 +2,6 @@
* jmemnobs.c * jmemnobs.c
* *
* Copyright (C) 1992-1996, Thomas G. Lane. * Copyright (C) 1992-1996, Thomas G. Lane.
* Modified 2019 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -13,7 +12,7 @@
* This is very portable in the sense that it'll compile on almost anything, * This is very portable in the sense that it'll compile on almost anything,
* but you'd better have lots of main memory (or virtual memory) if you want * but you'd better have lots of main memory (or virtual memory) if you want
* to process big images. * to process big images.
* Note that the max_memory_to_use option is respected by this implementation. * Note that the max_memory_to_use option is ignored by this implementation.
*/ */
#define JPEG_INTERNALS #define JPEG_INTERNALS
@@ -67,16 +66,13 @@ jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
/* /*
* This routine computes the total memory space available for allocation. * This routine computes the total memory space available for allocation.
* Here we always say, "we got all you want bud!"
*/ */
GLOBAL(long) GLOBAL(long)
jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
long max_bytes_needed, long already_allocated) long max_bytes_needed, long already_allocated)
{ {
if (cinfo->mem->max_memory_to_use)
return cinfo->mem->max_memory_to_use - already_allocated;
/* Here we say, "we got all you want bud!" */
return max_bytes_needed; return max_bytes_needed;
} }
+1 -8
View File
@@ -2,7 +2,7 @@
* jpegint.h * jpegint.h
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 1997-2019 by Guido Vollbeding. * Modified 1997-2017 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -302,13 +302,6 @@ struct jpeg_color_quantizer {
#define RIGHT_SHIFT(x,shft) ((x) >> (shft)) #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
#endif #endif
/* Descale and correctly round an INT32 value that's scaled by N bits.
* We assume RIGHT_SHIFT rounds towards minus infinity, so adding
* the fudge factor is correct for either sign of X.
*/
#define DESCALE(x,n) RIGHT_SHIFT((x) + ((INT32) 1 << ((n)-1)), n)
/* Short forms of external names for systems with brain-damaged linkers. */ /* Short forms of external names for systems with brain-damaged linkers. */
+4 -7
View File
@@ -2,7 +2,7 @@
* jpeglib.h * jpeglib.h
* *
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2002-2019 by Guido Vollbeding. * Modified 2002-2017 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -39,7 +39,7 @@ extern "C" {
#define JPEG_LIB_VERSION 90 /* Compatibility version 9.0 */ #define JPEG_LIB_VERSION 90 /* Compatibility version 9.0 */
#define JPEG_LIB_VERSION_MAJOR 9 #define JPEG_LIB_VERSION_MAJOR 9
#define JPEG_LIB_VERSION_MINOR 4 #define JPEG_LIB_VERSION_MINOR 3
/* Various constants determining the sizes of things. /* Various constants determining the sizes of things.
@@ -909,7 +909,6 @@ typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
#define jpeg_suppress_tables jSuppressTables #define jpeg_suppress_tables jSuppressTables
#define jpeg_alloc_quant_table jAlcQTable #define jpeg_alloc_quant_table jAlcQTable
#define jpeg_alloc_huff_table jAlcHTable #define jpeg_alloc_huff_table jAlcHTable
#define jpeg_std_huff_table jStdHTable
#define jpeg_start_compress jStrtCompress #define jpeg_start_compress jStrtCompress
#define jpeg_write_scanlines jWrtScanlines #define jpeg_write_scanlines jWrtScanlines
#define jpeg_finish_compress jFinCompress #define jpeg_finish_compress jFinCompress
@@ -978,10 +977,10 @@ EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
/* Data source and destination managers: memory buffers. */ /* Data source and destination managers: memory buffers. */
EXTERN(void) jpeg_mem_dest JPP((j_compress_ptr cinfo, EXTERN(void) jpeg_mem_dest JPP((j_compress_ptr cinfo,
unsigned char ** outbuffer, unsigned char ** outbuffer,
size_t * outsize)); unsigned long * outsize));
EXTERN(void) jpeg_mem_src JPP((j_decompress_ptr cinfo, EXTERN(void) jpeg_mem_src JPP((j_decompress_ptr cinfo,
const unsigned char * inbuffer, const unsigned char * inbuffer,
size_t insize)); unsigned long insize));
/* Default parameter setup for compression */ /* Default parameter setup for compression */
EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo)); EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
@@ -1006,8 +1005,6 @@ EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
boolean suppress)); boolean suppress));
EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo)); EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo)); EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
EXTERN(JHUFF_TBL *) jpeg_std_huff_table JPP((j_common_ptr cinfo,
boolean isDC, int tblno));
/* Main entry points for compression */ /* Main entry points for compression */
EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo, EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
+3 -3
View File
@@ -2,7 +2,7 @@
* jutils.c * jutils.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2009-2019 by Guido Vollbeding. * Modified 2009-2011 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -185,7 +185,7 @@ jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
{ {
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
#ifdef FMEMCOPY #ifdef FMEMCOPY
register size_t count = (size_t) num_cols * SIZEOF(JSAMPLE); register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
#else #else
register JDIMENSION count; register JDIMENSION count;
#endif #endif
@@ -213,7 +213,7 @@ jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
/* Copy a row of coefficient blocks from one place to another. */ /* Copy a row of coefficient blocks from one place to another. */
{ {
#ifdef FMEMCOPY #ifdef FMEMCOPY
FMEMCOPY(output_row, input_row, (size_t) num_blocks * (DCTSIZE2 * SIZEOF(JCOEF))); FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
#else #else
register JCOEFPTR inptr, outptr; register JCOEFPTR inptr, outptr;
register long count; register long count;
+3 -3
View File
@@ -1,7 +1,7 @@
/* /*
* jversion.h * jversion.h
* *
* Copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding. * Copyright (C) 1991-2018, Thomas G. Lane, Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@@ -9,6 +9,6 @@
*/ */
#define JVERSION "9d 12-Jan-2020" #define JVERSION "9c 14-Jan-2018"
#define JCOPYRIGHT "Copyright (C) 2020, Thomas G. Lane, Guido Vollbeding" #define JCOPYRIGHT "Copyright (C) 2018, Thomas G. Lane, Guido Vollbeding"
+2 -2
View File
@@ -74,7 +74,7 @@ if(MSVC)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE) add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
endif(MSVC) endif(MSVC)
add_library(${PNG_LIBRARY} STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${lib_srcs} ${lib_hdrs}) add_library(${PNG_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs})
target_link_libraries(${PNG_LIBRARY} ${ZLIB_LIBRARIES}) target_link_libraries(${PNG_LIBRARY} ${ZLIB_LIBRARIES})
ocv_warnings_disable(CMAKE_C_FLAGS -Wundef -Wcast-align -Wimplicit-fallthrough -Wunused-parameter -Wsign-compare) ocv_warnings_disable(CMAKE_C_FLAGS -Wundef -Wcast-align -Wimplicit-fallthrough -Wunused-parameter -Wsign-compare)
@@ -92,7 +92,7 @@ if(ENABLE_SOLUTION_FOLDERS)
endif() endif()
if(NOT BUILD_SHARED_LIBS) if(NOT BUILD_SHARED_LIBS)
ocv_install_target(${PNG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev OPTIONAL) ocv_install_target(${PNG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif() endif()
ocv_install_3rdparty_licenses(libpng LICENSE README) ocv_install_3rdparty_licenses(libpng LICENSE README)
Vendored Regular → Executable
View File
-80
View File
@@ -1,80 +0,0 @@
# COPYRIGHT
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# License); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Copyright (c) 2020, OPEN AI LAB
# Author: qtang@openailab.com or https://github.com/BUG1989
# qli@openailab.com
# sqfu@openailab.com
SET(TENGINE_COMMIT_VERSION "e89cf8870de2ff0a80cfe626c0b52b2a16fb302e")
SET(OCV_TENGINE_DIR "${OpenCV_BINARY_DIR}/3rdparty/libtengine")
SET(OCV_TENGINE_SOURCE_PATH "${OCV_TENGINE_DIR}/Tengine-${TENGINE_COMMIT_VERSION}")
IF(EXISTS "${OCV_TENGINE_SOURCE_PATH}")
MESSAGE(STATUS "Tengine is exist already at: ${OCV_TENGINE_SOURCE_PATH}")
SET(Tengine_FOUND ON)
SET(BUILD_TENGINE ON)
ELSE()
SET(OCV_TENGINE_FILENAME "${TENGINE_COMMIT_VERSION}.zip")#name
SET(OCV_TENGINE_URL "https://github.com/OAID/Tengine/archive/") #url
SET(tengine_md5sum 23f61ebb1dd419f1207d8876496289c5) #md5sum
ocv_download(FILENAME ${OCV_TENGINE_FILENAME}
HASH ${tengine_md5sum}
URL
"${OPENCV_TENGINE_URL}"
"$ENV{OPENCV_TENGINE_URL}"
"${OCV_TENGINE_URL}"
DESTINATION_DIR "${OCV_TENGINE_DIR}"
ID TENGINE
STATUS res
UNPACK RELATIVE_URL)
if (NOT res)
MESSAGE(STATUS "TENGINE DOWNLOAD FAILED. Turning Tengine_FOUND off.")
SET(Tengine_FOUND OFF)
else ()
MESSAGE(STATUS "TENGINE DOWNLOAD success . ")
SET(Tengine_FOUND ON)
SET(BUILD_TENGINE ON)
endif()
ENDIF()
if(BUILD_TENGINE)
SET(HAVE_TENGINE 1)
if(NOT ANDROID)
# linux system
if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
SET(TENGINE_TOOLCHAIN_FLAG "-march=armv7-a")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) ## AARCH64
SET(TENGINE_TOOLCHAIN_FLAG "-march=armv8-a")
endif()
endif()
SET(BUILT_IN_OPENCV ON) ## set for tengine compile discern .
SET(Tengine_INCLUDE_DIR "${OCV_TENGINE_SOURCE_PATH}/include" CACHE INTERNAL "")
if(EXISTS "${OCV_TENGINE_SOURCE_PATH}/CMakeLists.txt")
add_subdirectory("${OCV_TENGINE_SOURCE_PATH}" "${OCV_TENGINE_DIR}/build")
else()
message(WARNING "TENGINE: Missing 'CMakeLists.txt' in source code package: ${OCV_TENGINE_SOURCE_PATH}")
endif()
SET(Tengine_LIB "tengine" CACHE INTERNAL "")
endif()
+8 -13
View File
@@ -126,30 +126,30 @@ endif()
if(SIZEOF_UNSIGNED_INT EQUAL SIZEOF_SIZE_T) if(SIZEOF_UNSIGNED_INT EQUAL SIZEOF_SIZE_T)
set(TIFF_SIZE_T "unsigned int") set(TIFF_SIZE_T "unsigned int")
set(TIFF_SIZE_FORMAT "%u") set(TIFF_SIZE_FORMAT "%u")
set(TIFF_SSIZE_T "signed int")
set(TIFF_SSIZE_FORMAT "%d")
elseif(SIZEOF_UNSIGNED_LONG EQUAL SIZEOF_SIZE_T) elseif(SIZEOF_UNSIGNED_LONG EQUAL SIZEOF_SIZE_T)
set(TIFF_SIZE_T "unsigned long") set(TIFF_SIZE_T "unsigned long")
set(TIFF_SIZE_FORMAT "%lu") set(TIFF_SIZE_FORMAT "%lu")
set(TIFF_SSIZE_T "signed long")
set(TIFF_SSIZE_FORMAT "%ld")
elseif(SIZEOF_UNSIGNED_LONG_LONG EQUAL SIZEOF_SIZE_T) elseif(SIZEOF_UNSIGNED_LONG_LONG EQUAL SIZEOF_SIZE_T)
set(TIFF_SIZE_T "unsigned long") set(TIFF_SIZE_T "unsigned long")
if(MINGW) if(MINGW)
set(TIFF_SIZE_FORMAT "%I64u") set(TIFF_SIZE_FORMAT "%I64u")
set(TIFF_SSIZE_FORMAT "%I64d")
else() else()
set(TIFF_SIZE_FORMAT "%llu") set(TIFF_SIZE_FORMAT "%llu")
set(TIFF_SSIZE_FORMAT "%lld")
endif() endif()
endif() endif()
if(SIZEOF_SIGNED_INT EQUAL SIZEOF_UNSIGNED_CHAR_P) if(SIZEOF_SIGNED_INT EQUAL SIZEOF_UNSIGNED_CHAR_P)
set(TIFF_SSIZE_T "signed int")
set(TIFF_SSIZE_FORMAT "%d")
elseif(SIZEOF_SIGNED_LONG EQUAL SIZEOF_UNSIGNED_CHAR_P) elseif(SIZEOF_SIGNED_LONG EQUAL SIZEOF_UNSIGNED_CHAR_P)
set(TIFF_SSIZE_T "signed long")
set(TIFF_SSIZE_FORMAT "%ld")
elseif(SIZEOF_SIGNED_LONG_LONG EQUAL SIZEOF_UNSIGNED_CHAR_P) elseif(SIZEOF_SIGNED_LONG_LONG EQUAL SIZEOF_UNSIGNED_CHAR_P)
set(TIFF_SSIZE_T "signed long long") set(TIFF_SSIZE_T "signed long long")
if(MINGW) if(MINGW)
set(TIFF_SSIZE_FORMAT "%I64d")
else() else()
set(TIFF_SSIZE_FORMAT "%lld")
endif() endif()
endif() endif()
@@ -216,8 +216,6 @@ endif()
set(fillorder FILLORDER_MSB2LSB) set(fillorder FILLORDER_MSB2LSB)
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i.*86.*" OR if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i.*86.*" OR
CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64.*" OR CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64.*" OR
# AMD64 on Windows
CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "AMD64" OR
CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64.*") CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64.*")
set(fillorder FILLORDER_LSB2MSB) set(fillorder FILLORDER_LSB2MSB)
endif() endif()
@@ -239,9 +237,6 @@ if(HOST_BIG_ENDIAN)
else() else()
set(HOST_BIG_ENDIAN 0) set(HOST_BIG_ENDIAN 0)
endif() endif()
if(HOST_BIG_ENDIAN)
add_definitions(-DWORDS_BIGENDIAN)
endif()
# IEEE floating point # IEEE floating point
set(HAVE_IEEEFP 1 CACHE STRING "IEEE floating point is available") set(HAVE_IEEEFP 1 CACHE STRING "IEEE floating point is available")
@@ -465,7 +460,7 @@ ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4456 /wd4457 /wd4312) # vs2015
ocv_warnings_disable(CMAKE_C_FLAGS /wd4267 /wd4244 /wd4018 /wd4311 /wd4312) ocv_warnings_disable(CMAKE_C_FLAGS /wd4267 /wd4244 /wd4018 /wd4311 /wd4312)
add_library(${TIFF_LIBRARY} STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${lib_srcs}) add_library(${TIFF_LIBRARY} STATIC ${lib_srcs})
target_link_libraries(${TIFF_LIBRARY} ${ZLIB_LIBRARIES}) target_link_libraries(${TIFF_LIBRARY} ${ZLIB_LIBRARIES})
set_target_properties(${TIFF_LIBRARY} set_target_properties(${TIFF_LIBRARY}
@@ -482,7 +477,7 @@ if(ENABLE_SOLUTION_FOLDERS)
endif() endif()
if(NOT BUILD_SHARED_LIBS) if(NOT BUILD_SHARED_LIBS)
ocv_install_target(${TIFF_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev OPTIONAL) ocv_install_target(${TIFF_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif() endif()
ocv_install_3rdparty_licenses(libtiff COPYRIGHT) ocv_install_3rdparty_licenses(libtiff COPYRIGHT)
-2326
View File
File diff suppressed because it is too large Load Diff
+4 -8
View File
@@ -24,10 +24,6 @@
#ifndef _LIBPORT_ #ifndef _LIBPORT_
#define _LIBPORT_ #define _LIBPORT_
#if defined(HAVE_CONFIG_H)
# include <tif_config.h>
#endif
int getopt(int argc, char * const argv[], const char *optstring); int getopt(int argc, char * const argv[], const char *optstring);
extern char *optarg; extern char *optarg;
extern int opterr; extern int opterr;
@@ -40,16 +36,16 @@ int strcasecmp(const char *s1, const char *s2);
# define HAVE_GETOPT 1 # define HAVE_GETOPT 1
#endif #endif
#if !defined(HAVE_STRTOL) #if HAVE_STRTOL
long strtol(const char *nptr, char **endptr, int base); long strtol(const char *nptr, char **endptr, int base);
#endif #endif
#if !defined(HAVE_STRTOLL) #if HAVE_STRTOLL
long long strtoll(const char *nptr, char **endptr, int base); long long strtoll(const char *nptr, char **endptr, int base);
#endif #endif
#if !defined(HAVE_STRTOUL) #if HAVE_STRTOUL
unsigned long strtoul(const char *nptr, char **endptr, int base); unsigned long strtoul(const char *nptr, char **endptr, int base);
#endif #endif
#if !defined(HAVE_STRTOULL) #if HAVE_STRTOULL
unsigned long long strtoull(const char *nptr, char **endptr, int base); unsigned long long strtoull(const char *nptr, char **endptr, int base);
#endif #endif
-4
View File
@@ -16,11 +16,7 @@ int _TIFF_vsnprintf_f(char* str, size_t size, const char* format, va_list ap)
int count = -1; int count = -1;
if (size != 0) if (size != 0)
#if _MSC_VER <= 1310
count = _vsnprintf(str, size, format, ap);
#else
count = _vsnprintf_s(str, size, _TRUNCATE, format, ap); count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
#endif
if (count == -1) if (count == -1)
count = _vscprintf(format, ap); count = _vscprintf(format, ap);

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