mirror of
https://github.com/Dadido3/noita-mapcap.git
synced 2024-11-18 17:17:31 +00:00
Add SubStitchedImage
This commit is contained in:
parent
6d028d4064
commit
915da73845
@ -128,12 +128,6 @@ func (si *StitchedImage) RGBAAt(x, y int) color.RGBA {
|
||||
go si.cacheRows[newRowIndex].Regenerate()
|
||||
}
|
||||
|
||||
// Invalidate old cache row.
|
||||
oldRowIndex := si.oldCacheRowIndex
|
||||
if oldRowIndex >= 0 && oldRowIndex < len(si.cacheRows) {
|
||||
si.cacheRows[oldRowIndex].Invalidate()
|
||||
}
|
||||
|
||||
// Invalidate all tiles that are above the next row.
|
||||
si.tiles.InvalidateAboveY((rowIndex+1)*si.cacheRowHeight - si.cacheRowYOffset)
|
||||
|
||||
@ -146,7 +140,7 @@ func (si *StitchedImage) RGBAAt(x, y int) color.RGBA {
|
||||
// Opaque returns whether the image is fully opaque.
|
||||
//
|
||||
// For more speed and smaller file size, StitchedImage will be marked as non-transparent.
|
||||
// This will speed up image saving by 2x, as there is no need to iterate over the whole image to find a single non opaque pixel.
|
||||
// This will speed up image saving by 2x, as there is no need to iterate over the whole image just to find a single non opaque pixel.
|
||||
func (si *StitchedImage) Opaque() bool {
|
||||
return true
|
||||
}
|
||||
@ -157,3 +151,12 @@ func (si *StitchedImage) Progress() (value, max int) {
|
||||
|
||||
return int(si.queryCounter.Load()), size.X * size.Y
|
||||
}
|
||||
|
||||
// SubStitchedImage returns an image representing the portion of the image p visible through r.
|
||||
// The returned image references to the original stitched image, and therefore reuses its cache.
|
||||
func (si *StitchedImage) SubStitchedImage(r image.Rectangle) SubStitchedImage {
|
||||
return SubStitchedImage{
|
||||
StitchedImage: si,
|
||||
bounds: si.Bounds().Intersect(r),
|
||||
}
|
||||
}
|
||||
|
36
bin/stitch/sub-stitched-image.go
Normal file
36
bin/stitch/sub-stitched-image.go
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2023 David Vogel
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
)
|
||||
|
||||
type SubStitchedImage struct {
|
||||
*StitchedImage // The original stitched image.
|
||||
|
||||
bounds image.Rectangle // The new bounds of the cropped image.
|
||||
}
|
||||
|
||||
// Bounds returns the domain for which At can return non-zero color.
|
||||
// The bounds do not necessarily contain the point (0, 0).
|
||||
func (s SubStitchedImage) Bounds() image.Rectangle {
|
||||
return s.bounds
|
||||
}
|
||||
|
||||
func (s SubStitchedImage) At(x, y int) color.Color {
|
||||
return s.RGBAAt(x, y)
|
||||
}
|
||||
|
||||
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 s.StitchedImage.RGBAAt(x, y)
|
||||
}
|
Loading…
Reference in New Issue
Block a user