var image = Document.RasterImage;
var w = image.sizeX;
var h = image.sizeY;
var c,r,g,b,a,x,y;
for (x=0; x<w; x++){
for (y=0; y<h; y++){
c = image.GetPixel(x,y,0,0);
b = c & 255;
g = c >> 8 & 255;
r = c >> 16 & 255;
a = c >> 24 & 255;
if (r > 127) r = 255 - r;
if (g > 127) g = 255 - g;
if (b > 127) b = 255 - b;
c=(a << 24) |
(r << 16) |
(g << 8) |
b;
image.SetPixel(x, y, 0, 0, c);
}
}