sfml3-rb 0.2.2 → 0.3.1
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/.yardopts +9 -0
- data/CHANGELOG.md +67 -16
- data/README.md +123 -32
- data/TODO.md +18 -11
- data/ext/audio/audio_enums.c +58 -20
- data/ext/audio/listener.c +89 -6
- data/ext/audio/music.c +212 -5
- data/ext/audio/sound.c +218 -9
- data/ext/audio/sound_buffer.c +197 -47
- data/ext/audio/sound_buffer_recorder.c +90 -18
- data/ext/audio/sound_recorder.c +188 -58
- data/ext/audio/sound_source_cone.c +127 -33
- data/ext/audio/sound_stream.c +204 -21
- data/ext/core/exceptions.c +10 -8
- data/ext/core/unicode.c +12 -2
- data/ext/ext.c +8 -0
- data/ext/graphics/blend_mode.c +218 -60
- data/ext/graphics/circle.c +300 -16
- data/ext/graphics/color.c +253 -94
- data/ext/graphics/drawable.c +16 -4
- data/ext/graphics/font.c +144 -25
- data/ext/graphics/glyph.c +38 -8
- data/ext/graphics/image.c +205 -41
- data/ext/graphics/polygon.c +317 -30
- data/ext/graphics/rect.c +225 -60
- data/ext/graphics/rectangle.c +307 -35
- data/ext/graphics/render_state.c +124 -12
- data/ext/graphics/render_texture.c +191 -14
- data/ext/graphics/render_window.c +55 -0
- data/ext/graphics/render_window.h +10 -0
- data/ext/graphics/shader.c +289 -17
- data/ext/graphics/shape.c +265 -32
- data/ext/graphics/sprite.c +245 -30
- data/ext/graphics/stencil_mode.c +163 -46
- data/ext/graphics/target.c +121 -43
- data/ext/graphics/target.h +31 -17
- data/ext/graphics/text.c +339 -19
- data/ext/graphics/texture.c +291 -6
- data/ext/graphics/transform.c +178 -5
- data/ext/graphics/transformable.c +127 -12
- data/ext/graphics/vertex.c +98 -6
- data/ext/graphics/vertex_array.c +142 -21
- data/ext/graphics/vertex_buffer.c +154 -12
- data/ext/graphics/view.c +140 -6
- data/ext/network/ftp.c +278 -12
- data/ext/network/http.c +179 -44
- data/ext/network/ip_address.c +127 -35
- data/ext/network/network_enums.c +248 -141
- data/ext/network/packet.c +280 -41
- data/ext/network/socket_selector.c +98 -21
- data/ext/network/tcp_listener.c +82 -18
- data/ext/network/tcp_socket.c +135 -27
- data/ext/network/udp_socket.c +129 -28
- data/ext/ports.rb +7 -0
- data/ext/system/buffer.c +47 -16
- data/ext/system/clock.c +77 -12
- data/ext/system/input_stream.c +113 -51
- data/ext/system/sleep.c +10 -2
- data/ext/system/time.c +182 -40
- data/ext/system/vec2.c +166 -39
- data/ext/system/vec3.c +177 -39
- data/ext/window/clipboard.c +47 -17
- data/ext/window/context.c +66 -13
- data/ext/window/context_settings.c +132 -42
- data/ext/window/cursor.c +45 -9
- data/ext/window/event.c +164 -53
- data/ext/window/joystick.c +69 -3
- data/ext/window/keyboard.c +168 -116
- data/ext/window/mouse.c +64 -13
- data/ext/window/sensor.c +28 -2
- data/ext/window/touch.c +32 -12
- data/ext/window/video_mode.c +93 -31
- data/ext/window/vulkan.c +34 -6
- data/ext/window/window.c +228 -229
- data/ext/window/window.h +4 -4
- data/ext/window/window_base.c +251 -0
- data/ext/window/window_base.h +43 -0
- data/ext/window/window_base.inc +236 -0
- data/lib/sfml/version.rb +1 -1
- data/sig/audio/audio_enums.rbs +30 -0
- data/sig/audio/listener.rbs +16 -0
- data/sig/audio/music.rbs +56 -0
- data/sig/audio/sound.rbs +51 -0
- data/sig/audio/sound_buffer.rbs +17 -0
- data/sig/audio/sound_buffer_recorder.rbs +14 -0
- data/sig/audio/sound_recorder.rbs +17 -0
- data/sig/audio/sound_source_cone.rbs +14 -0
- data/sig/audio/sound_stream.rbs +51 -0
- data/sig/graphics/blend_mode.rbs +29 -0
- data/sig/graphics/circle.rbs +44 -0
- data/sig/graphics/color.rbs +39 -0
- data/sig/graphics/drawable.rbs +5 -0
- data/sig/graphics/font.rbs +20 -0
- data/sig/graphics/glyph.rbs +7 -0
- data/sig/graphics/image.rbs +22 -0
- data/sig/graphics/polygon.rbs +42 -0
- data/sig/graphics/rect.rbs +33 -0
- data/sig/graphics/rectangle.rbs +42 -0
- data/sig/graphics/render_state.rbs +21 -0
- data/sig/graphics/render_target.rbs +18 -0
- data/sig/graphics/render_texture.rbs +39 -0
- data/sig/graphics/render_window.rbs +7 -0
- data/sig/graphics/shader.rbs +39 -0
- data/sig/graphics/shape.rbs +38 -0
- data/sig/graphics/sprite.rbs +34 -0
- data/sig/graphics/stencil_mode.rbs +18 -0
- data/sig/graphics/target.rbs +8 -0
- data/sig/graphics/text.rbs +48 -0
- data/sig/graphics/texture.rbs +34 -0
- data/sig/graphics/transform.rbs +37 -0
- data/sig/graphics/transformable.rbs +25 -0
- data/sig/graphics/vertex.rbs +17 -0
- data/sig/graphics/vertex_array.rbs +17 -0
- data/sig/graphics/vertex_buffer.rbs +22 -0
- data/sig/graphics/view.rbs +23 -0
- data/sig/network/ftp.rbs +46 -0
- data/sig/network/http.rbs +27 -0
- data/sig/network/ip_address.rbs +22 -0
- data/sig/network/network_enums.rbs +95 -0
- data/sig/network/packet.rbs +40 -0
- data/sig/network/socket_selector.rbs +14 -0
- data/sig/network/tcp_listener.rbs +13 -0
- data/sig/network/tcp_socket.rbs +18 -0
- data/sig/network/udp_socket.rbs +17 -0
- data/sig/sfml/version.rbs +3 -0
- data/sig/system/buffer.rbs +11 -0
- data/sig/system/clock.rbs +13 -0
- data/sig/system/input_stream.rbs +7 -0
- data/sig/system/sleep.rbs +3 -0
- data/sig/system/time.rbs +28 -0
- data/sig/system/vec2.rbs +26 -0
- data/sig/system/vec3.rbs +27 -0
- data/sig/window/clipboard.rbs +8 -0
- data/sig/window/context.rbs +11 -0
- data/sig/window/context_settings.rbs +20 -0
- data/sig/window/cursor.rbs +6 -0
- data/sig/window/event.rbs +20 -0
- data/sig/window/joystick.rbs +15 -0
- data/sig/window/keyboard.rbs +10 -0
- data/sig/window/mouse.rbs +9 -0
- data/sig/window/sensor.rbs +8 -0
- data/sig/window/touch.rbs +6 -0
- data/sig/window/video_mode.rbs +16 -0
- data/sig/window/vulkan.rbs +7 -0
- data/sig/window/window.rbs +34 -0
- data/sig/window/window_base.rbs +33 -0
- metadata +76 -3
data/ext/graphics/image.c
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#include "graphics/image.h"
|
|
2
2
|
|
|
3
3
|
#include <ruby.h>
|
|
4
|
+
#include <stdint.h>
|
|
4
5
|
#include <stdlib.h>
|
|
5
6
|
|
|
6
7
|
#include "graphics/color.h"
|
|
@@ -13,17 +14,18 @@
|
|
|
13
14
|
|
|
14
15
|
static VALUE rb_cImage;
|
|
15
16
|
|
|
16
|
-
static void Image_free(void
|
|
17
|
-
|
|
17
|
+
static void Image_free(void* ptr) {
|
|
18
|
+
if (ptr != NULL) {
|
|
19
|
+
sfImage_destroy(ptr);
|
|
20
|
+
}
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
static const rb_data_type_t Image_data_type = {
|
|
21
24
|
.wrap_struct_name = "SFML::Image",
|
|
22
25
|
.function = {.dmark = NULL, .dfree = Image_free, .dsize = NULL},
|
|
23
|
-
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
24
|
-
};
|
|
26
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
25
27
|
|
|
26
|
-
static VALUE Image_wrap(VALUE klass, sfImage
|
|
28
|
+
static VALUE Image_wrap(VALUE klass, sfImage* image) {
|
|
27
29
|
if (image == NULL) {
|
|
28
30
|
rb_raise(rb_eRuntimeError, "failed to create image");
|
|
29
31
|
}
|
|
@@ -31,67 +33,174 @@ static VALUE Image_wrap(VALUE klass, sfImage *image) {
|
|
|
31
33
|
return TypedData_Wrap_Struct(klass, &Image_data_type, image);
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
static VALUE
|
|
35
|
-
|
|
36
|
+
static VALUE Image_initialize_copy(VALUE self, VALUE other) {
|
|
37
|
+
(void)other;
|
|
38
|
+
rb_raise(rb_eTypeError, "can't copy a %s", rb_obj_classname(self));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static VALUE Image_alloc(VALUE klass) {
|
|
42
|
+
return TypedData_Wrap_Struct(klass, &Image_data_type, NULL);
|
|
36
43
|
}
|
|
37
44
|
|
|
45
|
+
/* call-seq:
|
|
46
|
+
* Image.new(size) -> Image
|
|
47
|
+
*
|
|
48
|
+
* Creates a black, fully-opaque image of the given size. +size+ is a
|
|
49
|
+
* Vector2 or 2-element Array.
|
|
50
|
+
*
|
|
51
|
+
* @return [Image]
|
|
52
|
+
* @raise [RuntimeError] if the image cannot be created
|
|
53
|
+
*/
|
|
54
|
+
static VALUE Image_initialize(VALUE self, VALUE rb_size) {
|
|
55
|
+
sfImage* image = sfImage_create(vec2u_from_rb(rb_size));
|
|
56
|
+
|
|
57
|
+
if (image == NULL) {
|
|
58
|
+
rb_raise(rb_eRuntimeError, "failed to create image");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
DATA_PTR(self) = image;
|
|
62
|
+
|
|
63
|
+
return self;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* call-seq:
|
|
67
|
+
* Image.from_color(size, color) -> Image
|
|
68
|
+
*
|
|
69
|
+
* Creates an image of the given +size+ filled with +color+.
|
|
70
|
+
*
|
|
71
|
+
* @return [Image]
|
|
72
|
+
* @raise [RuntimeError] if the image cannot be created
|
|
73
|
+
*/
|
|
38
74
|
static VALUE Image_from_color(VALUE klass, VALUE rb_size, VALUE rb_color) {
|
|
39
|
-
return Image_wrap(klass,
|
|
75
|
+
return Image_wrap(klass,
|
|
76
|
+
sfImage_createFromColor(vec2u_from_rb(rb_size), color_from_rb(rb_color)));
|
|
40
77
|
}
|
|
41
78
|
|
|
79
|
+
/* call-seq:
|
|
80
|
+
* Image.from_pixels(size, pixels) -> Image
|
|
81
|
+
*
|
|
82
|
+
* +pixels+ is a String of raw RGBA bytes, at least +width * height * 4+
|
|
83
|
+
* bytes long.
|
|
84
|
+
*
|
|
85
|
+
* @return [Image]
|
|
86
|
+
* @raise [ArgumentError] if +pixels+ is shorter than required
|
|
87
|
+
* @raise [RuntimeError] if the image cannot be created
|
|
88
|
+
*/
|
|
42
89
|
static VALUE Image_from_pixels(VALUE klass, VALUE rb_size, VALUE rb_pixels) {
|
|
43
90
|
sfVector2u size = vec2u_from_rb(rb_size);
|
|
44
|
-
size_t expected
|
|
45
|
-
sfImage
|
|
91
|
+
size_t expected;
|
|
92
|
+
sfImage* image;
|
|
93
|
+
|
|
94
|
+
/* size.x * size.y * 4 as a bare size_t multiplication can wrap on the
|
|
95
|
+
32-bit targets this gem ships, e.g. size.x = size.y = 32768: the true
|
|
96
|
+
product overflows to 0, which would then pass the length check below
|
|
97
|
+
for any input (even an empty string) and hand CSFML a declared size
|
|
98
|
+
far larger than the buffer actually backing it. Check before
|
|
99
|
+
multiplying rather than after. */
|
|
100
|
+
if (size.x != 0 && size.y > (SIZE_MAX / 4) / size.x) {
|
|
101
|
+
rb_raise(rb_eArgError, "image dimensions too large");
|
|
102
|
+
}
|
|
103
|
+
expected = (size_t)size.x * size.y * 4;
|
|
46
104
|
|
|
47
105
|
StringValue(rb_pixels);
|
|
48
106
|
|
|
49
|
-
if ((size_t)
|
|
50
|
-
rb_raise(rb_eArgError, "pixel data too short: expected %lu bytes", (unsigned long)
|
|
107
|
+
if ((size_t)RSTRING_LEN(rb_pixels) < expected) {
|
|
108
|
+
rb_raise(rb_eArgError, "pixel data too short: expected %lu bytes", (unsigned long)expected);
|
|
51
109
|
}
|
|
52
110
|
|
|
53
|
-
image = sfImage_createFromPixels(size, (const uint8_t
|
|
111
|
+
image = sfImage_createFromPixels(size, (const uint8_t*)RSTRING_PTR(rb_pixels));
|
|
54
112
|
|
|
55
113
|
return Image_wrap(klass, image);
|
|
56
114
|
}
|
|
57
115
|
|
|
116
|
+
/* call-seq:
|
|
117
|
+
* Image.from_file(path) -> Image
|
|
118
|
+
*
|
|
119
|
+
* Loads an image from the image file at +filename+.
|
|
120
|
+
*
|
|
121
|
+
* @return [Image]
|
|
122
|
+
* @raise [RuntimeError] if the file cannot be loaded
|
|
123
|
+
*/
|
|
58
124
|
static VALUE Image_from_file(VALUE klass, VALUE rb_path) {
|
|
59
125
|
return Image_wrap(klass, sfImage_createFromFile(StringValueCStr(rb_path)));
|
|
60
126
|
}
|
|
61
127
|
|
|
128
|
+
/* call-seq:
|
|
129
|
+
* Image.from_memory(data) -> Image
|
|
130
|
+
*
|
|
131
|
+
* Loads an image from an in-memory image buffer.
|
|
132
|
+
*
|
|
133
|
+
* @return [Image]
|
|
134
|
+
* @raise [RuntimeError] if the image data cannot be decoded
|
|
135
|
+
*/
|
|
62
136
|
static VALUE Image_from_memory(VALUE klass, VALUE rb_data) {
|
|
63
137
|
StringValue(rb_data);
|
|
64
138
|
|
|
65
|
-
return Image_wrap(klass,
|
|
139
|
+
return Image_wrap(klass,
|
|
140
|
+
sfImage_createFromMemory(RSTRING_PTR(rb_data), (size_t)RSTRING_LEN(rb_data)));
|
|
66
141
|
}
|
|
67
142
|
|
|
143
|
+
/* call-seq:
|
|
144
|
+
* Image.from_stream(stream) -> Image
|
|
145
|
+
*
|
|
146
|
+
* +stream+ is any object responding to the InputStream protocol (see
|
|
147
|
+
* InputStream).
|
|
148
|
+
*
|
|
149
|
+
* @return [Image]
|
|
150
|
+
* @raise [RuntimeError] if the image cannot be loaded
|
|
151
|
+
*/
|
|
68
152
|
static VALUE Image_from_stream(VALUE klass, VALUE rb_stream) {
|
|
69
153
|
VALUE holder = Qnil;
|
|
70
|
-
sfInputStream
|
|
154
|
+
sfInputStream* stream = input_stream_from_rb(rb_stream, &holder);
|
|
71
155
|
|
|
72
|
-
(void)
|
|
156
|
+
(void)holder;
|
|
73
157
|
|
|
74
158
|
return Image_wrap(klass, sfImage_createFromStream(stream));
|
|
75
159
|
}
|
|
76
160
|
|
|
161
|
+
/* call-seq: copy -> Image
|
|
162
|
+
*
|
|
163
|
+
* Returns a deep copy of the object.
|
|
164
|
+
*
|
|
165
|
+
* @return [Image] an independent copy
|
|
166
|
+
*/
|
|
77
167
|
static VALUE Image_copy(VALUE self) {
|
|
78
168
|
return Image_wrap(Get_Klass_Image(), sfImage_copy(Get_Image_Struct(self)));
|
|
79
169
|
}
|
|
80
170
|
|
|
171
|
+
/* call-seq: size -> Vector2
|
|
172
|
+
*
|
|
173
|
+
* Returns the object's size.
|
|
174
|
+
*
|
|
175
|
+
* @return [Vector2] the image's dimensions in pixels
|
|
176
|
+
*/
|
|
81
177
|
static VALUE Image_get_size(VALUE self) {
|
|
82
|
-
return vec2f_to_rb((sfVector2f)
|
|
83
|
-
|
|
84
|
-
(float) sfImage_getSize(Get_Image_Struct(self)).y
|
|
85
|
-
});
|
|
178
|
+
return vec2f_to_rb((sfVector2f){(float)sfImage_getSize(Get_Image_Struct(self)).x,
|
|
179
|
+
(float)sfImage_getSize(Get_Image_Struct(self)).y});
|
|
86
180
|
}
|
|
87
181
|
|
|
182
|
+
/* call-seq: save_to_file(path) -> true or false
|
|
183
|
+
*
|
|
184
|
+
* The format is deduced from +path+'s extension.
|
|
185
|
+
*
|
|
186
|
+
* @return [Boolean] whether the save succeeded
|
|
187
|
+
*/
|
|
88
188
|
static VALUE Image_save_to_file(VALUE self, VALUE rb_path) {
|
|
89
189
|
return BOOL2RB(sfImage_saveToFile(Get_Image_Struct(self), StringValueCStr(rb_path)));
|
|
90
190
|
}
|
|
91
191
|
|
|
92
|
-
|
|
192
|
+
/* call-seq:
|
|
193
|
+
* save_to_memory(format = "png") -> Buffer or nil
|
|
194
|
+
*
|
|
195
|
+
* +format+ is an image file extension without the dot (e.g. +"png"+,
|
|
196
|
+
* +"bmp"+, +"tga"+, +"jpg"+).
|
|
197
|
+
*
|
|
198
|
+
* @return [Buffer, nil] the encoded image data, or +nil+ if encoding failed
|
|
199
|
+
* @raise [ArgumentError] if given more than one argument
|
|
200
|
+
*/
|
|
201
|
+
static VALUE Image_save_to_memory(int argc, VALUE* argv, VALUE self) {
|
|
93
202
|
VALUE rb_buffer;
|
|
94
|
-
const char
|
|
203
|
+
const char* format = "png";
|
|
95
204
|
if (argc > 1) {
|
|
96
205
|
raise_invalid_arguments_excepted(1, argc);
|
|
97
206
|
}
|
|
@@ -109,12 +218,28 @@ static VALUE Image_save_to_memory(int argc, VALUE *argv, VALUE self) {
|
|
|
109
218
|
return Qnil;
|
|
110
219
|
}
|
|
111
220
|
|
|
221
|
+
/* call-seq: create_mask_from_color(color, alpha) -> self
|
|
222
|
+
*
|
|
223
|
+
* Sets the alpha channel of every pixel matching +color+ to +alpha+.
|
|
224
|
+
*
|
|
225
|
+
* @return [self]
|
|
226
|
+
*/
|
|
112
227
|
static VALUE Image_create_mask_from_color(VALUE self, VALUE rb_color, VALUE rb_alpha) {
|
|
113
|
-
sfImage_createMaskFromColor((sfImage
|
|
228
|
+
sfImage_createMaskFromColor((sfImage*)Get_Image_Struct(self), color_from_rb(rb_color),
|
|
229
|
+
(uint8_t)NUM2INT(rb_alpha));
|
|
114
230
|
return self;
|
|
115
231
|
}
|
|
116
232
|
|
|
117
|
-
|
|
233
|
+
/* call-seq:
|
|
234
|
+
* copy_image(source, dest, source_rect = Rect.new, apply_alpha = true) -> true or false
|
|
235
|
+
*
|
|
236
|
+
* Copies pixels from +source+ (an Image) onto +self+ at position +dest+.
|
|
237
|
+
* +source_rect+ restricts the copied region; an empty/zero rect copies the
|
|
238
|
+
* whole source image.
|
|
239
|
+
*
|
|
240
|
+
* @return [Boolean] whether the copy succeeded
|
|
241
|
+
*/
|
|
242
|
+
static VALUE Image_copy_image(int argc, VALUE* argv, VALUE self) {
|
|
118
243
|
VALUE rb_source, rb_dest, rb_source_rect, rb_apply_alpha;
|
|
119
244
|
bool apply_alpha = true;
|
|
120
245
|
|
|
@@ -128,49 +253,88 @@ static VALUE Image_copy_image(int argc, VALUE *argv, VALUE self) {
|
|
|
128
253
|
apply_alpha = RTEST(rb_apply_alpha);
|
|
129
254
|
}
|
|
130
255
|
|
|
131
|
-
return BOOL2RB(sfImage_copyImage((sfImage
|
|
132
|
-
vec2u_from_rb(rb_dest), int_rect_from_rb(rb_source_rect),
|
|
256
|
+
return BOOL2RB(sfImage_copyImage((sfImage*)Get_Image_Struct(self), Get_Image_Struct(rb_source),
|
|
257
|
+
vec2u_from_rb(rb_dest), int_rect_from_rb(rb_source_rect),
|
|
258
|
+
apply_alpha));
|
|
133
259
|
}
|
|
134
260
|
|
|
261
|
+
/* call-seq: pixel(x, y) -> Color
|
|
262
|
+
*
|
|
263
|
+
* Returns the color of the pixel at +x+, +y+.
|
|
264
|
+
*
|
|
265
|
+
* @return [Color] the color of the pixel at (+x+, +y+)
|
|
266
|
+
*/
|
|
135
267
|
static VALUE Image_get_pixel(VALUE self, VALUE rb_x, VALUE rb_y) {
|
|
136
|
-
sfColor color = sfImage_getPixel(
|
|
137
|
-
|
|
268
|
+
sfColor color = sfImage_getPixel(
|
|
269
|
+
Get_Image_Struct(self), (sfVector2u){(unsigned)NUM2UINT(rb_x), (unsigned)NUM2UINT(rb_y)});
|
|
138
270
|
|
|
139
271
|
return color_to_rb(color);
|
|
140
272
|
}
|
|
141
273
|
|
|
274
|
+
/* call-seq: set_pixel(x, y, color) -> self
|
|
275
|
+
*
|
|
276
|
+
* Sets the color of the pixel at +x+, +y+.
|
|
277
|
+
*
|
|
278
|
+
* @return [self]
|
|
279
|
+
*/
|
|
142
280
|
static VALUE Image_set_pixel(VALUE self, VALUE rb_x, VALUE rb_y, VALUE rb_color) {
|
|
143
|
-
sfImage_setPixel((sfImage
|
|
144
|
-
(sfVector2u)
|
|
281
|
+
sfImage_setPixel((sfImage*)Get_Image_Struct(self),
|
|
282
|
+
(sfVector2u){(unsigned)NUM2UINT(rb_x), (unsigned)NUM2UINT(rb_y)},
|
|
283
|
+
color_from_rb(rb_color));
|
|
145
284
|
return self;
|
|
146
285
|
}
|
|
147
286
|
|
|
287
|
+
/* call-seq: pixels -> String
|
|
288
|
+
*
|
|
289
|
+
* Returns a flat array of the image's pixels.
|
|
290
|
+
*
|
|
291
|
+
* @return [String] the raw RGBA pixel data, +width * height * 4+ bytes,
|
|
292
|
+
* row-major starting from the top-left
|
|
293
|
+
*/
|
|
148
294
|
static VALUE Image_get_pixels(VALUE self) {
|
|
149
|
-
const sfImage
|
|
295
|
+
const sfImage* image = Get_Image_Struct(self);
|
|
150
296
|
sfVector2u size = sfImage_getSize(image);
|
|
151
|
-
const uint8_t
|
|
297
|
+
const uint8_t* pixels = sfImage_getPixelsPtr(image);
|
|
152
298
|
|
|
153
299
|
if (pixels == NULL) {
|
|
154
300
|
return rb_str_new("", 0);
|
|
155
301
|
}
|
|
156
302
|
|
|
157
|
-
return rb_str_new((const char
|
|
303
|
+
return rb_str_new((const char*)pixels, (long)(size.x * size.y * 4));
|
|
158
304
|
}
|
|
159
305
|
|
|
306
|
+
/* call-seq: flip_horizontally! -> self
|
|
307
|
+
*
|
|
308
|
+
* Flips the image horizontally.
|
|
309
|
+
*
|
|
310
|
+
* @return [self]
|
|
311
|
+
*/
|
|
160
312
|
static VALUE Image_flip_horizontally(VALUE self) {
|
|
161
|
-
sfImage_flipHorizontally((sfImage
|
|
313
|
+
sfImage_flipHorizontally((sfImage*)Get_Image_Struct(self));
|
|
162
314
|
return self;
|
|
163
315
|
}
|
|
164
316
|
|
|
317
|
+
/* call-seq: flip_vertically! -> self
|
|
318
|
+
*
|
|
319
|
+
* Flips the image vertically.
|
|
320
|
+
*
|
|
321
|
+
* @return [self]
|
|
322
|
+
*/
|
|
165
323
|
static VALUE Image_flip_vertically(VALUE self) {
|
|
166
|
-
sfImage_flipVertically((sfImage
|
|
324
|
+
sfImage_flipVertically((sfImage*)Get_Image_Struct(self));
|
|
167
325
|
return self;
|
|
168
326
|
}
|
|
169
327
|
|
|
170
|
-
|
|
171
|
-
|
|
328
|
+
/* Document-class: SFML::Image
|
|
329
|
+
* A 2D array of RGBA pixels, held in RAM (as opposed to Texture, which is
|
|
330
|
+
* GPU-side). Used for loading, editing and saving raw pixel data.
|
|
331
|
+
*/
|
|
332
|
+
void Init_Image(VALUE rb_mSFML) {
|
|
333
|
+
rb_cImage = rb_define_class_under(rb_mSFML, "Image", rb_cObject);
|
|
172
334
|
|
|
173
|
-
|
|
335
|
+
rb_define_alloc_func(rb_cImage, Image_alloc);
|
|
336
|
+
rb_define_method(rb_cImage, "initialize", Image_initialize, 1);
|
|
337
|
+
rb_define_private_method(rb_cImage, "initialize_copy", Image_initialize_copy, 1);
|
|
174
338
|
rb_define_singleton_method(rb_cImage, "from_color", Image_from_color, 2);
|
|
175
339
|
rb_define_singleton_method(rb_cImage, "from_pixels", Image_from_pixels, 2);
|
|
176
340
|
rb_define_singleton_method(rb_cImage, "from_file", Image_from_file, 1);
|
|
@@ -194,12 +358,12 @@ VALUE Get_Klass_Image(void) {
|
|
|
194
358
|
return rb_cImage;
|
|
195
359
|
}
|
|
196
360
|
|
|
197
|
-
const sfImage
|
|
198
|
-
sfImage
|
|
361
|
+
const sfImage* Get_Image_Struct(VALUE self) {
|
|
362
|
+
sfImage* ptr;
|
|
199
363
|
TypedData_Get_Struct(self, sfImage, &Image_data_type, ptr);
|
|
200
364
|
return ptr;
|
|
201
365
|
}
|
|
202
366
|
|
|
203
|
-
VALUE image_from_c(sfImage
|
|
367
|
+
VALUE image_from_c(sfImage* image) {
|
|
204
368
|
return Image_wrap(Get_Klass_Image(), image);
|
|
205
369
|
}
|