diff options
author | ConfuSomu | 2024-03-24 21:10:57 -0400 |
---|---|---|
committer | ConfuSomu | 2024-03-24 21:10:57 -0400 |
commit | 4142690acd68dde59d0a6b16ccdda12f9195f304 (patch) | |
tree | cfeb5d2ec22335a765d4ee602cca2fd7a5c5bf71 /src/activitypub/apattachment.cpp | |
parent | 13c3f52f9b5027d5b1ead5f8b828da3bebd50937 (diff) | |
download | ActorViewer-4142690acd68dde59d0a6b16ccdda12f9195f304.tar ActorViewer-4142690acd68dde59d0a6b16ccdda12f9195f304.tar.gz ActorViewer-4142690acd68dde59d0a6b16ccdda12f9195f304.zip |
Recreate QPixmap in get_pixmap() if size differs
The pixmap should have the size requested and not the original size.
Note that it may be better to do resizing on the callee/method user side
as recreating a pixmap instead of scaling an existing one is expensive.
Diffstat (limited to 'src/activitypub/apattachment.cpp')
-rw-r--r-- | src/activitypub/apattachment.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/activitypub/apattachment.cpp b/src/activitypub/apattachment.cpp index b5c82ce..db305ba 100644 --- a/src/activitypub/apattachment.cpp +++ b/src/activitypub/apattachment.cpp @@ -30,7 +30,14 @@ QString APAttachment::get_html_render(HtmlRenderDetails info) { } const QPixmap& APAttachment::get_pixmap(int width, int height) { - if (pixmap) return *pixmap; + // Recreating the pixmap if it doesn't have the requested dimensions is quite inefficent. So it's better for the callee to resize the image instead of relying on this function. + if (pixmap and pixmap_dimens.is_equal(width, height)) return *pixmap; + else if (pixmap) + delete pixmap; + + // pixmap_dimens are correctly based on the requested/function argument width and height, and not the actual dimentions of the pixmap! + pixmap_dimens.height = height; + pixmap_dimens.width = width; if (width > 0 or height > 0) { QPixmap image(path_url); |