From bd92f9f406c03f2099dcbab6f0d00840a2fb6420 Mon Sep 17 00:00:00 2001
From: Claudiu Cristea <clau.cristea@gmail.com>
Date: Thu, 7 Apr 2011 09:51:38 -0400
Subject: [PATCH] #1118490 by claudiu.cristea: Fixed Rounded corners are dirty.

---
 canvasactions.inc |   35 ++++++++++++++++++++---------------
 1 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/canvasactions.inc b/canvasactions.inc
index 1388078..7fbfce8 100755
--- a/canvasactions.inc
+++ b/canvasactions.inc
@@ -757,25 +757,30 @@ function imageapi_gd_image_roundedcorners(&$image, $action = array()) {
         $ix = floor($is_right ? $width-$dx : $dx);
         $iy = floor($is_bottom ? $height-$dy : $dy);
         
-        $opacity = _canvasactions_roundedcorners_pixel_opacity($dx, $dy, $r);
-        if ($opacity >= 1) {
-          // we can finish this row,
-          // all following pixels will be fully opaque.
-          break;
-        }
-        
         // Color lookup at ($ix, $iy).
         $color_ix = imagecolorat($im, $ix, $iy);
         $color = imagecolorsforindex($im, $color_ix);
-        
-        if (isset($rgba['alpha'])) {
-          $color['alpha'] = 127 - round($opacity * (127 - $color['alpha']));
-        } 
-        else {
-          $color['alpha'] = 127 - round($opacity * 127);
+
+        // Do not process opacity if transparency is 100%. Just jump...
+        // Opacity is always 0 on a transparent source pixel.
+        if ($color['alpha'] != 127) {
+          $opacity = _canvasactions_roundedcorners_pixel_opacity($dx, $dy, $r);
+          if ($opacity >= 1) {
+            // we can finish this row,
+            // all following pixels will be fully opaque.
+            break;
+          }
+          
+          
+          if (isset($color['alpha'])) {
+            $color['alpha'] = 127 - round($opacity * (127 - $color['alpha']));
+          } 
+          else {
+            $color['alpha'] = 127 - round($opacity * 127);
+          }
+          // Value should not be more than 127, and not less than 0.
+          $color['alpha'] = ($color['alpha'] > 127) ? 127 : (($color['alpha'] < 0) ? 0 : $color['alpha']);
         }
-        // Value should not be more than 127, and not less than 0.
-        $color['alpha'] = ($color['alpha'] > 127) ? 127 : (($color['alpha'] < 0) ? 0 : $color['alpha']);
         $color_ix = imagecolorallocatealpha($im, $color['red'], $color['green'], $color['blue'], $color['alpha']);
         imagesetpixel($im, $ix, $iy, $color_ix);
       }
-- 
1.5.6.5

