]> git.imager.perl.org - imager.git/blob - dynfilt/dyntest.c
add i_gsamp_bg/i_gsampf_bg functions, sample based versions of
[imager.git] / dynfilt / dyntest.c
1 #include "pluginst.h"
2
3
4 char evalstr[]="Description string of plugin dyntest - kind of like";
5
6 void null_plug(void *ptr) { }
7
8 /* Example dynamic filter - level stretch (linear) - note it only stretches and doesn't compress */
9
10 /* input parameters
11    a: the current black
12    b: the current white
13    
14    0 <= a < b <= 255;
15
16    output pixel value calculated by: o=((i-a)*255)/(b-a);
17
18    note that since we do not have the needed functions to manipulate the data structures *** YET ***
19 */
20
21
22 unsigned char
23 static
24 saturate(int in) {
25   if (in>255) { return 255; }
26   else if (in>0) return in;
27   return 0;
28 }
29
30 void lin_stretch(void *INP) {
31
32   int a, b;
33   i_img *im;
34   i_color rcolor;
35   int i,bytes,x,y;
36   int info[4];
37
38   if ( !getOBJ("image","Imager::ImgRaw",&im) ) { fprintf(stderr,"Error: image is missing\n"); }
39   if ( !getINT("a",&a) ) { fprintf(stderr,"Error: a is missing\n"); }
40   if ( !getINT("b",&b) ) { fprintf(stderr,"Error: b is missing\n"); }
41   
42   /*   fprintf(stderr,"parameters: (im 0x%x,a %d,b %d)\n",im,a,b);*/
43   bytes=im->bytes;
44
45   i_img_info(im,info); 
46   for(i=0;i<4;i++) { printf("%d: %d\n",i,info[i]); } 
47   printf("image info:\n size (%d,%d)\n channels (%d)\n",
48          im->xsize, im->ysize, im->channels); 
49
50   for(y=0;y<im->ysize;y++) for(x=0;x<im->xsize;x++) {
51     i_gpix(im,x,y,&rcolor);
52     for(i=0;i<im->channels;i++) rcolor.channel[i]=saturate((255*(rcolor.channel[i]-a))/(b-a));    
53     i_ppix(im,x,y,&rcolor);
54   }
55
56 }
57
58 func_ptr function_list[]={
59   {
60     "null_plug",
61     null_plug,
62     "callsub => sub { 1; }"
63   },{
64     "lin_stretch",
65     lin_stretch,
66     "callseq => ['image','a','b'], \
67     callsub => sub { my %hsh=@_; DSO_call($DSO_handle,1,\\%hsh); } \
68     "
69   },
70   {NULL,NULL,NULL}};
71
72
73 /* Remember to double backslash backslashes within Double quotes in C */
74