Skylicht Engine
Loading...
Searching...
No Matches
IImage.h
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5#ifndef __I_IMAGE_H_INCLUDED__
6#define __I_IMAGE_H_INCLUDED__
7
8#include "IReferenceCounted.h"
9#include "position2d.h"
10#include "rect.h"
11#include "SColor.h"
12
13namespace irr
14{
15namespace video
16{
17
19
22class IImage : public virtual IReferenceCounted
23{
24public:
25
27
32 virtual void* lock() = 0;
33
35
37 virtual void unlock() = 0;
38
40 virtual const core::dimension2d<u32>& getDimension() const = 0;
41
43 virtual u32 getBitsPerPixel() const = 0;
44
46 virtual u32 getBytesPerPixel() const = 0;
47
49 virtual u32 getImageDataSizeInBytes() const = 0;
50
52 virtual u32 getImageDataSizeInPixels() const = 0;
53
55 virtual SColor getPixel(u32 x, u32 y) const = 0;
56
58 virtual void setPixel(u32 x, u32 y, const SColor &color, bool blend = false ) = 0;
59
61 virtual ECOLOR_FORMAT getColorFormat() const = 0;
62
64 virtual u32 getRedMask() const = 0;
65
67 virtual u32 getGreenMask() const = 0;
68
70 virtual u32 getBlueMask() const = 0;
71
73 virtual u32 getAlphaMask() const = 0;
74
76 virtual u32 getPitch() const =0;
77
79 virtual void copyToScaling(void* target, u32 width, u32 height, ECOLOR_FORMAT format=ECF_A8R8G8B8, u32 pitch=0, bool swapBG=false) =0;
80
82 virtual void copyToScaling(IImage* target) =0;
83
85 virtual void copyTo(IImage* target, const core::position2d<s32>& pos=core::position2d<s32>(0,0)) =0;
86
88 virtual void copyTo(IImage* target, const core::position2d<s32>& pos, const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect=0) =0;
89
91 virtual void copyToWithAlpha(IImage* target, const core::position2d<s32>& pos,
92 const core::rect<s32>& sourceRect, const SColor &color,
93 const core::rect<s32>* clipRect = 0) =0;
94
96 virtual void copyToScalingBoxFilter(IImage* target, s32 bias = 0, bool blend = false) = 0;
97
99 virtual void fill(const SColor &color) =0;
100
102 virtual bool isCompressed() const = 0;
103
105
106 virtual bool hasMipMaps() const = 0;
107
108 virtual void swapBG() = 0;
109
112 {
113 switch (format)
114 {
115 case ECF_A1R5G5B5:
116 return 16;
117 case ECF_R5G6B5:
118 return 16;
119 case ECF_R8G8B8:
120 return 24;
121 case ECF_A8R8G8B8:
122 return 32;
123 case ECF_DXT1:
124 return 16;
125 case ECF_DXT2:
126 case ECF_DXT3:
127 case ECF_DXT4:
128 case ECF_DXT5:
129 return 32;
130 case ECF_PVRTC_RGB2:
131 return 12;
132 case ECF_PVRTC_ARGB2:
133 case ECF_PVRTC2_ARGB2:
134 return 16;
135 case ECF_PVRTC_RGB4:
136 return 24;
137 case ECF_PVRTC_ARGB4:
138 case ECF_PVRTC2_ARGB4:
139 return 32;
140 case ECF_ETC1:
141 case ECF_ETC2_RGB:
142 return 24;
143 case ECF_ETC2_ARGB:
144 return 32;
145 case ECF_R16F:
146 return 16;
147 case ECF_G16R16F:
148 return 32;
150 return 64;
151 case ECF_R32F:
152 return 32;
153 case ECF_G32R32F:
154 return 64;
156 return 128;
157 default:
158 return 0;
159 }
160 }
161
163 static u32 getCompressedImageSize(ECOLOR_FORMAT format, u32 width, u32 height)
164 {
165 if (!isCompressedFormat(format))
166 return 0;
167
168 u32 compressedImageSize = 0;
169
170 switch (format)
171 {
172 case ECF_DXT1:
173 compressedImageSize = ((width + 3) / 4) * ((height + 3) / 4) * 8;
174 break;
175 case ECF_DXT2:
176 case ECF_DXT3:
177 case ECF_DXT4:
178 case ECF_DXT5:
179 compressedImageSize = ((width + 3) / 4) * ((height + 3) / 4) * 16;
180 break;
181 case ECF_PVRTC_RGB2:
182 case ECF_PVRTC_ARGB2:
183 compressedImageSize = (core::max_<u32>(width, 16) * core::max_<u32>(height, 8) * 2 + 7) / 8;
184 break;
185 case ECF_PVRTC_RGB4:
186 case ECF_PVRTC_ARGB4:
187 compressedImageSize = (core::max_<u32>(width, 8) * core::max_<u32>(height, 8) * 4 + 7) / 8;
188 break;
189 case ECF_PVRTC2_ARGB2:
190 compressedImageSize = core::ceil32(width / 8.0f) * core::ceil32(height / 4.0f) * 8;
191 break;
192 case ECF_PVRTC2_ARGB4:
193 case ECF_ETC1:
194 case ECF_ETC2_RGB:
195 compressedImageSize = core::ceil32(width / 4.0f) * core::ceil32(height / 4.0f) * 8;
196 break;
197 case ECF_ETC2_ARGB:
198 compressedImageSize = core::ceil32(width / 4.0f) * core::ceil32(height / 4.0f) * 16;
199 break;
202 compressedImageSize = width * height * 2;
203 break;
205 compressedImageSize = width * height * 3;
206 break;
208 compressedImageSize = width * height * 4;
209 break;
210 default:
211 break;
212 }
213
214 return compressedImageSize;
215 }
216
218 static bool isCompressedFormat(const ECOLOR_FORMAT format)
219 {
220 switch (format)
221 {
222 case ECF_DXT1:
223 case ECF_DXT2:
224 case ECF_DXT3:
225 case ECF_DXT4:
226 case ECF_DXT5:
227 case ECF_PVRTC_RGB2:
228 case ECF_PVRTC_ARGB2:
229 case ECF_PVRTC2_ARGB2:
230 case ECF_PVRTC_RGB4:
231 case ECF_PVRTC_ARGB4:
232 case ECF_PVRTC2_ARGB4:
233 case ECF_ETC1:
234 case ECF_ETC2_RGB:
235 case ECF_ETC2_ARGB:
240 return true;
241 default:
242 return false;
243 }
244 }
245
247 static bool isDepthFormat(const ECOLOR_FORMAT format)
248 {
249 switch(format)
250 {
251 case ECF_D16:
252 case ECF_D32:
253 case ECF_D24S8:
254 return true;
255 default:
256 return false;
257 }
258 }
259
261
264 static bool isRenderTargetOnlyFormat(const ECOLOR_FORMAT format)
265 {
266 switch(format)
267 {
268 case ECF_A1R5G5B5:
269 case ECF_R5G6B5:
270 case ECF_R8G8B8:
271 case ECF_A8R8G8B8:
272 return false;
273 default:
274 return true;
275 }
276 }
277
278};
279
280} // end namespace video
281} // end namespace irr
282
283#endif
284
IReferenceCounted()
Constructor.
Definition IReferenceCounted.h:50
Specifies a 2 dimensional size.
Definition dimension2d.h:21
Rectangle template.
Definition rect.h:27
Interface for software image data.
Definition IImage.h:23
virtual void fill(const SColor &color)=0
fills the surface with given color
virtual SColor getPixel(u32 x, u32 y) const =0
Returns a pixel.
virtual u32 getBytesPerPixel() const =0
Returns bytes per pixel.
virtual u32 getGreenMask() const =0
Returns mask for green value of a pixel.
virtual const core::dimension2d< u32 > & getDimension() const =0
Returns width and height of image data.
static bool isCompressedFormat(const ECOLOR_FORMAT format)
test if this is compressed color format
Definition IImage.h:218
virtual u32 getBlueMask() const =0
Returns mask for blue value of a pixel.
virtual u32 getAlphaMask() const =0
Returns mask for alpha value of a pixel.
virtual bool hasMipMaps() const =0
Check whether the image has MipMaps.
virtual void copyToScalingBoxFilter(IImage *target, s32 bias=0, bool blend=false)=0
copies this surface into another, scaling it to fit, appyling a box filter
static u32 getBitsPerPixelFromFormat(const ECOLOR_FORMAT format)
get the amount of Bits per Pixel of the given color format
Definition IImage.h:111
virtual void copyToWithAlpha(IImage *target, const core::position2d< s32 > &pos, const core::rect< s32 > &sourceRect, const SColor &color, const core::rect< s32 > *clipRect=0)=0
copies this surface into another, using the alpha mask and cliprect and a color to add with
virtual void copyToScaling(void *target, u32 width, u32 height, ECOLOR_FORMAT format=ECF_A8R8G8B8, u32 pitch=0, bool swapBG=false)=0
Copies the image into the target, scaling the image to fit.
virtual void setPixel(u32 x, u32 y, const SColor &color, bool blend=false)=0
Sets a pixel.
virtual u32 getImageDataSizeInPixels() const =0
Returns image data size in pixels.
static u32 getCompressedImageSize(ECOLOR_FORMAT format, u32 width, u32 height)
calculate compressed image size for selected width and height.
Definition IImage.h:163
virtual void copyToScaling(IImage *target)=0
Copies the image into the target, scaling the image to fit.
virtual u32 getPitch() const =0
Returns pitch of image.
virtual u32 getImageDataSizeInBytes() const =0
Returns image data size in bytes.
virtual u32 getRedMask() const =0
Returns mask for red value of a pixel.
static bool isRenderTargetOnlyFormat(const ECOLOR_FORMAT format)
test if the color format is only viable for RenderTarget textures
Definition IImage.h:264
virtual void copyTo(IImage *target, const core::position2d< s32 > &pos, const core::rect< s32 > &sourceRect, const core::rect< s32 > *clipRect=0)=0
copies this surface into another
static bool isDepthFormat(const ECOLOR_FORMAT format)
test if the color format is only viable for depth/stencil textures
Definition IImage.h:247
virtual void * lock()=0
Lock function. Use this to get a pointer to the image data.
virtual ECOLOR_FORMAT getColorFormat() const =0
Returns the color format.
virtual void unlock()=0
Unlock function.
virtual bool isCompressed() const =0
Inform whether the image is compressed.
virtual u32 getBitsPerPixel() const =0
Returns bits per pixel.
virtual void copyTo(IImage *target, const core::position2d< s32 > &pos=core::position2d< s32 >(0, 0))=0
copies this surface into another
Class representing a 32 bit ARGB color.
Definition SColor.h:285
const T & max_(const T &a, const T &b)
returns maximum of two values. Own implementation to get rid of the STL (VS6 problems)
Definition irrMath.h:137
The video namespace contains classes for accessing the video driver. All 2d and 3d rendering is done ...
Definition EDriverFeatures.h:11
ECOLOR_FORMAT
An enum for the color format of textures used by the Irrlicht Engine.
Definition SColor.h:18
@ ECT_PVRTC2_RGBA4444
PVRTC2 RGBA 4444.
Definition SColor.h:70
@ ECF_A1R5G5B5
16 bit color format used by the software driver.
Definition SColor.h:23
@ ECF_D16
16 bit format using 16 bits for depth.
Definition SColor.h:115
@ ECF_DXT5
DXT5 color format.
Definition SColor.h:49
@ ECT_PVRTC2_RGB565
ECT_PVRTC2_RGB 565.
Definition SColor.h:73
@ ECF_A32B32G32R32F
128 bit format using 32 bits for the red, green, blue and alpha channels.
Definition SColor.h:110
@ ECF_D24S8
32 bit format using 24 bits for depth and 8 bits for stencil.
Definition SColor.h:121
@ ECF_R8G8B8
24 bit color, no alpha channel, but 8 bit for red, green and blue.
Definition SColor.h:29
@ ECF_R5G6B5
Standard 16 bit color format.
Definition SColor.h:26
@ ECF_DXT3
DXT3 color format.
Definition SColor.h:43
@ ECF_A8R8G8B8
Default 32 bit color format. 8 bits are used for every component: red, green, blue and alpha.
Definition SColor.h:32
@ ECT_PVRTC2_RGB888
ECT_PVRTC2_RGB 888.
Definition SColor.h:76
@ ECF_ETC2_RGB
ETC2 RGB.
Definition SColor.h:85
@ ECF_PVRTC2_ARGB4
PVRTC2 ARGB 4bpp.
Definition SColor.h:67
@ ECF_ETC1
ETC1 RGB.
Definition SColor.h:82
@ ECT_PVRTC2_RGBA8888
ECT_PVRTC2_RGBA 8888.
Definition SColor.h:79
@ ECF_ETC2_ARGB
ETC2 ARGB.
Definition SColor.h:88
@ ECF_A16B16G16R16F
64 bit format using 16 bits for the red, green, blue and alpha channels.
Definition SColor.h:101
@ ECF_G32R32F
64 bit format using 32 bits for the red and green channels.
Definition SColor.h:107
@ ECF_PVRTC_RGB2
PVRTC RGB 2bpp.
Definition SColor.h:52
@ ECF_PVRTC_RGB4
PVRTC RGB 4bpp.
Definition SColor.h:58
@ ECF_DXT2
DXT2 color format.
Definition SColor.h:40
@ ECF_R16F
16 bit format using 16 bits for the red channel.
Definition SColor.h:95
@ ECF_PVRTC_ARGB4
PVRTC ARGB 4bpp.
Definition SColor.h:61
@ ECF_D32
32 bit format using 32 bits for depth.
Definition SColor.h:118
@ ECF_PVRTC2_ARGB2
PVRTC2 ARGB 2bpp.
Definition SColor.h:64
@ ECF_DXT1
DXT1 color format.
Definition SColor.h:37
@ ECF_DXT4
DXT4 color format.
Definition SColor.h:46
@ ECF_R32F
32 bit format using 32 bits for the red channel.
Definition SColor.h:104
@ ECF_PVRTC_ARGB2
PVRTC ARGB 2bpp.
Definition SColor.h:55
@ ECF_G16R16F
32 bit format using 16 bits for the red and green channels.
Definition SColor.h:98
Everything in the Irrlicht Engine can be found in this namespace.
Definition Skylicht.h:33
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58
signed int s32
32 bit signed variable.
Definition irrTypes.h:66