Documentation
¶
Overview ¶
Package buffer wraps MaaFramework image, string, rect, and list buffers.
Constructors create owned buffers that must be destroyed exactly once and not used afterwards. ByHandle constructors borrow existing handles; borrowed wrappers share the same buffer and must not call Destroy.
Index ¶
- type ImageBuffer
- func (i *ImageBuffer) Clear() bool
- func (i *ImageBuffer) Destroy()
- func (i *ImageBuffer) Get() image.Image
- func (i *ImageBuffer) GetInto(dst *image.RGBA) *image.RGBA
- func (i *ImageBuffer) Handle() uintptr
- func (i *ImageBuffer) IsEmpty() bool
- func (i *ImageBuffer) Resize(width, height int32) bool
- func (i *ImageBuffer) Set(img image.Image) error
- type ImageListBuffer
- func (il *ImageListBuffer) Append(value *ImageBuffer) bool
- func (il *ImageListBuffer) Clear() bool
- func (il *ImageListBuffer) Destroy()
- func (il *ImageListBuffer) Get(index uint64) image.Image
- func (il *ImageListBuffer) GetAll() []image.Image
- func (il *ImageListBuffer) Handle() uintptr
- func (il *ImageListBuffer) IsEmpty() bool
- func (il *ImageListBuffer) Remove(index uint64) bool
- func (il *ImageListBuffer) Size() uint64
- type RectBuffer
- type StringBuffer
- func (s *StringBuffer) Clear() bool
- func (s *StringBuffer) Destroy()
- func (s *StringBuffer) Get() string
- func (s *StringBuffer) GetWithSize() string
- func (s *StringBuffer) Handle() uintptr
- func (s *StringBuffer) IsEmpty() bool
- func (s *StringBuffer) Set(str string) bool
- func (s *StringBuffer) SetWithSize(str string, size uint64) bool
- func (s *StringBuffer) Size() uint64
- type StringListBuffer
- func (sl *StringListBuffer) Append(value *StringBuffer) bool
- func (sl *StringListBuffer) Clear() bool
- func (sl *StringListBuffer) Destroy()
- func (sl *StringListBuffer) Get(index uint64) string
- func (sl *StringListBuffer) GetAll() []string
- func (sl *StringListBuffer) Handle() uintptr
- func (sl *StringListBuffer) IsEmpty() bool
- func (sl *StringListBuffer) Remove(index uint64) bool
- func (sl *StringListBuffer) Size() uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ImageBuffer ¶
type ImageBuffer struct {
// contains filtered or unexported fields
}
ImageBuffer wraps a native image buffer holding raw BGR pixels. Create one with NewImageBuffer, or borrow an existing handle with NewImageBufferByHandle.
func NewImageBuffer ¶
func NewImageBuffer() (*ImageBuffer, error)
NewImageBuffer creates a new image buffer. It returns an error when the underlying native buffer cannot be created.
func NewImageBufferByHandle ¶
func NewImageBufferByHandle(handle uintptr) *ImageBuffer
NewImageBufferByHandle wraps a borrowed native image buffer handle.
func (*ImageBuffer) Clear ¶
func (i *ImageBuffer) Clear() bool
Clear releases the stored image and reports whether the native call succeeded.
func (*ImageBuffer) Destroy ¶
func (i *ImageBuffer) Destroy()
Destroy releases the underlying native image buffer.
func (*ImageBuffer) Get ¶
func (i *ImageBuffer) Get() image.Image
Get retrieves the image from raw data stored in the buffer, interpreted as the CV_8UC3 BGR layout Set produces. It returns a fresh opaque *image.RGBA copy each call (alpha fixed to 255) and never shares memory with the buffer; it returns a nil interface when the buffer has no raw image data.
func (*ImageBuffer) GetInto ¶
func (i *ImageBuffer) GetInto(dst *image.RGBA) *image.RGBA
GetInto retrieves the image from raw data stored in the buffer and writes into dst when possible, interpreted as the CV_8UC3 BGR layout Set produces. The pixels are copied into dst, which is reallocated when dst is nil or sized for a different image; it returns nil and leaves dst unchanged when the buffer has no raw image data.
func (*ImageBuffer) Handle ¶
func (i *ImageBuffer) Handle() uintptr
Handle returns the underlying native buffer handle for passing to framework functions that take an image buffer.
func (*ImageBuffer) IsEmpty ¶
func (i *ImageBuffer) IsEmpty() bool
IsEmpty reports whether the buffer holds no image.
func (*ImageBuffer) Resize ¶
func (i *ImageBuffer) Resize(width, height int32) bool
Resize resizes the image buffer to the specified width and height. It returns true if the operation was successful, otherwise false. An empty buffer and a zero width together with a zero height fail; a single zero dimension is computed proportionally from the other one.
func (*ImageBuffer) Set ¶
func (i *ImageBuffer) Set(img image.Image) error
Set converts an image.Image to raw data and sets it in the buffer. Alpha is dropped: non-opaque RGBA pixels are exactly unpremultiplied before the BGR conversion, and the stored data has no alpha channel. The buffer is left unchanged and an error is returned when img is nil, has a non-positive dimension, or the underlying write fails.
type ImageListBuffer ¶
type ImageListBuffer struct {
// contains filtered or unexported fields
}
ImageListBuffer wraps a native list of image buffers. Create one with NewImageListBuffer, or borrow an existing handle with NewImageListBufferByHandle.
func NewImageListBuffer ¶
func NewImageListBuffer() *ImageListBuffer
NewImageListBuffer creates a new empty image list buffer. It returns nil when the underlying native buffer cannot be created.
func NewImageListBufferByHandle ¶
func NewImageListBufferByHandle(handle uintptr) *ImageListBuffer
NewImageListBufferByHandle wraps a borrowed native image list buffer handle.
func (*ImageListBuffer) Append ¶
func (il *ImageListBuffer) Append(value *ImageBuffer) bool
Append stores value in the list and reports whether the native call succeeded; the stored element stays valid after the caller destroys value. It returns false when value is nil.
func (*ImageListBuffer) Clear ¶
func (il *ImageListBuffer) Clear() bool
Clear removes all images and reports whether the native call succeeded.
func (*ImageListBuffer) Destroy ¶
func (il *ImageListBuffer) Destroy()
Destroy releases the underlying native image list buffer.
func (*ImageListBuffer) Get ¶
func (il *ImageListBuffer) Get(index uint64) image.Image
Get returns a copy of the image at index. It returns a nil interface when index is out of range or the element holds no image.
func (*ImageListBuffer) GetAll ¶
func (il *ImageListBuffer) GetAll() []image.Image
GetAll returns copies of all images in list order. It returns a non-nil empty slice when the list is empty.
func (*ImageListBuffer) Handle ¶
func (il *ImageListBuffer) Handle() uintptr
Handle returns the underlying native list buffer handle for passing to framework functions that take an image list buffer.
func (*ImageListBuffer) IsEmpty ¶
func (il *ImageListBuffer) IsEmpty() bool
IsEmpty reports whether the list holds no images.
func (*ImageListBuffer) Remove ¶
func (il *ImageListBuffer) Remove(index uint64) bool
Remove deletes the image at index and reports whether index was in range.
func (*ImageListBuffer) Size ¶
func (il *ImageListBuffer) Size() uint64
Size returns the number of images in the list.
type RectBuffer ¶
type RectBuffer struct {
// contains filtered or unexported fields
}
RectBuffer wraps a native rect buffer holding x, y, width, and height as int32 values. Create one with NewRectBuffer, or borrow an existing handle with NewRectBufferByHandle.
func NewRectBuffer ¶
func NewRectBuffer() (*RectBuffer, error)
NewRectBuffer creates a new rect buffer. It returns an error when the underlying native buffer cannot be created.
func NewRectBufferByHandle ¶
func NewRectBufferByHandle(handle uintptr) *RectBuffer
NewRectBufferByHandle wraps a borrowed native rect buffer handle.
func (*RectBuffer) Destroy ¶
func (r *RectBuffer) Destroy()
Destroy releases the underlying native rect buffer.
func (*RectBuffer) Get ¶
func (r *RectBuffer) Get() rect.Rect
Get returns the rect currently stored in the buffer.
func (*RectBuffer) GetH ¶
func (r *RectBuffer) GetH() int32
GetH returns the height component of the stored rect.
func (*RectBuffer) GetW ¶
func (r *RectBuffer) GetW() int32
GetW returns the width component of the stored rect.
func (*RectBuffer) GetX ¶
func (r *RectBuffer) GetX() int32
GetX returns the x component of the stored rect.
func (*RectBuffer) GetY ¶
func (r *RectBuffer) GetY() int32
GetY returns the y component of the stored rect.
func (*RectBuffer) Handle ¶
func (r *RectBuffer) Handle() uintptr
Handle returns the underlying native rect buffer handle for passing to framework functions that take a rect buffer.
type StringBuffer ¶
type StringBuffer struct {
// contains filtered or unexported fields
}
StringBuffer wraps a native string buffer holding a byte string. Create one with NewStringBuffer, or borrow an existing handle with NewStringBufferByHandle.
func NewStringBuffer ¶
func NewStringBuffer() *StringBuffer
NewStringBuffer creates a new empty string buffer. It returns nil when the underlying native buffer cannot be created.
func NewStringBufferByHandle ¶
func NewStringBufferByHandle(handle uintptr) *StringBuffer
NewStringBufferByHandle wraps a borrowed native string buffer handle.
func (*StringBuffer) Clear ¶
func (s *StringBuffer) Clear() bool
Clear discards the content and reports whether the native call succeeded.
func (*StringBuffer) Destroy ¶
func (s *StringBuffer) Destroy()
Destroy releases the underlying native string buffer.
func (*StringBuffer) Get ¶
func (s *StringBuffer) Get() string
Get returns the buffer content as a Go string, truncating at the first NUL. Embedded NUL bytes stay in the buffer; read them back with GetWithSize.
func (*StringBuffer) GetWithSize ¶
func (s *StringBuffer) GetWithSize() string
GetWithSize copies the entire buffer content into a Go string, preserving embedded NULs. The returned string remains valid after the buffer is modified or destroyed.
func (*StringBuffer) Handle ¶
func (s *StringBuffer) Handle() uintptr
Handle returns the underlying native string buffer handle for passing to framework functions that take a string buffer.
func (*StringBuffer) IsEmpty ¶
func (s *StringBuffer) IsEmpty() bool
IsEmpty reports whether the buffer holds no content.
func (*StringBuffer) Set ¶
func (s *StringBuffer) Set(str string) bool
Set stores str through a NUL-terminated C string, so content is truncated at the first NUL. It reports whether the native call succeeded.
func (*StringBuffer) SetWithSize ¶
func (s *StringBuffer) SetWithSize(str string, size uint64) bool
SetWithSize stores exactly size bytes of str, preserving embedded NULs. It returns false when size exceeds len(str), which would make the native side read past the string, and otherwise reports whether the native call succeeded.
func (*StringBuffer) Size ¶
func (s *StringBuffer) Size() uint64
Size returns the content length in bytes, including any embedded NULs.
type StringListBuffer ¶
type StringListBuffer struct {
// contains filtered or unexported fields
}
StringListBuffer wraps a native list of string buffers. Create one with NewStringListBuffer, or borrow an existing handle with NewStringListBufferByHandle.
func NewStringListBuffer ¶
func NewStringListBuffer() *StringListBuffer
NewStringListBuffer creates a new empty string list buffer. It returns nil when the underlying native buffer cannot be created.
func NewStringListBufferByHandle ¶
func NewStringListBufferByHandle(handle uintptr) *StringListBuffer
NewStringListBufferByHandle wraps a borrowed native string list buffer handle.
func (*StringListBuffer) Append ¶
func (sl *StringListBuffer) Append(value *StringBuffer) bool
Append stores a deep copy of value and reports whether the native call succeeded; the caller keeps owning value. It returns false when value is nil.
func (*StringListBuffer) Clear ¶
func (sl *StringListBuffer) Clear() bool
Clear removes all strings and reports whether the native call succeeded.
func (*StringListBuffer) Destroy ¶
func (sl *StringListBuffer) Destroy()
Destroy releases the underlying native string list buffer.
func (*StringListBuffer) Get ¶
func (sl *StringListBuffer) Get(index uint64) string
Get returns the string at index. It returns an empty string when index is out of range, indistinguishable from an empty element.
func (*StringListBuffer) GetAll ¶
func (sl *StringListBuffer) GetAll() []string
GetAll returns all strings in list order. It returns a non-nil empty slice when the list is empty.
func (*StringListBuffer) Handle ¶
func (sl *StringListBuffer) Handle() uintptr
Handle returns the underlying native list buffer handle for passing to framework functions that take a string list buffer.
func (*StringListBuffer) IsEmpty ¶
func (sl *StringListBuffer) IsEmpty() bool
IsEmpty reports whether the list holds no strings.
func (*StringListBuffer) Remove ¶
func (sl *StringListBuffer) Remove(index uint64) bool
Remove deletes the string at index and reports whether index was in range.
func (*StringListBuffer) Size ¶
func (sl *StringListBuffer) Size() uint64
Size returns the number of strings in the list.