12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849(* Claude Code
*
* Copyright (C) 2026 Yoann Padioleau
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License
* (LGPL) as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*)(* See Blend.mli *)typemode=Normal|Multiply|Screen|Overlay|Hard_light|Darken|Lighten|Difference|Colorletmodes=[Normal;Multiply;Screen;Overlay;Hard_light;Darken;Lighten;Difference;Color]letname=function|Normal->"Normal"|Multiply->"Multiply"|Screen->"Screen"|Overlay->"Overlay"|Hard_light->"Hard Light"|Darken->"Darken"|Lighten->"Lighten"|Difference->"Difference"|Color->"Color"letscreenbs=1.-.((1.-.b)*.(1.-.s))lethard_lightbs=ifs<=0.5thenb*.2.*.selsescreenb((2.*.s)-.1.)letchannel(mode:mode)(b:float)(s:float):float=matchmodewith|Normal|Color->s|Multiply->b*.s|Screen->screenbs|Overlay->hard_lightsb|Hard_light->hard_lightbs|Darken->Float.minbs|Lighten->Float.maxbs|Difference->Float.abs(b-.s)letblend(mode:mode)((br,bg,bb):float*float*float)((sr,sg,sb):float*float*float):float*float*float=matchmodewith|Color->letbytev=int_of_float(Float.round(v*.255.))inleth,s,_=Hsl.of_rgb(bytesr)(bytesg)(bytesb)and_,_,l=Hsl.of_rgb(bytebr)(bytebg)(bytebb)inletr,g,b=Hsl.to_rgbhslin(float_of_intr/.255.,float_of_intg/.255.,float_of_intb/.255.)|_->(channelmodebrsr,channelmodebgsg,channelmodebbsb)