forked from 3d0c/gmf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sws.go
66 lines (53 loc) · 1.59 KB
/
sws.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package gmf
/*
#cgo pkg-config: libswscale
#include "libswscale/swscale.h"
*/
import "C"
import (
"unsafe"
)
var (
SWS_FAST_BILINEAR int = C.SWS_FAST_BILINEAR
SWS_BILINEAR int = C.SWS_BILINEAR
SWS_BICUBIC int = C.SWS_BICUBIC
SWS_X int = C.SWS_X
SWS_POINT int = C.SWS_POINT
SWS_AREA int = C.SWS_AREA
SWS_BICUBLIN int = C.SWS_BICUBLIN
SWS_GAUSS int = C.SWS_GAUSS
SWS_SINC int = C.SWS_SINC
SWS_LANCZOS int = C.SWS_LANCZOS
SWS_SPLINE int = C.SWS_SPLINE
)
type SwsCtx struct {
swsCtx *C.struct_SwsContext
CgoMemoryManage
}
func NewSwsCtx(src *CodecCtx, dst *CodecCtx, method int) *SwsCtx {
ctx := C.sws_getContext(C.int(src.Width()), C.int(src.Height()), src.PixFmt(), C.int(dst.Width()), C.int(dst.Height()), dst.PixFmt(), C.int(method), nil, nil, nil)
if ctx == nil {
return nil
}
return &SwsCtx{swsCtx: ctx}
}
func NewPicSwsCtx(srcWidth int, srcHeight int, srcPixFmt int32, dst *CodecCtx, method int) *SwsCtx {
ctx := C.sws_getContext(C.int(srcWidth), C.int(srcHeight), srcPixFmt, C.int(dst.Width()), C.int(dst.Height()), dst.PixFmt(), C.int(method), nil, nil, nil)
if ctx == nil {
return nil
}
return &SwsCtx{swsCtx: ctx}
}
func (this *SwsCtx) Free() {
C.sws_freeContext(this.swsCtx)
}
func (this *SwsCtx) Scale(src *Frame, dst *Frame) {
C.sws_scale(
this.swsCtx,
(**C.uint8_t)(unsafe.Pointer(&src.avFrame.data)),
(*_Ctype_int)(unsafe.Pointer(&src.avFrame.linesize)),
0,
C.int(src.Height()),
(**C.uint8_t)(unsafe.Pointer(&dst.avFrame.data)),
(*_Ctype_int)(unsafe.Pointer(&dst.avFrame.linesize)))
}