DanBloomberg / leptonica

Leptonica is an open source library containing software that is broadly useful for image processing and image analysis applications. The official github repository for Leptonica is: danbloomberg/leptonica. See leptonica.org for more documentation.
Other
1.79k stars 392 forks source link

Read image from bytes array on Windows #557

Closed z-pc closed 3 years ago

z-pc commented 3 years ago

This is not issue, I'm using tesseract. On Windows, I trying read image from bytes array that I extracted from PDF file, pass to "pixReadMem(...)", some warning about leptonica write it to a temp file.

work-around: writing to a temp file

I'm interested in performance, looks like this will reduce its, only on Linux was supported "HAVE_FMEMOPEN". Will Windows be supported for this in the near future?

OS: Windows Compiler: MVC++ 14

Forgive me if this isn't where to discuss this, I can't find the user group

z-pc commented 3 years ago

In "pixReadStreamJpeg(...)", why we did not use "jpeg_mem_src(...)" to read directly from buffer data instead of from FILE ?

DanBloomberg commented 3 years ago

We have to support all platforms, so writing to a temp file is a fallback when you don't have functions like fmemopen() that redirect to a buffer.

As for jpeg_mem_src(), this was added in jpeg-8 about 4 years ago. We can't assume that users have that version (or later) of lthe jpeg library. Maybe in a few years ...

Another option is to write the code to handle the buffers, as T. D. Hintz did for png. This is a significant job to get right, even though there are existing implementations, and it's not a high priority right now.

In any event, I know it is not ideal to use a temp file, but it doesn't cause a big hit to performance because the compression and decompression takes much longer than writing and reading bytes to file.

z-pc commented 3 years ago

Yeppp, I tried changes that read from buffer, performance is not significantly reduced, at least with jpg, about 10% for "pixReadMem (...)". Thanks for responds