parent
d738eca230
commit
10e13c033d
@ -0,0 +1,39 @@ |
||||
package filters |
||||
|
||||
import ( |
||||
"image" |
||||
"image/draw" |
||||
"image/color" |
||||
"github.com/disintegration/gift" |
||||
) |
||||
|
||||
type UpscaleFilter struct { |
||||
Size image.Rectangle |
||||
PixelWidth int |
||||
} |
||||
|
||||
func UpscaleImage(size image.Rectangle, width int) gift.Filter { |
||||
return UpscaleFilter{size, width} |
||||
} |
||||
|
||||
func (filter UpscaleFilter) Bounds(src image.Rectangle) (dst_bounds image.Rectangle) { |
||||
return filter.Size |
||||
} |
||||
|
||||
func (filter UpscaleFilter) Draw(dst draw.Image, src image.Image, _ *gift.Options) { |
||||
var from_x, from_y int |
||||
var from color.Color |
||||
bounds := filter.Size |
||||
|
||||
for y := bounds.Min.Y; y < bounds.Max.Y; y++ { |
||||
for x := bounds.Min.X; x < bounds.Max.X; x++ { |
||||
if x % filter.PixelWidth == 0 { |
||||
from_x = x / filter.PixelWidth |
||||
from_y = y / filter.PixelWidth |
||||
from = src.At(from_x, from_y) |
||||
} |
||||
|
||||
dst.Set(x, y, from) |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue