| 1 | /* |
| 2 | * Copyright 2022-2026 Andrey Kutejko <[email protected]> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 3 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * For more details see the file COPYING. |
| 18 | */ |
| 19 | |
| 20 | use gtkrust-analyzer cargo gtk4 0.11.1 crate/::{gdkrust-analyzer cargo gdk4 0.11.1 crate/, giorust-analyzer cargo gio 0.22.2 crate/, graphenerust-analyzer cargo graphene-rs 0.22.0 crate/, gskrust-analyzer cargo gsk4 0.11.1 crate/, preluderust-analyzer cargo gtk4 0.11.1 prelude/::*}; |
| 21 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#; |
| 22 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#; |
| 23 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#; |
| 24 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/::Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#; |
| 25 | |
| 26 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 27 | pub struct Imagerust-analyzer cargo gnome-robots 50.0.0 image/Image#(Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<ImageInnerrust-analyzer cargo gnome-robots 50.0.0 image/ImageInner#>); |
| 28 | |
| 29 | struct ImageInnerrust-analyzer cargo gnome-robots 50.0.0 image/ImageInner# { |
| 30 | imagerust-analyzer cargo gnome-robots 50.0.0 image/ImageInner#image.: glyrust-analyzer cargo libglycin-rebind 0.1.0 crate/::Imagerust-analyzer cargo libglycin-rebind 0.1.0 auto/image/Image#, |
| 31 | texturerust-analyzer cargo gnome-robots 50.0.0 image/ImageInner#texture.: gdkrust-analyzer cargo gdk4 0.11.1 crate/::Texturerust-analyzer cargo gdk4 0.11.1 auto/texture/Texture#, |
| 32 | scaledrust-analyzer cargo gnome-robots 50.0.0 image/ImageInner#scaled.: RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<gdkrust-analyzer cargo gdk4 0.11.1 crate/::Texturerust-analyzer cargo gdk4 0.11.1 auto/texture/Texture#>>, |
| 33 | } |
| 34 | |
| 35 | impl Imagerust-analyzer cargo gnome-robots 50.0.0 image/Image# { |
| 36 | pub fn from_filerust-analyzer cargo gnome-robots 50.0.0 image/impl#[Image]from_file().(filename: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo gnome-robots 50.0.0 image/impl#[Image], Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> { |
| 37 | let file = giorust-analyzer cargo gio 0.22.2 crate/::Filerust-analyzer cargo gio 0.22.2 auto/file/File#::for_pathrust-analyzer cargo gio 0.22.2 auto/file/impl#[File]for_path().(filename); |
| 38 | let loader = glyrust-analyzer cargo libglycin-rebind 0.1.0 crate/::Loaderrust-analyzer cargo libglycin-rebind 0.1.0 auto/loader/Loader#::newrust-analyzer cargo libglycin-rebind 0.1.0 auto/loader/impl#[Loader]new().(&file); |
| 39 | let image = loader.loadrust-analyzer cargo libglycin-rebind 0.1.0 auto/loader/impl#[Loader]load().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 40 | let frame = image.next_framerust-analyzer cargo libglycin-rebind 0.1.0 auto/image/impl#[Image]next_frame().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 41 | let texture = gly_gtkrust-analyzer cargo libglycin-gtk4-rebind 0.1.0 crate/::frame_get_texturerust-analyzer cargo libglycin-gtk4-rebind 0.1.0 auto/functions/frame_get_texture().(&frame); |
| 42 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo gnome-robots 50.0.0 image/impl#[Image](Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T>`]new().(ImageInnerrust-analyzer cargo gnome-robots 50.0.0 image/ImageInner# { |
| 43 | imagerust-analyzer cargo gnome-robots 50.0.0 image/ImageInner#image., |
| 44 | texturerust-analyzer cargo gnome-robots 50.0.0 image/ImageInner#texture., |
| 45 | scaledrust-analyzer cargo gnome-robots 50.0.0 image/ImageInner#scaled.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`][Default]default().(), |
| 46 | }))) |
| 47 | } |
| 48 | |
| 49 | fn is_svgrust-analyzer cargo gnome-robots 50.0.0 image/impl#[Image]is_svg().(&self) -> bool { |
| 50 | const SVG_CONTENT_TYPErust-analyzer cargo gnome-robots 50.0.0 image/SVG_CONTENT_TYPE.: &str = "image/svg+xml"; |
| 51 | self.0rust-analyzer cargo gnome-robots 50.0.0 image/Image#0..imagerust-analyzer cargo gnome-robots 50.0.0 image/ImageInner#image..mime_typerust-analyzer cargo libglycin-rebind 0.1.0 auto/image/impl#[Image]mime_type().() rust-analyzer cargo glib 0.22.3 gstring/impl#[GString][`PartialEq<&str>`]eq().==rust-analyzer cargo glib 0.22.3 gstring/impl#[GString][`PartialEq<&str>`]eq(). rust-analyzer cargo glib 0.22.3 gstring/impl#[GString][`PartialEq<&str>`]eq().SVG_CONTENT_TYPErust-analyzer cargo gnome-robots 50.0.0 image/SVG_CONTENT_TYPE. |
| 52 | } |
| 53 | |
| 54 | pub fn to_paintablerust-analyzer cargo gnome-robots 50.0.0 image/impl#[Image]to_paintable().(&self) -> gdkrust-analyzer cargo gdk4 0.11.1 crate/::Paintablerust-analyzer cargo gdk4 0.11.1 auto/paintable/Paintable# { |
| 55 | self.0rust-analyzer cargo gnome-robots 50.0.0 image/Image#0..texturerust-analyzer cargo gnome-robots 50.0.0 image/ImageInner#texture..clonerust-analyzer cargo gdk4 0.11.1 auto/texture/impl#[Texture][Clone]clone().().upcastrust-analyzer cargo glib 0.22.3 object/Cast#upcast().() |
| 56 | } |
| 57 | |
| 58 | pub fn scaledrust-analyzer cargo gnome-robots 50.0.0 image/impl#[Image]scaled().( |
| 59 | &self, |
| 60 | width: i32, |
| 61 | height: i32, |
| 62 | renderer: &gskrust-analyzer cargo gsk4 0.11.1 crate/::Rendererrust-analyzer cargo gsk4 0.11.1 auto/renderer/Renderer#, |
| 63 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<gdkrust-analyzer cargo gdk4 0.11.1 crate/::Texturerust-analyzer cargo gdk4 0.11.1 auto/texture/Texture#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> { |
| 64 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(texture) = self.0rust-analyzer cargo gnome-robots 50.0.0 image/Image#0..scaledrust-analyzer cargo gnome-robots 50.0.0 image/ImageInner#scaled..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() |
| 65 | && texture.widthrust-analyzer cargo gdk4 0.11.1 auto/texture/TextureExt#width().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().width |
| 66 | && texture.heightrust-analyzer cargo gdk4 0.11.1 auto/texture/TextureExt#height().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().height |
| 67 | { |
| 68 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(texture.clonerust-analyzer cargo gdk4 0.11.1 auto/texture/impl#[Texture][Clone]clone().()); |
| 69 | } |
| 70 | |
| 71 | let texture = if self.is_svgrust-analyzer cargo gnome-robots 50.0.0 image/impl#[Image]is_svg().() { |
| 72 | let request = glyrust-analyzer cargo libglycin-rebind 0.1.0 crate/::FrameRequestrust-analyzer cargo libglycin-rebind 0.1.0 auto/frame_request/FrameRequest#::newrust-analyzer cargo libglycin-rebind 0.1.0 auto/frame_request/impl#[FrameRequest]new().(); |
| 73 | request.set_scalerust-analyzer cargo libglycin-rebind 0.1.0 auto/frame_request/impl#[FrameRequest]set_scale().(width as u32, height as u32); |
| 74 | let frame = self.0rust-analyzer cargo gnome-robots 50.0.0 image/Image#0..imagerust-analyzer cargo gnome-robots 50.0.0 image/ImageInner#image..specific_framerust-analyzer cargo libglycin-rebind 0.1.0 auto/image/impl#[Image]specific_frame().(&request)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 75 | gly_gtkrust-analyzer cargo libglycin-gtk4-rebind 0.1.0 crate/::frame_get_texturerust-analyzer cargo libglycin-gtk4-rebind 0.1.0 auto/functions/frame_get_texture().(&frame) |
| 76 | } else { |
| 77 | let snapshot = gtkrust-analyzer cargo gtk4 0.11.1 crate/::Snapshotrust-analyzer cargo gtk4 0.11.1 auto/snapshot/Snapshot#::newrust-analyzer cargo gtk4 0.11.1 auto/snapshot/impl#[Snapshot]new().(); |
| 78 | let bounds = graphenerust-analyzer cargo graphene-rs 0.22.0 crate/::Rectrust-analyzer cargo graphene-rs 0.22.0 auto/rect/Rect#::newrust-analyzer cargo graphene-rs 0.22.0 rect/impl#[Rect]new().(0.0, 0.0, width as f32, height as f32); |
| 79 | snapshot.append_texturerust-analyzer cargo gtk4 0.11.1 auto/snapshot/SnapshotExt#append_texture().(&self.0rust-analyzer cargo gnome-robots 50.0.0 image/Image#0..texturerust-analyzer cargo gnome-robots 50.0.0 image/ImageInner#texture., &bounds); |
| 80 | let node = snapshot.to_noderust-analyzer cargo gtk4 0.11.1 auto/snapshot/SnapshotExt#to_node().().ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("No node")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 81 | renderer.render_texturerust-analyzer cargo gsk4 0.11.1 auto/renderer/GskRendererExt#render_texture().(node, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) |
| 82 | }; |
| 83 | |
| 84 | self.0rust-analyzer cargo gnome-robots 50.0.0 image/Image#0..scaledrust-analyzer cargo gnome-robots 50.0.0 image/ImageInner#scaled..replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]replace().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(texture.clonerust-analyzer cargo gdk4 0.11.1 auto/texture/impl#[Texture][Clone]clone().())); |
| 85 | |
| 86 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(texture) |
| 87 | } |
| 88 | } |