MCPcopy
hub / github.com/g3n/engine / DecodeImage

Function DecodeImage

texture/texture2D.go:317–339  ·  view source on GitHub ↗

DecodeImage reads and decodes the specified image file into RGBA8. The supported image files are PNG, JPEG and GIF.

(imgfile string)

Source from the content-addressed store, hash-verified

315// DecodeImage reads and decodes the specified image file into RGBA8.
316// The supported image files are PNG, JPEG and GIF.
317func 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
342func (t *Texture2D) RenderSetup(gs *gls.GLS, slotIdx, uniIdx int) { // Could have as input - TEXTURE0 (slot) and uni location

Callers 2

NewTexture2DFromImageFunction · 0.85
SetImageMethod · 0.85

Calls 2

CloseMethod · 0.65
SizeMethod · 0.45

Tested by

no test coverage detected