plug-ins: check for invalid resolution when loading TIFF image

This is essentially the same check as done in gimp_image_set_resolution,
but doing it here means we can load the image instead of throwing an
error.

We still need to get replacement xres and yres values, because these are
used to compute layer_offset_x_pixel and layer_offset_y_pixel.
This commit is contained in:
Jacob Boerema 2022-08-22 22:21:33 -04:00
parent 18d466df7f
commit ced071a8ee
1 changed files with 18 additions and 4 deletions

View File

@ -1371,11 +1371,25 @@ load_image (GFile *file,
*/
if (read_unit != RESUNIT_NONE)
{
gimp_image_set_resolution (*image, xres, yres);
if (unit != GIMP_UNIT_PIXEL)
gimp_image_set_unit (*image, unit);
if (! isfinite (xres) ||
xres < GIMP_MIN_RESOLUTION || xres > GIMP_MAX_RESOLUTION ||
! isfinite (yres) ||
yres < GIMP_MIN_RESOLUTION || yres > GIMP_MAX_RESOLUTION)
{
g_message (_("Invalid image resolution info, using default"));
/* We need valid xres and yres for computing
* layer_offset_x_pixel and layer_offset_y_pixel.
*/
gimp_image_get_resolution (*image, &xres, &yres);
}
else
{
gimp_image_set_resolution (*image, xres, yres);
if (unit != GIMP_UNIT_PIXEL)
gimp_image_set_unit (*image, unit);
*resolution_loaded = TRUE;
*resolution_loaded = TRUE;
}
}
}