// 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 3-way"; group "TMTS Color"; input d0, "Shadows", label, "Shadows" input rbalance0, "C...R", slider, 0, -100, 100 detent 0; input gbalance0, "M...G", slider, 0, -100, 100 detent 0; input bbalance0, "Y...B", slider, 0, -100, 100 detent 0; input d1, "Midtones", label, "Midtones" input rbalance1, "C...R", slider, 0, -100, 100 detent 0; input gbalance1, "M...G", slider, 0, -100, 100 detent 0; input bbalance1, "Y...B", slider, 0, -100, 100 detent 0; input d2, "Highlights", label, "Highlights" input rbalance2, "C...R", slider, 0, -100, 100 detent 0; input gbalance2, "M...G", slider, 0, -100, 100 detent 0; input bbalance2, "Y...B", slider, 0, -100, 100 detent 0; code float w, h, i, rlut[256], glut[256], blut[256], rr0, gg0, bb0, rr1, gg1, bb1, rr2, gg2, bb2, offset0[3], offset128[3]; dimensionsof(dest, w, h); image buf[w][h]; offset128[1] = 128; offset128[2] = 128; rr0 = rbalance0/2 gg0 = -rbalance0/4 bb0 = -rbalance0/4 rr0 -= gbalance0/4 gg0 += gbalance0/2 bb0 -= gbalance0/4 rr0 -= bbalance0/4 gg0 -= bbalance0/4 bb0 += bbalance0/2 rr1 = rbalance1/2 gg1 = -rbalance1/4 bb1 = -rbalance1/4 rr1 -= gbalance1/4 gg1 += gbalance1/2 bb1 -= gbalance1/4 rr1 -= bbalance1/4 gg1 -= bbalance1/4 bb1 += bbalance1/2 rr2 = rbalance2/2 gg2 = -rbalance2/4 bb2 = -rbalance2/4 rr2 -= gbalance2/4 gg2 += gbalance2/2 bb2 -= gbalance2/4 rr2 -= bbalance2/4 gg2 -= bbalance2/4 bb2 += bbalance2/2 for i = 0 to 127 rlut[i] = i+(127-i)*rr0/127+i*rr1/127; glut[i] = i+(127-i)*gg0/127+i*gg1/127; blut[i] = i+(127-i)*bb0/127+i*bb1/127; 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; for i = 128 to 255 rlut[i] = i+(255-i)*rr1/127+(i-128)*rr2/127; glut[i] = i+(255-i)*gg1/127+(i-128)*gg2/127; blut[i] = i+(255-i)*bb1/127+(i-128)*bb2/127; 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);