From 75be054b7f191a5d7f50e6044aa0d5afccd356f8 Mon Sep 17 00:00:00 2001 From: for13to1 Date: Tue, 7 May 2024 07:00:41 +0000 Subject: [PATCH 1/2] support openning Bayer raw file as gray YUV raw file --- YUViewLib/src/playlistitem/playlistItemRawFile.cpp | 6 ++++-- YUViewLib/src/video/yuv/PixelFormatYUV.cpp | 8 ++++---- YUViewLib/src/video/yuv/PixelFormatYUV.h | 2 +- YUViewLib/src/video/yuv/PixelFormatYUVGuess.cpp | 7 +++++++ YUViewLib/src/video/yuv/videoHandlerYUV.h | 4 ++-- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/YUViewLib/src/playlistitem/playlistItemRawFile.cpp b/YUViewLib/src/playlistitem/playlistItemRawFile.cpp index 10e96bcfd..9d019150f 100644 --- a/YUViewLib/src/playlistitem/playlistItemRawFile.cpp +++ b/YUViewLib/src/playlistitem/playlistItemRawFile.cpp @@ -54,6 +54,7 @@ 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"}; +constexpr auto RAW_EXTENSIONS = {"raw",}; bool isInExtensions(const QString &testValue, const std::initializer_list &extensions) { @@ -94,7 +95,7 @@ playlistItemRawFile::playlistItemRawFile(const QString &rawFilePath, // Create a new videoHandler instance depending on the input format QFileInfo fi(rawFilePath); const auto ext = fi.suffix().toLower(); - if (isInExtensions(ext, YUV_EXTENSIONS) || fmt.toLower() == "yuv") + if (isInExtensions(ext, YUV_EXTENSIONS) || isInExtensions(ext, RAW_EXTENSIONS) || fmt.toLower() == "yuv") { this->video = std::make_unique(); this->rawFormat = video::RawFormat::YUV; @@ -568,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, RAW_EXTENSIONS}) for (const auto &extension : extensionsList) allExtensions.append(QString(extension)); @@ -577,6 +578,7 @@ void playlistItemRawFile::getSupportedFileExtensions(QStringList &allExtensions, filters.append("Raw RGBA File (*.rgba *.rbga *.grba *.gbra *.brga *.bgra *.argb *.arbg *.agrb " "*.agbr *.abrg *.abgr)"); filters.append("YUV4MPEG2 File (*.y4m)"); + filters.append("Bayer Raw File (*.raw)"); } void playlistItemRawFile::reloadItemSource() diff --git a/YUViewLib/src/video/yuv/PixelFormatYUV.cpp b/YUViewLib/src/video/yuv/PixelFormatYUV.cpp index dbb40fc89..de214dd48 100644 --- a/YUViewLib/src/video/yuv/PixelFormatYUV.cpp +++ b/YUViewLib/src/video/yuv/PixelFormatYUV.cpp @@ -44,11 +44,11 @@ void getColorConversionCoefficients(ColorConversion colorConversion, int RGBConv // cGV, cBU]. const int yuvRgbConvCoeffs[6][5] = { {76309, 117489, -13975, -34925, 138438}, // BT709_LimitedRange - {65536, 103206, -12276, -30679, 121608}, // BT709_FullRange + {65536, 103206, -12276, -30679, 121609}, // BT709_FullRange {76309, 104597, -25675, -53279, 132201}, // BT601_LimitedRange - {65536, 91881, -22553, -46802, 116129}, // BT601_FullRange - {76309, 110013, -12276, -42626, 140363}, // BT2020_LimitedRange - {65536, 96638, -10783, -37444, 123299} // BT2020_FullRange + {65536, 91881, -22553, -46802, 116130}, // BT601_FullRange + {76309, 110014, -12277, -42626, 140363}, // BT2020_LimitedRange + {65536, 96639, -10784, -37444, 123299} // BT2020_FullRange }; const auto index = ColorConversionMapper.indexOf(colorConversion); for (unsigned i = 0; i < 5; i++) diff --git a/YUViewLib/src/video/yuv/PixelFormatYUV.h b/YUViewLib/src/video/yuv/PixelFormatYUV.h index aa560b23f..11cb2a8fe 100644 --- a/YUViewLib/src/video/yuv/PixelFormatYUV.h +++ b/YUViewLib/src/video/yuv/PixelFormatYUV.h @@ -55,7 +55,7 @@ R = Y + V*(1-Kr) G = Y - U*(1-Kb)*Kb/Kg - V*(1-Kr)*Kr/Kg B = Y + U*(1-Kb) To respect value range of Y in [16:235] and U/V in [16:240], the matrix entries need to be scaled -by 255/219 for Y and 255/112 for U/V In this software color conversion is performed with 16bit +by 255/219 for Y and 255/224 for U/V In this software color conversion is performed with 16bit precision. Thus, further scaling with 2^16 is performed to get all factors as integers. */ enum class ColorConversion diff --git a/YUViewLib/src/video/yuv/PixelFormatYUVGuess.cpp b/YUViewLib/src/video/yuv/PixelFormatYUVGuess.cpp index 513073d92..8924f2f0a 100644 --- a/YUViewLib/src/video/yuv/PixelFormatYUVGuess.cpp +++ b/YUViewLib/src/video/yuv/PixelFormatYUVGuess.cpp @@ -249,6 +249,13 @@ PixelFormatYUV guessFormatFromSizeAndName(const Size size, return fmt; } + if (fileInfo.suffix().toLower() == "raw") + { + auto fmt = PixelFormatYUV(Subsampling::YUV_400, bitDepth, PlaneOrder::YUV, false, {}, true); + if (checkFormat(fmt, size, fileSize)) + return fmt; + } + for (const auto &name : {fileName, dirName}) { // Check if the filename contains NV12 diff --git a/YUViewLib/src/video/yuv/videoHandlerYUV.h b/YUViewLib/src/video/yuv/videoHandlerYUV.h index a3bc8faff..bd6d9208a 100644 --- a/YUViewLib/src/video/yuv/videoHandlerYUV.h +++ b/YUViewLib/src/video/yuv/videoHandlerYUV.h @@ -63,9 +63,9 @@ const auto ComponentDisplayModeMapper = struct ConversionSettings { - ChromaInterpolation chromaInterpolation{ChromaInterpolation::NearestNeighbor}; + ChromaInterpolation chromaInterpolation{ChromaInterpolation::Bilinear}; ComponentDisplayMode componentDisplayMode{ComponentDisplayMode::DisplayAll}; - ColorConversion colorConversion{ColorConversion::BT709_LimitedRange}; + ColorConversion colorConversion{ColorConversion::BT709_FullRange}; // Parameters for the YUV transformation (like scaling, invert, offset). For Luma ([0]) and // chroma([1]). std::map mathParameters; From a05bbcac23e23ed3b876bdd81f7a29c26d94cf18 Mon Sep 17 00:00:00 2001 From: for13to1 Date: Fri, 17 May 2024 00:53:00 +0800 Subject: [PATCH 2/2] support openning raw CMYK as RGBA file --- YUViewLib/src/playlistitem/playlistItemRawFile.cpp | 8 +++++--- YUViewLib/src/video/rgb/PixelFormatRGBGuess.cpp | 10 ++++++++++ YUViewLib/src/video/yuv/videoHandlerYUV.h | 4 ++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/YUViewLib/src/playlistitem/playlistItemRawFile.cpp b/YUViewLib/src/playlistitem/playlistItemRawFile.cpp index 9d019150f..84142c5bf 100644 --- a/YUViewLib/src/playlistitem/playlistItemRawFile.cpp +++ b/YUViewLib/src/playlistitem/playlistItemRawFile.cpp @@ -55,6 +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"}; constexpr auto RAW_EXTENSIONS = {"raw",}; +constexpr auto CMYK_EXTENSIONS = {"cmyk",}; bool isInExtensions(const QString &testValue, const std::initializer_list &extensions) { @@ -100,7 +101,7 @@ playlistItemRawFile::playlistItemRawFile(const QString &rawFilePath, this->video = std::make_unique(); this->rawFormat = video::RawFormat::YUV; } - else if (isInExtensions(ext, RGB_EXTENSIONS) || isInExtensions(ext, RGBA_EXTENSIONS) || + else if (isInExtensions(ext, RGB_EXTENSIONS) || isInExtensions(ext, RGBA_EXTENSIONS) || isInExtensions(ext, CMYK_EXTENSIONS) || fmt.toLower() == "rgb") { this->video = std::make_unique(); @@ -569,7 +570,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, RAW_EXTENSIONS}) + for (const auto &extensionsList : {YUV_EXTENSIONS, RGB_EXTENSIONS, RGBA_EXTENSIONS, RAW_EXTENSIONS, CMYK_EXTENSIONS}) for (const auto &extension : extensionsList) allExtensions.append(QString(extension)); @@ -578,7 +579,8 @@ void playlistItemRawFile::getSupportedFileExtensions(QStringList &allExtensions, filters.append("Raw RGBA File (*.rgba *.rbga *.grba *.gbra *.brga *.bgra *.argb *.arbg *.agrb " "*.agbr *.abrg *.abgr)"); filters.append("YUV4MPEG2 File (*.y4m)"); - filters.append("Bayer Raw File (*.raw)"); + filters.append("Raw Bayer File (*.raw)"); + filters.append("Raw CMYK File (*.cmyk)"); } void playlistItemRawFile::reloadItemSource() diff --git a/YUViewLib/src/video/rgb/PixelFormatRGBGuess.cpp b/YUViewLib/src/video/rgb/PixelFormatRGBGuess.cpp index 55c62a4ec..6d2ca903d 100644 --- a/YUViewLib/src/video/rgb/PixelFormatRGBGuess.cpp +++ b/YUViewLib/src/video/rgb/PixelFormatRGBGuess.cpp @@ -136,6 +136,16 @@ guessFormatFromSizeAndName(const QFileInfo &fileInfo, Size frameSize, int64_t fi auto ext = fileInfo.suffix().toLower().toStdString(); + if (fileInfo.suffix().toLower() == "cmyk") + { + auto fmt = PixelFormatRGB(8, DataLayout::Packed, ChannelOrder::RGB, AlphaMode::Last); + auto bpf = fmt.bytesPerFrame(frameSize); + if (bpf != 0 && (fileSize % bpf) == 0) + { + return fmt; + } + } + for (const auto &name : {fileName, dirName}) { for (auto format : diff --git a/YUViewLib/src/video/yuv/videoHandlerYUV.h b/YUViewLib/src/video/yuv/videoHandlerYUV.h index bd6d9208a..a3bc8faff 100644 --- a/YUViewLib/src/video/yuv/videoHandlerYUV.h +++ b/YUViewLib/src/video/yuv/videoHandlerYUV.h @@ -63,9 +63,9 @@ const auto ComponentDisplayModeMapper = struct ConversionSettings { - ChromaInterpolation chromaInterpolation{ChromaInterpolation::Bilinear}; + ChromaInterpolation chromaInterpolation{ChromaInterpolation::NearestNeighbor}; ComponentDisplayMode componentDisplayMode{ComponentDisplayMode::DisplayAll}; - ColorConversion colorConversion{ColorConversion::BT709_FullRange}; + ColorConversion colorConversion{ColorConversion::BT709_LimitedRange}; // Parameters for the YUV transformation (like scaling, invert, offset). For Luma ([0]) and // chroma([1]). std::map mathParameters;