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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4a408fdf8bf60cb32907e9be2fe9048f0c5de133
4
+ data.tar.gz: 8e0ab09661a2083e27f9770d7ad8d23c2482fe0f
5
+ SHA512:
6
+ metadata.gz: d9d66ab38417be7291948a5003b71836f74cc6d19e9c1163b0156032784d4677bc666afde3551644992180523af55bf501e0bba2435c2080ba90891d3cc7badd
7
+ data.tar.gz: 3f52a64943eb855b4cfbb5cd0ebeb7a337fde08d771eca0f42e3272ea6668af9cd16d5a675df426381b70da25493c79c049cc0fde56a3723c96a3e6aa8febae5
@@ -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,50 +14,17 @@ 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
32
-
33
-
34
- namespace Rucy
35
- {
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)
27
+ #define CHECK RUCY_CHECK_OBJECT(Rays::Bitmap, cBitmap, self)
57
28
 
58
29
 
59
30
  static
@@ -63,12 +34,24 @@ VALUE alloc(VALUE klass)
63
34
  }
64
35
 
65
36
  static
66
- VALUE setup(VALUE self, VALUE width, VALUE height, VALUE colorspace)
37
+ VALUE initialize_copy(VALUE self, VALUE obj)
38
+ {
39
+ RUCY_CHECK_OBJ(Rays::Bitmap, cBitmap, self);
40
+
41
+ *THIS = to<Rays::Bitmap&>(obj).copy();
42
+ return self;
43
+ }
44
+
45
+ static
46
+ VALUE setup(VALUE self, VALUE width, VALUE height, VALUE color_space)
67
47
  {
68
- RUCY_CHECK_OBJ(self, Rays::Bitmap, cBitmap);
69
- *THIS = Rays::Bitmap(
70
- to<int>(width), to<int>(height),
71
- (Rays::ColorSpaceType) to<uint>(colorspace));
48
+ RUCY_CHECK_OBJ(Rays::Bitmap, cBitmap, self);
49
+
50
+ Rays::ColorSpace* cs = to<Rays::ColorSpace*>(color_space);
51
+ if (!cs)
52
+ argument_error(__FILE__, __LINE__);
53
+
54
+ *THIS = Rays::Bitmap(to<int>(width), to<int>(height), *cs);
72
55
  return self;
73
56
  }
74
57
 
@@ -76,8 +59,7 @@ static
76
59
  VALUE draw_string(VALUE self)
77
60
  {
78
61
  CHECK;
79
- if (argc < 1 || 4 < argc)
80
- arg_count_error("Bitmap#draw_string", argc, 1, 2, 3, 4);
62
+ check_arg_count(__FILE__, __LINE__, "Bitmap#draw_string", argc, 1, 2, 3, 4);
81
63
 
82
64
  const char* str = to<const char*>(argv[0]);
83
65
  coord x = argc >= 2 ? to<coord>(argv[1]) : 0;
@@ -85,13 +67,7 @@ VALUE draw_string(VALUE self)
85
67
  const Rays::Font* font = argc >= 4
86
68
  ? to<Rays::Font*>(argv[3]) : &Rays::default_font();
87
69
 
88
- if (!Rays::draw_string(THIS, str, x, y, *font))
89
- {
90
- rays_error(
91
- "Bitmap#draw_string('%s', %f, %f, %s) failed.",
92
- str, x, y, font->name().c_str());
93
- }
94
-
70
+ Rays::draw_string(THIS, str, x, y, *font);
95
71
  return self;
96
72
  }
97
73
 
@@ -116,7 +92,7 @@ VALUE color_space(VALUE self)
116
92
  {
117
93
  CHECK;
118
94
 
119
- return value(THIS->color_space().type());
95
+ return value(THIS->color_space());
120
96
  }
121
97
 
122
98
  static
@@ -124,198 +100,46 @@ VALUE at(VALUE self, VALUE x, VALUE y)
124
100
  {
125
101
  CHECK;
126
102
 
127
- int xx = x.as_i(), yy = y.as_i();
128
- void* pixel = THIS->at<void*>(xx, yy);
129
- if (!pixel) rays_error("Bitmap#at(%d, %d) failed.", xx, yy);
103
+ return value(Rays::Color(THIS->at<void>(x.as_i(), y.as_i()), THIS->color_space()));
104
+ }
130
105
 
131
- Value array(THIS->color_space().Bpp() / THIS->color_space().Bpc(), NULL);
132
- if (THIS->color_space().is_float())
133
- {
134
- float* p = (float*) pixel;
135
- switch (THIS->color_space().type())
136
- {
137
- case Rays::GRAY_float:
138
- array.push(p[0]);
139
- break;
140
- case Rays::RGB_float:
141
- array.push(p[0]).push(p[1]).push(p[2]);
142
- break;
143
- case Rays::RGBA_float:
144
- array.push(p[0]).push(p[1]).push(p[2]).push(p[3]);
145
- break;
146
- case Rays::ARGB_float:
147
- array.push(p[1]).push(p[2]).push(p[3]).push(p[0]);
148
- break;
149
- case Rays::BGR_float:
150
- array.push(p[2]).push(p[1]).push(p[0]);
151
- break;
152
- case Rays::BGRA_float:
153
- array.push(p[2]).push(p[1]).push(p[0]).push(p[3]);
154
- break;
155
- case Rays::ABGR_float:
156
- array.push(p[3]).push(p[2]).push(p[1]).push(p[0]);
157
- break;
158
- default:
159
- rays_error("Bitmap#at: unknown color space");
160
- }
161
- }
162
- else
163
- {
164
- uchar* p = (uchar*) pixel;
165
- switch (THIS->color_space().type())
166
- {
167
- case Rays::GRAY_8:
168
- array.push(*(uchar*) pixel);
169
- break;
170
- case Rays::GRAY_16:
171
- array.push(*(ushort*) pixel);
172
- break;
173
- case Rays::GRAY_32:
174
- array.push(*(ulong*) pixel);
175
- break;
176
- case Rays::RGB_888:
177
- array.push(p[0]).push(p[1]).push(p[2]);
178
- break;
179
- case Rays::RGBA_8888:
180
- array.push(p[0]).push(p[1]).push(p[2]).push(p[3]);
181
- break;
182
- case Rays::ARGB_8888:
183
- array.push(p[1]).push(p[2]).push(p[3]).push(p[0]);
184
- break;
185
- case Rays::RGBX_8888:
186
- array.push(p[0]).push(p[1]).push(p[2]);
187
- break;
188
- case Rays::XRGB_8888:
189
- array.push(p[1]).push(p[2]).push(p[3]);
190
- break;
191
- case Rays::BGR_888:
192
- array.push(p[2]).push(p[1]).push(p[0]);
193
- break;
194
- case Rays::BGRA_8888:
195
- array.push(p[2]).push(p[1]).push(p[0]).push(p[3]);
196
- break;
197
- case Rays::ABGR_8888:
198
- array.push(p[3]).push(p[2]).push(p[1]).push(p[0]);
199
- break;
200
- case Rays::BGRX_8888:
201
- array.push(p[2]).push(p[1]).push(p[0]);
202
- break;
203
- case Rays::XBGR_8888:
204
- array.push(p[3]).push(p[2]).push(p[1]);
205
- break;
206
- default:
207
- rays_error("Bitmap#at: unknown color space");
208
- }
209
- }
106
+ static
107
+ VALUE set_at(VALUE self, VALUE x, VALUE y, VALUE color)
108
+ {
109
+ CHECK;
110
+
111
+ Rays::Color* col = to<Rays::Color*>(color);
112
+ if (!col)
113
+ argument_error(__FILE__, __LINE__);
114
+
115
+ col->get(THIS->at<void>(x.as_i(), y.as_i()), THIS->color_space());
210
116
 
211
- return array;
117
+ return color;
212
118
  }
213
119
 
214
120
  static
215
- VALUE assign_at(VALUE self, VALUE x, VALUE y, VALUE color)
121
+ VALUE to_texture(VALUE self)
216
122
  {
217
123
  CHECK;
218
124
 
219
- int xx = x.as_i(), yy = y.as_i();
220
- void* pixel = THIS->at<void*>(xx, yy);
221
- if (!pixel) rays_error("Bitmap#assign_at(%d, %d) failed.", xx, yy);
125
+ bool alpha_only = (argc >= 1) ? to<bool>(argv[0]) : false;
126
+ return value(Rays::Texture(*THIS, alpha_only));
127
+ }
222
128
 
223
- Value array(THIS->color_space().Bpp() / THIS->color_space().Bpc(), NULL);
224
- if (THIS->color_space().is_float())
225
- {
226
- float* p = (float*) pixel;
227
- switch (THIS->color_space().type())
228
- {
229
- #define C(n) ((float) color[n].as_f())
230
- case Rays::GRAY_float:
231
- p[0] = C(0);
232
- break;
233
- case Rays::RGB_float:
234
- p[0] = C(0); p[1] = C(1); p[2] = C(2);
235
- break;
236
- case Rays::RGBA_float:
237
- p[0] = C(0); p[1] = C(1); p[2] = C(2); p[3] = C(3);
238
- break;
239
- case Rays::ARGB_float:
240
- p[0] = C(1); p[1] = C(2); p[2] = C(3); p[3] = C(0);
241
- break;
242
- case Rays::BGR_float:
243
- p[0] = C(2); p[1] = C(1); p[2] = C(0);
244
- break;
245
- case Rays::BGRA_float:
246
- p[0] = C(2); p[1] = C(1); p[2] = C(0); p[3] = C(3);
247
- break;
248
- case Rays::ABGR_float:
249
- p[0] = C(3); p[1] = C(2); p[2] = C(1); p[3] = C(0);
250
- break;
251
- #undef C
252
- default:
253
- rays_error("Bitmap#at: unknown color space");
254
- }
255
- }
256
- else
257
- {
258
- uchar* p = (uchar*) pixel;
259
- switch (THIS->color_space().type())
260
- {
261
- #define C(n) ((uchar) color[n].as_i())
262
- case Rays::GRAY_8:
263
- *(uchar*) pixel = C(0);
264
- break;
265
- case Rays::GRAY_16:
266
- *(ushort*) pixel = C(0);
267
- break;
268
- case Rays::GRAY_32:
269
- *(ulong*) pixel = C(0);
270
- break;
271
- case Rays::RGB_888:
272
- p[0] = C(0); p[1] = C(1); p[2] = C(2);
273
- break;
274
- case Rays::RGBA_8888:
275
- p[0] = C(0); p[1] = C(1); p[2] = C(2); p[3] = C(3);
276
- break;
277
- case Rays::ARGB_8888:
278
- p[0] = C(1); p[1] = C(2); p[2] = C(3); p[3] = C(0);
279
- break;
280
- case Rays::RGBX_8888:
281
- p[0] = C(0); p[1] = C(1); p[2] = C(2);
282
- break;
283
- case Rays::XRGB_8888:
284
- p[0] = C(1); p[1] = C(2); p[2] = C(3);
285
- break;
286
- case Rays::BGR_888:
287
- p[0] = C(2); p[1] = C(1); p[2] = C(0);
288
- break;
289
- case Rays::BGRA_8888:
290
- p[0] = C(2); p[1] = C(1); p[2] = C(0); p[3] = C(3);
291
- break;
292
- case Rays::ABGR_8888:
293
- p[0] = C(3); p[1] = C(2); p[2] = C(1); p[3] = C(0);
294
- break;
295
- case Rays::BGRX_8888:
296
- p[0] = C(2); p[1] = C(1); p[2] = C(0);
297
- break;
298
- case Rays::XBGR_8888:
299
- p[0] = C(3); p[1] = C(2); p[2] = C(1);
300
- break;
301
- #undef C
302
- default:
303
- rays_error("Bitmap#at: unknown color space");
304
- }
305
- }
129
+ static
130
+ VALUE save(VALUE self, VALUE path)
131
+ {
132
+ CHECK;
306
133
 
307
- return color;
134
+ Rays::save_bitmap(*THIS, path.c_str());
135
+ return self;
308
136
  }
309
137
 
310
138
 
311
139
  static
312
140
  VALUE load(VALUE self, VALUE path)
313
141
  {
314
- Rays::Bitmap bmp;
315
- if (!Rays::load_bitmap(&bmp, path.c_str()))
316
- rays_error("Bitmap.load('%s') failed.", path.c_str());
317
-
318
- return value(bmp);
142
+ return value(Rays::load_bitmap(path.c_str()));
319
143
  }
320
144
 
321
145
 
@@ -324,18 +148,31 @@ Init_bitmap ()
324
148
  {
325
149
  Module mRays = rb_define_module("Rays");
326
150
 
327
- mRays.define_const("GRAY", Rays::GRAY);
328
- mRays.define_const("RGB", Rays::RGB);
329
- mRays.define_const("RGBA", Rays::RGBA);
330
-
331
151
  cBitmap = rb_define_class_under(mRays, "Bitmap", rb_cObject);
332
152
  rb_define_alloc_func(cBitmap, alloc);
153
+ rb_define_private_method(cBitmap, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
333
154
  rb_define_private_method(cBitmap, "setup", RUBY_METHOD_FUNC(setup), 3);
334
155
  rb_define_method(cBitmap, "draw_string", RUBY_METHOD_FUNC(draw_string), -1);
335
156
  rb_define_method(cBitmap, "width", RUBY_METHOD_FUNC(width), 0);
336
157
  rb_define_method(cBitmap, "height", RUBY_METHOD_FUNC(height), 0);
337
158
  rb_define_method(cBitmap, "color_space", RUBY_METHOD_FUNC(color_space), 0);
338
159
  cBitmap.define_method("[]", at);
339
- cBitmap.define_method("[]=", assign_at);
160
+ rb_define_method(cBitmap, "set_at", RUBY_METHOD_FUNC(set_at), 3);
161
+ rb_define_method(cBitmap, "to_texture", RUBY_METHOD_FUNC(to_texture), -1);
162
+ rb_define_method(cBitmap, "save", RUBY_METHOD_FUNC(save), 1);
340
163
  rb_define_function(cBitmap, "load", RUBY_METHOD_FUNC(load), 1);
341
164
  }
165
+
166
+
167
+ namespace Rays
168
+ {
169
+
170
+
171
+ Class
172
+ bitmap_class ()
173
+ {
174
+ return cBitmap;
175
+ }
176
+
177
+
178
+ }// Rays