Debian Codegraph @

DynTest/linstretch.c

raw
1 #include "imext.h"
2
3 char evalstr[]="Description string of plugin dyntest - kind of like";
4
5 void null_plug(void *ptr) {
6 (void)ptr;
7 }
8
9 /* Example dynamic filter - level stretch (linear) - note it only stretches and doesn't compress */
10
11 /* input parameters
12 a: the current black
13 b: the current white
14
15 0 <= a < b <= 255;
16
17 output pixel value calculated by: o=((i-a)*255)/(b-a);
18
19 note that since we do not have the needed functions to manipulate the data structures *** YET ***
20 */
21
22
23 static
24 unsigned char
25 saturate(int in) {
26 if (in>255) { return 255; }
27 else if (in>0) return in;
28 return 0;
29 }
30
31 void lin_stretch(i_img *im, int a, int b) {
32
33 i_color rcolor;
34 i_img_dim x,y;
35 int i;
36
37
38 /* fprintf(stderr,"parameters: (im 0x%x,a %d,b %d)\n",im,a,b);*/
39
40 for(y=0;y<im->ysize;y++) for(x=0;x<im->xsize;x++) {
41 i_gpix(im,x,y,&rcolor);
42 for(i=0;i<im->channels;i++) rcolor.channel[i]=saturate((255*(rcolor.channel[i]-a))/(b-a));
43 i_ppix(im,x,y,&rcolor);
44 }
45
46 }
47
48