… and a program that calculates mean R, G, B, A values is on
/n/sources/contrib/pac/sys/src/cmd/img/rgb.tbz
Redefine the function doSomethingWithPixel() according to your needs, and enjoy!
++pac.