openshot-audio  0.1.4
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) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_IMAGE_H_INCLUDED
26 #define JUCE_IMAGE_H_INCLUDED
27 
28 class ImageType;
29 class ImagePixelData;
30 
31 
32 //==============================================================================
55 {
56 public:
57  //==============================================================================
61  {
63  RGB,
64  ARGB,
65  SingleChannel
66  };
67 
68  //==============================================================================
70  Image() noexcept;
71 
86  Image (PixelFormat format, int imageWidth, int imageHeight, bool clearImage);
87 
101  Image (PixelFormat format, int imageWidth, int imageHeight, bool clearImage, const ImageType& type);
102 
109  Image (const Image&) noexcept;
110 
117  Image& operator= (const Image&);
118 
119  #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
120  Image (Image&&) noexcept;
121  Image& operator= (Image&&) noexcept;
122  #endif
123 
125  ~Image();
126 
128  bool operator== (const Image& other) const noexcept { return image == other.image; }
129 
131  bool operator!= (const Image& other) const noexcept { return image != other.image; }
132 
139  inline bool isValid() const noexcept { return image != nullptr; }
140 
147  inline bool isNull() const noexcept { return image == nullptr; }
148 
152  static const Image null;
153 
154  //==============================================================================
156  int getWidth() const noexcept;
157 
159  int getHeight() const noexcept;
160 
164  Rectangle<int> getBounds() const noexcept;
165 
167  PixelFormat getFormat() const noexcept;
168 
170  bool isARGB() const noexcept;
171 
173  bool isRGB() const noexcept;
174 
176  bool isSingleChannel() const noexcept;
177 
179  bool hasAlphaChannel() const noexcept;
180 
181  //==============================================================================
187  void clear (const Rectangle<int>& area, Colour colourToClearTo = Colour (0x00000000));
188 
196  Image rescaled (int newWidth, int newHeight,
197  Graphics::ResamplingQuality quality = Graphics::mediumResamplingQuality) const;
198 
204  Image createCopy() const;
205 
213  Image convertedToFormat (PixelFormat newFormat) const;
214 
226  void duplicateIfShared();
227 
239  Image getClippedImage (const Rectangle<int>& area) const;
240 
241  //==============================================================================
249  Colour getPixelAt (int x, int y) const;
250 
261  void setPixelAt (int x, int y, Colour colour);
262 
273  void multiplyAlphaAt (int x, int y, float multiplier);
274 
283  void multiplyAllAlphas (float amountToMultiplyBy);
284 
287  void desaturate();
288 
289  //==============================================================================
307  {
308  public:
310  {
313  readWrite
314  };
315 
316  BitmapData (Image& image, int x, int y, int w, int h, ReadWriteMode mode);
317  BitmapData (const Image& image, int x, int y, int w, int h);
318  BitmapData (const Image& image, ReadWriteMode mode);
319  ~BitmapData();
320 
325  inline uint8* getLinePointer (int y) const noexcept { return data + y * lineStride; }
326 
331  inline uint8* getPixelPointer (int x, int y) const noexcept { return data + y * lineStride + x * pixelStride; }
332 
337  Colour getPixelColour (int x, int y) const noexcept;
338 
343  void setPixelColour (int x, int y, Colour colour) const noexcept;
344 
346  Rectangle<int> getBounds() const noexcept { return Rectangle<int> (width, height); }
347 
352  int width, height;
353 
354  //==============================================================================
357  {
358  protected:
360  public:
361  virtual ~BitmapDataReleaser() {}
362  };
363 
365 
366  private:
367  JUCE_DECLARE_NON_COPYABLE (BitmapData)
368  };
369 
370  //==============================================================================
372  void moveImageSection (int destX, int destY,
373  int sourceX, int sourceY,
374  int width, int height);
375 
383  void createSolidAreaMask (RectangleList<int>& result, float alphaThreshold) const;
384 
385  //==============================================================================
391  NamedValueSet* getProperties() const;
392 
393  //==============================================================================
397  LowLevelGraphicsContext* createLowLevelContext() const;
398 
404  int getReferenceCount() const noexcept;
405 
406  //==============================================================================
408  ImagePixelData* getPixelData() const noexcept { return image; }
409 
411  explicit Image (ImagePixelData*) noexcept;
412 
413 private:
414  //==============================================================================
416 
417  JUCE_LEAK_DETECTOR (Image)
418 };
419 
420 
421 //==============================================================================
433 {
434 public:
435  ImagePixelData (Image::PixelFormat, int width, int height);
436  ~ImagePixelData();
437 
439  virtual LowLevelGraphicsContext* createLowLevelContext() = 0;
441  virtual ImagePixelData* clone() = 0;
443  virtual ImageType* createType() const = 0;
445  virtual void initialiseBitmapData (Image::BitmapData&, int x, int y, Image::BitmapData::ReadWriteMode) = 0;
449  virtual int getSharedCount() const noexcept;
450 
451 
454  const int width, height;
455 
460 
462 
463  //==============================================================================
464  struct Listener
465  {
466  virtual ~Listener() {}
467 
468  virtual void imageDataChanged (ImagePixelData*) = 0;
469  virtual void imageDataBeingDeleted (ImagePixelData*) = 0;
470  };
471 
473 
474  void sendDataChangeMessage();
475 
476 private:
478 };
479 
480 //==============================================================================
488 {
489 public:
490  ImageType();
491  virtual ~ImageType();
492 
494  virtual ImagePixelData::Ptr create (Image::PixelFormat format, int width, int height, bool shouldClearImage) const = 0;
495 
497  virtual int getTypeID() const = 0;
498 
503  virtual Image convert (const Image& source) const;
504 };
505 
506 //==============================================================================
512 {
513 public:
516 
517  ImagePixelData::Ptr create (Image::PixelFormat, int width, int height, bool clearImage) const override;
518  int getTypeID() const override;
519 };
520 
521 //==============================================================================
528 {
529 public:
530  NativeImageType();
531  ~NativeImageType();
532 
533  ImagePixelData::Ptr create (Image::PixelFormat, int width, int height, bool clearImage) const override;
534  int getTypeID() const override;
535 };
536 
537 
538 #endif // JUCE_IMAGE_H_INCLUDED
virtual ~Listener()
Definition: juce_Image.h:466
Definition: juce_Image.h:311
Definition: juce_Image.h:527
const int width
Definition: juce_Image.h:454
Rectangle< int > getBounds() const noexcept
Definition: juce_Image.h:346
bool isNull() const noexcept
Definition: juce_Image.h:147
#define noexcept
Definition: juce_CompilerSupport.h:141
uint8 * getLinePointer(int y) const noexcept
Definition: juce_Image.h:325
ReferenceCountedObjectPtr< ImagePixelData > Ptr
Definition: juce_Image.h:461
Definition: juce_Image.h:432
PixelFormat pixelFormat
Definition: juce_Image.h:349
Definition: juce_Image.h:464
NamedValueSet userData
Definition: juce_Image.h:459
Definition: juce_Image.h:312
ScopedPointer< BitmapDataReleaser > dataReleaser
Definition: juce_Image.h:364
ReadWriteMode
Definition: juce_Image.h:309
Definition: juce_Image.h:63
Definition: juce_Image.h:511
BitmapDataReleaser()
Definition: juce_Image.h:359
Definition: juce_Image.h:487
#define JUCE_API
Definition: juce_StandardHeader.h:139
PixelFormat
Definition: juce_Image.h:60
uint8 * data
Definition: juce_Image.h:348
ListenerList< Listener > listeners
Definition: juce_Image.h:472
Definition: juce_ReferenceCountedObject.h:65
Definition: juce_Rectangle.h:36
virtual ~BitmapDataReleaser()
Definition: juce_Image.h:361
int width
Definition: juce_Image.h:352
Definition: juce_NamedValueSet.h:39
Definition: juce_Colour.h:35
Definition: juce_Image.h:64
Definition: juce_ListenerList.h:69
const Image::PixelFormat pixelFormat
Definition: juce_Image.h:453
Definition: juce_ScopedPointer.h:70
int lineStride
Definition: juce_Image.h:350
bool operator==(const var &v1, const var &v2) noexcept
Definition: juce_Variant.cpp:565
Definition: juce_Image.h:306
#define JUCE_DECLARE_NON_COPYABLE(className)
Definition: juce_PlatformDefs.h:191
Definition: juce_Image.h:62
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
Definition: juce_GraphicsContext.h:42
Definition: juce_Image.h:54
int pixelStride
Definition: juce_Image.h:351
Definition: juce_LowLevelGraphicsContext.h:43
Definition: juce_Image.h:356
#define JUCE_LEAK_DETECTOR(OwnerClass)
Definition: juce_LeakedObjectDetector.h:141
bool operator!=(const var &v1, const var &v2) noexcept
Definition: juce_Variant.cpp:566
unsigned char uint8
Definition: juce_MathsFunctions.h:43
bool isValid() const noexcept
Definition: juce_Image.h:139
static const Image null
Definition: juce_Image.h:152
uint8 * getPixelPointer(int x, int y) const noexcept
Definition: juce_Image.h:331