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,144 @@
1
+ /* XPM */
2
+ static char * prev_pressed_xpm[] = {
3
+ "24 24 117 2",
4
+ " c None",
5
+ ". c #777777",
6
+ "+ c #5F5F5F",
7
+ "@ c #7E7E7E",
8
+ "# c #7C7C7C",
9
+ "$ c #757575",
10
+ "% c #616161",
11
+ "& c #575757",
12
+ "* c #696969",
13
+ "= c #898989",
14
+ "- c #565656",
15
+ "; c #838383",
16
+ "> c #626262",
17
+ ", c #686868",
18
+ "' c #9E9E9E",
19
+ ") c #818181",
20
+ "! c #848484",
21
+ "~ c #737373",
22
+ "{ c #6A6A6A",
23
+ "] c #787878",
24
+ "^ c #7D7D7D",
25
+ "/ c #909090",
26
+ "( c #8C8C8C",
27
+ "_ c #878787",
28
+ ": c #646464",
29
+ "< c #6E6E6E",
30
+ "[ c #8A8A8A",
31
+ "} c #868686",
32
+ "| c #9A9A9A",
33
+ "1 c #929292",
34
+ "2 c #808080",
35
+ "3 c #7B7B7B",
36
+ "4 c #7F7F7F",
37
+ "5 c #888888",
38
+ "6 c #9C9C9C",
39
+ "7 c #A3A3A3",
40
+ "8 c #B7B7B7",
41
+ "9 c #7A7A7A",
42
+ "0 c #A0A0A0",
43
+ "a c #A6A6A6",
44
+ "b c #999999",
45
+ "c c #C0C0C0",
46
+ "d c #8F8F8F",
47
+ "e c #767676",
48
+ "f c #B0B0B0",
49
+ "g c #B5B5B5",
50
+ "h c #B8B8B8",
51
+ "i c #939393",
52
+ "j c #B2B2B2",
53
+ "k c #C2C2C2",
54
+ "l c #C8C8C8",
55
+ "m c #B9B9B9",
56
+ "n c #ADADAD",
57
+ "o c #CFCFCF",
58
+ "p c #BBBBBB",
59
+ "q c #6D6D6D",
60
+ "r c #8D8D8D",
61
+ "s c #676767",
62
+ "t c #989898",
63
+ "u c #8E8E8E",
64
+ "v c #797979",
65
+ "w c #AAAAAA",
66
+ "x c #969696",
67
+ "y c #707070",
68
+ "z c #5A5A5A",
69
+ "A c #858585",
70
+ "B c #9F9F9F",
71
+ "C c #585858",
72
+ "D c #363636",
73
+ "E c #0F0F0F",
74
+ "F c #111111",
75
+ "G c #464646",
76
+ "H c #424242",
77
+ "I c #505050",
78
+ "J c #747474",
79
+ "K c #919191",
80
+ "L c #959595",
81
+ "M c #3F3F3F",
82
+ "N c #3A3A3A",
83
+ "O c #5D5D5D",
84
+ "P c #5B5B5B",
85
+ "Q c #949494",
86
+ "R c #535353",
87
+ "S c #2B2B2B",
88
+ "T c #2C2C2C",
89
+ "U c #242424",
90
+ "V c #373737",
91
+ "W c #232323",
92
+ "X c #3B3B3B",
93
+ "Y c #2F2F2F",
94
+ "Z c #252525",
95
+ "` c #343434",
96
+ " . c #1F1F1F",
97
+ ".. c #222222",
98
+ "+. c #606060",
99
+ "@. c #828282",
100
+ "#. c #323232",
101
+ "$. c #6B6B6B",
102
+ "%. c #272727",
103
+ "&. c #5C5C5C",
104
+ "*. c #434343",
105
+ "=. c #656565",
106
+ "-. c #6C6C6C",
107
+ ";. c #666666",
108
+ ">. c #8B8B8B",
109
+ ",. c #A2A2A2",
110
+ "'. c #ABABAB",
111
+ "). c #9B9B9B",
112
+ "!. c #555555",
113
+ "~. c #636363",
114
+ "{. c #979797",
115
+ "]. c #ACACAC",
116
+ "^. c #515151",
117
+ "/. c #525252",
118
+ "(. c #CDCDCD",
119
+ "_. c #A9A9A9",
120
+ ":. c #A8A8A8",
121
+ " . ",
122
+ " + @ # ",
123
+ " $ % & * = ",
124
+ " - % @ ; > , ' ",
125
+ " $ ) ! ~ { . ] ] = ",
126
+ " ^ / ( @ _ ] : < ! [ } ",
127
+ " / | 1 2 3 ; 4 4 ^ @ 5 [ @ ",
128
+ " 4 6 | @ 7 8 9 ) ^ ) @ ; 0 a _ ",
129
+ " ] _ b c d e ! f = @ @ e = g h i 3 ",
130
+ " j k g l m ) d ~ # e j a n c o p } q 3 ",
131
+ " ) r | d 2 s 3 @ 9 t u ^ v b w m f x ; y z ",
132
+ " A B ! C D E F G H I $ J K L ( < M N C O & z P ",
133
+ " Q K R S T U V W X ~ R _ ! A Y Z ` V ...+.u @.",
134
+ " #.H ] ; @ $.z ..s . * %.&.A @ 9 s *.N P @ ",
135
+ " [ } J A @.C R ^ q & 4 y ; ; y : =.< 9 ",
136
+ " = ; } } -.{ ;.9 ! ) @ @ u 1 y : ; ",
137
+ " ~ } >.1 ] @ ) } ] ! K A 4 ! 2 ",
138
+ " ,.= '.).2 2 [ d ; @ u x [ ",
139
+ " d / !.~.J . 3 {.].t ] ",
140
+ " 3 I ^./.v p (._.u ",
141
+ " :./ >.B ).; # ",
142
+ " ( e . @.r ",
143
+ " -.e e ",
144
+ " "};
@@ -0,0 +1,29 @@
1
+ /* XPM */
2
+ static char * vnext_xpm[] = {
3
+ "24 24 2 1",
4
+ " c None",
5
+ ". c #000000",
6
+ " .......................",
7
+ " ...................... ",
8
+ " ...................... ",
9
+ " .................... ",
10
+ " .................... ",
11
+ " .................. ",
12
+ " .................. ",
13
+ " ................ ",
14
+ " ................ ",
15
+ " .............. ",
16
+ " .............. ",
17
+ " ............ ",
18
+ " ............ ",
19
+ " .......... ",
20
+ " .......... ",
21
+ " ........ ",
22
+ " ........ ",
23
+ " ...... ",
24
+ " ...... ",
25
+ " .... ",
26
+ " .... ",
27
+ " .. ",
28
+ " .. ",
29
+ " "};
@@ -0,0 +1,29 @@
1
+ /* XPM */
2
+ static char * vprev_xpm[] = {
3
+ "24 24 2 1",
4
+ " c None",
5
+ ". c #000000",
6
+ " ",
7
+ " .. ",
8
+ " .. ",
9
+ " .... ",
10
+ " .... ",
11
+ " ...... ",
12
+ " ...... ",
13
+ " ........ ",
14
+ " ........ ",
15
+ " .......... ",
16
+ " .......... ",
17
+ " ............ ",
18
+ " ............ ",
19
+ " .............. ",
20
+ " .............. ",
21
+ " ................ ",
22
+ " ................ ",
23
+ " .................. ",
24
+ " .................. ",
25
+ " .................... ",
26
+ " .................... ",
27
+ " ...................... ",
28
+ " ...................... ",
29
+ " ......................."};
@@ -0,0 +1,2 @@
1
+ /ext.rb/1.1.1.1/Tue Nov 15 17:32:40 2005//
2
+ D
@@ -0,0 +1 @@
1
+ extract-curves/ruby_libs/pav/numeric
@@ -0,0 +1 @@
1
+ :ext:pavpen@rubyforge.org:/var/cvs/extract-curves
@@ -0,0 +1,13 @@
1
+ class Numeric
2
+ def scaled_floor(toler)
3
+ (sc = self / toler).finite? ? sc.floor * toler : self
4
+ end
5
+
6
+ def scaled_ceil(toler)
7
+ (sc = self / toler).finite? ? sc.ceil * toler : self
8
+ end
9
+
10
+ def scaled_round(toler)
11
+ (sc = self / toler).finite? ? sc.round * toler : self
12
+ end
13
+ end
@@ -0,0 +1,90 @@
1
+ # From Ruby's Find module:
2
+ module PavFind
3
+ def self.pfind_follow_symlinks(paths)
4
+ paths = paths.collect{|d| d.dup}
5
+ while file = paths.shift
6
+ catch(:prune) do
7
+ next unless File.exist? file
8
+ yield file.dup.taint
9
+ begin
10
+ if File.directory?(file) then
11
+ d = Dir.open(file)
12
+ begin
13
+ for f in d
14
+ next if f == "." or f == ".."
15
+ if File::ALT_SEPARATOR and
16
+ file =~ /^(?:[\/\\]|[A-Za-z]:[\/\\]?)$/ then
17
+ f = file + f
18
+ elsif file == "/" then
19
+ f = "/" + f
20
+ else
21
+ f = File.join(file, f)
22
+ end
23
+ paths.unshift f.untaint
24
+ end
25
+ ensure
26
+ d.close
27
+ end
28
+ end
29
+ rescue Errno::ENOENT, Errno::EACCES
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ def self.pfind_no_follow_symlinks(paths)
36
+ paths = paths.collect{|d| d.dup}
37
+ while file = paths.shift
38
+ catch(:prune) do
39
+ next unless File.exist? file
40
+ yield file.dup.taint
41
+ begin
42
+ if File.lstat(file).directory? then
43
+ d = Dir.open(file)
44
+ begin
45
+ for f in d
46
+ next if f == "." or f == ".."
47
+ if File::ALT_SEPARATOR and
48
+ file =~ /^(?:[\/\\]|[A-Za-z]:[\/\\]?)$/ then
49
+ f = file + f
50
+ elsif file == "/" then
51
+ f = "/" + f
52
+ else
53
+ f = File.join(file, f)
54
+ end
55
+ paths.unshift f.untaint
56
+ end
57
+ ensure
58
+ d.close
59
+ end
60
+ end
61
+ rescue Errno::ENOENT, Errno::EACCES
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ def self.pfind(paths, follow_symlinks=true, entry_visit_once=true, &block)
68
+ if follow_symlinks
69
+ if entry_visit_once
70
+ visited = {}
71
+ self.pfind_follow_symlinks(paths) { |path|
72
+ if visited.include?(path)
73
+ self.prune
74
+ else
75
+ yield(path)
76
+ visited[path] = true
77
+ end
78
+ }
79
+ else
80
+ self.pfind_follow_symlinks(paths, &block)
81
+ end
82
+ else
83
+ self.pfind_no_follow_symlinks(paths, &block)
84
+ end
85
+ end
86
+
87
+ def self.prune
88
+ throw :prune
89
+ end
90
+ end
@@ -0,0 +1,402 @@
1
+ require 'gtk2'
2
+ require 'sync'
3
+ require 'observer'
4
+ require 'pav/sub_arr'
5
+ require 'pav/attr_cache'
6
+ require 'pav/string/ext'
7
+
8
+ begin
9
+ require 'pav/pav'
10
+ rescue LoadError
11
+
12
+ module PPix
13
+
14
+ class Xy
15
+ attr_accessor :x, :y
16
+
17
+ def initialize(x, y)
18
+ @x = x
19
+ @y = y
20
+ end
21
+
22
+ def coords_to_s
23
+ "(#{@x}, #{@y})"
24
+ end
25
+ end
26
+
27
+ class Xy
28
+ ADJACENT4 = [Xy.new(1, 0), Xy.new(0, 1), Xy.new(-1, 0), Xy.new(0, -1)]
29
+ ADJACENT8 = ADJACENT4 + [Xy.new(1,1), Xy.new(-1,1),
30
+ Xy.new(-1,-1), Xy.new(1, -1)]
31
+ end
32
+
33
+ class PixbufPix < Xy
34
+ include AttrCache
35
+
36
+ attr_reader :pixbuf, :x, :y, :color_id, :yx
37
+
38
+ def self.rgb_to_hsv(r, g, b)
39
+ # From the colorsys module of Python 2.4:
40
+ maxc = [r, g, b].max
41
+ minc = [r, g, b].min
42
+ v = maxc
43
+ return [0.0, 0.0, v] if minc == maxc
44
+ s = (maxc-minc) / maxc
45
+ rc = (maxc-r) / (maxc-minc)
46
+ gc = (maxc-g) / (maxc-minc)
47
+ bc = (maxc-b) / (maxc-minc)
48
+ if r == maxc then h = bc-gc
49
+ elsif g == maxc then h = 2.0+rc-bc
50
+ else h = 4.0+gc-rc; end
51
+ h = (h/6.0) % 1.0
52
+ [h, s, v]
53
+ end
54
+
55
+ def initialize(pixbuf, x, y)
56
+ @pixbuf = pixbuf
57
+ @x = x
58
+ @y = y
59
+ @yx = [y, x]
60
+ #@pixbuf.add_observer(PixbufObserver.new(self))
61
+ end
62
+
63
+ def color_id
64
+ #$PDbgLog.sig_call(self); c =
65
+ @pixbuf.pixels[@pixbuf.ofs0 + @y*@pixbuf.rowstride +
66
+ @x*@pixbuf.pix_length, @pixbuf.pix_length]
67
+ #$PDbgLog.sig_return("#{self.coords_to_s}: #{c.unpack("H*")}")
68
+ #c
69
+ end
70
+
71
+ def color_rgb
72
+ #$PDbgLog.sig_call(self)
73
+ cid = self.color_id; clen = @pixbuf.sample_length
74
+ #res =
75
+ [cid[0,clen].bits_to_i, cid[clen, clen].bits_to_i,
76
+ cid[2*clen, clen].bits_to_i]
77
+ #$PDbgLog.sig_return("color_id=#{cid.inspect}: #{res.inspect}")
78
+ #res
79
+ end
80
+
81
+ def color_hsv
82
+ r, g, b = *self.color_rgb
83
+ c_max = Float((1 << @pixbuf.bits_per_sample) - 1)
84
+ PixbufPix.rgb_to_hsv(r/c_max, g/c_max, b/c_max)
85
+ end
86
+
87
+ def virtual?
88
+ @x < 0 || @x >= @pixbuf.picture_width || @y < 0 ||
89
+ @y >= @pixbuf.picture_height
90
+ end
91
+
92
+ def border?(adjacents = ADJACENT8)
93
+ clr = self.color_id
94
+ for adj in adjacents
95
+ x, y = @x + adj.x, @y + adj.y
96
+ return true if x < 0 || x >= @pixbuf.picture_width ||
97
+ y < 0 || y >= @pixbuf.picture_height
98
+ return true if @pixbuf.get_pix(x, y).color_id != clr
99
+ end
100
+ false
101
+ end
102
+
103
+ def border8?
104
+ self.border?
105
+ end
106
+
107
+ def border4?
108
+ self.border?(ADJACENT4)
109
+ end
110
+
111
+ def adj(adjacents = ADJACENT8)
112
+ res = []
113
+ for adj in adjacents
114
+ if (x=@x+adj.x) >= 0 && x < @pixbuf.picture_width &&
115
+ (y=@y+adj.y) >= 0 && y < @pixbuf.picture_height
116
+ res << @pixbuf[y][x]
117
+ end
118
+ end
119
+ res
120
+ end
121
+
122
+ def adj8
123
+ self.adj
124
+ end
125
+
126
+ def adj4
127
+ self.adj(ADJACENT4)
128
+ end
129
+
130
+ def adj_cocolor(adjacents = ADJACENT8)
131
+ clr = self.color_id
132
+ res = []
133
+ adjacents.each { |adj| x, y = @x + adj.x, @y + adj.y
134
+ if x >= 0 && x < @pixbuf.picture_width && y >= 0 &&
135
+ y < @pixbuf.picture_height
136
+ pix = @pixbuf.get_pix(x, y)
137
+ res << pix if pix.color_id == clr
138
+ end
139
+ }
140
+ res
141
+ end
142
+
143
+ def adj_cocolor8
144
+ self.adj_cocolor
145
+ end
146
+
147
+ def adj_cocolor4
148
+ self.adj_cocolor(ADJACENT4)
149
+ end
150
+
151
+ def adj_fuzzy_rgb_cocolor(adjacents=ADJACENT8, r_toler=10, g_toler=10,
152
+ b_toler=10)
153
+ r, g, b = *self.color_rgb
154
+ w = @pixbuf.picture_width; h = @pixbuf.picture_height
155
+ res = []
156
+ adjacents.each { |adj| x = @x + adj.x; y = @y + adj.y
157
+ if x >= 0 && x < w && y >= 0 && y < h
158
+ ra, ga, ba = *(apix = @pixbuf.get_pix(x,y)).color_rgb
159
+ res << apix if (ra - r).abs <= r_toler &&
160
+ (ga - g).abs <= g_toler &&
161
+ (ba - b).abs <= b_toler
162
+ end
163
+ }
164
+ res
165
+ end
166
+
167
+ def adj_fuzzy_hsv_cocolor(adjacents=ADJACENT8, h_toler=0.1, s_toler=0.1,
168
+ v_toler=0.1)
169
+ h, s, v = *self.color_hsv
170
+ w = @pixbuf.picture_width; hgt = @pixbuf.picture_height
171
+ res = []
172
+ adjacents.each { |adj| x = @x + adj.x; y = @y + adj.y
173
+ if x >= 0 && x < w && y >= 0 && y < hgt
174
+ ha, sa, va = *(apix = @pixbuf.get_pix(x,y)).color_hsv
175
+ res << apix if (ha - h).abs <= h_toler &&
176
+ (sa - s).abs <= s_toler &&
177
+ (va - v).abs <= v_toler
178
+ end
179
+ }
180
+ res
181
+ end
182
+
183
+ #cache_attr! :color_id, :color_rgb
184
+ #freeze_cache_attr! :border8?, :border4?, :adj8, :adj4, :adj_cocolor8,
185
+ # :adj_cocolor4, :adj_border_cocolor8_4, :color_hsv
186
+
187
+ def color_id=(val)
188
+ @pixbuf.set_pix(@x, @y, val)
189
+ end
190
+
191
+ def hash
192
+ #@x.hash + @y.hash + @pixbuf.hash
193
+ #self.yx.hash
194
+ @y * @pixbuf.width + @x
195
+ end
196
+ end
197
+
198
+ class Pixbuf #< Gdk::Pixbuf
199
+ #include Sync_m
200
+
201
+ attr_accessor :border_width, :ofs0, :picture_width, :picture_height
202
+ attr_reader :pix_length, :sample_length
203
+
204
+ def initialize(*args)
205
+ unless args.length==1 && (@under=args[0]).kind_of?(Gdk::Pixbuf)
206
+ @under = Gdk::Pixbuf.new(*args)
207
+ end
208
+ @virtual_pix = {}
209
+ @sample_length = self.bits_per_sample / 8
210
+ @pix_length = self.n_channels * @sample_length
211
+ @picture_width = self.width
212
+ @picture_height = self.height
213
+ @border_width = 0
214
+ @ofs0 = 0
215
+ end
216
+
217
+ def method_missing(id, *args, &block)
218
+ @under.send(id, *args, &block)
219
+ end
220
+
221
+ def get_pix(x, y)
222
+ if x < 0 || y < 0 || x >= @picture_width || y >= @picture_height
223
+ tmp = @virtual_pix[[y, x]]
224
+ return tmp if tmp
225
+ return (@virtual_pix[[y, x]] = PixbufPix.new(self,x,y))
226
+ end
227
+ end
228
+
229
+ def set_pix(x, y, clr)
230
+ if x < 0
231
+ if x < -self.width
232
+ return nil
233
+ else x = self.width+x end
234
+ else
235
+ if x >= self.width
236
+ return nil
237
+ end
238
+ end
239
+ if y < 0
240
+ if y < -self.height
241
+ return nil
242
+ else y = self.height+y end
243
+ else
244
+ if y >= self.height
245
+ return nil
246
+ end
247
+ end
248
+ ofs = y*@rowstride + x*@pix_length
249
+ self.synchronize {
250
+ self.changed( c = (@pixels[ofs,@pix_length]==
251
+ (@pixels[ofs,@pix_length]=clr)) )
252
+ if c
253
+ self.notify_observers(self, "set_pix",[x,y,clr],nil)
254
+ pix.update(self, "set_pix",[x,y,clr],nil) if
255
+ @scanlines[y] && (pix = @scanlines[y].pixels[x])
256
+ end
257
+ }
258
+ end
259
+
260
+ def dup
261
+ Pixbuf.new(@pixels.dup, @width, @height, @n_channels,
262
+ @rowstride)
263
+ end
264
+
265
+ def add_border(width)
266
+ res_pb = Gdk::Pixbuf.new(self.colorspace, self.has_alpha?,
267
+ self.bits_per_sample, self.width+2*width,
268
+ self.height+2*width)
269
+ res_pb.scale!(@under, width, width,
270
+ self.width+width, self.height+width, width, width,
271
+ 1, 1, Gdk::Pixbuf::INTERP_NEAREST)
272
+ res_pb = Pixbuf.new(res_pb)
273
+ res_pb.picture_width = self.picture_width
274
+ res_pb.picture_height = self.picture_height
275
+ res_pb.border_width = self.border_width + width
276
+ res_pb
277
+ end
278
+
279
+ def scaled(kx, ky, x, y, width, height)
280
+ res_pb = Gdk::Pixbuf.new(self.colorspace, self.has_alpha?,
281
+ self.bits_per_sample, width, height)
282
+ res_pb.scale!(@under, 0, 0, width, height, -x, -y, kx, ky,
283
+ Gdk::Pixbuf::INTERP_NEAREST)
284
+ res_pb
285
+ end
286
+
287
+ def dup
288
+ res = Pixbuf.new(@under.dup)
289
+ res.picture_width = self.picture_width
290
+ res.picture_height = self.picture_height
291
+ res.ofs0 = self.ofs0
292
+ res.border_width = self.border_width
293
+ res
294
+ end
295
+
296
+ def <=>(other)
297
+ return leg if (leg = @width <=> other.width) != 0
298
+ return leg if (leg = @height <=> other.height) != 0
299
+ return leg if (leg = @pix_length <=> other.pix_length) != 0
300
+ self.object_id <=> other.object_id
301
+ #@pixels <=> other.pixels
302
+ end
303
+
304
+ #cache_attr! :pixels
305
+ end
306
+
307
+ end # module PPix
308
+
309
+ end # require 'pav/pav'
310
+
311
+ module PPix
312
+
313
+ class Xy
314
+ include Comparable
315
+
316
+ ADJ8_CCW_ORDER = [Xy.new(1,-1), Xy.new(0,-1), Xy.new(-1,-1),
317
+ Xy.new(-1,0), Xy.new(-1,1), Xy.new(0,1), Xy.new(1,1), Xy.new(1,0)]
318
+
319
+ ADJ4_CCW_ORDER = (0...4).collect {|i| ADJ8_CCW_ORDER[2*i+1] }
320
+
321
+ def neighb8?(pix)
322
+ dx = (self.x - pix.x).abs; dy = (self.y - pix.y).abs
323
+ dx < 2 && dy < 2
324
+ end
325
+
326
+ def neighb4?(pix)
327
+ dx = (self.x - pix.x).abs; dy = (self.y - pix.y).abs
328
+ (dx < 2 && dy == 0) || (dy < 2 && dx == 0)
329
+ end
330
+
331
+ def self.path_to_s(path)
332
+ path.collect { |xy| xy.coords_to_s }.join(' ')
333
+ end
334
+
335
+ def <=>(other)
336
+ self.yx <=> other.yx
337
+ end
338
+
339
+ def hash
340
+ self.yx.hash
341
+ end
342
+
343
+ def eql?(xy)
344
+ self.yx == xy.yx
345
+ end
346
+ end
347
+
348
+ module MPixbufPix
349
+ def adj_border_cocolor(adjacents = ADJACENT8, border_adj = ADJACENT4)
350
+ self.adj(adjacents).find_all { |pix| pix.border?(border_adj) }
351
+ end
352
+
353
+ def adj_border_cocolor8_4
354
+ self.adj_border_cocolor
355
+ end
356
+
357
+ def adj_border_cocolor4_8
358
+ self.adj_border_cocolor(ADJACENT4, ADJACENT8)
359
+ end
360
+
361
+ def end_pt_excl_yx_set?(excl_set)
362
+ self.adj8.find_all { |pix| !excl_set.include?(pix.yx) }.length<2
363
+ end
364
+
365
+ def end_pt_incl_set?(incl_set)
366
+ self.adj8.find_all { |pix| incl_set.include?(pix) }.length < 2
367
+ end
368
+
369
+ #def to_s
370
+ # self.class.name + self.coords_to_s
371
+ #end
372
+ end
373
+
374
+ class Xy
375
+ def adj8_get_i(adj)
376
+ x = adj.x - self.x; y = adj.y - self.y
377
+ Xy::ADJ8_CCW_ORDER.each_with_index{ |a,i|
378
+ return i if a.y == y && a.x == x }
379
+ nil
380
+ end
381
+
382
+ def self.adj8_xy_id(dx, dy)
383
+ ((dy + 1) << 2) | (dx + 1)
384
+ end
385
+
386
+ tmp1 = []
387
+ ADJ8_CCW_ORDER.each_with_index { |a,i| tmp1[self.adj8_xy_id(a.x,a.y)] =
388
+ [a, i, 1<<i] }
389
+ tmp1[self.adj8_xy_id(0,0)] = [nil, 8, 0]
390
+ ADJ8_ID2SPEC = tmp1
391
+
392
+ def adj8_situation_id(neighbs)
393
+ res = 0
394
+ for ngb in neighbs
395
+ res |= Xy::ADJ8_ID2SPEC.at(PixbufPix.adj8_xy_id(
396
+ ngb.x - self.x, ngb.y - self.y)).at(2)
397
+ end
398
+ res
399
+ end
400
+ end
401
+
402
+ end