1 /* fswebcam - Small and simple webcam for *nix */
2 /*============================================================*/
3 /* Copyright (C)2005-2010 Philip Heron <phil@sanslogic.co.uk> */
5 /* This program is distributed under the terms of the GNU */
6 /* General Public License, version 2. You may use, modify, */
7 /* and redistribute it under the terms of this license. A */
8 /* copy should be included with this source. */
17 int fswc_add_image_rgb32(src_t *src, avgbmp_t *abitmap)
19 uint8_t *img = (uint8_t *) src->img;
20 uint32_t i = src->width * src->height;
22 if(src->length << 2 < i) return(-1);
26 *(abitmap++) += *(img++);
27 *(abitmap++) += *(img++);
28 *(abitmap++) += *(img++);
35 int fswc_add_image_bgr32(src_t *src, avgbmp_t *abitmap)
37 uint8_t *img = (uint8_t *) src->img;
38 uint32_t p, i = src->width * src->height;
40 if(src->length << 2 < i) return(-1);
42 for(p = 0; p < i; p += 4)
54 int fswc_add_image_rgb24(src_t *src, avgbmp_t *abitmap)
56 uint8_t *img = (uint8_t *) src->img;
57 uint32_t i = src->width * src->height * 3;
59 if(src->length < i) return(-1);
60 while(i-- > 0) *(abitmap++) += *(img++);
65 int fswc_add_image_bgr24(src_t *src, avgbmp_t *abitmap)
67 uint8_t *img = (uint8_t *) src->img;
68 uint32_t p, i = src->width * src->height * 3;
70 if(src->length < i) return(-1);
72 for(p = 0; p < src->length; p += 3)
84 int fswc_add_image_rgb565(src_t *src, avgbmp_t *abitmap)
86 uint16_t *img = (uint16_t *) src->img;
87 uint32_t i = src->width * src->height;
89 if(src->length >> 1 < i) return(-1);
95 r = (*img & 0xF800) >> 8;
96 g = (*img & 0x7E0) >> 3;
97 b = (*img & 0x1F) << 3;
99 *(abitmap++) += r + (r >> 5);
100 *(abitmap++) += g + (g >> 6);
101 *(abitmap++) += b + (b >> 5);
109 int fswc_add_image_rgb555(src_t *src, avgbmp_t *abitmap)
111 uint16_t *img = (uint16_t *) src->img;
112 uint32_t i = src->width * src->height;
114 if(src->length >> 1 < i) return(-1);
120 r = (*img & 0x7C00) >> 7;
121 g = (*img & 0x3E0) >> 2;
122 b = (*img & 0x1F) << 3;
124 *(abitmap++) += r + (r >> 5);
125 *(abitmap++) += g + (g >> 5);
126 *(abitmap++) += b + (b >> 5);