texplay 0.4.2 → 0.4.3

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.
Files changed (74) hide show
  1. data/CHANGELOG +222 -222
  2. data/README.markdown +48 -43
  3. data/Rakefile +16 -3
  4. data/examples/common.rb +18 -18
  5. data/examples/example_alpha_blend.rb +29 -29
  6. data/examples/example_bezier.rb +41 -41
  7. data/examples/example_blank.rb +37 -37
  8. data/examples/example_cache.rb +21 -21
  9. data/examples/example_color_control.rb +69 -69
  10. data/examples/example_color_transform.rb +62 -62
  11. data/examples/example_color_transform_circle.rb +34 -34
  12. data/examples/example_darken.rb +24 -24
  13. data/examples/example_dup.rb +73 -73
  14. data/examples/example_each.rb +39 -39
  15. data/examples/example_effect.rb +34 -34
  16. data/examples/example_fill.rb +43 -43
  17. data/examples/example_fill_old.rb +48 -48
  18. data/examples/example_fluent.rb +29 -29
  19. data/examples/example_font.rb +31 -31
  20. data/examples/example_hash_arguments.rb +46 -46
  21. data/examples/example_ippa.rb +23 -23
  22. data/examples/example_light.rb +75 -75
  23. data/examples/example_light_multiply.rb +18 -18
  24. data/examples/example_lsystem.rb +61 -61
  25. data/examples/example_melt.rb +25 -25
  26. data/examples/example_meyet.rb +62 -62
  27. data/examples/example_polyline.rb +42 -42
  28. data/examples/example_scale.rb +27 -27
  29. data/examples/example_select.rb +36 -36
  30. data/examples/example_select2.rb +25 -25
  31. data/examples/example_simple.rb +46 -46
  32. data/examples/example_splice.rb +26 -26
  33. data/examples/example_sync.rb +59 -59
  34. data/examples/example_tiles.rb +41 -41
  35. data/examples/example_trace.rb +22 -22
  36. data/examples/example_transparent.rb +28 -28
  37. data/examples/example_transparent2.rb +24 -24
  38. data/examples/example_transparent3.rb +20 -20
  39. data/examples/example_turtle.rb +39 -39
  40. data/examples/example_weird.rb +22 -22
  41. data/examples/example_window_render_to_image.rb +41 -41
  42. data/examples/example_window_to_blob.rb +35 -35
  43. data/examples/media/maria.png +0 -0
  44. data/examples/media/rose.bmp +0 -0
  45. data/ext/texplay/actions.c +1006 -1006
  46. data/ext/texplay/actions.h +60 -60
  47. data/ext/texplay/bindings.c +1125 -1125
  48. data/ext/texplay/bindings.h +46 -46
  49. data/ext/texplay/cache.c +118 -118
  50. data/ext/texplay/cache.h +24 -24
  51. data/ext/texplay/compat.h +27 -27
  52. data/ext/texplay/extconf.rb +38 -28
  53. data/ext/texplay/graphics_utils.c +1313 -1313
  54. data/ext/texplay/graphics_utils.h +22 -22
  55. data/ext/texplay/texplay.c +201 -201
  56. data/ext/texplay/texplay.h +153 -153
  57. data/ext/texplay/utils.c +891 -891
  58. data/ext/texplay/utils.h +153 -153
  59. data/ext/texplay/vendor/freeglut/include/GL/freeglut.h +22 -0
  60. data/ext/texplay/vendor/freeglut/include/GL/freeglut_ext.h +236 -0
  61. data/ext/texplay/vendor/freeglut/include/GL/freeglut_std.h +628 -0
  62. data/ext/texplay/vendor/freeglut/include/GL/glut.h +21 -0
  63. data/lib/texplay-contrib.rb +147 -147
  64. data/lib/texplay.rb +347 -341
  65. data/lib/texplay/1.8/texplay.so +0 -0
  66. data/lib/texplay/1.9/texplay.so +0 -0
  67. data/lib/texplay/alone.rb +20 -20
  68. data/lib/texplay/c_function_docs.rb +178 -178
  69. data/lib/texplay/live.rb +84 -84
  70. data/lib/texplay/version.rb +3 -3
  71. data/live/live.rb +85 -85
  72. data/test/image_spec.rb +45 -45
  73. data/test/texplay_spec.rb +144 -144
  74. metadata +63 -49
@@ -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,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 <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 <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,153 +1,153 @@
1
- /* texplay.h (C) John Mair 2008
2
- * This program is distributed under the terms of the MIT License
3
- *
4
- *
5
- * */
6
-
7
- #ifndef GUARD_TEXPLAY_H
8
- #define GUARD_TEXPLAY_H
9
-
10
- #include <ruby.h>
11
-
12
- /* #defines */
13
- #define OOB_VAL 9999
14
- #define XMAX_OOB OOB_VAL
15
- #define YMAX_OOB OOB_VAL
16
- #define XMIN_OOB -OOB_VAL
17
- #define YMIN_OOB -OOB_VAL
18
- #define RGBA_LIST_SIZE 100
19
- #define PI 3.14159265358979
20
-
21
- /* macros */
22
- #define SWAP(X, Y) {(X) ^= (Y); (Y) ^= (X); (X) ^= (Y);}
23
- #define ROUND(X) (int)((X) + 0.5)
24
- #define ARY_SIZE(X) sizeof(X) / sizeof(*X)
25
- #define SGN(X) ((X) >= 0 ? 1 : -1)
26
- #define MAX(X, Y) ((X) > (Y)) ? (X) :(Y)
27
- #define MIN(X, Y) ((X) < (Y)) ? (X) : (Y)
28
- #define ABS(X) ((X) >= 0 ? (X) : -(X))
29
-
30
- /* enums */
31
- typedef enum e_bool {
32
- false, true
33
- } bool;
34
-
35
- typedef enum e_color {
36
- red, green, blue, alpha
37
- } color_t;
38
-
39
- typedef enum e_sync_mode {
40
- lazy_sync, eager_sync, no_sync
41
- } sync;
42
-
43
-
44
- typedef enum {
45
- clear, copy, noop,
46
- set, copy_inverted,
47
- invert, and_reverse, and,
48
- or, nand, nor, xor,
49
- equiv, and_inverted,
50
- or_inverted, additive,
51
- multiply, screen, overlay,
52
- darken, lighten, color_dodge,
53
- color_burn, hard_light, soft_light,
54
- difference, exclusion
55
- } draw_mode;
56
-
57
- typedef enum {
58
- source, dest, source_with_fixed_alpha, dest_with_fixed_alpha
59
- } alpha_blend_mode_t;
60
-
61
- /* structs */
62
- typedef struct s_rgba {
63
- float red, green, blue, alpha;
64
- } rgba;
65
-
66
- typedef struct {
67
- rgba colors[RGBA_LIST_SIZE];
68
- int size;
69
- } rgba_list;
70
-
71
-
72
- /* stores image data */
73
- typedef struct {
74
- int width, height;
75
- float top, left;
76
- int tname;
77
- float * td_array;
78
- int yincr, firstpixel;
79
- int x_offset, y_offset;
80
- VALUE image;
81
- } texture_info;
82
-
83
-
84
- /* convenience macro */
85
- #define IMAGE_BOUNDS(X) ((image_bounds *) (X))
86
- typedef struct {
87
- int xmin;
88
- int ymin;
89
- int xmax;
90
- int ymax;
91
- } image_bounds;
92
-
93
-
94
- typedef struct action_struct {
95
- int xmin, ymin, xmax, ymax;
96
- sync sync_mode;
97
-
98
- /* pointer to associated texture */
99
- /* a bit of a kludge having this here
100
- since it's only being used by convert_image_local_color_to_rgba */
101
- texture_info * tex;
102
-
103
- VALUE hash_arg;
104
-
105
- /* action color */
106
- rgba color;
107
-
108
- /* pen data */
109
- struct {
110
-
111
- /* color control, dynamic */
112
- bool has_color_control_proc;
113
- VALUE color_control_proc;
114
- int color_control_arity;
115
-
116
- /* color control, static */
117
- bool has_color_control_transform;
118
- rgba color_mult;
119
- rgba color_add;
120
-
121
- /* texture fill */
122
- bool has_source_texture;
123
- texture_info source_tex;
124
-
125
- /* lerp */
126
- bool has_lerp;
127
- float lerp;
128
-
129
- /* alpha blend */
130
- bool alpha_blend;
131
- alpha_blend_mode_t alpha_blend_mode;
132
-
133
- /* drawing mode */
134
- bool has_drawing_mode;
135
- draw_mode drawing_mode;
136
-
137
- /* tolerance */
138
- bool has_tolerance;
139
- float tolerance;
140
-
141
- /* color selection */
142
- bool has_color_select;
143
- rgba_list source_select;
144
- rgba_list source_ignore;
145
- rgba_list dest_select;
146
- rgba_list dest_ignore;
147
-
148
- } pen;
149
-
150
- } action_struct;
151
-
152
-
153
- #endif
1
+ /* texplay.h (C) John Mair 2008
2
+ * This program is distributed under the terms of the MIT License
3
+ *
4
+ *
5
+ * */
6
+
7
+ #ifndef GUARD_TEXPLAY_H
8
+ #define GUARD_TEXPLAY_H
9
+
10
+ #include <ruby.h>
11
+
12
+ /* #defines */
13
+ #define OOB_VAL 9999
14
+ #define XMAX_OOB OOB_VAL
15
+ #define YMAX_OOB OOB_VAL
16
+ #define XMIN_OOB -OOB_VAL
17
+ #define YMIN_OOB -OOB_VAL
18
+ #define RGBA_LIST_SIZE 100
19
+ #define PI 3.14159265358979
20
+
21
+ /* macros */
22
+ #define SWAP(X, Y) {(X) ^= (Y); (Y) ^= (X); (X) ^= (Y);}
23
+ #define ROUND(X) (int)((X) + 0.5)
24
+ #define ARY_SIZE(X) sizeof(X) / sizeof(*X)
25
+ #define SGN(X) ((X) >= 0 ? 1 : -1)
26
+ #define MAX(X, Y) ((X) > (Y)) ? (X) :(Y)
27
+ #define MIN(X, Y) ((X) < (Y)) ? (X) : (Y)
28
+ #define ABS(X) ((X) >= 0 ? (X) : -(X))
29
+
30
+ /* enums */
31
+ typedef enum e_bool {
32
+ false, true
33
+ } bool;
34
+
35
+ typedef enum e_color {
36
+ red, green, blue, alpha
37
+ } color_t;
38
+
39
+ typedef enum e_sync_mode {
40
+ lazy_sync, eager_sync, no_sync
41
+ } sync;
42
+
43
+
44
+ typedef enum {
45
+ clear, copy, noop,
46
+ set, copy_inverted,
47
+ invert, and_reverse, and,
48
+ or, nand, nor, xor,
49
+ equiv, and_inverted,
50
+ or_inverted, additive,
51
+ multiply, screen, overlay,
52
+ darken, lighten, color_dodge,
53
+ color_burn, hard_light, soft_light,
54
+ difference, exclusion
55
+ } draw_mode;
56
+
57
+ typedef enum {
58
+ source, dest, source_with_fixed_alpha, dest_with_fixed_alpha
59
+ } alpha_blend_mode_t;
60
+
61
+ /* structs */
62
+ typedef struct s_rgba {
63
+ float red, green, blue, alpha;
64
+ } rgba;
65
+
66
+ typedef struct {
67
+ rgba colors[RGBA_LIST_SIZE];
68
+ int size;
69
+ } rgba_list;
70
+
71
+
72
+ /* stores image data */
73
+ typedef struct {
74
+ int width, height;
75
+ float top, left;
76
+ int tname;
77
+ float * td_array;
78
+ int yincr, firstpixel;
79
+ int x_offset, y_offset;
80
+ VALUE image;
81
+ } texture_info;
82
+
83
+
84
+ /* convenience macro */
85
+ #define IMAGE_BOUNDS(X) ((image_bounds *) (X))
86
+ typedef struct {
87
+ int xmin;
88
+ int ymin;
89
+ int xmax;
90
+ int ymax;
91
+ } image_bounds;
92
+
93
+
94
+ typedef struct action_struct {
95
+ int xmin, ymin, xmax, ymax;
96
+ sync sync_mode;
97
+
98
+ /* pointer to associated texture */
99
+ /* a bit of a kludge having this here
100
+ since it's only being used by convert_image_local_color_to_rgba */
101
+ texture_info * tex;
102
+
103
+ VALUE hash_arg;
104
+
105
+ /* action color */
106
+ rgba color;
107
+
108
+ /* pen data */
109
+ struct {
110
+
111
+ /* color control, dynamic */
112
+ bool has_color_control_proc;
113
+ VALUE color_control_proc;
114
+ int color_control_arity;
115
+
116
+ /* color control, static */
117
+ bool has_color_control_transform;
118
+ rgba color_mult;
119
+ rgba color_add;
120
+
121
+ /* texture fill */
122
+ bool has_source_texture;
123
+ texture_info source_tex;
124
+
125
+ /* lerp */
126
+ bool has_lerp;
127
+ float lerp;
128
+
129
+ /* alpha blend */
130
+ bool alpha_blend;
131
+ alpha_blend_mode_t alpha_blend_mode;
132
+
133
+ /* drawing mode */
134
+ bool has_drawing_mode;
135
+ draw_mode drawing_mode;
136
+
137
+ /* tolerance */
138
+ bool has_tolerance;
139
+ float tolerance;
140
+
141
+ /* color selection */
142
+ bool has_color_select;
143
+ rgba_list source_select;
144
+ rgba_list source_ignore;
145
+ rgba_list dest_select;
146
+ rgba_list dest_ignore;
147
+
148
+ } pen;
149
+
150
+ } action_struct;
151
+
152
+
153
+ #endif