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

Image: Add new BitmapData constructor accepting a Rectangle

This commit is contained in:
reuk 2025-01-14 19:43:32 +00:00
parent 01821b5811
commit 8cb8c5e572
No known key found for this signature in database
2 changed files with 21 additions and 15 deletions

View file

@ -342,7 +342,7 @@ public:
sendDataChangeMessage();
}
ImagePixelData::Ptr clone() override
Ptr clone() override
{
auto s = new SoftwarePixelData (pixelFormat, width, height, false);
memcpy (s->imageData, imageData, (size_t) lineStride * (size_t) height);
@ -515,8 +515,8 @@ Image Image::convertedToFormat (PixelFormat newFormat) const
}
else
{
const BitmapData destData (newImage, 0, 0, w, h, BitmapData::writeOnly);
const BitmapData srcData (*this, 0, 0, w, h);
const BitmapData destData (newImage, { w, h }, BitmapData::writeOnly);
const BitmapData srcData (*this, { w, h }, BitmapData::readOnly);
for (int y = 0; y < h; ++y)
{
@ -530,8 +530,8 @@ Image Image::convertedToFormat (PixelFormat newFormat) const
}
else if (image->pixelFormat == SingleChannel && newFormat == Image::ARGB)
{
const BitmapData destData (newImage, 0, 0, w, h, BitmapData::writeOnly);
const BitmapData srcData (*this, 0, 0, w, h);
const BitmapData destData (newImage, { w, h }, BitmapData::writeOnly);
const BitmapData srcData (*this, { w, h }, BitmapData::readOnly);
for (int y = 0; y < h; ++y)
{
@ -560,14 +560,24 @@ NamedValueSet* Image::getProperties() const
}
//==============================================================================
Image::BitmapData::BitmapData (Image& im, int x, int y, int w, int h, BitmapData::ReadWriteMode mode)
: width (w), height (h)
Image::BitmapData::BitmapData (Image& im, int x, int y, int w, int h, ReadWriteMode mode)
: BitmapData (im, { x, y, w, h }, mode)
{
}
Image::BitmapData::BitmapData (const Image& im, Rectangle<int> bounds, ReadWriteMode mode)
: width (bounds.getWidth()), height (bounds.getHeight())
{
// The BitmapData class must be given a valid image, and a valid rectangle within it!
jassert (im.image != nullptr);
jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= im.getWidth() && y + h <= im.getHeight());
jassert (bounds.getX() >= 0);
jassert (bounds.getY() >= 0);
jassert (bounds.getWidth() > 0);
jassert (bounds.getHeight() > 0);
jassert (bounds.getRight() <= im.getWidth());
jassert (bounds.getBottom() <= im.getHeight());
im.image->initialiseBitmapData (*this, x, y, mode);
im.image->initialiseBitmapData (*this, bounds.getX(), bounds.getY(), mode);
jassert (data != nullptr && pixelStride > 0 && lineStride != 0);
}
@ -582,7 +592,7 @@ Image::BitmapData::BitmapData (const Image& im, int x, int y, int w, int h)
jassert (data != nullptr && pixelStride > 0 && lineStride != 0);
}
Image::BitmapData::BitmapData (const Image& im, BitmapData::ReadWriteMode mode)
Image::BitmapData::BitmapData (const Image& im, ReadWriteMode mode)
: width (im.getWidth()),
height (im.getHeight())
{
@ -593,10 +603,6 @@ Image::BitmapData::BitmapData (const Image& im, BitmapData::ReadWriteMode mode)
jassert (data != nullptr && pixelStride > 0 && lineStride != 0);
}
Image::BitmapData::~BitmapData()
{
}
Colour Image::BitmapData::getPixelColour (int x, int y) const noexcept
{
auto* pixel = getPixelPointer (x, y);

View file

@ -326,9 +326,9 @@ public:
};
BitmapData (Image& image, int x, int y, int w, int h, ReadWriteMode mode);
BitmapData (const Image& image, Rectangle<int>, ReadWriteMode mode);
BitmapData (const Image& image, int x, int y, int w, int h);
BitmapData (const Image& image, ReadWriteMode mode);
~BitmapData();
/** Returns a pointer to the start of a line in the image.
The coordinate you provide here isn't checked, so it's the caller's responsibility to make