コード例 #1
0
ファイル: test_csc.py プロジェクト: DiGuoZhiMeng/Xpra
def check_plane(info,
                data,
                expected,
                tolerance=3,
                pixel_stride=4,
                ignore_byte=-1):
    if expected is None:
        #nothing to check
        return
    assert data is not None
    print("check_plane(%s, %s:%s, %s:%s" %
          (info, type(data), len(data), type(expected), len(expected)))
    #chop data to same size as expected sample:
    if type(data) in (memoryview, _buffer, str):
        data = bytearray(data)
    if type(expected) in (_buffer, str):
        expected = bytearray(expected)
    actual_data = data[:len(expected)]
    if actual_data == expected:
        return True
    assert type(actual_data) == type(
        expected), "expected result as %s but got %s" % (type(expected),
                                                         type(actual_data))
    assert len(actual_data) == len(
        expected), "expected at least %s items but got %s" % (len(expected),
                                                              len(actual_data))
    #now compare values, with some tolerance for rounding (off by one):
    errs = {}
    diff = []
    for i in range(len(expected)):
        if ignore_byte >= 0:
            if (i % pixel_stride) == ignore_byte:
                continue
        va = actual_data[i]
        ve = expected[i]
        d = abs(va - ve)
        diff.append(d)
        if d > tolerance:
            errs[i] = hex(va)[2:], hex(ve)[2:]
    ratio = 100.0 * len(errs) / len(diff)
    if len(errs) > 0:
        h = ""
        if ratio > 1:
            h = "ERROR "
        print(h + "output differs for %s, max difference=%s, avg=%.1f" %
              (info, max(diff), float(sum(diff)) / len(diff)))
        print("check_plane(%s, .., ..) expected=%s" %
              (info, dump_pixels(expected)))
        print("check_plane(%s, .., ..)   actual=%s" %
              (info, dump_pixels(data)))
        serrs = []
        for k in sorted(errs.keys())[:10]:
            serrs.append((hex(k)[2:], (errs.get(k))))
        print("errors at %s locations: %s (%.1f%%)" %
              (len(errs), serrs, ratio))
    return ratio <= 2.1
コード例 #2
0
ファイル: test_csc.py プロジェクト: svn2github/Xpra
def do_test_csc_rgb(csc_module, src_format, dst_format, w, h, pixels, dst_w, dst_h, checks=(), count=1, csc_speed=100):
    ColorspaceConverterClass = getattr(csc_module, "ColorspaceConverter")
    cc = ColorspaceConverterClass()
    #print("%s()=%s" % (ColorspaceConverterClass, cc))
    cc.init_context(w, h, src_format, dst_w, dst_h, dst_format, csc_speed)
    if DEBUG:
        print("ColorspaceConverter=%s" % cc)
        print("    %s" % cc.get_info())
        print("do_test_csc_rgb() input pixels=%s" % dump_pixels(pixels))
    bpp = len(src_format)
    image = ImageWrapper(0, 0, w, h, pixels, src_format, 32, w*bpp, planes=ImageWrapper.PACKED)
    for _ in range(count):
        out = cc.convert_image(image)
    if DEBUG:
        print("do_test_csc_rgb() output=%s" % out)
    pixels = out.get_pixels()
    if dst_format.endswith("P"):
        assert out.get_planes()==ImageWrapper._3_PLANES, "expected 3 planes as output but got: %s in %s" % (out.get_planes(), out)
        assert len(pixels)==3, "expected 3 planes but found: %s" % len(pixels)
        assert len(out.get_rowstride())==3, "expected 3 rowstrides but got: %s" % str(out.get_rowstride())
    #for i in range(3):
    #    print("do_test_csc_rgb() plane data[%s]=%s" % (i, dump_pixels(pixels[i])))
    ok = True
    if checks:
        for plane, index, expected in checks:
            ok &= check_plane(plane, pixels[index], expected)
    cc.clean()
    return ok
コード例 #3
0
ファイル: test_csc.py プロジェクト: svn2github/Xpra
def do_test_csc_planar(csc_module, src_format, dst_format, w, h, strides, pixels, checks=(), count=1):
    assert len(pixels) == 3, "this test only handles 3-plane pixels but we have %s" % len(pixels)
    ColorspaceConverterClass = getattr(csc_module, "ColorspaceConverter")
    cc = ColorspaceConverterClass()
    # print("%s()=%s" % (ColorspaceConverterClass, cc))
    cc.init_context(w, h, src_format, w, h, dst_format)
    if DEBUG:
        print("ColorspaceConverter=%s" % cc)
        for i in range(3):
            print("test_csc() plane[%s]=%s" % (i, dump_pixels(pixels[i])))
    image = ImageWrapper(0, 0, w, h, pixels, src_format, 24, strides, planes=ImageWrapper._3_PLANES)
    for _ in range(count):
        out = cc.convert_image(image)
    if DEBUG:
        print("do_test_csc_planar() output=%s" % out)
    assert out is not None, "convert_image returned None!"
    assert out.get_planes() == ImageWrapper.PACKED, "output image %s is not in packed format: it has %s planes" % (
        out,
        out.get_planes(),
    )
    outw = out.get_width()
    assert out.get_rowstride() >= outw * 3, "output stride is too small: expected at least 3*%s=%s, but got %s" % (
        outw,
        3 * outw,
        out.get_rowstride(),
    )
    # clone the pixels before the wrapper falls out of scope!
    out.clone_pixel_data()
    cc.clean()
    return out.get_pixels()
コード例 #4
0
ファイル: test_csc.py プロジェクト: svn2github/Xpra
def check_plane(info, data, expected, tolerance=3, pixel_stride=4, ignore_byte=-1):
    if expected is None:
        # nothing to check
        return
    assert data is not None
    print("check_plane(%s, %s:%s, %s:%s" % (info, type(data), len(data), type(expected), len(expected)))
    # chop data to same size as expected sample:
    if type(data) in (buffer, str):
        data = bytearray(data)
    if type(expected) in (buffer, str):
        expected = bytearray(expected)
    actual_data = data[: len(expected)]
    if actual_data == expected:
        return True
    assert type(actual_data) == type(expected), "expected result as %s but got %s" % (type(expected), type(actual_data))
    assert len(actual_data) == len(expected), "expected at least %s items but got %s" % (
        len(expected),
        len(actual_data),
    )
    # now compare values, with some tolerance for rounding (off by one):
    errs = {}
    diff = []
    for i in range(len(expected)):
        if ignore_byte >= 0:
            if (i % pixel_stride) == ignore_byte:
                continue
        va = actual_data[i]
        ve = expected[i]
        d = abs(va - ve)
        diff.append(d)
        if d > tolerance:
            errs[i] = hex(va)[2:], hex(ve)[2:]
    ratio = 100.0 * len(errs) / len(diff)
    if len(errs) > 0:
        h = ""
        if ratio > 1:
            h = "ERROR "
        print(
            h + "output differs for %s, max difference=%s, avg=%.1f" % (info, max(diff), float(sum(diff)) / len(diff))
        )
        print("check_plane(%s, .., ..) expected=%s" % (info, dump_pixels(expected)))
        print("check_plane(%s, .., ..)   actual=%s" % (info, dump_pixels(data)))
        serrs = []
        for k in sorted(errs.keys())[:10]:
            serrs.append((hex(k)[2:], (errs.get(k))))
        print("errors at %s locations: %s (%.1f%%)" % (len(errs), serrs, ratio))
    return ratio <= 2.1
コード例 #5
0
ファイル: test_csc.py プロジェクト: svn2github/Xpra
def test_csc_planar_all(csc_module, w, h):
    # get_subsampling_divs()
    e420 = bytearray([0xFF, 0x0, 0x87, 0x0, 0xFF, 0x0, 0x88, 0x0, 0xFF, 0x0, 0x81, 0x0, 0xFF, 0x0, 0x82])
    e422 = bytearray([0xFF, 0x0, 0x87, 0x0, 0xFF, 0x0, 0x86, 0x0, 0xFF, 0x0, 0x84, 0x0, 0xFF, 0x0, 0x84])
    e444 = bytearray([0xFF, 0x0, 0x87, 0x0, 0xFF, 0x0, 0x87, 0x0, 0xFF, 0x0, 0x87, 0x0, 0xFF, 0x0, 0x87])
    CHECKS = {
        ("YUV420P", "XRGB", 32, 32): ((e420,)),
        ("YUV422P", "XRGB", 32, 32): ((e422,)),
        ("YUV444P", "XRGB", 32, 32): ((e444,)),
    }
    for use_strings in (True, False):
        planar_in = [x for x in csc_module.get_input_colorspaces() if x.startswith("YUV")]
        for src_format in sorted(planar_in):
            dst_formats = sorted(
                [
                    x
                    for x in csc_module.get_output_colorspaces(src_format)
                    if (not x.startswith("YUV") and not x.endswith("P"))
                ]
            )
            populate = (
                len(
                    [
                        cs
                        for (cs, cd, cw, ch) in CHECKS.keys()
                        if (cs == src_format and cd in dst_formats and cw == w and ch == h)
                    ]
                )
                > 0
            )
            # populate = len([x for x in FMT_TO_EXPECTED_OUTPUT.keys() if x[0]==src_format and x[1] in dst_formats])>0
            strides, pixels = make_planar_input(src_format, w, h, use_strings, populate=populate)
            for dst_format in dst_formats:
                spec = csc_module.get_spec(src_format, dst_format)
                if w < spec.min_w or h < spec.min_h:
                    print(
                        "skipping test %s to %s at %sx%s because dimensions are too small"
                        % (src_format, dst_format, w, h)
                    )
                    continue
                out_pixels = do_test_csc_planar(csc_module, src_format, dst_format, w, h, strides, pixels)
                if DEBUG:
                    print(
                        "test_csc_planar_all() %s to %s head of output pixels=%s"
                        % (src_format, dst_format, dump_pixels(out_pixels[:128]))
                    )
                expected = CHECKS.get((src_format, dst_format))
                ok = check_plane(dst_format, out_pixels, expected)
                print(
                    "test_csc_planar_all(%s, %s, %s) %s to %s, use_strings=%s, ok=%s"
                    % (csc_module.get_type(), w, h, src_format, dst_format, use_strings, ok)
                )
コード例 #6
0
ファイル: test_csc.py プロジェクト: DiGuoZhiMeng/Xpra
def do_test_csc_rgb(csc_module,
                    src_format,
                    dst_format,
                    w,
                    h,
                    pixels,
                    dst_w,
                    dst_h,
                    checks=(),
                    count=1,
                    csc_speed=100):
    ColorspaceConverterClass = getattr(csc_module, "ColorspaceConverter")
    cc = ColorspaceConverterClass()
    #print("%s()=%s" % (ColorspaceConverterClass, cc))
    cc.init_context(w, h, src_format, dst_w, dst_h, dst_format, csc_speed)
    if DEBUG:
        print("ColorspaceConverter=%s" % cc)
        print("    %s" % cc.get_info())
        print("do_test_csc_rgb() input pixels=%s" % dump_pixels(pixels))
    bpp = len(src_format)
    image = ImageWrapper(0,
                         0,
                         w,
                         h,
                         pixels,
                         src_format,
                         32,
                         w * bpp,
                         planes=ImageWrapper.PACKED)
    for _ in range(count):
        out = cc.convert_image(image)
    if DEBUG:
        print("do_test_csc_rgb() output=%s" % out)
    pixels = out.get_pixels()
    if dst_format.endswith("P"):
        assert out.get_planes(
        ) == ImageWrapper.PLANAR_3, "expected 3 planes as output but got: %s in %s" % (
            out.get_planes(), out)
        assert len(
            pixels) == 3, "expected 3 planes but found: %s" % len(pixels)
        assert len(out.get_rowstride(
        )) == 3, "expected 3 rowstrides but got: %s" % str(out.get_rowstride())
    #for i in range(3):
    #    print("do_test_csc_rgb() plane data[%s]=%s" % (i, dump_pixels(pixels[i])))
    ok = True
    if checks:
        for plane, index, expected in checks:
            ok &= check_plane(plane, pixels[index], expected)
    cc.clean()
    return ok
コード例 #7
0
ファイル: test_csc.py プロジェクト: DiGuoZhiMeng/Xpra
def do_test_csc_planar(csc_module,
                       src_format,
                       dst_format,
                       w,
                       h,
                       strides,
                       pixels,
                       dst_w,
                       dst_h,
                       checks=(),
                       count=1,
                       csc_speed=100):
    assert len(
        pixels
    ) == 3, "this test only handles 3-plane pixels but we have %s" % len(
        pixels)
    ColorspaceConverterClass = getattr(csc_module, "ColorspaceConverter")
    cc = ColorspaceConverterClass()
    #print("%s()=%s" % (ColorspaceConverterClass, cc))
    cc.init_context(w, h, src_format, dst_w, dst_h, dst_format, csc_speed)
    if DEBUG:
        print("ColorspaceConverter=%s" % cc)
        for i in range(3):
            print("test_csc() plane[%s]=%s" % (i, dump_pixels(pixels[i])))
    image = ImageWrapper(0,
                         0,
                         w,
                         h,
                         pixels,
                         src_format,
                         24,
                         strides,
                         planes=ImageWrapper.PLANAR_3)
    for _ in range(count):
        out = cc.convert_image(image)
    if DEBUG:
        print("do_test_csc_planar() output=%s" % out)
    assert out is not None, "convert_image returned None!"
    assert out.get_planes(
    ) == ImageWrapper.PACKED, "output image %s is not in packed format: it has %s planes" % (
        out, out.get_planes())
    outw = out.get_width()
    assert out.get_rowstride(
    ) >= outw * 3, "output stride is too small: expected at least 3*%s=%s, but got %s" % (
        outw, 3 * outw, out.get_rowstride())
    #clone the pixels before the wrapper falls out of scope!
    out.clone_pixel_data()
    cc.clean()
    return out.get_pixels()
コード例 #8
0
ファイル: test_csc.py プロジェクト: DiGuoZhiMeng/Xpra
def test_csc_planar_all(csc_module, w, h):
    #get_subsampling_divs()
    e420 = bytearray([
        0xff, 0x0, 0x87, 0x0, 0xff, 0x0, 0x88, 0x0, 0xff, 0x0, 0x81, 0x0, 0xff,
        0x0, 0x82
    ])
    e422 = bytearray([
        0xff, 0x0, 0x87, 0x0, 0xff, 0x0, 0x86, 0x0, 0xff, 0x0, 0x84, 0x0, 0xff,
        0x0, 0x84
    ])
    e444 = bytearray([
        0xff, 0x0, 0x87, 0x0, 0xff, 0x0, 0x87, 0x0, 0xff, 0x0, 0x87, 0x0, 0xff,
        0x0, 0x87
    ])
    CHECKS = {
        ("YUV420P", "XRGB", 32, 32): ((e420, )),
        ("YUV422P", "XRGB", 32, 32): ((e422, )),
        ("YUV444P", "XRGB", 32, 32): ((e444, )),
    }
    for use_strings in (True, False):
        planar_in = [
            x for x in csc_module.get_input_colorspaces()
            if x.startswith("YUV")
        ]
        for src_format in sorted(planar_in):
            dst_formats = sorted([
                x for x in csc_module.get_output_colorspaces(src_format)
                if (not x.startswith("YUV") and not x.endswith("P"))
            ])
            populate = len([
                cs for (cs, cd, cw, ch) in CHECKS.keys()
                if (cs == src_format and cd in dst_formats and cw == w
                    and ch == h)
            ]) > 0
            #populate = len([x for x in FMT_TO_EXPECTED_OUTPUT.keys() if x[0]==src_format and x[1] in dst_formats])>0
            strides, pixels = make_planar_input(src_format,
                                                w,
                                                h,
                                                use_strings,
                                                populate=populate)
            for dst_format in dst_formats:
                spec = csc_module.get_spec(src_format, dst_format)
                if w < spec.min_w or h < spec.min_h:
                    print(
                        "skipping test %s to %s at %sx%s because dimensions are too small"
                        % (src_format, dst_format, w, h))
                    continue
                out_pixels = do_test_csc_planar(csc_module, src_format,
                                                dst_format, w, h, strides,
                                                pixels, w, h)
                if DEBUG:
                    print(
                        "test_csc_planar_all() %s to %s head of output pixels=%s"
                        % (src_format, dst_format, dump_pixels(
                            out_pixels[:128])))
                expected = CHECKS.get((src_format, dst_format))
                ok = check_plane(dst_format, out_pixels, expected)
                if ok:
                    pass
                else:
                    print(
                        "test_csc_planar_all(%s, %s, %s) %s to %s, use_strings=%s"
                        % (csc_module.get_type(), w, h, src_format, dst_format,
                           use_strings))