rays 0.1.47 → 0.1.49

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/bitmap.cpp +287 -46
  3. data/.doc/ext/rays/camera.cpp +2 -2
  4. data/.doc/ext/rays/color.cpp +11 -0
  5. data/.doc/ext/rays/defs.cpp +32 -8
  6. data/.doc/ext/rays/font.cpp +50 -2
  7. data/.doc/ext/rays/image.cpp +3 -3
  8. data/.doc/ext/rays/matrix.cpp +65 -7
  9. data/.doc/ext/rays/native.cpp +2 -4
  10. data/.doc/ext/rays/painter.cpp +117 -9
  11. data/.doc/ext/rays/point.cpp +1 -11
  12. data/.doc/ext/rays/polygon.cpp +133 -97
  13. data/.doc/ext/rays/polyline.cpp +89 -10
  14. data/.doc/ext/rays/rays.cpp +80 -0
  15. data/.doc/ext/rays/{noise.cpp → util.cpp} +2 -2
  16. data/ChangeLog.md +46 -0
  17. data/VERSION +1 -1
  18. data/ext/rays/bitmap.cpp +288 -46
  19. data/ext/rays/camera.cpp +2 -2
  20. data/ext/rays/color.cpp +13 -1
  21. data/ext/rays/defs.cpp +32 -8
  22. data/ext/rays/defs.h +56 -3
  23. data/ext/rays/font.cpp +56 -4
  24. data/ext/rays/image.cpp +3 -3
  25. data/ext/rays/matrix.cpp +69 -7
  26. data/ext/rays/native.cpp +2 -4
  27. data/ext/rays/painter.cpp +132 -13
  28. data/ext/rays/point.cpp +1 -12
  29. data/ext/rays/polygon.cpp +136 -99
  30. data/ext/rays/polyline.cpp +95 -9
  31. data/ext/rays/rays.cpp +80 -0
  32. data/ext/rays/{noise.cpp → util.cpp} +2 -2
  33. data/include/rays/color.h +3 -1
  34. data/include/rays/defs.h +24 -26
  35. data/include/rays/font.h +17 -3
  36. data/include/rays/image.h +1 -1
  37. data/include/rays/matrix.h +24 -0
  38. data/include/rays/painter.h +24 -0
  39. data/include/rays/polygon.h +68 -43
  40. data/include/rays/polyline.h +17 -2
  41. data/include/rays/ruby/polygon.h +0 -11
  42. data/include/rays/ruby/rays.h +4 -0
  43. data/include/rays/{noise.h → util.h} +2 -2
  44. data/lib/rays/color.rb +7 -1
  45. data/lib/rays/font.rb +1 -1
  46. data/lib/rays/image.rb +11 -1
  47. data/lib/rays/matrix.rb +16 -0
  48. data/lib/rays/painter.rb +18 -7
  49. data/lib/rays/point.rb +5 -1
  50. data/lib/rays/polygon.rb +44 -35
  51. data/lib/rays/polyline.rb +54 -8
  52. data/lib/rays.rb +0 -1
  53. data/rays.gemspec +2 -2
  54. data/src/color.cpp +11 -2
  55. data/src/font.cpp +37 -18
  56. data/src/font.h +6 -5
  57. data/src/image.cpp +58 -14
  58. data/src/ios/font.mm +89 -32
  59. data/src/ios/helper.h +2 -2
  60. data/src/ios/helper.mm +2 -2
  61. data/src/matrix.cpp +45 -0
  62. data/src/osx/font.mm +93 -33
  63. data/src/osx/helper.h +2 -2
  64. data/src/osx/helper.mm +2 -2
  65. data/src/painter.cpp +246 -114
  66. data/src/painter.h +11 -3
  67. data/src/polygon.cpp +431 -332
  68. data/src/polyline.cpp +138 -27
  69. data/src/polyline.h +3 -5
  70. data/src/shader.cpp +36 -4
  71. data/src/shader.h +1 -1
  72. data/src/texture.cpp +23 -4
  73. data/src/texture.h +2 -0
  74. data/src/{noise.cpp → util.cpp} +1 -1
  75. data/src/win32/font.cpp +1 -1
  76. data/test/test_bitmap.rb +12 -5
  77. data/test/test_color.rb +25 -4
  78. data/test/test_font.rb +23 -2
  79. data/test/test_image.rb +44 -18
  80. data/test/test_matrix.rb +22 -0
  81. data/test/test_painter.rb +27 -0
  82. data/test/test_point.rb +1 -1
  83. data/test/test_polygon.rb +52 -45
  84. data/test/test_polyline.rb +191 -72
  85. metadata +12 -18
  86. data/.doc/ext/rays/polygon_line.cpp +0 -97
  87. data/ext/rays/polygon_line.cpp +0 -100
  88. data/lib/rays/polygon_line.rb +0 -33
  89. data/test/test_polygon_line.rb +0 -164
data/ext/rays/bitmap.cpp CHANGED
@@ -72,6 +72,257 @@ RUCY_DEF0(color_space)
72
72
  }
73
73
  RUCY_END
74
74
 
75
+ static void
76
+ set_pixels (Rays::Bitmap* bmp, Value pixels)
77
+ {
78
+ int w = bmp->width(), h = bmp->height();
79
+ const auto& cs = bmp->color_space();
80
+ if (pixels.size() != (w * h * (cs.is_float() ? cs.Bpp() / cs.Bpc() : 1)))
81
+ {
82
+ argument_error(
83
+ __FILE__, __LINE__,
84
+ "The size of the pixel array does not match the size of the bitmap");
85
+ }
86
+
87
+ const Value* array = pixels.as_array();
88
+
89
+ switch (cs.type())
90
+ {
91
+ case Rays::GRAY_8:
92
+ case Rays::ALPHA_8:
93
+ for (int y = 0; y < h; ++y)
94
+ {
95
+ const Value* pa = &array[w * y];
96
+ auto* pb = bmp->at<uint8_t>(0, y);
97
+ for (int x = 0; x < w; ++x, ++pa, ++pb)
98
+ *pb = to<uint8_t>(*pa);
99
+ }
100
+ break;
101
+
102
+ case Rays::GRAY_16:
103
+ case Rays::ALPHA_16:
104
+ for (int y = 0; y < h; ++y)
105
+ {
106
+ const Value* pa = &array[w * y];
107
+ auto* pb = bmp->at<uint16_t>(0, y);
108
+ for (int x = 0; x < w; ++x, ++pa, ++pb)
109
+ *pb = to<uint16_t>(*pa);
110
+ }
111
+ break;
112
+
113
+ case Rays::GRAY_32:
114
+ case Rays::ALPHA_32:
115
+ for (int y = 0; y < h; ++y)
116
+ {
117
+ const Value* pa = &array[w * y];
118
+ auto* pb = bmp->at<uint32_t>(0, y);
119
+ for (int x = 0; x < w; ++x, ++pa, ++pb)
120
+ *pb = to<uint32_t>(*pa);
121
+ }
122
+ break;
123
+
124
+ case Rays::GRAY_float:
125
+ case Rays::ALPHA_float:
126
+ for (int y = 0; y < h; ++y)
127
+ {
128
+ const Value* pa = &array[w * y];
129
+ auto* pb = bmp->at<float>(0, y);
130
+ for (int x = 0; x < w; ++x, ++pa, ++pb)
131
+ *pb = to<float>(*pa);
132
+ }
133
+ break;
134
+
135
+ case Rays::RGB_888:
136
+ for (int y = 0; y < h; ++y)
137
+ {
138
+ const Value* pa = &array[w * y];
139
+ auto* pb = bmp->at<uint8_t>(0, y);
140
+ for (int x = 0; x < w; ++x, ++pa, pb += 3)
141
+ {
142
+ uint32_t argb = to<uint32_t>(*pa);
143
+ pb[0] = (uint8_t) (argb >> 16 & 0xff);
144
+ pb[1] = (uint8_t) (argb >> 8 & 0xff);
145
+ pb[2] = (uint8_t) (argb >> 0 & 0xff);
146
+ }
147
+ }
148
+ break;
149
+
150
+ case Rays::RGBA_8888:
151
+ case Rays::RGBX_8888:
152
+ for (int y = 0; y < h; ++y)
153
+ {
154
+ const Value* pa = &array[w * y];
155
+ auto* pb = bmp->at<uint8_t>(0, y);
156
+ for (int x = 0; x < w; ++x, ++pa, pb += 4)
157
+ {
158
+ uint32_t argb = to<uint32_t>(*pa);
159
+ pb[0] = (uint8_t) (argb >> 16 & 0xff);
160
+ pb[1] = (uint8_t) (argb >> 8 & 0xff);
161
+ pb[2] = (uint8_t) (argb >> 0 & 0xff);
162
+ pb[3] = (uint8_t) (argb >> 24 & 0xff);
163
+ }
164
+ }
165
+ break;
166
+
167
+ case Rays::ARGB_8888:
168
+ case Rays::XRGB_8888:
169
+ for (int y = 0; y < h; ++y)
170
+ {
171
+ const Value* pa = &array[w * y];
172
+ auto* pb = bmp->at<uint8_t>(0, y);
173
+ for (int x = 0; x < w; ++x, ++pa, pb += 4)
174
+ {
175
+ uint32_t argb = to<uint32_t>(*pa);
176
+ pb[0] = (uint8_t) (argb >> 24 & 0xff);
177
+ pb[1] = (uint8_t) (argb >> 16 & 0xff);
178
+ pb[2] = (uint8_t) (argb >> 8 & 0xff);
179
+ pb[3] = (uint8_t) (argb >> 0 & 0xff);
180
+ }
181
+ }
182
+ break;
183
+
184
+ case Rays::BGR_888:
185
+ for (int y = 0; y < h; ++y)
186
+ {
187
+ const Value* pa = &array[w * y];
188
+ auto* pb = bmp->at<uint8_t>(0, y);
189
+ for (int x = 0; x < w; ++x, ++pa, pb += 3)
190
+ {
191
+ uint32_t argb = to<uint32_t>(*pa);
192
+ pb[0] = (uint8_t) (argb >> 0 & 0xff);
193
+ pb[1] = (uint8_t) (argb >> 8 & 0xff);
194
+ pb[2] = (uint8_t) (argb >> 16 & 0xff);
195
+ }
196
+ }
197
+ break;
198
+
199
+ case Rays::BGRA_8888:
200
+ case Rays::BGRX_8888:
201
+ for (int y = 0; y < h; ++y)
202
+ {
203
+ const Value* pa = &array[w * y];
204
+ auto* pb = bmp->at<uint8_t>(0, y);
205
+ for (int x = 0; x < w; ++x, ++pa, pb += 4)
206
+ {
207
+ uint32_t argb = to<uint32_t>(*pa);
208
+ pb[0] = (uint8_t) (argb >> 0 & 0xff);
209
+ pb[1] = (uint8_t) (argb >> 8 & 0xff);
210
+ pb[2] = (uint8_t) (argb >> 16 & 0xff);
211
+ pb[3] = (uint8_t) (argb >> 24 & 0xff);
212
+ }
213
+ }
214
+ break;
215
+
216
+ case Rays::ABGR_8888:
217
+ case Rays::XBGR_8888:
218
+ for (int y = 0; y < h; ++y)
219
+ {
220
+ const Value* pa = &array[w * y];
221
+ auto* pb = bmp->at<uint8_t>(0, y);
222
+ for (int x = 0; x < w; ++x, ++pa, pb += 4)
223
+ {
224
+ uint32_t argb = to<uint32_t>(*pa);
225
+ pb[0] = (uint8_t) (argb >> 24 & 0xff);
226
+ pb[1] = (uint8_t) (argb >> 0 & 0xff);
227
+ pb[2] = (uint8_t) (argb >> 8 & 0xff);
228
+ pb[3] = (uint8_t) (argb >> 16 & 0xff);
229
+ }
230
+ }
231
+ break;
232
+
233
+ case Rays::RGB_float:
234
+ for (int y = 0; y < h; ++y)
235
+ {
236
+ const Value* pa = &array[3 * w * y];
237
+ auto* pb = bmp->at<float>(0, y);
238
+ for (int x = 0; x < w; ++x, pa += 3, pb += 3)
239
+ {
240
+ pb[0] = to<float>(pa[0]);
241
+ pb[1] = to<float>(pa[1]);
242
+ pb[2] = to<float>(pa[2]);
243
+ }
244
+ }
245
+ break;
246
+
247
+ case Rays::RGBA_float:
248
+ for (int y = 0; y < h; ++y)
249
+ {
250
+ const Value* pa = &array[4 * w * y];
251
+ auto* pb = bmp->at<float>(0, y);
252
+ for (int x = 0; x < w; ++x, pa += 4, pb += 4)
253
+ {
254
+ pb[0] = to<float>(pa[0]);
255
+ pb[1] = to<float>(pa[1]);
256
+ pb[2] = to<float>(pa[2]);
257
+ pb[3] = to<float>(pa[3]);
258
+ }
259
+ }
260
+ break;
261
+
262
+ case Rays::ARGB_float:
263
+ for (int y = 0; y < h; ++y)
264
+ {
265
+ const Value* pa = &array[4 * w * y];
266
+ auto* pb = bmp->at<float>(0, y);
267
+ for (int x = 0; x < w; ++x, pa += 4, pb += 4)
268
+ {
269
+ pb[0] = to<float>(pa[3]);
270
+ pb[1] = to<float>(pa[0]);
271
+ pb[2] = to<float>(pa[1]);
272
+ pb[3] = to<float>(pa[2]);
273
+ }
274
+ }
275
+ break;
276
+
277
+ case Rays::BGR_float:
278
+ for (int y = 0; y < h; ++y)
279
+ {
280
+ const Value* pa = &array[3 * w * y];
281
+ auto* pb = bmp->at<float>(0, y);
282
+ for (int x = 0; x < w; ++x, pa += 3, pb += 3)
283
+ {
284
+ pb[0] = to<float>(pa[2]);
285
+ pb[1] = to<float>(pa[1]);
286
+ pb[2] = to<float>(pa[0]);
287
+ }
288
+ }
289
+ break;
290
+
291
+ case Rays::BGRA_float:
292
+ for (int y = 0; y < h; ++y)
293
+ {
294
+ const Value* pa = &array[4 * w * y];
295
+ auto* pb = bmp->at<float>(0, y);
296
+ for (int x = 0; x < w; ++x, pa += 4, pb += 4)
297
+ {
298
+ pb[0] = to<float>(pa[2]);
299
+ pb[1] = to<float>(pa[1]);
300
+ pb[2] = to<float>(pa[0]);
301
+ pb[3] = to<float>(pa[3]);
302
+ }
303
+ }
304
+ break;
305
+
306
+ case Rays::ABGR_float:
307
+ for (int y = 0; y < h; ++y)
308
+ {
309
+ const Value* pa = &array[4 * w * y];
310
+ auto* pb = bmp->at<float>(0, y);
311
+ for (int x = 0; x < w; ++x, pa += 4, pb += 4)
312
+ {
313
+ pb[0] = to<float>(pa[3]);
314
+ pb[1] = to<float>(pa[2]);
315
+ pb[2] = to<float>(pa[1]);
316
+ pb[3] = to<float>(pa[0]);
317
+ }
318
+ }
319
+ break;
320
+
321
+ default:
322
+ argument_error(__FILE__, __LINE__);
323
+ }
324
+ }
325
+
75
326
  static inline Value
76
327
  to_rgb_value (uint8_t r, uint8_t g, uint8_t b)
77
328
  {
@@ -82,7 +333,7 @@ to_rgb_value (uint8_t r, uint8_t g, uint8_t b)
82
333
  }
83
334
 
84
335
  static inline Value
85
- to_rgba_value (uint8_t r, uint8_t g, uint8_t b, uint8_t a)
336
+ to_argb_value (uint8_t r, uint8_t g, uint8_t b, uint8_t a)
86
337
  {
87
338
  return value(
88
339
  ((uint) a) << 24 |
@@ -95,8 +346,8 @@ static void
95
346
  get_pixels (auto* pixels, const Rays::Bitmap& bmp)
96
347
  {
97
348
  int w = bmp.width(), h = bmp.height();
98
-
99
349
  const auto& cs = bmp.color_space();
350
+
100
351
  pixels->clear();
101
352
  pixels->reserve(w * h * (cs.is_float() ? cs.Bpp() / cs.Bpc() : 1));
102
353
 
@@ -152,38 +403,22 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
152
403
  break;
153
404
 
154
405
  case Rays::RGBA_8888:
155
- for (int y = 0; y < h; ++y)
156
- {
157
- const auto* p = bmp.at<uint8_t>(0, y);
158
- for (int x = 0; x < w; ++x, p += 4)
159
- pixels->push_back(to_rgba_value(p[0], p[1], p[2], p[3]));
160
- }
161
- break;
162
-
163
406
  case Rays::RGBX_8888:
164
407
  for (int y = 0; y < h; ++y)
165
408
  {
166
409
  const auto* p = bmp.at<uint8_t>(0, y);
167
410
  for (int x = 0; x < w; ++x, p += 4)
168
- pixels->push_back(to_rgb_value(p[0], p[1], p[2]));
411
+ pixels->push_back(to_argb_value(p[0], p[1], p[2], p[3]));
169
412
  }
170
413
  break;
171
414
 
172
415
  case Rays::ARGB_8888:
173
- for (int y = 0; y < h; ++y)
174
- {
175
- const auto* p = bmp.at<uint8_t>(0, y);
176
- for (int x = 0; x < w; ++x, p += 4)
177
- pixels->push_back(to_rgba_value(p[1], p[2], p[3], p[0]));
178
- }
179
- break;
180
-
181
416
  case Rays::XRGB_8888:
182
417
  for (int y = 0; y < h; ++y)
183
418
  {
184
419
  const auto* p = bmp.at<uint8_t>(0, y);
185
420
  for (int x = 0; x < w; ++x, p += 4)
186
- pixels->push_back(to_rgb_value(p[1], p[2], p[3]));
421
+ pixels->push_back(to_argb_value(p[1], p[2], p[3], p[0]));
187
422
  }
188
423
  break;
189
424
 
@@ -197,45 +432,29 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
197
432
  break;
198
433
 
199
434
  case Rays::BGRA_8888:
200
- for (int y = 0; y < h; ++y)
201
- {
202
- const auto* p = bmp.at<uint8_t>(0, y);
203
- for (int x = 0; x < w; ++x, p += 4)
204
- pixels->push_back(to_rgba_value(p[2], p[1], p[0], p[3]));
205
- }
206
- break;
207
-
208
435
  case Rays::BGRX_8888:
209
436
  for (int y = 0; y < h; ++y)
210
437
  {
211
438
  const auto* p = bmp.at<uint8_t>(0, y);
212
439
  for (int x = 0; x < w; ++x, p += 4)
213
- pixels->push_back(to_rgb_value(p[2], p[1], p[0]));
440
+ pixels->push_back(to_argb_value(p[2], p[1], p[0], p[3]));
214
441
  }
215
442
  break;
216
443
 
217
444
  case Rays::ABGR_8888:
218
- for (int y = 0; y < h; ++y)
219
- {
220
- const auto* p = bmp.at<uint8_t>(0, y);
221
- for (int x = 0; x < w; ++x, p += 4)
222
- pixels->push_back(to_rgba_value(p[3], p[2], p[1], p[0]));
223
- }
224
- break;
225
-
226
445
  case Rays::XBGR_8888:
227
446
  for (int y = 0; y < h; ++y)
228
447
  {
229
448
  const auto* p = bmp.at<uint8_t>(0, y);
230
449
  for (int x = 0; x < w; ++x, p += 4)
231
- pixels->push_back(to_rgb_value(p[3], p[2], p[1]));
450
+ pixels->push_back(to_argb_value(p[3], p[2], p[1], p[0]));
232
451
  }
233
452
  break;
234
453
 
235
454
  case Rays::RGB_float:
236
455
  for (int y = 0; y < h; ++y)
237
456
  {
238
- const auto* p = bmp.at<uint8_t>(0, y);
457
+ const auto* p = bmp.at<float>(0, y);
239
458
  for (int x = 0; x < w; ++x, p += 3)
240
459
  {
241
460
  pixels->push_back(value(p[0]));
@@ -248,7 +467,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
248
467
  case Rays::RGBA_float:
249
468
  for (int y = 0; y < h; ++y)
250
469
  {
251
- const auto* p = bmp.at<uint8_t>(0, y);
470
+ const auto* p = bmp.at<float>(0, y);
252
471
  for (int x = 0; x < w; ++x, p += 4)
253
472
  {
254
473
  pixels->push_back(value(p[0]));
@@ -262,7 +481,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
262
481
  case Rays::ARGB_float:
263
482
  for (int y = 0; y < h; ++y)
264
483
  {
265
- const auto* p = bmp.at<uint8_t>(0, y);
484
+ const auto* p = bmp.at<float>(0, y);
266
485
  for (int x = 0; x < w; ++x, p += 4)
267
486
  {
268
487
  pixels->push_back(value(p[1]));
@@ -276,7 +495,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
276
495
  case Rays::BGR_float:
277
496
  for (int y = 0; y < h; ++y)
278
497
  {
279
- const auto* p = bmp.at<uint8_t>(0, y);
498
+ const auto* p = bmp.at<float>(0, y);
280
499
  for (int x = 0; x < w; ++x, p += 3)
281
500
  {
282
501
  pixels->push_back(value(p[2]));
@@ -289,7 +508,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
289
508
  case Rays::BGRA_float:
290
509
  for (int y = 0; y < h; ++y)
291
510
  {
292
- const auto* p = bmp.at<uint8_t>(0, y);
511
+ const auto* p = bmp.at<float>(0, y);
293
512
  for (int x = 0; x < w; ++x, p += 4)
294
513
  {
295
514
  pixels->push_back(value(p[2]));
@@ -303,7 +522,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
303
522
  case Rays::ABGR_float:
304
523
  for (int y = 0; y < h; ++y)
305
524
  {
306
- const auto* p = bmp.at<uint8_t>(0, y);
525
+ const auto* p = bmp.at<float>(0, y);
307
526
  for (int x = 0; x < w; ++x, p += 4)
308
527
  {
309
528
  pixels->push_back(value(p[3]));
@@ -320,10 +539,32 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
320
539
  }
321
540
 
322
541
  static
323
- RUCY_DEF0(pixels)
542
+ RUCY_DEF1(set_pixels, pixels)
543
+ {
544
+ CHECK;
545
+
546
+ if (sizeof(VALUE) <= 4)
547
+ {
548
+ not_implemented_error(
549
+ __FILE__, __LINE__, "Bitmap#pixels=() does not support 32-bit platforms");
550
+ }
551
+
552
+ set_pixels(THIS, pixels);
553
+ return pixels;
554
+ }
555
+ RUCY_END
556
+
557
+ static
558
+ RUCY_DEF0(get_pixels)
324
559
  {
325
560
  CHECK;
326
561
 
562
+ if (sizeof(VALUE) <= 4)
563
+ {
564
+ not_implemented_error(
565
+ __FILE__, __LINE__, "Bitmap#pixels() does not support 32-bit platforms");
566
+ }
567
+
327
568
  std::vector<VALUE> pixels;
328
569
  get_pixels(&pixels, *THIS);
329
570
  return value(pixels.size(), (const Value*) &pixels[0]);
@@ -371,7 +612,8 @@ Init_rays_bitmap ()
371
612
  cBitmap.define_method("width", width);
372
613
  cBitmap.define_method("height", height);
373
614
  cBitmap.define_method("color_space", color_space);
374
- cBitmap.define_method("pixels", pixels);
615
+ cBitmap.define_method("pixels=", set_pixels);
616
+ cBitmap.define_method("pixels", get_pixels);
375
617
  cBitmap.define_method("[]=", set_at);
376
618
  cBitmap.define_method("[]", get_at);
377
619
  }
data/ext/rays/camera.cpp CHANGED
@@ -139,8 +139,8 @@ RUCY_DEF0(device_names)
139
139
  auto names = Rays::get_camera_device_names();
140
140
 
141
141
  std::vector<Value> v;
142
- for (auto it = names.begin(), end = names.end(); it != end; ++it)
143
- v.emplace_back(value(it->c_str()));
142
+ for (const auto& name : names)
143
+ v.emplace_back(name.c_str());
144
144
  return value(v.size(), &v[0]);
145
145
  }
146
146
  RUCY_END
data/ext/rays/color.cpp CHANGED
@@ -114,6 +114,17 @@ RUCY_DEF0(get_alpha)
114
114
  }
115
115
  RUCY_END
116
116
 
117
+ static
118
+ RUCY_DEF0(to_hsv)
119
+ {
120
+ CHECK;
121
+
122
+ float h, s, v;
123
+ Rays::get_hsv(&h, &s, &v, *THIS);
124
+ return array(h, s, v, THIS->alpha);
125
+ }
126
+ RUCY_END
127
+
117
128
 
118
129
  typedef std::map<Rays::String, Rays::Color> ColorMap;
119
130
 
@@ -212,7 +223,8 @@ Init_rays_color ()
212
223
  cColor.define_method("blue", get_blue);
213
224
  cColor.define_method("alpha=", set_alpha);
214
225
  cColor.define_method("alpha", get_alpha);
215
- cColor.define_module_function("hsv", hsv);
226
+ cColor.define_method( "to_hsv", to_hsv);
227
+ cColor.define_module_function("hsv", hsv);
216
228
  cColor.define_module_function("set_palette_color", set_palette_color);
217
229
  }
218
230
 
data/ext/rays/defs.cpp CHANGED
@@ -1,16 +1,14 @@
1
1
  #include "defs.h"
2
2
 
3
3
 
4
- #include <assert.h>
5
4
  #include "rays/ruby/bounds.h"
5
+ #include "rays/ruby/color.h"
6
6
  #include "rays/ruby/point.h"
7
7
 
8
8
 
9
9
  void
10
- get_line_args (std::vector<Rays::Point>* points, int argc, const Value* argv)
10
+ get_points (std::vector<Rays::Point>* points, int argc, const Value* argv)
11
11
  {
12
- assert(points && argv);
13
-
14
12
  points->clear();
15
13
 
16
14
  if (argc <= 0)
@@ -37,6 +35,36 @@ get_line_args (std::vector<Rays::Point>* points, int argc, const Value* argv)
37
35
  }
38
36
  }
39
37
 
38
+ void
39
+ get_colors (std::vector<Rays::Color>* colors, int argc, const Value* argv)
40
+ {
41
+ colors->clear();
42
+
43
+ if (argc <= 0)
44
+ return;
45
+
46
+ if (argv[0].is_num())
47
+ {
48
+ if (argc % 3 != 0)
49
+ argument_error(__FILE__, __LINE__);
50
+
51
+ colors->reserve(argc / 3);
52
+ for (int i = 0; i < argc; i += 3)
53
+ {
54
+ colors->emplace_back(
55
+ to<float>(argv[i + 0]),
56
+ to<float>(argv[i + 1]),
57
+ to<float>(argv[i + 2]));
58
+ }
59
+ }
60
+ else
61
+ {
62
+ colors->reserve(argc);
63
+ for (int i = 0; i < argc; ++i)
64
+ colors->emplace_back(to<Rays::Color>(argv[i]));
65
+ }
66
+ }
67
+
40
68
  static uint
41
69
  get_nsegment (Value nsegment)
42
70
  {
@@ -53,8 +81,6 @@ void get_rect_args (
53
81
  Value round, Value lefttop, Value righttop, Value leftbottom, Value rightbottom,
54
82
  Value nsegment)
55
83
  {
56
- assert(x && y && w && h && lt && rt && lb && rb && nseg && argv);
57
-
58
84
  if (argc <= 0)
59
85
  argument_error(__FILE__, __LINE__);
60
86
 
@@ -124,8 +150,6 @@ void get_ellipse_args (
124
150
  Value center, Value radius, Value hole, Value angle_from, Value angle_to,
125
151
  Value nsegment)
126
152
  {
127
- assert(x && y && w && h && hole_size && from && to_ && nseg && argv);
128
-
129
153
  if (argc <= 0)
130
154
  {
131
155
  *x = *y = *w = *h = 0;
data/ext/rays/defs.h CHANGED
@@ -7,6 +7,7 @@
7
7
  #include <vector>
8
8
  #include <rucy.h>
9
9
  #include "rays/defs.h"
10
+ #include "rays/color.h"
10
11
  #include "rays/point.h"
11
12
  #include "rays/ruby/defs.h"
12
13
 
@@ -16,9 +17,9 @@ using namespace Rucy;
16
17
  using Rays::coord;
17
18
 
18
19
 
19
- void get_line_args (
20
- std::vector<Rays::Point>* points,
21
- int argc, const Value* argv);
20
+ void get_points (std::vector<Rays::Point>* points, int argc, const Value* argv);
21
+
22
+ void get_colors (std::vector<Rays::Color>* colors, int argc, const Value* argv);
22
23
 
23
24
  void get_rect_args (
24
25
  coord* x, coord* y, coord* w, coord* h,
@@ -35,4 +36,56 @@ void get_ellipse_args (
35
36
  Value nsegment);
36
37
 
37
38
 
39
+ struct CreateParams
40
+ {
41
+
42
+ std::vector<Rays::Point> points;
43
+
44
+ std::vector<Rays::Color> colors;
45
+
46
+ std::vector<Rays::Point> texcoords;
47
+
48
+ CreateParams (
49
+ const Value& points_, const Value& colors_, const Value& texcoords_)
50
+ {
51
+ get_points(&points, points_.size(), points_.as_array());
52
+
53
+ if (colors_)
54
+ {
55
+ get_colors(&colors, colors_.size(), colors_.as_array());
56
+ if (colors.size() != points.size())
57
+ argument_error(__FILE__, __LINE__, "colors.size() != points.size()");
58
+ }
59
+
60
+ if (texcoords_)
61
+ {
62
+ get_points(&texcoords, texcoords_.size(), texcoords_.as_array());
63
+ if (texcoords.size() != points.size())
64
+ argument_error(__FILE__, __LINE__, "texcoords.size() != points.size()");
65
+ }
66
+ }
67
+
68
+ const Rays::Point* ppoints () const
69
+ {
70
+ return points.empty() ? NULL : &points[0];
71
+ }
72
+
73
+ const Rays::Color* pcolors () const
74
+ {
75
+ return colors.empty() ? NULL : &colors[0];
76
+ }
77
+
78
+ const Rays::Point* ptexcoords () const
79
+ {
80
+ return texcoords.empty() ? NULL : &texcoords[0];
81
+ }
82
+
83
+ size_t size () const
84
+ {
85
+ return points.size();
86
+ }
87
+
88
+ };// CreateParams
89
+
90
+
38
91
  #endif//EOH