Skip to content

Commit

Permalink
Prevent transparent background
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadido3 committed Jan 15, 2024
1 parent d82fda5 commit f22ef05
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 4 additions & 1 deletion bin/stitch/stitched-image-cache.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2023 David Vogel
// Copyright (c) 2022-2024 David Vogel
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
Expand All @@ -8,6 +8,7 @@ package main
import (
"image"
"image/color"
"image/draw"
"runtime"
"sync"
)
Expand Down Expand Up @@ -69,7 +70,9 @@ func (sic *StitchedImageCache) Regenerate() *image.RGBA {

si := sic.stitchedImage

// Create new image with default background color.
cacheImage := image.NewRGBA(sic.rect)
draw.Draw(cacheImage, cacheImage.Bounds(), &image.Uniform{colorBackground}, cacheImage.Bounds().Min, draw.Src)

// List of tiles that intersect with the to be generated cache image.
intersectingTiles := []*ImageTile{}
Expand Down
8 changes: 6 additions & 2 deletions bin/stitch/stitched-image.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2023 David Vogel
// Copyright (c) 2022-2024 David Vogel
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
Expand All @@ -13,6 +13,10 @@ import (
"time"
)

// The default background color.
// We use a non transparent black.
var colorBackground = color.RGBA{0, 0, 0, 255}

// StitchedImageCacheGridSize defines the worker chunk size when the cache image is regenerated.
var StitchedImageCacheGridSize = 256

Expand Down Expand Up @@ -116,7 +120,7 @@ func (si *StitchedImage) RGBAAt(x, y int) color.RGBA {
// Determine the cache rowIndex index.
rowIndex := (y + si.cacheRowYOffset) / si.cacheRowHeight
if rowIndex < 0 || rowIndex >= len(si.cacheRows) {
return color.RGBA{}
return colorBackground
}

// Check if we advanced/changed the row index.
Expand Down
4 changes: 2 additions & 2 deletions bin/stitch/sub-stitched-image.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023 David Vogel
// Copyright (c) 2023-2024 David Vogel
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
Expand Down Expand Up @@ -29,7 +29,7 @@ func (s SubStitchedImage) At(x, y int) color.Color {
func (s SubStitchedImage) RGBAAt(x, y int) color.RGBA {
point := image.Point{X: x, Y: y}
if !point.In(s.bounds) {
return color.RGBA{}
return colorBackground
}

return s.StitchedImage.RGBAAt(x, y)
Expand Down

0 comments on commit f22ef05

Please sign in to comment.