rays 0.1.47 → 0.1.48
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.doc/ext/rays/bitmap.cpp +287 -46
- data/.doc/ext/rays/camera.cpp +2 -2
- data/.doc/ext/rays/defs.cpp +32 -8
- data/.doc/ext/rays/font.cpp +50 -2
- data/.doc/ext/rays/native.cpp +2 -4
- data/.doc/ext/rays/painter.cpp +73 -3
- data/.doc/ext/rays/polygon.cpp +131 -97
- data/.doc/ext/rays/polyline.cpp +89 -10
- data/.doc/ext/rays/rays.cpp +80 -0
- data/.doc/ext/rays/{noise.cpp → util.cpp} +2 -2
- data/ChangeLog.md +23 -0
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +288 -46
- data/ext/rays/camera.cpp +2 -2
- data/ext/rays/defs.cpp +32 -8
- 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 +80 -3
- data/ext/rays/polygon.cpp +134 -99
- data/ext/rays/polyline.cpp +95 -9
- data/ext/rays/rays.cpp +80 -0
- data/ext/rays/{noise.cpp → util.cpp} +2 -2
- data/include/rays/defs.h +24 -26
- data/include/rays/font.h +17 -3
- data/include/rays/painter.h +14 -0
- data/include/rays/polygon.h +56 -37
- data/include/rays/polyline.h +17 -2
- 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 +12 -1
- data/lib/rays/point.rb +1 -1
- data/lib/rays/polygon.rb +44 -35
- data/lib/rays/polyline.rb +54 -8
- data/lib/rays.rb +0 -1
- data/rays.gemspec +1 -1
- data/src/font.cpp +24 -2
- data/src/font.h +8 -1
- data/src/ios/font.mm +88 -27
- 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 +155 -85
- data/src/painter.h +11 -3
- data/src/polygon.cpp +404 -315
- data/src/polyline.cpp +138 -27
- 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 +12 -5
- 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 +9 -15
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0da22dbb538f841d5c21371e0b0749479467b1c0746bbd459118b649c66678e0
|
4
|
+
data.tar.gz: f55580763f45ce98198c59f6fe9ed86ac21f64aba8d16cf8b002923650c9b703
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d74814adfebbb7b9f0449abeebab017a475c76ae48a61c4f2f066e12a376fe52279db08cb6a27c3a3cadd26ae9179ce7fb204c59eff8440f9569121711d3a26e
|
7
|
+
data.tar.gz: 74e423c7faa9747f34e7e37737882fffce493e127fb5870a7e6a2fb0d4cc6f122a3cac43d9afa96373a6ce69f147198007db9d958a93d478cd4d5f1a9441053b
|
data/.doc/ext/rays/bitmap.cpp
CHANGED
@@ -66,6 +66,257 @@ 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
|
+
|
69
320
|
static inline Value
|
70
321
|
to_rgb_value (uint8_t r, uint8_t g, uint8_t b)
|
71
322
|
{
|
@@ -76,7 +327,7 @@ to_rgb_value (uint8_t r, uint8_t g, uint8_t b)
|
|
76
327
|
}
|
77
328
|
|
78
329
|
static inline Value
|
79
|
-
|
330
|
+
to_argb_value (uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
80
331
|
{
|
81
332
|
return value(
|
82
333
|
((uint) a) << 24 |
|
@@ -89,8 +340,8 @@ static void
|
|
89
340
|
get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
90
341
|
{
|
91
342
|
int w = bmp.width(), h = bmp.height();
|
92
|
-
|
93
343
|
const auto& cs = bmp.color_space();
|
344
|
+
|
94
345
|
pixels->clear();
|
95
346
|
pixels->reserve(w * h * (cs.is_float() ? cs.Bpp() / cs.Bpc() : 1));
|
96
347
|
|
@@ -146,38 +397,22 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
|
146
397
|
break;
|
147
398
|
|
148
399
|
case Rays::RGBA_8888:
|
149
|
-
for (int y = 0; y < h; ++y)
|
150
|
-
{
|
151
|
-
const auto* p = bmp.at<uint8_t>(0, y);
|
152
|
-
for (int x = 0; x < w; ++x, p += 4)
|
153
|
-
pixels->push_back(to_rgba_value(p[0], p[1], p[2], p[3]));
|
154
|
-
}
|
155
|
-
break;
|
156
|
-
|
157
400
|
case Rays::RGBX_8888:
|
158
401
|
for (int y = 0; y < h; ++y)
|
159
402
|
{
|
160
403
|
const auto* p = bmp.at<uint8_t>(0, y);
|
161
404
|
for (int x = 0; x < w; ++x, p += 4)
|
162
|
-
pixels->push_back(
|
405
|
+
pixels->push_back(to_argb_value(p[0], p[1], p[2], p[3]));
|
163
406
|
}
|
164
407
|
break;
|
165
408
|
|
166
409
|
case Rays::ARGB_8888:
|
167
|
-
for (int y = 0; y < h; ++y)
|
168
|
-
{
|
169
|
-
const auto* p = bmp.at<uint8_t>(0, y);
|
170
|
-
for (int x = 0; x < w; ++x, p += 4)
|
171
|
-
pixels->push_back(to_rgba_value(p[1], p[2], p[3], p[0]));
|
172
|
-
}
|
173
|
-
break;
|
174
|
-
|
175
410
|
case Rays::XRGB_8888:
|
176
411
|
for (int y = 0; y < h; ++y)
|
177
412
|
{
|
178
413
|
const auto* p = bmp.at<uint8_t>(0, y);
|
179
414
|
for (int x = 0; x < w; ++x, p += 4)
|
180
|
-
pixels->push_back(
|
415
|
+
pixels->push_back(to_argb_value(p[1], p[2], p[3], p[0]));
|
181
416
|
}
|
182
417
|
break;
|
183
418
|
|
@@ -191,45 +426,29 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
|
191
426
|
break;
|
192
427
|
|
193
428
|
case Rays::BGRA_8888:
|
194
|
-
for (int y = 0; y < h; ++y)
|
195
|
-
{
|
196
|
-
const auto* p = bmp.at<uint8_t>(0, y);
|
197
|
-
for (int x = 0; x < w; ++x, p += 4)
|
198
|
-
pixels->push_back(to_rgba_value(p[2], p[1], p[0], p[3]));
|
199
|
-
}
|
200
|
-
break;
|
201
|
-
|
202
429
|
case Rays::BGRX_8888:
|
203
430
|
for (int y = 0; y < h; ++y)
|
204
431
|
{
|
205
432
|
const auto* p = bmp.at<uint8_t>(0, y);
|
206
433
|
for (int x = 0; x < w; ++x, p += 4)
|
207
|
-
pixels->push_back(
|
434
|
+
pixels->push_back(to_argb_value(p[2], p[1], p[0], p[3]));
|
208
435
|
}
|
209
436
|
break;
|
210
437
|
|
211
438
|
case Rays::ABGR_8888:
|
212
|
-
for (int y = 0; y < h; ++y)
|
213
|
-
{
|
214
|
-
const auto* p = bmp.at<uint8_t>(0, y);
|
215
|
-
for (int x = 0; x < w; ++x, p += 4)
|
216
|
-
pixels->push_back(to_rgba_value(p[3], p[2], p[1], p[0]));
|
217
|
-
}
|
218
|
-
break;
|
219
|
-
|
220
439
|
case Rays::XBGR_8888:
|
221
440
|
for (int y = 0; y < h; ++y)
|
222
441
|
{
|
223
442
|
const auto* p = bmp.at<uint8_t>(0, y);
|
224
443
|
for (int x = 0; x < w; ++x, p += 4)
|
225
|
-
pixels->push_back(
|
444
|
+
pixels->push_back(to_argb_value(p[3], p[2], p[1], p[0]));
|
226
445
|
}
|
227
446
|
break;
|
228
447
|
|
229
448
|
case Rays::RGB_float:
|
230
449
|
for (int y = 0; y < h; ++y)
|
231
450
|
{
|
232
|
-
const auto* p = bmp.at<
|
451
|
+
const auto* p = bmp.at<float>(0, y);
|
233
452
|
for (int x = 0; x < w; ++x, p += 3)
|
234
453
|
{
|
235
454
|
pixels->push_back(value(p[0]));
|
@@ -242,7 +461,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
|
242
461
|
case Rays::RGBA_float:
|
243
462
|
for (int y = 0; y < h; ++y)
|
244
463
|
{
|
245
|
-
const auto* p = bmp.at<
|
464
|
+
const auto* p = bmp.at<float>(0, y);
|
246
465
|
for (int x = 0; x < w; ++x, p += 4)
|
247
466
|
{
|
248
467
|
pixels->push_back(value(p[0]));
|
@@ -256,7 +475,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
|
256
475
|
case Rays::ARGB_float:
|
257
476
|
for (int y = 0; y < h; ++y)
|
258
477
|
{
|
259
|
-
const auto* p = bmp.at<
|
478
|
+
const auto* p = bmp.at<float>(0, y);
|
260
479
|
for (int x = 0; x < w; ++x, p += 4)
|
261
480
|
{
|
262
481
|
pixels->push_back(value(p[1]));
|
@@ -270,7 +489,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
|
270
489
|
case Rays::BGR_float:
|
271
490
|
for (int y = 0; y < h; ++y)
|
272
491
|
{
|
273
|
-
const auto* p = bmp.at<
|
492
|
+
const auto* p = bmp.at<float>(0, y);
|
274
493
|
for (int x = 0; x < w; ++x, p += 3)
|
275
494
|
{
|
276
495
|
pixels->push_back(value(p[2]));
|
@@ -283,7 +502,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
|
283
502
|
case Rays::BGRA_float:
|
284
503
|
for (int y = 0; y < h; ++y)
|
285
504
|
{
|
286
|
-
const auto* p = bmp.at<
|
505
|
+
const auto* p = bmp.at<float>(0, y);
|
287
506
|
for (int x = 0; x < w; ++x, p += 4)
|
288
507
|
{
|
289
508
|
pixels->push_back(value(p[2]));
|
@@ -297,7 +516,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
|
297
516
|
case Rays::ABGR_float:
|
298
517
|
for (int y = 0; y < h; ++y)
|
299
518
|
{
|
300
|
-
const auto* p = bmp.at<
|
519
|
+
const auto* p = bmp.at<float>(0, y);
|
301
520
|
for (int x = 0; x < w; ++x, p += 4)
|
302
521
|
{
|
303
522
|
pixels->push_back(value(p[3]));
|
@@ -314,10 +533,31 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
|
314
533
|
}
|
315
534
|
|
316
535
|
static
|
317
|
-
VALUE
|
536
|
+
VALUE set_pixels(VALUE self, VALUE pixels)
|
318
537
|
{
|
319
538
|
CHECK;
|
320
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
|
+
|
321
561
|
std::vector<VALUE> pixels;
|
322
562
|
get_pixels(&pixels, *THIS);
|
323
563
|
return value(pixels.size(), (const Value*) &pixels[0]);
|
@@ -362,7 +602,8 @@ Init_rays_bitmap ()
|
|
362
602
|
rb_define_method(cBitmap, "width", RUBY_METHOD_FUNC(width), 0);
|
363
603
|
rb_define_method(cBitmap, "height", RUBY_METHOD_FUNC(height), 0);
|
364
604
|
rb_define_method(cBitmap, "color_space", RUBY_METHOD_FUNC(color_space), 0);
|
365
|
-
rb_define_method(cBitmap, "pixels", RUBY_METHOD_FUNC(
|
605
|
+
rb_define_method(cBitmap, "pixels=", RUBY_METHOD_FUNC(set_pixels), 1);
|
606
|
+
rb_define_method(cBitmap, "pixels", RUBY_METHOD_FUNC(get_pixels), 0);
|
366
607
|
cBitmap.define_method("[]=", set_at);
|
367
608
|
cBitmap.define_method("[]", get_at);
|
368
609
|
}
|
data/.doc/ext/rays/camera.cpp
CHANGED
@@ -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
|
129
|
-
v.emplace_back(
|
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
|
|
data/.doc/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)
|
@@ -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/.doc/ext/rays/font.cpp
CHANGED
@@ -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::
|
173
|
+
return Rays::get_default_font();
|
126
174
|
|
127
|
-
coord size = argc >= 2 ? to<coord>(argv[1]) :
|
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())
|
data/.doc/ext/rays/native.cpp
CHANGED
@@ -12,7 +12,6 @@ void Init_rays_matrix ();
|
|
12
12
|
|
13
13
|
void Init_rays_painter ();
|
14
14
|
void Init_rays_polyline ();
|
15
|
-
void Init_rays_polygon_line ();
|
16
15
|
void Init_rays_polygon ();
|
17
16
|
void Init_rays_bitmap ();
|
18
17
|
void Init_rays_image ();
|
@@ -20,7 +19,7 @@ void Init_rays_font ();
|
|
20
19
|
void Init_rays_shader ();
|
21
20
|
void Init_rays_camera ();
|
22
21
|
|
23
|
-
void
|
22
|
+
void Init_rays_util ();
|
24
23
|
|
25
24
|
|
26
25
|
extern "C" void
|
@@ -45,7 +44,6 @@ extern "C" void
|
|
45
44
|
|
46
45
|
Init_rays_painter();
|
47
46
|
Init_rays_polyline();
|
48
|
-
Init_rays_polygon_line();
|
49
47
|
Init_rays_polygon();
|
50
48
|
Init_rays_bitmap();
|
51
49
|
Init_rays_image();
|
@@ -53,7 +51,7 @@ extern "C" void
|
|
53
51
|
Init_rays_shader();
|
54
52
|
Init_rays_camera();
|
55
53
|
|
56
|
-
|
54
|
+
Init_rays_util();
|
57
55
|
|
58
56
|
RUCY_CATCH
|
59
57
|
}
|