mirror of
https://github.com/minetest/irrlicht.git
synced 2025-07-02 00:00:26 +02:00
Reformat the code, using:
find -type f | # list all regular files grep -E '\.(h|cpp|mm)$' | # filter for source files grep -v '/mt_' | # filter out generated files grep -v '/vendor/' | # and vendored GL grep -v '/test/image_loader_test.cpp' | # and this file (has giant literals arrays) xargs -n 1 -P $(nproc) clang-format -i # reformat everything Co-authored-by: numzero <numzer0@yandex.ru>
This commit is contained in:
129
include/IImage.h
129
include/IImage.h
@ -23,10 +23,9 @@ NOTE: Floating point formats are not well supported yet. Basically only getData(
|
||||
class IImage : public virtual IReferenceCounted
|
||||
{
|
||||
public:
|
||||
|
||||
//! constructor
|
||||
IImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size, bool deleteMemory) :
|
||||
Format(format), Size(size), Data(0), MipMapsData(0), BytesPerPixel(0), Pitch(0), DeleteMemory(deleteMemory), DeleteMipMapsMemory(false)
|
||||
IImage(ECOLOR_FORMAT format, const core::dimension2d<u32> &size, bool deleteMemory) :
|
||||
Format(format), Size(size), Data(0), MipMapsData(0), BytesPerPixel(0), Pitch(0), DeleteMemory(deleteMemory), DeleteMipMapsMemory(false)
|
||||
{
|
||||
BytesPerPixel = getBitsPerPixelFromFormat(Format) / 8;
|
||||
Pitch = BytesPerPixel * Size.Width;
|
||||
@ -49,7 +48,7 @@ public:
|
||||
}
|
||||
|
||||
//! Returns width and height of image data.
|
||||
const core::dimension2d<u32>& getDimension() const
|
||||
const core::dimension2d<u32> &getDimension() const
|
||||
{
|
||||
return Size;
|
||||
}
|
||||
@ -88,8 +87,7 @@ public:
|
||||
//! Returns mask for red value of a pixel
|
||||
u32 getRedMask() const
|
||||
{
|
||||
switch (Format)
|
||||
{
|
||||
switch (Format) {
|
||||
case ECF_A1R5G5B5:
|
||||
return 0x1F << 10;
|
||||
case ECF_R5G6B5:
|
||||
@ -106,8 +104,7 @@ public:
|
||||
//! Returns mask for green value of a pixel
|
||||
u32 getGreenMask() const
|
||||
{
|
||||
switch (Format)
|
||||
{
|
||||
switch (Format) {
|
||||
case ECF_A1R5G5B5:
|
||||
return 0x1F << 5;
|
||||
case ECF_R5G6B5:
|
||||
@ -124,8 +121,7 @@ public:
|
||||
//! Returns mask for blue value of a pixel
|
||||
u32 getBlueMask() const
|
||||
{
|
||||
switch (Format)
|
||||
{
|
||||
switch (Format) {
|
||||
case ECF_A1R5G5B5:
|
||||
return 0x1F;
|
||||
case ECF_R5G6B5:
|
||||
@ -142,8 +138,7 @@ public:
|
||||
//! Returns mask for alpha value of a pixel
|
||||
u32 getAlphaMask() const
|
||||
{
|
||||
switch (Format)
|
||||
{
|
||||
switch (Format) {
|
||||
case ECF_A1R5G5B5:
|
||||
return 0x1 << 15;
|
||||
case ECF_R5G6B5:
|
||||
@ -162,7 +157,7 @@ public:
|
||||
\return Pointer to the image data. What type of data is pointed to
|
||||
depends on the color format of the image. For example if the color
|
||||
format is ECF_A8R8G8B8, it is of u32. */
|
||||
void* getData() const
|
||||
void *getData() const
|
||||
{
|
||||
return Data;
|
||||
}
|
||||
@ -175,43 +170,38 @@ public:
|
||||
return getMipMapsSize(Size, mipmapLevel);
|
||||
}
|
||||
|
||||
|
||||
//! Calculate mipmap size for a certain level
|
||||
/** level 0 will be full image size. Every further level is half the size. */
|
||||
static core::dimension2du getMipMapsSize(const core::dimension2du& sizeLevel0, u32 mipmapLevel)
|
||||
static core::dimension2du getMipMapsSize(const core::dimension2du &sizeLevel0, u32 mipmapLevel)
|
||||
{
|
||||
core::dimension2du result(sizeLevel0);
|
||||
u32 i=0;
|
||||
while (i != mipmapLevel)
|
||||
{
|
||||
if (result.Width>1)
|
||||
u32 i = 0;
|
||||
while (i != mipmapLevel) {
|
||||
if (result.Width > 1)
|
||||
result.Width >>= 1;
|
||||
if (result.Height>1)
|
||||
result.Height>>=1;
|
||||
if (result.Height > 1)
|
||||
result.Height >>= 1;
|
||||
++i;
|
||||
|
||||
if ( result.Width == 1 && result.Height == 1 && i < mipmapLevel )
|
||||
return core::dimension2du(0,0);
|
||||
if (result.Width == 1 && result.Height == 1 && i < mipmapLevel)
|
||||
return core::dimension2du(0, 0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//! Get mipmaps data.
|
||||
/** Note that different mip levels are just behind each other in memory block.
|
||||
So if you just get level 1 you also have the data for all other levels.
|
||||
There is no level 0 - use getData to get the original image data.
|
||||
*/
|
||||
void* getMipMapsData(irr::u32 mipLevel=1) const
|
||||
void *getMipMapsData(irr::u32 mipLevel = 1) const
|
||||
{
|
||||
if ( MipMapsData && mipLevel > 0)
|
||||
{
|
||||
if (MipMapsData && mipLevel > 0) {
|
||||
size_t dataSize = 0;
|
||||
core::dimension2du mipSize(Size);
|
||||
u32 i = 1; // We want the start of data for this level, not end.
|
||||
u32 i = 1; // We want the start of data for this level, not end.
|
||||
|
||||
while (i != mipLevel)
|
||||
{
|
||||
while (i != mipLevel) {
|
||||
if (mipSize.Width > 1)
|
||||
mipSize.Width >>= 1;
|
||||
|
||||
@ -221,7 +211,7 @@ public:
|
||||
dataSize += getDataSizeFromFormat(Format, mipSize.Width, mipSize.Height);
|
||||
|
||||
++i;
|
||||
if ( mipSize.Width == 1 && mipSize.Height == 1 && i < mipLevel)
|
||||
if (mipSize.Width == 1 && mipSize.Height == 1 && i < mipLevel)
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -240,33 +230,26 @@ public:
|
||||
will by copied internally.
|
||||
\param deleteMemory Whether the memory is deallocated upon
|
||||
destruction. */
|
||||
void setMipMapsData(void* data, bool ownForeignMemory)
|
||||
void setMipMapsData(void *data, bool ownForeignMemory)
|
||||
{
|
||||
if (data != MipMapsData)
|
||||
{
|
||||
if (DeleteMipMapsMemory)
|
||||
{
|
||||
if (data != MipMapsData) {
|
||||
if (DeleteMipMapsMemory) {
|
||||
delete[] MipMapsData;
|
||||
|
||||
DeleteMipMapsMemory = false;
|
||||
}
|
||||
|
||||
if (data)
|
||||
{
|
||||
if (ownForeignMemory)
|
||||
{
|
||||
MipMapsData = static_cast<u8*>(data);
|
||||
if (data) {
|
||||
if (ownForeignMemory) {
|
||||
MipMapsData = static_cast<u8 *>(data);
|
||||
|
||||
DeleteMipMapsMemory = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
u32 dataSize = 0;
|
||||
u32 width = Size.Width;
|
||||
u32 height = Size.Height;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
if (width > 1)
|
||||
width >>= 1;
|
||||
|
||||
@ -281,9 +264,7 @@ public:
|
||||
|
||||
DeleteMipMapsMemory = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
MipMapsData = 0;
|
||||
}
|
||||
}
|
||||
@ -293,51 +274,50 @@ public:
|
||||
virtual SColor getPixel(u32 x, u32 y) const = 0;
|
||||
|
||||
//! Sets a pixel
|
||||
virtual void setPixel(u32 x, u32 y, const SColor &color, bool blend = false ) = 0;
|
||||
virtual void setPixel(u32 x, u32 y, const SColor &color, bool blend = false) = 0;
|
||||
|
||||
//! Copies this surface into another, if it has the exact same size and format.
|
||||
/** NOTE: mipmaps are ignored
|
||||
\return True if it was copied, false otherwise.
|
||||
*/
|
||||
virtual bool copyToNoScaling(void *target, u32 width, u32 height, ECOLOR_FORMAT format=ECF_A8R8G8B8, u32 pitch=0) const = 0;
|
||||
virtual bool copyToNoScaling(void *target, u32 width, u32 height, ECOLOR_FORMAT format = ECF_A8R8G8B8, u32 pitch = 0) const = 0;
|
||||
|
||||
//! Copies the image into the target, scaling the image to fit
|
||||
/** NOTE: mipmaps are ignored */
|
||||
virtual void copyToScaling(void* target, u32 width, u32 height, ECOLOR_FORMAT format=ECF_A8R8G8B8, u32 pitch=0) =0;
|
||||
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
|
||||
/** NOTE: mipmaps are ignored */
|
||||
virtual void copyToScaling(IImage* target) =0;
|
||||
virtual void copyToScaling(IImage *target) = 0;
|
||||
|
||||
//! copies this surface into another
|
||||
/** NOTE: mipmaps are ignored */
|
||||
virtual void copyTo(IImage* target, const core::position2d<s32>& pos=core::position2d<s32>(0,0)) =0;
|
||||
virtual void copyTo(IImage *target, const core::position2d<s32> &pos = core::position2d<s32>(0, 0)) = 0;
|
||||
|
||||
//! copies this surface into another
|
||||
/** NOTE: mipmaps are ignored */
|
||||
virtual void copyTo(IImage* target, const core::position2d<s32>& pos, const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect=0) =0;
|
||||
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, using the alpha mask and cliprect and a color to add with
|
||||
/** NOTE: mipmaps are ignored
|
||||
\param combineAlpha - When true then combine alpha channels. When false replace target image alpha with source image alpha.
|
||||
*/
|
||||
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;
|
||||
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, scaling it to fit, applying a box filter
|
||||
/** NOTE: mipmaps are ignored */
|
||||
virtual void copyToScalingBoxFilter(IImage* target, s32 bias = 0, bool blend = false) = 0;
|
||||
virtual void copyToScalingBoxFilter(IImage *target, s32 bias = 0, bool blend = false) = 0;
|
||||
|
||||
//! fills the surface with given color
|
||||
virtual void fill(const SColor &color) =0;
|
||||
virtual void fill(const SColor &color) = 0;
|
||||
|
||||
//! get the amount of Bits per Pixel of the given color format
|
||||
static u32 getBitsPerPixelFromFormat(const ECOLOR_FORMAT format)
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
switch (format) {
|
||||
case ECF_A1R5G5B5:
|
||||
return 16;
|
||||
case ECF_R5G6B5:
|
||||
@ -396,14 +376,13 @@ public:
|
||||
//! check if the color format is only viable for depth/stencil textures
|
||||
static bool isDepthFormat(const ECOLOR_FORMAT format)
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case ECF_D16:
|
||||
case ECF_D32:
|
||||
case ECF_D24S8:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
switch (format) {
|
||||
case ECF_D16:
|
||||
case ECF_D32:
|
||||
case ECF_D24S8:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -413,8 +392,7 @@ public:
|
||||
if (isCompressedFormat(format))
|
||||
return false;
|
||||
|
||||
switch(format)
|
||||
{
|
||||
switch (format) {
|
||||
case ECF_R16F:
|
||||
case ECF_G16R16F:
|
||||
case ECF_A16B16G16R16F:
|
||||
@ -432,8 +410,8 @@ protected:
|
||||
ECOLOR_FORMAT Format;
|
||||
core::dimension2d<u32> Size;
|
||||
|
||||
u8* Data;
|
||||
u8* MipMapsData;
|
||||
u8 *Data;
|
||||
u8 *MipMapsData;
|
||||
|
||||
u32 BytesPerPixel;
|
||||
u32 Pitch;
|
||||
@ -442,6 +420,5 @@ protected:
|
||||
bool DeleteMipMapsMemory;
|
||||
};
|
||||
|
||||
|
||||
} // end namespace video
|
||||
} // end namespace irr
|
||||
|
Reference in New Issue
Block a user