JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_Image.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29class ImageType;
30class ImagePixelData;
31
32
33//==============================================================================
57class JUCE_API Image final
58{
59public:
60 //==============================================================================
64 {
65 UnknownFormat,
68 SingleChannel
69 };
70
71 //==============================================================================
73 Image() noexcept;
74
91 Image (PixelFormat format, int imageWidth, int imageHeight, bool clearImage);
92
108 Image (PixelFormat format, int imageWidth, int imageHeight, bool clearImage, const ImageType& type);
109
116 Image (const Image&) noexcept;
117
124 Image& operator= (const Image&);
125
127 Image (Image&&) noexcept;
128
130 Image& operator= (Image&&) noexcept;
131
133 ~Image();
134
136 bool operator== (const Image& other) const noexcept { return image == other.image; }
137
139 bool operator!= (const Image& other) const noexcept { return image != other.image; }
140
147 inline bool isValid() const noexcept { return image != nullptr; }
148
155 inline bool isNull() const noexcept { return image == nullptr; }
156
157 //==============================================================================
159 int getWidth() const noexcept;
160
162 int getHeight() const noexcept;
163
167 Rectangle<int> getBounds() const noexcept;
168
170 PixelFormat getFormat() const noexcept;
171
173 bool isARGB() const noexcept;
174
176 bool isRGB() const noexcept;
177
179 bool isSingleChannel() const noexcept;
180
182 bool hasAlphaChannel() const noexcept;
183
184 //==============================================================================
190 void clear (const Rectangle<int>& area, Colour colourToClearTo = Colour (0x00000000));
191
199 Image rescaled (int newWidth, int newHeight,
200 Graphics::ResamplingQuality quality = Graphics::mediumResamplingQuality) const;
201
207 Image createCopy() const;
208
216 Image convertedToFormat (PixelFormat newFormat) const;
217
229 void duplicateIfShared();
230
242 Image getClippedImage (const Rectangle<int>& area) const;
243
244 //==============================================================================
252 Colour getPixelAt (int x, int y) const;
253
264 void setPixelAt (int x, int y, Colour colour);
265
276 void multiplyAlphaAt (int x, int y, float multiplier);
277
286 void multiplyAllAlphas (float amountToMultiplyBy);
287
290 void desaturate();
291
292 //==============================================================================
309 class JUCE_API BitmapData final
310 {
311 public:
312 enum ReadWriteMode
313 {
314 readOnly,
315 writeOnly,
316 readWrite
317 };
318
319 BitmapData (Image& image, int x, int y, int w, int h, ReadWriteMode mode);
320 BitmapData (const Image& image, int x, int y, int w, int h);
321 BitmapData (const Image& image, ReadWriteMode mode);
322 ~BitmapData();
323
328 inline uint8* getLinePointer (int y) const noexcept { return data + (size_t) y * (size_t) lineStride; }
329
334 inline uint8* getPixelPointer (int x, int y) const noexcept { return data + (size_t) y * (size_t) lineStride + (size_t) x * (size_t) pixelStride; }
335
340 Colour getPixelColour (int x, int y) const noexcept;
341
346 void setPixelColour (int x, int y, Colour colour) const noexcept;
347
349 Rectangle<int> getBounds() const noexcept { return Rectangle<int> (width, height); }
350
352 size_t size;
356 int width, height;
357
358 //==============================================================================
361 {
362 protected:
363 BitmapDataReleaser() = default;
364 public:
365 virtual ~BitmapDataReleaser() = default;
366 };
367
369
370 private:
372 };
373
374 //==============================================================================
376 void moveImageSection (int destX, int destY,
377 int sourceX, int sourceY,
378 int width, int height);
379
387 void createSolidAreaMask (RectangleList<int>& result, float alphaThreshold) const;
388
389 //==============================================================================
395 NamedValueSet* getProperties() const;
396
397 //==============================================================================
401 std::unique_ptr<LowLevelGraphicsContext> createLowLevelContext() const;
402
408 int getReferenceCount() const noexcept;
409
410 //==============================================================================
412 ImagePixelData* getPixelData() const noexcept { return image.get(); }
413
416
417 //==============================================================================
418 #if JUCE_ALLOW_STATIC_NULL_VARIABLES && ! defined (DOXYGEN)
419 /* A null Image object that can be used when you need to return an invalid image. */
420 [[deprecated ("If you need a default-constructed var, just use Image() or {}.")]]
421 static const Image null;
422 #endif
423
424private:
425 //==============================================================================
427
429};
430
431
432//==============================================================================
446{
447public:
448 ImagePixelData (Image::PixelFormat, int width, int height);
449 ~ImagePixelData() override;
450
452
456 virtual Ptr clone() = 0;
460 virtual void initialiseBitmapData (Image::BitmapData&, int x, int y, Image::BitmapData::ReadWriteMode) = 0;
464 virtual int getSharedCount() const noexcept;
465
466
468 const Image::PixelFormat pixelFormat;
469 const int width, height;
470
475
476 //==============================================================================
478 struct Listener
479 {
480 virtual ~Listener() = default;
481
482 virtual void imageDataChanged (ImagePixelData*) = 0;
483 virtual void imageDataBeingDeleted (ImagePixelData*) = 0;
484 };
485
486 ListenerList<Listener> listeners;
487
488 void sendDataChangeMessage();
489
490private:
492};
493
494//==============================================================================
503class JUCE_API ImageType
504{
505public:
506 ImageType();
507 virtual ~ImageType();
508
510 virtual ImagePixelData::Ptr create (Image::PixelFormat, int width, int height, bool shouldClearImage) const = 0;
511
513 virtual int getTypeID() const = 0;
514
519 virtual Image convert (const Image& source) const;
520};
521
522//==============================================================================
529class JUCE_API SoftwareImageType : public ImageType
530{
531public:
533 ~SoftwareImageType() override;
534
535 ImagePixelData::Ptr create (Image::PixelFormat, int width, int height, bool clearImage) const override;
536 int getTypeID() const override;
537};
538
539//==============================================================================
547class JUCE_API NativeImageType : public ImageType
548{
549public:
551 ~NativeImageType() override;
552
553 ImagePixelData::Ptr create (Image::PixelFormat, int width, int height, bool clearImage) const override;
554 int getTypeID() const override;
555};
556
557} // namespace juce
Represents a colour, also including a transparency value.
Definition juce_Colour.h:38
A graphics context, used for drawing a component or image.
This is a base class for holding image data in implementation-specific ways.
Definition juce_Image.h:446
virtual std::unique_ptr< LowLevelGraphicsContext > createLowLevelContext()=0
Creates a context that will draw into this image.
virtual void initialiseBitmapData(Image::BitmapData &, int x, int y, Image::BitmapData::ReadWriteMode)=0
Initialises a BitmapData object.
virtual std::unique_ptr< ImageType > createType() const =0
Creates an instance of the type of this image.
virtual Ptr clone()=0
Creates a copy of this image.
This base class is for handlers that control a type of image manipulation format, e....
Definition juce_Image.h:504
virtual ImagePixelData::Ptr create(Image::PixelFormat, int width, int height, bool shouldClearImage) const =0
Creates a new image of this type, and the specified parameters.
virtual int getTypeID() const =0
Must return a unique number to identify this type.
Used internally by custom image types to manage pixel data lifetime.
Definition juce_Image.h:361
Retrieves a section of an image as raw pixel data, so it can be read or written to.
Definition juce_Image.h:310
int pixelStride
The number of bytes between each pixel.
Definition juce_Image.h:355
uint8 * getPixelPointer(int x, int y) const noexcept
Returns a pointer to a pixel in the image.
Definition juce_Image.h:334
int lineStride
The number of bytes between each line.
Definition juce_Image.h:354
uint8 * getLinePointer(int y) const noexcept
Returns a pointer to the start of a line in the image.
Definition juce_Image.h:328
PixelFormat pixelFormat
The format of the data.
Definition juce_Image.h:353
uint8 * data
The raw pixel data, packed according to the image's pixel format.
Definition juce_Image.h:351
Rectangle< int > getBounds() const noexcept
Returns the size of the bitmap.
Definition juce_Image.h:349
size_t size
The number of valid/allocated bytes after data.
Definition juce_Image.h:352
Holds a fixed-size bitmap.
Definition juce_Image.h:58
bool isNull() const noexcept
Returns true if this image is not valid.
Definition juce_Image.h:155
bool isValid() const noexcept
Returns true if this image isn't null.
Definition juce_Image.h:147
@ ARGB
< each pixel is a 4-byte ARGB premultiplied colour value.
Definition juce_Image.h:67
@ RGB
< each pixel is a 3-byte packed RGB colour value.
Definition juce_Image.h:66
Holds a set of objects and can invoke a member function callback on each object in the set with a sin...
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...
Definition juce_Image.h:548
ImagePixelData::Ptr create(Image::PixelFormat, int width, int height, bool clearImage) const override
Creates a new image of this type, and the specified parameters.
Maintains a set of rectangles as a complex region.
Manages a rectangle and allows geometric operations to be performed on it.
A smart-pointer class which points to a reference-counted object.
A base class which provides methods for reference-counting.
An image storage type which holds the pixels in-memory as a simple block of values.
Definition juce_Image.h:530
#define JUCE_LEAK_DETECTOR(OwnerClass)
This macro lets you embed a leak-detecting object inside a class.
#define JUCE_DECLARE_NON_COPYABLE(className)
This is a shorthand macro for deleting a class's copy constructor and copy assignment operator.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
unsigned char uint8
A platform-independent 8-bit unsigned integer type.
Used to receive callbacks for image data changes.
Definition juce_Image.h:479
typedef size_t