Skip to content

Commit

Permalink
colorspace: Add support for gamma22 transfer characteristics
Browse files Browse the repository at this point in the history
  • Loading branch information
kodawah committed Sep 18, 2017
1 parent 108f113 commit 94bf39f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 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 },
{ "log10", TransferCharacteristics::LOG_10 },
{ "log316", TransferCharacteristics::LOG_SQRT },
{ "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
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_10,
LOG_SQRT,
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 @@ -120,6 +120,16 @@ float rec_1886_inverse_eotf(float x) noexcept
return x < 0.0f ? 0.0f : zimg_x_powf(x, 1.0f / 2.4f);
}

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

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

float rec_470bg_eotf(float x) noexcept
{
return x < 0.0f ? 0.0f : zimg_x_powf(x, 2.8f);
Expand Down Expand Up @@ -312,6 +322,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 = rec_470m_eotf;
func.to_gamma = rec_470m_inverse_eotf;
break;
case TransferCharacteristics::REC_470_BG:
func.to_linear = rec_470bg_eotf;
func.to_gamma = rec_470bg_inverse_eotf;
Expand Down

0 comments on commit 94bf39f

Please sign in to comment.