Skip to content

Commit

Permalink
Merge pull request #554 from IENT/feature/DetectRGBAExtensions
Browse files Browse the repository at this point in the history
Add rgba extensions to open as RGB files.
  • Loading branch information
ChristianFeldmann authored Dec 15, 2023
2 parents 62f9f4e + 7424b4a commit 844a97f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion YUViewLib/src/common/Typedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
};
Expand Down
37 changes: 26 additions & 11 deletions YUViewLib/src/playlistitem/playlistItemRawFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(const QString &testValue, const std::initializer_list<const char *> &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,
Expand Down Expand Up @@ -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<video::yuv::videoHandlerYUV>();
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<video::rgb::videoHandlerRGB>();
this->rawFormat = video::RawFormat::RGB;
Expand Down Expand Up @@ -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)");
}

Expand Down

0 comments on commit 844a97f

Please sign in to comment.