rays 0.1.47 → 0.1.48

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) 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/defs.cpp +32 -8
  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 +73 -3
  8. data/.doc/ext/rays/polygon.cpp +131 -97
  9. data/.doc/ext/rays/polyline.cpp +89 -10
  10. data/.doc/ext/rays/rays.cpp +80 -0
  11. data/.doc/ext/rays/{noise.cpp → util.cpp} +2 -2
  12. data/ChangeLog.md +23 -0
  13. data/VERSION +1 -1
  14. data/ext/rays/bitmap.cpp +288 -46
  15. data/ext/rays/camera.cpp +2 -2
  16. data/ext/rays/defs.cpp +32 -8
  17. data/ext/rays/defs.h +56 -3
  18. data/ext/rays/font.cpp +56 -4
  19. data/ext/rays/native.cpp +2 -4
  20. data/ext/rays/painter.cpp +80 -3
  21. data/ext/rays/polygon.cpp +134 -99
  22. data/ext/rays/polyline.cpp +95 -9
  23. data/ext/rays/rays.cpp +80 -0
  24. data/ext/rays/{noise.cpp → util.cpp} +2 -2
  25. data/include/rays/defs.h +24 -26
  26. data/include/rays/font.h +17 -3
  27. data/include/rays/painter.h +14 -0
  28. data/include/rays/polygon.h +56 -37
  29. data/include/rays/polyline.h +17 -2
  30. data/include/rays/ruby/polygon.h +0 -11
  31. data/include/rays/ruby/rays.h +4 -0
  32. data/include/rays/{noise.h → util.h} +2 -2
  33. data/lib/rays/color.rb +1 -1
  34. data/lib/rays/font.rb +1 -1
  35. data/lib/rays/image.rb +1 -1
  36. data/lib/rays/painter.rb +12 -1
  37. data/lib/rays/point.rb +1 -1
  38. data/lib/rays/polygon.rb +44 -35
  39. data/lib/rays/polyline.rb +54 -8
  40. data/lib/rays.rb +0 -1
  41. data/rays.gemspec +1 -1
  42. data/src/font.cpp +24 -2
  43. data/src/font.h +8 -1
  44. data/src/ios/font.mm +88 -27
  45. data/src/osx/font.mm +90 -28
  46. data/src/osx/helper.h +2 -2
  47. data/src/osx/helper.mm +2 -2
  48. data/src/painter.cpp +155 -85
  49. data/src/painter.h +11 -3
  50. data/src/polygon.cpp +404 -315
  51. data/src/polyline.cpp +138 -27
  52. data/src/polyline.h +3 -5
  53. data/src/shader.cpp +36 -4
  54. data/src/shader.h +1 -1
  55. data/src/texture.cpp +2 -2
  56. data/src/{noise.cpp → util.cpp} +1 -1
  57. data/src/win32/font.cpp +1 -1
  58. data/test/test_bitmap.rb +12 -5
  59. data/test/test_color.rb +4 -0
  60. data/test/test_font.rb +20 -2
  61. data/test/test_image.rb +18 -18
  62. data/test/test_point.rb +1 -1
  63. data/test/test_polygon.rb +52 -45
  64. data/test/test_polyline.rb +191 -72
  65. metadata +9 -15
  66. data/.doc/ext/rays/polygon_line.cpp +0 -97
  67. data/ext/rays/polygon_line.cpp +0 -100
  68. data/lib/rays/polygon_line.rb +0 -33
  69. data/test/test_polygon_line.rb +0 -164
@@ -9,6 +9,8 @@
9
9
  RUCY_DEFINE_CONVERT_TO(Rays::CapType)
10
10
  RUCY_DEFINE_CONVERT_TO(Rays::JoinType)
11
11
  RUCY_DEFINE_CONVERT_TO(Rays::BlendMode)
12
+ RUCY_DEFINE_CONVERT_TO(Rays::TexCoordMode)
13
+ RUCY_DEFINE_CONVERT_TO(Rays::TexCoordWrap)
12
14
 
13
15
 
14
16
  template <typename T>
@@ -43,6 +45,16 @@ static std::vector<EnumType<Rays::BlendMode>> BLEND_MODES({
43
45
  {"BLEND_REPLACE", "REPLACE", Rays::BLEND_REPLACE},
44
46
  });
45
47
 
48
+ static std::vector<EnumType<Rays::TexCoordMode>> TEXCOORD_MODES({
49
+ {"TEXCOORD_IMAGE", "IMAGE", Rays::TEXCOORD_IMAGE},
50
+ {"TEXCOORD_NORMAL", "NORMAL", Rays::TEXCOORD_NORMAL},
51
+ });
52
+
53
+ static std::vector<EnumType<Rays::TexCoordWrap>> TEXCOORD_WRAPS({
54
+ {"TEXCOORD_CLAMP", "CLAMP", Rays::TEXCOORD_CLAMP},
55
+ {"TEXCOORD_REPEAT", "REPEAT", Rays::TEXCOORD_REPEAT},
56
+ });
57
+
46
58
 
47
59
  static
48
60
  VALUE init(VALUE self)
@@ -77,6 +89,12 @@ Init_rays ()
77
89
 
78
90
  for (auto it = BLEND_MODES.begin(); it != BLEND_MODES.end(); ++it)
79
91
  mRays.define_const(it->name, it->value);
92
+
93
+ for (auto it = TEXCOORD_MODES.begin(); it != TEXCOORD_MODES.end(); ++it)
94
+ mRays.define_const(it->name, it->value);
95
+
96
+ for (auto it = TEXCOORD_WRAPS.begin(); it != TEXCOORD_WRAPS.end(); ++it)
97
+ mRays.define_const(it->name, it->value);
80
98
  }
81
99
 
82
100
 
@@ -177,6 +195,68 @@ namespace Rucy
177
195
  }
178
196
 
179
197
 
198
+ template <> Rays::TexCoordMode
199
+ value_to<Rays::TexCoordMode> (int argc, const Value* argv, bool convert)
200
+ {
201
+ assert(argc > 0 && argv);
202
+
203
+ if (convert)
204
+ {
205
+ if (argv->is_s() || argv->is_sym())
206
+ {
207
+ const char* str = argv->c_str();
208
+ for (auto it = TEXCOORD_MODES.begin(); it != TEXCOORD_MODES.end(); ++it)
209
+ {
210
+ if (
211
+ strcasecmp(str, it->name) == 0 ||
212
+ strcasecmp(str, it->short_name) == 0)
213
+ {
214
+ return it->value;
215
+ }
216
+ }
217
+ argument_error(__FILE__, __LINE__, "invalid texcoord mode -- %s", str);
218
+ }
219
+ }
220
+
221
+ int mode = value_to<int>(*argv, convert);
222
+ if (mode < 0 || Rays::TEXCOORD_MODE_MAX <= mode)
223
+ argument_error(__FILE__, __LINE__, "invalid texcoord mode -- %d", mode);
224
+
225
+ return (Rays::TexCoordMode) mode;
226
+ }
227
+
228
+
229
+ template <> Rays::TexCoordWrap
230
+ value_to<Rays::TexCoordWrap> (int argc, const Value* argv, bool convert)
231
+ {
232
+ assert(argc > 0 && argv);
233
+
234
+ if (convert)
235
+ {
236
+ if (argv->is_s() || argv->is_sym())
237
+ {
238
+ const char* str = argv->c_str();
239
+ for (auto it = TEXCOORD_WRAPS.begin(); it != TEXCOORD_WRAPS.end(); ++it)
240
+ {
241
+ if (
242
+ strcasecmp(str, it->name) == 0 ||
243
+ strcasecmp(str, it->short_name) == 0)
244
+ {
245
+ return it->value;
246
+ }
247
+ }
248
+ argument_error(__FILE__, __LINE__, "invalid texcoord wrap -- %s", str);
249
+ }
250
+ }
251
+
252
+ int wrap = value_to<int>(*argv, convert);
253
+ if (wrap < 0 || Rays::TEXCOORD_WRAP_MAX <= wrap)
254
+ argument_error(__FILE__, __LINE__, "invalid texcoord wrap -- %d", wrap);
255
+
256
+ return (Rays::TexCoordWrap) wrap;
257
+ }
258
+
259
+
180
260
  }// Rucy
181
261
 
182
262
 
@@ -1,4 +1,4 @@
1
- #include "rays/noise.h"
1
+ #include "rays/util.h"
2
2
  #include "rays/ruby/point.h"
3
3
  #include "defs.h"
4
4
 
@@ -45,7 +45,7 @@ VALUE simplex(VALUE self)
45
45
 
46
46
 
47
47
  void
48
- Init_rays_noise ()
48
+ Init_rays_util ()
49
49
  {
50
50
  Module mRays = rb_define_module("Rays");
51
51
  rb_define_singleton_method(mRays, "perlin", RUBY_METHOD_FUNC(perlin), -1);
data/ChangeLog.md CHANGED
@@ -1,6 +1,29 @@
1
1
  # rays ChangeLog
2
2
 
3
3
 
4
+ ## [v0.1.48] - 2024-01-08
5
+
6
+ - Add Bitmap#pixels=
7
+ - Add Font#dup, Font#size=, Font.families, and Font.load
8
+ - Add Polyline#with
9
+ - Add Painter#texture, Painter#texcoord_mode, and Painter#texcoord_wrap
10
+
11
+ - Delete Polygon::Line because it was merged into Polyline
12
+
13
+ - Polygon and Polyline can take colors and texcoords for each vertex
14
+ - Polyline.new can take 'hole' parameter
15
+ - 'polygonA + polygonB' means Polygon.new(*polygonA.to_a, *polygonB.to_a)
16
+ - Polygon with only holes raises an ArgumentError
17
+ - Image delegates 'pixels' accessors to Bitmap
18
+ - Use GL_CLAMP_TO_EDGE for texturing
19
+ - Refine Point#inspect(), Color#inspect(), and Font#inspect()
20
+ - default_font() -> get_default_font()
21
+ - rays/include/noise.h -> rays/include/util.h
22
+
23
+ - Fix Polygon.bezier() returns broken object
24
+ - Fix get_pixels() does not work with float colors
25
+
26
+
4
27
  ## [v0.1.47] - 2023-12-09
5
28
 
6
29
  - Add Polygon's singleton methods: points(), lines(), triangles(), triangle_strip(), triangle_fan(), quads(), quad_strip()
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.47
1
+ 0.1.48
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/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;