mirror of
https://github.com/asticode/go-astiav.git
synced 2025-10-04 15:52:52 +08:00
Implementation for SWS scale (#33)
* Draft implementation for SWS scale
* Update go.mod
* Revert "Update go.mod"
This reverts commit 760fb8c427
.
* Renaming to AllocSwsContext and remove ChangeResolution this should handled by users
* update example to use new name and remove ChangeResolution
* Follow scaling example from libav, update readme, improve sws
Change scaling example to an similar libav example
Update readme
Add func to UpdateScalingParameters
Rename AllocSwsContext to SwsGetContext
Using a type for scaling algos/flags
* Fix Errors in scale example
* Review Changes
Now using sws context flags
Restructer sws context and adding ned simpler methods to update the ctx
Update the example
Update the test
* Correctly handle error for buffer alloc in PrepareDestinationFrameForScaling
* Add more getter and setter for sws
Get/Set source w,h,pixfmt
Get/Set dst w,h,pixfmt
Get/Set sws flags
* Adding resolution get/set
* Use CachedContext when updating sws ctx
* Review changes
Reorder flags, and update them
# Update Example
Use renaming function to create sws context
Clean up
Use new framdata image funcs
# Sws scale context
New way to update the context
Use sws_scale_frame instead of sws_scale
Reordering funcs for get and set
# Sws sclate context flag
Add "Flag" for algo name
# Update sws test
* fix fmt error args bug
* Review Changes
Simpfy sws update
Use c.int for sws flags
update test
This commit is contained in:
88
software_scale_context_test.go
Normal file
88
software_scale_context_test.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package astiav_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/asticode/go-astiav"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSoftwareScaleContext(t *testing.T) {
|
||||
f1 := astiav.AllocFrame()
|
||||
require.NotNil(t, f1)
|
||||
defer f1.Free()
|
||||
|
||||
f2 := astiav.AllocFrame()
|
||||
require.NotNil(t, f2)
|
||||
defer f2.Free()
|
||||
|
||||
f3 := astiav.AllocFrame()
|
||||
require.NotNil(t, f3)
|
||||
defer f3.Free()
|
||||
|
||||
srcW := 320
|
||||
srcH := 280
|
||||
srcPixelFormat := astiav.PixelFormatYuv420P
|
||||
dstW := 640
|
||||
dstH := 480
|
||||
dstPixelFormat := astiav.PixelFormatRgba
|
||||
swscf1 := astiav.SoftwareScaleContextFlags(astiav.SoftwareScaleContextFlagBilinear)
|
||||
|
||||
f1.SetHeight(srcH)
|
||||
f1.SetWidth(srcW)
|
||||
f1.SetPixelFormat(srcPixelFormat)
|
||||
require.NoError(t, f1.AllocBuffer(1))
|
||||
|
||||
swsc, err := astiav.CreateSoftwareScaleContext(srcW, srcH, srcPixelFormat, dstW, dstH, dstPixelFormat, swscf1)
|
||||
require.NoError(t, err)
|
||||
defer swsc.Free()
|
||||
|
||||
require.NoError(t, swsc.ScaleFrame(f1, f2))
|
||||
require.Equal(t, dstH, f2.Height())
|
||||
require.Equal(t, dstW, f2.Width())
|
||||
require.Equal(t, dstPixelFormat, f2.PixelFormat())
|
||||
|
||||
dstW = 1024
|
||||
dstH = 576
|
||||
dstPixelFormat = astiav.PixelFormatYuv420P
|
||||
swscf2 := astiav.SoftwareScaleContextFlags(astiav.SoftwareScaleContextFlagPoint)
|
||||
|
||||
require.Equal(t, swsc.Flags(), swscf1)
|
||||
swsc.SetFlags(swscf2)
|
||||
require.Equal(t, swsc.Flags(), swscf2)
|
||||
|
||||
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())
|
||||
|
||||
newSourceW := 1280
|
||||
newSourceH := 720
|
||||
require.NoError(t, swsc.SetSourceResolution(newSourceW, newSourceH))
|
||||
w, h := swsc.SourceResolution()
|
||||
require.Equal(t, w, newSourceW)
|
||||
require.Equal(t, h, newSourceH)
|
||||
require.NoError(t, swsc.SetSourceResolution(f2.Width(), f2.Height()))
|
||||
require.NoError(t, swsc.SetSourcePixelFormat(f2.PixelFormat()))
|
||||
require.Equal(t, swsc.SourcePixelFormat(), f2.PixelFormat())
|
||||
|
||||
newDestW := 800
|
||||
newDestH := 600
|
||||
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.SetDestinationResolution(newDestW, newDestH))
|
||||
w, h = swsc.DestinationResolution()
|
||||
require.Equal(t, w, newDestW)
|
||||
require.Equal(t, h, newDestH)
|
||||
require.NoError(t, swsc.SetDestinationResolution(dstW, dstH))
|
||||
require.NoError(t, swsc.SetDestinationPixelFormat(dstPixelFormat))
|
||||
require.Equal(t, swsc.DestinationPixelFormat(), dstPixelFormat)
|
||||
|
||||
require.NoError(t, swsc.ScaleFrame(f2, f3))
|
||||
require.Equal(t, dstW, f3.Width())
|
||||
require.Equal(t, dstH, f3.Height())
|
||||
require.Equal(t, dstPixelFormat, f3.PixelFormat())
|
||||
|
||||
}
|
Reference in New Issue
Block a user