Skip to content

Commit

Permalink
Update dependencies (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfuest authored Nov 26, 2023
1 parent d11431f commit ddbee88
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## [Unreleased] - ReleaseDate

- **(breaking)** [#49](https://github.com/embedded-graphics/simulator/pull/49) Bump Minimum Supported Rust Version (MSRV) to 1.71.1.
- **(breaking)** [#52](https://github.com/embedded-graphics/simulator/pull/52) Bump `image` crate dependency to 0.24.7.

## [0.5.0] - 2023-05-14

Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ exclude = [
circle-ci = { repository = "embedded-graphics/simulator", branch = "master" }

[dependencies]
image = "0.23.14"
base64 = "0.13.0"
embedded-graphics = "0.8.0"
sdl2 = { version = "0.35.1", optional = true }
ouroboros = { version = "0.17.2", optional = true }
image = "0.24.7"
base64 = "0.21.5"
embedded-graphics = "0.8.1"
sdl2 = { version = "0.35.2", optional = true }
ouroboros = { version = "0.18.0", optional = true }

[features]
default = ["with-sdl"]
Expand Down
14 changes: 9 additions & 5 deletions src/output_image.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::{convert::TryFrom, marker::PhantomData, path::Path};

use base64::Engine;
use embedded_graphics::{
pixelcolor::{raw::ToBytes, Gray8, Rgb888, RgbColor},
prelude::*,
primitives::Rectangle,
};
use image::{
png::{CompressionType, FilterType, PngEncoder},
ImageBuffer, Luma, Pixel as _, Rgb,
codecs::png::{CompressionType, FilterType, PngEncoder},
ImageBuffer, ImageEncoder, Luma, Rgb,
};

use crate::{display::SimulatorDisplay, output_settings::OutputSettings};
Expand Down Expand Up @@ -99,18 +100,18 @@ impl<C: OutputImageColor> OutputImage<C> {
pub fn to_base64_png(&self) -> image::ImageResult<String> {
let png = self.encode_png()?;

Ok(base64::encode(&png))
Ok(base64::engine::general_purpose::STANDARD.encode(&png))
}

fn encode_png(&self) -> image::ImageResult<Vec<u8>> {
let mut png = Vec::new();

PngEncoder::new_with_quality(&mut png, CompressionType::Best, FilterType::default())
.encode(
.write_image(
self.data.as_ref(),
self.size.width,
self.size.height,
C::ImageColor::COLOR_TYPE,
C::IMAGE_COLOR_TYPE,
)?;

Ok(png)
Expand All @@ -130,12 +131,15 @@ impl<C> OriginDimensions for OutputImage<C> {

pub trait OutputImageColor {
type ImageColor: image::Pixel<Subpixel = u8> + 'static;
const IMAGE_COLOR_TYPE: image::ColorType;
}

impl OutputImageColor for Gray8 {
type ImageColor = Luma<u8>;
const IMAGE_COLOR_TYPE: image::ColorType = image::ColorType::L8;
}

impl OutputImageColor for Rgb888 {
type ImageColor = Rgb<u8>;
const IMAGE_COLOR_TYPE: image::ColorType = image::ColorType::Rgb8;
}

0 comments on commit ddbee88

Please sign in to comment.