[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/koffice/1.6/koffice/krita
From:       Cyrille Berger <cyb () lepi ! org>
Date:       2006-10-23 22:26:39
Message-ID: 1161642399.540509.13467.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 598554 by berger:

make the convolution filter behave slightly better with alpha (at least for rgb U8)

 M  +28 -9     colorspaces/rgb_u8/kis_rgb_colorspace.cc  
 M  +3 -2      plugins/filters/convolutionfilters/kis_convolution_filter.cc  


--- branches/koffice/1.6/koffice/krita/colorspaces/rgb_u8/kis_rgb_colorspace.cc \
#598553:598554 @@ -127,26 +127,45 @@
 void KisRgbColorSpace::convolveColors(Q_UINT8** colors, Q_INT32* kernelValues, \
KisChannelInfo::enumChannelFlags channelFlags, Q_UINT8 *dst, Q_INT32 factor, Q_INT32 \
offset, Q_INT32 nColors) const  {
     Q_INT32 totalRed = 0, totalGreen = 0, totalBlue = 0, totalAlpha = 0;
-
+    Q_INT32 totalWeight = 0, totalWeightTransparent = 0;
     while (nColors--)
     {
         Q_INT32 weight = *kernelValues;
 
         if (weight != 0) {
-            totalRed += (*colors)[PIXEL_RED] * weight;
-            totalGreen += (*colors)[PIXEL_GREEN] * weight;
-            totalBlue += (*colors)[PIXEL_BLUE] * weight;
+            if((*colors)[PIXEL_ALPHA] == 0)
+            {
+              totalWeightTransparent += weight;
+            } else {
+              totalRed += (*colors)[PIXEL_RED] * weight;
+              totalGreen += (*colors)[PIXEL_GREEN] * weight;
+              totalBlue += (*colors)[PIXEL_BLUE] * weight;
+            }
             totalAlpha += (*colors)[PIXEL_ALPHA] * weight;
+            totalWeight += weight;
         }
         colors++;
         kernelValues++;
     }
 
-
-    if (channelFlags & KisChannelInfo::FLAG_COLOR) {
-        dst[PIXEL_RED] = CLAMP((totalRed / factor) + offset, 0, Q_UINT8_MAX);
-        dst[PIXEL_GREEN] = CLAMP((totalGreen / factor) + offset, 0, Q_UINT8_MAX);
-        dst[PIXEL_BLUE] =  CLAMP((totalBlue / factor) + offset, 0, Q_UINT8_MAX);
+    if(totalWeightTransparent == 0)
+    {
+      if (channelFlags & KisChannelInfo::FLAG_COLOR) {
+          dst[PIXEL_RED] = CLAMP((totalRed / factor) + offset, 0, Q_UINT8_MAX);
+          dst[PIXEL_GREEN] = CLAMP((totalGreen / factor) + offset, 0, Q_UINT8_MAX);
+          dst[PIXEL_BLUE] =  CLAMP((totalBlue / factor) + offset, 0, Q_UINT8_MAX);
+      }
+      if (channelFlags & KisChannelInfo::FLAG_ALPHA) {
+          dst[PIXEL_ALPHA] = CLAMP((totalAlpha/ factor) + offset, 0, Q_UINT8_MAX);
+      }
+    } else if(totalWeightTransparent != totalWeight) {
+      Q_INT32 a = factor * ( totalWeight - totalWeightTransparent );
+      
+      if (channelFlags & KisChannelInfo::FLAG_COLOR) {
+          dst[PIXEL_RED] = CLAMP((totalRed * totalWeight  / a) + offset, 0, \
Q_UINT8_MAX); +          dst[PIXEL_GREEN] = CLAMP((totalGreen * totalWeight / a) + \
offset, 0, Q_UINT8_MAX); +          dst[PIXEL_BLUE] =  CLAMP((totalBlue * totalWeight \
/ a) + offset, 0, Q_UINT8_MAX); +      }
     }
     if (channelFlags & KisChannelInfo::FLAG_ALPHA) {
         dst[PIXEL_ALPHA] = CLAMP((totalAlpha/ factor) + offset, 0, Q_UINT8_MAX);
--- branches/koffice/1.6/koffice/krita/plugins/filters/convolutionfilters/kis_convolution_filter.cc \
#598553:598554 @@ -112,8 +112,9 @@
 
     KisKernelSP kernel = ((KisConvolutionConfiguration*)configuration)->matrix();
 
-    painter.applyMatrix(kernel, rect.x(), rect.y(), rect.width(), rect.height(), \
                BORDER_REPEAT);
-
+    painter.applyMatrix(kernel, rect.x(), rect.y(), rect.width(), rect.height(), \
BORDER_REPEAT, KisChannelInfo::FLAG_COLOR ); +    painter.applyMatrix(kernel, \
rect.x(), rect.y(), rect.width(), rect.height(), BORDER_REPEAT, \
KisChannelInfo::FLAG_ALPHA ); // THAT'S SUXX ^10 ! +    
     if (painter.cancelRequested()) {
         cancel();
     }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic