From dc65b072a13994ff02cc7b54f3b00ba087e7f86a Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期三, 20 十一月 2019 14:05:52 +0800 Subject: [PATCH] add zerocopy --- godecjpeg.go | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) diff --git a/godecjpeg.go b/godecjpeg.go index 6cef6af..ac1151f 100644 --- a/godecjpeg.go +++ b/godecjpeg.go @@ -34,3 +34,30 @@ } return nil, int(width), int(height) } + +// Decode2 decode jpeg file +// return val: -1 open error; -2, find stream error; -3, converter create error +func Decode2(input string, gb bool) (unsafe.Pointer, []byte, int, int) { + in := C.CString(input) + defer C.free(unsafe.Pointer(in)) + + withGB := 0 + if gb { + withGB = 1 + } + + var width C.int + var height C.int + p := C.wrap_fn_decode(unsafe.Pointer(libcffmpeg), in, C.int(withGB), &width, &height) + + if width > 0 && height > 0 { + wid := int(width) + hei := int(height) + const maxLen = 0x7fffffff + size := int(width * height * 3) + data := (*[maxLen]byte)(unsafe.Pointer(p))[:size:size] + + return p, data, wid, hei + } + return nil, nil, 0, 0 +} -- Gitblit v1.8.0