English 中文(简体)
alternatives to jpeg_read_header libjpeg
原标题:

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?

问题回答

Sompe people report a workaround for the issue with linking against msvcrt in newer visual studio s. Found by googling msvcrt.dll "visual studio"

One of the "other ways to feed data" is these functions:

  1. jpeg_CreateDecompress
  2. jpeg_read_header
  3. jpeg_start_decompress
  4. jpeg_read_raw_data / jpeg_read_scanlines
  5. jpeg_destroy_decompress

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.

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.

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.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签