static void generate_boundary (PixelRegion *PR, BoundaryType type, gint x1, gint y1, gint x2, gint y2) { gint scanline; gint i; gint start, end; gint *tmp_segs; gint num_empty_n = 0; gint num_empty_c = 0; gint num_empty_l = 0; start = 0; end = 0; /* array for determining the vertical line segments which must be drawn */ allocate_vert_segs (PR); /* make sure there is enough space for the empty segment array */ allocate_empty_segs (PR); num_segs = 0; if (type == WithinBounds) { start = y1; end = y2; } else if (type == IgnoreBounds) { start = 0; end = PR->h; } /* Find the empty segments for the previous and current scanlines */ find_empty_segs (PR, start - 1, empty_segs_l, max_empty_segs, &num_empty_l, type, x1, y1, x2, y2); find_empty_segs (PR, start, empty_segs_c, max_empty_segs, &num_empty_c, type, x1, y1, x2, y2); for (scanline = start; scanline < end; scanline++) { /* find the empty segment list for the next scanline */ find_empty_segs (PR, scanline + 1, empty_segs_n, max_empty_segs, &num_empty_n, type, x1, y1, x2, y2); /* process the segments on the current scanline */ for (i = 1; i < num_empty_c - 1; i += 2) { make_horiz_segs (empty_segs_c [i], empty_segs_c [i+1], scanline, empty_segs_l, num_empty_l, true); make_horiz_segs (empty_segs_c [i], empty_segs_c [i+1], scanline+1, empty_segs_n, num_empty_n, false); } /* get the next scanline of empty segments, swap others */ tmp_segs = empty_segs_l; empty_segs_l = empty_segs_c; num_empty_l = num_empty_c; empty_segs_c = empty_segs_n; num_empty_c = num_empty_n; empty_segs_n = tmp_segs; } }
static Boundary * generate_boundary (PixelRegion *PR, BoundaryType type, gint x1, gint y1, gint x2, gint y2, guchar threshold) { Boundary *boundary; gint scanline; gint i; gint start, end; gint *tmp_segs; gint num_empty_n = 0; gint num_empty_c = 0; gint num_empty_l = 0; boundary = boundary_new (PR); start = 0; end = 0; if (type == BOUNDARY_WITHIN_BOUNDS) { start = y1; end = y2; } else if (type == BOUNDARY_IGNORE_BOUNDS) { start = PR->y; end = PR->y + PR->h; } /* Find the empty segments for the previous and current scanlines */ find_empty_segs (PR, start - 1, boundary->empty_segs_l, boundary->max_empty_segs, &num_empty_l, type, x1, y1, x2, y2, threshold); find_empty_segs (PR, start, boundary->empty_segs_c, boundary->max_empty_segs, &num_empty_c, type, x1, y1, x2, y2, threshold); for (scanline = start; scanline < end; scanline++) { /* find the empty segment list for the next scanline */ find_empty_segs (PR, scanline + 1, boundary->empty_segs_n, boundary->max_empty_segs, &num_empty_n, type, x1, y1, x2, y2, threshold); /* process the segments on the current scanline */ for (i = 1; i < num_empty_c - 1; i += 2) { make_horiz_segs (boundary, boundary->empty_segs_c [i], boundary->empty_segs_c [i+1], scanline, boundary->empty_segs_l, num_empty_l, 1); make_horiz_segs (boundary, boundary->empty_segs_c [i], boundary->empty_segs_c [i+1], scanline + 1, boundary->empty_segs_n, num_empty_n, 0); } /* get the next scanline of empty segments, swap others */ tmp_segs = boundary->empty_segs_l; boundary->empty_segs_l = boundary->empty_segs_c; num_empty_l = num_empty_c; boundary->empty_segs_c = boundary->empty_segs_n; num_empty_c = num_empty_n; boundary->empty_segs_n = tmp_segs; } return boundary; }