30 : pixelFormat (
format), width (w), height (h)
32 jassert (format == Image::RGB || format == Image::ARGB || format == Image::SingleChannel);
36ImagePixelData::~ImagePixelData()
38 listeners.call ([
this] (Listener& l) { l.imageDataBeingDeleted (
this); });
41void ImagePixelData::sendDataChangeMessage()
43 listeners.call ([
this] (Listener& l) { l.imageDataChanged (
this); });
46int ImagePixelData::getSharedCount() const noexcept
48 return getReferenceCount();
52ImageType::ImageType() {}
53ImageType::~ImageType() {}
57 if (source.
isNull() || getTypeID() == source.getPixelData()->
createType()->getTypeID())
67 for (
int y = 0; y < dest.height; ++y)
72 for (
int y = 0; y < dest.height; ++y)
73 for (
int x = 0; x < dest.width; ++x)
86 pixelStride (formatToUse == Image::RGB ? 3 : ((formatToUse == Image::ARGB) ? 4 : 1)),
87 lineStride ((pixelStride *
jmax (1, w) + 3) & ~3)
89 imageData.allocate ((
size_t) lineStride * (
size_t)
jmax (1, h), clearImage);
94 sendDataChangeMessage();
95 return std::make_unique<LowLevelGraphicsSoftwareRenderer> (
Image (*
this));
100 const auto offset = (
size_t) x * (
size_t) pixelStride + (
size_t) y * (
size_t) lineStride;
101 bitmap.
data = imageData + offset;
102 bitmap.
size = (
size_t) (height * lineStride) - offset;
107 if (mode != Image::BitmapData::readOnly)
108 sendDataChangeMessage();
114 memcpy (s->imageData, imageData, (
size_t) lineStride * (
size_t) height);
122 const int pixelStride, lineStride;
127SoftwareImageType::SoftwareImageType() {}
128SoftwareImageType::~SoftwareImageType() {}
135int SoftwareImageType::getTypeID()
const
141NativeImageType::NativeImageType() {}
142NativeImageType::~NativeImageType() {}
144int NativeImageType::getTypeID()
const
149#if JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD
162 sourceImage (std::move (source)), area (r)
168 auto g = sourceImage->createLowLevelContext();
169 g->clipToRectangle (area);
170 g->setOrigin (area.getPosition());
176 sourceImage->initialiseBitmapData (bitmap, x + area.getX(), y + area.getY(), mode);
178 if (mode != Image::BitmapData::readOnly)
179 sendDataChangeMessage();
184 jassert (getReferenceCount() > 0);
185 auto type = createType();
187 Image newImage (type->create (pixelFormat, area.getWidth(), area.getHeight(), pixelFormat != Image::RGB));
194 return *newImage.getPixelData();
200 int getSharedCount() const noexcept
override {
return getReferenceCount() + sourceImage->getSharedCount() - 1; }
217 if (validArea.isEmpty())
225Image::Image() noexcept
230 : image (std::move (instance))
234Image::Image (
PixelFormat format,
int width,
int height,
bool clearImage)
240 : image (type.create (format, width, height,
clearImage))
245 : image (
other.image)
256 : image (std::move (
other.image))
262 image = std::move (
other.image);
282 if (image !=
nullptr)
283 return image->createLowLevelContext();
291 image = image->clone();
296 if (image !=
nullptr)
297 return Image (image->clone());
304 if (image ==
nullptr || (image->width ==
newWidth && image->height ==
newHeight))
307 auto type = image->createType();
313 (
float)
newHeight / (
float) image->height),
false);
319 if (image ==
nullptr ||
newFormat == image->pixelFormat)
322 auto w = image->width, h = image->height;
324 auto type = image->createType();
338 for (
int y = 0; y < h; ++y)
343 for (
int x = 0; x < w; ++x)
344 dst[x] = src[x].getAlpha();
353 for (
int y = 0; y < h; ++y)
358 for (
int x = 0; x < w; ++x)
376 return image ==
nullptr ?
nullptr : &(image->userData);
380Image::BitmapData::BitmapData (
Image&
im,
int x,
int y,
int w,
int h, BitmapData::ReadWriteMode mode)
381 : width (w), height (h)
385 jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <=
im.getWidth() && y + h <=
im.getHeight());
387 im.image->initialiseBitmapData (*
this, x, y, mode);
388 jassert (data !=
nullptr && pixelStride > 0 && lineStride != 0);
391Image::BitmapData::BitmapData (
const Image&
im,
int x,
int y,
int w,
int h)
392 : width (w), height (h)
396 jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <=
im.getWidth() && y + h <=
im.getHeight());
398 im.image->initialiseBitmapData (*
this, x, y, readOnly);
399 jassert (data !=
nullptr && pixelStride > 0 && lineStride != 0);
402Image::BitmapData::BitmapData (
const Image&
im, BitmapData::ReadWriteMode mode)
403 : width (
im.getWidth()),
404 height (
im.getHeight())
409 im.image->initialiseBitmapData (*
this, 0, 0, mode);
410 jassert (data !=
nullptr && pixelStride > 0 && lineStride != 0);
413Image::BitmapData::~BitmapData()
421 auto pixel = getPixelPointer (x, y);
428 case Image::UnknownFormat:
439 auto pixel = getPixelPointer (x, y);
440 auto col = colour.getPixelARGB();
447 case Image::UnknownFormat:
455 if (image !=
nullptr)
457 auto g = image->createLowLevelContext();
459 g->fillRect (area,
true);
479 const BitmapData destData (*
this, x, y, 1, 1, BitmapData::writeOnly);
489 const BitmapData destData (*
this, x, y, 1, 1, BitmapData::readWrite);
498template <
class PixelType>
501 template <
class PixelOperation>
502 static void iterate (
const Image::BitmapData& data,
const PixelOperation& pixelOp)
504 for (
int y = 0; y < data.height; ++y)
506 auto p = data.getLinePointer (y);
508 for (
int x = 0; x < data.width; ++x)
510 pixelOp (*
reinterpret_cast<PixelType*
> (p));
511 p += data.pixelStride;
517template <
class PixelOperation>
520 switch (data.pixelFormat)
525 case Image::UnknownFormat:
534 template <
class PixelType>
535 void operator() (PixelType& pixel)
const
537 pixel.multiplyAlpha (alpha);
551 template <
class PixelType>
552 void operator() (PixelType& pixel)
const
576 for (
int y = 0; y < srcData.height; ++y)
583 for (
int x = 0; x < srcData.width; ++x)
593 for (
int x = 0; x < srcData.width; ++x)
602 for (
int i = 0; i <
pixelsOnRow.getNumRanges(); ++i)
658 auto maxY =
jmax (dy,
sy) + h;
688#if JUCE_ALLOW_STATIC_NULL_VARIABLES
690JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE (
"-Wdeprecated-declarations")
691JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4996)
695JUCE_END_IGNORE_WARNINGS_GCC_LIKE
696JUCE_END_IGNORE_WARNINGS_MSVC
Represents a colour, also including a transparency value.
A graphics context, used for drawing a component or image.
void setImageResamplingQuality(ResamplingQuality newQuality)
Changes the quality that will be used when resampling images.
ResamplingQuality
Types of rendering quality that can be specified when drawing images.
void drawImageAt(const Image &imageToDraw, int topLeftX, int topLeftY, bool fillAlphaChannelWithCurrentBrush=false) const
Draws an image.
void drawImageTransformed(const Image &imageToDraw, const AffineTransform &transform, bool fillAlphaChannelWithCurrentBrush=false) const
Draws an image, having applied an affine transform to it.
Very simple container class to hold a pointer to some data on the heap.
This is a base class for holding image data in implementation-specific ways.
virtual std::unique_ptr< ImageType > createType() const =0
Creates an instance of the type of this image.
This base class is for handlers that control a type of image manipulation format, e....
Retrieves a section of an image as raw pixel data, so it can be read or written to.
int pixelStride
The number of bytes between each pixel.
uint8 * getPixelPointer(int x, int y) const noexcept
Returns a pointer to a pixel in the image.
int lineStride
The number of bytes between each line.
uint8 * getLinePointer(int y) const noexcept
Returns a pointer to the start of a line in the image.
void setPixelColour(int x, int y, Colour colour) const noexcept
Sets the colour of a given pixel.
Colour getPixelColour(int x, int y) const noexcept
Returns the colour of a given pixel.
PixelFormat pixelFormat
The format of the data.
uint8 * data
The raw pixel data, packed according to the image's pixel format.
size_t size
The number of valid/allocated bytes after data.
Holds a fixed-size bitmap.
int getWidth() const noexcept
Returns the image's width (in pixels).
bool isRGB() const noexcept
True if the image's format is RGB.
std::unique_ptr< LowLevelGraphicsContext > createLowLevelContext() const
Creates a context suitable for drawing onto this image.
Image() noexcept
Creates a null image.
Image & operator=(const Image &)
Makes this image refer to the same underlying image as another object.
void clear(const Rectangle< int > &area, Colour colourToClearTo=Colour(0x00000000))
Clears a section of the image with a given colour.
bool isARGB() const noexcept
True if the image's format is ARGB.
void desaturate()
Changes all the colours to be shades of grey, based on their current luminosity.
bool hasAlphaChannel() const noexcept
True if the image contains an alpha-channel.
Colour getPixelAt(int x, int y) const
Returns the colour of one of the pixels in the image.
PixelFormat getFormat() const noexcept
Returns the image's pixel format.
void moveImageSection(int destX, int destY, int sourceX, int sourceY, int width, int height)
Copies a section of the image to somewhere else within itself.
void multiplyAllAlphas(float amountToMultiplyBy)
Changes the overall opacity of the image.
int getHeight() const noexcept
Returns the image's height (in pixels).
Rectangle< int > getBounds() const noexcept
Returns a rectangle with the same size as this image.
void multiplyAlphaAt(int x, int y, float multiplier)
Changes the opacity of a pixel.
void setPixelAt(int x, int y, Colour colour)
Sets the colour of one of the image's pixels.
void createSolidAreaMask(RectangleList< int > &result, float alphaThreshold) const
Creates a RectangleList containing rectangles for all non-transparent pixels of the image.
Image convertedToFormat(PixelFormat newFormat) const
Returns a version of this image with a different image format.
bool isSingleChannel() const noexcept
True if the image's format is a single-channel alpha map.
bool isNull() const noexcept
Returns true if this image is not valid.
Image rescaled(int newWidth, int newHeight, Graphics::ResamplingQuality quality=Graphics::mediumResamplingQuality) const
Returns a rescaled version of this image.
void duplicateIfShared()
Makes sure that no other Image objects share the same underlying data as this one.
Image createCopy() const
Creates a copy of this image.
NamedValueSet * getProperties() const
Returns a NamedValueSet that is attached to the image and which can be used for associating custom va...
@ SingleChannel
< each pixel is a 1-byte alpha channel value.
@ ARGB
< each pixel is a 4-byte ARGB premultiplied colour value.
@ RGB
< each pixel is a 3-byte packed RGB colour value.
int getReferenceCount() const noexcept
Returns the number of Image objects which are currently referring to the same internal shared image d...
Holds a set of named var objects.
An image storage type which holds the pixels using whatever is the default storage format on the curr...
Represents a 32-bit INTERNAL pixel with premultiplied alpha, and can perform compositing operations w...
Represents an 8-bit single-channel pixel, and can perform compositing operations on it.
Represents a 24-bit RGB pixel, and can perform compositing operations on it.
A general-purpose range object, that simply represents any linear range with a start and end point.
Maintains a set of rectangles as a complex region.
void add(RectangleType rect)
Merges a new rectangle into the list.
void consolidate()
Optimises the list into a minimum number of constituent rectangles.
Manages a rectangle and allows geometric operations to be performed on it.
bool contains(ValueType xCoord, ValueType yCoord) const noexcept
Returns true if this coordinate is inside the rectangle.
Rectangle getIntersection(Rectangle other) const noexcept
Returns the region that is the overlap between this and another rectangle.
ValueType getWidth() const noexcept
Returns the width of the rectangle.
ValueType getHeight() const noexcept
Returns the height of the rectangle.
A smart-pointer class which points to a reference-counted object.
std::unique_ptr< ImageType > createType() const override
Creates an instance of the type of this image.
std::unique_ptr< LowLevelGraphicsContext > createLowLevelContext() override
Creates a context that will draw into this image.
void initialiseBitmapData(Image::BitmapData &bitmap, int x, int y, Image::BitmapData::ReadWriteMode mode) override
Initialises a BitmapData object.
ImagePixelData::Ptr clone() override
Creates a copy of this image.
Holds a set of primitive values, storing them as a set of ranges.
void initialiseBitmapData(Image::BitmapData &bitmap, int x, int y, Image::BitmapData::ReadWriteMode mode) override
Initialises a BitmapData object.
std::unique_ptr< ImageType > createType() const override
Creates an instance of the type of this image.
int getSharedCount() const noexcept override
Returns the number of Image objects which are currently referring to the same internal shared image d...
std::unique_ptr< LowLevelGraphicsContext > createLowLevelContext() override
Creates a context that will draw into this image.
ImagePixelData::Ptr clone() override
Creates a copy of this image.
#define JUCE_LEAK_DETECTOR(OwnerClass)
This macro lets you embed a leak-detecting object inside a class.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.
unsigned char uint8
A platform-independent 8-bit unsigned integer type.
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.