Skip to content

Commit

Permalink
Minor TurboJPEG doc tweaks
Browse files Browse the repository at this point in the history
- When transforming, the worst-case JPEG buffer size depends on the
  subsampling level used in the destination image, since a grayscale
  transform might have been applied.

- Parentheses Police
  • Loading branch information
dcommander committed Sep 6, 2024
1 parent 2e40a68 commit 6d95917
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion doc/html/group___turbo_j_p_e_g.html
Original file line number Diff line number Diff line change
Expand Up @@ -3173,7 +3173,7 @@ <h2 class="memtitle"><span class="permalink"><a href="#gaff23ba1dcabed456794b844
<tr><td class="paramname">dstBufs</td><td>pointer to an array of n byte buffers. <code>dstBufs[i]</code> will receive a JPEG image that has been transformed using the parameters in <code>transforms[i]</code>. TurboJPEG has the ability to reallocate the JPEG destination buffer to accommodate the size of the transformed JPEG image. Thus, you can choose to:<ol type="1">
<li>pre-allocate the JPEG destination buffer with an arbitrary size using <a class="el" href="group___turbo_j_p_e_g.html#ga1a2c96d8b47530b6e6050ba6f10b7c57" title="Allocate a byte buffer for use with TurboJPEG.">tj3Alloc()</a> and let TurboJPEG grow the buffer as needed,</li>
<li>set <code>dstBufs[i]</code> to NULL to tell TurboJPEG to allocate the buffer for you, or</li>
<li>pre-allocate the buffer to a "worst case" size determined by calling <a class="el" href="group___turbo_j_p_e_g.html#gac6285e58e35a35d871d7162ec5a929c4" title="The maximum size of the buffer (in bytes) required to hold a JPEG image with the given parameters.">tj3JPEGBufSize()</a> with the transformed or cropped width and height and the level of subsampling used in the source image. Under normal circumstances, this should ensure that the buffer never has to be re-allocated. (Setting <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82ae64ffb358bc7b194fd48e0f27750b29b" title="JPEG destination buffer (re)allocation [compression, lossless transformation].">TJPARAM_NOREALLOC</a> guarantees that it won't be.) Note, however, that there are some rare cases (such as transforming images with a large amount of embedded Exif or ICC profile data) in which the transformed JPEG image will be larger than the worst-case size, and <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82ae64ffb358bc7b194fd48e0f27750b29b" title="JPEG destination buffer (re)allocation [compression, lossless transformation].">TJPARAM_NOREALLOC</a> cannot be used in those cases.</li>
<li>pre-allocate the buffer to a "worst case" size determined by calling <a class="el" href="group___turbo_j_p_e_g.html#gac6285e58e35a35d871d7162ec5a929c4" title="The maximum size of the buffer (in bytes) required to hold a JPEG image with the given parameters.">tj3JPEGBufSize()</a> with the transformed or cropped width and height and the level of subsampling used in the destination image. Under normal circumstances, this should ensure that the buffer never has to be re-allocated. (Setting <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82ae64ffb358bc7b194fd48e0f27750b29b" title="JPEG destination buffer (re)allocation [compression, lossless transformation].">TJPARAM_NOREALLOC</a> guarantees that it won't be.) Note, however, that there are some rare cases (such as transforming images with a large amount of embedded Exif or ICC profile data) in which the transformed JPEG image will be larger than the worst-case size, and <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82ae64ffb358bc7b194fd48e0f27750b29b" title="JPEG destination buffer (re)allocation [compression, lossless transformation].">TJPARAM_NOREALLOC</a> cannot be used in those cases.</li>
</ol>
If you choose option 1, then <code>dstSizes[i]</code> should be set to the size of your pre-allocated buffer. In any case, unless you have set <a class="el" href="group___turbo_j_p_e_g.html#ggaa0f6be63ba78278299c9f5c12031fe82ae64ffb358bc7b194fd48e0f27750b29b" title="JPEG destination buffer (re)allocation [compression, lossless transformation].">TJPARAM_NOREALLOC</a>, you should always check <code>dstBufs[i]</code> upon return from this function, as it may have changed.</td></tr>
<tr><td class="paramname">dstSizes</td><td>pointer to an array of n size_t variables that will receive the actual sizes (in bytes) of each transformed JPEG image. If <code>dstBufs[i]</code> points to a pre-allocated buffer, then <code>dstSizes[i]</code> should be set to the size of the buffer. Upon return, <code>dstSizes[i]</code> will contain the size of the transformed JPEG image (in bytes.)</td></tr>
Expand Down
Binary file modified java/doc/member-search-index.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ <h4>setCroppingRegion</h4>
subsampling in the JPEG image (see <a href="TJ.html#PARAM_SUBSAMP"><code>TJ.PARAM_SUBSAMP</code></a>.) The
cropping region should be specified relative to the scaled image
dimensions. Unless <code>croppingRegion</code> is <a href="TJ.html#UNCROPPED"><code>TJ.UNCROPPED</code></a>,
the JPEG header must be read (see <a href="#setSourceImage(byte%5B%5D,int)"><code>setSourceImage(byte[], int)</code></a>
the JPEG header must be read (see <a href="#setSourceImage(byte%5B%5D,int)"><code>setSourceImage(byte[], int)</code></a>)
prior to calling this method.</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code><a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></code></dd>
Expand Down
2 changes: 1 addition & 1 deletion java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ <h4>transform</h4>
transformed using the parameters in <code>transforms[i]</code>. Use
<a href="TJ.html#bufSize(int,int,int)"><code>TJ.bufSize()</code></a> to determine the maximum size for each
buffer based on the transformed or cropped width and height and the level
of subsampling used in the source image.</dd>
of subsampling used in the destination image.</dd>
<dd><code>transforms</code> - an array of <a href="TJTransform.html" title="class in org.libjpegturbo.turbojpeg"><code>TJTransform</code></a> instances, each of
which specifies the transform parameters and/or cropping region for the
corresponding transformed JPEG image</dd>
Expand Down
Binary file modified java/doc/package-search-index.zip
Binary file not shown.
Binary file modified java/doc/type-search-index.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion java/org/libjpegturbo/turbojpeg/TJDecompressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public void setScalingFactor(TJScalingFactor scalingFactor) {
* subsampling in the JPEG image (see {@link TJ#PARAM_SUBSAMP}.) The
* cropping region should be specified relative to the scaled image
* dimensions. Unless <code>croppingRegion</code> is {@link TJ#UNCROPPED},
* the JPEG header must be read (see {@link #setSourceImage(byte[], int)}
* the JPEG header must be read (see {@link #setSourceImage(byte[], int)})
* prior to calling this method.
*/
@SuppressWarnings("checkstyle:HiddenField")
Expand Down
2 changes: 1 addition & 1 deletion java/org/libjpegturbo/turbojpeg/TJTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public TJTransformer(byte[] jpegImage, int imageSize) throws TJException {
* transformed using the parameters in <code>transforms[i]</code>. Use
* {@link TJ#bufSize TJ.bufSize()} to determine the maximum size for each
* buffer based on the transformed or cropped width and height and the level
* of subsampling used in the source image.
* of subsampling used in the destination image.
*
* @param transforms an array of {@link TJTransform} instances, each of
* which specifies the transform parameters and/or cropping region for the
Expand Down
14 changes: 7 additions & 7 deletions turbojpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -2065,13 +2065,13 @@ DLLEXPORT int tj3DecodeYUV8(tjhandle handle, const unsigned char *srcBuf,
* you, or
* -# pre-allocate the buffer to a "worst case" size determined by calling
* #tj3JPEGBufSize() with the transformed or cropped width and height and the
* level of subsampling used in the source image. Under normal circumstances,
* this should ensure that the buffer never has to be re-allocated. (Setting
* #TJPARAM_NOREALLOC guarantees that it won't be.) Note, however, that there
* are some rare cases (such as transforming images with a large amount of
* embedded Exif or ICC profile data) in which the transformed JPEG image will
* be larger than the worst-case size, and #TJPARAM_NOREALLOC cannot be used in
* those cases.
* level of subsampling used in the destination image. Under normal
* circumstances, this should ensure that the buffer never has to be
* re-allocated. (Setting #TJPARAM_NOREALLOC guarantees that it won't be.)
* Note, however, that there are some rare cases (such as transforming images
* with a large amount of embedded Exif or ICC profile data) in which the
* transformed JPEG image will be larger than the worst-case size, and
* #TJPARAM_NOREALLOC cannot be used in those cases.
* .
* If you choose option 1, then `dstSizes[i]` should be set to the size of your
* pre-allocated buffer. In any case, unless you have set #TJPARAM_NOREALLOC,
Expand Down

0 comments on commit 6d95917

Please sign in to comment.