ReadImage TGA very slow

[email protected] Mon, 1 Oct 2018 21:37:57 +0200
Newsgroups gmane.comp.video.graphicsmagick.help
Message-ID <[email protected]>
Hello,

I wanted to find which uncompressed image format was the fastest to decode with
the attached trivial C program, and I obtained very puzzling results:

> ~/gmdecode wallpaper.miff
0.0119
> ~/gmdecode wallpaper.png
0.0404
> ~/gmdecode wallpaper.sgi
0.0317
> ~/gmdecode wallpaper.tga TGA
0.1538
> ~/gmdecode wallpaper.tiff
0.0123

I don't understand why TGA loading is more than ten times slower than the other
formats, while being as simple or simpler. Any idea?


(the program was compiled with `gcc -O2 -s -o gmdecode gmdecode.c -O $(GraphicsMagick-config --cppflags --ldflags --libs)`
on Gentoo GNU/Linux with graphicsmagic 1.3.30)

_______________________________________________
Graphicsmagick-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/graphicsmagick-help
gmdecode.c (text/x-c, 1.1 KB)
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <magick/api.h>


int64_t timespec_diff(struct timespec *ts1, struct timespec *ts2)
{
	return (ts1->tv_sec * 1000000000 + ts1->tv_nsec) -
	(ts2->tv_sec * 1000000000 + ts2->tv_nsec);
}


int main (int argc, char **argv)
{
	if(argc != 2 && argc != 3)
	    err(EXIT_FAILURE, "Usage: %s image [magick]\n", argv[0]);

	InitializeMagick(NULL);
	Image *img = NULL;
	ImageInfo *imginfo = CloneImageInfo(0);
	ExceptionInfo exception;

	GetExceptionInfo(&exception);
	imginfo->file = !strcmp(argv[1], "-") ? stdin : fopen(argv[1], "r");
	if(imginfo->file == NULL)
		err(EXIT_FAILURE, "%s", argv[1]);
	if(argc == 3)
		strncpy(imginfo->magick, argv[2], MaxTextExtent - 1);

	struct timespec start, end;
	clock_gettime(CLOCK_MONOTONIC, &start);
	img = ReadImage(imginfo, &exception);
	clock_gettime(CLOCK_MONOTONIC, &end);
	printf("%.4f\n", timespec_diff(&end, &start) / 1e9);

	if(img == NULL)
    {
		CatchException(&exception);
		exit(EXIT_FAILURE);
    }
    DestroyImage(img);
    DestroyImageInfo(imginfo);
	DestroyMagick();

	return EXIT_SUCCESS;
}