TJCompressor.compress(int): Fix YUV-to-JPEG error
Due to an oversight, the TJCompressor.compress(int) method did not
handle YUV source images.
Fixes #413
diff --git a/ChangeLog.md b/ChangeLog.md
index 3db2b4b..d63ad90 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -8,6 +8,11 @@
fixed, and other functions that are incompatible with big endian MIPS CPUs are
disabled when building libjpeg-turbo for such CPUs.
+2. Fixed an oversight in the `TJCompressor.compress(int)` method in the
+TurboJPEG Java API that caused an error ("java.lang.IllegalStateException: No
+source image is associated with this instance") when attempting to use that
+method to compress a YUV image.
+
2.0.4
=====
diff --git a/java/org/libjpegturbo/turbojpeg/TJCompressor.java b/java/org/libjpegturbo/turbojpeg/TJCompressor.java
index 74e5db9..6d4830f 100644
--- a/java/org/libjpegturbo/turbojpeg/TJCompressor.java
+++ b/java/org/libjpegturbo/turbojpeg/TJCompressor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C)2011-2015, 2018 D. R. Commander. All Rights Reserved.
+ * Copyright (C)2011-2015, 2018, 2020 D. R. Commander. All Rights Reserved.
* Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -377,8 +377,15 @@
* #getCompressedSize} to obtain the size of the JPEG image.
*/
public byte[] compress(int flags) throws TJException {
- checkSourceImage();
- byte[] buf = new byte[TJ.bufSize(srcWidth, srcHeight, subsamp)];
+ byte[] buf;
+ if (srcYUVImage != null) {
+ buf = new byte[TJ.bufSize(srcYUVImage.getWidth(),
+ srcYUVImage.getHeight(),
+ srcYUVImage.getSubsamp())];
+ } else {
+ checkSourceImage();
+ buf = new byte[TJ.bufSize(srcWidth, srcHeight, subsamp)];
+ }
compress(buf, flags);
return buf;
}