Ticket #1765: gl-yuva.patch
File gl-yuva.patch, 7.6 KB (added by , 9 months ago) |
---|
-
xpra/client/gl/gl_window_backing_base.py
1 1 # This file is part of Xpra. 2 2 # Copyright (C) 2013 Serviware (Arthur Huillet, <ahuillet@serviware.com>) 3 # Copyright (C) 2012-20 19Antoine Martin <antoine@xpra.org>3 # Copyright (C) 2012-2020 Antoine Martin <antoine@xpra.org> 4 4 # Xpra is released under the terms of the GNU GPL v2, or, at your option, any 5 5 # later version. See the file COPYING for details. 6 6 … … 15 15 GL_UNPACK_ROW_LENGTH, GL_UNPACK_ALIGNMENT, 16 16 GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_NEAREST, 17 17 GL_UNSIGNED_BYTE, GL_LUMINANCE, GL_LINEAR, 18 GL_TEXTURE0, GL_TEXTURE1, GL_TEXTURE2, GL_QUADS, GL_LINE_LOOP, GL_LINES, GL_COLOR_BUFFER_BIT, 18 GL_TEXTURE0, GL_TEXTURE1, GL_TEXTURE2, GL_TEXTURE3, 19 GL_QUADS, GL_LINE_LOOP, GL_LINES, GL_COLOR_BUFFER_BIT, 19 20 GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER, 20 21 GL_DONT_CARE, GL_TRUE, GL_DEPTH_TEST, GL_SCISSOR_TEST, GL_LIGHTING, GL_DITHER, 21 22 GL_RGB, GL_RGBA, GL_BGR, GL_BGRA, GL_RGBA8, GL_RGB8, GL_RGB10_A2, GL_RGB565, GL_RGB5_A1, GL_RGBA4, … … 63 64 WEBP_PILLOW, SCROLL_ENCODING, 64 65 ) 65 66 from xpra.client.gl.gl_check import GL_ALPHA_SUPPORTED, is_pyopengl_memoryview_safe, get_max_texture_size 66 from xpra.client.gl.gl_colorspace_conversions import YUV2RGB_shader, YUV2RGB_FULL_shader, RGBP2RGB_shader 67 from xpra.client.gl.gl_colorspace_conversions import ( 68 YUV2RGB_shader, YUV2RGB_FULL_shader, RGBP2RGB_shader, YUVA2RGBA_shader, 69 ) 67 70 from xpra.client.gl.gl_spinner import draw_spinner 68 71 from xpra.log import Logger 69 72 … … 200 203 TEX_Y = 0 201 204 TEX_U = 1 202 205 TEX_V = 2 203 TEX_RGB = 3 204 TEX_FBO = 4 #FBO texture (guaranteed up-to-date window contents) 205 TEX_TMP_FBO = 5 206 TEX_CURSOR = 6 207 N_TEXTURES = 7 206 TEX_A = 3 207 TEX_RGB = 4 208 TEX_FBO = 5 #FBO texture (guaranteed up-to-date window contents) 209 TEX_TMP_FBO = 6 210 TEX_CURSOR = 7 211 N_TEXTURES = 8 208 212 209 213 # Shader number assignment 210 214 YUV2RGB_SHADER = 0 211 215 RGBP2RGB_SHADER = 1 212 216 YUV2RGB_FULL_SHADER = 2 217 YUVA2RGBA_SHADER = 3 213 218 219 SHADER_STR = { 220 YUV2RGB_SHADER : "YUV2RGB", 221 RGBP2RGB_SHADER : "RGBP2RGB", 222 YUV2RGB_FULL_SHADER : "YUV2RGB_FULL", 223 YUVA2RGBA_SHADER : "YUVA2RGBA", 224 } 214 225 215 226 """ 216 227 The logic is as follows: … … 450 461 for name, progid, progstr in ( 451 462 ("YUV2RGB", YUV2RGB_SHADER, YUV2RGB_shader), 452 463 ("YUV2RGBFULL", YUV2RGB_FULL_SHADER, YUV2RGB_FULL_shader), 464 ("YUVA2RGBA", YUVA2RGBA_SHADER, YUVA2RGBA_shader), 453 465 ("RGBP2RGB", RGBP2RGB_SHADER, RGBP2RGB_shader), 454 466 ): 455 467 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, self.shaders[progid]) … … 1007 1019 def paint_webp(self, img_data, x : int, y : int, width : int, height : int, options, callbacks): 1008 1020 subsampling = options.strget("subsampling") 1009 1021 has_alpha = options.boolget("has_alpha") 1010 if subsampling=="YUV420P" and WEBP_YUV and self.webp_decoder and not WEBP_PILLOW and not has_alpha andwidth>=2 and height>=2:1022 if subsampling=="YUV420P" and WEBP_YUV and self.webp_decoder and not WEBP_PILLOW and width>=2 and height>=2: 1011 1023 img = self.webp_decoder.decompress_yuv(img_data) 1012 1024 flush = options.intget("flush", 0) 1013 1025 w = img.get_width() 1014 1026 h = img.get_height() 1015 self.idle_add(self.gl_paint_planar, YUV2RGB_SHADER, flush, "webp", img, 1027 if has_alpha: 1028 shader = YUVA2RGBA_SHADER 1029 else: 1030 shader = YUV2RGB_SHADER 1031 self.idle_add(self.gl_paint_planar, shader, flush, "webp", img, 1016 1032 x, y, w, h, width, height, options, callbacks) 1017 1033 return 1018 1034 super().paint_webp(img_data, x, y, width, height, options, callbacks) … … 1112 1128 x : int, y : int, enc_width : int, enc_height : int, width : int, height : int, 1113 1129 options, callbacks): 1114 1130 #this function runs in the UI thread, no video_decoder lock held 1115 log("gl_paint_planar%s", (flush, encoding, img, x, y, enc_width, enc_height, width, height, options, callbacks)) 1131 log("gl_paint_planar%s", (SHADER_STR.get(shader, shader), flush, encoding, img, 1132 x, y, enc_width, enc_height, width, height, 1133 options, callbacks)) 1116 1134 x, y = self.gravity_adjust(x, y, options) 1117 1135 try: 1118 1136 pixel_format = img.get_pixel_format() 1119 assert pixel_format in ("YUV420P", "YUV422P", "YUV444P", "GBRP" ), \1137 assert pixel_format in ("YUV420P", "YUV422P", "YUV444P", "GBRP", "YUVA"), \ 1120 1138 "sorry the GL backing does not handle pixel format '%s' yet!" % (pixel_format) 1121 1139 1122 1140 context = self.gl_context() … … 1164 1182 self.pixel_format = pixel_format 1165 1183 self.texture_size = (width, height) 1166 1184 # Create textures of the same size as the window's 1167 for texture, index in ((GL_TEXTURE0, TEX_Y), (GL_TEXTURE1, TEX_U), (GL_TEXTURE2, TEX_V)): 1168 (div_w, div_h) = divs[index] 1185 for texture, index in ( 1186 (GL_TEXTURE0, TEX_Y), 1187 (GL_TEXTURE1, TEX_U), 1188 (GL_TEXTURE2, TEX_V), 1189 (GL_TEXTURE3, TEX_A), 1190 ): 1191 div_w, div_h = divs[index] 1169 1192 glActiveTexture(texture) 1170 1193 target = GL_TEXTURE_RECTANGLE_ARB 1171 1194 glBindTexture(target, self.textures[index]) -
xpra/client/gl/gl_colorspace_conversions.py
43 43 # 10 instructions, 2 R-regs 44 44 """ 45 45 46 YUVA2RGBA_shader = b"""!!ARBfp1.0 47 # cgc version 3.1.0010, build date Feb 10 2012 48 # command line args: -profile arbfp1 49 # source file: yuv.cg 50 #vendor NVIDIA Corporation 51 #version 3.1.0.10 52 #profile arbfp1 53 #program main 54 #semantic main.IN 55 #var float2 IN.texcoord1 : $vin.TEXCOORD0 : TEX0 : 0 : 1 56 #var float2 IN.texcoord2 : $vin.TEXCOORD1 : TEX1 : 0 : 1 57 #var float2 IN.texcoord3 : $vin.TEXCOORD2 : TEX2 : 0 : 1 58 #var float2 IN.texcoord4 : $vin.TEXCOORD2 : TEX3 : 0 : 1 59 #var samplerRECT IN.texture1 : TEXUNIT0 : texunit 0 : 0 : 1 60 #var samplerRECT IN.texture2 : TEXUNIT1 : texunit 1 : 0 : 1 61 #var samplerRECT IN.texture3 : TEXUNIT2 : texunit 2 : 0 : 1 62 #var samplerRECT IN.texture4 : TEXUNIT3 : texunit 3 : 0 : 1 63 #var float4 IN.color : $vin.COLOR0 : COL0 : 0 : 1 64 #var float4 main.color : $vout.COLOR0 : COL : -1 : 1 65 #const c[0] = 1.1643835 2.017231 0 0.5 66 #const c[1] = 0.0625 1.1643835 -0.3917616 -0.81296802 67 #const c[2] = 1.1643835 0 1.5960271 68 PARAM c[3] = { { 1.1643835, 2.017231, 0, 0.5 }, 69 { 0.0625, 1.1643835, -0.3917616, -0.81296802 }, 70 { 1.1643835, 0, 1.5960271 } }; 71 TEMP R0; 72 TEMP R1; 73 TEX R0.x, fragment.texcoord[2], texture[2], RECT; 74 ADD R1.z, R0.x, -c[0].w; 75 TEX R1.x, fragment.texcoord[0], texture[0], RECT; 76 TEX R0.x, fragment.texcoord[1], texture[1], RECT; 77 ADD R1.x, R1, -c[1]; 78 ADD R1.y, R0.x, -c[0].w; 79 DP3 result.color.z, R1, c[0]; 80 DP3 result.color.y, R1, c[1].yzww; 81 DP3 result.color.x, R1, c[2]; 82 MOV result.color.w, fragment.texcoord[3]; 83 END 84 # 10 instructions, 2 R-regs 85 """ 86 46 87 YUV2RGB_FULL_shader = b"""!!ARBfp1.0 47 88 # cgc version 3.0.0016, build date Feb 13 2011 48 89 # command line args: -profile arbfp1