From 297789284b8680a1d15549dc2d192f3abc552160 Mon Sep 17 00:00:00 2001
From: Andrew Murray <radarhere@users.noreply.github.com>
Date: Mon, 22 Feb 2021 19:32:52 +1100
Subject: [PATCH] Fixed linear_gradient and radial_gradient 32-bit modes

Conflict:NA
Reference:https://github.com/python-pillow/Pillow/commit/297789284b8680a1d15549dc2d192f3abc552160
---
 Tests/test_image.py   |  4 ++--
 src/libImaging/Fill.c | 28 ++++++++++++++++++++++++----
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/Tests/test_image.py b/Tests/test_image.py
index f2a1917..54448f3 100644
--- a/Tests/test_image.py
+++ b/Tests/test_image.py
@@ -516,7 +516,7 @@ class TestImage:
 
         # Arrange
         target_file = "Tests/images/linear_gradient.png"
-        for mode in ["L", "P"]:
+        for mode in ["L", "P", "I", "F"]:
 
             # Act
             im = Image.linear_gradient(mode)
@@ -542,7 +542,7 @@ class TestImage:
 
         # Arrange
         target_file = "Tests/images/radial_gradient.png"
-        for mode in ["L", "P"]:
+        for mode in ["L", "P", "I", "F"]:
 
             # Act
             im = Image.radial_gradient(mode)
diff --git a/src/libImaging/Fill.c b/src/libImaging/Fill.c
index da143b4..6c6e107 100644
--- a/src/libImaging/Fill.c
+++ b/src/libImaging/Fill.c
@@ -79,8 +79,21 @@ ImagingFillLinearGradient(const char *mode)
         return NULL;
     }
 
-    for (y = 0; y < 256; y++) {
-        memset(im->image8[y], (unsigned char) y, 256);
+    if (im->image8) {
+        for (y = 0; y < 256; y++) {
+            memset(im->image8[y], (unsigned char)y, 256);
+        }
+    } else {
+        int x;
+        for (y = 0; y < 256; y++) {
+            for (x = 0; x < 256; x++) {
+                if (im->type == IMAGING_TYPE_FLOAT32) {
+                    IMAGING_PIXEL_FLOAT32(im, x, y) = y;
+                } else {
+                    IMAGING_PIXEL_INT32(im, x, y) = y;
+                }
+            }
+        }
     }
 
     return im;
@@ -106,9 +119,16 @@ ImagingFillRadialGradient(const char *mode)
         for (x = 0; x < 256; x++) {
             d = (int) sqrt((double) ((x-128)*(x-128) + (y-128)*(y-128)) * 2.0);
             if (d >= 255) {
-                im->image8[y][x] = 255;
-            } else {
+                d = 255;
+            }
+            if (im->image8) {
                 im->image8[y][x] = d;
+            } else {
+                if (im->type == IMAGING_TYPE_FLOAT32) {
+                    IMAGING_PIXEL_FLOAT32(im, x, y) = d;
+                } else {
+                    IMAGING_PIXEL_INT32(im, x, y) = d;
+                }
             }
         }
     }
-- 
2.23.0

