commit cb4307b7502e9bfa91daae633b6d9212bf1385eb
parent 06d845a483030377bf2d2479f88974809f9a87bf
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Fri, 18 Sep 2026 16:09:28 -0400
icns: take the interpolation function in resizeSquare
Call sites had to reach for the unexported scaler before calling the helper,
spreading the choice of resampler across the encoder for no gain. Selecting
it is a switch over package-level kernels, so doing that per icon rather than
once costs nothing.
Diffstat:
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/icns.go b/icns.go
@@ -65,7 +65,6 @@ func NewIconSet(img image.Image, interp InterpolationFunction) (*IconSet, error)
return nil, ErrImageTooSmall{image: img, need: 16}
}
icons := make([]*Icon, len(osTypes))
- scaler := interp.scaler()
work := sync.WaitGroup{}
var iconIdx int
for _, size := range sizesFrom(biggest) {
@@ -79,7 +78,7 @@ func NewIconSet(img image.Image, interp InterpolationFunction) (*IconSet, error)
go func(iconIdx int, osType OsType, size uint) {
icons[iconIdx] = &Icon{
Type: osType,
- Image: resizeSquare(img, size, scaler),
+ Image: resizeSquare(img, size, interp),
}
work.Done()
}(iconIdx, osType, size)
@@ -98,13 +97,13 @@ func NewIconSet(img image.Image, interp InterpolationFunction) (*IconSet, error)
//
// Scaling happens in alpha-premultiplied space, so colour does not bleed out
// of fully transparent pixels into the icon's edges.
-func resizeSquare(img image.Image, size uint, scaler draw.Interpolator) image.Image {
+func resizeSquare(img image.Image, size uint, interp InterpolationFunction) image.Image {
bounds := img.Bounds()
if bounds.Dx() == int(size) && bounds.Dy() == int(size) {
return img
}
dst := image.NewRGBA(image.Rect(0, 0, int(size), int(size)))
- scaler.Scale(dst, dst.Bounds(), img, bounds, draw.Src, nil)
+ interp.scaler().Scale(dst, dst.Bounds(), img, bounds, draw.Src, nil)
return dst
}
diff --git a/icns_test.go b/icns_test.go
@@ -130,7 +130,7 @@ func TestResizeKeepsColorOutOfTransparentPixels(t *testing.T) {
}
// Bilinear has no negative lobes, so every output pixel is a plain
// average of its neighbours and the expected values are exact.
- got := resizeSquare(src, 32, Bilinear.scaler())
+ got := resizeSquare(src, 32, Bilinear)
var blended int
for y := got.Bounds().Min.Y; y < got.Bounds().Max.Y; y++ {
for x := got.Bounds().Min.X; x < got.Bounds().Max.X; x++ {