8 i_mmarray_cr(i_mmarray *ar,int l) {
12 ar->data=mymalloc(sizeof(minmax)*l);
13 for(i=0;i<l;i++) { ar->data[i].max=-1; ar->data[i].min=MAXINT; }
17 i_mmarray_dst(i_mmarray *ar) {
19 if (ar->data != NULL) { myfree(ar->data); ar->data=NULL; }
23 i_mmarray_add(i_mmarray *ar,int x,int y) {
24 if (y>-1 && y<ar->lines)
26 if (x<ar->data[y].min) ar->data[y].min=x;
27 if (x>ar->data[y].max) ar->data[y].max=x;
32 i_mmarray_gmin(i_mmarray *ar,int y) {
33 if (y>-1 && y<ar->lines) return ar->data[y].min;
38 i_mmarray_getm(i_mmarray *ar,int y) {
39 if (y>-1 && y<ar->lines) return ar->data[y].max;
44 i_mmarray_render(i_img *im,i_mmarray *ar,i_color *val) {
46 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);
50 i_mmarray_render_fill(i_img *im,i_mmarray *ar,i_fill_t *fill) {
52 if (im->bits == i_8_bits && fill->fill_with_color) {
53 i_color *line = mymalloc(sizeof(i_color) * im->xsize);
56 work = mymalloc(sizeof(i_color) * im->xsize);
57 for(y=0;y<ar->lines;y++) {
58 if (ar->data[y].max!=-1) {
60 w = ar->data[y].max-ar->data[y].min;
63 i_glin(im, x, x+w, y, line);
64 (fill->fill_with_color)(fill, x, y, w, im->channels, work);
65 (fill->combine)(line, work, im->channels, w);
68 (fill->fill_with_color)(fill, x, y, w, im->channels, line);
70 i_plin(im, x, x+w, y, line);
79 i_fcolor *line = mymalloc(sizeof(i_fcolor) * im->xsize);
80 i_fcolor *work = NULL;
82 work = mymalloc(sizeof(i_fcolor) * im->xsize);
83 for(y=0;y<ar->lines;y++) {
84 if (ar->data[y].max!=-1) {
86 w = ar->data[y].max-ar->data[y].min;
89 i_glinf(im, x, x+w, y, line);
90 (fill->fill_with_fcolor)(fill, x, y, w, im->channels, work);
91 (fill->combinef)(line, work, im->channels, w);
94 (fill->fill_with_fcolor)(fill, x, y, w, im->channels, line);
96 i_plinf(im, x, x+w, y, line);
109 i_arcdraw(int x1, int y1, int x2, int y2, i_mmarray *ar) {
113 alpha=(double)(y2-y1)/(double)(x2-x1);
116 if (x2<x1) { temp=x1; x1=x2; x2=temp; temp=y1; y1=y2; y2=temp; }
121 i_mmarray_add(ar,x1,(int)(dsec+0.5));
128 if (y2<y1) { temp=x1; x1=x2; x2=temp; temp=y1; y1=y2; y2=temp; }
133 i_mmarray_add(ar,(int)(dsec+0.5),y1);
140 i_mmarray_info(i_mmarray *ar) {
142 for(i=0;i<ar->lines;i++)
143 if (ar->data[i].max!=-1) printf("line %d: min=%d, max=%d.\n",i,ar->data[i].min,ar->data[i].max);
148 i_arc(i_img *im,int x,int y,float rad,float d1,float d2,i_color *val) {
153 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));
155 i_mmarray_cr(&dot,im->ysize);
157 x1=(int)(x+0.5+rad*cos(d1*PI/180.0));
158 y1=(int)(y+0.5+rad*sin(d1*PI/180.0));
159 fx=(float)x1; fy=(float)y1;
161 /* printf("x1: %d.\ny1: %d.\n",x1,y1); */
162 i_arcdraw(x, y, x1, y1, &dot);
164 x1=(int)(x+0.5+rad*cos(d2*PI/180.0));
165 y1=(int)(y+0.5+rad*sin(d2*PI/180.0));
167 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)));
169 /* printf("x1: %d.\ny1: %d.\n",x1,y1); */
170 i_arcdraw(x, y, x1, y1, &dot);
173 i_mmarray_render(im,&dot,val);
178 i_arc_cfill(i_img *im,int x,int y,float rad,float d1,float d2,i_fill_t *fill) {
183 mm_log((1,"i_arc_cfill(im* 0x%x,x %d,y %d,rad %.2f,d1 %.2f,d2 %.2f,fill 0x%x)\n",im,x,y,rad,d1,d2,fill));
185 i_mmarray_cr(&dot,im->ysize);
187 x1=(int)(x+0.5+rad*cos(d1*PI/180.0));
188 y1=(int)(y+0.5+rad*sin(d1*PI/180.0));
189 fx=(float)x1; fy=(float)y1;
191 /* printf("x1: %d.\ny1: %d.\n",x1,y1); */
192 i_arcdraw(x, y, x1, y1, &dot);
194 x1=(int)(x+0.5+rad*cos(d2*PI/180.0));
195 y1=(int)(y+0.5+rad*sin(d2*PI/180.0));
197 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)));
199 /* printf("x1: %d.\ny1: %d.\n",x1,y1); */
200 i_arcdraw(x, y, x1, y1, &dot);
203 i_mmarray_render_fill(im,&dot,fill);
209 /* Temporary AA HACK */
213 static frac float_to_frac(float x) { return (frac)(0.5+x*16.0); }
214 static int frac_sub (frac x) { return (x%16); }
215 static int frac_int (frac x) { return (x/16); }
216 static float frac_to_float(float x) { return (float)x/16.0; }
220 polar_to_plane(float cx, float cy, float angle, float radius, frac *x, frac *y) {
221 *x = float_to_frac(cx+radius*cos(angle));
222 *y = float_to_frac(cy+radius*sin(angle));
227 order_pair(frac *x, frac *y) {
240 make_minmax_list(i_mmarray *dot, float x, float y, float radius) {
242 float astep = radius>0.1 ? .5/radius : 10;
243 frac cx, cy, lx, ly, sx, sy;
245 mm_log((1, "make_minmax_list(dot %p, x %.2f, y %.2f, radius %.2f)\n", dot, x, y, radius));
247 polar_to_plane(x, y, angle, radius, &sx, &sy);
249 for(angle = 0.0; angle<361; angle +=astep) {
251 polar_to_plane(x, y, angle, radius, &cx, &cy);
254 if (fabs(cx-lx) > fabs(cy-ly)) {
257 ccx = lx; lx = cx; cx = ccx;
258 ccy = ly; ly = cy; cy = ccy;
261 for(ccx=lx; ccx<=cx; ccx++) {
262 ccy = ly + ((cy-ly)*(ccx-lx))/(cx-lx);
263 i_mmarray_add(dot, ccx, ccy);
269 ccy = ly; ly = cy; cy = ccy;
270 ccx = lx; lx = cx; cx = ccx;
273 for(ccy=ly; ccy<=cy; ccy++) {
274 if (cy-ly) ccx = lx + ((cx-lx)*(ccy-ly))/(cy-ly); else ccx = lx;
275 i_mmarray_add(dot, ccx, ccy);
281 /* Get the number of subpixels covered */
285 i_pixel_coverage(i_mmarray *dot, int x, int y) {
291 for(cy=y*16; cy<(y+1)*16; cy++) {
292 frac tmin = dot->data[cy].min;
293 frac tmax = dot->data[cy].max;
295 if (tmax == -1 || tmin > maxx || tmax < minx) continue;
297 if (tmin < minx) tmin = minx;
298 if (tmax > maxx) tmax = maxx;
306 i_circle_aa(i_img *im, float x, float y, float rad, i_color *val) {
311 mm_log((1, "i_circle_aa(im %p, x %d, y %d, rad %.2f, val %p)\n", im, x, y, rad, val));
313 i_mmarray_cr(&dot,16*im->ysize);
314 make_minmax_list(&dot, x, y, rad);
316 for(ly = 0; ly<im->ysize; ly++) {
317 int ix, cy, minx = INT_MAX, maxx = INT_MIN;
319 /* Find the left/rightmost set subpixels */
320 for(cy = 0; cy<16; cy++) {
321 frac tmin = dot.data[ly*16+cy].min;
322 frac tmax = dot.data[ly*16+cy].max;
323 if (tmax == -1) continue;
325 if (minx > tmin) minx = tmin;
326 if (maxx < tmax) maxx = tmax;
329 if (maxx == INT_MIN) continue; /* no work to be done for this row of pixels */
333 for(ix=minx; ix<=maxx; ix++) {
334 int cnt = i_pixel_coverage(&dot, ix, ly);
335 if (cnt>255) cnt = 255;
336 if (cnt) { /* should never be true */
338 float ratio = (float)cnt/255.0;
339 i_gpix(im, ix, ly, &temp);
340 for(ch=0;ch<im->channels; ch++) temp.channel[ch] = (unsigned char)((float)val->channel[ch]*ratio + (float)temp.channel[ch]*(1.0-ratio));
341 i_ppix(im, ix, ly, &temp);
354 i_box(i_img *im,int x1,int y1,int x2,int y2,i_color *val) {
356 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));
357 for(x=x1;x<x2+1;x++) {
361 for(y=y1;y<y2+1;y++) {
368 i_box_filled(i_img *im,int x1,int y1,int x2,int y2,i_color *val) {
370 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));
371 for(x=x1;x<x2+1;x++) for (y=y1;y<y2+1;y++) i_ppix(im,x,y,val);
375 i_box_cfill(i_img *im,int x1,int y1,int x2,int y2,i_fill_t *fill) {
376 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));
379 if (im->bits == i_8_bits && fill->fill_with_color) {
380 i_color *line = mymalloc(sizeof(i_color) * (x2 - x1));
381 i_color *work = NULL;
383 work = mymalloc(sizeof(i_color) * (x2-x1));
386 i_glin(im, x1, x2, y1, line);
387 (fill->fill_with_color)(fill, x1, y1, x2-x1, im->channels, work);
388 (fill->combine)(line, work, im->channels, x2-x1);
391 (fill->fill_with_color)(fill, x1, y1, x2-x1, im->channels, line);
393 i_plin(im, x1, x2, y1, line);
401 i_fcolor *line = mymalloc(sizeof(i_fcolor) * (x2 - x1));
403 work = mymalloc(sizeof(i_fcolor) * (x2 - x1));
407 i_glinf(im, x1, x2, y1, line);
408 (fill->fill_with_fcolor)(fill, x1, y1, x2-x1, im->channels, work);
409 (fill->combinef)(line, work, im->channels, x2-x1);
412 (fill->fill_with_fcolor)(fill, x1, y1, x2-x1, im->channels, line);
414 i_plinf(im, x1, x2, y1, line);
425 =item i_line(im, x1, y1, x2, y2, val, endp)
427 Draw a line to image using bresenhams linedrawing algorithm
429 im - image to draw to
430 x1 - starting x coordinate
431 y1 - starting x coordinate
432 x2 - starting x coordinate
433 y2 - starting x coordinate
434 val - color to write to image
435 endp - endpoint flag (boolean)
441 i_line(i_img *im, int x1, int y1, int x2, int y2, i_color *val, int endp) {
450 /* choose variable to iterate on */
451 if (abs(dx)>abs(dy)) {
457 t = x1; x1 = x2; x2 = t;
458 t = y1; y1 = y2; y2 = t;
476 for(x=x1; x<x2-1; x++) {
483 i_ppix(im, x+1, y, val);
491 t = x1; x1 = x2; x2 = t;
492 t = y1; y1 = y2; y2 = t;
510 for(y=y1; y<y2-1; y++) {
517 i_ppix(im, x, y+1, val);
521 i_ppix(im, x1, y1, val);
522 i_ppix(im, x2, y2, val);
524 if (x1 != x2 || y1 != y2)
525 i_ppix(im, x1, y1, val);
531 i_line_dda(i_img *im, int x1, int y1, int x2, int y2, i_color *val) {
536 for(x=x1; x<=x2; x++) {
537 dy = y1+ (x-x1)/(float)(x2-x1)*(y2-y1);
538 i_ppix(im, x, (int)(dy+0.5), val);
569 i_line_aa3(i_img *im,int x1,int y1,int x2,int y2,i_color *val) {
573 int temp,dx,dy,isec,ch;
575 mm_log((1,"i_line_aa(im* 0x%x,x1 %d,y1 %d,x2 %d,y2 %d,val 0x%x)\n",im,x1,y1,x2,y2,val));
580 if (abs(dx)>abs(dy)) { /* alpha < 1 */
581 if (x2<x1) { temp=x1; x1=x2; x2=temp; temp=y1; y1=y2; y2=temp; }
582 alpha=(float)(y2-y1)/(float)(x2-x1);
588 /* dfrac=1-(1-dfrac)*(1-dfrac); */
589 /* This is something we can play with to try to get better looking lines */
591 i_gpix(im,x1,isec,&tval);
592 for(ch=0;ch<im->channels;ch++) tval.channel[ch]=(unsigned char)(dfrac*(float)tval.channel[ch]+(1-dfrac)*(float)val->channel[ch]);
593 i_ppix(im,x1,isec,&tval);
595 i_gpix(im,x1,isec+1,&tval);
596 for(ch=0;ch<im->channels;ch++) tval.channel[ch]=(unsigned char)((1-dfrac)*(float)tval.channel[ch]+dfrac*(float)val->channel[ch]);
597 i_ppix(im,x1,isec+1,&tval);
603 if (y2<y1) { temp=y1; y1=y2; y2=temp; temp=x1; x1=x2; x2=temp; }
604 alpha=(float)(x2-x1)/(float)(y2-y1);
609 /* dfrac=sqrt(dfrac); */
610 /* This is something we can play with */
611 i_gpix(im,isec,y1,&tval);
612 for(ch=0;ch<im->channels;ch++) tval.channel[ch]=(unsigned char)(dfrac*(float)tval.channel[ch]+(1-dfrac)*(float)val->channel[ch]);
613 i_ppix(im,isec,y1,&tval);
615 i_gpix(im,isec+1,y1,&tval);
616 for(ch=0;ch<im->channels;ch++) tval.channel[ch]=(unsigned char)((1-dfrac)*(float)tval.channel[ch]+dfrac*(float)val->channel[ch]);
617 i_ppix(im,isec+1,y1,&tval);
629 i_line_aa(i_img *im, int x1, int y1, int x2, int y2, i_color *val, int endp) {
637 /* choose variable to iterate on */
638 if (abs(dx)>abs(dy)) {
644 t = x1; x1 = x2; x2 = t;
645 t = y1; y1 = y2; y2 = t;
659 p = dy2 - dx2; /* this has to be like this for AA */
663 for(x=x1; x<x2-1; x++) {
666 float t = (dy) ? -(float)(p)/(float)(dx2) : 1;
673 i_gpix(im,x+1,y,&tval);
674 for(ch=0;ch<im->channels;ch++)
675 tval.channel[ch]=(unsigned char)(t1*(float)tval.channel[ch]+t2*(float)val->channel[ch]);
676 i_ppix(im,x+1,y,&tval);
678 i_gpix(im,x+1,y+cpy,&tval);
679 for(ch=0;ch<im->channels;ch++)
680 tval.channel[ch]=(unsigned char)(t2*(float)tval.channel[ch]+t1*(float)val->channel[ch]);
681 i_ppix(im,x+1,y+cpy,&tval);
696 t = x1; x1 = x2; x2 = t;
697 t = y1; y1 = y2; y2 = t;
711 p = dx2 - dy2; /* this has to be like this for AA */
715 for(y=y1; y<y2-1; y++) {
718 float t = (dx) ? -(float)(p)/(float)(dy2) : 1;
725 i_gpix(im,x,y+1,&tval);
726 for(ch=0;ch<im->channels;ch++)
727 tval.channel[ch]=(unsigned char)(t1*(float)tval.channel[ch]+t2*(float)val->channel[ch]);
728 i_ppix(im,x,y+1,&tval);
730 i_gpix(im,x+cpx,y+1,&tval);
731 for(ch=0;ch<im->channels;ch++)
732 tval.channel[ch]=(unsigned char)(t2*(float)tval.channel[ch]+t1*(float)val->channel[ch]);
733 i_ppix(im,x+cpx,y+1,&tval);
746 i_ppix(im, x1, y1, val);
747 i_ppix(im, x2, y2, val);
749 if (x1 != x2 || y1 != y2)
750 i_ppix(im, x1, y1, val);
761 for(i=k+1;i<=n;i++) r*=i;
762 for(i=1;i<=(n-k);i++) r/=i;
767 /* Note in calculating t^k*(1-t)^(n-k)
768 we can start by using t^0=1 so this simplifies to
769 t^0*(1-t)^n - we want to multiply that with t/(1-t) each iteration
770 to get a new level - this may lead to errors who knows lets test it */
773 i_bezier_multi(i_img *im,int l,double *x,double *y,i_color *val) {
782 bzcoef=mymalloc(sizeof(double)*l);
783 for(k=0;k<l;k++) bzcoef[k]=perm(n,k);
787 /* for(k=0;k<l;k++) printf("bzcoef: %d -> %f\n",k,bzcoef[k]); */
789 for(t=0;t<=1;t+=0.005) {
794 /* cx+=bzcoef[k]*x[k]*pow(t,k)*pow(1-t,n-k);
795 cy+=bzcoef[k]*y[k]*pow(t,k)*pow(1-t,n-k);*/
797 cx+=bzcoef[k]*x[k]*ccoef;
798 cy+=bzcoef[k]*y[k]*ccoef;
801 /* printf("%f -> (%d,%d)\n",t,(int)(0.5+cx),(int)(0.5+cy)); */
803 i_line_aa(im,lx,ly,(int)(0.5+cx),(int)(0.5+cy),val, 1);
805 /* i_ppix(im,(int)(0.5+cx),(int)(0.5+cy),val); */
825 REF: Graphics Gems I. page 282+
829 /* This should be moved into a seperate file? */
831 /* This is the truncation used:
833 a double is multiplied by 16 and then truncated.
834 This means that 0 -> 0
835 So a triangle of (0,0) (10,10) (10,0) Will look like it's
836 not filling the (10,10) point nor the (10,0)-(10,10) line segment
841 /* Flood fill algorithm - based on the Ken Fishkins (pixar) gem in
856 struct stack_element {
864 /* create the link data to put push onto the stack */
867 struct stack_element*
868 crdata(int left,int right,int dadl,int dadr,int y, int dir) {
869 struct stack_element *ste;
870 ste = mymalloc(sizeof(struct stack_element));
876 ste->myDirection = dir;
880 /* i_ccomp compares two colors and gives true if they are the same */
883 i_ccomp(i_color *val1,i_color *val2,int ch) {
885 for(i=0;i<ch;i++) if (val1->channel[i] !=val2->channel[i]) return 0;
891 i_lspan(i_img *im, int seedx, int seedy, i_color *val) {
894 if (seedx-1 < 0) break;
895 i_gpix(im,seedx-1,seedy,&cval);
896 if (!i_ccomp(val,&cval,im->channels)) break;
903 i_rspan(i_img *im, int seedx, int seedy, i_color *val) {
906 if (seedx+1 > im->xsize-1) break;
907 i_gpix(im,seedx+1,seedy,&cval);
908 if (!i_ccomp(val,&cval,im->channels)) break;
914 /* Macro to create a link and push on to the list */
916 #define ST_PUSH(left,right,dadl,dadr,y,dir) do { \
917 struct stack_element *s = crdata(left,right,dadl,dadr,y,dir); \
921 /* pops the shadow on TOS into local variables lx,rx,y,direction,dadLx and dadRx */
922 /* No overflow check! */
924 #define ST_POP() do { \
925 struct stack_element *s; \
932 direction = s->myDirection; \
936 #define ST_STACK(dir,dadLx,dadRx,lx,rx,y) do { \
939 ST_PUSH(lx,rx,pushlx,pushrx,y+dir,dir); \
941 ST_PUSH(dadRx+1,rx,pushlx,pushrx,y-dir,-dir); \
942 if (lx < dadLx) ST_PUSH(lx,dadLx-1,pushlx,pushrx,y-dir,-dir); \
945 #define SET(x,y) btm_set(btm,x,y)
947 /* INSIDE returns true if pixel is correct color and we haven't set it before. */
948 #define INSIDE(x,y) ((!btm_test(btm,x,y) && ( i_gpix(im,x,y,&cval),i_ccomp(&val,&cval,channels) ) ))
952 /* The function that does all the real work */
954 static struct i_bitmap *
955 i_flood_fill_low(i_img *im,int seedx,int seedy,
956 int *bxminp, int *bxmaxp, int *byminp, int *bymaxp) {
974 struct i_bitmap *btm;
976 int channels,xsize,ysize;
979 channels = im->channels;
983 btm = btm_new(xsize, ysize);
984 st = llist_new(100, sizeof(struct stack_element*));
986 /* Get the reference color */
987 i_gpix(im, seedx, seedy, &val);
989 /* Find the starting span and fill it */
990 ltx = i_lspan(im, seedx, seedy, &val);
991 rtx = i_rspan(im, seedx, seedy, &val);
992 for(tx=ltx; tx<=rtx; tx++) SET(tx, seedy);
994 ST_PUSH(ltx, rtx, ltx, rtx, seedy+1, 1);
995 ST_PUSH(ltx, rtx, ltx, rtx, seedy-1, -1);
998 /* Stack variables */
1007 ST_POP(); /* sets lx, rx, dadLx, dadRx, y, direction */
1010 if (y<0 || y>ysize-1) continue;
1011 if (bymin > y) bymin=y; /* in the worst case an extra line */
1012 if (bymax < y) bymax=y;
1016 if ( lx >= 0 && (wasIn = INSIDE(lx, y)) ) {
1019 while(INSIDE(lx, y) && lx > 0) {
1025 if (bxmin > lx) bxmin = lx;
1026 while(x <= xsize-1) {
1027 /* printf("x=%d\n",x); */
1031 /* case 1: was inside, am still inside */
1034 /* case 2: was inside, am no longer inside: just found the
1035 right edge of a span */
1036 ST_STACK(direction, dadLx, dadRx, lx, (x-1), y);
1038 if (bxmax < x) bxmax = x;
1042 if (x > rx) goto EXT;
1045 /* case 3: Wasn't inside, am now: just found the start of a new run */
1049 /* case 4: Wasn't inside, still isn't */
1054 EXT: /* out of loop */
1056 /* hit an edge of the frame buffer while inside a run */
1057 ST_STACK(direction, dadLx, dadRx, lx, (x-1), y);
1058 if (bxmax < x) bxmax = x;
1076 i_flood_fill(i_img *im, int seedx, int seedy, i_color *dcol) {
1077 int bxmin, bxmax, bymin, bymax;
1078 struct i_bitmap *btm;
1082 if (seedx < 0 || seedx >= im->xsize ||
1083 seedy < 0 || seedy >= im->ysize) {
1084 i_push_error(0, "i_flood_cfill: Seed pixel outside of image");
1088 btm = i_flood_fill_low(im, seedx, seedy, &bxmin, &bxmax, &bymin, &bymax);
1090 for(y=bymin;y<=bymax;y++)
1091 for(x=bxmin;x<=bxmax;x++)
1092 if (btm_test(btm,x,y))
1093 i_ppix(im,x,y,dcol);
1101 i_flood_cfill(i_img *im, int seedx, int seedy, i_fill_t *fill) {
1102 int bxmin, bxmax, bymin, bymax;
1103 struct i_bitmap *btm;
1109 if (seedx < 0 || seedx >= im->xsize ||
1110 seedy < 0 || seedy >= im->ysize) {
1111 i_push_error(0, "i_flood_cfill: Seed pixel outside of image");
1115 btm = i_flood_fill_low(im, seedx, seedy, &bxmin, &bxmax, &bymin, &bymax);
1117 if (im->bits == i_8_bits && fill->fill_with_color) {
1118 i_color *line = mymalloc(sizeof(i_color) * (bxmax - bxmin));
1119 i_color *work = NULL;
1121 work = mymalloc(sizeof(i_color) * (bxmax - bxmin));
1123 for(y=bymin; y<=bymax; y++) {
1126 while (x < bxmax && !btm_test(btm, x, y)) {
1129 if (btm_test(btm, x, y)) {
1131 while (x < bxmax && btm_test(btm, x, y)) {
1134 if (fill->combine) {
1135 i_glin(im, start, x, y, line);
1136 (fill->fill_with_color)(fill, start, y, x-start, im->channels,
1138 (fill->combine)(line, work, im->channels, x-start);
1141 (fill->fill_with_color)(fill, start, y, x-start, im->channels,
1144 i_plin(im, start, x, y, line);
1153 i_fcolor *line = mymalloc(sizeof(i_fcolor) * (bxmax - bxmin));
1154 i_fcolor *work = NULL;
1156 work = mymalloc(sizeof(i_fcolor) * (bxmax - bxmin));
1158 for(y=bymin;y<=bymax;y++) {
1161 while (x < bxmax && !btm_test(btm, x, y)) {
1164 if (btm_test(btm, x, y)) {
1166 while (x < bxmax && btm_test(btm, x, y)) {
1169 if (fill->combinef) {
1170 i_glinf(im, start, x, y, line);
1171 (fill->fill_with_fcolor)(fill, start, y, x-start, im->channels,
1173 (fill->combinef)(line, work, im->channels, x-start);
1176 (fill->fill_with_fcolor)(fill, start, y, x-start, im->channels,
1179 i_plinf(im, start, x, y, line);