Exemple #1
0
ILboolean iLoadJpegInternal(ILstring FileName, ILvoid *Lump, ILuint Size)

{

    JPEG_CORE_PROPERTIES Image;



	if (iCurImage == NULL) {

		ilSetError(IL_ILLEGAL_OPERATION);

		return IL_FALSE;

	}



	if (ijlInit(&Image) != IJL_OK) {

		ilSetError(IL_LIB_JPEG_ERROR);

		return IL_FALSE;

	}



	if (FileName != NULL) {

		Image.JPGFile = FileName;

		if (ijlRead(&Image, IJL_JFILE_READPARAMS) != IJL_OK) {

			ilSetError(IL_LIB_JPEG_ERROR);

			return IL_FALSE;

		}

	}

	else {

		Image.JPGBytes = Lump;

		Image.JPGSizeBytes = Size > 0 ? Size : UINT_MAX;

		if (ijlRead(&Image, IJL_JBUFF_READPARAMS) != IJL_OK) {

			ilSetError(IL_LIB_JPEG_ERROR);

			return IL_FALSE;

		}

	}



	switch (Image.JPGChannels)

	{

		case 1:

			Image.JPGColor		= IJL_G;

			Image.DIBChannels	= 1;

			Image.DIBColor		= IJL_G;

			iCurImage->Format	= IL_LUMINANCE;

			break;



		case 3:

			Image.JPGColor		= IJL_YCBCR;

			Image.DIBChannels	= 3;

			Image.DIBColor		= IJL_RGB;

			iCurImage->Format	= IL_RGB;

			break;



        case 4:

			Image.JPGColor		= IJL_YCBCRA_FPX;

			Image.DIBChannels	= 4;

			Image.DIBColor		= IJL_RGBA_FPX;

			iCurImage->Format	= IL_RGBA;

			break;



        default:

			// This catches everything else, but no

			// color twist will be performed by the IJL.

			/*Image.DIBColor = (IJL_COLOR)IJL_OTHER;

			Image.JPGColor = (IJL_COLOR)IJL_OTHER;

			Image.DIBChannels = Image.JPGChannels;

			break;*/

			ijlFree(&Image);

			ilSetError(IL_LIB_JPEG_ERROR);

			return IL_FALSE;

	}



	if (!ilTexImage(Image.JPGWidth, Image.JPGHeight, 1, (ILubyte)Image.DIBChannels, iCurImage->Format, IL_UNSIGNED_BYTE, NULL)) {

		ijlFree(&Image);

		return IL_FALSE;

	}

	iCurImage->Origin = IL_ORIGIN_UPPER_LEFT;



	Image.DIBWidth		= Image.JPGWidth;

	Image.DIBHeight		= Image.JPGHeight;

	Image.DIBPadBytes	= 0;

	Image.DIBBytes		= iCurImage->Data;



	if (FileName != NULL) {

		if (ijlRead(&Image, IJL_JFILE_READWHOLEIMAGE) != IJL_OK) {

			ijlFree(&Image);

			ilSetError(IL_LIB_JPEG_ERROR);

			return IL_FALSE;

		}

	}

	else {

		if (ijlRead(&Image, IJL_JBUFF_READWHOLEIMAGE) != IJL_OK) {

			ijlFree(&Image);

			ilSetError(IL_LIB_JPEG_ERROR);

			return IL_FALSE;

		}

	}



	ijlFree(&Image);

	ilFixImage();



	return IL_TRUE;

}
Exemple #2
0
ILboolean iSaveJpegInternal(ILstring FileName, ILvoid *Lump, ILuint Size)

{

	JPEG_CORE_PROPERTIES	Image;

	ILuint	Quality;

	ILimage	*TempImage;

	ILubyte	*TempData;



	imemclear(&Image, sizeof(JPEG_CORE_PROPERTIES));



	if (iCurImage == NULL) {

		ilSetError(IL_ILLEGAL_OPERATION);

		return IL_FALSE;

	}

	if (FileName == NULL && Lump == NULL) {

		ilSetError(IL_INVALID_PARAM);

		return IL_FALSE;

	}



	if (iGetHint(IL_COMPRESSION_HINT) == IL_USE_COMPRESSION)

		Quality = 85;  // Not sure how low we should dare go...

	else

		Quality = 99;



	if (ijlInit(&Image) != IJL_OK) {

		ilSetError(IL_LIB_JPEG_ERROR);

		return IL_FALSE;

	}



	if ((iCurImage->Format != IL_RGB && iCurImage->Format != IL_RGBA && iCurImage->Format != IL_LUMINANCE)

		|| iCurImage->Bpc != 1) {

		if (iCurImage->Format == IL_BGRA)

			Temp = iConvertImage(iCurImage, IL_RGBA, IL_UNSIGNED_BYTE);

		else

			Temp = iConvertImage(iCurImage, IL_RGB, IL_UNSIGNED_BYTE);

		if (Temp == NULL) {

			return IL_FALSE;

		}

	}

	else {

		Temp = iCurImage;

	}



	if (TempImage->Origin == IL_ORIGIN_LOWER_LEFT) {

		TempData = iGetFlipped(TempImage);

		if (TempData == NULL) {

			if (TempImage != iCurImage)

				ilCloseImage(TempImage);

			return IL_FALSE;

		}

	}

	else {

		TempData = TempImage->Data;

	}



	// Setup DIB

	Image.DIBWidth		= TempImage->Width;

	Image.DIBHeight		= TempImage->Height;

	Image.DIBChannels	= TempImage->Bpp;

	Image.DIBBytes		= TempData;

	Image.DIBPadBytes	= 0;



	// Setup JPEG

	Image.JPGWidth		= TempImage->Width;

	Image.JPGHeight		= TempImage->Height;

	Image.JPGChannels	= TempImage->Bpp;



	switch (Temp->Bpp)

	{

		case 1:

			Image.DIBColor			= IJL_G;

			Image.JPGColor			= IJL_G;

			Image.JPGSubsampling	= IJL_NONE;

			break;

		case 3:

			Image.DIBColor			= IJL_RGB;

			Image.JPGColor			= IJL_YCBCR;

			Image.JPGSubsampling	= IJL_411;

			break;

		case 4:

			Image.DIBColor			= IJL_RGBA_FPX;

			Image.JPGColor			= IJL_YCBCRA_FPX;

			Image.JPGSubsampling	= IJL_4114;

			break;

	}



	if (FileName != NULL) {

		Image.JPGFile = FileName;

		if (ijlWrite(&Image, IJL_JFILE_WRITEWHOLEIMAGE) != IJL_OK) {

			if (TempImage != iCurImage)

				ilCloseImage(TempImage);

			ilSetError(IL_LIB_JPEG_ERROR);

			return IL_FALSE;

		}

	}

	else {

		Image.JPGBytes = Lump;

		Image.JPGSizeBytes = Size;

		if (ijlWrite(&Image, IJL_JBUFF_WRITEWHOLEIMAGE) != IJL_OK) {

			if (TempImage != iCurImage)

				ilCloseImage(TempImage);

			ilSetError(IL_LIB_JPEG_ERROR);

			return IL_FALSE;

		}

	}



	ijlFree(&Image);



	if (TempImage->Origin == IL_ORIGIN_LOWER_LEFT)

		ifree(TempData);

	if (Temp != iCurImage)

		ilCloseImage(Temp);



	return IL_TRUE;

}
Exemple #3
0
void __stdcall IMAGE_LoadFromMemory(void *data_in, int size_in, void **data_out, int *size_out, int *width, int *height)
{
//----------------------------------------------------------
// An example using the Intel(R) JPEG Library:
// -- Decode image from a JFIF buffer.
//----------------------------------------------------------
int i;
unsigned char tp,*cp; 
BYTE* lpJpgBuffer=(BYTE *)data_in;
DWORD dwJpgBufferSize=size_in;
//DWORD* numberOfChannels;

BOOL bres;
IJLERR jerr;
DWORD dwWholeImageSize;
BYTE* lpTemp = NULL;
// Allocate the IJL JPEG_CORE_PROPERTIES structure.
JPEG_CORE_PROPERTIES jcprops;
bres = TRUE;
__try
{
// Initialize the Intel(R) JPEG Library.
jerr = ijlInit(&jcprops);
if(IJL_OK != jerr)
{
bres = FALSE;
__leave;
}
// Get information on the JPEG image
// (i.e., width, height, and channels).
jcprops.JPGFile = NULL;
jcprops.JPGBytes = lpJpgBuffer;
jcprops.JPGSizeBytes = dwJpgBufferSize;
jerr = ijlRead(&jcprops, IJL_JBUFF_READPARAMS);
if(IJL_OK != jerr)
{
bres = FALSE;
__leave;
}
// 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(jcprops.JPGChannels)
{
case 1:
{
jcprops.JPGColor = IJL_G;
jcprops.DIBColor = IJL_RGBA_FPX;
jcprops.DIBChannels = 4;
break;
}
case 3:
{
jcprops.JPGColor = IJL_YCBCR;
jcprops.DIBColor = IJL_RGBA_FPX;
jcprops.DIBChannels = 4;
break;
}
default:
{
// This catches everything else, but no
// color twist will be performed by the IJL.
jcprops.JPGColor = IJL_OTHER;
jcprops.DIBColor = IJL_OTHER;
jcprops.DIBChannels = jcprops.JPGChannels;
break;
}
}
// Compute size of desired pixel buffer.
*size_out = dwWholeImageSize = jcprops.JPGWidth * jcprops.JPGHeight * 
jcprops.DIBChannels;
// Allocate memory to hold the decompressed image data.
lpTemp = new BYTE [dwWholeImageSize];
if(NULL == lpTemp)
{
bres = FALSE;
__leave;
}
// Set up the info on the desired DIB properties.
jcprops.DIBWidth = jcprops.JPGWidth;
jcprops.DIBHeight = jcprops.JPGHeight;
jcprops.DIBPadBytes = 0;
jcprops.DIBBytes = lpTemp;
// Now get the actual JPEG image data into the pixel buffer.
jerr = ijlRead(&jcprops, IJL_JBUFF_READWHOLEIMAGE);
if(IJL_OK != jerr)
{
bres = FALSE;
__leave;
}
} // __try
__finally
{
//if(FALSE == bres)
//{
//if(NULL != lpTemp)
//{
//delete [] lpTemp;
//lpTemp = NULL;
//}
}
// Clean up the Intel(R) JPEG Library.
ijlFree(&jcprops);
*width = jcprops.DIBWidth;
*height = jcprops.DIBHeight;
//*numberOfChannels = jcprops.DIBChannels;
cp=(unsigned char *)lpTemp;

//ora converto da RGBA -> a -> BGRA
for (i=0; i<*width * *height *4 ; i+=4)
{
	tp=cp[i];
	cp[i]=cp[i+2];
	cp[i+2]=tp;
	//cp[i+3]=0; //setto l'alpha a zero
}
*data_out = lpTemp;
//} // __finally

 
}
Exemple #4
0
void * Jpeg::Compress(const void *source,
                      int width,
                      int height,
                      int bpp,
                      int &len,
                      int quality)
{
  JPEG_CORE_PROPERTIES jcprops;

  if ( ijlInit(&jcprops) != IJL_OK )
  {
    ijlFree(&jcprops);
    return false;
  }

  jcprops.DIBWidth    = width;
  jcprops.DIBHeight   = height;
  jcprops.JPGWidth    = width;
  jcprops.JPGHeight   = height;
  jcprops.DIBBytes    = (unsigned char *) source;
  jcprops.DIBPadBytes = 0;
  jcprops.DIBChannels = bpp;
  jcprops.JPGChannels = bpp;

  if ( bpp == 3 )
  {
    jcprops.DIBColor = IJL_RGB;
    jcprops.JPGColor = IJL_YCBCR;
    jcprops.JPGSubsampling = IJL_411;
    jcprops.DIBSubsampling = (IJL_DIBSUBSAMPLING) 0;
  }
  else
  {
    jcprops.DIBColor = IJL_G;
    jcprops.JPGColor = IJL_G;
    jcprops.JPGSubsampling = (IJL_JPGSUBSAMPLING) 0;
    jcprops.DIBSubsampling = (IJL_DIBSUBSAMPLING) 0;
  }

  int size = width*height*bpp;

  unsigned char * buffer = new unsigned char[size];

  jcprops.JPGSizeBytes = size;
  jcprops.JPGBytes     = buffer;

  jcprops.jquality = quality;


  if ( ijlWrite(&jcprops,IJL_JBUFF_WRITEWHOLEIMAGE) != IJL_OK )
  {
    ijlFree(&jcprops);
    delete buffer;
    return 0;
  }


  if ( ijlFree(&jcprops) != IJL_OK )
  {
    delete buffer;
    return 0;
  }

  len = jcprops.JPGSizeBytes;
  return buffer;
}
Exemple #5
0
// read image into this buffer.
void * Jpeg::ReadImage(int &width,
                       int &height,
                       int &nchannels,
                       const void *buffer,
                       int sizebytes)
{
  JPEG_CORE_PROPERTIES jcprops;

  if ( ijlInit(&jcprops) != IJL_OK )
  {
    ijlFree(&jcprops);
    return 0;
  }

  jcprops.JPGBytes = (unsigned char *) buffer;
  jcprops.JPGSizeBytes = sizebytes;
  jcprops.jquality = 100;

  if ( ijlRead(&jcprops,IJL_JBUFF_READPARAMS) != IJL_OK )
  {
    ijlFree(&jcprops);
    return 0;
  }

  width  = jcprops.JPGWidth;
  height = jcprops.JPGHeight;
  IJLIOTYPE mode;

  mode = IJL_JBUFF_READWHOLEIMAGE;
  nchannels = jcprops.JPGChannels;
  unsigned char * pixbuff = new unsigned char[width*height*nchannels];
  if ( !pixbuff )
  {
    ijlFree(&jcprops);
    return 0;
  }

  jcprops.DIBWidth  = width;
  jcprops.DIBHeight = height;
  jcprops.DIBChannels = nchannels;
  jcprops.DIBPadBytes = 0;
  jcprops.DIBBytes = (unsigned char *)pixbuff;

  if ( jcprops.JPGChannels == 3 )
  {
    jcprops.DIBColor = IJL_RGB;
    jcprops.JPGColor = IJL_YCBCR;
    jcprops.JPGSubsampling = IJL_411;
    jcprops.DIBSubsampling = (IJL_DIBSUBSAMPLING) 0;
  }
  else
  {
    jcprops.DIBColor = IJL_G;
    jcprops.JPGColor = IJL_G;
    jcprops.JPGSubsampling = (IJL_JPGSUBSAMPLING) 0;
    jcprops.DIBSubsampling = (IJL_DIBSUBSAMPLING) 0;
  }

  if ( ijlRead(&jcprops, mode) != IJL_OK )
  {
    ijlFree(&jcprops);
    return 0;
  }

  if ( ijlFree(&jcprops) != IJL_OK ) return 0;

  return (void *)pixbuff;
}
Exemple #6
0
ALERROR JPEGLoadFromMemory (char *pImage, int iSize, DWORD dwFlags, HPALETTE hPalette, HBITMAP *rethBitmap)

//	JPEGLoadFromMemory
//
//	Load from a memory stream

	{
	ALERROR error;
	IJLERR jerr;

	//	Initialize library

	JPEG_CORE_PROPERTIES jcprops;
	jerr = ijlInit(&jcprops);
	if (jerr != IJL_OK)
		return ERR_FAIL;

	//	Point to the buffer

	jcprops.JPGFile = NULL;
	jcprops.JPGBytes = (BYTE *)pImage;
	jcprops.JPGSizeBytes = iSize;

	//	Read parameters

	jerr = ijlRead(&jcprops, IJL_JBUFF_READPARAMS);
	if (jerr != IJL_OK)
		{
		ijlFree(&jcprops);
		return ERR_FAIL;
		}

	DWORD width = jcprops.JPGWidth;
	DWORD height = jcprops.JPGHeight;
	DWORD nchannels = 3;	//	24-bits
	DWORD dib_line_width = width * nchannels;
	DWORD dib_pad_bytes = IJL_DIB_PAD_BYTES(width,nchannels);

	//	Allocate a dib

	HBITMAP hBitmap;
	BYTE *p24BitPixel;
	if (error = dibCreate24bitDIB(width,
			height,
			0,
			&hBitmap,
			&p24BitPixel))
		{
		ijlFree(&jcprops);
		return error;
		}

	//	Setup the library to load into the dib format

	jcprops.DIBWidth = width;
	jcprops.DIBHeight = -(int)height;
	jcprops.DIBChannels = nchannels;
	jcprops.DIBColor = IJL_BGR;
	jcprops.DIBPadBytes = dib_pad_bytes;
	jcprops.DIBBytes = p24BitPixel;

	//	Setup the color space

	switch (jcprops.JPGChannels)
		{
		case 1:
			jcprops.JPGColor = IJL_G;
			break;

		case 3:
			jcprops.JPGColor = IJL_YCBCR;
			break;

		default:
			{
			jcprops.DIBColor = (IJL_COLOR)IJL_OTHER;
			jcprops.JPGColor = (IJL_COLOR)IJL_OTHER;
			}
		}

	//	Load the data in the buffer

	jerr = ijlRead(&jcprops, IJL_JBUFF_READWHOLEIMAGE);
	if (jerr != IJL_OK)
		{
		::DeleteObject(hBitmap);
		ijlFree(&jcprops);
		return ERR_FAIL;
		}

	//	Done

	ijlFree(&jcprops);

	//	If we want a DIB, just return that; otherwise,
	//	convert to DDB and return that

	if (dwFlags & JPEG_LFR_DIB)
		*rethBitmap = hBitmap;
	else
		{
		HBITMAP hDDB;
		error = dibConvertToDDB(hBitmap, hPalette, &hDDB);
		::DeleteObject(hBitmap);
		if (error)
			return error;

		*rethBitmap = hDDB;
		}

	return NOERROR;
	}
Exemple #7
0
static bool EncodeToJPEGBuffer( byte* lpRgbBuffer, dword dwWidth, dword dwHeight, byte** lppJpgBuffer, dword* lpdwJpgBufferSize, int quality )
{
	bool	bres = true;
	IJLERR	jerr;
	dword	dwRgbBufferSize;
	byte *	lpTemp = NULL;

	// Allocate the IJL JPEG_CORE_PROPERTIES structure.
	JPEG_CORE_PROPERTIES jcprops;
	__try {
		// Initialize the Intel(R) JPEG Library.
		jerr = ijlInit(&jcprops);
		if(IJL_OK != jerr)
		{
			bres = false;
			__leave;
		}

		dwRgbBufferSize = dwWidth * dwHeight * 4;
		lpTemp = new byte [dwRgbBufferSize];
		if(NULL == lpTemp)
		{
			bres = false;
			__leave;
		}

		// Set up information to write from the pixel buffer.
		jcprops.DIBWidth = dwWidth;
		jcprops.DIBHeight = dwHeight; // Implies a bottom-up DIB.
		jcprops.DIBBytes = lpRgbBuffer;
		jcprops.DIBPadBytes = 0;
		jcprops.DIBChannels = 4;
		jcprops.DIBColor = IJL_RGBA_FPX;
		jcprops.JPGWidth = dwWidth;
		jcprops.JPGHeight = dwHeight;
		jcprops.JPGFile = NULL;
		jcprops.JPGBytes = lpTemp;
		jcprops.JPGSizeBytes = dwRgbBufferSize;
		jcprops.JPGChannels = 4;
		jcprops.JPGColor = IJL_YCBCRA_FPX;
		jcprops.JPGSubsampling = IJL_4114; // 4:1:1 subsampling.
		jcprops.jquality = quality;

		// Write the actual JPEG image from the pixel buffer.
		jerr = ijlWrite(&jcprops,IJL_JBUFF_WRITEWHOLEIMAGE);
		if(IJL_OK != jerr)
		{
			bres = false;
			__leave;
		}

	} // __try
	__finally
	{
		if( bres == false )
		{
			if(NULL != lpTemp)
			{
				delete[] lpTemp;
				lpTemp = NULL;
			}
		}

		*lppJpgBuffer = lpTemp;
		*lpdwJpgBufferSize = jcprops.JPGSizeBytes;
		// Clean up the Intel(R) JPEG Library.
		ijlFree(&jcprops);
	}
	
	return bres;
} // EncodeToJPEGBuffer()
Exemple #8
0
static bool DecodeFromJPEGBuffer( byte* lpJpgBuffer, dword dwJpgBufferSize, byte** lppRgbBuffer, 
						  dword* lpdwWidth, dword* lpdwHeight, dword* lpdwNumberOfChannels)
{
	bool	bres = true;
	IJLERR	jerr;
	dword	dwWholeImageSize;
	byte *	lpTemp = NULL;

	// Allocate the IJL JPEG_CORE_PROPERTIES structure.
	JPEG_CORE_PROPERTIES jcprops;
	__try
	{
		// Initialize the Intel(R) JPEG Library.
		jerr = ijlInit(&jcprops);
		if(IJL_OK != jerr)
		{
			bres = false;
			__leave;
		}
		// Get information on the JPEG image
		// (i.e., width, height, and channels).

		jcprops.JPGFile = NULL;
		jcprops.JPGBytes = lpJpgBuffer;
		jcprops.JPGSizeBytes = dwJpgBufferSize;
		jerr = ijlRead(&jcprops, IJL_JBUFF_READPARAMS);
		if(IJL_OK != jerr)
		{
			bres = false;
			__leave;
		}

		ASSERT( jcprops.JPGChannels == 4 );
		//jcprops.JPGColor = IJL_YCBCRA_FPX;
		jcprops.DIBColor = IJL_RGBA_FPX;
		jcprops.DIBChannels = 4;

		// Compute size of desired pixel buffer.
		dwWholeImageSize = jcprops.JPGWidth * jcprops.JPGHeight * jcprops.DIBChannels;
		// Allocate memory to hold the decompressed image data.
		lpTemp = new byte [dwWholeImageSize];
		if(NULL == lpTemp)
		{
			bres = false;
			__leave;
		}
		// Set up the info on the desired DIB properties.
		jcprops.DIBWidth = jcprops.JPGWidth;
		jcprops.DIBHeight = jcprops.JPGHeight;
		jcprops.DIBPadBytes = 0;
		jcprops.DIBBytes = lpTemp;
		// Now get the actual JPEG image data into the pixel buffer.
		jerr = ijlRead(&jcprops, IJL_JBUFF_READWHOLEIMAGE);
		if(IJL_OK != jerr)
		{
			bres = false;
			__leave;
		}
	} // __try
	__finally
	{
		if(false == bres)
		{
			if(NULL != lpTemp)
			{
				delete [] lpTemp;
				lpTemp = NULL;
			}
		}

		// Clean up the Intel(R) JPEG Library.
		ijlFree(&jcprops);
		*lpdwWidth = jcprops.DIBWidth;
		*lpdwHeight = jcprops.DIBHeight;
		*lpdwNumberOfChannels = jcprops.DIBChannels;
		*lppRgbBuffer = lpTemp;
	} // __finally
	
	return bres;

} // DecodeFromJPEGBuffer()
	/////////////////////////////////////////
	// Texture::ImageJPG::Load
	void Texture::ImageJPG::Load(const char *filename)
	{
	throw Daher::Exception("Cannot load image: IJL initialization failed");
#if 0
		JPEG_CORE_PROPERTIES		image;
		unsigned char				*imageBits = NULL;		// the bits, before swapping
		int							imageSize = 0;
		
		DGL::LogPrint("Loading JPEG Image '%s' ...",filename);
		ZeroMemory( &image, sizeof( JPEG_CORE_PROPERTIES ) );
		// try to init the image 'container'
		if( ijlInit( &image ) != IJL_OK )
			throw Daher::Exception("Cannot load image: IJL initialization failed");

		image.JPGFile = const_cast<char*>(filename);
		// try to read the params from the file
		if( ijlRead( &image, IJL_JFILE_READPARAMS ) != IJL_OK )
			throw Daher::Exception("File Not Found");

		// check info about the channels
		switch(image.JPGChannels) {
			case 1:
				image.JPGColor = IJL_G;
				break;
			case 3:
				image.JPGColor = IJL_YCBCR;
				break;
			default:
				// This catches everything else, but no
				// color twist will be performed by the IJL.
				image.DIBColor = (IJL_COLOR)IJL_OTHER;
				image.JPGColor = (IJL_COLOR)IJL_OTHER;
				break;
		}
		image.DIBWidth    = image.JPGWidth;
		image.DIBHeight   = image.JPGHeight;
		image.DIBChannels = 3;
		image.DIBPadBytes = IJL_DIB_PAD_BYTES(image.DIBWidth,image.DIBChannels);
		imageSize = (image.DIBWidth * image.DIBChannels + image.DIBPadBytes) * image.DIBHeight;
		// allocate memory to store the image unsigned chars (the info OGL wants)
		imageBits = new unsigned char[ imageSize ];
		this->data = new unsigned char[ imageSize ];

		image.DIBBytes = imageBits;
		// Read the image unsigned chars from the image
		if( ijlRead( &image, IJL_JFILE_READWHOLEIMAGE ) != IJL_OK ) {
			delete [] imageBits;
			delete [] this->data;
			this->data = NULL;
			return;
		}
		// free the image container
		if( ijlFree( &image ) != IJL_OK ) 
			throw Daher::Exception("Cannot Free IJL Container");

		this->width	= image.DIBWidth;
		this->height = image.DIBHeight;
		// the JPG stores its image unsigned chars in a different order, instead of
		// going from lower to higher lines it goes higher to lower.
		// Use imageBits2 after this loop.
		for (int j = 0;j < this->height; j++) {
			for (int i = 0;i < this->width; i++) {
				this->data[(j * this->width+i)* 3+ this->Red] = imageBits[((this->height-1-j) * this->width+i)* 3+ this->Blue];
				this->data[(j * this->width+i)* 3+ this->Green] = imageBits[((this->height-1-j) * this->width+i)* 3+ this->Green];
				this->data[(j * this->width+i)* 3+ this->Blue] = imageBits[((this->height-1-j) * this->width+i)* 3+ this->Red];
			}
		}
		// free memory
		delete [] imageBits;
#endif
	}