Skip to content

Commit

Permalink
colorspace: Add support for bt470m/gamma22 transfer characteristics
Browse files Browse the repository at this point in the history
  • Loading branch information
kodawah committed Oct 3, 2017
1 parent 5bc60aa commit 7cc84f2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/testapp/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ const zimg::static_string_map<MatrixCoefficients, 10> g_matrix_table{
{ "ictcp", MatrixCoefficients::REC_2100_ICTCP },
};

const zimg::static_string_map<TransferCharacteristics, 11> g_transfer_table{
const zimg::static_string_map<TransferCharacteristics, 12> g_transfer_table{
{ "unspec", TransferCharacteristics::UNSPECIFIED },
{ "linear", TransferCharacteristics::LINEAR },
{ "log100", TransferCharacteristics::LOG_100 },
{ "log316", TransferCharacteristics::LOG_316 },
{ "240m", TransferCharacteristics::SMPTE_240M },
{ "709", TransferCharacteristics::REC_709 },
{ "470m", TransferCharacteristics::REC_470_M },
{ "470bg", TransferCharacteristics::REC_470_BG },
{ "xvycc", TransferCharacteristics::XVYCC },
{ "srgb", TransferCharacteristics::SRGB },
Expand Down
2 changes: 1 addition & 1 deletion src/testapp/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Filter;
extern const zimg::static_string_map<zimg::CPUClass, 8> g_cpu_table;
extern const zimg::static_string_map<zimg::PixelType, 4> g_pixel_table;
extern const zimg::static_string_map<zimg::colorspace::MatrixCoefficients, 10> g_matrix_table;
extern const zimg::static_string_map<zimg::colorspace::TransferCharacteristics, 11> g_transfer_table;
extern const zimg::static_string_map<zimg::colorspace::TransferCharacteristics, 12> g_transfer_table;
extern const zimg::static_string_map<zimg::colorspace::ColorPrimaries, 6> g_primaries_table;
extern const zimg::static_string_map<zimg::depth::DitherType, 4> g_dither_table;
extern const zimg::static_string_map<std::unique_ptr<zimg::resize::Filter>(*)(double, double), 7> g_resize_table;
Expand Down
3 changes: 2 additions & 1 deletion src/zimg/api/zimg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,12 @@ zimg::colorspace::TransferCharacteristics translate_transfer(zimg_transfer_chara
{
using zimg::colorspace::TransferCharacteristics;

static SM_CONSTEXPR_14 const zimg::static_map<zimg_transfer_characteristics_e, TransferCharacteristics, 14> map{
static SM_CONSTEXPR_14 const zimg::static_map<zimg_transfer_characteristics_e, TransferCharacteristics, 15> map{
{ ZIMG_TRANSFER_709, TransferCharacteristics::REC_709 },
{ ZIMG_TRANSFER_UNSPECIFIED, TransferCharacteristics::UNSPECIFIED },
{ ZIMG_TRANSFER_240M, TransferCharacteristics::SMPTE_240M },
{ ZIMG_TRANSFER_601, TransferCharacteristics::REC_709 },
{ ZIMG_TRANSFER_470M, TransferCharacteristics::REC_470_M },
{ ZIMG_TRANSFER_470BG, TransferCharacteristics::REC_470_BG },
{ ZIMG_TRANSFER_IEC_61966_2_4, TransferCharacteristics::XVYCC },
{ ZIMG_TRANSFER_IEC_61966_2_1, TransferCharacteristics::SRGB },
Expand Down
1 change: 1 addition & 0 deletions src/zimg/api/zimg.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ typedef enum zimg_transfer_characteristics_e {
ZIMG_TRANSFER_INTERNAL = -1, /**< Not part of the API. */
ZIMG_TRANSFER_709 = 1,
ZIMG_TRANSFER_UNSPECIFIED = 2,
ZIMG_TRANSFER_470M = 4,
ZIMG_TRANSFER_470BG = 5,
ZIMG_TRANSFER_601 = 6, /* Equivalent to 1. */
ZIMG_TRANSFER_240M = 7,
Expand Down
1 change: 1 addition & 0 deletions src/zimg/colorspace/colorspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum class TransferCharacteristics {
LOG_100,
LOG_316,
REC_709,
REC_470_M,
REC_470_BG,
SMPTE_240M,
XVYCC,
Expand Down
14 changes: 14 additions & 0 deletions src/zimg/colorspace/gamma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ float log316_inverse_oetf(float x) noexcept
return x <= 0.0f ? 0.00316227766f : zimg_x_powf(10, 2.5 * (x - 1.0f));
}

float rec_470m_oetf(float x) noexcept
{
return x < 0.0f ? 0.0f : zimg_x_powf(x, 1.0f / 2.2f);
}

float rec_470m_inverse_oetf(float x) noexcept
{
return x < 0.0f ? 0.0f : zimg_x_powf(x, 2.2f);
}

float rec_470bg_oetf(float x) noexcept
{
return x < 0.0f ? 0.0f : zimg_x_powf(x, 1.0f / 2.8f);
Expand Down Expand Up @@ -292,6 +302,10 @@ TransferFunction select_transfer_function(TransferCharacteristics transfer, doub
func.to_linear = scene_referred ? rec_709_inverse_oetf : rec_1886_eotf;
func.to_gamma = scene_referred ? rec_709_oetf : rec_1886_inverse_eotf;
break;
case TransferCharacteristics::REC_470_M:
func.to_linear = scene_referred ? rec_470m_inverse_oetf : rec_1886_eotf;
func.to_gamma = scene_referred ? rec_470m_oetf: rec_1886_eotf;
break;
case TransferCharacteristics::REC_470_BG:
func.to_linear = scene_referred ? rec_470bg_inverse_oetf : rec_1886_eotf;
func.to_gamma = scene_referred ? rec_470bg_oetf: rec_1886_eotf;
Expand Down

0 comments on commit 7cc84f2

Please sign in to comment.