Programmatically finding file support.

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
boffo

Programmatically finding file support.

Post by boffo »

Hello everyone.

Is there some way to interrogate MagickWand (in c/c++) to find out which file types or file extensions are supported?

For the life of me, I'm not seeing that in the API.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Programmatically finding file support.

Post by magick »

You can call MagickSetImageFormat() and if it returns MagickFalse, the image format is not recognized or not supported. You can also call the MagickCore API method GetMagickInfo(). If it returns a non-null result, the image format is recognized and supported by ImageMagick.
boffo

Re: Programmatically finding file support.

Post by boffo »

Thanks for the response.

So you are saying that the only way I can get a complete set of file formats is to call 'MagickSetImageFormat' for every 2-4 letter combination of letters and numerals? There isn't any way to get back a simple list of what's supported?

regards.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Programmatically finding file support.

Post by magick »

You can get a list of all supported image formats with a MagickCore API call:
  • p = GetMagickInfo("*",exception);
boffo

Re: Programmatically finding file support.

Post by boffo »

Aha...thanks.
boffo

Re: Programmatically finding file support.

Post by boffo »

Ah well...bummer.

It works fine, according to Visual Studio it's loading a whole slew of *.dll's (things like IM_MOD_RL_tga_.dll), and then it gets up to
'IM_MOD_RL_xtrn_.dll'', and then blammo:

First-chance exception at 0x048decd5 in test.exe: 0xC0000005: Access violation reading location 0x00000014.
Unhandled exception at 0x048decd5 in test.exe: 0xC0000005: Access violation reading location 0x00000014.

No biggie, I'll just have to have a list of file types in my own application. It's less elegant but should work fine.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Programmatically finding file support.

Post by el_supremo »

FYI: This C function works fine on my Win XP system using IM 6.6.3-9
It writes the list of 208 formats into the file "formats.txt".

Pete

Code: Select all

#include <windows.h>
#include <magick/MagickCore.h>
void test_wand(void)
{
	ExceptionInfo *exception;
	const MagickInfo **mi_ptr = NULL;
	size_t num_ptr; 
	size_t i;
	FILE *fdo = NULL;

	MagickCoreGenesis((char *) NULL,MagickFalse);
	// Get and Initialize an exception info
	exception = AcquireExceptionInfo();
	GetExceptionInfo(exception);

	mi_ptr = GetMagickInfoList("*",&num_ptr,exception);
	if(mi_ptr == NULL) {
		MessageBox(NULL,"NULL list returned","",MB_OK);
	} else {
		fdo = fopen("formats.txt","w");
		for(i=0;i<num_ptr;i++) {
			fprintf(fdo,"%s\n",mi_ptr[i]->name);
		}
		fclose(fdo);
	}

	DestroyExceptionInfo(exception);
	MagickCoreTerminus();
}
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
boffo

Re: Programmatically finding file support.

Post by boffo »

Many thanks, that's exactly what I needed to know. It works now.
Post Reply