gd2-ffij 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +15 -0
- data/COPYRIGHT +2 -1
- data/Gemfile +3 -0
- data/{README → README.rdoc} +28 -15
- data/Rakefile +8 -20
- data/gd2-ffij.gemspec +11 -76
- data/lib/gd2-ffij.rb +4 -5
- data/lib/gd2/canvas.rb +16 -16
- data/lib/gd2/color.rb +1 -1
- data/lib/gd2/ffi_struct.rb +1 -1
- data/lib/gd2/font.rb +29 -27
- data/lib/gd2/image.rb +48 -49
- data/lib/gd2/palette.rb +6 -6
- data/lib/gd2/version.rb +5 -0
- data/test/canvas_tests.rb +176 -181
- data/test/image_tests.rb +135 -140
- data/test/images/test_text.gd2 +0 -0
- data/test/images/test_text_circle.gd2 +0 -0
- data/test/test_helper.rb +16 -8
- metadata +88 -9
- data/VERSION +0 -1
data/test/image_tests.rb
CHANGED
@@ -1,149 +1,144 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'tmpdir'
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'gd2-ffij'
|
6
1
|
|
7
2
|
require './test/test_helper'
|
8
3
|
|
9
4
|
class ImageTest < Test::Unit::TestCase
|
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
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
5
|
+
include TestHelper
|
6
|
+
|
7
|
+
def test_image_new_and_release
|
8
|
+
GD2::Image.new(50, 50)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_image_true_color_new_and_release
|
12
|
+
GD2::Image::TrueColor.new(50, 50)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_image_indexed_color_new_and_release
|
16
|
+
GD2::Image::IndexedColor.new(50, 50)
|
17
|
+
end
|
18
|
+
|
19
|
+
[ :png, :gif, :jpg, :wbmp, :gd2 ].each do |ext|
|
20
|
+
self.class_eval(<<-EOF)
|
21
|
+
def test_load_#{ext}_from_file
|
22
|
+
GD2::Image.load(File.open(File.join(PATH_TO_IMAGES, 'test.#{ext}')))
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_load_#{ext}_from_string
|
26
|
+
GD2::Image.load(File.read(File.join(PATH_TO_IMAGES, 'test.#{ext}')))
|
27
|
+
end
|
28
|
+
EOF
|
29
|
+
end
|
30
|
+
|
31
|
+
# TODO: add xbm, xpm and wbmp tests
|
32
|
+
[ :png, :gif, :jpg, :gd, :gd2 ].each do |ext|
|
33
|
+
self.class_eval(<<-EOF)
|
34
|
+
def test_import_#{ext}_from_file
|
35
|
+
GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_export_#{ext}
|
39
|
+
img = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.gd2'))
|
40
|
+
out = File.join(Dir.tmpdir, 'test.#{ext}')
|
41
|
+
img.export(out)
|
42
|
+
|
43
|
+
assert(File.exists?(out))
|
44
|
+
|
45
|
+
imgA = GD2::Image.import(out)
|
46
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
47
|
+
|
48
|
+
assert(imgA == imgB)
|
49
|
+
|
50
|
+
File.unlink(out)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_compare_#{ext}
|
54
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
55
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
56
|
+
assert_equal(imgA.compare(imgB), 0)
|
57
|
+
assert_equal(imgA.compare(imgA.dup), 0)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_eqeq_#{ext}
|
61
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
62
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
63
|
+
assert(imgA == imgB)
|
64
|
+
assert(imgA == imgA.dup)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_height_#{ext}
|
68
|
+
img = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
69
|
+
assert_equal(img.height, 256)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_width_#{ext}
|
73
|
+
img = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
74
|
+
assert_equal(img.width, 256)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_size_#{ext}
|
78
|
+
img = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
79
|
+
assert_equal(img.size, [ 256, 256 ])
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_aspect_#{ext}
|
83
|
+
img = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
84
|
+
assert_in_delta(img.aspect, 1.0, 0.00000001)
|
85
|
+
end
|
86
|
+
EOF
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_rotate
|
90
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.gd2')).rotate!(Math::PI)
|
91
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_rotated_180.gd2'))
|
92
|
+
|
93
|
+
assert(imgA == imgB)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_crop
|
97
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.gd2')).crop!(64, 64, 128, 128)
|
98
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_cropped.gd2'))
|
99
|
+
|
100
|
+
assert(imgA == imgB)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_uncrop
|
104
|
+
img = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.gd2')).crop!(64, 64, 128, 128)
|
105
|
+
img.uncrop!(64)
|
106
|
+
|
107
|
+
assert_equal(img.size, [ 256, 256 ])
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_resize
|
111
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.gd2')).resize!(512, 512)
|
112
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_resized.gd2'))
|
113
|
+
|
114
|
+
assert(imgA == imgB)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_resampled
|
118
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.gd2')).resize!(512, 512, true)
|
119
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_resampled.gd2'))
|
120
|
+
|
121
|
+
assert(imgA == imgB)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_polar_transform
|
125
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.gd2')).polar_transform!(100)
|
126
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_polar_transform.gd2'))
|
127
|
+
|
128
|
+
assert(imgA == imgB)
|
129
|
+
end
|
135
130
|
|
136
|
-
|
137
|
-
|
138
|
-
|
131
|
+
def test_color_sharpened
|
132
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_color.gd2')).sharpen(100)
|
133
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_color_sharpened.gd2'))
|
139
134
|
|
140
|
-
|
141
|
-
|
135
|
+
assert(imgA == imgB)
|
136
|
+
end
|
142
137
|
|
143
|
-
|
144
|
-
|
145
|
-
|
138
|
+
def test_to_indexed_color
|
139
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_color.gd2')).to_indexed_color
|
140
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_color_indexed.gd2'))
|
146
141
|
|
147
|
-
|
148
|
-
|
142
|
+
assert(imgA == imgB)
|
143
|
+
end
|
149
144
|
end
|
data/test/images/test_text.gd2
CHANGED
Binary file
|
Binary file
|
data/test/test_helper.rb
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
|
2
|
+
require 'test/unit'
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'gd2-ffij'
|
7
|
+
|
8
|
+
puts "GD2 version: #{GD2::VERSION}"
|
9
|
+
|
2
10
|
module TestHelper
|
3
|
-
|
4
|
-
|
11
|
+
PATH_TO_IMAGES = File.join(File.dirname(__FILE__), 'images')
|
12
|
+
PATH_TO_FONT = File.join(File.dirname(__FILE__), '..', 'vendor', 'fonts', 'ttf', 'DejaVuSans.ttf')
|
5
13
|
|
6
|
-
|
7
|
-
|
8
|
-
|
14
|
+
def new_image
|
15
|
+
GD2::Image.new(256, 256)
|
16
|
+
end
|
9
17
|
|
10
|
-
|
11
|
-
|
12
|
-
|
18
|
+
def load_image(file_name)
|
19
|
+
GD2::Image.load(File.read(File.join(PATH_TO_IMAGES, file_name)))
|
20
|
+
end
|
13
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gd2-ffij
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,19 +21,57 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.9'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
25
62
|
description: gd2-ffij is a refactoring of the Ruby/GD2 library implemented with FFI
|
26
63
|
email: dark.panda@gmail.com
|
27
64
|
executables: []
|
28
65
|
extensions: []
|
29
66
|
extra_rdoc_files:
|
30
|
-
- README
|
67
|
+
- README.rdoc
|
31
68
|
files:
|
69
|
+
- .gitignore
|
32
70
|
- COPYING
|
33
71
|
- COPYRIGHT
|
34
|
-
-
|
72
|
+
- Gemfile
|
73
|
+
- README.rdoc
|
35
74
|
- Rakefile
|
36
|
-
- VERSION
|
37
75
|
- gd2-ffij.gemspec
|
38
76
|
- lib/gd2-ffij.rb
|
39
77
|
- lib/gd2/canvas.rb
|
@@ -42,6 +80,7 @@ files:
|
|
42
80
|
- lib/gd2/font.rb
|
43
81
|
- lib/gd2/image.rb
|
44
82
|
- lib/gd2/palette.rb
|
83
|
+
- lib/gd2/version.rb
|
45
84
|
- test/canvas_tests.rb
|
46
85
|
- test/image_tests.rb
|
47
86
|
- test/images/test.bmp
|
@@ -104,8 +143,48 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
143
|
version: '0'
|
105
144
|
requirements: []
|
106
145
|
rubyforge_project:
|
107
|
-
rubygems_version: 1.8.
|
146
|
+
rubygems_version: 1.8.23
|
108
147
|
signing_key:
|
109
148
|
specification_version: 3
|
110
149
|
summary: gd2-ffij is a refactoring of the Ruby/GD2 library implemented with FFI
|
111
|
-
test_files:
|
150
|
+
test_files:
|
151
|
+
- test/canvas_tests.rb
|
152
|
+
- test/image_tests.rb
|
153
|
+
- test/images/test.bmp
|
154
|
+
- test/images/test.gd
|
155
|
+
- test/images/test.gd2
|
156
|
+
- test/images/test.gif
|
157
|
+
- test/images/test.jpg
|
158
|
+
- test/images/test.png
|
159
|
+
- test/images/test.wbmp
|
160
|
+
- test/images/test.xbm
|
161
|
+
- test/images/test.xcf
|
162
|
+
- test/images/test.xpm
|
163
|
+
- test/images/test_arc.gd2
|
164
|
+
- test/images/test_canvas_filled_polygon.gd2
|
165
|
+
- test/images/test_canvas_filled_rectangle.gd2
|
166
|
+
- test/images/test_canvas_line.gd2
|
167
|
+
- test/images/test_canvas_move_to_and_line_to.gd2
|
168
|
+
- test/images/test_canvas_polygon.gd2
|
169
|
+
- test/images/test_canvas_rectangle.gd2
|
170
|
+
- test/images/test_circle.gd2
|
171
|
+
- test/images/test_color.gd2
|
172
|
+
- test/images/test_color.png
|
173
|
+
- test/images/test_color.xcf
|
174
|
+
- test/images/test_color_indexed.gd2
|
175
|
+
- test/images/test_color_sharpened.gd2
|
176
|
+
- test/images/test_cropped.gd2
|
177
|
+
- test/images/test_ellipse.gd2
|
178
|
+
- test/images/test_fill.gd2
|
179
|
+
- test/images/test_fill_to.gd2
|
180
|
+
- test/images/test_filled_circle.gd2
|
181
|
+
- test/images/test_filled_ellipse.gd2
|
182
|
+
- test/images/test_filled_wedge.gd2
|
183
|
+
- test/images/test_polar_transform.gd2
|
184
|
+
- test/images/test_resampled.gd2
|
185
|
+
- test/images/test_resized.gd2
|
186
|
+
- test/images/test_rotated_180.gd2
|
187
|
+
- test/images/test_text.gd2
|
188
|
+
- test/images/test_text_circle.gd2
|
189
|
+
- test/images/test_wedge.gd2
|
190
|
+
- test/test_helper.rb
|