aboutsummaryrefslogtreecommitdiffstats
path: root/console
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2010-04-01 09:24:39 (GMT)
committerGerd Hoffmann <kraxel@redhat.com>2010-04-01 09:24:39 (GMT)
commit9ee950dde5943ee4083c2a0176ad4a1da4b49220 (patch)
tree2c5de44cea4582a75ba172617eb7526985346de2 /console
parentbc7f101b0c874e21473aca15d9b08de8bd164392 (diff)
v3.76
Diffstat (limited to 'console')
-rw-r--r--console/Subdir.mk16
-rw-r--r--console/fbtools.c42
-rw-r--r--console/fbtools.h1
-rw-r--r--console/fbtv.c2
-rw-r--r--console/showriff.c14
-rw-r--r--console/vbi-tty.c99
-rw-r--r--console/webcam.c154
7 files changed, 269 insertions, 59 deletions
diff --git a/console/Subdir.mk b/console/Subdir.mk
index 8f166d4..b44b8c3 100644
--- a/console/Subdir.mk
+++ b/console/Subdir.mk
@@ -63,16 +63,16 @@ console/record: console/record.o
console/v4l-conf: console/v4l-conf.o
# libraries to link
-console/fbtv : LDLIBS := \
+console/fbtv : LDLIBS += \
$(THREAD_LIBS) $(CURSES_LIBS) $(LIRC_LIBS) $(ALSA_LIBS) \
$(FS_LIBS) -ljpeg -lm
-console/ttv : LDLIBS := $(THREAD_LIBS) $(AA_LIBS) -ljpeg -lm
-console/scantv : LDLIBS := $(THREAD_LIBS) $(VBI_LIBS) -ljpeg
-console/streamer : LDLIBS := $(THREAD_LIBS) -ljpeg -lm
-console/webcam : LDLIBS := $(THREAD_LIBS) -ljpeg
-console/radio : LDLIBS := $(CURSES_LIBS)
-console/record : LDLIBS := $(CURSES_LIBS)
-console/v4l-conf : LDLIBS := $(ATHENA_LIBS)
+console/ttv : LDLIBS += $(THREAD_LIBS) $(AA_LIBS) -ljpeg -lm
+console/scantv : LDLIBS += $(THREAD_LIBS) $(VBI_LIBS) -ljpeg
+console/streamer : LDLIBS += $(THREAD_LIBS) -ljpeg -lm
+console/webcam : LDLIBS += $(THREAD_LIBS) -ljpeg -lm
+console/radio : LDLIBS += $(CURSES_LIBS)
+console/record : LDLIBS += $(CURSES_LIBS)
+console/v4l-conf : LDLIBS += $(ATHENA_LIBS)
# linker flags
console/fbtv : LDFLAGS := $(DLFLAGS)
diff --git a/console/fbtools.c b/console/fbtools.c
index b094aa5..bc13a1f 100644
--- a/console/fbtools.c
+++ b/console/fbtools.c
@@ -74,6 +74,17 @@ struct DEVS devs_devfs = {
};
struct DEVS *devices;
+static void dev_init(void)
+{
+ struct stat dummy;
+
+ if (NULL != devices)
+ return;
+ if (0 == stat("/dev/.devfsd",&dummy))
+ devices = &devs_devfs;
+ else
+ devices = &devs_default;
+}
/* -------------------------------------------------------------------- */
/* console switching */
@@ -288,6 +299,29 @@ fb_setvt(int vtno)
}
}
+int fb_probe(void)
+{
+ struct fb_con2fbmap c2m;
+ struct stat st;
+ int fb;
+
+ dev_init();
+ fstat(0,&st);
+ if (((st.st_rdev >> 8) & 0xff) != TTY_MAJOR)
+ /* not a linux console */
+ return -1;
+ if (-1 == (fb = open(devices->fb0,O_WRONLY,0)))
+ /* can't open /dev/fb0 */
+ return -1;
+
+ c2m.console = st.st_rdev & 0xff;
+ if (-1 == ioctl(fb, FBIOGET_CON2FBMAP, &c2m))
+ /* ??? */
+ return -1;
+ close(fb);
+ return 0;
+}
+
int
fb_init(char *device, char *mode, int vt)
{
@@ -299,6 +333,7 @@ fb_init(char *device, char *mode, int vt)
fb_setvt(vt);
/* FIXME: where are MAJOR() / MINOR() ??? */
+ dev_init();
fstat(tty,&st);
if (((st.st_rdev >> 8) & 0xff) != TTY_MAJOR) {
/* catch that here, give a more user friendly error message that just
@@ -308,13 +343,6 @@ fb_init(char *device, char *mode, int vt)
" tool from a pseudo tty (xterm/ssh/screen/...).\n");
exit(1);
}
- if (NULL == devices) {
- struct stat dummy;
- if (0 == stat("/dev/.devfsd",&dummy))
- devices = &devs_devfs;
- else
- devices = &devs_default;
- }
if (NULL == device) {
device = getenv("FRAMEBUFFER");
diff --git a/console/fbtools.h b/console/fbtools.h
index a501c2f..469675c 100644
--- a/console/fbtools.h
+++ b/console/fbtools.h
@@ -11,6 +11,7 @@ extern int fb_mem_offset;
extern int fb_switch_state;
/* init + cleanup */
+int fb_probe(void);
int fb_init(char *device, char *mode, int vt);
void fb_cleanup(void);
void fb_catch_exit_signals(void);
diff --git a/console/fbtv.c b/console/fbtv.c
index 5eb9c7c..5104246 100644
--- a/console/fbtv.c
+++ b/console/fbtv.c
@@ -648,7 +648,7 @@ main(int argc, char *argv[])
if (optarg)
vt = strtoul(optarg, 0, 0);
else
- vt = -1;
+ vt = 0;
break;
case 'j':
joydev = optarg;
diff --git a/console/showriff.c b/console/showriff.c
index e069fd8..c2240b9 100644
--- a/console/showriff.c
+++ b/console/showriff.c
@@ -72,6 +72,10 @@ typedef unsigned char boolean;
#define audstag MAKEFOURCC('a','u','d','s')
#define dmlhtag MAKEFOURCC('d','m','l','h')
+#define avi_tag MAKEFOURCC('A','V','I',' ')
+#define wavetag MAKEFOURCC('W','A','V','E')
+#define fmt_tag MAKEFOURCC('f','m','t',' ')
+
#define MJPGtag MAKEFOURCC('M','J','P','G')
#define _00dbtag MAKEFOURCC('0','0','d','b')
#define _00dctag MAKEFOURCC('0','0','d','c')
@@ -96,6 +100,7 @@ static void FOURCC2Str(FOURCC fcc, char* s)
}
static DWORD fcc_type;
+static DWORD riff_type;
static int stop_on_errors = 1;
static int print_mjpeg = 0;
@@ -429,10 +434,11 @@ static boolean ProcessChunk(FILE* f, off_t filepos, off_t filesize,
FOURCC2Str(formtype,formstr); /* make it printable */
/* print out the indented form of the chunk: */
- if (chunkid==RIFFtag)
+ if (chunkid==RIFFtag) {
printf("%12c %*c Form Type = <%s>\n",
' ',(RekDepth+1)*4,' ',formstr);
- else
+ riff_type = formtype;
+ } else
printf("%12c %*c List Type = <%s>\n",
' ',(RekDepth+1)*4,' ',formstr);
@@ -483,6 +489,10 @@ static boolean ProcessChunk(FILE* f, off_t filepos, off_t filesize,
break;
}
break;
+ case fmt_tag:
+ if (riff_type == wavetag)
+ dump_vals(f,sizeof(names_strf_auds)/sizeof(char*),names_strf_auds);
+ break;
case dmlhtag:
dump_vals(f,sizeof(names_dmlh)/sizeof(struct VAL),names_dmlh);
break;
diff --git a/console/vbi-tty.c b/console/vbi-tty.c
index ae28bd0..07b09c4 100644
--- a/console/vbi-tty.c
+++ b/console/vbi-tty.c
@@ -19,8 +19,11 @@
#include <sys/types.h>
#include <sys/ioctl.h>
+#include <linux/fb.h>
+
#include "vbi-data.h"
#include "vbi-tty.h"
+#include "fbtools.h"
/* --------------------------------------------------------------------- */
@@ -48,6 +51,30 @@ static void tty_restore(void)
tcsetattr (0, TCSANOW, &saved_attributes);
}
+/* FIXME: Yes, I know, hardcoding ANSI sequences is bad. ncurses
+ * can't handle multibyte locales like UTF-8 not yet, that's why that
+ * dirty hack for now ... */
+static void tty_clear(void)
+{
+ fprintf(stderr,"\033[H\033[2J");
+}
+
+static void tty_goto(int x, int y)
+{
+ fprintf(stderr,"\033[%d;%dH",y,x);
+}
+
+/* --------------------------------------------------------------------- */
+
+static int have_fb = 0;
+static int fb_fmt = VBI_PIXFMT_RGBA32_LE;
+static int switch_last;
+
+static void fb_clear(void)
+{
+ fb_memset(fb_mem+fb_mem_offset,0,fb_fix.smem_len);
+}
+
/* --------------------------------------------------------------------- */
struct vbi_tty {
@@ -106,12 +133,22 @@ vbi_render_page(struct vbi_tty *tty)
vbi_fetch_vt_page(tty->vbi->dec,&tty->pg,tty->pgno,tty->subno,
VBI_WST_LEVEL_1p5,25,1);
vbi_fix_head(tty,tty->pg.text);
- len = vbi_export_txt(data,nl_langinfo(CODESET),25*41*8,
- &tty->pg,&vbi_fullrect,VBI_ANSICOLOR);
- fprintf(stderr,"\033[H");
- fwrite(data,len,1,stderr);
- fprintf(stderr,"\033[0;42H");
- free(data);
+ if (have_fb) {
+ vbi_draw_vt_page_region(&tty->pg, fb_fmt,
+ fb_mem + fb_mem_offset,
+ fb_fix.line_length,
+ 0,0,
+ tty->pg.columns, tty->pg.rows,
+ 0,1);
+
+ } else {
+ len = vbi_export_txt(data,nl_langinfo(CODESET),25*41*8,
+ &tty->pg,&vbi_fullrect,VBI_ANSICOLOR);
+ tty_goto(0,0);
+ fwrite(data,len,1,stderr);
+ tty_goto(42,0);
+ free(data);
+ }
}
static void
@@ -129,12 +166,22 @@ vbi_render_head(struct vbi_tty *tty, int pgno, int subno)
vbi_fetch_vt_page(tty->vbi->dec,&pg,pgno,subno,
VBI_WST_LEVEL_1p5,1,1);
vbi_fix_head(tty,pg.text);
- len = vbi_export_txt(data,nl_langinfo(CODESET),41*8,
- &pg,&head,VBI_ANSICOLOR);
- fprintf(stderr,"\033[H");
- fwrite(data,len,1,stderr);
- fprintf(stderr,"\033[0;42H");
- free(data);
+ if (have_fb) {
+ vbi_draw_vt_page_region(&pg, fb_fmt,
+ fb_mem + fb_mem_offset,
+ fb_fix.line_length,
+ 0,0,
+ pg.columns, 1,
+ 0,1);
+
+ } else {
+ len = vbi_export_txt(data,nl_langinfo(CODESET),41*8,
+ &pg,&head,VBI_ANSICOLOR);
+ tty_goto(0,0);
+ fwrite(data,len,1,stderr);
+ tty_goto(42,0);
+ free(data);
+ }
}
static void
@@ -186,13 +233,21 @@ void vbi_tty(char *device, int debug, int sim)
if (NULL == vbi)
exit(1);
- if (-1 != ioctl(0,TIOCGWINSZ,&win) && win.ws_row < 26) {
- fprintf(stderr,"terminal too small (need 26 rows, have %d)\n",
- win.ws_row);
- exit(1);
+ if (0 /* 0 == fb_probe() */ ) {
+ have_fb = 1;
+ fb_init(NULL,NULL,0);
+ fb_catch_exit_signals();
+ fb_switch_init();
+ switch_last = fb_switch_state;
+ } else {
+ if (-1 != ioctl(0,TIOCGWINSZ,&win) && win.ws_row < 26) {
+ fprintf(stderr,"Terminal too small (need 26 rows, have %d)\n",
+ win.ws_row);
+ exit(1);
+ }
}
tty_raw();
- fprintf(stderr,"\033[H\033[2J");
+ have_fb ? fb_clear() : tty_clear();
tty = malloc(sizeof(*tty));
memset(tty,0,sizeof(*tty));
@@ -209,10 +264,14 @@ void vbi_tty(char *device, int debug, int sim)
rc = select(vbi->fd+1,&set,NULL,NULL,&tv);
if (-1 == rc) {
tty_restore();
+ if (have_fb)
+ fb_cleanup();
perror("select");
exit(1);
}
if (0 == rc) {
+ if (have_fb)
+ fb_cleanup();
tty_restore();
fprintf(stderr,"oops: timeout\n");
exit(1);
@@ -230,7 +289,7 @@ void vbi_tty(char *device, int debug, int sim)
break;
case 'L' & 0x1f:
/* refresh */
- fprintf(stderr,"\033[H\033[2J");
+ have_fb ? fb_clear() : tty_clear();
vbi_render_page(tty);
break;
case 'i':
@@ -280,6 +339,8 @@ void vbi_tty(char *device, int debug, int sim)
vbi_hasdata(vbi);
}
}
- fprintf(stderr,"\033[H");
+ if (have_fb)
+ fb_cleanup();
+ tty_goto(0,0);
tty_restore();
}
diff --git a/console/webcam.c b/console/webcam.c
index 5dbc88e..2d8b3a6 100644
--- a/console/webcam.c
+++ b/console/webcam.c
@@ -14,6 +14,7 @@
#include <fcntl.h>
#include <limits.h>
#include <pthread.h>
+#include <math.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
@@ -24,6 +25,7 @@
#include "parseconfig.h"
#include "list.h"
+
/* ---------------------------------------------------------------------- */
/* configuration */
@@ -333,7 +335,7 @@ grab_init(void)
/* check all available conversion functions */
fmt.bytesperline = fmt.width*ng_vfmt_to_depth[fmt.fmtid]/8;
for (i = 0;;) {
- conv = ng_conv_find(fmt.fmtid, &i);
+ conv = ng_conv_find_to(fmt.fmtid, &i);
if (NULL == conv)
break;
gfmt = fmt;
@@ -440,6 +442,98 @@ add_text(char *image, int width, int height)
}
}
+/* ---------------------------------------------------------------------- */
+/* Frederic Helin <Frederic.Helin@inrialpes.fr> - 15/07/2002 */
+/* Correction fonction of stereographic radial distortion */
+
+int grab_dist_on = 0;
+int grab_dist_k = 700;
+int grab_dist_cx = -1;
+int grab_dist_cy = -1;
+int grab_dist_zoom = 50;
+int grab_dist_sensorw = 640;
+int grab_dist_sensorh = 480;
+
+static unsigned char *
+correct_distor(unsigned char * in, int width, int height,
+ int grab_zoom, int grap_k, int cx, int cy,
+ int grab_sensorw, int grab_sensorh)
+{
+ static unsigned char * corrimg = NULL;
+
+ int i, j, di, dj;
+ float dr, cr,ca, sensor_w, sensor_h, sx, zoom, k;
+
+ sensor_w = grab_dist_sensorw/100.0;
+ sensor_h = grab_dist_sensorh/100.0;
+ zoom = grab_zoom / 100.0;
+ k = grap_k / 100.0;
+
+ if (corrimg == NULL && (corrimg = malloc(width*height*3)) == NULL ) {
+ fprintf(stderr, "out of memory\n");
+ exit(1);
+ }
+
+ sensor_w = 6.4;
+ sensor_h = 4.8;
+
+ // calc ratio x/y
+ sx = width * sensor_h / (height * sensor_w);
+
+ // calc new value of k in the coordonates systeme of computer
+ k = k * height / sensor_h;
+
+ // Clear image
+ for (i = 0; i < height*width*3; i++) corrimg[i] = 255;
+
+ for (j = 0; j < height ; j++) {
+ for (i = 0; i < width ; i++) {
+
+ // compute radial distortion / parameters of center of image
+ cr = sqrt((i-cx)/sx*(i-cx)/sx+(j-cy)*(j-cy));
+ ca = atan(cr/k/zoom);
+ dr = k * tan(ca/2);
+
+ if (i == cx && j == cy) {di = cx; dj = cy;}
+ else {
+ di = (i-cx) * dr / cr + cx;
+ dj = (j-cy) * dr / cr + cy;
+ }
+
+ if (dj<height && di < width && di >= 0 && dj >= 0 &&
+ j<height && i < width && i >= 0 && j >= 0 ) {
+ corrimg[3*(j*width + i) ] = in[3*(dj*width + di) ];
+ corrimg[3*(j*width + i)+1] = in[3*(dj*width + di)+1];
+ corrimg[3*(j*width + i)+2] = in[3*(dj*width + di)+2];
+ }
+ }
+ }
+ return corrimg;
+}
+
+/* ---------------------------------------------------------------------- */
+
+static unsigned int
+compare_images(unsigned char *last, unsigned char *current,
+ int width, int height)
+{
+ unsigned char *p1 = last;
+ unsigned char *p2 = current;
+ int avg, diff, max, i = width*height*3;
+
+ for (max = 0, avg = 0; --i; p1++,p2++) {
+ diff = (*p1 < *p2) ? (*p2 - *p1) : (*p1 - *p2);
+ avg += diff;
+ if (diff > max)
+ max = diff;
+ }
+ avg = avg / width / height;
+ fprintf(stderr,"compare: max=%d,avg=%d\n",max,avg);
+ /* return avg */
+ return max;
+}
+
+
static unsigned char *
rotate_image(unsigned char * in, int *wp, int *hp, int rot,
int top, int left, int bottom, int right)
@@ -456,7 +550,7 @@ rotate_image(unsigned char * in, int *wp, int *hp, int rot,
fprintf(stderr, "out of memory\n");
exit(1);
}
- switch ( rot ) {
+ switch (rot) {
default:
case 0:
for (j = 0; j < oh; j++) {
@@ -514,25 +608,6 @@ rotate_image(unsigned char * in, int *wp, int *hp, int rot,
return rotimg;
}
-static unsigned int
-compare_images(unsigned char *last, unsigned char *current,
- int width, int height)
-{
- unsigned char *p1 = last;
- unsigned char *p2 = current;
- int avg, diff, max, i = width*height*3;
-
- for (max = 0, avg = 0; --i; p1++,p2++) {
- diff = (*p1 < *p2) ? (*p2 - *p1) : (*p1 - *p2);
- avg += diff;
- if (diff > max)
- max = diff;
- }
- avg = avg / width / height;
- fprintf(stderr,"compare: max=%d,avg=%d\n",max,avg);
- /* return avg */
- return max;
-}
/* ---------------------------------------------------------------------- */
@@ -609,7 +684,22 @@ main(int argc, char *argv[])
if (-1 != (i = cfg_get_int("grab","bg_blue")))
if (i >= 0 && i <= 255)
grab_bg_b = i;
-
+
+ if (-1 != (i = cfg_get_int("grab","distor")))
+ grab_dist_on = i;
+ if (-1 != (i = cfg_get_int("grab","distor_k")))
+ grab_dist_k = i;
+ if (-1 != (i = cfg_get_int("grab","distor_cx")))
+ grab_dist_cx = i;
+ if (-1 != (i = cfg_get_int("grab","distor_cy")))
+ grab_dist_cy = i;
+ if (-1 != (i = cfg_get_int("grab","distor_zoom")))
+ grab_dist_zoom =i;
+ if (-1 != (i = cfg_get_int("grab","distor_sensorw")))
+ grab_dist_sensorw = i;
+ if (-1 != (i = cfg_get_int("grab","distor_sensorh")))
+ grab_dist_sensorh = i;
+
if ( grab_top < 0 ) grab_top = 0;
if ( grab_left < 0 ) grab_left = 0;
if ( grab_bottom > grab_height ) grab_bottom = grab_height;
@@ -619,6 +709,19 @@ main(int argc, char *argv[])
if ( grab_top >= grab_bottom ) grab_top = 0;
if ( grab_left >= grab_right ) grab_left = 0;
+ if (grab_dist_k < 1 || grab_dist_k > 10000)
+ grab_dist_k = 700;
+ if (grab_dist_cx < 0 || grab_dist_cx > grab_width)
+ grab_dist_cx = grab_width / 2;
+ if (grab_dist_cy < 0 || grab_dist_cy > grab_height)
+ grab_dist_cy = grab_height / 2;
+ if (grab_dist_zoom < 1 || grab_dist_zoom > 1000)
+ grab_dist_zoom = 100;
+ if (grab_dist_sensorw < 1 || grab_dist_sensorw >9999)
+ grab_dist_sensorw = 640;
+ if (grab_dist_sensorh < 1 || grab_dist_sensorh >9999)
+ grab_dist_sensorh = 480;
+
INIT_LIST_HEAD(&connections);
for (sections = cfg_list_sections(); *sections != NULL; sections++) {
if (0 == strcasecmp(*sections,"grab"))
@@ -708,6 +811,13 @@ main(int argc, char *argv[])
for (;;) {
/* grab a new one */
gimg = grab_one(&width,&height);
+
+ if (grab_dist_on)
+ gimg = correct_distor(gimg, width, height,
+ grab_dist_zoom, grab_dist_k,
+ grab_dist_cx, grab_dist_cy,
+ grab_dist_sensorw, grab_dist_sensorh);
+
image = rotate_image(gimg, &width, &height, grab_rotate,
grab_top, grab_left, grab_bottom, grab_right);

Privacy Policy