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

Added support to get all pixels(x,y,r,g,b) or specfic pixel. #19

Closed
wants to merge 1 commit into from

Conversation

WilgnerFSDev
Copy link

I added two functions to get all or individual pixels of the image returning the position and the RGB.
I also updated the readme with the 2 examples (all pixels and a specific pixel).

I hope you see the benefit and believe it's an improvement. Any questions please contact me and feel free to edit the code (today is my first day with rust so suggestions for improvement are very welcome).

@nashaofu
Copy link
Owner

nashaofu commented Sep 21, 2022

Maybe storing a copy of the original RGBA value is better,it is easy to do other processing on the image without decode, such as cropping.

pub struct Image {
  width: u32,
  height: u32,
  buffer: Vec<u8>,
  rgba: Vec<u8>, // The original rgba data of the picture
}

get_pixel also easy to implement.

pub fn get_pixel(&self, x: u32, y: u32) -> Pixel {
  let index = y * self.width + x;
  Pixel {
    x,
    y,
    r: self.rgba.get(index),
    g: self.rgba.get(index + 1),
    b: self.rgba.get(index + 2),
    a: self.rgba.get(index + 3),
  }
}

@WilgnerFSDev
Copy link
Author

WilgnerFSDev commented Sep 22, 2022

In my project I need all pixels (positions and rgb) so I can pass the pixels to my algorithm.
I have stored it in a list in case in the future someone wants to do other types of operations.

Before editing, you commented if it is really necessary to add this feature, in fact it is something very specific for me, I decided send a pull request in case someone is going through the same thing or a similar situation to mine. Feel free to accept or not, since is really specific situation, anyways thanks for you time and by the library, it's really useful for me.

@c-h-johnson
Copy link
Contributor

@nashaofu nashaofu closed this Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants