devil 0.1.9.1 → 0.1.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +112 -105
- data/LICENSE +21 -21
- data/README +52 -52
- data/Rakefile +55 -76
- data/ext/devil/extconf.rb +23 -23
- data/ext/devil/ruby_devil_ext.c +9 -9
- data/ext/devil/ruby_devil_ext.h +8 -8
- data/ext/devil/ruby_il.c +546 -546
- data/ext/devil/ruby_ilu.c +228 -228
- data/lib/devil.rb +547 -542
- data/lib/devil/gosu.rb +122 -122
- data/lib/devil/version.rb +3 -3
- data/test/test_blank.rb +21 -21
- data/test/test_blit.rb +21 -21
- data/test/test_clone_and_crop.rb +28 -28
- data/test/test_gosu_load.rb +23 -23
- data/test/test_gosu_roundtrip.rb +29 -29
- data/test/test_gosu_save.rb +26 -26
- data/test/test_gosu_show.rb +10 -10
- data/test/test_group.rb +18 -18
- data/test/test_ilut.rb +95 -95
- data/test/test_new_api.rb +28 -28
- data/test/test_profile.rb +8 -8
- data/test/test_quality.rb +9 -9
- data/test/test_scale_algos.rb +30 -30
- data/test/test_screenshot.rb +33 -33
- data/test/test_thumbnail.rb +13 -13
- data/test/texture_out1.jpg +0 -0
- data/test/texture_out2.jpg +0 -0
- data/test/thumb.png +0 -0
- metadata +33 -19
- data/test/test_equality.rb +0 -18
data/lib/devil/gosu.rb
CHANGED
@@ -1,122 +1,122 @@
|
|
1
|
-
# (C) John Mair 2009, under the MIT licence
|
2
|
-
|
3
|
-
require 'texplay'
|
4
|
-
require 'devil'
|
5
|
-
|
6
|
-
# monkey patches for TexPlay module (and by proxy the Gosu::Image class)
|
7
|
-
module TexPlay
|
8
|
-
|
9
|
-
# save a Gosu::Image to +file+
|
10
|
-
# This method is only available if require 'devil/gosu' is used
|
11
|
-
def save(file)
|
12
|
-
capture {
|
13
|
-
img = to_devil
|
14
|
-
img.save(file)
|
15
|
-
img.free
|
16
|
-
}
|
17
|
-
self
|
18
|
-
end
|
19
|
-
|
20
|
-
# convert a Gosu::Image to a Devil::Image.
|
21
|
-
# This method is only available if require 'devil/gosu' is used
|
22
|
-
def to_devil
|
23
|
-
devil_img = nil
|
24
|
-
capture {
|
25
|
-
devil_img = Devil.from_blob(self.to_blob, self.width, self.height).flip
|
26
|
-
devil_img
|
27
|
-
}
|
28
|
-
devil_img
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# monkey patches for Gosu::Window class
|
33
|
-
class Gosu::Window
|
34
|
-
|
35
|
-
# return a screenshot of the framebuffer as a Devil::Image.
|
36
|
-
# This method is only available if require 'devil/gosu' is used
|
37
|
-
def screenshot
|
38
|
-
require 'opengl'
|
39
|
-
|
40
|
-
img = nil
|
41
|
-
self.gl do
|
42
|
-
data = glReadPixels(0, 0, self.width, self.height, GL_RGBA, GL_UNSIGNED_BYTE)
|
43
|
-
img = Devil.from_blob(data, self.width, self.height)
|
44
|
-
end
|
45
|
-
|
46
|
-
img
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
class Gosu::Image
|
51
|
-
class << self
|
52
|
-
alias_method :original_new_redux, :new
|
53
|
-
|
54
|
-
# monkey patching to support multiple image formats.
|
55
|
-
# This method is only available if require 'devil/gosu' is used
|
56
|
-
def new(window, file, *args, &block)
|
57
|
-
if file.respond_to?(:to_blob) || file =~ /\.(bmp|png)$/
|
58
|
-
original_new_redux(window, file, *args, &block)
|
59
|
-
else
|
60
|
-
img = Devil.load(file).flip
|
61
|
-
begin
|
62
|
-
gosu_img = original_new_redux(window, img, *args, &block)
|
63
|
-
ensure
|
64
|
-
img.free
|
65
|
-
end
|
66
|
-
|
67
|
-
gosu_img
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
class Devil::Image
|
74
|
-
|
75
|
-
# convert a Devil::Image to a Gosu::Image.
|
76
|
-
# Must provide a +window+ parameter, as per Gosu::Image#new()
|
77
|
-
# This method is only available if require 'devil/gosu' is used
|
78
|
-
def to_gosu(window)
|
79
|
-
Gosu::Image.new(window, self)
|
80
|
-
end
|
81
|
-
|
82
|
-
# display the Devil images on screen utilizing the Gosu library for visualization
|
83
|
-
# if +x+ and +y+ are specified then show the image centered at this location, otherwise
|
84
|
-
# draw the image at the center of the screen
|
85
|
-
# This method is only available if require 'devil/gosu' is used
|
86
|
-
def show(x = Devil.get_options[:window_size][0] / 2,
|
87
|
-
y = Devil.get_options[:window_size][1] / 2)
|
88
|
-
|
89
|
-
if !Devil.const_defined?(:Window)
|
90
|
-
c = Class.new(Gosu::Window) do
|
91
|
-
attr_accessor :show_list
|
92
|
-
|
93
|
-
def initialize
|
94
|
-
super(Devil.get_options[:window_size][0], Devil.get_options[:window_size][1], false)
|
95
|
-
@show_list = []
|
96
|
-
end
|
97
|
-
|
98
|
-
def draw # :nodoc:
|
99
|
-
@show_list.each { |v| v[:image].draw_rot(v[:x], v[:y], 1, 0) }
|
100
|
-
|
101
|
-
exit if button_down?(Gosu::KbEscape)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
Devil.const_set :Window, c
|
106
|
-
end
|
107
|
-
|
108
|
-
if !defined? @@window
|
109
|
-
@@window ||= Devil::Window.new
|
110
|
-
|
111
|
-
at_exit { @@window.show }
|
112
|
-
end
|
113
|
-
|
114
|
-
# note we dup the image so the displayed image is a snapshot taken at the time #show is invoked
|
115
|
-
|
116
|
-
img = self.dup.flip
|
117
|
-
@@window.show_list.push :image => Gosu::Image.new(@@window, img), :x => x, :y => y
|
118
|
-
img.free
|
119
|
-
|
120
|
-
self
|
121
|
-
end
|
122
|
-
end
|
1
|
+
# (C) John Mair 2009, under the MIT licence
|
2
|
+
|
3
|
+
require 'texplay'
|
4
|
+
require 'devil'
|
5
|
+
|
6
|
+
# monkey patches for TexPlay module (and by proxy the Gosu::Image class)
|
7
|
+
module TexPlay
|
8
|
+
|
9
|
+
# save a Gosu::Image to +file+
|
10
|
+
# This method is only available if require 'devil/gosu' is used
|
11
|
+
def save(file)
|
12
|
+
capture {
|
13
|
+
img = to_devil
|
14
|
+
img.save(file)
|
15
|
+
img.free
|
16
|
+
}
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
# convert a Gosu::Image to a Devil::Image.
|
21
|
+
# This method is only available if require 'devil/gosu' is used
|
22
|
+
def to_devil
|
23
|
+
devil_img = nil
|
24
|
+
capture {
|
25
|
+
devil_img = Devil.from_blob(self.to_blob, self.width, self.height).flip
|
26
|
+
devil_img
|
27
|
+
}
|
28
|
+
devil_img
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# monkey patches for Gosu::Window class
|
33
|
+
class Gosu::Window
|
34
|
+
|
35
|
+
# return a screenshot of the framebuffer as a Devil::Image.
|
36
|
+
# This method is only available if require 'devil/gosu' is used
|
37
|
+
def screenshot
|
38
|
+
require 'opengl'
|
39
|
+
|
40
|
+
img = nil
|
41
|
+
self.gl do
|
42
|
+
data = glReadPixels(0, 0, self.width, self.height, GL_RGBA, GL_UNSIGNED_BYTE)
|
43
|
+
img = Devil.from_blob(data, self.width, self.height)
|
44
|
+
end
|
45
|
+
|
46
|
+
img
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Gosu::Image
|
51
|
+
class << self
|
52
|
+
alias_method :original_new_redux, :new
|
53
|
+
|
54
|
+
# monkey patching to support multiple image formats.
|
55
|
+
# This method is only available if require 'devil/gosu' is used
|
56
|
+
def new(window, file, *args, &block)
|
57
|
+
if file.respond_to?(:to_blob) || file =~ /\.(bmp|png)$/
|
58
|
+
original_new_redux(window, file, *args, &block)
|
59
|
+
else
|
60
|
+
img = Devil.load(file).flip
|
61
|
+
begin
|
62
|
+
gosu_img = original_new_redux(window, img, *args, &block)
|
63
|
+
ensure
|
64
|
+
img.free
|
65
|
+
end
|
66
|
+
|
67
|
+
gosu_img
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Devil::Image
|
74
|
+
|
75
|
+
# convert a Devil::Image to a Gosu::Image.
|
76
|
+
# Must provide a +window+ parameter, as per Gosu::Image#new()
|
77
|
+
# This method is only available if require 'devil/gosu' is used
|
78
|
+
def to_gosu(window)
|
79
|
+
Gosu::Image.new(window, self)
|
80
|
+
end
|
81
|
+
|
82
|
+
# display the Devil images on screen utilizing the Gosu library for visualization
|
83
|
+
# if +x+ and +y+ are specified then show the image centered at this location, otherwise
|
84
|
+
# draw the image at the center of the screen
|
85
|
+
# This method is only available if require 'devil/gosu' is used
|
86
|
+
def show(x = Devil.get_options[:window_size][0] / 2,
|
87
|
+
y = Devil.get_options[:window_size][1] / 2)
|
88
|
+
|
89
|
+
if !Devil.const_defined?(:Window)
|
90
|
+
c = Class.new(Gosu::Window) do
|
91
|
+
attr_accessor :show_list
|
92
|
+
|
93
|
+
def initialize
|
94
|
+
super(Devil.get_options[:window_size][0], Devil.get_options[:window_size][1], false)
|
95
|
+
@show_list = []
|
96
|
+
end
|
97
|
+
|
98
|
+
def draw # :nodoc:
|
99
|
+
@show_list.each { |v| v[:image].draw_rot(v[:x], v[:y], 1, 0) }
|
100
|
+
|
101
|
+
exit if button_down?(Gosu::KbEscape)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
Devil.const_set :Window, c
|
106
|
+
end
|
107
|
+
|
108
|
+
if !defined? @@window
|
109
|
+
@@window ||= Devil::Window.new
|
110
|
+
|
111
|
+
at_exit { @@window.show }
|
112
|
+
end
|
113
|
+
|
114
|
+
# note we dup the image so the displayed image is a snapshot taken at the time #show is invoked
|
115
|
+
|
116
|
+
img = self.dup.flip
|
117
|
+
@@window.show_list.push :image => Gosu::Image.new(@@window, img), :x => x, :y => y
|
118
|
+
img.free
|
119
|
+
|
120
|
+
self
|
121
|
+
end
|
122
|
+
end
|
data/lib/devil/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Devil
|
2
|
-
VERSION = "0.1.9.
|
3
|
-
end
|
1
|
+
module Devil
|
2
|
+
VERSION = "0.1.9.5"
|
3
|
+
end
|
data/test/test_blank.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
$direc = File.dirname(__FILE__)
|
2
|
-
|
3
|
-
$LOAD_PATH.push("#{$direc}/../lib/")
|
4
|
-
|
5
|
-
require 'rubygems'
|
6
|
-
require 'devil/gosu'
|
7
|
-
|
8
|
-
Devil.create_image(500, 500, :color => [255, 255, 0, 255]) do |img|
|
9
|
-
source1 = Devil.load("texture.png").thumbnail(100)
|
10
|
-
img.blit source1, 100, 100
|
11
|
-
img.blit source1, 400, 100
|
12
|
-
|
13
|
-
source1_dup = source1.dup
|
14
|
-
img.blit source1_dup.rotate(45), 100, 300
|
15
|
-
|
16
|
-
img.show
|
17
|
-
|
18
|
-
source1.free
|
19
|
-
source1_dup.free
|
20
|
-
end
|
21
|
-
|
1
|
+
$direc = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
$LOAD_PATH.push("#{$direc}/../lib/")
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'devil/gosu'
|
7
|
+
|
8
|
+
Devil.create_image(500, 500, :color => [255, 255, 0, 255]) do |img|
|
9
|
+
source1 = Devil.load("texture.png").thumbnail(100)
|
10
|
+
img.blit source1, 100, 100
|
11
|
+
img.blit source1, 400, 100
|
12
|
+
|
13
|
+
source1_dup = source1.dup
|
14
|
+
img.blit source1_dup.rotate(45), 100, 300
|
15
|
+
|
16
|
+
img.show
|
17
|
+
|
18
|
+
source1.free
|
19
|
+
source1_dup.free
|
20
|
+
end
|
21
|
+
|
data/test/test_blit.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
$direc = File.dirname(__FILE__)
|
2
|
-
|
3
|
-
$LOAD_PATH.push("#{$direc}/../lib/")
|
4
|
-
|
5
|
-
require 'rubygems'
|
6
|
-
require 'devil/gosu'
|
7
|
-
|
8
|
-
Devil.with_image("#{$direc}/texture.png") do |img|
|
9
|
-
img2 = Devil.load("#{$direc}/red.png")
|
10
|
-
|
11
|
-
img.blit img2, 100, 100, :crop => [0, 0, img2.width / 2, img2.height / 2]
|
12
|
-
img2.free
|
13
|
-
|
14
|
-
img.show
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
1
|
+
$direc = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
$LOAD_PATH.push("#{$direc}/../lib/")
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'devil/gosu'
|
7
|
+
|
8
|
+
Devil.with_image("#{$direc}/texture.png") do |img|
|
9
|
+
img2 = Devil.load("#{$direc}/red.png")
|
10
|
+
|
11
|
+
img.blit img2, 100, 100, :crop => [0, 0, img2.width / 2, img2.height / 2]
|
12
|
+
img2.free
|
13
|
+
|
14
|
+
img.show
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
data/test/test_clone_and_crop.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
direc = File.dirname(__FILE__)
|
2
|
-
|
3
|
-
$LOAD_PATH.push("#{direc}/../lib/")
|
4
|
-
|
5
|
-
require 'rubygems'
|
6
|
-
require "devil/gosu"
|
7
|
-
|
8
|
-
img = Devil.load_image("#{direc}/texture.png")
|
9
|
-
|
10
|
-
img.crop(100,100, 200, 200)
|
11
|
-
img_dup = img.dup
|
12
|
-
|
13
|
-
img.rotate(rand(360))
|
14
|
-
|
15
|
-
img.show(200,200)
|
16
|
-
img_dup.show(450, 200)
|
17
|
-
|
18
|
-
img.free
|
19
|
-
img_dup.free
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
1
|
+
direc = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
$LOAD_PATH.push("#{direc}/../lib/")
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require "devil/gosu"
|
7
|
+
|
8
|
+
img = Devil.load_image("#{direc}/texture.png")
|
9
|
+
|
10
|
+
img.crop(100,100, 200, 200)
|
11
|
+
img_dup = img.dup
|
12
|
+
|
13
|
+
img.rotate(rand(360))
|
14
|
+
|
15
|
+
img.show(200,200)
|
16
|
+
img_dup.show(450, 200)
|
17
|
+
|
18
|
+
img.free
|
19
|
+
img_dup.free
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
data/test/test_gosu_load.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
$direc = File.dirname(__FILE__)
|
2
|
-
|
3
|
-
$LOAD_PATH.push("#{$direc}/../lib/")
|
4
|
-
|
5
|
-
require 'rubygems'
|
6
|
-
require 'devil/gosu'
|
7
|
-
|
8
|
-
class W < Gosu::Window
|
9
|
-
def initialize
|
10
|
-
super(1024, 768, false, 20)
|
11
|
-
|
12
|
-
@img = Gosu::Image.new(self, "#{$direc}/texture.jpg")
|
13
|
-
end
|
14
|
-
|
15
|
-
def draw
|
16
|
-
@img.draw 100, 50,1
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
w = W.new
|
22
|
-
w.show
|
23
|
-
|
1
|
+
$direc = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
$LOAD_PATH.push("#{$direc}/../lib/")
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'devil/gosu'
|
7
|
+
|
8
|
+
class W < Gosu::Window
|
9
|
+
def initialize
|
10
|
+
super(1024, 768, false, 20)
|
11
|
+
|
12
|
+
@img = Gosu::Image.new(self, "#{$direc}/texture.jpg")
|
13
|
+
end
|
14
|
+
|
15
|
+
def draw
|
16
|
+
@img.draw 100, 50,1
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
w = W.new
|
22
|
+
w.show
|
23
|
+
|
data/test/test_gosu_roundtrip.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
$direc = File.dirname(__FILE__)
|
2
|
-
|
3
|
-
$LOAD_PATH.push("#{$direc}/../lib/")
|
4
|
-
|
5
|
-
require 'rubygems'
|
6
|
-
require 'devil/gosu'
|
7
|
-
|
8
|
-
class W < Gosu::Window
|
9
|
-
def initialize
|
10
|
-
super(1024, 768, false, 20)
|
11
|
-
|
12
|
-
@img = Gosu::Image.new(self, "#{$direc}/texture.jpg")
|
13
|
-
dimg = @img.to_devil
|
14
|
-
@img = dimg.emboss.
|
15
|
-
rotate(45).
|
16
|
-
to_gosu(self)
|
17
|
-
|
18
|
-
dimg.free
|
19
|
-
end
|
20
|
-
|
21
|
-
def draw
|
22
|
-
@img.draw 100, 50,1
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
w = W.new
|
28
|
-
w.show
|
29
|
-
|
1
|
+
$direc = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
$LOAD_PATH.push("#{$direc}/../lib/")
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'devil/gosu'
|
7
|
+
|
8
|
+
class W < Gosu::Window
|
9
|
+
def initialize
|
10
|
+
super(1024, 768, false, 20)
|
11
|
+
|
12
|
+
@img = Gosu::Image.new(self, "#{$direc}/texture.jpg")
|
13
|
+
dimg = @img.to_devil
|
14
|
+
@img = dimg.emboss.
|
15
|
+
rotate(45).
|
16
|
+
to_gosu(self)
|
17
|
+
|
18
|
+
dimg.free
|
19
|
+
end
|
20
|
+
|
21
|
+
def draw
|
22
|
+
@img.draw 100, 50,1
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
w = W.new
|
28
|
+
w.show
|
29
|
+
|