rays 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +5 -5
  2. data/.doc/ext/rays/bitmap.cpp +22 -76
  3. data/.doc/ext/rays/bounds.cpp +95 -125
  4. data/.doc/ext/rays/color.cpp +224 -45
  5. data/.doc/ext/rays/color_space.cpp +137 -45
  6. data/.doc/ext/rays/defs.cpp +183 -0
  7. data/.doc/ext/rays/font.cpp +39 -21
  8. data/.doc/ext/rays/image.cpp +26 -37
  9. data/.doc/ext/rays/matrix.cpp +186 -29
  10. data/.doc/ext/rays/native.cpp +12 -6
  11. data/.doc/ext/rays/noise.cpp +53 -0
  12. data/.doc/ext/rays/painter.cpp +120 -308
  13. data/.doc/ext/rays/point.cpp +82 -77
  14. data/.doc/ext/rays/polygon.cpp +287 -0
  15. data/.doc/ext/rays/polygon_line.cpp +96 -0
  16. data/.doc/ext/rays/polyline.cpp +161 -0
  17. data/.doc/ext/rays/rays.cpp +0 -13
  18. data/.doc/ext/rays/shader.cpp +83 -9
  19. data/README.md +1 -1
  20. data/Rakefile +21 -9
  21. data/VERSION +1 -1
  22. data/ext/rays/bitmap.cpp +22 -80
  23. data/ext/rays/bounds.cpp +100 -128
  24. data/ext/rays/color.cpp +232 -51
  25. data/ext/rays/color_space.cpp +140 -46
  26. data/ext/rays/defs.cpp +183 -0
  27. data/ext/rays/defs.h +26 -2
  28. data/ext/rays/extconf.rb +1 -2
  29. data/ext/rays/font.cpp +39 -22
  30. data/ext/rays/image.cpp +27 -39
  31. data/ext/rays/matrix.cpp +198 -30
  32. data/ext/rays/native.cpp +12 -6
  33. data/ext/rays/noise.cpp +55 -0
  34. data/ext/rays/painter.cpp +129 -315
  35. data/ext/rays/point.cpp +89 -81
  36. data/ext/rays/polygon.cpp +301 -0
  37. data/ext/rays/polygon_line.cpp +99 -0
  38. data/ext/rays/polyline.cpp +170 -0
  39. data/ext/rays/rays.cpp +0 -14
  40. data/ext/rays/shader.cpp +84 -9
  41. data/include/rays.h +10 -2
  42. data/include/rays/bitmap.h +14 -26
  43. data/include/rays/bounds.h +21 -4
  44. data/include/rays/color.h +25 -14
  45. data/include/rays/color_space.h +11 -8
  46. data/include/rays/coord.h +114 -0
  47. data/include/rays/debug.h +22 -0
  48. data/include/rays/defs.h +3 -0
  49. data/include/rays/font.h +4 -4
  50. data/include/rays/image.h +11 -17
  51. data/include/rays/matrix.h +50 -24
  52. data/include/rays/noise.h +42 -0
  53. data/include/rays/opengl.h +2 -50
  54. data/include/rays/painter.h +57 -99
  55. data/include/rays/point.h +44 -51
  56. data/include/rays/polygon.h +164 -0
  57. data/include/rays/polyline.h +65 -0
  58. data/include/rays/rays.h +3 -0
  59. data/include/rays/ruby.h +7 -1
  60. data/include/rays/ruby/bounds.h +1 -1
  61. data/include/rays/ruby/color.h +1 -1
  62. data/include/rays/ruby/color_space.h +1 -1
  63. data/include/rays/ruby/font.h +1 -1
  64. data/include/rays/ruby/matrix.h +1 -1
  65. data/include/rays/ruby/point.h +1 -1
  66. data/include/rays/ruby/polygon.h +52 -0
  67. data/include/rays/ruby/polyline.h +41 -0
  68. data/include/rays/ruby/shader.h +1 -1
  69. data/include/rays/shader.h +36 -8
  70. data/lib/rays.rb +6 -1
  71. data/lib/rays/bitmap.rb +0 -15
  72. data/lib/rays/bounds.rb +17 -23
  73. data/lib/rays/color.rb +20 -47
  74. data/lib/rays/color_space.rb +13 -13
  75. data/lib/rays/image.rb +2 -6
  76. data/lib/rays/matrix.rb +28 -0
  77. data/lib/rays/module.rb +4 -19
  78. data/lib/rays/painter.rb +60 -97
  79. data/lib/rays/point.rb +13 -21
  80. data/lib/rays/polygon.rb +50 -0
  81. data/lib/rays/polygon_line.rb +36 -0
  82. data/lib/rays/polyline.rb +32 -0
  83. data/lib/rays/shader.rb +20 -1
  84. data/rays.gemspec +5 -7
  85. data/src/bitmap.h +36 -0
  86. data/src/bounds.cpp +74 -11
  87. data/src/color.cpp +58 -23
  88. data/src/color_space.cpp +50 -32
  89. data/src/color_space.h +22 -0
  90. data/src/coord.cpp +170 -0
  91. data/src/coord.h +35 -0
  92. data/src/font.cpp +118 -0
  93. data/src/font.h +64 -0
  94. data/src/frame_buffer.cpp +37 -71
  95. data/src/frame_buffer.h +4 -4
  96. data/src/image.cpp +171 -97
  97. data/src/image.h +25 -0
  98. data/src/ios/bitmap.mm +107 -105
  99. data/src/ios/font.mm +48 -60
  100. data/src/ios/helper.h +2 -2
  101. data/src/ios/opengl.mm +19 -4
  102. data/src/ios/rays.mm +3 -0
  103. data/src/matrix.cpp +111 -26
  104. data/src/matrix.h +30 -0
  105. data/src/noise.cpp +74 -0
  106. data/src/opengl.cpp +9 -27
  107. data/src/opengl.h +37 -0
  108. data/src/osx/bitmap.mm +111 -106
  109. data/src/osx/font.mm +48 -61
  110. data/src/osx/helper.h +2 -2
  111. data/src/osx/opengl.mm +19 -83
  112. data/src/osx/rays.mm +3 -0
  113. data/src/painter.cpp +780 -696
  114. data/src/painter.h +24 -0
  115. data/src/point.cpp +140 -119
  116. data/src/polygon.cpp +1100 -0
  117. data/src/polygon.h +32 -0
  118. data/src/polyline.cpp +158 -0
  119. data/src/polyline.h +67 -0
  120. data/src/render_buffer.cpp +11 -4
  121. data/src/render_buffer.h +2 -2
  122. data/src/shader.cpp +163 -106
  123. data/src/shader.h +38 -0
  124. data/src/shader_program.cpp +533 -0
  125. data/src/{program.h → shader_program.h} +28 -16
  126. data/src/shader_source.cpp +140 -0
  127. data/src/shader_source.h +52 -0
  128. data/src/texture.cpp +136 -160
  129. data/src/texture.h +65 -0
  130. data/src/win32/bitmap.cpp +62 -52
  131. data/src/win32/font.cpp +11 -13
  132. data/src/win32/font.h +24 -0
  133. data/src/win32/gdi.h +6 -6
  134. data/test/helper.rb +0 -3
  135. data/test/test_bitmap.rb +31 -7
  136. data/test/test_bounds.rb +36 -0
  137. data/test/test_color.rb +59 -19
  138. data/test/test_color_space.rb +95 -0
  139. data/test/test_image.rb +24 -20
  140. data/test/test_matrix.rb +106 -0
  141. data/test/test_painter.rb +92 -46
  142. data/test/test_painter_shape.rb +57 -0
  143. data/test/test_point.rb +21 -0
  144. data/test/test_polygon.rb +234 -0
  145. data/test/test_polygon_line.rb +167 -0
  146. data/test/test_polyline.rb +145 -0
  147. data/test/test_shader.rb +9 -9
  148. metadata +88 -67
  149. data/.doc/ext/rays/texture.cpp +0 -138
  150. data/ext/rays/texture.cpp +0 -149
  151. data/include/rays/ruby/texture.h +0 -41
  152. data/include/rays/texture.h +0 -71
  153. data/lib/rays/texture.rb +0 -24
  154. data/src/program.cpp +0 -648
  155. data/test/test_texture.rb +0 -27
@@ -1,14 +1,11 @@
1
1
  #include "rays/ruby/color.h"
2
2
 
3
3
 
4
- #include <rucy.h>
4
+ #include <map>
5
5
  #include "defs.h"
6
6
 
7
7
 
8
- using namespace Rucy;
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(setup)
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 == 0) return self;
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,19 @@ Init_color ()
147
201
 
148
202
  cColor = mRays.define_class("Color");
149
203
  cColor.define_alloc_func(alloc);
150
- cColor.define_private_method("setup", setup);
204
+ cColor.define_private_method("initialize", initialize);
151
205
  cColor.define_private_method("initialize_copy", initialize_copy);
152
- cColor.define_method("red=", set_red);
153
- cColor.define_method("red", get_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", get_green);
156
- cColor.define_method("blue=", set_blue);
157
- cColor.define_method("blue", get_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", get_alpha);
213
+ cColor.define_method("alpha", get_alpha);
214
+
215
+ cColor.define_function("hsv", hsv);
216
+ cColor.define_function("set_palette_color", set_palette_color);
160
217
  }
161
218
 
162
219
 
@@ -164,31 +221,155 @@ namespace Rucy
164
221
  {
165
222
 
166
223
 
224
+ static int
225
+ char2hex (char c)
226
+ {
227
+ if ('0' <= c && c <= '9') return c - '0';
228
+ else if ('a' <= c && c <= 'f') return 10 + c - 'a';
229
+ else if ('A' <= c && c <= 'F') return 10 + c - 'A';
230
+ else return -1;
231
+ }
232
+
233
+ static bool
234
+ parse_channel (float* channel, const char* str, size_t nchars, size_t index)
235
+ {
236
+ assert(channel && str && 1 <= nchars && nchars <= 2 && 0 <= index && index <= 3);
237
+
238
+ const char* p = str + index * nchars;
239
+
240
+ if (nchars == 1)
241
+ {
242
+ int c0 = char2hex(p[0]);
243
+ if (c0 < 0)
244
+ return false;
245
+
246
+ assert(c0 < 16);
247
+
248
+ *channel = c0 / 15.f;
249
+ return true;
250
+ }
251
+ else
252
+ {
253
+ int c0 = char2hex(p[0]);
254
+ int c1 = char2hex(p[1]);
255
+ if (c0 < 0 || c1 < 0)
256
+ return false;
257
+
258
+ assert(c0 < 16 && c1 < 16);
259
+
260
+ *channel = (c0 * 16 + c1) / 255.f;
261
+ return true;
262
+ }
263
+ }
264
+
265
+ static bool
266
+ parse_string (Rays::Color* color, const char* str)
267
+ {
268
+ assert(color && str);
269
+
270
+ if (*str != '#') return false;
271
+ ++str;
272
+
273
+ size_t len = strlen(str);
274
+ switch (len)
275
+ {
276
+ case 3:
277
+ case 6:
278
+ {
279
+ size_t nchars = len / 3;
280
+
281
+ float r, g, b;
282
+ if (
283
+ !parse_channel(&r, str, nchars, 0) ||
284
+ !parse_channel(&g, str, nchars, 1) ||
285
+ !parse_channel(&b, str, nchars, 2))
286
+ {
287
+ return false;
288
+ }
289
+
290
+ color->reset(r, g, b);
291
+ break;
292
+ }
293
+
294
+ case 4:
295
+ case 8:
296
+ {
297
+ size_t nchars = len / 4;
298
+
299
+ float r, g, b, a;
300
+ if (
301
+ !parse_channel(&r, str, nchars, 0) ||
302
+ !parse_channel(&g, str, nchars, 1) ||
303
+ !parse_channel(&b, str, nchars, 2) ||
304
+ !parse_channel(&a, str, nchars, 3))
305
+ {
306
+ return false;
307
+ }
308
+
309
+ color->reset(r, g, b, a);
310
+ break;
311
+ }
312
+
313
+ default: return false;
314
+ }
315
+
316
+ return true;
317
+ }
318
+
319
+ static Rays::Color
320
+ str2color (const char* str)
321
+ {
322
+ if (!str)
323
+ argument_error(__FILE__, __LINE__);
324
+
325
+ Rays::String str_ = str;
326
+ str_ = str_.strip();
327
+
328
+ Rays::Color color;
329
+ if (parse_string(&color, str_.c_str()))
330
+ return color;
331
+ else
332
+ return find_color(str_.c_str());
333
+ }
334
+
167
335
  template <> Rays::Color
168
- value_to<Rays::Color> (Value value, bool convert)
336
+ value_to<Rays::Color> (int argc, const Value*argv, bool convert)
169
337
  {
338
+ if (argc == 1 && argv->is_array())
339
+ {
340
+ argc = argv->size();
341
+ argv = argv->as_array();
342
+ }
343
+
344
+ assert(argc == 0 || (argc > 0 && argv));
345
+
170
346
  if (convert)
171
347
  {
172
- if (value.is_i() || value.is_f())
173
- return Rays::Color(value.as_f(true));
174
- else if (value.is_array())
348
+ if (argc == 0)
349
+ return Rays::Color();
350
+ else if (argv->is_nil())
351
+ return str2color("none");
352
+ else if (argv->is_s() || argv->is_sym())
353
+ return str2color(argv[0].c_str());
354
+ else if (argv->is_num())
175
355
  {
176
- int size = value.size();
177
- if (size <= 0 || 4 < size)
178
- Rucy::argument_error(__FILE__, __LINE__);
179
-
180
- Value* a = value.as_array();
181
- switch (size)
356
+ switch (argc)
182
357
  {
183
- case 1: return Rays::Color(a[0].as_f(true));
184
- case 2: return Rays::Color(a[0].as_f(true), a[1].as_f(true));
185
- case 3: return Rays::Color(a[0].as_f(true), a[1].as_f(true), a[2].as_f(true));
186
- case 4: return Rays::Color(a[0].as_f(true), a[1].as_f(true), a[2].as_f(true), a[3].as_f(true));
358
+ #define V(i) argv[i].as_f(true)
359
+ case 1: return Rays::Color(V(0));
360
+ case 2: return Rays::Color(V(0), V(1));
361
+ case 3: return Rays::Color(V(0), V(1), V(2));
362
+ case 4: return Rays::Color(V(0), V(1), V(2), V(3));
363
+ #undef V
364
+ default: argument_error(__FILE__, __LINE__, "invalid array size.");
187
365
  }
188
366
  }
189
367
  }
190
368
 
191
- return value_to<Rays::Color&>(value, convert);
369
+ if (argc != 1)
370
+ argument_error(__FILE__, __LINE__);
371
+
372
+ return value_to<Rays::Color&>(*argv, convert);
192
373
  }
193
374
 
194
375
 
@@ -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
- using namespace Rucy;
7
+ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::ColorSpace)
9
8
 
9
+ #define THIS to<Rays::ColorSpace*>(self)
10
10
 
11
- RUCY_DEFINE_VALUE_FROM_TO(Rays::ColorSpace)
11
+ #define CHECK RUCY_CHECK_OBJECT(Rays::ColorSpace, self)
12
12
 
13
- #define THIS to<Rays::ColorSpace*>(self)
14
13
 
15
- #define CHECK RUCY_CHECK_OBJ(Rays::ColorSpace, self)
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
- RUCY_DEF2(setup, type, premultiplied)
73
+ RUCY_DEFN(initialize)
27
74
  {
28
- CHECK;
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
 
@@ -125,52 +196,75 @@ Init_color_space ()
125
196
 
126
197
  cColorSpace = mRays.define_class("ColorSpace");
127
198
  cColorSpace.define_alloc_func(alloc);
199
+ cColorSpace.define_private_method("initialize", initialize);
128
200
  cColorSpace.define_private_method("initialize_copy", initialize_copy);
129
- cColorSpace.define_private_method("setup", setup);
130
- cColorSpace.define_method("type", type);
201
+ cColorSpace.define_method("type", type);
131
202
  cColorSpace.define_method("gray?", is_gray);
203
+ cColorSpace.define_method("alpha?", is_alpha);
132
204
  cColorSpace.define_method("rgb?", is_rgb);
133
205
  cColorSpace.define_method("bgr?", is_bgr);
134
206
  cColorSpace.define_method("float?", is_float);
135
- cColorSpace.define_method("alpha?", has_alpha);
136
- cColorSpace.define_method("skip?", has_skip);
207
+ cColorSpace.define_method("has_alpha?", has_alpha);
208
+ cColorSpace.define_method("has_skip?", has_skip);
137
209
  cColorSpace.define_method("premult?", is_premult);
210
+ cColorSpace.define_method("to_s", to_s);
138
211
 
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);
212
+ for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
213
+ cColorSpace.define_const(COLOR_SPACES[i].name, COLOR_SPACES[i].type);
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_s() || argv->is_sym())
235
+ {
236
+ const char* str = argv[0].c_str();
237
+ for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
238
+ {
239
+ if (strcasecmp(str, COLOR_SPACES[i].name) == 0)
240
+ return Rays::ColorSpace(COLOR_SPACES[i].type);
241
+ }
242
+ }
243
+ else if (argv->is_i())
244
+ {
245
+ return Rays::ColorSpace(
246
+ to<Rays::ColorSpaceType>(argv[0]),
247
+ argc >= 2 ? to<bool>(argv[1]) : true);
248
+ }
249
+ }
250
+
251
+ if (argc != 1)
252
+ argument_error(__FILE__, __LINE__);
253
+
254
+ return value_to<Rays::ColorSpace&>(*argv, convert);
255
+ }
256
+
257
+
258
+ template <> Rays::ColorSpaceType
259
+ value_to<Rays::ColorSpaceType> (Value value, bool convert)
260
+ {
261
+ return (Rays::ColorSpaceType) value_to<uint>(value, convert);
262
+ }
263
+
264
+
265
+ }// Rucy
266
+
267
+
174
268
  namespace Rays
175
269
  {
176
270