You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
2.6 KiB

#ifndef _VIDOILTANK_H_
#define _VIDOILTANK_H_
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <getopt.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <linux/videodev2.h>
#include <stdint.h>
#include <jpeglib.h>
#include <setjmp.h>
#define LEN_FILENAME 1024
enum {
IOM_READ,
IOM_MMAP
};
struct s_rect {
int x;
int y;
int w;
int h;
} typedef Rect;
struct s_image_raw {
unsigned char *data;
int size; // allocated size
int h;
int w;
} typedef ImageRaw;
struct s_image_float {
float *data;
int size; // allocated size
int h;
int w;
} typedef ImageFloat;
struct s_inbuffer {
unsigned char *data;
int size;
};
#define VDEV_INBUFFERS 3
struct s_video {
char devname[LEN_FILENAME];
int fd;
int height; // will be set on start
int width;
int iomode;
struct s_inbuffer inbuffer[VDEV_INBUFFERS];
int inbuffer_idx;
struct jpeg_decompress_struct jpgcinfo;
char format[32];
struct v4l2_capability vcap;
struct v4l2_cropcap cropcap;
struct v4l2_crop crop;
struct v4l2_format fmt;
unsigned int ctrl_bright;
unsigned int ctrl_contrast;
} typedef Video;
//
// jpeg error handling
//
struct jpg_error_mgr {
struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */
};
typedef struct jpg_error_mgr *jpg_error_ptr;
int convert (struct jpeg_decompress_struct *cdata, ImageRaw *dest, unsigned char *ptrsrc, int srcsize, uint32_t pixelformat, int srcw, int srch);
int convertstart(struct jpeg_decompress_struct *cdata, uint32_t pixelformat);
int convertstop(struct jpeg_decompress_struct *cdata, uint32_t pixelformat);
/* image.c
*
*/
ImageRaw *image_alloc (int w, int h);
void image_resize(ImageRaw *i, int w, int h);
int image_save(ImageRaw *i, char *fn, int quality);
void image_rotate (ImageRaw *img, int deg);
void image_draw_pixel (ImageRaw *img, int x, int y, int col);
void image_draw_rect (ImageRaw *img, Rect *r, int col);
ImageFloat *imageF_alloc (int w, int h);
ImageFloat *imageF_copy(ImageRaw *iraw, Rect *r);
ImageRaw *image_copyF(ImageFloat *ifloat);
void imageF_add(ImageFloat *ifloat, ImageRaw *iraw, Rect *r);
void image_get_minmax (ImageRaw *img, Rect *r, int *min, int *max);
/* getvideo.c
*
*/
Video *vid_open(char *device);
int vid_start(Video* video, int ionmode, int width, int height);
ImageRaw *vid_grabimage(Video* video, ImageRaw *img);
int vid_stop(Video* video);
void vid_close(Video* video);
void vid_getctrls (Video* video);
void vid_setctrls (Video* video, int bright, int contrast);
#endif