Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
primaries: added wconv parameter
Browse files Browse the repository at this point in the history
Selects between standard chromatic adaptation and full gamut conversion.
  • Loading branch information
EleonoreMizo committed Aug 16, 2022
1 parent 7e0e95b commit c190d65
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 6 deletions.
20 changes: 19 additions & 1 deletion doc/fmtconv.html
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ <h3><a id="primaries"></a>primaries</h3>
wd : float[]: opt;
prims : data : opt;
primd : data : opt;
wconv : int : opt; (False)
cpuopt: int : opt; (-1)
)</pre></td>
<td class="n"><pre class="proto">fmtc_primaries (
Expand All @@ -973,6 +974,7 @@ <h3><a id="primaries"></a>primaries</h3>
arrayf wd (undefined),
string prims (undefined),
string primd (undefined),
bool wconv (False),
int cpuopt (-1)
)</pre></td>
</tr>
Expand Down Expand Up @@ -1070,6 +1072,21 @@ <h4>Parameters</h4>
<tr><td><b><code>&quot;redwide&quot;</code></b></td><td>R<br />G<br />B<br />W (D65)</td><td>0.780308,<br />0.121595,<br />0.095612,<br />0.3217,</td><td>0.304253<br />1.493994<br />&minus;0.084589<br />0.3290</td><td>REDWideGamutRGB</td></tr>
</table>

<p class="var">wconv</p>
<p>Indicates we want a full conversion for the white point.</p>
<p>If set to <code>False</code>, chromatic adaptation will be used, so the
white will stay white on the destination illuminant and colors will be adapted
to implement a real illuminant change.
This is generally what you want when converting between gamuts: the eye adapts
to the new white and colors should be matched accordingly.</p>
<p>If set to <code>True</code>, the chromatic adaptation is bypassed.
The white from the source colorspace will appear with a tint if the target
colorspace has a different white point.
Use this if you want to emulate what a picture displayed with a monitor using
the source illuminant looks like on a display using the target illuminant.
This is also what you want when converting to and from XYZ for further
operations in this colorspace.</p>

<p class="var">cpuopt</p>
<p>Limits the CPU instruction set.
&minus;1: automatic (no limitation),
Expand Down Expand Up @@ -1978,7 +1995,8 @@ <h2><a id="changelog"></a>V) Changelog</h2>
<li><code>matrix</code>: The <code>_ColorRange</code> frame property is now set when a matrix preset is used.</li>
<li><code>transfer</code>: Added ACEScct transfer function.</li>
<li><code>primaries</code>: Added DCI P3+ and Cinema Gamut presets.</li>
<li>Changed the <code>configure</<code> options to compile with Clang.</li>
<li><code>primaries</code>: Added <var>wconv</var> parameter for full conversion.</li>
<li>Changed the <code>configure</code> options to compile with Clang.</li>
<li>Updated datatypes in the examples.</li>
</ul>

Expand Down
4 changes: 3 additions & 1 deletion src/fmtc/Primaries_vs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ Primaries::Primaries (const ::VSMap &in, ::VSMap &out, void *user_data_ptr, ::VS
init (_prim_d, *this, in, out, "rd", "gd", "bd", "wd");
assert (_prim_d.is_ready ());

const auto conv_flag = (get_arg_int (in, out, "wconv", 0) != 0);

const fmtcl::Mat3 mat_conv =
fmtcl::PrimUtil::compute_conversion_matrix (_prim_s, _prim_d);
fmtcl::PrimUtil::compute_conversion_matrix (_prim_s, _prim_d, conv_flag);
_mat_main.insert3 (mat_conv);
_mat_main.clean3 (1);

Expand Down
1 change: 1 addition & 0 deletions src/fmtcavs/Primaries.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Primaries
Param_WD,
Param_PRIMS,
Param_PRIMD,
Param_WCONV,
Param_CPUOPT,

Param_NBR_ELT
Expand Down
4 changes: 3 additions & 1 deletion src/fmtcavs/Primaries_avs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ Primaries::Primaries (::IScriptEnvironment &env, const ::AVSValue &args)
init (_prim_d, env, args, Param_RD, Param_GD, Param_BD, Param_WD);
assert (_prim_d.is_ready ());

const auto conv_flag = args [Param_WCONV].AsBool (false);

const fmtcl::Mat3 mat_conv =
fmtcl::PrimUtil::compute_conversion_matrix (_prim_s, _prim_d);
fmtcl::PrimUtil::compute_conversion_matrix (_prim_s, _prim_d, conv_flag);
_mat_main.insert3 (mat_conv);
_mat_main.clean3 (1);

Expand Down
9 changes: 8 additions & 1 deletion src/fmtcl/PrimUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,20 @@ constexpr int PrimUtil::_nbr_planes;



Mat3 PrimUtil::compute_conversion_matrix (const RgbSystem &prim_s, const RgbSystem &prim_d)
// conv_flag indicates we want a full conversion, not a chromatic adatpation
Mat3 PrimUtil::compute_conversion_matrix (const RgbSystem &prim_s, const RgbSystem &prim_d, bool conv_flag)
{
assert (prim_s.is_ready ());
assert (prim_d.is_ready ());

const Mat3 rgb2xyz = compute_rgb2xyz (prim_s);
const Mat3 xyz2rgb = compute_rgb2xyz (prim_d).invert ();

if (conv_flag)
{
return xyz2rgb * rgb2xyz;
}

const Mat3 adapt = compute_chroma_adapt (prim_s, prim_d);

return xyz2rgb * adapt * rgb2xyz;
Expand Down
2 changes: 1 addition & 1 deletion src/fmtcl/PrimUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PrimUtil

static constexpr int _nbr_planes = RgbSystem::_nbr_planes;

static Mat3 compute_conversion_matrix (const RgbSystem &prim_s, const RgbSystem &prim_d);
static Mat3 compute_conversion_matrix (const RgbSystem &prim_s, const RgbSystem &prim_d, bool conv_flag);
static Mat3 compute_rgb2xyz (const RgbSystem &prim);
static Mat3 compute_chroma_adapt (const RgbSystem &prim_s, const RgbSystem &prim_d);
static Vec3 conv_xy_to_xyz (const RgbSystem::Vec2 &xy);
Expand Down
3 changes: 2 additions & 1 deletion src/main-avs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ const char * __stdcall AvisynthPluginInit3 (::IScriptEnvironment *env_ptr, const
env_ptr->AddFunction (fmtcavs_PRIMARIES,
"c" "[rs].+" "[gs].+" "[bs].+" // 0
"[ws].+" "[rd].+" "[gd].+" "[bd].+" // 4
"[wd].+" "[prims]s" "[primd]s" "[cpuopt]i" // 8
"[wd].+" "[prims]s" "[primd]s" "[wconv]b" // 8
"[cpuopt]i" // 12
, &main_avs_create <fmtcavs::Primaries>, nullptr
);
env_ptr->AddFunction (fmtcavs_RESAMPLE,
Expand Down
1 change: 1 addition & 0 deletions src/main-vs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ VS_EXTERNAL_API (void) VapourSynthPluginInit2 (::VSPlugin *plugin_ptr, const ::V
"wd:float[]:opt;"
"prims:data:opt;"
"primd:data:opt;"
"wconv:int:opt;"
"cpuopt:int:opt;"
, "clip:vnode;"
, &vsutl::Redirect <fmtc::Primaries>::create, nullptr, plugin_ptr
Expand Down

0 comments on commit c190d65

Please sign in to comment.