diff --git a/src/modules/Image/colortable.c b/src/modules/Image/colortable.c index 5db00a3160af7c62458f3365ec2667600b1fe24f..5b17298c6bde961cda29559c769b9d55aae6bcfd 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.86 2000/08/10 09:51:53 per Exp $ */ +/* $Id: colortable.c,v 1.87 2000/08/10 16:56:20 grubba Exp $ */ /* **! module Image **! note -**! $Id: colortable.c,v 1.86 2000/08/10 09:51:53 per Exp $ +**! $Id: colortable.c,v 1.87 2000/08/10 16:56:20 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.86 2000/08/10 09:51:53 per Exp $"); +RCSID("$Id: colortable.c,v 1.87 2000/08/10 16:56:20 grubba Exp $"); #include <math.h> /* fabs() */ @@ -302,12 +302,12 @@ static ptrdiff_t reduce_recurse(struct nct_flat_entry *src, rgbd_group position,rgbd_group space, enum nct_reduce_method type) { - ptrdiff_t n,i,m; + ptrdiff_t n, i, m, g; rgbl_group sum={0,0,0},diff={0,0,0}; rgbl_group min={256,256,256},max={0,0,0}; size_t mmul,tot=0; - INT32 gdiff=0,g; - int left,right; + INT32 gdiff=0; + ptrdiff_t left, right; enum { SORT_R,SORT_G,SORT_B,SORT_GREY } st; rgbd_group newpos1,newpos2; @@ -357,11 +357,11 @@ static ptrdiff_t reduce_recurse(struct nct_flat_entry *src, tot+=mul; } - dest->color.r=sum.r/tot; - dest->color.g=sum.g/tot; - dest->color.b=sum.b/tot; - dest->weight=tot; - dest->no=-1; + dest->color.r = DO_NOT_WARN(sum.r/tot); + dest->color.g = DO_NOT_WARN(sum.g/tot); + dest->color.b = DO_NOT_WARN(sum.b/tot); + dest->weight = tot; + dest->no = -1; #ifdef COLORTABLE_REDUCE_DEBUG fprintf(stderr,"COLORTABLE%*s sum=%d,%d,%d tot=%d\n",level,"",sum.r,sum.g,sum.b,tot); @@ -601,7 +601,7 @@ static struct nct_flat _img_reduce_number_of_colors(struct nct_flat flat, unsigned long maxcols, rgbl_group sf) { - int i,j; + ptrdiff_t i,j; struct nct_flat_entry *newe; rgbd_group pos={0.5,0.5,0.5},space={0.5,0.5,0.5}; @@ -615,7 +615,10 @@ static struct nct_flat _img_reduce_number_of_colors(struct nct_flat flat, flat.entries=realloc(newe,i*sizeof(struct nct_flat_entry)); flat.numentries=i; - if (!flat.entries) { free(newe); resource_error(NULL,0,0,"memory",0,"Out of memory.\n"); } + if (!flat.entries) { + free(newe); + resource_error(NULL, 0, 0, "memory", 0, "Out of memory.\n"); + } for (j=0; j<i; j++) flat.entries[j].no=j; @@ -637,9 +640,9 @@ struct color_hash_entry static INLINE struct color_hash_entry *insert_in_hash(rgb_group rgb, struct color_hash_entry *hash, - unsigned long hashsize) + size_t hashsize) { - unsigned long j,k; + size_t j, k; j=(rgb.r*127+rgb.b*997+rgb.g*2111)%hashsize; k=100; if (j+100>=hashsize) @@ -662,9 +665,9 @@ static INLINE struct color_hash_entry *insert_in_hash(rgb_group rgb, static INLINE struct color_hash_entry *insert_in_hash_nd(rgb_group rgb, struct color_hash_entry *hash, - unsigned long hashsize) + size_t hashsize) { - unsigned long j,k; + size_t j, k; j=(rgb.r*127+rgb.b*997+rgb.g*2111)%hashsize; k=100; if (j+100>=hashsize) @@ -1029,10 +1032,10 @@ static INLINE void _find_cube_dist(struct nct_cube cube,rgb_group rgb, b.g=((INT32)rgb.g)-s->low.g; b.b=((INT32)rgb.b)-s->low.b; - n=(int)((s->steps*(b.r*s->vector.r+ - b.g*s->vector.g+ - b.b*s->vector.b))*s->invsqvector); - + n = DOUBLE_TO_INT((s->steps*(b.r*s->vector.r+ + b.g*s->vector.g+ + b.b*s->vector.b))*s->invsqvector); + if (n<0) n=0; else if (n>=s->steps) n=s->steps-1; if (s->no[n]>=nc) @@ -1261,7 +1264,7 @@ static void _img_add_colortable(struct neo_colortable *rdest, struct nct_flat_entry *en; struct nct_flat flat; struct neo_colortable *dest=rdest; - int no; + ptrdiff_t no; colortable_init_stuff(&tmp1); colortable_init_stuff(&tmp2); @@ -1439,7 +1442,7 @@ static void _img_sub_colortable(struct neo_colortable *rdest, { struct neo_colortable tmp1,tmp2; struct color_hash_entry *hash,*mark; - unsigned long i,j,hashsize,k; + size_t i,j,hashsize,k; struct nct_flat_entry *en; struct nct_flat flat; struct neo_colortable *dest=rdest; @@ -2521,7 +2524,7 @@ void image_colortable_cast_to_mapping(struct neo_colortable *nct) free(flat.entries); } -int image_colortable_size(struct neo_colortable *nct) +ptrdiff_t image_colortable_size(struct neo_colortable *nct) { if (nct->type==NCT_FLAT) return nct->u.flat.numentries; @@ -3134,7 +3137,7 @@ static INLINE void _build_cubicle(struct neo_colortable *nct, int bmin,bmax; struct nct_flat_entry *fe=nct->u.flat.entries; - int n=nct->u.flat.numentries; + ptrdiff_t n=nct->u.flat.numentries; int i=0; int *p=malloc(n*sizeof(struct nctlu_cubicle)); diff --git a/src/modules/Image/colortable.h b/src/modules/Image/colortable.h index 91191ceea0a1ea1fe5b954ccb535f1ad60cfffdc..2821a15564e30e47c8b8577f086eb91a5c016889 100644 --- a/src/modules/Image/colortable.h +++ b/src/modules/Image/colortable.h @@ -1,7 +1,7 @@ /* **! module Image **! note -**! $Id: colortable.h,v 1.19 2000/08/09 17:13:15 grubba Exp $ +**! $Id: colortable.h,v 1.20 2000/08/10 16:56:10 grubba Exp $ */ #ifdef PIKE_IMAGE_COLORTABLE_H @@ -25,7 +25,7 @@ struct nct_flat_entry /* flat colorentry */ { rgb_group color; nct_weight_t weight; - signed long no; + ptrdiff_t no; }; struct nct_scale diff --git a/src/modules/Image/dct.c b/src/modules/Image/dct.c index 1f17b3d6e402d95863caec1d7dec7e70047067ab..95389a06c287ae1dd4db6edaadd4cd706bec5b23 100644 --- a/src/modules/Image/dct.c +++ b/src/modules/Image/dct.c @@ -1,9 +1,9 @@ -/* $Id: dct.c,v 1.15 2000/07/28 07:12:44 hubbe Exp $ */ +/* $Id: dct.c,v 1.16 2000/08/10 16:48:59 grubba Exp $ */ /* **! module Image **! note -**! $Id: dct.c,v 1.15 2000/07/28 07:12:44 hubbe Exp $ +**! $Id: dct.c,v 1.16 2000/08/10 16:48:59 grubba Exp $ **! class Image */ @@ -84,8 +84,8 @@ void image_dct(INT32 args) if (!THIS->img) error("Called Image.Image object is not initialized\n");; fprintf(stderr,"%lu bytes, %lu bytes\n", - (unsigned long)(sizeof(rgbd_group)*THIS->xsize*THIS->ysize), - (unsigned long)(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1)); + DO_NOT_WARN((unsigned long)(sizeof(rgbd_group)*THIS->xsize*THIS->ysize)), + DO_NOT_WARN((unsigned long)(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1))); if (!(area=malloc(sizeof(rgbd_group)*THIS->xsize*THIS->ysize+1))) resource_error(NULL,0,0,"memory",0,"Out of memory.\n"); @@ -193,9 +193,9 @@ void image_dct(INT32 args) sum.r*=enh; sum.g*=enh; sum.b*=enh; - pix->r=testrange(((int)(sum.r+0.5))); - pix->g=testrange(((int)(sum.g+0.5))); - pix->b=testrange(((int)(sum.b+0.5))); + pix->r=testrange((DOUBLE_TO_INT(sum.r+0.5))); + pix->g=testrange((DOUBLE_TO_INT(sum.g+0.5))); + pix->b=testrange((DOUBLE_TO_INT(sum.b+0.5))); pix++; } fprintf(stderr,"."); fflush(stderr); diff --git a/src/modules/Image/pattern.c b/src/modules/Image/pattern.c index b38f11bd9ab405c5c6a2a82268206cfa869f92a4..800b495cbc6bf8d9dd882281953c11cd435bd75e 100644 --- a/src/modules/Image/pattern.c +++ b/src/modules/Image/pattern.c @@ -1,9 +1,9 @@ -/* $Id: pattern.c,v 1.20 2000/07/28 07:12:44 hubbe Exp $ */ +/* $Id: pattern.c,v 1.21 2000/08/10 16:47:00 grubba Exp $ */ /* **! module Image **! note -**! $Id: pattern.c,v 1.20 2000/07/28 07:12:44 hubbe Exp $ +**! $Id: pattern.c,v 1.21 2000/08/10 16:47:00 grubba Exp $ **! class Image */ @@ -193,8 +193,8 @@ static double noise(double Vx,double Vy,double *noise_p) for (n=0; n<3; n++) { - Ax[n]=(int)floor(NOISE_PX*FRAC( (fx+n)*NOISE_PHI )); - Ay[n]=(int)floor(NOISE_PY*FRAC( (fy+n)*NOISE_PHI )); + Ax[n] = DOUBLE_TO_INT(floor(NOISE_PX*FRAC( (fx+n)*NOISE_PHI ))); + Ay[n] = DOUBLE_TO_INT(floor(NOISE_PY*FRAC( (fy+n)*NOISE_PHI ))); } f=FRAC(Vx); @@ -242,10 +242,10 @@ static INLINE double turbulence(double x,double y,int octaves) static void init_colorrange(rgb_group *cr,struct svalue *s,char *where) { - float *v,*vp; + double *v,*vp; int i,n,k; rgbd_group lrgb,*rgbp,*rgb; - float fr,fg,fb,q; + double fr,fg,fb,q; int b; if (s->type!=T_ARRAY) @@ -253,7 +253,7 @@ static void init_colorrange(rgb_group *cr,struct svalue *s,char *where) else if (s->u.array->size<2) error("Colorrange array too small (meaningless) (to %s)\n",where); - vp=v=(void*)xalloc(sizeof(float)*(s->u.array->size/2+1)); + vp=v=(void*)xalloc(sizeof(double)*(s->u.array->size/2+1)); rgbp=rgb=(void*)xalloc(sizeof(rgbd_group)*(s->u.array->size/2+1)); for (i=0; i<s->u.array->size-1; i+=2) @@ -261,9 +261,9 @@ static void init_colorrange(rgb_group *cr,struct svalue *s,char *where) rgb_group rgbt; if (s->u.array->item[i].type==T_INT) - *vp=s->u.array->item[i].u.integer; + *vp = (double)s->u.array->item[i].u.integer; else if (s->u.array->item[i].type==T_FLOAT) - *vp=s->u.array->item[i].u.float_number; + *vp = s->u.array->item[i].u.float_number; else bad_arg_error(where, 0,0, 1, "array of int|float,color", 0, @@ -295,7 +295,7 @@ static void init_colorrange(rgb_group *cr,struct svalue *s,char *where) if (n>i) { - q=1/((float)(n-i)); + q = 1.0/((double)(n-i)); fr=(rgb[k].r-lrgb.r)*q; fg=(rgb[k].g-lrgb.g)*q; @@ -330,7 +330,7 @@ static void init_colorrange(rgb_group *cr,struct svalue *s,char *where) #define GET_INT_ARG(sp,args,n,def,where) \ ( (args>n) \ ? ( (sp[n-args].type==T_INT) ? sp[n-args].u.integer \ - : ( (sp[n-args].type==T_FLOAT) ? (int)(sp[n-args].u.float_number) \ + : ( (sp[n-args].type==T_FLOAT) ? DOUBLE_TO_INT(sp[n-args].u.float_number) \ : ( error("illegal argument(s) to %s\n", where), 0.0 ) ) ) \ : def ) @@ -392,12 +392,12 @@ void image_noise(INT32 args) for (x=THIS->xsize,yp=ydiff; x--; yp+=1.0) { *(d++)= - cr[(int)((noise((double)x*scale,(double)y*scale,noise_p1) + cr[DOUBLE_TO_INT((noise((double)x*scale,(double)y*scale,noise_p1) /* +noise((double)(x*0.5+y*0.8660254037844386)*scale, */ /* (double)(-y*0.5+x*0.8660254037844386)*scale, */ /* noise_p2) */ - ) - *cscale)&(COLORRANGE_LEVELS-1)]; + ) + *cscale)&(COLORRANGE_LEVELS-1)]; } pop_n_elems(args); @@ -448,11 +448,11 @@ void image_turbulence(INT32 args) if (args<1) error("too few arguments to image->turbulence()\n"); - octaves=GET_INT_ARG(sp,args,1,3,"image->turbulence"); - scale=GET_FLOAT_ARG(sp,args,2,0.1,"image->turbulence"); - xdiff=GET_FLOAT_ARG(sp,args,3,0,"image->turbulence"); - ydiff=GET_FLOAT_ARG(sp,args,4,0,"image->turbulence"); - cscale=GET_FLOAT_ARG(sp,args,5,2,"image->turbulence"); + octaves = GET_INT_ARG(sp,args,1,3,"image->turbulence"); + scale = GET_FLOAT_ARG(sp,args,2,0.1,"image->turbulence"); + xdiff = GET_FLOAT_ARG(sp,args,3,0,"image->turbulence"); + ydiff = GET_FLOAT_ARG(sp,args,4,0,"image->turbulence"); + cscale = GET_FLOAT_ARG(sp,args,5,2,"image->turbulence"); init_colorrange(cr,sp-args,"image->turbulence()"); @@ -482,7 +482,7 @@ void image_turbulence(INT32 args) } #endif *(d++)= - cr[(INT32)(turbulence(xp*scale,yp*scale,octaves)*cscale) + cr[DOUBLE_TO_INT(turbulence(xp*scale,yp*scale,octaves)*cscale) & (COLORRANGE_LEVELS-1)]; }