From: a-shigi@... Date: 2000-08-30T04:13:54+09:00 Subject: [ruby-dev:10719] GD-0.6.2 patch This is a MIME-encapsulated message --N8kYgH+nT+0OLYtXQM2j2Vye1HiKFXrX/lib.sgmail.org Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit ども鴫原です。 ちょっくら、GD-0.6.2を使ってみるか...と思ったら、GDってかなり古い(泣)。 ということで、一応、ruby-1.4.5でpngを吐くようにpatchを当ててみました。 かなり乱暴なパッチですが、一応sample.rbと、gd-demo_1.18は動くようです。 gd本体は、gd-1.7.3で確認していますが、gd-1.6あたりから、マルチバイト文 字のサポートになっているはずなんですが、このあたりのpatchはできませんで した。 --- ■ SGmail http://www.sgmail.org/ ■ SGrelay http://www.shigi.com/ --N8kYgH+nT+0OLYtXQM2j2Vye1HiKFXrX/lib.sgmail.org Content-Type: text/plain; name="GD.patch" Content-Transfer-Encoding: 7bit diff -u GD.orig/GD.c GD/GD.c --- GD.orig/GD.c Sat May 8 22:01:05 1999 +++ GD/GD.c Wed Aug 30 03:32:14 2000 @@ -13,9 +13,13 @@ /* ======================================================================= */ -VALUE io_binmode(VALUE io); /* 1999/04/23 modify */ +VALUE rb_io_binmode(VALUE io); /* 1999/04/23 modify */ /* ======================================================================= */ +#define FALSE 0 +#define TRUE (!FALSE) +#define io_writable(f) +#define io_readable(f) static VALUE mGD, cImage, cFont, cPolygon; @@ -40,7 +44,7 @@ } static VALUE -img_from_gif(class, f) +img_from_png(class, f) VALUE class, f; { VALUE img; @@ -48,11 +52,11 @@ gdImagePtr iptr; Check_Type(f, T_FILE); - io_binmode(f); + rb_io_binmode(f); GetOpenFile(f, fptr); io_readable(fptr); - iptr = gdImageCreateFromGif(fptr->f); + iptr = gdImageCreateFromPng(fptr->f); return Data_Wrap_Struct(class,0,free_img,iptr); } @@ -65,7 +69,7 @@ gdImagePtr iptr; Check_Type(f, T_FILE); - io_binmode(f); + rb_io_binmode(f); GetOpenFile(f, fptr); io_readable(fptr); @@ -82,7 +86,7 @@ gdImagePtr iptr; Check_Type(f, T_FILE); - io_binmode(f); + rb_io_binmode(f); GetOpenFile(f, fptr); io_readable(fptr); @@ -195,18 +199,18 @@ VALUE img, idx; { gdImagePtr im; - VALUE ary = ary_new2(3); + VALUE ary = rb_ary_new2(3); int i, c; Data_Get_Struct(img, gdImage, im); i = NUM2INT(idx); c = gdImageRed(im, i); - ary_push(ary, INT2FIX(c)); + rb_ary_push(ary, INT2FIX(c)); c = gdImageGreen(im, i); - ary_push(ary, INT2FIX(c)); + rb_ary_push(ary, INT2FIX(c)); c = gdImageBlue(im, i); - ary_push(ary, INT2FIX(c)); + rb_ary_push(ary, INT2FIX(c)); return ary; } @@ -228,7 +232,7 @@ image_req(img) VALUE img; { - if (!obj_is_kind_of(img, cImage)) { + if (!rb_obj_is_kind_of(img, cImage)) { TypeError("GD::Image required"); } } @@ -336,7 +340,7 @@ poly_req(ply) VALUE ply; { - if (!obj_is_kind_of(ply, cPolygon) || TYPE(ply) != T_ARRAY) { + if (!rb_obj_is_kind_of(ply, cPolygon) || TYPE(ply) != T_ARRAY) { TypeError("GD::Polygon required"); } } @@ -461,7 +465,7 @@ font_req(fnt) VALUE fnt; { - if (!obj_is_kind_of(fnt, cFont)) { + if (!rb_obj_is_kind_of(fnt, cFont)) { TypeError("GD::Font required"); } } @@ -581,14 +585,14 @@ VALUE img; { gdImagePtr im; - VALUE ary = ary_new2(2); + VALUE ary = rb_ary_new2(2); int i; Data_Get_Struct(img, gdImage, im); i = gdImageSX(im); - ary_push(ary, INT2FIX(i)); + rb_ary_push(ary, INT2FIX(i)); i = gdImageSY(im); - ary_push(ary, INT2FIX(i)); + rb_ary_push(ary, INT2FIX(i)); return ary; } @@ -618,7 +622,7 @@ } static VALUE -img_gif(img, out) +img_png(img, out) VALUE img, out; { gdImagePtr im; @@ -627,12 +631,12 @@ Data_Get_Struct(img, gdImage, im); Check_Type(out, T_FILE); - io_binmode(out); + rb_io_binmode(out); GetOpenFile(out, fptr); io_writable(fptr); f = (fptr->f2) ? fptr->f2 : fptr->f; - gdImageGif(im, f); + gdImagePng(im, f); return img; } @@ -647,7 +651,7 @@ Data_Get_Struct(img, gdImage, im); Check_Type(out, T_FILE); - io_binmode(out); + rb_io_binmode(out); GetOpenFile(out, fptr); io_writable(fptr); f = (fptr->f2) ? fptr->f2 : fptr->f; @@ -665,7 +669,7 @@ ply_new(klass) VALUE klass; { - VALUE self = ary_new(); + VALUE self = rb_ary_new(); RBASIC(self)->klass = klass; return self; @@ -679,8 +683,8 @@ NUM2INT(x); NUM2INT(y); - ary_push(ply, x); - ary_push(ply, y); + rb_ary_push(ply, x); + rb_ary_push(ply, y); return ply; } @@ -695,10 +699,10 @@ NUM2INT(dy); if (RARRAY(ply)->len > 0) { - x = ary_entry(ply, RARRAY(ply)->len - 2); - y = ary_entry(ply, RARRAY(ply)->len - 1); - ary_push(ply, INT2NUM(NUM2INT(x) + NUM2INT(dx))); - ary_push(ply, INT2NUM(NUM2INT(y) + NUM2INT(dy))); + x = rb_ary_entry(ply, RARRAY(ply)->len - 2); + y = rb_ary_entry(ply, RARRAY(ply)->len - 1); + rb_ary_push(ply, INT2NUM(NUM2INT(x) + NUM2INT(dx))); + rb_ary_push(ply, INT2NUM(NUM2INT(y) + NUM2INT(dy))); } else { ply_add_pt(ply, dx, dy); } @@ -714,7 +718,7 @@ if (RARRAY(ply)->len < idx) return Qnil; i *= 2; - return assoc_new(ary_entry(ply, i), ary_entry(ply, i+1)); + return rb_assoc_new(rb_ary_entry(ply, i), rb_ary_entry(ply, i+1)); } static VALUE @@ -727,8 +731,8 @@ NUM2INT(x); NUM2INT(y); - ary_store(ply, i, x); - ary_store(ply, i+1, y); + rb_ary_store(ply, i, x); + rb_ary_store(ply, i+1, y); return ply; } @@ -739,8 +743,8 @@ { int i = NUM2INT(idx)*2; - ary_delete_at(ply, INT2FIX(i)); - ary_delete_at(ply, INT2FIX(i+1)); + rb_ary_delete_at(ply, INT2FIX(i)); + rb_ary_delete_at(ply, INT2FIX(i+1)); return ply; } @@ -757,10 +761,10 @@ struct RArray *ply; { int i; - VALUE ary = ary_new2(ply->len/2); + VALUE ary = rb_ary_new2(ply->len/2); for (i = 0; ilen; i+=2) { - ary_push(ary, assoc_new(ply->ptr[i], ply->ptr[i+1])); + rb_ary_push(ary, rb_assoc_new(ply->ptr[i], ply->ptr[i+1])); } return ary; } @@ -787,7 +791,7 @@ if (ny < t) t = ny; if (ny > b) b = ny; } - return ary_new3(4, INT2FIX(l), INT2FIX(t), INT2FIX(r), INT2FIX(b)); + return rb_ary_new3(4, INT2FIX(l), INT2FIX(t), INT2FIX(r), INT2FIX(b)); } static VALUE @@ -983,9 +987,9 @@ Init_GD() { mGD = rb_define_module("GD"); - cImage = rb_define_class_under(mGD, "Image", cObject); + cImage = rb_define_class_under(mGD, "Image", rb_cObject); rb_define_singleton_method(cImage, "new", img_s_new, 2); - rb_define_singleton_method(cImage, "newFromGif", img_from_gif, 1); + rb_define_singleton_method(cImage, "newFromPng", img_from_png, 1); rb_define_singleton_method(cImage, "newFromXbm", img_from_xbm, 1); rb_define_singleton_method(cImage, "newFromGd", img_from_gd, 1); rb_define_method(cImage, "destroy", img_destroy, 0); @@ -1035,10 +1039,10 @@ rb_define_method(cImage, "width", img_width, 0); rb_define_method(cImage, "height", img_height, 0); - rb_define_method(cImage, "gif", img_gif, 1); + rb_define_method(cImage, "png", img_png, 1); rb_define_method(cImage, "gd", img_gd, 1); - cPolygon = rb_define_class_under(mGD, "Polygon", cObject); + cPolygon = rb_define_class_under(mGD, "Polygon", rb_cObject); rb_define_singleton_method(cPolygon, "new", ply_new, 0); rb_define_method(cPolygon, "addPt", ply_add_pt, 2); @@ -1054,7 +1058,7 @@ rb_define_method(cPolygon, "transform", ply_transform, 6); rb_define_method(cPolygon, "scale", ply_scale, 2); - cFont = rb_define_class_under(mGD, "Font", cObject); + cFont = rb_define_class_under(mGD, "Font", rb_cObject); rb_define_singleton_method(cFont, "new", fnt_s_new, 1); rb_define_const(cFont, "GiantFont", fnt_new("Giant")); diff -u GD.orig/example.rb GD/example.rb --- GD.orig/example.rb Fri Apr 23 00:37:39 1999 +++ GD/example.rb Sat Aug 26 04:45:30 2000 @@ -25,4 +25,4 @@ im.fill(50,50,red) # Convert the image to GIF and print it on standard output -im.gif STDOUT +im.png STDOUT diff -u GD.orig/extconf.rb GD/extconf.rb --- GD.orig/extconf.rb Fri Apr 23 00:37:39 1999 +++ GD/extconf.rb Sat Aug 26 04:11:13 2000 @@ -2,13 +2,13 @@ $CFLAGS = "-I/usr/local/include" $LDFLAGS = "-L/usr/local/lib" have_library("m", "floor") -$lib_cache.delete("gd") # disable cache +#$lib_cache.delete("gd") # disable cache if have_library("gd", "gdImageCreate") create_makefile("GD") else # may need VFlib - have_library("VFlib", "VF_GetBitmap") - $lib_cache.delete("gd") + have_library("VFlib2", "VF_GetBitmap") +# $lib_cache.delete("gd") if have_library("gd", "gdImageCreate") create_makefile("GD") end --N8kYgH+nT+0OLYtXQM2j2Vye1HiKFXrX/lib.sgmail.org--