(url string, data io.Reader)
| 44 | } |
| 45 | |
| 46 | func (i *imageLoader) Load(url string, data io.Reader) error { |
| 47 | var res TextureResource |
| 48 | if getExt(url) == ".svg" { |
| 49 | icon, err := oksvg.ReadIconStream(data, oksvg.WarnErrorMode) |
| 50 | if err != nil { |
| 51 | return err |
| 52 | } |
| 53 | w, h := int(icon.ViewBox.W), int(icon.ViewBox.H) |
| 54 | img := image.NewRGBA(image.Rect(0, 0, w, h)) |
| 55 | gv := rasterx.NewScannerGV(w, h, img, img.Bounds()) |
| 56 | r := rasterx.NewDasher(w, h, gv) |
| 57 | icon.Draw(r, 1.0) |
| 58 | b := img.Bounds() |
| 59 | newm := image.NewNRGBA(image.Rect(0, 0, b.Dx(), b.Dy())) |
| 60 | draw.Draw(newm, newm.Bounds(), img, b.Min, draw.Src) |
| 61 | res = NewTextureResource(&ImageObject{newm}) |
| 62 | } else { |
| 63 | img, _, err := image.Decode(data) |
| 64 | if err != nil { |
| 65 | return err |
| 66 | } |
| 67 | b := img.Bounds() |
| 68 | newm := image.NewNRGBA(image.Rect(0, 0, b.Dx(), b.Dy())) |
| 69 | draw.Draw(newm, newm.Bounds(), img, b.Min, draw.Src) |
| 70 | res = NewTextureResource(&ImageObject{newm}) |
| 71 | } |
| 72 | res.url = url |
| 73 | i.images[url] = res |
| 74 | |
| 75 | return nil |
| 76 | } |
| 77 | |
| 78 | func (i *imageLoader) Unload(url string) error { |
| 79 | delete(i.images, url) |
nothing calls this directly
no test coverage detected