diff --git a/software_scale_context.go b/software_scale_context.go index c4d5f7f..bf76c83 100644 --- a/software_scale_context.go +++ b/software_scale_context.go @@ -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() } @@ -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() } @@ -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) } diff --git a/software_scale_context_test.go b/software_scale_context_test.go index 90e2a2a..4935566 100644 --- a/software_scale_context_test.go +++ b/software_scale_context_test.go @@ -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)) @@ -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)