diff --git a/examples/scaling/main.go b/examples/scaling/main.go index f646033..ba4614a 100644 --- a/examples/scaling/main.go +++ b/examples/scaling/main.go @@ -62,7 +62,9 @@ func main() { defer swsCtx.Free() // Prepare destination frame (Width, Height and Buffer for correct scaling would be set) - swsCtx.PrepareDestinationFrameForScaling(dstFrame) + if err = swsCtx.PrepareDestinationFrameForScaling(dstFrame); err != nil { + log.Fatal(fmt.Errorf("main: prepare destination image failed: %w", err)) + } // Scale frame if output_slice_height := swsCtx.ScaleFrame(srcFrame, dstFrame); output_slice_height != *dstHeight { diff --git a/software_scale_context.go b/software_scale_context.go index f5d8edb..c4d5f7f 100644 --- a/software_scale_context.go +++ b/software_scale_context.go @@ -76,11 +76,11 @@ func (ssc *SoftwareScaleContext) updateContext() error { return nil } -func (ssc *SoftwareScaleContext) PrepareDestinationFrameForScaling(dstFrame *Frame) { +func (ssc *SoftwareScaleContext) PrepareDestinationFrameForScaling(dstFrame *Frame) error { dstFrame.SetPixelFormat(PixelFormat(ssc.dstFormat)) dstFrame.SetWidth(int(ssc.dstW)) dstFrame.SetHeight(int(ssc.dstH)) - dstFrame.AllocBuffer(1) + return dstFrame.AllocBuffer(1) } func (ssc *SoftwareScaleContext) SetDestinationHeight(i int) error { diff --git a/software_scale_context_test.go b/software_scale_context_test.go index 75c32b2..90e2a2a 100644 --- a/software_scale_context_test.go +++ b/software_scale_context_test.go @@ -37,7 +37,7 @@ func TestSoftwareScaleContext(t *testing.T) { swsc := astiav.NewSoftwareScaleContext(srcW, srcH, srcPixelFormat, dstW, dstH, dstPixelFormat, swscf) require.NotNil(t, swsc) - swsc.PrepareDestinationFrameForScaling(f2) + require.NoError(t, swsc.PrepareDestinationFrameForScaling(f2)) require.Equal(t, dstH, swsc.ScaleFrame(f1, f2)) require.Equal(t, dstW, f2.Height()) @@ -63,7 +63,7 @@ func TestSoftwareScaleContext(t *testing.T) { require.NoError(t, swsc.SetDestinationHeight(dstH)) require.NoError(t, swsc.SetDestinationPixelFormat(dstPixelFormat)) - swsc.PrepareDestinationFrameForScaling(f3) + require.NoError(t, swsc.PrepareDestinationFrameForScaling(f3)) require.Equal(t, f3.Height(), dstH) require.Equal(t, f3.Width(), dstW) require.Equal(t, f3.PixelFormat(), dstPixelFormat)