rays 0.1.46 → 0.1.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.doc/ext/rays/bitmap.cpp +499 -0
- data/.doc/ext/rays/camera.cpp +2 -2
- data/.doc/ext/rays/defs.cpp +35 -11
- data/.doc/ext/rays/font.cpp +50 -2
- data/.doc/ext/rays/native.cpp +2 -4
- data/.doc/ext/rays/painter.cpp +111 -6
- data/.doc/ext/rays/polygon.cpp +152 -41
- data/.doc/ext/rays/polyline.cpp +89 -10
- data/.doc/ext/rays/rays.cpp +91 -11
- data/.doc/ext/rays/{noise.cpp → util.cpp} +2 -2
- data/.github/workflows/test.yml +0 -1
- data/ChangeLog.md +38 -0
- data/Rakefile +4 -4
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +501 -0
- data/ext/rays/camera.cpp +2 -2
- data/ext/rays/defs.cpp +35 -11
- data/ext/rays/defs.h +56 -3
- data/ext/rays/font.cpp +56 -4
- data/ext/rays/native.cpp +2 -4
- data/ext/rays/painter.cpp +125 -11
- data/ext/rays/polygon.cpp +161 -41
- data/ext/rays/polyline.cpp +95 -9
- data/ext/rays/rays.cpp +91 -11
- data/ext/rays/{noise.cpp → util.cpp} +2 -2
- data/include/rays/defs.h +24 -0
- data/include/rays/font.h +17 -3
- data/include/rays/matrix.h +2 -0
- data/include/rays/painter.h +29 -1
- data/include/rays/polygon.h +57 -33
- data/include/rays/polyline.h +20 -1
- data/include/rays/ruby/polygon.h +0 -11
- data/include/rays/ruby/rays.h +4 -0
- data/include/rays/{noise.h → util.h} +2 -2
- data/lib/rays/color.rb +1 -1
- data/lib/rays/font.rb +1 -1
- data/lib/rays/image.rb +1 -1
- data/lib/rays/painter.rb +13 -2
- data/lib/rays/point.rb +1 -1
- data/lib/rays/polygon.rb +54 -16
- data/lib/rays/polyline.rb +54 -8
- data/lib/rays.rb +0 -1
- data/rays.gemspec +2 -2
- data/src/color_space.cpp +2 -2
- data/src/font.cpp +24 -2
- data/src/font.h +8 -1
- data/src/ios/font.mm +88 -27
- data/src/matrix.cpp +8 -0
- data/src/osx/font.mm +90 -28
- data/src/osx/helper.h +2 -2
- data/src/osx/helper.mm +2 -2
- data/src/painter.cpp +227 -90
- data/src/painter.h +11 -3
- data/src/polygon.cpp +588 -205
- data/src/polyline.cpp +154 -28
- data/src/polyline.h +3 -5
- data/src/shader.cpp +36 -4
- data/src/shader.h +1 -1
- data/src/texture.cpp +2 -2
- data/src/{noise.cpp → util.cpp} +1 -1
- data/src/win32/font.cpp +1 -1
- data/test/test_bitmap.rb +16 -2
- data/test/test_color.rb +4 -0
- data/test/test_font.rb +20 -2
- data/test/test_image.rb +18 -18
- data/test/test_point.rb +1 -1
- data/test/test_polygon.rb +52 -45
- data/test/test_polyline.rb +191 -72
- metadata +11 -17
- data/.doc/ext/rays/polygon_line.cpp +0 -97
- data/ext/rays/polygon_line.cpp +0 -100
- data/lib/rays/polygon_line.rb +0 -33
- data/test/test_polygon_line.rb +0 -164
data/ext/rays/bitmap.cpp
CHANGED
@@ -72,6 +72,505 @@ 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
|
+
|
326
|
+
static inline Value
|
327
|
+
to_rgb_value (uint8_t r, uint8_t g, uint8_t b)
|
328
|
+
{
|
329
|
+
return value(
|
330
|
+
((uint) r) << 16 |
|
331
|
+
((uint) g) << 8 |
|
332
|
+
((uint) b));
|
333
|
+
}
|
334
|
+
|
335
|
+
static inline Value
|
336
|
+
to_argb_value (uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
337
|
+
{
|
338
|
+
return value(
|
339
|
+
((uint) a) << 24 |
|
340
|
+
((uint) r) << 16 |
|
341
|
+
((uint) g) << 8 |
|
342
|
+
((uint) b));
|
343
|
+
}
|
344
|
+
|
345
|
+
static void
|
346
|
+
get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
347
|
+
{
|
348
|
+
int w = bmp.width(), h = bmp.height();
|
349
|
+
const auto& cs = bmp.color_space();
|
350
|
+
|
351
|
+
pixels->clear();
|
352
|
+
pixels->reserve(w * h * (cs.is_float() ? cs.Bpp() / cs.Bpc() : 1));
|
353
|
+
|
354
|
+
switch (cs.type())
|
355
|
+
{
|
356
|
+
case Rays::GRAY_8:
|
357
|
+
case Rays::ALPHA_8:
|
358
|
+
for (int y = 0; y < h; ++y)
|
359
|
+
{
|
360
|
+
const auto* p = bmp.at<uint8_t>(0, y);
|
361
|
+
for (int x = 0; x < w; ++x, ++p)
|
362
|
+
pixels->push_back(value(*p));
|
363
|
+
}
|
364
|
+
break;
|
365
|
+
|
366
|
+
case Rays::GRAY_16:
|
367
|
+
case Rays::ALPHA_16:
|
368
|
+
for (int y = 0; y < h; ++y)
|
369
|
+
{
|
370
|
+
const auto* p = bmp.at<uint16_t>(0, y);
|
371
|
+
for (int x = 0; x < w; ++x, ++p)
|
372
|
+
pixels->push_back(value(*p));
|
373
|
+
}
|
374
|
+
break;
|
375
|
+
|
376
|
+
case Rays::GRAY_32:
|
377
|
+
case Rays::ALPHA_32:
|
378
|
+
for (int y = 0; y < h; ++y)
|
379
|
+
{
|
380
|
+
const auto* p = bmp.at<uint32_t>(0, y);
|
381
|
+
for (int x = 0; x < w; ++x, ++p)
|
382
|
+
pixels->push_back(value(*p));
|
383
|
+
}
|
384
|
+
break;
|
385
|
+
|
386
|
+
case Rays::GRAY_float:
|
387
|
+
case Rays::ALPHA_float:
|
388
|
+
for (int y = 0; y < h; ++y)
|
389
|
+
{
|
390
|
+
const auto* p = bmp.at<float>(0, y);
|
391
|
+
for (int x = 0; x < w; ++x, ++p)
|
392
|
+
pixels->push_back(value(*p));
|
393
|
+
}
|
394
|
+
break;
|
395
|
+
|
396
|
+
case Rays::RGB_888:
|
397
|
+
for (int y = 0; y < h; ++y)
|
398
|
+
{
|
399
|
+
const auto* p = bmp.at<uint8_t>(0, y);
|
400
|
+
for (int x = 0; x < w; ++x, p += 3)
|
401
|
+
pixels->push_back(to_rgb_value(p[0], p[1], p[2]));
|
402
|
+
}
|
403
|
+
break;
|
404
|
+
|
405
|
+
case Rays::RGBA_8888:
|
406
|
+
case Rays::RGBX_8888:
|
407
|
+
for (int y = 0; y < h; ++y)
|
408
|
+
{
|
409
|
+
const auto* p = bmp.at<uint8_t>(0, y);
|
410
|
+
for (int x = 0; x < w; ++x, p += 4)
|
411
|
+
pixels->push_back(to_argb_value(p[0], p[1], p[2], p[3]));
|
412
|
+
}
|
413
|
+
break;
|
414
|
+
|
415
|
+
case Rays::ARGB_8888:
|
416
|
+
case Rays::XRGB_8888:
|
417
|
+
for (int y = 0; y < h; ++y)
|
418
|
+
{
|
419
|
+
const auto* p = bmp.at<uint8_t>(0, y);
|
420
|
+
for (int x = 0; x < w; ++x, p += 4)
|
421
|
+
pixels->push_back(to_argb_value(p[1], p[2], p[3], p[0]));
|
422
|
+
}
|
423
|
+
break;
|
424
|
+
|
425
|
+
case Rays::BGR_888:
|
426
|
+
for (int y = 0; y < h; ++y)
|
427
|
+
{
|
428
|
+
const auto* p = bmp.at<uint8_t>(0, y);
|
429
|
+
for (int x = 0; x < w; ++x, p += 3)
|
430
|
+
pixels->push_back(to_rgb_value(p[2], p[1], p[0]));
|
431
|
+
}
|
432
|
+
break;
|
433
|
+
|
434
|
+
case Rays::BGRA_8888:
|
435
|
+
case Rays::BGRX_8888:
|
436
|
+
for (int y = 0; y < h; ++y)
|
437
|
+
{
|
438
|
+
const auto* p = bmp.at<uint8_t>(0, y);
|
439
|
+
for (int x = 0; x < w; ++x, p += 4)
|
440
|
+
pixels->push_back(to_argb_value(p[2], p[1], p[0], p[3]));
|
441
|
+
}
|
442
|
+
break;
|
443
|
+
|
444
|
+
case Rays::ABGR_8888:
|
445
|
+
case Rays::XBGR_8888:
|
446
|
+
for (int y = 0; y < h; ++y)
|
447
|
+
{
|
448
|
+
const auto* p = bmp.at<uint8_t>(0, y);
|
449
|
+
for (int x = 0; x < w; ++x, p += 4)
|
450
|
+
pixels->push_back(to_argb_value(p[3], p[2], p[1], p[0]));
|
451
|
+
}
|
452
|
+
break;
|
453
|
+
|
454
|
+
case Rays::RGB_float:
|
455
|
+
for (int y = 0; y < h; ++y)
|
456
|
+
{
|
457
|
+
const auto* p = bmp.at<float>(0, y);
|
458
|
+
for (int x = 0; x < w; ++x, p += 3)
|
459
|
+
{
|
460
|
+
pixels->push_back(value(p[0]));
|
461
|
+
pixels->push_back(value(p[1]));
|
462
|
+
pixels->push_back(value(p[2]));
|
463
|
+
}
|
464
|
+
}
|
465
|
+
break;
|
466
|
+
|
467
|
+
case Rays::RGBA_float:
|
468
|
+
for (int y = 0; y < h; ++y)
|
469
|
+
{
|
470
|
+
const auto* p = bmp.at<float>(0, y);
|
471
|
+
for (int x = 0; x < w; ++x, p += 4)
|
472
|
+
{
|
473
|
+
pixels->push_back(value(p[0]));
|
474
|
+
pixels->push_back(value(p[1]));
|
475
|
+
pixels->push_back(value(p[2]));
|
476
|
+
pixels->push_back(value(p[3]));
|
477
|
+
}
|
478
|
+
}
|
479
|
+
break;
|
480
|
+
|
481
|
+
case Rays::ARGB_float:
|
482
|
+
for (int y = 0; y < h; ++y)
|
483
|
+
{
|
484
|
+
const auto* p = bmp.at<float>(0, y);
|
485
|
+
for (int x = 0; x < w; ++x, p += 4)
|
486
|
+
{
|
487
|
+
pixels->push_back(value(p[1]));
|
488
|
+
pixels->push_back(value(p[2]));
|
489
|
+
pixels->push_back(value(p[3]));
|
490
|
+
pixels->push_back(value(p[0]));
|
491
|
+
}
|
492
|
+
}
|
493
|
+
break;
|
494
|
+
|
495
|
+
case Rays::BGR_float:
|
496
|
+
for (int y = 0; y < h; ++y)
|
497
|
+
{
|
498
|
+
const auto* p = bmp.at<float>(0, y);
|
499
|
+
for (int x = 0; x < w; ++x, p += 3)
|
500
|
+
{
|
501
|
+
pixels->push_back(value(p[2]));
|
502
|
+
pixels->push_back(value(p[1]));
|
503
|
+
pixels->push_back(value(p[0]));
|
504
|
+
}
|
505
|
+
}
|
506
|
+
break;
|
507
|
+
|
508
|
+
case Rays::BGRA_float:
|
509
|
+
for (int y = 0; y < h; ++y)
|
510
|
+
{
|
511
|
+
const auto* p = bmp.at<float>(0, y);
|
512
|
+
for (int x = 0; x < w; ++x, p += 4)
|
513
|
+
{
|
514
|
+
pixels->push_back(value(p[2]));
|
515
|
+
pixels->push_back(value(p[1]));
|
516
|
+
pixels->push_back(value(p[0]));
|
517
|
+
pixels->push_back(value(p[3]));
|
518
|
+
}
|
519
|
+
}
|
520
|
+
break;
|
521
|
+
|
522
|
+
case Rays::ABGR_float:
|
523
|
+
for (int y = 0; y < h; ++y)
|
524
|
+
{
|
525
|
+
const auto* p = bmp.at<float>(0, y);
|
526
|
+
for (int x = 0; x < w; ++x, p += 4)
|
527
|
+
{
|
528
|
+
pixels->push_back(value(p[3]));
|
529
|
+
pixels->push_back(value(p[2]));
|
530
|
+
pixels->push_back(value(p[1]));
|
531
|
+
pixels->push_back(value(p[0]));
|
532
|
+
}
|
533
|
+
}
|
534
|
+
break;
|
535
|
+
|
536
|
+
default:
|
537
|
+
argument_error(__FILE__, __LINE__);
|
538
|
+
}
|
539
|
+
}
|
540
|
+
|
541
|
+
static
|
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)
|
559
|
+
{
|
560
|
+
CHECK;
|
561
|
+
|
562
|
+
if (sizeof(VALUE) <= 4)
|
563
|
+
{
|
564
|
+
not_implemented_error(
|
565
|
+
__FILE__, __LINE__, "Bitmap#pixels() does not support 32-bit platforms");
|
566
|
+
}
|
567
|
+
|
568
|
+
std::vector<VALUE> pixels;
|
569
|
+
get_pixels(&pixels, *THIS);
|
570
|
+
return value(pixels.size(), (const Value*) &pixels[0]);
|
571
|
+
}
|
572
|
+
RUCY_END
|
573
|
+
|
75
574
|
static
|
76
575
|
RUCY_DEF3(set_at, x, y, color)
|
77
576
|
{
|
@@ -113,6 +612,8 @@ Init_rays_bitmap ()
|
|
113
612
|
cBitmap.define_method("width", width);
|
114
613
|
cBitmap.define_method("height", height);
|
115
614
|
cBitmap.define_method("color_space", color_space);
|
615
|
+
cBitmap.define_method("pixels=", set_pixels);
|
616
|
+
cBitmap.define_method("pixels", get_pixels);
|
116
617
|
cBitmap.define_method("[]=", set_at);
|
117
618
|
cBitmap.define_method("[]", get_at);
|
118
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
|
143
|
-
v.emplace_back(
|
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
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
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;
|
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
|
20
|
-
|
21
|
-
|
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
|