texplay 0.2.7-x86-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +103 -0
- data/README.markdown +41 -0
- data/Rakefile +61 -0
- data/examples/common.rb +8 -0
- data/examples/example_alpha_blend.rb +31 -0
- data/examples/example_bezier.rb +42 -0
- data/examples/example_blur.rb +59 -0
- data/examples/example_color_control.rb +69 -0
- data/examples/example_color_transform.rb +29 -0
- data/examples/example_dup.rb +75 -0
- data/examples/example_each.rb +42 -0
- data/examples/example_effect.rb +35 -0
- data/examples/example_fill.rb +44 -0
- data/examples/example_fill_old.rb +49 -0
- data/examples/example_fluent.rb +31 -0
- data/examples/example_gen_eval.rb +34 -0
- data/examples/example_hash_arguments.rb +47 -0
- data/examples/example_lsystem.rb +61 -0
- data/examples/example_melt.rb +27 -0
- data/examples/example_polyline.rb +43 -0
- data/examples/example_scale.rb +29 -0
- data/examples/example_simple.rb +38 -0
- data/examples/example_splice.rb +33 -0
- data/examples/example_sync.rb +60 -0
- data/examples/example_turtle.rb +40 -0
- data/examples/media/empty2.png +0 -0
- data/examples/media/gosu.png +0 -0
- data/examples/media/logo.png +0 -0
- data/examples/media/maria.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 +1331 -0
- data/ext/texplay/actions.h +52 -0
- data/ext/texplay/bindings.c +1129 -0
- data/ext/texplay/bindings.h +46 -0
- data/ext/texplay/cache.c +135 -0
- data/ext/texplay/cache.h +24 -0
- data/ext/texplay/compat.h +27 -0
- data/ext/texplay/extconf.rb +30 -0
- data/ext/texplay/gen_eval.c +211 -0
- data/ext/texplay/gen_eval.h +20 -0
- data/ext/texplay/object2module.c +171 -0
- data/ext/texplay/object2module.h +11 -0
- data/ext/texplay/texplay.c +137 -0
- data/ext/texplay/texplay.h +107 -0
- data/ext/texplay/utils.c +978 -0
- data/ext/texplay/utils.h +145 -0
- data/lib/1.8/texplay.so +0 -0
- data/lib/1.9/texplay.so +0 -0
- data/lib/texplay-contrib.rb +171 -0
- data/lib/texplay.rb +134 -0
- metadata +114 -0
@@ -0,0 +1,137 @@
|
|
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_texplay() {
|
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, "to_blob", m_to_blob, 0);
|
64
|
+
rb_define_method(jm_Module, "force_sync", m_force_sync, 1);
|
65
|
+
rb_define_method(jm_Module, "set_options", m_user_set_options, 1);
|
66
|
+
rb_define_method(jm_Module, "get_options", m_get_options, 0);
|
67
|
+
rb_define_method(jm_Module, "delete_options", m_user_delete_options, 0);
|
68
|
+
|
69
|
+
rb_define_method(jm_Module, "refresh_cache", m_cache_refresh, 0);
|
70
|
+
|
71
|
+
/* a constant containing the sidelength of largest allowable quad */
|
72
|
+
rb_define_const(jm_Module, "TP_MAX_QUAD_SIZE", INT2FIX(max_quad_size() - 2));
|
73
|
+
|
74
|
+
/* singleton method for creating & removing macros */
|
75
|
+
rb_define_singleton_method(jm_Module, "create_macro", M_create_macro, 1);
|
76
|
+
rb_define_singleton_method(jm_Module, "remove_macro", M_remove_macro, 1);
|
77
|
+
rb_define_singleton_method(jm_Module, "refresh_cache_all", M_refresh_cache_all, 0);
|
78
|
+
rb_define_singleton_method(jm_Module, "create_blank_image", M_create_blank, 3);
|
79
|
+
|
80
|
+
/** aliases; must be made on singleton class because we're using class methods **/
|
81
|
+
rb_define_method(jm_Module, "box", m_rect, -1);
|
82
|
+
rb_define_method(jm_Module, "colour", m_color, -1);
|
83
|
+
rb_define_method(jm_Module, "composite", m_splice, -1);
|
84
|
+
rb_define_method(jm_Module, "set_pixel", m_pixel, -1);
|
85
|
+
rb_define_method(jm_Module, "[]", m_getpixel, 2);
|
86
|
+
/** end of aliases **/
|
87
|
+
|
88
|
+
/** associated with gen_eval **/
|
89
|
+
rb_define_method(rb_cObject, "gen_eval", rb_gen_eval, -1);
|
90
|
+
rb_define_method(rb_cObject, "capture", rb_capture, 0);
|
91
|
+
|
92
|
+
rb_define_method(rb_cObject, "to_module", rb_to_module , 0);
|
93
|
+
rb_define_method(rb_cObject, "reset_tbls", rb_reset_tbls , 0);
|
94
|
+
rb_define_method(rb_cObject, "gen_extend", rb_gen_extend, -1);
|
95
|
+
rb_define_method(rb_cModule, "gen_include", rb_gen_include, -1);
|
96
|
+
|
97
|
+
rb_define_alias(rb_cObject, "gen_eval_with", "gen_eval");
|
98
|
+
/** end of gen_eval defs **/
|
99
|
+
|
100
|
+
|
101
|
+
/** basic setup **/
|
102
|
+
|
103
|
+
/* seed the random number generator */
|
104
|
+
srand(time(NULL));
|
105
|
+
|
106
|
+
/** end basic setup **/
|
107
|
+
}
|
108
|
+
|
109
|
+
/** constructor for TPPoint class **/
|
110
|
+
static VALUE
|
111
|
+
m_init_TPPoint(int argc, VALUE * argv, VALUE self)
|
112
|
+
{
|
113
|
+
if(argc == 0) {
|
114
|
+
rb_iv_set(self, "@x", INT2FIX(0));
|
115
|
+
rb_iv_set(self, "@y", INT2FIX(0));
|
116
|
+
}
|
117
|
+
else if(argc == 2){
|
118
|
+
if(is_a_num(argv[0]) && is_a_num(argv[1])) {
|
119
|
+
rb_iv_set(self, "@x", argv[0]);
|
120
|
+
rb_iv_set(self, "@y", argv[1]);
|
121
|
+
}
|
122
|
+
else
|
123
|
+
rb_raise(rb_eArgError, "must provide two numbers");
|
124
|
+
}
|
125
|
+
else
|
126
|
+
rb_raise(rb_eArgError, "please provide x and y args only");
|
127
|
+
|
128
|
+
return Qnil;
|
129
|
+
|
130
|
+
}
|
131
|
+
/** end constructor for TPPoint **/
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
@@ -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
|