_freeimage.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:PYEdit 作者: Congren 项目源码 文件源码
def __init__(self):

        # Initialize freeimage lib as None
        self._lib = None

        # A lock to create thread-safety
        self._lock = threading.RLock()

        # Init log messages lists
        self._messages = []

        # Select functype for error handler
        if sys.platform.startswith('win'): 
            functype = ctypes.WINFUNCTYPE
        else: 
            functype = ctypes.CFUNCTYPE

        # Create output message handler
        @functype(None, ctypes.c_int, ctypes.c_char_p)
        def error_handler(fif, message):
            message = message.decode('utf-8')
            self._messages.append(message)
            while (len(self._messages)) > 256:
                self._messages.pop(0)

        # Make sure to keep a ref to function
        self._error_handler = error_handler

        # Load library and register API
        success = False
        try:
            # Try without forcing a download, but giving preference
            # to the imageio-provided lib (if previously downloaded)
            self._load_freeimage()
            self._register_api()
            if self._lib.FreeImage_GetVersion().decode('utf-8') >= '3.15':
                success = True
        except OSError:
            pass

        if not success:
            # Ensure we have our own lib, try again
            get_freeimage_lib()
            self._load_freeimage()
            self._register_api()

        # Wrap up
        self._lib.FreeImage_SetOutputMessage(self._error_handler)
        self._lib_version = self._lib.FreeImage_GetVersion().decode('utf-8')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号