From 6fc7365e5dd345aa7ff619272ad1aed45b00d3de Mon Sep 17 00:00:00 2001 From: Christian Feldmann Date: Fri, 15 Dec 2023 14:15:08 +0100 Subject: [PATCH 1/2] Add rgba extensions to open as RGB files. --- YUViewLib/src/common/Typedef.h | 2 +- .../src/playlistitem/playlistItemRawFile.cpp | 37 +++++++++++++------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/YUViewLib/src/common/Typedef.h b/YUViewLib/src/common/Typedef.h index 12a44b90c..23fbf0334 100644 --- a/YUViewLib/src/common/Typedef.h +++ b/YUViewLib/src/common/Typedef.h @@ -273,7 +273,7 @@ struct Size { return this->width != other.width || this->height != other.height; } - constexpr bool isValid() const { return this->width != 0 && this->height != 0; } + constexpr bool isValid() const { return this->width > 0 && this->height > 0; } unsigned width{}; unsigned height{}; }; diff --git a/YUViewLib/src/playlistitem/playlistItemRawFile.cpp b/YUViewLib/src/playlistitem/playlistItemRawFile.cpp index d4f409a62..7ff5fee23 100644 --- a/YUViewLib/src/playlistitem/playlistItemRawFile.cpp +++ b/YUViewLib/src/playlistitem/playlistItemRawFile.cpp @@ -48,6 +48,24 @@ #define DEBUG_RAWFILE(f) ((void)0) #endif +namespace +{ + +constexpr auto YUV_EXTENSIONS = {"yuv", "nv12", "y4m"}; +constexpr auto RGB_EXTENSIONS = {"rgb", "gbr", "bgr", "brg"}; +constexpr auto RGBA_EXTENSIONS = {"rgba", "gbra", "bgra", "brga", "argb", "agbr", "abgr", "abrg"}; + +bool isInExtensions(QString testValue, std::initializer_list extensions) +{ + const auto it = + std::find_if(extensions.begin(), extensions.end(), [testValue](const char *extension) { + return QString(extension) == testValue; + }); + return it != extensions.end(); +} + +} // namespace + playlistItemRawFile::playlistItemRawFile(const QString &rawFilePath, const QSize qFrameSize, const QString &sourcePixelFormat, @@ -77,12 +95,13 @@ playlistItemRawFile::playlistItemRawFile(const QString &rawFilePath, QFileInfo fi(rawFilePath); QString ext = fi.suffix(); ext = ext.toLower(); - if (ext == "yuv" || ext == "nv21" || fmt.toLower() == "yuv" || ext == "y4m") + if (isInExtensions(ext, YUV_EXTENSIONS) || fmt.toLower() == "yuv") { this->video = std::make_unique(); this->rawFormat = video::RawFormat::YUV; } - else if (ext == "rgb" || ext == "gbr" || ext == "bgr" || ext == "brg" || fmt.toLower() == "rgb") + else if (isInExtensions(ext, RGB_EXTENSIONS) || isInExtensions(ext, RGBA_EXTENSIONS) || + fmt.toLower() == "rgb") { this->video = std::make_unique(); this->rawFormat = video::RawFormat::RGB; @@ -550,18 +569,14 @@ ValuePairListSets playlistItemRawFile::getPixelValues(const QPoint &pixelPos, in void playlistItemRawFile::getSupportedFileExtensions(QStringList &allExtensions, QStringList &filters) { - allExtensions.append("yuv"); - allExtensions.append("rgb"); - allExtensions.append("rbg"); - allExtensions.append("grb"); - allExtensions.append("gbr"); - allExtensions.append("brg"); - allExtensions.append("bgr"); - allExtensions.append("nv21"); - allExtensions.append("y4m"); + for (const auto extensionsList : {YUV_EXTENSIONS, RGB_EXTENSIONS, RGBA_EXTENSIONS}) + for (const auto &extension : extensionsList) + allExtensions.append(QString(extension)); filters.append("Raw YUV File (*.yuv *.nv21)"); filters.append("Raw RGB File (*.rgb *.rbg *.grb *.gbr *.brg *.bgr)"); + filters.append("Raw RGBA File (*.rgba *.rbga *.grba *.gbra *.brga *.bgra *.argb *.arbg *.agrb " + "*.agbr *.abrg *.abgr)"); filters.append("YUV4MPEG2 File (*.y4m)"); } From 7424b4aad8dbf444f1920c17555f98ae03555da5 Mon Sep 17 00:00:00 2001 From: Christian Feldmann Date: Fri, 15 Dec 2023 14:21:54 +0100 Subject: [PATCH 2/2] Add some const --- YUViewLib/src/playlistitem/playlistItemRawFile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/YUViewLib/src/playlistitem/playlistItemRawFile.cpp b/YUViewLib/src/playlistitem/playlistItemRawFile.cpp index 7ff5fee23..0d586e683 100644 --- a/YUViewLib/src/playlistitem/playlistItemRawFile.cpp +++ b/YUViewLib/src/playlistitem/playlistItemRawFile.cpp @@ -55,7 +55,7 @@ constexpr auto YUV_EXTENSIONS = {"yuv", "nv12", "y4m"}; constexpr auto RGB_EXTENSIONS = {"rgb", "gbr", "bgr", "brg"}; constexpr auto RGBA_EXTENSIONS = {"rgba", "gbra", "bgra", "brga", "argb", "agbr", "abgr", "abrg"}; -bool isInExtensions(QString testValue, std::initializer_list extensions) +bool isInExtensions(const QString &testValue, const std::initializer_list &extensions) { const auto it = std::find_if(extensions.begin(), extensions.end(), [testValue](const char *extension) { @@ -569,7 +569,7 @@ ValuePairListSets playlistItemRawFile::getPixelValues(const QPoint &pixelPos, in void playlistItemRawFile::getSupportedFileExtensions(QStringList &allExtensions, QStringList &filters) { - for (const auto extensionsList : {YUV_EXTENSIONS, RGB_EXTENSIONS, RGBA_EXTENSIONS}) + for (const auto &extensionsList : {YUV_EXTENSIONS, RGB_EXTENSIONS, RGBA_EXTENSIONS}) for (const auto &extension : extensionsList) allExtensions.append(QString(extension));