TJ: Add func/method for computing xformed buf size

This commit is contained in:
DRC
2024-09-14 11:56:14 -04:00
parent 5b09958060
commit 9b01f5a057
30 changed files with 464 additions and 256 deletions

View File

@@ -528,7 +528,7 @@ final class TJBench {
byte[][] jpegBufs = null;
byte[] srcBuf;
int[] jpegSizes = null;
int iccSize = 0, totalJpegSize;
int totalJpegSize;
double start, elapsed;
int ps = TJ.getPixelSize(pf), tile, x, y, iter;
// Original image
@@ -571,8 +571,6 @@ final class TJBench {
System.out.println("JPEG image is progressive\n");
if (tjt.get(TJ.PARAM_ARITHMETIC) == 1)
System.out.println("JPEG image uses arithmetic entropy coding\n");
if ((xformOpt & TJTransform.OPT_COPYNONE) == 0)
iccSize = tjt.getICCSize();
tjt.set(TJ.PARAM_PROGRESSIVE, progressive ? 1 : 0);
tjt.set(TJ.PARAM_ARITHMETIC, arithmetic ? 1 : 0);
@@ -688,9 +686,7 @@ final class TJBench {
t[tile].options = xformOpt | TJTransform.OPT_TRIM;
t[tile].cf = customFilter;
if ((t[tile].options & TJTransform.OPT_NOOUTPUT) == 0)
jpegBufs[tile] =
new byte[TJ.bufSize(t[tile].width, t[tile].height, tsubsamp) +
iccSize];
jpegBufs[tile] = new byte[tjt.bufSize(t[tile])];
}
}
@@ -739,7 +735,7 @@ final class TJBench {
} else {
if (quiet == 1)
System.out.print("N/A N/A ");
jpegBufs = new byte[1][TJ.bufSize(ttilew, ttileh, tsubsamp) + iccSize];
jpegBufs = new byte[1][];
jpegSizes = new int[1];
jpegBufs[0] = srcBuf;
jpegSizes[0] = srcSize;

View File

@@ -101,6 +101,13 @@ $('.navPadding').css('padding-top', $('.fixedNav').css("height"));
<div class="block">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.</div>
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJTransformer.html#bufSize(org.libjpegturbo.turbojpeg.TJTransform)">bufSize(TJTransform)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJTransformer.html" title="class in org.libjpegturbo.turbojpeg">TJTransformer</a></dt>
<dd>
<div class="block">Returns the maximum size of the buffer (in bytes) required to hold a JPEG
image transformed, with the given transform parameters and/or cropping
region, from the JPEG source image associated with this transformer
instance.</div>
</dd>
<dt><span class="memberNameLink"><a href="org/libjpegturbo/turbojpeg/TJ.html#bufSizeYUV(int,int,int,int)">bufSizeYUV(int, int, int, int)</a></span> - Static method in class org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg">TJ</a></dt>
<dd>
<div class="block">Returns the size of the buffer (in bytes) required to hold a unified

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@@ -27,7 +27,7 @@
catch(err) {
}
//-->
var data = {"i0":10,"i1":10,"i2":10,"i3":10};
var data = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10};
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
@@ -203,6 +203,16 @@ extends <a href="TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg
<th class="colLast" scope="col">Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code>int</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#bufSize(org.libjpegturbo.turbojpeg.TJTransform)">bufSize</a></span>&#8203;(<a href="TJTransform.html" title="class in org.libjpegturbo.turbojpeg">TJTransform</a>&nbsp;transform)</code></th>
<td class="colLast">
<div class="block">Returns the maximum size of the buffer (in bytes) required to hold a JPEG
image transformed, with the given transform parameters and/or cropping
region, from the JPEG source image associated with this transformer
instance.</div>
</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code>int[]</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#getTransformedSizes()">getTransformedSizes</a></span>()</code></th>
<td class="colLast">
@@ -210,7 +220,7 @@ extends <a href="TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg
(in bytes) generated by the most recent transform operation.</div>
</td>
</tr>
<tr id="i1" class="rowColor">
<tr id="i2" class="altColor">
<td class="colFirst"><code>void</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#setICCProfile(byte%5B%5D)">setICCProfile</a></span>&#8203;(byte[]&nbsp;iccBuf)</code></th>
<td class="colLast">
@@ -218,7 +228,7 @@ extends <a href="TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg
JPEG images generated by subsequent transform operations.</div>
</td>
</tr>
<tr id="i2" class="altColor">
<tr id="i3" class="rowColor">
<td class="colFirst"><code>void</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#transform(byte%5B%5D%5B%5D,org.libjpegturbo.turbojpeg.TJTransform%5B%5D)">transform</a></span>&#8203;(byte[][]&nbsp;dstBufs,
<a href="TJTransform.html" title="class in org.libjpegturbo.turbojpeg">TJTransform</a>[]&nbsp;transforms)</code></th>
@@ -228,7 +238,7 @@ extends <a href="TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg
destination buffers.</div>
</td>
</tr>
<tr id="i3" class="rowColor">
<tr id="i4" class="altColor">
<td class="colFirst"><code><a href="TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a>[]</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#transform(org.libjpegturbo.turbojpeg.TJTransform%5B%5D)">transform</a></span>&#8203;(<a href="TJTransform.html" title="class in org.libjpegturbo.turbojpeg">TJTransform</a>[]&nbsp;transforms)</code></th>
<td class="colLast">
@@ -358,6 +368,39 @@ extends <a href="TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg
</dl>
</li>
</ul>
<a id="bufSize(org.libjpegturbo.turbojpeg.TJTransform)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>bufSize</h4>
<pre class="methodSignature">public&nbsp;int&nbsp;bufSize&#8203;(<a href="TJTransform.html" title="class in org.libjpegturbo.turbojpeg">TJTransform</a>&nbsp;transform)
throws <a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Returns the maximum size of the buffer (in bytes) required to hold a JPEG
image transformed, with the given transform parameters and/or cropping
region, from the JPEG source image associated with this transformer
instance. This function is a wrapper for <a href="TJ.html#bufSize(int,int,int)"><code>TJ.bufSize()</code></a>
that takes into account cropping, transposition of the width and height
(which affects the destination image dimensions and level of chrominance
subsampling), grayscale conversion, and the ICC profile (if any) that was
previously associated with this transformer instance (see
<a href="#setICCProfile(byte%5B%5D)"><code>setICCProfile()</code></a>) or extracted from the source image
(see <a href="TJDecompressor.html#getICCProfile()"><code>TJDecompressor.getICCProfile()</code></a> and <a href="TJ.html#PARAM_SAVEMARKERS"><code>TJ.PARAM_SAVEMARKERS</code></a>.)</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>transform</code> - a <a href="TJTransform.html" title="class in org.libjpegturbo.turbojpeg"><code>TJTransform</code></a> instance that specifies the
transform parameters and/or cropping region for the transformed JPEG
image.</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the maximum size of the buffer (in bytes) required to hold a JPEG
image transformed, with the given transform parameters and/or cropping
region, from the JPEG source image associated with this transformer
instance</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code><a href="TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></code></dd>
</dl>
</li>
</ul>
<a id="transform(byte[][],org.libjpegturbo.turbojpeg.TJTransform[])">
<!-- -->
</a>
@@ -384,14 +427,7 @@ extends <a href="TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg
<dd><code>dstBufs</code> - an array of JPEG destination buffers.
<code>dstbufs[i]</code> will receive a JPEG image that has been
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 destination image (taking into account
grayscale conversion and transposition of the width and height), then add
the size of the ICC profile (if any) that was previously associated with
this transformer instance (see <a href="#setICCProfile(byte%5B%5D)"><code>setICCProfile()</code></a>) or
extracted from the source image (see
<a href="TJDecompressor.html#getICCProfile()"><code>TJDecompressor.getICCProfile()</code></a> and <a href="TJ.html#PARAM_SAVEMARKERS"><code>TJ.PARAM_SAVEMARKERS</code></a>.)</dd>
<a href="#bufSize(org.libjpegturbo.turbojpeg.TJTransform)"><code>bufSize()</code></a> to determine the maximum size for each buffer.</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>

Binary file not shown.

Binary file not shown.

View File

@@ -82,6 +82,29 @@ public class TJTransformer extends TJDecompressor {
*/
public native void setICCProfile(byte[] iccBuf) throws TJException;
/**
* Returns the maximum size of the buffer (in bytes) required to hold a JPEG
* image transformed, with the given transform parameters and/or cropping
* region, from the JPEG source image associated with this transformer
* instance. This function is a wrapper for {@link TJ#bufSize TJ.bufSize()}
* that takes into account cropping, transposition of the width and height
* (which affects the destination image dimensions and level of chrominance
* subsampling), grayscale conversion, and the ICC profile (if any) that was
* previously associated with this transformer instance (see
* {@link #setICCProfile setICCProfile()}) or extracted from the source image
* (see {@link #getICCProfile} and {@link TJ#PARAM_SAVEMARKERS}.)
*
* @param transform a {@link TJTransform} instance that specifies the
* transform parameters and/or cropping region for the transformed JPEG
* image.
*
* @return the maximum size of the buffer (in bytes) required to hold a JPEG
* image transformed, with the given transform parameters and/or cropping
* region, from the JPEG source image associated with this transformer
* instance
*/
public native int bufSize(TJTransform transform) throws TJException;
/**
* Losslessly transform the JPEG source image associated with this
* transformer instance into one or more JPEG images stored in the given
@@ -99,14 +122,7 @@ public class TJTransformer extends TJDecompressor {
* @param dstBufs an array of JPEG destination buffers.
* <code>dstbufs[i]</code> will receive a JPEG image that has been
* 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 destination image (taking into account
* grayscale conversion and transposition of the width and height), then add
* the size of the ICC profile (if any) that was previously associated with
* this transformer instance (see {@link #setICCProfile setICCProfile()}) or
* extracted from the source image (see
* {@link TJDecompressor#getICCProfile()} and {@link TJ#PARAM_SAVEMARKERS}.)
* {@link #bufSize bufSize()} to determine the maximum size for each buffer.
*
* @param transforms an array of {@link TJTransform} instances, each of
* which specifies the transform parameters and/or cropping region for the
@@ -133,41 +149,8 @@ public class TJTransformer extends TJDecompressor {
public TJDecompressor[] transform(TJTransform[] transforms)
throws TJException {
byte[][] dstBufs = new byte[transforms.length][];
if (getWidth() < 1 || getHeight() < 1)
throw new IllegalStateException("JPEG buffer not initialized");
int srcSubsamp = get(TJ.PARAM_SUBSAMP);
int saveMarkers = get(TJ.PARAM_SAVEMARKERS);
int extractedICCSize = getICCSize();
for (int i = 0; i < transforms.length; i++) {
int w = getWidth(), h = getHeight();
int dstSubsamp = srcSubsamp, iccLen = iccSize;
if ((transforms[i].options & TJTransform.OPT_GRAY) != 0)
dstSubsamp = TJ.SAMP_GRAY;
if (transforms[i].op == TJTransform.OP_TRANSPOSE ||
transforms[i].op == TJTransform.OP_TRANSVERSE ||
transforms[i].op == TJTransform.OP_ROT90 ||
transforms[i].op == TJTransform.OP_ROT270) {
w = getHeight(); h = getWidth();
if (dstSubsamp == TJ.SAMP_422)
dstSubsamp = TJ.SAMP_440;
else if (dstSubsamp == TJ.SAMP_440)
dstSubsamp = TJ.SAMP_422;
else if (dstSubsamp == TJ.SAMP_411)
dstSubsamp = TJ.SAMP_441;
else if (dstSubsamp == TJ.SAMP_441)
dstSubsamp = TJ.SAMP_411;
}
if ((transforms[i].options & TJTransform.OPT_CROP) != 0) {
if (transforms[i].width != 0) w = transforms[i].width;
if (transforms[i].height != 0) h = transforms[i].height;
}
if ((saveMarkers == 2 || saveMarkers == 4) &&
(transforms[i].options & TJTransform.OPT_COPYNONE) == 0)
iccLen = extractedICCSize;
dstBufs[i] = new byte[TJ.bufSize(w, h, dstSubsamp) + iccLen];
}
for (int i = 0; i < transforms.length; i++)
dstBufs[i] = new byte[bufSize(transforms[i])];
TJDecompressor[] tjd = new TJDecompressor[transforms.length];
transform(dstBufs, transforms);
for (int i = 0; i < transforms.length; i++)

View File

@@ -15,6 +15,14 @@ extern "C" {
JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJTransformer_setICCProfile
(JNIEnv *, jobject, jbyteArray);
/*
* Class: org_libjpegturbo_turbojpeg_TJTransformer
* Method: bufSize
* Signature: (Lorg/libjpegturbo/turbojpeg/TJTransform;)I
*/
JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJTransformer_bufSize
(JNIEnv *, jobject, jobject);
/*
* Class: org_libjpegturbo_turbojpeg_TJTransformer
* Method: init

View File

@@ -1203,6 +1203,42 @@ bailout:
return -1;
}
/* TurboJPEG 3.1.x: TJTransformed.bufSize() */
JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJTransformer_bufSize
(JNIEnv *env, jobject obj, jobject tobj)
{
tjhandle handle = 0;
tjtransform transform;
size_t retval = 0;
GET_HANDLE();
memset(&transform, 0, sizeof(tjtransform));
BAILIF0(_cls = (*env)->GetObjectClass(env, tobj));
BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "op", "I"));
transform.op = (*env)->GetIntField(env, tobj, _fid);
BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "options", "I"));
transform.options = (*env)->GetIntField(env, tobj, _fid);
BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "x", "I"));
transform.r.x = (*env)->GetIntField(env, tobj, _fid);
BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "y", "I"));
transform.r.y = (*env)->GetIntField(env, tobj, _fid);
BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "width", "I"));
transform.r.w = (*env)->GetIntField(env, tobj, _fid);
BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "height", "I"));
transform.r.h = (*env)->GetIntField(env, tobj, _fid);
retval = tj3TransformBufSize(handle, &transform);
if (retval == 0) THROW_ARG(tj3GetErrorStr(NULL));
if (retval > (size_t)INT_MAX)
THROW_ARG("Image is too large");
bailout:
return (jint)retval;
}
/* TurboJPEG 1.2.x: TJTransformer.transform() */
JNIEXPORT jintArray JNICALL Java_org_libjpegturbo_turbojpeg_TJTransformer_transform
(JNIEnv *env, jobject obj, jbyteArray jsrcBuf, jint jpegSize,