From 40dd3146cde2ba5036fe76a4f09e1125b4592347 Mon Sep 17 00:00:00 2001 From: DRC Date: Sun, 17 Aug 2014 12:23:49 +0000 Subject: [PATCH] Refactored YUVImage Java class so that it supports both unified YUV image buffers as well as separate YUV image planes; modified the JNI functions accordingly and added new helper functions to the TurboJPEG C API (tjPlaneWidth(), tjPlaneHeight(), tjPlaneSizeYUV()) to facilitate those modifications; changed potentially confusing "component width" and "component height" terms to "plane width" and "plane height" and modified variable names in turbojpeg.c to reflect this; numerous other documentation tweaks git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@1360 632fc199-4ca6-4c93-a231-07263d6284db --- doc/html/group___turbo_j_p_e_g.html | 224 +++++++-- doc/html/search/all_74.js | 5 +- doc/html/search/functions_74.js | 3 + java/TJExample.java | 2 +- java/doc/deprecated-list.html | 64 ++- java/doc/index-all.html | 242 ++++++---- java/doc/index.html | 9 +- java/doc/org/libjpegturbo/turbojpeg/TJ.html | 124 ++++- .../libjpegturbo/turbojpeg/TJCompressor.html | 161 ++++--- .../turbojpeg/TJCustomFilter.html | 4 +- .../turbojpeg/TJDecompressor.html | 284 +++++------ .../turbojpeg/TJScalingFactor.html | 8 +- .../libjpegturbo/turbojpeg/TJTransform.html | 14 +- .../libjpegturbo/turbojpeg/TJTransformer.html | 16 +- .../org/libjpegturbo/turbojpeg/YUVImage.html | 319 +++++++++++-- java/org/libjpegturbo/turbojpeg/TJ.java | 82 +++- .../libjpegturbo/turbojpeg/TJCompressor.java | 79 +++- .../turbojpeg/TJDecompressor.java | 175 ++++--- .../turbojpeg/TJScalingFactor.java | 11 +- .../libjpegturbo/turbojpeg/TJTransformer.java | 4 +- java/org/libjpegturbo/turbojpeg/YUVImage.java | 298 ++++++++++-- java/org_libjpegturbo_turbojpeg_TJ.h | 24 + .../org_libjpegturbo_turbojpeg_TJCompressor.h | 18 +- ...rg_libjpegturbo_turbojpeg_TJDecompressor.h | 18 +- turbojpeg-jni.c | 443 ++++++++++++++---- turbojpeg-mapfile.jni | 15 +- turbojpeg.c | 282 +++++++---- turbojpeg.h | 218 +++++---- 28 files changed, 2260 insertions(+), 886 deletions(-) diff --git a/doc/html/group___turbo_j_p_e_g.html b/doc/html/group___turbo_j_p_e_g.html index e40189e..c7b19bf 100644 --- a/doc/html/group___turbo_j_p_e_g.html +++ b/doc/html/group___turbo_j_p_e_g.html @@ -241,6 +241,15 @@ Functions DLLEXPORT unsigned long DLLCALL tjBufSizeYUV2 (int width, int pad, int height, int subsamp)  The size of the buffer (in bytes) required to hold a YUV planar image with the given parameters. More...
  +DLLEXPORT unsigned long DLLCALL tjPlaneSizeYUV (int componentID, int width, int stride, int height, int subsamp) + The size of the buffer (in bytes) required to hold a YUV image plane with the given parameters. More...
+  +DLLEXPORT int tjPlaneWidth (int componentID, int width, int subsamp) + The plane width of a YUV image plane 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...
  @@ -317,7 +326,7 @@ Variables

YUV Image Format Notes

Technically, the JPEG format uses the YCbCr colorspace (which is technically not a colorspace but a color transform), but per the convention of the digital video community, the TurboJPEG API uses "YUV" to refer to an image format consisting of Y, Cb, and Cr image planes.

-

Each plane is simply a 2D array of bytes, each byte representing the value of one of the components (Y, Cb, or Cr) at a particular location in the image. The "component width" and "component height" of each plane are determined by the image width, height, and level of chrominance subsampling. For the luminance plane, the component width is the image width padded to the nearest multiple of the horizontal subsampling factor (2 in the case of 4:2:0 and 4:2:2, 4 in the case of 4:1:1, 1 in the case of 4:4:4 or grayscale.) Similarly, the component height of the luminance plane is the image height padded to the nearest multiple of the vertical subsampling factor (2 in the case of 4:2:0 or 4:4:0, 1 in the case of 4:4:4 or grayscale.) This is irrespective of any additional padding that may be specified as an argument to the various YUV functions. The component width of the chrominance planes is equal to the component width of the luminance plane divided by the horizontal subsampling factor, and the component height of the chrominance planes is equal to the component height of the luminance plane divided by the vertical subsampling factor.

+

Each plane is simply a 2D array of bytes, each byte representing the value of one of the components (Y, Cb, or Cr) at a particular location in the image. The width and height of each plane are determined by the image width, height, and level of chrominance subsampling. The luminance plane width is the image width padded to the nearest multiple of the horizontal subsampling factor (2 in the case of 4:2:0 and 4:2:2, 4 in the case of 4:1:1, 1 in the case of 4:4:4 or grayscale.) Similarly, the luminance plane height is the image height padded to the nearest multiple of the vertical subsampling factor (2 in the case of 4:2:0 or 4:4:0, 1 in the case of 4:4:4 or grayscale.) This is irrespective of any additional padding that may be specified as an argument to the various YUV functions. The chrominance plane width is equal to the luminance plane width divided by the horizontal subsampling factor, and the chrominance plane height is equal to the luminance plane height divided by the vertical subsampling factor.

For example, if the source image is 35 x 35 pixels and 4:2:2 subsampling is used, then the luminance plane would be 36 x 35 bytes, and each of the chrominance planes would be 18 x 35 bytes. If you specify a line padding of 4 bytes on top of this, then the luminance plane would be 36 x 35 bytes, and each of the chrominance planes would be 20 x 35 bytes.

Macro Definition Documentation

@@ -810,7 +819,7 @@ Variables -
Returns
a pointer to a newly-allocated buffer with the specified number of bytes
+
Returns
a pointer to a newly-allocated buffer with the specified number of bytes.
See Also
tjFree()
@@ -849,8 +858,8 @@ Variables

The number of bytes returned by this function is larger than the size of the uncompressed source image. The reason for this is that the JPEG format uses 16-bit coefficients, and it is thus possible for a very high-quality JPEG image with very high-frequency content to expand rather than compress when converted to the JPEG format. Such images represent a very rare corner case, but since there is no way to predict the size of a JPEG image prior to compression, the corner case has to be handled.

Parameters
- - + +
widthwidth of the image (in pixels)
heightheight of the image (in pixels)
widthwidth (in pixels) of the image
heightheight (in pixels) of the image
jpegSubsampthe level of chrominance subsampling to be used when generating the JPEG image (see Chrominance subsampling options.)
@@ -898,9 +907,9 @@ Variables

The size of the buffer (in bytes) required to hold a YUV planar image with the given parameters.

Parameters
- + - +
widthwidth of the image (in pixels)
widthwidth (in pixels) of the image
padthe width of each line in each plane of the image is padded to the nearest multiple of this number of bytes (must be a power of 2.)
heightheight of the image (in pixels)
heightheight (in pixels) of the image
subsamplevel of chrominance subsampling in the image (see Chrominance subsampling options.)
@@ -993,7 +1002,7 @@ Variables handlea handle to a TurboJPEG compressor or transformer instance srcBufpointer to an image buffer containing RGB, grayscale, or CMYK pixels to be compressed widthwidth (in pixels) of the source image - pitchbytes per line of 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]. + 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 pixelFormatpixel format of the source image (see Pixel formats.) jpegBufaddress of a pointer to an image 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:
    @@ -1005,7 +1014,7 @@ If you choose option 1, *jpegSize should be set to the size of your jpegSizepointer to an unsigned long variable that holds the size of the JPEG image 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.) jpegSubsampthe level of chrominance subsampling to be used when generating the JPEG image (see Chrominance subsampling options.) jpegQualthe image quality of the generated JPEG image (1 = worst, 100 = best) - flagsthe bitwise OR of one or more of the flags. + flagsthe bitwise OR of one or more of the flags
@@ -1102,7 +1111,7 @@ If you choose option 1, *jpegSize should be set to the size of your If you choose option 1, *jpegSize should be set to the size of your pre-allocated buffer. In any case, unless you have set TJFLAG_NOREALLOC, you should always check *jpegBuf upon return from this function, as it may have changed. jpegSizepointer to an unsigned long variable that holds the size of the JPEG image 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.) jpegQualthe image quality of the generated JPEG image (1 = worst, 100 = best) - flagsthe bitwise OR of one or more of the flags. + flagsthe bitwise OR of one or more of the flags
@@ -1186,9 +1195,9 @@ If you choose option 1, *jpegSize should be set to the size of your
Parameters
- + - + - +
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. Each plane should be at least {component stride} * {component height} bytes in size. (See below for a description of stride, and refer to YUV Image Format Notes for a description of component height.)
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 component width for the plane. If strides is NULL, then the strides for all planes will be set to their respective component 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.
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.
subsampthe level of chrominance subsampling used in the source image (see Chrominance subsampling options.)
jpegBufaddress of a pointer to an image 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:
    @@ -1199,7 +1208,7 @@ If you choose option 1, *jpegSize should be set to the size of your If you choose option 1, *jpegSize should be set to the size of your pre-allocated buffer. In any case, unless you have set TJFLAG_NOREALLOC, you should always check *jpegBuf upon return from this function, as it may have changed.
jpegSizepointer to an unsigned long variable that holds the size of the JPEG image 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.)
jpegQualthe image quality of the generated JPEG image (1 = worst, 100 = best)
flagsthe bitwise OR of one or more of the flags.
flagsthe bitwise OR of one or more of the flags
@@ -1289,10 +1298,10 @@ If you choose option 1, *jpegSize should be set to the size of your 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. widthwidth (in pixels) of the source and destination images - pitchbytes per line of the destination image. Normally, this should be width * tjPixelSize[pixelFormat] if the destination image is unpadded, or TJPAD(width * tjPixelSize[pixelFormat]) if each line of the destination image should be padded to the nearest 32-bit boundary, as is the case for Windows bitmaps. You can also be clever and use the pitch parameter to skip lines, etc. Setting this parameter to 0 is the equivalent of setting it to width * tjPixelSize[pixelFormat]. + pitchbytes per line in the destination image. Normally, this should be width * tjPixelSize[pixelFormat] if the destination image is unpadded, or TJPAD(width * tjPixelSize[pixelFormat]) if each line of the destination image should be padded to the nearest 32-bit boundary, as is the case for Windows bitmaps. You can also be clever and use the pitch 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 and destination images pixelFormatpixel format of the destination image (see Pixel formats.) - flagsthe bitwise OR of one or more of the flags. + flagsthe bitwise OR of one or more of the flags @@ -1377,15 +1386,15 @@ If you choose option 1, *jpegSize should be set to the size of your
Parameters
- - + + - + - +
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. Each plane should be at least {component stride} * {component height} bytes in size. (See below for a description of stride, and refer to YUV Image Format Notes for a description of component height.)
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 component width for the plane. If strides is NULL, then the strides for all planes will be set to their respective component 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.
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.
widthwidth (in pixels) of the source and destination images
pitchbytes per line of the destination image. Normally, this should be width * tjPixelSize[pixelFormat] if the destination image is unpadded, or TJPAD(width * tjPixelSize[pixelFormat]) if each line of the destination image should be padded to the nearest 32-bit boundary, as is the case for Windows bitmaps. You can also be clever and use the pitch parameter to skip lines, etc. Setting this parameter to 0 is the equivalent of setting it to width * tjPixelSize[pixelFormat].
pitchbytes per line in the destination image. Normally, this should be width * tjPixelSize[pixelFormat] if the destination image is unpadded, or TJPAD(width * tjPixelSize[pixelFormat]) if each line of the destination image should be padded to the nearest 32-bit boundary, as is the case for Windows bitmaps. You can also be clever and use the pitch 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 and destination images
pixelFormatpixel format of the destination image (see Pixel formats.)
flagsthe bitwise OR of one or more of the flags.
flagsthe bitwise OR of one or more of the flags
@@ -1467,10 +1476,10 @@ If you choose option 1, *jpegSize should be set to the size of your 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. - pitchbytes per line of the destination image. Normally, this is scaledWidth * tjPixelSize[pixelFormat] if the decompressed image is unpadded, else TJPAD(scaledWidth * tjPixelSize[pixelFormat]) if each line of the decompressed image is padded to the nearest 32-bit boundary, as is the case for Windows bitmaps. (NOTE: scaledWidth can be determined by calling TJSCALED() with the JPEG image width and one of the scaling factors returned by tjGetScalingFactors().) You can also be clever and use the pitch parameter to skip lines, etc. Setting this parameter to 0 is the equivalent of setting it to scaledWidth * tjPixelSize[pixelFormat]. + pitchbytes per line in the destination image. Normally, this is scaledWidth * tjPixelSize[pixelFormat] if the decompressed image is unpadded, else TJPAD(scaledWidth * tjPixelSize[pixelFormat]) if each line of the decompressed image is padded to the nearest 32-bit boundary, as is the case for Windows bitmaps. (NOTE: scaledWidth can be determined by calling TJSCALED() with the JPEG image width and one of the scaling factors returned by tjGetScalingFactors().) You can also be clever and use the pitch parameter to skip lines, etc. Setting this parameter to 0 is the equivalent of setting it to scaledWidth * tjPixelSize[pixelFormat]. heightdesired height (in pixels) of the destination image. If this is different than the height 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 height. If height is set to 0, then only the width will be considered when determining the scaled image size. pixelFormatpixel format of the destination image (see Pixel formats.) - flagsthe bitwise OR of one or more of the flags. + flagsthe bitwise OR of one or more of the flags @@ -1540,7 +1549,7 @@ If you choose option 1, *jpegSize should be set to the size of your 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 - jpegSubsamppointer to an integer variable that will receive the level of chrominance subsampling used when compressing the JPEG image (see Chrominance subsampling options.) + jpegSubsamppointer to an integer variable that will receive the level of chrominance subsampling used when the JPEG image was compressed (see Chrominance subsampling options.) jpegColorspacepointer to an integer variable that will receive one of the JPEG colorspace constants, indicating the colorspace of the JPEG image (see JPEG colorspaces.) @@ -1620,7 +1629,7 @@ If you choose option 1, *jpegSize should be set to the size of your 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. padthe width of each line in each plane of the YUV image will be padded to the nearest multiple of this number of bytes (must be a power of 2.) To generate images suitable for X Video, pad should be set to 4. heightdesired height (in pixels) of the YUV image. If this is different than the height 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 height. If height is set to 0, then only the width will be considered when determining the scaled image size. If the scaled height is not an even multiple of the MCU block height (see tjMCUHeight), then an intermediate buffer copy will be performed within TurboJPEG. - flagsthe bitwise OR of one or more of the flags. + flagsthe bitwise OR of one or more of the flags @@ -1695,11 +1704,11 @@ If you choose option 1, *jpegSize should be set to the size of your handlea handle to a TurboJPEG decompressor or transformer instance 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. Each plane should be at least {component stride} * {scaled component height} bytes in size. (See below for a description of stride, and refer to YUV Image Format Notes for a description of component height.) + 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. - stridesan array of integers, each specifying the number of bytes per line in the corresponding plane of the output image. Setting the stride for any plane to 0 is the same as setting it to the scaled component width for the plane. If strides is NULL, then the strides for all planes will be set to their respective scaled component widths. You can adjust the strides in order to add an arbitrary amount of line padding to each plane or to decompress the JPEG image into a subregion of a larger YUV planar image. + stridesan array of integers, each specifying the number of bytes per line in the corresponding plane of the output image. Setting the stride for any plane to 0 is the same as setting it to the scaled plane width (see YUV Image Format Notes.) If strides is NULL, then the strides for all planes will be set to their respective scaled plane widths. You can adjust the strides in order to add an arbitrary amount of line padding to each plane or to decompress the JPEG image into a subregion of a larger YUV planar image. heightdesired height (in pixels) of the YUV image. If this is different than the height 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 height. If height is set to 0, then only the width will be considered when determining the scaled image size. If the scaled height is not an even multiple of the MCU block height (see tjMCUHeight), then an intermediate buffer copy will be performed within TurboJPEG. - flagsthe bitwise OR of one or more of the flags. + flagsthe bitwise OR of one or more of the flags @@ -1811,13 +1820,13 @@ If you choose option 1, *jpegSize should be set to the size of your handlea handle to a TurboJPEG compressor or transformer instance srcBufpointer to an image buffer containing RGB or grayscale pixels to be encoded widthwidth (in pixels) of the source image - pitchbytes per line of 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]. + 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 pixelFormatpixel format of the source image (see Pixel formats.) 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 chrominance subsampling. The Y, U (Cb), and V (Cr) image planes will be stored sequentially in the buffer (refer to YUV Image Format Notes.) padthe width of each line in each plane of the YUV image will be padded to the nearest multiple of this number of bytes (must be a power of 2.) To generate images suitable for X Video, pad should be set to 4. subsampthe level of chrominance subsampling to be used when generating the YUV image (see Chrominance subsampling options.) To generate images suitable for X Video, subsamp should be set to TJSAMP_420. This produces an image compatible with the I420 (AKA "YUV420P") format. - flagsthe bitwise OR of one or more of the flags. + flagsthe bitwise OR of one or more of the flags @@ -1904,13 +1913,13 @@ If you choose option 1, *jpegSize should be set to the size of your handlea handle to a TurboJPEG compressor or transformer instance srcBufpointer to an image buffer containing RGB or grayscale pixels to be encoded widthwidth (in pixels) of the source image - pitchbytes per line of 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]. + 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 pixelFormatpixel format of the source image (see Pixel formats.) - dstPlanesan array of pointers to Y, U (Cb), and V (Cr) image planes (or just a Y plane, if generating a grayscale image) that will receive the encoded image. These planes can be contiguous or non-contiguous in memory. Each plane should be at least {component stride} * {component height} bytes in size. (See below for a description of stride, and refer to YUV Image Format Notes for a description of component height.) - stridesan array of integers, each specifying the number of bytes per line in the corresponding plane of the output image. Setting the stride for any plane to 0 is the same as setting it to the component width for the plane. If strides is NULL, then the strides for all planes will be set to their respective component widths. You can adjust the strides in order to add an arbitrary amount of line padding to each plane or to encode an RGB or grayscale image into a subregion of a larger YUV planar image. + dstPlanesan array of pointers to Y, U (Cb), and V (Cr) image planes (or just a Y plane, if generating a grayscale image) that will receive the encoded image. These planes can be contiguous or non-contiguous in memory. Use tjPlaneSizeYUV() to determine the appropriate size for each plane based on the 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 output 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 add an arbitrary amount of line padding to each plane or to encode an RGB or grayscale image into a subregion of a larger YUV planar image. subsampthe level of chrominance subsampling to be used when generating the YUV image (see Chrominance subsampling options.) To generate images suitable for X Video, subsamp should be set to TJSAMP_420. This produces an image compatible with the I420 (AKA "YUV420P") format. - flagsthe bitwise OR of one or more of the flags. + flagsthe bitwise OR of one or more of the flags @@ -2043,6 +2052,151 @@ If you choose option 1, *jpegSize should be set to the size of your

Create a new TurboJPEG transformer instance.

Returns
a handle to the newly-created instance, or NULL if an error occurred (see tjGetErrorStr().)
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
DLLEXPORT int tjPlaneHeight (int componentID,
int height,
int subsamp 
)
+
+ +

The plane height of a YUV image plane with the given parameters.

+

Refer to YUV Image Format Notes for a description of plane height.

+
Parameters
+ + + + +
componentIDID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)
heightheight (in pixels) of the YUV image
subsamplevel of chrominance subsampling in the image (see Chrominance subsampling options.)
+
+
+
Returns
the plane height of a YUV image plane with the given parameters, or -1 if the arguments are out of bounds.
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DLLEXPORT unsigned long DLLCALL tjPlaneSizeYUV (int componentID,
int width,
int stride,
int height,
int subsamp 
)
+
+ +

The size of the buffer (in bytes) required to hold a YUV image plane with the given parameters.

+
Parameters
+ + + + + + +
componentIDID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)
widthwidth (in pixels) of the YUV image. NOTE: this is the width of the whole image, not the plane width.
stridebytes per line in the image plane. Setting this to 0 is the equivalent of setting it to the plane width.
heightheight (in pixels) of the YUV image. NOTE: this is the height of the whole image, not the plane height.
subsamplevel of chrominance subsampling in the image (see Chrominance subsampling options.)
+
+
+
Returns
the size of the buffer (in bytes) required to hold the YUV image plane, or -1 if the arguments are out of bounds.
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
DLLEXPORT int tjPlaneWidth (int componentID,
int width,
int subsamp 
)
+
+ +

The plane width of a YUV image plane with the given parameters.

+

Refer to YUV Image Format Notes for a description of plane width.

+
Parameters
+ + + + +
componentIDID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)
widthwidth (in pixels) of the YUV image
subsamplevel of chrominance subsampling in the image (see Chrominance subsampling options.)
+
+
+
Returns
the plane width of a YUV image plane with the given parameters, or -1 if the arguments are out of bounds.
+
@@ -2106,12 +2260,12 @@ If you choose option 1, *jpegSize should be set to the size of your

Losslessly transform a JPEG image into another JPEG image.

-

Lossless transforms work by moving the raw coefficients from one JPEG image structure to another without altering the values of the coefficients. While this is typically faster than decompressing the image, transforming it, and re-compressing it, lossless transforms are not free. Each lossless transform requires reading and performing Huffman decoding on all of the coefficients in the source image, regardless of the size of the destination image. Thus, this function provides a means of generating multiple transformed images from the same source or applying multiple transformations simultaneously, in order to eliminate the need to read the source coefficients multiple times.

+

Lossless transforms work by moving the raw DCT coefficients from one JPEG image structure to another without altering the values of the coefficients. While this is typically faster than decompressing the image, transforming it, and re-compressing it, lossless transforms are not free. Each lossless transform requires reading and performing Huffman decoding on all of the coefficients in the source image, regardless of the size of the destination image. Thus, this function provides a means of generating multiple transformed images from the same source or applying multiple transformations simultaneously, in order to eliminate the need to read the source coefficients multiple times.

Parameters
- - + + - +
handlea handle to a TurboJPEG transformer instance
jpegBufpointer to a buffer containing the JPEG image to transform
jpegSizesize of the JPEG image (in bytes)
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:
  1. pre-allocate the JPEG buffer with an arbitrary size using tjAlloc() and let TurboJPEG grow the buffer as needed,
  2. @@ -2121,7 +2275,7 @@ If you choose option 1, *jpegSize should be set to the size of your If you choose option 1, dstSizes[i] should be set to the size of your pre-allocated buffer. In any case, unless you have set TJFLAG_NOREALLOC, you should always check dstBufs[i] upon return from this function, as it may have changed.
dstSizespointer to an array of n unsigned long variables that will receive the actual sizes (in bytes) of each transformed JPEG image. If dstBufs[i] points to a pre-allocated buffer, then dstSizes[i] should be set to the size of the buffer. Upon return, dstSizes[i] will contain the size of the JPEG image (in bytes.)
transformspointer to an array of n tjtransform structures, each of which specifies the transform parameters and/or cropping region for the corresponding transformed output image.
flagsthe bitwise OR of one or more of the flags.
flagsthe bitwise OR of one or more of the flags
diff --git a/doc/html/search/all_74.js b/doc/html/search/all_74.js index 7b50830..5b46106 100644 --- a/doc/html/search/all_74.js +++ b/doc/html/search/all_74.js @@ -56,6 +56,9 @@ var searchData= ['tjpf_5fxbgr',['TJPF_XBGR',['../group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aaf6603b27147de47e212e75dac027b2af',1,'turbojpeg.h']]], ['tjpf_5fxrgb',['TJPF_XRGB',['../group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aadae996905efcfa3b42a0bb3bea7f9d84',1,'turbojpeg.h']]], ['tjpixelsize',['tjPixelSize',['../group___turbo_j_p_e_g.html#gad77cf8fe5b2bfd3cb3f53098146abb4c',1,'turbojpeg.h']]], + ['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']]], ['tjredoffset',['tjRedOffset',['../group___turbo_j_p_e_g.html#gadd9b446742ac8a3923f7992c7988fea8',1,'turbojpeg.h']]], ['tjregion',['tjregion',['../structtjregion.html',1,'']]], ['tjsamp',['TJSAMP',['../group___turbo_j_p_e_g.html#ga1d047060ea80bb9820d540bb928e9074',1,'turbojpeg.h']]], @@ -67,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#gaa29f3189c41be12ec5dee7caec318a31',1,'tjtransform(): turbojpeg.h'],['../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']]], + ['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']]], ['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 35a3f8e..73b7ee9 100644 --- a/doc/html/search/functions_74.js +++ b/doc/html/search/functions_74.js @@ -21,5 +21,8 @@ var searchData= ['tjinitcompress',['tjInitCompress',['../group___turbo_j_p_e_g.html#ga3d10c47fbe4a2489a2b30c931551d01a',1,'turbojpeg.h']]], ['tjinitdecompress',['tjInitDecompress',['../group___turbo_j_p_e_g.html#gae5408179d041e2a2f7199c8283cf649e',1,'turbojpeg.h']]], ['tjinittransform',['tjInitTransform',['../group___turbo_j_p_e_g.html#ga3155b775bfbac9dbba869b95a0367902',1,'turbojpeg.h']]], + ['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']]] ]; diff --git a/java/TJExample.java b/java/TJExample.java index 2c6324d..7562114 100644 --- a/java/TJExample.java +++ b/java/TJExample.java @@ -277,7 +277,7 @@ public class TJExample implements TJCustomFilter { scaleFactor.isOne()) { file = new File(argv[1]); FileOutputStream fos = new FileOutputStream(file); - fos.write(tjd.getSourceBuf(), 0, tjd.getSourceSize()); + fos.write(tjd.getJPEGBuf(), 0, tjd.getJPEGSize()); fos.close(); System.exit(0); } diff --git a/java/doc/deprecated-list.html b/java/doc/deprecated-list.html index 79fd7ed..e47ffb1 100644 --- a/java/doc/deprecated-list.html +++ b/java/doc/deprecated-list.html @@ -106,83 +106,73 @@ -org.libjpegturbo.turbojpeg.TJ.bufSizeYUV(int, int, int) - +org.libjpegturbo.turbojpeg.TJ.bufSizeYUV(int, int, int) + -org.libjpegturbo.turbojpeg.TJCompressor.compress(BufferedImage, byte[], int) +org.libjpegturbo.turbojpeg.TJCompressor.compress(BufferedImage, byte[], int) + TJCompressor.setSourceImage(BufferedImage, int, int, int, int) and + TJCompressor.compress(byte[], int) instead.
-org.libjpegturbo.turbojpeg.TJCompressor.compress(BufferedImage, int) +org.libjpegturbo.turbojpeg.TJCompressor.compress(BufferedImage, int)
Use - TJCompressor.setSourceImage(BufferedImage, int, int, int, int) and + TJCompressor.setSourceImage(BufferedImage, int, int, int, int) and TJCompressor.compress(int) instead.
-org.libjpegturbo.turbojpeg.TJDecompressor.decompress(byte[], int, int, int, int, int) +org.libjpegturbo.turbojpeg.TJDecompressor.decompress(byte[], int, int, int, int, int)
Use - TJDecompressor.decompress(byte[], int, int, int, int, int, int, int) instead.
+ TJDecompressor.decompress(byte[], int, int, int, int, int, int, int) instead. -org.libjpegturbo.turbojpeg.TJDecompressor.decompressToYUV(byte[], int) -
Use TJDecompressor.decompressToYUV(YUVImage, int) instead.
+org.libjpegturbo.turbojpeg.TJDecompressor.decompressToYUV(byte[], int) +
Use TJDecompressor.decompressToYUV(YUVImage, int) instead.
org.libjpegturbo.turbojpeg.TJDecompressor.decompressToYUV(int) -
Use TJDecompressor.decompressToYUV(int, int, int, int) instead.
+
Use TJDecompressor.decompressToYUV(int, int, int, int) instead.
-org.libjpegturbo.turbojpeg.TJCompressor.encodeYUV(BufferedImage, byte[], int) +org.libjpegturbo.turbojpeg.TJCompressor.encodeYUV(BufferedImage, byte[], int)
Use - TJCompressor.setSourceImage(BufferedImage, int, int, int, int) and - TJCompressor.encodeYUV(byte[], int) instead.
+ TJCompressor.setSourceImage(BufferedImage, int, int, int, int) and + TJCompressor.encodeYUV(byte[], int) instead. -org.libjpegturbo.turbojpeg.TJCompressor.encodeYUV(BufferedImage, int) +org.libjpegturbo.turbojpeg.TJCompressor.encodeYUV(BufferedImage, int)
Use - TJCompressor.setSourceImage(BufferedImage, int, int, int, int) and - TJCompressor.encodeYUV(int) instead.
+ TJCompressor.setSourceImage(BufferedImage, int, int, int, int) and + TJCompressor.encodeYUV(int, int) instead. -org.libjpegturbo.turbojpeg.TJCompressor.encodeYUV(byte[], int) -
Use TJCompressor.encodeYUV(YUVImage, int) instead.
+org.libjpegturbo.turbojpeg.TJCompressor.encodeYUV(byte[], int) +
Use TJCompressor.encodeYUV(YUVImage, int) instead.
org.libjpegturbo.turbojpeg.TJCompressor.encodeYUV(int) -
Use TJCompressor.encodeYUV(int, int) instead.
+
Use TJCompressor.encodeYUV(int, int) instead.
-org.libjpegturbo.turbojpeg.TJDecompressor.getJPEGBuf() -
Use TJDecompressor.getSourceBuf() instead.
+org.libjpegturbo.turbojpeg.TJDecompressor.setJPEGImage(byte[], int) +
Use TJDecompressor.setSourceImage(byte[], int) instead.
-org.libjpegturbo.turbojpeg.TJDecompressor.getJPEGSize() -
Use TJDecompressor.getSourceSize() instead.
- - - -org.libjpegturbo.turbojpeg.TJDecompressor.setJPEGImage(byte[], int) -
Use TJDecompressor.setSourceImage(byte[], int) instead.
- - - -org.libjpegturbo.turbojpeg.TJCompressor.setSourceImage(byte[], int, int, int, int) +org.libjpegturbo.turbojpeg.TJCompressor.setSourceImage(byte[], int, int, int, int)
Use - TJCompressor.setSourceImage(byte[], int, int, int, int, int, int) instead.
+ TJCompressor.setSourceImage(byte[], int, int, int, int, int, int) instead. @@ -201,9 +191,9 @@ -org.libjpegturbo.turbojpeg.TJCompressor(byte[], int, int, int, int) +org.libjpegturbo.turbojpeg.TJCompressor(byte[], int, int, int, int)
Use - TJCompressor.TJCompressor(byte[], int, int, int, int, int, int) instead.
+ TJCompressor.TJCompressor(byte[], int, int, int, int, int, int) instead. diff --git a/java/doc/index-all.html b/java/doc/index-all.html index a976556..1af78be 100644 --- a/java/doc/index-all.html +++ b/java/doc/index-all.html @@ -63,20 +63,20 @@

B

-
bufSize(int, int, int) - Static method in class org.libjpegturbo.turbojpeg.TJ
+
bufSize(int, int, int) - Static method in class org.libjpegturbo.turbojpeg.TJ
Returns the maximum size of the buffer (in bytes) required to hold a JPEG image with the given width, height, and level of chrominance subsampling.
-
bufSizeYUV(int, int, int, int) - Static method in class org.libjpegturbo.turbojpeg.TJ
+
bufSizeYUV(int, int, int, int) - Static method in class org.libjpegturbo.turbojpeg.TJ
Returns the size of the buffer (in bytes) required to hold a YUV planar image with the given width, height, and level of chrominance subsampling.
-
bufSizeYUV(int, int, int) - Static method in class org.libjpegturbo.turbojpeg.TJ
+
bufSizeYUV(int, int, int) - Static method in class org.libjpegturbo.turbojpeg.TJ
@@ -97,7 +97,7 @@
Free the native structures associated with this decompressor instance.
-
compress(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
compress(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
Compress the uncompressed source image associated with this compressor instance and output a JPEG image to the given destination buffer.
@@ -107,19 +107,19 @@
Compress the uncompressed source image associated with this compressor instance and return a buffer containing a JPEG image.
-
compress(BufferedImage, byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
compress(BufferedImage, byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
-
compress(BufferedImage, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
compress(BufferedImage, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
@@ -143,7 +143,7 @@
YCCK colorspace.
-
customFilter(ShortBuffer, Rectangle, Rectangle, int, int, TJTransform) - Method in interface org.libjpegturbo.turbojpeg.TJCustomFilter
+
customFilter(ShortBuffer, Rectangle, Rectangle, int, int, TJTransform) - Method in interface org.libjpegturbo.turbojpeg.TJCustomFilter
A callback function that can be used to modify the DCT coefficients after they are losslessly transformed but before they are transcoded to a new @@ -155,64 +155,70 @@

D

-
decompress(byte[], int, int, int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
decompress(byte[], int, int, int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
Decompress the JPEG source image or decode the YUV source image associated with this decompressor instance and output a grayscale, RGB, or CMYK image to the given destination buffer.
-
decompress(byte[], int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
decompress(byte[], int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
-
decompress(int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
decompress(int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
Decompress the JPEG source image associated with this decompressor instance and return a buffer containing the decompressed image.
-
decompress(int[], int, int, int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
decompress(int[], int, int, int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
Decompress the JPEG source image or decode the YUV source image associated with this decompressor instance and output a grayscale, RGB, or CMYK image to the given destination buffer.
-
decompress(BufferedImage, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
decompress(BufferedImage, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
Decompress the JPEG source image or decode the YUV source image associated with this decompressor instance and output a decompressed/decoded image to the given BufferedImage instance.
-
decompress(int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
decompress(int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
Decompress the JPEG source image or decode the YUV source image associated with this decompressor instance and return a BufferedImage instance containing the decompressed/decoded image.
-
decompressToYUV(YUVImage, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
decompressToYUV(YUVImage, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
Decompress the JPEG source image associated with this decompressor instance into a YUV planar image and store it in the given YUVImage instance.
-
decompressToYUV(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
decompressToYUV(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
-
decompressToYUV(int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
decompressToYUV(int, int[], int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
Decompress the JPEG source image associated with this decompressor - instance into a YUV planar image and return a YUVImage - instance containing the decompressed image.
+ instance into a set of Y, U (Cb), and V (Cr) image planes and return a + YUVImage instance containing the decompressed image planes. +
+
decompressToYUV(int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
+
Decompress the JPEG source image associated with this decompressor + instance into a unified YUV planar image buffer and return a + YUVImage instance containing the decompressed image.
decompressToYUV(int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
@@ -221,44 +227,50 @@

E

-
encodeYUV(YUVImage, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
encodeYUV(YUVImage, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
Encode the uncompressed source image associated with this compressor instance into a YUV planar image and store it in the given YUVImage instance.
-
encodeYUV(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
encodeYUV(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
-
encodeYUV(int, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
encodeYUV(int, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
+
Encode the uncompressed source image associated with this compressor + instance into a unified YUV planar image buffer and return a + YUVImage instance containing the encoded image.
+
+
encodeYUV(int[], int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
Encode the uncompressed source image associated with this compressor - instance into a YUV planar image and return a YUVImage - instance containing the encoded image.
+ instance into separate Y, U (Cb), and V (Cr) image planes and return a + YUVImage instance containing the encoded image planes.
encodeYUV(int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
-
encodeYUV(BufferedImage, byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
encodeYUV(BufferedImage, byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
-
encodeYUV(BufferedImage, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
encodeYUV(BufferedImage, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
equals(TJScalingFactor) - Method in class org.libjpegturbo.turbojpeg.TJScalingFactor
@@ -325,7 +337,8 @@
getBuf() - Method in class org.libjpegturbo.turbojpeg.YUVImage
-
Returns the YUV image buffer
+
Returns the YUV image buffer (if this image is stored in a unified + buffer rather than separate image planes.)
getColorspace() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
@@ -335,7 +348,7 @@
getCompressedSize() - Method in class org.libjpegturbo.turbojpeg.TJCompressor
Returns the size of the image (in bytes) generated by the most recent - compress/encode operation.
+ compress operation.
getDenom() - Method in class org.libjpegturbo.turbojpeg.TJScalingFactor
@@ -353,19 +366,16 @@
getHeight() - Method in class org.libjpegturbo.turbojpeg.YUVImage
-
Returns the height of the YUV image.
+
Returns the height of the YUV image (or subregion.)
getJPEGBuf() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
-
Deprecated. - -
+
Returns the JPEG image buffer associated with this decompressor instance.
getJPEGSize() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
-
Deprecated. - -
+
Returns the size of the JPEG image (in bytes) associated with this + decompressor instance.
getMCUHeight(int) - Static method in class org.libjpegturbo.turbojpeg.TJ
@@ -381,14 +391,24 @@
Returns numerator
+
getOffsets() - Method in class org.libjpegturbo.turbojpeg.YUVImage
+
+
Returns the offsets (in bytes) of each plane within the planes of a larger + YUV image.
+
getPad() - Method in class org.libjpegturbo.turbojpeg.YUVImage
-
Returns the line padding used in the YUV image buffer.
+
Returns the line padding used in the YUV image buffer (if this image is + stored in a unified buffer rather than separate image planes.)
getPixelSize(int) - Static method in class org.libjpegturbo.turbojpeg.TJ
Returns the pixel size (in bytes) for the given pixel format.
+
getPlanes() - Method in class org.libjpegturbo.turbojpeg.YUVImage
+
+
Returns the YUV image planes.
+
getRedOffset(int) - Static method in class org.libjpegturbo.turbojpeg.TJ
For the given pixel format, returns the number of bytes that the red @@ -398,13 +418,13 @@
Returns the scaled value of dimension.
-
getScaledHeight(int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
getScaledHeight(int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
Returns the height of the largest scaled-down image that the TurboJPEG decompressor can generate without exceeding the desired image width and height.
-
getScaledWidth(int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
getScaledWidth(int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
Returns the width of the largest scaled-down image that the TurboJPEG decompressor can generate without exceeding the desired image width and @@ -417,17 +437,12 @@
getSize() - Method in class org.libjpegturbo.turbojpeg.YUVImage
-
Returns the size (in bytes) of the YUV image buffer
+
Returns the size (in bytes) of the YUV image buffer (if this image is + stored in a unified buffer rather than separate image planes.)
-
getSourceBuf() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
getStrides() - Method in class org.libjpegturbo.turbojpeg.YUVImage
-
Returns the source image buffer associated with this decompressor - instance.
-
-
getSourceSize() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
-
-
Returns the size of the source image (in bytes) associated with this - decompressor instance.
+
Returns the number of bytes per line of each plane in the YUV image.
getSubsamp() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
@@ -450,7 +465,7 @@
getWidth() - Method in class org.libjpegturbo.turbojpeg.YUVImage
-
Returns the width of the YUV image.
+
Returns the width of the YUV image (or subregion.)
@@ -483,6 +498,14 @@
 
jpegBufSize - Variable in class org.libjpegturbo.turbojpeg.TJDecompressor
 
+
jpegColorspace - Variable in class org.libjpegturbo.turbojpeg.TJDecompressor
+
 
+
jpegHeight - Variable in class org.libjpegturbo.turbojpeg.TJDecompressor
+
 
+
jpegSubsamp - Variable in class org.libjpegturbo.turbojpeg.TJDecompressor
+
 
+
jpegWidth - Variable in class org.libjpegturbo.turbojpeg.TJDecompressor
+
 
@@ -559,12 +582,12 @@
OPT_NOOUTPUT - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
-
This option will prevent TJTransformer.transform() from outputting a JPEG image for this +
This option will prevent TJTransformer.transform() from outputting a JPEG image for this particular transform.
OPT_PERFECT - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
-
This option will cause TJTransformer.transform() to throw an exception if the transform is not +
This option will cause TJTransformer.transform() to throw an exception if the transform is not perfect.
OPT_TRIM - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
@@ -632,6 +655,19 @@
XRGB pixel format.
+
planeHeight(int, int, int) - Static method in class org.libjpegturbo.turbojpeg.TJ
+
+
Returns the plane height of a YUV image plane with the given parameters.
+
+
planeSizeYUV(int, int, int, int, int) - Static method in class org.libjpegturbo.turbojpeg.TJ
+
+
Returns the size of the buffer (in bytes) required to hold a YUV image + plane with the given parameters.
+
+
planeWidth(int, int, int) - Static method in class org.libjpegturbo.turbojpeg.TJ
+
+
Returns the plane width of a YUV image plane with the given parameters.
+
@@ -662,34 +698,37 @@
Grayscale.
-
setBuf(byte[], int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.YUVImage
+
setBuf(byte[][], int[], int, int[], int, int) - Method in class org.libjpegturbo.turbojpeg.YUVImage
-
Assign an existing YUV planar image buffer to this YUVImage - instance.
+
Assign a set of image planes to this YUVImage instance.
-
setJPEGImage(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
setBuf(byte[], int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.YUVImage
+
+
Assign a unified image buffer to this YUVImage instance.
+
+
setJPEGImage(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
setJPEGQuality(int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
Set the JPEG image quality level for subsequent compress operations.
-
setSourceImage(byte[], int, int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
setSourceImage(byte[], int, int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
Associate an uncompressed RGB, grayscale, or CMYK source image with this compressor instance.
-
setSourceImage(byte[], int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
setSourceImage(byte[], int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
-
setSourceImage(BufferedImage, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
setSourceImage(BufferedImage, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
Associate an uncompressed RGB or grayscale source image with this compressor instance.
@@ -699,10 +738,10 @@
Associate an uncompressed YUV planar source image with this compressor instance.
-
setSourceImage(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
setSourceImage(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
Associate the JPEG image of length imageSize bytes stored in - srcImage with this decompressor instance.
+ jpegImage with this decompressor instance.
setSourceImage(YUVImage) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
@@ -714,14 +753,6 @@
Set the level of chrominance subsampling for subsequent compress/encode operations.
-
srcColorspace - Variable in class org.libjpegturbo.turbojpeg.TJDecompressor
-
 
-
srcHeight - Variable in class org.libjpegturbo.turbojpeg.TJDecompressor
-
 
-
srcSubsamp - Variable in class org.libjpegturbo.turbojpeg.TJDecompressor
-
 
-
srcWidth - Variable in class org.libjpegturbo.turbojpeg.TJDecompressor
-
 
@@ -742,20 +773,20 @@
Create a TurboJPEG compressor instance.
-
TJCompressor(byte[], int, int, int, int, int, int) - Constructor for class org.libjpegturbo.turbojpeg.TJCompressor
+
TJCompressor(byte[], int, int, int, int, int, int) - Constructor for class org.libjpegturbo.turbojpeg.TJCompressor
Create a TurboJPEG compressor instance and associate the uncompressed source image stored in srcImage with the newly created instance.
-
TJCompressor(byte[], int, int, int, int) - Constructor for class org.libjpegturbo.turbojpeg.TJCompressor
+
TJCompressor(byte[], int, int, int, int) - Constructor for class org.libjpegturbo.turbojpeg.TJCompressor
-
TJCompressor(BufferedImage, int, int, int, int) - Constructor for class org.libjpegturbo.turbojpeg.TJCompressor
+
TJCompressor(BufferedImage, int, int, int, int) - Constructor for class org.libjpegturbo.turbojpeg.TJCompressor
Create a TurboJPEG compressor instance and associate the uncompressed source image stored in srcImage with the newly created @@ -778,7 +809,7 @@
Create a TurboJPEG decompressor instance and associate the JPEG source image stored in jpegImage with the newly created instance.
-
TJDecompressor(byte[], int) - Constructor for class org.libjpegturbo.turbojpeg.TJDecompressor
+
TJDecompressor(byte[], int) - Constructor for class org.libjpegturbo.turbojpeg.TJDecompressor
Create a TurboJPEG decompressor instance and associate the JPEG source image of length imageSize bytes stored in @@ -794,7 +825,7 @@
Fractional scaling factor
-
TJScalingFactor(int, int) - Constructor for class org.libjpegturbo.turbojpeg.TJScalingFactor
+
TJScalingFactor(int, int) - Constructor for class org.libjpegturbo.turbojpeg.TJScalingFactor
 
TJTransform - Class in org.libjpegturbo.turbojpeg
@@ -804,11 +835,11 @@
Create a new lossless transform instance.
-
TJTransform(int, int, int, int, int, int, TJCustomFilter) - Constructor for class org.libjpegturbo.turbojpeg.TJTransform
+
TJTransform(int, int, int, int, int, int, TJCustomFilter) - Constructor for class org.libjpegturbo.turbojpeg.TJTransform
Create a new lossless transform instance with the given parameters.
-
TJTransform(Rectangle, int, int, TJCustomFilter) - Constructor for class org.libjpegturbo.turbojpeg.TJTransform
+
TJTransform(Rectangle, int, int, TJCustomFilter) - Constructor for class org.libjpegturbo.turbojpeg.TJTransform
Create a new lossless transform instance with the given parameters.
@@ -825,19 +856,19 @@
Create a TurboJPEG lossless transformer instance and associate the JPEG image stored in jpegImage with the newly created instance.
-
TJTransformer(byte[], int) - Constructor for class org.libjpegturbo.turbojpeg.TJTransformer
+
TJTransformer(byte[], int) - Constructor for class org.libjpegturbo.turbojpeg.TJTransformer
Create a TurboJPEG lossless transformer instance and associate the JPEG image of length imageSize bytes stored in jpegImage with the newly created instance.
-
transform(byte[][], TJTransform[], int) - Method in class org.libjpegturbo.turbojpeg.TJTransformer
+
transform(byte[][], TJTransform[], int) - Method in class org.libjpegturbo.turbojpeg.TJTransformer
Losslessly transform the JPEG image associated with this transformer instance into one or more JPEG images stored in the given destination buffers.
-
transform(TJTransform[], int) - Method in class org.libjpegturbo.turbojpeg.TJTransformer
+
transform(TJTransform[], int) - Method in class org.libjpegturbo.turbojpeg.TJTransformer
Losslessly transform the JPEG image associated with this transformer instance and return an array of TJDecompressor instances, each of @@ -849,8 +880,6 @@

Y

-
yuvBuf - Variable in class org.libjpegturbo.turbojpeg.YUVImage
-
 
yuvHeight - Variable in class org.libjpegturbo.turbojpeg.YUVImage
 
yuvImage - Variable in class org.libjpegturbo.turbojpeg.TJDecompressor
@@ -860,17 +889,34 @@
This class encapsulates a YUV planar image and the metadata associated with it.
-
YUVImage(int, int, int, int) - Constructor for class org.libjpegturbo.turbojpeg.YUVImage
+
YUVImage(int, int[], int, int) - Constructor for class org.libjpegturbo.turbojpeg.YUVImage
+
+
Create a new YUVImage instance backed by separate image + planes, and allocate memory for the image planes.
+
+
YUVImage(int, int, int, int) - Constructor for class org.libjpegturbo.turbojpeg.YUVImage
-
Create a YUVImage instance with a new image buffer.
+
Create a new YUVImage instance backed by a unified image + buffer, and allocate memory for the image buffer.
-
YUVImage(byte[], int, int, int, int) - Constructor for class org.libjpegturbo.turbojpeg.YUVImage
+
YUVImage(byte[][], int[], int, int[], int, int) - Constructor for class org.libjpegturbo.turbojpeg.YUVImage
-
Create a YUVImage instance from an existing YUV planar image +
Create a new YUVImage instance from a set of existing image + planes.
+
+
YUVImage(byte[], int, int, int, int) - Constructor for class org.libjpegturbo.turbojpeg.YUVImage
+
+
Create a new YUVImage instance from an existing unified image buffer.
+
yuvOffsets - Variable in class org.libjpegturbo.turbojpeg.YUVImage
+
 
yuvPad - Variable in class org.libjpegturbo.turbojpeg.YUVImage
 
+
yuvPlanes - Variable in class org.libjpegturbo.turbojpeg.YUVImage
+
 
+
yuvStrides - Variable in class org.libjpegturbo.turbojpeg.YUVImage
+
 
yuvSubsamp - Variable in class org.libjpegturbo.turbojpeg.YUVImage
 
yuvWidth - Variable in class org.libjpegturbo.turbojpeg.YUVImage
diff --git a/java/doc/index.html b/java/doc/index.html index 25a639d..b983957 100644 --- a/java/doc/index.html +++ b/java/doc/index.html @@ -10,6 +10,12 @@ if (targetPage.indexOf(":") != -1 || (targetPage != "" && !validURL(targetPage))) targetPage = "undefined"; function validURL(url) { + try { + url = decodeURIComponent(url); + } + catch (error) { + return false; + } var pos = url.indexOf(".html"); if (pos == -1 || pos != url.length - 5) return false; @@ -21,7 +27,8 @@ if ('a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '$' || - ch == '_') { + ch == '_' || + ch.charCodeAt(0) > 127) { allowNumber = true; allowSep = true; } else if ('0' <= ch && ch <= '9' diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJ.html b/java/doc/org/libjpegturbo/turbojpeg/TJ.html index ee22e76..f8342f2 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJ.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJ.html @@ -355,7 +355,7 @@ extends java.lang.Object static int -bufSize(int width, +bufSize(int width, int height, int jpegSubsamp)
Returns the maximum size of the buffer (in bytes) required to hold a JPEG @@ -364,17 +364,17 @@ extends java.lang.Object static int -bufSizeYUV(int width, +bufSizeYUV(int width, int height, int subsamp)
Deprecated.  - +
static int -bufSizeYUV(int width, +bufSizeYUV(int width, int pad, int height, int subsamp) @@ -430,6 +430,33 @@ extends java.lang.Object this implementation of TurboJPEG supports.
+ +static int +planeHeight(int componentID, + int height, + int subsamp) +
Returns the plane height of a YUV image plane with the given parameters.
+ + + +static int +planeSizeYUV(int componentID, + int width, + int stride, + int height, + int subsamp) +
Returns the size of the buffer (in bytes) required to hold a YUV image + plane with the given parameters.
+ + + +static int +planeWidth(int componentID, + int width, + int subsamp) +
Returns the plane width of a YUV image plane with the given parameters.
+ + + + + +
    +
  • +

    planeSizeYUV

    +
    public static int planeSizeYUV(int componentID,
    +               int width,
    +               int stride,
    +               int height,
    +               int subsamp)
    +                        throws java.lang.Exception
    +
    Returns the size of the buffer (in bytes) required to hold a YUV image + plane with the given parameters.
    +
    Parameters:
    componentID - ID number of the image plane (0 = Y, 1 = U/Cb, + 2 = V/Cr)
    width - width (in pixels) of the YUV image. NOTE: this is the width + of the whole image, not the plane width.
    stride - bytes per line in the image plane.
    height - height (in pixels) of the YUV image. NOTE: this is the + height of the whole image, not the plane height.
    subsamp - the level of chrominance subsampling used in the YUV + image (one of TJ.SAMP_*)
    +
    Returns:
    the size of the buffer (in bytes) required to hold a YUV planar + image with the given parameters.
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + +
    +
  • +

    planeWidth

    +
    public static int planeWidth(int componentID,
    +             int width,
    +             int subsamp)
    +                      throws java.lang.Exception
    +
    Returns the plane width of a YUV image plane with the given parameters. + Refer to YUVImage for a description of plane width.
    +
    Parameters:
    componentID - ID number of the image plane (0 = Y, 1 = U/Cb, + 2 = V/Cr)
    width - width (in pixels) of the YUV image
    subsamp - the level of chrominance subsampling used in the YUV image + (one of TJ.SAMP_*)
    +
    Returns:
    the plane width of a YUV image plane with the given parameters.
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + +
    +
  • +

    planeHeight

    +
    public static int planeHeight(int componentID,
    +              int height,
    +              int subsamp)
    +                       throws java.lang.Exception
    +
    Returns the plane height of a YUV image plane with the given parameters. + Refer to YUVImage for a description of plane height.
    +
    Parameters:
    componentID - ID number of the image plane (0 = Y, 1 = U/Cb, + 2 = V/Cr)
    height - height (in pixels) of the YUV image
    subsamp - the level of chrominance subsampling used in the YUV image + (one of TJ.SAMP_*)
    +
    Returns:
    the plane height of a YUV image plane with the given parameters.
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
@@ -1127,7 +1219,7 @@ public static int bufSizeYUV(int width,
Returns a list of fractional scaling factors that the JPEG decompressor in this implementation of TurboJPEG supports.
Returns:
a list of fractional scaling factors that the JPEG decompressor in - this implementation of TurboJPEG supports
+ this implementation of TurboJPEG supports.
Throws:
java.lang.Exception
diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html b/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html index 6c367a7..9387253 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html @@ -118,7 +118,7 @@ extends java.lang.Object -TJCompressor(java.awt.image.BufferedImage srcImage, +TJCompressor(java.awt.image.BufferedImage srcImage, int x, int y, int width, @@ -129,19 +129,19 @@ extends java.lang.Object -TJCompressor(byte[] srcImage, +TJCompressor(byte[] srcImage, int width, int pitch, int height, int pixelFormat) -TJCompressor(byte[] srcImage, +TJCompressor(byte[] srcImage, int x, int y, int width, @@ -176,30 +176,30 @@ extends java.lang.Object void -compress(java.awt.image.BufferedImage srcImage, +compress(java.awt.image.BufferedImage srcImage, byte[] dstBuf, int flags) byte[] -compress(java.awt.image.BufferedImage srcImage, +compress(java.awt.image.BufferedImage srcImage, int flags) void -compress(byte[] dstBuf, +compress(byte[] dstBuf, int flags)
Compress the uncompressed source image associated with this compressor instance and output a JPEG image to the given destination buffer.
@@ -214,33 +214,33 @@ extends java.lang.Object void -encodeYUV(java.awt.image.BufferedImage srcImage, +encodeYUV(java.awt.image.BufferedImage srcImage, byte[] dstBuf, int flags) byte[] -encodeYUV(java.awt.image.BufferedImage srcImage, +encodeYUV(java.awt.image.BufferedImage srcImage, int flags) void -encodeYUV(byte[] dstBuf, +encodeYUV(byte[] dstBuf, int flags)
Deprecated.  - +
@@ -248,48 +248,57 @@ extends java.lang.Object byte[] encodeYUV(int flags)
Deprecated.  -
Use encodeYUV(int, int) instead.
+
Use encodeYUV(int, int) instead.
YUVImage -encodeYUV(int pad, +encodeYUV(int[] strides, int flags)
Encode the uncompressed source image associated with this compressor - instance into a YUV planar image and return a YUVImage - instance containing the encoded image.
+ instance into separate Y, U (Cb), and V (Cr) image planes and return a + YUVImage instance containing the encoded image planes. +YUVImage +encodeYUV(int pad, + int flags) +
Encode the uncompressed source image associated with this compressor + instance into a unified YUV planar image buffer and return a + YUVImage instance containing the encoded image.
+ + + void -encodeYUV(YUVImage dstImage, +encodeYUV(YUVImage dstImage, int flags)
Encode the uncompressed source image associated with this compressor instance into a YUV planar image and store it in the given YUVImage instance.
- + protected void finalize()  - + int getCompressedSize()
Returns the size of the image (in bytes) generated by the most recent - compress/encode operation.
+ compress operation. - + void setJPEGQuality(int quality)
Set the JPEG image quality level for subsequent compress operations.
- + void -setSourceImage(java.awt.image.BufferedImage srcImage, +setSourceImage(java.awt.image.BufferedImage srcImage, int x, int y, int width, @@ -298,22 +307,22 @@ extends java.lang.Object compressor instance. - + void -setSourceImage(byte[] srcImage, +setSourceImage(byte[] srcImage, int width, int pitch, int height, int pixelFormat) - + void -setSourceImage(byte[] srcImage, +setSourceImage(byte[] srcImage, int x, int y, int width, @@ -324,14 +333,14 @@ extends java.lang.Object compressor instance. - + void setSourceImage(YUVImage srcImage)
Associate an uncompressed YUV planar source image with this compressor instance.
- + void setSubsamp(int newSubsamp)
Set the level of chrominance subsampling for subsequent compress/encode @@ -390,7 +399,7 @@ extends java.lang.Object
Create a TurboJPEG compressor instance and associate the uncompressed source image stored in srcImage with the newly created instance.
-
Parameters:
srcImage - see setSourceImage(byte[], int, int, int, int, int, int) for description
x - see setSourceImage(byte[], int, int, int, int, int, int) for description
y - see setSourceImage(byte[], int, int, int, int, int, int) for description
width - see setSourceImage(byte[], int, int, int, int, int, int) for description
pitch - see setSourceImage(byte[], int, int, int, int, int, int) for description
height - see setSourceImage(byte[], int, int, int, int, int, int) for description
pixelFormat - pixel format of the source image (one of +
Parameters:
srcImage - see setSourceImage(byte[], int, int, int, int, int, int) for description
x - see setSourceImage(byte[], int, int, int, int, int, int) for description
y - see setSourceImage(byte[], int, int, int, int, int, int) for description
width - see setSourceImage(byte[], int, int, int, int, int, int) for description
pitch - see setSourceImage(byte[], int, int, int, int, int, int) for description
height - see setSourceImage(byte[], int, int, int, int, int, int) for description
pixelFormat - pixel format of the source image (one of TJ.PF_*)
Throws:
java.lang.Exception
@@ -410,7 +419,7 @@ public TJCompressor(byte[] srcImage, int pixelFormat) throws java.lang.Exception + TJCompressor(byte[], int, int, int, int, int, int) instead.
Throws:
java.lang.Exception
@@ -431,11 +440,11 @@ public TJCompressor(byte[] srcImage, source image stored in srcImage with the newly created instance.
Parameters:
srcImage - see - setSourceImage(BufferedImage, int, int, int, int) for description
x - see - setSourceImage(BufferedImage, int, int, int, int) for description
y - see - setSourceImage(BufferedImage, int, int, int, int) for description
width - see - setSourceImage(BufferedImage, int, int, int, int) for description
height - see - setSourceImage(BufferedImage, int, int, int, int) for description
+ setSourceImage(BufferedImage, int, int, int, int) for description
x - see + setSourceImage(BufferedImage, int, int, int, int) for description
y - see + setSourceImage(BufferedImage, int, int, int, int) for description
width - see + setSourceImage(BufferedImage, int, int, int, int) for description
height - see + setSourceImage(BufferedImage, int, int, int, int) for description
Throws:
java.lang.Exception
@@ -496,7 +505,7 @@ public void setSourceImage(byte[] srcImage, int pixelFormat) throws java.lang.Exception + setSourceImage(byte[], int, int, int, int, int, int) instead.
Throws:
java.lang.Exception
@@ -599,7 +608,7 @@ public void setSourceImage(byte[] srcImage,
Compress the uncompressed source image associated with this compressor instance and output a JPEG image to the given destination buffer.
Parameters:
dstBuf - buffer that will receive the JPEG image. Use - TJ.bufSize(int, int, int) to determine the maximum size for this buffer based on + TJ.bufSize(int, int, int) to determine the maximum size for this buffer based on the source image's width and height and the desired level of chrominance subsampling.
flags - the bitwise OR of one or more of TJ.FLAG_*
@@ -637,8 +646,8 @@ public void compress(java.awt.image.BufferedImage srcImage, int flags) throws java.lang.Exception + setSourceImage(BufferedImage, int, int, int, int) and + compress(byte[], int) instead.
Throws:
java.lang.Exception
@@ -654,7 +663,7 @@ public byte[] compress(java.awt.image.BufferedImage srcImage, int flags) throws java.lang.Exception
Throws:
java.lang.Exception
@@ -692,7 +701,7 @@ public byte[] compress(java.awt.image.BufferedImage srcImage, public void encodeYUV(byte[] dstBuf, int flags) throws java.lang.Exception -
Deprecated. Use encodeYUV(YUVImage, int) instead.
+
Deprecated. Use encodeYUV(YUVImage, int) instead.
Throws:
java.lang.Exception
@@ -707,16 +716,44 @@ public void encodeYUV(byte[] dstBuf, int flags) throws java.lang.Exception
Encode the uncompressed source image associated with this compressor - instance into a YUV planar image and return a YUVImage - instance containing the encoded image. This method uses the accelerated - color conversion routines in TurboJPEG's underlying codec but does not - execute any of the other steps in the JPEG compression process. Encoding - CMYK source images to YUV is not supported.
+ instance into a unified YUV planar image buffer and return a + YUVImage instance containing the encoded image. This method + uses the accelerated color conversion routines in TurboJPEG's underlying + codec but does not execute any of the other steps in the JPEG compression + process. Encoding CMYK source images to YUV is not supported.
Parameters:
pad - the width of each line in each plane of the YUV image will be padded to the nearest multiple of this number of bytes (must be a power of 2.)
flags - the bitwise OR of one or more of TJ.FLAG_*
-
Returns:
a YUV planar image
+
Returns:
a YUV planar image.
+
Throws:
+
java.lang.Exception
+ + + + + +
    +
  • +

    encodeYUV

    +
    public YUVImage encodeYUV(int[] strides,
    +                 int flags)
    +                   throws java.lang.Exception
    +
    Encode the uncompressed source image associated with this compressor + instance into separate Y, U (Cb), and V (Cr) image planes and return a + YUVImage instance containing the encoded image planes. This + method uses the accelerated color conversion routines in TurboJPEG's + underlying codec but does not execute any of the other steps in the JPEG + compression process. Encoding CMYK source images to YUV is not supported.
    +
    Parameters:
    strides - an array of integers, each specifying the number of bytes + per line in the corresponding plane of the output image. Setting the + stride for any plane to 0 is the same as setting it to the component width + of the plane. If strides is null, then the strides for all + planes will be set to their respective component widths. You can adjust + the strides in order to add an arbitrary amount of line padding to each + plane.
    flags - the bitwise OR of one or more of + TJ.FLAG_*
    +
    Returns:
    a YUV planar image.
    Throws:
    java.lang.Exception
  • @@ -730,7 +767,7 @@ public void encodeYUV(byte[] dstBuf,
    @Deprecated
     public byte[] encodeYUV(int flags)
                      throws java.lang.Exception
    -
    Deprecated. Use encodeYUV(int, int) instead.
    +
    Deprecated. Use encodeYUV(int, int) instead.
    Throws:
    java.lang.Exception
    @@ -747,8 +784,8 @@ public void encodeYUV(java.awt.image.BufferedImage srcImage, int flags) throws java.lang.Exception + setSourceImage(BufferedImage, int, int, int, int) and + encodeYUV(byte[], int) instead.
    Throws:
    java.lang.Exception
    @@ -764,8 +801,8 @@ public byte[] encodeYUV(java.awt.image.BufferedImage srcImage, int flags) throws java.lang.Exception + setSourceImage(BufferedImage, int, int, int, int) and + encodeYUV(int, int) instead.
    Throws:
    java.lang.Exception
    @@ -778,9 +815,9 @@ public byte[] encodeYUV(java.awt.image.BufferedImage srcImage,

    getCompressedSize

    public int getCompressedSize()
    Returns the size of the image (in bytes) generated by the most recent - compress/encode operation.
    + compress operation.
    Returns:
    the size of the image (in bytes) generated by the most recent - compress/encode operation
    + compress operation.
diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJCustomFilter.html b/java/doc/org/libjpegturbo/turbojpeg/TJCustomFilter.html index bac519b..c2b6e61 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJCustomFilter.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJCustomFilter.html @@ -106,7 +106,7 @@ void -customFilter(java.nio.ShortBuffer coeffBuffer, +customFilter(java.nio.ShortBuffer coeffBuffer, java.awt.Rectangle bufferRegion, java.awt.Rectangle planeRegion, int componentID, @@ -162,7 +162,7 @@ coeffBuffer belongs (Y, Cb, and Cr have, respectively, ID's of 0, 1, and 2 in typical JPEG images.)
transformID - ID number of the transformed image to which coeffBuffer belongs. This is the same as the index of the - transform in the transforms array that was passed to TJTransformer.transform().
transform - a TJTransform instance that specifies the + transform in the transforms array that was passed to TJTransformer.transform().
transform - a TJTransform instance that specifies the parameters and/or cropping region for this transform
Throws:
java.lang.Exception
diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html b/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html index af6a902..faf9b6e 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html @@ -131,19 +131,19 @@ extends java.lang.Object protected int -srcColorspace  +jpegColorspace  protected int -srcHeight  +jpegHeight  protected int -srcSubsamp  +jpegSubsamp  protected int -srcWidth  +jpegWidth  protected YUVImage @@ -175,7 +175,7 @@ extends java.lang.Object -TJDecompressor(byte[] jpegImage, +TJDecompressor(byte[] jpegImage, int imageSize)
Create a TurboJPEG decompressor instance and associate the JPEG source image of length imageSize bytes stored in @@ -212,7 +212,7 @@ extends java.lang.Object void -decompress(java.awt.image.BufferedImage dstImage, +decompress(java.awt.image.BufferedImage dstImage, int flags)
Decompress the JPEG source image or decode the YUV source image associated with this decompressor instance and output a decompressed/decoded image to @@ -221,7 +221,7 @@ extends java.lang.Object void -decompress(byte[] dstBuf, +decompress(byte[] dstBuf, int desiredWidth, int pitch, int desiredHeight, @@ -229,13 +229,13 @@ extends java.lang.Object int flags)
void -decompress(byte[] dstBuf, +decompress(byte[] dstBuf, int x, int y, int desiredWidth, @@ -250,7 +250,7 @@ extends java.lang.Object void -decompress(int[] dstBuf, +decompress(int[] dstBuf, int x, int y, int desiredWidth, @@ -265,7 +265,7 @@ extends java.lang.Object java.awt.image.BufferedImage -decompress(int desiredWidth, +decompress(int desiredWidth, int desiredHeight, int bufferedImageType, int flags) @@ -276,7 +276,7 @@ extends java.lang.Object byte[] -decompress(int desiredWidth, +decompress(int desiredWidth, int pitch, int desiredHeight, int pixelFormat, @@ -287,10 +287,10 @@ extends java.lang.Object void -decompressToYUV(byte[] dstBuf, +decompressToYUV(byte[] dstBuf, int flags)
Deprecated.  - +
@@ -298,128 +298,122 @@ extends java.lang.Object byte[] decompressToYUV(int flags) YUVImage -decompressToYUV(int desiredWidth, - int pad, +decompressToYUV(int desiredWidth, + int[] strides, int desiredHeight, int flags)
Decompress the JPEG source image associated with this decompressor - instance into a YUV planar image and return a YUVImage - instance containing the decompressed image.
+ instance into a set of Y, U (Cb), and V (Cr) image planes and return a + YUVImage instance containing the decompressed image planes.
+YUVImage +decompressToYUV(int desiredWidth, + int pad, + int desiredHeight, + int flags) +
Decompress the JPEG source image associated with this decompressor + instance into a unified YUV planar image buffer and return a + YUVImage instance containing the decompressed image.
+ + + void -decompressToYUV(YUVImage dstImage, +decompressToYUV(YUVImage dstImage, int flags)
Decompress the JPEG source image associated with this decompressor instance into a YUV planar image and store it in the given YUVImage instance.
- + protected void finalize()  - + int getColorspace()
Returns the colorspace used in the source image (JPEG or YUV) associated with this decompressor instance.
- + int getHeight()
Returns the height of the source image (JPEG or YUV) associated with this decompressor instance.
- + byte[] getJPEGBuf() -
Deprecated.  -
Use getSourceBuf() instead.
-
+
Returns the JPEG image buffer associated with this decompressor instance.
- + int getJPEGSize() -
Deprecated.  -
Use getSourceSize() instead.
-
+
Returns the size of the JPEG image (in bytes) associated with this + decompressor instance.
- + int -getScaledHeight(int desiredWidth, +getScaledHeight(int desiredWidth, int desiredHeight)
Returns the height of the largest scaled-down image that the TurboJPEG decompressor can generate without exceeding the desired image width and height.
- + int -getScaledWidth(int desiredWidth, +getScaledWidth(int desiredWidth, int desiredHeight)
Returns the width of the largest scaled-down image that the TurboJPEG decompressor can generate without exceeding the desired image width and height.
- -byte[] -getSourceBuf() -
Returns the source image buffer associated with this decompressor - instance.
- - int -getSourceSize() -
Returns the size of the source image (in bytes) associated with this - decompressor instance.
- - - -int getSubsamp()
Returns the level of chrominance subsampling used in the source image (JPEG or YUV) associated with this decompressor instance.
- + int getWidth()
Returns the width of the source image (JPEG or YUV) associated with this decompressor instance.
- + void -setJPEGImage(byte[] jpegImage, +setJPEGImage(byte[] jpegImage, int imageSize)
Deprecated.  - +
- + void -setSourceImage(byte[] srcImage, +setSourceImage(byte[] jpegImage, int imageSize)
Associate the JPEG image of length imageSize bytes stored in - srcImage with this decompressor instance.
+ jpegImage with this decompressor instance. - + void setSourceImage(YUVImage srcImage)
Associate the specified YUV planar source image with this decompressor @@ -484,40 +478,40 @@ extends java.lang.Object
protected YUVImage yuvImage
- +
  • -

    srcWidth

    -
    protected int srcWidth
    +

    jpegWidth

    +
    protected int jpegWidth
- +
  • -

    srcHeight

    -
    protected int srcHeight
    +

    jpegHeight

    +
    protected int jpegHeight
- +
  • -

    srcSubsamp

    -
    protected int srcSubsamp
    +

    jpegSubsamp

    +
    protected int jpegSubsamp
- +
  • -

    srcColorspace

    -
    protected int srcColorspace
    +

    jpegColorspace

    +
    protected int jpegColorspace
@@ -605,13 +599,13 @@ extends java.lang.Object
  • setSourceImage

    -
    public void setSourceImage(byte[] srcImage,
    +
    public void setSourceImage(byte[] jpegImage,
                       int imageSize)
                         throws java.lang.Exception
    Associate the JPEG image of length imageSize bytes stored in - srcImage with this decompressor instance. This image will + jpegImage with this decompressor instance. This image will be used as the source image for subsequent decompress operations.
    -
    Parameters:
    srcImage - JPEG image buffer
    imageSize - size of the JPEG image (in bytes)
    +
    Parameters:
    jpegImage - JPEG image buffer
    imageSize - size of the JPEG image (in bytes)
    Throws:
    java.lang.Exception
  • @@ -626,7 +620,7 @@ extends java.lang.Object public void setJPEGImage(byte[] jpegImage, int imageSize) throws java.lang.Exception -
    Deprecated. Use setSourceImage(byte[], int) instead.
    +
    Deprecated. Use setSourceImage(byte[], int) instead.
    Throws:
    java.lang.Exception
    @@ -659,7 +653,7 @@ public void setJPEGImage(byte[] jpegImage,
    Returns the width of the source image (JPEG or YUV) associated with this decompressor instance.
    Returns:
    the width of the source image (JPEG or YUV) associated with this - decompressor instance
    + decompressor instance.
    Throws:
    java.lang.Exception
    @@ -675,7 +669,7 @@ public void setJPEGImage(byte[] jpegImage,
    Returns the height of the source image (JPEG or YUV) associated with this decompressor instance.
    Returns:
    the height of the source image (JPEG or YUV) associated with this - decompressor instance
    + decompressor instance.
    Throws:
    java.lang.Exception
    @@ -692,7 +686,7 @@ public void setJPEGImage(byte[] jpegImage, (JPEG or YUV) associated with this decompressor instance. See TJ.SAMP_*.
Returns:
the level of chrominance subsampling used in the source image - (JPEG or YUV) associated with this decompressor instance
+ (JPEG or YUV) associated with this decompressor instance.
Throws:
java.lang.Exception
@@ -709,22 +703,7 @@ public void setJPEGImage(byte[] jpegImage, with this decompressor instance. See TJ.CS_*. If the source image is YUV, then this always returns TJ.CS_YCbCr.
Returns:
the colorspace used in the source image (JPEG or YUV) associated - with this decompressor instance
-
Throws:
-
java.lang.Exception
- - - - - -
    -
  • -

    getSourceBuf

    -
    public byte[] getSourceBuf()
    -                    throws java.lang.Exception
    -
    Returns the source image buffer associated with this decompressor - instance.
    -
    Returns:
    the source image buffer associated with this decompressor instance
    + with this decompressor instance.
    Throws:
    java.lang.Exception
  • @@ -735,26 +714,10 @@ public void setJPEGImage(byte[] jpegImage,
    • getJPEGBuf

      -
      @Deprecated
      -public byte[] getJPEGBuf()
      +
      public byte[] getJPEGBuf()
                         throws java.lang.Exception
      -
      Deprecated. Use getSourceBuf() instead.
      -
      Throws:
      -
      java.lang.Exception
      -
    • -
    - - - -
      -
    • -

      getSourceSize

      -
      public int getSourceSize()
      -                  throws java.lang.Exception
      -
      Returns the size of the source image (in bytes) associated with this - decompressor instance.
      -
      Returns:
      the size of the source image (in bytes) associated with this - decompressor instance
      +
      Returns the JPEG image buffer associated with this decompressor instance.
      +
      Returns:
      the JPEG image buffer associated with this decompressor instance.
      Throws:
      java.lang.Exception
    • @@ -765,11 +728,13 @@ public byte[] getJPEGBuf()
      • getJPEGSize

        -
        @Deprecated
        -public int getJPEGSize()
        +
        public int getJPEGSize()
                         throws java.lang.Exception
        -
        Deprecated. Use getSourceSize() instead.
        -
        Throws:
        +
        Returns the size of the JPEG image (in bytes) associated with this + decompressor instance.
        +
        Returns:
        the size of the JPEG image (in bytes) associated with this + decompressor instance.
        +
        Throws:
        java.lang.Exception
      @@ -794,7 +759,7 @@ public int getJPEGSize() the scaled image size.)
      Returns:
      the width of the largest scaled-down image that the TurboJPEG decompressor can generate without exceeding the desired image width and - height
      + height.
      Throws:
      java.lang.Exception
      @@ -820,7 +785,7 @@ public int getJPEGSize() the scaled image size.)
      Returns:
      the height of the largest scaled-down image that the TurboJPEG decompressor can generate without exceeding the desired image width and - height
      + height.
      Throws:
      java.lang.Exception
      @@ -848,7 +813,7 @@ public int getJPEGSize() pitch * scaledHeight bytes in size, where scaledHeight can be determined by calling scalingFactor.getScaled(jpegHeight) - with one of the scaling factors returned from TJ.getScalingFactors() or by calling getScaledHeight(int, int). If the +
      with one of the scaling factors returned from TJ.getScalingFactors() or by calling getScaledHeight(int, int). If the source image is a YUV image, then this buffer should normally be pitch * height bytes in size, where height is the height of the YUV image. However, the buffer may also be larger than @@ -872,7 +837,7 @@ public int getJPEGSize() if the source image is a JPEG image, then scaledWidth can be determined by calling scalingFactor.getScaled(jpegWidth) - or by calling getScaledWidth(int, int). If the source image is a + or by calling getScaledWidth(int, int). If the source image is a YUV image, then scaledWidth is the width of the YUV image. Setting this parameter to 0 is the equivalent of setting it to scaledWidth * TJ.pixelSize(pixelFormat).
      desiredHeight - If the source image is a JPEG image, then this @@ -905,7 +870,7 @@ public void decompress(byte[] dstBuf, int flags) throws java.lang.Exception + decompress(byte[], int, int, int, int, int, int, int) instead.
      Throws:
      java.lang.Exception
      @@ -925,15 +890,15 @@ public void decompress(byte[] dstBuf,
      Decompress the JPEG source image associated with this decompressor instance and return a buffer containing the decompressed image.
      Parameters:
      desiredWidth - see - decompress(byte[], int, int, int, int, int, int, int) + decompress(byte[], int, int, int, int, int, int, int) for description
      pitch - see - decompress(byte[], int, int, int, int, int, int, int) + decompress(byte[], int, int, int, int, int, int, int) for description
      desiredHeight - see - decompress(byte[], int, int, int, int, int, int, int) + decompress(byte[], int, int, int, int, int, int, int) for description
      pixelFormat - pixel format of the decompressed image (one of TJ.PF_*)
      flags - the bitwise OR of one or more of TJ.FLAG_*
      -
      Returns:
      a buffer containing the decompressed image
      +
      Returns:
      a buffer containing the decompressed image.
      Throws:
      java.lang.Exception
      @@ -974,11 +939,54 @@ public void decompress(byte[] dstBuf, public void decompressToYUV(byte[] dstBuf, int flags) throws java.lang.Exception -
      Deprecated. Use decompressToYUV(YUVImage, int) instead.
      +
      Deprecated. Use decompressToYUV(YUVImage, int) instead.
      Throws:
      java.lang.Exception
    + + + +
      +
    • +

      decompressToYUV

      +
      public YUVImage decompressToYUV(int desiredWidth,
      +                       int[] strides,
      +                       int desiredHeight,
      +                       int flags)
      +                         throws java.lang.Exception
      +
      Decompress the JPEG source image associated with this decompressor + instance into a set of Y, U (Cb), and V (Cr) image planes and return a + YUVImage instance containing the decompressed image planes. + This method performs JPEG decompression but leaves out the color + conversion step, so a planar YUV image is generated instead of an RGB or + grayscale image. This method cannot be used to decompress JPEG source + images with the CMYK or YCCK colorspace.
      +
      Parameters:
      desiredWidth - desired width (in pixels) of the YUV image. If the + desired image dimensions are different than the dimensions 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 dimensions. Setting this to 0 is the same as setting it to + the width of the JPEG image (in other words, the width will not be + considered when determining the scaled image size.)
      strides - an array of integers, each specifying the number of bytes + per line in the corresponding plane of the output image. Setting the + stride for any plane to 0 is the same as setting it to the scaled + component width of the plane. If strides is NULL, then the + strides for all planes will be set to their respective scaled component + widths. You can adjust the strides in order to add an arbitrary amount of + line padding to each plane.
      desiredHeight - desired height (in pixels) of the YUV image. If the + desired image dimensions are different than the dimensions 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 dimensions. Setting this to 0 is the same as setting it to + the height of the JPEG image (in other words, the height will not be + considered when determining the scaled image size.)
      flags - the bitwise OR of one or more of + TJ.FLAG_*
      +
      Returns:
      a YUV planar image.
      +
      Throws:
      +
      java.lang.Exception
      +
    • +
    @@ -991,12 +999,12 @@ public void decompressToYUV(byte[] dstBuf, int flags) throws java.lang.Exception
    Decompress the JPEG source image associated with this decompressor - instance into a YUV planar image and return a YUVImage - instance containing the decompressed image. This method performs JPEG - decompression but leaves out the color conversion step, so a planar YUV - image is generated instead of an RGB or grayscale image. This method - cannot be used to decompress JPEG source images with the CMYK or YCCK - colorspace.
    + instance into a unified YUV planar image buffer and return a + YUVImage instance containing the decompressed image. This + method performs JPEG decompression but leaves out the color conversion + step, so a planar YUV image is generated instead of an RGB or grayscale + image. This method cannot be used to decompress JPEG source images with + the CMYK or YCCK colorspace.
    Parameters:
    desiredWidth - desired width (in pixels) of the YUV image. If the desired image dimensions are different than the dimensions of the JPEG image being decompressed, then TurboJPEG will use scaling in the JPEG @@ -1013,7 +1021,7 @@ public void decompressToYUV(byte[] dstBuf, the height of the JPEG image (in other words, the height will not be considered when determining the scaled image size.)
    flags - the bitwise OR of one or more of TJ.FLAG_*
    -
    Returns:
    a YUV planar image
    +
    Returns:
    a YUV planar image.
    Throws:
    java.lang.Exception
    @@ -1027,7 +1035,7 @@ public void decompressToYUV(byte[] dstBuf,
    @Deprecated
     public byte[] decompressToYUV(int flags)
                            throws java.lang.Exception
    -
    Deprecated. Use decompressToYUV(int, int, int, int) instead.
    +
    Deprecated. Use decompressToYUV(int, int, int, int) instead.
    Throws:
    java.lang.Exception
    @@ -1055,7 +1063,7 @@ public byte[] decompressToYUV(int flags) stride * scaledHeight pixels in size, where scaledHeight can be determined by calling scalingFactor.getScaled(jpegHeight) - with one of the scaling factors returned from TJ.getScalingFactors() or by calling getScaledHeight(int, int). If the + with one of the scaling factors returned from TJ.getScalingFactors() or by calling getScaledHeight(int, int). If the source image is a YUV image, then this buffer should normally be stride * height pixels in size, where height is the height of the YUV image. However, the buffer may also be larger than @@ -1077,7 +1085,7 @@ public byte[] decompressToYUV(int flags) NOTE: if the source image is a JPEG image, then scaledWidth can be determined by calling scalingFactor.getScaled(jpegWidth) - or by calling getScaledWidth(int, int). If the source image is a + or by calling getScaledWidth(int, int). If the source image is a YUV image, then scaledWidth is the width of the YUV image. Setting this parameter to 0 is the equivalent of setting it to scaledWidth.
    desiredHeight - If the source image is a JPEG image, then this @@ -1134,15 +1142,15 @@ public byte[] decompressToYUV(int flags) with this decompressor instance and return a BufferedImage instance containing the decompressed/decoded image.
    Parameters:
    desiredWidth - see - decompress(byte[], int, int, int, int, int, int, int) for + decompress(byte[], int, int, int, int, int, int, int) for description
    desiredHeight - see - decompress(byte[], int, int, int, int, int, int, int) for + decompress(byte[], int, int, int, int, int, int, int) for description
    bufferedImageType - the image type of the BufferedImage instance that will be created (for instance, BufferedImage.TYPE_INT_RGB)
    flags - the bitwise OR of one or more of TJ.FLAG_*
    Returns:
    a BufferedImage instance containing the - decompressed/decoded image
    + decompressed/decoded image.
    Throws:
    java.lang.Exception
    diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJScalingFactor.html b/java/doc/org/libjpegturbo/turbojpeg/TJScalingFactor.html index 1b90147..c28c00c 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJScalingFactor.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJScalingFactor.html @@ -113,7 +113,7 @@ extends java.lang.Object Constructor and Description -TJScalingFactor(int num, +TJScalingFactor(int num, int denom)  @@ -238,7 +238,7 @@ extends java.lang.Object
    Returns the scaled value of dimension. This function performs the integer equivalent of ceil(dimension * scalingFactor).
    -
    Returns:
    the scaled value of dimension
    +
    Returns:
    the scaled value of dimension.
@@ -251,7 +251,7 @@ extends java.lang.Object
Returns true or false, depending on whether this instance and other have the same numerator and denominator.
Returns:
true or false, depending on whether this instance and - other have the same numerator and denominator
+ other have the same numerator and denominator.
@@ -264,7 +264,7 @@ extends java.lang.Object
Returns true or false, depending on whether this instance is equal to 1/1.
Returns:
true or false, depending on whether this instance is equal to - 1/1
+ 1/1. diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html b/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html index b4bd5cc..daabfb3 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html @@ -231,14 +231,14 @@ extends java.awt.Rectangle static int
OPT_NOOUTPUT -
This option will prevent TJTransformer.transform() from outputting a JPEG image for this +
This option will prevent TJTransformer.transform() from outputting a JPEG image for this particular transform.
static int OPT_PERFECT -
This option will cause TJTransformer.transform() to throw an exception if the transform is not +
This option will cause TJTransformer.transform() to throw an exception if the transform is not perfect.
@@ -289,7 +289,7 @@ extends java.awt.Rectangle -TJTransform(int x, +TJTransform(int x, int y, int w, int h, @@ -300,7 +300,7 @@ extends java.awt.Rectangle -TJTransform(java.awt.Rectangle r, +TJTransform(java.awt.Rectangle r, int op, int options, TJCustomFilter cf) @@ -486,7 +486,7 @@ extends java.awt.Rectangle
  • OPT_PERFECT

    public static final int OPT_PERFECT
    -
    This option will cause TJTransformer.transform() to throw an exception if the transform is not +
    This option will cause TJTransformer.transform() to throw an exception if the transform is not perfect. Lossless transforms operate on MCU blocks, whose size depends on the level of chrominance subsampling used. If the image's width or height is not evenly divisible by the MCU block size (see TJ.getMCUWidth(int) @@ -541,7 +541,7 @@ extends java.awt.Rectangle
  • OPT_NOOUTPUT

    public static final int OPT_NOOUTPUT
    -
    This option will prevent TJTransformer.transform() from outputting a JPEG image for this +
    This option will prevent TJTransformer.transform() 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.
    @@ -636,7 +636,7 @@ extends java.awt.Rectangle throws java.lang.Exception
    Create a new lossless transform instance with the given parameters.
    Parameters:
    r - a Rectangle instance that specifies the cropping - region. See TJTransform(int, int, int, int, int, int, TJCustomFilter) for more + region. See TJTransform(int, int, int, int, int, int, TJCustomFilter) for more detail.
    op - one of the transform operations (OP_*)
    options - the bitwise OR of one or more of the transform options (OPT_*)
    cf - an instance of an object that implements the TJCustomFilter interface, or null if no custom filter is needed
    Throws:
    diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html b/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html index 3be18ec..333f3eb 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html @@ -117,7 +117,7 @@ extends

    Fields inherited from class org.libjpegturbo.turbojpeg.TJDecompressor

    -handle, jpegBuf, jpegBufSize, srcColorspace, srcHeight, srcSubsamp, srcWidth, yuvImage
  • +handle, jpegBuf, jpegBufSize, jpegColorspace, jpegHeight, jpegSubsamp, jpegWidth, yuvImage @@ -144,7 +144,7 @@ extends -TJTransformer(byte[] jpegImage, +TJTransformer(byte[] jpegImage, int imageSize)
    Create a TurboJPEG lossless transformer instance and associate the JPEG image of length imageSize bytes stored in @@ -175,7 +175,7 @@ extends void -transform(byte[][] dstBufs, +transform(byte[][] dstBufs, TJTransform[] transforms, int flags)
    Losslessly transform the JPEG image associated with this transformer @@ -185,7 +185,7 @@ extends TJDecompressor[] -transform(TJTransform[] transforms, +transform(TJTransform[] transforms, int flags)
    Losslessly transform the JPEG image associated with this transformer instance and return an array of TJDecompressor instances, each of @@ -198,7 +198,7 @@ extends

    Methods inherited from class org.libjpegturbo.turbojpeg.TJDecompressor

    -close, decompress, decompress, decompress, decompress, decompress, decompress, decompressToYUV, decompressToYUV, decompressToYUV, decompressToYUV, finalize, getColorspace, getHeight, getJPEGBuf, getJPEGSize, getScaledHeight, getScaledWidth, getSourceBuf, getSourceSize, getSubsamp, getWidth, setJPEGImage, setSourceImage, setSourceImage +close, decompress, decompress, decompress, decompress, decompress, decompress, decompressToYUV, decompressToYUV, decompressToYUV, decompressToYUV, decompressToYUV, finalize, getColorspace, getHeight, getJPEGBuf, getJPEGSize, getScaledHeight, getScaledWidth, getSubsamp, getWidth, setJPEGImage, setSourceImage, setSourceImage
    Returns:
    an array containing the sizes of the transformed JPEG images - generated by the most recent transform operation
    + generated by the most recent transform operation.
    Throws:
    java.lang.Exception
    diff --git a/java/doc/org/libjpegturbo/turbojpeg/YUVImage.html b/java/doc/org/libjpegturbo/turbojpeg/YUVImage.html index 3e7a6e8..0a3e0a5 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/YUVImage.html +++ b/java/doc/org/libjpegturbo/turbojpeg/YUVImage.html @@ -108,20 +108,18 @@ extends java.lang.Object image format consisting of Y, Cb, and Cr image planes.

    Each plane is simply a 2D array of bytes, each byte representing the value - of one of the components at a particular location in the image. The - "component width" and "component height" of each plane are determined by the - image width, height, and level of chrominance subsampling. For the - luminance plane, the component width is the image width padded to the - nearest multiple of the horizontal subsampling factor (2 in the case of - 4:2:0 and 4:2:2, 4 in the case of 4:1:1, 1 in the case of 4:4:4 or - grayscale.) Similarly, the component height of the luminance plane is the - image height padded to the nearest multiple of the vertical subsampling - factor (2 in the case of 4:2:0 or 4:4:0, 1 in the case of 4:4:4 or - grayscale.) The component width of the chrominance planes is equal to the - component width of the luminance plane divided by the horizontal subsampling - factor, and the component height of the chrominance planes is equal to the - component height of the luminance plane divided by the vertical subsampling - factor. + of one of the components (Y, Cb, or Cr) at a particular location in the + image. The width and height of each plane are determined by the image + width, height, and level of chrominance subsampling. The luminance plane + width is the image width padded to the nearest multiple of the horizontal + subsampling factor (2 in the case of 4:2:0 and 4:2:2, 4 in the case of + 4:1:1, 1 in the case of 4:4:4 or grayscale.) Similarly, the luminance plane + height is the image height padded to the nearest multiple of the vertical + subsampling factor (2 in the case of 4:2:0 or 4:4:0, 1 in the case of 4:4:4 + or grayscale.) The chrominance plane width is equal to the luminance plane + width divided by the horizontal subsampling factor, and the chrominance + plane height is equal to the luminance plane height divided by the vertical + subsampling factor.

    For example, if the source image is 35 x 35 pixels and 4:2:2 subsampling is used, then the luminance plane would be 36 x 35 bytes, and each of the @@ -151,18 +149,26 @@ extends java.lang.Object handle  -protected byte[] -yuvBuf  - - protected int yuvHeight  + +protected int[] +yuvOffsets  + protected int yuvPad  +protected byte[][] +yuvPlanes  + + +protected int[] +yuvStrides  + + protected int yuvSubsamp  @@ -185,21 +191,42 @@ extends java.lang.Object Constructor and Description -YUVImage(byte[] yuvImage, +YUVImage(byte[][] planes, + int[] offsets, + int width, + int[] strides, + int height, + int subsamp) +

    Create a new YUVImage instance from a set of existing image + planes.
    + + + +YUVImage(byte[] yuvImage, int width, int pad, int height, int subsamp) -
    Create a YUVImage instance from an existing YUV planar image +
    Create a new YUVImage instance from an existing unified image buffer.
    + +YUVImage(int width, + int[] strides, + int height, + int subsamp) +
    Create a new YUVImage instance backed by separate image + planes, and allocate memory for the image planes.
    + + -YUVImage(int width, +YUVImage(int width, int pad, int height, int subsamp) -
    Create a YUVImage instance with a new image buffer.
    +
    Create a new YUVImage instance backed by a unified image + buffer, and allocate memory for the image buffer.
    @@ -220,48 +247,80 @@ extends java.lang.Object byte[] getBuf() -
    Returns the YUV image buffer
    +
    Returns the YUV image buffer (if this image is stored in a unified + buffer rather than separate image planes.)
    int getHeight() -
    Returns the height of the YUV image.
    +
    Returns the height of the YUV image (or subregion.)
    +int[] +getOffsets() +
    Returns the offsets (in bytes) of each plane within the planes of a larger + YUV image.
    + + + int getPad() -
    Returns the line padding used in the YUV image buffer.
    +
    Returns the line padding used in the YUV image buffer (if this image is + stored in a unified buffer rather than separate image planes.)
    + + + +byte[][] +getPlanes() +
    Returns the YUV image planes.
    int getSize() -
    Returns the size (in bytes) of the YUV image buffer
    +
    Returns the size (in bytes) of the YUV image buffer (if this image is + stored in a unified buffer rather than separate image planes.)
    +int[] +getStrides() +
    Returns the number of bytes per line of each plane in the YUV image.
    + + + int getSubsamp()
    Returns the level of chrominance subsampling used in the YUV image.
    - + int getWidth() -
    Returns the width of the YUV image.
    +
    Returns the width of the YUV image (or subregion.)
    + + + +void +setBuf(byte[][] planes, + int[] offsets, + int width, + int[] strides, + int height, + int subsamp) +
    Assign a set of image planes to this YUVImage instance.
    void -setBuf(byte[] yuvImage, +setBuf(byte[] yuvImage, int width, int pad, int height, int subsamp) -
    Assign an existing YUV planar image buffer to this YUVImage - instance.
    +
    Assign a unified image buffer to this YUVImage instance.
    @@ -295,13 +354,31 @@ extends java.lang.Object
    protected long handle
    - +
    • -

      yuvBuf

      -
      protected byte[] yuvBuf
      +

      yuvPlanes

      +
      protected byte[][] yuvPlanes
      +
    • +
    + + + +
      +
    • +

      yuvOffsets

      +
      protected int[] yuvOffsets
      +
    • +
    + + + +
      +
    • +

      yuvStrides

      +
      protected int[] yuvStrides
    @@ -348,6 +425,31 @@ extends java.lang.Object

    Constructor Detail

    + + + +
      +
    • +

      YUVImage

      +
      public YUVImage(int width,
      +        int[] strides,
      +        int height,
      +        int subsamp)
      +         throws java.lang.Exception
      +
      Create a new YUVImage instance backed by separate image + planes, and allocate memory for the image planes.
      +
      Parameters:
      width - width (in pixels) of the YUV image
      strides - an array of integers, each specifying the number of bytes + per line in the corresponding plane of the YUV image. Setting the stride + for any plane to 0 is the same as setting it to the plane width (see + above.) If strides is null, then the + strides for all planes will be set to their respective plane widths. When + using this constructor, the stride for each plane must be equal to or + greater than the plane width.
      height - height (in pixels) of the YUV image
      subsamp - the level of chrominance subsampling to be used in the YUV + image (one of TJ.SAMP_*)
      +
      Throws:
      +
      java.lang.Exception
      +
    • +
    @@ -359,7 +461,8 @@ extends java.lang.Object int height, int subsamp) throws java.lang.Exception -
    Create a YUVImage instance with a new image buffer.
    +
    Create a new YUVImage instance backed by a unified image + buffer, and allocate memory for the image buffer.
    Parameters:
    width - width (in pixels) of the YUV image
    pad - Each line of each plane in the YUV image buffer will be padded to this number of bytes (must be a power of 2.)
    height - height (in pixels) of the YUV image
    subsamp - the level of chrominance subsampling to be used in the YUV image (one of TJ.SAMP_*)
    @@ -367,6 +470,44 @@ extends java.lang.Object
    java.lang.Exception
    + + + +
      +
    • +

      YUVImage

      +
      public YUVImage(byte[][] planes,
      +        int[] offsets,
      +        int width,
      +        int[] strides,
      +        int height,
      +        int subsamp)
      +         throws java.lang.Exception
      +
      Create a new YUVImage instance from a set of existing image + planes.
      +
      Parameters:
      planes - an array of buffers representing the Y, U (Cb), and V (Cr) + image planes (or just the Y plane, if the image is grayscale.) These + planes can be contiguous or non-contiguous in memory. Plane + i should be at least offsets[i] + + TJ.planeSizeYUV(i, width, strides[i], height, subsamp) + bytes in size.
      offsets - If this YUVImage instance represents a + subregion of a larger image, then offsets[i] specifies the + offset (in bytes) of the subregion within plane i of the + larger image. Setting this to null is the same as setting the offsets for + all planes to 0.
      width - width (in pixels) of the new YUV image (or subregion)
      strides - an array of integers, each specifying the number of bytes + per line in the corresponding plane of the YUV image. Setting the stride + for any plane to 0 is the same as setting it to the plane width (see + above.) 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 add an arbitrary amount of line padding + to each plane or to specify that this YUVImage instance is a + subregion of a larger image (in which case, strides[i] should + be set to the plane width of plane i in the larger image.)
      height - height (in pixels) of the new YUV image (or subregion)
      subsamp - the level of chrominance subsampling used in the YUV + image (one of TJ.SAMP_*)
      +
      Throws:
      +
      java.lang.Exception
      +
    • +
    @@ -379,10 +520,10 @@ extends java.lang.Object int height, int subsamp) throws java.lang.Exception -
    Create a YUVImage instance from an existing YUV planar image +
    Create a new YUVImage instance from an existing unified image buffer.
    Parameters:
    yuvImage - image buffer that contains or will contain YUV planar - image data. Use TJ.bufSizeYUV(int, int, int, int) to determine the minimum size for + image data. Use TJ.bufSizeYUV(int, int, int, int) to determine the minimum size for this buffer. The Y, U (Cb), and V (Cr) image planes are stored sequentially in the buffer (see above for a description of the image format.)
    width - width (in pixels) of the YUV image
    pad - the line padding used in the YUV image buffer. For @@ -401,6 +542,43 @@ extends java.lang.Object

    Method Detail

    + + + +
      +
    • +

      setBuf

      +
      public void setBuf(byte[][] planes,
      +          int[] offsets,
      +          int width,
      +          int[] strides,
      +          int height,
      +          int subsamp)
      +            throws java.lang.Exception
      +
      Assign a set of image planes to this YUVImage instance.
      +
      Parameters:
      planes - an array of buffers representing the Y, U (Cb), and V (Cr) + image planes (or just the Y plane, if the image is grayscale.) These + planes can be contiguous or non-contiguous in memory. Plane + i should be at least offsets[i] + + TJ.planeSizeYUV(i, width, strides[i], height, subsamp) + bytes in size.
      offsets - If this YUVImage instance represents a + subregion of a larger image, then offsets[i] specifies the + offset (in bytes) of the subregion within plane i of the + larger image. Setting this to null is the same as setting the offsets for + all planes to 0.
      width - width (in pixels) of the YUV image (or subregion)
      strides - an array of integers, each specifying the number of bytes + per line in the corresponding plane of the YUV image. Setting the stride + for any plane to 0 is the same as setting it to the plane width (see + above.) 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 add an arbitrary amount of line padding + to each plane or to specify that this YUVImage image is a + subregion of a larger image (in which case, strides[i] should + be set to the plane width of plane i in the larger image.)
      height - height (in pixels) of the YUV image (or subregion)
      subsamp - the level of chrominance subsampling used in the YUV + image (one of TJ.SAMP_*)
      +
      Throws:
      +
      java.lang.Exception
      +
    • +
    @@ -413,10 +591,9 @@ extends java.lang.Object int height, int subsamp) throws java.lang.Exception -
    Assign an existing YUV planar image buffer to this YUVImage - instance.
    +
    Assign a unified image buffer to this YUVImage instance.
    Parameters:
    yuvImage - image buffer that contains or will contain YUV planar - image data. Use TJ.bufSizeYUV(int, int, int, int) to determine the minimum size for + image data. Use TJ.bufSizeYUV(int, int, int, int) to determine the minimum size for this buffer. The Y, U (Cb), and V (Cr) image planes are stored sequentially in the buffer (see above for a description of the image format.)
    width - width (in pixels) of the YUV image
    pad - the line padding used in the YUV image buffer. For @@ -435,8 +612,8 @@ extends java.lang.Object

    getWidth

    public int getWidth()
                  throws java.lang.Exception
    -
    Returns the width of the YUV image.
    -
    Returns:
    the width of the YUV image
    +
    Returns the width of the YUV image (or subregion.)
    +
    Returns:
    the width of the YUV image (or subregion)
    Throws:
    java.lang.Exception
    @@ -449,8 +626,8 @@ extends java.lang.Object

    getHeight

    public int getHeight()
                   throws java.lang.Exception
    -
    Returns the height of the YUV image.
    -
    Returns:
    the height of the YUV image
    +
    Returns the height of the YUV image (or subregion.)
    +
    Returns:
    the height of the YUV image (or subregion)
    Throws:
    java.lang.Exception
    @@ -463,12 +640,43 @@ extends java.lang.Object

    getPad

    public int getPad()
                throws java.lang.Exception
    -
    Returns the line padding used in the YUV image buffer.
    +
    Returns the line padding used in the YUV image buffer (if this image is + stored in a unified buffer rather than separate image planes.)
    Returns:
    the line padding used in the YUV image buffer
    Throws:
    java.lang.Exception
    + + + +
      +
    • +

      getStrides

      +
      public int[] getStrides()
      +                 throws java.lang.Exception
      +
      Returns the number of bytes per line of each plane in the YUV image.
      +
      Returns:
      the number of bytes per line of each plane in the YUV image
      +
      Throws:
      +
      java.lang.Exception
      +
    • +
    + + + +
      +
    • +

      getOffsets

      +
      public int[] getOffsets()
      +                 throws java.lang.Exception
      +
      Returns the offsets (in bytes) of each plane within the planes of a larger + YUV image.
      +
      Returns:
      the offsets (in bytes) of each plane within the planes of a larger + YUV image
      +
      Throws:
      +
      java.lang.Exception
      +
    • +
    @@ -484,6 +692,21 @@ extends java.lang.Object
    java.lang.Exception
    + + + +
      +
    • +

      getPlanes

      +
      public byte[][] getPlanes()
      +                   throws java.lang.Exception
      +
      Returns the YUV image planes. If the image is stored in a unified buffer, + then all image planes will point to that buffer.
      +
      Returns:
      the YUV image planes
      +
      Throws:
      +
      java.lang.Exception
      +
    • +
    @@ -492,7 +715,8 @@ extends java.lang.Object

    getBuf

    public byte[] getBuf()
                   throws java.lang.Exception
    -
    Returns the YUV image buffer
    +
    Returns the YUV image buffer (if this image is stored in a unified + buffer rather than separate image planes.)
    Returns:
    the YUV image buffer
    Throws:
    java.lang.Exception
    @@ -506,7 +730,8 @@ extends java.lang.Object

    getSize

    public int getSize()
                 throws java.lang.Exception
    -
    Returns the size (in bytes) of the YUV image buffer
    +
    Returns the size (in bytes) of the YUV image buffer (if this image is + stored in a unified buffer rather than separate image planes.)
    Returns:
    the size (in bytes) of the YUV image buffer
    Throws:
    java.lang.Exception
    diff --git a/java/org/libjpegturbo/turbojpeg/TJ.java b/java/org/libjpegturbo/turbojpeg/TJ.java index ac4a4dd..644a197 100644 --- a/java/org/libjpegturbo/turbojpeg/TJ.java +++ b/java/org/libjpegturbo/turbojpeg/TJ.java @@ -84,7 +84,8 @@ public final class TJ { * @param subsamp the level of chrominance subsampling (one of * SAMP_*) * - * @return the MCU block width for the given level of chrominance subsampling + * @return the MCU block width for the given level of chrominance + * subsampling. */ public static int getMCUWidth(int subsamp) throws Exception { if (subsamp < 0 || subsamp >= NUMSAMP) @@ -105,7 +106,7 @@ public final class TJ { * SAMP_*) * * @return the MCU block height for the given level of chrominance - * subsampling + * subsampling. */ public static int getMCUHeight(int subsamp) throws Exception { if (subsamp < 0 || subsamp >= NUMSAMP) @@ -214,7 +215,7 @@ public final class TJ { * * @param pixelFormat the pixel format (one of PF_*) * - * @return the pixel size (in bytes) for the given pixel format + * @return the pixel size (in bytes) for the given pixel format. */ public static int getPixelSize(int pixelFormat) throws Exception { if (pixelFormat < 0 || pixelFormat >= NUMPF) @@ -236,7 +237,7 @@ public final class TJ { * * @param pixelFormat the pixel format (one of PF_*) * - * @return the red offset for the given pixel format + * @return the red offset for the given pixel format. */ public static int getRedOffset(int pixelFormat) throws Exception { if (pixelFormat < 0 || pixelFormat >= NUMPF) @@ -258,7 +259,7 @@ public final class TJ { * * @param pixelFormat the pixel format (one of PF_*) * - * @return the green offset for the given pixel format + * @return the green offset for the given pixel format. */ public static int getGreenOffset(int pixelFormat) throws Exception { if (pixelFormat < 0 || pixelFormat >= NUMPF) @@ -280,7 +281,7 @@ public final class TJ { * * @param pixelFormat the pixel format (one of PF_*) * - * @return the blue offset for the given pixel format + * @return the blue offset for the given pixel format. */ public static int getBlueOffset(int pixelFormat) throws Exception { if (pixelFormat < 0 || pixelFormat >= NUMPF) @@ -404,7 +405,7 @@ public final class TJ { * generating the JPEG image (one of {@link TJ TJ.SAMP_*}) * * @return the maximum size of the buffer (in bytes) required to hold a JPEG - * image with the given width, height, and level of chrominance subsampling + * image with the given width, height, and level of chrominance subsampling. */ public static native int bufSize(int width, int height, int jpegSubsamp) throws Exception; @@ -416,8 +417,7 @@ public final class TJ { * @param width the width (in pixels) of the YUV image * * @param pad the width of each line in each plane of the image is padded to - * the nearest multiple of this number of bytes (must be a power of - * 2.) + * the nearest multiple of this number of bytes (must be a power of 2.) * * @param height the height (in pixels) of the YUV image * @@ -425,7 +425,7 @@ public final class TJ { * image (one of {@link TJ TJ.SAMP_*}) * * @return the size of the buffer (in bytes) required to hold a YUV planar - * image with the given width, height, and level of chrominance subsampling + * image with the given width, height, and level of chrominance subsampling. */ public static native int bufSizeYUV(int width, int pad, int height, int subsamp) @@ -438,12 +438,72 @@ public final class TJ { public static native int bufSizeYUV(int width, int height, int subsamp) throws Exception; + /** + * Returns the size of the buffer (in bytes) required to hold a YUV image + * plane with the given parameters. + * + * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, + * 2 = V/Cr) + * + * @param width width (in pixels) of the YUV image. NOTE: this is the width + * of the whole image, not the plane width. + * + * @param stride bytes per line in the image plane. + * + * @param height height (in pixels) of the YUV image. NOTE: this is the + * height of the whole image, not the plane height. + * + * @param subsamp the level of chrominance subsampling used in the YUV + * image (one of {@link TJ TJ.SAMP_*}) + * + * @return the size of the buffer (in bytes) required to hold a YUV planar + * image with the given parameters. + */ + public static native int planeSizeYUV(int componentID, int width, int stride, + int height, int subsamp) + throws Exception; + + /** + * Returns the plane width of a YUV image plane with the given parameters. + * Refer to {@link YUVImage YUVImage} for a description of plane width. + * + * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, + * 2 = V/Cr) + * + * @param width width (in pixels) of the YUV image + * + * @param subsamp the level of chrominance subsampling used in the YUV image + * (one of {@link TJ TJ.SAMP_*}) + * + * @return the plane width of a YUV image plane with the given parameters. + */ + public static native int planeWidth(int componentID, int width, int subsamp) + throws Exception; + + /** + * Returns the plane height of a YUV image plane with the given parameters. + * Refer to {@link YUVImage YUVImage} for a description of plane height. + * + * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, + * 2 = V/Cr) + * + * @param height height (in pixels) of the YUV image + * + * @param subsamp the level of chrominance subsampling used in the YUV image + * (one of {@link TJ TJ.SAMP_*}) + * + * @return the plane height of a YUV image plane with the given parameters. + */ + public static native int planeHeight(int componentID, int height, + int subsamp) + throws Exception; + /** * Returns a list of fractional scaling factors that the JPEG decompressor in * this implementation of TurboJPEG supports. * * @return a list of fractional scaling factors that the JPEG decompressor in - * this implementation of TurboJPEG supports + * this implementation of TurboJPEG supports. */ public static native TJScalingFactor[] getScalingFactors() throws Exception; diff --git a/java/org/libjpegturbo/turbojpeg/TJCompressor.java b/java/org/libjpegturbo/turbojpeg/TJCompressor.java index 0debf53..c4a8cc5 100644 --- a/java/org/libjpegturbo/turbojpeg/TJCompressor.java +++ b/java/org/libjpegturbo/turbojpeg/TJCompressor.java @@ -332,9 +332,10 @@ public class TJCompressor { throw new Exception("Subsampling level not set"); if (srcYUVImage != null) - compressedSize = compressFromYUV(srcYUVImage.getBuf(), + compressedSize = compressFromYUV(srcYUVImage.getPlanes(), + srcYUVImage.getOffsets(), srcYUVImage.getWidth(), - srcYUVImage.getPad(), + srcYUVImage.getStrides(), srcYUVImage.getHeight(), srcYUVImage.getSubsamp(), dstBuf, jpegQuality, flags); @@ -429,14 +430,14 @@ public class TJCompressor { if (srcBufInt != null) { encodeYUV(srcBufInt, srcX, srcY, srcWidth, srcStride, srcHeight, - srcPixelFormat, dstImage.getBuf(), dstImage.getPad(), - dstImage.getSubsamp(), flags); + srcPixelFormat, dstImage.getPlanes(), dstImage.getOffsets(), + dstImage.getStrides(), dstImage.getSubsamp(), flags); } else { encodeYUV(srcBuf, srcX, srcY, srcWidth, srcPitch, srcHeight, - srcPixelFormat, dstImage.getBuf(), dstImage.getPad(), - dstImage.getSubsamp(), flags); + srcPixelFormat, dstImage.getPlanes(), dstImage.getOffsets(), + dstImage.getStrides(), dstImage.getSubsamp(), flags); } - compressedSize = dstImage.getSize(); + compressedSize = 0; } /** @@ -456,11 +457,11 @@ public class TJCompressor { /** * Encode the uncompressed source image associated with this compressor - * instance into a YUV planar image and return a YUVImage - * instance containing the encoded image. This method uses the accelerated - * color conversion routines in TurboJPEG's underlying codec but does not - * execute any of the other steps in the JPEG compression process. Encoding - * CMYK source images to YUV is not supported. + * instance into a unified YUV planar image buffer and return a + * YUVImage instance containing the encoded image. This method + * uses the accelerated color conversion routines in TurboJPEG's underlying + * codec but does not execute any of the other steps in the JPEG compression + * process. Encoding CMYK source images to YUV is not supported. * * @param pad the width of each line in each plane of the YUV image will be * padded to the nearest multiple of this number of bytes (must be a power of @@ -469,7 +470,7 @@ public class TJCompressor { * @param flags the bitwise OR of one or more of * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} * - * @return a YUV planar image + * @return a YUV planar image. */ public YUVImage encodeYUV(int pad, int flags) throws Exception { if (srcWidth < 1 || srcHeight < 1) @@ -483,6 +484,37 @@ public class TJCompressor { return yuvImage; } + /** + * Encode the uncompressed source image associated with this compressor + * instance into separate Y, U (Cb), and V (Cr) image planes and return a + * YUVImage instance containing the encoded image planes. This + * method uses the accelerated color conversion routines in TurboJPEG's + * underlying codec but does not execute any of the other steps in the JPEG + * compression process. Encoding CMYK source images to YUV is not supported. + * + * @param strides an array of integers, each specifying the number of bytes + * per line in the corresponding plane of the output image. Setting the + * stride for any plane to 0 is the same as setting it to the component width + * of the plane. If strides is null, then the strides for all + * planes will be set to their respective component widths. You can adjust + * the strides in order to add an arbitrary amount of line padding to each + * plane. + * + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} + * + * @return a YUV planar image. + */ + public YUVImage encodeYUV(int[] strides, int flags) throws Exception { + if (srcWidth < 1 || srcHeight < 1) + throw new Exception(NO_ASSOC_ERROR); + if (subsamp < 0) + throw new Exception("Subsampling level not set"); + YUVImage yuvImage = new YUVImage(srcWidth, strides, srcHeight, subsamp); + encodeYUV(yuvImage, flags); + return yuvImage; + } + /** * @deprecated Use {@link #encodeYUV(int, int)} instead. */ @@ -512,7 +544,7 @@ public class TJCompressor { /** * @deprecated Use * {@link #setSourceImage(BufferedImage, int, int, int, int)} and - * {@link #encodeYUV(int)} instead. + * {@link #encodeYUV(int, int)} instead. */ @Deprecated public byte[] encodeYUV(BufferedImage srcImage, int flags) throws Exception { @@ -522,10 +554,10 @@ public class TJCompressor { /** * Returns the size of the image (in bytes) generated by the most recent - * compress/encode operation. + * compress operation. * * @return the size of the image (in bytes) generated by the most recent - * compress/encode operation + * compress operation. */ public int getCompressedSize() { return compressedSize; @@ -568,8 +600,9 @@ public class TJCompressor { int stride, int height, int pixelFormat, byte[] dstBuf, int jpegSubsamp, int jpegQual, int flags) throws Exception; - private native int compressFromYUV(byte[] srcBuf, int width, int pad, - int height, int subsamp, byte[] dstBuf, int jpegQual, int flags) + private native int compressFromYUV(byte[][] srcPlanes, int[] srcOffsets, + int width, int[] srcStrides, int height, int subsamp, byte[] dstBuf, + int jpegQual, int flags) throws Exception; private native void encodeYUV(byte[] srcBuf, int width, int pitch, @@ -577,16 +610,18 @@ public class TJCompressor { throws Exception; // deprecated private native void encodeYUV(byte[] srcBuf, int x, int y, int width, - int pitch, int height, int pixelFormat, byte[] dstBuf, int pad, - int subsamp, int flags) throws Exception; + int pitch, int height, int pixelFormat, byte[][] dstPlanes, + int[] dstOffsets, int[] dstStrides, int subsamp, int flags) + throws Exception; private native void encodeYUV(int[] srcBuf, int width, int stride, int height, int pixelFormat, byte[] dstBuf, int subsamp, int flags) throws Exception; // deprecated private native void encodeYUV(int[] srcBuf, int x, int y, int width, - int pitch, int height, int pixelFormat, byte[] dstBuf, int pad, - int subsamp, int flags) throws Exception; + int srcStride, int height, int pixelFormat, byte[][] dstPlanes, + int[] dstOffsets, int[] dstStrides, int subsamp, int flags) + throws Exception; static { TJLoader.load(); diff --git a/java/org/libjpegturbo/turbojpeg/TJDecompressor.java b/java/org/libjpegturbo/turbojpeg/TJDecompressor.java index c71ce77..1a2774c 100644 --- a/java/org/libjpegturbo/turbojpeg/TJDecompressor.java +++ b/java/org/libjpegturbo/turbojpeg/TJDecompressor.java @@ -87,18 +87,18 @@ public class TJDecompressor { /** * Associate the JPEG image of length imageSize bytes stored in - * srcImage with this decompressor instance. This image will + * jpegImage with this decompressor instance. This image will * be used as the source image for subsequent decompress operations. * - * @param srcImage JPEG image buffer + * @param jpegImage JPEG image buffer * * @param imageSize size of the JPEG image (in bytes) */ - public void setSourceImage(byte[] srcImage, int imageSize) + public void setSourceImage(byte[] jpegImage, int imageSize) throws Exception { - if (srcImage == null || imageSize < 1) + if (jpegImage == null || imageSize < 1) throw new Exception("Invalid argument in setSourceImage()"); - jpegBuf = srcImage; + jpegBuf = jpegImage; jpegBufSize = imageSize; decompressHeader(jpegBuf, jpegBufSize); yuvImage = null; @@ -134,7 +134,7 @@ public class TJDecompressor { * decompressor instance. * * @return the width of the source image (JPEG or YUV) associated with this - * decompressor instance + * decompressor instance. */ public int getWidth() throws Exception { if (yuvImage != null) @@ -149,7 +149,7 @@ public class TJDecompressor { * decompressor instance. * * @return the height of the source image (JPEG or YUV) associated with this - * decompressor instance + * decompressor instance. */ public int getHeight() throws Exception { if (yuvImage != null) @@ -165,7 +165,7 @@ public class TJDecompressor { * {@link TJ#SAMP_444 TJ.SAMP_*}. * * @return the level of chrominance subsampling used in the source image - * (JPEG or YUV) associated with this decompressor instance + * (JPEG or YUV) associated with this decompressor instance. */ public int getSubsamp() throws Exception { if (yuvImage != null) @@ -183,7 +183,7 @@ public class TJDecompressor { * source image is YUV, then this always returns {@link TJ#CS_YCbCr}. * * @return the colorspace used in the source image (JPEG or YUV) associated - * with this decompressor instance + * with this decompressor instance. */ public int getColorspace() throws Exception { if (yuvImage != null) @@ -196,23 +196,10 @@ public class TJDecompressor { } /** - * Returns the source image buffer associated with this decompressor - * instance. + * Returns the JPEG image buffer associated with this decompressor instance. * - * @return the source image buffer associated with this decompressor instance + * @return the JPEG image buffer associated with this decompressor instance. */ - public byte[] getSourceBuf() throws Exception { - if (yuvImage != null) - return yuvImage.getBuf(); - if (jpegBuf == null) - throw new Exception(NO_ASSOC_ERROR); - return jpegBuf; - } - - /** - * @deprecated Use {@link #getSourceBuf} instead. - */ - @Deprecated public byte[] getJPEGBuf() throws Exception { if (jpegBuf == null) throw new Exception(NO_ASSOC_ERROR); @@ -220,24 +207,12 @@ public class TJDecompressor { } /** - * Returns the size of the source image (in bytes) associated with this + * Returns the size of the JPEG image (in bytes) associated with this * decompressor instance. * - * @return the size of the source image (in bytes) associated with this - * decompressor instance - */ - public int getSourceSize() throws Exception { - if (yuvImage != null) - return yuvImage.getSize(); - if (jpegBufSize < 1) - throw new Exception(NO_ASSOC_ERROR); - return jpegBufSize; - } - - /** - * @deprecated Use {@link #getSourceSize} instead. + * @return the size of the JPEG image (in bytes) associated with this + * decompressor instance. */ - @Deprecated public int getJPEGSize() throws Exception { if (jpegBufSize < 1) throw new Exception(NO_ASSOC_ERROR); @@ -261,7 +236,7 @@ public class TJDecompressor { * * @return the width of the largest scaled-down image that the TurboJPEG * decompressor can generate without exceeding the desired image width and - * height + * height. */ public int getScaledWidth(int desiredWidth, int desiredHeight) throws Exception { @@ -303,7 +278,7 @@ public class TJDecompressor { * * @return the height of the largest scaled-down image that the TurboJPEG * decompressor can generate without exceeding the desired image width and - * height + * height. */ public int getScaledHeight(int desiredWidth, int desiredHeight) throws Exception { @@ -402,9 +377,10 @@ public class TJDecompressor { pixelFormat < 0 || pixelFormat >= TJ.NUMPF || flags < 0) throw new Exception("Invalid argument in decompress()"); if (yuvImage != null) - decodeYUV(yuvImage.getBuf(), yuvImage.getPad(), yuvImage.getSubsamp(), - dstBuf, x, y, yuvImage.getWidth(), pitch, yuvImage.getHeight(), - pixelFormat, flags); + decodeYUV(yuvImage.getPlanes(), yuvImage.getOffsets(), + yuvImage.getStrides(), yuvImage.getSubsamp(), dstBuf, x, y, + yuvImage.getWidth(), pitch, yuvImage.getHeight(), pixelFormat, + flags); else { if (x > 0 || y > 0) decompress(jpegBuf, jpegBufSize, dstBuf, x, y, desiredWidth, pitch, @@ -449,7 +425,7 @@ public class TJDecompressor { * @param flags the bitwise OR of one or more of * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} * - * @return a buffer containing the decompressed image + * @return a buffer containing the decompressed image. */ public byte[] decompress(int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags) throws Exception { @@ -500,9 +476,9 @@ public class TJDecompressor { if (jpegSubsamp != dstImage.getSubsamp()) throw new Exception("YUVImage subsampling level does not match that of the JPEG image"); - decompressToYUV(jpegBuf, jpegBufSize, dstImage.getBuf(), - dstImage.getWidth(), dstImage.getPad(), - dstImage.getHeight(), flags); + decompressToYUV(jpegBuf, jpegBufSize, dstImage.getPlanes(), + dstImage.getOffsets(), dstImage.getWidth(), + dstImage.getStrides(), dstImage.getHeight(), flags); } /** @@ -517,12 +493,70 @@ public class TJDecompressor { /** * Decompress the JPEG source image associated with this decompressor - * instance into a YUV planar image and return a YUVImage - * instance containing the decompressed image. This method performs JPEG - * decompression but leaves out the color conversion step, so a planar YUV - * image is generated instead of an RGB or grayscale image. This method - * cannot be used to decompress JPEG source images with the CMYK or YCCK - * colorspace. + * instance into a set of Y, U (Cb), and V (Cr) image planes and return a + * YUVImage instance containing the decompressed image planes. + * This method performs JPEG decompression but leaves out the color + * conversion step, so a planar YUV image is generated instead of an RGB or + * grayscale image. This method cannot be used to decompress JPEG source + * images with the CMYK or YCCK colorspace. + * + * @param desiredWidth desired width (in pixels) of the YUV image. If the + * desired image dimensions are different than the dimensions 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 dimensions. Setting this to 0 is the same as setting it to + * the width of the JPEG image (in other words, the width will not be + * considered when determining the scaled image size.) + * + * @param strides an array of integers, each specifying the number of bytes + * per line in the corresponding plane of the output image. Setting the + * stride for any plane to 0 is the same as setting it to the scaled + * component width of the plane. If strides is NULL, then the + * strides for all planes will be set to their respective scaled component + * widths. You can adjust the strides in order to add an arbitrary amount of + * line padding to each plane. + * + * @param desiredHeight desired height (in pixels) of the YUV image. If the + * desired image dimensions are different than the dimensions 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 dimensions. Setting this to 0 is the same as setting it to + * the height of the JPEG image (in other words, the height will not be + * considered when determining the scaled image size.) + * + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} + * + * @return a YUV planar image. + */ + public YUVImage decompressToYUV(int desiredWidth, int[] strides, + int desiredHeight, + int flags) throws Exception { + if (flags < 0) + throw new Exception("Invalid argument in decompressToYUV()"); + if (jpegWidth < 1 || jpegHeight < 1 || jpegSubsamp < 0) + throw new Exception(NO_ASSOC_ERROR); + if (jpegSubsamp >= TJ.NUMSAMP) + throw new Exception("JPEG header information is invalid"); + if (yuvImage != null) + throw new Exception("Source image is the wrong type"); + + int scaledWidth = getScaledWidth(desiredWidth, desiredHeight); + int scaledHeight = getScaledHeight(desiredWidth, desiredHeight); + YUVImage yuvImage = new YUVImage(scaledWidth, null, scaledHeight, + jpegSubsamp); + decompressToYUV(yuvImage, flags); + return yuvImage; + } + + /** + * Decompress the JPEG source image associated with this decompressor + * instance into a unified YUV planar image buffer and return a + * YUVImage instance containing the decompressed image. This + * method performs JPEG decompression but leaves out the color conversion + * step, so a planar YUV image is generated instead of an RGB or grayscale + * image. This method cannot be used to decompress JPEG source images with + * the CMYK or YCCK colorspace. * * @param desiredWidth desired width (in pixels) of the YUV image. If the * desired image dimensions are different than the dimensions of the JPEG @@ -547,7 +581,7 @@ public class TJDecompressor { * @param flags the bitwise OR of one or more of * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} * - * @return a YUV planar image + * @return a YUV planar image. */ public YUVImage decompressToYUV(int desiredWidth, int pad, int desiredHeight, int flags) throws Exception { @@ -650,9 +684,10 @@ public class TJDecompressor { pixelFormat < 0 || pixelFormat >= TJ.NUMPF || flags < 0) throw new Exception("Invalid argument in decompress()"); if (yuvImage != null) - decodeYUV(yuvImage.getBuf(), yuvImage.getPad(), yuvImage.getSubsamp(), - dstBuf, x, y, yuvImage.getWidth(), stride, - yuvImage.getHeight(), pixelFormat, flags); + decodeYUV(yuvImage.getPlanes(), yuvImage.getOffsets(), + yuvImage.getStrides(), yuvImage.getSubsamp(), dstBuf, x, y, + yuvImage.getWidth(), stride, yuvImage.getHeight(), pixelFormat, + flags); else decompress(jpegBuf, jpegBufSize, dstBuf, x, y, desiredWidth, stride, desiredHeight, pixelFormat, flags); @@ -734,8 +769,9 @@ public class TJDecompressor { DataBufferInt db = (DataBufferInt)wr.getDataBuffer(); int[] buf = db.getData(); if (yuvImage != null) - decodeYUV(yuvImage.getBuf(), yuvImage.getPad(), yuvImage.getSubsamp(), - buf, 0, 0, yuvImage.getWidth(), stride, yuvImage.getHeight(), + decodeYUV(yuvImage.getPlanes(), yuvImage.getOffsets(), + yuvImage.getStrides(), yuvImage.getSubsamp(), buf, 0, 0, + yuvImage.getWidth(), stride, yuvImage.getHeight(), pixelFormat, flags); else { if (jpegBuf == null) @@ -778,7 +814,7 @@ public class TJDecompressor { * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} * * @return a BufferedImage instance containing the - * decompressed/decoded image + * decompressed/decoded image. */ public BufferedImage decompress(int desiredWidth, int desiredHeight, int bufferedImageType, int flags) @@ -836,16 +872,17 @@ public class TJDecompressor { private native void decompressToYUV(byte[] srcBuf, int size, byte[] dstBuf, int flags) throws Exception; // deprecated - private native void decompressToYUV(byte[] srcBuf, int size, byte[] dstBuf, - int desiredWidth, int pad, int desiredheight, int flags) throws Exception; + private native void decompressToYUV(byte[] srcBuf, int size, + byte[][] dstPlanes, int[] dstOffsets, int desiredWidth, int[] dstStrides, + int desiredheight, int flags) throws Exception; - private native void decodeYUV(byte[] srcBuf, int pad, int subsamp, - byte[] dstBuf, int x, int y, int width, int pitch, int height, - int pixelFormat, int flags) throws Exception; + private native void decodeYUV(byte[][] srcPlanes, int[] srcOffsets, + int[] srcStrides, int subsamp, byte[] dstBuf, int x, int y, int width, + int pitch, int height, int pixelFormat, int flags) throws Exception; - private native void decodeYUV(byte[] srcBuf, int pad, int subsamp, - int[] dstBuf, int x, int y, int width, int stride, int height, - int pixelFormat, int flags) throws Exception; + private native void decodeYUV(byte[][] srcPlanes, int[] srcOffsets, + int[] srcStrides, int subsamp, int[] dstBuf, int x, int y, int width, + int stride, int height, int pixelFormat, int flags) throws Exception; static { TJLoader.load(); diff --git a/java/org/libjpegturbo/turbojpeg/TJScalingFactor.java b/java/org/libjpegturbo/turbojpeg/TJScalingFactor.java index 4e7363f..e00fdf7 100644 --- a/java/org/libjpegturbo/turbojpeg/TJScalingFactor.java +++ b/java/org/libjpegturbo/turbojpeg/TJScalingFactor.java @@ -42,6 +42,7 @@ public class TJScalingFactor { /** * Returns numerator + * * @return numerator */ public int getNum() { @@ -50,6 +51,7 @@ public class TJScalingFactor { /** * Returns denominator + * * @return denominator */ public int getDenom() { @@ -60,7 +62,8 @@ public class TJScalingFactor { * Returns the scaled value of dimension. This function * performs the integer equivalent of * ceil(dimension * scalingFactor). - * @return the scaled value of dimension + * + * @return the scaled value of dimension. */ public int getScaled(int dimension) { return (dimension * num + denom - 1) / denom; @@ -69,8 +72,9 @@ public class TJScalingFactor { /** * Returns true or false, depending on whether this instance and * other have the same numerator and denominator. + * * @return true or false, depending on whether this instance and - * other have the same numerator and denominator + * other have the same numerator and denominator. */ public boolean equals(TJScalingFactor other) { return (this.num == other.num && this.denom == other.denom); @@ -79,8 +83,9 @@ public class TJScalingFactor { /** * Returns true or false, depending on whether this instance is equal to * 1/1. + * * @return true or false, depending on whether this instance is equal to - * 1/1 + * 1/1. */ public boolean isOne() { return (num == 1 && denom == 1); diff --git a/java/org/libjpegturbo/turbojpeg/TJTransformer.java b/java/org/libjpegturbo/turbojpeg/TJTransformer.java index a62f410..cf773fa 100644 --- a/java/org/libjpegturbo/turbojpeg/TJTransformer.java +++ b/java/org/libjpegturbo/turbojpeg/TJTransformer.java @@ -111,7 +111,7 @@ public class TJTransformer extends TJDecompressor { * corresponding transformed output image * * @return an array of {@link TJDecompressor} instances, each of - * which has a transformed JPEG image associated with it + * which has a transformed JPEG image associated with it. * * @param flags the bitwise OR of one or more of * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} @@ -141,7 +141,7 @@ public class TJTransformer extends TJDecompressor { * generated by the most recent transform operation. * * @return an array containing the sizes of the transformed JPEG images - * generated by the most recent transform operation + * generated by the most recent transform operation. */ public int[] getTransformedSizes() throws Exception { if (transformedSizes == null) diff --git a/java/org/libjpegturbo/turbojpeg/YUVImage.java b/java/org/libjpegturbo/turbojpeg/YUVImage.java index 27b1b70..2d790e9 100644 --- a/java/org/libjpegturbo/turbojpeg/YUVImage.java +++ b/java/org/libjpegturbo/turbojpeg/YUVImage.java @@ -43,20 +43,18 @@ package org.libjpegturbo.turbojpeg; * image format consisting of Y, Cb, and Cr image planes. *

    * Each plane is simply a 2D array of bytes, each byte representing the value - * of one of the components at a particular location in the image. The - * "component width" and "component height" of each plane are determined by the - * image width, height, and level of chrominance subsampling. For the - * luminance plane, the component width is the image width padded to the - * nearest multiple of the horizontal subsampling factor (2 in the case of - * 4:2:0 and 4:2:2, 4 in the case of 4:1:1, 1 in the case of 4:4:4 or - * grayscale.) Similarly, the component height of the luminance plane is the - * image height padded to the nearest multiple of the vertical subsampling - * factor (2 in the case of 4:2:0 or 4:4:0, 1 in the case of 4:4:4 or - * grayscale.) The component width of the chrominance planes is equal to the - * component width of the luminance plane divided by the horizontal subsampling - * factor, and the component height of the chrominance planes is equal to the - * component height of the luminance plane divided by the vertical subsampling - * factor. + * of one of the components (Y, Cb, or Cr) at a particular location in the + * image. The width and height of each plane are determined by the image + * width, height, and level of chrominance subsampling. The luminance plane + * width is the image width padded to the nearest multiple of the horizontal + * subsampling factor (2 in the case of 4:2:0 and 4:2:2, 4 in the case of + * 4:1:1, 1 in the case of 4:4:4 or grayscale.) Similarly, the luminance plane + * height is the image height padded to the nearest multiple of the vertical + * subsampling factor (2 in the case of 4:2:0 or 4:4:0, 1 in the case of 4:4:4 + * or grayscale.) The chrominance plane width is equal to the luminance plane + * width divided by the horizontal subsampling factor, and the chrominance + * plane height is equal to the luminance plane height divided by the vertical + * subsampling factor. *

    * For example, if the source image is 35 x 35 pixels and 4:2:2 subsampling is * used, then the luminance plane would be 36 x 35 bytes, and each of the @@ -67,10 +65,35 @@ package org.libjpegturbo.turbojpeg; public class YUVImage { private static final String NO_ASSOC_ERROR = - "No YUV buffer is associated with this instance"; + "No image data is associated with this instance"; /** - * Create a YUVImage instance with a new image buffer. + * Create a new YUVImage instance backed by separate image + * planes, and allocate memory for the image planes. + * + * @param width width (in pixels) of the YUV image + * + * @param strides an array of integers, each specifying the number of bytes + * per line in the corresponding plane of the YUV image. Setting the stride + * for any plane to 0 is the same as setting it to the plane width (see + * {@link YUVImage above}.) If strides is null, then the + * strides for all planes will be set to their respective plane widths. When + * using this constructor, the stride for each plane must be equal to or + * greater than the plane width. + * + * @param height height (in pixels) of the YUV image + * + * @param subsamp the level of chrominance subsampling to be used in the YUV + * image (one of {@link TJ#SAMP_444 TJ.SAMP_*}) + */ + public YUVImage(int width, int[] strides, int height, int subsamp) + throws Exception { + setBuf(null, null, width, strides, height, subsamp, true); + } + + /** + * Create a new YUVImage instance backed by a unified image + * buffer, and allocate memory for the image buffer. * * @param width width (in pixels) of the YUV image * @@ -83,13 +106,52 @@ public class YUVImage { * image (one of {@link TJ#SAMP_444 TJ.SAMP_*}) */ public YUVImage(int width, int pad, int height, int subsamp) - throws Exception { + throws Exception { setBuf(new byte[TJ.bufSizeYUV(width, pad, height, subsamp)], width, pad, height, subsamp); } /** - * Create a YUVImage instance from an existing YUV planar image + * Create a new YUVImage instance from a set of existing image + * planes. + * + * @param planes an array of buffers representing the Y, U (Cb), and V (Cr) + * image planes (or just the Y plane, if the image is grayscale.) These + * planes can be contiguous or non-contiguous in memory. Plane + * i should be at least offsets[i] + + * {@link TJ#planeSizeYUV TJ.planeSizeYUV}(i, width, strides[i], height, subsamp) + * bytes in size. + * + * @param offsets If this YUVImage instance represents a + * subregion of a larger image, then offsets[i] specifies the + * offset (in bytes) of the subregion within plane i of the + * larger image. Setting this to null is the same as setting the offsets for + * all planes to 0. + * + * @param width width (in pixels) of the new YUV image (or subregion) + * + * @param strides an array of integers, each specifying the number of bytes + * per line in the corresponding plane of the YUV image. Setting the stride + * for any plane to 0 is the same as setting it to the plane width (see + * {@link YUVImage above}.) 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 add an arbitrary amount of line padding + * to each plane or to specify that this YUVImage instance is a + * subregion of a larger image (in which case, strides[i] should + * be set to the plane width of plane i in the larger image.) + * + * @param height height (in pixels) of the new YUV image (or subregion) + * + * @param subsamp the level of chrominance subsampling used in the YUV + * image (one of {@link TJ#SAMP_444 TJ.SAMP_*}) + */ + public YUVImage(byte[][] planes, int[] offsets, int width, int[] strides, + int height, int subsamp) throws Exception { + setBuf(planes, offsets, width, strides, height, subsamp, false); + } + + /** + * Create a new YUVImage instance from an existing unified image * buffer. * * @param yuvImage image buffer that contains or will contain YUV planar @@ -115,8 +177,89 @@ public class YUVImage { } /** - * Assign an existing YUV planar image buffer to this YUVImage - * instance. + * Assign a set of image planes to this YUVImage instance. + * + * @param planes an array of buffers representing the Y, U (Cb), and V (Cr) + * image planes (or just the Y plane, if the image is grayscale.) These + * planes can be contiguous or non-contiguous in memory. Plane + * i should be at least offsets[i] + + * {@link TJ#planeSizeYUV TJ.planeSizeYUV}(i, width, strides[i], height, subsamp) + * bytes in size. + * + * @param offsets If this YUVImage instance represents a + * subregion of a larger image, then offsets[i] specifies the + * offset (in bytes) of the subregion within plane i of the + * larger image. Setting this to null is the same as setting the offsets for + * all planes to 0. + * + * @param width width (in pixels) of the YUV image (or subregion) + * + * @param strides an array of integers, each specifying the number of bytes + * per line in the corresponding plane of the YUV image. Setting the stride + * for any plane to 0 is the same as setting it to the plane width (see + * {@link YUVImage above}.) 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 add an arbitrary amount of line padding + * to each plane or to specify that this YUVImage image is a + * subregion of a larger image (in which case, strides[i] should + * be set to the plane width of plane i in the larger image.) + * + * @param height height (in pixels) of the YUV image (or subregion) + * + * @param subsamp the level of chrominance subsampling used in the YUV + * image (one of {@link TJ#SAMP_444 TJ.SAMP_*}) + */ + public void setBuf(byte[][] planes, int[] offsets, int width, int strides[], + int height, int subsamp) throws Exception { + setBuf(planes, offsets, width, strides, height, subsamp, false); + } + + private void setBuf(byte[][] planes, int[] offsets, int width, int strides[], + int height, int subsamp, boolean alloc) throws Exception { + if ((planes == null && !alloc) || width < 1 || height < 1 || subsamp < 0 || + subsamp >= TJ.NUMSAMP) + throw new Exception("Invalid argument in YUVImage::setBuf()"); + + int nc = (subsamp == TJ.SAMP_GRAY ? 1 : 3); + if (planes.length != nc || (offsets != null && offsets.length != nc) || + (strides != null && strides.length != nc)) + throw new Exception("YUVImage::setBuf(): planes, offsets, or strides array is the wrong size"); + + if (offsets == null) + offsets = new int[nc]; + if (strides == null) + strides = new int[nc]; + + for (int i = 0; i < nc; i++) { + int pw = TJ.planeWidth(i, width, subsamp); + int ph = TJ.planeHeight(i, height, subsamp); + int planeSize = TJ.planeSizeYUV(i, width, strides[i], height, subsamp); + + if (strides[i] == 0) + strides[i] = pw; + if (alloc) { + if (strides[i] < pw) + throw new Exception("Stride must be >= plane width when allocating a new YUV image"); + planes[i] = new byte[strides[i] * ph]; + } + if (planes[i] == null || offsets[i] < 0) + throw new Exception("Invalid argument in YUVImage::setBuf()"); + if (strides[i] < 0 && offsets[i] - planeSize + pw < 0) + throw new Exception("Stride for plane " + i + " would cause memory to be accessed below plane boundary"); + if (planes[i].length < offsets[i] + planeSize) + throw new Exception("Image plane " + i + " is not large enough"); + } + + yuvPlanes = planes; + yuvOffsets = offsets; + yuvWidth = width; + yuvStrides = strides; + yuvHeight = height; + yuvSubsamp = subsamp; + } + + /** + * Assign a unified image buffer to this YUVImage instance. * * @param yuvImage image buffer that contains or will contain YUV planar * image data. Use {@link TJ#bufSizeYUV} to determine the minimum size for @@ -139,20 +282,34 @@ public class YUVImage { int subsamp) throws Exception { if (yuvImage == null || width < 1 || pad < 1 || ((pad & (pad - 1)) != 0) || height < 1 || subsamp < 0 || subsamp >= TJ.NUMSAMP) - throw new Exception("Invalid argument in YUVImage()"); + throw new Exception("Invalid argument in YUVImage::setBuf()"); if (yuvImage.length < TJ.bufSizeYUV(width, pad, height, subsamp)) throw new Exception("YUV image buffer is not large enough"); - yuvBuf = yuvImage; - yuvWidth = width; + + int nc = (subsamp == TJ.SAMP_GRAY ? 1 : 3); + byte[][] planes = new byte[nc][]; + int[] strides = new int[nc]; + int[] offsets = new int[nc]; + + planes[0] = yuvImage; + strides[0] = PAD(TJ.planeWidth(0, width, subsamp), pad); + if (subsamp != TJ.SAMP_GRAY) { + strides[1] = strides[2] = PAD(TJ.planeWidth(1, width, subsamp), pad); + planes[1] = planes[2] = yuvImage; + offsets[1] = offsets[0] + + strides[0] * TJ.planeHeight(0, height, subsamp); + offsets[2] = offsets[1] + + strides[1] * TJ.planeHeight(1, height, subsamp); + } + yuvPad = pad; - yuvHeight = height; - yuvSubsamp = subsamp; + setBuf(planes, offsets, width, strides, height, subsamp); } /** - * Returns the width of the YUV image. + * Returns the width of the YUV image (or subregion.) * - * @return the width of the YUV image + * @return the width of the YUV image (or subregion) */ public int getWidth() throws Exception { if (yuvWidth < 1) @@ -161,9 +318,9 @@ public class YUVImage { } /** - * Returns the height of the YUV image. + * Returns the height of the YUV image (or subregion.) * - * @return the height of the YUV image + * @return the height of the YUV image (or subregion) */ public int getHeight() throws Exception { if (yuvHeight < 1) @@ -172,16 +329,43 @@ public class YUVImage { } /** - * Returns the line padding used in the YUV image buffer. + * Returns the line padding used in the YUV image buffer (if this image is + * stored in a unified buffer rather than separate image planes.) * * @return the line padding used in the YUV image buffer */ public int getPad() throws Exception { - if (yuvPad < 1 || ((yuvPad & (yuvPad - 1)) != 0)) + if (yuvPlanes == null) throw new Exception(NO_ASSOC_ERROR); + if (yuvPad < 1 || ((yuvPad & (yuvPad - 1)) != 0)) + throw new Exception("Image is not stored in a unified buffer"); return yuvPad; } + /** + * Returns the number of bytes per line of each plane in the YUV image. + * + * @return the number of bytes per line of each plane in the YUV image + */ + public int[] getStrides() throws Exception { + if (yuvStrides == null) + throw new Exception(NO_ASSOC_ERROR); + return yuvStrides; + } + + /** + * Returns the offsets (in bytes) of each plane within the planes of a larger + * YUV image. + * + * @return the offsets (in bytes) of each plane within the planes of a larger + * YUV image + */ + public int[] getOffsets() throws Exception { + if (yuvOffsets == null) + throw new Exception(NO_ASSOC_ERROR); + return yuvOffsets; + } + /** * Returns the level of chrominance subsampling used in the YUV image. See * {@link TJ#SAMP_444 TJ.SAMP_*}. @@ -195,29 +379,61 @@ public class YUVImage { } /** - * Returns the YUV image buffer + * Returns the YUV image planes. If the image is stored in a unified buffer, + * then all image planes will point to that buffer. + * + * @return the YUV image planes + */ + public byte[][] getPlanes() throws Exception { + if (yuvPlanes == null) + throw new Exception(NO_ASSOC_ERROR); + return yuvPlanes; + } + + /** + * Returns the YUV image buffer (if this image is stored in a unified + * buffer rather than separate image planes.) * * @return the YUV image buffer */ public byte[] getBuf() throws Exception { - if (yuvBuf == null) + if (yuvPlanes == null || yuvSubsamp < 0 || yuvSubsamp >= TJ.NUMSAMP) throw new Exception(NO_ASSOC_ERROR); - return yuvBuf; + int nc = (yuvSubsamp == TJ.SAMP_GRAY ? 1 : 3); + for (int i = 1; i < nc; i++) { + if (yuvPlanes[i] != yuvPlanes[0]) + throw new Exception("Image is not stored in a unified buffer"); + } + return yuvPlanes[0]; } /** - * Returns the size (in bytes) of the YUV image buffer + * Returns the size (in bytes) of the YUV image buffer (if this image is + * stored in a unified buffer rather than separate image planes.) * * @return the size (in bytes) of the YUV image buffer */ - public int getSize() throws Exception { - if (yuvBuf == null) - throw new Exception(NO_ASSOC_ERROR); - return TJ.bufSizeYUV(yuvWidth, yuvPad, yuvHeight, yuvSubsamp); - } + public int getSize() throws Exception { + if (yuvPlanes == null || yuvSubsamp < 0 || yuvSubsamp >= TJ.NUMSAMP) + throw new Exception(NO_ASSOC_ERROR); + int nc = (yuvSubsamp == TJ.SAMP_GRAY ? 1 : 3); + if (yuvPad < 1) + throw new Exception("Image is not stored in a unified buffer"); + for (int i = 1; i < nc; i++) { + if (yuvPlanes[i] != yuvPlanes[0]) + throw new Exception("Image is not stored in a unified buffer"); + } + return TJ.bufSizeYUV(yuvWidth, yuvPad, yuvHeight, yuvSubsamp); + } + + private static final int PAD(int v, int p) { + return (v + p - 1) & (~(p - 1)); + } protected long handle = 0; - protected byte[] yuvBuf = null; + protected byte[][] yuvPlanes = null; + protected int[] yuvOffsets = null; + protected int[] yuvStrides = null; protected int yuvPad = 0; protected int yuvWidth = 0; protected int yuvHeight = 0; diff --git a/java/org_libjpegturbo_turbojpeg_TJ.h b/java/org_libjpegturbo_turbojpeg_TJ.h index b00a128..84ee871 100644 --- a/java/org_libjpegturbo_turbojpeg_TJ.h +++ b/java/org_libjpegturbo_turbojpeg_TJ.h @@ -91,6 +91,30 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__IIII JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__III (JNIEnv *, jclass, jint, jint, jint); +/* + * Class: org_libjpegturbo_turbojpeg_TJ + * Method: planeSizeYUV + * Signature: (IIIII)I + */ +JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_planeSizeYUV__IIIII + (JNIEnv *, jclass, jint, jint, jint, jint, jint); + +/* + * Class: org_libjpegturbo_turbojpeg_TJ + * Method: planeWidth + * Signature: (III)I + */ +JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_planeWidth__III + (JNIEnv *, jclass, jint, jint, jint); + +/* + * Class: org_libjpegturbo_turbojpeg_TJ + * Method: planeHeight + * Signature: (III)I + */ +JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_planeHeight__III + (JNIEnv *, jclass, jint, jint, jint); + /* * Class: org_libjpegturbo_turbojpeg_TJ * Method: getScalingFactors diff --git a/java/org_libjpegturbo_turbojpeg_TJCompressor.h b/java/org_libjpegturbo_turbojpeg_TJCompressor.h index edb23b4..e76bd0e 100644 --- a/java/org_libjpegturbo_turbojpeg_TJCompressor.h +++ b/java/org_libjpegturbo_turbojpeg_TJCompressor.h @@ -58,10 +58,10 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3 /* * Class: org_libjpegturbo_turbojpeg_TJCompressor * Method: compressFromYUV - * Signature: ([BIIII[BII)I + * Signature: ([[B[II[III[BII)I */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFromYUV___3BIIII_3BII - (JNIEnv *, jobject, jbyteArray, jint, jint, jint, jint, jbyteArray, jint, jint); +JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFromYUV___3_3B_3II_3III_3BII + (JNIEnv *, jobject, jobjectArray, jintArray, jint, jintArray, jint, jint, jbyteArray, jint, jint); /* * Class: org_libjpegturbo_turbojpeg_TJCompressor @@ -74,10 +74,10 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ /* * Class: org_libjpegturbo_turbojpeg_TJCompressor * Method: encodeYUV - * Signature: ([BIIIIII[BIII)V + * Signature: ([BIIIIII[[B[I[III)V */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIIIII_3BIII - (JNIEnv *, jobject, jbyteArray, jint, jint, jint, jint, jint, jint, jbyteArray, jint, jint, jint); +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIIIII_3_3B_3I_3III + (JNIEnv *, jobject, jbyteArray, jint, jint, jint, jint, jint, jint, jobjectArray, jintArray, jintArray, jint, jint); /* * Class: org_libjpegturbo_turbojpeg_TJCompressor @@ -90,10 +90,10 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ /* * Class: org_libjpegturbo_turbojpeg_TJCompressor * Method: encodeYUV - * Signature: ([IIIIIII[BIII)V + * Signature: ([IIIIIII[[B[I[III)V */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIIIII_3BIII - (JNIEnv *, jobject, jintArray, jint, jint, jint, jint, jint, jint, jbyteArray, jint, jint, jint); +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIIIII_3_3B_3I_3III + (JNIEnv *, jobject, jintArray, jint, jint, jint, jint, jint, jint, jobjectArray, jintArray, jintArray, jint, jint); #ifdef __cplusplus } diff --git a/java/org_libjpegturbo_turbojpeg_TJDecompressor.h b/java/org_libjpegturbo_turbojpeg_TJDecompressor.h index 1d8205c..2d58e73 100644 --- a/java/org_libjpegturbo_turbojpeg_TJDecompressor.h +++ b/java/org_libjpegturbo_turbojpeg_TJDecompressor.h @@ -74,26 +74,26 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress /* * Class: org_libjpegturbo_turbojpeg_TJDecompressor * Method: decompressToYUV - * Signature: ([BI[BIIII)V + * Signature: ([BI[[B[II[III)V */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3BIIII - (JNIEnv *, jobject, jbyteArray, jint, jbyteArray, jint, jint, jint, jint); +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3_3B_3II_3III + (JNIEnv *, jobject, jbyteArray, jint, jobjectArray, jintArray, jint, jintArray, jint, jint); /* * Class: org_libjpegturbo_turbojpeg_TJDecompressor * Method: decodeYUV - * Signature: ([BII[BIIIIIII)V + * Signature: ([[B[I[II[BIIIIIII)V */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3BII_3BIIIIIII - (JNIEnv *, jobject, jbyteArray, jint, jint, jbyteArray, jint, jint, jint, jint, jint, jint, jint); +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3_3B_3I_3II_3BIIIIIII + (JNIEnv *, jobject, jobjectArray, jintArray, jintArray, jint, jbyteArray, jint, jint, jint, jint, jint, jint, jint); /* * Class: org_libjpegturbo_turbojpeg_TJDecompressor * Method: decodeYUV - * Signature: ([BII[IIIIIIII)V + * Signature: ([[B[I[II[IIIIIIII)V */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3BII_3IIIIIIII - (JNIEnv *, jobject, jbyteArray, jint, jint, jintArray, jint, jint, jint, jint, jint, jint, jint); +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3_3B_3I_3II_3IIIIIIII + (JNIEnv *, jobject, jobjectArray, jintArray, jintArray, jint, jintArray, jint, jint, jint, jint, jint, jint, jint); #ifdef __cplusplus } diff --git a/turbojpeg-jni.c b/turbojpeg-jni.c index f872cf0..cab57bd 100644 --- a/turbojpeg-jni.c +++ b/turbojpeg-jni.c @@ -37,6 +37,8 @@ #include "java/org_libjpegturbo_turbojpeg_TJDecompressor.h" #include "java/org_libjpegturbo_turbojpeg_TJ.h" +#define PAD(v, p) ((v+(p)-1)&(~((p)-1))) + #define _throw(msg) { \ jclass _exccls=(*env)->FindClass(env, "java/lang/Exception"); \ if(!_exccls) goto bailout; \ @@ -87,6 +89,41 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__III 4, height, subsamp); } +/* TurboJPEG 1.4.x: TJ::planeSizeYUV() */ +JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_planeSizeYUV__IIIII + (JNIEnv *env, jclass cls, jint componentID, jint width, jint stride, + jint height, jint subsamp) +{ + jint retval=(jint)tjPlaneSizeYUV(componentID, width, stride, height, + subsamp); + if(retval==-1) _throw(tjGetErrorStr()); + + bailout: + return retval; +} + +/* TurboJPEG 1.4.x: TJ::planeWidth() */ +JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_planeWidth__III + (JNIEnv *env, jclass cls, jint componentID, jint width, jint subsamp) +{ + jint retval=(jint)tjPlaneWidth(componentID, width, subsamp); + if(retval==-1) _throw(tjGetErrorStr()); + + bailout: + return retval; +} + +/* TurboJPEG 1.4.x: TJ::planeHeight() */ +JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_planeHeight__III + (JNIEnv *env, jclass cls, jint componentID, jint height, jint subsamp) +{ + jint retval=(jint)tjPlaneHeight(componentID, height, subsamp); + if(retval==-1) _throw(tjGetErrorStr()); + + bailout: + return retval; +} + /* TurboJPEG 1.2.x: TJCompressor::init() */ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_init (JNIEnv *env, jobject obj) @@ -203,101 +240,172 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3 } /* TurboJPEG 1.4.x: TJCompressor::compressFromYUV() */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFromYUV___3BIIII_3BII - (JNIEnv *env, jobject obj, jbyteArray src, jint width, jint pad, jint height, - jint subsamp, jbyteArray dst, jint jpegQual, jint flags) +JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFromYUV___3_3B_3II_3III_3BII + (JNIEnv *env, jobject obj, jobjectArray srcobjs, jintArray jSrcOffsets, + jint width, jintArray jSrcStrides, jint height, jint subsamp, + jbyteArray dst, jint jpegQual, jint flags) { tjhandle handle=0; unsigned long jpegSize=0; - jsize arraySize=0; - unsigned char *srcBuf=NULL, *jpegBuf=NULL; + jbyteArray jSrcPlanes[3]={NULL, NULL, NULL}; + unsigned char *srcPlanes[3], *jpegBuf=NULL; + int *srcOffsets=NULL, *srcStrides=NULL; + int nc=(subsamp==org_libjpegturbo_turbojpeg_TJ_SAMP_GRAY? 1:3), i; gethandle(); - arraySize=tjBufSizeYUV2(width, pad, height, subsamp); - if((*env)->GetArrayLength(env, src)=org_libjpegturbo_turbojpeg_TJ_NUMSAMP) + _throw("Invalid argument in compressFromYUV()"); + if(org_libjpegturbo_turbojpeg_TJ_NUMSAMP!=TJ_NUMSAMP) + _throw("Mismatch between Java and C API"); + + if((*env)->GetArrayLength(env, srcobjs)GetArrayLength(env, jSrcOffsets)GetArrayLength(env, jSrcStrides)GetArrayLength(env, dst)<(jsize)jpegSize) _throw("Destination buffer is not large enough"); - bailif0(srcBuf=(*env)->GetPrimitiveArrayCritical(env, src, 0)); + bailif0(srcOffsets=(*env)->GetPrimitiveArrayCritical(env, jSrcOffsets, 0)); + bailif0(srcStrides=(*env)->GetPrimitiveArrayCritical(env, jSrcStrides, 0)); + for(i=0; iGetObjectArrayElement(env, srcobjs, i)); + if((*env)->GetArrayLength(env, jSrcPlanes[i])GetPrimitiveArrayCritical(env, jSrcPlanes[i], + 0)); + srcPlanes[i]=&srcPlanes[i][srcOffsets[i]]; + } bailif0(jpegBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); - if(tjCompressFromYUV(handle, srcBuf, width, pad, height, subsamp, &jpegBuf, - &jpegSize, jpegQual, flags|TJFLAG_NOREALLOC)==-1) + if(tjCompressFromYUVPlanes(handle, srcPlanes, width, srcStrides, height, + subsamp, &jpegBuf, &jpegSize, jpegQual, flags|TJFLAG_NOREALLOC)==-1) _throw(tjGetErrorStr()); bailout: if(jpegBuf) (*env)->ReleasePrimitiveArrayCritical(env, dst, jpegBuf, 0); - if(srcBuf) (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0); + for(i=0; iReleasePrimitiveArrayCritical(env, jSrcPlanes[i], srcPlanes[i], + 0); + } + if(srcStrides) + (*env)->ReleasePrimitiveArrayCritical(env, jSrcStrides, srcStrides, 0); + if(srcOffsets) + (*env)->ReleasePrimitiveArrayCritical(env, jSrcOffsets, srcOffsets, 0); return (jint)jpegSize; } static void TJCompressor_encodeYUV (JNIEnv *env, jobject obj, jarray src, jint srcElementSize, jint x, jint y, - jint width, jint pitch, jint height, jint pf, jbyteArray dst, jint pad, - jint subsamp, jint flags) + jint width, jint pitch, jint height, jint pf, jobjectArray dstobjs, + jintArray jDstOffsets, jintArray jDstStrides, jint subsamp, jint flags) { tjhandle handle=0; - jsize arraySize=0, actualPitch, yuvSize; - unsigned char *srcBuf=NULL, *dstBuf=NULL; + jsize arraySize=0, actualPitch; + jbyteArray jDstPlanes[3]={NULL, NULL, NULL}; + unsigned char *srcBuf=NULL, *dstPlanes[3]; + int *dstOffsets=NULL, *dstStrides=NULL; + int nc=(subsamp==org_libjpegturbo_turbojpeg_TJ_SAMP_GRAY? 1:3), i; gethandle(); if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF || width<1 || height<1 - || pitch<0) + || pitch<0 || subsamp<0 || subsamp>=org_libjpegturbo_turbojpeg_TJ_NUMSAMP) _throw("Invalid argument in encodeYUV()"); - if(org_libjpegturbo_turbojpeg_TJ_NUMPF!=TJ_NUMPF) + if(org_libjpegturbo_turbojpeg_TJ_NUMPF!=TJ_NUMPF + || org_libjpegturbo_turbojpeg_TJ_NUMSAMP!=TJ_NUMSAMP) _throw("Mismatch between Java and C API"); + if((*env)->GetArrayLength(env, dstobjs)GetArrayLength(env, jDstOffsets)GetArrayLength(env, jDstStrides)GetArrayLength(env, src)*srcElementSizeGetArrayLength(env, dst)GetPrimitiveArrayCritical(env, jDstOffsets, 0)); + bailif0(dstStrides=(*env)->GetPrimitiveArrayCritical(env, jDstStrides, 0)); + for(i=0; iGetObjectArrayElement(env, dstobjs, i)); + if((*env)->GetArrayLength(env, jDstPlanes[i])GetPrimitiveArrayCritical(env, jDstPlanes[i], + 0)); + dstPlanes[i]=&dstPlanes[i][dstOffsets[i]]; + } bailif0(srcBuf=(*env)->GetPrimitiveArrayCritical(env, src, 0)); - bailif0(dstBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); - if(tjEncodeYUV3(handle, &srcBuf[y*actualPitch + x*tjPixelSize[pf]], width, - pitch, height, pf, dstBuf, pad, subsamp, flags)==-1) + if(tjEncodeYUVPlanes(handle, &srcBuf[y*actualPitch + x*tjPixelSize[pf]], + width, pitch, height, pf, dstPlanes, dstStrides, subsamp, flags)==-1) _throw(tjGetErrorStr()); bailout: - if(dstBuf) (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); if(srcBuf) (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0); + for(i=0; iReleasePrimitiveArrayCritical(env, jDstPlanes[i], dstPlanes[i], + 0); + } + if(dstStrides) + (*env)->ReleasePrimitiveArrayCritical(env, jDstStrides, dstStrides, 0); + if(dstOffsets) + (*env)->ReleasePrimitiveArrayCritical(env, jDstOffsets, dstOffsets, 0); return; } /* TurboJPEG 1.4.x: TJCompressor::encodeYUV() byte source */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIIIII_3BIII +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIIIII_3_3B_3I_3III (JNIEnv *env, jobject obj, jbyteArray src, jint x, jint y, jint width, - jint pitch, jint height, jint pf, jbyteArray dst, jint pad, jint subsamp, - jint flags) -{ - TJCompressor_encodeYUV(env, obj, src, 1, x, y, width, pitch, height, pf, dst, - pad, subsamp, flags); -} - -/* TurboJPEG 1.2.x: TJCompressor::encodeYUV() byte source */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIII_3BII - (JNIEnv *env, jobject obj, jbyteArray src, jint width, jint pitch, - jint height, jint pf, jbyteArray dst, jint subsamp, jint flags) + jint pitch, jint height, jint pf, jobjectArray dstobjs, + jintArray jDstOffsets, jintArray jDstStrides, jint subsamp, jint flags) { - TJCompressor_encodeYUV(env, obj, src, 1, 0, 0, width, pitch, height, pf, dst, - 4, subsamp, flags); + TJCompressor_encodeYUV(env, obj, src, 1, x, y, width, pitch, height, pf, + dstobjs, jDstOffsets, jDstStrides, subsamp, flags); } /* TurboJPEG 1.4.x: TJCompressor::encodeYUV() int source */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIIIII_3BIII +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, jbyteArray dst, jint pad, jint subsamp, - jint flags) + 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) _throw("Invalid argument in encodeYUV()"); @@ -305,12 +413,58 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ _throw("Pixel format must be 32-bit when encoding from an integer buffer."); TJCompressor_encodeYUV(env, obj, src, sizeof(jint), x, y, width, - stride*sizeof(jint), height, pf, dst, pad, subsamp, flags); + stride*sizeof(jint), height, pf, dstobjs, jDstOffsets, jDstStrides, + subsamp, flags); bailout: return; } +JNIEXPORT void JNICALL TJCompressor_encodeYUV_12 + (JNIEnv *env, jobject obj, jarray src, jint srcElementSize, jint width, + jint pitch, jint height, jint pf, jbyteArray dst, jint subsamp, jint flags) +{ + tjhandle handle=0; + jsize arraySize=0; + unsigned char *srcBuf=NULL, *dstBuf=NULL; + + gethandle(); + + if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF || width<1 || height<1 + || pitch<0) + _throw("Invalid argument in encodeYUV()"); + if(org_libjpegturbo_turbojpeg_TJ_NUMPF!=TJ_NUMPF) + _throw("Mismatch between Java and C API"); + + arraySize=(pitch==0)? width*tjPixelSize[pf]*height:pitch*height; + if((*env)->GetArrayLength(env, src)*srcElementSizeGetArrayLength(env, dst) + <(jsize)tjBufSizeYUV(width, height, subsamp)) + _throw("Destination buffer is not large enough"); + + bailif0(srcBuf=(*env)->GetPrimitiveArrayCritical(env, src, 0)); + bailif0(dstBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); + + if(tjEncodeYUV2(handle, srcBuf, width, pitch, height, pf, dstBuf, subsamp, + flags)==-1) + _throw(tjGetErrorStr()); + + bailout: + if(dstBuf) (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); + if(srcBuf) (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0); + return; +} + +/* TurboJPEG 1.2.x: TJCompressor::encodeYUV() byte source */ +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIII_3BII + (JNIEnv *env, jobject obj, jbyteArray src, jint width, jint pitch, + jint height, jint pf, jbyteArray dst, jint subsamp, jint flags) +{ + TJCompressor_encodeYUV_12(env, obj, src, 1, width, pitch, height, pf, dst, + subsamp, flags); +} + /* TurboJPEG 1.2.x: TJCompressor::encodeYUV() int source */ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIII_3BII (JNIEnv *env, jobject obj, jintArray src, jint width, jint stride, @@ -321,8 +475,8 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ if(tjPixelSize[pf]!=sizeof(jint)) _throw("Pixel format must be 32-bit when encoding from an integer buffer."); - TJCompressor_encodeYUV(env, obj, src, sizeof(jint), 0, 0, width, - stride*sizeof(jint), height, pf, dst, 4, subsamp, flags); + TJCompressor_encodeYUV_12(env, obj, src, sizeof(jint), width, + stride*sizeof(jint), height, pf, dst, subsamp, flags); bailout: return; @@ -518,14 +672,19 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress } /* TurboJPEG 1.4.x: TJDecompressor::decompressToYUV() */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3BIIII - (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jbyteArray dst, - jint desiredWidth, jint pad, jint desiredHeight, jint flags) +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3_3B_3II_3III + (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, + jobjectArray dstobjs, jintArray jDstOffsets, jint desiredWidth, + jintArray jDstStrides, jint desiredHeight, jint flags) { tjhandle handle=0; - unsigned char *jpegBuf=NULL, *dstBuf=NULL; + jbyteArray jDstPlanes[3]={NULL, NULL, NULL}; + unsigned char *jpegBuf=NULL, *dstPlanes[3]; + int *dstOffsets=NULL, *dstStrides=NULL; int jpegSubsamp=-1, jpegWidth=0, jpegHeight=0; - jsize yuvSize; + int nc=0, i, width, height, scaledWidth, scaledHeight, nsf=0; + tjscalingfactor *sf; + gethandle(); @@ -538,22 +697,64 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegHeight", "I")); jpegHeight=(int)(*env)->GetIntField(env, obj, _fid); - yuvSize=(jsize)tjBufSizeYUV2(desiredWidth==0? jpegWidth:desiredWidth, - pad, desiredHeight==0? jpegHeight:desiredHeight, jpegSubsamp); - if(yuvSize==(unsigned long)-1) + nc=(jpegSubsamp==org_libjpegturbo_turbojpeg_TJ_SAMP_GRAY? 1:3); + + width=desiredWidth; height=desiredHeight; + if(width==0) width=jpegWidth; + if(height==0) height=jpegHeight; + sf=tjGetScalingFactors(&nsf); + if(!sf || nsf<1) _throw(tjGetErrorStr()); - if((*env)->GetArrayLength(env, dst)GetPrimitiveArrayCritical(env, jDstOffsets, 0)); + bailif0(dstStrides=(*env)->GetPrimitiveArrayCritical(env, jDstStrides, 0)); + for(i=0; iGetObjectArrayElement(env, dstobjs, i)); + if((*env)->GetArrayLength(env, jDstPlanes[i])GetPrimitiveArrayCritical(env, jDstPlanes[i], + 0)); + dstPlanes[i]=&dstPlanes[i][dstOffsets[i]]; + } bailif0(jpegBuf=(*env)->GetPrimitiveArrayCritical(env, src, 0)); - bailif0(dstBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); - if(tjDecompressToYUV2(handle, jpegBuf, (unsigned long)jpegSize, dstBuf, - desiredWidth, pad, desiredHeight, flags)==-1) + if(tjDecompressToYUVPlanes(handle, jpegBuf, (unsigned long)jpegSize, + dstPlanes, desiredWidth, dstStrides, desiredHeight, flags)==-1) _throw(tjGetErrorStr()); bailout: - if(dstBuf) (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); if(jpegBuf) (*env)->ReleasePrimitiveArrayCritical(env, src, jpegBuf, 0); + for(i=0; iReleasePrimitiveArrayCritical(env, jDstPlanes[i], dstPlanes[i], + 0); + } + if(dstStrides) + (*env)->ReleasePrimitiveArrayCritical(env, jDstStrides, dstStrides, 0); + if(dstOffsets) + (*env)->ReleasePrimitiveArrayCritical(env, jDstOffsets, dstOffsets, 0); return; } @@ -562,71 +763,139 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jbyteArray dst, jint flags) { - Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3BIIII( - env, obj, src, jpegSize, dst, 0, 4, 0, flags); + tjhandle handle=0; + unsigned char *jpegBuf=NULL, *dstBuf=NULL; + int jpegSubsamp=-1, jpegWidth=0, jpegHeight=0; + + gethandle(); + + if((*env)->GetArrayLength(env, src)GetFieldID(env, _cls, "jpegSubsamp", "I")); + jpegSubsamp=(int)(*env)->GetIntField(env, obj, _fid); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegWidth", "I")); + jpegWidth=(int)(*env)->GetIntField(env, obj, _fid); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegHeight", "I")); + jpegHeight=(int)(*env)->GetIntField(env, obj, _fid); + if((*env)->GetArrayLength(env, dst) + <(jsize)tjBufSizeYUV(jpegWidth, jpegHeight, jpegSubsamp)) + _throw("Destination buffer is not large enough"); + + bailif0(jpegBuf=(*env)->GetPrimitiveArrayCritical(env, src, 0)); + bailif0(dstBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); + + if(tjDecompressToYUV(handle, jpegBuf, (unsigned long)jpegSize, dstBuf, + flags)==-1) + _throw(tjGetErrorStr()); + + bailout: + if(dstBuf) (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); + if(jpegBuf) (*env)->ReleasePrimitiveArrayCritical(env, src, jpegBuf, 0); + return; } static void TJDecompressor_decodeYUV - (JNIEnv *env, jobject obj, jbyteArray src, jint pad, jint subsamp, - jarray dst, jint dstElementSize, jint x, jint y, jint width, jint pitch, - jint height, jint pf, jint flags) + (JNIEnv *env, jobject obj, jobjectArray srcobjs, jintArray jSrcOffsets, + jintArray jSrcStrides, jint subsamp, jarray dst, jint dstElementSize, + jint x, jint y, jint width, jint pitch, jint height, jint pf, jint flags) { tjhandle handle=0; jsize arraySize=0, actualPitch; - unsigned char *srcBuf=NULL, *dstBuf=NULL; + jbyteArray jSrcPlanes[3]={NULL, NULL, NULL}; + unsigned char *srcPlanes[3], *dstBuf=NULL; + int *srcOffsets=NULL, *srcStrides=NULL; + int nc=(subsamp==org_libjpegturbo_turbojpeg_TJ_SAMP_GRAY? 1:3), i; gethandle(); - if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF) + if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF || subsamp<0 + || subsamp>=org_libjpegturbo_turbojpeg_TJ_NUMSAMP) _throw("Invalid argument in decodeYUV()"); - if(org_libjpegturbo_turbojpeg_TJ_NUMPF!=TJ_NUMPF) + if(org_libjpegturbo_turbojpeg_TJ_NUMPF!=TJ_NUMPF + || org_libjpegturbo_turbojpeg_TJ_NUMSAMP!=TJ_NUMSAMP) _throw("Mismatch between Java and C API"); - arraySize=tjBufSizeYUV2(width, pad, height, subsamp); - if((*env)->GetArrayLength(env, src)GetArrayLength(env, srcobjs)GetArrayLength(env, jSrcOffsets)GetArrayLength(env, jSrcStrides)GetArrayLength(env, dst)*dstElementSizeGetPrimitiveArrayCritical(env, src, 0)); + bailif0(srcOffsets=(*env)->GetPrimitiveArrayCritical(env, jSrcOffsets, 0)); + bailif0(srcStrides=(*env)->GetPrimitiveArrayCritical(env, jSrcStrides, 0)); + for(i=0; iGetObjectArrayElement(env, srcobjs, i)); + if((*env)->GetArrayLength(env, jSrcPlanes[i])GetPrimitiveArrayCritical(env, jSrcPlanes[i], + 0)); + srcPlanes[i]=&srcPlanes[i][srcOffsets[i]]; + } bailif0(dstBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); - if(tjDecodeYUV(handle, srcBuf, pad, subsamp, + if(tjDecodeYUVPlanes(handle, srcPlanes, srcStrides, subsamp, &dstBuf[y*actualPitch + x*tjPixelSize[pf]], width, pitch, height, pf, flags)==-1) _throw(tjGetErrorStr()); bailout: if(dstBuf) (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); - if(srcBuf) (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0); + for(i=0; iReleasePrimitiveArrayCritical(env, jSrcPlanes[i], srcPlanes[i], + 0); + } + if(srcStrides) + (*env)->ReleasePrimitiveArrayCritical(env, jSrcStrides, srcStrides, 0); + if(srcOffsets) + (*env)->ReleasePrimitiveArrayCritical(env, jSrcOffsets, srcOffsets, 0); return; } /* TurboJPEG 1.4.x: TJDecompressor::decodeYUV() byte destination */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3BII_3BIIIIIII - (JNIEnv *env, jobject obj, jbyteArray src, jint pad, jint subsamp, - jbyteArray dst, jint x, jint y, jint width, jint pitch, jint height, - jint pf, jint flags) +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3_3B_3I_3II_3BIIIIIII + (JNIEnv *env, jobject obj, jobjectArray srcobjs, jintArray jSrcOffsets, + jintArray jSrcStrides, jint subsamp, jbyteArray dst, jint x, jint y, + jint width, jint pitch, jint height, jint pf, jint flags) { - TJDecompressor_decodeYUV(env, obj, src, pad, subsamp, dst, 1, x, y, width, - pitch, height, pf, flags); + TJDecompressor_decodeYUV(env, obj, srcobjs, jSrcOffsets, jSrcStrides, + subsamp, dst, 1, x, y, width, pitch, height, pf, flags); } /* TurboJPEG 1.4.x: TJDecompressor::decodeYUV() int destination */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3BII_3IIIIIIII - (JNIEnv *env, jobject obj, jbyteArray src, jint pad, jint subsamp, - jintArray dst, jint x, jint y, jint width, jint stride, jint height, - jint pf, jint flags) +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3_3B_3I_3II_3IIIIIIII + (JNIEnv *env, jobject obj, jobjectArray srcobjs, jintArray jSrcOffsets, + jintArray jSrcStrides, jint subsamp, jintArray dst, jint x, jint y, + jint width, jint stride, jint height, jint pf, jint flags) { if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF) _throw("Invalid argument in decodeYUV()"); if(tjPixelSize[pf]!=sizeof(jint)) _throw("Pixel format must be 32-bit when decoding to an integer buffer."); - TJDecompressor_decodeYUV(env, obj, src, pad, subsamp, dst, sizeof(jint), x, - y, width, stride*sizeof(jint), height, pf, flags); + TJDecompressor_decodeYUV(env, obj, srcobjs, jSrcOffsets, jSrcStrides, + subsamp, dst, sizeof(jint), x, y, width, stride*sizeof(jint), height, pf, + flags); bailout: return; diff --git a/turbojpeg-mapfile.jni b/turbojpeg-mapfile.jni index 31c8ae0..3370d1f 100755 --- a/turbojpeg-mapfile.jni +++ b/turbojpeg-mapfile.jni @@ -77,10 +77,13 @@ TURBOJPEG_1.4 tjEncodeYUV3; tjEncodeYUVPlanes; Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__IIII; - Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFromYUV___3BIIII_3BII; - Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIIIII_3BIII; - Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIIIII_3BIII; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3BIIII; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3BII_3BIIIIIII; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3BII_3IIIIIIII; + Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFromYUV___3_3B_3II_3III_3BII; + Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIIIII_3_3B_3I_3III; + Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIIIII_3_3B_3I_3III; + Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3_3B_3II_3III; + Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3_3B_3I_3II_3BIIIIIII; + Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3_3B_3I_3II_3IIIIIIII; + Java_org_libjpegturbo_turbojpeg_TJ_planeHeight__III; + Java_org_libjpegturbo_turbojpeg_TJ_planeSizeYUV__IIIII; + Java_org_libjpegturbo_turbojpeg_TJ_planeWidth__III; } TURBOJPEG_1.3; diff --git a/turbojpeg.c b/turbojpeg.c index 926f633..0daa86a 100644 --- a/turbojpeg.c +++ b/turbojpeg.c @@ -579,15 +579,19 @@ DLLEXPORT unsigned long DLLCALL TJBUFSIZE(int width, int height) DLLEXPORT unsigned long DLLCALL tjBufSizeYUV2(int width, int pad, int height, int subsamp) { - unsigned long retval=0; - int pw, ph, cw, ch; - if(width<1 || height<1 || pad<1 || !isPow2(pad) || subsamp<0 - || subsamp>=NUMSUBOPT) + int retval=0, nc, i; + + if(subsamp<0 || subsamp>=NUMSUBOPT) _throw("tjBufSizeYUV2(): Invalid argument"); - pw=PAD(width, tjMCUWidth[subsamp]/8); - ph=PAD(height, tjMCUHeight[subsamp]/8); - cw=pw*8/tjMCUWidth[subsamp]; ch=ph*8/tjMCUHeight[subsamp]; - retval=PAD(pw, pad)*ph + (subsamp==TJSAMP_GRAY? 0:PAD(cw, pad)*ch*2); + + nc=(subsamp==TJSAMP_GRAY? 1:3); + for(i=0; i=TJ_NUMSAMP) + _throw("tjPlaneWidth(): Invalid argument"); + nc=(subsamp==TJSAMP_GRAY? 1:3); + if(componentID<0 || componentID>=nc) + _throw("tjPlaneWidth(): Invalid argument"); + + pw=PAD(width, tjMCUWidth[subsamp]/8); + if(componentID==0) + retval=pw; + else + retval=pw*8/tjMCUWidth[subsamp]; + + bailout: + return retval; +} + + +DLLEXPORT int tjPlaneHeight(int componentID, int height, int subsamp) +{ + int ph, nc, retval=0; + + if(height<1 || subsamp<0 || subsamp>=TJ_NUMSAMP) + _throw("tjPlaneHeight(): Invalid argument"); + nc=(subsamp==TJSAMP_GRAY? 1:3); + if(componentID<0 || componentID>=nc) + _throw("tjPlaneHeight(): Invalid argument"); + + ph=PAD(height, tjMCUHeight[subsamp]/8); + if(componentID==0) + retval=ph; + else + retval=ph*8/tjMCUHeight[subsamp]; + + bailout: + return retval; +} + + +DLLEXPORT unsigned long DLLCALL tjPlaneSizeYUV(int componentID, int width, + int stride, int height, int subsamp) +{ + unsigned long retval=0; + int pw, ph; + + if(width<1 || height<1 || subsamp<0 || subsamp>=NUMSUBOPT) + _throw("tjPlaneSizeYUV(): Invalid argument"); + + pw=tjPlaneWidth(componentID, width, subsamp); + ph=tjPlaneHeight(componentID, height, subsamp); + + if(stride==0) stride=pw; + else stride=abs(stride); + + retval=stride*(ph-1)+pw; + + bailout: + return retval; +} + + 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) @@ -712,7 +780,7 @@ DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle, unsigned char *srcBuf, JSAMPLE *_tmpbuf[MAX_COMPONENTS], *_tmpbuf2[MAX_COMPONENTS]; JSAMPROW *tmpbuf[MAX_COMPONENTS], *tmpbuf2[MAX_COMPONENTS]; JSAMPROW *outbuf[MAX_COMPONENTS]; - int row, pw, ph, cw[MAX_COMPONENTS], ch[MAX_COMPONENTS]; + int row, pw0, ph0, pw[MAX_COMPONENTS], ph[MAX_COMPONENTS]; JSAMPLE *ptr; jpeg_component_info *compptr; #ifndef JCS_EXTENSIONS @@ -780,18 +848,18 @@ DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle, unsigned char *srcBuf, jinit_downsampler(cinfo); (*cinfo->cconvert->start_pass)(cinfo); - pw=PAD(width, cinfo->max_h_samp_factor); - ph=PAD(height, cinfo->max_v_samp_factor); + pw0=PAD(width, cinfo->max_h_samp_factor); + ph0=PAD(height, cinfo->max_v_samp_factor); - if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph))==NULL) + if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph0))==NULL) _throw("tjEncodeYUVPlanes(): Memory allocation failure"); for(i=0; inum_components; i++) { @@ -822,19 +890,19 @@ DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle, unsigned char *srcBuf, tmpbuf2[i][row]=&_tmpbuf2_aligned[ PAD(compptr->width_in_blocks*DCTSIZE, 16) * row]; } - cw[i]=pw*compptr->h_samp_factor/cinfo->max_h_samp_factor; - ch[i]=ph*compptr->v_samp_factor/cinfo->max_v_samp_factor; - outbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ch[i]); + pw[i]=pw0*compptr->h_samp_factor/cinfo->max_h_samp_factor; + ph[i]=ph0*compptr->v_samp_factor/cinfo->max_v_samp_factor; + outbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph[i]); if(!outbuf[i]) _throw("tjEncodeYUVPlanes(): Memory allocation failure"); ptr=dstPlanes[i]; - for(row=0; row0)? strides[i]:cw[i]; + ptr+=(strides && strides[i]!=0)? strides[i]:pw[i]; } } - for(row=0; rowmax_v_samp_factor) + for(row=0; rowmax_v_samp_factor) { (*cinfo->cconvert->color_convert)(cinfo, &row_pointer[row], tmpbuf, 0, cinfo->max_v_samp_factor); @@ -842,7 +910,7 @@ DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle, unsigned char *srcBuf, for(i=0, compptr=cinfo->comp_info; inum_components; i++, compptr++) jcopy_sample_rows(tmpbuf2[i], 0, outbuf[i], row*compptr->v_samp_factor/cinfo->max_v_samp_factor, - compptr->v_samp_factor, cw[i]); + compptr->v_samp_factor, pw[i]); } cinfo->next_scanline+=height; jpeg_abort_compress(cinfo); @@ -869,21 +937,29 @@ DLLEXPORT int DLLCALL tjEncodeYUV3(tjhandle handle, unsigned char *srcBuf, int pad, int subsamp, int flags) { unsigned char *dstPlanes[3]; - int pw, ph, cw, ch, strides[3], retval=-1; + int pw0, ph0, strides[3], retval=-1; if(width<=0 || height<=0 || dstBuf==NULL || pad<0 || !isPow2(pad) || subsamp<0 || subsamp>=NUMSUBOPT) _throw("tjEncodeYUV3(): Invalid argument"); - pw=PAD(width, tjMCUWidth[subsamp]/8); - ph=PAD(height, tjMCUHeight[subsamp]/8); - cw=pw*8/tjMCUWidth[subsamp]; ch=ph*8/tjMCUHeight[subsamp]; - - strides[0]=PAD(pw, pad); - strides[1]=strides[2]=(subsamp==TJSAMP_GRAY? 0:PAD(cw, pad)); + pw0=tjPlaneWidth(0, width, subsamp); + ph0=tjPlaneHeight(0, height, subsamp); dstPlanes[0]=dstBuf; - dstPlanes[1]=(subsamp==TJSAMP_GRAY? NULL:dstPlanes[0]+strides[0]*ph); - dstPlanes[2]=(subsamp==TJSAMP_GRAY? NULL:dstPlanes[1]+strides[1]*ch); + strides[0]=PAD(pw0, pad); + if(subsamp==TJSAMP_GRAY) + { + strides[1]=strides[2]=0; + dstPlanes[1]=dstPlanes[2]=NULL; + } + else + { + int pw1=tjPlaneWidth(1, width, subsamp); + int ph1=tjPlaneHeight(1, height, subsamp); + strides[1]=strides[2]=PAD(pw1, pad); + dstPlanes[1]=dstPlanes[0]+strides[0]*ph0; + dstPlanes[2]=dstPlanes[1]+strides[1]*ph1; + } return tjEncodeYUVPlanes(handle, srcBuf, width, pitch, height, pixelFormat, dstPlanes, strides, subsamp, flags); @@ -914,7 +990,7 @@ DLLEXPORT int DLLCALL tjCompressFromYUVPlanes(tjhandle handle, unsigned char **jpegBuf, unsigned long *jpegSize, int jpegQual, int flags) { int i, row, retval=0, alloc=1; JSAMPROW *inbuf[MAX_COMPONENTS]; - int cw[MAX_COMPONENTS], ch[MAX_COMPONENTS], iw[MAX_COMPONENTS], + int pw[MAX_COMPONENTS], ph[MAX_COMPONENTS], iw[MAX_COMPONENTS], tmpbufsize=0, usetmpbuf=0, th[MAX_COMPONENTS]; JSAMPLE *_tmpbuf=NULL, *ptr; JSAMPROW *tmpbuf[MAX_COMPONENTS]; @@ -965,20 +1041,20 @@ DLLEXPORT int DLLCALL tjCompressFromYUVPlanes(tjhandle handle, int ih; iw[i]=compptr->width_in_blocks*DCTSIZE; ih=compptr->height_in_blocks*DCTSIZE; - cw[i]=PAD(cinfo->image_width, cinfo->max_h_samp_factor) + pw[i]=PAD(cinfo->image_width, cinfo->max_h_samp_factor) *compptr->h_samp_factor/cinfo->max_h_samp_factor; - ch[i]=PAD(cinfo->image_height, cinfo->max_v_samp_factor) + ph[i]=PAD(cinfo->image_height, cinfo->max_v_samp_factor) *compptr->v_samp_factor/cinfo->max_v_samp_factor; - if(iw[i]!=cw[i] || ih!=ch[i]) usetmpbuf=1; + if(iw[i]!=pw[i] || ih!=ph[i]) usetmpbuf=1; th[i]=compptr->v_samp_factor*DCTSIZE; tmpbufsize+=iw[i]*th[i]; - if((inbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ch[i]))==NULL) + if((inbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph[i]))==NULL) _throw("tjCompressFromYUVPlanes(): Memory allocation failure"); ptr=srcPlanes[i]; - for(row=0; row0)? strides[i]:cw[i]; + ptr+=(strides && strides[i]!=0)? strides[i]:pw[i]; } } if(usetmpbuf) @@ -1010,15 +1086,15 @@ DLLEXPORT int DLLCALL tjCompressFromYUVPlanes(tjhandle handle, if(usetmpbuf) { int j, k; - for(j=0; j=NUMSUBOPT) _throw("tjCompressFromYUV(): Invalid argument"); - pw=PAD(width, tjMCUWidth[subsamp]/8); - ph=PAD(height, tjMCUHeight[subsamp]/8); - cw=pw*8/tjMCUWidth[subsamp]; ch=ph*8/tjMCUHeight[subsamp]; - - strides[0]=PAD(pw, pad); - strides[1]=strides[2]=(subsamp==TJSAMP_GRAY? 0:PAD(cw, pad)); + pw0=tjPlaneWidth(0, width, subsamp); + ph0=tjPlaneHeight(0, height, subsamp); srcPlanes[0]=srcBuf; - srcPlanes[1]=(subsamp==TJSAMP_GRAY? NULL:srcPlanes[0]+strides[0]*ph); - srcPlanes[2]=(subsamp==TJSAMP_GRAY? NULL:srcPlanes[1]+strides[1]*ch); + strides[0]=PAD(pw0, pad); + if(subsamp==TJSAMP_GRAY) + { + strides[1]=strides[2]=0; + srcPlanes[1]=srcPlanes[2]=NULL; + } + else + { + int pw1=tjPlaneWidth(1, width, subsamp); + int ph1=tjPlaneHeight(1, height, subsamp); + strides[1]=strides[2]=PAD(pw1, pad); + srcPlanes[1]=srcPlanes[0]+strides[0]*ph0; + srcPlanes[2]=srcPlanes[1]+strides[1]*ph1; + } return tjCompressFromYUVPlanes(handle, srcPlanes, width, strides, height, subsamp, jpegBuf, jpegSize, jpegQual, flags); @@ -1361,7 +1445,7 @@ DLLEXPORT int DLLCALL tjDecodeYUVPlanes(tjhandle handle, int i, retval=0; JSAMPROW *row_pointer=NULL; JSAMPLE *_tmpbuf[MAX_COMPONENTS]; JSAMPROW *tmpbuf[MAX_COMPONENTS], *inbuf[MAX_COMPONENTS]; - int row, pw, ph, cw[MAX_COMPONENTS], ch[MAX_COMPONENTS]; + int row, pw0, ph0, pw[MAX_COMPONENTS], ph[MAX_COMPONENTS]; JSAMPLE *ptr; jpeg_component_info *compptr; #ifndef JCS_EXTENSIONS @@ -1426,8 +1510,8 @@ DLLEXPORT int DLLCALL tjDecodeYUVPlanes(tjhandle handle, jinit_master_decompress(dinfo); (*dinfo->upsample->start_pass)(dinfo); - pw=PAD(width, dinfo->max_h_samp_factor); - ph=PAD(height, dinfo->max_v_samp_factor); + pw0=PAD(width, dinfo->max_h_samp_factor); + ph0=PAD(height, dinfo->max_v_samp_factor); if(pitch==0) pitch=dinfo->output_width*tjPixelSize[pixelFormat]; @@ -1445,15 +1529,15 @@ DLLEXPORT int DLLCALL tjDecodeYUVPlanes(tjhandle handle, } #endif - if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph))==NULL) + if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph0))==NULL) _throw("tjDecodeYUVPlanes(): Memory allocation failure"); for(i=0; inum_components; i++) { @@ -1470,25 +1554,25 @@ DLLEXPORT int DLLCALL tjDecodeYUVPlanes(tjhandle handle, tmpbuf[i][row]=&_tmpbuf_aligned[ PAD(compptr->width_in_blocks*DCTSIZE, 16) * row]; } - cw[i]=pw*compptr->h_samp_factor/dinfo->max_h_samp_factor; - ch[i]=ph*compptr->v_samp_factor/dinfo->max_v_samp_factor; - inbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ch[i]); + pw[i]=pw0*compptr->h_samp_factor/dinfo->max_h_samp_factor; + ph[i]=ph0*compptr->v_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]; - for(row=0; row0)? strides[i]:cw[i]; + ptr+=(strides && strides[i]!=0)? strides[i]:pw[i]; } } - for(row=0; rowmax_v_samp_factor) + for(row=0; rowmax_v_samp_factor) { JDIMENSION inrow=0, outrow=0; for(i=0, compptr=dinfo->comp_info; inum_components; i++, compptr++) jcopy_sample_rows(inbuf[i], row*compptr->v_samp_factor/dinfo->max_v_samp_factor, tmpbuf[i], 0, - compptr->v_samp_factor, cw[i]); + compptr->v_samp_factor, pw[i]); (dinfo->upsample->upsample)(dinfo, tmpbuf, &inrow, dinfo->max_v_samp_factor, &row_pointer[row], &outrow, dinfo->max_v_samp_factor); @@ -1519,21 +1603,29 @@ DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf, int height, int pixelFormat, int flags) { unsigned char *srcPlanes[3]; - int pw, ph, cw, ch, strides[3], retval=-1; + int pw0, ph0, strides[3], retval=-1; if(srcBuf==NULL || pad<0 || !isPow2(pad) || subsamp<0 || subsamp>=NUMSUBOPT || width<=0 || height<=0) _throw("tjDecodeYUV(): Invalid argument"); - pw=PAD(width, tjMCUWidth[subsamp]/8); - ph=PAD(height, tjMCUHeight[subsamp]/8); - cw=pw*8/tjMCUWidth[subsamp]; ch=ph*8/tjMCUHeight[subsamp]; - - strides[0]=PAD(pw, pad); - strides[1]=strides[2]=(subsamp==TJSAMP_GRAY? 0:PAD(cw, pad)); + pw0=tjPlaneWidth(0, width, subsamp); + ph0=tjPlaneHeight(0, height, subsamp); srcPlanes[0]=srcBuf; - srcPlanes[1]=(subsamp==TJSAMP_GRAY? NULL:srcPlanes[0]+strides[0]*ph); - srcPlanes[2]=(subsamp==TJSAMP_GRAY? NULL:srcPlanes[1]+strides[1]*ch); + strides[0]=PAD(pw0, pad); + if(subsamp==TJSAMP_GRAY) + { + strides[1]=strides[2]=0; + srcPlanes[1]=srcPlanes[2]=NULL; + } + else + { + int pw1=tjPlaneWidth(1, width, subsamp); + int ph1=tjPlaneHeight(1, height, subsamp); + strides[1]=strides[2]=PAD(pw1, pad); + srcPlanes[1]=srcPlanes[0]+strides[0]*ph0; + srcPlanes[2]=srcPlanes[1]+strides[1]*ph1; + } return tjDecodeYUVPlanes(handle, srcPlanes, strides, subsamp, dstBuf, width, pitch, height, pixelFormat, flags); @@ -1548,7 +1640,7 @@ DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle, { int i, sfi, row, retval=0; JSAMPROW *outbuf[MAX_COMPONENTS]; int jpegwidth, jpegheight, jpegSubsamp, scaledw, scaledh; - int cw[MAX_COMPONENTS], ch[MAX_COMPONENTS], iw[MAX_COMPONENTS], + int pw[MAX_COMPONENTS], ph[MAX_COMPONENTS], iw[MAX_COMPONENTS], tmpbufsize=0, usetmpbuf=0, th[MAX_COMPONENTS]; JSAMPLE *_tmpbuf=NULL, *ptr; JSAMPROW *tmpbuf[MAX_COMPONENTS]; int dctsize; @@ -1620,20 +1712,20 @@ DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle, int ih; iw[i]=compptr->width_in_blocks*dctsize; ih=compptr->height_in_blocks*dctsize; - cw[i]=PAD(dinfo->output_width, dinfo->max_h_samp_factor) + pw[i]=PAD(dinfo->output_width, dinfo->max_h_samp_factor) *compptr->h_samp_factor/dinfo->max_h_samp_factor; - ch[i]=PAD(dinfo->output_height, dinfo->max_v_samp_factor) + ph[i]=PAD(dinfo->output_height, dinfo->max_v_samp_factor) *compptr->v_samp_factor/dinfo->max_v_samp_factor; - if(iw[i]!=cw[i] || ih!=ch[i]) usetmpbuf=1; + if(iw[i]!=pw[i] || ih!=ph[i]) usetmpbuf=1; th[i]=compptr->v_samp_factor*dctsize; tmpbufsize+=iw[i]*th[i]; - if((outbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ch[i]))==NULL) + if((outbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph[i]))==NULL) _throw("tjDecompressToYUVPlanes(): Memory allocation failure"); ptr=dstPlanes[i]; - for(row=0; row0)? strides[i]:cw[i]; + ptr+=(strides && strides[i]!=0)? strides[i]:pw[i]; } } if(usetmpbuf) @@ -1695,9 +1787,9 @@ DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle, int j; for(i=0; inum_components; i++) { - for(j=0; jwidth || scaledh>height) _throw("tjDecompressToYUV2(): Could not scale down to desired image dimensions"); - pw=PAD(scaledw, tjMCUWidth[jpegSubsamp]/8); - ph=PAD(scaledh, tjMCUHeight[jpegSubsamp]/8); - cw=pw*8/tjMCUWidth[jpegSubsamp]; ch=ph*8/tjMCUHeight[jpegSubsamp]; - - strides[0]=PAD(pw, pad); - strides[1]=strides[2]=(jpegSubsamp==TJSAMP_GRAY? 0:PAD(cw, pad)); + pw0=tjPlaneWidth(0, width, jpegSubsamp); + ph0=tjPlaneHeight(0, height, jpegSubsamp); dstPlanes[0]=dstBuf; - dstPlanes[1]=(jpegSubsamp==TJSAMP_GRAY? NULL:dstPlanes[0]+strides[0]*ph); - dstPlanes[2]=(jpegSubsamp==TJSAMP_GRAY? NULL:dstPlanes[1]+strides[1]*ch); + strides[0]=PAD(pw0, pad); + if(jpegSubsamp==TJSAMP_GRAY) + { + strides[1]=strides[2]=0; + dstPlanes[1]=dstPlanes[2]=NULL; + } + else + { + int pw1=tjPlaneWidth(1, width, jpegSubsamp); + int ph1=tjPlaneHeight(1, height, jpegSubsamp); + strides[1]=strides[2]=PAD(pw1, pad); + dstPlanes[1]=dstPlanes[0]+strides[0]*ph0; + dstPlanes[2]=dstPlanes[1]+strides[1]*ph1; + } this->headerRead=1; return tjDecompressToYUVPlanes(handle, jpegBuf, jpegSize, dstPlanes, width, diff --git a/turbojpeg.h b/turbojpeg.h index 0ba7070..2505100 100644 --- a/turbojpeg.h +++ b/turbojpeg.h @@ -52,20 +52,18 @@ * * Each plane is simply a 2D array of bytes, each byte representing the value * of one of the components (Y, Cb, or Cr) at a particular location in the - * image. The "component width" and "component height" of each plane are - * determined by the image width, height, and level of chrominance subsampling. - * For the luminance plane, the component width is the image width padded to - * the nearest multiple of the horizontal subsampling factor (2 in the case of - * 4:2:0 and 4:2:2, 4 in the case of 4:1:1, 1 in the case of 4:4:4 or - * grayscale.) Similarly, the component height of the luminance plane is the - * image height padded to the nearest multiple of the vertical subsampling - * factor (2 in the case of 4:2:0 or 4:4:0, 1 in the case of 4:4:4 or - * grayscale.) This is irrespective of any additional padding that may be - * specified as an argument to the various YUV functions. The component width - * of the chrominance planes is equal to the component width of the luminance - * plane divided by the horizontal subsampling factor, and the component height - * of the chrominance planes is equal to the component height of the luminance - * plane divided by the vertical subsampling factor. + * image. The width and height of each plane are determined by the image + * width, height, and level of chrominance subsampling. The luminance plane + * width is the image width padded to the nearest multiple of the horizontal + * subsampling factor (2 in the case of 4:2:0 and 4:2:2, 4 in the case of + * 4:1:1, 1 in the case of 4:4:4 or grayscale.) Similarly, the luminance plane + * height is the image height padded to the nearest multiple of the vertical + * subsampling factor (2 in the case of 4:2:0 or 4:4:0, 1 in the case of 4:4:4 + * or grayscale.) This is irrespective of any additional padding that may be + * specified as an argument to the various YUV functions. The chrominance + * plane width is equal to the luminance plane width divided by the horizontal + * subsampling factor, and the chrominance plane height is equal to the + * luminance plane height divided by the vertical subsampling factor. * * For example, if the source image is 35 x 35 pixels and 4:2:2 subsampling is * used, then the luminance plane would be 36 x 35 bytes, and each of the @@ -625,7 +623,7 @@ DLLEXPORT tjhandle DLLCALL tjInitCompress(void); * * @param width width (in pixels) of the source image * - * @param pitch bytes per line of the source image. Normally, this should be + * @param pitch bytes 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 @@ -668,7 +666,7 @@ DLLEXPORT tjhandle DLLCALL tjInitCompress(void); * 100 = best) * * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP - * "flags". + * "flags" * * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ @@ -730,7 +728,7 @@ DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf, * 100 = best) * * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP - * "flags". + * "flags" * * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ @@ -747,10 +745,10 @@ DLLEXPORT int DLLCALL tjCompressFromYUV(tjhandle handle, unsigned char *srcBuf, * @param srcPlanes an 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. Each plane should be at least - * {component stride} * {component height} bytes in size. (See - * below for a description of stride, and refer to @ref YUVnotes - * "YUV Image Format Notes" for a description of component height.) + * 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. * * @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 @@ -758,11 +756,12 @@ DLLEXPORT int DLLCALL tjCompressFromYUV(tjhandle handle, unsigned char *srcBuf, * * @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 - * for any plane to 0 is the same as setting it to the component width for the - * plane. If strides is NULL, then the strides for all planes will be - * set to their respective component 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. + * for any plane to 0 is the same as setting it to the plane width (see + * @ref YUVnotes "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. * * @param height height (in pixels) of the source image. If the height is not * an even multiple of the MCU block height (see #tjMCUHeight), then an @@ -797,7 +796,7 @@ DLLEXPORT int DLLCALL tjCompressFromYUV(tjhandle handle, unsigned char *srcBuf, * 100 = best) * * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP - * "flags". + * "flags" * * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ @@ -817,9 +816,9 @@ DLLEXPORT int DLLCALL tjCompressFromYUVPlanes(tjhandle handle, * size of a JPEG image prior to compression, the corner case has to be * handled. * - * @param width width of the image (in pixels) + * @param width width (in pixels) of the image * - * @param height height of the image (in pixels) + * @param height height (in pixels) of the image * * @param jpegSubsamp the level of chrominance subsampling to be used when * generating the JPEG image (see @ref TJSAMP @@ -836,12 +835,12 @@ DLLEXPORT unsigned long DLLCALL tjBufSize(int width, int height, * The size of the buffer (in bytes) required to hold a YUV planar image with * the given parameters. * - * @param width width of the image (in pixels) + * @param width width (in pixels) of the image * * @param pad the width of each line in each plane of the image is padded to * the nearest multiple of this number of bytes (must be a power of 2.) * - * @param height height of the image (in pixels) + * @param height height (in pixels) of the image * * @param subsamp level of chrominance subsampling in the image (see * @ref TJSAMP "Chrominance subsampling options".) @@ -853,6 +852,65 @@ DLLEXPORT unsigned long DLLCALL tjBufSizeYUV2(int width, int pad, int height, int subsamp); +/** + * The size of the buffer (in bytes) required to hold a YUV image plane with + * the given parameters. + * + * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr) + * + * @param width width (in pixels) of the YUV image. NOTE: this is the width of + * the whole image, not the plane width. + * + * @param stride bytes per line in the image plane. Setting this to 0 is the + * equivalent of setting it to the plane width. + * + * @param height height (in pixels) of the YUV image. NOTE: this is the height + * of the whole image, not the plane height. + * + * @param subsamp level of chrominance subsampling in the image (see + * @ref TJSAMP "Chrominance subsampling options".) + * + * @return the size of the buffer (in bytes) required to hold the YUV image + * plane, or -1 if the arguments are out of bounds. + */ +DLLEXPORT unsigned long DLLCALL tjPlaneSizeYUV(int componentID, int width, + int stride, int height, int subsamp); + + +/** + * The plane width of a YUV image plane with the given parameters. Refer to + * @ref YUVnotes "YUV Image Format Notes" for a description of plane width. + * + * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr) + * + * @param width width (in pixels) of the YUV image + * + * @param subsamp level of chrominance subsampling in the image (see + * @ref TJSAMP "Chrominance subsampling options".) + * + * @return the plane width of a YUV image plane with the given parameters, or + * -1 if the arguments are out of bounds. + */ +DLLEXPORT int tjPlaneWidth(int componentID, int width, int subsamp); + + +/** + * The plane height of a YUV image plane with the given parameters. Refer to + * @ref YUVnotes "YUV Image Format Notes" for a description of plane height. + * + * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr) + * + * @param height height (in pixels) of the YUV image + * + * @param subsamp level of chrominance subsampling in the image (see + * @ref TJSAMP "Chrominance subsampling options".) + * + * @return the plane height of a YUV image plane with the given parameters, or + * -1 if the arguments are out of bounds. + */ +DLLEXPORT int tjPlaneHeight(int componentID, int height, int subsamp); + + /** * Encode an RGB or grayscale image into a YUV planar image. This function * uses the accelerated color conversion routines in the underlying @@ -866,7 +924,7 @@ DLLEXPORT unsigned long DLLCALL tjBufSizeYUV2(int width, int pad, int height, * * @param width width (in pixels) of the source image * - * @param pitch bytes per line of the source image. Normally, this should be + * @param pitch bytes 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 @@ -897,7 +955,7 @@ DLLEXPORT unsigned long DLLCALL tjBufSizeYUV2(int width, int pad, int height, * image compatible with the I420 (AKA "YUV420P") format. * * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP - * "flags". + * "flags" * * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ @@ -919,7 +977,7 @@ DLLEXPORT int DLLCALL tjEncodeYUV3(tjhandle handle, * * @param width width (in pixels) of the source image * - * @param pitch bytes per line of the source image. Normally, this should be + * @param pitch bytes 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 @@ -935,18 +993,18 @@ DLLEXPORT int DLLCALL tjEncodeYUV3(tjhandle handle, * @param dstPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes * (or just a Y plane, if generating a grayscale image) that will receive the * encoded image. These planes can be contiguous or non-contiguous in memory. - * Each plane should be at least - * {component stride} * {component height} bytes in size. - * (See below for a description of stride, and refer to @ref YUVnotes - * "YUV Image Format Notes" for a description of component height.) + * Use #tjPlaneSizeYUV() to determine the appropriate size for each plane based + * on the image width, height, strides, and level of chrominance subsampling. + * Refer to @ref YUVnotes "YUV Image Format Notes" for more details. * * @param strides an array of integers, each specifying the number of bytes per * line in the corresponding plane of the output image. Setting the stride for - * any plane to 0 is the same as setting it to the component width for the - * plane. If strides is NULL, then the strides for all planes will be - * set to their respective component widths. You can adjust the strides in - * order to add an arbitrary amount of line padding to each plane or to encode - * an RGB or grayscale image into a subregion of a larger YUV planar image. + * any plane to 0 is the same as setting it to the plane width (see + * @ref YUVnotes "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 add an arbitrary amount of line + * padding to each plane or to encode an RGB or grayscale image into a + * subregion of a larger YUV planar image. * * @param subsamp the level of chrominance subsampling to be used when * generating the YUV image (see @ref TJSAMP @@ -955,7 +1013,7 @@ DLLEXPORT int DLLCALL tjEncodeYUV3(tjhandle handle, * image compatible with the I420 (AKA "YUV420P") format. * * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP - * "flags". + * "flags" * * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ @@ -989,8 +1047,8 @@ DLLEXPORT tjhandle DLLCALL tjInitDecompress(void); * (in pixels) of the JPEG image * * @param jpegSubsamp pointer to an integer variable that will receive the - * level of chrominance subsampling used when compressing the JPEG image (see - * @ref TJSAMP "Chrominance subsampling options".) + * level of chrominance subsampling used when the JPEG image was compressed + * (see @ref TJSAMP "Chrominance subsampling options".) * * @param jpegColorspace pointer to an integer variable that will receive one * of the JPEG colorspace constants, indicating the colorspace of the JPEG @@ -1039,7 +1097,7 @@ DLLEXPORT tjscalingfactor* DLLCALL tjGetScalingFactors(int *numscalingfactors); * set to 0, then only the height will be considered when determining the * scaled image size. * - * @param pitch bytes per line of the destination image. Normally, this is + * @param pitch bytes per line in the destination image. Normally, this is * scaledWidth * #tjPixelSize[pixelFormat] if the decompressed image * is unpadded, else #TJPAD(scaledWidth * #tjPixelSize[pixelFormat]) * if each line of the decompressed image is padded to the nearest 32-bit @@ -1061,7 +1119,7 @@ DLLEXPORT tjscalingfactor* DLLCALL tjGetScalingFactors(int *numscalingfactors); * TJPF "Pixel formats".) * * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP - * "flags". + * "flags" * * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ @@ -1111,7 +1169,7 @@ DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle, * performed within TurboJPEG. * * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP - * "flags". + * "flags" * * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ @@ -1134,10 +1192,10 @@ DLLEXPORT int DLLCALL tjDecompressToYUV2(tjhandle handle, * @param dstPlanes an 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. - * Each plane should be at least - * {component stride} * {scaled component height} bytes in size. - * (See below for a description of stride, and refer to @ref YUVnotes - * "YUV Image Format Notes" for a description of component height.) + * 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 @ref YUVnotes "YUV Image Format Notes" + * for more details. * * @param width desired width (in pixels) of the YUV image. If this is * different than the width of the JPEG image being decompressed, then @@ -1150,11 +1208,12 @@ DLLEXPORT int DLLCALL tjDecompressToYUV2(tjhandle handle, * * @param strides an array of integers, each specifying the number of bytes per * line in the corresponding plane of the output image. Setting the stride for - * any plane to 0 is the same as setting it to the scaled component width for - * the plane. If strides is NULL, then the strides for all planes - * will be set to their respective scaled component widths. You can adjust the - * strides in order to add an arbitrary amount of line padding to each plane or - * to decompress the JPEG image into a subregion of a larger YUV planar image. + * any plane to 0 is the same as setting it to the scaled plane width (see + * @ref YUVnotes "YUV Image Format Notes".) If strides is NULL, then + * the strides for all planes will be set to their respective scaled plane + * widths. You can adjust the strides in order to add an arbitrary amount of + * line padding to each plane or to decompress the JPEG image into a subregion + * of a larger YUV planar image. * * @param height desired height (in pixels) of the YUV image. If this is * different than the height of the JPEG image being decompressed, then @@ -1166,7 +1225,7 @@ DLLEXPORT int DLLCALL tjDecompressToYUV2(tjhandle handle, * performed within TurboJPEG. * * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP - * "flags". + * "flags" * * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ @@ -1204,7 +1263,7 @@ DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle, * * @param width width (in pixels) of the source and destination images * - * @param pitch bytes per line of the destination image. Normally, this should + * @param pitch bytes per line in the destination image. Normally, this should * be width * #tjPixelSize[pixelFormat] if the destination image is * unpadded, or #TJPAD(width * #tjPixelSize[pixelFormat]) if each line * of the destination image should be padded to the nearest 32-bit boundary, as @@ -1218,7 +1277,7 @@ DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle, * "Pixel formats".) * * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP - * "flags". + * "flags" * * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ @@ -1238,18 +1297,18 @@ DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf, * @param srcPlanes an 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. - * Each plane should be at least - * {component stride} * {component height} bytes in size. - * (See below for a description of stride, and refer to @ref YUVnotes - * "YUV Image Format Notes" for a description of component height.) + * 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. * * @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 - * for any plane to 0 is the same as setting it to the component width for the - * plane. If strides is NULL, then the strides for all planes will be - * set to their respective component 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. + * for any plane to 0 is the same as setting it to the plane width (see + * @ref YUVnotes "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. * * @param subsamp the level of chrominance subsampling used in the YUV source * image (see @ref TJSAMP "Chrominance subsampling options".) @@ -1261,7 +1320,7 @@ DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf, * * @param width width (in pixels) of the source and destination images * - * @param pitch bytes per line of the destination image. Normally, this should + * @param pitch bytes per line in the destination image. Normally, this should * be width * #tjPixelSize[pixelFormat] if the destination image is * unpadded, or #TJPAD(width * #tjPixelSize[pixelFormat]) if each line * of the destination image should be padded to the nearest 32-bit boundary, as @@ -1275,7 +1334,7 @@ DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf, * "Pixel formats".) * * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP - * "flags". + * "flags" * * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ @@ -1295,9 +1354,9 @@ DLLEXPORT tjhandle DLLCALL tjInitTransform(void); /** * Losslessly transform a JPEG image into another JPEG image. Lossless - * transforms work by moving the raw coefficients from one JPEG image structure - * to another without altering the values of the coefficients. While this is - * typically faster than decompressing the image, transforming it, and + * transforms work by moving the raw DCT coefficients from one JPEG image + * structure to another without altering the values of the coefficients. While + * this is typically faster than decompressing the image, transforming it, and * re-compressing it, lossless transforms are not free. Each lossless * transform requires reading and performing Huffman decoding on all of the * coefficients in the source image, regardless of the size of the destination @@ -1308,9 +1367,10 @@ DLLEXPORT tjhandle DLLCALL tjInitTransform(void); * * @param handle a handle to a TurboJPEG transformer instance * - * @param jpegBuf pointer to a buffer containing the JPEG image to transform + * @param jpegBuf pointer to a buffer containing the JPEG source image to + * transform * - * @param jpegSize size of the JPEG image (in bytes) + * @param jpegSize size of the JPEG source image (in bytes) * * @param n the number of transformed JPEG images to generate * @@ -1343,7 +1403,7 @@ DLLEXPORT tjhandle DLLCALL tjInitTransform(void); * corresponding transformed output image. * * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP - * "flags". + * "flags" * * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) */ @@ -1372,7 +1432,7 @@ DLLEXPORT int DLLCALL tjDestroy(tjhandle handle); * @param bytes the number of bytes to allocate * * @return a pointer to a newly-allocated buffer with the specified number of - * bytes + * bytes. * * @sa tjFree() */ -- 2.49.0