Handle lossless JPEG images w/2-15 bits per sample

Closes #768
Closes #769
This commit is contained in:
DRC
2024-06-13 11:52:13 -04:00
parent 3290711d9c
commit 6ec8e41f50
63 changed files with 1566 additions and 869 deletions

View File

@@ -886,6 +886,54 @@ if(WITH_JAVA)
${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -precision 12 -lossless)
add_test(TJUnitTest2-lossless
${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -precision 2)
add_test(TJUnitTest3-lossless
${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -precision 3)
add_test(TJUnitTest4-lossless
${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -precision 4)
add_test(TJUnitTest5-lossless
${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -precision 5)
add_test(TJUnitTest6-lossless
${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -precision 6)
add_test(TJUnitTest7-lossless
${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -precision 7)
add_test(TJUnitTest9-lossless
${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -precision 9)
add_test(TJUnitTest10-lossless
${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -precision 10)
add_test(TJUnitTest11-lossless
${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -precision 11)
add_test(TJUnitTest13-lossless
${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -precision 13)
add_test(TJUnitTest14-lossless
${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -precision 14)
add_test(TJUnitTest15-lossless
${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
TJUnitTest -precision 15)
add_test(TJUnitTest16-lossless
${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
@@ -1041,6 +1089,78 @@ foreach(libtype ${TEST_LIBTYPES})
COMMAND tjunittest${suffix} -precision 12 -lossless -alloc)
add_test(NAME tjunittest12-${libtype}-bmp
COMMAND tjunittest${suffix} -precision 12 -bmp)
add_test(NAME tjunittest2-${libtype}-lossless
COMMAND tjunittest${suffix} -precision 2)
add_test(NAME tjunittest2-${libtype}-lossless-alloc
COMMAND tjunittest${suffix} -precision 2 -alloc)
add_test(NAME tjunittest2-${libtype}-bmp
COMMAND tjunittest${suffix} -precision 2 -bmp)
add_test(NAME tjunittest3-${libtype}-lossless
COMMAND tjunittest${suffix} -precision 3)
add_test(NAME tjunittest3-${libtype}-lossless-alloc
COMMAND tjunittest${suffix} -precision 3 -alloc)
add_test(NAME tjunittest3-${libtype}-bmp
COMMAND tjunittest${suffix} -precision 3 -bmp)
add_test(NAME tjunittest4-${libtype}-lossless
COMMAND tjunittest${suffix} -precision 4)
add_test(NAME tjunittest4-${libtype}-lossless-alloc
COMMAND tjunittest${suffix} -precision 4 -alloc)
add_test(NAME tjunittest4-${libtype}-bmp
COMMAND tjunittest${suffix} -precision 4 -bmp)
add_test(NAME tjunittest5-${libtype}-lossless
COMMAND tjunittest${suffix} -precision 5)
add_test(NAME tjunittest5-${libtype}-lossless-alloc
COMMAND tjunittest${suffix} -precision 5 -alloc)
add_test(NAME tjunittest5-${libtype}-bmp
COMMAND tjunittest${suffix} -precision 5 -bmp)
add_test(NAME tjunittest6-${libtype}-lossless
COMMAND tjunittest${suffix} -precision 6)
add_test(NAME tjunittest6-${libtype}-lossless-alloc
COMMAND tjunittest${suffix} -precision 6 -alloc)
add_test(NAME tjunittest6-${libtype}-bmp
COMMAND tjunittest${suffix} -precision 6 -bmp)
add_test(NAME tjunittest7-${libtype}-lossless
COMMAND tjunittest${suffix} -precision 7)
add_test(NAME tjunittest7-${libtype}-lossless-alloc
COMMAND tjunittest${suffix} -precision 7 -alloc)
add_test(NAME tjunittest7-${libtype}-bmp
COMMAND tjunittest${suffix} -precision 7 -bmp)
add_test(NAME tjunittest9-${libtype}-lossless
COMMAND tjunittest${suffix} -precision 9)
add_test(NAME tjunittest9-${libtype}-lossless-alloc
COMMAND tjunittest${suffix} -precision 9 -alloc)
add_test(NAME tjunittest9-${libtype}-bmp
COMMAND tjunittest${suffix} -precision 9 -bmp)
add_test(NAME tjunittest10-${libtype}-lossless
COMMAND tjunittest${suffix} -precision 10)
add_test(NAME tjunittest10-${libtype}-lossless-alloc
COMMAND tjunittest${suffix} -precision 10 -alloc)
add_test(NAME tjunittest10-${libtype}-bmp
COMMAND tjunittest${suffix} -precision 10 -bmp)
add_test(NAME tjunittest11-${libtype}-lossless
COMMAND tjunittest${suffix} -precision 11)
add_test(NAME tjunittest11-${libtype}-lossless-alloc
COMMAND tjunittest${suffix} -precision 11 -alloc)
add_test(NAME tjunittest11-${libtype}-bmp
COMMAND tjunittest${suffix} -precision 11 -bmp)
add_test(NAME tjunittest13-${libtype}-lossless
COMMAND tjunittest${suffix} -precision 13)
add_test(NAME tjunittest13-${libtype}-lossless-alloc
COMMAND tjunittest${suffix} -precision 13 -alloc)
add_test(NAME tjunittest13-${libtype}-bmp
COMMAND tjunittest${suffix} -precision 13 -bmp)
add_test(NAME tjunittest14-${libtype}-lossless
COMMAND tjunittest${suffix} -precision 14)
add_test(NAME tjunittest14-${libtype}-lossless-alloc
COMMAND tjunittest${suffix} -precision 14 -alloc)
add_test(NAME tjunittest14-${libtype}-bmp
COMMAND tjunittest${suffix} -precision 14 -bmp)
add_test(NAME tjunittest15-${libtype}-lossless
COMMAND tjunittest${suffix} -precision 15)
add_test(NAME tjunittest15-${libtype}-lossless-alloc
COMMAND tjunittest${suffix} -precision 15 -alloc)
add_test(NAME tjunittest15-${libtype}-bmp
COMMAND tjunittest${suffix} -precision 15 -bmp)
add_test(NAME tjunittest16-${libtype}-lossless
COMMAND tjunittest${suffix} -precision 16)
add_test(NAME tjunittest16-${libtype}-lossless-alloc
@@ -1718,6 +1838,30 @@ if(WITH_TURBOJPEG)
${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest
${CMAKE_CURRENT_BINARY_DIR}/tjexampletest)
add_custom_target(tjtest16 COMMAND ${CMAKE_COMMAND} -DWITH_JAVA=${WITH_JAVA}
-DPRECISION=2 -P ${CMAKE_SOURCE_DIR}/cmakescripts/tjbenchtest.cmake
COMMAND ${CMAKE_COMMAND} -DWITH_JAVA=${WITH_JAVA}
-DPRECISION=3 -P ${CMAKE_SOURCE_DIR}/cmakescripts/tjbenchtest.cmake
COMMAND ${CMAKE_COMMAND} -DWITH_JAVA=${WITH_JAVA}
-DPRECISION=4 -P ${CMAKE_SOURCE_DIR}/cmakescripts/tjbenchtest.cmake
COMMAND ${CMAKE_COMMAND} -DWITH_JAVA=${WITH_JAVA}
-DPRECISION=5 -P ${CMAKE_SOURCE_DIR}/cmakescripts/tjbenchtest.cmake
COMMAND ${CMAKE_COMMAND} -DWITH_JAVA=${WITH_JAVA}
-DPRECISION=6 -P ${CMAKE_SOURCE_DIR}/cmakescripts/tjbenchtest.cmake
COMMAND ${CMAKE_COMMAND} -DWITH_JAVA=${WITH_JAVA}
-DPRECISION=7 -P ${CMAKE_SOURCE_DIR}/cmakescripts/tjbenchtest.cmake
COMMAND ${CMAKE_COMMAND} -DWITH_JAVA=${WITH_JAVA}
-DPRECISION=9 -P ${CMAKE_SOURCE_DIR}/cmakescripts/tjbenchtest.cmake
COMMAND ${CMAKE_COMMAND} -DWITH_JAVA=${WITH_JAVA}
-DPRECISION=10 -P ${CMAKE_SOURCE_DIR}/cmakescripts/tjbenchtest.cmake
COMMAND ${CMAKE_COMMAND} -DWITH_JAVA=${WITH_JAVA}
-DPRECISION=11 -P ${CMAKE_SOURCE_DIR}/cmakescripts/tjbenchtest.cmake
COMMAND ${CMAKE_COMMAND} -DWITH_JAVA=${WITH_JAVA}
-DPRECISION=13 -P ${CMAKE_SOURCE_DIR}/cmakescripts/tjbenchtest.cmake
COMMAND ${CMAKE_COMMAND} -DWITH_JAVA=${WITH_JAVA}
-DPRECISION=14 -P ${CMAKE_SOURCE_DIR}/cmakescripts/tjbenchtest.cmake
COMMAND ${CMAKE_COMMAND} -DWITH_JAVA=${WITH_JAVA}
-DPRECISION=15 -P ${CMAKE_SOURCE_DIR}/cmakescripts/tjbenchtest.cmake
COMMAND ${CMAKE_COMMAND} -DWITH_JAVA=${WITH_JAVA}
-DPRECISION=16 -P ${CMAKE_SOURCE_DIR}/cmakescripts/tjbenchtest.cmake
DEPENDS ${CMAKE_SOURCE_DIR}/cmakescripts/tjbenchtest.cmake
${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest

View File

@@ -18,6 +18,18 @@ packed-pixel grayscale image.
images have at most 256 colors referenced from a palette of 8-bit-per-component
RGB values.
4. Added support for lossless JPEG images with 2 to 15 bits per sample to the
libjpeg and TurboJPEG APIs. When creating or decompressing a lossless JPEG
image and when loading or saving a PBMPLUS image, functions/methods specific to
8-bit samples now handle 8-bit samples with 2 to 8 bits of data precision
(specified using the `data_precision` field in `jpeg_compress_struct` or
`jpeg_decompress_struct` or using `TJPARAM_PRECISION`/`TJ.PARAM_PRECISION`),
functions/methods specific to 12-bit samples now handle 12-bit samples with 9
to 12 bits of data precision, and functions/methods specific to 16-bit samples
now handle 16-bit samples with 13 to 16 bits of data precision. Refer to
[libjpeg.txt](doc/libjpeg.txt), [usage.txt](doc/usage.txt), and the TurboJPEG
API documentation for more details.
3.0.4
=====

View File

@@ -20,7 +20,7 @@ macro(run_test PROG ARGS)
check_error("${PROG} ${SPACED_ARGS}")
endmacro()
if(NOT PRECISION EQUAL 16)
if(PRECISION EQUAL 8 OR PRECISION EQUAL 12)
run_test(tjbenchtest "-precision;${PRECISION}")
run_test(tjbenchtest "-precision;${PRECISION};-alloc")
endif()
@@ -30,13 +30,13 @@ if(PRECISION EQUAL 8)
run_test(tjbenchtest "-precision;${PRECISION};-optimize")
run_test(tjbenchtest "-precision;${PRECISION};-optimize;-yuv")
endif()
if(NOT PRECISION EQUAL 16)
if(PRECISION EQUAL 8 OR PRECISION EQUAL 12)
run_test(tjbenchtest "-precision;${PRECISION};-progressive")
endif()
if(PRECISION EQUAL 8)
run_test(tjbenchtest "-precision;${PRECISION};-progressive;-yuv")
endif()
if(NOT PRECISION EQUAL 16)
if(PRECISION EQUAL 8 OR PRECISION EQUAL 12)
run_test(tjbenchtest "-precision;${PRECISION};-arithmetic")
run_test(tjbenchtest "-precision;${PRECISION};-progressive;-arithmetic")
endif()
@@ -49,7 +49,7 @@ if(PRECISION EQUAL 8)
run_test(tjexampletest "")
endif()
if(WITH_JAVA)
if(NOT PRECISION EQUAL 16)
if(PRECISION EQUAL 8 OR PRECISION EQUAL 12)
run_test(tjbenchtest "-java;-precision;${PRECISION}")
endif()
if(PRECISION EQUAL 8)
@@ -57,13 +57,13 @@ if(WITH_JAVA)
run_test(tjbenchtest "-java;-precision;${PRECISION};-optimize")
run_test(tjbenchtest "-java;-precision;${PRECISION};-optimize;-yuv")
endif()
if(NOT PRECISION EQUAL 16)
if(PRECISION EQUAL 8 OR PRECISION EQUAL 12)
run_test(tjbenchtest "-java;-precision;${PRECISION};-progressive")
endif()
if(PRECISION EQUAL 8)
run_test(tjbenchtest "-java;-precision;${PRECISION};-progressive;-yuv")
endif()
if(NOT PRECISION EQUAL 16)
if(PRECISION EQUAL 8 OR PRECISION EQUAL 12)
run_test(tjbenchtest "-java;-precision;${PRECISION};-arithmetic")
run_test(tjbenchtest "-java;-precision;${PRECISION};-progressive;-arithmetic")
endif()

View File

@@ -154,8 +154,8 @@ about the same --- often a little smaller.
Switches for advanced users:
.TP
.BI \-precision " N"
Create JPEG file with N-bit data precision. N is 8, 12, or 16; default is 8.
If N is 16, then
Create JPEG file with N-bit data precision. N is 2 to 16; default is 8. If N
is not 8 or 12, then
.B -lossless
must also be specified. Note that only the PBMPLUS input file format supports
data precisions other than 8. Note also that PBMPLUS input files are silently
@@ -166,9 +166,8 @@ to
.B cjpeg
will cause it to print information about the precision of the input file.
.B Caution:
12-bit and 16-bit data precision is not yet widely implemented, so many
decoders will be unable to handle a 12-bit-per-sample or 16-bit-per-sample JPEG
file at all.
only 8-bit data precision is widely implemented, so many decoders will be
unable to handle JPEG files with other data precisions.
.IP
.B \-precision\ 12
implies

View File

@@ -1,5 +1,5 @@
PROJECT_NAME = TurboJPEG
PROJECT_NUMBER = 3.0.1
PROJECT_NUMBER = 3.0.2
OUTPUT_DIRECTORY = ../doc/
HTML_OUTPUT = turbojpeg
USE_WINDOWS_ENCODING = NO

View File

@@ -31,7 +31,7 @@ TABLE OF CONTENTS
Overview:
Functions provided by the library
12-bit and 16-bit Data Precision
Data Precision
Outline of typical usage
Basic library usage:
Data formats
@@ -101,8 +101,8 @@ use.) Unsupported ISO options include:
* Hierarchical storage
* DNL marker
* Nonintegral subsampling ratios
We support 8-bit (lossy and lossless), 12-bit (lossy and lossless), and 16-bit
(lossless) data precision.
We support 8-bit and 12-bit data precision in lossy mode and 2-bit through
16-bit data precision in lossless mode.
By itself, the library handles only interchange JPEG datastreams --- in
particular the widely used JFIF file format. The library can be used by
@@ -111,19 +111,21 @@ are embedded in more complex file formats. (For example, this library is
used by the free LIBTIFF library to support JPEG compression in TIFF.)
12-bit and 16-bit Data Precision
--------------------------------
Data Precision
--------------
The JPEG standard provides for baseline (8-bit-per-sample) and
12-bit-per-sample DCT processes as well as 8-bit-per-sample, 12-bit-per-sample,
and 16-bit-per-sample lossless (predictive) processes. This code supports
12-bit-per-sample lossy or lossless JPEG if you set cinfo->data_precision to 12
and 16-bit-per-sample lossless JPEG if you set cinfo->data_precision to 16.
Note that this causes the sample size to be larger than a char, so it affects
the surrounding application's image data. The sample application djpeg can
support 12-bit data precision only for PPM, PGM, and GIF file formats. The
sample applications cjpeg and djpeg can support 16-bit data precision only for
PPM and PGM file formats.
The data precision is the number of bits in the maximum sample value (which may
not be the same as the width of the data type used to store the sample.) The
JPEG standard provides for, and this code supports, baseline (8-bit-per-sample)
and 12-bit-per-sample DCT processes as well as lossless (predictive) processes
with 2 to 16 bits of data precision per sample. To create a JPEG image with a
particular data precision, set cinfo->data_precision accordingly. Note that
9-bit and higher data precisions cause the sample size to be larger than a
char, which affects the surrounding application's image data. The sample
application djpeg can support 12-bit data precision only for PPM, PGM, and GIF
file formats. The sample applications cjpeg and djpeg can support 2-bit
through 7-bit and 9-bit through 16-bit data precision only for PPM and PGM file
formats.
Note that, when 12-bit data precision is enabled in lossy mode, the library
compresses in Huffman optimization mode by default, in order to generate valid
@@ -134,8 +136,9 @@ to supply your own DCT quantization tables; the existing quality-scaling code
has been developed for 8-bit data precision and probably doesn't generate
especially good tables for 12-bit data precision.
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:
Functions that are specific to 9-bit through 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
@@ -144,8 +147,9 @@ instead of "jpeg_" and use the following data types and macros:
* MAXJ12SAMPLE instead of MAXJSAMPLE
* CENTERJ12SAMPLE instead of CENTERJSAMPLE
Functions that are specific to 16-bit data precision have a prefix of "jpeg16_"
instead of "jpeg_" and use the following data types and macros:
Functions that are specific to 13-bit through 16-bit data precision have a
prefix of "jpeg16_" instead of "jpeg_" and use the following data types and
macros:
* J16SAMPLE instead of JSAMPLE
* J16SAMPROW instead of JSAMPROW
@@ -154,17 +158,17 @@ instead of "jpeg_" and use the following data types and macros:
* MAXJ16SAMPLE instead of MAXJSAMPLE
* CENTERJ16SAMPLE instead of CENTERJSAMPLE
This allows 8-bit, 12-bit, and 16-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, nor are they
implemented for lossless mode with any data precision.
This allows multiple data precisions to be used in a single application.
(Refer to example.c). Arithmetic coding and SIMD acceleration are currently
only implemented for lossy mode with 8-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 the 8-bit-per-sample, 12-bit-per-sample,
or 16-bit-per-sample data types.
"J*SAMPIMAGE" to generically refer to the data types with 2 to 8 bits of data
precision per sample, 9 to 12 bits of data precision per sample, and 13 to 16
bits of data precision per sample.
Outline of typical usage
@@ -178,9 +182,11 @@ The rough outline of a JPEG compression operation is:
jpeg_start_compress(...);
while (scan lines remain to be written)
jpeg_write_scanlines(...); /* Use jpeg12_write_scanlines() for
12-bit data precision and
9-bit through 12-bit data
precision and
jpeg16_write_scanlines() for
16-bit data precision. */
13-bit through 16-bit data
precision. */
jpeg_finish_compress(...);
Release the JPEG compression object
@@ -208,9 +214,11 @@ Similarly, the rough outline of a JPEG decompression operation is:
jpeg_start_decompress(...);
while (scan lines remain to be read)
jpeg_read_scanlines(...); /* Use jpeg12_read_scanlines() for
12-bit data precision and
9-bit through 12-bit data
precision and
jpeg16_read_scanlines() for
16-bit data precision. */
13-bit through 16-bit data
precision. */
jpeg_finish_decompress(...);
Release the JPEG decompression object
@@ -287,13 +295,6 @@ processed top-to-bottom. You can process an entire image in one call if you
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
cinfo->data_precision (normally 8 bits per sample). 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
or 16.
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
@@ -443,10 +444,10 @@ the compression cycle.
5. while (scan lines remain to be written)
jpeg_write_scanlines(...); /* Use jpeg12_write_scanlines() for 12-bit
data precision and
jpeg16_write_scanlines() for 16-bit data
precision. */
jpeg_write_scanlines(...); /* Use jpeg12_write_scanlines() for 9-bit
through 12-bit data precision and
jpeg16_write_scanlines() for 13-bit
through 16-bit data precision. */
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
@@ -472,17 +473,19 @@ 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
Use J12SAMPROW for 12-bit data
precision and J16SAMPROW for 16-bit
data precision. */
Use J12SAMPROW for 9-bit through
12-bit data precision and J16SAMPROW
for 13-bit through 16-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 and
jpeg16_write_scanlines() for 16-bit
data precision. */
9-bit through 12-bit data precision
and jpeg16_write_scanlines() for
13-bit through 16-bit data
precision. */
}
jpeg*_write_scanlines() returns the number of scanlines actually written.
@@ -726,10 +729,10 @@ relevant parameters (scaling, output color space, and quantization flag).
6. while (scan lines remain to be read)
jpeg_read_scanlines(...); /* Use jpeg12_read_scanlines() for 12-bit
data precision and
jpeg16_read_scanlines() for 16-bit data
precision. */
jpeg_read_scanlines(...); /* Use jpeg12_read_scanlines() for 9-bit
through 12-bit data precision and
jpeg16_read_scanlines() for 13-bit
through 16-bit data precision. */
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
@@ -1083,14 +1086,14 @@ boolean arith_code
If FALSE, use Huffman coding.
int data_precision
To create a 12-bit-per-sample JPEG file, set data_precision to 12 prior
to calling jpeg_start_compress() or using the memory manager, then use
Prior to calling jpeg_start_compress() or using the memory manager, set
data_precision to the desired number of bits per sample (2 to 16) in
the JPEG file. To create a JPEG file with 9 to 12 bits per sample, use
jpeg12_write_scanlines() or jpeg12_write_raw_data() instead of
jpeg_write_scanlines() or jpeg_write_raw_data(). To create a
16-bit-per-sample lossless JPEG file, set data_precision to 16 prior to
calling jpeg_start_compress() or using the memory manager, then use
jpeg16_write_scanlines() instead of jpeg_write_scanlines(). Note that
16-bit data precision requires lossless mode. (See
jpeg_write_scanlines() or jpeg_write_raw_data(). To create a lossless
JPEG file with 13 to 16 bits per sample, use jpeg16_write_scanlines()
instead of jpeg_write_scanlines(). Note that data precisions other
than 8-bit and 12-bit require lossless mode. (See
jpeg_enable_lossless().)
J_DCT_METHOD dct_method
@@ -1318,11 +1321,11 @@ 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 sample)
If data_precision is 12, then use jpeg12_read_scanlines(),
If data_precision is 9 to 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(). If data_precision is 16, then use
jpeg_read_raw_data(). If data_precision is 13 to 16, then use
jpeg16_read_scanlines() instead of jpeg_read_scanlines().
JDIMENSION image_width Width and height of image
@@ -2122,9 +2125,10 @@ The basic control flow for buffered-image decoding is
jpeg_start_output() /* start a new output pass */
for (all scanlines in image) {
jpeg_read_scanlines() /* Use jpeg12_read_scanlines() for
12-bit data precision and
jpeg16_read_scanlines() for 16-bit
data precision. */
9-bit through 12-bit data precision
and jpeg16_read_scanlines() for
13-bit through 16-bit data
precision. */
display scanlines
}
jpeg_finish_output() /* terminate output pass */
@@ -3191,11 +3195,11 @@ As of v6b, the decompressor requires:
This does not count any memory allocated by the application, such as a
buffer to hold the final output image.
The above figures are valid for 8-bit JPEG data precision and a machine with
32-bit ints. For 12-bit-per-sample and 16-bit-per-sample JPEG data, double the
size of the strip buffers and quantization pixel buffer. The "fixed-size" data
will be somewhat smaller with 16-bit ints, larger with 64-bit ints. Also, CMYK
or other unusual color spaces will require different amounts of space.
The above figures are valid for 2-bit through 8-bit JPEG data precision and a
machine with 32-bit ints. For other data precisions, double the size of the
strip buffers and quantization pixel buffer. The "fixed-size" data will be
somewhat smaller with 16-bit ints, larger with 64-bit ints. Also, CMYK or
other unusual color spaces will require different amounts of space.
The full-image coefficient and pixel buffers, if needed at all, do not
have to be fully RAM resident; you can have the library use temporary

View File

@@ -22,7 +22,7 @@
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.1</span>
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.2</span>
</div>
</td>
</tr>

View File

@@ -22,7 +22,7 @@
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.1</span>
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.2</span>
</div>
</td>
</tr>

View File

@@ -22,7 +22,7 @@
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.1</span>
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.2</span>
</div>
</td>
</tr>

View File

@@ -22,7 +22,7 @@
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.1</span>
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.2</span>
</div>
</td>
</tr>

View File

@@ -22,7 +22,7 @@
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.1</span>
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.2</span>
</div>
</td>
</tr>
@@ -278,13 +278,13 @@ Functions</h2></td></tr>
<tr class="memdesc:ga34af9ba3183bdf0ec7c8f47bb9a4c84f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the value of a parameter. <br /></td></tr>
<tr class="separator:ga34af9ba3183bdf0ec7c8f47bb9a4c84f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga2cc418a2dab709ad7f30f5b25905f138" id="r_ga2cc418a2dab709ad7f30f5b25905f138"><td class="memItemLeft" align="right" valign="top">DLLEXPORT int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga2cc418a2dab709ad7f30f5b25905f138">tj3Compress8</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle, const unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf, size_t *jpegSize)</td></tr>
<tr class="memdesc:ga2cc418a2dab709ad7f30f5b25905f138"><td class="mdescLeft">&#160;</td><td class="mdescRight">Compress an 8-bit-per-sample packed-pixel RGB, grayscale, or CMYK image into an 8-bit-per-sample JPEG image. <br /></td></tr>
<tr class="memdesc:ga2cc418a2dab709ad7f30f5b25905f138"><td class="mdescLeft">&#160;</td><td class="mdescRight">Compress a packed-pixel RGB, grayscale, or CMYK image with 2 to 8 bits of data precision per sample into a JPEG image with the same data precision. <br /></td></tr>
<tr class="separator:ga2cc418a2dab709ad7f30f5b25905f138"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga9a1968c384ec7abb6122830253ebf570" id="r_ga9a1968c384ec7abb6122830253ebf570"><td class="memItemLeft" align="right" valign="top">DLLEXPORT int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga9a1968c384ec7abb6122830253ebf570">tj3Compress12</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle, const short *srcBuf, int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf, size_t *jpegSize)</td></tr>
<tr class="memdesc:ga9a1968c384ec7abb6122830253ebf570"><td class="mdescLeft">&#160;</td><td class="mdescRight">Compress a 12-bit-per-sample packed-pixel RGB, grayscale, or CMYK image into a 12-bit-per-sample JPEG image. <br /></td></tr>
<tr class="memdesc:ga9a1968c384ec7abb6122830253ebf570"><td class="mdescLeft">&#160;</td><td class="mdescRight">Compress a packed-pixel RGB, grayscale, or CMYK image with 9 to 12 bits of data precision per sample into a JPEG image with the same data precision. <br /></td></tr>
<tr class="separator:ga9a1968c384ec7abb6122830253ebf570"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga77901b71d0471784f318ada31ff4e7bd" id="r_ga77901b71d0471784f318ada31ff4e7bd"><td class="memItemLeft" align="right" valign="top">DLLEXPORT int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga77901b71d0471784f318ada31ff4e7bd">tj3Compress16</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle, const unsigned short *srcBuf, int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf, size_t *jpegSize)</td></tr>
<tr class="memdesc:ga77901b71d0471784f318ada31ff4e7bd"><td class="mdescLeft">&#160;</td><td class="mdescRight">Compress a 16-bit-per-sample packed-pixel RGB, grayscale, or CMYK image into a 16-bit-per-sample lossless JPEG image. <br /></td></tr>
<tr class="memdesc:ga77901b71d0471784f318ada31ff4e7bd"><td class="mdescLeft">&#160;</td><td class="mdescRight">Compress a packed-pixel RGB, grayscale, or CMYK image with 13 to 16 bits of data precision per sample into a lossless JPEG image with the same data precision. <br /></td></tr>
<tr class="separator:ga77901b71d0471784f318ada31ff4e7bd"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga041c870d9c669eb3f385c78f4346c43f" id="r_ga041c870d9c669eb3f385c78f4346c43f"><td class="memItemLeft" align="right" valign="top">DLLEXPORT int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga041c870d9c669eb3f385c78f4346c43f">tj3CompressFromYUV8</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle, const unsigned char *srcBuf, int width, int align, int height, unsigned char **jpegBuf, size_t *jpegSize)</td></tr>
<tr class="memdesc:ga041c870d9c669eb3f385c78f4346c43f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Compress an 8-bit-per-sample unified planar YUV image into an 8-bit-per-sample JPEG image. <br /></td></tr>
@@ -326,13 +326,13 @@ Functions</h2></td></tr>
<tr class="memdesc:gaa49c7bd4c9431667a043cfc93388ba1c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Set the cropping region for partially decompressing a lossy JPEG image into a packed-pixel image. <br /></td></tr>
<tr class="separator:gaa49c7bd4c9431667a043cfc93388ba1c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga1169c7c1a26ec18c9e6122cb8ae64013" id="r_ga1169c7c1a26ec18c9e6122cb8ae64013"><td class="memItemLeft" align="right" valign="top">DLLEXPORT int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga1169c7c1a26ec18c9e6122cb8ae64013">tj3Decompress8</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle, const unsigned char *jpegBuf, size_t jpegSize, unsigned char *dstBuf, int pitch, int pixelFormat)</td></tr>
<tr class="memdesc:ga1169c7c1a26ec18c9e6122cb8ae64013"><td class="mdescLeft">&#160;</td><td class="mdescRight">Decompress an 8-bit-per-sample JPEG image into an 8-bit-per-sample packed-pixel RGB, grayscale, or CMYK image. <br /></td></tr>
<tr class="memdesc:ga1169c7c1a26ec18c9e6122cb8ae64013"><td class="mdescLeft">&#160;</td><td class="mdescRight">Decompress a JPEG image with 2 to 8 bits of data precision per sample into a packed-pixel RGB, grayscale, or CMYK image with the same data precision. <br /></td></tr>
<tr class="separator:ga1169c7c1a26ec18c9e6122cb8ae64013"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga39b848f01781ad74a5b3941c012b6199" id="r_ga39b848f01781ad74a5b3941c012b6199"><td class="memItemLeft" align="right" valign="top">DLLEXPORT int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga39b848f01781ad74a5b3941c012b6199">tj3Decompress12</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle, const unsigned char *jpegBuf, size_t jpegSize, short *dstBuf, int pitch, int pixelFormat)</td></tr>
<tr class="memdesc:ga39b848f01781ad74a5b3941c012b6199"><td class="mdescLeft">&#160;</td><td class="mdescRight">Decompress a 12-bit-per-sample JPEG image into a 12-bit-per-sample packed-pixel RGB, grayscale, or CMYK image. <br /></td></tr>
<tr class="memdesc:ga39b848f01781ad74a5b3941c012b6199"><td class="mdescLeft">&#160;</td><td class="mdescRight">Decompress a JPEG image with 9 to 12 bits of data precision per sample into a packed-pixel RGB, grayscale, or CMYK image with the same data precision. <br /></td></tr>
<tr class="separator:ga39b848f01781ad74a5b3941c012b6199"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaa074e63f9beb0b3ff42b833a4049df6e" id="r_gaa074e63f9beb0b3ff42b833a4049df6e"><td class="memItemLeft" align="right" valign="top">DLLEXPORT int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#gaa074e63f9beb0b3ff42b833a4049df6e">tj3Decompress16</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle, const unsigned char *jpegBuf, size_t jpegSize, unsigned short *dstBuf, int pitch, int pixelFormat)</td></tr>
<tr class="memdesc:gaa074e63f9beb0b3ff42b833a4049df6e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Decompress a 16-bit-per-sample lossless JPEG image into a 16-bit-per-sample packed-pixel RGB, grayscale, or CMYK image. <br /></td></tr>
<tr class="memdesc:gaa074e63f9beb0b3ff42b833a4049df6e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Decompress a lossless JPEG image with 13 to 16 bits of data precision per sample into a packed-pixel RGB, grayscale, or CMYK image with the same data precision. <br /></td></tr>
<tr class="separator:gaa074e63f9beb0b3ff42b833a4049df6e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga1e6bf6a19fec3f9fa7534348879d8320" id="r_ga1e6bf6a19fec3f9fa7534348879d8320"><td class="memItemLeft" align="right" valign="top">DLLEXPORT int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga1e6bf6a19fec3f9fa7534348879d8320">tj3DecompressToYUV8</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle, const unsigned char *jpegBuf, size_t jpegSize, unsigned char *dstBuf, int align)</td></tr>
<tr class="memdesc:ga1e6bf6a19fec3f9fa7534348879d8320"><td class="mdescLeft">&#160;</td><td class="mdescRight">Decompress an 8-bit-per-sample JPEG image into an 8-bit-per-sample unified planar YUV image. <br /></td></tr>
@@ -356,22 +356,22 @@ Functions</h2></td></tr>
<tr class="memdesc:ga1a2c96d8b47530b6e6050ba6f10b7c57"><td class="mdescLeft">&#160;</td><td class="mdescRight">Allocate a byte buffer for use with TurboJPEG. <br /></td></tr>
<tr class="separator:ga1a2c96d8b47530b6e6050ba6f10b7c57"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga884023536e70985616126a073f662001" id="r_ga884023536e70985616126a073f662001"><td class="memItemLeft" align="right" valign="top">DLLEXPORT unsigned char *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga884023536e70985616126a073f662001">tj3LoadImage8</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle, const char *filename, int *width, int align, int *height, int *pixelFormat)</td></tr>
<tr class="memdesc:ga884023536e70985616126a073f662001"><td class="mdescLeft">&#160;</td><td class="mdescRight">Load an 8-bit-per-sample packed-pixel image from disk into memory. <br /></td></tr>
<tr class="memdesc:ga884023536e70985616126a073f662001"><td class="mdescLeft">&#160;</td><td class="mdescRight">Load a packed-pixel image with 2 to 8 bits of data precision per sample from disk into memory. <br /></td></tr>
<tr class="separator:ga884023536e70985616126a073f662001"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaa1d3772cfdb53afa21aae3c606238d44" id="r_gaa1d3772cfdb53afa21aae3c606238d44"><td class="memItemLeft" align="right" valign="top">DLLEXPORT short *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#gaa1d3772cfdb53afa21aae3c606238d44">tj3LoadImage12</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle, const char *filename, int *width, int align, int *height, int *pixelFormat)</td></tr>
<tr class="memdesc:gaa1d3772cfdb53afa21aae3c606238d44"><td class="mdescLeft">&#160;</td><td class="mdescRight">Load a 12-bit-per-sample packed-pixel image from disk into memory. <br /></td></tr>
<tr class="memdesc:gaa1d3772cfdb53afa21aae3c606238d44"><td class="mdescLeft">&#160;</td><td class="mdescRight">Load a packed-pixel image with 9 to 12 bits of data precision per sample from disk into memory. <br /></td></tr>
<tr class="separator:gaa1d3772cfdb53afa21aae3c606238d44"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gace4240b665dc47742cbb3b76b03dfd69" id="r_gace4240b665dc47742cbb3b76b03dfd69"><td class="memItemLeft" align="right" valign="top">DLLEXPORT unsigned short *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#gace4240b665dc47742cbb3b76b03dfd69">tj3LoadImage16</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle, const char *filename, int *width, int align, int *height, int *pixelFormat)</td></tr>
<tr class="memdesc:gace4240b665dc47742cbb3b76b03dfd69"><td class="mdescLeft">&#160;</td><td class="mdescRight">Load a 16-bit-per-sample packed-pixel image from disk into memory. <br /></td></tr>
<tr class="memdesc:gace4240b665dc47742cbb3b76b03dfd69"><td class="mdescLeft">&#160;</td><td class="mdescRight">Load a packed-pixel image with 13 to 16 bits of data precision per sample from disk into memory. <br /></td></tr>
<tr class="separator:gace4240b665dc47742cbb3b76b03dfd69"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaa4ec838988e469cc15618e4690cc8722" id="r_gaa4ec838988e469cc15618e4690cc8722"><td class="memItemLeft" align="right" valign="top">DLLEXPORT int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#gaa4ec838988e469cc15618e4690cc8722">tj3SaveImage8</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle, const char *filename, const unsigned char *buffer, int width, int pitch, int height, int pixelFormat)</td></tr>
<tr class="memdesc:gaa4ec838988e469cc15618e4690cc8722"><td class="mdescLeft">&#160;</td><td class="mdescRight">Save an 8-bit-per-sample packed-pixel image from memory to disk. <br /></td></tr>
<tr class="memdesc:gaa4ec838988e469cc15618e4690cc8722"><td class="mdescLeft">&#160;</td><td class="mdescRight">Save a packed-pixel image with 2 to 8 bits of data precision per sample from memory to disk. <br /></td></tr>
<tr class="separator:gaa4ec838988e469cc15618e4690cc8722"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga7c64b5106d04267a46aad85f9714ad90" id="r_ga7c64b5106d04267a46aad85f9714ad90"><td class="memItemLeft" align="right" valign="top">DLLEXPORT int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga7c64b5106d04267a46aad85f9714ad90">tj3SaveImage12</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle, const char *filename, const short *buffer, int width, int pitch, int height, int pixelFormat)</td></tr>
<tr class="memdesc:ga7c64b5106d04267a46aad85f9714ad90"><td class="mdescLeft">&#160;</td><td class="mdescRight">Save a 12-bit-per-sample packed-pixel image from memory to disk. <br /></td></tr>
<tr class="memdesc:ga7c64b5106d04267a46aad85f9714ad90"><td class="mdescLeft">&#160;</td><td class="mdescRight">Save a packed-pixel image with 9 to 12 bits of data precision per sample from memory to disk. <br /></td></tr>
<tr class="separator:ga7c64b5106d04267a46aad85f9714ad90"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga0fd87851f4266aca24bf4594dd0c0e71" id="r_ga0fd87851f4266aca24bf4594dd0c0e71"><td class="memItemLeft" align="right" valign="top">DLLEXPORT int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga0fd87851f4266aca24bf4594dd0c0e71">tj3SaveImage16</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle, const char *filename, const unsigned short *buffer, int width, int pitch, int height, int pixelFormat)</td></tr>
<tr class="memdesc:ga0fd87851f4266aca24bf4594dd0c0e71"><td class="mdescLeft">&#160;</td><td class="mdescRight">Save a 16-bit-per-sample packed-pixel image from memory to disk. <br /></td></tr>
<tr class="memdesc:ga0fd87851f4266aca24bf4594dd0c0e71"><td class="mdescLeft">&#160;</td><td class="mdescRight">Save a packed-pixel image with 13 to 16 bits of data precision per sample from memory to disk. <br /></td></tr>
<tr class="separator:ga0fd87851f4266aca24bf4594dd0c0e71"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaddb84fb6c81769e9faa0f5a63b296606" id="r_gaddb84fb6c81769e9faa0f5a63b296606"><td class="memItemLeft" align="right" valign="top">DLLEXPORT void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#gaddb84fb6c81769e9faa0f5a63b296606">tj3Free</a> (void *buffer)</td></tr>
<tr class="memdesc:gaddb84fb6c81769e9faa0f5a63b296606"><td class="mdescLeft">&#160;</td><td class="mdescRight">Free a byte buffer previously allocated by TurboJPEG. <br /></td></tr>
@@ -861,12 +861,13 @@ scalingFactor)</code>. </p>
</td></tr>
<tr><td class="fieldname"><a id="ggaa0f6be63ba78278299c9f5c12031fe82a8f76673be73f2b659440a9572a65a95f" name="ggaa0f6be63ba78278299c9f5c12031fe82a8f76673be73f2b659440a9572a65a95f"></a>TJPARAM_JPEGHEIGHT&#160;</td><td class="fielddoc"><p>JPEG height (in pixels) [decompression only, read-only]. </p>
</td></tr>
<tr><td class="fieldname"><a id="ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" name="ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8"></a>TJPARAM_PRECISION&#160;</td><td class="fielddoc"><p>JPEG data precision (bits per sample) [decompression only, read-only]. </p>
<p>The JPEG image uses the specified number of bits per sample.</p>
<tr><td class="fieldname"><a id="ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" name="ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8"></a>TJPARAM_PRECISION&#160;</td><td class="fielddoc"><p>Data precision (bits per sample) </p>
<p>The JPEG image uses (decompression) or will use (lossless compression) the specified number of bits per sample. This parameter also specifies the target data precision when loading a PBMPLUS file with <a class="el" href="group___turbo_j_p_e_g.html#ga884023536e70985616126a073f662001" title="Load a packed-pixel image with 2 to 8 bits of data precision per sample from disk into memory.">tj3LoadImage8()</a>, <a class="el" href="group___turbo_j_p_e_g.html#gaa1d3772cfdb53afa21aae3c606238d44" title="Load a packed-pixel image with 9 to 12 bits of data precision per sample from disk into memory.">tj3LoadImage12()</a>, or <a class="el" href="group___turbo_j_p_e_g.html#gace4240b665dc47742cbb3b76b03dfd69" title="Load a packed-pixel image with 13 to 16 bits of data precision per sample from disk into memory.">tj3LoadImage16()</a> and the source data precision when saving a PBMPLUS file with <a class="el" href="group___turbo_j_p_e_g.html#gaa4ec838988e469cc15618e4690cc8722" title="Save a packed-pixel image with 2 to 8 bits of data precision per sample from memory to disk.">tj3SaveImage8()</a>, <a class="el" href="group___turbo_j_p_e_g.html#ga7c64b5106d04267a46aad85f9714ad90" title="Save a packed-pixel image with 9 to 12 bits of data precision per sample from memory to disk.">tj3SaveImage12()</a>, or <a class="el" href="group___turbo_j_p_e_g.html#ga0fd87851f4266aca24bf4594dd0c0e71" title="Save a packed-pixel image with 13 to 16 bits of data precision per sample from memory to disk.">tj3SaveImage16()</a>.</p>
<p>The data precision is the number of bits in the maximum sample value, which may not be the same as the width of the data type used to store the sample.</p>
<p><b>Value</b></p><ul>
<li><code>8</code>, <code>12</code>, or <code>16</code></li>
<li><code>8</code> or <code>12</code> for lossy JPEG images; <code>2</code> to <code>16</code> for lossless JPEG and PBMPLUS images</li>
</ul>
<p>12-bit data precision implies <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a8f0af9afc0b36443751f9ee82b760aa6" title="Optimized baseline entropy coding [lossy compression only].">TJPARAM_OPTIMIZE</a> unless <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a1c756757384308145602c040524aebf7" title="Arithmetic entropy coding.">TJPARAM_ARITHMETIC</a> is set. </p>
<p>12-bit JPEG data precision implies <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a8f0af9afc0b36443751f9ee82b760aa6" title="Optimized baseline entropy coding [lossy compression only].">TJPARAM_OPTIMIZE</a> unless <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a1c756757384308145602c040524aebf7" title="Arithmetic entropy coding.">TJPARAM_ARITHMETIC</a> is set. </p>
</td></tr>
<tr><td class="fieldname"><a id="ggaa0f6be63ba78278299c9f5c12031fe82a46a10d46309514907d0c39fcd86c324c" name="ggaa0f6be63ba78278299c9f5c12031fe82a46a10d46309514907d0c39fcd86c324c"></a>TJPARAM_COLORSPACE&#160;</td><td class="fielddoc"><p>JPEG colorspace. </p>
<p>The JPEG image uses (decompression) or will use (lossy compression) the specified colorspace.</p>
@@ -969,7 +970,7 @@ scalingFactor)</code>. </p>
<li><code>0</code> through <em><b>precision</b></em> <em>- 1</em>, where <em><b>precision</b></em> is the JPEG data precision in bits <em>[default for compression: <code>0</code>]</em></li>
</ul>
<p>A point transform value of <code>0</code> is necessary in order to generate a fully lossless JPEG image. (A non-zero point transform value right-shifts the input samples by the specified number of bits, which is effectively a form of lossy color quantization.)</p>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a249f35f0770792b19f995e603bb17c6f" title="Lossless JPEG.">TJPARAM_LOSSLESS</a>, <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="JPEG data precision (bits per sample) [decompression only, read-only].">TJPARAM_PRECISION</a> </dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a249f35f0770792b19f995e603bb17c6f" title="Lossless JPEG.">TJPARAM_LOSSLESS</a>, <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> </dd></dl>
</td></tr>
<tr><td class="fieldname"><a id="ggaa0f6be63ba78278299c9f5c12031fe82a343c72883b7160f23f3ef46fc548a0ec" name="ggaa0f6be63ba78278299c9f5c12031fe82a343c72883b7160f23f3ef46fc548a0ec"></a>TJPARAM_RESTARTBLOCKS&#160;</td><td class="fielddoc"><p>JPEG restart marker interval in MCU blocks (lossy) or samples (lossless) [compression only]. </p>
<p>The nature of entropy coding is such that a corrupt JPEG image cannot be decompressed beyond the point of corruption unless it contains restart markers. A restart marker stops and restarts the entropy coding algorithm so that, if a JPEG image is corrupted, decompression can resume at the next marker. Thus, adding more restart markers improves the fault tolerance of the JPEG image, but adding too many restart markers can adversely affect the compression ratio and performance.</p>
@@ -989,14 +990,14 @@ scalingFactor)</code>. </p>
<p><b>Value</b></p><ul>
<li>The JPEG image has (decompression) or will have (compression) the specified horizontal pixel density <em>[default for compression: <code>1</code>]</em>.</li>
</ul>
<p>This value is stored in or read from the JPEG header. It does not affect the contents of the JPEG image. Note that this parameter is set by <a class="el" href="group___turbo_j_p_e_g.html#ga884023536e70985616126a073f662001" title="Load an 8-bit-per-sample packed-pixel image from disk into memory.">tj3LoadImage8()</a> when loading a Windows BMP file that contains pixel density information, and the value of this parameter is stored to a Windows BMP file by <a class="el" href="group___turbo_j_p_e_g.html#gaa4ec838988e469cc15618e4690cc8722" title="Save an 8-bit-per-sample packed-pixel image from memory to disk.">tj3SaveImage8()</a> if the value of <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a4c045981bd8a303521a401dbbe1df208" title="JPEG pixel density units.">TJPARAM_DENSITYUNITS</a> is <code>2</code>.</p>
<p>This value is stored in or read from the JPEG header. It does not affect the contents of the JPEG image. Note that this parameter is set by <a class="el" href="group___turbo_j_p_e_g.html#ga884023536e70985616126a073f662001" title="Load a packed-pixel image with 2 to 8 bits of data precision per sample from disk into memory.">tj3LoadImage8()</a> when loading a Windows BMP file that contains pixel density information, and the value of this parameter is stored to a Windows BMP file by <a class="el" href="group___turbo_j_p_e_g.html#gaa4ec838988e469cc15618e4690cc8722" title="Save a packed-pixel image with 2 to 8 bits of data precision per sample from memory to disk.">tj3SaveImage8()</a> if the value of <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a4c045981bd8a303521a401dbbe1df208" title="JPEG pixel density units.">TJPARAM_DENSITYUNITS</a> is <code>2</code>.</p>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a4c045981bd8a303521a401dbbe1df208" title="JPEG pixel density units.">TJPARAM_DENSITYUNITS</a> </dd></dl>
</td></tr>
<tr><td class="fieldname"><a id="ggaa0f6be63ba78278299c9f5c12031fe82abda48f2df7eb9b88e2b7621efb017eba" name="ggaa0f6be63ba78278299c9f5c12031fe82abda48f2df7eb9b88e2b7621efb017eba"></a>TJPARAM_YDENSITY&#160;</td><td class="fielddoc"><p>JPEG vertical pixel density. </p>
<p><b>Value</b></p><ul>
<li>The JPEG image has (decompression) or will have (compression) the specified vertical pixel density <em>[default for compression: <code>1</code>]</em>.</li>
</ul>
<p>This value is stored in or read from the JPEG header. It does not affect the contents of the JPEG image. Note that this parameter is set by <a class="el" href="group___turbo_j_p_e_g.html#ga884023536e70985616126a073f662001" title="Load an 8-bit-per-sample packed-pixel image from disk into memory.">tj3LoadImage8()</a> when loading a Windows BMP file that contains pixel density information, and the value of this parameter is stored to a Windows BMP file by <a class="el" href="group___turbo_j_p_e_g.html#gaa4ec838988e469cc15618e4690cc8722" title="Save an 8-bit-per-sample packed-pixel image from memory to disk.">tj3SaveImage8()</a> if the value of <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a4c045981bd8a303521a401dbbe1df208" title="JPEG pixel density units.">TJPARAM_DENSITYUNITS</a> is <code>2</code>.</p>
<p>This value is stored in or read from the JPEG header. It does not affect the contents of the JPEG image. Note that this parameter is set by <a class="el" href="group___turbo_j_p_e_g.html#ga884023536e70985616126a073f662001" title="Load a packed-pixel image with 2 to 8 bits of data precision per sample from disk into memory.">tj3LoadImage8()</a> when loading a Windows BMP file that contains pixel density information, and the value of this parameter is stored to a Windows BMP file by <a class="el" href="group___turbo_j_p_e_g.html#gaa4ec838988e469cc15618e4690cc8722" title="Save a packed-pixel image with 2 to 8 bits of data precision per sample from memory to disk.">tj3SaveImage8()</a> if the value of <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a4c045981bd8a303521a401dbbe1df208" title="JPEG pixel density units.">TJPARAM_DENSITYUNITS</a> is <code>2</code>.</p>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a4c045981bd8a303521a401dbbe1df208" title="JPEG pixel density units.">TJPARAM_DENSITYUNITS</a> </dd></dl>
</td></tr>
<tr><td class="fieldname"><a id="ggaa0f6be63ba78278299c9f5c12031fe82a4c045981bd8a303521a401dbbe1df208" name="ggaa0f6be63ba78278299c9f5c12031fe82a4c045981bd8a303521a401dbbe1df208"></a>TJPARAM_DENSITYUNITS&#160;</td><td class="fielddoc"><p>JPEG pixel density units. </p>
@@ -1005,7 +1006,7 @@ scalingFactor)</code>. </p>
<li><code>1</code> The pixel density of the JPEG image is expressed (decompression) or will be expressed (compression) in units of pixels/inch.</li>
<li><code>2</code> The pixel density of the JPEG image is expressed (decompression) or will be expressed (compression) in units of pixels/cm.</li>
</ul>
<p>This value is stored in or read from the JPEG header. It does not affect the contents of the JPEG image. Note that this parameter is set by <a class="el" href="group___turbo_j_p_e_g.html#ga884023536e70985616126a073f662001" title="Load an 8-bit-per-sample packed-pixel image from disk into memory.">tj3LoadImage8()</a> when loading a Windows BMP file that contains pixel density information, and the value of this parameter is stored to a Windows BMP file by <a class="el" href="group___turbo_j_p_e_g.html#gaa4ec838988e469cc15618e4690cc8722" title="Save an 8-bit-per-sample packed-pixel image from memory to disk.">tj3SaveImage8()</a> if the value is <code>2</code>.</p>
<p>This value is stored in or read from the JPEG header. It does not affect the contents of the JPEG image. Note that this parameter is set by <a class="el" href="group___turbo_j_p_e_g.html#ga884023536e70985616126a073f662001" title="Load a packed-pixel image with 2 to 8 bits of data precision per sample from disk into memory.">tj3LoadImage8()</a> when loading a Windows BMP file that contains pixel density information, and the value of this parameter is stored to a Windows BMP file by <a class="el" href="group___turbo_j_p_e_g.html#gaa4ec838988e469cc15618e4690cc8722" title="Save a packed-pixel image with 2 to 8 bits of data precision per sample from memory to disk.">tj3SaveImage8()</a> if the value is <code>2</code>.</p>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a4de5c9d7cab5be806143a43c3b0e0877" title="JPEG horizontal pixel density.">TJPARAM_XDENSITY</a>, <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82abda48f2df7eb9b88e2b7621efb017eba" title="JPEG vertical pixel density.">TJPARAM_YDENSITY</a> </dd></dl>
</td></tr>
<tr><td class="fieldname"><a id="ggaa0f6be63ba78278299c9f5c12031fe82a0de0a8281da45d1fc984edc8918f7dd2" name="ggaa0f6be63ba78278299c9f5c12031fe82a0de0a8281da45d1fc984edc8918f7dd2"></a>TJPARAM_MAXMEMORY&#160;</td><td class="fielddoc"><p>Memory limit for intermediate buffers. </p>
@@ -1056,7 +1057,7 @@ scalingFactor)</code>. </p>
<p>The red, green, and blue components in the image are stored in 4-sample pixels in the order B, G, R from highest to lowest memory address within each pixel. The X component is ignored when compressing and undefined when decompressing. </p>
</td></tr>
<tr><td class="fieldname"><a id="ggac916144e26c3817ac514e64ae5d12e2aa5431b54b015337705f13118073711a1a" name="ggac916144e26c3817ac514e64ae5d12e2aa5431b54b015337705f13118073711a1a"></a>TJPF_GRAY&#160;</td><td class="fielddoc"><p>Grayscale pixel format. </p>
<p>Each 1-sample pixel represents a luminance (brightness) level from 0 to the maximum sample value (255 for 8-bit samples, 4095 for 12-bit samples, and 65535 for 16-bit samples.) </p>
<p>Each 1-sample pixel represents a luminance (brightness) level from 0 to the maximum sample value (which is, for instance, 255 for 8-bit samples or 4095 for 12-bit samples or 65535 for 16-bit samples.) </p>
</td></tr>
<tr><td class="fieldname"><a id="ggac916144e26c3817ac514e64ae5d12e2aa88d2e88fab67f6503cf972e14851cc12" name="ggac916144e26c3817ac514e64ae5d12e2aa88d2e88fab67f6503cf972e14851cc12"></a>TJPF_RGBA&#160;</td><td class="fielddoc"><p>RGBA pixel format. </p>
<p>This is the same as <a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa83973bebb7e2dc6fa8bae89ff3f42e01">TJPF_RGBX</a>, except that when decompressing, the X component is guaranteed to be equal to the maximum sample value, which can be interpreted as an opaque alpha channel. </p>
@@ -1074,7 +1075,7 @@ scalingFactor)</code>. </p>
<p>Unlike RGB, which is an additive color model used primarily for display, CMYK (Cyan/Magenta/Yellow/Key) is a subtractive color model used primarily for printing. In the CMYK color model, the value of each color component typically corresponds to an amount of cyan, magenta, yellow, or black ink that is applied to a white background. In order to convert between CMYK and RGB, it is necessary to use a color management system (CMS.) A CMS will attempt to map colors within the printer's gamut to perceptually similar colors in the display's gamut and vice versa, but the mapping is typically not 1:1 or reversible, nor can it be defined with a simple formula. Thus, such a conversion is out of scope for a codec library. However, the TurboJPEG API allows for compressing packed-pixel CMYK images into YCCK JPEG images (see <a class="el" href="group___turbo_j_p_e_g.html#gga4f83ad3368e0e29d1957be0efa7c3720a53839e0fe867b76b58d16b0a1a7c598e" title="YCCK colorspace.">TJCS_YCCK</a>) and decompressing YCCK JPEG images into packed-pixel CMYK images. </p>
</td></tr>
<tr><td class="fieldname"><a id="ggac916144e26c3817ac514e64ae5d12e2aa84c1a6cead7952998e2fb895844a21ed" name="ggac916144e26c3817ac514e64ae5d12e2aa84c1a6cead7952998e2fb895844a21ed"></a>TJPF_UNKNOWN&#160;</td><td class="fielddoc"><p>Unknown pixel format. </p>
<p>Currently this is only used by <a class="el" href="group___turbo_j_p_e_g.html#ga884023536e70985616126a073f662001" title="Load an 8-bit-per-sample packed-pixel image from disk into memory.">tj3LoadImage8()</a>, <a class="el" href="group___turbo_j_p_e_g.html#gaa1d3772cfdb53afa21aae3c606238d44" title="Load a 12-bit-per-sample packed-pixel image from disk into memory.">tj3LoadImage12()</a>, and <a class="el" href="group___turbo_j_p_e_g.html#gace4240b665dc47742cbb3b76b03dfd69" title="Load a 16-bit-per-sample packed-pixel image from disk into memory.">tj3LoadImage16()</a>. </p>
<p>Currently this is only used by <a class="el" href="group___turbo_j_p_e_g.html#ga884023536e70985616126a073f662001" title="Load a packed-pixel image with 2 to 8 bits of data precision per sample from disk into memory.">tj3LoadImage8()</a>, <a class="el" href="group___turbo_j_p_e_g.html#gaa1d3772cfdb53afa21aae3c606238d44" title="Load a packed-pixel image with 9 to 12 bits of data precision per sample from disk into memory.">tj3LoadImage12()</a>, and <a class="el" href="group___turbo_j_p_e_g.html#gace4240b665dc47742cbb3b76b03dfd69" title="Load a packed-pixel image with 13 to 16 bits of data precision per sample from disk into memory.">tj3LoadImage16()</a>. </p>
</td></tr>
</table>
@@ -1261,11 +1262,11 @@ scalingFactor)</code>. </p>
</table>
</div><div class="memdoc">
<p>Compress a 12-bit-per-sample packed-pixel RGB, grayscale, or CMYK image into a 12-bit-per-sample JPEG image. </p>
<p>Compress a packed-pixel RGB, grayscale, or CMYK image with 9 to 12 bits of data precision per sample into a JPEG image with the same data precision. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">handle</td><td>handle to a TurboJPEG instance that has been initialized for compression</td></tr>
<tr><td class="paramname">srcBuf</td><td>pointer to a buffer containing a packed-pixel RGB, grayscale, or CMYK source image to be compressed. This buffer should normally be <code>pitch * height</code> samples in size. However, you can also use this parameter to compress from a specific region of a larger buffer.</td></tr>
<tr><td class="paramname">srcBuf</td><td>pointer to a buffer containing a packed-pixel RGB, grayscale, or CMYK source image to be compressed. This buffer should normally be <code>pitch * height</code> samples in size. However, you can also use this parameter to compress from a specific region of a larger buffer. The data precision of the source image (from 9 to 12 bits per sample) can be specified using <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> and defaults to 12 if <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> is unset or out of range.</td></tr>
<tr><td class="paramname">width</td><td>width (in pixels) of the source image</td></tr>
<tr><td class="paramname">pitch</td><td>samples per row in the source image. Normally this should be <code>width * <a class="el" href="group___turbo_j_p_e_g.html#gad77cf8fe5b2bfd3cb3f53098146abb4c" title="Pixel size (in samples) for a given pixel format.">tjPixelSize</a>[pixelFormat]</code>, if the image is unpadded. (Setting this parameter to 0 is the equivalent of setting it to <code>width * <a class="el" href="group___turbo_j_p_e_g.html#gad77cf8fe5b2bfd3cb3f53098146abb4c" title="Pixel size (in samples) for a given pixel format.">tjPixelSize</a>[pixelFormat]</code>.) However, you can also use this parameter to specify the row alignment/padding of the source image, to skip rows, or to compress from a specific region of a larger buffer.</td></tr>
<tr><td class="paramname">height</td><td>height (in pixels) of the source image</td></tr>
@@ -1280,7 +1281,7 @@ If you choose option 1, then <code>*jpegSize</code> should be set to the size of
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga5a23ad0776c5333cda0d7c6d826e9d29" title="Returns a descriptive error message explaining why the last command failed.">tj3GetErrorStr()</a> and <a class="el" href="group___turbo_j_p_e_g.html#gab8c8279f1415fe425ff30dbbc56013bd" title="Returns a code indicating the severity of the last error.">tj3GetErrorCode()</a>.) </dd></dl>
<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga5a23ad0776c5333cda0d7c6d826e9d29" title="Returns a descriptive error message explaining why the last command failed.">tj3GetErrorStr()</a> and <a class="el" href="group___turbo_j_p_e_g.html#gab8c8279f1415fe425ff30dbbc56013bd" title="Returns a code indicating the severity of the last error.">tj3GetErrorCode()</a>.) </dd></dl>
</div>
</div>
@@ -1346,11 +1347,11 @@ If you choose option 1, then <code>*jpegSize</code> should be set to the size of
</table>
</div><div class="memdoc">
<p>Compress a 16-bit-per-sample packed-pixel RGB, grayscale, or CMYK image into a 16-bit-per-sample lossless JPEG image. </p>
<p>Compress a packed-pixel RGB, grayscale, or CMYK image with 13 to 16 bits of data precision per sample into a lossless JPEG image with the same data precision. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">handle</td><td>handle to a TurboJPEG instance that has been initialized for compression</td></tr>
<tr><td class="paramname">srcBuf</td><td>pointer to a buffer containing a packed-pixel RGB, grayscale, or CMYK source image to be compressed. This buffer should normally be <code>pitch * height</code> samples in size. However, you can also use this parameter to compress from a specific region of a larger buffer.</td></tr>
<tr><td class="paramname">srcBuf</td><td>pointer to a buffer containing a packed-pixel RGB, grayscale, or CMYK source image to be compressed. This buffer should normally be <code>pitch * height</code> samples in size. However, you can also use this parameter to compress from a specific region of a larger buffer. The data precision of the source image (from 13 to 16 bits per sample) can be specified using <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> and defaults to 16 if <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> is unset or out of range.</td></tr>
<tr><td class="paramname">width</td><td>width (in pixels) of the source image</td></tr>
<tr><td class="paramname">pitch</td><td>samples per row in the source image. Normally this should be <code>width * <a class="el" href="group___turbo_j_p_e_g.html#gad77cf8fe5b2bfd3cb3f53098146abb4c" title="Pixel size (in samples) for a given pixel format.">tjPixelSize</a>[pixelFormat]</code>, if the image is unpadded. (Setting this parameter to 0 is the equivalent of setting it to <code>width * <a class="el" href="group___turbo_j_p_e_g.html#gad77cf8fe5b2bfd3cb3f53098146abb4c" title="Pixel size (in samples) for a given pixel format.">tjPixelSize</a>[pixelFormat]</code>.) However, you can also use this parameter to specify the row alignment/padding of the source image, to skip rows, or to compress from a specific region of a larger buffer.</td></tr>
<tr><td class="paramname">height</td><td>height (in pixels) of the source image</td></tr>
@@ -1365,7 +1366,7 @@ If you choose option 1, then <code>*jpegSize</code> should be set to the size of
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga5a23ad0776c5333cda0d7c6d826e9d29" title="Returns a descriptive error message explaining why the last command failed.">tj3GetErrorStr()</a> and <a class="el" href="group___turbo_j_p_e_g.html#gab8c8279f1415fe425ff30dbbc56013bd" title="Returns a code indicating the severity of the last error.">tj3GetErrorCode()</a>.) </dd></dl>
<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga5a23ad0776c5333cda0d7c6d826e9d29" title="Returns a descriptive error message explaining why the last command failed.">tj3GetErrorStr()</a> and <a class="el" href="group___turbo_j_p_e_g.html#gab8c8279f1415fe425ff30dbbc56013bd" title="Returns a code indicating the severity of the last error.">tj3GetErrorCode()</a>.) </dd></dl>
</div>
</div>
@@ -1431,11 +1432,11 @@ If you choose option 1, then <code>*jpegSize</code> should be set to the size of
</table>
</div><div class="memdoc">
<p>Compress an 8-bit-per-sample packed-pixel RGB, grayscale, or CMYK image into an 8-bit-per-sample JPEG image. </p>
<p>Compress a packed-pixel RGB, grayscale, or CMYK image with 2 to 8 bits of data precision per sample into a JPEG image with the same data precision. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">handle</td><td>handle to a TurboJPEG instance that has been initialized for compression</td></tr>
<tr><td class="paramname">srcBuf</td><td>pointer to a buffer containing a packed-pixel RGB, grayscale, or CMYK source image to be compressed. This buffer should normally be <code>pitch * height</code> samples in size. However, you can also use this parameter to compress from a specific region of a larger buffer.</td></tr>
<tr><td class="paramname">srcBuf</td><td>pointer to a buffer containing a packed-pixel RGB, grayscale, or CMYK source image to be compressed. This buffer should normally be <code>pitch * height</code> samples in size. However, you can also use this parameter to compress from a specific region of a larger buffer. The data precision of the source image (from 2 to 8 bits per sample) can be specified using <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> and defaults to 8 if <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> is unset or out of range.</td></tr>
<tr><td class="paramname">width</td><td>width (in pixels) of the source image</td></tr>
<tr><td class="paramname">pitch</td><td>samples per row in the source image. Normally this should be <code>width * <a class="el" href="group___turbo_j_p_e_g.html#gad77cf8fe5b2bfd3cb3f53098146abb4c" title="Pixel size (in samples) for a given pixel format.">tjPixelSize</a>[pixelFormat]</code>, if the image is unpadded. (Setting this parameter to 0 is the equivalent of setting it to <code>width * <a class="el" href="group___turbo_j_p_e_g.html#gad77cf8fe5b2bfd3cb3f53098146abb4c" title="Pixel size (in samples) for a given pixel format.">tjPixelSize</a>[pixelFormat]</code>.) However, you can also use this parameter to specify the row alignment/padding of the source image, to skip rows, or to compress from a specific region of a larger buffer.</td></tr>
<tr><td class="paramname">height</td><td>height (in pixels) of the source image</td></tr>
@@ -1822,7 +1823,7 @@ If you choose option 1, then <code>*jpegSize</code> should be set to the size of
</table>
</div><div class="memdoc">
<p>Decompress a 12-bit-per-sample JPEG image into a 12-bit-per-sample packed-pixel RGB, grayscale, or CMYK image. </p>
<p>Decompress a JPEG image with 9 to 12 bits of data precision per sample into a packed-pixel RGB, grayscale, or CMYK image with the same data precision. </p>
<p>The <a class="el" href="group___turbo_j_p_e_g.html#gaa0f6be63ba78278299c9f5c12031fe82">parameters</a> that describe the JPEG image will be set when this function returns.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
@@ -1889,7 +1890,7 @@ If you choose option 1, then <code>*jpegSize</code> should be set to the size of
</table>
</div><div class="memdoc">
<p>Decompress a 16-bit-per-sample lossless JPEG image into a 16-bit-per-sample packed-pixel RGB, grayscale, or CMYK image. </p>
<p>Decompress a lossless JPEG image with 13 to 16 bits of data precision per sample into a packed-pixel RGB, grayscale, or CMYK image with the same data precision. </p>
<p>The <a class="el" href="group___turbo_j_p_e_g.html#gaa0f6be63ba78278299c9f5c12031fe82">parameters</a> that describe the JPEG image will be set when this function returns.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
@@ -1956,7 +1957,7 @@ If you choose option 1, then <code>*jpegSize</code> should be set to the size of
</table>
</div><div class="memdoc">
<p>Decompress an 8-bit-per-sample JPEG image into an 8-bit-per-sample packed-pixel RGB, grayscale, or CMYK image. </p>
<p>Decompress a JPEG image with 2 to 8 bits of data precision per sample into a packed-pixel RGB, grayscale, or CMYK image with the same data precision. </p>
<p>The <a class="el" href="group___turbo_j_p_e_g.html#gaa0f6be63ba78278299c9f5c12031fe82">parameters</a> that describe the JPEG image will be set when this function returns.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
@@ -2598,17 +2599,17 @@ If you choose option 1, then <code>*jpegSize</code> should be set to the size of
</table>
</div><div class="memdoc">
<p>Load a 12-bit-per-sample packed-pixel image from disk into memory. </p>
<p>Load a packed-pixel image with 9 to 12 bits of data precision per sample from disk into memory. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">handle</td><td>handle to a TurboJPEG instance</td></tr>
<tr><td class="paramname">filename</td><td>name of a file containing a packed-pixel image in Windows BMP or PBMPLUS (PPM/PGM) format. Windows BMP files require 8-bit-per-sample data precision. If the data precision of the PBMPLUS file does not match the target data precision, then upconverting or downconverting will be performed.</td></tr>
<tr><td class="paramname">filename</td><td>name of a file containing a packed-pixel image in PBMPLUS (PPM/PGM) format. The target data precision (from 9 to 12 bits per sample) can be specified using <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> and defaults to 12 if <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> is unset or out of range. If the data precision of the PBMPLUS file does not match the target data precision, then upconverting or downconverting will be performed.</td></tr>
<tr><td class="paramname">width</td><td>pointer to an integer variable that will receive the width (in pixels) of the packed-pixel image</td></tr>
<tr><td class="paramname">align</td><td>row alignment (in samples) of the packed-pixel buffer to be returned (must be a power of 2.) Setting this parameter to n will cause all rows in the buffer to be padded to the nearest multiple of n samples (1 = unpadded.)</td></tr>
<tr><td class="paramname">height</td><td>pointer to an integer variable that will receive the height (in pixels) of the packed-pixel image</td></tr>
<tr><td class="paramname">pixelFormat</td><td>pointer to an integer variable that specifies or will receive the pixel format of the packed-pixel buffer. The behavior of this function will vary depending on the value of <code>*pixelFormat</code> passed to the function:<ul>
<li><a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa84c1a6cead7952998e2fb895844a21ed">TJPF_UNKNOWN</a> : The packed-pixel buffer returned by this function will use the most optimal pixel format for the file type, and <code>*pixelFormat</code> will contain the ID of that pixel format upon successful return from this function.</li>
<li><a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa5431b54b015337705f13118073711a1a">TJPF_GRAY</a> : Only PGM files and 8-bit-per-pixel BMP files with a grayscale colormap can be loaded.</li>
<li><a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa5431b54b015337705f13118073711a1a">TJPF_GRAY</a> : Only PGM files can be loaded.</li>
<li><a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa7f5100ec44c91994e243f1cf55553f8b">TJPF_CMYK</a> : The RGB or grayscale pixels stored in the file will be converted using a quick &amp; dirty algorithm that is suitable only for testing purposes. (Proper conversion between CMYK and other formats requires a color management system.)</li>
<li>Other <a class="el" href="group___turbo_j_p_e_g.html#gac916144e26c3817ac514e64ae5d12e2a">pixel formats</a> : The packed-pixel buffer will use the specified pixel format, and pixel format conversion will be performed if necessary.</li>
</ul>
@@ -2616,7 +2617,7 @@ If you choose option 1, then <code>*jpegSize</code> should be set to the size of
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a pointer to a newly-allocated buffer containing the packed-pixel image, converted to the chosen pixel format and with the chosen row alignment, or NULL if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga5a23ad0776c5333cda0d7c6d826e9d29" title="Returns a descriptive error message explaining why the last command failed.">tj3GetErrorStr()</a>.) This buffer should be freed using <a class="el" href="group___turbo_j_p_e_g.html#gaddb84fb6c81769e9faa0f5a63b296606" title="Free a byte buffer previously allocated by TurboJPEG.">tj3Free()</a>. </dd></dl>
<dl class="section return"><dt>Returns</dt><dd>a pointer to a newly-allocated buffer containing the packed-pixel image, converted to the chosen pixel format and with the chosen row alignment, or NULL if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga5a23ad0776c5333cda0d7c6d826e9d29" title="Returns a descriptive error message explaining why the last command failed.">tj3GetErrorStr()</a>.) This buffer should be freed using <a class="el" href="group___turbo_j_p_e_g.html#gaddb84fb6c81769e9faa0f5a63b296606" title="Free a byte buffer previously allocated by TurboJPEG.">tj3Free()</a>. </dd></dl>
</div>
</div>
@@ -2670,17 +2671,17 @@ If you choose option 1, then <code>*jpegSize</code> should be set to the size of
</table>
</div><div class="memdoc">
<p>Load a 16-bit-per-sample packed-pixel image from disk into memory. </p>
<p>Load a packed-pixel image with 13 to 16 bits of data precision per sample from disk into memory. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">handle</td><td>handle to a TurboJPEG instance</td></tr>
<tr><td class="paramname">filename</td><td>name of a file containing a packed-pixel image in Windows BMP or PBMPLUS (PPM/PGM) format. Windows BMP files require 8-bit-per-sample data precision. If the data precision of the PBMPLUS file does not match the target data precision, then upconverting or downconverting will be performed.</td></tr>
<tr><td class="paramname">filename</td><td>name of a file containing a packed-pixel image in PBMPLUS (PPM/PGM) format. The target data precision (from 13 to 16 bits per sample) can be specified using <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> and defaults to 16 if <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> is unset or out of range. If the data precision of the PBMPLUS file does not match the target data precision, then upconverting or downconverting will be performed.</td></tr>
<tr><td class="paramname">width</td><td>pointer to an integer variable that will receive the width (in pixels) of the packed-pixel image</td></tr>
<tr><td class="paramname">align</td><td>row alignment (in samples) of the packed-pixel buffer to be returned (must be a power of 2.) Setting this parameter to n will cause all rows in the buffer to be padded to the nearest multiple of n samples (1 = unpadded.)</td></tr>
<tr><td class="paramname">height</td><td>pointer to an integer variable that will receive the height (in pixels) of the packed-pixel image</td></tr>
<tr><td class="paramname">pixelFormat</td><td>pointer to an integer variable that specifies or will receive the pixel format of the packed-pixel buffer. The behavior of this function will vary depending on the value of <code>*pixelFormat</code> passed to the function:<ul>
<li><a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa84c1a6cead7952998e2fb895844a21ed">TJPF_UNKNOWN</a> : The packed-pixel buffer returned by this function will use the most optimal pixel format for the file type, and <code>*pixelFormat</code> will contain the ID of that pixel format upon successful return from this function.</li>
<li><a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa5431b54b015337705f13118073711a1a">TJPF_GRAY</a> : Only PGM files and 8-bit-per-pixel BMP files with a grayscale colormap can be loaded.</li>
<li><a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa5431b54b015337705f13118073711a1a">TJPF_GRAY</a> : Only PGM files can be loaded.</li>
<li><a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa7f5100ec44c91994e243f1cf55553f8b">TJPF_CMYK</a> : The RGB or grayscale pixels stored in the file will be converted using a quick &amp; dirty algorithm that is suitable only for testing purposes. (Proper conversion between CMYK and other formats requires a color management system.)</li>
<li>Other <a class="el" href="group___turbo_j_p_e_g.html#gac916144e26c3817ac514e64ae5d12e2a">pixel formats</a> : The packed-pixel buffer will use the specified pixel format, and pixel format conversion will be performed if necessary.</li>
</ul>
@@ -2688,7 +2689,7 @@ If you choose option 1, then <code>*jpegSize</code> should be set to the size of
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a pointer to a newly-allocated buffer containing the packed-pixel image, converted to the chosen pixel format and with the chosen row alignment, or NULL if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga5a23ad0776c5333cda0d7c6d826e9d29" title="Returns a descriptive error message explaining why the last command failed.">tj3GetErrorStr()</a>.) This buffer should be freed using <a class="el" href="group___turbo_j_p_e_g.html#gaddb84fb6c81769e9faa0f5a63b296606" title="Free a byte buffer previously allocated by TurboJPEG.">tj3Free()</a>. </dd></dl>
<dl class="section return"><dt>Returns</dt><dd>a pointer to a newly-allocated buffer containing the packed-pixel image, converted to the chosen pixel format and with the chosen row alignment, or NULL if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga5a23ad0776c5333cda0d7c6d826e9d29" title="Returns a descriptive error message explaining why the last command failed.">tj3GetErrorStr()</a>.) This buffer should be freed using <a class="el" href="group___turbo_j_p_e_g.html#gaddb84fb6c81769e9faa0f5a63b296606" title="Free a byte buffer previously allocated by TurboJPEG.">tj3Free()</a>. </dd></dl>
</div>
</div>
@@ -2742,11 +2743,11 @@ If you choose option 1, then <code>*jpegSize</code> should be set to the size of
</table>
</div><div class="memdoc">
<p>Load an 8-bit-per-sample packed-pixel image from disk into memory. </p>
<p>Load a packed-pixel image with 2 to 8 bits of data precision per sample from disk into memory. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">handle</td><td>handle to a TurboJPEG instance</td></tr>
<tr><td class="paramname">filename</td><td>name of a file containing a packed-pixel image in Windows BMP or PBMPLUS (PPM/PGM) format. Windows BMP files require 8-bit-per-sample data precision. If the data precision of the PBMPLUS file does not match the target data precision, then upconverting or downconverting will be performed.</td></tr>
<tr><td class="paramname">filename</td><td>name of a file containing a packed-pixel image in Windows BMP or PBMPLUS (PPM/PGM) format. Windows BMP files require 8-bit-per-sample data precision. When loading a PBMPLUS file, the target data precision (from 2 to 8 bits per sample) can be specified using <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> and defaults to 8 if <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> is unset or out of range. If the data precision of the PBMPLUS file does not match the target data precision, then upconverting or downconverting will be performed.</td></tr>
<tr><td class="paramname">width</td><td>pointer to an integer variable that will receive the width (in pixels) of the packed-pixel image</td></tr>
<tr><td class="paramname">align</td><td>row alignment (in samples) of the packed-pixel buffer to be returned (must be a power of 2.) Setting this parameter to n will cause all rows in the buffer to be padded to the nearest multiple of n samples (1 = unpadded.)</td></tr>
<tr><td class="paramname">height</td><td>pointer to an integer variable that will receive the height (in pixels) of the packed-pixel image</td></tr>
@@ -2820,20 +2821,20 @@ If you choose option 1, then <code>*jpegSize</code> should be set to the size of
</table>
</div><div class="memdoc">
<p>Save a 12-bit-per-sample packed-pixel image from memory to disk. </p>
<p>Save a packed-pixel image with 9 to 12 bits of data precision per sample from memory to disk. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">handle</td><td>handle to a TurboJPEG instance</td></tr>
<tr><td class="paramname">filename</td><td>name of a file to which to save the packed-pixel image. The image will be stored in Windows BMP or PBMPLUS (PPM/PGM) format, depending on the file extension. Windows BMP files require 8-bit-per-sample data precision.</td></tr>
<tr><td class="paramname">filename</td><td>name of a file to which to save the packed-pixel image, which will be stored in PBMPLUS (PPM/PGM) format. The source data precision (from 9 to 12 bits per sample) can be specified using <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> and defaults to 12 if <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> is unset or out of range.</td></tr>
<tr><td class="paramname">buffer</td><td>pointer to a buffer containing a packed-pixel RGB, grayscale, or CMYK image to be saved</td></tr>
<tr><td class="paramname">width</td><td>width (in pixels) of the packed-pixel image</td></tr>
<tr><td class="paramname">pitch</td><td>samples per row in the packed-pixel image. Setting this parameter to 0 is the equivalent of setting it to <code>width * <a class="el" href="group___turbo_j_p_e_g.html#gad77cf8fe5b2bfd3cb3f53098146abb4c" title="Pixel size (in samples) for a given pixel format.">tjPixelSize</a>[pixelFormat]</code>.</td></tr>
<tr><td class="paramname">height</td><td>height (in pixels) of the packed-pixel image</td></tr>
<tr><td class="paramname">pixelFormat</td><td>pixel format of the packed-pixel image (see <a class="el" href="group___turbo_j_p_e_g.html#gac916144e26c3817ac514e64ae5d12e2a">Pixel formats</a>.) If this parameter is set to <a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa5431b54b015337705f13118073711a1a">TJPF_GRAY</a>, then the image will be stored in PGM or 8-bit-per-pixel (indexed color) BMP format. Otherwise, the image will be stored in PPM or 24-bit-per-pixel BMP format. If this parameter is set to <a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa7f5100ec44c91994e243f1cf55553f8b">TJPF_CMYK</a>, then the CMYK pixels will be converted to RGB using a quick &amp; dirty algorithm that is suitable only for testing purposes. (Proper conversion between CMYK and other formats requires a color management system.)</td></tr>
<tr><td class="paramname">pixelFormat</td><td>pixel format of the packed-pixel image (see <a class="el" href="group___turbo_j_p_e_g.html#gac916144e26c3817ac514e64ae5d12e2a">Pixel formats</a>.) If this parameter is set to <a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa5431b54b015337705f13118073711a1a">TJPF_GRAY</a>, then the image will be stored in PGM format. Otherwise, the image will be stored in PPM format. If this parameter is set to <a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa7f5100ec44c91994e243f1cf55553f8b">TJPF_CMYK</a>, then the CMYK pixels will be converted to RGB using a quick &amp; dirty algorithm that is suitable only for testing purposes. (Proper conversion between CMYK and other formats requires a color management system.)</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga5a23ad0776c5333cda0d7c6d826e9d29" title="Returns a descriptive error message explaining why the last command failed.">tj3GetErrorStr()</a>.) </dd></dl>
<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga5a23ad0776c5333cda0d7c6d826e9d29" title="Returns a descriptive error message explaining why the last command failed.">tj3GetErrorStr()</a>.) </dd></dl>
</div>
</div>
@@ -2893,20 +2894,20 @@ If you choose option 1, then <code>*jpegSize</code> should be set to the size of
</table>
</div><div class="memdoc">
<p>Save a 16-bit-per-sample packed-pixel image from memory to disk. </p>
<p>Save a packed-pixel image with 13 to 16 bits of data precision per sample from memory to disk. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">handle</td><td>handle to a TurboJPEG instance</td></tr>
<tr><td class="paramname">filename</td><td>name of a file to which to save the packed-pixel image. The image will be stored in Windows BMP or PBMPLUS (PPM/PGM) format, depending on the file extension. Windows BMP files require 8-bit-per-sample data precision.</td></tr>
<tr><td class="paramname">filename</td><td>name of a file to which to save the packed-pixel image, which will be stored in PBMPLUS (PPM/PGM) format. The source data precision (from 13 to 16 bits per sample) can be specified using <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> and defaults to 16 if <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> is unset or out of range.</td></tr>
<tr><td class="paramname">buffer</td><td>pointer to a buffer containing a packed-pixel RGB, grayscale, or CMYK image to be saved</td></tr>
<tr><td class="paramname">width</td><td>width (in pixels) of the packed-pixel image</td></tr>
<tr><td class="paramname">pitch</td><td>samples per row in the packed-pixel image. Setting this parameter to 0 is the equivalent of setting it to <code>width * <a class="el" href="group___turbo_j_p_e_g.html#gad77cf8fe5b2bfd3cb3f53098146abb4c" title="Pixel size (in samples) for a given pixel format.">tjPixelSize</a>[pixelFormat]</code>.</td></tr>
<tr><td class="paramname">height</td><td>height (in pixels) of the packed-pixel image</td></tr>
<tr><td class="paramname">pixelFormat</td><td>pixel format of the packed-pixel image (see <a class="el" href="group___turbo_j_p_e_g.html#gac916144e26c3817ac514e64ae5d12e2a">Pixel formats</a>.) If this parameter is set to <a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa5431b54b015337705f13118073711a1a">TJPF_GRAY</a>, then the image will be stored in PGM or 8-bit-per-pixel (indexed color) BMP format. Otherwise, the image will be stored in PPM or 24-bit-per-pixel BMP format. If this parameter is set to <a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa7f5100ec44c91994e243f1cf55553f8b">TJPF_CMYK</a>, then the CMYK pixels will be converted to RGB using a quick &amp; dirty algorithm that is suitable only for testing purposes. (Proper conversion between CMYK and other formats requires a color management system.)</td></tr>
<tr><td class="paramname">pixelFormat</td><td>pixel format of the packed-pixel image (see <a class="el" href="group___turbo_j_p_e_g.html#gac916144e26c3817ac514e64ae5d12e2a">Pixel formats</a>.) If this parameter is set to <a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa5431b54b015337705f13118073711a1a">TJPF_GRAY</a>, then the image will be stored in PGM format. Otherwise, the image will be stored in PPM format. If this parameter is set to <a class="el" href="group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa7f5100ec44c91994e243f1cf55553f8b">TJPF_CMYK</a>, then the CMYK pixels will be converted to RGB using a quick &amp; dirty algorithm that is suitable only for testing purposes. (Proper conversion between CMYK and other formats requires a color management system.)</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga5a23ad0776c5333cda0d7c6d826e9d29" title="Returns a descriptive error message explaining why the last command failed.">tj3GetErrorStr()</a>.) </dd></dl>
<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga5a23ad0776c5333cda0d7c6d826e9d29" title="Returns a descriptive error message explaining why the last command failed.">tj3GetErrorStr()</a>.) </dd></dl>
</div>
</div>
@@ -2966,11 +2967,11 @@ If you choose option 1, then <code>*jpegSize</code> should be set to the size of
</table>
</div><div class="memdoc">
<p>Save an 8-bit-per-sample packed-pixel image from memory to disk. </p>
<p>Save a packed-pixel image with 2 to 8 bits of data precision per sample from memory to disk. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">handle</td><td>handle to a TurboJPEG instance</td></tr>
<tr><td class="paramname">filename</td><td>name of a file to which to save the packed-pixel image. The image will be stored in Windows BMP or PBMPLUS (PPM/PGM) format, depending on the file extension. Windows BMP files require 8-bit-per-sample data precision.</td></tr>
<tr><td class="paramname">filename</td><td>name of a file to which to save the packed-pixel image. The image will be stored in Windows BMP or PBMPLUS (PPM/PGM) format, depending on the file extension. Windows BMP files require 8-bit-per-sample data precision. When saving a PBMPLUS file, the source data precision (from 2 to 8 bits per sample) can be specified using <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> and defaults to 8 if <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82a781db82741934e8cd008d308597c59d8" title="Data precision (bits per sample)">TJPARAM_PRECISION</a> is unset or out of range.</td></tr>
<tr><td class="paramname">buffer</td><td>pointer to a buffer containing a packed-pixel RGB, grayscale, or CMYK image to be saved</td></tr>
<tr><td class="paramname">width</td><td>width (in pixels) of the packed-pixel image</td></tr>
<tr><td class="paramname">pitch</td><td>samples per row in the packed-pixel image. Setting this parameter to 0 is the equivalent of setting it to <code>width * <a class="el" href="group___turbo_j_p_e_g.html#gad77cf8fe5b2bfd3cb3f53098146abb4c" title="Pixel size (in samples) for a given pixel format.">tjPixelSize</a>[pixelFormat]</code>.</td></tr>

View File

@@ -22,7 +22,7 @@
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.1</span>
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.2</span>
</div>
</td>
</tr>

View File

@@ -22,7 +22,7 @@
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.1</span>
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.2</span>
</div>
</td>
</tr>

View File

@@ -22,7 +22,7 @@
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.1</span>
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.2</span>
</div>
</td>
</tr>

View File

@@ -22,7 +22,7 @@
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.1</span>
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.2</span>
</div>
</td>
</tr>

View File

@@ -22,7 +22,7 @@
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.1</span>
<div id="projectname">TurboJPEG<span id="projectnumber">&#160;3.0.2</span>
</div>
</td>
</tr>

View File

@@ -167,7 +167,7 @@ file size is about the same --- often a little smaller.
Switches for advanced users:
-precision N Create JPEG file with N-bit data precision.
N is 8, 12, or 16; default is 8. If N is 16, then
N is 2 to 16; default is 8. If N is not 8 or 12, then
-lossless must also be specified. Note that only the
PBMPLUS input file format supports data precisions other
than 8. Note also that PBMPLUS input files are silently
@@ -175,10 +175,9 @@ Switches for advanced users:
than the precision of the input file. Passing an
argument of -verbose to cjpeg will cause it to print
information about the precision of the input file.
CAUTION: 12-bit and 16-bit data precision is not yet
widely implemented, so many decoders will be unable to
handle a 12-bit-per-sample or 16-bit-per-sample JPEG
file at all.
CAUTION: only 8-bit data precision is widely
implemented, so many decoders will be unable to handle
JPEG files with other data precisions.
"-precision 12" implies -optimize unless -arithmetic is
also specified.

View File

@@ -203,7 +203,7 @@ final class TJBench {
if (dstBuf == null) {
if ((long)pitch * (long)scaledh > (long)Integer.MAX_VALUE)
throw new Exception("Image is too large");
if (precision == 8)
if (precision <= 8)
dstBuf = new byte[pitch * scaledh];
else
dstBuf = new short[pitch * scaledh];
@@ -211,9 +211,9 @@ final class TJBench {
/* Set the destination buffer to gray so we know whether the decompressor
attempted to write to it */
if (precision == 8)
if (precision <= 8)
Arrays.fill((byte[])dstBuf, (byte)127);
else if (precision == 12)
else if (precision <= 12)
Arrays.fill((short[])dstBuf, (short)2047);
else
Arrays.fill((short[])dstBuf, (short)32767);
@@ -256,9 +256,9 @@ final class TJBench {
elapsedDecode += getTime() - startDecode;
} else {
try {
if (precision == 8)
if (precision <= 8)
tjd.decompress8((byte[])dstBuf, x, y, pitch, pf);
else if (precision == 12)
else if (precision <= 12)
tjd.decompress12((short[])dstBuf, x, y, pitch, pf);
else
tjd.decompress16((short[])dstBuf, x, y, pitch, pf);
@@ -344,7 +344,7 @@ final class TJBench {
if ((long)pitch * (long)h > (long)Integer.MAX_VALUE)
throw new Exception("Image is too large");
if (precision == 8)
if (precision <= 8)
tmpBuf = new byte[pitch * h];
else
tmpBuf = new short[pitch * h];
@@ -388,7 +388,7 @@ final class TJBench {
bottomUp ? "BU" : "TD", precision,
lossless ? "LOSSLS" : SUBNAME_LONG[subsamp],
jpegQual);
if (precision == 8) {
if (precision <= 8) {
for (i = 0; i < h; i++)
System.arraycopy((byte[])srcBuf, w * ps * i, (byte[])tmpBuf,
pitch * i, w * ps);
@@ -416,10 +416,10 @@ final class TJBench {
int width = Math.min(tilew, w - x);
int height = Math.min(tileh, h - y);
if (precision == 8)
if (precision <= 8)
tjc.setSourceImage((byte[])srcBuf, x, y, width, pitch, height,
pf);
else if (precision == 12)
else if (precision <= 12)
tjc.setSourceImage12((short[])srcBuf, x, y, width, pitch, height,
pf);
else
@@ -793,8 +793,8 @@ final class TJBench {
System.out.println(" [default = BGR]");
System.out.println("-cmyk = Indirectly test YCCK JPEG compression/decompression");
System.out.println(" (use the CMYK pixel format for packed-pixel source/destination buffers)");
System.out.println("-precision N = Use N-bit data precision when compressing [N is 8, 12, or 16;");
System.out.println(" default = 8; if N is 16, then -lossless must also be specified]");
System.out.println("-precision N = Use N-bit data precision when compressing [N=2..16; default = 8;");
System.out.println(" if N is not 8 or 12, then -lossless must also be specified]");
System.out.println(" (-precision 12 implies -optimize unless -arithmetic is also specified)");
System.out.println("-quiet = Output results in tabular rather than verbose format");
System.out.println("-restart N = When compressing, add a restart marker every N MCU rows (lossy) or");
@@ -915,7 +915,7 @@ final class TJBench {
try {
temp = Integer.parseInt(argv[++i]);
} catch (NumberFormatException e) {}
if (temp == 8 || temp == 12 || temp == 16)
if (temp >= 2 && temp <= 16)
precision = temp;
else
usage();
@@ -1142,8 +1142,9 @@ final class TJBench {
if (ext == null)
ext = new String("ppm");
if (precision == 16 && !lossless)
throw new Exception("-lossless must be specified along with -precision 16");
if ((precision != 8 && precision != 12) && !lossless)
throw new Exception(
"-lossless must be specified along with -precision " + precision);
if (precision != 8 && doYUV)
throw new Exception("-yuv requires 8-bit data precision");
if (lossless && doYUV)
@@ -1176,6 +1177,7 @@ final class TJBench {
tjc = new TJCompressor();
tjc.set(TJ.PARAM_STOPONWARNING, stopOnWarning ? 1 : 0);
tjc.set(TJ.PARAM_BOTTOMUP, bottomUp ? 1 : 0);
tjc.set(TJ.PARAM_PRECISION, precision);
tjc.set(TJ.PARAM_MAXPIXELS, maxPixels);
pixelFormat[0] = pf;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C)2011-2018, 2022-2023 D. R. Commander. All Rights Reserved.
* Copyright (C)2011-2018, 2022-2024 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:
@@ -52,8 +52,8 @@ final class TJUnitTest {
System.out.println(" (8-bit data precision only)");
System.out.println("-noyuvpad = do not pad each row in each Y, U, and V plane to the nearest");
System.out.println(" multiple of 4 bytes");
System.out.println("-precision N = test N-bit data precision (N is 8, 12, or 16; default is 8; if N");
System.out.println(" is 16, then -lossless is implied)");
System.out.println("-precision N = test N-bit data precision (N=2..16; default is 8; if N is not 8");
System.out.println(" or 12, then -lossless is implied)");
System.out.println("-lossless = test lossless JPEG compression/decompression");
System.out.println("-bi = test BufferedImage I/O (8-bit data precision only)\n");
System.exit(1);
@@ -151,14 +151,14 @@ final class TJUnitTest {
}
static void fillArray(Object buf, int val) {
if (precision == 8)
if (precision <= 8)
Arrays.fill((byte[])buf, (byte)val);
else
Arrays.fill((short[])buf, (short)val);
}
static void setVal(Object buf, int index, int value) {
if (precision == 8)
if (precision <= 8)
((byte[])buf)[index] = (byte)value;
else
((short[])buf)[index] = (short)value;
@@ -318,7 +318,7 @@ final class TJUnitTest {
static int getVal(Object buf, int index) {
int v;
if (precision == 8)
if (precision <= 8)
v = (int)(((byte[])buf)[index]);
else
v = (int)(((short[])buf)[index]);
@@ -686,14 +686,14 @@ final class TJUnitTest {
ImageIO.write(img, "png", file);
tjc.setSourceImage(img, 0, 0, 0, 0);
} else {
if (precision == 8)
if (precision <= 8)
srcBuf = new byte[w * h * ps + 1];
else
srcBuf = new short[w * h * ps + 1];
initBuf(srcBuf, w, w * ps, h, pf, bottomUp);
if (precision == 8)
if (precision <= 8)
tjc.setSourceImage((byte[])srcBuf, 0, 0, w, 0, h, pf);
else if (precision == 12)
else if (precision <= 12)
tjc.setSourceImage12((short[])srcBuf, 0, 0, w, 0, h, pf);
else
tjc.setSourceImage16((short[])srcBuf, 0, 0, w, 0, h, pf);
@@ -716,10 +716,11 @@ final class TJUnitTest {
buStrLong, jpegQual);
tjc.setSourceImage(yuvImage);
} else {
if (lossless)
if (lossless) {
tjc.set(TJ.PARAM_PRECISION, precision);
System.out.format("%s %s -> LOSSLESS PSV%d ... ", pfStrLong, buStrLong,
jpegPSV);
else
} else
System.out.format("%s %s -> %s Q%d ... ", pfStrLong, buStrLong,
SUBNAME_LONG[subsamp], jpegQual);
}
@@ -792,9 +793,9 @@ final class TJUnitTest {
if (bi)
img = tjd.decompress8(imgType);
else {
if (precision == 8)
if (precision <= 8)
dstBuf = tjd.decompress8(0, pf);
else if (precision == 12)
else if (precision <= 12)
dstBuf = tjd.decompress12(0, pf);
else
dstBuf = tjd.decompress16(0, pf);
@@ -956,6 +957,7 @@ final class TJUnitTest {
tjc = new TJCompressor();
if (lossless) {
tjc.set(TJ.PARAM_PRECISION, precision);
tjc.set(TJ.PARAM_LOSSLESS, 1);
tjc.set(TJ.PARAM_LOSSLESSPSV, ((psv++ - 1) % 7) + 1);
numSamp = 1;
@@ -1031,10 +1033,10 @@ final class TJUnitTest {
try {
tempi = Integer.parseInt(argv[++i]);
} catch (NumberFormatException e) {}
if (tempi != 8 && tempi != 12 && tempi != 16)
if (tempi < 2 || tempi > 16)
usage();
precision = tempi;
if (precision == 16)
if (precision != 8 && precision != 12)
lossless = true;
} else
usage();
@@ -1047,7 +1049,7 @@ final class TJUnitTest {
throw new Exception("BufferedImage support requires 8-bit data precision.");
System.out.format("Testing %d-bit precision\n", precision);
sampleSize = (precision == 8 ? 1 : 2);
sampleSize = (precision <= 8 ? 1 : 2);
maxSample = (1 << precision) - 1;
tolerance = (lossless ? 0 : (precision > 8 ? 2 : 1));
redToY = (19595 * maxSample) >> 16;

View File

@@ -217,35 +217,36 @@ $('.navPadding').css('padding-top', $('.fixedNav').css("height"));
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJDecompressor.html#decompress12(int,int)">decompress12(int, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>
<dd>
<div class="block">Decompress the 12-bit-per-sample JPEG source image associated with this
decompressor instance and return a buffer containing a 12-bit-per-sample
packed-pixel decompressed image.</div>
<div class="block">Decompress the JPEG source image with 9 to 12 bits per sample associated
with this decompressor instance and return a buffer containing a
packed-pixel decompressed image with the same data precision.</div>
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJDecompressor.html#decompress12(short%5B%5D,int,int,int,int)">decompress12(short[], int, int, int, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>
<dd>
<div class="block">Decompress the 12-bit-per-sample JPEG source image associated with this
decompressor instance and output a 12-bit-per-sample packed-pixel
grayscale, RGB, or CMYK image to the given destination buffer.</div>
<div class="block">Decompress the JPEG source image with 9 to 12 bits per sample associated
with this decompressor instance and output a packed-pixel grayscale, RGB,
or CMYK image with the same data precision to the given destination
buffer.</div>
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJDecompressor.html#decompress16(int,int)">decompress16(int, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>
<dd>
<div class="block">Decompress the 16-bit-per-sample JPEG source image associated with this
decompressor instance and return a buffer containing a 16-bit-per-sample
packed-pixel decompressed image.</div>
<div class="block">Decompress the JPEG source image with 13 to 16 bits per sample associated
with this decompressor instance and return a buffer containing a
packed-pixel decompressed image with the same data precision.</div>
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJDecompressor.html#decompress16(short%5B%5D,int,int,int,int)">decompress16(short[], int, int, int, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>
<dd>
<div class="block">Decompress the 16-bit-per-sample lossless JPEG source image associated
with this decompressor instance and output a 16-bit-per-sample
packed-pixel grayscale, RGB, or CMYK image to the given destination
<div class="block">Decompress the JPEG source image with 13 to 16 bits per sample associated
with this decompressor instance and output a packed-pixel grayscale, RGB,
or CMYK image with the same data precision to the given destination
buffer.</div>
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJDecompressor.html#decompress8(byte%5B%5D,int,int,int,int)">decompress8(byte[], int, int, int, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>
<dd>
<div class="block">Decompress the 8-bit-per-sample JPEG source image or decode the planar YUV
source image associated with this decompressor instance and output an
8-bit-per-sample packed-pixel grayscale, RGB, or CMYK image to the given
destination buffer.</div>
<div class="block">Decompress the JPEG source image with 2 to 8 bits per sample, or decode
the 8-bit-per-sample planar YUV source image, associated with this
decompressor instance and output a packed-pixel grayscale, RGB, or CMYK
image with the same data precision to the given destination buffer.</div>
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJDecompressor.html#decompress8(int)">decompress8(int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>
<dd>
@@ -263,9 +264,10 @@ $('.navPadding').css('padding-top', $('.fixedNav').css("height"));
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJDecompressor.html#decompress8(int,int)">decompress8(int, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>
<dd>
<div class="block">Decompress the 8-bit-per-sample JPEG source image or decode the planar YUV
source image associated with this decompressor instance and return a
buffer containing an 8-bit-per-sample packed-pixel decompressed image.</div>
<div class="block">Decompress the JPEG source image with 2 to 8 bits per sample, or decode
the 8-bit-per-sample planar YUV source image, associated with this
decompressor instance and return a buffer containing a packed-pixel
decompressed image with the same data precision.</div>
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJDecompressor.html#decompress8(java.awt.image.BufferedImage)">decompress8(BufferedImage)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>
<dd>
@@ -783,7 +785,7 @@ $('.navPadding').css('padding-top', $('.fixedNav').css("height"));
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJ.html#PARAM_PRECISION">PARAM_PRECISION</a></span> - Static variable in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg">TJ</a></dt>
<dd>
<div class="block">JPEG data precision (bits per sample) [decompression only, read-only]</div>
<div class="block">Data precision (bits per sample)</div>
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJ.html#PARAM_PROGRESSIVE">PARAM_PROGRESSIVE</a></span> - Static variable in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg">TJ</a></dt>
<dd>
@@ -963,8 +965,8 @@ $('.navPadding').css('padding-top', $('.fixedNav').css("height"));
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(byte%5B%5D,int,int,int,int,int,int)">setSourceImage(byte[], int, int, int, int, int, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</a></dt>
<dd>
<div class="block">Associate an 8-bit-per-sample packed-pixel RGB, grayscale, or CMYK source
image with this compressor instance.</div>
<div class="block">Associate a packed-pixel RGB, grayscale, or CMYK source image with 2 to 8
bits of data precision per sample with this compressor instance.</div>
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage(java.awt.image.BufferedImage,int,int,int,int)">setSourceImage(BufferedImage, int, int, int, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</a></dt>
<dd>
@@ -983,13 +985,13 @@ $('.navPadding').css('padding-top', $('.fixedNav').css("height"));
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage12(short%5B%5D,int,int,int,int,int,int)">setSourceImage12(short[], int, int, int, int, int, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</a></dt>
<dd>
<div class="block">Associate a 12-bit-per-sample packed-pixel RGB, grayscale, or CMYK source
image with this compressor instance.</div>
<div class="block">Associate a packed-pixel RGB, grayscale, or CMYK source image with 9 to 12
bits of data precision per sample with this compressor instance.</div>
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJCompressor.html#setSourceImage16(short%5B%5D,int,int,int,int,int,int)">setSourceImage16(short[], int, int, int, int, int, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</a></dt>
<dd>
<div class="block">Associate a 16-bit-per-sample packed-pixel RGB, grayscale, or CMYK source
image with this compressor instance.</div>
<div class="block">Associate a packed-pixel RGB, grayscale, or CMYK source image with 13 to
16 bits of data precision per sample with this compressor instance.</div>
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJCompressor.html#setSubsamp(int)">setSubsamp(int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</a></dt>
<dd>
@@ -1018,9 +1020,9 @@ $('.navPadding').css('padding-top', $('.fixedNav').css("height"));
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJCompressor.html#%3Cinit%3E(byte%5B%5D,int,int,int,int,int,int)">TJCompressor(byte[], int, int, int, int, int, int)</a></span> - Constructor for class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</a></dt>
<dd>
<div class="block">Create a TurboJPEG compressor instance and associate the 8-bit-per-sample
packed-pixel source image stored in <code>srcImage</code> with the newly
created instance.</div>
<div class="block">Create a TurboJPEG compressor instance and associate the packed-pixel
source image, stored in <code>srcImage</code> with 2 to 8 bits of data
precision per sample, with the newly created instance.</div>
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJCompressor.html#%3Cinit%3E(java.awt.image.BufferedImage,int,int,int,int)">TJCompressor(BufferedImage, int, int, int, int)</a></span> - Constructor for class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</a></dt>
<dd>

Binary file not shown.

View File

@@ -396,7 +396,7 @@ extends java.lang.Object</pre>
<td class="colFirst"><code>static int</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#PARAM_PRECISION">PARAM_PRECISION</a></span></code></th>
<td class="colLast">
<div class="block">JPEG data precision (bits per sample) [decompression only, read-only]</div>
<div class="block">Data precision (bits per sample)</div>
</td>
</tr>
<tr class="rowColor">
@@ -1053,8 +1053,9 @@ extends java.lang.Object</pre>
<h4>PF_GRAY</h4>
<pre>public static final&nbsp;int PF_GRAY</pre>
<div class="block">Grayscale pixel format. Each 1-sample pixel represents a luminance
(brightness) level from 0 to the maximum sample value (255 for 8-bit
samples, 4095 for 12-bit samples, and 65535 for 16-bit samples.)</div>
(brightness) level from 0 to the maximum sample value (which is, for
instance, 255 for 8-bit samples or 4095 for 12-bit samples or 65535 for
16-bit samples.)</div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../constant-values.html#org.libjpegturbo.turbojpeg.TJ.PF_GRAY">Constant Field Values</a></dd>
@@ -1400,16 +1401,22 @@ extends java.lang.Object</pre>
<li class="blockList">
<h4>PARAM_PRECISION</h4>
<pre>public static final&nbsp;int PARAM_PRECISION</pre>
<div class="block">JPEG data precision (bits per sample) [decompression only, read-only]
<div class="block">Data precision (bits per sample)
<p>The JPEG image uses the specified number of bits per sample.
<p>The JPEG image uses (decompression) or will use (lossless compression)
the specified number of bits per sample.
<p>The data precision is the number of bits in the maximum sample value,
which may not be the same as the width of the data type used to store the
sample.
<p><b>Value</b>
<ul>
<li> <code>8</code>, <code>12</code>, or <code>16</code>
<li> <code>8</code> or <code>12</code> for lossy JPEG images;
<code>2</code> to <code>16</code> for lossless JPEG images
</ul>
<p>12-bit data precision implies <a href="#PARAM_OPTIMIZE"><code>PARAM_OPTIMIZE</code></a> unless
<p>12-bit JPEG data precision implies <a href="#PARAM_OPTIMIZE"><code>PARAM_OPTIMIZE</code></a> unless
<a href="#PARAM_ARITHMETIC"><code>PARAM_ARITHMETIC</code></a> is set.</div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>

View File

@@ -172,9 +172,9 @@ implements java.io.Closeable</pre>
int&nbsp;height,
int&nbsp;pixelFormat)</code></th>
<td class="colLast">
<div class="block">Create a TurboJPEG compressor instance and associate the 8-bit-per-sample
packed-pixel source image stored in <code>srcImage</code> with the newly
created instance.</div>
<div class="block">Create a TurboJPEG compressor instance and associate the packed-pixel
source image, stored in <code>srcImage</code> with 2 to 8 bits of data
precision per sample, with the newly created instance.</div>
</td>
</tr>
<tr class="altColor">
@@ -357,8 +357,8 @@ implements java.io.Closeable</pre>
int&nbsp;height,
int&nbsp;pixelFormat)</code></th>
<td class="colLast">
<div class="block">Associate an 8-bit-per-sample packed-pixel RGB, grayscale, or CMYK source
image with this compressor instance.</div>
<div class="block">Associate a packed-pixel RGB, grayscale, or CMYK source image with 2 to 8
bits of data precision per sample with this compressor instance.</div>
</td>
</tr>
<tr id="i17" class="rowColor">
@@ -391,8 +391,8 @@ implements java.io.Closeable</pre>
int&nbsp;height,
int&nbsp;pixelFormat)</code></th>
<td class="colLast">
<div class="block">Associate a 12-bit-per-sample packed-pixel RGB, grayscale, or CMYK source
image with this compressor instance.</div>
<div class="block">Associate a packed-pixel RGB, grayscale, or CMYK source image with 9 to 12
bits of data precision per sample with this compressor instance.</div>
</td>
</tr>
<tr id="i20" class="altColor">
@@ -405,8 +405,8 @@ implements java.io.Closeable</pre>
int&nbsp;height,
int&nbsp;pixelFormat)</code></th>
<td class="colLast">
<div class="block">Associate a 16-bit-per-sample packed-pixel RGB, grayscale, or CMYK source
image with this compressor instance.</div>
<div class="block">Associate a packed-pixel RGB, grayscale, or CMYK source image with 13 to
16 bits of data precision per sample with this compressor instance.</div>
</td>
</tr>
<tr id="i21" class="rowColor">
@@ -472,9 +472,9 @@ implements java.io.Closeable</pre>
int&nbsp;height,
int&nbsp;pixelFormat)
throws <a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Create a TurboJPEG compressor instance and associate the 8-bit-per-sample
packed-pixel source image stored in <code>srcImage</code> with the newly
created instance.</div>
<div class="block">Create a TurboJPEG compressor instance and associate the packed-pixel
source image, stored in <code>srcImage</code> with 2 to 8 bits of data
precision per sample, with the newly created instance.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>srcImage</code> - see <a href="#setSourceImage(byte%5B%5D,int,int,int,int,int,int)"><code>setSourceImage(byte[], int, int, int, int, int, int)</code></a> for description</dd>
@@ -546,12 +546,17 @@ implements java.io.Closeable</pre>
int&nbsp;height,
int&nbsp;pixelFormat)
throws <a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Associate an 8-bit-per-sample packed-pixel RGB, grayscale, or CMYK source
image with this compressor instance.</div>
<div class="block">Associate a packed-pixel RGB, grayscale, or CMYK source image with 2 to 8
bits of data precision per sample with this compressor instance. Note
that packed-pixel source images with 2 to 7 bits of data precision per
sample can only be compressed into lossless JPEG images.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>srcImage</code> - buffer containing a packed-pixel RGB, grayscale, or CMYK
source image to be compressed or encoded. This buffer is not modified.</dd>
source image to be compressed or encoded. The data precision of the
source image (from 2 to 8 bits per sample) can be specified using
<a href="TJ.html#PARAM_PRECISION"><code>TJ.PARAM_PRECISION</code></a> and defaults to 8 if <a href="TJ.html#PARAM_PRECISION"><code>TJ.PARAM_PRECISION</code></a>
is unset or out of range. This buffer is not modified.</dd>
<dd><code>x</code> - x offset (in pixels) of the region in the source image from which
the JPEG or YUV image should be compressed/encoded</dd>
<dd><code>y</code> - y offset (in pixels) of the region in the source image from which
@@ -589,14 +594,18 @@ implements java.io.Closeable</pre>
int&nbsp;height,
int&nbsp;pixelFormat)
throws <a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Associate a 12-bit-per-sample packed-pixel RGB, grayscale, or CMYK source
image with this compressor instance. Note that 12-bit-per-sample
packed-pixel source images can only be compressed into 12-bit-per-sample
JPEG images.</div>
<div class="block">Associate a packed-pixel RGB, grayscale, or CMYK source image with 9 to 12
bits of data precision per sample with this compressor instance. Note
that packed-pixel source images with 9 to 11 bits of data precision per
sample can only be compressed into lossless JPEG images.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>srcImage</code> - buffer containing a packed-pixel RGB, grayscale, or CMYK
source image to be compressed. This buffer is not modified.</dd>
source image to be compressed. The data precision of the source image
(from 9 to 12 bits per sample) can be specified using
<a href="TJ.html#PARAM_PRECISION"><code>TJ.PARAM_PRECISION</code></a> and defaults to 12 if
<a href="TJ.html#PARAM_PRECISION"><code>TJ.PARAM_PRECISION</code></a> is unset or out of range. This buffer is not
modified.</dd>
<dd><code>x</code> - x offset (in pixels) of the region in the source image from which
the JPEG image should be compressed</dd>
<dd><code>y</code> - y offset (in pixels) of the region in the source image from which
@@ -634,14 +643,18 @@ implements java.io.Closeable</pre>
int&nbsp;height,
int&nbsp;pixelFormat)
throws <a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Associate a 16-bit-per-sample packed-pixel RGB, grayscale, or CMYK source
image with this compressor instance. Note that 16-bit-per-sample
packed-pixel source images can only be compressed into 16-bit-per-sample
lossless JPEG images.</div>
<div class="block">Associate a packed-pixel RGB, grayscale, or CMYK source image with 13 to
16 bits of data precision per sample with this compressor instance. Note
that packed-pixel source images with 13 to 16 bits of data precision per
sample can only be compressed into lossless JPEG images.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>srcImage</code> - buffer containing a packed-pixel RGB, grayscale, or CMYK
source image to be compressed. This buffer is not modified.</dd>
source image to be compressed. The data precision of the source image
(from 13 to 16 bits per sample) can be specified using
<a href="TJ.html#PARAM_PRECISION"><code>TJ.PARAM_PRECISION</code></a> and defaults to 16 if
<a href="TJ.html#PARAM_PRECISION"><code>TJ.PARAM_PRECISION</code></a> is unset or out of range. This buffer is not
modified.</dd>
<dd><code>x</code> - x offset (in pixels) of the region in the source image from which
the JPEG image should be compressed</dd>
<dd><code>y</code> - y offset (in pixels) of the region in the source image from which

View File

@@ -295,9 +295,9 @@ implements java.io.Closeable</pre>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#decompress12(int,int)">decompress12</a></span>&#8203;(int&nbsp;pitch,
int&nbsp;pixelFormat)</code></th>
<td class="colLast">
<div class="block">Decompress the 12-bit-per-sample JPEG source image associated with this
decompressor instance and return a buffer containing a 12-bit-per-sample
packed-pixel decompressed image.</div>
<div class="block">Decompress the JPEG source image with 9 to 12 bits per sample associated
with this decompressor instance and return a buffer containing a
packed-pixel decompressed image with the same data precision.</div>
</td>
</tr>
<tr id="i7" class="rowColor">
@@ -308,9 +308,10 @@ implements java.io.Closeable</pre>
int&nbsp;pitch,
int&nbsp;pixelFormat)</code></th>
<td class="colLast">
<div class="block">Decompress the 12-bit-per-sample JPEG source image associated with this
decompressor instance and output a 12-bit-per-sample packed-pixel
grayscale, RGB, or CMYK image to the given destination buffer.</div>
<div class="block">Decompress the JPEG source image with 9 to 12 bits per sample associated
with this decompressor instance and output a packed-pixel grayscale, RGB,
or CMYK image with the same data precision to the given destination
buffer.</div>
</td>
</tr>
<tr id="i8" class="altColor">
@@ -318,9 +319,9 @@ implements java.io.Closeable</pre>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#decompress16(int,int)">decompress16</a></span>&#8203;(int&nbsp;pitch,
int&nbsp;pixelFormat)</code></th>
<td class="colLast">
<div class="block">Decompress the 16-bit-per-sample JPEG source image associated with this
decompressor instance and return a buffer containing a 16-bit-per-sample
packed-pixel decompressed image.</div>
<div class="block">Decompress the JPEG source image with 13 to 16 bits per sample associated
with this decompressor instance and return a buffer containing a
packed-pixel decompressed image with the same data precision.</div>
</td>
</tr>
<tr id="i9" class="rowColor">
@@ -331,9 +332,9 @@ implements java.io.Closeable</pre>
int&nbsp;pitch,
int&nbsp;pixelFormat)</code></th>
<td class="colLast">
<div class="block">Decompress the 16-bit-per-sample lossless JPEG source image associated
with this decompressor instance and output a 16-bit-per-sample
packed-pixel grayscale, RGB, or CMYK image to the given destination
<div class="block">Decompress the JPEG source image with 13 to 16 bits per sample associated
with this decompressor instance and output a packed-pixel grayscale, RGB,
or CMYK image with the same data precision to the given destination
buffer.</div>
</td>
</tr>
@@ -345,10 +346,10 @@ implements java.io.Closeable</pre>
int&nbsp;pitch,
int&nbsp;pixelFormat)</code></th>
<td class="colLast">
<div class="block">Decompress the 8-bit-per-sample JPEG source image or decode the planar YUV
source image associated with this decompressor instance and output an
8-bit-per-sample packed-pixel grayscale, RGB, or CMYK image to the given
destination buffer.</div>
<div class="block">Decompress the JPEG source image with 2 to 8 bits per sample, or decode
the 8-bit-per-sample planar YUV source image, associated with this
decompressor instance and output a packed-pixel grayscale, RGB, or CMYK
image with the same data precision to the given destination buffer.</div>
</td>
</tr>
<tr id="i11" class="rowColor">
@@ -380,9 +381,10 @@ implements java.io.Closeable</pre>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#decompress8(int,int)">decompress8</a></span>&#8203;(int&nbsp;pitch,
int&nbsp;pixelFormat)</code></th>
<td class="colLast">
<div class="block">Decompress the 8-bit-per-sample JPEG source image or decode the planar YUV
source image associated with this decompressor instance and return a
buffer containing an 8-bit-per-sample packed-pixel decompressed image.</div>
<div class="block">Decompress the JPEG source image with 2 to 8 bits per sample, or decode
the 8-bit-per-sample planar YUV source image, associated with this
decompressor instance and return a buffer containing a packed-pixel
decompressed image with the same data precision.</div>
</td>
</tr>
<tr id="i14" class="altColor">
@@ -976,10 +978,10 @@ public&nbsp;int&nbsp;getScaledHeight&#8203;(int&nbsp;desiredWidth,
int&nbsp;pitch,
int&nbsp;pixelFormat)
throws <a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Decompress the 8-bit-per-sample JPEG source image or decode the planar YUV
source image associated with this decompressor instance and output an
8-bit-per-sample packed-pixel grayscale, RGB, or CMYK image to the given
destination buffer.
<div class="block">Decompress the JPEG source image with 2 to 8 bits per sample, or decode
the 8-bit-per-sample planar YUV source image, associated with this
decompressor instance and output a packed-pixel grayscale, RGB, or CMYK
image with the same data precision to the given destination buffer.
<p>
NOTE: The destination image is fully recoverable if this method throws a
non-fatal <a href="TJException.html" title="class in org.libjpegturbo.turbojpeg"><code>TJException</code></a> (unless <a href="TJ.html#PARAM_STOPONWARNING"><code>TJ.PARAM_STOPONWARNING</code></a> is
@@ -1062,9 +1064,10 @@ public&nbsp;void&nbsp;decompress&#8203;(byte[]&nbsp;dstBuf,
<pre class="methodSignature">public&nbsp;byte[]&nbsp;decompress8&#8203;(int&nbsp;pitch,
int&nbsp;pixelFormat)
throws <a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Decompress the 8-bit-per-sample JPEG source image or decode the planar YUV
source image associated with this decompressor instance and return a
buffer containing an 8-bit-per-sample packed-pixel decompressed image.</div>
<div class="block">Decompress the JPEG source image with 2 to 8 bits per sample, or decode
the 8-bit-per-sample planar YUV source image, associated with this
decompressor instance and return a buffer containing a packed-pixel
decompressed image with the same data precision.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>pitch</code> - see
@@ -1072,8 +1075,8 @@ public&nbsp;void&nbsp;decompress&#8203;(byte[]&nbsp;dstBuf,
<dd><code>pixelFormat</code> - pixel format of the decompressed image (one of
<a href="TJ.html#PF_RGB"><code>TJ.PF_*</code></a>)</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a buffer containing an 8-bit-per-sample packed-pixel decompressed
image.</dd>
<dd>a buffer containing a packed-pixel decompressed image with 2 to 8
bits of data precision per sample.</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code><a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></code></dd>
</dl>
@@ -1115,9 +1118,10 @@ public&nbsp;byte[]&nbsp;decompress&#8203;(int&nbsp;desiredWidth,
int&nbsp;pitch,
int&nbsp;pixelFormat)
throws <a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Decompress the 12-bit-per-sample JPEG source image associated with this
decompressor instance and output a 12-bit-per-sample packed-pixel
grayscale, RGB, or CMYK image to the given destination buffer.
<div class="block">Decompress the JPEG source image with 9 to 12 bits per sample associated
with this decompressor instance and output a packed-pixel grayscale, RGB,
or CMYK image with the same data precision to the given destination
buffer.
<p>
NOTE: The destination image is fully recoverable if this method throws a
non-fatal <a href="TJException.html" title="class in org.libjpegturbo.turbojpeg"><code>TJException</code></a> (unless <a href="TJ.html#PARAM_STOPONWARNING"><code>TJ.PARAM_STOPONWARNING</code></a> is
@@ -1174,9 +1178,9 @@ public&nbsp;byte[]&nbsp;decompress&#8203;(int&nbsp;desiredWidth,
<pre class="methodSignature">public&nbsp;short[]&nbsp;decompress12&#8203;(int&nbsp;pitch,
int&nbsp;pixelFormat)
throws <a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Decompress the 12-bit-per-sample JPEG source image associated with this
decompressor instance and return a buffer containing a 12-bit-per-sample
packed-pixel decompressed image.</div>
<div class="block">Decompress the JPEG source image with 9 to 12 bits per sample associated
with this decompressor instance and return a buffer containing a
packed-pixel decompressed image with the same data precision.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>pitch</code> - see
@@ -1184,8 +1188,8 @@ public&nbsp;byte[]&nbsp;decompress&#8203;(int&nbsp;desiredWidth,
<dd><code>pixelFormat</code> - pixel format of the decompressed image (one of
<a href="TJ.html#PF_RGB"><code>TJ.PF_*</code></a>)</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a buffer containing a 12-bit-per-sample packed-pixel decompressed
image.</dd>
<dd>a buffer containing a packed-pixel decompressed image with 9 to 12
bits of data precision per sample.</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code><a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></code></dd>
</dl>
@@ -1203,9 +1207,9 @@ public&nbsp;byte[]&nbsp;decompress&#8203;(int&nbsp;desiredWidth,
int&nbsp;pitch,
int&nbsp;pixelFormat)
throws <a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Decompress the 16-bit-per-sample lossless JPEG source image associated
with this decompressor instance and output a 16-bit-per-sample
packed-pixel grayscale, RGB, or CMYK image to the given destination
<div class="block">Decompress the JPEG source image with 13 to 16 bits per sample associated
with this decompressor instance and output a packed-pixel grayscale, RGB,
or CMYK image with the same data precision to the given destination
buffer.
<p>
NOTE: The destination image is fully recoverable if this method throws a
@@ -1248,9 +1252,9 @@ public&nbsp;byte[]&nbsp;decompress&#8203;(int&nbsp;desiredWidth,
<pre class="methodSignature">public&nbsp;short[]&nbsp;decompress16&#8203;(int&nbsp;pitch,
int&nbsp;pixelFormat)
throws <a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Decompress the 16-bit-per-sample JPEG source image associated with this
decompressor instance and return a buffer containing a 16-bit-per-sample
packed-pixel decompressed image.</div>
<div class="block">Decompress the JPEG source image with 13 to 16 bits per sample associated
with this decompressor instance and return a buffer containing a
packed-pixel decompressed image with the same data precision.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>pitch</code> - see
@@ -1258,8 +1262,8 @@ public&nbsp;byte[]&nbsp;decompress&#8203;(int&nbsp;desiredWidth,
<dd><code>pixelFormat</code> - pixel format of the decompressed image (one of
<a href="TJ.html#PF_RGB"><code>TJ.PF_*</code></a>)</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a buffer containing a 16-bit-per-sample packed-pixel decompressed
image.</dd>
<dd>a buffer containing a packed-pixel decompressed image with 13 to
16 bits of data precision per sample.</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code><a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></code></dd>
</dl>

Binary file not shown.

Binary file not shown.

View File

@@ -190,8 +190,9 @@ public final class TJ {
public static final int PF_XRGB = 5;
/**
* Grayscale pixel format. Each 1-sample pixel represents a luminance
* (brightness) level from 0 to the maximum sample value (255 for 8-bit
* samples, 4095 for 12-bit samples, and 65535 for 16-bit samples.)
* (brightness) level from 0 to the maximum sample value (which is, for
* instance, 255 for 8-bit samples or 4095 for 12-bit samples or 65535 for
* 16-bit samples.)
*/
public static final int PF_GRAY = 6;
/**
@@ -467,16 +468,22 @@ public final class TJ {
*/
public static final int PARAM_JPEGHEIGHT = 6;
/**
* JPEG data precision (bits per sample) [decompression only, read-only]
* Data precision (bits per sample)
*
* <p>The JPEG image uses the specified number of bits per sample.
* <p>The JPEG image uses (decompression) or will use (lossless compression)
* the specified number of bits per sample.
*
* <p>The data precision is the number of bits in the maximum sample value,
* which may not be the same as the width of the data type used to store the
* sample.
*
* <p><b>Value</b>
* <ul>
* <li> <code>8</code>, <code>12</code>, or <code>16</code>
* <li> <code>8</code> or <code>12</code> for lossy JPEG images;
* <code>2</code> to <code>16</code> for lossless JPEG images
* </ul>
*
* <p>12-bit data precision implies {@link #PARAM_OPTIMIZE} unless
* <p>12-bit JPEG data precision implies {@link #PARAM_OPTIMIZE} unless
* {@link #PARAM_ARITHMETIC} is set.
*/
public static final int PARAM_PRECISION = 7;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C)2011-2015, 2018, 2020, 2022-2023 D. R. Commander.
* Copyright (C)2011-2015, 2018, 2020, 2022-2024 D. R. Commander.
* All Rights Reserved.
* Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
*
@@ -47,9 +47,9 @@ public class TJCompressor implements Closeable {
}
/**
* Create a TurboJPEG compressor instance and associate the 8-bit-per-sample
* packed-pixel source image stored in <code>srcImage</code> with the newly
* created instance.
* Create a TurboJPEG compressor instance and associate the packed-pixel
* source image, stored in <code>srcImage</code> with 2 to 8 bits of data
* precision per sample, with the newly created instance.
*
* @param srcImage see {@link #setSourceImage} for description
*
@@ -97,11 +97,16 @@ public class TJCompressor implements Closeable {
}
/**
* Associate an 8-bit-per-sample packed-pixel RGB, grayscale, or CMYK source
* image with this compressor instance.
* Associate a packed-pixel RGB, grayscale, or CMYK source image with 2 to 8
* bits of data precision per sample with this compressor instance. Note
* that packed-pixel source images with 2 to 7 bits of data precision per
* sample can only be compressed into lossless JPEG images.
*
* @param srcImage buffer containing a packed-pixel RGB, grayscale, or CMYK
* source image to be compressed or encoded. This buffer is not modified.
* source image to be compressed or encoded. The data precision of the
* source image (from 2 to 8 bits per sample) can be specified using
* {@link TJ#PARAM_PRECISION} and defaults to 8 if {@link TJ#PARAM_PRECISION}
* is unset or out of range. This buffer is not modified.
*
* @param x x offset (in pixels) of the region in the source image from which
* the JPEG or YUV image should be compressed/encoded
@@ -151,13 +156,17 @@ public class TJCompressor implements Closeable {
}
/**
* Associate a 12-bit-per-sample packed-pixel RGB, grayscale, or CMYK source
* image with this compressor instance. Note that 12-bit-per-sample
* packed-pixel source images can only be compressed into 12-bit-per-sample
* JPEG images.
* Associate a packed-pixel RGB, grayscale, or CMYK source image with 9 to 12
* bits of data precision per sample with this compressor instance. Note
* that packed-pixel source images with 9 to 11 bits of data precision per
* sample can only be compressed into lossless JPEG images.
*
* @param srcImage buffer containing a packed-pixel RGB, grayscale, or CMYK
* source image to be compressed. This buffer is not modified.
* source image to be compressed. The data precision of the source image
* (from 9 to 12 bits per sample) can be specified using
* {@link TJ#PARAM_PRECISION} and defaults to 12 if
* {@link TJ#PARAM_PRECISION} is unset or out of range. This buffer is not
* modified.
*
* @param x x offset (in pixels) of the region in the source image from which
* the JPEG image should be compressed
@@ -207,13 +216,17 @@ public class TJCompressor implements Closeable {
}
/**
* Associate a 16-bit-per-sample packed-pixel RGB, grayscale, or CMYK source
* image with this compressor instance. Note that 16-bit-per-sample
* packed-pixel source images can only be compressed into 16-bit-per-sample
* lossless JPEG images.
* Associate a packed-pixel RGB, grayscale, or CMYK source image with 13 to
* 16 bits of data precision per sample with this compressor instance. Note
* that packed-pixel source images with 13 to 16 bits of data precision per
* sample can only be compressed into lossless JPEG images.
*
* @param srcImage buffer containing a packed-pixel RGB, grayscale, or CMYK
* source image to be compressed. This buffer is not modified.
* source image to be compressed. The data precision of the source image
* (from 13 to 16 bits per sample) can be specified using
* {@link TJ#PARAM_PRECISION} and defaults to 16 if
* {@link TJ#PARAM_PRECISION} is unset or out of range. This buffer is not
* modified.
*
* @param x x offset (in pixels) of the region in the source image from which
* the JPEG image should be compressed

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C)2011-2015, 2018, 2022-2023 D. R. Commander.
* Copyright (C)2011-2015, 2018, 2022-2024 D. R. Commander.
* All Rights Reserved.
* Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
*
@@ -376,10 +376,10 @@ public class TJDecompressor implements Closeable {
}
/**
* Decompress the 8-bit-per-sample JPEG source image or decode the planar YUV
* source image associated with this decompressor instance and output an
* 8-bit-per-sample packed-pixel grayscale, RGB, or CMYK image to the given
* destination buffer.
* Decompress the JPEG source image with 2 to 8 bits per sample, or decode
* the 8-bit-per-sample planar YUV source image, associated with this
* decompressor instance and output a packed-pixel grayscale, RGB, or CMYK
* image with the same data precision to the given destination buffer.
* <p>
* NOTE: The destination image is fully recoverable if this method throws a
* non-fatal {@link TJException} (unless {@link TJ#PARAM_STOPONWARNING} is
@@ -464,9 +464,10 @@ public class TJDecompressor implements Closeable {
}
/**
* Decompress the 8-bit-per-sample JPEG source image or decode the planar YUV
* source image associated with this decompressor instance and return a
* buffer containing an 8-bit-per-sample packed-pixel decompressed image.
* Decompress the JPEG source image with 2 to 8 bits per sample, or decode
* the 8-bit-per-sample planar YUV source image, associated with this
* decompressor instance and return a buffer containing a packed-pixel
* decompressed image with the same data precision.
*
* @param pitch see
* {@link #decompress8(byte[], int, int, int, int)} for description
@@ -474,8 +475,8 @@ public class TJDecompressor implements Closeable {
* @param pixelFormat pixel format of the decompressed image (one of
* {@link TJ#PF_RGB TJ.PF_*})
*
* @return a buffer containing an 8-bit-per-sample packed-pixel decompressed
* image.
* @return a buffer containing a packed-pixel decompressed image with 2 to 8
* bits of data precision per sample.
*/
public byte[] decompress8(int pitch, int pixelFormat) throws TJException {
if (pitch < 0 || pixelFormat < 0 || pixelFormat >= TJ.NUMPF)
@@ -512,9 +513,10 @@ public class TJDecompressor implements Closeable {
}
/**
* Decompress the 12-bit-per-sample JPEG source image associated with this
* decompressor instance and output a 12-bit-per-sample packed-pixel
* grayscale, RGB, or CMYK image to the given destination buffer.
* Decompress the JPEG source image with 9 to 12 bits per sample associated
* with this decompressor instance and output a packed-pixel grayscale, RGB,
* or CMYK image with the same data precision to the given destination
* buffer.
* <p>
* NOTE: The destination image is fully recoverable if this method throws a
* non-fatal {@link TJException} (unless {@link TJ#PARAM_STOPONWARNING} is
@@ -572,9 +574,9 @@ public class TJDecompressor implements Closeable {
}
/**
* Decompress the 12-bit-per-sample JPEG source image associated with this
* decompressor instance and return a buffer containing a 12-bit-per-sample
* packed-pixel decompressed image.
* Decompress the JPEG source image with 9 to 12 bits per sample associated
* with this decompressor instance and return a buffer containing a
* packed-pixel decompressed image with the same data precision.
*
* @param pitch see
* {@link #decompress12(short[], int, int, int, int)} for description
@@ -582,8 +584,8 @@ public class TJDecompressor implements Closeable {
* @param pixelFormat pixel format of the decompressed image (one of
* {@link TJ#PF_RGB TJ.PF_*})
*
* @return a buffer containing a 12-bit-per-sample packed-pixel decompressed
* image.
* @return a buffer containing a packed-pixel decompressed image with 9 to 12
* bits of data precision per sample.
*/
public short[] decompress12(int pitch, int pixelFormat) throws TJException {
if (pitch < 0 || pixelFormat < 0 || pixelFormat >= TJ.NUMPF)
@@ -599,9 +601,9 @@ public class TJDecompressor implements Closeable {
}
/**
* Decompress the 16-bit-per-sample lossless JPEG source image associated
* with this decompressor instance and output a 16-bit-per-sample
* packed-pixel grayscale, RGB, or CMYK image to the given destination
* Decompress the JPEG source image with 13 to 16 bits per sample associated
* with this decompressor instance and output a packed-pixel grayscale, RGB,
* or CMYK image with the same data precision to the given destination
* buffer.
* <p>
* NOTE: The destination image is fully recoverable if this method throws a
@@ -645,9 +647,9 @@ public class TJDecompressor implements Closeable {
}
/**
* Decompress the 16-bit-per-sample JPEG source image associated with this
* decompressor instance and return a buffer containing a 16-bit-per-sample
* packed-pixel decompressed image.
* Decompress the JPEG source image with 13 to 16 bits per sample associated
* with this decompressor instance and return a buffer containing a
* packed-pixel decompressed image with the same data precision.
*
* @param pitch see
* {@link #decompress16(short[], int, int, int, int)} for description
@@ -655,8 +657,8 @@ public class TJDecompressor implements Closeable {
* @param pixelFormat pixel format of the decompressed image (one of
* {@link TJ#PF_RGB TJ.PF_*})
*
* @return a buffer containing a 16-bit-per-sample packed-pixel decompressed
* image.
* @return a buffer containing a packed-pixel decompressed image with 13 to
* 16 bits of data precision per sample.
*/
public short[] decompress16(int pitch, int pixelFormat) throws TJException {
if (pitch < 0 || pixelFormat < 0 || pixelFormat >= TJ.NUMPF)

View File

@@ -1281,8 +1281,7 @@ JNIEXPORT jobject JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_loadImage
GET_HANDLE();
if ((precision != 8 && precision != 12 && precision != 16) ||
jfilename == NULL || jwidth == NULL ||
if (precision < 2 || precision > 16 || jfilename == NULL || jwidth == NULL ||
(*env)->GetArrayLength(env, jwidth) < 1 || jheight == NULL ||
(*env)->GetArrayLength(env, jheight) < 1 || jpixelFormat == NULL ||
(*env)->GetArrayLength(env, jpixelFormat) < 1)
@@ -1299,11 +1298,11 @@ JNIEXPORT jobject JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_loadImage
(*env)->ReleasePrimitiveArrayCritical(env, jpixelFormat, pfarr, 0);
BAILIF0(filename = (*env)->GetStringUTFChars(env, jfilename, &isCopy));
if (precision == 8) {
if (precision <= 8) {
if ((dstBuf = tj3LoadImage8(handle, filename, &width, align, &height,
&pixelFormat)) == NULL)
THROW_TJ();
} else if (precision == 12) {
} else if (precision <= 12) {
if ((dstBuf = tj3LoadImage12(handle, filename, &width, align, &height,
&pixelFormat)) == NULL)
THROW_TJ();
@@ -1332,7 +1331,7 @@ JNIEXPORT jobject JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_loadImage
(*env)->ReleasePrimitiveArrayCritical(env, jpixelFormat, pfarr, 0);
n = width * height * tjPixelSize[pixelFormat];
if (precision == 8)
if (precision <= 8)
jdstBuf = (*env)->NewByteArray(env, n);
else
jdstBuf = (*env)->NewShortArray(env, n);
@@ -1359,9 +1358,9 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_saveImage
GET_HANDLE();
if ((precision != 8 && precision != 12 && precision != 16) ||
jfilename == NULL || jsrcBuf == NULL || width < 1 || height < 1 ||
pixelFormat < 0 || pixelFormat >= TJ_NUMPF)
if (precision < 2 || precision > 16 || jfilename == NULL ||
jsrcBuf == NULL || width < 1 || height < 1 || pixelFormat < 0 ||
pixelFormat >= TJ_NUMPF)
THROW_ARG("Invalid argument in saveImage()");
if ((unsigned long long)width * (unsigned long long)height *
@@ -1380,11 +1379,11 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_saveImage
(*env)->ReleasePrimitiveArrayCritical(env, jsrcBuf, jsrcPtr, 0);
BAILIF0(filename = (*env)->GetStringUTFChars(env, jfilename, &isCopy));
if (precision == 8) {
if (precision <= 8) {
if (tj3SaveImage8(handle, filename, srcBuf, width, pitch, height,
pixelFormat) == -1)
THROW_TJ();
} else if (precision == 12) {
} else if (precision <= 12) {
if (tj3SaveImage12(handle, filename, srcBuf, width, pitch, height,
pixelFormat) == -1)
THROW_TJ();

View File

@@ -109,17 +109,18 @@ select_file_type(j_compress_ptr cinfo, FILE *infile)
#endif
#ifdef PPM_SUPPORTED
case 'P':
if (cinfo->data_precision == 16) {
if (cinfo->data_precision <= 8)
return jinit_read_ppm(cinfo);
else if (cinfo->data_precision <= 12)
return j12init_read_ppm(cinfo);
else {
#ifdef C_LOSSLESS_SUPPORTED
return j16init_read_ppm(cinfo);
#else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
break;
#endif
} else if (cinfo->data_precision == 12)
return j12init_read_ppm(cinfo);
else
return jinit_read_ppm(cinfo);
}
#endif
#ifdef TARGA_SUPPORTED
case 0x00:
@@ -218,7 +219,7 @@ usage(void)
fprintf(stderr, "Switches for advanced users:\n");
fprintf(stderr, " -precision N Create JPEG file with N-bit data precision\n");
#ifdef C_LOSSLESS_SUPPORTED
fprintf(stderr, " (N is 8, 12, or 16; default is 8; if N is 16, then -lossless\n");
fprintf(stderr, " (N=2..16; default is 8; if N is not 8 or 12, then -lossless\n");
fprintf(stderr, " must also be specified)\n");
#else
fprintf(stderr, " (N is 8 or 12; default is 8)\n");
@@ -439,7 +440,7 @@ parse_switches(j_compress_ptr cinfo, int argc, char **argv,
if (sscanf(argv[argn], "%d", &val) != 1)
usage();
#ifdef C_LOSSLESS_SUPPORTED
if (val != 8 && val != 12 && val != 16)
if (val < 2 || val > 16)
#else
if (val != 8 && val != 12)
#endif
@@ -788,7 +789,17 @@ main(int argc, char **argv)
jpeg_write_icc_profile(&cinfo, icc_profile, (unsigned int)icc_len);
/* Process data */
if (cinfo.data_precision == 16) {
if (cinfo.data_precision <= 8) {
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);
}
} else if (cinfo.data_precision <= 12) {
while (cinfo.next_scanline < cinfo.image_height) {
num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
(void)jpeg12_write_scanlines(&cinfo, src_mgr->buffer12, num_scanlines);
}
} else {
#ifdef C_LOSSLESS_SUPPORTED
while (cinfo.next_scanline < cinfo.image_height) {
num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
@@ -797,16 +808,6 @@ main(int argc, char **argv)
#else
ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision);
#endif
} else if (cinfo.data_precision == 12) {
while (cinfo.next_scanline < cinfo.image_height) {
num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
(void)jpeg12_write_scanlines(&cinfo, src_mgr->buffer12, num_scanlines);
}
} else {
while (cinfo.next_scanline < cinfo.image_height) {
num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
(void)jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
}
}
/* Finish compression and release memory */

View File

@@ -1,7 +1,7 @@
/*
* cmyk.h
*
* Copyright (C) 2017-2018, 2022, D. R. Commander.
* Copyright (C) 2017-2018, 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -24,12 +24,12 @@
INLINE
LOCAL(void)
rgb_to_cmyk(_JSAMPLE r, _JSAMPLE g, _JSAMPLE b,
rgb_to_cmyk(int maxval, _JSAMPLE r, _JSAMPLE g, _JSAMPLE b,
_JSAMPLE *c, _JSAMPLE *m, _JSAMPLE *y, _JSAMPLE *k)
{
double ctmp = 1.0 - ((double)r / (double)_MAXJSAMPLE);
double mtmp = 1.0 - ((double)g / (double)_MAXJSAMPLE);
double ytmp = 1.0 - ((double)b / (double)_MAXJSAMPLE);
double ctmp = 1.0 - ((double)r / (double)maxval);
double mtmp = 1.0 - ((double)g / (double)maxval);
double ytmp = 1.0 - ((double)b / (double)maxval);
double ktmp = MIN(MIN(ctmp, mtmp), ytmp);
if (ktmp == 1.0) ctmp = mtmp = ytmp = 0.0;
@@ -38,10 +38,10 @@ rgb_to_cmyk(_JSAMPLE r, _JSAMPLE g, _JSAMPLE b,
mtmp = (mtmp - ktmp) / (1.0 - ktmp);
ytmp = (ytmp - ktmp) / (1.0 - ktmp);
}
*c = (_JSAMPLE)((double)_MAXJSAMPLE - ctmp * (double)_MAXJSAMPLE + 0.5);
*m = (_JSAMPLE)((double)_MAXJSAMPLE - mtmp * (double)_MAXJSAMPLE + 0.5);
*y = (_JSAMPLE)((double)_MAXJSAMPLE - ytmp * (double)_MAXJSAMPLE + 0.5);
*k = (_JSAMPLE)((double)_MAXJSAMPLE - ktmp * (double)_MAXJSAMPLE + 0.5);
*c = (_JSAMPLE)((double)maxval - ctmp * (double)maxval + 0.5);
*m = (_JSAMPLE)((double)maxval - mtmp * (double)maxval + 0.5);
*y = (_JSAMPLE)((double)maxval - ytmp * (double)maxval + 0.5);
*k = (_JSAMPLE)((double)maxval - ktmp * (double)maxval + 0.5);
}
@@ -49,12 +49,12 @@ rgb_to_cmyk(_JSAMPLE r, _JSAMPLE g, _JSAMPLE b,
INLINE
LOCAL(void)
cmyk_to_rgb(_JSAMPLE c, _JSAMPLE m, _JSAMPLE y, _JSAMPLE k,
cmyk_to_rgb(int maxval, _JSAMPLE c, _JSAMPLE m, _JSAMPLE y, _JSAMPLE k,
_JSAMPLE *r, _JSAMPLE *g, _JSAMPLE *b)
{
*r = (_JSAMPLE)((double)c * (double)k / (double)_MAXJSAMPLE + 0.5);
*g = (_JSAMPLE)((double)m * (double)k / (double)_MAXJSAMPLE + 0.5);
*b = (_JSAMPLE)((double)y * (double)k / (double)_MAXJSAMPLE + 0.5);
*r = (_JSAMPLE)((double)c * (double)k / (double)maxval + 0.5);
*g = (_JSAMPLE)((double)m * (double)k / (double)maxval + 0.5);
*b = (_JSAMPLE)((double)y * (double)k / (double)maxval + 0.5);
}

View File

@@ -668,12 +668,12 @@ main(int argc, char **argv)
#endif
#ifdef GIF_SUPPORTED
case FMT_GIF:
if (cinfo.data_precision == 16)
ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision);
if (cinfo.data_precision == 8)
dest_mgr = jinit_write_gif(&cinfo, TRUE);
else if (cinfo.data_precision == 12)
dest_mgr = j12init_write_gif(&cinfo, TRUE);
else
dest_mgr = jinit_write_gif(&cinfo, TRUE);
ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision);
break;
case FMT_GIF0:
dest_mgr = jinit_write_gif(&cinfo, FALSE);
@@ -681,16 +681,16 @@ main(int argc, char **argv)
#endif
#ifdef PPM_SUPPORTED
case FMT_PPM:
if (cinfo.data_precision == 16)
if (cinfo.data_precision <= 8)
dest_mgr = jinit_write_ppm(&cinfo);
else if (cinfo.data_precision <= 12)
dest_mgr = j12init_write_ppm(&cinfo);
else
#ifdef D_LOSSLESS_SUPPORTED
dest_mgr = j16init_write_ppm(&cinfo);
#else
ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision);
#endif
else if (cinfo.data_precision == 12)
dest_mgr = j12init_write_ppm(&cinfo);
else
dest_mgr = jinit_write_ppm(&cinfo);
break;
#endif
#ifdef TARGA_SUPPORTED
@@ -729,27 +729,7 @@ main(int argc, char **argv)
(*dest_mgr->start_output) (&cinfo, dest_mgr);
cinfo.output_height = tmp;
if (cinfo.data_precision == 16)
ERREXIT(&cinfo, JERR_NOTIMPL);
else if (cinfo.data_precision == 12) {
/* Process data */
while (cinfo.output_scanline < skip_start) {
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
if ((tmp = jpeg12_skip_scanlines(&cinfo, skip_end - skip_start + 1)) !=
skip_end - skip_start + 1) {
fprintf(stderr, "%s: jpeg12_skip_scanlines() returned %u rather than %u\n",
progname, tmp, skip_end - skip_start + 1);
exit(EXIT_FAILURE);
}
while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
} else {
if (cinfo.data_precision == 8) {
/* Process data */
while (cinfo.output_scanline < skip_start) {
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
@@ -767,7 +747,26 @@ main(int argc, char **argv)
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
}
} else if (cinfo.data_precision == 12) {
/* Process data */
while (cinfo.output_scanline < skip_start) {
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
if ((tmp = jpeg12_skip_scanlines(&cinfo, skip_end - skip_start + 1)) !=
skip_end - skip_start + 1) {
fprintf(stderr, "%s: jpeg12_skip_scanlines() returned %u rather than %u\n",
progname, tmp, skip_end - skip_start + 1);
exit(EXIT_FAILURE);
}
while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
} else
ERREXIT(&cinfo, JERR_NOTIMPL);
/* Decompress a subregion */
} else if (crop) {
@@ -783,12 +782,12 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
if (cinfo.data_precision == 16)
ERREXIT(&cinfo, JERR_NOTIMPL);
if (cinfo.data_precision == 8)
jpeg_crop_scanline(&cinfo, &crop_x, &crop_width);
else if (cinfo.data_precision == 12)
jpeg12_crop_scanline(&cinfo, &crop_x, &crop_width);
else
jpeg_crop_scanline(&cinfo, &crop_x, &crop_width);
ERREXIT(&cinfo, JERR_NOTIMPL);
if (dest_mgr->calc_buffer_dimensions)
(*dest_mgr->calc_buffer_dimensions) (&cinfo, dest_mgr);
else
@@ -802,29 +801,7 @@ main(int argc, char **argv)
(*dest_mgr->start_output) (&cinfo, dest_mgr);
cinfo.output_height = tmp;
if (cinfo.data_precision == 16)
ERREXIT(&cinfo, JERR_NOTIMPL);
else if (cinfo.data_precision == 12) {
/* Process data */
if ((tmp = jpeg12_skip_scanlines(&cinfo, crop_y)) != crop_y) {
fprintf(stderr, "%s: jpeg12_skip_scanlines() returned %u rather than %u\n",
progname, tmp, crop_y);
exit(EXIT_FAILURE);
}
while (cinfo.output_scanline < crop_y + crop_height) {
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
if ((tmp =
jpeg12_skip_scanlines(&cinfo, cinfo.output_height - crop_y -
crop_height)) !=
cinfo.output_height - crop_y - crop_height) {
fprintf(stderr, "%s: jpeg12_skip_scanlines() returned %u rather than %u\n",
progname, tmp, cinfo.output_height - crop_y - crop_height);
exit(EXIT_FAILURE);
}
} else {
if (cinfo.data_precision == 8) {
/* Process data */
if ((tmp = jpeg_skip_scanlines(&cinfo, crop_y)) != crop_y) {
fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n",
@@ -844,14 +821,49 @@ main(int argc, char **argv)
progname, tmp, cinfo.output_height - crop_y - crop_height);
exit(EXIT_FAILURE);
}
}
} else if (cinfo.data_precision == 12) {
/* Process data */
if ((tmp = jpeg12_skip_scanlines(&cinfo, crop_y)) != crop_y) {
fprintf(stderr, "%s: jpeg12_skip_scanlines() returned %u rather than %u\n",
progname, tmp, crop_y);
exit(EXIT_FAILURE);
}
while (cinfo.output_scanline < crop_y + crop_height) {
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
if ((tmp =
jpeg12_skip_scanlines(&cinfo, cinfo.output_height - crop_y -
crop_height)) !=
cinfo.output_height - crop_y - crop_height) {
fprintf(stderr, "%s: jpeg12_skip_scanlines() returned %u rather than %u\n",
progname, tmp, cinfo.output_height - crop_y - crop_height);
exit(EXIT_FAILURE);
}
} else
ERREXIT(&cinfo, JERR_NOTIMPL);
/* Normal full-image decompress */
} else {
/* Write output file header */
(*dest_mgr->start_output) (&cinfo, dest_mgr);
if (cinfo.data_precision == 16) {
if (cinfo.data_precision <= 8) {
/* 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);
}
} else if (cinfo.data_precision <= 12) {
/* Process data */
while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
} else {
#ifdef D_LOSSLESS_SUPPORTED
/* Process data */
while (cinfo.output_scanline < cinfo.output_height) {
@@ -862,20 +874,6 @@ main(int argc, char **argv)
#else
ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision);
#endif
} else if (cinfo.data_precision == 12) {
/* Process data */
while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
} else {
/* Process data */
while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
}
}
}

View File

@@ -5,7 +5,7 @@
* Copyright (C) 1994-1998, Thomas G. Lane.
* Modified 2003-2010 by Guido Vollbeding.
* libjpeg-turbo Modifications:
* Copyright (C) 2022, D. R. Commander.
* Copyright (C) 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -194,19 +194,19 @@ 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->data_precision == 16) {
if (cinfo->data_precision <= 8) {
if (!(*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE)NULL))
ERREXIT(cinfo, JERR_CANT_SUSPEND);
} else if (cinfo->data_precision <= 12) {
if (!(*cinfo->coef->compress_data_12) (cinfo, (J12SAMPIMAGE)NULL))
ERREXIT(cinfo, JERR_CANT_SUSPEND);
} else {
#ifdef C_LOSSLESS_SUPPORTED
if (!(*cinfo->coef->compress_data_16) (cinfo, (J16SAMPIMAGE)NULL))
ERREXIT(cinfo, JERR_CANT_SUSPEND);
#else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#endif
} else if (cinfo->data_precision == 12) {
if (!(*cinfo->coef->compress_data_12) (cinfo, (J12SAMPIMAGE)NULL))
ERREXIT(cinfo, JERR_CANT_SUSPEND);
} else {
if (!(*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE)NULL))
ERREXIT(cinfo, JERR_CANT_SUSPEND);
}
}
(*cinfo->master->finish_pass) (cinfo);

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) 2022, D. R. Commander.
* Copyright (C) 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -88,8 +88,21 @@ _jpeg_write_scanlines(j_compress_ptr cinfo, _JSAMPARRAY scanlines,
#if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)
JDIMENSION row_ctr, rows_left;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#ifdef C_LOSSLESS_SUPPORTED
if (cinfo->master->lossless) {
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
} else
#endif
{
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);

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) 2009-2012, 2015, 2022, D. R. Commander.
* Copyright (C) 2009-2012, 2015, 2022, 2024, D. R. Commander.
* Copyright (C) 2014, MIPS Technologies, Inc., California.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
@@ -552,8 +552,21 @@ _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);
#ifdef C_LOSSLESS_SUPPORTED
if (cinfo->master->lossless) {
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
} else
#endif
{
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,

View File

@@ -6,7 +6,7 @@
* Lossless JPEG Modifications:
* Copyright (C) 1999, Ken Murchison.
* libjpeg-turbo Modifications:
* Copyright (C) 2022, D. R. Commander.
* Copyright (C) 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -346,6 +346,14 @@ _jinit_c_diff_controller(j_compress_ptr cinfo, boolean need_full_buffer)
int ci, row;
jpeg_component_info *compptr;
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
diff = (my_diff_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_diff_controller));

View File

@@ -6,7 +6,7 @@
* Lossless JPEG Modifications:
* Copyright (C) 1999, Ken Murchison.
* libjpeg-turbo Modifications:
* Copyright (C) 2020, 2022, D. R. Commander.
* Copyright (C) 2020, 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -40,7 +40,16 @@ jinit_compress_master(j_compress_ptr cinfo)
/* Preprocessing */
if (!cinfo->raw_data_in) {
if (cinfo->data_precision == 16) {
if (cinfo->data_precision <= 8) {
jinit_color_converter(cinfo);
jinit_downsampler(cinfo);
jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
} else if (cinfo->data_precision <= 12) {
j12init_color_converter(cinfo);
j12init_downsampler(cinfo);
j12init_c_prep_controller(cinfo,
FALSE /* never need full buffer here */);
} else {
#ifdef C_LOSSLESS_SUPPORTED
j16init_color_converter(cinfo);
j16init_downsampler(cinfo);
@@ -49,27 +58,18 @@ jinit_compress_master(j_compress_ptr cinfo)
#else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#endif
} else if (cinfo->data_precision == 12) {
j12init_color_converter(cinfo);
j12init_downsampler(cinfo);
j12init_c_prep_controller(cinfo,
FALSE /* never need full buffer here */);
} else {
jinit_color_converter(cinfo);
jinit_downsampler(cinfo);
jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
}
}
if (cinfo->master->lossless) {
#ifdef C_LOSSLESS_SUPPORTED
/* Prediction, sample differencing, and point transform */
if (cinfo->data_precision == 16)
j16init_lossless_compressor(cinfo);
else if (cinfo->data_precision == 12)
if (cinfo->data_precision <= 8)
jinit_lossless_compressor(cinfo);
else if (cinfo->data_precision <= 12)
j12init_lossless_compressor(cinfo);
else
jinit_lossless_compressor(cinfo);
j16init_lossless_compressor(cinfo);
/* Entropy encoding: either Huffman or arithmetic coding. */
if (cinfo->arith_code) {
ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
@@ -78,26 +78,26 @@ jinit_compress_master(j_compress_ptr cinfo)
}
/* Need a full-image difference buffer in any multi-pass mode. */
if (cinfo->data_precision == 16)
j16init_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
cinfo->optimize_coding));
else if (cinfo->data_precision == 12)
if (cinfo->data_precision <= 8)
jinit_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
cinfo->optimize_coding));
else if (cinfo->data_precision <= 12)
j12init_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
cinfo->optimize_coding));
else
jinit_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
cinfo->optimize_coding));
j16init_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
cinfo->optimize_coding));
#else
ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif
} else {
if (cinfo->data_precision == 16)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Forward DCT */
if (cinfo->data_precision == 12)
if (cinfo->data_precision == 8)
jinit_forward_dct(cinfo);
else if (cinfo->data_precision == 12)
j12init_forward_dct(cinfo);
else
jinit_forward_dct(cinfo);
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Entropy encoding: either Huffman or arithmetic coding. */
if (cinfo->arith_code) {
#ifdef C_ARITH_CODING_SUPPORTED
@@ -125,16 +125,16 @@ jinit_compress_master(j_compress_ptr cinfo)
cinfo->optimize_coding));
}
if (cinfo->data_precision == 16)
if (cinfo->data_precision <= 8)
jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
else if (cinfo->data_precision <= 12)
j12init_c_main_controller(cinfo, FALSE /* never need full buffer here */);
else
#ifdef C_LOSSLESS_SUPPORTED
j16init_c_main_controller(cinfo, FALSE /* never need full buffer here */);
#else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#endif
else if (cinfo->data_precision == 12)
j12init_c_main_controller(cinfo, FALSE /* never need full buffer here */);
else
jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
jinit_marker_writer(cinfo);

View File

@@ -6,7 +6,7 @@
* Lossless JPEG Modifications:
* Copyright (C) 1999, Ken Murchison.
* libjpeg-turbo Modifications:
* Copyright (C) 2022, D. R. Commander.
* Copyright (C) 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -308,6 +308,14 @@ _jinit_lossless_compressor(j_compress_ptr cinfo)
{
lossless_comp_ptr losslessc;
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Create subobject in permanent pool */
losslessc = (lossless_comp_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,

View File

@@ -6,7 +6,7 @@
* Lossless JPEG Modifications:
* Copyright (C) 1999, Ken Murchison.
* libjpeg-turbo Modifications:
* Copyright (C) 2022, D. R. Commander.
* Copyright (C) 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -140,8 +140,21 @@ _jinit_c_main_controller(j_compress_ptr cinfo, boolean need_full_buffer)
jpeg_component_info *compptr;
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#ifdef C_LOSSLESS_SUPPORTED
if (cinfo->master->lossless) {
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
} else
#endif
{
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,

View File

@@ -190,13 +190,19 @@ initial_setup(j_compress_ptr cinfo, boolean transcode_only)
if ((long)jd_samplesperrow != samplesperrow)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
/* Lossy JPEG images must have 8 or 12 bits per sample. Lossless JPEG images
* can have 2 to 16 bits per sample.
*/
#ifdef C_LOSSLESS_SUPPORTED
if (cinfo->data_precision != 8 && cinfo->data_precision != 12 &&
cinfo->data_precision != 16)
#else
if (cinfo->data_precision != 8 && cinfo->data_precision != 12)
if (cinfo->master->lossless) {
if (cinfo->data_precision < 2 || cinfo->data_precision > 16)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
} else
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
{
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 */
if (cinfo->num_components > MAX_COMPONENTS)

View File

@@ -6,7 +6,7 @@
* Lossless JPEG Modifications:
* Copyright (C) 1999, Ken Murchison.
* libjpeg-turbo Modifications:
* Copyright (C) 2022, D. R. Commander.
* Copyright (C) 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -324,8 +324,21 @@ _jinit_c_prep_controller(j_compress_ptr cinfo, boolean need_full_buffer)
jpeg_component_info *compptr;
int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#ifdef C_LOSSLESS_SUPPORTED
if (cinfo->master->lossless) {
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
} else
#endif
{
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);

View File

@@ -8,7 +8,7 @@
* libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2014, MIPS Technologies, Inc., California.
* Copyright (C) 2015, 2019, 2022, D. R. Commander.
* Copyright (C) 2015, 2019, 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -470,8 +470,21 @@ _jinit_downsampler(j_compress_ptr cinfo)
jpeg_component_info *compptr;
boolean smoothok = TRUE;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#ifdef C_LOSSLESS_SUPPORTED
if (cinfo->master->lossless) {
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
} else
#endif
{
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,

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, 2015-2020, 2022-2023, D. R. Commander.
* Copyright (C) 2010, 2015-2020, 2022-2024, D. R. Commander.
* Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
@@ -128,20 +128,19 @@ output_pass_setup(j_decompress_ptr cinfo)
}
/* Process some data */
last_scanline = cinfo->output_scanline;
#ifdef D_LOSSLESS_SUPPORTED
if (cinfo->data_precision == 16)
(*cinfo->main->process_data_16) (cinfo, (J16SAMPARRAY)NULL,
&cinfo->output_scanline,
(JDIMENSION)0);
else
#endif
if (cinfo->data_precision == 12)
if (cinfo->data_precision <= 8)
(*cinfo->main->process_data) (cinfo, (JSAMPARRAY)NULL,
&cinfo->output_scanline, (JDIMENSION)0);
else if (cinfo->data_precision <= 12)
(*cinfo->main->process_data_12) (cinfo, (J12SAMPARRAY)NULL,
&cinfo->output_scanline,
(JDIMENSION)0);
#ifdef D_LOSSLESS_SUPPORTED
else
(*cinfo->main->process_data) (cinfo, (JSAMPARRAY)NULL,
&cinfo->output_scanline, (JDIMENSION)0);
(*cinfo->main->process_data_16) (cinfo, (J16SAMPARRAY)NULL,
&cinfo->output_scanline,
(JDIMENSION)0);
#endif
if (cinfo->output_scanline == last_scanline)
return FALSE; /* No progress made, must suspend */
}
@@ -313,8 +312,21 @@ _jpeg_read_scanlines(j_decompress_ptr cinfo, _JSAMPARRAY scanlines,
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
JDIMENSION row_ctr;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#ifdef D_LOSSLESS_SUPPORTED
if (cinfo->master->lossless) {
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
} else
#endif
{
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);

View File

@@ -6,7 +6,7 @@
* Modified 2011 by Guido Vollbeding.
* libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2009, 2011-2012, 2014-2015, 2022, D. R. Commander.
* Copyright (C) 2009, 2011-2012, 2014-2015, 2022, 2024, D. R. Commander.
* Copyright (C) 2013, Linaro Limited.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
@@ -759,8 +759,21 @@ _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);
#ifdef D_LOSSLESS_SUPPORTED
if (cinfo->master->lossless) {
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
} else
#endif
{
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,

View File

@@ -6,7 +6,7 @@
* Lossless JPEG Modifications:
* Copyright (C) 1999, Ken Murchison.
* libjpeg-turbo Modifications:
* Copyright (C) 2022, D. R. Commander.
* Copyright (C) 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -350,6 +350,14 @@ _jinit_d_diff_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
int ci;
jpeg_component_info *compptr;
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
diff = (my_diff_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_diff_controller));

View File

@@ -6,7 +6,7 @@
* Lossless JPEG Modifications:
* Copyright (C) 1999, Ken Murchison.
* libjpeg-turbo Modifications:
* Copyright (C) 2010, 2016, 2018, 2022, D. R. Commander.
* Copyright (C) 2010, 2016, 2018, 2022, 2024, D. R. Commander.
* Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
@@ -56,14 +56,19 @@ initial_setup(j_decompress_ptr cinfo)
(long)cinfo->image_width > (long)JPEG_MAX_DIMENSION)
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int)JPEG_MAX_DIMENSION);
/* For now, precision must match compiled-in value... */
/* Lossy JPEG images must have 8 or 12 bits per sample. Lossless JPEG images
* can have 2 to 16 bits per sample.
*/
#ifdef D_LOSSLESS_SUPPORTED
if (cinfo->data_precision != 8 && cinfo->data_precision != 12 &&
cinfo->data_precision != 16)
#else
if (cinfo->data_precision != 8 && cinfo->data_precision != 12)
if (cinfo->master->lossless) {
if (cinfo->data_precision < 2 || cinfo->data_precision > 16)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
} else
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
{
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 */
if (cinfo->num_components > MAX_COMPONENTS)

View File

@@ -6,7 +6,7 @@
* Lossless JPEG Modifications:
* Copyright (C) 1999, Ken Murchison.
* libjpeg-turbo Modifications:
* Copyright (C) 2022, D. R. Commander.
* Copyright (C) 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -278,6 +278,14 @@ _jinit_lossless_decompressor(j_decompress_ptr cinfo)
{
lossless_decomp_ptr losslessd;
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Create subobject in permanent pool */
losslessd = (lossless_decomp_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,

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, 2022, D. R. Commander.
* Copyright (C) 2010, 2016, 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -431,8 +431,21 @@ _jinit_d_main_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
int ci, rgroup, ngroups;
jpeg_component_info *compptr;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#ifdef D_LOSSLESS_SUPPORTED
if (cinfo->master->lossless) {
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
} else
#endif
{
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,

View File

@@ -7,7 +7,7 @@
* Lossless JPEG Modifications:
* Copyright (C) 1999, Ken Murchison.
* libjpeg-turbo Modifications:
* Copyright (C) 2009-2011, 2016, 2019, 2022-2023, D. R. Commander.
* Copyright (C) 2009-2011, 2016, 2019, 2022-2024, D. R. Commander.
* Copyright (C) 2013, Linaro Limited.
* Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg
@@ -422,7 +422,50 @@ prepare_range_limit_table(j_decompress_ptr cinfo)
#endif
int i;
if (cinfo->data_precision == 16) {
if (cinfo->data_precision <= 8) {
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));
} else if (cinfo->data_precision <= 12) {
table12 = (J12SAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(5 * (MAXJ12SAMPLE + 1) + CENTERJ12SAMPLE) *
sizeof(J12SAMPLE));
table12 += (MAXJ12SAMPLE + 1); /* allow negative subscripts of simple
table */
cinfo->sample_range_limit = (JSAMPLE *)table12;
/* First segment of "simple" table: limit[x] = 0 for x < 0 */
memset(table12 - (MAXJ12SAMPLE + 1), 0,
(MAXJ12SAMPLE + 1) * sizeof(J12SAMPLE));
/* Main part of "simple" table: limit[x] = x */
for (i = 0; i <= MAXJ12SAMPLE; i++)
table12[i] = (J12SAMPLE)i;
table12 += CENTERJ12SAMPLE; /* Point to where post-IDCT table starts */
/* End of simple table, rest of first half of post-IDCT table */
for (i = CENTERJ12SAMPLE; i < 2 * (MAXJ12SAMPLE + 1); i++)
table12[i] = MAXJ12SAMPLE;
/* Second half of post-IDCT table */
memset(table12 + (2 * (MAXJ12SAMPLE + 1)), 0,
(2 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE) * sizeof(J12SAMPLE));
memcpy(table12 + (4 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE),
cinfo->sample_range_limit, CENTERJ12SAMPLE * sizeof(J12SAMPLE));
} else {
#ifdef D_LOSSLESS_SUPPORTED
table16 = (J16SAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
@@ -449,49 +492,6 @@ prepare_range_limit_table(j_decompress_ptr cinfo)
#else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#endif
} else if (cinfo->data_precision == 12) {
table12 = (J12SAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(5 * (MAXJ12SAMPLE + 1) + CENTERJ12SAMPLE) *
sizeof(J12SAMPLE));
table12 += (MAXJ12SAMPLE + 1); /* allow negative subscripts of simple
table */
cinfo->sample_range_limit = (JSAMPLE *)table12;
/* First segment of "simple" table: limit[x] = 0 for x < 0 */
memset(table12 - (MAXJ12SAMPLE + 1), 0,
(MAXJ12SAMPLE + 1) * sizeof(J12SAMPLE));
/* Main part of "simple" table: limit[x] = x */
for (i = 0; i <= MAXJ12SAMPLE; i++)
table12[i] = (J12SAMPLE)i;
table12 += CENTERJ12SAMPLE; /* Point to where post-IDCT table starts */
/* End of simple table, rest of first half of post-IDCT table */
for (i = CENTERJ12SAMPLE; i < 2 * (MAXJ12SAMPLE + 1); i++)
table12[i] = MAXJ12SAMPLE;
/* Second half of post-IDCT table */
memset(table12 + (2 * (MAXJ12SAMPLE + 1)), 0,
(2 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE) * sizeof(J12SAMPLE));
memcpy(table12 + (4 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE),
cinfo->sample_range_limit, CENTERJ12SAMPLE * sizeof(J12SAMPLE));
} else {
table = (JSAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(5 * (MAXJSAMPLE + 1) + CENTERJSAMPLE) * sizeof(JSAMPLE));
table += (MAXJSAMPLE + 1); /* allow negative subscripts of simple table */
cinfo->sample_range_limit = table;
/* First segment of "simple" table: limit[x] = 0 for x < 0 */
memset(table - (MAXJSAMPLE + 1), 0, (MAXJSAMPLE + 1) * sizeof(JSAMPLE));
/* Main part of "simple" table: limit[x] = x */
for (i = 0; i <= MAXJSAMPLE; i++)
table[i] = (JSAMPLE)i;
table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
/* End of simple table, rest of first half of post-IDCT table */
for (i = CENTERJSAMPLE; i < 2 * (MAXJSAMPLE + 1); i++)
table[i] = MAXJSAMPLE;
/* Second half of post-IDCT table */
memset(table + (2 * (MAXJSAMPLE + 1)), 0,
(2 * (MAXJSAMPLE + 1) - CENTERJSAMPLE) * sizeof(JSAMPLE));
memcpy(table + (4 * (MAXJSAMPLE + 1) - CENTERJSAMPLE),
cinfo->sample_range_limit, CENTERJSAMPLE * sizeof(JSAMPLE));
}
}
@@ -570,12 +570,12 @@ master_selection(j_decompress_ptr cinfo)
if (cinfo->enable_1pass_quant) {
#ifdef QUANT_1PASS_SUPPORTED
if (cinfo->data_precision == 16)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if (cinfo->data_precision == 8)
jinit_1pass_quantizer(cinfo);
else if (cinfo->data_precision == 12)
j12init_1pass_quantizer(cinfo);
else
jinit_1pass_quantizer(cinfo);
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
master->quantizer_1pass = cinfo->cquantize;
#else
ERREXIT(cinfo, JERR_NOT_COMPILED);
@@ -585,12 +585,12 @@ master_selection(j_decompress_ptr cinfo)
/* We use the 2-pass code to map to external colormaps. */
if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
#ifdef QUANT_2PASS_SUPPORTED
if (cinfo->data_precision == 16)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if (cinfo->data_precision == 8)
jinit_2pass_quantizer(cinfo);
else if (cinfo->data_precision == 12)
j12init_2pass_quantizer(cinfo);
else
jinit_2pass_quantizer(cinfo);
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
master->quantizer_2pass = cinfo->cquantize;
#else
ERREXIT(cinfo, JERR_NOT_COMPILED);
@@ -605,41 +605,41 @@ master_selection(j_decompress_ptr cinfo)
if (!cinfo->raw_data_out) {
if (master->using_merged_upsample) {
#ifdef UPSAMPLE_MERGING_SUPPORTED
if (cinfo->data_precision == 16)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if (cinfo->data_precision == 8)
jinit_merged_upsampler(cinfo); /* does color conversion too */
else if (cinfo->data_precision == 12)
j12init_merged_upsampler(cinfo); /* does color conversion too */
else
jinit_merged_upsampler(cinfo); /* does color conversion too */
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#else
ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif
} else {
if (cinfo->data_precision == 16) {
if (cinfo->data_precision <= 8) {
jinit_color_deconverter(cinfo);
jinit_upsampler(cinfo);
} else if (cinfo->data_precision <= 12) {
j12init_color_deconverter(cinfo);
j12init_upsampler(cinfo);
} else {
#ifdef D_LOSSLESS_SUPPORTED
j16init_color_deconverter(cinfo);
j16init_upsampler(cinfo);
#else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#endif
} else if (cinfo->data_precision == 12) {
j12init_color_deconverter(cinfo);
j12init_upsampler(cinfo);
} else {
jinit_color_deconverter(cinfo);
jinit_upsampler(cinfo);
}
}
if (cinfo->data_precision == 16)
if (cinfo->data_precision <= 8)
jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
else if (cinfo->data_precision <= 12)
j12init_d_post_controller(cinfo, cinfo->enable_2pass_quant);
else
#ifdef D_LOSSLESS_SUPPORTED
j16init_d_post_controller(cinfo, cinfo->enable_2pass_quant);
#else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#endif
else if (cinfo->data_precision == 12)
j12init_d_post_controller(cinfo, cinfo->enable_2pass_quant);
else
jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
}
if (cinfo->master->lossless) {
@@ -647,12 +647,12 @@ master_selection(j_decompress_ptr cinfo)
/* Prediction, sample undifferencing, point transform, and sample size
* scaling
*/
if (cinfo->data_precision == 16)
j16init_lossless_decompressor(cinfo);
else if (cinfo->data_precision == 12)
if (cinfo->data_precision <= 8)
jinit_lossless_decompressor(cinfo);
else if (cinfo->data_precision <= 12)
j12init_lossless_decompressor(cinfo);
else
jinit_lossless_decompressor(cinfo);
j16init_lossless_decompressor(cinfo);
/* Entropy decoding: either Huffman or arithmetic coding. */
if (cinfo->arith_code) {
ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
@@ -663,23 +663,23 @@ master_selection(j_decompress_ptr cinfo)
/* Initialize principal buffer controllers. */
use_c_buffer = cinfo->inputctl->has_multiple_scans ||
cinfo->buffered_image;
if (cinfo->data_precision == 16)
j16init_d_diff_controller(cinfo, use_c_buffer);
else if (cinfo->data_precision == 12)
if (cinfo->data_precision <= 8)
jinit_d_diff_controller(cinfo, use_c_buffer);
else if (cinfo->data_precision <= 12)
j12init_d_diff_controller(cinfo, use_c_buffer);
else
jinit_d_diff_controller(cinfo, use_c_buffer);
j16init_d_diff_controller(cinfo, use_c_buffer);
#else
ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif
} else {
if (cinfo->data_precision == 16)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Inverse DCT */
if (cinfo->data_precision == 12)
if (cinfo->data_precision == 8)
jinit_inverse_dct(cinfo);
else if (cinfo->data_precision == 12)
j12init_inverse_dct(cinfo);
else
jinit_inverse_dct(cinfo);
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Entropy decoding: either Huffman or arithmetic coding. */
if (cinfo->arith_code) {
#ifdef D_ARITH_CODING_SUPPORTED
@@ -708,18 +708,18 @@ master_selection(j_decompress_ptr cinfo)
}
if (!cinfo->raw_data_out) {
if (cinfo->data_precision == 16)
if (cinfo->data_precision <= 8)
jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
else if (cinfo->data_precision <= 12)
j12init_d_main_controller(cinfo,
FALSE /* never need full buffer here */);
else
#ifdef D_LOSSLESS_SUPPORTED
j16init_d_main_controller(cinfo,
FALSE /* never need full buffer here */);
#else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#endif
else if (cinfo->data_precision == 12)
j12init_d_main_controller(cinfo,
FALSE /* never need full buffer here */);
else
jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
}
/* We can now tell the memory manager to allocate virtual arrays. */

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) 2022-2023, D. R. Commander.
* Copyright (C) 2022-2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -267,8 +267,21 @@ _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);
#ifdef D_LOSSLESS_SUPPORTED
if (cinfo->master->lossless) {
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
} else
#endif
{
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,

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, 2022, D. R. Commander.
* Copyright (C) 2010, 2015-2016, 2022, 2024, D. R. Commander.
* Copyright (C) 2014, MIPS Technologies, Inc., California.
* Copyright (C) 2015, Google, Inc.
* Copyright (C) 2019-2020, Arm Limited.
@@ -421,8 +421,21 @@ _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);
#ifdef D_LOSSLESS_SUPPORTED
if (cinfo->master->lossless) {
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
} else
#endif
{
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)

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) 2016, 2021-2022, D. R. Commander.
* Copyright (C) 2016, 2021-2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -156,8 +156,9 @@ typedef my_memory_mgr *my_mem_ptr;
struct jvirt_sarray_control {
JSAMPARRAY mem_buffer; /* => the in-memory buffer (if
cinfo->data_precision is 12, then this is
actually a J12SAMPARRAY) */
cinfo->data_precision > 8, then this is
actually a J12SAMPARRAY or a
J16SAMPARRAY) */
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 */
@@ -449,8 +450,8 @@ alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow,
int data_precision = cinfo->is_decompressor ?
((j_decompress_ptr)cinfo)->data_precision :
((j_compress_ptr)cinfo)->data_precision;
size_t sample_size = data_precision == 16 ?
sizeof(J16SAMPLE) : (data_precision == 12 ?
size_t sample_size = data_precision > 12 ?
sizeof(J16SAMPLE) : (data_precision > 8 ?
sizeof(J12SAMPLE) :
sizeof(JSAMPLE));
@@ -477,7 +478,44 @@ alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow,
rowsperchunk = numrows;
mem->last_rowsperchunk = rowsperchunk;
if (data_precision == 16) {
if (data_precision <= 8) {
/* 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;
} else if (data_precision <= 12) {
/* Get space for row pointers (small object) */
result12 = (J12SAMPARRAY)alloc_small(cinfo, pool_id,
(size_t)(numrows *
sizeof(J12SAMPROW)));
/* Get the rows themselves (large objects) */
currow = 0;
while (currow < numrows) {
rowsperchunk = MIN(rowsperchunk, numrows - currow);
workspace12 = (J12SAMPROW)alloc_large(cinfo, pool_id,
(size_t)((size_t)rowsperchunk * (size_t)samplesperrow * sample_size));
for (i = rowsperchunk; i > 0; i--) {
result12[currow++] = workspace12;
workspace12 += samplesperrow;
}
}
return (JSAMPARRAY)result12;
} else {
#if defined(C_LOSSLESS_SUPPORTED) || defined(D_LOSSLESS_SUPPORTED)
/* Get space for row pointers (small object) */
result16 = (J16SAMPARRAY)alloc_small(cinfo, pool_id,
@@ -501,43 +539,6 @@ alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow,
ERREXIT1(cinfo, JERR_BAD_PRECISION, data_precision);
return NULL;
#endif
} else if (data_precision == 12) {
/* Get space for row pointers (small object) */
result12 = (J12SAMPARRAY)alloc_small(cinfo, pool_id,
(size_t)(numrows *
sizeof(J12SAMPROW)));
/* Get the rows themselves (large objects) */
currow = 0;
while (currow < numrows) {
rowsperchunk = MIN(rowsperchunk, numrows - currow);
workspace12 = (J12SAMPROW)alloc_large(cinfo, pool_id,
(size_t)((size_t)rowsperchunk * (size_t)samplesperrow * sample_size));
for (i = rowsperchunk; i > 0; i--) {
result12[currow++] = workspace12;
workspace12 += samplesperrow;
}
}
return (JSAMPARRAY)result12;
} else {
/* Get space for row pointers (small object) */
result = (JSAMPARRAY)alloc_small(cinfo, pool_id,
(size_t)(numrows * sizeof(JSAMPROW)));
/* Get the rows themselves (large objects) */
currow = 0;
while (currow < numrows) {
rowsperchunk = MIN(rowsperchunk, numrows - currow);
workspace = (JSAMPROW)alloc_large(cinfo, pool_id,
(size_t)((size_t)rowsperchunk * (size_t)samplesperrow * sample_size));
for (i = rowsperchunk; i > 0; i--) {
result[currow++] = workspace;
workspace += samplesperrow;
}
}
return result;
}
}
@@ -703,8 +704,8 @@ realize_virt_arrays(j_common_ptr cinfo)
int data_precision = cinfo->is_decompressor ?
((j_decompress_ptr)cinfo)->data_precision :
((j_compress_ptr)cinfo)->data_precision;
size_t sample_size = data_precision == 16 ?
sizeof(J16SAMPLE) : (data_precision == 12 ?
size_t sample_size = data_precision > 12 ?
sizeof(J16SAMPLE) : (data_precision > 8 ?
sizeof(J12SAMPLE) :
sizeof(JSAMPLE));
@@ -821,8 +822,8 @@ do_sarray_io(j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
int data_precision = cinfo->is_decompressor ?
((j_decompress_ptr)cinfo)->data_precision :
((j_compress_ptr)cinfo)->data_precision;
size_t sample_size = data_precision == 16 ?
sizeof(J16SAMPLE) : (data_precision == 12 ?
size_t sample_size = data_precision > 12 ?
sizeof(J16SAMPLE) : (data_precision > 8 ?
sizeof(J12SAMPLE) :
sizeof(JSAMPLE));
@@ -840,7 +841,27 @@ 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 (data_precision == 16) {
if (data_precision <= 8) {
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);
} else if (data_precision <= 12) {
J12SAMPARRAY mem_buffer12 = (J12SAMPARRAY)ptr->mem_buffer;
if (writing)
(*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info,
(void *)mem_buffer12[i],
file_offset, byte_count);
else
(*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info,
(void *)mem_buffer12[i],
file_offset, byte_count);
} else {
#if defined(C_LOSSLESS_SUPPORTED) || defined(D_LOSSLESS_SUPPORTED)
J16SAMPARRAY mem_buffer16 = (J16SAMPARRAY)ptr->mem_buffer;
@@ -855,26 +876,6 @@ do_sarray_io(j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
#else
ERREXIT1(cinfo, JERR_BAD_PRECISION, data_precision);
#endif
} else if (data_precision == 12) {
J12SAMPARRAY mem_buffer12 = (J12SAMPARRAY)ptr->mem_buffer;
if (writing)
(*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info,
(void *)mem_buffer12[i],
file_offset, byte_count);
else
(*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info,
(void *)mem_buffer12[i],
file_offset, byte_count);
} else {
if (writing)
(*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info,
(void *)ptr->mem_buffer[i],
file_offset, byte_count);
else
(*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info,
(void *)ptr->mem_buffer[i],
file_offset, byte_count);
}
file_offset += byte_count;
}
@@ -926,8 +927,8 @@ access_virt_sarray(j_common_ptr cinfo, jvirt_sarray_ptr ptr,
int data_precision = cinfo->is_decompressor ?
((j_decompress_ptr)cinfo)->data_precision :
((j_compress_ptr)cinfo)->data_precision;
size_t sample_size = data_precision == 16 ?
sizeof(J16SAMPLE) : (data_precision == 12 ?
size_t sample_size = data_precision > 12 ?
sizeof(J16SAMPLE) : (data_precision > 8 ?
sizeof(J12SAMPLE) :
sizeof(JSAMPLE));

View File

@@ -86,22 +86,26 @@ extern "C" {
/* Data structures for images (arrays of samples and of DCT coefficients).
*/
typedef JSAMPLE *JSAMPROW; /* ptr to one image row of pixel samples. */
typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
typedef JSAMPLE *JSAMPROW; /* ptr to one image row of pixel samples with
2-bit through 8-bit data precision. */
typedef JSAMPROW *JSAMPARRAY; /* ptr to some JSAMPLE rows (a 2-D JSAMPLE
array) */
typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D JSAMPLE array: top index is color */
typedef J12SAMPLE *J12SAMPROW; /* ptr to one image row of 12-bit pixel
samples. */
typedef J12SAMPROW *J12SAMPARRAY; /* ptr to some 12-bit sample rows (a 2-D
12-bit sample array) */
typedef J12SAMPARRAY *J12SAMPIMAGE; /* a 3-D 12-bit sample array: top index is
typedef J12SAMPLE *J12SAMPROW; /* ptr to one image row of pixel samples
with 9-bit through 12-bit data
precision. */
typedef J12SAMPROW *J12SAMPARRAY; /* ptr to some J12SAMPLE rows (a 2-D
J12SAMPLE array) */
typedef J12SAMPARRAY *J12SAMPIMAGE; /* a 3-D J12SAMPLE array: top index is
color */
typedef J16SAMPLE *J16SAMPROW; /* ptr to one image row of 16-bit pixel
samples. */
typedef J16SAMPROW *J16SAMPARRAY; /* ptr to some 16-bit sample rows (a 2-D
16-bit sample array) */
typedef J16SAMPARRAY *J16SAMPIMAGE; /* a 3-D 16-bit sample array: top index is
typedef J16SAMPLE *J16SAMPROW; /* ptr to one image row of pixel samples
with 13-bit through 16-bit data
precision. */
typedef J16SAMPROW *J16SAMPARRAY; /* ptr to some J16SAMPLE rows (a 2-D
J16SAMPLE array) */
typedef J16SAMPARRAY *J16SAMPIMAGE; /* a 3-D J16SAMPLE array: top index is
color */
typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
@@ -708,11 +712,12 @@ struct jpeg_decompress_struct {
*/
JSAMPLE *sample_range_limit; /* table for fast range-limiting
If data_precision is 12 or 16, then this is
actually a J12SAMPLE pointer or a J16SAMPLE
pointer, so callers must type-cast it in
order to read 12-bit or 16-bit samples from
the array. */
If data_precision is 9 to 12, then this is
actually a J12SAMPLE pointer, and if
data_precision is 13 to 16, then this is
actually a J16SAMPLE pointer, so callers
must type-cast it in order to read samples
from the array. */
/*
* These fields are valid during any one scan.

View File

@@ -6,7 +6,7 @@
* Modified 2009-2017 by Guido Vollbeding.
* libjpeg-turbo Modifications:
* Modified 2011 by Siarhei Siamashka.
* Copyright (C) 2015, 2017-2018, 2021-2023, D. R. Commander.
* Copyright (C) 2015, 2017-2018, 2021-2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -180,7 +180,7 @@ get_8bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
t = *inptr++;
if (t >= cmaplen)
ERREXIT(cinfo, JERR_BMP_OUTOFRANGE);
rgb_to_cmyk(colormap[0][t], colormap[1][t], colormap[2][t], outptr,
rgb_to_cmyk(255, colormap[0][t], colormap[1][t], colormap[2][t], outptr,
outptr + 1, outptr + 2, outptr + 3);
outptr += 4;
}
@@ -250,7 +250,7 @@ get_24bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
} else if (cinfo->in_color_space == JCS_CMYK) {
for (col = cinfo->image_width; col > 0; col--) {
JSAMPLE b = *inptr++, g = *inptr++, r = *inptr++;
rgb_to_cmyk(r, g, b, outptr, outptr + 1, outptr + 2, outptr + 3);
rgb_to_cmyk(255, r, g, b, outptr, outptr + 1, outptr + 2, outptr + 3);
outptr += 4;
}
} else {
@@ -314,7 +314,7 @@ get_32bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
} else if (cinfo->in_color_space == JCS_CMYK) {
for (col = cinfo->image_width; col > 0; col--) {
JSAMPLE b = *inptr++, g = *inptr++, r = *inptr++;
rgb_to_cmyk(r, g, b, outptr, outptr + 1, outptr + 2, outptr + 3);
rgb_to_cmyk(255, r, g, b, outptr, outptr + 1, outptr + 2, outptr + 3);
inptr++; /* skip the 4th byte (Alpha channel) */
outptr += 4;
}

View File

@@ -125,10 +125,11 @@ 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 cinfo->data_precision.
*
* 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 and maxval == (1U << cinfo->data_precision) - 1U,
* which is the normal case for 8-bit data.
*/
@@ -177,16 +178,16 @@ get_text_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
register int ps = rgb_pixelsize[cinfo->in_color_space];
ptr = source->pub._buffer[0];
if (maxval == _MAXJSAMPLE) {
if (maxval == (1U << cinfo->data_precision) - 1U) {
if (aindex >= 0)
GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
ptr[aindex] = _MAXJSAMPLE;)
ptr[aindex] = (_JSAMPLE)maxval;)
else
GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
} else {
if (aindex >= 0)
GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
ptr[aindex] = _MAXJSAMPLE;)
ptr[aindex] = (1 << cinfo->data_precision) - 1;)
else
GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
}
@@ -207,16 +208,16 @@ get_text_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
unsigned int maxval = source->maxval;
ptr = source->pub._buffer[0];
if (maxval == _MAXJSAMPLE) {
if (maxval == (1U << cinfo->data_precision) - 1U) {
for (col = cinfo->image_width; col > 0; col--) {
_JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
rgb_to_cmyk(maxval, 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)];
rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
}
@@ -251,16 +252,16 @@ get_text_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
register int ps = rgb_pixelsize[cinfo->in_color_space];
ptr = source->pub._buffer[0];
if (maxval == _MAXJSAMPLE) {
if (maxval == (1U << cinfo->data_precision) - 1U) {
if (aindex >= 0)
RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
ptr[aindex] = _MAXJSAMPLE;)
ptr[aindex] = (_JSAMPLE)maxval;)
else
RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
} else {
if (aindex >= 0)
RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
ptr[aindex] = _MAXJSAMPLE;)
ptr[aindex] = (1 << cinfo->data_precision) - 1;)
else
RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
}
@@ -281,12 +282,12 @@ get_text_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
unsigned int maxval = source->maxval;
ptr = source->pub._buffer[0];
if (maxval == _MAXJSAMPLE) {
if (maxval == (1U << cinfo->data_precision) - 1U) {
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);
rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
} else {
@@ -294,7 +295,7 @@ get_text_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
_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);
rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
}
@@ -344,15 +345,15 @@ get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
ERREXIT(cinfo, JERR_INPUT_EOF);
ptr = source->pub._buffer[0];
bufferptr = source->iobuffer;
if (maxval == _MAXJSAMPLE) {
if (maxval == (1U << cinfo->data_precision) - 1U) {
if (aindex >= 0)
GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;)
GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
else
GRAY_RGB_READ_LOOP(*bufferptr++, {})
} else {
if (aindex >= 0)
GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
ptr[aindex] = _MAXJSAMPLE;)
ptr[aindex] = (1 << cinfo->data_precision) - 1;)
else
GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
}
@@ -376,16 +377,16 @@ get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
ERREXIT(cinfo, JERR_INPUT_EOF);
ptr = source->pub._buffer[0];
bufferptr = source->iobuffer;
if (maxval == _MAXJSAMPLE) {
if (maxval == (1U << cinfo->data_precision) - 1U) {
for (col = cinfo->image_width; col > 0; col--) {
_JSAMPLE gray = *bufferptr++;
rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
rgb_to_cmyk(maxval, 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++)];
rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
rgb_to_cmyk(maxval, gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
}
@@ -413,14 +414,15 @@ get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
ERREXIT(cinfo, JERR_INPUT_EOF);
ptr = source->pub._buffer[0];
bufferptr = source->iobuffer;
if (maxval == _MAXJSAMPLE) {
if (maxval == (1U << cinfo->data_precision) - 1U) {
if (aindex >= 0)
RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;)
RGB_READ_LOOP(*bufferptr++, ptr[aindex] = (_JSAMPLE)maxval;)
else
RGB_READ_LOOP(*bufferptr++, {})
} else {
if (aindex >= 0)
RGB_READ_LOOP(rescale[UCH(*bufferptr++)], ptr[aindex] = _MAXJSAMPLE;)
RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
ptr[aindex] = (1 << cinfo->data_precision) - 1;)
else
RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
}
@@ -444,12 +446,12 @@ get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
ERREXIT(cinfo, JERR_INPUT_EOF);
ptr = source->pub._buffer[0];
bufferptr = source->iobuffer;
if (maxval == _MAXJSAMPLE) {
if (maxval == (1U << cinfo->data_precision) - 1U) {
for (col = cinfo->image_width; col > 0; col--) {
_JSAMPLE r = *bufferptr++;
_JSAMPLE g = *bufferptr++;
_JSAMPLE b = *bufferptr++;
rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
} else {
@@ -457,7 +459,7 @@ get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
_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);
rgb_to_cmyk(maxval, r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
}
@@ -467,7 +469,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.
/* This version is for reading raw-byte-format files with
* maxval <= _MAXJSAMPLE and maxval == (1U << cinfo->data_precision) - 1U.
* In this case we just read right into the _JSAMPLE buffer!
* Note that same code works for PPM and PGM files.
*/
@@ -535,7 +538,7 @@ get_word_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
if (aindex >= 0)
ptr[aindex] = _MAXJSAMPLE;
ptr[aindex] = (1 << cinfo->data_precision) - 1;
ptr += ps;
}
return 1;
@@ -563,8 +566,8 @@ get_word_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
gray |= UCH(*bufferptr++);
if (gray > maxval)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
rgb_to_cmyk(rescale[gray], rescale[gray], rescale[gray], ptr, ptr + 1,
ptr + 2, ptr + 3);
rgb_to_cmyk(maxval, rescale[gray], rescale[gray], rescale[gray], ptr,
ptr + 1, ptr + 2, ptr + 3);
ptr += 4;
}
return 1;
@@ -609,7 +612,7 @@ get_word_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
ptr[bindex] = rescale[temp];
if (aindex >= 0)
ptr[aindex] = _MAXJSAMPLE;
ptr[aindex] = (1 << cinfo->data_precision) - 1;
ptr += ps;
}
return 1;
@@ -645,8 +648,8 @@ get_word_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
b |= UCH(*bufferptr++);
if (b > maxval)
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
rgb_to_cmyk(rescale[r], rescale[g], rescale[b], ptr, ptr + 1, ptr + 2,
ptr + 3);
rgb_to_cmyk(maxval, rescale[r], rescale[g], rescale[b], ptr, ptr + 1,
ptr + 2, ptr + 3);
ptr += 4;
}
return 1;
@@ -692,7 +695,6 @@ start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels);
cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */
cinfo->image_width = (JDIMENSION)w;
cinfo->image_height = (JDIMENSION)h;
source->maxval = maxval;
@@ -746,7 +748,8 @@ start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
source->pub.get_pixel_rows = get_word_gray_cmyk_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) &&
maxval == ((1U << cinfo->data_precision) - 1U) &&
cinfo->in_color_space == JCS_GRAYSCALE) {
source->pub.get_pixel_rows = get_raw_row;
use_raw_buffer = TRUE;
@@ -774,7 +777,8 @@ start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
source->pub.get_pixel_rows = get_word_rgb_cmyk_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) &&
maxval == ((1U << cinfo->data_precision) - 1U) &&
#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)) {
@@ -844,8 +848,9 @@ start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
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) /
maxval);
source->rescale[val] =
(_JSAMPLE)((val * ((1 << cinfo->data_precision) - 1) + half_maxval) /
maxval);
}
}
}
@@ -871,7 +876,12 @@ _jinit_read_ppm(j_compress_ptr cinfo)
{
ppm_source_ptr source;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Create module interface object */

View File

@@ -238,9 +238,9 @@ static int decomp(unsigned char **jpegBufs, size_t *jpegSizes, void *dstBuf,
/* Set the destination buffer to gray so we know whether the decompressor
attempted to write to it */
if (precision == 8)
if (precision <= 8)
memset((unsigned char *)dstBuf, 127, (size_t)pitch * scaledh);
else if (precision == 12) {
else if (precision <= 12) {
for (i = 0; i < pitch * scaledh; i++)
((short *)dstBuf)[i] = (short)2047;
} else {
@@ -286,11 +286,11 @@ static int decomp(unsigned char **jpegBufs, size_t *jpegSizes, void *dstBuf,
THROW_TJ();
if (iter >= 0) elapsedDecode += getTime() - startDecode;
} else {
if (precision == 8) {
if (precision <= 8) {
if (tj3Decompress8(handle, jpegBufs[tile], jpegSizes[tile],
dstPtr2, pitch, pf) == -1)
THROW_TJ();
} else if (precision == 12) {
} else if (precision <= 12) {
if (tj3Decompress12(handle, jpegBufs[tile], jpegSizes[tile],
(short *)dstPtr2, pitch, pf) == -1)
THROW_TJ();
@@ -349,11 +349,11 @@ static int decomp(unsigned char **jpegBufs, size_t *jpegSizes, void *dstBuf,
SNPRINTF(tempStr, 1024, "%s_%s%s_%s.%s", fileName,
lossless ? "LOSSLS" : subName[subsamp], qualStr, sizeStr, ext);
if (precision == 8) {
if (precision <= 8) {
if (tj3SaveImage8(handle, tempStr, (unsigned char *)dstBuf, scaledw, 0,
scaledh, pf) == -1)
THROW_TJ();
} else if (precision == 12) {
} else if (precision <= 12) {
if (tj3SaveImage12(handle, tempStr, (short *)dstBuf, scaledw, 0, scaledh,
pf) == -1)
THROW_TJ();
@@ -432,7 +432,7 @@ static int fullTest(tjhandle handle, void *srcBuf, int w, int h, int subsamp,
if (quiet == 1)
printf("%-4s(%s) %-2d/%-6s %-3d ", pfStr, bottomUp ? "BU" : "TD",
precision, lossless ? "LOSSLS" : subNameLong[subsamp], jpegQual);
if (precision == 8) {
if (precision <= 8) {
for (i = 0; i < h; i++)
memcpy(&((unsigned char *)tmpBuf)[pitch * i],
&((unsigned char *)srcBuf)[w * ps * i], w * ps);
@@ -505,11 +505,11 @@ static int fullTest(tjhandle handle, void *srcBuf, int w, int h, int subsamp,
&jpegBufs[tile], &jpegSizes[tile]) == -1)
THROW_TJ();
} else {
if (precision == 8) {
if (precision <= 8) {
if (tj3Compress8(handle, srcPtr2, width, pitch, height, pf,
&jpegBufs[tile], &jpegSizes[tile]) == -1)
THROW_TJ();
} else if (precision == 12) {
} else if (precision <= 12) {
if (tj3Compress12(handle, (short *)srcPtr2, width, pitch, height,
pf, &jpegBufs[tile], &jpegSizes[tile]) == -1)
THROW_TJ();
@@ -688,7 +688,7 @@ static int decompTest(char *fileName)
THROW_TJ();
lossless = tj3Get(handle, TJPARAM_LOSSLESS);
sampleSize = (precision == 8 ? sizeof(unsigned char) : sizeof(short));
sampleSize = (precision <= 8 ? sizeof(unsigned char) : sizeof(short));
cs = tj3Get(handle, TJPARAM_COLORSPACE);
if (w < 1 || h < 1)
THROW("reading JPEG header", "Invalid image dimensions");
@@ -930,8 +930,8 @@ static void usage(char *progName)
printf(" [default = BGR]\n");
printf("-cmyk = Indirectly test YCCK JPEG compression/decompression\n");
printf(" (use the CMYK pixel format for packed-pixel source/destination buffers)\n");
printf("-precision N = Use N-bit data precision when compressing [N is 8, 12, or 16;\n");
printf(" default = 8; if N is 16, then -lossless must also be specified]\n");
printf("-precision N = Use N-bit data precision when compressing [N=2..16; default = 8;\n");
printf(" if N is not 8 or 12, then -lossless must also be specified]\n");
printf(" (-precision 12 implies -optimize unless -arithmetic is also specified)\n");
printf("-quiet = Output results in tabular rather than verbose format\n");
printf("-restart N = When compressing, add a restart marker every N MCU rows (lossy) or\n");
@@ -1037,7 +1037,7 @@ int main(int argc, char *argv[])
} else if (!strcasecmp(argv[i], "-precision") && i < argc - 1) {
int tempi = atoi(argv[++i]);
if (tempi != 8 && tempi != 12 && tempi != 16)
if (tempi < 2 || tempi > 16)
usage(argv[0]);
precision = tempi;
} else if (!strcasecmp(argv[i], "-fastupsample")) {
@@ -1206,8 +1206,9 @@ int main(int argc, char *argv[])
subsamp = TJSAMP_GRAY;
}
if (precision == 16 && !lossless) {
printf("ERROR: -lossless must be specified along with -precision 16\n");
if ((precision != 8 && precision != 12) && !lossless) {
printf("ERROR: -lossless must be specified along with -precision %d\n",
precision);
retval = -1; goto bailout;
}
if (precision != 8 && doYUV) {
@@ -1218,7 +1219,7 @@ int main(int argc, char *argv[])
printf("ERROR: -lossless and -yuv are incompatible\n");
retval = -1; goto bailout;
}
sampleSize = (precision == 8 ? sizeof(unsigned char) : sizeof(short));
sampleSize = (precision <= 8 ? sizeof(unsigned char) : sizeof(short));
if ((sf.num != 1 || sf.denom != 1) && doTile) {
printf("Disabling tiled compression/decompression tests, because those tests do not\n");
@@ -1255,13 +1256,15 @@ int main(int argc, char *argv[])
THROW_TJ();
if (tj3Set(handle, TJPARAM_BOTTOMUP, bottomUp) == -1)
THROW_TJ();
if (tj3Set(handle, TJPARAM_PRECISION, precision) == -1)
THROW_TJ();
if (tj3Set(handle, TJPARAM_MAXPIXELS, maxPixels) == -1)
THROW_TJ();
if (precision == 8) {
if (precision <= 8) {
if ((srcBuf = tj3LoadImage8(handle, argv[1], &w, 1, &h, &pf)) == NULL)
THROW_TJ();
} else if (precision == 12) {
} else if (precision <= 12) {
if ((srcBuf = tj3LoadImage12(handle, argv[1], &w, 1, &h, &pf)) == NULL)
THROW_TJ();
} else {

View File

@@ -62,8 +62,8 @@ static void usage(char *progName)
printf(" (8-bit data precision only)\n");
printf("-noyuvpad = do not pad each row in each Y, U, and V plane to the nearest\n");
printf(" multiple of 4 bytes\n");
printf("-precision N = test N-bit data precision (N is 8, 12, or 16; default is 8; if N\n");
printf(" is 16, then -lossless is implied)\n");
printf("-precision N = test N-bit data precision (N=2..16; default is 8; if N is not 8\n");
printf(" or 12, then -lossless is implied)\n");
printf("-lossless = test lossless JPEG compression/decompression\n");
printf("-alloc = test automatic JPEG buffer allocation\n");
printf("-bmp = test packed-pixel image I/O\n");
@@ -111,9 +111,9 @@ static int exitStatus = 0;
static void setVal(void *buf, int index, int value)
{
if (precision == 8)
if (precision <= 8)
((unsigned char *)buf)[index] = (unsigned char)value;
else if (precision == 12)
else if (precision <= 12)
((short *)buf)[index] = (short)value;
else
((unsigned short *)buf)[index] = (unsigned short)value;
@@ -201,9 +201,9 @@ static void initBuf(void *buf, int w, int h, int pf, int bottomUp)
static int getVal(void *buf, int index)
{
if (precision == 8)
if (precision <= 8)
return ((unsigned char *)buf)[index];
else if (precision == 12)
else if (precision <= 12)
return ((short *)buf)[index];
else
return ((unsigned short *)buf)[index];
@@ -440,15 +440,16 @@ static void compTest(tjhandle handle, unsigned char **dstBuf, size_t *dstSize,
TRY_TJ(handle, tj3CompressFromYUV8(handle, yuvBuf, w, yuvAlign, h, dstBuf,
dstSize));
} else {
if (lossless)
if (lossless) {
TRY_TJ(handle, tj3Set(handle, TJPARAM_PRECISION, precision));
printf("%s %s -> LOSSLESS PSV%d ... ", pfStr, buStrLong, jpegPSV);
else
} else
printf("%s %s -> %s Q%d ... ", pfStr, buStrLong, subNameLong[subsamp],
jpegQual);
if (precision == 8) {
if (precision <= 8) {
TRY_TJ(handle, tj3Compress8(handle, (unsigned char *)srcBuf, w, 0, h, pf,
dstBuf, dstSize));
} else if (precision == 12) {
} else if (precision <= 12) {
TRY_TJ(handle, tj3Compress12(handle, (short *)srcBuf, w, 0, h, pf,
dstBuf, dstSize));
} else {
@@ -536,10 +537,10 @@ static void _decompTest(tjhandle handle, unsigned char *jpegBuf,
if (sf.num != 1 || sf.denom != 1)
printf("%d/%d ... ", sf.num, sf.denom);
else printf("... ");
if (precision == 8) {
if (precision <= 8) {
TRY_TJ(handle, tj3Decompress8(handle, jpegBuf, jpegSize,
(unsigned char *)dstBuf, 0, pf));
} else if (precision == 12) {
} else if (precision <= 12) {
TRY_TJ(handle, tj3Decompress12(handle, jpegBuf, jpegSize,
(short *)dstBuf, 0, pf));
} else {
@@ -731,6 +732,7 @@ static void bufSizeTest(void)
TRY_TJ(handle, tj3Set(handle, TJPARAM_NOREALLOC, !alloc));
if (lossless) {
TRY_TJ(handle, tj3Set(handle, TJPARAM_PRECISION, precision));
TRY_TJ(handle, tj3Set(handle, TJPARAM_LOSSLESS, lossless));
TRY_TJ(handle, tj3Set(handle, TJPARAM_LOSSLESSPSV,
((psv++ - 1) % 7) + 1));
@@ -764,10 +766,10 @@ static void bufSizeTest(void)
TRY_TJ(handle, tj3EncodeYUV8(handle, (unsigned char *)srcBuf, w, 0,
h, TJPF_BGRX, dstBuf, yuvAlign));
} else {
if (precision == 8) {
if (precision <= 8) {
TRY_TJ(handle, tj3Compress8(handle, (unsigned char *)srcBuf, w, 0,
h, TJPF_BGRX, &dstBuf, &dstSize));
} else if (precision == 12) {
} else if (precision <= 12) {
TRY_TJ(handle, tj3Compress12(handle, (short *)srcBuf, w, 0, h,
TJPF_BGRX, &dstBuf, &dstSize));
} else {
@@ -798,10 +800,10 @@ static void bufSizeTest(void)
TRY_TJ(handle, tj3EncodeYUV8(handle, (unsigned char *)srcBuf, h, 0,
w, TJPF_BGRX, dstBuf, yuvAlign));
} else {
if (precision == 8) {
if (precision <= 8) {
TRY_TJ(handle, tj3Compress8(handle, (unsigned char *)srcBuf, h, 0,
w, TJPF_BGRX, &dstBuf, &dstSize));
} else if (precision == 12) {
} else if (precision <= 12) {
TRY_TJ(handle, tj3Compress12(handle, (short *)srcBuf, h, 0, w,
TJPF_BGRX, &dstBuf, &dstSize));
} else {
@@ -952,39 +954,49 @@ static int doBmpTest(const char *ext, int width, int align, int height, int pf,
loadHeight = 0, retval = 0, pixelFormat = pf;
void *buf = NULL;
char *md5ref;
char *colorPPMRefs[17] = {
"", "", "0bad09d9ef38eda566848fb7c0b7fd0a",
"7ef2c87261a8bd6838303b541563cf27", "28a37cf9636ff6bb9ed6b206bdac60db",
"723307791d42e0b5f9e91625c7636086", "d729c4bcd3addc14abc16b656c6bbc98",
"5d7636eedae3cf579b6de13078227548", "c0c9f772b464d1896326883a5c79c545",
"fcf6490e0445569427f1d95baf5f8fcb", "5cbc3b0ccba23f5781d950a72e0ccc83",
"0d4e26d6d16d7bfee380f6feb10f7e53", "2ff5299287017502832c99718450c90a",
"44ae6cd70c798ea583ab0c8c03621092", "697b2fe03892bc9a75396ad3e73d9203",
"599732f973eb7c0849a888e783bbe27e", "623f54661b928d170bd2324bc3620565"
};
char *grayPPMRefs[17] = {
"", "", "7565be35a2ce909cae016fa282af8efa",
"e86b9ea57f7d53f6b5497653740992b5", "8924d4d81fe0220c684719294f93407a",
"e2e69ba70efcfae317528c91651c7ae2", "e6154aafc1eb9e4333d68ce7ad9df051",
"3d7fe831d6fbe55d3fa12f52059c15d3", "112c682e82ce5de1cca089e20d60000b",
"05a7ce86c649dda86d6fed185ab78a67", "0b723c0bc087592816523fbc906b7c3a",
"5da422b1ddfd44c7659094d42ba5580c", "0d1895c7e6f2b2c9af6e821a655c239c",
"00fc2803bca103ff75785ea0dca992aa", "d8c91fac522c16b029e514d331a22bc4",
"e50cff0b3562ed7e64dbfc093440e333", "64f3320b226ea37fb58080713b4df1b2"
};
if ((handle = tj3Init(TJINIT_TRANSFORM)) == NULL)
THROW_TJ(NULL);
TRY_TJ(handle, tj3Set(handle, TJPARAM_BOTTOMUP, bottomUp));
TRY_TJ(handle, tj3Set(handle, TJPARAM_PRECISION, precision));
if (pf == TJPF_GRAY) {
if (precision == 8)
md5ref = !strcasecmp(ext, "ppm") ? "112c682e82ce5de1cca089e20d60000b" :
"51976530acf75f02beddf5d21149101d";
else if (precision == 12)
md5ref = "0d1895c7e6f2b2c9af6e821a655c239c";
else
md5ref = "64f3320b226ea37fb58080713b4df1b2";
} else {
if (precision == 8)
md5ref = !strcasecmp(ext, "ppm") ? "c0c9f772b464d1896326883a5c79c545" :
"6d659071b9bfcdee2def22cb58ddadca";
else if (precision == 12)
md5ref = "2ff5299287017502832c99718450c90a";
else
md5ref = "623f54661b928d170bd2324bc3620565";
}
if (precision == 8 && !strcasecmp(ext, "bmp"))
md5ref = (pf == TJPF_GRAY ? "51976530acf75f02beddf5d21149101d" :
"6d659071b9bfcdee2def22cb58ddadca");
else
md5ref = (pf == TJPF_GRAY ? grayPPMRefs[precision] :
colorPPMRefs[precision]);
if ((buf = tj3Alloc(pitch * height * sampleSize)) == NULL)
THROW("Could not allocate memory");
initBitmap(buf, width, pitch, height, pf, bottomUp);
SNPRINTF(filename, 80, "test_bmp%d_%s_%d_%s_%d.%s", precision, pixFormatStr[pf],
align, bottomUp ? "bu" : "td", getpid(), ext);
if (precision == 8) {
SNPRINTF(filename, 80, "test_bmp%d_%s_%d_%s_%d.%s", precision,
pixFormatStr[pf], align, bottomUp ? "bu" : "td", getpid(), ext);
if (precision <= 8) {
TRY_TJ(handle, tj3SaveImage8(handle, filename, (unsigned char *)buf, width,
pitch, height, pf));
} else if (precision == 12) {
} else if (precision <= 12) {
TRY_TJ(handle, tj3SaveImage12(handle, filename, (short *)buf, width, pitch,
height, pf));
} else {
@@ -1000,11 +1012,11 @@ static int doBmpTest(const char *ext, int width, int align, int height, int pf,
THROW_MD5(filename, md5sum, md5ref);
tj3Free(buf); buf = NULL;
if (precision == 8) {
if (precision <= 8) {
if ((buf = tj3LoadImage8(handle, filename, &loadWidth, align, &loadHeight,
&pf)) == NULL)
THROW_TJ(handle);
} else if (precision == 12) {
} else if (precision <= 12) {
if ((buf = tj3LoadImage12(handle, filename, &loadWidth, align, &loadHeight,
&pf)) == NULL)
THROW_TJ(handle);
@@ -1024,11 +1036,11 @@ static int doBmpTest(const char *ext, int width, int align, int height, int pf,
if (pf == TJPF_GRAY) {
tj3Free(buf); buf = NULL;
pf = TJPF_XBGR;
if (precision == 8) {
if (precision <= 8) {
if ((buf = tj3LoadImage8(handle, filename, &loadWidth, align,
&loadHeight, &pf)) == NULL)
THROW_TJ(handle);
} else if (precision == 12) {
} else if (precision <= 12) {
if ((buf = tj3LoadImage12(handle, filename, &loadWidth, align,
&loadHeight, &pf)) == NULL)
THROW_TJ(handle);
@@ -1045,11 +1057,11 @@ static int doBmpTest(const char *ext, int width, int align, int height, int pf,
tj3Free(buf); buf = NULL;
pf = TJPF_CMYK;
if (precision == 8) {
if (precision <= 8) {
if ((buf = tj3LoadImage8(handle, filename, &loadWidth, align,
&loadHeight, &pf)) == NULL)
THROW_TJ(handle);
} else if (precision == 12) {
} else if (precision <= 12) {
if ((buf = tj3LoadImage12(handle, filename, &loadWidth, align,
&loadHeight, &pf)) == NULL)
THROW_TJ(handle);
@@ -1069,11 +1081,11 @@ static int doBmpTest(const char *ext, int width, int align, int height, int pf,
tj3Free(buf); buf = NULL;
pf = pixelFormat;
pixelFormat = TJPF_UNKNOWN;
if (precision == 8) {
if (precision <= 8) {
if ((buf = tj3LoadImage8(handle, filename, &loadWidth, align, &loadHeight,
&pixelFormat)) == NULL)
THROW_TJ(handle);
} else if (precision == 12) {
} else if (precision <= 12) {
if ((buf = tj3LoadImage12(handle, filename, &loadWidth, align, &loadHeight,
&pixelFormat)) == NULL)
THROW_TJ(handle);
@@ -1158,10 +1170,10 @@ int main(int argc, char *argv[])
else if (!strcasecmp(argv[i], "-precision") && i < argc - 1) {
int tempi = atoi(argv[++i]);
if (tempi != 8 && tempi != 12 && tempi != 16)
if (tempi < 2 || tempi > 16)
usage(argv[0]);
precision = tempi;
if (precision == 16) lossless = 1;
if (precision != 8 && precision != 12) lossless = 1;
} else
usage(argv[0]);
}
@@ -1172,7 +1184,7 @@ int main(int argc, char *argv[])
THROW("YUV encoding/decoding requires 8-bit data precision.");
printf("Testing %d-bit precision\n", precision);
sampleSize = (precision == 8 ? sizeof(unsigned char) : sizeof(short));
sampleSize = (precision <= 8 ? sizeof(unsigned char) : sizeof(short));
maxSample = (1 << precision) - 1;
tolerance = (lossless ? 0 : (precision > 8 ? 2 : 1));
redToY = (19595U * maxSample) >> 16;

View File

@@ -104,6 +104,14 @@ DLLEXPORT int GET_NAME(tj3Compress, BITS_IN_JSAMPLE)
cinfo->image_width = width;
cinfo->image_height = height;
cinfo->data_precision = BITS_IN_JSAMPLE;
#if BITS_IN_JSAMPLE == 8
if (this->lossless && this->precision >= 2 &&
this->precision <= BITS_IN_JSAMPLE)
#else
if (this->lossless && this->precision >= BITS_IN_JSAMPLE - 3 &&
this->precision <= BITS_IN_JSAMPLE)
#endif
cinfo->data_precision = this->precision;
setCompDefaults(this, pixelFormat);
if (this->noRealloc) {
@@ -342,6 +350,13 @@ DLLEXPORT _JSAMPLE *GET_NAME(tj3LoadImage, BITS_IN_JSAMPLE)
THROW("Could not initialize bitmap loader");
invert = !this->bottomUp;
} else if (tempc == 'P') {
#if BITS_IN_JSAMPLE == 8
if (this->precision >= 2 && this->precision <= BITS_IN_JSAMPLE)
#else
if (this->precision >= BITS_IN_JSAMPLE - 3 &&
this->precision <= BITS_IN_JSAMPLE)
#endif
cinfo->data_precision = this->precision;
if ((src = _jinit_read_ppm(cinfo)) == NULL)
THROW("Could not initialize PPM loader");
invert = this->bottomUp;
@@ -484,6 +499,13 @@ DLLEXPORT int GET_NAME(tj3SaveImage, BITS_IN_JSAMPLE)
dinfo->Y_density = (UINT16)this->yDensity;
dinfo->density_unit = (UINT8)this->densityUnits;
} else {
#if BITS_IN_JSAMPLE == 8
if (this->precision >= 2 && this->precision <= BITS_IN_JSAMPLE)
#else
if (this->precision >= BITS_IN_JSAMPLE - 3 &&
this->precision <= BITS_IN_JSAMPLE)
#endif
dinfo->data_precision = this->precision;
if ((dst = _jinit_write_ppm(dinfo)) == NULL)
THROW("Could not initialize PPM writer");
invert = this->bottomUp;

View File

@@ -624,9 +624,9 @@ DLLEXPORT int tj3Set(tjhandle handle, int param, int value)
THROW("TJPARAM_JPEGHEIGHT is read-only in decompression instances.");
break;
case TJPARAM_PRECISION:
if (!(this->init & DECOMPRESS))
THROW("TJPARAM_PRECISION is not applicable to compression instances.");
THROW("TJPARAM_PRECISION is read-only in decompression instances.");
if (!(this->init & COMPRESS))
THROW("TJPARAM_PRECISION is read-only in decompression instances.");
SET_PARAM(precision, 2, 16);
break;
case TJPARAM_COLORSPACE:
if (!(this->init & COMPRESS))
@@ -1929,7 +1929,7 @@ DLLEXPORT int tj3SetCroppingRegion(tjhandle handle, tjregion croppingRegion)
THROW("Invalid cropping region");
if (this->jpegWidth < 0 || this->jpegHeight < 0)
THROW("JPEG header has not yet been read");
if (this->precision == 16 || this->lossless)
if ((this->precision != 8 && this->precision != 12) || this->lossless)
THROW("Cannot partially decompress lossless JPEG images");
if (this->subsamp == TJSAMP_UNKNOWN)
THROW("Could not determine subsampling level of JPEG image");

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C)2009-2015, 2017, 2020-2023 D. R. Commander.
* Copyright (C)2009-2015, 2017, 2020-2024 D. R. Commander.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -257,8 +257,9 @@ enum TJPF {
TJPF_XRGB,
/**
* Grayscale pixel format. Each 1-sample pixel represents a luminance
* (brightness) level from 0 to the maximum sample value (255 for 8-bit
* samples, 4095 for 12-bit samples, and 65535 for 16-bit samples.)
* (brightness) level from 0 to the maximum sample value (which is, for
* instance, 255 for 8-bit samples or 4095 for 12-bit samples or 65535 for
* 16-bit samples.)
*/
TJPF_GRAY,
/**
@@ -489,15 +490,25 @@ enum TJPARAM {
*/
TJPARAM_JPEGHEIGHT,
/**
* JPEG data precision (bits per sample) [decompression only, read-only]
* Data precision (bits per sample)
*
* The JPEG image uses the specified number of bits per sample.
* The JPEG image uses (decompression) or will use (lossless compression) the
* specified number of bits per sample. This parameter also specifies the
* target data precision when loading a PBMPLUS file with #tj3LoadImage8(),
* #tj3LoadImage12(), or #tj3LoadImage16() and the source data precision when
* saving a PBMPLUS file with #tj3SaveImage8(), #tj3SaveImage12(), or
* #tj3SaveImage16().
*
* The data precision is the number of bits in the maximum sample value,
* which may not be the same as the width of the data type used to store the
* sample.
*
* **Value**
* - `8`, `12`, or `16`
* - `8` or `12` for lossy JPEG images; `2` to `16` for lossless JPEG and
* PBMPLUS images
*
* 12-bit data precision implies #TJPARAM_OPTIMIZE unless #TJPARAM_ARITHMETIC
* is set.
* 12-bit JPEG data precision implies #TJPARAM_OPTIMIZE unless
* #TJPARAM_ARITHMETIC is set.
*/
TJPARAM_PRECISION,
/**
@@ -1116,8 +1127,8 @@ DLLEXPORT int tj3Get(tjhandle handle, int param);
/**
* Compress an 8-bit-per-sample packed-pixel RGB, grayscale, or CMYK image into
* an 8-bit-per-sample JPEG image.
* Compress a packed-pixel RGB, grayscale, or CMYK image with 2 to 8 bits of
* data precision per sample into a JPEG image with the same data precision.
*
* @param handle handle to a TurboJPEG instance that has been initialized for
* compression
@@ -1125,7 +1136,10 @@ DLLEXPORT int tj3Get(tjhandle handle, int param);
* @param srcBuf pointer to a buffer containing a packed-pixel RGB, grayscale,
* or CMYK source image to be compressed. This buffer should normally be
* `pitch * height` samples in size. However, you can also use this parameter
* to compress from a specific region of a larger buffer.
* to compress from a specific region of a larger buffer. The data precision
* of the source image (from 2 to 8 bits per sample) can be specified using
* #TJPARAM_PRECISION and defaults to 8 if #TJPARAM_PRECISION is unset or out
* of range.
*
* @param width width (in pixels) of the source image
*
@@ -1172,20 +1186,119 @@ DLLEXPORT int tj3Compress8(tjhandle handle, const unsigned char *srcBuf,
unsigned char **jpegBuf, size_t *jpegSize);
/**
* Compress a 12-bit-per-sample packed-pixel RGB, grayscale, or CMYK image into
* a 12-bit-per-sample JPEG image.
* Compress a packed-pixel RGB, grayscale, or CMYK image with 9 to 12 bits of
* data precision per sample into a JPEG image with the same data precision.
*
* \details \copydetails tj3Compress8()
* @param handle handle to a TurboJPEG instance that has been initialized for
* compression
*
* @param srcBuf pointer to a buffer containing a packed-pixel RGB, grayscale,
* or CMYK source image to be compressed. This buffer should normally be
* `pitch * height` samples in size. However, you can also use this parameter
* to compress from a specific region of a larger buffer. The data precision
* of the source image (from 9 to 12 bits per sample) can be specified using
* #TJPARAM_PRECISION and defaults to 12 if #TJPARAM_PRECISION is unset or out
* of range.
*
* @param width width (in pixels) of the source image
*
* @param pitch samples per row in the source image. Normally this should be
* <tt>width * #tjPixelSize[pixelFormat]</tt>, if the image is unpadded.
* (Setting this parameter to 0 is the equivalent of setting it to
* <tt>width * #tjPixelSize[pixelFormat]</tt>.) However, you can also use this
* parameter to specify the row alignment/padding of the source image, to skip
* rows, or to compress from a specific region of a larger buffer.
*
* @param height height (in pixels) of the source image
*
* @param pixelFormat pixel format of the source image (see @ref TJPF
* "Pixel formats".)
*
* @param jpegBuf address of a pointer to a byte buffer that will receive the
* JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer to
* accommodate the size of the JPEG image. Thus, you can choose to:
* -# pre-allocate the JPEG buffer with an arbitrary size using #tj3Alloc() and
* let TurboJPEG grow the buffer as needed,
* -# set `*jpegBuf` to NULL to tell TurboJPEG to allocate the buffer for you,
* or
* -# pre-allocate the buffer to a "worst case" size determined by calling
* #tj3JPEGBufSize(). This should ensure that the buffer never has to be
* re-allocated. (Setting #TJPARAM_NOREALLOC guarantees that it won't be.)
* .
* If you choose option 1, then `*jpegSize` should be set to the size of your
* pre-allocated buffer. In any case, unless you have set #TJPARAM_NOREALLOC,
* you should always check `*jpegBuf` upon return from this function, as it may
* have changed.
*
* @param jpegSize pointer to a size_t variable that holds the size of the JPEG
* buffer. If `*jpegBuf` points to a pre-allocated buffer, then `*jpegSize`
* should be set to the size of the buffer. Upon return, `*jpegSize` will
* contain the size of the JPEG image (in bytes.) If `*jpegBuf` points to a
* JPEG buffer that is being reused from a previous call to one of the JPEG
* compression functions, then `*jpegSize` is ignored.
*
* @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr()
* and #tj3GetErrorCode().)
*/
DLLEXPORT int tj3Compress12(tjhandle handle, const short *srcBuf, int width,
int pitch, int height, int pixelFormat,
unsigned char **jpegBuf, size_t *jpegSize);
/**
* Compress a 16-bit-per-sample packed-pixel RGB, grayscale, or CMYK image into
* a 16-bit-per-sample lossless JPEG image.
* Compress a packed-pixel RGB, grayscale, or CMYK image with 13 to 16 bits of
* data precision per sample into a lossless JPEG image with the same data
* precision.
*
* \details \copydetails tj3Compress8()
* @param handle handle to a TurboJPEG instance that has been initialized for
* compression
*
* @param srcBuf pointer to a buffer containing a packed-pixel RGB, grayscale,
* or CMYK source image to be compressed. This buffer should normally be
* `pitch * height` samples in size. However, you can also use this parameter
* to compress from a specific region of a larger buffer. The data precision
* of the source image (from 13 to 16 bits per sample) can be specified using
* #TJPARAM_PRECISION and defaults to 16 if #TJPARAM_PRECISION is unset or out
* of range.
*
* @param width width (in pixels) of the source image
*
* @param pitch samples per row in the source image. Normally this should be
* <tt>width * #tjPixelSize[pixelFormat]</tt>, if the image is unpadded.
* (Setting this parameter to 0 is the equivalent of setting it to
* <tt>width * #tjPixelSize[pixelFormat]</tt>.) However, you can also use this
* parameter to specify the row alignment/padding of the source image, to skip
* rows, or to compress from a specific region of a larger buffer.
*
* @param height height (in pixels) of the source image
*
* @param pixelFormat pixel format of the source image (see @ref TJPF
* "Pixel formats".)
*
* @param jpegBuf address of a pointer to a byte buffer that will receive the
* JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer to
* accommodate the size of the JPEG image. Thus, you can choose to:
* -# pre-allocate the JPEG buffer with an arbitrary size using #tj3Alloc() and
* let TurboJPEG grow the buffer as needed,
* -# set `*jpegBuf` to NULL to tell TurboJPEG to allocate the buffer for you,
* or
* -# pre-allocate the buffer to a "worst case" size determined by calling
* #tj3JPEGBufSize(). This should ensure that the buffer never has to be
* re-allocated. (Setting #TJPARAM_NOREALLOC guarantees that it won't be.)
* .
* If you choose option 1, then `*jpegSize` should be set to the size of your
* pre-allocated buffer. In any case, unless you have set #TJPARAM_NOREALLOC,
* you should always check `*jpegBuf` upon return from this function, as it may
* have changed.
*
* @param jpegSize pointer to a size_t variable that holds the size of the JPEG
* buffer. If `*jpegBuf` points to a pre-allocated buffer, then `*jpegSize`
* should be set to the size of the buffer. Upon return, `*jpegSize` will
* contain the size of the JPEG image (in bytes.) If `*jpegBuf` points to a
* JPEG buffer that is being reused from a previous call to one of the JPEG
* compression functions, then `*jpegSize` is ignored.
*
* @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr()
* and #tj3GetErrorCode().)
*/
DLLEXPORT int tj3Compress16(tjhandle handle, const unsigned short *srcBuf,
int width, int pitch, int height, int pixelFormat,
@@ -1620,9 +1733,10 @@ DLLEXPORT int tj3SetCroppingRegion(tjhandle handle, tjregion croppingRegion);
/**
* Decompress an 8-bit-per-sample JPEG image into an 8-bit-per-sample
* packed-pixel RGB, grayscale, or CMYK image. The @ref TJPARAM "parameters"
* that describe the JPEG image will be set when this function returns.
* Decompress a JPEG image with 2 to 8 bits of data precision per sample into a
* packed-pixel RGB, grayscale, or CMYK image with the same data precision.
* The @ref TJPARAM "parameters" that describe the JPEG image will be set when
* this function returns.
*
* @param handle handle to a TurboJPEG instance that has been initialized for
* decompression
@@ -1666,8 +1780,8 @@ DLLEXPORT int tj3Decompress8(tjhandle handle, const unsigned char *jpegBuf,
int pixelFormat);
/**
* Decompress a 12-bit-per-sample JPEG image into a 12-bit-per-sample
* packed-pixel RGB, grayscale, or CMYK image.
* Decompress a JPEG image with 9 to 12 bits of data precision per sample into
* a packed-pixel RGB, grayscale, or CMYK image with the same data precision.
*
* \details \copydetails tj3Decompress8()
*/
@@ -1676,8 +1790,9 @@ DLLEXPORT int tj3Decompress12(tjhandle handle, const unsigned char *jpegBuf,
int pixelFormat);
/**
* Decompress a 16-bit-per-sample lossless JPEG image into a 16-bit-per-sample
* packed-pixel RGB, grayscale, or CMYK image.
* Decompress a lossless JPEG image with 13 to 16 bits of data precision per
* sample into a packed-pixel RGB, grayscale, or CMYK image with the same
* data precision.
*
* \details \copydetails tj3Decompress8()
*/
@@ -1962,15 +2077,18 @@ DLLEXPORT void *tj3Alloc(size_t bytes);
/**
* Load an 8-bit-per-sample packed-pixel image from disk into memory.
* Load a packed-pixel image with 2 to 8 bits of data precision per sample from
* disk into memory.
*
* @param handle handle to a TurboJPEG instance
*
* @param filename name of a file containing a packed-pixel image in Windows
* BMP or PBMPLUS (PPM/PGM) format. Windows BMP files require 8-bit-per-sample
* data precision. If the data precision of the PBMPLUS file does not match
* the target data precision, then upconverting or downconverting will be
* performed.
* data precision. When loading a PBMPLUS file, the target data precision
* (from 2 to 8 bits per sample) can be specified using #TJPARAM_PRECISION and
* defaults to 8 if #TJPARAM_PRECISION is unset or out of range. If the data
* precision of the PBMPLUS file does not match the target data precision, then
* upconverting or downconverting will be performed.
*
* @param width pointer to an integer variable that will receive the width (in
* pixels) of the packed-pixel image
@@ -2011,18 +2129,100 @@ DLLEXPORT unsigned char *tj3LoadImage8(tjhandle handle, const char *filename,
int *pixelFormat);
/**
* Load a 12-bit-per-sample packed-pixel image from disk into memory.
* Load a packed-pixel image with 9 to 12 bits of data precision per sample
* from disk into memory.
*
* \details \copydetails tj3LoadImage8()
* @param handle handle to a TurboJPEG instance
*
* @param filename name of a file containing a packed-pixel image in PBMPLUS
* (PPM/PGM) format. The target data precision (from 9 to 12 bits per sample)
* can be specified using #TJPARAM_PRECISION and defaults to 12 if
* #TJPARAM_PRECISION is unset or out of range. If the data precision of the
* PBMPLUS file does not match the target data precision, then upconverting or
* downconverting will be performed.
*
* @param width pointer to an integer variable that will receive the width (in
* pixels) of the packed-pixel image
*
* @param align row alignment (in samples) of the packed-pixel buffer to be
* returned (must be a power of 2.) Setting this parameter to n will cause all
* rows in the buffer to be padded to the nearest multiple of n samples
* (1 = unpadded.)
*
* @param height pointer to an integer variable that will receive the height
* (in pixels) of the packed-pixel image
*
* @param pixelFormat pointer to an integer variable that specifies or will
* receive the pixel format of the packed-pixel buffer. The behavior of this
* function will vary depending on the value of `*pixelFormat` passed to the
* function:
* - @ref TJPF_UNKNOWN : The packed-pixel buffer returned by this function will
* use the most optimal pixel format for the file type, and `*pixelFormat` will
* contain the ID of that pixel format upon successful return from this
* function.
* - @ref TJPF_GRAY : Only PGM files can be loaded.
* - @ref TJPF_CMYK : The RGB or grayscale pixels stored in the file will be
* converted using a quick & dirty algorithm that is suitable only for testing
* purposes. (Proper conversion between CMYK and other formats requires a
* color management system.)
* - Other @ref TJPF "pixel formats" : The packed-pixel buffer will use the
* specified pixel format, and pixel format conversion will be performed if
* necessary.
*
* @return a pointer to a newly-allocated buffer containing the packed-pixel
* image, converted to the chosen pixel format and with the chosen row
* alignment, or NULL if an error occurred (see #tj3GetErrorStr().) This
* buffer should be freed using #tj3Free().
*/
DLLEXPORT short *tj3LoadImage12(tjhandle handle, const char *filename,
int *width, int align, int *height,
int *pixelFormat);
/**
* Load a 16-bit-per-sample packed-pixel image from disk into memory.
* Load a packed-pixel image with 13 to 16 bits of data precision per sample
* from disk into memory.
*
* \details \copydetails tj3LoadImage8()
* @param handle handle to a TurboJPEG instance
*
* @param filename name of a file containing a packed-pixel image in PBMPLUS
* (PPM/PGM) format. The target data precision (from 13 to 16 bits per sample)
* can be specified using #TJPARAM_PRECISION and defaults to 16 if
* #TJPARAM_PRECISION is unset or out of range. If the data precision of the
* PBMPLUS file does not match the target data precision, then upconverting or
* downconverting will be performed.
*
* @param width pointer to an integer variable that will receive the width (in
* pixels) of the packed-pixel image
*
* @param align row alignment (in samples) of the packed-pixel buffer to be
* returned (must be a power of 2.) Setting this parameter to n will cause all
* rows in the buffer to be padded to the nearest multiple of n samples
* (1 = unpadded.)
*
* @param height pointer to an integer variable that will receive the height
* (in pixels) of the packed-pixel image
*
* @param pixelFormat pointer to an integer variable that specifies or will
* receive the pixel format of the packed-pixel buffer. The behavior of this
* function will vary depending on the value of `*pixelFormat` passed to the
* function:
* - @ref TJPF_UNKNOWN : The packed-pixel buffer returned by this function will
* use the most optimal pixel format for the file type, and `*pixelFormat` will
* contain the ID of that pixel format upon successful return from this
* function.
* - @ref TJPF_GRAY : Only PGM files can be loaded.
* - @ref TJPF_CMYK : The RGB or grayscale pixels stored in the file will be
* converted using a quick & dirty algorithm that is suitable only for testing
* purposes. (Proper conversion between CMYK and other formats requires a
* color management system.)
* - Other @ref TJPF "pixel formats" : The packed-pixel buffer will use the
* specified pixel format, and pixel format conversion will be performed if
* necessary.
*
* @return a pointer to a newly-allocated buffer containing the packed-pixel
* image, converted to the chosen pixel format and with the chosen row
* alignment, or NULL if an error occurred (see #tj3GetErrorStr().) This
* buffer should be freed using #tj3Free().
*/
DLLEXPORT unsigned short *tj3LoadImage16(tjhandle handle, const char *filename,
int *width, int align, int *height,
@@ -2030,14 +2230,17 @@ DLLEXPORT unsigned short *tj3LoadImage16(tjhandle handle, const char *filename,
/**
* Save an 8-bit-per-sample packed-pixel image from memory to disk.
* Save a packed-pixel image with 2 to 8 bits of data precision per sample from
* memory to disk.
*
* @param handle handle to a TurboJPEG instance
*
* @param filename name of a file to which to save the packed-pixel image. The
* image will be stored in Windows BMP or PBMPLUS (PPM/PGM) format, depending
* on the file extension. Windows BMP files require 8-bit-per-sample data
* precision.
* precision. When saving a PBMPLUS file, the source data precision (from 2 to
* 8 bits per sample) can be specified using #TJPARAM_PRECISION and defaults to
* 8 if #TJPARAM_PRECISION is unset or out of range.
*
* @param buffer pointer to a buffer containing a packed-pixel RGB, grayscale,
* or CMYK image to be saved
@@ -2066,18 +2269,72 @@ DLLEXPORT int tj3SaveImage8(tjhandle handle, const char *filename,
int height, int pixelFormat);
/**
* Save a 12-bit-per-sample packed-pixel image from memory to disk.
* Save a packed-pixel image with 9 to 12 bits of data precision per sample
* from memory to disk.
*
* \details \copydetails tj3SaveImage8()
* @param handle handle to a TurboJPEG instance
*
* @param filename name of a file to which to save the packed-pixel image,
* which will be stored in PBMPLUS (PPM/PGM) format. The source data precision
* (from 9 to 12 bits per sample) can be specified using #TJPARAM_PRECISION and
* defaults to 12 if #TJPARAM_PRECISION is unset or out of range.
*
* @param buffer pointer to a buffer containing a packed-pixel RGB, grayscale,
* or CMYK image to be saved
*
* @param width width (in pixels) of the packed-pixel image
*
* @param pitch samples per row in the packed-pixel image. Setting this
* parameter to 0 is the equivalent of setting it to
* <tt>width * #tjPixelSize[pixelFormat]</tt>.
*
* @param height height (in pixels) of the packed-pixel image
*
* @param pixelFormat pixel format of the packed-pixel image (see @ref TJPF
* "Pixel formats".) If this parameter is set to @ref TJPF_GRAY, then the
* image will be stored in PGM format. Otherwise, the image will be stored in
* PPM format. If this parameter is set to @ref TJPF_CMYK, then the CMYK
* pixels will be converted to RGB using a quick & dirty algorithm that is
* suitable only for testing purposes. (Proper conversion between CMYK and
* other formats requires a color management system.)
*
* @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr().)
*/
DLLEXPORT int tj3SaveImage12(tjhandle handle, const char *filename,
const short *buffer, int width, int pitch,
int height, int pixelFormat);
/**
* Save a 16-bit-per-sample packed-pixel image from memory to disk.
* Save a packed-pixel image with 13 to 16 bits of data precision per sample
* from memory to disk.
*
* \details \copydetails tj3SaveImage8()
* @param handle handle to a TurboJPEG instance
*
* @param filename name of a file to which to save the packed-pixel image,
* which will be stored in PBMPLUS (PPM/PGM) format. The source data precision
* (from 13 to 16 bits per sample) can be specified using #TJPARAM_PRECISION
* and defaults to 16 if #TJPARAM_PRECISION is unset or out of range.
*
* @param buffer pointer to a buffer containing a packed-pixel RGB, grayscale,
* or CMYK image to be saved
*
* @param width width (in pixels) of the packed-pixel image
*
* @param pitch samples per row in the packed-pixel image. Setting this
* parameter to 0 is the equivalent of setting it to
* <tt>width * #tjPixelSize[pixelFormat]</tt>.
*
* @param height height (in pixels) of the packed-pixel image
*
* @param pixelFormat pixel format of the packed-pixel image (see @ref TJPF
* "Pixel formats".) If this parameter is set to @ref TJPF_GRAY, then the
* image will be stored in PGM format. Otherwise, the image will be stored in
* PPM format. If this parameter is set to @ref TJPF_CMYK, then the CMYK
* pixels will be converted to RGB using a quick & dirty algorithm that is
* suitable only for testing purposes. (Proper conversion between CMYK and
* other formats requires a color management system.)
*
* @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr().)
*/
DLLEXPORT int tj3SaveImage16(tjhandle handle, const char *filename,
const unsigned short *buffer, int width,

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, 2017, 2019, 2022, D. R. Commander.
* Copyright (C) 2014-2015, 2017, 2019, 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -142,7 +142,7 @@ put_pixel_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
} else if (cinfo->out_color_space == JCS_CMYK) {
for (col = cinfo->output_width; col > 0; col--) {
JSAMPLE c = *inptr++, m = *inptr++, y = *inptr++, k = *inptr++;
cmyk_to_rgb(c, m, y, k, outptr + 2, outptr + 1, outptr);
cmyk_to_rgb(255, c, m, y, k, outptr + 2, outptr + 1, outptr);
outptr += 3;
}
} else {

View File

@@ -5,7 +5,7 @@
* Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2009 by Guido Vollbeding.
* libjpeg-turbo Modifications:
* Copyright (C) 2017, 2019-2020, 2022, D. R. Commander.
* Copyright (C) 2017, 2019-2020, 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -39,10 +39,11 @@
#if BITS_IN_JSAMPLE == 8
#define PUTPPMSAMPLE(ptr, v) *ptr++ = (char)(v)
#define BYTESPERSAMPLE 1
#define PPM_MAXVAL 255
#define PPM_MAXVAL ((1 << cinfo->data_precision) - 1)
#else
#ifdef PPM_NORAWWORD
#define PUTPPMSAMPLE(ptr, v) *ptr++ = (char)((v) >> (BITS_IN_JSAMPLE - 8))
#define PUTPPMSAMPLE(ptr, v) \
*ptr++ = (char)((v) >> (cinfo->data_precision - 8))
#define BYTESPERSAMPLE 1
#define PPM_MAXVAL 255
#else
@@ -53,7 +54,7 @@
*ptr++ = (char)(val_ & 0xFF); \
}
#define BYTESPERSAMPLE 2
#define PPM_MAXVAL ((1 << BITS_IN_JSAMPLE) - 1)
#define PPM_MAXVAL ((1 << cinfo->data_precision) - 1)
#endif
#endif
@@ -171,7 +172,7 @@ put_cmyk(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
bufferptr = dest->iobuffer;
for (col = cinfo->output_width; col > 0; col--) {
_JSAMPLE r, g, b, c = *ptr++, m = *ptr++, y = *ptr++, k = *ptr++;
cmyk_to_rgb(c, m, y, k, &r, &g, &b);
cmyk_to_rgb(PPM_MAXVAL, c, m, y, k, &r, &g, &b);
PUTPPMSAMPLE(bufferptr, r);
PUTPPMSAMPLE(bufferptr, g);
PUTPPMSAMPLE(bufferptr, b);
@@ -309,7 +310,12 @@ _jinit_write_ppm(j_decompress_ptr cinfo)
{
ppm_dest_ptr dest;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
#if BITS_IN_JSAMPLE == 8
if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
#else
if (cinfo->data_precision > BITS_IN_JSAMPLE ||
cinfo->data_precision < BITS_IN_JSAMPLE - 3)
#endif
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Create module interface object, fill in method pointers */