Skip to content

Commit aee72fd

Browse files
committed
Allow reading tiles with transparency
1 parent 04eeca2 commit aee72fd

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

bin/stitch/image-tile.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package main
88
import (
99
"fmt"
1010
"image"
11+
"image/draw"
1112
_ "image/png"
1213
"log"
1314
"os"
@@ -127,9 +128,16 @@ func (it *ImageTile) GetImage() *image.RGBA {
127128
img = resize.Resize(uint(oldRect.Dx()), uint(oldRect.Dy()), img, resize.NearestNeighbor)
128129
}
129130

130-
imgRGBA, ok := img.(*image.RGBA)
131-
if !ok {
132-
log.Printf("Expected an RGBA image for %q, got %T instead.", it.fileName, img)
131+
var imgRGBA *image.RGBA
132+
switch img := img.(type) {
133+
case *image.RGBA:
134+
imgRGBA = img
135+
case *image.NRGBA:
136+
bounds := img.Bounds()
137+
imgRGBA = image.NewRGBA(image.Rect(0, 0, bounds.Dx(), bounds.Dy()))
138+
draw.Draw(imgRGBA, imgRGBA.Bounds(), img, bounds.Min, draw.Src)
139+
default:
140+
log.Printf("Expected an RGBA or NRGBA image for %q, got %T instead.", it.fileName, img)
133141
return nil
134142
}
135143

0 commit comments

Comments
 (0)