commit 9f8964affe255c8b6f0ae65e3c1cf9e496dac34a
parent 74033e320b1ed16f581302a33809e044e1228c3b
Author: Jack Mordaunt <jackmordaunt@gmail.com>
Date: Mon, 29 Jan 2018 19:28:30 +0100
[+] Can now configure interpolation function.
Diffstat:
| A | interp.go | | | 44 | ++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 44 insertions(+), 0 deletions(-)
diff --git a/interp.go b/interp.go
@@ -0,0 +1,44 @@
+package icns
+
+import (
+ "image"
+ "io"
+
+ "github.com/nfnt/resize"
+)
+
+// InterpolationFunction is the algorithm used to resize the image.
+type InterpolationFunction = resize.InterpolationFunction
+
+// InterpolationFunction constants.
+const (
+ // Nearest-neighbor interpolation
+ NearestNeighbor InterpolationFunction = iota
+ // Bilinear interpolation
+ Bilinear
+ // Bicubic interpolation (with cubic hermite spline)
+ Bicubic
+ // Mitchell-Netravali interpolation
+ MitchellNetravali
+ // Lanczos interpolation (a=2)
+ Lanczos2
+ // Lanczos interpolation (a=3)
+ Lanczos3
+)
+
+// EncodeWithInterpolationFunction uses the given interpolation function resize
+// the image before writing out to wr.
+func EncodeWithInterpolationFunction(
+ wr io.Writer,
+ img image.Image,
+ interp InterpolationFunction,
+) error {
+ iconset, err := NewIconSet(img, interp)
+ if err != nil {
+ return err
+ }
+ if _, err := iconset.WriteTo(wr); err != nil {
+ return err
+ }
+ return nil
+}