Skip to content

Commit

Permalink
encoding for filter 2
Browse files Browse the repository at this point in the history
  • Loading branch information
aberant committed Nov 29, 2009
1 parent df2f760 commit 8286908
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/spittle/filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def encode( filter_type, value, index, row, last_row, record_width )
when 1
#left
(value - fetch_pixel(index - record_width, row)) % 256
when 2
#up
(value - fetch_pixel(index, last_row)) % 256
when 4
#paeth
left = fetch_pixel(index - record_width, row)
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@
# second byte of pixel 2 - pixel 1 is 3.. etc
image.filter_encoded_rows(1).should == [[1, 1, 2, 3, 3, 3, 3]]
end

it "can encode the rows with filter 2" do
image = @builder.build( :width => 2, :height => 1, :name => "image1", :data => [0,1,2,3,4,5,6] )
result = image.fill_to_height(2)

# filter byte of 2
result.filter_encoded_rows(2).should == [[2, 1, 2, 3, 4, 5, 6], [2, 255, 254, 253, 252, 251, 250]]
end
end

0 comments on commit 8286908

Please sign in to comment.