ruby-libgd 0.1.0

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.
data/ext/gd/encode.c ADDED
@@ -0,0 +1,66 @@
1
+ #include "ruby_gd.h"
2
+
3
+ /**
4
+ - [ ] imagegif — Output image to browser or file
5
+ - [x] imagewbmp — Output image to browser or file
6
+ - [x] imagewebp — Output a WebP image to browser or file
7
+ - [ ] imagexbm — Output an XBM image to browser or file
8
+ - [x] imagepng — Output a PNG image to either the browser or a file
9
+ - [x] imagejpeg — Output image to browser or file
10
+ - [ ] imagegd — Output GD image to browser or file
11
+ - [ ] imagegd2 — Output GD2 image to browser or file
12
+ - [ ] imageavif — Output image to browser or file
13
+ - [ ] imagebmp — Output a BMP image to browser or file
14
+ **/
15
+ static VALUE gd_image_save(int argc, VALUE *argv, VALUE self) {
16
+ VALUE path, opts;
17
+ rb_scan_args(argc, argv, "11", &path, &opts);
18
+
19
+ gd_image_wrapper *wrap;
20
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
21
+
22
+ const char *filename = StringValueCStr(path);
23
+
24
+ const char *ext = strrchr(filename, '.');
25
+ if (!ext) rb_raise(rb_eArgError, "file extension required");
26
+
27
+ FILE *f = fopen(filename, "wb");
28
+ if (!f) rb_sys_fail(filename);
29
+
30
+ if (strcmp(ext, ".png") == 0) {
31
+ gdImagePng(wrap->img, f);
32
+ } else if (strcmp(ext, ".jpg") == 0 || strcmp(ext, ".jpeg") == 0) {
33
+ int quality = 90;
34
+ if (opts != Qnil) {
35
+ VALUE q = rb_hash_aref(opts, ID2SYM(rb_intern("quality")));
36
+ if (!NIL_P(q)) quality = NUM2INT(q);
37
+ }
38
+ gdImageJpeg(wrap->img, f, quality);
39
+ } else if (strcmp(ext, ".webp") == 0) {
40
+ gdImageWebp(wrap->img, f);
41
+ } else {
42
+ fclose(f);
43
+ rb_raise(rb_eArgError, "unsupported format");
44
+ }
45
+
46
+ fclose(f);
47
+ return Qtrue;
48
+ }
49
+
50
+ static VALUE gd_image_to_png(VALUE self) {
51
+ gd_image_wrapper *wrap;
52
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
53
+
54
+ int size = 0;
55
+ void *data = gdImagePngPtr(wrap->img, &size);
56
+ if (!data) rb_raise(rb_eRuntimeError, "PNG encode failed");
57
+
58
+ VALUE str = rb_str_new((const char*)data, size);
59
+ gdFree(data);
60
+ return str;
61
+ }
62
+
63
+ void gd_define_encode(VALUE cGDImage) {
64
+ rb_define_method(cGDImage, "save", gd_image_save, -1);
65
+ rb_define_method(cGDImage, "to_png", gd_image_to_png, 0);
66
+ }
data/ext/gd/encode.o ADDED
Binary file
data/ext/gd/extconf.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'mkmf'
2
+
3
+ abort "libgd not found" unless have_library("gd")
4
+ have_library("m")
5
+ create_makefile("gd/gd")
data/ext/gd/fill.c ADDED
@@ -0,0 +1,24 @@
1
+ #include "ruby_gd.h"
2
+
3
+ /**
4
+ - [x] imagefill — Flood fill
5
+ */
6
+ static VALUE gd_image_fill(VALUE self, VALUE color) {
7
+ gd_image_wrapper *wrap;
8
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
9
+
10
+ if (!wrap || !wrap->img)
11
+ rb_raise(rb_eRuntimeError, "uninitialized GD::Image");
12
+
13
+ int r = NUM2INT(rb_ary_entry(color,0));
14
+ int g = NUM2INT(rb_ary_entry(color,1));
15
+ int b = NUM2INT(rb_ary_entry(color,2));
16
+ int c = gdImageColorAllocate(wrap->img,r,g,b);
17
+
18
+ gdImageFilledRectangle(wrap->img,0,0,wrap->img->sx,wrap->img->sy,c);
19
+ return Qnil;
20
+ }
21
+
22
+ void gd_define_fill(VALUE cGDImage) {
23
+ rb_define_method(cGDImage,"fill",gd_image_fill,1);
24
+ }
data/ext/gd/fill.o ADDED
Binary file
data/ext/gd/filter.c ADDED
@@ -0,0 +1,70 @@
1
+ #include "ruby_gd.h"
2
+ #include <string.h>
3
+
4
+ static VALUE gd_image_filter(int argc, VALUE *argv, VALUE self) {
5
+ VALUE type, arg1, arg2, arg3, arg4;
6
+ rb_scan_args(argc, argv, "14", &type, &arg1, &arg2, &arg3, &arg4);
7
+
8
+ gd_image_wrapper *wrap;
9
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
10
+
11
+ type = rb_obj_as_string(type);
12
+ const char *name = StringValueCStr(type);
13
+
14
+ if (strcmp(name, "negate") == 0) {
15
+ gdImageNegate(wrap->img);
16
+ }
17
+ else if (strcmp(name, "grayscale") == 0) {
18
+ gdImageGrayScale(wrap->img);
19
+ }
20
+ else if (strcmp(name, "brightness") == 0) {
21
+ gdImageBrightness(wrap->img, NUM2INT(arg1));
22
+ }
23
+ else if (strcmp(name, "contrast") == 0) {
24
+ gdImageContrast(wrap->img, NUM2INT(arg1));
25
+ }
26
+ else if (strcmp(name, "colorize") == 0) {
27
+ rb_raise(rb_eNotImpError, "colorize not supported by libgd");
28
+ }
29
+ else if (strcmp(name, "edge_detect") == 0) {
30
+ gdImageEdgeDetectQuick(wrap->img);
31
+ }
32
+ else if (strcmp(name, "emboss") == 0) {
33
+ gdImageEmboss(wrap->img);
34
+ }
35
+ else if (strcmp(name, "gaussian_blur") == 0) {
36
+ gdImageGaussianBlur(wrap->img);
37
+ }
38
+ else if (strcmp(name, "selective_blur") == 0) {
39
+ gdImageSelectiveBlur(wrap->img);
40
+ }
41
+ else if (strcmp(name, "mean_removal") == 0) {
42
+ gdImageMeanRemoval(wrap->img);
43
+ }
44
+ else if (strcmp(name, "smooth") == 0) {
45
+ gdImageSmooth(wrap->img, NUM2INT(arg1));
46
+ }
47
+ else if (strcmp(name, "pixelate") == 0) {
48
+ gdImagePixelate(
49
+ wrap->img,
50
+ NUM2INT(arg1),
51
+ RTEST(arg2)
52
+ );
53
+ }
54
+ else if (strcmp(name, "scatter") == 0) {
55
+ gdImageScatter(
56
+ wrap->img,
57
+ NUM2INT(arg1),
58
+ NUM2INT(arg2)
59
+ );
60
+ }
61
+ else {
62
+ rb_raise(rb_eArgError, "unknown filter");
63
+ }
64
+
65
+ return self;
66
+ }
67
+
68
+ void gd_define_filter(VALUE cGDImage) {
69
+ rb_define_method(cGDImage, "filter", gd_image_filter, -1);
70
+ }
data/ext/gd/filter.o ADDED
Binary file
data/ext/gd/gd.c ADDED
@@ -0,0 +1,87 @@
1
+ #include "ruby_gd.h"
2
+
3
+ static VALUE mGD;
4
+ static VALUE cGDImage;
5
+
6
+ static VALUE gd_info(VALUE self) {
7
+ return rb_str_new_cstr(gdVersionString());
8
+ }
9
+
10
+ static VALUE gd_types(VALUE self) {
11
+ VALUE h = rb_hash_new();
12
+
13
+ rb_hash_aset(h, ID2SYM(rb_intern("png")),
14
+ gdSupportsFileType("test.png", 1) ? Qtrue : Qfalse);
15
+
16
+ rb_hash_aset(h, ID2SYM(rb_intern("jpeg")),
17
+ gdSupportsFileType("test.jpg", 1) ? Qtrue : Qfalse);
18
+
19
+ rb_hash_aset(h, ID2SYM(rb_intern("gif")),
20
+ gdSupportsFileType("test.gif", 1) ? Qtrue : Qfalse);
21
+
22
+ rb_hash_aset(h, ID2SYM(rb_intern("webp")),
23
+ gdSupportsFileType("test.webp", 1) ? Qtrue : Qfalse);
24
+
25
+ rb_hash_aset(h, ID2SYM(rb_intern("bmp")),
26
+ gdSupportsFileType("test.bmp", 1) ? Qtrue : Qfalse);
27
+
28
+ return h;
29
+ }
30
+
31
+ static VALUE gd_mime_for(VALUE self, VALUE sym) {
32
+ const char *t = rb_id2name(SYM2ID(sym));
33
+
34
+ if (!strcmp(t,"png")) return rb_str_new_cstr("image/png");
35
+ if (!strcmp(t,"jpeg")) return rb_str_new_cstr("image/jpeg");
36
+ if (!strcmp(t,"jpg")) return rb_str_new_cstr("image/jpeg");
37
+ if (!strcmp(t,"gif")) return rb_str_new_cstr("image/gif");
38
+ if (!strcmp(t,"webp")) return rb_str_new_cstr("image/webp");
39
+ if (!strcmp(t,"bmp")) return rb_str_new_cstr("image/bmp");
40
+
41
+ return Qnil;
42
+ }
43
+
44
+ static VALUE gd_ext_for(VALUE self, VALUE sym) {
45
+ const char *t = rb_id2name(SYM2ID(sym));
46
+
47
+ if (!strcmp(t,"png")) return rb_str_new_cstr(".png");
48
+ if (!strcmp(t,"jpeg")) return rb_str_new_cstr(".jpg");
49
+ if (!strcmp(t,"jpg")) return rb_str_new_cstr(".jpg");
50
+ if (!strcmp(t,"gif")) return rb_str_new_cstr(".gif");
51
+ if (!strcmp(t,"webp")) return rb_str_new_cstr(".webp");
52
+ if (!strcmp(t,"bmp")) return rb_str_new_cstr(".bmp");
53
+
54
+ return Qnil;
55
+ }
56
+
57
+ void Init_gd(void) {
58
+ mGD = rb_define_module("GD");
59
+
60
+ rb_define_singleton_method(mGD, "info", gd_info, 0);
61
+ rb_define_singleton_method(mGD, "types", gd_types, 0);
62
+ rb_define_singleton_method(mGD, "mime_for", gd_mime_for, 1);
63
+ rb_define_singleton_method(mGD, "ext_for", gd_ext_for, 1);
64
+
65
+ gd_define_image(mGD);
66
+
67
+ cGDImage = rb_path2class("GD::Image");
68
+
69
+ gd_define_blit(cGDImage);
70
+ gd_define_fill(cGDImage);
71
+
72
+ gd_define_pixel(cGDImage);
73
+ gd_define_line(cGDImage);
74
+ gd_define_arc(cGDImage);
75
+ gd_define_rect(cGDImage);
76
+ gd_define_circle(cGDImage);
77
+ gd_define_polygon(cGDImage);
78
+
79
+ gd_define_text(cGDImage);
80
+
81
+ gd_define_filter(cGDImage);
82
+ gd_define_transform(cGDImage);
83
+ gd_define_encode(cGDImage);
84
+
85
+ gd_define_color(mGD);
86
+ gd_define_version(mGD);
87
+ }
data/ext/gd/gd.o ADDED
Binary file
data/ext/gd/gd.so ADDED
Binary file
data/ext/gd/image.c ADDED
@@ -0,0 +1,203 @@
1
+ #include "ruby_gd.h"
2
+
3
+ static VALUE gd_image_initialize(int argc, VALUE *argv, VALUE self) {
4
+ gd_image_wrapper *wrap;
5
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
6
+
7
+ wrap->img = NULL;
8
+
9
+ if (argc == 0) {
10
+ return self;
11
+ }
12
+ if (argc != 2) {
13
+ rb_raise(rb_eArgError, "expected 0 or 2 arguments");
14
+ }
15
+
16
+ int w = NUM2INT(argv[0]);
17
+ int h = NUM2INT(argv[1]);
18
+ if (w <= 0 || h <= 0)
19
+ rb_raise(rb_eArgError, "width and height must be positive");
20
+
21
+ wrap->img = gdImageCreateTrueColor(w, h);
22
+ if (!wrap->img)
23
+ rb_raise(rb_eRuntimeError, "gdImageCreateTrueColor failed");
24
+
25
+ return self;
26
+ }
27
+
28
+ static VALUE gd_image_initialize_empty(VALUE self) {
29
+ gd_image_wrapper *wrap;
30
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
31
+ wrap->img = NULL;
32
+ return self;
33
+ }
34
+
35
+ static VALUE gd_image_initialize_true_color(VALUE self, VALUE width, VALUE height) {
36
+ gd_image_wrapper *wrap;
37
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
38
+
39
+ if (wrap->img) {
40
+ gdImageDestroy(wrap->img);
41
+ }
42
+
43
+ int w = NUM2INT(width);
44
+ int h = NUM2INT(height);
45
+ if (w <= 0 || h <= 0) {
46
+ rb_raise(rb_eArgError, "width and height must be positive");
47
+ }
48
+
49
+ wrap->img = gdImageCreateTrueColor(w, h);
50
+ if (!wrap->img) {
51
+ rb_raise(rb_eRuntimeError, "failed to create true color image");
52
+ }
53
+
54
+ // Opcional: desactivar el fondo transparente si no lo necesitas
55
+ gdImageAlphaBlending(wrap->img, 1);
56
+ gdImageSaveAlpha(wrap->img, 0);
57
+
58
+ return self;
59
+ }
60
+
61
+ static VALUE gd_image_s_new_true_color(VALUE klass, VALUE width, VALUE height) {
62
+ VALUE obj = rb_class_new_instance(0, NULL, klass);
63
+ gd_image_initialize_true_color(obj, width, height);
64
+ return obj;
65
+ }
66
+
67
+ static VALUE gd_image_clone(VALUE self) {
68
+ gd_image_wrapper *wrap;
69
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
70
+
71
+ if (!wrap->img) rb_raise(rb_eRuntimeError, "cannot clone: image is NULL");
72
+
73
+ gdImagePtr copy = gdImageClone(wrap->img);
74
+ if (!copy) rb_raise(rb_eRuntimeError, "gdImageClone failed");
75
+
76
+ VALUE obj = rb_class_new_instance(0, NULL, CLASS_OF(self));
77
+ gd_image_wrapper *w2;
78
+ TypedData_Get_Struct(obj, gd_image_wrapper, &gd_image_type, w2);
79
+ w2->img = copy;
80
+
81
+ return obj;
82
+ }
83
+
84
+ static void gd_image_free(void *ptr) {
85
+ gd_image_wrapper *wrap = (gd_image_wrapper *)ptr;
86
+ if (!wrap) return;
87
+
88
+ if (wrap->img) {
89
+ gdImageDestroy(wrap->img);
90
+ wrap->img = NULL;
91
+ }
92
+ }
93
+
94
+ static size_t gd_image_memsize(const void *ptr) {
95
+ return ptr ? sizeof(gd_image_wrapper) : 0;
96
+ }
97
+
98
+ const rb_data_type_t gd_image_type = {
99
+ "GD::Image",
100
+ { 0, gd_image_free, gd_image_memsize, 0 }, // <-- dcompact agregado
101
+ 0, 0,
102
+ RUBY_TYPED_FREE_IMMEDIATELY
103
+ };
104
+
105
+ static VALUE gd_image_alloc(VALUE klass) {
106
+ gd_image_wrapper *wrap;
107
+ VALUE obj = TypedData_Make_Struct(klass, gd_image_wrapper, &gd_image_type, wrap);
108
+ wrap->img = NULL;
109
+ return obj;
110
+ }
111
+
112
+ static VALUE gd_image_new(VALUE klass, VALUE w, VALUE h) {
113
+ VALUE obj = rb_class_new_instance(0, NULL, klass);
114
+ gd_image_wrapper *wrap;
115
+ TypedData_Get_Struct(obj, gd_image_wrapper, &gd_image_type, wrap);
116
+
117
+ int width = NUM2INT(w);
118
+ int height = NUM2INT(h);
119
+ if (width <= 0 || height <= 0)
120
+ rb_raise(rb_eArgError, "width and height must be positive");
121
+
122
+ wrap->img = gdImageCreateTrueColor(width, height);
123
+ if (!wrap->img) rb_raise(rb_eRuntimeError, "gdImageCreateTrueColor failed");
124
+ return obj;
125
+ }
126
+
127
+ static VALUE gd_image_open(VALUE klass, VALUE path) {
128
+ const char *filename = StringValueCStr(path);
129
+
130
+ FILE *f = fopen(filename, "rb");
131
+ if (!f) rb_sys_fail(filename);
132
+
133
+ gdImagePtr img = NULL;
134
+
135
+ const char *ext = strrchr(filename, '.');
136
+ if (!ext) rb_raise(rb_eArgError, "unknown image type");
137
+
138
+ if (strcmp(ext, ".png") == 0) {
139
+ img = gdImageCreateFromPng(f);
140
+ } else if (strcmp(ext, ".jpg") == 0 || strcmp(ext, ".jpeg") == 0) {
141
+ img = gdImageCreateFromJpeg(f);
142
+ } else if (strcmp(ext, ".webp") == 0) {
143
+ img = gdImageCreateFromWebp(f);
144
+ } else if (strcmp(ext, ".gif") == 0) {
145
+ img = gdImageCreateFromGif(f);
146
+ } else {
147
+ fclose(f);
148
+ rb_raise(rb_eArgError, "unsupported format");
149
+ }
150
+
151
+ fclose(f);
152
+ if (!img) rb_raise(rb_eRuntimeError, "image decode failed");
153
+
154
+ VALUE obj = rb_class_new_instance(0, NULL, klass);
155
+ gd_image_wrapper *wrap;
156
+ TypedData_Get_Struct(obj, gd_image_wrapper, &gd_image_type, wrap);
157
+ wrap->img = img;
158
+
159
+ return obj;
160
+ }
161
+
162
+ static VALUE gd_image_alpha_blending(VALUE self, VALUE flag) {
163
+ gd_image_wrapper *wrap;
164
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
165
+
166
+ gdImageAlphaBlending(wrap->img, RTEST(flag));
167
+ return self;
168
+ }
169
+
170
+ static VALUE gd_image_save_alpha(VALUE self, VALUE flag) {
171
+ gd_image_wrapper *wrap;
172
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
173
+
174
+ gdImageSaveAlpha(wrap->img, RTEST(flag));
175
+ return self;
176
+ }
177
+
178
+ static VALUE gd_image_width(VALUE self) {
179
+ gd_image_wrapper *wrap;
180
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
181
+ return INT2NUM(gdImageSX(wrap->img));
182
+ }
183
+
184
+ static VALUE gd_image_height(VALUE self) {
185
+ gd_image_wrapper *wrap;
186
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
187
+ return INT2NUM(gdImageSY(wrap->img));
188
+ }
189
+
190
+ void gd_define_image(VALUE mGD) {
191
+ VALUE cGDImage = rb_define_class_under(mGD, "Image", rb_cObject);
192
+
193
+ rb_define_alloc_func(cGDImage, gd_image_alloc);
194
+
195
+ rb_define_method(cGDImage, "width", gd_image_width, 0);
196
+ rb_define_method(cGDImage, "height", gd_image_height, 0);
197
+ rb_define_method(cGDImage, "initialize", gd_image_initialize, -1);
198
+ rb_define_method(cGDImage, "clone", gd_image_clone, 0);
199
+ rb_define_singleton_method(cGDImage, "open", gd_image_open, 1);
200
+ rb_define_singleton_method(cGDImage, "new_true_color", gd_image_s_new_true_color, 2);
201
+ rb_define_method(cGDImage, "alpha_blending=", gd_image_alpha_blending, 1);
202
+ rb_define_method(cGDImage, "save_alpha=", gd_image_save_alpha, 1);
203
+ }
data/ext/gd/image.o ADDED
Binary file
data/ext/gd/join.sh ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ OUT="c_sources_dump.txt"
5
+
6
+ echo "Generating $OUT ..."
7
+ echo "======================" > "$OUT"
8
+ echo "Generated on $(date)" >> "$OUT"
9
+ echo "" >> "$OUT"
10
+
11
+ find . -name "*.c" -type f | sort | while read -r file; do
12
+ echo "----------------------------------------" >> "$OUT"
13
+ echo "FILE: $file" >> "$OUT"
14
+ echo "----------------------------------------" >> "$OUT"
15
+ echo "" >> "$OUT"
16
+
17
+ sed 's/\t/ /g' "$file" >> "$OUT"
18
+
19
+ echo "" >> "$OUT"
20
+ echo "" >> "$OUT"
21
+ done
22
+
23
+ echo "Done."
24
+ echo "Output written to: $OUT"
data/ext/gd/mkmf.log ADDED
@@ -0,0 +1,59 @@
1
+ have_library: checking for -lgd... -------------------- yes
2
+
3
+ LD_LIBRARY_PATH=.:/usr/local/lib "gcc -o conftest -I/usr/local/include/ruby-3.3.0/x86_64-linux -I/usr/local/include/ruby-3.3.0/ruby/backward -I/usr/local/include/ruby-3.3.0 -I. -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdiv-by-zero -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wold-style-definition -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wmisleading-indentation -Wundef -fPIC conftest.c -L. -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,--no-as-needed -Wl,-rpath,/usr/local/lib -L/usr/local/lib -lruby -lm -lpthread -lc"
4
+ checked program was:
5
+ /* begin */
6
+ 1: #include "ruby.h"
7
+ 2:
8
+ 3: int main(int argc, char **argv)
9
+ 4: {
10
+ 5: return !!argv[argc];
11
+ 6: }
12
+ /* end */
13
+
14
+ LD_LIBRARY_PATH=.:/usr/local/lib "gcc -o conftest -I/usr/local/include/ruby-3.3.0/x86_64-linux -I/usr/local/include/ruby-3.3.0/ruby/backward -I/usr/local/include/ruby-3.3.0 -I. -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdiv-by-zero -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wold-style-definition -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wmisleading-indentation -Wundef -fPIC conftest.c -L. -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,--no-as-needed -Wl,-rpath,/usr/local/lib -L/usr/local/lib -lruby -lgd -lm -lpthread -lc"
15
+ checked program was:
16
+ /* begin */
17
+ 1: #include "ruby.h"
18
+ 2:
19
+ 3: /*top*/
20
+ 4: extern int t(void);
21
+ 5: int main(int argc, char **argv)
22
+ 6: {
23
+ 7: if (argc > 1000000) {
24
+ 8: int (* volatile tp)(void)=(int (*)(void))&t;
25
+ 9: printf("%d", (*tp)());
26
+ 10: }
27
+ 11:
28
+ 12: return !!argv[argc];
29
+ 13: }
30
+ 14:
31
+ 15: int t(void) { ; return 0; }
32
+ /* end */
33
+
34
+ --------------------
35
+
36
+ have_library: checking for -lm... -------------------- yes
37
+
38
+ LD_LIBRARY_PATH=.:/usr/local/lib "gcc -o conftest -I/usr/local/include/ruby-3.3.0/x86_64-linux -I/usr/local/include/ruby-3.3.0/ruby/backward -I/usr/local/include/ruby-3.3.0 -I. -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdiv-by-zero -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wold-style-definition -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wmisleading-indentation -Wundef -fPIC conftest.c -L. -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,--no-as-needed -lgd -Wl,-rpath,/usr/local/lib -L/usr/local/lib -lruby -lm -lgd -lm -lpthread -lc"
39
+ checked program was:
40
+ /* begin */
41
+ 1: #include "ruby.h"
42
+ 2:
43
+ 3: /*top*/
44
+ 4: extern int t(void);
45
+ 5: int main(int argc, char **argv)
46
+ 6: {
47
+ 7: if (argc > 1000000) {
48
+ 8: int (* volatile tp)(void)=(int (*)(void))&t;
49
+ 9: printf("%d", (*tp)());
50
+ 10: }
51
+ 11:
52
+ 12: return !!argv[argc];
53
+ 13: }
54
+ 14:
55
+ 15: int t(void) { ; return 0; }
56
+ /* end */
57
+
58
+ --------------------
59
+
data/ext/gd/pixel.c ADDED
@@ -0,0 +1,39 @@
1
+ #include "ruby_gd.h"
2
+
3
+ static VALUE gd_image_set_pixel(VALUE self, VALUE x, VALUE y, VALUE color) {
4
+ gd_image_wrapper *wrap;
5
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
6
+
7
+ int r = NUM2INT(rb_ary_entry(color,0));
8
+ int g = NUM2INT(rb_ary_entry(color,1));
9
+ int b = NUM2INT(rb_ary_entry(color,2));
10
+
11
+ int c = gdImageColorAllocate(wrap->img, r, g, b);
12
+
13
+ gdImageSetPixel(wrap->img, NUM2INT(x), NUM2INT(y), c);
14
+
15
+ return Qnil;
16
+ }
17
+
18
+ static VALUE gd_image_get_pixel(VALUE self, VALUE x, VALUE y) {
19
+ gd_image_wrapper *wrap;
20
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
21
+
22
+ int c = gdImageGetPixel(wrap->img, NUM2INT(x), NUM2INT(y));
23
+
24
+ int r = gdImageRed(wrap->img, c);
25
+ int g = gdImageGreen(wrap->img, c);
26
+ int b = gdImageBlue(wrap->img, c);
27
+
28
+ VALUE ary = rb_ary_new_capa(3);
29
+ rb_ary_push(ary, INT2NUM(r));
30
+ rb_ary_push(ary, INT2NUM(g));
31
+ rb_ary_push(ary, INT2NUM(b));
32
+
33
+ return ary;
34
+ }
35
+
36
+ void gd_define_pixel(VALUE cGDImage) {
37
+ rb_define_method(cGDImage, "set_pixel", gd_image_set_pixel, 3);
38
+ rb_define_method(cGDImage, "get_pixel", gd_image_get_pixel, 2);
39
+ }
data/ext/gd/pixel.o ADDED
Binary file