r4947 - developers/werner/gta03/cam/capture
werner at docs.openmoko.org
werner at docs.openmoko.org
Wed Mar 4 10:12:59 CET 2009
Author: werner
Date: 2009-03-04 10:12:58 +0100 (Wed, 04 Mar 2009)
New Revision: 4947
Modified:
developers/werner/gta03/cam/capture/capture.c
Log:
Added framebuffer mode to have a viewfinder. The image is recognizable
but the color mapping is all wrong and there's a stretching along the
long axis by a factor of 2.
Modified: developers/werner/gta03/cam/capture/capture.c
===================================================================
--- developers/werner/gta03/cam/capture/capture.c 2009-03-03 14:37:21 UTC (rev 4946)
+++ developers/werner/gta03/cam/capture/capture.c 2009-03-04 09:12:58 UTC (rev 4947)
@@ -1,9 +1,8 @@
/*
- * V4L2 video capture example
- *
* This program can be used and distributed without restrictions.
*/
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -44,6 +43,9 @@
struct buffer * buffers = NULL;
static unsigned int n_buffers = 0;
+static void *fb;
+
+
static void
errno_exit (const char * s)
{
@@ -69,8 +71,24 @@
static void
process_image (const void * p, size_t size)
{
-write(1, p, size);
- // fflush (stdout);
+ if (fb) {
+#if 0
+ for (i = 0; i != size; i += 2) {
+ ((uint8_t *) fb)[i] = ((uint8_t *) p)[i+1];
+ ((uint8_t *) fb)[i+1] = ((uint8_t *) p)[i];
+ }
+#endif
+#if 0
+ uint32_t *w;
+
+ for (w = p; w != p+size; w++)
+ *w = ~*w;
+#endif
+ memcpy(fb, p, size);
+ } else {
+ write(1, p, size);
+ exit(0);
+ }
}
static int
@@ -162,8 +180,6 @@
if (-1 == xioctl (fd, VIDIOC_QBUF, &buf))
errno_exit ("VIDIOC_QBUF");
-
- break;
}
return 1;
@@ -175,14 +191,10 @@
unsigned int count;
//count = 100;
- count = 1;
+ count = 10000;
while (count-- > 0) {
-fprintf(stderr, "mainloop: outer\n");
-usleep(100000);
for (;;) {
-fprintf(stderr, "mainloop: inner\n");
-usleep(100000);
fd_set fds;
struct timeval tv;
int r;
@@ -517,10 +529,16 @@
CLEAR (fmt);
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- fmt.fmt.pix.width = 640;
- fmt.fmt.pix.height = 480;
- fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
- fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24;
+ if (fb) {
+ fmt.fmt.pix.width = 480;
+ fmt.fmt.pix.height = 640;
+ fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB565;
+ } else {
+ fmt.fmt.pix.width = 640;
+ fmt.fmt.pix.height = 480;
+ fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24;
+ }
+// fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
fmt.fmt.pix.field = 0;
@@ -603,7 +621,7 @@
argv[0]);
}
-static const char short_options [] = "d:hmru";
+static const char short_options [] = "d:f:hmru";
static const struct option
long_options [] = {
@@ -612,6 +630,7 @@
{ "mmap", no_argument, NULL, 'm' },
{ "read", no_argument, NULL, 'r' },
{ "userp", no_argument, NULL, 'u' },
+ { "fb", required_argument, NULL, 'f' },
{ 0, 0, 0, 0 }
};
@@ -640,6 +659,16 @@
dev_name = optarg;
break;
+ case 'f':
+ fd = open("/dev/mem", O_RDWR);
+ if (fd < 0) {
+ perror("/dev/mem");
+ exit(1);
+ }
+ fb = mmap(NULL, 0xa0000, PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, strtoul(optarg, NULL, 0));
+ break;
+
case 'h':
usage (stdout, argc, argv);
exit (EXIT_SUCCESS);
More information about the commitlog
mailing list