Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make denoiseprofile less log-noisy #18033

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions src/common/noiseprofiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

const dt_noiseprofile_t dt_noiseprofile_generic = {N_("generic poissonian"), "", "", 0, {0.0001f, 0.0001f, 0.0001}, {0.0f, 0.0f, 0.0f}};

static gboolean dt_noiseprofile_verify(JsonParser *parser);
static gboolean _noiseprofile_verify(JsonParser *parser);

JsonParser *dt_noiseprofile_init(const char *alternative)
{
Expand All @@ -42,8 +42,11 @@ JsonParser *dt_noiseprofile_init(const char *alternative)
else
g_strlcpy(filename, alternative, sizeof(filename));

dt_print(DT_DEBUG_CONTROL, "[noiseprofile] loading noiseprofiles from `%s'", filename);
if(!g_file_test(filename, G_FILE_TEST_EXISTS)) return NULL;
if(!g_file_test(filename, G_FILE_TEST_EXISTS))
{
dt_print(DT_DEBUG_CONTROL, "[noiseprofile] can't load noiseprofiles from `%s'", filename);
return NULL;
}

// TODO: shall we cache the content? for now this looks fast enough(TM)
JsonParser *parser = json_parser_new();
Expand All @@ -56,7 +59,7 @@ JsonParser *dt_noiseprofile_init(const char *alternative)
}

// run over the file once to verify that it is sane
if(!dt_noiseprofile_verify(parser))
if(!_noiseprofile_verify(parser))
{
dt_control_log(_("noiseprofile file `%s' is not valid"), filename);
dt_print(DT_DEBUG_ALWAYS, "[noiseprofile] error: `%s' is not a valid noiseprofile file. run with -d control for details", filename);
jenshannoschwalm marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -92,12 +95,12 @@ static gint _sort_by_iso(gconstpointer a, gconstpointer b)
goto end;\
}

static gboolean dt_noiseprofile_verify(JsonParser *parser)
static gboolean _noiseprofile_verify(JsonParser *parser)
{
JsonReader *reader = NULL;
gboolean valid = TRUE;

dt_print(DT_DEBUG_CONTROL, "[noiseprofile] verifying noiseprofile file");
dt_print(DT_DEBUG_CONTROL | DT_DEBUG_VERBOSE, "[noiseprofile] verifying noiseprofile file");

JsonNode *root = json_parser_get_root(parser);
if(!root) _ERROR("can't get the root node");
Expand All @@ -120,35 +123,35 @@ static gboolean dt_noiseprofile_verify(JsonParser *parser)

// go through all makers
const int n_makers = json_reader_count_elements(reader);
dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %d makers", n_makers);
dt_print(DT_DEBUG_CONTROL | DT_DEBUG_VERBOSE, "[noiseprofile] found %d makers", n_makers);
for(int i = 0; i < n_makers; i++)
{
if(!json_reader_read_element(reader, i)) _ERROR("can't access maker at position %d / %d", i+1, n_makers);

if(!json_reader_read_member(reader, "maker")) _ERROR("missing `maker`");

dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found maker `%s'", json_reader_get_string_value(reader));
dt_print(DT_DEBUG_CONTROL | DT_DEBUG_VERBOSE, "[noiseprofile] found maker `%s'", json_reader_get_string_value(reader));
// go through all models and check those
json_reader_end_member(reader);

if(!json_reader_read_member(reader, "models")) _ERROR("missing `models`");

const int n_models = json_reader_count_elements(reader);
dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %d models", n_models);
dt_print(DT_DEBUG_CONTROL | DT_DEBUG_VERBOSE, "[noiseprofile] found %d models", n_models);
n_profiles_total += n_models;
for(int j = 0; j < n_models; j++)
{
if(!json_reader_read_element(reader, j)) _ERROR("can't access model at position %d / %d", j+1, n_models);

if(!json_reader_read_member(reader, "model")) _ERROR("missing `model`");

dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %s", json_reader_get_string_value(reader));
dt_print(DT_DEBUG_CONTROL | DT_DEBUG_VERBOSE, "[noiseprofile] found %s", json_reader_get_string_value(reader));
json_reader_end_member(reader);

if(!json_reader_read_member(reader, "profiles")) _ERROR("missing `profiles`");

const int n_profiles = json_reader_count_elements(reader);
dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %d profiles", n_profiles);
dt_print(DT_DEBUG_CONTROL | DT_DEBUG_VERBOSE, "[noiseprofile] found %d profiles", n_profiles);
for(int k = 0; k < n_profiles; k++)
{
if(!json_reader_read_element(reader, k)) _ERROR("can't access profile at position %d / %d", k+1, n_profiles);
Expand Down Expand Up @@ -212,8 +215,8 @@ static gboolean dt_noiseprofile_verify(JsonParser *parser)

json_reader_end_member(reader);

dt_print(DT_DEBUG_CONTROL, "[noiseprofile] verifying noiseprofile completed");
dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %zu profiles total", n_profiles_total);
dt_print(DT_DEBUG_CONTROL | DT_DEBUG_VERBOSE, "[noiseprofile] verifying noiseprofile completed");
dt_print(DT_DEBUG_CONTROL | DT_DEBUG_VERBOSE, "[noiseprofile] found %zu profiles total", n_profiles_total);

end:
if(reader) g_object_unref(reader);
Expand All @@ -229,7 +232,7 @@ GList *dt_noiseprofile_get_matching(const dt_image_t *cimg)

if(!parser) goto end;

dt_print(DT_DEBUG_CONTROL, "[noiseprofile] looking for maker `%s', model `%s'", cimg->camera_maker, cimg->camera_model);
dt_print(DT_DEBUG_CONTROL | DT_DEBUG_VERBOSE, "[noiseprofile] looking for maker `%s', model `%s'", cimg->camera_maker, cimg->camera_model);

JsonNode *root = json_parser_get_root(parser);

Expand All @@ -239,7 +242,7 @@ GList *dt_noiseprofile_get_matching(const dt_image_t *cimg)

// go through all makers
const int n_makers = json_reader_count_elements(reader);
dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %d makers", n_makers);
dt_print(DT_DEBUG_CONTROL | DT_DEBUG_VERBOSE, "[noiseprofile] found %d makers", n_makers);
for(int i = 0; i < n_makers; i++)
{
json_reader_read_element(reader, i);
Expand All @@ -248,14 +251,14 @@ GList *dt_noiseprofile_get_matching(const dt_image_t *cimg)

if(g_strstr_len(cimg->camera_maker, -1, json_reader_get_string_value(reader)))
{
dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found `%s' as `%s'", cimg->camera_maker, json_reader_get_string_value(reader));
dt_print(DT_DEBUG_CONTROL | DT_DEBUG_VERBOSE, "[noiseprofile] found `%s' as `%s'", cimg->camera_maker, json_reader_get_string_value(reader));
// go through all models and check those
json_reader_end_member(reader);

json_reader_read_member(reader, "models");

const int n_models = json_reader_count_elements(reader);
dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %d models", n_models);
dt_print(DT_DEBUG_CONTROL | DT_DEBUG_VERBOSE, "[noiseprofile] found %d models", n_models);
for(int j = 0; j < n_models; j++)
{
json_reader_read_element(reader, j);
Expand All @@ -264,14 +267,14 @@ GList *dt_noiseprofile_get_matching(const dt_image_t *cimg)

if(!g_strcmp0(cimg->camera_model, json_reader_get_string_value(reader)))
{
dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %s", cimg->camera_model);
dt_print(DT_DEBUG_CONTROL | DT_DEBUG_VERBOSE, "[noiseprofile] found %s", cimg->camera_model);
// we got a match, return at most bufsize elements
json_reader_end_member(reader);

json_reader_read_member(reader, "profiles");

const int n_profiles = json_reader_count_elements(reader);
dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %d profiles", n_profiles);
dt_print(DT_DEBUG_CONTROL | DT_DEBUG_VERBOSE, "[noiseprofile] found %d profiles", n_profiles);
for(int k = 0; k < n_profiles; k++)
{
dt_noiseprofile_t tmp_profile = { 0 };
Expand Down
Loading