Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
282 andreas 1
/*
289 andreas 2
 * Copyright (C) 2023 by Andreas Theofilu <andreas@theosys.at>
282 andreas 3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
 
19
#ifndef __TBITMAP_H__
20
#define __TBITMAP_H__
21
 
289 andreas 22
#include <cstring>
282 andreas 23
 
24
class TBitmap
25
{
26
    public:
27
        TBitmap();
284 andreas 28
        TBitmap(const TBitmap& bm);
282 andreas 29
        TBitmap(const unsigned char *data, size_t size);
283 andreas 30
        TBitmap(const unsigned char *data, int width, int height, int pixsize=4);
282 andreas 31
        ~TBitmap();
32
 
33
        void setBitmap(const unsigned char *data, size_t size);
283 andreas 34
        void setBitmap(const unsigned char *data, int width, int height, int pixsize=4);
35
        unsigned char *getBitmap(size_t *size=nullptr);
282 andreas 36
        size_t getSize() { return mSize; }
289 andreas 37
        bool isValid();
282 andreas 38
 
283 andreas 39
        int getPixline() { return mPixline; }
40
        void setPixline(int pl);
41
        int getWidth() { return mWidth; }
42
        void setWidth(int w);
43
        int getHeight() { return mHeight; }
44
        void setHeight(int h);
45
 
46
        void setSize(int w, int h);
289 andreas 47
        void clear();
283 andreas 48
 
49
        int getPixelSize() { return mPixelSize; }
50
        void setPixelSize(int ps);
51
 
284 andreas 52
        TBitmap& operator=(const TBitmap& bm)
53
        {
289 andreas 54
            this->clear();
284 andreas 55
 
56
            if (bm.mSize > 0)
57
            {
58
                this->mData = new unsigned char[bm.mSize];
59
                memmove(this->mData, bm.mData, bm.mSize);
60
                this->mSize = bm.mSize;
61
            }
62
 
63
            this->mPixline = bm.mPixline;
64
            this->mPixelSize = bm.mPixelSize;
65
            this->mWidth = bm.mWidth;
66
            this->mHeight = bm.mHeight;
67
 
68
            return *this;
69
        }
70
 
282 andreas 71
    private:
72
        unsigned char *mData{nullptr};
73
        size_t mSize{0};
283 andreas 74
        int mPixline{0};
75
        int mWidth{0};
76
        int mHeight{0};
77
        int mPixelSize{4};
282 andreas 78
};
79
 
80
#endif