Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upDraw image rectangles into each other, with alpha blending #168
Conversation
abonander
reviewed
Nov 25, 2014
| let max_t = max_t.to_f32().unwrap(); | ||
| let (bg_r, bg_g, bg_b, bg_a) = self.channels(); | ||
| let (fg_r, fg_g, fg_b, fg_a) = other.channels(); | ||
| let (bg_r, bg_g, bg_b, bg_a) = (bg_r.to_f32().unwrap() / max_t, bg_g.to_f32().unwrap() / max_t, bg_b.to_f32().unwrap() / max_t, bg_a.to_f32().unwrap() / max_t); |
This comment has been minimized.
This comment has been minimized.
abonander
Nov 25, 2014
Contributor
Do you mind adding some comments explaining the logic here, in this function?
abonander
reviewed
Nov 25, 2014
| fn blend_pixel(&mut self, x: u32, y: u32, pixel: P); | ||
|
|
||
| /// Put an image at a given coordinate (x, y) | ||
| fn put_image<I: GenericImage<P>>(&mut self, x: u32, y: u32, image: &I) { |
This comment has been minimized.
This comment has been minimized.
abonander
Nov 25, 2014
Contributor
This function probably belongs in the imageops module, maybe as:
pub fn overlay<Pb: Pixel, Pt: Pixel>(bottom: &mut GenericImage<P>, top: &GenericImage<S>, x: u32, y: u32)
Maybe consider supporting different blend modes, like add, multiply, subtract, overlay, etc, and overlaying images with differing pixel types?
This comment has been minimized.
This comment has been minimized.
|
I think Maybe a future branch could explore that. Edit: I believe the Piston team prefers PRs to be rebased down to a single commit. |
This comment has been minimized.
This comment has been minimized.
|
I'll have a look at moving things around today. Blend modes should probably wait for another PR, because they are waaaaaay outside of my skill level. |
This comment has been minimized.
This comment has been minimized.
|
@AngryLawyer I think adding some simple functionality is good, because later on we probably need matrix transforms + blend modes as a slower, but more flexible version. |
This comment has been minimized.
This comment has been minimized.
|
Rebased with the feedback on board :) Edit: also, rebasing is terrifying. |
This comment has been minimized.
This comment has been minimized.
|
Good work! +1 from me. |
This comment has been minimized.
This comment has been minimized.
|
Great! |
bvssvni
added a commit
that referenced
this pull request
Nov 27, 2014
bvssvni
merged commit 266f2ba
into
image-rs:master
Nov 27, 2014
1 check passed
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
great work! |
AngryLawyer commentedNov 25, 2014
Hello!
For a project I'm working on, I needed a nice way of drawing images into other images. After doing the base case, I realised it wasn't going to handle alpha channels, so I've implemented something to solve that too.
Low-level image manipulation isn't my strongest skill, so it might be a bit naive, but it works as a basic implementation.
Let me know if you need any changes.