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
This commit is contained in:
DRC
2020-02-24 13:29:50 -06:00
parent ecf5f9a96a
commit 8cc1277b69
2 changed files with 15 additions and 3 deletions

View File

@@ -8,6 +8,11 @@ in the MIPS DSPr2 SIMD extensions are now disabled until/unless they can be
fixed, and other functions that are incompatible with big endian MIPS CPUs are fixed, and other functions that are incompatible with big endian MIPS CPUs are
disabled when building libjpeg-turbo for such CPUs. 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 2.0.4
===== =====

View File

@@ -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. * Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -377,8 +377,15 @@ public class TJCompressor implements Closeable {
* #getCompressedSize} to obtain the size of the JPEG image. * #getCompressedSize} to obtain the size of the JPEG image.
*/ */
public byte[] compress(int flags) throws TJException { public byte[] compress(int flags) throws TJException {
checkSourceImage(); byte[] buf;
byte[] buf = new byte[TJ.bufSize(srcWidth, srcHeight, subsamp)]; 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); compress(buf, flags);
return buf; return buf;
} }