Added A8 pixel format

PixelFormat::GetBytesPerPixel() will no longer warn with
less-than-one-byte formats

Former-commit-id: af41f0c2bc7a35c2ee617980878628ff1c8bf868
This commit is contained in:
Lynix 2014-12-07 03:09:39 +01:00
parent 4b2e3370d9
commit d22c4a5ac9
5 changed files with 121 additions and 19 deletions

View File

@ -130,6 +130,7 @@ enum nzPixelFormat
{
nzPixelFormat_Undefined = -1,
nzPixelFormat_A8, // 1*uint8
nzPixelFormat_BGR8, // 3*uint8
nzPixelFormat_BGRA8, // 4*uint8
nzPixelFormat_DXT1,

View File

@ -168,6 +168,9 @@ inline nzUInt8 NzPixelFormat::GetBitsPerPixel(nzPixelFormat format)
{
switch (format)
{
case nzPixelFormat_A8:
return 8;
case nzPixelFormat_BGR8:
return 24;
@ -287,20 +290,14 @@ inline nzUInt8 NzPixelFormat::GetBitsPerPixel(nzPixelFormat format)
inline nzUInt8 NzPixelFormat::GetBytesPerPixel(nzPixelFormat format)
{
nzUInt8 bytesPerPixel = GetBitsPerPixel(format)/8;
#if NAZARA_UTILITY_SAFE
if (bytesPerPixel == 0)
NazaraWarning("This format is either invalid or using less than one byte per pixel");
#endif
return bytesPerPixel;
return GetBitsPerPixel(format)/8;
}
inline nzPixelFormatType NzPixelFormat::GetType(nzPixelFormat format)
{
switch (format)
{
case nzPixelFormat_A8:
case nzPixelFormat_BGR8:
case nzPixelFormat_BGRA8:
case nzPixelFormat_DXT1:
@ -372,6 +369,7 @@ inline bool NzPixelFormat::HasAlpha(nzPixelFormat format)
{
switch (format)
{
case nzPixelFormat_A8:
case nzPixelFormat_BGRA8:
case nzPixelFormat_DXT3:
case nzPixelFormat_DXT5:
@ -444,6 +442,7 @@ inline bool NzPixelFormat::IsCompressed(nzPixelFormat format)
case nzPixelFormat_DXT5:
return true;
case nzPixelFormat_A8:
case nzPixelFormat_BGR8:
case nzPixelFormat_BGRA8:
case nzPixelFormat_L8:
@ -529,6 +528,9 @@ inline NzString NzPixelFormat::ToString(nzPixelFormat format)
{
switch (format)
{
case nzPixelFormat_A8:
return "A8";
case nzPixelFormat_BGR8:
return "BGR8";

View File

@ -1465,6 +1465,9 @@ bool NzOpenGL::TranslateFormat(nzPixelFormat pixelFormat, Format* format, Format
{
switch (pixelFormat)
{
case nzPixelFormat_A8:
return false; ///FIXME: Tester le mode d'OpenGL pour se permettre une fonctionnalité dépréciée ?
case nzPixelFormat_BGR8:
format->dataFormat = GL_BGR;
format->dataType = GL_UNSIGNED_BYTE;

View File

@ -1272,6 +1272,13 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format)
case nzPixelFormat_RGBA32UI:
return NzOpenGL::GetVersion() >= 300;
// Dépréciés depuis OpenGL 3
///FIXME: Accepter si le contexte OpenGL est de compatibilité/OpenGL 2 ?
case nzPixelFormat_A8:
case nzPixelFormat_L8:
case nzPixelFormat_LA8:
return false;
// Formats de profondeur (Supportés avec les FBOs)
case nzPixelFormat_Depth16:
case nzPixelFormat_Depth24:
@ -1286,12 +1293,7 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format)
case nzPixelFormat_Stencil16:
return false;
// Dépréciés depuis OpenGL 3
///FIXME: Il doit bien exister des remplaçants (GL_RED ?)
case nzPixelFormat_L8:
case nzPixelFormat_LA8:
return false;
// Formats compressés
case nzPixelFormat_DXT1:
case nzPixelFormat_DXT3:
case nzPixelFormat_DXT5:
@ -1302,7 +1304,6 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format)
}
NazaraError("Invalid pixel format");
return false;
}

View File

@ -50,6 +50,94 @@ namespace
return nullptr;
}
/**********************************A8***********************************/
template<>
nzUInt8* ConvertPixels<nzPixelFormat_A8, nzPixelFormat_BGRA8>(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst)
{
while (start < end)
{
*dst++ = 0xFF;
*dst++ = 0xFF;
*dst++ = 0xFF;
*dst++ = *start;
start += 1;
}
return dst;
}
template<>
nzUInt8* ConvertPixels<nzPixelFormat_A8, nzPixelFormat_LA8>(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst)
{
while (start < end)
{
*dst++ = 0xFF;
*dst++ = *start;
start += 1;
}
return dst;
}
template<>
nzUInt8* ConvertPixels<nzPixelFormat_A8, nzPixelFormat_RGB5A1>(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst)
{
nzUInt16* ptr = reinterpret_cast<nzUInt16*>(dst);
while (start < end)
{
*ptr = (static_cast<nzUInt16>(c8to5(start[2])) << 11) |
(static_cast<nzUInt16>(c8to5(start[1])) << 6) |
(static_cast<nzUInt16>(c8to5(start[0])) << 1) |
((*start > 0xF) ? 1 : 0); // > 128
#ifdef NAZARA_BIG_ENDIAN
NzByteSwap(ptr, sizeof(nzUInt16));
#endif
ptr++;
start += 1;
}
return reinterpret_cast<nzUInt8*>(ptr);
}
template<>
nzUInt8* ConvertPixels<nzPixelFormat_A8, nzPixelFormat_RGBA4>(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst)
{
nzUInt16* ptr = reinterpret_cast<nzUInt16*>(dst);
while (start < end)
{
*ptr = 0xFFF0 | c8to4(*start);
#ifdef NAZARA_BIG_ENDIAN
NzByteSwap(ptr, sizeof(nzUInt16));
#endif
ptr++;
start += 1;
}
return dst;
}
template<>
nzUInt8* ConvertPixels<nzPixelFormat_A8, nzPixelFormat_RGBA8>(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst)
{
while (start < end)
{
*dst++ = 0xFF;
*dst++ = 0xFF;
*dst++ = 0xFF;
*dst++ = *start;
start += 1;
}
return dst;
}
/**********************************BGR8***********************************/
template<>
nzUInt8* ConvertPixels<nzPixelFormat_BGR8, nzPixelFormat_BGRA8>(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst)
@ -243,7 +331,7 @@ namespace
*ptr = (static_cast<nzUInt16>(c8to5(start[2])) << 11) |
(static_cast<nzUInt16>(c8to5(start[1])) << 6) |
(static_cast<nzUInt16>(c8to5(start[0])) << 1) |
((start[3] == 0xFF) ? 1 : 0);
((start[3] > 0xF) ? 1 : 0); // > 128
#ifdef NAZARA_BIG_ENDIAN
NzByteSwap(ptr, sizeof(nzUInt16));
@ -465,7 +553,7 @@ namespace
{
nzUInt16 l = static_cast<nzUInt16>(c8to5(start[0]));
*ptr = (l << 11) | (l << 6) | (l << 1) | ((start[1] == 0xFF) ? 1 : 0);
*ptr = (l << 11) | (l << 6) | (l << 1) | ((start[1] > 0xF) ? 1 : 0);
#ifdef NAZARA_BIG_ENDIAN
NzByteSwap(ptr, sizeof(nzUInt16));
@ -638,7 +726,7 @@ namespace
nzUInt16 b = c4to5((pixel & 0x00F0) >> 4);
nzUInt16 a = c4to5((pixel & 0x000F) >> 0);
*ptr = (r << 11) | (g << 6) | (b << 1) | ((a == 0xFF) ? 1 : 0);
*ptr = (r << 11) | (g << 6) | (b << 1) | ((a > 0x3) ? 1 : 0);
#ifdef NAZARA_BIG_ENDIAN
NzByteSwap(ptr, sizeof(nzUInt16));
@ -1044,7 +1132,7 @@ namespace
*ptr = (static_cast<nzUInt16>(c8to5(start[0])) << 11) |
(static_cast<nzUInt16>(c8to5(start[1])) << 6) |
(static_cast<nzUInt16>(c8to5(start[2])) << 1) |
((start[3] == 0xFF) ? 1 : 0);
((start[3] > 0xF) ? 1 : 0); // > 128
#ifdef NAZARA_BIG_ENDIAN
NzByteSwap(ptr, sizeof(nzUInt16));
@ -1106,6 +1194,13 @@ bool NzPixelFormat::Initialize()
// Réinitialisation
std::memset(s_convertFunctions, 0, (nzPixelFormat_Max+1)*(nzPixelFormat_Max+1)*sizeof(NzPixelFormat::ConvertFunction));
/***********************************A8************************************/
RegisterConverter<nzPixelFormat_A8, nzPixelFormat_BGRA8>();
RegisterConverter<nzPixelFormat_A8, nzPixelFormat_LA8>();
RegisterConverter<nzPixelFormat_A8, nzPixelFormat_RGB5A1>();
RegisterConverter<nzPixelFormat_A8, nzPixelFormat_RGBA4>();
RegisterConverter<nzPixelFormat_A8, nzPixelFormat_RGBA8>();
/**********************************BGR8***********************************/
RegisterConverter<nzPixelFormat_BGR8, nzPixelFormat_BGRA8>();
RegisterConverter<nzPixelFormat_BGR8, nzPixelFormat_L8>();