Merge branch 'main' into dev
This commit is contained in:
@@ -857,6 +857,43 @@ final class TJUnitTest {
|
|||||||
if (tjd != null) tjd.close();
|
if (tjd != null) tjd.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void overflowTest() throws Exception {
|
||||||
|
/* Ensure that the various buffer size methods don't overflow */
|
||||||
|
int size = 0;
|
||||||
|
boolean exception = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
exception = false;
|
||||||
|
size = TJ.bufSize(26755, 26755, TJ.SAMP_444);
|
||||||
|
} catch (Exception e) { exception = true; }
|
||||||
|
if (!exception || size != 0)
|
||||||
|
throw new Exception("TJ.bufSize() overflow");
|
||||||
|
try {
|
||||||
|
exception = false;
|
||||||
|
size = TJ.bufSizeYUV(37838, 1, 37838, TJ.SAMP_444);
|
||||||
|
} catch (Exception e) { exception = true; }
|
||||||
|
if (!exception || size != 0)
|
||||||
|
throw new Exception("TJ.bufSizeYUV() overflow");
|
||||||
|
try {
|
||||||
|
exception = false;
|
||||||
|
size = TJ.bufSizeYUV(37837, 3, 37837, TJ.SAMP_444);
|
||||||
|
} catch (Exception e) { exception = true; }
|
||||||
|
if (!exception || size != 0)
|
||||||
|
throw new Exception("TJ.bufSizeYUV() overflow");
|
||||||
|
try {
|
||||||
|
exception = false;
|
||||||
|
size = TJ.bufSizeYUV(37837, -1, 37837, TJ.SAMP_444);
|
||||||
|
} catch (Exception e) { exception = true; }
|
||||||
|
if (!exception || size != 0)
|
||||||
|
throw new Exception("TJ.bufSizeYUV() overflow");
|
||||||
|
try {
|
||||||
|
exception = false;
|
||||||
|
size = TJ.planeSizeYUV(0, 65536, 0, 65536, TJ.SAMP_444);
|
||||||
|
} catch (Exception e) { exception = true; }
|
||||||
|
if (!exception || size != 0)
|
||||||
|
throw new Exception("TJ.planeSizeYUV() overflow");
|
||||||
|
}
|
||||||
|
|
||||||
static void bufSizeTest() throws Exception {
|
static void bufSizeTest() throws Exception {
|
||||||
int w, h, i, subsamp, flags = 0, quality = 100, numSamp = TJ.NUMSAMP;
|
int w, h, i, subsamp, flags = 0, quality = 100, numSamp = TJ.NUMSAMP;
|
||||||
byte[] srcBuf, dstBuf = null;
|
byte[] srcBuf, dstBuf = null;
|
||||||
@@ -942,6 +979,7 @@ final class TJUnitTest {
|
|||||||
throw new Exception("Lossless JPEG and YUV encoding/decoding are incompatible.");
|
throw new Exception("Lossless JPEG and YUV encoding/decoding are incompatible.");
|
||||||
if (doYUV)
|
if (doYUV)
|
||||||
FORMATS_4BYTE[4] = -1;
|
FORMATS_4BYTE[4] = -1;
|
||||||
|
overflowTest();
|
||||||
doTest(35, 39, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_444,
|
doTest(35, 39, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_444,
|
||||||
testName);
|
testName);
|
||||||
doTest(39, 41, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_444,
|
doTest(39, 41, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_444,
|
||||||
|
|||||||
@@ -166,9 +166,10 @@
|
|||||||
</dd>
|
</dd>
|
||||||
<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html#decompress(int,%20int,%20int,%20int)">decompress(int, int, int, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>
|
<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html#decompress(int,%20int,%20int,%20int)">decompress(int, int, int, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>
|
||||||
<dd>
|
<dd>
|
||||||
<div class="block">Decompress the JPEG source image or decode the YUV source image associated
|
<div class="block">Decompress the JPEG source image or decode the planar YUV source image
|
||||||
with this decompressor instance and return a <code>BufferedImage</code>
|
associated with this decompressor instance and return a
|
||||||
instance containing the packed-pixel decompressed/decoded image.</div>
|
<code>BufferedImage</code> instance containing the packed-pixel
|
||||||
|
decompressed/decoded image.</div>
|
||||||
</dd>
|
</dd>
|
||||||
<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html#decompressToYUV(org.libjpegturbo.turbojpeg.YUVImage,%20int)">decompressToYUV(YUVImage, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>
|
<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html#decompressToYUV(org.libjpegturbo.turbojpeg.YUVImage,%20int)">decompressToYUV(YUVImage, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>
|
||||||
<dd>
|
<dd>
|
||||||
|
|||||||
@@ -271,9 +271,10 @@ implements java.io.Closeable</pre>
|
|||||||
int desiredHeight,
|
int desiredHeight,
|
||||||
int bufferedImageType,
|
int bufferedImageType,
|
||||||
int flags)</code>
|
int flags)</code>
|
||||||
<div class="block">Decompress the JPEG source image or decode the YUV source image associated
|
<div class="block">Decompress the JPEG source image or decode the planar YUV source image
|
||||||
with this decompressor instance and return a <code>BufferedImage</code>
|
associated with this decompressor instance and return a
|
||||||
instance containing the packed-pixel decompressed/decoded image.</div>
|
<code>BufferedImage</code> instance containing the packed-pixel
|
||||||
|
decompressed/decoded image.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="rowColor">
|
<tr class="rowColor">
|
||||||
@@ -1093,9 +1094,10 @@ implements java.io.Closeable</pre>
|
|||||||
int bufferedImageType,
|
int bufferedImageType,
|
||||||
int flags)
|
int flags)
|
||||||
throws <a href="../../../org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
|
throws <a href="../../../org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
|
||||||
<div class="block">Decompress the JPEG source image or decode the YUV source image associated
|
<div class="block">Decompress the JPEG source image or decode the planar YUV source image
|
||||||
with this decompressor instance and return a <code>BufferedImage</code>
|
associated with this decompressor instance and return a
|
||||||
instance containing the packed-pixel decompressed/decoded image.</div>
|
<code>BufferedImage</code> instance containing the packed-pixel
|
||||||
|
decompressed/decoded image.</div>
|
||||||
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>desiredWidth</code> - see
|
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>desiredWidth</code> - see
|
||||||
<a href="../../../org/libjpegturbo/turbojpeg/TJDecompressor.html#decompress(byte[],%20int,%20int,%20int,%20int,%20int,%20int,%20int)"><code>decompress(byte[], int, int, int, int, int, int, int)</code></a> for
|
<a href="../../../org/libjpegturbo/turbojpeg/TJDecompressor.html#decompress(byte[],%20int,%20int,%20int,%20int,%20int,%20int,%20int)"><code>decompress(byte[], int, int, int, int, int, int, int)</code></a> for
|
||||||
description</dd><dd><code>desiredHeight</code> - see
|
description</dd><dd><code>desiredHeight</code> - see
|
||||||
|
|||||||
@@ -803,9 +803,10 @@ public class TJDecompressor implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decompress the JPEG source image or decode the YUV source image associated
|
* Decompress the JPEG source image or decode the planar YUV source image
|
||||||
* with this decompressor instance and return a <code>BufferedImage</code>
|
* associated with this decompressor instance and return a
|
||||||
* instance containing the packed-pixel decompressed/decoded image.
|
* <code>BufferedImage</code> instance containing the packed-pixel
|
||||||
|
* decompressed/decoded image.
|
||||||
*
|
*
|
||||||
* @param desiredWidth see
|
* @param desiredWidth see
|
||||||
* {@link #decompress(byte[], int, int, int, int, int, int, int)} for
|
* {@link #decompress(byte[], int, int, int, int, int, int, int)} for
|
||||||
|
|||||||
@@ -132,24 +132,28 @@ bailout:
|
|||||||
JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSize
|
JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSize
|
||||||
(JNIEnv *env, jclass cls, jint width, jint height, jint jpegSubsamp)
|
(JNIEnv *env, jclass cls, jint width, jint height, jint jpegSubsamp)
|
||||||
{
|
{
|
||||||
jint retval = (jint)tjBufSize(width, height, jpegSubsamp);
|
unsigned long retval = tjBufSize(width, height, jpegSubsamp);
|
||||||
|
|
||||||
if (retval == -1) THROW_ARG(tjGetErrorStr());
|
if (retval == (unsigned long)-1) THROW_ARG(tjGetErrorStr());
|
||||||
|
if (retval > (unsigned long)((unsigned int)-1))
|
||||||
|
THROW_ARG("Image is too large");
|
||||||
|
|
||||||
bailout:
|
bailout:
|
||||||
return retval;
|
return (jint)retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TurboJPEG 1.4.x: TJ::bufSizeYUV() */
|
/* TurboJPEG 1.4.x: TJ::bufSizeYUV() */
|
||||||
JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__IIII
|
JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__IIII
|
||||||
(JNIEnv *env, jclass cls, jint width, jint align, jint height, jint subsamp)
|
(JNIEnv *env, jclass cls, jint width, jint align, jint height, jint subsamp)
|
||||||
{
|
{
|
||||||
jint retval = (jint)tjBufSizeYUV2(width, align, height, subsamp);
|
unsigned long retval = tjBufSizeYUV2(width, align, height, subsamp);
|
||||||
|
|
||||||
if (retval == -1) THROW_ARG(tjGetErrorStr());
|
if (retval == (unsigned long)-1) THROW_ARG(tjGetErrorStr());
|
||||||
|
if (retval > (unsigned long)((unsigned int)-1))
|
||||||
|
THROW_ARG("Image is too large");
|
||||||
|
|
||||||
bailout:
|
bailout:
|
||||||
return retval;
|
return (jint)retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TurboJPEG 1.4.x: TJ::planeSizeYUV() */
|
/* TurboJPEG 1.4.x: TJ::planeSizeYUV() */
|
||||||
@@ -157,13 +161,15 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_planeSizeYUV__IIIII
|
|||||||
(JNIEnv *env, jclass cls, jint componentID, jint width, jint stride,
|
(JNIEnv *env, jclass cls, jint componentID, jint width, jint stride,
|
||||||
jint height, jint subsamp)
|
jint height, jint subsamp)
|
||||||
{
|
{
|
||||||
jint retval = (jint)tjPlaneSizeYUV(componentID, width, stride, height,
|
unsigned long retval = tjPlaneSizeYUV(componentID, width, stride, height,
|
||||||
subsamp);
|
subsamp);
|
||||||
|
|
||||||
if (retval == -1) THROW_ARG(tjGetErrorStr());
|
if (retval == (unsigned long)-1) THROW_ARG(tjGetErrorStr());
|
||||||
|
if (retval > (unsigned long)((unsigned int)-1))
|
||||||
|
THROW_ARG("Image is too large");
|
||||||
|
|
||||||
bailout:
|
bailout:
|
||||||
return retval;
|
return (jint)retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TurboJPEG 1.4.x: TJ::planeWidth() */
|
/* TurboJPEG 1.4.x: TJ::planeWidth() */
|
||||||
|
|||||||
Reference in New Issue
Block a user