(filepath string)
| 10 | ) |
| 11 | |
| 12 | func 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 | } |