Calcualates the size of a compressed texture level in bytes
973540
function textureLevelSize(format, width, height) {
    switch (format) {
        case COMPRESSED_RGB_S3TC_DXT1_EXT:
        case COMPRESSED_RGB_ATC_WEBGL:
        case COMPRESSED_RGB_ETC1_WEBGL:
            return ((width + 3) >> 2) * ((height + 3) >> 2) * 8;

        case COMPRESSED_RGBA_S3TC_DXT3_EXT:
        case COMPRESSED_RGBA_S3TC_DXT5_EXT:
        case COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL:
        case COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL:
            return ((width + 3) >> 2) * ((height + 3) >> 2) * 16;

        case COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
        case COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:
            return Math.floor((Math.max(width, 8) * Math.max(height, 8) * 4 + 7) / 8);

        case COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
        case COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
            return Math.floor((Math.max(width, 16) * Math.max(height, 8) * 2 + 7) / 8);

    	//ASTC formats, https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
        case COMPRESSED_RGBA_ASTC_4x4_KHR:
        case COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
            return Math.floor((width + 3) / 4) *  Math.floor((height + 3) / 4) * 16; 
        case COMPRESSED_RGBA_ASTC_5x4_KHR:
        case COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
            return Math.floor((width + 4) / 5) * Math.floor((height + 3) / 4) * 16;
        case COMPRESSED_RGBA_ASTC_5x5_KHR:
        case COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
            return Math.floor((width + 4) / 5) * Math.floor((height + 4) / 5) * 16;
        case COMPRESSED_RGBA_ASTC_6x5_KHR:
        case COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
            return Math.floor((width + 5) / 6) *  Math.floor((height + 4) / 5) * 16;
        case COMPRESSED_RGBA_ASTC_6x6_KHR:
        case COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
             return Math.floor((width + 5) / 6) * Math.floor((height + 5) / 6) * 16;
        case COMPRESSED_RGBA_ASTC_8x5_KHR:
        case COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
             return Math.floor((width + 7) / 8) * Math.floor((height + 4) / 5) * 16;
        case COMPRESSED_RGBA_ASTC_8x6_KHR:
        case COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
             return Math.floor((width + 7) / 8) * Math.floor((height + 5) / 6) * 16;
        case COMPRESSED_RGBA_ASTC_8x8_KHR:
        case COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
             return Math.floor((width + 7) / 8) * Math.floor((height + 7) / 8) * 16;
        case COMPRESSED_RGBA_ASTC_10x5_KHR:
        case COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
             return Math.floor((width + 9) / 10) * Math.floor((height + 4) / 5) * 16;
        case COMPRESSED_RGBA_ASTC_10x6_KHR:
        case COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
             return Math.floor((width + 9) / 10) * Math.floor((height + 5) / 6) * 16;
        case COMPRESSED_RGBA_ASTC_10x8_KHR:
        case COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
             return Math.floor((width + 9) / 10) * Math.floor((height + 7) / 8) * 16;
        case COMPRESSED_RGBA_ASTC_10x10_KHR:
        case COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
             return Math.floor((width + 9) / 10) * Math.floor((height + 9) / 10) * 16;
        case COMPRESSED_RGBA_ASTC_12x10_KHR:
        case COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
             return Math.floor((width + 11) / 12) * Math.floor((height + 9) / 10) * 16;
        case COMPRESSED_RGBA_ASTC_12x12_KHR:
        case COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
             return Math.floor((width + 11) / 12) * Math.floor((height + 11) / 12) * 16; 

        default:
            return 0;
    }
}
1117461
def _calcsize(fmt):
    '''
    '''
     # sizeof(long) != sizeof(ssize_t) on LLP64
    if _sizeof_Clong < _sizeof_Cvoidp: # pragma: no coverage
        z = 'P'
    else:
        z = 'L'
    return calcsize(fmt.replace('z', z))
708565
private int bytesPerPixel() {
		long fileSize = data.getFile().length();
		long pixelMax = getXPixels() * (long) getYPixels();
		// ceil result, because it is a maximum that we use to divide
		return (int) Math.ceil(fileSize / (double) pixelMax);
	}
151803
def get_net_size(mask):
    '''
    
    '''
    binary_str = ''
    for octet in mask.split('.'):
        binary_str += bin(int(octet))[2:].zfill(8)
    return len(binary_str.rstrip('0'))
711751
def _compute_chunk_size(self):
        # type: (Descriptor) -> int
        
        if self._src_block_list is not None:
            blen = len(self._src_block_list)
            if blen == 0:
                # this is a one-shot block blob
                return self._src_ase.size
            elif blen == 1:
                return self._src_block_list[0].size
            else:
                return -1
        else:
            return _MAX_NONBLOCK_BLOB_CHUNKSIZE_BYTES
1309156
function(arrayBuffer, texture, exposure) {
        if (exposure == null) {
            exposure = 0;
        }
        var data = new Uint8Array(arrayBuffer);
        var size = data.length;
        if (uint82string(data, 0, 2) !== '#?') {
            return;
        }
        // find empty line, next line is resolution info
        for (var i = 2; i < size; i++) {
            if (toChar(data[i]) === '\n' && toChar(data[i+1]) === '\n') {
                break;
            }
        }
        if (i >= size) { // not found
            return;
        }
        // find resolution info line
        i += 2;
        var str = '';
        for (; i < size; i++) {
            var _char = toChar(data[i]);
            if (_char === '\n') {
                break;
            }
            str += _char;
        }
        // -Y M +X N
        var tmp = str.split(' ');
        var height = parseInt(tmp[1]);
        var width = parseInt(tmp[3]);
        if (!width || !height) {
            return;
        }

        // read and decode actual data
        var offset = i+1;
        var scanline = [];
        // memzero
        for (var x = 0; x < width; x++) {
            scanline[x] = [];
            for (var j = 0; j < 4; j++) {
                scanline[x][j] = 0;
            }
        }
        var pixels = new Float32Array(width * height * 4);
        var offset2 = 0;
        for (var y = 0; y < height; y++) {
            var offset = readColors(scanline, data, offset, width);
            if (!offset) {
                return null;
            }
            for (var x = 0; x < width; x++) {
                rgbe2float(scanline[x], pixels, offset2, exposure);
                offset2 += 4;
            }
        }

        if (!texture) {
            texture = new Texture2D();
        }
        texture.width = width;
        texture.height = height;
        texture.pixels = pixels;
        // HALF_FLOAT can't use Float32Array
        texture.type = Texture.FLOAT;
        return texture;
    }
684882
def bytes_from_readable_size(C, size, suffix='B'):
        """"""
        s = re.split("^([0-9\.]+)\s*([%s]?)%s?" % (''.join(C.SIZE_UNITS), suffix), size, flags=re.I)
        bytes, unit = round(float(s[1])), s[2].upper()
        while unit in C.SIZE_UNITS and C.SIZE_UNITS.index(unit) > 0:
            bytes *= 1024
            unit = C.SIZE_UNITS[C.SIZE_UNITS.index(unit) - 1]
        return bytes
24786
def readable_size(C, bytes, suffix='B', decimals=1, sep='\u00a0'):
        """"""
        if bytes is None:
            return
        size = float(bytes)
        for unit in C.SIZE_UNITS:
            if abs(size) < 1024 or unit == C.SIZE_UNITS[-1]:
                return "{size:.{decimals}f}{sep}{unit}{suffix}".format(
                    size=size,
                    unit=unit,
                    suffix=suffix,
                    sep=sep,
                    decimals=C.SIZE_UNITS.index(unit) > 0 and decimals or 0,  # B with no decimal
                )
            size /= 1024
1009305
def _file_size(file_path, uncompressed=False):
    """"""
    _, ext = os.path.splitext(file_path)

    if uncompressed:
        if ext in {".gz", ".gzip"}:
            with gzip.GzipFile(file_path, mode="rb") as fp:
                try:
                    fp.seek(0, os.SEEK_END)
                    return fp.tell()
                except ValueError:
                    # on python2, cannot seek from end and must instead read to end
                    fp.seek(0)
                    while len(fp.read(8192)) != 0:
                        pass
                    return fp.tell()
        elif ext in {".bz", ".bz2", ".bzip", ".bzip2"}:
            with bz2.BZ2File(file_path, mode="rb") as fp:
                fp.seek(0, os.SEEK_END)
                return fp.tell()

    return os.path.getsize(file_path)
974960
def convert_size(size_bytes):
    
    if size_bytes == 0:
        return "0B"
    size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
    i = int(math.floor(math.log(size_bytes, 1024)))
    p = math.pow(1024, i)
    s = round(size_bytes / p, 2)
    return "%s %s" % (s, size_name[i])
777335
function (texture) {
        var pixels = texture.pixels;
        var width = texture.width;
        var height = texture.height;

        function fetchPixel(x, y, rg) {
            x = Math.max(Math.min(x, width - 1), 0);
            y = Math.max(Math.min(y, height - 1), 0);
            var idx = (y * (width - 1) + x) * 4;
            if (pixels[idx + 3] === 0) {
                return false;
            }
            rg[0] = pixels[idx];
            rg[1] = pixels[idx + 1];
            return true;
        }

        function addPixel(a, b, out) {
            out[0] = a[0] + b[0];
            out[1] = a[1] + b[1];
        }

        var center = [], left = [], right = [], top = [], bottom = [];
        var weight = 0;
        for (var y = 0; y < height; y++) {
            for (var x = 0; x < width; x++) {
                var idx = (y * (width - 1) + x) * 4;
                if (pixels[idx + 3] === 0) {
                    weight = center[0] = center[1] = 0;
                    if (fetchPixel(x - 1, y, left)) {
                        weight++; addPixel(left, center, center);
                    }
                    if (fetchPixel(x + 1, y, right)) {
                        weight++; addPixel(right, center, center);
                    }
                    if (fetchPixel(x, y - 1, top)) {
                        weight++; addPixel(top, center, center);
                    }
                    if (fetchPixel(x, y + 1, bottom)) {
                        weight++; addPixel(bottom, center, center);
                    }
                    center[0] /= weight;
                    center[1] /= weight;
                    // PENDING If overwrite. bilinear interpolation.
                    pixels[idx] = center[0];
                    pixels[idx + 1] = center[1];
                }
                pixels[idx + 3] = 1;
            }
        }
    }
760845
def inspect
      "#<ZPNG::Image " +
      %w'width height bpp chunks scanlines'.map do |k|
        v = case (v = send(k))
          when Array
            "[#{v.size} entries]"
          when String
            v.size > 40 ? "[#{v.bytesize} bytes]" : v.inspect
          else v.inspect
        end
        "#{k}=#{v}"
      end.compact.join(", ") + ">"
    end
627429
def _long2bytes(n, blocksize=0):
    

    # After much testing, this algorithm was deemed to be the fastest.
    s = ''
    pack = struct.pack
    while n > 0:
        ### CHANGED FROM '>I' TO '<I'. (DCG)
        s = pack('<I', n & 0xffffffffL) + s
        ### --------------------------
        n = n >> 32

    # Strip off leading zeros.
    for i in range(len(s)):
        if s[i] <> '\000':
            break
    else:
        # Only happens when n == 0.
        s = '\000'
        i = 0

    s = s[i:]

    # Add back some pad bytes. This could be done more efficiently
    # w.r.t. the de-padding being done above, but sigh...
    if blocksize > 0 and len(s) % blocksize:
        s = (blocksize - len(s) % blocksize) * '\000' + s

    return s
1010546
def sub_bytes(state):
    
    state = state.reshape(4, 32)
    return fcat(
        subword(state[0]),
        subword(state[1]),
        subword(state[2]),
        subword(state[3]),
    )
107925
public static int estimateCompressedSize(int[] inputBlock, int bits,
                int blockSize)  {
                int maxNoExp = (1 << bits) - 1;
                // Size of the header and the bits-bit slots
                int outputOffset = HEADER_SIZE + bits * blockSize;
                int expNum = 0;

                for (int i = 0; i < blockSize; ++i) {
                        if (inputBlock[i] > maxNoExp) {
                                expNum++;
                        }
                }
                outputOffset += (expNum << 5);

                return outputOffset;
        }
698430
def _calc_texture_gradient(img):
    
    ret = numpy.zeros((img.shape[0], img.shape[1], img.shape[2]))

    for colour_channel in (0, 1, 2):
        ret[:, :, colour_channel] = skimage.feature.local_binary_pattern(
            img[:, :, colour_channel], 8, 1.0)

    return ret
974750
def _requiredSize(shape, dtype):
	
	return math.floor(np.prod(np.asarray(shape, dtype=np.uint64)) * np.dtype(dtype).itemsize)