Skip to content

Commit

Permalink
Merge pull request #1085 from aschampion/features/16bpc-dynimage-squash
Browse files Browse the repository at this point in the history
16 bit per channel image buffers and dynamic images
  • Loading branch information
HeroicKatora committed Dec 12, 2019
2 parents 3a7eb68 + 5dae1fd commit d3b3133
Show file tree
Hide file tree
Showing 18 changed files with 669 additions and 98 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Expand Up @@ -20,13 +20,14 @@ name = "image"
path = "./src/lib.rs"

[dependencies]
byteorder = "1.2.1"
bytemuck = "1"
byteorder = "1.3.2"
num-iter = "0.1.32"
num-rational = { version = "0.2.1", default-features = false }
num-traits = "0.2.0"
gif = { version = "0.10.0", optional = true }
jpeg = { package = "jpeg-decoder", version = "0.1", default-features = false, optional = true }
png = { version = "0.15", optional = true }
png = { version = "0.15.2", optional = true }
scoped_threadpool = { version = "0.1", optional = true }
tiff = { version = "0.4.0", optional = true }

Expand Down
14 changes: 13 additions & 1 deletion src/bmp/encoder.rs
Expand Up @@ -2,7 +2,7 @@ use byteorder::{LittleEndian, WriteBytesExt};
use std::io::{self, Write};

use color;
use image::{ImageError, ImageResult};
use image::{ImageEncoder, ImageError, ImageResult};

const BITMAPFILEHEADER_SIZE: u32 = 14;
const BITMAPINFOHEADER_SIZE: u32 = 40;
Expand Down Expand Up @@ -213,6 +213,18 @@ impl<'a, W: Write + 'a> BMPEncoder<'a, W> {
}
}

impl<'a, W: Write> ImageEncoder for BMPEncoder<'a, W> {
fn write_image(
mut self,
buf: &[u8],
width: u32,
height: u32,
color_type: color::ColorType,
) -> ImageResult<()> {
self.encode(buf, width, height, color_type)
}
}

fn get_unsupported_error_message(c: color::ColorType) -> String {
format!(
"Unsupported color type {:?}. Supported types: RGB(8), RGBA(8), Gray(8), GrayA(8).",
Expand Down
24 changes: 17 additions & 7 deletions src/buffer.rs
Expand Up @@ -8,7 +8,7 @@ use color::{ColorType, FromColor, Luma, LumaA, Rgb, Rgba, Bgr, Bgra};
use flat::{FlatSamples, SampleLayout};
use dynimage::{save_buffer, save_buffer_with_format};
use image::{GenericImage, GenericImageView, ImageFormat, ImageResult};
use traits::Primitive;
use traits::{EncodableLayout, Primitive};
use utils::expand_packed;

/// A generalized pixel.
Expand Down Expand Up @@ -745,8 +745,9 @@ where

impl<P, Container> ImageBuffer<P, Container>
where
P: Pixel<Subpixel = u8> + 'static,
Container: Deref<Target = [u8]>,
P: Pixel + 'static,
[P::Subpixel]: EncodableLayout,
Container: Deref<Target = [P::Subpixel]>,
{
/// Saves the buffer to a file at the path specified.
///
Expand All @@ -759,7 +760,7 @@ where
// This is valid as the subpixel is u8.
save_buffer(
path,
self,
self.as_bytes(),
self.width(),
self.height(),
<P as Pixel>::COLOR_TYPE,
Expand All @@ -769,8 +770,9 @@ where

impl<P, Container> ImageBuffer<P, Container>
where
P: Pixel<Subpixel = u8> + 'static,
Container: Deref<Target = [u8]>,
P: Pixel + 'static,
[P::Subpixel]: EncodableLayout,
Container: Deref<Target = [P::Subpixel]>,
{
/// Saves the buffer to a file at the specified path in
/// the specified format.
Expand All @@ -784,7 +786,7 @@ where
// This is valid as the subpixel is u8.
save_buffer_with_format(
path,
self,
self.as_bytes(),
self.width(),
self.height(),
<P as Pixel>::COLOR_TYPE,
Expand Down Expand Up @@ -1076,6 +1078,14 @@ pub type GrayAlphaImage = ImageBuffer<LumaA<u8>, Vec<u8>>;
pub(crate) type BgrImage = ImageBuffer<Bgr<u8>, Vec<u8>>;
/// Sendable Bgr + alpha channel image buffer
pub(crate) type BgraImage = ImageBuffer<Bgra<u8>, Vec<u8>>;
/// Sendable 16-bit Rgb image buffer
pub(crate) type Rgb16Image = ImageBuffer<Rgb<u16>, Vec<u16>>;
/// Sendable 16-bit Rgb + alpha channel image buffer
pub(crate) type Rgba16Image = ImageBuffer<Rgba<u16>, Vec<u16>>;
/// Sendable 16-bit grayscale image buffer
pub(crate) type Gray16Image = ImageBuffer<Luma<u16>, Vec<u16>>;
/// Sendable 16-bit grayscale + alpha channel image buffer
pub(crate) type GrayAlpha16Image = ImageBuffer<LumaA<u16>, Vec<u16>>;

#[cfg(test)]
mod test {
Expand Down

0 comments on commit d3b3133

Please sign in to comment.