From c4e00c2c24992ddc284fb9bbc368007d4d0ef339 Mon Sep 17 00:00:00 2001 From: Pascal Obry Date: Tue, 28 Dec 2021 18:49:23 +0100 Subject: [PATCH] Minor code clean-up. --- src/common/imageio.c | 33 ++++++++++++++++---------------- src/libs/export.c | 40 +++++++++++++++++++-------------------- src/libs/print_settings.c | 2 +- 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/common/imageio.c b/src/common/imageio.c index db9dbf23c007..9fd012ad06bb 100644 --- a/src/common/imageio.c +++ b/src/common/imageio.c @@ -169,7 +169,7 @@ int dt_imageio_large_thumbnail(const char *filename, uint8_t **buffer, int32_t * image = NewMagickWand(); mret = MagickReadImageBlob(image, buf, bufsize); - if (mret != MagickTrue) + if(mret != MagickTrue) { fprintf(stderr, "[dt_imageio_large_thumbnail IM] thumbnail not found?\n"); goto error_im; @@ -189,10 +189,10 @@ int dt_imageio_large_thumbnail(const char *filename, uint8_t **buffer, int32_t * } *buffer = malloc(sizeof(uint8_t) * (*width) * (*height) * 4); - if (*buffer == NULL) goto error_im; + if(*buffer == NULL) goto error_im; mret = MagickExportImagePixels(image, 0, 0, *width, *height, "RGBP", CharPixel, *buffer); - if (mret != MagickTrue) { + if(mret != MagickTrue) { free(*buffer); *buffer = NULL; fprintf(stderr, @@ -204,7 +204,7 @@ int dt_imageio_large_thumbnail(const char *filename, uint8_t **buffer, int32_t * error_im: DestroyMagickWand(image); - if (res != 0) goto error; + if(res != 0) goto error; #else fprintf(stderr, "[dt_imageio_large_thumbnail] error: The thumbnail image is not in " @@ -834,15 +834,15 @@ int dt_imageio_export_with_flags(const int32_t imgid, const char *filename, */ const gboolean iscropped = - ((pipe.processed_width < (wd - img->crop_x - img->crop_width)) || - (pipe.processed_height < (ht - img->crop_y - img->crop_height))); + ( (pipe.processed_width < (wd - img->crop_x - img->crop_width)) + || (pipe.processed_height < (ht - img->crop_y - img->crop_height))); - const gboolean exact_size = ( - iscropped || - upscale || - (format_params->max_width != 0) || - (format_params->max_height != 0) || - thumbnail_export); + const gboolean exact_size = + iscropped + || upscale + || (format_params->max_width != 0) + || (format_params->max_height != 0) + || thumbnail_export; int width = format_params->max_width > 0 ? format_params->max_width : 0; int height = format_params->max_height > 0 ? format_params->max_height : 0; @@ -853,7 +853,7 @@ int dt_imageio_export_with_flags(const int32_t imgid, const char *filename, height = pipe.processed_height; } - const double max_scale = ( upscale && ( width > 0 || height > 0 )) ? 100.0 : 1.0; + const double max_scale = (upscale && (width > 0 || height > 0)) ? 100.0 : 1.0; const double scalex = width > 0 ? fmin((double)width / (double)pipe.processed_width, max_scale) : max_scale; const double scaley = height > 0 ? fmin((double)height / (double)pipe.processed_height, max_scale) : max_scale; @@ -879,16 +879,15 @@ int dt_imageio_export_with_flags(const int32_t imgid, const char *filename, const gboolean is_scaling = dt_conf_is_equal("plugins/lighttable/export/resizing", "scaling"); - if (is_scaling) + if(is_scaling) { // scaling - double scale_factor = 1; double _num, _denum; dt_imageio_resizing_factor_get_and_parsing(&_num, &_denum); - scale_factor = _num / _denum; + const double scale_factor = _num / _denum; - if (!thumbnail_export) + if(!thumbnail_export) { scale = fmin(scale_factor, max_scale); } diff --git a/src/libs/export.c b/src/libs/export.c index b133ad54385a..91a5e3103e74 100644 --- a/src/libs/export.c +++ b/src/libs/export.c @@ -221,9 +221,9 @@ static void _scale_optim() gchar *pdiv = strchr(scale_str, '/'); gchar scale_buf[64] = ""; - if (pdiv == NULL) + if(pdiv == NULL) { - if (_is_int(num) && num > 0.0) + if(_is_int(num) && num > 0.0) { sprintf(_str, "%d", (int) num); g_strlcat(scale_buf, _str, sizeof(scale_buf)); @@ -233,9 +233,9 @@ static void _scale_optim() g_strlcat(scale_buf, scale_str, sizeof(scale_buf)); } } - else if (pdiv-scale_str == 0) + else if(pdiv-scale_str == 0) { - if (_is_int(denum) && denum > 0.0) + if(_is_int(denum) && denum > 0.0) { sprintf(_str, "%d", (int) denum); g_strlcat(scale_buf, _str, sizeof(scale_buf)); @@ -248,7 +248,7 @@ static void _scale_optim() } else { - if (_is_int(num) && num > 0.0) + if(_is_int(num) && num > 0.0) { sprintf(_str, "%d", (int) num); g_strlcat(scale_buf, _str, sizeof(scale_buf)); @@ -258,7 +258,7 @@ static void _scale_optim() g_strlcat(scale_buf, scale_str, sizeof(scale_buf)); } g_strlcat(scale_buf, "/", sizeof(scale_buf)); - if (_is_int(denum) && denum > 0.0) + if(_is_int(denum) && denum > 0.0) { sprintf(_str, "%d", (int) denum); g_strlcat(scale_buf, _str, sizeof(scale_buf)); @@ -385,17 +385,17 @@ static void _scale_changed(GtkEntry *spin, dt_lib_export_t *d) for (i = 0; i < len; i++) { char *val = strchr(validSign, value[i]); - if (val == NULL) + if(val == NULL) { - if (idiv==0) + if(idiv==0) { - if (i == 0) + if(i == 0) { new_value[j++] = '1'; } else { - if (atof(value) == 0.0) + if(atof(value) == 0.0) { new_value[0] = '1'; } @@ -406,11 +406,11 @@ static void _scale_changed(GtkEntry *spin, dt_lib_export_t *d) } } } - else if ((val[0] == '.') || (val[0] == ',')) + else if((val[0] == '.') || (val[0] == ',')) { - if (idec == 0) + if(idec == 0) { - if ((i == 0) || (i == pdiv)) + if((i == 0) || (i == pdiv)) { new_value[j++] = '0'; } @@ -421,7 +421,7 @@ static void _scale_changed(GtkEntry *spin, dt_lib_export_t *d) } } } - else if (value[i] == '\0') + else if(value[i] == '\0') { break; } @@ -439,7 +439,7 @@ static void _height_changed(GtkEditable *entry, gpointer user_data); static gboolean _scale_mdlclick(GtkEntry *spin, GdkEventButton *event, dt_lib_export_t *d) { - if (event->button == 2) + if(event->button == 2) { dt_conf_set_string(CONFIG_PREFIX "resizing_factor", "1"); g_signal_handlers_block_by_func(spin, _scale_changed, d); @@ -455,7 +455,7 @@ static gboolean _scale_mdlclick(GtkEntry *spin, GdkEventButton *event, dt_lib_ex static void _widht_mdlclick(GtkEntry *spin, GdkEventButton *event, gpointer user_data) { - if (event->button == 2) + if(event->button == 2) { dt_conf_set_int(CONFIG_PREFIX "width", 0); g_signal_handlers_block_by_func(spin, _width_changed, user_data); @@ -470,7 +470,7 @@ static void _widht_mdlclick(GtkEntry *spin, GdkEventButton *event, gpointer user static void _height_mdlclick(GtkEntry *spin, GdkEventButton *event, gpointer user_data) { - if (event->button == 2) + if(event->button == 2) { dt_conf_set_int(CONFIG_PREFIX "height", 0); g_signal_handlers_block_by_func(spin, _height_changed, user_data); @@ -487,7 +487,7 @@ static void _size_in_px_update(dt_lib_export_t *d) { const dt_dimensions_type_t d_type = (dt_dimensions_type_t)dt_bauhaus_combobox_get(d->dimensions_type); - if ((d_type == DT_DIMENSIONS_SCALE) || (d_type == DT_DIMENSIONS_PIXELS)) + if((d_type == DT_DIMENSIONS_SCALE) || (d_type == DT_DIMENSIONS_PIXELS)) { gtk_widget_hide(d->size_in_px); } @@ -534,7 +534,7 @@ void _print_size_update_display(dt_lib_export_t *self) else { const gboolean is_scaling = dt_conf_is_equal(CONFIG_PREFIX "resizing", "scaling"); - if (!is_scaling) + if(!is_scaling) { // max size gtk_widget_set_visible(GTK_WIDGET(self->print_size), TRUE); @@ -1407,7 +1407,7 @@ void gui_init(dt_lib_module_t *self) dt_bauhaus_combobox_set(d->dimensions_type, dt_conf_get_int(CONFIG_PREFIX "dimensions_type")); const gboolean is_scaling = dt_conf_is_equal(CONFIG_PREFIX "resizing", "scaling"); - if (is_scaling) + if(is_scaling) { // scaling gtk_widget_show(GTK_WIDGET(d->scale)); diff --git a/src/libs/print_settings.c b/src/libs/print_settings.c index 8969f5a70ee5..e57cb3c62c8d 100644 --- a/src/libs/print_settings.c +++ b/src/libs/print_settings.c @@ -513,7 +513,7 @@ static int _print_job_run(dt_job_t *job) // send to CUPS - dt_print_file (imgid, params->pdf_filename, params->job_title, ¶ms->prt); + dt_print_file(imgid, params->pdf_filename, params->job_title, ¶ms->prt); dt_control_job_set_progress(job, 1.0); // add tag for this image