Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1173 → Rev 1174

/demos/trunk/bttvdemo/bttv.c
1,176 → 1,165
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Giacomo Guidi <giacomo@gandalf.sssup.it>
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2003 Giacomo Guidi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
#include "kernel/kern.h"
#include <drivers/fg.h>
#include <drivers/vga.h>
#include <drivers/keyb.h>
#include <unistd.h>
#include <stdlib.h>
 
#define WIDTH 640
#define HEIGHT 480
#define BYTES_PP 2
#define INITSTR G640x480x64K //SVGAlib standard mode definitions
#define CARD VESA //Video driver
 
unsigned char *video_buf = NULL; //Video Buffer
unsigned long int VMEMLONG = WIDTH * HEIGHT * BYTES_PP / 4; // Used by copy_videomem_16to16
unsigned long int RGB565MEM = WIDTH * HEIGHT * BYTES_PP; // Total video mem
 
#define FG_PERIOD 40000
#define FG_WCET 30000
#define FG_W 320
#define FG_H 200
 
unsigned int color = FG_MONO;
 
static int screen(int mode)
{
 
vga_modeinfo *minf;
 
vga_setmode(mode,CARD);
minf = vga_getmodeinfo(mode);
if(! (minf->flags & CAPABLE_LINEAR)){
vga_setmode(TEXT,CARD);
printk(KERN_INFO "The mode %d is not capable of linear\n",mode);
return 1;
}
vga_setpage(0);
if(vga_setlinearaddressing() == -1) {
vga_setmode(TEXT,CARD);
printk(KERN_INFO "Could not set linear addressing for mode %d\n",mode);
return 1;
}
video_buf = vga_getgraphmem();
memset(video_buf, 0, RGB565MEM);
grx_setbuffer(video_buf, WIDTH, HEIGHT); //Init of RGBA version of grx functions
//created to work with Mesa buffer
return 0;
}
 
void program_end(void *arg)
{
 
FG_close();
vga_setmode(TEXT,CARD);
sys_end();
 
}
 
void program_key_end(KEY_EVT *k)
{
 
sys_end();
 
}
void elaborate_image(void *imageptr)
{
 
WORD x,y;
BYTE *col;
 
if (color == FG_MONO) {
 
for(y = 0; y < FG_H; y++)
for(x = 0; x < FG_W; x++) {
 
col = (BYTE *)(imageptr + y*FG_W + x);
*(WORD *)(video_buf + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col),*(BYTE *)(col));
 
}
 
}
 
if (color == FG_RGB24) {
 
for(y = 0; y < FG_H; y++)
for(x = 0; x < FG_W; x++) {
 
col = (BYTE *)(imageptr + y*(FG_W*3) + (x*3));
*(WORD *)(video_buf + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col+1),*(BYTE *)(col+2));
 
}
 
}
 
printf_xy(0,0,WHITE,"Grabbed = %08lx",*(DWORD *)(imageptr + 50*FG_W + 50));
printf_xy(0,1,WHITE,"Grabbed = %08lx",*(DWORD *)(imageptr + 51*FG_W + 50));
}
 
int main(int argc, char **argv)
{
 
int channel = 0;
if (argc < 2) {
channel = 0;
} else {
channel = atoi(argv[1]);
}
sys_atrunlevel(program_end,NULL, RUNLEVEL_BEFORE_EXIT);
{
KEY_EVT k;
k.flag = ALTL_BIT;
k.scan = KEY_C;
k.ascii = 'c';
keyb_hook(k,program_key_end);
}
 
//screen(INITSTR);
video_buf = malloc(RGB565MEM);
 
sleep(1);
FG_init(FG_PERIOD, FG_WCET, FG_W, FG_H, color, channel);
 
FG_set_hook(elaborate_image);
 
FG_start_grabbing();
return 0;
 
}
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Giacomo Guidi <giacomo@gandalf.sssup.it>
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2003 Giacomo Guidi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
#include "kernel/kern.h"
#include <drivers/fg.h>
#include <drivers/glib.h>
#include <drivers/keyb.h>
#include <unistd.h>
#include <stdlib.h>
 
#define WIDTH 640
#define HEIGHT 480
#define BYTES_PP 2
 
unsigned char *video_buf = NULL; //Video Buffer
unsigned long int VMEMLONG = WIDTH * HEIGHT * BYTES_PP / 4; // Used by copy_videomem_16to16
unsigned long int RGB565MEM = WIDTH * HEIGHT * BYTES_PP; // Total video mem
 
#define FG_PERIOD 40000
#define FG_WCET 30000
#define FG_W 320
#define FG_H 200
 
unsigned int color = FG_MONO;
 
extern DWORD flbaddr;
 
static void screen()
{
 
/* graphic card Initialization */
if (grx_init() < 1) {
sys_abort(1);
}
if (grx_open(640, 480, 16) < 0) {
cprintf("GRX Err\n");
sys_abort(1);
}
 
video_buf = (unsigned char *)flbaddr;
}
 
void program_end(void *arg)
{
 
FG_close();
grx_close();
sys_end();
 
}
 
void program_key_end(KEY_EVT *k)
{
sys_end();
 
}
void elaborate_image(void *imageptr)
{
 
WORD x,y;
BYTE *col;
 
if (color == FG_MONO) {
 
for(y = 0; y < FG_H; y++)
for(x = 0; x < FG_W; x++) {
 
col = (BYTE *)(imageptr + y*FG_W + x);
*(WORD *)(video_buf + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col),*(BYTE *)(col));
 
}
 
}
 
if (color == FG_RGB24) {
 
for(y = 0; y < FG_H; y++)
for(x = 0; x < FG_W; x++) {
 
col = (BYTE *)(imageptr + y*(FG_W*3) + (x*3));
*(WORD *)(video_buf + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col+1),*(BYTE *)(col+2));
 
}
 
}
 
//printf_xy(0,0,WHITE,"Grabbed = %08lx",*(DWORD *)(imageptr + 50*FG_W + 50));
//printf_xy(0,1,WHITE,"Grabbed = %08lx",*(DWORD *)(imageptr + 51*FG_W + 50));
}
 
int main(int argc, char **argv)
{
 
int channel = 0;
if (argc < 2) {
channel = 0;
} else {
channel = atoi(argv[1]);
}
sys_atrunlevel(program_end,NULL, RUNLEVEL_BEFORE_EXIT);
{
KEY_EVT k;
k.flag = ALTL_BIT;
k.scan = KEY_C;
k.ascii = 'c';
keyb_hook(k,program_key_end);
}
 
screen();
//video_buf = malloc(RGB565MEM);
 
sleep(1);
FG_init(FG_PERIOD, FG_WCET, FG_W, FG_H, color, channel);
 
FG_set_hook(elaborate_image);
 
FG_start_grabbing();
return 0;
 
}
/demos/trunk/bttvdemo/readme.txt
7,10 → 7,17
 
Last update 27/05/2003
--------------------------------------
Ex:
 
x bttv [channel number]
 
if the channel is not specified 0 is taken.
If you don't see a grabbed image, you
can try to set a channel number from 1 to 4.
 
This is a simple demo for the BTTV driver.
It starts the frame grabber at 25 fps 320x200.
The SVGA driver (default VESA) is used to
The GRX driver is used to
visualize the grabbed images.
 
See also drivers/bttv/readme
/demos/trunk/bttvdemo/makefile
12,5 → 12,5
include $(BASE)/config/example.mk
 
bttv:
make -f $(SUBMAKE) APP=bttv INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__OLDCHAR__ __SVGA__ __BTTV__"
make -f $(SUBMAKE) APP=bttv INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__OLDCHAR__ __GRX__ __BTTV__"