From c70d864c02e69cf800c10f422c3b356dbe742dc2 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Fri, 20 Jul 2018 14:09:44 -0700 Subject: [PATCH] Fix support for premultiplied alpha in gaussian blur for now (Cairo surfaces are always premultiplied) --- src/lime/_internal/graphics/ImageDataUtil.hx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lime/_internal/graphics/ImageDataUtil.hx b/src/lime/_internal/graphics/ImageDataUtil.hx index d2077a11b..121501e2a 100644 --- a/src/lime/_internal/graphics/ImageDataUtil.hx +++ b/src/lime/_internal/graphics/ImageDataUtil.hx @@ -511,11 +511,17 @@ class ImageDataUtil { // TODO: Support sourceRect better, do not modify sourceImage, create C++ implementation for native - if (image.buffer.premultiplied || sourceImage.buffer.premultiplied) { - // TODO: Better handling of premultiplied alpha - throw "Pre-multiplied bitmaps are not supported"; + // TODO: Faster approach + var imagePremultiplied = image.premultiplied; + var sourceImagePremultiplied = sourceImage.premultiplied; + if (imagePremultiplied) image.premultiplied = false; + if (sourceImagePremultiplied) sourceImage.premultiplied = false; - } + // if (image.buffer.premultiplied || sourceImage.buffer.premultiplied) { + // // TODO: Better handling of premultiplied alpha + // throw "Pre-multiplied bitmaps are not supported"; + + // } var boxesForGauss = function (sigma:Float, n:Int):Array { var wIdeal = Math.sqrt((12*sigma*sigma/n)+1); // Ideal averaging filter width @@ -665,6 +671,9 @@ class ImageDataUtil { image.version++; sourceImage.dirty = true; sourceImage.version++; + + if (imagePremultiplied) image.premultiplied = true; + if (sourceImagePremultiplied) sourceImage.premultiplied = true; if (imgB == image.data) return image; return sourceImage;