SDL_image, JPeg, JSDL problem

I hope someone can help. I am trying to us JSDL (Java for SDL) and am hung up on only one thing: Loading JPG images (actually any image type fails using SDL_image.). The JNI code runs fine. The JNI code in turn calls SDL_image’s SDL_Load function with the name of a JPG image. The image and DLLs are definitely located in the correct places.

Using the SDL_image DLL that I’ve built myself, java reports and UnsatisfiedLinkError while loading SDL_image.dll.

While tracking it down, I’ve added debug code to SDL_image and can pinpoint the exact line where the failure occurs, but I cannot figure out how to solve the problem. By the way, I wrote a simple C++ application that uses the exact same DLLs and images and that code loads the JPG image just fine. So the problem seems to me to be somewhere in the interface between the JNI code and the C++ code.

Here is where the failure occurs… This code is in SDL_image’s IMP_jpg.c file:

SDL_Surface *IMG_LoadJPG_RW(SDL_RWops *src)
{
struct jpeg_decompress_struct cinfo;
JSAMPROW rowptr[1];
SDL_Surface *volatile surface = NULL;
struct my_error_mgr jerr;

 // PROBLEM OCCURS HERE.  If I return NULL at this point and comment out the rest of this function
 //  Then the DLL loads just fine (but then I get a NULL surface of course.)
 //


/* Create a decompression structure and load the JPEG header */

cinfo.err = jpeg_std_error(&jerr.errmgr);
jerr.errmgr.error_exit = my_error_exit;
jerr.errmgr.output_message = output_no_message;
if(setjmp(jerr.escape)) {
/* If we get here, libjpeg found an error */
jpeg_destroy_decompress(&cinfo);
IMG_SetError(“JPEG loading error”);
SDL_FreeSurface(surface);
return NULL;
}

jpeg_create_decompress(&cinfo);
jpeg_SDL_RW_src(&cinfo, src);
jpeg_read_header(&cinfo, TRUE);

/* Set 24-bit RGB output */
cinfo.out_color_space = JCS_RGB;
cinfo.quantize_colors = FALSE;
#ifdef FAST_JPEG
cinfo.scale_num = 1;
cinfo.scale_denom = 1;
cinfo.dct_method = JDCT_FASTEST;
cinfo.do_fancy_upsampling = FALSE;
#endif
jpeg_calc_output_dimensions(&cinfo);

/* Allocate an output surface to hold the image */
surface = SDL_AllocSurface(SDL_SWSURFACE,
cinfo.output_width, cinfo.output_height, 24,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x0000FF, 0x00FF00, 0xFF0000,
#else
0xFF0000, 0x00FF00, 0x0000FF,
#endif
0);
if ( surface == NULL ) {
IMG_SetError(“Out of memory”);
goto done;
}

/* Decompress the image */
jpeg_start_decompress(&cinfo);
while ( cinfo.output_scanline < cinfo.output_height ) {
rowptr[0] = (JSAMPROW)(Uint8 *)surface->pixels +
cinfo.output_scanline * surface->pitch;
jpeg_read_scanlines(&cinfo, rowptr, (JDIMENSION) 1);
}
jpeg_finish_decompress(&cinfo);

/* Clean up and return */
done:
jpeg_destroy_decompress(&cinfo);
return(surface);
}

One final note: I have tried DLLs that others have created. Some of them loaded just fine but did not return a proper surface made from the JPG image. I’ve also tried loading other image types such as PNG and BMP without success.

I am using MS VC++ 5 on Windows 2000.

Please help! Thanks!

Warren Schwader (aspiring SDL author.)