]> git.imager.perl.org - imager.git/blob - dynfilt/dyntest.c
- update the URLs for libpng and zlib
[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 channel mask (%d)\n bytes (%d)\n",im->xsize,im->ysize,im->channels,im->ch_mask,im->bytes); 
48
49   for(y=0;y<im->ysize;y++) for(x=0;x<im->xsize;x++) {
50     i_gpix(im,x,y,&rcolor);
51     for(i=0;i<im->channels;i++) rcolor.channel[i]=saturate((255*(rcolor.channel[i]-a))/(b-a));    
52     i_ppix(im,x,y,&rcolor);
53   }
54
55 }
56
57 func_ptr function_list[]={
58   {
59     "null_plug",
60     null_plug,
61     "callsub => sub { 1; }"
62   },{
63     "lin_stretch",
64     lin_stretch,
65     "callseq => ['image','a','b'], \
66     callsub => sub { my %hsh=@_; DSO_call($DSO_handle,1,\\%hsh); } \
67     "
68   },
69   {NULL,NULL,NULL}};
70
71
72 /* Remember to double backslash backslashes within Double quotes in C */
73