1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Image: Add NativeExtensions type to help with inspecting images from graphics context implementations

This type isn't used anywhere in this commit, but this change lays the
foundation for the following commits.
This commit is contained in:
reuk 2025-01-15 16:36:43 +00:00
parent 55e5e2082c
commit 9b08c8fd51
No known key found for this signature in database
2 changed files with 77 additions and 0 deletions

View file

@ -262,9 +262,49 @@ namespace BitmapDataDetail
}
}
//==============================================================================
/* Allows access to ImagePixelData implementation details by LowLevelGraphicsContext instances.
The internal templating is mainly to facilitate returning a type with dynamic implementation by value.
*/
class ImagePixelDataNativeExtensions
{
public:
template <typename Impl>
explicit ImagePixelDataNativeExtensions (Impl x)
: impl (std::make_unique<Concrete<Impl>> (std::move (x))) {}
/* For subsection images, this returns the top-left pixel inside the root image */
Point<int> getTopLeft() const { return impl->getTopLeft(); }
private:
struct Base
{
virtual ~Base() = default;
virtual Point<int> getTopLeft() const = 0;
};
template <typename Impl>
class Concrete : public Base
{
public:
explicit Concrete (Impl x)
: impl (std::move (x)) {}
Point<int> getTopLeft() const override { return impl.getTopLeft(); }
private:
Impl impl;
};
std::unique_ptr<Base> impl;
};
//==============================================================================
class SubsectionPixelData : public ImagePixelData
{
public:
using Ptr = ReferenceCountedObjectPtr<SubsectionPixelData>;
SubsectionPixelData (ImagePixelData::Ptr source, Rectangle<int> r)
: ImagePixelData (source->pixelFormat, r.getWidth(), r.getHeight()),
sourceImage (std::move (source)),
@ -330,6 +370,24 @@ public:
/* as we always hold a reference to image, don't double count */
int getSharedCount() const noexcept override { return getReferenceCount() + sourceImage->getSharedCount() - 1; }
NativeExtensions getNativeExtensions() override
{
struct Wrapped
{
explicit Wrapped (Ptr selfIn)
: self (selfIn) {}
Point<int> getTopLeft() const
{
return self->sourceImage->getNativeExtensions().getTopLeft() + self->area.getTopLeft();
}
Ptr self;
};
return NativeExtensions { Wrapped { this } };
}
private:
Rectangle<int> getIntersection (Rectangle<int> b) const
{
@ -402,6 +460,16 @@ void ImagePixelData::desaturateInArea (Rectangle<int> b)
}
}
auto ImagePixelData::getNativeExtensions() -> NativeExtensions
{
struct Wrapped
{
Point<int> getTopLeft() const { return {}; }
};
return NativeExtensions { Wrapped{} };
}
//==============================================================================
ImageType::ImageType() = default;
ImageType::~ImageType() = default;

View file

@ -555,6 +555,11 @@ protected:
~ImagePixelDataBackupExtensions() = default;
};
/** @internal
@tags{Graphics}
*/
class ImagePixelDataNativeExtensions;
//==============================================================================
/**
This is a base class for holding image data in implementation-specific ways.
@ -572,6 +577,7 @@ class JUCE_API ImagePixelData : public ReferenceCountedObject
{
public:
using BackupExtensions = ImagePixelDataBackupExtensions;
using NativeExtensions = ImagePixelDataNativeExtensions;
ImagePixelData (Image::PixelFormat, int width, int height);
~ImagePixelData() override;
@ -679,6 +685,9 @@ public:
void sendDataChangeMessage();
/** @internal intentionally not callable from user code */
virtual NativeExtensions getNativeExtensions();
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ImagePixelData)
};