Used GNU indent style.

DEVEL_2_0_BRANCH-1
Henning Geinitz 2002-08-25 19:36:18 +00:00
rodzic 421fa4e12a
commit 2b54c3e7c4
4 zmienionych plików z 608 dodań i 603 usunięć

Wyświetl plik

@ -88,12 +88,14 @@
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
struct CHANLIST { struct CHANLIST
{
char *name; char *name;
int freq; int freq;
}; };
struct CHANLISTS { struct CHANLISTS
{
char *name; char *name;
struct CHANLIST *list; struct CHANLIST *list;
int count; int count;

Wyświetl plik

@ -6,8 +6,8 @@
#define VIDEO_RGB16_BE 6 /* 16 bpp big endian */ #define VIDEO_RGB16_BE 6 /* 16 bpp big endian */
#define VIDEO_BGR24 7 /* bgrbgrbgrbgr (LE) */ #define VIDEO_BGR24 7 /* bgrbgrbgrbgr (LE) */
#define VIDEO_BGR32 8 /* bgr-bgr-bgr- (LE) */ #define VIDEO_BGR32 8 /* bgr-bgr-bgr- (LE) */
#define VIDEO_RGB24 9 /* rgbrgbrgbrgb (BE)*/ #define VIDEO_RGB24 9 /* rgbrgbrgbrgb (BE) */
#define VIDEO_RGB32 10 /* -rgb-rgb-rgb (BE)*/ #define VIDEO_RGB32 10 /* -rgb-rgb-rgb (BE) */
#define VIDEO_LUT2 11 /* lookup-table 2 byte depth */ #define VIDEO_LUT2 11 /* lookup-table 2 byte depth */
#define VIDEO_LUT4 12 /* lookup-table 4 byte depth */ #define VIDEO_LUT4 12 /* lookup-table 4 byte depth */
@ -17,37 +17,41 @@
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
struct STRTAB { struct STRTAB
{
long nr; long nr;
char *str; char *str;
}; };
struct OVERLAY_CLIP { struct OVERLAY_CLIP
int x1,x2,y1,y2; {
int x1, x2, y1, y2;
}; };
struct GRABBER { struct GRABBER
{
char *name; char *name;
int flags; int flags;
struct STRTAB *norms; struct STRTAB *norms;
struct STRTAB *inputs; struct STRTAB *inputs;
int (*grab_open)(char *opt); int (*grab_open) (char *opt);
int (*grab_close)(void); int (*grab_close) (void);
int (*grab_setupfb)(int sw, int sh, int format, void *base, int bpl); int (*grab_setupfb) (int sw, int sh, int format, void *base, int bpl);
int (*grab_overlay)(int x, int y, int width, int height, int format, int (*grab_overlay) (int x, int y, int width, int height, int format,
struct OVERLAY_CLIP *oc, int count); struct OVERLAY_CLIP * oc, int count);
int (*grab_setparams)(int format, int *width, int *height, int *linelength); int (*grab_setparams) (int format, int *width, int *height,
void* (*grab_capture)(int single); int *linelength);
void (*grab_cleanup)(void); void *(*grab_capture) (int single);
void (*grab_cleanup) (void);
int (*grab_tune)(unsigned long freq); int (*grab_tune) (unsigned long freq);
int (*grab_tuned)(void); int (*grab_tuned) (void);
int (*grab_input)(int input, int norm); int (*grab_input) (int input, int norm);
int (*grab_picture)(int color, int bright, int hue, int contrast); int (*grab_picture) (int color, int bright, int hue, int contrast);
int (*grab_audio)(int mute, int volume, int *mode); int (*grab_audio) (int mute, int volume, int *mode);
}; };
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
@ -60,11 +64,11 @@ extern int fd_grab;
extern struct GRABBER *grabber; extern struct GRABBER *grabber;
extern unsigned int format2depth[]; extern unsigned int format2depth[];
extern unsigned char* format_desc[]; extern unsigned char *format_desc[];
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
int grabber_open(int sw, int sh, void *base, int format, int width); int grabber_open (int sw, int sh, void *base, int format, int width);
int grabber_setparams(int format, int *width, int *height, int grabber_setparams (int format, int *width, int *height,
int *linelength, int lut_valid); int *linelength, int lut_valid);
void* grabber_capture(void *dest, int dest_linelength, int single); void *grabber_capture (void *dest, int dest_linelength, int single);

Wyświetl plik

@ -52,11 +52,11 @@
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#ifdef _AIX #ifdef _AIX
# include "lalloca.h" /* MUST come first for AIX! */ # include "../include/lalloca.h" /* MUST come first for AIX! */
#endif #endif
#include "sane/config.h" #include "../include/sane/config.h"
#include "lalloca.h" #include "../include/lalloca.h"
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
@ -79,13 +79,13 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "sane/sane.h" #include "../include/sane/sane.h"
#include "sane/sanei.h" #include "../include/sane/sanei.h"
#include "sane/saneopts.h" #include "../include/sane/saneopts.h"
#include "v4l-grab.h" #include "v4l-grab.h"
#if what_is_this #if what_is_this
# include "colorspace.h" # include "colorspace.h" /* ??? */
#endif #endif
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <asm/types.h> /* XXX glibc */ #include <asm/types.h> /* XXX glibc */
@ -99,74 +99,68 @@
#include "v4l.h" #include "v4l.h"
#define BACKEND_NAME v4l #define BACKEND_NAME v4l
#include "sane/sanei_backend.h" #include "../include/sane/sanei_backend.h"
#ifndef PATH_MAX #ifndef PATH_MAX
# define PATH_MAX 1024 # define PATH_MAX 1024
#endif #endif
#include "sane/sanei_config.h" #include "../include/sane/sanei_config.h"
#define V4L_CONFIG_FILE "v4l.conf" #define V4L_CONFIG_FILE "v4l.conf"
static const SANE_Device ** devlist = NULL; static const SANE_Device **devlist = NULL;
static int num_devices; static int num_devices;
static V4L_Device * first_dev; static V4L_Device *first_dev;
static V4L_Scanner * first_handle; static V4L_Scanner *first_handle;
static int v4ldev; static int v4ldev;
static char *buffer; static char *buffer;
static int buffercount; static int buffercount;
static const SANE_String_Const resolution_list[] = static const SANE_String_Const resolution_list[] = {
{
"Low", /* million-mode */ "Low", /* million-mode */
"High", /* billion-mode */ "High", /* billion-mode */
0 0
}; };
static const SANE_Int color_depth_list[] = static const SANE_Int color_depth_list[] = {
{ 3, /* # of elements */
3 , /* # of elements */
6, 8, 24 /* "thousand" mode not implemented yet */ 6, 8, 24 /* "thousand" mode not implemented yet */
}; };
static const SANE_Int xfer_scale_list[] = static const SANE_Int xfer_scale_list[] = {
{
4, /* # of elements */ 4, /* # of elements */
1, 2, 4 , 8 1, 2, 4, 8
}; };
static const SANE_Range u8_range = static const SANE_Range u8_range = {
{
/* min, max, quantization */ /* min, max, quantization */
0, 255, 0 0, 255, 0
}; };
static const SANE_Range brightness_range = static const SANE_Range brightness_range = {
{
/* min, max, quantization */ /* min, max, quantization */
0, 255, 0 /* 255 is bulb mode! */ 0, 255, 0 /* 255 is bulb mode! */
}; };
static SANE_Range x_range = {0,338,2}; static SANE_Range x_range = { 0, 338, 2 };
static SANE_Range odd_x_range = {1,339,2}; static SANE_Range odd_x_range = { 1, 339, 2 };
static SANE_Range y_range = {0,249,1}; static SANE_Range y_range = { 0, 249, 1 };
static SANE_Range odd_y_range ={1,250,1}; static SANE_Range odd_y_range = { 1, 250, 1 };
static SANE_Parameters parms = static SANE_Parameters parms = {
{
SANE_FRAME_RGB, SANE_FRAME_RGB,
1, /* 1 = Last Frame , 0 = More Frames to come */ 1, /* 1 = Last Frame , 0 = More Frames to come */
0, /* Number of bytes returned per scan line: */ 0, /* Number of bytes returned per scan line: */
0, /* Number of pixels per scan line. */ 0, /* Number of pixels per scan line. */
0, /* Number of lines for the current scan. */ 0, /* Number of lines for the current scan. */
8, /* Number of bits per sample. */ 8, /* Number of bits per sample. */
}; };
static struct video_capability capability; static struct video_capability capability;
@ -176,9 +170,9 @@ static struct video_mbuf ov_mbuf;
static struct video_mmap gb; static struct video_mmap gb;
static SANE_Status static SANE_Status
attach (const char *devname, V4L_Device **devp) attach (const char *devname, V4L_Device ** devp)
{ {
V4L_Device * q; V4L_Device *q;
errno = 0; errno = 0;
@ -206,7 +200,7 @@ attach (const char *devname, V4L_Device **devp)
static SANE_Status static SANE_Status
init_options (V4L_Scanner *s) init_options (V4L_Scanner * s)
{ {
int i; int i;
@ -295,7 +289,7 @@ init_options (V4L_Scanner *s)
parms.bytes_per_line = window.width * 3; parms.bytes_per_line = window.width * 3;
break; break;
} }
case VIDEO_PALETTE_UYVY: /*The great thing about standards is..*/ case VIDEO_PALETTE_UYVY: /*The great thing about standards is.. */
{ {
parms.format = SANE_FRAME_RGB; parms.format = SANE_FRAME_RGB;
parms.bytes_per_line = window.width * 3; parms.bytes_per_line = window.width * 3;
@ -515,7 +509,7 @@ init_options (V4L_Scanner *s)
s->opt[OPT_CONTRAST].type = SANE_TYPE_INT; s->opt[OPT_CONTRAST].type = SANE_TYPE_INT;
s->opt[OPT_CONTRAST].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_CONTRAST].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_CONTRAST].constraint.range = &u8_range; s->opt[OPT_CONTRAST].constraint.range = &u8_range;
s->val[OPT_CONTRAST].w = pict.contrast /256; s->val[OPT_CONTRAST].w = pict.contrast / 256;
/* black-level */ /* black-level */
s->opt[OPT_BLACK_LEVEL].name = SANE_NAME_BLACK_LEVEL; s->opt[OPT_BLACK_LEVEL].name = SANE_NAME_BLACK_LEVEL;
@ -537,7 +531,7 @@ init_options (V4L_Scanner *s)
s->opt[OPT_WHITE_LEVEL].type = SANE_TYPE_INT; s->opt[OPT_WHITE_LEVEL].type = SANE_TYPE_INT;
s->opt[OPT_WHITE_LEVEL].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_WHITE_LEVEL].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_WHITE_LEVEL].constraint.range = &u8_range; s->opt[OPT_WHITE_LEVEL].constraint.range = &u8_range;
s->val[OPT_WHITE_LEVEL].w = pict.whiteness /256; s->val[OPT_WHITE_LEVEL].w = pict.whiteness / 256;
/* hue */ /* hue */
s->opt[OPT_HUE].name = SANE_NAME_HUE; s->opt[OPT_HUE].name = SANE_NAME_HUE;
@ -558,20 +552,20 @@ init_options (V4L_Scanner *s)
s->opt[OPT_SATURATION].type = SANE_TYPE_INT; s->opt[OPT_SATURATION].type = SANE_TYPE_INT;
s->opt[OPT_SATURATION].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_SATURATION].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_SATURATION].constraint.range = &u8_range; s->opt[OPT_SATURATION].constraint.range = &u8_range;
s->val[OPT_SATURATION].w = pict.colour / 256 ; s->val[OPT_SATURATION].w = pict.colour / 256;
return SANE_STATUS_GOOD; return SANE_STATUS_GOOD;
} }
SANE_Status SANE_Status
sane_init (SANE_Int *version_code, SANE_Auth_Callback authorize) sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{ {
char dev_name[PATH_MAX], * str; char dev_name[PATH_MAX], *str;
size_t len; size_t len;
FILE *fp; FILE *fp;
authorize = authorize; /* stop gcc from complaining */ authorize = authorize; /* stop gcc from complaining */
DBG_INIT(); DBG_INIT ();
if (version_code) if (version_code)
*version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR, 0); *version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR, 0);
@ -583,7 +577,7 @@ sane_init (SANE_Int *version_code, SANE_Auth_Callback authorize)
return SANE_STATUS_INVAL; return SANE_STATUS_INVAL;
} }
while (sanei_config_read(dev_name, sizeof (dev_name), fp)) while (sanei_config_read (dev_name, sizeof (dev_name), fp))
{ {
if (dev_name[0] == '#') /* ignore line comments */ if (dev_name[0] == '#') /* ignore line comments */
continue; continue;
@ -604,12 +598,14 @@ sane_init (SANE_Int *version_code, SANE_Auth_Callback authorize)
attach (dev_name, 0); attach (dev_name, 0);
} }
else else
DBG (1, "sane_init: ioctl (%d, VIDIOCGCAP,..) failed on `%s': %s\n", DBG (1,
"sane_init: ioctl (%d, VIDIOCGCAP,..) failed on `%s': %s\n",
v4ldev, dev_name, strerror (errno)); v4ldev, dev_name, strerror (errno));
close (v4ldev); close (v4ldev);
} }
else else
DBG (1, "sane_init: failed to open device `%s': %s\n", dev_name, strerror (errno)); DBG (1, "sane_init: failed to open device `%s': %s\n", dev_name,
strerror (errno));
} }
fclose (fp); fclose (fp);
return SANE_STATUS_GOOD; return SANE_STATUS_GOOD;
@ -629,7 +625,7 @@ sane_exit (void)
if (NULL != devlist) if (NULL != devlist)
{ {
free(devlist); free (devlist);
devlist = NULL; devlist = NULL;
} }
} }
@ -659,7 +655,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only)
} }
SANE_Status SANE_Status
sane_open (SANE_String_Const devicename, SANE_Handle *handle) sane_open (SANE_String_Const devicename, SANE_Handle * handle)
{ {
SANE_Status status; SANE_Status status;
V4L_Device *dev; V4L_Device *dev;
@ -669,10 +665,10 @@ sane_open (SANE_String_Const devicename, SANE_Handle *handle)
if (devicename[0]) if (devicename[0])
{ {
v4ldev = open ( devicename,O_RDWR); v4ldev = open (devicename, O_RDWR);
if (-1 == v4ldev) if (-1 == v4ldev)
return SANE_STATUS_DEVICE_BUSY; return SANE_STATUS_DEVICE_BUSY;
if (-1 == ioctl(v4ldev,VIDIOCGCAP,&capability)) if (-1 == ioctl (v4ldev, VIDIOCGCAP, &capability))
return SANE_STATUS_INVAL; return SANE_STATUS_INVAL;
status = attach (devicename, &dev); status = attach (devicename, &dev);
if (status != SANE_STATUS_GOOD) if (status != SANE_STATUS_GOOD)
@ -697,14 +693,14 @@ sane_open (SANE_String_Const devicename, SANE_Handle *handle)
syslog (LOG_NOTICE,"V4L Device is Monochrome"); syslog (LOG_NOTICE,"V4L Device is Monochrome");
if (VID_TYPE_SUBCAPTURE & capability.type) if (VID_TYPE_SUBCAPTURE & capability.type)
syslog (LOG_NOTICE,"V4L Device can capture parts of the Image"); syslog (LOG_NOTICE,"V4L Device can capture parts of the Image");
*/ */
if (-1 == ioctl(v4ldev,VIDIOCGPICT,&pict)) if (-1 == ioctl (v4ldev, VIDIOCGPICT, &pict))
return SANE_STATUS_INVAL; return SANE_STATUS_INVAL;
if (-1 == ioctl(v4ldev,VIDIOCGWIN,&window)) if (-1 == ioctl (v4ldev, VIDIOCGWIN, &window))
return SANE_STATUS_INVAL; return SANE_STATUS_INVAL;
if (-1 == ioctl(v4ldev,VIDIOCGMBUF,&ov_mbuf)) if (-1 == ioctl (v4ldev, VIDIOCGMBUF, &ov_mbuf))
DBG (1, "sane_open: no Fbuffer\n"); DBG (1, "sane_open: no Fbuffer\n");
} }
else else
@ -758,7 +754,7 @@ sane_close (SANE_Handle handle)
if (s->scanning) if (s->scanning)
sane_cancel (handle); sane_cancel (handle);
close(s->fd); close (s->fd);
free (s); free (s);
} }
@ -774,7 +770,7 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option)
SANE_Status SANE_Status
sane_control_option (SANE_Handle handle, SANE_Int option, sane_control_option (SANE_Handle handle, SANE_Int option,
SANE_Action action, void *val, SANE_Int *info) SANE_Action action, void *val, SANE_Int * info)
{ {
V4L_Scanner *s = handle; V4L_Scanner *s = handle;
SANE_Status status; SANE_Status status;
@ -793,7 +789,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option,
if (action == SANE_ACTION_GET_VALUE) if (action == SANE_ACTION_GET_VALUE)
{ {
init_options(s); init_options (s);
switch (option) switch (option)
{ {
/* word options: */ /* word options: */
@ -828,10 +824,10 @@ sane_control_option (SANE_Handle handle, SANE_Int option,
if (status != SANE_STATUS_GOOD) if (status != SANE_STATUS_GOOD)
return status; return status;
if (-1 == ioctl(s->fd,VIDIOCGWIN,&window)) if (-1 == ioctl (s->fd, VIDIOCGWIN, &window))
{ {
DBG (1, "sane_control_option: can not get window geometry\n"); DBG (1, "sane_control_option: can not get window geometry\n");
/*return SANE_STATUS_INVAL;*/ /*return SANE_STATUS_INVAL; */
} }
window.clipcount = 0; window.clipcount = 0;
window.clips = 0; window.clips = 0;
@ -853,21 +849,21 @@ sane_control_option (SANE_Handle handle, SANE_Int option,
case OPT_TL_Y: case OPT_TL_Y:
break; break;
case OPT_BR_X: case OPT_BR_X:
window.width = *(SANE_Word *)val; window.width = *(SANE_Word *) val;
parms.pixels_per_line = *(SANE_Word *)val; parms.pixels_per_line = *(SANE_Word *) val;
if (info) if (info)
*info |= SANE_INFO_RELOAD_PARAMS; *info |= SANE_INFO_RELOAD_PARAMS;
break; break;
case OPT_BR_Y: case OPT_BR_Y:
window.height = *(SANE_Word *)val; window.height = *(SANE_Word *) val;
parms.lines = *(SANE_Word *)val; parms.lines = *(SANE_Word *) val;
if (info) if (info)
*info |= SANE_INFO_RELOAD_PARAMS; *info |= SANE_INFO_RELOAD_PARAMS;
break; break;
case OPT_XFER_SCALE: case OPT_XFER_SCALE:
break; break;
case OPT_DEPTH: case OPT_DEPTH:
pict.depth = *(SANE_Word *)val; pict.depth = *(SANE_Word *) val;
if (info) if (info)
*info |= SANE_INFO_RELOAD_PARAMS; *info |= SANE_INFO_RELOAD_PARAMS;
break; break;
@ -881,17 +877,17 @@ sane_control_option (SANE_Handle handle, SANE_Int option,
case OPT_TEST: case OPT_TEST:
case OPT_DESPECKLE: case OPT_DESPECKLE:
case OPT_BRIGHTNESS: case OPT_BRIGHTNESS:
pict.brightness = *(SANE_Word *)val * 256; pict.brightness = *(SANE_Word *) val *256;
if (info) if (info)
*info |= SANE_INFO_RELOAD_PARAMS; *info |= SANE_INFO_RELOAD_PARAMS;
break; break;
case OPT_CONTRAST: case OPT_CONTRAST:
pict.contrast = *(SANE_Word *)val * 256; pict.contrast = *(SANE_Word *) val *256;
/* if (info) *info |= SANE_INFO_RELOAD_PARAMS;*/ /* if (info) *info |= SANE_INFO_RELOAD_PARAMS; */
break; break;
case OPT_BLACK_LEVEL: case OPT_BLACK_LEVEL:
case OPT_WHITE_LEVEL: case OPT_WHITE_LEVEL:
pict.whiteness = *(SANE_Word *)val * 256; pict.whiteness = *(SANE_Word *) val *256;
if (info) if (info)
*info |= SANE_INFO_RELOAD_PARAMS; *info |= SANE_INFO_RELOAD_PARAMS;
break; break;
@ -899,19 +895,19 @@ sane_control_option (SANE_Handle handle, SANE_Int option,
case OPT_SATURATION: case OPT_SATURATION:
s->val[option].w = *(SANE_Word *) val; s->val[option].w = *(SANE_Word *) val;
} }
if (-1 == ioctl(s->fd,VIDIOCSWIN,&window)) if (-1 == ioctl (s->fd, VIDIOCSWIN, &window))
{ {
DBG (1, "sane_control_option: can not set window geometry\n"); DBG (1, "sane_control_option: can not set window geometry\n");
/*return SANE_STATUS_INVAL;*/ /*return SANE_STATUS_INVAL; */
} }
if (-1 == ioctl(s->fd,VIDIOCGWIN,&window)) if (-1 == ioctl (s->fd, VIDIOCGWIN, &window))
{ {
DBG (1, "sane_control_option: can not get window geometry\n"); DBG (1, "sane_control_option: can not get window geometry\n");
} }
if (-1 == ioctl(s->fd,VIDIOCSPICT,&pict)) if (-1 == ioctl (s->fd, VIDIOCSPICT, &pict))
{ {
DBG (1, "sane_control_option: can not set picture parameters\n"); DBG (1, "sane_control_option: can not set picture parameters\n");
/*return SANE_STATUS_INVAL;*/ /*return SANE_STATUS_INVAL; */
} }
return SANE_STATUS_GOOD; return SANE_STATUS_GOOD;
} }
@ -931,11 +927,11 @@ sane_control_option (SANE_Handle handle, SANE_Int option,
} }
SANE_Status SANE_Status
sane_get_parameters (SANE_Handle handle, SANE_Parameters *params) sane_get_parameters (SANE_Handle handle, SANE_Parameters * params)
{ {
V4L_Scanner *s = handle; V4L_Scanner *s = handle;
if (-1 == ioctl(s->fd,VIDIOCGWIN,&window)) if (-1 == ioctl (s->fd, VIDIOCGWIN, &window))
return SANE_STATUS_INVAL; return SANE_STATUS_INVAL;
parms.pixels_per_line = window.width; parms.pixels_per_line = window.width;
parms.bytes_per_line = window.width; parms.bytes_per_line = window.width;
@ -953,7 +949,7 @@ sane_start (SANE_Handle handle)
int len; int len;
V4L_Scanner *s; V4L_Scanner *s;
DBG(2, "sane_start\n"); DBG (2, "sane_start\n");
for (s = first_handle; s; s = s->next) for (s = first_handle; s; s = s->next)
{ {
if (s == handle) if (s == handle)
@ -964,18 +960,19 @@ sane_start (SANE_Handle handle)
DBG (1, "sane_start: bad handle %p\n", handle); DBG (1, "sane_start: bad handle %p\n", handle);
return SANE_STATUS_INVAL; /* oops, not a handle we know about */ return SANE_STATUS_INVAL; /* oops, not a handle we know about */
} }
len = ioctl(v4ldev,VIDIOCGCAP,&capability); len = ioctl (v4ldev, VIDIOCGCAP, &capability);
if (-1 == len) if (-1 == len)
DBG (1, "sane_start: can not get capabilities\n"); DBG (1, "sane_start: can not get capabilities\n");
buffercount = 0; buffercount = 0;
if (-1 == ioctl(s->fd,VIDIOCGMBUF,&ov_mbuf)) if (-1 == ioctl (s->fd, VIDIOCGMBUF, &ov_mbuf))
{ {
s->mmap = FALSE; s->mmap = FALSE;
buffer = malloc(capability.maxwidth * capability.maxheight * pict.depth); buffer =
malloc (capability.maxwidth * capability.maxheight * pict.depth);
if (0 == buffer) if (0 == buffer)
return SANE_STATUS_NO_MEM; return SANE_STATUS_NO_MEM;
DBG (2, "sane_start: V4L READING Frame\n"); DBG (2, "sane_start: V4L READING Frame\n");
len = read (s->fd,buffer,parms.bytes_per_line * parms.lines); len = read (s->fd, buffer, parms.bytes_per_line * parms.lines);
DBG (2, "sane_start: V4L Frame read\n"); DBG (2, "sane_start: V4L Frame read\n");
} }
else else
@ -984,7 +981,8 @@ sane_start (SANE_Handle handle)
DBG (2, "sane_start: MMAP Frame\n"); DBG (2, "sane_start: MMAP Frame\n");
DBG (2, "sane_start: Buffersize %d , Buffers %d , Offset %p\n", DBG (2, "sane_start: Buffersize %d , Buffers %d , Offset %p\n",
ov_mbuf.size, ov_mbuf.frames, ov_mbuf.offsets); ov_mbuf.size, ov_mbuf.frames, ov_mbuf.offsets);
buffer = mmap (0,ov_mbuf.size,PROT_READ|PROT_WRITE,MAP_SHARED,s->fd,0); buffer =
mmap (0, ov_mbuf.size, PROT_READ | PROT_WRITE, MAP_SHARED, s->fd, 0);
DBG (2, "sane_start: MMAPed Frame, Capture 1 Pict into %p\n", buffer); DBG (2, "sane_start: MMAPed Frame, Capture 1 Pict into %p\n", buffer);
gb.frame = 0; gb.frame = 0;
gb.width = window.width; gb.width = window.width;
@ -992,16 +990,17 @@ sane_start (SANE_Handle handle)
gb.height = window.height; gb.height = window.height;
gb.height = parms.lines; gb.height = parms.lines;
gb.format = pict.palette; gb.format = pict.palette;
DBG (2,"sane_start: MMAPed Frame %d x %d with Palette %d\n", DBG (2, "sane_start: MMAPed Frame %d x %d with Palette %d\n",
gb.width,gb.height,gb.format); gb.width, gb.height, gb.format);
len = ioctl(v4ldev,VIDIOCMCAPTURE,&gb); len = ioctl (v4ldev, VIDIOCMCAPTURE, &gb);
DBG (2, "sane_start: mmap-result %d\n",len); DBG (2, "sane_start: mmap-result %d\n", len);
DBG (2, "sane_start: Frame %x\n",gb.frame); DBG (2, "sane_start: Frame %x\n", gb.frame);
#if 0 #if 0
len = ioctl(v4ldev,VIDIOCSYNC,&(gb.frame)); len = ioctl (v4ldev, VIDIOCSYNC, &(gb.frame));
if (-1 == len) if (-1 == len)
{ {
DBG (1, "sane_start: Call to ioctl(%d, VIDIOCSYNC, ..) failed\n", v4ldev); DBG (1, "sane_start: Call to ioctl(%d, VIDIOCSYNC, ..) failed\n",
v4ldev);
return SANE_STATUS_INVAL; return SANE_STATUS_INVAL;
} }
#endif #endif
@ -1011,10 +1010,10 @@ sane_start (SANE_Handle handle)
} }
SANE_Status SANE_Status
sane_read (SANE_Handle handle, SANE_Byte *buf, SANE_Int max_len, sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len,
SANE_Int *lenp) SANE_Int * lenp)
{ {
int i,min; int i, min;
V4L_Scanner *s = handle; V4L_Scanner *s = handle;
if ((buffercount + 1) > (parms.lines * parms.bytes_per_line)) if ((buffercount + 1) > (parms.lines * parms.bytes_per_line))
@ -1027,20 +1026,20 @@ sane_read (SANE_Handle handle, SANE_Byte *buf, SANE_Int max_len,
min = (max_len + buffercount); min = (max_len + buffercount);
if (s->mmap == FALSE) if (s->mmap == FALSE)
{ {
for (i=buffercount;i<(min+0);i++) for (i = buffercount; i < (min + 0); i++)
{ {
*(buf + i - buffercount) = *(buffer +i); *(buf + i - buffercount) = *(buffer + i);
}; };
*lenp = (parms.lines * parms.bytes_per_line - buffercount); *lenp = (parms.lines * parms.bytes_per_line - buffercount);
if (max_len < *lenp) if (max_len < *lenp)
*lenp = max_len; *lenp = max_len;
buffercount = i ; buffercount = i;
} }
else else
{ {
for (i=buffercount;i<(min+0);i++) for (i = buffercount; i < (min + 0); i++)
{ {
*(buf + i - buffercount) = *(buffer +i); *(buf + i - buffercount) = *(buffer + i);
/*switch (i % 3) /*switch (i % 3)
{ {
case 0: case 0:
@ -1051,13 +1050,13 @@ sane_read (SANE_Handle handle, SANE_Byte *buf, SANE_Int max_len,
break; break;
case 2: case 2:
*(buf + i - buffercount) = *(buffer + i - 0); *(buf + i - buffercount) = *(buffer + i - 0);
};*/ }; */
}; };
*lenp = (parms.lines * parms.bytes_per_line - buffercount); *lenp = (parms.lines * parms.bytes_per_line - buffercount);
if ((i - buffercount) < *lenp) if ((i - buffercount) < *lenp)
*lenp = (i-buffercount); *lenp = (i - buffercount);
/* syslog(LOG_NOTICE,"Transfering %d Bytes",*lenp); /* syslog(LOG_NOTICE,"Transfering %d Bytes",*lenp);
syslog(LOG_NOTICE,"Transfering from Byte %d to Byte %d",buffercount,i);*/ syslog(LOG_NOTICE,"Transfering from Byte %d to Byte %d",buffercount,i); */
buffercount = i; buffercount = i;
} }
return SANE_STATUS_GOOD; return SANE_STATUS_GOOD;
@ -1069,7 +1068,7 @@ sane_cancel (SANE_Handle handle)
V4L_Scanner *s = handle; V4L_Scanner *s = handle;
if ((buffer != 0) && (s->mmap == FALSE)) if ((buffer != 0) && (s->mmap == FALSE))
free(buffer); free (buffer);
buffer = 0; buffer = 0;
} }

Wyświetl plik

@ -50,25 +50,25 @@
#ifndef v4l_h #ifndef v4l_h
#define v4l_h #define v4l_h
#include <sane/sane.h> #include <../include/sane/sane.h>
typedef enum typedef enum
{ {
V4L_MONO = 0x01, V4L_MONO = 0x01,
V4L_COLOR = 0x10 V4L_COLOR = 0x10
} }
V4L_Model; V4L_Model;
typedef enum typedef enum
{ {
V4L_RES_LOW = 0, V4L_RES_LOW = 0,
V4L_RES_HIGH V4L_RES_HIGH
} }
V4L_Resolution; V4L_Resolution;
/* commands common to all quick-cameras: */ /* commands common to all quick-cameras: */
typedef enum typedef enum
{ {
V4L_SEND_VIDEO_FRAME = 7, V4L_SEND_VIDEO_FRAME = 7,
V4L_SET_BRIGHTNESS = 11, V4L_SET_BRIGHTNESS = 11,
V4L_SET_TOP = 13, V4L_SET_TOP = 13,
@ -81,29 +81,29 @@ typedef enum
V4L_SET_SATURATION = 35, V4L_SET_SATURATION = 35,
V4L_SEND_STATUS = 41, V4L_SEND_STATUS = 41,
V4L_SET_SPEED = 45 V4L_SET_SPEED = 45
} }
V4L_Command; V4L_Command;
/* commands for grayscale camera: */ /* commands for grayscale camera: */
typedef enum typedef enum
{ {
V4L_MONO_SET_CONTRAST = 25, V4L_MONO_SET_CONTRAST = 25,
V4L_MONO_AUTO_ADJUST_OFFSET = 27, V4L_MONO_AUTO_ADJUST_OFFSET = 27,
V4L_MONO_GET_OFFSET = 33 V4L_MONO_GET_OFFSET = 33
} }
V4L_Mono_Command; V4L_Mono_Command;
/* commands for color camera: */ /* commands for color camera: */
typedef enum typedef enum
{ {
V4L_COL_LOAD_RAM = 27, V4L_COL_LOAD_RAM = 27,
V4L_COL_SET_HUE = 33, V4L_COL_SET_HUE = 33,
V4L_COL_SET_CONTRAST = 37 V4L_COL_SET_CONTRAST = 37
} }
V4L_Col_Command; V4L_Col_Command;
typedef enum typedef enum
{ {
OPT_NUM_OPTS = 0, OPT_NUM_OPTS = 0,
OPT_MODE_GROUP, OPT_MODE_GROUP,
@ -129,46 +129,46 @@ typedef enum
/* must come last: */ /* must come last: */
NUM_OPTIONS NUM_OPTIONS
} }
V4L_Option; V4L_Option;
typedef union typedef union
{ {
SANE_Word w; SANE_Word w;
SANE_Word *wa; /* word array */ SANE_Word *wa; /* word array */
SANE_String s; SANE_String s;
} }
Option_Value; Option_Value;
typedef enum typedef enum
{ {
V4L_UNIDIR, V4L_UNIDIR,
V4L_BIDIR V4L_BIDIR
} }
V4L_Port_Mode; V4L_Port_Mode;
typedef struct typedef struct
{ {
size_t num_bytes; /* # of bytes to read */ size_t num_bytes; /* # of bytes to read */
V4L_Resolution resolution; /* high-resolution? */ V4L_Resolution resolution; /* high-resolution? */
SANE_Parameters params; /* other parameters */ SANE_Parameters params; /* other parameters */
u_int mode; /* qcam scan code (get video data command) */ u_int mode; /* qcam scan code (get video data command) */
int despeckle; /* apply despeckling filter? */ int despeckle; /* apply despeckling filter? */
} }
V4L_Scan_Request; V4L_Scan_Request;
typedef struct V4L_Device typedef struct V4L_Device
{ {
struct V4L_Device * next; struct V4L_Device *next;
SANE_Device sane; SANE_Device sane;
V4L_Port_Mode port_mode; V4L_Port_Mode port_mode;
int version; /* camera version */ int version; /* camera version */
int lock_fd; /* used for locking protocol */ int lock_fd; /* used for locking protocol */
} }
V4L_Device; V4L_Device;
typedef struct V4L_Scanner typedef struct V4L_Scanner
{ {
struct V4L_Scanner *next; struct V4L_Scanner *next;
SANE_Option_Descriptor opt[NUM_OPTIONS]; SANE_Option_Descriptor opt[NUM_OPTIONS];
@ -188,7 +188,7 @@ typedef struct V4L_Scanner
/* internal state for v4l_readbytes(): */ /* internal state for v4l_readbytes(): */
int readbytes_state; int readbytes_state;
unsigned int saved_bits; unsigned int saved_bits;
} }
V4L_Scanner; V4L_Scanner;
#endif /* v4l_h */ #endif /* v4l_h */