Write 32/64bpc bitmaps and PSD file format

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

Moderators: XnTriq, xnview

mslaf
Posts: 3
Joined: Sun Mar 20, 2011 12:37 am

Write 32/64bpc bitmaps and PSD file format

Post by mslaf »

Hi,

I got 3 questions and one suggestion:

Q1: How to convert and/or save a 16/32 bit per channel/component (64bpp/128bpp) bitmap loaded with GFL_LOAD_ORIGINAL_DEPTH flag set, as a 8 bit per channel/component bitmap? Doesn't see anything in gflChangeColorDepth that could do it.

Q2: Is it possible to write multilayer psd (photoshop) files or only the 'merged copy' is currently supported? If it is possible, then how to save multiple layers into such file.

Q3: Any plans for openexr format?

S: In reference to http://newsgroup.xnview.com/viewtopic.php?f=4&t=17800, could you name the dll differently (according to the target platform) they could coexist in the same folder - it would help to develop applications that operate in 32/64 bit environment. For eg.

libgflex64.dll
libgflex64w.dll
libgflex86.dll
libgflex86w.dll
libgflx64.dll
libgflx64w.dll
libgflx86.dll
libgflx86w.dll

So far it can be only achieved by modifying paths in the static libraries.

Kind regards,

m.
mslaf
Posts: 3
Joined: Sun Mar 20, 2011 12:37 am

Re: Write 32/64bpc bitmaps and PSD file format

Post by mslaf »

I figured out how to save layered PSDs and TIFFs. Here's the code for those who find it useful.

Code: Select all

		GFL_SAVE_PARAMS lParameters;
		gflGetDefaultSaveParams( &lParameters );
		lParameters.Flags |= GFL_SAVE_REPLACE_EXTENSION;

		switch( in_FileType )
		{
			default:
				return false;

			case ImageFileType_PSD: 
				lParameters.FormatIndex = gflGetFormatIndexByName( "psd" );
				break;
			case ImageFileType_TIFF: 
				lParameters.FormatIndex = gflGetFormatIndexByName( "tiff" );
				lParameters.Compression = GFL_RLE;
				break;
		}

		/*
		Initialize save:
		*/

		GFL_FILE_HANDLE lFile;

		GFL_UINT32 nCount = this->GetCount();

		/*
		PSD requires additional layer for the 'merged copy'.
		*/

		if ( in_FileType == ImageFileType_PSD )
			nCount++;

		if ( gflFileCreateT( &lFile, in_Filename, nCount, &lParameters ) != 0 )
			return false;

		GFL_BITMAP* ptrBitmap;
		for( size_t i=0; i < this->GetCount(); i++ )
		{
			if ( in_Format == this->operator[]( i ).GetFormat() )
			{
				if ( gflFileAddPicture( lFile, (GFL_BITMAP*)this->operator[]( i ).GetObjectPtr() ) != 0 )
					return false;
			}
			/*
			Convert:
			*/
			else
			{
				switch( in_Format )
				{
					case BitmapDataFormat_RGB8:
					case BitmapDataFormat_RGB16:
						if ( gflChangeColorDepth( (GFL_BITMAP*)this->operator[]( i ).GetObjectPtr(), &ptrBitmap, GFL_MODE_TO_RGB, 0 ) != 0 )
							return false;
						break;

					case BitmapDataFormat_RGBA8:
					case BitmapDataFormat_RGBA16:
						if ( gflChangeColorDepth( (GFL_BITMAP*)this->operator[]( i ).GetObjectPtr(), &ptrBitmap, GFL_MODE_TO_RGBA, 0 ) != 0 )
							return false;
						break;
				}

				if ( gflFileAddPicture( lFile, ptrBitmap ) != 0 )
					return false;

				gflFreeBitmap( ptrBitmap );
			}
		}

		/*
		Use the first bitmap as the PSD's 'merged copy', that needs to be in RGB format.
		*/

		if ( in_FileType == ImageFileType_PSD )
		{
			if ( this->operator[]( 0 ).GetFormat() == BitmapDataFormat_RGB8 )
			{
				if ( gflFileAddPicture( lFile, (GFL_BITMAP*)this->operator[]( 0 ).GetObjectPtr() ) != 0 )
						return false;
			}
			else
			{
				if ( gflChangeColorDepth( (GFL_BITMAP*)this->operator[]( 0 ).GetObjectPtr(), &ptrBitmap, GFL_MODE_TO_RGB, 0 ) != 0 )
					return false;

				if ( gflFileAddPicture( lFile, ptrBitmap ) != 0 )
					return false;

				gflFreeBitmap( ptrBitmap );
			}
		}

		/*
		Finish:
		*/

		gflFileClose( lFile );
		return true;
User avatar
xnview
Author of XnView
Posts: 36291
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: Write 32/64bpc bitmaps and PSD file format

Post by xnview »

mslaf wrote: Q1: How to convert and/or save a 16/32 bit per channel/component (64bpp/128bpp) bitmap loaded with GFL_LOAD_ORIGINAL_DEPTH flag set, as a 8 bit per channel/component bitmap? Doesn't see anything in gflChangeColorDepth that could do it.
gflChangeColorDepth change to 8bits
Q3: Any plans for openexr format?
You can take IlmImf.dll from XnView (but only support 8bits)
Pierre.
mslaf
Posts: 3
Joined: Sun Mar 20, 2011 12:37 am

Re: Write 32/64bpc bitmaps and PSD file format

Post by mslaf »

Thank you.