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 5b0ad8e61f26efc85b437667ebf38fd107e98613
Author: yaojingwei <[email protected]>
AuthorDate: Mon Jul 27 20:34:01 2026 +0800

    nxcamera: add FB_FMT_RGB24 framebuffer output support
    
    Add RGB24 (24-bit) framebuffer format support to nxcamera show_image().
    Uses libyuv ConvertToARGB as intermediate step, then strips alpha channel
    to write 3 bytes per pixel to the framebuffer. Supports center-crop when
    camera resolution exceeds fb resolution.
    
    Signed-off-by: yaojingwei <[email protected]>
---
 include/system/nxcamera.h  |  4 ++++
 system/nxcamera/nxcamera.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/include/system/nxcamera.h b/include/system/nxcamera.h
index 45f2c46c3..4f5fa318a 100644
--- a/include/system/nxcamera.h
+++ b/include/system/nxcamera.h
@@ -73,6 +73,10 @@ struct nxcamera_s
   size_t                nbuffers;                    /* Number of buffers */
   FAR size_t            *buf_sizes;                  /* Buffer lengths */
   FAR uint8_t           **bufs;                      /* Buffer pointers */
+#ifdef CONFIG_LIBYUV
+  FAR uint8_t           *conv_buf;                   /* Preallocated ARGB conv 
buffer */
+  size_t                conv_buf_size;               /* Size of conv buffer in 
bytes */
+#endif
 };
 
 struct video_msg_s
diff --git a/system/nxcamera/nxcamera.c b/system/nxcamera/nxcamera.c
index c47f27d05..96c4879be 100644
--- a/system/nxcamera/nxcamera.c
+++ b/system/nxcamera/nxcamera.c
@@ -64,6 +64,7 @@
 #  define CONVERT_TO_ARGB            ConvertToARGB
 #  define CONVERT_FROM_I420          ConvertFromI420
 #  define CONVERT_TO_I420            ConvertToI420
+#  define CONVERT_ARGB_TO_RGB24      ARGBToRGB24
 #endif
 
 #define NXCAMERA_STATE_IDLE      0
@@ -195,6 +196,56 @@ err:
           return ret;
         }
     }
+  else if (pcam->display_vinfo.fmt == FB_FMT_RGB24)
+    {
+      int ret;
+      uint32_t dst_w = pcam->display_vinfo.xres;
+      uint32_t dst_h = pcam->display_vinfo.yres;
+      uint32_t src_w = pcam->fmt.fmt.pix.width;
+      uint32_t src_h = pcam->fmt.fmt.pix.height;
+      int crop_x = (src_w > dst_w) ? (src_w - dst_w) / 2 : 0;
+      int crop_y = (src_h > dst_h) ? (src_h - dst_h) / 2 : 0;
+      size_t need = dst_w * dst_h * 4;
+
+      /* Lazy-allocate conversion buffer, reused across frames */
+
+      if (pcam->conv_buf_size < need)
+        {
+          free(pcam->conv_buf);
+          pcam->conv_buf = malloc(need);
+          if (pcam->conv_buf == NULL)
+            {
+              pcam->conv_buf_size = 0;
+              return -ENOMEM;
+            }
+
+          pcam->conv_buf_size = need;
+        }
+
+      ret = CONVERT_TO_ARGB(pcam->bufs[buf->index],
+                           sample_size,
+                           pcam->conv_buf,
+                           dst_w * 4,
+                           crop_x,
+                           crop_y,
+                           src_w,
+                           src_h,
+                           dst_w,
+                           dst_h,
+                           0,
+                           pcam->fmt.fmt.pix.pixelformat);
+      if (ret < 0)
+        {
+          return ret;
+        }
+
+      return CONVERT_ARGB_TO_RGB24(pcam->conv_buf,
+                                   dst_w * 4,
+                                   pcam->display_pinfo.fbmem,
+                                   pcam->display_pinfo.stride,
+                                   dst_w,
+                                   dst_h);
+    }
 
   return 0;
 #else
@@ -1063,6 +1114,9 @@ void nxcamera_release(FAR struct nxcamera_s *pcam)
 
   if (refcount == 1)
     {
+#ifdef CONFIG_LIBYUV
+      free(pcam->conv_buf);
+#endif
       pthread_mutex_destroy(&pcam->mutex);
       free(pcam);
     }

Reply via email to