summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2023-05-04 09:17:15 -0400
committerGitHub <noreply@github.com>2023-05-04 09:17:15 -0400
commit2479d91f31e1d4687ad45aadc7da93ed16959f19 (patch)
tree6d0d549c5d3c37902349d6113de4f0814311c3c0
parent5ac2593ca31ca78857e8e4bf0a2a097b654d7f98 (diff)
downloadlcms2-2479d91f31e1d4687ad45aadc7da93ed16959f19.tar.gz
Simplify fixed-point to double conversion routines
No behavior change. I checked that old and new code has the same results: https://godbolt.org/z/Eo3GT7rzP
-rw-r--r--src/cmsplugin.c21
1 files changed, 2 insertions, 19 deletions
diff --git a/src/cmsplugin.c b/src/cmsplugin.c
index 3876506..e278832 100644
--- a/src/cmsplugin.c
+++ b/src/cmsplugin.c
@@ -364,12 +364,7 @@ cmsBool CMSEXPORT _cmsWriteXYZNumber(cmsIOHANDLER* io, const cmsCIEXYZ* XYZ)
// from Fixed point 8.8 to double
cmsFloat64Number CMSEXPORT _cms8Fixed8toDouble(cmsUInt16Number fixed8)
{
- cmsUInt8Number msb, lsb;
-
- lsb = (cmsUInt8Number) (fixed8 & 0xff);
- msb = (cmsUInt8Number) (((cmsUInt16Number) fixed8 >> 8) & 0xff);
-
- return (cmsFloat64Number) ((cmsFloat64Number) msb + ((cmsFloat64Number) lsb / 256.0));
+ return fixed8 / 256.0;
}
cmsUInt16Number CMSEXPORT _cmsDoubleTo8Fixed8(cmsFloat64Number val)
@@ -381,19 +376,7 @@ cmsUInt16Number CMSEXPORT _cmsDoubleTo8Fixed8(cmsFloat64Number val)
// from Fixed point 15.16 to double
cmsFloat64Number CMSEXPORT _cms15Fixed16toDouble(cmsS15Fixed16Number fix32)
{
- cmsFloat64Number floater, sign, mid;
- int Whole, FracPart;
-
- sign = (fix32 < 0 ? -1 : 1);
- fix32 = abs(fix32);
-
- Whole = (cmsUInt16Number)(fix32 >> 16) & 0xffff;
- FracPart = (cmsUInt16Number)(fix32 & 0xffff);
-
- mid = (cmsFloat64Number) FracPart / 65536.0;
- floater = (cmsFloat64Number) Whole + mid;
-
- return sign * floater;
+ return fix32 / 65536.0;
}
// from double to Fixed point 15.16