-#include "image.h"
+#include "imager.h"
#include "draw.h"
#include "log.h"
-
+#include "imrender.h"
#define IMTRUNC(x) ((int)((x)*16))
static
p_line *
-line_set_new(double *x, double *y, int l) {
+line_set_new(const double *x, const double *y, int l) {
int i;
p_line *lset = mymalloc(sizeof(p_line) * l);
static
p_point *
-point_set_new(double *x, double *y, int l) {
+point_set_new(const double *x, const double *y, int l) {
int i;
p_point *pset = mymalloc(sizeof(p_point) * l);
return 0;
}
-typedef void (*scanline_flusher)(i_img *im, ss_scanline *ss, int y, void *ctx);
+typedef void (*scanline_flusher)(i_img *im, ss_scanline *ss, int y, const void *ctx);
/* This function must be modified later to do proper blending */
static void
-scanline_flush(i_img *im, ss_scanline *ss, int y, void *ctx) {
+scanline_flush(i_img *im, ss_scanline *ss, int y, const void *ctx) {
int x, ch, tv;
i_color t;
i_color *val = (i_color *)ctx;
(maxx-p_eval_aty(line, miny))*(p_eval_atx(line, maxx)-miny)/2.0;
return r;
}
+
+ return 0; /* silence compiler warning */
}
static void
-i_poly_aa_low(i_img *im, int l, double *x, double *y, void *ctx, scanline_flusher flusher) {
+i_poly_aa_low(i_img *im, int l, const double *x, const double *y, void const *ctx, scanline_flusher flusher) {
int i ,k; /* Index variables */
int clc; /* Lines inside current interval */
- pcord tempy;
- int cscl; /* Current scanline */
+ /* initialize to avoid compiler warnings */
+ pcord tempy = 0;
+ int cscl = 0; /* Current scanline */
ss_scanline templine; /* scanline accumulator */
p_point *pset; /* List of points in polygon */
} /* Function */
void
-i_poly_aa(i_img *im, int l, double *x, double *y, i_color *val) {
+i_poly_aa(i_img *im, int l, const double *x, const double *y, const i_color *val) {
i_poly_aa_low(im, l, x, y, val, scanline_flush);
}
+#if 0
struct poly_cfill_state {
i_color *fillbuf;
i_color *linebuf;
};
static void
-scanline_flush_cfill(i_img *im, ss_scanline *ss, int y, void *ctx) {
+scanline_flush_cfill(i_img *im, ss_scanline *ss, int y, const void *ctx) {
int x, ch, tv;
int pos;
int left, right;
- struct poly_cfill_state *state = (struct poly_cfill_state *)ctx;
+ struct poly_cfill_state const *state = (struct poly_cfill_state const *)ctx;
i_color *fillbuf = state->fillbuf;
i_color *line = state->linebuf;
};
static void
-scanline_flush_cfill_f(i_img *im, ss_scanline *ss, int y, void *ctx) {
+scanline_flush_cfill_f(i_img *im, ss_scanline *ss, int y, const void *ctx) {
int x, ch, tv;
int pos;
int left, right;
- struct poly_cfill_state_f *state = (struct poly_cfill_state_f *)ctx;
+ struct poly_cfill_state_f const *state = (struct poly_cfill_state_f const *)ctx;
i_fcolor *fillbuf = state->fillbuf;
i_fcolor *line = state->linebuf;
i_plinf(im, left, right, y, line);
}
}
+#endif
+
+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, const void *ctx) {
+ int x, ch, tv;
+ int pos;
+ int left, right;
+ struct poly_render_state const *state = (struct poly_render_state const *)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);
+ }
+}
void
-i_poly_aa_cfill(i_img *im, int l, double *x, double *y, i_fill_t *fill) {
+i_poly_aa_cfill(i_img *im, int l, const double *x, const double *y,
+ i_fill_t *fill) {
+ struct poly_render_state ctx;
+
+ i_render_init(&ctx.render, im, im->xsize);
+ ctx.fill = fill;
+ ctx.cover = mymalloc(im->xsize);
+ i_poly_aa_low(im, l, x, y, &ctx, scanline_flush_render);
+ myfree(ctx.cover);
+ i_render_done(&ctx.render);
+#if 0
if (im->bits == i_8_bits && fill->fill_with_color) {
struct poly_cfill_state ctx;
ctx.fillbuf = mymalloc(sizeof(i_color) * im->xsize * 2);
myfree(ctx.fillbuf);
myfree(ctx.cover);
}
+#endif
}