texplay 0.4.3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/CHANGELOG +222 -0
- data/README.markdown +48 -0
- data/Rakefile +16 -0
- data/examples/common.rb +18 -0
- data/examples/example_alpha_blend.rb +29 -0
- data/examples/example_bezier.rb +41 -0
- data/examples/example_blank.rb +37 -0
- data/examples/example_cache.rb +21 -0
- data/examples/example_color_control.rb +69 -0
- data/examples/example_color_transform.rb +62 -0
- data/examples/example_color_transform_circle.rb +34 -0
- data/examples/example_darken.rb +24 -0
- data/examples/example_dup.rb +73 -0
- data/examples/example_each.rb +39 -0
- data/examples/example_effect.rb +34 -0
- data/examples/example_fill.rb +43 -0
- data/examples/example_fill_old.rb +48 -0
- data/examples/example_fluent.rb +29 -0
- data/examples/example_font.rb +31 -0
- data/examples/example_hash_arguments.rb +46 -0
- data/examples/example_ippa.rb +23 -0
- data/examples/example_light.rb +75 -0
- data/examples/example_light_multiply.rb +18 -0
- data/examples/example_lsystem.rb +61 -0
- data/examples/example_melt.rb +25 -0
- data/examples/example_meyet.rb +62 -0
- data/examples/example_polyline.rb +42 -0
- data/examples/example_scale.rb +27 -0
- data/examples/example_select.rb +36 -0
- data/examples/example_select2.rb +25 -0
- data/examples/example_simple.rb +46 -0
- data/examples/example_splice.rb +26 -0
- data/examples/example_sync.rb +59 -0
- data/examples/example_tiles.rb +41 -0
- data/examples/example_trace.rb +22 -0
- data/examples/example_transparent.rb +28 -0
- data/examples/example_transparent2.rb +24 -0
- data/examples/example_transparent3.rb +20 -0
- data/examples/example_turtle.rb +39 -0
- data/examples/example_weird.rb +22 -0
- data/examples/example_window_render_to_image.rb +41 -0
- data/examples/example_window_to_blob.rb +35 -0
- data/examples/media/bird.png +0 -0
- data/examples/media/body.png +0 -0
- data/examples/media/empty2.png +0 -0
- data/examples/media/face.png +0 -0
- data/examples/media/gob.png +0 -0
- data/examples/media/gosu.png +0 -0
- data/examples/media/green.png +0 -0
- data/examples/media/logo.png +0 -0
- data/examples/media/maria.png +0 -0
- data/examples/media/object.png +0 -0
- data/examples/media/rose.bmp +0 -0
- data/examples/media/sand1.png +0 -0
- data/examples/media/sunset.png +0 -0
- data/examples/media/texplay.png +0 -0
- data/ext/texplay/actions.c +1006 -0
- data/ext/texplay/actions.h +60 -0
- data/ext/texplay/bindings.c +1125 -0
- data/ext/texplay/bindings.h +46 -0
- data/ext/texplay/cache.c +118 -0
- data/ext/texplay/cache.h +24 -0
- data/ext/texplay/compat.h +27 -0
- data/ext/texplay/extconf.rb +38 -0
- data/ext/texplay/graphics_utils.c +1313 -0
- data/ext/texplay/graphics_utils.h +22 -0
- data/ext/texplay/texplay.c +201 -0
- data/ext/texplay/texplay.h +153 -0
- data/ext/texplay/utils.c +891 -0
- data/ext/texplay/utils.h +153 -0
- data/ext/texplay/vendor/freeglut/include/GL/freeglut.h +22 -0
- data/ext/texplay/vendor/freeglut/include/GL/freeglut_ext.h +236 -0
- data/ext/texplay/vendor/freeglut/include/GL/freeglut_std.h +628 -0
- data/ext/texplay/vendor/freeglut/include/GL/glut.h +21 -0
- data/lib/texplay-contrib.rb +147 -0
- data/lib/texplay.rb +347 -0
- data/lib/texplay/1.8/texplay.so +0 -0
- data/lib/texplay/1.9/texplay.so +0 -0
- data/lib/texplay/alone.rb +20 -0
- data/lib/texplay/c_function_docs.rb +178 -0
- data/lib/texplay/live.rb +84 -0
- data/lib/texplay/version.rb +3 -0
- data/live/live.rb +85 -0
- data/test/image_spec.rb +45 -0
- data/test/texplay_spec.rb +144 -0
- metadata +179 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
#ifndef GUARD_ACTIONS_H
|
2
|
+
#define GUARD_ACTIONS_H
|
3
|
+
|
4
|
+
#include "texplay.h"
|
5
|
+
|
6
|
+
/* used by line_do_action */
|
7
|
+
typedef struct {
|
8
|
+
int x, y;
|
9
|
+
rgba color;
|
10
|
+
} trace_match;
|
11
|
+
|
12
|
+
|
13
|
+
/* lines */
|
14
|
+
trace_match line_do_action(int, int, int, int, texture_info *, VALUE, sync, bool primary, action_struct * payload);
|
15
|
+
|
16
|
+
/* circles */
|
17
|
+
void circle_do_action(int, int, int, texture_info *, VALUE, sync, bool primary, action_struct * payload);
|
18
|
+
|
19
|
+
/* pixels */
|
20
|
+
void pixel_do_action(int, int, texture_info *, VALUE, sync, bool primary, action_struct * payload);
|
21
|
+
|
22
|
+
/* rectangles */
|
23
|
+
void rect_do_action(int x1, int y1, int x2, int y2, texture_info * tex, VALUE hash_arg,
|
24
|
+
sync sync_mode, bool primary, action_struct * payload);
|
25
|
+
|
26
|
+
/* flood fill */
|
27
|
+
void flood_fill_do_action(int x, int y, texture_info * tex, VALUE hash_arg, sync sync_mode, bool primary,
|
28
|
+
action_struct * payload);
|
29
|
+
|
30
|
+
/* glow fill */
|
31
|
+
void glow_fill_do_action(int x, int y, texture_info * tex, VALUE hash_arg, sync sync_mode, bool primary,
|
32
|
+
action_struct * payload);
|
33
|
+
|
34
|
+
/* scan fill */
|
35
|
+
void scan_fill_do_action(int x, int y, texture_info * tex, VALUE hash_arg,
|
36
|
+
sync sync_mode, bool primary, action_struct * payload);
|
37
|
+
|
38
|
+
/* polyline */
|
39
|
+
void polyline_do_action(VALUE points, texture_info * tex, VALUE hash_arg, sync sync_mode, bool primary,
|
40
|
+
action_struct * payload);
|
41
|
+
|
42
|
+
/* bezier */
|
43
|
+
void bezier_do_action(VALUE points, texture_info * tex, VALUE hash_arg, sync sync_mode, bool primary,
|
44
|
+
action_struct * payload);
|
45
|
+
|
46
|
+
/* ngon */
|
47
|
+
void ngon_do_action(int x, int y, int r, int num_sides, texture_info * tex, VALUE hash_arg,
|
48
|
+
sync sync_mode, bool primary, action_struct * payload);
|
49
|
+
|
50
|
+
|
51
|
+
/* splice */
|
52
|
+
void splice_do_action(int x0,int y0, int cx1, int cy1, int cx2, int cy2, texture_info * splice_tex,
|
53
|
+
texture_info * tex, VALUE hash_arg, sync sync_mode,
|
54
|
+
bool primary, action_struct * payload);
|
55
|
+
|
56
|
+
/* each iterator */
|
57
|
+
void each_pixel_do_action(int x1, int y1, int x2, int y2, VALUE proc, texture_info * tex, VALUE hash_arg,
|
58
|
+
sync sync_mode, bool primary, action_struct * payload);
|
59
|
+
|
60
|
+
#endif
|
@@ -0,0 +1,1125 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <string.h>
|
4
|
+
#include <ctype.h>
|
5
|
+
#include <math.h>
|
6
|
+
#include <stdlib.h>
|
7
|
+
#include <assert.h>
|
8
|
+
#include <stdarg.h>
|
9
|
+
|
10
|
+
#ifdef __APPLE__
|
11
|
+
# include <glut.h>
|
12
|
+
#else
|
13
|
+
# include <GL/glut.h>
|
14
|
+
#endif
|
15
|
+
|
16
|
+
#include "texplay.h"
|
17
|
+
#include "utils.h"
|
18
|
+
#include "graphics_utils.h"
|
19
|
+
#include "bindings.h"
|
20
|
+
#include "actions.h"
|
21
|
+
#include "cache.h"
|
22
|
+
#include "compat.h"
|
23
|
+
|
24
|
+
/* syncing mode */
|
25
|
+
/* lazy_sync = sync at end of paint block */
|
26
|
+
/* eager_sync = sync immediately (after action) */
|
27
|
+
/* no_sync = do not sync at all */
|
28
|
+
sync sync_mode = eager_sync;
|
29
|
+
|
30
|
+
static void
|
31
|
+
process_x_y_pairs(VALUE image, int num_pairs, VALUE * argv, ...)
|
32
|
+
{
|
33
|
+
va_list ap;
|
34
|
+
int i;
|
35
|
+
int draw_offset_x;
|
36
|
+
int draw_offset_y;
|
37
|
+
VALUE offset_val;
|
38
|
+
|
39
|
+
offset_val = get_image_local(image, DRAW_OFFSET);
|
40
|
+
|
41
|
+
draw_offset_x = NUM2INT(get_from_array(offset_val, 0));
|
42
|
+
draw_offset_y = NUM2INT(get_from_array(offset_val, 1));
|
43
|
+
|
44
|
+
va_start(ap, argv);
|
45
|
+
if(is_a_point(argv[0])) {
|
46
|
+
for(i = 0; i < num_pairs; i++) {
|
47
|
+
int *x_ptr, *y_ptr;
|
48
|
+
|
49
|
+
x_ptr = va_arg(ap, int*);
|
50
|
+
y_ptr = va_arg(ap, int*);
|
51
|
+
|
52
|
+
*x_ptr = NUM2INT(rb_funcall(argv[i], rb_intern("x"), 0)) + draw_offset_x;
|
53
|
+
*y_ptr = NUM2INT(rb_funcall(argv[i], rb_intern("y"), 0)) + draw_offset_y;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
else {
|
57
|
+
for(i = 0; i < (num_pairs * 2); i+=2) {
|
58
|
+
int *x_ptr, *y_ptr;
|
59
|
+
|
60
|
+
x_ptr = va_arg(ap, int*);
|
61
|
+
y_ptr = va_arg(ap, int*);
|
62
|
+
|
63
|
+
*x_ptr = NUM2INT(argv[i]) + draw_offset_x;
|
64
|
+
*y_ptr = NUM2INT(argv[i + 1]) + draw_offset_y;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
va_end(ap);
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
/* singleton methods */
|
72
|
+
|
73
|
+
/* responsible for creating macros */
|
74
|
+
VALUE
|
75
|
+
M_create_macro(VALUE self, VALUE method_name)
|
76
|
+
{
|
77
|
+
VALUE proc;
|
78
|
+
|
79
|
+
rb_need_block();
|
80
|
+
|
81
|
+
/* convert the block to a proc */
|
82
|
+
proc = rb_block_proc();
|
83
|
+
|
84
|
+
/* define the method in the TexPlay class so that it is accessible to 'instances' */
|
85
|
+
rb_funcall(self, rb_intern("define_method"), 2, method_name, proc);
|
86
|
+
|
87
|
+
return Qnil;
|
88
|
+
}
|
89
|
+
|
90
|
+
|
91
|
+
/* responsible for removing macros */
|
92
|
+
VALUE
|
93
|
+
M_remove_macro(VALUE self, VALUE method_name)
|
94
|
+
{
|
95
|
+
|
96
|
+
/* remove the method in the TexPlay class */
|
97
|
+
rb_funcall(self, rb_intern("remove_method"), 1, method_name);
|
98
|
+
|
99
|
+
return Qnil;
|
100
|
+
}
|
101
|
+
|
102
|
+
/* responsible for refreshing all entries in cache */
|
103
|
+
VALUE
|
104
|
+
M_refresh_cache_all(VALUE self)
|
105
|
+
{
|
106
|
+
cache_refresh_all();
|
107
|
+
|
108
|
+
return Qnil;
|
109
|
+
}
|
110
|
+
|
111
|
+
/* VALUE */
|
112
|
+
/* M_screenshot(VALUE self, VALUE x, VALUE y, VALUE width, VALUE width) */
|
113
|
+
/* { */
|
114
|
+
/* texture_info tex; */
|
115
|
+
/* int sidelength; */
|
116
|
+
/* int rb_x = FIX2INT(x); */
|
117
|
+
/* int rb_y = FIX2INT(y); */
|
118
|
+
/* int rb_width = FIX2INT(width); */
|
119
|
+
/* int rb_height = FIX2INT(height); */
|
120
|
+
|
121
|
+
/* VALUE blob = rb_str_new(NULL, 4 * rb_width * rb_height); */
|
122
|
+
|
123
|
+
/* glReadPixels(rb_x, rb_y, rb_width, rb_height, GL_RGBA, GL_UNSIGNED_BYTE, RSTRING_PTR(blob)); */
|
124
|
+
|
125
|
+
/* return blob; */
|
126
|
+
/* } */
|
127
|
+
|
128
|
+
|
129
|
+
/* creates a blank image */
|
130
|
+
/* VALUE */
|
131
|
+
/* M_create_blank(VALUE self, VALUE window, VALUE width, VALUE height) */
|
132
|
+
/* { */
|
133
|
+
/* VALUE fresh_image; */
|
134
|
+
|
135
|
+
/* fresh_image = create_image(window, NUM2INT(width), NUM2INT(height)); */
|
136
|
+
|
137
|
+
/* return fresh_image; */
|
138
|
+
/* } */
|
139
|
+
/** end singleton methods **/
|
140
|
+
|
141
|
+
/* some helper methods */
|
142
|
+
static void
|
143
|
+
rb_lazy_bounds_to_image_bounds(VALUE image, image_bounds * bounds)
|
144
|
+
{
|
145
|
+
VALUE lazy_bounds;
|
146
|
+
|
147
|
+
lazy_bounds = get_image_local(image, LAZY_BOUNDS);
|
148
|
+
|
149
|
+
Check_Type(lazy_bounds, T_ARRAY);
|
150
|
+
|
151
|
+
bounds->xmin = FIX2INT(get_from_array(lazy_bounds, 0));
|
152
|
+
bounds->ymin = FIX2INT(get_from_array(lazy_bounds, 1));
|
153
|
+
bounds->xmax = FIX2INT(get_from_array(lazy_bounds, 2));
|
154
|
+
bounds->ymax = FIX2INT(get_from_array(lazy_bounds, 3));
|
155
|
+
}
|
156
|
+
|
157
|
+
static VALUE
|
158
|
+
parse_sync_mode(VALUE user_sync_mode)
|
159
|
+
{
|
160
|
+
sync mode;
|
161
|
+
|
162
|
+
Check_Type(user_sync_mode, T_SYMBOL);
|
163
|
+
|
164
|
+
if(user_sync_mode == string2sym("lazy_sync"))
|
165
|
+
mode = lazy_sync;
|
166
|
+
else if(user_sync_mode == string2sym("eager_sync"))
|
167
|
+
mode = eager_sync;
|
168
|
+
else if(user_sync_mode == string2sym("no_sync"))
|
169
|
+
mode = no_sync;
|
170
|
+
else
|
171
|
+
rb_raise(rb_eArgError, "unrecognized sync mode: %s\n. Allowable modes are "
|
172
|
+
":lazy_sync, :eager_sync, :no_sync.",
|
173
|
+
sym2string(user_sync_mode));
|
174
|
+
|
175
|
+
return mode;
|
176
|
+
}
|
177
|
+
/* end helpers */
|
178
|
+
|
179
|
+
/* entry point for TexPlay paint actions */
|
180
|
+
VALUE
|
181
|
+
m_paint(int argc, VALUE * argv, VALUE self)
|
182
|
+
{
|
183
|
+
texture_info tex;
|
184
|
+
VALUE options;
|
185
|
+
image_bounds bounds;
|
186
|
+
int arity;
|
187
|
+
|
188
|
+
rb_scan_args(argc, argv, "01", &options);
|
189
|
+
|
190
|
+
/* get texture info from image */
|
191
|
+
get_texture_info(self, &tex);
|
192
|
+
|
193
|
+
/* set default sync_mode to lazy */
|
194
|
+
sync_mode = lazy_sync;
|
195
|
+
|
196
|
+
/* parse sync_mode, overriding lazy sync mode? */
|
197
|
+
if(has_optional_hash_arg(options, "sync_mode")) {
|
198
|
+
VALUE user_sync_mode = get_from_hash(options, "sync_mode");
|
199
|
+
sync_mode = parse_sync_mode(user_sync_mode);
|
200
|
+
}
|
201
|
+
|
202
|
+
/* if no block then just sync */
|
203
|
+
if(!rb_block_given_p()) {
|
204
|
+
|
205
|
+
rb_lazy_bounds_to_image_bounds(self, &bounds);
|
206
|
+
|
207
|
+
create_subtexture_and_sync_to_gl(&bounds, &tex);
|
208
|
+
|
209
|
+
/* reset the LAZY_BOUNDS now we've sync'd */
|
210
|
+
set_image_local(self, LAZY_BOUNDS, Qnil);
|
211
|
+
|
212
|
+
sync_mode = eager_sync;
|
213
|
+
|
214
|
+
return self;
|
215
|
+
}
|
216
|
+
|
217
|
+
/* find arity of block */
|
218
|
+
arity = FIX2INT(rb_funcall(rb_block_proc(), rb_intern("arity"), 0));
|
219
|
+
|
220
|
+
/* yield self if the arity is 1, else instance_eval the block */
|
221
|
+
switch(arity) {
|
222
|
+
case -1:
|
223
|
+
case 0:
|
224
|
+
rb_obj_instance_eval(0, 0, self);
|
225
|
+
break;
|
226
|
+
case 1:
|
227
|
+
rb_yield(self);
|
228
|
+
break;
|
229
|
+
default:
|
230
|
+
rb_raise(rb_eArgError, "block arity must be either 1 or -1 or 0, received arity of: %d", arity);
|
231
|
+
}
|
232
|
+
|
233
|
+
/* if lazy sync is selected then sync now..as the paint block has finished executing the draw actions*/
|
234
|
+
if(sync_mode == lazy_sync) {
|
235
|
+
|
236
|
+
rb_lazy_bounds_to_image_bounds(self, &bounds);
|
237
|
+
|
238
|
+
create_subtexture_and_sync_to_gl(&bounds, &tex);
|
239
|
+
|
240
|
+
/* reset the LAZY_BOUNDS now we've sync'd */
|
241
|
+
set_image_local(self, LAZY_BOUNDS, Qnil);
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
/* now we've finished the paint block we reset the default sync_mode back to eager */
|
246
|
+
sync_mode = eager_sync;
|
247
|
+
|
248
|
+
return self;
|
249
|
+
}
|
250
|
+
|
251
|
+
VALUE
|
252
|
+
m_force_sync(VALUE self, VALUE ary)
|
253
|
+
{
|
254
|
+
image_bounds bounds;
|
255
|
+
texture_info tex;
|
256
|
+
|
257
|
+
Check_Type(ary, T_ARRAY);
|
258
|
+
|
259
|
+
get_texture_info(self, &tex);
|
260
|
+
|
261
|
+
bounds.xmin = NUM2INT(get_from_array(ary, 0));
|
262
|
+
bounds.ymin = NUM2INT(get_from_array(ary, 1));
|
263
|
+
bounds.xmax = NUM2INT(get_from_array(ary, 2));
|
264
|
+
bounds.ymax = NUM2INT(get_from_array(ary, 3));
|
265
|
+
|
266
|
+
create_subtexture_and_sync_to_gl(&bounds, &tex);
|
267
|
+
|
268
|
+
return Qnil;
|
269
|
+
}
|
270
|
+
|
271
|
+
VALUE
|
272
|
+
m_dup_image(VALUE self)
|
273
|
+
{
|
274
|
+
texture_info tex, dup_tex;
|
275
|
+
VALUE dupped_image;
|
276
|
+
VALUE window;
|
277
|
+
|
278
|
+
get_texture_info(self, &tex);
|
279
|
+
|
280
|
+
window = rb_funcall(self, rb_intern("__window__"), 0);
|
281
|
+
|
282
|
+
/* create a new blank image with the height/width of the current image */
|
283
|
+
dupped_image = create_image(window, tex.width, tex.height);
|
284
|
+
|
285
|
+
/* get the new image's data */
|
286
|
+
get_texture_info(dupped_image, &dup_tex);
|
287
|
+
|
288
|
+
/* splice into the new image content from the current image, and sync it to gl */
|
289
|
+
splice_do_action(0, 0, 0, 0, XMAX_OOB, YMAX_OOB, &tex, &dup_tex, Qnil, eager_sync, true, NULL);
|
290
|
+
|
291
|
+
/* copy across the ivars too! */
|
292
|
+
rb_copy_generic_ivar(dupped_image, self);
|
293
|
+
|
294
|
+
/* we now have a full dup of the current image, return it */
|
295
|
+
return dupped_image;
|
296
|
+
}
|
297
|
+
|
298
|
+
VALUE
|
299
|
+
m_clone_image(VALUE self)
|
300
|
+
{
|
301
|
+
VALUE cloned_image;
|
302
|
+
|
303
|
+
cloned_image = m_dup_image(self);
|
304
|
+
|
305
|
+
/* the main diff b/w clone and dup is that clone also dups the singleton */
|
306
|
+
KLASS_OF(cloned_image) = rb_singleton_class_clone(self);
|
307
|
+
|
308
|
+
return cloned_image;
|
309
|
+
}
|
310
|
+
|
311
|
+
VALUE
|
312
|
+
m_user_set_options(VALUE self, VALUE options)
|
313
|
+
{
|
314
|
+
if(!is_a_hash(options))
|
315
|
+
rb_raise(rb_eArgError, "only a single hash argument is accepted");
|
316
|
+
|
317
|
+
set_image_local(self, USER_DEFAULTS, options);
|
318
|
+
|
319
|
+
return Qnil;
|
320
|
+
}
|
321
|
+
|
322
|
+
VALUE
|
323
|
+
m_user_delete_options(VALUE self)
|
324
|
+
{
|
325
|
+
|
326
|
+
set_image_local(self, USER_DEFAULTS, Qnil);
|
327
|
+
|
328
|
+
return Qnil;
|
329
|
+
}
|
330
|
+
|
331
|
+
VALUE
|
332
|
+
m_get_options(VALUE self)
|
333
|
+
{
|
334
|
+
return get_image_local(self, USER_DEFAULTS);
|
335
|
+
}
|
336
|
+
|
337
|
+
static void
|
338
|
+
get_image_chunk_with_size(char * data, texture_info * tex, char * blob)
|
339
|
+
{
|
340
|
+
for(int y = 0; y < tex->height; y++)
|
341
|
+
for(int x = 0; x < tex->width; x++) {
|
342
|
+
int buf_index = 4 * (x + y * tex->width);
|
343
|
+
|
344
|
+
int offset = calc_pixel_offset(tex, x, y);
|
345
|
+
|
346
|
+
memcpy(blob + buf_index, data + offset, 4);
|
347
|
+
}
|
348
|
+
}
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
VALUE
|
353
|
+
m_to_blob(VALUE self)
|
354
|
+
{
|
355
|
+
texture_info tex;
|
356
|
+
int sidelength;
|
357
|
+
|
358
|
+
get_texture_info(self, &tex);
|
359
|
+
|
360
|
+
glEnable(GL_TEXTURE_2D);
|
361
|
+
glBindTexture(GL_TEXTURE_2D, tex.tname);
|
362
|
+
|
363
|
+
/* get length of a side, since square texture */
|
364
|
+
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &sidelength);
|
365
|
+
|
366
|
+
/* initialize texture data array, mult. by 4 because {rgba} */
|
367
|
+
char new_array[sidelength * sidelength * 4];
|
368
|
+
|
369
|
+
/* get texture data from video memory */
|
370
|
+
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE,(void*)(new_array));
|
371
|
+
|
372
|
+
VALUE blob = rb_str_new(NULL, 4 * tex.width * tex.height);
|
373
|
+
|
374
|
+
get_image_chunk_with_size(new_array, &tex, RSTRING_PTR(blob));
|
375
|
+
|
376
|
+
glDisable(GL_TEXTURE_2D);
|
377
|
+
|
378
|
+
return blob;
|
379
|
+
}
|
380
|
+
|
381
|
+
/* return the pixel colour for the given x, y */
|
382
|
+
VALUE
|
383
|
+
m_getpixel(int argc, VALUE * argv, VALUE self)
|
384
|
+
{
|
385
|
+
int x1, y1;
|
386
|
+
int last = argc - 1;
|
387
|
+
texture_info tex;
|
388
|
+
rgba pix;
|
389
|
+
bool gosu_color_mode = false;
|
390
|
+
VALUE options;
|
391
|
+
|
392
|
+
|
393
|
+
process_x_y_pairs(self, 1, argv, &x1, &y1);
|
394
|
+
|
395
|
+
/* get texture info */
|
396
|
+
get_texture_info(self, &tex);
|
397
|
+
|
398
|
+
options = argv[last];
|
399
|
+
|
400
|
+
if (hash_value_is(options, "color_mode", string2sym("gosu")))
|
401
|
+
gosu_color_mode = true;
|
402
|
+
|
403
|
+
/* locate the desired pixel; */
|
404
|
+
pix = get_pixel_color(&tex, x1, y1);
|
405
|
+
|
406
|
+
if(not_a_color(pix))
|
407
|
+
return Qnil;
|
408
|
+
else {
|
409
|
+
if (gosu_color_mode)
|
410
|
+
return convert_rgba_to_gosu_color(&pix);
|
411
|
+
else
|
412
|
+
return convert_rgba_to_rb_color(&pix);
|
413
|
+
}
|
414
|
+
}
|
415
|
+
|
416
|
+
/* circle action */
|
417
|
+
VALUE
|
418
|
+
m_circle(int argc, VALUE * argv, VALUE self)
|
419
|
+
{
|
420
|
+
int x1, y1, r;
|
421
|
+
int last = argc - 1;
|
422
|
+
VALUE options;
|
423
|
+
texture_info tex;
|
424
|
+
|
425
|
+
if(argc < 2) rb_raise(rb_eArgError, "circle action needs at least 2 parameter");
|
426
|
+
|
427
|
+
process_x_y_pairs(self, 1, argv, &x1, &y1);
|
428
|
+
|
429
|
+
if(is_a_point(argv[0]))
|
430
|
+
r = NUM2INT(argv[1]);
|
431
|
+
else
|
432
|
+
r = NUM2INT(argv[2]);
|
433
|
+
|
434
|
+
options = argv[last];
|
435
|
+
|
436
|
+
get_texture_info(self, &tex);
|
437
|
+
|
438
|
+
circle_do_action(x1, y1, r, &tex, options, sync_mode, true, NULL);
|
439
|
+
|
440
|
+
return self;
|
441
|
+
}
|
442
|
+
|
443
|
+
/* ngon */
|
444
|
+
VALUE
|
445
|
+
m_ngon(int argc, VALUE * argv, VALUE self)
|
446
|
+
{
|
447
|
+
int x1, y1, r, n;
|
448
|
+
int last = argc - 1;
|
449
|
+
VALUE options;
|
450
|
+
texture_info tex;
|
451
|
+
|
452
|
+
if(argc < 3) rb_raise(rb_eArgError, "ngon requires at least 3 parameters (x, y, radius, num_sides)");
|
453
|
+
|
454
|
+
process_x_y_pairs(self, 1, argv, &x1, &y1);
|
455
|
+
|
456
|
+
options = argv[last];
|
457
|
+
|
458
|
+
get_texture_info(self, &tex);
|
459
|
+
|
460
|
+
r = NUM2INT(argv[2]);
|
461
|
+
n = NUM2INT(argv[3]);
|
462
|
+
|
463
|
+
ngon_do_action(x1, y1, r, n, &tex, options, sync_mode, true, NULL);
|
464
|
+
|
465
|
+
return self;
|
466
|
+
}
|
467
|
+
|
468
|
+
|
469
|
+
/* flood fill action */
|
470
|
+
VALUE
|
471
|
+
m_flood_fill(int argc, VALUE * argv, VALUE self)
|
472
|
+
{
|
473
|
+
int x1, y1;
|
474
|
+
int last = argc - 1;
|
475
|
+
VALUE options;
|
476
|
+
texture_info tex;
|
477
|
+
bool iter = false, glow = false;
|
478
|
+
|
479
|
+
if (argc < 1) rb_raise(rb_eArgError, "flood fill action needs at least 1 parameter");
|
480
|
+
|
481
|
+
process_x_y_pairs(self, 1, argv, &x1, &y1);
|
482
|
+
|
483
|
+
options = argv[last];
|
484
|
+
|
485
|
+
get_texture_info(self, &tex);
|
486
|
+
|
487
|
+
if(is_a_hash(options)) {
|
488
|
+
if(RTEST(get_from_hash(options, "iter")))
|
489
|
+
iter = true;
|
490
|
+
if(RTEST(get_from_hash(options, "glow")))
|
491
|
+
glow = true;
|
492
|
+
}
|
493
|
+
|
494
|
+
if(iter) {
|
495
|
+
flood_fill_do_action(x1, y1, &tex, options, sync_mode, true, NULL);
|
496
|
+
}
|
497
|
+
else if(glow) {
|
498
|
+
glow_fill_do_action(x1, y1, &tex, options, sync_mode, true, NULL);
|
499
|
+
|
500
|
+
}
|
501
|
+
/* this is the default fill */
|
502
|
+
else {
|
503
|
+
scan_fill_do_action(x1, y1, &tex, options, sync_mode, true, NULL);
|
504
|
+
}
|
505
|
+
|
506
|
+
return self;
|
507
|
+
}
|
508
|
+
|
509
|
+
static inline VALUE
|
510
|
+
convert_trace_match_to_ruby_array(trace_match match, bool gosu_color_mode)
|
511
|
+
{
|
512
|
+
VALUE ary = rb_ary_new();
|
513
|
+
|
514
|
+
rb_ary_store(ary, 0, INT2FIX(match.x));
|
515
|
+
rb_ary_store(ary, 1, INT2FIX(match.y));
|
516
|
+
|
517
|
+
if (gosu_color_mode)
|
518
|
+
rb_ary_store(ary, 2, convert_rgba_to_gosu_color(&match.color));
|
519
|
+
else
|
520
|
+
rb_ary_store(ary, 2, convert_rgba_to_rb_color(&match.color));
|
521
|
+
|
522
|
+
return ary;
|
523
|
+
}
|
524
|
+
|
525
|
+
/* line action */
|
526
|
+
VALUE
|
527
|
+
m_line(int argc, VALUE * argv, VALUE self)
|
528
|
+
{
|
529
|
+
int x1, y1, x2, y2;
|
530
|
+
int last = argc - 1;
|
531
|
+
bool gosu_color_mode = false;
|
532
|
+
VALUE options;
|
533
|
+
texture_info tex;
|
534
|
+
trace_match match;
|
535
|
+
|
536
|
+
if(argc < 2) rb_raise(rb_eArgError, "line action needs at least 2 parameters");
|
537
|
+
|
538
|
+
process_x_y_pairs(self, 2, argv, &x1, &y1, &x2, &y2);
|
539
|
+
|
540
|
+
options = argv[last];
|
541
|
+
|
542
|
+
if (hash_value_is(options, "color_mode", string2sym("gosu")))
|
543
|
+
gosu_color_mode = true;
|
544
|
+
|
545
|
+
get_texture_info(self, &tex);
|
546
|
+
|
547
|
+
match = line_do_action(x1, y1, x2, y2, &tex, options, sync_mode, true, NULL);
|
548
|
+
|
549
|
+
if (has_optional_hash_arg(options, "trace")) {
|
550
|
+
if (match.x == -9999)
|
551
|
+
return Qnil;
|
552
|
+
else
|
553
|
+
return convert_trace_match_to_ruby_array(match, gosu_color_mode);
|
554
|
+
}
|
555
|
+
|
556
|
+
return self;
|
557
|
+
}
|
558
|
+
|
559
|
+
/* box action */
|
560
|
+
VALUE
|
561
|
+
m_rect(int argc, VALUE * argv, VALUE self)
|
562
|
+
{
|
563
|
+
|
564
|
+
int x1, y1, x2, y2;
|
565
|
+
int last = argc - 1;
|
566
|
+
VALUE options;
|
567
|
+
texture_info tex;
|
568
|
+
|
569
|
+
if(argc < 2) rb_raise(rb_eArgError, "rect action needs at least 2 parameters");
|
570
|
+
|
571
|
+
process_x_y_pairs(self, 2, argv, &x1, &y1, &x2, &y2);
|
572
|
+
|
573
|
+
options = argv[last];
|
574
|
+
|
575
|
+
get_texture_info(self, &tex);
|
576
|
+
|
577
|
+
rect_do_action(x1, y1, x2, y2, &tex, options, sync_mode, true, NULL);
|
578
|
+
|
579
|
+
return self;
|
580
|
+
}
|
581
|
+
|
582
|
+
|
583
|
+
/* pixel action */
|
584
|
+
VALUE
|
585
|
+
m_pixel(int argc, VALUE * argv, VALUE self)
|
586
|
+
{
|
587
|
+
int x1, y1;
|
588
|
+
int last = argc - 1;
|
589
|
+
VALUE options;
|
590
|
+
texture_info tex;
|
591
|
+
|
592
|
+
if(argc < 1) rb_raise(rb_eArgError, "pixel action needs 1 parameter");
|
593
|
+
|
594
|
+
process_x_y_pairs(self, 1, argv, &x1, &y1);
|
595
|
+
|
596
|
+
options = argv[last];
|
597
|
+
|
598
|
+
get_texture_info(self, &tex);
|
599
|
+
|
600
|
+
pixel_do_action(x1, y1, &tex, options, sync_mode, true, NULL);
|
601
|
+
|
602
|
+
return self;
|
603
|
+
}
|
604
|
+
|
605
|
+
/* bezier curve */
|
606
|
+
VALUE
|
607
|
+
m_bezier(int argc, VALUE * argv, VALUE self)
|
608
|
+
{
|
609
|
+
VALUE points = Qnil;
|
610
|
+
VALUE options = Qnil;
|
611
|
+
int last = argc - 1;
|
612
|
+
texture_info tex;
|
613
|
+
|
614
|
+
if(argc < 1) rb_raise(rb_eArgError, "bezier action needs at least 1 parameter");
|
615
|
+
|
616
|
+
/* get array of points */
|
617
|
+
points = argv[0];
|
618
|
+
Check_Type(points, T_ARRAY);
|
619
|
+
|
620
|
+
options = argv[last];
|
621
|
+
|
622
|
+
get_texture_info(self, &tex);
|
623
|
+
|
624
|
+
bezier_do_action(points, &tex, options, sync_mode, true, NULL);
|
625
|
+
|
626
|
+
return self;
|
627
|
+
}
|
628
|
+
|
629
|
+
/* bezier curve */
|
630
|
+
VALUE
|
631
|
+
m_polyline(int argc, VALUE * argv, VALUE self)
|
632
|
+
{
|
633
|
+
VALUE points = Qnil;
|
634
|
+
VALUE options = Qnil;
|
635
|
+
int last = argc - 1;
|
636
|
+
texture_info tex;
|
637
|
+
|
638
|
+
if(argc < 1) rb_raise(rb_eArgError, "polyline action needs at least 1 parameter");
|
639
|
+
|
640
|
+
/* get array of points */
|
641
|
+
points = argv[0];
|
642
|
+
Check_Type(points, T_ARRAY);
|
643
|
+
|
644
|
+
options = argv[last];
|
645
|
+
|
646
|
+
get_texture_info(self, &tex);
|
647
|
+
|
648
|
+
polyline_do_action(points, &tex, options, sync_mode, true, NULL);
|
649
|
+
|
650
|
+
return self;
|
651
|
+
}
|
652
|
+
|
653
|
+
|
654
|
+
|
655
|
+
/* splice action */
|
656
|
+
VALUE
|
657
|
+
m_splice(int argc, VALUE * argv, VALUE self)
|
658
|
+
{
|
659
|
+
int x0, y0;
|
660
|
+
int cx1 = 0, cy1 = 0, cx2 = XMAX_OOB, cy2 = YMAX_OOB;
|
661
|
+
texture_info splice_tex;
|
662
|
+
int last = argc - 1;
|
663
|
+
texture_info tex;
|
664
|
+
VALUE options;
|
665
|
+
|
666
|
+
if(argc < 3) rb_raise(rb_eArgError, "splice action needs at least 3 parameters");
|
667
|
+
|
668
|
+
if(!is_gosu_image(argv[0]))
|
669
|
+
rb_raise(rb_eArgError, "first parameter must be a valid Gosu::Image");
|
670
|
+
|
671
|
+
/* get the splice image */
|
672
|
+
get_texture_info(argv[0], &splice_tex);
|
673
|
+
|
674
|
+
/* add 1 to argv to skip the Image parameter */
|
675
|
+
process_x_y_pairs(self, 1, argv + 1, &x0, &y0);
|
676
|
+
|
677
|
+
/* get the hash args */
|
678
|
+
options = argv[last];
|
679
|
+
|
680
|
+
get_texture_info(self, &tex);
|
681
|
+
|
682
|
+
/* get the crop boundaries */
|
683
|
+
if(is_a_hash(options))
|
684
|
+
if(RTEST(get_from_hash(options, "crop"))) {
|
685
|
+
VALUE c = get_from_hash(options, "crop");
|
686
|
+
Check_Type(c, T_ARRAY);
|
687
|
+
cx1 = NUM2INT(get_from_array(c, 0));
|
688
|
+
cy1 = NUM2INT(get_from_array(c, 1));
|
689
|
+
cx2 = NUM2INT(get_from_array(c, 2));
|
690
|
+
cy2 = NUM2INT(get_from_array(c, 3));
|
691
|
+
}
|
692
|
+
|
693
|
+
splice_do_action(x0, y0, cx1, cy1, cx2, cy2, &splice_tex,
|
694
|
+
&tex, options, sync_mode, true, NULL);
|
695
|
+
|
696
|
+
return self;
|
697
|
+
}
|
698
|
+
|
699
|
+
|
700
|
+
/* clear action - really just an alias for box */
|
701
|
+
VALUE
|
702
|
+
m_clear(int argc, VALUE * argv, VALUE self)
|
703
|
+
{
|
704
|
+
VALUE parms[4];
|
705
|
+
|
706
|
+
parms[0] = INT2NUM(0);
|
707
|
+
parms[1] = INT2NUM(0);
|
708
|
+
parms[2] = INT2NUM(XMAX_OOB);
|
709
|
+
parms[3] = INT2NUM(YMAX_OOB);
|
710
|
+
|
711
|
+
// m_box(ARY_SIZE(parms), parms, self);
|
712
|
+
|
713
|
+
return self;
|
714
|
+
}
|
715
|
+
|
716
|
+
/* offset function */
|
717
|
+
VALUE
|
718
|
+
m_offset(int argc, VALUE * argv, VALUE self)
|
719
|
+
{
|
720
|
+
char * try_offset;
|
721
|
+
|
722
|
+
if(argc == 0)
|
723
|
+
return get_image_local(self, DRAW_OFFSET);
|
724
|
+
|
725
|
+
switch(TYPE(argv[0])) {
|
726
|
+
|
727
|
+
case T_ARRAY:
|
728
|
+
|
729
|
+
set_image_local(self, DRAW_OFFSET, argv[0]);
|
730
|
+
break;
|
731
|
+
case T_SYMBOL:
|
732
|
+
try_offset = sym2string(argv[0]);
|
733
|
+
|
734
|
+
if(!strcmp("default", try_offset)) {
|
735
|
+
set_image_local(self, DRAW_OFFSET, Qnil);
|
736
|
+
}
|
737
|
+
else {
|
738
|
+
rb_raise(rb_eArgError, "no such offset defined: %s\n", try_offset);
|
739
|
+
}
|
740
|
+
|
741
|
+
break;
|
742
|
+
default:
|
743
|
+
rb_raise(rb_eArgError, "invalid offset. please use an array or :default.");
|
744
|
+
}
|
745
|
+
return Qnil;
|
746
|
+
}
|
747
|
+
|
748
|
+
/* color change */
|
749
|
+
VALUE
|
750
|
+
m_color(int argc, VALUE * argv, VALUE self)
|
751
|
+
{
|
752
|
+
VALUE first;
|
753
|
+
rgba new_color;
|
754
|
+
|
755
|
+
/* if no params then return action current color */
|
756
|
+
if(argc == 0)
|
757
|
+
return get_image_local(self, IMAGE_COLOR);
|
758
|
+
|
759
|
+
/* otherwise set the action color */
|
760
|
+
/* NB: we cannot just set image_local_color to 'first' because first may not be an array,
|
761
|
+
it could also be a symbol */
|
762
|
+
|
763
|
+
first = argv[0];
|
764
|
+
|
765
|
+
new_color = convert_rb_color_to_rgba(first);
|
766
|
+
|
767
|
+
/* im quite sure i DO want to set the color even if it is not_a_color.
|
768
|
+
why ? consistency only
|
769
|
+
(NB: not_a_color_v is skipped by the set_pixel_color routine */
|
770
|
+
|
771
|
+
/* if(is_a_color(new_color)) */
|
772
|
+
|
773
|
+
save_rgba_to_image_local_color(self, new_color);
|
774
|
+
|
775
|
+
return Qnil;
|
776
|
+
}
|
777
|
+
|
778
|
+
/* this function manages all other method calls */
|
779
|
+
VALUE
|
780
|
+
m_missing(int argc, VALUE * argv, VALUE self)
|
781
|
+
{
|
782
|
+
char * action_name = lowercase(sym2string(argv[0]));
|
783
|
+
|
784
|
+
/* try case insensitive version of action name */
|
785
|
+
if(rb_respond_to(self, rb_intern(action_name))) {
|
786
|
+
rb_funcall2(self, rb_intern(action_name), --argc, ++argv);
|
787
|
+
}
|
788
|
+
/* still no match? then method does not exist */
|
789
|
+
else {
|
790
|
+
rb_raise (rb_eRuntimeError, "unrecognized action: %s\n", action_name);
|
791
|
+
}
|
792
|
+
|
793
|
+
return self;
|
794
|
+
}
|
795
|
+
|
796
|
+
/* refreshes the cache */
|
797
|
+
VALUE
|
798
|
+
m_cache_refresh(VALUE self)
|
799
|
+
{
|
800
|
+
texture_info tex;
|
801
|
+
|
802
|
+
get_texture_info(self, &tex);
|
803
|
+
|
804
|
+
cache_refresh_entry(tex.tname);
|
805
|
+
|
806
|
+
return self;
|
807
|
+
}
|
808
|
+
|
809
|
+
/* check whether img quad is already cached */
|
810
|
+
VALUE
|
811
|
+
m_quad_cached(VALUE self)
|
812
|
+
{
|
813
|
+
VALUE info, gc_state_off;
|
814
|
+
int tex_name;
|
815
|
+
cache_entry * entry;
|
816
|
+
|
817
|
+
/* prevent weird segfault bug */
|
818
|
+
gc_state_off = rb_gc_disable();
|
819
|
+
|
820
|
+
/* ensure gl_tex_info returns non nil */
|
821
|
+
info = check_for_texture_info(self);
|
822
|
+
|
823
|
+
tex_name = FIX2INT(rb_funcall(info, rb_intern("tex_name"), 0));
|
824
|
+
|
825
|
+
entry = find_in_cache(tex_name);
|
826
|
+
|
827
|
+
/* only enable gc if was enabled on function entry */
|
828
|
+
if(!gc_state_off) rb_gc_enable();
|
829
|
+
|
830
|
+
return entry ? Qtrue : Qfalse;
|
831
|
+
}
|
832
|
+
|
833
|
+
/** m_each **/
|
834
|
+
VALUE
|
835
|
+
m_each(int argc, VALUE * argv, VALUE self)
|
836
|
+
{
|
837
|
+
int x1 = 0, y1 = 0, x2 = XMAX_OOB, y2 = YMAX_OOB;
|
838
|
+
texture_info tex;
|
839
|
+
VALUE proc;
|
840
|
+
VALUE options = Qnil;
|
841
|
+
|
842
|
+
rb_need_block();
|
843
|
+
|
844
|
+
get_texture_info(self, &tex);
|
845
|
+
|
846
|
+
if(argc >= 1) {
|
847
|
+
options = argv[0];
|
848
|
+
Check_Type(options, T_HASH);
|
849
|
+
if(RTEST(get_from_hash(options, "region"))) {
|
850
|
+
VALUE region = get_from_hash(options, "region");
|
851
|
+
Check_Type(region, T_ARRAY);
|
852
|
+
|
853
|
+
if(RARRAY_LEN(region) < 4)
|
854
|
+
rb_raise(rb_eArgError, "region requires 4 elements");
|
855
|
+
|
856
|
+
x1 = NUM2INT(get_from_array(region, 0));
|
857
|
+
y1 = NUM2INT(get_from_array(region, 1));
|
858
|
+
x2 = NUM2INT(get_from_array(region, 2));
|
859
|
+
y2 = NUM2INT(get_from_array(region, 3));
|
860
|
+
|
861
|
+
}
|
862
|
+
|
863
|
+
}
|
864
|
+
|
865
|
+
constrain_boundaries(&x1, &y1,
|
866
|
+
&x2, &y2, tex.width, tex.height);
|
867
|
+
|
868
|
+
proc = rb_block_proc();
|
869
|
+
|
870
|
+
each_pixel_do_action(x1, y1, x2, y2, proc, &tex, options, sync_mode, true, NULL);
|
871
|
+
|
872
|
+
return self;
|
873
|
+
}
|
874
|
+
/** end of each **/
|
875
|
+
|
876
|
+
/** turtle drawing functions **/
|
877
|
+
/* static VALUE */
|
878
|
+
/* m_turtle_move_to */
|
879
|
+
|
880
|
+
/* VALUE */
|
881
|
+
/* m_bezier(int argc, VALUE * argv, VALUE self) */
|
882
|
+
/* { */
|
883
|
+
/* VALUE points = Qnil; */
|
884
|
+
/* VALUE options = Qnil; */
|
885
|
+
/* int last = argc - 1; */
|
886
|
+
/* texture_info tex; */
|
887
|
+
|
888
|
+
/* if(argc < 1) rb_raise(rb_eArgError, "bezier action needs at least 1 parameter"); */
|
889
|
+
|
890
|
+
/* /\* get array of points *\/ */
|
891
|
+
/* points = argv[0]; */
|
892
|
+
/* Check_Type(points, T_ARRAY); */
|
893
|
+
|
894
|
+
/* options = argv[last]; */
|
895
|
+
|
896
|
+
/* get_texture_info(self, &tex); */
|
897
|
+
|
898
|
+
/* bezier_do_action(points, &tex, options, sync_mode, true, NULL); */
|
899
|
+
|
900
|
+
/* return self; */
|
901
|
+
/* } */
|
902
|
+
|
903
|
+
/** end turtle drawing **/
|
904
|
+
|
905
|
+
|
906
|
+
/* below is yucky old code that needs to be updated */
|
907
|
+
/* each_pixel iterator */
|
908
|
+
|
909
|
+
|
910
|
+
/* VALUE */
|
911
|
+
/* m_each(int argc, VALUE * argv, VALUE self) */
|
912
|
+
/* { */
|
913
|
+
/* int x0, y0, x1, y1, xbound, ybound, arity; */
|
914
|
+
/* VALUE options, region, pixel_data[2], yield_vals; */
|
915
|
+
/* register int x, y; */
|
916
|
+
/* texture_info tex; */
|
917
|
+
/* image_bounds bounds; */
|
918
|
+
|
919
|
+
/* rb_need_block(); */
|
920
|
+
|
921
|
+
/* arity = FIX2INT(rb_funcall(rb_block_proc(), rb_intern("arity"), 0)); */
|
922
|
+
/* if(arity != 1 && arity != 3) */
|
923
|
+
/* rb_raise(rb_eRuntimeError, "block arity must be either 1 or 3"); */
|
924
|
+
|
925
|
+
/* /\* rb_scan_args(argc, argv, "01", &options); *\/ */
|
926
|
+
|
927
|
+
/* /\* /\\* get texture info *\\/ *\/ */
|
928
|
+
/* /\* get_texture_info(self, &tex); *\/ */
|
929
|
+
|
930
|
+
/* /\* /\\* default values for region *\\/ *\/ */
|
931
|
+
/* /\* x0 = 0; y0 = 0; x1 = tex.width; y1 = tex.height; *\/ */
|
932
|
+
|
933
|
+
/* /\* if(has_optional_hash_arg(options, "region")) { *\/ */
|
934
|
+
/* /\* region = get_from_hash(options, "region"); *\/ */
|
935
|
+
|
936
|
+
/* /\* x0 = NUM2INT(get_from_array(region, 0)); *\/ */
|
937
|
+
/* /\* y0 = NUM2INT(get_from_array(region, 1)); *\/ */
|
938
|
+
/* /\* x1 = NUM2INT(get_from_array(region, 2)); *\/ */
|
939
|
+
/* /\* y1 = NUM2INT(get_from_array(region, 3)); *\/ */
|
940
|
+
|
941
|
+
/* /\* constrain_boundaries(&x0, &y0, &x1, &y1, tex.width, tex.height); *\/ */
|
942
|
+
/* /\* } *\/ */
|
943
|
+
|
944
|
+
/* /\* /\\* width and height of action *\\/ *\/ */
|
945
|
+
/* /\* xbound = x1 - x0; *\/ */
|
946
|
+
/* /\* ybound = y1 - y0; *\/ */
|
947
|
+
|
948
|
+
/* /\* yield_vals = rb_ary_new(); *\/ */
|
949
|
+
|
950
|
+
/* /\* for(y = 0; y < ybound; y++) *\/ */
|
951
|
+
/* /\* for(x = 0; x < xbound; x++) { *\/ */
|
952
|
+
/* /\* VALUE pixel_color; *\/ */
|
953
|
+
/* /\* rgba old_color; *\/ */
|
954
|
+
|
955
|
+
/* /\* /\\* adjusted x and y *\\/ *\/ */
|
956
|
+
/* /\* register int ax = x + x0, ay = y + y0; *\/ */
|
957
|
+
|
958
|
+
/* /\* pixel_data[0] = INT2FIX(ax); *\/ */
|
959
|
+
/* /\* pixel_data[1] = INT2FIX(ay); *\/ */
|
960
|
+
|
961
|
+
/* /\* pixel_color = m_getpixel(self, INT2FIX(ax), INT2FIX(ay)); *\/ */
|
962
|
+
|
963
|
+
/* /\* if(arity == 1) { *\/ */
|
964
|
+
/* /\* rb_yield(pixel_color); *\/ */
|
965
|
+
/* /\* } *\/ */
|
966
|
+
/* /\* else if(arity == 3) { *\/ */
|
967
|
+
/* /\* rb_ary_store(yield_vals, 0, pixel_color); *\/ */
|
968
|
+
/* /\* rb_ary_store(yield_vals, 1, INT2FIX(x)); *\/ */
|
969
|
+
/* /\* rb_ary_store(yield_vals, 2, INT2FIX(y)); *\/ */
|
970
|
+
|
971
|
+
/* /\* rb_yield(yield_vals); *\/ */
|
972
|
+
/* /\* } *\/ */
|
973
|
+
|
974
|
+
/* /\* m_color(1, &pixel_color, self); *\/ */
|
975
|
+
/* /\* // process_action(pixel, self, 2, pixel_data, false); *\/ */
|
976
|
+
/* /\* // color_struct = old_color; *\/ */
|
977
|
+
/* /\* } *\/ */
|
978
|
+
|
979
|
+
/* /\* bounds.xmin = x0; *\/ */
|
980
|
+
/* /\* bounds.ymin = y0; *\/ */
|
981
|
+
/* /\* bounds.xmax = x1; *\/ */
|
982
|
+
/* /\* bounds.ymax = y1; *\/ */
|
983
|
+
|
984
|
+
/* /\* create_subtexture_and_sync_to_gl(&bounds, &tex); *\/ */
|
985
|
+
|
986
|
+
/* /\* return self; *\/ */
|
987
|
+
/* /\* } *\/ */
|
988
|
+
|
989
|
+
/* /\** end each_pixel algorithm **\/} */
|
990
|
+
/* /\** end each_pixel algorithm **\/ */
|
991
|
+
|
992
|
+
|
993
|
+
/* /\* VALUE *\/ */
|
994
|
+
/* /\* m_lshift(int argc, VALUE * argv, VALUE self) *\/ */
|
995
|
+
/* /\* { *\/ */
|
996
|
+
/* /\* int y,x, step, yoffset; *\/ */
|
997
|
+
/* /\* VALUE options, loop; *\/ */
|
998
|
+
/* /\* register int offset; *\/ */
|
999
|
+
/* /\* texture_info tex; *\/ */
|
1000
|
+
/* /\* image_bounds bounds; *\/ */
|
1001
|
+
|
1002
|
+
/* /\* rb_scan_args(argc, argv, "01", &options); *\/ */
|
1003
|
+
|
1004
|
+
/* /\* /\\* default values for other params *\\/ *\/ */
|
1005
|
+
/* /\* step = 1; loop = Qfalse; *\/ */
|
1006
|
+
|
1007
|
+
/* /\* if(TYPE(options) == T_HASH) { *\/ */
|
1008
|
+
/* /\* step = NUM2INT(get_from_hash(options, "step")); *\/ */
|
1009
|
+
/* /\* loop = get_from_hash(options, "loop"); *\/ */
|
1010
|
+
/* /\* } *\/ */
|
1011
|
+
/* /\* else if(options != Qnil) { *\/ */
|
1012
|
+
/* /\* rb_raise(rb_eArgError, "argument must be a hash"); *\/ */
|
1013
|
+
/* /\* } *\/ */
|
1014
|
+
|
1015
|
+
/* /\* /\\* get texture info *\\/ *\/ */
|
1016
|
+
/* /\* get_texture_info(self, &tex); *\/ */
|
1017
|
+
|
1018
|
+
/* /\* for(y = 0; y < tex.height; y++) { *\/ */
|
1019
|
+
/* /\* for(x = 0; x < tex.width; x++) { *\/ */
|
1020
|
+
/* /\* offset = calc_pixel_offset(&tex, x, y); *\/ */
|
1021
|
+
|
1022
|
+
/* /\* if((x + step) < tex.width) { *\/ */
|
1023
|
+
/* /\* color_copy(tex.td_array + offset + step * 4, tex.td_array + offset); *\/ */
|
1024
|
+
/* /\* } *\/ */
|
1025
|
+
/* /\* else { *\/ */
|
1026
|
+
/* /\* if(loop == Qtrue) { *\/ */
|
1027
|
+
/* /\* yoffset = calc_pixel_offset(&tex, x + step - tex.width, y); *\/ */
|
1028
|
+
|
1029
|
+
/* /\* color_copy(tex.td_array + yoffset, tex.td_array + offset); *\/ */
|
1030
|
+
/* /\* } *\/ */
|
1031
|
+
/* /\* else { *\/ */
|
1032
|
+
|
1033
|
+
/* /\* zero_color(tex.td_array + offset); *\/ */
|
1034
|
+
/* /\* } *\/ */
|
1035
|
+
/* /\* } *\/ */
|
1036
|
+
|
1037
|
+
/* /\* } *\/ */
|
1038
|
+
/* /\* } *\/ */
|
1039
|
+
|
1040
|
+
/* /\* bounds.xmin = 0; *\/ */
|
1041
|
+
/* /\* bounds.xmax = tex.width; *\/ */
|
1042
|
+
/* /\* bounds.ymin = 0; *\/ */
|
1043
|
+
/* /\* bounds.ymax = tex.height; *\/ */
|
1044
|
+
|
1045
|
+
/* /\* create_subtexture_and_sync_to_gl(&bounds, &tex); *\/ */
|
1046
|
+
|
1047
|
+
/* /\* return Qnil; *\/ */
|
1048
|
+
/* /\* } *\/ */
|
1049
|
+
|
1050
|
+
/* /\* VALUE *\/ */
|
1051
|
+
/* /\* m_rshift(int argc, VALUE * argv, VALUE self) *\/ */
|
1052
|
+
/* /\* { *\/ */
|
1053
|
+
/* /\* int y,x, step, yoffset; *\/ */
|
1054
|
+
/* /\* VALUE options, loop; *\/ */
|
1055
|
+
/* /\* register int offset; *\/ */
|
1056
|
+
/* /\* texture_info tex; *\/ */
|
1057
|
+
/* /\* image_bounds bounds; *\/ */
|
1058
|
+
|
1059
|
+
/* /\* rb_scan_args(argc, argv, "01", &options); *\/ */
|
1060
|
+
|
1061
|
+
/* /\* /\\* default values for other params *\\/ *\/ */
|
1062
|
+
/* /\* step = 1; loop = Qfalse; *\/ */
|
1063
|
+
|
1064
|
+
/* /\* if(TYPE(options) == T_HASH) { *\/ */
|
1065
|
+
/* /\* step = NUM2INT(get_from_hash(options, "step")); *\/ */
|
1066
|
+
/* /\* loop = get_from_hash(options, "loop"); *\/ */
|
1067
|
+
/* /\* } *\/ */
|
1068
|
+
/* /\* else if(options != Qnil) { *\/ */
|
1069
|
+
/* /\* rb_raise(rb_eArgError, "argument must be a hash"); *\/ */
|
1070
|
+
/* /\* } *\/ */
|
1071
|
+
|
1072
|
+
/* /\* /\\* get texture info *\\/ *\/ */
|
1073
|
+
/* /\* get_texture_info(self, &tex); *\/ */
|
1074
|
+
|
1075
|
+
/* /\* for(y = 0; y < tex.height; y++) { *\/ */
|
1076
|
+
/* /\* for(x = tex.width - 1; x > -1; x--) { *\/ */
|
1077
|
+
/* /\* offset = calc_pixel_offset(&tex, x, y); *\/ */
|
1078
|
+
|
1079
|
+
/* /\* if((x - step) > -1) { *\/ */
|
1080
|
+
/* /\* color_copy(tex.td_array + offset - step * 4, tex.td_array + offset); *\/ */
|
1081
|
+
/* /\* } *\/ */
|
1082
|
+
/* /\* else { *\/ */
|
1083
|
+
/* /\* if(loop == Qtrue) { *\/ */
|
1084
|
+
/* /\* yoffset = calc_pixel_offset(&tex, x + tex.width - step, y); *\/ */
|
1085
|
+
/* /\* color_copy(tex.td_array + yoffset, tex.td_array + offset); *\/ */
|
1086
|
+
/* /\* } *\/ */
|
1087
|
+
/* /\* else { *\/ */
|
1088
|
+
/* /\* zero_color(tex.td_array + offset); *\/ */
|
1089
|
+
/* /\* } *\/ */
|
1090
|
+
/* /\* } *\/ */
|
1091
|
+
|
1092
|
+
/* /\* } *\/ */
|
1093
|
+
/* /\* } *\/ */
|
1094
|
+
|
1095
|
+
/* /\* bounds.xmin = 0; *\/ */
|
1096
|
+
/* /\* bounds.xmax = tex.width; *\/ */
|
1097
|
+
/* /\* bounds.ymin = 0; *\/ */
|
1098
|
+
/* /\* bounds.ymax = tex.height; *\/ */
|
1099
|
+
|
1100
|
+
/* /\* create_subtexture_and_sync_to_gl(&bounds, &tex); *\/ */
|
1101
|
+
|
1102
|
+
/* /\* return Qnil; *\/ */
|
1103
|
+
/* /\* } *\/ */
|
1104
|
+
|
1105
|
+
/* /\* /\\* special pixel action for image[]= *\\/ *\/ */
|
1106
|
+
/* /\* VALUE *\/ */
|
1107
|
+
/* /\* m_special_pixel(int argc, VALUE * argv, VALUE self) *\/ */
|
1108
|
+
/* /\* { *\/ */
|
1109
|
+
|
1110
|
+
/* /\* rgba old_color; *\/ */
|
1111
|
+
|
1112
|
+
/* /\* if(argc < 3) rb_raise(rb_eArgError, "[]= action needs 3 parameters"); *\/ */
|
1113
|
+
|
1114
|
+
/* /\* m_color(1, &argv[2], self); *\/ */
|
1115
|
+
|
1116
|
+
/* /\* m_pixel(2, argv, self); *\/ */
|
1117
|
+
|
1118
|
+
/* /\* // color_struct = old_color; *\/ */
|
1119
|
+
|
1120
|
+
|
1121
|
+
/* /\* return Qnil; *\/ */
|
1122
|
+
/* /\* } *\/ */
|
1123
|
+
|
1124
|
+
/* /\* /\\* instance methods *\\/ *\/ */
|
1125
|
+
|