diff --git a/ChangeLog.md b/ChangeLog.md index 62a9b0cf..a00651ac 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,12 @@ 1. Fixed a regression introduced in 2.1.3 that caused build failures with Visual Studio 2010. +2. The `tjDecompressHeader3()` function in the TurboJPEG C API and the +`TJDecompressor.setSourceImage()` method in the TurboJPEG Java API now accept +"abbreviated table specification" (AKA "tables-only") datastreams, which can be +used to prime the decompressor with quantization and Huffman tables that can be +used when decompressing subsequent "abbreviated image" datastreams. + 2.1.3 ===== diff --git a/doc/html/annotated.html b/doc/html/annotated.html index b7773dd4..c735a5a7 100644 --- a/doc/html/annotated.html +++ b/doc/html/annotated.html @@ -23,7 +23,7 @@
*jpegSize should be set to the size of your
Retrieve information about a JPEG image without decompressing it.
+Retrieve information about a JPEG image without decompressing it, or prime the decompressor with quantization and Huffman tables.
| handle | a handle to a TurboJPEG decompressor or transformer instance |
| jpegBuf | pointer to a buffer containing a JPEG image |
| jpegSize | size of the JPEG image (in bytes) |
| width | pointer to an integer variable that will receive the width (in pixels) of the JPEG image |
| height | pointer to an integer variable that will receive the height (in pixels) of the JPEG image |
| jpegSubsamp | pointer to an integer variable that will receive the level of chrominance subsampling used when the JPEG image was compressed (see Chrominance subsampling options.) |
| jpegColorspace | pointer to an integer variable that will receive one of the JPEG colorspace constants, indicating the colorspace of the JPEG image (see JPEG colorspaces.) |
| jpegBuf | pointer to a buffer containing a JPEG image or an "abbreviated table specification" (AKA "tables-only") datastream. Passing a tables-only datastream to this function primes the decompressor with quantization and Huffman tables that can be used when decompressing subsequent "abbreviated image" datastreams. This is useful, for instance, when decompressing video streams in which all frames share the same quantization and Huffman tables. |
| jpegSize | size of the JPEG image or tables-only datastream (in bytes) |
| width | pointer to an integer variable that will receive the width (in pixels) of the JPEG image. If jpegBuf points to a tables-only datastream, then width is ignored. |
| height | pointer to an integer variable that will receive the height (in pixels) of the JPEG image. If jpegBuf points to a tables-only datastream, then height is ignored. |
| jpegSubsamp | pointer to an integer variable that will receive the level of chrominance subsampling used when the JPEG image was compressed (see Chrominance subsampling options.) If jpegBuf points to a tables-only datastream, then jpegSubsamp is ignored. |
| jpegColorspace | pointer to an integer variable that will receive one of the JPEG colorspace constants, indicating the colorspace of the JPEG image (see JPEG colorspaces.) If jpegBuf points to a tables-only datastream, then jpegColorspace is ignored. |
imageSize bytes stored in
+imageSize bytes stored in
jpegImage with this decompressor instance.voidsetSourceImage(byte[] jpegImage,
int imageSize)
-imageSize bytes stored in
+imageSize bytes stored in
jpegImage with this decompressor instance.public void setSourceImage(byte[] jpegImage,
int imageSize)
throws TJException
-imageSize bytes stored in
- jpegImage with this decompressor instance. This image will
- be used as the source image for subsequent decompress operations.jpegImage - JPEG image buffer. This buffer is not modified.imageSize - size of the JPEG image (in bytes)imageSize bytes stored in
+ jpegImage with this decompressor instance. If
+ jpegImage contains a JPEG image, then this image will be used
+ as the source image for subsequent decompress operations. Passing a
+ tables-only datastream to this method primes the decompressor with
+ quantization and Huffman tables that can be used when decompressing
+ subsequent "abbreviated image" datastreams. This is useful, for instance,
+ when decompressing video streams in which all frames share the same
+ quantization and Huffman tables.jpegImage - buffer containing a JPEG image or an "abbreviated table
+ specification" (AKA "tables-only") datastream. This buffer is not
+ modified.imageSize - size of the JPEG image (in bytes)TJExceptionimageSize bytes stored in
- * jpegImage with this decompressor instance. This image will
- * be used as the source image for subsequent decompress operations.
+ * Associate the JPEG image or "abbreviated table specification" (AKA
+ * "tables-only") datastream of length imageSize bytes stored in
+ * jpegImage with this decompressor instance. If
+ * jpegImage contains a JPEG image, then this image will be used
+ * as the source image for subsequent decompress operations. Passing a
+ * tables-only datastream to this method primes the decompressor with
+ * quantization and Huffman tables that can be used when decompressing
+ * subsequent "abbreviated image" datastreams. This is useful, for instance,
+ * when decompressing video streams in which all frames share the same
+ * quantization and Huffman tables.
*
- * @param jpegImage JPEG image buffer. This buffer is not modified.
+ * @param jpegImage buffer containing a JPEG image or an "abbreviated table
+ * specification" (AKA "tables-only") datastream. This buffer is not
+ * modified.
*
* @param imageSize size of the JPEG image (in bytes)
*/
diff --git a/turbojpeg.c b/turbojpeg.c
index 32394cca..a1544f24 100644
--- a/turbojpeg.c
+++ b/turbojpeg.c
@@ -1225,7 +1225,13 @@ DLLEXPORT int tjDecompressHeader3(tjhandle handle,
}
jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize);
- jpeg_read_header(dinfo, TRUE);
+
+ /* jpeg_read_header() calls jpeg_abort() and returns JPEG_HEADER_TABLES_ONLY
+ if the datastream is a tables-only datastream. Since we aren't using a
+ suspending data source, the only other value it can return is
+ JPEG_HEADER_OK. */
+ if (jpeg_read_header(dinfo, FALSE) == JPEG_HEADER_TABLES_ONLY)
+ return 0;
*width = dinfo->image_width;
*height = dinfo->image_height;
diff --git a/turbojpeg.h b/turbojpeg.h
index 5b33ad84..02b54ca9 100644
--- a/turbojpeg.h
+++ b/turbojpeg.h
@@ -1129,27 +1129,38 @@ DLLEXPORT tjhandle tjInitDecompress(void);
/**
- * Retrieve information about a JPEG image without decompressing it.
+ * Retrieve information about a JPEG image without decompressing it, or prime
+ * the decompressor with quantization and Huffman tables.
*
* @param handle a handle to a TurboJPEG decompressor or transformer instance
*
- * @param jpegBuf pointer to a buffer containing a JPEG image
+ * @param jpegBuf pointer to a buffer containing a JPEG image or an
+ * "abbreviated table specification" (AKA "tables-only") datastream. Passing a
+ * tables-only datastream to this function primes the decompressor with
+ * quantization and Huffman tables that can be used when decompressing
+ * subsequent "abbreviated image" datastreams. This is useful, for instance,
+ * when decompressing video streams in which all frames share the same
+ * quantization and Huffman tables.
*
- * @param jpegSize size of the JPEG image (in bytes)
+ * @param jpegSize size of the JPEG image or tables-only datastream (in bytes)
*
* @param width pointer to an integer variable that will receive the width (in
- * pixels) of the JPEG image
+ * pixels) of the JPEG image. If jpegBuf points to a tables-only
+ * datastream, then width is ignored.
*
* @param height pointer to an integer variable that will receive the height
- * (in pixels) of the JPEG image
+ * (in pixels) of the JPEG image. If jpegBuf points to a tables-only
+ * datastream, then height is ignored.
*
* @param jpegSubsamp pointer to an integer variable that will receive the
* level of chrominance subsampling used when the JPEG image was compressed
- * (see @ref TJSAMP "Chrominance subsampling options".)
+ * (see @ref TJSAMP "Chrominance subsampling options".) If jpegBuf
+ * points to a tables-only datastream, then jpegSubsamp is ignored.
*
* @param jpegColorspace pointer to an integer variable that will receive one
* of the JPEG colorspace constants, indicating the colorspace of the JPEG
- * image (see @ref TJCS "JPEG colorspaces".)
+ * image (see @ref TJCS "JPEG colorspaces".) If jpegBuf
+ * points to a tables-only datastream, then jpegColorspace is ignored.
*
* @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
* and #tjGetErrorCode().)