Skip to content

Commit

Permalink
Fixed BT2020 decode speed.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Mar 11, 2024
1 parent 1f99f57 commit fc333c6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
7 changes: 3 additions & 4 deletions lib/tlCore/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ namespace tl
const std::array<math::Vector4f, static_cast<size_t>(YUVCoefficients::Count)> data =
{
math::Vector4f(1.79274, 2.1124, 0.213242, 0.532913),
// Is BT2020 right? These are the coeffs I got:
// math::Vector4f(1.4746, 2.0184, 1.5958, 0.0); // chatgpt3.5
// math::Vector4f(1.8556, 2.14101, 0.2124, 0.6301), // gemini
math::Vector4f(1.67867, 2.14177, 0.187332, 0.650421) // darby
// Is Darby's BT2020 right? These are the coeffs I got:
math::Vector4f(1.8556, 2.14101, 0.2124, 0.6301), // gemini
//math::Vector4f(1.67867, 2.14177, 0.187332, 0.650421) // darby
};
return data[static_cast<size_t>(value)];
}
Expand Down
36 changes: 21 additions & 15 deletions lib/tlIO/FFmpegReadVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,25 +606,31 @@ namespace tl
{
throw std::runtime_error(string::Format("{0}: Cannot initialize sws context").arg(_fileName));
}

const auto params = _avCodecParameters[_avStream];
int in_full, out_full, brightness, contrast, saturation;
const int *inv_table, *table;

sws_getColorspaceDetails(
_swsContext, (int**)&inv_table, &in_full,
(int**)&table, &out_full, &brightness, &contrast,
&saturation);

inv_table = sws_getCoefficients(params->color_space);
table = sws_getCoefficients(AVCOL_SPC_BT709);
// We should not do a BT2020_NCL to BT709 conversion in
// software which is slow.
if (params->color_space != AVCOL_SPC_BT2020_NCL)
{
int in_full, out_full, brightness, contrast, saturation;
const int *inv_table, *table;

sws_getColorspaceDetails(
_swsContext, (int**)&inv_table, &in_full,
(int**)&table, &out_full, &brightness, &contrast,
&saturation);

inv_table = sws_getCoefficients(params->color_space);
table = sws_getCoefficients(AVCOL_SPC_BT709);

in_full = (params->color_range == AVCOL_RANGE_JPEG);
out_full = (params->color_range == AVCOL_RANGE_JPEG);
in_full = (params->color_range == AVCOL_RANGE_JPEG);
out_full = (params->color_range == AVCOL_RANGE_JPEG);

sws_setColorspaceDetails(
_swsContext, inv_table, in_full, table, out_full,
brightness, contrast, saturation);
sws_setColorspaceDetails(
_swsContext, inv_table, in_full, table, out_full,
brightness, contrast, saturation);
}
}
}
}
Expand Down

0 comments on commit fc333c6

Please sign in to comment.