Read BlipJPEG record. Holds raw JPEG image data
505923
private function _readBlipJPEG()
	{
		// offset: 0; size: 2; recVer and recInstance

		// bit: 4-15; mask: 0xFFF0; recInstance
		$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4;

		$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
		$recordData = substr($this->_data, $this->_pos + 8, $length);

		// move stream pointer to next record
		$this->_pos += 8 + $length;

		$pos = 0;

		// offset: 0; size: 16; rgbUid1 (MD4 digest of)
		$rgbUid1 = substr($recordData, 0, 16);
		$pos += 16;

		// offset: 16; size: 16; rgbUid2 (MD4 digest), only if $recInstance = 0x46B or 0x6E3
		if (in_array($recInstance, array(0x046B, 0x06E3))) {
			$rgbUid2 = substr($recordData, 16, 16);
			$pos += 16;
		}

		// offset: var; size: 1; tag
		$tag = ord($recordData{$pos});
		$pos += 1;

		// offset: var; size: var; the raw image data
		$data = substr($recordData, $pos);

		$blip = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip();
		$blip->setData($data);

		$this->_object->setBlip($blip);
	}
353591
def retrieve_data_blob(self, txid):
        """"""
        rawtx = self.retrieve_tx(txid)
        return self.get_data_blob(rawtx)
66839
def _getImageSize(filename):
    """"""
    result = None
    file = open(filename, 'rb')
    if file.read(8) == b'\x89PNG\r\n\x1a\n': # PNG
        while 1:
            length, = _struct.unpack('>i', file.read(4))
            chunkID = file.read(4)
            if chunkID == '': # EOF
                break
            if chunkID == b'IHDR':
                # return width, height
                result = _struct.unpack('>ii', file.read(8))
                break
            file.seek(4 + length, 1)
        file.close()
        return result
    file.seek(0)
    if file.read(8) == b'BM': # Bitmap
        file.seek(18, 0) # skip to size data
        result = _struct.unpack('<ii', file.read(8))
    file.close()
    return result
713195
def select_visible_page_image(infiles, output_file, log, context):
    """"""

    options = context.get_options()
    if options.clean_final:
        image_suffix = '.pp-clean.png'
    elif options.deskew:
        image_suffix = '.pp-deskew.png'
    elif options.remove_background:
        image_suffix = '.pp-background.png'
    else:
        image_suffix = '.page.png'
    image = next(ii for ii in infiles if ii.endswith(image_suffix))

    pageinfo = get_pageinfo(image, context)
    if pageinfo.images and all(im.enc == 'jpeg' for im in pageinfo.images):
        log.debug(f'{page_number(image):4d}: JPEG input -> JPEG output')
        # If all images were JPEGs originally, produce a JPEG as output
        with Image.open(image) as im:
            # At this point the image should be a .png, but deskew, unpaper
            # might have removed the DPI information. In this case, fall back to
            # square DPI used to rasterize. When the preview image was
            # rasterized, it was also converted to square resolution, which is
            # what we want to give tesseract, so keep it square.
            fallback_dpi = get_page_square_dpi(pageinfo, options)
            dpi = im.info.get('dpi', (fallback_dpi, fallback_dpi))

            # Pillow requires integer DPI
            dpi = round(dpi[0]), round(dpi[1])
            im.save(output_file, format='JPEG', dpi=dpi)
    else:
        re_symlink(image, output_file, log)
225646
def get_qpimage_raw(self, idx=0):
        """"""
        # Load experimental data
        nf = np.load(str(self.path), mmap_mode="c", allow_pickle=False)
        meta_data = copy.copy(self.meta_data)
        qpi = qpimage.QPImage(data=nf,
                              which_data=self.storage_type,
                              meta_data=meta_data,
                              h5dtype=self.as_type)
        # get identifier
        qpi["identifier"] = self.get_identifier(idx)
        return qpi
1167146
def file_reader(self):
        """"""
        self.update_config()
        path = self.config['path']
        fourcc = self.metadata.get('fourcc')
        xlen, ylen = self.metadata.image_size()
        # set bits per pixel and component dimensions
        if fourcc in ('BGR[24]',):
            bpp = 24
            Y_shape = (ylen, xlen)
        elif fourcc in ('RGB[24]',):
            bpp = 24
            Y_shape = (ylen, xlen, 3)
        elif fourcc in ('IYU2',):
            bpp = 24
            Y_shape = (ylen, xlen, 1)
            UV_shape = (ylen, xlen)
        elif fourcc in ('UYVY', 'UYNV', 'Y422', 'HDYC', 'YVYU', 'YUYV',
                        'YV16', 'YUY2', 'YUNV', 'V422'):
            bpp = 16
            Y_shape = (ylen, xlen, 1)
            UV_shape = (ylen, xlen // 2)
        elif fourcc in ('IYUV', 'I420', 'YV12'):
            bpp = 12
            Y_shape = (ylen, xlen, 1)
            UV_shape = (ylen // 2, xlen // 2)
        elif fourcc in ('YVU9',):
            bpp = 9
            Y_shape = (ylen, xlen, 1)
            UV_shape = (ylen // 4, xlen // 4)
        else:
            self.logger.critical("Can't open %s files", fourcc)
            return
        bytes_per_frame = (xlen * ylen * bpp) // 8
        zlen = os.path.getsize(path) // bytes_per_frame
        if zlen < 1:
            self.logger.critical("Zero length file %s", path)
            return
        # set raw array slice parameters
        if fourcc in ('BGR[24]',):
            Y_slice = ((2, None, 3), (1, None, 3), (0, None, 3))
            UV_slice = None
        elif fourcc in ('RGB[24]',):
            Y_slice = ((0, None, 1),)
            UV_slice = None
        elif fourcc in ('IYU2',):
            Y_slice = ((1, None, 3),)
            UV_slice = ((0, None, 3), (2, None, 3))
        elif fourcc in ('UYVY', 'UYNV', 'Y422', 'HDYC'):
            # packed format, UYVY order
            Y_slice = ((1, None, 2),)
            UV_slice = ((0, None, 4), (2, None, 4))
        elif fourcc in ('YVYU',):
            # packed format, YVYU order
            Y_slice = ((0, None, 2),)
            UV_slice = ((3, None, 4), (1, None, 4))
        elif fourcc in ('YUYV', 'YUY2', 'YUNV', 'V422'):
            # packed format, YUYV order
            Y_slice = ((0, None, 2),)
            UV_slice = ((1, None, 4), (3, None, 4))
        elif fourcc in ('IYUV', 'I420'):
            # planar format, YUV order
            Y_size = xlen * ylen
            UV_size = UV_shape[0] * UV_shape[1]
            Y_slice = ((0,                Y_size,                 1),)
            UV_slice = ((Y_size,           Y_size + UV_size,       1),
                        (Y_size + UV_size, Y_size + (UV_size * 2), 1))
        elif fourcc in ('YV16', 'YV12', 'YVU9'):
            # planar format, YVU order
            Y_size = xlen * ylen
            UV_size = UV_shape[0] * UV_shape[1]
            Y_slice = ((0,                Y_size,                 1),)
            UV_slice = ((Y_size + UV_size, Y_size + (UV_size * 2), 1),
                        (Y_size,           Y_size + UV_size,       1))
        else:
            self.logger.critical("Can't open %s files", fourcc)
            return
        # set frame type
        if fourcc in ('BGR[24]', 'RGB[24]'):
            self.Y_type = 'RGB'
        else:
            self.Y_type = 'Y'
            self.UV_type = 'CbCr'
        file_frame = 0
        direction = 1
        with io.open(path, 'rb', 0) as raw_file:
            while True:
                self.update_config()
                if file_frame >= zlen:
                    if self.config['looping'] == 'off':
                        break
                    elif self.config['looping'] == 'repeat':
                        file_frame = 0
                        raw_file.seek(0)
                    else:
                        file_frame = zlen - 2
                        direction = -1
                elif file_frame < 0:
                    file_frame = 1
                    direction = 1
                if direction != 1:
                    raw_file.seek((direction - 1) * bytes_per_frame, io.SEEK_CUR)
                file_frame += direction
                raw_data = raw_file.read(bytes_per_frame)
                # convert to numpy arrays
                raw_array = numpy.frombuffer(raw_data, numpy.uint8)
                Y_data = []
                for start, end, step in Y_slice:
                    raw_data = raw_array[start:end:step]
                    Y_data.append(raw_data.reshape(Y_shape))
                if len(Y_data) > 1:
                    Y_data = numpy.dstack(Y_data)
                else:
                    Y_data = Y_data[0]
                if UV_slice:
                    UV_data = []
                    for start, end, step in UV_slice:
                        raw_data = raw_array[start:end:step]
                        UV_data.append(raw_data.reshape(UV_shape))
                    UV_data = numpy.dstack(UV_data)
                    # remove offset
                    UV_data = UV_data.astype(pt_float) - pt_float(128.0)
                else:
                    UV_data = None
                yield Y_data, UV_data
726826
def ReadTif(tifFile):
        """"""
        img = Image.open(tifFile)
        img = np.array(img)
        return img
1169379
def _parse_blob(self):
        """"""
        lineno = self.lineno
        mark = self._get_mark_if_any()
        data = self._get_data(b'blob')
        return commands.BlobCommand(mark, data, lineno)
1183319
def imread(img, color=None, dtype=None):
    '''
    
    '''
    COLOR2CV = {'gray': cv2.IMREAD_GRAYSCALE,
                'all': cv2.IMREAD_COLOR,
                None: cv2.IMREAD_ANYCOLOR
                }
    c = COLOR2CV[color]
    if callable(img):
        img = img()
    elif isinstance(img, string_types):
        #         from_file = True
        #         try:
        #             ftype = img[img.find('.'):]
        #             img = READERS[ftype](img)[0]
        #         except KeyError:
        # open with openCV
        # grey - 8 bit
        if dtype in (None, "noUint") or np.dtype(dtype) != np.uint8:
            c |= cv2.IMREAD_ANYDEPTH
        img2 = cv2.imread(img, c)
        if img2 is None:
            raise IOError("image '%s' is not existing" % img)
        img = img2

    elif color == 'gray' and img.ndim == 3:  # multi channel img like rgb
        # cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #cannot handle float64
        img = toGray(img)
    # transform array to uint8 array due to openCV restriction
    if dtype is not None:
        if isinstance(img, np.ndarray):
            img = _changeArrayDType(img, dtype, cutHigh=False)

    return img
225608
def read(self, size=None):
        """"""
        blob = self.s.read(size)
        if size is not None and len(blob) < size:
            raise EOFError
        if self._captured:
            self._captured.write(blob)
        return blob
274267
def _get_blob(self):
        """"""
        if not self.__blob:
            self.__blob = self.repo.get_object(self.id)
        return self.__blob
802068
def get_data_blob(self, rawtx):
        """"""
        tx = deserialize.tx(rawtx)
        data = control.get_data_blob(tx)
        return serialize.data(data)
179434
def is_valid_image(self, raw_data):
        '''
        
        '''

        try:
            Image(blob=raw_data)
            return True
        except (exceptions.CorruptImageError, exceptions.MissingDelegateError):
            return False
80403
def read_from_blobs_file(entry)
      begin
        raw = File.read(@blobs_file_name, entry[BYTES], entry[START])
      rescue => e
        PEROBS.log.fatal "Cannot read blobs file #{@blobs_file_name}: " +
          e.message
      end
      if Zlib.crc32(raw, 0) != entry[CRC]
        PEROBS.log.fatal "BTreeBlob for object #{entry[ID]} has been " +
          "corrupted: Checksum mismatch"
      end

      raw
    end
24046
def parse_buffer_to_ppm(data):
    

    images = []

    index = 0

    while index < len(data):
        code, size, rgb = tuple(data[index:index + 40].split(b'\n')[0:3])
        size_x, size_y = tuple(size.split(b' '))
        file_size = len(code) + len(size) + len(rgb) + 3 + int(size_x) * int(size_y) * 3
        images.append(Image.open(BytesIO(data[index:index + file_size])))
        index += file_size

    return images
194021
def image_query_record(self, imagename=None):
        """"""

        if imagename:
            with get_image_conn() as conn:
                result = conn.execute("SELECT * FROM image WHERE "
                                      "imagename=?", (imagename,))
                image_list = result.fetchall()
            if not image_list:
                obj_desc = "Image with name: %s" % imagename
                raise exception.SDKObjectNotExistError(obj_desc=obj_desc,
                                                   modID=self._module_id)
        else:
            with get_image_conn() as conn:
                result = conn.execute("SELECT * FROM image")
                image_list = result.fetchall()

        # Map each image record to be a dict, with the key is the field name in
        # image DB
        image_keys_list = ['imagename', 'imageosdistro', 'md5sum',
                      'disk_size_units', 'image_size_in_bytes', 'type',
                      'comments']

        image_result = []
        for item in image_list:
            image_item = dict(zip(image_keys_list, item))
            image_result.append(image_item)
        return image_result
816766
def read_data(label, image):
    
    base_url = 'http://yann.lecun.com/exdb/mnist/'
    with gzip.open(download_file(base_url+label, os.path.join('data',label))) as flbl:
        magic, num = struct.unpack(">II", flbl.read(8))
        label = np.fromstring(flbl.read(), dtype=np.int8)
    with gzip.open(download_file(base_url+image, os.path.join('data',image)), 'rb') as fimg:
        magic, num, rows, cols = struct.unpack(">IIII", fimg.read(16))
        image = np.fromstring(fimg.read(), dtype=np.uint8).reshape(len(label), rows, cols)
    return (label, image)