devil 0.1.9.5-i386-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +112 -0
- data/LICENSE +21 -0
- data/README +52 -0
- data/Rakefile +55 -0
- data/ext/devil/extconf.rb +23 -0
- data/ext/devil/ruby_devil_ext.c +9 -0
- data/ext/devil/ruby_devil_ext.h +8 -0
- data/ext/devil/ruby_il.c +546 -0
- data/ext/devil/ruby_ilu.c +228 -0
- data/lib/1.8/devil.so +0 -0
- data/lib/1.9/devil.so +0 -0
- data/lib/devil.rb +547 -0
- data/lib/devil/gosu.rb +122 -0
- data/lib/devil/version.rb +3 -0
- data/test/red.png +0 -0
- data/test/tank.png +0 -0
- data/test/test_blank.rb +21 -0
- data/test/test_blit.rb +21 -0
- data/test/test_clone_and_crop.rb +28 -0
- data/test/test_gosu_load.rb +23 -0
- data/test/test_gosu_roundtrip.rb +29 -0
- data/test/test_gosu_save.rb +26 -0
- data/test/test_gosu_show.rb +10 -0
- data/test/test_group.rb +18 -0
- data/test/test_ilut.rb +95 -0
- data/test/test_new_api.rb +28 -0
- data/test/test_profile.rb +8 -0
- data/test/test_quality.rb +9 -0
- data/test/test_scale_algos.rb +30 -0
- data/test/test_screenshot.rb +33 -0
- data/test/test_thumbnail.rb +13 -0
- data/test/texture.jpg +0 -0
- data/test/texture.png +0 -0
- data/test/texture_out1.jpg +0 -0
- data/test/texture_out2.jpg +0 -0
- data/test/thumb.png +0 -0
- metadata +101 -0
data/lib/devil/gosu.rb
ADDED
@@ -0,0 +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
|
data/test/red.png
ADDED
Binary file
|
data/test/tank.png
ADDED
Binary file
|
data/test/test_blank.rb
ADDED
@@ -0,0 +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
|
+
|
data/test/test_blit.rb
ADDED
@@ -0,0 +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
|
+
|
@@ -0,0 +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
|
+
|
@@ -0,0 +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
|
+
|
@@ -0,0 +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
|
+
|
@@ -0,0 +1,26 @@
|
|
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, "tank.png")
|
13
|
+
@img.circle 100, 100, 50, :color => :purple, :filled => true
|
14
|
+
|
15
|
+
@img.save("tank-modified.png")
|
16
|
+
end
|
17
|
+
|
18
|
+
def draw
|
19
|
+
@img.draw 100, 50,1
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
w = W.new
|
25
|
+
w.show
|
26
|
+
|
data/test/test_group.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$direc = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
$LOAD_PATH.push("#{$direc}/../lib/")
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'devil/gosu'
|
7
|
+
|
8
|
+
Devil.with_group("#{$direc}/texture.png", "#{$direc}/red.png") do |img, img2|
|
9
|
+
|
10
|
+
img.blit img2, 100, 100, :crop => [0, 0, img2.width / 2, img2.height / 2]
|
11
|
+
img.show
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
data/test/test_ilut.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# this test is a hold over from the original ruby-devil bindings (by Jaroslaw Tworek)
|
2
|
+
|
3
|
+
$direc = File.dirname(__FILE__)
|
4
|
+
|
5
|
+
$LOAD_PATH.push("#{$direc}/../lib/")
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'glut'
|
9
|
+
require 'opengl'
|
10
|
+
require 'devil'
|
11
|
+
require 'thread'
|
12
|
+
|
13
|
+
$tex_id = 0
|
14
|
+
|
15
|
+
$idle = proc {
|
16
|
+
GLUT.PostRedisplay
|
17
|
+
}
|
18
|
+
|
19
|
+
$display = proc {
|
20
|
+
GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT)
|
21
|
+
GL.LoadIdentity
|
22
|
+
GLU.LookAt(0,0,-5,0,0,0,0,1,0)
|
23
|
+
|
24
|
+
GL.Begin GL::QUADS
|
25
|
+
|
26
|
+
|
27
|
+
GL.TexCoord(1,0)
|
28
|
+
GL.Vertex(1, 1,0)
|
29
|
+
GL.TexCoord(1,1)
|
30
|
+
GL.Vertex(1, -1,0)
|
31
|
+
GL.TexCoord(0,1)
|
32
|
+
GL.Vertex(-1, -1,0)
|
33
|
+
GL.TexCoord(0,0)
|
34
|
+
GL.Vertex(-1, 1,0)
|
35
|
+
|
36
|
+
GL.End
|
37
|
+
|
38
|
+
GLUT.SwapBuffers
|
39
|
+
}
|
40
|
+
|
41
|
+
$reshape = proc { |w,h|
|
42
|
+
GL.Viewport(0,0,w,h)
|
43
|
+
GL.MatrixMode(GL::PROJECTION)
|
44
|
+
GL.LoadIdentity
|
45
|
+
GLU.Perspective(45.0, Float(w)/h, 0.01, 100)
|
46
|
+
GL.MatrixMode(GL::MODELVIEW)
|
47
|
+
GL.LoadIdentity
|
48
|
+
}
|
49
|
+
|
50
|
+
def setup_gl
|
51
|
+
GL.ClearColor( 0,0,0,1)
|
52
|
+
IL.Init
|
53
|
+
ILUT.Renderer(ILUT::OPENGL)
|
54
|
+
GL.Enable(GL::DEPTH_TEST)
|
55
|
+
GL.DrawBuffer(GL::BACK)
|
56
|
+
GL.Disable(GL::CULL_FACE)
|
57
|
+
GL.ShadeModel(GL::FLAT)
|
58
|
+
GL.Enable(GL::TEXTURE_2D)
|
59
|
+
|
60
|
+
name = IL.GenImages(1)[0]
|
61
|
+
IL.BindImage(name)
|
62
|
+
|
63
|
+
if File.directory?("test") then
|
64
|
+
if !File.exist?("test/texture.png") then
|
65
|
+
raise RuntimeError, "File test/texture.png doesn't exist"
|
66
|
+
end
|
67
|
+
IL.LoadImage("test/texture.png")
|
68
|
+
else
|
69
|
+
if !File.exist?("texture.png") then
|
70
|
+
raise RuntimeError, "File texture.png doesn't exist"
|
71
|
+
end
|
72
|
+
IL.LoadImage("texture.png")
|
73
|
+
end
|
74
|
+
|
75
|
+
$tex_id = ILUT.GLBindMipmaps()
|
76
|
+
IL.DeleteImages([name])
|
77
|
+
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
def main
|
82
|
+
GLUT.Init
|
83
|
+
GLUT.InitDisplayMode(GLUT::DOUBLE | GLUT::RGB | GLUT::DEPTH)
|
84
|
+
GLUT.InitWindowSize(800,600)
|
85
|
+
GLUT.CreateWindow("Ruby-DevIL test")
|
86
|
+
setup_gl
|
87
|
+
GLUT.DisplayFunc($display)
|
88
|
+
GLUT.ReshapeFunc($reshape)
|
89
|
+
GLUT.IdleFunc($idle)
|
90
|
+
GLUT.MainLoop
|
91
|
+
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
main
|
@@ -0,0 +1,28 @@
|
|
1
|
+
$direc = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
$LOAD_PATH.push("#{$direc}/../lib/")
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require "devil"
|
7
|
+
|
8
|
+
Devil.with_image("#{$direc}/texture.png") do |img|
|
9
|
+
img.pixelize(10)
|
10
|
+
img.save("#{$direc}/texture_blocky.png")
|
11
|
+
img.free
|
12
|
+
end
|
13
|
+
|
14
|
+
img = Devil.load_image("#{$direc}/texture.png")
|
15
|
+
bink = Devil.load_image("#{$direc}/texture.png")
|
16
|
+
|
17
|
+
img.gamma_correct(1.6)
|
18
|
+
bink.resize(50, 50)
|
19
|
+
|
20
|
+
img.save("#{$direc}/texture_gamma.png").free
|
21
|
+
bink.save("#{$direc}/texture_tiny.png").free
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|