[librsvg: 38/53] Convert the result of ImageSurface::create_from_png() to ARGB
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 38/53] Convert the result of ImageSurface::create_from_png() to ARGB
- Date: Fri, 23 Oct 2020 02:19:07 +0000 (UTC)
commit a6b927fd96da8a659cafcf09438306665ca1fc67
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Oct 21 19:32:36 2020 -0500
Convert the result of ImageSurface::create_from_png() to ARGB
It may come out as Rgb24, who knew...
tests/src/reference.rs | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/tests/src/reference.rs b/tests/src/reference.rs
index 8c25f173..01e2474f 100644
--- a/tests/src/reference.rs
+++ b/tests/src/reference.rs
@@ -250,18 +250,37 @@ mod duplicated_from_librsvg_crate {
path
}
+ // FIXME: proper errors?
+ fn load_png_as_argb(path: &PathBuf) -> Result<cairo::ImageSurface, ()> {
+ let file = File::open(path).map_err(|_| ())?;
+
+ let mut reference_file = BufReader::new(file);
+
+ let png = cairo::ImageSurface::create_from_png(&mut reference_file).map_err(|_| ())?;
+ let argb = cairo::ImageSurface::create(
+ cairo::Format::ARgb32,
+ png.get_width(),
+ png.get_height(),
+ ).map_err(|_| ())?;
+
+ {
+ // convert to ARGB; the PNG may come as Rgb24
+ let cr = cairo::Context::new(&argb);
+ cr.set_source_surface(&png, 0.0, 0.0);
+ cr.paint();
+ }
+
+ Ok(argb)
+ }
+
// FIXME: this is slightly different from librsvg_crate
pub fn compare_to_file(
output_surf: &SharedImageSurface,
output_base_name: &str,
reference_path: &PathBuf,
) {
- let file = File::open(reference_path).unwrap();
-
- let mut reference_file = BufReader::new(file);
-
- let reference = cairo::ImageSurface::create_from_png(&mut reference_file).unwrap();
- let reference_surf = SharedImageSurface::wrap(reference, SurfaceType::SRgb).unwrap();
+ let png = load_png_as_argb(reference_path).unwrap();
+ let reference_surf = SharedImageSurface::wrap(png, SurfaceType::SRgb).unwrap();
compare_to_surface(output_surf, &reference_surf, output_base_name);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]