+#define IMAGER_NO_CONTEXT
#include "imager.h"
#include "draw.h"
#include "log.h"
work = *col;
i_adapt_colors(2, 4, &work, 1);
i_gpix(im, x, y, &src);
+ remains = 255 - work.channel[1];
dest_alpha = work.channel[1] + remains * src.channel[1] / 255;
if (work.channel[1] == 255) {
return i_ppix(im, x, y, &work);
case 4:
work = *col;
i_gpix(im, x, y, &src);
+ remains = 255 - work.channel[3];
dest_alpha = work.channel[3] + remains * src.channel[3] / 255;
if (work.channel[3] == 255) {
return i_ppix(im, x, y, &work);
static void
cfill_from_btm(i_img *im, i_fill_t *fill, struct i_bitmap *btm,
- int bxmin, int bxmax, int bymin, int bymax);
+ i_img_dim bxmin, i_img_dim bxmax, i_img_dim bymin, i_img_dim bymax);
void
-i_mmarray_cr(i_mmarray *ar,int l) {
- int i;
- int alloc_size;
+i_mmarray_cr(i_mmarray *ar,i_img_dim l) {
+ i_img_dim i;
+ size_t alloc_size;
ar->lines=l;
alloc_size = sizeof(minmax) * l;
}
void
-i_mmarray_add(i_mmarray *ar,int x,int y) {
+i_mmarray_add(i_mmarray *ar,i_img_dim x,i_img_dim y) {
if (y>-1 && y<ar->lines)
{
if (x<ar->data[y].min) ar->data[y].min=x;
}
int
-i_mmarray_gmin(i_mmarray *ar,int y) {
+i_mmarray_gmin(i_mmarray *ar,i_img_dim y) {
if (y>-1 && y<ar->lines) return ar->data[y].min;
else return -1;
}
int
-i_mmarray_getm(i_mmarray *ar,int y) {
+i_mmarray_getm(i_mmarray *ar,i_img_dim y) {
if (y>-1 && y<ar->lines) return ar->data[y].max;
else return MAXINT;
}
+#if 0
+/* unused? */
void
i_mmarray_render(i_img *im,i_mmarray *ar,i_color *val) {
- int i,x;
+ i_img_dim i,x;
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);
}
+#endif
static
void
-i_arcdraw(int x1, int y1, int x2, int y2, i_mmarray *ar) {
+i_arcdraw(i_img_dim x1, i_img_dim y1, i_img_dim x2, i_img_dim y2, i_mmarray *ar) {
double alpha;
double dsec;
- int temp;
+ i_img_dim temp;
alpha=(double)(y2-y1)/(double)(x2-x1);
if (fabs(alpha) <= 1)
{
dsec=y1;
while(x1<=x2)
{
- i_mmarray_add(ar,x1,(int)(dsec+0.5));
+ i_mmarray_add(ar,x1,(i_img_dim)(dsec+0.5));
dsec+=alpha;
x1++;
}
dsec=x1;
while(y1<=y2)
{
- i_mmarray_add(ar,(int)(dsec+0.5),y1);
+ i_mmarray_add(ar,(i_img_dim)(dsec+0.5),y1);
dsec+=alpha;
y1++;
}
void
i_mmarray_info(i_mmarray *ar) {
- int i;
+ i_img_dim i;
for(i=0;i<ar->lines;i++)
- if (ar->data[i].max!=-1) printf("line %d: min=%d, max=%d.\n",i,ar->data[i].min,ar->data[i].max);
+ if (ar->data[i].max!=-1)
+ printf("line %"i_DF ": min=%" i_DF ", max=%" i_DF ".\n",
+ i_DFc(i), i_DFc(ar->data[i].min), i_DFc(ar->data[i].max));
}
static void
-i_arc_minmax(i_int_hlines *hlines,int x,int y,float rad,float d1,float d2) {
+i_arc_minmax(i_int_hlines *hlines,i_img_dim x,i_img_dim y, double rad,float d1,float d2) {
i_mmarray dot;
- float f,fx,fy;
- int x1,y1;
-
- /*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));*/
+ double f,fx,fy;
+ i_img_dim x1,y1;
i_mmarray_cr(&dot, hlines->limit_y);
- x1=(int)(x+0.5+rad*cos(d1*PI/180.0));
- y1=(int)(y+0.5+rad*sin(d1*PI/180.0));
+ x1=(i_img_dim)(x+0.5+rad*cos(d1*PI/180.0));
+ y1=(i_img_dim)(y+0.5+rad*sin(d1*PI/180.0));
fx=(float)x1; fy=(float)y1;
/* printf("x1: %d.\ny1: %d.\n",x1,y1); */
i_arcdraw(x, y, x1, y1, &dot);
- x1=(int)(x+0.5+rad*cos(d2*PI/180.0));
- y1=(int)(y+0.5+rad*sin(d2*PI/180.0));
+ x1=(i_img_dim)(x+0.5+rad*cos(d2*PI/180.0));
+ y1=(i_img_dim)(y+0.5+rad*sin(d2*PI/180.0));
- 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)));
+ for(f=d1;f<=d2;f+=0.01)
+ 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)));
/* printf("x1: %d.\ny1: %d.\n",x1,y1); */
i_arcdraw(x, y, x1, y1, &dot);
/* render the minmax values onto the hlines */
for (y = 0; y < dot.lines; y++) {
if (dot.data[y].max!=-1) {
- int minx, width;
+ i_img_dim minx, width;
minx = dot.data[y].min;
width = dot.data[y].max - dot.data[y].min + 1;
i_int_hlines_add(hlines, y, minx, width);
}
static void
-i_arc_hlines(i_int_hlines *hlines,int x,int y,float rad,float d1,float d2) {
+i_arc_hlines(i_int_hlines *hlines,i_img_dim x,i_img_dim y,double rad,float d1,float d2) {
if (d1 <= d2) {
i_arc_minmax(hlines, x, y, rad, d1, d2);
}
*/
void
-i_arc(i_img *im,int x,int y,float rad,float d1,float d2,const i_color *val) {
+i_arc(i_img *im, i_img_dim x, i_img_dim y,double rad,double d1,double d2,const i_color *val) {
i_int_hlines hlines;
i_int_init_hlines_img(&hlines, im);
#define MAX_CIRCLE_STEPS 360
void
-i_arc_cfill(i_img *im,int x,int y,float rad,float d1,float d2,i_fill_t *fill) {
+i_arc_cfill(i_img *im, i_img_dim x, i_img_dim y,double rad,double d1,double d2,i_fill_t *fill) {
i_int_hlines hlines;
i_int_init_hlines_img(&hlines, im);
double x, double y, double rad, double d1, double d2) {
double d1_rad, d2_rad;
double circum;
- int steps, point_count;
+ i_img_dim steps, point_count;
double angle_inc;
/* normalize the angles */
=category Drawing
=synopsis i_arc_aa(im, 50, 50, 35, 90, 135, &color);
-Antialias fills an arc centered at (x,y) with radius I<rad> covering
+Anti-alias fills an arc centered at (x,y) with radius I<rad> covering
the range of angles in degrees from d1 to d2, with the color.
=cut
=category Drawing
=synopsis i_arc_aa_cfill(im, 50, 50, 35, 90, 135, fill);
-Antialias fills an arc centered at (x,y) with radius I<rad> covering
+Anti-alias fills an arc centered at (x,y) with radius I<rad> covering
the range of angles in degrees from d1 to d2, with the fill object.
=cut
/* Temporary AA HACK */
-typedef int frac;
-static frac float_to_frac(float x) { return (frac)(0.5+x*16.0); }
+typedef i_img_dim frac;
+static frac float_to_frac(double x) { return (frac)(0.5+x*16.0); }
static
void
-polar_to_plane(float cx, float cy, float angle, float radius, frac *x, frac *y) {
+polar_to_plane(double cx, double cy, float angle, double radius, frac *x, frac *y) {
*x = float_to_frac(cx+radius*cos(angle));
*y = float_to_frac(cy+radius*sin(angle));
}
static
void
-make_minmax_list(i_mmarray *dot, float x, float y, float radius) {
+make_minmax_list(pIMCTX, i_mmarray *dot, double x, double y, double radius) {
float angle = 0.0;
float astep = radius>0.1 ? .5/radius : 10;
frac cx, cy, lx, ly, sx, sy;
- mm_log((1, "make_minmax_list(dot %p, x %.2f, y %.2f, radius %.2f)\n", dot, x, y, radius));
+ im_log((aIMCTX, 1, "make_minmax_list(dot %p, x %.2f, y %.2f, radius %.2f)\n", dot, x, y, radius));
polar_to_plane(x, y, angle, radius, &sx, &sy);
static
int
-i_pixel_coverage(i_mmarray *dot, int x, int y) {
+i_pixel_coverage(i_mmarray *dot, i_img_dim x, i_img_dim y) {
frac minx = x*16;
frac maxx = minx+15;
frac cy;
=category Drawing
=synopsis i_circle_aa(im, 50, 50, 45, &color);
-Antialias fills a circle centered at (x,y) for radius I<rad> with
+Anti-alias fills a circle centered at (x,y) for radius I<rad> with
color.
=cut
*/
void
-i_circle_aa(i_img *im, float x, float y, float rad, const i_color *val) {
+i_circle_aa(i_img *im, double x, double y, double rad, const i_color *val) {
i_mmarray dot;
i_color temp;
- int ly;
+ i_img_dim ly;
+ dIMCTXim(im);
- mm_log((1, "i_circle_aa(im %p, x %d, y %d, rad %.2f, val %p)\n", im, x, y, rad, val));
+ im_log((aIMCTX, 1, "i_circle_aa(im %p, centre(" i_DFp "), rad %.2f, val %p)\n",
+ im, i_DFcp(x, y), rad, val));
i_mmarray_cr(&dot,16*im->ysize);
- make_minmax_list(&dot, x, y, rad);
+ make_minmax_list(aIMCTX, &dot, x, y, rad);
for(ly = 0; ly<im->ysize; ly++) {
int ix, cy, minx = INT_MAX, maxx = INT_MIN;
i_img_dim x, y;
i_img_dim dx, dy;
int error;
+ dIMCTXim(im);
- i_clear_error();
+ im_clear_error(aIMCTX);
if (r < 0) {
- i_push_error(0, "circle: radius must be non-negative");
+ im_push_error(aIMCTX, 0, "circle: radius must be non-negative");
return 0;
}
arc_seg(double angle, int scale) {
i_img_dim seg = (angle + 45) / 90;
double remains = angle - seg * 90; /* should be in the range [-45,45] */
- int sign = remains < 0 ? -1 : remains ? 1 : 0;
while (seg > 4)
seg -= 4;
int
i_arc_out(i_img *im, i_img_dim xc, i_img_dim yc, i_img_dim r,
- float d1, float d2, const i_color *col) {
+ double d1, double d2, const i_color *col) {
i_img_dim x, y;
i_img_dim dx, dy;
int error;
i_img_dim sin_th;
i_img_dim seg_d1, seg_d2;
int seg_num;
- double inv_r;
i_img_dim scale = r + 1;
i_img_dim seg1 = scale * 2;
i_img_dim seg2 = scale * 4;
i_img_dim seg3 = scale * 6;
i_img_dim seg4 = scale * 8;
- i_clear_error();
+ im_clear_error(aIMCTX);
if (r <= 0) {
- i_push_error(0, "arc: radius must be non-negative");
+ im_push_error(aIMCTX, 0, "arc: radius must be non-negative");
return 0;
}
if (d1 + 360 <= d2)
static double
cover(i_img_dim r, i_img_dim j) {
- float rjsqrt = sqrt(r*r - j*j);
+ double rjsqrt = sqrt(r*r - j*j);
return ceil(rjsqrt) - rjsqrt;
}
double t;
i_color workc = *col;
int orig_alpha = col->channel[3];
+ dIMCTXim(im);
- i_clear_error();
+ im_clear_error(aIMCTX);
if (r <= 0) {
- i_push_error(0, "arc: radius must be non-negative");
+ im_push_error(aIMCTX, 0, "arc: radius must be non-negative");
return 0;
}
i = r;
while (i > j+1) {
double d;
int cv, inv_cv;
- i_color p;
- int ch;
j++;
d = cover(r, j);
cv = (int)(d * 255 + 0.5);
*/
int
-i_arc_out_aa(i_img *im, i_img_dim xc, i_img_dim yc, i_img_dim r, float d1, float d2, const i_color *col) {
+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) {
i_img_dim i, j;
double t;
i_color workc = *col;
i_img_dim seg2 = scale * 4;
i_img_dim seg3 = scale * 6;
i_img_dim seg4 = scale * 8;
+ dIMCTXim(im);
- i_clear_error();
+ im_clear_error(aIMCTX);
if (r <= 0) {
- i_push_error(0, "arc: radius must be non-negative");
+ im_push_error(aIMCTX, 0, "arc: radius must be non-negative");
return 0;
}
if (d1 + 360 <= d2)
while (i > j+1) {
int cv, inv_cv;
- i_color p;
- int ch;
double d;
j++;
d = cover(r, j);
*/
void
-i_box(i_img *im,int x1,int y1,int x2,int y2,const i_color *val) {
- int x,y;
- 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));
+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) {
+ i_img_dim x,y;
+ mm_log((1,"i_box(im* %p, p1(" i_DFp "), p2(" i_DFp "),val %p)\n",
+ im, i_DFcp(x1,y1), i_DFcp(x2,y2), val));
for(x=x1;x<x2+1;x++) {
i_ppix(im,x,y1,val);
i_ppix(im,x,y2,val);
*/
void
-i_box_filled(i_img *im,int x1,int y1,int x2,int y2, const i_color *val) {
- int x,y;
- 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));
- for(x=x1;x<x2+1;x++) for (y=y1;y<y2+1;y++) i_ppix(im,x,y,val);
+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) {
+ i_img_dim x, y, width;
+ i_palidx index;
+
+ mm_log((1,"i_box_filled(im* %p, p1(" i_DFp "), p2(" i_DFp "),val %p)\n",
+ im, i_DFcp(x1, y1), i_DFcp(x2,y2) ,val));
+
+ if (x1 > x2 || y1 > y2
+ || x2 < 0 || y2 < 0
+ || x1 >= im->xsize || y1 > im->ysize)
+ return;
+
+ if (x1 < 0)
+ x1 = 0;
+ if (x2 >= im->xsize)
+ x2 = im->xsize - 1;
+ if (y1 < 0)
+ y1 = 0;
+ if (y2 >= im->ysize)
+ y2 = im->ysize - 1;
+
+ width = x2 - x1 + 1;
+
+ if (im->type == i_palette_type
+ && i_findcolor(im, val, &index)) {
+ i_palidx *line = mymalloc(sizeof(i_palidx) * width);
+
+ for (x = 0; x < width; ++x)
+ line[x] = index;
+
+ for (y = y1; y <= y2; ++y)
+ i_ppal(im, x1, x2+1, y, line);
+
+ myfree(line);
+ }
+ else {
+ i_color *line = mymalloc(sizeof(i_color) * width);
+
+ for (x = 0; x < width; ++x)
+ line[x] = *val;
+
+ for (y = y1; y <= y2; ++y)
+ i_plin(im, x1, x2+1, y, line);
+
+ myfree(line);
+ }
+}
+
+/*
+=item i_box_filledf(im, x1, y1, x2, y2, color)
+
+=category Drawing
+=synopsis i_box_filledf(im, 0, 0, im->xsize-1, im->ysize-1, &fcolor);
+
+Fills the box from (x1,y1) to (x2,y2) inclusive with a floating point
+color.
+
+=cut
+*/
+
+int
+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) {
+ i_img_dim x, y, width;
+
+ mm_log((1,"i_box_filledf(im* %p, p1(" i_DFp "), p2(" i_DFp "),val %p)\n",
+ im, i_DFcp(x1, y1), i_DFcp(x2, y2), val));
+
+ if (x1 > x2 || y1 > y2
+ || x2 < 0 || y2 < 0
+ || x1 >= im->xsize || y1 > im->ysize)
+ return 0;
+
+ if (x1 < 0)
+ x1 = 0;
+ if (x2 >= im->xsize)
+ x2 = im->xsize - 1;
+ if (y1 < 0)
+ y1 = 0;
+ if (y2 >= im->ysize)
+ y2 = im->ysize - 1;
+
+ width = x2 - x1 + 1;
+
+ if (im->bits <= 8) {
+ i_color c;
+ c.rgba.r = SampleFTo8(val->rgba.r);
+ c.rgba.g = SampleFTo8(val->rgba.g);
+ c.rgba.b = SampleFTo8(val->rgba.b);
+ c.rgba.a = SampleFTo8(val->rgba.a);
+
+ i_box_filled(im, x1, y1, x2, y2, &c);
+ }
+ else {
+ i_fcolor *line = mymalloc(sizeof(i_fcolor) * width);
+
+ for (x = 0; x < width; ++x)
+ line[x] = *val;
+
+ for (y = y1; y <= y2; ++y)
+ i_plinf(im, x1, x2+1, y, line);
+
+ myfree(line);
+ }
+
+ return 1;
}
/*
*/
void
-i_box_cfill(i_img *im,int x1,int y1,int x2,int y2,i_fill_t *fill) {
+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) {
i_render r;
- 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));
+
+ mm_log((1,"i_box_cfill(im* %p, p1(" i_DFp "), p2(" i_DFp "), fill %p)\n",
+ im, i_DFcp(x1, y1), i_DFcp(x2,y2), fill));
++x2;
if (x1 < 0)
}
/*
-=item i_line(im, x1, y1, x2, y2, val, endp)
+=item i_line(C<im>, C<x1>, C<y1>, C<x2>, C<y2>, C<color>, C<endp>)
=category Drawing
-Draw a line to image using bresenhams linedrawing algorithm
+=for stopwords Bresenham's
+
+Draw a line to image using Bresenham's line drawing algorithm
- im - image to draw to
- x1 - starting x coordinate
- y1 - starting x coordinate
- x2 - starting x coordinate
- y2 - starting x coordinate
- val - color to write to image
- endp - endpoint flag (boolean)
+ im - image to draw to
+ x1 - starting x coordinate
+ y1 - starting x coordinate
+ x2 - starting x coordinate
+ y2 - starting x coordinate
+ color - color to write to image
+ endp - endpoint flag (boolean)
=cut
*/
void
-i_line(i_img *im, int x1, int y1, int x2, int y2, const i_color *val, int endp) {
- int x, y;
- int dx, dy;
- int p;
+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) {
+ i_img_dim x, y;
+ i_img_dim dx, dy;
+ i_img_dim p;
dx = x2 - x1;
dy = y2 - y1;
/* choose variable to iterate on */
- if (abs(dx)>abs(dy)) {
- int dx2, dy2, cpy;
+ if (i_abs(dx) > i_abs(dy)) {
+ i_img_dim dx2, dy2, cpy;
/* sort by x */
if (x1 > x2) {
- int t;
+ i_img_dim t;
t = x1; x1 = x2; x2 = t;
t = y1; y1 = y2; y2 = t;
}
- dx = abs(dx);
+ dx = i_abs(dx);
dx2 = dx*2;
dy = y2 - y1;
i_ppix(im, x+1, y, val);
}
} else {
- int dy2, dx2, cpx;
+ i_img_dim dy2, dx2, cpx;
/* sort bx y */
if (y1 > y2) {
- int t;
+ i_img_dim t;
t = x1; x1 = x2; x2 = t;
t = y1; y1 = y2; y2 = t;
}
- dy = abs(dy);
+ dy = i_abs(dy);
dx = x2 - x1;
dy2 = dy*2;
void
-i_line_dda(i_img *im, int x1, int y1, int x2, int y2, i_color *val) {
+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) {
- float dy;
- int x;
+ double dy;
+ i_img_dim x;
for(x=x1; x<=x2; x++) {
- dy = y1+ (x-x1)/(float)(x2-x1)*(y2-y1);
- i_ppix(im, x, (int)(dy+0.5), val);
+ dy = y1+ (x-x1)/(double)(x2-x1)*(y2-y1);
+ i_ppix(im, x, (i_img_dim)(dy+0.5), val);
}
}
/*
-=item i_line_aa(im, x1, x2, y1, y2, color, endp)
+=item i_line_aa(C<im>, C<x1>, C<x2>, C<y1>, C<y2>, C<color>, C<endp>)
=category Drawing
-Antialias draws a line from (x1,y1) to (x2, y2) in color.
+Anti-alias draws a line from (x1,y1) to (x2, y2) in color.
-The point (x2, y2) is drawn only if endp is set.
+The point (x2, y2) is drawn only if C<endp> is set.
=cut
*/
void
-i_line_aa(i_img *im, int x1, int y1, int x2, int y2, const i_color *val, int endp) {
- int x, y;
- int dx, dy;
- int p;
+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) {
+ i_img_dim x, y;
+ i_img_dim dx, dy;
+ i_img_dim p;
dx = x2 - x1;
dy = y2 - y1;
/* choose variable to iterate on */
- if (abs(dx)>abs(dy)) {
- int dx2, dy2, cpy;
+ if (i_abs(dx) > i_abs(dy)) {
+ i_img_dim dx2, dy2, cpy;
/* sort by x */
if (x1 > x2) {
- int t;
+ i_img_dim t;
t = x1; x1 = x2; x2 = t;
t = y1; y1 = y2; y2 = t;
}
- dx = abs(dx);
+ dx = i_abs(dx);
dx2 = dx*2;
dy = y2 - y1;
for(x=x1; x<x2-1; x++) {
int ch;
i_color tval;
- float t = (dy) ? -(float)(p)/(float)(dx2) : 1;
- float t1, t2;
+ double t = (dy) ? -(float)(p)/(float)(dx2) : 1;
+ double t1, t2;
if (t<0) t = 0;
t1 = 1-t;
}
}
} else {
- int dy2, dx2, cpx;
+ i_img_dim dy2, dx2, cpx;
/* sort bx y */
if (y1 > y2) {
- int t;
+ i_img_dim t;
t = x1; x1 = x2; x2 = t;
t = y1; y1 = y2; y2 = t;
}
- dy = abs(dy);
+ dy = i_abs(dy);
dx = x2 - x1;
dy2 = dy*2;
for(y=y1; y<y2-1; y++) {
int ch;
i_color tval;
- float t = (dx) ? -(float)(p)/(float)(dy2) : 1;
- float t1, t2;
+ double t = (dx) ? -(double)(p)/(double)(dy2) : 1;
+ double t1, t2;
if (t<0) t = 0;
t1 = 1-t;
i_gpix(im,x,y+1,&tval);
for(ch=0;ch<im->channels;ch++)
- tval.channel[ch]=(unsigned char)(t1*(float)tval.channel[ch]+t2*(float)val->channel[ch]);
+ tval.channel[ch]=(unsigned char)(t1*(double)tval.channel[ch]+t2*(double)val->channel[ch]);
i_ppix(im,x,y+1,&tval);
i_gpix(im,x+cpx,y+1,&tval);
for(ch=0;ch<im->channels;ch++)
- tval.channel[ch]=(unsigned char)(t2*(float)tval.channel[ch]+t1*(float)val->channel[ch]);
+ tval.channel[ch]=(unsigned char)(t2*(double)tval.channel[ch]+t1*(double)val->channel[ch]);
i_ppix(im,x+cpx,y+1,&tval);
if (p<0) {
static double
-perm(int n,int k) {
+perm(i_img_dim n,i_img_dim k) {
double r;
- int i;
+ i_img_dim i;
r=1;
for(i=k+1;i<=n;i++) r*=i;
for(i=1;i<=(n-k);i++) r/=i;
double *bzcoef;
double t,cx,cy;
int k,i;
- int lx = 0,ly = 0;
+ i_img_dim lx = 0,ly = 0;
int n=l-1;
double itr,ccoef;
}
/* printf("%f -> (%d,%d)\n",t,(int)(0.5+cx),(int)(0.5+cy)); */
if (i++) {
- i_line_aa(im,lx,ly,(int)(0.5+cx),(int)(0.5+cy),val, 1);
+ i_line_aa(im,lx,ly,(i_img_dim)(0.5+cx),(i_img_dim)(0.5+cy),val, 1);
}
- /* i_ppix(im,(int)(0.5+cx),(int)(0.5+cy),val); */
- lx=(int)(0.5+cx);
- ly=(int)(0.5+cy);
+ /* i_ppix(im,(i_img_dim)(0.5+cx),(i_img_dim)(0.5+cy),val); */
+ lx=(i_img_dim)(0.5+cx);
+ ly=(i_img_dim)(0.5+cy);
}
ICL_info(val);
myfree(bzcoef);
/*
struct stc {
- int mylx,myrx;
- int dadlx,dadrx;
- int myy;
+ i_img_dim mylx,myrx;
+ i_img_dim dadlx,dadrx;
+ i_img_dim myy;
int mydirection;
};
struct stack_element {
- int myLx,myRx;
- int dadLx,dadRx;
- int myY;
+ i_img_dim myLx,myRx;
+ i_img_dim dadLx,dadRx;
+ i_img_dim myY;
int myDirection;
};
static
struct stack_element*
-crdata(int left,int right,int dadl,int dadr,int y, int dir) {
+crdata(i_img_dim left,i_img_dim right,i_img_dim dadl,i_img_dim dadr,i_img_dim y, int dir) {
struct stack_element *ste;
ste = mymalloc(sizeof(struct stack_element)); /* checked 5jul05 tonyc */
ste->myLx = left;
}
static int
-i_lspan(i_img *im, int seedx, int seedy, i_color const *val, ff_cmpfunc cmpfunc) {
+i_lspan(i_img *im, i_img_dim seedx, i_img_dim seedy, i_color const *val, ff_cmpfunc cmpfunc) {
i_color cval;
while(1) {
if (seedx-1 < 0) break;
}
static int
-i_rspan(i_img *im, int seedx, int seedy, i_color const *val, ff_cmpfunc cmpfunc) {
+i_rspan(i_img *im, i_img_dim seedx, i_img_dim seedy, i_color const *val, ff_cmpfunc cmpfunc) {
i_color cval;
while(1) {
if (seedx+1 > im->xsize-1) break;
} while (0)
#define ST_STACK(dir,dadLx,dadRx,lx,rx,y) do { \
- int pushrx = rx+1; \
- int pushlx = lx-1; \
+ i_img_dim pushrx = rx+1; \
+ i_img_dim pushlx = lx-1; \
ST_PUSH(lx,rx,pushlx,pushrx,y+dir,dir); \
if (rx > dadRx) \
ST_PUSH(dadRx+1,rx,pushlx,pushrx,y-dir,-dir); \
/* The function that does all the real work */
static struct i_bitmap *
-i_flood_fill_low(i_img *im,int seedx,int seedy,
- int *bxminp, int *bxmaxp, int *byminp, int *bymaxp,
+i_flood_fill_low(i_img *im,i_img_dim seedx,i_img_dim seedy,
+ i_img_dim *bxminp, i_img_dim *bxmaxp, i_img_dim *byminp, i_img_dim *bymaxp,
i_color const *seed, ff_cmpfunc cmpfunc) {
- int ltx, rtx;
- int tx = 0;
+ i_img_dim ltx, rtx;
+ i_img_dim tx = 0;
- int bxmin = seedx;
- int bxmax = seedx;
- int bymin = seedy;
- int bymax = seedy;
+ i_img_dim bxmin = seedx;
+ i_img_dim bxmax = seedx;
+ i_img_dim bymin = seedy;
+ i_img_dim bymax = seedy;
struct llist *st;
struct i_bitmap *btm;
- int channels,xsize,ysize;
+ int channels;
+ i_img_dim xsize,ysize;
i_color cval;
channels = im->channels;
ltx = i_lspan(im, seedx, seedy, seed, cmpfunc);
rtx = i_rspan(im, seedx, seedy, seed, cmpfunc);
for(tx=ltx; tx<=rtx; tx++) SET(tx, seedy);
+ bxmin = ltx;
+ bxmax = rtx;
ST_PUSH(ltx, rtx, ltx, rtx, seedy+1, 1);
ST_PUSH(ltx, rtx, ltx, rtx, seedy-1, -1);
while(st->count) {
/* Stack variables */
- int lx,rx;
- int dadLx,dadRx;
- int y;
+ i_img_dim lx,rx;
+ i_img_dim dadLx,dadRx;
+ i_img_dim y;
int direction;
- int x;
+ i_img_dim x;
int wasIn=0;
ST_POP(); /* sets lx, rx, dadLx, dadRx, y, direction */
if ( lx >= 0 && (wasIn = INSIDE(lx, y, seed)) ) {
SET(lx, y);
lx--;
- while(INSIDE(lx, y, seed) && lx > 0) {
+ while(lx >= 0 && INSIDE(lx, y, seed)) {
SET(lx,y);
lx--;
}
}
/*
-=item i_flood_fill(im, seedx, seedy, color)
+=item i_flood_fill(C<im>, C<seedx>, C<seedy>, C<color>)
=category Drawing
=synopsis i_flood_fill(im, 50, 50, &color);
-Flood fills the 4-connected region starting from the point (seedx,
-seedy) with I<color>.
+Flood fills the 4-connected region starting from the point (C<seedx>,
+C<seedy>) with I<color>.
-Returns false if (seedx, seedy) are outside the image.
+Returns false if (C<seedx>, C<seedy>) are outside the image.
=cut
*/
undef_int
-i_flood_fill(i_img *im, int seedx, int seedy, const i_color *dcol) {
- int bxmin, bxmax, bymin, bymax;
+i_flood_fill(i_img *im, i_img_dim seedx, i_img_dim seedy, const i_color *dcol) {
+ i_img_dim bxmin, bxmax, bymin, bymax;
struct i_bitmap *btm;
- int x, y;
+ i_img_dim x, y;
i_color val;
+ dIMCTXim(im);
- i_clear_error();
+ im_clear_error(aIMCTX);
if (seedx < 0 || seedx >= im->xsize ||
seedy < 0 || seedy >= im->ysize) {
- i_push_error(0, "i_flood_cfill: Seed pixel outside of image");
+ im_push_error(aIMCTX, 0, "i_flood_cfill: Seed pixel outside of image");
return 0;
}
}
/*
-=item i_flood_cfill(im, seedx, seedy, fill)
+=item i_flood_cfill(C<im>, C<seedx>, C<seedy>, C<fill>)
=category Drawing
=synopsis i_flood_cfill(im, 50, 50, fill);
-Flood fills the 4-connected region starting from the point (seedx,
-seedy) with I<fill>.
+Flood fills the 4-connected region starting from the point (C<seedx>,
+C<seedy>) with C<fill>.
-Returns false if (seedx, seedy) are outside the image.
+Returns false if (C<seedx>, C<seedy>) are outside the image.
=cut
*/
undef_int
-i_flood_cfill(i_img *im, int seedx, int seedy, i_fill_t *fill) {
- int bxmin, bxmax, bymin, bymax;
+i_flood_cfill(i_img *im, i_img_dim seedx, i_img_dim seedy, i_fill_t *fill) {
+ i_img_dim bxmin, bxmax, bymin, bymax;
struct i_bitmap *btm;
i_color val;
+ dIMCTXim(im);
- i_clear_error();
+ im_clear_error(aIMCTX);
if (seedx < 0 || seedx >= im->xsize ||
seedy < 0 || seedy >= im->ysize) {
- i_push_error(0, "i_flood_cfill: Seed pixel outside of image");
+ im_push_error(aIMCTX, 0, "i_flood_cfill: Seed pixel outside of image");
return 0;
}
}
/*
-=item i_flood_fill_border(im, seedx, seedy, color, border)
+=item i_flood_fill_border(C<im>, C<seedx>, C<seedy>, C<color>, C<border>)
=category Drawing
=synopsis i_flood_fill_border(im, 50, 50, &color, &border);
-Flood fills the 4-connected region starting from the point (seedx,
-seedy) with I<color>, fill stops when the fill reaches a pixels with
-color I<border>.
+Flood fills the 4-connected region starting from the point (C<seedx>,
+C<seedy>) with C<color>, fill stops when the fill reaches a pixels
+with color C<border>.
-Returns false if (seedx, seedy) are outside the image.
+Returns false if (C<seedx>, C<seedy>) are outside the image.
=cut
*/
undef_int
-i_flood_fill_border(i_img *im, int seedx, int seedy, const i_color *dcol,
+i_flood_fill_border(i_img *im, i_img_dim seedx, i_img_dim seedy, const i_color *dcol,
const i_color *border) {
- int bxmin, bxmax, bymin, bymax;
+ i_img_dim bxmin, bxmax, bymin, bymax;
struct i_bitmap *btm;
- int x, y;
+ i_img_dim x, y;
+ dIMCTXim(im);
- i_clear_error();
+ im_clear_error(aIMCTX);
if (seedx < 0 || seedx >= im->xsize ||
seedy < 0 || seedy >= im->ysize) {
- i_push_error(0, "i_flood_cfill: Seed pixel outside of image");
+ im_push_error(aIMCTX, 0, "i_flood_cfill: Seed pixel outside of image");
return 0;
}
}
/*
-=item i_flood_cfill_border(im, seedx, seedy, fill, border)
+=item i_flood_cfill_border(C<im>, C<seedx>, C<seedy>, C<fill>, C<border>)
=category Drawing
=synopsis i_flood_cfill_border(im, 50, 50, fill, border);
-Flood fills the 4-connected region starting from the point (seedx,
-seedy) with I<fill>, the fill stops when it reaches pixels of color
-I<border>.
+Flood fills the 4-connected region starting from the point (C<seedx>,
+C<seedy>) with C<fill>, the fill stops when it reaches pixels of color
+C<border>.
-Returns false if (seedx, seedy) are outside the image.
+Returns false if (C<seedx>, C<seedy>) are outside the image.
=cut
*/
undef_int
-i_flood_cfill_border(i_img *im, int seedx, int seedy, i_fill_t *fill,
+i_flood_cfill_border(i_img *im, i_img_dim seedx, i_img_dim seedy, i_fill_t *fill,
const i_color *border) {
- int bxmin, bxmax, bymin, bymax;
+ i_img_dim bxmin, bxmax, bymin, bymax;
struct i_bitmap *btm;
+ dIMCTXim(im);
- i_clear_error();
+ im_clear_error(aIMCTX);
if (seedx < 0 || seedx >= im->xsize ||
seedy < 0 || seedy >= im->ysize) {
- i_push_error(0, "i_flood_cfill_border: Seed pixel outside of image");
+ im_push_error(aIMCTX, 0, "i_flood_cfill_border: Seed pixel outside of image");
return 0;
}
static void
cfill_from_btm(i_img *im, i_fill_t *fill, struct i_bitmap *btm,
- int bxmin, int bxmax, int bymin, int bymax) {
- int x, y;
- int start;
+ i_img_dim bxmin, i_img_dim bxmax, i_img_dim bymin, i_img_dim bymax) {
+ i_img_dim x, y;
+ i_img_dim start;
i_render r;