Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
erazortt committed Feb 11, 2024
1 parent 1343473 commit fedcf46
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 38 deletions.
8 changes: 8 additions & 0 deletions DoViBaker/AvisynthEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ AVSValue __cdecl Create_RealDoViTonemap(
env->ThrowError("DoViTonemap: valid range of knee offset is [0.5; 2.0]");
}

if (targetMaxNits < 0 || targetMinNits < 0) {
env->ThrowError("DoViTonemap: target capabilities must be given explicitly");
}

if (targetMaxNits < targetMinNits || masterMaxNits < masterMinNits) {
env->ThrowError("DoViTonemap: values given are invalid");
}

switch (clip->GetVideoInfo().BitsPerComponent())
{
case 10: return new DoViTonemap<10>(clip, targetMaxNits, targetMinNits, masterMaxNits, masterMinNits, lumScale, kneeOffset, normalizeOutput, env); break;
Expand Down
8 changes: 4 additions & 4 deletions DoViBaker/DoViBaker.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\DoViBaker.h" />
<ClInclude Include="..\include\DoViCubes.h" />
<ClInclude Include="..\include\DoViEetf.h" />
<ClInclude Include="..\include\DoViProcessor.h" />
<ClInclude Include="..\include\DoViStatsFileLoader.h" />
<ClInclude Include="..\include\DoViTonemap.h" />
<ClInclude Include="..\include\dovi\rpu_parser.h" />
<ClInclude Include="DoViCubes.h" />
<ClInclude Include="DoViEetf.h" />
<ClInclude Include="DoViStatsFileLoader.h" />
<ClInclude Include="DoViTonemap.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
Expand Down
8 changes: 4 additions & 4 deletions DoViBaker/DoViBaker.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@
<ClInclude Include="..\include\dovi\rpu_parser.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DoViCubes.h">
<ClInclude Include="..\include\DoViCubes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DoViStatsFileLoader.h">
<ClInclude Include="..\include\DoViEetf.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DoViEetf.h">
<ClInclude Include="..\include\DoViStatsFileLoader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DoViTonemap.h">
<ClInclude Include="..\include\DoViTonemap.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
Expand Down
20 changes: 9 additions & 11 deletions DoViBaker/DoViCubes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ DoViCubes::DoViCubes(
env->ThrowError((std::string("DoViCubes: cannot find cube file ") + cube_path).c_str());
}
std::unique_ptr<timecube_lut, TimecubeLutFree> cube{ timecube_lut_from_file(cube_path.c_str()) };
if (!cube)
throw std::runtime_error{ "DoViCubes: error reading LUT from file" };
if (!cube) {
env->ThrowError((std::string("DoViCubes: error reading LUT from file ") + cube_path).c_str());
}

timecube_filter* lut = timecube_filter_create(cube.get(), &params);
if (!lut)
throw std::runtime_error{ "DoViCubes: error creating LUT" };
if (!lut) {
env->ThrowError((std::string("DoViCubes: error creating LUT from file ") + cube_path).c_str());
}

luts.push_back(std::pair(cubes[i].first, lut));
}
Expand Down Expand Up @@ -98,13 +100,9 @@ PVideoFrame DoViCubes::GetFrame(int n, IScriptEnvironment* env)
PVideoFrame dst = env->NewVideoFrameP(vi, &src);

uint16_t maxCll = 0;
try {
if (env->propNumElements(env->getFramePropsRO(src), "_dovi_dynamic_max_content_light_level") > -1) {
maxCll = env->propGetInt(env->getFramePropsRO(src), "_dovi_dynamic_max_content_light_level", 0, 0);
} else throw std::runtime_error("");
} catch (...) {
env->ThrowError("DoViCubes: Expected frame property not available");
}
if (env->propNumElements(env->getFramePropsRO(src), "_dovi_dynamic_max_content_light_level") > -1) {
maxCll = env->propGetInt(env->getFramePropsRO(src), "_dovi_dynamic_max_content_light_level", 0, 0);
} else env->ThrowError("DoViCubes: Expected frame property not available");

currentFrameLut = luts[luts.size() - 1].second;
for (int i = 1; i < luts.size(); i++) {
Expand Down
38 changes: 19 additions & 19 deletions DoViBaker/DoViTonemap.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "DoViTonemap.h"
#include "DoViProcessor.h"
#include <stdexcept>

// explicitly instantiate the template for the linker
template class DoViTonemap<10>;
Expand Down Expand Up @@ -61,25 +60,26 @@ PVideoFrame DoViTonemap<signalBitDepth>::GetFrame(int n, IScriptEnvironment* env
uint16_t minPq = masterMinPq;
float scale = lumScale;

try {
if (dynamicMasterMaxPq) {
if (env->propNumElements(env->getFramePropsRO(src), "_dovi_dynamic_max_pq") > -1) {
maxPq = env->propGetInt(env->getFramePropsRO(src), "_dovi_dynamic_max_pq", 0, 0);
} else throw std::runtime_error("DoViTonemap: Expected frame property not available. Set 'masterMaxNits' explicitly.");
if (env->propNumElements(env->getFramePropsRO(src), "_ColorRange") > -1) {
bool limitedRange = env->propGetInt(env->getFramePropsRO(dst), "_ColorRange", 0, 0);
if (limitedRange) {
env->ThrowError("DoViTonemap: Only full range inputs supported");
}
if (dynamicMasterMinPq) {
if (env->propNumElements(env->getFramePropsRO(src), "_dovi_dynamic_min_pq") > -1) {
minPq = env->propGetInt(env->getFramePropsRO(src), "_dovi_dynamic_min_pq", 0, 0);
} else throw std::runtime_error("DoViTonemap: Expected frame property not available. Set 'masterMinNits' explicitly.");
}
if (dynamicLumScale) {
if (env->propNumElements(env->getFramePropsRO(src), "_dovi_dynamic_luminosity_scale") > -1) {
scale = env->propGetFloat(env->getFramePropsRO(src), "_dovi_dynamic_luminosity_scale", 0, 0);
} else throw std::runtime_error("DoViTonemap: Expected frame property not available. Set 'lumSacle' explicitly.");
}
} catch(std::exception &e) {
env->ThrowError(e.what());
return dst;
}
if (dynamicMasterMaxPq) {
if (env->propNumElements(env->getFramePropsRO(src), "_dovi_dynamic_max_pq") > -1) {
maxPq = env->propGetInt(env->getFramePropsRO(src), "_dovi_dynamic_max_pq", 0, 0);
} else env->ThrowError("DoViTonemap: Expected frame property not available. Set 'masterMaxNits' explicitly.");
}
if (dynamicMasterMinPq) {
if (env->propNumElements(env->getFramePropsRO(src), "_dovi_dynamic_min_pq") > -1) {
minPq = env->propGetInt(env->getFramePropsRO(src), "_dovi_dynamic_min_pq", 0, 0);
} else env->ThrowError("DoViTonemap: Expected frame property not available. Set 'masterMinNits' explicitly.");
}
if (dynamicLumScale) {
if (env->propNumElements(env->getFramePropsRO(src), "_dovi_dynamic_luminosity_scale") > -1) {
scale = env->propGetFloat(env->getFramePropsRO(src), "_dovi_dynamic_luminosity_scale", 0, 0);
} else env->ThrowError("DoViTonemap: Expected frame property not available. Set 'lumSacle' explicitly.");
}

if (maxPq != masterMaxPq || minPq != masterMinPq || std::abs(scale-lumScale)>0.001f) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit fedcf46

Please sign in to comment.