Skip to content

Commit

Permalink
Address comments for PR #5475
Browse files Browse the repository at this point in the history
  • Loading branch information
falhassen committed Feb 13, 2025
1 parent 484366a commit bfae3d8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private static int getOrientationInternal(
* Returns the result from the first of {@code parsers} that returns true when MPF is detected, if
* any..
*
* <p>If {@code buffer} is null, the parers list is empty, or none of the parsers returns a valid
* <p>If {@code buffer} is null, the parsers list is empty, or none of the parsers returns a valid
* value, false is returned.
*/
public static boolean hasJpegMpf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,22 +354,33 @@ private int moveToExifSegmentAndGetLength(Reader reader) throws IOException {
return moveToSegmentAndGetLength(reader, EXIF_SEGMENT_TYPE);
}

private boolean hasJpegMpfPreamble(Reader reader, byte[] tempArray, int mpfSegmentLength)
/**
* Returns whether the reader, set at the beginning of the APP2 segment past the length bytes,
* contains multi-picture format (MPF) data.
*
* @param reader must be set at the start of an APP2 segment, past the APP2 label and length
* bytes.
* @param tempArray for storing temporary array. Must be at least the size of
* {@code app2SegmentLength}.
* @param app2SegmentLength the length of the APP2 segment.
* @throws IOException if an EOF is reached before anything was read.
*/
private boolean hasJpegMpfPreamble(Reader reader, byte[] tempArray, int app2SegmentLength)
throws IOException {
int read = reader.read(tempArray, mpfSegmentLength);
if (read != mpfSegmentLength) {
int read = reader.read(tempArray, app2SegmentLength);
if (read != app2SegmentLength) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(
TAG,
"Unable to read MPF segment data"
"Unable to read APP2 segment data"
+ ", length: "
+ mpfSegmentLength
+ app2SegmentLength
+ ", actually read: "
+ read);
}
return false;
}
return hasMatchingBytes(tempArray, mpfSegmentLength, JPEG_MPF_SEGMENT_PREAMBLE_BYTES);
return hasMatchingBytes(tempArray, app2SegmentLength, JPEG_MPF_SEGMENT_PREAMBLE_BYTES);
}

private int moveToApp2SegmentAndGetLength(Reader reader) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public int getImageOrientation() throws IOException {
public boolean hasJpegMpf() throws IOException {
InputStream is = null;
try {
is = new RecyclableBufferedInputStream(new FileInputStream(file), byteArrayPool);
is = new FileInputStream(file);
return ImageHeaderParserUtils.hasJpegMpf(parsers, is, byteArrayPool);
} finally {
if (is != null) {
Expand Down

0 comments on commit bfae3d8

Please sign in to comment.