DGHDRtoSDR 1.11 by Donald A. Graft
---------------------------------

This Avisynth+/Vapoursynth filter converts HDR10 PQ from UHD blurays to 8-bit SDR YV12
or 10-bit SDR stored in YUV420P16. The input must be YUV420P16, e.g., from
DGSource(fulldepth=true). Support for HDR10 HLG will be added in a future version.

This filter runs on both CUDA and in software mode. If you try to run
in CUDA mode without an nVidia card and driver installed, you will get
an error. Use the parameter impl="sw" to run in software mode.

Here is a typical Avisynth+ script using default parameters:

loadplugin("dgdecodenv.dll")
loadplugin("dghdrtosdr.dll")
DGSource("hdr_sample.dgi",fulldepth=true)
DGHDRtoSDR()
prefetch(6)

Here is the Vapoursynth equivalent:

import vapoursynth as vs
core = vs.get_core()

core.std.LoadPlugin(path="DGHDRtoSDR.dll")
core.std.LoadPlugin(path="DGDecodeNV.dll")
video=core.dgdecodenv.DGSource("sample.dgi",fulldepth=True)
video=core.dghdrtosdr.DGHDRtoSDR(clip=video,fulldepth=True)
video.set_output()

The parameters are:

impl="sw" Software mode (very slow).
impl="255" Use CUDA, device is chosen automatically.
impl="0" Use CUDA on device 0 (use desired device number).
Default is "255".

fulldepth=false When set to false, 8-bit YV12 is output. When set to true,
10-bit stored in YUV420P16 is output. Use fulldepth=true if you intend to
make a 10-bit encoding. The default is false.

light=300.0 Target display brightness, lower values increase the resulting
output brightness. A good starting point is the maximum nits of your intended
display, although you may have to tweak it depending on the source mastering.
Default is 300.0. 

gamma=0.42 Final gamma for the output. The default is 0.42, standard for Rec.709.

hue=5.0 Hue adjustment used to correct hue shift due to the gamut mapping.
Values above 0.0 shift toward red. Values below 0.0 shift toward green. The
default value is 5.0.

sat=1.0 Saturation adjustment used to desaturate or resaturate the output.
Do not overdo it; 0.5 to 1.5 is probably the most you can get away with without
ruining colors. Values below 1.0 reduce saturation and values above 1.0
increase saturation. The default is 1.0.

tm=1.0 Strength of tonemapping. Reduce this towards 0.0 to smoothly transition
to blowout (clipping) of highlights. This value controls a LERP between Reinhard
tonemapping and no tonemapping. Default is 1.0.

roll=0.5 Rolloff strength of the tonemapping. Increase this towards 1.0 to soften
and desaturate the result. The default value of 0.5 is effective at retaining
saturation and contrast. This parameter also affects overall brightness so you may
have to adjust the light parameter as needed when changing the rolloff.

Cropping and Resizing:

Often the goal is to convert to HD bluray with a size of 1920 x 1080.
And sometimes one wants to crop as well. The fastest way to do this is to
use DGSource() cropping and resizing. Following is a typical script:

loadplugin("dgdecodenv.dll")
loadplugin("dghdrtosdr.dll")
dgsource("hdr sample.dgi",crop_t=276,crop_b=276,resize_w=1920,resize_h=804,fulldepth=true)
dghdrtosdr()
prefetch(6)

Alternatively, the cropping and resizing can be done in Avisynth. Do it before
calling dghdrtosdr() for best performance. Here is a script corresponding
to the one above:

loadplugin("dgdecodenv.dll")
loadplugin("dghdrtosdr.dll")
dgsource("hdr sample.dgi",fulldepth=true)
crop(0,276,-0,-276)
spline36resize(1920,804)
dghdrtosdr()
prefetch(6)

Copyright (c) 2018 Donald A. Graft, All Rights Reserved
