Utility/PixelFormat: Add ComputeSize method

Former-commit-id: 8d9017541a812c98ba96c694cbd10da895338d1d
This commit is contained in:
Lynix
2016-04-21 13:21:39 +02:00
parent d6112c99f4
commit e5f5d7ed11
4 changed files with 44 additions and 12 deletions

View File

@@ -131,7 +131,7 @@ namespace Nz
Image& operator=(const Image& image);
static void Copy(UInt8* destination, const UInt8* source, UInt8 bpp, unsigned int width, unsigned int height, unsigned int depth = 1, unsigned int dstWidth = 0, unsigned int dstHeight = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0);
static void Copy(UInt8* destination, const UInt8* source, PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth = 1, unsigned int dstWidth = 0, unsigned int dstHeight = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0);
static UInt8 GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth = 1);
static UInt8 GetMaxLevel(ImageType type, unsigned int width, unsigned int height, unsigned int depth = 1);
template<typename... Args> static ImageRef New(Args&&... args);

View File

@@ -28,6 +28,8 @@ namespace Nz
using ConvertFunction = std::function<UInt8*(const UInt8* start, const UInt8* end, UInt8* dst)>;
using FlipFunction = std::function<void(unsigned int width, unsigned int height, unsigned int depth, const UInt8* src, UInt8* dst)>;
static inline std::size_t ComputeSize(PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth);
static bool Convert(PixelFormatType srcFormat, PixelFormatType dstFormat, const void* src, void* dst);
static bool Convert(PixelFormatType srcFormat, PixelFormatType dstFormat, const void* start, const void* end, void* dst);

View File

@@ -9,6 +9,26 @@
namespace Nz
{
inline std::size_t PixelFormat::ComputeSize(PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth)
{
if (IsCompressed(format))
{
switch (format)
{
case PixelFormatType_DXT1:
case PixelFormatType_DXT3:
case PixelFormatType_DXT5:
return (((width + 3) / 4) * ((height + 3) / 4) * (format == PixelFormatType_DXT1) ? 8 : 16) * depth;
default:
NazaraError("Unsupported format");
return 0;
}
}
else
return width * height * depth * GetBytesPerPixel(format);
}
inline bool PixelFormat::Convert(PixelFormatType srcFormat, PixelFormatType dstFormat, const void* src, void* dst)
{
if (srcFormat == dstFormat)