pixelformat: added convenience functions for determining the format equivalent with and without an alpha channel

This commit is contained in:
itsmattkc
2020-06-11 21:27:42 +10:00
parent 23d92df3c8
commit 663cf4a020
2 changed files with 49 additions and 0 deletions
+46
View File
@@ -164,6 +164,52 @@ PixelFormat::Format PixelFormat::OIIOFormatToOliveFormat(OIIO::TypeDesc desc, bo
return PixelFormat::PIX_FMT_INVALID;
}
PixelFormat::Format PixelFormat::GetFormatWithAlphaChannel(PixelFormat::Format f)
{
switch (f) {
case PIX_FMT_INVALID:
case PIX_FMT_COUNT:
break;
case PIX_FMT_RGB8:
case PIX_FMT_RGBA8:
return PIX_FMT_RGBA8;
case PIX_FMT_RGB16U:
case PIX_FMT_RGBA16U:
return PIX_FMT_RGBA16U;
case PIX_FMT_RGB16F:
case PIX_FMT_RGBA16F:
return PIX_FMT_RGBA16F;
case PIX_FMT_RGB32F:
case PIX_FMT_RGBA32F:
return PIX_FMT_RGBA32F;
}
return PIX_FMT_INVALID;
}
PixelFormat::Format PixelFormat::GetFormatWithoutAlphaChannel(PixelFormat::Format f)
{
switch (f) {
case PIX_FMT_INVALID:
case PIX_FMT_COUNT:
break;
case PIX_FMT_RGB8:
case PIX_FMT_RGBA8:
return PIX_FMT_RGB8;
case PIX_FMT_RGB16U:
case PIX_FMT_RGBA16U:
return PIX_FMT_RGB16U;
case PIX_FMT_RGB16F:
case PIX_FMT_RGBA16F:
return PIX_FMT_RGB16F;
case PIX_FMT_RGB32F:
case PIX_FMT_RGBA32F:
return PIX_FMT_RGB32F;
}
return PIX_FMT_INVALID;
}
int PixelFormat::GetBufferSize(const PixelFormat::Format &format, const int &width, const int &height)
{
return BytesPerPixel(format) * width * height;
+3
View File
@@ -68,6 +68,9 @@ public:
static Format OIIOFormatToOliveFormat(OIIO::TypeDesc desc, bool has_alpha);
static Format GetFormatWithAlphaChannel(Format f);
static Format GetFormatWithoutAlphaChannel(Format f);
/**
* @brief Returns the minimum buffer size (in bytes) necessary for a given format, width, and height.
*