*/}}
Bladeren bron

sRGB tag for color widgets

Yiming Wu 1 jaar geleden
bovenliggende
commit
df8e0dc228
8 gewijzigde bestanden met toevoegingen van 120 en 390 verwijderingen
  1. 0 30
      la_data.c
  2. 1 0
      la_data.h
  3. 1 0
      la_interface.h
  4. 6 5
      la_tns.h
  5. 30 44
      la_tns_kernel.c
  6. 53 295
      resources/la_tns_shaders.cpp
  7. 19 13
      resources/la_widgets.c
  8. 10 3
      resources/la_widgets_viewers.c

+ 0 - 30
la_data.c

@@ -1319,11 +1319,6 @@ int laGetIntArray(laPropPack *pp, int *result){
 }
 int laSetFloatArraySingle(laPropPack *pp, int index, real n){
     laFloatProp *p = pp->LastPs->p;
-    //if (pp->LastPs->p->Tag&LA_COLOR_DATA) {
-    //	if (MAIN.ColorAccessCorrectGamma && index!=3) {
-    //		tnsSingleLogToLinear(&n, MAIN.Gamma);
-    //	}
-    //}
     if (p->Max != p->Min){
         n = n > p->Max ? p->Max : (n < p->Min ? p->Min : n);
     }
@@ -1357,11 +1352,6 @@ int laSetFloatArraySingle(laPropPack *pp, int index, real n){
 }
 int laSetFloatArrayAll(laPropPack *pp, real n){
     laFloatProp *p = pp->LastPs->p;
-    //if (pp->LastPs->p->Tag&LA_COLOR_DATA) {
-    //	if (MAIN.ColorAccessCorrectGamma) {
-    //		tnsSingleLogToLinear(&n, MAIN.Gamma);
-    //	}
-    //}
     if (p->Max != p->Min){
         n = n > p->Max ? p->Max : (n < p->Min ? p->Min : n);
     }
@@ -1392,11 +1382,6 @@ int laSetFloatArrayAll(laPropPack *pp, real n){
     return 0;
 }
 int laReadFloatArrayAllArray(laPropPack *pp, real *arr){
-    //if (pp->LastPs->p->Tag&LA_COLOR_DATA) {
-    //	if (MAIN.ColorAccessCorrectGamma) {
-    //		tnsLogToLinear(arr, MAIN.Gamma);
-    //	}
-    //}
     if (((laFloatProp *)pp->LastPs->p)->Base.DetachedPP.LastPs){
         int i = 0, len = laGetArrayLength(pp);
         for (i; i < len; i++){
@@ -1423,11 +1408,6 @@ int laReadFloatArrayAllArray(laPropPack *pp, real *arr){
     return 0;
 }
 int laSetFloatArrayAllArray(laPropPack *pp, real *arr){
-    //if (pp->LastPs->p->Tag&LA_COLOR_DATA) {
-    //	if (MAIN.ColorAccessCorrectGamma) {
-    //		tnsLogToLinear(arr, MAIN.Gamma);
-    //	}
-    //}
     if (((laFloatProp *)pp->LastPs->p)->Base.DetachedPP.LastPs){
         int i = 0, len = laGetArrayLength(pp);
         for (i; i < len; i++){
@@ -1471,18 +1451,8 @@ int laGetFloatArray(laPropPack *pp, real *result){
                 memcpy(result, src, len * sizeof(real));
             }else{ *result=0; }
             return 1;
-            //if (pp->LastPs->p->Tag&LA_COLOR_DATA) {
-            //	if (MAIN.ColorAccessCorrectGamma) {
-            //		tnsLinearToLog(result,MAIN.Gamma);
-            //	}
-            //}
         }else{
             ((laFloatProp *)pp->LastPs->p)->GetAll(pp->LastPs->UseInstance, result);
-            //if (pp->LastPs->p->Tag&LA_COLOR_DATA) {
-            //	if (MAIN.ColorAccessCorrectGamma) {
-            //		tnsLinearToLog(result, MAIN.Gamma);
-            //	}
-            //}
             return 1;
         }
     }

+ 1 - 0
la_data.h

@@ -90,6 +90,7 @@ typedef void (*laContainerpUDFPropagateF)(void *, void* udf, int Force);
 #define LA_PROP_IS_FOLDER (1<<22)
 #define LA_PROP_IS_FILE   (1<<23)
 #define LA_PROP_RAW       (1<<24)
+#define LA_PROP_IS_LINEAR_SRGB (1<<24)
 
 #define LA_PROP_OTHER_ALLOC (1<<3)
 #define LA_PROP_HYPER_BITS (1|2)

+ 1 - 0
la_interface.h

@@ -778,6 +778,7 @@ STRUCTURE(laCanvasTemplate){
 #define LA_CANVAS_SELECT_THROUGH_OFF 0
 #define LA_CANVAS_SELECT_THROUGH_ON  1
 
+void la_CanvasDefaultOverlay(laUiItem* ui, int h);
 void la_CanvasDrawOverlay(laUiItem *ui, int h);
 void la_CanvasInit(laUiItem *ui);
 void la_CanvasDestroy(laUiItem *ui);

+ 6 - 5
la_tns.h

@@ -1326,11 +1326,12 @@ void tnsMakeBridgedIndex(unsigned int *result, int num, int revert, int begin);
 void DrawWireRect2dp(real x, real y, real x2, real y2);
 void tnsViewportWithScissor(int x, int y, int w, int h);
 
-void tnsSingleLinearToLog(real *a, real gamma);
-void tnsSingleLogToLinear(real *a, real gamma);
-void tnsLinearToLog(real *rgb, real gamma);
-void tnsLogToLinear(real *rgb, real gamma);
-void tnsRgbToLuminance(real *rgb);
+void tns2LogsRGBSingle(real* a);
+void tns2LinearsRGBSingle(real* a);
+void tns2LogsRGB(real* srgb);
+void tns2LinearsRGB(real* srgb);
+void tnsRGB2OKLAB(real* rgb, real* oklab);
+void tnsOKLAB2RGB(real* oklab, real* rgb);
 void tnsHCY2RGB(real *hcy, real *rgb);
 void tnsRGB2HCY(real *rgb, real *hcy);
 

+ 30 - 44
la_tns_kernel.c

@@ -153,7 +153,8 @@ void main(){\n\
         vec3 oNormal=fNormal; if(view<0){ oNormal=-fNormal; }\n\
         outNormal = oNormal;\n\
     }\n\
-    if(ColorMode!=0){ color.rgb=okhsl_to_srgb(color.rgb); }\n\
+    if(ColorMode==1){ color.rgb=okhsl_to_srgb(color.rgb); }\n\
+    else if(ColorMode==2){ color.rgb=to_log_srgb(color.rgb); }\n\
     outColor = color;\n\
     outGPos = fGPos;\n\
 }";
@@ -479,6 +480,7 @@ void tnsShaderMakeIndex(tnsShader *tns){
     tns->iTexColorMS = glGetUniformLocation(program, "TexColorMS");
     tns->iMultiplyColor = glGetUniformLocation(program, "MultiplyColor");
     tns->iTextureMode = glGetUniformLocation(program, "TextureMode");
+    tns->iColorMode = glGetUniformLocation(program, "ColorMode");
     tns->iSampleAmount = glGetUniformLocation(program, "SampleAmount");
     tns->iUseNormal = glGetUniformLocation(program, "UseNormal");
     if(tns->iTexColor>=0){glUniform1i(tns->iTexColor, 0);}
@@ -3810,45 +3812,29 @@ tnsMaterial *tnsFindMaterial(char *name){
 
 extern LA MAIN;
 
-void tnsSingleLinearToLog(real *a, real gamma){
-    if (*a < 0) *a = 0;
-    *a = powf(*a, gamma);
-}
-void tnsSingleLogToLinear(real *a, real gamma){
-    if (*a < 0) *a = 0;
-    *a = powf(*a, 1.0f / gamma);
-}
-void tnsLinearToLog(real *rgb, real gamma){
-    if (rgb[0] < 0) rgb[0] = 0;
-    if (rgb[1] < 0) rgb[1] = 0;
-    if (rgb[2] < 0) rgb[2] = 0;
-    rgb[0] = pow(rgb[0], gamma);
-    rgb[1] = pow(rgb[1], gamma);
-    rgb[2] = pow(rgb[2], gamma);
-}
-void tnsLogToLinear(real *rgb, real gamma){
-    if (rgb[0] < 0) rgb[0] = 0;
-    if (rgb[1] < 0) rgb[1] = 0;
-    if (rgb[2] < 0) rgb[2] = 0;
-    rgb[0] = pow(rgb[0], 1.0f / gamma);
-    rgb[1] = pow(rgb[1], 1.0f / gamma);
-    rgb[2] = pow(rgb[2], 1.0f / gamma);
-}
-void tnsRgbToLuminance(real *rgb){
-    real l;
-    if (rgb[0] < 0) rgb[0] = 0;
-    if (rgb[1] < 0) rgb[1] = 0;
-    if (rgb[2] < 0) rgb[2] = 0;
-    l = rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114;
-    rgb[0] = rgb[1] = rgb[2] = l;
-}
-
-real _srgb_transfer_function(real a){
+
+static real _srgb_transfer_function(real a){
 	return .0031308f >= a ? 12.92f * a : 1.055f * powf(a, .4166666666666667f) - .055f;
 }
-real _srgb_transfer_function_inv(real a){
+static real _srgb_transfer_function_inv(real a){
 	return .04045f < a ? powf((a + .055f) / 1.055f, 2.4f) : a / 12.92f;
 }
+void tns2LogsRGBSingle(real* a){
+    *a=_srgb_transfer_function(*a);
+}
+void tns2LinearsRGBSingle(real* a){
+    *a=_srgb_transfer_function_inv(*a);
+}
+void tns2LogsRGB(real* srgb){
+    srgb[0]=_srgb_transfer_function(srgb[0]);
+    srgb[1]=_srgb_transfer_function(srgb[1]);
+    srgb[2]=_srgb_transfer_function(srgb[2]);
+}
+void tns2LinearsRGB(real* srgb){
+    srgb[0]=_srgb_transfer_function_inv(srgb[0]);
+    srgb[1]=_srgb_transfer_function_inv(srgb[1]);
+    srgb[2]=_srgb_transfer_function_inv(srgb[2]);
+}
 void tnsRGB2OKLAB(real* rgb, real* oklab){
     real l = 0.4122214708f * rgb[0] + 0.5363325363f * rgb[1] + 0.0514459929f * rgb[2];
 	real m = 0.2119034982f * rgb[0] + 0.6806995451f * rgb[1] + 0.1073969566f * rgb[2];
@@ -3871,7 +3857,7 @@ void tnsOKLAB2RGB(real* oklab, real* rgb){
     rgb[1]=-1.2684380046f * l + 2.6097574011f * m - 0.3413193965f * s;
     rgb[2]=-0.0041960863f * l - 0.7034186147f * m + 1.7076147010f * s;
 }
-real _compute_max_saturation(real a, real b){
+static real _compute_max_saturation(real a, real b){
 	real k0, k1, k2, k3, k4, wl, wm, ws;
 	if (-1.88170328f * a - 0.80936493f * b > 1){
 		k0 = +1.19086277f; k1 = +1.76576728f; k2 = +0.59662641f; k3 = +0.75515197f; k4 = +0.56771245f;
@@ -3915,7 +3901,7 @@ real _compute_max_saturation(real a, real b){
 
 	return S;
 }
-void _find_cusp(real a, real b, real *l, real *c)
+static void _find_cusp(real a, real b, real *l, real *c)
 {
 	real S_cusp = _compute_max_saturation(a, b);
     real oklab[3]={1, S_cusp * a, S_cusp * b}; real rgb_at_max[3];
@@ -3924,7 +3910,7 @@ void _find_cusp(real a, real b, real *l, real *c)
 	real C_cusp = L_cusp * S_cusp;
 	*l=L_cusp; *c=C_cusp;
 }
-real _find_gamut_intersection(real a, real b, real L1, real C1, real L0, real cusp_L, real cusp_C)
+static real _find_gamut_intersection(real a, real b, real L1, real C1, real L0, real cusp_L, real cusp_C)
 {
 	real t;
 	if (((L1 - L0) * cusp_C - (cusp_L - L0) * C1) <= 0.f) {
@@ -3993,19 +3979,19 @@ real _find_gamut_intersection(real a, real b, real L1, real C1, real L0, real cu
 
 	return t;
 }
-real _toe(real x) {
+static real _toe(real x) {
 	const real k_1 = 0.206f; const real k_2 = 0.03f; const real k_3 = (1.f + k_1) / (1.f + k_2);
 	return 0.5f * (k_3 * x - k_1 + sqrt((k_3 * x - k_1) * (k_3 * x - k_1) + 4 * k_2 * k_3 * x));
 }
-real _toe_inv(real x) {
+static real _toe_inv(real x) {
 	const real k_1 = 0.206f; const real k_2 = 0.03f; const real k_3 = (1.f + k_1) / (1.f + k_2);
 	return (x * x + k_1 * x) / (k_3 * (x + k_2));
 }
-void _to_ST(real cusp_L, real cusp_C, real* _s, real* _t) {
+static void _to_ST(real cusp_L, real cusp_C, real* _s, real* _t) {
 	real L = cusp_L; real C = cusp_C;
 	*_s=C / L; *_t=C / (1 - L);
 }
-void _get_ST_mid(real a_, real b_, real *s,real *t){
+static void _get_ST_mid(real a_, real b_, real *s,real *t){
 	*s = 0.11516993f + 1.f / (
 		+7.44778970f + 4.15901240f * b_
 		+ a_ * (-2.19557347f + 1.75198401f * b_
@@ -4021,7 +4007,7 @@ void _get_ST_mid(real a_, real b_, real *s,real *t){
 					)))
 		);
 }
-void _get_Cs(real L, real a_, real b_,real *rC_0, real *rC_mid, real *rC_max){
+static void _get_Cs(real L, real a_, real b_,real *rC_0, real *rC_mid, real *rC_max){
 	real cusp_L,cusp_C; _find_cusp(a_, b_,&cusp_L,&cusp_C);
 
 	real C_max = _find_gamut_intersection(a_, b_, L, 1, L,cusp_L,cusp_C);

+ 53 - 295
resources/la_tns_shaders.cpp

@@ -1,389 +1,236 @@
 #include "la_5.h"
-
 extern "C" const char* TNS_SHADER_COLOR_COMMON=R"(
-//okhsl by Björn Ottosson
-
 #define M_PI 3.1415926535897932384626433832795
-
-float cbrt( float x )
-{
+float cbrt( float x ){
     return sign(x)*pow(abs(x),1.0f/3.0f);
 }
-
-float srgb_transfer_function(float a)
-{
+float srgb_transfer_function(float a){
 	return .0031308f >= a ? 12.92f * a : 1.055f * pow(a, .4166666666666667f) - .055f;
 }
-
-float srgb_transfer_function_inv(float a)
-{
+float srgb_transfer_function_inv(float a){
 	return .04045f < a ? pow((a + .055f) / 1.055f, 2.4f) : a / 12.92f;
 }
-
-vec3 linear_srgb_to_oklab(vec3 c)
-{
+vec3 to_log_srgb(vec3 color){
+	return vec3(srgb_transfer_function(color.r),srgb_transfer_function(color.g),srgb_transfer_function(color.b));
+}
+vec3 to_linear_srgb(vec3 color){
+	return vec3(srgb_transfer_function_inv(color.r),srgb_transfer_function_inv(color.g),srgb_transfer_function_inv(color.b));
+}
+vec3 linear_srgb_to_oklab(vec3 c){
 	float l = 0.4122214708f * c.r + 0.5363325363f * c.g + 0.0514459929f * c.b;
 	float m = 0.2119034982f * c.r + 0.6806995451f * c.g + 0.1073969566f * c.b;
 	float s = 0.0883024619f * c.r + 0.2817188376f * c.g + 0.6299787005f * c.b;
-
 	float l_ = cbrt(l);
 	float m_ = cbrt(m);
 	float s_ = cbrt(s);
-
 	return vec3(
 		0.2104542553f * l_ + 0.7936177850f * m_ - 0.0040720468f * s_,
 		1.9779984951f * l_ - 2.4285922050f * m_ + 0.4505937099f * s_,
 		0.0259040371f * l_ + 0.7827717662f * m_ - 0.8086757660f * s_
 	);
 }
-
-vec3 oklab_to_linear_srgb(vec3 c)
-{
+vec3 oklab_to_linear_srgb(vec3 c){
 	float l_ = c.x + 0.3963377774f * c.y + 0.2158037573f * c.z;
 	float m_ = c.x - 0.1055613458f * c.y - 0.0638541728f * c.z;
 	float s_ = c.x - 0.0894841775f * c.y - 1.2914855480f * c.z;
-
 	float l = l_ * l_ * l_;
 	float m = m_ * m_ * m_;
 	float s = s_ * s_ * s_;
-
 	return vec3(
 		+4.0767416621f * l - 3.3077115913f * m + 0.2309699292f * s,
 		-1.2684380046f * l + 2.6097574011f * m - 0.3413193965f * s,
 		-0.0041960863f * l - 0.7034186147f * m + 1.7076147010f * s
 	);
 }
-
-// Finds the maximum saturation possible for a given hue that fits in sRGB
-// Saturation here is defined as S = C/L
-// a and b must be normalized so a^2 + b^2 == 1
-float compute_max_saturation(float a, float b)
-{
-	// Max saturation will be when one of r, g or b goes below zero.
-
-	// Select different coefficients depending on which component goes below zero first
-	float k0, k1, k2, k3, k4, wl, wm, ws;
-
-	if (-1.88170328f * a - 0.80936493f * b > 1.f)
-	{
-		// Red component
-		k0 = +1.19086277f; k1 = +1.76576728f; k2 = +0.59662641f; k3 = +0.75515197f; k4 = +0.56771245f;
+float compute_max_saturation(float a, float b){	float k0, k1, k2, k3, k4, wl, wm, ws;
+	if (-1.88170328f * a - 0.80936493f * b > 1.f){		k0 = +1.19086277f; k1 = +1.76576728f; k2 = +0.59662641f; k3 = +0.75515197f; k4 = +0.56771245f;
 		wl = +4.0767416621f; wm = -3.3077115913f; ws = +0.2309699292f;
 	}
-	else if (1.81444104f * a - 1.19445276f * b > 1.f)
-	{
-		// Green component
-		k0 = +0.73956515f; k1 = -0.45954404f; k2 = +0.08285427f; k3 = +0.12541070f; k4 = +0.14503204f;
+	else if (1.81444104f * a - 1.19445276f * b > 1.f){		k0 = +0.73956515f; k1 = -0.45954404f; k2 = +0.08285427f; k3 = +0.12541070f; k4 = +0.14503204f;
 		wl = -1.2684380046f; wm = +2.6097574011f; ws = -0.3413193965f;
 	}
-	else
-	{
-		// Blue component
-		k0 = +1.35733652f; k1 = -0.00915799f; k2 = -1.15130210f; k3 = -0.50559606f; k4 = +0.00692167f;
+	else{		k0 = +1.35733652f; k1 = -0.00915799f; k2 = -1.15130210f; k3 = -0.50559606f; k4 = +0.00692167f;
 		wl = -0.0041960863f; wm = -0.7034186147f; ws = +1.7076147010f;
-	}
-
-	// Approximate max saturation using a polynomial:
-	float S = k0 + k1 * a + k2 * b + k3 * a * a + k4 * a * b;
-
-	// Do one step Halley's method to get closer
-	// this gives an error less than 10e6, except for some blue hues where the dS/dh is close to infinite
-	// this should be sufficient for most applications, otherwise do two/three steps 
-
+	}	float S = k0 + k1 * a + k2 * b + k3 * a * a + k4 * a * b;
 	float k_l = +0.3963377774f * a + 0.2158037573f * b;
 	float k_m = -0.1055613458f * a - 0.0638541728f * b;
-	float k_s = -0.0894841775f * a - 1.2914855480f * b;
-
-	{
+	float k_s = -0.0894841775f * a - 1.2914855480f * b;{
 		float l_ = 1.f + S * k_l;
 		float m_ = 1.f + S * k_m;
 		float s_ = 1.f + S * k_s;
-
 		float l = l_ * l_ * l_;
 		float m = m_ * m_ * m_;
 		float s = s_ * s_ * s_;
-
 		float l_dS = 3.f * k_l * l_ * l_;
 		float m_dS = 3.f * k_m * m_ * m_;
 		float s_dS = 3.f * k_s * s_ * s_;
-
 		float l_dS2 = 6.f * k_l * k_l * l_;
 		float m_dS2 = 6.f * k_m * k_m * m_;
 		float s_dS2 = 6.f * k_s * k_s * s_;
-
 		float f = wl * l + wm * m + ws * s;
 		float f1 = wl * l_dS + wm * m_dS + ws * s_dS;
 		float f2 = wl * l_dS2 + wm * m_dS2 + ws * s_dS2;
-
 		S = S - f * f1 / (f1 * f1 - 0.5f * f * f2);
 	}
-
 	return S;
 }
-
-// finds L_cusp and C_cusp for a given hue
-// a and b must be normalized so a^2 + b^2 == 1
-vec2 find_cusp(float a, float b)
-{
-	// First, find the maximum saturation (saturation S = C/L)
-	float S_cusp = compute_max_saturation(a, b);
-
-	// Convert to linear sRGB to find the first point where at least one of r,g or b >= 1:
-	vec3 rgb_at_max = oklab_to_linear_srgb(vec3( 1, S_cusp * a, S_cusp * b ));
+vec2 find_cusp(float a, float b){	float S_cusp = compute_max_saturation(a, b);	vec3 rgb_at_max = oklab_to_linear_srgb(vec3( 1, S_cusp * a, S_cusp * b ));
 	float L_cusp = cbrt(1.f / max(max(rgb_at_max.r, rgb_at_max.g), rgb_at_max.b));
 	float C_cusp = L_cusp * S_cusp;
-
 	return vec2( L_cusp , C_cusp );
 }
-
-// Finds intersection of the line defined by 
-// L = L0 * (1 - t) + t * L1;
-// C = t * C1;
-// a and b must be normalized so a^2 + b^2 == 1
-float find_gamut_intersection(float a, float b, float L1, float C1, float L0, vec2 cusp)
-{
-	// Find the intersection for upper and lower half seprately
-	float t;
-	if (((L1 - L0) * cusp.y - (cusp.x - L0) * C1) <= 0.f)
-	{
-		// Lower half
-
+float find_gamut_intersection(float a, float b, float L1, float C1, float L0, vec2 cusp){	float t;
+	if (((L1 - L0) * cusp.y - (cusp.x - L0) * C1) <= 0.f){
 		t = cusp.y * L0 / (C1 * cusp.x + cusp.y * (L0 - L1));
 	}
-	else
-	{
-		// Upper half
-
-		// First intersect with triangle
-		t = cusp.y * (L0 - 1.f) / (C1 * (cusp.x - 1.f) + cusp.y * (L0 - L1));
-
-		// Then one step Halley's method
-		{
+	else{		t = cusp.y * (L0 - 1.f) / (C1 * (cusp.x - 1.f) + cusp.y * (L0 - L1));		{
 			float dL = L1 - L0;
 			float dC = C1;
-
 			float k_l = +0.3963377774f * a + 0.2158037573f * b;
 			float k_m = -0.1055613458f * a - 0.0638541728f * b;
 			float k_s = -0.0894841775f * a - 1.2914855480f * b;
-
 			float l_dt = dL + dC * k_l;
 			float m_dt = dL + dC * k_m;
-			float s_dt = dL + dC * k_s;
-
-
-			// If higher accuracy is required, 2 or 3 iterations of the following block can be used:
-			{
+			float s_dt = dL + dC * k_s;			{
 				float L = L0 * (1.f - t) + t * L1;
 				float C = t * C1;
-
 				float l_ = L + C * k_l;
 				float m_ = L + C * k_m;
 				float s_ = L + C * k_s;
-
 				float l = l_ * l_ * l_;
 				float m = m_ * m_ * m_;
 				float s = s_ * s_ * s_;
-
 				float ldt = 3.f * l_dt * l_ * l_;
 				float mdt = 3.f * m_dt * m_ * m_;
 				float sdt = 3.f * s_dt * s_ * s_;
-
 				float ldt2 = 6.f * l_dt * l_dt * l_;
 				float mdt2 = 6.f * m_dt * m_dt * m_;
 				float sdt2 = 6.f * s_dt * s_dt * s_;
-
 				float r = 4.0767416621f * l - 3.3077115913f * m + 0.2309699292f * s - 1.f;
 				float r1 = 4.0767416621f * ldt - 3.3077115913f * mdt + 0.2309699292f * sdt;
 				float r2 = 4.0767416621f * ldt2 - 3.3077115913f * mdt2 + 0.2309699292f * sdt2;
-
 				float u_r = r1 / (r1 * r1 - 0.5f * r * r2);
 				float t_r = -r * u_r;
-
 				float g = -1.2684380046f * l + 2.6097574011f * m - 0.3413193965f * s - 1.f;
 				float g1 = -1.2684380046f * ldt + 2.6097574011f * mdt - 0.3413193965f * sdt;
 				float g2 = -1.2684380046f * ldt2 + 2.6097574011f * mdt2 - 0.3413193965f * sdt2;
-
 				float u_g = g1 / (g1 * g1 - 0.5f * g * g2);
 				float t_g = -g * u_g;
-
 				float b = -0.0041960863f * l - 0.7034186147f * m + 1.7076147010f * s - 1.f;
 				float b1 = -0.0041960863f * ldt - 0.7034186147f * mdt + 1.7076147010f * sdt;
 				float b2 = -0.0041960863f * ldt2 - 0.7034186147f * mdt2 + 1.7076147010f * sdt2;
-
 				float u_b = b1 / (b1 * b1 - 0.5f * b * b2);
 				float t_b = -b * u_b;
-
 				t_r = u_r >= 0.f ? t_r : 10000.f;
 				t_g = u_g >= 0.f ? t_g : 10000.f;
 				t_b = u_b >= 0.f ? t_b : 10000.f;
-
 				t += min(t_r, min(t_g, t_b));
 			}
 		}
 	}
-
 	return t;
 }
-
-float find_gamut_intersection(float a, float b, float L1, float C1, float L0)
-{
-	// Find the cusp of the gamut triangle
-	vec2 cusp = find_cusp(a, b);
-
+float find_gamut_intersection(float a, float b, float L1, float C1, float L0){	vec2 cusp = find_cusp(a, b);
 	return find_gamut_intersection(a, b, L1, C1, L0, cusp);
 }
-
-vec3 gamut_clip_preserve_chroma(vec3 rgb)
-{
+vec3 gamut_clip_preserve_chroma(vec3 rgb){
 	if (rgb.r < 1.f && rgb.g < 1.f && rgb.b < 1.f && rgb.r > 0.f && rgb.g > 0.f && rgb.b > 0.f)
 		return rgb;
-
 	vec3 lab = linear_srgb_to_oklab(rgb);
-
 	float L = lab.x;
 	float eps = 0.00001f;
 	float C = max(eps, sqrt(lab.y * lab.y + lab.z * lab.z));
 	float a_ = lab.y / C;
 	float b_ = lab.z / C;
-
 	float L0 = clamp(L, 0.f, 1.f);
-
 	float t = find_gamut_intersection(a_, b_, L, C, L0);
 	float L_clipped = L0 * (1.f - t) + t * L;
 	float C_clipped = t * C;
-
 	return oklab_to_linear_srgb(vec3( L_clipped, C_clipped * a_, C_clipped * b_ ));
 }
-
-vec3 gamut_clip_project_to_0_5(vec3 rgb)
-{
+vec3 gamut_clip_project_to_0_5(vec3 rgb){
 	if (rgb.r < 1.f && rgb.g < 1.f && rgb.b < 1.f && rgb.r > 0.f && rgb.g > 0.f && rgb.b > 0.f)
 		return rgb;
-
 	vec3 lab = linear_srgb_to_oklab(rgb);
-
 	float L = lab.x;
 	float eps = 0.00001f;
 	float C = max(eps, sqrt(lab.y * lab.y + lab.z * lab.z));
 	float a_ = lab.y / C;
 	float b_ = lab.z / C;
-
 	float L0 = 0.5;
-
 	float t = find_gamut_intersection(a_, b_, L, C, L0);
 	float L_clipped = L0 * (1.f - t) + t * L;
 	float C_clipped = t * C;
-
 	return oklab_to_linear_srgb(vec3( L_clipped, C_clipped * a_, C_clipped * b_ ));
 }
-
-vec3 gamut_clip_project_to_L_cusp(vec3 rgb)
-{
+vec3 gamut_clip_project_to_L_cusp(vec3 rgb){
 	if (rgb.r < 1.f && rgb.g < 1.f && rgb.b < 1.f && rgb.r > 0.f && rgb.g > 0.f && rgb.b > 0.f)
 		return rgb;
-
 	vec3 lab = linear_srgb_to_oklab(rgb);
-
 	float L = lab.x;
 	float eps = 0.00001f;
 	float C = max(eps, sqrt(lab.y * lab.y + lab.z * lab.z));
 	float a_ = lab.y / C;
-	float b_ = lab.z / C;
-
-	// The cusp is computed here and in find_gamut_intersection, an optimized solution would only compute it once.
-	vec2 cusp = find_cusp(a_, b_);
-
+	float b_ = lab.z / C;	vec2 cusp = find_cusp(a_, b_);
 	float L0 = cusp.x;
-
 	float t = find_gamut_intersection(a_, b_, L, C, L0);
-
 	float L_clipped = L0 * (1.f - t) + t * L;
 	float C_clipped = t * C;
-
 	return oklab_to_linear_srgb(vec3( L_clipped, C_clipped * a_, C_clipped * b_ ));
 }
-
-vec3 gamut_clip_adaptive_L0_0_5(vec3 rgb, float alpha)
-{
+vec3 gamut_clip_adaptive_L0_0_5(vec3 rgb, float alpha){
 	if (rgb.r < 1.f && rgb.g < 1.f && rgb.b < 1.f && rgb.r > 0.f && rgb.g > 0.f && rgb.b > 0.f)
 		return rgb;
-
 	vec3 lab = linear_srgb_to_oklab(rgb);
-
 	float L = lab.x;
 	float eps = 0.00001f;
 	float C = max(eps, sqrt(lab.y * lab.y + lab.z * lab.z));
 	float a_ = lab.y / C;
 	float b_ = lab.z / C;
-
 	float Ld = L - 0.5f;
 	float e1 = 0.5f + abs(Ld) + alpha * C;
 	float L0 = 0.5f * (1.f + sign(Ld) * (e1 - sqrt(e1 * e1 - 2.f * abs(Ld))));
-
 	float t = find_gamut_intersection(a_, b_, L, C, L0);
 	float L_clipped = L0 * (1.f - t) + t * L;
 	float C_clipped = t * C;
-
 	return oklab_to_linear_srgb(vec3( L_clipped, C_clipped * a_, C_clipped * b_ ));
 }
-
-vec3 gamut_clip_adaptive_L0_L_cusp(vec3 rgb, float alpha)
-{
+vec3 gamut_clip_adaptive_L0_L_cusp(vec3 rgb, float alpha){
 	if (rgb.r < 1.f && rgb.g < 1.f && rgb.b < 1.f && rgb.r > 0.f && rgb.g > 0.f && rgb.b > 0.f)
 		return rgb;
-
 	vec3 lab = linear_srgb_to_oklab(rgb);
-
 	float L = lab.x;
 	float eps = 0.00001f;
 	float C = max(eps, sqrt(lab.y * lab.y + lab.z * lab.z));
 	float a_ = lab.y / C;
-	float b_ = lab.z / C;
-
-	// The cusp is computed here and in find_gamut_intersection, an optimized solution would only compute it once.
-	vec2 cusp = find_cusp(a_, b_);
-
+	float b_ = lab.z / C;	vec2 cusp = find_cusp(a_, b_);
 	float Ld = L - cusp.x;
 	float k = 2.f * (Ld > 0.f ? 1.f - cusp.x : cusp.x);
-
 	float e1 = 0.5f * k + abs(Ld) + alpha * C / k;
 	float L0 = cusp.x + 0.5f * (sign(Ld) * (e1 - sqrt(e1 * e1 - 2.f * k * abs(Ld))));
-
 	float t = find_gamut_intersection(a_, b_, L, C, L0);
 	float L_clipped = L0 * (1.f - t) + t * L;
 	float C_clipped = t * C;
-
 	return oklab_to_linear_srgb(vec3( L_clipped, C_clipped * a_, C_clipped * b_ ));
 }
-
-float toe(float x)
-{
+float toe(float x){
 	float k_1 = 0.206f;
 	float k_2 = 0.03f;
 	float k_3 = (1.f + k_1) / (1.f + k_2);
 	return 0.5f * (k_3 * x - k_1 + sqrt((k_3 * x - k_1) * (k_3 * x - k_1) + 4.f * k_2 * k_3 * x));
 }
-
-float toe_inv(float x)
-{
+float toe_inv(float x){
 	float k_1 = 0.206f;
 	float k_2 = 0.03f;
 	float k_3 = (1.f + k_1) / (1.f + k_2);
 	return (x * x + k_1 * x) / (k_3 * (x + k_2));
 }
-
-vec2 to_ST(vec2 cusp)
-{
+vec2 to_ST(vec2 cusp){
 	float L = cusp.x;
 	float C = cusp.y;
 	return vec2( C / L, C / (1.f - L) );
 }
-
-// Returns a smooth approximation of the location of the cusp
-// This polynomial was created by an optimization process
-// It has been designed so that S_mid < S_max and T_mid < T_max
-vec2 get_ST_mid(float a_, float b_)
-{
+vec2 get_ST_mid(float a_, float b_){
 	float S = 0.11516993f + 1.f / (
 		+7.44778970f + 4.15901240f * b_
 		+ a_ * (-2.19557347f + 1.75198401f * b_
@@ -391,7 +238,6 @@ vec2 get_ST_mid(float a_, float b_)
 				+ a_ * (-4.24894561f + 5.38770819f * b_ + 4.69891013f * a_
 					)))
 		);
-
 	float T = 0.11239642f + 1.f / (
 		+1.61320320f - 0.68124379f * b_
 		+ a_ * (+0.40370612f + 0.90148123f * b_
@@ -399,93 +245,55 @@ vec2 get_ST_mid(float a_, float b_)
 				+ a_ * (+0.00299215f - 0.45399568f * b_ - 0.14661872f * a_
 					)))
 		);
-
 	return vec2( S, T );
 }
-
-vec3 get_Cs(float L, float a_, float b_)
-{
+vec3 get_Cs(float L, float a_, float b_){
 	vec2 cusp = find_cusp(a_, b_);
-
 	float C_max = find_gamut_intersection(a_, b_, L, 1.f, L, cusp);
-	vec2 ST_max = to_ST(cusp);
-	
-	// Scale factor to compensate for the curved part of gamut shape:
-	float k = C_max / min((L * ST_max.x), (1.f - L) * ST_max.y);
-
-	float C_mid;
-	{
-		vec2 ST_mid = get_ST_mid(a_, b_);
-
-		// Use a soft minimum function, instead of a sharp triangle shape to get a smooth value for chroma.
-		float C_a = L * ST_mid.x;
+	vec2 ST_max = to_ST(cusp);	float k = C_max / min((L * ST_max.x), (1.f - L) * ST_max.y);
+	float C_mid;{
+		vec2 ST_mid = get_ST_mid(a_, b_);		float C_a = L * ST_mid.x;
 		float C_b = (1.f - L) * ST_mid.y;
 		C_mid = 0.9f * k * sqrt(sqrt(1.f / (1.f / (C_a * C_a * C_a * C_a) + 1.f / (C_b * C_b * C_b * C_b))));
 	}
-
-	float C_0;
-	{
-		// for C_0, the shape is independent of hue, so vec2 are constant. Values picked to roughly be the average values of vec2.
-		float C_a = L * 0.4f;
-		float C_b = (1.f - L) * 0.8f;
-
-		// Use a soft minimum function, instead of a sharp triangle shape to get a smooth value for chroma.
-		C_0 = sqrt(1.f / (1.f / (C_a * C_a) + 1.f / (C_b * C_b)));
+	float C_0;{		float C_a = L * 0.4f;
+		float C_b = (1.f - L) * 0.8f;		C_0 = sqrt(1.f / (1.f / (C_a * C_a) + 1.f / (C_b * C_b)));
 	}
-
 	return vec3( C_0, C_mid, C_max );
 }
-
-vec3 okhsl_to_srgb(vec3 hsl)
-{
+vec3 okhsl_to_srgb(vec3 hsl){
 	float h = hsl.x;
 	float s = hsl.y;
 	float l = hsl.z;
-
-	if (l == 1.0f)
-	{
+	if (l == 1.0f){
 		return vec3( 1.f, 1.f, 1.f );
 	}
-
-	else if (l == 0.f)
-	{
+	else if (l == 0.f){
 		return vec3( 0.f, 0.f, 0.f );
 	}
-
 	float a_ = cos(2.f * M_PI * h);
 	float b_ = sin(2.f * M_PI * h);
 	float L = toe_inv(l);
-
 	vec3 cs = get_Cs(L, a_, b_);
 	float C_0 = cs.x;
 	float C_mid = cs.y;
 	float C_max = cs.z;
-
 	float mid = 0.8f;
 	float mid_inv = 1.25f;
-
 	float C, t, k_0, k_1, k_2;
-
-	if (s < mid)
-	{
+	if (s < mid){
 		t = mid_inv * s;
-
 		k_1 = mid * C_0;
 		k_2 = (1.f - k_1 / C_mid);
-
 		C = t * k_1 / (1.f - k_2 * t);
 	}
-	else
-	{
+	else{
 		t = (s - mid)/ (1.f - mid);
-
 		k_0 = C_mid;
 		k_1 = (1.f - mid) * C_mid * C_mid * mid_inv * mid_inv / C_0;
 		k_2 = (1.f - (k_1) / (C_max - C_mid));
-
 		C = k_0 + t * k_1 / (1.f - k_2 * t);
 	}
-
 	vec3 rgb = oklab_to_linear_srgb(vec3( L, C * a_, C * b_ ));
 	return vec3(
 		srgb_transfer_function(rgb.r),
@@ -493,62 +301,44 @@ vec3 okhsl_to_srgb(vec3 hsl)
 		srgb_transfer_function(rgb.b)
 	);
 }
-
-vec3 srgb_to_okhsl(vec3 rgb)
-{
+vec3 srgb_to_okhsl(vec3 rgb){
 	vec3 lab = linear_srgb_to_oklab(vec3(
 		srgb_transfer_function_inv(rgb.r),
 		srgb_transfer_function_inv(rgb.g),
 		srgb_transfer_function_inv(rgb.b)
 		));
-
 	float C = sqrt(lab.y * lab.y + lab.z * lab.z);
 	float a_ = lab.y / C;
 	float b_ = lab.z / C;
-
 	float L = lab.x;
 	float h = 0.5f + 0.5f * atan(-lab.z, -lab.y) / M_PI;
-
 	vec3 cs = get_Cs(L, a_, b_);
 	float C_0 = cs.x;
 	float C_mid = cs.y;
 	float C_max = cs.z;
-
-	// Inverse of the interpolation in okhsl_to_srgb:
-
 	float mid = 0.8f;
 	float mid_inv = 1.25f;
-
 	float s;
-	if (C < C_mid)
-	{
+	if (C < C_mid){
 		float k_1 = mid * C_0;
 		float k_2 = (1.f - k_1 / C_mid);
-
 		float t = C / (k_1 + k_2 * C);
 		s = t * mid;
 	}
-	else
-	{
+	else{
 		float k_0 = C_mid;
 		float k_1 = (1.f - mid) * C_mid * C_mid * mid_inv * mid_inv / C_0;
 		float k_2 = (1.f - (k_1) / (C_max - C_mid));
-
 		float t = (C - k_0) / (k_1 + k_2 * (C - k_0));
 		s = mid + (1.f - mid) * t;
 	}
-
 	float l = toe(L);
 	return vec3( h, s, l );
 }
-
-
-vec3 okhsv_to_srgb(vec3 hsv)
-{
+vec3 okhsv_to_srgb(vec3 hsv){
 	float h = hsv.x;
 	float s = hsv.y;
 	float v = hsv.z;
-
 	float a_ = cos(2.f * M_PI * h);
 	float b_ = sin(2.f * M_PI * h);
 	
@@ -557,31 +347,18 @@ vec3 okhsv_to_srgb(vec3 hsv)
 	float S_max = ST_max.x;
 	float T_max = ST_max.y;
 	float S_0 = 0.5f;
-	float k = 1.f- S_0 / S_max;
-
-	// first we compute L and V as if the gamut is a perfect triangle:
-
-	// L, C when v==1:
-	float L_v = 1.f   - s * S_0 / (S_0 + T_max - T_max * k * s);
+	float k = 1.f- S_0 / S_max;	float L_v = 1.f   - s * S_0 / (S_0 + T_max - T_max * k * s);
 	float C_v = s * T_max * S_0 / (S_0 + T_max - T_max * k * s);
-
 	float L = v * L_v;
-	float C = v * C_v;
-
-	// then we compensate for both toe and the curved top part of the triangle:
-	float L_vt = toe_inv(L_v);
+	float C = v * C_v;	float L_vt = toe_inv(L_v);
 	float C_vt = C_v * L_vt / L_v;
-
 	float L_new = toe_inv(L);
 	C = C * L_new / L;
 	L = L_new;
-
 	vec3 rgb_scale = oklab_to_linear_srgb(vec3( L_vt, a_ * C_vt, b_ * C_vt ));
 	float scale_L = cbrt(1.f / max(max(rgb_scale.r, rgb_scale.g), max(rgb_scale.b, 0.f)));
-
 	L = L * scale_L;
 	C = C * scale_L;
-
 	vec3 rgb = oklab_to_linear_srgb(vec3( L, C * a_, C * b_ ));
 	return vec3(
 		srgb_transfer_function(rgb.r),
@@ -589,54 +366,35 @@ vec3 okhsv_to_srgb(vec3 hsv)
 		srgb_transfer_function(rgb.b)
 	);
 }
-
-vec3 srgb_to_okhsv(vec3 rgb)
-{
+vec3 srgb_to_okhsv(vec3 rgb){
 	vec3 lab = linear_srgb_to_oklab(vec3(
 		srgb_transfer_function_inv(rgb.r),
 		srgb_transfer_function_inv(rgb.g),
 		srgb_transfer_function_inv(rgb.b)
 		));
-
 	float C = sqrt(lab.y * lab.y + lab.z * lab.z);
 	float a_ = lab.y / C;
 	float b_ = lab.z / C;
-
 	float L = lab.x;
 	float h = 0.5f + 0.5f * atan(-lab.z, -lab.y) / M_PI;
-
 	vec2 cusp = find_cusp(a_, b_);
 	vec2 ST_max = to_ST(cusp);
 	float S_max = ST_max.x;
 	float T_max = ST_max.y;
 	float S_0 = 0.5f;
 	float k = 1.f - S_0 / S_max;
-
-	// first we find L_v, C_v, L_vt and C_vt
-
 	float t = T_max / (C + L * T_max);
 	float L_v = t * L;
 	float C_v = t * C;
-
 	float L_vt = toe_inv(L_v);
-	float C_vt = C_v * L_vt / L_v;
-
-	// we can then use these to invert the step that compensates for the toe and the curved top part of the triangle:
-	vec3 rgb_scale = oklab_to_linear_srgb(vec3( L_vt, a_ * C_vt, b_ * C_vt ));
+	float C_vt = C_v * L_vt / L_v;	vec3 rgb_scale = oklab_to_linear_srgb(vec3( L_vt, a_ * C_vt, b_ * C_vt ));
 	float scale_L = cbrt(1.f / max(max(rgb_scale.r, rgb_scale.g), max(rgb_scale.b, 0.f)));
-
 	L = L / scale_L;
 	C = C / scale_L;
-
 	C = C * toe(L) / L;
 	L = toe(L);
-
-	// we can now compute v and s:
-
 	float v = L / L_v;
 	float s = (S_0 + T_max) * C_v / ((T_max * S_0) + T_max * k * C_v);
-
 	return vec3 (h, s, v );
 }
-
 )";

+ 19 - 13
resources/la_widgets.c

@@ -669,6 +669,8 @@ void la_FloatArrayColorDraw(laUiItem *ui, int h){
     laGetFloatArray(&ui->PP, Data);
     Len = laGetArrayLength(&ui->PP);
 
+    if(ui->PP.LastPs->p->Tag&LA_PROP_IS_LINEAR_SRGB){ tns2LogsRGB(Data); }
+
     tnsUseNoTexture();
     tnsColor4d(Data[0], Data[1], Data[2], /*Len>3?Data[4]:*/ 1);
     tnsVertex2d(ui->L, Y);
@@ -1045,7 +1047,7 @@ void la_ColorCircleDrawHCY(laUiItem *ui, int h){
     real verts[292]={0}; //72*2*2+2*2
     real hcy[3] = {0, 1, 1};
     real step = 1.0 / 72.0f;
-    real RealColor[4] = {0};
+    real RealColor[4] = {0,0,0,1};
     real PickerPos[2];
     real pi_4;
     GLuint index[26];
@@ -1053,6 +1055,8 @@ void la_ColorCircleDrawHCY(laUiItem *ui, int h){
 
     laGetFloatArray(&ui->PP, RealColor);
 
+    if(ui->PP.LastPs->p->Tag&LA_PROP_IS_LINEAR_SRGB){ tns2LogsRGB(RealColor); }
+
     tnsRGB2HCY(RealColor, hcy);
 
     PickerPos[0] = c + cos(hcy[0] * TNS_PI * 2) * hcy[1] * r;
@@ -1089,18 +1093,6 @@ void la_ColorCircleDrawHCY(laUiItem *ui, int h){
     tnsVertexArray2d(verts, 72);
     tnsPackAs(GL_LINE_LOOP);
 
-    tnsColor4dv(RealColor);
-    tnsMakeCircle2d(verts, 16, PickerPos[0], PickerPos[1], 8,0);
-    tnsVertexArray2d(verts, 16);
-    tnsPackAs(GL_TRIANGLE_FAN);
-    tnsColor4d(1, 1, 1, 1);
-    tnsVertexArray2d(verts, 16);
-    tnsPackAs(GL_LINE_LOOP);
-    tnsMakeCircle2d(verts, 16, PickerPos[0], PickerPos[1], 7,0);
-    tnsColor4d(0.1, 0.1, 0.1, 1);
-    tnsVertexArray2d(verts, 16);
-    tnsPackAs(GL_LINE_LOOP);
-
     pi_4 = TNS_PI / 4;
 
     tnsMakeArc2d(&verts[26], 12, c, ui->U + r, r + bt->LM + h, pi_4, -pi_4);
@@ -1130,6 +1122,18 @@ void la_ColorCircleDrawHCY(laUiItem *ui, int h){
     tnsVertexArray2d(verts, 2);
     tnsPackAs(GL_LINES);
 
+    tnsColor4dv(RealColor);
+    tnsMakeCircle2d(verts, 16, PickerPos[0], PickerPos[1], 8,0);
+    tnsVertexArray2d(verts, 16);
+    tnsPackAs(GL_TRIANGLE_FAN);
+    tnsColor4d(1, 1, 1, 1);
+    tnsVertexArray2d(verts, 16);
+    tnsPackAs(GL_LINE_LOOP);
+    tnsMakeCircle2d(verts, 16, PickerPos[0], PickerPos[1], 7,0);
+    tnsColor4d(0.1, 0.1, 0.1, 1);
+    tnsVertexArray2d(verts, 16);
+    tnsPackAs(GL_LINE_LOOP);
+
     if(ui->Extra->HeightCoeff>=0)
         tnsDrawStringAuto("◿",laThemeColor(bt,LA_BT_BORDER),ui->R-LA_RH, ui->R, ui->B-bt->BM-LA_RH, LA_TEXT_ALIGN_CENTER);
 
@@ -2005,6 +2009,7 @@ int OPMOD_ColorHCY(laOperator *a, laEvent *e){
 
     if (e->Type & LA_MOUSE_EVENT && es->Dragging){
         laGetFloatArray(&ui->PP, Color);
+        if(ui->PP.LastPs->p->Tag&LA_PROP_IS_LINEAR_SRGB){ tns2LogsRGB(Color); }
         tnsRGB2HCY(Color, hcy);
         if (es->Dragging==1){
             abso = fabs(atan((real)dy / (real)dx));
@@ -2024,6 +2029,7 @@ int OPMOD_ColorHCY(laOperator *a, laEvent *e){
             hcy[2] = abso; TNS_CLAMP(hcy[2],0,1);
         }
         tnsHCY2RGB(hcy, Color);
+        if(ui->PP.LastPs->p->Tag&LA_PROP_IS_LINEAR_SRGB){ tns2LinearsRGB(Color); }
         laSetFloatArrayAllArray(&ui->PP, Color);
         laRedrawCurrentPanel();
         return LA_RUNNING;

+ 10 - 3
resources/la_widgets_viewers.c

@@ -383,12 +383,11 @@ void la_CanvasDraw(laUiItem *ui, int h){
     laBoxedTheme *bt = (*ui->Type->Theme);
     if (ui->CanvasTemplate && ui->CanvasTemplate->Draw) ui->CanvasTemplate->Draw(bt, ui->PP.EndInstance, ui);
 }
-void la_CanvasDrawOverlay(laUiItem *ui, int h){
+
+void la_CanvasDefaultOverlay(laUiItem* ui, int h){
     laCanvasExtra *e = ui->Extra;
     laBoxedTheme *bt = (*ui->Type->Theme);
 
-    tnsDraw2DTextureDirectly(e->OffScr->pColor[0], ui->L, ui->U, ui->R - ui->L, ui->B - ui->U);
-
     tnsUseNoTexture();
 
     if(MAIN.CurrentWindow->MaximizedUi!=ui){
@@ -421,6 +420,14 @@ void la_CanvasDrawOverlay(laUiItem *ui, int h){
 
     tnsFlush();
 }
+void la_CanvasDrawOverlay(laUiItem *ui, int h){
+    laCanvasExtra *e = ui->Extra;
+    laBoxedTheme *bt = (*ui->Type->Theme);
+
+    tnsDraw2DTextureDirectly(e->OffScr->pColor[0], ui->L, ui->U, ui->R - ui->L, ui->B - ui->U);
+
+    la_CanvasDefaultOverlay(ui, h);
+}
 
 int la_AnimateUiListRecursive(laUiList *uil);