def __compute_num_layers(bpp, extra_bits, layer_bits=64):
    """
    Computes the number of 'layers' required to store the original image with bpp bits-per-pixel
    along with the results of len(extra_bits) filtered versions of the image, each requiring
    bpp + extra_bits[i] bits. The filters are done in that order and each layer can have at most
    layer_bits bits (defaults to 64).
    """
    nlayers, shift = 1, layer_bits-bpp
    for ex_bits in extra_bits:
        shift -= bpp + ex_bits
        if shift < 0:
            nlayers += 1
            shift = layer_bits - bpp - ex_bits
    return nlayers