9 cfill_from_btm(i_img *im, i_fill_t *fill, struct i_bitmap *btm,
10 int bxmin, int bxmax, int bymin, int bymax);
13 i_mmarray_cr(i_mmarray *ar,int l) {
18 alloc_size = sizeof(minmax) * l;
19 /* check for overflow */
20 if (alloc_size / l != sizeof(minmax)) {
21 fprintf(stderr, "overflow calculating memory allocation");
24 ar->data=mymalloc(alloc_size); /* checked 5jul05 tonyc */
25 for(i=0;i<l;i++) { ar->data[i].max=-1; ar->data[i].min=MAXINT; }
29 i_mmarray_dst(i_mmarray *ar) {
31 if (ar->data != NULL) { myfree(ar->data); ar->data=NULL; }
35 i_mmarray_add(i_mmarray *ar,int x,int y) {
36 if (y>-1 && y<ar->lines)
38 if (x<ar->data[y].min) ar->data[y].min=x;
39 if (x>ar->data[y].max) ar->data[y].max=x;
44 i_mmarray_gmin(i_mmarray *ar,int y) {
45 if (y>-1 && y<ar->lines) return ar->data[y].min;
50 i_mmarray_getm(i_mmarray *ar,int y) {
51 if (y>-1 && y<ar->lines) return ar->data[y].max;
56 i_mmarray_render(i_img *im,i_mmarray *ar,i_color *val) {
58 for(i=0;i<ar->lines;i++) if (ar->data[i].max!=-1) for(x=ar->data[i].min;x<ar->data[i].max;x++) i_ppix(im,x,i,val);
63 i_arcdraw(int x1, int y1, int x2, int y2, i_mmarray *ar) {
67 alpha=(double)(y2-y1)/(double)(x2-x1);
70 if (x2<x1) { temp=x1; x1=x2; x2=temp; temp=y1; y1=y2; y2=temp; }
74 i_mmarray_add(ar,x1,(int)(dsec+0.5));
82 if (y2<y1) { temp=x1; x1=x2; x2=temp; temp=y1; y1=y2; y2=temp; }
86 i_mmarray_add(ar,(int)(dsec+0.5),y1);
94 i_mmarray_info(i_mmarray *ar) {
96 for(i=0;i<ar->lines;i++)
97 if (ar->data[i].max!=-1) printf("line %d: min=%d, max=%d.\n",i,ar->data[i].min,ar->data[i].max);
101 i_arc_minmax(i_int_hlines *hlines,int x,int y,float rad,float d1,float d2) {
106 /*mm_log((1,"i_arc(im* 0x%x,x %d,y %d,rad %.2f,d1 %.2f,d2 %.2f,val 0x%x)\n",im,x,y,rad,d1,d2,val));*/
108 i_mmarray_cr(&dot, hlines->limit_y);
110 x1=(int)(x+0.5+rad*cos(d1*PI/180.0));
111 y1=(int)(y+0.5+rad*sin(d1*PI/180.0));
112 fx=(float)x1; fy=(float)y1;
114 /* printf("x1: %d.\ny1: %d.\n",x1,y1); */
115 i_arcdraw(x, y, x1, y1, &dot);
117 x1=(int)(x+0.5+rad*cos(d2*PI/180.0));
118 y1=(int)(y+0.5+rad*sin(d2*PI/180.0));
120 for(f=d1;f<=d2;f+=0.01) i_mmarray_add(&dot,(int)(x+0.5+rad*cos(f*PI/180.0)),(int)(y+0.5+rad*sin(f*PI/180.0)));
122 /* printf("x1: %d.\ny1: %d.\n",x1,y1); */
123 i_arcdraw(x, y, x1, y1, &dot);
125 /* render the minmax values onto the hlines */
126 for (y = 0; y < dot.lines; y++) {
127 if (dot.data[y].max!=-1) {
129 minx = dot.data[y].min;
130 width = dot.data[y].max - dot.data[y].min + 1;
131 i_int_hlines_add(hlines, y, minx, width);
140 i_arc_hlines(i_int_hlines *hlines,int x,int y,float rad,float d1,float d2) {
142 i_arc_minmax(hlines, x, y, rad, d1, d2);
145 i_arc_minmax(hlines, x, y, rad, d1, 360);
146 i_arc_minmax(hlines, x, y, rad, 0, d2);
151 =item i_arc(im, x, y, rad, d1, d2, color)
154 =synopsis i_arc(im, 50, 50, 20, 45, 135, &color);
156 Fills an arc centered at (x,y) with radius I<rad> covering the range
157 of angles in degrees from d1 to d2, with the color.
163 i_arc(i_img *im,int x,int y,float rad,float d1,float d2,const i_color *val) {
166 i_int_init_hlines_img(&hlines, im);
168 i_arc_hlines(&hlines, x, y, rad, d1, d2);
170 i_int_hlines_fill_color(im, &hlines, val);
172 i_int_hlines_destroy(&hlines);
176 =item i_arc_cfill(im, x, y, rad, d1, d2, fill)
179 =synopsis i_arc_cfill(im, 50, 50, 35, 90, 135, fill);
181 Fills an arc centered at (x,y) with radius I<rad> covering the range
182 of angles in degrees from d1 to d2, with the fill object.
187 #define MIN_CIRCLE_STEPS 8
188 #define MAX_CIRCLE_STEPS 360
191 i_arc_cfill(i_img *im,int x,int y,float rad,float d1,float d2,i_fill_t *fill) {
194 i_int_init_hlines_img(&hlines, im);
196 i_arc_hlines(&hlines, x, y, rad, d1, d2);
198 i_int_hlines_fill_fill(im, &hlines, fill);
200 i_int_hlines_destroy(&hlines);
204 arc_poly(int *count, double **xvals, double **yvals,
205 double x, double y, double rad, double d1, double d2) {
206 double d1_rad, d2_rad;
208 int steps, point_count;
211 /* normalize the angles */
214 if (d2 >= 360) { /* default is 361 */
228 d1_rad = d1 * PI / 180;
229 d2_rad = d2 * PI / 180;
231 /* how many segments for the curved part?
232 we do a maximum of one per degree, with a minimum of 8/circle
233 we try to aim at having about one segment per 2 pixels
234 Work it out per circle to get a step size.
236 I was originally making steps = circum/2 but that looked horrible.
238 I think there might be an issue in the polygon filler.
240 circum = 2 * PI * rad;
242 if (steps > MAX_CIRCLE_STEPS)
243 steps = MAX_CIRCLE_STEPS;
244 else if (steps < MIN_CIRCLE_STEPS)
245 steps = MIN_CIRCLE_STEPS;
247 angle_inc = 2 * PI / steps;
249 point_count = steps + 5; /* rough */
250 /* point_count is always relatively small, so allocation won't overflow */
251 *xvals = mymalloc(point_count * sizeof(double)); /* checked 17feb2005 tonyc */
252 *yvals = mymalloc(point_count * sizeof(double)); /* checked 17feb2005 tonyc */
254 /* from centre to edge at d1 */
257 (*xvals)[1] = x + rad * cos(d1_rad);
258 (*yvals)[1] = y + rad * sin(d1_rad);
261 /* step around the curve */
262 while (d1_rad < d2_rad) {
263 (*xvals)[*count] = x + rad * cos(d1_rad);
264 (*yvals)[*count] = y + rad * sin(d1_rad);
269 /* finish off the curve */
270 (*xvals)[*count] = x + rad * cos(d2_rad);
271 (*yvals)[*count] = y + rad * sin(d2_rad);
276 =item i_arc_aa(im, x, y, rad, d1, d2, color)
279 =synopsis i_arc_aa(im, 50, 50, 35, 90, 135, &color);
281 Antialias fills an arc centered at (x,y) with radius I<rad> covering
282 the range of angles in degrees from d1 to d2, with the color.
288 i_arc_aa(i_img *im, double x, double y, double rad, double d1, double d2,
289 const i_color *val) {
290 double *xvals, *yvals;
293 arc_poly(&count, &xvals, &yvals, x, y, rad, d1, d2);
295 i_poly_aa(im, count, xvals, yvals, val);
302 =item i_arc_aa_cfill(im, x, y, rad, d1, d2, fill)
305 =synopsis i_arc_aa_cfill(im, 50, 50, 35, 90, 135, fill);
307 Antialias fills an arc centered at (x,y) with radius I<rad> covering
308 the range of angles in degrees from d1 to d2, with the fill object.
314 i_arc_aa_cfill(i_img *im, double x, double y, double rad, double d1, double d2,
316 double *xvals, *yvals;
319 arc_poly(&count, &xvals, &yvals, x, y, rad, d1, d2);
321 i_poly_aa_cfill(im, count, xvals, yvals, fill);
327 /* Temporary AA HACK */
331 static frac float_to_frac(float x) { return (frac)(0.5+x*16.0); }
335 polar_to_plane(float cx, float cy, float angle, float radius, frac *x, frac *y) {
336 *x = float_to_frac(cx+radius*cos(angle));
337 *y = float_to_frac(cy+radius*sin(angle));
342 make_minmax_list(i_mmarray *dot, float x, float y, float radius) {
344 float astep = radius>0.1 ? .5/radius : 10;
345 frac cx, cy, lx, ly, sx, sy;
347 mm_log((1, "make_minmax_list(dot %p, x %.2f, y %.2f, radius %.2f)\n", dot, x, y, radius));
349 polar_to_plane(x, y, angle, radius, &sx, &sy);
351 for(angle = 0.0; angle<361; angle +=astep) {
353 polar_to_plane(x, y, angle, radius, &cx, &cy);
356 if (fabs(cx-lx) > fabs(cy-ly)) {
359 ccx = lx; lx = cx; cx = ccx;
360 ccy = ly; ly = cy; cy = ccy;
363 for(ccx=lx; ccx<=cx; ccx++) {
364 ccy = ly + ((cy-ly)*(ccx-lx))/(cx-lx);
365 i_mmarray_add(dot, ccx, ccy);
371 ccy = ly; ly = cy; cy = ccy;
372 ccx = lx; lx = cx; cx = ccx;
375 for(ccy=ly; ccy<=cy; ccy++) {
376 if (cy-ly) ccx = lx + ((cx-lx)*(ccy-ly))/(cy-ly); else ccx = lx;
377 i_mmarray_add(dot, ccx, ccy);
383 /* Get the number of subpixels covered */
387 i_pixel_coverage(i_mmarray *dot, int x, int y) {
393 for(cy=y*16; cy<(y+1)*16; cy++) {
394 frac tmin = dot->data[cy].min;
395 frac tmax = dot->data[cy].max;
397 if (tmax == -1 || tmin > maxx || tmax < minx) continue;
399 if (tmin < minx) tmin = minx;
400 if (tmax > maxx) tmax = maxx;
408 =item i_circle_aa(im, x, y, rad, color)
411 =synopsis i_circle_aa(im, 50, 50, 45, &color);
413 Antialias fills a circle centered at (x,y) for radius I<rad> with
419 i_circle_aa(i_img *im, float x, float y, float rad, const i_color *val) {
424 mm_log((1, "i_circle_aa(im %p, x %d, y %d, rad %.2f, val %p)\n", im, x, y, rad, val));
426 i_mmarray_cr(&dot,16*im->ysize);
427 make_minmax_list(&dot, x, y, rad);
429 for(ly = 0; ly<im->ysize; ly++) {
430 int ix, cy, minx = INT_MAX, maxx = INT_MIN;
432 /* Find the left/rightmost set subpixels */
433 for(cy = 0; cy<16; cy++) {
434 frac tmin = dot.data[ly*16+cy].min;
435 frac tmax = dot.data[ly*16+cy].max;
436 if (tmax == -1) continue;
438 if (minx > tmin) minx = tmin;
439 if (maxx < tmax) maxx = tmax;
442 if (maxx == INT_MIN) continue; /* no work to be done for this row of pixels */
446 for(ix=minx; ix<=maxx; ix++) {
447 int cnt = i_pixel_coverage(&dot, ix, ly);
448 if (cnt>255) cnt = 255;
449 if (cnt) { /* should never be true */
451 float ratio = (float)cnt/255.0;
452 i_gpix(im, ix, ly, &temp);
453 for(ch=0;ch<im->channels; ch++) temp.channel[ch] = (unsigned char)((float)val->channel[ch]*ratio + (float)temp.channel[ch]*(1.0-ratio));
454 i_ppix(im, ix, ly, &temp);
462 =item i_box(im, x1, y1, x2, y2, color)
465 =synopsis i_box(im, 0, 0, im->xsize-1, im->ysize-1, &color).
467 Outlines the box from (x1,y1) to (x2,y2) inclusive with I<color>.
473 i_box(i_img *im,int x1,int y1,int x2,int y2,const i_color *val) {
475 mm_log((1,"i_box(im* 0x%x,x1 %d,y1 %d,x2 %d,y2 %d,val 0x%x)\n",im,x1,y1,x2,y2,val));
476 for(x=x1;x<x2+1;x++) {
480 for(y=y1;y<y2+1;y++) {
487 =item i_box_filled(im, x1, y1, x2, y2, color)
490 =synopsis i_box_filled(im, 0, 0, im->xsize-1, im->ysize-1, &color);
492 Fills the box from (x1,y1) to (x2,y2) inclusive with color.
498 i_box_filled(i_img *im,int x1,int y1,int x2,int y2, const i_color *val) {
500 mm_log((1,"i_box_filled(im* 0x%x,x1 %d,y1 %d,x2 %d,y2 %d,val 0x%x)\n",im,x1,y1,x2,y2,val));
501 for(x=x1;x<x2+1;x++) for (y=y1;y<y2+1;y++) i_ppix(im,x,y,val);
505 =item i_box_cfill(im, x1, y1, x2, y2, fill)
508 =synopsis i_box_cfill(im, 0, 0, im->xsize-1, im->ysize-1, fill);
510 Fills the box from (x1,y1) to (x2,y2) inclusive with fill.
516 i_box_cfill(i_img *im,int x1,int y1,int x2,int y2,i_fill_t *fill) {
518 mm_log((1,"i_box_cfill(im* 0x%x,x1 %d,y1 %d,x2 %d,y2 %d,fill 0x%x)\n",im,x1,y1,x2,y2,fill));
529 if (x1 >= x2 || y1 > y2)
532 i_render_init(&r, im, x2-x1);
534 i_render_fill(&r, x1, y1, x2-x1, NULL, fill);
541 =item i_line(im, x1, y1, x2, y2, val, endp)
545 Draw a line to image using bresenhams linedrawing algorithm
547 im - image to draw to
548 x1 - starting x coordinate
549 y1 - starting x coordinate
550 x2 - starting x coordinate
551 y2 - starting x coordinate
552 val - color to write to image
553 endp - endpoint flag (boolean)
559 i_line(i_img *im, int x1, int y1, int x2, int y2, const i_color *val, int endp) {
568 /* choose variable to iterate on */
569 if (abs(dx)>abs(dy)) {
575 t = x1; x1 = x2; x2 = t;
576 t = y1; y1 = y2; y2 = t;
594 for(x=x1; x<x2-1; x++) {
601 i_ppix(im, x+1, y, val);
609 t = x1; x1 = x2; x2 = t;
610 t = y1; y1 = y2; y2 = t;
628 for(y=y1; y<y2-1; y++) {
635 i_ppix(im, x, y+1, val);
639 i_ppix(im, x1, y1, val);
640 i_ppix(im, x2, y2, val);
642 if (x1 != x2 || y1 != y2)
643 i_ppix(im, x1, y1, val);
649 i_line_dda(i_img *im, int x1, int y1, int x2, int y2, i_color *val) {
654 for(x=x1; x<=x2; x++) {
655 dy = y1+ (x-x1)/(float)(x2-x1)*(y2-y1);
656 i_ppix(im, x, (int)(dy+0.5), val);
661 =item i_line_aa(im, x1, x2, y1, y2, color, endp)
665 Antialias draws a line from (x1,y1) to (x2, y2) in color.
667 The point (x2, y2) is drawn only if endp is set.
673 i_line_aa(i_img *im, int x1, int y1, int x2, int y2, const i_color *val, int endp) {
681 /* choose variable to iterate on */
682 if (abs(dx)>abs(dy)) {
688 t = x1; x1 = x2; x2 = t;
689 t = y1; y1 = y2; y2 = t;
703 p = dy2 - dx2; /* this has to be like this for AA */
707 for(x=x1; x<x2-1; x++) {
710 float t = (dy) ? -(float)(p)/(float)(dx2) : 1;
717 i_gpix(im,x+1,y,&tval);
718 for(ch=0;ch<im->channels;ch++)
719 tval.channel[ch]=(unsigned char)(t1*(float)tval.channel[ch]+t2*(float)val->channel[ch]);
720 i_ppix(im,x+1,y,&tval);
722 i_gpix(im,x+1,y+cpy,&tval);
723 for(ch=0;ch<im->channels;ch++)
724 tval.channel[ch]=(unsigned char)(t2*(float)tval.channel[ch]+t1*(float)val->channel[ch]);
725 i_ppix(im,x+1,y+cpy,&tval);
740 t = x1; x1 = x2; x2 = t;
741 t = y1; y1 = y2; y2 = t;
755 p = dx2 - dy2; /* this has to be like this for AA */
759 for(y=y1; y<y2-1; y++) {
762 float t = (dx) ? -(float)(p)/(float)(dy2) : 1;
769 i_gpix(im,x,y+1,&tval);
770 for(ch=0;ch<im->channels;ch++)
771 tval.channel[ch]=(unsigned char)(t1*(float)tval.channel[ch]+t2*(float)val->channel[ch]);
772 i_ppix(im,x,y+1,&tval);
774 i_gpix(im,x+cpx,y+1,&tval);
775 for(ch=0;ch<im->channels;ch++)
776 tval.channel[ch]=(unsigned char)(t2*(float)tval.channel[ch]+t1*(float)val->channel[ch]);
777 i_ppix(im,x+cpx,y+1,&tval);
790 i_ppix(im, x1, y1, val);
791 i_ppix(im, x2, y2, val);
793 if (x1 != x2 || y1 != y2)
794 i_ppix(im, x1, y1, val);
805 for(i=k+1;i<=n;i++) r*=i;
806 for(i=1;i<=(n-k);i++) r/=i;
811 /* Note in calculating t^k*(1-t)^(n-k)
812 we can start by using t^0=1 so this simplifies to
813 t^0*(1-t)^n - we want to multiply that with t/(1-t) each iteration
814 to get a new level - this may lead to errors who knows lets test it */
817 i_bezier_multi(i_img *im,int l,const double *x,const double *y, const i_color *val) {
825 /* this is the same size as the x and y arrays, so shouldn't overflow */
826 bzcoef=mymalloc(sizeof(double)*l); /* checked 5jul05 tonyc */
827 for(k=0;k<l;k++) bzcoef[k]=perm(n,k);
831 /* for(k=0;k<l;k++) printf("bzcoef: %d -> %f\n",k,bzcoef[k]); */
833 for(t=0;t<=1;t+=0.005) {
838 /* cx+=bzcoef[k]*x[k]*pow(t,k)*pow(1-t,n-k);
839 cy+=bzcoef[k]*y[k]*pow(t,k)*pow(1-t,n-k);*/
841 cx+=bzcoef[k]*x[k]*ccoef;
842 cy+=bzcoef[k]*y[k]*ccoef;
845 /* printf("%f -> (%d,%d)\n",t,(int)(0.5+cx),(int)(0.5+cy)); */
847 i_line_aa(im,lx,ly,(int)(0.5+cx),(int)(0.5+cy),val, 1);
849 /* i_ppix(im,(int)(0.5+cx),(int)(0.5+cy),val); */
859 REF: Graphics Gems I. page 282+
863 /* This should be moved into a seperate file? */
865 /* This is the truncation used:
867 a double is multiplied by 16 and then truncated.
868 This means that 0 -> 0
869 So a triangle of (0,0) (10,10) (10,0) Will look like it's
870 not filling the (10,10) point nor the (10,0)-(10,10) line segment
875 /* Flood fill algorithm - based on the Ken Fishkins (pixar) gem in
890 struct stack_element {
898 /* create the link data to put push onto the stack */
901 struct stack_element*
902 crdata(int left,int right,int dadl,int dadr,int y, int dir) {
903 struct stack_element *ste;
904 ste = mymalloc(sizeof(struct stack_element)); /* checked 5jul05 tonyc */
910 ste->myDirection = dir;
914 /* i_ccomp compares two colors and gives true if they are the same */
916 typedef int (*ff_cmpfunc)(i_color const *c1, i_color const *c2, int channels);
919 i_ccomp_normal(i_color const *val1, i_color const *val2, int ch) {
921 for(i = 0; i < ch; i++)
922 if (val1->channel[i] !=val2->channel[i])
928 i_ccomp_border(i_color const *val1, i_color const *val2, int ch) {
930 for(i = 0; i < ch; i++)
931 if (val1->channel[i] !=val2->channel[i])
937 i_lspan(i_img *im, int seedx, int seedy, i_color const *val, ff_cmpfunc cmpfunc) {
940 if (seedx-1 < 0) break;
941 i_gpix(im,seedx-1,seedy,&cval);
942 if (!cmpfunc(val,&cval,im->channels))
950 i_rspan(i_img *im, int seedx, int seedy, i_color const *val, ff_cmpfunc cmpfunc) {
953 if (seedx+1 > im->xsize-1) break;
954 i_gpix(im,seedx+1,seedy,&cval);
955 if (!cmpfunc(val,&cval,im->channels)) break;
961 /* Macro to create a link and push on to the list */
963 #define ST_PUSH(left,right,dadl,dadr,y,dir) do { \
964 struct stack_element *s = crdata(left,right,dadl,dadr,y,dir); \
968 /* pops the shadow on TOS into local variables lx,rx,y,direction,dadLx and dadRx */
969 /* No overflow check! */
971 #define ST_POP() do { \
972 struct stack_element *s; \
979 direction = s->myDirection; \
983 #define ST_STACK(dir,dadLx,dadRx,lx,rx,y) do { \
986 ST_PUSH(lx,rx,pushlx,pushrx,y+dir,dir); \
988 ST_PUSH(dadRx+1,rx,pushlx,pushrx,y-dir,-dir); \
989 if (lx < dadLx) ST_PUSH(lx,dadLx-1,pushlx,pushrx,y-dir,-dir); \
992 #define SET(x,y) btm_set(btm,x,y)
994 /* INSIDE returns true if pixel is correct color and we haven't set it before. */
995 #define INSIDE(x,y, seed) ((!btm_test(btm,x,y) && ( i_gpix(im,x,y,&cval),cmpfunc(seed,&cval,channels) ) ))
999 /* The function that does all the real work */
1001 static struct i_bitmap *
1002 i_flood_fill_low(i_img *im,int seedx,int seedy,
1003 int *bxminp, int *bxmaxp, int *byminp, int *bymaxp,
1004 i_color const *seed, ff_cmpfunc cmpfunc) {
1014 struct i_bitmap *btm;
1016 int channels,xsize,ysize;
1019 channels = im->channels;
1023 btm = btm_new(xsize, ysize);
1024 st = llist_new(100, sizeof(struct stack_element*));
1026 /* Find the starting span and fill it */
1027 ltx = i_lspan(im, seedx, seedy, seed, cmpfunc);
1028 rtx = i_rspan(im, seedx, seedy, seed, cmpfunc);
1029 for(tx=ltx; tx<=rtx; tx++) SET(tx, seedy);
1031 ST_PUSH(ltx, rtx, ltx, rtx, seedy+1, 1);
1032 ST_PUSH(ltx, rtx, ltx, rtx, seedy-1, -1);
1035 /* Stack variables */
1044 ST_POP(); /* sets lx, rx, dadLx, dadRx, y, direction */
1047 if (y<0 || y>ysize-1) continue;
1048 if (bymin > y) bymin=y; /* in the worst case an extra line */
1049 if (bymax < y) bymax=y;
1053 if ( lx >= 0 && (wasIn = INSIDE(lx, y, seed)) ) {
1056 while(INSIDE(lx, y, seed) && lx > 0) {
1062 if (bxmin > lx) bxmin = lx;
1063 while(x <= xsize-1) {
1064 /* printf("x=%d\n",x); */
1067 if (INSIDE(x, y, seed)) {
1068 /* case 1: was inside, am still inside */
1071 /* case 2: was inside, am no longer inside: just found the
1072 right edge of a span */
1073 ST_STACK(direction, dadLx, dadRx, lx, (x-1), y);
1075 if (bxmax < x) bxmax = x;
1079 if (x > rx) goto EXT;
1080 if (INSIDE(x, y, seed)) {
1082 /* case 3: Wasn't inside, am now: just found the start of a new run */
1086 /* case 4: Wasn't inside, still isn't */
1091 EXT: /* out of loop */
1093 /* hit an edge of the frame buffer while inside a run */
1094 ST_STACK(direction, dadLx, dadRx, lx, (x-1), y);
1095 if (bxmax < x) bxmax = x;
1110 =item i_flood_fill(im, seedx, seedy, color)
1113 =synopsis i_flood_fill(im, 50, 50, &color);
1115 Flood fills the 4-connected region starting from the point (seedx,
1116 seedy) with I<color>.
1118 Returns false if (seedx, seedy) are outside the image.
1124 i_flood_fill(i_img *im, int seedx, int seedy, const i_color *dcol) {
1125 int bxmin, bxmax, bymin, bymax;
1126 struct i_bitmap *btm;
1131 if (seedx < 0 || seedx >= im->xsize ||
1132 seedy < 0 || seedy >= im->ysize) {
1133 i_push_error(0, "i_flood_cfill: Seed pixel outside of image");
1137 /* Get the reference color */
1138 i_gpix(im, seedx, seedy, &val);
1140 btm = i_flood_fill_low(im, seedx, seedy, &bxmin, &bxmax, &bymin, &bymax,
1141 &val, i_ccomp_normal);
1143 for(y=bymin;y<=bymax;y++)
1144 for(x=bxmin;x<=bxmax;x++)
1145 if (btm_test(btm,x,y))
1146 i_ppix(im,x,y,dcol);
1152 =item i_flood_cfill(im, seedx, seedy, fill)
1155 =synopsis i_flood_cfill(im, 50, 50, fill);
1157 Flood fills the 4-connected region starting from the point (seedx,
1158 seedy) with I<fill>.
1160 Returns false if (seedx, seedy) are outside the image.
1166 i_flood_cfill(i_img *im, int seedx, int seedy, i_fill_t *fill) {
1167 int bxmin, bxmax, bymin, bymax;
1168 struct i_bitmap *btm;
1173 if (seedx < 0 || seedx >= im->xsize ||
1174 seedy < 0 || seedy >= im->ysize) {
1175 i_push_error(0, "i_flood_cfill: Seed pixel outside of image");
1179 /* Get the reference color */
1180 i_gpix(im, seedx, seedy, &val);
1182 btm = i_flood_fill_low(im, seedx, seedy, &bxmin, &bxmax, &bymin, &bymax,
1183 &val, i_ccomp_normal);
1185 cfill_from_btm(im, fill, btm, bxmin, bxmax, bymin, bymax);
1192 =item i_flood_fill_border(im, seedx, seedy, color, border)
1195 =synopsis i_flood_fill_border(im, 50, 50, &color, &border);
1197 Flood fills the 4-connected region starting from the point (seedx,
1198 seedy) with I<color>, fill stops when the fill reaches a pixels with
1201 Returns false if (seedx, seedy) are outside the image.
1207 i_flood_fill_border(i_img *im, int seedx, int seedy, const i_color *dcol,
1208 const i_color *border) {
1209 int bxmin, bxmax, bymin, bymax;
1210 struct i_bitmap *btm;
1214 if (seedx < 0 || seedx >= im->xsize ||
1215 seedy < 0 || seedy >= im->ysize) {
1216 i_push_error(0, "i_flood_cfill: Seed pixel outside of image");
1220 btm = i_flood_fill_low(im, seedx, seedy, &bxmin, &bxmax, &bymin, &bymax,
1221 border, i_ccomp_border);
1223 for(y=bymin;y<=bymax;y++)
1224 for(x=bxmin;x<=bxmax;x++)
1225 if (btm_test(btm,x,y))
1226 i_ppix(im,x,y,dcol);
1232 =item i_flood_cfill_border(im, seedx, seedy, fill, border)
1235 =synopsis i_flood_cfill_border(im, 50, 50, fill, border);
1237 Flood fills the 4-connected region starting from the point (seedx,
1238 seedy) with I<fill>, the fill stops when it reaches pixels of color
1241 Returns false if (seedx, seedy) are outside the image.
1247 i_flood_cfill_border(i_img *im, int seedx, int seedy, i_fill_t *fill,
1248 const i_color *border) {
1249 int bxmin, bxmax, bymin, bymax;
1250 struct i_bitmap *btm;
1254 if (seedx < 0 || seedx >= im->xsize ||
1255 seedy < 0 || seedy >= im->ysize) {
1256 i_push_error(0, "i_flood_cfill_border: Seed pixel outside of image");
1260 btm = i_flood_fill_low(im, seedx, seedy, &bxmin, &bxmax, &bymin, &bymax,
1261 border, i_ccomp_border);
1263 cfill_from_btm(im, fill, btm, bxmin, bxmax, bymin, bymax);
1271 cfill_from_btm(i_img *im, i_fill_t *fill, struct i_bitmap *btm,
1272 int bxmin, int bxmax, int bymin, int bymax) {
1278 i_render_init(&r, im, bxmax - bxmin + 1);
1280 for(y=bymin; y<=bymax; y++) {
1282 while (x <= bxmax) {
1283 while (x <= bxmax && !btm_test(btm, x, y)) {
1286 if (btm_test(btm, x, y)) {
1288 while (x <= bxmax && btm_test(btm, x, y)) {
1291 i_render_fill(&r, start, y, x-start, NULL, fill);