extract_curves 0.0.1-i586-linux

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.
Files changed (99) 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/extconf.rb +22 -0
  18. data/ruby_ext/pav/pav.so +0 -0
  19. data/ruby_libs/CVS/Entries +1 -0
  20. data/ruby_libs/CVS/Repository +1 -0
  21. data/ruby_libs/CVS/Root +1 -0
  22. data/ruby_libs/pav/CVS/Entries +20 -0
  23. data/ruby_libs/pav/CVS/Repository +1 -0
  24. data/ruby_libs/pav/CVS/Root +1 -0
  25. data/ruby_libs/pav/attr_cache.rb +211 -0
  26. data/ruby_libs/pav/attr_cache.t1.rb +32 -0
  27. data/ruby_libs/pav/cache.rb +31 -0
  28. data/ruby_libs/pav/dbg_log.rb +458 -0
  29. data/ruby_libs/pav/floatsio.rb +53 -0
  30. data/ruby_libs/pav/generator_cache.rb +165 -0
  31. data/ruby_libs/pav/gtk/CVS/Entries +4 -0
  32. data/ruby_libs/pav/gtk/CVS/Repository +1 -0
  33. data/ruby_libs/pav/gtk/CVS/Root +1 -0
  34. data/ruby_libs/pav/gtk/button.rb +130 -0
  35. data/ruby_libs/pav/gtk/icons.rb +87 -0
  36. data/ruby_libs/pav/gtk/toolbar.rb +192 -0
  37. data/ruby_libs/pav/heap.rb +54 -0
  38. data/ruby_libs/pav/icons/CVS/Entries +17 -0
  39. data/ruby_libs/pav/icons/CVS/Repository +1 -0
  40. data/ruby_libs/pav/icons/CVS/Root +1 -0
  41. data/ruby_libs/pav/icons/alt_handle.xpm +3832 -0
  42. data/ruby_libs/pav/icons/alt_handle_hover.xpm +3368 -0
  43. data/ruby_libs/pav/icons/alt_handle_pressed.xpm +3828 -0
  44. data/ruby_libs/pav/icons/extract_curves/CVS/Entries +6 -0
  45. data/ruby_libs/pav/icons/extract_curves/CVS/Repository +1 -0
  46. data/ruby_libs/pav/icons/extract_curves/CVS/Root +1 -0
  47. data/ruby_libs/pav/icons/extract_curves/extract_curves-icon-rgb.ppm +14 -0
  48. data/ruby_libs/pav/icons/extract_curves/extract_curves-logo-rgb.gif +0 -0
  49. data/ruby_libs/pav/icons/extract_curves/trace_mark.xpm +38 -0
  50. data/ruby_libs/pav/icons/handle.xpm +213 -0
  51. data/ruby_libs/pav/icons/next.xpm +29 -0
  52. data/ruby_libs/pav/icons/next_hover.xpm +315 -0
  53. data/ruby_libs/pav/icons/next_pressed.xpm +144 -0
  54. data/ruby_libs/pav/icons/prev.xpm +29 -0
  55. data/ruby_libs/pav/icons/prev_hover.xpm +315 -0
  56. data/ruby_libs/pav/icons/prev_pressed.xpm +144 -0
  57. data/ruby_libs/pav/icons/vnext.xpm +29 -0
  58. data/ruby_libs/pav/icons/vprev.xpm +29 -0
  59. data/ruby_libs/pav/numeric/CVS/Entries +2 -0
  60. data/ruby_libs/pav/numeric/CVS/Repository +1 -0
  61. data/ruby_libs/pav/numeric/CVS/Root +1 -0
  62. data/ruby_libs/pav/numeric/ext.rb +13 -0
  63. data/ruby_libs/pav/pav_find.rb +90 -0
  64. data/ruby_libs/pav/pix/CVS/Entries +11 -0
  65. data/ruby_libs/pav/pix/CVS/Repository +1 -0
  66. data/ruby_libs/pav/pix/CVS/Root +1 -0
  67. data/ruby_libs/pav/pix/aapix.rb +378 -0
  68. data/ruby_libs/pav/pix/blob.rb +543 -0
  69. data/ruby_libs/pav/pix/circle.rb +73 -0
  70. data/ruby_libs/pav/pix/contour/CVS/Entries +5 -0
  71. data/ruby_libs/pav/pix/contour/CVS/Repository +1 -0
  72. data/ruby_libs/pav/pix/contour/CVS/Root +1 -0
  73. data/ruby_libs/pav/pix/contour/calc_situations.rb +9 -0
  74. data/ruby_libs/pav/pix/contour/carp_calc.rb +212 -0
  75. data/ruby_libs/pav/pix/contour/situations.dmp +0 -0
  76. data/ruby_libs/pav/pix/contour/situations.rb +21 -0
  77. data/ruby_libs/pav/pix/contour.rb +644 -0
  78. data/ruby_libs/pav/pix/curve.rb +1508 -0
  79. data/ruby_libs/pav/pix/img_obj.rb +751 -0
  80. data/ruby_libs/pav/pix/node.rb +712 -0
  81. data/ruby_libs/pav/pix/node_grp.rb +853 -0
  82. data/ruby_libs/pav/pix/shaved_core.rb +534 -0
  83. data/ruby_libs/pav/pix/subpix.rb +212 -0
  84. data/ruby_libs/pav/pix.rb +402 -0
  85. data/ruby_libs/pav/rand_accessible.rb +16 -0
  86. data/ruby_libs/pav/rangeset.rb +63 -0
  87. data/ruby_libs/pav/search.rb +210 -0
  88. data/ruby_libs/pav/set.rb +20 -0
  89. data/ruby_libs/pav/string/CVS/Entries +6 -0
  90. data/ruby_libs/pav/string/CVS/Repository +1 -0
  91. data/ruby_libs/pav/string/CVS/Root +1 -0
  92. data/ruby_libs/pav/string/bits.rb +523 -0
  93. data/ruby_libs/pav/string/ext.rb +58 -0
  94. data/ruby_libs/pav/string/observable.rb +155 -0
  95. data/ruby_libs/pav/string/text.rb +79 -0
  96. data/ruby_libs/pav/string/words.rb +42 -0
  97. data/ruby_libs/pav/sub_arr.rb +55 -0
  98. data/ruby_libs/pav/traced_obj.rb +79 -0
  99. metadata +147 -0
@@ -0,0 +1,212 @@
1
+ require 'pav/pix'
2
+
3
+ module PPix
4
+
5
+ class PixbufPix
6
+ def subpix8(sub_n)
7
+ @subpix8 = [] unless @subpix8
8
+ tmp = @subpix8[sub_n]
9
+ return tmp if tmp
10
+ @subpix8[sub_n] = Subpix8.new(self, sub_n)
11
+ end
12
+
13
+ def subpix4(sub_n)
14
+ @subpix4 = [] unless @subpix4
15
+ tmp = @subpix4[sub_n]
16
+ return tmp if tmp
17
+ @subpix4[sub_n] = Subpix4.new(self, sub_n)
18
+ end
19
+ end
20
+
21
+ class SubXy < Xy
22
+ attr_accessor :sub_n
23
+
24
+ def initialize(x, y, sub_n)
25
+ super(x, y)
26
+ @sub_n = sub_n
27
+ end
28
+
29
+ def yxn
30
+ self.yx + [@sub_n]
31
+ end
32
+
33
+ def to_s
34
+ "(#{self.x}, #{self.y}, sub=#{@sub_n})"
35
+ end
36
+
37
+ def inspect
38
+ idmem = self.object_id & ( (1 << (8*self.object_id.size)) - 1 )
39
+ "<#{self.class.name}:0x%x: " % idmem + self.to_s + ">"
40
+ end
41
+
42
+ def <=>(subxy)
43
+ self.yxn <=> subxy.yxn
44
+ end
45
+
46
+ def eql?(subxy)
47
+ subxy && self.y == subxy.y && self.x == subxy.x &&
48
+ self.sub_n == subxy.sub_n
49
+ end
50
+ end
51
+
52
+ class Subpix < SubXy
53
+ attr_reader :img_pix
54
+
55
+ def self.mk_sub_n_neighbs(adj_subpix_order)
56
+ subpix_cnt = 2*adj_subpix_order.length
57
+ ofs1 = adj_subpix_order.length - 2
58
+ ofs2 = adj_subpix_order.length + 2
59
+ (0...subpix_cnt).collect { |n|
60
+ res = [ SubXy.new(0, 0, (n-1) % subpix_cnt),
61
+ SubXy.new(0, 0, (n+1) % subpix_cnt)]
62
+ if (n & 1) == 0
63
+ a1 = adj_subpix_order[n/2 - 1]
64
+ a2 = adj_subpix_order[n/2]
65
+ res[1,0]=[SubXy.new(a1.x,a1.y,(n+ofs1) % subpix_cnt)]
66
+ res << SubXy.new(a2.x,a2.y,(n+ofs2) % subpix_cnt)
67
+ else
68
+ a1_2 = adj_subpix_order[n/2]
69
+ res[1,0] = [SubXy.new(a1_2.x, a1_2.y,
70
+ (n + adj_subpix_order.length) % subpix_cnt)]
71
+ end
72
+ res
73
+ } << (0...subpix_cnt).collect { |n| SubXy.new(0, 0, n) }
74
+ end
75
+
76
+ def self.path_to_s(path)
77
+ path.collect { |subpix| subpix.to_s }.join(" ")
78
+ end
79
+
80
+ def initialize(img_pix, sub_n)
81
+ @img_pix = img_pix
82
+ super(@img_pix.x, @img_pix.y, sub_n)
83
+ end
84
+
85
+ def adj
86
+ self.neighbs.find_all { |ngb|
87
+ ngb.img_pix.x >= 0 &&
88
+ ngb.img_pix.x < ngb.img_pix.pixbuf.picture_width &&
89
+ ngb.img_pix.y >= 0 &&
90
+ ngb.img_pix.y < ngb.img_pix.pixbuf.picture_height
91
+ }
92
+ end
93
+
94
+ cache_attr! :adj
95
+ end
96
+
97
+ class Subpix8 < Subpix
98
+ SUB_N_NEIGHBS = Subpix.mk_sub_n_neighbs(Xy::ADJ8_CCW_ORDER)
99
+ SUB_N_BORDER = SUB_N_NEIGHBS
100
+
101
+ def neighbs
102
+ SUB_N_NEIGHBS[@sub_n].collect { |ngb_spec|
103
+ @img_pix.pixbuf.get_pix(@img_pix.x + ngb_spec.dx,
104
+ @img_pix.y + ngb_spec.dy).
105
+ subpix8(ngb_spec.sub_n)
106
+ }
107
+ end
108
+
109
+ def neighbs_into(res=[])
110
+ res.clear
111
+ SUB_N_NEIGHBS[@sub_n].each { |ngb_spec|
112
+ res << @img_pix.pixbuf.get_pix(@img_pix.x + ngb_spec.dx,
113
+ @img_pix.y+ngb_spec.dy).subpix8(ngb_spec.sub_n)
114
+ }
115
+ res
116
+ end
117
+
118
+ alias_method :border, :neighbs
119
+ alias_method :border_into, :neighbs_into
120
+
121
+ def self.vertical?(sub_n)
122
+ [7, 15].include?(sub_n)
123
+ end
124
+
125
+ def self.horizontal?(sub_n)
126
+ [3, 11].include?(sub_n)
127
+ end
128
+
129
+ def vertical?
130
+ [7, 15].include?(@sub_n)
131
+ end
132
+
133
+ def horizontal?
134
+ [3, 11].include?(@sub_n)
135
+ end
136
+
137
+ def to_s
138
+ "(#{self.x}, #{self.y}, sub8=#{self.sub_n})"
139
+ end
140
+
141
+ cache_attr! :neighbs, :border
142
+ end
143
+
144
+ class Subpix4 < Subpix
145
+ SUB_N_NEIGHBS = Subpix.mk_sub_n_neighbs(PixbufPix::ADJ4_CCW_ORDER)
146
+ SUB_N_BORDER = (0...8).collect { |i|
147
+ res = SUB_N_NEIGHBS[i]
148
+ if i & 1 == 0
149
+ a = PixbufPix::ADJ8_CCW_ORDER[i]
150
+ res += [SubXy.new(a.x, a.y, (i+4) % 8)]
151
+ end
152
+ res
153
+ } << SUB_N_NEIGHBS.last
154
+
155
+ def neighbs
156
+ SUB_N_NEIGHBS[@sub_n].collect { |ngb_spec|
157
+ @img_pix.pixbuf.get_pix(@img_pix.x + ngb_spec.dx,
158
+ @img_pix.y + ngb_spec.dy).
159
+ subpix4(ngb_spec.sub_n)
160
+ }
161
+ end
162
+
163
+ def border
164
+ SUB_N_BORDER[@sub_n].collect { |ngb_spec|
165
+ @img_pix.pixbuf.get_pix(@img_pix.x + ngb_spec.dx,
166
+ @img_pix.y + ngb_spec.dy).
167
+ subpix4(ngb_spec.sub_n)
168
+ }
169
+ end
170
+
171
+ def neighbs_into(res=[])
172
+ res.clear
173
+ SUB_N_NEIGHBS[@sub_n].each { |ngb_spec|
174
+ res << @img_pix.pixbuf.get_pix(@img_pix.x + ngb_spec.dx,
175
+ @img_pix.y+ngb_spec.dy).subpix4(ngb_spec.sub_n)
176
+ }
177
+ res
178
+ end
179
+
180
+ def border_into(res=[])
181
+ res.clear
182
+ SUB_N_BORDER[@sub_n].each { |ngb_spec|
183
+ res << @img_pix.pixbuf.get_pix(@img_pix.x + ngb_spec.dx,
184
+ @img_pix.y+ngb_spec.dy).subpix4(ngb_spec.sub_n)
185
+ }
186
+ res
187
+ end
188
+
189
+ def self.vertical?(sub_n)
190
+ [3, 7].include?(sub_n)
191
+ end
192
+
193
+ def self.horizontal?(sub_n)
194
+ [1, 5].include?(sub_n)
195
+ end
196
+
197
+ def vertical?
198
+ [3, 7].include?(@sub_n)
199
+ end
200
+
201
+ def horizontal?
202
+ [1, 5].include?(@sub_n)
203
+ end
204
+
205
+ def to_s
206
+ "(#{self.x}, #{self.y}, sub4=#{self.sub_n})"
207
+ end
208
+
209
+ cache_attr! :neighbs, :border
210
+ end
211
+
212
+ 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
@@ -0,0 +1,16 @@
1
+ module RandomlyReadable
2
+
3
+ def [](i, len=nil)
4
+ if len
5
+ is = i...i+len
6
+ else
7
+ if i.kind_of?(Integer)
8
+ return at(i)
9
+ else
10
+ is = i
11
+ end
12
+ end
13
+ is.collect { |i| at(i) }
14
+ end
15
+
16
+ end
@@ -0,0 +1,63 @@
1
+ require 'pav/search'
2
+
3
+ class RangeSet
4
+ attr_accessor :ranges
5
+
6
+ def initialize
7
+ @ranges = []
8
+ @cmp_proc = proc { |range, n| range[0] <=> n }
9
+ end
10
+
11
+ def extend_range_to(range_i, end_n)
12
+ j = range_i
13
+ j += 1 while j+1 < @ranges.length && @ranges[j+1][0] <= end_n
14
+ end_n = @ranges[j][1] if @ranges[j][1] > end_n
15
+ @ranges[range_i][1] = end_n
16
+ @ranges[range_i+1..j] = nil
17
+ end
18
+
19
+ def merge_range!(start_n, end_n)
20
+ if (i = PSearch.bsearch(@ranges, start_n, &@cmp_proc)) >= 0
21
+ self.extend_range_to(i, end_n)
22
+ else
23
+ i = -i-1
24
+ if i > 0 && @ranges[i-1][1] >= start_n
25
+ self.extend_range_to(i-1, end_n)
26
+ elsif i < @ranges.length && @ranges[i][0] <= end_n
27
+ @ranges[i][0] = start_n
28
+ self.extend_range_to(i, end_n)
29
+ else
30
+ @ranges[i, 0] = [[start_n, end_n]]
31
+ end
32
+ end
33
+ end
34
+
35
+ def include?(n)
36
+ return true if (i = PSearch.bsearch(@ranges, n, &@cmp_proc))>=0
37
+ i = -i-1
38
+ i > 0 && @ranges[i-1][1] >= n
39
+ end
40
+
41
+ alias_method :member?, :include?
42
+
43
+ def range_end(n)
44
+ if (i = PSearch.bsearch(@ranges, n, &@cmp_proc)) >= 0
45
+ @ranges[i][1]
46
+ else
47
+ i = -i-1
48
+ if i > 0 && @ranges[i-1][1] >= n
49
+ @ranges[i-1][1]
50
+ else
51
+ n
52
+ end
53
+ end
54
+ end
55
+
56
+ def inspect
57
+ idmem = self.object_id & ( (1 << (8*self.object_id.size)) - 1 )
58
+ "#<#{self.class.name}:0x%x: " % idmem + @ranges.collect { |r|
59
+ "#{r[0]}..#{r[1]}"}.join(", ") + ">"
60
+ end
61
+
62
+ alias_method :to_s, :inspect
63
+ end