Newish drawImage problem


So, I decided to sync with the current JUCE tip as of this Monday, and part of my plugin’s compositing broke. I am running MacOS 10.5.

The symptom is: drawing sub-rects of an image using drawImage results in drawn rectangles that are the proper width, but only four pixels high. After looking over my code I’ve reduced the drawing code to the following simple example. To reproduce, replace any component’s paint method with this:

void MainComponent::paint (Graphics& g)
	const int height = 128;
	const int width = 128;

	Image imageB(Image::ARGB, height, width, false);

	// draw colorful test image
	for (int j = 0; j < height; j++)
		for(int i = 0; i < width; i++)
			float hue = (float)i / width;
			Colour dest(hue, 1.f, 1.f, 1.f);			
			imageB.setPixelAt(i, j, dest);

	// copy squares of the test image
	int px = 20;
	int py = 20;
	int margin = 10;
	int w, h;
	for(int x = 1; x < 10; x++)
		w = x*6;
		h = x*6;
		g.drawImage (&imageB, px, py, w, h,
			 0, 0, w, h, false);
		px = px + w + margin;

Instead of the series of squares one would expect, I get this image.

It’s only the code path in CoreGraphicsContext::drawImage() with (srcClip != sourceImage.getBounds()) that is breaking. When these rects are equal, the image draws fine. It looks like CGImageCreateWithImageInRect and CGContextDrawImage are getting called with reasonable parameters.

That’s all for tonight. My next step would be to sanity-check the CGImages, I guess.


Good catch, thanks! Normally I use Image::createNativeImage to create my image objects, which works fine (and should render faster, BTW), but you hit a bug in the code that turns a non-native Image into a CGImage. It’s a simple fix, I’ll check it in shortly…


And… fixed while I slept. Nice!