shithub: hugo

Download patch

ref: 13ea1e7c352852966f88ef119d9434bbb1ee62fa
parent: 9f740b37cfb3278e34a5d085380ccd4d619dabff
author: Bjørn Erik Pedersen <[email protected]>
date: Mon Feb 26 13:55:00 EST 2018

resource: Use Floyd-Steinberg dithering for PNGs

Fixes #4453

--- a/resource/image.go
+++ b/resource/image.go
@@ -80,7 +80,7 @@
 	// Add or increment if changes to an image format's processing requires
 	// re-generation.
 	imageFormatsVersions = map[imaging.Format]int{
-		imaging.PNG: 1, // 1: Add proper palette handling
+		imaging.PNG: 2, // Floyd Steinberg dithering
 	}
 
 	// Increment to mark all processed images as stale. Only use when absolutely needed.
@@ -266,7 +266,7 @@
 			// Apply the colour palette from the source
 			if paletted, ok := src.(*image.Paletted); ok {
 				tmp := image.NewPaletted(converted.Bounds(), paletted.Palette)
-				draw.Src.Draw(tmp, tmp.Bounds(), converted, converted.Bounds().Min)
+				draw.FloydSteinberg.Draw(tmp, tmp.Bounds(), converted, converted.Bounds().Min)
 				converted = tmp
 			}
 		}
--- a/resource/image_test.go
+++ b/resource/image_test.go
@@ -273,7 +273,7 @@
 	resized, err := image.Resize("800x")
 	assert.NoError(err)
 	assert.Equal(imaging.PNG, resized.format)
-	assert.Equal("/a/gohugoio_hu0e1b9e4a4be4d6f86c7b37b9ccce3fbc_73886_800x0_resize_linear_1.png", resized.RelPermalink())
+	assert.Equal("/a/gohugoio_hu0e1b9e4a4be4d6f86c7b37b9ccce3fbc_73886_800x0_resize_linear_2.png", resized.RelPermalink())
 	assert.Equal(800, resized.Width())
 
 }