Having problem with a JpegLoad function again!!!

Started by
12 comments, last by Corrosive 21 years, 9 months ago
I still dont have a solution, please help me!!

To code is to make things come to life
To code is to make things come to life ;)
Advertisement
well, i just happened to code a jpeg loading function using libjpeg, so if it''s of any help to you, here it is:

  HBITMAP LoadJpeg(LPCTSTR FileName){	jpeg_decompress_struct cinfo;	jpeg_error_mgr jerr;	cinfo.err = jpeg_std_error(&jerr);	jpeg_create_decompress(&cinfo);	FILE * infile;	if ((infile = _tfopen(FileName, _T("rb"))) == NULL)		return NULL;	jpeg_stdio_src(&cinfo, infile);	jpeg_read_header(&cinfo, TRUE);	jpeg_start_decompress(&cinfo);	BITMAPINFO bmi = { { sizeof (BITMAPINFOHEADER), cinfo.output_width, cinfo.output_height, 1, WORD(cinfo.output_components*8), BI_RGB } };	PVOID pBitmapBits;	HBITMAP hBitmap = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, &pBitmapBits, 0, 0);	if (hBitmap)	{		BITMAP bm;		GetObject(hBitmap, sizeof bm, &bm);		PBYTE CurrentScanLine = PBYTE(bm.bmBits)+bm.bmWidthBytes*bm.bmHeight;		for (UINT i = 0; i < cinfo.output_height; ++i)		{			CurrentScanLine -= bm.bmWidthBytes;			UINT read = jpeg_read_scanlines(&cinfo, &CurrentScanLine, 1);			ATLASSERT(read == 1);		}		PBYTE CurrentLine = PBYTE(pBitmapBits);		for (UINT line = 0; line < cinfo.output_height; ++line)		{			PBYTE CurrentPixel = CurrentLine;			CurrentLine += bm.bmWidthBytes;			for (UINT pixel = 0; pixel < cinfo.output_width; ++pixel)			{				std::swap(CurrentPixel[0], CurrentPixel[2]);				CurrentPixel += cinfo.output_components;			}		}	}	jpeg_finish_decompress(&cinfo);	jpeg_destroy_decompress(&cinfo);	return hBitmap;}  


---
visit #directxdev on afternet
---visit #directxdev on afternet <- not just for directx, despite the name
Thank´s, but i dont know the lib that you used and where can i find it!!! Can you sen me the adress to the file? because im using the Intel Jpeg Lib.. Thanks

To code is to make things come to life
To code is to make things come to life ;)
Since I have a feeling that you wouldn't want to build libjpeg by yourself, I zipped up only required headers and the lib file that I built for myself here. If you do want to build libjpeg yourself, here is the full source (including my prebuilt lib).

---
Come to #directxdev IRC channel on AfterNET

[edited by - niyaw on July 15, 2002 1:22:21 AM]

This topic is closed to new replies.

Advertisement