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

Add BGRA and BGR support. #666

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -59,6 +59,8 @@ All image format decoders implement the ```ImageDecoder``` trait which provides
```image``` provides the following pixel types:
+ **Rgb**: RGB pixel
+ **Rgba**: RGBA pixel
+ **Bgr**: BGR pixel
+ **Bgra**: BGRA pixel
+ **Luma**: Grayscale pixel
+ **LumaA**: Grayscale with alpha

Expand Down
14 changes: 12 additions & 2 deletions src/buffer.rs
Expand Up @@ -6,7 +6,7 @@ use std::io;
use num_traits::Zero;

use traits::Primitive;
use color::{ Rgb, Rgba, Luma, LumaA, FromColor, ColorType };
use color::{ Bgr, Bgra, Rgb, Rgba, Luma, LumaA, FromColor, ColorType };
use image::GenericImage;
use dynimage::save_buffer;
use utils::expand_packed;
Expand Down Expand Up @@ -64,6 +64,12 @@ pub trait Pixel: Copy + Clone {
/// Convert this pixel to RGB with an alpha channel
fn to_rgba(&self) -> Rgba<Self::Subpixel>;

/// Convert this pixel to BGR
fn to_bgr(&self) -> Bgr<Self::Subpixel>;

/// Convert this pixel to BGRA with an alpha channel
fn to_bgra(&self) -> Bgra<Self::Subpixel>;

/// Convert this pixel to luma
fn to_luma(&self) -> Luma<Self::Subpixel>;

Expand Down Expand Up @@ -609,11 +615,15 @@ pub type RgbaImage = ImageBuffer<Rgba<u8>, Vec<u8>>;
pub type GrayImage = ImageBuffer<Luma<u8>, Vec<u8>>;
/// Sendable grayscale + alpha channel image buffer
pub type GrayAlphaImage = ImageBuffer<LumaA<u8>, Vec<u8>>;
/// Sendable Bgr image buffer
pub type BgrImage = ImageBuffer<Bgr<u8>, Vec<u8>>;
/// Sendable Bgr + alpha channel image buffer
pub type BgraImage = ImageBuffer<Bgra<u8>, Vec<u8>>;

#[cfg(test)]
mod test {

use super::{ImageBuffer, RgbImage};
use super::{ImageBuffer, RgbImage, ConvertBuffer, Pixel, GrayImage};
use color;
#[cfg(feature = "benchmarks")]
use test;
Expand Down