--- /dev/null
+#include <jh.h>
+#include <assert.h>
+#include <stdbool.h>
+
+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; y<iimg->height-1; y++) {
+ unsigned char *irow = iimg->data + rowsize*y;
+ //unsigned char *orow = oimg->data + rowsize*y;
+ for (int x=0; x<iimg->width-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; x<iimg->width; x++) {
+ for (int y=/*1*/0; y<iimg->height; y++) {
+ bool notresh = true;
+ if (nuldif(*pxptr(iimg,x,y))>TRESH) notresh=false;
+ for (int x_=x-5; x_<x; x_++) if (nuldif(*pxptr(iimg,x_,y))>TRESH) notresh=false;
+ //for (int y_=y-10; y_<y; y_++) if (nuldif(*pxptr(iimg,x,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