Difference Between composite() and draw()? [magick++]

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mankyd

Difference Between composite() and draw()? [magick++]

Post by mankyd »

I'm trying to create a mosaic of square images, some repeated mutliple times. Is there a functional difference between making calls to compsite(Image(file_name), _x, _y, OverCompositeOp) vs. draw(DrawableCompsiteImage(_x, _y, file_name))?

I am, of course, looking to optimize speed and memory usage. There is no actual overlap between the images I am putting together, but the order that I am drawing them might be non-linear, i.e. I might draw one in the top left and the bottom right, then a different one in the middle.

Here is my code as I have it now. "tiles" is a STL list of a class I wrote, sorted by each tile's id. "out" is the destination image. "ts" is a list of Drawables.

Code: Select all

prev_id = -1;
tl = NULL;
for (tiles_it = tiles.begin(); tiles_it != tiles.end(); tiles_it++) {

	//if we've come upon a new id, draw out whatever we currently have
	if ((*tiles_it).id() != prev_id) {
		if (ts.empty() == false) {
			out.draw(ts);
			ts.clear();
		}

		prev_id = (*tiles_it).id();

		//clean up the old image
		if (tl != NULL)
			tl->remove_image(base_size);

		//get the new image
		tl = &(*tiles_it);

	}

	//push back a new drawable for every tile we have
	ts.push_back(DrawableCompositeImage((*tiles_it).x() * base_size, (*tiles_it).y() * base_size, tl->get_image(base_size)));
}
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

Both methods end up calling CompositeImage() so the cost should be proportional. The only way to be sure is to try both methods.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

However -draw probably is doing more parseing work to do the same job, better to try to use composite more directly.

the only time I prefer draw over composite is when I am overlaying a single image over a whoel sequence of images. This is especially the case with animation processing, OR using the "mogrify" batch processing comamnd.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply