Skip to content

Commit

Permalink
fix i422ToI420 calculation, add mock FastBoxSampling
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdarrakhman Akhmetgali authored and edaniels committed Apr 15, 2023
1 parent 0dc4f43 commit bf290b0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/io/video/convert_nocgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func i422ToI420(img image.YCbCr, dst []uint8) image.YCbCr {
for j := 0; j < img.CStride; j++ {
cb := uint16(img.Cb[addrSrc]) + uint16(img.Cb[addrSrc+img.CStride])
cr := uint16(img.Cr[addrSrc]) + uint16(img.Cr[addrSrc+img.CStride])
cbDst[addrDst] = uint8(cb / 4)
crDst[addrDst] = uint8(cr / 4)
cbDst[addrDst] = uint8(cb / 2)
crDst[addrDst] = uint8(cr / 2)
addrSrc++
addrDst++
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/io/video/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@ func TestScale(t *testing.T) {
}

func TestScaleFastBoxSampling(t *testing.T) {
if !hasCGOConvert {
t.Skip("Skip: nocgo implementation is not supported for FastBoxSampling")
}
cases := map[string]struct {
src image.Image
width, height int
Expand Down
22 changes: 22 additions & 0 deletions pkg/io/video/scaler_nocgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build !cgo
// +build !cgo

package video

import (
"golang.org/x/image/draw"
"image"
)

// ScalerFastBoxSampling mock scaler for nocgo implementation to pass tests for CGO_ENABLED=0
var (
ScalerFastBoxSampling = Scaler(&FastBoxSampling{})
)

// FastBoxSampling mock implementation for nocgo implementation
// TODO implement nocgo FastBoxSampling scaling algorithm
type FastBoxSampling struct {
}

func (f *FastBoxSampling) Scale(_ draw.Image, _ image.Rectangle, _ image.Image, _ image.Rectangle, _ draw.Op, _ *draw.Options) {
}

0 comments on commit bf290b0

Please sign in to comment.