3

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?

Tom
  • 663
  • 5
  • 19
  • Recompiling the library using MS VC++ Express edition took less than a minute. Is that not acceptable for you. – Sinan Ünür Nov 03 '10 at 22:41
  • it might have to be... However, I recompiled it and that gave me linker errors to the tune of MSVCRT.lib(MSVCR100.dll) : error LNK2005: _sprintf already defined in LIBCMT.lib(sprintf.obj). Ideally, I just want to be able to use jpeg_mem_src instead of jpeg_stdio_src, which should be more cross-platform. I'd rather not have to remember(or have anyone have to figure out in the future) a stipulation of what C library my jpeg library needs to be compiled against =/. – Tom Nov 04 '10 at 17:39
  • the linker errors came when I tried to compile my project, btw. Side note: I'm using scons with cl.exe as the compiler. – Tom Nov 04 '10 at 17:40

5 Answers5

2

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

1

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.

Sid
  • 1,239
  • 2
  • 13
  • 36
1

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.

hookenz
  • 36,432
  • 45
  • 177
  • 286
1

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
1

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.

noah.c
  • 11
  • 2