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')
评论列表
文章目录