Skip to content

Commit

Permalink
Merge pull request #286 from dbmdz/fix-twelvemonkeys-tiffjpeg
Browse files Browse the repository at this point in the history
turbojpeg: Fix JPEG decoding from TIFFs with versions >=2.1.4
  • Loading branch information
stefan-it authored May 7, 2024
2 parents d2d5861 + 2395d93 commit b63e7b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
/** Java bindings for libturbojpeg via JFFI * */
public class TurboJpeg {

private static final int INITIAL_PTR_VALUE = 31337;
private static final Logger LOG = LoggerFactory.getLogger(TurboJpeg.class);

public libturbojpeg lib;
public Runtime runtime;

Expand All @@ -52,10 +54,13 @@ public Info getInfo(byte[] jpegData) throws TurboJpegException {
try {
codec = lib.tjInitDecompress();

IntByReference width = new IntByReference();
IntByReference height = new IntByReference();
IntByReference jpegSubsamp = new IntByReference();
IntByReference jpegColorspace = new IntByReference();
ByteBuffer infoBuf = ByteBuffer.allocate(4 * 4).order(runtime.byteOrder());
Pointer buf = Pointer.wrap(runtime, infoBuf);

IntByReference width = new IntByReference(INITIAL_PTR_VALUE);
IntByReference height = new IntByReference(INITIAL_PTR_VALUE);
IntByReference jpegSubsamp = new IntByReference(INITIAL_PTR_VALUE);
IntByReference jpegColorspace = new IntByReference(INITIAL_PTR_VALUE);
int rv =
lib.tjDecompressHeader3(
codec,
Expand All @@ -69,6 +74,13 @@ public Info getInfo(byte[] jpegData) throws TurboJpegException {
throw new TurboJpegException(lib.tjGetErrorStr());
}

if (width.getValue() == INITIAL_PTR_VALUE
&& height.getValue() == INITIAL_PTR_VALUE
&& jpegSubsamp.getValue() == INITIAL_PTR_VALUE
&& jpegColorspace.getValue() == INITIAL_PTR_VALUE) {
return null;
}

IntByReference numRef = new IntByReference();
Pointer factorPtr = lib.tjGetScalingFactors(numRef);
final Integer numOfFactors = numRef.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ int tjDecompressHeader3(
Pointer handle,
Buffer jpegBuf,
@u_int32_t long jpegSize,
@Out IntByReference width,
@Out IntByReference height,
@Out IntByReference jpegSubsamp,
@Out IntByReference jpegColorspace);
@Out @In IntByReference width,
@Out @In IntByReference height,
@Out @In IntByReference jpegSubsamp,
@Out @In IntByReference jpegColorspace);

int tjTransform(
Pointer handle,
Expand Down

0 comments on commit b63e7b4

Please sign in to comment.