Esempio n. 1
0
def loadimage(fileref, isSlide = True):
    
    # I know usually in Python you don't verify types but this will help detect problems during the current refactor.
    if not isinstance(fileref, FilePath):
        raise Exception("fileref must be a FilePath object")
    
    try:
        #Tmpsurface to hold loaded image
        tmpsurface = None
        #If uncompressed
        if fileref.getArchiveName() == None:
            
            if fileref.arePathsAbsolute():
                filepath = fileref.getFileName()
            elif isSlide:
                filepath = filemanager.find_slide(fileref.getFileName())
            else:
                filepath = filemanager.find_image(fileref.getFileName())
            
            if fileref.getEncryption() == 0:
                #if not encrypted, load the image and return it
                tmpsurface = GLTexture(filepath)
            else:
                #If encrypted, decrypt it, and load it
                # FIXME: in new versions of Python, data should NOT be stored in a string
                tmpfile = file(filepath,'rb')
                data = tmpfile.read()
                data2=crypto.decrypt(data)
                data_io = StringIO(data2)
                tmpsurface = GLTexture(data_io, fileref.getFileName())
        else:
            #If compressed load the file from the zipfile
            
            if fileref.arePathsAbsolute():
                filepath = fileref.getArchiveName()
            elif isSlide:
                filepath = filemanager.find_slide(fileref.getArchiveName())
            else:
                filepath = filemanager.find_image(fileref.getArchiveName())
                
            data = zipfile.ZipFile(filepath).read(fileref.getFileName())
            if fileref.getEncryption() == 0:
                #if not encrypted, read image into string
                data_io = StringIO(data)
            else:
                #If encrypted, decrypt it, read image into string
                # FIXME: in new versions of python, data should NOT be stored in a string
                data2=crypto.decrypt(data)
                data_io = StringIO(data2)
            #Create image from data
            tmpsurface = GLTexture(data_io, fileref.getFileName())
        #return the image
        return tmpsurface
    except:
        print "Error while loading image <%s>!" % fileref.getFileName()
        raise
Esempio n. 2
0
 def getFullFilePath(self, texid=0):
     if self._datfile is None:
         return (filemanager.find_slide(self._file[texid]), None, self._encrypted[texid])
     else:
         return (self._file[texid], filemanager.find_slide(self._datfile[texid]), self._encrypted[texid])