DecodeImage reads and decodes the specified image file into RGBA8. The supported image files are PNG, JPEG and GIF.
(imgfile string)
| 315 | // DecodeImage reads and decodes the specified image file into RGBA8. |
| 316 | // The supported image files are PNG, JPEG and GIF. |
| 317 | func DecodeImage(imgfile string) (*image.RGBA, error) { |
| 318 | |
| 319 | // Open image file |
| 320 | file, err := os.Open(imgfile) |
| 321 | if err != nil { |
| 322 | return nil, err |
| 323 | } |
| 324 | defer file.Close() |
| 325 | |
| 326 | // Decodes image |
| 327 | img, _, err := image.Decode(file) |
| 328 | if err != nil { |
| 329 | return nil, err |
| 330 | } |
| 331 | |
| 332 | // Converts image to RGBA format |
| 333 | rgba := image.NewRGBA(img.Bounds()) |
| 334 | if rgba.Stride != rgba.Rect.Size().X*4 { |
| 335 | return nil, fmt.Errorf("unsupported stride") |
| 336 | } |
| 337 | draw.Draw(rgba, rgba.Bounds(), img, image.Point{0, 0}, draw.Src) |
| 338 | return rgba, nil |
| 339 | } |
| 340 | |
| 341 | // RenderSetup is called by the material render setup |
| 342 | func (t *Texture2D) RenderSetup(gs *gls.GLS, slotIdx, uniIdx int) { // Could have as input - TEXTURE0 (slot) and uni location |
no test coverage detected