Skip to content

Commit

Permalink
⬆️ Update image, nalgebra, ndarray, num-traits requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
davidB committed Jan 7, 2025
1 parent e1fd7ef commit 0f8d8bd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
16 changes: 10 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ opener = "^0.7"
anyhow = "^1.0"

#arrow = {version = "0.13.0", optional = true} # nightly
image = {version = "^0.23", optional = true}
nalgebra = {version = "^0.26", optional = true}
num-traits = {version = "^0.2", optional = true}
ndarray = {version = "^0.15", optional = true}
image = { version = "^0.25", optional = true }
nalgebra = { version = "^0.33", optional = true }
num-traits = { version = "^0.2", optional = true }
ndarray = { version = "^0.16", optional = true }

[dev-dependencies]
mime = "0.3.14"
nalgebra = "0.26.1"
mime = "0.3"
nalgebra = "0.33"

[features]
default = []
all = ["show_nalgebra", "show_ndarray", "show_image"]
show_nalgebra = ["nalgebra", "num-traits"]
show_ndarray = ["ndarray"]
show_image = ["image"]

[[example]]
name = "sample_nalgebra"
required-features = ["nalgebra"]
20 changes: 10 additions & 10 deletions src/show_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use crate::Showable;
use anyhow::{anyhow, Error};
use base64::prelude::*;
use image;
use image::EncodableLayout;
use image::PixelWithColorType;
use std::io::Cursor;
use std::ops::Deref;

impl Showable for image::DynamicImage {
Expand All @@ -34,17 +37,14 @@ impl Showable for image::DynamicImage {

impl<P, Container> Showable for image::ImageBuffer<P, Container>
where
P: image::Pixel<Subpixel = u8> + 'static,
Container: Deref<Target = [u8]>,
P: PixelWithColorType,
[P::Subpixel]: EncodableLayout,
Container: Deref<Target = [P::Subpixel]>,
{
fn to_content_info(&self) -> Result<ContentInfo, Error> {
let mut buffer = Vec::new();
image::png::PngEncoder::new(&mut buffer).encode(
self,
self.width(),
self.height(),
<P as image::Pixel>::COLOR_TYPE,
)?;
let mut buffer: Vec<u8> = Vec::new();
self.write_to(&mut Cursor::new(&mut buffer), image::ImageFormat::Png)?;

Ok(ContentInfo {
content: BASE64_STANDARD.encode(&buffer),
mime_type: "image/png;base64".into(),
Expand Down Expand Up @@ -89,7 +89,7 @@ mod tests {

#[test]
fn test_show_gen_image() {
let img = image::ImageBuffer::from_fn(256, 256, |x, y| {
let img = image::RgbImage::from_fn(256, 256, |x, y| {
if (x as i32 - y as i32).abs() < 3 {
image::Rgb([0, 0, 255])
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/show_ndarray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ where
html.push_str(&format!("<th>{}</th>", c));
}
html.push_str("</tr>");
for (r, row) in v.genrows().into_iter().enumerate() {
for (r, row) in v.rows().into_iter().enumerate() {
html.push_str("<tr>");
html.push_str(&format!("<th>{}</th>", r));
for v in row.iter() {
Expand Down

0 comments on commit 0f8d8bd

Please sign in to comment.