func newInnerCBuffer(size int, dontResize ...bool) *innerCBuffer { p := new(innerCBuffer) if size > 0 { p.cptr = C.webpMalloc(C.size_t(size)) p.data = (*[1 << 30]byte)(p.cptr)[0:size:size] } if len(dontResize) > 0 { p.dontResize = dontResize[0] } return p }
func (p *innerCBuffer) Resize(size int) error { if size < 0 { return errors.New("webp: cBuffer.Resize, bad size!") } if p.dontResize { return errors.New("webp: cBuffer.Resize, donot resize!") } if n := len(p.data); n > 0 && n != size { C.webpFree(p.cptr) p.cptr = nil p.data = nil } p.Close() if size > 0 { p.cptr = C.webpMalloc(C.size_t(size)) p.data = (*[1 << 30]byte)(p.cptr)[0:size:size] } return nil }