Python CFFI bindings for image format libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

53 rivejä
1.2 KiB

#!/usr/bin/env python3
# libwebp cffi bindings
# (c) 2017 Taeyeon Mori
import os
import cffi
from simplecpp import simple_cpp
# --------------------------------------------------------------
# libwebp headers
webp_headers = [os.path.join("lib_headers/webp", hdr_name) for hdr_name in
("types.h", "decode.h", "encode.h", "mux_types.h", "mux.h", "demux.h")]
# --------------------------------------------------------------
# C Code
header = """
"""
source = """
#include <Python.h>
#include <webp/decode.h>
#include <webp/encode.h>
#include <webp/mux.h>
#include <webp/demux.h>
"""
# --------------------------------------------------------------
# Initialize CFFI
libwebp = cffi.FFI()
libwebp.cdef(header)
libwebp.set_source("imglibs._libwebp", source, libraries=["webp", "webpmux", "webpdemux"])
# --------------------------------------------------------------
# Import libwebp symbols
defs = {"CFFI": True}
for header in webp_headers:
print(header)
with open(header, "r") as f:
content = "".join(simple_cpp(f, defs))
libwebp.cdef(content)
# --------------------------------------------------------------
# Build
if __name__ == "__main__":
libwebp.compile(verbose=True)