diff --git a/src/modules/Image/colors.c b/src/modules/Image/colors.c index bb3a6d859960dabbcb7ad5e9cd69abaf60b6f789..4c95aab905ebd1f09ff7f820afef2ab112fb2223 100644 --- a/src/modules/Image/colors.c +++ b/src/modules/Image/colors.c @@ -1,7 +1,7 @@ /* **! module Image **! note -**! $Id: colors.c,v 1.37 2000/08/11 19:25:53 grubba Exp $ +**! $Id: colors.c,v 1.38 2000/08/11 19:28:39 grubba Exp $ **! submodule Color **! **! This module keeps names and easy handling @@ -179,7 +179,7 @@ #include "global.h" -RCSID("$Id: colors.c,v 1.37 2000/08/11 19:25:53 grubba Exp $"); +RCSID("$Id: colors.c,v 1.38 2000/08/11 19:28:39 grubba Exp $"); #include "image_machine.h" @@ -1259,9 +1259,9 @@ static void image_get_color(INT32 args) push_array_items(sp->u.array); get_all_args("Image.Color()",3,"%f%f%f",&h,&s,&v); pop_n_elems(3); - push_int((INT32)(h/360.0*256.0)); - push_int((INT32)(s/100.0*255.4)); - push_int((INT32)(v/100.0*255.4)); + push_int(DOUBLE_TO_INT(h/360.0*256.0)); + push_int(DOUBLE_TO_INT(s/100.0*255.4)); + push_int(DOUBLE_TO_INT(v/100.0*255.4)); image_make_hsv_color(3); return; } @@ -1288,7 +1288,7 @@ static void image_get_color(INT32 args) pop_stack(); } for (n=0; (size_t)n<sizeof(callables)/sizeof(callables[0]); n++) - if (sp[-1].u.string->len>(INT32)strlen(callables[n]) && + if (sp[-1].u.string->len>(ptrdiff_t)strlen(callables[n]) && memcmp(sp[-1].u.string->str,callables[n],strlen(callables[n]))==0) { push_int(DO_NOT_WARN(strlen(callables[n]))); @@ -1493,8 +1493,8 @@ static void image_make_hsv_color(INT32 args) get_all_args("Image.Color.hsv()",args,"%f%f%f", &h,&s,&v); pop_n_elems(args); - if (h<0) h=360+h-(((int)h/360)*360); - if (h>360.0) h-=(((int)h/360)*360); + if (h<0) h = 360 + h - ((DOUBLE_TO_INT(h)/360)*360); + if (h>360.0) h -= ((DOUBLE_TO_INT(h)/360)*360); h/=60; } diff --git a/src/modules/Image/colortable.c b/src/modules/Image/colortable.c index a67ed3da886494f4c8cb758cd303c823fd34b49e..3eda676216c0dd47e2c17530a89b5e93e9ba92b9 100644 --- a/src/modules/Image/colortable.c +++ b/src/modules/Image/colortable.c @@ -1,11 +1,11 @@ #include "global.h" -/* $Id: colortable.c,v 1.90 2000/08/11 18:59:59 grubba Exp $ */ +/* $Id: colortable.c,v 1.91 2000/08/11 19:12:35 grubba Exp $ */ /* **! module Image **! note -**! $Id: colortable.c,v 1.90 2000/08/11 18:59:59 grubba Exp $ +**! $Id: colortable.c,v 1.91 2000/08/11 19:12:35 grubba Exp $ **! class Colortable **! **! This object keeps colortable information, @@ -20,7 +20,7 @@ #undef COLORTABLE_DEBUG #undef COLORTABLE_REDUCE_DEBUG -RCSID("$Id: colortable.c,v 1.90 2000/08/11 18:59:59 grubba Exp $"); +RCSID("$Id: colortable.c,v 1.91 2000/08/11 19:12:35 grubba Exp $"); #include <math.h> /* fabs() */ @@ -3025,7 +3025,7 @@ static INLINE ptrdiff_t _cub_find_full_add(int **pp,int *i,int *p,int n, } static void _cub_add_cs_full_recur(int **pp,int *i,int *p, - int n,struct nct_flat_entry *fe, + ptrdiff_t n, struct nct_flat_entry *fe, int rp,int gp,int bp, int rd1,int gd1,int bd1, int rd2,int gd2,int bd2, @@ -3166,7 +3166,7 @@ static INLINE void _build_cubicle(struct neo_colortable *nct, (int)fe->color.g>=gmin && (int)fe->color.g<=gmax && (int)fe->color.b>=bmin && (int)fe->color.b<=bmax) { - *pp=fe->no; + *pp = DO_NOT_WARN((int)fe->no); pp++; i++; } @@ -3333,6 +3333,26 @@ void build_rigid(struct neo_colortable *nct) **! see also: cubicles, full **/ +/* Some functions to avoid warnings about losss of precision. */ +#ifdef __ECL +static inline unsigned char TO_UCHAR(ptrdiff_t val) +{ + return DO_NOT_WARN((unsigned char)val); +} +static inline unsigned short TO_USHORT(ptrdiff_t val) +{ + return DO_NOT_WARN((unsigned short)val); +} +static inline unsigned INT32 TO_UINT32(ptrdiff_t val) +{ + return DO_NOT_WARN((unsigned INT32)val); +} +#else /* !__ECL */ +#define TO_UCHAR(x) ((unsigned char)x) +#define TO_USHORT(x) ((unsigned short)x) +#define TO_UINT32(x) ((unsigned INT32)x) +#endif /* __ECL */ + /* begin instantiating from colortable_lookup.h */ /* instantiate map functions */ @@ -3384,7 +3404,7 @@ void build_rigid(struct neo_colortable *nct) #define NCTLU_CUBE_NAME _img_nct_index_8bit_cube #define NCTLU_FLAT_RIGID_NAME _img_nct_index_8bit_flat_rigid #define NCTLU_LINE_ARGS (dith,&rowpos,&s,NULL,&d,NULL,NULL,&cd) -#define NCTLU_RIGID_WRITE (d[0]=(unsigned char)(feprim[i].no)) +#define NCTLU_RIGID_WRITE (d[0] = TO_UCHAR(feprim[i].no)) #define NCTLU_DITHER_RIGID_GOT (feprim[i].color) #define NCTLU_SELECT_FUNCTION image_colortable_index_8bit_function #define NCTLU_EXECUTE_FUNCTION image_colortable_index_8bit_image @@ -3432,7 +3452,7 @@ void build_rigid(struct neo_colortable *nct) #define NCTLU_CUBE_NAME _img_nct_index_16bit_cube #define NCTLU_FLAT_RIGID_NAME _img_nct_index_16bit_flat_rigid #define NCTLU_LINE_ARGS (dith,&rowpos,&s,NULL,NULL,&d,NULL,&cd) -#define NCTLU_RIGID_WRITE (d[0]=(unsigned short)(feprim[i].no)) +#define NCTLU_RIGID_WRITE (d[0] = TO_USHORT(feprim[i].no)) #define NCTLU_DITHER_RIGID_GOT (feprim[i].color) #define NCTLU_SELECT_FUNCTION image_colortable_index_16bit_function #define NCTLU_EXECUTE_FUNCTION image_colortable_index_16bit_image @@ -3480,7 +3500,7 @@ void build_rigid(struct neo_colortable *nct) #define NCTLU_CUBE_NAME _img_nct_index_32bit_cube #define NCTLU_FLAT_RIGID_NAME _img_nct_index_32bit_flat_rigid #define NCTLU_LINE_ARGS (dith,&rowpos,&s,NULL,NULL,NULL,&d,&cd) -#define NCTLU_RIGID_WRITE (d[0]=(unsigned INT32)(feprim[i].no)) +#define NCTLU_RIGID_WRITE (d[0] = TO_UINT32(feprim[i].no)) #define NCTLU_DITHER_RIGID_GOT (feprim[i].color) #define NCTLU_SELECT_FUNCTION image_colortable_index_32bit_function #define NCTLU_EXECUTE_FUNCTION image_colortable_index_32bit_image @@ -4312,7 +4332,7 @@ void image_colortable_image(INT32 args) rgb_group *dest; pop_n_elems(args); - push_int(image_colortable_size(THIS)); + push_int64(image_colortable_size(THIS)); push_int(1); o=clone_object(image_program,2); push_object(o); diff --git a/src/modules/Image/orient.c b/src/modules/Image/orient.c index 5780ceb27b6ed909410079d2cf12d4874e839ceb..4ac88ec95919ed779a16bc1fe738ca17a73e2c27 100644 --- a/src/modules/Image/orient.c +++ b/src/modules/Image/orient.c @@ -1,9 +1,9 @@ -/* $Id: orient.c,v 1.16 2000/08/09 17:32:57 grubba Exp $ */ +/* $Id: orient.c,v 1.17 2000/08/11 19:22:14 grubba Exp $ */ /* **! module Image **! note -**! $Id: orient.c,v 1.16 2000/08/09 17:32:57 grubba Exp $ +**! $Id: orient.c,v 1.17 2000/08/11 19:22:14 grubba Exp $ **! class Image */ @@ -243,15 +243,20 @@ CHRONO("begin hsv..."); int z,w; - if (my_abs(h)>my_abs(j)) - if (h) z=-(int)(32*(j/h)+(h>0)*128+64),w=my_abs(h); + if (my_abs(DOUBLE_TO_INT(h)) > my_abs(DOUBLE_TO_INT(j))) + if (h) { + z = -DOUBLE_TO_INT(32*(j/h)+(h>0)*128+64); + w = my_abs(DOUBLE_TO_INT(h)); + } else z=0,w=0; - else - z=-(int)(-32*(h/j)+(j>0)*128+128),w=my_abs(j); + else { + z = -DOUBLE_TO_INT(-32*(h/j)+(j>0)*128+128); + w = my_abs(DOUBLE_TO_INT(j)); + } d->r=(COLORTYPE)z; d->g=255; - d->b=(COLORTYPE)MINIMUM(w*mag,255); + d->b = MINIMUM(DOUBLE_TO_COLORTYPE(w*mag), 255); d++; s0++; diff --git a/src/modules/Image/polyfill.c b/src/modules/Image/polyfill.c index ffbc1782965f4180f82135cad6ec11b029e8d650..6ade21282a7ac0e060f4fff65926cf475b568e90 100644 --- a/src/modules/Image/polyfill.c +++ b/src/modules/Image/polyfill.c @@ -1,5 +1,5 @@ #include "global.h" -RCSID("$Id: polyfill.c,v 1.33 2000/08/07 14:03:35 grubba Exp $"); +RCSID("$Id: polyfill.c,v 1.34 2000/08/11 19:18:21 grubba Exp $"); /* Prototypes are needed for these */ extern double floor(double); @@ -40,7 +40,7 @@ extern double floor(double); /* **! module Image **! note -**! $Id: polyfill.c,v 1.33 2000/08/07 14:03:35 grubba Exp $ +**! $Id: polyfill.c,v 1.34 2000/08/11 19:18:21 grubba Exp $ **! class Image */ @@ -69,14 +69,14 @@ extern double floor(double); struct line_list { struct vertex *above,*below; - float dx,dy; + double dx, dy; struct line_list *next; - float xmin,xmax,yxmin,yxmax; /* temporary storage */ + double xmin, xmax, yxmin, yxmax; /* temporary storage */ }; struct vertex { - float x,y; + double x, y; struct vertex *next; /* total list, sorted downwards */ struct line_list *below,*above; /* childs */ int done; @@ -84,7 +84,7 @@ struct vertex #define VY(V,X) ((V)->above->y+(V)->dy*((X)-(V)->above->x)) -static struct vertex *vertex_new(float x,float y,struct vertex **top) +static struct vertex *vertex_new(double x, double y, struct vertex **top) { struct vertex *c; while (*top && (*top)->y<y) top=&((*top)->next); @@ -108,7 +108,7 @@ static void vertex_connect(struct vertex *above, struct vertex *below) { struct line_list *c,*d; - float diff; + double diff; if (below==above) return; @@ -136,7 +136,7 @@ static void vertex_connect(struct vertex *above, below->above = d; } -static INLINE float line_xmax(struct line_list *v,float yp,float *ydest) +static INLINE double line_xmax(struct line_list *v, double yp, double *ydest) { if (v->dx>0.0) if (v->below->y>yp+1.0+1e-10) @@ -154,7 +154,7 @@ static INLINE float line_xmax(struct line_list *v,float yp,float *ydest) return (*ydest=v->below->y),v->below->x; } -static INLINE float line_xmin(struct line_list *v,float yp,float *ydest) +static INLINE double line_xmin(struct line_list *v, double yp, double *ydest) { if (v->dx<0.0) if (v->below->y>yp+1.0+1e-10) @@ -174,7 +174,7 @@ static INLINE float line_xmin(struct line_list *v,float yp,float *ydest) static void add_vertices(struct line_list **first, struct line_list *what, - float yp) + double yp) { struct line_list **ins,*c; #ifdef POLYDEBUG @@ -293,7 +293,7 @@ static void add_vertices(struct line_list **first, static void sub_vertices(struct line_list **first, struct vertex *below, - float yp) + double yp) { struct line_list **ins,*c; @@ -325,9 +325,9 @@ static void sub_vertices(struct line_list **first, } } -static INLINE void polyfill_row_add(float *buf, - float xmin,float xmax, - float add) +static INLINE void polyfill_row_add(double *buf, + double xmin, double xmax, + double add) { int i; int xmin_i = DOUBLE_TO_INT(floor(xmin)); @@ -337,9 +337,9 @@ static INLINE void polyfill_row_add(float *buf, buf[xmin_i] += (xmax-xmin)*add; else if (xmin_i>=0) { - buf[xmin_i] += (1-(xmin-((float)xmin_i)))*add; + buf[xmin_i] += (1-(xmin-((double)xmin_i)))*add; for (i=xmin_i+1; i<xmax_i; i++) buf[i]+=add; - buf[xmax_i] += add*(xmax-((float)xmax_i)); + buf[xmax_i] += add*(xmax-((double)xmax_i)); } else { @@ -348,11 +348,11 @@ static INLINE void polyfill_row_add(float *buf, } } -static INLINE void polyfill_slant_add(float *buf, - float xmin,float xmax, - float lot, - float y1, - float dy) +static INLINE void polyfill_slant_add(double *buf, + double xmin, double xmax, + double lot, + double y1, + double dy) { int i; int xmin_i = DOUBLE_TO_INT(floor(xmin)); @@ -360,40 +360,40 @@ static INLINE void polyfill_slant_add(float *buf, if (xmax_i<0) return; if (xmin_i == xmax_i) { - float dx = xmax - xmin; + double dx = xmax - xmin; buf[xmin_i] += lot*(y1+dy*dx/2)*dx; } else if (xmin_i>=0) { - float dx = DO_NOT_WARN(1.0 - (xmin-((float)xmin_i))); + double dx = DO_NOT_WARN(1.0 - (xmin-((double)xmin_i))); buf[xmin_i] += lot*(y1+dy*dx/2.0)*dx; y1 += dy*dx; for (i=xmin_i+1; i<xmax_i; i++) { buf[i] += lot*(y1+dy/2.0); y1 += dy; } - dx = (xmax-((float)xmax_i)); + dx = (xmax-((double)xmax_i)); buf[xmax_i] += lot*(y1+dy*dx/2.0)*dx; } else { - float dx; + double dx; y1 -= dy*xmin; /* Adjust y1 for the first -xmin steps. */ for (i=0; i<xmax_i; i++) { buf[i] += lot*(y1+dy/2.0); y1 += dy; } - dx = (xmax-((float)xmax_i)); + dx = (xmax-((double)xmax_i)); buf[xmax_i] += lot*(y1+dy*dx/2)*dx; } } -static int polyfill_event(float xmin, - float xmax, +static int polyfill_event(double xmin, + double xmax, struct line_list **pll, int tog, - float yp, - float *buf) + double yp, + double *buf) { struct line_list *c; struct line_list *ll=*pll; @@ -481,9 +481,9 @@ static int polyfill_event(float xmin, { if (c->xmin<=xmin && c->xmax>=xmax) { - float y1=VY(c,xmin); + double y1 = VY(c,xmin); #ifdef POLYDEBUG - float y2=VY(c,xmax); + double y2 = VY(c,xmax); fprintf(stderr," use line %g,%g - %g,%g [%g,%g - %g,%g] : %g,%g - %g,%g = %+g\n", c->xmin,c->yxmin,c->xmax,c->yxmax, c->above->x,c->above->y,c->below->x,c->below->y, @@ -504,11 +504,11 @@ static int polyfill_event(float xmin, static void polyfill_some(struct image *img, struct vertex *v, - float *buf) + double *buf) { struct line_list *ll=NULL; int y=0; - float ixmax=(float)img->xsize; + double ixmax = (double)img->xsize; struct vertex *to_add=v,*to_loose=v; /* beat row for row */ @@ -517,9 +517,9 @@ static void polyfill_some(struct image *img, while (y<img->ysize && (to_loose||to_add) ) { - float yp=y; + double yp = y; struct line_list *c; - float xmin,xmax; + double xmin, xmax; int tog=0; int i; rgb_group *d; @@ -715,7 +715,7 @@ static INLINE struct vertex *polyfill_add(struct vertex *top, #endif } -#define POINT(A,N) (((A)->item[N].type==T_FLOAT)?((A)->item[N].u.float_number):((float)((A)->item[N].u.integer))) +#define POINT(A,N) (((A)->item[N].type==T_FLOAT)?((A)->item[N].u.float_number):((FLOAT_TYPE)((A)->item[N].u.integer))) last = first = vertex_new(DO_NOT_WARN(POINT(a,0)), DO_NOT_WARN(POINT(a,1)), @@ -756,12 +756,12 @@ static INLINE struct vertex *polyfill_add(struct vertex *top, void image_polyfill(INT32 args) { struct vertex *v; - float *buf; + double *buf; if (!THIS->img) error("Image.Image->polyfill: no image\n"); - buf=malloc(sizeof(float)*(THIS->xsize+1)); + buf=malloc(sizeof(double)*(THIS->xsize+1)); if (!buf) error("Image.Image->polyfill: out of memory\n");