[Armadeus-commitlog] armadeus branch, master, updated. armadeus-6.0-314-ga21d1e5
Brought to you by:
sszy
|
From: Julien B a. A. <ar...@us...> - 2017-08-07 17:12:52
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, master has been updated
via a21d1e5f65d1aac96660b379ae735c8ee80a2620 (commit)
from 19f5f27466f95f48b676143174905d65e6194f22 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit a21d1e5f65d1aac96660b379ae735c8ee80a2620
Author: Julien BOIBESSOT <jul...@ar...>
Date: Mon Aug 7 19:11:57 2017 +0200
[DEMOS] capture: add support for 32 bits framebuffer (HDMI on APF6) and now display framerate
-----------------------------------------------------------------------
Summary of changes:
target/demos/camera/capture/capture.c | 172 ++++++++++++++++++++++++++++++++--
1 file changed, 163 insertions(+), 9 deletions(-)
diff --git a/target/demos/camera/capture/capture.c b/target/demos/camera/capture/capture.c
index a0175ff..988de51 100644
--- a/target/demos/camera/capture/capture.c
+++ b/target/demos/camera/capture/capture.c
@@ -167,7 +167,8 @@ static void yuv422_to_greyscale(void *yuv, int size, void *grey)
}
}
#endif
-static void yuv422_to_rgb565(void *yuv, int size, void *rgb)
+
+static void yuyv_to_rgb565(void *yuv, int size, void *rgb)
{
unsigned int Y, Y2, U, V, yuv32, rgb32;
int R, G, B;
@@ -201,6 +202,97 @@ static void yuv422_to_rgb565(void *yuv, int size, void *rgb)
}
}
+static void yuyv_to_rgb32(void *yuv, int size, void *rgb)
+{
+ unsigned int Y, Y2, U, V, yuv32, rgb32;
+ int R, G, B;
+ int i;
+ Uint32 *dest = (Uint32*) rgb;
+ Uint32 *src = (Uint32*) yuv;
+
+ for (i=size/4; i; i--)
+ {
+ yuv32 = *(src++);
+
+ /* packed format */
+ Y = (yuv32 & 0x000000ff);
+ U = (yuv32 & 0x0000ff00) >> 8;
+ Y2 = (yuv32 & 0x00ff0000) >> 16;
+ V = (yuv32 & 0xff000000) >> 24;
+
+ R = YUV2R(Y, U, V);
+ G = YUV2G(Y, U, V);
+ B = YUV2B(Y, U, V);
+ rgb32 = ((R << 16) | (G << 8) | B);
+ *(dest++) = rgb32;
+
+ R = YUV2R(Y2, U, V);
+ G = YUV2G(Y2, U, V);
+ B = YUV2B(Y2, U, V);
+ rgb32 = ((R << 16) | (G << 8) | B);
+ *(dest++) = rgb32;
+ }
+}
+
+static void yuyv_to_rgb(void *yuv, int size, void *rgb, int bpp)
+{
+ if (bpp == 32) {
+ yuyv_to_rgb32(yuv, size, rgb);
+ } else if (bpp = 16) {
+ yuyv_to_rgb565(yuv, size, rgb);
+ } else {
+ fprintf(stdout, "yuyv_to_rgb: unsupported screen bpp\n");
+ }
+}
+
+static void uyvy_to_rgb32(void *yuv, int size, void *rgb)
+{
+ unsigned int Y, Y2, U, V, yuv32, rgb32;
+ int R, G, B;
+ int i;
+ Uint32 *dest = (Uint32*) rgb;
+ Uint32 *src = (Uint32*) yuv;
+
+ for (i=size/4; i; i--)
+ {
+ yuv32 = *(src++);
+
+ /* packed format */
+ U = (yuv32 & 0x000000ff);
+ Y = (yuv32 & 0x0000ff00) >> 8;
+ V = (yuv32 & 0x00ff0000) >> 16;
+ Y2 = (yuv32 & 0xff000000) >> 24;
+
+ R = YUV2R(Y, U, V);
+ G = YUV2G(Y, U, V);
+ B = YUV2B(Y, U, V);
+ //rgb32 = ((R>>3) << 11) | ((G>>2) << 5) | (B>>3);
+ rgb32 = ((R << 16) | (G << 8) | B);
+ *(dest++) = rgb32;
+// rgb32 = yuv2rgb(Y, U, V);
+
+ R = YUV2R(Y2, U, V);
+ G = YUV2G(Y2, U, V);
+ B = YUV2B(Y2, U, V);
+ //rgb32 |= (((R>>3) << 11) | ((G>>2) << 5) | (B>>3)) << 16;
+ rgb32 = ((R << 16) | (G << 8) | B);
+// rgb32 |= yuv2rgb(Y2, U, V) << 16;
+
+ *(dest++) = rgb32;
+ }
+}
+
+static void uyvy_to_rgb(void *yuv, int size, void *rgb, int bpp)
+{
+ if (bpp == 32) {
+ uyvy_to_rgb32(yuv, size, rgb);
+ } else if (bpp = 16) {
+ yuyv_to_rgb565(yuv, size, rgb);
+ } else {
+ fprintf(stdout, "uyvy_to_rgb: unsupported screen bpp\n");
+ }
+}
+
/* Only grayscale conversion for the moment
As yuv420 is slightly complicated to decode it would be worth using libv4l
*/
@@ -221,6 +313,38 @@ static void yuv420_to_rgb565(void *yuv, int size, void *rgb)
}
}
+static void yuv420_to_rgb32(void *yuv, int size, void *rgb)
+{
+ Uint8 yuv8;
+ Uint32 yuv32;
+ Uint8 R, G, B;
+ int i, j;
+ int nbpix = mycamera.width * mycamera.height;
+ Uint16 *dest16 = (Uint16*) rgb;
+ Uint32 *dest32 = (Uint32*) rgb;
+ Uint32 *src = (Uint32*) yuv;
+
+ nbpix = mycamera.width * mycamera.height;
+ for (i=nbpix/4; i; i--) {
+ yuv32 = *(src++);
+ for (j=0; j<4; j++) {
+ R = G = B = (&yuv32)[j];
+ *(dest32++) = (R << 16) | (G << 8) | (B);
+ }
+ }
+}
+
+static void yuv420_to_rgb(void *yuv, int size, void *rgb, int bpp)
+{
+ if (bpp == 32) {
+ yuv420_to_rgb32(yuv, size, rgb);
+ } else if (bpp = 16) {
+ yuv420_to_rgb565(yuv, size, rgb);
+ } else {
+ fprintf(stdout, "yuv420_to_rgb: unsupported screen bpp\n");
+ }
+}
+
#if 0
static void rgb565_to_yuv420(void *rgb, int size, void *yuv)
{
@@ -292,13 +416,18 @@ static void simple_copy(void *yuv, int size, void* rgb)
static void process_image(/*const */void *pCaptured, int size)
{
SDL_Rect update_rec;
+ int sec, usec, run_time;
+ static struct timeval now, last;
+ static int fps;
if (mycamera.pixelformat == V4L2_PIX_FMT_YUYV) {
- yuv422_to_rgb565(pCaptured, mycamera.sizeimage, image->pixels);
+ yuyv_to_rgb(pCaptured, mycamera.sizeimage, image->pixels, screen->format->BitsPerPixel);
+ } else if (mycamera.pixelformat == V4L2_PIX_FMT_UYVY) {
+ uyvy_to_rgb(pCaptured, mycamera.sizeimage, image->pixels, screen->format->BitsPerPixel);
} else if (mycamera.pixelformat == V4L2_PIX_FMT_YUV420) {
- yuv420_to_rgb565(pCaptured, mycamera.sizeimage, image->pixels);
+ yuv420_to_rgb(pCaptured, mycamera.sizeimage, image->pixels, screen->format->BitsPerPixel);
} else {
- if (mycamera.pixelformat != V4L2_PIX_FMT_RGB565) {
+ if ((mycamera.pixelformat != V4L2_PIX_FMT_RGB565) || (mycamera.pixelformat != V4L2_PIX_FMT_RGB32)) {
printf("Unknown image format\n");
}
if (size == 0)
@@ -313,6 +442,26 @@ static void process_image(/*const */void *pCaptured, int size)
update_rec.h = mycamera.height;
SDL_BlitSurface(image, NULL, screen, &update_rec);
SDL_Flip(screen);
+
+ /* Calculate FPS */
+ gettimeofday(&now, NULL);
+ if (now.tv_sec == last.tv_sec) {
+ fps++;
+ } else {
+ printf("FPS = %d\r", fps);
+ fflush(stdout);
+ fps = 0;
+ }
+ sec = now.tv_sec - last.tv_sec;
+ usec = now.tv_usec - last.tv_usec;
+ if (usec < 0) {
+ sec--;
+ usec = usec + 1000000;
+ }
+ run_time = (sec * 1000000) + usec;
+// printf("Run time %d ms (%d, %d) (%d, %d)\n", run_time, now.tv_sec, now.tv_usec, last.tv_sec, last.tv_usec);
+ last.tv_sec = now.tv_sec;
+ last.tv_usec = now.tv_usec;
}
static int read_frame(void)
@@ -712,7 +861,7 @@ static Uint32 get_a_supported_pix_fmt(void)
struct v4l2_fmtdesc fmtdesc;
int i;
- /* First check if a LCD native format is available (-> no CSC) */
+ /* First check if a LCD native format is available (-> no need for CSC) */
for (i = 0;; i++) {
CLEAR(fmtdesc);
fmtdesc.index = i;
@@ -720,9 +869,13 @@ static Uint32 get_a_supported_pix_fmt(void)
if (-1 == ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc))
break;
- if (fmtdesc.pixelformat == V4L2_PIX_FMT_RGB565) {
+ /*fprintf(stdout, "Trying format N°%d %c%c%c%c (%s)\n",
+ fmtdesc.index, fmtdesc.pixelformat & 0xff,
+ fmtdesc.pixelformat >> 8 & 0xff, fmtdesc.pixelformat >> 16 & 0xff,
+ fmtdesc.pixelformat >> 24 & 0xff, fmtdesc.description);*/
+ if ((fmtdesc.pixelformat == V4L2_PIX_FMT_RGB565) || (fmtdesc.pixelformat == V4L2_PIX_FMT_RGB32)) {
fprintf(stdout, "Using img format (%d 0x%08x): ", i, fmtdesc.pixelformat);
- fprintf(stdout, "RGB565\n");
+ fprintf(stdout, "RGB565/RGB32\n");
return fmtdesc.pixelformat;
}
}
@@ -736,6 +889,7 @@ static Uint32 get_a_supported_pix_fmt(void)
break;
if ((fmtdesc.pixelformat == V4L2_PIX_FMT_YUYV)
+ || (fmtdesc.pixelformat == V4L2_PIX_FMT_UYVY)
|| (fmtdesc.pixelformat == V4L2_PIX_FMT_YUV420)
|| (fmtdesc.pixelformat == V4L2_PIX_FMT_JPEG)) {
fprintf(stdout, "Using img format (%d 0x%08x): ", i, fmtdesc.pixelformat);
@@ -1044,7 +1198,7 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
fprintf(stderr, "SDL OK\n");
- screen = SDL_SetVideoMode(width, height, 16, SDL_ANYFORMAT /*| SDL_DOUBLEBUF | SDL_HWSURFACE*/);
+ screen = SDL_SetVideoMode(width, height, 0, SDL_ANYFORMAT /*| SDL_DOUBLEBUF | SDL_HWSURFACE*/);
if (screen) {
printf("Video mode: %dx%dx%d\n", screen->w, screen->h,
screen->format->BitsPerPixel);
@@ -1061,7 +1215,7 @@ int main(int argc, char **argv)
open_capture_device();
init_capture_device(camwidth, camheight);
- image = SDL_CreateRGBSurface(/*SDL_HWSURFACE*/0, mycamera.width, mycamera.height, 16, 0, 0, 0, 0);
+ image = SDL_CreateRGBSurface(/*SDL_HWSURFACE*/0, mycamera.width, mycamera.height, screen->format->BitsPerPixel, 0, 0, 0, 0);
// printf("image fmt: RGB%d%d%d\n", image->format->Rshift, image->format->Gshift, image->format->Bshift);
start_capturing();
mainloop();
hooks/post-receive
--
armadeus
|