Skip to content

Commit b3dece0

Browse files
author
Cristy
committed
https://github.com/ImageMagick/ImageMagick/issues/8375
1 parent b706c11 commit b3dece0

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

coders/jpeg.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,13 +1251,33 @@ static Image *ReadJPEGImage_(const ImageInfo *image_info,
12511251
/*
12521252
Set image resolution.
12531253
*/
1254+
image->x_resolution=DefaultResolution;
1255+
image->y_resolution=DefaultResolution;
12541256
units=0;
1255-
if ((jpeg_info->saw_JFIF_marker != 0) && (jpeg_info->X_density != 1) &&
1256-
(jpeg_info->Y_density != 1))
1257+
if (jpeg_info->saw_JFIF_marker != 0)
12571258
{
1258-
image->x_resolution=(double) jpeg_info->X_density;
1259-
image->y_resolution=(double) jpeg_info->Y_density;
1260-
units=(size_t) jpeg_info->density_unit;
1259+
if (jpeg_info->density_unit != 0)
1260+
{
1261+
/*
1262+
Units are defined: 1 = DPI, 2 = DPC.
1263+
*/
1264+
image->x_resolution=(double) jpeg_info->X_density;
1265+
image->y_resolution=(double) jpeg_info->Y_density;
1266+
units=(size_t) jpeg_info->density_unit;
1267+
}
1268+
else
1269+
{
1270+
/*
1271+
Optionally scale based on aspect ratio.
1272+
*/
1273+
if ((jpeg_info->X_density != 0) && (jpeg_info->Y_density != 0))
1274+
{
1275+
double aspect_ratio = (double) jpeg_info->Y_density/
1276+
(double) jpeg_info->X_density;
1277+
image->y_resolution=image->x_resolution*aspect_ratio;
1278+
}
1279+
units=1;
1280+
}
12611281
}
12621282
if (units == 1)
12631283
image->units=PixelsPerInchResolution;

0 commit comments

Comments
 (0)