SaveBitmap problems

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

Moderators: XnTriq, helmut, xnview

Alessandro

SaveBitmap problems

Post by Alessandro »

Hi,

1) I tryed, using AllockBitmap(), to alloc an RGB32 image (both abgr and bgra) and the image wasn't correctly saved into any formats.
I got in every case a white image.
2) I tryed to save into a gif a RGB (24 bits since 32 doesn't work...) image and SaveBitmap() asked me to convert the colorspace.
SaveBitmap() could call itself colorconvert() if it recognizes a bad colorspace for the requested output format, and btw there's now way (maybe... am I wrong?) I could know what's the maximum colour depth for every format, I mean...I know it's 8bits for gif, but I dunno if other formats have the same limitation.
If actually there isn't a way you could add such a field into the structure that returns info about fileformats.

Best regards.
User avatar
xnview
Author of XnView
Posts: 44920
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: SaveBitmap problems

Post by xnview »

Alessandro wrote:Hi,

1) I tryed, using AllockBitmap(), to alloc an RGB32 image (both abgr and bgra) and the image wasn't correctly saved into any formats.
I got in every case a white image.
Could you post your code?
2) I tryed to save into a gif a RGB (24 bits since 32 doesn't work...) image and SaveBitmap() asked me to convert the colorspace.
SaveBitmap() could call itself colorconvert() if it recognizes a bad colorspace for the requested output format, and btw there's now way (maybe... am I wrong?) I could know what's the maximum colour depth for every format, I mean...I know it's 8bits for gif, but I dunno if other formats have the same limitation.
If actually there isn't a way you could add such a field into the structure that returns info about fileformats.
You can use GFL_SAVE_ANYWAY
Pierre.
Alessandro

Post by Alessandro »

The following code works because I modified it to save rgb24 images.
CopyFrame() was the function that I previously used and you can think of it like a memcopy() applyed on every row since Image is a rgb32 image.

Code: Select all

int MySaveImage(const char *filename, char *FormatName, DWORD *Image, DWORD w, DWORD h, DWORD pitch, bool IsGray, bool flipV)
{
GFL_FILE_INFORMATION info;
GFL_SAVE_PARAMS save_params;
GFL_BITMAP *pBmp=gflAllockBitmap(IsGray ? GFL_GREY : GFL_BGR,w,h,IsGray ? 1 : 4,NULL);

 if(pBmp==NULL)
  return GFL_ERROR_NO_MEMORY;

// CopyFrame((DWORD *)Bmp->Data,Image,Bmp->BytesPerLine,pitch,h);
 RGB32ToGB24(pBmp->Data,pBmp->Width,pBmp->Height,pBmp->BytesPerLine,Image,pitch,flipV);

 gflGetDefaultSaveParams(&save_params);
 save_params.Flags=GFL_SAVE_REPLACE_EXTENSION;
 save_params.FormatIndex=gflGetFormatIndexByName(FormatName);
 save_params.Compression=GFL_LZW;
 save_params.CompressionLevel=7;
 save_params.Quality=75;
 save_params.ChannelType=IsGray ? GFL_CTYPE_GREYSCALE : GFL_BGR;
 save_params.ChannelOrder=GFL_CORDER_INTERLEAVED; // for raw format

GFL_ERROR retVal;
 if((retVal=gflSaveBitmap((char *)filename, pBmp, &save_params))!=GFL_NO_ERROR)
 {
  gflGetErrorString(retVal);
//  MessageBox(NULL, "Error saving file!", NULL, MB_OK);
  MessageBox(NULL, gflGetErrorString(retVal), NULL, MB_OK);
 }

 gflFreeBitmap(pBmp);

 return retVal;
}
What about the questions I asked about multipages formats?
The reply was actually an addiction appended by me...
User avatar
xnview
Author of XnView
Posts: 44920
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Post by xnview »

I've tried the following code, and it works:

Code: Select all

	gflGetDefaultLoadParams( &load_option );

	pBmp=gflAllockBitmap(GFL_BGRA,512,512,4,NULL);

	for ( y=0; y<pBmp->Height; y++ )
	{
		ptr = gflGetBitmapPtr( pBmp, y ); 
		for ( x=0; x<pBmp->Width; x++ )
		{
			*ptr++ = 0; 
			*ptr++ = 0; 
			*ptr++ = 255; // red
			*ptr++ = 0; 
		}
	}

	gflGetDefaultSaveParams(&save_params);
	save_params.Flags=GFL_SAVE_REPLACE_EXTENSION;
	save_params.FormatIndex=gflGetFormatIndexByName("bmp");
	save_params.Compression=GFL_LZW;
	save_params.CompressionLevel=7;
	save_params.Quality=75;

	gflSaveBitmap("d:/temp/test.bmp", pBmp, &save_params); 

	gflFreeBitmap(pBmp);

Pierre.
Alessandro

Post by Alessandro »

hi,

I tryed the code and it works, but it looks like saving in .png still there're problems, aniway thanks, it helped me.
User avatar
xnview
Author of XnView
Posts: 44920
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Post by xnview »

Alessandro wrote:I tryed the code and it works, but it looks like saving in .png still there're problems, aniway thanks, it helped me.
What's happened?
Pierre.
Alessandro

Post by Alessandro »

I tryed to store into a png file an rgb32 image, but whether I set the alpha channel to 0 or to 255 the images looks transparent (format of my data is in DWORDs: AARRGGBB, format set as parameter in save function: GFL_BGRA).
I solved it converting in RGB24 but I can't figure out what's the problem.
Maybe when (and if) I'll try to store a transparent image I'll get it.

Thanks for your help.