-
Notifications
You must be signed in to change notification settings - Fork 25
Add PNG support for transparency #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
AmitMY
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Good work! Minor modifications required/should be discussed.
| colors = [np.array(c[::-1]) for c in component.colors] | ||
|
|
||
| @lru_cache(maxsize=None) | ||
| def _point_color(p_i: int): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would add transparency=False, since it can be that we don't want it.
| opacity = c[p_i + idx] | ||
| np_color = colors[p_i % len(component.colors)] * opacity + (1 - opacity) * background_color | ||
| np_color = colors[p_i % len(component.colors)] * opacity + (1 - opacity) * background_color[:3] | ||
| np_color = np.append(np_color, opacity * 255) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only when transparency==True
| return img | ||
|
|
||
| def draw(self, background_color: Tuple[int, int, int] = (255, 255, 255), max_frames: int = None): | ||
| def draw(self, background_color: Tuple[int, int, int] = (255, 255, 255), max_frames: int = None, alpha: int = 0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too I think we should have transparency, not alpha, because this will (IMO) break support for video exports
| background_color += (alpha,) | ||
| int_frames = np.array(np.around(self.pose.body.data.data), dtype="int32") | ||
| background = np.full((self.pose.header.dimensions.height, self.pose.header.dimensions.width, 3), | ||
| background = np.full((self.pose.header.dimensions.height, self.pose.header.dimensions.width, 4), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and then I'd split this into two cases, transparent or not
| duration=1000 / self.pose.body.fps, | ||
| loop=0) | ||
|
|
||
| def save_png(self, f_name: str, frames: Iterable[np.ndarray]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think save_png and save_gif could be both using save_image(f_name: str, frames: ..., format="PNG", transparency=False) for example. right now the code is mostly duplicate
| images[0].save(f_name, | ||
| format="GIF", | ||
| append_images=images, | ||
| append_images=images[1:], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch!
|
All the changes requested are fixed |
AmitMY
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absolutely fantastic.
Issue for more info : #82