5#ifndef NIRT_I_IMAGE_HPP_INCLUDED
6#define NIRT_I_IMAGE_HPP_INCLUDED
8#include <nirtcpp/core/engine/IReferenceCounted.hpp>
9#include <nirtcpp/core/engine/position2d.hpp>
10#include <nirtcpp/core/engine/rect.hpp>
11#include <nirtcpp/core/engine/SColor.hpp>
12#include <nirtcpp/core/engine/irrAllocator.hpp>
31 Format(format), Size(size), Data(0), MipMapsData(0), BytesPerPixel(0), Pitch(0), DeleteMemory(deleteMemory), DeleteMipMapsMemory(false)
32#if defined(NIRTCPP_sRGB)
37 Pitch = BytesPerPixel * Size.
Width;
46 if (DeleteMipMapsMemory)
56#if defined(NIRTCPP_sRGB)
62 void set_sRGB(
int val)
219 while (i != mipmapLevel)
227 if ( result.
Width == 1 && result.
Height == 1 && i < mipmapLevel )
241 if ( MipMapsData && mipLevel > 0)
247 while (i != mipLevel)
249 if (mipSize.
Width > 1)
258 if ( mipSize.
Width == 1 && mipSize.
Height == 1 && i < mipLevel)
262 return MipMapsData + dataSize;
279 if (data != MipMapsData)
281 if (DeleteMipMapsMemory)
285 DeleteMipMapsMemory =
false;
290 if (ownForeignMemory)
292 MipMapsData =
static_cast<u8*
>(data);
294 DeleteMipMapsMemory = deleteMemory;
311 }
while (width != 1 || height != 1);
313 MipMapsData = Allocator.
allocate(dataSize);
314 std::copy_n((
char *)data, dataSize, (
char *)MipMapsData);
316 DeleteMipMapsMemory =
true;
355 bool combineAlpha=
false) =0;
364 virtual void flip(
bool topBottom,
bool leftRight) = 0;
459 return (
size_t)(
s32)(dataSize) == dataSize;
465 size_t imageSize = 0;
470 imageSize = (size_t)((width + 3) / 4) * ((height + 3) / 4) * 8;
476 imageSize = (size_t)((width + 3) / 4) * ((height + 3) / 4) * 16;
487 imageSize = (size_t)core::ceil32(width / 8.0f) * core::ceil32(height / 4.0f) * 8;
492 imageSize = (size_t)core::ceil32(width / 4.0f) * core::ceil32(height / 4.0f) * 8;
495 imageSize = (size_t)core::ceil32(width / 4.0f) * core::ceil32(height / 4.0f) * 16;
507#define NIRT_CASE_IIMAGE_COMPRESSED_FORMAT\
513 case ECF_PVRTC_RGB2:\
514 case ECF_PVRTC_ARGB2:\
515 case ECF_PVRTC2_ARGB2:\
516 case ECF_PVRTC_RGB4:\
517 case ECF_PVRTC_ARGB4:\
518 case ECF_PVRTC2_ARGB4:\
528 NIRT_CASE_IIMAGE_COMPRESSED_FORMAT
567#if defined(PATCH_SUPERTUX_8_0_1_with_1_9_0)
568 static bool isRenderTargetOnlyFormat(
const ECOLOR_FORMAT format)
585 core::dimension2d<u32> Size;
594 bool DeleteMipMapsMemory;
596 core::irrAllocator<u8> Allocator;
597#if defined(NIRTCPP_sRGB)
Base class of most objects of the Nirtcpp Engine.
Definition IReferenceCounted.hpp:46
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
T Height
Height of the dimension.
Definition dimension2d.hpp:206
T Width
Width of the dimension.
Definition dimension2d.hpp:204
void deallocate(T *ptr)
Deallocate memory for an array of objects.
Definition irrAllocator.hpp:39
T * allocate(size_t cnt)
Allocate memory for an array of objects.
Definition irrAllocator.hpp:33
Interface for software image data.
Definition IImage.hpp:26
NIRT_DEPRECATED bool isCompressed() const
Inform whether the image is compressed.
Definition IImage.hpp:370
static u32 getBitsPerPixelFromFormat(const ECOLOR_FORMAT format)
get the amount of Bits per Pixel of the given color format
Definition IImage.hpp:383
void * getData() const
Use this to get a pointer to the image data.
Definition IImage.hpp:181
static bool isFloatingPointFormat(const ECOLOR_FORMAT format)
Check if the color format uses floating point values for pixels.
Definition IImage.hpp:550
const core::dimension2d< u32 > & getDimension() const
Returns width and height of image data.
Definition IImage.hpp:69
virtual void copyToScaling(void *target, u32 width, u32 height, ECOLOR_FORMAT format=ECF_A8R8G8B8, u32 pitch=0)=0
Copies the image into the target, scaling the image to fit.
ECOLOR_FORMAT getColorFormat() const
Returns the color format.
Definition IImage.hpp:51
IImage(ECOLOR_FORMAT format, const core::dimension2d< u32 > &size, bool deleteMemory)
constructor
Definition IImage.hpp:30
static bool isCompressedFormat(const ECOLOR_FORMAT format)
check if this is compressed color format
Definition IImage.hpp:524
static core::dimension2du getMipMapsSize(const core::dimension2du &sizeLevel0, u32 mipmapLevel)
Calculate mipmap size for a certain level.
Definition IImage.hpp:215
u32 getRedMask() const
Returns mask for red value of a pixel.
Definition IImage.hpp:105
NIRT_DEPRECATED void unlock()
Unlock function.
Definition IImage.hpp:200
virtual void copyTo(IImage *target, const core::position2d< s32 > &pos=core::position2d< s32 >(0, 0))=0
copies this surface into another
u32 getBytesPerPixel() const
Returns bytes per pixel.
Definition IImage.hpp:81
u32 getAlphaMask() const
Returns mask for alpha value of a pixel.
Definition IImage.hpp:159
virtual void copyToScalingBoxFilter(IImage *target, s32 bias=0, bool blend=false)=0
copies this surface into another, scaling it to fit, applying a box filter
virtual ~IImage()
destructor
Definition IImage.hpp:41
u32 getBlueMask() const
Returns mask for blue value of a pixel.
Definition IImage.hpp:141
static bool isDepthFormat(const ECOLOR_FORMAT format)
check if the color format is only viable for depth/stencil textures
Definition IImage.hpp:536
virtual void flip(bool topBottom, bool leftRight)=0
Flips (mirrors) the image in one or two directions.
core::dimension2du getMipMapsSize(u32 mipmapLevel) const
Get the mipmap size for this image for a certain mipmap level.
Definition IImage.hpp:207
u32 getGreenMask() const
Returns mask for green value of a pixel.
Definition IImage.hpp:123
u32 getPitch() const
Returns pitch of image.
Definition IImage.hpp:99
virtual void copyToWithAlpha(IImage *target, const core::position2d< s32 > &pos, const core::rect< s32 > &sourceRect, const SColor &color, const core::rect< s32 > *clipRect=0, bool combineAlpha=false)=0
copies this surface into another, using the alpha mask and cliprect and a color to add with
void setMipMapsData(void *data, bool ownForeignMemory, bool deleteMemory)
Set mipmaps data.
Definition IImage.hpp:277
NIRT_DEPRECATED void * lock()
Lock function. Use this to get a pointer to the image data.
Definition IImage.hpp:192
virtual void copyToScaling(IImage *target)=0
Copies the image into the target, scaling the image to fit.
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
virtual void fill(const SColor &color)=0
fills the surface with given color
static bool checkDataSizeLimit(size_t dataSize)
You should not create images where the result of getDataSizeFromFormat doesn't pass this function.
Definition IImage.hpp:454
virtual void setPixel(u32 x, u32 y, const SColor &color, bool blend=false)=0
Sets a pixel.
static size_t getDataSizeFromFormat(ECOLOR_FORMAT format, u32 width, u32 height)
calculate image data size in bytes for selected format, width and height.
Definition IImage.hpp:463
void * getMipMapsData(nirt::u32 mipLevel=1) const
Get mipmaps data.
Definition IImage.hpp:239
u32 getBitsPerPixel() const
Returns bits per pixel.
Definition IImage.hpp:75
NIRT_DEPRECATED bool hasMipMaps() const
Check whether the image has MipMaps.
Definition IImage.hpp:377
size_t getImageDataSizeInBytes() const
Returns image data size in bytes.
Definition IImage.hpp:87
virtual SColor getPixel(u32 x, u32 y) const =0
Returns a pixel.
u32 getImageDataSizeInPixels() const
Returns image data size in pixels.
Definition IImage.hpp:93
Class representing a 32 bit ARGB color.
Definition SColor.hpp:317
dimension2d< u32 > dimension2du
using type alias for an unsigned integer dimension.
Definition dimension2d.hpp:212
ECOLOR_FORMAT
An enum for the color format of textures used by the Nirtcpp Engine.
Definition SColor.hpp:21
@ ECF_D32
32 bit format using 32 bits for depth.
Definition SColor.hpp:126
@ ECF_PVRTC_ARGB4
PVRTC ARGB 4bpp.
Definition SColor.hpp:67
@ ECF_G32R32F
64 bit format using 32 bits for the red and green channels.
Definition SColor.hpp:101
@ ECF_A16B16G16R16F
64 bit format using 16 bits for the red, green, blue and alpha channels.
Definition SColor.hpp:95
@ ECF_ETC2_RGB
ETC2 RGB.
Definition SColor.hpp:79
@ ECF_A32B32G32R32F
128 bit format using 32 bits for the red, green, blue and alpha channels.
Definition SColor.hpp:104
@ ECF_DXT5
DXT5 color format.
Definition SColor.hpp:55
@ ECF_ETC1
ETC1 RGB.
Definition SColor.hpp:76
@ ECF_R16G16
32 bit format using 16 bits for the red and green channels.
Definition SColor.hpp:118
@ ECF_D16
16 bit format using 16 bits for depth.
Definition SColor.hpp:123
@ ECF_R8G8
16 bit format using 8 bits for the red and green channels.
Definition SColor.hpp:112
@ ECF_A8R8G8B8
Definition SColor.hpp:38
@ ECF_PVRTC_RGB2
PVRTC RGB 2bpp.
Definition SColor.hpp:58
@ ECF_R8G8B8
Definition SColor.hpp:34
@ ECF_DXT1
DXT1 color format.
Definition SColor.hpp:43
@ ECF_PVRTC_ARGB2
PVRTC ARGB 2bpp.
Definition SColor.hpp:61
@ ECF_PVRTC_RGB4
PVRTC RGB 4bpp.
Definition SColor.hpp:64
@ ECF_A1R5G5B5
16 bit color format used by the software driver.
Definition SColor.hpp:26
@ ECF_PVRTC2_ARGB4
PVRTC2 ARGB 4bpp.
Definition SColor.hpp:73
@ ECF_DXT4
DXT4 color format.
Definition SColor.hpp:52
@ ECF_R16F
16 bit format using 16 bits for the red channel.
Definition SColor.hpp:89
@ ECF_G16R16F
32 bit format using 16 bits for the red and green channels.
Definition SColor.hpp:92
@ ECF_R32F
32 bit format using 32 bits for the red channel.
Definition SColor.hpp:98
@ ECF_D24S8
32 bit format using 24 bits for depth and 8 bits for stencil.
Definition SColor.hpp:129
@ ECF_DXT3
DXT3 color format.
Definition SColor.hpp:49
@ ECF_R5G6B5
Standard 16 bit color format.
Definition SColor.hpp:29
@ ECF_R16
16 bit format using 16 bits for the red channel.
Definition SColor.hpp:115
@ ECF_PVRTC2_ARGB2
PVRTC2 ARGB 2bpp.
Definition SColor.hpp:70
@ ECF_ETC2_ARGB
ETC2 ARGB.
Definition SColor.hpp:82
@ ECF_R8
8 bit format using 8 bits for the red channel.
Definition SColor.hpp:109
@ ECF_DXT2
DXT2 color format.
Definition SColor.hpp:46
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
signed int s32
32 bit signed variable.
Definition irrTypes.hpp:72
unsigned char u8
8 bit unsigned variable.
Definition irrTypes.hpp:24
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64