rays 0.1.46 → 0.1.48

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/bitmap.cpp +499 -0
  3. data/.doc/ext/rays/camera.cpp +2 -2
  4. data/.doc/ext/rays/defs.cpp +35 -11
  5. data/.doc/ext/rays/font.cpp +50 -2
  6. data/.doc/ext/rays/native.cpp +2 -4
  7. data/.doc/ext/rays/painter.cpp +111 -6
  8. data/.doc/ext/rays/polygon.cpp +152 -41
  9. data/.doc/ext/rays/polyline.cpp +89 -10
  10. data/.doc/ext/rays/rays.cpp +91 -11
  11. data/.doc/ext/rays/{noise.cpp → util.cpp} +2 -2
  12. data/.github/workflows/test.yml +0 -1
  13. data/ChangeLog.md +38 -0
  14. data/Rakefile +4 -4
  15. data/VERSION +1 -1
  16. data/ext/rays/bitmap.cpp +501 -0
  17. data/ext/rays/camera.cpp +2 -2
  18. data/ext/rays/defs.cpp +35 -11
  19. data/ext/rays/defs.h +56 -3
  20. data/ext/rays/font.cpp +56 -4
  21. data/ext/rays/native.cpp +2 -4
  22. data/ext/rays/painter.cpp +125 -11
  23. data/ext/rays/polygon.cpp +161 -41
  24. data/ext/rays/polyline.cpp +95 -9
  25. data/ext/rays/rays.cpp +91 -11
  26. data/ext/rays/{noise.cpp → util.cpp} +2 -2
  27. data/include/rays/defs.h +24 -0
  28. data/include/rays/font.h +17 -3
  29. data/include/rays/matrix.h +2 -0
  30. data/include/rays/painter.h +29 -1
  31. data/include/rays/polygon.h +57 -33
  32. data/include/rays/polyline.h +20 -1
  33. data/include/rays/ruby/polygon.h +0 -11
  34. data/include/rays/ruby/rays.h +4 -0
  35. data/include/rays/{noise.h → util.h} +2 -2
  36. data/lib/rays/color.rb +1 -1
  37. data/lib/rays/font.rb +1 -1
  38. data/lib/rays/image.rb +1 -1
  39. data/lib/rays/painter.rb +13 -2
  40. data/lib/rays/point.rb +1 -1
  41. data/lib/rays/polygon.rb +54 -16
  42. data/lib/rays/polyline.rb +54 -8
  43. data/lib/rays.rb +0 -1
  44. data/rays.gemspec +2 -2
  45. data/src/color_space.cpp +2 -2
  46. data/src/font.cpp +24 -2
  47. data/src/font.h +8 -1
  48. data/src/ios/font.mm +88 -27
  49. data/src/matrix.cpp +8 -0
  50. data/src/osx/font.mm +90 -28
  51. data/src/osx/helper.h +2 -2
  52. data/src/osx/helper.mm +2 -2
  53. data/src/painter.cpp +227 -90
  54. data/src/painter.h +11 -3
  55. data/src/polygon.cpp +588 -205
  56. data/src/polyline.cpp +154 -28
  57. data/src/polyline.h +3 -5
  58. data/src/shader.cpp +36 -4
  59. data/src/shader.h +1 -1
  60. data/src/texture.cpp +2 -2
  61. data/src/{noise.cpp → util.cpp} +1 -1
  62. data/src/win32/font.cpp +1 -1
  63. data/test/test_bitmap.rb +16 -2
  64. data/test/test_color.rb +4 -0
  65. data/test/test_font.rb +20 -2
  66. data/test/test_image.rb +18 -18
  67. data/test/test_point.rb +1 -1
  68. data/test/test_polygon.rb +52 -45
  69. data/test/test_polyline.rb +191 -72
  70. metadata +11 -17
  71. data/.doc/ext/rays/polygon_line.cpp +0 -97
  72. data/ext/rays/polygon_line.cpp +0 -100
  73. data/lib/rays/polygon_line.rb +0 -33
  74. data/test/test_polygon_line.rb +0 -164
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4232c9c8e77b4d6e9d3a60a283934c268baade87875d0bf7ce2f6ee7f4e53aa8
4
- data.tar.gz: d8931fbc4a860a97425e56f716ac995ff5c51e5b7c2cc4bca160eda184007706
3
+ metadata.gz: 0da22dbb538f841d5c21371e0b0749479467b1c0746bbd459118b649c66678e0
4
+ data.tar.gz: f55580763f45ce98198c59f6fe9ed86ac21f64aba8d16cf8b002923650c9b703
5
5
  SHA512:
6
- metadata.gz: 735f49b98489b5a3da4bacb0e501b28410aa67954875185eef2515eaa90112573bee44762bbfd9d1489eaeae06f8543fb02a945d177e901eb5f33c5c90811d35
7
- data.tar.gz: ba69b4be7967c303fb8cf0cee65f804be444e7ce426c3d2ea0e337fd8a86837ac95e6011d847c238f8a6c520a81a924c8783b1476040c311080e6ac4f4b72ba8
6
+ metadata.gz: d74814adfebbb7b9f0449abeebab017a475c76ae48a61c4f2f066e12a376fe52279db08cb6a27c3a3cadd26ae9179ce7fb204c59eff8440f9569121711d3a26e
7
+ data.tar.gz: 74e423c7faa9747f34e7e37737882fffce493e127fb5870a7e6a2fb0d4cc6f122a3cac43d9afa96373a6ce69f147198007db9d958a93d478cd4d5f1a9441053b
@@ -66,6 +66,503 @@ VALUE color_space(VALUE self)
66
66
  return value(THIS->color_space());
67
67
  }
68
68
 
69
+ static void
70
+ set_pixels (Rays::Bitmap* bmp, Value pixels)
71
+ {
72
+ int w = bmp->width(), h = bmp->height();
73
+ const auto& cs = bmp->color_space();
74
+ if (pixels.size() != (w * h * (cs.is_float() ? cs.Bpp() / cs.Bpc() : 1)))
75
+ {
76
+ argument_error(
77
+ __FILE__, __LINE__,
78
+ "The size of the pixel array does not match the size of the bitmap");
79
+ }
80
+
81
+ const Value* array = pixels.as_array();
82
+
83
+ switch (cs.type())
84
+ {
85
+ case Rays::GRAY_8:
86
+ case Rays::ALPHA_8:
87
+ for (int y = 0; y < h; ++y)
88
+ {
89
+ const Value* pa = &array[w * y];
90
+ auto* pb = bmp->at<uint8_t>(0, y);
91
+ for (int x = 0; x < w; ++x, ++pa, ++pb)
92
+ *pb = to<uint8_t>(*pa);
93
+ }
94
+ break;
95
+
96
+ case Rays::GRAY_16:
97
+ case Rays::ALPHA_16:
98
+ for (int y = 0; y < h; ++y)
99
+ {
100
+ const Value* pa = &array[w * y];
101
+ auto* pb = bmp->at<uint16_t>(0, y);
102
+ for (int x = 0; x < w; ++x, ++pa, ++pb)
103
+ *pb = to<uint16_t>(*pa);
104
+ }
105
+ break;
106
+
107
+ case Rays::GRAY_32:
108
+ case Rays::ALPHA_32:
109
+ for (int y = 0; y < h; ++y)
110
+ {
111
+ const Value* pa = &array[w * y];
112
+ auto* pb = bmp->at<uint32_t>(0, y);
113
+ for (int x = 0; x < w; ++x, ++pa, ++pb)
114
+ *pb = to<uint32_t>(*pa);
115
+ }
116
+ break;
117
+
118
+ case Rays::GRAY_float:
119
+ case Rays::ALPHA_float:
120
+ for (int y = 0; y < h; ++y)
121
+ {
122
+ const Value* pa = &array[w * y];
123
+ auto* pb = bmp->at<float>(0, y);
124
+ for (int x = 0; x < w; ++x, ++pa, ++pb)
125
+ *pb = to<float>(*pa);
126
+ }
127
+ break;
128
+
129
+ case Rays::RGB_888:
130
+ for (int y = 0; y < h; ++y)
131
+ {
132
+ const Value* pa = &array[w * y];
133
+ auto* pb = bmp->at<uint8_t>(0, y);
134
+ for (int x = 0; x < w; ++x, ++pa, pb += 3)
135
+ {
136
+ uint32_t argb = to<uint32_t>(*pa);
137
+ pb[0] = (uint8_t) (argb >> 16 & 0xff);
138
+ pb[1] = (uint8_t) (argb >> 8 & 0xff);
139
+ pb[2] = (uint8_t) (argb >> 0 & 0xff);
140
+ }
141
+ }
142
+ break;
143
+
144
+ case Rays::RGBA_8888:
145
+ case Rays::RGBX_8888:
146
+ for (int y = 0; y < h; ++y)
147
+ {
148
+ const Value* pa = &array[w * y];
149
+ auto* pb = bmp->at<uint8_t>(0, y);
150
+ for (int x = 0; x < w; ++x, ++pa, pb += 4)
151
+ {
152
+ uint32_t argb = to<uint32_t>(*pa);
153
+ pb[0] = (uint8_t) (argb >> 16 & 0xff);
154
+ pb[1] = (uint8_t) (argb >> 8 & 0xff);
155
+ pb[2] = (uint8_t) (argb >> 0 & 0xff);
156
+ pb[3] = (uint8_t) (argb >> 24 & 0xff);
157
+ }
158
+ }
159
+ break;
160
+
161
+ case Rays::ARGB_8888:
162
+ case Rays::XRGB_8888:
163
+ for (int y = 0; y < h; ++y)
164
+ {
165
+ const Value* pa = &array[w * y];
166
+ auto* pb = bmp->at<uint8_t>(0, y);
167
+ for (int x = 0; x < w; ++x, ++pa, pb += 4)
168
+ {
169
+ uint32_t argb = to<uint32_t>(*pa);
170
+ pb[0] = (uint8_t) (argb >> 24 & 0xff);
171
+ pb[1] = (uint8_t) (argb >> 16 & 0xff);
172
+ pb[2] = (uint8_t) (argb >> 8 & 0xff);
173
+ pb[3] = (uint8_t) (argb >> 0 & 0xff);
174
+ }
175
+ }
176
+ break;
177
+
178
+ case Rays::BGR_888:
179
+ for (int y = 0; y < h; ++y)
180
+ {
181
+ const Value* pa = &array[w * y];
182
+ auto* pb = bmp->at<uint8_t>(0, y);
183
+ for (int x = 0; x < w; ++x, ++pa, pb += 3)
184
+ {
185
+ uint32_t argb = to<uint32_t>(*pa);
186
+ pb[0] = (uint8_t) (argb >> 0 & 0xff);
187
+ pb[1] = (uint8_t) (argb >> 8 & 0xff);
188
+ pb[2] = (uint8_t) (argb >> 16 & 0xff);
189
+ }
190
+ }
191
+ break;
192
+
193
+ case Rays::BGRA_8888:
194
+ case Rays::BGRX_8888:
195
+ for (int y = 0; y < h; ++y)
196
+ {
197
+ const Value* pa = &array[w * y];
198
+ auto* pb = bmp->at<uint8_t>(0, y);
199
+ for (int x = 0; x < w; ++x, ++pa, pb += 4)
200
+ {
201
+ uint32_t argb = to<uint32_t>(*pa);
202
+ pb[0] = (uint8_t) (argb >> 0 & 0xff);
203
+ pb[1] = (uint8_t) (argb >> 8 & 0xff);
204
+ pb[2] = (uint8_t) (argb >> 16 & 0xff);
205
+ pb[3] = (uint8_t) (argb >> 24 & 0xff);
206
+ }
207
+ }
208
+ break;
209
+
210
+ case Rays::ABGR_8888:
211
+ case Rays::XBGR_8888:
212
+ for (int y = 0; y < h; ++y)
213
+ {
214
+ const Value* pa = &array[w * y];
215
+ auto* pb = bmp->at<uint8_t>(0, y);
216
+ for (int x = 0; x < w; ++x, ++pa, pb += 4)
217
+ {
218
+ uint32_t argb = to<uint32_t>(*pa);
219
+ pb[0] = (uint8_t) (argb >> 24 & 0xff);
220
+ pb[1] = (uint8_t) (argb >> 0 & 0xff);
221
+ pb[2] = (uint8_t) (argb >> 8 & 0xff);
222
+ pb[3] = (uint8_t) (argb >> 16 & 0xff);
223
+ }
224
+ }
225
+ break;
226
+
227
+ case Rays::RGB_float:
228
+ for (int y = 0; y < h; ++y)
229
+ {
230
+ const Value* pa = &array[3 * w * y];
231
+ auto* pb = bmp->at<float>(0, y);
232
+ for (int x = 0; x < w; ++x, pa += 3, pb += 3)
233
+ {
234
+ pb[0] = to<float>(pa[0]);
235
+ pb[1] = to<float>(pa[1]);
236
+ pb[2] = to<float>(pa[2]);
237
+ }
238
+ }
239
+ break;
240
+
241
+ case Rays::RGBA_float:
242
+ for (int y = 0; y < h; ++y)
243
+ {
244
+ const Value* pa = &array[4 * w * y];
245
+ auto* pb = bmp->at<float>(0, y);
246
+ for (int x = 0; x < w; ++x, pa += 4, pb += 4)
247
+ {
248
+ pb[0] = to<float>(pa[0]);
249
+ pb[1] = to<float>(pa[1]);
250
+ pb[2] = to<float>(pa[2]);
251
+ pb[3] = to<float>(pa[3]);
252
+ }
253
+ }
254
+ break;
255
+
256
+ case Rays::ARGB_float:
257
+ for (int y = 0; y < h; ++y)
258
+ {
259
+ const Value* pa = &array[4 * w * y];
260
+ auto* pb = bmp->at<float>(0, y);
261
+ for (int x = 0; x < w; ++x, pa += 4, pb += 4)
262
+ {
263
+ pb[0] = to<float>(pa[3]);
264
+ pb[1] = to<float>(pa[0]);
265
+ pb[2] = to<float>(pa[1]);
266
+ pb[3] = to<float>(pa[2]);
267
+ }
268
+ }
269
+ break;
270
+
271
+ case Rays::BGR_float:
272
+ for (int y = 0; y < h; ++y)
273
+ {
274
+ const Value* pa = &array[3 * w * y];
275
+ auto* pb = bmp->at<float>(0, y);
276
+ for (int x = 0; x < w; ++x, pa += 3, pb += 3)
277
+ {
278
+ pb[0] = to<float>(pa[2]);
279
+ pb[1] = to<float>(pa[1]);
280
+ pb[2] = to<float>(pa[0]);
281
+ }
282
+ }
283
+ break;
284
+
285
+ case Rays::BGRA_float:
286
+ for (int y = 0; y < h; ++y)
287
+ {
288
+ const Value* pa = &array[4 * w * y];
289
+ auto* pb = bmp->at<float>(0, y);
290
+ for (int x = 0; x < w; ++x, pa += 4, pb += 4)
291
+ {
292
+ pb[0] = to<float>(pa[2]);
293
+ pb[1] = to<float>(pa[1]);
294
+ pb[2] = to<float>(pa[0]);
295
+ pb[3] = to<float>(pa[3]);
296
+ }
297
+ }
298
+ break;
299
+
300
+ case Rays::ABGR_float:
301
+ for (int y = 0; y < h; ++y)
302
+ {
303
+ const Value* pa = &array[4 * w * y];
304
+ auto* pb = bmp->at<float>(0, y);
305
+ for (int x = 0; x < w; ++x, pa += 4, pb += 4)
306
+ {
307
+ pb[0] = to<float>(pa[3]);
308
+ pb[1] = to<float>(pa[2]);
309
+ pb[2] = to<float>(pa[1]);
310
+ pb[3] = to<float>(pa[0]);
311
+ }
312
+ }
313
+ break;
314
+
315
+ default:
316
+ argument_error(__FILE__, __LINE__);
317
+ }
318
+ }
319
+
320
+ static inline Value
321
+ to_rgb_value (uint8_t r, uint8_t g, uint8_t b)
322
+ {
323
+ return value(
324
+ ((uint) r) << 16 |
325
+ ((uint) g) << 8 |
326
+ ((uint) b));
327
+ }
328
+
329
+ static inline Value
330
+ to_argb_value (uint8_t r, uint8_t g, uint8_t b, uint8_t a)
331
+ {
332
+ return value(
333
+ ((uint) a) << 24 |
334
+ ((uint) r) << 16 |
335
+ ((uint) g) << 8 |
336
+ ((uint) b));
337
+ }
338
+
339
+ static void
340
+ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
341
+ {
342
+ int w = bmp.width(), h = bmp.height();
343
+ const auto& cs = bmp.color_space();
344
+
345
+ pixels->clear();
346
+ pixels->reserve(w * h * (cs.is_float() ? cs.Bpp() / cs.Bpc() : 1));
347
+
348
+ switch (cs.type())
349
+ {
350
+ case Rays::GRAY_8:
351
+ case Rays::ALPHA_8:
352
+ for (int y = 0; y < h; ++y)
353
+ {
354
+ const auto* p = bmp.at<uint8_t>(0, y);
355
+ for (int x = 0; x < w; ++x, ++p)
356
+ pixels->push_back(value(*p));
357
+ }
358
+ break;
359
+
360
+ case Rays::GRAY_16:
361
+ case Rays::ALPHA_16:
362
+ for (int y = 0; y < h; ++y)
363
+ {
364
+ const auto* p = bmp.at<uint16_t>(0, y);
365
+ for (int x = 0; x < w; ++x, ++p)
366
+ pixels->push_back(value(*p));
367
+ }
368
+ break;
369
+
370
+ case Rays::GRAY_32:
371
+ case Rays::ALPHA_32:
372
+ for (int y = 0; y < h; ++y)
373
+ {
374
+ const auto* p = bmp.at<uint32_t>(0, y);
375
+ for (int x = 0; x < w; ++x, ++p)
376
+ pixels->push_back(value(*p));
377
+ }
378
+ break;
379
+
380
+ case Rays::GRAY_float:
381
+ case Rays::ALPHA_float:
382
+ for (int y = 0; y < h; ++y)
383
+ {
384
+ const auto* p = bmp.at<float>(0, y);
385
+ for (int x = 0; x < w; ++x, ++p)
386
+ pixels->push_back(value(*p));
387
+ }
388
+ break;
389
+
390
+ case Rays::RGB_888:
391
+ for (int y = 0; y < h; ++y)
392
+ {
393
+ const auto* p = bmp.at<uint8_t>(0, y);
394
+ for (int x = 0; x < w; ++x, p += 3)
395
+ pixels->push_back(to_rgb_value(p[0], p[1], p[2]));
396
+ }
397
+ break;
398
+
399
+ case Rays::RGBA_8888:
400
+ case Rays::RGBX_8888:
401
+ for (int y = 0; y < h; ++y)
402
+ {
403
+ const auto* p = bmp.at<uint8_t>(0, y);
404
+ for (int x = 0; x < w; ++x, p += 4)
405
+ pixels->push_back(to_argb_value(p[0], p[1], p[2], p[3]));
406
+ }
407
+ break;
408
+
409
+ case Rays::ARGB_8888:
410
+ case Rays::XRGB_8888:
411
+ for (int y = 0; y < h; ++y)
412
+ {
413
+ const auto* p = bmp.at<uint8_t>(0, y);
414
+ for (int x = 0; x < w; ++x, p += 4)
415
+ pixels->push_back(to_argb_value(p[1], p[2], p[3], p[0]));
416
+ }
417
+ break;
418
+
419
+ case Rays::BGR_888:
420
+ for (int y = 0; y < h; ++y)
421
+ {
422
+ const auto* p = bmp.at<uint8_t>(0, y);
423
+ for (int x = 0; x < w; ++x, p += 3)
424
+ pixels->push_back(to_rgb_value(p[2], p[1], p[0]));
425
+ }
426
+ break;
427
+
428
+ case Rays::BGRA_8888:
429
+ case Rays::BGRX_8888:
430
+ for (int y = 0; y < h; ++y)
431
+ {
432
+ const auto* p = bmp.at<uint8_t>(0, y);
433
+ for (int x = 0; x < w; ++x, p += 4)
434
+ pixels->push_back(to_argb_value(p[2], p[1], p[0], p[3]));
435
+ }
436
+ break;
437
+
438
+ case Rays::ABGR_8888:
439
+ case Rays::XBGR_8888:
440
+ for (int y = 0; y < h; ++y)
441
+ {
442
+ const auto* p = bmp.at<uint8_t>(0, y);
443
+ for (int x = 0; x < w; ++x, p += 4)
444
+ pixels->push_back(to_argb_value(p[3], p[2], p[1], p[0]));
445
+ }
446
+ break;
447
+
448
+ case Rays::RGB_float:
449
+ for (int y = 0; y < h; ++y)
450
+ {
451
+ const auto* p = bmp.at<float>(0, y);
452
+ for (int x = 0; x < w; ++x, p += 3)
453
+ {
454
+ pixels->push_back(value(p[0]));
455
+ pixels->push_back(value(p[1]));
456
+ pixels->push_back(value(p[2]));
457
+ }
458
+ }
459
+ break;
460
+
461
+ case Rays::RGBA_float:
462
+ for (int y = 0; y < h; ++y)
463
+ {
464
+ const auto* p = bmp.at<float>(0, y);
465
+ for (int x = 0; x < w; ++x, p += 4)
466
+ {
467
+ pixels->push_back(value(p[0]));
468
+ pixels->push_back(value(p[1]));
469
+ pixels->push_back(value(p[2]));
470
+ pixels->push_back(value(p[3]));
471
+ }
472
+ }
473
+ break;
474
+
475
+ case Rays::ARGB_float:
476
+ for (int y = 0; y < h; ++y)
477
+ {
478
+ const auto* p = bmp.at<float>(0, y);
479
+ for (int x = 0; x < w; ++x, p += 4)
480
+ {
481
+ pixels->push_back(value(p[1]));
482
+ pixels->push_back(value(p[2]));
483
+ pixels->push_back(value(p[3]));
484
+ pixels->push_back(value(p[0]));
485
+ }
486
+ }
487
+ break;
488
+
489
+ case Rays::BGR_float:
490
+ for (int y = 0; y < h; ++y)
491
+ {
492
+ const auto* p = bmp.at<float>(0, y);
493
+ for (int x = 0; x < w; ++x, p += 3)
494
+ {
495
+ pixels->push_back(value(p[2]));
496
+ pixels->push_back(value(p[1]));
497
+ pixels->push_back(value(p[0]));
498
+ }
499
+ }
500
+ break;
501
+
502
+ case Rays::BGRA_float:
503
+ for (int y = 0; y < h; ++y)
504
+ {
505
+ const auto* p = bmp.at<float>(0, y);
506
+ for (int x = 0; x < w; ++x, p += 4)
507
+ {
508
+ pixels->push_back(value(p[2]));
509
+ pixels->push_back(value(p[1]));
510
+ pixels->push_back(value(p[0]));
511
+ pixels->push_back(value(p[3]));
512
+ }
513
+ }
514
+ break;
515
+
516
+ case Rays::ABGR_float:
517
+ for (int y = 0; y < h; ++y)
518
+ {
519
+ const auto* p = bmp.at<float>(0, y);
520
+ for (int x = 0; x < w; ++x, p += 4)
521
+ {
522
+ pixels->push_back(value(p[3]));
523
+ pixels->push_back(value(p[2]));
524
+ pixels->push_back(value(p[1]));
525
+ pixels->push_back(value(p[0]));
526
+ }
527
+ }
528
+ break;
529
+
530
+ default:
531
+ argument_error(__FILE__, __LINE__);
532
+ }
533
+ }
534
+
535
+ static
536
+ VALUE set_pixels(VALUE self, VALUE pixels)
537
+ {
538
+ CHECK;
539
+
540
+ if (sizeof(VALUE) <= 4)
541
+ {
542
+ not_implemented_error(
543
+ __FILE__, __LINE__, "Bitmap#pixels=() does not support 32-bit platforms");
544
+ }
545
+
546
+ set_pixels(THIS, pixels);
547
+ return pixels;
548
+ }
549
+
550
+ static
551
+ VALUE get_pixels(VALUE self)
552
+ {
553
+ CHECK;
554
+
555
+ if (sizeof(VALUE) <= 4)
556
+ {
557
+ not_implemented_error(
558
+ __FILE__, __LINE__, "Bitmap#pixels() does not support 32-bit platforms");
559
+ }
560
+
561
+ std::vector<VALUE> pixels;
562
+ get_pixels(&pixels, *THIS);
563
+ return value(pixels.size(), (const Value*) &pixels[0]);
564
+ }
565
+
69
566
  static
70
567
  VALUE set_at(VALUE self, VALUE x, VALUE y, VALUE color)
71
568
  {
@@ -105,6 +602,8 @@ Init_rays_bitmap ()
105
602
  rb_define_method(cBitmap, "width", RUBY_METHOD_FUNC(width), 0);
106
603
  rb_define_method(cBitmap, "height", RUBY_METHOD_FUNC(height), 0);
107
604
  rb_define_method(cBitmap, "color_space", RUBY_METHOD_FUNC(color_space), 0);
605
+ rb_define_method(cBitmap, "pixels=", RUBY_METHOD_FUNC(set_pixels), 1);
606
+ rb_define_method(cBitmap, "pixels", RUBY_METHOD_FUNC(get_pixels), 0);
108
607
  cBitmap.define_method("[]=", set_at);
109
608
  cBitmap.define_method("[]", get_at);
110
609
  }
@@ -125,8 +125,8 @@ VALUE device_names(VALUE self)
125
125
  auto names = Rays::get_camera_device_names();
126
126
 
127
127
  std::vector<Value> v;
128
- for (auto it = names.begin(), end = names.end(); it != end; ++it)
129
- v.emplace_back(value(it->c_str()));
128
+ for (const auto& name : names)
129
+ v.emplace_back(name.c_str());
130
130
  return value(v.size(), &v[0]);
131
131
  }
132
132
 
@@ -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)
@@ -24,9 +22,9 @@ get_line_args (std::vector<Rays::Point>* points, int argc, const Value* argv)
24
22
  points->reserve(argc / 2);
25
23
  for (int i = 0; i < argc; i += 2)
26
24
  {
27
- coord x = to<coord>(argv[i + 0]);
28
- coord y = to<coord>(argv[i + 1]);
29
- points->emplace_back(Rays::Point(x, y));
25
+ points->emplace_back(
26
+ to<coord>(argv[i + 0]),
27
+ to<coord>(argv[i + 1]));
30
28
  }
31
29
  }
32
30
  else
@@ -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;
@@ -28,6 +28,15 @@ VALUE initialize(VALUE self)
28
28
  return self;
29
29
  }
30
30
 
31
+ static
32
+ VALUE initialize_copy(VALUE self, VALUE obj)
33
+ {
34
+ RUCY_CHECK_OBJ(Rays::Font, self);
35
+
36
+ *THIS = to<Rays::Font&>(obj).dup();
37
+ return self;
38
+ }
39
+
31
40
  static
32
41
  VALUE name(VALUE self)
33
42
  {
@@ -35,6 +44,14 @@ VALUE name(VALUE self)
35
44
  return value(THIS->name().c_str());
36
45
  }
37
46
 
47
+ static
48
+ VALUE set_size(VALUE self, VALUE size)
49
+ {
50
+ CHECK;
51
+ THIS->set_size(to<coord>(size));
52
+ return size;
53
+ }
54
+
38
55
  static
39
56
  VALUE size(VALUE self)
40
57
  {
@@ -83,6 +100,33 @@ VALUE leading(VALUE self)
83
100
  return value(leading);
84
101
  }
85
102
 
103
+ static
104
+ VALUE families(VALUE self)
105
+ {
106
+ Hash hash;
107
+ for (const auto& family : Rays::get_font_families())
108
+ {
109
+ std::vector<Value> members;
110
+ for (const auto& member : family.second)
111
+ members.emplace_back(member.c_str());
112
+ hash.set(family.first.c_str(), value(members.size(), &members[0]));
113
+ }
114
+ return hash;
115
+ }
116
+
117
+ static
118
+ VALUE load(VALUE self)
119
+ {
120
+ check_arg_count(__FILE__, __LINE__, "Font.load", argc, 1, 2);
121
+
122
+ const char* path = argv[0].c_str();
123
+
124
+ if (argc >= 2)
125
+ return value(Rays::load_font(path, to<Rays::coord>(argv[1])));
126
+ else
127
+ return value(Rays::load_font(path));
128
+ }
129
+
86
130
 
87
131
  static Class cFont;
88
132
 
@@ -94,13 +138,17 @@ Init_rays_font ()
94
138
  cFont = rb_define_class_under(mRays, "Font", rb_cObject);
95
139
  rb_define_alloc_func(cFont, alloc);
96
140
  rb_define_private_method(cFont, "initialize", RUBY_METHOD_FUNC(initialize), -1);
141
+ rb_define_private_method(cFont, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
97
142
  rb_define_method(cFont, "name", RUBY_METHOD_FUNC(name), 0);
143
+ rb_define_method(cFont, "size=", RUBY_METHOD_FUNC(set_size), 1);
98
144
  rb_define_method(cFont, "size", RUBY_METHOD_FUNC(size), 0);
99
145
  rb_define_method(cFont, "width", RUBY_METHOD_FUNC(width), 1);
100
146
  rb_define_method(cFont, "height", RUBY_METHOD_FUNC(height), 0);
101
147
  rb_define_method(cFont, "ascent", RUBY_METHOD_FUNC(ascent), 0);
102
148
  rb_define_method(cFont, "descent", RUBY_METHOD_FUNC(descent), 0);
103
149
  rb_define_method(cFont, "leading", RUBY_METHOD_FUNC(leading), 0);
150
+ rb_define_module_function(cFont, "families", RUBY_METHOD_FUNC(families), 0);
151
+ rb_define_module_function(cFont, "load", RUBY_METHOD_FUNC(load), -1);
104
152
  }
105
153
 
106
154
 
@@ -122,9 +170,9 @@ namespace Rucy
122
170
  if (convert)
123
171
  {
124
172
  if (argc == 0)
125
- return Rays::default_font();
173
+ return Rays::get_default_font();
126
174
 
127
- coord size = argc >= 2 ? to<coord>(argv[1]) : 0;
175
+ coord size = argc >= 2 ? to<coord>(argv[1]) : Rays::Font::DEFAULT_SIZE;
128
176
  if (argv->is_nil())
129
177
  return Rays::Font(NULL, size);
130
178
  else if (argv->is_s() || argv->is_sym())