1 #define IMAGER_NO_CONTEXT
10 i_ppix_norm(i_img *im, i_img_dim x, i_img_dim y, i_color const *col) {
19 switch (im->channels) {
22 i_adapt_colors(2, 4, &work, 1);
23 i_gpix(im, x, y, &src);
24 remains = 255 - work.channel[1];
25 src.channel[0] = (src.channel[0] * remains
26 + work.channel[0] * work.channel[1]) / 255;
27 return i_ppix(im, x, y, &src);
31 i_adapt_colors(2, 4, &work, 1);
32 i_gpix(im, x, y, &src);
33 remains = 255 - work.channel[1];
34 dest_alpha = work.channel[1] + remains * src.channel[1] / 255;
35 if (work.channel[1] == 255) {
36 return i_ppix(im, x, y, &work);
39 src.channel[0] = (work.channel[1] * work.channel[0]
40 + remains * src.channel[0] * src.channel[1] / 255) / dest_alpha;
41 src.channel[1] = dest_alpha;
42 return i_ppix(im, x, y, &src);
47 i_gpix(im, x, y, &src);
48 remains = 255 - work.channel[3];
49 src.channel[0] = (src.channel[0] * remains
50 + work.channel[0] * work.channel[3]) / 255;
51 src.channel[1] = (src.channel[1] * remains
52 + work.channel[1] * work.channel[3]) / 255;
53 src.channel[2] = (src.channel[2] * remains
54 + work.channel[2] * work.channel[3]) / 255;
55 return i_ppix(im, x, y, &src);
59 i_gpix(im, x, y, &src);
60 remains = 255 - work.channel[3];
61 dest_alpha = work.channel[3] + remains * src.channel[3] / 255;
62 if (work.channel[3] == 255) {
63 return i_ppix(im, x, y, &work);
66 src.channel[0] = (work.channel[3] * work.channel[0]
67 + remains * src.channel[0] * src.channel[3] / 255) / dest_alpha;
68 src.channel[1] = (work.channel[3] * work.channel[1]
69 + remains * src.channel[1] * src.channel[3] / 255) / dest_alpha;
70 src.channel[2] = (work.channel[3] * work.channel[2]
71 + remains * src.channel[2] * src.channel[3] / 255) / dest_alpha;
72 src.channel[3] = dest_alpha;
73 return i_ppix(im, x, y, &src);
80 cfill_from_btm(i_img *im, i_fill_t *fill, struct i_bitmap *btm,
81 i_img_dim bxmin, i_img_dim bxmax, i_img_dim bymin, i_img_dim bymax);
84 i_mmarray_cr(i_mmarray *ar,i_img_dim l) {
89 alloc_size = sizeof(minmax) * l;
90 /* check for overflow */
91 if (alloc_size / l != sizeof(minmax)) {
92 fprintf(stderr, "overflow calculating memory allocation");
95 ar->data=mymalloc(alloc_size); /* checked 5jul05 tonyc */
96 for(i=0;i<l;i++) { ar->data[i].max=-1; ar->data[i].min=MAXINT; }
100 i_mmarray_dst(i_mmarray *ar) {
102 if (ar->data != NULL) { myfree(ar->data); ar->data=NULL; }
106 i_mmarray_add(i_mmarray *ar,i_img_dim x,i_img_dim y) {
107 if (y>-1 && y<ar->lines)
109 if (x<ar->data[y].min) ar->data[y].min=x;
110 if (x>ar->data[y].max) ar->data[y].max=x;
115 i_mmarray_gmin(i_mmarray *ar,i_img_dim y) {
116 if (y>-1 && y<ar->lines) return ar->data[y].min;
121 i_mmarray_getm(i_mmarray *ar,i_img_dim y) {
122 if (y>-1 && y<ar->lines) return ar->data[y].max;
129 i_mmarray_render(i_img *im,i_mmarray *ar,i_color *val) {
131 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);
137 i_arcdraw(i_img_dim x1, i_img_dim y1, i_img_dim x2, i_img_dim y2, i_mmarray *ar) {
141 alpha=(double)(y2-y1)/(double)(x2-x1);
142 if (fabs(alpha) <= 1)
144 if (x2<x1) { temp=x1; x1=x2; x2=temp; temp=y1; y1=y2; y2=temp; }
148 i_mmarray_add(ar,x1,(i_img_dim)(dsec+0.5));
156 if (y2<y1) { temp=x1; x1=x2; x2=temp; temp=y1; y1=y2; y2=temp; }
160 i_mmarray_add(ar,(i_img_dim)(dsec+0.5),y1);
168 i_mmarray_info(i_mmarray *ar) {
170 for(i=0;i<ar->lines;i++)
171 if (ar->data[i].max!=-1)
172 printf("line %"i_DF ": min=%" i_DF ", max=%" i_DF ".\n",
173 i_DFc(i), i_DFc(ar->data[i].min), i_DFc(ar->data[i].max));
177 i_arc_minmax(i_int_hlines *hlines,i_img_dim x,i_img_dim y, double rad,float d1,float d2) {
182 i_mmarray_cr(&dot, hlines->limit_y);
184 x1=(i_img_dim)(x+0.5+rad*cos(d1*PI/180.0));
185 y1=(i_img_dim)(y+0.5+rad*sin(d1*PI/180.0));
187 /* printf("x1: %d.\ny1: %d.\n",x1,y1); */
188 i_arcdraw(x, y, x1, y1, &dot);
190 x1=(i_img_dim)(x+0.5+rad*cos(d2*PI/180.0));
191 y1=(i_img_dim)(y+0.5+rad*sin(d2*PI/180.0));
193 for(f=d1;f<=d2;f+=0.01)
194 i_mmarray_add(&dot,(i_img_dim)(x+0.5+rad*cos(f*PI/180.0)),(i_img_dim)(y+0.5+rad*sin(f*PI/180.0)));
196 /* printf("x1: %d.\ny1: %d.\n",x1,y1); */
197 i_arcdraw(x, y, x1, y1, &dot);
199 /* render the minmax values onto the hlines */
200 for (y = 0; y < dot.lines; y++) {
201 if (dot.data[y].max!=-1) {
202 i_img_dim minx, width;
203 minx = dot.data[y].min;
204 width = dot.data[y].max - dot.data[y].min + 1;
205 i_int_hlines_add(hlines, y, minx, width);
214 i_arc_hlines(i_int_hlines *hlines,i_img_dim x,i_img_dim y,double rad,float d1,float d2) {
216 i_arc_minmax(hlines, x, y, rad, d1, d2);
219 i_arc_minmax(hlines, x, y, rad, d1, 360);
220 i_arc_minmax(hlines, x, y, rad, 0, d2);
225 =item i_arc(im, x, y, rad, d1, d2, color)
228 =synopsis i_arc(im, 50, 50, 20, 45, 135, &color);
230 Fills an arc centered at (x,y) with radius I<rad> covering the range
231 of angles in degrees from d1 to d2, with the color.
237 i_arc(i_img *im, i_img_dim x, i_img_dim y,double rad,double d1,double d2,const i_color *val) {
241 im_log((aIMCTX,1,"i_arc(im %p,(x,y)=(" i_DFp "), rad %f, d1 %f, d2 %f, col %p)",
242 im, i_DFcp(x, y), rad, d1, d2, val));
244 i_int_init_hlines_img(&hlines, im);
246 i_arc_hlines(&hlines, x, y, rad, d1, d2);
248 i_int_hlines_fill_color(im, &hlines, val);
250 i_int_hlines_destroy(&hlines);
254 =item i_arc_cfill(im, x, y, rad, d1, d2, fill)
257 =synopsis i_arc_cfill(im, 50, 50, 35, 90, 135, fill);
259 Fills an arc centered at (x,y) with radius I<rad> covering the range
260 of angles in degrees from d1 to d2, with the fill object.
265 #define MIN_CIRCLE_STEPS 8
266 #define MAX_CIRCLE_STEPS 360
269 i_arc_cfill(i_img *im, i_img_dim x, i_img_dim y,double rad,double d1,double d2,i_fill_t *fill) {
273 im_log((aIMCTX,1,"i_arc_cfill(im %p,(x,y)=(" i_DFp "), rad %f, d1 %f, d2 %f, fill %p)",
274 im, i_DFcp(x, y), rad, d1, d2, fill));
276 i_int_init_hlines_img(&hlines, im);
278 i_arc_hlines(&hlines, x, y, rad, d1, d2);
280 i_int_hlines_fill_fill(im, &hlines, fill);
282 i_int_hlines_destroy(&hlines);
286 arc_poly(int *count, double **xvals, double **yvals,
287 double x, double y, double rad, double d1, double d2) {
288 double d1_rad, d2_rad;
290 i_img_dim steps, point_count;
293 /* normalize the angles */
296 if (d2 >= 360) { /* default is 361 */
310 d1_rad = d1 * PI / 180;
311 d2_rad = d2 * PI / 180;
313 /* how many segments for the curved part?
314 we do a maximum of one per degree, with a minimum of 8/circle
315 we try to aim at having about one segment per 2 pixels
316 Work it out per circle to get a step size.
318 I was originally making steps = circum/2 but that looked horrible.
320 I think there might be an issue in the polygon filler.
322 circum = 2 * PI * rad;
324 if (steps > MAX_CIRCLE_STEPS)
325 steps = MAX_CIRCLE_STEPS;
326 else if (steps < MIN_CIRCLE_STEPS)
327 steps = MIN_CIRCLE_STEPS;
329 angle_inc = 2 * PI / steps;
331 point_count = steps + 5; /* rough */
332 /* point_count is always relatively small, so allocation won't overflow */
333 *xvals = mymalloc(point_count * sizeof(double)); /* checked 17feb2005 tonyc */
334 *yvals = mymalloc(point_count * sizeof(double)); /* checked 17feb2005 tonyc */
336 /* from centre to edge at d1 */
339 (*xvals)[1] = x + rad * cos(d1_rad);
340 (*yvals)[1] = y + rad * sin(d1_rad);
343 /* step around the curve */
344 while (d1_rad < d2_rad) {
345 (*xvals)[*count] = x + rad * cos(d1_rad);
346 (*yvals)[*count] = y + rad * sin(d1_rad);
351 /* finish off the curve */
352 (*xvals)[*count] = x + rad * cos(d2_rad);
353 (*yvals)[*count] = y + rad * sin(d2_rad);
358 =item i_arc_aa(im, x, y, rad, d1, d2, color)
361 =synopsis i_arc_aa(im, 50, 50, 35, 90, 135, &color);
363 Anti-alias fills an arc centered at (x,y) with radius I<rad> covering
364 the range of angles in degrees from d1 to d2, with the color.
370 i_arc_aa(i_img *im, double x, double y, double rad, double d1, double d2,
371 const i_color *val) {
372 double *xvals, *yvals;
376 im_log((aIMCTX,1,"i_arc_aa(im %p,(x,y)=(%f,%f), rad %f, d1 %f, d2 %f, col %p)",
377 im, x, y, rad, d1, d2, val));
379 arc_poly(&count, &xvals, &yvals, x, y, rad, d1, d2);
381 i_poly_aa(im, count, xvals, yvals, val);
388 =item i_arc_aa_cfill(im, x, y, rad, d1, d2, fill)
391 =synopsis i_arc_aa_cfill(im, 50, 50, 35, 90, 135, fill);
393 Anti-alias fills an arc centered at (x,y) with radius I<rad> covering
394 the range of angles in degrees from d1 to d2, with the fill object.
400 i_arc_aa_cfill(i_img *im, double x, double y, double rad, double d1, double d2,
402 double *xvals, *yvals;
406 im_log((aIMCTX,1,"i_arc_aa_cfill(im %p,(x,y)=(%f,%f), rad %f, d1 %f, d2 %f, fill %p)",
407 im, x, y, rad, d1, d2, fill));
409 arc_poly(&count, &xvals, &yvals, x, y, rad, d1, d2);
411 i_poly_aa_cfill(im, count, xvals, yvals, fill);
417 /* Temporary AA HACK */
420 typedef i_img_dim frac;
421 static frac float_to_frac(double x) { return (frac)(0.5+x*16.0); }
425 polar_to_plane(double cx, double cy, float angle, double radius, frac *x, frac *y) {
426 *x = float_to_frac(cx+radius*cos(angle));
427 *y = float_to_frac(cy+radius*sin(angle));
432 make_minmax_list(pIMCTX, i_mmarray *dot, double x, double y, double radius) {
434 float astep = radius>0.1 ? .5/radius : 10;
435 frac cx, cy, lx, ly, sx, sy;
437 im_log((aIMCTX, 1, "make_minmax_list(dot %p, x %.2f, y %.2f, radius %.2f)\n", dot, x, y, radius));
439 polar_to_plane(x, y, angle, radius, &sx, &sy);
441 for(angle = 0.0; angle<361; angle +=astep) {
443 polar_to_plane(x, y, angle, radius, &cx, &cy);
446 if (fabs(cx-lx) > fabs(cy-ly)) {
449 ccx = lx; lx = cx; cx = ccx;
450 ccy = ly; ly = cy; cy = ccy;
453 for(ccx=lx; ccx<=cx; ccx++) {
454 ccy = ly + ((cy-ly)*(ccx-lx))/(cx-lx);
455 i_mmarray_add(dot, ccx, ccy);
461 ccy = ly; ly = cy; cy = ccy;
462 ccx = lx; lx = cx; cx = ccx;
465 for(ccy=ly; ccy<=cy; ccy++) {
466 if (cy-ly) ccx = lx + ((cx-lx)*(ccy-ly))/(cy-ly); else ccx = lx;
467 i_mmarray_add(dot, ccx, ccy);
473 /* Get the number of subpixels covered */
477 i_pixel_coverage(i_mmarray *dot, i_img_dim x, i_img_dim y) {
483 for(cy=y*16; cy<(y+1)*16; cy++) {
484 frac tmin = dot->data[cy].min;
485 frac tmax = dot->data[cy].max;
487 if (tmax == -1 || tmin > maxx || tmax < minx) continue;
489 if (tmin < minx) tmin = minx;
490 if (tmax > maxx) tmax = maxx;
498 =item i_circle_aa(im, x, y, rad, color)
501 =synopsis i_circle_aa(im, 50, 50, 45, &color);
503 Anti-alias fills a circle centered at (x,y) for radius I<rad> with
509 i_circle_aa(i_img *im, double x, double y, double rad, const i_color *val) {
515 im_log((aIMCTX, 1, "i_circle_aa(im %p, centre(" i_DFp "), rad %.2f, val %p)\n",
516 im, i_DFcp(x, y), rad, val));
518 i_mmarray_cr(&dot,16*im->ysize);
519 make_minmax_list(aIMCTX, &dot, x, y, rad);
521 for(ly = 0; ly<im->ysize; ly++) {
522 int ix, cy, minx = INT_MAX, maxx = INT_MIN;
524 /* Find the left/rightmost set subpixels */
525 for(cy = 0; cy<16; cy++) {
526 frac tmin = dot.data[ly*16+cy].min;
527 frac tmax = dot.data[ly*16+cy].max;
528 if (tmax == -1) continue;
530 if (minx > tmin) minx = tmin;
531 if (maxx < tmax) maxx = tmax;
534 if (maxx == INT_MIN) continue; /* no work to be done for this row of pixels */
538 for(ix=minx; ix<=maxx; ix++) {
539 int cnt = i_pixel_coverage(&dot, ix, ly);
540 if (cnt>255) cnt = 255;
541 if (cnt) { /* should never be true */
543 float ratio = (float)cnt/255.0;
544 i_gpix(im, ix, ly, &temp);
545 for(ch=0;ch<im->channels; ch++) temp.channel[ch] = (unsigned char)((float)val->channel[ch]*ratio + (float)temp.channel[ch]*(1.0-ratio));
546 i_ppix(im, ix, ly, &temp);
554 =item i_circle_out(im, x, y, r, col)
557 =synopsis i_circle_out(im, 50, 50, 45, &color);
559 Draw a circle outline centered at (x,y) with radius r,
568 (x, y) - the center of the circle
572 r - the radius of the circle in pixels, must be non-negative
576 Returns non-zero on success.
584 i_circle_out(i_img *im, i_img_dim xc, i_img_dim yc, i_img_dim r,
585 const i_color *col) {
591 im_log((aIMCTX, 1, "i_circle_out(im %p, centre(" i_DFp "), rad %" i_DF ", col %p)\n",
592 im, i_DFcp(xc, yc), i_DFc(r), col));
594 im_clear_error(aIMCTX);
597 im_push_error(aIMCTX, 0, "circle: radius must be non-negative");
601 i_ppix(im, xc+r, yc, col);
602 i_ppix(im, xc-r, yc, col);
603 i_ppix(im, xc, yc+r, col);
604 i_ppix(im, xc, yc-r, col);
621 i_ppix(im, xc + x, yc + y, col);
622 i_ppix(im, xc + x, yc - y, col);
623 i_ppix(im, xc - x, yc + y, col);
624 i_ppix(im, xc - x, yc - y, col);
626 i_ppix(im, xc + y, yc + x, col);
627 i_ppix(im, xc + y, yc - x, col);
628 i_ppix(im, xc - y, yc + x, col);
629 i_ppix(im, xc - y, yc - x, col);
639 Convert an angle in degrees into an angle measure we can generate
640 simply from the numbers we have when drawing the circle.
646 arc_seg(double angle, int scale) {
647 i_img_dim seg = (angle + 45) / 90;
648 double remains = angle - seg * 90; /* should be in the range [-45,45] */
652 if (seg == 4 && remains > 0)
655 return scale * (seg * 2 + sin(remains * PI/180));
659 =item i_arc_out(im, x, y, r, d1, d2, col)
662 =synopsis i_arc_out(im, 50, 50, 45, 45, 135, &color);
664 Draw an arc outline centered at (x,y) with radius r, non-anti-aliased
665 over the angle range d1 through d2 degrees.
673 (x, y) - the center of the circle
677 r - the radius of the circle in pixels, must be non-negative
681 d1, d2 - the range of angles to draw the arc over, in degrees.
685 Returns non-zero on success.
693 i_arc_out(i_img *im, i_img_dim xc, i_img_dim yc, i_img_dim r,
694 double d1, double d2, const i_color *col) {
698 i_img_dim segs[2][2];
701 i_img_dim seg_d1, seg_d2;
703 i_img_dim scale = r + 1;
704 i_img_dim seg1 = scale * 2;
705 i_img_dim seg2 = scale * 4;
706 i_img_dim seg3 = scale * 6;
707 i_img_dim seg4 = scale * 8;
710 im_log((aIMCTX,1,"i_arc_out(im %p,centre(" i_DFp "), rad %" i_DF ", d1 %f, d2 %f, col %p)",
711 im, i_DFcp(xc, yc), i_DFc(r), d1, d2, col));
713 im_clear_error(aIMCTX);
716 im_push_error(aIMCTX, 0, "arc: radius must be non-negative");
720 return i_circle_out(im, xc, yc, r, col);
723 d1 += 360 * floor((-d1 + 359) / 360);
725 d2 += 360 * floor((-d2 + 359) / 360);
728 seg_d1 = arc_seg(d1, scale);
729 seg_d2 = arc_seg(d2, scale);
730 if (seg_d2 < seg_d1) {
731 /* split into two segments */
744 for (seg_num = 0; seg_num < seg_count; ++seg_num) {
745 i_img_dim seg_start = segs[seg_num][0];
746 i_img_dim seg_end = segs[seg_num][1];
748 i_ppix(im, xc+r, yc, col);
749 if (seg_start <= seg1 && seg_end >= seg1)
750 i_ppix(im, xc, yc+r, col);
751 if (seg_start <= seg2 && seg_end >= seg2)
752 i_ppix(im, xc-r, yc, col);
753 if (seg_start <= seg3 && seg_end >= seg3)
754 i_ppix(im, xc, yc-r, col);
772 if (seg_start <= sin_th && seg_end >= sin_th)
773 i_ppix(im, xc + x, yc + y, col);
774 if (seg_start <= seg1 - sin_th && seg_end >= seg1 - sin_th)
775 i_ppix(im, xc + y, yc + x, col);
777 if (seg_start <= seg1 + sin_th && seg_end >= seg1 + sin_th)
778 i_ppix(im, xc - y, yc + x, col);
779 if (seg_start <= seg2 - sin_th && seg_end >= seg2 - sin_th)
780 i_ppix(im, xc - x, yc + y, col);
782 if (seg_start <= seg2 + sin_th && seg_end >= seg2 + sin_th)
783 i_ppix(im, xc - x, yc - y, col);
784 if (seg_start <= seg3 - sin_th && seg_end >= seg3 - sin_th)
785 i_ppix(im, xc - y, yc - x, col);
787 if (seg_start <= seg3 + sin_th && seg_end >= seg3 + sin_th)
788 i_ppix(im, xc + y, yc - x, col);
789 if (seg_start <= seg4 - sin_th && seg_end >= seg4 - sin_th)
790 i_ppix(im, xc + x, yc - y, col);
798 cover(i_img_dim r, i_img_dim j) {
799 double rjsqrt = sqrt(r*r - j*j);
801 return ceil(rjsqrt) - rjsqrt;
805 =item i_circle_out_aa(im, xc, yc, r, col)
807 =synopsis i_circle_out_aa(im, 50, 50, 45, &color);
809 Draw a circle outline centered at (x,y) with radius r, anti-aliased.
817 (xc, yc) - the center of the circle
821 r - the radius of the circle in pixels, must be non-negative
825 col - an i_color for the color to draw in.
829 Returns non-zero on success.
833 Based on "Fast Anti-Aliased Circle Generation", Xiaolin Wu, Graphics
836 I use floating point for I<D> since for large circles the precision of
837 a [0,255] value isn't sufficient when approaching the end of the
843 i_circle_out_aa(i_img *im, i_img_dim xc, i_img_dim yc, i_img_dim r, const i_color *col) {
846 i_color workc = *col;
847 int orig_alpha = col->channel[3];
850 im_log((aIMCTX,1,"i_circle_out_aa(im %p,centre(" i_DFp "), rad %" i_DF ", col %p)",
851 im, i_DFcp(xc, yc), i_DFc(r), col));
853 im_clear_error(aIMCTX);
855 im_push_error(aIMCTX, 0, "arc: radius must be non-negative");
861 i_ppix_norm(im, xc+i, yc+j, col);
862 i_ppix_norm(im, xc-i, yc+j, col);
863 i_ppix_norm(im, xc+j, yc+i, col);
864 i_ppix_norm(im, xc+j, yc-i, col);
871 cv = (int)(d * 255 + 0.5);
877 workc.channel[3] = orig_alpha * inv_cv / 255;
878 i_ppix_norm(im, xc+i, yc+j, &workc);
879 i_ppix_norm(im, xc-i, yc+j, &workc);
880 i_ppix_norm(im, xc+i, yc-j, &workc);
881 i_ppix_norm(im, xc-i, yc-j, &workc);
884 i_ppix_norm(im, xc+j, yc+i, &workc);
885 i_ppix_norm(im, xc-j, yc+i, &workc);
886 i_ppix_norm(im, xc+j, yc-i, &workc);
887 i_ppix_norm(im, xc-j, yc-i, &workc);
891 workc.channel[3] = orig_alpha * cv / 255;
892 i_ppix_norm(im, xc+i-1, yc+j, &workc);
893 i_ppix_norm(im, xc-i+1, yc+j, &workc);
894 i_ppix_norm(im, xc+i-1, yc-j, &workc);
895 i_ppix_norm(im, xc-i+1, yc-j, &workc);
898 i_ppix_norm(im, xc+j, yc+i-1, &workc);
899 i_ppix_norm(im, xc-j, yc+i-1, &workc);
900 i_ppix_norm(im, xc+j, yc-i+1, &workc);
901 i_ppix_norm(im, xc-j, yc-i+1, &workc);
911 =item i_arc_out_aa(im, xc, yc, r, d1, d2, col)
913 =synopsis i_arc_out_aa(im, 50, 50, 45, 45, 125, &color);
915 Draw a circle arc outline centered at (x,y) with radius r, from angle
916 d1 degrees through angle d2 degrees, anti-aliased.
924 (xc, yc) - the center of the circle
928 r - the radius of the circle in pixels, must be non-negative
932 d1, d2 - the range of angle in degrees to draw the arc through. If
933 d2-d1 >= 360 a full circle is drawn.
937 Returns non-zero on success.
941 Based on "Fast Anti-Aliased Circle Generation", Xiaolin Wu, Graphics
947 i_arc_out_aa(i_img *im, i_img_dim xc, i_img_dim yc, i_img_dim r, double d1, double d2, const i_color *col) {
950 i_color workc = *col;
951 i_img_dim segs[2][2];
954 i_img_dim seg_d1, seg_d2;
956 int orig_alpha = col->channel[3];
957 i_img_dim scale = r + 1;
958 i_img_dim seg1 = scale * 2;
959 i_img_dim seg2 = scale * 4;
960 i_img_dim seg3 = scale * 6;
961 i_img_dim seg4 = scale * 8;
964 im_log((aIMCTX,1,"i_arc_out_aa(im %p,centre(" i_DFp "), rad %" i_DF ", d1 %f, d2 %f, col %p)",
965 im, i_DFcp(xc, yc), i_DFc(r), d1, d2, col));
967 im_clear_error(aIMCTX);
969 im_push_error(aIMCTX, 0, "arc: radius must be non-negative");
973 return i_circle_out_aa(im, xc, yc, r, col);
976 d1 += 360 * floor((-d1 + 359) / 360);
978 d2 += 360 * floor((-d2 + 359) / 360);
981 seg_d1 = arc_seg(d1, scale);
982 seg_d2 = arc_seg(d2, scale);
983 if (seg_d2 < seg_d1) {
984 /* split into two segments */
997 for (seg_num = 0; seg_num < seg_count; ++seg_num) {
998 i_img_dim seg_start = segs[seg_num][0];
999 i_img_dim seg_end = segs[seg_num][1];
1006 i_ppix_norm(im, xc+i, yc+j, col);
1007 if (seg_start <= seg1 && seg_end >= seg1)
1008 i_ppix_norm(im, xc+j, yc+i, col);
1009 if (seg_start <= seg2 && seg_end >= seg2)
1010 i_ppix_norm(im, xc-i, yc+j, col);
1011 if (seg_start <= seg3 && seg_end >= seg3)
1012 i_ppix_norm(im, xc+j, yc-i, col);
1019 cv = (int)(d * 255 + 0.5);
1026 workc.channel[3] = orig_alpha * inv_cv / 255;
1028 if (seg_start <= sin_th && seg_end >= sin_th)
1029 i_ppix_norm(im, xc+i, yc+j, &workc);
1030 if (seg_start <= seg2 - sin_th && seg_end >= seg2 - sin_th)
1031 i_ppix_norm(im, xc-i, yc+j, &workc);
1032 if (seg_start <= seg4 - sin_th && seg_end >= seg4 - sin_th)
1033 i_ppix_norm(im, xc+i, yc-j, &workc);
1034 if (seg_start <= seg2 + sin_th && seg_end >= seg2 + sin_th)
1035 i_ppix_norm(im, xc-i, yc-j, &workc);
1038 if (seg_start <= seg1 - sin_th && seg_end >= seg1 - sin_th)
1039 i_ppix_norm(im, xc+j, yc+i, &workc);
1040 if (seg_start <= seg1 + sin_th && seg_end >= seg1 + sin_th)
1041 i_ppix_norm(im, xc-j, yc+i, &workc);
1042 if (seg_start <= seg3 + sin_th && seg_end >= seg3 + sin_th)
1043 i_ppix_norm(im, xc+j, yc-i, &workc);
1044 if (seg_start <= seg3 - sin_th && seg_end >= seg3 - sin_th)
1045 i_ppix_norm(im, xc-j, yc-i, &workc);
1049 workc.channel[3] = orig_alpha * cv / 255;
1050 if (seg_start <= sin_th && seg_end >= sin_th)
1051 i_ppix_norm(im, xc+i-1, yc+j, &workc);
1052 if (seg_start <= seg2 - sin_th && seg_end >= seg2 - sin_th)
1053 i_ppix_norm(im, xc-i+1, yc+j, &workc);
1054 if (seg_start <= seg4 - sin_th && seg_end >= seg4 - sin_th)
1055 i_ppix_norm(im, xc+i-1, yc-j, &workc);
1056 if (seg_start <= seg2 + sin_th && seg_end >= seg2 + sin_th)
1057 i_ppix_norm(im, xc-i+1, yc-j, &workc);
1059 if (seg_start <= seg1 - sin_th && seg_end >= seg1 - sin_th)
1060 i_ppix_norm(im, xc+j, yc+i-1, &workc);
1061 if (seg_start <= seg1 + sin_th && seg_end >= seg1 + sin_th)
1062 i_ppix_norm(im, xc-j, yc+i-1, &workc);
1063 if (seg_start <= seg3 + sin_th && seg_end >= seg3 + sin_th)
1064 i_ppix_norm(im, xc+j, yc-i+1, &workc);
1065 if (seg_start <= seg3 - sin_th && seg_end >= seg3 - sin_th)
1066 i_ppix_norm(im, xc-j, yc-i+1, &workc);
1076 =item i_box(im, x1, y1, x2, y2, color)
1079 =synopsis i_box(im, 0, 0, im->xsize-1, im->ysize-1, &color).
1081 Outlines the box from (x1,y1) to (x2,y2) inclusive with I<color>.
1087 i_box(i_img *im,i_img_dim x1,i_img_dim y1,i_img_dim x2,i_img_dim y2,const i_color *val) {
1091 im_log((aIMCTX, 1,"i_box(im* %p, p1(" i_DFp "), p2(" i_DFp "),val %p)\n",
1092 im, i_DFcp(x1,y1), i_DFcp(x2,y2), val));
1093 for(x=x1;x<x2+1;x++) {
1094 i_ppix(im,x,y1,val);
1095 i_ppix(im,x,y2,val);
1097 for(y=y1;y<y2+1;y++) {
1098 i_ppix(im,x1,y,val);
1099 i_ppix(im,x2,y,val);
1104 =item i_box_filled(im, x1, y1, x2, y2, color)
1107 =synopsis i_box_filled(im, 0, 0, im->xsize-1, im->ysize-1, &color);
1109 Fills the box from (x1,y1) to (x2,y2) inclusive with color.
1115 i_box_filled(i_img *im,i_img_dim x1,i_img_dim y1,i_img_dim x2,i_img_dim y2, const i_color *val) {
1116 i_img_dim x, y, width;
1120 im_log((aIMCTX,1,"i_box_filled(im* %p, p1(" i_DFp "), p2(" i_DFp "),val %p)\n",
1121 im, i_DFcp(x1, y1), i_DFcp(x2,y2) ,val));
1123 if (x1 > x2 || y1 > y2
1125 || x1 >= im->xsize || y1 > im->ysize)
1130 if (x2 >= im->xsize)
1134 if (y2 >= im->ysize)
1137 width = x2 - x1 + 1;
1139 if (im->type == i_palette_type
1140 && i_findcolor(im, val, &index)) {
1141 i_palidx *line = mymalloc(sizeof(i_palidx) * width);
1143 for (x = 0; x < width; ++x)
1146 for (y = y1; y <= y2; ++y)
1147 i_ppal(im, x1, x2+1, y, line);
1152 i_color *line = mymalloc(sizeof(i_color) * width);
1154 for (x = 0; x < width; ++x)
1157 for (y = y1; y <= y2; ++y)
1158 i_plin(im, x1, x2+1, y, line);
1165 =item i_box_filledf(im, x1, y1, x2, y2, color)
1168 =synopsis i_box_filledf(im, 0, 0, im->xsize-1, im->ysize-1, &fcolor);
1170 Fills the box from (x1,y1) to (x2,y2) inclusive with a floating point
1177 i_box_filledf(i_img *im,i_img_dim x1,i_img_dim y1,i_img_dim x2,i_img_dim y2, const i_fcolor *val) {
1178 i_img_dim x, y, width;
1181 im_log((aIMCTX, 1,"i_box_filledf(im* %p, p1(" i_DFp "), p2(" i_DFp "),val %p)\n",
1182 im, i_DFcp(x1, y1), i_DFcp(x2, y2), val));
1184 if (x1 > x2 || y1 > y2
1186 || x1 >= im->xsize || y1 > im->ysize)
1191 if (x2 >= im->xsize)
1195 if (y2 >= im->ysize)
1198 width = x2 - x1 + 1;
1200 if (im->bits <= 8) {
1202 c.rgba.r = SampleFTo8(val->rgba.r);
1203 c.rgba.g = SampleFTo8(val->rgba.g);
1204 c.rgba.b = SampleFTo8(val->rgba.b);
1205 c.rgba.a = SampleFTo8(val->rgba.a);
1207 i_box_filled(im, x1, y1, x2, y2, &c);
1210 i_fcolor *line = mymalloc(sizeof(i_fcolor) * width);
1212 for (x = 0; x < width; ++x)
1215 for (y = y1; y <= y2; ++y)
1216 i_plinf(im, x1, x2+1, y, line);
1225 =item i_box_cfill(im, x1, y1, x2, y2, fill)
1228 =synopsis i_box_cfill(im, 0, 0, im->xsize-1, im->ysize-1, fill);
1230 Fills the box from (x1,y1) to (x2,y2) inclusive with fill.
1236 i_box_cfill(i_img *im,i_img_dim x1,i_img_dim y1,i_img_dim x2,i_img_dim y2,i_fill_t *fill) {
1240 im_log((aIMCTX,1,"i_box_cfill(im* %p, p1(" i_DFp "), p2(" i_DFp "), fill %p)\n",
1241 im, i_DFcp(x1, y1), i_DFcp(x2,y2), fill));
1250 if (y2 >= im->ysize)
1252 if (x1 >= x2 || y1 > y2)
1255 i_render_init(&r, im, x2-x1);
1257 i_render_fill(&r, x1, y1, x2-x1, NULL, fill);
1264 =item i_line(C<im>, C<x1>, C<y1>, C<x2>, C<y2>, C<color>, C<endp>)
1268 =for stopwords Bresenham's
1270 Draw a line to image using Bresenham's line drawing algorithm
1272 im - image to draw to
1273 x1 - starting x coordinate
1274 y1 - starting x coordinate
1275 x2 - starting x coordinate
1276 y2 - starting x coordinate
1277 color - color to write to image
1278 endp - endpoint flag (boolean)
1284 i_line(i_img *im, i_img_dim x1, i_img_dim y1, i_img_dim x2, i_img_dim y2, const i_color *val, int endp) {
1293 /* choose variable to iterate on */
1294 if (i_abs(dx) > i_abs(dy)) {
1295 i_img_dim dx2, dy2, cpy;
1300 t = x1; x1 = x2; x2 = t;
1301 t = y1; y1 = y2; y2 = t;
1319 for(x=x1; x<x2-1; x++) {
1326 i_ppix(im, x+1, y, val);
1329 i_img_dim dy2, dx2, cpx;
1334 t = x1; x1 = x2; x2 = t;
1335 t = y1; y1 = y2; y2 = t;
1353 for(y=y1; y<y2-1; y++) {
1360 i_ppix(im, x, y+1, val);
1364 i_ppix(im, x1, y1, val);
1365 i_ppix(im, x2, y2, val);
1367 if (x1 != x2 || y1 != y2)
1368 i_ppix(im, x1, y1, val);
1374 i_line_dda(i_img *im, i_img_dim x1, i_img_dim y1, i_img_dim x2, i_img_dim y2, i_color *val) {
1379 for(x=x1; x<=x2; x++) {
1380 dy = y1+ (x-x1)/(double)(x2-x1)*(y2-y1);
1381 i_ppix(im, x, (i_img_dim)(dy+0.5), val);
1386 =item i_line_aa(C<im>, C<x1>, C<x2>, C<y1>, C<y2>, C<color>, C<endp>)
1390 Anti-alias draws a line from (x1,y1) to (x2, y2) in color.
1392 The point (x2, y2) is drawn only if C<endp> is set.
1398 i_line_aa(i_img *im, i_img_dim x1, i_img_dim y1, i_img_dim x2, i_img_dim y2, const i_color *val, int endp) {
1406 /* choose variable to iterate on */
1407 if (i_abs(dx) > i_abs(dy)) {
1408 i_img_dim dx2, dy2, cpy;
1413 t = x1; x1 = x2; x2 = t;
1414 t = y1; y1 = y2; y2 = t;
1428 p = dy2 - dx2; /* this has to be like this for AA */
1432 for(x=x1; x<x2-1; x++) {
1435 double t = (dy) ? -(float)(p)/(float)(dx2) : 1;
1442 i_gpix(im,x+1,y,&tval);
1443 for(ch=0;ch<im->channels;ch++)
1444 tval.channel[ch]=(unsigned char)(t1*(float)tval.channel[ch]+t2*(float)val->channel[ch]);
1445 i_ppix(im,x+1,y,&tval);
1447 i_gpix(im,x+1,y+cpy,&tval);
1448 for(ch=0;ch<im->channels;ch++)
1449 tval.channel[ch]=(unsigned char)(t2*(float)tval.channel[ch]+t1*(float)val->channel[ch]);
1450 i_ppix(im,x+1,y+cpy,&tval);
1460 i_img_dim dy2, dx2, cpx;
1465 t = x1; x1 = x2; x2 = t;
1466 t = y1; y1 = y2; y2 = t;
1480 p = dx2 - dy2; /* this has to be like this for AA */
1484 for(y=y1; y<y2-1; y++) {
1487 double t = (dx) ? -(double)(p)/(double)(dy2) : 1;
1494 i_gpix(im,x,y+1,&tval);
1495 for(ch=0;ch<im->channels;ch++)
1496 tval.channel[ch]=(unsigned char)(t1*(double)tval.channel[ch]+t2*(double)val->channel[ch]);
1497 i_ppix(im,x,y+1,&tval);
1499 i_gpix(im,x+cpx,y+1,&tval);
1500 for(ch=0;ch<im->channels;ch++)
1501 tval.channel[ch]=(unsigned char)(t2*(double)tval.channel[ch]+t1*(double)val->channel[ch]);
1502 i_ppix(im,x+cpx,y+1,&tval);
1515 i_ppix(im, x1, y1, val);
1516 i_ppix(im, x2, y2, val);
1518 if (x1 != x2 || y1 != y2)
1519 i_ppix(im, x1, y1, val);
1526 perm(i_img_dim n,i_img_dim k) {
1530 for(i=k+1;i<=n;i++) r*=i;
1531 for(i=1;i<=(n-k);i++) r/=i;
1536 /* Note in calculating t^k*(1-t)^(n-k)
1537 we can start by using t^0=1 so this simplifies to
1538 t^0*(1-t)^n - we want to multiply that with t/(1-t) each iteration
1539 to get a new level - this may lead to errors who knows lets test it */
1542 i_bezier_multi(i_img *im,int l,const double *x,const double *y, const i_color *val) {
1546 i_img_dim lx = 0,ly = 0;
1550 /* this is the same size as the x and y arrays, so shouldn't overflow */
1551 bzcoef=mymalloc(sizeof(double)*l); /* checked 5jul05 tonyc */
1552 for(k=0;k<l;k++) bzcoef[k]=perm(n,k);
1556 /* for(k=0;k<l;k++) printf("bzcoef: %d -> %f\n",k,bzcoef[k]); */
1558 for(t=0;t<=1;t+=0.005) {
1563 /* cx+=bzcoef[k]*x[k]*pow(t,k)*pow(1-t,n-k);
1564 cy+=bzcoef[k]*y[k]*pow(t,k)*pow(1-t,n-k);*/
1566 cx+=bzcoef[k]*x[k]*ccoef;
1567 cy+=bzcoef[k]*y[k]*ccoef;
1570 /* printf("%f -> (%d,%d)\n",t,(int)(0.5+cx),(int)(0.5+cy)); */
1572 i_line_aa(im,lx,ly,(i_img_dim)(0.5+cx),(i_img_dim)(0.5+cy),val, 1);
1574 /* i_ppix(im,(i_img_dim)(0.5+cx),(i_img_dim)(0.5+cy),val); */
1575 lx=(i_img_dim)(0.5+cx);
1576 ly=(i_img_dim)(0.5+cy);
1584 REF: Graphics Gems I. page 282+
1588 /* This should be moved into a seperate file? */
1590 /* This is the truncation used:
1592 a double is multiplied by 16 and then truncated.
1593 This means that 0 -> 0
1594 So a triangle of (0,0) (10,10) (10,0) Will look like it's
1595 not filling the (10,10) point nor the (10,0)-(10,10) line segment
1600 /* Flood fill algorithm - based on the Ken Fishkins (pixar) gem in
1605 i_img_dim mylx,myrx;
1606 i_img_dim dadlx,dadrx;
1615 struct stack_element {
1616 i_img_dim myLx,myRx;
1617 i_img_dim dadLx,dadRx;
1623 /* create the link data to put push onto the stack */
1626 struct stack_element*
1627 crdata(i_img_dim left,i_img_dim right,i_img_dim dadl,i_img_dim dadr,i_img_dim y, int dir) {
1628 struct stack_element *ste;
1629 ste = mymalloc(sizeof(struct stack_element)); /* checked 5jul05 tonyc */
1635 ste->myDirection = dir;
1639 /* i_ccomp compares two colors and gives true if they are the same */
1641 typedef int (*ff_cmpfunc)(i_color const *c1, i_color const *c2, int channels);
1644 i_ccomp_normal(i_color const *val1, i_color const *val2, int ch) {
1646 for(i = 0; i < ch; i++)
1647 if (val1->channel[i] !=val2->channel[i])
1653 i_ccomp_border(i_color const *val1, i_color const *val2, int ch) {
1655 for(i = 0; i < ch; i++)
1656 if (val1->channel[i] !=val2->channel[i])
1662 i_lspan(i_img *im, i_img_dim seedx, i_img_dim seedy, i_color const *val, ff_cmpfunc cmpfunc) {
1665 if (seedx-1 < 0) break;
1666 i_gpix(im,seedx-1,seedy,&cval);
1667 if (!cmpfunc(val,&cval,im->channels))
1675 i_rspan(i_img *im, i_img_dim seedx, i_img_dim seedy, i_color const *val, ff_cmpfunc cmpfunc) {
1678 if (seedx+1 > im->xsize-1) break;
1679 i_gpix(im,seedx+1,seedy,&cval);
1680 if (!cmpfunc(val,&cval,im->channels)) break;
1686 /* Macro to create a link and push on to the list */
1688 #define ST_PUSH(left,right,dadl,dadr,y,dir) do { \
1689 struct stack_element *s = crdata(left,right,dadl,dadr,y,dir); \
1690 llist_push(st,&s); \
1693 /* pops the shadow on TOS into local variables lx,rx,y,direction,dadLx and dadRx */
1694 /* No overflow check! */
1696 #define ST_POP() do { \
1697 struct stack_element *s; \
1704 direction = s->myDirection; \
1708 #define ST_STACK(dir,dadLx,dadRx,lx,rx,y) do { \
1709 i_img_dim pushrx = rx+1; \
1710 i_img_dim pushlx = lx-1; \
1711 ST_PUSH(lx,rx,pushlx,pushrx,y+dir,dir); \
1713 ST_PUSH(dadRx+1,rx,pushlx,pushrx,y-dir,-dir); \
1714 if (lx < dadLx) ST_PUSH(lx,dadLx-1,pushlx,pushrx,y-dir,-dir); \
1717 #define SET(x,y) btm_set(btm,x,y)
1719 /* INSIDE returns true if pixel is correct color and we haven't set it before. */
1720 #define INSIDE(x,y, seed) ((!btm_test(btm,x,y) && ( i_gpix(im,x,y,&cval),cmpfunc(seed,&cval,channels) ) ))
1724 /* The function that does all the real work */
1726 static struct i_bitmap *
1727 i_flood_fill_low(i_img *im,i_img_dim seedx,i_img_dim seedy,
1728 i_img_dim *bxminp, i_img_dim *bxmaxp, i_img_dim *byminp, i_img_dim *bymaxp,
1729 i_color const *seed, ff_cmpfunc cmpfunc) {
1733 i_img_dim bxmin = seedx;
1734 i_img_dim bxmax = seedx;
1735 i_img_dim bymin = seedy;
1736 i_img_dim bymax = seedy;
1739 struct i_bitmap *btm;
1742 i_img_dim xsize,ysize;
1745 channels = im->channels;
1749 btm = btm_new(xsize, ysize);
1750 st = llist_new(100, sizeof(struct stack_element*));
1752 /* Find the starting span and fill it */
1753 ltx = i_lspan(im, seedx, seedy, seed, cmpfunc);
1754 rtx = i_rspan(im, seedx, seedy, seed, cmpfunc);
1755 for(tx=ltx; tx<=rtx; tx++) SET(tx, seedy);
1759 ST_PUSH(ltx, rtx, ltx, rtx, seedy+1, 1);
1760 ST_PUSH(ltx, rtx, ltx, rtx, seedy-1, -1);
1763 /* Stack variables */
1765 i_img_dim dadLx,dadRx;
1772 ST_POP(); /* sets lx, rx, dadLx, dadRx, y, direction */
1775 if (y<0 || y>ysize-1) continue;
1776 if (bymin > y) bymin=y; /* in the worst case an extra line */
1777 if (bymax < y) bymax=y;
1781 if ( lx >= 0 && (wasIn = INSIDE(lx, y, seed)) ) {
1784 while(lx >= 0 && INSIDE(lx, y, seed)) {
1790 if (bxmin > lx) bxmin = lx;
1791 while(x <= xsize-1) {
1792 /* printf("x=%d\n",x); */
1795 if (INSIDE(x, y, seed)) {
1796 /* case 1: was inside, am still inside */
1799 /* case 2: was inside, am no longer inside: just found the
1800 right edge of a span */
1801 ST_STACK(direction, dadLx, dadRx, lx, (x-1), y);
1803 if (bxmax < x) bxmax = x;
1807 if (x > rx) goto EXT;
1808 if (INSIDE(x, y, seed)) {
1810 /* case 3: Wasn't inside, am now: just found the start of a new run */
1814 /* case 4: Wasn't inside, still isn't */
1819 EXT: /* out of loop */
1821 /* hit an edge of the frame buffer while inside a run */
1822 ST_STACK(direction, dadLx, dadRx, lx, (x-1), y);
1823 if (bxmax < x) bxmax = x;
1838 =item i_flood_fill(C<im>, C<seedx>, C<seedy>, C<color>)
1841 =synopsis i_flood_fill(im, 50, 50, &color);
1843 Flood fills the 4-connected region starting from the point (C<seedx>,
1844 C<seedy>) with I<color>.
1846 Returns false if (C<seedx>, C<seedy>) are outside the image.
1852 i_flood_fill(i_img *im, i_img_dim seedx, i_img_dim seedy, const i_color *dcol) {
1853 i_img_dim bxmin, bxmax, bymin, bymax;
1854 struct i_bitmap *btm;
1859 im_log((aIMCTX, 1, "i_flood_fill(im %p, seed(" i_DFp "), col %p)",
1860 im, i_DFcp(seedx, seedy), dcol));
1862 im_clear_error(aIMCTX);
1863 if (seedx < 0 || seedx >= im->xsize ||
1864 seedy < 0 || seedy >= im->ysize) {
1865 im_push_error(aIMCTX, 0, "i_flood_cfill: Seed pixel outside of image");
1869 /* Get the reference color */
1870 i_gpix(im, seedx, seedy, &val);
1872 btm = i_flood_fill_low(im, seedx, seedy, &bxmin, &bxmax, &bymin, &bymax,
1873 &val, i_ccomp_normal);
1875 for(y=bymin;y<=bymax;y++)
1876 for(x=bxmin;x<=bxmax;x++)
1877 if (btm_test(btm,x,y))
1878 i_ppix(im,x,y,dcol);
1884 =item i_flood_cfill(C<im>, C<seedx>, C<seedy>, C<fill>)
1887 =synopsis i_flood_cfill(im, 50, 50, fill);
1889 Flood fills the 4-connected region starting from the point (C<seedx>,
1890 C<seedy>) with C<fill>.
1892 Returns false if (C<seedx>, C<seedy>) are outside the image.
1898 i_flood_cfill(i_img *im, i_img_dim seedx, i_img_dim seedy, i_fill_t *fill) {
1899 i_img_dim bxmin, bxmax, bymin, bymax;
1900 struct i_bitmap *btm;
1904 im_log((aIMCTX, 1, "i_flood_cfill(im %p, seed(" i_DFp "), fill %p)",
1905 im, i_DFcp(seedx, seedy), fill));
1907 im_clear_error(aIMCTX);
1909 if (seedx < 0 || seedx >= im->xsize ||
1910 seedy < 0 || seedy >= im->ysize) {
1911 im_push_error(aIMCTX, 0, "i_flood_cfill: Seed pixel outside of image");
1915 /* Get the reference color */
1916 i_gpix(im, seedx, seedy, &val);
1918 btm = i_flood_fill_low(im, seedx, seedy, &bxmin, &bxmax, &bymin, &bymax,
1919 &val, i_ccomp_normal);
1921 cfill_from_btm(im, fill, btm, bxmin, bxmax, bymin, bymax);
1928 =item i_flood_fill_border(C<im>, C<seedx>, C<seedy>, C<color>, C<border>)
1931 =synopsis i_flood_fill_border(im, 50, 50, &color, &border);
1933 Flood fills the 4-connected region starting from the point (C<seedx>,
1934 C<seedy>) with C<color>, fill stops when the fill reaches a pixels
1935 with color C<border>.
1937 Returns false if (C<seedx>, C<seedy>) are outside the image.
1943 i_flood_fill_border(i_img *im, i_img_dim seedx, i_img_dim seedy, const i_color *dcol,
1944 const i_color *border) {
1945 i_img_dim bxmin, bxmax, bymin, bymax;
1946 struct i_bitmap *btm;
1950 im_log((aIMCTX, 1, "i_flood_cfill(im %p, seed(" i_DFp "), dcol %p, border %p)",
1951 im, i_DFcp(seedx, seedy), dcol, border));
1953 im_clear_error(aIMCTX);
1954 if (seedx < 0 || seedx >= im->xsize ||
1955 seedy < 0 || seedy >= im->ysize) {
1956 im_push_error(aIMCTX, 0, "i_flood_cfill: Seed pixel outside of image");
1960 btm = i_flood_fill_low(im, seedx, seedy, &bxmin, &bxmax, &bymin, &bymax,
1961 border, i_ccomp_border);
1963 for(y=bymin;y<=bymax;y++)
1964 for(x=bxmin;x<=bxmax;x++)
1965 if (btm_test(btm,x,y))
1966 i_ppix(im,x,y,dcol);
1972 =item i_flood_cfill_border(C<im>, C<seedx>, C<seedy>, C<fill>, C<border>)
1975 =synopsis i_flood_cfill_border(im, 50, 50, fill, border);
1977 Flood fills the 4-connected region starting from the point (C<seedx>,
1978 C<seedy>) with C<fill>, the fill stops when it reaches pixels of color
1981 Returns false if (C<seedx>, C<seedy>) are outside the image.
1987 i_flood_cfill_border(i_img *im, i_img_dim seedx, i_img_dim seedy, i_fill_t *fill,
1988 const i_color *border) {
1989 i_img_dim bxmin, bxmax, bymin, bymax;
1990 struct i_bitmap *btm;
1993 im_log((aIMCTX, 1, "i_flood_cfill_border(im %p, seed(" i_DFp "), fill %p, border %p)",
1994 im, i_DFcp(seedx, seedy), fill, border));
1996 im_clear_error(aIMCTX);
1998 if (seedx < 0 || seedx >= im->xsize ||
1999 seedy < 0 || seedy >= im->ysize) {
2000 im_push_error(aIMCTX, 0, "i_flood_cfill_border: Seed pixel outside of image");
2004 btm = i_flood_fill_low(im, seedx, seedy, &bxmin, &bxmax, &bymin, &bymax,
2005 border, i_ccomp_border);
2007 cfill_from_btm(im, fill, btm, bxmin, bxmax, bymin, bymax);
2015 cfill_from_btm(i_img *im, i_fill_t *fill, struct i_bitmap *btm,
2016 i_img_dim bxmin, i_img_dim bxmax, i_img_dim bymin, i_img_dim bymax) {
2022 i_render_init(&r, im, bxmax - bxmin + 1);
2024 for(y=bymin; y<=bymax; y++) {
2026 while (x <= bxmax) {
2027 while (x <= bxmax && !btm_test(btm, x, y)) {
2030 if (btm_test(btm, x, y)) {
2032 while (x <= bxmax && btm_test(btm, x, y)) {
2035 i_render_fill(&r, start, y, x-start, NULL, fill);