Skip to content
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

Draw image rectangles into each other, with alpha blending #168

Merged
merged 1 commit into from Nov 27, 2014

Conversation

@AngryLawyer
Copy link
Contributor

commented Nov 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.

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.

Copy link
@abonander

abonander Nov 25, 2014

Contributor

Do you mind adding some comments explaining the logic here, in this function?

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.

Copy link
@abonander

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?

@abonander

This comment has been minimized.

Copy link
Contributor

commented Nov 25, 2014

I think Pixel::blend is a perfect test case for SIMD, as is a lot of this repo.

Maybe a future branch could explore that.

Edit: I believe the Piston team prefers PRs to be rebased down to a single commit.

@AngryLawyer

This comment has been minimized.

Copy link
Contributor Author

commented Nov 26, 2014

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.

@bvssvni

This comment has been minimized.

Copy link
Contributor

commented Nov 26, 2014

@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.

@AngryLawyer

This comment has been minimized.

Copy link
Contributor Author

commented Nov 26, 2014

Rebased with the feedback on board :)

Edit: also, rebasing is terrifying.

@abonander

This comment has been minimized.

Copy link
Contributor

commented Nov 26, 2014

Good work! +1 from me.

@bvssvni

This comment has been minimized.

Copy link
Contributor

commented Nov 27, 2014

Great!

bvssvni added a commit that referenced this pull request Nov 27, 2014

Merge pull request #168 from AngryLawyer/master
Draw image rectangles into each other, with alpha blending

@bvssvni bvssvni merged commit 266f2ba into image-rs:master Nov 27, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
@AngryLawyer

This comment has been minimized.

Copy link
Contributor Author

commented Nov 27, 2014

❤️

@ccgn

This comment has been minimized.

Copy link
Contributor

commented Nov 27, 2014

great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.