rays 0.1.11 → 0.1.16
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 +5 -5
- data/.doc/ext/rays/bitmap.cpp +22 -76
- data/.doc/ext/rays/bounds.cpp +95 -125
- data/.doc/ext/rays/camera.cpp +88 -0
- data/.doc/ext/rays/color.cpp +223 -45
- data/.doc/ext/rays/color_space.cpp +146 -46
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +69 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +14 -8
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +187 -292
- data/.doc/ext/rays/point.cpp +96 -77
- data/.doc/ext/rays/polygon.cpp +313 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +167 -0
- data/.doc/ext/rays/rays.cpp +103 -12
- data/.doc/ext/rays/shader.cpp +83 -9
- data/LICENSE +21 -0
- data/README.md +1 -1
- data/Rakefile +24 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +22 -80
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/camera.cpp +94 -0
- data/ext/rays/color.cpp +231 -51
- data/ext/rays/color_space.cpp +149 -47
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +2 -3
- data/ext/rays/font.cpp +74 -24
- data/ext/rays/image.cpp +28 -40
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +14 -8
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +203 -298
- data/ext/rays/point.cpp +105 -81
- data/ext/rays/polygon.cpp +329 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +176 -0
- data/ext/rays/rays.cpp +103 -13
- data/ext/rays/shader.cpp +84 -9
- data/include/rays.h +10 -2
- data/include/rays/bitmap.h +14 -26
- data/include/rays/bounds.h +21 -4
- data/include/rays/camera.h +49 -0
- data/include/rays/color.h +25 -14
- data/include/rays/color_space.h +15 -10
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +36 -0
- data/include/rays/exception.h +6 -2
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +12 -18
- data/include/rays/matrix.h +50 -24
- data/include/rays/noise.h +42 -0
- data/include/rays/opengl.h +2 -50
- data/include/rays/painter.h +89 -93
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +198 -0
- data/include/rays/polyline.h +71 -0
- data/include/rays/rays.h +3 -0
- data/include/rays/ruby.h +7 -1
- data/include/rays/ruby/bounds.h +1 -1
- data/include/rays/ruby/camera.h +41 -0
- data/include/rays/ruby/color.h +1 -1
- data/include/rays/ruby/color_space.h +1 -1
- data/include/rays/ruby/font.h +1 -1
- data/include/rays/ruby/matrix.h +1 -1
- data/include/rays/ruby/point.h +1 -1
- data/include/rays/ruby/polygon.h +52 -0
- data/include/rays/ruby/polyline.h +41 -0
- data/include/rays/ruby/rays.h +8 -0
- data/include/rays/ruby/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +7 -2
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/camera.rb +21 -0
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +3 -7
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +78 -93
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +58 -0
- data/lib/rays/polygon_line.rb +36 -0
- data/lib/rays/polyline.rb +32 -0
- data/lib/rays/shader.rb +20 -1
- data/rays.gemspec +5 -7
- data/src/bitmap.h +36 -0
- data/src/bounds.cpp +74 -11
- data/src/color.cpp +58 -23
- data/src/color_space.cpp +52 -34
- data/src/color_space.h +22 -0
- data/src/coord.cpp +170 -0
- data/src/coord.h +35 -0
- data/src/font.cpp +118 -0
- data/src/font.h +64 -0
- data/src/frame_buffer.cpp +37 -71
- data/src/frame_buffer.h +4 -4
- data/src/image.cpp +172 -98
- data/src/image.h +25 -0
- data/src/ios/bitmap.h +21 -0
- data/src/ios/bitmap.mm +129 -110
- data/src/ios/camera.mm +236 -0
- data/src/ios/font.mm +50 -62
- data/src/ios/helper.h +2 -2
- data/src/ios/opengl.mm +19 -4
- data/src/ios/rays.mm +3 -0
- data/src/matrix.cpp +111 -26
- data/src/matrix.h +30 -0
- data/src/noise.cpp +74 -0
- data/src/opengl.cpp +9 -27
- data/src/opengl.h +37 -0
- data/src/osx/bitmap.h +21 -0
- data/src/osx/bitmap.mm +129 -110
- data/src/osx/camera.mm +236 -0
- data/src/osx/font.mm +49 -62
- data/src/osx/helper.h +2 -2
- data/src/osx/opengl.mm +19 -83
- data/src/osx/rays.mm +3 -0
- data/src/painter.cpp +845 -671
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1266 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +160 -0
- data/src/polyline.h +69 -0
- data/src/render_buffer.cpp +11 -4
- data/src/render_buffer.h +2 -2
- data/src/shader.cpp +163 -106
- data/src/shader.h +38 -0
- data/src/shader_program.cpp +533 -0
- data/src/{program.h → shader_program.h} +28 -16
- data/src/shader_source.cpp +140 -0
- data/src/shader_source.h +52 -0
- data/src/texture.cpp +136 -160
- data/src/texture.h +65 -0
- data/src/win32/bitmap.cpp +62 -52
- data/src/win32/font.cpp +11 -13
- data/src/win32/font.h +24 -0
- data/src/win32/gdi.h +6 -6
- data/test/helper.rb +0 -3
- data/test/test_bitmap.rb +31 -7
- data/test/test_bounds.rb +36 -0
- data/test/test_color.rb +59 -19
- data/test/test_color_space.rb +95 -0
- data/test/test_font.rb +5 -0
- data/test/test_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +157 -51
- data/test/test_painter_shape.rb +102 -0
- data/test/test_point.rb +29 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +171 -0
- data/test/test_shader.rb +9 -9
- metadata +102 -70
- data/.doc/ext/rays/texture.cpp +0 -138
- data/ext/rays/texture.cpp +0 -149
- data/include/rays/ruby/texture.h +0 -41
- data/include/rays/texture.h +0 -71
- data/lib/rays/texture.rb +0 -24
- data/src/program.cpp +0 -648
- data/test/test_texture.rb +0 -27
@@ -0,0 +1,88 @@
|
|
1
|
+
#include "rays/ruby/camera.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include "rays/ruby/image.h"
|
5
|
+
#include "defs.h"
|
6
|
+
|
7
|
+
|
8
|
+
RUCY_DEFINE_VALUE_FROM_TO(Rays::Camera)
|
9
|
+
|
10
|
+
#define THIS to<Rays::Camera*>(self)
|
11
|
+
|
12
|
+
#define CHECK RUCY_CHECK_OBJECT(Rays::Camera, self)
|
13
|
+
|
14
|
+
|
15
|
+
static
|
16
|
+
VALUE alloc(VALUE klass)
|
17
|
+
{
|
18
|
+
return new_type<Rays::Camera>(klass);
|
19
|
+
}
|
20
|
+
|
21
|
+
static
|
22
|
+
VALUE initialize(VALUE self)
|
23
|
+
{
|
24
|
+
RUCY_CHECK_OBJ(Rays::Camera, self);
|
25
|
+
|
26
|
+
*THIS = Rays::Camera();
|
27
|
+
return self;
|
28
|
+
}
|
29
|
+
|
30
|
+
static
|
31
|
+
VALUE start(VALUE self)
|
32
|
+
{
|
33
|
+
CHECK;
|
34
|
+
return value(THIS->start());
|
35
|
+
}
|
36
|
+
|
37
|
+
static
|
38
|
+
VALUE stop(VALUE self)
|
39
|
+
{
|
40
|
+
CHECK;
|
41
|
+
THIS->stop();
|
42
|
+
}
|
43
|
+
|
44
|
+
static
|
45
|
+
VALUE is_active(VALUE self)
|
46
|
+
{
|
47
|
+
CHECK;
|
48
|
+
return value(THIS->is_active());
|
49
|
+
}
|
50
|
+
|
51
|
+
static
|
52
|
+
VALUE image(VALUE self)
|
53
|
+
{
|
54
|
+
CHECK;
|
55
|
+
const Rays::Image* img = THIS->image();
|
56
|
+
return img ? value(*img) : nil();
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
static Class cCamera;
|
61
|
+
|
62
|
+
void
|
63
|
+
Init_camera ()
|
64
|
+
{
|
65
|
+
Module mRays = rb_define_module("Rays");
|
66
|
+
|
67
|
+
cCamera = rb_define_class_under(mRays, "Camera", rb_cObject);
|
68
|
+
rb_define_alloc_func(cCamera, alloc);
|
69
|
+
rb_define_private_method(cCamera, "initialize", RUBY_METHOD_FUNC(initialize), -1);
|
70
|
+
rb_define_method(cCamera, "start", RUBY_METHOD_FUNC(start), 0);
|
71
|
+
rb_define_method(cCamera, "stop", RUBY_METHOD_FUNC(stop), 0);
|
72
|
+
cCamera.define_method("active?", is_active);
|
73
|
+
rb_define_method(cCamera, "image", RUBY_METHOD_FUNC(image), 0);
|
74
|
+
}
|
75
|
+
|
76
|
+
|
77
|
+
namespace Rays
|
78
|
+
{
|
79
|
+
|
80
|
+
|
81
|
+
Class
|
82
|
+
camera_class ()
|
83
|
+
{
|
84
|
+
return cCamera;
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
}// Rays
|
data/.doc/ext/rays/color.cpp
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
#include "rays/ruby/color.h"
|
2
2
|
|
3
3
|
|
4
|
-
#include <
|
4
|
+
#include <map>
|
5
5
|
#include "defs.h"
|
6
6
|
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
RUCY_DEFINE_VALUE_FROM_TO(Rays::Color)
|
8
|
+
RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Color)
|
12
9
|
|
13
10
|
#define THIS to<Rays::Color*>(self)
|
14
11
|
|
@@ -22,34 +19,13 @@ VALUE alloc(VALUE klass)
|
|
22
19
|
}
|
23
20
|
|
24
21
|
static
|
25
|
-
VALUE
|
22
|
+
VALUE initialize(VALUE self)
|
26
23
|
{
|
27
24
|
CHECK;
|
28
25
|
check_arg_count(__FILE__, __LINE__, "Color#initialize", argc, 0, 1, 2, 3, 4);
|
29
26
|
|
30
|
-
if (argc
|
31
|
-
|
32
|
-
switch (argc)
|
33
|
-
{
|
34
|
-
case 1:
|
35
|
-
*THIS = Rays::Color(to<float>(argv[0]));
|
36
|
-
break;
|
37
|
-
|
38
|
-
case 2:
|
39
|
-
*THIS = Rays::Color(to<float>(argv[0]), to<float>(argv[1]));
|
40
|
-
break;
|
41
|
-
|
42
|
-
case 3:
|
43
|
-
*THIS = Rays::Color(
|
44
|
-
to<float>(argv[0]), to<float>(argv[1]), to<float>(argv[2]));
|
45
|
-
break;
|
46
|
-
|
47
|
-
case 4:
|
48
|
-
*THIS = Rays::Color(
|
49
|
-
to<float>(argv[0]), to<float>(argv[1]),
|
50
|
-
to<float>(argv[2]), to<float>(argv[3]));
|
51
|
-
break;
|
52
|
-
}
|
27
|
+
if (argc >= 1)
|
28
|
+
*THIS = to<Rays::Color>(argc, argv);
|
53
29
|
|
54
30
|
return self;
|
55
31
|
}
|
@@ -127,6 +103,82 @@ VALUE get_alpha(VALUE self)
|
|
127
103
|
}
|
128
104
|
|
129
105
|
|
106
|
+
typedef std::map<Rays::String, Rays::Color> ColorMap;
|
107
|
+
|
108
|
+
static ColorMap&
|
109
|
+
get_color_map ()
|
110
|
+
{
|
111
|
+
static ColorMap map;
|
112
|
+
if (map.empty())
|
113
|
+
{
|
114
|
+
map["no"] =
|
115
|
+
map["none"] =
|
116
|
+
map["transp"] =
|
117
|
+
map["transparent"] = Rays::gray(0, 0);
|
118
|
+
|
119
|
+
map["black"] = Rays::rgb8( 0, 0, 0);
|
120
|
+
map["white"] = Rays::rgb8(255, 241, 232);
|
121
|
+
map["gray"] =
|
122
|
+
map["lightgray"] = Rays::rgb8(194, 195, 199);
|
123
|
+
map["darkgray"] = Rays::rgb8( 95, 87, 79);
|
124
|
+
map["brown"] = Rays::rgb8(171, 82, 54);
|
125
|
+
map["red"] = Rays::rgb8(255, 0, 77);
|
126
|
+
map["orange"] = Rays::rgb8(255, 163, 0);
|
127
|
+
map["yellow"] = Rays::rgb8(255, 236, 39);
|
128
|
+
map["green"] = Rays::rgb8( 0, 228, 54);
|
129
|
+
map["darkgreen"] = Rays::rgb8( 0, 135, 81);
|
130
|
+
map["blue"] = Rays::rgb8( 41, 173, 255);
|
131
|
+
map["darkblue"] = Rays::rgb8( 29, 43, 83);
|
132
|
+
map["indigo"] = Rays::rgb8(131, 118, 156);
|
133
|
+
map["pink"] = Rays::rgb8(255, 119, 168);
|
134
|
+
map["peach"] = Rays::rgb8(255, 204, 170);
|
135
|
+
map["darkpurple"] = Rays::rgb8(126, 37, 83);
|
136
|
+
}
|
137
|
+
return map;
|
138
|
+
}
|
139
|
+
|
140
|
+
static const Rays::String
|
141
|
+
to_color_name (const char* name)
|
142
|
+
{
|
143
|
+
return Rays::String(name).downcase();
|
144
|
+
}
|
145
|
+
|
146
|
+
static const Rays::Color&
|
147
|
+
find_color (const char* name)
|
148
|
+
{
|
149
|
+
assert(name);
|
150
|
+
|
151
|
+
const ColorMap& map = get_color_map();
|
152
|
+
ColorMap::const_iterator it = map.find(to_color_name(name));
|
153
|
+
if (it == map.end())
|
154
|
+
argument_error(__FILE__, __LINE__, "color '%s' is not found.", name);
|
155
|
+
|
156
|
+
return it->second;
|
157
|
+
}
|
158
|
+
|
159
|
+
static
|
160
|
+
VALUE hsv(VALUE self)
|
161
|
+
{
|
162
|
+
check_arg_count(__FILE__, __LINE__, "Color.hsv", argc, 3, 4);
|
163
|
+
|
164
|
+
float h = to<float>(argv[0]);
|
165
|
+
float s = to<float>(argv[1]);
|
166
|
+
float v = to<float>(argv[2]);
|
167
|
+
if (argc >= 4)
|
168
|
+
return value(Rays::hsv(h, s, v, to<float>(argv[3])));
|
169
|
+
else
|
170
|
+
return value(Rays::hsv(h, s, v));
|
171
|
+
}
|
172
|
+
|
173
|
+
static
|
174
|
+
VALUE set_palette_color(VALUE self)
|
175
|
+
{
|
176
|
+
check_arg_count(__FILE__, __LINE__, "Color.set_palette_color", argc, 2, 3, 4, 5);
|
177
|
+
|
178
|
+
get_color_map()[to_color_name(argv[0].c_str())] = to<Rays::Color>(argc - 1, &argv[1]);
|
179
|
+
}
|
180
|
+
|
181
|
+
|
130
182
|
static Class cColor;
|
131
183
|
|
132
184
|
void
|
@@ -136,7 +188,7 @@ Init_color ()
|
|
136
188
|
|
137
189
|
cColor = rb_define_class_under(mRays, "Color", rb_cObject);
|
138
190
|
rb_define_alloc_func(cColor, alloc);
|
139
|
-
rb_define_private_method(cColor, "
|
191
|
+
rb_define_private_method(cColor, "initialize", RUBY_METHOD_FUNC(initialize), -1);
|
140
192
|
rb_define_private_method(cColor, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
|
141
193
|
rb_define_method(cColor, "red=", RUBY_METHOD_FUNC(set_red), 1);
|
142
194
|
rb_define_method(cColor, "red", RUBY_METHOD_FUNC(get_red), 0);
|
@@ -146,6 +198,8 @@ Init_color ()
|
|
146
198
|
rb_define_method(cColor, "blue", RUBY_METHOD_FUNC(get_blue), 0);
|
147
199
|
rb_define_method(cColor, "alpha=", RUBY_METHOD_FUNC(set_alpha), 1);
|
148
200
|
rb_define_method(cColor, "alpha", RUBY_METHOD_FUNC(get_alpha), 0);
|
201
|
+
rb_define_module_function(cColor, "hsv", RUBY_METHOD_FUNC(hsv), -1);
|
202
|
+
rb_define_module_function(cColor, "set_palette_color", RUBY_METHOD_FUNC(set_palette_color), -1);
|
149
203
|
}
|
150
204
|
|
151
205
|
|
@@ -153,31 +207,155 @@ namespace Rucy
|
|
153
207
|
{
|
154
208
|
|
155
209
|
|
210
|
+
static int
|
211
|
+
char2hex (char c)
|
212
|
+
{
|
213
|
+
if ('0' <= c && c <= '9') return c - '0';
|
214
|
+
else if ('a' <= c && c <= 'f') return 10 + c - 'a';
|
215
|
+
else if ('A' <= c && c <= 'F') return 10 + c - 'A';
|
216
|
+
else return -1;
|
217
|
+
}
|
218
|
+
|
219
|
+
static bool
|
220
|
+
parse_channel (float* channel, const char* str, size_t nchars, size_t index)
|
221
|
+
{
|
222
|
+
assert(channel && str && 1 <= nchars && nchars <= 2 && 0 <= index && index <= 3);
|
223
|
+
|
224
|
+
const char* p = str + index * nchars;
|
225
|
+
|
226
|
+
if (nchars == 1)
|
227
|
+
{
|
228
|
+
int c0 = char2hex(p[0]);
|
229
|
+
if (c0 < 0)
|
230
|
+
return false;
|
231
|
+
|
232
|
+
assert(c0 < 16);
|
233
|
+
|
234
|
+
*channel = c0 / 15.f;
|
235
|
+
return true;
|
236
|
+
}
|
237
|
+
else
|
238
|
+
{
|
239
|
+
int c0 = char2hex(p[0]);
|
240
|
+
int c1 = char2hex(p[1]);
|
241
|
+
if (c0 < 0 || c1 < 0)
|
242
|
+
return false;
|
243
|
+
|
244
|
+
assert(c0 < 16 && c1 < 16);
|
245
|
+
|
246
|
+
*channel = (c0 * 16 + c1) / 255.f;
|
247
|
+
return true;
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
static bool
|
252
|
+
parse_string (Rays::Color* color, const char* str)
|
253
|
+
{
|
254
|
+
assert(color && str);
|
255
|
+
|
256
|
+
if (*str != '#') return false;
|
257
|
+
++str;
|
258
|
+
|
259
|
+
size_t len = strlen(str);
|
260
|
+
switch (len)
|
261
|
+
{
|
262
|
+
case 3:
|
263
|
+
case 6:
|
264
|
+
{
|
265
|
+
size_t nchars = len / 3;
|
266
|
+
|
267
|
+
float r, g, b;
|
268
|
+
if (
|
269
|
+
!parse_channel(&r, str, nchars, 0) ||
|
270
|
+
!parse_channel(&g, str, nchars, 1) ||
|
271
|
+
!parse_channel(&b, str, nchars, 2))
|
272
|
+
{
|
273
|
+
return false;
|
274
|
+
}
|
275
|
+
|
276
|
+
color->reset(r, g, b);
|
277
|
+
break;
|
278
|
+
}
|
279
|
+
|
280
|
+
case 4:
|
281
|
+
case 8:
|
282
|
+
{
|
283
|
+
size_t nchars = len / 4;
|
284
|
+
|
285
|
+
float r, g, b, a;
|
286
|
+
if (
|
287
|
+
!parse_channel(&r, str, nchars, 0) ||
|
288
|
+
!parse_channel(&g, str, nchars, 1) ||
|
289
|
+
!parse_channel(&b, str, nchars, 2) ||
|
290
|
+
!parse_channel(&a, str, nchars, 3))
|
291
|
+
{
|
292
|
+
return false;
|
293
|
+
}
|
294
|
+
|
295
|
+
color->reset(r, g, b, a);
|
296
|
+
break;
|
297
|
+
}
|
298
|
+
|
299
|
+
default: return false;
|
300
|
+
}
|
301
|
+
|
302
|
+
return true;
|
303
|
+
}
|
304
|
+
|
305
|
+
static Rays::Color
|
306
|
+
str2color (const char* str)
|
307
|
+
{
|
308
|
+
if (!str)
|
309
|
+
argument_error(__FILE__, __LINE__);
|
310
|
+
|
311
|
+
Rays::String str_ = str;
|
312
|
+
str_ = str_.strip();
|
313
|
+
|
314
|
+
Rays::Color color;
|
315
|
+
if (parse_string(&color, str_.c_str()))
|
316
|
+
return color;
|
317
|
+
else
|
318
|
+
return find_color(str_.c_str());
|
319
|
+
}
|
320
|
+
|
156
321
|
template <> Rays::Color
|
157
|
-
value_to<Rays::Color> (
|
322
|
+
value_to<Rays::Color> (int argc, const Value*argv, bool convert)
|
158
323
|
{
|
324
|
+
if (argc == 1 && argv->is_array())
|
325
|
+
{
|
326
|
+
argc = argv->size();
|
327
|
+
argv = argv->as_array();
|
328
|
+
}
|
329
|
+
|
330
|
+
assert(argc == 0 || (argc > 0 && argv));
|
331
|
+
|
159
332
|
if (convert)
|
160
333
|
{
|
161
|
-
if (
|
162
|
-
return Rays::Color(
|
163
|
-
else if (
|
334
|
+
if (argc == 0)
|
335
|
+
return Rays::Color();
|
336
|
+
else if (argv->is_nil())
|
337
|
+
return str2color("none");
|
338
|
+
else if (argv->is_s() || argv->is_sym())
|
339
|
+
return str2color(argv[0].c_str());
|
340
|
+
else if (argv->is_num())
|
164
341
|
{
|
165
|
-
|
166
|
-
if (size <= 0 || 4 < size)
|
167
|
-
Rucy::argument_error(__FILE__, __LINE__);
|
168
|
-
|
169
|
-
Value* a = value.as_array();
|
170
|
-
switch (size)
|
342
|
+
switch (argc)
|
171
343
|
{
|
172
|
-
|
173
|
-
case
|
174
|
-
case
|
175
|
-
case
|
344
|
+
#define V(i) argv[i].as_f(true)
|
345
|
+
case 1: return Rays::Color(V(0));
|
346
|
+
case 2: return Rays::Color(V(0), V(1));
|
347
|
+
case 3: return Rays::Color(V(0), V(1), V(2));
|
348
|
+
case 4: return Rays::Color(V(0), V(1), V(2), V(3));
|
349
|
+
#undef V
|
350
|
+
default: argument_error(__FILE__, __LINE__, "invalid array size.");
|
176
351
|
}
|
177
352
|
}
|
178
353
|
}
|
179
354
|
|
180
|
-
|
355
|
+
if (argc != 1)
|
356
|
+
argument_error(__FILE__, __LINE__);
|
357
|
+
|
358
|
+
return value_to<Rays::Color&>(*argv, convert);
|
181
359
|
}
|
182
360
|
|
183
361
|
|
@@ -1,18 +1,65 @@
|
|
1
1
|
#include "rays/ruby/color_space.h"
|
2
2
|
|
3
3
|
|
4
|
-
#include <rucy.h>
|
5
4
|
#include "defs.h"
|
6
5
|
|
7
6
|
|
8
|
-
|
7
|
+
RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::ColorSpace)
|
9
8
|
|
9
|
+
#define THIS to<Rays::ColorSpace*>(self)
|
10
10
|
|
11
|
-
|
11
|
+
#define CHECK RUCY_CHECK_OBJECT(Rays::ColorSpace, self)
|
12
12
|
|
13
|
-
#define THIS to<Rays::ColorSpace*>(self)
|
14
13
|
|
15
|
-
|
14
|
+
static struct ColorSpaceEnum
|
15
|
+
{
|
16
|
+
const char* name;
|
17
|
+
Rays::ColorSpaceType type;
|
18
|
+
}
|
19
|
+
COLOR_SPACES[] =
|
20
|
+
{
|
21
|
+
{"GRAY", Rays::GRAY},
|
22
|
+
{"ALPHA", Rays::ALPHA},
|
23
|
+
{"RGB", Rays:: RGB},
|
24
|
+
{"BGR", Rays:: BGR},
|
25
|
+
{"RGBA", Rays:: RGBA},
|
26
|
+
{"RGBX", Rays:: RGBX},
|
27
|
+
{"ARGB", Rays::ARGB},
|
28
|
+
{"XRGB", Rays::XRGB},
|
29
|
+
{"BGRA", Rays:: BGRA},
|
30
|
+
{"BGRX", Rays:: BGRX},
|
31
|
+
{"ABGR", Rays::ABGR},
|
32
|
+
{"XBGR", Rays::XBGR},
|
33
|
+
{"GRAY_8", Rays::GRAY_8},
|
34
|
+
{"GRAY_16", Rays::GRAY_16},
|
35
|
+
{"GRAY_24", Rays::GRAY_24},
|
36
|
+
{"GRAY_32", Rays::GRAY_32},
|
37
|
+
{"GRAY_float", Rays::GRAY_float},
|
38
|
+
{"ALPHA_8", Rays::ALPHA_8},
|
39
|
+
{"ALPHA_16", Rays::ALPHA_16},
|
40
|
+
{"ALPHA_24", Rays::ALPHA_24},
|
41
|
+
{"ALPHA_32", Rays::ALPHA_32},
|
42
|
+
{"ALPHA_float", Rays::ALPHA_float},
|
43
|
+
{"RGB_888", Rays:: RGB_888},
|
44
|
+
{"RGBA_8888", Rays:: RGBA_8888},
|
45
|
+
{"RGBX_8888", Rays:: RGBX_8888},
|
46
|
+
{"ARGB_8888", Rays::ARGB_8888},
|
47
|
+
{"XRGB_8888", Rays::XRGB_8888},
|
48
|
+
{"BGR_888", Rays:: BGR_888},
|
49
|
+
{"BGRA_8888", Rays:: BGRA_8888},
|
50
|
+
{"BGRX_8888", Rays:: BGRX_8888},
|
51
|
+
{"ABGR_8888", Rays::ABGR_8888},
|
52
|
+
{"XBGR_8888", Rays::XBGR_8888},
|
53
|
+
{"RGB_float", Rays:: RGB_float},
|
54
|
+
{"RGBA_float", Rays:: RGBA_float},
|
55
|
+
{"ARGB_float", Rays::ARGB_float},
|
56
|
+
{"BGR_float", Rays:: BGR_float},
|
57
|
+
{"BGRA_float", Rays:: BGRA_float},
|
58
|
+
{"ABGR_float", Rays::ABGR_float},
|
59
|
+
};
|
60
|
+
|
61
|
+
static const size_t COLOR_SPACES_SIZE =
|
62
|
+
sizeof(COLOR_SPACES) / sizeof(COLOR_SPACES[0]);
|
16
63
|
|
17
64
|
|
18
65
|
static
|
@@ -22,13 +69,12 @@ VALUE alloc(VALUE klass)
|
|
22
69
|
}
|
23
70
|
|
24
71
|
static
|
25
|
-
VALUE
|
72
|
+
VALUE initialize(VALUE self)
|
26
73
|
{
|
27
|
-
|
74
|
+
RUCY_CHECK_OBJ(Rays::ColorSpace, self);
|
75
|
+
check_arg_count(__FILE__, __LINE__, "ColorSpace#initialize", argc, 1, 2);
|
28
76
|
|
29
|
-
*THIS = Rays::ColorSpace(
|
30
|
-
(Rays::ColorSpaceType) to<uint>(type),
|
31
|
-
to<bool>(premultiplied));
|
77
|
+
*THIS = to<Rays::ColorSpace>(argc, argv);
|
32
78
|
return self;
|
33
79
|
}
|
34
80
|
|
@@ -56,6 +102,14 @@ VALUE is_gray(VALUE self)
|
|
56
102
|
return value(THIS->is_gray());
|
57
103
|
}
|
58
104
|
|
105
|
+
static
|
106
|
+
VALUE is_alpha(VALUE self)
|
107
|
+
{
|
108
|
+
CHECK;
|
109
|
+
|
110
|
+
return value(THIS->is_alpha());
|
111
|
+
}
|
112
|
+
|
59
113
|
static
|
60
114
|
VALUE is_rgb(VALUE self)
|
61
115
|
{
|
@@ -104,6 +158,21 @@ VALUE is_premult(VALUE self)
|
|
104
158
|
return value(THIS->is_premult());
|
105
159
|
}
|
106
160
|
|
161
|
+
static
|
162
|
+
VALUE to_s(VALUE self)
|
163
|
+
{
|
164
|
+
CHECK;
|
165
|
+
|
166
|
+
Rays::ColorSpaceType type = THIS->type();
|
167
|
+
for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
|
168
|
+
{
|
169
|
+
if (type == COLOR_SPACES[i].type)
|
170
|
+
return value(COLOR_SPACES[i].name);
|
171
|
+
}
|
172
|
+
|
173
|
+
invalid_object_error(__FILE__, __LINE__);
|
174
|
+
}
|
175
|
+
|
107
176
|
|
108
177
|
static Class cColorSpace;
|
109
178
|
|
@@ -112,54 +181,85 @@ Init_color_space ()
|
|
112
181
|
{
|
113
182
|
Module mRays = rb_define_module("Rays");
|
114
183
|
|
184
|
+
for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
|
185
|
+
mRays.define_const(COLOR_SPACES[i].name, COLOR_SPACES[i].type);
|
186
|
+
|
115
187
|
cColorSpace = rb_define_class_under(mRays, "ColorSpace", rb_cObject);
|
116
188
|
rb_define_alloc_func(cColorSpace, alloc);
|
189
|
+
rb_define_private_method(cColorSpace, "initialize", RUBY_METHOD_FUNC(initialize), -1);
|
117
190
|
rb_define_private_method(cColorSpace, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
|
118
|
-
rb_define_private_method(cColorSpace, "setup", RUBY_METHOD_FUNC(setup), 2);
|
119
191
|
rb_define_method(cColorSpace, "type", RUBY_METHOD_FUNC(type), 0);
|
120
192
|
cColorSpace.define_method("gray?", is_gray);
|
193
|
+
cColorSpace.define_method("alpha?", is_alpha);
|
121
194
|
cColorSpace.define_method("rgb?", is_rgb);
|
122
195
|
cColorSpace.define_method("bgr?", is_bgr);
|
123
196
|
cColorSpace.define_method("float?", is_float);
|
124
|
-
cColorSpace.define_method("
|
125
|
-
cColorSpace.define_method("
|
197
|
+
cColorSpace.define_method("has_alpha?", has_alpha);
|
198
|
+
cColorSpace.define_method("has_skip?", has_skip);
|
126
199
|
cColorSpace.define_method("premult?", is_premult);
|
127
|
-
|
128
|
-
cColorSpace.define_const("GRAY_8", Rays::GRAY_8);
|
129
|
-
cColorSpace.define_const("GRAY_16", Rays::GRAY_16);
|
130
|
-
cColorSpace.define_const("GRAY_24", Rays::GRAY_24);
|
131
|
-
cColorSpace.define_const("GRAY_32", Rays::GRAY_32);
|
132
|
-
cColorSpace.define_const("GRAY_float", Rays::GRAY_float);
|
133
|
-
cColorSpace.define_const("RGB_888", Rays:: RGB_888);
|
134
|
-
cColorSpace.define_const("RGBA_8888", Rays:: RGBA_8888);
|
135
|
-
cColorSpace.define_const("RGBX_8888", Rays:: RGBX_8888);
|
136
|
-
cColorSpace.define_const("ARGB_8888", Rays::ARGB_8888);
|
137
|
-
cColorSpace.define_const("XRGB_8888", Rays::XRGB_8888);
|
138
|
-
cColorSpace.define_const("BGR_888", Rays:: BGR_888);
|
139
|
-
cColorSpace.define_const("BGRA_8888", Rays:: BGRA_8888);
|
140
|
-
cColorSpace.define_const("BGRX_8888", Rays:: BGRX_8888);
|
141
|
-
cColorSpace.define_const("ABGR_8888", Rays::ABGR_8888);
|
142
|
-
cColorSpace.define_const("XBGR_8888", Rays::XBGR_8888);
|
143
|
-
cColorSpace.define_const("RGB_float", Rays:: RGB_float);
|
144
|
-
cColorSpace.define_const("RGBA_float", Rays:: RGBA_float);
|
145
|
-
cColorSpace.define_const("ARGB_float", Rays::ARGB_float);
|
146
|
-
cColorSpace.define_const("BGR_float", Rays:: BGR_float);
|
147
|
-
cColorSpace.define_const("BGRA_float", Rays:: BGRA_float);
|
148
|
-
cColorSpace.define_const("ABGR_float", Rays::ABGR_float);
|
149
|
-
cColorSpace.define_const("GRAY", Rays::GRAY);
|
150
|
-
cColorSpace.define_const("RGB", Rays:: RGB);
|
151
|
-
cColorSpace.define_const("BGR", Rays:: BGR);
|
152
|
-
cColorSpace.define_const("RGBA", Rays:: RGBA);
|
153
|
-
cColorSpace.define_const("RGBX", Rays:: RGBX);
|
154
|
-
cColorSpace.define_const("ARGB", Rays::ARGB);
|
155
|
-
cColorSpace.define_const("XRGB", Rays::XRGB);
|
156
|
-
cColorSpace.define_const("BGRA", Rays:: BGRA);
|
157
|
-
cColorSpace.define_const("BGRX", Rays:: BGRX);
|
158
|
-
cColorSpace.define_const("ABGR", Rays::ABGR);
|
159
|
-
cColorSpace.define_const("XBGR", Rays::XBGR);
|
200
|
+
rb_define_method(cColorSpace, "to_s", RUBY_METHOD_FUNC(to_s), 0);
|
160
201
|
}
|
161
202
|
|
162
203
|
|
204
|
+
namespace Rucy
|
205
|
+
{
|
206
|
+
|
207
|
+
|
208
|
+
template <> Rays::ColorSpace
|
209
|
+
value_to<Rays::ColorSpace> (int argc, const Value* argv, bool convert)
|
210
|
+
{
|
211
|
+
if (argc == 1 && argv->is_array())
|
212
|
+
{
|
213
|
+
argc = argv->size();
|
214
|
+
argv = argv->as_array();
|
215
|
+
}
|
216
|
+
|
217
|
+
assert(argc > 0 && argv);
|
218
|
+
|
219
|
+
if (convert)
|
220
|
+
{
|
221
|
+
if (argv->is_i() || argv->is_s() || argv->is_sym())
|
222
|
+
{
|
223
|
+
return Rays::ColorSpace(
|
224
|
+
to<Rays::ColorSpaceType>(argv[0]),
|
225
|
+
argc >= 2 ? to<bool>(argv[1]) : true);
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
229
|
+
if (argc != 1)
|
230
|
+
argument_error(__FILE__, __LINE__);
|
231
|
+
|
232
|
+
return value_to<Rays::ColorSpace&>(*argv, convert);
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
template <> Rays::ColorSpaceType
|
237
|
+
value_to<Rays::ColorSpaceType> (Value value, bool convert)
|
238
|
+
{
|
239
|
+
if (convert)
|
240
|
+
{
|
241
|
+
if (value.is_s() || value.is_sym())
|
242
|
+
{
|
243
|
+
const char* str = value.c_str();
|
244
|
+
for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
|
245
|
+
{
|
246
|
+
if (strcasecmp(str, COLOR_SPACES[i].name) == 0)
|
247
|
+
return COLOR_SPACES[i].type;
|
248
|
+
}
|
249
|
+
}
|
250
|
+
}
|
251
|
+
|
252
|
+
uint type = value_to<uint>(value, convert);
|
253
|
+
if (type >= Rays::COLORSPACE_MAX)
|
254
|
+
argument_error(__FILE__, __LINE__, "invalid color space type -- %d", type);
|
255
|
+
|
256
|
+
return (Rays::ColorSpaceType) type;
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
}// Rucy
|
261
|
+
|
262
|
+
|
163
263
|
namespace Rays
|
164
264
|
{
|
165
265
|
|