问题
So I'm running into an issue using libjpeg on Windows which causes jpeg_read_header() to crash.
The problem is (fairly hilariously) described here: http://sourceforge.net/projects/gnuwin32/forums/forum/74807/topic/1629371?message=4053776
I've decided on the 3rd option, which is not using jpeg_stdio_src/dest APIs. However, after much googling, I can't seem to find the 'other ways to feed data into libjpeg' mentioned at the end of the post, can anyone point me to the right place?
回答1:
Sompe people report a workaround for the issue with linking against msvcrt in newer visual studio's. Found by googling msvcrt.dll "visual studio"
回答2:
One of the "other ways to feed data" is these functions:
- jpeg_CreateDecompress
- jpeg_read_header
- jpeg_start_decompress
- jpeg_read_raw_data / jpeg_read_scanlines
- jpeg_destroy_decompress
回答3:
If I understand the problem correctly it's because of the differences between all the various file handles in windows. They are not all compatible with each other.
Would this link be of help? it tells you how to convert between them all. You can then provide the correct kind of file handle to the function and get it running.
http://www.codeproject.com/KB/files/handles.aspx
Alternatively, don't use that jpeg library and use another. There are none I can specifically recommend as I haven't had a need to use a jpeg library before.
回答4:
I had a similar issue and came across this post when looking for solutions. Ultimately, I just messed around with the code because it was crucial for me to read directly from file. To fix, I did the following:
// Declare needed structs
struct jpeg_decompress_struct dinfo;
struct jpeg_error_mgr jerr;
// Open file
FILE * infile = fopen("myimage.jpg", "rw");
// Create error manager instance
dinfo.err = jpeg_std_error(&jerr);
// Decompression process
jpeg_create_decompress(&dinfo);
jpeg_stdio_src(&dinfo, infile);
jpeg_read_header(&dinfo, TRUE);
// ... remainder of program
The two functions work fine and as expected after doing this... I'm not sure why this fixed my issue, but I'll take it. Hope this helps someone else.
回答5:
I ran into the same problem recently with libjppeg-turbo. I did not want to recompile the library or link mscvr.dll to my vs2015 app.
This function worked for me: jpeg_mem_src(...)
instead of using jpeg_stdio_src
. Since it doesn't pass any C runtime structures to the library, it works just fine. The function definition can be found here link
It gets the input data from a memory buffer instead of a file, which works if your file isn't too big/memory isn't too much of a concern.
来源:https://stackoverflow.com/questions/4092251/alternatives-to-jpeg-read-header-libjpeg