@Nullable private static Directory readPlainTextBlock(SequentialReader reader, int blockSizeBytes) throws IOException { // It seems this extension is deprecated. If somebody finds an image with this in it, could implement here. // Just skip the entire block for now. if (blockSizeBytes != 12) return new ErrorDirectory(String.format("Invalid GIF plain text block size. Expected 12, got %d.", blockSizeBytes)); // skip 'blockSizeBytes' bytes reader.skip(12); // keep reading and skipping until a 0 byte is reached skipBlocks(reader); return null; }
protected void addError(@NotNull String errorMessage, final @NotNull Metadata metadata) { ErrorDirectory directory = metadata.getFirstDirectoryOfType(ErrorDirectory.class); if (directory == null) { metadata.addDirectory(new ErrorDirectory(errorMessage)); } else { directory.addError(errorMessage); } } }
public void extract(byte[] segmentBytes, Metadata metadata, JpegSegmentType segmentType) { JpegDirectory directory = metadata.getFirstDirectoryOfType(JpegDirectory.class); if (directory == null) { ErrorDirectory errorDirectory = new ErrorDirectory(); metadata.addDirectory(errorDirectory); errorDirectory.addError("DNL segment found without SOFx - illegal JPEG format"); return; } SequentialReader reader = new SequentialByteArrayReader(segmentBytes); try { // Only set height from DNL if it's not already defined Integer i = directory.getInteger(JpegDirectory.TAG_IMAGE_HEIGHT); if (i == null || i == 0) { directory.setInt(JpegDirectory.TAG_IMAGE_HEIGHT, reader.getUInt16()); } } catch (IOException ex) { directory.addError(ex.getMessage()); } } }
metadata.addDirectory(header); } catch (IOException ex) { metadata.addDirectory(new ErrorDirectory("IOException processing GIF data")); return; metadata.addDirectory(new ErrorDirectory("GIF did not had hasGlobalColorTable bit.")); metadata.addDirectory(new ErrorDirectory("Unknown gif block marker found.")); return; metadata.addDirectory(new ErrorDirectory("IOException processing GIF data"));
metadata.addDirectory(new ErrorDirectory(String.format("Invalid GIF application extension block size. Expected 11, got %d.", blockSizeBytes))); return;
private static void readGifExtensionBlock(SequentialReader reader, Metadata metadata) throws IOException { byte extensionLabel = reader.getInt8(); short blockSizeBytes = reader.getUInt8(); long blockStartPos = reader.getPosition(); switch (extensionLabel) { case (byte) 0x01: Directory plainTextBlock = readPlainTextBlock(reader, blockSizeBytes); if (plainTextBlock != null) metadata.addDirectory(plainTextBlock); break; case (byte) 0xf9: metadata.addDirectory(readControlBlock(reader, blockSizeBytes)); break; case (byte) 0xfe: metadata.addDirectory(readCommentBlock(reader, blockSizeBytes)); break; case (byte) 0xff: readApplicationExtensionBlock(reader, blockSizeBytes, metadata); break; default: metadata.addDirectory(new ErrorDirectory(String.format("Unsupported GIF extension block with type 0x%02X.", extensionLabel))); break; } long skipCount = blockStartPos + blockSizeBytes - reader.getPosition(); if (skipCount > 0) reader.skip(skipCount); }
magicNumber = reader.getUInt16(); } catch (IOException e) { metadata.addDirectory(new ErrorDirectory("Couldn't determine bitmap type: " + e.getMessage())); return; break; default: metadata.addDirectory(new ErrorDirectory("Invalid BMP magic number 0x" + Integer.toHexString(magicNumber))); return;
@Nullable private static Directory readPlainTextBlock(SequentialReader reader, int blockSizeBytes) throws IOException { // It seems this extension is deprecated. If somebody finds an image with this in it, could implement here. // Just skip the entire block for now. if (blockSizeBytes != 12) return new ErrorDirectory(String.format("Invalid GIF plain text block size. Expected 12, got %d.", blockSizeBytes)); // skip 'blockSizeBytes' bytes reader.skip(12); // keep reading and skipping until a 0 byte is reached skipBlocks(reader); return null; }
protected void addError(@NotNull String errorMessage, final @NotNull Metadata metadata) { ErrorDirectory directory = metadata.getFirstDirectoryOfType(ErrorDirectory.class); if (directory == null) { metadata.addDirectory(new ErrorDirectory(errorMessage)); } else { directory.addError(errorMessage); } } }
public void extract(byte[] segmentBytes, Metadata metadata, JpegSegmentType segmentType) { JpegDirectory directory = metadata.getFirstDirectoryOfType(JpegDirectory.class); if (directory == null) { ErrorDirectory errorDirectory = new ErrorDirectory(); metadata.addDirectory(errorDirectory); errorDirectory.addError("DNL segment found without SOFx - illegal JPEG format"); return; } SequentialReader reader = new SequentialByteArrayReader(segmentBytes); try { // Only set height from DNL if it's not already defined Integer i = directory.getInteger(JpegDirectory.TAG_IMAGE_HEIGHT); if (i == null || i == 0) { directory.setInt(JpegDirectory.TAG_IMAGE_HEIGHT, reader.getUInt16()); } } catch (IOException ex) { directory.addError(ex.getMessage()); } } }
metadata.addDirectory(header); } catch (IOException ex) { metadata.addDirectory(new ErrorDirectory("IOException processing GIF data")); return; metadata.addDirectory(new ErrorDirectory("GIF did not had hasGlobalColorTable bit.")); metadata.addDirectory(new ErrorDirectory("Unknown gif block marker found.")); return; metadata.addDirectory(new ErrorDirectory("IOException processing GIF data"));
metadata.addDirectory(new ErrorDirectory(String.format("Invalid GIF application extension block size. Expected 11, got %d.", blockSizeBytes))); return;
private static void readGifExtensionBlock(SequentialReader reader, Metadata metadata) throws IOException { byte extensionLabel = reader.getInt8(); short blockSizeBytes = reader.getUInt8(); long blockStartPos = reader.getPosition(); switch (extensionLabel) { case (byte) 0x01: Directory plainTextBlock = readPlainTextBlock(reader, blockSizeBytes); if (plainTextBlock != null) metadata.addDirectory(plainTextBlock); break; case (byte) 0xf9: metadata.addDirectory(readControlBlock(reader, blockSizeBytes)); break; case (byte) 0xfe: metadata.addDirectory(readCommentBlock(reader, blockSizeBytes)); break; case (byte) 0xff: readApplicationExtensionBlock(reader, blockSizeBytes, metadata); break; default: metadata.addDirectory(new ErrorDirectory(String.format("Unsupported GIF extension block with type 0x%02X.", extensionLabel))); break; } long skipCount = blockStartPos + blockSizeBytes - reader.getPosition(); if (skipCount > 0) reader.skip(skipCount); }
magicNumber = reader.getUInt16(); } catch (IOException e) { metadata.addDirectory(new ErrorDirectory("Couldn't determine bitmap type: " + e.getMessage())); return; break; default: metadata.addDirectory(new ErrorDirectory("Invalid BMP magic number 0x" + Integer.toHexString(magicNumber))); return;