class EmbedXMP::JFIF

JPEG File Interchange Format (container format for JPEG)

Constants

JFIF_END
JFIF_SOI

Public Instance Methods

check_file_markers() click to toggle source

Check if file has JFIF markers.

# File lib/embed_xmp/jfif.rb, line 15
def check_file_markers
  raise 'NoJPEGStartOfFile' if JFIF_SOI != @image_data[0..1]
  raise 'NoJPEGEndOfFile' if JFIF_END != @image_data[-2..-1]
end
new_segment(marker, data) click to toggle source
# File lib/embed_xmp/jfif.rb, line 39
def new_segment(marker, data)
  raise 'SegmentMarkerNotTwoBytes' if marker.length != 2
  raise 'SegmentMarkerDoesNotBeginWithNullByte' if marker == '\b'.b

  length = [2 + data.length].pack('n')

  marker + length + data
end
remove_segment(offset) click to toggle source

Remove the chunk at offset from the beginning of the file.

# File lib/embed_xmp/jfif.rb, line 33
def remove_segment(offset)
  _, length, = segment(offset)

  @image_data.slice!(offset, length)
end
segment(offset) click to toggle source

Return segment at offset from the beginning of the file.

# File lib/embed_xmp/jfif.rb, line 21
def segment(offset)
  marker = @image_data[offset, 2]
  length = @image_data[offset + 2, 2].b.unpack1('n') + 2

  raise 'SegmentExceedFileLength' if offset + length > @image_data.length

  data = @image_data[offset + 2, length]

  [marker, length, data]
end