Skip to content

Commit

Permalink
Don't render jpg pictures with ghostscript
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Aug 30, 2024
1 parent 9febc8a commit 95d801a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 36 deletions.
Binary file removed assets/refs/image_luma8_jpg_ghostscript.png
Binary file not shown.
Binary file removed assets/refs/image_rgb8_jpg_ghostscript.png
Binary file not shown.
65 changes: 32 additions & 33 deletions src/svg/image.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
use tiny_skia_path::Rect;
use usvg::ImageKind;
use crate::FillRule;
use crate::image::Image;
use crate::surface::Surface;
use crate::svg::ProcessContext;
use crate::svg::{group, ProcessContext};
use crate::util::RectExt;

/// Render an image into a surface.
pub fn render(image: &usvg::Image, surface: &mut Surface, process_context: &mut ProcessContext) {
if !image.is_visible() {
return;
}

unimplemented!();
// match image.kind() {
// ImageKind::JPEG(d) => {
// let dynamic_image =
// image::load_from_memory_with_format(d.as_slice(), ImageFormat::Jpeg).unwrap();
// let d_image = Image::new(&dynamic_image);
// surface.draw_image(d_image, image.size());
// }
// ImageKind::PNG(d) => {
// let dynamic_image =
// image::load_from_memory_with_format(d.as_slice(), ImageFormat::Png).unwrap();
// let d_image = Image::new(&dynamic_image);
// surface.draw_image(d_image, image.size());
// }
// ImageKind::GIF(d) => {
// let dynamic_image =
// image::load_from_memory_with_format(d.as_slice(), ImageFormat::Gif).unwrap();
// let d_image = Image::new(&dynamic_image);
// surface.draw_image(d_image, image.size());
// }
// ImageKind::SVG(t) => {
// surface.push_clip_path(
// &Rect::from_xywh(0.0, 0.0, t.size().width(), t.size().height())
// .unwrap()
// .to_clip_path(),
// &FillRule::NonZero,
// );
// group::render(t.root(), surface, process_context);
// surface.pop();
// }
// _ => unimplemented!(),
// }
match image.kind() {
ImageKind::JPEG(d) => {
// TODO: Remove unwraps
let d_image = Image::from_jpeg(&d).unwrap();
surface.draw_image(d_image, image.size());
}
ImageKind::PNG(d) => {
let d_image = Image::from_png(&d).unwrap();
surface.draw_image(d_image, image.size());
}
ImageKind::GIF(d) => {
let d_image = Image::from_gif(&d).unwrap();
surface.draw_image(d_image, image.size());
}
ImageKind::SVG(t) => {
surface.push_clip_path(
&Rect::from_xywh(0.0, 0.0, t.size().width(), t.size().height())
.unwrap()
.to_clip_path(),
&FillRule::NonZero,
);
group::render(t.root(), surface, process_context);
surface.pop();
}
_ => unimplemented!(),
}
}
5 changes: 4 additions & 1 deletion src/tests/manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use crate::font::Font;
use crate::rgb::Rgb;
use crate::serialize::SerializeSettings;
use crate::stream::Glyph;
use crate::tests::{write_manual_to_store, ASSETS_PATH, COLR_TEST_GLYPHS, DEJAVU_SANS_MONO, NOTO_SANS, NOTO_SANS_ARABIC, NOTO_SANS_CJK, NOTO_SANS_DEVANAGARI, load_jpg_image};
use crate::tests::{
load_jpg_image, write_manual_to_store, ASSETS_PATH, COLR_TEST_GLYPHS, DEJAVU_SANS_MONO,
NOTO_SANS, NOTO_SANS_ARABIC, NOTO_SANS_CJK, NOTO_SANS_DEVANAGARI,
};
use crate::util::SliceExt;
use crate::Fill;
use skrifa::instance::{Location, LocationRef, Size};
Expand Down
4 changes: 2 additions & 2 deletions src/tests/visreg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ fn image_rgba16_png(surface: &mut Surface) {
png_image_impl(surface, "rgba16.png");
}

#[visreg(all)]
#[visreg(pdfium, mupdf, pdfbox, pdfjs, poppler, quartz)]
fn image_luma8_jpg(surface: &mut Surface) {
jpg_image_impl(surface, "luma8.jpg");
}

#[visreg(all)]
#[visreg(pdfium, mupdf, pdfbox, pdfjs, poppler, quartz)]
fn image_rgb8_jpg(surface: &mut Surface) {
jpg_image_impl(surface, "rgb8.jpg");
}
Expand Down

0 comments on commit 95d801a

Please sign in to comment.