gotomypc / leptonica

Automatically exported from code.google.com/p/leptonica
0 stars 0 forks source link

Use jpeg_mem_src/jpeg_mem_dst instead of save to tempfile hack #83

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently pixReadMemJpeg and pixWriteMemJpeg fails on windows due to /tmp/... 
not being a valid path and fmemopen not existing. However there isn't much 
reason for that hack anymore anyways as we could just use jpeg_mem_src and 
jpeg_mem_dst (at least when using libjpeg 8 or newer).

Original issue reported on code.google.com by poiza...@gmail.com on 18 Sep 2013 at 1:02

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
In 1.70 (which should come out RSN -- I keep saying that), we're using

    fp = tmpfile();
    fwrite(cdata, 1, size, fp);

This has two advantages over the 1.69 implementation: it works on Windows and 
it's secure against hacking where someone is able to guess the filename.

I agree it would be nicer not to have to write to a file, and when jpeglib8 has 
attained widespread adoption it would make sense to require it.  I see that 
people are still having issues with detecting availability of these functions 
using config files; e.g.,
   http://comments.gmane.org/gmane.comp.kde.devel.graphics/307

So let's consider this resolved for now.  You can put those lines in to patch 
for pixReadMemJpeg().  Here's the code to patch pixWriteMemJpeg():

    fp = tmpfile();
    ret = pixWriteStreamJpeg(fp, pix, quality, progressive);
    rewind(fp);
    *pdata = l_binaryReadStream(fp, psize);

~          

Original comment by dan.bloo...@gmail.com on 21 Sep 2013 at 1:22

GoogleCodeExporter commented 9 years ago
Could we add a HAS_JPEG_MEMIO config or something like that so we could enable 
it manually even if we can't detect the availability? I can create a patch if 
interested.

Original comment by poiza...@gmail.com on 24 Sep 2013 at 11:20

GoogleCodeExporter commented 9 years ago
Let's not.  I believe these mem functions are in version 9, which I've never 
even tried.  And as I said before, I want to limit the amount of #if 
configuration code because it becomes a real headache to support even on one 
platform, let alone on several.  Generality is nice, but robustness is 
mandatory.

Original comment by dan.bloo...@gmail.com on 4 Oct 2013 at 9:51

GoogleCodeExporter commented 9 years ago
The mem functions were introduced in version 8 according to the changelog which 
was released back in january 2010.

Original comment by poiza...@gmail.com on 7 Oct 2013 at 12:28

GoogleCodeExporter commented 9 years ago
1.70 is out.  The temp file issue should be resolved on windows.  Not 
proceeding further on the memio config change that you proposed.  If you want 
to give me a patch, we can consider it for a future release.

You can get 1.70 at leptonica.org/download.html.

Original comment by dan.bloo...@gmail.com on 23 Jan 2014 at 8:58