texplay 0.4.3 → 0.4.4.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +225 -222
  3. data/README.markdown +48 -48
  4. data/Rakefile +16 -16
  5. data/examples/common.rb +18 -18
  6. data/examples/example_alpha_blend.rb +29 -29
  7. data/examples/example_bezier.rb +41 -41
  8. data/examples/example_blank.rb +37 -37
  9. data/examples/example_cache.rb +21 -21
  10. data/examples/example_color_control.rb +69 -69
  11. data/examples/example_color_transform.rb +62 -62
  12. data/examples/example_color_transform_circle.rb +34 -34
  13. data/examples/example_darken.rb +24 -24
  14. data/examples/example_dup.rb +73 -73
  15. data/examples/example_each.rb +39 -39
  16. data/examples/example_effect.rb +34 -34
  17. data/examples/example_fill.rb +43 -43
  18. data/examples/example_fill_old.rb +48 -48
  19. data/examples/example_fluent.rb +29 -29
  20. data/examples/example_font.rb +31 -31
  21. data/examples/example_hash_arguments.rb +46 -46
  22. data/examples/example_ippa.rb +23 -23
  23. data/examples/example_light.rb +75 -75
  24. data/examples/example_light_multiply.rb +18 -18
  25. data/examples/example_lsystem.rb +61 -61
  26. data/examples/example_melt.rb +25 -25
  27. data/examples/example_meyet.rb +62 -62
  28. data/examples/example_polyline.rb +42 -42
  29. data/examples/example_scale.rb +27 -27
  30. data/examples/example_select.rb +36 -36
  31. data/examples/example_select2.rb +25 -25
  32. data/examples/example_simple.rb +46 -46
  33. data/examples/example_splice.rb +26 -26
  34. data/examples/example_sync.rb +59 -59
  35. data/examples/example_tiles.rb +41 -41
  36. data/examples/example_trace.rb +22 -22
  37. data/examples/example_transparent.rb +28 -28
  38. data/examples/example_transparent2.rb +24 -24
  39. data/examples/example_transparent3.rb +20 -20
  40. data/examples/example_turtle.rb +39 -39
  41. data/examples/example_weird.rb +22 -22
  42. data/examples/example_window_render_to_image.rb +41 -41
  43. data/examples/example_window_to_blob.rb +35 -35
  44. data/examples/media/maria.png +0 -0
  45. data/examples/media/rose.bmp +0 -0
  46. data/ext/texplay/actions.c +1011 -1006
  47. data/ext/texplay/actions.h +60 -60
  48. data/ext/texplay/bindings.c +1130 -1125
  49. data/ext/texplay/bindings.h +46 -46
  50. data/ext/texplay/cache.c +123 -118
  51. data/ext/texplay/cache.h +24 -24
  52. data/ext/texplay/compat.h +21 -27
  53. data/ext/texplay/extconf.rb +38 -38
  54. data/ext/texplay/graphics_utils.c +1318 -1313
  55. data/ext/texplay/graphics_utils.h +22 -22
  56. data/ext/texplay/texplay.c +206 -201
  57. data/ext/texplay/texplay.h +153 -153
  58. data/ext/texplay/utils.c +896 -891
  59. data/ext/texplay/utils.h +153 -153
  60. data/lib/texplay-contrib.rb +147 -147
  61. data/lib/texplay.rb +347 -347
  62. data/lib/texplay/alone.rb +20 -20
  63. data/lib/texplay/c_function_docs.rb +178 -178
  64. data/lib/texplay/live.rb +84 -84
  65. data/lib/texplay/version.rb +3 -3
  66. data/live/live.rb +85 -85
  67. data/test/image_spec.rb +45 -45
  68. data/test/texplay_spec.rb +144 -144
  69. metadata +42 -52
  70. data/lib/texplay/1.8/texplay.so +0 -0
  71. data/lib/texplay/1.9/texplay.so +0 -0
@@ -1,22 +1,22 @@
1
- #ifndef GUARD_GRAPHICS_UTILS_H
2
- #define GUARD_GRAPHICS_UTILS_H
3
-
4
- void update_lazy_bounds(action_struct * cur, texture_info * tex);
5
- void update_bounds(action_struct * cur, int xmin, int ymin, int xmax, int ymax);
6
- void set_local_bounds(action_struct * cur, int xmin, int ymin, int xmax, int ymax, texture_info * tex);
7
-
8
- void draw_prologue(action_struct * cur, texture_info * tex, int xmin, int ymin, int xmax, int ymax, VALUE * hash_arg,
9
- sync sync_mode, bool primary, action_struct ** payload_ptr);
10
- void draw_epilogue(action_struct * cur, texture_info * tex, bool primary);
11
-
12
- void set_pixel_color_with_style(action_struct * payload, texture_info * tex, int x, int y);
13
- void set_pixel_color(rgba * pixel_color, texture_info * tex, int x, int y);
14
-
15
- rgba get_pixel_color_from_chunk(float * chunk, int width, int height, int x, int y);
16
- rgba get_pixel_color(texture_info * tex, int x, int y);
17
- float* get_pixel_data(texture_info * tex, int x, int y);
18
-
19
- /* create a blank gosu image of width and height */
20
- VALUE create_image(VALUE window, int width, int height);
21
-
22
- #endif
1
+ #ifndef GUARD_GRAPHICS_UTILS_H
2
+ #define GUARD_GRAPHICS_UTILS_H
3
+
4
+ void update_lazy_bounds(action_struct * cur, texture_info * tex);
5
+ void update_bounds(action_struct * cur, int xmin, int ymin, int xmax, int ymax);
6
+ void set_local_bounds(action_struct * cur, int xmin, int ymin, int xmax, int ymax, texture_info * tex);
7
+
8
+ void draw_prologue(action_struct * cur, texture_info * tex, int xmin, int ymin, int xmax, int ymax, VALUE * hash_arg,
9
+ sync_ sync_mode, bool primary, action_struct ** payload_ptr);
10
+ void draw_epilogue(action_struct * cur, texture_info * tex, bool primary);
11
+
12
+ void set_pixel_color_with_style(action_struct * payload, texture_info * tex, int x, int y);
13
+ void set_pixel_color(rgba * pixel_color, texture_info * tex, int x, int y);
14
+
15
+ rgba get_pixel_color_from_chunk(float * chunk, int width, int height, int x, int y);
16
+ rgba get_pixel_color(texture_info * tex, int x, int y);
17
+ float* get_pixel_data(texture_info * tex, int x, int y);
18
+
19
+ /* create a blank gosu image of width and height */
20
+ VALUE create_image(VALUE window, int width, int height);
21
+
22
+ #endif
@@ -1,201 +1,206 @@
1
- /* texplay.c, light-weight alternative to rmagick for ruby */
2
- /* (C) John Mair 2009
3
- * This program is distributed under the terms of the MIT License
4
- * */
5
-
6
- #include <ruby.h>
7
- #include <stdio.h>
8
- #include <time.h>
9
- #include "texplay.h"
10
- #include "actions.h"
11
- #include "utils.h"
12
- #include "bindings.h"
13
- #ifdef __APPLE__
14
- # include <glut.h>
15
- #else
16
- # include <GL/glut.h>
17
- #endif
18
-
19
-
20
- /* setup ruby bindings */
21
-
22
- /** constructor for TPPoint class **/
23
- static VALUE m_init_TPPoint(int argc, VALUE * argv, VALUE self);
24
- static void monkey_patch_gosu(void);
25
- static VALUE gosu_window(void);
26
-
27
- void
28
- Init_texplay() {
29
-
30
- VALUE jm_Module = rb_define_module("TexPlay");
31
- VALUE TPPoint = rb_define_class_under(jm_Module, "TPPoint", rb_cObject);
32
-
33
- /** define basic point class TPPoint **/
34
- rb_attr(TPPoint, rb_intern("x"), 1, 1, Qtrue);
35
- rb_attr(TPPoint, rb_intern("y"), 1, 1, Qtrue);
36
- rb_define_method(TPPoint, "initialize", m_init_TPPoint, -1);
37
- /** end of TPPoint definition **/
38
-
39
- /* TexPlay methods */
40
- rb_define_method(jm_Module, "paint", m_paint, -1);
41
- rb_define_method(jm_Module, "get_pixel", m_getpixel, -1);
42
- rb_define_method(jm_Module, "circle", m_circle, -1);
43
- rb_define_method(jm_Module, "line", m_line, -1);
44
- rb_define_method(jm_Module, "rect", m_rect, -1);
45
- rb_define_method(jm_Module, "pixel", m_pixel, -1);
46
- rb_define_method(jm_Module, "fill", m_flood_fill, -1);
47
- rb_define_method(jm_Module, "bezier", m_bezier, -1);
48
- rb_define_method(jm_Module, "polyline", m_polyline, -1);
49
- rb_define_method(jm_Module, "ngon", m_ngon, -1);
50
-
51
- rb_define_method(jm_Module, "splice", m_splice, -1);
52
-
53
- rb_define_method(jm_Module, "color", m_color, -1);
54
- rb_define_method(jm_Module, "offset", m_offset, -1);
55
- rb_define_method(jm_Module, "method_missing", m_missing, -1);
56
- rb_define_method(jm_Module, "quad_cached?", m_quad_cached, 0);
57
-
58
- rb_define_method(jm_Module, "each", m_each, -1);
59
-
60
- /* needs to be updated, not yet done **/
61
- /* rb_define_method(jm_Module, "bitmask", m_bitmask, -1); */
62
- /* rb_define_method(jm_Module, "leftshift", m_lshift, -1); */
63
- /* rb_define_method(jm_Module, "rightshift", m_rshift, -1); */
64
- /* rb_define_method(jm_Module, "[]=", m_special_pixel, -1); */
65
-
66
- rb_define_method(jm_Module, "dup", m_dup_image, 0);
67
- rb_define_method(jm_Module, "clone", m_clone_image, 0);
68
- rb_define_method(jm_Module, "to_blob", m_to_blob, 0);
69
- rb_define_method(jm_Module, "force_sync", m_force_sync, 1);
70
- rb_define_method(jm_Module, "set_options", m_user_set_options, 1);
71
- rb_define_method(jm_Module, "get_options", m_get_options, 0);
72
- rb_define_method(jm_Module, "delete_options", m_user_delete_options, 0);
73
-
74
- rb_define_method(jm_Module, "refresh_cache", m_cache_refresh, 0);
75
-
76
- /* a constant containing the sidelength of largest allowable quad */
77
- rb_define_const(jm_Module, "TP_MAX_QUAD_SIZE", INT2FIX(max_quad_size() - 2));
78
-
79
- /* singleton method for creating & removing macros */
80
- rb_define_singleton_method(jm_Module, "create_macro", M_create_macro, 1);
81
- rb_define_singleton_method(jm_Module, "remove_macro", M_remove_macro, 1);
82
- rb_define_singleton_method(jm_Module, "refresh_cache_all", M_refresh_cache_all, 0);
83
- /* rb_define_singleton_method(jm_Module, "create_blank_image", M_create_blank, 3); */
84
-
85
- /** aliases; must be made on singleton class because we're using class methods **/
86
- rb_define_method(jm_Module, "box", m_rect, -1);
87
- rb_define_method(jm_Module, "colour", m_color, -1);
88
- rb_define_method(jm_Module, "composite", m_splice, -1);
89
- rb_define_method(jm_Module, "set_pixel", m_pixel, -1);
90
- rb_define_method(jm_Module, "[]", m_getpixel, -1);
91
- rb_define_method(jm_Module, "cache", m_cache_refresh, 0);
92
- /** end of aliases **/
93
-
94
- /** basic setup **/
95
-
96
- /* seed the random number generator */
97
- srand(time(NULL));
98
-
99
- monkey_patch_gosu();
100
- /** end basic setup **/
101
- }
102
-
103
- /** constructor for TPPoint class **/
104
- static VALUE
105
- m_init_TPPoint(int argc, VALUE * argv, VALUE self)
106
- {
107
- if(argc == 0) {
108
- rb_iv_set(self, "@x", INT2FIX(0));
109
- rb_iv_set(self, "@y", INT2FIX(0));
110
- }
111
- else if(argc == 2){
112
- if(is_a_num(argv[0]) && is_a_num(argv[1])) {
113
- rb_iv_set(self, "@x", argv[0]);
114
- rb_iv_set(self, "@y", argv[1]);
115
- }
116
- else
117
- rb_raise(rb_eArgError, "must provide two numbers");
118
- }
119
- else
120
- rb_raise(rb_eArgError, "please provide x and y args only");
121
-
122
- return Qnil;
123
-
124
- }
125
- /** end constructor for TPPoint **/
126
-
127
-
128
- static VALUE
129
- gosu_window_to_blob(VALUE self, VALUE rb_x, VALUE rb_y, VALUE rb_width, VALUE rb_height)
130
- {
131
- int x = FIX2INT(rb_x);
132
- int y = FIX2INT(rb_y);
133
- int width = FIX2INT(rb_width);
134
- int height = FIX2INT(rb_height);
135
- int window_height = FIX2INT(rb_funcall(self, rb_intern("height"), 0));
136
-
137
- VALUE blob = rb_str_new(NULL, 4 * width * height);
138
-
139
- rb_funcall(self, rb_intern("flush"), 0);
140
- glFinish();
141
-
142
- glReadPixels(x, y, width, window_height - y, GL_RGBA,
143
- GL_UNSIGNED_BYTE, RSTRING_PTR(blob));
144
-
145
- return blob;
146
- }
147
-
148
- static VALUE
149
- gosu_window_to_texture(VALUE self, VALUE rb_tex_name, VALUE rb_xoffset, VALUE rb_yoffset,
150
- VALUE rb_x, VALUE rb_y, VALUE rb_width, VALUE rb_height)
151
- {
152
-
153
- int tex_name = FIX2INT(rb_tex_name);
154
- int xoffset = FIX2INT(rb_xoffset);
155
- int yoffset = FIX2INT(rb_yoffset);
156
- int x = FIX2INT(rb_x);
157
- int y = FIX2INT(rb_y);
158
- int width = FIX2INT(rb_width);
159
- int height = FIX2INT(rb_height);
160
-
161
- rb_funcall(self, rb_intern("flush"), 0);
162
- glFinish();
163
-
164
- glEnable(GL_TEXTURE_2D);
165
- glBindTexture(GL_TEXTURE_2D, tex_name);
166
-
167
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, x, y, width, height);
168
- glDisable(GL_TEXTURE_2D);
169
-
170
- return Qnil;
171
- }
172
-
173
-
174
- static void
175
- monkey_patch_gosu(void)
176
- {
177
- rb_define_method(gosu_window(), "to_blob", gosu_window_to_blob, 4);
178
- rb_define_method(gosu_window(), "to_texture", gosu_window_to_texture, 7);
179
- }
180
-
181
- static VALUE
182
- gosu_window(void)
183
- {
184
- static VALUE GosuWindow = 0;
185
-
186
- if (!GosuWindow) {
187
- VALUE Gosu = rb_const_get(rb_cObject, rb_intern("Gosu"));
188
- GosuWindow = rb_const_get(Gosu, rb_intern("Window"));
189
- }
190
-
191
- return GosuWindow;
192
- }
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
1
+ /* texplay.c, light-weight alternative to rmagick for ruby */
2
+ /* (C) John Mair 2009
3
+ * This program is distributed under the terms of the MIT License
4
+ * */
5
+
6
+ #include <ruby.h>
7
+ #include <stdio.h>
8
+ #include <time.h>
9
+ #include "texplay.h"
10
+ #include "actions.h"
11
+ #include "utils.h"
12
+ #include "bindings.h"
13
+ #ifdef __APPLE__
14
+ # include <AvailabilityMacros.h>
15
+ #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9
16
+ # include <GLUT/glut.h>
17
+ #else
18
+ # include <GL/glut.h>
19
+ #endif
20
+ #else
21
+ # include <GL/glut.h>
22
+ #endif
23
+
24
+
25
+ /* setup ruby bindings */
26
+
27
+ /** constructor for TPPoint class **/
28
+ static VALUE m_init_TPPoint(int argc, VALUE * argv, VALUE self);
29
+ static void monkey_patch_gosu(void);
30
+ static VALUE gosu_window(void);
31
+
32
+ void
33
+ Init_texplay() {
34
+
35
+ VALUE jm_Module = rb_define_module("TexPlay");
36
+ VALUE TPPoint = rb_define_class_under(jm_Module, "TPPoint", rb_cObject);
37
+
38
+ /** define basic point class TPPoint **/
39
+ rb_attr(TPPoint, rb_intern("x"), 1, 1, Qtrue);
40
+ rb_attr(TPPoint, rb_intern("y"), 1, 1, Qtrue);
41
+ rb_define_method(TPPoint, "initialize", m_init_TPPoint, -1);
42
+ /** end of TPPoint definition **/
43
+
44
+ /* TexPlay methods */
45
+ rb_define_method(jm_Module, "paint", m_paint, -1);
46
+ rb_define_method(jm_Module, "get_pixel", m_getpixel, -1);
47
+ rb_define_method(jm_Module, "circle", m_circle, -1);
48
+ rb_define_method(jm_Module, "line", m_line, -1);
49
+ rb_define_method(jm_Module, "rect", m_rect, -1);
50
+ rb_define_method(jm_Module, "pixel", m_pixel, -1);
51
+ rb_define_method(jm_Module, "fill", m_flood_fill, -1);
52
+ rb_define_method(jm_Module, "bezier", m_bezier, -1);
53
+ rb_define_method(jm_Module, "polyline", m_polyline, -1);
54
+ rb_define_method(jm_Module, "ngon", m_ngon, -1);
55
+
56
+ rb_define_method(jm_Module, "splice", m_splice, -1);
57
+
58
+ rb_define_method(jm_Module, "color", m_color, -1);
59
+ rb_define_method(jm_Module, "offset", m_offset, -1);
60
+ rb_define_method(jm_Module, "method_missing", m_missing, -1);
61
+ rb_define_method(jm_Module, "quad_cached?", m_quad_cached, 0);
62
+
63
+ rb_define_method(jm_Module, "each", m_each, -1);
64
+
65
+ /* needs to be updated, not yet done **/
66
+ /* rb_define_method(jm_Module, "bitmask", m_bitmask, -1); */
67
+ /* rb_define_method(jm_Module, "leftshift", m_lshift, -1); */
68
+ /* rb_define_method(jm_Module, "rightshift", m_rshift, -1); */
69
+ /* rb_define_method(jm_Module, "[]=", m_special_pixel, -1); */
70
+
71
+ rb_define_method(jm_Module, "dup", m_dup_image, 0);
72
+ rb_define_method(jm_Module, "clone", m_clone_image, 0);
73
+ rb_define_method(jm_Module, "to_blob", m_to_blob, 0);
74
+ rb_define_method(jm_Module, "force_sync", m_force_sync, 1);
75
+ rb_define_method(jm_Module, "set_options", m_user_set_options, 1);
76
+ rb_define_method(jm_Module, "get_options", m_get_options, 0);
77
+ rb_define_method(jm_Module, "delete_options", m_user_delete_options, 0);
78
+
79
+ rb_define_method(jm_Module, "refresh_cache", m_cache_refresh, 0);
80
+
81
+ /* a constant containing the sidelength of largest allowable quad */
82
+ rb_define_const(jm_Module, "TP_MAX_QUAD_SIZE", INT2FIX(max_quad_size() - 2));
83
+
84
+ /* singleton method for creating & removing macros */
85
+ rb_define_singleton_method(jm_Module, "create_macro", M_create_macro, 1);
86
+ rb_define_singleton_method(jm_Module, "remove_macro", M_remove_macro, 1);
87
+ rb_define_singleton_method(jm_Module, "refresh_cache_all", M_refresh_cache_all, 0);
88
+ /* rb_define_singleton_method(jm_Module, "create_blank_image", M_create_blank, 3); */
89
+
90
+ /** aliases; must be made on singleton class because we're using class methods **/
91
+ rb_define_method(jm_Module, "box", m_rect, -1);
92
+ rb_define_method(jm_Module, "colour", m_color, -1);
93
+ rb_define_method(jm_Module, "composite", m_splice, -1);
94
+ rb_define_method(jm_Module, "set_pixel", m_pixel, -1);
95
+ rb_define_method(jm_Module, "[]", m_getpixel, -1);
96
+ rb_define_method(jm_Module, "cache", m_cache_refresh, 0);
97
+ /** end of aliases **/
98
+
99
+ /** basic setup **/
100
+
101
+ /* seed the random number generator */
102
+ srand(time(NULL));
103
+
104
+ monkey_patch_gosu();
105
+ /** end basic setup **/
106
+ }
107
+
108
+ /** constructor for TPPoint class **/
109
+ static VALUE
110
+ m_init_TPPoint(int argc, VALUE * argv, VALUE self)
111
+ {
112
+ if(argc == 0) {
113
+ rb_iv_set(self, "@x", INT2FIX(0));
114
+ rb_iv_set(self, "@y", INT2FIX(0));
115
+ }
116
+ else if(argc == 2){
117
+ if(is_a_num(argv[0]) && is_a_num(argv[1])) {
118
+ rb_iv_set(self, "@x", argv[0]);
119
+ rb_iv_set(self, "@y", argv[1]);
120
+ }
121
+ else
122
+ rb_raise(rb_eArgError, "must provide two numbers");
123
+ }
124
+ else
125
+ rb_raise(rb_eArgError, "please provide x and y args only");
126
+
127
+ return Qnil;
128
+
129
+ }
130
+ /** end constructor for TPPoint **/
131
+
132
+
133
+ static VALUE
134
+ gosu_window_to_blob(VALUE self, VALUE rb_x, VALUE rb_y, VALUE rb_width, VALUE rb_height)
135
+ {
136
+ int x = FIX2INT(rb_x);
137
+ int y = FIX2INT(rb_y);
138
+ int width = FIX2INT(rb_width);
139
+ int height = FIX2INT(rb_height);
140
+ int window_height = FIX2INT(rb_funcall(self, rb_intern("height"), 0));
141
+
142
+ VALUE blob = rb_str_new(NULL, 4 * width * height);
143
+
144
+ rb_funcall(self, rb_intern("flush"), 0);
145
+ glFinish();
146
+
147
+ glReadPixels(x, y, width, window_height - y, GL_RGBA,
148
+ GL_UNSIGNED_BYTE, RSTRING_PTR(blob));
149
+
150
+ return blob;
151
+ }
152
+
153
+ static VALUE
154
+ gosu_window_to_texture(VALUE self, VALUE rb_tex_name, VALUE rb_xoffset, VALUE rb_yoffset,
155
+ VALUE rb_x, VALUE rb_y, VALUE rb_width, VALUE rb_height)
156
+ {
157
+
158
+ int tex_name = FIX2INT(rb_tex_name);
159
+ int xoffset = FIX2INT(rb_xoffset);
160
+ int yoffset = FIX2INT(rb_yoffset);
161
+ int x = FIX2INT(rb_x);
162
+ int y = FIX2INT(rb_y);
163
+ int width = FIX2INT(rb_width);
164
+ int height = FIX2INT(rb_height);
165
+
166
+ rb_funcall(self, rb_intern("flush"), 0);
167
+ glFinish();
168
+
169
+ glEnable(GL_TEXTURE_2D);
170
+ glBindTexture(GL_TEXTURE_2D, tex_name);
171
+
172
+ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, x, y, width, height);
173
+ glDisable(GL_TEXTURE_2D);
174
+
175
+ return Qnil;
176
+ }
177
+
178
+
179
+ static void
180
+ monkey_patch_gosu(void)
181
+ {
182
+ rb_define_method(gosu_window(), "to_blob", gosu_window_to_blob, 4);
183
+ rb_define_method(gosu_window(), "to_texture", gosu_window_to_texture, 7);
184
+ }
185
+
186
+ static VALUE
187
+ gosu_window(void)
188
+ {
189
+ static VALUE GosuWindow = 0;
190
+
191
+ if (!GosuWindow) {
192
+ VALUE Gosu = rb_const_get(rb_cObject, rb_intern("Gosu"));
193
+ GosuWindow = rb_const_get(Gosu, rb_intern("Window"));
194
+ }
195
+
196
+ return GosuWindow;
197
+ }
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+