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

version» Context lines:

pike.git/src/modules/Image/orient.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. - || $Id$ +    */      /*   **! module Image   **! class Image   */      #include "global.h"      #include <math.h>
pike.git/src/modules/Image/orient.c:89:   **! The <tt>orient4</tt> function gives back   **! 4 image objects, corresponding to the   **! amount of different directions, see above.   **!   **! returns an image or an array of the four new image objects   **!   **! note   **! experimental status; 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 void _image_orient(struct image *source,    struct object *o[5],    struct image *img[5])   {    int i;    struct { int x,y; } or[4]={ {1,0}, {1,1}, {0,1}, {-1,1} };    int x,y;       for (i=0; i<5; i++)    {    push_int(source->xsize);    push_int(source->ysize);    o[i]=clone_object(image_program,2); -  img[i]=(struct image*)get_storage(o[i],image_program); +  img[i]=get_storage(o[i],image_program);    push_object(o[i]);    }      THREADS_ALLOW();   CHRONO("start");    for (i=0; i<4; i++) /* four directions */    {    rgb_group *d=img[i]->img;    rgb_group *s=source->img;    int xz=source->xsize;
pike.git/src/modules/Image/orient.c:129:       for(x=1; x<xz-1; x++)    for(y=1; y<yz-1; y++)    {   #define FOOBAR(CO) \    d[x+y*xz].CO \    = \    (COLORTYPE) \    my_abs( s[(x+xd)+(y+yd)*xz].CO - s[(x-xd)+(y-yd)*xz].CO )    -  /* -  sqrt( ( sq( s[(x-xd)+(y-yd)*xz].CO - s[x+y*xz].CO ) + \ -  sq( s[(x+xd)+(y+yd)*xz].CO - s[x+y*xz].CO ) ) / 2.0 ) -  */ -  +     FOOBAR(r);    FOOBAR(g);    FOOBAR(b);      #undef FOOBAR    }    }   CHRONO("end");   THREADS_DISALLOW();   }
pike.git/src/modules/Image/orient.c:165:       this=THIS;       if (args)    {    if (TYPEOF(sp[-args]) == T_INT)    mag=sp[-args].u.integer;    else if (TYPEOF(sp[-args]) == T_FLOAT)    mag=sp[-args].u.float_number;    else { -  bad_arg_error("image->orient\\n",sp-args,args,1,"",sp+1-1-args, -  "Bad argument 1 to image->orient\n()\n"); -  /* Not reached, but keeps the compiler happy. */ -  mag = 0.0; +  SIMPLE_BAD_ARG_ERROR("orient",1,"int|float"); +  UNREACHABLE(mag=0.0);    }    }    else mag=1.0;       if (args==1)    pop_n_elems(args);       if (args>1)    {    if (TYPEOF(sp[1-args]) != T_ARRAY) -  bad_arg_error("image->orient\\n",sp-args,args,2,"",sp+2-1-args, -  "Bad argument 2 to image->orient\n()\n"); +  SIMPLE_BAD_ARG_ERROR("orient",2,"array");    if (sp[1-args].u.array->size!=4) -  Pike_error("The array given as argument 2 to image->orient do not have size 4\n"); +  Pike_error("The array given as argument 2 to orient do not have size 4\n");    for(i=0; i<4; i++)    if ((TYPEOF(sp[1-args].u.array->item[i]) != T_OBJECT) ||    (!(sp[1-args].u.array->item[i].u.object)) ||    (sp[1-args].u.array->item[i].u.object->prog!=image_program)) -  Pike_error("The array given as argument 2 to image->orient do not contain images\n"); +  Pike_error("The array given as argument 2 to orient do not contain images\n");    img1=(struct image*)sp[1-args].u.array->item[0].u.object->storage;       w=this->xsize;    h=this->ysize;       for(i=0; i<4; i++)    {    img1=(struct image*)sp[1-args].u.array->item[i].u.object->storage;    if ((img1->xsize!=w)||    (img1->ysize!=h)) -  Pike_error("The images in the array given as argument 2 to image->orient have different sizes\n"); +  Pike_error("The images in the array given as argument 2 to orient have different sizes\n");    }    for(i=0; i<4; i++) -  img[i]=(struct image*)sp[1-args].u.array->item[i].u.object->storage; +  img[i]=get_storage(sp[1-args].u.array->item[i].u.object,image_program);    pop_n_elems(args);    push_int(this->xsize);    push_int(this->ysize);    o[4]=clone_object(image_program,2); -  img[4]=(struct image*)get_storage(o[4],image_program); +  img[4]=get_storage(o[4],image_program);    push_object(o[4]);    w=1;    }    else    {    _image_orient(this,o,img);    w=0;    }    s0=img[0]->img;    s1=img[1]->img;
pike.git/src/modules/Image/orient.c:242:       int z,w;       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 { +  if (j) {    z = -DOUBLE_TO_INT(-32*(h/j)+(j>0)*128+128);    w = my_abs(DOUBLE_TO_INT(j));    } -  +  else z=0,w=0; +  }       d->r=(COLORTYPE)z;    d->g=255;    d->b = MINIMUM(DOUBLE_TO_COLORTYPE(w*mag), 255);       d++;    s0++;    s1++;    s2++;    s3++;