File: linstretch.c

package info (click to toggle)
libimager-perl 1.027%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,820 kB
  • sloc: perl: 32,971; ansic: 28,092; makefile: 52; cpp: 4
file content (46 lines) | stat: -rw-r--r-- 978 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "imext.h"

char evalstr[]="Description string of plugin dyntest - kind of like";

void null_plug(void *ptr) { }

/* Example dynamic filter - level stretch (linear) - note it only stretches and doesn't compress */

/* input parameters
   a: the current black
   b: the current white
   
   0 <= a < b <= 255;

   output pixel value calculated by: o=((i-a)*255)/(b-a);

   note that since we do not have the needed functions to manipulate the data structures *** YET ***
*/


static
unsigned char
saturate(int in) {
  if (in>255) { return 255; }
  else if (in>0) return in;
  return 0;
}

void lin_stretch(i_img *im, int a, int b) {

  i_color rcolor;
  i_img_dim x,y;
  int i;

  
  /*   fprintf(stderr,"parameters: (im 0x%x,a %d,b %d)\n",im,a,b);*/
 
  for(y=0;y<im->ysize;y++) for(x=0;x<im->xsize;x++) {
    i_gpix(im,x,y,&rcolor);
    for(i=0;i<im->channels;i++) rcolor.channel[i]=saturate((255*(rcolor.channel[i]-a))/(b-a));    
    i_ppix(im,x,y,&rcolor);
  }

}