1 
2 /**
3  * File name: RkImage.h
4  * Project: Redkite (A small GUI toolkit)
5  *
6  * Copyright (C) 2019 Iurie Nistor <http://geontime.com>
7  *
8  * This file is part of Redkite.
9  *
10  * Redkite is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #ifndef RK_IMAGE_H
26 #define RK_IMAGE_H
27 
28 #include "RkCanvas.h"
29 #include "RkSize.h"
30 #include "RkColor.h"
31 
32 class RK_EXPORT RkImage : public RkCanvas {
33  public:
34         enum class Format : int {
35                 ARGB32 = 0,
36                 RGB32  = 1
37         };
38 
39         RkImage();
40         explicit RkImage(int width,
41                          int height,
42                          const unsigned char *data = nullptr,
43                          Format format = Format::ARGB32);
44 
45         explicit RkImage(const RkSize &size,
46                          const unsigned char *data = nullptr,
47                          Format format = Format::ARGB32);
48 
49         virtual ~RkImage();
50         RkImage(const RkImage &image);
51         RkImage& operator=(const RkImage &other);
52         friend  bool operator==(const RkImage &im1, const RkImage &im2)
53         {
54                 return im1.width() == im2.width()
55                         && im1.height() == im2.height()
56                         && im1.format() == im2.format()
57                         && im1.dataCopy() == im2.dataCopy();
58 
59         }
60 
61         friend  bool operator!=(const RkImage &im1, const RkImage &im2)
62         {
63                 return im1.width() != im2.width()
64                         || im1.height() != im2.height()
65                         || im1.format() != im2.format()
66                         || im1.dataCopy() != im2.dataCopy();
67 
68          }
69         void fill(const RkColor &color);
70         const RkCanvasInfo* getCanvasInfo() const;
71         unsigned char* data() const;
72         std::vector<unsigned char> dataCopy() const;
73         Format format() const;
74         int width() const;
75         int height() const;
76         RkSize size() const;
77         bool isNull() const;
78 
79  protected:
80         RK_DECLARE_IMPL(RkImage);
81         explicit RkImage(std::unique_ptr<RkImageImpl> impl);
82 
83  private:
84         RK_DISABLE_MOVE(RkImage);
85 };
86 
87 #endif // RK_IMAGE_H
88