TBitmap


This template class provides implementation of image in system memory. It supports pixels of different data types and number of color channels. It also supports so-called "constant" images which are images located somewhere else in the source code as constant pixel data.

You can find more information in comments below.

template<class TYPE, size_t CHANNELS = 4>
class TBitmap
{
public:
    size_t const &Width{ m_iWidth }; // Width of the bitmap. Read only
    size_t const &Height{ m_iHeight }; // Height of the bitmap. Read only
    const TPixel<TYPE, CHANNELS>* const &Data{ m_pConstData }; // Pointer to pixels array. Read only
    bool const &Destroyable{ m_bDestroyable }; // Whether bitmap is constant one or not(destroyable)

    TBitmap(); // Create empty bitmap
    TBitmap(const size_t w, const size_t h); // Create bitmap of specified size
    TBitmap(const size_t w, const size_t h, const TPixel<TYPE, CHANNELS> *data); // Create constant bitmap of specified size and pixels
    TBitmap(const TBitmap &other); // Copy constructor
    TBitmap(TBitmap &&other); // Move constructor
    ~TBitmap(); // Destructor

    const COLUMN &operator[](const size_t x) const; // Return constant reference to specified column of bitmap
    COLUMN &operator[](const size_t x); // Return reference to specified column of bitmap
    TBitmap &operator=(const TBitmap &other); // Copy assignement
    TBitmap &operator=(TBitmap &&other); // Move assignement

    TPixel<TYPE, CHANNELS> getPixel(const size_t x, const size_t y) const; // Return pixel at specified position
    TPixel<TYPE, CHANNELS> getPixel(const size_t x, const size_t y, const TPixel<TYPE, CHANNELS> &def) const; // Return pixel at specified position or specified one("def" argument) if specified position is out of bitmap dimentions
    bool isEmpty() const; // Return whether bitmap has pixels or it empty

    bool setWidth(const size_t value); // Set new width. Return false and do nothing if bitmap already has specified width
    bool setHeight(const size_t value); // Set new height. Return false and do nothing if bitmap already has specified height
    bool setSize(const size_t w, const size_t h); // Set new size. Return false and do nothing if bitmap already has specified size
    bool setPixel(const size_t x, const size_t y, const TPixel<TYPE, CHANNELS> &value); // Set pixel at specified position. Return false if position is out of bitmap bounds
    bool setData(const size_t w, const size_t h, const TPixel<TYPE, CHANNELS> *data); // Makes constant bitmap
};

Additionally following operators exists and can be used for bitmaps comparison. They are available for non-float data types.

template<class TYPE, size_t CHANNELS = 4>
bool operator==(const TBitmap<TYPE, CHANNELS> &a, const TBitmap<TYPE, CHANNELS> &b); // Compare if bitmaps are equal
template<class TYPE, size_t CHANNELS = 4>
bool operator!=(const TBitmap<TYPE, CHANNELS> &a, const TBitmap<TYPE, CHANNELS> &b); // Compare if bitmaps aren't equal

Also there are some overloaded functions which can be used with TBitmap template. Here they are.

Namespace: ntl
Include: NTL/Core/Bitmap.h