: intensity cog >r 4 ndrop r> ; # average intensity # contrast: (1-x) image + (x) average : agc >r dup intensity r> swap / * ; : contrast >r unpack r> over intensity over + >r -1.0 * over swap * + r> + 3 image:join ; # unpack image into 3 equal size single plane images : plane:unpack-3 unpack type # get type symbol for first plane swap over convert >r swap over convert >r convert r> r> ; # YUV conversion: this needs checking # probably a lot more convenient to build libtile programs for these # Y = 0.299R + 0.587G + 0.114B # U'= (B-Y)*0.565 # V'= (R-Y)*0.713 0.299 constant coef-r 0.587 constant coef-g 0.114 constant coef-b 0.565 constant coef-u 0.713 constant coef-v # color space conversion: input needs to have a list of 3 channels # FIXME: this no work : plane:rgb->Y coef-b * swap coef-g *+ swap coef-r *+ ; : plane:rgb->P411 3 pack dup unpack plane:rgb->Y >r # get luma unpack swap drop # ( b r ) r - .565 * swap r - .713 * swap # ( Cb Cr ) r> ; # ( Cb Cr Y ) : rgb->P411 plane:unpack-3 plane:rgb->P411 >r image:halve swap image:halve swap r> 3 image:join ;