]> git.sesse.net Git - kdenlive/blob - src/v4l/dec_rgb.c
Stopmotion widget: Improved webcam support, taken from the fswebcam project
[kdenlive] / src / v4l / dec_rgb.c
1 /* fswebcam - Small and simple webcam for *nix                */
2 /*============================================================*/
3 /* Copyright (C)2005-2010 Philip Heron <phil@sanslogic.co.uk> */
4 /*                                                            */
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.                  */
9
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
13
14 #include <stdint.h>
15 #include "src.h"
16
17 int fswc_add_image_rgb32(src_t *src, avgbmp_t *abitmap)
18 {
19         uint8_t *img = (uint8_t *) src->img;
20         uint32_t i = src->width * src->height;
21         
22         if(src->length << 2 < i) return(-1);
23         
24         while(i-- > 0)
25         {
26                 *(abitmap++) += *(img++);
27                 *(abitmap++) += *(img++);
28                 *(abitmap++) += *(img++);
29                 img++;
30         }
31         
32         return(0);
33 }
34
35 int fswc_add_image_bgr32(src_t *src, avgbmp_t *abitmap)
36 {
37         uint8_t *img = (uint8_t *) src->img;
38         uint32_t p, i = src->width * src->height;
39         
40         if(src->length << 2 < i) return(-1);
41         
42         for(p = 0; p < i; p += 4)
43         {
44                 abitmap[0] += img[2];
45                 abitmap[1] += img[1];
46                 abitmap[2] += img[0];
47                 abitmap += 3;
48                 img += 4;
49         }
50         
51         return(0);
52 }
53
54 int fswc_add_image_rgb24(src_t *src, avgbmp_t *abitmap)
55 {
56         uint8_t *img = (uint8_t *) src->img;
57         uint32_t i = src->width * src->height * 3;
58         
59         if(src->length < i) return(-1);
60         while(i-- > 0) *(abitmap++) += *(img++);
61         
62         return(0);
63 }
64
65 int fswc_add_image_bgr24(src_t *src, avgbmp_t *abitmap)
66 {
67         uint8_t *img = (uint8_t *) src->img;
68         uint32_t p, i = src->width * src->height * 3;
69         
70         if(src->length < i) return(-1);
71         
72         for(p = 0; p < src->length; p += 3)
73         {
74                 abitmap[0] += img[2];
75                 abitmap[1] += img[1];
76                 abitmap[2] += img[0];
77                 abitmap += 3;
78                 img += 3;
79         }
80         
81         return(0);
82 }
83
84 int fswc_add_image_rgb565(src_t *src, avgbmp_t *abitmap)
85 {
86         uint16_t *img = (uint16_t *) src->img;
87         uint32_t i = src->width * src->height;
88         
89         if(src->length >> 1 < i) return(-1);
90         
91         while(i-- > 0)
92         {
93                 uint8_t r, g, b;
94                 
95                 r = (*img & 0xF800) >> 8;
96                 g = (*img &  0x7E0) >> 3;
97                 b = (*img &   0x1F) << 3;
98                 
99                 *(abitmap++) += r + (r >> 5);
100                 *(abitmap++) += g + (g >> 6);
101                 *(abitmap++) += b + (b >> 5);
102                 
103                 img++;
104         }
105         
106         return(0);
107 }
108
109 int fswc_add_image_rgb555(src_t *src, avgbmp_t *abitmap)
110 {
111         uint16_t *img = (uint16_t *) src->img;
112         uint32_t i = src->width * src->height;
113         
114         if(src->length >> 1 < i) return(-1);
115         
116         while(i-- > 0)
117         {
118                 uint8_t r, g, b;
119                 
120                 r = (*img & 0x7C00) >> 7;
121                 g = (*img &  0x3E0) >> 2;
122                 b = (*img &   0x1F) << 3;
123                 
124                 *(abitmap++) += r + (r >> 5);
125                 *(abitmap++) += g + (g >> 5);
126                 *(abitmap++) += b + (b >> 5);
127                 
128                 img++;
129         }
130         
131         return(0);
132 }
133