rays 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/.doc/ext/rays/bitmap.cpp +70 -233
  3. data/.doc/ext/rays/bounds.cpp +339 -57
  4. data/.doc/ext/rays/color.cpp +58 -48
  5. data/.doc/ext/rays/color_space.cpp +174 -0
  6. data/.doc/ext/rays/font.cpp +31 -53
  7. data/.doc/ext/rays/image.cpp +64 -67
  8. data/.doc/ext/rays/matrix.cpp +22 -50
  9. data/.doc/ext/rays/native.cpp +9 -2
  10. data/.doc/ext/rays/painter.cpp +276 -259
  11. data/.doc/ext/rays/point.cpp +186 -52
  12. data/.doc/ext/rays/rays.cpp +25 -20
  13. data/.doc/ext/rays/shader.cpp +61 -0
  14. data/.doc/ext/rays/texture.cpp +47 -59
  15. data/{README → README.md} +0 -0
  16. data/Rakefile +6 -5
  17. data/VERSION +1 -1
  18. data/ext/rays/bitmap.cpp +88 -248
  19. data/ext/rays/bounds.cpp +437 -141
  20. data/ext/rays/color.cpp +79 -69
  21. data/ext/rays/color_space.cpp +185 -0
  22. data/ext/rays/extconf.rb +14 -63
  23. data/ext/rays/font.cpp +44 -65
  24. data/ext/rays/image.cpp +82 -81
  25. data/ext/rays/matrix.cpp +32 -60
  26. data/ext/rays/native.cpp +9 -2
  27. data/ext/rays/painter.cpp +345 -321
  28. data/ext/rays/point.cpp +212 -69
  29. data/ext/rays/rays.cpp +29 -23
  30. data/ext/rays/shader.cpp +63 -0
  31. data/ext/rays/texture.cpp +64 -74
  32. data/include/rays/bitmap.h +21 -12
  33. data/include/rays/bounds.h +67 -9
  34. data/include/rays/color.h +23 -7
  35. data/include/rays/{colorspace.h → color_space.h} +6 -3
  36. data/include/rays/exception.h +17 -11
  37. data/include/rays/font.h +4 -3
  38. data/include/rays/image.h +11 -6
  39. data/include/rays/matrix.h +15 -12
  40. data/include/rays/opengl.h +54 -1
  41. data/include/rays/painter.h +98 -108
  42. data/include/rays/point.h +45 -5
  43. data/include/rays/rays.h +2 -2
  44. data/include/rays/ruby/bitmap.h +2 -16
  45. data/include/rays/ruby/bounds.h +4 -16
  46. data/include/rays/ruby/color.h +3 -16
  47. data/include/rays/ruby/color_space.h +27 -0
  48. data/include/rays/ruby/font.h +2 -16
  49. data/include/rays/ruby/image.h +2 -16
  50. data/include/rays/ruby/matrix.h +2 -16
  51. data/include/rays/ruby/painter.h +2 -16
  52. data/include/rays/ruby/point.h +3 -16
  53. data/include/rays/ruby/shader.h +27 -0
  54. data/include/rays/ruby/texture.h +2 -16
  55. data/include/rays/ruby.h +1 -0
  56. data/include/rays/shader.h +48 -0
  57. data/include/rays/texture.h +13 -2
  58. data/include/rays.h +2 -1
  59. data/lib/rays/bitmap.rb +20 -11
  60. data/lib/rays/bounds.rb +29 -68
  61. data/lib/rays/color.rb +39 -0
  62. data/lib/rays/color_space.rb +33 -0
  63. data/lib/rays/font.rb +29 -0
  64. data/lib/rays/image.rb +22 -0
  65. data/lib/rays/module.rb +11 -7
  66. data/lib/rays/painter.rb +103 -40
  67. data/lib/rays/point.rb +19 -36
  68. data/lib/rays/shader.rb +13 -0
  69. data/lib/rays/texture.rb +9 -0
  70. data/lib/rays.rb +4 -0
  71. data/rays.gemspec +3 -4
  72. data/src/bounds.cpp +272 -63
  73. data/src/color.cpp +168 -21
  74. data/src/{colorspace.cpp → color_space.cpp} +38 -1
  75. data/src/exception.cpp +24 -15
  76. data/src/frame_buffer.cpp +275 -0
  77. data/src/frame_buffer.h +79 -0
  78. data/src/image.cpp +80 -36
  79. data/src/ios/bitmap.mm +340 -0
  80. data/src/ios/font.mm +206 -0
  81. data/src/{cocoa → ios}/helper.h +2 -2
  82. data/src/{cocoa → ios}/helper.mm +0 -0
  83. data/src/ios/opengl.mm +21 -0
  84. data/src/ios/program.cpp +122 -0
  85. data/src/{cocoa → ios}/rays.mm +8 -7
  86. data/src/matrix.cpp +10 -22
  87. data/src/opengl.cpp +64 -0
  88. data/src/{cocoa → osx}/bitmap.mm +121 -70
  89. data/src/{cocoa → osx}/font.mm +32 -24
  90. data/src/osx/helper.h +26 -0
  91. data/src/osx/helper.mm +25 -0
  92. data/src/osx/opengl.mm +103 -0
  93. data/src/osx/rays.mm +43 -0
  94. data/src/painter.cpp +596 -422
  95. data/src/point.cpp +154 -11
  96. data/src/program.cpp +513 -0
  97. data/src/program.h +73 -0
  98. data/src/render_buffer.cpp +120 -0
  99. data/src/render_buffer.h +47 -0
  100. data/src/shader.cpp +117 -0
  101. data/src/texture.cpp +104 -134
  102. data/test/helper.rb +10 -3
  103. data/test/test_bitmap.rb +18 -0
  104. data/test/test_bounds.rb +81 -35
  105. data/test/test_color.rb +29 -2
  106. data/test/test_image.rb +63 -0
  107. data/test/test_painter.rb +120 -0
  108. data/test/test_point.rb +30 -9
  109. data/test/test_shader.rb +37 -0
  110. data/test/test_texture.rb +18 -0
  111. metadata +75 -58
  112. data/.gitignore +0 -14
  113. data/ChangeLog +0 -8
data/ext/rays/bitmap.cpp CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
 
4
4
  #include <rucy.h>
5
+ #include "rays/exception.h"
6
+ #include "rays/ruby/color_space.h"
7
+ #include "rays/ruby/color.h"
5
8
  #include "rays/ruby/font.h"
9
+ #include "rays/ruby/texture.h"
6
10
  #include "defs.h"
7
11
 
8
12
 
@@ -10,76 +14,55 @@ using namespace Rucy;
10
14
 
11
15
  using Rays::uchar;
12
16
  using Rays::ushort;
13
- using Rays::ulong;
17
+ using Rays::uint;
14
18
  using Rays::coord;
15
19
 
16
20
 
17
21
  static Class cBitmap;
18
22
 
23
+ RUCY_DEFINE_VALUE_FROM_TO(Rays::Bitmap, cBitmap)
19
24
 
20
- namespace Rays
21
- {
22
-
23
-
24
- Class
25
- bitmap_class ()
26
- {
27
- return cBitmap;
28
- }
25
+ #define THIS to<Rays::Bitmap*>(self)
29
26
 
30
-
31
- }// Rays
27
+ #define CHECK RUCY_CHECK_OBJECT(Rays::Bitmap, cBitmap, self)
32
28
 
33
29
 
34
- namespace Rucy
30
+ static
31
+ RUCY_DEF_ALLOC(alloc, klass)
35
32
  {
36
-
37
-
38
- Value
39
- value (const Rays::Bitmap& obj)
40
- {
41
- return new_type(cBitmap, new Rays::Bitmap(obj));
42
- }
43
-
44
- Value
45
- value (const Rays::Bitmap* obj)
46
- {
47
- return obj ? value(*obj) : nil();
48
- }
49
-
50
-
51
- }// Rucy
52
-
53
-
54
- #define THIS to<Rays::Bitmap*>(self)
55
-
56
- #define CHECK RUCY_CHECK_OBJECT(self, Rays::Bitmap, cBitmap)
57
-
33
+ return new_type<Rays::Bitmap>(klass);
34
+ }
35
+ RUCY_END
58
36
 
59
37
  static
60
- RUBY_DEF_ALLOC(alloc, klass)
38
+ RUCY_DEF1(initialize_copy, obj)
61
39
  {
62
- return new_type<Rays::Bitmap>(klass);
40
+ RUCY_CHECK_OBJ(Rays::Bitmap, cBitmap, self);
41
+
42
+ *THIS = to<Rays::Bitmap&>(obj).copy();
43
+ return self;
63
44
  }
64
- RUBY_END
45
+ RUCY_END
65
46
 
66
47
  static
67
- RUBY_DEF3(setup, width, height, colorspace)
48
+ RUCY_DEF3(setup, width, height, color_space)
68
49
  {
69
- RUCY_CHECK_OBJ(self, Rays::Bitmap, cBitmap);
70
- *THIS = Rays::Bitmap(
71
- to<int>(width), to<int>(height),
72
- (Rays::ColorSpaceType) to<uint>(colorspace));
50
+ RUCY_CHECK_OBJ(Rays::Bitmap, cBitmap, self);
51
+
52
+ Rays::ColorSpace* cs = to<Rays::ColorSpace*>(color_space);
53
+ if (!cs)
54
+ argument_error(__FILE__, __LINE__);
55
+
56
+ *THIS = Rays::Bitmap(to<int>(width), to<int>(height), *cs);
73
57
  return self;
74
58
  }
75
- RUBY_END
59
+ RUCY_END
76
60
 
77
61
  static
78
- RUBY_DEFN(draw_string)
62
+ RUCY_DEFN(draw_string)
79
63
  {
80
64
  CHECK;
81
- if (argc < 1 || 4 < argc)
82
- arg_count_error("Bitmap#draw_string", argc, 1, 2, 3, 4);
65
+ check_arg_count(__FILE__, __LINE__, "Bitmap#draw_string", argc, 1, 2, 3, 4);
83
66
 
84
67
  const char* str = to<const char*>(argv[0]);
85
68
  coord x = argc >= 2 ? to<coord>(argv[1]) : 0;
@@ -87,245 +70,89 @@ RUBY_DEFN(draw_string)
87
70
  const Rays::Font* font = argc >= 4
88
71
  ? to<Rays::Font*>(argv[3]) : &Rays::default_font();
89
72
 
90
- if (!Rays::draw_string(THIS, str, x, y, *font))
91
- {
92
- rays_error(
93
- "Bitmap#draw_string('%s', %f, %f, %s) failed.",
94
- str, x, y, font->name().c_str());
95
- }
96
-
73
+ Rays::draw_string(THIS, str, x, y, *font);
97
74
  return self;
98
75
  }
99
- RUBY_END
76
+ RUCY_END
100
77
 
101
78
  static
102
- RUBY_DEF0(width)
79
+ RUCY_DEF0(width)
103
80
  {
104
81
  CHECK;
105
82
 
106
83
  return value(THIS->width());
107
84
  }
108
- RUBY_END
85
+ RUCY_END
109
86
 
110
87
  static
111
- RUBY_DEF0(height)
88
+ RUCY_DEF0(height)
112
89
  {
113
90
  CHECK;
114
91
 
115
92
  return value(THIS->height());
116
93
  }
117
- RUBY_END
94
+ RUCY_END
118
95
 
119
96
  static
120
- RUBY_DEF0(color_space)
97
+ RUCY_DEF0(color_space)
121
98
  {
122
99
  CHECK;
123
100
 
124
- return value(THIS->color_space().type());
101
+ return value(THIS->color_space());
125
102
  }
126
- RUBY_END
103
+ RUCY_END
127
104
 
128
105
  static
129
- RUBY_DEF2(at, x, y)
106
+ RUCY_DEF2(at, x, y)
130
107
  {
131
108
  CHECK;
132
109
 
133
- int xx = x.as_i(), yy = y.as_i();
134
- void* pixel = THIS->at<void*>(xx, yy);
135
- if (!pixel) rays_error("Bitmap#at(%d, %d) failed.", xx, yy);
136
-
137
- Value array(THIS->color_space().Bpp() / THIS->color_space().Bpc(), NULL);
138
- if (THIS->color_space().is_float())
139
- {
140
- float* p = (float*) pixel;
141
- switch (THIS->color_space().type())
142
- {
143
- case Rays::GRAY_float:
144
- array.push(p[0]);
145
- break;
146
- case Rays::RGB_float:
147
- array.push(p[0]).push(p[1]).push(p[2]);
148
- break;
149
- case Rays::RGBA_float:
150
- array.push(p[0]).push(p[1]).push(p[2]).push(p[3]);
151
- break;
152
- case Rays::ARGB_float:
153
- array.push(p[1]).push(p[2]).push(p[3]).push(p[0]);
154
- break;
155
- case Rays::BGR_float:
156
- array.push(p[2]).push(p[1]).push(p[0]);
157
- break;
158
- case Rays::BGRA_float:
159
- array.push(p[2]).push(p[1]).push(p[0]).push(p[3]);
160
- break;
161
- case Rays::ABGR_float:
162
- array.push(p[3]).push(p[2]).push(p[1]).push(p[0]);
163
- break;
164
- default:
165
- rays_error("Bitmap#at: unknown color space");
166
- }
167
- }
168
- else
169
- {
170
- uchar* p = (uchar*) pixel;
171
- switch (THIS->color_space().type())
172
- {
173
- case Rays::GRAY_8:
174
- array.push(*(uchar*) pixel);
175
- break;
176
- case Rays::GRAY_16:
177
- array.push(*(ushort*) pixel);
178
- break;
179
- case Rays::GRAY_32:
180
- array.push(*(ulong*) pixel);
181
- break;
182
- case Rays::RGB_888:
183
- array.push(p[0]).push(p[1]).push(p[2]);
184
- break;
185
- case Rays::RGBA_8888:
186
- array.push(p[0]).push(p[1]).push(p[2]).push(p[3]);
187
- break;
188
- case Rays::ARGB_8888:
189
- array.push(p[1]).push(p[2]).push(p[3]).push(p[0]);
190
- break;
191
- case Rays::RGBX_8888:
192
- array.push(p[0]).push(p[1]).push(p[2]);
193
- break;
194
- case Rays::XRGB_8888:
195
- array.push(p[1]).push(p[2]).push(p[3]);
196
- break;
197
- case Rays::BGR_888:
198
- array.push(p[2]).push(p[1]).push(p[0]);
199
- break;
200
- case Rays::BGRA_8888:
201
- array.push(p[2]).push(p[1]).push(p[0]).push(p[3]);
202
- break;
203
- case Rays::ABGR_8888:
204
- array.push(p[3]).push(p[2]).push(p[1]).push(p[0]);
205
- break;
206
- case Rays::BGRX_8888:
207
- array.push(p[2]).push(p[1]).push(p[0]);
208
- break;
209
- case Rays::XBGR_8888:
210
- array.push(p[3]).push(p[2]).push(p[1]);
211
- break;
212
- default:
213
- rays_error("Bitmap#at: unknown color space");
214
- }
215
- }
216
-
217
- return array;
110
+ return value(Rays::Color(THIS->at<void>(x.as_i(), y.as_i()), THIS->color_space()));
218
111
  }
219
- RUBY_END
112
+ RUCY_END
220
113
 
221
114
  static
222
- RUBY_DEF3(assign_at, x, y, color)
115
+ RUCY_DEF3(set_at, x, y, color)
223
116
  {
224
117
  CHECK;
225
118
 
226
- int xx = x.as_i(), yy = y.as_i();
227
- void* pixel = THIS->at<void*>(xx, yy);
228
- if (!pixel) rays_error("Bitmap#assign_at(%d, %d) failed.", xx, yy);
119
+ Rays::Color* col = to<Rays::Color*>(color);
120
+ if (!col)
121
+ argument_error(__FILE__, __LINE__);
229
122
 
230
- Value array(THIS->color_space().Bpp() / THIS->color_space().Bpc(), NULL);
231
- if (THIS->color_space().is_float())
232
- {
233
- float* p = (float*) pixel;
234
- switch (THIS->color_space().type())
235
- {
236
- #define C(n) ((float) color[n].as_f())
237
- case Rays::GRAY_float:
238
- p[0] = C(0);
239
- break;
240
- case Rays::RGB_float:
241
- p[0] = C(0); p[1] = C(1); p[2] = C(2);
242
- break;
243
- case Rays::RGBA_float:
244
- p[0] = C(0); p[1] = C(1); p[2] = C(2); p[3] = C(3);
245
- break;
246
- case Rays::ARGB_float:
247
- p[0] = C(1); p[1] = C(2); p[2] = C(3); p[3] = C(0);
248
- break;
249
- case Rays::BGR_float:
250
- p[0] = C(2); p[1] = C(1); p[2] = C(0);
251
- break;
252
- case Rays::BGRA_float:
253
- p[0] = C(2); p[1] = C(1); p[2] = C(0); p[3] = C(3);
254
- break;
255
- case Rays::ABGR_float:
256
- p[0] = C(3); p[1] = C(2); p[2] = C(1); p[3] = C(0);
257
- break;
258
- #undef C
259
- default:
260
- rays_error("Bitmap#at: unknown color space");
261
- }
262
- }
263
- else
264
- {
265
- uchar* p = (uchar*) pixel;
266
- switch (THIS->color_space().type())
267
- {
268
- #define C(n) ((uchar) color[n].as_i())
269
- case Rays::GRAY_8:
270
- *(uchar*) pixel = C(0);
271
- break;
272
- case Rays::GRAY_16:
273
- *(ushort*) pixel = C(0);
274
- break;
275
- case Rays::GRAY_32:
276
- *(ulong*) pixel = C(0);
277
- break;
278
- case Rays::RGB_888:
279
- p[0] = C(0); p[1] = C(1); p[2] = C(2);
280
- break;
281
- case Rays::RGBA_8888:
282
- p[0] = C(0); p[1] = C(1); p[2] = C(2); p[3] = C(3);
283
- break;
284
- case Rays::ARGB_8888:
285
- p[0] = C(1); p[1] = C(2); p[2] = C(3); p[3] = C(0);
286
- break;
287
- case Rays::RGBX_8888:
288
- p[0] = C(0); p[1] = C(1); p[2] = C(2);
289
- break;
290
- case Rays::XRGB_8888:
291
- p[0] = C(1); p[1] = C(2); p[2] = C(3);
292
- break;
293
- case Rays::BGR_888:
294
- p[0] = C(2); p[1] = C(1); p[2] = C(0);
295
- break;
296
- case Rays::BGRA_8888:
297
- p[0] = C(2); p[1] = C(1); p[2] = C(0); p[3] = C(3);
298
- break;
299
- case Rays::ABGR_8888:
300
- p[0] = C(3); p[1] = C(2); p[2] = C(1); p[3] = C(0);
301
- break;
302
- case Rays::BGRX_8888:
303
- p[0] = C(2); p[1] = C(1); p[2] = C(0);
304
- break;
305
- case Rays::XBGR_8888:
306
- p[0] = C(3); p[1] = C(2); p[2] = C(1);
307
- break;
308
- #undef C
309
- default:
310
- rays_error("Bitmap#at: unknown color space");
311
- }
312
- }
123
+ col->get(THIS->at<void>(x.as_i(), y.as_i()), THIS->color_space());
313
124
 
314
125
  return color;
315
126
  }
316
- RUBY_END
127
+ RUCY_END
317
128
 
129
+ static
130
+ RUCY_DEFN(to_texture)
131
+ {
132
+ CHECK;
133
+
134
+ bool alpha_only = (argc >= 1) ? to<bool>(argv[0]) : false;
135
+ return value(Rays::Texture(*THIS, alpha_only));
136
+ }
137
+ RUCY_END
318
138
 
319
139
  static
320
- RUBY_DEF1(load, path)
140
+ RUCY_DEF1(save, path)
321
141
  {
322
- Rays::Bitmap bmp;
323
- if (!Rays::load_bitmap(&bmp, path.c_str()))
324
- rays_error("Bitmap.load('%s') failed.", path.c_str());
142
+ CHECK;
143
+
144
+ Rays::save_bitmap(*THIS, path.c_str());
145
+ return self;
146
+ }
147
+ RUCY_END
325
148
 
326
- return value(bmp);
149
+
150
+ static
151
+ RUCY_DEF1(load, path)
152
+ {
153
+ return value(Rays::load_bitmap(path.c_str()));
327
154
  }
328
- RUBY_END
155
+ RUCY_END
329
156
 
330
157
 
331
158
  void
@@ -333,18 +160,31 @@ Init_bitmap ()
333
160
  {
334
161
  Module mRays = define_module("Rays");
335
162
 
336
- mRays.define_const("GRAY", Rays::GRAY);
337
- mRays.define_const("RGB", Rays::RGB);
338
- mRays.define_const("RGBA", Rays::RGBA);
339
-
340
163
  cBitmap = mRays.define_class("Bitmap");
341
164
  cBitmap.define_alloc_func(alloc);
165
+ cBitmap.define_private_method("initialize_copy", initialize_copy);
342
166
  cBitmap.define_private_method("setup", setup);
343
167
  cBitmap.define_method("draw_string", draw_string);
344
168
  cBitmap.define_method("width", width);
345
169
  cBitmap.define_method("height", height);
346
170
  cBitmap.define_method("color_space", color_space);
347
171
  cBitmap.define_method("[]", at);
348
- cBitmap.define_method("[]=", assign_at);
172
+ cBitmap.define_method("set_at", set_at);
173
+ cBitmap.define_method("to_texture", to_texture);
174
+ cBitmap.define_method("save", save);
349
175
  cBitmap.define_function("load", load);
350
176
  }
177
+
178
+
179
+ namespace Rays
180
+ {
181
+
182
+
183
+ Class
184
+ bitmap_class ()
185
+ {
186
+ return cBitmap;
187
+ }
188
+
189
+
190
+ }// Rays