texplay 0.2.1-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/CHANGELOG +68 -0
  2. data/README +21 -0
  3. data/README1st +9 -0
  4. data/Rakefile +85 -0
  5. data/examples/basic.rb +48 -0
  6. data/examples/basic2.rb +37 -0
  7. data/examples/benchmark.rb +299 -0
  8. data/examples/common.rb +8 -0
  9. data/examples/example_alpha_blend.rb +31 -0
  10. data/examples/example_bezier.rb +51 -0
  11. data/examples/example_color_control.rb +68 -0
  12. data/examples/example_color_transform.rb +29 -0
  13. data/examples/example_dup.rb +52 -0
  14. data/examples/example_each.rb +42 -0
  15. data/examples/example_effect.rb +35 -0
  16. data/examples/example_fill.rb +49 -0
  17. data/examples/example_fill_old.rb +49 -0
  18. data/examples/example_fluent.rb +31 -0
  19. data/examples/example_gen_eval.rb +34 -0
  20. data/examples/example_hash_arguments.rb +47 -0
  21. data/examples/example_melt.rb +27 -0
  22. data/examples/example_polyline.rb +43 -0
  23. data/examples/example_simple.rb +35 -0
  24. data/examples/example_sync.rb +60 -0
  25. data/examples/example_turtle.rb +40 -0
  26. data/examples/media/empty2.png +0 -0
  27. data/examples/media/gosu.png +0 -0
  28. data/examples/media/maria.png +0 -0
  29. data/examples/media/rose.bmp +0 -0
  30. data/examples/media/sand1.png +0 -0
  31. data/examples/media/sunset.png +0 -0
  32. data/examples/media/texplay.png +0 -0
  33. data/examples/specs.rb +240 -0
  34. data/examples/test.rb +70 -0
  35. data/examples/test2.rb +72 -0
  36. data/lib/ctexplay.18.so +0 -0
  37. data/lib/ctexplay.19.so +0 -0
  38. data/lib/texplay-contrib.rb +77 -0
  39. data/lib/texplay.rb +134 -0
  40. data/src/Makefile +181 -0
  41. data/src/TAGS +286 -0
  42. data/src/actions.c +1306 -0
  43. data/src/actions.h +52 -0
  44. data/src/actions.obj +0 -0
  45. data/src/bindings.c +1081 -0
  46. data/src/bindings.h +45 -0
  47. data/src/bindings.obj +0 -0
  48. data/src/cache.c +132 -0
  49. data/src/cache.h +24 -0
  50. data/src/cache.obj +0 -0
  51. data/src/compat.h +23 -0
  52. data/src/ctexplay-i386-mswin32.def +2 -0
  53. data/src/ctexplay-i386-mswin32.exp +0 -0
  54. data/src/ctexplay-i386-mswin32.lib +0 -0
  55. data/src/ctexplay-i386-mswin32.pdb +0 -0
  56. data/src/ctexplay.so +0 -0
  57. data/src/extconf.rb +18 -0
  58. data/src/gen_eval.c +209 -0
  59. data/src/gen_eval.h +20 -0
  60. data/src/gen_eval.obj +0 -0
  61. data/src/mkmf.log +18 -0
  62. data/src/object2module.c +171 -0
  63. data/src/object2module.h +11 -0
  64. data/src/object2module.obj +0 -0
  65. data/src/texplay.c +136 -0
  66. data/src/texplay.h +107 -0
  67. data/src/texplay.obj +0 -0
  68. data/src/utils.c +959 -0
  69. data/src/utils.h +143 -0
  70. data/src/utils.obj +0 -0
  71. data/src/vc60.pdb +0 -0
  72. metadata +132 -0
data/src/gen_eval.h ADDED
@@ -0,0 +1,20 @@
1
+ /* gen_eval.h */
2
+
3
+ #ifndef GUARD_GEN_EVAL_H
4
+ #define GUARD_GEN_EVAL_H
5
+
6
+ #include <ruby.h>
7
+
8
+ VALUE rb_gen_eval(int argc, VALUE * argv, VALUE self);
9
+ VALUE rb_capture(VALUE self);
10
+ VALUE retrieve_hidden_self(VALUE duped_context);
11
+ void set_hidden_self(VALUE duped_context, VALUE hidden_self);
12
+
13
+ /* change self to hidden self if __hidden_self__ defined */
14
+ #define ADJUST_SELF(X) \
15
+ do { \
16
+ if(!NIL_P(retrieve_hidden_self((X)))) \
17
+ (X) = retrieve_hidden_self((X)); \
18
+ } while(0)
19
+
20
+ #endif
data/src/gen_eval.obj ADDED
Binary file
data/src/mkmf.log ADDED
@@ -0,0 +1,18 @@
1
+ have_library: checking for main() in glut32.lib... -------------------- yes
2
+
3
+ "cl -nologo -Feconftest -I. -Ic:/ruby/lib/ruby/1.8/i386-mswin32 -I. -Ic:/ruby/lib/ruby/1.8/i386-mswin32 -MD -Zi -O2b2xg- -G6 conftest.c msvcrt-ruby18-static.lib glut32.lib oldnames.lib user32.lib advapi32.lib shell32.lib ws2_32.lib -link -libpath:"." -libpath:"c:/ruby/lib" -stack:0x2000000"
4
+ conftest.c
5
+ checked program was:
6
+ /* begin */
7
+ 1: #define WIN32_LEAN_AND_MEAN
8
+ 2: #define WIN32
9
+ 3: #include <winsock2.h>
10
+ 4: #include <windows.h>
11
+ 5:
12
+ 6: /*top*/
13
+ 7: int main() { return 0; }
14
+ 8: int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
15
+ /* end */
16
+
17
+ --------------------
18
+
@@ -0,0 +1,171 @@
1
+ /* object2module.c */
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 "compat.h"
8
+
9
+ #ifdef RUBY_19
10
+ # include <ruby/st.h>
11
+ #else
12
+ # include <st.h>
13
+ #endif
14
+
15
+ /* class creation. from class.c in 1.9.1 */
16
+ #ifdef RUBY_19
17
+ static VALUE
18
+ class_alloc(VALUE flags, VALUE klass)
19
+ {
20
+ rb_classext_t *ext = ALLOC(rb_classext_t);
21
+ NEWOBJ(obj, struct RClass);
22
+ OBJSETUP(obj, klass, flags);
23
+ obj->ptr = ext;
24
+ RCLASS_IV_TBL(obj) = 0;
25
+ RCLASS_M_TBL(obj) = 0;
26
+ RCLASS_SUPER(obj) = 0;
27
+ RCLASS_IV_INDEX_TBL(obj) = 0;
28
+ return (VALUE)obj;
29
+ }
30
+ #endif
31
+
32
+ /* a modified version of include_class_new from class.c */
33
+ static VALUE
34
+ j_class_new(VALUE module, VALUE sup)
35
+ {
36
+
37
+ #ifdef RUBY_19
38
+ VALUE klass = class_alloc(T_ICLASS, rb_cClass);
39
+ #else
40
+ NEWOBJ(klass, struct RClass);
41
+ OBJSETUP(klass, rb_cClass, T_ICLASS);
42
+ #endif
43
+
44
+ if (BUILTIN_TYPE(module) == T_ICLASS) {
45
+ module = KLASS_OF(module);
46
+ }
47
+
48
+ if (!RCLASS_IV_TBL(module)) {
49
+
50
+ RCLASS_IV_TBL(module) = (struct st_table *)st_init_numtable();
51
+ }
52
+
53
+ /* assign iv_tbl, m_tbl and super */
54
+ RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module);
55
+ RCLASS_SUPER(klass) = sup;
56
+ if(TYPE(module) != T_OBJECT) {
57
+
58
+ RCLASS_M_TBL(klass) = RCLASS_M_TBL(module);
59
+ }
60
+ else {
61
+ RCLASS_M_TBL(klass) = RCLASS_M_TBL(CLASS_OF(module));
62
+ }
63
+
64
+ /* */
65
+
66
+ if (TYPE(module) == T_ICLASS) {
67
+ KLASS_OF(klass) = KLASS_OF(module);
68
+ }
69
+ else {
70
+ KLASS_OF(klass) = module;
71
+ }
72
+
73
+ if(TYPE(module) != T_OBJECT) {
74
+ OBJ_INFECT(klass, module);
75
+ OBJ_INFECT(klass, sup);
76
+ }
77
+ return (VALUE)klass;
78
+ }
79
+
80
+ VALUE
81
+ rb_to_module(VALUE self)
82
+ {
83
+ VALUE rclass, chain_start, jcur, klass;
84
+
85
+ switch(BUILTIN_TYPE(self)) {
86
+ case T_MODULE:
87
+ return self;
88
+ case T_CLASS:
89
+ klass = self;
90
+ break;
91
+ case T_OBJECT:
92
+ default:
93
+ klass = rb_singleton_class(self);
94
+ }
95
+
96
+ chain_start = j_class_new(klass, rb_cObject);
97
+
98
+ KLASS_OF(chain_start) = rb_cModule;
99
+ RBASIC(chain_start)->flags = T_MODULE;
100
+
101
+ jcur = chain_start;
102
+ for(rclass = RCLASS_SUPER(klass); rclass != rb_cObject;
103
+ rclass = RCLASS_SUPER(rclass)) {
104
+
105
+ RCLASS_SUPER(jcur) = j_class_new(rclass, rb_cObject);
106
+ jcur = RCLASS_SUPER(jcur);
107
+ }
108
+
109
+ RCLASS_SUPER(jcur) = (VALUE)NULL;
110
+
111
+ return chain_start;
112
+ }
113
+
114
+ VALUE
115
+ rb_reset_tbls(VALUE self)
116
+ {
117
+ RCLASS_IV_TBL(self) = (struct st_table *) 0;
118
+ RCLASS_M_TBL(self) = (struct st_table *) st_init_numtable();
119
+ return Qnil;
120
+ }
121
+
122
+ /* cannot simply forward to gen_include as need to invoke 'extended' hook */
123
+ VALUE
124
+ rb_gen_extend(int argc, VALUE * argv, VALUE self)
125
+ {
126
+ int i;
127
+
128
+ if (argc == 0) rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)");
129
+
130
+ rb_singleton_class(self);
131
+
132
+ for(i = 0; i < argc; i++) {
133
+ VALUE mod = rb_to_module(argv[i]);
134
+ rb_funcall(mod, rb_intern("extend_object"), 1, self);
135
+ rb_funcall(mod, rb_intern("extended"), 1, self);
136
+
137
+ /* only redirect if argv[i] is not a module */
138
+ if(argv[i] != mod) rb_reset_tbls(mod);
139
+ }
140
+
141
+ return self;
142
+ }
143
+
144
+ VALUE
145
+ rb_gen_include(int argc, VALUE * argv, VALUE self)
146
+ {
147
+ int i;
148
+
149
+ if (argc == 0) rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)");
150
+
151
+ for(i = 0; i < argc; i++) {
152
+ VALUE mod = rb_to_module(argv[i]);
153
+ rb_funcall(mod, rb_intern("append_features"), 1, self);
154
+ rb_funcall(mod, rb_intern("included"), 1, self);
155
+
156
+ if(argv[i] != mod) rb_reset_tbls(mod);
157
+ }
158
+
159
+ return self;
160
+ }
161
+
162
+
163
+ void Init_object2module()
164
+ {
165
+
166
+ rb_define_method(rb_cObject, "to_module", rb_to_module , 0);
167
+ rb_define_method(rb_cObject, "gen_extend", rb_gen_extend, -1);
168
+ rb_define_method(rb_cModule, "gen_include", rb_gen_include, -1);
169
+ rb_define_method(rb_cModule, "reset_tbls", rb_reset_tbls, 0);
170
+ }
171
+
@@ -0,0 +1,11 @@
1
+ /* object2module.h */
2
+
3
+ #ifndef GUARD_OBJECT2MODULE_H
4
+ #define GUARD_OBJECT2MODULE_H
5
+
6
+ VALUE rb_gen_include(int argc, VALUE * argv, VALUE self);
7
+ VALUE rb_gen_extend(int argc, VALUE * argv, VALUE self);
8
+ VALUE rb_to_module(VALUE self);
9
+ VALUE rb_reset_tbls(VALUE self);
10
+
11
+ #endif
Binary file
data/src/texplay.c ADDED
@@ -0,0 +1,136 @@
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
+ #include "object2module.h"
14
+ #include "gen_eval.h"
15
+
16
+ /* setup ruby bindings */
17
+
18
+ /** constructor for TPPoint class **/
19
+ static VALUE m_init_TPPoint(int argc, VALUE * argv, VALUE self);
20
+
21
+ void
22
+ Init_ctexplay() {
23
+
24
+ VALUE jm_Module = rb_define_module("TexPlay");
25
+ VALUE TPPoint = rb_define_class_under(jm_Module, "TPPoint", rb_cObject);
26
+
27
+ /** define basic point class TPPoint **/
28
+ rb_attr(TPPoint, rb_intern("x"), 1, 1, Qtrue);
29
+ rb_attr(TPPoint, rb_intern("y"), 1, 1, Qtrue);
30
+ rb_define_method(TPPoint, "initialize", m_init_TPPoint, -1);
31
+ /** end of TPPoint definition **/
32
+
33
+ /* TexPlay methods */
34
+ rb_define_method(jm_Module, "paint", m_paint, -1);
35
+ rb_define_method(jm_Module, "get_pixel", m_getpixel, -1);
36
+ rb_define_method(jm_Module, "circle", m_circle, -1);
37
+ rb_define_method(jm_Module, "line", m_line, -1);
38
+ rb_define_method(jm_Module, "rect", m_rect, -1);
39
+ rb_define_method(jm_Module, "clear", m_clear, -1);
40
+ rb_define_method(jm_Module, "pixel", m_pixel, -1);
41
+ rb_define_method(jm_Module, "fill", m_flood_fill, -1);
42
+ rb_define_method(jm_Module, "bezier", m_bezier, -1);
43
+ rb_define_method(jm_Module, "polyline", m_polyline, -1);
44
+ rb_define_method(jm_Module, "ngon", m_ngon, -1);
45
+
46
+ rb_define_method(jm_Module, "splice", m_splice, -1);
47
+
48
+ rb_define_method(jm_Module, "color", m_color, -1);
49
+ rb_define_method(jm_Module, "offset", m_offset, -1);
50
+ rb_define_method(jm_Module, "method_missing", m_missing, -1);
51
+ rb_define_method(jm_Module, "quad_cached?", m_quad_cached, 0);
52
+
53
+ rb_define_method(jm_Module, "each", m_each, -1);
54
+
55
+ /* needs to be updated, not yet done **/
56
+ /* rb_define_method(jm_Module, "bitmask", m_bitmask, -1); */
57
+ /* rb_define_method(jm_Module, "leftshift", m_lshift, -1); */
58
+ /* rb_define_method(jm_Module, "rightshift", m_rshift, -1); */
59
+ /* rb_define_method(jm_Module, "[]=", m_special_pixel, -1); */
60
+
61
+ rb_define_method(jm_Module, "dup", m_dup_image, 0);
62
+ rb_define_method(jm_Module, "clone", m_clone_image, 0);
63
+ rb_define_method(jm_Module, "force_sync", m_force_sync, 1);
64
+ rb_define_method(jm_Module, "set_options", m_user_set_options, 1);
65
+ rb_define_method(jm_Module, "get_options", m_get_options, 0);
66
+ rb_define_method(jm_Module, "delete_options", m_user_delete_options, 0);
67
+
68
+ rb_define_method(jm_Module, "refresh_cache", m_cache_refresh, 0);
69
+
70
+ /* a constant containing the sidelength of largest allowable quad */
71
+ rb_define_const(jm_Module, "TP_MAX_QUAD_SIZE", INT2FIX(max_quad_size()));
72
+
73
+ /* singleton method for creating & removing macros */
74
+ rb_define_singleton_method(jm_Module, "create_macro", M_create_macro, 1);
75
+ rb_define_singleton_method(jm_Module, "remove_macro", M_remove_macro, 1);
76
+ rb_define_singleton_method(jm_Module, "refresh_cache_all", M_refresh_cache_all, 0);
77
+ rb_define_singleton_method(jm_Module, "create_blank_image", M_create_blank, 3);
78
+
79
+ /** aliases; must be made on singleton class because we're using class methods **/
80
+ rb_define_method(jm_Module, "box", m_rect, -1);
81
+ rb_define_method(jm_Module, "colour", m_color, -1);
82
+ rb_define_method(jm_Module, "composite", m_splice, -1);
83
+ rb_define_method(jm_Module, "set_pixel", m_pixel, -1);
84
+ rb_define_method(jm_Module, "[]", m_getpixel, 2);
85
+ /** end of aliases **/
86
+
87
+ /** associated with gen_eval **/
88
+ rb_define_method(rb_cObject, "gen_eval", rb_gen_eval, -1);
89
+ rb_define_method(rb_cObject, "capture", rb_capture, 0);
90
+
91
+ rb_define_method(rb_cObject, "to_module", rb_to_module , 0);
92
+ rb_define_method(rb_cObject, "reset_tbls", rb_reset_tbls , 0);
93
+ rb_define_method(rb_cObject, "gen_extend", rb_gen_extend, -1);
94
+ rb_define_method(rb_cModule, "gen_include", rb_gen_include, -1);
95
+
96
+ rb_define_alias(rb_cObject, "gen_eval_with", "gen_eval");
97
+ /** end of gen_eval defs **/
98
+
99
+
100
+ /** basic setup **/
101
+
102
+ /* seed the random number generator */
103
+ srand(time(NULL));
104
+
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
+
134
+
135
+
136
+
data/src/texplay.h ADDED
@@ -0,0 +1,107 @@
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
+
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
+ /* structs */
44
+ typedef struct s_rgba {
45
+ float red, green, blue, alpha;
46
+ } rgba;
47
+
48
+ /* stores image data */
49
+ typedef struct {
50
+ int width, height;
51
+ float top, left;
52
+ int tname;
53
+ float * td_array;
54
+ int yincr, firstpixel;
55
+ int x_offset, y_offset;
56
+ VALUE image;
57
+ } texture_info;
58
+
59
+
60
+ /* convenience macro */
61
+ #define IMAGE_BOUNDS(X) ((image_bounds *) (X))
62
+ typedef struct {
63
+ int xmin;
64
+ int ymin;
65
+ int xmax;
66
+ int ymax;
67
+ } image_bounds;
68
+
69
+ typedef struct action_struct {
70
+ int xmin, ymin, xmax, ymax;
71
+ sync sync_mode;
72
+
73
+ /* pointer to associated texture */
74
+ /* a bit of a kludge having this here
75
+ since it's only being used by convert_image_local_color_to_rgba */
76
+ texture_info * tex;
77
+
78
+ VALUE hash_arg;
79
+
80
+ /* action color */
81
+ rgba color;
82
+
83
+ /* pen data */
84
+ struct {
85
+
86
+ /* color control, dynamic */
87
+ VALUE color_control_proc;
88
+ bool has_color_control_proc;
89
+ int color_control_arity;
90
+
91
+ /* color control, static */
92
+ bool has_color_control_transform;
93
+ rgba color_mult;
94
+ rgba color_add;
95
+
96
+ /* texture fill */
97
+ texture_info source_tex;
98
+ bool has_source_texture;
99
+
100
+ /* alpha blend */
101
+ bool alpha_blend;
102
+ } pen;
103
+
104
+ } action_struct;
105
+
106
+
107
+ #endif