I'm writing a program who's main function will essentially boil down to copying a small rectangle from one image to another and write it out as a JPG file. No other image manipulation functions are required. It does have to be as absolutely speedy fast as possible, so I was wondering if anyone could comment on the reference implementation I've coded up and offer suggestions on making it faster.

Thanks.

-b

#include <Imlib2.h>

#define SIZE	50

int main (int argc, char **argv)
{
	/* image handles */
	Imlib_Image src, dest;
	int src_width, src_height, dest_width, dest_height;
	char *tmp;

	/* if we provided < 3 arguments after the command - exit */
	if (argc != 4)
		exit (1);

	/* load the images */
	src = imlib_load_image (argv[1]);
	dest = imlib_load_image (argv[2]);

	/* if the load was successful */
	if (src && dest)
	{
		/* get the sizes of the images */
		imlib_context_set_image (src);
		src_width = imlib_image_get_width ();
		src_height = imlib_image_get_height ();

		imlib_context_set_image (dest);
		dest_width = imlib_image_get_width ();
		dest_height = imlib_image_get_height ();

		/* set the image format to be the format of the extension of our last */
		/* argument - i.e. .png = png, .tif = tiff etc. */
		tmp = strrchr (argv[3], '.');
		if (tmp)
			imlib_image_set_format (tmp + 1);
		else
			imlib_image_set_format ("jpg");

		/* copy the center block of size SIZE from src to dest. */
		imlib_blend_image_onto_image (src, 0,
			(src_width - SIZE) / 2, (src_height - SIZE) / 2, SIZE, SIZE,
			(dest_width - SIZE) / 2, (dest_height - SIZE) / 2, SIZE, SIZE);

		/* save the image */
		imlib_save_image (argv[3]);
	}
}

Reply via email to