From 17e888bbae95363afe6fab11b716d74954b33695 Mon Sep 17 00:00:00 2001 From: DRC Date: Thu, 13 Aug 2015 20:06:03 -0500 Subject: [PATCH] Declare source buffers in TurboJPEG C API as const This reassures the caller that the buffers will not be modified and also allows read-only buffers to be passed to the functions. Partially reverts 3947a19f25fc8186d3812dbcf8e70baea36ef652. --- ChangeLog.txt | 6 + doc/html/group___turbo_j_p_e_g.html | 172 ++++++++++++++-------------- doc/html/search/all_74.js | 24 ++-- doc/html/search/functions_74.js | 24 ++-- doc/html/structtjtransform.html | 2 +- jdatasrc-tj.c | 4 +- turbojpeg-jni.c | 16 +-- turbojpeg.c | 76 ++++++------ turbojpeg.h | 76 ++++++------ 9 files changed, 207 insertions(+), 193 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 9b3df4136..f901e5200 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -25,6 +25,12 @@ negative width or height was used as an input image (Windows bitmaps can have a negative height if they are stored in top-down order, but such files are rare and not supported by libjpeg-turbo.) +[6] Source buffers for the TurboJPEG C API functions, as well as the +jpeg_mem_src() function in the libjpeg API, are now declared as const pointers. +This facilitates passing read-only buffers to those functions and ensures the +caller that the source buffer will not be modified. This should not create any +backward API or ABI incompatibilities with prior libjpeg-turbo releases. + 1.4.1 ===== diff --git a/doc/html/group___turbo_j_p_e_g.html b/doc/html/group___turbo_j_p_e_g.html index 233fe6c06..553ec92fb 100644 --- a/doc/html/group___turbo_j_p_e_g.html +++ b/doc/html/group___turbo_j_p_e_g.html @@ -132,10 +132,10 @@  The number of transform operations. More...
  #define TJXOPT_PERFECT - This option will cause tjTransform() to return an error if the transform is not perfect. More...
+ This option will cause tjTransform() to return an error if the transform is not perfect. More...
  #define TJXOPT_TRIM - This option will cause tjTransform() to discard any partial MCU blocks that cannot be transformed. More...
+ This option will cause tjTransform() to discard any partial MCU blocks that cannot be transformed. More...
  #define TJXOPT_CROP  This option will enable lossless cropping. More...
@@ -144,7 +144,7 @@  This option will discard the color data in the input image and produce a grayscale output image. More...
  #define TJXOPT_NOOUTPUT - This option will prevent tjTransform() from outputting a JPEG image for this particular transform (this can be used in conjunction with a custom filter to capture the transformed DCT coefficients without transcoding them.) More...
+ This option will prevent tjTransform() from outputting a JPEG image for this particular transform (this can be used in conjunction with a custom filter to capture the transformed DCT coefficients without transcoding them.) More...
  #define TJPAD(width)  Pad the given width to the nearest 32-bit boundary. More...
@@ -218,7 +218,7 @@ TJXOP_ROT270
} - Transform operations for tjTransform() More...
+ Transform operations for tjTransform() More...
  - - - - - - - - - + + + + + + + + + @@ -250,42 +250,42 @@ - - - - - - + + + + + + - - - + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - + + + @@ -455,7 +455,7 @@

Macro Definition Documentation

Disable buffer (re)allocation.

-

If passed to tjCompress2() or tjTransform(), this flag will cause those functions to generate an error if the JPEG image buffer is invalid or too small rather than attempting to allocate or reallocate that buffer. This reproduces the behavior of earlier versions of TurboJPEG.

+

If passed to tjCompress2() or tjTransform(), this flag will cause those functions to generate an error if the JPEG image buffer is invalid or too small rather than attempting to allocate or reallocate that buffer. This reproduces the behavior of earlier versions of TurboJPEG.

@@ -517,7 +517,7 @@

Macro Definition Documentation

This option will enable lossless cropping.

-

See tjTransform() for more information.

+

See tjTransform() for more information.

@@ -545,7 +545,7 @@

Macro Definition Documentation

@@ -226,15 +226,15 @@

DLLEXPORT tjhandle DLLCALL tjInitCompress (void)
 Create a TurboJPEG compressor instance. More...
 
DLLEXPORT int DLLCALL tjCompress2 (tjhandle handle, unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf, unsigned long *jpegSize, int jpegSubsamp, int jpegQual, int flags)
 Compress an RGB, grayscale, or CMYK image into a JPEG image. More...
 
DLLEXPORT int DLLCALL tjCompressFromYUV (tjhandle handle, unsigned char *srcBuf, int width, int pad, int height, int subsamp, unsigned char **jpegBuf, unsigned long *jpegSize, int jpegQual, int flags)
 Compress a YUV planar image into a JPEG image. More...
 
DLLEXPORT int DLLCALL tjCompressFromYUVPlanes (tjhandle handle, unsigned char **srcPlanes, int width, int *strides, int height, int subsamp, unsigned char **jpegBuf, unsigned long *jpegSize, int jpegQual, int flags)
 Compress a set of Y, U (Cb), and V (Cr) image planes into a JPEG image. More...
 
DLLEXPORT int DLLCALL tjCompress2 (tjhandle handle, const unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf, unsigned long *jpegSize, int jpegSubsamp, int jpegQual, int flags)
 Compress an RGB, grayscale, or CMYK image into a JPEG image. More...
 
DLLEXPORT int DLLCALL tjCompressFromYUV (tjhandle handle, const unsigned char *srcBuf, int width, int pad, int height, int subsamp, unsigned char **jpegBuf, unsigned long *jpegSize, int jpegQual, int flags)
 Compress a YUV planar image into a JPEG image. More...
 
DLLEXPORT int DLLCALL tjCompressFromYUVPlanes (tjhandle handle, const unsigned char **srcPlanes, int width, const int *strides, int height, int subsamp, unsigned char **jpegBuf, unsigned long *jpegSize, int jpegQual, int flags)
 Compress a set of Y, U (Cb), and V (Cr) image planes into a JPEG image. More...
 
DLLEXPORT unsigned long DLLCALL tjBufSize (int width, int height, int jpegSubsamp)
 The maximum size of the buffer (in bytes) required to hold a JPEG image with the given parameters. More...
 
DLLEXPORT int tjPlaneHeight (int componentID, int height, int subsamp)
 The plane height of a YUV image plane with the given parameters. More...
 
DLLEXPORT int DLLCALL tjEncodeYUV3 (tjhandle handle, unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, unsigned char *dstBuf, int pad, int subsamp, int flags)
 Encode an RGB or grayscale image into a YUV planar image. More...
 
DLLEXPORT int DLLCALL tjEncodeYUVPlanes (tjhandle handle, unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, unsigned char **dstPlanes, int *strides, int subsamp, int flags)
 Encode an RGB or grayscale image into separate Y, U (Cb), and V (Cr) image planes. More...
 
DLLEXPORT int DLLCALL tjEncodeYUV3 (tjhandle handle, const unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, unsigned char *dstBuf, int pad, int subsamp, int flags)
 Encode an RGB or grayscale image into a YUV planar image. More...
 
DLLEXPORT int DLLCALL tjEncodeYUVPlanes (tjhandle handle, const unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, unsigned char **dstPlanes, int *strides, int subsamp, int flags)
 Encode an RGB or grayscale image into separate Y, U (Cb), and V (Cr) image planes. More...
 
DLLEXPORT tjhandle DLLCALL tjInitDecompress (void)
 Create a TurboJPEG decompressor instance. More...
 
DLLEXPORT int DLLCALL tjDecompressHeader3 (tjhandle handle, unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height, int *jpegSubsamp, int *jpegColorspace)
 Retrieve information about a JPEG image without decompressing it. More...
 
DLLEXPORT int DLLCALL tjDecompressHeader3 (tjhandle handle, const unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height, int *jpegSubsamp, int *jpegColorspace)
 Retrieve information about a JPEG image without decompressing it. More...
 
DLLEXPORT tjscalingfactor *DLLCALL tjGetScalingFactors (int *numscalingfactors)
 Returns a list of fractional scaling factors that the JPEG decompressor in this implementation of TurboJPEG supports. More...
 
DLLEXPORT int DLLCALL tjDecompress2 (tjhandle handle, unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, int width, int pitch, int height, int pixelFormat, int flags)
 Decompress a JPEG image to an RGB, grayscale, or CMYK image. More...
 
DLLEXPORT int DLLCALL tjDecompressToYUV2 (tjhandle handle, unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, int width, int pad, int height, int flags)
 Decompress a JPEG image to a YUV planar image. More...
 
DLLEXPORT int DLLCALL tjDecompressToYUVPlanes (tjhandle handle, unsigned char *jpegBuf, unsigned long jpegSize, unsigned char **dstPlanes, int width, int *strides, int height, int flags)
 Decompress a JPEG image into separate Y, U (Cb), and V (Cr) image planes. More...
 
DLLEXPORT int DLLCALL tjDecodeYUV (tjhandle handle, unsigned char *srcBuf, int pad, int subsamp, unsigned char *dstBuf, int width, int pitch, int height, int pixelFormat, int flags)
 Decode a YUV planar image into an RGB or grayscale image. More...
 
DLLEXPORT int DLLCALL tjDecodeYUVPlanes (tjhandle handle, unsigned char **srcPlanes, int *strides, int subsamp, unsigned char *dstBuf, int width, int pitch, int height, int pixelFormat, int flags)
 Decode a set of Y, U (Cb), and V (Cr) image planes into an RGB or grayscale image. More...
 
DLLEXPORT int DLLCALL tjDecompress2 (tjhandle handle, const unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, int width, int pitch, int height, int pixelFormat, int flags)
 Decompress a JPEG image to an RGB, grayscale, or CMYK image. More...
 
DLLEXPORT int DLLCALL tjDecompressToYUV2 (tjhandle handle, const unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, int width, int pad, int height, int flags)
 Decompress a JPEG image to a YUV planar image. More...
 
DLLEXPORT int DLLCALL tjDecompressToYUVPlanes (tjhandle handle, const unsigned char *jpegBuf, unsigned long jpegSize, unsigned char **dstPlanes, int width, int *strides, int height, int flags)
 Decompress a JPEG image into separate Y, U (Cb), and V (Cr) image planes. More...
 
DLLEXPORT int DLLCALL tjDecodeYUV (tjhandle handle, const unsigned char *srcBuf, int pad, int subsamp, unsigned char *dstBuf, int width, int pitch, int height, int pixelFormat, int flags)
 Decode a YUV planar image into an RGB or grayscale image. More...
 
DLLEXPORT int DLLCALL tjDecodeYUVPlanes (tjhandle handle, const unsigned char **srcPlanes, const int *strides, int subsamp, unsigned char *dstBuf, int width, int pitch, int height, int pixelFormat, int flags)
 Decode a set of Y, U (Cb), and V (Cr) image planes into an RGB or grayscale image. More...
 
DLLEXPORT tjhandle DLLCALL tjInitTransform (void)
 Create a new TurboJPEG transformer instance. More...
 
DLLEXPORT int DLLCALL tjTransform (tjhandle handle, unsigned char *jpegBuf, unsigned long jpegSize, int n, unsigned char **dstBufs, unsigned long *dstSizes, tjtransform *transforms, int flags)
 Losslessly transform a JPEG image into another JPEG image. More...
 
DLLEXPORT int DLLCALL tjTransform (tjhandle handle, const unsigned char *jpegBuf, unsigned long jpegSize, int n, unsigned char **dstBufs, unsigned long *dstSizes, tjtransform *transforms, int flags)
 Losslessly transform a JPEG image into another JPEG image. More...
 
DLLEXPORT int DLLCALL tjDestroy (tjhandle handle)
 Destroy a TurboJPEG compressor, decompressor, or transformer instance. More...
 
-

This option will prevent tjTransform() from outputting a JPEG image for this particular transform (this can be used in conjunction with a custom filter to capture the transformed DCT coefficients without transcoding them.)

+

This option will prevent tjTransform() from outputting a JPEG image for this particular transform (this can be used in conjunction with a custom filter to capture the transformed DCT coefficients without transcoding them.)

@@ -559,7 +559,7 @@

Macro Definition Documentation

-

This option will cause tjTransform() to return an error if the transform is not perfect.

+

This option will cause tjTransform() to return an error if the transform is not perfect.

Lossless transforms operate on MCU blocks, whose size depends on the level of chrominance subsampling used (see tjMCUWidth and tjMCUHeight.) If the image's width or height is not evenly divisible by the MCU block size, then there will be partial MCU blocks on the right and/or bottom edges. It is not possible to move these partial MCU blocks to the top or left of the image, so any transform that would require that is "imperfect." If this option is not specified, then any partial MCU blocks that cannot be transformed will be left in place, which will create odd-looking strips on the right or bottom edge of the image.

@@ -574,7 +574,7 @@

Macro Definition Documentation

-

This option will cause tjTransform() to discard any partial MCU blocks that cannot be transformed.

+

This option will cause tjTransform() to discard any partial MCU blocks that cannot be transformed.

@@ -761,7 +761,7 @@

Enumeration Type Documentation

-

Transform operations for tjTransform()

+

Transform operations for tjTransform()

Enumerator
TJXOP_NONE 

Do not transform the position of the image pixels.

@@ -812,7 +812,7 @@

Function Documentation

Allocate an image buffer for use with TurboJPEG.

-

You should always use this function to allocate the JPEG destination buffer(s) for tjCompress2() and tjTransform() unless you are disabling automatic buffer (re)allocation (by setting TJFLAG_NOREALLOC.)

+

You should always use this function to allocate the JPEG destination buffer(s) for tjCompress2() and tjTransform() unless you are disabling automatic buffer (re)allocation (by setting TJFLAG_NOREALLOC.)

Parameters
@@ -918,7 +918,7 @@

Function Documentation

- +
bytesthe number of bytes to allocate
@@ -931,7 +931,7 @@

Function Documentation

- + @@ -1000,7 +1000,7 @@

Function Documentation

Parameters
unsigned char * const unsigned char *  srcBuf,
- + @@ -1022,7 +1022,7 @@

Function Documentation

- +
handlea handle to a TurboJPEG compressor or transformer instance
srcBufpointer to an image buffer containing RGB, grayscale, or CMYK pixels to be compressed. This buffer is not modified.
srcBufpointer to an image buffer containing RGB, grayscale, or CMYK pixels to be compressed
widthwidth (in pixels) of the source image
pitchbytes per line in the source image. Normally, this should be width * tjPixelSize[pixelFormat] if the image is unpadded, or TJPAD(width * tjPixelSize[pixelFormat]) if each line of the image is padded to the nearest 32-bit boundary, as is the case for Windows bitmaps. You can also be clever and use this parameter to skip lines, etc. Setting this parameter to 0 is the equivalent of setting it to width * tjPixelSize[pixelFormat].
heightheight (in pixels) of the source image
@@ -1035,7 +1035,7 @@

Function Documentation

- + @@ -1098,7 +1098,7 @@

Function Documentation

Parameters
unsigned char * const unsigned char *  srcBuf,
- + @@ -1119,7 +1119,7 @@

Function Documentation

- +
handlea handle to a TurboJPEG compressor or transformer instance
srcBufpointer to an image buffer containing a YUV planar image to be compressed. The size of this buffer should match the value returned by tjBufSizeYUV2() for the given image width, height, padding, and level of chrominance subsampling. The Y, U (Cb), and V (Cr) image planes should be stored sequentially in the source buffer (refer to YUV Image Format Notes.) This buffer is not modified.
srcBufpointer to an image buffer containing a YUV planar image to be compressed. The size of this buffer should match the value returned by tjBufSizeYUV2() for the given image width, height, padding, and level of chrominance subsampling. The Y, U (Cb), and V (Cr) image planes should be stored sequentially in the source buffer (refer to YUV Image Format Notes.)
widthwidth (in pixels) of the source image. If the width is not an even multiple of the MCU block width (see tjMCUWidth), then an intermediate buffer copy will be performed within TurboJPEG.
padthe line padding used in the source image. For instance, if each line in each plane of the YUV image is padded to the nearest multiple of 4 bytes, then pad should be set to 4.
heightheight (in pixels) of the source image. If the height is not an even multiple of the MCU block height (see tjMCUHeight), then an intermediate buffer copy will be performed within TurboJPEG.
@@ -1132,7 +1132,7 @@

Function Documentation

- + @@ -1144,7 +1144,7 @@

Function Documentation

- + @@ -1195,7 +1195,7 @@

Function Documentation

Parameters
unsigned char ** const unsigned char **  srcPlanes,
int * const int *  strides,
- + @@ -1216,7 +1216,7 @@

Function Documentation

- +
handlea handle to a TurboJPEG compressor or transformer instance
srcPlanesan array of pointers to Y, U (Cb), and V (Cr) image planes (or just a Y plane, if compressing a grayscale image) that contain a YUV image to be compressed. These planes can be contiguous or non-contiguous in memory. The size of each plane should match the value returned by tjPlaneSizeYUV() for the given image width, height, strides, and level of chrominance subsampling. Refer to YUV Image Format Notes for more details. These image planes are not modified.
srcPlanesan array of pointers to Y, U (Cb), and V (Cr) image planes (or just a Y plane, if compressing a grayscale image) that contain a YUV image to be compressed. These planes can be contiguous or non-contiguous in memory. The size of each plane should match the value returned by tjPlaneSizeYUV() for the given image width, height, strides, and level of chrominance subsampling. Refer to YUV Image Format Notes for more details.
widthwidth (in pixels) of the source image. If the width is not an even multiple of the MCU block width (see tjMCUWidth), then an intermediate buffer copy will be performed within TurboJPEG.
stridesan array of integers, each specifying the number of bytes per line in the corresponding plane of the YUV source image. Setting the stride for any plane to 0 is the same as setting it to the plane width (see YUV Image Format Notes.) If strides is NULL, then the strides for all planes will be set to their respective plane widths. You can adjust the strides in order to specify an arbitrary amount of line padding in each plane or to create a JPEG image from a subregion of a larger YUV planar image.
heightheight (in pixels) of the source image. If the height is not an even multiple of the MCU block height (see tjMCUHeight), then an intermediate buffer copy will be performed within TurboJPEG.
@@ -1229,7 +1229,7 @@

Function Documentation

- + @@ -1293,7 +1293,7 @@

Function Documentation

Parameters
unsigned char * const unsigned char *  srcBuf,
- + @@ -1309,7 +1309,7 @@

Function Documentation

- +
handlea handle to a TurboJPEG decompressor or transformer instance
srcBufpointer to an image buffer containing a YUV planar image to be decoded. The size of this buffer should match the value returned by tjBufSizeYUV2() for the given image width, height, padding, and level of chrominance subsampling. The Y, U (Cb), and V (Cr) image planes should be stored sequentially in the source buffer (refer to YUV Image Format Notes.) This buffer is not modified.
srcBufpointer to an image buffer containing a YUV planar image to be decoded. The size of this buffer should match the value returned by tjBufSizeYUV2() for the given image width, height, padding, and level of chrominance subsampling. The Y, U (Cb), and V (Cr) image planes should be stored sequentially in the source buffer (refer to YUV Image Format Notes.)
padUse this parameter to specify that the width of each line in each plane of the YUV source image is padded to the nearest multiple of this number of bytes (must be a power of 2.)
subsampthe level of chrominance subsampling used in the YUV source image (see Chrominance subsampling options.)
dstBufpointer to an image buffer that will receive the decoded image. This buffer should normally be pitch * height bytes in size, but the dstBuf pointer can also be used to decode into a specific region of a larger buffer.
@@ -1322,13 +1322,13 @@

Function Documentation

- + - + @@ -1386,7 +1386,7 @@

Function Documentation

Parameters
unsigned char ** const unsigned char **  srcPlanes,
int * const int *  strides,
- + @@ -1402,7 +1402,7 @@

Function Documentation

- +
handlea handle to a TurboJPEG decompressor or transformer instance
srcPlanesan array of pointers to Y, U (Cb), and V (Cr) image planes (or just a Y plane, if decoding a grayscale image) that contain a YUV image to be decoded. These planes can be contiguous or non-contiguous in memory. The size of each plane should match the value returned by tjPlaneSizeYUV() for the given image width, height, strides, and level of chrominance subsampling. Refer to YUV Image Format Notes for more details. These image planes are not modified.
srcPlanesan array of pointers to Y, U (Cb), and V (Cr) image planes (or just a Y plane, if decoding a grayscale image) that contain a YUV image to be decoded. These planes can be contiguous or non-contiguous in memory. The size of each plane should match the value returned by tjPlaneSizeYUV() for the given image width, height, strides, and level of chrominance subsampling. Refer to YUV Image Format Notes for more details.
stridesan array of integers, each specifying the number of bytes per line in the corresponding plane of the YUV source image. Setting the stride for any plane to 0 is the same as setting it to the plane width (see YUV Image Format Notes.) If strides is NULL, then the strides for all planes will be set to their respective plane widths. You can adjust the strides in order to specify an arbitrary amount of line padding in each plane or to decode a subregion of a larger YUV planar image.
subsampthe level of chrominance subsampling used in the YUV source image (see Chrominance subsampling options.)
dstBufpointer to an image buffer that will receive the decoded image. This buffer should normally be pitch * height bytes in size, but the dstBuf pointer can also be used to decode into a specific region of a larger buffer.
@@ -1415,7 +1415,7 @@

Function Documentation

- + @@ -1472,7 +1472,7 @@

Function Documentation

Parameters
unsigned char * const unsigned char *  jpegBuf,
- + @@ -1487,7 +1487,7 @@

Function Documentation

- +
handlea handle to a TurboJPEG decompressor or transformer instance
jpegBufpointer to a buffer containing the JPEG image to decompress. This buffer is not modified.
jpegBufpointer to a buffer containing the JPEG image to decompress
jpegSizesize of the JPEG image (in bytes)
dstBufpointer to an image buffer that will receive the decompressed image. This buffer should normally be pitch * scaledHeight bytes in size, where scaledHeight can be determined by calling TJSCALED() with the JPEG image height and one of the scaling factors returned by tjGetScalingFactors(). The dstBuf pointer may also be used to decompress into a specific region of a larger buffer.
widthdesired width (in pixels) of the destination image. If this is different than the width of the JPEG image being decompressed, then TurboJPEG will use scaling in the JPEG decompressor to generate the largest possible image that will fit within the desired width. If width is set to 0, then only the height will be considered when determining the scaled image size.
@@ -1500,7 +1500,7 @@

Function Documentation

- + @@ -1545,7 +1545,7 @@

Function Documentation

Parameters
unsigned char * const unsigned char *  jpegBuf,
- + @@ -1558,7 +1558,7 @@

Function Documentation

- +
handlea handle to a TurboJPEG decompressor or transformer instance
jpegBufpointer to a buffer containing a JPEG image. This buffer is not modified.
jpegBufpointer to a buffer containing a JPEG image
jpegSizesize of the JPEG image (in bytes)
widthpointer to an integer variable that will receive the width (in pixels) of the JPEG image
heightpointer to an integer variable that will receive the height (in pixels) of the JPEG image
@@ -1571,7 +1571,7 @@

Function Documentation

- + @@ -1623,7 +1623,7 @@

Function Documentation

Parameters
unsigned char * const unsigned char *  jpegBuf,
- + @@ -1637,7 +1637,7 @@

Function Documentation

- +
handlea handle to a TurboJPEG decompressor or transformer instance
jpegBufpointer to a buffer containing the JPEG image to decompress. This buffer is not modified.
jpegBufpointer to a buffer containing the JPEG image to decompress
jpegSizesize of the JPEG image (in bytes)
dstBufpointer to an image buffer that will receive the YUV image. Use tjBufSizeYUV2() to determine the appropriate size for this buffer based on the image width, height, padding, and level of subsampling. The Y, U (Cb), and V (Cr) image planes will be stored sequentially in the buffer (refer to YUV Image Format Notes.)
widthdesired width (in pixels) of the YUV image. If this is different than the width of the JPEG image being decompressed, then TurboJPEG will use scaling in the JPEG decompressor to generate the largest possible image that will fit within the desired width. If width is set to 0, then only the height will be considered when determining the scaled image size. If the scaled width is not an even multiple of the MCU block width (see tjMCUWidth), then an intermediate buffer copy will be performed within TurboJPEG.
@@ -1650,7 +1650,7 @@

Function Documentation

- + @@ -1702,7 +1702,7 @@

Function Documentation

Parameters
unsigned char * const unsigned char *  jpegBuf,
- + @@ -1741,7 +1741,7 @@

Function Documentation

- +
handlea handle to a TurboJPEG decompressor or transformer instance
jpegBufpointer to a buffer containing the JPEG image to decompress. This buffer is not modified.
jpegBufpointer to a buffer containing the JPEG image to decompress
jpegSizesize of the JPEG image (in bytes)
dstPlanesan array of pointers to Y, U (Cb), and V (Cr) image planes (or just a Y plane, if decompressing a grayscale image) that will receive the YUV image. These planes can be contiguous or non-contiguous in memory. Use tjPlaneSizeYUV() to determine the appropriate size for each plane based on the scaled image width, scaled image height, strides, and level of chrominance subsampling. Refer to YUV Image Format Notes for more details.
widthdesired width (in pixels) of the YUV image. If this is different than the width of the JPEG image being decompressed, then TurboJPEG will use scaling in the JPEG decompressor to generate the largest possible image that will fit within the desired width. If width is set to 0, then only the height will be considered when determining the scaled image size. If the scaled width is not an even multiple of the MCU block width (see tjMCUWidth), then an intermediate buffer copy will be performed within TurboJPEG.
@@ -1754,7 +1754,7 @@

Function Documentation

- + @@ -1818,7 +1818,7 @@

Function Documentation

Parameters
unsigned char * const unsigned char *  srcBuf,
- + @@ -1834,7 +1834,7 @@

Function Documentation

- +
handlea handle to a TurboJPEG compressor or transformer instance
srcBufpointer to an image buffer containing RGB or grayscale pixels to be encoded. This buffer is not modified.
srcBufpointer to an image buffer containing RGB or grayscale pixels to be encoded
widthwidth (in pixels) of the source image
pitchbytes per line in the source image. Normally, this should be width * tjPixelSize[pixelFormat] if the image is unpadded, or TJPAD(width * tjPixelSize[pixelFormat]) if each line of the image is padded to the nearest 32-bit boundary, as is the case for Windows bitmaps. You can also be clever and use this parameter to skip lines, etc. Setting this parameter to 0 is the equivalent of setting it to width * tjPixelSize[pixelFormat].
heightheight (in pixels) of the source image
@@ -1847,7 +1847,7 @@

Function Documentation

- + @@ -1911,7 +1911,7 @@

Function Documentation

Parameters
unsigned char * const unsigned char *  srcBuf,
- + @@ -1942,7 +1942,7 @@

Function Documentation

Free an image buffer previously allocated by TurboJPEG.

-

You should always use this function to free JPEG destination buffer(s) that were automatically (re)allocated by tjCompress2() or tjTransform() or that were manually allocated using tjAlloc().

+

You should always use this function to free JPEG destination buffer(s) that were automatically (re)allocated by tjCompress2() or tjTransform() or that were manually allocated using tjAlloc().

Parameters
handlea handle to a TurboJPEG compressor or transformer instance
srcBufpointer to an image buffer containing RGB or grayscale pixels to be encoded. This buffer is not modified.
srcBufpointer to an image buffer containing RGB or grayscale pixels to be encoded
widthwidth (in pixels) of the source image
pitchbytes per line in the source image. Normally, this should be width * tjPixelSize[pixelFormat] if the image is unpadded, or TJPAD(width * tjPixelSize[pixelFormat]) if each line of the image is padded to the nearest 32-bit boundary, as is the case for Windows bitmaps. You can also be clever and use this parameter to skip lines, etc. Setting this parameter to 0 is the equivalent of setting it to width * tjPixelSize[pixelFormat].
heightheight (in pixels) of the source image
@@ -2199,7 +2199,7 @@

Function Documentation

- +
bufferaddress of the buffer to free
@@ -2212,7 +2212,7 @@

Function Documentation

- + @@ -2264,7 +2264,7 @@

Function Documentation

Parameters
unsigned char * const unsigned char *  jpegBuf,
- + - +
handlea handle to a TurboJPEG transformer instance
jpegBufpointer to a buffer containing the JPEG source image to transform. This buffer is not modified.
jpegBufpointer to a buffer containing the JPEG source image to transform
jpegSizesize of the JPEG source image (in bytes)
nthe number of transformed JPEG images to generate
dstBufspointer to an array of n image buffers. dstBufs[i] will receive a JPEG image that has been transformed using the parameters in transforms[i]. TurboJPEG has the ability to reallocate the JPEG buffer to accommodate the size of the JPEG image. Thus, you can choose to:
    diff --git a/doc/html/search/all_74.js b/doc/html/search/all_74.js index 5b46106fc..444aaef21 100644 --- a/doc/html/search/all_74.js +++ b/doc/html/search/all_74.js @@ -8,24 +8,24 @@ var searchData= ['tjblueoffset',['tjBlueOffset',['../group___turbo_j_p_e_g.html#ga84e2e35d3f08025f976ec1ec53693dea',1,'turbojpeg.h']]], ['tjbufsize',['tjBufSize',['../group___turbo_j_p_e_g.html#gaccc5bca7f12fcdcc302e6e1c6d4b311b',1,'turbojpeg.h']]], ['tjbufsizeyuv2',['tjBufSizeYUV2',['../group___turbo_j_p_e_g.html#gaf451664a62c1f6c7cc5a6401f32908c9',1,'turbojpeg.h']]], - ['tjcompress2',['tjCompress2',['../group___turbo_j_p_e_g.html#gaba62b7a98f960839b588579898495cf2',1,'turbojpeg.h']]], - ['tjcompressfromyuv',['tjCompressFromYUV',['../group___turbo_j_p_e_g.html#ga0b931126c7a615ddc3bbd0cca6698d67',1,'turbojpeg.h']]], - ['tjcompressfromyuvplanes',['tjCompressFromYUVPlanes',['../group___turbo_j_p_e_g.html#gaa89a1982cb4556b12ae7af4439991af6',1,'turbojpeg.h']]], + ['tjcompress2',['tjCompress2',['../group___turbo_j_p_e_g.html#gaf38f2ed44bdc88e730e08b632fa6e88e',1,'turbojpeg.h']]], + ['tjcompressfromyuv',['tjCompressFromYUV',['../group___turbo_j_p_e_g.html#ga6f6de375d6ec0020faba627e37e5a060',1,'turbojpeg.h']]], + ['tjcompressfromyuvplanes',['tjCompressFromYUVPlanes',['../group___turbo_j_p_e_g.html#ga0b84c682d8accf097d7a743c965d3464',1,'turbojpeg.h']]], ['tjcs',['TJCS',['../group___turbo_j_p_e_g.html#ga4f83ad3368e0e29d1957be0efa7c3720',1,'turbojpeg.h']]], ['tjcs_5fcmyk',['TJCS_CMYK',['../group___turbo_j_p_e_g.html#gga4f83ad3368e0e29d1957be0efa7c3720a6c8b636152ac8195b869587db315ee53',1,'turbojpeg.h']]], ['tjcs_5fgray',['TJCS_GRAY',['../group___turbo_j_p_e_g.html#gga4f83ad3368e0e29d1957be0efa7c3720ab3e7d6a87f695e45b81c1b5262b5a50a',1,'turbojpeg.h']]], ['tjcs_5frgb',['TJCS_RGB',['../group___turbo_j_p_e_g.html#gga4f83ad3368e0e29d1957be0efa7c3720a677cb7ccb85c4038ac41964a2e09e555',1,'turbojpeg.h']]], ['tjcs_5fycbcr',['TJCS_YCbCr',['../group___turbo_j_p_e_g.html#gga4f83ad3368e0e29d1957be0efa7c3720a7389b8f65bb387ffedce3efd0d78ec75',1,'turbojpeg.h']]], ['tjcs_5fycck',['TJCS_YCCK',['../group___turbo_j_p_e_g.html#gga4f83ad3368e0e29d1957be0efa7c3720a53839e0fe867b76b58d16b0a1a7c598e',1,'turbojpeg.h']]], - ['tjdecodeyuv',['tjDecodeYUV',['../group___turbo_j_p_e_g.html#ga132ae2c2cadcf64c8bb0f3bdf69da3ed',1,'turbojpeg.h']]], - ['tjdecodeyuvplanes',['tjDecodeYUVPlanes',['../group___turbo_j_p_e_g.html#ga6cb5b0e1101a2b20edea576e11faf93d',1,'turbojpeg.h']]], - ['tjdecompress2',['tjDecompress2',['../group___turbo_j_p_e_g.html#gada69cc6443d1bb493b40f1626259e5e9',1,'turbojpeg.h']]], - ['tjdecompressheader3',['tjDecompressHeader3',['../group___turbo_j_p_e_g.html#gacd0fac3af74b3511d39b4781b7103086',1,'turbojpeg.h']]], - ['tjdecompresstoyuv2',['tjDecompressToYUV2',['../group___turbo_j_p_e_g.html#ga7c08b340ad7f8e85d407bd9e81d44d07',1,'turbojpeg.h']]], - ['tjdecompresstoyuvplanes',['tjDecompressToYUVPlanes',['../group___turbo_j_p_e_g.html#ga0828a38ae29631ac28b6857cefb0eebf',1,'turbojpeg.h']]], + ['tjdecodeyuv',['tjDecodeYUV',['../group___turbo_j_p_e_g.html#ga077c61027b875afecd5a1613bf18b3c1',1,'turbojpeg.h']]], + ['tjdecodeyuvplanes',['tjDecodeYUVPlanes',['../group___turbo_j_p_e_g.html#gaf42f19b7a496eb18bdc84fe61ee6d3e2',1,'turbojpeg.h']]], + ['tjdecompress2',['tjDecompress2',['../group___turbo_j_p_e_g.html#gad8026a417e16a76313bc0a6c9e8b2ba2',1,'turbojpeg.h']]], + ['tjdecompressheader3',['tjDecompressHeader3',['../group___turbo_j_p_e_g.html#ga3fced455e504e8ff4fbad28ba94a3020',1,'turbojpeg.h']]], + ['tjdecompresstoyuv2',['tjDecompressToYUV2',['../group___turbo_j_p_e_g.html#ga39e08906528db5a764670ea48d344b09',1,'turbojpeg.h']]], + ['tjdecompresstoyuvplanes',['tjDecompressToYUVPlanes',['../group___turbo_j_p_e_g.html#ga38d0ef90692663b3ffb5b16da2541512',1,'turbojpeg.h']]], ['tjdestroy',['tjDestroy',['../group___turbo_j_p_e_g.html#ga674adee917b95ad4a896f1ba39e12540',1,'turbojpeg.h']]], - ['tjencodeyuv3',['tjEncodeYUV3',['../group___turbo_j_p_e_g.html#ga0a5ffbf7cb58a5b6a8201114fe889360',1,'turbojpeg.h']]], - ['tjencodeyuvplanes',['tjEncodeYUVPlanes',['../group___turbo_j_p_e_g.html#gaa791db8598853ddcad24e42897ef1269',1,'turbojpeg.h']]], + ['tjencodeyuv3',['tjEncodeYUV3',['../group___turbo_j_p_e_g.html#gaabe05acd734990053ad1294b5ef239aa',1,'turbojpeg.h']]], + ['tjencodeyuvplanes',['tjEncodeYUVPlanes',['../group___turbo_j_p_e_g.html#ga8a65ed3bd12df57c219d46afbc9008f1',1,'turbojpeg.h']]], ['tjflag_5faccuratedct',['TJFLAG_ACCURATEDCT',['../group___turbo_j_p_e_g.html#gacb233cfd722d66d1ccbf48a7de81f0e0',1,'turbojpeg.h']]], ['tjflag_5fbottomup',['TJFLAG_BOTTOMUP',['../group___turbo_j_p_e_g.html#ga72ecf4ebe6eb702d3c6f5ca27455e1ec',1,'turbojpeg.h']]], ['tjflag_5ffastdct',['TJFLAG_FASTDCT',['../group___turbo_j_p_e_g.html#gaabce235db80d3f698b27f36cbd453da2',1,'turbojpeg.h']]], @@ -70,7 +70,7 @@ var searchData= ['tjsamp_5fgray',['TJSAMP_GRAY',['../group___turbo_j_p_e_g.html#gga1d047060ea80bb9820d540bb928e9074a3f1c9504842ddc7a48d0f690754b6248',1,'turbojpeg.h']]], ['tjscaled',['TJSCALED',['../group___turbo_j_p_e_g.html#ga84878bb65404204743aa18cac02781df',1,'turbojpeg.h']]], ['tjscalingfactor',['tjscalingfactor',['../structtjscalingfactor.html',1,'']]], - ['tjtransform',['tjtransform',['../structtjtransform.html',1,'tjtransform'],['../group___turbo_j_p_e_g.html#gae403193ceb4aafb7e0f56ab587b48616',1,'tjTransform(tjhandle handle, unsigned char *jpegBuf, unsigned long jpegSize, int n, unsigned char **dstBufs, unsigned long *dstSizes, tjtransform *transforms, int flags): turbojpeg.h'],['../group___turbo_j_p_e_g.html#gaa29f3189c41be12ec5dee7caec318a31',1,'tjtransform(): turbojpeg.h']]], + ['tjtransform',['tjtransform',['../structtjtransform.html',1,'tjtransform'],['../group___turbo_j_p_e_g.html#gad02cd42b69f193a0623a9c801788df3a',1,'tjTransform(tjhandle handle, const unsigned char *jpegBuf, unsigned long jpegSize, int n, unsigned char **dstBufs, unsigned long *dstSizes, tjtransform *transforms, int flags): turbojpeg.h'],['../group___turbo_j_p_e_g.html#gaa29f3189c41be12ec5dee7caec318a31',1,'tjtransform(): turbojpeg.h']]], ['tjxop',['TJXOP',['../group___turbo_j_p_e_g.html#ga2de531af4e7e6c4f124908376b354866',1,'turbojpeg.h']]], ['tjxop_5fhflip',['TJXOP_HFLIP',['../group___turbo_j_p_e_g.html#gga2de531af4e7e6c4f124908376b354866aa0df69776caa30f0fa28e26332d311ce',1,'turbojpeg.h']]], ['tjxop_5fnone',['TJXOP_NONE',['../group___turbo_j_p_e_g.html#gga2de531af4e7e6c4f124908376b354866aad88c0366cd3f7d0eac9d7a3fa1c2c27',1,'turbojpeg.h']]], diff --git a/doc/html/search/functions_74.js b/doc/html/search/functions_74.js index 73b7ee98f..69410b051 100644 --- a/doc/html/search/functions_74.js +++ b/doc/html/search/functions_74.js @@ -3,18 +3,18 @@ var searchData= ['tjalloc',['tjAlloc',['../group___turbo_j_p_e_g.html#ga5c9234bda6d993cdaffdd89bf81a00ff',1,'turbojpeg.h']]], ['tjbufsize',['tjBufSize',['../group___turbo_j_p_e_g.html#gaccc5bca7f12fcdcc302e6e1c6d4b311b',1,'turbojpeg.h']]], ['tjbufsizeyuv2',['tjBufSizeYUV2',['../group___turbo_j_p_e_g.html#gaf451664a62c1f6c7cc5a6401f32908c9',1,'turbojpeg.h']]], - ['tjcompress2',['tjCompress2',['../group___turbo_j_p_e_g.html#gaba62b7a98f960839b588579898495cf2',1,'turbojpeg.h']]], - ['tjcompressfromyuv',['tjCompressFromYUV',['../group___turbo_j_p_e_g.html#ga0b931126c7a615ddc3bbd0cca6698d67',1,'turbojpeg.h']]], - ['tjcompressfromyuvplanes',['tjCompressFromYUVPlanes',['../group___turbo_j_p_e_g.html#gaa89a1982cb4556b12ae7af4439991af6',1,'turbojpeg.h']]], - ['tjdecodeyuv',['tjDecodeYUV',['../group___turbo_j_p_e_g.html#ga132ae2c2cadcf64c8bb0f3bdf69da3ed',1,'turbojpeg.h']]], - ['tjdecodeyuvplanes',['tjDecodeYUVPlanes',['../group___turbo_j_p_e_g.html#ga6cb5b0e1101a2b20edea576e11faf93d',1,'turbojpeg.h']]], - ['tjdecompress2',['tjDecompress2',['../group___turbo_j_p_e_g.html#gada69cc6443d1bb493b40f1626259e5e9',1,'turbojpeg.h']]], - ['tjdecompressheader3',['tjDecompressHeader3',['../group___turbo_j_p_e_g.html#gacd0fac3af74b3511d39b4781b7103086',1,'turbojpeg.h']]], - ['tjdecompresstoyuv2',['tjDecompressToYUV2',['../group___turbo_j_p_e_g.html#ga7c08b340ad7f8e85d407bd9e81d44d07',1,'turbojpeg.h']]], - ['tjdecompresstoyuvplanes',['tjDecompressToYUVPlanes',['../group___turbo_j_p_e_g.html#ga0828a38ae29631ac28b6857cefb0eebf',1,'turbojpeg.h']]], + ['tjcompress2',['tjCompress2',['../group___turbo_j_p_e_g.html#gaf38f2ed44bdc88e730e08b632fa6e88e',1,'turbojpeg.h']]], + ['tjcompressfromyuv',['tjCompressFromYUV',['../group___turbo_j_p_e_g.html#ga6f6de375d6ec0020faba627e37e5a060',1,'turbojpeg.h']]], + ['tjcompressfromyuvplanes',['tjCompressFromYUVPlanes',['../group___turbo_j_p_e_g.html#ga0b84c682d8accf097d7a743c965d3464',1,'turbojpeg.h']]], + ['tjdecodeyuv',['tjDecodeYUV',['../group___turbo_j_p_e_g.html#ga077c61027b875afecd5a1613bf18b3c1',1,'turbojpeg.h']]], + ['tjdecodeyuvplanes',['tjDecodeYUVPlanes',['../group___turbo_j_p_e_g.html#gaf42f19b7a496eb18bdc84fe61ee6d3e2',1,'turbojpeg.h']]], + ['tjdecompress2',['tjDecompress2',['../group___turbo_j_p_e_g.html#gad8026a417e16a76313bc0a6c9e8b2ba2',1,'turbojpeg.h']]], + ['tjdecompressheader3',['tjDecompressHeader3',['../group___turbo_j_p_e_g.html#ga3fced455e504e8ff4fbad28ba94a3020',1,'turbojpeg.h']]], + ['tjdecompresstoyuv2',['tjDecompressToYUV2',['../group___turbo_j_p_e_g.html#ga39e08906528db5a764670ea48d344b09',1,'turbojpeg.h']]], + ['tjdecompresstoyuvplanes',['tjDecompressToYUVPlanes',['../group___turbo_j_p_e_g.html#ga38d0ef90692663b3ffb5b16da2541512',1,'turbojpeg.h']]], ['tjdestroy',['tjDestroy',['../group___turbo_j_p_e_g.html#ga674adee917b95ad4a896f1ba39e12540',1,'turbojpeg.h']]], - ['tjencodeyuv3',['tjEncodeYUV3',['../group___turbo_j_p_e_g.html#ga0a5ffbf7cb58a5b6a8201114fe889360',1,'turbojpeg.h']]], - ['tjencodeyuvplanes',['tjEncodeYUVPlanes',['../group___turbo_j_p_e_g.html#gaa791db8598853ddcad24e42897ef1269',1,'turbojpeg.h']]], + ['tjencodeyuv3',['tjEncodeYUV3',['../group___turbo_j_p_e_g.html#gaabe05acd734990053ad1294b5ef239aa',1,'turbojpeg.h']]], + ['tjencodeyuvplanes',['tjEncodeYUVPlanes',['../group___turbo_j_p_e_g.html#ga8a65ed3bd12df57c219d46afbc9008f1',1,'turbojpeg.h']]], ['tjfree',['tjFree',['../group___turbo_j_p_e_g.html#ga8c4a1231dc06a450514c835f6471f137',1,'turbojpeg.h']]], ['tjgeterrorstr',['tjGetErrorStr',['../group___turbo_j_p_e_g.html#ga9af79c908ec131b1ae8d52fe40375abf',1,'turbojpeg.h']]], ['tjgetscalingfactors',['tjGetScalingFactors',['../group___turbo_j_p_e_g.html#ga6449044b9af402999ccf52f401333be8',1,'turbojpeg.h']]], @@ -24,5 +24,5 @@ var searchData= ['tjplaneheight',['tjPlaneHeight',['../group___turbo_j_p_e_g.html#ga1a209696c6a80748f20e134b3c64789f',1,'turbojpeg.h']]], ['tjplanesizeyuv',['tjPlaneSizeYUV',['../group___turbo_j_p_e_g.html#ga6f98d977bfa9d167c97172e876ba61e2',1,'turbojpeg.h']]], ['tjplanewidth',['tjPlaneWidth',['../group___turbo_j_p_e_g.html#ga63fb66bb1e36c74008c4634360becbb1',1,'turbojpeg.h']]], - ['tjtransform',['tjTransform',['../group___turbo_j_p_e_g.html#gae403193ceb4aafb7e0f56ab587b48616',1,'turbojpeg.h']]] + ['tjtransform',['tjTransform',['../group___turbo_j_p_e_g.html#gad02cd42b69f193a0623a9c801788df3a',1,'turbojpeg.h']]] ]; diff --git a/doc/html/structtjtransform.html b/doc/html/structtjtransform.html index 7a07c2aa2..3bfd1291d 100644 --- a/doc/html/structtjtransform.html +++ b/doc/html/structtjtransform.html @@ -133,7 +133,7 @@
arrayRegiontjregion structure containing the width and height of the array pointed to by coeffs as well as its offset relative to the component plane. TurboJPEG implementations may choose to split each component plane into multiple DCT coefficient arrays and call the callback function once for each array.
planeRegiontjregion structure containing the width and height of the component plane to which coeffs belongs
componentIDID number of the component plane to which coeffs belongs (Y, Cb, and Cr have, respectively, ID's of 0, 1, and 2 in typical JPEG images.)
transformIDID number of the transformed image to which coeffs belongs. This is the same as the index of the transform in the transforms array that was passed to tjTransform().
transformIDID number of the transformed image to which coeffs belongs. This is the same as the index of the transform in the transforms array that was passed to tjTransform().
transforma pointer to a tjtransform structure that specifies the parameters and/or cropping region for this transform
diff --git a/jdatasrc-tj.c b/jdatasrc-tj.c index 09f959602..87e84b1d9 100644 --- a/jdatasrc-tj.c +++ b/jdatasrc-tj.c @@ -157,7 +157,7 @@ term_source (j_decompress_ptr cinfo) GLOBAL(void) jpeg_mem_src_tj (j_decompress_ptr cinfo, - unsigned char * inbuffer, unsigned long insize) + const unsigned char * inbuffer, unsigned long insize) { struct jpeg_source_mgr * src; @@ -181,5 +181,5 @@ jpeg_mem_src_tj (j_decompress_ptr cinfo, src->resync_to_restart = jpeg_resync_to_restart; /* use default method */ src->term_source = term_source; src->bytes_in_buffer = (size_t) insize; - src->next_input_byte = (JOCTET *) inbuffer; + src->next_input_byte = (const JOCTET *) inbuffer; } diff --git a/turbojpeg-jni.c b/turbojpeg-jni.c index b3e99fbc6..4d9900c91 100644 --- a/turbojpeg-jni.c +++ b/turbojpeg-jni.c @@ -291,7 +291,8 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFrom tjhandle handle=0; unsigned long jpegSize=0; jbyteArray jSrcPlanes[3]={NULL, NULL, NULL}; - unsigned char *srcPlanes[3], *jpegBuf=NULL; + const unsigned char *srcPlanes[3]; + unsigned char *jpegBuf=NULL; int *srcOffsets=NULL, *srcStrides=NULL; int nc=(subsamp==org_libjpegturbo_turbojpeg_TJ_SAMP_GRAY? 1:3), i; @@ -349,8 +350,8 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFrom for(i=0; iReleasePrimitiveArrayCritical(env, jSrcPlanes[i], srcPlanes[i], - 0); + (*env)->ReleasePrimitiveArrayCritical(env, jSrcPlanes[i], + (unsigned char *)srcPlanes[i], 0); } if(srcStrides) (*env)->ReleasePrimitiveArrayCritical(env, jSrcStrides, srcStrides, 0); @@ -449,7 +450,7 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ /* TurboJPEG 1.4.x: TJCompressor::encodeYUV() int source */ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIIIII_3_3B_3I_3III (JNIEnv *env, jobject obj, jintArray src, jint x, jint y, jint width, - jint stride, jint height, jint pf, jobjectArray dstobjs, + jint stride, jint height, jint pf, jobjectArray dstobjs, jintArray jDstOffsets, jintArray jDstStrides, jint subsamp, jint flags) { if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF) @@ -847,7 +848,8 @@ static void TJDecompressor_decodeYUV tjhandle handle=0; jsize arraySize=0, actualPitch; jbyteArray jSrcPlanes[3]={NULL, NULL, NULL}; - unsigned char *srcPlanes[3], *dstBuf=NULL; + const unsigned char *srcPlanes[3]; + unsigned char *dstBuf=NULL; int *srcOffsets=NULL, *srcStrides=NULL; int nc=(subsamp==org_libjpegturbo_turbojpeg_TJ_SAMP_GRAY? 1:3), i; @@ -907,8 +909,8 @@ static void TJDecompressor_decodeYUV for(i=0; iReleasePrimitiveArrayCritical(env, jSrcPlanes[i], srcPlanes[i], - 0); + (*env)->ReleasePrimitiveArrayCritical(env, jSrcPlanes[i], + (unsigned char *)srcPlanes[i], 0); } if(srcStrides) (*env)->ReleasePrimitiveArrayCritical(env, jSrcStrides, srcStrides, 0); diff --git a/turbojpeg.c b/turbojpeg.c index 5ba9a19be..cd9bfd734 100644 --- a/turbojpeg.c +++ b/turbojpeg.c @@ -44,7 +44,8 @@ extern void jpeg_mem_dest_tj(j_compress_ptr, unsigned char **, unsigned long *, boolean); -extern void jpeg_mem_src_tj(j_decompress_ptr, unsigned char *, unsigned long); +extern void jpeg_mem_src_tj(j_decompress_ptr, const unsigned char *, + unsigned long); #define PAD(v, p) ((v+(p)-1)&(~((p)-1))) #define isPow2(x) (((x)&(x-1))==0) @@ -728,7 +729,7 @@ DLLEXPORT unsigned long DLLCALL tjPlaneSizeYUV(int componentID, int width, } -DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf, +DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, const unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf, unsigned long *jpegSize, int jpegSubsamp, int jpegQual, int flags) { @@ -785,8 +786,9 @@ DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf, _throw("tjCompress2(): Memory allocation failure"); for(i=0; inext_scanlineimage_height) { @@ -827,9 +829,10 @@ DLLEXPORT int DLLCALL tjCompress(tjhandle handle, unsigned char *srcBuf, } -DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle, unsigned char *srcBuf, - int width, int pitch, int height, int pixelFormat, unsigned char **dstPlanes, - int *strides, int subsamp, int flags) +DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle, + const unsigned char *srcBuf, int width, int pitch, int height, + int pixelFormat, unsigned char **dstPlanes, int *strides, int subsamp, + int flags) { int i, retval=0; JSAMPROW *row_pointer=NULL; JSAMPLE *_tmpbuf[MAX_COMPONENTS], *_tmpbuf2[MAX_COMPONENTS]; @@ -910,8 +913,9 @@ DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle, unsigned char *srcBuf, _throw("tjEncodeYUVPlanes(): Memory allocation failure"); for(i=0; iv_samp_factor/dinfo->max_v_samp_factor; inbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph[i]); if(!inbuf[i]) _throw("tjDecodeYUVPlanes(): Memory allocation failure"); - ptr=srcPlanes[i]; + ptr=(JSAMPLE *)srcPlanes[i]; for(row=0; row=NUMSUBOPT @@ -1698,8 +1704,8 @@ DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf, } DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle, - unsigned char *jpegBuf, unsigned long jpegSize, unsigned char **dstPlanes, - int width, int *strides, int height, int flags) + const unsigned char *jpegBuf, unsigned long jpegSize, + unsigned char **dstPlanes, int width, int *strides, int height, int flags) { int i, sfi, row, retval=0; JSAMPROW *outbuf[MAX_COMPONENTS]; int jpegwidth, jpegheight, jpegSubsamp, scaledw, scaledh; @@ -1872,7 +1878,7 @@ DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle, } DLLEXPORT int DLLCALL tjDecompressToYUV2(tjhandle handle, - unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, + const unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, int width, int pad, int height, int flags) { unsigned char *dstPlanes[3]; @@ -1959,9 +1965,9 @@ DLLEXPORT tjhandle DLLCALL tjInitTransform(void) } -DLLEXPORT int DLLCALL tjTransform(tjhandle handle, unsigned char *jpegBuf, - unsigned long jpegSize, int n, unsigned char **dstBufs, - unsigned long *dstSizes, tjtransform *t, int flags) +DLLEXPORT int DLLCALL tjTransform(tjhandle handle, + const unsigned char *jpegBuf, unsigned long jpegSize, int n, + unsigned char **dstBufs, unsigned long *dstSizes, tjtransform *t, int flags) { jpeg_transform_info *xinfo=NULL; jvirt_barray_ptr *srccoefs, *dstcoefs; diff --git a/turbojpeg.h b/turbojpeg.h index d5c624e10..583029fa7 100644 --- a/turbojpeg.h +++ b/turbojpeg.h @@ -619,7 +619,7 @@ DLLEXPORT tjhandle DLLCALL tjInitCompress(void); * @param handle a handle to a TurboJPEG compressor or transformer instance * * @param srcBuf pointer to an image buffer containing RGB, grayscale, or - * CMYK pixels to be compressed. This buffer is not modified. + * CMYK pixels to be compressed * * @param width width (in pixels) of the source image * @@ -672,7 +672,7 @@ DLLEXPORT tjhandle DLLCALL tjInitCompress(void); * * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ -DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf, +DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, const unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf, unsigned long *jpegSize, int jpegSubsamp, int jpegQual, int flags); @@ -687,7 +687,7 @@ DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf, * #tjBufSizeYUV2() for the given image width, height, padding, and level of * chrominance subsampling. The Y, U (Cb), and V (Cr) image planes should be * stored sequentially in the source buffer (refer to @ref YUVnotes - * "YUV Image Format Notes".) This buffer is not modified. + * "YUV Image Format Notes".) * * @param width width (in pixels) of the source image. If the width is not an * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate @@ -736,9 +736,9 @@ DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf, * * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ -DLLEXPORT int DLLCALL tjCompressFromYUV(tjhandle handle, unsigned char *srcBuf, - int width, int pad, int height, int subsamp, unsigned char **jpegBuf, - unsigned long *jpegSize, int jpegQual, int flags); +DLLEXPORT int DLLCALL tjCompressFromYUV(tjhandle handle, + const unsigned char *srcBuf, int width, int pad, int height, int subsamp, + unsigned char **jpegBuf, unsigned long *jpegSize, int jpegQual, int flags); /** @@ -752,7 +752,7 @@ DLLEXPORT int DLLCALL tjCompressFromYUV(tjhandle handle, unsigned char *srcBuf, * memory. The size of each plane should match the value returned by * #tjPlaneSizeYUV() for the given image width, height, strides, and level of * chrominance subsampling. Refer to @ref YUVnotes "YUV Image Format Notes" - * for more details. These image planes are not modified. + * for more details. * * @param width width (in pixels) of the source image. If the width is not an * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate @@ -807,8 +807,9 @@ DLLEXPORT int DLLCALL tjCompressFromYUV(tjhandle handle, unsigned char *srcBuf, * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ DLLEXPORT int DLLCALL tjCompressFromYUVPlanes(tjhandle handle, - unsigned char **srcPlanes, int width, int *strides, int height, int subsamp, - unsigned char **jpegBuf, unsigned long *jpegSize, int jpegQual, int flags); + const unsigned char **srcPlanes, int width, const int *strides, int height, + int subsamp, unsigned char **jpegBuf, unsigned long *jpegSize, int jpegQual, + int flags); /** @@ -926,7 +927,7 @@ DLLEXPORT int tjPlaneHeight(int componentID, int height, int subsamp); * @param handle a handle to a TurboJPEG compressor or transformer instance * * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels - * to be encoded. This buffer is not modified. + * to be encoded * * @param width width (in pixels) of the source image * @@ -966,8 +967,8 @@ DLLEXPORT int tjPlaneHeight(int componentID, int height, int subsamp); * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ DLLEXPORT int DLLCALL tjEncodeYUV3(tjhandle handle, - unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, - unsigned char *dstBuf, int pad, int subsamp, int flags); + const unsigned char *srcBuf, int width, int pitch, int height, + int pixelFormat, unsigned char *dstBuf, int pad, int subsamp, int flags); /** @@ -979,7 +980,7 @@ DLLEXPORT int DLLCALL tjEncodeYUV3(tjhandle handle, * @param handle a handle to a TurboJPEG compressor or transformer instance * * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels - * to be encoded. This buffer is not modified. + * to be encoded * * @param width width (in pixels) of the source image * @@ -1024,8 +1025,9 @@ DLLEXPORT int DLLCALL tjEncodeYUV3(tjhandle handle, * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle, - unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, - unsigned char **dstPlanes, int *strides, int subsamp, int flags); + const unsigned char *srcBuf, int width, int pitch, int height, + int pixelFormat, unsigned char **dstPlanes, int *strides, int subsamp, + int flags); /** @@ -1042,8 +1044,7 @@ DLLEXPORT tjhandle DLLCALL tjInitDecompress(void); * * @param handle a handle to a TurboJPEG decompressor or transformer instance * - * @param jpegBuf pointer to a buffer containing a JPEG image. This buffer is - * not modified. + * @param jpegBuf pointer to a buffer containing a JPEG image * * @param jpegSize size of the JPEG image (in bytes) * @@ -1064,8 +1065,8 @@ DLLEXPORT tjhandle DLLCALL tjInitDecompress(void); * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ DLLEXPORT int DLLCALL tjDecompressHeader3(tjhandle handle, - unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height, - int *jpegSubsamp, int *jpegColorspace); + const unsigned char *jpegBuf, unsigned long jpegSize, int *width, + int *height, int *jpegSubsamp, int *jpegColorspace); /** @@ -1086,8 +1087,7 @@ DLLEXPORT tjscalingfactor* DLLCALL tjGetScalingFactors(int *numscalingfactors); * * @param handle a handle to a TurboJPEG decompressor or transformer instance * - * @param jpegBuf pointer to a buffer containing the JPEG image to decompress. - * This buffer is not modified. + * @param jpegBuf pointer to a buffer containing the JPEG image to decompress * * @param jpegSize size of the JPEG image (in bytes) * @@ -1132,7 +1132,7 @@ DLLEXPORT tjscalingfactor* DLLCALL tjGetScalingFactors(int *numscalingfactors); * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle, - unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, + const unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, int width, int pitch, int height, int pixelFormat, int flags); @@ -1143,8 +1143,7 @@ DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle, * * @param handle a handle to a TurboJPEG decompressor or transformer instance * - * @param jpegBuf pointer to a buffer containing the JPEG image to decompress. - * This buffer is not modified. + * @param jpegBuf pointer to a buffer containing the JPEG image to decompress * * @param jpegSize size of the JPEG image (in bytes) * @@ -1183,7 +1182,7 @@ DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle, * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ DLLEXPORT int DLLCALL tjDecompressToYUV2(tjhandle handle, - unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, + const unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, int width, int pad, int height, int flags); @@ -1194,8 +1193,7 @@ DLLEXPORT int DLLCALL tjDecompressToYUV2(tjhandle handle, * * @param handle a handle to a TurboJPEG decompressor or transformer instance * - * @param jpegBuf pointer to a buffer containing the JPEG image to decompress. - * This buffer is not modified. + * @param jpegBuf pointer to a buffer containing the JPEG image to decompress * * @param jpegSize size of the JPEG image (in bytes) * @@ -1240,8 +1238,8 @@ DLLEXPORT int DLLCALL tjDecompressToYUV2(tjhandle handle, * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle, - unsigned char *jpegBuf, unsigned long jpegSize, unsigned char **dstPlanes, - int width, int *strides, int height, int flags); + const unsigned char *jpegBuf, unsigned long jpegSize, + unsigned char **dstPlanes, int width, int *strides, int height, int flags); /** @@ -1257,7 +1255,7 @@ DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle, * #tjBufSizeYUV2() for the given image width, height, padding, and level of * chrominance subsampling. The Y, U (Cb), and V (Cr) image planes should be * stored sequentially in the source buffer (refer to @ref YUVnotes - * "YUV Image Format Notes".) This buffer is not modified. + * "YUV Image Format Notes".) * * @param pad Use this parameter to specify that the width of each line in each * plane of the YUV source image is padded to the nearest multiple of this @@ -1291,7 +1289,7 @@ DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle, * * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ -DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf, +DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, const unsigned char *srcBuf, int pad, int subsamp, unsigned char *dstBuf, int width, int pitch, int height, int pixelFormat, int flags); @@ -1310,7 +1308,7 @@ DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf, * The size of each plane should match the value returned by #tjPlaneSizeYUV() * for the given image width, height, strides, and level of chrominance * subsampling. Refer to @ref YUVnotes "YUV Image Format Notes" for more - * details. These image planes are not modified. + * details. * * @param strides an array of integers, each specifying the number of bytes per * line in the corresponding plane of the YUV source image. Setting the stride @@ -1349,8 +1347,9 @@ DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf, * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ DLLEXPORT int DLLCALL tjDecodeYUVPlanes(tjhandle handle, - unsigned char **srcPlanes, int *strides, int subsamp, unsigned char *dstBuf, - int width, int pitch, int height, int pixelFormat, int flags); + const unsigned char **srcPlanes, const int *strides, int subsamp, + unsigned char *dstBuf, int width, int pitch, int height, int pixelFormat, + int flags); /** @@ -1378,7 +1377,7 @@ DLLEXPORT tjhandle DLLCALL tjInitTransform(void); * @param handle a handle to a TurboJPEG transformer instance * * @param jpegBuf pointer to a buffer containing the JPEG source image to - * transform. This buffer is not modified. + * transform * * @param jpegSize size of the JPEG source image (in bytes) * @@ -1417,9 +1416,10 @@ DLLEXPORT tjhandle DLLCALL tjInitTransform(void); * * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ -DLLEXPORT int DLLCALL tjTransform(tjhandle handle, unsigned char *jpegBuf, - unsigned long jpegSize, int n, unsigned char **dstBufs, - unsigned long *dstSizes, tjtransform *transforms, int flags); +DLLEXPORT int DLLCALL tjTransform(tjhandle handle, + const unsigned char *jpegBuf, unsigned long jpegSize, int n, + unsigned char **dstBufs, unsigned long *dstSizes, tjtransform *transforms, + int flags); /**