bmp->jpg
//now, use intel jpeg library.
BOOL CImageJpeg::LoadFile(const char *filename)
{
//Use the IJL to load up the jpeg
JPEG_CORE_PROPERTIES image;
memset(&image, 0, sizeof(image));
//Init the IJL
if (ijlInit(&image) != IJL_OK)
{
TRACE(_T("Cannot initialize Intel JPEG library!\n"));
return FALSE;
}
//Read in the Jpeg file parameters
image.JPGFile = filename;
if (ijlRead(&image, IJL_JFILE_READPARAMS) != IJL_OK)
{
TRACE(_T("Cannot read JPEG file header from %s file!\n"), image.JPGFile);
ijlFree(&image);
return FALSE;
}
// Set the JPG color space ... this will always be
// somewhat of an educated guess at best because JPEG
// is "color blind" (i.e., nothing in the bit stream
// tells you what color space the data was encoded from).
// However, in this example we assume that we are
// reading JFIF files which means that 3 channel images
// are in the YCbCr color space and 1 channel images are
// in the Y color space.
switch(image.JPGChannels)
{
case 1:
image.JPGColor = IJL_G;
image.DIBColor = IJL_BGR;
image.DIBChannels = 3;
break;
case 3:
image.JPGColor = IJL_YCBCR;
image.DIBColor = IJL_BGR;
image.DIBChannels = 3;
break;
case 4:
image.JPGColor = IJL_YCBCRA_FPX;
image.DIBColor = IJL_RGBA_FPX;
image.DIBChannels = 3;
default:
// This catches everything else, but no
// color twist will be performed by the IJL.
image.JPGColor = IJL_OTHER;
image.DIBColor = IJL_OTHER;
image.DIBChannels = 3; //image.JPGChannels;
break;
}
//Allocate memory for the image
DWORD dwImageSize = image.JPGWidth * image.JPGHeight * image.DIBChannels;
BYTE* pImageData = new BYTE[dwImageSize];
if(pImageData == NULL){
ijlFree(&image);
return FALSE;
}
//Call the IJL to load the Jpeg from file
image.DIBWidth = image.JPGWidth;
image.DIBHeight = image.JPGHeight;
image.DIBPadBytes = 0;
image.DIBBytes = pImageData;