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.

54 lines
1.2KB

  1. #!/usr/bin/env python3
  2. # libwebp cffi bindings
  3. # (c) 2017 Taeyeon Mori
  4. import os
  5. import cffi
  6. from simplecpp import simple_cpp
  7. # --------------------------------------------------------------
  8. # libwebp headers
  9. webp_headers = [os.path.join("lib_headers/webp", hdr_name) for hdr_name in
  10. ("types.h", "decode.h", "encode.h", "mux_types.h", "mux.h", "demux.h")]
  11. # --------------------------------------------------------------
  12. # C Code
  13. header = """
  14. """
  15. source = """
  16. #include <Python.h>
  17. #include <webp/decode.h>
  18. #include <webp/encode.h>
  19. #include <webp/mux.h>
  20. #include <webp/demux.h>
  21. """
  22. # --------------------------------------------------------------
  23. # Initialize CFFI
  24. libwebp = cffi.FFI()
  25. libwebp.cdef(header)
  26. libwebp.set_source("imglibs._libwebp", source, libraries=["webp", "webpmux", "webpdemux"])
  27. # --------------------------------------------------------------
  28. # Import libwebp symbols
  29. defs = {"CFFI": True}
  30. for header in webp_headers:
  31. print(header)
  32. with open(header, "r") as f:
  33. content = "".join(simple_cpp(f, defs))
  34. libwebp.cdef(content)
  35. # --------------------------------------------------------------
  36. # Build
  37. if __name__ == "__main__":
  38. libwebp.compile(verbose=True)