Exemplo n.º 1
0
def gen_src_images(src_format, w, h, nframes):
    seed = 0
    images = []
    for i in range(nframes):
        #create a dummy ImageWrapper to compress:
        if src_format.startswith("YUV"):
            strides, pixels = make_planar_input(src_format,
                                                w,
                                                h,
                                                use_strings=False,
                                                populate=True,
                                                seed=seed + i)
            planes = ImageWrapper._3_PLANES
        else:
            pixels = make_rgb_input(src_format,
                                    w,
                                    h,
                                    use_strings=False,
                                    populate=True,
                                    seed=seed + i)
            strides = w * 3
            planes = ImageWrapper.PACKED
        image = ImageWrapper(0,
                             0,
                             w,
                             h,
                             pixels,
                             src_format,
                             24,
                             strides,
                             planes=planes)
        images.append(image)
        seed += 10
    return images
Exemplo n.º 2
0
def perf_measure_rgb(csc_module, w=1920, h=1080):
    count = min(MAX_ITER, int(PERF_LOOP * 1024 * 1024 / (w * h)))
    rgb_src_formats = sorted([
        x for x in csc_module.get_input_colorspaces()
        if (x.find("RGB") >= 0 or x.find("BGR") >= 0)
    ])
    if DEBUG:
        print("%s: rgb src_formats=%s" % (csc_module, rgb_src_formats))
    for src_format in rgb_src_formats:
        pixels = make_rgb_input(src_format, w, h, populate=True)
        yuv_dst_formats = sorted([
            x for x in csc_module.get_output_colorspaces(src_format)
            if (x.find("RGB") < 0 and x.find("BGR") < 0)
        ])
        if DEBUG:
            print("%s: yuv_formats(%s)=%s" %
                  (csc_module, src_format, yuv_dst_formats))
        for dst_format in yuv_dst_formats:
            start = time.time()
            do_test_csc_rgb(csc_module,
                            src_format,
                            dst_format,
                            w,
                            h,
                            pixels,
                            count=count)
            end = time.time()
            if DEBUG:
                print("%s did %sx%s csc %s times in %.1fms" %
                      (csc_module, w, h, count, end - start))
            mpps = float(w * h * count) / (end - start)
            dim = ("%sx%s" % (w, h)).rjust(10)
            info = ("%s to %s at %s" %
                    (src_format.ljust(7), dst_format.ljust(7), dim)).ljust(40)
            print("%s: %s MPixels/s" % (info, int(mpps / 1024 / 1024)))
Exemplo n.º 3
0
def perf_measure_rgb(csc_module, w=1920, h=1080, test_scaling=[(1,1), (1,2), (1,3)]):
    count = min(MAX_ITER, int(PERF_LOOP*1024*1024/(w*h)))
    rgb_src_formats = sorted([x for x in csc_module.get_input_colorspaces() if x in RGB_FORMATS])
    if DEBUG:
        print("%s: rgb src_formats=%s" % (csc_module, rgb_src_formats))
    for csc_speed in (0, 50, 100):
        print("**** %4ix%-4i - speed=%i%%" % (w, h, csc_speed))
        for src_format in rgb_src_formats:
            pixels = make_rgb_input(src_format, w, h, populate=True)
            yuv_dst_formats = sorted([x for x in csc_module.get_output_colorspaces(src_format) if x not in RGB_FORMATS])
            if DEBUG:
                print("%s: yuv_formats(%s)=%s" % (csc_module, src_format, yuv_dst_formats))
            for dst_format in yuv_dst_formats:
                if not csc_module.get_spec(src_format, dst_format).can_scale:
                    test_scaling=[(1,1)]
                #print("make_planar_input(%s, %s, %s) strides=%s, len(pixels=%s", src_format, w, h, strides, len(pixels))
                for m,d in test_scaling:
                    dst_w, dst_h = w*m//d, h*m//d
                    start = time.time()
                    do_test_csc_rgb(csc_module, src_format, dst_format, w, h, pixels, dst_w, dst_h, count=count, csc_speed=csc_speed)
                    end = time.time()
                    if DEBUG:
                        print("%s did %sx%s csc %s times in %.1fms" % (csc_module, w, h, count, end-start))
                    mpps = float(w*h*count)/(end-start)
                    info = ("%s to %s" % (src_format.ljust(7), dst_format.ljust(7))).ljust(24)
                    if m!=1 or d!=1:
                        scaling_info = ", downscaled by %i/%i" % (m, d)
                    else:
                        scaling_info = ""
                    print("%s: %4i MPixels/s%s" % (info, int(mpps/1024/1024), scaling_info))
Exemplo n.º 4
0
def test_csc_rgb_all(csc_module, w, h):
    #some output planes we can verify:
    CHECKS = {
                ("BGRX", "YUV444P", 16, 16) : (("Y", 0, "5155585b5f6266696d7073777a7e8185888c8f9296999d"),
                                               ("U", 1, "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a"),
                                               ("V", 2, "a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1")),
                ("BGRX", "YUV422P", 32, 32) : (("Y", 0, "51585f666d737a81888f969da4aab1b87e848b9299a0a6ad343a41484f565c637d848b9299a0a7ad343a41484f565c6351585f666d737a81888f969da4aab1"),
                                               ("U", 1, "5a5a5a5a5a5a5a5a80808080cbcbcbcb80808080cbcbcbcb5b5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a80808080cbcbcbcb80808080cbcbcbcb5b5a5a5a5a5a5a"),
                                               ("V", 2, "a1a1a1a1a1a1a1a1313030308e8e8e8e303030308e8e8e8ea1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1313030308e8e8e8e303030308e8e8e8ea1a1a1a1a1a1a1")),
                ("BGRX", "YUV440P", 32, 32) : (("Y", 0, "5155585b5f6266696d7073777a7e8185888c8f9296999d"),
                                               ("U", 1, "6d6d6d6d6d6d6d6d93939393939393936d6d6d6d6d6d6d"),
                                               ("V", 2, "6868686868686868979898989898989868686868686868")),
              }
    for use_strings in (True, False):
        rgb_in = sorted([x for x in csc_module.get_input_colorspaces() if not x.endswith("P")])
        for src_format in rgb_in:
            dst_formats = sorted([x for x in csc_module.get_output_colorspaces(src_format) if x.startswith("YUV")])
            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
            pixels = make_rgb_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
                checks = CHECKS.get((src_format, dst_format, w, h))
                ok = do_test_csc_rgb(csc_module, src_format, dst_format, w, h, pixels, w, h, checks)
                if ok:
                    pass
                else:
                    print("FAILURE: test_csc_rgb_all(%s, %s, %s) %s to %s, use_strings=%s" % (csc_module.get_type(), w, h, src_format, dst_format, use_strings))
Exemplo n.º 5
0
def test_csc_rgb_all(csc_module, w, h):
    #some output planes we can verify:
    CHECKS = {
        ("BGRX", "YUV444P", 16, 16):
        (("Y", 0, "5155585b5f6266696d7073777a7e8185888c8f9296999d"),
         ("U", 1, "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a"),
         ("V", 2, "a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1")),
        ("BGRX", "YUV422P", 32, 32):
        (("Y", 0,
          "51585f666d737a81888f969da4aab1b87e848b9299a0a6ad343a41484f565c637d848b9299a0a7ad343a41484f565c6351585f666d737a81888f969da4aab1"
          ),
         ("U", 1,
          "5a5a5a5a5a5a5a5a80808080cbcbcbcb80808080cbcbcbcb5b5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a80808080cbcbcbcb80808080cbcbcbcb5b5a5a5a5a5a5a"
          ),
         ("V", 2,
          "a1a1a1a1a1a1a1a1313030308e8e8e8e303030308e8e8e8ea1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1313030308e8e8e8e303030308e8e8e8ea1a1a1a1a1a1a1"
          )),
        ("BGRX", "YUV440P", 32, 32):
        (("Y", 0, "5155585b5f6266696d7073777a7e8185888c8f9296999d"),
         ("U", 1, "6d6d6d6d6d6d6d6d93939393939393936d6d6d6d6d6d6d"),
         ("V", 2, "6868686868686868979898989898989868686868686868")),
    }
    for use_strings in (True, False):
        rgb_in = sorted([
            x for x in csc_module.get_input_colorspaces()
            if not x.endswith("P")
        ])
        for src_format in rgb_in:
            dst_formats = sorted([
                x for x in csc_module.get_output_colorspaces(src_format)
                if x.startswith("YUV")
            ])
            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
            pixels = make_rgb_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
                checks = CHECKS.get((src_format, dst_format, w, h))
                ok = do_test_csc_rgb(csc_module, src_format, dst_format, w, h,
                                     pixels, w, h, checks)
                if ok:
                    pass
                else:
                    print(
                        "FAILURE: test_csc_rgb_all(%s, %s, %s) %s to %s, use_strings=%s"
                        % (csc_module.get_type(), w, h, src_format, dst_format,
                           use_strings))
Exemplo n.º 6
0
def perf_measure_rgb(csc_module,
                     w=1920,
                     h=1080,
                     test_scaling=[(1, 1), (1, 2), (1, 3)]):
    count = min(MAX_ITER, int(PERF_LOOP * 1024 * 1024 / (w * h)))
    rgb_src_formats = sorted([
        x for x in csc_module.get_input_colorspaces()
        if (x.find("RGB") >= 0 or x.find("BGR") >= 0)
    ])
    if DEBUG:
        print("%s: rgb src_formats=%s" % (csc_module, rgb_src_formats))
    for csc_speed in (0, 50, 100):
        print("**** %4ix%-4i - speed=%i%%" % (w, h, csc_speed))
        for src_format in rgb_src_formats:
            pixels = make_rgb_input(src_format, w, h, populate=True)
            yuv_dst_formats = sorted([
                x for x in csc_module.get_output_colorspaces(src_format)
                if (x.find("RGB") < 0 and x.find("BGR") < 0)
            ])
            if DEBUG:
                print("%s: yuv_formats(%s)=%s" %
                      (csc_module, src_format, yuv_dst_formats))
            for dst_format in yuv_dst_formats:
                if not csc_module.get_spec(src_format, dst_format).can_scale:
                    test_scaling = [(1, 1)]
                #print("make_planar_input(%s, %s, %s) strides=%s, len(pixels=%s", src_format, w, h, strides, len(pixels))
                for m, d in test_scaling:
                    dst_w, dst_h = w * m // d, h * m // d
                    start = time.time()
                    do_test_csc_rgb(csc_module,
                                    src_format,
                                    dst_format,
                                    w,
                                    h,
                                    pixels,
                                    dst_w,
                                    dst_h,
                                    count=count,
                                    csc_speed=csc_speed)
                    end = time.time()
                    if DEBUG:
                        print("%s did %sx%s csc %s times in %.1fms" %
                              (csc_module, w, h, count, end - start))
                    mpps = float(w * h * count) / (end - start)
                    info = (
                        "%s to %s" %
                        (src_format.ljust(7), dst_format.ljust(7))).ljust(24)
                    if m != 1 or d != 1:
                        scaling_info = ", downscaled by %i/%i" % (m, d)
                    else:
                        scaling_info = ""
                    print("%s: %4i MPixels/s%s" %
                          (info, int(mpps / 1024 / 1024), scaling_info))
Exemplo n.º 7
0
def do_test_csc_roundtrip(csc_module, src_format, dst_format, w, h):
    assert src_format.find("RGB") >= 0 or src_format.find("BGR") >= 0
    pixels = make_rgb_input(src_format, w, h, populate=True)
    stride = len(src_format) * w
    #print(" input pixels: %s (%sx%s, stride=%s, stride*h=%s)" % (len(pixels), w, h, stride, stride*h))
    assert len(
        pixels
    ) >= stride * h, "not enough pixels! (expected at least %s but got %s)" % (
        stride * h, len(pixels))
    image = ImageWrapper(0,
                         0,
                         w,
                         h,
                         pixels,
                         src_format,
                         24,
                         stride,
                         planes=ImageWrapper.PACKED)

    ColorspaceConverterClass = getattr(csc_module, "ColorspaceConverter")
    cc1 = ColorspaceConverterClass()
    cc1.init_context(w, h, src_format, w, h, dst_format)

    temp = cc1.convert_image(image)

    ColorspaceConverterClass = getattr(csc_module, "ColorspaceConverter")
    cc2 = ColorspaceConverterClass()
    cc2.init_context(w, h, dst_format, w, h, src_format)

    regen = cc2.convert_image(temp)
    assert regen

    #compare with original:
    rpixels = regen.get_pixels()
    info = "%s to %s and back @ %sx%s" % (src_format, dst_format, w, h)
    #if src_format.find("RGB")>=0 or src_format.find("BGR")>=0:
    ib = max(src_format.find("X"), src_format.find("A"))
    import binascii
    print("pixels start=%s" % binascii.hexlify(pixels[:20]))
    print("regen  start=%s" % binascii.hexlify(rpixels[:20]))
    check_plane(info, rpixels, pixels, tolerance=5, ignore_byte=ib)
    #else:
    #    for i in range(3):
    #        check_plane(info, rpixels[i], pixels[i], tolerance=5)
    #image.free()
    temp.free()
    regen.free()
    cc1.clean()
    cc2.clean()
Exemplo n.º 8
0
def do_test_codec_roundtrip(encoder_class, decoder_class, encoding, src_format, dst_formats, w, h, populate):
    quality = 100
    speed = 100
    scaling = (1,1)
    options = {}

    start = time.time()
    encoder = encoder_class()
    #print("%s%s" % (encoder.init_context, (w, h, src_format, dst_formats, encoding, quality, speed, scaling, options)))
    encoder.init_context(w, h, src_format, dst_formats, encoding, quality, speed, scaling, options)
    end = time.time()
    print("encoder %s initialized in %.1fms" % (encoder, 1000.0*(end-start)))

    start = time.time()
    decoder = decoder_class()
    decoder.init_context(encoding, w, h, src_format)
    end = time.time()
    print("decoder %s initialized in %.1fms" % (decoder, 1000.0*(end-start)))

    for i in range(4):

        if src_format.find("RGB")>=0 or src_format.find("BGR")>=0:
            pixels = make_rgb_input(src_format, w, h, populate=populate, seed=i)
            isize = len(pixels)
            stride = len(src_format)*w
            #print(" input pixels: %s (%sx%s, stride=%s, stride*h=%s)" % (len(pixels), w, h, stride, stride*h))
            assert len(pixels)>=stride*h, "not enough pixels! (expected at least %s but got %s)" % (stride*h, len(pixels))
            image = ImageWrapper(0, 0, w, h, pixels, src_format, 24, stride, planes=ImageWrapper.PACKED)
        else:
            strides, pixels = make_planar_input(src_format, w, h, populate=populate)
            isize = sum([len(x) for x in pixels])
            image = ImageWrapper(0, 0, w, h, pixels, src_format, 24, strides, planes=ImageWrapper.PLANAR_3)

        print("FRAME %s" % i)
        print("using %s to compress %s" % (encoder, image))
        start = time.time()
        data, options = encoder.compress_image(image)
        end = time.time()
        assert data is not None, "compression failed"
        print("compressed %s bytes down to %s (%.1f%%) in %.1fms" % (isize, len(data), 100.0*len(data)/isize, 1000.0*(end-start)))

        print("uncompressing %s bytes using %s" % (len(data), decoder))
        options['csc'] = src_format
        start = time.time()
        out_image = decoder.decompress_image(data, options)
        end = time.time()
        assert out_image is not None, "decompression failed"
        print("uncompressed to %s in %.1fms" % (str(out_image), 1000.0*(end-start)))
Exemplo n.º 9
0
def do_test_codec_roundtrip(encoder_class, decoder_class, encoding, src_format, dst_formats, w, h, populate):
    quality = 100
    speed = 100
    scaling = (1,1)
    options = {}

    start = time.time()
    encoder = encoder_class()
    #print("%s%s" % (encoder.init_context, (w, h, src_format, dst_formats, encoding, quality, speed, scaling, options)))
    encoder.init_context(w, h, src_format, dst_formats, encoding, quality, speed, scaling, options)
    end = time.time()
    print("encoder %s initialized in %.1fms" % (encoder, 1000.0*(end-start)))

    start = time.time()
    decoder = decoder_class()
    decoder.init_context(encoding, w, h, src_format)
    end = time.time()
    print("decoder %s initialized in %.1fms" % (decoder, 1000.0*(end-start)))

    for i in range(4):

        if src_format.find("RGB")>=0 or src_format.find("BGR")>=0:
            pixels = make_rgb_input(src_format, w, h, populate=populate, seed=i)
            isize = len(pixels)
            stride = len(src_format)*w
            #print(" input pixels: %s (%sx%s, stride=%s, stride*h=%s)" % (len(pixels), w, h, stride, stride*h))
            assert len(pixels)>=stride*h, "not enough pixels! (expected at least %s but got %s)" % (stride*h, len(pixels))
            image = ImageWrapper(0, 0, w, h, pixels, src_format, 24, stride, planes=ImageWrapper.PACKED)
        else:
            strides, pixels = make_planar_input(src_format, w, h, populate=populate)
            isize = sum([len(x) for x in pixels])
            image = ImageWrapper(0, 0, w, h, pixels, src_format, 24, strides, planes=ImageWrapper._3_PLANES)

        print("FRAME %s" % i)
        print("using %s to compress %s" % (encoder, image))
        start = time.time()
        data, options = encoder.compress_image(image)
        end = time.time()
        assert data is not None, "compression failed"
        print("compressed %s bytes down to %s (%.1f%%) in %.1fms" % (isize, len(data), 100.0*len(data)/isize, 1000.0*(end-start)))

        print("uncompressing %s bytes using %s" % (len(data), decoder))
        options['csc'] = src_format
        start = time.time()
        out_image = decoder.decompress_image(data, options)
        end = time.time()
        assert out_image is not None, "decompression failed"
        print("uncompressed to %s in %.1fms" % (str(out_image), 1000.0*(end-start)))
Exemplo n.º 10
0
def gen_src_images(src_format, w, h, nframes):
    seed = 0
    images = []
    for i in range(nframes):
        #create a dummy ImageWrapper to compress:
        if src_format.startswith("YUV"):
            strides, pixels = make_planar_input(src_format, w, h, use_strings=False, populate=True, seed=seed+i)
            planes = ImageWrapper._3_PLANES
        else:
            pixels = make_rgb_input(src_format, w, h, use_strings=False, populate=True, seed=seed+i)
            strides = w*3
            planes = ImageWrapper.PACKED
        image = ImageWrapper(0, 0, w, h, pixels, src_format, 24, strides, planes=planes)
        images.append(image)
        seed += 10
    return images
Exemplo n.º 11
0
def perf_measure_rgb(csc_module, w=1920, h=1080):
    count = min(MAX_ITER, int(PERF_LOOP*1024*1024/(w*h)))
    rgb_src_formats = sorted([x for x in csc_module.get_input_colorspaces() if (x.find("RGB")>=0 or x.find("BGR")>=0)])
    if DEBUG:
        print("%s: rgb src_formats=%s" % (csc_module, rgb_src_formats))
    for src_format in rgb_src_formats:
        pixels = make_rgb_input(src_format, w, h, populate=True)
        yuv_dst_formats = sorted([x for x in csc_module.get_output_colorspaces(src_format) if (x.find("RGB")<0 and x.find("BGR")<0)])
        if DEBUG:
            print("%s: yuv_formats(%s)=%s" % (csc_module, src_format, yuv_dst_formats))
        for dst_format in yuv_dst_formats:
            start = time.time()
            do_test_csc_rgb(csc_module, src_format, dst_format, w, h, pixels, count=count)
            end = time.time()
            if DEBUG:
                print("%s did %sx%s csc %s times in %.1fms" % (csc_module, w, h, count, end-start))
            mpps = float(w*h*count)/(end-start)
            dim = ("%sx%s" % (w,h)).rjust(10)
            info = ("%s to %s at %s" % (src_format.ljust(7), dst_format.ljust(7), dim)).ljust(40)
            print("%s: %s MPixels/s" % (info, int(mpps/1024/1024)))
Exemplo n.º 12
0
def do_test_csc_roundtrip(csc_module, src_format, dst_format, w, h):
    assert src_format.find("RGB") >= 0 or src_format.find("BGR") >= 0
    pixels = make_rgb_input(src_format, w, h, populate=True)
    stride = len(src_format) * w
    # print(" input pixels: %s (%sx%s, stride=%s, stride*h=%s)" % (len(pixels), w, h, stride, stride*h))
    assert len(pixels) >= stride * h, "not enough pixels! (expected at least %s but got %s)" % (stride * h, len(pixels))
    image = ImageWrapper(0, 0, w, h, pixels, src_format, 24, stride, planes=ImageWrapper.PACKED)

    ColorspaceConverterClass = getattr(csc_module, "ColorspaceConverter")
    cc1 = ColorspaceConverterClass()
    cc1.init_context(w, h, src_format, w, h, dst_format)

    temp = cc1.convert_image(image)

    ColorspaceConverterClass = getattr(csc_module, "ColorspaceConverter")
    cc2 = ColorspaceConverterClass()
    cc2.init_context(w, h, dst_format, w, h, src_format)

    regen = cc2.convert_image(temp)
    assert regen

    # compare with original:
    rpixels = regen.get_pixels()
    info = "%s to %s and back @ %sx%s" % (src_format, dst_format, w, h)
    # if src_format.find("RGB")>=0 or src_format.find("BGR")>=0:
    ib = max(src_format.find("X"), src_format.find("A"))
    import binascii

    print("pixels start=%s" % binascii.hexlify(pixels[:20]))
    print("regen  start=%s" % binascii.hexlify(rpixels[:20]))
    check_plane(info, rpixels, pixels, tolerance=5, ignore_byte=ib)
    # else:
    #    for i in range(3):
    #        check_plane(info, rpixels[i], pixels[i], tolerance=5)
    # image.free()
    temp.free()
    regen.free()
    cc1.clean()
    cc2.clean()