1 /**
2  * File name: RkImage.cpp
3  * Project: Redkite (A small GUI toolkit)
4  *
5  * Copyright (C) 2019 Iurie Nistor <http://geontime.com>
6  *
7  * This file is part of Redkite.
8  *
9  * Redkite is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #include "RkImage.h"
25 #include "RkImageImpl.h"
26 
RkImage()27 RkImage::RkImage()
28         : o_ptr{std::make_unique<RkImageImpl>(this, 0, 0, nullptr)}
29 {
30 }
31 
RkImage(int width,int height,const unsigned char * data,Format format)32 RkImage::RkImage(int width,
33                  int height,
34                  const unsigned char *data,
35                  Format format)
36         : o_ptr{std::make_unique<RkImageImpl>(this, width, height, data, format)}
37 {
38 }
39 
RkImage(const RkSize & size,const unsigned char * data,Format format)40 RkImage::RkImage(const RkSize &size,
41                  const unsigned char *data,
42                  Format format)
43         : o_ptr{std::make_unique<RkImageImpl>(this, size.width(), size.height(), data, format)}
44 {
45 }
46 
RkImage(std::unique_ptr<RkImageImpl> impl)47 RkImage::RkImage(std::unique_ptr<RkImageImpl> impl)
48         : o_ptr{std::move(impl)}
49 {
50 }
51 
RkImage(const RkImage & image)52 RkImage::RkImage(const RkImage &image) :
53         o_ptr{std::make_unique<RkImageImpl>(this, 0, 0, nullptr)}
54 {
55         o_ptr->createImage({image.width(), image.height()}, image.format(), image.data());
56 }
57 
~RkImage()58 RkImage::~RkImage()
59 {
60 }
61 
operator =(const RkImage & other)62 RkImage& RkImage::operator=(const RkImage &other)
63 {
64         o_ptr->createImage({other.width(), other.height()}, other.format(), other.data());
65         return *this;
66 }
67 
fill(const RkColor & color)68 void RkImage::fill(const RkColor &color)
69 {
70         o_ptr->fill(color);
71 }
72 
getCanvasInfo() const73 const RkCanvasInfo* RkImage::getCanvasInfo() const
74 {
75         return o_ptr->getCanvasInfo();
76 }
77 
data() const78 unsigned char* RkImage::data() const
79 {
80         return o_ptr->data();
81 }
82 
dataCopy() const83 std::vector<unsigned char> RkImage::dataCopy() const
84 {
85         return o_ptr->dataCopy();
86 }
87 
format() const88 RkImage::Format RkImage::format() const
89 {
90         return o_ptr->format();
91 }
92 
width() const93 int RkImage::width() const
94 {
95         return o_ptr->width();
96 }
97 
height() const98 int RkImage::height() const
99 {
100         return o_ptr->height();
101 }
102 
size() const103 RkSize RkImage::size() const
104 {
105         return o_ptr->size();
106 }
107 
isNull() const108 bool RkImage::isNull() const
109 {
110         return o_ptr->isNull();
111 }
112