rays 0.2.1 → 0.3.1
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 +99 -32
- data/.doc/ext/rays/bounds.cpp +16 -12
- data/.doc/ext/rays/camera.cpp +1 -1
- data/.doc/ext/rays/color.cpp +2 -2
- data/.doc/ext/rays/color_space.cpp +3 -3
- data/.doc/ext/rays/defs.cpp +4 -4
- data/.doc/ext/rays/font.cpp +4 -3
- data/.doc/ext/rays/image.cpp +32 -18
- data/.doc/ext/rays/matrix.cpp +6 -6
- data/.doc/ext/rays/painter.cpp +1 -1
- data/.doc/ext/rays/point.cpp +10 -6
- data/.doc/ext/rays/polygon.cpp +11 -9
- data/.doc/ext/rays/polyline.cpp +6 -4
- data/.doc/ext/rays/rays.cpp +25 -15
- data/.doc/ext/rays/shader.cpp +3 -3
- data/.github/workflows/release-gem.yml +1 -1
- data/.github/workflows/test.yml +3 -0
- data/ChangeLog.md +11 -0
- data/Gemfile.lock +1 -1
- data/LICENSE +1 -1
- data/Rakefile +17 -3
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +99 -32
- data/ext/rays/bounds.cpp +16 -12
- data/ext/rays/camera.cpp +1 -1
- data/ext/rays/color.cpp +2 -2
- data/ext/rays/color_space.cpp +3 -3
- data/ext/rays/defs.cpp +4 -4
- data/ext/rays/defs.h +2 -0
- data/ext/rays/extconf.rb +4 -2
- data/ext/rays/font.cpp +4 -3
- data/ext/rays/image.cpp +34 -18
- data/ext/rays/matrix.cpp +6 -6
- data/ext/rays/painter.cpp +1 -1
- data/ext/rays/point.cpp +10 -6
- data/ext/rays/polygon.cpp +11 -9
- data/ext/rays/polyline.cpp +6 -4
- data/ext/rays/rays.cpp +25 -15
- data/ext/rays/shader.cpp +3 -3
- data/include/rays/defs.h +7 -0
- data/include/rays/image.h +8 -2
- data/include/rays/ruby/bitmap.h +2 -2
- data/include/rays/ruby/bounds.h +2 -2
- data/include/rays/ruby/camera.h +2 -2
- data/include/rays/ruby/color.h +2 -2
- data/include/rays/ruby/color_space.h +2 -2
- data/include/rays/ruby/exception.h +3 -3
- data/include/rays/ruby/font.h +2 -2
- data/include/rays/ruby/image.h +2 -2
- data/include/rays/ruby/matrix.h +2 -2
- data/include/rays/ruby/painter.h +2 -2
- data/include/rays/ruby/point.h +2 -2
- data/include/rays/ruby/polygon.h +2 -2
- data/include/rays/ruby/polyline.h +2 -2
- data/include/rays/ruby/rays.h +6 -6
- data/include/rays/ruby/shader.h +2 -2
- data/lib/rays/bitmap.rb +7 -0
- data/lib/rays/extension.rb +4 -0
- data/lib/rays/image.rb +4 -0
- data/rays.gemspec +2 -2
- data/src/bounds.cpp +6 -2
- data/src/color.cpp +12 -4
- data/src/coord.h +2 -2
- data/src/font.cpp +1 -0
- data/src/image.cpp +32 -4
- data/src/ios/bitmap.mm +40 -33
- data/src/ios/font.mm +6 -1
- data/src/ios/rays.mm +2 -2
- data/src/matrix.h +1 -1
- data/src/opengl.h +1 -2
- data/src/osx/bitmap.mm +40 -33
- data/src/osx/font.mm +6 -1
- data/src/osx/rays.mm +2 -2
- data/src/painter.cpp +4 -1
- data/src/point.cpp +15 -3
- data/src/polygon.cpp +3 -5
- data/src/render_buffer.cpp +11 -3
- data/src/shader.cpp +3 -0
- data/src/shader_program.cpp +19 -9
- data/src/shader_source.cpp +5 -1
- data/src/texture.cpp +33 -11
- data/src/texture.h +6 -2
- data/src/win32/bitmap.cpp +178 -66
- data/src/win32/camera.cpp +119 -0
- data/src/win32/font.cpp +181 -40
- data/src/win32/gdi.h +1 -1
- data/src/win32/opengl.cpp +127 -0
- data/src/win32/rays.cpp +16 -9
- data/test/helper.rb +2 -0
- data/test/test_bitmap.rb +3 -1
- data/test/test_image.rb +8 -14
- data/test/test_painter.rb +4 -4
- data/test/test_painter_shape.rb +6 -5
- metadata +8 -7
- data/src/win32/font.h +0 -24
data/.doc/ext/rays/polygon.cpp
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
#include "defs.h"
|
9
9
|
|
10
10
|
|
11
|
-
RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Polygon)
|
11
|
+
RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::Polygon)
|
12
12
|
|
13
13
|
#define THIS to<Rays::Polygon*>(self)
|
14
14
|
|
@@ -26,7 +26,7 @@ VALUE setup(VALUE self, VALUE args, VALUE loop, VALUE colors, VALUE texcoords)
|
|
26
26
|
{
|
27
27
|
CHECK;
|
28
28
|
|
29
|
-
if (args[0].
|
29
|
+
if (args[0].is_a(Rays::polyline_class()))
|
30
30
|
*THIS = to<Rays::Polygon>(args.size(), args.as_array());
|
31
31
|
else
|
32
32
|
{
|
@@ -46,7 +46,7 @@ VALUE expand(VALUE self)
|
|
46
46
|
coord width = to<coord> (argv[0]);
|
47
47
|
Rays::CapType cap = argc >= 2 ? to<Rays::CapType> (argv[1]) : Rays::CAP_DEFAULT;
|
48
48
|
Rays::JoinType join = argc >= 3 ? to<Rays::JoinType>(argv[2]) : Rays::JOIN_DEFAULT;
|
49
|
-
coord ml = argc >= 4 ? to<coord> (argv[3]) : Rays::JOIN_DEFAULT_MITER_LIMIT;
|
49
|
+
coord ml = argc >= 4 ? to<coord> (argv[3]) : (coord) Rays::JOIN_DEFAULT_MITER_LIMIT;
|
50
50
|
|
51
51
|
Rays::Polygon polygon;
|
52
52
|
THIS->expand(&polygon, width, cap, join, ml);
|
@@ -83,7 +83,9 @@ VALUE get_at(VALUE self, VALUE index)
|
|
83
83
|
int i = to<int>(index);
|
84
84
|
if (i < 0) i += size;
|
85
85
|
|
86
|
-
if (i < 0
|
86
|
+
if (i < 0)
|
87
|
+
index_error(__FILE__, __LINE__);
|
88
|
+
if (i >= size)
|
87
89
|
index_error(__FILE__, __LINE__);
|
88
90
|
|
89
91
|
return value((*THIS)[i]);
|
@@ -116,10 +118,10 @@ VALUE op_add(VALUE self, VALUE obj)
|
|
116
118
|
{
|
117
119
|
CHECK;
|
118
120
|
|
119
|
-
if (obj.
|
121
|
+
if (obj.is_a(Rays::polyline_class()))
|
120
122
|
return value(*THIS + to<Rays::Polyline&>(obj));
|
121
123
|
|
122
|
-
if (obj.
|
124
|
+
if (obj.is_a(Rays::polygon_class()))
|
123
125
|
return value(*THIS + to<Rays::Polygon&>(obj));
|
124
126
|
|
125
127
|
if (!obj.is_array())
|
@@ -131,7 +133,7 @@ VALUE op_add(VALUE self, VALUE obj)
|
|
131
133
|
for (const auto& polyline : to<Rays::Polygon&>(self))
|
132
134
|
polylines.emplace_back(polyline);
|
133
135
|
|
134
|
-
if (obj[0].
|
136
|
+
if (obj[0].is_a(Rays::polyline_class()))
|
135
137
|
{
|
136
138
|
each_poly<Rays::Polyline>(obj, [&](const auto& polyline)
|
137
139
|
{
|
@@ -375,14 +377,14 @@ namespace Rucy
|
|
375
377
|
{
|
376
378
|
|
377
379
|
|
378
|
-
template <> Rays::Polygon
|
380
|
+
template <> RAYS_EXPORT Rays::Polygon
|
379
381
|
value_to<Rays::Polygon> (int argc, const Value* argv, bool convert)
|
380
382
|
{
|
381
383
|
if (convert)
|
382
384
|
{
|
383
385
|
if (argc <= 0)
|
384
386
|
return Rays::Polygon();
|
385
|
-
else if (argv->
|
387
|
+
else if (argv->is_a(Rays::polyline_class()))
|
386
388
|
{
|
387
389
|
if (argc == 1)
|
388
390
|
return Rays::Polygon(to<Rays::Polyline&>(*argv));
|
data/.doc/ext/rays/polyline.cpp
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
#include "defs.h"
|
11
11
|
|
12
12
|
|
13
|
-
RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Polyline)
|
13
|
+
RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::Polyline)
|
14
14
|
|
15
15
|
#define THIS to<Rays::Polyline*>(self)
|
16
16
|
|
@@ -44,7 +44,7 @@ VALUE expand(VALUE self)
|
|
44
44
|
coord width = to<coord> (argv[0]);
|
45
45
|
Rays::CapType cap = argc >= 2 ? to<Rays::CapType> (argv[1]) : Rays::CAP_DEFAULT;
|
46
46
|
Rays::JoinType join = argc >= 3 ? to<Rays::JoinType>(argv[2]) : Rays::JOIN_DEFAULT;
|
47
|
-
coord ml = argc >= 4 ? to<coord> (argv[3]) : Rays::JOIN_DEFAULT_MITER_LIMIT;
|
47
|
+
coord ml = argc >= 4 ? to<coord> (argv[3]) : (coord) Rays::JOIN_DEFAULT_MITER_LIMIT;
|
48
48
|
|
49
49
|
Rays::Polygon polygon;
|
50
50
|
THIS->expand(&polygon, width, cap, join, ml);
|
@@ -102,7 +102,9 @@ VALUE get_at(VALUE self, VALUE index)
|
|
102
102
|
int i = to<int>(index);
|
103
103
|
if (i < 0) i += size;
|
104
104
|
|
105
|
-
if (i < 0
|
105
|
+
if (i < 0)
|
106
|
+
index_error(__FILE__, __LINE__);
|
107
|
+
if (i >= size)
|
106
108
|
index_error(__FILE__, __LINE__);
|
107
109
|
|
108
110
|
return value((*THIS)[i]);
|
@@ -206,7 +208,7 @@ namespace Rucy
|
|
206
208
|
{
|
207
209
|
|
208
210
|
|
209
|
-
template <> Rays::Polyline
|
211
|
+
template <> RAYS_EXPORT Rays::Polyline
|
210
212
|
value_to<Rays::Polyline> (int argc, const Value* argv, bool convert)
|
211
213
|
{
|
212
214
|
assert(argc == 0 || (argc > 0 && argv));
|
data/.doc/ext/rays/rays.cpp
CHANGED
@@ -6,11 +6,11 @@
|
|
6
6
|
#include "defs.h"
|
7
7
|
|
8
8
|
|
9
|
-
RUCY_DEFINE_CONVERT_TO(Rays::CapType)
|
10
|
-
RUCY_DEFINE_CONVERT_TO(Rays::JoinType)
|
11
|
-
RUCY_DEFINE_CONVERT_TO(Rays::BlendMode)
|
12
|
-
RUCY_DEFINE_CONVERT_TO(Rays::TexCoordMode)
|
13
|
-
RUCY_DEFINE_CONVERT_TO(Rays::TexCoordWrap)
|
9
|
+
RUCY_DEFINE_CONVERT_TO(RAYS_EXPORT, Rays::CapType)
|
10
|
+
RUCY_DEFINE_CONVERT_TO(RAYS_EXPORT, Rays::JoinType)
|
11
|
+
RUCY_DEFINE_CONVERT_TO(RAYS_EXPORT, Rays::BlendMode)
|
12
|
+
RUCY_DEFINE_CONVERT_TO(RAYS_EXPORT, Rays::TexCoordMode)
|
13
|
+
RUCY_DEFINE_CONVERT_TO(RAYS_EXPORT, Rays::TexCoordWrap)
|
14
14
|
|
15
15
|
|
16
16
|
template <typename T>
|
@@ -102,7 +102,7 @@ namespace Rucy
|
|
102
102
|
{
|
103
103
|
|
104
104
|
|
105
|
-
template <> Rays::CapType
|
105
|
+
template <> RAYS_EXPORT Rays::CapType
|
106
106
|
value_to<Rays::CapType> (int argc, const Value* argv, bool convert)
|
107
107
|
{
|
108
108
|
assert(argc > 0 && argv);
|
@@ -126,14 +126,16 @@ namespace Rucy
|
|
126
126
|
}
|
127
127
|
|
128
128
|
int type = value_to<int>(*argv, convert);
|
129
|
-
if (type < 0
|
129
|
+
if (type < 0)
|
130
|
+
argument_error(__FILE__, __LINE__, "invalid cap type -- %d", type);
|
131
|
+
if (type >= Rays::CAP_MAX)
|
130
132
|
argument_error(__FILE__, __LINE__, "invalid cap type -- %d", type);
|
131
133
|
|
132
134
|
return (Rays::CapType) type;
|
133
135
|
}
|
134
136
|
|
135
137
|
|
136
|
-
template <> Rays::JoinType
|
138
|
+
template <> RAYS_EXPORT Rays::JoinType
|
137
139
|
value_to<Rays::JoinType> (int argc, const Value* argv, bool convert)
|
138
140
|
{
|
139
141
|
assert(argc > 0 && argv);
|
@@ -157,14 +159,16 @@ namespace Rucy
|
|
157
159
|
}
|
158
160
|
|
159
161
|
int type = value_to<int>(*argv, convert);
|
160
|
-
if (type < 0
|
162
|
+
if (type < 0)
|
163
|
+
argument_error(__FILE__, __LINE__, "invalid join type -- %d", type);
|
164
|
+
if (type >= Rays::JOIN_MAX)
|
161
165
|
argument_error(__FILE__, __LINE__, "invalid join type -- %d", type);
|
162
166
|
|
163
167
|
return (Rays::JoinType) type;
|
164
168
|
}
|
165
169
|
|
166
170
|
|
167
|
-
template <> Rays::BlendMode
|
171
|
+
template <> RAYS_EXPORT Rays::BlendMode
|
168
172
|
value_to<Rays::BlendMode> (int argc, const Value* argv, bool convert)
|
169
173
|
{
|
170
174
|
assert(argc > 0 && argv);
|
@@ -188,14 +192,16 @@ namespace Rucy
|
|
188
192
|
}
|
189
193
|
|
190
194
|
int mode = value_to<int>(*argv, convert);
|
191
|
-
if (mode < 0
|
195
|
+
if (mode < 0)
|
196
|
+
argument_error(__FILE__, __LINE__, "invalid blend mode -- %d", mode);
|
197
|
+
if (mode >= Rays::BLEND_MAX)
|
192
198
|
argument_error(__FILE__, __LINE__, "invalid blend mode -- %d", mode);
|
193
199
|
|
194
200
|
return (Rays::BlendMode) mode;
|
195
201
|
}
|
196
202
|
|
197
203
|
|
198
|
-
template <> Rays::TexCoordMode
|
204
|
+
template <> RAYS_EXPORT Rays::TexCoordMode
|
199
205
|
value_to<Rays::TexCoordMode> (int argc, const Value* argv, bool convert)
|
200
206
|
{
|
201
207
|
assert(argc > 0 && argv);
|
@@ -219,14 +225,16 @@ namespace Rucy
|
|
219
225
|
}
|
220
226
|
|
221
227
|
int mode = value_to<int>(*argv, convert);
|
222
|
-
if (mode < 0
|
228
|
+
if (mode < 0)
|
229
|
+
argument_error(__FILE__, __LINE__, "invalid texcoord mode -- %d", mode);
|
230
|
+
if (mode >= Rays::TEXCOORD_MODE_MAX)
|
223
231
|
argument_error(__FILE__, __LINE__, "invalid texcoord mode -- %d", mode);
|
224
232
|
|
225
233
|
return (Rays::TexCoordMode) mode;
|
226
234
|
}
|
227
235
|
|
228
236
|
|
229
|
-
template <> Rays::TexCoordWrap
|
237
|
+
template <> RAYS_EXPORT Rays::TexCoordWrap
|
230
238
|
value_to<Rays::TexCoordWrap> (int argc, const Value* argv, bool convert)
|
231
239
|
{
|
232
240
|
assert(argc > 0 && argv);
|
@@ -250,7 +258,9 @@ namespace Rucy
|
|
250
258
|
}
|
251
259
|
|
252
260
|
int wrap = value_to<int>(*argv, convert);
|
253
|
-
if (wrap < 0
|
261
|
+
if (wrap < 0)
|
262
|
+
argument_error(__FILE__, __LINE__, "invalid texcoord wrap -- %d", wrap);
|
263
|
+
if (wrap >= Rays::TEXCOORD_WRAP_MAX)
|
254
264
|
argument_error(__FILE__, __LINE__, "invalid texcoord wrap -- %d", wrap);
|
255
265
|
|
256
266
|
return (Rays::TexCoordWrap) wrap;
|
data/.doc/ext/rays/shader.cpp
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
#include "defs.h"
|
7
7
|
|
8
8
|
|
9
|
-
RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Shader)
|
9
|
+
RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::Shader)
|
10
10
|
|
11
11
|
#define THIS to<Rays::Shader*>(self)
|
12
12
|
|
@@ -139,7 +139,7 @@ VALUE set_uniform(VALUE self)
|
|
139
139
|
case 4: THIS->set_uniform(name, Af(0), Af(1), Af(2), Af(3)); break;
|
140
140
|
}
|
141
141
|
}
|
142
|
-
else if (argv[0].
|
142
|
+
else if (argv[0].is_a(Rays::image_class()))
|
143
143
|
THIS->set_uniform(name, to<Rays::Image&>(argv[0]));
|
144
144
|
else
|
145
145
|
argument_error(__FILE__, __LINE__);
|
@@ -189,7 +189,7 @@ namespace Rucy
|
|
189
189
|
{
|
190
190
|
|
191
191
|
|
192
|
-
template <> Rays::Shader
|
192
|
+
template <> RAYS_EXPORT Rays::Shader
|
193
193
|
value_to<Rays::Shader> (int argc, const Value* argv, bool convert)
|
194
194
|
{
|
195
195
|
if (argc == 1 && argv->is_array())
|
data/.github/workflows/test.yml
CHANGED
data/ChangeLog.md
CHANGED
data/Gemfile.lock
CHANGED
data/LICENSE
CHANGED
data/Rakefile
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# -*- mode: ruby -*-
|
2
2
|
|
3
|
-
|
4
3
|
%w[../xot ../rucy .]
|
5
4
|
.map {|s| File.expand_path "#{s}/lib", __dir__}
|
6
5
|
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
@@ -15,6 +14,8 @@ require 'rays/extension'
|
|
15
14
|
EXTENSIONS = [Xot, Rucy, Rays]
|
16
15
|
TESTS_ALONE = ['test/test_rays_init.rb']
|
17
16
|
|
17
|
+
install_packages win32: %w[MINGW_PACKAGE_PREFIX-glew]
|
18
|
+
|
18
19
|
use_external_library 'https://github.com/g-truc/glm',
|
19
20
|
tag: '0.9.9.8',
|
20
21
|
srcdirs: 'NOSRC'
|
@@ -32,12 +33,25 @@ use_external_library 'https://github.com/mapbox/earcut.hpp',
|
|
32
33
|
|
33
34
|
use_external_library 'https://github.com/andrewwillmott/splines-lib',
|
34
35
|
commit: '11e7240d57b0d22871aec3308186a5fcf915ba77',
|
35
|
-
excludes: 'Test\.cpp'
|
36
|
+
excludes: 'Test\.cpp',
|
37
|
+
&proc {
|
38
|
+
filter_file('Splines.cpp') do |cpp|
|
39
|
+
<<~EOS + cpp
|
40
|
+
#include <cstdint>
|
41
|
+
EOS
|
42
|
+
end
|
43
|
+
}
|
44
|
+
|
45
|
+
if win32?
|
46
|
+
use_external_library 'https://github.com/nothings/stb',
|
47
|
+
commit: 'ae721c50eaf761660b4f90cc590453cdb0c2acd0',
|
48
|
+
srcdirs: 'NOSRC'
|
49
|
+
end
|
36
50
|
|
37
51
|
default_tasks :ext
|
38
52
|
use_bundler
|
39
53
|
build_native_library
|
40
54
|
build_ruby_extension
|
41
|
-
test_ruby_extension
|
55
|
+
test_ruby_extension unless github_actions? && win32?
|
42
56
|
generate_documents
|
43
57
|
build_ruby_gem
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.1
|
data/ext/rays/bitmap.cpp
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
#include "defs.h"
|
8
8
|
|
9
9
|
|
10
|
-
RUCY_DEFINE_VALUE_FROM_TO(Rays::Bitmap)
|
10
|
+
RUCY_DEFINE_VALUE_FROM_TO(RAYS_EXPORT, Rays::Bitmap)
|
11
11
|
|
12
12
|
#define THIS to<Rays::Bitmap*>(self)
|
13
13
|
|
@@ -323,23 +323,23 @@ set_pixels (Rays::Bitmap* bmp, Value pixels)
|
|
323
323
|
}
|
324
324
|
}
|
325
325
|
|
326
|
-
static inline
|
327
|
-
|
326
|
+
static inline uint32_t
|
327
|
+
to_rgb (uint8_t r, uint8_t g, uint8_t b)
|
328
328
|
{
|
329
|
-
return
|
330
|
-
((
|
331
|
-
((
|
332
|
-
((
|
329
|
+
return
|
330
|
+
((uint32_t) r) << 16 |
|
331
|
+
((uint32_t) g) << 8 |
|
332
|
+
((uint32_t) b);
|
333
333
|
}
|
334
334
|
|
335
|
-
static inline
|
336
|
-
|
335
|
+
static inline uint32_t
|
336
|
+
to_argb (uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
337
337
|
{
|
338
|
-
return
|
339
|
-
((
|
340
|
-
((
|
341
|
-
((
|
342
|
-
((
|
338
|
+
return
|
339
|
+
((uint32_t) a) << 24 |
|
340
|
+
((uint32_t) r) << 16 |
|
341
|
+
((uint32_t) g) << 8 |
|
342
|
+
((uint32_t) b);
|
343
343
|
}
|
344
344
|
|
345
345
|
static void
|
@@ -398,7 +398,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
|
398
398
|
{
|
399
399
|
const auto* p = bmp.at<uint8_t>(0, y);
|
400
400
|
for (int x = 0; x < w; ++x, p += 3)
|
401
|
-
pixels->push_back(
|
401
|
+
pixels->push_back(value(to_rgb(p[0], p[1], p[2])));
|
402
402
|
}
|
403
403
|
break;
|
404
404
|
|
@@ -408,7 +408,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
|
408
408
|
{
|
409
409
|
const auto* p = bmp.at<uint8_t>(0, y);
|
410
410
|
for (int x = 0; x < w; ++x, p += 4)
|
411
|
-
pixels->push_back(
|
411
|
+
pixels->push_back(value(to_argb(p[0], p[1], p[2], p[3])));
|
412
412
|
}
|
413
413
|
break;
|
414
414
|
|
@@ -418,7 +418,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
|
418
418
|
{
|
419
419
|
const auto* p = bmp.at<uint8_t>(0, y);
|
420
420
|
for (int x = 0; x < w; ++x, p += 4)
|
421
|
-
pixels->push_back(
|
421
|
+
pixels->push_back(value(to_argb(p[1], p[2], p[3], p[0])));
|
422
422
|
}
|
423
423
|
break;
|
424
424
|
|
@@ -427,7 +427,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
|
427
427
|
{
|
428
428
|
const auto* p = bmp.at<uint8_t>(0, y);
|
429
429
|
for (int x = 0; x < w; ++x, p += 3)
|
430
|
-
pixels->push_back(
|
430
|
+
pixels->push_back(value(to_rgb(p[2], p[1], p[0])));
|
431
431
|
}
|
432
432
|
break;
|
433
433
|
|
@@ -437,7 +437,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
|
437
437
|
{
|
438
438
|
const auto* p = bmp.at<uint8_t>(0, y);
|
439
439
|
for (int x = 0; x < w; ++x, p += 4)
|
440
|
-
pixels->push_back(
|
440
|
+
pixels->push_back(value(to_argb(p[2], p[1], p[0], p[3])));
|
441
441
|
}
|
442
442
|
break;
|
443
443
|
|
@@ -447,7 +447,7 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
|
447
447
|
{
|
448
448
|
const auto* p = bmp.at<uint8_t>(0, y);
|
449
449
|
for (int x = 0; x < w; ++x, p += 4)
|
450
|
-
pixels->push_back(
|
450
|
+
pixels->push_back(value(to_argb(p[3], p[2], p[1], p[0])));
|
451
451
|
}
|
452
452
|
break;
|
453
453
|
|
@@ -538,17 +538,85 @@ get_pixels (auto* pixels, const Rays::Bitmap& bmp)
|
|
538
538
|
}
|
539
539
|
}
|
540
540
|
|
541
|
-
static
|
542
|
-
|
541
|
+
static Value
|
542
|
+
get_32bit_pixels_string (const Rays::Bitmap& bmp)
|
543
543
|
{
|
544
|
-
|
544
|
+
// avoid SEGV caused by 32bit argb value on 'x64-mingw-ucrt' platform.
|
545
|
+
|
546
|
+
const auto& cs = bmp.color_space();
|
547
|
+
if (cs.bpp() != 32) return nil();
|
548
|
+
|
549
|
+
int w = bmp.width(), h = bmp.height();
|
545
550
|
|
546
|
-
|
551
|
+
std::vector<uint32_t> pixels;
|
552
|
+
pixels.reserve(w * h);
|
553
|
+
|
554
|
+
switch (cs.type())
|
547
555
|
{
|
548
|
-
|
549
|
-
|
556
|
+
case Rays::GRAY_32:
|
557
|
+
case Rays::ALPHA_32:
|
558
|
+
for (int y = 0; y < h; ++y)
|
559
|
+
{
|
560
|
+
const auto* p = bmp.at<uint32_t>(0, y);
|
561
|
+
for (int x = 0; x < w; ++x, ++p)
|
562
|
+
pixels.push_back(*p);
|
563
|
+
}
|
564
|
+
break;
|
565
|
+
|
566
|
+
case Rays::RGBA_8888:
|
567
|
+
case Rays::RGBX_8888:
|
568
|
+
for (int y = 0; y < h; ++y)
|
569
|
+
{
|
570
|
+
const auto* p = bmp.at<uint8_t>(0, y);
|
571
|
+
for (int x = 0; x < w; ++x, p += 4)
|
572
|
+
pixels.push_back(to_argb(p[0], p[1], p[2], p[3]));
|
573
|
+
}
|
574
|
+
break;
|
575
|
+
|
576
|
+
case Rays::ARGB_8888:
|
577
|
+
case Rays::XRGB_8888:
|
578
|
+
for (int y = 0; y < h; ++y)
|
579
|
+
{
|
580
|
+
const auto* p = bmp.at<uint8_t>(0, y);
|
581
|
+
for (int x = 0; x < w; ++x, p += 4)
|
582
|
+
pixels.push_back(to_argb(p[1], p[2], p[3], p[0]));
|
583
|
+
}
|
584
|
+
break;
|
585
|
+
|
586
|
+
case Rays::BGRA_8888:
|
587
|
+
case Rays::BGRX_8888:
|
588
|
+
for (int y = 0; y < h; ++y)
|
589
|
+
{
|
590
|
+
const auto* p = bmp.at<uint8_t>(0, y);
|
591
|
+
for (int x = 0; x < w; ++x, p += 4)
|
592
|
+
pixels.push_back(to_argb(p[2], p[1], p[0], p[3]));
|
593
|
+
}
|
594
|
+
break;
|
595
|
+
|
596
|
+
case Rays::ABGR_8888:
|
597
|
+
case Rays::XBGR_8888:
|
598
|
+
for (int y = 0; y < h; ++y)
|
599
|
+
{
|
600
|
+
const auto* p = bmp.at<uint8_t>(0, y);
|
601
|
+
for (int x = 0; x < w; ++x, p += 4)
|
602
|
+
pixels.push_back(to_argb(p[3], p[2], p[1], p[0]));
|
603
|
+
}
|
604
|
+
break;
|
605
|
+
|
606
|
+
default:
|
607
|
+
return nil();
|
550
608
|
}
|
551
609
|
|
610
|
+
return value(
|
611
|
+
(const char*) &pixels[0], pixels.size() * sizeof(uint32_t),
|
612
|
+
rb_ascii8bit_encoding());
|
613
|
+
}
|
614
|
+
|
615
|
+
static
|
616
|
+
RUCY_DEF1(set_pixels, pixels)
|
617
|
+
{
|
618
|
+
CHECK;
|
619
|
+
|
552
620
|
set_pixels(THIS, pixels);
|
553
621
|
return pixels;
|
554
622
|
}
|
@@ -559,11 +627,10 @@ RUCY_DEF0(get_pixels)
|
|
559
627
|
{
|
560
628
|
CHECK;
|
561
629
|
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
}
|
630
|
+
#ifdef RAYS_32BIT_PIXELS_STRING
|
631
|
+
Value str = get_32bit_pixels_string(*THIS);
|
632
|
+
if (str) return str;
|
633
|
+
#endif
|
567
634
|
|
568
635
|
std::vector<VALUE> pixels;
|
569
636
|
get_pixels(&pixels, *THIS);
|
@@ -613,7 +680,7 @@ Init_rays_bitmap ()
|
|
613
680
|
cBitmap.define_method("height", height);
|
614
681
|
cBitmap.define_method("color_space", color_space);
|
615
682
|
cBitmap.define_method("pixels=", set_pixels);
|
616
|
-
cBitmap.define_method("pixels",
|
683
|
+
cBitmap.define_method("pixels!", get_pixels);
|
617
684
|
cBitmap.define_method("[]=", set_at);
|
618
685
|
cBitmap.define_method("[]", get_at);
|
619
686
|
}
|
data/ext/rays/bounds.cpp
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
#include "defs.h"
|
7
7
|
|
8
8
|
|
9
|
-
RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Bounds)
|
9
|
+
RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::Bounds)
|
10
10
|
|
11
11
|
#define THIS to<Rays::Bounds*>(self)
|
12
12
|
|
@@ -75,7 +75,7 @@ RUCY_DEFN(move_to)
|
|
75
75
|
CHECK;
|
76
76
|
check_arg_count(__FILE__, __LINE__, "Bounds#move_to", argc, 1, 2, 3);
|
77
77
|
|
78
|
-
if (argv[0].
|
78
|
+
if (argv[0].is_a(Rays::point_class()))
|
79
79
|
THIS->move_to(to<Rays::Point&>(argv[0]));
|
80
80
|
else
|
81
81
|
{
|
@@ -102,7 +102,7 @@ RUCY_DEFN(move_by)
|
|
102
102
|
CHECK;
|
103
103
|
check_arg_count(__FILE__, __LINE__, "Bounds#move_by", argc, 1, 2, 3);
|
104
104
|
|
105
|
-
if (argv[0].
|
105
|
+
if (argv[0].is_a(Rays::point_class()))
|
106
106
|
THIS->move_by(to<Rays::Point&>(argv[0]));
|
107
107
|
else
|
108
108
|
{
|
@@ -128,7 +128,7 @@ RUCY_DEFN(resize_to)
|
|
128
128
|
CHECK;
|
129
129
|
check_arg_count(__FILE__, __LINE__, "Bounds#resize_to", argc, 1, 2, 3);
|
130
130
|
|
131
|
-
if (argv[0].
|
131
|
+
if (argv[0].is_a(Rays::point_class()))
|
132
132
|
THIS->resize_to(to<Rays::Point&>(argv[0]));
|
133
133
|
else
|
134
134
|
{
|
@@ -155,7 +155,7 @@ RUCY_DEFN(resize_by)
|
|
155
155
|
CHECK;
|
156
156
|
check_arg_count(__FILE__, __LINE__, "Bounds#resize_by", argc, 1, 2, 3);
|
157
157
|
|
158
|
-
if (argv[0].
|
158
|
+
if (argv[0].is_a(Rays::point_class()))
|
159
159
|
THIS->resize_by(to<Rays::Point&>(argv[0]));
|
160
160
|
else
|
161
161
|
{
|
@@ -181,7 +181,7 @@ RUCY_DEFN(inset_by)
|
|
181
181
|
CHECK;
|
182
182
|
check_arg_count(__FILE__, __LINE__, "Bounds#inset_by", argc, 1, 2, 3);
|
183
183
|
|
184
|
-
if (argv[0].
|
184
|
+
if (argv[0].is_a(Rays::point_class()))
|
185
185
|
THIS->inset_by(to<Rays::Point&>(argv[0]));
|
186
186
|
else
|
187
187
|
{
|
@@ -501,7 +501,9 @@ RUCY_DEF2(set_at, index, value)
|
|
501
501
|
CHECK;
|
502
502
|
|
503
503
|
int i = index.as_i();
|
504
|
-
if (i < 0
|
504
|
+
if (i < 0)
|
505
|
+
index_error(__FILE__, __LINE__);
|
506
|
+
if (i > 1)
|
505
507
|
index_error(__FILE__, __LINE__);
|
506
508
|
|
507
509
|
(*THIS)[i] = to<Rays::Point&>(value);
|
@@ -515,7 +517,9 @@ RUCY_DEF1(get_at, index)
|
|
515
517
|
CHECK;
|
516
518
|
|
517
519
|
int i = index.as_i();
|
518
|
-
if (i < 0
|
520
|
+
if (i < 0)
|
521
|
+
index_error(__FILE__, __LINE__);
|
522
|
+
if (i > 1)
|
519
523
|
index_error(__FILE__, __LINE__);
|
520
524
|
|
521
525
|
return value((*THIS)[i]);
|
@@ -539,9 +543,9 @@ RUCY_DEF1(op_or, arg)
|
|
539
543
|
CHECK;
|
540
544
|
|
541
545
|
Rays::Bounds b = *THIS;
|
542
|
-
if (arg.
|
546
|
+
if (arg.is_a(Rays::bounds_class()))
|
543
547
|
b |= to<Rays::Bounds&>(arg);
|
544
|
-
else if (arg.
|
548
|
+
else if (arg.is_a(Rays::point_class()))
|
545
549
|
b |= to<Rays::Point&>(arg);
|
546
550
|
else
|
547
551
|
argument_error(__FILE__, __LINE__);
|
@@ -629,7 +633,7 @@ namespace Rucy
|
|
629
633
|
{
|
630
634
|
|
631
635
|
|
632
|
-
template <> Rays::Bounds
|
636
|
+
template <> RAYS_EXPORT Rays::Bounds
|
633
637
|
value_to<Rays::Bounds> (int argc, const Value* argv, bool convert)
|
634
638
|
{
|
635
639
|
if (argc == 1 && argv->is_array())
|
@@ -644,7 +648,7 @@ namespace Rucy
|
|
644
648
|
{
|
645
649
|
if (argc == 0)
|
646
650
|
return Rays::Bounds();
|
647
|
-
else if (argv->
|
651
|
+
else if (argv->is_a(Rays::point_class()))
|
648
652
|
{
|
649
653
|
switch (argc)
|
650
654
|
{
|