lib/prawn/images/jpg.rb in prawn-0.13.0 vs lib/prawn/images/jpg.rb in prawn-0.13.1

- old
+ new

@@ -15,37 +15,36 @@ # class JPG < Image attr_reader :width, :height, :bits, :channels attr_accessor :scaled_width, :scaled_height - JPEG_SOF_BLOCKS = %W(\xc0 \xc1 \xc2 \xc3 \xc5 \xc6 \xc7 \xc9 \xca \xcb \xcd \xce \xcf) - JPEG_APP_BLOCKS = %W(\xe0 \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea \xeb \xec \xed \xee \xef) + JPEG_SOF_BLOCKS = [0xC0, 0xC1, 0xC2, 0xC3, 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCD, 0xCE, 0xCF] def self.can_render?(image_blob) image_blob[0, 3].unpack("C*") == [255, 216, 255] end # Process a new JPG image # # <tt>:data</tt>:: A binary string of JPEG data # def initialize(data) - @data = data.dup - ruby_19 { data.force_encoding("binary") } - data = StringIO.new(data) + @data = data + d = StringIO.new(@data) + d.binmode - c_marker = "\xff" # Section marker. - data.read(2) # Skip the first two bytes of JPEG identifier. + c_marker = 0xff # Section marker. + d.seek(2) # Skip the first two bytes of JPEG identifier. loop do - marker, code, length = data.read(4).unpack('aan') + marker, code, length = d.read(4).unpack('CCn') raise "JPEG marker not found!" if marker != c_marker if JPEG_SOF_BLOCKS.include?(code) - @bits, @height, @width, @channels = data.read(6).unpack("CnnC") + @bits, @height, @width, @channels = d.read(6).unpack("CnnC") break end - data.read(length - 2) + d.seek(length - 2, IO::SEEK_CUR) end end # Build a PDF object representing this image in +document+, and return # a Reference to it.