Page 1 of 1

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

Posted: 2006-09-04T18:33:09-07:00
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)));
}

Posted: 2006-09-05T07:33:57-07:00
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.

Posted: 2006-09-06T23:05:33-07:00
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.