-
Notifications
You must be signed in to change notification settings - Fork 79
/
resampling_spec.rb
121 lines (94 loc) · 4.36 KB
/
resampling_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
require 'spec_helper'
describe ChunkyPNG::Canvas::Resampling do
subject { reference_canvas('clock') }
describe '#resample_nearest_neighbor' do
it "should downscale from 2x2 to 1x1 correctly" do
canvas = ChunkyPNG::Canvas.new(2, 2, [1, 2, 3, 4])
canvas.resample_nearest_neighbor(1, 1).should == ChunkyPNG::Canvas.new(1, 1, [4])
end
it "should upscale from 2x2 to 4x4 correctly" do
canvas = ChunkyPNG::Canvas.new(2, 2, [1, 2, 3, 4])
canvas.resample_nearest_neighbor(4, 4).should == ChunkyPNG::Canvas.new(4, 4, [1, 1, 2, 2, 1, 1, 2, 2, 3, 3, 4, 4, 3, 3, 4, 4])
end
it "should upscale both axis of the image" do
subject.resample_nearest_neighbor(45, 45).should == reference_canvas('clock_nn_xup_yup')
end
it "should downscale both axis of the image" do
subject.resample_nearest_neighbor(12, 12).should == reference_canvas('clock_nn_xdown_ydown')
end
it "should downscale the x-axis and upscale the y-axis of the image" do
subject.resample_nearest_neighbor(20, 50).should == reference_canvas('clock_nn_xdown_yup')
end
it "should not return itself" do
subject.resample_nearest_neighbor(1, 1).should_not equal(subject)
end
it "should not change the original image's dimensions" do
lambda { subject.resample_nearest_neighbor(1, 1) }.should_not change(subject, :dimension)
end
end
describe '#resample_nearest_neighbor!' do
it "should upscale both axis of the image" do
subject.resample_nearest_neighbor!(45, 45)
subject.should == reference_canvas('clock_nn_xup_yup')
end
it "should downscale both axis of the image" do
subject.resample_nearest_neighbor!(12, 12)
subject.should == reference_canvas('clock_nn_xdown_ydown')
end
it "should downscale the x-axis and upscale the y-axis of the image" do
subject.resample_nearest_neighbor!(20, 50)
subject.should == reference_canvas('clock_nn_xdown_yup')
end
it "should return itself" do
subject.resample_nearest_neighbor!(1, 1).should equal(subject)
end
it "should change the original image's dimensions" do
lambda { subject.resample_nearest_neighbor!(1, 1) }.should change(subject, :dimension).to(ChunkyPNG::Dimension('1x1'))
end
end
describe "#resample_bilinear" do
it "should downscale from 2x2 to 1x1 correctly" do
canvas = ChunkyPNG::Canvas.new(2, 2, [1, 2, 3, 4])
canvas.resample_bilinear(1, 1).should == ChunkyPNG::Canvas.new(1, 1, [2])
end
it "should upscale from 2x2 to 4x4 correctly" do
canvas = ChunkyPNG::Canvas.new(2, 2, [1, 2, 3, 4])
canvas.resample_bilinear(4, 4).should == ChunkyPNG::Canvas.new(4, 4, [1, 2, 1, 2, 2, 2, 2, 2, 2, 3, 3, 4, 3, 3, 4, 4])
end
it "should upscale both axis of the image" do
subject.resample_bilinear(45, 45).should == reference_canvas('clock_bl_xup_yup')
end
it "should downscale both axis of the image" do
subject.resample_bilinear(12, 12).should == reference_canvas('clock_bl_xdown_ydown')
end
it "should downscale the x-axis and upscale the y-axis of the image" do
subject.resample_bilinear(20, 50).should == reference_canvas('clock_bl_xdown_yup')
end
it "should not return itself" do
subject.resample_bilinear(1, 1).should_not equal(subject)
end
it "should not change the original image's dimensions" do
lambda { subject.resample_bilinear(1, 1) }.should_not change(subject, :dimension)
end
end
describe '#resample_bilinear!' do
it "should upscale both axis of the image" do
subject.resample_bilinear!(45, 45)
subject.should == reference_canvas('clock_bl_xup_yup')
end
it "should downscale both axis of the image" do
subject.resample_bilinear!(12, 12)
subject.should == reference_canvas('clock_bl_xdown_ydown')
end
it "should downscale the x-axis and upscale the y-axis of the image" do
subject.resample_bilinear!(20, 50)
subject.should == reference_canvas('clock_bl_xdown_yup')
end
it "should return itself" do
subject.resample_bilinear!(1, 1).should equal(subject)
end
it "should change the original image's dimensions" do
lambda { subject.resample_bilinear!(1, 1) }.should change(subject, :dimension).to(ChunkyPNG::Dimension('1x1'))
end
end
end