commit f4d6e9e5f20f6958efca2df03159dcb12c8b46b7
parent 5d48d7301c0bd040faee94ad8310f7ce72f9f0d5
Author: Jack Mordaunt <jackmordaunt@gmail.com>
Date: Fri, 9 Feb 2018 14:10:06 +0100
[*] `getType` returns a boolean instead of panicking.
Diffstat:
| M | icns.go | | | 34 | +++++++++++++++++----------------- |
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/icns.go b/icns.go
@@ -32,9 +32,13 @@ func NewIconSet(img image.Image, interp InterpolationFunction) (*IconSet, error)
}
icons := []*Icon{}
for _, size := range sizesFrom(biggest) {
+ t, ok := getType(size)
+ if !ok {
+ continue
+ }
iconImg := resize.Resize(size, size, img, interp)
icon := &Icon{
- Type: getType(size),
+ Type: t,
Image: iconImg,
}
icons = append(icons, icon)
@@ -94,21 +98,17 @@ func sizesFrom(max uint) []uint {
return nil
}
-var types = map[uint]OsType{
- 1024: "ic10",
- 512: "ic14",
- 256: "ic13",
- 128: "ic07",
- 64: "ic12",
- 32: "ic11",
-}
-
-// should this return error, panic or return a default (but probably incorrect)
-// format? For now, failing explicitly is preferable to failing silently.
-func getType(size uint) OsType {
- v, ok := types[size]
- if !ok {
- panicf("could not select the correct icon type for size %d", size)
+// getType returns the type for the given icon size (in px).
+// The boolean indicates whether the type exists.
+func getType(size uint) (OsType, bool) {
+ types := map[uint]OsType{
+ 1024: "ic10",
+ 512: "ic14",
+ 256: "ic13",
+ 128: "ic07",
+ 64: "ic12",
+ 32: "ic11",
}
- return v
+ v, ok := types[size]
+ return v, ok
}