camera.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. pygame - Python Game Library
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with this library; if not, write to the Free
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. */
  15. #include "pygame.h"
  16. #include "pygamedocs.h"
  17. #if defined(__unix__)
  18. #include <structmember.h>
  19. #include <stringobject.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <assert.h>
  24. #include <fcntl.h> /* low-level i/o */
  25. #include <unistd.h>
  26. #include <errno.h>
  27. #include <sys/stat.h>
  28. #include <sys/types.h>
  29. #include <sys/time.h>
  30. #include <sys/mman.h>
  31. #include <sys/ioctl.h>
  32. /* in Linux it is not needed, and in kfreebsd it does not exists */
  33. /* #include <asm/types.h> for videodev2.h */
  34. #include <linux/videodev2.h>
  35. #endif
  36. #define CLEAR(x) memset (&(x), 0, sizeof (x))
  37. #define SAT(c) if (c & (~255)) { if (c < 0) c = 0; else c = 255; }
  38. #define SAT2(c) ((c) & (~255) ? ((c) < 0 ? 0 : 255) : (c))
  39. #define DEFAULT_WIDTH 640
  40. #define DEFAULT_HEIGHT 480
  41. #define RGB_OUT 1
  42. #define YUV_OUT 2
  43. #define HSV_OUT 4
  44. #define CAM_V4L 1 /* deprecated. the incomplete support in pygame was removed */
  45. #define CAM_V4L2 2
  46. struct buffer
  47. {
  48. void * start;
  49. size_t length;
  50. };
  51. typedef struct
  52. {
  53. PyObject_HEAD
  54. char* device_name;
  55. int camera_type;
  56. unsigned long pixelformat;
  57. unsigned int color_out;
  58. struct buffer* buffers;
  59. unsigned int n_buffers;
  60. int width;
  61. int height;
  62. int size;
  63. int hflip;
  64. int vflip;
  65. int brightness;
  66. int fd;
  67. } PyCameraObject;
  68. /* internal functions for colorspace conversion */
  69. void colorspace (SDL_Surface *src, SDL_Surface *dst, int cspace);
  70. void rgb24_to_rgb (const void* src, void* dst, int length, SDL_PixelFormat* format);
  71. void rgb444_to_rgb (const void* src, void* dst, int length, SDL_PixelFormat* format);
  72. void rgb_to_yuv (const void* src, void* dst, int length,
  73. unsigned long source, SDL_PixelFormat* format);
  74. void rgb_to_hsv (const void* src, void* dst, int length,
  75. unsigned long source, SDL_PixelFormat* format);
  76. void yuyv_to_rgb (const void* src, void* dst, int length, SDL_PixelFormat* format);
  77. void yuyv_to_yuv (const void* src, void* dst, int length, SDL_PixelFormat* format);
  78. void sbggr8_to_rgb (const void* src, void* dst, int width, int height, SDL_PixelFormat* format);
  79. void yuv420_to_rgb (const void* src, void* dst, int width, int height, SDL_PixelFormat* format);
  80. void yuv420_to_yuv (const void* src, void* dst, int width, int height, SDL_PixelFormat* format);
  81. #if defined(__unix__)
  82. /* internal functions specific to v4l2 */
  83. char** v4l2_list_cameras (int* num_devices);
  84. int v4l2_get_control (int fd, int id, int *value);
  85. int v4l2_set_control (int fd, int id, int value);
  86. PyObject* v4l2_read_raw (PyCameraObject* self);
  87. int v4l2_xioctl (int fd, int request, void *arg);
  88. int v4l2_process_image (PyCameraObject* self, const void *image,
  89. unsigned int buffer_size, SDL_Surface* surf);
  90. int v4l2_query_buffer (PyCameraObject* self);
  91. int v4l2_read_frame (PyCameraObject* self, SDL_Surface* surf);
  92. int v4l2_stop_capturing (PyCameraObject* self);
  93. int v4l2_start_capturing (PyCameraObject* self);
  94. int v4l2_uninit_device (PyCameraObject* self);
  95. int v4l2_init_mmap (PyCameraObject* self);
  96. int v4l2_init_device (PyCameraObject* self);
  97. int v4l2_close_device (PyCameraObject* self);
  98. int v4l2_open_device (PyCameraObject* self);
  99. #endif