From: Jann Horn Date: Tue, 5 Nov 2013 21:50:40 +0000 (+0100) Subject: initial commit X-Git-Url: http://git.thejh.net/?p=detafelator.git;a=commitdiff_plain;h=5021ac04daddff52b9a4629e261bb891e03536d1 initial commit --- 5021ac04daddff52b9a4629e261bb891e03536d1 diff --git a/detafelator.c b/detafelator.c new file mode 100644 index 0000000..ebc68b5 --- /dev/null +++ b/detafelator.c @@ -0,0 +1,56 @@ +#include +#include +#include + +int avg(int a, int b) { return (a+b)/2; } + +int nuldif(int n) { return abs(128-n); } + +int blimround(int a) { return (a<0)?0:((a>255)?255:a); } + +unsigned char *pxptr(pnm_image *img, int x, int y) { + return img->data + 3*(x + y*img->width); +} + +#define TRESH 4 + +int main(int argc, char **argv) { + pnm_image *iimg = CHK_PTR(read_image("/dev/stdin"), "can't read image from stdin", 1); + + int rowsize = 3*iimg->width; + + for (int y=0; yheight-1; y++) { + unsigned char *irow = iimg->data + rowsize*y; + //unsigned char *orow = oimg->data + rowsize*y; + for (int x=0; xwidth-1; x++) { + unsigned char *ipx = irow + 3*x; + for (int i=0; i<3; i++) { + unsigned char *ipxc = ipx+i; + int xdiff = ipxc[3]-ipxc[0]; + int ydiff = ipxc[rowsize]-ipxc[0]; + ipxc[0] = blimround(128+xdiff/*+ydiff*/); + } + } + } + + pnm_image *oimg = CHK_PTR(dup_image(iimg), "can't dup image", 1); + + for (int x=5; xwidth; x++) { + for (int y=/*1*/0; yheight; y++) { + bool notresh = true; + if (nuldif(*pxptr(iimg,x,y))>TRESH) notresh=false; + for (int x_=x-5; x_TRESH) notresh=false; + //for (int y_=y-10; y_TRESH) notresh=false; + if (notresh) { + pxptr(oimg,x,y)[0]=255; + } else { + pxptr(oimg,x,y)[0]=blimround( + /*avg(*/pxptr(oimg,x-1,y)[0]/*,pxptr(oimg,x,y-1)[0])*/ - (pxptr(iimg, x, y)[0]-128) + ); + } + } + } + + if (write_image(oimg, "/dev/stdout")) xperror("unable to write image to stdout", 1); + return 0; +} \ No newline at end of file