Vastly improve 12-bit JPEG integration

The Gordian knot that 7fec5074f9 attempted
to unravel was caused by the fact that there are several
data-precision-dependent (JSAMPLE-dependent) fields and methods in the
exposed libjpeg API structures, and if you change the exposed libjpeg
API structures, then you have to change the whole API.  If you change
the whole API, then you have to provide a whole new library to support
the new API, and that makes it difficult to support multiple data
precisions in the same application.  (It is not impossible, as example.c
demonstrated, but using data-precision-dependent libjpeg API structures
would have made the cjpeg, djpeg, and jpegtran source code hard to read,
so it made more sense to build, install, and package 12-bit-specific
versions of those applications.)

Unfortunately, the result of that initial integration effort was an
unreadable and unmaintainable mess, which is a problem for a library
that is an ISO/ITU-T reference implementation.  Also, as I dug into the
problem of lossless JPEG support, I realized that 16-bit lossless JPEG
images are a thing, and supporting yet another version of the libjpeg
API just for those images is untenable.

In fact, however, the touch points for JSAMPLE in the exposed libjpeg
API structures are minimal:

  - The colormap and sample_range_limit fields in jpeg_decompress_struct
  - The alloc_sarray() and access_virt_sarray() methods in
    jpeg_memory_mgr
  - jpeg_write_scanlines() and jpeg_write_raw_data()
  - jpeg_read_scanlines() and jpeg_read_raw_data()
  - jpeg_skip_scanlines() and jpeg_crop_scanline()
    (This is subtle, but both of those functions use JSAMPLE-dependent
    opaque structures behind the scenes.)

It is much more readable and maintainable to provide 12-bit-specific
versions of those six top-level API functions and to document that the
aforementioned methods and fields must be type-cast when using 12-bit
samples.  Since that eliminates the need to provide a 12-bit-specific
version of the exposed libjpeg API structures, we can:

  - Compile only the precision-dependent libjpeg modules (the
    coefficient buffer controllers, the colorspace converters, the
    DCT/IDCT managers, the main buffer controllers, the preprocessing
    and postprocessing controller, the downsampler and upsamplers, the
    quantizers, the integer DCT methods, and the IDCT methods) for
    multiple data precisions.
  - Introduce 12-bit-specific methods into the various internal
    structures defined in jpegint.h.
  - Create precision-independent data type, macro, method, field, and
    function names that are prefixed by an underscore, and use an
    internal header to convert those into precision-dependent data
    type, macro, method, field, and function names, based on the value
    of BITS_IN_JSAMPLE, when compiling the precision-dependent libjpeg
    modules.
  - Expose precision-dependent jinit*() functions for each of the
    precision-dependent libjpeg modules.
  - Abstract the precision-dependent libjpeg modules by calling the
    appropriate precision-dependent jinit*() function, based on the
    value of cinfo->data_precision, from top-level libjpeg API
    functions.
This commit is contained in:
DRC
2022-11-01 21:45:39 -05:00
parent 6c2bc901e2
commit e8b40f3c2b
114 changed files with 2903 additions and 5075 deletions

View File

@@ -267,19 +267,32 @@ report_option(WITH_ARITH_ENC "Arithmetic encoding support")
report_option(WITH_TURBOJPEG "TurboJPEG API library")
report_option(WITH_JAVA "TurboJPEG Java wrapper")
if(NOT WITH_JPEG8)
set(MEM_SRCDST_FUNCTIONS "global: jpeg_mem_dest; jpeg_mem_src;")
endif()
# 0: Original libjpeg v6b/v7/v8 API/ABI
#
# libjpeg v6b/v7 API/ABI emulation:
# 1: + In-memory source/destination managers (libjpeg-turbo 1.3.x)
# 2: + Partial image decompression functions (libjpeg-turbo 1.5.x)
# 3: + ICC functions (libjpeg-turbo 2.0.x)
# 4: + 12-bit-per-component functions (libjpeg-turbo 2.2.x)
#
# libjpeg v8 API/ABI emulation:
# 1: + Partial image decompression functions (libjpeg-turbo 1.5.x)
# 2: + ICC functions (libjpeg-turbo 2.0.x)
set(SO_AGE 2)
if(NOT WITH_JPEG8)
# 3: + 12-bit-per-component functions (libjpeg-turbo 2.2.x)
if(WITH_12BIT)
set(SO_AGE 3)
if(NOT WITH_JPEG8)
set(SO_AGE 4)
endif()
else()
set(SO_AGE 2)
if(NOT WITH_JPEG8)
set(SO_AGE 3)
endif()
endif()
if(WITH_JPEG8)
@@ -519,18 +532,7 @@ configure_file(jconfig.h.in jconfig.h)
configure_file(jconfigint.h.in jconfigint.h)
configure_file(jversion.h.in jversion.h)
if(UNIX)
if(NOT WITH_JPEG8)
set(MEM_SRCDST_FUNCTIONS "global: jpeg_mem_dest; jpeg_mem_src;")
endif()
set(SIMD_FUNCTIONS "jsimd_*")
configure_file(libjpeg.map.in libjpeg.map)
if(WITH_12BIT)
if(NOT WITH_JPEG8)
set(MEM_SRCDST_FUNCTIONS "global: jpeg12_mem_dest; jpeg12_mem_src;")
endif()
set(SIMD_FUNCTIONS "jsimd12_*")
configure_file(libjpeg.map.in libjpeg12.map)
endif()
endif()
# Include directories and compiler definitions
@@ -546,15 +548,13 @@ if(CMAKE_EXECUTABLE_SUFFIX_TMP)
endif()
message(STATUS "CMAKE_EXECUTABLE_SUFFIX = ${CMAKE_EXECUTABLE_SUFFIX}")
set(JPEG12_SOURCES jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c
jchuff.c jcicc.c jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c
jcparam.c jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c
jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c jdicc.c
jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c jdpostct.c
jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c
jidctfst.c jidctint.c jidctred.c jquant1.c jquant2.c jutils.c jmemmgr.c
jmemnobs.c)
set(JPEG_SOURCES ${JPEG12_SOURCES})
set(JPEG_SOURCES jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c
jcicc.c jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c
jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c jdatadst.c
jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c jdicc.c jdinput.c
jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c jdpostct.c jdsample.c
jdtrans.c jerror.c jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c
jidctint.c jidctred.c jquant1.c jquant2.c jutils.c jmemmgr.c jmemnobs.c)
if(WITH_ARITH_ENC OR WITH_ARITH_DEC)
set(JPEG_SOURCES ${JPEG_SOURCES} jaricom.c)
@@ -568,6 +568,17 @@ if(WITH_ARITH_DEC)
set(JPEG_SOURCES ${JPEG_SOURCES} jdarith.c)
endif()
if(WITH_12BIT)
# Compile a separate version of these source files with 12-bit data
# precision.
add_library(jpeg12 OBJECT jcapistd.c jccoefct.c jccolor.c jcdctmgr.c
jcmainct.c jcprepct.c jcsample.c jdapistd.c jdcoefct.c jdcolor.c jddctmgr.c
jdmainct.c jdmerge.c jdpostct.c jdsample.c jfdctfst.c jfdctint.c jidctflt.c
jidctfst.c jidctint.c jidctred.c jquant1.c jquant2.c jutils.c)
set_property(TARGET jpeg12 PROPERTY COMPILE_FLAGS "-DBITS_IN_JSAMPLE=12")
set(JPEG12_OBJS $<TARGET_OBJECTS:jpeg12>)
endif()
if(WITH_SIMD)
add_subdirectory(simd)
if(NEON_INTRINSICS)
@@ -598,26 +609,17 @@ endif()
if(ENABLE_STATIC)
add_library(jpeg-static STATIC ${JPEG_SOURCES} $<TARGET_OBJECTS:simd>
${SIMD_OBJS})
${SIMD_OBJS} ${JPEG12_OBJS})
if(NOT MSVC)
set_target_properties(jpeg-static PROPERTIES OUTPUT_NAME jpeg)
endif()
if(WITH_12BIT)
add_library(jpeg12-static STATIC ${JPEG12_SOURCES} jsimd_none.c)
set_property(TARGET jpeg12-static PROPERTY COMPILE_FLAGS
"-DBITS_IN_JSAMPLE=12")
if(NOT MSVC)
set_target_properties(jpeg12-static PROPERTIES OUTPUT_NAME jpeg12)
endif()
endif()
endif()
if(WITH_TURBOJPEG)
if(ENABLE_SHARED)
set(TURBOJPEG_SOURCES ${JPEG_SOURCES} $<TARGET_OBJECTS:simd> ${SIMD_OBJS}
turbojpeg.c transupp.c jdatadst-tj.c jdatasrc-tj.c rdbmp.c rdppm.c
wrbmp.c wrppm.c)
wrbmp.c wrppm.c ${JPEG12_OBJS})
set(TJMAPFILE ${CMAKE_CURRENT_SOURCE_DIR}/turbojpeg-mapfile)
if(WITH_JAVA)
set(TURBOJPEG_SOURCES ${TURBOJPEG_SOURCES} turbojpeg-jni.c)
@@ -669,7 +671,7 @@ if(WITH_TURBOJPEG)
if(ENABLE_STATIC)
add_library(turbojpeg-static STATIC ${JPEG_SOURCES} $<TARGET_OBJECTS:simd>
${SIMD_OBJS} turbojpeg.c transupp.c jdatadst-tj.c jdatasrc-tj.c rdbmp.c
rdppm.c wrbmp.c wrppm.c)
rdppm.c wrbmp.c wrppm.c ${JPEG12_OBJS})
set_property(TARGET turbojpeg-static PROPERTY COMPILE_FLAGS
"-DBMP_SUPPORTED -DPPM_SUPPORTED")
if(NOT MSVC)
@@ -691,49 +693,44 @@ endif()
if(WIN32)
set(USE_SETMODE "-DUSE_SETMODE")
endif()
set(CDJPEG_COMPILE_FLAGS
"-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED ${USE_SETMODE}")
if(ENABLE_STATIC)
if(WITH_12BIT)
# Compile a separate version of these source files with 12-bit data
# precision.
add_library(cjpeg12-static OBJECT rdgif.c rdppm.c)
set_property(TARGET cjpeg12-static PROPERTY COMPILE_FLAGS
"-DBITS_IN_JSAMPLE=12 -DGIF_SUPPORTED -DPPM_SUPPORTED")
set(CJPEG12_OBJS $<TARGET_OBJECTS:cjpeg12-static>)
endif()
add_executable(cjpeg-static cjpeg.c cdjpeg.c rdbmp.c rdgif.c rdppm.c
rdswitch.c rdtarga.c)
rdswitch.c rdtarga.c ${CJPEG12_OBJS})
set_property(TARGET cjpeg-static PROPERTY COMPILE_FLAGS
"-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED ${USE_SETMODE}")
${CDJPEG_COMPILE_FLAGS})
target_link_libraries(cjpeg-static jpeg-static)
if(WITH_12BIT)
# Compile a separate version of these source files with 12-bit data
# precision.
add_library(djpeg12-static OBJECT rdcolmap.c wrgif.c wrppm.c)
set_property(TARGET djpeg12-static PROPERTY COMPILE_FLAGS
"-DBITS_IN_JSAMPLE=12 -DGIF_SUPPORTED -DPPM_SUPPORTED")
set(DJPEG12_OBJS $<TARGET_OBJECTS:djpeg12-static>)
endif()
add_executable(djpeg-static djpeg.c cdjpeg.c rdcolmap.c rdswitch.c wrbmp.c
wrgif.c wrppm.c wrtarga.c)
wrgif.c wrppm.c wrtarga.c ${DJPEG12_OBJS})
set_property(TARGET djpeg-static PROPERTY COMPILE_FLAGS
"-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED ${USE_SETMODE}")
${CDJPEG_COMPILE_FLAGS})
target_link_libraries(djpeg-static jpeg-static)
add_executable(jpegtran-static jpegtran.c cdjpeg.c rdswitch.c transupp.c)
target_link_libraries(jpegtran-static jpeg-static)
set_property(TARGET jpegtran-static PROPERTY COMPILE_FLAGS "${USE_SETMODE}")
if(WITH_12BIT)
add_executable(cjpeg12-static cjpeg.c cdjpeg.c rdgif.c rdppm.c rdswitch.c)
set_property(TARGET cjpeg12-static PROPERTY COMPILE_FLAGS
"-DBITS_IN_JSAMPLE=12 -DGIF_SUPPORTED -DPPM_SUPPORTED ${USE_SETMODE}")
target_link_libraries(cjpeg12-static jpeg12-static)
add_executable(djpeg12-static djpeg.c cdjpeg.c rdcolmap.c rdswitch.c
wrgif.c wrppm.c)
set_property(TARGET djpeg12-static PROPERTY COMPILE_FLAGS
"-DBITS_IN_JSAMPLE=12 -DGIF_SUPPORTED -DPPM_SUPPORTED ${USE_SETMODE}")
target_link_libraries(djpeg12-static jpeg12-static)
add_executable(jpeg12tran-static jpegtran.c cdjpeg.c rdswitch.c transupp.c)
target_link_libraries(jpeg12tran-static jpeg12-static)
set_property(TARGET jpeg12tran-static PROPERTY COMPILE_FLAGS
"-DBITS_IN_JSAMPLE=12 ${USE_SETMODE}")
endif()
add_executable(example-static example.c)
if(WITH_12BIT)
target_link_libraries(example-static jpeg-static jpeg12-static)
set_property(TARGET example-static PROPERTY COMPILE_FLAGS "-DWITH_12BIT")
else()
target_link_libraries(example-static jpeg-static)
endif()
target_link_libraries(example-static jpeg-static)
endif()
add_executable(rdjpgcom rdjpgcom.c)
@@ -1004,8 +1001,14 @@ foreach(libtype ${TEST_LIBTYPES})
# SIMD-accelerated ones.)
macro(add_bittest PROG NAME ARGS OUTFILE INFILE MD5SUM)
if(${PROG} STREQUAL "cjpeg12")
set(ACTUAL_ARGS "${ARGS};-precision;12")
else()
set(ACTUAL_ARGS ${ARGS})
endif()
string(REGEX REPLACE "12" "" ACTUAL_PROG ${PROG})
add_test(${PROG}-${libtype}-${NAME}
${CMAKE_CROSSCOMPILING_EMULATOR} ${PROG}${suffix} ${ARGS}
${CMAKE_CROSSCOMPILING_EMULATOR} ${ACTUAL_PROG}${suffix} ${ACTUAL_ARGS}
-outfile ${OUTFILE} ${INFILE})
add_test(${PROG}-${libtype}-${NAME}-cmp
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP} ${MD5SUM} ${OUTFILE})
@@ -1023,7 +1026,7 @@ foreach(libtype ${TEST_LIBTYPES})
if(sample_bits EQUAL 12)
set(cjpeg cjpeg12)
set(djpeg djpeg12)
set(jpegtran jpeg12tran)
set(jpegtran jpegtran12)
set(testout testout12)
set(TESTORIG testorig12.jpg)
@@ -1166,9 +1169,10 @@ foreach(libtype ${TEST_LIBTYPES})
${MD5_JPEG_RGB_ISLOW})
# CC: null SAMP: fullsize IDCT: islow ENT: huff
add_bittest(${djpeg} rgb-islow "-dct;int;-ppm;-icc;${testout}_rgb_islow.icc"
${testout}_rgb_islow.ppm ${testout}_rgb_islow.jpg ${MD5_PPM_RGB_ISLOW}
${cjpeg}-${libtype}-rgb-islow)
add_bittest(${djpeg} rgb-islow
"-dct;int;-ppm;-icc;${testout}_rgb_islow.icc"
${testout}_rgb_islow.ppm ${testout}_rgb_islow.jpg
${MD5_PPM_RGB_ISLOW} ${cjpeg}-${libtype}-rgb-islow)
add_test(${djpeg}-${libtype}-rgb-islow-icc-cmp
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP}
@@ -1292,7 +1296,7 @@ foreach(libtype ${TEST_LIBTYPES})
${cjpeg}-${libtype}-3x2-float-prog)
endif()
# CC: RGB->YCC SAMP: fullsize/int FDCT: ifast ENT: prog huff
# CC: RGB->YCC SAMP: fullsize/int FDCT: ifast ENT: prog huff
add_bittest(${cjpeg} 3x2-ifast-prog "-sample;3x2;-dct;fast;-prog"
${testout}_3x2_ifast_prog.jpg ${TESTIMAGES}/testorig.ppm
${MD5_JPEG_3x2_IFAST_PROG})
@@ -1398,15 +1402,17 @@ foreach(libtype ${TEST_LIBTYPES})
# ENT: arith
if(WITH_ARITH_DEC AND sample_bits EQUAL 8)
add_bittest(${djpeg} 420-islow-ari-skip16_139
"-dct;int;-skip;16,139;-ppm" ${testout}_420_islow_ari_skip16,139.ppm
${TESTIMAGES}/testimgari.jpg ${MD5_PPM_420_ISLOW_ARI_SKIP16_139})
"-dct;int;-skip;16,139;-ppm"
${testout}_420_islow_ari_skip16,139.ppm ${TESTIMAGES}/testimgari.jpg
${MD5_PPM_420_ISLOW_ARI_SKIP16_139})
endif()
# Context rows: Yes Intra-iMCU row: No iMCU row prefetch: No
# ENT: prog huff
add_test(${cjpeg}-${libtype}-420-islow-prog
${CMAKE_CROSSCOMPILING_EMULATOR} ${cjpeg}${suffix} -dct int -prog
-outfile ${testout}_420_islow_prog.jpg ${TESTIMAGES}/testorig.ppm)
${CMAKE_CROSSCOMPILING_EMULATOR} cjpeg${suffix} -dct int -prog
-precision ${sample_bits} -outfile ${testout}_420_islow_prog.jpg
${TESTIMAGES}/testorig.ppm)
add_bittest(${djpeg} 420-islow-prog-crop62x62_71_71
"-dct;int;-crop;62x62+71+71;-ppm"
${testout}_420_islow_prog_crop62x62,71,71.ppm
@@ -1424,17 +1430,18 @@ foreach(libtype ${TEST_LIBTYPES})
# Context rows: No Intra-iMCU row: Yes ENT: huff
add_test(${cjpeg}-${libtype}-444-islow
${CMAKE_CROSSCOMPILING_EMULATOR} ${cjpeg}${suffix} -dct int -sample 1x1
-outfile ${testout}_444_islow.jpg ${TESTIMAGES}/testorig.ppm)
${CMAKE_CROSSCOMPILING_EMULATOR} cjpeg${suffix} -dct int -sample 1x1
-precision ${sample_bits} -outfile ${testout}_444_islow.jpg
${TESTIMAGES}/testorig.ppm)
add_bittest(${djpeg} 444-islow-skip1_6 "-dct;int;-skip;1,6;-ppm"
${testout}_444_islow_skip1,6.ppm ${testout}_444_islow.jpg
${MD5_PPM_444_ISLOW_SKIP1_6} ${cjpeg}-${libtype}-444-islow)
# Context rows: No Intra-iMCU row: No ENT: prog huff
add_test(${cjpeg}-${libtype}-444-islow-prog
${CMAKE_CROSSCOMPILING_EMULATOR} ${cjpeg}${suffix} -dct int -prog
-sample 1x1 -outfile ${testout}_444_islow_prog.jpg
${TESTIMAGES}/testorig.ppm)
${CMAKE_CROSSCOMPILING_EMULATOR} cjpeg${suffix} -dct int -prog
-precision ${sample_bits} -sample 1x1
-outfile ${testout}_444_islow_prog.jpg ${TESTIMAGES}/testorig.ppm)
add_bittest(${djpeg} 444-islow-prog-crop98x98_13_13
"-dct;int;-crop;98x98+13+13;-ppm"
${testout}_444_islow_prog_crop98x98,13,13.ppm
@@ -1444,9 +1451,9 @@ foreach(libtype ${TEST_LIBTYPES})
# Context rows: No Intra-iMCU row: No ENT: arith
if(WITH_ARITH_ENC AND sample_bits EQUAL 8)
add_test(${cjpeg}-${libtype}-444-islow-ari
${CMAKE_CROSSCOMPILING_EMULATOR} ${cjpeg}${suffix} -dct int -arithmetic
-sample 1x1 -outfile ${testout}_444_islow_ari.jpg
${TESTIMAGES}/testorig.ppm)
${CMAKE_CROSSCOMPILING_EMULATOR} cjpeg${suffix} -dct int -arithmetic
-sample 1x1 -precision ${sample_bits}
-outfile ${testout}_444_islow_ari.jpg ${TESTIMAGES}/testorig.ppm)
if(WITH_ARITH_DEC)
add_bittest(${djpeg} 444-islow-ari-crop37x37_0_0
"-dct;int;-crop;37x37+0+0;-ppm"
@@ -1462,7 +1469,7 @@ foreach(libtype ${TEST_LIBTYPES})
unset(EXAMPLE_12BIT_ARG)
if(sample_bits EQUAL 12)
set(EXAMPLE_12BIT_ARG "-12bit")
set(EXAMPLE_12BIT_ARG "-precision;12")
endif()
add_test(example-${sample_bits}bit-${libtype}-compress
@@ -1610,20 +1617,6 @@ if(ENABLE_STATIC)
install(PROGRAMS ${DIR}/jpegtran-static${EXE}
DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME jpegtran${EXE})
endif()
if(WITH_12BIT)
install(TARGETS jpeg12-static EXPORT ${CMAKE_PROJECT_NAME}Targets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(NOT ENABLE_SHARED)
install(PROGRAMS ${DIR}/cjpeg12-static${EXE}
DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME cjpeg12${EXE})
install(PROGRAMS ${DIR}/djpeg12-static${EXE}
DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME djpeg12${EXE})
install(PROGRAMS ${DIR}/jpeg12tran-static${EXE}
DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME jpeg12tran${EXE})
endif()
endif()
endif()
install(TARGETS rdjpgcom wrjpgcom RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
@@ -1649,10 +1642,6 @@ if(UNIX OR MINGW)
endif()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgscripts/libjpeg.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
if(WITH_12BIT)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgscripts/libjpeg12.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()
if(WITH_TURBOJPEG)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgscripts/libturbojpeg.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
@@ -1669,11 +1658,6 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/jconfig.h
${CMAKE_CURRENT_SOURCE_DIR}/jerror.h ${CMAKE_CURRENT_SOURCE_DIR}/jmorecfg.h
${CMAKE_CURRENT_SOURCE_DIR}/jpeglib.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if(WITH_12BIT)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/jpeg12lib.h
${CMAKE_CURRENT_SOURCE_DIR}/j12error.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
include(cmakescripts/BuildPackages.cmake)

View File

@@ -1,15 +1,26 @@
2.2 pre-beta
============
### Significant changes relative to 2.1.4
### Significant changes relative to 2.1.4:
1. By default, the build system now builds, packages, and tests a separate
12-bit-per-component flavor of the libjpeg API library, cjpeg, djpeg, and
jpegtran. The 12-bit-per-component libjpeg API library mangles the names of
libjpeg API functions, data types, structures, and macros to enable calling
applications to more easily support both 8-bit-per-component and
12-bit-per-component JPEG images. (Refer to [libjpeg.txt](libjpeg.txt) for
more details.) The `WITH_12BIT` CMake variable can be used to disable
1. 12-bit-per-component JPEG support is now included in the libjpeg API
library, cjpeg, djpeg, and jpegtran by default:
- The existing `data_precision` field in `jpeg_compress_struct` and
`jpeg_decompress_struct` has been repurposed to enable the creation of
12-bit-per-component JPEG images or to detect whether a 12-bit-per-component
JPEG image is being decompressed.
- New 12-bit-per-component versions of `jpeg_write_scanlines()`,
`jpeg_write_raw_data()`, `jpeg_read_scanlines()`, `jpeg_skip_scanlines()`,
`jpeg_crop_scanline()`, and `jpeg_read_raw_data()` provide interfaces for
compressing from/decompressing to 12-bit-per-component uncompressed image
buffers.
- A new cjpeg command-line argument (`-precision`) can be used to enable
the creation of 12-bit-per-component JPEG images. (djpeg and jpegtran handle
12-bit-per-component JPEG images automatically.)
Refer to [libjpeg.txt](libjpeg.txt) and [usage.txt](usage.txt) for more
details. The `WITH_12BIT` CMake variable can be used to disable
12-bit-per-component JPEG support.
2. Significantly sped up the computation of optimal Huffman tables. This

View File

@@ -16,8 +16,8 @@
#define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */
#define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */
#include "jinclude.h"
#include "jpeglibint.h"
#include "jerrorint.h" /* get library error codes too */
#include "jpeglib.h"
#include "jerror.h" /* get library error codes too */
#include "cderror.h" /* get application-specific error codes */
@@ -35,6 +35,9 @@ struct cjpeg_source_struct {
FILE *input_file;
JSAMPARRAY buffer;
#ifdef WITH_12BIT
J12SAMPARRAY buffer12;
#endif
JDIMENSION buffer_height;
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
JDIMENSION max_pixels;
@@ -75,6 +78,9 @@ struct djpeg_dest_struct {
* height is buffer_height.
*/
JSAMPARRAY buffer;
#ifdef WITH_12BIT
J12SAMPARRAY buffer12;
#endif
JDIMENSION buffer_height;
};
@@ -109,8 +115,17 @@ EXTERN(djpeg_dest_ptr) jinit_write_bmp(j_decompress_ptr cinfo, boolean is_os2,
boolean use_inversion_array);
EXTERN(cjpeg_source_ptr) jinit_read_gif(j_compress_ptr cinfo);
EXTERN(djpeg_dest_ptr) jinit_write_gif(j_decompress_ptr cinfo, boolean is_lzw);
#ifdef WITH_12BIT
EXTERN(cjpeg_source_ptr) j12init_read_gif(j_compress_ptr cinfo);
EXTERN(djpeg_dest_ptr) j12init_write_gif(j_decompress_ptr cinfo,
boolean is_lzw);
#endif
EXTERN(cjpeg_source_ptr) jinit_read_ppm(j_compress_ptr cinfo);
EXTERN(djpeg_dest_ptr) jinit_write_ppm(j_decompress_ptr cinfo);
#ifdef WITH_12BIT
EXTERN(cjpeg_source_ptr) j12init_read_ppm(j_compress_ptr cinfo);
EXTERN(djpeg_dest_ptr) j12init_write_ppm(j_decompress_ptr cinfo);
#endif
EXTERN(cjpeg_source_ptr) jinit_read_targa(j_compress_ptr cinfo);
EXTERN(djpeg_dest_ptr) jinit_write_targa(j_decompress_ptr cinfo);
@@ -127,6 +142,9 @@ EXTERN(boolean) set_sample_factors(j_compress_ptr cinfo, char *arg);
/* djpeg support routines (in rdcolmap.c) */
EXTERN(void) read_color_map(j_decompress_ptr cinfo, FILE *infile);
#ifdef WITH_12BIT
EXTERN(void) read_color_map_12(j_decompress_ptr cinfo, FILE *infile);
#endif
/* common support routines (in cdjpeg.c) */

View File

@@ -1,4 +1,4 @@
.TH CJPEG 1 "30 November 2021"
.TH CJPEG 1 "2 November 2022"
.SH NAME
cjpeg \- compress an image file to a JPEG file
.SH SYNOPSIS
@@ -149,6 +149,12 @@ about the same --- often a little smaller.
.PP
Switches for advanced users:
.TP
.BI \-precision " N"
Create JPEG file with N-bit data precision. N is 8 or 12; default is 8.
.B Caution:
12-bit JPEG is not yet widely implemented, so many decoders will be unable to
view a 12-bit JPEG file at all.
.TP
.B \-arithmetic
Use arithmetic coding.
.B Caution:

46
cjpeg.c
View File

@@ -103,11 +103,21 @@ select_file_type(j_compress_ptr cinfo, FILE *infile)
#endif
#ifdef GIF_SUPPORTED
case 'G':
return jinit_read_gif(cinfo);
#ifdef WITH_12BIT
if (cinfo->data_precision == 12)
return j12init_read_gif(cinfo);
else
#endif
return jinit_read_gif(cinfo);
#endif
#ifdef PPM_SUPPORTED
case 'P':
return jinit_read_ppm(cinfo);
#ifdef WITH_12BIT
if (cinfo->data_precision == 12)
return j12init_read_ppm(cinfo);
else
#endif
return jinit_read_ppm(cinfo);
#endif
#ifdef TARGA_SUPPORTED
case 0x00:
@@ -204,6 +214,8 @@ usage(void)
fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n");
#endif
fprintf(stderr, "Switches for advanced users:\n");
fprintf(stderr, " -precision N Create JPEG file with N-bit data precision\n");
fprintf(stderr, " (N is 8 or 12; default is 8)\n");
#ifdef C_ARITH_CODING_SUPPORTED
fprintf(stderr, " -arithmetic Use arithmetic coding\n");
#endif
@@ -382,7 +394,19 @@ parse_switches(j_compress_ptr cinfo, int argc, char **argv,
usage();
outfilename = argv[argn]; /* save it away for later use */
} else if (keymatch(arg, "progressive", 1)) {
} else if (keymatch(arg, "precision", 3)) {
/* Set data precision. */
int val;
if (++argn >= argc) /* advance to next argument */
usage();
if (sscanf(argv[argn], "%d", &val) != 1)
usage();
if (val != 8 && val != 12)
usage();
cinfo->data_precision = val;
} else if (keymatch(arg, "progressive", 3)) {
/* Select simple progressive mode. */
#ifdef C_PROGRESSIVE_SUPPORTED
simple_progressive = TRUE;
@@ -719,9 +743,19 @@ main(int argc, char **argv)
jpeg_write_icc_profile(&cinfo, icc_profile, (unsigned int)icc_len);
/* Process data */
while (cinfo.next_scanline < cinfo.image_height) {
num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
(void)jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
#ifdef WITH_12BIT
if (cinfo.data_precision == 12) {
while (cinfo.next_scanline < cinfo.image_height) {
num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
(void)jpeg12_write_scanlines(&cinfo, src_mgr->buffer12, num_scanlines);
}
} else
#endif
{
while (cinfo.next_scanline < cinfo.image_height) {
num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
(void)jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
}
}
/* Finish compression and release memory */

View File

@@ -90,10 +90,6 @@ if(WITH_JAVA)
set(INST_DEFS ${INST_DEFS} -DJAVA)
endif()
if(WITH_12BIT)
set(INST_DEFS ${INST_DEFS} -D12BIT)
endif()
if(GENERATOR_IS_MULTI_CONFIG)
set(INST_DEFS ${INST_DEFS} "-DBUILDDIR=${CMAKE_CFG_INTDIR}\\")
else()
@@ -116,13 +112,10 @@ endif()
if(WITH_TURBOJPEG)
set(TURBOJPEG_DEPEND turbojpeg turbojpeg-static tjbench)
endif()
if(WITH_12BIT)
set(12BIT_DEPEND jpeg12 jpeg12-static cjpeg12 djpeg12 jpeg12tran)
endif()
add_custom_target(installer
makensis -nocd ${INST_DEFS} installer.nsi
DEPENDS jpeg jpeg-static rdjpgcom wrjpgcom cjpeg djpeg jpegtran
${JAVA_DEPEND} ${TURBOJPEG_DEPEND} ${12BIT_DEPEND}
${JAVA_DEPEND} ${TURBOJPEG_DEPEND}
SOURCES installer.nsi)
endif() # WIN32
@@ -169,10 +162,6 @@ add_custom_target(tarball pkgscripts/maketarball
configure_file(release/libjpeg.pc.in pkgscripts/libjpeg.pc @ONLY)
if(WITH_12BIT)
configure_file(release/libjpeg12.pc.in pkgscripts/libjpeg12.pc @ONLY)
endif()
if(WITH_TURBOJPEG)
configure_file(release/libturbojpeg.pc.in pkgscripts/libturbojpeg.pc @ONLY)
endif()

31
cmyk.h
View File

@@ -16,19 +16,20 @@
#include <jinclude.h>
#define JPEG_INTERNALS
#include "jpeglibint.h"
#include <jpeglib.h>
#include "jsamplecomp.h"
/* Fully reversible */
INLINE
LOCAL(void)
rgb_to_cmyk(JSAMPLE r, JSAMPLE g, JSAMPLE b, JSAMPLE *c, JSAMPLE *m,
JSAMPLE *y, JSAMPLE *k)
rgb_to_cmyk(_JSAMPLE r, _JSAMPLE g, _JSAMPLE b,
_JSAMPLE *c, _JSAMPLE *m, _JSAMPLE *y, _JSAMPLE *k)
{
double ctmp = 1.0 - ((double)r / 255.0);
double mtmp = 1.0 - ((double)g / 255.0);
double ytmp = 1.0 - ((double)b / 255.0);
double ctmp = 1.0 - ((double)r / (double)_MAXJSAMPLE);
double mtmp = 1.0 - ((double)g / (double)_MAXJSAMPLE);
double ytmp = 1.0 - ((double)b / (double)_MAXJSAMPLE);
double ktmp = MIN(MIN(ctmp, mtmp), ytmp);
if (ktmp == 1.0) ctmp = mtmp = ytmp = 0.0;
@@ -37,10 +38,10 @@ rgb_to_cmyk(JSAMPLE r, JSAMPLE g, JSAMPLE b, JSAMPLE *c, JSAMPLE *m,
mtmp = (mtmp - ktmp) / (1.0 - ktmp);
ytmp = (ytmp - ktmp) / (1.0 - ktmp);
}
*c = (JSAMPLE)(255.0 - ctmp * 255.0 + 0.5);
*m = (JSAMPLE)(255.0 - mtmp * 255.0 + 0.5);
*y = (JSAMPLE)(255.0 - ytmp * 255.0 + 0.5);
*k = (JSAMPLE)(255.0 - ktmp * 255.0 + 0.5);
*c = (_JSAMPLE)((double)_MAXJSAMPLE - ctmp * (double)_MAXJSAMPLE + 0.5);
*m = (_JSAMPLE)((double)_MAXJSAMPLE - mtmp * (double)_MAXJSAMPLE + 0.5);
*y = (_JSAMPLE)((double)_MAXJSAMPLE - ytmp * (double)_MAXJSAMPLE + 0.5);
*k = (_JSAMPLE)((double)_MAXJSAMPLE - ktmp * (double)_MAXJSAMPLE + 0.5);
}
@@ -48,12 +49,12 @@ rgb_to_cmyk(JSAMPLE r, JSAMPLE g, JSAMPLE b, JSAMPLE *c, JSAMPLE *m,
INLINE
LOCAL(void)
cmyk_to_rgb(JSAMPLE c, JSAMPLE m, JSAMPLE y, JSAMPLE k, JSAMPLE *r, JSAMPLE *g,
JSAMPLE *b)
cmyk_to_rgb(_JSAMPLE c, _JSAMPLE m, _JSAMPLE y, _JSAMPLE k,
_JSAMPLE *r, _JSAMPLE *g, _JSAMPLE *b)
{
*r = (JSAMPLE)((double)c * (double)k / 255.0 + 0.5);
*g = (JSAMPLE)((double)m * (double)k / 255.0 + 0.5);
*b = (JSAMPLE)((double)y * (double)k / 255.0 + 0.5);
*r = (_JSAMPLE)((double)c * (double)k / (double)_MAXJSAMPLE + 0.5);
*g = (_JSAMPLE)((double)m * (double)k / (double)_MAXJSAMPLE + 0.5);
*b = (_JSAMPLE)((double)y * (double)k / (double)_MAXJSAMPLE + 0.5);
}

159
djpeg.c
View File

@@ -660,7 +660,12 @@ main(int argc, char **argv)
#endif
#ifdef GIF_SUPPORTED
case FMT_GIF:
dest_mgr = jinit_write_gif(&cinfo, TRUE);
#ifdef WITH_12BIT
if (cinfo.data_precision == 12)
dest_mgr = j12init_write_gif(&cinfo, TRUE);
else
#endif
dest_mgr = jinit_write_gif(&cinfo, TRUE);
break;
case FMT_GIF0:
dest_mgr = jinit_write_gif(&cinfo, FALSE);
@@ -668,7 +673,12 @@ main(int argc, char **argv)
#endif
#ifdef PPM_SUPPORTED
case FMT_PPM:
dest_mgr = jinit_write_ppm(&cinfo);
#ifdef WITH_12BIT
if (cinfo.data_precision == 12)
dest_mgr = j12init_write_ppm(&cinfo);
else
#endif
dest_mgr = jinit_write_ppm(&cinfo);
break;
#endif
#ifdef TARGA_SUPPORTED
@@ -707,22 +717,45 @@ main(int argc, char **argv)
(*dest_mgr->start_output) (&cinfo, dest_mgr);
cinfo.output_height = tmp;
/* Process data */
while (cinfo.output_scanline < skip_start) {
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
if ((tmp = jpeg_skip_scanlines(&cinfo, skip_end - skip_start + 1)) !=
skip_end - skip_start + 1) {
fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n",
progname, tmp, skip_end - skip_start + 1);
exit(EXIT_FAILURE);
}
while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
#ifdef WITH_12BIT
if (cinfo.data_precision == 12) {
/* Process data */
while (cinfo.output_scanline < skip_start) {
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
if ((tmp = jpeg12_skip_scanlines(&cinfo, skip_end - skip_start + 1)) !=
skip_end - skip_start + 1) {
fprintf(stderr, "%s: jpeg12_skip_scanlines() returned %u rather than %u\n",
progname, tmp, skip_end - skip_start + 1);
exit(EXIT_FAILURE);
}
while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
} else
#endif
{
/* Process data */
while (cinfo.output_scanline < skip_start) {
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
if ((tmp = jpeg_skip_scanlines(&cinfo, skip_end - skip_start + 1)) !=
skip_end - skip_start + 1) {
fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n",
progname, tmp, skip_end - skip_start + 1);
exit(EXIT_FAILURE);
}
while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
}
/* Decompress a subregion */
@@ -739,7 +772,12 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
jpeg_crop_scanline(&cinfo, &crop_x, &crop_width);
#ifdef WITH_12BIT
if (cinfo.data_precision == 12)
jpeg12_crop_scanline(&cinfo, &crop_x, &crop_width);
else
#endif
jpeg_crop_scanline(&cinfo, &crop_x, &crop_width);
if (dest_mgr->calc_buffer_dimensions)
(*dest_mgr->calc_buffer_dimensions) (&cinfo, dest_mgr);
else
@@ -753,24 +791,49 @@ main(int argc, char **argv)
(*dest_mgr->start_output) (&cinfo, dest_mgr);
cinfo.output_height = tmp;
/* Process data */
if ((tmp = jpeg_skip_scanlines(&cinfo, crop_y)) != crop_y) {
fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n",
progname, tmp, crop_y);
exit(EXIT_FAILURE);
}
while (cinfo.output_scanline < crop_y + crop_height) {
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
if ((tmp =
jpeg_skip_scanlines(&cinfo,
cinfo.output_height - crop_y - crop_height)) !=
cinfo.output_height - crop_y - crop_height) {
fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n",
progname, tmp, cinfo.output_height - crop_y - crop_height);
exit(EXIT_FAILURE);
#ifdef WITH_12BIT
if (cinfo.data_precision == 12) {
/* Process data */
if ((tmp = jpeg12_skip_scanlines(&cinfo, crop_y)) != crop_y) {
fprintf(stderr, "%s: jpeg12_skip_scanlines() returned %u rather than %u\n",
progname, tmp, crop_y);
exit(EXIT_FAILURE);
}
while (cinfo.output_scanline < crop_y + crop_height) {
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
if ((tmp =
jpeg12_skip_scanlines(&cinfo, cinfo.output_height - crop_y -
crop_height)) !=
cinfo.output_height - crop_y - crop_height) {
fprintf(stderr, "%s: jpeg12_skip_scanlines() returned %u rather than %u\n",
progname, tmp, cinfo.output_height - crop_y - crop_height);
exit(EXIT_FAILURE);
}
} else
#endif
{
/* Process data */
if ((tmp = jpeg_skip_scanlines(&cinfo, crop_y)) != crop_y) {
fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n",
progname, tmp, crop_y);
exit(EXIT_FAILURE);
}
while (cinfo.output_scanline < crop_y + crop_height) {
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
if ((tmp =
jpeg_skip_scanlines(&cinfo,
cinfo.output_height - crop_y - crop_height)) !=
cinfo.output_height - crop_y - crop_height) {
fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n",
progname, tmp, cinfo.output_height - crop_y - crop_height);
exit(EXIT_FAILURE);
}
}
/* Normal full-image decompress */
@@ -778,11 +841,23 @@ main(int argc, char **argv)
/* Write output file header */
(*dest_mgr->start_output) (&cinfo, dest_mgr);
/* Process data */
while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
#ifdef WITH_12BIT
if (cinfo.data_precision == 12) {
/* Process data */
while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
} else
#endif
{
/* Process data */
while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
}
}

378
example.c
View File

@@ -47,8 +47,6 @@
#include "jpeglib.h"
#include "jerror.h"
#include "jpeg12lib.h"
#include "j12error.h"
/*
* <setjmp.h> is used for the optional error recovery mechanism shown in
@@ -72,10 +70,10 @@
*
* The standard input image format is a rectangular array of pixels, with
* each pixel having the same number of "component" values (color channels).
* Each pixel row is an array of JSAMPLEs (which typically are unsigned chars).
* If you are working with color data, then the color values for each pixel
* must be adjacent in the row; for example, R,G,B,R,G,B,R,G,B,... for 24-bit
* RGB color.
* Each pixel row is an array of JSAMPLEs (which typically are unsigned chars)
* or J12SAMPLEs (which typically are shorts). If you are working with color
* data, then the color values for each pixel must be adjacent in the row; for
* example, R,G,B,R,G,B,R,G,B,... for 24-bit RGB color.
*
* For this example, we'll assume that this data structure matches the way
* our application has stored the image in memory, so we can just pass a
@@ -88,12 +86,12 @@
/*
* Sample routine for JPEG compression with 8-bit data precision. We assume
* that the target file name and a compression quality factor are passed in.
* Sample routine for JPEG compression. We assume that the target file name,
* a compression quality factor, and a data precision are passed in.
*/
METHODDEF(void)
write_JPEG_file(char *filename, int quality)
write_JPEG_file(char *filename, int quality, int data_precision)
{
/* This struct contains the JPEG compression parameters and pointers to
* working space (which is allocated as needed by the JPEG library).
@@ -113,8 +111,15 @@ write_JPEG_file(char *filename, int quality)
struct jpeg_error_mgr jerr;
/* More stuff */
FILE *outfile; /* target file */
JSAMPARRAY image_buffer; /* Points to large array of R,G,B-order data */
JSAMPARRAY image_buffer = NULL;
/* Points to large array of R,G,B-order data */
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
#ifdef WITH_12BIT
J12SAMPARRAY image_buffer12 = NULL;
/* Points to large array of R,G,B-order 12-bit
data */
J12SAMPROW row_pointer12[1]; /* pointer to J12SAMPLE row[s] */
#endif
int row_stride; /* physical row width in image buffer */
int row, col;
@@ -150,6 +155,7 @@ write_JPEG_file(char *filename, int quality)
cinfo.image_height = HEIGHT;
cinfo.input_components = 3; /* # of color components per pixel */
cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
cinfo.data_precision = data_precision; /* data precision of input image */
/* Now use the library's routine to set default compression parameters.
* (You must set at least cinfo.in_color_space before calling this,
* since the defaults depend on the source color space.)
@@ -171,25 +177,45 @@ write_JPEG_file(char *filename, int quality)
/* Step 5: allocate and initialize image buffer */
row_stride = WIDTH * 3; /* JSAMPLEs per row in image_buffer */
row_stride = WIDTH * 3; /* J[12]SAMPLEs per row in image_buffer */
/* Make a sample array that will go away when done with image. Note that,
* for the purposes of this example, we could also create a one-row-high
* sample array and initialize it for each successive scanline written in the
* scanline loop below.
*/
image_buffer = (*cinfo.mem->alloc_sarray)
((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, HEIGHT);
#ifdef WITH_12BIT
if (cinfo.data_precision == 12) {
image_buffer12 = (J12SAMPARRAY)(*cinfo.mem->alloc_sarray)
((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, HEIGHT);
/* Initialize image buffer with a repeating pattern */
for (row = 0; row < HEIGHT; row++) {
for (col = 0; col < WIDTH; col++) {
image_buffer[row][col * 3] =
(col * (MAXJSAMPLE + 1) / WIDTH) % (MAXJSAMPLE + 1);
image_buffer[row][col * 3 + 1] =
(row * (MAXJSAMPLE + 1) / HEIGHT) % (MAXJSAMPLE + 1);
image_buffer[row][col * 3 + 2] =
(row * (MAXJSAMPLE + 1) / HEIGHT + col * (MAXJSAMPLE + 1) / WIDTH) %
(MAXJSAMPLE + 1);
/* Initialize image buffer with a repeating pattern */
for (row = 0; row < HEIGHT; row++) {
for (col = 0; col < WIDTH; col++) {
image_buffer12[row][col * 3] =
(col * (MAXJ12SAMPLE + 1) / WIDTH) % (MAXJ12SAMPLE + 1);
image_buffer12[row][col * 3 + 1] =
(row * (MAXJ12SAMPLE + 1) / HEIGHT) % (MAXJ12SAMPLE + 1);
image_buffer12[row][col * 3 + 2] =
(row * (MAXJ12SAMPLE + 1) / HEIGHT +
col * (MAXJ12SAMPLE + 1) / WIDTH) % (MAXJ12SAMPLE + 1);
}
}
} else
#endif
{
image_buffer = (*cinfo.mem->alloc_sarray)
((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, HEIGHT);
for (row = 0; row < HEIGHT; row++) {
for (col = 0; col < WIDTH; col++) {
image_buffer[row][col * 3] =
(col * (MAXJSAMPLE + 1) / WIDTH) % (MAXJSAMPLE + 1);
image_buffer[row][col * 3 + 1] =
(row * (MAXJSAMPLE + 1) / HEIGHT) % (MAXJSAMPLE + 1);
image_buffer[row][col * 3 + 2] =
(row * (MAXJSAMPLE + 1) / HEIGHT + col * (MAXJSAMPLE + 1) / WIDTH) %
(MAXJSAMPLE + 1);
}
}
}
@@ -201,13 +227,27 @@ write_JPEG_file(char *filename, int quality)
* To keep things simple, we pass one scanline per call; you can pass
* more if you wish, though.
*/
while (cinfo.next_scanline < cinfo.image_height) {
/* jpeg_write_scanlines expects an array of pointers to scanlines.
* Here the array is only one element long, but you could pass
* more than one scanline at a time if that's more convenient.
*/
row_pointer[0] = image_buffer[cinfo.next_scanline];
(void)jpeg_write_scanlines(&cinfo, row_pointer, 1);
#ifdef WITH_12BIT
if (cinfo.data_precision == 12) {
while (cinfo.next_scanline < cinfo.image_height) {
/* jpeg12_write_scanlines expects an array of pointers to scanlines.
* Here the array is only one element long, but you could pass
* more than one scanline at a time if that's more convenient.
*/
row_pointer12[0] = image_buffer12[cinfo.next_scanline];
(void)jpeg12_write_scanlines(&cinfo, row_pointer12, 1);
}
} else
#endif
{
while (cinfo.next_scanline < cinfo.image_height) {
/* jpeg_write_scanlines expects an array of pointers to scanlines.
* Here the array is only one element long, but you could pass
* more than one scanline at a time if that's more convenient.
*/
row_pointer[0] = image_buffer[cinfo.next_scanline];
(void)jpeg_write_scanlines(&cinfo, row_pointer, 1);
}
}
/* Step 7: Finish compression */
@@ -254,74 +294,6 @@ write_JPEG_file(char *filename, int quality)
*/
/*
* Sample routine for JPEG compression with 12-bit data precision. We assume
* that the target file name and a compression quality factor are passed in.
*/
#ifdef WITH_12BIT
METHODDEF(void)
write_JPEG12_file(char *filename, int quality)
{
struct jpeg12_compress_struct cinfo;
struct jpeg12_error_mgr jerr;
FILE *outfile;
J12SAMPARRAY image_buffer;
J12SAMPROW row_pointer[1];
int row_stride;
int row, col;
cinfo.err = jpeg12_std_error(&jerr);
jpeg12_create_compress(&cinfo);
if ((outfile = fopen(filename, "wb")) == NULL)
J12ERREXIT(&cinfo, JERR_FILE_WRITE);
jpeg12_stdio_dest(&cinfo, outfile);
cinfo.image_width = WIDTH;
cinfo.image_height = HEIGHT;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg12_set_defaults(&cinfo);
jpeg12_set_quality(&cinfo, quality, TRUE);
cinfo.comp_info[0].h_samp_factor = cinfo.comp_info[0].v_samp_factor = 1;
jpeg12_start_compress(&cinfo, TRUE);
row_stride = WIDTH * 3;
image_buffer = (*cinfo.mem->alloc_sarray)
((j12_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, HEIGHT);
/* Initialize image buffer with a repeating pattern */
for (row = 0; row < HEIGHT; row++) {
for (col = 0; col < WIDTH; col++) {
image_buffer[row][col * 3] =
(col * (MAXJ12SAMPLE + 1) / WIDTH) % (MAXJ12SAMPLE + 1);
image_buffer[row][col * 3 + 1] =
(row * (MAXJ12SAMPLE + 1) / HEIGHT) % (MAXJ12SAMPLE + 1);
image_buffer[row][col * 3 + 2] =
(row * (MAXJ12SAMPLE + 1) / HEIGHT +
col * (MAXJ12SAMPLE + 1) / WIDTH) % (MAXJ12SAMPLE + 1);
}
}
row_stride = WIDTH * 3;
while (cinfo.next_scanline < cinfo.image_height) {
row_pointer[0] = image_buffer[cinfo.next_scanline];
(void)jpeg12_write_scanlines(&cinfo, row_pointer, 1);
}
jpeg12_finish_compress(&cinfo);
fclose(outfile);
jpeg12_destroy_compress(&cinfo);
}
#endif
/******************** JPEG DECOMPRESSION SAMPLE INTERFACE *******************/
@@ -333,10 +305,11 @@ write_JPEG12_file(char *filename, int quality)
* Just to make this example a little different from the first one, we'll
* assume that we do not intend to put the whole image into an in-memory
* buffer, but to send it line-by-line someplace else. We need a one-
* scanline-high JSAMPLE array as a work buffer, and we will let the JPEG
* memory manager allocate it for us. This approach is actually quite useful
* because we don't need to remember to deallocate the buffer separately: it
* will go away automatically when the JPEG object is cleaned up.
* scanline-high JSAMPLE or J12SAMPLE array as a work buffer, and we will let
* the JPEG memory manager allocate it for us. This approach is actually quite
* useful because we don't need to remember to deallocate the buffer
* separately: it will go away automatically when the JPEG object is cleaned
* up.
*/
@@ -394,9 +367,8 @@ METHODDEF(int) do_read_JPEG_file(struct jpeg_decompress_struct *cinfo,
char *infilename, char *outfilename);
/*
* Sample routine for JPEG decompression with 8-bit data precision. We assume
* that the source file name is passed in. We want to return 1 on success, 0
* on error.
* Sample routine for JPEG decompression. We assume that the source file name
* is passed in. We want to return 1 on success, 0 on error.
*/
METHODDEF(int)
@@ -431,6 +403,10 @@ do_read_JPEG_file(struct jpeg_decompress_struct *cinfo, char *infilename,
FILE *infile; /* source file */
FILE *outfile; /* output file */
JSAMPARRAY buffer; /* Output row buffer */
#ifdef WITH_12BIT
J12SAMPARRAY buffer12; /* 12-bit output row buffer */
int col;
#endif
int row_stride; /* physical row width in output buffer */
/* In this example we want to open the input and output files before doing
@@ -450,8 +426,6 @@ do_read_JPEG_file(struct jpeg_decompress_struct *cinfo, char *infilename,
fclose(infile);
return 0;
}
/* emit header for raw PPM format */
fprintf(outfile, "P6\n%d %d\n%d\n", WIDTH, HEIGHT, MAXJSAMPLE);
/* Step 1: allocate and initialize JPEG decompression object */
@@ -484,6 +458,14 @@ do_read_JPEG_file(struct jpeg_decompress_struct *cinfo, char *infilename,
* See libjpeg.txt for more info.
*/
/* emit header for raw PPM format */
#ifdef WITH_12BIT
fprintf(outfile, "P6\n%d %d\n%d\n", WIDTH, HEIGHT,
cinfo->data_precision == 12 ? MAXJ12SAMPLE : MAXJSAMPLE);
#else
fprintf(outfile, "P6\n%d %d\n%d\n", WIDTH, HEIGHT, MAXJSAMPLE);
#endif
/* Step 4: set parameters for decompression */
/* In this example, we don't need to change any of the defaults set by
@@ -503,11 +485,17 @@ do_read_JPEG_file(struct jpeg_decompress_struct *cinfo, char *infilename,
* if we asked for color quantization.
* In this example, we need to make an output work buffer of the right size.
*/
/* JSAMPLEs per row in output buffer */
/* Samples per row in output buffer */
row_stride = cinfo->output_width * cinfo->output_components;
/* Make a one-row-high sample array that will go away when done with image */
buffer = (*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE, row_stride, 1);
#ifdef WITH_12BIT
if (cinfo->data_precision == 12)
buffer12 = (J12SAMPARRAY)(*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE, row_stride, 1);
else
#endif
buffer = (*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE, row_stride, 1);
/* Step 6: while (scan lines remain to be read) */
/* jpeg_read_scanlines(...); */
@@ -515,13 +503,31 @@ do_read_JPEG_file(struct jpeg_decompress_struct *cinfo, char *infilename,
/* Here we use the library's state variable cinfo->output_scanline as the
* loop counter, so that we don't have to keep track ourselves.
*/
while (cinfo->output_scanline < cinfo->output_height) {
/* jpeg_read_scanlines expects an array of pointers to scanlines.
* Here the array is only one element long, but you could ask for
* more than one scanline at a time if that's more convenient.
*/
(void)jpeg_read_scanlines(cinfo, buffer, 1);
fwrite(buffer[0], 1, row_stride, outfile);
#ifdef WITH_12BIT
if (cinfo->data_precision == 12) {
while (cinfo->output_scanline < cinfo->output_height) {
/* jpeg12_read_scanlines expects an array of pointers to scanlines.
* Here the array is only one element long, but you could ask for
* more than one scanline at a time if that's more convenient.
*/
(void)jpeg12_read_scanlines(cinfo, buffer12, 1);
/* Swap MSB and LSB in each sample */
for (col = 0; col < row_stride; col++)
buffer12[0][col] = ((buffer12[0][col] & 0xFF) << 8) |
((buffer12[0][col] >> 8) & 0xFF);
fwrite(buffer12[0], 1, row_stride * sizeof(J12SAMPLE), outfile);
}
} else
#endif
{
while (cinfo->output_scanline < cinfo->output_height) {
/* jpeg_read_scanlines expects an array of pointers to scanlines.
* Here the array is only one element long, but you could ask for
* more than one scanline at a time if that's more convenient.
*/
(void)jpeg_read_scanlines(cinfo, buffer, 1);
fwrite(buffer[0], 1, row_stride, outfile);
}
}
/* Step 7: Finish decompression */
@@ -579,108 +585,6 @@ do_read_JPEG_file(struct jpeg_decompress_struct *cinfo, char *infilename,
*/
#ifdef WITH_12BIT
struct my12_error_mgr {
struct jpeg12_error_mgr pub;
jmp_buf setjmp_buffer;
};
typedef struct my12_error_mgr *my12_error_ptr;
METHODDEF(void)
my12_error_exit(j12_common_ptr cinfo)
{
my12_error_ptr myerr = (my12_error_ptr)cinfo->err;
(*cinfo->err->output_message) (cinfo);
longjmp(myerr->setjmp_buffer, 1);
}
METHODDEF(int) do_read_JPEG12_file(struct jpeg12_decompress_struct *cinfo,
char *infilename, char *outfilename);
/*
* Sample routine for JPEG decompression with 12-bit data precision. We assume
* that the source file name is passed in. We want to return 1 on success, 0
* on error.
*/
METHODDEF(int)
read_JPEG12_file(char *infilename, char *outfilename)
{
struct jpeg12_decompress_struct cinfo;
return do_read_JPEG12_file(&cinfo, infilename, outfilename);
}
METHODDEF(int)
do_read_JPEG12_file(struct jpeg12_decompress_struct *cinfo, char *infilename,
char *outfilename)
{
struct my12_error_mgr jerr;
FILE *infile;
FILE *outfile;
J12SAMPARRAY buffer;
int row_stride;
int col;
if ((infile = fopen(infilename, "rb")) == NULL) {
fprintf(stderr, "can't open %s\n", infilename);
return 0;
}
if ((outfile = fopen(outfilename, "wb")) == NULL) {
fprintf(stderr, "can't open %s\n", outfilename);
fclose(infile);
return 0;
}
fprintf(outfile, "P6\n%d %d\n%d\n", WIDTH, HEIGHT, MAXJ12SAMPLE);
cinfo->err = jpeg12_std_error(&jerr.pub);
jerr.pub.error_exit = my12_error_exit;
if (setjmp(jerr.setjmp_buffer)) {
jpeg12_destroy_decompress(cinfo);
fclose(infile);
fclose(outfile);
return 0;
}
jpeg12_create_decompress(cinfo);
jpeg12_stdio_src(cinfo, infile);
(void)jpeg12_read_header(cinfo, TRUE);
(void)jpeg12_start_decompress(cinfo);
row_stride = cinfo->output_width * cinfo->output_components;
buffer = (*cinfo->mem->alloc_sarray)
((j12_common_ptr)cinfo, JPOOL_IMAGE, row_stride, 1);
while (cinfo->output_scanline < cinfo->output_height) {
(void)jpeg12_read_scanlines(cinfo, buffer, 1);
/* Swap MSB and LSB in each sample */
for (col = 0; col < row_stride; col++)
buffer[0][col] = ((buffer[0][col] & 0xFF) << 8) |
((buffer[0][col] >> 8) & 0xFF);
fwrite(buffer[0], 1, row_stride * sizeof(J12SAMPLE), outfile);
}
(void)jpeg12_finish_decompress(cinfo);
jpeg12_destroy_decompress(cinfo);
fclose(infile);
fclose(outfile);
return 1;
}
#endif
LOCAL(void)
usage(const char *progname)
{
@@ -690,7 +594,8 @@ usage(const char *progname)
progname);
fprintf(stderr, "Switches (names may be abbreviated):\n");
#ifdef WITH_12BIT
fprintf(stderr, " -12bit Compress/decompress JPEG file with 12-bit data precision\n");
fprintf(stderr, " -precision N Create JPEG file with N-bit data precision\n");
fprintf(stderr, " (N is 8 or 12; default is 8)\n");
#endif
fprintf(stderr, " -quality N Compression quality (0..100; 5-95 is most useful range,\n");
fprintf(stderr, " default is 75)\n");
@@ -709,9 +614,7 @@ int
main(int argc, char **argv)
{
int argn, quality = 75;
#ifdef WITH_12BIT
int _12bit = 0;
#endif
int data_precision = 8;
EXAMPLE_MODE mode = -1;
char *arg, *filename = NULL;
@@ -735,9 +638,14 @@ main(int argc, char **argv)
arg++; /* advance past switch marker character */
#ifdef WITH_12BIT
if (!strncasecmp(arg, "1", 1))
_12bit = 1;
else
if (!strncasecmp(arg, "p", 1)) {
/* Set data precision. */
if (++argn >= argc) /* advance to next argument */
usage(argv[0]);
if (sscanf(argv[argn], "%d", &data_precision) < 1 ||
(data_precision != 8 && data_precision != 12))
usage(argv[0]);
} else
#endif
if (!strncasecmp(arg, "q", 1)) {
/* Quality rating (quantization table scaling factor). */
@@ -754,23 +662,13 @@ main(int argc, char **argv)
if (!filename)
usage(argv[0]);
if (mode == COMPRESS) {
#ifdef WITH_12BIT
if (_12bit)
write_JPEG12_file(filename, quality);
else
#endif
write_JPEG_file(filename, quality);
} else if (mode == DECOMPRESS) {
if (mode == COMPRESS)
write_JPEG_file(filename, quality, data_precision);
else if (mode == DECOMPRESS) {
if (argc - argn < 2)
usage(argv[0]);
#ifdef WITH_12BIT
if (_12bit)
read_JPEG12_file(argv[argn], argv[argn + 1]);
else
#endif
read_JPEG_file(argv[argn], argv[argn + 1]);
read_JPEG_file(argv[argn], argv[argn + 1]);
}
return 0;

View File

@@ -33,6 +33,17 @@ target_link_libraries(cjpeg_fuzzer${FUZZER_SUFFIX} ${FUZZ_LIBRARY} jpeg-static)
install(TARGETS cjpeg_fuzzer${FUZZER_SUFFIX} RUNTIME DESTINATION
${FUZZ_BINDIR})
if(WITH_12BIT)
add_executable(cjpeg12_fuzzer${FUZZER_SUFFIX} cjpeg12.cc ../cdjpeg.c
../rdbmp.c ../rdgif.c ../rdppm.c ../rdswitch.c ../rdtarga.c)
set_property(TARGET cjpeg12_fuzzer${FUZZER_SUFFIX} PROPERTY COMPILE_FLAGS
${COMPILE_FLAGS})
target_link_libraries(cjpeg12_fuzzer${FUZZER_SUFFIX} ${FUZZ_LIBRARY}
jpeg-static)
install(TARGETS cjpeg12_fuzzer${FUZZER_SUFFIX} RUNTIME DESTINATION
${FUZZ_BINDIR})
endif()
macro(add_fuzz_target target source_file)
add_executable(${target}_fuzzer${FUZZER_SUFFIX} ${source_file})
target_link_libraries(${target}_fuzzer${FUZZER_SUFFIX} ${FUZZ_LIBRARY}

View File

@@ -18,6 +18,7 @@ make "-j$(nproc)" "--load-average=$(nproc)"
make install
cp $SRC/compress_fuzzer_seed_corpus.zip $OUT/cjpeg_fuzzer${FUZZER_SUFFIX}_seed_corpus.zip
cp $SRC/compress_fuzzer_seed_corpus.zip $OUT/cjpeg12_fuzzer${FUZZER_SUFFIX}_seed_corpus.zip
cp $SRC/compress_fuzzer_seed_corpus.zip $OUT/compress_fuzzer${FUZZER_SUFFIX}_seed_corpus.zip
cp $SRC/compress_fuzzer_seed_corpus.zip $OUT/compress_yuv_fuzzer${FUZZER_SUFFIX}_seed_corpus.zip
cp $SRC/decompress_fuzzer_seed_corpus.zip $OUT/libjpeg_turbo_fuzzer${FUZZER_SUFFIX}_seed_corpus.zip

90
fuzz/cjpeg12.cc Normal file
View File

@@ -0,0 +1,90 @@
/*
* Copyright (C)2021-2022 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the libjpeg-turbo Project nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* This fuzz target wraps cjpeg in order to test esoteric compression options
as well as the GIF and Targa readers. */
#define main cjpeg_main
#define CJPEG_FUZZER
extern "C" {
#include "../cjpeg.c"
}
#undef main
#undef CJPEG_FUZZER
#include <stdint.h>
#include <unistd.h>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
char filename[FILENAME_MAX] = { 0 };
char *argv1[] = {
(char *)"cjpeg", (char *)"-precision", (char *)"12",
(char *)"-dct", (char *)"int", (char *)"-memdst",
(char *)"-quality", (char *)"100,99,98", (char *)"-restart", (char *)"2",
(char *)"-sample", (char *)"4x1,2x2,1x2", (char *)"-ppm", NULL
};
char *argv2[] = {
(char *)"cjpeg", (char *)"-precision", (char *)"12",
(char *)"-dct", (char *)"fast", (char *)"-memdst",
(char *)"-quality", (char *)"90,80,70", (char *)"-rgb",
(char *)"-sample", (char *)"2x1", (char *)"-smooth", (char *)"50",
(char *)"-gif", NULL
};
int fd = -1;
#if defined(__has_feature) && __has_feature(memory_sanitizer)
char env[18] = "JSIMD_FORCENONE=1";
/* The libjpeg-turbo SIMD extensions produce false positives with
MemorySanitizer. */
putenv(env);
#endif
snprintf(filename, FILENAME_MAX, "/tmp/libjpeg-turbo_cjpeg12_fuzz.XXXXXX");
if ((fd = mkstemp(filename)) < 0 || write(fd, data, size) < 0)
goto bailout;
argv1[12] = argv2[13] = filename;
cjpeg_main(13, argv1);
cjpeg_main(14, argv2);
argv1[12] = argv2[13] = NULL;
argv1[11] = argv2[12] = filename;
cjpeg_main(12, argv1);
cjpeg_main(13, argv2);
bailout:
if (fd >= 0) {
close(fd);
if (strlen(filename) > 0) unlink(filename);
}
return 0;
}

View File

@@ -1,331 +0,0 @@
/*
* j12error.h
*
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1997, Thomas G. Lane.
* Modified 1997-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications:
* Copyright (C) 2014, 2017, 2021-2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
* This file defines the error and message codes for the JPEG library.
* Edit this file to add new codes, or to translate the message strings to
* some other language.
* A set of error-reporting macros are defined too. Some applications using
* the JPEG library may wish to include this file to get the error codes
* and/or the macros.
*/
/*
* To define the enum list of message codes, include this file without
* defining macro JMESSAGE. To create a message string table, include it
* again with a suitable JMESSAGE definition (see jerror.c for an example).
*/
#ifndef JMESSAGE
#if !defined(JERROR_H) && !defined(J12ERROR_H)
/* First time through, define the enum list */
#define JMAKE_ENUM_LIST
#else
/* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */
#define JMESSAGE(code, string)
#endif /* JERROR_H */
#endif /* JMESSAGE */
#ifdef JMAKE_ENUM_LIST
typedef enum {
#define JMESSAGE(code, string) code,
#endif /* JMAKE_ENUM_LIST */
JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
/* For maintenance convenience, list is alphabetical by message code name */
#if JPEG_LIB_VERSION < 70
JMESSAGE(JERR_ARITH_NOTIMPL, "Sorry, arithmetic coding is not implemented")
#endif
JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
#if JPEG_LIB_VERSION >= 70
JMESSAGE(JERR_BAD_CROP_SPEC, "Invalid crop request")
#endif
JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
#if JPEG_LIB_VERSION >= 70
JMESSAGE(JERR_BAD_DROP_SAMPLING,
"Component index %d: mismatching sampling ratio %d:%d, %d:%d, %c")
#endif
JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
JMESSAGE(JERR_BAD_LIB_VERSION,
"Wrong JPEG library version: library is %d, caller expects %d")
JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
JMESSAGE(JERR_BAD_PROGRESSION,
"Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
JMESSAGE(JERR_BAD_PROG_SCRIPT,
"Invalid progressive parameters at scan script entry %d")
JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
JMESSAGE(JERR_BAD_STRUCT_SIZE,
"JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
JMESSAGE(JERR_FILE_READ, "Input file read error")
JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
"Cannot transcode due to multiple use of quantization table %d")
JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
JMESSAGE(JERR_NOTIMPL, "Requested features are incompatible")
JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
#if JPEG_LIB_VERSION >= 70
JMESSAGE(JERR_NO_ARITH_TABLE, "Arithmetic table 0x%02x was not defined")
#endif
JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
JMESSAGE(JERR_QUANT_COMPONENTS,
"Cannot quantize more than %d color components")
JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
JMESSAGE(JERR_TFILE_WRITE,
"Write failed on temporary file --- out of disk space?")
JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT_SHORT)
JMESSAGE(JMSG_VERSION, JVERSION)
JMESSAGE(JTRC_16BIT_TABLES,
"Caution: quantization tables are too coarse for baseline JPEG")
JMESSAGE(JTRC_ADOBE,
"Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
JMESSAGE(JTRC_EOI, "End Of Image")
JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
"Warning: thumbnail image size does not match data length %u")
JMESSAGE(JTRC_JFIF_EXTENSION, "JFIF extension marker: type 0x%02x, length %u")
JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
JMESSAGE(JTRC_RST, "RST%d")
JMESSAGE(JTRC_SMOOTH_NOTIMPL,
"Smoothing not supported with nonstandard sampling ratios")
JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
JMESSAGE(JTRC_SOI, "Start of Image")
JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
JMESSAGE(JTRC_THUMB_JPEG,
"JFIF extension marker: JPEG-compressed thumbnail image, length %u")
JMESSAGE(JTRC_THUMB_PALETTE,
"JFIF extension marker: palette thumbnail image, length %u")
JMESSAGE(JTRC_THUMB_RGB,
"JFIF extension marker: RGB thumbnail image, length %u")
JMESSAGE(JTRC_UNKNOWN_IDS,
"Unrecognized component IDs %d %d %d, assuming YCbCr")
JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
#if JPEG_LIB_VERSION >= 70
JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code")
#endif
JMESSAGE(JWRN_BOGUS_PROGRESSION,
"Inconsistent progression sequence for component %d coefficient %d")
JMESSAGE(JWRN_EXTRANEOUS_DATA,
"Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
JMESSAGE(JWRN_MUST_RESYNC,
"Corrupt JPEG data: found marker 0x%02x instead of RST%d")
JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
#if JPEG_LIB_VERSION < 70
JMESSAGE(JERR_BAD_CROP_SPEC, "Invalid crop request")
#if defined(C_ARITH_CODING_SUPPORTED) || defined(D_ARITH_CODING_SUPPORTED)
JMESSAGE(JERR_NO_ARITH_TABLE, "Arithmetic table 0x%02x was not defined")
JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code")
#endif
#endif
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
JMSG_LASTMSGCODE
} J_MESSAGE_CODE;
#undef JMAKE_ENUM_LIST
#endif /* JMAKE_ENUM_LIST */
/* Zap JMESSAGE macro so that future re-inclusions do nothing by default */
#undef JMESSAGE
#ifndef J12ERROR_H
#define J12ERROR_H
/* Macros to simplify using the error and trace message stuff */
/* The first parameter is either type of cinfo pointer */
/* Fatal errors (print message and exit) */
#define J12ERREXIT(cinfo, code) \
((cinfo)->err->msg_code = (code), \
(*(cinfo)->err->error_exit) ((j12_common_ptr)(cinfo)))
#define J12ERREXIT1(cinfo, code, p1) \
((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[0] = (p1), \
(*(cinfo)->err->error_exit) ((j12_common_ptr)(cinfo)))
#define J12ERREXIT2(cinfo, code, p1, p2) \
((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[0] = (p1), \
(cinfo)->err->msg_parm.i[1] = (p2), \
(*(cinfo)->err->error_exit) ((j12_common_ptr)(cinfo)))
#define J12ERREXIT3(cinfo, code, p1, p2, p3) \
((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->error_exit) ((j12_common_ptr)(cinfo)))
#define J12ERREXIT4(cinfo, code, p1, p2, p3, p4) \
((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->error_exit) ((j12_common_ptr)(cinfo)))
#define J12ERREXIT6(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) ((j12_common_ptr)(cinfo)))
#define J12ERREXITS(cinfo, code, str) \
((cinfo)->err->msg_code = (code), \
strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
(cinfo)->err->msg_parm.s[JMSG_STR_PARM_MAX - 1] = '\0', \
(*(cinfo)->err->error_exit) ((j12_common_ptr)(cinfo)))
#define MAKESTMT(stuff) do { stuff } while (0)
/* Nonfatal errors (we can keep going, but the data is probably corrupt) */
#define J12WARNMS(cinfo, code) \
((cinfo)->err->msg_code = (code), \
(*(cinfo)->err->emit_message) ((j12_common_ptr)(cinfo), -1))
#define J12WARNMS1(cinfo, code, p1) \
((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[0] = (p1), \
(*(cinfo)->err->emit_message) ((j12_common_ptr)(cinfo), -1))
#define J12WARNMS2(cinfo, code, p1, p2) \
((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[0] = (p1), \
(cinfo)->err->msg_parm.i[1] = (p2), \
(*(cinfo)->err->emit_message) ((j12_common_ptr)(cinfo), -1))
/* Informational/debugging messages */
#define J12TRACEMS(cinfo, lvl, code) \
((cinfo)->err->msg_code = (code), \
(*(cinfo)->err->emit_message) ((j12_common_ptr)(cinfo), (lvl)))
#define J12TRACEMS1(cinfo, lvl, code, p1) \
((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[0] = (p1), \
(*(cinfo)->err->emit_message) ((j12_common_ptr)(cinfo), (lvl)))
#define J12TRACEMS2(cinfo, lvl, code, p1, p2) \
((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[0] = (p1), \
(cinfo)->err->msg_parm.i[1] = (p2), \
(*(cinfo)->err->emit_message) ((j12_common_ptr)(cinfo), (lvl)))
#define J12TRACEMS3(cinfo, lvl, code, p1, p2, p3) \
MAKESTMT(int *_mp = (cinfo)->err->msg_parm.i; \
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
(cinfo)->err->msg_code = (code); \
(*(cinfo)->err->emit_message) ((j12_common_ptr)(cinfo), (lvl)); )
#define J12TRACEMS4(cinfo, lvl, code, p1, p2, p3, p4) \
MAKESTMT(int *_mp = (cinfo)->err->msg_parm.i; \
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
(cinfo)->err->msg_code = (code); \
(*(cinfo)->err->emit_message) ((j12_common_ptr)(cinfo), (lvl)); )
#define J12TRACEMS5(cinfo, lvl, code, p1, p2, p3, p4, p5) \
MAKESTMT(int *_mp = (cinfo)->err->msg_parm.i; \
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
_mp[4] = (p5); \
(cinfo)->err->msg_code = (code); \
(*(cinfo)->err->emit_message) ((j12_common_ptr)(cinfo), (lvl)); )
#define J12TRACEMS8(cinfo, lvl, code, p1, p2, p3, p4, p5, p6, p7, p8) \
MAKESTMT(int *_mp = (cinfo)->err->msg_parm.i; \
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
_mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
(cinfo)->err->msg_code = (code); \
(*(cinfo)->err->emit_message) ((j12_common_ptr)(cinfo), (lvl)); )
#define J12TRACEMSS(cinfo, lvl, code, str) \
((cinfo)->err->msg_code = (code), \
strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
(cinfo)->err->msg_parm.s[JMSG_STR_PARM_MAX - 1] = '\0', \
(*(cinfo)->err->emit_message) ((j12_common_ptr)(cinfo), (lvl)))
#endif /* JERROR_H */

View File

@@ -22,7 +22,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
/*
@@ -90,6 +90,8 @@ jpeg_CreateCompress(j_compress_ptr cinfo, int version, size_t structsize)
cinfo->input_gamma = 1.0; /* in case application forgets */
cinfo->data_precision = BITS_IN_JSAMPLE;
/* OK, I'm ready */
cinfo->global_state = CSTATE_START;
}
@@ -183,8 +185,16 @@ jpeg_finish_compress(j_compress_ptr cinfo)
/* We bypass the main controller and invoke coef controller directly;
* all work is being done from the coefficient buffer.
*/
if (!(*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE)NULL))
ERREXIT(cinfo, JERR_CANT_SUSPEND);
#ifdef WITH_12BIT
if (cinfo->data_precision == 12) {
if (!(*cinfo->coef->compress_data_12) (cinfo, (J12SAMPIMAGE)NULL))
ERREXIT(cinfo, JERR_CANT_SUSPEND);
} else
#endif
{
if (!(*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE)NULL))
ERREXIT(cinfo, JERR_CANT_SUSPEND);
}
}
(*cinfo->master->finish_pass) (cinfo);
}

View File

@@ -1,7 +1,7 @@
/*
* jcapistd.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-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2022, D. R. Commander.
@@ -19,9 +19,12 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jsamplecomp.h"
#if BITS_IN_JSAMPLE == 8
/*
* Compression initialization.
* Before calling this, all parameters and a data destination must be set up.
@@ -53,13 +56,15 @@ jpeg_start_compress(j_compress_ptr cinfo, boolean write_all_tables)
jinit_compress_master(cinfo);
/* Set up for the first pass */
(*cinfo->master->prepare_for_pass) (cinfo);
/* Ready for application to drive first pass through jpeg_write_scanlines
* or jpeg_write_raw_data.
/* Ready for application to drive first pass through _jpeg_write_scanlines
* or _jpeg_write_raw_data.
*/
cinfo->next_scanline = 0;
cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
}
#endif
/*
* Write some scanlines of data to the JPEG compressor.
@@ -69,7 +74,7 @@ jpeg_start_compress(j_compress_ptr cinfo, boolean write_all_tables)
* the data destination module has requested suspension of the compressor,
* or if more than image_height scanlines are passed in.
*
* Note: we warn about excess calls to jpeg_write_scanlines() since
* Note: we warn about excess calls to _jpeg_write_scanlines() since
* this likely signals an application programmer error. However,
* excess scanlines passed in the last valid call are *silently* ignored,
* so that the application need not adjust num_lines for end-of-image
@@ -77,11 +82,14 @@ jpeg_start_compress(j_compress_ptr cinfo, boolean write_all_tables)
*/
GLOBAL(JDIMENSION)
jpeg_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines,
JDIMENSION num_lines)
_jpeg_write_scanlines(j_compress_ptr cinfo, _JSAMPARRAY scanlines,
JDIMENSION num_lines)
{
JDIMENSION row_ctr, rows_left;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if (cinfo->global_state != CSTATE_SCANNING)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
if (cinfo->next_scanline >= cinfo->image_height)
@@ -95,9 +103,9 @@ jpeg_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines,
}
/* Give master control module another chance if this is first call to
* jpeg_write_scanlines. This lets output of the frame/scan headers be
* _jpeg_write_scanlines. This lets output of the frame/scan headers be
* delayed so that application can write COM, etc, markers between
* jpeg_start_compress and jpeg_write_scanlines.
* jpeg_start_compress and _jpeg_write_scanlines.
*/
if (cinfo->master->call_pass_startup)
(*cinfo->master->pass_startup) (cinfo);
@@ -108,7 +116,7 @@ jpeg_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines,
num_lines = rows_left;
row_ctr = 0;
(*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
(*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, num_lines);
cinfo->next_scanline += row_ctr;
return row_ctr;
}
@@ -120,11 +128,14 @@ jpeg_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines,
*/
GLOBAL(JDIMENSION)
jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
JDIMENSION num_lines)
_jpeg_write_raw_data(j_compress_ptr cinfo, _JSAMPIMAGE data,
JDIMENSION num_lines)
{
JDIMENSION lines_per_iMCU_row;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if (cinfo->global_state != CSTATE_RAW_OK)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
if (cinfo->next_scanline >= cinfo->image_height) {
@@ -140,9 +151,9 @@ jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
}
/* Give master control module another chance if this is first call to
* jpeg_write_raw_data. This lets output of the frame/scan headers be
* _jpeg_write_raw_data. This lets output of the frame/scan headers be
* delayed so that application can write COM, etc, markers between
* jpeg_start_compress and jpeg_write_raw_data.
* jpeg_start_compress and _jpeg_write_raw_data.
*/
if (cinfo->master->call_pass_startup)
(*cinfo->master->pass_startup) (cinfo);
@@ -153,7 +164,7 @@ jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
ERREXIT(cinfo, JERR_BUFFER_SIZE);
/* Directly compress the row. */
if (!(*cinfo->coef->compress_data) (cinfo, data)) {
if (!(*cinfo->coef->_compress_data) (cinfo, data)) {
/* If compressor did not consume the whole row, suspend processing. */
return 0;
}

View File

@@ -914,6 +914,9 @@ jinit_arith_encoder(j_compress_ptr cinfo)
arith_entropy_ptr entropy;
int i;
if (cinfo->data_precision != 8)
ERREXIT(cinfo, JERR_NOTIMPL);
entropy = (arith_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(arith_entropy_encoder));

View File

@@ -15,7 +15,8 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jsamplecomp.h"
/* We use a full-image coefficient buffer when doing Huffman optimization,
@@ -58,11 +59,12 @@ typedef my_coef_controller *my_coef_ptr;
/* Forward declarations */
METHODDEF(boolean) compress_data(j_compress_ptr cinfo, JSAMPIMAGE input_buf);
METHODDEF(boolean) compress_data(j_compress_ptr cinfo, _JSAMPIMAGE input_buf);
#ifdef FULL_COEF_BUFFER_SUPPORTED
METHODDEF(boolean) compress_first_pass(j_compress_ptr cinfo,
JSAMPIMAGE input_buf);
METHODDEF(boolean) compress_output(j_compress_ptr cinfo, JSAMPIMAGE input_buf);
_JSAMPIMAGE input_buf);
METHODDEF(boolean) compress_output(j_compress_ptr cinfo,
_JSAMPIMAGE input_buf);
#endif
@@ -106,18 +108,18 @@ start_pass_coef(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
case JBUF_PASS_THRU:
if (coef->whole_image[0] != NULL)
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
coef->pub.compress_data = compress_data;
coef->pub._compress_data = compress_data;
break;
#ifdef FULL_COEF_BUFFER_SUPPORTED
case JBUF_SAVE_AND_PASS:
if (coef->whole_image[0] == NULL)
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
coef->pub.compress_data = compress_first_pass;
coef->pub._compress_data = compress_first_pass;
break;
case JBUF_CRANK_DEST:
if (coef->whole_image[0] == NULL)
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
coef->pub.compress_data = compress_output;
coef->pub._compress_data = compress_output;
break;
#endif
default:
@@ -138,7 +140,7 @@ start_pass_coef(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
*/
METHODDEF(boolean)
compress_data(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
compress_data(j_compress_ptr cinfo, _JSAMPIMAGE input_buf)
{
my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
JDIMENSION MCU_col_num; /* index of current MCU within row */
@@ -172,10 +174,10 @@ compress_data(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
if (coef->iMCU_row_num < last_iMCU_row ||
yoffset + yindex < compptr->last_row_height) {
(*cinfo->fdct->forward_DCT) (cinfo, compptr,
input_buf[compptr->component_index],
coef->MCU_buffer[blkn],
ypos, xpos, (JDIMENSION)blockcnt);
(*cinfo->fdct->_forward_DCT) (cinfo, compptr,
input_buf[compptr->component_index],
coef->MCU_buffer[blkn],
ypos, xpos, (JDIMENSION)blockcnt);
if (blockcnt < compptr->MCU_width) {
/* Create some dummy blocks at the right edge of the image. */
jzero_far((void *)coef->MCU_buffer[blkn + blockcnt],
@@ -242,7 +244,7 @@ compress_data(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
*/
METHODDEF(boolean)
compress_first_pass(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
compress_first_pass(j_compress_ptr cinfo, _JSAMPIMAGE input_buf)
{
my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
@@ -279,10 +281,10 @@ compress_first_pass(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
*/
for (block_row = 0; block_row < block_rows; block_row++) {
thisblockrow = buffer[block_row];
(*cinfo->fdct->forward_DCT) (cinfo, compptr,
input_buf[ci], thisblockrow,
(JDIMENSION)(block_row * DCTSIZE),
(JDIMENSION)0, blocks_across);
(*cinfo->fdct->_forward_DCT) (cinfo, compptr,
input_buf[ci], thisblockrow,
(JDIMENSION)(block_row * DCTSIZE),
(JDIMENSION)0, blocks_across);
if (ndummy > 0) {
/* Create dummy blocks at the right edge of the image. */
thisblockrow += blocks_across; /* => first dummy block */
@@ -338,7 +340,7 @@ compress_first_pass(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
*/
METHODDEF(boolean)
compress_output(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
compress_output(j_compress_ptr cinfo, _JSAMPIMAGE input_buf)
{
my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
JDIMENSION MCU_col_num; /* index of current MCU within row */
@@ -402,10 +404,13 @@ compress_output(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
*/
GLOBAL(void)
jinit_c_coef_controller(j_compress_ptr cinfo, boolean need_full_buffer)
_jinit_c_coef_controller(j_compress_ptr cinfo, boolean need_full_buffer)
{
my_coef_ptr coef;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
coef = (my_coef_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_coef_controller));

View File

@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2009-2012, 2015, D. R. Commander.
* Copyright (C) 2009-2012, 2015, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -29,15 +29,15 @@
INLINE
LOCAL(void)
rgb_ycc_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPIMAGE output_buf, JDIMENSION output_row,
rgb_ycc_convert_internal(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPIMAGE output_buf, JDIMENSION output_row,
int num_rows)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int r, g, b;
register JLONG *ctab = cconvert->rgb_ycc_tab;
register JSAMPROW inptr;
register JSAMPROW outptr0, outptr1, outptr2;
register _JSAMPROW inptr;
register _JSAMPROW outptr0, outptr1, outptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->image_width;
@@ -52,20 +52,20 @@ rgb_ycc_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
g = inptr[RGB_GREEN];
b = inptr[RGB_BLUE];
inptr += RGB_PIXELSIZE;
/* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
/* If the inputs are 0.._MAXJSAMPLE, the outputs of these equations
* must be too; we do not need an explicit range-limiting operation.
* Hence the value being shifted is never negative, and we don't
* need the general RIGHT_SHIFT macro.
*/
/* Y */
outptr0[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
ctab[b + B_Y_OFF]) >> SCALEBITS);
outptr0[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
ctab[b + B_Y_OFF]) >> SCALEBITS);
/* Cb */
outptr1[col] = (JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
ctab[b + B_CB_OFF]) >> SCALEBITS);
outptr1[col] = (_JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
ctab[b + B_CB_OFF]) >> SCALEBITS);
/* Cr */
outptr2[col] = (JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
ctab[b + B_CR_OFF]) >> SCALEBITS);
outptr2[col] = (_JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
ctab[b + B_CR_OFF]) >> SCALEBITS);
}
}
}
@@ -83,15 +83,15 @@ rgb_ycc_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
INLINE
LOCAL(void)
rgb_gray_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPIMAGE output_buf, JDIMENSION output_row,
rgb_gray_convert_internal(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPIMAGE output_buf, JDIMENSION output_row,
int num_rows)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int r, g, b;
register JLONG *ctab = cconvert->rgb_ycc_tab;
register JSAMPROW inptr;
register JSAMPROW outptr;
register _JSAMPROW inptr;
register _JSAMPROW outptr;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->image_width;
@@ -105,8 +105,8 @@ rgb_gray_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
b = inptr[RGB_BLUE];
inptr += RGB_PIXELSIZE;
/* Y */
outptr[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
ctab[b + B_Y_OFF]) >> SCALEBITS);
outptr[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
ctab[b + B_Y_OFF]) >> SCALEBITS);
}
}
}
@@ -119,12 +119,12 @@ rgb_gray_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
INLINE
LOCAL(void)
rgb_rgb_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPIMAGE output_buf, JDIMENSION output_row,
rgb_rgb_convert_internal(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPIMAGE output_buf, JDIMENSION output_row,
int num_rows)
{
register JSAMPROW inptr;
register JSAMPROW outptr0, outptr1, outptr2;
register _JSAMPROW inptr;
register _JSAMPROW outptr0, outptr1, outptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->image_width;

166
jccolor.c
View File

@@ -15,8 +15,9 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jsimd.h"
#include "jsamplecomp.h"
/* Private subobject */
@@ -35,14 +36,14 @@ typedef my_color_converter *my_cconvert_ptr;
/*
* YCbCr is defined per CCIR 601-1, except that Cb and Cr are
* normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
* normalized to the range 0.._MAXJSAMPLE rather than -0.5 .. 0.5.
* The conversion equations to be implemented are therefore
* Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
* Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
* Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
* Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + _CENTERJSAMPLE
* Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + _CENTERJSAMPLE
* (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
* Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,
* rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and
* Note: older versions of the IJG code used a zero offset of _MAXJSAMPLE/2,
* rather than _CENTERJSAMPLE, for Cb and Cr. This gave equal positive and
* negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0)
* were not represented exactly. Now we sacrifice exact representation of
* maximum red and maximum blue in order to get exact grayscales.
@@ -53,16 +54,16 @@ typedef my_color_converter *my_cconvert_ptr;
*
* For even more speed, we avoid doing any multiplications in the inner loop
* by precalculating the constants times R,G,B for all possible values.
* For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
* For 8-bit samples this is very reasonable (only 256 entries per table);
* for 12-bit samples it is still acceptable. It's not very reasonable for
* 16-bit samples, but if you want lossless storage you shouldn't be changing
* colorspace anyway.
* The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
* The _CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
* in the tables to save adding them separately in the inner loop.
*/
#define SCALEBITS 16 /* speediest right-shift on some machines */
#define CBCR_OFFSET ((JLONG)CENTERJSAMPLE << SCALEBITS)
#define CBCR_OFFSET ((JLONG)_CENTERJSAMPLE << SCALEBITS)
#define ONE_HALF ((JLONG)1 << (SCALEBITS - 1))
#define FIX(x) ((JLONG)((x) * (1L << SCALEBITS) + 0.5))
@@ -73,15 +74,15 @@ typedef my_color_converter *my_cconvert_ptr;
*/
#define R_Y_OFF 0 /* offset to R => Y section */
#define G_Y_OFF (1 * (MAXJSAMPLE + 1)) /* offset to G => Y section */
#define B_Y_OFF (2 * (MAXJSAMPLE + 1)) /* etc. */
#define R_CB_OFF (3 * (MAXJSAMPLE + 1))
#define G_CB_OFF (4 * (MAXJSAMPLE + 1))
#define B_CB_OFF (5 * (MAXJSAMPLE + 1))
#define G_Y_OFF (1 * (_MAXJSAMPLE + 1)) /* offset to G => Y section */
#define B_Y_OFF (2 * (_MAXJSAMPLE + 1)) /* etc. */
#define R_CB_OFF (3 * (_MAXJSAMPLE + 1))
#define G_CB_OFF (4 * (_MAXJSAMPLE + 1))
#define B_CB_OFF (5 * (_MAXJSAMPLE + 1))
#define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
#define G_CR_OFF (6 * (MAXJSAMPLE + 1))
#define B_CR_OFF (7 * (MAXJSAMPLE + 1))
#define TABLE_SIZE (8 * (MAXJSAMPLE + 1))
#define G_CR_OFF (6 * (_MAXJSAMPLE + 1))
#define B_CR_OFF (7 * (_MAXJSAMPLE + 1))
#define TABLE_SIZE (8 * (_MAXJSAMPLE + 1))
/* Include inline routines for colorspace extensions */
@@ -205,15 +206,15 @@ rgb_ycc_start(j_compress_ptr cinfo)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(TABLE_SIZE * sizeof(JLONG)));
for (i = 0; i <= MAXJSAMPLE; i++) {
for (i = 0; i <= _MAXJSAMPLE; i++) {
rgb_ycc_tab[i + R_Y_OFF] = FIX(0.29900) * i;
rgb_ycc_tab[i + G_Y_OFF] = FIX(0.58700) * i;
rgb_ycc_tab[i + B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
rgb_ycc_tab[i + R_CB_OFF] = (-FIX(0.16874)) * i;
rgb_ycc_tab[i + G_CB_OFF] = (-FIX(0.33126)) * i;
/* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
* This ensures that the maximum output will round to MAXJSAMPLE
* not MAXJSAMPLE+1, and thus that we don't have to range-limit.
* This ensures that the maximum output will round to _MAXJSAMPLE
* not _MAXJSAMPLE+1, and thus that we don't have to range-limit.
*/
rgb_ycc_tab[i + B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF - 1;
/* B=>Cb and R=>Cr tables are the same
@@ -230,8 +231,8 @@ rgb_ycc_start(j_compress_ptr cinfo)
*/
METHODDEF(void)
rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
rgb_ycc_convert(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
{
switch (cinfo->in_color_space) {
case JCS_EXT_RGB:
@@ -278,8 +279,8 @@ rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
*/
METHODDEF(void)
rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
rgb_gray_convert(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
{
switch (cinfo->in_color_space) {
case JCS_EXT_RGB:
@@ -323,8 +324,8 @@ rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
*/
METHODDEF(void)
rgb_rgb_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
rgb_rgb_convert(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
{
switch (cinfo->in_color_space) {
case JCS_EXT_RGB:
@@ -372,14 +373,14 @@ rgb_rgb_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
*/
METHODDEF(void)
cmyk_ycck_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
cmyk_ycck_convert(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int r, g, b;
register JLONG *ctab = cconvert->rgb_ycc_tab;
register JSAMPROW inptr;
register JSAMPROW outptr0, outptr1, outptr2, outptr3;
register _JSAMPROW inptr;
register _JSAMPROW outptr0, outptr1, outptr2, outptr3;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->image_width;
@@ -391,26 +392,26 @@ cmyk_ycck_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
outptr3 = output_buf[3][output_row];
output_row++;
for (col = 0; col < num_cols; col++) {
r = MAXJSAMPLE - inptr[0];
g = MAXJSAMPLE - inptr[1];
b = MAXJSAMPLE - inptr[2];
r = _MAXJSAMPLE - inptr[0];
g = _MAXJSAMPLE - inptr[1];
b = _MAXJSAMPLE - inptr[2];
/* K passes through as-is */
outptr3[col] = inptr[3];
inptr += 4;
/* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
/* If the inputs are 0.._MAXJSAMPLE, the outputs of these equations
* must be too; we do not need an explicit range-limiting operation.
* Hence the value being shifted is never negative, and we don't
* need the general RIGHT_SHIFT macro.
*/
/* Y */
outptr0[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
ctab[b + B_Y_OFF]) >> SCALEBITS);
outptr0[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
ctab[b + B_Y_OFF]) >> SCALEBITS);
/* Cb */
outptr1[col] = (JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
ctab[b + B_CB_OFF]) >> SCALEBITS);
outptr1[col] = (_JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] +
ctab[b + B_CB_OFF]) >> SCALEBITS);
/* Cr */
outptr2[col] = (JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
ctab[b + B_CR_OFF]) >> SCALEBITS);
outptr2[col] = (_JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] +
ctab[b + B_CR_OFF]) >> SCALEBITS);
}
}
}
@@ -423,11 +424,11 @@ cmyk_ycck_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
*/
METHODDEF(void)
grayscale_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
grayscale_convert(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
{
register JSAMPROW inptr;
register JSAMPROW outptr;
register _JSAMPROW inptr;
register _JSAMPROW outptr;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->image_width;
int instride = cinfo->input_components;
@@ -451,11 +452,11 @@ grayscale_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
*/
METHODDEF(void)
null_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows)
null_convert(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
{
register JSAMPROW inptr;
register JSAMPROW outptr, outptr0, outptr1, outptr2, outptr3;
register _JSAMPROW inptr;
register _JSAMPROW outptr, outptr0, outptr1, outptr2, outptr3;
register JDIMENSION col;
register int ci;
int nc = cinfo->num_components;
@@ -523,10 +524,13 @@ null_method(j_compress_ptr cinfo)
*/
GLOBAL(void)
jinit_color_converter(j_compress_ptr cinfo)
_jinit_color_converter(j_compress_ptr cinfo)
{
my_cconvert_ptr cconvert;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
cconvert = (my_cconvert_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_color_converter));
@@ -579,7 +583,7 @@ jinit_color_converter(j_compress_ptr cinfo)
if (cinfo->num_components != 1)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
if (cinfo->in_color_space == JCS_GRAYSCALE)
cconvert->pub.color_convert = grayscale_convert;
cconvert->pub._color_convert = grayscale_convert;
else if (cinfo->in_color_space == JCS_RGB ||
cinfo->in_color_space == JCS_EXT_RGB ||
cinfo->in_color_space == JCS_EXT_RGBX ||
@@ -591,14 +595,17 @@ jinit_color_converter(j_compress_ptr cinfo)
cinfo->in_color_space == JCS_EXT_BGRA ||
cinfo->in_color_space == JCS_EXT_ABGR ||
cinfo->in_color_space == JCS_EXT_ARGB) {
#ifdef WITH_SIMD
if (jsimd_can_rgb_gray())
cconvert->pub.color_convert = jsimd_rgb_gray_convert;
else {
cconvert->pub._color_convert = jsimd_rgb_gray_convert;
else
#endif
{
cconvert->pub.start_pass = rgb_ycc_start;
cconvert->pub.color_convert = rgb_gray_convert;
cconvert->pub._color_convert = rgb_gray_convert;
}
} else if (cinfo->in_color_space == JCS_YCbCr)
cconvert->pub.color_convert = grayscale_convert;
cconvert->pub._color_convert = grayscale_convert;
else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break;
@@ -610,12 +617,12 @@ jinit_color_converter(j_compress_ptr cinfo)
rgb_green[cinfo->in_color_space] == 1 &&
rgb_blue[cinfo->in_color_space] == 2 &&
rgb_pixelsize[cinfo->in_color_space] == 3) {
#if defined(__mips__)
#if defined(WITH_SIMD) && defined(__mips__)
if (jsimd_c_can_null_convert())
cconvert->pub.color_convert = jsimd_c_null_convert;
cconvert->pub._color_convert = jsimd_c_null_convert;
else
#endif
cconvert->pub.color_convert = null_convert;
cconvert->pub._color_convert = null_convert;
} else if (cinfo->in_color_space == JCS_RGB ||
cinfo->in_color_space == JCS_EXT_RGB ||
cinfo->in_color_space == JCS_EXT_RGBX ||
@@ -627,7 +634,7 @@ jinit_color_converter(j_compress_ptr cinfo)
cinfo->in_color_space == JCS_EXT_BGRA ||
cinfo->in_color_space == JCS_EXT_ABGR ||
cinfo->in_color_space == JCS_EXT_ARGB)
cconvert->pub.color_convert = rgb_rgb_convert;
cconvert->pub._color_convert = rgb_rgb_convert;
else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break;
@@ -646,19 +653,22 @@ jinit_color_converter(j_compress_ptr cinfo)
cinfo->in_color_space == JCS_EXT_BGRA ||
cinfo->in_color_space == JCS_EXT_ABGR ||
cinfo->in_color_space == JCS_EXT_ARGB) {
#ifdef WITH_SIMD
if (jsimd_can_rgb_ycc())
cconvert->pub.color_convert = jsimd_rgb_ycc_convert;
else {
cconvert->pub.start_pass = rgb_ycc_start;
cconvert->pub.color_convert = rgb_ycc_convert;
}
} else if (cinfo->in_color_space == JCS_YCbCr) {
#if defined(__mips__)
if (jsimd_c_can_null_convert())
cconvert->pub.color_convert = jsimd_c_null_convert;
cconvert->pub._color_convert = jsimd_rgb_ycc_convert;
else
#endif
cconvert->pub.color_convert = null_convert;
{
cconvert->pub.start_pass = rgb_ycc_start;
cconvert->pub._color_convert = rgb_ycc_convert;
}
} else if (cinfo->in_color_space == JCS_YCbCr) {
#if defined(WITH_SIMD) && defined(__mips__)
if (jsimd_c_can_null_convert())
cconvert->pub._color_convert = jsimd_c_null_convert;
else
#endif
cconvert->pub._color_convert = null_convert;
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break;
@@ -667,12 +677,12 @@ jinit_color_converter(j_compress_ptr cinfo)
if (cinfo->num_components != 4)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
if (cinfo->in_color_space == JCS_CMYK) {
#if defined(__mips__)
#if defined(WITH_SIMD) && defined(__mips__)
if (jsimd_c_can_null_convert())
cconvert->pub.color_convert = jsimd_c_null_convert;
cconvert->pub._color_convert = jsimd_c_null_convert;
else
#endif
cconvert->pub.color_convert = null_convert;
cconvert->pub._color_convert = null_convert;
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break;
@@ -682,14 +692,14 @@ jinit_color_converter(j_compress_ptr cinfo)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
if (cinfo->in_color_space == JCS_CMYK) {
cconvert->pub.start_pass = rgb_ycc_start;
cconvert->pub.color_convert = cmyk_ycck_convert;
cconvert->pub._color_convert = cmyk_ycck_convert;
} else if (cinfo->in_color_space == JCS_YCCK) {
#if defined(__mips__)
#if defined(WITH_SIMD) && defined(__mips__)
if (jsimd_c_can_null_convert())
cconvert->pub.color_convert = jsimd_c_null_convert;
cconvert->pub._color_convert = jsimd_c_null_convert;
else
#endif
cconvert->pub.color_convert = null_convert;
cconvert->pub._color_convert = null_convert;
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break;
@@ -698,12 +708,12 @@ jinit_color_converter(j_compress_ptr cinfo)
if (cinfo->jpeg_color_space != cinfo->in_color_space ||
cinfo->num_components != cinfo->input_components)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
#if defined(__mips__)
#if defined(WITH_SIMD) && defined(__mips__)
if (jsimd_c_can_null_convert())
cconvert->pub.color_convert = jsimd_c_null_convert;
cconvert->pub._color_convert = jsimd_c_null_convert;
else
#endif
cconvert->pub.color_convert = null_convert;
cconvert->pub._color_convert = null_convert;
break;
}
}

View File

@@ -18,7 +18,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */
#include "jsimddct.h"
@@ -28,10 +28,10 @@
typedef void (*forward_DCT_method_ptr) (DCTELEM *data);
typedef void (*float_DCT_method_ptr) (FAST_FLOAT *data);
typedef void (*convsamp_method_ptr) (JSAMPARRAY sample_data,
typedef void (*convsamp_method_ptr) (_JSAMPARRAY sample_data,
JDIMENSION start_col,
DCTELEM *workspace);
typedef void (*float_convsamp_method_ptr) (JSAMPARRAY sample_data,
typedef void (*float_convsamp_method_ptr) (_JSAMPARRAY sample_data,
JDIMENSION start_col,
FAST_FLOAT *workspace);
@@ -264,7 +264,7 @@ start_pass_fdctmgr(j_compress_ptr cinfo)
}
dtbl = fdct->divisors[qtblno];
for (i = 0; i < DCTSIZE2; i++) {
#if BITS_IN_JSAMPLE == 8
#if defined(WITH_SIMD) && BITS_IN_JSAMPLE == 8
if (!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]) &&
fdct->quantize == jsimd_quantize)
fdct->quantize = quantize;
@@ -304,7 +304,7 @@ start_pass_fdctmgr(j_compress_ptr cinfo)
}
dtbl = fdct->divisors[qtblno];
for (i = 0; i < DCTSIZE2; i++) {
#if BITS_IN_JSAMPLE == 8
#if defined(WITH_SIMD) && BITS_IN_JSAMPLE == 8
if (!compute_reciprocal(
DESCALE(MULTIPLY16V16((JLONG)qtbl->quantval[i],
(JLONG)aanscales[i]),
@@ -370,10 +370,10 @@ start_pass_fdctmgr(j_compress_ptr cinfo)
*/
METHODDEF(void)
convsamp(JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM *workspace)
convsamp(_JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM *workspace)
{
register DCTELEM *workspaceptr;
register JSAMPROW elemptr;
register _JSAMPROW elemptr;
register int elemr;
workspaceptr = workspace;
@@ -381,19 +381,19 @@ convsamp(JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM *workspace)
elemptr = sample_data[elemr] + start_col;
#if DCTSIZE == 8 /* unroll the inner loop */
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
#else
{
register int elemc;
for (elemc = DCTSIZE; elemc > 0; elemc--)
*workspaceptr++ = (*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = (*elemptr++) - _CENTERJSAMPLE;
}
#endif
}
@@ -488,7 +488,7 @@ quantize(JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
METHODDEF(void)
forward_DCT(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
_JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
JDIMENSION start_row, JDIMENSION start_col, JDIMENSION num_blocks)
/* This version is used for integer DCT implementations. */
{
@@ -522,30 +522,30 @@ forward_DCT(j_compress_ptr cinfo, jpeg_component_info *compptr,
#ifdef DCT_FLOAT_SUPPORTED
METHODDEF(void)
convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
convsamp_float(_JSAMPARRAY sample_data, JDIMENSION start_col,
FAST_FLOAT *workspace)
{
register FAST_FLOAT *workspaceptr;
register JSAMPROW elemptr;
register _JSAMPROW elemptr;
register int elemr;
workspaceptr = workspace;
for (elemr = 0; elemr < DCTSIZE; elemr++) {
elemptr = sample_data[elemr] + start_col;
#if DCTSIZE == 8 /* unroll the inner loop */
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
#else
{
register int elemc;
for (elemc = DCTSIZE; elemc > 0; elemc--)
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)((*elemptr++) - _CENTERJSAMPLE);
}
#endif
}
@@ -577,7 +577,7 @@ quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
METHODDEF(void)
forward_DCT_float(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
_JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
JDIMENSION start_row, JDIMENSION start_col,
JDIMENSION num_blocks)
/* This version is used for floating-point DCT implementations. */
@@ -617,11 +617,14 @@ forward_DCT_float(j_compress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jinit_forward_dct(j_compress_ptr cinfo)
_jinit_forward_dct(j_compress_ptr cinfo)
{
my_fdct_ptr fdct;
int i;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
fdct = (my_fdct_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_fdct_controller));
@@ -632,28 +635,34 @@ jinit_forward_dct(j_compress_ptr cinfo)
switch (cinfo->dct_method) {
#ifdef DCT_ISLOW_SUPPORTED
case JDCT_ISLOW:
fdct->pub.forward_DCT = forward_DCT;
fdct->pub._forward_DCT = forward_DCT;
#ifdef WITH_SIMD
if (jsimd_can_fdct_islow())
fdct->dct = jsimd_fdct_islow;
else
fdct->dct = jpeg_fdct_islow;
#endif
fdct->dct = _jpeg_fdct_islow;
break;
#endif
#ifdef DCT_IFAST_SUPPORTED
case JDCT_IFAST:
fdct->pub.forward_DCT = forward_DCT;
fdct->pub._forward_DCT = forward_DCT;
#ifdef WITH_SIMD
if (jsimd_can_fdct_ifast())
fdct->dct = jsimd_fdct_ifast;
else
fdct->dct = jpeg_fdct_ifast;
#endif
fdct->dct = _jpeg_fdct_ifast;
break;
#endif
#ifdef DCT_FLOAT_SUPPORTED
case JDCT_FLOAT:
fdct->pub.forward_DCT = forward_DCT_float;
fdct->pub._forward_DCT = forward_DCT_float;
#ifdef WITH_SIMD
if (jsimd_can_fdct_float())
fdct->float_dct = jsimd_fdct_float;
else
#endif
fdct->float_dct = jpeg_fdct_float;
break;
#endif
@@ -671,25 +680,33 @@ jinit_forward_dct(j_compress_ptr cinfo)
case JDCT_IFAST:
#endif
#if defined(DCT_ISLOW_SUPPORTED) || defined(DCT_IFAST_SUPPORTED)
#ifdef WITH_SIMD
if (jsimd_can_convsamp())
fdct->convsamp = jsimd_convsamp;
else
#endif
fdct->convsamp = convsamp;
#ifdef WITH_SIMD
if (jsimd_can_quantize())
fdct->quantize = jsimd_quantize;
else
#endif
fdct->quantize = quantize;
break;
#endif
#ifdef DCT_FLOAT_SUPPORTED
case JDCT_FLOAT:
#ifdef WITH_SIMD
if (jsimd_can_convsamp_float())
fdct->float_convsamp = jsimd_convsamp_float;
else
#endif
fdct->float_convsamp = convsamp_float;
#ifdef WITH_SIMD
if (jsimd_can_quantize_float())
fdct->float_quantize = jsimd_quantize_float;
else
#endif
fdct->float_quantize = quantize_float;
break;
#endif

View File

@@ -26,7 +26,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jsimd.h"
#include <limits.h>
@@ -801,6 +801,7 @@ htest_one_block(j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
register int temp;
register int nbits;
register int k, r;
int max_coef_bits = cinfo->data_precision + 2;
/* Encode the DC coefficient difference per section F.1.2.1 */
@@ -817,7 +818,7 @@ htest_one_block(j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
/* Check for out-of-range coefficient values.
* Since we're encoding a difference, the range limit is twice as much.
*/
if (nbits > MAX_COEF_BITS + 1)
if (nbits > max_coef_bits + 1)
ERREXIT(cinfo, JERR_BAD_DCT_COEF);
/* Count the Huffman symbol for the number of bits */
@@ -846,7 +847,7 @@ htest_one_block(j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
while ((temp >>= 1))
nbits++;
/* Check for out-of-range coefficient values */
if (nbits > MAX_COEF_BITS)
if (nbits > max_coef_bits)
ERREXIT(cinfo, JERR_BAD_DCT_COEF);
/* Count Huffman symbol for run length / number of bits */

View File

@@ -19,12 +19,6 @@
* Hence the magnitude should always fit in 10 or 14 bits respectively.
*/
#if BITS_IN_JSAMPLE == 8
#define MAX_COEF_BITS 10
#else
#define MAX_COEF_BITS 14
#endif
/* Derived data constructed for each Huffman table */
typedef struct {

View File

@@ -2,7 +2,7 @@
* jcicc.c
*
* Copyright (C) 1997-1998, Thomas G. Lane, Todd Newman.
* Copyright (C) 2017, 2022, D. R. Commander.
* Copyright (C) 2017, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -15,8 +15,8 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jerrorint.h"
#include "jpeglib.h"
#include "jerror.h"
/*

View File

@@ -20,8 +20,8 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpegcomp.h"
#include "jpeglib.h"
#include "jpegapicomp.h"
/*
@@ -36,14 +36,29 @@ jinit_compress_master(j_compress_ptr cinfo)
/* Initialize master control (includes parameter checking/processing) */
jinit_c_master_control(cinfo, FALSE /* full compression */);
/* Preprocessing */
if (!cinfo->raw_data_in) {
jinit_color_converter(cinfo);
jinit_downsampler(cinfo);
jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
#ifdef WITH_12BIT
if (cinfo->data_precision == 12) {
/* Preprocessing */
if (!cinfo->raw_data_in) {
j12init_color_converter(cinfo);
j12init_downsampler(cinfo);
j12init_c_prep_controller(cinfo,
FALSE /* never need full buffer here */);
}
/* Forward DCT */
j12init_forward_dct(cinfo);
} else
#endif
{
/* Preprocessing */
if (!cinfo->raw_data_in) {
jinit_color_converter(cinfo);
jinit_downsampler(cinfo);
jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
}
/* Forward DCT */
jinit_forward_dct(cinfo);
}
/* Forward DCT */
jinit_forward_dct(cinfo);
/* Entropy encoding: either Huffman or arithmetic coding. */
if (cinfo->arith_code) {
#ifdef C_ARITH_CODING_SUPPORTED
@@ -63,9 +78,18 @@ jinit_compress_master(j_compress_ptr cinfo)
}
/* Need a full-image coefficient buffer in any multi-pass mode. */
jinit_c_coef_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
cinfo->optimize_coding));
jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
#ifdef WITH_12BIT
if (cinfo->data_precision == 12) {
j12init_c_coef_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
cinfo->optimize_coding));
j12init_c_main_controller(cinfo, FALSE /* never need full buffer here */);
} else
#endif
{
jinit_c_coef_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
cinfo->optimize_coding));
jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
}
jinit_marker_writer(cinfo);

View File

@@ -15,7 +15,8 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jsamplecomp.h"
/* Private buffer controller object */
@@ -32,7 +33,7 @@ typedef struct {
* (we allocate one for each component). In the full-image case, this
* points to the currently accessible strips of the virtual arrays.
*/
JSAMPARRAY buffer[MAX_COMPONENTS];
_JSAMPARRAY buffer[MAX_COMPONENTS];
} my_main_controller;
typedef my_main_controller *my_main_ptr;
@@ -40,7 +41,7 @@ typedef my_main_controller *my_main_ptr;
/* Forward declarations */
METHODDEF(void) process_data_simple_main(j_compress_ptr cinfo,
JSAMPARRAY input_buf,
_JSAMPARRAY input_buf,
JDIMENSION *in_row_ctr,
JDIMENSION in_rows_avail);
@@ -65,7 +66,7 @@ start_pass_main(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
main_ptr->rowgroup_ctr = 0;
main_ptr->suspended = FALSE;
main_ptr->pass_mode = pass_mode; /* save mode for use by process_data */
main_ptr->pub.process_data = process_data_simple_main;
main_ptr->pub._process_data = process_data_simple_main;
}
@@ -76,7 +77,7 @@ start_pass_main(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
*/
METHODDEF(void)
process_data_simple_main(j_compress_ptr cinfo, JSAMPARRAY input_buf,
process_data_simple_main(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail)
{
my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
@@ -84,10 +85,10 @@ process_data_simple_main(j_compress_ptr cinfo, JSAMPARRAY input_buf,
while (main_ptr->cur_iMCU_row < cinfo->total_iMCU_rows) {
/* Read input data if we haven't filled the main buffer yet */
if (main_ptr->rowgroup_ctr < DCTSIZE)
(*cinfo->prep->pre_process_data) (cinfo, input_buf, in_row_ctr,
in_rows_avail, main_ptr->buffer,
&main_ptr->rowgroup_ctr,
(JDIMENSION)DCTSIZE);
(*cinfo->prep->_pre_process_data) (cinfo, input_buf, in_row_ctr,
in_rows_avail, main_ptr->buffer,
&main_ptr->rowgroup_ctr,
(JDIMENSION)DCTSIZE);
/* If we don't have a full iMCU row buffered, return to application for
* more data. Note that preprocessor will always pad to fill the iMCU row
@@ -97,7 +98,7 @@ process_data_simple_main(j_compress_ptr cinfo, JSAMPARRAY input_buf,
return;
/* Send the completed row to the compressor */
if (!(*cinfo->coef->compress_data) (cinfo, main_ptr->buffer)) {
if (!(*cinfo->coef->_compress_data) (cinfo, main_ptr->buffer)) {
/* If compressor did not consume the whole row, then we must need to
* suspend processing and return to the application. In this situation
* we pretend we didn't yet consume the last input row; otherwise, if
@@ -128,12 +129,15 @@ process_data_simple_main(j_compress_ptr cinfo, JSAMPARRAY input_buf,
*/
GLOBAL(void)
jinit_c_main_controller(j_compress_ptr cinfo, boolean need_full_buffer)
_jinit_c_main_controller(j_compress_ptr cinfo, boolean need_full_buffer)
{
my_main_ptr main_ptr;
int ci;
jpeg_component_info *compptr;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
main_ptr = (my_main_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_main_controller));
@@ -153,7 +157,7 @@ jinit_c_main_controller(j_compress_ptr cinfo, boolean need_full_buffer)
/* Allocate a strip buffer for each component */
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) {
main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray)
main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE,
compptr->width_in_blocks * DCTSIZE,
(JDIMENSION)(compptr->v_samp_factor * DCTSIZE));

View File

@@ -14,8 +14,8 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpegcomp.h"
#include "jpeglib.h"
#include "jpegapicomp.h"
typedef enum { /* JPEG marker codes */

View File

@@ -17,8 +17,8 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpegcomp.h"
#include "jpeglib.h"
#include "jpegapicomp.h"
/* Private state */
@@ -109,8 +109,7 @@ initial_setup(j_compress_ptr cinfo, boolean transcode_only)
if ((long)jd_samplesperrow != samplesperrow)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
/* For now, precision must match compiled-in value... */
if (cinfo->data_precision != BITS_IN_JSAMPLE)
if (cinfo->data_precision != 8 && cinfo->data_precision != 12)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Check that number of components won't exceed internal array sizes */
@@ -240,13 +239,10 @@ validate_script(j_compress_ptr cinfo)
* out-of-range reconstructed DC values during the first DC scan,
* which might cause problems for some decoders.
*/
#if BITS_IN_JSAMPLE == 8
#define MAX_AH_AL 10
#else
#define MAX_AH_AL 13
#endif
int max_Ah_Al = cinfo->data_precision == 12 ? 13 : 10;
if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
Ah < 0 || Ah > max_Ah_Al || Al < 0 || Al > max_Ah_Al)
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
if (Ss == 0) {
if (Se != 0) /* DC and AC together not OK */
@@ -615,7 +611,11 @@ jinit_c_master_control(j_compress_ptr cinfo, boolean transcode_only)
}
if (cinfo->progressive_mode && !cinfo->arith_code) /* TEMPORARY HACK ??? */
cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
cinfo->optimize_coding = TRUE; /* assume default tables no good for
progressive mode */
if (cinfo->data_precision == 12)
cinfo->optimize_coding = TRUE; /* assume default tables no good for 12-bit
data precision */
/* Initialize my private state */
if (transcode_only) {

View File

@@ -3,8 +3,8 @@
*
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1997, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2022, D. R. Commander.
* It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -14,7 +14,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
/*

View File

@@ -18,6 +18,9 @@
/* Use accelerated SIMD routines when using 8-bit samples */
#cmakedefine WITH_SIMD 1
/* Include 12-bit JPEG support */
#cmakedefine WITH_12BIT 1
#ifdef _WIN32
#undef RIGHT_SHIFT_IS_UNSIGNED

View File

@@ -5,7 +5,7 @@
* Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2003-2008 by Guido Vollbeding.
* libjpeg-turbo Modifications:
* Copyright (C) 2009-2011, 2018, 2022, D. R. Commander.
* Copyright (C) 2009-2011, 2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -16,7 +16,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jstdhuff.c"
@@ -202,7 +202,6 @@ jpeg_set_defaults(j_compress_ptr cinfo)
cinfo->scale_num = 1; /* 1:1 scaling */
cinfo->scale_denom = 1;
#endif
cinfo->data_precision = BITS_IN_JSAMPLE;
/* Set up two quantization tables using default quality of 75 */
jpeg_set_quality(cinfo, 75, TRUE);
/* Set up two Huffman tables */

View File

@@ -20,7 +20,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jsimd.h"
#include <limits.h>
@@ -489,6 +489,7 @@ encode_mcu_DC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
JBLOCKROW block;
jpeg_component_info *compptr;
ISHIFT_TEMPS
int max_coef_bits = cinfo->data_precision + 2;
entropy->next_output_byte = cinfo->dest->next_output_byte;
entropy->free_in_buffer = cinfo->dest->free_in_buffer;
@@ -531,7 +532,7 @@ encode_mcu_DC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Check for out-of-range coefficient values.
* Since we're encoding a difference, the range limit is twice as much.
*/
if (nbits > MAX_COEF_BITS + 1)
if (nbits > max_coef_bits + 1)
ERREXIT(cinfo, JERR_BAD_DCT_COEF);
/* Count/emit the Huffman-coded symbol for the number of bits */
@@ -642,7 +643,7 @@ label \
/* Find the number of bits needed for the magnitude of the coefficient */ \
nbits = JPEG_NBITS_NONZERO(temp); /* there must be at least one 1 bit */ \
/* Check for out-of-range coefficient values */ \
if (nbits > MAX_COEF_BITS) \
if (nbits > max_coef_bits) \
ERREXIT(cinfo, JERR_BAD_DCT_COEF); \
\
/* Count/emit Huffman symbol for run length / number of bits */ \
@@ -670,6 +671,7 @@ encode_mcu_AC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
const JCOEF *cvalue;
size_t zerobits;
size_t bits[8 / SIZEOF_SIZE_T];
int max_coef_bits = cinfo->data_precision + 2;
entropy->next_output_byte = cinfo->dest->next_output_byte;
entropy->free_in_buffer = cinfo->dest->free_in_buffer;

View File

@@ -19,7 +19,8 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jsamplecomp.h"
/* At present, jcsample.c can request context rows only for smoothing.
@@ -59,7 +60,7 @@ typedef struct {
/* Downsampling input buffer. This buffer holds color-converted data
* until we have enough to do a downsample step.
*/
JSAMPARRAY color_buf[MAX_COMPONENTS];
_JSAMPARRAY color_buf[MAX_COMPONENTS];
JDIMENSION rows_to_go; /* counts rows remaining in source image */
int next_buf_row; /* index of next row to store in color_buf */
@@ -106,14 +107,14 @@ start_pass_prep(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
*/
LOCAL(void)
expand_bottom_edge(JSAMPARRAY image_data, JDIMENSION num_cols, int input_rows,
expand_bottom_edge(_JSAMPARRAY image_data, JDIMENSION num_cols, int input_rows,
int output_rows)
{
register int row;
for (row = input_rows; row < output_rows; row++) {
jcopy_sample_rows(image_data, input_rows - 1, image_data, row, 1,
num_cols);
_jcopy_sample_rows(image_data, input_rows - 1, image_data, row, 1,
num_cols);
}
}
@@ -128,9 +129,9 @@ expand_bottom_edge(JSAMPARRAY image_data, JDIMENSION num_cols, int input_rows,
*/
METHODDEF(void)
pre_process_data(j_compress_ptr cinfo, JSAMPARRAY input_buf,
pre_process_data(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail,
JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
_JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
JDIMENSION out_row_groups_avail)
{
my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
@@ -144,10 +145,10 @@ pre_process_data(j_compress_ptr cinfo, JSAMPARRAY input_buf,
inrows = in_rows_avail - *in_row_ctr;
numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
numrows = (int)MIN((JDIMENSION)numrows, inrows);
(*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
prep->color_buf,
(JDIMENSION)prep->next_buf_row,
numrows);
(*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
prep->color_buf,
(JDIMENSION)prep->next_buf_row,
numrows);
*in_row_ctr += numrows;
prep->next_buf_row += numrows;
prep->rows_to_go -= numrows;
@@ -162,9 +163,9 @@ pre_process_data(j_compress_ptr cinfo, JSAMPARRAY input_buf,
}
/* If we've filled the conversion buffer, empty it. */
if (prep->next_buf_row == cinfo->max_v_samp_factor) {
(*cinfo->downsample->downsample) (cinfo,
prep->color_buf, (JDIMENSION)0,
output_buf, *out_row_group_ctr);
(*cinfo->downsample->_downsample) (cinfo,
prep->color_buf, (JDIMENSION)0,
output_buf, *out_row_group_ctr);
prep->next_buf_row = 0;
(*out_row_group_ctr)++;
}
@@ -192,9 +193,9 @@ pre_process_data(j_compress_ptr cinfo, JSAMPARRAY input_buf,
*/
METHODDEF(void)
pre_process_context(j_compress_ptr cinfo, JSAMPARRAY input_buf,
pre_process_context(j_compress_ptr cinfo, _JSAMPARRAY input_buf,
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail,
JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
_JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
JDIMENSION out_row_groups_avail)
{
my_prep_ptr prep = (my_prep_ptr)cinfo->prep;
@@ -208,17 +209,17 @@ pre_process_context(j_compress_ptr cinfo, JSAMPARRAY input_buf,
inrows = in_rows_avail - *in_row_ctr;
numrows = prep->next_buf_stop - prep->next_buf_row;
numrows = (int)MIN((JDIMENSION)numrows, inrows);
(*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
prep->color_buf,
(JDIMENSION)prep->next_buf_row,
numrows);
(*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr,
prep->color_buf,
(JDIMENSION)prep->next_buf_row,
numrows);
/* Pad at top of image, if first time through */
if (prep->rows_to_go == cinfo->image_height) {
for (ci = 0; ci < cinfo->num_components; ci++) {
int row;
for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
jcopy_sample_rows(prep->color_buf[ci], 0, prep->color_buf[ci],
-row, 1, cinfo->image_width);
_jcopy_sample_rows(prep->color_buf[ci], 0, prep->color_buf[ci],
-row, 1, cinfo->image_width);
}
}
}
@@ -240,9 +241,9 @@ pre_process_context(j_compress_ptr cinfo, JSAMPARRAY input_buf,
}
/* If we've gotten enough data, downsample a row group. */
if (prep->next_buf_row == prep->next_buf_stop) {
(*cinfo->downsample->downsample) (cinfo, prep->color_buf,
(JDIMENSION)prep->this_row_group,
output_buf, *out_row_group_ctr);
(*cinfo->downsample->_downsample) (cinfo, prep->color_buf,
(JDIMENSION)prep->this_row_group,
output_buf, *out_row_group_ctr);
(*out_row_group_ctr)++;
/* Advance pointers with wraparound as necessary. */
prep->this_row_group += cinfo->max_v_samp_factor;
@@ -267,15 +268,15 @@ create_context_buffer(j_compress_ptr cinfo)
int rgroup_height = cinfo->max_v_samp_factor;
int ci, i;
jpeg_component_info *compptr;
JSAMPARRAY true_buffer, fake_buffer;
_JSAMPARRAY true_buffer, fake_buffer;
/* Grab enough space for fake row pointers for all the components;
* we need five row groups' worth of pointers for each component.
*/
fake_buffer = (JSAMPARRAY)
fake_buffer = (_JSAMPARRAY)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(cinfo->num_components * 5 * rgroup_height) *
sizeof(JSAMPROW));
sizeof(_JSAMPROW));
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) {
@@ -283,14 +284,14 @@ create_context_buffer(j_compress_ptr cinfo)
* We make the buffer wide enough to allow the downsampler to edge-expand
* horizontally within the buffer, if it so chooses.
*/
true_buffer = (*cinfo->mem->alloc_sarray)
true_buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE,
(JDIMENSION)(((long)compptr->width_in_blocks * DCTSIZE *
cinfo->max_h_samp_factor) / compptr->h_samp_factor),
(JDIMENSION)(3 * rgroup_height));
/* Copy true buffer row pointers into the middle of the fake row array */
memcpy(fake_buffer + rgroup_height, true_buffer,
3 * rgroup_height * sizeof(JSAMPROW));
3 * rgroup_height * sizeof(_JSAMPROW));
/* Fill in the above and below wraparound pointers */
for (i = 0; i < rgroup_height; i++) {
fake_buffer[i] = true_buffer[2 * rgroup_height + i];
@@ -309,12 +310,15 @@ create_context_buffer(j_compress_ptr cinfo)
*/
GLOBAL(void)
jinit_c_prep_controller(j_compress_ptr cinfo, boolean need_full_buffer)
_jinit_c_prep_controller(j_compress_ptr cinfo, boolean need_full_buffer)
{
my_prep_ptr prep;
int ci;
jpeg_component_info *compptr;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if (need_full_buffer) /* safety check */
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
@@ -331,17 +335,17 @@ jinit_c_prep_controller(j_compress_ptr cinfo, boolean need_full_buffer)
if (cinfo->downsample->need_context_rows) {
/* Set up to provide context rows */
#ifdef CONTEXT_ROWS_SUPPORTED
prep->pub.pre_process_data = pre_process_context;
prep->pub._pre_process_data = pre_process_context;
create_context_buffer(cinfo);
#else
ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif
} else {
/* No context, just make it tall enough for one row group */
prep->pub.pre_process_data = pre_process_data;
prep->pub._pre_process_data = pre_process_data;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) {
prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
prep->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE,
(JDIMENSION)(((long)compptr->width_in_blocks * DCTSIZE *
cinfo->max_h_samp_factor) / compptr->h_samp_factor),

View File

@@ -52,15 +52,16 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jsimd.h"
#include "jsamplecomp.h"
/* Pointer to routine to downsample a single component */
typedef void (*downsample1_ptr) (j_compress_ptr cinfo,
jpeg_component_info *compptr,
JSAMPARRAY input_data,
JSAMPARRAY output_data);
_JSAMPARRAY input_data,
_JSAMPARRAY output_data);
/* Private subobject */
@@ -91,11 +92,11 @@ start_pass_downsample(j_compress_ptr cinfo)
*/
LOCAL(void)
expand_right_edge(JSAMPARRAY image_data, int num_rows, JDIMENSION input_cols,
expand_right_edge(_JSAMPARRAY image_data, int num_rows, JDIMENSION input_cols,
JDIMENSION output_cols)
{
register JSAMPROW ptr;
register JSAMPLE pixval;
register _JSAMPROW ptr;
register _JSAMPLE pixval;
register int count;
int row;
int numcols = (int)(output_cols - input_cols);
@@ -118,14 +119,14 @@ expand_right_edge(JSAMPARRAY image_data, int num_rows, JDIMENSION input_cols,
*/
METHODDEF(void)
sep_downsample(j_compress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION in_row_index, JSAMPIMAGE output_buf,
sep_downsample(j_compress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION in_row_index, _JSAMPIMAGE output_buf,
JDIMENSION out_row_group_index)
{
my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample;
int ci;
jpeg_component_info *compptr;
JSAMPARRAY in_ptr, out_ptr;
_JSAMPARRAY in_ptr, out_ptr;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) {
@@ -145,12 +146,12 @@ sep_downsample(j_compress_ptr cinfo, JSAMPIMAGE input_buf,
METHODDEF(void)
int_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)
_JSAMPARRAY input_data, _JSAMPARRAY output_data)
{
int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
JSAMPROW inptr, outptr;
_JSAMPROW inptr, outptr;
JLONG outvalue;
h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
@@ -177,7 +178,7 @@ int_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
outvalue += (JLONG)(*inptr++);
}
}
*outptr++ = (JSAMPLE)((outvalue + numpix2) / numpix);
*outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix);
}
inrow += v_expand;
}
@@ -192,11 +193,11 @@ int_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
METHODDEF(void)
fullsize_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)
_JSAMPARRAY input_data, _JSAMPARRAY output_data)
{
/* Copy the data */
jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
cinfo->image_width);
_jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
cinfo->image_width);
/* Edge-expand */
expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
compptr->width_in_blocks * DCTSIZE);
@@ -217,12 +218,12 @@ fullsize_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
METHODDEF(void)
h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)
_JSAMPARRAY input_data, _JSAMPARRAY output_data)
{
int outrow;
JDIMENSION outcol;
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
register JSAMPROW inptr, outptr;
register _JSAMPROW inptr, outptr;
register int bias;
/* Expand input data enough to let all the output samples be generated
@@ -237,7 +238,7 @@ h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
inptr = input_data[outrow];
bias = 0; /* bias = 0,1,0,1,... for successive samples */
for (outcol = 0; outcol < output_cols; outcol++) {
*outptr++ = (JSAMPLE)((inptr[0] + inptr[1] + bias) >> 1);
*outptr++ = (_JSAMPLE)((inptr[0] + inptr[1] + bias) >> 1);
bias ^= 1; /* 0=>1, 1=>0 */
inptr += 2;
}
@@ -253,12 +254,12 @@ h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
METHODDEF(void)
h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)
_JSAMPARRAY input_data, _JSAMPARRAY output_data)
{
int inrow, outrow;
JDIMENSION outcol;
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
register JSAMPROW inptr0, inptr1, outptr;
register _JSAMPROW inptr0, inptr1, outptr;
register int bias;
/* Expand input data enough to let all the output samples be generated
@@ -275,8 +276,8 @@ h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
inptr1 = input_data[inrow + 1];
bias = 1; /* bias = 1,2,1,2,... for successive samples */
for (outcol = 0; outcol < output_cols; outcol++) {
*outptr++ =
(JSAMPLE)((inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1] + bias) >> 2);
*outptr++ = (_JSAMPLE)
((inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1] + bias) >> 2);
bias ^= 3; /* 1=>2, 2=>1 */
inptr0 += 2; inptr1 += 2;
}
@@ -295,12 +296,12 @@ h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
METHODDEF(void)
h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)
_JSAMPARRAY input_data, _JSAMPARRAY output_data)
{
int inrow, outrow;
JDIMENSION colctr;
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
register _JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
JLONG membersum, neighsum, memberscale, neighscale;
/* Expand input data enough to let all the output samples be generated
@@ -341,7 +342,7 @@ h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
neighsum += neighsum;
neighsum += above_ptr[0] + above_ptr[2] + below_ptr[0] + below_ptr[2];
membersum = membersum * memberscale + neighsum * neighscale;
*outptr++ = (JSAMPLE)((membersum + 32768) >> 16);
*outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
for (colctr = output_cols - 2; colctr > 0; colctr--) {
@@ -357,7 +358,7 @@ h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
/* form final output scaled up by 2^16 */
membersum = membersum * memberscale + neighsum * neighscale;
/* round, descale and output it */
*outptr++ = (JSAMPLE)((membersum + 32768) >> 16);
*outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
}
@@ -368,7 +369,7 @@ h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
neighsum += neighsum;
neighsum += above_ptr[-1] + above_ptr[1] + below_ptr[-1] + below_ptr[1];
membersum = membersum * memberscale + neighsum * neighscale;
*outptr = (JSAMPLE)((membersum + 32768) >> 16);
*outptr = (_JSAMPLE)((membersum + 32768) >> 16);
inrow += 2;
}
@@ -383,12 +384,12 @@ h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
METHODDEF(void)
fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)
_JSAMPARRAY input_data, _JSAMPARRAY output_data)
{
int outrow;
JDIMENSION colctr;
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
register JSAMPROW inptr, above_ptr, below_ptr, outptr;
register _JSAMPROW inptr, above_ptr, below_ptr, outptr;
JLONG membersum, neighsum, memberscale, neighscale;
int colsum, lastcolsum, nextcolsum;
@@ -420,7 +421,7 @@ fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
neighsum = colsum + (colsum - membersum) + nextcolsum;
membersum = membersum * memberscale + neighsum * neighscale;
*outptr++ = (JSAMPLE)((membersum + 32768) >> 16);
*outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
lastcolsum = colsum; colsum = nextcolsum;
for (colctr = output_cols - 2; colctr > 0; colctr--) {
@@ -429,7 +430,7 @@ fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
membersum = membersum * memberscale + neighsum * neighscale;
*outptr++ = (JSAMPLE)((membersum + 32768) >> 16);
*outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
lastcolsum = colsum; colsum = nextcolsum;
}
@@ -437,7 +438,7 @@ fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
membersum = *inptr;
neighsum = lastcolsum + (colsum - membersum) + colsum;
membersum = membersum * memberscale + neighsum * neighscale;
*outptr = (JSAMPLE)((membersum + 32768) >> 16);
*outptr = (_JSAMPLE)((membersum + 32768) >> 16);
}
}
@@ -451,19 +452,22 @@ fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jinit_downsampler(j_compress_ptr cinfo)
_jinit_downsampler(j_compress_ptr cinfo)
{
my_downsample_ptr downsample;
int ci;
jpeg_component_info *compptr;
boolean smoothok = TRUE;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
downsample = (my_downsample_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_downsampler));
cinfo->downsample = (struct jpeg_downsampler *)downsample;
downsample->pub.start_pass = start_pass_downsample;
downsample->pub.downsample = sep_downsample;
downsample->pub._downsample = sep_downsample;
downsample->pub.need_context_rows = FALSE;
if (cinfo->CCIR601_sampling)
@@ -484,15 +488,17 @@ jinit_downsampler(j_compress_ptr cinfo)
} else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
compptr->v_samp_factor == cinfo->max_v_samp_factor) {
smoothok = FALSE;
#ifdef WITH_SIMD
if (jsimd_can_h2v1_downsample())
downsample->methods[ci] = jsimd_h2v1_downsample;
else
#endif
downsample->methods[ci] = h2v1_downsample;
} else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
#ifdef INPUT_SMOOTHING_SUPPORTED
if (cinfo->smoothing_factor) {
#if defined(__mips__)
#if defined(WITH_SIMD) && defined(__mips__)
if (jsimd_can_h2v2_smooth_downsample())
downsample->methods[ci] = jsimd_h2v2_smooth_downsample;
else
@@ -502,9 +508,11 @@ jinit_downsampler(j_compress_ptr cinfo)
} else
#endif
{
#ifdef WITH_SIMD
if (jsimd_can_h2v2_downsample())
downsample->methods[ci] = jsimd_h2v2_downsample;
else
#endif
downsample->methods[ci] = h2v2_downsample;
}
} else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&

View File

@@ -16,8 +16,8 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpegcomp.h"
#include "jpeglib.h"
#include "jpegapicomp.h"
/* Forward declarations */
@@ -364,6 +364,17 @@ compress_output(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
}
#ifdef WITH_12BIT
METHODDEF(boolean)
compress_output_12(j_compress_ptr cinfo, J12SAMPIMAGE input_buf)
{
return compress_output(cinfo, (JSAMPIMAGE)input_buf);
}
#endif
/*
* Initialize coefficient buffer controller.
*
@@ -386,6 +397,9 @@ transencode_coef_controller(j_compress_ptr cinfo,
cinfo->coef = (struct jpeg_c_coef_controller *)coef;
coef->pub.start_pass = start_pass_coef;
coef->pub.compress_data = compress_output;
#ifdef WITH_12BIT
coef->pub.compress_data_12 = compress_output_12;
#endif
/* Save pointer to virtual arrays */
coef->whole_image = coef_arrays;

View File

@@ -21,7 +21,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jdmaster.h"
@@ -82,6 +82,8 @@ jpeg_CreateDecompress(j_decompress_ptr cinfo, int version, size_t structsize)
/* And initialize the overall input controller. */
jinit_input_controller(cinfo);
cinfo->data_precision = BITS_IN_JSAMPLE;
/* OK, I'm ready */
cinfo->global_state = DSTATE_START;

View File

@@ -26,6 +26,8 @@
#include "jdsample.h"
#include "jmemsys.h"
#if BITS_IN_JSAMPLE == 8
/* Forward declarations */
LOCAL(boolean) output_pass_setup(j_decompress_ptr cinfo);
@@ -121,8 +123,15 @@ output_pass_setup(j_decompress_ptr cinfo)
}
/* Process some data */
last_scanline = cinfo->output_scanline;
(*cinfo->main->process_data) (cinfo, (JSAMPARRAY)NULL,
&cinfo->output_scanline, (JDIMENSION)0);
#ifdef WITH_12BIT
if (cinfo->data_precision == 12)
(*cinfo->main->process_data_12) (cinfo, (J12SAMPARRAY)NULL,
&cinfo->output_scanline,
(JDIMENSION)0);
else
#endif
(*cinfo->main->process_data) (cinfo, (JSAMPARRAY)NULL,
&cinfo->output_scanline, (JDIMENSION)0);
if (cinfo->output_scanline == last_scanline)
return FALSE; /* No progress made, must suspend */
}
@@ -135,25 +144,27 @@ output_pass_setup(j_decompress_ptr cinfo)
#endif /* QUANT_2PASS_SUPPORTED */
}
/* Ready for application to drive output pass through
* jpeg_read_scanlines or jpeg_read_raw_data.
* _jpeg_read_scanlines or _jpeg_read_raw_data.
*/
cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
return TRUE;
}
#endif /* BITS_IN_JSAMPLE == 8 */
/*
* Enable partial scanline decompression
*
* Must be called after jpeg_start_decompress() and before any calls to
* jpeg_read_scanlines() or jpeg_skip_scanlines().
* _jpeg_read_scanlines() or _jpeg_skip_scanlines().
*
* Refer to libjpeg.txt for more information.
*/
GLOBAL(void)
jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
JDIMENSION *width)
_jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
JDIMENSION *width)
{
int ci, align, orig_downsampled_width;
JDIMENSION input_xoffset;
@@ -163,6 +174,9 @@ jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
my_master_ptr master = (my_master_ptr)cinfo->master;
#endif
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if ((cinfo->global_state != DSTATE_SCANNING &&
cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
@@ -254,7 +268,7 @@ jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
if (reinit_upsampler) {
cinfo->master->jinit_upsampler_no_alloc = TRUE;
jinit_upsampler(cinfo);
_jinit_upsampler(cinfo);
cinfo->master->jinit_upsampler_no_alloc = FALSE;
}
}
@@ -268,17 +282,20 @@ jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
* including bottom of image, data source suspension, and operating
* modes that emit multiple scanlines at a time.
*
* Note: we warn about excess calls to jpeg_read_scanlines() since
* Note: we warn about excess calls to _jpeg_read_scanlines() since
* this likely signals an application programmer error. However,
* an oversize buffer (max_lines > scanlines remaining) is not an error.
*/
GLOBAL(JDIMENSION)
jpeg_read_scanlines(j_decompress_ptr cinfo, JSAMPARRAY scanlines,
JDIMENSION max_lines)
_jpeg_read_scanlines(j_decompress_ptr cinfo, _JSAMPARRAY scanlines,
JDIMENSION max_lines)
{
JDIMENSION row_ctr;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if (cinfo->global_state != DSTATE_SCANNING)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
if (cinfo->output_scanline >= cinfo->output_height) {
@@ -295,30 +312,30 @@ jpeg_read_scanlines(j_decompress_ptr cinfo, JSAMPARRAY scanlines,
/* Process some data */
row_ctr = 0;
(*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
(*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
cinfo->output_scanline += row_ctr;
return row_ctr;
}
/* Dummy color convert function used by jpeg_skip_scanlines() */
/* Dummy color convert function used by _jpeg_skip_scanlines() */
LOCAL(void)
noop_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
noop_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
{
}
/* Dummy quantize function used by jpeg_skip_scanlines() */
/* Dummy quantize function used by _jpeg_skip_scanlines() */
LOCAL(void)
noop_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows)
noop_quantize(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPARRAY output_buf, int num_rows)
{
}
/*
* In some cases, it is best to call jpeg_read_scanlines() and discard the
* In some cases, it is best to call _jpeg_read_scanlines() and discard the
* output, rather than skipping the scanlines, because this allows us to
* maintain the internal state of the context-based upsampler. In these cases,
* we set up and tear down a dummy color converter in order to avoid valgrind
@@ -332,27 +349,27 @@ read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
#ifdef UPSAMPLE_MERGING_SUPPORTED
my_master_ptr master = (my_master_ptr)cinfo->master;
#endif
JSAMPLE dummy_sample[1] = { 0 };
JSAMPROW dummy_row = dummy_sample;
JSAMPARRAY scanlines = NULL;
void (*color_convert) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf,
_JSAMPLE dummy_sample[1] = { 0 };
_JSAMPROW dummy_row = dummy_sample;
_JSAMPARRAY scanlines = NULL;
void (*color_convert) (j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf,
int num_rows) = NULL;
void (*color_quantize) (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) = NULL;
void (*color_quantize) (j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPARRAY output_buf, int num_rows) = NULL;
if (cinfo->cconvert && cinfo->cconvert->color_convert) {
color_convert = cinfo->cconvert->color_convert;
cinfo->cconvert->color_convert = noop_convert;
if (cinfo->cconvert && cinfo->cconvert->_color_convert) {
color_convert = cinfo->cconvert->_color_convert;
cinfo->cconvert->_color_convert = noop_convert;
/* This just prevents UBSan from complaining about adding 0 to a NULL
* pointer. The pointer isn't actually used.
*/
scanlines = &dummy_row;
}
if (cinfo->cquantize && cinfo->cquantize->color_quantize) {
color_quantize = cinfo->cquantize->color_quantize;
cinfo->cquantize->color_quantize = noop_quantize;
if (cinfo->cquantize && cinfo->cquantize->_color_quantize) {
color_quantize = cinfo->cquantize->_color_quantize;
cinfo->cquantize->_color_quantize = noop_quantize;
}
#ifdef UPSAMPLE_MERGING_SUPPORTED
@@ -363,19 +380,19 @@ read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
#endif
for (n = 0; n < num_lines; n++)
jpeg_read_scanlines(cinfo, scanlines, 1);
_jpeg_read_scanlines(cinfo, scanlines, 1);
if (color_convert)
cinfo->cconvert->color_convert = color_convert;
cinfo->cconvert->_color_convert = color_convert;
if (color_quantize)
cinfo->cquantize->color_quantize = color_quantize;
cinfo->cquantize->_color_quantize = color_quantize;
}
/*
* Called by jpeg_skip_scanlines(). This partially skips a decompress block by
* incrementing the rowgroup counter.
* Called by _jpeg_skip_scanlines(). This partially skips a decompress block
* by incrementing the rowgroup counter.
*/
LOCAL(void)
@@ -414,7 +431,7 @@ increment_simple_rowgroup_ctr(j_decompress_ptr cinfo, JDIMENSION rows)
*/
GLOBAL(JDIMENSION)
jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
_jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
{
my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
@@ -425,6 +442,9 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
JDIMENSION lines_to_skip, lines_to_read;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Two-pass color quantization is not supported. */
if (cinfo->quantize_colors && cinfo->two_pass_quantize)
ERREXIT(cinfo, JERR_NOTIMPL);
@@ -597,11 +617,14 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
*/
GLOBAL(JDIMENSION)
jpeg_read_raw_data(j_decompress_ptr cinfo, JSAMPIMAGE data,
JDIMENSION max_lines)
_jpeg_read_raw_data(j_decompress_ptr cinfo, _JSAMPIMAGE data,
JDIMENSION max_lines)
{
JDIMENSION lines_per_iMCU_row;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if (cinfo->global_state != DSTATE_RAW_OK)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
if (cinfo->output_scanline >= cinfo->output_height) {
@@ -622,7 +645,7 @@ jpeg_read_raw_data(j_decompress_ptr cinfo, JSAMPIMAGE data,
ERREXIT(cinfo, JERR_BUFFER_SIZE);
/* Decompress directly into user's buffer. */
if (!(*cinfo->coef->decompress_data) (cinfo, data))
if (!(*cinfo->coef->_decompress_data) (cinfo, data))
return 0; /* suspension forced, can do nothing more */
/* OK, we processed one iMCU row. */
@@ -631,6 +654,8 @@ jpeg_read_raw_data(j_decompress_ptr cinfo, JSAMPIMAGE data,
}
#if BITS_IN_JSAMPLE == 8
/* Additional entry points for buffered-image mode. */
#ifdef D_MULTISCAN_FILES_SUPPORTED
@@ -687,3 +712,5 @@ jpeg_finish_output(j_decompress_ptr cinfo)
}
#endif /* D_MULTISCAN_FILES_SUPPORTED */
#endif /* BITS_IN_JSAMPLE == 8 */

View File

@@ -752,6 +752,9 @@ jinit_arith_decoder(j_decompress_ptr cinfo)
arith_entropy_ptr entropy;
int i;
if (cinfo->data_precision != 8)
ERREXIT(cinfo, JERR_NOTIMPL);
entropy = (arith_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(arith_entropy_decoder));

View File

@@ -20,8 +20,8 @@
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
#include "jinclude.h"
#include "jpeglibint.h"
#include "jerrorint.h"
#include "jpeglib.h"
#include "jerror.h"
/* Expanded data destination object for stdio output */

View File

@@ -20,8 +20,8 @@
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
#include "jinclude.h"
#include "jpeglibint.h"
#include "jerrorint.h"
#include "jpeglib.h"
#include "jerror.h"
/* Expanded data source object for stdio input */

View File

@@ -21,19 +21,20 @@
#include "jinclude.h"
#include "jdcoefct.h"
#include "jpegcomp.h"
#include "jpegapicomp.h"
#include "jsamplecomp.h"
/* Forward declarations */
METHODDEF(int) decompress_onepass(j_decompress_ptr cinfo,
JSAMPIMAGE output_buf);
_JSAMPIMAGE output_buf);
#ifdef D_MULTISCAN_FILES_SUPPORTED
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf);
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
#endif
#ifdef BLOCK_SMOOTHING_SUPPORTED
LOCAL(boolean) smoothing_ok(j_decompress_ptr cinfo);
METHODDEF(int) decompress_smooth_data(j_decompress_ptr cinfo,
JSAMPIMAGE output_buf);
_JSAMPIMAGE output_buf);
#endif
@@ -62,9 +63,9 @@ start_output_pass(j_decompress_ptr cinfo)
/* If multipass, check to see whether to use block smoothing on this pass */
if (coef->pub.coef_arrays != NULL) {
if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
coef->pub.decompress_data = decompress_smooth_data;
coef->pub._decompress_data = decompress_smooth_data;
else
coef->pub.decompress_data = decompress_data;
coef->pub._decompress_data = decompress_data;
}
#endif
cinfo->output_iMCU_row = 0;
@@ -82,17 +83,17 @@ start_output_pass(j_decompress_ptr cinfo)
*/
METHODDEF(int)
decompress_onepass(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
decompress_onepass(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
{
my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
JDIMENSION MCU_col_num; /* index of current MCU within row */
JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
int blkn, ci, xindex, yindex, yoffset, useful_width;
JSAMPARRAY output_ptr;
_JSAMPARRAY output_ptr;
JDIMENSION start_col, output_col;
jpeg_component_info *compptr;
inverse_DCT_method_ptr inverse_DCT;
_inverse_DCT_method_ptr inverse_DCT;
/* Loop to process as much as one whole iMCU row */
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
@@ -129,7 +130,7 @@ decompress_onepass(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
blkn += compptr->MCU_blocks;
continue;
}
inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
useful_width = (MCU_col_num < last_MCU_col) ?
compptr->MCU_width : compptr->last_col_width;
output_ptr = output_buf[compptr->component_index] +
@@ -262,7 +263,7 @@ consume_data(j_decompress_ptr cinfo)
*/
METHODDEF(int)
decompress_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
{
my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
@@ -270,10 +271,10 @@ decompress_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
int ci, block_row, block_rows;
JBLOCKARRAY buffer;
JBLOCKROW buffer_ptr;
JSAMPARRAY output_ptr;
_JSAMPARRAY output_ptr;
JDIMENSION output_col;
jpeg_component_info *compptr;
inverse_DCT_method_ptr inverse_DCT;
_inverse_DCT_method_ptr inverse_DCT;
/* Force some input to be done if we are getting ahead of the input. */
while (cinfo->input_scan_number < cinfo->output_scan_number ||
@@ -302,7 +303,7 @@ decompress_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
if (block_rows == 0) block_rows = compptr->v_samp_factor;
}
inverse_DCT = cinfo->idct->inverse_DCT[ci];
inverse_DCT = cinfo->idct->_inverse_DCT[ci];
output_ptr = output_buf[ci];
/* Loop over all DCT blocks to be processed. */
for (block_row = 0; block_row < block_rows; block_row++) {
@@ -425,7 +426,7 @@ smoothing_ok(j_decompress_ptr cinfo)
*/
METHODDEF(int)
decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
decompress_smooth_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
{
my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
@@ -434,10 +435,10 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
JBLOCKARRAY buffer;
JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
JBLOCKROW next_block_row, next_next_block_row;
JSAMPARRAY output_ptr;
_JSAMPARRAY output_ptr;
JDIMENSION output_col;
jpeg_component_info *compptr;
inverse_DCT_method_ptr inverse_DCT;
_inverse_DCT_method_ptr inverse_DCT;
boolean change_dc;
JCOEF *workspace;
int *coef_bits;
@@ -535,7 +536,7 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
Q21 = quanttbl->quantval[Q21_POS];
Q30 = quanttbl->quantval[Q30_POS];
}
inverse_DCT = cinfo->idct->inverse_DCT[ci];
inverse_DCT = cinfo->idct->_inverse_DCT[ci];
output_ptr = output_buf[ci];
/* Loop over all DCT blocks to be processed. */
for (block_row = 0; block_row < block_rows; block_row++) {
@@ -810,10 +811,13 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
*/
GLOBAL(void)
jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
_jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
{
my_coef_ptr coef;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
coef = (my_coef_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_coef_controller));
@@ -850,7 +854,7 @@ jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
(JDIMENSION)access_rows);
}
coef->pub.consume_data = consume_data;
coef->pub.decompress_data = decompress_data;
coef->pub._decompress_data = decompress_data;
coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
#else
ERREXIT(cinfo, JERR_NOT_COMPILED);
@@ -867,7 +871,7 @@ jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
coef->MCU_buffer[i] = buffer + i;
}
coef->pub.consume_data = dummy_consume_data;
coef->pub.decompress_data = decompress_onepass;
coef->pub._decompress_data = decompress_onepass;
coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
}

View File

@@ -6,13 +6,12 @@
* libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2020, Google, Inc.
* Copyright (C) 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*/
#define JPEG_INTERNALS
#include "jpeglibint.h"
#include "jpeglib.h"
/* Block smoothing is only applicable for progressive JPEG, so: */

View File

@@ -5,7 +5,7 @@
* Copyright (C) 1991-1997, Thomas G. Lane.
* Modifications:
* Copyright (C) 2013, Linaro Limited.
* Copyright (C) 2014-2015, D. R. Commander.
* Copyright (C) 2014-2015, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -17,18 +17,18 @@
INLINE
LOCAL(void)
ycc_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf,
ycc_rgb565_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf,
int num_rows)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int y, cb, cr;
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register _JSAMPROW outptr;
register _JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
/* copy these pointers into registers if possible */
register JSAMPLE *range_limit = cinfo->sample_range_limit;
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
register int *Crrtab = cconvert->Cr_r_tab;
register int *Cbbtab = cconvert->Cb_b_tab;
register JLONG *Crgtab = cconvert->Cr_g_tab;
@@ -96,18 +96,18 @@ ycc_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
INLINE
LOCAL(void)
ycc_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf,
ycc_rgb565D_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf,
int num_rows)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int y, cb, cr;
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register _JSAMPROW outptr;
register _JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
/* copy these pointers into registers if possible */
register JSAMPLE *range_limit = cinfo->sample_range_limit;
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
register int *Crrtab = cconvert->Cr_r_tab;
register int *Cbbtab = cconvert->Cb_b_tab;
register JLONG *Crgtab = cconvert->Cr_g_tab;
@@ -182,12 +182,12 @@ ycc_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
INLINE
LOCAL(void)
rgb_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf,
rgb_rgb565_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf,
int num_rows)
{
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register _JSAMPROW outptr;
register _JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
SHIFT_TEMPS
@@ -237,14 +237,14 @@ rgb_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
INLINE
LOCAL(void)
rgb_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf,
rgb_rgb565D_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf,
int num_rows)
{
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register _JSAMPROW outptr;
register _JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
register JSAMPLE *range_limit = cinfo->sample_range_limit;
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
JDIMENSION num_cols = cinfo->output_width;
JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];
SHIFT_TEMPS
@@ -296,11 +296,11 @@ rgb_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
INLINE
LOCAL(void)
gray_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf,
gray_rgb565_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf,
int num_rows)
{
register JSAMPROW inptr, outptr;
register _JSAMPROW inptr, outptr;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
@@ -336,13 +336,13 @@ gray_rgb565_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
INLINE
LOCAL(void)
gray_rgb565D_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf,
gray_rgb565D_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf,
int num_rows)
{
register JSAMPROW inptr, outptr;
register _JSAMPROW inptr, outptr;
register JDIMENSION col;
register JSAMPLE *range_limit = cinfo->sample_range_limit;
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
JDIMENSION num_cols = cinfo->output_width;
JLONG d0 = dither_matrix[cinfo->output_scanline & DITHER_MASK];

View File

@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2009, 2011, 2015, D. R. Commander.
* Copyright (C) 2009, 2011, 2015, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -28,18 +28,18 @@
INLINE
LOCAL(void)
ycc_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf,
ycc_rgb_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf,
int num_rows)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int y, cb, cr;
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register _JSAMPROW outptr;
register _JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
/* copy these pointers into registers if possible */
register JSAMPLE *range_limit = cinfo->sample_range_limit;
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
register int *Crrtab = cconvert->Cr_r_tab;
register int *Cbbtab = cconvert->Cb_b_tab;
register JLONG *Crgtab = cconvert->Cr_g_tab;
@@ -81,11 +81,11 @@ ycc_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
INLINE
LOCAL(void)
gray_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf,
gray_rgb_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf,
int num_rows)
{
register JSAMPROW inptr, outptr;
register _JSAMPROW inptr, outptr;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
@@ -111,12 +111,12 @@ gray_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
INLINE
LOCAL(void)
rgb_rgb_convert_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf,
rgb_rgb_convert_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf,
int num_rows)
{
register JSAMPROW inptr0, inptr1, inptr2;
register JSAMPROW outptr;
register _JSAMPROW inptr0, inptr1, inptr2;
register _JSAMPROW outptr;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;

158
jdcolor.c
View File

@@ -16,8 +16,9 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jsimd.h"
#include "jsamplecomp.h"
/* Private subobject */
@@ -43,7 +44,7 @@ typedef my_color_deconverter *my_cconvert_ptr;
/*
* YCbCr is defined per CCIR 601-1, except that Cb and Cr are
* normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
* normalized to the range 0.._MAXJSAMPLE rather than -0.5 .. 0.5.
* The conversion equations to be implemented are therefore
*
* R = Y + 1.40200 * Cr
@@ -52,7 +53,7 @@ typedef my_color_deconverter *my_cconvert_ptr;
*
* Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
*
* where Cb and Cr represent the incoming values less CENTERJSAMPLE.
* where Cb and Cr represent the incoming values less _CENTERJSAMPLE.
* (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
*
* To avoid floating-point arithmetic, we represent the fractional constants
@@ -63,7 +64,7 @@ typedef my_color_deconverter *my_cconvert_ptr;
*
* For even more speed, we avoid doing any multiplications in the inner loop
* by precalculating the constants times Cb and Cr for all possible values.
* For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
* For 8-bit samples this is very reasonable (only 256 entries per table);
* for 12-bit samples it is still acceptable. It's not very reasonable for
* 16-bit samples, but if you want lossless storage you shouldn't be changing
* colorspace anyway.
@@ -84,9 +85,9 @@ typedef my_color_deconverter *my_cconvert_ptr;
*/
#define R_Y_OFF 0 /* offset to R => Y section */
#define G_Y_OFF (1 * (MAXJSAMPLE + 1)) /* offset to G => Y section */
#define B_Y_OFF (2 * (MAXJSAMPLE + 1)) /* etc. */
#define TABLE_SIZE (3 * (MAXJSAMPLE + 1))
#define G_Y_OFF (1 * (_MAXJSAMPLE + 1)) /* offset to G => Y section */
#define B_Y_OFF (2 * (_MAXJSAMPLE + 1)) /* etc. */
#define TABLE_SIZE (3 * (_MAXJSAMPLE + 1))
/* Include inline routines for colorspace extensions */
@@ -216,20 +217,20 @@ build_ycc_rgb_table(j_decompress_ptr cinfo)
cconvert->Cr_r_tab = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE + 1) * sizeof(int));
(_MAXJSAMPLE + 1) * sizeof(int));
cconvert->Cb_b_tab = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE + 1) * sizeof(int));
(_MAXJSAMPLE + 1) * sizeof(int));
cconvert->Cr_g_tab = (JLONG *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE + 1) * sizeof(JLONG));
(_MAXJSAMPLE + 1) * sizeof(JLONG));
cconvert->Cb_g_tab = (JLONG *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE + 1) * sizeof(JLONG));
(_MAXJSAMPLE + 1) * sizeof(JLONG));
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
for (i = 0, x = -_CENTERJSAMPLE; i <= _MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0.._MAXJSAMPLE */
/* The Cb or Cr value we are thinking of is x = i - _CENTERJSAMPLE */
/* Cr=>R value is nearest int to 1.40200 * x */
cconvert->Cr_r_tab[i] = (int)
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
@@ -250,8 +251,8 @@ build_ycc_rgb_table(j_decompress_ptr cinfo)
*/
METHODDEF(void)
ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
ycc_rgb_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
{
switch (cinfo->out_color_space) {
case JCS_EXT_RGB:
@@ -309,7 +310,7 @@ build_rgb_y_table(j_decompress_ptr cinfo)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(TABLE_SIZE * sizeof(JLONG)));
for (i = 0; i <= MAXJSAMPLE; i++) {
for (i = 0; i <= _MAXJSAMPLE; i++) {
rgb_y_tab[i + R_Y_OFF] = FIX(0.29900) * i;
rgb_y_tab[i + G_Y_OFF] = FIX(0.58700) * i;
rgb_y_tab[i + B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
@@ -322,14 +323,14 @@ build_rgb_y_table(j_decompress_ptr cinfo)
*/
METHODDEF(void)
rgb_gray_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
rgb_gray_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int r, g, b;
register JLONG *ctab = cconvert->rgb_y_tab;
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register _JSAMPROW outptr;
register _JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
@@ -344,8 +345,8 @@ rgb_gray_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
g = inptr1[col];
b = inptr2[col];
/* Y */
outptr[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
ctab[b + B_Y_OFF]) >> SCALEBITS);
outptr[col] = (_JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
ctab[b + B_Y_OFF]) >> SCALEBITS);
}
}
}
@@ -357,10 +358,10 @@ rgb_gray_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
*/
METHODDEF(void)
null_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
null_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
{
register JSAMPROW inptr, inptr0, inptr1, inptr2, inptr3, outptr;
register _JSAMPROW inptr, inptr0, inptr1, inptr2, inptr3, outptr;
register JDIMENSION col;
register int num_components = cinfo->num_components;
JDIMENSION num_cols = cinfo->output_width;
@@ -418,11 +419,11 @@ null_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
*/
METHODDEF(void)
grayscale_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
grayscale_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
{
jcopy_sample_rows(input_buf[0], (int)input_row, output_buf, 0, num_rows,
cinfo->output_width);
_jcopy_sample_rows(input_buf[0], (int)input_row, output_buf, 0, num_rows,
cinfo->output_width);
}
@@ -431,8 +432,8 @@ grayscale_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
*/
METHODDEF(void)
gray_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
gray_rgb_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
{
switch (cinfo->out_color_space) {
case JCS_EXT_RGB:
@@ -476,8 +477,8 @@ gray_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
*/
METHODDEF(void)
rgb_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
rgb_rgb_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
{
switch (cinfo->out_color_space) {
case JCS_EXT_RGB:
@@ -524,17 +525,17 @@ rgb_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
*/
METHODDEF(void)
ycck_cmyk_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
ycck_cmyk_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert;
register int y, cb, cr;
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2, inptr3;
register _JSAMPROW outptr;
register _JSAMPROW inptr0, inptr1, inptr2, inptr3;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
/* copy these pointers into registers if possible */
register JSAMPLE *range_limit = cinfo->sample_range_limit;
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
register int *Crrtab = cconvert->Cr_r_tab;
register int *Cbbtab = cconvert->Cb_b_tab;
register JLONG *Crgtab = cconvert->Cr_g_tab;
@@ -553,11 +554,11 @@ ycck_cmyk_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
cb = inptr1[col];
cr = inptr2[col];
/* Range-limiting is essential due to noise introduced by DCT losses. */
outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
outptr[0] = range_limit[_MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
outptr[1] = range_limit[_MAXJSAMPLE - (y + /* green */
((int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS)))];
outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
outptr[2] = range_limit[_MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
/* K passes through unchanged */
outptr[3] = inptr3[col];
outptr += 4;
@@ -652,8 +653,8 @@ static INLINE boolean is_big_endian(void)
METHODDEF(void)
ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
ycc_rgb565_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
{
if (is_big_endian())
ycc_rgb565_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
@@ -663,8 +664,8 @@ ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
METHODDEF(void)
ycc_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
ycc_rgb565D_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
{
if (is_big_endian())
ycc_rgb565D_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
@@ -674,8 +675,8 @@ ycc_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
METHODDEF(void)
rgb_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
rgb_rgb565_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
{
if (is_big_endian())
rgb_rgb565_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
@@ -685,8 +686,8 @@ rgb_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
METHODDEF(void)
rgb_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
rgb_rgb565D_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
{
if (is_big_endian())
rgb_rgb565D_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
@@ -696,8 +697,8 @@ rgb_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
METHODDEF(void)
gray_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
gray_rgb565_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
{
if (is_big_endian())
gray_rgb565_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
@@ -707,8 +708,8 @@ gray_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
METHODDEF(void)
gray_rgb565D_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
gray_rgb565D_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
{
if (is_big_endian())
gray_rgb565D_convert_be(cinfo, input_buf, input_row, output_buf, num_rows);
@@ -733,11 +734,14 @@ start_pass_dcolor(j_decompress_ptr cinfo)
*/
GLOBAL(void)
jinit_color_deconverter(j_decompress_ptr cinfo)
_jinit_color_deconverter(j_decompress_ptr cinfo)
{
my_cconvert_ptr cconvert;
int ci;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
cconvert = (my_cconvert_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_color_deconverter));
@@ -779,12 +783,12 @@ jinit_color_deconverter(j_decompress_ptr cinfo)
cinfo->out_color_components = 1;
if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
cinfo->jpeg_color_space == JCS_YCbCr) {
cconvert->pub.color_convert = grayscale_convert;
cconvert->pub._color_convert = grayscale_convert;
/* For color->grayscale conversion, only the Y (0) component is needed */
for (ci = 1; ci < cinfo->num_components; ci++)
cinfo->comp_info[ci].component_needed = FALSE;
} else if (cinfo->jpeg_color_space == JCS_RGB) {
cconvert->pub.color_convert = rgb_gray_convert;
cconvert->pub._color_convert = rgb_gray_convert;
build_rgb_y_table(cinfo);
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
@@ -803,22 +807,25 @@ jinit_color_deconverter(j_decompress_ptr cinfo)
case JCS_EXT_ARGB:
cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space];
if (cinfo->jpeg_color_space == JCS_YCbCr) {
#ifdef WITH_SIMD
if (jsimd_can_ycc_rgb())
cconvert->pub.color_convert = jsimd_ycc_rgb_convert;
else {
cconvert->pub.color_convert = ycc_rgb_convert;
cconvert->pub._color_convert = jsimd_ycc_rgb_convert;
else
#endif
{
cconvert->pub._color_convert = ycc_rgb_convert;
build_ycc_rgb_table(cinfo);
}
} else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
cconvert->pub.color_convert = gray_rgb_convert;
cconvert->pub._color_convert = gray_rgb_convert;
} else if (cinfo->jpeg_color_space == JCS_RGB) {
if (rgb_red[cinfo->out_color_space] == 0 &&
rgb_green[cinfo->out_color_space] == 1 &&
rgb_blue[cinfo->out_color_space] == 2 &&
rgb_pixelsize[cinfo->out_color_space] == 3)
cconvert->pub.color_convert = null_convert;
cconvert->pub._color_convert = null_convert;
else
cconvert->pub.color_convert = rgb_rgb_convert;
cconvert->pub._color_convert = rgb_rgb_convert;
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break;
@@ -827,27 +834,30 @@ jinit_color_deconverter(j_decompress_ptr cinfo)
cinfo->out_color_components = 3;
if (cinfo->dither_mode == JDITHER_NONE) {
if (cinfo->jpeg_color_space == JCS_YCbCr) {
#ifdef WITH_SIMD
if (jsimd_can_ycc_rgb565())
cconvert->pub.color_convert = jsimd_ycc_rgb565_convert;
else {
cconvert->pub.color_convert = ycc_rgb565_convert;
cconvert->pub._color_convert = jsimd_ycc_rgb565_convert;
else
#endif
{
cconvert->pub._color_convert = ycc_rgb565_convert;
build_ycc_rgb_table(cinfo);
}
} else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
cconvert->pub.color_convert = gray_rgb565_convert;
cconvert->pub._color_convert = gray_rgb565_convert;
} else if (cinfo->jpeg_color_space == JCS_RGB) {
cconvert->pub.color_convert = rgb_rgb565_convert;
cconvert->pub._color_convert = rgb_rgb565_convert;
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
} else {
/* only ordered dithering is supported */
if (cinfo->jpeg_color_space == JCS_YCbCr) {
cconvert->pub.color_convert = ycc_rgb565D_convert;
cconvert->pub._color_convert = ycc_rgb565D_convert;
build_ycc_rgb_table(cinfo);
} else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
cconvert->pub.color_convert = gray_rgb565D_convert;
cconvert->pub._color_convert = gray_rgb565D_convert;
} else if (cinfo->jpeg_color_space == JCS_RGB) {
cconvert->pub.color_convert = rgb_rgb565D_convert;
cconvert->pub._color_convert = rgb_rgb565D_convert;
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
@@ -856,10 +866,10 @@ jinit_color_deconverter(j_decompress_ptr cinfo)
case JCS_CMYK:
cinfo->out_color_components = 4;
if (cinfo->jpeg_color_space == JCS_YCCK) {
cconvert->pub.color_convert = ycck_cmyk_convert;
cconvert->pub._color_convert = ycck_cmyk_convert;
build_ycc_rgb_table(cinfo);
} else if (cinfo->jpeg_color_space == JCS_CMYK) {
cconvert->pub.color_convert = null_convert;
cconvert->pub._color_convert = null_convert;
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break;
@@ -868,7 +878,7 @@ jinit_color_deconverter(j_decompress_ptr cinfo)
/* Permit null conversion to same output space */
if (cinfo->out_color_space == cinfo->jpeg_color_space) {
cinfo->out_color_components = cinfo->num_components;
cconvert->pub.color_convert = null_convert;
cconvert->pub._color_convert = null_convert;
} else /* unsupported non-null conversion */
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break;

135
jdct.h
View File

@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2015, D. R. Commander.
* Copyright (C) 2015, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -15,13 +15,15 @@
* machine-dependent tuning (e.g., assembly coding).
*/
#include "jsamplecomp.h"
/*
* A forward DCT routine is given a pointer to a work area of type DCTELEM[];
* the DCT is to be performed in-place in that buffer. Type DCTELEM is int
* for 8-bit samples, JLONG for 12-bit samples. (NOTE: Floating-point DCT
* implementations use an array of type FAST_FLOAT, instead.)
* The DCT inputs are expected to be signed (range +-CENTERJSAMPLE).
* The DCT inputs are expected to be signed (range +-_CENTERJSAMPLE).
* The DCT outputs are returned scaled up by a factor of 8; they therefore
* have a range of +-8K for 8-bit data, +-128K for 12-bit data. This
* convention improves accuracy in integer implementations and saves some
@@ -76,78 +78,89 @@ typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
/*
* Each IDCT routine is responsible for range-limiting its results and
* converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
* converting them to unsigned form (0.._MAXJSAMPLE). The raw outputs could
* be quite far out of range if the input data is corrupt, so a bulletproof
* range-limiting step is required. We use a mask-and-table-lookup method
* to do the combined operations quickly. See the comments with
* prepare_range_limit_table (in jdmaster.c) for more info.
*/
#define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
#define IDCT_range_limit(cinfo) \
((_JSAMPLE *)((cinfo)->sample_range_limit) + _CENTERJSAMPLE)
#define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
#define RANGE_MASK (_MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
/* Extern declarations for the forward and inverse DCT routines. */
EXTERN(void) jpeg_fdct_islow(DCTELEM *data);
EXTERN(void) jpeg_fdct_ifast(DCTELEM *data);
EXTERN(void) _jpeg_fdct_islow(DCTELEM *data);
EXTERN(void) _jpeg_fdct_ifast(DCTELEM *data);
EXTERN(void) jpeg_fdct_float(FAST_FLOAT *data);
EXTERN(void) jpeg_idct_islow(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_ifast(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_float(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_7x7(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_6x6(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_5x5(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_4x4(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_3x3(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_2x2(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_1x1(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_9x9(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_10x10(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_11x11(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_12x12(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_13x13(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_14x14(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_15x15(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) jpeg_idct_16x16(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) _jpeg_idct_islow(j_decompress_ptr cinfo,
jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col);
EXTERN(void) _jpeg_idct_ifast(j_decompress_ptr cinfo,
jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col);
EXTERN(void) _jpeg_idct_float(j_decompress_ptr cinfo,
jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col);
EXTERN(void) _jpeg_idct_7x7(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
_JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) _jpeg_idct_6x6(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
_JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) _jpeg_idct_5x5(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
_JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) _jpeg_idct_4x4(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
_JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) _jpeg_idct_3x3(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
_JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) _jpeg_idct_2x2(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
_JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) _jpeg_idct_1x1(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
_JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) _jpeg_idct_9x9(j_decompress_ptr cinfo,
jpeg_component_info *compptr, JCOEFPTR coef_block,
_JSAMPARRAY output_buf, JDIMENSION output_col);
EXTERN(void) _jpeg_idct_10x10(j_decompress_ptr cinfo,
jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col);
EXTERN(void) _jpeg_idct_11x11(j_decompress_ptr cinfo,
jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col);
EXTERN(void) _jpeg_idct_12x12(j_decompress_ptr cinfo,
jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col);
EXTERN(void) _jpeg_idct_13x13(j_decompress_ptr cinfo,
jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col);
EXTERN(void) _jpeg_idct_14x14(j_decompress_ptr cinfo,
jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col);
EXTERN(void) _jpeg_idct_15x15(j_decompress_ptr cinfo,
jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col);
EXTERN(void) _jpeg_idct_16x16(j_decompress_ptr cinfo,
jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col);
/*

View File

@@ -23,10 +23,10 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */
#include "jsimddct.h"
#include "jpegcomp.h"
#include "jpegapicomp.h"
/*
@@ -100,7 +100,7 @@ start_pass(j_decompress_ptr cinfo)
int ci, i;
jpeg_component_info *compptr;
int method = 0;
inverse_DCT_method_ptr method_ptr = NULL;
_inverse_DCT_method_ptr method_ptr = NULL;
JQUANT_TBL *qtbl;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
@@ -109,42 +109,46 @@ start_pass(j_decompress_ptr cinfo)
switch (compptr->_DCT_scaled_size) {
#ifdef IDCT_SCALING_SUPPORTED
case 1:
method_ptr = jpeg_idct_1x1;
method_ptr = _jpeg_idct_1x1;
method = JDCT_ISLOW; /* jidctred uses islow-style table */
break;
case 2:
#ifdef WITH_SIMD
if (jsimd_can_idct_2x2())
method_ptr = jsimd_idct_2x2;
else
method_ptr = jpeg_idct_2x2;
#endif
method_ptr = _jpeg_idct_2x2;
method = JDCT_ISLOW; /* jidctred uses islow-style table */
break;
case 3:
method_ptr = jpeg_idct_3x3;
method_ptr = _jpeg_idct_3x3;
method = JDCT_ISLOW; /* jidctint uses islow-style table */
break;
case 4:
#ifdef WITH_SIMD
if (jsimd_can_idct_4x4())
method_ptr = jsimd_idct_4x4;
else
method_ptr = jpeg_idct_4x4;
#endif
method_ptr = _jpeg_idct_4x4;
method = JDCT_ISLOW; /* jidctred uses islow-style table */
break;
case 5:
method_ptr = jpeg_idct_5x5;
method_ptr = _jpeg_idct_5x5;
method = JDCT_ISLOW; /* jidctint uses islow-style table */
break;
case 6:
#if defined(__mips__)
#if defined(WITH_SIMD) && defined(__mips__)
if (jsimd_can_idct_6x6())
method_ptr = jsimd_idct_6x6;
else
#endif
method_ptr = jpeg_idct_6x6;
method_ptr = _jpeg_idct_6x6;
method = JDCT_ISLOW; /* jidctint uses islow-style table */
break;
case 7:
method_ptr = jpeg_idct_7x7;
method_ptr = _jpeg_idct_7x7;
method = JDCT_ISLOW; /* jidctint uses islow-style table */
break;
#endif
@@ -152,28 +156,34 @@ start_pass(j_decompress_ptr cinfo)
switch (cinfo->dct_method) {
#ifdef DCT_ISLOW_SUPPORTED
case JDCT_ISLOW:
#ifdef WITH_SIMD
if (jsimd_can_idct_islow())
method_ptr = jsimd_idct_islow;
else
method_ptr = jpeg_idct_islow;
#endif
method_ptr = _jpeg_idct_islow;
method = JDCT_ISLOW;
break;
#endif
#ifdef DCT_IFAST_SUPPORTED
case JDCT_IFAST:
#ifdef WITH_SIMD
if (jsimd_can_idct_ifast())
method_ptr = jsimd_idct_ifast;
else
method_ptr = jpeg_idct_ifast;
#endif
method_ptr = _jpeg_idct_ifast;
method = JDCT_IFAST;
break;
#endif
#ifdef DCT_FLOAT_SUPPORTED
case JDCT_FLOAT:
#ifdef WITH_SIMD
if (jsimd_can_idct_float())
method_ptr = jsimd_idct_float;
else
method_ptr = jpeg_idct_float;
#endif
method_ptr = _jpeg_idct_float;
method = JDCT_FLOAT;
break;
#endif
@@ -184,40 +194,40 @@ start_pass(j_decompress_ptr cinfo)
break;
#ifdef IDCT_SCALING_SUPPORTED
case 9:
method_ptr = jpeg_idct_9x9;
method_ptr = _jpeg_idct_9x9;
method = JDCT_ISLOW; /* jidctint uses islow-style table */
break;
case 10:
method_ptr = jpeg_idct_10x10;
method_ptr = _jpeg_idct_10x10;
method = JDCT_ISLOW; /* jidctint uses islow-style table */
break;
case 11:
method_ptr = jpeg_idct_11x11;
method_ptr = _jpeg_idct_11x11;
method = JDCT_ISLOW; /* jidctint uses islow-style table */
break;
case 12:
#if defined(__mips__)
#if defined(WITH_SIMD) && defined(__mips__)
if (jsimd_can_idct_12x12())
method_ptr = jsimd_idct_12x12;
else
#endif
method_ptr = jpeg_idct_12x12;
method_ptr = _jpeg_idct_12x12;
method = JDCT_ISLOW; /* jidctint uses islow-style table */
break;
case 13:
method_ptr = jpeg_idct_13x13;
method_ptr = _jpeg_idct_13x13;
method = JDCT_ISLOW; /* jidctint uses islow-style table */
break;
case 14:
method_ptr = jpeg_idct_14x14;
method_ptr = _jpeg_idct_14x14;
method = JDCT_ISLOW; /* jidctint uses islow-style table */
break;
case 15:
method_ptr = jpeg_idct_15x15;
method_ptr = _jpeg_idct_15x15;
method = JDCT_ISLOW; /* jidctint uses islow-style table */
break;
case 16:
method_ptr = jpeg_idct_16x16;
method_ptr = _jpeg_idct_16x16;
method = JDCT_ISLOW; /* jidctint uses islow-style table */
break;
#endif
@@ -225,7 +235,7 @@ start_pass(j_decompress_ptr cinfo)
ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->_DCT_scaled_size);
break;
}
idct->pub.inverse_DCT[ci] = method_ptr;
idct->pub._inverse_DCT[ci] = method_ptr;
/* Create multiplier table from quant table.
* However, we can skip this if the component is uninteresting
* or if we already built the table. Also, if no quant table
@@ -327,12 +337,15 @@ start_pass(j_decompress_ptr cinfo)
*/
GLOBAL(void)
jinit_inverse_dct(j_decompress_ptr cinfo)
_jinit_inverse_dct(j_decompress_ptr cinfo)
{
my_idct_ptr idct;
int ci;
jpeg_component_info *compptr;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
idct = (my_idct_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_idct_controller));

View File

@@ -23,9 +23,9 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jdhuff.h" /* Declarations shared with jdphuff.c */
#include "jpegcomp.h"
#include "jpegapicomp.h"
#include "jstdhuff.c"

View File

@@ -2,7 +2,7 @@
* jdicc.c
*
* Copyright (C) 1997-1998, Thomas G. Lane, Todd Newman.
* Copyright (C) 2017, 2022, D. R. Commander.
* Copyright (C) 2017, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -15,8 +15,8 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jerrorint.h"
#include "jpeglib.h"
#include "jerror.h"
#define ICC_MARKER (JPEG_APP0 + 2) /* JPEG marker code for ICC */

View File

@@ -17,8 +17,8 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpegcomp.h"
#include "jpeglib.h"
#include "jpegapicomp.h"
/* Private state */
@@ -53,7 +53,7 @@ initial_setup(j_decompress_ptr cinfo)
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int)JPEG_MAX_DIMENSION);
/* For now, precision must match compiled-in value... */
if (cinfo->data_precision != BITS_IN_JSAMPLE)
if (cinfo->data_precision != 8 && cinfo->data_precision != 12)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Check that number of components won't exceed internal array sizes */

View File

@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2010, 2016, D. R. Commander.
* Copyright (C) 2010, 2016, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -113,16 +113,16 @@
/* Forward declarations */
METHODDEF(void) process_data_simple_main(j_decompress_ptr cinfo,
JSAMPARRAY output_buf,
_JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail);
METHODDEF(void) process_data_context_main(j_decompress_ptr cinfo,
JSAMPARRAY output_buf,
_JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail);
#ifdef QUANT_2PASS_SUPPORTED
METHODDEF(void) process_data_crank_post(j_decompress_ptr cinfo,
JSAMPARRAY output_buf,
_JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail);
#endif
@@ -138,14 +138,15 @@ alloc_funny_pointers(j_decompress_ptr cinfo)
int ci, rgroup;
int M = cinfo->_min_DCT_scaled_size;
jpeg_component_info *compptr;
JSAMPARRAY xbuf;
_JSAMPARRAY xbuf;
/* Get top-level space for component array pointers.
* We alloc both arrays with one call to save a few cycles.
*/
main_ptr->xbuffer[0] = (JSAMPIMAGE)
main_ptr->xbuffer[0] = (_JSAMPIMAGE)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
cinfo->num_components * 2 * sizeof(JSAMPARRAY));
cinfo->num_components * 2 *
sizeof(_JSAMPARRAY));
main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
@@ -155,9 +156,9 @@ alloc_funny_pointers(j_decompress_ptr cinfo)
/* Get space for pointer lists --- M+4 row groups in each list.
* We alloc both pointer lists with one call to save a few cycles.
*/
xbuf = (JSAMPARRAY)
xbuf = (_JSAMPARRAY)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
2 * (rgroup * (M + 4)) * sizeof(JSAMPROW));
2 * (rgroup * (M + 4)) * sizeof(_JSAMPROW));
xbuf += rgroup; /* want one row group at negative offsets */
main_ptr->xbuffer[0][ci] = xbuf;
xbuf += rgroup * (M + 4);
@@ -179,7 +180,7 @@ make_funny_pointers(j_decompress_ptr cinfo)
int ci, i, rgroup;
int M = cinfo->_min_DCT_scaled_size;
jpeg_component_info *compptr;
JSAMPARRAY buf, xbuf0, xbuf1;
_JSAMPARRAY buf, xbuf0, xbuf1;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) {
@@ -219,7 +220,7 @@ set_bottom_pointers(j_decompress_ptr cinfo)
my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
int ci, i, rgroup, iMCUheight, rows_left;
jpeg_component_info *compptr;
JSAMPARRAY xbuf;
_JSAMPARRAY xbuf;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) {
@@ -258,14 +259,14 @@ start_pass_main(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
switch (pass_mode) {
case JBUF_PASS_THRU:
if (cinfo->upsample->need_context_rows) {
main_ptr->pub.process_data = process_data_context_main;
main_ptr->pub._process_data = process_data_context_main;
make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
main_ptr->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
main_ptr->iMCU_row_ctr = 0;
} else {
/* Simple case with no context needed */
main_ptr->pub.process_data = process_data_simple_main;
main_ptr->pub._process_data = process_data_simple_main;
}
main_ptr->buffer_full = FALSE; /* Mark buffer empty */
main_ptr->rowgroup_ctr = 0;
@@ -273,7 +274,7 @@ start_pass_main(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
#ifdef QUANT_2PASS_SUPPORTED
case JBUF_CRANK_DEST:
/* For last pass of 2-pass quantization, just crank the postprocessor */
main_ptr->pub.process_data = process_data_crank_post;
main_ptr->pub._process_data = process_data_crank_post;
break;
#endif
default:
@@ -289,7 +290,7 @@ start_pass_main(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
*/
METHODDEF(void)
process_data_simple_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
process_data_simple_main(j_decompress_ptr cinfo, _JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
{
my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
@@ -297,7 +298,7 @@ process_data_simple_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
/* Read input data if we haven't filled the main buffer yet */
if (!main_ptr->buffer_full) {
if (!(*cinfo->coef->decompress_data) (cinfo, main_ptr->buffer))
if (!(*cinfo->coef->_decompress_data) (cinfo, main_ptr->buffer))
return; /* suspension forced, can do nothing more */
main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
}
@@ -310,9 +311,9 @@ process_data_simple_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
*/
/* Feed the postprocessor */
(*cinfo->post->post_process_data) (cinfo, main_ptr->buffer,
&main_ptr->rowgroup_ctr, rowgroups_avail,
output_buf, out_row_ctr, out_rows_avail);
(*cinfo->post->_post_process_data) (cinfo, main_ptr->buffer,
&main_ptr->rowgroup_ctr, rowgroups_avail,
output_buf, out_row_ctr, out_rows_avail);
/* Has postprocessor consumed all the data yet? If so, mark buffer empty */
if (main_ptr->rowgroup_ctr >= rowgroups_avail) {
@@ -328,15 +329,15 @@ process_data_simple_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
*/
METHODDEF(void)
process_data_context_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
process_data_context_main(j_decompress_ptr cinfo, _JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
{
my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
/* Read input data if we haven't filled the main buffer yet */
if (!main_ptr->buffer_full) {
if (!(*cinfo->coef->decompress_data) (cinfo,
main_ptr->xbuffer[main_ptr->whichptr]))
if (!(*cinfo->coef->_decompress_data) (cinfo,
main_ptr->xbuffer[main_ptr->whichptr]))
return; /* suspension forced, can do nothing more */
main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
main_ptr->iMCU_row_ctr++; /* count rows received */
@@ -350,11 +351,11 @@ process_data_context_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
switch (main_ptr->context_state) {
case CTX_POSTPONED_ROW:
/* Call postprocessor using previously set pointers for postponed row */
(*cinfo->post->post_process_data) (cinfo,
main_ptr->xbuffer[main_ptr->whichptr],
&main_ptr->rowgroup_ctr,
main_ptr->rowgroups_avail, output_buf,
out_row_ctr, out_rows_avail);
(*cinfo->post->_post_process_data) (cinfo,
main_ptr->xbuffer[main_ptr->whichptr],
&main_ptr->rowgroup_ctr,
main_ptr->rowgroups_avail, output_buf,
out_row_ctr, out_rows_avail);
if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
return; /* Need to suspend */
main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
@@ -374,11 +375,11 @@ process_data_context_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
FALLTHROUGH /*FALLTHROUGH*/
case CTX_PROCESS_IMCU:
/* Call postprocessor using previously set pointers */
(*cinfo->post->post_process_data) (cinfo,
main_ptr->xbuffer[main_ptr->whichptr],
&main_ptr->rowgroup_ctr,
main_ptr->rowgroups_avail, output_buf,
out_row_ctr, out_rows_avail);
(*cinfo->post->_post_process_data) (cinfo,
main_ptr->xbuffer[main_ptr->whichptr],
&main_ptr->rowgroup_ctr,
main_ptr->rowgroups_avail, output_buf,
out_row_ctr, out_rows_avail);
if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
return; /* Need to suspend */
/* After the first iMCU, change wraparound pointers to normal state */
@@ -405,12 +406,12 @@ process_data_context_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
#ifdef QUANT_2PASS_SUPPORTED
METHODDEF(void)
process_data_crank_post(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
process_data_crank_post(j_decompress_ptr cinfo, _JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
{
(*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE)NULL,
(JDIMENSION *)NULL, (JDIMENSION)0,
output_buf, out_row_ctr, out_rows_avail);
(*cinfo->post->_post_process_data) (cinfo, (_JSAMPIMAGE)NULL,
(JDIMENSION *)NULL, (JDIMENSION)0,
output_buf, out_row_ctr, out_rows_avail);
}
#endif /* QUANT_2PASS_SUPPORTED */
@@ -421,12 +422,15 @@ process_data_crank_post(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
*/
GLOBAL(void)
jinit_d_main_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
_jinit_d_main_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
{
my_main_ptr main_ptr;
int ci, rgroup, ngroups;
jpeg_component_info *compptr;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
main_ptr = (my_main_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_main_controller));
@@ -452,7 +456,7 @@ jinit_d_main_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
ci++, compptr++) {
rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
cinfo->_min_DCT_scaled_size; /* height of a row group of component */
main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray)
main_ptr->buffer[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE,
compptr->width_in_blocks * compptr->_DCT_scaled_size,
(JDIMENSION)(rgroup * ngroups));

View File

@@ -10,8 +10,9 @@
*/
#define JPEG_INTERNALS
#include "jpeglibint.h"
#include "jpegcomp.h"
#include "jpeglib.h"
#include "jpegapicomp.h"
#include "jsamplecomp.h"
/* Private buffer controller object */
@@ -20,7 +21,7 @@ typedef struct {
struct jpeg_d_main_controller pub; /* public fields */
/* Pointer to allocated workspace (M or M+2 row groups). */
JSAMPARRAY buffer[MAX_COMPONENTS];
_JSAMPARRAY buffer[MAX_COMPONENTS];
boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
@@ -28,7 +29,7 @@ typedef struct {
/* Remaining fields are only used in the context case. */
/* These are the master pointers to the funny-order pointer lists. */
JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
_JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
int whichptr; /* indicates which pointer set is now in use */
int context_state; /* process_data state machine status */
@@ -55,7 +56,7 @@ set_wraparound_pointers(j_decompress_ptr cinfo)
int ci, i, rgroup;
int M = cinfo->_min_DCT_scaled_size;
jpeg_component_info *compptr;
JSAMPARRAY xbuf0, xbuf1;
_JSAMPARRAY xbuf0, xbuf1;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) {

View File

@@ -17,7 +17,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
typedef enum { /* JPEG marker codes */

View File

@@ -19,8 +19,8 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpegcomp.h"
#include "jpeglib.h"
#include "jpegapicomp.h"
#include "jdmaster.h"
@@ -409,27 +409,58 @@ prepare_range_limit_table(j_decompress_ptr cinfo)
/* Allocate and fill in the sample_range_limit table */
{
JSAMPLE *table;
#ifdef WITH_12BIT
J12SAMPLE *table12;
#endif
int i;
table = (JSAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(5 * (MAXJSAMPLE + 1) + CENTERJSAMPLE) * sizeof(JSAMPLE));
table += (MAXJSAMPLE + 1); /* allow negative subscripts of simple table */
cinfo->sample_range_limit = table;
/* First segment of "simple" table: limit[x] = 0 for x < 0 */
memset(table - (MAXJSAMPLE + 1), 0, (MAXJSAMPLE + 1) * sizeof(JSAMPLE));
/* Main part of "simple" table: limit[x] = x */
for (i = 0; i <= MAXJSAMPLE; i++)
table[i] = (JSAMPLE)i;
table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
/* End of simple table, rest of first half of post-IDCT table */
for (i = CENTERJSAMPLE; i < 2 * (MAXJSAMPLE + 1); i++)
table[i] = MAXJSAMPLE;
/* Second half of post-IDCT table */
memset(table + (2 * (MAXJSAMPLE + 1)), 0,
(2 * (MAXJSAMPLE + 1) - CENTERJSAMPLE) * sizeof(JSAMPLE));
memcpy(table + (4 * (MAXJSAMPLE + 1) - CENTERJSAMPLE),
cinfo->sample_range_limit, CENTERJSAMPLE * sizeof(JSAMPLE));
#ifdef WITH_12BIT
if (cinfo->data_precision == 12) {
table12 = (J12SAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(5 * (MAXJ12SAMPLE + 1) + CENTERJ12SAMPLE) *
sizeof(J12SAMPLE));
table12 += (MAXJ12SAMPLE + 1); /* allow negative subscripts of simple
table */
cinfo->sample_range_limit = (JSAMPLE *)table12;
/* First segment of "simple" table: limit[x] = 0 for x < 0 */
memset(table12 - (MAXJ12SAMPLE + 1), 0,
(MAXJ12SAMPLE + 1) * sizeof(J12SAMPLE));
/* Main part of "simple" table: limit[x] = x */
for (i = 0; i <= MAXJ12SAMPLE; i++)
table12[i] = (J12SAMPLE)i;
table12 += CENTERJ12SAMPLE; /* Point to where post-IDCT table starts */
/* End of simple table, rest of first half of post-IDCT table */
for (i = CENTERJ12SAMPLE; i < 2 * (MAXJ12SAMPLE + 1); i++)
table12[i] = MAXJ12SAMPLE;
/* Second half of post-IDCT table */
memset(table12 + (2 * (MAXJ12SAMPLE + 1)), 0,
(2 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE) * sizeof(J12SAMPLE));
memcpy(table12 + (4 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE),
cinfo->sample_range_limit, CENTERJ12SAMPLE * sizeof(J12SAMPLE));
} else
#endif
{
table = (JSAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(5 * (MAXJSAMPLE + 1) + CENTERJSAMPLE) * sizeof(JSAMPLE));
table += (MAXJSAMPLE + 1); /* allow negative subscripts of simple table */
cinfo->sample_range_limit = table;
/* First segment of "simple" table: limit[x] = 0 for x < 0 */
memset(table - (MAXJSAMPLE + 1), 0, (MAXJSAMPLE + 1) * sizeof(JSAMPLE));
/* Main part of "simple" table: limit[x] = x */
for (i = 0; i <= MAXJSAMPLE; i++)
table[i] = (JSAMPLE)i;
table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
/* End of simple table, rest of first half of post-IDCT table */
for (i = CENTERJSAMPLE; i < 2 * (MAXJSAMPLE + 1); i++)
table[i] = MAXJSAMPLE;
/* Second half of post-IDCT table */
memset(table + (2 * (MAXJSAMPLE + 1)), 0,
(2 * (MAXJSAMPLE + 1) - CENTERJSAMPLE) * sizeof(JSAMPLE));
memcpy(table + (4 * (MAXJSAMPLE + 1) - CENTERJSAMPLE),
cinfo->sample_range_limit, CENTERJSAMPLE * sizeof(JSAMPLE));
}
}
@@ -495,7 +526,12 @@ master_selection(j_decompress_ptr cinfo)
if (cinfo->enable_1pass_quant) {
#ifdef QUANT_1PASS_SUPPORTED
jinit_1pass_quantizer(cinfo);
#ifdef WITH_12BIT
if (cinfo->data_precision == 12)
j12init_1pass_quantizer(cinfo);
else
#endif
jinit_1pass_quantizer(cinfo);
master->quantizer_1pass = cinfo->cquantize;
#else
ERREXIT(cinfo, JERR_NOT_COMPILED);
@@ -505,7 +541,12 @@ master_selection(j_decompress_ptr cinfo)
/* We use the 2-pass code to map to external colormaps. */
if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
#ifdef QUANT_2PASS_SUPPORTED
jinit_2pass_quantizer(cinfo);
#ifdef WITH_12BIT
if (cinfo->data_precision == 12)
j12init_2pass_quantizer(cinfo);
else
#endif
jinit_2pass_quantizer(cinfo);
master->quantizer_2pass = cinfo->cquantize;
#else
ERREXIT(cinfo, JERR_NOT_COMPILED);
@@ -516,22 +557,44 @@ master_selection(j_decompress_ptr cinfo)
*/
}
/* Post-processing: in particular, color conversion first */
if (!cinfo->raw_data_out) {
if (master->using_merged_upsample) {
#ifdef WITH_12BIT
if (cinfo->data_precision == 12) {
/* Post-processing: in particular, color conversion first */
if (!cinfo->raw_data_out) {
if (master->using_merged_upsample) {
#ifdef UPSAMPLE_MERGING_SUPPORTED
jinit_merged_upsampler(cinfo); /* does color conversion too */
j12init_merged_upsampler(cinfo); /* does color conversion too */
#else
ERREXIT(cinfo, JERR_NOT_COMPILED);
ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif
} else {
jinit_color_deconverter(cinfo);
jinit_upsampler(cinfo);
} else {
j12init_color_deconverter(cinfo);
j12init_upsampler(cinfo);
}
j12init_d_post_controller(cinfo, cinfo->enable_2pass_quant);
}
jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
/* Inverse DCT */
j12init_inverse_dct(cinfo);
} else
#endif
{
/* Post-processing: in particular, color conversion first */
if (!cinfo->raw_data_out) {
if (master->using_merged_upsample) {
#ifdef UPSAMPLE_MERGING_SUPPORTED
jinit_merged_upsampler(cinfo); /* does color conversion too */
#else
ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif
} else {
jinit_color_deconverter(cinfo);
jinit_upsampler(cinfo);
}
jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
}
/* Inverse DCT */
jinit_inverse_dct(cinfo);
}
/* Inverse DCT */
jinit_inverse_dct(cinfo);
/* Entropy decoding: either Huffman or arithmetic coding. */
if (cinfo->arith_code) {
#ifdef D_ARITH_CODING_SUPPORTED
@@ -552,10 +615,21 @@ master_selection(j_decompress_ptr cinfo)
/* Initialize principal buffer controllers. */
use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
jinit_d_coef_controller(cinfo, use_c_buffer);
#ifdef WITH_12BIT
if (cinfo->data_precision == 12) {
j12init_d_coef_controller(cinfo, use_c_buffer);
if (!cinfo->raw_data_out)
jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
if (!cinfo->raw_data_out)
j12init_d_main_controller(cinfo,
FALSE /* never need full buffer here */);
} else
#endif
{
jinit_d_coef_controller(cinfo, use_c_buffer);
if (!cinfo->raw_data_out)
jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
}
/* We can now tell the memory manager to allocate virtual arrays. */
(*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo);

View File

@@ -39,7 +39,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jdmerge.h"
#include "jsimd.h"
@@ -167,20 +167,20 @@ build_ycc_rgb_table(j_decompress_ptr cinfo)
upsample->Cr_r_tab = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE + 1) * sizeof(int));
(_MAXJSAMPLE + 1) * sizeof(int));
upsample->Cb_b_tab = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE + 1) * sizeof(int));
(_MAXJSAMPLE + 1) * sizeof(int));
upsample->Cr_g_tab = (JLONG *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE + 1) * sizeof(JLONG));
(_MAXJSAMPLE + 1) * sizeof(JLONG));
upsample->Cb_g_tab = (JLONG *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(MAXJSAMPLE + 1) * sizeof(JLONG));
(_MAXJSAMPLE + 1) * sizeof(JLONG));
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
for (i = 0, x = -_CENTERJSAMPLE; i <= _MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0.._MAXJSAMPLE */
/* The Cb or Cr value we are thinking of is x = i - _CENTERJSAMPLE */
/* Cr=>R value is nearest int to 1.40200 * x */
upsample->Cr_r_tab[i] = (int)
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
@@ -219,14 +219,14 @@ start_pass_merged_upsample(j_decompress_ptr cinfo)
*/
METHODDEF(void)
merged_2v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
merged_2v_upsample(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
JDIMENSION in_row_groups_avail, _JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
/* 2:1 vertical sampling case: may need a spare row. */
{
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
JSAMPROW work_ptrs[2];
_JSAMPROW work_ptrs[2];
JDIMENSION num_rows; /* number of rows returned to caller */
if (upsample->spare_full) {
@@ -234,8 +234,8 @@ merged_2v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION size = upsample->out_row_width;
if (cinfo->out_color_space == JCS_RGB565)
size = cinfo->output_width * 2;
jcopy_sample_rows(&upsample->spare_row, 0, output_buf + *out_row_ctr, 0, 1,
size);
_jcopy_sample_rows(&upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
1, size);
num_rows = 1;
upsample->spare_full = FALSE;
} else {
@@ -270,9 +270,9 @@ merged_2v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
METHODDEF(void)
merged_1v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
merged_1v_upsample(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
JDIMENSION in_row_groups_avail, _JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
/* 1:1 vertical sampling case: much easier, never need a spare row. */
{
@@ -302,8 +302,8 @@ merged_1v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
*/
METHODDEF(void)
h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
h2v1_merged_upsample(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, _JSAMPARRAY output_buf)
{
switch (cinfo->out_color_space) {
case JCS_EXT_RGB:
@@ -347,8 +347,8 @@ h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
*/
METHODDEF(void)
h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
h2v2_merged_upsample(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, _JSAMPARRAY output_buf)
{
switch (cinfo->out_color_space) {
case JCS_EXT_RGB:
@@ -474,8 +474,8 @@ static INLINE boolean is_big_endian(void)
METHODDEF(void)
h2v1_merged_upsample_565(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
h2v1_merged_upsample_565(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, _JSAMPARRAY output_buf)
{
if (is_big_endian())
h2v1_merged_upsample_565_be(cinfo, input_buf, in_row_group_ctr,
@@ -487,8 +487,8 @@ h2v1_merged_upsample_565(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
METHODDEF(void)
h2v1_merged_upsample_565D(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
h2v1_merged_upsample_565D(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, _JSAMPARRAY output_buf)
{
if (is_big_endian())
h2v1_merged_upsample_565D_be(cinfo, input_buf, in_row_group_ctr,
@@ -500,8 +500,8 @@ h2v1_merged_upsample_565D(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
METHODDEF(void)
h2v2_merged_upsample_565(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
h2v2_merged_upsample_565(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, _JSAMPARRAY output_buf)
{
if (is_big_endian())
h2v2_merged_upsample_565_be(cinfo, input_buf, in_row_group_ctr,
@@ -513,8 +513,8 @@ h2v2_merged_upsample_565(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
METHODDEF(void)
h2v2_merged_upsample_565D(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
h2v2_merged_upsample_565D(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, _JSAMPARRAY output_buf)
{
if (is_big_endian())
h2v2_merged_upsample_565D_be(cinfo, input_buf, in_row_group_ctr,
@@ -534,10 +534,13 @@ h2v2_merged_upsample_565D(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
*/
GLOBAL(void)
jinit_merged_upsampler(j_decompress_ptr cinfo)
_jinit_merged_upsampler(j_decompress_ptr cinfo)
{
my_merged_upsample_ptr upsample;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
upsample = (my_merged_upsample_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_merged_upsampler));
@@ -548,10 +551,12 @@ jinit_merged_upsampler(j_decompress_ptr cinfo)
upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
if (cinfo->max_v_samp_factor == 2) {
upsample->pub.upsample = merged_2v_upsample;
upsample->pub._upsample = merged_2v_upsample;
#ifdef WITH_SIMD
if (jsimd_can_h2v2_merged_upsample())
upsample->upmethod = jsimd_h2v2_merged_upsample;
else
#endif
upsample->upmethod = h2v2_merged_upsample;
if (cinfo->out_color_space == JCS_RGB565) {
if (cinfo->dither_mode != JDITHER_NONE) {
@@ -561,14 +566,16 @@ jinit_merged_upsampler(j_decompress_ptr cinfo)
}
}
/* Allocate a spare row buffer */
upsample->spare_row = (JSAMPROW)
upsample->spare_row = (_JSAMPROW)
(*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(size_t)(upsample->out_row_width * sizeof(JSAMPLE)));
(size_t)(upsample->out_row_width * sizeof(_JSAMPLE)));
} else {
upsample->pub.upsample = merged_1v_upsample;
upsample->pub._upsample = merged_1v_upsample;
#ifdef WITH_SIMD
if (jsimd_can_h2v1_merged_upsample())
upsample->upmethod = jsimd_h2v1_merged_upsample;
else
#endif
upsample->upmethod = h2v1_merged_upsample;
if (cinfo->out_color_space == JCS_RGB565) {
if (cinfo->dither_mode != JDITHER_NONE) {

View File

@@ -10,7 +10,8 @@
*/
#define JPEG_INTERNALS
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jsamplecomp.h"
#ifdef UPSAMPLE_MERGING_SUPPORTED
@@ -21,8 +22,8 @@ typedef struct {
struct jpeg_upsampler pub; /* public fields */
/* Pointer to routine to do actual upsampling/conversion of one row group */
void (*upmethod) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf);
void (*upmethod) (j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, _JSAMPARRAY output_buf);
/* Private state for YCC->RGB conversion */
int *Cr_r_tab; /* => table for Cr to R conversion */
@@ -35,7 +36,7 @@ typedef struct {
* application provides just a one-row buffer; we also use the spare
* to discard the dummy last row if the image height is odd.
*/
JSAMPROW spare_row;
_JSAMPROW spare_row;
boolean spare_full; /* T if spare buffer is occupied */
JDIMENSION out_row_width; /* samples per output row */

View File

@@ -5,7 +5,7 @@
* Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2013, Linaro Limited.
* Copyright (C) 2014-2015, 2018, 2020, D. R. Commander.
* Copyright (C) 2014-2015, 2018, 2020, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -15,18 +15,19 @@
INLINE
LOCAL(void)
h2v1_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
h2v1_merged_upsample_565_internal(j_decompress_ptr cinfo,
_JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
_JSAMPARRAY output_buf)
{
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue;
int cb, cr;
register JSAMPROW outptr;
JSAMPROW inptr0, inptr1, inptr2;
register _JSAMPROW outptr;
_JSAMPROW inptr0, inptr1, inptr2;
JDIMENSION col;
/* copy these pointers into registers if possible */
register JSAMPLE *range_limit = cinfo->sample_range_limit;
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
int *Crrtab = upsample->Cr_r_tab;
int *Cbbtab = upsample->Cb_b_tab;
JLONG *Crgtab = upsample->Cr_g_tab;
@@ -86,18 +87,18 @@ h2v1_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
INLINE
LOCAL(void)
h2v1_merged_upsample_565D_internal(j_decompress_ptr cinfo,
JSAMPIMAGE input_buf,
_JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
_JSAMPARRAY output_buf)
{
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue;
int cb, cr;
register JSAMPROW outptr;
JSAMPROW inptr0, inptr1, inptr2;
register _JSAMPROW outptr;
_JSAMPROW inptr0, inptr1, inptr2;
JDIMENSION col;
/* copy these pointers into registers if possible */
register JSAMPLE *range_limit = cinfo->sample_range_limit;
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
int *Crrtab = upsample->Cr_r_tab;
int *Cbbtab = upsample->Cb_b_tab;
JLONG *Crgtab = upsample->Cr_g_tab;
@@ -159,18 +160,18 @@ h2v1_merged_upsample_565D_internal(j_decompress_ptr cinfo,
INLINE
LOCAL(void)
h2v2_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
h2v2_merged_upsample_565_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
_JSAMPARRAY output_buf)
{
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue;
int cb, cr;
register JSAMPROW outptr0, outptr1;
JSAMPROW inptr00, inptr01, inptr1, inptr2;
register _JSAMPROW outptr0, outptr1;
_JSAMPROW inptr00, inptr01, inptr1, inptr2;
JDIMENSION col;
/* copy these pointers into registers if possible */
register JSAMPLE *range_limit = cinfo->sample_range_limit;
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
int *Crrtab = upsample->Cr_r_tab;
int *Cbbtab = upsample->Cb_b_tab;
JLONG *Crgtab = upsample->Cr_g_tab;
@@ -255,18 +256,18 @@ h2v2_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
INLINE
LOCAL(void)
h2v2_merged_upsample_565D_internal(j_decompress_ptr cinfo,
JSAMPIMAGE input_buf,
_JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
_JSAMPARRAY output_buf)
{
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue;
int cb, cr;
register JSAMPROW outptr0, outptr1;
JSAMPROW inptr00, inptr01, inptr1, inptr2;
register _JSAMPROW outptr0, outptr1;
_JSAMPROW inptr00, inptr01, inptr1, inptr2;
JDIMENSION col;
/* copy these pointers into registers if possible */
register JSAMPLE *range_limit = cinfo->sample_range_limit;
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
int *Crrtab = upsample->Cr_r_tab;
int *Cbbtab = upsample->Cb_b_tab;
JLONG *Crgtab = upsample->Cr_g_tab;

View File

@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2011, 2015, 2020, D. R. Commander.
* Copyright (C) 2011, 2015, 2020, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -21,18 +21,18 @@
INLINE
LOCAL(void)
h2v1_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
h2v1_merged_upsample_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
_JSAMPARRAY output_buf)
{
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue;
int cb, cr;
register JSAMPROW outptr;
JSAMPROW inptr0, inptr1, inptr2;
register _JSAMPROW outptr;
_JSAMPROW inptr0, inptr1, inptr2;
JDIMENSION col;
/* copy these pointers into registers if possible */
register JSAMPLE *range_limit = cinfo->sample_range_limit;
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
int *Crrtab = upsample->Cr_r_tab;
int *Cbbtab = upsample->Cb_b_tab;
JLONG *Crgtab = upsample->Cr_g_tab;
@@ -93,18 +93,18 @@ h2v1_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
INLINE
LOCAL(void)
h2v2_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
h2v2_merged_upsample_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)
_JSAMPARRAY output_buf)
{
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
register int y, cred, cgreen, cblue;
int cb, cr;
register JSAMPROW outptr0, outptr1;
JSAMPROW inptr00, inptr01, inptr1, inptr2;
register _JSAMPROW outptr0, outptr1;
_JSAMPROW inptr00, inptr01, inptr1, inptr2;
JDIMENSION col;
/* copy these pointers into registers if possible */
register JSAMPLE *range_limit = cinfo->sample_range_limit;
register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
int *Crrtab = upsample->Cr_r_tab;
int *Cbbtab = upsample->Cb_b_tab;
JLONG *Crgtab = upsample->Cr_g_tab;

View File

@@ -22,7 +22,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jdhuff.h" /* Declarations shared with jdhuff.c */
#include <limits.h>

View File

@@ -21,7 +21,8 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jsamplecomp.h"
/* Private buffer controller object */
@@ -35,7 +36,7 @@ typedef struct {
* for one-pass operation, a strip buffer is sufficient.
*/
jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
_JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
JDIMENSION strip_height; /* buffer size in rows */
/* for two-pass mode only: */
JDIMENSION starting_row; /* row # of first row in current strip */
@@ -47,25 +48,25 @@ typedef my_post_controller *my_post_ptr;
/* Forward declarations */
METHODDEF(void) post_process_1pass(j_decompress_ptr cinfo,
JSAMPIMAGE input_buf,
_JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf,
_JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail);
#ifdef QUANT_2PASS_SUPPORTED
METHODDEF(void) post_process_prepass(j_decompress_ptr cinfo,
JSAMPIMAGE input_buf,
_JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf,
_JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail);
METHODDEF(void) post_process_2pass(j_decompress_ptr cinfo,
JSAMPIMAGE input_buf,
_JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf,
_JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail);
#endif
@@ -84,13 +85,13 @@ start_pass_dpost(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
case JBUF_PASS_THRU:
if (cinfo->quantize_colors) {
/* Single-pass processing with color quantization. */
post->pub.post_process_data = post_process_1pass;
post->pub._post_process_data = post_process_1pass;
/* We could be doing buffered-image output before starting a 2-pass
* color quantization; in that case, jinit_d_post_controller did not
* allocate a strip buffer. Use the virtual-array buffer as workspace.
*/
if (post->buffer == NULL) {
post->buffer = (*cinfo->mem->access_virt_sarray)
post->buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
((j_common_ptr)cinfo, post->whole_image,
(JDIMENSION)0, post->strip_height, TRUE);
}
@@ -98,7 +99,7 @@ start_pass_dpost(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
/* For single-pass processing without color quantization,
* I have no work to do; just call the upsampler directly.
*/
post->pub.post_process_data = cinfo->upsample->upsample;
post->pub._post_process_data = cinfo->upsample->_upsample;
}
break;
#ifdef QUANT_2PASS_SUPPORTED
@@ -106,13 +107,13 @@ start_pass_dpost(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
/* First pass of 2-pass quantization */
if (post->whole_image == NULL)
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
post->pub.post_process_data = post_process_prepass;
post->pub._post_process_data = post_process_prepass;
break;
case JBUF_CRANK_DEST:
/* Second pass of 2-pass quantization */
if (post->whole_image == NULL)
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
post->pub.post_process_data = post_process_2pass;
post->pub._post_process_data = post_process_2pass;
break;
#endif /* QUANT_2PASS_SUPPORTED */
default:
@@ -129,9 +130,9 @@ start_pass_dpost(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
*/
METHODDEF(void)
post_process_1pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
post_process_1pass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
JDIMENSION in_row_groups_avail, _JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
{
my_post_ptr post = (my_post_ptr)cinfo->post;
@@ -143,13 +144,13 @@ post_process_1pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
if (max_rows > post->strip_height)
max_rows = post->strip_height;
num_rows = 0;
(*cinfo->upsample->upsample) (cinfo, input_buf, in_row_group_ctr,
in_row_groups_avail, post->buffer, &num_rows,
max_rows);
(*cinfo->upsample->_upsample) (cinfo, input_buf, in_row_group_ctr,
in_row_groups_avail, post->buffer, &num_rows,
max_rows);
/* Quantize and emit data. */
(*cinfo->cquantize->color_quantize) (cinfo, post->buffer,
output_buf + *out_row_ctr,
(int)num_rows);
(*cinfo->cquantize->_color_quantize) (cinfo, post->buffer,
output_buf + *out_row_ctr,
(int)num_rows);
*out_row_ctr += num_rows;
}
@@ -161,9 +162,9 @@ post_process_1pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
*/
METHODDEF(void)
post_process_prepass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
post_process_prepass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
JDIMENSION in_row_groups_avail, _JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
{
my_post_ptr post = (my_post_ptr)cinfo->post;
@@ -171,23 +172,23 @@ post_process_prepass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
/* Reposition virtual buffer if at start of strip. */
if (post->next_row == 0) {
post->buffer = (*cinfo->mem->access_virt_sarray)
post->buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
((j_common_ptr)cinfo, post->whole_image,
post->starting_row, post->strip_height, TRUE);
}
/* Upsample some data (up to a strip height's worth). */
old_next_row = post->next_row;
(*cinfo->upsample->upsample) (cinfo, input_buf, in_row_group_ctr,
in_row_groups_avail, post->buffer,
&post->next_row, post->strip_height);
(*cinfo->upsample->_upsample) (cinfo, input_buf, in_row_group_ctr,
in_row_groups_avail, post->buffer,
&post->next_row, post->strip_height);
/* Allow quantizer to scan new data. No data is emitted, */
/* but we advance out_row_ctr so outer loop can tell when we're done. */
if (post->next_row > old_next_row) {
num_rows = post->next_row - old_next_row;
(*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
(JSAMPARRAY)NULL, (int)num_rows);
(*cinfo->cquantize->_color_quantize) (cinfo, post->buffer + old_next_row,
(_JSAMPARRAY)NULL, (int)num_rows);
*out_row_ctr += num_rows;
}
@@ -204,9 +205,9 @@ post_process_prepass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
*/
METHODDEF(void)
post_process_2pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
post_process_2pass(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
JDIMENSION in_row_groups_avail, _JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
{
my_post_ptr post = (my_post_ptr)cinfo->post;
@@ -214,7 +215,7 @@ post_process_2pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
/* Reposition virtual buffer if at start of strip. */
if (post->next_row == 0) {
post->buffer = (*cinfo->mem->access_virt_sarray)
post->buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
((j_common_ptr)cinfo, post->whole_image,
post->starting_row, post->strip_height, FALSE);
}
@@ -230,9 +231,9 @@ post_process_2pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
num_rows = max_rows;
/* Quantize and emit data. */
(*cinfo->cquantize->color_quantize) (cinfo, post->buffer + post->next_row,
output_buf + *out_row_ctr,
(int)num_rows);
(*cinfo->cquantize->_color_quantize) (cinfo, post->buffer + post->next_row,
output_buf + *out_row_ctr,
(int)num_rows);
*out_row_ctr += num_rows;
/* Advance if we filled the strip. */
@@ -251,10 +252,13 @@ post_process_2pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
*/
GLOBAL(void)
jinit_d_post_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
_jinit_d_post_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
{
my_post_ptr post;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
post = (my_post_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_post_controller));
@@ -285,7 +289,7 @@ jinit_d_post_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
#endif /* QUANT_2PASS_SUPPORTED */
} else {
/* One-pass color quantization: just make a strip buffer. */
post->buffer = (*cinfo->mem->alloc_sarray)
post->buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE,
cinfo->output_width * cinfo->out_color_components,
post->strip_height);

View File

@@ -5,7 +5,7 @@
* Copyright (C) 1991-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2010, 2015-2016, D. R. Commander.
* Copyright (C) 2010, 2015-2016, 2022, D. R. Commander.
* Copyright (C) 2014, MIPS Technologies, Inc., California.
* Copyright (C) 2015, Google, Inc.
* Copyright (C) 2019-2020, Arm Limited.
@@ -28,7 +28,7 @@
#include "jinclude.h"
#include "jdsample.h"
#include "jsimd.h"
#include "jpegcomp.h"
#include "jpegapicomp.h"
@@ -57,9 +57,9 @@ start_pass_upsample(j_decompress_ptr cinfo)
*/
METHODDEF(void)
sep_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
sep_upsample(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
_JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail)
{
my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
@@ -95,9 +95,10 @@ sep_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
if (num_rows > out_rows_avail)
num_rows = out_rows_avail;
(*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
(JDIMENSION)upsample->next_row_out,
output_buf + *out_row_ctr, (int)num_rows);
(*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
(JDIMENSION)upsample->next_row_out,
output_buf + *out_row_ctr,
(int)num_rows);
/* Adjust counts */
*out_row_ctr += num_rows;
@@ -124,7 +125,7 @@ sep_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
METHODDEF(void)
fullsize_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
{
*output_data_ptr = input_data;
}
@@ -137,7 +138,7 @@ fullsize_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
METHODDEF(void)
noop_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
{
*output_data_ptr = NULL; /* safety check */
}
@@ -156,14 +157,14 @@ noop_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
METHODDEF(void)
int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
{
my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
JSAMPARRAY output_data = *output_data_ptr;
register JSAMPROW inptr, outptr;
register JSAMPLE invalue;
_JSAMPARRAY output_data = *output_data_ptr;
register _JSAMPROW inptr, outptr;
register _JSAMPLE invalue;
register int h;
JSAMPROW outend;
_JSAMPROW outend;
int h_expand, v_expand;
int inrow, outrow;
@@ -184,8 +185,8 @@ int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
}
/* Generate any additional output rows by duplicating the first one */
if (v_expand > 1) {
jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
v_expand - 1, cinfo->output_width);
_jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
v_expand - 1, cinfo->output_width);
}
inrow++;
outrow += v_expand;
@@ -200,12 +201,12 @@ int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
METHODDEF(void)
h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
{
JSAMPARRAY output_data = *output_data_ptr;
register JSAMPROW inptr, outptr;
register JSAMPLE invalue;
JSAMPROW outend;
_JSAMPARRAY output_data = *output_data_ptr;
register _JSAMPROW inptr, outptr;
register _JSAMPLE invalue;
_JSAMPROW outend;
int inrow;
for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
@@ -228,12 +229,12 @@ h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
METHODDEF(void)
h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
{
JSAMPARRAY output_data = *output_data_ptr;
register JSAMPROW inptr, outptr;
register JSAMPLE invalue;
JSAMPROW outend;
_JSAMPARRAY output_data = *output_data_ptr;
register _JSAMPROW inptr, outptr;
register _JSAMPLE invalue;
_JSAMPROW outend;
int inrow, outrow;
inrow = outrow = 0;
@@ -246,8 +247,8 @@ h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*outptr++ = invalue;
*outptr++ = invalue;
}
jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
cinfo->output_width);
_jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
cinfo->output_width);
inrow++;
outrow += 2;
}
@@ -271,10 +272,10 @@ h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
METHODDEF(void)
h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
{
JSAMPARRAY output_data = *output_data_ptr;
register JSAMPROW inptr, outptr;
_JSAMPARRAY output_data = *output_data_ptr;
register _JSAMPROW inptr, outptr;
register int invalue;
register JDIMENSION colctr;
int inrow;
@@ -284,20 +285,20 @@ h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
outptr = output_data[inrow];
/* Special case for first column */
invalue = *inptr++;
*outptr++ = (JSAMPLE)invalue;
*outptr++ = (JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
*outptr++ = (_JSAMPLE)invalue;
*outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
/* General case: 3/4 * nearer pixel + 1/4 * further pixel */
invalue = (*inptr++) * 3;
*outptr++ = (JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
*outptr++ = (JSAMPLE)((invalue + inptr[0] + 2) >> 2);
*outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
*outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
}
/* Special case for last column */
invalue = *inptr;
*outptr++ = (JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
*outptr++ = (JSAMPLE)invalue;
*outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
*outptr++ = (_JSAMPLE)invalue;
}
}
@@ -311,10 +312,10 @@ h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
METHODDEF(void)
h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
{
JSAMPARRAY output_data = *output_data_ptr;
JSAMPROW inptr0, inptr1, outptr;
_JSAMPARRAY output_data = *output_data_ptr;
_JSAMPROW inptr0, inptr1, outptr;
#if BITS_IN_JSAMPLE == 8
int thiscolsum, bias;
#else
@@ -339,7 +340,7 @@ h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
thiscolsum = (*inptr0++) * 3 + (*inptr1++);
*outptr++ = (JSAMPLE)((thiscolsum + bias) >> 2);
*outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
}
}
inrow++;
@@ -357,10 +358,10 @@ h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
METHODDEF(void)
h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
_JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
{
JSAMPARRAY output_data = *output_data_ptr;
register JSAMPROW inptr0, inptr1, outptr;
_JSAMPARRAY output_data = *output_data_ptr;
register _JSAMPROW inptr0, inptr1, outptr;
#if BITS_IN_JSAMPLE == 8
register int thiscolsum, lastcolsum, nextcolsum;
#else
@@ -383,22 +384,22 @@ h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* Special case for first column */
thiscolsum = (*inptr0++) * 3 + (*inptr1++);
nextcolsum = (*inptr0++) * 3 + (*inptr1++);
*outptr++ = (JSAMPLE)((thiscolsum * 4 + 8) >> 4);
*outptr++ = (JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
*outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
*outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
lastcolsum = thiscolsum; thiscolsum = nextcolsum;
for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
/* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
/* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
nextcolsum = (*inptr0++) * 3 + (*inptr1++);
*outptr++ = (JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
*outptr++ = (JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
*outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
*outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
lastcolsum = thiscolsum; thiscolsum = nextcolsum;
}
/* Special case for last column */
*outptr++ = (JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
*outptr++ = (JSAMPLE)((thiscolsum * 4 + 7) >> 4);
*outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
*outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
}
inrow++;
}
@@ -410,7 +411,7 @@ h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jinit_upsampler(j_decompress_ptr cinfo)
_jinit_upsampler(j_decompress_ptr cinfo)
{
my_upsample_ptr upsample;
int ci;
@@ -418,13 +419,16 @@ jinit_upsampler(j_decompress_ptr cinfo)
boolean need_buffer, do_fancy;
int h_in_group, v_in_group, h_out_group, v_out_group;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if (!cinfo->master->jinit_upsampler_no_alloc) {
upsample = (my_upsample_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_upsampler));
cinfo->upsample = (struct jpeg_upsampler *)upsample;
upsample->pub.start_pass = start_pass_upsample;
upsample->pub.upsample = sep_upsample;
upsample->pub._upsample = sep_upsample;
upsample->pub.need_context_rows = FALSE; /* until we find out differently */
} else
upsample = (my_upsample_ptr)cinfo->upsample;
@@ -464,21 +468,25 @@ jinit_upsampler(j_decompress_ptr cinfo)
} else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
/* Special cases for 2h1v upsampling */
if (do_fancy && compptr->downsampled_width > 2) {
#ifdef WITH_SIMD
if (jsimd_can_h2v1_fancy_upsample())
upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
else
#endif
upsample->methods[ci] = h2v1_fancy_upsample;
} else {
#ifdef WITH_SIMD
if (jsimd_can_h2v1_upsample())
upsample->methods[ci] = jsimd_h2v1_upsample;
else
#endif
upsample->methods[ci] = h2v1_upsample;
}
} else if (h_in_group == h_out_group &&
v_in_group * 2 == v_out_group && do_fancy) {
/* Non-fancy upsampling is handled by the generic method */
#if defined(__arm__) || defined(__aarch64__) || \
defined(_M_ARM) || defined(_M_ARM64)
#if defined(WITH_SIMD) && (defined(__arm__) || defined(__aarch64__) || \
defined(_M_ARM) || defined(_M_ARM64))
if (jsimd_can_h1v2_fancy_upsample())
upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
else
@@ -489,21 +497,25 @@ jinit_upsampler(j_decompress_ptr cinfo)
v_in_group * 2 == v_out_group) {
/* Special cases for 2h2v upsampling */
if (do_fancy && compptr->downsampled_width > 2) {
#ifdef WITH_SIMD
if (jsimd_can_h2v2_fancy_upsample())
upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
else
#endif
upsample->methods[ci] = h2v2_fancy_upsample;
upsample->pub.need_context_rows = TRUE;
} else {
#ifdef WITH_SIMD
if (jsimd_can_h2v2_upsample())
upsample->methods[ci] = jsimd_h2v2_upsample;
else
#endif
upsample->methods[ci] = h2v2_upsample;
}
} else if ((h_out_group % h_in_group) == 0 &&
(v_out_group % v_in_group) == 0) {
/* Generic integral-factors upsampling method */
#if defined(__mips__)
#if defined(WITH_SIMD) && defined(__mips__)
if (jsimd_can_int_upsample())
upsample->methods[ci] = jsimd_int_upsample;
else
@@ -514,7 +526,7 @@ jinit_upsampler(j_decompress_ptr cinfo)
} else
ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE,
(JDIMENSION)jround_up((long)cinfo->output_width,
(long)cinfo->max_h_samp_factor),

View File

@@ -10,14 +10,15 @@
*/
#define JPEG_INTERNALS
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jsamplecomp.h"
/* Pointer to routine to upsample a single component */
typedef void (*upsample1_ptr) (j_decompress_ptr cinfo,
jpeg_component_info *compptr,
JSAMPARRAY input_data,
JSAMPARRAY *output_data_ptr);
_JSAMPARRAY input_data,
_JSAMPARRAY *output_data_ptr);
/* Private subobject */
@@ -31,7 +32,7 @@ typedef struct {
* ie do not need rescaling. The corresponding entry of color_buf[] is
* simply set to point to the input data array, thereby avoiding copying.
*/
JSAMPARRAY color_buf[MAX_COMPONENTS];
_JSAMPARRAY color_buf[MAX_COMPONENTS];
/* Per-component upsampling method pointers */
upsample1_ptr methods[MAX_COMPONENTS];

View File

@@ -15,8 +15,8 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpegcomp.h"
#include "jpeglib.h"
#include "jpegapicomp.h"
/* Forward declarations */
@@ -127,7 +127,12 @@ transdecode_master_selection(j_decompress_ptr cinfo)
}
/* Always get a full-image coefficient buffer. */
jinit_d_coef_controller(cinfo, TRUE);
#ifdef WITH_12BIT
if (cinfo->data_precision == 12)
j12init_d_coef_controller(cinfo, TRUE);
else
#endif
jinit_d_coef_controller(cinfo, TRUE);
/* We can now tell the memory manager to allocate virtual arrays. */
(*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo);

View File

@@ -22,11 +22,10 @@
*/
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jversion.h"
#include "jerrorint.h"
#include "jerror.h"
#ifdef USE_WINDOWS_MESSAGEBOX
#include <windows.h>
@@ -48,7 +47,7 @@
#define JMESSAGE(code, string) string,
const char * const jpeg_std_message_table[] = {
#include "jerrorint.h"
#include "jerror.h"
NULL
};

View File

@@ -23,7 +23,7 @@
* again with a suitable JMESSAGE definition (see jerror.c for an example).
*/
#ifndef JMESSAGE
#if !defined(JERROR_H) && !defined(J12ERROR_H)
#ifndef JERROR_H
/* First time through, define the enum list */
#define JMAKE_ENUM_LIST
#else

View File

@@ -1,13 +0,0 @@
/*
* jerrorint.h
*
* Copyright (C) 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*/
#if BITS_IN_JSAMPLE == 12
#include "j12error.h"
#else
#include "jerror.h"
#endif

View File

@@ -1,10 +1,8 @@
/*
* jfdctflt.c
*
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2022, D. R. Commander.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -39,7 +37,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_FLOAT_SUPPORTED

View File

@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2015, 2022, D. R. Commander.
* Copyright (C) 2015, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -35,7 +35,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_IFAST_SUPPORTED
@@ -114,7 +114,7 @@
*/
GLOBAL(void)
jpeg_fdct_ifast(DCTELEM *data)
_jpeg_fdct_ifast(DCTELEM *data)
{
DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
DCTELEM tmp10, tmp11, tmp12, tmp13;

View File

@@ -28,7 +28,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_ISLOW_SUPPORTED
@@ -140,7 +140,7 @@
*/
GLOBAL(void)
jpeg_fdct_islow(DCTELEM *data)
_jpeg_fdct_islow(DCTELEM *data)
{
JLONG tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
JLONG tmp10, tmp11, tmp12, tmp13;

View File

@@ -42,7 +42,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_FLOAT_SUPPORTED
@@ -69,9 +69,9 @@
*/
GLOBAL(void)
jpeg_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
@@ -79,8 +79,8 @@ jpeg_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR inptr;
FLOAT_MULT_TYPE *quantptr;
FAST_FLOAT *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = cinfo->sample_range_limit;
_JSAMPROW outptr;
_JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
int ctr;
FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
#define _0_125 ((FLOAT_MULT_TYPE)0.125)
@@ -192,7 +192,7 @@ jpeg_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
/* Even part */
/* Apply signed->unsigned and prepare float->int conversion */
z5 = wsptr[0] + ((FAST_FLOAT)CENTERJSAMPLE + (FAST_FLOAT)0.5);
z5 = wsptr[0] + ((FAST_FLOAT)_CENTERJSAMPLE + (FAST_FLOAT)0.5);
tmp10 = z5 + wsptr[4];
tmp11 = z5 - wsptr[4];

View File

@@ -37,7 +37,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_IFAST_SUPPORTED
@@ -64,10 +64,10 @@
* The dequantized coefficients are not integers because the AA&N scaling
* factors have been incorporated. We represent them scaled up by PASS1_BITS,
* so that the first and second IDCT rounds have the same input scaling.
* For 8-bit JSAMPLEs, we choose IFAST_SCALE_BITS = PASS1_BITS so as to
* For 8-bit samples, we choose IFAST_SCALE_BITS = PASS1_BITS so as to
* avoid a descaling shift; this compromises accuracy rather drastically
* for small quantization table entries, but it saves a lot of shifts.
* For 12-bit JSAMPLEs, there's no hope of using 16x16 multiplies anyway,
* For 12-bit samples, there's no hope of using 16x16 multiplies anyway,
* so we use a much larger scaling factor to preserve accuracy.
*
* A final compromise is to represent the multiplicative constants to only
@@ -168,9 +168,9 @@
*/
GLOBAL(void)
jpeg_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
DCTELEM tmp10, tmp11, tmp12, tmp13;
@@ -178,8 +178,8 @@ jpeg_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR inptr;
IFAST_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[DCTSIZE2]; /* buffers data between passes */
SHIFT_TEMPS /* for DESCALE */
@@ -296,7 +296,7 @@ jpeg_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
/* AC terms all zero */
JSAMPLE dcval =
_JSAMPLE dcval =
range_limit[IDESCALE(wsptr[0], PASS1_BITS + 3) & RANGE_MASK];
outptr[0] = dcval;

View File

@@ -52,7 +52,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_ISLOW_SUPPORTED
@@ -170,9 +170,9 @@
*/
GLOBAL(void)
jpeg_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
JLONG tmp0, tmp1, tmp2, tmp3;
JLONG tmp10, tmp11, tmp12, tmp13;
@@ -180,8 +180,8 @@ jpeg_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR inptr;
ISLOW_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[DCTSIZE2]; /* buffers data between passes */
SHIFT_TEMPS
@@ -314,8 +314,8 @@ jpeg_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
/* AC terms all zero */
JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
PASS1_BITS + 3) & RANGE_MASK];
_JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
PASS1_BITS + 3) & RANGE_MASK];
outptr[0] = dcval;
outptr[1] = dcval;
@@ -424,17 +424,17 @@ jpeg_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jpeg_idct_7x7(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_7x7(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
JLONG tmp0, tmp1, tmp2, tmp10, tmp11, tmp12, tmp13;
JLONG z1, z2, z3;
JCOEFPTR inptr;
ISLOW_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[7 * 7]; /* buffers data between passes */
SHIFT_TEMPS
@@ -573,17 +573,17 @@ jpeg_idct_7x7(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jpeg_idct_6x6(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_6x6(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
JLONG tmp0, tmp1, tmp2, tmp10, tmp11, tmp12;
JLONG z1, z2, z3;
JCOEFPTR inptr;
ISLOW_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[6 * 6]; /* buffers data between passes */
SHIFT_TEMPS
@@ -694,17 +694,17 @@ jpeg_idct_6x6(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jpeg_idct_5x5(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_5x5(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
JLONG tmp0, tmp1, tmp10, tmp11, tmp12;
JLONG z1, z2, z3;
JCOEFPTR inptr;
ISLOW_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[5 * 5]; /* buffers data between passes */
SHIFT_TEMPS
@@ -809,16 +809,16 @@ jpeg_idct_5x5(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jpeg_idct_3x3(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_3x3(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
JLONG tmp0, tmp2, tmp10, tmp12;
JCOEFPTR inptr;
ISLOW_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[3 * 3]; /* buffers data between passes */
SHIFT_TEMPS
@@ -899,17 +899,17 @@ jpeg_idct_3x3(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jpeg_idct_9x9(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_9x9(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
JLONG tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13, tmp14;
JLONG z1, z2, z3, z4;
JCOEFPTR inptr;
ISLOW_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[8 * 9]; /* buffers data between passes */
SHIFT_TEMPS
@@ -1070,9 +1070,9 @@ jpeg_idct_9x9(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jpeg_idct_10x10(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_10x10(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
JLONG tmp10, tmp11, tmp12, tmp13, tmp14;
JLONG tmp20, tmp21, tmp22, tmp23, tmp24;
@@ -1080,8 +1080,8 @@ jpeg_idct_10x10(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR inptr;
ISLOW_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[8 * 10]; /* buffers data between passes */
SHIFT_TEMPS
@@ -1265,9 +1265,9 @@ jpeg_idct_10x10(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jpeg_idct_11x11(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_11x11(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
JLONG tmp10, tmp11, tmp12, tmp13, tmp14;
JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25;
@@ -1275,8 +1275,8 @@ jpeg_idct_11x11(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR inptr;
ISLOW_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[8 * 11]; /* buffers data between passes */
SHIFT_TEMPS
@@ -1459,9 +1459,9 @@ jpeg_idct_11x11(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jpeg_idct_12x12(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_12x12(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
JLONG tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25;
@@ -1469,8 +1469,8 @@ jpeg_idct_12x12(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR inptr;
ISLOW_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[8 * 12]; /* buffers data between passes */
SHIFT_TEMPS
@@ -1675,9 +1675,9 @@ jpeg_idct_12x12(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jpeg_idct_13x13(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_13x13(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
JLONG tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;
JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26;
@@ -1685,8 +1685,8 @@ jpeg_idct_13x13(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR inptr;
ISLOW_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[8 * 13]; /* buffers data between passes */
SHIFT_TEMPS
@@ -1903,9 +1903,9 @@ jpeg_idct_13x13(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jpeg_idct_14x14(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_14x14(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
JLONG tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26;
@@ -1913,8 +1913,8 @@ jpeg_idct_14x14(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR inptr;
ISLOW_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[8 * 14]; /* buffers data between passes */
SHIFT_TEMPS
@@ -2129,9 +2129,9 @@ jpeg_idct_14x14(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jpeg_idct_15x15(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_15x15(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
JLONG tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;
JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27;
@@ -2139,8 +2139,8 @@ jpeg_idct_15x15(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR inptr;
ISLOW_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[8 * 15]; /* buffers data between passes */
SHIFT_TEMPS
@@ -2371,9 +2371,9 @@ jpeg_idct_15x15(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jpeg_idct_16x16(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_16x16(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
JLONG tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13;
JLONG tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27;
@@ -2381,8 +2381,8 @@ jpeg_idct_16x16(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR inptr;
ISLOW_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[8 * 16]; /* buffers data between passes */
SHIFT_TEMPS

View File

@@ -25,7 +25,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef IDCT_SCALING_SUPPORTED
@@ -118,17 +118,17 @@
*/
GLOBAL(void)
jpeg_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
JLONG tmp0, tmp2, tmp10, tmp12;
JLONG z1, z2, z3, z4;
JCOEFPTR inptr;
ISLOW_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[DCTSIZE * 4]; /* buffers data between passes */
SHIFT_TEMPS
@@ -210,8 +210,8 @@ jpeg_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
/* AC terms all zero */
JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
PASS1_BITS + 3) & RANGE_MASK];
_JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
PASS1_BITS + 3) & RANGE_MASK];
outptr[0] = dcval;
outptr[1] = dcval;
@@ -276,16 +276,16 @@ jpeg_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jpeg_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
JLONG tmp0, tmp10, z1;
JCOEFPTR inptr;
ISLOW_MULT_TYPE *quantptr;
int *wsptr;
JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPROW outptr;
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr;
int workspace[DCTSIZE * 2]; /* buffers data between passes */
SHIFT_TEMPS
@@ -345,8 +345,8 @@ jpeg_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
#ifndef NO_ZERO_ROW_TEST
if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
/* AC terms all zero */
JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
PASS1_BITS + 3) & RANGE_MASK];
_JSAMPLE dcval = range_limit[(int)DESCALE((JLONG)wsptr[0],
PASS1_BITS + 3) & RANGE_MASK];
outptr[0] = dcval;
outptr[1] = dcval;
@@ -387,13 +387,13 @@ jpeg_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
*/
GLOBAL(void)
jpeg_idct_1x1(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
_jpeg_idct_1x1(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, _JSAMPARRAY output_buf,
JDIMENSION output_col)
{
int dcval;
ISLOW_MULT_TYPE *quantptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
_JSAMPLE *range_limit = IDCT_range_limit(cinfo);
SHIFT_TEMPS
/* We hardly need an inverse DCT routine for this: just take the

151
jmemmgr.c
View File

@@ -30,7 +30,7 @@
#define JPEG_INTERNALS
#define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jmemsys.h" /* import the system-dependent declarations */
#if !defined(_MSC_VER) || _MSC_VER > 1600
#include <stdint.h>
@@ -155,7 +155,9 @@ typedef my_memory_mgr *my_mem_ptr;
*/
struct jvirt_sarray_control {
JSAMPARRAY mem_buffer; /* => the in-memory buffer */
JSAMPARRAY mem_buffer; /* => the in-memory buffer (if
cinfo->data_precision is 12, then this is
actually a J12SAMPARRAY) */
JDIMENSION rows_in_array; /* total virtual array height */
JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
@@ -351,9 +353,9 @@ alloc_small(j_common_ptr cinfo, int pool_id, size_t sizeofobject)
* request is large enough that it may as well be passed directly to
* jpeg_get_large; the pool management just links everything together
* so that we can free it all on demand.
* Note: the major use of "large" objects is in JSAMPARRAY and JBLOCKARRAY
* structures. The routines that create these structures (see below)
* deliberately bunch rows together to ensure a large request size.
* Note: the major use of "large" objects is in JSAMPARRAY/J12SAMPARRAY and
* JBLOCKARRAY structures. The routines that create these structures (see
* below) deliberately bunch rows together to ensure a large request size.
*/
METHODDEF(void *)
@@ -437,9 +439,20 @@ alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow,
JSAMPROW workspace;
JDIMENSION rowsperchunk, currow, i;
long ltemp;
#ifdef WITH_12BIT
J12SAMPARRAY result12;
J12SAMPROW workspace12;
int data_precision = cinfo->is_decompressor ?
((j_decompress_ptr)cinfo)->data_precision :
((j_compress_ptr)cinfo)->data_precision;
size_t sample_size = data_precision == 12 ?
sizeof(J12SAMPLE) : sizeof(JSAMPLE);
#else
size_t sample_size = sizeof(JSAMPLE);
#endif
/* Make sure each row is properly aligned */
if ((ALIGN_SIZE % sizeof(JSAMPLE)) != 0)
if ((ALIGN_SIZE % sample_size) != 0)
out_of_memory(cinfo, 5); /* safety check */
if (samplesperrow > MAX_ALLOC_CHUNK) {
@@ -448,11 +461,11 @@ alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow,
out_of_memory(cinfo, 9);
}
samplesperrow = (JDIMENSION)round_up_pow2(samplesperrow, (2 * ALIGN_SIZE) /
sizeof(JSAMPLE));
sample_size);
/* Calculate max # of rows allowed in one allocation chunk */
ltemp = (MAX_ALLOC_CHUNK - sizeof(large_pool_hdr)) /
((long)samplesperrow * sizeof(JSAMPLE));
((long)samplesperrow * (long)sample_size);
if (ltemp <= 0)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
if (ltemp < (long)numrows)
@@ -461,24 +474,47 @@ alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow,
rowsperchunk = numrows;
mem->last_rowsperchunk = rowsperchunk;
/* Get space for row pointers (small object) */
result = (JSAMPARRAY)alloc_small(cinfo, pool_id,
(size_t)(numrows * sizeof(JSAMPROW)));
#ifdef WITH_12BIT
if (data_precision == 12) {
/* Get space for row pointers (small object) */
result12 = (J12SAMPARRAY)alloc_small(cinfo, pool_id,
(size_t)(numrows *
sizeof(J12SAMPROW)));
/* Get the rows themselves (large objects) */
currow = 0;
while (currow < numrows) {
rowsperchunk = MIN(rowsperchunk, numrows - currow);
workspace = (JSAMPROW)alloc_large(cinfo, pool_id,
(size_t)((size_t)rowsperchunk * (size_t)samplesperrow *
sizeof(JSAMPLE)));
for (i = rowsperchunk; i > 0; i--) {
result[currow++] = workspace;
workspace += samplesperrow;
/* Get the rows themselves (large objects) */
currow = 0;
while (currow < numrows) {
rowsperchunk = MIN(rowsperchunk, numrows - currow);
workspace12 = (J12SAMPROW)alloc_large(cinfo, pool_id,
(size_t)((size_t)rowsperchunk * (size_t)samplesperrow * sample_size));
for (i = rowsperchunk; i > 0; i--) {
result12[currow++] = workspace12;
workspace12 += samplesperrow;
}
}
}
return result;
return (JSAMPARRAY)result12;
} else
#endif
{
/* Get space for row pointers (small object) */
result = (JSAMPARRAY)alloc_small(cinfo, pool_id,
(size_t)(numrows * sizeof(JSAMPROW)));
/* Get the rows themselves (large objects) */
currow = 0;
while (currow < numrows) {
rowsperchunk = MIN(rowsperchunk, numrows - currow);
workspace = (JSAMPROW)alloc_large(cinfo, pool_id,
(size_t)((size_t)rowsperchunk * (size_t)samplesperrow * sample_size));
for (i = rowsperchunk; i > 0; i--) {
result[currow++] = workspace;
workspace += samplesperrow;
}
}
return result;
}
}
@@ -640,6 +676,15 @@ realize_virt_arrays(j_common_ptr cinfo)
size_t minheights, max_minheights;
jvirt_sarray_ptr sptr;
jvirt_barray_ptr bptr;
#ifdef WITH_12BIT
int data_precision = cinfo->is_decompressor ?
((j_decompress_ptr)cinfo)->data_precision :
((j_compress_ptr)cinfo)->data_precision;
size_t sample_size = data_precision == 12 ?
sizeof(J12SAMPLE) : sizeof(JSAMPLE);
#else
size_t sample_size = sizeof(JSAMPLE);
#endif
/* Compute the minimum space needed (maxaccess rows in each buffer)
* and the maximum space needed (full image height in each buffer).
@@ -650,10 +695,10 @@ realize_virt_arrays(j_common_ptr cinfo)
for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
if (sptr->mem_buffer == NULL) { /* if not realized yet */
size_t new_space = (long)sptr->rows_in_array *
(long)sptr->samplesperrow * sizeof(JSAMPLE);
(long)sptr->samplesperrow * sample_size;
space_per_minheight += (long)sptr->maxaccess *
(long)sptr->samplesperrow * sizeof(JSAMPLE);
(long)sptr->samplesperrow * sample_size;
if (SIZE_MAX - maximum_space < new_space)
out_of_memory(cinfo, 10);
maximum_space += new_space;
@@ -708,7 +753,7 @@ realize_virt_arrays(j_common_ptr cinfo)
jpeg_open_backing_store(cinfo, &sptr->b_s_info,
(long)sptr->rows_in_array *
(long)sptr->samplesperrow *
(long)sizeof(JSAMPLE));
(long)sample_size);
sptr->b_s_open = TRUE;
}
sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
@@ -751,8 +796,17 @@ do_sarray_io(j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
/* Do backing store read or write of a virtual sample array */
{
long bytesperrow, file_offset, byte_count, rows, thisrow, i;
#ifdef WITH_12BIT
int data_precision = cinfo->is_decompressor ?
((j_decompress_ptr)cinfo)->data_precision :
((j_compress_ptr)cinfo)->data_precision;
size_t sample_size = data_precision == 12 ?
sizeof(J12SAMPLE) : sizeof(JSAMPLE);
#else
size_t sample_size = sizeof(JSAMPLE);
#endif
bytesperrow = (long)ptr->samplesperrow * sizeof(JSAMPLE);
bytesperrow = (long)ptr->samplesperrow * (long)sample_size;
file_offset = ptr->cur_start_row * bytesperrow;
/* Loop to read or write each allocation chunk in mem_buffer */
for (i = 0; i < (long)ptr->rows_in_mem; i += ptr->rowsperchunk) {
@@ -766,14 +820,30 @@ do_sarray_io(j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
if (rows <= 0) /* this chunk might be past end of file! */
break;
byte_count = rows * bytesperrow;
if (writing)
(*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info,
(void *)ptr->mem_buffer[i],
file_offset, byte_count);
else
(*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info,
(void *)ptr->mem_buffer[i],
file_offset, byte_count);
#ifdef WITH_12BIT
if (data_precision == 12) {
J12SAMPARRAY mem_buffer12 = (J12SAMPARRAY)ptr->mem_buffer;
if (writing)
(*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info,
(void *)mem_buffer12[i],
file_offset, byte_count);
else
(*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info,
(void *)mem_buffer12[i],
file_offset, byte_count);
} else
#endif
{
if (writing)
(*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info,
(void *)ptr->mem_buffer[i],
file_offset, byte_count);
else
(*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info,
(void *)ptr->mem_buffer[i],
file_offset, byte_count);
}
file_offset += byte_count;
}
}
@@ -821,6 +891,15 @@ access_virt_sarray(j_common_ptr cinfo, jvirt_sarray_ptr ptr,
{
JDIMENSION end_row = start_row + num_rows;
JDIMENSION undef_row;
#ifdef WITH_12BIT
int data_precision = cinfo->is_decompressor ?
((j_decompress_ptr)cinfo)->data_precision :
((j_compress_ptr)cinfo)->data_precision;
size_t sample_size = data_precision == 12 ?
sizeof(J12SAMPLE) : sizeof(JSAMPLE);
#else
size_t sample_size = sizeof(JSAMPLE);
#endif
/* debugging check */
if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
@@ -876,7 +955,7 @@ access_virt_sarray(j_common_ptr cinfo, jvirt_sarray_ptr ptr,
if (writable)
ptr->first_undef_row = end_row;
if (ptr->pre_zero) {
size_t bytesperrow = (size_t)ptr->samplesperrow * sizeof(JSAMPLE);
size_t bytesperrow = (size_t)ptr->samplesperrow * sample_size;
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
end_row -= ptr->cur_start_row;
while (undef_row < end_row) {

View File

@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1992-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2017-2018, 2022, D. R. Commander.
* Copyright (C) 2017-2018, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -19,7 +19,7 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jmemsys.h" /* import the system-dependent declarations */

View File

@@ -14,9 +14,6 @@
* optimizations. Most users will not need to touch this file.
*/
#ifndef JMORECFG_H
#define JMORECFG_H
/*
* Maximum number of components (color channels) allowed in JPEG image.
@@ -44,8 +41,7 @@
* arrays is very slow on your hardware, you might want to change these.
*/
/* JSAMPLE should be the smallest type that will hold the values 0..255.
*/
/* JSAMPLE should be the smallest type that will hold the values 0..255. */
typedef unsigned char JSAMPLE;
#define GETJSAMPLE(value) ((int)(value))
@@ -54,15 +50,17 @@ typedef unsigned char JSAMPLE;
#define CENTERJSAMPLE 128
/* J12SAMPLE should be the smallest type that will hold the values 0..4095.
* On nearly all machines "short" will do nicely.
*/
#ifdef WITH_12BIT
/* J12SAMPLE should be the smallest type that will hold the values 0..4095. */
typedef short J12SAMPLE;
#define MAXJ12SAMPLE 4095
#define CENTERJ12SAMPLE 2048
#endif
/* Representation of a DCT frequency coefficient.
* This should be a signed value of at least 16 bits; "short" is usually OK.
@@ -376,5 +374,3 @@ static const int rgb_pixelsize[JPEG_NUMCS] = {
#endif
#endif /* JPEG_INTERNAL_OPTIONS */
#endif /* JMORECFG_H */

View File

@@ -1,391 +0,0 @@
/*
* jpeg12int.h
*
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 1997-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications:
* Copyright (C) 2015-2016, 2019, 2021-2022, D. R. Commander.
* Copyright (C) 2015, Google, Inc.
* Copyright (C) 2021, Alex Richardson.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
* This file provides common declarations for the various JPEG modules.
* These declarations are considered internal to the JPEG library; most
* applications using the library shouldn't need to include this file.
*/
#ifndef JPEG12INT_H
#define JPEG12INT_H
#ifndef JPEGINT_H
/* Declarations for both compression & decompression */
typedef enum { /* Operating modes for buffer controllers */
JBUF_PASS_THRU, /* Plain stripwise operation */
/* Remaining modes require a full-image buffer to have been created */
JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
} J_BUF_MODE;
/* Values of global_state field (jdapi.c has some dependencies on ordering!) */
#define CSTATE_START 100 /* after create_compress */
#define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
#define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
#define CSTATE_WRCOEFS 103 /* jpeg12_write_coefficients done */
#define DSTATE_START 200 /* after create_decompress */
#define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
#define DSTATE_READY 202 /* found SOS, ready for start_decompress */
#define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
#define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
#define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
#define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
#define DSTATE_BUFIMAGE 207 /* expecting jpeg12_start_output */
#define DSTATE_BUFPOST 208 /* looking for SOS/EOI in
jpeg12_finish_output */
#define DSTATE_RDCOEFS 209 /* reading file in jpeg12_read_coefficients */
#define DSTATE_STOPPING 210 /* looking for EOI in
jpeg12_finish_decompress */
/* JLONG must hold at least signed 32-bit values. */
typedef long JLONG;
/* JUINTPTR must hold pointer values. */
#ifdef __UINTPTR_TYPE__
/*
* __UINTPTR_TYPE__ is GNU-specific and available in GCC 4.6+ and Clang 3.0+.
* Fortunately, that is sufficient to support the few architectures for which
* sizeof(void *) != sizeof(size_t). The only other options would require C99
* or Clang-specific builtins.
*/
typedef __UINTPTR_TYPE__ JUINTPTR;
#else
typedef size_t JUINTPTR;
#endif
/*
* Left shift macro that handles a negative operand without causing any
* sanitizer warnings
*/
#define LEFT_SHIFT(a, b) ((JLONG)((unsigned long)(a) << (b)))
#endif /* JPEGINT_H */
/* Declarations for compression modules */
/* Master control module */
struct jpeg12_comp_master {
void (*prepare_for_pass) (j12_compress_ptr cinfo);
void (*pass_startup) (j12_compress_ptr cinfo);
void (*finish_pass) (j12_compress_ptr cinfo);
/* State variables made visible to other modules */
boolean call_pass_startup; /* True if pass_startup must be called */
boolean is_last_pass; /* True during last pass */
};
/* Main buffer control (downsampled-data buffer) */
struct jpeg12_c_main_controller {
void (*start_pass) (j12_compress_ptr cinfo, J_BUF_MODE pass_mode);
void (*process_data) (j12_compress_ptr cinfo, J12SAMPARRAY input_buf,
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail);
};
/* Compression preprocessing (downsampling input buffer control) */
struct jpeg12_c_prep_controller {
void (*start_pass) (j12_compress_ptr cinfo, J_BUF_MODE pass_mode);
void (*pre_process_data) (j12_compress_ptr cinfo, J12SAMPARRAY input_buf,
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail,
J12SAMPIMAGE output_buf,
JDIMENSION *out_row_group_ctr,
JDIMENSION out_row_groups_avail);
};
/* Coefficient buffer control */
struct jpeg12_c_coef_controller {
void (*start_pass) (j12_compress_ptr cinfo, J_BUF_MODE pass_mode);
boolean (*compress_data) (j12_compress_ptr cinfo, J12SAMPIMAGE input_buf);
};
/* Colorspace conversion */
struct jpeg12_color_converter {
void (*start_pass) (j12_compress_ptr cinfo);
void (*color_convert) (j12_compress_ptr cinfo, J12SAMPARRAY input_buf,
J12SAMPIMAGE output_buf, JDIMENSION output_row,
int num_rows);
};
/* Downsampling */
struct jpeg12_downsampler {
void (*start_pass) (j12_compress_ptr cinfo);
void (*downsample) (j12_compress_ptr cinfo, J12SAMPIMAGE input_buf,
JDIMENSION in_row_index, J12SAMPIMAGE output_buf,
JDIMENSION out_row_group_index);
boolean need_context_rows; /* TRUE if need rows above & below */
};
/* Forward DCT (also controls coefficient quantization) */
struct jpeg12_forward_dct {
void (*start_pass) (j12_compress_ptr cinfo);
/* perhaps this should be an array??? */
void (*forward_DCT) (j12_compress_ptr cinfo, jpeg_component_info *compptr,
J12SAMPARRAY sample_data, JBLOCKROW coef_blocks,
JDIMENSION start_row, JDIMENSION start_col,
JDIMENSION num_blocks);
};
/* Entropy encoding */
struct jpeg12_entropy_encoder {
void (*start_pass) (j12_compress_ptr cinfo, boolean gather_statistics);
boolean (*encode_mcu) (j12_compress_ptr cinfo, JBLOCKROW *MCU_data);
void (*finish_pass) (j12_compress_ptr cinfo);
};
/* Marker writing */
struct jpeg12_marker_writer {
void (*write_file_header) (j12_compress_ptr cinfo);
void (*write_frame_header) (j12_compress_ptr cinfo);
void (*write_scan_header) (j12_compress_ptr cinfo);
void (*write_file_trailer) (j12_compress_ptr cinfo);
void (*write_tables_only) (j12_compress_ptr cinfo);
/* These routines are exported to allow insertion of extra markers */
/* Probably only COM and APPn markers should be written this way */
void (*write_marker_header) (j12_compress_ptr cinfo, int marker,
unsigned int datalen);
void (*write_marker_byte) (j12_compress_ptr cinfo, int val);
};
/* Declarations for decompression modules */
/* Master control module */
struct jpeg12_decomp_master {
void (*prepare_for_output_pass) (j12_decompress_ptr cinfo);
void (*finish_output_pass) (j12_decompress_ptr cinfo);
/* State variables made visible to other modules */
boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
/* Partial decompression variables */
JDIMENSION first_iMCU_col;
JDIMENSION last_iMCU_col;
JDIMENSION first_MCU_col[MAX_COMPONENTS];
JDIMENSION last_MCU_col[MAX_COMPONENTS];
boolean jinit_upsampler_no_alloc;
/* Last iMCU row that was successfully decoded */
JDIMENSION last_good_iMCU_row;
};
/* Input control module */
struct jpeg12_input_controller {
int (*consume_input) (j12_decompress_ptr cinfo);
void (*reset_input_controller) (j12_decompress_ptr cinfo);
void (*start_input_pass) (j12_decompress_ptr cinfo);
void (*finish_input_pass) (j12_decompress_ptr cinfo);
/* State variables made visible to other modules */
boolean has_multiple_scans; /* True if file has multiple scans */
boolean eoi_reached; /* True when EOI has been consumed */
};
/* Main buffer control (downsampled-data buffer) */
struct jpeg12_d_main_controller {
void (*start_pass) (j12_decompress_ptr cinfo, J_BUF_MODE pass_mode);
void (*process_data) (j12_decompress_ptr cinfo, J12SAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
};
/* Coefficient buffer control */
struct jpeg12_d_coef_controller {
void (*start_input_pass) (j12_decompress_ptr cinfo);
int (*consume_data) (j12_decompress_ptr cinfo);
void (*start_output_pass) (j12_decompress_ptr cinfo);
int (*decompress_data) (j12_decompress_ptr cinfo, J12SAMPIMAGE output_buf);
/* Pointer to array of coefficient virtual arrays, or NULL if none */
jvirt_barray_ptr *coef_arrays;
};
/* Decompression postprocessing (color quantization buffer control) */
struct jpeg12_d_post_controller {
void (*start_pass) (j12_decompress_ptr cinfo, J_BUF_MODE pass_mode);
void (*post_process_data) (j12_decompress_ptr cinfo, J12SAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail,
J12SAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail);
};
/* Marker reading & parsing */
struct jpeg12_marker_reader {
void (*reset_marker_reader) (j12_decompress_ptr cinfo);
/* Read markers until SOS or EOI.
* Returns same codes as are defined for jpeg12_consume_input:
* JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
*/
int (*read_markers) (j12_decompress_ptr cinfo);
/* Read a restart marker --- exported for use by entropy decoder only */
jpeg12_marker_parser_method read_restart_marker;
/* State of marker reader --- nominally internal, but applications
* supplying COM or APPn handlers might like to know the state.
*/
boolean saw_SOI; /* found SOI? */
boolean saw_SOF; /* found SOF? */
int next_restart_num; /* next restart number expected (0-7) */
unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
};
/* Entropy decoding */
struct jpeg12_entropy_decoder {
void (*start_pass) (j12_decompress_ptr cinfo);
boolean (*decode_mcu) (j12_decompress_ptr cinfo, JBLOCKROW *MCU_data);
/* This is here to share code between baseline and progressive decoders; */
/* other modules probably should not use it */
boolean insufficient_data; /* set TRUE after emitting warning */
};
/* Inverse DCT (also performs dequantization) */
typedef void (*inverse_DCT_12_method_ptr) (j12_decompress_ptr cinfo,
jpeg_component_info *compptr,
JCOEFPTR coef_block,
J12SAMPARRAY output_buf,
JDIMENSION output_col);
struct jpeg12_inverse_dct {
void (*start_pass) (j12_decompress_ptr cinfo);
/* It is useful to allow each component to have a separate IDCT method. */
inverse_DCT_12_method_ptr inverse_DCT[MAX_COMPONENTS];
};
/* Upsampling (note that upsampler must also call color converter) */
struct jpeg12_upsampler {
void (*start_pass) (j12_decompress_ptr cinfo);
void (*upsample) (j12_decompress_ptr cinfo, J12SAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, J12SAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
boolean need_context_rows; /* TRUE if need rows above & below */
};
/* Colorspace conversion */
struct jpeg12_color_deconverter {
void (*start_pass) (j12_decompress_ptr cinfo);
void (*color_convert) (j12_decompress_ptr cinfo, J12SAMPIMAGE input_buf,
JDIMENSION input_row, J12SAMPARRAY output_buf,
int num_rows);
};
/* Color quantization or color precision reduction */
struct jpeg12_color_quantizer {
void (*start_pass) (j12_decompress_ptr cinfo, boolean is_pre_scan);
void (*color_quantize) (j12_decompress_ptr cinfo, J12SAMPARRAY input_buf,
J12SAMPARRAY output_buf, int num_rows);
void (*finish_pass) (j12_decompress_ptr cinfo);
void (*new_color_map) (j12_decompress_ptr cinfo);
};
/* Miscellaneous useful macros */
#undef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#undef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
/* We assume that right shift corresponds to signed division by 2 with
* rounding towards minus infinity. This is correct for typical "arithmetic
* shift" instructions that shift in copies of the sign bit. But some
* C compilers implement >> with an unsigned shift. For these machines you
* must define RIGHT_SHIFT_IS_UNSIGNED.
* RIGHT_SHIFT provides a proper signed right shift of a JLONG quantity.
* It is only applied with constant shift counts. SHIFT_TEMPS must be
* included in the variables of any routine using RIGHT_SHIFT.
*/
#ifdef RIGHT_SHIFT_IS_UNSIGNED
#define SHIFT_TEMPS JLONG shift_temp;
#define RIGHT_SHIFT(x, shft) \
((shift_temp = (x)) < 0 ? \
(shift_temp >> (shft)) | ((~((JLONG)0)) << (32 - (shft))) : \
(shift_temp >> (shft)))
#else
#define SHIFT_TEMPS
#define RIGHT_SHIFT(x, shft) ((x) >> (shft))
#endif
/* Compression module initialization routines */
EXTERN(void) j12init_compress_master(j12_compress_ptr cinfo);
EXTERN(void) j12init_c_master_control(j12_compress_ptr cinfo,
boolean transcode_only);
EXTERN(void) j12init_c_main_controller(j12_compress_ptr cinfo,
boolean need_full_buffer);
EXTERN(void) j12init_c_prep_controller(j12_compress_ptr cinfo,
boolean need_full_buffer);
EXTERN(void) j12init_c_coef_controller(j12_compress_ptr cinfo,
boolean need_full_buffer);
EXTERN(void) j12init_color_converter(j12_compress_ptr cinfo);
EXTERN(void) j12init_downsampler(j12_compress_ptr cinfo);
EXTERN(void) j12init_forward_dct(j12_compress_ptr cinfo);
EXTERN(void) j12init_huff_encoder(j12_compress_ptr cinfo);
EXTERN(void) j12init_phuff_encoder(j12_compress_ptr cinfo);
EXTERN(void) j12init_arith_encoder(j12_compress_ptr cinfo);
EXTERN(void) j12init_marker_writer(j12_compress_ptr cinfo);
/* Decompression module initialization routines */
EXTERN(void) j12init_master_decompress(j12_decompress_ptr cinfo);
EXTERN(void) j12init_d_main_controller(j12_decompress_ptr cinfo,
boolean need_full_buffer);
EXTERN(void) j12init_d_coef_controller(j12_decompress_ptr cinfo,
boolean need_full_buffer);
EXTERN(void) j12init_d_post_controller(j12_decompress_ptr cinfo,
boolean need_full_buffer);
EXTERN(void) j12init_input_controller(j12_decompress_ptr cinfo);
EXTERN(void) j12init_marker_reader(j12_decompress_ptr cinfo);
EXTERN(void) j12init_huff_decoder(j12_decompress_ptr cinfo);
EXTERN(void) j12init_phuff_decoder(j12_decompress_ptr cinfo);
EXTERN(void) j12init_arith_decoder(j12_decompress_ptr cinfo);
EXTERN(void) j12init_inverse_dct(j12_decompress_ptr cinfo);
EXTERN(void) j12init_upsampler(j12_decompress_ptr cinfo);
EXTERN(void) j12init_color_deconverter(j12_decompress_ptr cinfo);
EXTERN(void) j12init_1pass_quantizer(j12_decompress_ptr cinfo);
EXTERN(void) j12init_2pass_quantizer(j12_decompress_ptr cinfo);
EXTERN(void) j12init_merged_upsampler(j12_decompress_ptr cinfo);
/* Memory manager initialization */
EXTERN(void) j12init_memory_mgr(j12_common_ptr cinfo);
#ifndef JPEGINT_H
/* Utility routines in jutils.c */
EXTERN(long) j12div_round_up(long a, long b);
EXTERN(long) j12round_up(long a, long b);
#endif
EXTERN(void) j12copy_sample_rows(J12SAMPARRAY input_array, int source_row,
J12SAMPARRAY output_array, int dest_row,
int num_rows, JDIMENSION num_cols);
#ifndef JPEGINT_H
EXTERN(void) j12copy_block_row(JBLOCKROW input_row, JBLOCKROW output_row,
JDIMENSION num_blocks);
EXTERN(void) j12zero_far(void *target, size_t bytestozero);
/* Constant tables in jutils.c */
#if 0 /* This table is not actually needed in v6a */
extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
#endif
extern const int jpeg12_natural_order[]; /* zigzag coef order to natural
order */
/* Arithmetic coding probability estimation tables in jaricom.c */
extern const JLONG jpeg_aritab[];
#endif
#endif /* JPEG12INT_H */

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
/*
* jpegcomp.h
* jpegapicomp.h
*
* Copyright (C) 2010, 2020, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg

118
jpegint.h
View File

@@ -16,11 +16,6 @@
* applications using the library shouldn't need to include this file.
*/
#ifndef JPEGINT_H
#define JPEGINT_H
#ifndef JPEG12INT_H
/* Declarations for both compression & decompression */
@@ -73,8 +68,6 @@ typedef size_t JUINTPTR;
#define LEFT_SHIFT(a, b) ((JLONG)((unsigned long)(a) << (b)))
#endif /* JPEG12INT_H */
/* Declarations for compression modules */
@@ -94,6 +87,10 @@ struct jpeg_c_main_controller {
void (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode);
void (*process_data) (j_compress_ptr cinfo, JSAMPARRAY input_buf,
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail);
#ifdef WITH_12BIT
void (*process_data_12) (j_compress_ptr cinfo, J12SAMPARRAY input_buf,
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail);
#endif
};
/* Compression preprocessing (downsampling input buffer control) */
@@ -104,12 +101,23 @@ struct jpeg_c_prep_controller {
JSAMPIMAGE output_buf,
JDIMENSION *out_row_group_ctr,
JDIMENSION out_row_groups_avail);
#ifdef WITH_12BIT
void (*pre_process_data_12) (j_compress_ptr cinfo, J12SAMPARRAY input_buf,
JDIMENSION *in_row_ctr,
JDIMENSION in_rows_avail,
J12SAMPIMAGE output_buf,
JDIMENSION *out_row_group_ctr,
JDIMENSION out_row_groups_avail);
#endif
};
/* Coefficient buffer control */
struct jpeg_c_coef_controller {
void (*start_pass) (j_compress_ptr cinfo, J_BUF_MODE pass_mode);
boolean (*compress_data) (j_compress_ptr cinfo, JSAMPIMAGE input_buf);
#ifdef WITH_12BIT
boolean (*compress_data_12) (j_compress_ptr cinfo, J12SAMPIMAGE input_buf);
#endif
};
/* Colorspace conversion */
@@ -118,6 +126,11 @@ struct jpeg_color_converter {
void (*color_convert) (j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPIMAGE output_buf, JDIMENSION output_row,
int num_rows);
#ifdef WITH_12BIT
void (*color_convert_12) (j_compress_ptr cinfo, J12SAMPARRAY input_buf,
J12SAMPIMAGE output_buf, JDIMENSION output_row,
int num_rows);
#endif
};
/* Downsampling */
@@ -126,6 +139,11 @@ struct jpeg_downsampler {
void (*downsample) (j_compress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION in_row_index, JSAMPIMAGE output_buf,
JDIMENSION out_row_group_index);
#ifdef WITH_12BIT
void (*downsample_12) (j_compress_ptr cinfo, J12SAMPIMAGE input_buf,
JDIMENSION in_row_index, J12SAMPIMAGE output_buf,
JDIMENSION out_row_group_index);
#endif
boolean need_context_rows; /* TRUE if need rows above & below */
};
@@ -138,6 +156,12 @@ struct jpeg_forward_dct {
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
JDIMENSION start_row, JDIMENSION start_col,
JDIMENSION num_blocks);
#ifdef WITH_12BIT
void (*forward_DCT_12) (j_compress_ptr cinfo, jpeg_component_info *compptr,
J12SAMPARRAY sample_data, JBLOCKROW coef_blocks,
JDIMENSION start_row, JDIMENSION start_col,
JDIMENSION num_blocks);
#endif
};
/* Entropy encoding */
@@ -200,6 +224,10 @@ struct jpeg_d_main_controller {
void (*start_pass) (j_decompress_ptr cinfo, J_BUF_MODE pass_mode);
void (*process_data) (j_decompress_ptr cinfo, JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
#ifdef WITH_12BIT
void (*process_data_12) (j_decompress_ptr cinfo, J12SAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
#endif
};
/* Coefficient buffer control */
@@ -208,6 +236,9 @@ struct jpeg_d_coef_controller {
int (*consume_data) (j_decompress_ptr cinfo);
void (*start_output_pass) (j_decompress_ptr cinfo);
int (*decompress_data) (j_decompress_ptr cinfo, JSAMPIMAGE output_buf);
#ifdef WITH_12BIT
int (*decompress_data_12) (j_decompress_ptr cinfo, J12SAMPIMAGE output_buf);
#endif
/* Pointer to array of coefficient virtual arrays, or NULL if none */
jvirt_barray_ptr *coef_arrays;
};
@@ -220,6 +251,14 @@ struct jpeg_d_post_controller {
JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail);
#ifdef WITH_12BIT
void (*post_process_data_12) (j_decompress_ptr cinfo, J12SAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail,
J12SAMPARRAY output_buf,
JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail);
#endif
};
/* Marker reading & parsing */
@@ -258,11 +297,21 @@ typedef void (*inverse_DCT_method_ptr) (j_decompress_ptr cinfo,
JCOEFPTR coef_block,
JSAMPARRAY output_buf,
JDIMENSION output_col);
#ifdef WITH_12BIT
typedef void (*inverse_DCT_12_method_ptr) (j_decompress_ptr cinfo,
jpeg_component_info *compptr,
JCOEFPTR coef_block,
J12SAMPARRAY output_buf,
JDIMENSION output_col);
#endif
struct jpeg_inverse_dct {
void (*start_pass) (j_decompress_ptr cinfo);
/* It is useful to allow each component to have a separate IDCT method. */
inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
#ifdef WITH_12BIT
inverse_DCT_12_method_ptr inverse_DCT_12[MAX_COMPONENTS];
#endif
};
/* Upsampling (note that upsampler must also call color converter) */
@@ -272,6 +321,12 @@ struct jpeg_upsampler {
JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
#ifdef WITH_12BIT
void (*upsample_12) (j_decompress_ptr cinfo, J12SAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, J12SAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail);
#endif
boolean need_context_rows; /* TRUE if need rows above & below */
};
@@ -282,6 +337,11 @@ struct jpeg_color_deconverter {
void (*color_convert) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf,
int num_rows);
#ifdef WITH_12BIT
void (*color_convert_12) (j_decompress_ptr cinfo, J12SAMPIMAGE input_buf,
JDIMENSION input_row, J12SAMPARRAY output_buf,
int num_rows);
#endif
};
/* Color quantization or color precision reduction */
@@ -289,6 +349,10 @@ struct jpeg_color_quantizer {
void (*start_pass) (j_decompress_ptr cinfo, boolean is_pre_scan);
void (*color_quantize) (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows);
#ifdef WITH_12BIT
void (*color_quantize_12) (j_decompress_ptr cinfo, J12SAMPARRAY input_buf,
J12SAMPARRAY output_buf, int num_rows);
#endif
void (*finish_pass) (j_decompress_ptr cinfo);
void (*new_color_map) (j_decompress_ptr cinfo);
};
@@ -341,6 +405,19 @@ EXTERN(void) jinit_huff_encoder(j_compress_ptr cinfo);
EXTERN(void) jinit_phuff_encoder(j_compress_ptr cinfo);
EXTERN(void) jinit_arith_encoder(j_compress_ptr cinfo);
EXTERN(void) jinit_marker_writer(j_compress_ptr cinfo);
#ifdef WITH_12BIT
EXTERN(void) j12init_c_main_controller(j_compress_ptr cinfo,
boolean need_full_buffer);
EXTERN(void) j12init_c_prep_controller(j_compress_ptr cinfo,
boolean need_full_buffer);
EXTERN(void) j12init_c_coef_controller(j_compress_ptr cinfo,
boolean need_full_buffer);
EXTERN(void) j12init_color_converter(j_compress_ptr cinfo);
EXTERN(void) j12init_downsampler(j_compress_ptr cinfo);
EXTERN(void) j12init_forward_dct(j_compress_ptr cinfo);
#endif
/* Decompression module initialization routines */
EXTERN(void) jinit_master_decompress(j_decompress_ptr cinfo);
EXTERN(void) jinit_d_main_controller(j_decompress_ptr cinfo,
@@ -360,18 +437,36 @@ EXTERN(void) jinit_color_deconverter(j_decompress_ptr cinfo);
EXTERN(void) jinit_1pass_quantizer(j_decompress_ptr cinfo);
EXTERN(void) jinit_2pass_quantizer(j_decompress_ptr cinfo);
EXTERN(void) jinit_merged_upsampler(j_decompress_ptr cinfo);
#ifdef WITH_12BIT
EXTERN(void) j12init_d_main_controller(j_decompress_ptr cinfo,
boolean need_full_buffer);
EXTERN(void) j12init_d_coef_controller(j_decompress_ptr cinfo,
boolean need_full_buffer);
EXTERN(void) j12init_d_post_controller(j_decompress_ptr cinfo,
boolean need_full_buffer);
EXTERN(void) j12init_inverse_dct(j_decompress_ptr cinfo);
EXTERN(void) j12init_upsampler(j_decompress_ptr cinfo);
EXTERN(void) j12init_color_deconverter(j_decompress_ptr cinfo);
EXTERN(void) j12init_1pass_quantizer(j_decompress_ptr cinfo);
EXTERN(void) j12init_2pass_quantizer(j_decompress_ptr cinfo);
EXTERN(void) j12init_merged_upsampler(j_decompress_ptr cinfo);
#endif
/* Memory manager initialization */
EXTERN(void) jinit_memory_mgr(j_common_ptr cinfo);
#ifndef JPEG12INT_H
/* Utility routines in jutils.c */
EXTERN(long) jdiv_round_up(long a, long b);
EXTERN(long) jround_up(long a, long b);
#endif
EXTERN(void) jcopy_sample_rows(JSAMPARRAY input_array, int source_row,
JSAMPARRAY output_array, int dest_row,
int num_rows, JDIMENSION num_cols);
#ifndef JPEG12INT_H
#ifdef WITH_12BIT
EXTERN(void) j12copy_sample_rows(J12SAMPARRAY input_array, int source_row,
J12SAMPARRAY output_array, int dest_row,
int num_rows, JDIMENSION num_cols);
#endif
EXTERN(void) jcopy_block_row(JBLOCKROW input_row, JBLOCKROW output_row,
JDIMENSION num_blocks);
EXTERN(void) jzero_far(void *target, size_t bytestozero);
@@ -383,6 +478,3 @@ extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
/* Arithmetic coding probability estimation tables in jaricom.c */
extern const JLONG jpeg_aritab[];
#endif
#endif /* JPEGINT_H */

View File

@@ -70,7 +70,14 @@ typedef JSAMPLE *JSAMPROW; /* ptr to one image row of pixel samples. */
typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
#ifndef JPEG12LIB_H
#ifdef WITH_12BIT
typedef J12SAMPLE *J12SAMPROW; /* ptr to one image row of 12-bit pixel
samples. */
typedef J12SAMPROW *J12SAMPARRAY; /* ptr to some 12-bit sample rows (a 2-D
12-bit sample array) */
typedef J12SAMPARRAY *J12SAMPIMAGE; /* a 3-D 12-bit sample array: top index is
color */
#endif
typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
typedef JBLOCK *JBLOCKROW; /* pointer to one row of coefficient blocks */
@@ -266,8 +273,6 @@ typedef enum {
JDITHER_FS /* Floyd-Steinberg error diffusion dither */
} J_DITHER_MODE;
#endif /* JPEG12LIB_H */
/* Common fields between JPEG compression and decompression master structs. */
@@ -541,7 +546,11 @@ struct jpeg_decompress_struct {
* The map has out_color_components rows and actual_number_of_colors columns.
*/
int actual_number_of_colors; /* number of entries in use */
JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
JSAMPARRAY colormap; /* The color map as a 2-D pixel array
If data_precision is 12, then this is
actually a J12SAMPARRAY, so callers must
type-cast it in order to read/write 12-bit
samples from/to the array. */
/* State variables: these variables indicate the progress of decompression.
* The application may examine these but must not modify them.
@@ -659,7 +668,11 @@ struct jpeg_decompress_struct {
* v_samp_factor*DCT_[v_]scaled_size sample rows of a component per iMCU row.
*/
JSAMPLE *sample_range_limit; /* table for fast range-limiting */
JSAMPLE *sample_range_limit; /* table for fast range-limiting
If data_precision is 12, then this is
actually a J12SAMPLE pointer, so callers
must type-cast it in order to read 12-bit
samples from the array. */
/*
* These fields are valid during any one scan.
@@ -826,8 +839,6 @@ struct jpeg_source_mgr {
* successful.
*/
#ifndef JPEG12LIB_H
#define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
#define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
#define JPOOL_NUMPOOLS 2
@@ -835,14 +846,17 @@ struct jpeg_source_mgr {
typedef struct jvirt_sarray_control *jvirt_sarray_ptr;
typedef struct jvirt_barray_control *jvirt_barray_ptr;
#endif
struct jpeg_memory_mgr {
/* Method pointers */
void *(*alloc_small) (j_common_ptr cinfo, int pool_id, size_t sizeofobject);
void *(*alloc_large) (j_common_ptr cinfo, int pool_id,
size_t sizeofobject);
/* If cinfo->data_precision is 12, then this method and the
* access_virt_sarray method actually return a J12SAMPARRAY, so callers must
* type-cast the return value in order to read/write 12-bit samples from/to
* the array.
*/
JSAMPARRAY (*alloc_sarray) (j_common_ptr cinfo, int pool_id,
JDIMENSION samplesperrow, JDIMENSION numrows);
JBLOCKARRAY (*alloc_barray) (j_common_ptr cinfo, int pool_id,
@@ -959,6 +973,11 @@ EXTERN(void) jpeg_start_compress(j_compress_ptr cinfo,
EXTERN(JDIMENSION) jpeg_write_scanlines(j_compress_ptr cinfo,
JSAMPARRAY scanlines,
JDIMENSION num_lines);
#ifdef WITH_12BIT
EXTERN(JDIMENSION) jpeg12_write_scanlines(j_compress_ptr cinfo,
J12SAMPARRAY scanlines,
JDIMENSION num_lines);
#endif
EXTERN(void) jpeg_finish_compress(j_compress_ptr cinfo);
#if JPEG_LIB_VERSION >= 70
@@ -969,6 +988,11 @@ EXTERN(void) jpeg_calc_jpeg_dimensions(j_compress_ptr cinfo);
/* Replaces jpeg_write_scanlines when writing raw downsampled data. */
EXTERN(JDIMENSION) jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
JDIMENSION num_lines);
#ifdef WITH_12BIT
EXTERN(JDIMENSION) jpeg12_write_raw_data(j_compress_ptr cinfo,
J12SAMPIMAGE data,
JDIMENSION num_lines);
#endif
/* Write a special marker. See libjpeg.txt concerning safe usage. */
EXTERN(void) jpeg_write_marker(j_compress_ptr cinfo, int marker,
@@ -1004,15 +1028,33 @@ EXTERN(boolean) jpeg_start_decompress(j_decompress_ptr cinfo);
EXTERN(JDIMENSION) jpeg_read_scanlines(j_decompress_ptr cinfo,
JSAMPARRAY scanlines,
JDIMENSION max_lines);
#ifdef WITH_12BIT
EXTERN(JDIMENSION) jpeg12_read_scanlines(j_decompress_ptr cinfo,
J12SAMPARRAY scanlines,
JDIMENSION max_lines);
#endif
EXTERN(JDIMENSION) jpeg_skip_scanlines(j_decompress_ptr cinfo,
JDIMENSION num_lines);
#ifdef WITH_12BIT
EXTERN(JDIMENSION) jpeg12_skip_scanlines(j_decompress_ptr cinfo,
JDIMENSION num_lines);
#endif
EXTERN(void) jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
JDIMENSION *width);
#ifdef WITH_12BIT
EXTERN(void) jpeg12_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
JDIMENSION *width);
#endif
EXTERN(boolean) jpeg_finish_decompress(j_decompress_ptr cinfo);
/* Replaces jpeg_read_scanlines when reading raw downsampled data. */
EXTERN(JDIMENSION) jpeg_read_raw_data(j_decompress_ptr cinfo, JSAMPIMAGE data,
JDIMENSION max_lines);
#ifdef WITH_12BIT
EXTERN(JDIMENSION) jpeg12_read_raw_data(j_decompress_ptr cinfo,
J12SAMPIMAGE data,
JDIMENSION max_lines);
#endif
/* Additional entry points for buffered-image mode. */
EXTERN(boolean) jpeg_has_multiple_scans(j_decompress_ptr cinfo);

View File

@@ -1,346 +0,0 @@
/*
* jpeglibint.h
*
* Copyright (C) 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*/
#ifndef JPEGLIBINT_H
#define JPEGLIBINT_H
#if BITS_IN_JSAMPLE == 12
#include "jpeg12lib.h"
/* Rename all external types, functions, and macros that are affected by
JSAMPLE. */
#define JSAMPLE J12SAMPLE
#undef MAXJSAMPLE
#define MAXJSAMPLE MAXJ12SAMPLE
#undef CENTERJSAMPLE
#define CENTERJSAMPLE CENTERJ12SAMPLE
#define JSAMPROW J12SAMPROW
#define JSAMPARRAY J12SAMPARRAY
#define JSAMPIMAGE J12SAMPIMAGE
#define ERREXIT J12ERREXIT
#define ERREXIT1 J12ERREXIT1
#define ERREXIT2 J12ERREXIT2
#define ERREXIT3 J12ERREXIT3
#define ERREXIT4 J12ERREXIT4
#define ERREXIT6 J12ERREXIT6
#define ERREXITS J12ERREXITS
#define WARNMS J12WARNMS
#define WARNMS1 J12WARNMS1
#define WARNMS2 J12WARNMS2
#define TRACEMS J12TRACEMS
#define TRACEMS1 J12TRACEMS1
#define TRACEMS2 J12TRACEMS2
#define TRACEMS3 J12TRACEMS3
#define TRACEMS4 J12TRACEMS4
#define TRACEMS5 J12TRACEMS5
#define TRACEMS8 J12TRACEMS8
#define TRACEMSS J12TRACEMSS
#define jpeg_common_struct jpeg12_common_struct
#define j_common_ptr j12_common_ptr
#define j_compress_ptr j12_compress_ptr
#define j_decompress_ptr j12_decompress_ptr
#define jpeg_compress_struct jpeg12_compress_struct
#define jpeg_decompress_struct jpeg12_decompress_struct
#define jpeg_error_mgr jpeg12_error_mgr
#define jpeg_progress_mgr jpeg12_progress_mgr
#define jpeg_destination_mgr jpeg12_destination_mgr
#define jpeg_source_mgr jpeg12_source_mgr
#define jpeg_memory_mgr jpeg12_memory_mgr
#define jpeg_marker_parser_method jpeg12_marker_parser_method
#define jpeg_std_error jpeg12_std_error
#define jpeg_create_compress jpeg12_create_compress
#define jpeg_create_decompress jpeg12_create_decompress
#define jpeg_CreateCompress jpeg12_CreateCompress
#define jpeg_CreateDecompress jpeg12_CreateDecompress
#define jpeg_destroy_compress jpeg12_destroy_compress
#define jpeg_destroy_decompress jpeg12_destroy_decompress
#define jpeg_stdio_dest jpeg12_stdio_dest
#define jpeg_stdio_src jpeg12_stdio_src
#define jpeg_mem_dest jpeg12_mem_dest
#define jpeg_mem_src jpeg12_mem_src
#define jpeg_set_defaults jpeg12_set_defaults
#define jpeg_set_colorspace jpeg12_set_colorspace
#define jpeg_default_colorspace jpeg12_default_colorspace
#define jpeg_set_quality jpeg12_set_quality
#define jpeg_set_linear_quality jpeg12_set_linear_quality
#if JPEG_LIB_VERSION >= 70
#define jpeg_default_qtables jpeg12_default_qtables
#endif
#define jpeg_add_quant_table jpeg12_add_quant_table
#define jpeg_quality_scaling jpeg12_quality_scaling
#define jpeg_simple_progression jpeg12_simple_progression
#define jpeg_suppress_tables jpeg12_suppress_tables
#define jpeg_alloc_quant_table jpeg12_alloc_quant_table
#define jpeg_alloc_huff_table jpeg12_alloc_huff_table
#define jpeg_start_compress jpeg12_start_compress
#define jpeg_write_scanlines jpeg12_write_scanlines
#define jpeg_finish_compress jpeg12_finish_compress
#if JPEG_LIB_VERSION >= 70
#define jpeg_calc_jpeg_dimensions jpeg12_calc_jpeg_dimensions
#endif
#define jpeg_write_raw_data jpeg12_write_raw_data
#define jpeg_write_marker jpeg12_write_marker
#define jpeg_write_m_header jpeg12_write_m_header
#define jpeg_write_m_byte jpeg12_write_m_byte
#define jpeg_write_tables jpeg12_write_tables
#define jpeg_write_icc_profile jpeg12_write_icc_profile
#define jpeg_read_header jpeg12_read_header
#define jpeg_start_decompress jpeg12_start_decompress
#define jpeg_read_scanlines jpeg12_read_scanlines
#define jpeg_skip_scanlines jpeg12_skip_scanlines
#define jpeg_crop_scanline jpeg12_crop_scanline
#define jpeg_finish_decompress jpeg12_finish_decompress
#define jpeg_read_raw_data jpeg12_read_raw_data
#define jpeg_has_multiple_scans jpeg12_has_multiple_scans
#define jpeg_start_output jpeg12_start_output
#define jpeg_finish_output jpeg12_finish_output
#define jpeg_input_complete jpeg12_input_complete
#define jpeg_new_colormap jpeg12_new_colormap
#define jpeg_consume_input jpeg12_consume_input
#if JPEG_LIB_VERSION >= 80
#define jpeg_core_output_dimensions jpeg12_core_output_dimensions
#endif
#define jpeg_calc_output_dimensions jpeg12_calc_output_dimensions
#define jpeg_save_markers jpeg12_save_markers
#define jpeg_set_marker_processor jpeg12_set_marker_processor
#define jpeg_read_coefficients jpeg12_read_coefficients
#define jpeg_write_coefficients jpeg12_write_coefficients
#define jpeg_copy_critical_parameters jpeg12_copy_critical_parameters
#define jpeg_abort_compress jpeg12_abort_compress
#define jpeg_abort_decompress jpeg12_abort_decompress
#define jpeg_abort jpeg12_abort
#define jpeg_destroy jpeg12_destroy
#define jpeg_resync_to_restart jpeg12_resync_to_restart
#define jpeg_read_icc_profile jpeg12_read_icc_profile
/* Rename all internal types and functions that are affected by JSAMPLE. */
#ifdef JPEG_INTERNALS
#define jpeg_comp_master jpeg12_comp_master
#define jpeg_c_main_controller jpeg12_c_main_controller
#define jpeg_c_prep_controller jpeg12_c_prep_controller
#define jpeg_c_coef_controller jpeg12_c_coef_controller
#define jpeg_color_converter jpeg12_color_converter
#define jpeg_downsampler jpeg12_downsampler
#define jpeg_forward_dct jpeg12_forward_dct
#define jpeg_entropy_encoder jpeg12_entropy_encoder
#define jpeg_marker_writer jpeg12_marker_writer
#define jpeg_decomp_master jpeg12_decomp_master
#define jpeg_input_controller jpeg12_input_controller
#define jpeg_d_main_controller jpeg12_d_main_controller
#define jpeg_d_coef_controller jpeg12_d_coef_controller
#define jpeg_d_post_controller jpeg12_d_post_controller
#define jpeg_marker_reader jpeg12_marker_reader
#define jpeg_entropy_decoder jpeg12_entropy_decoder
#define inverse_DCT_method_ptr inverse_DCT_12_method_ptr
#define jpeg_inverse_dct jpeg12_inverse_dct
#define jpeg_upsampler jpeg12_upsampler
#define jpeg_color_deconverter jpeg12_color_deconverter
#define jpeg_color_quantizer jpeg12_color_quantizer
#define jinit_compress_master j12init_compress_master
#define jinit_c_master_control j12init_c_master_control
#define jinit_c_main_controller j12init_c_main_controller
#define jinit_c_prep_controller j12init_c_prep_controller
#define jinit_c_coef_controller j12init_c_coef_controller
#define jinit_color_converter j12init_color_converter
#define jinit_downsampler j12init_downsampler
#define jinit_forward_dct j12init_forward_dct
#define jinit_huff_encoder j12init_huff_encoder
#define jinit_phuff_encoder j12init_phuff_encoder
#define jinit_arith_encoder j12init_arith_encoder
#define jinit_marker_writer j12init_marker_writer
#define jinit_master_decompress j12init_master_decompress
#define jinit_d_main_controller j12init_d_main_controller
#define jinit_d_coef_controller j12init_d_coef_controller
#define jinit_d_post_controller j12init_d_post_controller
#define jinit_input_controller j12init_input_controller
#define jinit_marker_reader j12init_marker_reader
#define jinit_huff_decoder j12init_huff_decoder
#define jinit_phuff_decoder j12init_phuff_decoder
#define jinit_arith_decoder j12init_arith_decoder
#define jinit_inverse_dct j12init_inverse_dct
#define jinit_upsampler j12init_upsampler
#define jinit_color_deconverter j12init_color_deconverter
#define jinit_1pass_quantizer j12init_1pass_quantizer
#define jinit_2pass_quantizer j12init_2pass_quantizer
#define jinit_merged_upsampler j12init_merged_upsampler
#define jinit_memory_mgr j12init_memory_mgr
#define jdiv_round_up j12div_round_up
#define jround_up j12round_up
#define jcopy_sample_rows j12copy_sample_rows
#define jcopy_block_row j12copy_block_row
#define jzero_far j12zero_far
#define jpeg_natural_order jpeg12_natural_order
#define jpeg_make_c_derived_tbl jpeg12_make_c_derived_tbl
#define jpeg_gen_optimal_table jpeg12_gen_optimal_table
#define jpeg_fdct_islow jpeg12_fdct_islow
#define jpeg_fdct_ifast jpeg12_fdct_ifast
#define jpeg_fdct_float jpeg12_fdct_float
#define jpeg_idct_islow jpeg12_idct_islow
#define jpeg_idct_ifast jpeg12_idct_ifast
#define jpeg_idct_float jpeg12_idct_float
#define jpeg_idct_7x7 jpeg12_idct_7x7
#define jpeg_idct_6x6 jpeg12_idct_6x6
#define jpeg_idct_5x5 jpeg12_idct_5x5
#define jpeg_idct_4x4 jpeg12_idct_4x4
#define jpeg_idct_3x3 jpeg12_idct_3x3
#define jpeg_idct_2x2 jpeg12_idct_2x2
#define jpeg_idct_1x1 jpeg12_idct_1x1
#define jpeg_idct_9x9 jpeg12_idct_9x9
#define jpeg_idct_10x10 jpeg12_idct_10x10
#define jpeg_idct_11x11 jpeg12_idct_11x11
#define jpeg_idct_12x12 jpeg12_idct_12x12
#define jpeg_idct_13x13 jpeg12_idct_13x13
#define jpeg_idct_14x14 jpeg12_idct_14x14
#define jpeg_idct_15x15 jpeg12_idct_15x15
#define jpeg_idct_16x16 jpeg12_idct_16x16
#define jpeg_make_d_derived_tbl jpeg12_make_d_derived_tbl
#define jpeg_fill_bit_buffer jpeg12_fill_bit_buffer
#define jpeg_huff_decode jpeg12_huff_decode
#define jpeg_std_message_table jpeg12_std_message_table
#define jpeg_get_small jpeg12_get_small
#define jpeg_free_small jpeg12_free_small
#define jpeg_get_large jpeg12_get_large
#define jpeg_free_large jpeg12_free_large
#define jpeg_mem_available jpeg12_mem_available
#define jpeg_open_backing_store jpeg12_open_backing_store
#define jpeg_mem_init jpeg12_mem_init
#define jpeg_mem_term jpeg12_mem_term
#define jsimd_can_rgb_ycc j12simd_can_rgb_ycc
#define jsimd_can_rgb_gray j12simd_can_rgb_gray
#define jsimd_can_ycc_rgb j12simd_can_ycc_rgb
#define jsimd_can_ycc_rgb565 j12simd_can_ycc_rgb565
#define jsimd_c_can_null_convert j12simd_c_can_null_convert
#define jsimd_rgb_ycc_convert j12simd_rgb_ycc_convert
#define jsimd_rgb_gray_convert j12simd_rgb_gray_convert
#define jsimd_ycc_rgb_convert j12simd_ycc_rgb_convert
#define jsimd_ycc_rgb565_convert j12simd_ycc_rgb565_convert
#define jsimd_c_null_convert j12simd_c_null_convert
#define jsimd_can_h2v2_downsample j12simd_can_h2v2_downsample
#define jsimd_can_h2v1_downsample j12simd_can_h2v1_downsample
#define jsimd_h2v2_downsample j12simd_h2v2_downsample
#define jsimd_can_h2v2_smooth_downsample j12simd_can_h2v2_smooth_downsample
#define jsimd_h2v2_smooth_downsample j12simd_h2v2_smooth_downsample
#define jsimd_h2v1_downsample j12simd_h2v1_downsample
#define jsimd_can_h2v2_upsample j12simd_can_h2v2_upsample
#define jsimd_can_h2v1_upsample j12simd_can_h2v1_upsample
#define jsimd_can_int_upsample j12simd_can_int_upsample
#define jsimd_h2v2_upsample j12simd_h2v2_upsample
#define jsimd_h2v1_upsample j12simd_h2v1_upsample
#define jsimd_int_upsample j12simd_int_upsample
#define jsimd_can_h2v2_fancy_upsample j12simd_can_h2v2_fancy_upsample
#define jsimd_can_h2v1_fancy_upsample j12simd_can_h2v1_fancy_upsample
#define jsimd_can_h1v2_fancy_upsample j12simd_can_h1v2_fancy_upsample
#define jsimd_h2v2_fancy_upsample j12simd_h2v2_fancy_upsample
#define jsimd_h2v1_fancy_upsample j12simd_h2v1_fancy_upsample
#define jsimd_h1v2_fancy_upsample j12simd_h1v2_fancy_upsample
#define jsimd_can_h2v2_merged_upsample j12simd_can_h2v2_merged_upsample
#define jsimd_can_h2v1_merged_upsample j12simd_can_h2v1_merged_upsample
#define jsimd_h2v2_merged_upsample j12simd_h2v2_merged_upsample
#define jsimd_h2v1_merged_upsample j12simd_h2v1_merged_upsample
#define jsimd_can_huff_encode_one_block j12simd_can_huff_encode_one_block
#define jsimd_huff_encode_one_block j12simd_huff_encode_one_block
#define jsimd_can_encode_mcu_AC_first_prepare \
j12simd_can_encode_mcu_AC_first_prepare
#define jsimd_encode_mcu_AC_first_prepare \
j12simd_encode_mcu_AC_first_prepare
#define jsimd_can_encode_mcu_AC_refine_prepare \
j12simd_can_encode_mcu_AC_refine_prepare
#define jsimd_encode_mcu_AC_refine_prepare \
j12simd_encode_mcu_AC_refine_prepare
#define jsimd_can_convsamp j12simd_can_convsamp
#define jsimd_can_convsamp_float j12simd_can_convsamp_float
#define jsimd_convsamp j12simd_convsamp
#define jsimd_convsamp_float j12simd_convsamp_float
#define jsimd_can_fdct_islow j12simd_can_fdct_islow
#define jsimd_can_fdct_ifast j12simd_can_fdct_ifast
#define jsimd_can_fdct_float j12simd_can_fdct_float
#define jsimd_fdct_islow j12simd_fdct_islow
#define jsimd_fdct_ifast j12simd_fdct_ifast
#define jsimd_fdct_float j12simd_fdct_float
#define jsimd_can_quantize j12simd_can_quantize
#define jsimd_can_quantize_float j12simd_can_quantize_float
#define jsimd_quantize j12simd_quantize
#define jsimd_quantize_float j12simd_quantize_float
#define jsimd_can_idct_2x2 j12simd_can_idct_2x2
#define jsimd_can_idct_4x4 j12simd_can_idct_4x4
#define jsimd_can_idct_6x6 j12simd_can_idct_6x6
#define jsimd_can_idct_12x12 j12simd_can_idct_12x12
#define jsimd_idct_2x2 j12simd_idct_2x2
#define jsimd_idct_4x4 j12simd_idct_4x4
#define jsimd_idct_6x6 j12simd_idct_6x6
#define jsimd_idct_12x12 j12simd_idct_12x12
#define jsimd_can_idct_islow j12simd_can_idct_islow
#define jsimd_can_idct_ifast j12simd_can_idct_ifast
#define jsimd_can_idct_float j12simd_can_idct_float
#define jsimd_idct_islow j12simd_idct_islow
#define jsimd_idct_ifast j12simd_idct_ifast
#define jsimd_idct_float j12simd_idct_float
#endif /* JPEG_INTERNALS */
#else /* BITS_IN_JSAMPLE == 12 */
#include "jpeglib.h"
#endif
#endif /* JPEGLIBINT_H */

156
jquant1.c
View File

@@ -15,7 +15,8 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jsamplecomp.h"
#ifdef QUANT_1PASS_SUPPORTED
@@ -66,7 +67,7 @@
* worse, since the dither may be too much or too little at a given point.
*
* The normal calculation would be to form pixel value + dither, range-limit
* this to 0..MAXJSAMPLE, and then index into the colorindex table as usual.
* this to 0.._MAXJSAMPLE, and then index into the colorindex table as usual.
* We can skip the separate range-limiting step by extending the colorindex
* table in both directions.
*/
@@ -144,13 +145,13 @@ typedef struct {
struct jpeg_color_quantizer pub; /* public fields */
/* Initially allocated colormap is saved here */
JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
_JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
int sv_actual; /* number of entries in use */
JSAMPARRAY colorindex; /* Precomputed mapping for speed */
_JSAMPARRAY colorindex; /* Precomputed mapping for speed */
/* colorindex[i][j] = index of color closest to pixel value j in component i,
* premultiplied as described above. Since colormap indexes must fit into
* JSAMPLEs, the entries of this array will too.
* _JSAMPLEs, the entries of this array will too.
*/
boolean is_padded; /* is the colorindex padded for odither? */
@@ -248,24 +249,24 @@ select_ncolors(j_decompress_ptr cinfo, int Ncolors[])
LOCAL(int)
output_value(j_decompress_ptr cinfo, int ci, int j, int maxj)
/* Return j'th output value, where j will range from 0 to maxj */
/* The output values must fall in 0..MAXJSAMPLE in increasing order */
/* The output values must fall in 0.._MAXJSAMPLE in increasing order */
{
/* We always provide values 0 and MAXJSAMPLE for each component;
/* We always provide values 0 and _MAXJSAMPLE for each component;
* any additional values are equally spaced between these limits.
* (Forcing the upper and lower values to the limits ensures that
* dithering can't produce a color outside the selected gamut.)
*/
return (int)(((JLONG)j * MAXJSAMPLE + maxj / 2) / maxj);
return (int)(((JLONG)j * _MAXJSAMPLE + maxj / 2) / maxj);
}
LOCAL(int)
largest_input_value(j_decompress_ptr cinfo, int ci, int j, int maxj)
/* Return largest input value that should map to j'th output value */
/* Must have largest(j=0) >= 0, and largest(j=maxj) >= MAXJSAMPLE */
/* Must have largest(j=0) >= 0, and largest(j=maxj) >= _MAXJSAMPLE */
{
/* Breakpoints are halfway between values returned by output_value */
return (int)(((JLONG)(2 * j + 1) * MAXJSAMPLE + maxj) / (2 * maxj));
return (int)(((JLONG)(2 * j + 1) * _MAXJSAMPLE + maxj) / (2 * maxj));
}
@@ -277,7 +278,7 @@ LOCAL(void)
create_colormap(j_decompress_ptr cinfo)
{
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
JSAMPARRAY colormap; /* Created colormap */
_JSAMPARRAY colormap; /* Created colormap */
int total_colors; /* Number of distinct output colors */
int i, j, k, nci, blksize, blkdist, ptr, val;
@@ -296,7 +297,7 @@ create_colormap(j_decompress_ptr cinfo)
/* The colors are ordered in the map in standard row-major order, */
/* i.e. rightmost (highest-indexed) color changes most rapidly. */
colormap = (*cinfo->mem->alloc_sarray)
colormap = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE,
(JDIMENSION)total_colors, (JDIMENSION)cinfo->out_color_components);
@@ -315,7 +316,7 @@ create_colormap(j_decompress_ptr cinfo)
for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
/* fill in blksize entries beginning at ptr */
for (k = 0; k < blksize; k++)
colormap[i][ptr + k] = (JSAMPLE)val;
colormap[i][ptr + k] = (_JSAMPLE)val;
}
}
blkdist = blksize; /* blksize of this color is blkdist of next */
@@ -337,25 +338,25 @@ LOCAL(void)
create_colorindex(j_decompress_ptr cinfo)
{
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
JSAMPROW indexptr;
_JSAMPROW indexptr;
int i, j, k, nci, blksize, val, pad;
/* For ordered dither, we pad the color index tables by MAXJSAMPLE in
* each direction (input index values can be -MAXJSAMPLE .. 2*MAXJSAMPLE).
/* For ordered dither, we pad the color index tables by _MAXJSAMPLE in
* each direction (input index values can be -_MAXJSAMPLE .. 2*_MAXJSAMPLE).
* This is not necessary in the other dithering modes. However, we
* flag whether it was done in case user changes dithering mode.
*/
if (cinfo->dither_mode == JDITHER_ORDERED) {
pad = MAXJSAMPLE * 2;
pad = _MAXJSAMPLE * 2;
cquantize->is_padded = TRUE;
} else {
pad = 0;
cquantize->is_padded = FALSE;
}
cquantize->colorindex = (*cinfo->mem->alloc_sarray)
cquantize->colorindex = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE,
(JDIMENSION)(MAXJSAMPLE + 1 + pad),
(JDIMENSION)(_MAXJSAMPLE + 1 + pad),
(JDIMENSION)cinfo->out_color_components);
/* blksize is number of adjacent repeated entries for a component */
@@ -368,24 +369,24 @@ create_colorindex(j_decompress_ptr cinfo)
/* adjust colorindex pointers to provide padding at negative indexes. */
if (pad)
cquantize->colorindex[i] += MAXJSAMPLE;
cquantize->colorindex[i] += _MAXJSAMPLE;
/* in loop, val = index of current output value, */
/* and k = largest j that maps to current val */
indexptr = cquantize->colorindex[i];
val = 0;
k = largest_input_value(cinfo, i, 0, nci - 1);
for (j = 0; j <= MAXJSAMPLE; j++) {
for (j = 0; j <= _MAXJSAMPLE; j++) {
while (j > k) /* advance val if past boundary */
k = largest_input_value(cinfo, i, ++val, nci - 1);
/* premultiply so that no multiplication needed in main processing */
indexptr[j] = (JSAMPLE)(val * blksize);
indexptr[j] = (_JSAMPLE)(val * blksize);
}
/* Pad at both ends if necessary */
if (pad)
for (j = 1; j <= MAXJSAMPLE; j++) {
for (j = 1; j <= _MAXJSAMPLE; j++) {
indexptr[-j] = indexptr[0];
indexptr[MAXJSAMPLE + j] = indexptr[MAXJSAMPLE];
indexptr[_MAXJSAMPLE + j] = indexptr[_MAXJSAMPLE];
}
}
}
@@ -406,16 +407,16 @@ make_odither_array(j_decompress_ptr cinfo, int ncolors)
odither = (ODITHER_MATRIX_PTR)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(ODITHER_MATRIX));
/* The inter-value distance for this color is MAXJSAMPLE/(ncolors-1).
/* The inter-value distance for this color is _MAXJSAMPLE/(ncolors-1).
* Hence the dither value for the matrix cell with fill order f
* (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1).
* (f=0..N-1) should be (N-1-2*f)/(2*N) * _MAXJSAMPLE/(ncolors-1).
* On 16-bit-int machine, be careful to avoid overflow.
*/
den = 2 * ODITHER_CELLS * ((JLONG)(ncolors - 1));
for (j = 0; j < ODITHER_SIZE; j++) {
for (k = 0; k < ODITHER_SIZE; k++) {
num = ((JLONG)(ODITHER_CELLS - 1 -
2 * ((int)base_dither_matrix[j][k]))) * MAXJSAMPLE;
2 * ((int)base_dither_matrix[j][k]))) * _MAXJSAMPLE;
/* Ensure round towards zero despite C's lack of consistency
* about rounding negative values in integer division...
*/
@@ -460,14 +461,14 @@ create_odither_tables(j_decompress_ptr cinfo)
*/
METHODDEF(void)
color_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows)
color_quantize(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPARRAY output_buf, int num_rows)
/* General case, no dithering */
{
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
JSAMPARRAY colorindex = cquantize->colorindex;
_JSAMPARRAY colorindex = cquantize->colorindex;
register int pixcode, ci;
register JSAMPROW ptrin, ptrout;
register _JSAMPROW ptrin, ptrout;
int row;
JDIMENSION col;
JDIMENSION width = cinfo->output_width;
@@ -481,23 +482,23 @@ color_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (ci = 0; ci < nc; ci++) {
pixcode += colorindex[ci][*ptrin++];
}
*ptrout++ = (JSAMPLE)pixcode;
*ptrout++ = (_JSAMPLE)pixcode;
}
}
}
METHODDEF(void)
color_quantize3(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows)
color_quantize3(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPARRAY output_buf, int num_rows)
/* Fast path for out_color_components==3, no dithering */
{
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
register int pixcode;
register JSAMPROW ptrin, ptrout;
JSAMPROW colorindex0 = cquantize->colorindex[0];
JSAMPROW colorindex1 = cquantize->colorindex[1];
JSAMPROW colorindex2 = cquantize->colorindex[2];
register _JSAMPROW ptrin, ptrout;
_JSAMPROW colorindex0 = cquantize->colorindex[0];
_JSAMPROW colorindex1 = cquantize->colorindex[1];
_JSAMPROW colorindex2 = cquantize->colorindex[2];
int row;
JDIMENSION col;
JDIMENSION width = cinfo->output_width;
@@ -509,21 +510,21 @@ color_quantize3(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
pixcode = colorindex0[*ptrin++];
pixcode += colorindex1[*ptrin++];
pixcode += colorindex2[*ptrin++];
*ptrout++ = (JSAMPLE)pixcode;
*ptrout++ = (_JSAMPLE)pixcode;
}
}
}
METHODDEF(void)
quantize_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows)
quantize_ord_dither(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPARRAY output_buf, int num_rows)
/* General case, with ordered dithering */
{
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
register JSAMPROW input_ptr;
register JSAMPROW output_ptr;
JSAMPROW colorindex_ci;
register _JSAMPROW input_ptr;
register _JSAMPROW output_ptr;
_JSAMPROW colorindex_ci;
int *dither; /* points to active row of dither matrix */
int row_index, col_index; /* current indexes into dither matrix */
int nc = cinfo->out_color_components;
@@ -534,7 +535,7 @@ quantize_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (row = 0; row < num_rows; row++) {
/* Initialize output values to 0 so can process components separately */
jzero_far((void *)output_buf[row], (size_t)(width * sizeof(JSAMPLE)));
jzero_far((void *)output_buf[row], (size_t)(width * sizeof(_JSAMPLE)));
row_index = cquantize->row_index;
for (ci = 0; ci < nc; ci++) {
input_ptr = input_buf[row] + ci;
@@ -544,11 +545,11 @@ quantize_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
col_index = 0;
for (col = width; col > 0; col--) {
/* Form pixel value + dither, range-limit to 0..MAXJSAMPLE,
/* Form pixel value + dither, range-limit to 0.._MAXJSAMPLE,
* select output value, accumulate into output code for this pixel.
* Range-limiting need not be done explicitly, as we have extended
* the colorindex table to produce the right answers for out-of-range
* inputs. The maximum dither is +- MAXJSAMPLE; this sets the
* inputs. The maximum dither is +- _MAXJSAMPLE; this sets the
* required amount of padding.
*/
*output_ptr +=
@@ -566,17 +567,17 @@ quantize_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
METHODDEF(void)
quantize3_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows)
quantize3_ord_dither(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPARRAY output_buf, int num_rows)
/* Fast path for out_color_components==3, with ordered dithering */
{
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
register int pixcode;
register JSAMPROW input_ptr;
register JSAMPROW output_ptr;
JSAMPROW colorindex0 = cquantize->colorindex[0];
JSAMPROW colorindex1 = cquantize->colorindex[1];
JSAMPROW colorindex2 = cquantize->colorindex[2];
register _JSAMPROW input_ptr;
register _JSAMPROW output_ptr;
_JSAMPROW colorindex0 = cquantize->colorindex[0];
_JSAMPROW colorindex1 = cquantize->colorindex[1];
_JSAMPROW colorindex2 = cquantize->colorindex[2];
int *dither0; /* points to active row of dither matrix */
int *dither1;
int *dither2;
@@ -598,7 +599,7 @@ quantize3_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
pixcode = colorindex0[(*input_ptr++) + dither0[col_index]];
pixcode += colorindex1[(*input_ptr++) + dither1[col_index]];
pixcode += colorindex2[(*input_ptr++) + dither2[col_index]];
*output_ptr++ = (JSAMPLE)pixcode;
*output_ptr++ = (_JSAMPLE)pixcode;
col_index = (col_index + 1) & ODITHER_MASK;
}
row_index = (row_index + 1) & ODITHER_MASK;
@@ -608,8 +609,8 @@ quantize3_ord_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
METHODDEF(void)
quantize_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows)
quantize_fs_dither(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPARRAY output_buf, int num_rows)
/* General case, with Floyd-Steinberg dithering */
{
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
@@ -619,10 +620,10 @@ quantize_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
LOCFSERROR bnexterr; /* error for below/next col */
LOCFSERROR delta;
register FSERRPTR errorptr; /* => fserrors[] at column before current */
register JSAMPROW input_ptr;
register JSAMPROW output_ptr;
JSAMPROW colorindex_ci;
JSAMPROW colormap_ci;
register _JSAMPROW input_ptr;
register _JSAMPROW output_ptr;
_JSAMPROW colorindex_ci;
_JSAMPROW colormap_ci;
int pixcode;
int nc = cinfo->out_color_components;
int dir; /* 1 for left-to-right, -1 for right-to-left */
@@ -631,12 +632,12 @@ quantize_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
int row;
JDIMENSION col;
JDIMENSION width = cinfo->output_width;
JSAMPLE *range_limit = cinfo->sample_range_limit;
_JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
SHIFT_TEMPS
for (row = 0; row < num_rows; row++) {
/* Initialize output values to 0 so can process components separately */
jzero_far((void *)output_buf[row], (size_t)(width * sizeof(JSAMPLE)));
jzero_far((void *)output_buf[row], (size_t)(width * sizeof(_JSAMPLE)));
for (ci = 0; ci < nc; ci++) {
input_ptr = input_buf[row] + ci;
output_ptr = output_buf[row];
@@ -670,15 +671,15 @@ quantize_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
* Note: errorptr points to *previous* column's array entry.
*/
cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
/* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.
* The maximum error is +- MAXJSAMPLE; this sets the required size
/* Form pixel value + error, and range-limit to 0.._MAXJSAMPLE.
* The maximum error is +- _MAXJSAMPLE; this sets the required size
* of the range_limit array.
*/
cur += *input_ptr;
cur = range_limit[cur];
/* Select output value, accumulate into output code for this pixel */
pixcode = colorindex_ci[cur];
*output_ptr += (JSAMPLE)pixcode;
*output_ptr += (_JSAMPLE)pixcode;
/* Compute actual representation error at this pixel */
/* Note: we can do this even though we don't have the final */
/* pixel code, because the colormap is orthogonal. */
@@ -745,22 +746,22 @@ start_pass_1_quant(j_decompress_ptr cinfo, boolean is_pre_scan)
int i;
/* Install my colormap. */
cinfo->colormap = cquantize->sv_colormap;
cinfo->colormap = (JSAMPARRAY)cquantize->sv_colormap;
cinfo->actual_number_of_colors = cquantize->sv_actual;
/* Initialize for desired dithering mode. */
switch (cinfo->dither_mode) {
case JDITHER_NONE:
if (cinfo->out_color_components == 3)
cquantize->pub.color_quantize = color_quantize3;
cquantize->pub._color_quantize = color_quantize3;
else
cquantize->pub.color_quantize = color_quantize;
cquantize->pub._color_quantize = color_quantize;
break;
case JDITHER_ORDERED:
if (cinfo->out_color_components == 3)
cquantize->pub.color_quantize = quantize3_ord_dither;
cquantize->pub._color_quantize = quantize3_ord_dither;
else
cquantize->pub.color_quantize = quantize_ord_dither;
cquantize->pub._color_quantize = quantize_ord_dither;
cquantize->row_index = 0; /* initialize state for ordered dither */
/* If user changed to ordered dither from another mode,
* we must recreate the color index table with padding.
@@ -773,7 +774,7 @@ start_pass_1_quant(j_decompress_ptr cinfo, boolean is_pre_scan)
create_odither_tables(cinfo);
break;
case JDITHER_FS:
cquantize->pub.color_quantize = quantize_fs_dither;
cquantize->pub._color_quantize = quantize_fs_dither;
cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
/* Allocate Floyd-Steinberg workspace if didn't already. */
if (cquantize->fserrors[0] == NULL)
@@ -818,10 +819,13 @@ new_color_map_1_quant(j_decompress_ptr cinfo)
*/
GLOBAL(void)
jinit_1pass_quantizer(j_decompress_ptr cinfo)
_jinit_1pass_quantizer(j_decompress_ptr cinfo)
{
my_cquantize_ptr cquantize;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
cquantize = (my_cquantize_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_cquantizer));
@@ -835,9 +839,9 @@ jinit_1pass_quantizer(j_decompress_ptr cinfo)
/* Make sure my internal arrays won't overflow */
if (cinfo->out_color_components > MAX_Q_COMPS)
ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
/* Make sure colormap indexes can be represented by JSAMPLEs */
if (cinfo->desired_number_of_colors > (MAXJSAMPLE + 1))
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE + 1);
/* Make sure colormap indexes can be represented by _JSAMPLEs */
if (cinfo->desired_number_of_colors > (_MAXJSAMPLE + 1))
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, _MAXJSAMPLE + 1);
/* Create the colormap and color index table. */
create_colormap(cinfo);

123
jquant2.c
View File

@@ -22,7 +22,8 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jsamplecomp.h"
#ifdef QUANT_2PASS_SUPPORTED
@@ -106,7 +107,7 @@ static const int c_scales[3] = { R_SCALE, G_SCALE, B_SCALE };
* each 2-D array has 2^6*2^5 = 2048 or 2^6*2^6 = 4096 entries.
*/
#define MAXNUMCOLORS (MAXJSAMPLE + 1) /* maximum size of colormap */
#define MAXNUMCOLORS (_MAXJSAMPLE + 1) /* maximum size of colormap */
/* These will do the right thing for either R,G,B or B,G,R color order,
* but you may not like the results for other color orders.
@@ -173,7 +174,7 @@ typedef struct {
struct jpeg_color_quantizer pub; /* public fields */
/* Space for the eventually created colormap is stashed here */
JSAMPARRAY sv_colormap; /* colormap allocated at init time */
_JSAMPARRAY sv_colormap; /* colormap allocated at init time */
int desired; /* desired # of colors = size of colormap */
/* Variables for accumulating image statistics */
@@ -200,11 +201,11 @@ typedef my_cquantizer *my_cquantize_ptr;
*/
METHODDEF(void)
prescan_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows)
prescan_quantize(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPARRAY output_buf, int num_rows)
{
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
register JSAMPROW ptr;
register _JSAMPROW ptr;
register histptr histp;
register hist3d histogram = cquantize->histogram;
int row;
@@ -377,7 +378,7 @@ have_c2max:
* against making long narrow boxes, and it has the side benefit that
* a box is splittable iff norm > 0.
* Since the differences are expressed in histogram-cell units,
* we have to shift back to JSAMPLE units to get consistent distances;
* we have to shift back to _JSAMPLE units to get consistent distances;
* after which, we scale according to the selected distance scale factors.
*/
dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
@@ -508,9 +509,12 @@ compute_color(j_decompress_ptr cinfo, boxptr boxp, int icolor)
}
}
cinfo->colormap[0][icolor] = (JSAMPLE)((c0total + (total >> 1)) / total);
cinfo->colormap[1][icolor] = (JSAMPLE)((c1total + (total >> 1)) / total);
cinfo->colormap[2][icolor] = (JSAMPLE)((c2total + (total >> 1)) / total);
((_JSAMPARRAY)cinfo->colormap)[0][icolor] =
(_JSAMPLE)((c0total + (total >> 1)) / total);
((_JSAMPARRAY)cinfo->colormap)[1][icolor] =
(_JSAMPLE)((c1total + (total >> 1)) / total);
((_JSAMPARRAY)cinfo->colormap)[2][icolor] =
(_JSAMPLE)((c2total + (total >> 1)) / total);
}
@@ -528,11 +532,11 @@ select_colors(j_decompress_ptr cinfo, int desired_colors)
/* Initialize one box containing whole space */
numboxes = 1;
boxlist[0].c0min = 0;
boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
boxlist[0].c0max = _MAXJSAMPLE >> C0_SHIFT;
boxlist[0].c1min = 0;
boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
boxlist[0].c1max = _MAXJSAMPLE >> C1_SHIFT;
boxlist[0].c2min = 0;
boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
boxlist[0].c2max = _MAXJSAMPLE >> C2_SHIFT;
/* Shrink it to actually-used volume and set its statistics */
update_box(cinfo, &boxlist[0]);
/* Perform median-cut to produce final box list */
@@ -623,7 +627,7 @@ select_colors(j_decompress_ptr cinfo, int desired_colors)
LOCAL(int)
find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
JSAMPLE colorlist[])
_JSAMPLE colorlist[])
/* Locate the colormap entries close enough to an update box to be candidates
* for the nearest entry to some cell(s) in the update box. The update box
* is specified by the center coordinates of its first cell. The number of
@@ -665,7 +669,7 @@ find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
for (i = 0; i < numcolors; i++) {
/* We compute the squared-c0-distance term, then add in the other two. */
x = cinfo->colormap[0][i];
x = ((_JSAMPARRAY)cinfo->colormap)[0][i];
if (x < minc0) {
tdist = (x - minc0) * C0_SCALE;
min_dist = tdist * tdist;
@@ -688,7 +692,7 @@ find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
}
}
x = cinfo->colormap[1][i];
x = ((_JSAMPARRAY)cinfo->colormap)[1][i];
if (x < minc1) {
tdist = (x - minc1) * C1_SCALE;
min_dist += tdist * tdist;
@@ -710,7 +714,7 @@ find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
}
}
x = cinfo->colormap[2][i];
x = ((_JSAMPARRAY)cinfo->colormap)[2][i];
if (x < minc2) {
tdist = (x - minc2) * C2_SCALE;
min_dist += tdist * tdist;
@@ -744,7 +748,7 @@ find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
ncolors = 0;
for (i = 0; i < numcolors; i++) {
if (mindist[i] <= minmaxdist)
colorlist[ncolors++] = (JSAMPLE)i;
colorlist[ncolors++] = (_JSAMPLE)i;
}
return ncolors;
}
@@ -752,7 +756,7 @@ find_nearby_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
LOCAL(void)
find_best_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
int numcolors, _JSAMPLE colorlist[], _JSAMPLE bestcolor[])
/* Find the closest colormap entry for each cell in the update box,
* given the list of candidate colors prepared by find_nearby_colors.
* Return the indexes of the closest entries in the bestcolor[] array.
@@ -763,7 +767,7 @@ find_best_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
int ic0, ic1, ic2;
int i, icolor;
register JLONG *bptr; /* pointer into bestdist[] array */
JSAMPLE *cptr; /* pointer into bestcolor[] array */
_JSAMPLE *cptr; /* pointer into bestcolor[] array */
JLONG dist0, dist1; /* initial distance values */
register JLONG dist2; /* current distance in inner loop */
JLONG xx0, xx1; /* distance increments */
@@ -790,11 +794,11 @@ find_best_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
for (i = 0; i < numcolors; i++) {
icolor = colorlist[i];
/* Compute (square of) distance from minc0/c1/c2 to this color */
inc0 = (minc0 - cinfo->colormap[0][icolor]) * C0_SCALE;
inc0 = (minc0 - ((_JSAMPARRAY)cinfo->colormap)[0][icolor]) * C0_SCALE;
dist0 = inc0 * inc0;
inc1 = (minc1 - cinfo->colormap[1][icolor]) * C1_SCALE;
inc1 = (minc1 - ((_JSAMPARRAY)cinfo->colormap)[1][icolor]) * C1_SCALE;
dist0 += inc1 * inc1;
inc2 = (minc2 - cinfo->colormap[2][icolor]) * C2_SCALE;
inc2 = (minc2 - ((_JSAMPARRAY)cinfo->colormap)[2][icolor]) * C2_SCALE;
dist0 += inc2 * inc2;
/* Form the initial difference increments */
inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
@@ -813,7 +817,7 @@ find_best_colors(j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
for (ic2 = BOX_C2_ELEMS - 1; ic2 >= 0; ic2--) {
if (dist2 < *bptr) {
*bptr = dist2;
*cptr = (JSAMPLE)icolor;
*cptr = (_JSAMPLE)icolor;
}
dist2 += xx2;
xx2 += 2 * STEP_C2 * STEP_C2;
@@ -840,13 +844,13 @@ fill_inverse_cmap(j_decompress_ptr cinfo, int c0, int c1, int c2)
hist3d histogram = cquantize->histogram;
int minc0, minc1, minc2; /* lower left corner of update box */
int ic0, ic1, ic2;
register JSAMPLE *cptr; /* pointer into bestcolor[] array */
register _JSAMPLE *cptr; /* pointer into bestcolor[] array */
register histptr cachep; /* pointer into main cache array */
/* This array lists the candidate colormap indexes. */
JSAMPLE colorlist[MAXNUMCOLORS];
_JSAMPLE colorlist[MAXNUMCOLORS];
int numcolors; /* number of candidate colors */
/* This array holds the actually closest colormap index for each cell. */
JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
_JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
/* Convert cell coordinates to update box ID */
c0 >>= BOX_C0_LOG;
@@ -891,13 +895,13 @@ fill_inverse_cmap(j_decompress_ptr cinfo, int c0, int c1, int c2)
*/
METHODDEF(void)
pass2_no_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows)
pass2_no_dither(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPARRAY output_buf, int num_rows)
/* This version performs no dithering */
{
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
hist3d histogram = cquantize->histogram;
register JSAMPROW inptr, outptr;
register _JSAMPROW inptr, outptr;
register histptr cachep;
register int c0, c1, c2;
int row;
@@ -918,15 +922,15 @@ pass2_no_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
if (*cachep == 0)
fill_inverse_cmap(cinfo, c0, c1, c2);
/* Now emit the colormap index for this cell */
*outptr++ = (JSAMPLE)(*cachep - 1);
*outptr++ = (_JSAMPLE)(*cachep - 1);
}
}
}
METHODDEF(void)
pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows)
pass2_fs_dither(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPARRAY output_buf, int num_rows)
/* This version performs Floyd-Steinberg dithering */
{
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
@@ -935,19 +939,19 @@ pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
register FSERRPTR errorptr; /* => fserrors[] at column before current */
JSAMPROW inptr; /* => current input pixel */
JSAMPROW outptr; /* => current output pixel */
_JSAMPROW inptr; /* => current input pixel */
_JSAMPROW outptr; /* => current output pixel */
histptr cachep;
int dir; /* +1 or -1 depending on direction */
int dir3; /* 3*dir, for advancing inptr & errorptr */
int row;
JDIMENSION col;
JDIMENSION width = cinfo->output_width;
JSAMPLE *range_limit = cinfo->sample_range_limit;
_JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
int *error_limit = cquantize->error_limiter;
JSAMPROW colormap0 = cinfo->colormap[0];
JSAMPROW colormap1 = cinfo->colormap[1];
JSAMPROW colormap2 = cinfo->colormap[2];
_JSAMPROW colormap0 = ((_JSAMPARRAY)cinfo->colormap)[0];
_JSAMPROW colormap1 = ((_JSAMPARRAY)cinfo->colormap)[1];
_JSAMPROW colormap2 = ((_JSAMPARRAY)cinfo->colormap)[2];
SHIFT_TEMPS
for (row = 0; row < num_rows; row++) {
@@ -992,8 +996,8 @@ pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
cur0 = error_limit[cur0];
cur1 = error_limit[cur1];
cur2 = error_limit[cur2];
/* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.
* The maximum error is +- MAXJSAMPLE (or less with error limiting);
/* Form pixel value + error, and range-limit to 0.._MAXJSAMPLE.
* The maximum error is +- _MAXJSAMPLE (or less with error limiting);
* this sets the required size of the range_limit array.
*/
cur0 += inptr[0];
@@ -1013,7 +1017,7 @@ pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
/* Now emit the colormap index for this cell */
{
register int pixcode = *cachep - 1;
*outptr = (JSAMPLE)pixcode;
*outptr = (_JSAMPLE)pixcode;
/* Compute representation error for this pixel */
cur0 -= colormap0[pixcode];
cur1 -= colormap1[pixcode];
@@ -1064,7 +1068,7 @@ pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
/*
* Initialize the error-limiting transfer function (lookup table).
* The raw F-S error computation can potentially compute error values of up to
* +- MAXJSAMPLE. But we want the maximum correction applied to a pixel to be
* +- _MAXJSAMPLE. But we want the maximum correction applied to a pixel to be
* much less, otherwise obviously wrong pixels will be created. (Typical
* effects include weird fringes at color-area boundaries, isolated bright
* pixels in a dark area, etc.) The standard advice for avoiding this problem
@@ -1073,7 +1077,7 @@ pass2_fs_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
* error buildup. However, that only prevents the error from getting
* completely out of hand; Aaron Giles reports that error limiting improves
* the results even with corner colors allocated.
* A simple clamping of the error values to about +- MAXJSAMPLE/8 works pretty
* A simple clamping of the error values to about +- _MAXJSAMPLE/8 works pretty
* well, but the smoother transfer function used below is even better. Thanks
* to Aaron Giles for this idea.
*/
@@ -1087,22 +1091,22 @@ init_error_limit(j_decompress_ptr cinfo)
int in, out;
table = (int *)(*cinfo->mem->alloc_small)
((j_common_ptr)cinfo, JPOOL_IMAGE, (MAXJSAMPLE * 2 + 1) * sizeof(int));
table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
((j_common_ptr)cinfo, JPOOL_IMAGE, (_MAXJSAMPLE * 2 + 1) * sizeof(int));
table += _MAXJSAMPLE; /* so can index -_MAXJSAMPLE .. +_MAXJSAMPLE */
cquantize->error_limiter = table;
#define STEPSIZE ((MAXJSAMPLE + 1) / 16)
/* Map errors 1:1 up to +- MAXJSAMPLE/16 */
#define STEPSIZE ((_MAXJSAMPLE + 1) / 16)
/* Map errors 1:1 up to +- _MAXJSAMPLE/16 */
out = 0;
for (in = 0; in < STEPSIZE; in++, out++) {
table[in] = out; table[-in] = -out;
}
/* Map errors 1:2 up to +- 3*MAXJSAMPLE/16 */
/* Map errors 1:2 up to +- 3*_MAXJSAMPLE/16 */
for (; in < STEPSIZE * 3; in++, out += (in & 1) ? 0 : 1) {
table[in] = out; table[-in] = -out;
}
/* Clamp the rest to final out value (which is (MAXJSAMPLE+1)/8) */
for (; in <= MAXJSAMPLE; in++) {
/* Clamp the rest to final out value (which is (_MAXJSAMPLE+1)/8) */
for (; in <= _MAXJSAMPLE; in++) {
table[in] = out; table[-in] = -out;
}
#undef STEPSIZE
@@ -1119,7 +1123,7 @@ finish_pass1(j_decompress_ptr cinfo)
my_cquantize_ptr cquantize = (my_cquantize_ptr)cinfo->cquantize;
/* Select the representative colors and fill in cinfo->colormap */
cinfo->colormap = cquantize->sv_colormap;
cinfo->colormap = (JSAMPARRAY)cquantize->sv_colormap;
select_colors(cinfo, cquantize->desired);
/* Force next pass to zero the color index table */
cquantize->needs_zeroed = TRUE;
@@ -1151,15 +1155,15 @@ start_pass_2_quant(j_decompress_ptr cinfo, boolean is_pre_scan)
if (is_pre_scan) {
/* Set up method pointers */
cquantize->pub.color_quantize = prescan_quantize;
cquantize->pub._color_quantize = prescan_quantize;
cquantize->pub.finish_pass = finish_pass1;
cquantize->needs_zeroed = TRUE; /* Always zero histogram */
} else {
/* Set up method pointers */
if (cinfo->dither_mode == JDITHER_FS)
cquantize->pub.color_quantize = pass2_fs_dither;
cquantize->pub._color_quantize = pass2_fs_dither;
else
cquantize->pub.color_quantize = pass2_no_dither;
cquantize->pub._color_quantize = pass2_no_dither;
cquantize->pub.finish_pass = finish_pass2;
/* Make sure color count is acceptable */
@@ -1215,11 +1219,14 @@ new_color_map_2_quant(j_decompress_ptr cinfo)
*/
GLOBAL(void)
jinit_2pass_quantizer(j_decompress_ptr cinfo)
_jinit_2pass_quantizer(j_decompress_ptr cinfo)
{
my_cquantize_ptr cquantize;
int i;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
cquantize = (my_cquantize_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_cquantizer));
@@ -1253,10 +1260,10 @@ jinit_2pass_quantizer(j_decompress_ptr cinfo)
/* Lower bound on # of colors ... somewhat arbitrary as long as > 0 */
if (desired < 8)
ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
/* Make sure colormap indexes can be represented by JSAMPLEs */
/* Make sure colormap indexes can be represented by _JSAMPLEs */
if (desired > MAXNUMCOLORS)
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
cquantize->sv_colormap = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE, (JDIMENSION)desired, (JDIMENSION)3);
cquantize->desired = desired;
} else

235
jsamplecomp.h Normal file
View File

@@ -0,0 +1,235 @@
/*
* jsamplecomp.h
*
* Copyright (C) 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*/
/* In source files that must be compiled for multiple data precisions, we
* prefix all precision-dependent data types, macros, methods, fields, and
* function names with an underscore. Including this file replaces those
* precision-independent tokens with their precision-dependent equivalents,
* based on the value of BITS_IN_JSAMPLE.
*/
#ifndef JSAMPLECOMP_H
#define JSAMPLECOMP_H
#if BITS_IN_JSAMPLE == 12
/* Sample data types and macros (jmorecfg.h) */
#define _JSAMPLE J12SAMPLE
#define _MAXJSAMPLE MAXJ12SAMPLE
#define _CENTERJSAMPLE CENTERJ12SAMPLE
#define _JSAMPROW J12SAMPROW
#define _JSAMPARRAY J12SAMPARRAY
#define _JSAMPIMAGE J12SAMPIMAGE
/* External functions (jpeglib.h) */
#define _jpeg_write_scanlines jpeg12_write_scanlines
#define _jpeg_write_raw_data jpeg12_write_raw_data
#define _jpeg_read_scanlines jpeg12_read_scanlines
#define _jpeg_skip_scanlines jpeg12_skip_scanlines
#define _jpeg_crop_scanline jpeg12_crop_scanline
#define _jpeg_read_raw_data jpeg12_read_raw_data
/* Internal methods (jpegint.h) */
/* Use the 12-bit method in the jpeg_c_main_controller structure. */
#define _process_data process_data_12
/* Use the 12-bit method in the jpeg_c_prep_controller structure. */
#define _pre_process_data pre_process_data_12
/* Use the 12-bit method in the jpeg_c_coef_controller structure. */
#define _compress_data compress_data_12
/* Use the 12-bit method in the jpeg_color_converter structure. */
#define _color_convert color_convert_12
/* Use the 12-bit method in the jpeg_downsampler structure. */
#define _downsample downsample_12
/* Use the 12-bit method in the jpeg_forward_dct structure. */
#define _forward_DCT forward_DCT_12
/* Use the 12-bit method in the jpeg_d_main_controller structure. */
#define _process_data process_data_12
/* Use the 12-bit method in the jpeg_d_coef_controller structure. */
#define _decompress_data decompress_data_12
/* Use the 12-bit method in the jpeg_d_post_controller structure. */
#define _post_process_data post_process_data_12
/* Use the 12-bit method in the jpeg_inverse_dct structure. */
#define _inverse_DCT_method_ptr inverse_DCT_12_method_ptr
#define _inverse_DCT inverse_DCT_12
/* Use the 12-bit method in the jpeg_upsampler structure. */
#define _upsample upsample_12
/* Use the 12-bit method in the jpeg_color_converter structure. */
#define _color_convert color_convert_12
/* Use the 12-bit method in the jpeg_color_quantizer structure. */
#define _color_quantize color_quantize_12
/* Global internal functions (jpegint.h) */
#define _jinit_c_main_controller j12init_c_main_controller
#define _jinit_c_prep_controller j12init_c_prep_controller
#define _jinit_c_coef_controller j12init_c_coef_controller
#define _jinit_color_converter j12init_color_converter
#define _jinit_downsampler j12init_downsampler
#define _jinit_forward_dct j12init_forward_dct
#define _jinit_d_main_controller j12init_d_main_controller
#define _jinit_d_coef_controller j12init_d_coef_controller
#define _jinit_d_post_controller j12init_d_post_controller
#define _jinit_inverse_dct j12init_inverse_dct
#define _jinit_upsampler j12init_upsampler
#define _jinit_color_deconverter j12init_color_deconverter
#define _jinit_1pass_quantizer j12init_1pass_quantizer
#define _jinit_2pass_quantizer j12init_2pass_quantizer
#define _jinit_merged_upsampler j12init_merged_upsampler
#define _jcopy_sample_rows j12copy_sample_rows
/* Global internal functions (jdct.h) */
#define _jpeg_fdct_islow jpeg12_fdct_islow
#define _jpeg_fdct_ifast jpeg12_fdct_ifast
#define _jpeg_idct_islow jpeg12_idct_islow
#define _jpeg_idct_ifast jpeg12_idct_ifast
#define _jpeg_idct_float jpeg12_idct_float
#define _jpeg_idct_7x7 jpeg12_idct_7x7
#define _jpeg_idct_6x6 jpeg12_idct_6x6
#define _jpeg_idct_5x5 jpeg12_idct_5x5
#define _jpeg_idct_4x4 jpeg12_idct_4x4
#define _jpeg_idct_3x3 jpeg12_idct_3x3
#define _jpeg_idct_2x2 jpeg12_idct_2x2
#define _jpeg_idct_1x1 jpeg12_idct_1x1
#define _jpeg_idct_9x9 jpeg12_idct_9x9
#define _jpeg_idct_10x10 jpeg12_idct_10x10
#define _jpeg_idct_11x11 jpeg12_idct_11x11
#define _jpeg_idct_12x12 jpeg12_idct_12x12
#define _jpeg_idct_13x13 jpeg12_idct_13x13
#define _jpeg_idct_14x14 jpeg12_idct_14x14
#define _jpeg_idct_15x15 jpeg12_idct_15x15
#define _jpeg_idct_16x16 jpeg12_idct_16x16
/* Internal fields (cdjpeg.h) */
/* Use the 12-bit buffer in the cjpeg_source_struct and djpeg_dest_struct
structures. */
#define _buffer buffer12
/* Image I/O functions (cdjpeg.h) */
#define _jinit_read_gif j12init_read_gif
#define _jinit_write_gif j12init_write_gif
#define _jinit_read_ppm j12init_read_ppm
#define _jinit_write_ppm j12init_write_ppm
#define _read_color_map read_color_map_12
#else /* BITS_IN_JSAMPLE */
/* Sample data types and macros (jmorecfg.h) */
#define _JSAMPLE JSAMPLE
#define _MAXJSAMPLE MAXJSAMPLE
#define _CENTERJSAMPLE CENTERJSAMPLE
#define _JSAMPROW JSAMPROW
#define _JSAMPARRAY JSAMPARRAY
#define _JSAMPIMAGE JSAMPIMAGE
/* External functions (jpeglib.h) */
#define _jpeg_write_scanlines jpeg_write_scanlines
#define _jpeg_write_raw_data jpeg_write_raw_data
#define _jpeg_read_scanlines jpeg_read_scanlines
#define _jpeg_skip_scanlines jpeg_skip_scanlines
#define _jpeg_crop_scanline jpeg_crop_scanline
#define _jpeg_read_raw_data jpeg_read_raw_data
/* Internal methods (jpegint.h) */
/* Use the 8-bit method in the jpeg_c_main_controller structure. */
#define _process_data process_data
/* Use the 8-bit method in the jpeg_c_prep_controller structure. */
#define _pre_process_data pre_process_data
/* Use the 8-bit method in the jpeg_c_coef_controller structure. */
#define _compress_data compress_data
/* Use the 8-bit method in the jpeg_color_converter structure. */
#define _color_convert color_convert
/* Use the 8-bit method in the jpeg_downsampler structure. */
#define _downsample downsample
/* Use the 8-bit method in the jpeg_forward_dct structure. */
#define _forward_DCT forward_DCT
/* Use the 8-bit method in the jpeg_d_main_controller structure. */
#define _process_data process_data
/* Use the 8-bit method in the jpeg_d_coef_controller structure. */
#define _decompress_data decompress_data
/* Use the 8-bit method in the jpeg_d_post_controller structure. */
#define _post_process_data post_process_data
/* Use the 8-bit method in the jpeg_inverse_dct structure. */
#define _inverse_DCT_method_ptr inverse_DCT_method_ptr
#define _inverse_DCT inverse_DCT
/* Use the 8-bit method in the jpeg_upsampler structure. */
#define _upsample upsample
/* Use the 8-bit method in the jpeg_color_converter structure. */
#define _color_convert color_convert
/* Use the 8-bit method in the jpeg_color_quantizer structure. */
#define _color_quantize color_quantize
/* Global internal functions (jpegint.h) */
#define _jinit_c_main_controller jinit_c_main_controller
#define _jinit_c_prep_controller jinit_c_prep_controller
#define _jinit_c_coef_controller jinit_c_coef_controller
#define _jinit_color_converter jinit_color_converter
#define _jinit_downsampler jinit_downsampler
#define _jinit_forward_dct jinit_forward_dct
#define _jinit_d_main_controller jinit_d_main_controller
#define _jinit_d_coef_controller jinit_d_coef_controller
#define _jinit_d_post_controller jinit_d_post_controller
#define _jinit_inverse_dct jinit_inverse_dct
#define _jinit_upsampler jinit_upsampler
#define _jinit_color_deconverter jinit_color_deconverter
#define _jinit_1pass_quantizer jinit_1pass_quantizer
#define _jinit_2pass_quantizer jinit_2pass_quantizer
#define _jinit_merged_upsampler jinit_merged_upsampler
#define _jcopy_sample_rows jcopy_sample_rows
/* Global internal functions (jdct.h) */
#define _jpeg_fdct_islow jpeg_fdct_islow
#define _jpeg_fdct_ifast jpeg_fdct_ifast
#define _jpeg_idct_islow jpeg_idct_islow
#define _jpeg_idct_ifast jpeg_idct_ifast
#define _jpeg_idct_float jpeg_idct_float
#define _jpeg_idct_7x7 jpeg_idct_7x7
#define _jpeg_idct_6x6 jpeg_idct_6x6
#define _jpeg_idct_5x5 jpeg_idct_5x5
#define _jpeg_idct_4x4 jpeg_idct_4x4
#define _jpeg_idct_3x3 jpeg_idct_3x3
#define _jpeg_idct_2x2 jpeg_idct_2x2
#define _jpeg_idct_1x1 jpeg_idct_1x1
#define _jpeg_idct_9x9 jpeg_idct_9x9
#define _jpeg_idct_10x10 jpeg_idct_10x10
#define _jpeg_idct_11x11 jpeg_idct_11x11
#define _jpeg_idct_12x12 jpeg_idct_12x12
#define _jpeg_idct_13x13 jpeg_idct_13x13
#define _jpeg_idct_14x14 jpeg_idct_14x14
#define _jpeg_idct_15x15 jpeg_idct_15x15
#define _jpeg_idct_16x16 jpeg_idct_16x16
/* Internal fields (cdjpeg.h) */
/* Use the 8-bit buffer in the cjpeg_source_struct and djpeg_dest_struct
structures. */
#define _buffer buffer
/* Image I/O functions (cdjpeg.h) */
#define _jinit_read_gif jinit_read_gif
#define _jinit_write_gif jinit_write_gif
#define _jinit_read_ppm jinit_read_ppm
#define _jinit_write_ppm jinit_write_ppm
#define _read_color_map read_color_map
#endif /* BITS_IN_JSAMPLE */
#endif /* JSAMPLECOMP_H */

View File

@@ -2,7 +2,7 @@
* jsimd.h
*
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2011, 2014, D. R. Commander.
* Copyright (C) 2011, 2014, 2022, D. R. Commander.
* Copyright (C) 2015-2016, 2018, Matthieu Darbois.
* Copyright (C) 2020, Arm Limited.
*
@@ -12,6 +12,8 @@
*
*/
#ifdef WITH_SIMD
#include "jchuff.h" /* Declarations shared with jcphuff.c */
EXTERN(int) jsimd_can_rgb_ycc(void);
@@ -121,3 +123,5 @@ EXTERN(int) jsimd_can_encode_mcu_AC_refine_prepare(void);
EXTERN(int) jsimd_encode_mcu_AC_refine_prepare
(const JCOEF *block, const int *jpeg_natural_order_start, int Sl, int Al,
JCOEF *absvalues, size_t *bits);
#endif /* WITH_SIMD */

View File

@@ -1,431 +0,0 @@
/*
* jsimd_none.c
*
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2009-2011, 2014, 2022, D. R. Commander.
* Copyright (C) 2015-2016, 2018, Matthieu Darbois.
* Copyright (C) 2020, Arm Limited.
*
* Based on the x86 SIMD extension for IJG JPEG library,
* Copyright (C) 1999-2006, MIYASAKA Masaru.
* For conditions of distribution and use, see copyright notice in jsimdext.inc
*
* This file contains stubs for when there is no SIMD support available.
*/
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jsimd.h"
#include "jdct.h"
#include "jsimddct.h"
GLOBAL(int)
jsimd_can_rgb_ycc(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_rgb_gray(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_ycc_rgb(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_ycc_rgb565(void)
{
return 0;
}
GLOBAL(int)
jsimd_c_can_null_convert(void)
{
return 0;
}
GLOBAL(void)
jsimd_rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPIMAGE output_buf, JDIMENSION output_row,
int num_rows)
{
}
GLOBAL(void)
jsimd_rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPIMAGE output_buf, JDIMENSION output_row,
int num_rows)
{
}
GLOBAL(void)
jsimd_ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf,
int num_rows)
{
}
GLOBAL(void)
jsimd_ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION input_row, JSAMPARRAY output_buf,
int num_rows)
{
}
GLOBAL(void)
jsimd_c_null_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPIMAGE output_buf, JDIMENSION output_row,
int num_rows)
{
}
GLOBAL(int)
jsimd_can_h2v2_downsample(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_h2v1_downsample(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_h2v2_smooth_downsample(void)
{
return 0;
}
GLOBAL(void)
jsimd_h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)
{
}
GLOBAL(void)
jsimd_h2v2_smooth_downsample(j_compress_ptr cinfo,
jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)
{
}
GLOBAL(void)
jsimd_h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)
{
}
GLOBAL(int)
jsimd_can_h2v2_upsample(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_h2v1_upsample(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_int_upsample(void)
{
return 0;
}
GLOBAL(void)
jsimd_int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{
}
GLOBAL(void)
jsimd_h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{
}
GLOBAL(void)
jsimd_h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{
}
GLOBAL(int)
jsimd_can_h2v2_fancy_upsample(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_h2v1_fancy_upsample(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_h1v2_fancy_upsample(void)
{
return 0;
}
GLOBAL(void)
jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{
}
GLOBAL(void)
jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{
}
GLOBAL(void)
jsimd_h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
{
}
GLOBAL(int)
jsimd_can_h2v2_merged_upsample(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_h2v1_merged_upsample(void)
{
return 0;
}
GLOBAL(void)
jsimd_h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
{
}
GLOBAL(void)
jsimd_h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
{
}
GLOBAL(int)
jsimd_can_convsamp(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_convsamp_float(void)
{
return 0;
}
GLOBAL(void)
jsimd_convsamp(JSAMPARRAY sample_data, JDIMENSION start_col,
DCTELEM *workspace)
{
}
GLOBAL(void)
jsimd_convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
FAST_FLOAT *workspace)
{
}
GLOBAL(int)
jsimd_can_fdct_islow(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_fdct_ifast(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_fdct_float(void)
{
return 0;
}
GLOBAL(void)
jsimd_fdct_islow(DCTELEM *data)
{
}
GLOBAL(void)
jsimd_fdct_ifast(DCTELEM *data)
{
}
GLOBAL(void)
jsimd_fdct_float(FAST_FLOAT *data)
{
}
GLOBAL(int)
jsimd_can_quantize(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_quantize_float(void)
{
return 0;
}
GLOBAL(void)
jsimd_quantize(JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
{
}
GLOBAL(void)
jsimd_quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
FAST_FLOAT *workspace)
{
}
GLOBAL(int)
jsimd_can_idct_2x2(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_idct_4x4(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_idct_6x6(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_idct_12x12(void)
{
return 0;
}
GLOBAL(void)
jsimd_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
}
GLOBAL(void)
jsimd_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
}
GLOBAL(void)
jsimd_idct_6x6(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
}
GLOBAL(void)
jsimd_idct_12x12(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
}
GLOBAL(int)
jsimd_can_idct_islow(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_idct_ifast(void)
{
return 0;
}
GLOBAL(int)
jsimd_can_idct_float(void)
{
return 0;
}
GLOBAL(void)
jsimd_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
}
GLOBAL(void)
jsimd_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
}
GLOBAL(void)
jsimd_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf,
JDIMENSION output_col)
{
}
GLOBAL(int)
jsimd_can_huff_encode_one_block(void)
{
return 0;
}
GLOBAL(JOCTET *)
jsimd_huff_encode_one_block(void *state, JOCTET *buffer, JCOEFPTR block,
int last_dc_val, c_derived_tbl *dctbl,
c_derived_tbl *actbl)
{
return NULL;
}
GLOBAL(int)
jsimd_can_encode_mcu_AC_first_prepare(void)
{
return 0;
}
GLOBAL(void)
jsimd_encode_mcu_AC_first_prepare(const JCOEF *block,
const int *jpeg_natural_order_start, int Sl,
int Al, JCOEF *values, size_t *zerobits)
{
}
GLOBAL(int)
jsimd_can_encode_mcu_AC_refine_prepare(void)
{
return 0;
}
GLOBAL(int)
jsimd_encode_mcu_AC_refine_prepare(const JCOEF *block,
const int *jpeg_natural_order_start, int Sl,
int Al, JCOEF *absvalues, size_t *bits)
{
return 0;
}

View File

@@ -16,9 +16,12 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "jsamplecomp.h"
#if BITS_IN_JSAMPLE == 8
/*
* jpeg_zigzag_order[i] is the zigzag-order position of the i'th element
* of a DCT block read in natural order (left to right, top to bottom).
@@ -89,19 +92,21 @@ jround_up(long a, long b)
return a - (a % b);
}
#endif /* BITS_IN_JSAMPLE == 8 */
GLOBAL(void)
jcopy_sample_rows(JSAMPARRAY input_array, int source_row,
JSAMPARRAY output_array, int dest_row, int num_rows,
JDIMENSION num_cols)
_jcopy_sample_rows(_JSAMPARRAY input_array, int source_row,
_JSAMPARRAY output_array, int dest_row, int num_rows,
JDIMENSION num_cols)
/* Copy some rows of samples from one place to another.
* num_rows rows are copied from input_array[source_row++]
* to output_array[dest_row++]; these areas may overlap for duplication.
* The source and destination arrays must be at least as wide as num_cols.
*/
{
register JSAMPROW inptr, outptr;
register size_t count = (size_t)(num_cols * sizeof(JSAMPLE));
register _JSAMPROW inptr, outptr;
register size_t count = (size_t)(num_cols * sizeof(_JSAMPLE));
register int row;
input_array += source_row;
@@ -115,6 +120,8 @@ jcopy_sample_rows(JSAMPARRAY input_array, int source_row,
}
#if BITS_IN_JSAMPLE == 8
GLOBAL(void)
jcopy_block_row(JBLOCKROW input_row, JBLOCKROW output_row,
JDIMENSION num_blocks)
@@ -131,3 +138,5 @@ jzero_far(void *target, size_t bytestozero)
{
memset(target, 0, bytestozero);
}
#endif /* BITS_IN_JSAMPLE == 8 */

View File

@@ -1,7 +1,7 @@
LIBJPEGTURBO_@JPEG_LIB_VERSION_DECIMAL@ {
@MEM_SRCDST_FUNCTIONS@
local:
@SIMD_FUNCTIONS@;
jsimd_*;
jconst_*;
};

View File

@@ -12,10 +12,9 @@ This file describes how to use the IJG JPEG library within an application
program. Read it if you want to write a program that uses the library.
The file example.c provides heavily commented code for calling the JPEG
library. Also see jpeglib.h and jpeg12lib.h (the include files to be used by
application programs) for full details about data structures and function
parameter lists. The library source code, of course, is the ultimate
reference.
library. Also see jpeglib.h (the include file to be used by application
programs) for full details about data structures and function parameter lists.
The library source code, of course, is the ultimate reference.
Note that there have been *major* changes from the application interface
presented by IJG version 4 and earlier versions. The old design had several
@@ -113,11 +112,23 @@ used by the free LIBTIFF library to support JPEG compression in TIFF.)
12-bit Data Precision
---------------------
Support for JPEG images with 12-bit, rather than 8-bit, samples is provided
through a separate library, API, and header file (jpeg12lib.h instead of
jpeglib.h and j12error.h instead of jerror.h). Functions supporting 12-bit
samples have a prefix of "jpeg12_" instead of "jpeg_" and use the following
data types, structures, and macros:
The JPEG standard provides for both the baseline 8-bit DCT process and a 12-bit
DCT process. The IJG code supports 12-bit-per-component lossy JPEG if you set
cinfo->data_precision to 12. Note that this causes the sample size to be
larger than a char, so it affects the surrounding application's image data.
The sample applications cjpeg and djpeg can support 12-bit mode only for PPM
and GIF file formats.
Note that, when 12-bit data precision is enabled, the library always compresses
in Huffman optimization mode, in order to generate valid Huffman tables. This
is necessary because our default Huffman tables only cover 8-bit data. If you
need to output 12-bit files in one pass, you'll have to supply suitable default
Huffman tables. You may also want to supply your own DCT quantization tables;
the existing quality-scaling code has been developed for 8-bit use, and
probably doesn't generate especially good tables for 12-bit.
Functions that are specific to 12-bit data precision have a prefix of "jpeg12_"
instead of "jpeg_" and use the following data types and macros:
* J12SAMPLE instead of JSAMPLE
* J12SAMPROW instead of JSAMPROW
@@ -125,25 +136,16 @@ data types, structures, and macros:
* J12SAMPIMAGE instead of JSAMPIMAGE
* MAXJ12SAMPLE instead of MAXJSAMPLE
* CENTERJ12SAMPLE instead of CENTERJSAMPLE
* J12ERREXIT*() instead of ERREXIT*()
* J12WARNMS*() instead of WARNMS*()
* J12TRACEMS*() instead of TRACEMS*()
* jpeg12_common_struct instead of jpeg_common_struct
* j12_common_ptr instead of j_common_ptr
* jpeg12_compress_struct instead of jpeg_compress_struct
* j12_compress_ptr instead of j_compress_ptr
* jpeg12_decompress_struct instead of jpeg_decompress_struct
* j12_decompress_ptr instead of j_decompress_ptr
* jpeg12_error_mgr instead of jpeg_error_mgr
* jpeg12_progress_mgr instead of jpeg_progress_mgr
* jpeg12_destination_mgr instead of jpeg_destination_mgr
* jpeg12_source_mgr instead of jpeg_source_mgr
* jpeg12_memory_mgr instead of jpeg_memory_mgr
* jpeg12_marker_parser_method instead of jpeg_marker_parser_method
This allows both 8-bit and 12-bit precision to be used in a single application.
(Refer to example.c). Arithmetic coding and SIMD acceleration are not
currently implemented for 12-bit samples.
This allows both 8-bit and 12-bit data precision to be used in a single
application. (Refer to example.c). Arithmetic coding and SIMD acceleration
are not currently implemented for 12-bit data precision.
Refer to the descriptions of the data_precision compression and decompression
parameters below for further information.
This documentation uses "J*SAMPLE", "J*SAMPROW", "J*SAMPARRAY", and
"J*SAMPIMAGE" to generically refer to either the 8-bit or 12-bit data types.
Outline of typical usage
@@ -156,7 +158,8 @@ The rough outline of a JPEG compression operation is:
Set parameters for compression, including image size & colorspace
jpeg_start_compress(...);
while (scan lines remain to be written)
jpeg_write_scanlines(...);
jpeg_write_scanlines(...); /* Use jpeg12_write_scanlines() for
12-bit data precision. */
jpeg_finish_compress(...);
Release the JPEG compression object
@@ -168,7 +171,7 @@ same parameter settings for a sequence of images. Re-use of a JPEG object
also has important implications for processing abbreviated JPEG datastreams,
as discussed later.
The image data to be compressed is supplied to jpeg_write_scanlines() from
The image data to be compressed is supplied to jpeg*_write_scanlines() from
in-memory buffers. If the application is doing file-to-file compression,
reading image data from the source file is the application's responsibility.
The library emits compressed data by calling a "data destination manager",
@@ -183,7 +186,8 @@ Similarly, the rough outline of a JPEG decompression operation is:
Set parameters for decompression
jpeg_start_decompress(...);
while (scan lines remain to be read)
jpeg_read_scanlines(...);
jpeg_read_scanlines(...); /* Use jpeg12_read_scanlines() for
12-bit data precision. */
jpeg_finish_decompress(...);
Release the JPEG decompression object
@@ -196,7 +200,7 @@ output scaling ratio that will fit the image into the available screen size.
The decompression library obtains compressed data by calling a data source
manager, which typically will read the data from a file; but other behaviors
can be obtained with a custom source manager. Decompressed data is delivered
into in-memory buffers passed to jpeg_read_scanlines().
into in-memory buffers passed to jpeg*_read_scanlines().
It is possible to abort an incomplete compression or decompression operation
by calling jpeg_abort(); or, if you do not need to retain the JPEG object,
@@ -244,16 +248,16 @@ and the other references mentioned in the README.ijg file.
Pixels are stored by scanlines, with each scanline running from left to
right. The component values for each pixel are adjacent in the row; for
example, R,G,B,R,G,B,R,G,B,... for 24-bit RGB color. Each scanline is an
array of data type JSAMPLE --- which is typically "unsigned char", unless
you've changed jmorecfg.h. (You can also change the RGB pixel layout, say
to B,G,R order, by modifying jmorecfg.h. But see the restrictions listed in
that file before doing so.)
array of data type JSAMPLE or J12SAMPLE --- which is typically "unsigned char"
or "short" (respectively), unless you've changed jmorecfg.h. (You can also
change the RGB pixel layout, say to B,G,R order, by modifying jmorecfg.h. But
see the restrictions listed in that file before doing so.)
A 2-D array of pixels is formed by making a list of pointers to the starts of
scanlines; so the scanlines need not be physically adjacent in memory. Even
if you process just one scanline at a time, you must make a one-element
pointer array to conform to this structure. Pointers to JSAMPLE rows are of
type JSAMPROW, and the pointer to the pointer array is of type JSAMPARRAY.
pointer array to conform to this structure. Pointers to J*SAMPLE rows are of
type J*SAMPROW, and the pointer to the pointer array is of type J*SAMPARRAY.
The library accepts or supplies one or more complete scanlines per call.
It is not possible to process part of a row at a time. Scanlines are always
@@ -262,24 +266,24 @@ have it all in memory, but usually it's simplest to process one scanline at
a time.
For best results, source data values should have the precision specified by
BITS_IN_JSAMPLE (normally 8 bits). For instance, if you choose to compress
data that's only 6 bits/channel, you should left-justify each value in a
byte before passing it to the compressor. If you need to compress data
that has more than 8 bits/channel, compile with BITS_IN_JSAMPLE = 12.
(See "Library compile-time options", later.)
cinfo->data_precision (normally 8 bits). For instance, if you choose to
compress data that's only 6 bits/channel, you should left-justify each value in
a byte before passing it to the compressor. If you need to compress data
that has more than 8 bits/channel, set cinfo->data_precision = 12.
The data format returned by the decompressor is the same in all details,
except that colormapped output is supported. (Again, a JPEG file is never
colormapped. But you can ask the decompressor to perform on-the-fly color
quantization to deliver colormapped output.) If you request colormapped
output then the returned data array contains a single JSAMPLE per pixel;
output then the returned data array contains a single J*SAMPLE per pixel;
its value is an index into a color map. The color map is represented as
a 2-D JSAMPARRAY in which each row holds the values of one color component,
a 2-D J*SAMPARRAY in which each row holds the values of one color component,
that is, colormap[i][j] is the value of the i'th color component for pixel
value (map index) j. Note that since the colormap indexes are stored in
JSAMPLEs, the maximum number of colors is limited by the size of JSAMPLE
(ie, at most 256 colors for an 8-bit JPEG library).
J*SAMPLEs, the maximum number of colors is limited by the size of J*SAMPLE
(ie, at most 256 colors for 8-bit data precision and 4096 colors for 12-bit
data precision).
Compression details
@@ -416,9 +420,10 @@ the compression cycle.
5. while (scan lines remain to be written)
jpeg_write_scanlines(...);
jpeg_write_scanlines(...); /* Use jpeg12_write_scanlines() for 12-bit
data precision. */
Now write all the required image data by calling jpeg_write_scanlines()
Now write all the required image data by calling jpeg*_write_scanlines()
one or more times. You can pass one or more scanlines in each call, up
to the total image height. In most applications it is convenient to pass
just one or a few scanlines at a time. The expected format for the passed
@@ -441,14 +446,18 @@ Code for this step depends heavily on the way that you store the source data.
example.c shows the following code for the case of a full-size 2-D source
array containing 3-byte RGB pixels:
JSAMPROW row_pointer[1]; /* pointer to a single row */
JSAMPROW row_pointer[1]; /* pointer to a single row
Use J12SAMPROW for 12-bit data
precision. */
while (cinfo.next_scanline < cinfo.image_height) {
row_pointer[0] = image_buffer[cinfo.next_scanline];
jpeg_write_scanlines(&cinfo, row_pointer, 1);
/* Use jpeg12_write_scanlines() for
12-bit data precision. */
}
jpeg_write_scanlines() returns the number of scanlines actually written.
jpeg*_write_scanlines() returns the number of scanlines actually written.
This will normally be equal to the number passed in, so you can usually
ignore the return value. It is different in just two cases:
* If you try to write more scanlines than the declared image height,
@@ -673,11 +682,11 @@ colormapped output has been requested. Useful fields include
actual_number_of_colors number of entries in colormap
output_components is 1 (a colormap index) when quantizing colors; otherwise it
equals out_color_components. It is the number of JSAMPLE values that will be
equals out_color_components. It is the number of J*SAMPLE values that will be
emitted per pixel in the output arrays.
Typically you will need to allocate data buffers to hold the incoming image.
You will need output_width * output_components JSAMPLEs per scanline in your
You will need output_width * output_components J*SAMPLEs per scanline in your
output buffer, and a total of output_height scanlines will be returned.
Note: if you are using the JPEG library's internal memory manager to allocate
@@ -689,11 +698,12 @@ relevant parameters (scaling, output color space, and quantization flag).
6. while (scan lines remain to be read)
jpeg_read_scanlines(...);
jpeg_read_scanlines(...); /* Use jpeg12_read_scanlines() for 12-bit
data precision. */
Now you can read the decompressed image data by calling jpeg_read_scanlines()
Now you can read the decompressed image data by calling jpeg*_read_scanlines()
one or more times. At each call, you pass in the maximum number of scanlines
to be read (ie, the height of your working buffer); jpeg_read_scanlines()
to be read (ie, the height of your working buffer); jpeg*_read_scanlines()
will return up to that many lines. The return value is the number of lines
actually read. The format of the returned data is discussed under "Data
formats", above. Don't forget that grayscale and color JPEGs will return
@@ -713,13 +723,13 @@ image_height field is the height of the original unscaled image.)
The return value always equals the change in the value of output_scanline.
If you don't use a suspending data source, it is safe to assume that
jpeg_read_scanlines() reads at least one scanline per call, until the
jpeg*_read_scanlines() reads at least one scanline per call, until the
bottom of the image has been reached.
If you use a buffer larger than one scanline, it is NOT safe to assume that
jpeg_read_scanlines() fills it. (The current implementation returns only a
jpeg*_read_scanlines() fills it. (The current implementation returns only a
few scanlines per call, no matter how large a buffer you pass.) So you must
always provide a loop that calls jpeg_read_scanlines() repeatedly until the
always provide a loop that calls jpeg*_read_scanlines() repeatedly until the
whole image has been read.
@@ -777,33 +787,34 @@ partial image decompression:
1. Skipping rows when decompressing
jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines);
/* Use jpeg12_skip_scanlines() for 12-bit data precision. */
This function provides application programmers with the ability to skip over
multiple rows in the JPEG image.
Suspending data sources are not supported by this function. Calling
jpeg_skip_scanlines() with a suspending data source will result in undefined
jpeg*_skip_scanlines() with a suspending data source will result in undefined
behavior. Two-pass color quantization is also not supported by this function.
Calling jpeg_skip_scanlines() with two-pass color quantization enabled will
Calling jpeg*_skip_scanlines() with two-pass color quantization enabled will
result in an error.
jpeg_skip_scanlines() will not allow skipping past the bottom of the image. If
the value of num_lines is large enough to skip past the bottom of the image,
jpeg*_skip_scanlines() will not allow skipping past the bottom of the image.
If the value of num_lines is large enough to skip past the bottom of the image,
then the function will skip to the end of the image instead.
If the value of num_lines is valid, then jpeg_skip_scanlines() will always
If the value of num_lines is valid, then jpeg*_skip_scanlines() will always
skip all of the input rows requested. There is no need to inspect the return
value of the function in that case.
Best results will be achieved by calling jpeg_skip_scanlines() for large chunks
of rows. The function should be viewed as a way to quickly jump to a
Best results will be achieved by calling jpeg*_skip_scanlines() for large
chunks of rows. The function should be viewed as a way to quickly jump to a
particular vertical offset in the JPEG image in order to decode a subset of the
image. Used in this manner, it will provide significant performance
improvements.
Calling jpeg_skip_scanlines() for small values of num_lines has several
Calling jpeg*_skip_scanlines() for small values of num_lines has several
potential drawbacks:
1) JPEG decompression occurs in blocks, so if jpeg_skip_scanlines() is
1) JPEG decompression occurs in blocks, so if jpeg*_skip_scanlines() is
called from the middle of a decompression block, then it is likely that
much of the decompression work has already been done for the first
couple of rows that need to be skipped.
@@ -811,18 +822,19 @@ potential drawbacks:
such that it is ready to read the next line. This may involve
decompressing a block that must be partially skipped.
These issues are especially tricky for cases in which upsampling requires
context rows. In the worst case, jpeg_skip_scanlines() will perform similarly
to jpeg_read_scanlines() (since it will actually call jpeg_read_scanlines().)
context rows. In the worst case, jpeg*_skip_scanlines() will perform similarly
to jpeg*_read_scanlines() (since it will actually call jpeg*_read_scanlines().)
2. Decompressing partial scanlines
jpeg_crop_scanline (j_decompress_ptr cinfo, JDIMENSION *xoffset,
JDIMENSION *width)
/* Use jpeg12_crop_scanline() for 12-bit data precision. */
This function provides application programmers with the ability to decompress
only a portion of each row in the JPEG image. It must be called after
jpeg_start_decompress() and before any calls to jpeg_read_scanlines() or
jpeg_skip_scanlines().
jpeg_start_decompress() and before any calls to jpeg*_read_scanlines() or
jpeg*_skip_scanlines().
If xoffset and width do not form a valid subset of the image row, then this
function will generate an error. Note that if the output image is scaled, then
@@ -832,12 +844,12 @@ xoffset and width are passed by reference because xoffset must fall on an iMCU
boundary. If it doesn't, then it will be moved left to the nearest iMCU
boundary, and width will be increased accordingly. If the calling program does
not like the adjusted values of xoffset and width, then it can call
jpeg_crop_scanline() again with new values (for instance, if it wants to move
jpeg*_crop_scanline() again with new values (for instance, if it wants to move
xoffset to the nearest iMCU boundary to the right instead of to the left.)
After calling this function, cinfo->output_width will be set to the adjusted
width. This value should be used when allocating an output buffer to pass to
jpeg_read_scanlines().
jpeg*_read_scanlines().
The output image from a partial-width decompression will be identical to the
corresponding image region from a full decode, with one exception: The "fancy"
@@ -989,6 +1001,12 @@ boolean arith_code
If TRUE, use arithmetic coding.
If FALSE, use Huffman coding.
int data_precision
To create a 12-bit-per-component JPEG file, set data_precision to 12
prior to calling jpeg_start_compress() or using the memory manager,
then use jpeg12_write_scanlines() or jpeg12_write_raw_data() instead of
jpeg_write_scanlines() or jpeg_write_raw_data().
J_DCT_METHOD dct_method
Selects the algorithm used for the DCT step. Choices are:
JDCT_ISLOW: accurate integer method
@@ -1209,6 +1227,13 @@ processing.
The following fields in the JPEG object are set by jpeg_read_header() and
may be useful to the application in choosing decompression parameters:
int data_precision Data precision (bits per component)
If data_precision is 12, then use jpeg12_read_scanlines(),
jpeg12_skip_scanlines(), jpeg12_crop_scanline(), and/or
jpeg12_read_raw_data() instead of jpeg_read_scanlines(),
jpeg_skip_scanlines(), jpeg_crop_scanline(), and/or
jpeg_read_raw_data().
JDIMENSION image_width Width and height of image
JDIMENSION image_height
int num_components Number of color components
@@ -1292,6 +1317,9 @@ JSAMPARRAY colormap
CAUTION: if the JPEG library creates its own colormap, the storage
pointed to by this field is released by jpeg_finish_decompress().
Copy the colormap somewhere else first, if you want to save it.
CAUTION: if data_precision is 12, then this is actually a J12SAMPARRAY,
so it must be type-cast in order to read 12-bit samples from or write
12-bit samples to the array.
int actual_number_of_colors
The number of colors in the color map.
@@ -1371,10 +1399,10 @@ int rec_outbuf_height Recommended height of scanline buffer.
When quantizing colors, output_components is 1, indicating a single color map
index per pixel. Otherwise it equals out_color_components. The output arrays
are required to be output_width * output_components JSAMPLEs wide.
are required to be output_width * output_components J*SAMPLEs wide.
rec_outbuf_height is the recommended minimum height (in scanlines) of the
buffer passed to jpeg_read_scanlines(). If the buffer is smaller, the
buffer passed to jpeg*_read_scanlines(). If the buffer is smaller, the
library will still work, but time will be wasted due to unnecessary data
copying. In high-quality modes, rec_outbuf_height is always 1, but some
faster, lower-quality modes set it to larger values (typically 2 to 4).
@@ -1758,10 +1786,10 @@ Compression suspension:
For compression suspension, use an empty_output_buffer() routine that returns
FALSE; typically it will not do anything else. This will cause the
compressor to return to the caller of jpeg_write_scanlines(), with the return
compressor to return to the caller of jpeg*_write_scanlines(), with the return
value indicating that not all the supplied scanlines have been accepted.
The application must make more room in the output buffer, adjust the output
buffer pointer/count appropriately, and then call jpeg_write_scanlines()
buffer pointer/count appropriately, and then call jpeg*_write_scanlines()
again, pointing to the first unconsumed scanline.
When forced to suspend, the compressor will backtrack to a convenient stopping
@@ -1777,7 +1805,7 @@ for efficiency; you don't want the compressor to suspend often. (In fact, an
overly small buffer could lead to infinite looping, if a single MCU required
more data than would fit in the buffer.) We recommend a buffer of at least
several Kbytes. You may want to insert explicit code to ensure that you don't
call jpeg_write_scanlines() unless there is a reasonable amount of space in
call jpeg*_write_scanlines() unless there is a reasonable amount of space in
the output buffer; in other words, flush the buffer before trying to compress
more data.
@@ -1811,11 +1839,11 @@ This will cause the decompressor to return to its caller with an indication
that suspension has occurred. This can happen at four places:
* jpeg_read_header(): will return JPEG_SUSPENDED.
* jpeg_start_decompress(): will return FALSE, rather than its usual TRUE.
* jpeg_read_scanlines(): will return the number of scanlines already
* jpeg*_read_scanlines(): will return the number of scanlines already
completed (possibly 0).
* jpeg_finish_decompress(): will return FALSE, rather than its usual TRUE.
The surrounding application must recognize these cases, load more data into
the input buffer, and repeat the call. In the case of jpeg_read_scanlines(),
the input buffer, and repeat the call. In the case of jpeg*_read_scanlines(),
increment the passed pointers past any scanlines successfully read.
Just as with compression, the decompressor will typically backtrack to a
@@ -1952,7 +1980,7 @@ progressive scan sequence design. (If you want to provide user control of
scan sequences, you may wish to borrow the scan script reading code found
in rdswitch.c, so that you can read scan script files just like cjpeg's.)
When scan_info is not NULL, the compression library will store DCT'd data
into a buffer array as jpeg_write_scanlines() is called, and will emit all
into a buffer array as jpeg*_write_scanlines() is called, and will emit all
the requested scans during jpeg_finish_compress(). This implies that
multiple-scan output cannot be created with a suspending data destination
manager, since jpeg_finish_compress() does not support suspension. We
@@ -2000,7 +2028,8 @@ The basic control flow for buffered-image decoding is
adjust output decompression parameters if required
jpeg_start_output() /* start a new output pass */
for (all scanlines in image) {
jpeg_read_scanlines()
jpeg_read_scanlines() /* Use jpeg12_read_scanlines() for
12-bit data precision. */
display scanlines
}
jpeg_finish_output() /* terminate output pass */
@@ -2030,7 +2059,7 @@ input and output processing run in lockstep.
After reading the final scan and reaching the end of the input file, the
buffered image remains available; it can be read additional times by
repeating the jpeg_start_output()/jpeg_read_scanlines()/jpeg_finish_output()
repeating the jpeg_start_output()/jpeg*_read_scanlines()/jpeg_finish_output()
sequence. For example, a useful technique is to use fast one-pass color
quantization for display passes made while the image is arriving, followed by
a final display pass using two-pass quantization for highest quality. This
@@ -2194,7 +2223,7 @@ buffered-image mode must be prepared for suspension returns from these
routines:
* jpeg_start_output() performs input only if you request 2-pass quantization
and the target scan isn't fully read yet. (This is discussed below.)
* jpeg_read_scanlines(), as always, returns the number of scanlines that it
* jpeg*_read_scanlines(), as always, returns the number of scanlines that it
was able to produce before suspending.
* jpeg_finish_output() will read any markers following the target scan,
up to the end of the file or the SOS marker that begins another scan.
@@ -2553,7 +2582,7 @@ Adobe markers and will set the JPEG colorspace properly when one is found.
You can write special markers immediately following the datastream header by
calling jpeg_write_marker() after jpeg_start_compress() and before the first
call to jpeg_write_scanlines(). When you do this, the markers appear after
call to jpeg*_write_scanlines(). When you do this, the markers appear after
the SOI and the JFIF APP0 and Adobe APP14 markers (if written), but before
all else. Specify the marker type parameter as "JPEG_COM" for COM or
"JPEG_APP0 + n" for APPn. (Actually, jpeg_write_marker will let you write
@@ -2695,9 +2724,9 @@ JPEG file while writing it, or to extract the profile data from a JPEG file
while reading it.
jpeg_write_icc_profile() must be called after calling jpeg_start_compress() and
before the first call to jpeg_write_scanlines() or jpeg_write_raw_data(). This
ordering ensures that the APP2 marker(s) will appear after the SOI and JFIF or
Adobe markers, but before all other data.
before the first call to jpeg*_write_scanlines() or jpeg*_write_raw_data().
This ordering ensures that the APP2 marker(s) will appear after the SOI and
JFIF or Adobe markers, but before all other data.
jpeg_read_icc_profile() returns TRUE if an ICC profile was found and FALSE
otherwise. If an ICC profile was found, then the function will allocate a
@@ -2733,8 +2762,8 @@ To compress raw data, you must supply the data in the colorspace to be used
in the JPEG file (please read the earlier section on Special color spaces)
and downsampled to the sampling factors specified in the JPEG parameters.
You must supply the data in the format used internally by the JPEG library,
namely a JSAMPIMAGE array. This is an array of pointers to two-dimensional
arrays, each of type JSAMPARRAY. Each 2-D array holds the values for one
namely a J*SAMPIMAGE array. This is an array of pointers to two-dimensional
arrays, each of type J*SAMPARRAY. Each 2-D array holds the values for one
color component. This structure is necessary since the components are of
different sizes. If the image dimensions are not a multiple of the MCU size,
you must also pad the data correctly (usually, this is done by replicating
@@ -2746,8 +2775,9 @@ images, the standard image size is usually a multiple of the DCT block size,
so that no padding need actually be done.)
The procedure for compression of raw data is basically the same as normal
compression, except that you call jpeg_write_raw_data() in place of
jpeg_write_scanlines(). Before calling jpeg_start_compress(), you must do
compression, except that you call jpeg_write_raw_data() or
jpeg12_write_raw_data() in place of jpeg_write_scanlines() or
jpeg12_write_scanlines(). Before calling jpeg_start_compress(), you must do
the following:
* Set cinfo->raw_data_in to TRUE. (It is set FALSE by jpeg_set_defaults().)
This notifies the library that you will be supplying raw data.
@@ -2760,13 +2790,13 @@ the following:
dimensions of the data you are supplying, it's wise to set them
explicitly, rather than assuming the library's defaults are what you want.
To pass raw data to the library, call jpeg_write_raw_data() in place of
jpeg_write_scanlines(). The two routines work similarly except that
jpeg_write_raw_data takes a JSAMPIMAGE data array rather than JSAMPARRAY.
The scanlines count passed to and returned from jpeg_write_raw_data is
To pass raw data to the library, call jpeg*_write_raw_data() in place of
jpeg*_write_scanlines(). The routines work similarly except that
jpeg*_write_raw_data takes a J*SAMPIMAGE data array rather than J*SAMPARRAY.
The scanlines count passed to and returned from jpeg*_write_raw_data is
measured in terms of the component with the largest v_samp_factor.
jpeg_write_raw_data() processes one MCU row per call, which is to say
jpeg*_write_raw_data() processes one MCU row per call, which is to say
v_samp_factor*DCTSIZE sample rows of each component. The passed num_lines
value must be at least max_v_samp_factor*DCTSIZE, and the return value will
be exactly that amount (or possibly some multiple of that amount, in future
@@ -2797,7 +2827,7 @@ downsampled_width = 51 and width_in_blocks = 7 for Cb and Cr (and the same
for the height fields). You must pad the Y data to at least 13*8 = 104
columns and rows, the Cb/Cr data to at least 7*8 = 56 columns and rows. The
MCU height is max_v_samp_factor = 2 DCT rows so you must pass at least 16
scanlines on each call to jpeg_write_raw_data(), which is to say 16 actual
scanlines on each call to jpeg*_write_raw_data(), which is to say 16 actual
sample rows of Y and 8 each of Cb and Cr. A total of 7 MCU rows are needed,
so you must pass a total of 7*16 = 112 "scanlines". The last DCT block row
of Y data is dummy, so it doesn't matter what you pass for it in the data
@@ -2805,7 +2835,7 @@ arrays, but the scanlines count must total up to 112 so that all of the Cb
and Cr data gets passed.
Output suspension is supported with raw-data compression: if the data
destination module suspends, jpeg_write_raw_data() will return 0.
destination module suspends, jpeg*_write_raw_data() will return 0.
In this case the same data rows must be passed again on the next call.
@@ -2819,10 +2849,11 @@ The library will not convert to a different color space for you.
To obtain raw data output, set cinfo->raw_data_out = TRUE before
jpeg_start_decompress() (it is set FALSE by jpeg_read_header()). Be sure to
verify that the color space and sampling factors are ones you can handle.
Then call jpeg_read_raw_data() in place of jpeg_read_scanlines(). The
decompression process is otherwise the same as usual.
Then call jpeg_read_raw_data() or jpeg12_read_raw_data() in place of
jpeg_read_scanlines() or jpeg12_read_scanlines(). The decompression process is
otherwise the same as usual.
jpeg_read_raw_data() returns one MCU row per call, and thus you must pass a
jpeg*_read_raw_data() returns one MCU row per call, and thus you must pass a
buffer of at least max_v_samp_factor*DCTSIZE scanlines (scanline counting is
the same as for raw-data compression). The buffer you pass must be large
enough to hold the actual data plus padding to DCT-block boundaries. As with
@@ -2832,7 +2863,7 @@ above example of computing buffer dimensions for raw-data compression is
equally valid for decompression.
Input suspension is supported with raw-data decompression: if the data source
module suspends, jpeg_read_raw_data() will return 0. You can also use
module suspends, jpeg*_read_raw_data() will return 0. You can also use
buffered-image mode to read raw data in multiple passes.
@@ -2847,7 +2878,7 @@ multi-strip or multi-tile TIFF/JPEG file into a single JPEG datastream, etc.
To read the contents of a JPEG file as DCT coefficients, open the file and do
jpeg_read_header() as usual. But instead of calling jpeg_start_decompress()
and jpeg_read_scanlines(), call jpeg_read_coefficients(). This will read the
and jpeg*_read_scanlines(), call jpeg_read_coefficients(). This will read the
entire image into a set of virtual coefficient-block arrays, one array per
component. The return value is a pointer to an array of virtual-array
descriptors. Each virtual array can be accessed directly using the JPEG
@@ -2888,7 +2919,7 @@ the DCT coefficients stored in virtual block arrays. You can either pass
block arrays read from an input JPEG file by jpeg_read_coefficients(), or
allocate virtual arrays from the JPEG compression object and fill them
yourself. In either case, jpeg_write_coefficients() is substituted for
jpeg_start_compress() and jpeg_write_scanlines(). Thus the sequence is
jpeg_start_compress() and jpeg*_write_scanlines(). Thus the sequence is
* Create compression object
* Set all compression parameters as necessary
* Request virtual arrays if needed
@@ -2932,7 +2963,7 @@ Some applications may need to regain control from the JPEG library every so
often. The typical use of this feature is to produce a percent-done bar or
other progress display. (For a simple example, see cjpeg.c or djpeg.c.)
Although you do get control back frequently during the data-transferring pass
(the jpeg_read_scanlines or jpeg_write_scanlines loop), any additional passes
(the jpeg*_read_scanlines or jpeg*_write_scanlines loop), any additional passes
will occur inside jpeg_finish_compress or jpeg_start_decompress; those
routines may take a long time to execute, and you don't get control back
until they are done.
@@ -2943,8 +2974,8 @@ so we don't recommend you use it for mouse tracking or anything like that.
At present, a call will occur once per MCU row, scanline, or sample row
group, whichever unit is convenient for the current processing mode; so the
wider the image, the longer the time between calls. During the data
transferring pass, only one call occurs per call of jpeg_read_scanlines or
jpeg_write_scanlines, so don't pass a large number of scanlines at once if
transferring pass, only one call occurs per call of jpeg*_read_scanlines or
jpeg*_write_scanlines, so don't pass a large number of scanlines at once if
you want fine resolution in the progress count. (If you really need to use
the callback mechanism for time-critical tasks like mouse tracking, you could
insert additional calls inside some of the library's inner loops.)
@@ -3091,22 +3122,6 @@ Library compile-time options
A number of compile-time options are available by modifying jmorecfg.h.
The JPEG standard provides for both the baseline 8-bit DCT process and
a 12-bit DCT process. The IJG code supports 12-bit lossy JPEG if you define
BITS_IN_JSAMPLE as 12 rather than 8. Note that this causes JSAMPLE to be
larger than a char, so it affects the surrounding application's image data.
The sample applications cjpeg and djpeg can support 12-bit mode only for PPM
and GIF file formats; you must disable the other file formats to compile a
12-bit cjpeg or djpeg.
Note that a 12-bit library always compresses in Huffman optimization mode,
in order to generate valid Huffman tables. This is necessary because our
default Huffman tables only cover 8-bit data. If you need to output 12-bit
files in one pass, you'll have to supply suitable default Huffman tables.
You may also want to supply your own DCT quantization tables; the existing
quality-scaling code has been developed for 8-bit use, and probably doesn't
generate especially good tables for 12-bit.
The maximum number of components (color channels) in the image is determined
by MAX_COMPONENTS. The JPEG standard allows up to 255 components, but we
expect that few applications will need more than four or so.
@@ -3116,7 +3131,7 @@ performance or reduce memory space by tweaking the various typedefs in
jmorecfg.h. In particular, on some RISC CPUs, access to arrays of "short"s
is quite slow; consider trading memory for speed by making JCOEF, INT16, and
UINT16 be "int" or "unsigned int". UINT8 is also a candidate to become int.
You probably don't want to make JSAMPLE be int unless you have lots of memory
You probably don't want to make J*SAMPLE be int unless you have lots of memory
to burn.
You can reduce the size of the library by compiling out various optional

View File

@@ -670,6 +670,9 @@ jinit_read_bmp(j_compress_ptr cinfo, boolean use_inversion_array)
{
bmp_source_ptr source;
if (cinfo->data_precision != 8)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Create module interface object */
source = (bmp_source_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,

View File

@@ -1,8 +1,10 @@
/*
* rdcolmap.c
*
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1996, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software.
* libjpeg-turbo Modifications:
* Copyright (C) 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -18,11 +20,12 @@
* of each desired color. Such a file can be extracted from an
* ordinary image PPM file with ppmtomap(1).
*
* Rescaling a PPM that has a maxval unequal to MAXJSAMPLE is not
* Rescaling a PPM that has a maxval unequal to _MAXJSAMPLE is not
* currently implemented.
*/
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include "jsamplecomp.h"
#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */
@@ -46,9 +49,9 @@
LOCAL(void)
add_map_entry(j_decompress_ptr cinfo, int R, int G, int B)
{
JSAMPROW colormap0 = cinfo->colormap[0];
JSAMPROW colormap1 = cinfo->colormap[1];
JSAMPROW colormap2 = cinfo->colormap[2];
_JSAMPROW colormap0 = ((_JSAMPARRAY)cinfo->colormap)[0];
_JSAMPROW colormap1 = ((_JSAMPARRAY)cinfo->colormap)[1];
_JSAMPROW colormap2 = ((_JSAMPARRAY)cinfo->colormap)[2];
int ncolors = cinfo->actual_number_of_colors;
int index;
@@ -60,13 +63,13 @@ add_map_entry(j_decompress_ptr cinfo, int R, int G, int B)
}
/* Check for map overflow. */
if (ncolors >= (MAXJSAMPLE + 1))
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, (MAXJSAMPLE + 1));
if (ncolors >= (_MAXJSAMPLE + 1))
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, (_MAXJSAMPLE + 1));
/* OK, add color to map. */
colormap0[ncolors] = (JSAMPLE)R;
colormap1[ncolors] = (JSAMPLE)G;
colormap2[ncolors] = (JSAMPLE)B;
colormap0[ncolors] = (_JSAMPLE)R;
colormap1[ncolors] = (_JSAMPLE)G;
colormap2[ncolors] = (_JSAMPLE)B;
cinfo->actual_number_of_colors++;
}
@@ -186,7 +189,7 @@ read_ppm_map(j_decompress_ptr cinfo, FILE *infile)
ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
/* For now, we don't support rescaling from an unusual maxval. */
if (maxval != (unsigned int)MAXJSAMPLE)
if (maxval != (unsigned int)_MAXJSAMPLE)
ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
switch (c) {
@@ -228,12 +231,15 @@ read_ppm_map(j_decompress_ptr cinfo, FILE *infile)
*/
GLOBAL(void)
read_color_map(j_decompress_ptr cinfo, FILE *infile)
_read_color_map(j_decompress_ptr cinfo, FILE *infile)
{
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Allocate space for a color map of maximum supported size. */
cinfo->colormap = (*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE,
(JDIMENSION)(MAXJSAMPLE + 1), (JDIMENSION)3);
(JDIMENSION)(_MAXJSAMPLE + 1), (JDIMENSION)3);
cinfo->actual_number_of_colors = 0; /* initialize map to empty */
/* Read first byte to determine file format */

42
rdgif.c
View File

@@ -34,6 +34,7 @@
*/
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include "jsamplecomp.h"
#ifdef GIF_SUPPORTED
@@ -89,7 +90,7 @@ typedef struct {
j_compress_ptr cinfo; /* back link saves passing separate parm */
JSAMPARRAY colormap; /* GIF colormap (converted to my format) */
_JSAMPARRAY colormap; /* GIF colormap (converted to my format) */
/* State for GetCode and LZWReadByte */
U_CHAR code_buf[256 + 4]; /* current input data block */
@@ -342,7 +343,7 @@ LZWReadByte(gif_source_ptr sinfo)
LOCAL(void)
ReadColorMap(gif_source_ptr sinfo, int cmaplen, JSAMPARRAY cmap)
ReadColorMap(gif_source_ptr sinfo, int cmaplen, _JSAMPARRAY cmap)
/* Read a GIF colormap */
{
int i, gray = 1;
@@ -353,9 +354,9 @@ ReadColorMap(gif_source_ptr sinfo, int cmaplen, JSAMPARRAY cmap)
#else
#define UPSCALE(x) ((x) << (BITS_IN_JSAMPLE - 8))
#endif
cmap[CM_RED][i] = (JSAMPLE)UPSCALE(ReadByte(sinfo));
cmap[CM_GREEN][i] = (JSAMPLE)UPSCALE(ReadByte(sinfo));
cmap[CM_BLUE][i] = (JSAMPLE)UPSCALE(ReadByte(sinfo));
cmap[CM_RED][i] = (_JSAMPLE)UPSCALE(ReadByte(sinfo));
cmap[CM_GREEN][i] = (_JSAMPLE)UPSCALE(ReadByte(sinfo));
cmap[CM_BLUE][i] = (_JSAMPLE)UPSCALE(ReadByte(sinfo));
if (cmap[CM_RED][i] != cmap[CM_GREEN][i] ||
cmap[CM_GREEN][i] != cmap[CM_BLUE][i])
gray = 0;
@@ -427,7 +428,7 @@ start_input_gif(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
TRACEMS(cinfo, 1, JTRC_GIF_NONSQUARE);
/* Allocate space to store the colormap */
source->colormap = (*cinfo->mem->alloc_sarray)
source->colormap = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE, (JDIMENSION)MAXCOLORMAPSIZE,
(JDIMENSION)NUMCOLORS);
colormaplen = 0; /* indicate initialization */
@@ -530,7 +531,7 @@ start_input_gif(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
}
/* Create compressor input buffer. */
source->pub.buffer = (*cinfo->mem->alloc_sarray)
source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE,
(JDIMENSION)width * cinfo->input_components, (JDIMENSION)1);
source->pub.buffer_height = 1;
@@ -539,7 +540,7 @@ start_input_gif(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
for (c = colormaplen; c < source->clear_code; c++) {
source->colormap[CM_RED][c] =
source->colormap[CM_GREEN][c] =
source->colormap[CM_BLUE][c] = CENTERJSAMPLE;
source->colormap[CM_BLUE][c] = _CENTERJSAMPLE;
}
/* Return info about the image. */
@@ -562,11 +563,11 @@ get_pixel_rows(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
{
gif_source_ptr source = (gif_source_ptr)sinfo;
register int c;
register JSAMPROW ptr;
register _JSAMPROW ptr;
register JDIMENSION col;
register JSAMPARRAY colormap = source->colormap;
register _JSAMPARRAY colormap = source->colormap;
ptr = source->pub.buffer[0];
ptr = source->pub._buffer[0];
if (cinfo->in_color_space == JCS_GRAYSCALE) {
for (col = cinfo->image_width; col > 0; col--) {
c = LZWReadByte(source);
@@ -594,7 +595,7 @@ METHODDEF(JDIMENSION)
load_interlaced_image(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
{
gif_source_ptr source = (gif_source_ptr)sinfo;
register JSAMPROW sptr;
register _JSAMPROW sptr;
register JDIMENSION col;
JDIMENSION row;
cd_progress_ptr progress = (cd_progress_ptr)cinfo->progress;
@@ -606,11 +607,11 @@ load_interlaced_image(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
progress->pub.pass_limit = (long)cinfo->image_height;
(*progress->pub.progress_monitor) ((j_common_ptr)cinfo);
}
sptr = *(*cinfo->mem->access_virt_sarray)
sptr = *(_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
((j_common_ptr)cinfo, source->interlaced_image, row, (JDIMENSION)1,
TRUE);
for (col = cinfo->image_width; col > 0; col--) {
*sptr++ = (JSAMPLE)LZWReadByte(source);
*sptr++ = (_JSAMPLE)LZWReadByte(source);
}
}
if (progress != NULL)
@@ -639,9 +640,9 @@ get_interlaced_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
{
gif_source_ptr source = (gif_source_ptr)sinfo;
register int c;
register JSAMPROW sptr, ptr;
register _JSAMPROW sptr, ptr;
register JDIMENSION col;
register JSAMPARRAY colormap = source->colormap;
register _JSAMPARRAY colormap = source->colormap;
JDIMENSION irow;
/* Figure out which row of interlaced image is needed, and access it. */
@@ -659,11 +660,11 @@ get_interlaced_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
default: /* fourth-pass row */
irow = (source->cur_row_number >> 1) + source->pass4_offset;
}
sptr = *(*cinfo->mem->access_virt_sarray)
sptr = *(_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
((j_common_ptr)cinfo, source->interlaced_image, irow, (JDIMENSION)1,
FALSE);
/* Scan the row, expand colormap, and output */
ptr = source->pub.buffer[0];
ptr = source->pub._buffer[0];
if (cinfo->in_color_space == JCS_GRAYSCALE) {
for (col = cinfo->image_width; col > 0; col--) {
c = *sptr++;
@@ -698,10 +699,13 @@ finish_input_gif(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
*/
GLOBAL(cjpeg_source_ptr)
jinit_read_gif(j_compress_ptr cinfo)
_jinit_read_gif(j_compress_ptr cinfo)
{
gif_source_ptr source;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Create module interface object */
source = (gif_source_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,

165
rdppm.c
View File

@@ -62,9 +62,9 @@ typedef struct {
/* Usually these two pointers point to the same place: */
U_CHAR *iobuffer; /* fread's I/O buffer */
JSAMPROW pixrow; /* compressor input buffer */
_JSAMPROW pixrow; /* compressor input buffer */
size_t buffer_width; /* width of I/O buffer */
JSAMPLE *rescale; /* => maxval-remapping array, or NULL */
_JSAMPLE *rescale; /* => maxval-remapping array, or NULL */
unsigned int maxval;
} ppm_source_struct;
@@ -124,10 +124,10 @@ read_pbm_integer(j_compress_ptr cinfo, FILE *infile, unsigned int maxval)
* Read one row of pixels.
*
* We provide several different versions depending on input file format.
* In all cases, input is scaled to the size of JSAMPLE.
* In all cases, input is scaled to the size of _JSAMPLE.
*
* A really fast path is provided for reading byte/sample raw files with
* maxval = MAXJSAMPLE, which is the normal case for 8-bit data.
* maxval = _MAXJSAMPLE, which is the normal case for 8-bit data.
*/
@@ -137,12 +137,12 @@ get_text_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
{
ppm_source_ptr source = (ppm_source_ptr)sinfo;
FILE *infile = source->pub.input_file;
register JSAMPROW ptr;
register JSAMPLE *rescale = source->rescale;
register _JSAMPROW ptr;
register _JSAMPLE *rescale = source->rescale;
JDIMENSION col;
unsigned int maxval = source->maxval;
ptr = source->pub.buffer[0];
ptr = source->pub._buffer[0];
for (col = cinfo->image_width; col > 0; col--) {
*ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
}
@@ -165,8 +165,8 @@ get_text_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
{
ppm_source_ptr source = (ppm_source_ptr)sinfo;
FILE *infile = source->pub.input_file;
register JSAMPROW ptr;
register JSAMPLE *rescale = source->rescale;
register _JSAMPROW ptr;
register _JSAMPLE *rescale = source->rescale;
JDIMENSION col;
unsigned int maxval = source->maxval;
register int rindex = rgb_red[cinfo->in_color_space];
@@ -175,13 +175,13 @@ get_text_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
register int aindex = alpha_index[cinfo->in_color_space];
register int ps = rgb_pixelsize[cinfo->in_color_space];
ptr = source->pub.buffer[0];
if (maxval == MAXJSAMPLE) {
ptr = source->pub._buffer[0];
if (maxval == _MAXJSAMPLE) {
if (aindex >= 0)
GRAY_RGB_READ_LOOP((JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
ptr[aindex] = 0xFF;)
else
GRAY_RGB_READ_LOOP((JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
} else {
if (aindex >= 0)
GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
@@ -200,21 +200,21 @@ get_text_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
{
ppm_source_ptr source = (ppm_source_ptr)sinfo;
FILE *infile = source->pub.input_file;
register JSAMPROW ptr;
register JSAMPLE *rescale = source->rescale;
register _JSAMPROW ptr;
register _JSAMPLE *rescale = source->rescale;
JDIMENSION col;
unsigned int maxval = source->maxval;
ptr = source->pub.buffer[0];
if (maxval == MAXJSAMPLE) {
ptr = source->pub._buffer[0];
if (maxval == _MAXJSAMPLE) {
for (col = cinfo->image_width; col > 0; col--) {
JSAMPLE gray = (JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
_JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
} else {
for (col = cinfo->image_width; col > 0; col--) {
JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
_JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
@@ -239,8 +239,8 @@ get_text_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
{
ppm_source_ptr source = (ppm_source_ptr)sinfo;
FILE *infile = source->pub.input_file;
register JSAMPROW ptr;
register JSAMPLE *rescale = source->rescale;
register _JSAMPROW ptr;
register _JSAMPLE *rescale = source->rescale;
JDIMENSION col;
unsigned int maxval = source->maxval;
register int rindex = rgb_red[cinfo->in_color_space];
@@ -249,13 +249,13 @@ get_text_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
register int aindex = alpha_index[cinfo->in_color_space];
register int ps = rgb_pixelsize[cinfo->in_color_space];
ptr = source->pub.buffer[0];
if (maxval == MAXJSAMPLE) {
ptr = source->pub._buffer[0];
if (maxval == _MAXJSAMPLE) {
if (aindex >= 0)
RGB_READ_LOOP((JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
ptr[aindex] = 0xFF;)
else
RGB_READ_LOOP((JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
} else {
if (aindex >= 0)
RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
@@ -274,25 +274,25 @@ get_text_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
{
ppm_source_ptr source = (ppm_source_ptr)sinfo;
FILE *infile = source->pub.input_file;
register JSAMPROW ptr;
register JSAMPLE *rescale = source->rescale;
register _JSAMPROW ptr;
register _JSAMPLE *rescale = source->rescale;
JDIMENSION col;
unsigned int maxval = source->maxval;
ptr = source->pub.buffer[0];
if (maxval == MAXJSAMPLE) {
ptr = source->pub._buffer[0];
if (maxval == _MAXJSAMPLE) {
for (col = cinfo->image_width; col > 0; col--) {
JSAMPLE r = (JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
JSAMPLE g = (JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
JSAMPLE b = (JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
_JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
_JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
_JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
} else {
for (col = cinfo->image_width; col > 0; col--) {
JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
_JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
_JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
_JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
@@ -306,14 +306,14 @@ get_scaled_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* This version is for reading raw-byte-format PGM files with any maxval */
{
ppm_source_ptr source = (ppm_source_ptr)sinfo;
register JSAMPROW ptr;
register _JSAMPROW ptr;
register U_CHAR *bufferptr;
register JSAMPLE *rescale = source->rescale;
register _JSAMPLE *rescale = source->rescale;
JDIMENSION col;
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
ERREXIT(cinfo, JERR_INPUT_EOF);
ptr = source->pub.buffer[0];
ptr = source->pub._buffer[0];
bufferptr = source->iobuffer;
for (col = cinfo->image_width; col > 0; col--) {
*ptr++ = rescale[UCH(*bufferptr++)];
@@ -328,9 +328,9 @@ get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
and converting to extended RGB */
{
ppm_source_ptr source = (ppm_source_ptr)sinfo;
register JSAMPROW ptr;
register _JSAMPROW ptr;
register U_CHAR *bufferptr;
register JSAMPLE *rescale = source->rescale;
register _JSAMPLE *rescale = source->rescale;
JDIMENSION col;
unsigned int maxval = source->maxval;
register int rindex = rgb_red[cinfo->in_color_space];
@@ -341,9 +341,9 @@ get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
ERREXIT(cinfo, JERR_INPUT_EOF);
ptr = source->pub.buffer[0];
ptr = source->pub._buffer[0];
bufferptr = source->iobuffer;
if (maxval == MAXJSAMPLE) {
if (maxval == _MAXJSAMPLE) {
if (aindex >= 0)
GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = 0xFF;)
else
@@ -364,25 +364,25 @@ get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
and converting to CMYK */
{
ppm_source_ptr source = (ppm_source_ptr)sinfo;
register JSAMPROW ptr;
register _JSAMPROW ptr;
register U_CHAR *bufferptr;
register JSAMPLE *rescale = source->rescale;
register _JSAMPLE *rescale = source->rescale;
JDIMENSION col;
unsigned int maxval = source->maxval;
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
ERREXIT(cinfo, JERR_INPUT_EOF);
ptr = source->pub.buffer[0];
ptr = source->pub._buffer[0];
bufferptr = source->iobuffer;
if (maxval == MAXJSAMPLE) {
if (maxval == _MAXJSAMPLE) {
for (col = cinfo->image_width; col > 0; col--) {
JSAMPLE gray = *bufferptr++;
_JSAMPLE gray = *bufferptr++;
rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
} else {
for (col = cinfo->image_width; col > 0; col--) {
JSAMPLE gray = rescale[UCH(*bufferptr++)];
_JSAMPLE gray = rescale[UCH(*bufferptr++)];
rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
@@ -396,9 +396,9 @@ get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* This version is for reading raw-byte-format PPM files with any maxval */
{
ppm_source_ptr source = (ppm_source_ptr)sinfo;
register JSAMPROW ptr;
register _JSAMPROW ptr;
register U_CHAR *bufferptr;
register JSAMPLE *rescale = source->rescale;
register _JSAMPLE *rescale = source->rescale;
JDIMENSION col;
unsigned int maxval = source->maxval;
register int rindex = rgb_red[cinfo->in_color_space];
@@ -409,9 +409,9 @@ get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
ERREXIT(cinfo, JERR_INPUT_EOF);
ptr = source->pub.buffer[0];
ptr = source->pub._buffer[0];
bufferptr = source->iobuffer;
if (maxval == MAXJSAMPLE) {
if (maxval == _MAXJSAMPLE) {
if (aindex >= 0)
RGB_READ_LOOP(*bufferptr++, ptr[aindex] = 0xFF;)
else
@@ -432,29 +432,29 @@ get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
converting to CMYK */
{
ppm_source_ptr source = (ppm_source_ptr)sinfo;
register JSAMPROW ptr;
register _JSAMPROW ptr;
register U_CHAR *bufferptr;
register JSAMPLE *rescale = source->rescale;
register _JSAMPLE *rescale = source->rescale;
JDIMENSION col;
unsigned int maxval = source->maxval;
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
ERREXIT(cinfo, JERR_INPUT_EOF);
ptr = source->pub.buffer[0];
ptr = source->pub._buffer[0];
bufferptr = source->iobuffer;
if (maxval == MAXJSAMPLE) {
if (maxval == _MAXJSAMPLE) {
for (col = cinfo->image_width; col > 0; col--) {
JSAMPLE r = *bufferptr++;
JSAMPLE g = *bufferptr++;
JSAMPLE b = *bufferptr++;
_JSAMPLE r = *bufferptr++;
_JSAMPLE g = *bufferptr++;
_JSAMPLE b = *bufferptr++;
rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
} else {
for (col = cinfo->image_width; col > 0; col--) {
JSAMPLE r = rescale[UCH(*bufferptr++)];
JSAMPLE g = rescale[UCH(*bufferptr++)];
JSAMPLE b = rescale[UCH(*bufferptr++)];
_JSAMPLE r = rescale[UCH(*bufferptr++)];
_JSAMPLE g = rescale[UCH(*bufferptr++)];
_JSAMPLE b = rescale[UCH(*bufferptr++)];
rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
@@ -465,8 +465,8 @@ get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
METHODDEF(JDIMENSION)
get_raw_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* This version is for reading raw-byte-format files with maxval = MAXJSAMPLE.
* In this case we just read right into the JSAMPLE buffer!
/* This version is for reading raw-byte-format files with maxval = _MAXJSAMPLE.
* In this case we just read right into the _JSAMPLE buffer!
* Note that same code works for PPM and PGM files.
*/
{
@@ -483,15 +483,15 @@ get_word_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* This version is for reading raw-word-format PGM files with any maxval */
{
ppm_source_ptr source = (ppm_source_ptr)sinfo;
register JSAMPROW ptr;
register _JSAMPROW ptr;
register U_CHAR *bufferptr;
register JSAMPLE *rescale = source->rescale;
register _JSAMPLE *rescale = source->rescale;
JDIMENSION col;
unsigned int maxval = source->maxval;
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
ERREXIT(cinfo, JERR_INPUT_EOF);
ptr = source->pub.buffer[0];
ptr = source->pub._buffer[0];
bufferptr = source->iobuffer;
for (col = cinfo->image_width; col > 0; col--) {
register unsigned int temp;
@@ -510,9 +510,9 @@ get_word_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* This version is for reading raw-word-format PPM files with any maxval */
{
ppm_source_ptr source = (ppm_source_ptr)sinfo;
register JSAMPROW ptr;
register _JSAMPROW ptr;
register U_CHAR *bufferptr;
register JSAMPLE *rescale = source->rescale;
register _JSAMPLE *rescale = source->rescale;
JDIMENSION col;
unsigned int maxval = source->maxval;
register int rindex = rgb_red[cinfo->in_color_space];
@@ -523,7 +523,7 @@ get_word_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
ERREXIT(cinfo, JERR_INPUT_EOF);
ptr = source->pub.buffer[0];
ptr = source->pub._buffer[0];
bufferptr = source->iobuffer;
for (col = cinfo->image_width; col > 0; col--) {
register unsigned int temp;
@@ -641,7 +641,7 @@ start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
source->pub.get_pixel_rows = get_word_gray_row;
else
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
} else if (maxval == MAXJSAMPLE && sizeof(JSAMPLE) == sizeof(U_CHAR) &&
} else if (maxval == _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
cinfo->in_color_space == JCS_GRAYSCALE) {
source->pub.get_pixel_rows = get_raw_row;
use_raw_buffer = TRUE;
@@ -667,7 +667,7 @@ start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
source->pub.get_pixel_rows = get_word_rgb_row;
else
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
} else if (maxval == MAXJSAMPLE && sizeof(JSAMPLE) == sizeof(U_CHAR) &&
} else if (maxval == _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
(cinfo->in_color_space == JCS_EXT_RGB ||
cinfo->in_color_space == JCS_RGB)) {
@@ -711,13 +711,13 @@ start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* Create compressor input buffer. */
if (use_raw_buffer) {
/* For unscaled raw-input case, we can just map it onto the I/O buffer. */
/* Synthesize a JSAMPARRAY pointer structure */
source->pixrow = (JSAMPROW)source->iobuffer;
source->pub.buffer = &source->pixrow;
/* Synthesize a _JSAMPARRAY pointer structure */
source->pixrow = (_JSAMPROW)source->iobuffer;
source->pub._buffer = &source->pixrow;
source->pub.buffer_height = 1;
} else {
/* Need to translate anyway, so make a separate sample buffer. */
source->pub.buffer = (*cinfo->mem->alloc_sarray)
source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
((j_common_ptr)cinfo, JPOOL_IMAGE,
(JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
source->pub.buffer_height = 1;
@@ -728,16 +728,16 @@ start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
long val, half_maxval;
/* On 16-bit-int machines we have to be careful of maxval = 65535 */
source->rescale = (JSAMPLE *)
source->rescale = (_JSAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(size_t)(((long)MAX(maxval, 255) + 1L) *
sizeof(JSAMPLE)));
sizeof(_JSAMPLE)));
memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
sizeof(JSAMPLE)));
sizeof(_JSAMPLE)));
half_maxval = maxval / 2;
for (val = 0; val <= (long)maxval; val++) {
/* The multiplication here must be done in 32 bits to avoid overflow */
source->rescale[val] = (JSAMPLE)((val * MAXJSAMPLE + half_maxval) /
source->rescale[val] = (_JSAMPLE)((val * _MAXJSAMPLE + half_maxval) /
maxval);
}
}
@@ -760,10 +760,13 @@ finish_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
*/
GLOBAL(cjpeg_source_ptr)
jinit_read_ppm(j_compress_ptr cinfo)
_jinit_read_ppm(j_compress_ptr cinfo)
{
ppm_source_ptr source;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Create module interface object */
source = (ppm_source_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,

View File

@@ -490,6 +490,9 @@ jinit_read_targa(j_compress_ptr cinfo)
{
tga_source_ptr source;
if (cinfo->data_precision != 8)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Create module interface object */
source = (tga_source_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,

View File

@@ -47,23 +47,12 @@ Section "@CMAKE_PROJECT_NAME@ SDK for @INST_PLATFORM@ (required)"
!endif
!ifdef GCC
File "@CMAKE_CURRENT_BINARY_DIR@\libjpeg-@SO_MAJOR_VERSION@.dll"
!ifdef 12BIT
File "@CMAKE_CURRENT_BINARY_DIR@\libjpeg12-@SO_MAJOR_VERSION@.dll"
!endif
!else
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}jpeg@SO_MAJOR_VERSION@.dll"
!ifdef 12BIT
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}jpeg12-@SO_MAJOR_VERSION@.dll"
!endif
!endif
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}cjpeg.exe"
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}djpeg.exe"
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}jpegtran.exe"
!ifdef 12BIT
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}cjpeg12.exe"
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}djpeg12.exe"
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}jpeg12tran.exe"
!endif
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}tjbench.exe"
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}rdjpgcom.exe"
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}wrjpgcom.exe"
@@ -73,25 +62,14 @@ Section "@CMAKE_PROJECT_NAME@ SDK for @INST_PLATFORM@ (required)"
File "@CMAKE_CURRENT_BINARY_DIR@\libturbojpeg.a"
File "@CMAKE_CURRENT_BINARY_DIR@\libjpeg.dll.a"
File "@CMAKE_CURRENT_BINARY_DIR@\libjpeg.a"
!ifdef 12BIT
File "@CMAKE_CURRENT_BINARY_DIR@\libjpeg12.dll.a"
File "@CMAKE_CURRENT_BINARY_DIR@\libjpeg12.a"
!endif
!else
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}turbojpeg.lib"
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}turbojpeg-static.lib"
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}jpeg.lib"
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}jpeg-static.lib"
!ifdef 12BIT
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}jpeg12.lib"
File "@CMAKE_CURRENT_BINARY_DIR@\${BUILDDIR}jpeg12-static.lib"
!endif
!endif
SetOutPath $INSTDIR\lib\pkgconfig
File "@CMAKE_CURRENT_BINARY_DIR@\pkgscripts\libjpeg.pc"
!ifdef 12BIT
File "@CMAKE_CURRENT_BINARY_DIR@\pkgscripts\libjpeg12.pc"
!endif
File "@CMAKE_CURRENT_BINARY_DIR@\pkgscripts\libturbojpeg.pc"
SetOutPath $INSTDIR\lib\cmake\@CMAKE_PROJECT_NAME@
File "@CMAKE_CURRENT_BINARY_DIR@\pkgscripts\@CMAKE_PROJECT_NAME@Config.cmake"
@@ -107,10 +85,6 @@ Section "@CMAKE_PROJECT_NAME@ SDK for @INST_PLATFORM@ (required)"
File "@CMAKE_CURRENT_SOURCE_DIR@\jerror.h"
File "@CMAKE_CURRENT_SOURCE_DIR@\jmorecfg.h"
File "@CMAKE_CURRENT_SOURCE_DIR@\jpeglib.h"
!ifdef 12BIT
File "@CMAKE_CURRENT_SOURCE_DIR@\jpeg12lib.h"
File "@CMAKE_CURRENT_SOURCE_DIR@\j12error.h"
!endif
File "@CMAKE_CURRENT_SOURCE_DIR@\turbojpeg.h"
SetOutPath $INSTDIR\doc
File "@CMAKE_CURRENT_SOURCE_DIR@\README.ijg"
@@ -155,39 +129,22 @@ Section "Uninstall"
!ifdef GCC
Delete $INSTDIR\bin\libjpeg-@SO_MAJOR_VERSION@.dll
!ifdef 12BIT
Delete $INSTDIR\bin\libjpeg12-@SO_MAJOR_VERSION@.dll
!endif
Delete $INSTDIR\bin\libturbojpeg.dll
Delete $SYSDIR\libturbojpeg.dll
Delete $INSTDIR\lib\libturbojpeg.dll.a
Delete $INSTDIR\lib\libturbojpeg.a
Delete $INSTDIR\lib\libjpeg.dll.a
Delete $INSTDIR\lib\libjpeg.a
!ifdef 12BIT
Delete $INSTDIR\lib\libjpeg12.dll.a
Delete $INSTDIR\lib\libjpeg12.a
!endif
!else
Delete $INSTDIR\bin\jpeg@SO_MAJOR_VERSION@.dll
!ifdef 12BIT
Delete $INSTDIR\bin\jpeg12-@SO_MAJOR_VERSION@.dll
!endif
Delete $INSTDIR\bin\turbojpeg.dll
Delete $SYSDIR\turbojpeg.dll
Delete $INSTDIR\lib\jpeg.lib
Delete $INSTDIR\lib\jpeg-static.lib
!ifdef 12BIT
Delete $INSTDIR\lib\jpeg12.lib
Delete $INSTDIR\lib\jpeg12-static.lib
!endif
Delete $INSTDIR\lib\turbojpeg.lib
Delete $INSTDIR\lib\turbojpeg-static.lib
!endif
Delete $INSTDIR\lib\pkgconfig\libjpeg.pc
!ifdef 12BIT
Delete $INSTDIR\lib\pkgconfig\libjpeg12.pc
!endif
Delete $INSTDIR\lib\pkgconfig\libturbojpeg.pc
Delete $INSTDIR\lib\cmake\@CMAKE_PROJECT_NAME@\@CMAKE_PROJECT_NAME@Config.cmake
Delete $INSTDIR\lib\cmake\@CMAKE_PROJECT_NAME@\@CMAKE_PROJECT_NAME@ConfigVersion.cmake
@@ -199,11 +156,6 @@ Section "Uninstall"
Delete $INSTDIR\bin\cjpeg.exe
Delete $INSTDIR\bin\djpeg.exe
Delete $INSTDIR\bin\jpegtran.exe
!ifdef 12BIT
Delete $INSTDIR\bin\cjpeg12.exe
Delete $INSTDIR\bin\djpeg12.exe
Delete $INSTDIR\bin\jpeg12tran.exe
!endif
Delete $INSTDIR\bin\tjbench.exe
Delete $INSTDIR\bin\rdjpgcom.exe
Delete $INSTDIR\bin\wrjpgcom.exe
@@ -211,9 +163,6 @@ Section "Uninstall"
Delete $INSTDIR\include\jerror.h
Delete $INSTDIR\include\jmorecfg.h
Delete $INSTDIR\include\jpeglib.h
!ifdef 12BIT
Delete $INSTDIR\include\jpeg12lib.h
!endif
Delete $INSTDIR\include\turbojpeg.h
Delete $INSTDIR\uninstall_@VERSION@.exe
Delete $INSTDIR\doc\README.ijg

View File

@@ -1,10 +0,0 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
Name: libjpeg12
Description: A 12-bit JPEG codec that provides the libjpeg API
Version: @VERSION@
Libs: -L${libdir} -ljpeg12
Cflags: -I${includedir}

View File

@@ -9,7 +9,6 @@
%define _enable_shared @ENABLE_SHARED@
%define _with_turbojpeg @WITH_TURBOJPEG@
%define _with_java @WITH_JAVA@
%define _with_12bit @WITH_12BIT@
%if "%{?__isa_bits:1}" == "1"
%define _bits %{__isa_bits}
@@ -174,11 +173,6 @@ rm -rf $RPM_BUILD_ROOT
%{_bindir}/cjpeg
%{_bindir}/djpeg
%{_bindir}/jpegtran
%if "%{_with_12bit}" == "1"
%{_bindir}/cjpeg12
%{_bindir}/djpeg12
%{_bindir}/jpeg12tran
%endif
%if "%{_with_turbojpeg}" == "1"
%{_bindir}/tjbench
%endif
@@ -191,23 +185,12 @@ rm -rf $RPM_BUILD_ROOT
%{_libdir}/libjpeg.so.@SO_MAJOR_VERSION@.@SO_AGE@.@SO_MINOR_VERSION@
%{_libdir}/libjpeg.so.@SO_MAJOR_VERSION@
%{_libdir}/libjpeg.so
%if "%{_with_12bit}" == "1"
%{_libdir}/libjpeg12.so.@SO_MAJOR_VERSION@.@SO_AGE@.@SO_MINOR_VERSION@
%{_libdir}/libjpeg12.so.@SO_MAJOR_VERSION@
%{_libdir}/libjpeg12.so
%endif
%endif
%if "%{_enable_static}" == "1"
%{_libdir}/libjpeg.a
%if "%{_with_12bit}" == "1"
%{_libdir}/libjpeg12.a
%endif
%endif
%dir %{_libdir}/pkgconfig
%{_libdir}/pkgconfig/libjpeg.pc
%if "%{_with_12bit}" == "1"
%{_libdir}/pkgconfig/libjpeg12.pc
%endif
%dir %{_libdir}/cmake
%dir %{_libdir}/cmake/@CMAKE_PROJECT_NAME@
%{_libdir}/cmake/@CMAKE_PROJECT_NAME@
@@ -227,10 +210,6 @@ rm -rf $RPM_BUILD_ROOT
%{_includedir}/jerror.h
%{_includedir}/jmorecfg.h
%{_includedir}/jpeglib.h
%if "%{_with_12bit}" == "1"
%{_includedir}/jpeg12lib.h
%{_includedir}/j12error.h
%endif
%if "%{_with_turbojpeg}" == "1"
%{_includedir}/turbojpeg.h
%endif

View File

@@ -23,10 +23,6 @@ foreach(src ${JPEG_SOURCES})
set(JPEG_SRCS ${JPEG_SRCS} ../${src})
endforeach()
foreach(src ${JPEG12_SOURCES})
set(JPEG12_SRCS ${JPEG12_SRCS} ../${src})
endforeach()
if(WITH_SIMD AND (MSVC_IDE OR XCODE))
# This tells CMake that the "source" files haven't been generated yet
set_source_files_properties(${SIMD_OBJS} PROPERTIES GENERATED 1)
@@ -41,7 +37,7 @@ if(MSVC)
set(JPEG_SRCS ${JPEG_SRCS} ${CMAKE_BINARY_DIR}/win/jpeg.rc)
endif()
add_library(jpeg SHARED ${JPEG_SRCS} ${DEFFILE} $<TARGET_OBJECTS:simd>
${SIMD_OBJS})
${SIMD_OBJS} ${JPEG12_OBJS})
set_target_properties(jpeg PROPERTIES SOVERSION ${SO_MAJOR_VERSION}
VERSION ${SO_MAJOR_VERSION}.${SO_AGE}.${SO_MINOR_VERSION})
@@ -66,78 +62,42 @@ elseif(MINGW)
set_target_properties(jpeg PROPERTIES SUFFIX -${SO_MAJOR_VERSION}.dll)
endif()
if(WITH_12BIT)
if(WIN32)
set(DEFFILE ../win/jpeg12-${SO_MAJOR_VERSION}.def)
endif()
add_library(jpeg12 SHARED ${JPEG12_SRCS} ${DEFFILE} ../jsimd_none.c)
set_property(TARGET jpeg12 PROPERTY COMPILE_FLAGS "-DBITS_IN_JSAMPLE=12")
set_target_properties(jpeg12 PROPERTIES SOVERSION ${SO_MAJOR_VERSION}
VERSION ${SO_MAJOR_VERSION}.${SO_AGE}.${SO_MINOR_VERSION})
if(APPLE AND (NOT CMAKE_OSX_DEPLOYMENT_TARGET OR
CMAKE_OSX_DEPLOYMENT_TARGET VERSION_GREATER 10.4))
set_target_properties(jpeg12 PROPERTIES MACOSX_RPATH 1)
endif()
if(MAPFLAG)
set_target_properties(jpeg12 PROPERTIES
LINK_FLAGS "${MAPFLAG}${CMAKE_CURRENT_BINARY_DIR}/../libjpeg12.map")
endif()
if(MSVC)
set_target_properties(jpeg12 PROPERTIES
RUNTIME_OUTPUT_NAME jpeg12-${SO_MAJOR_VERSION})
elseif(MINGW)
set_target_properties(jpeg12 PROPERTIES SUFFIX -${SO_MAJOR_VERSION}.dll)
endif()
endif()
if(WIN32)
set(USE_SETMODE "-DUSE_SETMODE")
endif()
add_executable(cjpeg ../cjpeg.c ../cdjpeg.c ../rdbmp.c ../rdgif.c ../rdppm.c
../rdswitch.c ../rdtarga.c)
set_property(TARGET cjpeg PROPERTY COMPILE_FLAGS
set(CDJPEG_COMPILE_FLAGS
"-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED ${USE_SETMODE}")
# Compile a separate version of these source files with 12-bit data precision.
if(WITH_12BIT)
add_library(cjpeg12 OBJECT ../rdgif.c ../rdppm.c)
set_property(TARGET cjpeg12 PROPERTY COMPILE_FLAGS
"-DBITS_IN_JSAMPLE=12 -DGIF_SUPPORTED -DPPM_SUPPORTED")
set(CJPEG12_OBJS $<TARGET_OBJECTS:cjpeg12>)
endif()
add_executable(cjpeg ../cjpeg.c ../cdjpeg.c ../rdbmp.c ../rdgif.c ../rdppm.c
../rdswitch.c ../rdtarga.c ${CJPEG12_OBJS})
set_property(TARGET cjpeg PROPERTY COMPILE_FLAGS ${CDJPEG_COMPILE_FLAGS})
target_link_libraries(cjpeg jpeg)
# Compile a separate version of these source files with 12-bit data precision.
if(WITH_12BIT)
add_library(djpeg12 OBJECT ../rdcolmap.c ../wrgif.c ../wrppm.c)
set_property(TARGET djpeg12 PROPERTY COMPILE_FLAGS
"-DBITS_IN_JSAMPLE=12 -DGIF_SUPPORTED -DPPM_SUPPORTED")
set(DJPEG12_OBJS $<TARGET_OBJECTS:djpeg12>)
endif()
add_executable(djpeg ../djpeg.c ../cdjpeg.c ../rdcolmap.c ../rdswitch.c
../wrbmp.c ../wrgif.c ../wrppm.c ../wrtarga.c)
set_property(TARGET djpeg PROPERTY COMPILE_FLAGS
"-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED ${USE_SETMODE}")
../wrbmp.c ../wrgif.c ../wrppm.c ../wrtarga.c ${DJPEG12_OBJS})
set_property(TARGET djpeg PROPERTY COMPILE_FLAGS ${CDJPEG_COMPILE_FLAGS})
target_link_libraries(djpeg jpeg)
add_executable(jpegtran ../jpegtran.c ../cdjpeg.c ../rdswitch.c ../transupp.c)
target_link_libraries(jpegtran jpeg)
set_property(TARGET jpegtran PROPERTY COMPILE_FLAGS "${USE_SETMODE}")
if(WITH_12BIT)
add_executable(cjpeg12 ../cjpeg.c ../cdjpeg.c ../rdgif.c ../rdppm.c
../rdswitch.c)
set_property(TARGET cjpeg12 PROPERTY COMPILE_FLAGS
"-DBITS_IN_JSAMPLE=12 -DGIF_SUPPORTED -DPPM_SUPPORTED ${USE_SETMODE}")
target_link_libraries(cjpeg12 jpeg12)
add_executable(djpeg12 ../djpeg.c ../cdjpeg.c ../rdcolmap.c ../rdswitch.c
../wrgif.c ../wrppm.c)
set_property(TARGET djpeg12 PROPERTY COMPILE_FLAGS
"-DBITS_IN_JSAMPLE=12 -DGIF_SUPPORTED -DPPM_SUPPORTED ${USE_SETMODE}")
target_link_libraries(djpeg12 jpeg12)
add_executable(jpeg12tran ../jpegtran.c ../cdjpeg.c ../rdswitch.c
../transupp.c)
target_link_libraries(jpeg12tran jpeg12)
set_property(TARGET jpeg12tran PROPERTY COMPILE_FLAGS
"-DBITS_IN_JSAMPLE=12 ${USE_SETMODE}")
endif()
add_executable(example ../example.c)
if(WITH_12BIT)
target_link_libraries(example jpeg jpeg12)
set_property(TARGET example PROPERTY COMPILE_FLAGS "-DWITH_12BIT")
else()
target_link_libraries(example jpeg)
endif()
target_link_libraries(example jpeg)
add_executable(jcstest ../jcstest.c)
target_link_libraries(jcstest jpeg)
@@ -154,18 +114,3 @@ if(NOT CMAKE_VERSION VERSION_LESS "3.1" AND MSVC AND
install(FILES "$<TARGET_PDB_FILE:jpeg>"
DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
endif()
if(WITH_12BIT)
install(TARGETS jpeg12 EXPORT ${CMAKE_PROJECT_NAME}Targets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS cjpeg12 djpeg12 jpeg12tran
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
if(NOT CMAKE_VERSION VERSION_LESS "3.1" AND MSVC AND
CMAKE_C_LINKER_SUPPORTS_PDB)
install(FILES "$<TARGET_PDB_FILE:jpeg12>"
DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
endif()
endif()

View File

@@ -450,9 +450,9 @@ shown are:
is not used for full-color output. Works on one pixel row at a time; may
require two passes to generate a color map. Note that the output will
always be a single component representing colormap indexes. In the current
design, the output values are JSAMPLEs, so an 8-bit compilation cannot
quantize to more than 256 colors. This is unlikely to be a problem in
practice.
design, the output values are JSAMPLEs or J12SAMPLEs, so the library cannot
quantize to more than 256 colors when using 8-bit data precision. This is
unlikely to be a problem in practice.
* Color reduction: this module handles color precision reduction, e.g.,
generating 15-bit color (5 bits/primary) from JPEG's 24-bit output.
@@ -538,28 +538,35 @@ there isn't any real need for it.
*** Data formats ***
Arrays of pixel sample values use the following data structure:
Arrays of 8-bit pixel sample values use the following data structure:
typedef something JSAMPLE; a pixel component value, 0..MAXJSAMPLE
typedef JSAMPLE *JSAMPROW; ptr to a row of samples
typedef JSAMPROW *JSAMPARRAY; ptr to a list of rows
typedef JSAMPARRAY *JSAMPIMAGE; ptr to a list of color-component arrays
The basic element type JSAMPLE will be one of unsigned char or short. Short
will be used if samples wider than 8 bits are to be supported (this is a
compile-time option). Otherwise, unsigned char is used.
Arrays of 12-bit pixel sample values use the following data structure:
With these conventions, JSAMPLE values can be assumed to be >= 0. This helps
typedef something J12SAMPLE; a pixel component value, 0..MAXJ12SAMPLE
typedef J12SAMPLE *J12SAMPROW; ptr to a row of samples
typedef J12SAMPROW *J12SAMPARRAY; ptr to a list of rows
typedef J12SAMPARRAY *J12SAMPIMAGE; ptr to a list of color-component arrays
The basic element type JSAMPLE (8-bit sample) will be unsigned char, and the
basic element type J12SAMPLE (12-bit sample) with be short.
With these conventions, J*SAMPLE values can be assumed to be >= 0. This helps
simplify correct rounding during downsampling, etc. The JPEG standard's
specification that sample values run from -128..127 is accommodated by
specification that 8-bit sample values run from -128..127 is accommodated by
subtracting 128 from the sample value in the DCT step. Similarly, during
decompression the output of the IDCT step will be immediately shifted back to
0..255. (NB: different values are required when 12-bit samples are in use.
The code is written in terms of MAXJSAMPLE and CENTERJSAMPLE, which will be
defined as 255 and 128 respectively in an 8-bit implementation, and as 4095
and 2048 in a 12-bit implementation.)
0..255. (NOTE: different values are required when 12-bit samples are in use.
When 8-bit samples are in use, the code uses MAXJSAMPLE and CENTERJSAMPLE,
which are defined as 255 and 128 respectively. When 12-bit samples are in use,
the code uses MAXJ12SAMPLE and CENTERJ12SAMPLE, which are defined as 4095 and
2048 respectively.)
We use a pointer per row, rather than a two-dimensional JSAMPLE array. This
We use a pointer per row, rather than a two-dimensional J*SAMPLE array. This
choice costs only a small amount of memory and has several benefits:
* Code using the data structure doesn't need to know the allocated width of
the rows. This simplifies edge expansion/compression, since we can work
@@ -589,9 +596,9 @@ be precomputed by copying the relevant pointer.
Since most image-processing applications prefer to work on images in which
the components of a pixel are stored together, the data passed to or from the
surrounding application uses the traditional convention: a single pixel is
represented by N consecutive JSAMPLE values, and an image row is an array of
(# of color components)*(image width) JSAMPLEs. One or more rows of data can
be represented by a pointer of type JSAMPARRAY in this scheme. This scheme is
represented by N consecutive J*SAMPLE values, and an image row is an array of
(# of color components)*(image width) J*SAMPLEs. One or more rows of data can
be represented by a pointer of type J*SAMPARRAY in this scheme. This scheme is
converted to component-wise storage inside the JPEG library. (Applications
that want to skip JPEG preprocessing or postprocessing will have to contend
with component-wise storage.)
@@ -730,17 +737,17 @@ The memory manager deals with three kinds of object:
pointers on MS-DOS machines.) Note that individual "large" objects cannot
exceed the size allowed by type size_t, which may be 64K or less on some
machines.
3. "Virtual" objects. These are large 2-D arrays of JSAMPLEs or JBLOCKs
3. "Virtual" objects. These are large 2-D arrays of J*SAMPLEs or JBLOCKs
(typically large enough for the entire image being processed). The
memory manager provides stripwise access to these arrays. On machines
without virtual memory, the rest of the array may be swapped out to a
temporary file.
(Note: JSAMPARRAY and JBLOCKARRAY data structures are a combination of large
(Note: J*SAMPARRAY and JBLOCKARRAY data structures are a combination of large
objects for the data proper and small objects for the row pointers. For
convenience and speed, the memory manager provides single routines to create
these structures. Similarly, virtual arrays include a small control block
and a JSAMPARRAY or JBLOCKARRAY working buffer, all created with one call.)
and a J*SAMPARRAY or JBLOCKARRAY working buffer, all created with one call.)
In the present implementation, virtual arrays are only permitted to have image
lifespan. (Permanent lifespan would not be reasonable, and pass lifespan is
@@ -767,7 +774,7 @@ To support all this, we establish the following protocol for doing business
with the memory manager:
1. Modules must request virtual arrays (which may have only image lifespan)
during the initial setup phase, i.e., in their jinit_xxx routines.
2. All "large" objects (including JSAMPARRAYs and JBLOCKARRAYs) must also be
2. All "large" objects (including J*SAMPARRAYs and JBLOCKARRAYs) must also be
allocated during initial setup.
3. realize_virt_arrays will be called at the completion of initial setup.
The above conventions ensure that sufficient information is available

View File

@@ -21,9 +21,9 @@
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglibint.h"
#include "jpeglib.h"
#include "transupp.h" /* My own external interface */
#include "jpegcomp.h"
#include "jpegapicomp.h"
#include <ctype.h> /* to declare isdigit() */

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