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

version» Context lines:

pike.git/src/modules/Image/search.c:7:   /*   **! module Image   **! class Image   */   #include "global.h"      #include <math.h>   #include <ctype.h>      #include "stralloc.h" - #include "global.h" +    #include "pike_macros.h"   #include "object.h"   #include "interpret.h"   #include "svalue.h"   #include "threads.h"   #include "pike_error.h"   #include "module_support.h"      #include "image.h"         #define sp Pike_sp      extern struct program *image_program;   #ifdef THIS   #undef THIS /* Needed for NT */   #endif   #define THIS ((struct image *)(Pike_fp->current_storage))   #define THISOBJ (Pike_fp->current_object)    - #define testrange(x) MAXIMUM(MINIMUM((x),255),0) -  +    static const double c0=0.70710678118654752440;   static const double my_PI=3.14159265358979323846;      #if 0   #include <sys/resource.h>   #define CHRONO(X) chrono(X);      static void chrono(char *x)   {    struct rusage r;
pike.git/src/modules/Image/search.c:108:   **! </table>   **!   **! returns the new image object   ** see also: match_phase   **! bugs   **! 0 should not be set as explained above.   **! note   **! <b>experimental status</b>; may not be exact the same   **! output in later versions   */ - static INLINE int sq(int a) { return a*a; } - static INLINE int my_abs(int a) { return (a<0)?-a:a; } + static inline int my_abs(int a) { return (a<0)?-a:a; }      /* phase-image creating functions */      #define NEIG 1   #define IMAGE_PHASE image_phaseh   #include "phase.h"   #undef NEIG   #undef IMAGE_PHASE      #define NEIG xz
pike.git/src/modules/Image/search.c:236:   **! This method creates a string that looks like   **! the image. Example:   **! <pre>   **! //Stina is an image with a cat.   **! array(object) Stina4=Stina->orient4();   **! Stina4[1]*=215;   **! Stina4[3]*=215;   **! string foo=Stina->make_ascii(@Stina4,40,4,8);   **! </pre>   **! - **! returns some nice acsii-art. + **! returns some nice ASCII art.   **! see also: orient, orient4   **! note   **! <b>experimental status</b>; may not be exact the same   **! output in later versions   */      /* FIXME: This functions does not depend on the actual image object    and should be removed from the object or reworked. */   void image_make_ascii(INT32 args)   {    struct object *objs[4];    struct image *img[4];    INT32 xchar_size=0;    INT32 ychar_size=0;    INT32 tlevel=0;    int i, x, y,xy=0,y2=0, xmax=0,ymax=0,max;    struct pike_string *s;    -  get_all_args("make_ascii", args, "%o%o%o%o.%d%d%d", +  get_all_args(NULL, args, "%o%o%o%o.%d%d%d",    &objs[0], &objs[1], &objs[2], &objs[3],    &tlevel, &xchar_size, &ychar_size);       for(i=0; i<4; i++) { -  img[i]=(struct image*)get_storage(objs[i],image_program); +  img[i]=get_storage(objs[i],image_program);    if(!img[i]) -  SIMPLE_BAD_ARG_ERROR("make_ascii",i+1,"Image.Image"); +  SIMPLE_ARG_TYPE_ERROR("make_ascii",i+1,"Image.Image");    if(i!=0 &&    img[0]->xsize!=img[i]->xsize &&    img[0]->ysize!=img[i]->ysize)    Pike_error("make_ascii: Different sized images.\n");    }       if (!tlevel) tlevel=40;    if (!xchar_size) xchar_size=5;    if (!ychar_size) ychar_size=8;   
pike.git/src/modules/Image/search.c:422:   **! base level of result, default is zero   **! arg int|float div   **! division factor, default is 1.0.   **! note   **! <b>experimental status</b>; may not be exact the same   **! output in later versions   */          - static INLINE rgb_group _pixel_apply_max(struct image *img, + static inline rgb_group _pixel_apply_max(struct image *img,    int x,int y,    int width,int height,    rgbd_group *matrix,    rgb_group default_rgb,    double div)   {    rgb_group res;    int i,j,bx,by,xp,yp;    int sumr,sumg,sumb,r,g,b;    double qdiv=1.0/div;
pike.git/src/modules/Image/search.c:449:    sumr=sumg=sumb=0;    r=g=b=0;       bx=width/2;    by=height/2;       for (xp=x-bx,i=0; i<width; i++,xp++)    for (yp=y-by,j=0; j<height; j++,yp++)    if (xp>=0 && xp<img->xsize && yp>=0 && yp<img->ysize)    { -  r = DOUBLE_TO_INT(MAXIMUM(r, matrix[i+j*width].r * -  img->img[xp+yp*img->xsize].r)); -  g = DOUBLE_TO_INT(MAXIMUM(g, matrix[i+j*width].g * -  img->img[xp+yp*img->xsize].g)); -  b = DOUBLE_TO_INT(MAXIMUM(b, matrix[i+j*width].b * -  img->img[xp+yp*img->xsize].b)); +  r = (int)MAXIMUM(r, matrix[i+j*width].r * +  img->img[xp+yp*img->xsize].r); +  g = (int)MAXIMUM(g, matrix[i+j*width].g * +  img->img[xp+yp*img->xsize].g); +  b = (int)MAXIMUM(b, matrix[i+j*width].b * +  img->img[xp+yp*img->xsize].b);   #ifdef MATRIX_DEBUG    fprintf(stderr,"%d,%d %d,%d->%d,%d,%d\n",    i,j,xp,yp,    img->img[x+i+(y+j)*img->xsize].r,    img->img[x+i+(y+j)*img->xsize].g,    img->img[x+i+(y+j)*img->xsize].b);   #endif -  sumr = DOUBLE_TO_INT(MAXIMUM(sumr, matrix[i+j*width].r)); -  sumg = DOUBLE_TO_INT(MAXIMUM(sumg, matrix[i+j*width].g)); -  sumb = DOUBLE_TO_INT(MAXIMUM(sumb, matrix[i+j*width].b)); +  sumr = (int)MAXIMUM(sumr, matrix[i+j*width].r); +  sumg = (int)MAXIMUM(sumg, matrix[i+j*width].g); +  sumb = (int)MAXIMUM(sumb, matrix[i+j*width].b);    }    if (sumr) -  res.r = DOUBLE_TO_COLORTYPE(testrange(default_rgb.r + r/(sumr * div))); +  res.r = (COLORTYPE)testrange(default_rgb.r + r/(sumr * div));    else -  res.r = DOUBLE_TO_COLORTYPE(testrange(r * qdiv + default_rgb.r)); +  res.r = (COLORTYPE)testrange(r * qdiv + default_rgb.r);    if (sumg) -  res.g = DOUBLE_TO_COLORTYPE(testrange(default_rgb.g + g/(sumg * div))); +  res.g = (COLORTYPE)testrange(default_rgb.g + g/(sumg * div));    else -  res.g = DOUBLE_TO_COLORTYPE(testrange(g * qdiv + default_rgb.g)); +  res.g = (COLORTYPE)testrange(g * qdiv + default_rgb.g);    if (sumb) -  res.b = DOUBLE_TO_COLORTYPE(testrange(default_rgb.g + b/(sumb * div))); +  res.b = (COLORTYPE)testrange(default_rgb.b + b/(sumb * div));    else -  res.b = DOUBLE_TO_COLORTYPE(testrange(b * qdiv + default_rgb.b)); +  res.b = (COLORTYPE)testrange(b * qdiv + default_rgb.b);   #ifdef MATRIX_DEBUG    fprintf(stderr,"->%d,%d,%d\n",res.r,res.g,res.b);   #endif    return res;    REVEAL_GLOBAL_VARIABLES();   }         void img_apply_max(struct image *dest,    struct image *img,
pike.git/src/modules/Image/search.c:499:    rgbd_group *matrix,    rgb_group default_rgb,    double div)   {    rgb_group *d,*ip,*dp;    rgbd_group *mp;    int i,x,y,bx,by,ex,ey,yp;    int widthheight;    double sumr,sumg,sumb;    double qr,qg,qb; -  register double r=0,g=0,b=0; +  double r=0,g=0,b=0;       d=xalloc(sizeof(rgb_group)*img->xsize*img->ysize+RGB_VEC_PAD);      THREADS_ALLOW();       widthheight=width*height;    sumr=sumg=sumb=0;    for (i=0; i<widthheight;)    {    sumr=MAXIMUM(sumr, matrix[i].r);    sumg=MAXIMUM(sumg, matrix[i].g);    sumb=MAXIMUM(sumb, matrix[i++].b);    }    -  if (!sumr) sumr=1; sumr*=div; qr=1.0/sumr; -  if (!sumg) sumg=1; sumg*=div; qg=1.0/sumg; -  if (!sumb) sumb=1; sumb*=div; qb=1.0/sumb; +  if (!sumr) {sumr=1;} sumr*=div; qr=1.0/sumr; +  if (!sumg) {sumg=1;} sumg*=div; qg=1.0/sumg; +  if (!sumb) {sumb=1;} sumb*=div; qb=1.0/sumb;       bx=width/2;    by=height/2;    ex=width-bx;    ey=height-by;       for (y=by; y<img->ysize-ey; y++)    {    dp=d+y*img->xsize+bx;    for (x=bx; x<img->xsize-ex; x++)
pike.git/src/modules/Image/search.c:560:    img->img[x+i+(y+j)*img->xsize].b);   #endif    mp++;    ip++;    }    ip+=img->xsize-width;    }   #ifdef MATRIX_DEBUG    fprintf(stderr,"->%d,%d,%d\n",r/sumr,g/sumg,b/sumb);   #endif -  r = default_rgb.r+DOUBLE_TO_INT(r*qr+0.5); -  dp->r = DOUBLE_TO_COLORTYPE(testrange(r)); -  g = default_rgb.g+DOUBLE_TO_INT(g*qg+0.5); -  dp->g = DOUBLE_TO_COLORTYPE(testrange(g)); -  b = default_rgb.b+DOUBLE_TO_INT(b*qb+0.5); -  dp->b = DOUBLE_TO_COLORTYPE(testrange(b)); +  r = default_rgb.r+(int)(r*qr+0.5); +  dp->r = (COLORTYPE)testrange(r); +  g = default_rgb.g+(int)(g*qg+0.5); +  dp->g = (COLORTYPE)testrange(g); +  b = default_rgb.b+(int)(b*qb+0.5); +  dp->b = (COLORTYPE)testrange(b);    dp++;    }    }          for (y=0; y<img->ysize; y++)    {    for (x=0; x<bx; x++)    d[x+y*img->xsize]=_pixel_apply_max(img,x,y,width,height,    matrix,default_rgb,div);
pike.git/src/modules/Image/search.c:611:   void image_apply_max(INT32 args)   {    int width,height,i,j;    rgbd_group *matrix;    rgb_group default_rgb;    struct object *o;    double div;       if (args<1 ||    TYPEOF(sp[-args]) != T_ARRAY) -  bad_arg_error("Image",sp-args,args,0,"",sp-args, -  "Bad arguments to Image()\n"); +  SIMPLE_ARG_TYPE_ERROR("apply_max", 1, "array");       if (args>3) -  if (TYPEOF(sp[1-args]) != T_INT || -  TYPEOF(sp[2-args]) != T_INT || -  TYPEOF(sp[3-args]) != T_INT) -  Pike_error("Illegal argument(s) (2,3,4) to Image.Image->apply_max()\n"); -  else +     { -  default_rgb.r=sp[1-args].u.integer; -  default_rgb.g=sp[1-args].u.integer; -  default_rgb.b=sp[1-args].u.integer; +  struct array *a; +  get_all_args(NULL, args, "%a%d%d%d", &a, +  &default_rgb.r, &default_rgb.g, &default_rgb.b);    }    else    {    default_rgb.r=0;    default_rgb.g=0;    default_rgb.b=0;    }       if (args>4    && TYPEOF(sp[4-args]) == T_INT)