Skip to content

Commit

Permalink
Minor code clean-up.
Browse files Browse the repository at this point in the history
  • Loading branch information
TurboGit committed Dec 28, 2021
1 parent 477bc5c commit c4e00c2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
33 changes: 16 additions & 17 deletions src/common/imageio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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 "
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
40 changes: 20 additions & 20 deletions src/libs/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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';
}
Expand All @@ -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';
}
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/libs/print_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params->prt);
dt_print_file(imgid, params->pdf_filename, params->job_title, &params->prt);
dt_control_job_set_progress(job, 1.0);

// add tag for this image
Expand Down

0 comments on commit c4e00c2

Please sign in to comment.