def selftest(full=False): global ENCODINGS from xpra.os_util import hexstr from xpra.codecs.codec_checks import make_test_image img = make_test_image("BGRA", 32, 32) if full: vrange = (0, 50, 100) else: vrange = (50, ) for encoding in tuple(ENCODINGS): try: for q in vrange: for s in vrange: for alpha in (True, False): v = encode(encoding, img, q, s, False, alpha) assert v, "encode output was empty!" cdata = v[1].data log("encode(%s)=%s", (encoding, img, q, s, alpha), hexstr(cdata)) except Exception as e: # pragma: no cover l = log.warn l("Pillow error saving %s with quality=%s, speed=%s, alpha=%s", encoding, q, s, alpha) l(" %s", e, exc_info=True) ENCODINGS.remove(encoding)
def selftest(full=False): global ENCODINGS import binascii from xpra.codecs.codec_checks import make_test_image img = make_test_image("BGRA", 32, 32) if full: vrange = (0, 50, 100) else: vrange = (50, ) for encoding in list(ENCODINGS): try: for q in vrange: for s in vrange: for alpha in (True, False): v = encode(encoding, img, q, s, alpha) assert v, "encode output was empty!" cdata = v[1].data log("encode(%s)=%s", (encoding, img, q, s, alpha), binascii.hexlify(cdata)) except Exception as e: log.warn( "Pillow error saving %s with quality=%s, speed=%s, alpha=%s", encoding, q, s, alpha) log.warn(" %s", e, exc_info=True) ENCODINGS.remove(encoding)
def _test_csc(self, mod, width=16, height=16, in_csc="BGRX", out_csc="YUV420P", pixel="00000000", expected=()): csc_mod = loader.load_codec(mod) if not csc_mod: print("%s not found" % mod) return if in_csc not in csc_mod.get_input_colorspaces(): raise Exception("%s does not support %s as input" % (mod, in_csc)) if out_csc not in csc_mod.get_output_colorspaces(in_csc): raise Exception("%s does not support %s as output for %s" % (mod, out_csc, in_csc)) csc = csc_mod.ColorspaceConverter() csc.init_context(width, height, in_csc, width, height, out_csc) image = make_test_image(in_csc, width, height) size = image.get_rowstride()//4*image.get_height() bgrx = h2b(pixel)*size image.set_pixels(bgrx) out_image = csc.convert_image(image) csc.clean() assert out_image.get_planes()>=len(expected) #now verify the value for each plane specified: for i, v_str in enumerate(expected): plane = out_image.get_pixels()[i] #plane_stride = out_image.get_rowstride()[i] #assert len(plane)>=plane_stride*out_image.get_height() plane_bytes = memoryview_to_bytes(plane) v = h2b(v_str) if not cmpp(plane_bytes, v): raise Exception("%s: plane %s, expected %s but got %s" % ( mod, out_csc[i], v_str, hexstr(plane_bytes[:len(v)])))
def _test_YUV420P(self, encoding, encoder_module, decoder_module, yuvdata, width=16, height=16): in_csc = "YUV420P" if in_csc not in encoder_module.get_input_colorspaces(encoding): raise Exception("%s does not support %s as input" % (encoder_module, in_csc)) if in_csc != decoder_module.get_output_colorspace(encoding, in_csc): raise Exception("%s does not support %s as output for %s" % (decoder_module, in_csc, in_csc)) encoder = encoder_module.Encoder() options = typedict({"max-delayed": 0}) encoder.init_context(encoding, width, height, in_csc, options) in_image = make_test_image(in_csc, width, height) yuv = [] rowstrides = [] divs = get_subsampling_divs(in_csc) for i, bvalue in enumerate(yuvdata): xdiv, ydiv = divs[i] rowstride = width // xdiv rowstrides.append(rowstride) size = rowstride * height // ydiv yuv.append(chr(bvalue).encode("latin1") * size) in_image.set_pixels(yuv) in_image.set_rowstride(rowstrides) cdata, client_options = encoder.compress_image(in_image) assert cdata #decode it: decoder = decoder_module.Decoder() decoder.init_context(encoding, width, height, in_csc) out_image = decoder.decompress_image(cdata, typedict(client_options)) #print("%s %s : %s" % (encoding, decoder_module, out_image)) in_planes = in_image.get_pixels() out_planes = out_image.get_pixels() for i, plane in enumerate(("Y", "U", "V")): in_pdata = in_planes[i] out_pdata = out_planes[i] xdiv, ydiv = divs[i] in_stride = in_image.get_rowstride()[i] out_stride = out_image.get_rowstride()[i] #compare lines at a time since the rowstride may be different: for y in range(height // ydiv): in_rowdata = in_pdata[in_stride * y:in_stride * y + width // xdiv] out_rowdata = out_pdata[out_stride * y:out_stride * y + width // xdiv] if not cmpp(in_rowdata, out_rowdata): raise Exception( "expected %s but got %s for row %i of plane %s with %s" % (hexstr(in_rowdata), hexstr(out_rowdata), y, plane, encoding))
def selftest(full=False): global ENCODINGS import binascii from xpra.codecs.codec_checks import make_test_image img = make_test_image("BGRA", 32, 32) if full: vrange = (0, 50, 100) else: vrange = (50, ) for encoding in list(ENCODINGS): try: for q in vrange: for s in vrange: for alpha in (True, False): v = encode(encoding, img, q, s, alpha) assert v, "encode output was empty!" cdata = v[1].data log("encode(%s)=%s", (encoding, img, q, s, alpha), binascii.hexlify(cdata)) except Exception as e: log.warn("Pillow error saving %s with quality=%s, speed=%s, alpha=%s", encoding, q, s, alpha) log.warn(" %s", e, exc_info=True) ENCODINGS.remove(encoding)