Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support openning raw Bayer (as gray YUV400) and CMYK (as RGBA) file #576

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions YUViewLib/src/playlistitem/playlistItemRawFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ 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",};
constexpr auto CMYK_EXTENSIONS = {"cmyk",};

bool isInExtensions(const QString &testValue, const std::initializer_list<const char *> &extensions)
{
Expand Down Expand Up @@ -94,12 +96,12 @@ 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<video::yuv::videoHandlerYUV>();
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<video::rgb::videoHandlerRGB>();
Expand Down Expand Up @@ -568,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})
for (const auto &extensionsList : {YUV_EXTENSIONS, RGB_EXTENSIONS, RGBA_EXTENSIONS, RAW_EXTENSIONS, CMYK_EXTENSIONS})
for (const auto &extension : extensionsList)
allExtensions.append(QString(extension));

Expand All @@ -577,6 +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("Raw Bayer File (*.raw)");
filters.append("Raw CMYK File (*.cmyk)");
}

void playlistItemRawFile::reloadItemSource()
Expand Down
10 changes: 10 additions & 0 deletions YUViewLib/src/video/rgb/PixelFormatRGBGuess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
8 changes: 4 additions & 4 deletions YUViewLib/src/video/yuv/PixelFormatYUV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
2 changes: 1 addition & 1 deletion YUViewLib/src/video/yuv/PixelFormatYUV.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions YUViewLib/src/video/yuv/PixelFormatYUVGuess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down