rays 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.doc/ext/rays/bitmap.cpp +70 -233
- data/.doc/ext/rays/bounds.cpp +339 -57
- data/.doc/ext/rays/color.cpp +58 -48
- data/.doc/ext/rays/color_space.cpp +174 -0
- data/.doc/ext/rays/font.cpp +31 -53
- data/.doc/ext/rays/image.cpp +64 -67
- data/.doc/ext/rays/matrix.cpp +22 -50
- data/.doc/ext/rays/native.cpp +9 -2
- data/.doc/ext/rays/painter.cpp +276 -259
- data/.doc/ext/rays/point.cpp +186 -52
- data/.doc/ext/rays/rays.cpp +25 -20
- data/.doc/ext/rays/shader.cpp +61 -0
- data/.doc/ext/rays/texture.cpp +47 -59
- data/{README → README.md} +0 -0
- data/Rakefile +6 -5
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +88 -248
- data/ext/rays/bounds.cpp +437 -141
- data/ext/rays/color.cpp +79 -69
- data/ext/rays/color_space.cpp +185 -0
- data/ext/rays/extconf.rb +14 -63
- data/ext/rays/font.cpp +44 -65
- data/ext/rays/image.cpp +82 -81
- data/ext/rays/matrix.cpp +32 -60
- data/ext/rays/native.cpp +9 -2
- data/ext/rays/painter.cpp +345 -321
- data/ext/rays/point.cpp +212 -69
- data/ext/rays/rays.cpp +29 -23
- data/ext/rays/shader.cpp +63 -0
- data/ext/rays/texture.cpp +64 -74
- data/include/rays/bitmap.h +21 -12
- data/include/rays/bounds.h +67 -9
- data/include/rays/color.h +23 -7
- data/include/rays/{colorspace.h → color_space.h} +6 -3
- data/include/rays/exception.h +17 -11
- data/include/rays/font.h +4 -3
- data/include/rays/image.h +11 -6
- data/include/rays/matrix.h +15 -12
- data/include/rays/opengl.h +54 -1
- data/include/rays/painter.h +98 -108
- data/include/rays/point.h +45 -5
- data/include/rays/rays.h +2 -2
- data/include/rays/ruby/bitmap.h +2 -16
- data/include/rays/ruby/bounds.h +4 -16
- data/include/rays/ruby/color.h +3 -16
- data/include/rays/ruby/color_space.h +27 -0
- data/include/rays/ruby/font.h +2 -16
- data/include/rays/ruby/image.h +2 -16
- data/include/rays/ruby/matrix.h +2 -16
- data/include/rays/ruby/painter.h +2 -16
- data/include/rays/ruby/point.h +3 -16
- data/include/rays/ruby/shader.h +27 -0
- data/include/rays/ruby/texture.h +2 -16
- data/include/rays/ruby.h +1 -0
- data/include/rays/shader.h +48 -0
- data/include/rays/texture.h +13 -2
- data/include/rays.h +2 -1
- data/lib/rays/bitmap.rb +20 -11
- data/lib/rays/bounds.rb +29 -68
- data/lib/rays/color.rb +39 -0
- data/lib/rays/color_space.rb +33 -0
- data/lib/rays/font.rb +29 -0
- data/lib/rays/image.rb +22 -0
- data/lib/rays/module.rb +11 -7
- data/lib/rays/painter.rb +103 -40
- data/lib/rays/point.rb +19 -36
- data/lib/rays/shader.rb +13 -0
- data/lib/rays/texture.rb +9 -0
- data/lib/rays.rb +4 -0
- data/rays.gemspec +3 -4
- data/src/bounds.cpp +272 -63
- data/src/color.cpp +168 -21
- data/src/{colorspace.cpp → color_space.cpp} +38 -1
- data/src/exception.cpp +24 -15
- data/src/frame_buffer.cpp +275 -0
- data/src/frame_buffer.h +79 -0
- data/src/image.cpp +80 -36
- data/src/ios/bitmap.mm +340 -0
- data/src/ios/font.mm +206 -0
- data/src/{cocoa → ios}/helper.h +2 -2
- data/src/{cocoa → ios}/helper.mm +0 -0
- data/src/ios/opengl.mm +21 -0
- data/src/ios/program.cpp +122 -0
- data/src/{cocoa → ios}/rays.mm +8 -7
- data/src/matrix.cpp +10 -22
- data/src/opengl.cpp +64 -0
- data/src/{cocoa → osx}/bitmap.mm +121 -70
- data/src/{cocoa → osx}/font.mm +32 -24
- data/src/osx/helper.h +26 -0
- data/src/osx/helper.mm +25 -0
- data/src/osx/opengl.mm +103 -0
- data/src/osx/rays.mm +43 -0
- data/src/painter.cpp +596 -422
- data/src/point.cpp +154 -11
- data/src/program.cpp +513 -0
- data/src/program.h +73 -0
- data/src/render_buffer.cpp +120 -0
- data/src/render_buffer.h +47 -0
- data/src/shader.cpp +117 -0
- data/src/texture.cpp +104 -134
- data/test/helper.rb +10 -3
- data/test/test_bitmap.rb +18 -0
- data/test/test_bounds.rb +81 -35
- data/test/test_color.rb +29 -2
- data/test/test_image.rb +63 -0
- data/test/test_painter.rb +120 -0
- data/test/test_point.rb +30 -9
- data/test/test_shader.rb +37 -0
- data/test/test_texture.rb +18 -0
- metadata +75 -58
- data/.gitignore +0 -14
- 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::
|
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
|
-
|
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
|
-
|
30
|
+
static
|
31
|
+
RUCY_DEF_ALLOC(alloc, klass)
|
35
32
|
{
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
38
|
+
RUCY_DEF1(initialize_copy, obj)
|
61
39
|
{
|
62
|
-
|
40
|
+
RUCY_CHECK_OBJ(Rays::Bitmap, cBitmap, self);
|
41
|
+
|
42
|
+
*THIS = to<Rays::Bitmap&>(obj).copy();
|
43
|
+
return self;
|
63
44
|
}
|
64
|
-
|
45
|
+
RUCY_END
|
65
46
|
|
66
47
|
static
|
67
|
-
|
48
|
+
RUCY_DEF3(setup, width, height, color_space)
|
68
49
|
{
|
69
|
-
RUCY_CHECK_OBJ(
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
59
|
+
RUCY_END
|
76
60
|
|
77
61
|
static
|
78
|
-
|
62
|
+
RUCY_DEFN(draw_string)
|
79
63
|
{
|
80
64
|
CHECK;
|
81
|
-
|
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
|
-
|
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
|
-
|
76
|
+
RUCY_END
|
100
77
|
|
101
78
|
static
|
102
|
-
|
79
|
+
RUCY_DEF0(width)
|
103
80
|
{
|
104
81
|
CHECK;
|
105
82
|
|
106
83
|
return value(THIS->width());
|
107
84
|
}
|
108
|
-
|
85
|
+
RUCY_END
|
109
86
|
|
110
87
|
static
|
111
|
-
|
88
|
+
RUCY_DEF0(height)
|
112
89
|
{
|
113
90
|
CHECK;
|
114
91
|
|
115
92
|
return value(THIS->height());
|
116
93
|
}
|
117
|
-
|
94
|
+
RUCY_END
|
118
95
|
|
119
96
|
static
|
120
|
-
|
97
|
+
RUCY_DEF0(color_space)
|
121
98
|
{
|
122
99
|
CHECK;
|
123
100
|
|
124
|
-
return value(THIS->color_space()
|
101
|
+
return value(THIS->color_space());
|
125
102
|
}
|
126
|
-
|
103
|
+
RUCY_END
|
127
104
|
|
128
105
|
static
|
129
|
-
|
106
|
+
RUCY_DEF2(at, x, y)
|
130
107
|
{
|
131
108
|
CHECK;
|
132
109
|
|
133
|
-
|
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
|
-
|
112
|
+
RUCY_END
|
220
113
|
|
221
114
|
static
|
222
|
-
|
115
|
+
RUCY_DEF3(set_at, x, y, color)
|
223
116
|
{
|
224
117
|
CHECK;
|
225
118
|
|
226
|
-
|
227
|
-
|
228
|
-
|
119
|
+
Rays::Color* col = to<Rays::Color*>(color);
|
120
|
+
if (!col)
|
121
|
+
argument_error(__FILE__, __LINE__);
|
229
122
|
|
230
|
-
|
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
|
-
|
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
|
-
|
140
|
+
RUCY_DEF1(save, path)
|
321
141
|
{
|
322
|
-
|
323
|
-
|
324
|
-
|
142
|
+
CHECK;
|
143
|
+
|
144
|
+
Rays::save_bitmap(*THIS, path.c_str());
|
145
|
+
return self;
|
146
|
+
}
|
147
|
+
RUCY_END
|
325
148
|
|
326
|
-
|
149
|
+
|
150
|
+
static
|
151
|
+
RUCY_DEF1(load, path)
|
152
|
+
{
|
153
|
+
return value(Rays::load_bitmap(path.c_str()));
|
327
154
|
}
|
328
|
-
|
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("
|
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
|