Allow reading tiles with transparency

This commit is contained in:
David Vogel 2024-04-06 23:28:15 +02:00
parent 04eeca26e2
commit aee72fd3c6

View File

@ -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
} }