From 663cf4a02045954553eb59a739270a44f2272170 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Thu, 11 Jun 2020 21:27:42 +1000 Subject: [PATCH] pixelformat: added convenience functions for determining the format equivalent with and without an alpha channel --- app/render/pixelformat.cpp | 46 ++++++++++++++++++++++++++++++++++++++ app/render/pixelformat.h | 3 +++ 2 files changed, 49 insertions(+) diff --git a/app/render/pixelformat.cpp b/app/render/pixelformat.cpp index 33cc531b5..4c1ee999d 100644 --- a/app/render/pixelformat.cpp +++ b/app/render/pixelformat.cpp @@ -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; diff --git a/app/render/pixelformat.h b/app/render/pixelformat.h index 82388df6a..cb7c53fae 100644 --- a/app/render/pixelformat.h +++ b/app/render/pixelformat.h @@ -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. *