@@ -17,20 +17,18 @@ import (
1717 "github.com/facebookincubator/go-belt/tool/logger"
1818 "github.com/xaionaro-go/observability"
1919 "github.com/xaionaro-go/streamctl/pkg/screenshot"
20- "github.com/xaionaro-go/streamctl/pkg/screenshoter"
2120 streamdconsts "github.com/xaionaro-go/streamctl/pkg/streamd/consts"
2221 "github.com/xaionaro-go/streamctl/pkg/streampanel/consts"
2322 "github.com/xaionaro-go/xsync"
2423)
2524
2625type Screenshoter interface {
27- Engine () screenshoter.ScreenshotEngine
2826 Loop (
2927 ctx context.Context ,
3028 interval time.Duration ,
3129 config screenshot.Config ,
32- callback func (context.Context , * image.RGBA ),
33- )
30+ callback func (context.Context , image.Image ),
31+ ) error
3432}
3533
3634func (p * Panel ) setImage (
@@ -158,13 +156,27 @@ func imgFitTo(src image.Image, size image.Point) (image.Image, error) {
158156 factor = math .Min (factor , float64 (size .Y )/ float64 (sizeCur .Y ))
159157 newWidth := int (float64 (sizeCur .X ) * factor )
160158 newHeight := int (float64 (sizeCur .Y ) * factor )
161- output := image . NewRGBA ( image.Rectangle {Max : image.Point {
159+ newSize := image.Rectangle {Max : image.Point {
162160 X : newWidth ,
163161 Y : newHeight ,
164- }})
162+ }}
163+ var output image.Image
164+
165+ switch src := src .(type ) {
166+ case * image.RGBA :
167+ output = image .NewRGBA (newSize )
168+ case * image.RGBA64 :
169+ output = image .NewRGBA64 (newSize )
170+ case * image.Gray :
171+ output = image .NewGray (newSize )
172+ case * image.YCbCr :
173+ output = image .NewYCbCr (newSize , src .SubsampleRatio )
174+ default :
175+ return nil , fmt .Errorf ("image format %T is not supported, yet" , src )
176+ }
165177 err := rez .Convert (output , src , rez .NewBicubicFilter ())
166178 if err != nil {
167- return nil , err
179+ return nil , fmt . Errorf ( "unable to convert: %w" , err )
168180 }
169181 return output , nil
170182}
@@ -269,7 +281,7 @@ func (p *Panel) setScreenshot(
269281 screenshot image.Image ,
270282) {
271283 bounds := screenshot .Bounds ()
272- logger .Tracef (ctx , "screenshot bounds: %#+v" , bounds )
284+ logger .Tracef (ctx , "screenshot %T bounds: %#+v" , screenshot , bounds )
273285 if bounds .Max .X == 0 || bounds .Max .Y == 0 {
274286 p .DisplayError (fmt .Errorf ("received an empty screenshot" ))
275287 p .screenshoterLocker .Do (ctx , func () {
@@ -313,12 +325,15 @@ func (p *Panel) reinitScreenshoter(ctx context.Context) {
313325 ctx , cancelFunc := context .WithCancel (ctx )
314326 p .screenshoterClose = cancelFunc
315327 observability .Go (ctx , func (ctx context.Context ) {
316- p .Screenshoter .Loop (
328+ err := p .Screenshoter .Loop (
317329 ctx ,
318330 200 * time .Millisecond ,
319331 p .Config .Screenshot .Config ,
320- func (ctx context.Context , img * image.RGBA ) { p .setScreenshot (ctx , img ) },
332+ func (ctx context.Context , img image.Image ) { p .setScreenshot (ctx , img ) },
321333 )
334+ if err != nil {
335+ logger .Errorf (ctx , "unable to run the screenshoter loop: %v" , err )
336+ }
322337 })
323338 })
324339}
0 commit comments