rays 0.1.12 → 0.1.13
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/color.cpp +224 -45
- data/.doc/ext/rays/color_space.cpp +137 -45
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +39 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +12 -6
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +120 -308
- data/.doc/ext/rays/point.cpp +82 -77
- data/.doc/ext/rays/polygon.cpp +287 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +161 -0
- data/.doc/ext/rays/rays.cpp +0 -13
- data/.doc/ext/rays/shader.cpp +83 -9
- data/README.md +1 -1
- data/Rakefile +21 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +22 -80
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/color.cpp +232 -51
- data/ext/rays/color_space.cpp +140 -46
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +1 -2
- data/ext/rays/font.cpp +39 -22
- data/ext/rays/image.cpp +27 -39
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +12 -6
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +129 -315
- data/ext/rays/point.cpp +89 -81
- data/ext/rays/polygon.cpp +301 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +170 -0
- data/ext/rays/rays.cpp +0 -14
- 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/color.h +25 -14
- data/include/rays/color_space.h +11 -8
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +3 -0
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +11 -17
- 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 +57 -99
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +164 -0
- data/include/rays/polyline.h +65 -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/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/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +6 -1
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +2 -6
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +60 -97
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +50 -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 +50 -32
- 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 +171 -97
- data/src/image.h +25 -0
- data/src/ios/bitmap.mm +107 -105
- data/src/ios/font.mm +48 -60
- 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.mm +111 -106
- data/src/osx/font.mm +48 -61
- 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 +780 -696
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1100 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +158 -0
- data/src/polyline.h +67 -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_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +92 -46
- data/test/test_painter_shape.rb +57 -0
- data/test/test_point.rb +21 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +145 -0
- data/test/test_shader.rb +9 -9
- metadata +88 -67
- 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
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,9 @@ 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
|
+
|
202
|
+
rb_define_function(cColor, "hsv", RUBY_METHOD_FUNC(hsv), -1);
|
203
|
+
rb_define_function(cColor, "set_palette_color", RUBY_METHOD_FUNC(set_palette_color), -1);
|
149
204
|
}
|
150
205
|
|
151
206
|
|
@@ -153,31 +208,155 @@ namespace Rucy
|
|
153
208
|
{
|
154
209
|
|
155
210
|
|
211
|
+
static int
|
212
|
+
char2hex (char c)
|
213
|
+
{
|
214
|
+
if ('0' <= c && c <= '9') return c - '0';
|
215
|
+
else if ('a' <= c && c <= 'f') return 10 + c - 'a';
|
216
|
+
else if ('A' <= c && c <= 'F') return 10 + c - 'A';
|
217
|
+
else return -1;
|
218
|
+
}
|
219
|
+
|
220
|
+
static bool
|
221
|
+
parse_channel (float* channel, const char* str, size_t nchars, size_t index)
|
222
|
+
{
|
223
|
+
assert(channel && str && 1 <= nchars && nchars <= 2 && 0 <= index && index <= 3);
|
224
|
+
|
225
|
+
const char* p = str + index * nchars;
|
226
|
+
|
227
|
+
if (nchars == 1)
|
228
|
+
{
|
229
|
+
int c0 = char2hex(p[0]);
|
230
|
+
if (c0 < 0)
|
231
|
+
return false;
|
232
|
+
|
233
|
+
assert(c0 < 16);
|
234
|
+
|
235
|
+
*channel = c0 / 15.f;
|
236
|
+
return true;
|
237
|
+
}
|
238
|
+
else
|
239
|
+
{
|
240
|
+
int c0 = char2hex(p[0]);
|
241
|
+
int c1 = char2hex(p[1]);
|
242
|
+
if (c0 < 0 || c1 < 0)
|
243
|
+
return false;
|
244
|
+
|
245
|
+
assert(c0 < 16 && c1 < 16);
|
246
|
+
|
247
|
+
*channel = (c0 * 16 + c1) / 255.f;
|
248
|
+
return true;
|
249
|
+
}
|
250
|
+
}
|
251
|
+
|
252
|
+
static bool
|
253
|
+
parse_string (Rays::Color* color, const char* str)
|
254
|
+
{
|
255
|
+
assert(color && str);
|
256
|
+
|
257
|
+
if (*str != '#') return false;
|
258
|
+
++str;
|
259
|
+
|
260
|
+
size_t len = strlen(str);
|
261
|
+
switch (len)
|
262
|
+
{
|
263
|
+
case 3:
|
264
|
+
case 6:
|
265
|
+
{
|
266
|
+
size_t nchars = len / 3;
|
267
|
+
|
268
|
+
float r, g, b;
|
269
|
+
if (
|
270
|
+
!parse_channel(&r, str, nchars, 0) ||
|
271
|
+
!parse_channel(&g, str, nchars, 1) ||
|
272
|
+
!parse_channel(&b, str, nchars, 2))
|
273
|
+
{
|
274
|
+
return false;
|
275
|
+
}
|
276
|
+
|
277
|
+
color->reset(r, g, b);
|
278
|
+
break;
|
279
|
+
}
|
280
|
+
|
281
|
+
case 4:
|
282
|
+
case 8:
|
283
|
+
{
|
284
|
+
size_t nchars = len / 4;
|
285
|
+
|
286
|
+
float r, g, b, a;
|
287
|
+
if (
|
288
|
+
!parse_channel(&r, str, nchars, 0) ||
|
289
|
+
!parse_channel(&g, str, nchars, 1) ||
|
290
|
+
!parse_channel(&b, str, nchars, 2) ||
|
291
|
+
!parse_channel(&a, str, nchars, 3))
|
292
|
+
{
|
293
|
+
return false;
|
294
|
+
}
|
295
|
+
|
296
|
+
color->reset(r, g, b, a);
|
297
|
+
break;
|
298
|
+
}
|
299
|
+
|
300
|
+
default: return false;
|
301
|
+
}
|
302
|
+
|
303
|
+
return true;
|
304
|
+
}
|
305
|
+
|
306
|
+
static Rays::Color
|
307
|
+
str2color (const char* str)
|
308
|
+
{
|
309
|
+
if (!str)
|
310
|
+
argument_error(__FILE__, __LINE__);
|
311
|
+
|
312
|
+
Rays::String str_ = str;
|
313
|
+
str_ = str_.strip();
|
314
|
+
|
315
|
+
Rays::Color color;
|
316
|
+
if (parse_string(&color, str_.c_str()))
|
317
|
+
return color;
|
318
|
+
else
|
319
|
+
return find_color(str_.c_str());
|
320
|
+
}
|
321
|
+
|
156
322
|
template <> Rays::Color
|
157
|
-
value_to<Rays::Color> (
|
323
|
+
value_to<Rays::Color> (int argc, const Value*argv, bool convert)
|
158
324
|
{
|
325
|
+
if (argc == 1 && argv->is_array())
|
326
|
+
{
|
327
|
+
argc = argv->size();
|
328
|
+
argv = argv->as_array();
|
329
|
+
}
|
330
|
+
|
331
|
+
assert(argc == 0 || (argc > 0 && argv));
|
332
|
+
|
159
333
|
if (convert)
|
160
334
|
{
|
161
|
-
if (
|
162
|
-
return Rays::Color(
|
163
|
-
else if (
|
335
|
+
if (argc == 0)
|
336
|
+
return Rays::Color();
|
337
|
+
else if (argv->is_nil())
|
338
|
+
return str2color("none");
|
339
|
+
else if (argv->is_s() || argv->is_sym())
|
340
|
+
return str2color(argv[0].c_str());
|
341
|
+
else if (argv->is_num())
|
164
342
|
{
|
165
|
-
|
166
|
-
if (size <= 0 || 4 < size)
|
167
|
-
Rucy::argument_error(__FILE__, __LINE__);
|
168
|
-
|
169
|
-
Value* a = value.as_array();
|
170
|
-
switch (size)
|
343
|
+
switch (argc)
|
171
344
|
{
|
172
|
-
|
173
|
-
case
|
174
|
-
case
|
175
|
-
case
|
345
|
+
#define V(i) argv[i].as_f(true)
|
346
|
+
case 1: return Rays::Color(V(0));
|
347
|
+
case 2: return Rays::Color(V(0), V(1));
|
348
|
+
case 3: return Rays::Color(V(0), V(1), V(2));
|
349
|
+
case 4: return Rays::Color(V(0), V(1), V(2), V(3));
|
350
|
+
#undef V
|
351
|
+
default: argument_error(__FILE__, __LINE__, "invalid array size.");
|
176
352
|
}
|
177
353
|
}
|
178
354
|
}
|
179
355
|
|
180
|
-
|
356
|
+
if (argc != 1)
|
357
|
+
argument_error(__FILE__, __LINE__);
|
358
|
+
|
359
|
+
return value_to<Rays::Color&>(*argv, convert);
|
181
360
|
}
|
182
361
|
|
183
362
|
|
@@ -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
|
|
@@ -114,52 +183,75 @@ Init_color_space ()
|
|
114
183
|
|
115
184
|
cColorSpace = rb_define_class_under(mRays, "ColorSpace", rb_cObject);
|
116
185
|
rb_define_alloc_func(cColorSpace, alloc);
|
186
|
+
rb_define_private_method(cColorSpace, "initialize", RUBY_METHOD_FUNC(initialize), -1);
|
117
187
|
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
188
|
rb_define_method(cColorSpace, "type", RUBY_METHOD_FUNC(type), 0);
|
120
189
|
cColorSpace.define_method("gray?", is_gray);
|
190
|
+
cColorSpace.define_method("alpha?", is_alpha);
|
121
191
|
cColorSpace.define_method("rgb?", is_rgb);
|
122
192
|
cColorSpace.define_method("bgr?", is_bgr);
|
123
193
|
cColorSpace.define_method("float?", is_float);
|
124
|
-
cColorSpace.define_method("
|
125
|
-
cColorSpace.define_method("
|
194
|
+
cColorSpace.define_method("has_alpha?", has_alpha);
|
195
|
+
cColorSpace.define_method("has_skip?", has_skip);
|
126
196
|
cColorSpace.define_method("premult?", is_premult);
|
197
|
+
rb_define_method(cColorSpace, "to_s", RUBY_METHOD_FUNC(to_s), 0);
|
127
198
|
|
128
|
-
|
129
|
-
|
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);
|
199
|
+
for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
|
200
|
+
cColorSpace.define_const(COLOR_SPACES[i].name, COLOR_SPACES[i].type);
|
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_s() || argv->is_sym())
|
222
|
+
{
|
223
|
+
const char* str = argv[0].c_str();
|
224
|
+
for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
|
225
|
+
{
|
226
|
+
if (strcasecmp(str, COLOR_SPACES[i].name) == 0)
|
227
|
+
return Rays::ColorSpace(COLOR_SPACES[i].type);
|
228
|
+
}
|
229
|
+
}
|
230
|
+
else if (argv->is_i())
|
231
|
+
{
|
232
|
+
return Rays::ColorSpace(
|
233
|
+
to<Rays::ColorSpaceType>(argv[0]),
|
234
|
+
argc >= 2 ? to<bool>(argv[1]) : true);
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
if (argc != 1)
|
239
|
+
argument_error(__FILE__, __LINE__);
|
240
|
+
|
241
|
+
return value_to<Rays::ColorSpace&>(*argv, convert);
|
242
|
+
}
|
243
|
+
|
244
|
+
|
245
|
+
template <> Rays::ColorSpaceType
|
246
|
+
value_to<Rays::ColorSpaceType> (Value value, bool convert)
|
247
|
+
{
|
248
|
+
return (Rays::ColorSpaceType) value_to<uint>(value, convert);
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
}// Rucy
|
253
|
+
|
254
|
+
|
163
255
|
namespace Rays
|
164
256
|
{
|
165
257
|
|