SetFrameBuffer returns error
This commit is contained in:
parent
45952ddbd0
commit
9e805e183b
4 changed files with 41 additions and 10 deletions
15
camera.go
15
camera.go
|
@ -51,10 +51,14 @@ func (camera *Camera) FrameBuffer() []byte {
|
|||
return camera.framebuffer
|
||||
}
|
||||
|
||||
// Sets the framebuffer to the given byte array. Note that "buffer" must be large enough
|
||||
// to store one frame of video data which is width*height*3.
|
||||
func (camera *Camera) SetFrameBuffer(buffer []byte) {
|
||||
func (camera *Camera) SetFrameBuffer(buffer []byte) error {
|
||||
size := camera.width * camera.height * camera.depth
|
||||
if len(buffer) < size {
|
||||
return fmt.Errorf("buffer size %d is smaller than frame size %d", len(buffer), size)
|
||||
}
|
||||
|
||||
camera.framebuffer = buffer
|
||||
return nil
|
||||
}
|
||||
|
||||
// Returns the webcam device name.
|
||||
|
@ -200,7 +204,10 @@ func initCamera(camera *Camera) error {
|
|||
return err
|
||||
}
|
||||
|
||||
camera.framebuffer = make([]byte, camera.width*camera.height*camera.depth)
|
||||
if camera.framebuffer == nil {
|
||||
camera.framebuffer = make([]byte, camera.width*camera.height*camera.depth)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue