Archived

This topic is now archived and is closed to further replies.

Loading and Saving JPEG files in Visual C++?

This topic is 5962 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there! Can anyone give me the code for loading and saving JPEG files in a Visual C++ SID program? I know there''s some libraries out there, but most of them ain''t focused and there''s no documentation on how to INTEGRATE it into your own program. Thanks a lot!!!

Share this post


Link to post
Share on other sites
jpgs are a nasty combination of RLE runs, DCT (Discrete Cosine Transform) compression, and god knows what else (there are various different types) - if you cant figure out how to use the libraries and you cant roll your own given the info in The Programmers File Format Reference then you are probably better off using simpler formats like bmp, pcx, ppm, tga etc.

Share this post


Link to post
Share on other sites
Use the "Intel Jpeg Library" to load JPEG files. It could be found at the Intel homepage. (www.intel.com)

It easy to use and extreme fast!
Here some code to load in a jpg-File with this library:


typedef struct
{
char byFilename[256]; // The filename of the texture
BYTE *pbyData; // The texture data
int iColorDepth; // Color depth
int iWidth, iHeight; // The size of the texture
int iID; // The ID
GLuint iOpenGLID; // The OpenGL ID
int iUsed; // How often is this texture used?

} AS_TEXTURE;


BOOL ASLoadJpegRGB(AS_TEXTURE *texture, char* fileName)
{ // begin ASLoadJpegRGB()
JPEG_CORE_PROPERTIES jcProps;

memset(&jcProps, 0, sizeof(JPEG_CORE_PROPERTIES));
ijlInit(&jcProps);
jcProps.JPGFile = fileName;
ijlRead(&jcProps, IJL_JFILE_READPARAMS);
texture->iWidth = jcProps.JPGWidth;
texture->iHeight = jcProps.JPGHeight;
texture->pbyData = (BYTE *) malloc(sizeof(BYTE)*texture->iWidth*texture->iHeight*3);
jcProps.DIBWidth = jcProps.JPGWidth;
jcProps.DIBHeight = jcProps.JPGHeight;
jcProps.DIBChannels = 3;
jcProps.DIBColor = IJL_RGB;
jcProps.DIBPadBytes = 0;
jcProps.DIBBytes = (BYTE *) texture->pbyData;
jcProps.JPGColor = IJL_YCBCR;
if(ijlRead(&jcProps, IJL_JFILE_READWHOLEIMAGE) != IJL_OK)
return 1;
ijlFree(&jcProps);
return 0;
} // end ASLoadJpegRGB()

Share this post


Link to post
Share on other sites