Skip to content

Commit

Permalink
#878: Now detects APP14/Adobe markers with full 2 byte version
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldk committed Dec 16, 2023
1 parent 2b5f897 commit b91d02a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class AdobeDCT extends Application {
final int transform;

private AdobeDCT(int version, int flags0, int flags1, int transform) {
super(JPEG.APP14, "Adobe", new byte[]{'A', 'd', 'o', 'b', 'e', 0, (byte) version, (byte) (flags0 >> 8), (byte) (flags0 & 0xff), (byte) (flags1 >> 8), (byte) (flags1 & 0xff), (byte) transform});
super(JPEG.APP14, "Adobe", new byte[]{'A', 'd', 'o', 'b', 'e', (byte) (version >> 8), (byte) (version & 0xff), (byte) (flags0 >> 8), (byte) (flags0 & 0xff), (byte) (flags1 >> 8), (byte) (flags1 & 0xff), (byte) transform});

this.version = version; // 100 or 101
this.flags0 = flags0;
Expand All @@ -72,11 +72,11 @@ public String toString() {
public static AdobeDCT read(final DataInput data, final int length) throws IOException {
// TODO: Investigate http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6355567: 33/35 byte Adobe APP14 markers

data.skipBytes(6); // A, d, o, b, e, \0
data.skipBytes(5); // A, d, o, b, e

// version (byte), flags (4bytes), color transform (byte: 0=unknown, 1=YCC, 2=YCCK)
// version (2 bytes), flags (4bytes), color transform (byte: 0=unknown, 1=YCC, 2=YCCK)
return new AdobeDCT(
data.readUnsignedByte(),
data.readUnsignedShort(),
data.readUnsignedShort(),
data.readUnsignedShort(),
data.readUnsignedByte()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@
import javax.imageio.IIOException;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import java.awt.color.ICC_Profile;
import java.awt.color.*;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.twelvemonkeys.lang.Validate.notNull;

Expand Down Expand Up @@ -144,8 +148,10 @@ private static boolean isImageDone(final JPEGSegment segment) {
}

static String asNullTerminatedAsciiString(final byte[] data, final int offset) {
// TODO: JPEG App segment identifiers are not always 0-terminated...
// Need to rewrite. For now, make sure we read only ASCII non-control chars.
for (int i = 0; i < data.length - offset; i++) {
if (data[offset + i] == 0 || i > 255) {
if (data[offset + i] < 20 || i > 255) {
return asAsciiString(data, offset, offset + i);
}
}
Expand Down

0 comments on commit b91d02a

Please sign in to comment.