2015-02-20 08:28:54 +01:00
|
|
|
// generated by "go run gen.go". DO NOT EDIT.
|
2015-02-19 05:53:02 +01:00
|
|
|
|
|
|
|
package draw
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
)
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (z nnInterpolator) Scale(dst Image, dr image.Rectangle, src image.Image, sr image.Rectangle) {
|
|
|
|
// adr is the affected destination pixels, relative to dr.Min.
|
|
|
|
adr := dst.Bounds().Intersect(dr).Sub(dr.Min)
|
|
|
|
if adr.Empty() || sr.Empty() {
|
2015-02-26 06:20:04 +01:00
|
|
|
return
|
|
|
|
}
|
2015-02-27 11:26:47 +01:00
|
|
|
// sr is the source pixels. If it extends beyond the src bounds,
|
|
|
|
// we cannot use the type-specific fast paths, as they access
|
|
|
|
// the Pix fields directly without bounds checking.
|
2015-03-03 06:54:53 +01:00
|
|
|
if !sr.In(src.Bounds()) {
|
|
|
|
z.scale_Image_Image(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
} else {
|
|
|
|
switch dst := dst.(type) {
|
2015-02-24 05:28:16 +01:00
|
|
|
case *image.RGBA:
|
2015-02-27 11:26:47 +01:00
|
|
|
switch src := src.(type) {
|
2015-02-28 06:05:58 +01:00
|
|
|
case *image.Gray:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scale_RGBA_Gray(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
case *image.NRGBA:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scale_RGBA_NRGBA(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
case *image.RGBA:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scale_RGBA_RGBA(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
case *image.Uniform:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scale_RGBA_Uniform(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
case *image.YCbCr:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scale_RGBA_YCbCr(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
default:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scale_RGBA_Image(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
}
|
2015-02-24 05:28:16 +01:00
|
|
|
default:
|
2015-02-27 11:26:47 +01:00
|
|
|
switch src := src.(type) {
|
|
|
|
default:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scale_Image_Image(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
}
|
2015-02-24 05:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (nnInterpolator) scale_RGBA_Gray(dst *image.RGBA, dr, adr image.Rectangle, src *image.Gray, sr image.Rectangle) {
|
|
|
|
dw2 := uint64(dr.Dx()) * 2
|
|
|
|
dh2 := uint64(dr.Dy()) * 2
|
|
|
|
sw := uint64(sr.Dx())
|
|
|
|
sh := uint64(sr.Dy())
|
2015-03-03 05:47:39 +01:00
|
|
|
for dy := int32(adr.Min.Y); dy < int32(adr.Max.Y); dy++ {
|
2015-03-03 06:54:53 +01:00
|
|
|
sy := (2*uint64(dy) + 1) * sh / dh2
|
|
|
|
d := dst.PixOffset(dr.Min.X+adr.Min.X, dr.Min.Y+int(dy))
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
2015-03-03 06:54:53 +01:00
|
|
|
sx := (2*uint64(dx) + 1) * sw / dw2
|
|
|
|
pr, pg, pb, pa := src.At(sr.Min.X+int(sx), sr.Min.Y+int(sy)).RGBA()
|
2015-02-28 06:05:58 +01:00
|
|
|
dst.Pix[d+0] = uint8(uint32(pr) >> 8)
|
|
|
|
dst.Pix[d+1] = uint8(uint32(pg) >> 8)
|
|
|
|
dst.Pix[d+2] = uint8(uint32(pb) >> 8)
|
|
|
|
dst.Pix[d+3] = uint8(uint32(pa) >> 8)
|
|
|
|
d += 4
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (nnInterpolator) scale_RGBA_NRGBA(dst *image.RGBA, dr, adr image.Rectangle, src *image.NRGBA, sr image.Rectangle) {
|
|
|
|
dw2 := uint64(dr.Dx()) * 2
|
|
|
|
dh2 := uint64(dr.Dy()) * 2
|
|
|
|
sw := uint64(sr.Dx())
|
|
|
|
sh := uint64(sr.Dy())
|
2015-03-03 05:47:39 +01:00
|
|
|
for dy := int32(adr.Min.Y); dy < int32(adr.Max.Y); dy++ {
|
2015-03-03 06:54:53 +01:00
|
|
|
sy := (2*uint64(dy) + 1) * sh / dh2
|
|
|
|
d := dst.PixOffset(dr.Min.X+adr.Min.X, dr.Min.Y+int(dy))
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
2015-03-03 06:54:53 +01:00
|
|
|
sx := (2*uint64(dx) + 1) * sw / dw2
|
|
|
|
pr, pg, pb, pa := src.At(sr.Min.X+int(sx), sr.Min.Y+int(sy)).RGBA()
|
2015-02-27 06:18:34 +01:00
|
|
|
dst.Pix[d+0] = uint8(uint32(pr) >> 8)
|
|
|
|
dst.Pix[d+1] = uint8(uint32(pg) >> 8)
|
|
|
|
dst.Pix[d+2] = uint8(uint32(pb) >> 8)
|
|
|
|
dst.Pix[d+3] = uint8(uint32(pa) >> 8)
|
|
|
|
d += 4
|
2015-02-24 05:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (nnInterpolator) scale_RGBA_RGBA(dst *image.RGBA, dr, adr image.Rectangle, src *image.RGBA, sr image.Rectangle) {
|
|
|
|
dw2 := uint64(dr.Dx()) * 2
|
|
|
|
dh2 := uint64(dr.Dy()) * 2
|
|
|
|
sw := uint64(sr.Dx())
|
|
|
|
sh := uint64(sr.Dy())
|
2015-03-03 05:47:39 +01:00
|
|
|
for dy := int32(adr.Min.Y); dy < int32(adr.Max.Y); dy++ {
|
2015-03-03 06:54:53 +01:00
|
|
|
sy := (2*uint64(dy) + 1) * sh / dh2
|
|
|
|
d := dst.PixOffset(dr.Min.X+adr.Min.X, dr.Min.Y+int(dy))
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
2015-03-03 06:54:53 +01:00
|
|
|
sx := (2*uint64(dx) + 1) * sw / dw2
|
|
|
|
pi := src.PixOffset(sr.Min.X+int(sx), sr.Min.Y+int(sy))
|
2015-02-27 11:26:47 +01:00
|
|
|
pr := uint32(src.Pix[pi+0]) * 0x101
|
|
|
|
pg := uint32(src.Pix[pi+1]) * 0x101
|
|
|
|
pb := uint32(src.Pix[pi+2]) * 0x101
|
|
|
|
pa := uint32(src.Pix[pi+3]) * 0x101
|
2015-02-27 06:18:34 +01:00
|
|
|
dst.Pix[d+0] = uint8(uint32(pr) >> 8)
|
|
|
|
dst.Pix[d+1] = uint8(uint32(pg) >> 8)
|
|
|
|
dst.Pix[d+2] = uint8(uint32(pb) >> 8)
|
|
|
|
dst.Pix[d+3] = uint8(uint32(pa) >> 8)
|
|
|
|
d += 4
|
2015-02-24 05:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (nnInterpolator) scale_RGBA_Uniform(dst *image.RGBA, dr, adr image.Rectangle, src *image.Uniform, sr image.Rectangle) {
|
|
|
|
dw2 := uint64(dr.Dx()) * 2
|
|
|
|
dh2 := uint64(dr.Dy()) * 2
|
|
|
|
sw := uint64(sr.Dx())
|
|
|
|
sh := uint64(sr.Dy())
|
2015-03-03 05:47:39 +01:00
|
|
|
for dy := int32(adr.Min.Y); dy < int32(adr.Max.Y); dy++ {
|
2015-03-03 06:54:53 +01:00
|
|
|
sy := (2*uint64(dy) + 1) * sh / dh2
|
|
|
|
d := dst.PixOffset(dr.Min.X+adr.Min.X, dr.Min.Y+int(dy))
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
2015-03-03 06:54:53 +01:00
|
|
|
sx := (2*uint64(dx) + 1) * sw / dw2
|
|
|
|
pr, pg, pb, pa := src.At(sr.Min.X+int(sx), sr.Min.Y+int(sy)).RGBA()
|
2015-02-27 06:18:34 +01:00
|
|
|
dst.Pix[d+0] = uint8(uint32(pr) >> 8)
|
|
|
|
dst.Pix[d+1] = uint8(uint32(pg) >> 8)
|
|
|
|
dst.Pix[d+2] = uint8(uint32(pb) >> 8)
|
|
|
|
dst.Pix[d+3] = uint8(uint32(pa) >> 8)
|
|
|
|
d += 4
|
2015-02-24 05:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (nnInterpolator) scale_RGBA_YCbCr(dst *image.RGBA, dr, adr image.Rectangle, src *image.YCbCr, sr image.Rectangle) {
|
|
|
|
dw2 := uint64(dr.Dx()) * 2
|
|
|
|
dh2 := uint64(dr.Dy()) * 2
|
|
|
|
sw := uint64(sr.Dx())
|
|
|
|
sh := uint64(sr.Dy())
|
2015-03-03 05:47:39 +01:00
|
|
|
for dy := int32(adr.Min.Y); dy < int32(adr.Max.Y); dy++ {
|
2015-03-03 06:54:53 +01:00
|
|
|
sy := (2*uint64(dy) + 1) * sh / dh2
|
|
|
|
d := dst.PixOffset(dr.Min.X+adr.Min.X, dr.Min.Y+int(dy))
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
2015-03-03 06:54:53 +01:00
|
|
|
sx := (2*uint64(dx) + 1) * sw / dw2
|
|
|
|
pr, pg, pb, pa := src.At(sr.Min.X+int(sx), sr.Min.Y+int(sy)).RGBA()
|
2015-02-27 06:18:34 +01:00
|
|
|
dst.Pix[d+0] = uint8(uint32(pr) >> 8)
|
|
|
|
dst.Pix[d+1] = uint8(uint32(pg) >> 8)
|
|
|
|
dst.Pix[d+2] = uint8(uint32(pb) >> 8)
|
|
|
|
dst.Pix[d+3] = uint8(uint32(pa) >> 8)
|
|
|
|
d += 4
|
2015-02-24 05:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (nnInterpolator) scale_RGBA_Image(dst *image.RGBA, dr, adr image.Rectangle, src image.Image, sr image.Rectangle) {
|
|
|
|
dw2 := uint64(dr.Dx()) * 2
|
|
|
|
dh2 := uint64(dr.Dy()) * 2
|
|
|
|
sw := uint64(sr.Dx())
|
|
|
|
sh := uint64(sr.Dy())
|
2015-03-03 05:47:39 +01:00
|
|
|
for dy := int32(adr.Min.Y); dy < int32(adr.Max.Y); dy++ {
|
2015-03-03 06:54:53 +01:00
|
|
|
sy := (2*uint64(dy) + 1) * sh / dh2
|
|
|
|
d := dst.PixOffset(dr.Min.X+adr.Min.X, dr.Min.Y+int(dy))
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
2015-03-03 06:54:53 +01:00
|
|
|
sx := (2*uint64(dx) + 1) * sw / dw2
|
|
|
|
pr, pg, pb, pa := src.At(sr.Min.X+int(sx), sr.Min.Y+int(sy)).RGBA()
|
2015-02-27 06:18:34 +01:00
|
|
|
dst.Pix[d+0] = uint8(uint32(pr) >> 8)
|
|
|
|
dst.Pix[d+1] = uint8(uint32(pg) >> 8)
|
|
|
|
dst.Pix[d+2] = uint8(uint32(pb) >> 8)
|
|
|
|
dst.Pix[d+3] = uint8(uint32(pa) >> 8)
|
|
|
|
d += 4
|
2015-02-24 05:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (nnInterpolator) scale_Image_Image(dst Image, dr, adr image.Rectangle, src image.Image, sr image.Rectangle) {
|
|
|
|
dw2 := uint64(dr.Dx()) * 2
|
|
|
|
dh2 := uint64(dr.Dy()) * 2
|
|
|
|
sw := uint64(sr.Dx())
|
|
|
|
sh := uint64(sr.Dy())
|
2015-02-24 05:28:16 +01:00
|
|
|
dstColorRGBA64 := &color.RGBA64{}
|
|
|
|
dstColor := color.Color(dstColorRGBA64)
|
2015-03-03 05:47:39 +01:00
|
|
|
for dy := int32(adr.Min.Y); dy < int32(adr.Max.Y); dy++ {
|
2015-03-03 06:54:53 +01:00
|
|
|
sy := (2*uint64(dy) + 1) * sh / dh2
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
2015-03-03 06:54:53 +01:00
|
|
|
sx := (2*uint64(dx) + 1) * sw / dw2
|
|
|
|
pr, pg, pb, pa := src.At(sr.Min.X+int(sx), sr.Min.Y+int(sy)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
dstColorRGBA64.R = uint16(pr)
|
|
|
|
dstColorRGBA64.G = uint16(pg)
|
|
|
|
dstColorRGBA64.B = uint16(pb)
|
|
|
|
dstColorRGBA64.A = uint16(pa)
|
2015-03-03 06:54:53 +01:00
|
|
|
dst.Set(dr.Min.X+int(dx), dr.Min.Y+int(dy), dstColor)
|
2015-02-24 05:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (z ablInterpolator) Scale(dst Image, dr image.Rectangle, src image.Image, sr image.Rectangle) {
|
|
|
|
// adr is the affected destination pixels, relative to dr.Min.
|
|
|
|
adr := dst.Bounds().Intersect(dr).Sub(dr.Min)
|
|
|
|
if adr.Empty() || sr.Empty() {
|
2015-02-26 06:20:04 +01:00
|
|
|
return
|
|
|
|
}
|
2015-02-27 11:26:47 +01:00
|
|
|
// sr is the source pixels. If it extends beyond the src bounds,
|
|
|
|
// we cannot use the type-specific fast paths, as they access
|
|
|
|
// the Pix fields directly without bounds checking.
|
2015-03-03 06:54:53 +01:00
|
|
|
if !sr.In(src.Bounds()) {
|
|
|
|
z.scale_Image_Image(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
} else {
|
|
|
|
switch dst := dst.(type) {
|
2015-02-24 05:28:16 +01:00
|
|
|
case *image.RGBA:
|
2015-02-27 11:26:47 +01:00
|
|
|
switch src := src.(type) {
|
2015-02-28 06:05:58 +01:00
|
|
|
case *image.Gray:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scale_RGBA_Gray(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
case *image.NRGBA:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scale_RGBA_NRGBA(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
case *image.RGBA:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scale_RGBA_RGBA(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
case *image.Uniform:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scale_RGBA_Uniform(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
case *image.YCbCr:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scale_RGBA_YCbCr(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
default:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scale_RGBA_Image(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
}
|
2015-02-24 05:28:16 +01:00
|
|
|
default:
|
2015-02-27 11:26:47 +01:00
|
|
|
switch src := src.(type) {
|
|
|
|
default:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scale_Image_Image(dst, dr, adr, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
}
|
2015-02-24 05:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (ablInterpolator) scale_RGBA_Gray(dst *image.RGBA, dr, adr image.Rectangle, src *image.Gray, sr image.Rectangle) {
|
|
|
|
sw := int32(sr.Dx())
|
|
|
|
sh := int32(sr.Dy())
|
|
|
|
yscale := float64(sh) / float64(dr.Dy())
|
|
|
|
xscale := float64(sw) / float64(dr.Dx())
|
2015-03-03 05:47:39 +01:00
|
|
|
for dy := int32(adr.Min.Y); dy < int32(adr.Max.Y); dy++ {
|
2015-02-28 06:05:58 +01:00
|
|
|
sy := (float64(dy)+0.5)*yscale - 0.5
|
|
|
|
sy0 := int32(sy)
|
|
|
|
yFrac0 := sy - float64(sy0)
|
|
|
|
yFrac1 := 1 - yFrac0
|
|
|
|
sy1 := sy0 + 1
|
|
|
|
if sy < 0 {
|
|
|
|
sy0, sy1 = 0, 0
|
|
|
|
yFrac0, yFrac1 = 0, 1
|
2015-03-03 06:54:53 +01:00
|
|
|
} else if sy1 >= sh {
|
2015-02-28 06:05:58 +01:00
|
|
|
sy1 = sy0
|
|
|
|
yFrac0, yFrac1 = 1, 0
|
|
|
|
}
|
2015-03-03 06:54:53 +01:00
|
|
|
d := dst.PixOffset(dr.Min.X+adr.Min.X, dr.Min.Y+int(dy))
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
2015-02-28 06:05:58 +01:00
|
|
|
sx := (float64(dx)+0.5)*xscale - 0.5
|
|
|
|
sx0 := int32(sx)
|
|
|
|
xFrac0 := sx - float64(sx0)
|
|
|
|
xFrac1 := 1 - xFrac0
|
|
|
|
sx1 := sx0 + 1
|
|
|
|
if sx < 0 {
|
|
|
|
sx0, sx1 = 0, 0
|
|
|
|
xFrac0, xFrac1 = 0, 1
|
2015-03-03 06:54:53 +01:00
|
|
|
} else if sx1 >= sw {
|
2015-02-28 06:05:58 +01:00
|
|
|
sx1 = sx0
|
|
|
|
xFrac0, xFrac1 = 1, 0
|
|
|
|
}
|
2015-03-03 06:54:53 +01:00
|
|
|
s00ru, s00gu, s00bu, s00au := src.At(sr.Min.X+int(sx0), sr.Min.Y+int(sy0)).RGBA()
|
2015-02-28 06:05:58 +01:00
|
|
|
s00r := float64(s00ru)
|
|
|
|
s00g := float64(s00gu)
|
|
|
|
s00b := float64(s00bu)
|
|
|
|
s00a := float64(s00au)
|
2015-03-03 06:54:53 +01:00
|
|
|
s10ru, s10gu, s10bu, s10au := src.At(sr.Min.X+int(sx1), sr.Min.Y+int(sy0)).RGBA()
|
2015-02-28 06:05:58 +01:00
|
|
|
s10r := float64(s10ru)
|
|
|
|
s10g := float64(s10gu)
|
|
|
|
s10b := float64(s10bu)
|
|
|
|
s10a := float64(s10au)
|
|
|
|
s10r = xFrac1*s00r + xFrac0*s10r
|
|
|
|
s10g = xFrac1*s00g + xFrac0*s10g
|
|
|
|
s10b = xFrac1*s00b + xFrac0*s10b
|
|
|
|
s10a = xFrac1*s00a + xFrac0*s10a
|
2015-03-03 06:54:53 +01:00
|
|
|
s01ru, s01gu, s01bu, s01au := src.At(sr.Min.X+int(sx0), sr.Min.Y+int(sy1)).RGBA()
|
2015-02-28 06:05:58 +01:00
|
|
|
s01r := float64(s01ru)
|
|
|
|
s01g := float64(s01gu)
|
|
|
|
s01b := float64(s01bu)
|
|
|
|
s01a := float64(s01au)
|
2015-03-03 06:54:53 +01:00
|
|
|
s11ru, s11gu, s11bu, s11au := src.At(sr.Min.X+int(sx1), sr.Min.Y+int(sy1)).RGBA()
|
2015-02-28 06:05:58 +01:00
|
|
|
s11r := float64(s11ru)
|
|
|
|
s11g := float64(s11gu)
|
|
|
|
s11b := float64(s11bu)
|
|
|
|
s11a := float64(s11au)
|
|
|
|
s11r = xFrac1*s01r + xFrac0*s11r
|
|
|
|
s11g = xFrac1*s01g + xFrac0*s11g
|
|
|
|
s11b = xFrac1*s01b + xFrac0*s11b
|
|
|
|
s11a = xFrac1*s01a + xFrac0*s11a
|
|
|
|
s11r = yFrac1*s10r + yFrac0*s11r
|
|
|
|
s11g = yFrac1*s10g + yFrac0*s11g
|
|
|
|
s11b = yFrac1*s10b + yFrac0*s11b
|
|
|
|
s11a = yFrac1*s10a + yFrac0*s11a
|
|
|
|
dst.Pix[d+0] = uint8(uint32(s11r) >> 8)
|
|
|
|
dst.Pix[d+1] = uint8(uint32(s11g) >> 8)
|
|
|
|
dst.Pix[d+2] = uint8(uint32(s11b) >> 8)
|
|
|
|
dst.Pix[d+3] = uint8(uint32(s11a) >> 8)
|
|
|
|
d += 4
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (ablInterpolator) scale_RGBA_NRGBA(dst *image.RGBA, dr, adr image.Rectangle, src *image.NRGBA, sr image.Rectangle) {
|
|
|
|
sw := int32(sr.Dx())
|
|
|
|
sh := int32(sr.Dy())
|
|
|
|
yscale := float64(sh) / float64(dr.Dy())
|
|
|
|
xscale := float64(sw) / float64(dr.Dx())
|
2015-03-03 05:47:39 +01:00
|
|
|
for dy := int32(adr.Min.Y); dy < int32(adr.Max.Y); dy++ {
|
2015-02-24 05:28:16 +01:00
|
|
|
sy := (float64(dy)+0.5)*yscale - 0.5
|
|
|
|
sy0 := int32(sy)
|
|
|
|
yFrac0 := sy - float64(sy0)
|
|
|
|
yFrac1 := 1 - yFrac0
|
|
|
|
sy1 := sy0 + 1
|
|
|
|
if sy < 0 {
|
|
|
|
sy0, sy1 = 0, 0
|
|
|
|
yFrac0, yFrac1 = 0, 1
|
2015-03-03 06:54:53 +01:00
|
|
|
} else if sy1 >= sh {
|
2015-02-24 05:28:16 +01:00
|
|
|
sy1 = sy0
|
|
|
|
yFrac0, yFrac1 = 1, 0
|
|
|
|
}
|
2015-03-03 06:54:53 +01:00
|
|
|
d := dst.PixOffset(dr.Min.X+adr.Min.X, dr.Min.Y+int(dy))
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
2015-02-24 05:28:16 +01:00
|
|
|
sx := (float64(dx)+0.5)*xscale - 0.5
|
|
|
|
sx0 := int32(sx)
|
|
|
|
xFrac0 := sx - float64(sx0)
|
|
|
|
xFrac1 := 1 - xFrac0
|
|
|
|
sx1 := sx0 + 1
|
|
|
|
if sx < 0 {
|
|
|
|
sx0, sx1 = 0, 0
|
|
|
|
xFrac0, xFrac1 = 0, 1
|
2015-03-03 06:54:53 +01:00
|
|
|
} else if sx1 >= sw {
|
2015-02-24 05:28:16 +01:00
|
|
|
sx1 = sx0
|
|
|
|
xFrac0, xFrac1 = 1, 0
|
|
|
|
}
|
2015-03-03 06:54:53 +01:00
|
|
|
s00ru, s00gu, s00bu, s00au := src.At(sr.Min.X+int(sx0), sr.Min.Y+int(sy0)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s00r := float64(s00ru)
|
|
|
|
s00g := float64(s00gu)
|
|
|
|
s00b := float64(s00bu)
|
|
|
|
s00a := float64(s00au)
|
2015-03-03 06:54:53 +01:00
|
|
|
s10ru, s10gu, s10bu, s10au := src.At(sr.Min.X+int(sx1), sr.Min.Y+int(sy0)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s10r := float64(s10ru)
|
|
|
|
s10g := float64(s10gu)
|
|
|
|
s10b := float64(s10bu)
|
|
|
|
s10a := float64(s10au)
|
|
|
|
s10r = xFrac1*s00r + xFrac0*s10r
|
|
|
|
s10g = xFrac1*s00g + xFrac0*s10g
|
|
|
|
s10b = xFrac1*s00b + xFrac0*s10b
|
|
|
|
s10a = xFrac1*s00a + xFrac0*s10a
|
2015-03-03 06:54:53 +01:00
|
|
|
s01ru, s01gu, s01bu, s01au := src.At(sr.Min.X+int(sx0), sr.Min.Y+int(sy1)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s01r := float64(s01ru)
|
|
|
|
s01g := float64(s01gu)
|
|
|
|
s01b := float64(s01bu)
|
|
|
|
s01a := float64(s01au)
|
2015-03-03 06:54:53 +01:00
|
|
|
s11ru, s11gu, s11bu, s11au := src.At(sr.Min.X+int(sx1), sr.Min.Y+int(sy1)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s11r := float64(s11ru)
|
|
|
|
s11g := float64(s11gu)
|
|
|
|
s11b := float64(s11bu)
|
|
|
|
s11a := float64(s11au)
|
|
|
|
s11r = xFrac1*s01r + xFrac0*s11r
|
|
|
|
s11g = xFrac1*s01g + xFrac0*s11g
|
|
|
|
s11b = xFrac1*s01b + xFrac0*s11b
|
|
|
|
s11a = xFrac1*s01a + xFrac0*s11a
|
|
|
|
s11r = yFrac1*s10r + yFrac0*s11r
|
|
|
|
s11g = yFrac1*s10g + yFrac0*s11g
|
|
|
|
s11b = yFrac1*s10b + yFrac0*s11b
|
|
|
|
s11a = yFrac1*s10a + yFrac0*s11a
|
2015-02-27 06:18:34 +01:00
|
|
|
dst.Pix[d+0] = uint8(uint32(s11r) >> 8)
|
|
|
|
dst.Pix[d+1] = uint8(uint32(s11g) >> 8)
|
|
|
|
dst.Pix[d+2] = uint8(uint32(s11b) >> 8)
|
|
|
|
dst.Pix[d+3] = uint8(uint32(s11a) >> 8)
|
|
|
|
d += 4
|
2015-02-24 05:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (ablInterpolator) scale_RGBA_RGBA(dst *image.RGBA, dr, adr image.Rectangle, src *image.RGBA, sr image.Rectangle) {
|
|
|
|
sw := int32(sr.Dx())
|
|
|
|
sh := int32(sr.Dy())
|
|
|
|
yscale := float64(sh) / float64(dr.Dy())
|
|
|
|
xscale := float64(sw) / float64(dr.Dx())
|
2015-03-03 05:47:39 +01:00
|
|
|
for dy := int32(adr.Min.Y); dy < int32(adr.Max.Y); dy++ {
|
2015-02-24 05:28:16 +01:00
|
|
|
sy := (float64(dy)+0.5)*yscale - 0.5
|
|
|
|
sy0 := int32(sy)
|
|
|
|
yFrac0 := sy - float64(sy0)
|
|
|
|
yFrac1 := 1 - yFrac0
|
|
|
|
sy1 := sy0 + 1
|
|
|
|
if sy < 0 {
|
|
|
|
sy0, sy1 = 0, 0
|
|
|
|
yFrac0, yFrac1 = 0, 1
|
2015-03-03 06:54:53 +01:00
|
|
|
} else if sy1 >= sh {
|
2015-02-24 05:28:16 +01:00
|
|
|
sy1 = sy0
|
|
|
|
yFrac0, yFrac1 = 1, 0
|
|
|
|
}
|
2015-03-03 06:54:53 +01:00
|
|
|
d := dst.PixOffset(dr.Min.X+adr.Min.X, dr.Min.Y+int(dy))
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
2015-02-24 05:28:16 +01:00
|
|
|
sx := (float64(dx)+0.5)*xscale - 0.5
|
|
|
|
sx0 := int32(sx)
|
|
|
|
xFrac0 := sx - float64(sx0)
|
|
|
|
xFrac1 := 1 - xFrac0
|
|
|
|
sx1 := sx0 + 1
|
|
|
|
if sx < 0 {
|
|
|
|
sx0, sx1 = 0, 0
|
|
|
|
xFrac0, xFrac1 = 0, 1
|
2015-03-03 06:54:53 +01:00
|
|
|
} else if sx1 >= sw {
|
2015-02-24 05:28:16 +01:00
|
|
|
sx1 = sx0
|
|
|
|
xFrac0, xFrac1 = 1, 0
|
|
|
|
}
|
2015-03-03 06:54:53 +01:00
|
|
|
s00i := src.PixOffset(sr.Min.X+int(sx0), sr.Min.Y+int(sy0))
|
2015-02-27 11:26:47 +01:00
|
|
|
s00ru := uint32(src.Pix[s00i+0]) * 0x101
|
|
|
|
s00gu := uint32(src.Pix[s00i+1]) * 0x101
|
|
|
|
s00bu := uint32(src.Pix[s00i+2]) * 0x101
|
|
|
|
s00au := uint32(src.Pix[s00i+3]) * 0x101
|
2015-02-24 05:28:16 +01:00
|
|
|
s00r := float64(s00ru)
|
|
|
|
s00g := float64(s00gu)
|
|
|
|
s00b := float64(s00bu)
|
|
|
|
s00a := float64(s00au)
|
2015-03-03 06:54:53 +01:00
|
|
|
s10i := src.PixOffset(sr.Min.X+int(sx1), sr.Min.Y+int(sy0))
|
2015-02-27 11:26:47 +01:00
|
|
|
s10ru := uint32(src.Pix[s10i+0]) * 0x101
|
|
|
|
s10gu := uint32(src.Pix[s10i+1]) * 0x101
|
|
|
|
s10bu := uint32(src.Pix[s10i+2]) * 0x101
|
|
|
|
s10au := uint32(src.Pix[s10i+3]) * 0x101
|
2015-02-24 05:28:16 +01:00
|
|
|
s10r := float64(s10ru)
|
|
|
|
s10g := float64(s10gu)
|
|
|
|
s10b := float64(s10bu)
|
|
|
|
s10a := float64(s10au)
|
|
|
|
s10r = xFrac1*s00r + xFrac0*s10r
|
|
|
|
s10g = xFrac1*s00g + xFrac0*s10g
|
|
|
|
s10b = xFrac1*s00b + xFrac0*s10b
|
|
|
|
s10a = xFrac1*s00a + xFrac0*s10a
|
2015-03-03 06:54:53 +01:00
|
|
|
s01i := src.PixOffset(sr.Min.X+int(sx0), sr.Min.Y+int(sy1))
|
2015-02-27 11:26:47 +01:00
|
|
|
s01ru := uint32(src.Pix[s01i+0]) * 0x101
|
|
|
|
s01gu := uint32(src.Pix[s01i+1]) * 0x101
|
|
|
|
s01bu := uint32(src.Pix[s01i+2]) * 0x101
|
|
|
|
s01au := uint32(src.Pix[s01i+3]) * 0x101
|
2015-02-24 05:28:16 +01:00
|
|
|
s01r := float64(s01ru)
|
|
|
|
s01g := float64(s01gu)
|
|
|
|
s01b := float64(s01bu)
|
|
|
|
s01a := float64(s01au)
|
2015-03-03 06:54:53 +01:00
|
|
|
s11i := src.PixOffset(sr.Min.X+int(sx1), sr.Min.Y+int(sy1))
|
2015-02-27 11:26:47 +01:00
|
|
|
s11ru := uint32(src.Pix[s11i+0]) * 0x101
|
|
|
|
s11gu := uint32(src.Pix[s11i+1]) * 0x101
|
|
|
|
s11bu := uint32(src.Pix[s11i+2]) * 0x101
|
|
|
|
s11au := uint32(src.Pix[s11i+3]) * 0x101
|
2015-02-24 05:28:16 +01:00
|
|
|
s11r := float64(s11ru)
|
|
|
|
s11g := float64(s11gu)
|
|
|
|
s11b := float64(s11bu)
|
|
|
|
s11a := float64(s11au)
|
|
|
|
s11r = xFrac1*s01r + xFrac0*s11r
|
|
|
|
s11g = xFrac1*s01g + xFrac0*s11g
|
|
|
|
s11b = xFrac1*s01b + xFrac0*s11b
|
|
|
|
s11a = xFrac1*s01a + xFrac0*s11a
|
|
|
|
s11r = yFrac1*s10r + yFrac0*s11r
|
|
|
|
s11g = yFrac1*s10g + yFrac0*s11g
|
|
|
|
s11b = yFrac1*s10b + yFrac0*s11b
|
|
|
|
s11a = yFrac1*s10a + yFrac0*s11a
|
2015-02-27 06:18:34 +01:00
|
|
|
dst.Pix[d+0] = uint8(uint32(s11r) >> 8)
|
|
|
|
dst.Pix[d+1] = uint8(uint32(s11g) >> 8)
|
|
|
|
dst.Pix[d+2] = uint8(uint32(s11b) >> 8)
|
|
|
|
dst.Pix[d+3] = uint8(uint32(s11a) >> 8)
|
|
|
|
d += 4
|
2015-02-24 05:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (ablInterpolator) scale_RGBA_Uniform(dst *image.RGBA, dr, adr image.Rectangle, src *image.Uniform, sr image.Rectangle) {
|
|
|
|
sw := int32(sr.Dx())
|
|
|
|
sh := int32(sr.Dy())
|
|
|
|
yscale := float64(sh) / float64(dr.Dy())
|
|
|
|
xscale := float64(sw) / float64(dr.Dx())
|
2015-03-03 05:47:39 +01:00
|
|
|
for dy := int32(adr.Min.Y); dy < int32(adr.Max.Y); dy++ {
|
2015-02-24 05:28:16 +01:00
|
|
|
sy := (float64(dy)+0.5)*yscale - 0.5
|
|
|
|
sy0 := int32(sy)
|
|
|
|
yFrac0 := sy - float64(sy0)
|
|
|
|
yFrac1 := 1 - yFrac0
|
|
|
|
sy1 := sy0 + 1
|
|
|
|
if sy < 0 {
|
|
|
|
sy0, sy1 = 0, 0
|
|
|
|
yFrac0, yFrac1 = 0, 1
|
2015-03-03 06:54:53 +01:00
|
|
|
} else if sy1 >= sh {
|
2015-02-24 05:28:16 +01:00
|
|
|
sy1 = sy0
|
|
|
|
yFrac0, yFrac1 = 1, 0
|
|
|
|
}
|
2015-03-03 06:54:53 +01:00
|
|
|
d := dst.PixOffset(dr.Min.X+adr.Min.X, dr.Min.Y+int(dy))
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
2015-02-24 05:28:16 +01:00
|
|
|
sx := (float64(dx)+0.5)*xscale - 0.5
|
|
|
|
sx0 := int32(sx)
|
|
|
|
xFrac0 := sx - float64(sx0)
|
|
|
|
xFrac1 := 1 - xFrac0
|
|
|
|
sx1 := sx0 + 1
|
|
|
|
if sx < 0 {
|
|
|
|
sx0, sx1 = 0, 0
|
|
|
|
xFrac0, xFrac1 = 0, 1
|
2015-03-03 06:54:53 +01:00
|
|
|
} else if sx1 >= sw {
|
2015-02-24 05:28:16 +01:00
|
|
|
sx1 = sx0
|
|
|
|
xFrac0, xFrac1 = 1, 0
|
|
|
|
}
|
2015-03-03 06:54:53 +01:00
|
|
|
s00ru, s00gu, s00bu, s00au := src.At(sr.Min.X+int(sx0), sr.Min.Y+int(sy0)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s00r := float64(s00ru)
|
|
|
|
s00g := float64(s00gu)
|
|
|
|
s00b := float64(s00bu)
|
|
|
|
s00a := float64(s00au)
|
2015-03-03 06:54:53 +01:00
|
|
|
s10ru, s10gu, s10bu, s10au := src.At(sr.Min.X+int(sx1), sr.Min.Y+int(sy0)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s10r := float64(s10ru)
|
|
|
|
s10g := float64(s10gu)
|
|
|
|
s10b := float64(s10bu)
|
|
|
|
s10a := float64(s10au)
|
|
|
|
s10r = xFrac1*s00r + xFrac0*s10r
|
|
|
|
s10g = xFrac1*s00g + xFrac0*s10g
|
|
|
|
s10b = xFrac1*s00b + xFrac0*s10b
|
|
|
|
s10a = xFrac1*s00a + xFrac0*s10a
|
2015-03-03 06:54:53 +01:00
|
|
|
s01ru, s01gu, s01bu, s01au := src.At(sr.Min.X+int(sx0), sr.Min.Y+int(sy1)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s01r := float64(s01ru)
|
|
|
|
s01g := float64(s01gu)
|
|
|
|
s01b := float64(s01bu)
|
|
|
|
s01a := float64(s01au)
|
2015-03-03 06:54:53 +01:00
|
|
|
s11ru, s11gu, s11bu, s11au := src.At(sr.Min.X+int(sx1), sr.Min.Y+int(sy1)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s11r := float64(s11ru)
|
|
|
|
s11g := float64(s11gu)
|
|
|
|
s11b := float64(s11bu)
|
|
|
|
s11a := float64(s11au)
|
|
|
|
s11r = xFrac1*s01r + xFrac0*s11r
|
|
|
|
s11g = xFrac1*s01g + xFrac0*s11g
|
|
|
|
s11b = xFrac1*s01b + xFrac0*s11b
|
|
|
|
s11a = xFrac1*s01a + xFrac0*s11a
|
|
|
|
s11r = yFrac1*s10r + yFrac0*s11r
|
|
|
|
s11g = yFrac1*s10g + yFrac0*s11g
|
|
|
|
s11b = yFrac1*s10b + yFrac0*s11b
|
|
|
|
s11a = yFrac1*s10a + yFrac0*s11a
|
2015-02-27 06:18:34 +01:00
|
|
|
dst.Pix[d+0] = uint8(uint32(s11r) >> 8)
|
|
|
|
dst.Pix[d+1] = uint8(uint32(s11g) >> 8)
|
|
|
|
dst.Pix[d+2] = uint8(uint32(s11b) >> 8)
|
|
|
|
dst.Pix[d+3] = uint8(uint32(s11a) >> 8)
|
|
|
|
d += 4
|
2015-02-24 05:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
2015-02-20 08:28:54 +01:00
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (ablInterpolator) scale_RGBA_YCbCr(dst *image.RGBA, dr, adr image.Rectangle, src *image.YCbCr, sr image.Rectangle) {
|
|
|
|
sw := int32(sr.Dx())
|
|
|
|
sh := int32(sr.Dy())
|
|
|
|
yscale := float64(sh) / float64(dr.Dy())
|
|
|
|
xscale := float64(sw) / float64(dr.Dx())
|
2015-03-03 05:47:39 +01:00
|
|
|
for dy := int32(adr.Min.Y); dy < int32(adr.Max.Y); dy++ {
|
2015-02-24 05:28:16 +01:00
|
|
|
sy := (float64(dy)+0.5)*yscale - 0.5
|
|
|
|
sy0 := int32(sy)
|
|
|
|
yFrac0 := sy - float64(sy0)
|
|
|
|
yFrac1 := 1 - yFrac0
|
|
|
|
sy1 := sy0 + 1
|
|
|
|
if sy < 0 {
|
|
|
|
sy0, sy1 = 0, 0
|
|
|
|
yFrac0, yFrac1 = 0, 1
|
2015-03-03 06:54:53 +01:00
|
|
|
} else if sy1 >= sh {
|
2015-02-24 05:28:16 +01:00
|
|
|
sy1 = sy0
|
|
|
|
yFrac0, yFrac1 = 1, 0
|
|
|
|
}
|
2015-03-03 06:54:53 +01:00
|
|
|
d := dst.PixOffset(dr.Min.X+adr.Min.X, dr.Min.Y+int(dy))
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
2015-02-24 05:28:16 +01:00
|
|
|
sx := (float64(dx)+0.5)*xscale - 0.5
|
|
|
|
sx0 := int32(sx)
|
|
|
|
xFrac0 := sx - float64(sx0)
|
|
|
|
xFrac1 := 1 - xFrac0
|
|
|
|
sx1 := sx0 + 1
|
|
|
|
if sx < 0 {
|
|
|
|
sx0, sx1 = 0, 0
|
|
|
|
xFrac0, xFrac1 = 0, 1
|
2015-03-03 06:54:53 +01:00
|
|
|
} else if sx1 >= sw {
|
2015-02-24 05:28:16 +01:00
|
|
|
sx1 = sx0
|
|
|
|
xFrac0, xFrac1 = 1, 0
|
|
|
|
}
|
2015-03-03 06:54:53 +01:00
|
|
|
s00ru, s00gu, s00bu, s00au := src.At(sr.Min.X+int(sx0), sr.Min.Y+int(sy0)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s00r := float64(s00ru)
|
|
|
|
s00g := float64(s00gu)
|
|
|
|
s00b := float64(s00bu)
|
|
|
|
s00a := float64(s00au)
|
2015-03-03 06:54:53 +01:00
|
|
|
s10ru, s10gu, s10bu, s10au := src.At(sr.Min.X+int(sx1), sr.Min.Y+int(sy0)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s10r := float64(s10ru)
|
|
|
|
s10g := float64(s10gu)
|
|
|
|
s10b := float64(s10bu)
|
|
|
|
s10a := float64(s10au)
|
|
|
|
s10r = xFrac1*s00r + xFrac0*s10r
|
|
|
|
s10g = xFrac1*s00g + xFrac0*s10g
|
|
|
|
s10b = xFrac1*s00b + xFrac0*s10b
|
|
|
|
s10a = xFrac1*s00a + xFrac0*s10a
|
2015-03-03 06:54:53 +01:00
|
|
|
s01ru, s01gu, s01bu, s01au := src.At(sr.Min.X+int(sx0), sr.Min.Y+int(sy1)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s01r := float64(s01ru)
|
|
|
|
s01g := float64(s01gu)
|
|
|
|
s01b := float64(s01bu)
|
|
|
|
s01a := float64(s01au)
|
2015-03-03 06:54:53 +01:00
|
|
|
s11ru, s11gu, s11bu, s11au := src.At(sr.Min.X+int(sx1), sr.Min.Y+int(sy1)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s11r := float64(s11ru)
|
|
|
|
s11g := float64(s11gu)
|
|
|
|
s11b := float64(s11bu)
|
|
|
|
s11a := float64(s11au)
|
|
|
|
s11r = xFrac1*s01r + xFrac0*s11r
|
|
|
|
s11g = xFrac1*s01g + xFrac0*s11g
|
|
|
|
s11b = xFrac1*s01b + xFrac0*s11b
|
|
|
|
s11a = xFrac1*s01a + xFrac0*s11a
|
|
|
|
s11r = yFrac1*s10r + yFrac0*s11r
|
|
|
|
s11g = yFrac1*s10g + yFrac0*s11g
|
|
|
|
s11b = yFrac1*s10b + yFrac0*s11b
|
|
|
|
s11a = yFrac1*s10a + yFrac0*s11a
|
2015-02-27 06:18:34 +01:00
|
|
|
dst.Pix[d+0] = uint8(uint32(s11r) >> 8)
|
|
|
|
dst.Pix[d+1] = uint8(uint32(s11g) >> 8)
|
|
|
|
dst.Pix[d+2] = uint8(uint32(s11b) >> 8)
|
|
|
|
dst.Pix[d+3] = uint8(uint32(s11a) >> 8)
|
|
|
|
d += 4
|
2015-02-19 05:53:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (ablInterpolator) scale_RGBA_Image(dst *image.RGBA, dr, adr image.Rectangle, src image.Image, sr image.Rectangle) {
|
|
|
|
sw := int32(sr.Dx())
|
|
|
|
sh := int32(sr.Dy())
|
|
|
|
yscale := float64(sh) / float64(dr.Dy())
|
|
|
|
xscale := float64(sw) / float64(dr.Dx())
|
2015-03-03 05:47:39 +01:00
|
|
|
for dy := int32(adr.Min.Y); dy < int32(adr.Max.Y); dy++ {
|
2015-02-24 05:28:16 +01:00
|
|
|
sy := (float64(dy)+0.5)*yscale - 0.5
|
|
|
|
sy0 := int32(sy)
|
|
|
|
yFrac0 := sy - float64(sy0)
|
|
|
|
yFrac1 := 1 - yFrac0
|
|
|
|
sy1 := sy0 + 1
|
|
|
|
if sy < 0 {
|
|
|
|
sy0, sy1 = 0, 0
|
|
|
|
yFrac0, yFrac1 = 0, 1
|
2015-03-03 06:54:53 +01:00
|
|
|
} else if sy1 >= sh {
|
2015-02-24 05:28:16 +01:00
|
|
|
sy1 = sy0
|
|
|
|
yFrac0, yFrac1 = 1, 0
|
|
|
|
}
|
2015-03-03 06:54:53 +01:00
|
|
|
d := dst.PixOffset(dr.Min.X+adr.Min.X, dr.Min.Y+int(dy))
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
2015-02-24 05:28:16 +01:00
|
|
|
sx := (float64(dx)+0.5)*xscale - 0.5
|
|
|
|
sx0 := int32(sx)
|
|
|
|
xFrac0 := sx - float64(sx0)
|
|
|
|
xFrac1 := 1 - xFrac0
|
|
|
|
sx1 := sx0 + 1
|
|
|
|
if sx < 0 {
|
|
|
|
sx0, sx1 = 0, 0
|
|
|
|
xFrac0, xFrac1 = 0, 1
|
2015-03-03 06:54:53 +01:00
|
|
|
} else if sx1 >= sw {
|
2015-02-24 05:28:16 +01:00
|
|
|
sx1 = sx0
|
|
|
|
xFrac0, xFrac1 = 1, 0
|
|
|
|
}
|
2015-03-03 06:54:53 +01:00
|
|
|
s00ru, s00gu, s00bu, s00au := src.At(sr.Min.X+int(sx0), sr.Min.Y+int(sy0)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s00r := float64(s00ru)
|
|
|
|
s00g := float64(s00gu)
|
|
|
|
s00b := float64(s00bu)
|
|
|
|
s00a := float64(s00au)
|
2015-03-03 06:54:53 +01:00
|
|
|
s10ru, s10gu, s10bu, s10au := src.At(sr.Min.X+int(sx1), sr.Min.Y+int(sy0)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s10r := float64(s10ru)
|
|
|
|
s10g := float64(s10gu)
|
|
|
|
s10b := float64(s10bu)
|
|
|
|
s10a := float64(s10au)
|
|
|
|
s10r = xFrac1*s00r + xFrac0*s10r
|
|
|
|
s10g = xFrac1*s00g + xFrac0*s10g
|
|
|
|
s10b = xFrac1*s00b + xFrac0*s10b
|
|
|
|
s10a = xFrac1*s00a + xFrac0*s10a
|
2015-03-03 06:54:53 +01:00
|
|
|
s01ru, s01gu, s01bu, s01au := src.At(sr.Min.X+int(sx0), sr.Min.Y+int(sy1)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s01r := float64(s01ru)
|
|
|
|
s01g := float64(s01gu)
|
|
|
|
s01b := float64(s01bu)
|
|
|
|
s01a := float64(s01au)
|
2015-03-03 06:54:53 +01:00
|
|
|
s11ru, s11gu, s11bu, s11au := src.At(sr.Min.X+int(sx1), sr.Min.Y+int(sy1)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
s11r := float64(s11ru)
|
|
|
|
s11g := float64(s11gu)
|
|
|
|
s11b := float64(s11bu)
|
|
|
|
s11a := float64(s11au)
|
|
|
|
s11r = xFrac1*s01r + xFrac0*s11r
|
|
|
|
s11g = xFrac1*s01g + xFrac0*s11g
|
|
|
|
s11b = xFrac1*s01b + xFrac0*s11b
|
|
|
|
s11a = xFrac1*s01a + xFrac0*s11a
|
|
|
|
s11r = yFrac1*s10r + yFrac0*s11r
|
|
|
|
s11g = yFrac1*s10g + yFrac0*s11g
|
|
|
|
s11b = yFrac1*s10b + yFrac0*s11b
|
|
|
|
s11a = yFrac1*s10a + yFrac0*s11a
|
2015-02-27 06:18:34 +01:00
|
|
|
dst.Pix[d+0] = uint8(uint32(s11r) >> 8)
|
|
|
|
dst.Pix[d+1] = uint8(uint32(s11g) >> 8)
|
|
|
|
dst.Pix[d+2] = uint8(uint32(s11b) >> 8)
|
|
|
|
dst.Pix[d+3] = uint8(uint32(s11a) >> 8)
|
|
|
|
d += 4
|
2015-02-24 05:28:16 +01:00
|
|
|
}
|
2015-02-19 05:53:02 +01:00
|
|
|
}
|
2015-02-20 08:28:54 +01:00
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (ablInterpolator) scale_Image_Image(dst Image, dr, adr image.Rectangle, src image.Image, sr image.Rectangle) {
|
|
|
|
sw := int32(sr.Dx())
|
|
|
|
sh := int32(sr.Dy())
|
|
|
|
yscale := float64(sh) / float64(dr.Dy())
|
|
|
|
xscale := float64(sw) / float64(dr.Dx())
|
2015-02-19 05:53:02 +01:00
|
|
|
dstColorRGBA64 := &color.RGBA64{}
|
|
|
|
dstColor := color.Color(dstColorRGBA64)
|
2015-03-03 05:47:39 +01:00
|
|
|
for dy := int32(adr.Min.Y); dy < int32(adr.Max.Y); dy++ {
|
2015-02-19 05:53:02 +01:00
|
|
|
sy := (float64(dy)+0.5)*yscale - 0.5
|
|
|
|
sy0 := int32(sy)
|
|
|
|
yFrac0 := sy - float64(sy0)
|
|
|
|
yFrac1 := 1 - yFrac0
|
|
|
|
sy1 := sy0 + 1
|
|
|
|
if sy < 0 {
|
|
|
|
sy0, sy1 = 0, 0
|
|
|
|
yFrac0, yFrac1 = 0, 1
|
2015-03-03 06:54:53 +01:00
|
|
|
} else if sy1 >= sh {
|
2015-02-19 05:53:02 +01:00
|
|
|
sy1 = sy0
|
|
|
|
yFrac0, yFrac1 = 1, 0
|
|
|
|
}
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
2015-02-19 05:53:02 +01:00
|
|
|
sx := (float64(dx)+0.5)*xscale - 0.5
|
|
|
|
sx0 := int32(sx)
|
|
|
|
xFrac0 := sx - float64(sx0)
|
|
|
|
xFrac1 := 1 - xFrac0
|
|
|
|
sx1 := sx0 + 1
|
|
|
|
if sx < 0 {
|
|
|
|
sx0, sx1 = 0, 0
|
|
|
|
xFrac0, xFrac1 = 0, 1
|
2015-03-03 06:54:53 +01:00
|
|
|
} else if sx1 >= sw {
|
2015-02-19 05:53:02 +01:00
|
|
|
sx1 = sx0
|
|
|
|
xFrac0, xFrac1 = 1, 0
|
|
|
|
}
|
2015-03-03 06:54:53 +01:00
|
|
|
s00ru, s00gu, s00bu, s00au := src.At(sr.Min.X+int(sx0), sr.Min.Y+int(sy0)).RGBA()
|
2015-02-19 05:53:02 +01:00
|
|
|
s00r := float64(s00ru)
|
|
|
|
s00g := float64(s00gu)
|
|
|
|
s00b := float64(s00bu)
|
|
|
|
s00a := float64(s00au)
|
2015-03-03 06:54:53 +01:00
|
|
|
s10ru, s10gu, s10bu, s10au := src.At(sr.Min.X+int(sx1), sr.Min.Y+int(sy0)).RGBA()
|
2015-02-19 05:53:02 +01:00
|
|
|
s10r := float64(s10ru)
|
|
|
|
s10g := float64(s10gu)
|
|
|
|
s10b := float64(s10bu)
|
|
|
|
s10a := float64(s10au)
|
|
|
|
s10r = xFrac1*s00r + xFrac0*s10r
|
|
|
|
s10g = xFrac1*s00g + xFrac0*s10g
|
|
|
|
s10b = xFrac1*s00b + xFrac0*s10b
|
|
|
|
s10a = xFrac1*s00a + xFrac0*s10a
|
2015-03-03 06:54:53 +01:00
|
|
|
s01ru, s01gu, s01bu, s01au := src.At(sr.Min.X+int(sx0), sr.Min.Y+int(sy1)).RGBA()
|
2015-02-19 05:53:02 +01:00
|
|
|
s01r := float64(s01ru)
|
|
|
|
s01g := float64(s01gu)
|
|
|
|
s01b := float64(s01bu)
|
|
|
|
s01a := float64(s01au)
|
2015-03-03 06:54:53 +01:00
|
|
|
s11ru, s11gu, s11bu, s11au := src.At(sr.Min.X+int(sx1), sr.Min.Y+int(sy1)).RGBA()
|
2015-02-19 05:53:02 +01:00
|
|
|
s11r := float64(s11ru)
|
|
|
|
s11g := float64(s11gu)
|
|
|
|
s11b := float64(s11bu)
|
|
|
|
s11a := float64(s11au)
|
|
|
|
s11r = xFrac1*s01r + xFrac0*s11r
|
|
|
|
s11g = xFrac1*s01g + xFrac0*s11g
|
|
|
|
s11b = xFrac1*s01b + xFrac0*s11b
|
|
|
|
s11a = xFrac1*s01a + xFrac0*s11a
|
|
|
|
s11r = yFrac1*s10r + yFrac0*s11r
|
|
|
|
s11g = yFrac1*s10g + yFrac0*s11g
|
|
|
|
s11b = yFrac1*s10b + yFrac0*s11b
|
|
|
|
s11a = yFrac1*s10a + yFrac0*s11a
|
|
|
|
dstColorRGBA64.R = uint16(s11r)
|
|
|
|
dstColorRGBA64.G = uint16(s11g)
|
|
|
|
dstColorRGBA64.B = uint16(s11b)
|
|
|
|
dstColorRGBA64.A = uint16(s11a)
|
2015-03-03 06:54:53 +01:00
|
|
|
dst.Set(dr.Min.X+int(dx), dr.Min.Y+int(dy), dstColor)
|
2015-02-19 05:53:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (z *kernelScaler) Scale(dst Image, dr image.Rectangle, src image.Image, sr image.Rectangle) {
|
|
|
|
if z.dw != int32(dr.Dx()) || z.dh != int32(dr.Dy()) || z.sw != int32(sr.Dx()) || z.sh != int32(sr.Dy()) {
|
|
|
|
z.kernel.Scale(dst, dr, src, sr)
|
2015-02-19 05:53:02 +01:00
|
|
|
return
|
|
|
|
}
|
2015-03-03 06:54:53 +01:00
|
|
|
// adr is the affected destination pixels, relative to dr.Min.
|
|
|
|
adr := dst.Bounds().Intersect(dr).Sub(dr.Min)
|
|
|
|
if adr.Empty() || sr.Empty() {
|
2015-02-26 06:20:04 +01:00
|
|
|
return
|
|
|
|
}
|
2015-02-19 05:53:02 +01:00
|
|
|
// Create a temporary buffer:
|
|
|
|
// scaleX distributes the source image's columns over the temporary image.
|
|
|
|
// scaleY distributes the temporary image's rows over the destination image.
|
|
|
|
// TODO: is it worth having a sync.Pool for this temporary buffer?
|
|
|
|
tmp := make([][4]float64, z.dw*z.sh)
|
2015-02-27 11:26:47 +01:00
|
|
|
|
|
|
|
// sr is the source pixels. If it extends beyond the src bounds,
|
|
|
|
// we cannot use the type-specific fast paths, as they access
|
|
|
|
// the Pix fields directly without bounds checking.
|
2015-03-03 06:54:53 +01:00
|
|
|
if !sr.In(src.Bounds()) {
|
|
|
|
z.scaleX_Image(tmp, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
} else {
|
|
|
|
switch src := src.(type) {
|
2015-02-28 06:05:58 +01:00
|
|
|
case *image.Gray:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scaleX_Gray(tmp, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
case *image.NRGBA:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scaleX_NRGBA(tmp, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
case *image.RGBA:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scaleX_RGBA(tmp, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
case *image.Uniform:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scaleX_Uniform(tmp, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
case *image.YCbCr:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scaleX_YCbCr(tmp, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
default:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scaleX_Image(tmp, src, sr)
|
2015-02-27 11:26:47 +01:00
|
|
|
}
|
2015-02-24 05:28:16 +01:00
|
|
|
}
|
2015-02-27 11:26:47 +01:00
|
|
|
|
2015-02-24 05:28:16 +01:00
|
|
|
switch dst := dst.(type) {
|
|
|
|
case *image.RGBA:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scaleY_RGBA(dst, dr, adr, tmp)
|
2015-02-24 05:28:16 +01:00
|
|
|
default:
|
2015-03-03 06:54:53 +01:00
|
|
|
z.scaleY_Image(dst, dr, adr, tmp)
|
2015-02-24 05:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (z *kernelScaler) scaleX_Gray(tmp [][4]float64, src *image.Gray, sr image.Rectangle) {
|
2015-02-28 06:05:58 +01:00
|
|
|
t := 0
|
|
|
|
for y := int32(0); y < z.sh; y++ {
|
|
|
|
for _, s := range z.horizontal.sources {
|
|
|
|
var pr, pg, pb, pa float64
|
|
|
|
for _, c := range z.horizontal.contribs[s.i:s.j] {
|
2015-03-03 06:54:53 +01:00
|
|
|
pru, pgu, pbu, pau := src.At(sr.Min.X+int(c.coord), sr.Min.Y+int(y)).RGBA()
|
2015-02-28 06:05:58 +01:00
|
|
|
pr += float64(pru) * c.weight
|
|
|
|
pg += float64(pgu) * c.weight
|
|
|
|
pb += float64(pbu) * c.weight
|
|
|
|
pa += float64(pau) * c.weight
|
|
|
|
}
|
|
|
|
tmp[t] = [4]float64{
|
|
|
|
pr * s.invTotalWeightFFFF,
|
|
|
|
pg * s.invTotalWeightFFFF,
|
|
|
|
pb * s.invTotalWeightFFFF,
|
|
|
|
pa * s.invTotalWeightFFFF,
|
|
|
|
}
|
|
|
|
t++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (z *kernelScaler) scaleX_NRGBA(tmp [][4]float64, src *image.NRGBA, sr image.Rectangle) {
|
2015-02-24 05:28:16 +01:00
|
|
|
t := 0
|
|
|
|
for y := int32(0); y < z.sh; y++ {
|
|
|
|
for _, s := range z.horizontal.sources {
|
|
|
|
var pr, pg, pb, pa float64
|
|
|
|
for _, c := range z.horizontal.contribs[s.i:s.j] {
|
2015-03-03 06:54:53 +01:00
|
|
|
pru, pgu, pbu, pau := src.At(sr.Min.X+int(c.coord), sr.Min.Y+int(y)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
pr += float64(pru) * c.weight
|
|
|
|
pg += float64(pgu) * c.weight
|
|
|
|
pb += float64(pbu) * c.weight
|
|
|
|
pa += float64(pau) * c.weight
|
|
|
|
}
|
|
|
|
tmp[t] = [4]float64{
|
|
|
|
pr * s.invTotalWeightFFFF,
|
|
|
|
pg * s.invTotalWeightFFFF,
|
|
|
|
pb * s.invTotalWeightFFFF,
|
|
|
|
pa * s.invTotalWeightFFFF,
|
|
|
|
}
|
|
|
|
t++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (z *kernelScaler) scaleX_RGBA(tmp [][4]float64, src *image.RGBA, sr image.Rectangle) {
|
2015-02-24 05:28:16 +01:00
|
|
|
t := 0
|
|
|
|
for y := int32(0); y < z.sh; y++ {
|
|
|
|
for _, s := range z.horizontal.sources {
|
|
|
|
var pr, pg, pb, pa float64
|
|
|
|
for _, c := range z.horizontal.contribs[s.i:s.j] {
|
2015-03-03 06:54:53 +01:00
|
|
|
pi := src.PixOffset(sr.Min.X+int(c.coord), sr.Min.Y+int(y))
|
2015-02-27 11:26:47 +01:00
|
|
|
pru := uint32(src.Pix[pi+0]) * 0x101
|
|
|
|
pgu := uint32(src.Pix[pi+1]) * 0x101
|
|
|
|
pbu := uint32(src.Pix[pi+2]) * 0x101
|
|
|
|
pau := uint32(src.Pix[pi+3]) * 0x101
|
2015-02-24 05:28:16 +01:00
|
|
|
pr += float64(pru) * c.weight
|
|
|
|
pg += float64(pgu) * c.weight
|
|
|
|
pb += float64(pbu) * c.weight
|
|
|
|
pa += float64(pau) * c.weight
|
|
|
|
}
|
|
|
|
tmp[t] = [4]float64{
|
|
|
|
pr * s.invTotalWeightFFFF,
|
|
|
|
pg * s.invTotalWeightFFFF,
|
|
|
|
pb * s.invTotalWeightFFFF,
|
|
|
|
pa * s.invTotalWeightFFFF,
|
|
|
|
}
|
|
|
|
t++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (z *kernelScaler) scaleX_Uniform(tmp [][4]float64, src *image.Uniform, sr image.Rectangle) {
|
2015-02-24 05:28:16 +01:00
|
|
|
t := 0
|
|
|
|
for y := int32(0); y < z.sh; y++ {
|
|
|
|
for _, s := range z.horizontal.sources {
|
|
|
|
var pr, pg, pb, pa float64
|
|
|
|
for _, c := range z.horizontal.contribs[s.i:s.j] {
|
2015-03-03 06:54:53 +01:00
|
|
|
pru, pgu, pbu, pau := src.At(sr.Min.X+int(c.coord), sr.Min.Y+int(y)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
pr += float64(pru) * c.weight
|
|
|
|
pg += float64(pgu) * c.weight
|
|
|
|
pb += float64(pbu) * c.weight
|
|
|
|
pa += float64(pau) * c.weight
|
|
|
|
}
|
|
|
|
tmp[t] = [4]float64{
|
|
|
|
pr * s.invTotalWeightFFFF,
|
|
|
|
pg * s.invTotalWeightFFFF,
|
|
|
|
pb * s.invTotalWeightFFFF,
|
|
|
|
pa * s.invTotalWeightFFFF,
|
|
|
|
}
|
|
|
|
t++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (z *kernelScaler) scaleX_YCbCr(tmp [][4]float64, src *image.YCbCr, sr image.Rectangle) {
|
2015-02-24 05:28:16 +01:00
|
|
|
t := 0
|
|
|
|
for y := int32(0); y < z.sh; y++ {
|
|
|
|
for _, s := range z.horizontal.sources {
|
|
|
|
var pr, pg, pb, pa float64
|
|
|
|
for _, c := range z.horizontal.contribs[s.i:s.j] {
|
2015-03-03 06:54:53 +01:00
|
|
|
pru, pgu, pbu, pau := src.At(sr.Min.X+int(c.coord), sr.Min.Y+int(y)).RGBA()
|
2015-02-24 05:28:16 +01:00
|
|
|
pr += float64(pru) * c.weight
|
|
|
|
pg += float64(pgu) * c.weight
|
|
|
|
pb += float64(pbu) * c.weight
|
|
|
|
pa += float64(pau) * c.weight
|
|
|
|
}
|
|
|
|
tmp[t] = [4]float64{
|
|
|
|
pr * s.invTotalWeightFFFF,
|
|
|
|
pg * s.invTotalWeightFFFF,
|
|
|
|
pb * s.invTotalWeightFFFF,
|
|
|
|
pa * s.invTotalWeightFFFF,
|
|
|
|
}
|
|
|
|
t++
|
|
|
|
}
|
|
|
|
}
|
2015-02-19 05:53:02 +01:00
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (z *kernelScaler) scaleX_Image(tmp [][4]float64, src image.Image, sr image.Rectangle) {
|
2015-02-19 05:53:02 +01:00
|
|
|
t := 0
|
|
|
|
for y := int32(0); y < z.sh; y++ {
|
|
|
|
for _, s := range z.horizontal.sources {
|
2015-02-20 08:28:54 +01:00
|
|
|
var pr, pg, pb, pa float64
|
2015-02-19 05:53:02 +01:00
|
|
|
for _, c := range z.horizontal.contribs[s.i:s.j] {
|
2015-03-03 06:54:53 +01:00
|
|
|
pru, pgu, pbu, pau := src.At(sr.Min.X+int(c.coord), sr.Min.Y+int(y)).RGBA()
|
2015-02-20 08:28:54 +01:00
|
|
|
pr += float64(pru) * c.weight
|
|
|
|
pg += float64(pgu) * c.weight
|
|
|
|
pb += float64(pbu) * c.weight
|
|
|
|
pa += float64(pau) * c.weight
|
2015-02-19 05:53:02 +01:00
|
|
|
}
|
|
|
|
tmp[t] = [4]float64{
|
2015-02-20 08:28:54 +01:00
|
|
|
pr * s.invTotalWeightFFFF,
|
|
|
|
pg * s.invTotalWeightFFFF,
|
|
|
|
pb * s.invTotalWeightFFFF,
|
|
|
|
pa * s.invTotalWeightFFFF,
|
2015-02-19 05:53:02 +01:00
|
|
|
}
|
|
|
|
t++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (z *kernelScaler) scaleY_RGBA(dst *image.RGBA, dr, adr image.Rectangle, tmp [][4]float64) {
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
2015-03-03 06:54:53 +01:00
|
|
|
d := dst.PixOffset(dr.Min.X+int(dx), dr.Min.Y+adr.Min.Y)
|
2015-03-03 05:47:39 +01:00
|
|
|
for _, s := range z.vertical.sources[adr.Min.Y:adr.Max.Y] {
|
2015-02-24 05:28:16 +01:00
|
|
|
var pr, pg, pb, pa float64
|
|
|
|
for _, c := range z.vertical.contribs[s.i:s.j] {
|
2015-02-26 06:20:04 +01:00
|
|
|
p := &tmp[c.coord*z.dw+dx]
|
2015-02-24 05:28:16 +01:00
|
|
|
pr += p[0] * c.weight
|
|
|
|
pg += p[1] * c.weight
|
|
|
|
pb += p[2] * c.weight
|
|
|
|
pa += p[3] * c.weight
|
|
|
|
}
|
2015-02-27 06:18:34 +01:00
|
|
|
dst.Pix[d+0] = uint8(ftou(pr*s.invTotalWeight) >> 8)
|
|
|
|
dst.Pix[d+1] = uint8(ftou(pg*s.invTotalWeight) >> 8)
|
|
|
|
dst.Pix[d+2] = uint8(ftou(pb*s.invTotalWeight) >> 8)
|
|
|
|
dst.Pix[d+3] = uint8(ftou(pa*s.invTotalWeight) >> 8)
|
|
|
|
d += dst.Stride
|
2015-02-24 05:28:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:54:53 +01:00
|
|
|
func (z *kernelScaler) scaleY_Image(dst Image, dr, adr image.Rectangle, tmp [][4]float64) {
|
2015-02-19 05:53:02 +01:00
|
|
|
dstColorRGBA64 := &color.RGBA64{}
|
|
|
|
dstColor := color.Color(dstColorRGBA64)
|
2015-03-03 05:47:39 +01:00
|
|
|
for dx := int32(adr.Min.X); dx < int32(adr.Max.X); dx++ {
|
|
|
|
for dy, s := range z.vertical.sources[adr.Min.Y:adr.Max.Y] {
|
2015-02-20 08:28:54 +01:00
|
|
|
var pr, pg, pb, pa float64
|
2015-02-19 05:53:02 +01:00
|
|
|
for _, c := range z.vertical.contribs[s.i:s.j] {
|
2015-02-26 06:20:04 +01:00
|
|
|
p := &tmp[c.coord*z.dw+dx]
|
2015-02-20 08:28:54 +01:00
|
|
|
pr += p[0] * c.weight
|
|
|
|
pg += p[1] * c.weight
|
|
|
|
pb += p[2] * c.weight
|
|
|
|
pa += p[3] * c.weight
|
2015-02-19 05:53:02 +01:00
|
|
|
}
|
2015-02-20 08:28:54 +01:00
|
|
|
dstColorRGBA64.R = ftou(pr * s.invTotalWeight)
|
|
|
|
dstColorRGBA64.G = ftou(pg * s.invTotalWeight)
|
|
|
|
dstColorRGBA64.B = ftou(pb * s.invTotalWeight)
|
|
|
|
dstColorRGBA64.A = ftou(pa * s.invTotalWeight)
|
2015-03-03 06:54:53 +01:00
|
|
|
dst.Set(dr.Min.X+int(dx), dr.Min.Y+int(adr.Min.Y+dy), dstColor)
|
2015-02-19 05:53:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|