5 #pragma init (init_object_module) 10 #define is2Dstring(a) (isarray(a) && \ 11 ((a)->c.ary.rank==makeint(2)) && \ 12 isstring((a)->c.ary.entity)) 21 unsigned char *img, *result, *
g;
22 register int x,y,width,height,
v, diviser;
25 convp= argv[0]; imgp=argv[2]; resultp= argv[3];
26 diviser=ckintval(argv[1]);
34 for (y=1; y<=height-1; y++) {
35 for (x=1; x<=width-1; x++) {
37 v= g[-width-1]*conv[0] + g[-width]* conv[1] + g[-width+1]*conv[2] +
38 g[-1]*conv[3] + g[0]* conv[4] + g[1]*conv[5] +
39 g[width-1]*conv[6] + g[width]* conv[7] + g[width+1]*conv[8];
40 result[width*y+x]=v/diviser;}
49 {
pointer imgp, tablep, resultp;
50 register unsigned char *img, *ctable, *result;
51 register long size, i;
55 imgp=argv[0]; resultp= argv[1]; tablep=argv[2];
56 if (!isstring(imgp) || !isvector(tablep) || !isstring(resultp))
58 if (elmtypeof(imgp)==ELM_FOREIGN)
59 img=(
unsigned char *)imgp->
c.
ivec.
iv[0];
61 if (elmtypeof(resultp)==ELM_FOREIGN)
62 result=(
unsigned char *)resultp->
c.
ivec.
iv[0];
65 if (elmtypeof(tablep)==ELM_INT) {
67 for (i=0; i<size; i++) result[i]=itable[img[i]];}
68 else if (elmtypeof(tablep)==ELM_CHAR || elmtypeof(tablep)==ELM_BYTE) {
70 for (i=0; i<size; i++) result[i]=ctable[img[i]];}
78 register unsigned char *img, *half_img;
79 register int i, j, base, half_base;
81 register int half_width, half_height;
84 imgp=argv[0]; half_imgp=argv[1];
88 half_width=width/2; half_height=height/2;
93 for (j=0; j<half_height; j++) {
94 base= width*j*2; half_base=half_width*j;
95 for (i=0; i<half_width; i++)
96 half_img[half_base+i]=
97 (
unsigned long)(img[base+i*2]+img[base+i*2+1]+
98 img[base+width+i*2]+img[base+i*2+width+1])/4; }
106 register unsigned char *img, *double_img;
107 register int i, j, base, double_base;
109 register int double_width, double_height;
112 imgp=argv[0]; double_imgp=argv[1];
116 double_width=width*2; double_height=height*2;
121 for (j=0; j<height; j++) {
122 base= width*j; double_base=double_width*j*2;
123 for (i=0; i<width; i++)
124 double_img[double_base+i*2]=
125 double_img[double_base+i*2+1]=
126 double_img[double_base+double_width+i*2]=
127 double_img[double_base+double_width+i*2+1]=
128 (
unsigned long)(img[base+i]);
130 return(double_imgp);}
135 register int width, height, x, y, size;
136 {
register int med, p, q, r;
137 register int i, j, k,
v, cindex;
138 unsigned char seq[100], up[100], down[100];
142 for (j=0; j<size; j++)
143 for (i=0; i<size; i++)
144 seq[k++]= img[(j+y)*width+(x+i)];
154 else if (v>med) up[p++]=
v;
158 if (q+r>=cindex)
return(med);
160 for (i=0; i<p; i++) seq[i]=up[i];
161 cindex=cindex-(q+r); k=p;
164 for (i=0; i<q; i++) seq[i]=down[i];
174 register unsigned char *img1p, *img2p;
176 int width, height, swidth, sheight;
177 int hgrid, grid_size, hscale, scale;
183 grid_size=ckintval(argv[1]);
184 scale = ckintval(argv[2]);
192 sheight=height/scale;
193 for (j=0; j<sheight-1; j++) {
194 for (i=0; i<swidth-1; i++) {
196 median_img(img1p, width, height, scale*i, scale*j, grid_size);
pointer CONVOLVE3(context *ctx, int n, argv)
pointer LOOK_UP(context *ctx, int n, argv)
static void init_object_module()
defun("ADR_TO_STRING", mod, ADR_TO_STRING)
void add_module_initializer(char *, pointer(*)())
pointer MEDIAN_IMAGE(context *ctx, int n, argv)
pointer error(enum errorcode ec,...) pointer error(va_alist) va_dcl
pointer DOUBLE_IMAGE(context *ctx, int n, argv)
static int median_img(unsigned char *img, int width, int height, int x, int y, int size)
pointer HALVE_IMAGE(context *ctx, int n, argv)