Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/EleonoreMizo/fmtconv into…
Browse files Browse the repository at this point in the history
… mod
  • Loading branch information
AkarinVS committed Jan 20, 2023
2 parents 6a04c42 + 5ec9172 commit c828338
Show file tree
Hide file tree
Showing 29 changed files with 5,572 additions and 33 deletions.
51 changes: 51 additions & 0 deletions build/unix/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,31 @@ commonsrc = \
../../src/fstb/Hash.hpp \
../../src/fstb/SingleObj.h \
../../src/fstb/SingleObj.hpp \
../../src/fstb/Vf32.h \
../../src/fstb/Vf32.hpp \
../../src/fstb/Vs32.h \
../../src/fstb/Vs32.hpp \
../../src/fstb/Vu32.h \
../../src/fstb/Vu32.hpp \
../../src/avstp.h \
../../src/AvstpWrapper.cpp \
../../src/AvstpWrapper.h

libfmtconv_la_SOURCES = $(commonsrc) \
../../src/avisynth.h \
../../src/main-avs.cpp \
../../src/main-vs.cpp \
../../src/types.h \
../../src/VapourSynth4.h \
../../src/avs/alignment.h \
../../src/avs/capi.h \
../../src/avs/config.h \
../../src/avs/cpuid.h \
../../src/avs/filesystem.h \
../../src/avs/minmax.h \
../../src/avs/posix.h \
../../src/avs/types.h \
../../src/avs/win.h \
../../src/fmtc/Bitdepth_vs.cpp \
../../src/fmtc/Bitdepth.h \
../../src/fmtc/Convert.cpp \
Expand All @@ -326,6 +343,40 @@ libfmtconv_la_SOURCES = $(commonsrc) \
../../src/fmtc/Transfer_vs.cpp \
../../src/fmtc/Transfer.h \
../../src/fmtc/version.h \
../../src/fmtcavs/Bitdepth_avs.cpp \
../../src/fmtcavs/Bitdepth.h \
../../src/fmtcavs/CpuOpt_avs.cpp \
../../src/fmtcavs/CpuOpt.h \
../../src/fmtcavs/FmtAvs.cpp \
../../src/fmtcavs/FmtAvs.h \
../../src/fmtcavs/fnc_fmtcavs.cpp \
../../src/fmtcavs/fnc.h \
../../src/fmtcavs/function_names.h \
../../src/fmtcavs/Matrix2020CL_avs.cpp \
../../src/fmtcavs/Matrix2020CL.h \
../../src/fmtcavs/Matrix_avs.cpp \
../../src/fmtcavs/Matrix.h \
../../src/fmtcavs/Primaries_avs.cpp \
../../src/fmtcavs/Primaries.h \
../../src/fmtcavs/ProcAlpha.cpp \
../../src/fmtcavs/ProcAlpha.h \
../../src/fmtcavs/Resample_avs.cpp \
../../src/fmtcavs/Resample.h \
../../src/fmtcavs/Transfer_avs.cpp \
../../src/fmtcavs/Transfer.h \
../../src/avsutl/CsPlane.cpp \
../../src/avsutl/CsPlane.h \
../../src/avsutl/fnc_avsutl.cpp \
../../src/avsutl/fnc.h \
../../src/avsutl/fnc.hpp \
../../src/avsutl/PlaneProcCbInterface_avs.cpp \
../../src/avsutl/PlaneProcCbInterface.h \
../../src/avsutl/PlaneProcessor_avs.cpp \
../../src/avsutl/PlaneProcessor.h \
../../src/avsutl/PlaneProcMode.h \
../../src/avsutl/TFlag.h \
../../src/avsutl/VideoFilterBase.cpp \
../../src/avsutl/VideoFilterBase.h \
../../src/vsutl/FilterBase.cpp \
../../src/vsutl/FilterBase.h \
../../src/vsutl/fnc_vsutl.cpp \
Expand Down
2 changes: 1 addition & 1 deletion build/unix/configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([fmtconv], [r29], [http://forum.doom9.org/showthread.php?t=166504], [fmtconv], [http://forum.doom9.org/showthread.php?t=166504])
AC_INIT([fmtconv], [r30], [http://forum.doom9.org/showthread.php?t=166504], [fmtconv], [http://forum.doom9.org/showthread.php?t=166504])
AC_CONFIG_MACRO_DIR([m4])

AM_INIT_AUTOMAKE([foreign no-dist-gzip dist-xz subdir-objects no-define])
Expand Down
6 changes: 6 additions & 0 deletions build/win/common/common.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@
<ClInclude Include="..\..\..\src\avstp.h" />
<ClInclude Include="..\..\..\src\AvstpFinder.h" />
<ClInclude Include="..\..\..\src\AvstpWrapper.h" />
<ClInclude Include="..\..\..\src\fstb\Vf32.h" />
<ClInclude Include="..\..\..\src\fstb\Vf32.hpp" />
<ClInclude Include="..\..\..\src\fstb\Vs32.h" />
<ClInclude Include="..\..\..\src\fstb\Vs32.hpp" />
<ClInclude Include="..\..\..\src\fstb\Vu32.h" />
<ClInclude Include="..\..\..\src\fstb\Vu32.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\src\fmtcl\ArrayMultiType.cpp" />
Expand Down
18 changes: 18 additions & 0 deletions build/win/common/common.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,24 @@
<ClInclude Include="..\..\..\src\fmtcl\TransOpAcesCct.h">
<Filter>fmtcl</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\fstb\Vf32.h">
<Filter>fstb</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\fstb\Vf32.hpp">
<Filter>fstb</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\fstb\Vs32.h">
<Filter>fstb</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\fstb\Vs32.hpp">
<Filter>fstb</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\fstb\Vu32.h">
<Filter>fstb</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\fstb\Vu32.hpp">
<Filter>fstb</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="conc">
Expand Down
51 changes: 41 additions & 10 deletions doc/fmtconv.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h2>Abstract</h2>

<table class="n">
<tr><td class="n"><b>Authors: </b></td><td class="n">&nbsp;</td><td class="n">Firesledge (aka Cretindesalpes)</td></tr>
<tr><td class="n"><b>Version: </b></td><td class="n">&nbsp;</td><td class="n">r29</td></tr>
<tr><td class="n"><b>Version: </b></td><td class="n">&nbsp;</td><td class="n">r30</td></tr>
<tr><td class="n"><b>Download: </b></td><td class="n">&nbsp;</td><td class="n"><a href="http://ldesoras.free.fr/prod.html#src_fmtconv">http://ldesoras.free.fr/prod.html</a></td></tr>
<tr><td class="n"><b>Category: </b></td><td class="n">&nbsp;</td><td class="n">Format tools</td></tr>
<tr><td class="n"><b>Requirements:</b></td><td class="n">&nbsp;</td><td class="n"><a href="http://www.vapoursynth.com/">Vapoursynth r55</a> or <a href="https://avs-plus.net/">Avisynth+ 3.7.0</a></td></tr>
Expand Down Expand Up @@ -129,7 +129,7 @@ <h4>Resizing and chroma subsampling conversions</h4>
<p>Bobbing an interlaced stream (here, Top Field First):</p>

<pre class="src">c = c.std.SeparateFields (tff=True)
c = c.fmtc.resample (scalev=2, kernel="cubic", interlaced=True, interlacedd=False)</pre>
c = c.fmtc.resample (scalev=2, kernel="cubic", interlaced=1, interlacedd=0)</pre>

<p>Converting a progressive stream from YUV 4:2:2 to 4:2:0 and back to 8 bits:</p>

Expand All @@ -140,7 +140,7 @@ <h4>Resizing and chroma subsampling conversions</h4>

<pre class="src">tff = True
c = c.std.SeparateFields (tff=tff)
c = c.fmtc.resample (css="420", interlaced=True)
c = c.fmtc.resample (css="420", interlaced=1)
c = c.fmtc.bitdepth (bits=8)
c = c.std.DoubleWeave (tff=tff)
c = c.std.SelectEvery (cycle=2, offsets=0)</pre>
Expand Down Expand Up @@ -623,7 +623,7 @@ <h3><a id="matrix"></a>matrix</h3>
</code>primaries</code> to perform the intermediary conversion.</p>

<p>The <code>_ColorRange</code> frame property is set if the <var>fulld</var>
parameter has been explicitely defined.
parameter has been explicitely defined or if a preset is used.
If the destination colorspace is a standardized one (as deduced from the
specified matrix), the <code>_Matrix</code> and <code>_ColorSpace</code>
properties are set, otherwise they are deleted from the frame.</p>
Expand Down 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 @@ -1275,7 +1292,7 @@ <h4>Parameters</h4>
<p>Clip to be resized. Mandatory.
Supported input formats:</p>
<ul>
<li>8-, 9-, 10-, 12-, 16- and 16-bit integer.</li>
<li>8-, 9-, 10-, 12-, 14- and 16-bit integer.</li>
<li>32-bit floating point.</li>
<li>Any planar colorspace.</li>
</ul>
Expand Down Expand Up @@ -1872,9 +1889,15 @@ <h4>Parameters</h4>
<p>Indicate the peak white levels in cd/m<sup>2</sup>.
<var>lws</var> is for the source transfer function, and <var>lwd</var>
for the destination one.
These parameters are taken into account when display-referred transfer
functions are used.
Minimum <var>lw</var> value is 0.1&nbsp;cd/m<sup>2</sup>.
These parameters are taken into account to scale the luminance when the
following conditions are met:</p>
<ul>
<li>display-referred transfer functions are used,
<li><var>match</var> is set to 2 (display luminance matching) and</li>
<li>the EOTF shouldn’t specify any scale for the luminance (the cd/m² value
for F’&nbsp;= 1.0).</li>
</ul>
<p>Minimum <var>lw</var> value is 0.1&nbsp;cd/m<sup>2</sup>.
System gamma may be changed according to the <var>lw</var> parameter.
Unless specified, HDR functions use a peak white of 1000&nbsp;cd/m<sup>2</sup>.
Similarly, SDR and other functions use 100&nbsp;cd/m<sup>2</sup> by default.
Expand Down Expand Up @@ -1973,11 +1996,19 @@ <h2><a id="troubleshooting"></a>IV) Troubleshooting</h2>

<h2><a id="changelog"></a>V) Changelog</h2>

<p><b>r30, 2022-xx-xx</b></p>
<p><b>r31, 202x-xx-xx</b></p>
<ul>
<li><code>resample</code>: fixed 14 to 16 bit AVX2 conversion path, thanks to NSQY for the report.</li>
</ul>

<p><b>r30, 2022-08-29</b></p>
<ul>
<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>

<p><b>r29, 2022-04-11</b></p>
Expand Down
16 changes: 8 additions & 8 deletions src/avisynth.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,17 +442,17 @@ extern const AVS_Linkage* AVS_linkage;
# endif

# define AVS_BakedCode(arg) { arg ; }
# define AVS_LinkCall(arg) !AVS_linkage || offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? 0 : (this->*(AVS_linkage->arg))
# define AVS_LinkCall_Void(arg) !AVS_linkage || offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? (void)0 : (this->*(AVS_linkage->arg))
# define AVS_LinkCallV(arg) !AVS_linkage || offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? *this : (this->*(AVS_linkage->arg))
# define AVS_LinkCall(arg) !AVS_linkage || offsetof(AVS_Linkage, arg) >= (size_t)AVS_linkage->Size ? 0 : (this->*(AVS_linkage->arg))
# define AVS_LinkCall_Void(arg) !AVS_linkage || offsetof(AVS_Linkage, arg) >= (size_t)AVS_linkage->Size ? (void)0 : (this->*(AVS_linkage->arg))
# define AVS_LinkCallV(arg) !AVS_linkage || offsetof(AVS_Linkage, arg) >= (size_t)AVS_linkage->Size ? *this : (this->*(AVS_linkage->arg))
// Helper macros for fallback option when a function does not exists
#define CALL_MEMBER_FN(object,ptrToMember) ((object)->*(ptrToMember))
#define AVS_LinkCallOpt(arg, argOpt) !AVS_linkage ? 0 : \
( offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? \
(offsetof(AVS_Linkage, argOpt) >= AVS_linkage->Size ? 0 : CALL_MEMBER_FN(this, AVS_linkage->argOpt)() ) : \
( offsetof(AVS_Linkage, arg) >= (size_t)AVS_linkage->Size ? \
(offsetof(AVS_Linkage, argOpt) >= (size_t)AVS_linkage->Size ? 0 : CALL_MEMBER_FN(this, AVS_linkage->argOpt)() ) : \
CALL_MEMBER_FN(this, AVS_linkage->arg)() )
// AVS_LinkCallOptDefault puts automatically () only after arg
# define AVS_LinkCallOptDefault(arg, argDefaultValue) !AVS_linkage || offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? (argDefaultValue) : ((this->*(AVS_linkage->arg))())
# define AVS_LinkCallOptDefault(arg, argDefaultValue) !AVS_linkage || offsetof(AVS_Linkage, arg) >= (size_t)AVS_linkage->Size ? (argDefaultValue) : ((this->*(AVS_linkage->arg))())

#endif

Expand Down Expand Up @@ -1299,7 +1299,7 @@ class GenericVideoFilter : public IClip {
void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env) { child->GetAudio(buf, start, count, env); }
const VideoInfo& __stdcall GetVideoInfo() { return vi; }
bool __stdcall GetParity(int n) { return child->GetParity(n); }
int __stdcall SetCacheHints(int cachehints, int frame_range) { AVS_UNUSED(cachehints); AVS_UNUSED(frame_range); return 0; }; // We do not pass cache requests upwards, only to the next filter.
int __stdcall SetCacheHints(int cachehints, int frame_range) { AVS_UNUSED(cachehints); AVS_UNUSED(frame_range); return 0; } // We do not pass cache requests upwards, only to the next filter.
};


Expand Down Expand Up @@ -1864,7 +1864,7 @@ struct PNeoEnv {
#if defined(BUILDING_AVSCORE) || defined(AVS_STATIC_LIB)
;
#else
: p(!AVS_linkage || offsetof(AVS_Linkage, GetNeoEnv) >= AVS_linkage->Size ? 0 : AVS_linkage->GetNeoEnv(env)) { }
: p(!AVS_linkage || offsetof(AVS_Linkage, GetNeoEnv) >= (size_t)AVS_linkage->Size ? 0 : AVS_linkage->GetNeoEnv(env)) { }
#endif

int operator!() const { return !p; }
Expand Down
3 changes: 3 additions & 0 deletions src/fmtc/Matrix_vs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ Matrix::Matrix (const ::VSMap &in, ::VSMap &out, void * /*user_data_ptr*/, ::VSC
const int nbr_expected_coef = _nbr_planes * (_nbr_planes + 1);

bool mat_init_flag = false;
bool preset_flag = false;

// Matrix presets
std::string mat (get_arg_str (in, out, "mat", ""));
Expand Down Expand Up @@ -182,6 +183,7 @@ Matrix::Matrix (const ::VSMap &in, ::VSMap &out, void * /*user_data_ptr*/, ::VSC
_mat_main = m2d * m2s;

mat_init_flag = true;
preset_flag = true;
}

// Custom coefficients
Expand Down Expand Up @@ -309,6 +311,7 @@ Matrix::Matrix (const ::VSMap &in, ::VSMap &out, void * /*user_data_ptr*/, ::VSC
vsutl::is_full_range_default (fmt_dst) ? 1 : 0,
0, &_range_set_dst_flag
) != 0);
_range_set_dst_flag |= preset_flag;

prepare_matrix_coef (
*this, *_proc_uptr, _mat_main,
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
6 changes: 3 additions & 3 deletions src/fmtc/Resample_vs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ const ::VSFrame * Resample::get_frame (int n, int activation_reason, void * &fra
if (ret_val != 0)
{
_vsapi.freeFrame (dst_ptr);
dst_ptr = 0;
dst_ptr = nullptr;
}
}

Expand Down Expand Up @@ -680,15 +680,15 @@ int Resample::do_process_plane (::VSFrame &dst, int n, int plane_index, void *fr
{
const Ru::FrameInfo & frame_info =
*reinterpret_cast <const Ru::FrameInfo *> (frame_data_ptr);
process_plane_proc (
ret_val = process_plane_proc (
dst, n, plane_index, frame_ctx, src_node1_sptr, frame_info
);
}

// Copy (and convert)
else if (proc_mode == vsutl::PlaneProcMode_COPY1)
{
process_plane_copy (
ret_val = process_plane_copy (
dst, n, plane_index, frame_ctx, src_node1_sptr
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/fmtc/version.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#define fmtc_VERSION 29
#define fmtc_VERSION 30
#define fmtc_PLUGIN_NAME "fmtconv"
#define fmtc_NAMESPACE "fmtc"
5 changes: 3 additions & 2 deletions src/fmtcavs/Matrix_avs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ Matrix::Matrix (::IScriptEnvironment &env, const ::AVSValue &args)
{
env.ThrowError (fmtcavs_MATRIX ": input must be 4:4:4.");
}
const int nbr_planes_src = _vi_src.NumComponents ();
if (fmt_src.get_nbr_comp_non_alpha () != _nbr_planes_proc)
{
env.ThrowError (
Expand Down Expand Up @@ -129,6 +128,7 @@ Matrix::Matrix (::IScriptEnvironment &env, const ::AVSValue &args)
const int nbr_expected_coef = _nbr_planes_proc * (_nbr_planes_proc + 1);

bool mat_init_flag = false;
bool preset_flag = false;
fmtcl::Mat4 mat_main; // Main matrix, float input, float output

// Matrix presets
Expand Down Expand Up @@ -169,6 +169,7 @@ Matrix::Matrix (::IScriptEnvironment &env, const ::AVSValue &args)

mat_main = m2d * m2s;
mat_init_flag = true;
preset_flag = true;
}

// Alpha plane processing, if any
Expand Down Expand Up @@ -267,7 +268,7 @@ Matrix::Matrix (::IScriptEnvironment &env, const ::AVSValue &args)
_fulld_flag = args [Param_FULLD].AsBool (
fmtcl::is_full_range_default (fmt_dst.get_col_fam ())
);
_range_def_flag = args [Param_FULLD].Defined ();
_range_def_flag = (args [Param_FULLD].Defined () || preset_flag);

prepare_matrix_coef (
env, *_proc_uptr, mat_main,
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
Loading

0 comments on commit c828338

Please sign in to comment.