WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 0fbf363

Browse files
committed
Also register the image config decode
Not hugely efficient but it works :)
1 parent d00969f commit 0fbf363

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

xpm/register.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ import (
66
)
77

88
func init() {
9-
image.RegisterFormat("xpm", "/* XPM */", Decode, nil)
10-
image.RegisterFormat("xpm", "static char", Decode, nil)
9+
image.RegisterFormat("xpm", "/* XPM */", Decode, DecodeConfig)
10+
image.RegisterFormat("xpm", "static char", Decode, DecodeConfig)
1111
}
1212

1313
func Decode(r io.Reader) (image.Image, error) {
1414
return parseXPM(r)
1515
}
16+
17+
func DecodeConfig(r io.Reader) (image.Config, error) {
18+
return parseXPMConfig(r)
19+
}

xpm/xpm.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ func parseXPM(data io.Reader) (image.Image, error) {
6363
return img, scan.Err()
6464
}
6565

66+
func parseXPMConfig(data io.Reader) (image.Config, error) {
67+
p, err := parseXPM(data)
68+
if err != nil {
69+
return image.Config{}, err
70+
}
71+
72+
return image.Config{
73+
Width: p.Bounds().Dx(),
74+
Height: p.Bounds().Dy(),
75+
}, nil
76+
}
77+
6678
func parseColor(data string, charSize int) (id string, c color.Color, err error) {
6779
if len(data) < charSize {
6880
return "", nil, fmt.Errorf("%w: missing color specification", ErrInvalidFormat)

0 commit comments

Comments
 (0)