+/*
+=item i_poly_aa_m(im, count, x, y, mode, color)
+=synopsis i_poly_aa_m(im, count, x, y, mode, color);
+=category Drawing
+
+Fill a polygon defined by the points specified by the x and y arrays with
+the color specified by C<color>.
+
+=cut
+*/
+
+int
+i_poly_aa_m(i_img *im, int l, const double *x, const double *y,
+ i_poly_fill_mode_t mode, const i_color *val) {
+ i_polygon_t poly;
+
+ poly.count = l;
+ poly.x = x;
+ poly.y = y;
+ return i_poly_poly_aa(im, 1, &poly, mode, val);
+}
+
+int
+i_poly_aa(i_img *im, int l, const double *x, const double *y, const i_color *val) {
+ i_polygon_t poly;
+
+ poly.count = l;
+ poly.x = x;
+ poly.y = y;
+ return i_poly_poly_aa(im, 1, &poly, i_pfm_evenodd, val);
+}
+
+struct poly_render_state {
+ i_render render;
+ i_fill_t *fill;
+ unsigned char *cover;
+};
+
+static void
+scanline_flush_render(i_img *im, ss_scanline *ss, int y, void *ctx) {
+ i_img_dim x;
+ i_img_dim left, right;
+ struct poly_render_state *state = (struct poly_render_state *)ctx;
+
+ left = 0;
+ while (left < im->xsize && ss->line[left] <= 0)
+ ++left;
+ if (left < im->xsize) {
+ right = im->xsize;
+ /* since going from the left found something, moving from the
+ right should */
+ while (/* right > left && */ ss->line[right-1] <= 0)
+ --right;
+
+ /* convert to the format the render interface wants */
+ for (x = left; x < right; ++x) {
+ state->cover[x-left] = saturate(ss->line[x]);
+ }
+ i_render_fill(&state->render, left, y, right-left, state->cover,
+ state->fill);
+ }
+}
+
+/*
+=item i_poly_poly_aa_cfill(im, count, polys, mode, fill)
+=synopsis i_poly_poly_aa_cfill(im, 1, &poly, mode, fill);
+=category Drawing
+
+Fill the C<count> polygons defined by C<polys> the fill specified by
+C<fill>.
+
+At least one polygon must be supplied.
+
+All polygons must have at least 3 points.
+
+=cut
+*/
+
+int
+i_poly_poly_aa_cfill(i_img *im, int count, const i_polygon_t *polys,
+ i_poly_fill_mode_t mode, i_fill_t *fill) {
+ struct poly_render_state ctx;
+ int result;
+
+ i_render_init(&ctx.render, im, im->xsize);
+ ctx.fill = fill;
+ ctx.cover = mymalloc(im->xsize);
+
+ result = i_poly_poly_aa_low(im, count, polys, mode, &ctx,
+ scanline_flush_render);
+
+ myfree(ctx.cover);
+ i_render_done(&ctx.render);
+
+ return result;
+}
+
+/*
+=item i_poly_aa_cfill_m(im, count, x, y, mode, fill)
+=synopsis i_poly_aa_cfill(im, count, x, y, mode, fill);
+=category Drawing
+
+Fill a polygon defined by the points specified by the x and y arrays with
+the fill specified by C<fill>.
+
+=cut
+*/
+
+int
+i_poly_aa_cfill_m(i_img *im, int l, const double *x, const double *y,
+ i_poly_fill_mode_t mode, i_fill_t *fill) {
+ i_polygon_t poly;
+
+ poly.count = l;
+ poly.x = x;
+ poly.y = y;
+
+ return i_poly_poly_aa_cfill(im, 1, &poly, mode, fill);
+}
+
+int
+i_poly_aa_cfill(i_img *im, int l, const double *x, const double *y,
+ i_fill_t *fill) {
+ i_polygon_t poly;
+
+ poly.count = l;
+ poly.x = x;
+ poly.y = y;
+
+ return i_poly_poly_aa_cfill(im, 1, &poly, i_pfm_evenodd, fill);
+}