gd2-ffij 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/gd2-ffij.gemspec +4 -4
- data/lib/gd2-ffij.rb +13 -7
- data/lib/gd2/canvas.rb +20 -20
- data/lib/gd2/color.rb +1 -1
- data/lib/gd2/font.rb +16 -20
- data/lib/gd2/image.rb +36 -26
- data/lib/gd2/palette.rb +6 -6
- data/test/canvas_test.rb +177 -177
- data/test/image_test.rb +136 -136
- data/test/test_helper.rb +4 -4
- metadata +9 -4
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ begin
|
|
10
10
|
require 'jeweler'
|
11
11
|
Jeweler::Tasks.new do |gem|
|
12
12
|
gem.name = "gd2-ffij"
|
13
|
-
gem.version = "0.0.
|
13
|
+
gem.version = "0.0.3"
|
14
14
|
gem.summary = "gd2-ffij is a refactoring of the Ruby/GD2 library implemented with FFI"
|
15
15
|
gem.description = "gd2-ffij is a refactoring of the Ruby/GD2 library implemented with FFI"
|
16
16
|
gem.email = "dark.panda@gmail.com"
|
data/gd2-ffij.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{gd2-ffij}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["J Smith"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-11}
|
13
13
|
s.description = %q{gd2-ffij is a refactoring of the Ruby/GD2 library implemented with FFI}
|
14
14
|
s.email = %q{dark.panda@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -75,7 +75,7 @@ Gem::Specification.new do |s|
|
|
75
75
|
s.homepage = %q{http://github.com/dark-panda/gd2-ffij}
|
76
76
|
s.rdoc_options = ["--charset=UTF-8"]
|
77
77
|
s.require_paths = ["lib"]
|
78
|
-
s.rubygems_version = %q{1.3.
|
78
|
+
s.rubygems_version = %q{1.3.7}
|
79
79
|
s.summary = %q{gd2-ffij is a refactoring of the Ruby/GD2 library implemented with FFI}
|
80
80
|
s.test_files = [
|
81
81
|
"test/canvas_test.rb",
|
@@ -87,7 +87,7 @@ Gem::Specification.new do |s|
|
|
87
87
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
88
88
|
s.specification_version = 3
|
89
89
|
|
90
|
-
if Gem::Version.new(Gem::
|
90
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
91
91
|
else
|
92
92
|
end
|
93
93
|
else
|
data/lib/gd2-ffij.rb
CHANGED
@@ -24,17 +24,23 @@ require 'ffi'
|
|
24
24
|
require 'rbconfig'
|
25
25
|
|
26
26
|
module GD2
|
27
|
-
VERSION = '0.0.
|
27
|
+
VERSION = '0.0.3'.freeze
|
28
28
|
|
29
29
|
module GD2FFI
|
30
30
|
def self.gd_library_name
|
31
|
-
|
32
|
-
|
33
|
-
'libgd.2.dylib'
|
34
|
-
when /mswin32/, /cygwin/
|
35
|
-
'bgd.dll'
|
31
|
+
if ENV['GD2_LIBRARY_PATH']
|
32
|
+
ENV['GD2_LIBRARY_PATH']
|
36
33
|
else
|
37
|
-
'
|
34
|
+
lib = case Config::CONFIG['arch']
|
35
|
+
when /darwin/
|
36
|
+
[ '/usr/lib', '/usr/local/lib', '/opt/local/lib' ].detect { |path|
|
37
|
+
File.exists?("#{path}/libgd.2.dylib")
|
38
|
+
}.to_s + '/libgd.2.dylib'
|
39
|
+
when /mswin32/, /cygwin/
|
40
|
+
'bgd.dll'
|
41
|
+
else
|
42
|
+
'libgd.so.2'
|
43
|
+
end
|
38
44
|
end
|
39
45
|
end
|
40
46
|
|
data/lib/gd2/canvas.rb
CHANGED
@@ -59,7 +59,7 @@ module GD2
|
|
59
59
|
|
60
60
|
def draw(image, mode)
|
61
61
|
GD2FFI.send(:gdImageLine, image.image_ptr,
|
62
|
-
@p1.x, @p1.y, @p2.x, @p2.y, mode)
|
62
|
+
@p1.x.to_i, @p1.y.to_i, @p2.x.to_i, @p2.y.to_i, mode.to_i)
|
63
63
|
nil
|
64
64
|
end
|
65
65
|
end
|
@@ -70,7 +70,7 @@ module GD2
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def draw(image, mode)
|
73
|
-
GD2FFI.send(draw_sym, image.image_ptr, @p1.x, @p1.y, @p2.x, @p2.y, mode)
|
73
|
+
GD2FFI.send(draw_sym, image.image_ptr, @p1.x.to_i, @p1.y.to_i, @p2.x.to_i, @p2.y.to_i, mode.to_i)
|
74
74
|
nil
|
75
75
|
end
|
76
76
|
|
@@ -93,7 +93,7 @@ module GD2
|
|
93
93
|
def draw(image, mode)
|
94
94
|
GD2FFI.send(draw_sym, image.image_ptr, @points.map { |point|
|
95
95
|
point.coordinates.pack('i_i_')
|
96
|
-
}.join(''), @points.length, mode)
|
96
|
+
}.join(''), @points.length, mode.to_i)
|
97
97
|
nil
|
98
98
|
end
|
99
99
|
|
@@ -122,9 +122,9 @@ module GD2
|
|
122
122
|
end
|
123
123
|
|
124
124
|
def draw(image, mode)
|
125
|
-
GD2FFI.send(:gdImageArc, image.image_ptr, @center.x, @center.y,
|
126
|
-
@width, @height,
|
127
|
-
@range.begin.to_degrees.round, @range.end.to_degrees.round, mode)
|
125
|
+
GD2FFI.send(:gdImageArc, image.image_ptr, @center.x.to_i, @center.y.to_i,
|
126
|
+
@width.to_i, @height.to_i,
|
127
|
+
@range.begin.to_degrees.round.to_i, @range.end.to_degrees.round.to_i, mode.to_i)
|
128
128
|
nil
|
129
129
|
end
|
130
130
|
end
|
@@ -144,10 +144,10 @@ module GD2
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def draw(image, mode)
|
147
|
-
GD2FFI.send(:gdImageFilledArc, image.image_ptr, @center.x, @center.y,
|
148
|
-
@width, @height,
|
149
|
-
@range.begin.to_degrees.round, @range.end.to_degrees.round,
|
150
|
-
mode, style)
|
147
|
+
GD2FFI.send(:gdImageFilledArc, image.image_ptr, @center.x.to_i, @center.y.to_i,
|
148
|
+
@width.to_i, @height.to_i,
|
149
|
+
@range.begin.to_degrees.round.to_i, @range.end.to_degrees.round.to_i,
|
150
|
+
mode.to_i, style.to_i)
|
151
151
|
nil
|
152
152
|
end
|
153
153
|
|
@@ -168,16 +168,16 @@ module GD2
|
|
168
168
|
end
|
169
169
|
|
170
170
|
def draw(image, mode)
|
171
|
-
GD2FFI.send(:gdImageArc, image.image_ptr, @center.x, @center.y,
|
172
|
-
@width, @height, 0, 360, mode)
|
171
|
+
GD2FFI.send(:gdImageArc, image.image_ptr, @center.x.to_i, @center.y.to_i,
|
172
|
+
@width.to_i, @height.to_i, 0, 360, mode.to_i)
|
173
173
|
nil
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
177
177
|
class FilledEllipse < Ellipse
|
178
178
|
def draw(image, mode)
|
179
|
-
GD2FFI.send(:gdImageFilledEllipse, image.image_ptr, @center.x, @center.y,
|
180
|
-
@width, @height, mode)
|
179
|
+
GD2FFI.send(:gdImageFilledEllipse, image.image_ptr, @center.x.to_i, @center.y.to_i,
|
180
|
+
@width.to_i, @height.to_i, mode.to_i)
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
@@ -240,7 +240,7 @@ module GD2
|
|
240
240
|
end
|
241
241
|
|
242
242
|
def thickness=(thickness)
|
243
|
-
GD2FFI.send(:gdImageSetThickness, @image.image_ptr, @thickness = thickness)
|
243
|
+
GD2FFI.send(:gdImageSetThickness, @image.image_ptr, @thickness = thickness.to_i)
|
244
244
|
end
|
245
245
|
|
246
246
|
def style=(ary)
|
@@ -331,14 +331,14 @@ module GD2
|
|
331
331
|
end
|
332
332
|
|
333
333
|
def fill
|
334
|
-
GD2FFI.send(:gdImageFill, @image.image_ptr, @point.x, @point.y, fill_pixel)
|
334
|
+
GD2FFI.send(:gdImageFill, @image.image_ptr, @point.x.to_i, @point.y.to_i, fill_pixel.to_i)
|
335
335
|
self
|
336
336
|
end
|
337
337
|
|
338
338
|
def fill_to(border)
|
339
339
|
# An apparent bug in gd prevents us from using fill_pixel
|
340
|
-
GD2FFI.send(:gdImageFillToBorder, @image.image_ptr, @point.x, @point.y,
|
341
|
-
@image.color2pixel(border), pixel)
|
340
|
+
GD2FFI.send(:gdImageFillToBorder, @image.image_ptr, @point.x.to_i, @point.y.to_i,
|
341
|
+
@image.color2pixel(border), pixel.to_i)
|
342
342
|
self
|
343
343
|
end
|
344
344
|
|
@@ -405,9 +405,9 @@ module GD2
|
|
405
405
|
elsif anti_aliasing?
|
406
406
|
if @dont_blend
|
407
407
|
GD2FFI.send(:gdImageSetAntiAliasedDontBlend, @image.image_ptr,
|
408
|
-
pixel, @dont_blend)
|
408
|
+
pixel.to_i, @dont_blend.to_i)
|
409
409
|
else
|
410
|
-
GD2FFI.send(:gdImageSetAntiAliased, @image.image_ptr, pixel)
|
410
|
+
GD2FFI.send(:gdImageSetAntiAliased, @image.image_ptr, pixel.to_i)
|
411
411
|
end
|
412
412
|
ANTI_ALIASED
|
413
413
|
else
|
data/lib/gd2/color.rb
CHANGED
@@ -215,7 +215,7 @@ module GD2
|
|
215
215
|
# Alpha blend this color with the given color. If this color is associated
|
216
216
|
# with a palette entry, this also modifies the palette.
|
217
217
|
def alpha_blend!(other)
|
218
|
-
self.rgba = GD2FFI.send(:gdAlphaBlend, rgba, other.rgba)
|
218
|
+
self.rgba = GD2FFI.send(:gdAlphaBlend, rgba.to_i, other.rgba.to_i)
|
219
219
|
self
|
220
220
|
end
|
221
221
|
alias << alpha_blend!
|
data/lib/gd2/font.rb
CHANGED
@@ -58,7 +58,7 @@ module GD2
|
|
58
58
|
angle == 0.degrees || angle == 90.degrees
|
59
59
|
|
60
60
|
GD2FFI.send(angle > 0 ? :gdImageStringUp : :gdImageString, image_ptr,
|
61
|
-
font_ptr, x, y, string, fg)
|
61
|
+
font_ptr, x.to_i, y.to_i, string, fg.to_i)
|
62
62
|
nil
|
63
63
|
end
|
64
64
|
end
|
@@ -114,19 +114,17 @@ module GD2
|
|
114
114
|
@@fontconfig = false
|
115
115
|
|
116
116
|
def self.register(font) #:nodoc:
|
117
|
-
Thread.
|
117
|
+
Thread.exclusive do
|
118
|
+
count = @@fontcount
|
119
|
+
@@fontcount += 1
|
118
120
|
|
119
|
-
|
120
|
-
|
121
|
+
if count.zero?
|
122
|
+
raise FreeTypeError, 'FreeType library failed to initialize' unless
|
123
|
+
GD2FFI.send(:gdFontCacheSetup).zero?
|
124
|
+
end
|
121
125
|
|
122
|
-
|
123
|
-
raise FreeTypeError, 'FreeType library failed to initialize' unless
|
124
|
-
GD2FFI.send(:gdFontCacheSetup).zero?
|
126
|
+
ObjectSpace.define_finalizer(font, font_finalizer)
|
125
127
|
end
|
126
|
-
|
127
|
-
ObjectSpace.define_finalizer(font, font_finalizer)
|
128
|
-
ensure
|
129
|
-
Thread.critical = false
|
130
128
|
end
|
131
129
|
|
132
130
|
def self.font_finalizer
|
@@ -134,12 +132,10 @@ module GD2
|
|
134
132
|
end
|
135
133
|
|
136
134
|
def self.unregister
|
137
|
-
Thread.
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
ensure
|
142
|
-
Thread.critical = false
|
135
|
+
Thread.exclusive do
|
136
|
+
@@fontcount -= 1
|
137
|
+
GD2FFI.send(:gdFontCacheShutdown) if @@fontcount.zero?
|
138
|
+
end
|
143
139
|
end
|
144
140
|
|
145
141
|
private_class_method :font_finalizer, :unregister
|
@@ -253,7 +249,7 @@ module GD2
|
|
253
249
|
def draw(image_ptr, x, y, angle, string, fg) #:nodoc:
|
254
250
|
brect = FFI::MemoryPointer.new(:int, 8)
|
255
251
|
strex = strex(true)
|
256
|
-
args = [ image_ptr, brect, fg, @fontname, @ptsize, angle.to_f, x, y, string.gsub('&', '&'), strex ]
|
252
|
+
args = [ image_ptr, brect, fg, @fontname, @ptsize, angle.to_f, x.to_i, y.to_i, string.gsub('&', '&'), strex ]
|
257
253
|
|
258
254
|
r = GD2FFI.send(:gdImageStringFTEx, *args)
|
259
255
|
raise FreeTypeError.new(r.read_string) unless r.null?
|
@@ -290,9 +286,9 @@ module GD2
|
|
290
286
|
top, bottom, fgcolor
|
291
287
|
) #:nodoc:
|
292
288
|
r = GD2FFI.send(
|
293
|
-
:gdImageStringFTCircle, image_ptr, cx, cy,
|
289
|
+
:gdImageStringFTCircle, image_ptr, cx.to_i, cy.to_i,
|
294
290
|
radius.to_f, text_radius.to_f, fill_portion.to_f, @fontname, @ptsize,
|
295
|
-
top || '', bottom || '', fgcolor
|
291
|
+
top || '', bottom || '', fgcolor.to_i
|
296
292
|
)
|
297
293
|
raise FreeTypeError.new(r.read_string) unless r.null?
|
298
294
|
nil
|
data/lib/gd2/image.rb
CHANGED
@@ -88,12 +88,14 @@ module GD2
|
|
88
88
|
# automatically (JPEG, PNG, GIF, WBMP, or GD2). The resulting image will be
|
89
89
|
# either of class Image::TrueColor or Image::IndexedColor.
|
90
90
|
def self.load(src)
|
91
|
+
src = src.force_encoding("BINARY") if src.respond_to? :force_encoding
|
91
92
|
case src
|
92
93
|
when File
|
93
94
|
pos = src.pos
|
94
95
|
magic = src.read(4)
|
95
96
|
src.pos = pos
|
96
97
|
data = src.read
|
98
|
+
data = data.force_encoding("BINARY") if data.respond_to? :force_encoding
|
97
99
|
args = [ data.length, data ]
|
98
100
|
when String
|
99
101
|
magic = src
|
@@ -124,16 +126,23 @@ module GD2
|
|
124
126
|
end
|
125
127
|
|
126
128
|
def self.data_type(str)
|
127
|
-
|
128
|
-
|
129
|
+
ct = 0
|
130
|
+
mgc = ""
|
131
|
+
str.each_byte do |byte|
|
132
|
+
break if ct == 4
|
133
|
+
mgc << byte.to_s
|
134
|
+
ct += 1
|
135
|
+
end
|
136
|
+
case mgc
|
137
|
+
when "255216255224"
|
129
138
|
:jpeg
|
130
|
-
when
|
139
|
+
when "137807871"
|
131
140
|
:png
|
132
|
-
when
|
141
|
+
when "71737056"
|
133
142
|
:gif
|
134
|
-
when
|
143
|
+
when "001300"
|
135
144
|
:wbmp
|
136
|
-
when
|
145
|
+
when "103100500"
|
137
146
|
:gd2
|
138
147
|
end
|
139
148
|
end
|
@@ -173,7 +182,7 @@ module GD2
|
|
173
182
|
raise ArgumentError, 'Missing required option :height' if height.nil?
|
174
183
|
# TODO:
|
175
184
|
ptr = File.open(filename, 'rb') do |file|
|
176
|
-
GD2FFI.send(:gdImageCreateFromGd2Part, file, x, y, width, height)
|
185
|
+
GD2FFI.send(:gdImageCreateFromGd2Part, file, x.to_i, y.to_i, width.to_i, height.to_i)
|
177
186
|
end
|
178
187
|
else
|
179
188
|
raise ArgumentError, "Unexpected options #{options.inspect}" unless
|
@@ -191,6 +200,7 @@ module GD2
|
|
191
200
|
'Format (or file extension) is not recognized' unless create_sym
|
192
201
|
|
193
202
|
file = File.read(filename)
|
203
|
+
file = file.force_encoding("BINARY") if file.respond_to? :force_encoding
|
194
204
|
file_ptr = FFI::MemoryPointer.new(file.size, 1, false)
|
195
205
|
file_ptr.put_bytes(0, file)
|
196
206
|
|
@@ -212,7 +222,7 @@ module GD2
|
|
212
222
|
private_class_method :image_true_color?
|
213
223
|
|
214
224
|
def self.create_image_ptr(sx, sy, alpha_blending = true) #:nodoc:
|
215
|
-
ptr = FFIStruct::ImagePtr.new(GD2FFI.send(create_image_sym, sx, sy))
|
225
|
+
ptr = FFIStruct::ImagePtr.new(GD2FFI.send(create_image_sym, sx.to_i, sy.to_i))
|
216
226
|
GD2FFI.send(:gdImageAlphaBlending, ptr, alpha_blending ? 1 : 0)
|
217
227
|
ptr
|
218
228
|
end
|
@@ -287,13 +297,13 @@ module GD2
|
|
287
297
|
|
288
298
|
# Return the pixel value at image location (+x+, +y+).
|
289
299
|
def get_pixel(x, y)
|
290
|
-
GD2FFI.send(:gdImageGetPixel, @image_ptr, x, y)
|
300
|
+
GD2FFI.send(:gdImageGetPixel, @image_ptr, x.to_i, y.to_i)
|
291
301
|
end
|
292
302
|
alias pixel get_pixel
|
293
303
|
|
294
304
|
# Set the pixel value at image location (+x+, +y+).
|
295
305
|
def set_pixel(x, y, value)
|
296
|
-
GD2FFI.send(:gdImageSetPixel, @image_ptr, x, y, value)
|
306
|
+
GD2FFI.send(:gdImageSetPixel, @image_ptr, x.to_i, y.to_i, value.to_i)
|
297
307
|
nil
|
298
308
|
end
|
299
309
|
|
@@ -400,7 +410,7 @@ module GD2
|
|
400
410
|
clip = clipping
|
401
411
|
begin
|
402
412
|
p clipping
|
403
|
-
GD2FFI.send(:gdImageSetClip, image_ptr, x1, y1, x2, y2)
|
413
|
+
GD2FFI.send(:gdImageSetClip, image_ptr, x1.to_i, y1.to_i, x2.to_i, y2.to_i)
|
404
414
|
p clipping
|
405
415
|
yield self
|
406
416
|
self
|
@@ -411,7 +421,7 @@ module GD2
|
|
411
421
|
|
412
422
|
# Return *true* if the current clipping rectangle excludes the given point.
|
413
423
|
def clips?(x, y)
|
414
|
-
GD2FFI.send(:gdImageBoundsSafe, image_ptr, x, y).zero?
|
424
|
+
GD2FFI.send(:gdImageBoundsSafe, image_ptr, x.to_i, y.to_i).zero?
|
415
425
|
end
|
416
426
|
|
417
427
|
# Provide a drawing environment for a block. See GD2::Canvas.
|
@@ -496,7 +506,7 @@ module GD2
|
|
496
506
|
# compression (0 = none, 1 = minimal but fast, 9 = best but slow).
|
497
507
|
def png(level = nil)
|
498
508
|
size = FFI::MemoryPointer.new(:pointer)
|
499
|
-
ptr = GD2FFI.send(:gdImagePngPtrEx, image_ptr, size, level || -1)
|
509
|
+
ptr = GD2FFI.send(:gdImagePngPtrEx, image_ptr, size, level.to_i || -1)
|
500
510
|
ptr.get_bytes(0, size.get_int(0))
|
501
511
|
ensure
|
502
512
|
GD2FFI.send(:gdFree, ptr)
|
@@ -541,7 +551,7 @@ module GD2
|
|
541
551
|
# The specified +fmt+ may be either GD2::FMT_RAW or GD2::FMT_COMPRESSED.
|
542
552
|
def gd2(fmt = FMT_COMPRESSED, chunk_size = 0)
|
543
553
|
size = FFI::MemoryPointer.new(:pointer)
|
544
|
-
ptr = GD2FFI.send(:gdImageGd2Ptr, image_ptr, chunk_size, fmt, size)
|
554
|
+
ptr = GD2FFI.send(:gdImageGd2Ptr, image_ptr, chunk_size.to_i, fmt.to_i, size)
|
545
555
|
ptr.get_bytes(0, size.get_int(0))
|
546
556
|
ensure
|
547
557
|
GD2FFI.send(:gdFree, ptr)
|
@@ -555,10 +565,10 @@ module GD2
|
|
555
565
|
raise ArgumentError unless src_w.nil? == src_h.nil?
|
556
566
|
if src_w
|
557
567
|
GD2FFI.send(:gdImageCopyResampled, image_ptr, other.image_ptr,
|
558
|
-
dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
|
568
|
+
dst_x.to_i, dst_y.to_i, src_x.to_i, src_y.to_i, dst_w.to_i, dst_h.to_i, src_w.to_i, src_h.to_i)
|
559
569
|
else
|
560
570
|
GD2FFI.send(:gdImageCopy, image_ptr, other.image_ptr,
|
561
|
-
dst_x, dst_y, src_x, src_y, dst_w, dst_h)
|
571
|
+
dst_x.to_i, dst_y.to_i, src_x.to_i, src_y.to_i, dst_w.to_i, dst_h.to_i)
|
562
572
|
end
|
563
573
|
self
|
564
574
|
end
|
@@ -569,7 +579,7 @@ module GD2
|
|
569
579
|
# may be floating point.
|
570
580
|
def copy_from_rotated(other, dst_x, dst_y, src_x, src_y, w, h, angle)
|
571
581
|
GD2FFI.send(:gdImageCopyRotated, image_ptr, other.image_ptr,
|
572
|
-
dst_x.to_f, dst_y.to_f, src_x, src_y, w, h, angle.to_degrees.round)
|
582
|
+
dst_x.to_f, dst_y.to_f, src_x.to_i, src_y.to_i, w.to_i, h.to_i, angle.to_degrees.round.to_i)
|
573
583
|
self
|
574
584
|
end
|
575
585
|
|
@@ -579,7 +589,7 @@ module GD2
|
|
579
589
|
# channel information from the source image is ignored.
|
580
590
|
def merge_from(other, dst_x, dst_y, src_x, src_y, w, h, pct)
|
581
591
|
GD2FFI.send(:gdImageCopyMerge, image_ptr, other.image_ptr,
|
582
|
-
dst_x, dst_y, src_x, src_y, w, h, pct.to_percent.round)
|
592
|
+
dst_x.to_i, dst_y.to_i, src_x.to_i, src_y.to_i, w.to_i, h.to_i, pct.to_percent.round.to_i)
|
583
593
|
self
|
584
594
|
end
|
585
595
|
|
@@ -588,7 +598,7 @@ module GD2
|
|
588
598
|
def rotate!(angle, axis_x = width / 2.0, axis_y = height / 2.0)
|
589
599
|
ptr = self.class.create_image_ptr(width, height, alpha_blending?)
|
590
600
|
GD2FFI.send(:gdImageCopyRotated, ptr, image_ptr,
|
591
|
-
axis_x.to_f, axis_y.to_f, 0, 0, width, height, angle.to_degrees.round)
|
601
|
+
axis_x.to_f, axis_y.to_f, 0, 0, width.to_i, height.to_i, angle.to_degrees.round.to_i)
|
592
602
|
init_with_image(ptr)
|
593
603
|
end
|
594
604
|
|
@@ -601,7 +611,7 @@ module GD2
|
|
601
611
|
# (0, 0).
|
602
612
|
def crop!(x, y, w, h)
|
603
613
|
ptr = self.class.create_image_ptr(w, h, alpha_blending?)
|
604
|
-
GD2FFI.send(:gdImageCopy, ptr, image_ptr, 0, 0, x, y, w, h)
|
614
|
+
GD2FFI.send(:gdImageCopy, ptr, image_ptr, 0, 0, x.to_i, y.to_i, w.to_i, h.to_i)
|
605
615
|
init_with_image(ptr)
|
606
616
|
end
|
607
617
|
|
@@ -615,7 +625,7 @@ module GD2
|
|
615
625
|
def uncrop!(x1, y1 = x1, x2 = x1, y2 = y1)
|
616
626
|
ptr = self.class.create_image_ptr(x1 + width + x2, y1 + height + y2,
|
617
627
|
alpha_blending?)
|
618
|
-
GD2FFI.send(:gdImageCopy, ptr, image_ptr, x1, y1, 0, 0, width, height)
|
628
|
+
GD2FFI.send(:gdImageCopy, ptr, image_ptr, x1.to_i, y1.to_i, 0, 0, width.to_i, height.to_i)
|
619
629
|
init_with_image(ptr)
|
620
630
|
end
|
621
631
|
|
@@ -630,7 +640,7 @@ module GD2
|
|
630
640
|
def resize!(w, h, resample = true)
|
631
641
|
ptr = self.class.create_image_ptr(w, h, false)
|
632
642
|
GD2FFI.send(resample ? :gdImageCopyResampled : :gdImageCopyResized,
|
633
|
-
ptr, image_ptr, 0, 0, 0, 0, w, h, width, height)
|
643
|
+
ptr, image_ptr, 0, 0, 0, 0, w.to_i, h.to_i, width.to_i, height.to_i)
|
634
644
|
alpha_blending = alpha_blending?
|
635
645
|
init_with_image(ptr)
|
636
646
|
self.alpha_blending = alpha_blending
|
@@ -648,7 +658,7 @@ module GD2
|
|
648
658
|
# Note that the original image must be square.
|
649
659
|
def polar_transform!(radius)
|
650
660
|
raise 'Image must be square' unless width == height
|
651
|
-
ptr = GD2FFI.send(:gdImageSquareToCircle, image_ptr, radius)
|
661
|
+
ptr = GD2FFI.send(:gdImageSquareToCircle, image_ptr, radius.to_i)
|
652
662
|
raise LibraryError unless ptr
|
653
663
|
init_with_image(ptr)
|
654
664
|
end
|
@@ -675,7 +685,7 @@ module GD2
|
|
675
685
|
# +dither+ controls whether dithering is used.
|
676
686
|
def to_indexed_color(colors = MAX_COLORS, dither = true)
|
677
687
|
ptr = GD2FFI.send(:gdImageCreatePaletteFromTrueColor,
|
678
|
-
to_true_color.image_ptr, dither ? 1 : 0, colors)
|
688
|
+
to_true_color.image_ptr, dither ? 1 : 0, colors.to_i)
|
679
689
|
raise LibraryError unless ptr
|
680
690
|
|
681
691
|
obj = IndexedColor.allocate.init_with_image(ptr)
|
@@ -757,7 +767,7 @@ module GD2
|
|
757
767
|
def merge_from(other, dst_x, dst_y, src_x, src_y, w, h, pct, gray = false)
|
758
768
|
return super(other, dst_x, dst_y, src_x, src_y, w, h, pct) unless gray
|
759
769
|
GD2FFI.send(:gdImageCopyMergeGray, image_ptr, other.image_ptr,
|
760
|
-
dst_x, dst_y, src_x, src_y, w, h, pct.to_percent.round)
|
770
|
+
dst_x.to_i, dst_y.to_i, src_x.to_i, src_y.to_i, w.to_i, h.to_i, pct.to_percent.round.to_i)
|
761
771
|
self
|
762
772
|
end
|
763
773
|
end
|
@@ -778,7 +788,7 @@ module GD2
|
|
778
788
|
end
|
779
789
|
|
780
790
|
def sharpen(pct) #:nodoc:
|
781
|
-
GD2FFI.send(:gdImageSharpen, image_ptr, pct.to_percent.round)
|
791
|
+
GD2FFI.send(:gdImageSharpen, image_ptr, pct.to_percent.round.to_i)
|
782
792
|
self
|
783
793
|
end
|
784
794
|
end
|
data/lib/gd2/palette.rb
CHANGED
@@ -104,7 +104,7 @@ module GD2
|
|
104
104
|
def resolve(color)
|
105
105
|
raise TypeError unless color.kind_of? Color
|
106
106
|
c = GD2FFI.send(:gdImageColorResolveAlpha, @image.image_ptr,
|
107
|
-
color.red, color.
|
107
|
+
color.red.to_i, color.green.to_i, color.blue.to_i, color.alpha.to_i)
|
108
108
|
c == -1 ? nil : get_color(c)
|
109
109
|
end
|
110
110
|
|
@@ -113,7 +113,7 @@ module GD2
|
|
113
113
|
def exact(color)
|
114
114
|
raise TypeError unless color.kind_of? Color
|
115
115
|
c = GD2FFI.send(:gdImageColorExactAlpha, @image.image_ptr,
|
116
|
-
color.red, color.green, color.blue, color.alpha)
|
116
|
+
color.red.to_i, color.green.to_i, color.blue.to_i, color.alpha.to_i)
|
117
117
|
c == -1 ? nil : get_color(c)
|
118
118
|
end
|
119
119
|
|
@@ -129,7 +129,7 @@ module GD2
|
|
129
129
|
def closest(color)
|
130
130
|
raise TypeError unless color.kind_of? Color
|
131
131
|
c = GD2FFI.send(:gdImageColorClosestAlpha, @image.image_ptr,
|
132
|
-
color.red, color.green, color.blue, color.alpha)
|
132
|
+
color.red.to_i, color.green.to_i, color.blue.to_i, color.alpha.to_i)
|
133
133
|
c == -1 ? nil : get_color(c)
|
134
134
|
end
|
135
135
|
|
@@ -138,7 +138,7 @@ module GD2
|
|
138
138
|
def closest_hwb(color)
|
139
139
|
raise TypeError unless color.kind_of? Color
|
140
140
|
c = GD2FFI.send(:gdImageColorClosestHWB, @image.image_ptr,
|
141
|
-
color.red, color.green, color.blue)
|
141
|
+
color.red.to_i, color.green.to_i, color.blue.to_i)
|
142
142
|
c == -1 ? nil : get_color(c)
|
143
143
|
end
|
144
144
|
|
@@ -148,7 +148,7 @@ module GD2
|
|
148
148
|
def allocate(color)
|
149
149
|
raise TypeError unless color.kind_of? Color
|
150
150
|
c = GD2FFI.send(:gdImageColorAllocateAlpha, @image.image_ptr,
|
151
|
-
color.red, color.green, color.blue, color.alpha)
|
151
|
+
color.red.to_i, color.green.to_i, color.blue.to_i, color.alpha.to_i)
|
152
152
|
c == -1 ? raise(Palette::PaletteFullError, 'Palette is full') :
|
153
153
|
get_color(c)
|
154
154
|
end
|
@@ -164,7 +164,7 @@ module GD2
|
|
164
164
|
def deallocate(color)
|
165
165
|
color = exact(color) unless color.index
|
166
166
|
return nil if color.nil? || color.index.nil?
|
167
|
-
GD2FFI.send(:gdImageColorDeallocate, @image.image_ptr, color.index)
|
167
|
+
GD2FFI.send(:gdImageColorDeallocate, @image.image_ptr, color.index.to_i)
|
168
168
|
nil
|
169
169
|
end
|
170
170
|
|
data/test/canvas_test.rb
CHANGED
@@ -4,183 +4,183 @@ require 'tmpdir'
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'gd2-ffij'
|
6
6
|
|
7
|
-
require 'test/test_helper'
|
7
|
+
require './test/test_helper'
|
8
8
|
|
9
9
|
class CanvasTest < 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
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
10
|
+
include TestHelper
|
11
|
+
|
12
|
+
def test_line
|
13
|
+
image = new_image
|
14
|
+
image.draw do |pen|
|
15
|
+
pen.color = image.palette.resolve(GD2::Color[255, 255, 255])
|
16
|
+
pen.line(64, 64, 192, 192)
|
17
|
+
end
|
18
|
+
assert(image == load_image('test_canvas_line.gd2'))
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_rectangle
|
22
|
+
image = new_image
|
23
|
+
image.draw do |pen|
|
24
|
+
pen.color = image.palette.resolve(GD2::Color[255, 255, 255])
|
25
|
+
pen.rectangle(64, 64, 192, 192)
|
26
|
+
end
|
27
|
+
assert(image == load_image('test_canvas_rectangle.gd2'))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_filled_rectangle
|
31
|
+
image = new_image
|
32
|
+
image.draw do |pen|
|
33
|
+
pen.color = image.palette.resolve(GD2::Color[255, 255, 255])
|
34
|
+
pen.rectangle(64, 64, 192, 192, true)
|
35
|
+
end
|
36
|
+
assert(image == load_image('test_canvas_filled_rectangle.gd2'))
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_polygon
|
40
|
+
image = new_image
|
41
|
+
image.draw do |pen|
|
42
|
+
pen.color = image.palette.resolve(GD2::Color[255, 255, 255])
|
43
|
+
pen.polygon([
|
44
|
+
[ 64, 64 ],
|
45
|
+
[ 192, 192 ],
|
46
|
+
[ 64, 128 ]
|
47
|
+
])
|
48
|
+
end
|
49
|
+
assert(image == load_image('test_canvas_polygon.gd2'))
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_filled_polygon
|
53
|
+
image = new_image
|
54
|
+
image.draw do |pen|
|
55
|
+
pen.color = image.palette.resolve(GD2::Color[255, 255, 255])
|
56
|
+
pen.polygon([
|
57
|
+
[ 64, 64 ],
|
58
|
+
[ 192, 192 ],
|
59
|
+
[ 64, 128 ]
|
60
|
+
], true)
|
61
|
+
end
|
62
|
+
assert(image == load_image('test_canvas_filled_polygon.gd2'))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_move_to_and_line_to
|
66
|
+
image = new_image
|
67
|
+
image.draw do |pen|
|
68
|
+
pen.color = image.palette.resolve(GD2::Color[255, 255, 255])
|
69
|
+
pen.move_to(64, 64)
|
70
|
+
pen.line_to(128, 128)
|
71
|
+
end
|
72
|
+
assert(image == load_image('test_canvas_move_to_and_line_to.gd2'))
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_fill
|
76
|
+
image = new_image
|
77
|
+
image.draw do |pen|
|
78
|
+
pen.color = image.palette.resolve(GD2::Color[32, 64, 128])
|
79
|
+
pen.rectangle(64, 64, 192, 192)
|
80
|
+
pen.move_to(65, 65)
|
81
|
+
pen.fill
|
82
|
+
end
|
83
|
+
assert(image == load_image('test_fill.gd2'))
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_arc
|
87
|
+
image = new_image
|
88
|
+
image.draw do |pen|
|
89
|
+
pen.color = image.palette.resolve(GD2::Color[32, 64, 128])
|
90
|
+
pen.arc(128, 128, 128, 128, 0..256)
|
91
|
+
end
|
92
|
+
assert(image == load_image('test_arc.gd2'))
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_text
|
96
|
+
image = new_image
|
97
|
+
image.draw do |pen|
|
98
|
+
pen.color = image.palette.resolve(GD2::Color[32, 64, 128])
|
99
|
+
pen.font = GD2::Font::TrueType[PATH_TO_FONT, 32]
|
100
|
+
pen.move_to(0, 128)
|
101
|
+
pen.text("HELLO")
|
102
|
+
pen.move_to(256, 128)
|
103
|
+
pen.text("WORLD", Math::PI)
|
104
|
+
end
|
105
|
+
assert(image == load_image('test_text.gd2'))
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_text_circle
|
109
|
+
image = new_image
|
110
|
+
image.draw do |pen|
|
111
|
+
pen.color = image.palette.resolve(GD2::Color[32, 64, 128])
|
112
|
+
pen.font = GD2::Font::TrueType[PATH_TO_FONT, 32]
|
113
|
+
pen.move_to(128, 128)
|
114
|
+
pen.text_circle('HELLO', 'WORLD', 100, 20, 1)
|
115
|
+
end
|
116
|
+
assert(image == load_image('test_text_circle.gd2'))
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_wedge
|
120
|
+
image = new_image
|
121
|
+
image.draw do |pen|
|
122
|
+
pen.color = image.palette.resolve(GD2::Color[32, 64, 128])
|
123
|
+
pen.wedge(128, 128, 256, 256, 0..180)
|
124
|
+
end
|
125
|
+
assert(image == load_image('test_wedge.gd2'))
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_filled_wedge
|
129
|
+
image = new_image
|
130
|
+
image.draw do |pen|
|
131
|
+
pen.color = image.palette.resolve(GD2::Color[32, 64, 128])
|
132
|
+
pen.wedge(128, 128, 256, 256, 0..180, true)
|
133
|
+
end
|
134
|
+
assert(image == load_image('test_filled_wedge.gd2'))
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_ellipse
|
138
|
+
image = new_image
|
139
|
+
image.draw do |pen|
|
140
|
+
pen.color = image.palette.resolve(GD2::Color[32, 64, 128])
|
141
|
+
pen.ellipse(128, 128, 64, 32)
|
142
|
+
end
|
143
|
+
assert(image == load_image('test_ellipse.gd2'))
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_filled_ellipse
|
147
|
+
image = new_image
|
148
|
+
image.draw do |pen|
|
149
|
+
pen.color = image.palette.resolve(GD2::Color[32, 64, 128])
|
150
|
+
pen.ellipse(128, 128, 64, 32, true)
|
151
|
+
end
|
152
|
+
assert(image == load_image('test_filled_ellipse.gd2'))
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_circle
|
156
|
+
image = new_image
|
157
|
+
image.draw do |pen|
|
158
|
+
pen.color = image.palette.resolve(GD2::Color[32, 64, 128])
|
159
|
+
pen.circle(128, 128, 128)
|
160
|
+
end
|
161
|
+
assert(image == load_image('test_circle.gd2'))
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_filled_circle
|
165
|
+
image = new_image
|
166
|
+
image.draw do |pen|
|
167
|
+
pen.color = image.palette.resolve(GD2::Color[32, 64, 128])
|
168
|
+
pen.circle(128, 128, 128, true)
|
169
|
+
end
|
170
|
+
assert(image == load_image('test_filled_circle.gd2'))
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_fill_to
|
174
|
+
image = new_image
|
175
|
+
image.draw do |pen|
|
176
|
+
blue = image.palette.resolve(GD2::Color[32, 64, 128])
|
177
|
+
red = image.palette.resolve(GD2::Color[255, 0, 0])
|
178
|
+
pen.color = blue
|
179
|
+
pen.arc(128, 128, 256, 64, 0..(Math::PI))
|
180
|
+
pen.color = red
|
181
|
+
pen.move(128, 128)
|
182
|
+
pen.fill_to(blue)
|
183
|
+
end
|
184
|
+
assert(image == load_image('test_fill_to.gd2'))
|
185
|
+
end
|
186
186
|
end
|
data/test/image_test.rb
CHANGED
@@ -4,146 +4,146 @@ require 'tmpdir'
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'gd2-ffij'
|
6
6
|
|
7
|
-
require 'test/test_helper'
|
7
|
+
require './test/test_helper'
|
8
8
|
|
9
9
|
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
|
-
|
10
|
+
include TestHelper
|
11
|
+
|
12
|
+
def test_image_new_and_release
|
13
|
+
img = GD2::Image.new(50, 50)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_image_true_color_new_and_release
|
17
|
+
img = GD2::Image::TrueColor.new(50, 50)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_image_indexed_color_new_and_release
|
21
|
+
img = GD2::Image::IndexedColor.new(50, 50)
|
22
|
+
end
|
23
|
+
|
24
|
+
[ :png, :gif, :jpg, :wbmp, :gd2 ].each do |ext|
|
25
|
+
self.class_eval(<<-EOF)
|
26
|
+
def test_load_#{ext}_from_file
|
27
|
+
img = GD2::Image.load(File.open(File.join(PATH_TO_IMAGES, 'test.#{ext}')))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_load_#{ext}_from_string
|
31
|
+
img = GD2::Image.load(File.read(File.join(PATH_TO_IMAGES, 'test.#{ext}')))
|
32
|
+
end
|
33
|
+
EOF
|
34
|
+
end
|
35
|
+
|
36
|
+
# TODO: add xbm, xpm and wbmp tests
|
37
|
+
[ :png, :gif, :jpg, :gd, :gd2 ].each do |ext|
|
38
|
+
self.class_eval(<<-EOF)
|
39
|
+
def test_import_#{ext}_from_file
|
40
|
+
img = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_export_#{ext}
|
44
|
+
img = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.gd2'))
|
45
|
+
out = File.join(Dir.tmpdir, 'test.#{ext}')
|
46
|
+
img.export(out)
|
47
|
+
|
48
|
+
assert(File.exists?(out))
|
49
|
+
|
50
|
+
imgA = GD2::Image.import(out)
|
51
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
52
|
+
|
53
|
+
assert(imgA == imgB)
|
54
|
+
|
55
|
+
File.unlink(out)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_compare_#{ext}
|
59
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
60
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
61
|
+
assert_equal(imgA.compare(imgB), 0)
|
62
|
+
assert_equal(imgA.compare(imgA.dup), 0)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_eqeq_#{ext}
|
66
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
67
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
68
|
+
assert(imgA == imgB)
|
69
|
+
assert(imgA == imgA.dup)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_height_#{ext}
|
73
|
+
img = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
74
|
+
assert_equal(img.height, 256)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_width_#{ext}
|
78
|
+
img = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
79
|
+
assert_equal(img.width, 256)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_size_#{ext}
|
83
|
+
img = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
84
|
+
assert_equal(img.size, [ 256, 256 ])
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_aspect_#{ext}
|
88
|
+
img = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.#{ext}'))
|
89
|
+
assert_in_delta(img.aspect, 1.0, 0.00000001)
|
90
|
+
end
|
91
|
+
EOF
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_rotate
|
95
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.gd2')).rotate!(Math::PI)
|
96
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_rotated_180.gd2'))
|
97
|
+
|
98
|
+
assert(imgA == imgB)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_crop
|
102
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.gd2')).crop!(64, 64, 128, 128)
|
103
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_cropped.gd2'))
|
104
|
+
|
105
|
+
assert(imgA == imgB)
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_uncrop
|
109
|
+
img = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.gd2')).crop!(64, 64, 128, 128)
|
110
|
+
img.uncrop!(64)
|
111
|
+
|
112
|
+
assert_equal(img.size, [ 256, 256 ])
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_resize
|
116
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.gd2')).resize!(512, 512)
|
117
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_resized.gd2'))
|
118
|
+
|
119
|
+
assert(imgA == imgB)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_resampled
|
123
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.gd2')).resize!(512, 512, true)
|
124
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_resampled.gd2'))
|
125
|
+
|
126
|
+
assert(imgA == imgB)
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_polar_transform
|
130
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test.gd2')).polar_transform!(100)
|
131
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_polar_transform.gd2'))
|
132
|
+
|
133
|
+
assert(imgA == imgB)
|
134
|
+
end
|
135
135
|
|
136
|
-
|
137
|
-
|
138
|
-
|
136
|
+
def test_color_sharpened
|
137
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_color.gd2')).sharpen(100)
|
138
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_color_sharpened.gd2'))
|
139
139
|
|
140
|
-
|
141
|
-
|
140
|
+
assert(imgA == imgB)
|
141
|
+
end
|
142
142
|
|
143
|
-
|
144
|
-
|
145
|
-
|
143
|
+
def test_resampled
|
144
|
+
imgA = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_color.gd2')).to_indexed_color
|
145
|
+
imgB = GD2::Image.import(File.join(PATH_TO_IMAGES, 'test_color_indexed.gd2'))
|
146
146
|
|
147
|
-
|
148
|
-
|
147
|
+
assert(imgA == imgB)
|
148
|
+
end
|
149
149
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
|
2
2
|
module TestHelper
|
3
|
-
|
4
|
-
|
3
|
+
PATH_TO_IMAGES = File.join(File.dirname(__FILE__), 'images')
|
4
|
+
PATH_TO_FONT = File.join(File.dirname(__FILE__), '..', 'vendor', 'fonts', 'ttf', 'DejaVuSans.ttf')
|
5
5
|
|
6
6
|
def new_image
|
7
|
-
|
7
|
+
GD2::Image.new(256, 256)
|
8
8
|
end
|
9
9
|
|
10
10
|
def load_image(file_name)
|
11
|
-
|
11
|
+
GD2::Image.load(File.read(File.join(PATH_TO_IMAGES, file_name)))
|
12
12
|
end
|
13
13
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gd2-ffij
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- J Smith
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-11-11 00:00:00 -05:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -92,23 +93,27 @@ rdoc_options:
|
|
92
93
|
require_paths:
|
93
94
|
- lib
|
94
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
95
97
|
requirements:
|
96
98
|
- - ">="
|
97
99
|
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
98
101
|
segments:
|
99
102
|
- 0
|
100
103
|
version: "0"
|
101
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
102
106
|
requirements:
|
103
107
|
- - ">="
|
104
108
|
- !ruby/object:Gem::Version
|
109
|
+
hash: 3
|
105
110
|
segments:
|
106
111
|
- 0
|
107
112
|
version: "0"
|
108
113
|
requirements: []
|
109
114
|
|
110
115
|
rubyforge_project:
|
111
|
-
rubygems_version: 1.3.
|
116
|
+
rubygems_version: 1.3.7
|
112
117
|
signing_key:
|
113
118
|
specification_version: 3
|
114
119
|
summary: gd2-ffij is a refactoring of the Ruby/GD2 library implemented with FFI
|