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