From 9852f29f8b1f36643095078841960536e2e88385 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Sun, 27 Apr 2014 07:32:30 +0000 Subject: [PATCH] python3 compat: more string workarounds git-svn-id: https://xpra.org/svn/Xpra/trunk@6189 3bb7dfac-3a0b-4e04-842a-767bc560f471 --- .../csc_cython/colorspace_converter.pyx | 28 ++++++++++++------- .../csc_swscale/colorspace_converter.pyx | 19 ++++++++----- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/xpra/codecs/csc_cython/colorspace_converter.pyx b/src/xpra/codecs/csc_cython/colorspace_converter.pyx index 7da1ef27e8..38569a65b1 100644 --- a/src/xpra/codecs/csc_cython/colorspace_converter.pyx +++ b/src/xpra/codecs/csc_cython/colorspace_converter.pyx @@ -35,21 +35,29 @@ cdef int roundup(int n, int m): return (n + m - 1) & ~(m - 1) #precalculate indexes in native endianness: -tmp = str(struct.pack("=BBBB", 0, 1, 2, 3)) -cdef uint8_t BGRA_B = tmp.find('\0') -cdef uint8_t BGRA_G = tmp.find('\1') -cdef uint8_t BGRA_R = tmp.find('\2') -cdef uint8_t BGRA_A = tmp.find('\3') +BYTEORDER = struct.pack("=BBBB", 0, 1, 2, 3) +def byteorder(v): + for i in range(4): + bv = BYTEORDER[i] + if type(bv)==str: + #old versions of python: byte value is in fact a character (str) + bv = ord(bv) + if bv==v: + return i + raise Exception("cannot find byteorder for %s" % v) +cdef uint8_t BGRA_B = byteorder(0) +cdef uint8_t BGRA_G = byteorder(1) +cdef uint8_t BGRA_R = byteorder(2) +cdef uint8_t BGRA_A = byteorder(3) cdef uint8_t BGRX_R = BGRA_R cdef uint8_t BGRX_G = BGRA_G cdef uint8_t BGRX_B = BGRA_B cdef uint8_t BGRX_X = BGRA_A -tmp = str(struct.pack("=BBBB", 0, 1, 2, 3)) -cdef uint8_t RGBX_R = tmp.find('\0') -cdef uint8_t RGBX_G = tmp.find('\1') -cdef uint8_t RGBX_B = tmp.find('\2') -cdef uint8_t RGBX_X = tmp.find('\3') +cdef uint8_t RGBX_R = byteorder(0) +cdef uint8_t RGBX_G = byteorder(1) +cdef uint8_t RGBX_B = byteorder(2) +cdef uint8_t RGBX_X = byteorder(3) COLORSPACES = {"BGRX" : ["YUV420P"], "YUV420P" : ["RGBX", "BGRX"], "GBRP" : ["RGBX", "BGRX"] } diff --git a/src/xpra/codecs/csc_swscale/colorspace_converter.pyx b/src/xpra/codecs/csc_swscale/colorspace_converter.pyx index 9f6886b8f0..da5777eb1e 100644 --- a/src/xpra/codecs/csc_swscale/colorspace_converter.pyx +++ b/src/xpra/codecs/csc_swscale/colorspace_converter.pyx @@ -91,7 +91,8 @@ for av_enum_name, width_mult, height_mult, pix_fmt in FORMAT_OPTIONS: if av_enum is None: log("av pixel mode %s is not available", av_enum_name) continue - FORMATS[pix_fmt] = CSCPixelFormat(av_enum, av_enum_name, width_mult, height_mult, pix_fmt) + log("av_enum(%s)=%s", av_enum_name, av_enum) + FORMATS[pix_fmt] = CSCPixelFormat(av_enum, av_enum_name.encode("latin1"), width_mult, height_mult, pix_fmt.encode("latin1")) if pix_fmt not in COLORSPACES: COLORSPACES.append(pix_fmt) log("swscale pixel formats: %s", FORMATS) @@ -119,15 +120,17 @@ cdef class SWSFlags: #keeping this array in scope ensures the strings don't go away! +def b(x): + return x.encode("latin1") FLAGS_OPTIONS = [ - (30, ("SWS_BICUBIC", )), - (40, ("SWS_BICUBLIN", )), - (60, ("SWS_BILINEAR", )), - (80, ("SWS_FAST_BILINEAR", )), + (30, ("SWS_BICUBIC", ), []), + (40, ("SWS_BICUBLIN", ), []), + (60, ("SWS_BILINEAR", ), []), + (80, ("SWS_FAST_BILINEAR", ), []), ] cdef int flags #@DuplicatedSignature FLAGS = [] -for speed, flags_strs in FLAGS_OPTIONS: +for speed, flags_strs, bin_flags in FLAGS_OPTIONS: flags = 0 for flags_str in flags_strs: flag_val = constants.get(flags_str) @@ -136,8 +139,10 @@ for speed, flags_strs in FLAGS_OPTIONS: continue log("%s=%s", flags_str, flag_val) flags |= flag_val + for flag in flags_strs: + bin_flags.append(b(flag)) log("%s=%s", flags_strs, flags) - FLAGS.append((speed, SWSFlags(flags, flags_strs))) + FLAGS.append((speed, SWSFlags(flags, bin_flags))) log("swscale flags: %s", FLAGS)