ADTF_DISPLAY_TOOLBOX  3.8.0 (ADTF 3.14.3)
image.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #ifdef WIN32
10  #include <windows.h>
11 #endif
12 
13 #include <adtf_base.h>
17 
18 
19 
20 namespace adtf
21 {
22 
23 namespace disptb
24 {
25 
26 namespace graphicslib
27 {
28 
29 namespace dengar
30 {
31 class cColor;
32 
38 class cImage : public IImage
39 {
44 
45 public:
48 
49 protected:
50  tBool m_bReference;
51 
55 
56  tColor* m_pPalette;
57  tUInt8* m_pBitmap;
58  tHandle m_hBitmapMemory;
59 
61 
62 public:
66  cImage();
67 
72  cImage(const cImage& 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  static tInt FlipRGBFormat(tInt nPixelFormat);
219 
228  static tInt FlipToBGRFormat(tInt nPixelFormat);
229 
238  static tInt FlipToRGBFormat(tInt nPixelFormat);
239 
245  tInt GetWidth() const;
246 
252  tInt GetHeight() const;
253 
259  tInt GetBitsPerPixel() const;
260 
268  tInt GetBytesPerLine() const;
269 
275  tInt GetSize() const;
276 
282  tFloat64 GetRatio() const;
283 
290  const tBitmapFormat* GetFormat() const override;
291 
302  tResult SetPalette(tInt nPaletteSize, const tColor* pPalette);
303 
309  tColor* GetPalette() const;
310 
316  tInt GetPaletteSize() const;
317 
325  tColor GetPaletteEntry(tInt nIdx) const;
326 
336  tResult SetPaletteEntry(tInt nIdx, const tColor& sColor);
337 
343  tUInt8* GetBitmap() const;
344 
354  tUInt8* GetBitmapLine(tInt y) const;
355 
364 
371 
377  operator IImage*()
378  {
379  return dynamic_cast<IImage*>(this);
380  }
381 
382 public: // image manipulation
391  tResult Flip();
392 
400  tResult Mirror();
401 
418  tResult Resize(tInt nWidth, tInt nHeight);
419 
436  tResult ChangeDepth(tInt nBitsPerPixel, tInt nBytesPerLine = 0, tUInt32 ui32Mask = 0x0);
437 
452  tResult Convert(tInt nWidth, tInt nHeight, tInt nBitsPerPixel, tInt nBytesPerLine = 0, tUInt32 ui32Mask = 0x0);
453 
468  tResult Convert(const tBitmapFormat* psFormat, tUInt32 ui32Mask = 0x0);
469 
483  tResult ChangePixelFormat(tInt nFormat, tUInt32 ui32Flags = 0);
484 
497  tResult FlipRGB();
498 
506  tResult FlipAlpha();
507 
520  tResult MakeAlphaChannel(const tColor& sColorKey, tBool bClearTransparent = tFalse);
521 
522 public: // blit functions
536  tResult Blit(const cImage& oDestImage, tInt nFlags = 0);
537 
552  tResult SetBits(const tUInt8* pSrcBitmapData, const tBitmapFormat* psSrcBitmapFormat);
553 
566  tResult GetBits(tUInt8* pDestBitmapData, const tBitmapFormat* psDestBitmapFormat, tInt nFlags = 0);
567 
568 public: // static blit functions
569 
584  static tResult Blit(const disptb::graphicslib::dengar::cImage& oSrcImage,
585  const disptb::graphicslib::dengar::cImage& oDestImage,
586  tInt nFlags = 0);
587 
603  static tResult Blit(const tUInt8* pSrcBitmapData,
604  const tBitmapFormat* psSrcBitmapFormat,
605  tUInt8* pDestBitmapData,
606  const tBitmapFormat* psDestBitmapFormat,
607  tInt nFlags = 0);
608 
624  static tResult StretchBlit(const disptb::graphicslib::dengar::cImage& oSrcImage,
625  const disptb::graphicslib::dengar::cImage& oDestImage,
626  tInt nFlags = 0);
627 
645  static tResult StretchBlit(const tUInt8* pSrcBitmapData,
646  const tBitmapFormat* psSrcBitmapFormat,
647  tUInt8* pDestBitmapData,
648  const tBitmapFormat* psDestBitmapFormat,
649  tInt nFlags = 0);
650 
684  static tResult Convert(const tUInt8* pSrcBitmapData,
685  const tBitmapFormat* psSrcBitmapFormat,
686  tUInt8* pDestBitmapData,
687  const tBitmapFormat* psDestBitmapFormat,
688  tInt nFlags,
689  tUInt32 ui32Mask);
690 
702  static tResult AlphaBlend(disptb::graphicslib::dengar::cImage* pSourceImage,
705 
718 
730 
731 public: // color functions
739  static inline tUInt8 RedValue(tUInt32 nColor)
740  {
741  return ((tUInt8) (nColor));
742  };
743 
751  static inline tUInt8 GreenValue(tUInt32 nColor)
752  {
753  return ((tUInt8) (((tUInt16) (nColor)) >> 8));
754  };
755 
763  static inline tUInt8 BlueValue(tUInt32 nColor)
764  {
765  return ((tUInt8) ((nColor) >> 16));
766  };
767 
777  static inline tFloat64 Brightness(tFloat64 fRed, tFloat64 fGreen, tFloat64 fBlue)
778  {
779  return (0.114 * fRed + 0.587 * fGreen + 0.299 * fBlue);
780  }
781 
791  static inline tInt BrightnessValue(tInt nRed, tInt nGreen, tInt nBlue)
792  {
793  return 116 * nRed + 602 * nGreen + 306 * nBlue;
794  }
795 
805  static inline tUInt8 Brightness(tInt nRed, tInt nGreen, tInt nBlue)
806  {
807  return (tUInt8) (disptb::graphicslib::dengar::cImage::BrightnessValue(nRed, nGreen, nBlue) >> 10);
808  }
809 
817  static inline tUInt8 Brightness(tColor nColor)
818  {
819  return (tUInt8) (disptb::graphicslib::dengar::cImage::BrightnessValue(nColor.nRed, nColor.nGreen, nColor.nBlue) >> 10);
820  }
821 
829  static inline tUInt8 Brightness(tUInt32 nColor)
830  {
831  return (tUInt8) (disptb::graphicslib::dengar::cImage::BrightnessValue(RedValue(nColor), GreenValue(nColor), BlueValue(nColor)) >> 10);
832  }
833 
834 public: // helper functions
835 #ifdef WIN32
848  tResult LoadResource(tInt nResourceId, tHandle hModule=NULL, tUInt32 nFlags=0);
863  tResult CaptureScreen(tInt x, tInt y, tInt nWidth, tInt nHeight);
872  tHandle CreateRegion();
873 #endif // WIN32
874 
884 
893 
903  static tInt CalcAlignedMemSize(tInt nBytes, tInt nAlignment);
904 
911  static tInt GuessPixelFormat(const tBitmapFormat* pFormat);
912 
920  static tInt GetBitsPerPixelFromFormat(tInt nFormat);
921 
929  static tInt GetDefaultFormatFromBpp(tInt nBpp);
930 
938  static tChar const* const GetPixelFormatIdentifier(const tInt nImage);
939 
940 protected: // internal
946  tResult Initialize();
947 
955  tResult Alloc(const tBitmapFormat* psFormat);
956 
962  tResult Free();
963 
973  tResult AllocImpl(tInt nSize, tHandle* hMemory, tVoid** pBuffer);
974 
982  tResult FreeImpl(tHandle hMemory);
983 
991  tResult AllocPalette(tInt nPaletteSize);
992 
998  tResult FreePalette();
999 
1005  tResult AllocBitmapInfo();
1006 
1012  tResult FreeBitmapInfo();
1013 
1014 protected: // internal blitting operations
1026  static tResult Blit_impl(const tUInt8* pSrcBitmapData,
1027  const tBitmapFormat* psSrcBitmapFormat,
1028  tUInt8* pDestBitmapData,
1029  const tBitmapFormat* psDestBitmapFormat,
1030  tInt nFlags);
1031 
1044  static tResult StretchBlit_impl(const tUInt8* pSrcBitmapData,
1045  const tBitmapFormat* psSrcBitmapFormat,
1046  tUInt8* pDestBitmapData,
1047  const tBitmapFormat* psDestBitmapFormat,
1048  tInt nFlags,
1049  tUInt32 ui32Mask = 0x0);
1050 
1064  static tResult Convert_impl(const tUInt8* pSrcBitmapData,
1065  const tBitmapFormat* psSrcBitmapFormat,
1066  tUInt8* pDestBitmapData,
1067  const tBitmapFormat* psDestBitmapFormat,
1068  tInt nFlags,
1069  tUInt32 ui32Mask);
1070 
1071 
1072 protected:
1073  /*static tResult StretchConvert_impl(const tUInt8* pSrcBitmapData,
1074  const tBitmapFormat* psSrcBitmapFormat,
1075  tUInt8* pDestBitmapData,
1076  const tBitmapFormat* psDestBitmapFormat,
1077  tInt nFlags,
1078  tUInt32 ui32Mask);*/
1079 public:
1088 };
1089 
1090 #pragma pack(push)
1091 #pragma pack(1)
1095 typedef struct
1096 {
1097  tUInt16 ui16Type;
1098  tUInt32 ui32Size;
1099  tUInt16 ui16Reserved1;
1100  tUInt16 ui16Reserved2;
1101  tUInt32 ui32DataOffset;
1103 
1104 #pragma pack(pop)
1105 }
1106 
1107 using dengar::cImage;
1108 }
1109 
1110 }
1111 
1112 }
Image and bitmap handling.
Definition: image_intf.h:29
Image and bitmap handling.
Definition: image.h:39
static tInt m_nDefaultLineAlignment
the default line alignment, currently power of 2
Definition: image.h:47
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.
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:57
tInt m_nBitmapInfoSize
size of windows bitmap info
Definition: image.h:54
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:53
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:777
tInt m_nGreyPaletteSize
size of palette
Definition: image.h:60
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:739
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.
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:829
static tInt BrightnessValue(tInt nRed, tInt nGreen, tInt nBlue)
Calculates the bringhtness value of a color without scaling it down.
Definition: image.h:791
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:751
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.
tBool m_bReference
flag indicating the m_pBitmap pointer is used as a reference
Definition: image.h:50
static tInt m_nDefaultMemoryAlignment
the default memory alignment used, currently 16
Definition: image.h:46
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 tUInt8 Brightness(tColor nColor)
Calculates the bringhtness value of a color.
Definition: image.h:817
tColor * m_pPalette
array of colors making up the palette
Definition: image.h:56
const tBitmapFormat * GetFormat() const override
Returns the current bitmap format of the image.
tHandle m_hBitmapMemory
Handle for bitmap memory.
Definition: image.h:58
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:763
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:805
tResult SetPaletteEntry(tInt nIdx, const tColor &sColor)
Sets an entry of the color palette.
A_UTILS_D(cImage)
D-Pointer implementation.
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:52
static tChar const *const GetPixelFormatIdentifier(const tInt nImage)
Returns the image format as string (enum to string)
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:1096
tUInt16 ui16Type
always 0x4D42, for more information have a look at http://msdn.microsoft.com/en-us/library/AA930979....
Definition: image.h:1097
tUInt32 ui32Size
actual size of data + this header + windows bitmap header + palette
Definition: image.h:1098
Struct to specifie a bitmap.
Struct to get the informations and the color about a bitmap.