SOS

Discussions on GFL SDK, the graphic library for reading and writing graphic files

Moderators: XnTriq, xnview

Post Reply
User avatar
Grincheux
Posts: 33
Joined: Thu Nov 30, 2006 8:01 am
Location: Arbois - 39
Contact:

SOS

Post by Grincheux » Sat Jun 01, 2013 8:32 am

Je lis un fichier, jpeg ou autre avec gflLoadBitmap. Ici pas de problème. Ensuite j'appelle GetDiBits une première fois pour diverses initialisations. J'appelle une nouvelle fois cette fonction et elle me renvoie systématiquement 0. J'utilise GetDiBits car avec GFL je ne récupère qu'une image en 24 bits et je la voudrais en 32 bits. Devrais-je utiliser gflConvertBitmapIntoDIB pultôt que gflConvertBitmapIntoDDB ? Est-ce la source de mon problème ?

J'implore votre aide.
D'avance merci.

Code: Select all

LPIMAGEINFOS LoadImageFromFile(LPSTR __lpszFileName)
{
	GFL_LOAD_PARAMS			_LoadParams ;
	IMAGEINFOS				_ImageInfos, *_lpImageInfos ;
	HBITMAP					_hBitmap ;
	BITMAP					_BmpWork ;
	HDC						_hDC ;
	LPBYTE					_lpImageBits ;

	memset(&_ImageInfos,0,sizeof(IMAGEINFOS)) ;

	gflGetDefaultLoadParams(&_LoadParams);

	_LoadParams.ColorModel = GFL_ARGB ;
	_LoadParams.Origin = GFL_TOP_LEFT ;
	_LoadParams.Flags = GFL_LOAD_SKIP_ALPHA ;
	_LoadParams.DefaultAlpha = 255 ;
	_LoadParams.LinePadding = 4 ;

	if(gflLoadBitmap(__lpszFileName,&_ImageInfos.lpgflBitmap,&_LoadParams,&_ImageInfos.FileInfos))
		return (NULL) ;

	gflConvertBitmapIntoDDB(_ImageInfos.lpgflBitmap,&_hBitmap) ;
	if(_hBitmap)
	{
		ZeroMemory(&_BmpWork,sizeof(BITMAP));
		GetObject(_hBitmap,sizeof(BITMAP),&_BmpWork) ;

		_hDC = GetDC(NULL) ;
		if(_hDC)
		{
			_ImageInfos.SrcBitmapInfo.biSize = sizeof(BITMAPINFO) ;

			if(GetDIBits(_hDC,_hBitmap,0,_BmpWork.bmHeight,NULL,(LPBITMAPINFO) &_ImageInfos.SrcBitmapInfo,DIB_RGB_COLORS))
			{
				_lpImageInfos = (LPIMAGEINFOS) VirtualAlloc(NULL,sizeof(IMAGEINFOS),MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE) ;
				if(_lpImageInfos)
				{
					_lpImageBits = (LPBYTE) VirtualAlloc(NULL,_ImageInfos.SrcBitmapInfo.biSize,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE) ;
					if(_lpImageBits)
					{
						_ImageInfos.SrcBitmapInfo.biSize = sizeof(BITMAPINFOHEADER) ;

						if(!GetDIBits(_hDC,_hBitmap,0,_BmpWork.bmHeight,_lpImageBits,(LPBITMAPINFO) &_ImageInfos.SrcBitmapInfo,DIB_RGB_COLORS))
						{
							ReleaseDC(NULL,_hDC) ; // J'atteris toujours ICI !

							VirtualFree(_lpImageBits,0,MEM_RELEASE) ;
							VirtualFree(_lpImageInfos,0,MEM_RELEASE) ;
						}
						else
						{
							DeleteObject(_hBitmap) ;

							memcpy(_lpImageInfos,&_ImageInfos,sizeof(IMAGEINFOS)) ;
							memcpy(&_lpImageInfos->gflBitmap,_ImageInfos.lpgflBitmap,sizeof(GFL_BITMAP)) ;

							_lpImageInfos->lpImageBits = _lpImageBits ;

							gflFreeFileInformation(&_lpImageInfos->FileInfos) ;
							gflFreeBitmapData(_lpImageInfos->lpgflBitmap) ;

							ReleaseDC(NULL,_hDC) ;

							_lpImageInfos->lpgflBitmap = NULL ;
							return (_lpImageInfos) ;
						}
					}
					else
					{
						ReleaseDC(NULL,_hDC) ;
						VirtualFree(_lpImageInfos,0,MEM_RELEASE) ;
					}
				}
				else
				{
					ReleaseDC(NULL,_hDC) ;
				}
			}
			else
			{
				ReleaseDC(NULL,_hDC) ;
			}
		}

		DeleteObject(_hBitmap) ;
	}

	gflFreeFileInformation(&_ImageInfos.FileInfos) ;
	gflFreeBitmapData(_ImageInfos.lpgflBitmap) ;

	return (NULL) ;
}
Kenavo.

User avatar
Grincheux
Posts: 33
Joined: Thu Nov 30, 2006 8:01 am
Location: Arbois - 39
Contact:

Re: SOS

Post by Grincheux » Sat Jun 01, 2013 9:38 am

Thank you for your help. The correct code is shown here :

The problem was coming from the image size. I passed the structure size to allocate the image buffer !

_lpImageBits = (LPBYTE) VirtualAlloc(NULL,_ImageInfos.SrcBitmapInfo.biSizeImage,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE) ; is good but
_lpImageBits = (LPBYTE) VirtualAlloc(NULL,_ImageInfos.SrcBitmapInfo.biSize,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE) ; is wrong.

I resume, the buffer was too small.

Code: Select all

LPIMAGEINFOS LoadImageFromFile(LPSTR __lpszFileName)
{
	GFL_LOAD_PARAMS			_LoadParams ;
	IMAGEINFOS				_ImageInfos, *_lpImageInfos ;
	HBITMAP					_hBitmap ;
	BITMAP					_BmpWork ;
	HDC						_hDC ;
	LPBYTE					_lpImageBits ;

	memset(&_ImageInfos,0,sizeof(IMAGEINFOS)) ;

	gflGetDefaultLoadParams(&_LoadParams);

	_LoadParams.ColorModel = GFL_ARGB ;
	_LoadParams.Origin = GFL_TOP_LEFT ;
	_LoadParams.Flags = GFL_LOAD_SKIP_ALPHA ;
	_LoadParams.DefaultAlpha = 255 ;
	_LoadParams.LinePadding = 4 ;

	if(gflLoadBitmapIntoDDB(__lpszFileName,&_hBitmap,&_LoadParams,&_ImageInfos.FileInfos))
		return (NULL) ;

	if(_hBitmap)
	{
		ZeroMemory(&_BmpWork,sizeof(BITMAP));
		GetObject(_hBitmap,sizeof(BITMAP),&_BmpWork) ;

		_hDC = GetDC(NULL) ;
		if(_hDC)
		{
			_ImageInfos.SrcBitmapInfo.biSize = sizeof(BITMAPINFOHEADER) ;

			if(GetDIBits(_hDC,_hBitmap,0,_BmpWork.bmHeight,NULL,(LPBITMAPINFO) &_ImageInfos.SrcBitmapInfo,DIB_RGB_COLORS))
			{
				_lpImageInfos = (LPIMAGEINFOS) VirtualAlloc(NULL,sizeof(IMAGEINFOS),MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE) ;
				if(_lpImageInfos)
				{
					_lpImageBits = (LPBYTE) VirtualAlloc(NULL,_ImageInfos.SrcBitmapInfo.biSizeImage,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE) ;
					if(_lpImageBits)
					{
						if(!GetDIBits(_hDC,_hBitmap,0,_ImageInfos.SrcBitmapInfo.biHeight,_lpImageBits,(LPBITMAPINFO) &_ImageInfos.SrcBitmapInfo,DIB_RGB_COLORS))
						{
							VirtualFree(_lpImageBits,0,MEM_RELEASE) ;
							VirtualFree(_lpImageInfos,0,MEM_RELEASE) ;
						}
						else
						{
							DeleteObject(_hBitmap) ;

							memcpy(_lpImageInfos,&_ImageInfos,sizeof(IMAGEINFOS)) ;

							_lpImageInfos->lpImageBits = _lpImageBits ;

							gflFreeFileInformation(&_lpImageInfos->FileInfos) ;

							ReleaseDC(NULL,_hDC) ;

							return (_lpImageInfos) ;
						}
					}
					else
					{
						VirtualFree(_lpImageInfos,0,MEM_RELEASE) ;
					}
				}
			}

			ReleaseDC(NULL,_hDC) ;
		}

		DeleteObject(_hBitmap) ;
	}

	gflFreeFileInformation(&_ImageInfos.FileInfos) ;

	return (NULL) ;
}
Kenavo.

Post Reply