Skip to content

Commit

Permalink
Add more getter and setter for sws
Browse files Browse the repository at this point in the history
Get/Set source w,h,pixfmt
Get/Set dst w,h,pixfmt
Get/Set sws flags
  • Loading branch information
Cacsjep committed Jan 25, 2024
1 parent 2dcc530 commit 5a50f31
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
46 changes: 39 additions & 7 deletions software_scale_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,36 @@ func (ssc *SoftwareScaleContext) PrepareDestinationFrameForScaling(dstFrame *Fra
return dstFrame.AllocBuffer(1)
}

func (ssc *SoftwareScaleContext) SetDestinationHeight(i int) error {
ssc.dstH = C.int(i)
return ssc.updateContext()
func (ssc *SoftwareScaleContext) DestinationHeight() int {
return int(ssc.dstH)
}

func (ssc *SoftwareScaleContext) SetDestinationWidth(i int) error {
ssc.dstW = C.int(i)
func (ssc *SoftwareScaleContext) DestinationPixelFormat() PixelFormat {
return PixelFormat(ssc.dstFormat)
}

func (ssc *SoftwareScaleContext) DestinationWidth() int {
return int(ssc.dstW)
}

func (ssc *SoftwareScaleContext) SourceHeight() int {
return int(ssc.srcH)
}

func (ssc *SoftwareScaleContext) SourcePixelFormat() PixelFormat {
return PixelFormat(ssc.srcFormat)
}

func (ssc *SoftwareScaleContext) SourceWidth() int {
return int(ssc.srcW)
}

func (ssc *SoftwareScaleContext) Flags() SoftwareScaleContextFlags {
return ssc.flags
}

func (ssc *SoftwareScaleContext) SetDestinationHeight(i int) error {
ssc.dstH = C.int(i)
return ssc.updateContext()
}

Expand All @@ -98,8 +121,8 @@ func (ssc *SoftwareScaleContext) SetDestinationPixelFormat(p PixelFormat) error
return ssc.updateContext()
}

func (ssc *SoftwareScaleContext) SetSourceWidth(i int) error {
ssc.srcW = C.int(i)
func (ssc *SoftwareScaleContext) SetDestinationWidth(i int) error {
ssc.dstW = C.int(i)
return ssc.updateContext()
}

Expand All @@ -113,6 +136,15 @@ func (ssc *SoftwareScaleContext) SetSourcePixelFormat(p PixelFormat) error {
return ssc.updateContext()
}

func (ssc *SoftwareScaleContext) SetSourceWidth(i int) error {
ssc.srcW = C.int(i)
return ssc.updateContext()
}

func (ssc *SoftwareScaleContext) SetFlags(swscf SoftwareScaleContextFlags) {
ssc.flags = swscf
}

func (sc *SoftwareScaleContext) Free() {
C.sws_freeContext(sc.c)
}
15 changes: 13 additions & 2 deletions software_scale_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ func TestSoftwareScaleContext(t *testing.T) {
f1.SetPixelFormat(srcPixelFormat)
require.NoError(t, f1.AllocBuffer(1))

swscf := astiav.NewSoftwareScaleContextFlags(astiav.SoftwareScaleContextBilinear)
swsc := astiav.NewSoftwareScaleContext(srcW, srcH, srcPixelFormat, dstW, dstH, dstPixelFormat, swscf)
swscf_1 := astiav.NewSoftwareScaleContextFlags(astiav.SoftwareScaleContextBilinear)
swsc := astiav.NewSoftwareScaleContext(srcW, srcH, srcPixelFormat, dstW, dstH, dstPixelFormat, swscf_1)
require.NotNil(t, swsc)
require.Equal(t, swsc.Flags(), swscf_1)

swscf_2 := astiav.NewSoftwareScaleContextFlags(astiav.SoftwareScaleContextPoint)
swsc.SetFlags(swscf_2)
require.Equal(t, swsc.Flags(), swscf_2)

require.NoError(t, swsc.PrepareDestinationFrameForScaling(f2))
require.Equal(t, dstH, swsc.ScaleFrame(f1, f2))
Expand All @@ -56,12 +61,18 @@ func TestSoftwareScaleContext(t *testing.T) {
dstPixelFormat = astiav.PixelFormatYuv420P

require.NoError(t, swsc.SetSourceWidth(f2.Width()))
require.Equal(t, swsc.SourceWidth(), f2.Width())
require.NoError(t, swsc.SetSourceHeight(f2.Height()))
require.Equal(t, swsc.SourceHeight(), f2.Height())
require.NoError(t, swsc.SetSourcePixelFormat(f2.PixelFormat()))
require.Equal(t, swsc.SourcePixelFormat(), f2.PixelFormat())

require.NoError(t, swsc.SetDestinationWidth(dstW))
require.Equal(t, swsc.DestinationWidth(), dstW)
require.NoError(t, swsc.SetDestinationHeight(dstH))
require.Equal(t, swsc.DestinationHeight(), dstH)
require.NoError(t, swsc.SetDestinationPixelFormat(dstPixelFormat))
require.Equal(t, swsc.DestinationPixelFormat(), dstPixelFormat)

require.NoError(t, swsc.PrepareDestinationFrameForScaling(f3))
require.Equal(t, f3.Height(), dstH)
Expand Down

0 comments on commit 5a50f31

Please sign in to comment.