2024-02-21 15:14:28 +00:00
|
|
|
package imgrow
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
"image/draw"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DrawImage returns an image that is 'img' where (only) drawing is scalad by 'scalar'.
|
|
|
|
// The actual image stays the same size.
|
|
|
|
// Only the drawing is scaled.
|
|
|
|
//
|
|
|
|
// So, for example:
|
|
|
|
//
|
|
|
|
// var newImage draw.Image = imgrow.Image(2, oldImage)
|
|
|
|
//
|
|
|
|
// ... would return a new image that is just like 'oldImage' except any drawing on it is 2 times as big.
|
|
|
|
func DrawImage(scalar int, img draw.Image) draw.Image {
|
|
|
|
return internalDrawImage {
|
|
|
|
img:img,
|
|
|
|
scalar:scalar,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ draw.Image = &internalDrawImage{}
|
|
|
|
|
|
|
|
type internalDrawImage struct {
|
|
|
|
img draw.Image
|
|
|
|
scalar int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (receiver internalDrawImage) At(x, y int) color.Color {
|
|
|
|
var img image.Image = receiver.img
|
|
|
|
|
|
|
|
if nil == img {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return img.At(x, y)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (receiver internalDrawImage) Bounds() image.Rectangle {
|
|
|
|
var img image.Image = receiver.img
|
|
|
|
|
|
|
|
if nil == img {
|
|
|
|
return image.Rectangle{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return img.Bounds()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (receiver internalDrawImage) ColorModel() color.Model {
|
|
|
|
var img image.Image = receiver.img
|
|
|
|
|
|
|
|
if nil == img {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return img.ColorModel()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (receiver internalDrawImage) Set(x int, y int, c color.Color) {
|
|
|
|
var img draw.Image = receiver.img
|
|
|
|
|
|
|
|
if nil == img {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var scalar int = receiver.scalar
|
|
|
|
|
2024-02-21 15:41:52 +00:00
|
|
|
xScaled, yScaled := scaleXY(scalar, x, y)
|
2024-02-21 15:14:28 +00:00
|
|
|
|
|
|
|
for yi := yScaled; yi < (yScaled + scalar); yi++ {
|
|
|
|
for xi := xScaled; xi < (xScaled + scalar); xi++ {
|
|
|
|
img.Set(xi, yi, c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|