open_image 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+
2
+ #ifndef RB_OPEN_IMAGE_IMAGE_H
3
+ #define RB_OPEN_IMAGE_IMAGE_H 1
4
+
5
+ #include "common.h"
6
+
7
+ void Init_open_image_image(VALUE module);
8
+ static inline void open_image_free(void *data);
9
+ VALUE open_image_alloc(VALUE klass);
10
+ VALUE open_image_initialize(int argc, VALUE *argv, VALUE self);
11
+ VALUE open_image_dispose(VALUE self);
12
+ VALUE open_image_disposed_p(VALUE self);
13
+
14
+ VALUE open_image_width(VALUE self);
15
+ VALUE open_image_height(VALUE self);
16
+ VALUE open_image_pixels(VALUE self);
17
+ VALUE open_image_ptr(VALUE self);
18
+
19
+ VALUE open_image_save_png(VALUE self, VALUE path);
20
+ VALUE open_image_save_jpg(int argc, VALUE *argv, VALUE self);
21
+ VALUE open_image_save_tga(VALUE self, VALUE path);
22
+ VALUE open_image_save_bmp(VALUE self, VALUE path);
23
+
24
+ VALUE open_image_get_pixel(int argc, VALUE *argv, VALUE self);
25
+ VALUE open_image_set_pixel(int argc, VALUE *argv, VALUE self);
26
+ VALUE open_image_fill_rect(int argc, VALUE *argv, VALUE self);
27
+ VALUE open_image_subimage(int argc, VALUE *argv, VALUE self);
28
+
29
+ VALUE open_image_split(VALUE self, VALUE rows, VALUE columns);
30
+
31
+ VALUE open_image_size(VALUE self);
32
+ VALUE open_image_rect(VALUE self);
33
+ VALUE open_image_to_s(VALUE self);
34
+ VALUE open_image_dup(VALUE self);
35
+
36
+ #endif /* RB_OPEN_IMAGE_IMAGE_H */
@@ -0,0 +1,16 @@
1
+ #include "open_image.h"
2
+
3
+ VALUE rb_mOpenImage;
4
+ VALUE rb_cOpenImage;
5
+ VALUE rb_eOpenImageError;
6
+
7
+ void Init_open_image(void) {
8
+ rb_mOpenImage = rb_define_module("OpenImage");
9
+ rb_eOpenImageError = rb_define_class_under(rb_mOpenImage, "Error", rb_eStandardError);
10
+
11
+ Init_open_image_point(rb_mOpenImage);
12
+ Init_open_image_size(rb_mOpenImage);
13
+ Init_open_image_rect(rb_mOpenImage);
14
+ Init_open_image_color(rb_mOpenImage);
15
+ Init_open_image_image(rb_mOpenImage);
16
+ }
@@ -0,0 +1,10 @@
1
+ #ifndef RB_OPEN_IMAGE_H
2
+ #define RB_OPEN_IMAGE_H 1
3
+
4
+ #include "image.h"
5
+ #include "point.h"
6
+ #include "size.h"
7
+ #include "rect.h"
8
+ #include "color.h"
9
+
10
+ #endif /* RB_OPEN_IMAGE_H */
@@ -0,0 +1,96 @@
1
+
2
+ #include "point.h"
3
+
4
+ VALUE rb_cOpenImagePoint;
5
+
6
+ void Init_open_image_point(VALUE module) {
7
+ rb_cOpenImagePoint = rb_define_class_under(module, "Point", rb_cObject);
8
+
9
+ rb_define_method(rb_cOpenImagePoint, "x", open_image_point_get_x, 0);
10
+ rb_define_method(rb_cOpenImagePoint, "y", open_image_point_get_y, 0);
11
+ rb_define_method(rb_cOpenImagePoint, "x=", open_image_point_set_x, 1);
12
+ rb_define_method(rb_cOpenImagePoint, "y=", open_image_point_set_y, 1);
13
+
14
+ rb_define_method(rb_cOpenImagePoint, "to_a", open_image_point_to_a, 0);
15
+ rb_define_method(rb_cOpenImagePoint, "to_h", open_image_point_to_h, 0);
16
+ rb_define_method(rb_cOpenImagePoint, "to_s", open_image_point_to_s, 0);
17
+ rb_define_alias(rb_cOpenImagePoint, "to_str", "to_s");
18
+ rb_define_method(rb_cOpenImagePoint, "dup", open_image_point_dup, 0);
19
+ }
20
+
21
+ VALUE open_image_point_alloc(VALUE klass) {
22
+ Point *point = ALLOC(Point);
23
+ memset(point, 0, sizeof(Point));
24
+ RETURN_WRAP_STRUCT(klass, point);
25
+ }
26
+
27
+ VALUE open_image_point_initialize(int argc, VALUE *argv, VALUE self) {
28
+ POINT();
29
+ switch (argc) {
30
+ case 0:
31
+ break;
32
+ case 1: {
33
+ Size *size;
34
+ Data_Get_Struct(argv[0], Size, size);
35
+ point->x = size->width;
36
+ point->y = size->height;
37
+ }
38
+ case 2: {
39
+ point->x = NUM2INT(argv[0]);
40
+ point->y = NUM2INT(argv[1]);
41
+ }
42
+ default:
43
+ rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0, 1, 2)", argc);
44
+ }
45
+ return Qnil;
46
+ }
47
+
48
+ VALUE open_image_point_get_x(VALUE self) {
49
+ POINT();
50
+ return INT2NUM(point->x);
51
+ }
52
+
53
+ VALUE open_image_point_get_y(VALUE self) {
54
+ POINT();
55
+ return INT2NUM(point->y);
56
+ }
57
+
58
+ VALUE open_image_point_set_x(VALUE self, VALUE value) {
59
+ POINT();
60
+ point->x = NUM2INT(value);
61
+ return value;
62
+ }
63
+
64
+ VALUE open_image_point_set_y(VALUE self, VALUE value) {
65
+ POINT();
66
+ point->y = NUM2INT(value);
67
+ return value;
68
+ }
69
+
70
+ VALUE open_image_point_to_a(VALUE self) {
71
+ POINT();
72
+ VALUE ary = rb_ary_new_capa(2);
73
+ rb_ary_store(ary, 0, INT2NUM(point->x));
74
+ rb_ary_store(ary, 1, INT2NUM(point->y));
75
+ return ary;
76
+ }
77
+
78
+ VALUE open_image_point_to_h(VALUE self) {
79
+ POINT();
80
+ VALUE hash = rb_hash_new();
81
+ rb_hash_aset(hash, STR2SYM("x"), INT2NUM(point->x));
82
+ rb_hash_aset(hash, STR2SYM("y"), INT2NUM(point->y));
83
+ return hash;
84
+ }
85
+
86
+ VALUE open_image_point_to_s(VALUE self) {
87
+ POINT();
88
+ return rb_sprintf("<Point: x:%d, y:%d>", point->x, point->y);
89
+ }
90
+
91
+ VALUE open_image_point_dup(VALUE self) {
92
+ struct RData *rdata = RDATA(self);
93
+ Point *clone = ALLOC(Point);
94
+ memcpy(clone, rdata->data, sizeof(Point));
95
+ RETURN_WRAP_STRUCT(rdata->basic.klass, clone);
96
+ }
@@ -0,0 +1,24 @@
1
+ #ifndef OPEN_IMAGE_POINT_H
2
+ #define OPEN_IMAGE_POINT_H 1
3
+
4
+ #include "common.h"
5
+
6
+ #define POINT() \
7
+ Point *point; \
8
+ Data_Get_Struct(self, Point, point)
9
+
10
+ void Init_open_image_point(VALUE module);
11
+ VALUE open_image_point_alloc(VALUE klass);
12
+ VALUE open_image_point_initialize(int argc, VALUE *argv, VALUE self);
13
+
14
+ VALUE open_image_point_get_x(VALUE self);
15
+ VALUE open_image_point_get_y(VALUE self);
16
+ VALUE open_image_point_set_x(VALUE self, VALUE value);
17
+ VALUE open_image_point_set_y(VALUE self, VALUE value);
18
+
19
+ VALUE open_image_point_to_a(VALUE self);
20
+ VALUE open_image_point_to_h(VALUE self);
21
+ VALUE open_image_point_to_s(VALUE self);
22
+ VALUE open_image_point_dup(VALUE self);
23
+
24
+ #endif /* OPEN_IMAGE_POINT_H */
@@ -0,0 +1,192 @@
1
+
2
+ #include "rect.h"
3
+
4
+ VALUE rb_cOpenImageRect;
5
+
6
+ #define RECT() \
7
+ Rect *rect; \
8
+ Data_Get_Struct(self, Rect, rect)
9
+
10
+ void Init_open_image_rect(VALUE module) {
11
+ rb_cOpenImageRect = rb_define_class_under(module, "Rect", rb_cObject);
12
+
13
+ rb_define_method(rb_cOpenImageRect, "x", open_image_rect_get_x, 0);
14
+ rb_define_method(rb_cOpenImageRect, "y", open_image_rect_get_y, 0);
15
+ rb_define_method(rb_cOpenImageRect, "width", open_image_rect_get_width, 0);
16
+ rb_define_method(rb_cOpenImageRect, "height", open_image_rect_get_height, 0);
17
+ rb_define_method(rb_cOpenImageRect, "x=", open_image_rect_set_x, 1);
18
+ rb_define_method(rb_cOpenImageRect, "y=", open_image_rect_set_y, 1);
19
+ rb_define_method(rb_cOpenImageRect, "width=", open_image_rect_set_width, 1);
20
+ rb_define_method(rb_cOpenImageRect, "height=", open_image_rect_set_height, 1);
21
+
22
+ rb_define_method(rb_cOpenImageRect, "location", open_image_rect_get_location, 0);
23
+ rb_define_method(rb_cOpenImageRect, "size", open_image_rect_get_size, 0);
24
+ rb_define_method(rb_cOpenImageRect, "location=", open_image_rect_set_location, 1);
25
+ rb_define_method(rb_cOpenImageRect, "size=", open_image_rect_set_size, 1);
26
+
27
+ rb_define_method(rb_cOpenImageRect, "to_a", open_image_rect_to_a, 0);
28
+ rb_define_method(rb_cOpenImageRect, "to_h", open_image_rect_to_h, 0);
29
+ rb_define_method(rb_cOpenImageRect, "to_s", open_image_rect_to_s, 0);
30
+ rb_define_alias(rb_cOpenImageRect, "to_str", "to_s");
31
+ rb_define_method(rb_cOpenImageRect, "dup", open_image_rect_dup, 0);
32
+ }
33
+
34
+ VALUE open_image_rect_alloc(VALUE klass) {
35
+ Rect *rect = ALLOC(Rect);
36
+ memset(rect, 0, sizeof(Rect));
37
+ RETURN_WRAP_STRUCT(klass, rect);
38
+ }
39
+
40
+ VALUE open_image_rect_initialize(int argc, VALUE *argv, VALUE self) {
41
+ RECT();
42
+ switch (argc) {
43
+ case 0:
44
+ break;
45
+ case 2: {
46
+ Point *point;
47
+ Size *size;
48
+ Data_Get_Struct(argv[0], Point, point);
49
+ Data_Get_Struct(argv[1], Size, size);
50
+ rect->x = point->x;
51
+ rect->y = point->y;
52
+ rect->width = size->width;
53
+ rect->height = size->height;
54
+ }
55
+ case 3: {
56
+ if (FIXNUM_P(argv[0])) {
57
+ Size *s;
58
+ Data_Get_Struct(argv[2], Size, s);
59
+ rect->x = NUM2INT(argv[0]);
60
+ rect->y = NUM2INT(argv[1]);
61
+ rect->width = s->width;
62
+ rect->height = s->height;
63
+ } else {
64
+ Point *p;
65
+ Data_Get_Struct(argv[0], Point, p);
66
+ rect->x = p->x;
67
+ rect->y = p->y;
68
+ rect->width = NUM2INT(argv[1]);
69
+ rect->height = NUM2INT(argv[2]);
70
+ }
71
+ }
72
+ case 4: {
73
+ rect->x = NUM2INT(argv[0]);
74
+ rect->y = NUM2INT(argv[1]);
75
+ rect->width = NUM2INT(argv[2]);
76
+ rect->height = NUM2INT(argv[3]);
77
+ }
78
+ default:
79
+ rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0, 2, 3, 4)", argc);
80
+ }
81
+ return Qnil;
82
+ }
83
+
84
+ VALUE open_image_rect_get_x(VALUE self) {
85
+ RECT();
86
+ return INT2NUM(rect->x);
87
+ }
88
+
89
+ VALUE open_image_rect_get_y(VALUE self) {
90
+ RECT();
91
+ return INT2NUM(rect->y);
92
+ }
93
+
94
+ VALUE open_image_rect_get_width(VALUE self) {
95
+ RECT();
96
+ return INT2NUM(rect->width);
97
+ }
98
+
99
+ VALUE open_image_rect_get_height(VALUE self) {
100
+ RECT();
101
+ return INT2NUM(rect->height);
102
+ }
103
+
104
+ VALUE open_image_rect_set_x(VALUE self, VALUE value) {
105
+ RECT();
106
+ rect->x = NUM2INT(value);
107
+ return value;
108
+ }
109
+
110
+ VALUE open_image_rect_set_y(VALUE self, VALUE value) {
111
+ RECT();
112
+ rect->y = NUM2INT(value);
113
+ return value;
114
+ }
115
+
116
+ VALUE open_image_rect_set_width(VALUE self, VALUE value) {
117
+ RECT();
118
+ rect->width = NUM2INT(value);
119
+ return value;
120
+ }
121
+
122
+ VALUE open_image_rect_set_height(VALUE self, VALUE value) {
123
+ RECT();
124
+ rect->height = NUM2INT(value);
125
+ return value;
126
+ }
127
+
128
+ VALUE open_image_rect_get_location(VALUE self) {
129
+ RECT();
130
+ Point *point = ALLOC(Point);
131
+ point->x = rect->x;
132
+ point->y = rect->y;
133
+ RETURN_WRAP_STRUCT(rb_cOpenImagePoint, point);
134
+ }
135
+
136
+ VALUE open_image_rect_get_size(VALUE self) {
137
+ RECT();
138
+ Size *size = ALLOC(Size);
139
+ size->width = rect->width;
140
+ size->height = rect->height;
141
+ RETURN_WRAP_STRUCT(rb_cOpenImageSize, size);
142
+ }
143
+
144
+ VALUE open_image_rect_set_location(VALUE self, VALUE value) {
145
+ RECT();
146
+ Point *point;
147
+ Data_Get_Struct(value, Point, point);
148
+ rect->x = point->x;
149
+ rect->y = point->y;
150
+ return value;
151
+ }
152
+
153
+ VALUE open_image_rect_set_size(VALUE self, VALUE value) {
154
+ RECT();
155
+ Size *size;
156
+ Data_Get_Struct(value, Size, size);
157
+ rect->width = size->width;
158
+ rect->height = size->height;
159
+ return value;
160
+ }
161
+
162
+ VALUE open_image_rect_to_a(VALUE self) {
163
+ RECT();
164
+ VALUE ary = rb_ary_new_capa(4);
165
+ rb_ary_store(ary, 0, INT2NUM(rect->x));
166
+ rb_ary_store(ary, 1, INT2NUM(rect->y));
167
+ rb_ary_store(ary, 2, INT2NUM(rect->width));
168
+ rb_ary_store(ary, 3, INT2NUM(rect->height));
169
+ return ary;
170
+ }
171
+
172
+ VALUE open_image_rect_to_h(VALUE self) {
173
+ RECT();
174
+ VALUE hash = rb_hash_new();
175
+ rb_hash_aset(hash, STR2SYM("x"), INT2NUM(rect->x));
176
+ rb_hash_aset(hash, STR2SYM("y"), INT2NUM(rect->y));
177
+ rb_hash_aset(hash, STR2SYM("width"), INT2NUM(rect->width));
178
+ rb_hash_aset(hash, STR2SYM("height"), INT2NUM(rect->height));
179
+ return hash;
180
+ }
181
+
182
+ VALUE open_image_rect_to_s(VALUE self) {
183
+ RECT();
184
+ return rb_sprintf("<Rect: x:%d, y:%d, width:%d, height:%d>", rect->x, rect->y, rect->width, rect->height);
185
+ }
186
+
187
+ VALUE open_image_rect_dup(VALUE self) {
188
+ struct RData *rdata = RDATA(self);
189
+ Rect *clone = ALLOC(Rect);
190
+ memcpy(clone, rdata->data, sizeof(Rect));
191
+ RETURN_WRAP_STRUCT(rdata->basic.klass, clone);
192
+ }
@@ -0,0 +1,29 @@
1
+ #ifndef OPEN_IMAGE_RECT_H
2
+ #define OPEN_IMAGE_RECT_H 1
3
+
4
+ #include "common.h"
5
+
6
+ void Init_open_image_rect(VALUE module);
7
+ VALUE open_image_rect_alloc(VALUE klass);
8
+ VALUE open_image_rect_initialize(int argc, VALUE *argv, VALUE self);
9
+
10
+ VALUE open_image_rect_get_x(VALUE self);
11
+ VALUE open_image_rect_get_y(VALUE self);
12
+ VALUE open_image_rect_get_width(VALUE self);
13
+ VALUE open_image_rect_get_height(VALUE self);
14
+ VALUE open_image_rect_set_x(VALUE self, VALUE value);
15
+ VALUE open_image_rect_set_y(VALUE self, VALUE value);
16
+ VALUE open_image_rect_set_width(VALUE self, VALUE value);
17
+ VALUE open_image_rect_set_height(VALUE self, VALUE value);
18
+
19
+ VALUE open_image_rect_get_location(VALUE self);
20
+ VALUE open_image_rect_get_size(VALUE self);
21
+ VALUE open_image_rect_set_location(VALUE self, VALUE value);
22
+ VALUE open_image_rect_set_size(VALUE self, VALUE value);
23
+
24
+ VALUE open_image_rect_to_a(VALUE self);
25
+ VALUE open_image_rect_to_h(VALUE self);
26
+ VALUE open_image_rect_to_s(VALUE self);
27
+ VALUE open_image_rect_dup(VALUE self);
28
+
29
+ #endif /* OPEN_IMAGE_RECT_H */
@@ -0,0 +1,100 @@
1
+
2
+ #include "size.h"
3
+
4
+ VALUE rb_cOpenImageSize;
5
+
6
+ #define SIZE() \
7
+ Size *size; \
8
+ Data_Get_Struct(self, Size, size)
9
+
10
+ void Init_open_image_size(VALUE module) {
11
+ rb_cOpenImageSize = rb_define_class_under(module, "Size", rb_cObject);
12
+
13
+ rb_define_method(rb_cOpenImageSize, "width", open_image_size_get_width, 0);
14
+ rb_define_method(rb_cOpenImageSize, "height", open_image_size_get_height, 0);
15
+ rb_define_method(rb_cOpenImageSize, "width=", open_image_size_set_width, 1);
16
+ rb_define_method(rb_cOpenImageSize, "height=", open_image_size_set_height, 1);
17
+
18
+ rb_define_method(rb_cOpenImageSize, "to_a", open_image_size_to_a, 0);
19
+ rb_define_method(rb_cOpenImageSize, "to_h", open_image_size_to_h, 0);
20
+ rb_define_method(rb_cOpenImageSize, "to_s", open_image_size_to_s, 0);
21
+ rb_define_alias(rb_cOpenImageSize, "to_str", "to_s");
22
+ rb_define_method(rb_cOpenImageSize, "dup", open_image_size_dup, 0);
23
+ }
24
+
25
+ VALUE open_image_size_alloc(VALUE klass) {
26
+ Size *size = ALLOC(Size);
27
+ memset(size, 0, sizeof(Size));
28
+ RETURN_WRAP_STRUCT(klass, size);
29
+ }
30
+
31
+ VALUE open_image_size_initialize(int argc, VALUE *argv, VALUE self) {
32
+ SIZE();
33
+ switch (argc) {
34
+ case 0:
35
+ break;
36
+ case 1: {
37
+ Point *point;
38
+ Data_Get_Struct(argv[0], Point, point);
39
+ size->width = point->x;
40
+ size->height = point->y;
41
+ }
42
+ case 2: {
43
+ size->width = NUM2INT(argv[0]);
44
+ size->height = NUM2INT(argv[1]);
45
+ }
46
+ default:
47
+ rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0, 1, 2)", argc);
48
+ }
49
+ return Qnil;
50
+ }
51
+
52
+ VALUE open_image_size_get_width(VALUE self) {
53
+ SIZE();
54
+ return INT2NUM(size->width);
55
+ }
56
+
57
+ VALUE open_image_size_get_height(VALUE self) {
58
+ SIZE();
59
+ return INT2NUM(size->height);
60
+ }
61
+
62
+ VALUE open_image_size_set_width(VALUE self, VALUE value) {
63
+ SIZE();
64
+ size->width = NUM2INT(value);
65
+ return value;
66
+ }
67
+
68
+ VALUE open_image_size_set_height(VALUE self, VALUE value) {
69
+ SIZE();
70
+ size->height = NUM2INT(value);
71
+ return value;
72
+ }
73
+
74
+ VALUE open_image_size_to_a(VALUE self) {
75
+ SIZE();
76
+ VALUE ary = rb_ary_new_capa(2);
77
+ rb_ary_store(ary, 0, INT2NUM(size->width));
78
+ rb_ary_store(ary, 1, INT2NUM(size->height));
79
+ return ary;
80
+ }
81
+
82
+ VALUE open_image_size_to_h(VALUE self) {
83
+ SIZE();
84
+ VALUE hash = rb_hash_new();
85
+ rb_hash_aset(hash, STR2SYM("width"), INT2NUM(size->width));
86
+ rb_hash_aset(hash, STR2SYM("height"), INT2NUM(size->height));
87
+ return hash;
88
+ }
89
+
90
+ VALUE open_image_size_to_s(VALUE self) {
91
+ SIZE();
92
+ return rb_sprintf("<Size: width:%d, height:%d>", size->width, size->height);
93
+ }
94
+
95
+ VALUE open_image_size_dup(VALUE self) {
96
+ struct RData *rdata = RDATA(self);
97
+ Size *clone = ALLOC(Size);
98
+ memcpy(clone, rdata->data, sizeof(Size));
99
+ RETURN_WRAP_STRUCT(rdata->basic.klass, clone);
100
+ }