Skip to content

Commit

Permalink
Allow reading tiles with transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadido3 committed Apr 6, 2024
1 parent 04eeca2 commit aee72fd
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions bin/stitch/image-tile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package main
import (
"fmt"
"image"
"image/draw"
_ "image/png"
"log"
"os"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit aee72fd

Please sign in to comment.