Skip to content

Commit

Permalink
Update to 1.2.0
Browse files Browse the repository at this point in the history
More clean the code.
Update README.md.
Shader/Tonemap: add trc ST428.
Tonemap: add parameters percentile, metadata, visualize_lut, show_clipping.
Tonemap: add tone_mapping_function st2094_40, st2094_10.
Tonemap: improve the speed (Lypheo/vs-placebo@09075cf).
Tonemap: add support for libdovi 3. (Lypheo/vs-placebo@f65161b)
Remove libp2p dependency.
Tonemap: fix wrong levels when output is SDR.
Tonemap: remove HDR frame props when output is SDR.
Tonemap: add support for libplacebo v5.264.0. (Lypheo/vs-placebo@4a42255)
msvc: update libs.
Update submodules.
  • Loading branch information
Asd-g committed Mar 11, 2023
1 parent 4bbf726 commit 94faff9
Show file tree
Hide file tree
Showing 15 changed files with 429 additions and 452 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
[submodule "dovi_tool"]
path = dovi_tool
url = https://github.com/quietvoid/dovi_tool
[submodule "libp2p"]
path = libp2p
url = https://github.com/sekrit-twc/libp2p
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
##### 1.2.0:
Shader/Tonemap: added trc ST428.
Tonemap: added parameters percentile, metadata, visualize_lut, show_clipping.
Tonemap: added tone_mapping_function st2094_40, st2094_10.
Shader/Tonemap: improved speed. (based on https://github.com/Lypheo/vs-placebo/commit/09075cf2a3768b7c87903bb23640916b0b3b68cc)
Tonemap: added support for libdovi 3. (based on https://github.com/Lypheo/vs-placebo/commit/f65161b7dd167b60e7af4670a692c6df3c40de6e)
Removed libp2p dependency.
Tonemap: fixed wrong levels when output is SDR.
Tonemap: remove HDR frame props when output is SDR.
Tonemap: added support for libplacebo v5.264.0. (based on https://github.com/Lypheo/vs-placebo/commit/4a42255c880572d75c8b50b69b784a67fd93e241)
Shader: removed shader_param limit.

##### 1.1.5:
libplacebo_Tonemap: fixed `dst_min`.

Expand Down
88 changes: 61 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,15 @@ libplacebo_Resample(clip input, int width, int height, string "filter", float "r
7: GAMMA24 (Pure power gamma 2.4)\
8: GAMMA26 (Pure power gamma 2.6)\
9: GAMMA28 (Pure power gamma 2.8)\
10: PRO_PHOTO (ProPhoto RGB (ROMM))
10: PRO_PHOTO (ProPhoto RGB (ROMM))\
11: ST428 (Digital Cinema Distribution Master (XYZ))

High dynamic range:\
11: PQ (ITU-R BT.2100 PQ (perceptual quantizer), aka SMPTE ST2048)\
12: HLG (ITU-R BT.2100 HLG (hybrid log-gamma), aka ARIB STD-B67)\
13: V_LOG (Panasonic V-Log (VARICAM))\
14: S_LOG1 (Sony S-Log1)\
15: S_LOG2 (Sony S-Log2)
12: PQ (ITU-R BT.2100 PQ (perceptual quantizer), aka SMPTE ST2048)\
13: HLG (ITU-R BT.2100 HLG (hybrid log-gamma), aka ARIB STD-B67)\
14: V_LOG (Panasonic V-Log (VARICAM))\
15: S_LOG1 (Sony S-Log1)\
16: S_LOG2 (Sony S-Log2)

Default: 1.

Expand Down Expand Up @@ -363,14 +364,15 @@ libplacebo_Shader(clip input, string shader, int "width", int "height", int "chr
7: GAMMA24 (Pure power gamma 2.4)\
8: GAMMA26 (Pure power gamma 2.6)\
9: GAMMA28 (Pure power gamma 2.8)\
10: PRO_PHOTO (ProPhoto RGB (ROMM))
10: PRO_PHOTO (ProPhoto RGB (ROMM))\
11: ST428 (Digital Cinema Distribution Master (XYZ))

High dynamic range:\
11: PQ (ITU-R BT.2100 PQ (perceptual quantizer), aka SMPTE ST2048)\
12: HLG (ITU-R BT.2100 HLG (hybrid log-gamma), aka ARIB STD-B67)\
13: V_LOG (Panasonic V-Log (VARICAM))\
14: S_LOG1 (Sony S-Log1)\
15: S_LOG2 (Sony S-Log2)
12: PQ (ITU-R BT.2100 PQ (perceptual quantizer), aka SMPTE ST2048)\
13: HLG (ITU-R BT.2100 HLG (hybrid log-gamma), aka ARIB STD-B67)\
14: V_LOG (Panasonic V-Log (VARICAM))\
15: S_LOG1 (Sony S-Log1)\
16: S_LOG2 (Sony S-Log2)

Default: 1.

Expand Down Expand Up @@ -535,6 +537,12 @@ libplacebo_Tonemap(clip input, int "src_csp", float "dst_csp", float "src_max",
To disable this logic entirely, set either one to a negative value.\
Default: scene_threshold_low = 5.5; scene_threshold_high = 10.0

- percentile\
Which percentile of the input image brightness histogram to consider as the true peak of the scene.\
If this is set to 100 (or 0), the brightest pixel is measured. Otherwise, the top of the frequency distribution is progressively cut off.\
Setting this too low will cause clipping of very bright details, but can improve the dynamic brightness range of scenes with very bright isolated highlights.\
The default of 99.995% is very conservative and should cause no major issues in typical content.

- intent\
The rendering intent to use for gamut mapping.\
0: PERCEPTUAL\
Expand All @@ -557,32 +565,43 @@ libplacebo_Tonemap(clip input, int "src_csp", float "dst_csp", float "src_max",
1: clip (Performs no tone-mapping, just clips out-of-range colors.\
Retains perfect color accuracy for in-range colors but completely destroys out-of-range information.\
Does not perform any black point adaptation.)\
2: bt2390 (EETF from the ITU-R Report BT.2390, a hermite spline roll-off with linear segment.\
2: st2094_40 (EETF from SMPTE ST 2094-40 Annex B, which uses the provided OOTF based on Bezier curves to perform tone-mapping.\
The OOTF used is adjusted based on the ratio between the targeted and actual display peak luminances.\
In the absence of HDR10+ metadata, falls back to a simple constant bezier curve with tunable knee point.\
The `tone_mapping_param` gives the target brightness adaptation strength for the knee point, defaulting to 0.7.)\
3: st2094_10 (EETF from SMPTE ST 2094-10 Annex B.2, which takes into account the input signal average luminance in addition to the maximum/minimum.\
The `tone_mapping_param` gives the target brightness adaptation strength for the knee point, defaulting to 0.5.\
Note: This does *not* currently include the subjective gain/offset/gamma controls defined in Annex B.3.)\
4: bt2390 (EETF from the ITU-R Report BT.2390, a hermite spline roll-off with linear segment.\
The knee point offset is configurable. Note that this defaults to 1.0, rather than the value of 0.5 from the ITU-R spec.)\
3: bt2446a (EETF from ITU-R Report BT.2446, method A.\
5: bt2446a (EETF from ITU-R Report BT.2446, method A.\
Can be used for both forward and inverse tone mapping. Not configurable.)\
4: spline (Simple spline consisting of two polynomials, joined by a single pivot point.\
The `tone_mapping_param` gives the pivot point (in PQ space), defaulting to 0.30.\
Can be used for both forward and inverse tone mapping.)\
5: reinhard (Simple non-linear, global tone mapping algorithm.\
6: spline (Simple spline consisting of two polynomials, joined by a single pivot point.\
Simple spline consisting of two polynomials, joined by a single pivot point, which is tuned based on the source scene average brightness (taking into account HDR10+ metadata if available).\
The `tone_mapping_param` can be used to tune the desired subjective contrast characteristics.\
Higher values make the curve steeper (closer to `clip`), preserving midtones at the cost of losing shadow/highlight details, while lower values make the curve shallower (closer to `linear`), preserving highlights at the cost of losing midtone contrast.\
Values above 1.0 are possible, resulting in an output with more contrast than the input.\
The default value is 0.5.\
This function can be used for both forward and inverse tone mapping.
7: reinhard (Simple non-linear, global tone mapping algorithm.\
Named after Erik Reinhard.\
The `tone_mapping_param` specifies the local contrast coefficient at the display peak.\
Essentially, a value of param=0.5 implies that the reference white will be about half as bright as when clipping.\
Defaults to 0.5, which results in the simplest formulation of this function.)\
6: mobius (Generalization of the reinhard tone mapping algorithm to support an additional linear slope near black.\
8: mobius (Generalization of the reinhard tone mapping algorithm to support an additional linear slope near black.\
The tone mapping `tone_mapping_param` indicates the trade-off between the linear section and the non-linear section.\
Essentially, for param=0.5, every color value below 0.5 will be mapped linearly, with the higher values being non-linearly tone mapped.\
Values near 1.0 make this curve behave like `clip`, and values near 0.0 make this curve behave like `reinhard`.\
The default value is 0.3, which provides a good balance between colorimetric accuracy and preserving out-of-gamut details.\
The name is derived from its function shape (ax+b)/(cx+d), which is known as a Möbius transformation in mathematics.)\
7: hable (Piece-wise, filmic tone-mapping algorithm developed by John Hable for use in Uncharted 2, inspired by a similar tone-mapping algorithm used by Kodak.\
9: hable (Piece-wise, filmic tone-mapping algorithm developed by John Hable for use in Uncharted 2, inspired by a similar tone-mapping algorithm used by Kodak.\
Popularized by its use in video games with HDR rendering.\
Preserves both dark and bright details very well, but comes with the drawback of changing the average brightness quite significantly.\
This is sort of similar to `reinhard` with `tone_mapping_param` 0.24.)\
8: gamma (Fits a gamma (power) function to transfer between the source and target color spaces, effectively resulting in a perceptual hard-knee joining two roughly linear sections.\
10: gamma (Fits a gamma (power) function to transfer between the source and target color spaces, effectively resulting in a perceptual hard-knee joining two roughly linear sections.\
This preserves details at all scales fairly accurately, but can result in an image with a muted or dull appearance.\
The `tone_mapping_param` is used as the cutoff point, defaulting to 0.5.)\
9: linear (Linearly stretches the input range to the output range, in PQ space.\
11: linear (Linearly stretches the input range to the output range, in PQ space.\
This will preserve all details accurately, but results in a significantly different average brightness.\
Can be used for inverse tone-mapping in addition to regular tone-mapping.\
The parameter can be used as an additional linear gain coefficient (defaulting to 1.0).)\
Expand All @@ -607,6 +626,24 @@ libplacebo_Tonemap(clip input, int "src_csp", float "dst_csp", float "src_max",
May help to improve the appearance of very bright, monochromatic highlights.\
Default: 0.04.

- metadata\
Data source to use when tone-mapping.\
Setting this to a specific value allows overriding the default metadata preference logic.\
0: ANY\
1: NONE\
2: HDR10 (HDR10 static mastering display metadata)\
3: HDR10PLUS (HDR10+ dynamic metadata)\
4: CIE_Y (CIE Y derived dynamic luminance metadata)

- visualize_lut\
Visualize the tone-mapping curve / LUT. (PQ-PQ graph)\
Default: False.

- show_clipping\
Graphically highlight hard-clipped pixels during tone-mapping (i.e. pixels that exceed the claimed source luminance range).\
Note that the difference between this and `gamut_mode=1` is that the latter only shows out-of-gamut colors (that are inside the monitor brightness range), while this shows out-of-range colors (regardless of whether or not they're in-gamut).\
Default: False.

- use_dovi\
Whether to use the Dolby Vision RPU for ST2086 metadata.\
Defaults to true when tonemapping from Dolby Vision.
Expand All @@ -629,26 +666,23 @@ libplacebo_Tonemap(clip input, int "src_csp", float "dst_csp", float "src_max",
Requirements:
- Clang-cl (https://github.com/llvm/llvm-project/releases)
- Vulkan SDK (https://vulkan.lunarg.com/sdk/home#windows)
- libp2p (https://github.com/sekrit-twc/libp2p)
- dolby_vision C-lib (https://github.com/quietvoid/dovi_tool/blob/main/dolby_vision/README.md)
- libplacebo (https://gitlab.com/uvz/libplacebo)
```
```
Steps:
Install Vulkan SDk.
Build libp2p.
Build dolby_vision.
Building libplacebo:
set LIB=%LIB%;C:\VulkanSDK\1.3.224.1\Lib
meson build -Dvulkan-registry=C:\VulkanSDK\1.3.224.1\share\vulkan\registry\vk.xml --default-library=static --buildtype=release -Ddemos=false -Dopengl=disabled -Dd3d11=disabled
set LIB=%LIB%;C:\VulkanSDK\1.3.239.0\Lib
meson build -Dvulkan-registry=C:\VulkanSDK\1.3.239.0\share\vulkan\registry\vk.xml --default-library=static --buildtype=release -Ddemos=false -Dopengl=disabled -Dd3d11=disabled
Use solution files to build avs_libplacebo.
```
- Linux
```
Requirements:
- Vulkan lib
- libp2p (https://github.com/sekrit-twc/libp2p)
- dolby_vision C-lib (https://github.com/quietvoid/dovi_tool/blob/main/dolby_vision/README.md)
- libplacebo (https://code.videolan.org/videolan/libplacebo)
- AviSynth lib
Expand Down
2 changes: 1 addition & 1 deletion dovi_tool
Submodule dovi_tool updated 109 files
1 change: 0 additions & 1 deletion libp2p
Submodule libp2p deleted from 5e6567
2 changes: 1 addition & 1 deletion libplacebo
Submodule libplacebo updated from c87c74 to 7b585b
12 changes: 6 additions & 6 deletions msvc/avs_libplacebo.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>llvm</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
Expand Down Expand Up @@ -73,13 +73,13 @@
<LibraryPath>..\..\libplacebo\build_x86\src;..\..\dovi_tool\target\i686-pc-windows-msvc\release;C:\Users\asdq\Downloads\dep_libs\lib;..\..\libp2p\_msvc\Release;..\..\Avisynth_3.7.3_20220419_test1\x86_xp\c_api;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>..\..\libp2p;..\..\dovi_tool\target\x86_64-pc-windows-msvc\debug\include;D:\libplacebo\build_x64_debug\src\include;C:\VulkanSDK\1.3.231.1\Include;..\..\libplacebo\src\include;..\..\AviSynthPlus\avs_core\include;$(IncludePath)</IncludePath>
<LibraryPath>..\..\dovi_tool\target\x86_64-pc-windows-msvc\debug;..\..\libp2p\_msvc\x64\Debug;..\..\AviSynthPlus\build_test\Output\c_api;C:\VulkanSDK\1.3.231.1\Lib;..\..\libplacebo\build_x64_debug\src;$(LibraryPath)</LibraryPath>
<IncludePath>..\..\libp2p;..\..\dovi_tool\dolby_vision\target\x86_64-pc-windows-msvc\release\include;D:\libplacebo\build_x64\src\include;C:\VulkanSDK\1.3.239.0\Include;..\..\libplacebo\src\include;..\..\AviSynthPlus\avs_core\include;$(IncludePath)</IncludePath>
<LibraryPath>..\..\dovi_tool\dolby_vision\target\x86_64-pc-windows-msvc\debug;..\..\libp2p\_msvc\x64\Debug;..\..\AviSynthPlus\build_test\Output\c_api;C:\VulkanSDK\1.3.239.0\Lib;..\..\libplacebo\build_x64\src;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\..\libplacebo\build_x64\src\include;..\..\libplacebo\src\include;..\..\dovi_tool\target_\x86_64-pc-windows-msvc\release\include;..\..\libp2p;C:\VulkanSDK\1.3.236.0\Include;..\..\AviSynthPlus\avs_core\include;$(IncludePath)</IncludePath>
<LibraryPath>..\..\dovi_tool\target_\x86_64-pc-windows-msvc\release;..\..\libplacebo\build_x64\src;..\..\libp2p\_msvc\x64\Release;C:\VulkanSDK\1.3.236.0\Lib;..\..\AviSynthPlus\build_x64\Output\c_api;$(LibraryPath)</LibraryPath>
<IncludePath>..\libplacebo\build\src\include;..\libplacebo\src\include;..\..\dovi_tool\dolby_vision\target\x86_64-pc-windows-msvc\release\include;C:\VulkanSDK\1.3.239.0\Include;..\..\AviSynthPlus\avs_core\include;$(IncludePath)</IncludePath>
<LibraryPath>..\..\dovi_tool\dolby_vision\target\x86_64-pc-windows-msvc\release;..\libplacebo\build\src;C:\VulkanSDK\1.3.239.0\Lib;..\..\AviSynthPlus\build_x64_clang\Output\c_api;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Label="LLVM" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<UseLldLink>true</UseLldLink>
Expand Down Expand Up @@ -147,7 +147,7 @@
</Link>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<AdditionalDependencies>libplacebo.a;vulkan-1.lib;shaderc_combined.lib;AviSynth.lib;p2p_simd.lib;dovi.lib;ws2_32.lib;bcrypt.lib;Userenv.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>libplacebo.a;vulkan-1.lib;shaderc_combined.lib;AviSynth.lib;dovi.lib;ws2_32.lib;bcrypt.lib;Userenv.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
31 changes: 5 additions & 26 deletions src/avs_libplacebo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

#include "avisynth_c.h"

extern "C" {
extern "C"
{
#include <libplacebo/renderer.h>
#include <libplacebo/dispatch.h>
#include <libplacebo/shaders.h>
Expand All @@ -19,29 +20,6 @@ void avs_libplacebo_uninit(std::unique_ptr<struct priv> p);

AVS_Value devices_info(AVS_Clip* clip, AVS_ScriptEnvironment* env, std::vector<VkPhysicalDevice>& devices, VkInstance& inst, std::string& msg, std::string name, const int device, const int list_device);

struct format
{
int num_comps;
int bitdepth;
};

struct plane
{
int subx, suby; // subsampling shift
struct format fmt;
size_t stride;
void* data;
};

#define MAX_PLANES 4

struct image
{
int width, height;
int num_planes;
struct plane planes[MAX_PLANES];
};

struct priv
{
pl_log log;
Expand All @@ -51,15 +29,16 @@ struct priv
pl_shader_obj dither_state;

pl_renderer rr;
pl_tex tex_in[MAX_PLANES];
pl_tex tex_out[MAX_PLANES];
pl_tex tex_in[4];
pl_tex tex_out[4];
};

AVS_Value AVSC_CC create_deband(AVS_ScriptEnvironment* env, AVS_Value args, void* param);
AVS_Value AVSC_CC create_resample(AVS_ScriptEnvironment* env, AVS_Value args, void* param);
AVS_Value AVSC_CC create_shader(AVS_ScriptEnvironment* env, AVS_Value args, void* param);
AVS_Value AVSC_CC create_tonemap(AVS_ScriptEnvironment* env, AVS_Value args, void* param);

[[maybe_unused]]
static AVS_FORCEINLINE AVS_Value set_error(AVS_Clip* clip, const char* error_message)
{
avs_release_clip(clip);
Expand Down
8 changes: 4 additions & 4 deletions src/avs_libplacebo.rc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <winver.h>

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,1,5,0
PRODUCTVERSION 1,1,5,0
FILEVERSION 1,2,0,0
PRODUCTVERSION 1,2,0,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEFLAGS 0x0L
FILEOS VOS__WINDOWS32
Expand All @@ -15,11 +15,11 @@ BEGIN
BEGIN
VALUE "Comments", "AviSynth+ plugin interface to libplacebo."
VALUE "FileDescription", "avs_libplacebo for AviSynth+."
VALUE "FileVersion", "1.1.5"
VALUE "FileVersion", "1.2.0"
VALUE "InternalName", "avs_libplacebo"
VALUE "OriginalFilename", "avs_libplacebo.dll"
VALUE "ProductName", "avs_libplacebo"
VALUE "ProductVersion", "1.1.5"
VALUE "ProductVersion", "1.2.0"
END
END
BLOCK "VarFileInfo"
Expand Down
2 changes: 1 addition & 1 deletion src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ std::unique_ptr<struct priv> avs_libplacebo_init(VkPhysicalDevice device)

void avs_libplacebo_uninit(std::unique_ptr<struct priv> p)
{
for (int i{ 0 }; i < MAX_PLANES; ++i)
for (int i{ 0 }; i < 4; ++i)
{
pl_tex_destroy(p->gpu, &p->tex_in[i]);
pl_tex_destroy(p->gpu, &p->tex_out[i]);
Expand Down
Loading

0 comments on commit 94faff9

Please sign in to comment.