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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f566c090167c7d474884a2caed9fda37b3e378c2ad716012db964f2abd6fc1ee
4
+ data.tar.gz: 972e8939e822ce014cbb7005dca64ee29b39f72b55ff69229fe31c46c91f0740
5
+ SHA512:
6
+ metadata.gz: 0e2e8a0ce2d911de832dae17d146bcacdefdc962aa2055b6a8757e0dc10b97775b16f3e96c88b58a227e894a42f363470d2936eccb3853e1a811be9081da603d
7
+ data.tar.gz: ce9b77215a9500eb52fa5d6c328dc2fb58f81f153a849be441fd481e667e0307523fbdff65e4985d36265d269eb8d8fb4d866ed11f7a418457025c327d084bee
data/ext/gd/Makefile ADDED
@@ -0,0 +1,269 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ # V=0 quiet, V=1 verbose. other values don't work.
5
+ V = 0
6
+ V0 = $(V:0=)
7
+ Q1 = $(V:1=)
8
+ Q = $(Q1:0=@)
9
+ ECHO1 = $(V:1=@ :)
10
+ ECHO = $(ECHO1:0=@ echo)
11
+ NULLCMD = :
12
+
13
+ #### Start of system configuration section. ####
14
+
15
+ srcdir = .
16
+ topdir = /usr/local/include/ruby-3.3.0
17
+ hdrdir = $(topdir)
18
+ arch_hdrdir = /usr/local/include/ruby-3.3.0/x86_64-linux
19
+ PATH_SEPARATOR = :
20
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
21
+ prefix = $(DESTDIR)/usr/local
22
+ rubysitearchprefix = $(rubylibprefix)/$(sitearch)
23
+ rubyarchprefix = $(rubylibprefix)/$(arch)
24
+ rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
25
+ exec_prefix = $(prefix)
26
+ vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
27
+ sitearchhdrdir = $(sitehdrdir)/$(sitearch)
28
+ rubyarchhdrdir = $(rubyhdrdir)/$(arch)
29
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
30
+ sitehdrdir = $(rubyhdrdir)/site_ruby
31
+ rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
32
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
33
+ vendorlibdir = $(vendordir)/$(ruby_version)
34
+ vendordir = $(rubylibprefix)/vendor_ruby
35
+ sitearchdir = $(sitelibdir)/$(sitearch)
36
+ sitelibdir = $(sitedir)/$(ruby_version)
37
+ sitedir = $(rubylibprefix)/site_ruby
38
+ rubyarchdir = $(rubylibdir)/$(arch)
39
+ rubylibdir = $(rubylibprefix)/$(ruby_version)
40
+ sitearchincludedir = $(includedir)/$(sitearch)
41
+ archincludedir = $(includedir)/$(arch)
42
+ sitearchlibdir = $(libdir)/$(sitearch)
43
+ archlibdir = $(libdir)/$(arch)
44
+ ridir = $(datarootdir)/$(RI_BASE_NAME)
45
+ mandir = $(datarootdir)/man
46
+ localedir = $(datarootdir)/locale
47
+ libdir = $(exec_prefix)/lib
48
+ psdir = $(docdir)
49
+ pdfdir = $(docdir)
50
+ dvidir = $(docdir)
51
+ htmldir = $(docdir)
52
+ infodir = $(datarootdir)/info
53
+ docdir = $(datarootdir)/doc/$(PACKAGE)
54
+ oldincludedir = $(DESTDIR)/usr/include
55
+ includedir = $(prefix)/include
56
+ runstatedir = $(localstatedir)/run
57
+ localstatedir = $(prefix)/var
58
+ sharedstatedir = $(prefix)/com
59
+ sysconfdir = $(prefix)/etc
60
+ datadir = $(datarootdir)
61
+ datarootdir = $(prefix)/share
62
+ libexecdir = $(exec_prefix)/libexec
63
+ sbindir = $(exec_prefix)/sbin
64
+ bindir = $(exec_prefix)/bin
65
+ archdir = $(rubyarchdir)
66
+
67
+
68
+ CC_WRAPPER =
69
+ CC = gcc
70
+ CXX = g++
71
+ LIBRUBY = $(LIBRUBY_SO)
72
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
73
+ LIBRUBYARG_SHARED = -Wl,-rpath,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)
74
+ LIBRUBYARG_STATIC = -Wl,-rpath,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)-static $(MAINLIBS)
75
+ empty =
76
+ OUTFLAG = -o $(empty)
77
+ COUTFLAG = -o $(empty)
78
+ CSRCFLAG = $(empty)
79
+
80
+ RUBY_EXTCONF_H =
81
+ cflags = $(optflags) $(debugflags) $(warnflags)
82
+ cxxflags =
83
+ optflags = -O3 -fno-fast-math
84
+ debugflags = -ggdb3
85
+ warnflags = -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
86
+ cppflags =
87
+ CCDLFLAGS = -fPIC
88
+ CFLAGS = $(CCDLFLAGS) $(cflags) -fPIC $(ARCH_FLAG)
89
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
90
+ DEFS =
91
+ CPPFLAGS = $(DEFS) $(cppflags)
92
+ CXXFLAGS = $(CCDLFLAGS) $(ARCH_FLAG)
93
+ ldflags = -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,--no-as-needed
94
+ dldflags = -Wl,--compress-debug-sections=zlib
95
+ ARCH_FLAG =
96
+ DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
97
+ LDSHARED = $(CC) -shared
98
+ LDSHAREDXX = $(CXX) -shared
99
+ AR = gcc-ar
100
+ EXEEXT =
101
+
102
+ RUBY_INSTALL_NAME = $(RUBY_BASE_NAME)
103
+ RUBY_SO_NAME = ruby
104
+ RUBYW_INSTALL_NAME =
105
+ RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
106
+ RUBYW_BASE_NAME = rubyw
107
+ RUBY_BASE_NAME = ruby
108
+
109
+ arch = x86_64-linux
110
+ sitearch = $(arch)
111
+ ruby_version = 3.3.0
112
+ ruby = $(bindir)/$(RUBY_BASE_NAME)
113
+ RUBY = $(ruby)
114
+ BUILTRUBY = $(bindir)/$(RUBY_BASE_NAME)
115
+ ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/backward.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h
116
+
117
+ RM = rm -f
118
+ RM_RF = rm -fr
119
+ RMDIRS = rmdir --ignore-fail-on-non-empty -p
120
+ MAKEDIRS = /usr/bin/mkdir -p
121
+ INSTALL = /usr/bin/install -c
122
+ INSTALL_PROG = $(INSTALL) -m 0755
123
+ INSTALL_DATA = $(INSTALL) -m 644
124
+ COPY = cp
125
+ TOUCH = exit >
126
+
127
+ #### End of system configuration section. ####
128
+
129
+ preload =
130
+ libpath = . $(libdir)
131
+ LIBPATH = -L. -L$(libdir) -Wl,-rpath,$(libdir)
132
+ DEFFILE =
133
+
134
+ CLEANFILES = mkmf.log
135
+ DISTCLEANFILES =
136
+ DISTCLEANDIRS =
137
+
138
+ extout =
139
+ extout_prefix =
140
+ target_prefix = /gd
141
+ LOCAL_LIBS =
142
+ LIBS = $(LIBRUBYARG_SHARED) -lm -lgd -lm -lpthread -lc
143
+ ORIG_SRCS = arc.c blit.c char.c circle.c clip.c color.c draw_line.c ellipse.c encode.c fill.c filter.c gd.c image.c pixel.c polygon.c rectangle.c text.c transform.c version.c
144
+ SRCS = $(ORIG_SRCS)
145
+ OBJS = arc.o blit.o char.o circle.o clip.o color.o draw_line.o ellipse.o encode.o fill.o filter.o gd.o image.o pixel.o polygon.o rectangle.o text.o transform.o version.o
146
+ HDRS = $(srcdir)/clip.h $(srcdir)/ruby_gd.h
147
+ LOCAL_HDRS =
148
+ TARGET = gd
149
+ TARGET_NAME = gd
150
+ TARGET_ENTRY = Init_$(TARGET_NAME)
151
+ DLLIB = $(TARGET).so
152
+ EXTSTATIC =
153
+ STATIC_LIB =
154
+
155
+ TIMESTAMP_DIR = .
156
+ BINDIR = $(bindir)
157
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
158
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
159
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
160
+ HDRDIR = $(sitehdrdir)$(target_prefix)
161
+ ARCHHDRDIR = $(sitearchhdrdir)$(target_prefix)
162
+ TARGET_SO_DIR =
163
+ TARGET_SO = $(TARGET_SO_DIR)$(DLLIB)
164
+ CLEANLIBS = $(TARGET_SO) false
165
+ CLEANOBJS = $(OBJS) *.bak
166
+ TARGET_SO_DIR_TIMESTAMP = $(TIMESTAMP_DIR)/.sitearchdir.-.gd.time
167
+
168
+ all: $(DLLIB)
169
+ static: $(STATIC_LIB)
170
+ .PHONY: all install static install-so install-rb
171
+ .PHONY: clean clean-so clean-static clean-rb
172
+
173
+ clean-static::
174
+ clean-rb-default::
175
+ clean-rb::
176
+ clean-so::
177
+ clean: clean-so clean-static clean-rb-default clean-rb
178
+ -$(Q)$(RM_RF) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
179
+
180
+ distclean-rb-default::
181
+ distclean-rb::
182
+ distclean-so::
183
+ distclean-static::
184
+ distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
185
+ -$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
186
+ -$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
187
+ -$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
188
+
189
+ realclean: distclean
190
+ install: install-so install-rb
191
+
192
+ install-so: $(DLLIB) $(TARGET_SO_DIR_TIMESTAMP)
193
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
194
+ clean-static::
195
+ -$(Q)$(RM) $(STATIC_LIB)
196
+ install-rb: pre-install-rb do-install-rb install-rb-default
197
+ install-rb-default: pre-install-rb-default do-install-rb-default
198
+ pre-install-rb: Makefile
199
+ pre-install-rb-default: Makefile
200
+ do-install-rb:
201
+ do-install-rb-default:
202
+ pre-install-rb-default:
203
+ @$(NULLCMD)
204
+ $(TARGET_SO_DIR_TIMESTAMP):
205
+ $(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
206
+ $(Q) $(TOUCH) $@
207
+
208
+ site-install: site-install-so site-install-rb
209
+ site-install-so: install-so
210
+ site-install-rb: install-rb
211
+
212
+ .SUFFIXES: .c .m .cc .mm .cxx .cpp .o .S
213
+
214
+ .cc.o:
215
+ $(ECHO) compiling $(<)
216
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
217
+
218
+ .cc.S:
219
+ $(ECHO) translating $(<)
220
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
221
+
222
+ .mm.o:
223
+ $(ECHO) compiling $(<)
224
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
225
+
226
+ .mm.S:
227
+ $(ECHO) translating $(<)
228
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
229
+
230
+ .cxx.o:
231
+ $(ECHO) compiling $(<)
232
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
233
+
234
+ .cxx.S:
235
+ $(ECHO) translating $(<)
236
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
237
+
238
+ .cpp.o:
239
+ $(ECHO) compiling $(<)
240
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
241
+
242
+ .cpp.S:
243
+ $(ECHO) translating $(<)
244
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
245
+
246
+ .c.o:
247
+ $(ECHO) compiling $(<)
248
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
249
+
250
+ .c.S:
251
+ $(ECHO) translating $(<)
252
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
253
+
254
+ .m.o:
255
+ $(ECHO) compiling $(<)
256
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
257
+
258
+ .m.S:
259
+ $(ECHO) translating $(<)
260
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
261
+
262
+ $(TARGET_SO): $(OBJS) Makefile
263
+ $(ECHO) linking shared-object gd/$(DLLIB)
264
+ -$(Q)$(RM) $(@)
265
+ $(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
266
+
267
+
268
+
269
+ $(OBJS): $(HDRS) $(ruby_headers)
data/ext/gd/arc.c ADDED
@@ -0,0 +1,52 @@
1
+ #include "ruby_gd.h"
2
+
3
+ static VALUE gd_image_arc(VALUE self,
4
+ VALUE vcx, VALUE vcy,
5
+ VALUE vw, VALUE vh,
6
+ VALUE vstart, VALUE vend,
7
+ VALUE vcolor
8
+ ) {
9
+ gd_image_wrapper *wrap;
10
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
11
+
12
+ int cx = NUM2INT(vcx);
13
+ int cy = NUM2INT(vcy);
14
+ int w = NUM2INT(vw);
15
+ int h = NUM2INT(vh);
16
+ int s = NUM2INT(vstart);
17
+ int e = NUM2INT(vend);
18
+
19
+ int c = color_to_gd(wrap->img, vcolor);
20
+
21
+ gdImageArc(wrap->img, cx, cy, w, h, s, e, c);
22
+
23
+ return self;
24
+ }
25
+
26
+ static VALUE gd_image_filled_arc(VALUE self,
27
+ VALUE vcx, VALUE vcy,
28
+ VALUE vw, VALUE vh,
29
+ VALUE vstart, VALUE vend,
30
+ VALUE vcolor
31
+ ) {
32
+ gd_image_wrapper *wrap;
33
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
34
+
35
+ int cx = NUM2INT(vcx);
36
+ int cy = NUM2INT(vcy);
37
+ int w = NUM2INT(vw);
38
+ int h = NUM2INT(vh);
39
+ int s = NUM2INT(vstart);
40
+ int e = NUM2INT(vend);
41
+
42
+ int c = color_to_gd(wrap->img, vcolor);
43
+
44
+ gdImageFilledArc(wrap->img, cx, cy, w, h, s, e, c, gdArc);
45
+
46
+ return self;
47
+ }
48
+
49
+ void gd_define_arc(VALUE cGDImage) {
50
+ rb_define_method(cGDImage, "arc", gd_image_arc, 7);
51
+ rb_define_method(cGDImage, "filled_arc", gd_image_filled_arc, 7);
52
+ }
data/ext/gd/arc.o ADDED
Binary file
data/ext/gd/blit.c ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ - [ ] imagecopy — Copy part of an image
3
+ - [ ] imagecopymerge — Copy and merge part of an image
4
+ - [ ] imagecopymergegray — Copy and merge part of an image with gray scale
5
+ - [ ] imagecopyresampled — Copy and resize part of an image with resampling
6
+ - [ ] imagecopyresized — Copy and resize part of an image
7
+ */
8
+ #include "ruby_gd.h"
9
+
10
+ static VALUE gd_image_copy_merge(
11
+ VALUE self, VALUE src,
12
+ VALUE dx, VALUE dy,
13
+ VALUE sx, VALUE sy,
14
+ VALUE w, VALUE h,
15
+ VALUE pct
16
+ ) {
17
+ gd_image_wrapper *dst_wrap;
18
+ gd_image_wrapper *src_wrap;
19
+
20
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, dst_wrap);
21
+ TypedData_Get_Struct(src, gd_image_wrapper, &gd_image_type, src_wrap);
22
+
23
+ gdImageCopyMerge(
24
+ dst_wrap->img,
25
+ src_wrap->img,
26
+ NUM2INT(dx), NUM2INT(dy),
27
+ NUM2INT(sx), NUM2INT(sy),
28
+ NUM2INT(w), NUM2INT(h),
29
+ NUM2INT(pct)
30
+ );
31
+
32
+ return self;
33
+ }
34
+
35
+ void gd_define_blit(VALUE cGDImage) {
36
+ rb_define_method(cGDImage, "copy_merge", gd_image_copy_merge, 8);
37
+ }
data/ext/gd/blit.o ADDED
Binary file
data/ext/gd/char.c ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ - [ ] imagechar — Draw a character horizontally
3
+ - [ ] imagecharup — Draw a character vertically
4
+ */
5
+
6
+
data/ext/gd/char.o ADDED
Binary file
data/ext/gd/circle.c ADDED
@@ -0,0 +1,39 @@
1
+ #include "ruby_gd.h"
2
+
3
+ static VALUE gd_image_circle(VALUE self, VALUE cx, VALUE cy, VALUE r, VALUE color) {
4
+ gd_image_wrapper *wrap;
5
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
6
+
7
+ int red = NUM2INT(rb_ary_entry(color, 0));
8
+ int green = NUM2INT(rb_ary_entry(color, 1));
9
+ int blue = NUM2INT(rb_ary_entry(color, 2));
10
+ int c = gdImageColorAllocate(wrap->img, red, green, blue);
11
+
12
+ gdImageArc(wrap->img,
13
+ NUM2INT(cx), NUM2INT(cy),
14
+ NUM2INT(r)*2, NUM2INT(r)*2,
15
+ 0, 360,
16
+ c);
17
+ return Qnil;
18
+ }
19
+
20
+ static VALUE gd_image_filled_circle(VALUE self, VALUE cx, VALUE cy, VALUE r, VALUE color) {
21
+ gd_image_wrapper *wrap;
22
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
23
+
24
+ int red = NUM2INT(rb_ary_entry(color, 0));
25
+ int green = NUM2INT(rb_ary_entry(color, 1));
26
+ int blue = NUM2INT(rb_ary_entry(color, 2));
27
+ int c = gdImageColorAllocate(wrap->img, red, green, blue);
28
+
29
+ gdImageFilledEllipse(wrap->img,
30
+ NUM2INT(cx), NUM2INT(cy),
31
+ NUM2INT(r)*2, NUM2INT(r)*2,
32
+ c);
33
+ return Qnil;
34
+ }
35
+
36
+ void gd_define_circle(VALUE cGDImage) {
37
+ rb_define_method(cGDImage, "circle", gd_image_circle, 4);
38
+ rb_define_method(cGDImage, "filled_circle", gd_image_filled_circle, 4);
39
+ }
data/ext/gd/circle.o ADDED
Binary file
data/ext/gd/clip.c ADDED
@@ -0,0 +1,92 @@
1
+ #include "clip.h"
2
+ #include <math.h>
3
+
4
+ /* Cohen–Sutherland outcodes */
5
+ #define CS_LEFT 1
6
+ #define CS_RIGHT 2
7
+ #define CS_BOTTOM 4
8
+ #define CS_TOP 8
9
+
10
+ /**
11
+ - [ ] imagegetclip — Get the clipping rectangle
12
+ - [ ] imagesetclip — Set the clipping rectangle
13
+ */
14
+
15
+ static int cs_outcode(int x, int y, int xmin, int ymin, int xmax, int ymax)
16
+ {
17
+ int code = 0;
18
+ if (x < xmin) code |= CS_LEFT;
19
+ else if (x > xmax) code |= CS_RIGHT;
20
+
21
+ if (y < ymin) code |= CS_TOP;
22
+ else if (y > ymax) code |= CS_BOTTOM;
23
+
24
+ return code;
25
+ }
26
+
27
+ /*
28
+ * Clips a line segment to rectangle [xmin..xmax] × [ymin..ymax].
29
+ * On success, updates (*x1,*y1,*x2,*y2) to clipped endpoints and returns 1.
30
+ * If outside (no intersection), returns 0.
31
+ */
32
+ int gd_clip_line_to_rect(int *x1, int *y1, int *x2, int *y2,
33
+ int xmin, int ymin, int xmax, int ymax)
34
+ {
35
+ int x1i = *x1, y1i = *y1, x2i = *x2, y2i = *y2;
36
+ int out1 = cs_outcode(x1i, y1i, xmin, ymin, xmax, ymax);
37
+ int out2 = cs_outcode(x2i, y2i, xmin, ymin, xmax, ymax);
38
+
39
+ while (1) {
40
+ if ((out1 | out2) == 0) {
41
+ /* Trivially accept */
42
+ *x1 = x1i; *y1 = y1i; *x2 = x2i; *y2 = y2i;
43
+ return 1;
44
+ }
45
+ if ((out1 & out2) != 0) {
46
+ /* Trivially reject */
47
+ return 0;
48
+ }
49
+
50
+ /* At least one endpoint is outside; choose it */
51
+ int out = out1 ? out1 : out2;
52
+
53
+ /* Intersection point (use double to avoid integer rounding traps) */
54
+ double x = 0.0, y = 0.0;
55
+ double dx = (double)(x2i - x1i);
56
+ double dy = (double)(y2i - y1i);
57
+
58
+ if (out & CS_TOP) {
59
+ /* y = ymin */
60
+ if (dy == 0.0) return 0; /* horizontal line outside */
61
+ x = x1i + dx * ( (double)(ymin - y1i) / dy );
62
+ y = (double)ymin;
63
+ } else if (out & CS_BOTTOM) {
64
+ /* y = ymax */
65
+ if (dy == 0.0) return 0;
66
+ x = x1i + dx * ( (double)(ymax - y1i) / dy );
67
+ y = (double)ymax;
68
+ } else if (out & CS_RIGHT) {
69
+ /* x = xmax */
70
+ if (dx == 0.0) return 0; /* vertical line outside */
71
+ y = y1i + dy * ( (double)(xmax - x1i) / dx );
72
+ x = (double)xmax;
73
+ } else { /* CS_LEFT */
74
+ /* x = xmin */
75
+ if (dx == 0.0) return 0;
76
+ y = y1i + dy * ( (double)(xmin - x1i) / dx );
77
+ x = (double)xmin;
78
+ }
79
+
80
+ /* Round to nearest int (you can also use floor/ceil if prefieres) */
81
+ int xi = (int)lround(x);
82
+ int yi = (int)lround(y);
83
+
84
+ if (out == out1) {
85
+ x1i = xi; y1i = yi;
86
+ out1 = cs_outcode(x1i, y1i, xmin, ymin, xmax, ymax);
87
+ } else {
88
+ x2i = xi; y2i = yi;
89
+ out2 = cs_outcode(x2i, y2i, xmin, ymin, xmax, ymax);
90
+ }
91
+ }
92
+ }
data/ext/gd/clip.h ADDED
@@ -0,0 +1,7 @@
1
+ #ifndef RUBY_LIBGD_CLIP_H
2
+ #define RUBY_LIBGD_CLIP_H
3
+
4
+ int gd_clip_line_to_rect(int *x1, int *y1, int *x2, int *y2,
5
+ int xmin, int ymin, int xmax, int ymax);
6
+
7
+ #endif
data/ext/gd/clip.o ADDED
Binary file
data/ext/gd/color.c ADDED
@@ -0,0 +1,53 @@
1
+ #include "ruby_gd.h"
2
+
3
+ int color_to_gd(gdImagePtr im, VALUE color) {
4
+ Check_Type(color, T_ARRAY);
5
+ if (RARRAY_LEN(color) < 3)
6
+ rb_raise(rb_eArgError, "color must be [r,g,b] or [r,g,b,a]");
7
+
8
+ int r = NUM2INT(rb_ary_entry(color, 0));
9
+ int g = NUM2INT(rb_ary_entry(color, 1));
10
+ int b = NUM2INT(rb_ary_entry(color, 2));
11
+
12
+ if (gdImageTrueColor(im)) {
13
+ if (RARRAY_LEN(color) >= 4) {
14
+ int a = NUM2INT(rb_ary_entry(color, 3));
15
+ return gdTrueColorAlpha(r,g,b,a);
16
+ }
17
+ return gdTrueColor(r,g,b);
18
+ }
19
+
20
+ return gdImageColorAllocate(im, r,g,b);
21
+ }
22
+
23
+ static VALUE gd_color_rgb(VALUE self, VALUE r, VALUE g, VALUE b) {
24
+ VALUE ary = rb_ary_new_capa(3);
25
+ rb_ary_push(ary, r);
26
+ rb_ary_push(ary, g);
27
+ rb_ary_push(ary, b);
28
+ return ary;
29
+ }
30
+
31
+ static VALUE gd_color_rgba(VALUE self, VALUE vr, VALUE vg, VALUE vb, VALUE va) {
32
+ int r = NUM2INT(vr);
33
+ int g = NUM2INT(vg);
34
+ int b = NUM2INT(vb);
35
+ int a = NUM2INT(va);
36
+
37
+ if (a < 0) a = 0;
38
+ if (a > 127) a = 127; // GD usa 0=opaco, 127=transparente
39
+
40
+ VALUE ary = rb_ary_new2(4);
41
+ rb_ary_push(ary, INT2NUM(r));
42
+ rb_ary_push(ary, INT2NUM(g));
43
+ rb_ary_push(ary, INT2NUM(b));
44
+ rb_ary_push(ary, INT2NUM(a));
45
+
46
+ return ary;
47
+ }
48
+
49
+ void gd_define_color(VALUE mGD) {
50
+ VALUE mGDColor = rb_define_module_under(mGD, "Color");
51
+ rb_define_singleton_method(mGDColor, "rgb", gd_color_rgb, 3);
52
+ rb_define_singleton_method(mGDColor, "rgba", gd_color_rgba, 4);
53
+ }
data/ext/gd/color.o ADDED
Binary file
@@ -0,0 +1,53 @@
1
+ #include <math.h>
2
+ #include "ruby_gd.h"
3
+ #include "clip.h"
4
+
5
+ static VALUE gd_image_line(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE color) {
6
+ gd_image_wrapper *wrap;
7
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
8
+
9
+ int ix1 = NUM2INT(x1);
10
+ int iy1 = NUM2INT(y1);
11
+ int ix2 = NUM2INT(x2);
12
+ int iy2 = NUM2INT(y2);
13
+
14
+ int ox1 = ix1;
15
+ int oy1 = iy1;
16
+ int ox2 = ix2;
17
+ int oy2 = iy2;
18
+
19
+ int w = wrap->img->sx;
20
+ int h = wrap->img->sy;
21
+
22
+ /* Clip to image bounds */
23
+ int xmin = 0;
24
+ int ymin = 0;
25
+ int xmax = w - 1;
26
+ int ymax = h - 1;
27
+
28
+ if (!gd_clip_line_to_rect(&ix1, &iy1, &ix2, &iy2, xmin, ymin, xmax, ymax)) {
29
+ rb_warn("Line is completely outside image bounds");
30
+ return Qnil;
31
+ }
32
+
33
+ if (ix1 != ox1 || iy1 != oy1 || ix2 != ox2 || iy2 != oy2) {
34
+ rb_warn("Line coordinates clipped to image bounds");
35
+ }
36
+
37
+ if (TYPE(color) != T_ARRAY || RARRAY_LEN(color) != 3) {
38
+ rb_raise(rb_eArgError, "color must be [r,g,b]");
39
+ }
40
+
41
+ int r = NUM2INT(rb_ary_entry(color, 0));
42
+ int g = NUM2INT(rb_ary_entry(color, 1));
43
+ int b = NUM2INT(rb_ary_entry(color, 2));
44
+
45
+ int c = gdImageColorAllocate(wrap->img, r, g, b);
46
+ gdImageLine(wrap->img, NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2), c);
47
+
48
+ return Qnil;
49
+ }
50
+
51
+ void gd_define_line(VALUE cGDImage) {
52
+ rb_define_method(cGDImage, "line", gd_image_line, 5);
53
+ }
Binary file
data/ext/gd/ellipse.c ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ - [ ] imageellipse — Draw an ellipse
3
+ - [ ] imagefilledellipse — Draw a filled ellipse
4
+ */
data/ext/gd/ellipse.o ADDED
Binary file