From 29c1e15678fd48236aebdc1ec1f481e56278d306 Mon Sep 17 00:00:00 2001 From: Katharina Kufieta Date: Mon, 3 Oct 2022 19:47:07 +0100 Subject: [PATCH] Process images when they're of YCbCr type --- services/slam/builtin/builtin.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/services/slam/builtin/builtin.go b/services/slam/builtin/builtin.go index 276927e29cbf..c39063fa5452 100644 --- a/services/slam/builtin/builtin.go +++ b/services/slam/builtin/builtin.go @@ -736,13 +736,22 @@ func (slamSvc *builtIn) getLazyPNGImage(ctx context.Context, cam camera.Camera) } lazyImg, ok := img.(*rimage.LazyEncodedImage) - if !ok { - return nil, errors.Errorf("expected lazily encoded image, got %T", lazyImg) + if ok { + if lazyImg.MIMEType() != utils.MimeTypePNG { + return nil, errors.Errorf("expected mime type %v, got %T", utils.MimeTypePNG, img) + } + return lazyImg.RawData(), nil } - if lazyImg.MIMEType() != utils.MimeTypePNG { - return nil, errors.Errorf("expected mime type %v, got %v", utils.MimeTypePNG, lazyImg.MIMEType()) + ycbcrImg, ok := img.(*image.YCbCr) + if ok { + pngImage, err := rimage.EncodeImage(ctx, ycbcrImg, utils.MimeTypePNG) + if err != nil { + return nil, err + } + return pngImage, nil } - return lazyImg.RawData(), nil + + return nil, errors.Errorf("expected lazily encoded image or ycbcrImg, got %T", img) } // getAndSaveDataSparse implements the data extraction for sparse algos and saving to the directory path (data subfolder) specified in