PImage.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2018 Digital Barriers plc. All rights reserved.
3  * Contact: http://www.digitalbarriers.com/
4  *
5  * This file is part of the Papillon SDK.
6  *
7  * You can't use, modify or distribute any part of this file without
8  * the explicit written agreements of Digital Barriers.
9  */
10 
15 #pragma once
16 #include <PObject.h>
17 #include <PColour3i.h>
18 
19 PAPILLON_BEGIN_NAMESPACE
20 
23 
24 class PByteArray;
25 class PPoint2Df;
26 class PPoint2Di;
27 class PPolygonf;
28 class PPolygoni;
29 class PRectanglef;
30 class PRectanglei;
31 class PSizei;
32 
33 
37 static const papillon::int32 WAIT_FOR_RETURN = -1;
38 
39 
57 class PAPILLON_API_CORE PImage : public PObject
58 {
59 public:
64  {
72  E_HSV8U
73  };
74 
75 
80  {
81  E_INTERPOLATION_NEAREST = 0,
85  E_INTERPOLATION_LANCZOS4
86  };
87 
88 
93  {
94  E_IGNORE_ASPECT_RATIO = 0,
98  E_KEEP_ASPECT_RATIO_FILL_BORDER
99  };
100 
101 
105  enum EFont
106  {
107  E_FONT_HERSHEY_SIMPLEX = 0,
108  E_FONT_HERSHEY_PLAIN = 1,
109  E_FONT_HERSHEY_DUPLEX = 2,
110  E_FONT_HERSHEY_COMPLEX = 3,
111  E_FONT_HERSHEY_TRIPLEX = 4,
112  E_FONT_HERSHEY_COMPLEX_SMALL = 5,
113  E_FONT_HERSHEY_SCRIPT_SIMPLEX = 6,
114  E_FONT_HERSHEY_SCRIPT_COMPLEX = 7
115  };
116 
117 
122  {
123  E_UNKNOWN_FILE_FORMAT = 0,
132  E_JP2
133  };
134 
135 public:
139  static papillon::int32 MaxSize() { return 16384; }
140 
164  explicit PImage(papillon::int32 width = 0, papillon::int32 height = 0, PImage::EPixelFormat pixelFormat = PImage::E_BGR8U);
165 
171  PImage(const PImage& other);
172 
176  virtual ~PImage();
177 
183  PImage& operator=(const PImage& other);
184 
188  PImage Clone() const;
189 
196  bool operator==(const PImage& other) const;
197 
223  void Allocate(papillon::int32 width, papillon::int32 height, PImage::EPixelFormat pixelFormat = PImage::E_BGR8U);
224 
228  papillon::int32 GetWidth() const;
229 
233  papillon::int32 GetHeight() const;
234 
238  PRectanglei GetRectangle() const;
239 
243  PSizei GetSize() const;
244 
248  PSizei ScaleSize(float scaleFactor) const;
249 
254  float GetAspectRatio() const;
255 
260  papillon::int32 GetNumberOfChannels() const;
261 
265  papillon::int32 GetSizeInBytes() const;
266 
271  papillon::int32 GetSizeOfRowInBytes() const;
272 
276  papillon::int32 GetSizeOfPixelInBytes() const;
277 
281  PImage::EPixelFormat GetPixelFormat() const;
282 
286  PString GetPixelFormatToString() const;
287 
291  static PString GetPixelFormatToString(PImage::EPixelFormat pixelFormat);
292 
296  static PString GetAspectRatioToString(PImage::EAspectRatioMode aspectRatioMode);
297 
303  static PImage::EFileFormat GetEFileFormatFromString(const PString& format);
304 
308  static PString GetEFileFormatToString(PImage::EFileFormat format);
309 
315  papillon::uint8* GetDataPtr(papillon::int32 row = 0) const;
316 
321  papillon::uint8* GetPixel(papillon::int32 x, papillon::int32 y) const;
322 
327  bool IsEmpty() const;
328 
333  bool IsGrayscale() const;
334 
339  bool IsSame(const PImage& other) const;
340 
347  PResult Set(const void* inputRawBuffer, papillon::int32 width, papillon::int32 height, PImage::EPixelFormat pixelFormat);
348 
360  PResult ExtractSubImage(PImage& dest, papillon::int32 x, papillon::int32 y, papillon::int32 width, papillon::int32 height) const;
361 
373  PResult ExtractSubImage(PImage& dest, const PRectanglei& r) const;
374 
379  PResult Crop(papillon::int32 x, papillon::int32 y, papillon::int32 width, papillon::int32 height);
380 
385  PResult Crop(const PRectanglei& r);
386 
391  PResult InsertImageInPlace(const PImage& image, papillon::int32 x, papillon::int32 y);
392 
401  PResult Convert(PImage& dest, PImage::EPixelFormat destImageType) const;
402 
414  PResult SwapRGB(PImage& dest) const;
415 
430  PResult Resize(PImage& dest, papillon::int32 newWidth, papillon::int32 newHeight, PImage::EAspectRatioMode aspectRatioMode = PImage::E_IGNORE_ASPECT_RATIO, PImage::EInterpolation interpolation = PImage::E_INTERPOLATION_LINEAR) const;
431 
443  PResult Resize(papillon::int32 newWidth, papillon::int32 newHeight, PImage::EAspectRatioMode aspectRatioMode = PImage::E_IGNORE_ASPECT_RATIO, PImage::EInterpolation interpolation = PImage::E_INTERPOLATION_LINEAR);
444 
457  PResult Resize(PImage& dest, const PSizei& newSize, PImage::EAspectRatioMode aspectRatioMode = PImage::E_IGNORE_ASPECT_RATIO, PImage::EInterpolation interpolation = PImage::E_INTERPOLATION_LINEAR) const;
458 
469 
482  PResult Resize(PImage& dest, const float scaleFactor, PImage::EInterpolation interpolation = PImage::E_INTERPOLATION_LINEAR) const;
483 
493  PResult Resize(const float scaleFactor, PImage::EInterpolation interpolation = PImage::E_INTERPOLATION_LINEAR);
494 
504  PResult EqualizeHistogram(PImage& dest);
505 
512  PResult Rotate(PImage& dest, papillon::int32 angleInDegrees);
513 
523  PResult Blur(PImage& dest, double blurFactor) const;
524 
528  void Clear();
529 
535  PResult Fill(const PColour3i& color);
536 
541  PResult DrawString(const PString& text, const PPoint2Di& origin, PImage::EFont font, const PColour3i& color, double fontScale = 1.0);
542 
547  PResult DrawString(const PString& text, const PPoint2Di& origin, const PString& fontName, papillon::int32 fontSize, const PColour3i& fontColor);
548 
549 
563  PResult DrawLabel(const PString& text,
564  const PPoint2Di& centre,
565  const PColour3i& labelColour = PColour3i::Black(),
566  const PColour3i& textColor = PColour3i::White(),
568  double labelScale = 1.0);
569 
570 
574  PResult DrawLine(papillon::int32 x1, papillon::int32 y1, papillon::int32 x2, papillon::int32 y2, const PColour3i& color, papillon::int32 thickness = 1);
575 
579  PResult DrawRectangle(const PRectanglei& r, const PColour3i& color, papillon::int32 thickness = 1);
580 
584  PResult DrawRectangle(const PRectanglef& r, const PColour3i& color, papillon::int32 thickness = 1);
585 
589  PResult FillRectangle(const PRectanglei& r, const PColour3i& color);
590 
594  PResult DrawPolygon(const PPolygoni& p, const PColour3i& color, papillon::int32 thickness = 1);
595 
599  PResult DrawPolygon(const PPolygonf& p, const PColour3i& color, papillon::int32 thickness = 1);
600 
604  PResult DrawCircle(const PPoint2Df& p, papillon::int32 radius, const PColour3i& color, papillon::int32 thickness = 1);
605 
609  PResult DrawCircle(papillon::int32 x, papillon::int32 y, papillon::int32 radius, const PColour3i& color, papillon::int32 thickness = 1);
610 
614  PResult DrawEllipse(papillon::int32 x, papillon::int32 y,papillon::int32 width, papillon::int32 height, const PColour3i& color, papillon::int32 thickness = 1);
615 
621  PString GetFingerPrint() const;
622 
626  PString MD5() const;
627 
632  PString ToJpegBase64(papillon::int32 quality = -1) const;
633 
647  PResult Load(const PByteArray& inputBuffer, papillon::int32 offset = 0);
648 
664  PResult Load(const PString& filename);
665 
671  PResult LoadFromBase64(const PString& imageBase64Encoded);
672 
691  PResult Save(PByteArray& outputBuffer, PImage::EFileFormat format, papillon::int32 quality = -1) const;
692 
707  PResult Save(const PString& filename, papillon::int32 quality = -1) const;
708 
716  PResult Display(const PString& title, papillon::int32 waitTimeMs = 0) const;
717 
727  PResult DisplayScaled(const PString& title, papillon::int32 width, papillon::int32 height, papillon::int32 waitTimeMs = 0) const;
728 
736  PResult DisplayScaled(const PString& title, papillon::int32 waitTimeMs = 0) const;
737 
741  static PResult DisplayOff(const PString& title);
742 
746  void SetDisplayPosition(const PString& title, int x, int y) const;
747 
748 #ifdef WITH_CORE_LACE
749  // Add-ons
759  PResult Lace(float strength) const;
760 #endif
761 
762 public:
779  PResult SetFromCvMat(const void* cvMat, EPixelFormat pixelFormat, bool clone = true);
780 
781 private:
782  friend class PImageInternal;
783  friend class PImageImpl;
784 };
785 
787 
788 PAPILLON_END_NAMESPACE
The PString class provides an Unicode character strings.
Definition: PString.h:37
EInterpolation
All the available interpolation mode for resize.
Definition: PImage.h:79
The PPoint2Df class represents a 2D-point with float coordinates; PPoint2Df instances are immutable (...
Definition: PPoint2Df.h:28
Resampling using pixel area relation; good choice to shrink an image.
Definition: PImage.h:83
Colour image: each pixel is a triple (B, G, R); each component is a 8-bit unsigned int...
Definition: PImage.h:66
EAspectRatioMode
All the available aspect ratio mode for resize.
Definition: PImage.h:92
The PSizei class represents the size of an image or a rectangle: width (int) and height (int); PSizei...
Definition: PSizei.h:27
EFont
All the available embedded fonts.
Definition: PImage.h:105
The PImage class represents a 2D-image; several pixel format and number of channels are supported (BG...
Definition: PImage.h:57
EFileFormat
All the available supported image format: jpg, png, tif, bmp, webp, jpeg 2000, etc.
Definition: PImage.h:121
The PResult class represents the result returned by most of Papillon functions; this class is used to...
Definition: PResult.h:159
Bilinear interpolation.
Definition: PImage.h:82
Bicubic interpolation over 4x4 pixel neighborhood.
Definition: PImage.h:84
The size is scaled to a rectangle as small as possible outside a given rectangle, preserving the aspe...
Definition: PImage.h:96
The PPolygonf class represents a 2D closed polygon with float coordinates.
Definition: PPolygonf.h:29
Gray scale image: each pixel is encoded on a single 8-bit unsigned int value.
Definition: PImage.h:70
The PByteArray class represents a resizable array of bytes.
Definition: PByteArray.h:40
static const PColour3i & Black()
Definition: PColour3i.h:110
The PObject class is the root class of all Papillon classes; all PObject behaves like shared referenc...
Definition: PObject.h:27
The PRectanglei class represents an axis-aligned rectangle with 32-bit int coordinates; PRectanglei i...
Definition: PRectanglei.h:33
The size is scaled to a rectangle as large as possible inside a given rectangle, preserving the aspec...
Definition: PImage.h:95
Colour image: each pixel is a triple (Y, Cr, Cb); each component is a 8-bit unsigned int...
Definition: PImage.h:71
The size is scaled freely; the aspect ratio is not preserve.
Definition: PImage.h:94
Colour image: each pixel is a triple (B, G, R, A); each component is a 8-bit unsigned int...
Definition: PImage.h:68
The size is scaled to a rectangle preserving as much as possible aspect ratio, while preserving minim...
Definition: PImage.h:97
The PRectanglef class represents an axis-aligned rectangle with float coordinates; PRectanglef instan...
Definition: PRectanglef.h:34
The PColour3i class represents a Red-Green-Blue color (RGB), each channel encoded with one 32-bit int...
Definition: PColour3i.h:25
static const PColour3i & White()
Definition: PColour3i.h:131
Class PColour3i: a Red-Green-Blue color (RGB), each channel encoded with one 32-bit int...
The PPolygoni class represents a 2D closed polygon with 32-bit int coordinates.
Definition: PPolygoni.h:30
bool IsSame(const PObject &obj) const
Returns true underlying object is same.
Class PObject: the root class of all Papillon classes.
static papillon::int32 MaxSize()
Returns the maximum image width and height in pixels.
Definition: PImage.h:139
PObject & operator=(const PObject &obj)
Performs a shared copy of other to this object.
Definition: PObject.h:45
The PPoint2Di class represents a 2D-point with 32-bit int coordinates; PPoint2Di instances are immuta...
Definition: PPoint2Di.h:27
Colour image: each pixel is a triple (R, G, B, A); each component is a 8-bit unsigned int...
Definition: PImage.h:69
EPixelFormat
All the available pixel formats.
Definition: PImage.h:63
Colour image: each pixel is a triple (R, G, B); each component is a 8-bit unsigned int...
Definition: PImage.h:67