mirror of
https://github.com/asticode/go-astiav.git
synced 2025-10-10 02:20:10 +08:00

* 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
108 lines
3.0 KiB
Go
108 lines
3.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"text/template"
|
|
)
|
|
|
|
type listItem struct {
|
|
Name string
|
|
Suffix string
|
|
}
|
|
|
|
var list = []listItem{
|
|
{Name: "Buffersink"},
|
|
{Name: "Buffersrc"},
|
|
{Name: "CodecContext"},
|
|
{Name: "CodecContext", Suffix: "2"},
|
|
{Name: "CodecHardwareConfigMethod"},
|
|
{Name: "Dictionary"},
|
|
{Name: "FilterCommand"},
|
|
{Name: "FormatContext"},
|
|
{Name: "FormatContextCtx"},
|
|
{Name: "FormatEvent"},
|
|
{Name: "IOContext"},
|
|
{Name: "IOFormat"},
|
|
{Name: "Packet"},
|
|
{Name: "Seek"},
|
|
{Name: "SoftwareScaleContext"},
|
|
{Name: "StreamEvent"},
|
|
}
|
|
|
|
var tmpl = `// Code generated by astiav. DO NOT EDIT.
|
|
package astiav
|
|
|
|
import (
|
|
"github.com/asticode/go-astikit"
|
|
)
|
|
{{ range $val := . }}
|
|
type {{ $val.Name }}Flags{{ $val.Suffix }} astikit.BitFlags
|
|
|
|
func New{{ $val.Name }}Flags{{ $val.Suffix }}(fs ...{{ $val.Name }}Flag{{ $val.Suffix }}) {{ $val.Name }}Flags{{ $val.Suffix }} {
|
|
o := {{ $val.Name }}Flags{{ $val.Suffix }}(0)
|
|
for _, f := range fs {
|
|
o = o.Add(f)
|
|
}
|
|
return o
|
|
}
|
|
|
|
func (fs {{ $val.Name }}Flags{{ $val.Suffix }}) Add(f {{ $val.Name }}Flag{{ $val.Suffix }}) {{ $val.Name }}Flags{{ $val.Suffix }} {
|
|
return {{ $val.Name }}Flags{{ $val.Suffix }}(astikit.BitFlags(fs).Add(uint64(f)))
|
|
}
|
|
|
|
func (fs {{ $val.Name }}Flags{{ $val.Suffix }}) Del(f {{ $val.Name }}Flag{{ $val.Suffix }}) {{ $val.Name }}Flags{{ $val.Suffix }} {
|
|
return {{ $val.Name }}Flags{{ $val.Suffix }}(astikit.BitFlags(fs).Del(uint64(f)))
|
|
}
|
|
|
|
func (fs {{ $val.Name }}Flags{{ $val.Suffix }}) Has(f {{ $val.Name }}Flag{{ $val.Suffix }}) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
|
{{ end }}`
|
|
|
|
var tmplTest = `// Code generated by astiav. DO NOT EDIT.
|
|
package astiav_test
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/asticode/go-astiav"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
{{ range $val := . }}
|
|
func Test{{ $val.Name }}Flags{{ $val.Suffix }}(t *testing.T) {
|
|
fs := astiav.New{{ $val.Name }}Flags{{ $val.Suffix }}(astiav.{{ $val.Name }}Flag{{ $val.Suffix }}(1))
|
|
require.True(t, fs.Has(astiav.{{ $val.Name }}Flag{{ $val.Suffix }}(1)))
|
|
fs = fs.Add(astiav.{{ $val.Name }}Flag{{ $val.Suffix }}(2))
|
|
require.True(t, fs.Has(astiav.{{ $val.Name }}Flag{{ $val.Suffix }}(2)))
|
|
fs = fs.Del(astiav.{{ $val.Name }}Flag{{ $val.Suffix }}(2))
|
|
require.False(t, fs.Has(astiav.{{ $val.Name }}Flag{{ $val.Suffix }}(2)))
|
|
}
|
|
{{ end }}`
|
|
|
|
func main() {
|
|
dir, err := os.Getwd()
|
|
if err != nil {
|
|
log.Fatal(fmt.Errorf("main: getting working directory failed: %w", err))
|
|
}
|
|
|
|
f, err := os.Create(filepath.Join(dir, "flags.go"))
|
|
if err != nil {
|
|
log.Fatal(fmt.Errorf("main: creating file failed: %w", err))
|
|
}
|
|
defer f.Close()
|
|
|
|
if err = template.Must(template.New("tmpl").Parse(tmpl)).Execute(f, list); err != nil {
|
|
log.Fatal(fmt.Errorf("main: executing template failed: %w", err))
|
|
}
|
|
|
|
ft, err := os.Create(filepath.Join(dir, "flags_test.go"))
|
|
if err != nil {
|
|
log.Fatal(fmt.Errorf("main: creating test file failed: %w", err))
|
|
}
|
|
defer ft.Close()
|
|
|
|
if err = template.Must(template.New("tmpl").Parse(tmplTest)).Execute(ft, list); err != nil {
|
|
log.Fatal(fmt.Errorf("main: executing template failed: %w", err))
|
|
}
|
|
}
|