DXGL r912 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r911‎ | r912 | r913 >
Date:22:03, 12 April 2019
Author:admin
Status:new
Tags:
Comment:
Add conversion from RGB to YUV.
Modified paths:
  • /ddraw/ShaderGen2D.cpp (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen2D.cpp
@@ -106,8 +106,10 @@
107107 static const char const_bt601_coeff[] =
108108 "const mat3 bt601_coeff = mat3(1.164,1.164,1.164,0.0,-0.392,2.017,1.596,-0.813,0.0);\n\
109109 const vec3 yuv_offsets = vec3(-0.0625, -0.5, -0.5);\n";
 110+static const char const_bt601_coeff_inv[] =
 111+"const mat3 bt601_coeff_inv = mat3(0.2569,-0.1483,.4394,.5044,-.2911,-.3679,.0979,.4394,-.0715);\n\
 112+const vec3 yuv_offsets_inv = vec3(0.0625, 0.5, 0.5);\n";
110113
111 -
112114 // Attributes
113115 static const char attr_xy[] = "attribute vec2 xy;\n";
114116 static const char attr_rgb[] = "attribute vec3 rgb;\n";
@@ -163,6 +165,7 @@
164166 static const char op_destoutdestblend[] = "gl_FragColor = (vec4(pixel)/vec4(colorsizedest)) * texture2D(desttex,gl_TexCoord[1].st);\n";
165167 static const char op_destout[] = "gl_FragColor = vec4(pixel)/vec4(colorsizedest);\n";
166168 static const char op_destoutyuvrgb[] = "gl_FragColor = yuvatorgba(vec4(pixel)/vec4(colorsizedest));\n";
 169+static const char op_destoutrgbyuv[] = "gl_FragColor = rgbatoyuva(vec4(pixel)/vec4(colorsizedest));\n";
167170 static const char op_vertex[] = "vec4 xyzw = vec4(xy[0],xy[1],0,1);\n\
168171 mat4 proj = mat4(\n\
169172 vec4(2.0 / (view[1] - view[0]), 0, 0, 0),\n\
@@ -189,6 +192,11 @@
190193 {\n\
191194 return vec4(vec3(bt601_coeff * (yuva.rgb + yuv_offsets)),yuva.a);\n\
192195 }\n\n";
 196+static const char func_rgbatoyuva[] =
 197+"vec4 rgbatoyuva(vec4 rgba)\n\
 198+{\n\
 199+ return vec4(vec3((bt601_coeff_inv * rgba.rgb) + yuv_offsets_inv),rgba.a);\n\
 200+}\n\n";
193201 static const char func_readrgbg[] = "";
194202 static const char func_readgrgb[] = "";
195203 static const char func_readuyvy[] = "";
@@ -900,6 +908,17 @@
901909 break;
902910 }
903911
 912+ switch (desttype)
 913+ {
 914+ case 0:
 915+ default:
 916+ break;
 917+ case 0x83:
 918+ if ((srctype >= 0x80) && (srctype <= 0x83)) break;
 919+ String_Append(fsrc, const_bt601_coeff_inv);
 920+ break;
 921+ }
 922+
904923 // Uniforms
905924 if (id & DDBLT_COLORFILL) String_Append(fsrc, unif_fillcolor);
906925 else
@@ -969,7 +988,7 @@
970989 if (usedest) String_Append(fsrc, var_dest);
971990
972991 // Functions
973 - switch (srctype2)
 992+ switch (srctype)
974993 {
975994 case 0x20:
976995 break;
@@ -982,6 +1001,7 @@
9831002 case 0x82:
9841003 break;
9851004 case 0x83:
 1005+ if ((desttype >= 0x80) && (desttype <= 0x83)) break;
9861006 String_Append(fsrc, func_yuvatorgba);
9871007 break;
9881008 default:
@@ -988,6 +1008,26 @@
9891009 break;
9901010 }
9911011
 1012+ switch (desttype)
 1013+ {
 1014+ case 0x20:
 1015+ break;
 1016+ case 0x21:
 1017+ break;
 1018+ case 0x80:
 1019+ break;
 1020+ case 0x81:
 1021+ break;
 1022+ case 0x82:
 1023+ break;
 1024+ case 0x83:
 1025+ if ((srctype >= 0x80) && (srctype <= 0x83)) break;
 1026+ String_Append(fsrc, func_rgbatoyuva);
 1027+ break;
 1028+ default:
 1029+ break;
 1030+ }
 1031+
9921032 // Main
9931033 String_Append(fsrc, mainstart);
9941034 if (id & 0x10000000) String_Append(fsrc, op_clip);
@@ -1054,6 +1094,22 @@
10551095 {
10561096 switch (srctype)
10571097 {
 1098+ case 0x00:
 1099+ case 0x10:
 1100+ case 0x11:
 1101+ case 0x12:
 1102+ case 0x13:
 1103+ switch (desttype)
 1104+ {
 1105+ case 0:
 1106+ default:
 1107+ String_Append(fsrc, op_destout);
 1108+ break;
 1109+ case 0x83:
 1110+ String_Append(fsrc, op_destoutrgbyuv);
 1111+ break;
 1112+ }
 1113+ break;
10581114 case 0x83:
10591115 if ((desttype >= 0x80) && (desttype <= 0x83))
10601116 String_Append(fsrc, op_destout);