Old 04-04-2021, 09:41 PM   #1
oughts
Human being with feelings
 
Join Date: Apr 2021
Posts: 2
Default Colour warmth and tint adjustment

The existing "shadow/midtone/highlight RGB adjust" effect is really powerful, but directly altering the RGB values is not very intuitive or convenient (for me anyway).

I've modified it so instead we adjust the warmth and tint (and brightness), and I added a master control so we can do so for the entire image at once and/or adjust the shadow, midtones, and highlights separately. I also limited the range of the controls since extreme values are not very useful.

"Warmth" is not exactly the colour temperature, it's more like the blue/yellow axis, while "tint" is the green/magenta axis. Sort of. These are the simple formulae I came up with:
R = 1.5 * warmth + tint; G = 0.5 * warmth - tint; B = 0 - warmth

I'm sure this could be improved, but I'm already finding it very useful. This is my first time hacking at code in Reaper so excuse the mess.

Code:
// Warmth (blue/yellow) and tint (green/magneta) adjust
// Based on "shadow/midtone/highlight RGB adjust"

//@param 1:master_brightness 'master brightness' 0 -200 200 0 1
//@param 2:master_warmth 'master warmth' 0 -100 100 0 1
//@param 3:master_tint 'master tint' 0 -100 100 0 1
//@param 4:shadow_brightness 'shadow brightness' 0 -200 200 0 1
//@param 5:shadow_warmth 'shadow warmth' 0 -100 100 0 1
//@param 6:shadow_tint 'shadow tint' 0 -100 100 0 1
//@param 7:midtone_brightness 'midtone brightness' 0 -200 200 0 1
//@param 8:midtone_warmth 'midtone warmth' 0 -100 100 0 1
//@param 9:midtone_tint 'midtone tint' 0 -100 100 0 1
//@param 10:highlight_brightness 'highlight brightness' 0 -200 200 0 1
//@param 11:highlight_warmth 'highlight warmth' 0 -100 100 0 1
//@param 12:highlight_tint 'highlight tint' 0 -100 100 0 1
//@param 13:shadow_curve 'shadow steepness' 1 0 8 1 .05
//@param 14:midtone_curve 'midtone steepness' 1 .25 4 1 .05
//@param 15:highlight_curve 'highlight steepness' 1 0 8 1 .05
//@param 16:showc 'show curves' 0 0 1 0.5 1
//@param 17:fade 'fade' 1

function scurve(i) local(t) (
  t = (cos(i*$pi)*.5+.5)^shadow_curve;
  shadow_curve < 1 ? shadow_curve*t + (1-i)*(1-shadow_curve): t;
);
function hcurve(i) (
  t = (cos((1-i)*$pi)*.5+.5)^highlight_curve;
  highlight_curve < 1 ? highlight_curve*t + i*(1-highlight_curve): t;
);
function mcurve(i) ( sin(i*$pi)^midtone_curve );

function mk(i, chan*) (
  scurve(i)*chan.shadow +
  mcurve(i)*chan.midtone +
  hcurve(i)*chan.highlight;
);

function mix(channel, warmth, tint, brightness) (
  channel == 'r' ? 1.5*warmth+tint+brightness :
    channel == 'g' ? 0.5*warmth-tint+brightness : 
      channel == 'b' ? 0-warmth+brightness;
);

fade > 0 || showc ? (
  r.shadow = mix('r',shadow_warmth, shadow_tint, shadow_brightness);
  r.midtone = mix('r',midtone_warmth, midtone_tint, midtone_brightness);
  r.highlight = mix('r',highlight_warmth, highlight_tint, highlight_brightness);
  g.shadow = mix('g',shadow_warmth, shadow_tint, shadow_brightness);
  g.midtone = mix('g',midtone_warmth, midtone_tint, midtone_brightness);
  g.highlight = mix('g',highlight_warmth, highlight_tint, highlight_brightness);
  b.shadow = mix('b',shadow_warmth, shadow_tint, shadow_brightness);
  b.midtone = mix('b',midtone_warmth, midtone_tint, midtone_brightness);
  b.highlight = mix('b',highlight_warmth, highlight_tint, highlight_brightness);
  input_info(0,project_w,project_h);
  fade>0 ? colorspace='RGBA';
  gfx_blit(0);
  fade > 0 ? (
    i = v = 0;
    loop(256,
      i[0] = (mk(v,r)+mix('r',master_warmth, master_tint, master_brightness))*fade;
      i[1] = (mk(v,g)+mix('g',master_warmth, master_tint, master_brightness))*fade;
      i[2] = (mk(v,b)+mix('b',master_warmth, master_tint, master_brightness))*fade;
      v+=1/256; i+=3;
    );
    gfx_evalrect(0,0,project_w,project_h,"
      _1 = floor(0.299*r + 0.587*g + 0.114*b+0.5)*3;
      r = min(max(r+_1[0],0),255);
      g = min(max(g+_1[1],0),255);
      b = min(max(b+_1[2],0),255);
    ");
  );
  showc ? (
    x = 32; y = 32;
    ysz = 200;
    gfx_set(0,0,0,0.85);
    gfx_fillrect(x,y,512,ysz);
    gfx_set(.75,.75,.75,.4);
    i=0; loop(256, v=ysz*scurve(i/256); gfx_fillrect(x+i*2,y+ysz-v,2,v); i+=1; );
    i=0; loop(256, v=ysz*mcurve(i/256); gfx_fillrect(x+i*2,y+ysz-v,2,v); i+=1; );
    i=0; loop(256, v=ysz*hcurve(i/256); gfx_fillrect(x+i*2,y+ysz-v,2,v); i+=1; );
  );
);

Last edited by oughts; 04-05-2021 at 01:22 AM.
oughts is offline   Reply With Quote
Old 05-15-2021, 02:30 AM   #2
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 1,362
Default

This is indeed very useful. I wonder why no one has posted a reply or a thank you. Very nice work. And many thanks.
__________________
☆.。.:*・°☆.。.:*・°☆.。.:*・°☆REAPER//✿◔‿◔)°☆.。.:*・°☆.。.:*・°☆
Eliseat is offline   Reply With Quote
Old 06-08-2021, 04:55 AM   #3
Sumalc
Human being with feelings
 
Join Date: Oct 2009
Location: France
Posts: 743
Default

Thank you very much, this has just been very useful for me to standardize the colours on three slightly different sequences.
Sumalc is offline   Reply With Quote
Old 06-08-2021, 05:48 PM   #4
Spirit
Human being with feelings
 
Join Date: Jul 2008
Location: MotherDiskLand
Posts: 160
Default

Thanks Oughts, this is exactly what I was looking for ! Really nice control range gradation. The only other thing I could ask for would be for a contrast control as well
Spirit is offline   Reply With Quote
Old 06-11-2021, 08:39 AM   #5
Sumalc
Human being with feelings
 
Join Date: Oct 2009
Location: France
Posts: 743
Default render duration

Just a note, with this script, the render function becomes very slow even with only 2 parameters changed.
The playback is jerky when playing in the arrange window, even with a mac M1
A render of a 30 sec item is done (full-speed offline) in 1:24 (0,4 x realtime).
But it works
Sumalc is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.