pike.git / src / modules / Image / polyfill.c

version» Context lines:

pike.git/src/modules/Image/polyfill.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information.   */      #include "global.h"    - #if 0 - /* Prototypes are needed for these */ - /* Should really exist in math.h. This prototype might conflict with -  * dllimport stuff on Windows. /mast */ - extern double floor(double); - #endif -  - #ifdef HAVE_UNISTD_H - #include <unistd.h> - #endif -  +    #include <math.h>      #include "image_machine.h"      #include "interpret.h"   #include "svalue.h"   #include "threads.h"      #include "image.h"   
pike.git/src/modules/Image/polyfill.c:139:       d = malloc(sizeof(struct line_list));    if(!d) { free(c); return; }    d->above = above; d->below = below;    d->next = below->above;    d->dx = c->dx;    d->dy = c->dy;    below->above = d;   }    - static INLINE double line_xmax(struct line_list *v, double yp, double *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)    return v->above->x+v->dx*((*ydest=(yp+1.0))-v->above->y);    else    return (*ydest=v->below->y),v->below->x;    else if (v->dx<0.0)    if (v->above->y<yp-1e-10)    return v->above->x+v->dx*((*ydest=yp)-v->above->y);    else    return (*ydest=v->above->y),v->above->x;    else if (v->below->y>yp+1.0+1e-10)    return (*ydest=yp+1.0),v->above->x;    else    return (*ydest=v->below->y),v->below->x;   }    - static INLINE double line_xmin(struct line_list *v, double yp, double *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)    return v->above->x+v->dx*((*ydest=(yp+1.0))-v->above->y);    else    return (*ydest=v->below->y),v->below->x;    else if (v->dx>0.0)    if (v->above->y<yp-1e-10)    return v->above->x+v->dx*((*ydest=yp)-v->above->y);    else
pike.git/src/modules/Image/polyfill.c:329:    *ins=(*ins)->next;    free(c);    }    else    {    ins=&((*ins)->next);    }    }   }    - static INLINE void polyfill_row_add(double *buf, + static inline void polyfill_row_add(double *buf,    double xmin, double xmax,    double add)   {    int i; -  int xmin_i = DOUBLE_TO_INT(floor(xmin)); -  int xmax_i = DOUBLE_TO_INT(floor(xmax)); +  int xmin_i = (int)floor(xmin); +  int xmax_i = (int)floor(xmax);    if (xmax_i<0) return;    if (xmin_i == xmax_i)    buf[xmin_i] += (xmax-xmin)*add;    else if (xmin_i>=0)    {    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-((double)xmax_i));    }    else    {    for (i=0; i<xmax_i; i++) buf[i]+=add;    buf[xmax_i] += add*(xmax-((float)xmax_i));    }   }    - static INLINE void polyfill_slant_add(double *buf, + 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)); -  int xmax_i = DOUBLE_TO_INT(floor(xmax)); +  int xmin_i = (int)floor(xmin); +  int xmax_i = (int)floor(xmax);       if (xmax_i<0) return;    if (xmin_i == xmax_i) {    double dx = xmax - xmin;    buf[xmin_i] += lot*(y1+dy*dx/2)*dx;    }    else if (xmin_i>=0)    { -  double dx = DO_NOT_WARN(1.0 - (xmin-((double)xmin_i))); +  double dx = 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-((double)xmax_i));    buf[xmax_i] += lot*(y1+dy*dx/2.0)*dx;    }    else
pike.git/src/modules/Image/polyfill.c:493:    if (c->xmin<=xmin && c->xmax>=xmax)    {    double y1 = VY(c,xmin);   #ifdef POLYDEBUG    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,    xmin,y1,xmax,y2,(tog?-1.0:1.0)*((y1+y2)/2.0-yp));   #endif -  polyfill_slant_add(buf,xmin,xmax, -  DO_NOT_WARN(tog?-1.0:1.0), +  polyfill_slant_add(buf,xmin,xmax,tog?-1.0:1.0,    (yp+1)-y1,-c->dy);    tog=!tog;    }    if (c->xmin>xmax) break; /* skip the rest */    c=c->next;    }          return mtog;   }
pike.git/src/modules/Image/polyfill.c:517:    struct vertex *v,    double *buf)   {    struct line_list *ll=NULL;    int y=0;    double ixmax = (double)img->xsize;    struct vertex *to_add=v,*to_loose=v;    /* beat row for row */       if (y+1.0+1e-10<v->y) -  y = DOUBLE_TO_INT(v->y); +  y = (int)v->y;       while (y<img->ysize && (to_loose||to_add) )    {    double yp = y;    struct line_list *c;    double xmin, xmax;    rgb_group *d;    int tog=0;    int i;   
pike.git/src/modules/Image/polyfill.c:631:    if (c->xmax<xmax && c->xmax>xmin) xmax=c->xmax;    c=c->next;    }    if (xmax==1e10) break; /* no more events */       if (xmax>ixmax) xmax=ixmax;    tog=polyfill_event(xmin,xmax,yp,buf,&ll,tog);       /* shift to get next event */    xmin = xmax; -  xmax = DO_NOT_WARN(xmin - 1.0); +  xmax = xmin - 1.0;    }          /* remove any old vertices */    while (to_loose!=to_add && to_loose->y<yp+1.0-1e-10)    {    struct vertex *vx=to_loose;    to_loose=to_loose->next;    sub_vertices(&ll,vx,yp);    }       /* write this row */    d=img->img+img->xsize*y;    if(THIS->alpha)    {    for (i=0; i<img->xsize; i++)    {   #ifdef POLYDEBUG    fprintf(stderr,"%3.2f ",buf[i]);   #endif -  - #define apply_alpha(x,y,alpha) \ -  ((unsigned char)((y*(255L-(alpha))+x*(alpha))/255L)) -  +     d->r = apply_alpha( d->r, -  DOUBLE_TO_COLORTYPE((d->r*(1.0-buf[i]))+ +  (COLORTYPE)((d->r*(1.0-buf[i]))+    (img->rgb.r*buf[i])),    THIS->alpha );    d->g = apply_alpha( d->g, -  DOUBLE_TO_COLORTYPE((d->g*(1.0-buf[i]))+ +  (COLORTYPE)((d->g*(1.0-buf[i]))+    (img->rgb.g*buf[i])),    THIS->alpha );    d->b = apply_alpha( d->b, -  DOUBLE_TO_COLORTYPE((d->b*(1.0-buf[i]))+ +  (COLORTYPE)((d->b*(1.0-buf[i]))+    (img->rgb.b*buf[i])),    THIS->alpha );    d++;    }   #ifdef POLYDEBUG    fprintf(stderr,"\n");   #endif    }    else {    for (i=0; i<img->xsize; i++)    {   #ifdef POLYDEBUG    fprintf(stderr,"%3.2f ",buf[i]);   #endif -  d->r = DOUBLE_TO_COLORTYPE((d->r*(1.0-buf[i]))+(img->rgb.r*buf[i])); -  d->g = DOUBLE_TO_COLORTYPE((d->g*(1.0-buf[i]))+(img->rgb.g*buf[i])); -  d->b = DOUBLE_TO_COLORTYPE((d->b*(1.0-buf[i]))+(img->rgb.b*buf[i])); +  d->r = (COLORTYPE)((d->r*(1.0-buf[i]))+(img->rgb.r*buf[i])); +  d->g = (COLORTYPE)((d->g*(1.0-buf[i]))+(img->rgb.g*buf[i])); +  d->b = (COLORTYPE)((d->b*(1.0-buf[i]))+(img->rgb.b*buf[i]));    d++;    }   #ifdef POLYDEBUG    fprintf(stderr,"\n");   #endif    }       y++;    }    while (ll)    {    struct line_list *c;    ll=(c=ll)->next;    free(c);    }   }    - static INLINE void polyfill_free(struct vertex *top) + static inline void polyfill_free(struct vertex *top)   {    struct line_list *v,*vn;    struct vertex *tn;       while (top)    {    v=top->above;    while (v) { vn=v->next; free(v); v=vn; }    v=top->below;    while (v) { vn=v->next; free(v); v=vn; }    tn=top->next;    free(top);    top=tn;    }   }    - static INLINE struct vertex *polyfill_begin(void) + static inline struct vertex *polyfill_begin(void)   {    return NULL;   }    - static INLINE struct vertex *polyfill_add(struct vertex **top, + static inline struct vertex *polyfill_add(struct vertex **top,    struct array *a,    int arg,    char* what)   {    struct vertex *first,*last,*cur = NULL;    int n;       if( (a->type_field & ~(BIT_INT|BIT_FLOAT)) &&    (array_fix_type_field(a) & ~(BIT_INT|BIT_FLOAT)) ) {    polyfill_free(*top);
pike.git/src/modules/Image/polyfill.c:749: Inside #if 0
   return *top;   #if 0    polyfill_free(*top);    Pike_error("Illegal argument %d to %s, too few vertices (min 3)\n", arg, what);    return NULL; /* no polygon with less then tree corners */   #endif    }      #define POINT(A,N) ((TYPEOF((A)->item[N]) == 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)), -  top); +  last = first = vertex_new(POINT(a,0), POINT(a,1), top);       if (!last) {    return NULL;    }       for (n=2; n+1<a->size; n+=2)    { -  cur = vertex_new(DO_NOT_WARN(POINT(a,n)), -  DO_NOT_WARN(POINT(a,n+1)), -  top); +  cur = vertex_new(POINT(a,n), POINT(a,n+1), top);    if (!cur) {    return NULL;    }    if (cur->y<last->y)    vertex_connect(cur,last);    else if (cur->y>last->y)    vertex_connect(last,cur);    else if (cur->x<last->x)    vertex_connect(cur,last);    else
pike.git/src/modules/Image/polyfill.c:795:       return *top;   }      void image_polyfill(INT32 args)   {    struct vertex *v;    double *buf;    ONERROR err;    -  if (!THIS->img) -  Pike_error("Image.Image->polyfill: no image\n"); +  CHECK_INIT();       buf=xalloc(sizeof(double)*(THIS->xsize+1));    SET_ONERROR(err, free, buf);       v=polyfill_begin();       while (args)    {    struct vertex *v_tmp;       if (TYPEOF(sp[-1]) != T_ARRAY)    {    polyfill_free(v); -  SIMPLE_BAD_ARG_ERROR("Image.Image->polyfill", args, +  SIMPLE_ARG_TYPE_ERROR("Image.Image->polyfill", args,    "array(int|float)");    }    if ((v_tmp=polyfill_add(&v, sp[-1].u.array, args,    "Image.Image->polyfill()"))) {    v = v_tmp;    } else {    polyfill_free(v);    Pike_error("Image.Image->polyfill: Bad argument %d, bad vertex\n", args);    }    args--;