diff options
author | Alwin Esch <alwin.esch@web.de> | 2021-11-07 23:33:42 +0100 |
---|---|---|
committer | Alwin Esch <alwin.esch@web.de> | 2021-12-29 22:44:27 +0100 |
commit | b3ecd41a28ed56864ccd032b632105bba0cedcff (patch) | |
tree | 678a9326c8b3e26bd9916520db47a95625ebfe07 | |
parent | f820528665cd622fa614e069f9efb7e2ddb25999 (diff) |
[addons][imagedecoder] Read color size from KodiToAddonFormat
Previously this was done using switch / case, but since there is already a list, it is now moved to there and done together with the conversion of the Kodi format to the add-on format.
In addition, the values have been changed to "const" because there are no more changes to them anyway.
-rw-r--r-- | xbmc/addons/ImageDecoder.cpp | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/xbmc/addons/ImageDecoder.cpp b/xbmc/addons/ImageDecoder.cpp index 45aa0b4dc4..ee706a7eb0 100644 --- a/xbmc/addons/ImageDecoder.cpp +++ b/xbmc/addons/ImageDecoder.cpp @@ -16,11 +16,11 @@ using namespace KODI::ADDONS; namespace { -constexpr std::array<std::pair<unsigned int, ADDON_IMG_FMT>, 4> KodiToAddonFormat = { - {{XB_FMT_A8R8G8B8, ADDON_IMG_FMT_A8R8G8B8}, - {XB_FMT_A8, ADDON_IMG_FMT_A8}, - {XB_FMT_RGBA8, ADDON_IMG_FMT_RGBA8}, - {XB_FMT_RGB8, ADDON_IMG_FMT_RGB8}}}; +constexpr std::array<std::tuple<unsigned int, ADDON_IMG_FMT, size_t>, 4> KodiToAddonFormat = { + {{XB_FMT_A8R8G8B8, ADDON_IMG_FMT_A8R8G8B8, sizeof(uint8_t) * 4}, + {XB_FMT_A8, ADDON_IMG_FMT_A8, sizeof(uint8_t) * 1}, + {XB_FMT_RGBA8, ADDON_IMG_FMT_RGBA8, sizeof(uint8_t) * 4}, + {XB_FMT_RGB8, ADDON_IMG_FMT_RGB8, sizeof(uint8_t) * 3}}}; static char* cb_get_mime_type(KODI_HANDLE kodiInstance) { @@ -199,29 +199,15 @@ bool CImageDecoder::Decode(unsigned char* const pixels, if (!m_ifc.imagedecoder->toAddon->decode) return false; - auto it = std::find_if(KodiToAddonFormat.begin(), KodiToAddonFormat.end(), - [format](auto& p) { return p.first == format; }); + const auto it = std::find_if(KodiToAddonFormat.begin(), KodiToAddonFormat.end(), + [format](auto& p) { return std::get<0>(p) == format; }); if (it == KodiToAddonFormat.end()) return false; - size_t size; - switch (format) - { - case XB_FMT_A8: - size = width * height * sizeof(uint8_t) * 1; - break; - case XB_FMT_RGB8: - size = width * height * sizeof(uint8_t) * 3; - break; - case XB_FMT_A8R8G8B8: - case XB_FMT_RGBA8: - default: - size = width * height * sizeof(uint8_t) * 4; - break; - } - - bool result = m_ifc.imagedecoder->toAddon->decode(m_ifc.hdl, pixels, size, width, height, pitch, - it->second); + const ADDON_IMG_FMT addonFmt = std::get<1>(*it); + const size_t size = width * height * std::get<2>(*it); + const bool result = + m_ifc.imagedecoder->toAddon->decode(m_ifc.hdl, pixels, size, width, height, pitch, addonFmt); m_width = width; m_height = height; |