Permalink
Browse files

m17n cargo cult. yob, plz investigate

  • Loading branch information...
1 parent c9018a0 commit 2478ff8c26fa91a83ac35878514b65832ba80b0d @practicingruby practicingruby committed Aug 11, 2008
Showing with 16 additions and 12 deletions.
  1. +6 −6 lib/prawn/images/png.rb
  2. +6 −6 spec/png_spec.rb
  3. +4 −0 spec/spec_helper.rb
View
@@ -1,4 +1,4 @@
-# encoding: utf-8
+# encoding: ASCII-8BIT
# png.rb : Extracts the data from a PNG that is needed for embedding
#
@@ -125,28 +125,28 @@ def unfilter_image_data
row_data = data.slice! 0, scanline_length
filter = row_data.shift
case filter
- when 0 then # None
- when 1 then # Sub
+ when 0 # None
+ when 1 # Sub
row_data.each_with_index do |byte, index|
left = index < pixel_length ? 0 : row_data[index - pixel_length]
row_data[index] = (byte + left) % 256
#p [byte, left, row_data[index]]
end
- when 2 then # Up
+ when 2 # Up
row_data.each_with_index do |byte, index|
col = index / pixel_length
upper = row == 0 ? 0 : pixels[row-1][col][index % pixel_length]
row_data[index] = (upper + byte) % 256
end
- when 3 then # Average
+ when 3 # Average
row_data.each_with_index do |byte, index|
col = index / pixel_length
upper = row == 0 ? 0 : pixels[row-1][col][index % pixel_length]
left = index < pixel_length ? 0 : row_data[index - pixel_length]
row_data[index] = (byte + ((left + upper)/2).floor) % 256
end
- when 4 then # Paeth
+ when 4 # Paeth
left = upper = upper_left = nil
row_data.each_with_index do |byte, index|
col = index / pixel_length
View
@@ -1,4 +1,4 @@
-# encoding: utf-8
+# encoding: ASCII-8BIT
# Spec'ing the PNG class. Not complete yet - still needs to check the
# contents of palette and transparency to ensure they're correct.
@@ -115,13 +115,13 @@
it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
png = Prawn::Images::PNG.new(@img_data)
- data = File.open(@data_filename, "rb") { |f| f.read }
+ data = File.open(@data_filename, rb_flag) { |f| f.read }
png.img_data.should == data
end
it "should correctly extract the alpha channel data from the image data chunk" do
png = Prawn::Images::PNG.new(@img_data)
- data = File.open(@alpha_data_filename, "rb") { |f| f.read }
+ data = File.open(@alpha_data_filename, rb_flag) { |f| f.read }
png.alpha_channel.should == data
end
end
@@ -132,7 +132,7 @@
@filename = "#{Prawn::BASEDIR}/data/images/dice.png"
@data_filename = "#{Prawn::BASEDIR}/data/images/dice.dat"
@alpha_data_filename = "#{Prawn::BASEDIR}/data/images/dice.alpha"
- @img_data = File.open(@filename, "rb") { |f| f.read }
+ @img_data = File.open(@filename, "rb") { |f| f.read }
end
it "should read the attributes from the header chunk correctly" do
@@ -149,13 +149,13 @@
it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
png = Prawn::Images::PNG.new(@img_data)
- data = File.open(@data_filename, "rb") { |f| f.read }
+ data = File.open(@data_filename, rb_flag) { |f| f.read }
png.img_data.should == data
end
it "should correctly extract the alpha channel data from the image data chunk" do
png = Prawn::Images::PNG.new(@img_data)
- data = File.open(@alpha_data_filename, "rb") { |f| f.read }
+ data = File.open(@alpha_data_filename, rb_flag) { |f| f.read }
png.alpha_channel.should == data
end
end
View
@@ -33,4 +33,8 @@ def observer(klass)
def parse_pdf_object(obj)
PDF::Reader::Parser.new(
PDF::Reader::Buffer.new(sio = StringIO.new(obj)), nil).parse_token
+end
+
+def rb_flag
+ ruby_18 { "rb" } || ruby_19 { "rb:ASCII-8BIT" }
end

0 comments on commit 2478ff8

Please sign in to comment.