From b0732a0ed9c6b9988f6b2d5e7008c4c5732088c6 Mon Sep 17 00:00:00 2001
From: Cristy <urban-warrior@imagemagick.org>
Date: Mon, 1 Mar 2021 21:05:36 +0800
Subject: [PATCH] https://github.com/ImageMagick/ImageMagick/issues/1739

---
 magick/gem-private.h | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/magick/gem-private.h b/magick/gem-private.h
index fa464f0..0cfaf3b 100644
--- a/magick/gem-private.h
+++ b/magick/gem-private.h
@@ -132,6 +132,9 @@ static inline void ConvertXYZToLab(const double X,const double Y,const double Z,
 static inline void ConvertLuvToXYZ(const double L,const double u,const double v,
   double *X,double *Y,double *Z)
 {
+  double
+    gamma;
+
   assert(X != (double *) NULL);
   assert(Y != (double *) NULL);
   assert(Z != (double *) NULL);
@@ -139,9 +142,10 @@ static inline void ConvertLuvToXYZ(const double L,const double u,const double v,
     *Y=(double) pow((L+16.0)/116.0,3.0);
   else
     *Y=L/CIEK;
-  *X=((*Y*((39.0*L/(v+13.0*L*(9.0*D65Y/(D65X+15.0*D65Y+3.0*D65Z))))-5.0))+
-    5.0*(*Y))/((((52.0f*L/(u+13.0*L*(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z))))-1.0)/
-    3.0)-(-1.0/3.0));
+  gamma=PerceptibleReciprocal((((52.0*L/(u+13.0*L*(4.0*D65X/(D65X+15.0*D65Y+
+    3.0*D65Z))))-1.0)/3.0)-(-1.0/3.0));
+  *X=gamma*((*Y*((39.0*L/(v+13.0*L*(9.0*D65Y/(D65X+15.0*D65Y+3.0*D65Z))))-5.0))+
+    5.0*(*Y));
   *Z=(*X*(((52.0f*L/(u+13.0*L*(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z))))-1.0)/3.0))-
     5.0*(*Y);
 }
-- 
2.23.0

