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

update yuvRgbConvCoeffs slightly #584

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ YUView.pro.user
/decoders
.vscode
issues
.DS_Store
23 changes: 11 additions & 12 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 Expand Up @@ -174,7 +174,7 @@ PixelFormatYUV::PixelFormatYUV(const std::string &name)
auto bitdepthStr = sm.str(3);
size_t sz;
int bitDepth = std::stoi(bitdepthStr, &sz);
if (sz > 0 && bitDepth >= 8 && bitDepth <= 16)
if (sz > 0 && bitDepth >= 8 && bitDepth <= 32)
newFormat.bitsPerSample = bitDepth;
}

Expand Down Expand Up @@ -317,7 +317,7 @@ bool PixelFormatYUV::canConvertToRGB(Size imageSize, std::string *whyNot) const
// Check the bit depth
const int bps = this->bitsPerSample;
bool canConvert = true;
if (bps < 8 || bps > 16)
if (bps < 8 || bps > 32)
{
if (whyNot)
{
Expand Down Expand Up @@ -382,14 +382,14 @@ int64_t PixelFormatYUV::bytesPerFrame(const Size &frameSize) const
}

int64_t bytes = 0;
const auto bytesPerSample = get_min_standard_bytes(this->bitsPerSample); // Round to bytes

if (this->planar || !this->bytePacking)
{
// Add the bytes of the 3 (or 4) planes.
// This also works for packed formats without byte packing. For these formats the number of
// bytes are identical to the not packed formats, the bytes are just sorted in another way.

const auto bytesPerSample = (this->bitsPerSample + 7) / 8; // Round to bytes
bytes += frameSize.width * frameSize.height * bytesPerSample; // Luma plane
if (this->subsampling == Subsampling::YUV_444)
bytes += frameSize.width * frameSize.height * bytesPerSample * 2; // U/V planes
Expand Down Expand Up @@ -426,17 +426,16 @@ int64_t PixelFormatYUV::bytesPerFrame(const Size &frameSize) const
if (this->subsampling == Subsampling::YUV_422)
{
// All packing orders have 4 values per packed value (which has 2 Y samples)
const auto bitsPerPixel = this->bitsPerSample * 4;
return ((bitsPerPixel + 7) / 8) * (frameSize.width / 2) * frameSize.height;
return 4 * bytesPerSample * (frameSize.width / 2) * frameSize.height;
}
// This is a packed format. The added number of bytes might be lower because of the packing.
if (this->subsampling == Subsampling::YUV_444)
{
auto bitsPerPixel = this->bitsPerSample * 3;
auto channels = 3;
if (this->packingOrder == PackingOrder::AYUV || this->packingOrder == PackingOrder::YUVA ||
this->packingOrder == PackingOrder::VUYA)
bitsPerPixel += this->bitsPerSample;
return ((bitsPerPixel + 7) / 8) * frameSize.width * frameSize.height;
channels += 1;
return channels * bytesPerSample * frameSize.width * frameSize.height;
}
// else if (subsampling == Subsampling::YUV_422 || subsampling == Subsampling::YUV_440)
//{
Expand Down
19 changes: 18 additions & 1 deletion YUViewLib/src/video/yuv/PixelFormatYUV.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ constexpr EnumMapper<PlaneOrder, 4> PlaneOrderMapper(std::make_pair(PlaneOrder::
std::make_pair(PlaneOrder::YUVA, "YUVA"sv),
std::make_pair(PlaneOrder::YVUA, "YVUA"sv));

const auto BitDepthList = std::vector<unsigned>({8, 9, 10, 12, 14, 16});
const auto BitDepthList = std::vector<unsigned>({8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32});

// This class defines a specific YUV format with all properties like pixels per sample, subsampling
// of chroma components and so on.
Expand Down Expand Up @@ -263,4 +263,21 @@ class PixelFormatYUV
bool bytePacking{};
};

inline uint64_t get_min_standard_bytes(uint64_t x) {
if (x == 0)
return 0;

if (x >= UINT64_MAX / 8) {
return UINT64_MAX;
}

x--;

for (int current_shift = 1; current_shift < 64; current_shift <<= 1) {
x |= x >> current_shift;
}

return (x + 8) >> 3;
}

} // namespace video::yuv
4 changes: 2 additions & 2 deletions YUViewLib/src/video/yuv/PixelFormatYUVGuess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ Subsampling findSubsamplingTypeIndicatorInName(std::string name)
std::vector<unsigned> getDetectionBitDepthList(unsigned forceAsFirst)
{
std::vector<unsigned> bitDepthList;
if (forceAsFirst >= 8 && forceAsFirst <= 16)
if (forceAsFirst >= 8 && forceAsFirst <= 32)
bitDepthList.push_back(forceAsFirst);

for (auto bitDepth : {10u, 12u, 14u, 16u, 8u})
for (auto bitDepth : BitDepthList)
{
if (!vectorContains(bitDepthList, bitDepth))
bitDepthList.push_back(bitDepth);
Expand Down
Loading