Fix Avatar Resize (resize algo NearestNeighbor -> Bilinear) (#12745)
* Update Vendor github.com/nfnt/resize * switch resize algo NearestNeighbor -> Bilinear
This commit is contained in:
parent
332dbe7393
commit
f7b3e06026
2
go.mod
2
go.mod
|
@ -73,7 +73,7 @@ require (
|
||||||
github.com/minio/minio-go/v7 v7.0.4
|
github.com/minio/minio-go/v7 v7.0.4
|
||||||
github.com/mitchellh/go-homedir v1.1.0
|
github.com/mitchellh/go-homedir v1.1.0
|
||||||
github.com/msteinert/pam v0.0.0-20151204160544-02ccfbfaf0cc
|
github.com/msteinert/pam v0.0.0-20151204160544-02ccfbfaf0cc
|
||||||
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||||
github.com/niklasfasching/go-org v1.3.2
|
github.com/niklasfasching/go-org v1.3.2
|
||||||
github.com/oliamb/cutter v0.2.2
|
github.com/oliamb/cutter v0.2.2
|
||||||
github.com/olivere/elastic/v7 v7.0.9
|
github.com/olivere/elastic/v7 v7.0.9
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -703,8 +703,8 @@ github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOl
|
||||||
github.com/msteinert/pam v0.0.0-20151204160544-02ccfbfaf0cc h1:z1PgdCCmYYVL0BoJTUgmAq1p7ca8fzYIPsNyfsN3xAU=
|
github.com/msteinert/pam v0.0.0-20151204160544-02ccfbfaf0cc h1:z1PgdCCmYYVL0BoJTUgmAq1p7ca8fzYIPsNyfsN3xAU=
|
||||||
github.com/msteinert/pam v0.0.0-20151204160544-02ccfbfaf0cc/go.mod h1:np1wUFZ6tyoke22qDJZY40URn9Ae51gX7ljIWXN5TJs=
|
github.com/msteinert/pam v0.0.0-20151204160544-02ccfbfaf0cc/go.mod h1:np1wUFZ6tyoke22qDJZY40URn9Ae51gX7ljIWXN5TJs=
|
||||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||||
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/RzCAL/191HHwJA5b13R6diVlY=
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||||
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||||
github.com/niklasfasching/go-org v1.3.2 h1:ZKTSd+GdJYkoZl1pBXLR/k7DRiRXnmB96TRiHmHdzwI=
|
github.com/niklasfasching/go-org v1.3.2 h1:ZKTSd+GdJYkoZl1pBXLR/k7DRiRXnmB96TRiHmHdzwI=
|
||||||
|
|
|
@ -89,6 +89,6 @@ func Prepare(data []byte) (*image.Image, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
img = resize.Resize(AvatarSize, AvatarSize, img, resize.NearestNeighbor)
|
img = resize.Resize(AvatarSize, AvatarSize, img, resize.Bilinear)
|
||||||
return &img, nil
|
return &img, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
language: go
|
language: go
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- 1.1
|
- "1.x"
|
||||||
- 1.2
|
- "1.1"
|
||||||
- 1.3
|
- "1.4"
|
||||||
- tip
|
- "1.10"
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# This package is no longer being updated! Please look for alternatives if that bothers you.
|
||||||
|
|
||||||
Resize
|
Resize
|
||||||
======
|
======
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,7 @@ var blur = 1.0
|
||||||
// If one of the parameters width or height is set to 0, its size will be calculated so that
|
// If one of the parameters width or height is set to 0, its size will be calculated so that
|
||||||
// the aspect ratio is that of the originating image.
|
// the aspect ratio is that of the originating image.
|
||||||
// The resizing algorithm uses channels for parallel computation.
|
// The resizing algorithm uses channels for parallel computation.
|
||||||
|
// If the input image has width or height of 0, it is returned unchanged.
|
||||||
func Resize(width, height uint, img image.Image, interp InterpolationFunction) image.Image {
|
func Resize(width, height uint, img image.Image, interp InterpolationFunction) image.Image {
|
||||||
scaleX, scaleY := calcFactors(width, height, float64(img.Bounds().Dx()), float64(img.Bounds().Dy()))
|
scaleX, scaleY := calcFactors(width, height, float64(img.Bounds().Dx()), float64(img.Bounds().Dy()))
|
||||||
if width == 0 {
|
if width == 0 {
|
||||||
|
@ -92,6 +93,11 @@ func Resize(width, height uint, img image.Image, interp InterpolationFunction) i
|
||||||
return img
|
return img
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Input image has no pixels
|
||||||
|
if img.Bounds().Dx() <= 0 || img.Bounds().Dy() <= 0 {
|
||||||
|
return img
|
||||||
|
}
|
||||||
|
|
||||||
if interp == NearestNeighbor {
|
if interp == NearestNeighbor {
|
||||||
return resizeNearest(width, height, scaleX, scaleY, img, interp)
|
return resizeNearest(width, height, scaleX, scaleY, img, interp)
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,70 +88,34 @@ func newYCC(r image.Rectangle, s image.YCbCrSubsampleRatio) *ycc {
|
||||||
return &ycc{Pix: buf, Stride: 3 * w, Rect: r, SubsampleRatio: s}
|
return &ycc{Pix: buf, Stride: 3 * w, Rect: r, SubsampleRatio: s}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy of image.YCbCrSubsampleRatio constants - this allows us to support
|
||||||
|
// older versions of Go where these constants are not defined (i.e. Go 1.4)
|
||||||
|
const (
|
||||||
|
ycbcrSubsampleRatio444 image.YCbCrSubsampleRatio = iota
|
||||||
|
ycbcrSubsampleRatio422
|
||||||
|
ycbcrSubsampleRatio420
|
||||||
|
ycbcrSubsampleRatio440
|
||||||
|
ycbcrSubsampleRatio411
|
||||||
|
ycbcrSubsampleRatio410
|
||||||
|
)
|
||||||
|
|
||||||
// YCbCr converts ycc to a YCbCr image with the same subsample ratio
|
// YCbCr converts ycc to a YCbCr image with the same subsample ratio
|
||||||
// as the YCbCr image that ycc was generated from.
|
// as the YCbCr image that ycc was generated from.
|
||||||
func (p *ycc) YCbCr() *image.YCbCr {
|
func (p *ycc) YCbCr() *image.YCbCr {
|
||||||
ycbcr := image.NewYCbCr(p.Rect, p.SubsampleRatio)
|
ycbcr := image.NewYCbCr(p.Rect, p.SubsampleRatio)
|
||||||
var off int
|
|
||||||
|
|
||||||
switch ycbcr.SubsampleRatio {
|
switch ycbcr.SubsampleRatio {
|
||||||
case image.YCbCrSubsampleRatio422:
|
case ycbcrSubsampleRatio422:
|
||||||
for y := ycbcr.Rect.Min.Y; y < ycbcr.Rect.Max.Y; y++ {
|
return p.ycbcr422(ycbcr)
|
||||||
yy := (y - ycbcr.Rect.Min.Y) * ycbcr.YStride
|
case ycbcrSubsampleRatio420:
|
||||||
cy := (y - ycbcr.Rect.Min.Y) * ycbcr.CStride
|
return p.ycbcr420(ycbcr)
|
||||||
for x := ycbcr.Rect.Min.X; x < ycbcr.Rect.Max.X; x++ {
|
case ycbcrSubsampleRatio440:
|
||||||
xx := (x - ycbcr.Rect.Min.X)
|
return p.ycbcr440(ycbcr)
|
||||||
yi := yy + xx
|
case ycbcrSubsampleRatio444:
|
||||||
ci := cy + xx/2
|
return p.ycbcr444(ycbcr)
|
||||||
ycbcr.Y[yi] = p.Pix[off+0]
|
case ycbcrSubsampleRatio411:
|
||||||
ycbcr.Cb[ci] = p.Pix[off+1]
|
return p.ycbcr411(ycbcr)
|
||||||
ycbcr.Cr[ci] = p.Pix[off+2]
|
case ycbcrSubsampleRatio410:
|
||||||
off += 3
|
return p.ycbcr410(ycbcr)
|
||||||
}
|
|
||||||
}
|
|
||||||
case image.YCbCrSubsampleRatio420:
|
|
||||||
for y := ycbcr.Rect.Min.Y; y < ycbcr.Rect.Max.Y; y++ {
|
|
||||||
yy := (y - ycbcr.Rect.Min.Y) * ycbcr.YStride
|
|
||||||
cy := (y/2 - ycbcr.Rect.Min.Y/2) * ycbcr.CStride
|
|
||||||
for x := ycbcr.Rect.Min.X; x < ycbcr.Rect.Max.X; x++ {
|
|
||||||
xx := (x - ycbcr.Rect.Min.X)
|
|
||||||
yi := yy + xx
|
|
||||||
ci := cy + xx/2
|
|
||||||
ycbcr.Y[yi] = p.Pix[off+0]
|
|
||||||
ycbcr.Cb[ci] = p.Pix[off+1]
|
|
||||||
ycbcr.Cr[ci] = p.Pix[off+2]
|
|
||||||
off += 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case image.YCbCrSubsampleRatio440:
|
|
||||||
for y := ycbcr.Rect.Min.Y; y < ycbcr.Rect.Max.Y; y++ {
|
|
||||||
yy := (y - ycbcr.Rect.Min.Y) * ycbcr.YStride
|
|
||||||
cy := (y/2 - ycbcr.Rect.Min.Y/2) * ycbcr.CStride
|
|
||||||
for x := ycbcr.Rect.Min.X; x < ycbcr.Rect.Max.X; x++ {
|
|
||||||
xx := (x - ycbcr.Rect.Min.X)
|
|
||||||
yi := yy + xx
|
|
||||||
ci := cy + xx
|
|
||||||
ycbcr.Y[yi] = p.Pix[off+0]
|
|
||||||
ycbcr.Cb[ci] = p.Pix[off+1]
|
|
||||||
ycbcr.Cr[ci] = p.Pix[off+2]
|
|
||||||
off += 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
// Default to 4:4:4 subsampling.
|
|
||||||
for y := ycbcr.Rect.Min.Y; y < ycbcr.Rect.Max.Y; y++ {
|
|
||||||
yy := (y - ycbcr.Rect.Min.Y) * ycbcr.YStride
|
|
||||||
cy := (y - ycbcr.Rect.Min.Y) * ycbcr.CStride
|
|
||||||
for x := ycbcr.Rect.Min.X; x < ycbcr.Rect.Max.X; x++ {
|
|
||||||
xx := (x - ycbcr.Rect.Min.X)
|
|
||||||
yi := yy + xx
|
|
||||||
ci := cy + xx
|
|
||||||
ycbcr.Y[yi] = p.Pix[off+0]
|
|
||||||
ycbcr.Cb[ci] = p.Pix[off+1]
|
|
||||||
ycbcr.Cr[ci] = p.Pix[off+2]
|
|
||||||
off += 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ycbcr
|
return ycbcr
|
||||||
}
|
}
|
||||||
|
@ -159,69 +123,265 @@ func (p *ycc) YCbCr() *image.YCbCr {
|
||||||
// imageYCbCrToYCC converts a YCbCr image to a ycc image for resizing.
|
// imageYCbCrToYCC converts a YCbCr image to a ycc image for resizing.
|
||||||
func imageYCbCrToYCC(in *image.YCbCr) *ycc {
|
func imageYCbCrToYCC(in *image.YCbCr) *ycc {
|
||||||
w, h := in.Rect.Dx(), in.Rect.Dy()
|
w, h := in.Rect.Dx(), in.Rect.Dy()
|
||||||
r := image.Rect(0, 0, w, h)
|
p := ycc{
|
||||||
buf := make([]uint8, 3*w*h)
|
Pix: make([]uint8, 3*w*h),
|
||||||
p := ycc{Pix: buf, Stride: 3 * w, Rect: r, SubsampleRatio: in.SubsampleRatio}
|
Stride: 3 * w,
|
||||||
var off int
|
Rect: image.Rect(0, 0, w, h),
|
||||||
|
SubsampleRatio: in.SubsampleRatio,
|
||||||
|
}
|
||||||
switch in.SubsampleRatio {
|
switch in.SubsampleRatio {
|
||||||
case image.YCbCrSubsampleRatio422:
|
case ycbcrSubsampleRatio422:
|
||||||
for y := in.Rect.Min.Y; y < in.Rect.Max.Y; y++ {
|
return convertToYCC422(in, &p)
|
||||||
yy := (y - in.Rect.Min.Y) * in.YStride
|
case ycbcrSubsampleRatio420:
|
||||||
cy := (y - in.Rect.Min.Y) * in.CStride
|
return convertToYCC420(in, &p)
|
||||||
for x := in.Rect.Min.X; x < in.Rect.Max.X; x++ {
|
case ycbcrSubsampleRatio440:
|
||||||
xx := (x - in.Rect.Min.X)
|
return convertToYCC440(in, &p)
|
||||||
yi := yy + xx
|
case ycbcrSubsampleRatio444:
|
||||||
ci := cy + xx/2
|
return convertToYCC444(in, &p)
|
||||||
p.Pix[off+0] = in.Y[yi]
|
case ycbcrSubsampleRatio411:
|
||||||
p.Pix[off+1] = in.Cb[ci]
|
return convertToYCC411(in, &p)
|
||||||
p.Pix[off+2] = in.Cr[ci]
|
case ycbcrSubsampleRatio410:
|
||||||
off += 3
|
return convertToYCC410(in, &p)
|
||||||
}
|
|
||||||
}
|
|
||||||
case image.YCbCrSubsampleRatio420:
|
|
||||||
for y := in.Rect.Min.Y; y < in.Rect.Max.Y; y++ {
|
|
||||||
yy := (y - in.Rect.Min.Y) * in.YStride
|
|
||||||
cy := (y/2 - in.Rect.Min.Y/2) * in.CStride
|
|
||||||
for x := in.Rect.Min.X; x < in.Rect.Max.X; x++ {
|
|
||||||
xx := (x - in.Rect.Min.X)
|
|
||||||
yi := yy + xx
|
|
||||||
ci := cy + xx/2
|
|
||||||
p.Pix[off+0] = in.Y[yi]
|
|
||||||
p.Pix[off+1] = in.Cb[ci]
|
|
||||||
p.Pix[off+2] = in.Cr[ci]
|
|
||||||
off += 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case image.YCbCrSubsampleRatio440:
|
|
||||||
for y := in.Rect.Min.Y; y < in.Rect.Max.Y; y++ {
|
|
||||||
yy := (y - in.Rect.Min.Y) * in.YStride
|
|
||||||
cy := (y/2 - in.Rect.Min.Y/2) * in.CStride
|
|
||||||
for x := in.Rect.Min.X; x < in.Rect.Max.X; x++ {
|
|
||||||
xx := (x - in.Rect.Min.X)
|
|
||||||
yi := yy + xx
|
|
||||||
ci := cy + xx
|
|
||||||
p.Pix[off+0] = in.Y[yi]
|
|
||||||
p.Pix[off+1] = in.Cb[ci]
|
|
||||||
p.Pix[off+2] = in.Cr[ci]
|
|
||||||
off += 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
// Default to 4:4:4 subsampling.
|
|
||||||
for y := in.Rect.Min.Y; y < in.Rect.Max.Y; y++ {
|
|
||||||
yy := (y - in.Rect.Min.Y) * in.YStride
|
|
||||||
cy := (y - in.Rect.Min.Y) * in.CStride
|
|
||||||
for x := in.Rect.Min.X; x < in.Rect.Max.X; x++ {
|
|
||||||
xx := (x - in.Rect.Min.X)
|
|
||||||
yi := yy + xx
|
|
||||||
ci := cy + xx
|
|
||||||
p.Pix[off+0] = in.Y[yi]
|
|
||||||
p.Pix[off+1] = in.Cb[ci]
|
|
||||||
p.Pix[off+2] = in.Cr[ci]
|
|
||||||
off += 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return &p
|
return &p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ycc) ycbcr422(ycbcr *image.YCbCr) *image.YCbCr {
|
||||||
|
var off int
|
||||||
|
Pix := p.Pix
|
||||||
|
Y := ycbcr.Y
|
||||||
|
Cb := ycbcr.Cb
|
||||||
|
Cr := ycbcr.Cr
|
||||||
|
for y := 0; y < ycbcr.Rect.Max.Y-ycbcr.Rect.Min.Y; y++ {
|
||||||
|
yy := y * ycbcr.YStride
|
||||||
|
cy := y * ycbcr.CStride
|
||||||
|
for x := 0; x < ycbcr.Rect.Max.X-ycbcr.Rect.Min.X; x++ {
|
||||||
|
ci := cy + x/2
|
||||||
|
Y[yy+x] = Pix[off+0]
|
||||||
|
Cb[ci] = Pix[off+1]
|
||||||
|
Cr[ci] = Pix[off+2]
|
||||||
|
off += 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ycbcr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ycc) ycbcr420(ycbcr *image.YCbCr) *image.YCbCr {
|
||||||
|
var off int
|
||||||
|
Pix := p.Pix
|
||||||
|
Y := ycbcr.Y
|
||||||
|
Cb := ycbcr.Cb
|
||||||
|
Cr := ycbcr.Cr
|
||||||
|
for y := 0; y < ycbcr.Rect.Max.Y-ycbcr.Rect.Min.Y; y++ {
|
||||||
|
yy := y * ycbcr.YStride
|
||||||
|
cy := (y / 2) * ycbcr.CStride
|
||||||
|
for x := 0; x < ycbcr.Rect.Max.X-ycbcr.Rect.Min.X; x++ {
|
||||||
|
ci := cy + x/2
|
||||||
|
Y[yy+x] = Pix[off+0]
|
||||||
|
Cb[ci] = Pix[off+1]
|
||||||
|
Cr[ci] = Pix[off+2]
|
||||||
|
off += 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ycbcr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ycc) ycbcr440(ycbcr *image.YCbCr) *image.YCbCr {
|
||||||
|
var off int
|
||||||
|
Pix := p.Pix
|
||||||
|
Y := ycbcr.Y
|
||||||
|
Cb := ycbcr.Cb
|
||||||
|
Cr := ycbcr.Cr
|
||||||
|
for y := 0; y < ycbcr.Rect.Max.Y-ycbcr.Rect.Min.Y; y++ {
|
||||||
|
yy := y * ycbcr.YStride
|
||||||
|
cy := (y / 2) * ycbcr.CStride
|
||||||
|
for x := 0; x < ycbcr.Rect.Max.X-ycbcr.Rect.Min.X; x++ {
|
||||||
|
ci := cy + x
|
||||||
|
Y[yy+x] = Pix[off+0]
|
||||||
|
Cb[ci] = Pix[off+1]
|
||||||
|
Cr[ci] = Pix[off+2]
|
||||||
|
off += 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ycbcr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ycc) ycbcr444(ycbcr *image.YCbCr) *image.YCbCr {
|
||||||
|
var off int
|
||||||
|
Pix := p.Pix
|
||||||
|
Y := ycbcr.Y
|
||||||
|
Cb := ycbcr.Cb
|
||||||
|
Cr := ycbcr.Cr
|
||||||
|
for y := 0; y < ycbcr.Rect.Max.Y-ycbcr.Rect.Min.Y; y++ {
|
||||||
|
yy := y * ycbcr.YStride
|
||||||
|
cy := y * ycbcr.CStride
|
||||||
|
for x := 0; x < ycbcr.Rect.Max.X-ycbcr.Rect.Min.X; x++ {
|
||||||
|
ci := cy + x
|
||||||
|
Y[yy+x] = Pix[off+0]
|
||||||
|
Cb[ci] = Pix[off+1]
|
||||||
|
Cr[ci] = Pix[off+2]
|
||||||
|
off += 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ycbcr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ycc) ycbcr411(ycbcr *image.YCbCr) *image.YCbCr {
|
||||||
|
var off int
|
||||||
|
Pix := p.Pix
|
||||||
|
Y := ycbcr.Y
|
||||||
|
Cb := ycbcr.Cb
|
||||||
|
Cr := ycbcr.Cr
|
||||||
|
for y := 0; y < ycbcr.Rect.Max.Y-ycbcr.Rect.Min.Y; y++ {
|
||||||
|
yy := y * ycbcr.YStride
|
||||||
|
cy := y * ycbcr.CStride
|
||||||
|
for x := 0; x < ycbcr.Rect.Max.X-ycbcr.Rect.Min.X; x++ {
|
||||||
|
ci := cy + x/4
|
||||||
|
Y[yy+x] = Pix[off+0]
|
||||||
|
Cb[ci] = Pix[off+1]
|
||||||
|
Cr[ci] = Pix[off+2]
|
||||||
|
off += 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ycbcr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ycc) ycbcr410(ycbcr *image.YCbCr) *image.YCbCr {
|
||||||
|
var off int
|
||||||
|
Pix := p.Pix
|
||||||
|
Y := ycbcr.Y
|
||||||
|
Cb := ycbcr.Cb
|
||||||
|
Cr := ycbcr.Cr
|
||||||
|
for y := 0; y < ycbcr.Rect.Max.Y-ycbcr.Rect.Min.Y; y++ {
|
||||||
|
yy := y * ycbcr.YStride
|
||||||
|
cy := (y / 2) * ycbcr.CStride
|
||||||
|
for x := 0; x < ycbcr.Rect.Max.X-ycbcr.Rect.Min.X; x++ {
|
||||||
|
ci := cy + x/4
|
||||||
|
Y[yy+x] = Pix[off+0]
|
||||||
|
Cb[ci] = Pix[off+1]
|
||||||
|
Cr[ci] = Pix[off+2]
|
||||||
|
off += 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ycbcr
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertToYCC422(in *image.YCbCr, p *ycc) *ycc {
|
||||||
|
var off int
|
||||||
|
Pix := p.Pix
|
||||||
|
Y := in.Y
|
||||||
|
Cb := in.Cb
|
||||||
|
Cr := in.Cr
|
||||||
|
for y := 0; y < in.Rect.Max.Y-in.Rect.Min.Y; y++ {
|
||||||
|
yy := y * in.YStride
|
||||||
|
cy := y * in.CStride
|
||||||
|
for x := 0; x < in.Rect.Max.X-in.Rect.Min.X; x++ {
|
||||||
|
ci := cy + x/2
|
||||||
|
Pix[off+0] = Y[yy+x]
|
||||||
|
Pix[off+1] = Cb[ci]
|
||||||
|
Pix[off+2] = Cr[ci]
|
||||||
|
off += 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertToYCC420(in *image.YCbCr, p *ycc) *ycc {
|
||||||
|
var off int
|
||||||
|
Pix := p.Pix
|
||||||
|
Y := in.Y
|
||||||
|
Cb := in.Cb
|
||||||
|
Cr := in.Cr
|
||||||
|
for y := 0; y < in.Rect.Max.Y-in.Rect.Min.Y; y++ {
|
||||||
|
yy := y * in.YStride
|
||||||
|
cy := (y / 2) * in.CStride
|
||||||
|
for x := 0; x < in.Rect.Max.X-in.Rect.Min.X; x++ {
|
||||||
|
ci := cy + x/2
|
||||||
|
Pix[off+0] = Y[yy+x]
|
||||||
|
Pix[off+1] = Cb[ci]
|
||||||
|
Pix[off+2] = Cr[ci]
|
||||||
|
off += 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertToYCC440(in *image.YCbCr, p *ycc) *ycc {
|
||||||
|
var off int
|
||||||
|
Pix := p.Pix
|
||||||
|
Y := in.Y
|
||||||
|
Cb := in.Cb
|
||||||
|
Cr := in.Cr
|
||||||
|
for y := 0; y < in.Rect.Max.Y-in.Rect.Min.Y; y++ {
|
||||||
|
yy := y * in.YStride
|
||||||
|
cy := (y / 2) * in.CStride
|
||||||
|
for x := 0; x < in.Rect.Max.X-in.Rect.Min.X; x++ {
|
||||||
|
ci := cy + x
|
||||||
|
Pix[off+0] = Y[yy+x]
|
||||||
|
Pix[off+1] = Cb[ci]
|
||||||
|
Pix[off+2] = Cr[ci]
|
||||||
|
off += 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertToYCC444(in *image.YCbCr, p *ycc) *ycc {
|
||||||
|
var off int
|
||||||
|
Pix := p.Pix
|
||||||
|
Y := in.Y
|
||||||
|
Cb := in.Cb
|
||||||
|
Cr := in.Cr
|
||||||
|
for y := 0; y < in.Rect.Max.Y-in.Rect.Min.Y; y++ {
|
||||||
|
yy := y * in.YStride
|
||||||
|
cy := y * in.CStride
|
||||||
|
for x := 0; x < in.Rect.Max.X-in.Rect.Min.X; x++ {
|
||||||
|
ci := cy + x
|
||||||
|
Pix[off+0] = Y[yy+x]
|
||||||
|
Pix[off+1] = Cb[ci]
|
||||||
|
Pix[off+2] = Cr[ci]
|
||||||
|
off += 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertToYCC411(in *image.YCbCr, p *ycc) *ycc {
|
||||||
|
var off int
|
||||||
|
Pix := p.Pix
|
||||||
|
Y := in.Y
|
||||||
|
Cb := in.Cb
|
||||||
|
Cr := in.Cr
|
||||||
|
for y := 0; y < in.Rect.Max.Y-in.Rect.Min.Y; y++ {
|
||||||
|
yy := y * in.YStride
|
||||||
|
cy := y * in.CStride
|
||||||
|
for x := 0; x < in.Rect.Max.X-in.Rect.Min.X; x++ {
|
||||||
|
ci := cy + x/4
|
||||||
|
Pix[off+0] = Y[yy+x]
|
||||||
|
Pix[off+1] = Cb[ci]
|
||||||
|
Pix[off+2] = Cr[ci]
|
||||||
|
off += 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertToYCC410(in *image.YCbCr, p *ycc) *ycc {
|
||||||
|
var off int
|
||||||
|
Pix := p.Pix
|
||||||
|
Y := in.Y
|
||||||
|
Cb := in.Cb
|
||||||
|
Cr := in.Cr
|
||||||
|
for y := 0; y < in.Rect.Max.Y-in.Rect.Min.Y; y++ {
|
||||||
|
yy := y * in.YStride
|
||||||
|
cy := (y / 2) * in.CStride
|
||||||
|
for x := 0; x < in.Rect.Max.X-in.Rect.Min.X; x++ {
|
||||||
|
ci := cy + x/4
|
||||||
|
Pix[off+0] = Y[yy+x]
|
||||||
|
Pix[off+1] = Cb[ci]
|
||||||
|
Pix[off+2] = Cr[ci]
|
||||||
|
off += 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
|
@ -597,7 +597,7 @@ github.com/mschoch/smat
|
||||||
# github.com/msteinert/pam v0.0.0-20151204160544-02ccfbfaf0cc
|
# github.com/msteinert/pam v0.0.0-20151204160544-02ccfbfaf0cc
|
||||||
## explicit
|
## explicit
|
||||||
github.com/msteinert/pam
|
github.com/msteinert/pam
|
||||||
# github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5
|
# github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||||
## explicit
|
## explicit
|
||||||
github.com/nfnt/resize
|
github.com/nfnt/resize
|
||||||
# github.com/niklasfasching/go-org v1.3.2
|
# github.com/niklasfasching/go-org v1.3.2
|
||||||
|
|
Loading…
Reference in New Issue