From aee72fd3c6c734dfb15ab61e0be067c69c8b351f Mon Sep 17 00:00:00 2001 From: David Vogel Date: Sat, 6 Apr 2024 23:28:15 +0200 Subject: [PATCH] Allow reading tiles with transparency --- bin/stitch/image-tile.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bin/stitch/image-tile.go b/bin/stitch/image-tile.go index ce74dfe..726fbbc 100644 --- a/bin/stitch/image-tile.go +++ b/bin/stitch/image-tile.go @@ -8,6 +8,7 @@ package main import ( "fmt" "image" + "image/draw" _ "image/png" "log" "os" @@ -127,9 +128,16 @@ func (it *ImageTile) GetImage() *image.RGBA { img = resize.Resize(uint(oldRect.Dx()), uint(oldRect.Dy()), img, resize.NearestNeighbor) } - imgRGBA, ok := img.(*image.RGBA) - if !ok { - log.Printf("Expected an RGBA image for %q, got %T instead.", it.fileName, img) + var imgRGBA *image.RGBA + switch img := img.(type) { + 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 }