From 411981efbcba27175dbc928f5ce528e959782ce0 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Sat, 30 Jan 2016 15:06:25 -0800 Subject: [PATCH] Experiment with CFFI instead of ctypes --- ocrmypdf/lept.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 ocrmypdf/lept.py diff --git a/ocrmypdf/lept.py b/ocrmypdf/lept.py new file mode 100644 index 00000000..ed8e6295 --- /dev/null +++ b/ocrmypdf/lept.py @@ -0,0 +1,58 @@ +from cffi import FFI + +ffi = FFI() +ffi.set_source("_leptonica", None) +ffi.cdef(""" +typedef signed char l_int8; +typedef unsigned char l_uint8; +typedef short l_int16; +typedef unsigned short l_uint16; +typedef int l_int32; +typedef unsigned int l_uint32; +typedef float l_float32; +typedef double l_float64; +typedef long long l_int64; +typedef unsigned long long l_uint64; + +struct Pix +{ + l_uint32 w; /* width in pixels */ + l_uint32 h; /* height in pixels */ + l_uint32 d; /* depth in bits (bpp) */ + l_uint32 spp; /* number of samples per pixel */ + l_uint32 wpl; /* 32-bit words/line */ + l_uint32 refcount; /* reference count (1 if no clones) */ + l_int32 xres; /* image res (ppi) in x direction */ + /* (use 0 if unknown) */ + l_int32 yres; /* image res (ppi) in y direction */ + /* (use 0 if unknown) */ + l_int32 informat; /* input file format, IFF_* */ + l_int32 special; /* special instructions for I/O, etc */ + char *text; /* text string associated with pix */ + struct PixColormap *colormap; /* colormap (may be null) */ + l_uint32 *data; /* the image data */ +}; +typedef struct Pix PIX; + +struct PixColormap +{ + void *array; /* colormap table (array of RGBA_QUAD) */ + l_int32 depth; /* of pix (1, 2, 4 or 8 bpp) */ + l_int32 nalloc; /* number of color entries allocated */ + l_int32 n; /* number of color entries used */ +}; +typedef struct PixColormap PIXCMAP; +""") + +ffi.cdef(""" +PIX * pixRead ( const char *filename ); +PIX * pixScale ( PIX *pixs, l_float32 scalex, l_float32 scaley ); +l_int32 pixFindSkew ( PIX *pixs, l_float32 *pangle, l_float32 *pconf ); +l_int32 pixWriteImpliedFormat ( const char *filename, PIX *pix, l_int32 quality, l_int32 progressive ); +void pixDestroy ( PIX **ppix ); +PIX * pixDeskew ( PIX *pixs, l_int32 redsearch ); +char * getLeptonicaVersion ( ); +""") + +if __name__ == '__main__': + ffi.compile()