Skip to content

Commit

Permalink
python3 compat: more string workarounds
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@6189 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 27, 2014
1 parent 676bc38 commit 9852f29
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
28 changes: 18 additions & 10 deletions src/xpra/codecs/csc_cython/colorspace_converter.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
19 changes: 12 additions & 7 deletions src/xpra/codecs/csc_swscale/colorspace_converter.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)


Expand Down

0 comments on commit 9852f29

Please sign in to comment.