def __init__(self, parent):
        """Initialize instance and read first TiffPage from file.

        If parent is a TiffFile, the file position must be at an offset to an
        offset to a TiffPage. If parent is a TiffPage, page offsets are read
        from the SubIFDs tag.

        """
        self.parent = None
        self.pages = []  # cache of TiffPages, TiffFrames, or their offsets
        self._indexed = False  # True if offsets to all pages were read
        self._cached = False  # True if all pages were read into cache
        self._tiffpage = TiffPage  # class used for reading pages
        self._keyframe = None  # current page that is used as keyframe
        self._cache = False  # do not cache frames or pages (if not keyframe)
        self._nextpageoffset = None

        if isinstance(parent, TiffFile):
            # read offset to first page from current file position
            self.parent = parent
            fh = parent.filehandle
            self._nextpageoffset = fh.tell()
            offset = struct.unpack(parent.tiff.ifdoffsetformat,
                                   fh.read(parent.tiff.ifdoffsetsize))[0]
        elif 'SubIFDs' not in parent.tags:
            self._indexed = True
            return
        else:
            # use offsets from SubIFDs tag
            self.parent = parent.parent
            fh = self.parent.filehandle
            offsets = parent.tags['SubIFDs'].value
            offset = offsets[0]

        if offset == 0:
            log.warning('TiffPages: file contains no pages')
            self._indexed = True
            return
        if offset >= fh.size:
            log.warning('TiffPages: invalid page offset (%i)', offset)
            self._indexed = True
            return

        # read and cache first page
        fh.seek(offset)
        page = TiffPage(self.parent, index=0)
        self.pages.append(page)
        self._keyframe = page
        if self._nextpageoffset is None:
            # offsets from SubIFDs tag
            self.pages.extend(offsets[1:])
            self._indexed = True
            self._cached = True
def __init__ ( self , parent ) : self . parent = None self . pages = [ ] self . _indexed = False self . _cached = False self . _tiffpage = TiffPage self . _keyframe = None self . _cache = False self . _nextpageoffset = None if isinstance ( parent , TiffFile ) : self . parent = parent fh = parent . filehandle self . _nextpageoffset = fh . tell ( ) offset = struct . unpack ( parent . tiff . ifdoffsetformat , fh . read ( parent . tiff . ifdoffsetsize ) ) [ 0 ] elif 'SubIFDs' not in parent . tags : self . _indexed = True return else : self . parent = parent . parent fh = self . parent . filehandle offsets = parent . tags [ 'SubIFDs' ] . value offset = offsets [ 0 ] if offset == 0 : log . warning ( 'TiffPages: file contains no pages' ) self . _indexed = True return if offset >= fh . size : log . warning ( 'TiffPages: invalid page offset (%i)' , offset ) self . _indexed = True return fh . seek ( offset ) page = TiffPage ( self . parent , index = 0 ) self . pages . append ( page ) self . _keyframe = page if self . _nextpageoffset is None : self . pages . extend ( offsets [ 1 : ] ) self . _indexed = True self . _cached = True
Initialize instance and read first TiffPage from file.

        If parent is a TiffFile, the file position must be at an offset to an
        offset to a TiffPage. If parent is a TiffPage, page offsets are read
        from the SubIFDs tag.