Files
overlord/Overlord-Client/cmd/agent/capture/rgbapool.go
T

33 lines
551 B
Go
Raw Normal View History

2026-04-08 14:14:09 -05:00
package capture
import (
"image"
"sync"
)
var rgbaPool sync.Pool
func GetRGBA(w, h int) *image.RGBA {
need := w * h * 4
if need <= 0 {
return image.NewRGBA(image.Rect(0, 0, w, h))
}
if v := rgbaPool.Get(); v != nil {
2026-05-21 23:28:06 -05:00
if buf, ok := v.([]byte); ok && cap(buf) >= need {
2026-04-08 14:14:09 -05:00
return &image.RGBA{
Pix: buf[:need],
Stride: w * 4,
Rect: image.Rect(0, 0, w, h),
}
}
}
return image.NewRGBA(image.Rect(0, 0, w, h))
}
func PutRGBA(img *image.RGBA) {
if img == nil || len(img.Pix) == 0 {
return
}
rgbaPool.Put(img.Pix)
}