def generate_pairs(base_glyphs, target_glyphs):
    if not path.isfile(base_glyphs):
        raise Exception('base glyph image file %s does not exist' %
                        base_glyphs)
    if not path.isfile(target_glyphs):
        raise Exception('target glyph image file %s does not exist' %
                        target_glyphs)

    base_collection = glyph_image.read_file(base_glyphs)
    target_collection = glyph_image.read_file(target_glyphs)
    return get_collection_pairs(base_collection, target_collection)
Esempio n. 2
0
def compare_files(base_file, target_file, image_dir):
    """Reads the two glyph image files, then calls compare_collections.
    No pairing info is provided."""

    if not path.isfile(base_file):
        raise Exception("base file %s does not exist" % base_file)
    if not path.isfile(target_file):
        raise Exception("target file %s does not exist" % target_file)

    base_collection = glyph_image.read_file(base_file)
    target_collection = glyph_image.read_file(target_file)
    return compare_collections(base_collection, target_collection, None,
                               image_dir)
Esempio n. 3
0
def _test(image_file):
    """Compare size of our rle encoding with that of our lossy rle encoding."""
    coll = glyph_image.read_file(image_file)
    for ix, im in sorted(coll.image_dict.items())[:15]:
        data = im.data
        print("glyph %d (%d)" % (ix, len(data)))
        rle1_data = rle(data)
        rle2_data = rle2(data)

        rle1_len = len(rle1_data)
        rle2_len = len(rle2_data)
        pct = 0 if rle1_len == 0 else int(rle2_len * 100 / rle1_len)
        print("  rle %d, lossy rle %d (%2d%%)" % (rle1_len, rle2_len, pct))

        expanded_rle1 = expand_rle(rle1_data)
        rle1_ok, msg = compare_rle(expanded_rle1, data)
        if not rle1_ok:
            print("failed to expand rle data, %s" % msg)

        expanded_rle2 = expand_rle2(rle2_data)
        rle2_ok, msg = compare_rle2(expanded_rle2, data)
        if not rle2_ok:
            print("failed to expand rle2 data, %s" % msg)
        else:
            enc_rle2 = base64_encode(rle2_data)
            # print(wrap_str(enc_rle2, 80))
            temp = base64_decode(enc_rle2)
            enc_rle2_ok, msg = compare_rle(temp, rle2_data)
Esempio n. 4
0
def compress(input_file, output_file, comp):
    print("compress" if comp else "uncompress")
    print(" input: %s" % input_file)
    print("output: %s" % output_file)

    if comp:
        coll = glyph_image.read_file(input_file)
        with open(output_file, "w") as f:
            glyph_image.write_file_header(coll.file_header, f)
            for _, im in sorted(coll.image_dict.items()):
                glyph_image.write_glyph_image(im, True, f)
                rle_data = rle(im.data)
                rle_data_b64 = base64_encode(rle_data)
                b64_len = len(rle_data_b64)
                print("> rle %d" % b64_len, file=f)
                print(wrap_str(rle_data_b64, 80), file=f)
    else:
        print("uncompress not supported")
def compress(input_file, output_file, comp):
    print('compress' if comp else 'uncompress')
    print(' input: %s' % input_file)
    print('output: %s' % output_file)

    if comp:
        coll = glyph_image.read_file(input_file)
        with open(output_file, 'w') as f:
            glyph_image.write_file_header(coll.file_header, f)
            for _, im in sorted(coll.image_dict.items()):
                glyph_image.write_glyph_image(im, True, f)
                rle_data = rle(im.data)
                rle_data_b64 = base64_encode(rle_data)
                b64_len = len(rle_data_b64)
                print('> rle %d' % b64_len, file=f)
                print(wrap_str(rle_data_b64, 80), file=f)
    else:
        print('uncompress not supported')