resize!
This commit is contained in:
parent
095b52fb5d
commit
5c93e698b6
@ -6,6 +6,7 @@ import (
|
|||||||
"image/color"
|
"image/color"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/nfnt/resize"
|
||||||
"github.com/pion/mediadevices/pkg/frame"
|
"github.com/pion/mediadevices/pkg/frame"
|
||||||
"github.com/pion/mediadevices/pkg/io/video"
|
"github.com/pion/mediadevices/pkg/io/video"
|
||||||
"github.com/pion/mediadevices/pkg/prop"
|
"github.com/pion/mediadevices/pkg/prop"
|
||||||
@ -71,17 +72,16 @@ func (v *PPMStreamDriver) VideoRecord(p prop.Media) (video.Reader, error) {
|
|||||||
return nil, func() {}, err
|
return nil, func() {}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw input image in middle of canvas
|
// resize image and draw it to canvas
|
||||||
offsetX := (canvas.Bounds().Dx() - img.Bounds().Dx()) / 2
|
resized := resize.Resize(uint(p.Width), uint(p.Height), img, resize.Lanczos3)
|
||||||
offsetY := (canvas.Bounds().Dy() - img.Bounds().Dy()) / 2
|
for x := 0; x < resized.Bounds().Dx(); x++ {
|
||||||
for x := 0; x < img.Bounds().Dx(); x++ {
|
for y := 0; y < resized.Bounds().Dy(); y++ {
|
||||||
for y := 0; y < img.Bounds().Dy(); y++ {
|
r, g, b, _ := resized.At(x, y).RGBA()
|
||||||
r, g, b, _ := img.At(x, y).RGBA()
|
|
||||||
Y, Cb, Cr := color.RGBToYCbCr(uint8(r), uint8(g), uint8(b))
|
Y, Cb, Cr := color.RGBToYCbCr(uint8(r), uint8(g), uint8(b))
|
||||||
|
|
||||||
canvas.Y[canvas.YOffset(offsetX+x, offsetY+y)] = Y
|
canvas.Y[canvas.YOffset(x, y)] = Y
|
||||||
canvas.Cb[canvas.COffset(offsetX+x, offsetY+y)] = Cb
|
canvas.Cb[canvas.COffset(x, y)] = Cb
|
||||||
canvas.Cr[canvas.COffset(offsetX+x, offsetY+y)] = Cr
|
canvas.Cr[canvas.COffset(x, y)] = Cr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
go.mod
1
go.mod
@ -52,6 +52,7 @@ require (
|
|||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||||
github.com/digitalocean/go-qemu v0.0.0-20220804221245-2002801203aa
|
github.com/digitalocean/go-qemu v0.0.0-20220804221245-2002801203aa
|
||||||
github.com/gin-gonic/gin v1.8.1
|
github.com/gin-gonic/gin v1.8.1
|
||||||
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||||
github.com/pion/webrtc/v3 v3.1.43
|
github.com/pion/webrtc/v3 v3.1.43
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
github.com/sirupsen/logrus v1.9.0
|
github.com/sirupsen/logrus v1.9.0
|
||||||
|
2
go.sum
2
go.sum
@ -71,6 +71,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
|
|||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||||
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||||
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
|
Loading…
Reference in New Issue
Block a user