After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 513812 - Optimize gdk_cairo_set_source_pixbuf() alpha multiplication loop
Optimize gdk_cairo_set_source_pixbuf() alpha multiplication loop
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Backend: X11
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2008-02-02 00:07 UTC by Behdad Esfahbod
Modified: 2013-09-09 16:08 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
sample code (1.17 KB, text/x-python)
2008-02-02 00:08 UTC, Behdad Esfahbod
  Details
Updated code (1.35 KB, text/plain)
2008-02-02 00:23 UTC, Behdad Esfahbod
  Details
the oneline fix (408 bytes, patch)
2013-07-12 17:23 UTC, Rafał Mużyło
none Details | Review

Description Behdad Esfahbod 2008-02-02 00:07:35 UTC
Attaching python code showing how the alpha multiplication loop in gdk_cairo_set_source_pixbuf() can be optimized.  It also "fixes" the formula, which is a bit wrong for some cases.

I'm not sure how the branch mipacts performance, but it may be a good idea to special case alpha=0 and alpha=255.  The optimization shown in the code is real regardless.
Comment 1 Behdad Esfahbod 2008-02-02 00:08:34 UTC
Created attachment 104232 [details]
sample code
Comment 2 Behdad Esfahbod 2008-02-02 00:23:43 UTC
Created attachment 104234 [details]
Updated code
Comment 3 Behdad Esfahbod 2008-02-08 21:02:57 UTC
Also see this thread:

  http://lists.cairographics.org/archives/cairo/2008-February/012958.html
Comment 4 Rafał Mużyło 2012-06-05 19:38:41 UTC
So, setting the issue of optimization aside, could the formula for conversion be fixed ?
Sure, it's wrong in a very low number of cases and it doesn't seem to get worse with iterated cairo_surface -> GdkPixbuf conversions, but this code tends to get cargo culted.
*Please* ?
Comment 5 Rafał Mużyło 2012-07-10 10:28:35 UTC
You know what's both amusing and annoying about this little problem ?

About every other part of gtk already uses the correct formula.

in gtk+-2.24: i.e. in gdk/gdkdraw.c - static void composite (guchar *src_buf, gint src_rowstride, guchar *dest_buf, gint dest_rowstride, gint width, gint height)
in gdk-pixbuf 2.26: i.e. in gdk-pixbuf/pixops/pixops.c - pixops_composite_nearest
Comment 6 Behdad Esfahbod 2012-07-11 19:19:24 UTC
(In reply to comment #5)
> You know what's both amusing and annoying about this little problem ?

Maybe you can change your tone, and instead of sounding like a troll (and getting ignored), raise the same points in a constructive conversation kind of way.  Maybe someone would then take a few minutes to use your messages to convince themselves that the fix is correct, and commit it.



> About every other part of gtk already uses the correct formula.
> 
> in gtk+-2.24: i.e. in gdk/gdkdraw.c - static void composite (guchar *src_buf,
> gint src_rowstride, guchar *dest_buf, gint dest_rowstride, gint width, gint
> height)
> in gdk-pixbuf 2.26: i.e. in gdk-pixbuf/pixops/pixops.c -
> pixops_composite_nearest
Comment 7 Rafał Mużyło 2012-07-12 15:01:10 UTC
Perhaps if anyone was wiling to listen instead of being sure they were right those five or so years ago...

I already said that both the originally referenced article *and* pixman code confirm this. Now, it's even gtk+ code that does. See also https://bugs.freedesktop.org/show_bug.cgi?id=4096 and its result: http://cgit.freedesktop.org/cairo/commit/src/cairo-png.c?id=b9da101879afc6ab960e43f94d1e0a2fc10b3aac

I *can* be rational, if the other party also is.
Comment 8 Behdad Esfahbod 2012-07-12 19:05:46 UTC
(In reply to comment #7)

> I *can* be rational, if the other party also is.

Right now there is no other party.  If you are talking to me, I clearly said multiple times that I don't have time for this.  And I have not seen any behavior from any other gtk+ developer on this bug that you can call irrational.
Comment 9 Rafał Mużyło 2012-07-17 21:06:31 UTC
We're basically talking about a typo/thinko fix and the resistance is as if it was a core change.
Comment 10 Rafał Mużyło 2013-07-12 17:23:07 UTC
Created attachment 249031 [details] [review]
the oneline fix

...technically, it's a patch, but seriously...
Comment 11 Behdad Esfahbod 2013-09-05 22:44:00 UTC
Ok, I convinced myself that the oneline fix is correct.  Pushed to master.
Comment 12 Rafał Mużyło 2013-09-09 04:16:25 UTC
(In reply to comment #11)
> Ok, I convinced myself that the oneline fix is correct.  Pushed to master.

As I said on irc: thank you, but for completeness, this should be picked into 2.24 too.
Comment 13 Behdad Esfahbod 2013-09-09 15:50:48 UTC
I don't know where the 2.24 branch is these days.
Comment 14 Emmanuele Bassi (:ebassi) 2013-09-09 16:01:07 UTC
gtk-2-24, in the gtk+ repository.
Comment 15 Behdad Esfahbod 2013-09-09 16:08:46 UTC
Thanks.  Pushed.