• R/O
  • HTTP
  • SSH
  • HTTPS

BurageSnap: Commit


Commit MetaInfo

Revisión6ec663b58211a41fa0b394dfcedcbf7246655fb1 (tree)
Tiempo2018-12-16 21:59:19
AutorKazuhiro Fujieda <fujieda@user...>
CommiterKazuhiro Fujieda

Log Message

Include decorations in captured images

Cambiar Resumen

Diferencia incremental

--- a/BurageSnap/Capture.cs
+++ b/BurageSnap/Capture.cs
@@ -193,18 +193,21 @@ namespace BurageSnap
193193 for (var x = 1; x < width; x++)
194194 {
195195 var rect = Rectangle.Empty;
196+ var margin = Rectangle.Empty;
196197 rect.Y = y;
197198 if (!CheckEdgeVerticalLeft(map, x, x, rect.Y, height))
198199 continue;
199200 rect.X = x;
200- rect = FindBottomAndRight(map, rect);
201+ FindBottomAndRight(map, ref rect, ref margin);
201202 if (rect == Rectangle.Empty)
202203 continue;
203- if (!CheckEdgeStrictHorizontalTop(map, rect.X, rect.Right, y, y, vagueTop))
204+ var unused = Rectangle.Empty;
205+ if (!CheckEdgeStrictHorizontalTop(map, rect.X, rect.Right, y, y, vagueTop, ref unused))
204206 break;
205- if (!CheckEdgeStrictVerticalLeft(map, x, x, rect.Y, rect.Bottom))
207+ if (!CheckEdgeStrictVerticalLeft(map, x, x, rect.Y, rect.Bottom, ref unused))
206208 continue;
207- rect = FindTopAndLeft(map, rect, vagueTop);
209+ FindTopAndLeft(map, ref rect, vagueTop, ref margin);
210+ InflateRectangle(ref rect, margin);
208211 RoundUpRectangle(map, ref rect);
209212 return rect;
210213 }
@@ -212,7 +215,15 @@ namespace BurageSnap
212215 return Rectangle.Empty;
213216 }
214217
215- private Rectangle FindBottomAndRight(byte[,] map, Rectangle rect)
218+ private void InflateRectangle(ref Rectangle rect, Rectangle margin)
219+ {
220+ rect.X -= margin.X;
221+ rect.Y -= margin.Y;
222+ rect.Width += margin.X + margin.Width;
223+ rect.Height += margin.Y + margin.Height;
224+ }
225+
226+ private void FindBottomAndRight(byte[,] map, ref Rectangle rect, ref Rectangle margin)
216227 {
217228 var width = map.GetLength(0);
218229 var height = map.GetLength(1);
@@ -224,35 +235,40 @@ namespace BurageSnap
224235 rect.Width = 0;
225236 for (var x = rect.X; x < width; x++)
226237 {
227- if (!CheckEdgeStrictVerticalRight(map, x, x, rect.Y, rect.Bottom))
238+ if (!CheckEdgeStrictVerticalRight(map, x, x, rect.Y, rect.Bottom, ref margin))
228239 continue;
229240 rect.Width = x - rect.X;
230241 break;
231242 }
232243 if (rect.Width == 0)
233244 continue;
234- if (CheckEdgeStrictHorizontalBottom(map, rect.X, rect.Right, rect.Bottom, rect.Bottom))
245+ var unused = Rectangle.Empty;
246+ if (CheckEdgeStrictHorizontalBottom(map, rect.X, rect.Right, rect.Bottom, rect.Bottom, ref unused))
235247 break;
236248 }
237249 if (rect.Width == 0)
238- return Rectangle.Empty;
250+ {
251+ rect = Rectangle.Empty;
252+ return;
253+ }
239254 // check a smaller rectangle
240255 for (var y = rect.Y; y <= rect.Bottom; y++)
241256 {
242- if (CheckEdgeStrictHorizontalBottom(map, rect.X, rect.Right, y, y))
257+ if (CheckEdgeStrictHorizontalBottom(map, rect.X, rect.Right, y, y, ref margin))
243258 {
244259 rect.Height = y - rect.Y;
245260 break;
246261 }
247262 }
248- return rect.Width >= WidthMin && rect.Height >= HeightMin ? rect : Rectangle.Empty;
263+ if (!(rect.Width >= WidthMin && rect.Height >= HeightMin))
264+ rect = Rectangle.Empty;
249265 }
250266
251- private Rectangle FindTopAndLeft(byte[,] map, Rectangle rect, bool vagueTop)
267+ private void FindTopAndLeft(byte[,] map, ref Rectangle rect, bool vagueTop, ref Rectangle margin)
252268 {
253269 for (var y = rect.Bottom - 1; y >= rect.Y; y--)
254270 {
255- if (CheckEdgeStrictHorizontalTop(map, rect.Left, rect.Right, y, y, vagueTop))
271+ if (CheckEdgeStrictHorizontalTop(map, rect.Left, rect.Right, y, y, vagueTop, ref margin))
256272 {
257273 rect.Height += rect.Y - y;
258274 rect.Y = y;
@@ -261,14 +277,13 @@ namespace BurageSnap
261277 }
262278 for (var x = rect.Right - 1; x >= rect.X; x--)
263279 {
264- if (CheckEdgeStrictVerticalLeft(map, x, x, rect.Top, rect.Bottom))
280+ if (CheckEdgeStrictVerticalLeft(map, x, x, rect.Top, rect.Bottom, ref margin))
265281 {
266282 rect.Width += rect.X - x;
267283 rect.X = x;
268284 break;
269285 }
270286 }
271- return rect;
272287 }
273288
274289 const int EdgeWidth = WidthMin / 2;
@@ -332,51 +347,51 @@ namespace BurageSnap
332347 return false;
333348 }
334349
335- private bool CheckEdgeStrictHorizontalTop(byte[,] map, int left, int right, int top, int bottom, bool vagueTop)
350+ private bool CheckEdgeStrictHorizontalTop(byte[,] map, int left, int right, int top, int bottom, bool vagueTop, ref Rectangle margin)
336351 {
337352 return CheckEdgeHorizontalTop(map, left, right, top, bottom) &&
338- CheckEndOfEdgeHorizontalTop(map, left, right, top, bottom) &&
353+ CheckEndOfEdgeHorizontalTop(map, left, right, top, bottom, ref margin) &&
339354 CheckEnoughLengthHorizontalTop(map, left, right, top, bottom, vagueTop);
340355 }
341356
342- private bool CheckEdgeStrictVerticalLeft(byte[,] map, int left, int right, int top, int bottom)
357+ private bool CheckEdgeStrictVerticalLeft(byte[,] map, int left, int right, int top, int bottom, ref Rectangle margin)
343358 {
344359 return CheckEdgeVerticalLeft(map, left, right, top, bottom) &&
345- CheckEndOfEdgeVerticalLeft(map, left, right, top, bottom) &&
360+ CheckEndOfEdgeVerticalLeft(map, left, right, top, bottom, ref margin) &&
346361 CheckEnoughLengthVerticalLeft(map, left, right, top, bottom);
347362 }
348363
349- private bool CheckEdgeStrictHorizontalBottom(byte[,] map, int left, int right, int top, int bottom)
364+ private bool CheckEdgeStrictHorizontalBottom(byte[,] map, int left, int right, int top, int bottom, ref Rectangle margin)
350365 {
351366 return CheckEdgeHorizontalBottom(map, left, right, top, bottom) &&
352- CheckEndOfEdgeHorizontalBottom(map, left, right, top, bottom) &&
367+ CheckEndOfEdgeHorizontalBottom(map, left, right, top, bottom, ref margin) &&
353368 CheckEnoughLengthHorizontalBottom(map, left, right, top, bottom);
354369 }
355370
356- private bool CheckEdgeStrictVerticalRight(byte[,] map, int left, int right, int top, int bottom)
371+ private bool CheckEdgeStrictVerticalRight(byte[,] map, int left, int right, int top, int bottom, ref Rectangle margin)
357372 {
358373 return CheckEdgeVerticalRight(map, left, right, top, bottom) &&
359- CheckEndOfEdgeVerticalRight(map, left, right, top, bottom) &&
374+ CheckEndOfEdgeVerticalRight(map, left, right, top, bottom, ref margin) &&
360375 CheckEnoughLengthVerticalRight(map, left, right, top, bottom);
361376 }
362377
363378 private const int DecorationThickness = 20;
364379 private const int CornerSize = 10;
365380
366- private bool CheckEndOfEdgeHorizontalTop(byte[,] map, int left, int right, int top, int bottom)
381+ private bool CheckEndOfEdgeHorizontalTop(byte[,] map, int left, int right, int top, int bottom, ref Rectangle margin)
367382 {
368- for (var margin = 0; margin < DecorationThickness; margin++)
383+ for (margin.Y = 0; margin.Top < DecorationThickness; margin.Y++)
369384 {
370- if (top - margin - 1 < 0)
385+ if (top - margin.Y - 1 < 0)
371386 return false;
372387 for (var x = left; x < left + CornerSize; x++)
373388 {
374- if (map[x, top - margin - 1] == 0)
389+ if (map[x, top - margin.Y - 1] == 0)
375390 goto last;
376391 }
377392 for (var x = right - 1; x >= right - CornerSize; x--)
378393 {
379- if (map[x, top - margin - 1] == 0)
394+ if (map[x, top - margin.Y - 1] == 0)
380395 goto last;
381396 }
382397 return true;
@@ -386,20 +401,20 @@ namespace BurageSnap
386401 return false;
387402 }
388403
389- private bool CheckEndOfEdgeVerticalLeft(byte[,] map, int left, int right, int top, int bottom)
404+ private bool CheckEndOfEdgeVerticalLeft(byte[,] map, int left, int right, int top, int bottom, ref Rectangle margin)
390405 {
391- for (var margin = 0; margin < DecorationThickness; margin++)
406+ for (margin.X = 0; margin.X < DecorationThickness; margin.X++)
392407 {
393- if (left - margin - 1 < 0)
408+ if (left - margin.X - 1 < 0)
394409 return false;
395410 for (var y = top; y < top + CornerSize; y++)
396411 {
397- if (map[left - margin - 1, y] == 0)
412+ if (map[left - margin.X - 1, y] == 0)
398413 goto last;
399414 }
400415 for (var y = bottom - 1; y >= bottom - CornerSize; y--)
401416 {
402- if (map[left - margin - 1, y] == 0)
417+ if (map[left - margin.X - 1, y] == 0)
403418 goto last;
404419 }
405420 return true;
@@ -409,20 +424,20 @@ namespace BurageSnap
409424 return false;
410425 }
411426
412- private bool CheckEndOfEdgeHorizontalBottom(byte[,] map, int left, int right, int top, int bottom)
427+ private bool CheckEndOfEdgeHorizontalBottom(byte[,] map, int left, int right, int top, int bottom, ref Rectangle margin)
413428 {
414- for (var margin = 0; margin < DecorationThickness; margin++)
429+ for (margin.Height = 0; margin.Height < DecorationThickness; margin.Height++)
415430 {
416- if (bottom + margin >= map.GetLength(1))
431+ if (bottom + margin.Height >= map.GetLength(1))
417432 return false;
418433 for (var x = left; x < left + CornerSize; x++)
419434 {
420- if (map[x, bottom + margin] == 0)
435+ if (map[x, bottom + margin.Height] == 0)
421436 goto last;
422437 }
423438 for (var x = right - 1; x >= right - CornerSize; x--)
424439 {
425- if (map[x, bottom + margin] == 0)
440+ if (map[x, bottom + margin.Height] == 0)
426441 goto last;
427442 }
428443 return true;
@@ -432,20 +447,20 @@ namespace BurageSnap
432447 return false;
433448 }
434449
435- private bool CheckEndOfEdgeVerticalRight(byte[,] map, int left, int right, int top, int bottom)
450+ private bool CheckEndOfEdgeVerticalRight(byte[,] map, int left, int right, int top, int bottom, ref Rectangle margin)
436451 {
437- for (var margin = 0; margin < DecorationThickness; margin++)
452+ for (margin.Width = 0; margin.Width < DecorationThickness; margin.Width++)
438453 {
439- if (right + margin >= map.GetLength(0))
454+ if (right + margin.Width >= map.GetLength(0))
440455 return false;
441456 for (var y = top; y < top + CornerSize; y++)
442457 {
443- if (map[right + margin, y] == 0)
458+ if (map[right + margin.Width, y] == 0)
444459 goto last;
445460 }
446461 for (var y = bottom - 1; y >= bottom - CornerSize; y--)
447462 {
448- if (map[right + margin, y] == 0)
463+ if (map[right + margin.Width, y] == 0)
449464 goto last;
450465 }
451466 return true;
Show on old repository browser