def METHOD_NAME(data, width, height, depth, version):
    row_size = width * depth // 8
    with io.BytesIO(data) as fp:
        rows = [rle_impl.encode(fp.read(row_size)) for _ in range(height)]
    bytes_counts = array.array(('H', 'I')[version - 1], map(len, rows))
    encoded = b''.join(rows)
    with io.BytesIO() as fp:
        write_be_array(fp, bytes_counts)
        fp.write(encoded)
        result = fp.getvalue()
    return result