ADTF_DISPLAY_TOOLBOX  3.8.0 (ADTF 3.14.3)
cImage

Image and bitmap handling. More...

Inheritance diagram for cImage:
[legend]

Public Member Functions

 cImage ()
 Default constructor.
 
 cImage (const cImage &oImage)
 Copy constructor. More...
 
virtual ~cImage ()
 Destructor.
 
tVoid Destroy ()
 Destroy the instance.
 
tResult Create (tInt nWidth, tInt nHeight, tInt nBitsPerPixel, tInt nBytesPerLine=0, const tUInt8 *pBitmap=nullptr, tInt nPixelFormat=0)
 Creates a new image. More...
 
tResult Create (const tBitmapFormat *psFormat, const tColor *pPalette=nullptr, const tUInt8 *pBitmap=nullptr)
 Creates a new image from a bitmap format description. More...
 
tResult Attach (tUInt8 *pBitmap, tInt nWidth, tInt nHeight, tInt nBitsPerPixel, tInt nBytesPerLine=0)
 Attaches an image reference. More...
 
tResult Attach (tUInt8 *pBitmap, const tBitmapFormat *psFormat, const tColor *pPalette=nullptr)
 Attaches an image reference. More...
 
tResult Load (const tChar *strFile, tUInt32 nFlags=0)
 Loads an image from a file. More...
 
tResult Save (const tChar *strFile)
 Saves the image to a file. More...
 
tResult Release ()
 Frees all allocated resources. More...
 
tResult SetPixelFormat (tInt nPixelFormat)
 Sets the pixel format used. More...
 
tInt GetPixelFormat () const
 Returns the pixel format. More...
 
tInt GetWidth () const
 Returns the width of the image. More...
 
tInt GetHeight () const
 Returns the height of the image. More...
 
tInt GetBitsPerPixel () const
 Returns the bits per pixel of the image. More...
 
tInt GetBytesPerLine () const
 Returns the bytes per line of the image. More...
 
tInt GetSize () const
 Returns the size of the image in bytes. More...
 
tFloat64 GetRatio () const
 Returns the aspect ratio of the image. More...
 
const tBitmapFormatGetFormat () const override
 Returns the current bitmap format of the image. More...
 
tResult SetPalette (tInt nPaletteSize, const tColor *pPalette)
 Sets a color palette. More...
 
tColor * GetPalette () const
 Returns the color palette. More...
 
tInt GetPaletteSize () const
 Returns the color palette size. More...
 
tColor GetPaletteEntry (tInt nIdx) const
 Returns a color palette entry. More...
 
tResult SetPaletteEntry (tInt nIdx, const tColor &sColor)
 Sets an entry of the color palette. More...
 
tUInt8 * GetBitmap () const
 Returns a pointer to the raw data. More...
 
tUInt8 * GetBitmapLine (tInt y) const
 Returns a pointer to raw data of a line. More...
 
tWin32BitmapInfoGetBitmapInfo () override
 Generates a Win32 image descriptor. More...
 
tInt GetBitmapInfoSize ()
 Returns the size of the Win32 image descriptor. More...
 
 operator IImage * ()
 instance of IImage More...
 
tResult Flip ()
 Flips the image upside down. More...
 
tResult Mirror ()
 Mirrors the image. More...
 
tResult Resize (tInt nWidth, tInt nHeight)
 Resizes the image to the new height nHeight and width nWidth. More...
 
tResult ChangeDepth (tInt nBitsPerPixel, tInt nBytesPerLine=0, tUInt32 ui32Mask=0x0)
 Changes the color depth. More...
 
tResult Convert (tInt nWidth, tInt nHeight, tInt nBitsPerPixel, tInt nBytesPerLine=0, tUInt32 ui32Mask=0x0)
 Converts the image to new dimensions and color depth. More...
 
tResult Convert (const tBitmapFormat *psFormat, tUInt32 ui32Mask=0x0)
 Converts the image to a new image format. More...
 
tResult ChangePixelFormat (tInt nFormat, tUInt32 ui32Flags=0)
 Changes the pixel format used. More...
 
tResult FlipRGB ()
 Flips RGB to BGR and the other way around. More...
 
tResult FlipAlpha ()
 Flips the alpha part from left to right and back:ARGB <-> RGBA and ABGR <-> BGRA. More...
 
tResult MakeAlphaChannel (const tColor &sColorKey, tBool bClearTransparent=tFalse)
 Creates an alpha channel. More...
 
tResult Blit (const cImage &oDestImage, tInt nFlags=0)
 Copies bitmap data from one image to another. More...
 
tResult SetBits (const tUInt8 *pSrcBitmapData, const tBitmapFormat *psSrcBitmapFormat)
 Sets the image's bitmap data. More...
 
tResult GetBits (tUInt8 *pDestBitmapData, const tBitmapFormat *psDestBitmapFormat, tInt nFlags=0)
 Retrieves the image's bitmap data. More...
 
tBool Compare (const disptb::graphicslib::dengar::cImage &oImage)
 Compares the bitmaps of two images. More...
 
tInt CountDifferences (const disptb::graphicslib::dengar::cImage &oImage)
 Compares the bitmaps of two images and counts the amount of different pixels. More...
 
disptb::graphicslib::dengar::cImageoperator= (const disptb::graphicslib::dengar::cImage &oImage)
 Set the current image to the image oImage. More...
 

Static Public Member Functions

static tInt FlipRGBFormat (tInt nPixelFormat)
 Returns the format with flipped RGB. More...
 
static tInt FlipToBGRFormat (tInt nPixelFormat)
 Returns the pixel format flipped to BGR. More...
 
static tInt FlipToRGBFormat (tInt nPixelFormat)
 Returns the pixel format flipped to RGB. More...
 
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. More...
 
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. More...
 
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 image to the width and height of the dest image (with height H2 and width W2). More...
 
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 image to the width and height of the dest image (with height H2 and width W2). More...
 
static tResult Convert (const tUInt8 *pSrcBitmapData, const tBitmapFormat *psSrcBitmapFormat, tUInt8 *pDestBitmapData, const tBitmapFormat *psDestBitmapFormat, tInt nFlags, tUInt32 ui32Mask)
 Converts an image to another format. More...
 
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. More...
 
static tResult BilinearStretchBlit (disptb::graphicslib::dengar::cImage &oSrc, disptb::graphicslib::dengar::cImage &oDest)
 Copies an image to another using the bilinear algorithm. More...
 
static tResult SetTransparency (disptb::graphicslib::dengar::cImage *pImage, disptb::graphicslib::dengar::cColor oColor)
 Helper method for setting transparency in bitmaps. More...
 
static tUInt8 RedValue (tUInt32 nColor)
 Returns the red component of a color. More...
 
static tUInt8 GreenValue (tUInt32 nColor)
 Returns the green component of a color. More...
 
static tUInt8 BlueValue (tUInt32 nColor)
 Returns the blue component of a color. More...
 
static tFloat64 Brightness (tFloat64 fRed, tFloat64 fGreen, tFloat64 fBlue)
 Calculates the bringhtness value of a color. More...
 
static tInt BrightnessValue (tInt nRed, tInt nGreen, tInt nBlue)
 Calculates the bringhtness value of a color without scaling it down. More...
 
static tUInt8 Brightness (tInt nRed, tInt nGreen, tInt nBlue)
 Calculates the bringhtness value of a color. More...
 
static tUInt8 Brightness (tColor nColor)
 Calculates the bringhtness value of a color. More...
 
static tUInt8 Brightness (tUInt32 nColor)
 Calculates the bringhtness value of a color. More...
 
static tInt CalcAlignedMemSize (tInt nBytes, tInt nAlignment)
 Calculate the size of a given number of bytes to match a given alignment. More...
 
static tInt GuessPixelFormat (const tBitmapFormat *pFormat)
 Tries to guess the PixelFormat based on the other parameters of a bitmap format. More...
 
static tInt GetBitsPerPixelFromFormat (tInt nFormat)
 Retrieve image resolution from image format. More...
 
static tInt GetDefaultFormatFromBpp (tInt nBpp)
 Retrieve image format based on image resolution. More...
 
static tChar const *const GetPixelFormatIdentifier (const tInt nImage)
 Returns the image format as string (enum to string) More...
 

Static Public Attributes

static tInt m_nDefaultMemoryAlignment
 the default memory alignment used, currently 16
 
static tInt m_nDefaultLineAlignment
 the default line alignment, currently power of 2
 

Protected Member Functions

tResult Initialize ()
 Initialize the image. More...
 
tResult Alloc (const tBitmapFormat *psFormat)
 Allocates the image's bitmap buffer. More...
 
tResult Free ()
 Frees the image's bitmap buffer. More...
 
tResult AllocImpl (tInt nSize, tHandle *hMemory, tVoid **pBuffer)
 Internal implementation of the allocation function. More...
 
tResult FreeImpl (tHandle hMemory)
 Internal implementation of the free function. More...
 
tResult AllocPalette (tInt nPaletteSize)
 Allocate space for a palette. More...
 
tResult FreePalette ()
 Frees space from palette. More...
 
tResult AllocBitmapInfo ()
 Allocate space for bitmap info. More...
 
tResult FreeBitmapInfo ()
 Free space from bitmap info. More...
 

Static Protected Member Functions

static tResult Blit_impl (const tUInt8 *pSrcBitmapData, const tBitmapFormat *psSrcBitmapFormat, tUInt8 *pDestBitmapData, const tBitmapFormat *psDestBitmapFormat, tInt nFlags)
 Internal blitting operation. More...
 
static tResult StretchBlit_impl (const tUInt8 *pSrcBitmapData, const tBitmapFormat *psSrcBitmapFormat, tUInt8 *pDestBitmapData, const tBitmapFormat *psDestBitmapFormat, tInt nFlags, tUInt32 ui32Mask=0x0)
 Internal blitting operation. More...
 
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. More...
 

Protected Attributes

tBool m_bReference
 flag indicating the m_pBitmap pointer is used as a reference
 
tBitmapFormat m_sFormat
 current format of bitmap
 
tWin32BitmapInfom_psBitmapInfo
 current bitmap info, windows style
 
tInt m_nBitmapInfoSize
 size of windows bitmap info
 
tColor * m_pPalette
 array of colors making up the palette
 
tUInt8 * m_pBitmap
 actual pixel data, may be reference to data of other pic
 
tHandle m_hBitmapMemory
 Handle for bitmap memory.
 
tInt m_nGreyPaletteSize
 size of palette
 

Private Member Functions

 A_UTILS_D (cImage)
 D-Pointer implementation.
 

Additional Inherited Members

- Public Types inherited from IImage
enum  tPixelFormat {
  PF_UNKNOWN = 0 , PF_8BIT = 10 , PF_GREYSCALE_8 = 11 , PF_RGB_8 = 12 ,
  PF_16BIT = 20 , PF_GREYSCALE_10 = 21 , PF_GREYSCALE_12 = 22 , PF_GREYSCALE_14 = 23 ,
  PF_GREYSCALE_16 = 24 , PF_RGB_444 = 25 , PF_RGB_555 = 26 , PF_RGB_565 = 27 ,
  PF_RGBA_4444 = 28 , PF_ABGR_4444 = 29 , PF_RIII_10 = 30 , PF_RIII_12 = 31 ,
  PF_RIII_14 = 32 , PF_RIII_16 = 33 , PF_BGR_555 = 34 , PF_BGR_565 = 35 ,
  PF_24BIT = 40 , PF_GREYSCALE_18 = 41 , PF_GREYSCALE_20 = 42 , PF_GREYSCALE_22 = 43 ,
  PF_GREYSCALE_24 = 44 , PF_RGB_888 = 45 , PF_BGR_888 = 46 , PF_32BIT = 50 ,
  PF_ARGB_8888 = 51 , PF_ABGR_8888 = 52 , PF_RGBA_8888 = 53 , PF_BGRA_8888 = 54 ,
  PF_GREYSCALE_32 = 55 , PF_GREYSCALE_FLOAT32 = 56 , PF_YUV420P_888 = 60 , PF_CUSTOM = 1000
}
 The enum ePixelFormat specifies some common pixel formats, that is, descriptions of a byte to color mapping. More...
 
enum  tLoadFlags { LF_SWAP_RGB = 0x0001 , LF_FLIP_VERTICAL = 0x0002 }
 The enum tLoadFlags specifies options available for image transformation. More...
 
enum  tBlitFlags { BLIT_VerticalFlip = 0x01 , BLIT_DontStretch = 0x02 }
 This enumeration is used for the Blit function. More...
 

Detailed Description

Image and bitmap handling.

The cImage class encapsulates basic image handling methods.

Definition at line 38 of file image.h.

Constructor & Destructor Documentation

◆ cImage()

cImage ( const cImage oImage)

Copy constructor.

Parameters
oImage[in] the other instance of cImage.

Member Function Documentation

◆ Alloc()

tResult Alloc ( const tBitmapFormat psFormat)
protected

Allocates the image's bitmap buffer.

Parameters
psFormat[in] Specifies the image format.
Returns
Standard result code.

◆ AllocBitmapInfo()

tResult AllocBitmapInfo ( )
protected

Allocate space for bitmap info.

Returns
Standard result code.

◆ AllocImpl()

tResult AllocImpl ( tInt  nSize,
tHandle *  hMemory,
tVoid **  pBuffer 
)
protected

Internal implementation of the allocation function.

Parameters
nSize[in] Size of allocation.
hMemory[in] Memory handle.
pBuffer[in] Destination buffer.
Returns
Standard result code.

◆ AllocPalette()

tResult AllocPalette ( tInt  nPaletteSize)
protected

Allocate space for a palette.

Parameters
nPaletteSize[in] Size of palette.
Returns
Standard result code.

◆ AlphaBlend()

static tResult AlphaBlend ( disptb::graphicslib::dengar::cImage pSourceImage,
disptb::graphicslib::dengar::cImage pDestImage,
disptb::graphicslib::dengar::cImage pMaskImage 
)
static

Alpha blends an image to a destination image.

Parameters
pSourceImage[in] The source image.
pDestImage[in] The destination image.
pMaskImage[in] The image that contains the alpha mask to use.
Return values
ERR_NOT_SUPPORTEDif pSourceImage or pDestImage are not PF_RGB_888, PF_BGR_888, PF_RGBA or PF_BGRA
ERR_NOERRORif all went well

◆ Attach() [1/2]

tResult Attach ( tUInt8 *  pBitmap,
const tBitmapFormat psFormat,
const tColor *  pPalette = nullptr 
)

Attaches an image reference.

The Attach method initializes the image format block, but doesn't allocate actual bitmap data. Instead, it references the bitmap data it was passed. It does, However, copy the bitmap format.

Parameters
pBitmap[in] The external bitmap.
psFormat[in] The format description of the bitmap.
pPalette[in] An optional color palette array.
Return values
ERR_NOERROif all went well
ERR_FAILEDif a palette is provided, but bits per pixel is not 8
ERR_MEMORYif memory allocation for the palette failed
ERR_NOERRORif all went well

◆ Attach() [2/2]

tResult Attach ( tUInt8 *  pBitmap,
tInt  nWidth,
tInt  nHeight,
tInt  nBitsPerPixel,
tInt  nBytesPerLine = 0 
)

Attaches an image reference.

The Attach method initializes the image format block, but doesn't allocate actual bitmap data.

Parameters
pBitmap[in] The external bitmap.
nWidth[in] The width of the bitmap.
nHeight[in] The height of the bitmap.
nBitsPerPixel[in] The pits per pixel of the bitmap.
nBytesPerLine[in] The bytes per line (to account for padding bytes). Calculated for aligned memory if 0.
Return values
ERR_POINTERif pBitmap is NULL.
ERR_NOERRORif all went well

◆ BilinearStretchBlit()

static tResult BilinearStretchBlit ( disptb::graphicslib::dengar::cImage oSrc,
disptb::graphicslib::dengar::cImage oDest 
)
static

Copies an image to another using the bilinear algorithm.

Parameters
oSrc[in] The source image.
oDest[in] The destination image.
Return values
ERR_POINTERif either source or destination have no bitmap data or format data
ERR_NOERRORif all went well
ERR_ERR_NOT_SUPPORTEDif the pixelformat is not either PF_RGB_888 or PF_RGBA_8888
ERR_NOT_IMPLif source and destination have a different format

◆ Blit() [1/3]

tResult Blit ( const cImage oDestImage,
tInt  nFlags = 0 
)

Copies bitmap data from one image to another.

The Blit method copies bitmap data from one image to another.

Parameters
oDestImage[in] Specifies the destination image.
nFlags[in] Flags, see tBlitFlags
Return values
ERR_NOERRORif all went well.
ERR_NOT_SUPPORTEDif the blit needed a nont supported conversion
ERR_POINTERif any of the input pointer was NULL

◆ Blit() [2/3]

static tResult Blit ( const disptb::graphicslib::dengar::cImage oSrcImage,
const disptb::graphicslib::dengar::cImage oDestImage,
tInt  nFlags = 0 
)
static

Copies bitmap data from one image to another.

The Blit method copies bitmap data from one image to another.

Parameters
oSrcImage[in] Specifies the source image.
oDestImage[in] Specifies the destination image.
nFlags[in] Flags, see tBlitFlags
Return values
ERR_NOERRORif all went well.
ERR_NOT_SUPPORTEDif the blit needed a nont supported conversion
ERR_POINTERif any of the input pointer was NULL

◆ Blit() [3/3]

static tResult Blit ( const tUInt8 *  pSrcBitmapData,
const tBitmapFormat psSrcBitmapFormat,
tUInt8 *  pDestBitmapData,
const tBitmapFormat psDestBitmapFormat,
tInt  nFlags = 0 
)
static

Copies bitmap data from one image to another.

The Blit method copies bitmap data from one image to another.

Parameters
pSrcBitmapData[in] Specifies the source bitmap data.
psSrcBitmapFormat[in] Specifies the source bitmap format.
pDestBitmapData[in] Specifies the destination bitmap buffer.
psDestBitmapFormat[in] Specifies the destination bitmap format.
nFlags[in] Flags, see tBlitFlags
Return values
ERR_NOERRORif all went well.
ERR_NOT_SUPPORTEDif the blit needed a nont supported conversion
ERR_POINTERif any of the input pointer was NULL

◆ Blit_impl()

static tResult Blit_impl ( const tUInt8 *  pSrcBitmapData,
const tBitmapFormat psSrcBitmapFormat,
tUInt8 *  pDestBitmapData,
const tBitmapFormat psDestBitmapFormat,
tInt  nFlags 
)
staticprotected

Internal blitting operation.

Parameters
pSrcBitmapData[in] Source bitmap data.
psSrcBitmapFormat[in] Source bitmap format.
pDestBitmapData[in] Destination bitmap data.
psDestBitmapFormat[in] Destination bitmap format.
nFlags[in] Blitting flags.
Returns
Standard result code.

◆ BlueValue()

static tUInt8 BlueValue ( tUInt32  nColor)
inlinestatic

Returns the blue component of a color.

Parameters
nColor[in] The color.
Returns
The blue component of a color.

Definition at line 763 of file image.h.

Referenced by cImage::Brightness().

◆ Brightness() [1/4]

static tUInt8 Brightness ( tColor  nColor)
inlinestatic

Calculates the bringhtness value of a color.

Parameters
nColor[in] The color.
Returns
The brightness.

Definition at line 817 of file image.h.

References cImage::BrightnessValue().

◆ Brightness() [2/4]

static tFloat64 Brightness ( tFloat64  fRed,
tFloat64  fGreen,
tFloat64  fBlue 
)
inlinestatic

Calculates the bringhtness value of a color.

Parameters
fRed[in] The red component (0.0-1.0).
fGreen[in] The green component (0.0-1.0).
fBlue[in] The blue component (0.0-1.0).
Returns
The brightness.

Definition at line 777 of file image.h.

◆ Brightness() [3/4]

static tUInt8 Brightness ( tInt  nRed,
tInt  nGreen,
tInt  nBlue 
)
inlinestatic

Calculates the bringhtness value of a color.

Parameters
nRed[in] The red component.
nGreen[in] The green component.
nBlue[in] The blue component.
Returns
The brightness.

Definition at line 805 of file image.h.

References cImage::BrightnessValue().

◆ Brightness() [4/4]

static tUInt8 Brightness ( tUInt32  nColor)
inlinestatic

Calculates the bringhtness value of a color.

Parameters
nColor[in] The color as RGBA.
Returns
The brightness.

Definition at line 829 of file image.h.

References cImage::BlueValue(), cImage::BrightnessValue(), cImage::GreenValue(), and cImage::RedValue().

◆ BrightnessValue()

static tInt BrightnessValue ( tInt  nRed,
tInt  nGreen,
tInt  nBlue 
)
inlinestatic

Calculates the bringhtness value of a color without scaling it down.

Parameters
nRed[in] The red component.
nGreen[in] The green component.
nBlue[in] The blue component.
Returns
The brightness.

Definition at line 791 of file image.h.

Referenced by cImage::Brightness().

◆ CalcAlignedMemSize()

static tInt CalcAlignedMemSize ( tInt  nBytes,
tInt  nAlignment 
)
static

Calculate the size of a given number of bytes to match a given alignment.

Parameters
nBytesnumber of bytes to align
nAlignmentbytes to align with.
Returns
size of required buffer with stuffing bytes or nBytes if nBytes was less than 1 or 0 if nBytes was less than 1; nBytes take precedence to nAlignment

◆ ChangeDepth()

tResult ChangeDepth ( tInt  nBitsPerPixel,
tInt  nBytesPerLine = 0,
tUInt32  ui32Mask = 0x0 
)

Changes the color depth.

Note
the pixelformat of the result is the default one for the selected bitdepth. 8 bit : PF_GREYSCALE_8 16 bit : PF_RGB_555 24 bit : PF_RGB_888 32 bit : PF_RGBA_8888
Parameters
nBitsPerPixel[in] The bits per pixel.
nBytesPerLine[in] The bytes per line.
ui32Mask[in] Only bits of color values in this bitmask will be considered.
Return values
ERR_NOERRORif all went well
ERR_MEMORYif memory reallocation failed
ERR_POINTERif no image has been created, attached or loaded yet

◆ ChangePixelFormat()

tResult ChangePixelFormat ( tInt  nFormat,
tUInt32  ui32Flags = 0 
)

Changes the pixel format used.

This is a shortcut for convert, changing only the pixel format Can also convert between PF_RGB_888 <-> PF_YUV420P_888 PF_RGBA_8888 <-> PF_ARGB_8888 and PF_BGRA_8888 <-> PF_ABGR_8888. Supports also all conversions of the staic cImage::convert method

Parameters
nFormat[in] The new pixel format tPixelFormat.
ui32Flagsunused
Return values
ERR_NOT_SUPPORTEDif conversion is not supported.
ERR_NOERRORif all went well

◆ Compare()

tBool Compare ( const disptb::graphicslib::dengar::cImage oImage)

Compares the bitmaps of two images.

The format of both images must be the same.

Parameters
oImageThe image for comparison
Returns
tTrue if both images are equal tFalse if images are different

◆ Convert() [1/3]

tResult Convert ( const tBitmapFormat psFormat,
tUInt32  ui32Mask = 0x0 
)

Converts the image to a new image format.

Parameters
psFormat[in] The new format.
See also
cImage::convert_impl
Parameters
ui32Mask[in] Only bits of color values in this bitmask will be considered. This is used for 8bpp<->16bpp conversion of not listed pixel formats ONLY
Return values
ERR_POINTERif psFormat is NULL
ERR_INVAILD_ARGUMENTif nWidth or nHeight <= 0
ERR_MEMORYif memory reallocation failed
ERR_POINTERif no image has been created, attached or loaded yet
ERR_NOERRORif all went well

◆ Convert() [2/3]

static tResult Convert ( const tUInt8 *  pSrcBitmapData,
const tBitmapFormat psSrcBitmapFormat,
tUInt8 *  pDestBitmapData,
const tBitmapFormat psDestBitmapFormat,
tInt  nFlags,
tUInt32  ui32Mask 
)
static

Converts an image to another format.

List of possible conversions: PF_GREYSCALE_8 -> PF_RGB_888, PF_BGR_888 PF_RGBA_8888, PF_BGRA_8888 PF_RGB_555, PF_RGB_565

PF_RGB_555/PF_RGB_565 -> PF_GREYSCALE_8 PF_BGR_888, PF_RGB_888 PF_RGBA_8888, PF_BGRA_888 PF_ARGB_8888, PF_ABGR_888

PF_RGB_888/PF_BGR -> PF_GREYSCALE_8 PF_RGB_555, PF_RGB_565 PF_BGR_888/PF_RGB_888 PF_ARGB_8888,PF_RGBA_8888,PF_BGRA_8888,PF_ABGR_8888

PF_RGBA_8888,PF_BGRA_8888 -> GREYSCALE_8

PF_ARGB_8888,PF_RGBA_8888,PF_BGRA_8888,PF_ABGR_8888 -> PF_RGB_555, PF_RGB_565 PF_ARGB_8888 / PF_ABGR_888 -> PF_RGB_888 / PF_BGR_888

Parameters
pSrcBitmapData[in] Specifies the source bitmap data.
psSrcBitmapFormat[in] Specifies the source bitmap format.
pDestBitmapData[in] Specifies the destination bitmap buffer.
psDestBitmapFormat[in] Specifies the destination bitmap format.
ui32Mask[in] Only bits of color values in this bitmask will be considered.
nFlags[in] Flags, see tBlitFlags
Return values
ERR_NOERRORif all went well.
ERR_NOT_SUPPORTEDif conversio is not supported.

◆ Convert() [3/3]

tResult Convert ( tInt  nWidth,
tInt  nHeight,
tInt  nBitsPerPixel,
tInt  nBytesPerLine = 0,
tUInt32  ui32Mask = 0x0 
)

Converts the image to new dimensions and color depth.

Parameters
nWidth[in] The new width.
nHeight[in] The new height.
nBitsPerPixel[in] The new color depth.
nBytesPerLine[in] The new bytes per line value.
ui32Mask[in] Only bits of color values in this bitmask will be considered.
Return values
ERR_INVAILD_ARGUMENTif nWidth or nHeight <= 0
ERR_MEMORYif memory reallocation failed
ERR_POINTERif no image has been created, attached or loaded yet
ERR_NOERRORif all went well

◆ Convert_impl()

static tResult Convert_impl ( const tUInt8 *  pSrcBitmapData,
const tBitmapFormat psSrcBitmapFormat,
tUInt8 *  pDestBitmapData,
const tBitmapFormat psDestBitmapFormat,
tInt  nFlags,
tUInt32  ui32Mask 
)
staticprotected

will convert the bitmap from one format to another one.

Parameters
[in]nFlagsadditional flags, allowed values
  • BLIT_VerticalFlip
  • 0
[in]pSrcBitmapDatapointer to the source bitmap Data
[in]psSrcBitmapFormatpointer to the bitmap format description
[in]pDestBitmapDatapointer to the destination bitmap
[in]psDestBitmapFormatpointer to the destination bitmap format description
[in]ui32Maskmask for bit conversions
See also
cImage::Convert()
Returns
Standard result code.

◆ CountDifferences()

tInt CountDifferences ( const disptb::graphicslib::dengar::cImage oImage)

Compares the bitmaps of two images and counts the amount of different pixels.

The format of both images must be the same.

Parameters
oImageThe image for comparison
Returns
The number of different pixels

◆ Create() [1/2]

tResult Create ( const tBitmapFormat psFormat,
const tColor *  pPalette = nullptr,
const tUInt8 *  pBitmap = nullptr 
)

Creates a new image from a bitmap format description.

Please note that ALL fields of the format Description have to be correctly filled since none but the pixel format will be automatically calculated for you. This is especially important for the size of the bitmap. Even if width, height and bytes per line have been filled in, you still need to fill in the size or no buffer will be allocated.

Parameters
psFormat[in] The format description.
pPalette[in] An optional color palette array.
pBitmap[in] A bitmap that the image data should be initialized with.
Return values
ERR_POINTERif psFormat is NULL
ERR_MEMORYif memory allocation for the data buffer failed
ERR_NOERRORif all went well

◆ Create() [2/2]

tResult Create ( tInt  nWidth,
tInt  nHeight,
tInt  nBitsPerPixel,
tInt  nBytesPerLine = 0,
const tUInt8 *  pBitmap = nullptr,
tInt  nPixelFormat = 0 
)

Creates a new image.

Parameters
nWidth[in] The width of the image in pixels.
nHeight[in] The height of the image in pixels.
nBitsPerPixel[in] The bits per pixel
nBytesPerLine[in] The bytes per line (optional). leave this to zero for automatic calculation[recommended!] If a value is passed for this parameter it will be used as is, no padding bytes will be added.
pBitmap[in] A bitmap that the image data should be initialized with.
nPixelFormat[in] The pixelformat to use, see tPixelFormat
Return values
ERR_MEMORYif memory allocation for the data buffer failed, else ERR_NOERROR
ERR_NOERRORif all went well

◆ Flip()

tResult Flip ( )

Flips the image upside down.

Return values
ERR_NOERRORif all went well
ERR_UNEXPECTEDif the image formats height is zero
ERR_MEMORYif internal memory allocation failed
ERR_POINTERif internal bitmap pointer is null

◆ FlipAlpha()

tResult FlipAlpha ( )

Flips the alpha part from left to right and back:ARGB <-> RGBA and ABGR <-> BGRA.

Return values
ERR_UNEXPECTEDif the BitsPerLine are zero
ERR_NOT_SUPPORTEDif Format is not PF_ABGR_8888, PF_BGRA_8888, PF_ARGB_8888 or PF_ARGB_8888

◆ FlipRGB()

tResult FlipRGB ( )

Flips RGB to BGR and the other way around.

Return values
ERR_NOT_SUPPORTEDif the format is not one of the following PF_RGB_444 <-> PF_BGR_444 PF_RGB_555 <-> PF_BGR_555 PF_RGB_565 <-> PF_BGR_565 PF_RGB_888 <-> PF_BGR_888 PF_RGBA_8888 <-> PF_BGRA_8888 PF_ARGB_8888 <-> PF_ABGR_8888
ERR_NOERRORif all went well

◆ FlipRGBFormat()

static tInt FlipRGBFormat ( tInt  nPixelFormat)
static

Returns the format with flipped RGB.

Example: PF_RGB_888 gets flipped to PF_BGR_888

Parameters
nPixelFormat[in] The new pixel format, see cImage::tPixelFormat.
Returns
the opposite RGB format, see tPixelFormat.

◆ FlipToBGRFormat()

static tInt FlipToBGRFormat ( tInt  nPixelFormat)
static

Returns the pixel format flipped to BGR.

Example 1: PF_RGB_555 gets flipped to PF_BGR_888 Example 2: PF_RGBA_8888 gets flipped to PF_BGRA_8888

Parameters
nPixelFormat[in] The new pixel format, see cImage::tPixelFormat.
Returns
the associated BGR format, see tPixelFormat.

◆ FlipToRGBFormat()

static tInt FlipToRGBFormat ( tInt  nPixelFormat)
static

Returns the pixel format flipped to RGB.

Example 1: PF_BGR_555 gets flipped to PF_RGB_555 Example 2: PF_BGRA_8888 gets flipped to PF_RGBA_8888

Parameters
nPixelFormat[in] The new pixel format, see cImage::tPixelFormat.
Returns
the associated RGB format, see tPixelFormat.

◆ Free()

tResult Free ( )
protected

Frees the image's bitmap buffer.

Returns
Standard result code.

◆ FreeBitmapInfo()

tResult FreeBitmapInfo ( )
protected

Free space from bitmap info.

Returns
Standard result code.

◆ FreeImpl()

tResult FreeImpl ( tHandle  hMemory)
protected

Internal implementation of the free function.

Parameters
hMemory[in] Memory handle.
Returns
Standard result code.

◆ FreePalette()

tResult FreePalette ( )
protected

Frees space from palette.

Returns
Standard result code.

◆ GetBitmap()

tUInt8* GetBitmap ( ) const
virtual

Returns a pointer to the raw data.

Returns
a pointer to the raw data. NULL if image is not initialised.

Implements IImage.

◆ GetBitmapInfo()

tWin32BitmapInfo* GetBitmapInfo ( )
overridevirtual

Generates a Win32 image descriptor.

The GetBitmapInfo method generates a Win32 image descriptor structure.

Returns
Returns a pointer to the Win32 image descriptor structure.

Implements IImage.

◆ GetBitmapInfoSize()

tInt GetBitmapInfoSize ( )

Returns the size of the Win32 image descriptor.

Returns
The size of the Win32 image descriptor.

◆ GetBitmapLine()

tUInt8* GetBitmapLine ( tInt  y) const
virtual

Returns a pointer to raw data of a line.

Get the specified line of the bitmap. Use this function rather than calculating the line yourself, since the actual linewidth might vary due to stuffing bytes!

Parameters
y[in] The line number, starting at 0.
Returns
A pointer to raw data of a line or NULL if index is out of bounds

Implements IImage.

◆ GetBits()

tResult GetBits ( tUInt8 *  pDestBitmapData,
const tBitmapFormat psDestBitmapFormat,
tInt  nFlags = 0 
)
virtual

Retrieves the image's bitmap data.

The GetBits method retrieves the image's bitmap data.

Parameters
pDestBitmapData[in] Specifies the destination bitmap data.
psDestBitmapFormat[in] Specifies the destination bitmap format.
nFlags[in] Flags, see tBlitFlags
Return values
ERR_NOERRORif all went well.
ERR_POINTERif oSrcBitmapData or pSrcBitmapFormat is NULL

Implements IImage.

◆ GetBitsPerPixel()

tInt GetBitsPerPixel ( ) const
virtual

Returns the bits per pixel of the image.

Returns
The bits per pixel of the image.

Implements IImage.

◆ GetBitsPerPixelFromFormat()

static tInt GetBitsPerPixelFromFormat ( tInt  nFormat)
static

Retrieve image resolution from image format.

Parameters
nFormat[in] Image format.
Returns
Image resolution.

◆ GetBytesPerLine()

tInt GetBytesPerLine ( ) const
virtual

Returns the bytes per line of the image.

Since the actual linewidth may be bigger than the with of the image * bytesperpixel, use this function to retrieve the actual line width including stuffing bytes

Returns
The bytes per line of the image.

Implements IImage.

◆ GetDefaultFormatFromBpp()

static tInt GetDefaultFormatFromBpp ( tInt  nBpp)
static

Retrieve image format based on image resolution.

Parameters
nBpp[in] Image resolution.
Returns
Image format.

◆ GetFormat()

const tBitmapFormat* GetFormat ( ) const
overridevirtual

Returns the current bitmap format of the image.

See also
tBitmapFormat
Returns
Pointer to the current bitmap format of the image.

Implements IImage.

◆ GetHeight()

tInt GetHeight ( ) const
virtual

Returns the height of the image.

Returns
The height of the image.

Implements IImage.

◆ GetPalette()

tColor* GetPalette ( ) const
virtual

Returns the color palette.

Returns
The color palette.

Implements IImage.

◆ GetPaletteEntry()

tColor GetPaletteEntry ( tInt  nIdx) const
virtual

Returns a color palette entry.

  • Parameters
    nIdx[in] The index of the entry, starting at 0.
    Returns
    The color palette entry.

Implements IImage.

◆ GetPaletteSize()

tInt GetPaletteSize ( ) const
virtual

Returns the color palette size.

Returns
The color palette size.

Implements IImage.

◆ GetPixelFormat()

tInt GetPixelFormat ( ) const
virtual

Returns the pixel format.

Returns
The pixel format, see tPixelFormat.

Implements IImage.

◆ GetPixelFormatIdentifier()

static tChar const* const GetPixelFormatIdentifier ( const tInt  nImage)
static

Returns the image format as string (enum to string)

Parameters
nImage[in] Image format.
Returns
pixel identifier as string.

◆ GetRatio()

tFloat64 GetRatio ( ) const
virtual

Returns the aspect ratio of the image.

Returns
The aspect ratio of the image.

Implements IImage.

◆ GetSize()

tInt GetSize ( ) const
virtual

Returns the size of the image in bytes.

Returns
The size of the image in bytes. My be bigger than w*h*(bpp/8) due to stuffing bytes

Implements IImage.

◆ GetWidth()

tInt GetWidth ( ) const
virtual

Returns the width of the image.

Returns
The width of the image.

Implements IImage.

◆ GreenValue()

static tUInt8 GreenValue ( tUInt32  nColor)
inlinestatic

Returns the green component of a color.

Parameters
nColor[in] The color.
Returns
The green component of a color.

Definition at line 751 of file image.h.

Referenced by cImage::Brightness().

◆ GuessPixelFormat()

static tInt GuessPixelFormat ( const tBitmapFormat pFormat)
static

Tries to guess the PixelFormat based on the other parameters of a bitmap format.

Parameters
[in]pFormatThe input format to base the guess on. If the nPixelFormat member is set to something other than PF_UNKNOWN, this value is returned.
Returns
The guessed PixelFormat tPixelFormat.

◆ Initialize()

tResult Initialize ( )
protected

Initialize the image.

Returns
Standard result code.

◆ Load()

tResult Load ( const tChar *  strFile,
tUInt32  nFlags = 0 
)

Loads an image from a file.

This loads an image from a fileassuming the following pixelformats: 24 bit: PF_RGB_888 32 bit: PF_RGBA_8888 You may overwrite the pixelformat with cImage::SetPixelFormat

Currently only the BMP Format is supported.

Parameters
strFile[in] The filename.
nFlags[in] Special Flags, see tLoadFlags.
Return values
ERR_NOERRORif all went well
ERR_POINTERif strFile is NULL
ERR_NOERRORif all went well.
ERR_OPEN_FAILEDif the file could not be opened ( e.g. does not exist )
ERR_INVALID_FILEif file could be opened but is no compatible bitmap
ERR_NOT_SUPPORTEDif the file's bits per pixel is less than 8
ERR_MEMORYif memory allocation for the buffer failed

◆ MakeAlphaChannel()

tResult MakeAlphaChannel ( const tColor &  sColorKey,
tBool  bClearTransparent = tFalse 
)

Creates an alpha channel.

Remarks
if the input is not a bpp of 32, a conversion to 32 bpp is executed!
this function works on RGBA internally. If input is not RGBA , it is converted to RGBA! During conversion the (e.g. from 24Bit values), the alpha values are set to 0x00 per default.
Parameters
sColorKey[in] The alpha value of pixels with this color will be set to 0, all others will get 0xFF. A given alpha channel will be ignored
bClearTransparent[in] If tTrue then pixels matching sColorKey will be set to black.
Return values
ERR_NOERRORif all went well.
ERR_NOT_SUPPORTEDif no conversion could be found to convert to PF_RGBA_888
ERR_POINTERif no image has been loaded, attached or created yet

◆ Mirror()

tResult Mirror ( )

Mirrors the image.

Return values
ERR_NOERRORif all went well
ERR_NOT_SUPPORTEDif executed on unsupported pixel format
ERR_UNEXPECTEDif no bitmap data is associated

◆ operator IImage *()

operator IImage * ( )
inline

instance of IImage

Returns
object

Definition at line 377 of file image.h.

◆ operator=()

Set the current image to the image oImage.

Parameters
oImage[in] Given Image.
Returns
Returns a reference to the given image.

◆ RedValue()

static tUInt8 RedValue ( tUInt32  nColor)
inlinestatic

Returns the red component of a color.

Parameters
nColor[in] The color.
Returns
The red component of a color.

Definition at line 739 of file image.h.

Referenced by cImage::Brightness().

◆ Release()

tResult Release ( )

Frees all allocated resources.

Returns
always returns ERR_NOERROR

◆ Resize()

tResult Resize ( tInt  nWidth,
tInt  nHeight 
)

Resizes the image to the new height nHeight and width nWidth.

This function is calling the Convert() function, in which the parameters nBytesPerLine and ui32Mask are not specified and nBitsPerPixel stays unchanged. In this special case, the Convert() function calls the function StretchBlit(), in which the image is resized by a "Nearest Neighbour" algorithm. For further information about the implemented Nearest Neighbour algorithm, please have a look at StretchBlit().

Parameters
nWidth[in] The new width.
nHeight[in] The new height.
Return values
ERR_NOERRORif all went well.
ERR_INVAILD_ARGUMENTif nWidth or nHeight <= 0
ERR_MEMORYif memory reallocation failed
ERR_POINTERif no image has been created, attached or loaded yet

◆ Save()

tResult Save ( const tChar *  strFile)

Saves the image to a file.

This saves the raw image as is allowing you to save your data in what ever format it currenntly is. Since the format information, except the bpp, is not stored along in the resulting file, you have to use this with care.

Parameters
strFile[in] The filename.
Return values
ERR_NOERRORif all went well
ERR_POINTERif strFile is NULL
ERR_OPEN_FAILEDif the file could not be created
ERR_DEVICE_IOif there was an error while writing
ERR_NOT_IMPLif this function is called in non WIN32 environments.

◆ SetBits()

tResult SetBits ( const tUInt8 *  pSrcBitmapData,
const tBitmapFormat psSrcBitmapFormat 
)

Sets the image's bitmap data.

The SetBits method sets the image's bitmap data, and will release the current buffer if format differs. When format not differs it will only overwrite the current buffer.

Parameters
pSrcBitmapData[in] Specifies the source bitmap data.
psSrcBitmapFormat[in] Specifies the source bitmap format.
Return values
ERR_POINTERif pSrcBitmapData or psSrcBitmapFormat
ERR_MEMORYif a problem occured during creation of new image buffer
ERR_NOERRORif all went well

◆ SetPalette()

tResult SetPalette ( tInt  nPaletteSize,
const tColor *  pPalette 
)

Sets a color palette.

Parameters
nPaletteSize[in] The size of the pPalette array
pPalette[in] The color palette array. If this is NULL, initialises palette as greyscale
Return values
ERR_NOERRORif all went well.
ERR_NOT_SUPPORTEDif bits per pixel are not 8
ERR_MEMORYif memory allocation for the palette failed

◆ SetPaletteEntry()

tResult SetPaletteEntry ( tInt  nIdx,
const tColor &  sColor 
)

Sets an entry of the color palette.

Parameters
nIdx[in] The index of the entry, starting at 0.
sColor[in] The new color value.
Return values
ERR_INVALID_ARGif nIdx is not part of the palette
ERR_NOERRORif all went well

◆ SetPixelFormat()

tResult SetPixelFormat ( tInt  nPixelFormat)

Sets the pixel format used.

Does NOT perform a conversion.

Parameters
nPixelFormat[in] The new pixel format, see cImage::tPixelFormat.
Returns
Always returns ERR_NOERROR.

◆ SetTransparency()

static tResult SetTransparency ( disptb::graphicslib::dengar::cImage pImage,
disptb::graphicslib::dengar::cColor  oColor 
)
static

Helper method for setting transparency in bitmaps.

(BMP doesn't know anything about transparency) The alpha channel for all pixels with the given color will be set to 0. If the images is of format other than PF_RGBA_8888 and PF_BGRA_8888 it will be converted to PF_RGBA_8888.

Parameters
pImage[in/out] Pointer to the image which gets transparent pixels
oColor[in] The color of the pixels which will converted to transparent
Returns
ERR_INVALID_FORMAT if an image with not supported format is passed ERR_POINTER if either pImage, pImage->GetBitmap() or pImage->GetBitmapInfo() is NULL ERR_NOERROR if succeeded

◆ StretchBlit() [1/2]

static tResult StretchBlit ( const disptb::graphicslib::dengar::cImage oSrcImage,
const disptb::graphicslib::dengar::cImage oDestImage,
tInt  nFlags = 0 
)
static

Copies bitmap data from one image (with height H1 and width W1) to another image, stretching the scr image to the width and height of the dest image (with height H2 and width W2).

The stretching is done via a Nearest Neighbour algorithm. The value for the pixel (x_n,y_m) in the dest image is given by the value of the pixel: (x,y)= ( |_ (x_n*W1)/W2 _| , |_ (y_m*H1)/H2 _| ) of the src image. |_x_| stands for the mathematical floor function (e.g. |_1.34_| = 1).

Parameters
oSrcImage[in] Specifies the source image.
oDestImage[in] Specifies the destination image.
nFlags[in] Flags, see tBlitFlags
Return values
ERR_NOERRORif all went well.
ERR_NO_SUPPORTEDif a pixelformat conversion was needed but was not supported

◆ StretchBlit() [2/2]

static tResult StretchBlit ( const tUInt8 *  pSrcBitmapData,
const tBitmapFormat psSrcBitmapFormat,
tUInt8 *  pDestBitmapData,
const tBitmapFormat psDestBitmapFormat,
tInt  nFlags = 0 
)
static

Copies bitmap data from one image (with height H1 and width W1) to another image, stretching the scr image to the width and height of the dest image (with height H2 and width W2).

The stretching is done via a Nearest Neighbour algorithm. The value for the pixel (x_n,y_m) in the dest image is given by the value of the pixel: (x,y)= ( |_ (x_n*W1)/W2 _| , |_ (y_m*H1)/H2 _| ) of the src image. |_x_| stands for the mathematical floor function (e.g. |_1.34_| = 1).

Parameters
pSrcBitmapData[in] Specifies the source bitmap data.
psSrcBitmapFormat[in] Specifies the source bitmap format.
pDestBitmapData[in] Specifies the destination bitmap buffer.
psDestBitmapFormat[in] Specifies the destination bitmap format.
nFlags[in] Flags, see tBlitFlags
Return values
ERR_NOERRORif all went well.
ERR_NO_SUPPORTEDif a pixelformat conversion was needed but was not supported

◆ StretchBlit_impl()

static tResult StretchBlit_impl ( const tUInt8 *  pSrcBitmapData,
const tBitmapFormat psSrcBitmapFormat,
tUInt8 *  pDestBitmapData,
const tBitmapFormat psDestBitmapFormat,
tInt  nFlags,
tUInt32  ui32Mask = 0x0 
)
staticprotected

Internal blitting operation.

Parameters
pSrcBitmapData[in] Source bitmap data.
psSrcBitmapFormat[in] Source bitmap format.
pDestBitmapData[in] Destination bitmap data.
psDestBitmapFormat[in] Destination bitmap format.
nFlags[in] Blitting flags.
ui32Mask[in] Blitting mask.
Returns
Standard result code.