This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 0550d704e3fd91eb0d31ba425a8a253969d690b5 Author: zengshuang <[email protected]> AuthorDate: Mon Apr 20 19:04:45 2026 +0800 libyuv/nxcamera: enable JPEG decode support for UVC camera 1. libyuv: add HAVE_JPEG compile flag when CONFIG_LIB_JPEG_TURB is enabled, so that MJPGToARGB() is compiled and JPEG frames from UVC cameras can be decoded to ARGB/RGB565 for display. 2. nxcamera: use buf->bytesused as sample_size for libyuv ConvertToARGB and ConvertToI420 instead of the full buffer capacity. For compressed formats (JPEG/MJPEG), bytesused is the actual payload size which is much smaller than the buffer allocation. 3. nxcamera: wrap libyuv mixed-case API names with nxstyle-compliant macros to pass checkpatch. Signed-off-by: zengshuang <[email protected]> --- graphics/libyuv/CMakeLists.txt | 6 ++++++ graphics/libyuv/Makefile | 6 ++++++ system/nxcamera/nxcamera.c | 23 +++++++++++++++++------ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/graphics/libyuv/CMakeLists.txt b/graphics/libyuv/CMakeLists.txt index 1cf0ccd68..e936d813c 100644 --- a/graphics/libyuv/CMakeLists.txt +++ b/graphics/libyuv/CMakeLists.txt @@ -50,6 +50,12 @@ if(CONFIG_LIBYUV) target_sources(libyuv PRIVATE ${SRCS}) target_compile_options(libyuv PRIVATE -Wno-shadow -Wno-undef) + if(CONFIG_LIB_JPEG_TURBO) + target_compile_definitions(libyuv PRIVATE HAVE_JPEG) + target_include_directories( + libyuv PRIVATE ${NUTTX_APPS_DIR}/external/libjpeg-turbo/libjpeg-turbo) + endif() + set_property( TARGET nuttx APPEND diff --git a/graphics/libyuv/Makefile b/graphics/libyuv/Makefile index e4421ee1d..b17f3b0c3 100644 --- a/graphics/libyuv/Makefile +++ b/graphics/libyuv/Makefile @@ -28,6 +28,12 @@ CXXEXT := .cc CXXFLAGS += -Wno-shadow -Wno-undef CXXSRCS = $(wildcard $(SRCDIR)/source/*.cc) +# Enable JPEG support when libjpeg or libjpeg-turbo is available +ifeq ($(CONFIG_LIB_JPEG_TURBO),y) +CXXFLAGS += -DHAVE_JPEG +CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/libjpeg-turbo/libjpeg-turbo +endif + libyuv.tar.gz: $(Q) curl -L https://github.com/NuttX/nuttx/releases/download/libyuv/libyuv-refs_heads_$(CONFIG_LIBYUV_BRANCH).tar.gz -o libyuv.tar.gz $(Q) mkdir -p $(SRCDIR) diff --git a/system/nxcamera/nxcamera.c b/system/nxcamera/nxcamera.c index d2e386995..bfc108a4c 100644 --- a/system/nxcamera/nxcamera.c +++ b/system/nxcamera/nxcamera.c @@ -52,16 +52,20 @@ #ifdef CONFIG_LIBYUV # include <libyuv.h> - -# define CONVERT_TO_ARGB ConvertToARGB -# define CONVERT_FROM_I420 ConvertFromI420 -# define CONVERT_TO_I420 ConvertToI420 #endif /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* Wrap libyuv mixed-case APIs for nxstyle compliance */ + +#ifdef CONFIG_LIBYUV +# define CONVERT_TO_ARGB ConvertToARGB +# define CONVERT_FROM_I420 ConvertFromI420 +# define CONVERT_TO_I420 ConvertToI420 +#endif + #define NXCAMERA_STATE_IDLE 0 #define NXCAMERA_STATE_STREAMING 1 #define NXCAMERA_STATE_LOOPING 2 @@ -93,10 +97,17 @@ static void pan_display(int fb_device, FAR struct fb_planeinfo_s *plane_info) static int show_image(FAR struct nxcamera_s *pcam, FAR v4l2_buffer_t *buf) { #ifdef CONFIG_LIBYUV + /* Use bytesused for the actual payload size. For compressed formats + * such as JPEG, bytesused is much smaller than the buffer capacity. + */ + + uint32_t sample_size = buf->bytesused > 0 ? + buf->bytesused : pcam->buf_sizes[buf->index]; + if (pcam->display_vinfo.fmt == FB_FMT_RGB32) { return CONVERT_TO_ARGB(pcam->bufs[buf->index], - pcam->buf_sizes[buf->index], + sample_size, pcam->display_pinfo.fbmem, pcam->display_pinfo.stride, 0, @@ -139,7 +150,7 @@ static int show_image(FAR struct nxcamera_s *pcam, FAR v4l2_buffer_t *buf) } ret = CONVERT_TO_I420(pcam->bufs[buf->index], - pcam->buf_sizes[buf->index], + sample_size, dst, pcam->fmt.fmt.pix.width, &dst[pcam->fmt.fmt.pix.width *
