lib/prawn/images/jpg.rb in prawn-2.3.0 vs lib/prawn/images/jpg.rb in prawn-2.4.0

- old
+ new

@@ -14,10 +14,12 @@ module Images # A convenience class that wraps the logic for extracting the parts # of a JPG image that we need to embed them in a PDF # class JPG < Image + class FormatError < StandardError; end + # @group Extension API attr_reader :width, :height, :bits, :channels attr_accessor :scaled_width, :scaled_height @@ -33,18 +35,19 @@ # Process a new JPG image # # <tt>:data</tt>:: A binary string of JPEG data # def initialize(data) + super() @data = data d = StringIO.new(@data) d.binmode c_marker = 0xff # Section marker. d.seek(2) # Skip the first two bytes of JPEG identifier. loop do marker, code, length = d.read(4).unpack('CCn') - raise 'JPEG marker not found!' if marker != c_marker + raise FormatError, 'JPEG marker not found!' if marker != c_marker if JPEG_SOF_BLOCKS.include?(code) @bits, @height, @width, @channels = d.read(6).unpack('CnnC') break end