aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/activitypub/apattachment.cpp9
-rw-r--r--src/activitypub/apattachment.h8
2 files changed, 16 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);
diff --git a/src/activitypub/apattachment.h b/src/activitypub/apattachment.h
index f4e620b..83e9339 100644
--- a/src/activitypub/apattachment.h
+++ b/src/activitypub/apattachment.h
@@ -23,6 +23,14 @@ private:
QString filename; // nicer descriptor of the attachment's path
QPixmap* pixmap = nullptr;
+ struct {
+ int width = 0;
+ int height = 0;
+ // Compare with dimensions passed to get_pixmap()
+ inline bool is_equal(int comp_w, int comp_h) {
+ return width == comp_w and height == comp_h;
+ }
+ } pixmap_dimens; // requested dimensions of the pixmap
};
class APAttachmentList : public std::vector<APAttachment>, APBase {