سؤال

As ClutterTexture is now marked as deprecated, I followed the recommendation and replaced it with a ClutterActor that has it's content set to a pixbuf.

from gi.repository import Clutter, GdkPixbuf, Cogl

Clutter.init([])
stage = Clutter.Stage()
stage.set_size(600, 300)

# old style
texture_actor = Clutter.Texture(filename='icon_big_a.png')
texture_actor.set_opacity(127)
stage.add_child(texture_actor)

# replacement because ClutterTexture is deprecated
pixbuf = GdkPixbuf.Pixbuf.new_from_file('icon_big_b.png')
pixel_format = Cogl.PixelFormat.RGBA_8888 if pixbuf.get_has_alpha() \
    else Cogl.PixelFormat.RGB_888

image = Clutter.Image()
image.set_data(
    pixbuf.get_pixels(),
    pixel_format,
    pixbuf.get_width(),
    pixbuf.get_height(),
    pixbuf.get_rowstride(),
)

image_actor = Clutter.Actor()
image_actor.set_content_scaling_filters(
    Clutter.ScalingFilter.TRILINEAR,
    Clutter.ScalingFilter.LINEAR
)
image_actor.set_content(image)
image_actor.set_size(pixbuf.get_width(), pixbuf.get_height())
image_actor.set_opacity(127)
image_actor.move_by(300, 0)
stage.add_child(image_actor)

stage.show()
Clutter.main()

Everything works but when I change the actors opacity to 127, it darkens the background even where it's white.

Here is a git repo with code and screenshot of the problem

When I set the opacity to 255 everything looks like it should, white is then white.

هل كانت مفيدة؟

المحلول

you need to update your version of Clutter to a version greater than, or equal to, 1.16.2 (the latest 1.16 release is 1.16.4). there was a bug in the ClutterImage that caused the blend color to be premultiplied unnecessarily:

https://git.gnome.org/browse/clutter/commit/?h=clutter-1.16&id=32ccff85254f731cef6dab88d302eb3dcba93887

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top