mirror of
https://github.com/Dadido3/noita-mapcap.git
synced 2024-11-18 17:17:31 +00:00
Allow reading tiles with transparency
This commit is contained in:
parent
04eeca26e2
commit
aee72fd3c6
@ -8,6 +8,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
|
"image/draw"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -127,9 +128,16 @@ func (it *ImageTile) GetImage() *image.RGBA {
|
|||||||
img = resize.Resize(uint(oldRect.Dx()), uint(oldRect.Dy()), img, resize.NearestNeighbor)
|
img = resize.Resize(uint(oldRect.Dx()), uint(oldRect.Dy()), img, resize.NearestNeighbor)
|
||||||
}
|
}
|
||||||
|
|
||||||
imgRGBA, ok := img.(*image.RGBA)
|
var imgRGBA *image.RGBA
|
||||||
if !ok {
|
switch img := img.(type) {
|
||||||
log.Printf("Expected an RGBA image for %q, got %T instead.", it.fileName, img)
|
case *image.RGBA:
|
||||||
|
imgRGBA = img
|
||||||
|
case *image.NRGBA:
|
||||||
|
bounds := img.Bounds()
|
||||||
|
imgRGBA = image.NewRGBA(image.Rect(0, 0, bounds.Dx(), bounds.Dy()))
|
||||||
|
draw.Draw(imgRGBA, imgRGBA.Bounds(), img, bounds.Min, draw.Src)
|
||||||
|
default:
|
||||||
|
log.Printf("Expected an RGBA or NRGBA image for %q, got %T instead.", it.fileName, img)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user