]> git.imager.perl.org - imager.git/blame - dynfilt/dyntest.c
note GIF changes
[imager.git] / dynfilt / dyntest.c
CommitLineData
02d1d628
AMH
1#include "pluginst.h"
2
3
4char evalstr[]="Description string of plugin dyntest - kind of like";
5
6void 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
22unsigned char
23static
24saturate(int in) {
25 if (in>255) { return 255; }
26 else if (in>0) return in;
27 return 0;
28}
29
30void lin_stretch(void *INP) {
31
32 int a, b;
33 i_img *im;
34 i_color rcolor;
8d14daab
TC
35 int i;
36 i_img_dim x,y;
37 size_t bytes;
38 i_img_dim info[4];
02d1d628
AMH
39
40 if ( !getOBJ("image","Imager::ImgRaw",&im) ) { fprintf(stderr,"Error: image is missing\n"); }
41 if ( !getINT("a",&a) ) { fprintf(stderr,"Error: a is missing\n"); }
42 if ( !getINT("b",&b) ) { fprintf(stderr,"Error: b is missing\n"); }
43
44 /* fprintf(stderr,"parameters: (im 0x%x,a %d,b %d)\n",im,a,b);*/
45 bytes=im->bytes;
46
47 i_img_info(im,info);
8d14daab
TC
48 for(i=0;i<4;i++) { printf("%d: %" i_DF "\n", i, i_DFc(info[i])); }
49 printf("image info:\n size (" i_DFp ")\n channels (%d)\n",
50 i_DFcp(im->xsize, im->ysize), im->channels);
02d1d628
AMH
51
52 for(y=0;y<im->ysize;y++) for(x=0;x<im->xsize;x++) {
53 i_gpix(im,x,y,&rcolor);
54 for(i=0;i<im->channels;i++) rcolor.channel[i]=saturate((255*(rcolor.channel[i]-a))/(b-a));
55 i_ppix(im,x,y,&rcolor);
56 }
57
58}
59
60func_ptr function_list[]={
61 {
62 "null_plug",
63 null_plug,
64 "callsub => sub { 1; }"
65 },{
66 "lin_stretch",
67 lin_stretch,
68 "callseq => ['image','a','b'], \
69 callsub => sub { my %hsh=@_; DSO_call($DSO_handle,1,\\%hsh); } \
70 "
71 },
72 {NULL,NULL,NULL}};
73
74
75/* Remember to double backslash backslashes within Double quotes in C */
76