MCPcopy Create free account
hub / github.com/egonelbre/exp / loadImage

Function loadImage

textinput/util.go:12–35  ·  view source on GitHub ↗
(filepath string)

Source from the content-addressed store, hash-verified

10)
11
12func loadImage(filepath string) (*image.RGBA, error) {
13 file, err := os.Open(filepath)
14 if err != nil {
15 return nil, err
16 }
17 defer file.Close()
18
19 m, _, err := image.Decode(file)
20 if err != nil {
21 return nil, err
22 }
23
24 if rgba, ok := m.(*image.RGBA); ok {
25 return rgba, nil
26 }
27
28 rgba := image.NewRGBA(m.Bounds())
29 if rgba.Stride != rgba.Rect.Size().X*4 {
30 panic("unsupported stride")
31 }
32 draw.Draw(rgba, rgba.Bounds(), m, image.Point{0, 0}, draw.Src)
33
34 return rgba, nil
35}

Callers 1

LoadMethod · 0.85

Calls 6

BoundsMethod · 0.80
SizeMethod · 0.80
OpenMethod · 0.65
CloseMethod · 0.65
DecodeMethod · 0.65
DrawMethod · 0.45

Tested by

no test coverage detected