Renamed GetBPP to GetBytesPerPixel

Also added GetBitsPerPixel


Former-commit-id: 9cc1df58133c538b1dc74215a9022d13dfd9d7f6
This commit is contained in:
Lynix
2012-09-30 23:11:00 +02:00
parent 49ac00f28d
commit 8d057fb3b1
6 changed files with 73 additions and 62 deletions

View File

@@ -66,7 +66,7 @@ class NAZARA_API NzImage : public NzResource
bool FlipHorizontally();
bool FlipVertically();
nzUInt8 GetBPP() const;
nzUInt8 GetBytesPerPixel() const;
const nzUInt8* GetConstPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, nzUInt8 level = 0) const;
unsigned int GetDepth(nzUInt8 level = 0) const;
nzPixelFormat GetFormat() const;

View File

@@ -27,7 +27,8 @@ class NzPixelFormat
static bool Flip(nzPixelFlipping flipping, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst);
static nzUInt8 GetBPP(nzPixelFormat format);
static nzUInt8 GetBitsPerPixel(nzPixelFormat format);
static nzUInt8 GetBytesPerPixel(nzPixelFormat format);
static nzPixelFormatType GetType(nzPixelFormat format);
static bool HasAlpha(nzPixelFormat format);

View File

@@ -10,7 +10,7 @@ inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFor
{
if (srcFormat == dstFormat)
{
std::memcpy(dst, src, GetBPP(srcFormat));
std::memcpy(dst, src, GetBytesPerPixel(srcFormat));
return true;
}
@@ -35,7 +35,7 @@ inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFor
return false;
}
if (!func(reinterpret_cast<const nzUInt8*>(src), reinterpret_cast<const nzUInt8*>(src) + GetBPP(srcFormat), reinterpret_cast<nzUInt8*>(dst)))
if (!func(reinterpret_cast<const nzUInt8*>(src), reinterpret_cast<const nzUInt8*>(src) + GetBytesPerPixel(srcFormat), reinterpret_cast<nzUInt8*>(dst)))
{
NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed");
return false;
@@ -93,7 +93,7 @@ inline bool NzPixelFormat::Flip(nzPixelFlipping flipping, nzPixelFormat format,
}
#endif
nzUInt8 bpp = GetBPP(format);
nzUInt8 bpp = GetBytesPerPixel(format);
unsigned int lineStride = width*bpp;
switch (flipping)
{
@@ -164,93 +164,91 @@ inline bool NzPixelFormat::Flip(nzPixelFlipping flipping, nzPixelFormat format,
return true;
}
inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format)
inline nzUInt8 NzPixelFormat::GetBitsPerPixel(nzPixelFormat format)
{
switch (format)
{
case nzPixelFormat_BGR8:
return 3;
return 24;
case nzPixelFormat_BGRA8:
return 4;
return 32;
case nzPixelFormat_DXT1:
return 1;
return 8;
case nzPixelFormat_DXT3:
return 2;
return 16;
case nzPixelFormat_DXT5:
return 2;
return 16;
case nzPixelFormat_L8:
return 1;
return 8;
case nzPixelFormat_LA8:
return 2;
return 16;
/*
case nzPixelFormat_RGB16F:
return 6;
return 48;
case nzPixelFormat_RGB16I:
return 6;
return 48;
case nzPixelFormat_RGB32F:
return 12;
return 96;
case nzPixelFormat_RGB32I:
return 12;
return 96;
case nzPixelFormat_RGBA16F:
return 8;
return 64;
case nzPixelFormat_RGBA16I:
return 8;
return 64;
case nzPixelFormat_RGBA32F:
return 16;
return 128;
case nzPixelFormat_RGBA32I:
return 16;
return 128;
*/
case nzPixelFormat_RGBA4:
return 2;
return 16;
case nzPixelFormat_RGB5A1:
return 2;
return 16;
case nzPixelFormat_RGB8:
return 3;
return 24;
case nzPixelFormat_RGBA8:
return 4;
return 32;
case nzPixelFormat_Depth16:
return 2;
return 16;
case nzPixelFormat_Depth24:
return 3;
return 24;
case nzPixelFormat_Depth24Stencil8:
return 4;
return 32;
case nzPixelFormat_Depth32:
return 4;
return 32;
case nzPixelFormat_Stencil1:
NazaraWarning("This format uses less than one byte per pixel");
return 0;
case nzPixelFormat_Stencil4:
NazaraWarning("This format uses less than one byte per pixel");
return 0;
case nzPixelFormat_Stencil8:
return 1;
case nzPixelFormat_Stencil16:
case nzPixelFormat_Stencil4:
return 2;
case nzPixelFormat_Stencil8:
return 8;
case nzPixelFormat_Stencil16:
return 16;
case nzPixelFormat_Undefined:
break;
}
@@ -259,6 +257,18 @@ inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format)
return 0;
}
inline nzUInt8 NzPixelFormat::GetBytesPerPixel(nzPixelFormat format)
{
nzUInt8 bytesPerPixel = GetBitsPerPixel(format)/8;
#if NAZARA_UTILITY_SAFE
if (bytesPerPixel == 0)
NazaraWarning("This format is invalid or uses less than one byte per pixel");
#endif
return bytesPerPixel;
}
inline nzPixelFormatType NzPixelFormat::GetType(nzPixelFormat format)
{
switch (format)