Kiwano Engine v1.3.x
Bitmap.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/core/Resource.h>
23#include <kiwano/platform/NativeObject.hpp>
24
25namespace kiwano
26{
27
39{
40 Linear,
41 Nearest
42};
43
47
53enum class PixelFormat
54{
55 Bpp32RGBA,
56 Bpp32BGRA,
57};
58
63class KGE_API Image : public NativeObject
64{
65public:
66 Image();
67
70 InterpolationMode GetInterpolationMode() const;
71
74 void SetInterpolationMode(InterpolationMode mode);
75
78 static void SetDefaultInterpolationMode(InterpolationMode mode);
79
82 static InterpolationMode GetDefaultInterpolationMode();
83
84protected:
85 InterpolationMode interpolation_mode_;
86
87 static InterpolationMode default_interpolation_mode_;
88};
89
94class KGE_API Bitmap : public Image
95{
96public:
97 Bitmap();
98
101 Bitmap(StringView file_path);
102
105 Bitmap(const Resource& res);
106
109 Bitmap(const PixelSize& size, const BinaryData& data, PixelFormat format);
110
111 virtual ~Bitmap();
112
115 bool Load(StringView file_path);
116
119 bool Load(const Resource& res);
120
123 bool Load(const PixelSize& size, const BinaryData& data, PixelFormat format);
124
127 float GetWidth() const;
128
131 float GetHeight() const;
132
135 Size GetSize() const;
136
139 uint32_t GetWidthInPixels() const;
140
143 uint32_t GetHeightInPixels() const;
144
147 PixelSize GetSizeInPixels() const;
148
151 void SetSize(const Size& size);
152
155 void SetSizeInPixels(const PixelSize& size);
156
160 void CopyFrom(RefPtr<Bitmap> copy_from);
161
167 void CopyFrom(RefPtr<Bitmap> copy_from, const Rect& src_rect, const Point& dest_point);
168
169private:
170 Size size_;
171 PixelSize size_in_pixels_;
172};
173
177{
178 return interpolation_mode_;
179}
180
181inline float Bitmap::GetWidth() const
182{
183 return size_.x;
184}
185
186inline float Bitmap::GetHeight() const
187{
188 return size_.y;
189}
190
191inline Size Bitmap::GetSize() const
192{
193 return size_;
194}
195
196inline uint32_t Bitmap::GetWidthInPixels() const
197{
198 return size_in_pixels_.x;
199}
200
201inline uint32_t Bitmap::GetHeightInPixels() const
202{
203 return size_in_pixels_.y;
204}
205
207{
208 return size_in_pixels_;
209}
210
211inline void Bitmap::SetSize(const Size& size)
212{
213 size_ = size;
214}
215
216inline void Bitmap::SetSizeInPixels(const PixelSize& size)
217{
218 size_in_pixels_ = size;
219}
220
221} // namespace kiwano
位图
Definition: Bitmap.h:95
uint32_t GetHeightInPixels() const
获取像素高度
Definition: Bitmap.h:201
void SetSize(const Size &size)
设置大小
Definition: Bitmap.h:211
float GetWidth() const
获取位图宽度
Definition: Bitmap.h:181
uint32_t GetWidthInPixels() const
获取像素宽度
Definition: Bitmap.h:196
Size GetSize() const
获取位图大小
Definition: Bitmap.h:191
void SetSizeInPixels(const PixelSize &size)
设置像素大小
Definition: Bitmap.h:216
PixelSize GetSizeInPixels() const
获取像素大小
Definition: Bitmap.h:206
float GetHeight() const
获取位图高度
Definition: Bitmap.h:186
图像(位图或矢量图)
Definition: Bitmap.h:64
InterpolationMode GetInterpolationMode() const
获取像素插值方式
Definition: Bitmap.h:176
含有本地指针的对象
Definition: NativeObject.hpp:32
引用计数智能指针
Definition: RefBasePtr.hpp:35
资源
Definition: Resource.h:41
math::Vec2T< uint32_t > PixelSize
像素大小
Definition: Bitmap.h:46
PixelFormat
像素格式
Definition: Bitmap.h:54
InterpolationMode
插值模式
Definition: Bitmap.h:39
@ Nearest
最邻近插值,取最邻近的像素点的颜色值
二进制数据
Definition: BinaryData.h:30