Skip to content

Conversation

@NicoWeio
Copy link
Contributor

@NicoWeio NicoWeio commented Aug 15, 2022

Overview: What does this pull request change?

Methods like set_opacity, fade and set_color now preserve transparent areas in the image instead of overriding them.

Note: This depends on #2924.

Motivation and Explanation: Why and how do your changes improve the library?

The previous behavior was probably not intended in the first place, thus a bug.
If I add a PNG icon with transparency, for example, I don't expect the formerly transparent background to become (mostly) black when calling set_opacity(0.9).

Further Information and Comments

My Discord message

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

Previously, calling set_opacity(alpha) would have replaced the original alpha channel, thus making previously invisible parts visible.
@kolibril13 kolibril13 self-requested a review August 15, 2022 16:18
@kolibril13
Copy link
Member

Hi @NicoWeio,
thanks a lot for this pull request, that's a great improvement to the library.
I've just tested the code locally and it works, and also the implementation looks good to me!
One question:
Is there a reason why you use once

int(self.orig_alpha_pixel_array * alpha)

and the other time

(self.orig_alpha_pixel_array * alpha).astype(int)

?
From my side, it can be merged like this, I just keep the pr open so that other potential reviewers can have a look.
One nice extra to this pr would be a new example in the docs, I was thinking of e.g. this:

class Example1(Scene):
    def construct(self):
        im1 = ImageMobject("translate.png").scale(5)
        self.add(im1)
        self.wait(0.7)
        im1.set_opacity(0.7)

        self.play(im1.animate.set_color(YELLOW))
        self.play(FadeOut(im1))
Example1@2022-08-15@18-26-18.mp4

@NicoWeio
Copy link
Contributor Author

Thanks for taking a look at it!

In fact, int(self.orig_alpha_pixel_array * alpha) didn't even work, since self.orig_alpha_pixel_array isn't a scalar. Secondly, I didn't include it in my test. Oops. 😄
Now, I rely on implicit conversion to int, which definitely works.

I'm not sure how to reference our PNG file in the example, otherwise I'd gladly include it.

@kolibril13
Copy link
Member

You can use either this NumPy array then:
https://docs.manim.community/en/stable/reference/manim.mobject.types.image_mobject.ImageMobject.html#imagefromarray
or alternatively you can add assets to the docs like here https://docs.manim.community/en/stable/reference/manim.scene.scene.Scene.html?highlight=Soundexample#soundexample

@NicoWeio
Copy link
Contributor Author

NicoWeio commented Aug 15, 2022

Thanks for the pointers.

While creating this PR, I noticed another bug, which I just opened #2924 for.
And while investigating said bug, I found that pixel_array is explicitly excluded from hashing.
Now that I introduced orig_alpha_pixel_array in this PR, I think we should wait with merging it until #2924 is sorted out conceptually, so that either orig_alpha_pixel_array is exempt from hashing, too, or pixel_array no longer is.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2022

This PR/issue depends on:

@behackl behackl marked this pull request as draft September 24, 2022 13:57
@behackl
Copy link
Member

behackl commented Jul 13, 2024

Closing this as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Rejected

Development

Successfully merging this pull request may close these issues.

3 participants