*/}}

2 Commits 02b79b5dff ... d60c6b7473

Author SHA1 Message Date
  YimingWu d60c6b7473 log clay and xyz p3 functions 1 day ago
  YimingWu 4b0b36dd3a Premultiplied add 3 days ago
3 changed files with 30 additions and 8 deletions
  1. 4 2
      la_tns.h
  2. 21 6
      la_tns_kernel.c
  3. 5 0
      resources/la_tns_shaders.cpp

+ 4 - 2
la_tns.h

@@ -1524,15 +1524,17 @@ void tnsViewportWithScissor(int x, int y, int w, int h);
 
 void tnssRGB2XYZ(tnsVector3d rgb,tnsVector3d xyz);
 void tnsClay2XYZ(tnsVector3d rgb,tnsVector3d xyz);
+void tnsD65P32XYZ(tnsVector3d rgb,tnsVector3d xyz);
 void tnsXYZ2sRGB(tnsVector3d xyz,tnsVector3d rgb);
 void tnsXYZ2Clay(tnsVector3d xyz,tnsVector3d rgb);
-void tnsRGB2Clay(tnsVector3d rgb, tnsVector3d clay);
-void tnsClay2RGB(tnsVector3d clay, tnsVector3d rgb);
+void tnsXYZ2D65P3(tnsVector3d xyz,tnsVector3d rgb);
 
 void tns2LogsRGBSingle(real* a);
 void tns2LinearsRGBSingle(real* a);
 void tns2LogsRGB(real* srgb);
 void tns2LinearsRGB(real* srgb);
+void tns2LogClay(real* srgb);
+void tns2LinearClay(real* srgb);
 void tnsRGB2OKLAB(real* rgb, real* oklab);
 void tnsOKLAB2RGB(real* oklab, real* rgb);
 

+ 21 - 6
la_tns_kernel.c

@@ -1745,6 +1745,7 @@ void tnsConfigure2DTexture(tnsTexture *t){
         elif(t->GLTexBitsType==GL_RGBA32UI){ format=GL_RGBA_INTEGER; type=GL_UNSIGNED_INT; t->IsUIntTexture=1; }
         elif(t->GLTexBitsType==GL_R32UI){ format=GL_RED_INTEGER; type=GL_UNSIGNED_INT; t->IsUIntTexture=1; }
         elif(t->GLTexBitsType==GL_RGBA16F){ format=GL_RGBA; type=GL_FLOAT; }
+        elif(t->GLTexBitsType==GL_RGBA32F){ format=GL_RGBA; type=GL_FLOAT; }
         elif(t->GLTexBitsType==GL_DEPTH_STENCIL){ format=GL_DEPTH_STENCIL; type=GL_UNSIGNED_INT_24_8; t->GLTexBitsType=GL_DEPTH24_STENCIL8; }
 #ifdef LAGUI_ANDROID
         if(isDepth){t->GLTexBitsType=GL_DEPTH_COMPONENT24; type=GL_UNSIGNED_INT;}
@@ -4653,13 +4654,17 @@ void tnsXYZ2Clay(tnsVector3d xyz,tnsVector3d rgb){
                       0.0134474,-0.1183897,1.0154096};
     tnsApplyRotation33d(rgb,mat,xyz);
 }
-void tnsRGB2Clay(tnsVector3d rgb, tnsVector3d clay){
-    tnsVector3d xyz; tnssRGB2XYZ(rgb,xyz);
-    tnsXYZ2Clay(xyz,clay);
+void tnsD65P32XYZ(tnsVector3d rgb,tnsVector3d xyz){
+	tnsMatrix44d mat={0.48657095,0.26566769,0.19821729,
+				      0.22897456,0.69173852,0.07928691,
+				      0.0,0.04511338,1.04394437};
+    tnsApplyRotation33d(xyz,mat,rgb);
 }
-void tnsClay2RGB(tnsVector3d clay, tnsVector3d rgb){
-    tnsVector3d xyz; tnsClay2XYZ(clay,xyz);
-    tnsXYZ2sRGB(xyz,rgb);
+void tnsXYZ2D65P3(tnsVector3d xyz,tnsVector3d rgb){
+	tnsMatrix44d mat={2.49349691,-0.93138362,-0.40271078,
+                      -0.82948897,1.76266406,0.02362469,
+                      0.03584583,-0.07617239,0.95688452};
+    tnsApplyRotation33d(rgb,mat,xyz);
 }
 
 static real _srgb_transfer_function(real a){
@@ -4684,6 +4689,16 @@ void tns2LinearsRGB(real* srgb){
     srgb[1]=_srgb_transfer_function_inv(srgb[1]);
     srgb[2]=_srgb_transfer_function_inv(srgb[2]);
 }
+void tns2LogClay(real* srgb){
+    srgb[0]=pow(srgb[0],2.19921875);
+    srgb[1]=pow(srgb[1],2.19921875);
+    srgb[2]=pow(srgb[2],2.19921875);
+}
+void tns2LinearClay(real* srgb){
+    srgb[0]=pow(srgb[0],1.0f/2.19921875);
+    srgb[1]=pow(srgb[1],1.0f/2.19921875);
+    srgb[2]=pow(srgb[2],1.0f/2.19921875);
+}
 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];

+ 5 - 0
resources/la_tns_shaders.cpp

@@ -803,7 +803,12 @@ void main(){
 	}else if(TextureMode==6){
         vec4 color1=texture1(fUV.st); if(MultiplyColor!=0){color1*=fColor;}
 		vec4 color2=texture2();
+		if(TexPremultiplied==0){ color1=vec4(color1.rgb*color1.a,color1.a); color2=vec4(color2.rgb*color2.a,color2.a); }
 		color = color1+color2;
+		if(TexPremultiplied==0){
+			color1=(color1.a!=0.)?vec4(color1.rgb/color1.a,color1.a):vec4(0.,0.,0.,0.);
+			color2=(color2.a!=0.)?vec4(color2.rgb/color2.a,color2.a):vec4(0.,0.,0.,0.);
+		}
 	}else if(TextureMode==101){ // YUYV
 		ivec2 tsize = textureSize(TexColor,0);
 		vec2 pixel = fUV.st * vec2(tsize);