e576bb | 2002-10-11 | Martin Nilsson | |
|
c43fc1 | 1999-03-01 | Henrik Wallin | |
|
ec1232 | 2013-02-23 | Henrik Grubbström (Grubba) | | INAME The name of the match c-function. This is undef:ed at end of this file
|
12de55 | 1999-03-15 | Henrik Wallin | | PIXEL_VALUE_DISTANCE The inner loop code for each pixel.
undef:ed at end of this file
|
182649 | 1999-03-21 | Henrik Wallin | | NEEDLEAVRCODE If this is set, needle_average is calculated.
Not undef:ed at end
|
c43fc1 | 1999-03-01 | Henrik Wallin | | NORMCODE code used for normalizing in the haystack. Not undef:ed at end
|
12de55 | 1999-03-15 | Henrik Wallin | | SCALE_MODIFY(x) This modifies the output in each pixel
|
c43fc1 | 1999-03-01 | Henrik Wallin | |
*/
void INAME(INT32 args)
{
struct object *o;
|
182649 | 1999-03-21 | Henrik Wallin | | struct image *img,*needle=0, *haystack_cert=0, *haystack_avoid=0,
*haystack=0, *needle_cert=0, *this;
|
c43fc1 | 1999-03-01 | Henrik Wallin | | rgb_group *imgi=0, *needlei=0, *haystack_certi=0, *haystack_avoidi=0,
*haystacki=0, *needle_certi=0, *thisi=0;
int type=0;
int xs,ys, y, x;
int nxs,nys, ny, nx;
int foo=0;
|
36a00c | 2000-08-15 | Henrik Grubbström (Grubba) | | double scale = 1.0;
|
c43fc1 | 1999-03-01 | Henrik Wallin | | int needle_average=0;
|
ec1232 | 2013-02-23 | Henrik Grubbström (Grubba) | | int needle_size=1;
|
c43fc1 | 1999-03-01 | Henrik Wallin | |
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | if (!THIS->img) { Pike_error("no image\n"); return; }
|
c43fc1 | 1999-03-01 | Henrik Wallin | | this=THIS;
haystacki=this->img;
haystack=this;
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | if (!args) { Pike_error("Missing arguments to image->"NAME"\n"); return; }
else if (args<2) { Pike_error("Too few arguments to image->"NAME"\n"); return; }
|
c43fc1 | 1999-03-01 | Henrik Wallin | | else
{
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if (TYPEOF(sp[-args]) == T_INT)
|
ea7a4d | 2000-08-09 | Henrik Grubbström (Grubba) | | scale = (double)sp[-args].u.integer;
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | else if (TYPEOF(sp[-args]) == T_FLOAT)
|
ea7a4d | 2000-08-09 | Henrik Grubbström (Grubba) | | scale = sp[-args].u.float_number;
|
c43fc1 | 1999-03-01 | Henrik Wallin | | else
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Illegal argument 1 to image->"NAME"\n");
|
c43fc1 | 1999-03-01 | Henrik Wallin | |
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if ((TYPEOF(sp[1-args]) != T_OBJECT)
|
796864 | 2014-05-26 | Per Hedbor | | || !(needle=get_storage(sp[1-args].u.object,image_program)))
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Illegal argument 2 to image->"NAME"()\n");
|
c43fc1 | 1999-03-01 | Henrik Wallin | |
if ((needle->xsize>haystack->xsize)||
(needle->ysize>haystack->ysize))
|
a4a172 | 2000-12-05 | Per Hedbor | | Pike_error("Haystack must be bigger than needle, error in image->"NAME"()\n");
|
c43fc1 | 1999-03-01 | Henrik Wallin | | needlei=needle->img;
haystacki=haystack->img;
if ((args==2)||(args==3))
type=1;
else
{
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if ((TYPEOF(sp[2-args]) != T_OBJECT) ||
|
796864 | 2014-05-26 | Per Hedbor | | !(haystack_cert=get_storage(sp[2-args].u.object,image_program)))
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Illegal argument 3 to image->"NAME"()\n");
|
c43fc1 | 1999-03-01 | Henrik Wallin | | else
if ((haystack->xsize!=haystack_cert->xsize)||
(haystack->ysize!=haystack_cert->ysize))
|
a4a172 | 2000-12-05 | Per Hedbor | | Pike_error("Argument 3 must be the same size as haystack error in image->"NAME"()\n");
|
c43fc1 | 1999-03-01 | Henrik Wallin | |
|
90748e | 2012-03-01 | Henrik Grubbström (Grubba) | | if (TYPEOF(sp[3-args]) == T_INT)
|
c43fc1 | 1999-03-01 | Henrik Wallin | | {
foo=sp[3-args].u.integer;
type=3;
haystack_avoid=haystack_cert;
haystack_cert=0;
}
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | else if ((TYPEOF(sp[3-args]) != T_OBJECT) ||
|
796864 | 2014-05-26 | Per Hedbor | | !(needle_cert=get_storage(sp[3-args].u.object,image_program)))
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Illegal argument 4 to image->"NAME"()\n");
|
c43fc1 | 1999-03-01 | Henrik Wallin | | else
{
if ((needle_cert->xsize!=needle->xsize)||
(needle_cert->ysize!=needle->ysize))
|
a4a172 | 2000-12-05 | Per Hedbor | | Pike_error("Needle_cert must be the same size as needle error in image->"NAME"()\n");
|
c43fc1 | 1999-03-01 | Henrik Wallin | | type=2;
}
if (args>=6)
{
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if (TYPEOF(sp[5-args]) == T_INT)
|
c43fc1 | 1999-03-01 | Henrik Wallin | | {
foo=sp[5-args].u.integer;
type=4;
}
else
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Illegal argument 6 to image->"NAME"()\n");
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if ((TYPEOF(sp[4-args]) != T_OBJECT) ||
|
796864 | 2014-05-26 | Per Hedbor | | !(haystack_avoid=get_storage(sp[4-args].u.object,image_program)))
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Illegal argument 5 to image->"NAME"()\n");
|
c43fc1 | 1999-03-01 | Henrik Wallin | | else
if ((haystack->xsize!=haystack_avoid->xsize)||
(haystack->ysize!=haystack_avoid->ysize))
|
a4a172 | 2000-12-05 | Per Hedbor | | Pike_error("Haystack_avoid must be the same size as haystack error in image->"NAME"()\n");
|
c43fc1 | 1999-03-01 | Henrik Wallin | | }
}
push_int(this->xsize);
push_int(this->ysize);
o=clone_object(image_program,2);
|
796864 | 2014-05-26 | Per Hedbor | | img=get_storage(o,image_program);
|
c43fc1 | 1999-03-01 | Henrik Wallin | | imgi=img->img;
pop_n_elems(args);
if (haystack_cert)
haystack_certi=haystack_cert->img;
if (haystack_avoid)
haystack_avoidi=haystack_avoid->img;
if (needle_cert)
needle_certi=needle_cert->img;
THREADS_ALLOW();
|
12de55 | 1999-03-15 | Henrik Wallin | | nxs=needle->xsize;
nys=needle->ysize;
xs=this->xsize;
ys=this->ysize-nys;
|
d0ba6a | 1999-03-15 | Henrik Wallin | |
|
182649 | 1999-03-21 | Henrik Wallin | | #ifdef NEEDLEAVRCODE
needle_size=nxs*nys;
for(x=0; x<needle_size; x++)
needle_average+=needlei[x].r+needlei[x].g+needlei[x].b;
|
ec1232 | 2013-02-23 | Henrik Grubbström (Grubba) | | if (!needle_size) needle_size = 1;
|
182649 | 1999-03-21 | Henrik Wallin | | needle_average=(int)(((float)needle_average)/(3*needle_size));
#define NORMCODE for(ny=0; ny<nys; ny++) \
for(nx=0; nx<nxs; nx++) \
{ \
int j=i+ny*xs+nx; \
tempavr+=haystacki[j].r+haystacki[j].g+ \
haystacki[j].b; \
}
#else
#define NORMCODE
#endif
#define DOUBLE_LOOP(AVOID_IS_TOO_BIG, CERTI1, CERTI2,R1,G1,B1) \
|
7ff650 | 1999-03-29 | Henrik Wallin | | for(y=0; y<ys; y++) \
for(x=0; x<xs-nxs; x++) \
{ \
int i=y*this->xsize+x; \
int sum=0; \
int tempavr=0;\
if (AVOID_IS_TOO_BIG) \
{\
int k=0; \
imgi[k=i+(nys/2)*xs+(nxs/2)].r=0;\
imgi[k].g=100; imgi[k].b=0;\
}\
else\
{\
NORMCODE;\
|
ea7a4d | 2000-08-09 | Henrik Grubbström (Grubba) | | tempavr = DOUBLE_TO_INT(((double)tempavr)/(3*needle_size)); \
|
7ff650 | 1999-03-29 | Henrik Wallin | | for(ny=0; ny<nys; ny++) \
for(nx=0; nx<nxs; nx++) \
|
12de55 | 1999-03-15 | Henrik Wallin | | { \
|
7ff650 | 1999-03-29 | Henrik Wallin | | int j=i+ny*xs+nx; \
int h=0;\
int n=0;\
|
78b0d0 | 2002-05-29 | Per Hedbor | | sum+=(MAXIMUM(CERTI1 R1, CERTI1 R1) * PIXEL_VALUE_DISTANCE(r)); \
sum+=(MAXIMUM(CERTI1 G1, CERTI1 G1) * PIXEL_VALUE_DISTANCE(g)); \
sum+=(MAXIMUM(CERTI1 B1, CERTI1 B1) * PIXEL_VALUE_DISTANCE(b)); \
|
7ff650 | 1999-03-29 | Henrik Wallin | | } \
imgi[i+(nys/2)*xs+(nxs/2)].r=\
|
ea7a4d | 2000-08-09 | Henrik Grubbström (Grubba) | | DOUBLE_TO_INT(255.99/(1.0+((((double)scale) * SCALE_MODIFY((double)sum))))); \
|
7ff650 | 1999-03-29 | Henrik Wallin | | }\
}
|
12de55 | 1999-03-15 | Henrik Wallin | |
|
182649 | 1999-03-21 | Henrik Wallin | |
#define AVOID_IS_TOO_BIG ((haystack_avoidi[i].r)>(foo))
|
c43fc1 | 1999-03-01 | Henrik Wallin | |
|
12de55 | 1999-03-15 | Henrik Wallin | | if (type==1)
|
941bd2 | 1999-06-17 | Henrik Wallin | | DOUBLE_LOOP(0,1,1, *1, *1, *1)
|
12de55 | 1999-03-15 | Henrik Wallin | | else if (type==2)
|
182649 | 1999-03-21 | Henrik Wallin | | DOUBLE_LOOP(0, haystack_certi[j], needle_certi[ny*nxs+nx],.r,.g,.b)
|
12de55 | 1999-03-15 | Henrik Wallin | | else if (type==3)
|
941bd2 | 1999-06-17 | Henrik Wallin | | DOUBLE_LOOP(AVOID_IS_TOO_BIG,1,1, *1, *1, *1)
|
12de55 | 1999-03-15 | Henrik Wallin | | else if (type==4)
|
182649 | 1999-03-21 | Henrik Wallin | | DOUBLE_LOOP(AVOID_IS_TOO_BIG, haystack_certi[j], needle_certi[ny*nxs+nx],.r,.g,.b)
|
12de55 | 1999-03-15 | Henrik Wallin | |
|
182649 | 1999-03-21 | Henrik Wallin | | #undef NORMCODE
#undef AVOID_IS_TOO_BIG
|
12de55 | 1999-03-15 | Henrik Wallin | | #undef PIXEL_VALUE_DISTANCE
#undef DOUBLE_LOOP
|
c43fc1 | 1999-03-01 | Henrik Wallin | |
THREADS_DISALLOW();
}
push_object(o);
}
#undef NAME
#undef INAME
|