From fedcf46f1c633d3260b0953f0a87d62b15a20ab2 Mon Sep 17 00:00:00 2001 From: erazortt Date: Sun, 11 Feb 2024 19:43:55 +0100 Subject: [PATCH] code cleanup --- DoViBaker/AvisynthEntry.cpp | 8 +++++ DoViBaker/DoViBaker.vcxproj | 8 ++--- DoViBaker/DoViBaker.vcxproj.filters | 8 ++--- DoViBaker/DoViCubes.cpp | 20 +++++------ DoViBaker/DoViTonemap.cpp | 38 ++++++++++---------- {DoViBaker => include}/DoViCubes.h | 0 {DoViBaker => include}/DoViEetf.h | 0 {DoViBaker => include}/DoViStatsFileLoader.h | 0 {DoViBaker => include}/DoViTonemap.h | 0 9 files changed, 44 insertions(+), 38 deletions(-) rename {DoViBaker => include}/DoViCubes.h (100%) rename {DoViBaker => include}/DoViEetf.h (100%) rename {DoViBaker => include}/DoViStatsFileLoader.h (100%) rename {DoViBaker => include}/DoViTonemap.h (100%) diff --git a/DoViBaker/AvisynthEntry.cpp b/DoViBaker/AvisynthEntry.cpp index c2ed23e..08a9906 100644 --- a/DoViBaker/AvisynthEntry.cpp +++ b/DoViBaker/AvisynthEntry.cpp @@ -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; diff --git a/DoViBaker/DoViBaker.vcxproj b/DoViBaker/DoViBaker.vcxproj index bcecd59..2543f1d 100644 --- a/DoViBaker/DoViBaker.vcxproj +++ b/DoViBaker/DoViBaker.vcxproj @@ -37,12 +37,12 @@ + + + + - - - - 15.0 diff --git a/DoViBaker/DoViBaker.vcxproj.filters b/DoViBaker/DoViBaker.vcxproj.filters index 159ef17..c0f5068 100644 --- a/DoViBaker/DoViBaker.vcxproj.filters +++ b/DoViBaker/DoViBaker.vcxproj.filters @@ -47,16 +47,16 @@ Header Files - + Header Files - + Header Files - + Header Files - + Header Files diff --git a/DoViBaker/DoViCubes.cpp b/DoViBaker/DoViCubes.cpp index ee94adc..203d034 100644 --- a/DoViBaker/DoViCubes.cpp +++ b/DoViBaker/DoViCubes.cpp @@ -53,12 +53,14 @@ DoViCubes::DoViCubes( env->ThrowError((std::string("DoViCubes: cannot find cube file ") + cube_path).c_str()); } std::unique_ptr 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(), ¶ms); - 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)); } @@ -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++) { diff --git a/DoViBaker/DoViTonemap.cpp b/DoViBaker/DoViTonemap.cpp index 1bf60dd..e96a69e 100644 --- a/DoViBaker/DoViTonemap.cpp +++ b/DoViBaker/DoViTonemap.cpp @@ -1,6 +1,5 @@ #include "DoViTonemap.h" #include "DoViProcessor.h" -#include // explicitly instantiate the template for the linker template class DoViTonemap<10>; @@ -61,25 +60,26 @@ PVideoFrame DoViTonemap::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) { diff --git a/DoViBaker/DoViCubes.h b/include/DoViCubes.h similarity index 100% rename from DoViBaker/DoViCubes.h rename to include/DoViCubes.h diff --git a/DoViBaker/DoViEetf.h b/include/DoViEetf.h similarity index 100% rename from DoViBaker/DoViEetf.h rename to include/DoViEetf.h diff --git a/DoViBaker/DoViStatsFileLoader.h b/include/DoViStatsFileLoader.h similarity index 100% rename from DoViBaker/DoViStatsFileLoader.h rename to include/DoViStatsFileLoader.h diff --git a/DoViBaker/DoViTonemap.h b/include/DoViTonemap.h similarity index 100% rename from DoViBaker/DoViTonemap.h rename to include/DoViTonemap.h