Fix for painting with rgb 16/32f

View: New views
3 Messages — Rating Filter:   Alert me  

Fix for painting with rgb 16/32f

by Cyrille Berger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Anyone want to review the fix for this bug:

https://bugs.kde.org/show_bug.cgi?id=209532

So that I can apply to branch/2.1
--
Cyrille Berger

[fix-209532.diff]

Index: ctlcompositeops/alphabase.ctlt
===================================================================
--- ctlcompositeops/alphabase.ctlt (revision 1045264)
+++ ctlcompositeops/alphabase.ctlt (revision 1045271)
@@ -1,5 +1,7 @@
 @operation(compositeWithmask, inputs=2, arguments=int mask, optional_arguments=int opacity = 255)
 {
+  // @in(0) -> dst
+  // @in(1) -> src
   @alphachannel( float blend = @in(1) / @unit; )
   if(mask != 255)
   {
@@ -16,26 +18,13 @@
     if(newalpha > 0 )
     {
       blend = (blend * @unit) / newalpha;
-    } )
-    compose( @in(0), @in(1), blend, @out);
+    }
+    )
+    compose( @in(1), @in(0), blend, @out);
   }
 }
 
 @operation(compositeWithoutmask, inputs=2, optional_arguments=int opacity = 255)
 {
-  @alphachannel( float blend = @in(1) / @unit; )
-  if( @alphachannel( @in(1) != 0 ) )
-  {
-    if( opacity != 255 )
-    {
-      blend = (blend * opacity) / 255;
-    }
-    @alphachannel( @type newalpha = @in(0) + (( @unit - @in(0)) * blend) / @unit;
-    @out = newalpha;
-    if(newalpha > 0 )
-    {
-      blend = (blend * @unit) / newalpha;
-    } )
-    compose( @in(0), @in(1), blend, @out);
-  }
+  compositeWithmask(@in(0), @in(1), 255, @out, opacity);
 }
Index: tests/KoRgb32fTest.cpp
===================================================================
--- tests/KoRgb32fTest.cpp (revision 1045264)
+++ tests/KoRgb32fTest.cpp (revision 1045271)
@@ -170,6 +170,32 @@
     QCOMPARE(p32f1.blue, 0.750391f);
     QCOMPARE(p32f1.alpha, 1.0f);
 
+    // Test no mask, full opacity, transparent source
+    p32f.red = 0.5; p32f.green = 0.1; p32f.blue = 0.6; p32f.alpha = 0.0;
+    p32f1.red = 0.3; p32f1.green = 0.5; p32f1.blue = 0.8; p32f1.alpha = 1.0;
+    over->composite(p32fPtr1, rgb32f->pixelSize(), p32fPtr, rgb32f->pixelSize(), 0, 0, 1, 1, 255);
+    QCOMPARE(p32f1.red, 0.3f);
+    QCOMPARE(p32f1.green, 0.5f);
+    QCOMPARE(p32f1.blue, 0.8f);
+    QCOMPARE(p32f1.alpha, 1.0f);
+
+    // Test no mask, full opacity, transparent dst
+    p32f.red = 0.5; p32f.green = 0.1; p32f.blue = 0.6; p32f.alpha = 1.0;
+    p32f1.red = 0.3; p32f1.green = 0.5; p32f1.blue = 0.8; p32f1.alpha = 0.0;
+    over->composite(p32fPtr1, rgb32f->pixelSize(), p32fPtr, rgb32f->pixelSize(), 0, 0, 1, 1, 255);
+    QCOMPARE(p32f1.red, 0.5f);
+    QCOMPARE(p32f1.green, 0.1f);
+    QCOMPARE(p32f1.blue, 0.6f);
+    QCOMPARE(p32f1.alpha, 1.0f);
+
+    // Test no mask, full opacity, half-transparent dst
+    p32f.red = 0.5; p32f.green = 0.1; p32f.blue = 0.6; p32f.alpha = 1.0;
+    p32f1.red = 0.3; p32f1.green = 0.5; p32f1.blue = 0.8; p32f1.alpha = 0.5;
+    over->composite(p32fPtr1, rgb32f->pixelSize(), p32fPtr, rgb32f->pixelSize(), 0, 0, 1, 1, 255);
+    QCOMPARE(p32f1.red, 0.5f);
+    QCOMPARE(p32f1.green, 0.1f);
+    QCOMPARE(p32f1.blue, 0.6f);
+    QCOMPARE(p32f1.alpha, 1.0f);
 }
 
 QTEST_KDEMAIN(KoRgb32fTest, NoGUI)
Index: KoCtlCompositeOp.cpp
===================================================================
--- KoCtlCompositeOp.cpp (revision 1045264)
+++ KoCtlCompositeOp.cpp (revision 1045271)
@@ -83,8 +83,8 @@
         KoCtlBuffer src(reinterpret_cast<char*>(const_cast<quint8*>(srcRowStart)), numColumns * colorSpace()->pixelSize());
         KoCtlBuffer dst(reinterpret_cast<char*>(dstRowStart), numColumns * colorSpace()->pixelSize());
         std::list< GTLCore::Buffer* > ops;
+        ops.push_back(&dst);
         ops.push_back(&src);
-        ops.push_back(&dst);
         if (maskRowStart) {
             KoCtlBuffer mask(reinterpret_cast<char*>(const_cast<quint8*>(maskRowStart)), numColumns * sizeof(quint8));
             ops.push_back(&mask);


_______________________________________________
kimageshop mailing list
kimageshop@...
https://mail.kde.org/mailman/listinfo/kimageshop

Re: Fix for painting with rgb 16/32f

by Bugzilla from boud@valdyas.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thursday 05 November 2009, Cyrille Berger wrote:
> Hi,
>
> Anyone want to review the fix for this bug:
>
> https://bugs.kde.org/show_bug.cgi?id=209532
>
> So that I can apply to branch/2.1
>

It _looks_ very reasonable -- but I'm not really into openctl yet. Does it
also fix https://bugs.kde.org/show_bug.cgi?id=213295?

--
Boudewijn Rempt | http://www.valdyas.org
_______________________________________________
kimageshop mailing list
kimageshop@...
https://mail.kde.org/mailman/listinfo/kimageshop

Re: Fix for painting with rgb 16/32f

by Cyrille Berger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thursday 05 November 2009, Boudewijn Rempt wrote:

> On Thursday 05 November 2009, Cyrille Berger wrote:
> > Hi,
> >
> > Anyone want to review the fix for this bug:
> >
> > https://bugs.kde.org/show_bug.cgi?id=209532
> >
> > So that I can apply to branch/2.1
>
> It _looks_ very reasonable -- but I'm not really into openctl yet. Does it
> also fix https://bugs.kde.org/show_bug.cgi?id=213295?
Probably not since I asume enkithan did that after testing my patch. Also part
of that bug is the lack of alpha darken (something to fix in 2.2), and the
other part is some weirdness I did not notice :/ It would need more
investigation.

--
Cyrille Berger
_______________________________________________
kimageshop mailing list
kimageshop@...
https://mail.kde.org/mailman/listinfo/kimageshop