From 88ca4b9901138d63f4664e41622ddeef8ea1a07f Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Wed, 12 Jan 2011 10:20:27 +0000 Subject: [PATCH] CoreGraphics alpha-channel clipping fix. --- juce_amalgamated.cpp | 13 ++++++++----- src/gui/graphics/imaging/juce_Image.cpp | 11 ++++++----- src/native/mac/juce_mac_CoreGraphicsContext.mm | 1 + 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index d070711010..b51b1a4a13 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -95464,7 +95464,8 @@ const Image Image::convertedToFormat (PixelFormat newFormat) const if (image == 0 || newFormat == image->format) return *this; - Image newImage (newFormat, image->width, image->height, false, image->getType()); + const int w = image->width, h = image->height; + Image newImage (newFormat, w, h, false, image->getType()); if (newFormat == SingleChannel) { @@ -95474,15 +95475,15 @@ const Image Image::convertedToFormat (PixelFormat newFormat) const } else { - const BitmapData destData (newImage, 0, 0, image->width, image->height, true); - const BitmapData srcData (*this, 0, 0, image->width, image->height); + const BitmapData destData (newImage, 0, 0, w, h, true); + const BitmapData srcData (*this, 0, 0, w, h); - for (int y = 0; y < image->height; ++y) + for (int y = 0; y < h; ++y) { const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y); uint8* dst = destData.getLinePointer (y); - for (int x = image->width; --x >= 0;) + for (int x = w; --x >= 0;) { *dst++ = src->getAlpha(); ++src; @@ -266125,6 +266126,7 @@ public: applyTransform (t.inverted()); flip(); + CGContextFlush (context); CGImageRelease (image); lastClipRectIsValid = false; } @@ -270821,6 +270823,7 @@ public: applyTransform (t.inverted()); flip(); + CGContextFlush (context); CGImageRelease (image); lastClipRectIsValid = false; } diff --git a/src/gui/graphics/imaging/juce_Image.cpp b/src/gui/graphics/imaging/juce_Image.cpp index 869138054f..b6e82e2a33 100644 --- a/src/gui/graphics/imaging/juce_Image.cpp +++ b/src/gui/graphics/imaging/juce_Image.cpp @@ -209,7 +209,8 @@ const Image Image::convertedToFormat (PixelFormat newFormat) const if (image == 0 || newFormat == image->format) return *this; - Image newImage (newFormat, image->width, image->height, false, image->getType()); + const int w = image->width, h = image->height; + Image newImage (newFormat, w, h, false, image->getType()); if (newFormat == SingleChannel) { @@ -219,15 +220,15 @@ const Image Image::convertedToFormat (PixelFormat newFormat) const } else { - const BitmapData destData (newImage, 0, 0, image->width, image->height, true); - const BitmapData srcData (*this, 0, 0, image->width, image->height); + const BitmapData destData (newImage, 0, 0, w, h, true); + const BitmapData srcData (*this, 0, 0, w, h); - for (int y = 0; y < image->height; ++y) + for (int y = 0; y < h; ++y) { const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y); uint8* dst = destData.getLinePointer (y); - for (int x = image->width; --x >= 0;) + for (int x = w; --x >= 0;) { *dst++ = src->getAlpha(); ++src; diff --git a/src/native/mac/juce_mac_CoreGraphicsContext.mm b/src/native/mac/juce_mac_CoreGraphicsContext.mm index 4b42d78f7b..a01a4ae231 100644 --- a/src/native/mac/juce_mac_CoreGraphicsContext.mm +++ b/src/native/mac/juce_mac_CoreGraphicsContext.mm @@ -277,6 +277,7 @@ public: applyTransform (t.inverted()); flip(); + CGContextFlush (context); CGImageRelease (image); lastClipRectIsValid = false; }