diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2022-06-19 19:47:51 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2022-06-19 19:47:51 +0530 |
commit | 4fd287655a72b9aea14cdac715ad5b90ed082ed2 (patch) | |
tree | 65d393bc0e699dd12d05b29ba568e04cea666207 /circuitpython/lib/quirc/demo/camera.h | |
parent | 0150f70ce9c39e9e6dd878766c0620c85e47bed0 (diff) |
add circuitpython code
Diffstat (limited to 'circuitpython/lib/quirc/demo/camera.h')
-rw-r--r-- | circuitpython/lib/quirc/demo/camera.h | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/circuitpython/lib/quirc/demo/camera.h b/circuitpython/lib/quirc/demo/camera.h new file mode 100644 index 0000000..511b5bd --- /dev/null +++ b/circuitpython/lib/quirc/demo/camera.h @@ -0,0 +1,104 @@ +/* quirc -- QR-code recognition library + * Copyright (C) 2010-2014 Daniel Beer <dlbeer@gmail.com> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef CAMERA_H_ +#define CAMERA_H_ + +#include <stddef.h> + +#define CAMERA_MAX_BUFFERS 32 + +typedef enum { + CAMERA_FORMAT_UNKNOWN = 0, + CAMERA_FORMAT_MJPEG, + CAMERA_FORMAT_YUYV +} camera_format_t; + +struct camera_parms { + camera_format_t format; + int width; + int height; + int pitch_bytes; + int interval_n; + int interval_d; +}; + +struct camera_buffer { + void *addr; + size_t size; + unsigned long offset; +}; + +struct camera { + int fd; + + struct camera_parms parms; + + struct camera_buffer buf_desc[CAMERA_MAX_BUFFERS]; + int buf_count; + + /* Stream state */ + int s_on; + int s_qc; + int s_qhead; +}; + +/* Initialize/destroy a camera. No resources are allocated. */ +void camera_init(struct camera *c); +void camera_destroy(struct camera *c); + +/* Open/close the camera device */ +int camera_open(struct camera *c, const char *path, + int target_w, int target_h, + int tr_n, int tr_d); +void camera_close(struct camera *c); + +static inline int camera_get_fd(const struct camera *c) +{ + return c->fd; +} + +static inline const struct camera_parms *camera_get_parms + (const struct camera *c) +{ + return &c->parms; +} + +/* Map buffers */ +int camera_map(struct camera *c, int buf_count); +void camera_unmap(struct camera *c); + +static inline int camera_get_buf_count(const struct camera *c) +{ + return c->buf_count; +} + +/* Switch streaming on/off */ +int camera_on(struct camera *c); +void camera_off(struct camera *c); + +/* Enqueue/dequeue buffers (count = 0 means enqueue all) */ +int camera_enqueue_all(struct camera *c); +int camera_dequeue_one(struct camera *c); + +/* Fetch the oldest dequeued buffer */ +static inline const struct camera_buffer *camera_get_head + (const struct camera *c) +{ + return &c->buf_desc[(c->s_qhead + c->buf_count - 1) % c->buf_count]; +} + +#endif |