rays 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/ChangeLog +8 -0
  2. data/README +4 -0
  3. data/Rakefile +72 -0
  4. data/VERSION +1 -0
  5. data/ext/rays/bitmap.cpp +322 -0
  6. data/ext/rays/extconf.rb +61 -0
  7. data/ext/rays/font.cpp +125 -0
  8. data/ext/rays/image.cpp +166 -0
  9. data/ext/rays/native.cpp +24 -0
  10. data/ext/rays/painter.cpp +573 -0
  11. data/ext/rays/rays.cpp +61 -0
  12. data/ext/rays/rays.h +39 -0
  13. data/ext/rays/texture.cpp +130 -0
  14. data/include/rays.h +20 -0
  15. data/include/rays/bitmap.h +80 -0
  16. data/include/rays/colorspace.h +101 -0
  17. data/include/rays/defs.h +33 -0
  18. data/include/rays/font.h +49 -0
  19. data/include/rays/helpers.h +37 -0
  20. data/include/rays/image.h +68 -0
  21. data/include/rays/opengl.h +15 -0
  22. data/include/rays/painter.h +179 -0
  23. data/include/rays/rays.h +19 -0
  24. data/include/rays/ruby.h +15 -0
  25. data/include/rays/ruby/bitmap.h +39 -0
  26. data/include/rays/ruby/font.h +39 -0
  27. data/include/rays/ruby/image.h +39 -0
  28. data/include/rays/ruby/painter.h +39 -0
  29. data/include/rays/ruby/rays.h +21 -0
  30. data/include/rays/ruby/texture.h +39 -0
  31. data/include/rays/texture.h +56 -0
  32. data/include/rays/transform.h +35 -0
  33. data/lib/rays.rb +9 -0
  34. data/lib/rays/autoinit.rb +10 -0
  35. data/lib/rays/bitmap.rb +25 -0
  36. data/lib/rays/image.rb +15 -0
  37. data/lib/rays/module.rb +30 -0
  38. data/lib/rays/painter.rb +99 -0
  39. data/lib/rays/texture.rb +15 -0
  40. data/rays.gemspec +54 -0
  41. data/src/cocoa/bitmap.mm +286 -0
  42. data/src/cocoa/font.mm +193 -0
  43. data/src/cocoa/helpers.h +26 -0
  44. data/src/cocoa/helpers.mm +25 -0
  45. data/src/cocoa/rays.mm +40 -0
  46. data/src/colorspace.cpp +183 -0
  47. data/src/helpers.cpp +22 -0
  48. data/src/image.cpp +133 -0
  49. data/src/painter.cpp +769 -0
  50. data/src/texture.cpp +360 -0
  51. data/src/transform.cpp +88 -0
  52. data/src/win32/bitmap.cpp +212 -0
  53. data/src/win32/font.cpp +99 -0
  54. data/src/win32/gdi.cpp +771 -0
  55. data/src/win32/gdi.h +226 -0
  56. data/src/win32/rays.cpp +36 -0
  57. data/support.rb +58 -0
  58. data/task/ext.rake +41 -0
  59. data/task/gem.rake +33 -0
  60. data/task/git.rake +22 -0
  61. data/task/lib.rake +54 -0
  62. data/test/helpers.rb +15 -0
  63. data/test/test_painter.rb +11 -0
  64. data/test/test_rays.rb +19 -0
  65. data/test/test_texture.rb +11 -0
  66. metadata +153 -0
data/ChangeLog ADDED
@@ -0,0 +1,8 @@
1
+ 2011-08-28 snori <snori@xord.org>
2
+
3
+ * v0.1.1
4
+
5
+
6
+ 2011-06-03 snori <snori@xord.org>
7
+
8
+ * delete Gemfile.
data/README ADDED
@@ -0,0 +1,4 @@
1
+
2
+ = Rays - A Drawing Engine using OpenGL
3
+
4
+ == by snori@xord.org
data/Rakefile ADDED
@@ -0,0 +1,72 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+
3
+
4
+ $: << File.expand_path(File.dirname __FILE__)
5
+ %w[../rucy/lib ../rays/lib].each do |path|
6
+ $: << File.expand_path(File.join File.dirname(__FILE__), *path.split('/'))
7
+ end
8
+
9
+ require 'rubygems'
10
+ require 'rbconfig'
11
+ require 'support'
12
+ require 'rays/module'
13
+
14
+
15
+ NAME = 'rays'
16
+
17
+ SRCDIR = 'src'
18
+ INCDIR = 'include'
19
+ LIBDIR = 'lib'
20
+ EXTDIR = 'ext'
21
+ TASKDIR = 'task'
22
+
23
+ EXTEXT = RbConfig::CONFIG['DLEXT'] || 'so'
24
+
25
+ DEFS = %w[]
26
+ DEFS << 'WIN32' if win32?
27
+ DEFS << 'COCOA' if cocoa?
28
+
29
+ incroot = RbConfig::CONFIG['rubyhdrdir']
30
+ INCDIRS = Rays.include_dirs + [
31
+ incroot,
32
+ "#{incroot}/#{RUBY_PLATFORM}",
33
+ '/opt/local/include',
34
+ '/opt/include'
35
+ ]
36
+
37
+ RUBY = ENV['RUBY'] || 'ruby'
38
+ GEM = ENV['GEM'] || 'gem'
39
+ GIT = ENV['GIT'] || 'git'
40
+ MAKE = ENV['MAKE'] || 'make'
41
+ CC = RbConfig::CONFIG['CC'] || ENV['CC'] || 'g++'
42
+ CFLAGS = '-Wall -O' + DEFS.map{|s| " -D#{s}"}.join
43
+ AR = ENV['AR'] || 'ar'
44
+ ARFLAGS = 'crs'
45
+
46
+
47
+ task :default => :build
48
+
49
+ task :build => :ext
50
+
51
+ task :rebuild => [:clean, :build]
52
+
53
+ task :lib => 'lib:build'
54
+
55
+ task :ext => 'ext:build'
56
+
57
+ task :gem => 'gem:build'
58
+
59
+ task :install => 'gem:install'
60
+
61
+ task :uninstall => 'gem:uninstall'
62
+
63
+ task :clean => ['lib:clean', 'ext:clean', 'gem:clean']
64
+
65
+ task :test => :ext do
66
+ Dir['test/**/test_*.rb'].each do |rb|
67
+ sh %( ruby #{rb} )
68
+ end
69
+ end
70
+
71
+
72
+ Dir["#{TASKDIR}/**/*.rake"].each {|path| load path}
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,322 @@
1
+ #include "rays/ruby/bitmap.h"
2
+
3
+
4
+ #include <rucy.h>
5
+ #include "rays.h"
6
+
7
+
8
+ using namespace Rucy;
9
+
10
+ using Rays::uchar;
11
+ using Rays::ushort;
12
+ using Rays::ulong;
13
+ using Rays::coord;
14
+
15
+
16
+ namespace Rays
17
+ {
18
+
19
+
20
+ Class
21
+ bitmap_class ()
22
+ {
23
+ static Class c = rays_module().define_class("Bitmap");
24
+ return c;
25
+ }
26
+
27
+
28
+ }// Rays
29
+
30
+
31
+ namespace Rucy
32
+ {
33
+
34
+
35
+ Value
36
+ value (const Rays::Bitmap& bitmap)
37
+ {
38
+ return new_type<Rays::Bitmap>(
39
+ Rays::bitmap_class(), new Rays::Bitmap(bitmap));
40
+ }
41
+
42
+
43
+ }// Rucy
44
+
45
+
46
+ #define this to<Rays::Bitmap*>(self)
47
+
48
+ #define CHECK CHECK_OBJECT(self, Rays::Bitmap, Rays::bitmap_class())
49
+
50
+
51
+ static
52
+ RUBY_DEF_ALLOC(alloc, klass)
53
+ {
54
+ return new_type<Rays::Bitmap>(klass, new Rays::Bitmap);
55
+ }
56
+ RUBY_END
57
+
58
+ static
59
+ RUBY_DEFN(initialize)
60
+ {
61
+ CHECK_OBJ(self, Rays::Bitmap, Rays::bitmap_class());
62
+ if (argc != 0 && argc != 2 && argc != 3)
63
+ arg_count_error("Bitmap#initialize", argc, 0, 2, 3);
64
+
65
+ if (argc == 0) return self;
66
+
67
+ int width = to<int>(argv[0]);
68
+ int height = to<int>(argv[1]);
69
+ uint colorspace = (argc == 3) ? to<uint>(argv[2]) : (uint) Rays::RGBA;
70
+
71
+ *this = Rays::Bitmap(width, height, (Rays::ColorSpaceType) colorspace);
72
+ return self;
73
+ }
74
+ RUBY_END
75
+
76
+ static
77
+ RUBY_DEF0(width)
78
+ {
79
+ CHECK;
80
+
81
+ return value(this->width());
82
+ }
83
+ RUBY_END
84
+
85
+ static
86
+ RUBY_DEF0(height)
87
+ {
88
+ CHECK;
89
+
90
+ return value(this->height());
91
+ }
92
+ RUBY_END
93
+
94
+ static
95
+ RUBY_DEF0(color_space)
96
+ {
97
+ CHECK;
98
+
99
+ return value(this->color_space().type());
100
+ }
101
+ RUBY_END
102
+
103
+ static
104
+ RUBY_DEF2(at, x, y)
105
+ {
106
+ CHECK;
107
+
108
+ int xx = x.as_i(), yy = y.as_i();
109
+ void* pixel = this->at<void*>(xx, yy);
110
+ if (!pixel) error("Bitmap#at(%d, %d) failed.", xx, yy);
111
+
112
+ Value array(this->color_space().Bpp() / this->color_space().Bpc(), NULL);
113
+ if (this->color_space().is_float())
114
+ {
115
+ float* p = (float*) pixel;
116
+ switch (this->color_space().type())
117
+ {
118
+ case Rays::GRAY_float:
119
+ array.push(p[0]);
120
+ break;
121
+ case Rays::RGB_float:
122
+ array.push(p[0]).push(p[1]).push(p[2]);
123
+ break;
124
+ case Rays::RGBA_float:
125
+ array.push(p[0]).push(p[1]).push(p[2]).push(p[3]);
126
+ break;
127
+ case Rays::ARGB_float:
128
+ array.push(p[1]).push(p[2]).push(p[3]).push(p[0]);
129
+ break;
130
+ case Rays::BGR_float:
131
+ array.push(p[2]).push(p[1]).push(p[0]);
132
+ break;
133
+ case Rays::BGRA_float:
134
+ array.push(p[2]).push(p[1]).push(p[0]).push(p[3]);
135
+ break;
136
+ case Rays::ABGR_float:
137
+ array.push(p[3]).push(p[2]).push(p[1]).push(p[0]);
138
+ break;
139
+ default:
140
+ error("Bitmap#at: unknown color space");
141
+ }
142
+ }
143
+ else
144
+ {
145
+ uchar* p = (uchar*) pixel;
146
+ switch (this->color_space().type())
147
+ {
148
+ case Rays::GRAY_8:
149
+ array.push(*(uchar*) pixel);
150
+ break;
151
+ case Rays::GRAY_16:
152
+ array.push(*(ushort*) pixel);
153
+ break;
154
+ case Rays::GRAY_32:
155
+ array.push(*(ulong*) pixel);
156
+ break;
157
+ case Rays::RGB_888:
158
+ array.push(p[0]).push(p[1]).push(p[2]);
159
+ break;
160
+ case Rays::RGBA_8888:
161
+ array.push(p[0]).push(p[1]).push(p[2]).push(p[3]);
162
+ break;
163
+ case Rays::ARGB_8888:
164
+ array.push(p[1]).push(p[2]).push(p[3]).push(p[0]);
165
+ break;
166
+ case Rays::RGBX_8888:
167
+ array.push(p[0]).push(p[1]).push(p[2]);
168
+ break;
169
+ case Rays::XRGB_8888:
170
+ array.push(p[1]).push(p[2]).push(p[3]);
171
+ break;
172
+ case Rays::BGR_888:
173
+ array.push(p[2]).push(p[1]).push(p[0]);
174
+ break;
175
+ case Rays::BGRA_8888:
176
+ array.push(p[2]).push(p[1]).push(p[0]).push(p[3]);
177
+ break;
178
+ case Rays::ABGR_8888:
179
+ array.push(p[3]).push(p[2]).push(p[1]).push(p[0]);
180
+ break;
181
+ case Rays::BGRX_8888:
182
+ array.push(p[2]).push(p[1]).push(p[0]);
183
+ break;
184
+ case Rays::XBGR_8888:
185
+ array.push(p[3]).push(p[2]).push(p[1]);
186
+ break;
187
+ default:
188
+ error("Bitmap#at: unknown color space");
189
+ }
190
+ }
191
+
192
+ return array;
193
+ }
194
+ RUBY_END
195
+
196
+ static
197
+ RUBY_DEF3(assign_at, x, y, color)
198
+ {
199
+ CHECK;
200
+
201
+ int xx = x.as_i(), yy = y.as_i();
202
+ void* pixel = this->at<void*>(xx, yy);
203
+ if (!pixel) error("Bitmap#assign_at(%d, %d) failed.", xx, yy);
204
+
205
+ Value array(this->color_space().Bpp() / this->color_space().Bpc(), NULL);
206
+ if (this->color_space().is_float())
207
+ {
208
+ float* p = (float*) pixel;
209
+ switch (this->color_space().type())
210
+ {
211
+ #define C(n) ((float) color[n].as_f())
212
+ case Rays::GRAY_float:
213
+ p[0] = C(0);
214
+ break;
215
+ case Rays::RGB_float:
216
+ p[0] = C(0); p[1] = C(1); p[2] = C(2);
217
+ break;
218
+ case Rays::RGBA_float:
219
+ p[0] = C(0); p[1] = C(1); p[2] = C(2); p[3] = C(3);
220
+ break;
221
+ case Rays::ARGB_float:
222
+ p[0] = C(1); p[1] = C(2); p[2] = C(3); p[3] = C(0);
223
+ break;
224
+ case Rays::BGR_float:
225
+ p[0] = C(2); p[1] = C(1); p[2] = C(0);
226
+ break;
227
+ case Rays::BGRA_float:
228
+ p[0] = C(2); p[1] = C(1); p[2] = C(0); p[3] = C(3);
229
+ break;
230
+ case Rays::ABGR_float:
231
+ p[0] = C(3); p[1] = C(2); p[2] = C(1); p[3] = C(0);
232
+ break;
233
+ #undef C
234
+ default:
235
+ error("Bitmap#at: unknown color space");
236
+ }
237
+ }
238
+ else
239
+ {
240
+ uchar* p = (uchar*) pixel;
241
+ switch (this->color_space().type())
242
+ {
243
+ #define C(n) ((uchar) color[n].as_i())
244
+ case Rays::GRAY_8:
245
+ *(uchar*) pixel = C(0);
246
+ break;
247
+ case Rays::GRAY_16:
248
+ *(ushort*) pixel = C(0);
249
+ break;
250
+ case Rays::GRAY_32:
251
+ *(ulong*) pixel = C(0);
252
+ break;
253
+ case Rays::RGB_888:
254
+ p[0] = C(0); p[1] = C(1); p[2] = C(2);
255
+ break;
256
+ case Rays::RGBA_8888:
257
+ p[0] = C(0); p[1] = C(1); p[2] = C(2); p[3] = C(3);
258
+ break;
259
+ case Rays::ARGB_8888:
260
+ p[0] = C(1); p[1] = C(2); p[2] = C(3); p[3] = C(0);
261
+ break;
262
+ case Rays::RGBX_8888:
263
+ p[0] = C(0); p[1] = C(1); p[2] = C(2);
264
+ break;
265
+ case Rays::XRGB_8888:
266
+ p[0] = C(1); p[1] = C(2); p[2] = C(3);
267
+ break;
268
+ case Rays::BGR_888:
269
+ p[0] = C(2); p[1] = C(1); p[2] = C(0);
270
+ break;
271
+ case Rays::BGRA_8888:
272
+ p[0] = C(2); p[1] = C(1); p[2] = C(0); p[3] = C(3);
273
+ break;
274
+ case Rays::ABGR_8888:
275
+ p[0] = C(3); p[1] = C(2); p[2] = C(1); p[3] = C(0);
276
+ break;
277
+ case Rays::BGRX_8888:
278
+ p[0] = C(2); p[1] = C(1); p[2] = C(0);
279
+ break;
280
+ case Rays::XBGR_8888:
281
+ p[0] = C(3); p[1] = C(2); p[2] = C(1);
282
+ break;
283
+ #undef C
284
+ default:
285
+ error("Bitmap#at: unknown color space");
286
+ }
287
+ }
288
+
289
+ return color;
290
+ }
291
+ RUBY_END
292
+
293
+
294
+ static
295
+ RUBY_DEF1(load, path)
296
+ {
297
+ Rays::Bitmap bmp;
298
+ if (!Rays::load_bitmap(&bmp, path.c_str()))
299
+ error("Bitmap.load('%s') failed.", path.c_str());
300
+
301
+ return value(bmp);
302
+ }
303
+ RUBY_END
304
+
305
+
306
+ void
307
+ Init_bitmap ()
308
+ {
309
+ Rays::rays_module()
310
+ .define_const("RGB", Rays::RGB)
311
+ .define_const("RGBA", Rays::RGBA);
312
+
313
+ Rays::bitmap_class()
314
+ .define_alloc_func(alloc)
315
+ .define_method("initialize", initialize)
316
+ .define_method("width", width)
317
+ .define_method("height", height)
318
+ .define_method("color_space", color_space)
319
+ .define_method("[]", at)
320
+ .define_method("[]=", assign_at)
321
+ .define_function("load", load);
322
+ }
@@ -0,0 +1,61 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ %w[../../../rucy/lib ../../lib].each do |path|
5
+ $: << File.expand_path(File.join File.dirname(__FILE__), *path.split('/'))
6
+ end
7
+
8
+ require 'rubygems'
9
+ require 'mkmf'
10
+ require 'rucy/module'
11
+ require 'rays/module'
12
+
13
+
14
+ DEBUG = ENV['DEBUG'] || false
15
+
16
+ DEFS = []
17
+ INCDIRS = %w[/opt/local/include /opt/include] +
18
+ Rucy.include_dirs + Rays.include_dirs
19
+ LIBDIRS = %w[] +
20
+ Rucy.library_dirs + Rays.library_dirs
21
+
22
+ HEADERS = %w[
23
+ boost/scoped_array.hpp
24
+ boost/shared_ptr.hpp
25
+ ruby.h
26
+ rucy.h
27
+ rays.h
28
+ ]
29
+ LIBS = %w[stdc++ rucy rays]
30
+ FRAMEWORKS = %w[]
31
+
32
+
33
+ DEFS << '_DEBUG' if DEBUG
34
+
35
+ case RUBY_PLATFORM
36
+ when /mswin|ming|cygwin/
37
+ DEFS << 'WINDOWS' << 'WIN32' << $~[0].upcase
38
+ LIBS.unshift 'gdi32', 'opengl32'
39
+ when /darwin/
40
+ DEFS << 'COCOA'
41
+ FRAMEWORKS << 'AppKit' << 'OpenGL'
42
+ end
43
+
44
+ $CPPFLAGS << DEFS.map {|s| " -D#{s}"}.join
45
+ $CPPFLAGS << INCDIRS.map {|s| " -I#{s}"}.join
46
+ $LDFLAGS << LIBDIRS.map {|s| " -L#{s}"}.join
47
+ $LDFLAGS << FRAMEWORKS.map {|s| " -framework #{s}"}.join
48
+ $LOCAL_LIBS << ' -lrucy'
49
+
50
+ dir_config 'boost'
51
+ dir_config 'rucy', Rucy.root_dir
52
+ dir_config 'rays', Rays.root_dir
53
+
54
+
55
+ Config::CONFIG.each {|key, val| val.gsub!(/gcc/, 'g++')}
56
+
57
+ exit 1 unless HEADERS.all? {|s| have_header(s)}
58
+ exit 1 unless LIBS.all? {|s| have_library(s)}
59
+
60
+
61
+ create_makefile 'rays/native'