From 4ba01a80a0b25a258d3236887ab690a292a7d055 Mon Sep 17 00:00:00 2001 From: Oli Date: Tue, 15 Apr 2025 13:37:50 +0100 Subject: [PATCH] Component: Use Context appropriate ImageType for temporary images Co-authored-by: Matt Gonzalez --- .../juce_gui_basics/components/juce_Component.cpp | 13 ++++++++++--- modules/juce_gui_basics/components/juce_Component.h | 5 +++-- .../detail/juce_StandardCachedComponentImage.h | 4 +++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index ad2bb0fed1..e0337212b7 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -216,7 +216,12 @@ public: if (effectImage.getBounds() != scaledBounds) { - effectImage = Image { c.isOpaque() ? Image::RGB : Image::ARGB, scaledBounds.getWidth(), scaledBounds.getHeight(), false }; + auto tempImageType = g.getInternalContext().getPreferredImageTypeForTemporaryImages(); + effectImage = Image { c.isOpaque() ? Image::RGB : Image::ARGB, + scaledBounds.getWidth(), + scaledBounds.getHeight(), + false, + *tempImageType }; effectImage.setBackupEnabled (false); } @@ -1814,7 +1819,9 @@ bool Component::isPaintingUnclipped() const noexcept //============================================================================== Image Component::createComponentSnapshot (Rectangle areaToGrab, - bool clipImageToComponentBounds, float scaleFactor) + bool clipImageToComponentBounds, + float scaleFactor, + const ImageType& imageType) { auto r = areaToGrab; @@ -1827,7 +1834,7 @@ Image Component::createComponentSnapshot (Rectangle areaToGrab, auto w = roundToInt (scaleFactor * (float) r.getWidth()); auto h = roundToInt (scaleFactor * (float) r.getHeight()); - Image image (flags.opaqueFlag ? Image::RGB : Image::ARGB, w, h, true); + Image image (flags.opaqueFlag ? Image::RGB : Image::ARGB, w, h, true, imageType); Graphics g (image); diff --git a/modules/juce_gui_basics/components/juce_Component.h b/modules/juce_gui_basics/components/juce_Component.h index da4faf6191..bcffc5653d 100644 --- a/modules/juce_gui_basics/components/juce_Component.h +++ b/modules/juce_gui_basics/components/juce_Component.h @@ -1147,7 +1147,7 @@ public: /** Generates a snapshot of part of this component. - This will return a new Image, the size of the rectangle specified, + This will return a new Image of type imageType, the size of the rectangle specified, containing a snapshot of the specified area of the component and all its children. @@ -1162,7 +1162,8 @@ public: */ Image createComponentSnapshot (Rectangle areaToGrab, bool clipImageToComponentBounds = true, - float scaleFactor = 1.0f); + float scaleFactor = 1.0f, + const ImageType& imageType = NativeImageType{}); /** Draws this component and all its subcomponents onto the specified graphics context. diff --git a/modules/juce_gui_basics/detail/juce_StandardCachedComponentImage.h b/modules/juce_gui_basics/detail/juce_StandardCachedComponentImage.h index 6f48b5f8aa..d840b8748a 100644 --- a/modules/juce_gui_basics/detail/juce_StandardCachedComponentImage.h +++ b/modules/juce_gui_basics/detail/juce_StandardCachedComponentImage.h @@ -50,11 +50,13 @@ struct StandardCachedComponentImage : public CachedComponentImage if (image.isNull() || image.getBounds() != imageBounds) { + auto tempImageType = g.getInternalContext().getPreferredImageTypeForTemporaryImages(); image = Image (owner.isOpaque() ? Image::RGB : Image::ARGB, jmax (1, imageBounds.getWidth()), jmax (1, imageBounds.getHeight()), - ! owner.isOpaque()); + ! owner.isOpaque(), + *tempImageType); image.setBackupEnabled (false); validArea.clear(); }