texplay 0.4.3 → 0.4.4.pre
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.
- checksums.yaml +7 -0
- data/CHANGELOG +225 -222
- data/README.markdown +48 -48
- data/Rakefile +16 -16
- data/examples/common.rb +18 -18
- data/examples/example_alpha_blend.rb +29 -29
- data/examples/example_bezier.rb +41 -41
- data/examples/example_blank.rb +37 -37
- data/examples/example_cache.rb +21 -21
- data/examples/example_color_control.rb +69 -69
- data/examples/example_color_transform.rb +62 -62
- data/examples/example_color_transform_circle.rb +34 -34
- data/examples/example_darken.rb +24 -24
- data/examples/example_dup.rb +73 -73
- data/examples/example_each.rb +39 -39
- data/examples/example_effect.rb +34 -34
- data/examples/example_fill.rb +43 -43
- data/examples/example_fill_old.rb +48 -48
- data/examples/example_fluent.rb +29 -29
- data/examples/example_font.rb +31 -31
- data/examples/example_hash_arguments.rb +46 -46
- data/examples/example_ippa.rb +23 -23
- data/examples/example_light.rb +75 -75
- data/examples/example_light_multiply.rb +18 -18
- data/examples/example_lsystem.rb +61 -61
- data/examples/example_melt.rb +25 -25
- data/examples/example_meyet.rb +62 -62
- data/examples/example_polyline.rb +42 -42
- data/examples/example_scale.rb +27 -27
- data/examples/example_select.rb +36 -36
- data/examples/example_select2.rb +25 -25
- data/examples/example_simple.rb +46 -46
- data/examples/example_splice.rb +26 -26
- data/examples/example_sync.rb +59 -59
- data/examples/example_tiles.rb +41 -41
- data/examples/example_trace.rb +22 -22
- data/examples/example_transparent.rb +28 -28
- data/examples/example_transparent2.rb +24 -24
- data/examples/example_transparent3.rb +20 -20
- data/examples/example_turtle.rb +39 -39
- data/examples/example_weird.rb +22 -22
- data/examples/example_window_render_to_image.rb +41 -41
- data/examples/example_window_to_blob.rb +35 -35
- data/examples/media/maria.png +0 -0
- data/examples/media/rose.bmp +0 -0
- data/ext/texplay/actions.c +1011 -1006
- data/ext/texplay/actions.h +60 -60
- data/ext/texplay/bindings.c +1130 -1125
- data/ext/texplay/bindings.h +46 -46
- data/ext/texplay/cache.c +123 -118
- data/ext/texplay/cache.h +24 -24
- data/ext/texplay/compat.h +21 -27
- data/ext/texplay/extconf.rb +38 -38
- data/ext/texplay/graphics_utils.c +1318 -1313
- data/ext/texplay/graphics_utils.h +22 -22
- data/ext/texplay/texplay.c +206 -201
- data/ext/texplay/texplay.h +153 -153
- data/ext/texplay/utils.c +896 -891
- data/ext/texplay/utils.h +153 -153
- data/lib/texplay-contrib.rb +147 -147
- data/lib/texplay.rb +347 -347
- data/lib/texplay/alone.rb +20 -20
- data/lib/texplay/c_function_docs.rb +178 -178
- data/lib/texplay/live.rb +84 -84
- data/lib/texplay/version.rb +3 -3
- data/live/live.rb +85 -85
- data/test/image_spec.rb +45 -45
- data/test/texplay_spec.rb +144 -144
- metadata +42 -52
- data/lib/texplay/1.8/texplay.so +0 -0
- data/lib/texplay/1.9/texplay.so +0 -0
data/lib/texplay/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module TexPlay
|
2
|
-
VERSION = "0.4.
|
3
|
-
end
|
1
|
+
module TexPlay
|
2
|
+
VERSION = "0.4.4.pre"
|
3
|
+
end
|
data/live/live.rb
CHANGED
@@ -1,85 +1,85 @@
|
|
1
|
-
direc = File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require "#{direc}/../lib/texplay"
|
5
|
-
require 'pry'
|
6
|
-
|
7
|
-
WIDTH = 640
|
8
|
-
HEIGHT = 480
|
9
|
-
|
10
|
-
class Gosu::Image
|
11
|
-
attr_accessor :x, :y
|
12
|
-
|
13
|
-
alias_method :orig_init, :initialize
|
14
|
-
def initialize(*args)
|
15
|
-
@x = WIDTH / 2
|
16
|
-
@y = HEIGHT / 2
|
17
|
-
orig_init(*args)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class WinClass < Gosu::Window
|
22
|
-
|
23
|
-
class View
|
24
|
-
attr_accessor :zoom, :rotate
|
25
|
-
|
26
|
-
def initialize
|
27
|
-
@zoom = 1
|
28
|
-
@rotate = 0
|
29
|
-
end
|
30
|
-
|
31
|
-
def reset
|
32
|
-
@zoom = 1
|
33
|
-
@rotate = 0
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
attr_reader :images, :view
|
38
|
-
|
39
|
-
def initialize
|
40
|
-
super(WIDTH, HEIGHT, false)
|
41
|
-
Gosu.enable_undocumented_retrofication
|
42
|
-
|
43
|
-
@images = []
|
44
|
-
@view = View.new
|
45
|
-
@pry_instance = Pry.new :prompt => [Proc.new { "(live)> " }, Proc.new { "(live)* " }]
|
46
|
-
|
47
|
-
@img = TexPlay.create_image(self, 200, 200)
|
48
|
-
@img.rect 0, 0, @img.width - 1, @img.height - 1
|
49
|
-
|
50
|
-
images << @img
|
51
|
-
@binding = binding
|
52
|
-
end
|
53
|
-
|
54
|
-
def create_image(width, height, options={})
|
55
|
-
TexPlay.create_image(self, width, height, options)
|
56
|
-
end
|
57
|
-
|
58
|
-
def load_image(file)
|
59
|
-
Gosu::Image.new(self, file)
|
60
|
-
end
|
61
|
-
|
62
|
-
def show_image(image)
|
63
|
-
images << image
|
64
|
-
end
|
65
|
-
|
66
|
-
def hide_image(image)
|
67
|
-
images.delete(image)
|
68
|
-
end
|
69
|
-
|
70
|
-
def draw
|
71
|
-
images.uniq!
|
72
|
-
images.each do |v|
|
73
|
-
v.draw_rot(v.x, v.y, 1, view.rotate, 0.5, 0.5, view.zoom, view.zoom)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def update
|
78
|
-
@pry_instance.rep(@binding)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
w = WinClass.new
|
83
|
-
|
84
|
-
w.show
|
85
|
-
|
1
|
+
direc = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require "#{direc}/../lib/texplay"
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
WIDTH = 640
|
8
|
+
HEIGHT = 480
|
9
|
+
|
10
|
+
class Gosu::Image
|
11
|
+
attr_accessor :x, :y
|
12
|
+
|
13
|
+
alias_method :orig_init, :initialize
|
14
|
+
def initialize(*args)
|
15
|
+
@x = WIDTH / 2
|
16
|
+
@y = HEIGHT / 2
|
17
|
+
orig_init(*args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class WinClass < Gosu::Window
|
22
|
+
|
23
|
+
class View
|
24
|
+
attr_accessor :zoom, :rotate
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
@zoom = 1
|
28
|
+
@rotate = 0
|
29
|
+
end
|
30
|
+
|
31
|
+
def reset
|
32
|
+
@zoom = 1
|
33
|
+
@rotate = 0
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :images, :view
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
super(WIDTH, HEIGHT, false)
|
41
|
+
Gosu.enable_undocumented_retrofication
|
42
|
+
|
43
|
+
@images = []
|
44
|
+
@view = View.new
|
45
|
+
@pry_instance = Pry.new :prompt => [Proc.new { "(live)> " }, Proc.new { "(live)* " }]
|
46
|
+
|
47
|
+
@img = TexPlay.create_image(self, 200, 200)
|
48
|
+
@img.rect 0, 0, @img.width - 1, @img.height - 1
|
49
|
+
|
50
|
+
images << @img
|
51
|
+
@binding = binding
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_image(width, height, options={})
|
55
|
+
TexPlay.create_image(self, width, height, options)
|
56
|
+
end
|
57
|
+
|
58
|
+
def load_image(file)
|
59
|
+
Gosu::Image.new(self, file)
|
60
|
+
end
|
61
|
+
|
62
|
+
def show_image(image)
|
63
|
+
images << image
|
64
|
+
end
|
65
|
+
|
66
|
+
def hide_image(image)
|
67
|
+
images.delete(image)
|
68
|
+
end
|
69
|
+
|
70
|
+
def draw
|
71
|
+
images.uniq!
|
72
|
+
images.each do |v|
|
73
|
+
v.draw_rot(v.x, v.y, 1, view.rotate, 0.5, 0.5, view.zoom, view.zoom)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def update
|
78
|
+
@pry_instance.rep(@binding)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
w = WinClass.new
|
83
|
+
|
84
|
+
w.show
|
85
|
+
|
data/test/image_spec.rb
CHANGED
@@ -1,45 +1,45 @@
|
|
1
|
-
direc = File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require "#{direc}/../lib/texplay"
|
4
|
-
|
5
|
-
class Module
|
6
|
-
public :remove_const
|
7
|
-
end
|
8
|
-
|
9
|
-
describe Gosu::Image do
|
10
|
-
before do
|
11
|
-
@window = Gosu::Window.new(640, 480, false)
|
12
|
-
NormalImageSize = [Gosu::MAX_TEXTURE_SIZE - 2, Gosu::MAX_TEXTURE_SIZE - 2]
|
13
|
-
TooLargeImageSize = [2000, 2000]
|
14
|
-
end
|
15
|
-
|
16
|
-
after do
|
17
|
-
Object.remove_const(:NormalImageSize)
|
18
|
-
Object.remove_const(:TooLargeImageSize)
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "Gosu::Image#new (patched by TexPlay)" do
|
22
|
-
describe "caching option" do
|
23
|
-
it "should not cache image if :caching => false" do
|
24
|
-
source_image = TexPlay.create_image(@window, *NormalImageSize)
|
25
|
-
source_image.quad_cached?.should == false
|
26
|
-
|
27
|
-
image = Gosu::Image.new(@window, source_image, :caching => false)
|
28
|
-
image.width.should == NormalImageSize[0]
|
29
|
-
image.height.should == NormalImageSize[1]
|
30
|
-
|
31
|
-
image.quad_cached?.should == false
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should cache the image if :caching => true" do
|
35
|
-
source_image = TexPlay.create_image(@window, *NormalImageSize)
|
36
|
-
|
37
|
-
image = Gosu::Image.new(@window, source_image, :caching => true)
|
38
|
-
image.width.should == NormalImageSize[0]
|
39
|
-
image.height.should == NormalImageSize[1]
|
40
|
-
|
41
|
-
image.quad_cached?.should == true
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
1
|
+
direc = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require "#{direc}/../lib/texplay"
|
4
|
+
|
5
|
+
class Module
|
6
|
+
public :remove_const
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Gosu::Image do
|
10
|
+
before do
|
11
|
+
@window = Gosu::Window.new(640, 480, false)
|
12
|
+
NormalImageSize = [Gosu::MAX_TEXTURE_SIZE - 2, Gosu::MAX_TEXTURE_SIZE - 2]
|
13
|
+
TooLargeImageSize = [2000, 2000]
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
Object.remove_const(:NormalImageSize)
|
18
|
+
Object.remove_const(:TooLargeImageSize)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "Gosu::Image#new (patched by TexPlay)" do
|
22
|
+
describe "caching option" do
|
23
|
+
it "should not cache image if :caching => false" do
|
24
|
+
source_image = TexPlay.create_image(@window, *NormalImageSize)
|
25
|
+
source_image.quad_cached?.should == false
|
26
|
+
|
27
|
+
image = Gosu::Image.new(@window, source_image, :caching => false)
|
28
|
+
image.width.should == NormalImageSize[0]
|
29
|
+
image.height.should == NormalImageSize[1]
|
30
|
+
|
31
|
+
image.quad_cached?.should == false
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should cache the image if :caching => true" do
|
35
|
+
source_image = TexPlay.create_image(@window, *NormalImageSize)
|
36
|
+
|
37
|
+
image = Gosu::Image.new(@window, source_image, :caching => true)
|
38
|
+
image.width.should == NormalImageSize[0]
|
39
|
+
image.height.should == NormalImageSize[1]
|
40
|
+
|
41
|
+
image.quad_cached?.should == true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/test/texplay_spec.rb
CHANGED
@@ -1,144 +1,144 @@
|
|
1
|
-
$LOAD_PATH.unshift File.join(File.expand_path(__FILE__), '..', 'lib','texplay')
|
2
|
-
direc = File.dirname(__FILE__)
|
3
|
-
|
4
|
-
require "#{direc}/../lib/texplay"
|
5
|
-
|
6
|
-
describe TexPlay do
|
7
|
-
described_class = TexPlay
|
8
|
-
|
9
|
-
before do
|
10
|
-
@window = Gosu::Window.new(640, 480, false)
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#create_image" do
|
14
|
-
it "should create a blank image of the correct size" do
|
15
|
-
width, height = 30, 10
|
16
|
-
image = described_class.create_image(@window, width, height)
|
17
|
-
|
18
|
-
image.width.should == width
|
19
|
-
image.height.should == height
|
20
|
-
|
21
|
-
width.times do |x|
|
22
|
-
height.times do |y|
|
23
|
-
image.get_pixel(x, y).should == [0.0, 0.0, 0.0, 0.0]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should create a coloured image of the correct size" do
|
29
|
-
width, height = 10, 30
|
30
|
-
color = [1.0, 1.0, 0.0, 1.0]
|
31
|
-
image = described_class.create_image(@window, width, height, :color => color)
|
32
|
-
|
33
|
-
image.width.should == width
|
34
|
-
image.height.should == height
|
35
|
-
|
36
|
-
width.times do |x|
|
37
|
-
height.times do |y|
|
38
|
-
image.get_pixel(x, y).should == color
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should raise an error if an image dimension is 0 or less" do
|
44
|
-
lambda { described_class.create_image(@window, 0, 0)}.should raise_error(ArgumentError)
|
45
|
-
end
|
46
|
-
|
47
|
-
# TODO: Should probably be an ArgumentError.
|
48
|
-
it "should raise an ArgumentError if the image would be too large" do
|
49
|
-
too_big = TexPlay::TP_MAX_QUAD_SIZE + 1
|
50
|
-
[[too_big, 5], [10, too_big], [too_big, too_big]].each do |width, height|
|
51
|
-
puts "WIDTH: #{width.inspect}, HEIGHT: #{height.inspect}"
|
52
|
-
lambda {
|
53
|
-
described_class.create_image(@window, width, height)
|
54
|
-
}.should raise_error(ArgumentError)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "#clear" do
|
60
|
-
it "should clear an image to the correct color" do
|
61
|
-
img = described_class.create_image(@window, 10, 10)
|
62
|
-
img.clear :color => :red
|
63
|
-
(0...img.width).each do |x|
|
64
|
-
(0...img.height).each do |y|
|
65
|
-
img.get_pixel(x,y).should == [1,0,0,1]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "#from_blob" do
|
72
|
-
# it "should create an image with the requested pixel data and size" do
|
73
|
-
# # 4 x 3, with columns of red, blue, green, transparent.
|
74
|
-
# gosu_colors = [[255, 0, 0, 255], [0, 255, 0, 255], [0, 0, 255, 255], [0, 0, 0, 0]]
|
75
|
-
# texplay_colors = gosu_colors.map {|a| a.map {|c| c / 255.0 } }
|
76
|
-
# width, height = gosu_colors.size, 3
|
77
|
-
|
78
|
-
# image = described_class.from_blob(@window, (gosu_colors * height).flatten.pack('C*'), width, height)
|
79
|
-
|
80
|
-
# image.width.should == width
|
81
|
-
# image.height.should == height
|
82
|
-
|
83
|
-
# texplay_colors.each_with_index do |color, x|
|
84
|
-
# 3.times do |y|
|
85
|
-
# image.get_pixel(x, y).should == color
|
86
|
-
# end
|
87
|
-
# end
|
88
|
-
# end
|
89
|
-
|
90
|
-
it "should raise an error if the image size is not correct for the blob data" do
|
91
|
-
lambda { described_class.from_blob(@window, [1, 1, 1, 1].pack("C*"), 2, 1) }.should raise_error(ArgumentError)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should raise an error if an image dimension is 0 or less" do
|
95
|
-
lambda { described_class.from_blob(@window, '', 0, 0) }.should raise_error(ArgumentError)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "alpha_blend" do
|
100
|
-
it "should alpha blend using source alpha and not fixing alpha" do
|
101
|
-
img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
|
102
|
-
img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => :source
|
103
|
-
img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
|
104
|
-
end
|
105
|
-
|
106
|
-
it "hash params true and :source should be equivalent" do
|
107
|
-
img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
|
108
|
-
img2 = img1.dup
|
109
|
-
img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => :source
|
110
|
-
img2.clear :color => [0, 0, 1, 0.5], :alpha_blend => true
|
111
|
-
|
112
|
-
img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
|
113
|
-
img2.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
|
114
|
-
end
|
115
|
-
|
116
|
-
it "false or nil should prevent alpha blending" do
|
117
|
-
img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
|
118
|
-
img2 = img1.dup
|
119
|
-
img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => false
|
120
|
-
img2.clear :color => [0, 0, 1, 0.5], :alpha_blend => nil
|
121
|
-
|
122
|
-
img1.get_pixel(5, 5).should == [0, 0, 1, 0.5]
|
123
|
-
img2.get_pixel(5, 5).should == [0, 0, 1, 0.5]
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should alpha blend using dest alpha and not fixing alpha" do
|
127
|
-
img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 0.5]
|
128
|
-
img1.clear :color => [0, 0, 1, 1], :alpha_blend => :dest
|
129
|
-
img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should alpha blend using source alpha and fixing alpha" do
|
133
|
-
img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
|
134
|
-
img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => :source_with_fixed_alpha
|
135
|
-
img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 1]
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should alpha blend using dest alpha and fixing alpha" do
|
139
|
-
img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 0.5]
|
140
|
-
img1.clear :color => [0, 0, 1, 1], :alpha_blend => :dest_with_fixed_alpha
|
141
|
-
img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.5]
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
1
|
+
$LOAD_PATH.unshift File.join(File.expand_path(__FILE__), '..', 'lib','texplay')
|
2
|
+
direc = File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require "#{direc}/../lib/texplay"
|
5
|
+
|
6
|
+
describe TexPlay do
|
7
|
+
described_class = TexPlay
|
8
|
+
|
9
|
+
before do
|
10
|
+
@window = Gosu::Window.new(640, 480, false)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#create_image" do
|
14
|
+
it "should create a blank image of the correct size" do
|
15
|
+
width, height = 30, 10
|
16
|
+
image = described_class.create_image(@window, width, height)
|
17
|
+
|
18
|
+
image.width.should == width
|
19
|
+
image.height.should == height
|
20
|
+
|
21
|
+
width.times do |x|
|
22
|
+
height.times do |y|
|
23
|
+
image.get_pixel(x, y).should == [0.0, 0.0, 0.0, 0.0]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should create a coloured image of the correct size" do
|
29
|
+
width, height = 10, 30
|
30
|
+
color = [1.0, 1.0, 0.0, 1.0]
|
31
|
+
image = described_class.create_image(@window, width, height, :color => color)
|
32
|
+
|
33
|
+
image.width.should == width
|
34
|
+
image.height.should == height
|
35
|
+
|
36
|
+
width.times do |x|
|
37
|
+
height.times do |y|
|
38
|
+
image.get_pixel(x, y).should == color
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should raise an error if an image dimension is 0 or less" do
|
44
|
+
lambda { described_class.create_image(@window, 0, 0)}.should raise_error(ArgumentError)
|
45
|
+
end
|
46
|
+
|
47
|
+
# TODO: Should probably be an ArgumentError.
|
48
|
+
it "should raise an ArgumentError if the image would be too large" do
|
49
|
+
too_big = TexPlay::TP_MAX_QUAD_SIZE + 1
|
50
|
+
[[too_big, 5], [10, too_big], [too_big, too_big]].each do |width, height|
|
51
|
+
puts "WIDTH: #{width.inspect}, HEIGHT: #{height.inspect}"
|
52
|
+
lambda {
|
53
|
+
described_class.create_image(@window, width, height)
|
54
|
+
}.should raise_error(ArgumentError)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#clear" do
|
60
|
+
it "should clear an image to the correct color" do
|
61
|
+
img = described_class.create_image(@window, 10, 10)
|
62
|
+
img.clear :color => :red
|
63
|
+
(0...img.width).each do |x|
|
64
|
+
(0...img.height).each do |y|
|
65
|
+
img.get_pixel(x,y).should == [1,0,0,1]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#from_blob" do
|
72
|
+
# it "should create an image with the requested pixel data and size" do
|
73
|
+
# # 4 x 3, with columns of red, blue, green, transparent.
|
74
|
+
# gosu_colors = [[255, 0, 0, 255], [0, 255, 0, 255], [0, 0, 255, 255], [0, 0, 0, 0]]
|
75
|
+
# texplay_colors = gosu_colors.map {|a| a.map {|c| c / 255.0 } }
|
76
|
+
# width, height = gosu_colors.size, 3
|
77
|
+
|
78
|
+
# image = described_class.from_blob(@window, (gosu_colors * height).flatten.pack('C*'), width, height)
|
79
|
+
|
80
|
+
# image.width.should == width
|
81
|
+
# image.height.should == height
|
82
|
+
|
83
|
+
# texplay_colors.each_with_index do |color, x|
|
84
|
+
# 3.times do |y|
|
85
|
+
# image.get_pixel(x, y).should == color
|
86
|
+
# end
|
87
|
+
# end
|
88
|
+
# end
|
89
|
+
|
90
|
+
it "should raise an error if the image size is not correct for the blob data" do
|
91
|
+
lambda { described_class.from_blob(@window, [1, 1, 1, 1].pack("C*"), 2, 1) }.should raise_error(ArgumentError)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should raise an error if an image dimension is 0 or less" do
|
95
|
+
lambda { described_class.from_blob(@window, '', 0, 0) }.should raise_error(ArgumentError)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "alpha_blend" do
|
100
|
+
it "should alpha blend using source alpha and not fixing alpha" do
|
101
|
+
img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
|
102
|
+
img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => :source
|
103
|
+
img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
|
104
|
+
end
|
105
|
+
|
106
|
+
it "hash params true and :source should be equivalent" do
|
107
|
+
img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
|
108
|
+
img2 = img1.dup
|
109
|
+
img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => :source
|
110
|
+
img2.clear :color => [0, 0, 1, 0.5], :alpha_blend => true
|
111
|
+
|
112
|
+
img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
|
113
|
+
img2.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
|
114
|
+
end
|
115
|
+
|
116
|
+
it "false or nil should prevent alpha blending" do
|
117
|
+
img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
|
118
|
+
img2 = img1.dup
|
119
|
+
img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => false
|
120
|
+
img2.clear :color => [0, 0, 1, 0.5], :alpha_blend => nil
|
121
|
+
|
122
|
+
img1.get_pixel(5, 5).should == [0, 0, 1, 0.5]
|
123
|
+
img2.get_pixel(5, 5).should == [0, 0, 1, 0.5]
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should alpha blend using dest alpha and not fixing alpha" do
|
127
|
+
img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 0.5]
|
128
|
+
img1.clear :color => [0, 0, 1, 1], :alpha_blend => :dest
|
129
|
+
img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should alpha blend using source alpha and fixing alpha" do
|
133
|
+
img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
|
134
|
+
img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => :source_with_fixed_alpha
|
135
|
+
img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 1]
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should alpha blend using dest alpha and fixing alpha" do
|
139
|
+
img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 0.5]
|
140
|
+
img1.clear :color => [0, 0, 1, 1], :alpha_blend => :dest_with_fixed_alpha
|
141
|
+
img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.5]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|