Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

turbojpeg: Fix JPEG decoding from TIFFs with versions >=2.1.4 #286

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading