diff options
Diffstat (limited to 'src/generators.c')
| -rw-r--r-- | src/generators.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/generators.c b/src/generators.c index 5d5ba32..64ca08b 100644 --- a/src/generators.c +++ b/src/generators.c @@ -437,6 +437,19 @@ have_album_image_size_cb (gchar **args, gpointer user_data) return FALSE; } +static gboolean +have_fractional_hidpi_size (TGallerySetup *setup) +{ + int i; + double iptr; + + if (setup->design->hidpi_sizes) + for (i = 0; setup->design->hidpi_sizes[i] != 0; i++) + if (modf (setup->design->hidpi_sizes[i], &iptr) != 0.0) + return TRUE; + return FALSE; +} + static gboolean generate_image_for_size (TGallerySetup *setup, @@ -457,6 +470,7 @@ generate_image_for_size (TGallerySetup *setup, int src_img_quality, img_quality; ExifData *exif_data; int shave_amount; + gboolean hidpi_strict_dimensions; res = ! query_update; @@ -476,6 +490,7 @@ generate_image_for_size (TGallerySetup *setup, exif_data = exif_data_new_empty (); metadata_apply_overrides (exif_data, setup, path_info, items, item, image_size); + hidpi_strict_dimensions = image_size->is_hidpi; /* Do something when required */ res = res || needs_update (img_src, img_dst); @@ -515,8 +530,8 @@ generate_image_for_size (TGallerySetup *setup, return res; } /* Browsers need exactly n-factor of the original size */ - img_w = lround ((gdouble) ref_img_w * image_size->hidpi_scale_factor); - img_h = lround ((gdouble) ref_img_h * image_size->hidpi_scale_factor); + img_w = (gdouble) ref_img_w * image_size->hidpi_scale_factor; + img_h = (gdouble) ref_img_h * image_size->hidpi_scale_factor; if ((gdouble) img_w * (100 - setup->design->hidpi_upscale_threshold) / 100 > src_img_w || (gdouble) img_h * (100 - setup->design->hidpi_upscale_threshold) / 100 > src_img_h) { /* g_print (" Warning: source image %s (%lux%lu) is not large enough for the \"%s\" image size (need %lux%lu)\n", img_src, src_img_w, src_img_h, image_size->name, img_w, img_h); */ g_free (img_src); @@ -568,6 +583,13 @@ generate_image_for_size (TGallerySetup *setup, tmpw + image_size->no_resize_threshold, tmph + image_size->no_resize_threshold); */ } else { calculate_sizes (tmpw, tmph, &img_w, &img_h); + /* For HiDPI sizes that are not integer the base image dimensions must be even */ + if ((img_w % 2 != 0 || img_h % 2 != 0) && have_fractional_hidpi_size (setup)) { + img_w = img_w / 2 * 2; + img_h = img_h / 2 * 2; + /* This flag will take care of a convenient crop of the source image before resize based on the aspect ratio difference */ + hidpi_strict_dimensions = TRUE; + } if (setup->warn_resize) printf (" Warning: resizing image %s from %lux%lu to %lux%lu\n", img_src, src_img_w, src_img_h, img_w, img_h); } @@ -588,7 +610,7 @@ generate_image_for_size (TGallerySetup *setup, if (! copy_file (img_src, img_dst)) log_error (" Error copying image %s to %s\n", img_src, img_dst); } else { - if (! resize_image (img_src, img_dst, img_w, img_h, img_quality, image_size->is_thumbnail, setup->autorotate, image_size->is_hidpi, exif_data, + if (! resize_image (img_src, img_dst, img_w, img_h, img_quality, image_size->is_thumbnail, setup->autorotate, hidpi_strict_dimensions, exif_data, image_size->is_thumbnail ? setup->design->imgmagick_thumb_opts : setup->design->imgmagick_resize_opts)) log_error (" Error resizing image %s\n", img_src); } |
