ADTF Display Toolbox
image.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <adtf_base.h>
13 
14 namespace adtf
15 {
16 
17 namespace disptb
18 {
19 
20 namespace graphicslib
21 {
22 
23 namespace dengar
24 {
25 class cColor;
26 
32 class cImage : public IImage
33 {
37  A_UTILS_D(cImage)
38 
39 public:
42 
43 protected:
44  tBool m_bReference;
45 
49 
50  tColor* m_pPalette;
51  tUInt8* m_pBitmap;
52  tHandle m_hBitmapMemory;
53 
55 
56 public:
60  cImage();
61 
66  cImage(const cImage& oImage);
67 
72  cImage(const IImage& oImage);
73 
77  virtual ~cImage();
78 
82  tVoid Destroy();
83 
100  tResult Create(tInt nWidth, tInt nHeight, tInt nBitsPerPixel, tInt nBytesPerLine = 0, const tUInt8* pBitmap = nullptr,
101  tInt nPixelFormat = 0);
102 
117  tResult Create(const tBitmapFormat* psFormat, const tColor* pPalette = nullptr, const tUInt8* pBitmap = nullptr);
118 
133  tResult Attach(tUInt8* pBitmap, tInt nWidth, tInt nHeight, tInt nBitsPerPixel, tInt nBytesPerLine = 0);
134 
149  tResult Attach(tUInt8* pBitmap, const tBitmapFormat* psFormat, const tColor* pPalette = nullptr);
150 
170  tResult Load(const tChar* strFile, tUInt32 nFlags = 0);
171 
186  tResult Save(const tChar* strFile);
187 
193  tResult Release();
194 
202  tResult SetPixelFormat(tInt nPixelFormat);
203 
209  tInt GetPixelFormat() const;
210 
218  char const* GetPixelFormatStr() const;
219 
227  static tInt FlipRGBFormat(tInt nPixelFormat);
228 
237  static tInt FlipToBGRFormat(tInt nPixelFormat);
238 
247  static tInt FlipToRGBFormat(tInt nPixelFormat);
248 
254  tInt GetWidth() const;
255 
261  tInt GetHeight() const;
262 
268  tInt GetBitsPerPixel() const;
269 
277  tInt GetBytesPerLine() const;
278 
284  tInt GetSize() const;
285 
291  tFloat64 GetRatio() const;
292 
299  const tBitmapFormat* GetFormat() const override;
300 
311  tResult SetPalette(tInt nPaletteSize, const tColor* pPalette);
312 
318  tColor* GetPalette() const;
319 
325  tInt GetPaletteSize() const;
326 
334  tColor GetPaletteEntry(tInt nIdx) const;
335 
345  tResult SetPaletteEntry(tInt nIdx, const tColor& sColor);
346 
352  tUInt8* GetBitmap() const;
353 
363  tUInt8* GetBitmapLine(tInt y) const;
364 
373 
380 
386  operator IImage*()
387  {
388  return dynamic_cast<IImage*>(this);
389  }
390 
391 public: // image manipulation
400  tResult Flip();
401 
409  tResult Mirror();
410 
427  tResult Resize(tInt nWidth, tInt nHeight);
428 
445  tResult ChangeDepth(tInt nBitsPerPixel, tInt nBytesPerLine = 0, tUInt32 ui32Mask = 0x0);
446 
461  tResult Convert(tInt nWidth, tInt nHeight, tInt nBitsPerPixel, tInt nBytesPerLine = 0, tUInt32 ui32Mask = 0x0);
462 
477  tResult Convert(const tBitmapFormat* psFormat, tUInt32 ui32Mask = 0x0);
478 
487  tResult Convert(tInt oPixelFormat);
488 
502  tResult ChangePixelFormat(tInt nFormat, tUInt32 ui32Flags = 0);
503 
516  tResult FlipRGB();
517 
525  tResult FlipAlpha();
526 
539  tResult MakeAlphaChannel(const tColor& sColorKey, tBool bClearTransparent = tFalse);
540 
541 public: // blit functions
555  tResult Blit(const cImage& oDestImage, tInt nFlags = 0);
556 
571  tResult SetBits(const tUInt8* pSrcBitmapData, const tBitmapFormat* psSrcBitmapFormat);
572 
585  tResult GetBits(tUInt8* pDestBitmapData, const tBitmapFormat* psDestBitmapFormat, tInt nFlags = 0);
586 
587 public: // static blit functions
588 
603  static tResult Blit(const disptb::graphicslib::dengar::cImage& oSrcImage,
604  const disptb::graphicslib::dengar::cImage& oDestImage,
605  tInt nFlags = 0);
606 
622  static tResult Blit(const tUInt8* pSrcBitmapData,
623  const tBitmapFormat* psSrcBitmapFormat,
624  tUInt8* pDestBitmapData,
625  const tBitmapFormat* psDestBitmapFormat,
626  tInt nFlags = 0);
627 
643  static tResult StretchBlit(const disptb::graphicslib::dengar::cImage& oSrcImage,
644  const disptb::graphicslib::dengar::cImage& oDestImage,
645  tInt nFlags = 0);
646 
664  static tResult StretchBlit(const tUInt8* pSrcBitmapData,
665  const tBitmapFormat* psSrcBitmapFormat,
666  tUInt8* pDestBitmapData,
667  const tBitmapFormat* psDestBitmapFormat,
668  tInt nFlags = 0);
669 
703  static tResult Convert(const tUInt8* pSrcBitmapData,
704  const tBitmapFormat* psSrcBitmapFormat,
705  tUInt8* pDestBitmapData,
706  const tBitmapFormat* psDestBitmapFormat,
707  tInt nFlags,
708  tUInt32 ui32Mask);
709 
721  static tResult AlphaBlend(disptb::graphicslib::dengar::cImage* pSourceImage,
724 
737 
749 
750 public: // color functions
758  static inline tUInt8 RedValue(tUInt32 nColor)
759  {
760  return ((tUInt8) (nColor));
761  };
762 
770  static inline tUInt8 GreenValue(tUInt32 nColor)
771  {
772  return ((tUInt8) (((tUInt16) (nColor)) >> 8));
773  };
774 
782  static inline tUInt8 BlueValue(tUInt32 nColor)
783  {
784  return ((tUInt8) ((nColor) >> 16));
785  };
786 
796  static inline tFloat64 Brightness(tFloat64 fRed, tFloat64 fGreen, tFloat64 fBlue)
797  {
798  return (0.114 * fRed + 0.587 * fGreen + 0.299 * fBlue);
799  }
800 
810  static inline tInt BrightnessValue(tInt nRed, tInt nGreen, tInt nBlue)
811  {
812  return 116 * nRed + 602 * nGreen + 306 * nBlue;
813  }
814 
824  static inline tUInt8 Brightness(tInt nRed, tInt nGreen, tInt nBlue)
825  {
826  return (tUInt8) (disptb::graphicslib::dengar::cImage::BrightnessValue(nRed, nGreen, nBlue) >> 10);
827  }
828 
836  static inline tUInt8 Brightness(tColor nColor)
837  {
838  return (tUInt8) (disptb::graphicslib::dengar::cImage::BrightnessValue(nColor.nRed, nColor.nGreen, nColor.nBlue) >> 10);
839  }
840 
848  static inline tUInt8 Brightness(tUInt32 nColor)
849  {
850  return (tUInt8) (disptb::graphicslib::dengar::cImage::BrightnessValue(RedValue(nColor), GreenValue(nColor), BlueValue(nColor)) >> 10);
851  }
852 
853 public: // helper functions
854 #ifdef WIN32
867  tResult LoadResource(tInt nResourceId, tHandle hModule=NULL, tUInt32 nFlags=0);
882  tResult CaptureScreen(tInt x, tInt y, tInt nWidth, tInt nHeight);
891  tHandle CreateRegion();
892 #endif // WIN32
893 
903 
912 
922  static tInt CalcAlignedMemSize(tInt nBytes, tInt nAlignment);
923 
930  static tInt GuessPixelFormat(const tBitmapFormat* pFormat);
931 
939  static tInt GetBitsPerPixelFromFormat(tInt nFormat);
940 
948  static tInt GetDefaultFormatFromBpp(tInt nBpp);
949 
957  static tChar const* GetPixelFormatIdentifier(const tInt nImage);
958 
959 protected: // internal
965  tResult Initialize();
966 
974  tResult Alloc(const tBitmapFormat* psFormat);
975 
981  tResult Free();
982 
992  tResult AllocImpl(tInt nSize, tHandle* hMemory, tVoid** pBuffer);
993 
1001  tResult FreeImpl(tHandle hMemory);
1002 
1010  tResult AllocPalette(tInt nPaletteSize);
1011 
1017  tResult FreePalette();
1018 
1024  tResult AllocBitmapInfo();
1025 
1031  tResult FreeBitmapInfo();
1032 
1033 protected: // internal blitting operations
1045  static tResult Blit_impl(const tUInt8* pSrcBitmapData,
1046  const tBitmapFormat* psSrcBitmapFormat,
1047  tUInt8* pDestBitmapData,
1048  const tBitmapFormat* psDestBitmapFormat,
1049  tInt nFlags);
1050 
1063  static tResult StretchBlit_impl(const tUInt8* pSrcBitmapData,
1064  const tBitmapFormat* psSrcBitmapFormat,
1065  tUInt8* pDestBitmapData,
1066  const tBitmapFormat* psDestBitmapFormat,
1067  tInt nFlags,
1068  tUInt32 ui32Mask = 0x0);
1069 
1083  static tResult Convert_impl(const tUInt8* pSrcBitmapData,
1084  const tBitmapFormat* psSrcBitmapFormat,
1085  tUInt8* pDestBitmapData,
1086  const tBitmapFormat* psDestBitmapFormat,
1087  tInt nFlags,
1088  tUInt32 ui32Mask);
1089 
1090 
1091 protected:
1092  /*static tResult StretchConvert_impl(const tUInt8* pSrcBitmapData,
1093  const tBitmapFormat* psSrcBitmapFormat,
1094  tUInt8* pDestBitmapData,
1095  const tBitmapFormat* psDestBitmapFormat,
1096  tInt nFlags,
1097  tUInt32 ui32Mask);*/
1098 public:
1107 
1108 public:
1109  static int32_t GetNextPowerOfTwo(int32_t const a);
1110 
1111  static int32_t CalcBitsPerPixelFromPixelFormat(int32_t const oPixelFormat);
1112 
1113  static bool NeedAlphaBlend(int32_t const oPixelFormat);
1114 };
1115 
1116 #pragma pack(push)
1117 #pragma pack(1)
1121 typedef struct
1122 {
1123  tUInt16 ui16Type;
1124  tUInt32 ui32Size;
1125  tUInt16 ui16Reserved1;
1126  tUInt16 ui16Reserved2;
1127  tUInt32 ui32DataOffset;
1129 
1130 #pragma pack(pop)
1131 }
1132 
1133 using dengar::cImage;
1134 }
1135 
1136 }
1137 
1138 }
Image and bitmap handling.
Definition: image_intf.h:29
Image and bitmap handling.
Definition: image.h:33
static tInt m_nDefaultLineAlignment
the default line alignment, currently power of 2
Definition: image.h:41
static tResult SetTransparency(disptb::graphicslib::dengar::cImage *pImage, disptb::graphicslib::dengar::cColor oColor)
Helper method for setting transparency in bitmaps.
tUInt8 * GetBitmapLine(tInt y) const
Returns a pointer to raw data of a line.
tResult SetPalette(tInt nPaletteSize, const tColor *pPalette)
Sets a color palette.
static tInt CalcAlignedMemSize(tInt nBytes, tInt nAlignment)
Calculate the size of a given number of bytes to match a given alignment.
disptb::graphicslib::dengar::cImage & operator=(const disptb::graphicslib::dengar::cImage &oImage)
Set the current image to the image oImage.
tResult FreeBitmapInfo()
Free space from bitmap info.
tResult Convert(tInt nWidth, tInt nHeight, tInt nBitsPerPixel, tInt nBytesPerLine=0, tUInt32 ui32Mask=0x0)
Converts the image to new dimensions and color depth.
char const * GetPixelFormatStr() const
Retrieves the image's pixel format as string.
tResult Save(const tChar *strFile)
Saves the image to a file.
static tInt GuessPixelFormat(const tBitmapFormat *pFormat)
Tries to guess the PixelFormat based on the other parameters of a bitmap format.
tInt GetBitmapInfoSize()
Returns the size of the Win32 image descriptor.
tResult Alloc(const tBitmapFormat *psFormat)
Allocates the image's bitmap buffer.
tBool Compare(const disptb::graphicslib::dengar::cImage &oImage)
Compares the bitmaps of two images.
static tInt GetDefaultFormatFromBpp(tInt nBpp)
Retrieve image format based on image resolution.
static tResult BilinearStretchBlit(disptb::graphicslib::dengar::cImage &oSrc, disptb::graphicslib::dengar::cImage &oDest)
Copies an image to another using the bilinear algorithm.
tResult Resize(tInt nWidth, tInt nHeight)
Resizes the image to the new height nHeight and width nWidth.
static tResult Convert(const tUInt8 *pSrcBitmapData, const tBitmapFormat *psSrcBitmapFormat, tUInt8 *pDestBitmapData, const tBitmapFormat *psDestBitmapFormat, tInt nFlags, tUInt32 ui32Mask)
Converts an image to another format.
static tInt FlipToBGRFormat(tInt nPixelFormat)
Returns the pixel format flipped to BGR.
tInt GetPixelFormat() const
Returns the pixel format.
tResult FlipAlpha()
Flips the alpha part from left to right and back:ARGB <-> RGBA and ABGR <-> BGRA.
tUInt8 * m_pBitmap
actual pixel data, may be reference to data of other pic
Definition: image.h:51
tInt m_nBitmapInfoSize
size of windows bitmap info
Definition: image.h:48
tResult Attach(tUInt8 *pBitmap, const tBitmapFormat *psFormat, const tColor *pPalette=nullptr)
Attaches an image reference.
tWin32BitmapInfo * m_psBitmapInfo
current bitmap info, windows style
Definition: image.h:47
tResult Free()
Frees the image's bitmap buffer.
static tFloat64 Brightness(tFloat64 fRed, tFloat64 fGreen, tFloat64 fBlue)
Calculates the bringhtness value of a color.
Definition: image.h:796
tInt m_nGreyPaletteSize
size of palette
Definition: image.h:54
static tResult StretchBlit_impl(const tUInt8 *pSrcBitmapData, const tBitmapFormat *psSrcBitmapFormat, tUInt8 *pDestBitmapData, const tBitmapFormat *psDestBitmapFormat, tInt nFlags, tUInt32 ui32Mask=0x0)
Internal blitting operation.
tResult FlipRGB()
Flips RGB to BGR and the other way around.
cImage(const cImage &oImage)
Copy constructor.
tResult Attach(tUInt8 *pBitmap, tInt nWidth, tInt nHeight, tInt nBitsPerPixel, tInt nBytesPerLine=0)
Attaches an image reference.
tResult SetPixelFormat(tInt nPixelFormat)
Sets the pixel format used.
tInt GetBytesPerLine() const
Returns the bytes per line of the image.
static tResult Blit(const tUInt8 *pSrcBitmapData, const tBitmapFormat *psSrcBitmapFormat, tUInt8 *pDestBitmapData, const tBitmapFormat *psDestBitmapFormat, tInt nFlags=0)
Copies bitmap data from one image to another.
static tInt GetBitsPerPixelFromFormat(tInt nFormat)
Retrieve image resolution from image format.
static tResult Blit_impl(const tUInt8 *pSrcBitmapData, const tBitmapFormat *psSrcBitmapFormat, tUInt8 *pDestBitmapData, const tBitmapFormat *psDestBitmapFormat, tInt nFlags)
Internal blitting operation.
static tUInt8 RedValue(tUInt32 nColor)
Returns the red component of a color.
Definition: image.h:758
tResult AllocPalette(tInt nPaletteSize)
Allocate space for a palette.
tUInt8 * GetBitmap() const
Returns a pointer to the raw data.
static tResult StretchBlit(const tUInt8 *pSrcBitmapData, const tBitmapFormat *psSrcBitmapFormat, tUInt8 *pDestBitmapData, const tBitmapFormat *psDestBitmapFormat, tInt nFlags=0)
Copies bitmap data from one image (with height H1 and width W1) to another image, stretching the scr ...
tInt GetWidth() const
Returns the width of the image.
cImage(const IImage &oImage)
Copy constructor.
tResult GetBits(tUInt8 *pDestBitmapData, const tBitmapFormat *psDestBitmapFormat, tInt nFlags=0)
Retrieves the image's bitmap data.
tResult FreePalette()
Frees space from palette.
tResult Create(tInt nWidth, tInt nHeight, tInt nBitsPerPixel, tInt nBytesPerLine=0, const tUInt8 *pBitmap=nullptr, tInt nPixelFormat=0)
Creates a new image.
static tInt FlipToRGBFormat(tInt nPixelFormat)
Returns the pixel format flipped to RGB.
tColor GetPaletteEntry(tInt nIdx) const
Returns a color palette entry.
tInt GetPaletteSize() const
Returns the color palette size.
static tUInt8 Brightness(tUInt32 nColor)
Calculates the bringhtness value of a color.
Definition: image.h:848
static tInt BrightnessValue(tInt nRed, tInt nGreen, tInt nBlue)
Calculates the bringhtness value of a color without scaling it down.
Definition: image.h:810
tResult Create(const tBitmapFormat *psFormat, const tColor *pPalette=nullptr, const tUInt8 *pBitmap=nullptr)
Creates a new image from a bitmap format description.
tColor * GetPalette() const
Returns the color palette.
tResult Release()
Frees all allocated resources.
tResult Flip()
Flips the image upside down.
tResult AllocBitmapInfo()
Allocate space for bitmap info.
tResult ChangeDepth(tInt nBitsPerPixel, tInt nBytesPerLine=0, tUInt32 ui32Mask=0x0)
Changes the color depth.
static tResult Blit(const disptb::graphicslib::dengar::cImage &oSrcImage, const disptb::graphicslib::dengar::cImage &oDestImage, tInt nFlags=0)
Copies bitmap data from one image to another.
tResult Mirror()
Mirrors the image.
static tResult AlphaBlend(disptb::graphicslib::dengar::cImage *pSourceImage, disptb::graphicslib::dengar::cImage *pDestImage, disptb::graphicslib::dengar::cImage *pMaskImage)
Alpha blends an image to a destination image.
tResult SetBits(const tUInt8 *pSrcBitmapData, const tBitmapFormat *psSrcBitmapFormat)
Sets the image's bitmap data.
tInt CountDifferences(const disptb::graphicslib::dengar::cImage &oImage)
Compares the bitmaps of two images and counts the amount of different pixels.
static tUInt8 GreenValue(tUInt32 nColor)
Returns the green component of a color.
Definition: image.h:770
tResult FreeImpl(tHandle hMemory)
Internal implementation of the free function.
tVoid Destroy()
Destroy the instance.
tResult AllocImpl(tInt nSize, tHandle *hMemory, tVoid **pBuffer)
Internal implementation of the allocation function.
tResult Convert(tInt oPixelFormat)
Converts the image to a new image format.
tBool m_bReference
flag indicating the m_pBitmap pointer is used as a reference
Definition: image.h:44
static tInt m_nDefaultMemoryAlignment
D-Pointer implementation.
Definition: image.h:40
tWin32BitmapInfo * GetBitmapInfo() override
Generates a Win32 image descriptor.
static tResult StretchBlit(const disptb::graphicslib::dengar::cImage &oSrcImage, const disptb::graphicslib::dengar::cImage &oDestImage, tInt nFlags=0)
Copies bitmap data from one image (with height H1 and width W1) to another image, stretching the scr ...
static tInt FlipRGBFormat(tInt nPixelFormat)
Returns the format with flipped RGB.
tResult Initialize()
Initialize the image.
static tChar const * GetPixelFormatIdentifier(const tInt nImage)
Returns the image format as string (enum to string)
static tUInt8 Brightness(tColor nColor)
Calculates the bringhtness value of a color.
Definition: image.h:836
tColor * m_pPalette
array of colors making up the palette
Definition: image.h:50
const tBitmapFormat * GetFormat() const override
Returns the current bitmap format of the image.
tHandle m_hBitmapMemory
Handle for bitmap memory.
Definition: image.h:52
tResult Blit(const cImage &oDestImage, tInt nFlags=0)
Copies bitmap data from one image to another.
tResult Load(const tChar *strFile, tUInt32 nFlags=0)
Loads an image from a file.
static tUInt8 BlueValue(tUInt32 nColor)
Returns the blue component of a color.
Definition: image.h:782
tResult Convert(const tBitmapFormat *psFormat, tUInt32 ui32Mask=0x0)
Converts the image to a new image format.
static tResult Convert_impl(const tUInt8 *pSrcBitmapData, const tBitmapFormat *psSrcBitmapFormat, tUInt8 *pDestBitmapData, const tBitmapFormat *psDestBitmapFormat, tInt nFlags, tUInt32 ui32Mask)
will convert the bitmap from one format to another one.
tInt GetHeight() const
Returns the height of the image.
tInt GetSize() const
Returns the size of the image in bytes.
static tUInt8 Brightness(tInt nRed, tInt nGreen, tInt nBlue)
Calculates the bringhtness value of a color.
Definition: image.h:824
tResult SetPaletteEntry(tInt nIdx, const tColor &sColor)
Sets an entry of the color palette.
tResult MakeAlphaChannel(const tColor &sColorKey, tBool bClearTransparent=tFalse)
Creates an alpha channel.
tResult ChangePixelFormat(tInt nFormat, tUInt32 ui32Flags=0)
Changes the pixel format used.
tFloat64 GetRatio() const
Returns the aspect ratio of the image.
tInt GetBitsPerPixel() const
Returns the bits per pixel of the image.
tBitmapFormat m_sFormat
current format of bitmap
Definition: image.h:46
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Main namespace.
This structure defines the file header used to load and save a bitmap.
Definition: image.h:1122
tUInt16 ui16Type
always 0x4D42, for more information have a look at http://msdn.microsoft.com/en-us/library/AA930979....
Definition: image.h:1123
tUInt32 ui32Size
actual size of data + this header + windows bitmap header + palette
Definition: image.h:1124
Struct to specifie a bitmap.
Struct to get the informations and the color about a bitmap.