Permalink
Browse files

Set bounds correctly, add tests

  • Loading branch information...
1 parent 964d42f commit 20a305b3d86bf2e531d06212c562025e8e12a530 @natemueller natemueller committed Feb 15, 2013
Showing with 15 additions and 3 deletions.
  1. +1 −1 ext/oily_png/resampling.c
  2. +14 −2 spec/resampling_spec.rb
@@ -183,7 +183,7 @@ VALUE oily_png_canvas_resample_bilinear_bang(VALUE self, VALUE v_new_width, VALU
for (x = 0; x < new_width; x++) {
x1 = index_x[x] < 0 ? 0 : index_x[x];
- x2 = x1+1 >= self_height ? self_height-1 : x1+1;
+ x2 = x1+1 >= self_width ? self_height-1 : x1+1;
x_residue = interp_x[x];
pixel_11 = NUM2LONG(rb_ary_entry(source, y1*self_width + x1));
View
@@ -25,15 +25,27 @@
end
it "should resample [0,1,2,3] to 99x45 as ChunkyPNG does" do
- ChunkyPNG::Canvas.new(2,2,[0,1,2,3]).resample_nearest_neighbor(99,45).should == OilyPNG::Canvas.new(2,2,[0,1,2,3]).resample_nearest_neighbor(99,45)
+ ChunkyPNG::Canvas.new(2,2,[0,1,2,3]).resample_nearest_neighbor(99,45).should == OilyPNG::Canvas.new(2,2,[0,1,2,3]).resample_nearest_neighbor(99,45)
end
it "should resample an image to 10x20 as ChunkyPNG does" do
@reference.resample_nearest_neighbor(10,20).should == OilyPNG::Canvas.from_canvas(@reference).resample_nearest_neighbor(10,20)
end
-
+
it "should resample an image to 11x19 as ChunkyPNG does" do
@reference.resample_nearest_neighbor(11,19).should == OilyPNG::Canvas.from_canvas(@reference).resample_nearest_neighbor(11,19)
end
end
+
+ describe '#resample_bilinear!' do
+ before(:all) { @reference = ChunkyPNG::Canvas.from_file(resource_file('nonsquare.png'))}
+
+ it "should resample an image to 10x20 as ChunkyPNG does" do
+ @reference.resample_bilinear(10,20).should == OilyPNG::Canvas.from_canvas(@reference).resample_bilinear(10,20)
+ end
+
+ it "should resample an image to 11x19 as ChunkyPNG does" do
+ @reference.resample_bilinear(11,19).should == OilyPNG::Canvas.from_canvas(@reference).resample_bilinear(11,19)
+ end
+ end
end

0 comments on commit 20a305b

Please sign in to comment.