Skip to content

Commit

Permalink
TJCompressor.compress(int): Fix YUV-to-JPEG error
Browse files Browse the repository at this point in the history
Due to an oversight, the TJCompressor.compress(int) method did not
handle YUV source images.

Fixes mozilla#413
  • Loading branch information
dcommander committed Feb 24, 2020
1 parent ecf5f9a commit 8cc1277
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
=====
Expand Down
13 changes: 10 additions & 3 deletions java/org/libjpegturbo/turbojpeg/TJCompressor.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -377,8 377,15 @@ else if (srcBuf != null) {
* #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;
}
Expand Down

0 comments on commit 8cc1277

Please sign in to comment.