ImBuf: calculate the JPEG DPI with double precision

These were calculated as floats then converted to doubles,
loosing precision unnecessarily.
This commit is contained in:
Campbell Barton 2023-09-20 12:11:37 +10:00
parent bdbf1871ec
commit e3b77cf08a
3 changed files with 6 additions and 6 deletions

View File

@ -546,7 +546,7 @@ bool IMB_initImBuf(ImBuf *ibuf, uint x, uint y, uchar planes, uint flags)
/* float option, is set to other values when buffers get assigned. */
ibuf->channels = 4;
/* IMB_DPI_DEFAULT -> pixels-per-meter. */
ibuf->ppm[0] = ibuf->ppm[1] = IMB_DPI_DEFAULT / 0.0254f;
ibuf->ppm[0] = ibuf->ppm[1] = IMB_DPI_DEFAULT / 0.0254;
if (flags & IB_rect) {
if (imb_addrectImBuf(ibuf) == false) {

View File

@ -44,4 +44,4 @@
# define BIG_LONG SWAP_LONG
#endif
#define IMB_DPI_DEFAULT 72.0f
#define IMB_DPI_DEFAULT 72.0

View File

@ -421,12 +421,12 @@ static ImBuf *ibJpegImageFromCinfo(
/* Density_unit may be 0 for unknown, 1 for dots/inch, or 2 for dots/cm. */
if (cinfo->density_unit == 1) {
/* Convert inches to meters. */
ibuf->ppm[0] = cinfo->X_density / 0.0254f;
ibuf->ppm[1] = cinfo->Y_density / 0.0254f;
ibuf->ppm[0] = double(cinfo->X_density) / 0.0254;
ibuf->ppm[1] = double(cinfo->Y_density) / 0.0254;
}
else if (cinfo->density_unit == 2) {
ibuf->ppm[0] = cinfo->X_density * 100.0f;
ibuf->ppm[1] = cinfo->Y_density * 100.0f;
ibuf->ppm[0] = double(cinfo->X_density) * 100.0;
ibuf->ppm[1] = double(cinfo->Y_density) * 100.0;
}
ibuf->ftype = IMB_FTYPE_JPG;