Python CFFI bindings for image format libraries
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

53 lignes
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)