Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 74 lines (52 sloc) 1.827 kb
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#include "pluginst.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 ***
*/


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

void lin_stretch(void *INP) {

  int a, b;
  i_img *im;
  i_color rcolor;
  int i,bytes,x,y;
  int info[4];

  if ( !getOBJ("image","Imager::ImgRaw",&im) ) { fprintf(stderr,"Error: image is missing\n"); }
  if ( !getINT("a",&a) ) { fprintf(stderr,"Error: a is missing\n"); }
  if ( !getINT("b",&b) ) { fprintf(stderr,"Error: b is missing\n"); }
  
  /* fprintf(stderr,"parameters: (im 0x%x,a %d,b %d)\n",im,a,b);*/
  bytes=im->bytes;

  i_img_info(im,info);
  for(i=0;i<4;i++) { printf("%d: %d\n",i,info[i]); }
  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);

  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);
  }

}

func_ptr function_list[]={
  {
    "null_plug",
    null_plug,
    "callsub => sub { 1; }"
  },{
    "lin_stretch",
    lin_stretch,
    "callseq => ['image','a','b'], \
callsub => sub { my %hsh=@_; DSO_call($DSO_handle,1,\\%hsh); } \
"
  },
  {NULL,NULL,NULL}};


/* Remember to double backslash backslashes within Double quotes in C */

Something went wrong with that request. Please try again.