diff --git a/components/vision/include/maix_jpg_stream.hpp b/components/vision/include/maix_jpg_stream.hpp index 5dea2320..58ffcd77 100644 --- a/components/vision/include/maix_jpg_stream.hpp +++ b/components/vision/include/maix_jpg_stream.hpp @@ -52,7 +52,7 @@ namespace maix::http /** * @brief Write data to http - * @param img Must be jpeg image + * @param img image object * @return error code, err::ERR_NONE means success, others means failed * @maixpy maix.http.JpegStreamer.write */ diff --git a/components/vision/port/maixcam/maix_jpg_stream.cpp b/components/vision/port/maixcam/maix_jpg_stream.cpp index e25edd89..14721e6e 100644 --- a/components/vision/port/maixcam/maix_jpg_stream.cpp +++ b/components/vision/port/maixcam/maix_jpg_stream.cpp @@ -580,17 +580,26 @@ namespace maix::http err::Err JpegStreamer::write(image::Image *img) { int res = 0; + image::Image *jpg = NULL; if (img->format() != image::Format::FMT_JPEG) { - log::error("Only support jpeg format!\r\n"); - return err::ERR_RUNTIME; + jpg = img->to_jpeg(); + if (jpg == NULL) { + log::error("invert to jpeg failed!\r\n"); + return err::ERR_RUNTIME; + } + } else { + jpg = img; } - if (0 != (res = http_jpeg_server_send(img->data(), img->data_size()))) { + if (0 != (res = http_jpeg_server_send(jpg->data(), jpg->data_size()))) { log::error("http_jpeg_server_send failed! res:%d\r\n", res); return err::ERR_RUNTIME; } + if (img->format() != image::Format::FMT_JPEG) { + delete jpg; + } return err::ERR_NONE; }