// Copyright 2005 Matt Sandstršm/Too Much Too Soon // This script is freeware, meaning you may copy and // distribute it free of charge, as long as it's kept intact, // including this message. Feel free to use the code as // inspiration for your own scripts, but don't steal. // Email me at mattias@beauty.se if you have any questions. // Thank you. Have fun. filter "Color Balance"; group "TMTS Color"; input rbalance, "C...R", slider, 0, -100, 100 detent 0; input gbalance, "M...G", slider, 0, -100, 100 detent 0; input bbalance, "Y...B", slider, 0, -100, 100 detent 0; code float w, h, i, rlut[256], glut[256], blut[256], rr, gg, bb, offset0[3], offset128[3]; dimensionsof(dest, w, h); image buf[w][h]; offset128[1] = 128; offset128[2] = 128; rr = rbalance/2 gg = -rbalance/4 bb = -rbalance/4 rr -= gbalance/4 gg += gbalance/2 bb -= gbalance/4 rr -= bbalance/4 gg -= bbalance/4 bb += bbalance/2 for i = 0 to 255 rlut[i] = i+rr; glut[i] = i+gg; blut[i] = i+bb; if rlut[i] < 0 rlut[i] = 0; else if rlut[i] > 255 rlut[i] = 255; end if; if glut[i] < 0 glut[i] = 0; else if glut[i] > 255 glut[i] = 255; end if; if blut[i] < 0 blut[i] = 0; else if blut[i] > 255 blut[i] = 255; end if; next; rlut /= 255; glut /= 255; blut /= 255; levelmap(src1, dest, linearRamp, rlut, glut, blut); colorTransform(dest, dest, RGBtoYUV, offset0, offset128); colorTransform(Src1, buf, RGBtoYUV, offset0, offset128); channelcopy(buf, dest, knone, kred, knone, knone); colorTransform(Dest, Dest, YUVtoRGB, offset128, offset0);