Skip to content

Commit

Permalink
m17n cargo cult. yob, plz investigate
Browse files Browse the repository at this point in the history
  • Loading branch information
practicingruby committed Aug 11, 2008
1 parent c9018a0 commit 2478ff8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/prawn/images/png.rb
@@ -1,4 +1,4 @@
# encoding: utf-8
# encoding: ASCII-8BIT

# png.rb : Extracts the data from a PNG that is needed for embedding
#
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions spec/png_spec.rb
@@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -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.