extract_curves 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/CVS/Entries +4 -0
  2. data/CVS/Repository +1 -0
  3. data/CVS/Root +1 -0
  4. data/bin/CVS/Entries +5 -0
  5. data/bin/CVS/Repository +1 -0
  6. data/bin/CVS/Root +1 -0
  7. data/bin/ec_rect2polar.rb +22 -0
  8. data/bin/ec_rev_lines.rb +5 -0
  9. data/bin/ec_sph_area.rb +30 -0
  10. data/bin/extract_curves.rb +2145 -0
  11. data/ruby_ext/CVS/Entries +1 -0
  12. data/ruby_ext/CVS/Repository +1 -0
  13. data/ruby_ext/CVS/Root +1 -0
  14. data/ruby_ext/pav/CVS/Entries +14 -0
  15. data/ruby_ext/pav/CVS/Repository +1 -0
  16. data/ruby_ext/pav/CVS/Root +1 -0
  17. data/ruby_ext/pav/cstr.c +82 -0
  18. data/ruby_ext/pav/cstr.h +17 -0
  19. data/ruby_ext/pav/extconf.rb +22 -0
  20. data/ruby_ext/pav/pav.c +162 -0
  21. data/ruby_ext/pav/pgtk.c +40 -0
  22. data/ruby_ext/pav/pgtk.h +14 -0
  23. data/ruby_ext/pav/pix.c +806 -0
  24. data/ruby_ext/pav/pix.h +236 -0
  25. data/ruby_ext/pav/t.rb +35 -0
  26. data/ruby_ext/pav/t1.rb +35 -0
  27. data/ruby_libs/CVS/Entries +1 -0
  28. data/ruby_libs/CVS/Repository +1 -0
  29. data/ruby_libs/CVS/Root +1 -0
  30. data/ruby_libs/pav/CVS/Entries +20 -0
  31. data/ruby_libs/pav/CVS/Repository +1 -0
  32. data/ruby_libs/pav/CVS/Root +1 -0
  33. data/ruby_libs/pav/attr_cache.rb +211 -0
  34. data/ruby_libs/pav/attr_cache.t1.rb +32 -0
  35. data/ruby_libs/pav/cache.rb +31 -0
  36. data/ruby_libs/pav/dbg_log.rb +458 -0
  37. data/ruby_libs/pav/floatsio.rb +53 -0
  38. data/ruby_libs/pav/generator_cache.rb +165 -0
  39. data/ruby_libs/pav/gtk/CVS/Entries +4 -0
  40. data/ruby_libs/pav/gtk/CVS/Repository +1 -0
  41. data/ruby_libs/pav/gtk/CVS/Root +1 -0
  42. data/ruby_libs/pav/gtk/button.rb +130 -0
  43. data/ruby_libs/pav/gtk/icons.rb +87 -0
  44. data/ruby_libs/pav/gtk/toolbar.rb +192 -0
  45. data/ruby_libs/pav/heap.rb +54 -0
  46. data/ruby_libs/pav/icons/CVS/Entries +17 -0
  47. data/ruby_libs/pav/icons/CVS/Repository +1 -0
  48. data/ruby_libs/pav/icons/CVS/Root +1 -0
  49. data/ruby_libs/pav/icons/alt_handle.xcf +0 -0
  50. data/ruby_libs/pav/icons/alt_handle.xpm +3832 -0
  51. data/ruby_libs/pav/icons/alt_handle_hover.xcf +0 -0
  52. data/ruby_libs/pav/icons/alt_handle_hover.xpm +3368 -0
  53. data/ruby_libs/pav/icons/alt_handle_pressed.xcf +0 -0
  54. data/ruby_libs/pav/icons/alt_handle_pressed.xpm +3828 -0
  55. data/ruby_libs/pav/icons/extract_curves/CVS/Entries +6 -0
  56. data/ruby_libs/pav/icons/extract_curves/CVS/Repository +1 -0
  57. data/ruby_libs/pav/icons/extract_curves/CVS/Root +1 -0
  58. data/ruby_libs/pav/icons/extract_curves/extract_curves-icon-rgb.ppm +14 -0
  59. data/ruby_libs/pav/icons/extract_curves/extract_curves-logo-rgb.gif +0 -0
  60. data/ruby_libs/pav/icons/extract_curves/extract_curves-logo-rgb.xcf +0 -0
  61. data/ruby_libs/pav/icons/extract_curves/trace_mark.xcf +0 -0
  62. data/ruby_libs/pav/icons/extract_curves/trace_mark.xpm +38 -0
  63. data/ruby_libs/pav/icons/handle.xcf +0 -0
  64. data/ruby_libs/pav/icons/handle.xpm +213 -0
  65. data/ruby_libs/pav/icons/next.xpm +29 -0
  66. data/ruby_libs/pav/icons/next_hover.xpm +315 -0
  67. data/ruby_libs/pav/icons/next_pressed.xpm +144 -0
  68. data/ruby_libs/pav/icons/prev.xpm +29 -0
  69. data/ruby_libs/pav/icons/prev_hover.xpm +315 -0
  70. data/ruby_libs/pav/icons/prev_pressed.xpm +144 -0
  71. data/ruby_libs/pav/icons/vnext.xpm +29 -0
  72. data/ruby_libs/pav/icons/vprev.xpm +29 -0
  73. data/ruby_libs/pav/numeric/CVS/Entries +2 -0
  74. data/ruby_libs/pav/numeric/CVS/Repository +1 -0
  75. data/ruby_libs/pav/numeric/CVS/Root +1 -0
  76. data/ruby_libs/pav/numeric/ext.rb +13 -0
  77. data/ruby_libs/pav/pav_find.rb +90 -0
  78. data/ruby_libs/pav/pix.rb +402 -0
  79. data/ruby_libs/pav/pix/CVS/Entries +11 -0
  80. data/ruby_libs/pav/pix/CVS/Repository +1 -0
  81. data/ruby_libs/pav/pix/CVS/Root +1 -0
  82. data/ruby_libs/pav/pix/aapix.rb +378 -0
  83. data/ruby_libs/pav/pix/blob.rb +543 -0
  84. data/ruby_libs/pav/pix/circle.rb +73 -0
  85. data/ruby_libs/pav/pix/contour.rb +644 -0
  86. data/ruby_libs/pav/pix/contour/CVS/Entries +5 -0
  87. data/ruby_libs/pav/pix/contour/CVS/Repository +1 -0
  88. data/ruby_libs/pav/pix/contour/CVS/Root +1 -0
  89. data/ruby_libs/pav/pix/contour/calc_situations.rb +9 -0
  90. data/ruby_libs/pav/pix/contour/carp_calc.rb +212 -0
  91. data/ruby_libs/pav/pix/contour/situations.dmp +0 -0
  92. data/ruby_libs/pav/pix/contour/situations.rb +21 -0
  93. data/ruby_libs/pav/pix/curve.rb +1508 -0
  94. data/ruby_libs/pav/pix/img_obj.rb +751 -0
  95. data/ruby_libs/pav/pix/node.rb +712 -0
  96. data/ruby_libs/pav/pix/node_grp.rb +853 -0
  97. data/ruby_libs/pav/pix/shaved_core.rb +534 -0
  98. data/ruby_libs/pav/pix/subpix.rb +212 -0
  99. data/ruby_libs/pav/rand_accessible.rb +16 -0
  100. data/ruby_libs/pav/rangeset.rb +63 -0
  101. data/ruby_libs/pav/search.rb +210 -0
  102. data/ruby_libs/pav/set.rb +20 -0
  103. data/ruby_libs/pav/string/CVS/Entries +6 -0
  104. data/ruby_libs/pav/string/CVS/Repository +1 -0
  105. data/ruby_libs/pav/string/CVS/Root +1 -0
  106. data/ruby_libs/pav/string/bits.rb +523 -0
  107. data/ruby_libs/pav/string/ext.rb +58 -0
  108. data/ruby_libs/pav/string/observable.rb +155 -0
  109. data/ruby_libs/pav/string/text.rb +79 -0
  110. data/ruby_libs/pav/string/words.rb +42 -0
  111. data/ruby_libs/pav/sub_arr.rb +55 -0
  112. data/ruby_libs/pav/traced_obj.rb +79 -0
  113. metadata +161 -0
@@ -0,0 +1 @@
1
+ D/pav////
@@ -0,0 +1 @@
1
+ extract-curves/ruby_ext
@@ -0,0 +1 @@
1
+ :ext:pavpen@rubyforge.org:/var/cvs/extract-curves
@@ -0,0 +1,14 @@
1
+ /Makefile/1.1.1.1/Tue Nov 15 17:32:09 2005//
2
+ /Makefile.mingw32/1.1.1.1/Tue Nov 15 17:32:09 2005//
3
+ /cstr.c/1.1.1.1/Tue Nov 15 17:32:09 2005//
4
+ /cstr.h/1.1.1.1/Tue Nov 15 17:32:08 2005//
5
+ /extconf.rb/1.1.1.1/Tue Nov 15 17:32:08 2005//
6
+ /pav.c/1.1.1.1/Tue Nov 15 17:32:09 2005//
7
+ /pgtk.c/1.1.1.1/Tue Nov 15 17:32:08 2005//
8
+ /pgtk.h/1.1.1.1/Tue Nov 15 17:32:09 2005//
9
+ /pix.c/1.1.1.1/Tue Nov 15 17:32:08 2005//
10
+ /pix.h/1.1.1.1/Tue Nov 15 17:32:09 2005//
11
+ /rbconfig.rb/1.1.1.1/Tue Nov 15 17:32:09 2005//
12
+ /t.rb/1.1.1.1/Tue Nov 15 17:32:08 2005//
13
+ /t1.rb/1.1.1.1/Tue Nov 15 17:32:09 2005//
14
+ D
@@ -0,0 +1 @@
1
+ extract-curves/ruby_ext/pav
@@ -0,0 +1 @@
1
+ :ext:pavpen@rubyforge.org:/var/cvs/extract-curves
@@ -0,0 +1,82 @@
1
+ #include "cstr.h"
2
+ #include <rubysig.h>
3
+ #include <stdlib.h>
4
+ #include <string.h>
5
+
6
+ VALUE prb_str_view_new(VALUE from_obj, char *ptr, long len)
7
+ {
8
+ VALUE res;
9
+
10
+ res = rb_str_new(NULL, 0);
11
+ //rb_gc_register_address(&res);
12
+ /* rb_funcall(rb_eval_string("ObjectSpace"), rb_intern("define_finalizer"),
13
+ 2, res, rb_funcall(rb_funcall(res, rb_intern("method"), 1,
14
+ rb_str_new2("sterilize")), rb_intern("to_proc"), 0)); */
15
+ RSTRING(res)->aux.shared = from_obj;
16
+ RSTRING(res)->aux.capa = RSTRING(res)->len = len;
17
+ FL_SET(res, RBASIC(res)->flags | (ELTS_SHARED |FL_USER3/*|STR_ASSOC*/));
18
+ RUBY_CRITICAL(free(RSTRING(res)->ptr));
19
+ RSTRING(res)->ptr = ptr;
20
+ return res;
21
+ }
22
+
23
+ VALUE prb_str_cstr_view_new(int argc, VALUE *argv, VALUE self)
24
+ {
25
+ char *ptr;
26
+
27
+ if (argc > 3 || argc < 2) {
28
+ rb_raise(rb_eArgError, "Invalid number of arguments (%i); use "
29
+ "String.cstr_view_new(from_rb_obj, char *[, length])", argc);
30
+ }
31
+ ptr = (char*) NUM2ULONG(argv[1]);
32
+ if (argc == 2) {
33
+ return(prb_str_view_new(argv[0], ptr, strlen(ptr)));
34
+ } else {
35
+ return(prb_str_view_new(argv[0], ptr, NUM2LONG(argv[2])));
36
+ }
37
+ }
38
+
39
+ VALUE prb_str_ptr(VALUE self)
40
+ {
41
+ return ULONG2NUM((unsigned long) RSTRING(self)->ptr);
42
+ }
43
+
44
+ VALUE prb_cstr_sterilize(VALUE self, VALUE obj_id)
45
+ {
46
+ RSTRING(self)->ptr = NULL;
47
+ RSTRING(self)->aux.capa = RSTRING(self)->len = 0;
48
+ return Qnil;
49
+ }
50
+
51
+ __inline__ VALUE prb_cstr_new1(char *ptr, long len, VALUE from_obj)
52
+ {
53
+ return rb_funcall(prb_cCStrView, rb_intern("new"),3,LONG2NUM((long)ptr),
54
+ LONG2NUM(len), from_obj);
55
+ }
56
+
57
+ VALUE prb_cstr_new(int argc, VALUE *argv, VALUE self)
58
+ {
59
+ VALUE res;
60
+ char *ptr;
61
+
62
+ if (argc > 3 || argc < 2) {
63
+ rb_raise(rb_eArgError, "Invalid number of arguments (%i); use "
64
+ "CStrView.new(char *[, length], from_rb_obj)", argc);
65
+ }
66
+ res = rb_call_super(0, NULL);
67
+ //rb_gc_register_address(&res);
68
+ rb_funcall(rb_eval_string("ObjectSpace"), rb_intern("define_finalizer"),
69
+ 2, res, rb_funcall(rb_funcall(res, rb_intern("method"), 1,
70
+ rb_str_new2("sterilize")), rb_intern("to_proc"), 0));
71
+ ptr = (char*) NUM2LONG(argv[0]);
72
+ if (argc == 2) {
73
+ RSTRING(res)->aux.shared = argv[1];
74
+ RSTRING(res)->aux.capa = RSTRING(res)->len = strlen(ptr);
75
+ } else {
76
+ RSTRING(res)->aux.shared = argv[2];
77
+ RSTRING(res)->aux.capa = RSTRING(res)->len = NUM2LONG(argv[1]);
78
+ }
79
+ RSTRING(res)->ptr = ptr;
80
+ return res;
81
+ }
82
+
@@ -0,0 +1,17 @@
1
+ #ifndef PAV_CSTR_H
2
+ #define PAV_CSTR_H
3
+
4
+ #include <ruby.h>
5
+
6
+ VALUE prb_cCStrView;
7
+
8
+ VALUE prb_str_new6(VALUE from_obj, char *ptr, long len);
9
+ VALUE prb_str_view_new(VALUE from_obj, char *ptr, long len);
10
+ VALUE prb_str_cstr_view_new(int argc, VALUE *argv, VALUE self);
11
+ VALUE prb_str_ptr(VALUE self);
12
+
13
+ VALUE prb_cstr_sterilize(VALUE self, VALUE obj_id);
14
+ VALUE prb_cstr_new(int argc, VALUE *argv, VALUE self);
15
+ __inline__ VALUE prb_cstr_new1(char *ptr, long len, VALUE from_obj);
16
+
17
+ #endif /* PAV_CSTR_H */
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # To cross-compile for Win32 on Linux:
4
+ # shell$ export PKG_CONFIG_PATH=/devel/target/mswin32/lib/pkgconfig
5
+ # shell$ export TARGET_PLATFORM_RUBYLIB=/devel/target/mswin32/lib/ruby/site_ruby/1.8:/devel/target/mswin32/lib/ruby/site_ruby/1.8/i386-msvcrt:/devel/target/mswin32/lib/ruby/1.8:/devel/target/mswin32/lib/ruby/1.8/i386-target-mswin32
6
+ # shell$ ruby1.8 extconf.rb
7
+
8
+ if targ_rb_lib_paths = ENV['TARGET_PLATFORM_RUBYLIB']
9
+ targ_rb_lib_paths.split(':').reverse_each { |lpath| $:.unshift(lpath) }
10
+ end
11
+
12
+ #require 'rbconfig'
13
+ #Config::CONFIG.keys.sort.each { |k| puts "#{k} = #{Config::CONFIG[k]}" }
14
+ #puts Config::DESTDIR
15
+ #puts Config::TOPDIR
16
+
17
+ require 'mkmf'
18
+
19
+ have_header('string.h')
20
+
21
+ pkg_config('gobject-2.0 gdk-pixbuf-2.0 glib-2.0')
22
+ create_makefile('pav')
@@ -0,0 +1,162 @@
1
+ #include <ruby.h>
2
+ // #include <gtk/gtk.h>
3
+ #include "pix.h"
4
+ #include "cstr.h"
5
+ #include "pgtk.h"
6
+
7
+ VALUE prb_mPPix;
8
+
9
+ static __inline__ VALUE adjs_ary(const int *adjs, int n)
10
+ {
11
+ int x, y;
12
+ const int *adj, *end_a = adjs + 2*n;
13
+ VALUE res = rb_ary_new2(n);
14
+
15
+ for ( adj = adjs; adj < end_a; adj++ ) {
16
+ x = *adj; adj++; y = *adj;
17
+ rb_ary_push(res, rb_funcall(prb_cPPix_Xy, rb_intern("new"), 2,
18
+ INT2NUM(x), INT2NUM(y)));
19
+ }
20
+ return res;
21
+ }
22
+
23
+ void Init_pav()
24
+ {
25
+ rb_require("gtk2");
26
+
27
+ // class String
28
+ rb_define_singleton_method(rb_cString, "cstr_view_new",
29
+ prb_str_cstr_view_new, -1);
30
+ rb_define_method(rb_cString, "ptr", prb_str_ptr, 0);
31
+
32
+ // class CStrView
33
+ prb_cCStrView = rb_define_class("CStrView", rb_cString);
34
+ rb_define_singleton_method(prb_cCStrView, "new", prb_cstr_new, -1);
35
+ rb_define_method(prb_cCStrView, "sterilize", prb_cstr_sterilize, 1);
36
+
37
+ // module PGtk
38
+ prb_mPGtk = rb_define_module("PGtk");
39
+ rb_define_module_function(prb_mPGtk, "user_cache_dir",
40
+ prb_pgtk_user_cache_dir, 0);
41
+ rb_define_module_function(prb_mPGtk, "user_data_dir",
42
+ prb_pgtk_user_data_dir, 0);
43
+ rb_define_module_function(prb_mPGtk, "user_config_dir",
44
+ prb_pgtk_user_config_dir, 0);
45
+ rb_define_module_function(prb_mPGtk, "system_data_dirs",
46
+ prb_pgtk_system_data_dirs, 0);
47
+ rb_define_module_function(prb_mPGtk, "system_config_dirs",
48
+ prb_pgtk_system_config_dirs, 0);
49
+
50
+ // module PPix
51
+ prb_mPPix = rb_define_module("PPix");
52
+ // class PPix::Xy
53
+ prb_cPPix_Xy = rb_define_class_under(prb_mPPix, "Xy", rb_cObject);
54
+ rb_define_method(prb_cPPix_Xy, "initialize", prb_xy_init, 2);
55
+ rb_define_method(prb_cPPix_Xy, "x", prb_xy_x, 0);
56
+ rb_define_method(prb_cPPix_Xy, "y", prb_xy_y, 0);
57
+ rb_define_method(prb_cPPix_Xy, "yx", prb_xy_yx, 0);
58
+ rb_define_method(prb_cPPix_Xy, "hash", prb_xy_hash, 0);
59
+ rb_define_method(prb_cPPix_Xy, "to_s", prb_xy_to_s, 0);
60
+ rb_define_method(prb_cPPix_Xy, "coords_to_s", prb_xy_to_s, 0);
61
+
62
+ prb_rbPixAdjs8 = adjs_ary(prb_PixAdjs, 8);
63
+ prb_rbPixAdjs8_NoUp = adjs_ary(prb_PixAdjs_NoUp, 5);
64
+ prb_rbPixAdjs8_NoDown = adjs_ary(prb_PixAdjs_NoDown, 5);
65
+ prb_rbPixAdjs8_NoLeft = adjs_ary(prb_PixAdjs_NoLeft, 5);
66
+ prb_rbPixAdjs8_NoRight = adjs_ary(prb_PixAdjs_NoRight, 5);
67
+ prb_rbPixAdjs8_NoUpDown = adjs_ary(prb_PixAdjs_NoUpDown, 2);
68
+ prb_rbPixAdjs8_NoLeftRight = adjs_ary(prb_PixAdjs_NoLeftRight, 2);
69
+ prb_rbPixAdjs8_NoLeftUp = adjs_ary(prb_PixAdjs_NoLeftUp, 3);
70
+ prb_rbPixAdjs8_NoLeftDown = adjs_ary(prb_PixAdjs_NoLeftDown, 3);
71
+ prb_rbPixAdjs8_NoRightUp = adjs_ary(prb_PixAdjs_NoRightUp, 3);
72
+ prb_rbPixAdjs8_NoRightDown = adjs_ary(prb_PixAdjs_NoRightDown, 3);
73
+ prb_rbPixAdjs8_NoLeftRightUp = adjs_ary(prb_PixAdjs_NoLeftRightUp, 1);
74
+ prb_rbPixAdjs8_NoLeftRightDown =adjs_ary(prb_PixAdjs_NoLeftRightDown,1);
75
+ prb_rbPixAdjs8_NoLeftUpDown = adjs_ary(prb_PixAdjs_NoLeftUpDown, 1);
76
+ prb_rbPixAdjs8_NoRightUpDown = adjs_ary(prb_PixAdjs_NoRightUpDown, 1);
77
+ prb_rbPixAdjs8_None = rb_ary_new2(0);
78
+ prb_rbPixAdjs4 = adjs_ary(prb_PixAdjs, 4);
79
+ prb_rbPixAdjs4_NoUp = adjs_ary(prb_PixAdjs_NoUp, 3);
80
+ prb_rbPixAdjs4_NoDown = adjs_ary(prb_PixAdjs_NoDown, 3);
81
+ prb_rbPixAdjs4_NoLeft = adjs_ary(prb_PixAdjs_NoLeft, 3);
82
+ prb_rbPixAdjs4_NoRight = adjs_ary(prb_PixAdjs_NoRight, 3);
83
+ prb_rbPixAdjs4_NoUpDown = prb_rbPixAdjs8_NoUpDown;
84
+ prb_rbPixAdjs4_NoLeftRight = prb_rbPixAdjs8_NoLeftRight;
85
+ prb_rbPixAdjs4_NoLeftUp = adjs_ary(prb_PixAdjs_NoLeftUp, 2);
86
+ prb_rbPixAdjs4_NoLeftDown = adjs_ary(prb_PixAdjs_NoLeftDown, 2);
87
+ prb_rbPixAdjs4_NoRightUp = adjs_ary(prb_PixAdjs_NoRightUp, 2);
88
+ prb_rbPixAdjs4_NoRightDown = adjs_ary(prb_PixAdjs_NoRightDown, 2);
89
+ prb_rbPixAdjs4_NoLeftRightUp = prb_rbPixAdjs8_NoLeftRightUp;
90
+ prb_rbPixAdjs4_NoLeftRightDown = prb_rbPixAdjs8_NoLeftRightDown;
91
+ prb_rbPixAdjs4_NoLeftUpDown = prb_rbPixAdjs8_NoLeftUpDown;
92
+ prb_rbPixAdjs4_NoRightUpDown = prb_rbPixAdjs8_NoRightUpDown;
93
+ prb_rbPixAdjs4_None = prb_rbPixAdjs8_None;
94
+ rb_define_const(prb_cPPix_Xy, "ADJACENT4", prb_rbPixAdjs4);
95
+ rb_define_const(prb_cPPix_Xy, "ADJACENT8", prb_rbPixAdjs8);
96
+
97
+ // module PPix::PixbufPix
98
+ prb_mPPix_MPixbufPix = rb_define_module_under(prb_mPPix, "MPixbufPix");
99
+ rb_define_singleton_method(prb_mPPix_MPixbufPix, "rgb_to_hsv",
100
+ prb_pixbuf_pix_rgb_to_hsv, 3);
101
+ rb_define_method(prb_mPPix_MPixbufPix,"pixbuf",prb_pixbuf_pix_pixbuf,0);
102
+ rb_define_method(prb_mPPix_MPixbufPix, "color_id",
103
+ prb_pixbuf_pix_color_id, 0);
104
+ rb_define_method(prb_mPPix_MPixbufPix, "color_rgb",
105
+ prb_pixbuf_pix_color_rgb, 0);
106
+ rb_define_method(prb_mPPix_MPixbufPix, "color_hsv",
107
+ prb_pixbuf_pix_color_hsv, 0);
108
+ rb_define_method(prb_mPPix_MPixbufPix, "virtual?",
109
+ prb_pixbuf_pix_is_virtual, 0);
110
+ rb_define_method(prb_mPPix_MPixbufPix, "border?",
111
+ prb_pixbuf_pix_is_border, 1);
112
+ rb_define_method(prb_mPPix_MPixbufPix, "border8?",
113
+ prb_pixbuf_pix_is_border8, 0);
114
+ rb_define_method(prb_mPPix_MPixbufPix, "border4?",
115
+ prb_pixbuf_pix_is_border4, 0);
116
+ rb_define_method(prb_mPPix_MPixbufPix, "adj", prb_pixbuf_pix_adj, 1);
117
+ rb_define_method(prb_mPPix_MPixbufPix, "adj8", prb_pixbuf_pix_adj8, 0);
118
+ rb_define_method(prb_mPPix_MPixbufPix, "adj4", prb_pixbuf_pix_adj4, 0);
119
+ rb_define_method(prb_mPPix_MPixbufPix, "adj_cocolor",
120
+ prb_pixbuf_pix_adj_cocolor, 1);
121
+ rb_define_method(prb_mPPix_MPixbufPix, "adj_cocolor8",
122
+ prb_pixbuf_pix_adj_cocolor8, 0);
123
+ rb_define_method(prb_mPPix_MPixbufPix, "adj_cocolor4",
124
+ prb_pixbuf_pix_adj_cocolor4, 0);
125
+ rb_define_method(prb_mPPix_MPixbufPix, "adj_fuzzy_rgb_cocolor",
126
+ prb_pixbuf_pix_adj_fuzzy_rgb_cocolor, 4);
127
+ rb_define_method(prb_mPPix_MPixbufPix, "adj_fuzzy_hsv_cocolor",
128
+ prb_pixbuf_pix_adj_fuzzy_rgb_cocolor, 4);
129
+
130
+ // class PPix::PixbufPix
131
+ prb_cPPix_PixbufPix = rb_define_class_under(prb_mPPix, "PixbufPix",
132
+ prb_cPPix_Xy);
133
+ rb_include_module(prb_cPPix_PixbufPix, prb_mPPix_MPixbufPix);
134
+ rb_define_method(prb_cPPix_PixbufPix, "initialize", prb_pixbuf_pix_init,
135
+ 3);
136
+
137
+ // class PPix::Pixbuf
138
+ prb_cPPix_Pixbuf = rb_define_class_under(prb_mPPix, "Pixbuf",
139
+ rb_eval_string("Gdk::Pixbuf"));
140
+ rb_define_method(prb_cPPix_Pixbuf, "initialize", prb_pixbuf_init, -1);
141
+ rb_define_method(prb_cPPix_Pixbuf,"pixels_ptr",prb_pixbuf_pixels_ptr,0);
142
+ rb_define_method(prb_cPPix_Pixbuf, "pixels", prb_pixbuf_pixels, 0);
143
+ rb_define_method(prb_cPPix_Pixbuf, "sample_length",
144
+ prb_pixbuf_sample_length, 0);
145
+ rb_define_method(prb_cPPix_Pixbuf,"pix_length",prb_pixbuf_pix_length,0);
146
+ rb_define_method(prb_cPPix_Pixbuf, "picture_width",
147
+ prb_pixbuf_picture_width, 0);
148
+ rb_define_method(prb_cPPix_Pixbuf, "picture_height",
149
+ prb_pixbuf_picture_height, 0);
150
+ rb_define_method(prb_cPPix_Pixbuf, "ofs0", prb_pixbuf_ofs0, 0);
151
+ rb_define_method(prb_cPPix_Pixbuf, "pix_mask", prb_pixbuf_pix_mask, 0);
152
+ rb_define_method(prb_cPPix_Pixbuf, "border_width",
153
+ prb_pixbuf_border_width, 0);
154
+ rb_define_method(prb_cPPix_Pixbuf, "get_pix", prb_pixbuf_get_pix, 2);
155
+ rb_define_method(prb_cPPix_Pixbuf, "dup", prb_pixbuf_dup, 0);
156
+ rb_define_method(prb_cPPix_Pixbuf, "scale", prb_pixbuf_scale, -1);
157
+ rb_define_method(prb_cPPix_Pixbuf,"add_border",prb_pixbuf_add_border,1);
158
+ /*rb_define_method(prb_cPPix_Pixbuf, "subpixbuf",
159
+ prb_pixbuf_subpixbuf, 4);*/
160
+ rb_define_method(prb_cPPix_Pixbuf, "scaled", prb_pixbuf_scaled, 7);
161
+ rb_define_method(prb_cPPix_Pixbuf,"gdk_scaled",prb_pixbuf_gdk_scaled,7);
162
+ }
@@ -0,0 +1,40 @@
1
+ #include "pgtk.h"
2
+ #include <glib.h>
3
+ #include <ruby.h>
4
+
5
+ VALUE prb_pgtk_user_cache_dir(VALUE self)
6
+ {
7
+ return rb_str_new2(g_get_user_cache_dir());
8
+ }
9
+
10
+ VALUE prb_pgtk_user_data_dir(VALUE self)
11
+ {
12
+ return rb_str_new2(g_get_user_data_dir());
13
+ }
14
+
15
+ VALUE prb_pgtk_user_config_dir(VALUE self)
16
+ {
17
+ return rb_str_new2(g_get_user_config_dir());
18
+ }
19
+
20
+ VALUE prb_pgtk_system_data_dirs(VALUE self)
21
+ {
22
+ VALUE res = rb_ary_new();
23
+ const char * const * paths;
24
+
25
+ for ( paths = g_get_system_data_dirs(); *paths; paths++ ) {
26
+ rb_ary_push(res, rb_str_new2(*paths));
27
+ }
28
+ return res;
29
+ }
30
+
31
+ VALUE prb_pgtk_system_config_dirs(VALUE self)
32
+ {
33
+ VALUE res = rb_ary_new();
34
+ const char * const * paths;
35
+
36
+ for ( paths = g_get_system_config_dirs(); *paths; paths++ ) {
37
+ rb_ary_push(res, rb_str_new2(*paths));
38
+ }
39
+ return res;
40
+ }
@@ -0,0 +1,14 @@
1
+ #ifndef PAV_PGTK_H
2
+ #define PAV_PGTK_H
3
+
4
+ #include <ruby.h>
5
+
6
+ VALUE prb_mPGtk;
7
+
8
+ VALUE prb_pgtk_user_cache_dir(VALUE self);
9
+ VALUE prb_pgtk_user_data_dir(VALUE self);
10
+ VALUE prb_pgtk_user_config_dir(VALUE self);
11
+ VALUE prb_pgtk_system_data_dirs(VALUE self);
12
+ VALUE prb_pgtk_system_config_dirs(VALUE self);
13
+
14
+ #endif /* PAV_PGTK_H */
@@ -0,0 +1,806 @@
1
+ #include <math.h>
2
+ #include <ruby.h>
3
+ #include <intern.h>
4
+ #include <stdlib.h>
5
+ #include <string.h>
6
+ #include <glib-object.h>
7
+
8
+ #include "pix.h"
9
+ #include "cstr.h"
10
+
11
+ const int prb_PixAdjs[] ={1, 0, 0, -1, -1, 0, 0, 1, 1, -1, -1, -1, -1, 1, 1, 1};
12
+ const int prb_PixAdjs_NoUp[] = {1, 0, -1, 0, 0, 1, -1, 1, 1, 1};
13
+ const int prb_PixAdjs_NoDown[] = {1, 0, 0, -1, -1, 0, 1, -1, -1, -1};
14
+ const int prb_PixAdjs_NoLeft[] = {1, 0, 0, -1, 0, 1, 1, -1, 1, 1};
15
+ const int prb_PixAdjs_NoRight[] = {0, -1, -1, 0, 0, 1, -1, -1, -1, 1};
16
+ const int prb_PixAdjs_NoUpDown[] = {1, 0, -1, 0};
17
+ const int prb_PixAdjs_NoLeftRight[] = {0, -1, 0, 1};
18
+ const int prb_PixAdjs_NoLeftUp[] = {1, 0, 0, 1, 1, 1};
19
+ const int prb_PixAdjs_NoLeftDown[] = {1, 0, 0, -1, 1, -1};
20
+ const int prb_PixAdjs_NoRightUp[] = {-1, 0, 0, 1, -1, 1};
21
+ const int prb_PixAdjs_NoRightDown[] = {0, -1, -1, 0, -1, -1};
22
+ const int prb_PixAdjs_NoLeftRightUp[] = {0, 1};
23
+ const int prb_PixAdjs_NoLeftRightDown[] = {0, -1};
24
+ const int prb_PixAdjs_NoLeftUpDown[] = {1, 0};
25
+ const int prb_PixAdjs_NoRightUpDown[] = {-1, 0};
26
+
27
+ VALUE prb_xy_init(VALUE self, VALUE x, VALUE y)
28
+ {
29
+ rb_iv_set(self, "@x", x);
30
+ rb_iv_set(self, "@y", y);
31
+ rb_iv_set(self,"@yx", rb_ary_new3(2, y, x));
32
+ return Qnil;
33
+ }
34
+
35
+ VALUE prb_xy_x(VALUE self)
36
+ {
37
+ return rb_iv_get(self, "@x");
38
+ }
39
+
40
+ VALUE prb_xy_y(VALUE self)
41
+ {
42
+ return rb_iv_get(self, "@y");
43
+ }
44
+
45
+ VALUE prb_xy_yx(VALUE self)
46
+ {
47
+ return rb_iv_get(self, "@yx");
48
+ }
49
+
50
+ VALUE prb_xy_hash(VALUE self)
51
+ {
52
+ return LONG2NUM(NUM2LONG(rb_iv_get(self, "@y"))*32768 +
53
+ NUM2LONG(rb_iv_get(self, "@x")));
54
+ }
55
+
56
+ VALUE prb_xy_to_s(VALUE self)
57
+ {
58
+ VALUE res;
59
+
60
+ res = rb_str_buf_new2("(");
61
+ res = rb_str_buf_append(res, rb_obj_as_string(rb_iv_get(self, "@x")));
62
+ res = rb_str_buf_append(res, rb_str_new2(", "));
63
+ res = rb_str_buf_append(res, rb_obj_as_string(rb_iv_get(self, "@y")));
64
+ res = rb_str_buf_append(res, rb_str_new2(")"));
65
+ return res;
66
+ }
67
+
68
+ void prb_color_rgb_to_hsv(int r, int g, int b, double *h, double *s, double *v)
69
+ {
70
+ double d_c_delta, d_max_c; // c = (RGB) component, h = hue
71
+
72
+ #define PRB_CRTS_WITH_SORTED_CS(min_c,h_min_val,mid_c,h_mid_val,max_c,h_val,mt)\
73
+ d_max_c = (double) (max_c); \
74
+ (*v) = d_max_c / 255.0; \
75
+ if ( (min_c) == (max_c) ) {\
76
+ (*h) = (*s) = 0.0; \
77
+ } else {\
78
+ d_c_delta = (double) (max_c - min_c); \
79
+ (*s) = d_c_delta / d_max_c; \
80
+ (*h) = (h_val) / 6.0; \
81
+ }
82
+
83
+ PRB_3_FPASS_SORTED_WITH_PROPS(r,
84
+ (g-b) < 0 ? (6.0 + ((double)(g-b)) / d_c_delta) :
85
+ (((double) (g-b)) / d_c_delta),
86
+ g, 2.0 + ((double) (b-r)) / d_c_delta,
87
+ b, 4.0 + ((double) (r-g)) / d_c_delta, PRB_CRTS_WITH_SORTED_CS,)
88
+ }
89
+
90
+ VALUE prb_pixbuf_pix_rgb_to_hsv(VALUE klass, VALUE r, VALUE g, VALUE b)
91
+ {
92
+ double h, s, v;
93
+
94
+ prb_color_rgb_to_hsv(NUM2INT(r), NUM2INT(g), NUM2INT(b), &h, &s, &v);
95
+ return rb_ary_new3(3, rb_float_new(h),rb_float_new(s),rb_float_new(v));
96
+ }
97
+
98
+ VALUE prb_pixbuf_pix_init(VALUE self, VALUE pixbuf, VALUE x, VALUE y)
99
+ {
100
+ VALUE args[] = {x, y};
101
+
102
+ rb_call_super(2, args);
103
+ rb_iv_set(self,"@pixbuf", pixbuf);
104
+ return Qnil;
105
+ }
106
+
107
+ VALUE prb_pixbuf_pix_pixbuf(VALUE self)
108
+ {
109
+ return rb_iv_get(self, "@pixbuf");
110
+ }
111
+
112
+ VALUE prb_pixbuf_pix_color_id(VALUE self)
113
+ {
114
+ VALUE pixbuf;
115
+ int width, height, border_width, x, y, rowstride, pix_len;
116
+ unsigned char *pixels;
117
+
118
+ pixbuf = rb_iv_get(self, "@pixbuf");
119
+ pixels = (unsigned char*) RSTRING(rb_iv_get(pixbuf,"@pixels"))->ptr;
120
+ width = NUM2INT(rb_funcall(pixbuf, rb_intern("width"), 0));
121
+ height = NUM2INT(rb_funcall(pixbuf, rb_intern("height"), 0));
122
+ border_width = NUM2INT(rb_iv_get(pixbuf, "@border_width"));
123
+ x = NUM2INT(rb_funcall(self, rb_intern("x"), 0)) + border_width;
124
+ y = NUM2INT(rb_funcall(self, rb_intern("y"), 0)) + border_width;
125
+ if ( x < 0 )
126
+ x = 0;
127
+ else if ( x >= width )
128
+ x = width - 1;
129
+ if ( y < 0 )
130
+ y = 0;
131
+ else if ( y >= height)
132
+ y = height - 1;
133
+ rowstride = NUM2INT(rb_funcall(pixbuf, rb_intern("rowstride"), 0));
134
+ pix_len = NUM2INT(rb_iv_get(pixbuf, "@pix_length"));
135
+ return LONG2NUM((*((long*)(pixels + y*rowstride + x*pix_len))) &
136
+ NUM2LONG(rb_iv_get(pixbuf, "@pix_mask")));
137
+ }
138
+
139
+ VALUE prb_pixbuf_pix_color_rgb(VALUE self)
140
+ {
141
+ VALUE pixbuf;
142
+ int width, height, border_width, x, y, rowstride, pix_len;
143
+ unsigned char *pixels, *pix_ptr;
144
+
145
+ pixbuf = rb_iv_get(self, "@pixbuf");
146
+ pixels = (unsigned char*) RSTRING(rb_iv_get(pixbuf,"@pixels"))->ptr;
147
+ width = NUM2INT(rb_funcall(pixbuf, rb_intern("width"), 0));
148
+ height = NUM2INT(rb_funcall(pixbuf, rb_intern("height"), 0));
149
+ border_width = NUM2INT(rb_iv_get(pixbuf, "@border_width"));
150
+ x = NUM2INT(rb_funcall(self, rb_intern("x"), 0)) + border_width;
151
+ y = NUM2INT(rb_funcall(self, rb_intern("y"), 0)) + border_width;
152
+ if ( x < 0 )
153
+ x = 0;
154
+ else if ( x >= width )
155
+ x = width - 1;
156
+ if ( y < 0 )
157
+ y = 0;
158
+ else if ( y >= height)
159
+ y = height - 1;
160
+ rowstride = NUM2INT(rb_funcall(pixbuf, rb_intern("rowstride"), 0));
161
+ pix_len = NUM2INT(rb_iv_get(pixbuf, "@pix_length"));
162
+ pix_ptr = pixels + y*rowstride + x*pix_len;
163
+ return rb_ary_new3(3, INT2NUM(pix_ptr[0]), INT2NUM(pix_ptr[1]),
164
+ INT2NUM(pix_ptr[2]));
165
+ }
166
+
167
+ VALUE prb_pixbuf_pix_color_hsv(VALUE self)
168
+ {
169
+ double h, s, v;
170
+ VALUE pixbuf;
171
+ int width, height, border_width, x, y, rowstride, pix_len;
172
+ unsigned char *pixels, *pix_ptr;
173
+
174
+ pixbuf = rb_iv_get(self, "@pixbuf");
175
+ pixels = (unsigned char*) RSTRING(rb_iv_get(pixbuf,"@pixels"))->ptr;
176
+ width = NUM2INT(rb_funcall(pixbuf, rb_intern("width"), 0));
177
+ height = NUM2INT(rb_funcall(pixbuf, rb_intern("height"), 0));
178
+ border_width = NUM2INT(rb_iv_get(pixbuf, "@border_width"));
179
+ x = NUM2INT(rb_funcall(self, rb_intern("x"), 0)) + border_width;
180
+ y = NUM2INT(rb_funcall(self, rb_intern("y"), 0)) + border_width;
181
+ if ( x < 0 )
182
+ x = 0;
183
+ else if ( x >= width )
184
+ x = width - 1;
185
+ if ( y < 0 )
186
+ y = 0;
187
+ else if ( y >= height)
188
+ y = height - 1;
189
+ rowstride = NUM2INT(rb_funcall(pixbuf, rb_intern("rowstride"), 0));
190
+ pix_len = NUM2INT(rb_iv_get(pixbuf, "@pix_length"));
191
+ pix_ptr = pixels + y*rowstride + x*pix_len;
192
+ prb_color_rgb_to_hsv(pix_ptr[0], pix_ptr[1], pix_ptr[2], &h, &s, &v);
193
+ return rb_ary_new3(3, rb_float_new(h),rb_float_new(s),rb_float_new(v));
194
+ }
195
+
196
+ VALUE prb_pixbuf_pix_is_virtual(VALUE self)
197
+ {
198
+ VALUE pixbuf;
199
+ int x, y;
200
+
201
+ pixbuf = rb_iv_get(self, "@pixbuf");
202
+ x = NUM2INT(rb_funcall(self, rb_intern("x"), 0));
203
+ y = NUM2INT(rb_funcall(self, rb_intern("y"), 0));
204
+ if ( x < 0 || x >= NUM2INT(rb_iv_get(pixbuf, "@picture_width")) ||
205
+ y < 0 || y >= NUM2INT(rb_iv_get(pixbuf, "@picture_height")) ) {
206
+ return Qtrue;
207
+ } else {
208
+ return Qfalse;
209
+ }
210
+ }
211
+
212
+ VALUE prb_pixbuf_pix_is_border(VALUE self, VALUE adjacents)
213
+ {
214
+ VALUE pixbuf, *adj, *adjs = RARRAY(adjacents)->ptr,
215
+ *a_end = adjs + RARRAY(adjacents)->len;
216
+ unsigned char *pixels;
217
+ int rowstride, pix_len, x0, y0, x, y, width, height;
218
+ long clr_id, mask;
219
+ ID id_x = rb_intern("x"), id_y = rb_intern("y");
220
+
221
+ pixbuf = rb_iv_get(self, "@pixbuf");
222
+ x0 = NUM2INT(rb_funcall(self, rb_intern("x"), 0));
223
+ y0 = NUM2INT(rb_funcall(self, rb_intern("y"), 0));
224
+ width = NUM2INT(rb_iv_get(pixbuf, "@picture_width"));
225
+ height = NUM2INT(rb_iv_get(pixbuf, "@picture_height"));
226
+ pixels = (unsigned char*) RSTRING(rb_iv_get(pixbuf,"@pixels"))->ptr +
227
+ NUM2INT(rb_iv_get(pixbuf, "@ofs0"));
228
+ rowstride = NUM2INT(rb_funcall(pixbuf, rb_intern("rowstride"), 0));
229
+ pix_len = NUM2INT(rb_iv_get(pixbuf, "@pix_length"));
230
+ mask = NUM2LONG(rb_iv_get(pixbuf, "@pix_mask"));
231
+ clr_id = (*((long*) (pixels + y0*rowstride + x0*pix_len))) & mask;
232
+ for ( adj = adjs; adj < a_end; adj++ ) {
233
+ x = x0 + NUM2INT(rb_funcall(*adj, id_x, 0));
234
+ y = y0 + NUM2INT(rb_funcall(*adj, id_y, 0));
235
+ if (x < 0 || x >= width || y < 0 || y >= height ||
236
+ (( *((long*)(pixels+y*rowstride+x*pix_len))) & mask) != clr_id)
237
+ return Qtrue;
238
+ }
239
+ return Qfalse;
240
+ }
241
+
242
+ VALUE prb_pixbuf_pix_is_border_in_8(VALUE self, unsigned int neighbs_cnt)
243
+ {
244
+ VALUE pixbuf;
245
+ unsigned char *pixels;
246
+ int rowstride, pix_len, x0, y0, x, y, width, height;
247
+ const int *adj, *a_end = prb_PixAdjs + 2*neighbs_cnt;
248
+ long clr_id, mask;
249
+
250
+ x0 = NUM2INT(rb_funcall(self, rb_intern("x"), 0));
251
+ y0 = NUM2INT(rb_funcall(self, rb_intern("y"), 0));
252
+ if ( x0 < 1 || y0 < 1 )
253
+ return Qtrue;
254
+ pixbuf = rb_iv_get(self, "@pixbuf");
255
+ width = NUM2INT(rb_iv_get(pixbuf, "@picture_width"));
256
+ height = NUM2INT(rb_iv_get(pixbuf, "@picture_height"));
257
+ if ( x0 >= width-1 || y0 >= height-1 )
258
+ return Qtrue;
259
+ pixels = (unsigned char*) RSTRING(rb_iv_get(pixbuf,"@pixels"))->ptr +
260
+ NUM2INT(rb_iv_get(pixbuf, "@ofs0"));
261
+ rowstride = NUM2INT(rb_funcall(pixbuf, rb_intern("rowstride"), 0));
262
+ pix_len = NUM2INT(rb_iv_get(pixbuf, "@pix_length"));
263
+ mask = NUM2LONG(rb_iv_get(pixbuf, "@pix_mask"));
264
+ clr_id = (*((long*) (pixels + y0*rowstride + x0*pix_len))) & mask;
265
+ for ( adj = prb_PixAdjs; adj < a_end; adj++ ) {
266
+ x = x0 + (*adj); adj++;
267
+ y = y0 + (*adj);
268
+ if ( ((*((long*)(pixels + y*rowstride + x*pix_len))) & mask) !=
269
+ clr_id )
270
+ return Qtrue;
271
+ }
272
+ return Qfalse;
273
+ }
274
+
275
+ VALUE prb_pixbuf_pix_is_border8(VALUE self)
276
+ {
277
+ return prb_pixbuf_pix_is_border_in_8(self, 8);
278
+ }
279
+
280
+ VALUE prb_pixbuf_pix_is_border4(VALUE self)
281
+ {
282
+ return prb_pixbuf_pix_is_border_in_8(self, 4);
283
+ }
284
+
285
+ VALUE prb_pixbuf_pix_adj(VALUE self, VALUE adjacents)
286
+ {
287
+ VALUE res = rb_ary_new2(RARRAY(adjacents)->len), pixbuf, *adj,
288
+ *adjs = RARRAY(adjacents)->ptr,
289
+ *a_end = adjs + RARRAY(adjacents)->len;
290
+ unsigned char *pixels;
291
+ int rowstride, pix_len, x0, y0, x, y, width, height;
292
+ ID id_x = rb_intern("x"), id_y = rb_intern("y"),
293
+ id_get_pix = rb_intern("get_pix");
294
+
295
+ pixbuf = rb_iv_get(self, "@pixbuf");
296
+ x0 = NUM2INT(rb_funcall(self, rb_intern("x"), 0));
297
+ y0 = NUM2INT(rb_funcall(self, rb_intern("y"), 0));
298
+ width = NUM2INT(rb_iv_get(pixbuf, "@picture_width"));
299
+ height = NUM2INT(rb_iv_get(pixbuf, "@picture_height"));
300
+ pixels = (unsigned char*) RSTRING(rb_iv_get(pixbuf,"@pixels"))->ptr +
301
+ NUM2INT(rb_iv_get(pixbuf, "@ofs0"));
302
+ rowstride = NUM2INT(rb_funcall(pixbuf, rb_intern("rowstride"), 0));
303
+ pix_len = NUM2INT(rb_iv_get(pixbuf, "@pix_length"));
304
+ for ( adj = adjs; adj < a_end; adj++ ) {
305
+ x = x0 + NUM2INT(rb_funcall(*adj, id_x, 0));
306
+ y = y0 + NUM2INT(rb_funcall(*adj, id_y, 0));
307
+ if (x >= 0 && x < width && y >= 0 && y <= height)
308
+ rb_ary_push(res, rb_funcall(pixbuf, id_get_pix, 2,
309
+ INT2NUM(x), INT2NUM(y)));
310
+ }
311
+ return res;
312
+ }
313
+
314
+ VALUE prb_pixbuf_pix_adj8(VALUE self)
315
+ {
316
+ VALUE pixbuf, res;
317
+ int adj_cnt, x0, y0, x, y;
318
+ const int *adj, *a_end;
319
+ ID id_get_pix = rb_intern("get_pix");
320
+
321
+ pixbuf = rb_iv_get(self, "@pixbuf");
322
+ x0 = NUM2INT(rb_funcall(self, rb_intern("x"), 0));
323
+ y0 = NUM2INT(rb_funcall(self, rb_intern("y"), 0));
324
+ adj_cnt = PRB_PIX_ADJS8(x0, y0, 0, 0,
325
+ NUM2INT(rb_iv_get(pixbuf, "@picture_width"))-1,
326
+ NUM2INT(rb_iv_get(pixbuf, "@picture_height"))-1, adj);
327
+ a_end = adj + 2*adj_cnt;
328
+ res = rb_ary_new2(adj_cnt);
329
+ for ( ; adj < a_end; adj++ ) {
330
+ x = x0 + *adj; adj++; y = y0 + *adj;
331
+ rb_ary_push(res, rb_funcall(pixbuf, id_get_pix, 2,
332
+ INT2NUM(x), INT2NUM(y)));
333
+ }
334
+ return res;
335
+ }
336
+
337
+ VALUE prb_pixbuf_pix_adj4(VALUE self)
338
+ {
339
+ VALUE pixbuf, res;
340
+ int adj_cnt, x0, y0, x, y;
341
+ const int *adj, *a_end;
342
+ ID id_get_pix = rb_intern("get_pix");
343
+
344
+ pixbuf = rb_iv_get(self, "@pixbuf");
345
+ x0 = NUM2INT(rb_funcall(self, rb_intern("x"), 0));
346
+ y0 = NUM2INT(rb_funcall(self, rb_intern("y"), 0));
347
+ adj_cnt = PRB_PIX_ADJS4(x0, y0, 0, 0,
348
+ NUM2INT(rb_iv_get(pixbuf, "@picture_width"))-1,
349
+ NUM2INT(rb_iv_get(pixbuf, "@picture_height"))-1, adj);
350
+ a_end = adj + 2*adj_cnt;
351
+ res = rb_ary_new2(adj_cnt);
352
+ for ( ; adj < a_end; adj++ ) {
353
+ x = x0 + *adj; adj++; y = y0 + *adj;
354
+ rb_ary_push(res, rb_funcall(pixbuf, id_get_pix, 2,
355
+ INT2NUM(x), INT2NUM(y)));
356
+ }
357
+ return res;
358
+ }
359
+
360
+ VALUE prb_pixbuf_pix_adj_cocolor(VALUE self, VALUE adjacents)
361
+ {
362
+ VALUE res = rb_ary_new2(RARRAY(adjacents)->len), pixbuf, *adj,
363
+ *adjs = RARRAY(adjacents)->ptr,
364
+ *a_end = adjs + RARRAY(adjacents)->len;
365
+ unsigned char *pixels;
366
+ int rowstride, pix_len, x0, y0, x, y, width, height;
367
+ long clr_id, mask;
368
+ ID id_x = rb_intern("x"), id_y = rb_intern("y"),
369
+ id_get_pix = rb_intern("get_pix");
370
+
371
+ pixbuf = rb_iv_get(self, "@pixbuf");
372
+ x0 = NUM2INT(rb_funcall(self, id_x, 0));
373
+ y0 = NUM2INT(rb_funcall(self, id_y, 0));
374
+ width = NUM2INT(rb_iv_get(pixbuf, "@picture_width"));
375
+ height = NUM2INT(rb_iv_get(pixbuf, "@picture_height"));
376
+ pixels = (unsigned char*) RSTRING(rb_iv_get(pixbuf,"@pixels"))->ptr +
377
+ NUM2INT(rb_iv_get(pixbuf, "@ofs0"));
378
+ rowstride = NUM2INT(rb_funcall(pixbuf, rb_intern("rowstride"), 0));
379
+ pix_len = NUM2INT(rb_iv_get(pixbuf, "@pix_length"));
380
+ mask = NUM2LONG(rb_iv_get(pixbuf, "@pix_mask"));
381
+ clr_id = (*((long*) (pixels + y0*rowstride + x0*pix_len))) &
382
+ mask;
383
+ for ( adj = adjs; adj < a_end; adj++ ) {
384
+ x = x0 + NUM2INT(rb_funcall(*adj, id_x, 0));
385
+ y = y0 + NUM2INT(rb_funcall(*adj, id_y, 0));
386
+ if (x >= 0 && x < width && y >= 0 && y <= height &&
387
+ ((*((long*)(pixels+y*rowstride+x*pix_len))) & mask) == clr_id )
388
+ rb_ary_push(res, rb_funcall(pixbuf, id_get_pix, 2,
389
+ INT2NUM(x), INT2NUM(y)));
390
+ }
391
+ return res;
392
+ }
393
+
394
+ VALUE prb_pixbuf_pix_adj_cocolor8(VALUE self)
395
+ {
396
+ VALUE pixbuf, res;
397
+ int adj_cnt, x0, y0, x, y;
398
+ const int *adj, *a_end;
399
+ unsigned char *pixels;
400
+ int rowstride, pix_len;
401
+ long clr_id, mask;
402
+ ID id_get_pix = rb_intern("get_pix");
403
+
404
+ pixbuf = rb_iv_get(self, "@pixbuf");
405
+ x0 = NUM2INT(rb_funcall(self, rb_intern("x"), 0));
406
+ y0 = NUM2INT(rb_funcall(self, rb_intern("y"), 0));
407
+ adj_cnt = PRB_PIX_ADJS8(x0, y0, 0, 0,
408
+ NUM2INT(rb_iv_get(pixbuf, "@picture_width"))-1,
409
+ NUM2INT(rb_iv_get(pixbuf, "@picture_height"))-1, adj);
410
+ a_end = adj + 2*adj_cnt;
411
+ pixels = (unsigned char*) RSTRING(rb_iv_get(pixbuf,"@pixels"))->ptr +
412
+ NUM2INT(rb_iv_get(pixbuf, "@ofs0"));
413
+ rowstride = NUM2INT(rb_funcall(pixbuf, rb_intern("rowstride"), 0));
414
+ pix_len = NUM2INT(rb_iv_get(pixbuf, "@pix_length"));
415
+ mask = NUM2LONG(rb_iv_get(pixbuf, "@pix_mask"));
416
+ clr_id = (*((long*) (pixels + y0*rowstride + x0*pix_len))) & mask;
417
+ res = rb_ary_new2(adj_cnt);
418
+ for ( ; adj < a_end; adj++ ) {
419
+ x = x0 + *adj; adj++; y = y0 + *adj;
420
+ if ( ((*((long*)(pixels+y*rowstride+x*pix_len))) & mask) ==
421
+ clr_id )
422
+ rb_ary_push(res, rb_funcall(pixbuf, id_get_pix, 2,
423
+ INT2NUM(x), INT2NUM(y)));
424
+ }
425
+ return res;
426
+ }
427
+
428
+ VALUE prb_pixbuf_pix_adj_cocolor4(VALUE self)
429
+ {
430
+ VALUE pixbuf, res;
431
+ int adj_cnt, x0, y0, x, y;
432
+ const int *adj, *a_end;
433
+ unsigned char *pixels;
434
+ int rowstride, pix_len;
435
+ long clr_id, mask;
436
+ ID id_get_pix = rb_intern("get_pix");
437
+
438
+ pixbuf = rb_iv_get(self, "@pixbuf");
439
+ x0 = NUM2INT(rb_funcall(self, rb_intern("x"), 0));
440
+ y0 = NUM2INT(rb_funcall(self, rb_intern("y"), 0));
441
+ adj_cnt = PRB_PIX_ADJS4(x0, y0, 0, 0,
442
+ NUM2INT(rb_iv_get(pixbuf, "@picture_width"))-1,
443
+ NUM2INT(rb_iv_get(pixbuf, "@picture_height"))-1, adj);
444
+ a_end = adj + 2*adj_cnt;
445
+ pixels = (unsigned char*) RSTRING(rb_iv_get(pixbuf,"@pixels"))->ptr +
446
+ NUM2INT(rb_iv_get(pixbuf, "@ofs0"));
447
+ rowstride = NUM2INT(rb_funcall(pixbuf, rb_intern("rowstride"), 0));
448
+ pix_len = NUM2INT(rb_iv_get(pixbuf, "@pix_length"));
449
+ mask = NUM2LONG(rb_iv_get(pixbuf, "@pix_mask"));
450
+ clr_id = (*((long*) (pixels + y0*rowstride + x0*pix_len))) & mask;
451
+ res = rb_ary_new2(adj_cnt);
452
+ for ( ; adj < a_end; adj++ ) {
453
+ x = x0 + *adj; adj++; y = y0 + *adj;
454
+ if ( ((*((long*)(pixels+y*rowstride+x*pix_len))) & mask) ==
455
+ clr_id )
456
+ rb_ary_push(res, rb_funcall(pixbuf, id_get_pix, 2,
457
+ INT2NUM(x), INT2NUM(y)));
458
+ }
459
+ return res;
460
+ }
461
+
462
+ VALUE
463
+ prb_pixbuf_pix_adj_fuzzy_rgb_cocolor
464
+ (VALUE self, VALUE adjacents, VALUE rb_r_toler, VALUE rb_g_toler,
465
+ VALUE rb_b_toler)
466
+ {
467
+ VALUE res = rb_ary_new2(RARRAY(adjacents)->len), pixbuf, *adj,
468
+ *adjs = RARRAY(adjacents)->ptr,
469
+ *a_end = adjs + RARRAY(adjacents)->len;
470
+ unsigned char *pixels, *pix_ptr;
471
+ int rowstride, pix_len, width, height, x0,y0, x, y, r, g, b,
472
+ r_toler = NUM2INT(rb_r_toler),
473
+ g_toler = NUM2INT(rb_g_toler),
474
+ b_toler = NUM2INT(rb_b_toler);
475
+ ID id_x = rb_intern("x"), id_y = rb_intern("y"),
476
+ id_get_pix = rb_intern("get_pix");
477
+
478
+ pixbuf = rb_iv_get(self, "@pixbuf");
479
+ x0 = NUM2INT(rb_funcall(self, id_x, 0));
480
+ y0 = NUM2INT(rb_funcall(self, id_y, 0));
481
+ width = NUM2INT(rb_iv_get(pixbuf, "@picture_width"));
482
+ height = NUM2INT(rb_iv_get(pixbuf, "@picture_height"));
483
+ pixels = (unsigned char *) RSTRING(rb_iv_get(pixbuf,"@pixels"))->ptr +
484
+ NUM2INT(rb_iv_get(pixbuf, "@ofs0"));
485
+ rowstride = NUM2INT(rb_funcall(pixbuf, rb_intern("rowstride"), 0));
486
+ pix_len = NUM2INT(rb_iv_get(pixbuf, "@pix_length"));
487
+ pix_ptr = pixels + y0*rowstride + x0*pix_len;
488
+ r = pix_ptr[0]; g = pix_ptr[1]; b = pix_ptr[2];
489
+ for ( adj = adjs; adj < a_end; adj++ ) {
490
+ x = x0 + NUM2INT(rb_funcall(*adj, id_x, 0));
491
+ y = y0 + NUM2INT(rb_funcall(*adj, id_y, 0));
492
+ if (x >= 0 && x < width && y >= 0 && y <= height) {
493
+ pix_ptr = pixels + y*rowstride + x*pix_len;
494
+ if (abs(r-pix_ptr[0]) < r_toler &&
495
+ abs(g-pix_ptr[1]) < g_toler && abs(b-pix_ptr[2]) < b_toler)
496
+ rb_ary_push(res, rb_funcall(pixbuf, id_get_pix, 2,
497
+ INT2NUM(x), INT2NUM(y)));
498
+ }
499
+ }
500
+ return res;
501
+ }
502
+
503
+ VALUE
504
+ prb_pixbuf_pix_adj_fuzzy_hsv_cocolor
505
+ (VALUE self, VALUE adjacents, VALUE rb_h_toler, VALUE rb_s_toler,
506
+ VALUE rb_v_toler)
507
+ {
508
+ VALUE res = rb_ary_new2(RARRAY(adjacents)->len), pixbuf, *adj,
509
+ *adjs = RARRAY(adjacents)->ptr,
510
+ *a_end = adjs + RARRAY(adjacents)->len;
511
+ unsigned char *pixels, *pix_ptr;
512
+ int rowstride, pix_len, width, height, x0, y0, x, y;
513
+ double h, s, v, th, ts, tv, h_toler =RFLOAT(rb_h_toler)->value,
514
+ s_toler = RFLOAT(rb_s_toler)->value,
515
+ v_toler = RFLOAT(rb_v_toler)->value;
516
+ ID id_x = rb_intern("x"), id_y = rb_intern("y"),
517
+ id_get_pix = rb_intern("get_pix");
518
+
519
+ pixbuf = rb_iv_get(self, "@pixbuf");
520
+ x0 = NUM2INT(rb_funcall(self, id_x, 0));
521
+ y0 = NUM2INT(rb_funcall(self, id_y, 0));
522
+ width = NUM2INT(rb_iv_get(pixbuf, "@picture_width"));
523
+ height = NUM2INT(rb_iv_get(pixbuf, "@picture_height"));
524
+ pixels = (unsigned char*) RSTRING(rb_iv_get(pixbuf,"@pixels"))->ptr +
525
+ NUM2INT(rb_iv_get(pixbuf, "@ofs0"));
526
+ rowstride = NUM2INT(rb_funcall(pixbuf, rb_intern("rowstride"), 0));
527
+ pix_len = NUM2INT(rb_iv_get(pixbuf, "@pix_length"));
528
+ pix_ptr = pixels + y0*rowstride + x0*pix_len;
529
+ prb_color_rgb_to_hsv(pix_ptr[0], pix_ptr[1], pix_ptr[2], &h, &s, &v);
530
+ for ( adj = adjs; adj < a_end; adj++ ) {
531
+ x = x0 + NUM2INT(rb_funcall(*adj, id_x, 0));
532
+ y = y0 + NUM2INT(rb_funcall(*adj, id_y, 0));
533
+ if (x >= 0 && x < width && y >= 0 && y <= height) {
534
+ pix_ptr = pixels + y*rowstride + x*pix_len;
535
+ prb_color_rgb_to_hsv(pix_ptr[0], pix_ptr[1], pix_ptr[2],
536
+ &th, &ts, &tv);
537
+ if (fabs(h-th) < h_toler && fabs(s-ts) < s_toler &&
538
+ fabs(v-tv) < v_toler)
539
+ rb_ary_push(res, rb_funcall(pixbuf, id_get_pix, 2,
540
+ INT2NUM(x), INT2NUM(y)));
541
+ }
542
+ }
543
+ return res;
544
+ }
545
+
546
+ VALUE prb_pixbuf_pixels_ptr(VALUE self)
547
+ {
548
+ VALUE glib_ptr;
549
+ unsigned char **pixels;
550
+
551
+ glib_ptr = rb_funcall(self, rb_intern("get_property"), 1,
552
+ rb_str_new2("pixels"));
553
+ Data_Get_Struct(glib_ptr, unsigned char*, pixels);
554
+ return INT2NUM((long) pixels);
555
+ }
556
+
557
+ VALUE prb_pixbuf_pixels(VALUE self)
558
+ {
559
+ return rb_iv_get(self, "@pixels");
560
+ }
561
+
562
+ VALUE prb_pixbuf_sample_length(VALUE self)
563
+ {
564
+ return rb_iv_get(self, "@sample_length");
565
+ }
566
+
567
+ VALUE prb_pixbuf_pix_length(VALUE self)
568
+ {
569
+ return rb_iv_get(self, "@pix_length");
570
+ }
571
+
572
+ VALUE prb_pixbuf_picture_width(VALUE self)
573
+ {
574
+ return rb_iv_get(self, "@picture_width");
575
+ }
576
+
577
+ VALUE prb_pixbuf_picture_height(VALUE self)
578
+ {
579
+ return rb_iv_get(self, "@picture_height");
580
+ }
581
+
582
+ VALUE prb_pixbuf_ofs0(VALUE self)
583
+ {
584
+ return rb_iv_get(self, "@ofs0");
585
+ }
586
+
587
+ VALUE prb_pixbuf_pix_mask(VALUE self)
588
+ {
589
+ return rb_iv_get(self, "@pix_mask");
590
+ }
591
+
592
+ VALUE prb_pixbuf_border_width(VALUE self)
593
+ {
594
+ return rb_iv_get(self, "@border_width");
595
+ }
596
+
597
+ static void prb_pixbuf_do_init(VALUE self)
598
+ {
599
+ VALUE glib_ptr, rb_width, rb_height;
600
+ unsigned char **pixels;
601
+ int width, height, rowstride, n_channels, bits_per_sample,
602
+ sample_len, pix_len, i;
603
+ long pix_mask;
604
+
605
+ glib_ptr = rb_funcall(self, rb_intern("get_property"), 1,
606
+ rb_str_new2("pixels"));
607
+ Data_Get_Struct(glib_ptr, unsigned char*, pixels);
608
+ rb_width = rb_funcall(self, rb_intern("width"), 0);
609
+ width = NUM2INT(rb_width);
610
+ rb_height = rb_funcall(self, rb_intern("height"), 0);
611
+ height = NUM2INT(rb_height);
612
+ rowstride = NUM2INT(rb_funcall(self, rb_intern("rowstride"), 0));
613
+ n_channels = NUM2INT(rb_funcall(self, rb_intern("n_channels"), 0));
614
+ bits_per_sample = NUM2INT(rb_funcall(self, rb_intern("bits_per_sample"),
615
+ 0));
616
+
617
+ if (bits_per_sample % 8)
618
+ rb_raise(rb_eNotImpError, "bits_per_sample = %i",
619
+ bits_per_sample);
620
+ rb_iv_set(self, "@pixels", prb_cstr_new1((char*) pixels, height > 0 ?
621
+ (height-1)*rowstride + width*
622
+ ((n_channels * bits_per_sample + 7)/8) : 0, self));
623
+ rb_iv_set(self,"@sample_length",INT2NUM(sample_len=bits_per_sample>>3));
624
+ rb_iv_set(self, "@pix_length", INT2NUM(pix_len=sample_len*n_channels));
625
+ rb_iv_set(self, "@picture_width", rb_width);
626
+ rb_iv_set(self, "@picture_height", rb_height);
627
+ rb_iv_set(self, "@border_width", INT2NUM(0));
628
+ rb_iv_set(self, "@ofs0", INT2NUM(0));
629
+ pix_mask = 0;
630
+ for ( i = 0; i < pix_len; i++ ) {
631
+ pix_mask = (pix_mask << 8) | 0xff;
632
+ }
633
+ rb_iv_set(self, "@pix_mask", LONG2NUM(pix_mask));
634
+ }
635
+
636
+ VALUE prb_pixbuf_init(int argc, VALUE *argv, VALUE self)
637
+ {
638
+ rb_call_super(argc, argv);
639
+ prb_pixbuf_do_init(self);
640
+ return Qnil;
641
+ }
642
+
643
+ VALUE prb_pixbuf_get_pix(VALUE self, VALUE x, VALUE y)
644
+ {
645
+ return rb_funcall(prb_cPPix_PixbufPix, rb_intern("new"), 3, self, x, y);
646
+ }
647
+
648
+ VALUE prb_pixbuf_dup(VALUE self)
649
+ {
650
+ VALUE res, rb_width, rb_height;
651
+ int height;
652
+
653
+ rb_width = rb_funcall(self, rb_intern("width"), 0);
654
+ rb_height = rb_funcall(self, rb_intern("height"), 0);
655
+ res = rb_funcall(prb_cPPix_Pixbuf, rb_intern("new"), 5,
656
+ rb_funcall(self, rb_intern("colorspace"), 0),
657
+ rb_funcall(self, rb_intern("has_alpha?"), 0),
658
+ rb_funcall(self, rb_intern("bits_per_sample"), 0),
659
+ rb_width, rb_height);
660
+ rb_iv_set(res, "@border_width", rb_iv_get(self, "@border_width"));
661
+ rb_iv_set(res, "@ofs0", rb_iv_get(self, "@ofs0"));
662
+ height = NUM2INT(rb_height);
663
+ memcpy(RSTRING(rb_iv_get(res, "@pixels"))->ptr,
664
+ RSTRING(rb_iv_get(self, "@pixels"))->ptr,
665
+ height > 0 ? (height-1)*NUM2INT(rb_funcall(self,
666
+ rb_intern("rowstride"), 0)) + NUM2INT(rb_width)*NUM2INT(
667
+ rb_iv_get(self, "@pix_length")) : 0);
668
+ return res;
669
+ }
670
+
671
+ VALUE prb_pixbuf_scale(int argc, VALUE *argv, VALUE self)
672
+ {
673
+ VALUE res;
674
+
675
+ res = rb_call_super(argc, argv);
676
+ RBASIC(res)->klass = prb_cPPix_Pixbuf;
677
+ prb_pixbuf_do_init(res);
678
+ return res;
679
+ }
680
+
681
+ VALUE prb_pixbuf_add_border(VALUE self, VALUE rb_b_width)
682
+ {
683
+ int width, height, rowstride, b_width = NUM2INT(rb_b_width),
684
+ row_len, new_rowstride, new_width, new_height, pix_len,
685
+ t_skip, margin_len;
686
+ unsigned char *pixels, *src_pix, *src0;
687
+ VALUE res;
688
+
689
+ if ( b_width < 0 )
690
+ rb_raise(rb_eNotImpError, "Negative width=%i", b_width);
691
+ if ( b_width == 0 )
692
+ return rb_funcall(self, rb_intern("dup"), 0);
693
+ width = NUM2INT(rb_funcall(self, rb_intern("width"), 0));
694
+ height = NUM2INT(rb_funcall(self, rb_intern("height"), 0));
695
+ rowstride = NUM2INT(rb_funcall(self, rb_intern("rowstride"), 0));
696
+ pix_len = NUM2INT(rb_iv_get(self, "@pix_length"));
697
+ new_width = width + 2*b_width;
698
+ new_height = height + 2*b_width;
699
+ res = rb_funcall(self, rb_intern("scale"), 3, INT2NUM(new_width),
700
+ INT2NUM(new_height),
701
+ rb_eval_string("Gdk::Pixbuf::INTERP_TILES"));
702
+ pixels = (unsigned char*) RSTRING(rb_iv_get(res, "@pixels"))->ptr;
703
+ new_rowstride = NUM2INT(rb_funcall(res, rb_intern("rowstride"), 0));
704
+ row_len = pix_len * width;
705
+ margin_len = pix_len * b_width;
706
+ t_skip = new_rowstride - row_len - margin_len;
707
+ memset(pixels, 0, b_width*new_rowstride);
708
+ pixels += (height + b_width)*new_rowstride;
709
+ memset(pixels, 0, (b_width-1)*new_rowstride + new_width*pix_len);
710
+ src0 = (unsigned char*) RSTRING(rb_iv_get(self,"@pixels"))->ptr;
711
+ for ( src_pix = src0 +(height-1)*rowstride; src_pix >= src0;
712
+ src_pix -= rowstride ) {
713
+ pixels -= t_skip;
714
+ memset(pixels, 0, t_skip); pixels -= row_len;
715
+ memmove(pixels, src_pix, row_len); pixels -= margin_len;
716
+ memset(pixels, 0, margin_len);
717
+ }
718
+ rb_iv_set(res, "@ofs0", LONG2NUM(NUM2LONG(rb_iv_get(self, "@ofs0")) +
719
+ b_width*(new_rowstride + pix_len)));
720
+ rb_iv_set(res, "@border_width",INT2NUM(
721
+ NUM2INT(rb_iv_get(self,"@border_width")) + b_width));
722
+ rb_iv_set(res, "@picture_width", rb_iv_get(self, "@picture_width"));
723
+ rb_iv_set(res, "@picture_height", rb_iv_get(self, "@picture_height"));
724
+ return res;
725
+ }
726
+
727
+ /*
728
+ VALUE
729
+ prb_pixbuf_subpixbuf
730
+ (VALUE self, VALUE r_x, VALUE r_y, VALUE r_width, VALUE r_height)
731
+ {
732
+ VALUE res, args, rb_rowstride;
733
+ unsigned char *pixels;
734
+ int rowstride, pix_len, x = NUM2INT(r_x), y = NUM2INT(r_y),
735
+ width = NUM2INT(r_width), height = NUM2INT(r_height),
736
+ self_width, self_height;
737
+
738
+ pixels = RSTRING(rb_iv_get(self,"@pixels"))->ptr;
739
+ self_width = NUM2INT(rb_funcall(self, rb_intern("width"), 0));
740
+ self_height = NUM2INT(rb_funcall(self, rb_intern("height"), 0));
741
+ if ( x >= self_width )
742
+ rb_raise(rb_eArgError, "x(%i) >= width(%i)", x, self_width);
743
+ if ( y >= self_height )
744
+ rb_raise(rb_eArgError, "y(%i) >= height", y, self_height);
745
+ rb_rowstride = rb_funcall(self, rb_intern("rowstride"), 0);
746
+ rowstride = NUM2INT(rb_rowstride);
747
+ pix_len = NUM2INT(rb_iv_get(self, "@pix_length"));
748
+ args = rb_hash_new();
749
+ if ( x + width > self_width )
750
+ width = self_width - x;
751
+ if ( y + height > self_height )
752
+ height = self_height - y;
753
+ rb_hash_aset(args, rb_str_new2("colorspace"), rb_funcall(self,
754
+ rb_intern("colorspace"), 0));
755
+ rb_hash_aset(args, rb_str_new2("has_alpha"), rb_funcall(self,
756
+ rb_intern("has_alpha?"), 0));
757
+ rb_hash_aset(args, rb_str_new2("bits_per_sample"), rb_funcall(self,
758
+ rb_intern("bits_per_sample"), 0));
759
+ rb_hash_aset(args, rb_str_new2("width"), INT2NUM(width));
760
+ rb_hash_aset(args, rb_str_new2("height"), INT2NUM(height));
761
+ rb_hash_aset(args, rb_str_new2("rowstride"), rb_rowstride);
762
+ rb_hash_aset(args, rb_str_new2("pixels"), prb_cstr_new1(pixels +
763
+ y*rowstride + x*pix_len,
764
+ height > 0 ? (height-1)*rowstride + width*pix_len : 0, self));
765
+ res =rb_funcall(rb_eval_string("Gdk::Pixbuf"),rb_intern("new!"),1,args);
766
+ RBASIC(res)->klass = prb_cPPix_Pixbuf;
767
+ prb_pixbuf_do_init(res);
768
+ return res;
769
+ }
770
+ */
771
+
772
+ VALUE
773
+ prb_pixbuf_scaled
774
+ (VALUE self, VALUE r_kx, VALUE r_ky, VALUE r_x, VALUE r_y, VALUE r_width,
775
+ VALUE r_height, VALUE r_interp)
776
+ {
777
+ VALUE res_pb;
778
+
779
+ res_pb = rb_funcall(prb_cPPix_Pixbuf, rb_intern("new"), 5,
780
+ rb_funcall(self, rb_intern("colorspace"),0),
781
+ rb_funcall(self, rb_intern("has_alpha?"), 0),
782
+ rb_funcall(self, rb_intern("bits_per_sample"), 0),
783
+ INT2NUM(NUM2INT(r_width)+1),INT2NUM(NUM2INT(r_height)+1));
784
+ rb_funcall(res_pb, rb_intern("scale!"), 10,self, INT2NUM(0), INT2NUM(0),
785
+ r_width,r_height, rb_float_new(-NUM2INT(r_x)),
786
+ rb_float_new(-NUM2INT(r_y)), r_kx, r_ky, r_interp);
787
+ return res_pb;
788
+ }
789
+
790
+ VALUE
791
+ prb_pixbuf_gdk_scaled
792
+ (VALUE self, VALUE r_kx, VALUE r_ky, VALUE r_x, VALUE r_y, VALUE r_width,
793
+ VALUE r_height, VALUE r_interp)
794
+ {
795
+ VALUE res_pb;
796
+
797
+ res_pb = rb_funcall(rb_eval_string("Gdk::Pixbuf"), rb_intern("new"), 5,
798
+ rb_funcall(self, rb_intern("colorspace"),0),
799
+ rb_funcall(self, rb_intern("has_alpha?"), 0),
800
+ rb_funcall(self, rb_intern("bits_per_sample"), 0),
801
+ INT2NUM(NUM2INT(r_width)+1),INT2NUM(NUM2INT(r_height)+1));
802
+ rb_funcall(res_pb, rb_intern("scale!"), 10,self, INT2NUM(0), INT2NUM(0),
803
+ r_width,r_height, rb_float_new(-NUM2INT(r_x)),
804
+ rb_float_new(-NUM2INT(r_y)), r_kx, r_ky, r_interp);
805
+ return res_pb;
806
+ }