-
Notifications
You must be signed in to change notification settings - Fork 87
/
dec_rgb.c
135 lines (103 loc) · 2.67 KB
/
dec_rgb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* fswebcam - Small and simple webcam for *nix */
/*============================================================*/
/* Copyright (C)2005-2011 Philip Heron <phil@sanslogic.co.uk> */
/* */
/* This program is distributed under the terms of the GNU */
/* General Public License, version 2. You may use, modify, */
/* and redistribute it under the terms of this license. A */
/* copy should be included with this source. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdint.h>
#include "fswebcam.h"
#include "src.h"
int fswc_add_image_rgb32(src_t *src, avgbmp_t *abitmap)
{
uint8_t *img = (uint8_t *) src->img;
uint32_t p, i = src->width * src->height * 4;
if(src->length < i) return(-1);
for(p = 0; p < i; p += 4)
{
abitmap[0] += img[0];
abitmap[1] += img[1];
abitmap[2] += img[2];
abitmap += 3;
img += 4;
}
return(0);
}
int fswc_add_image_bgr32(src_t *src, avgbmp_t *abitmap)
{
uint8_t *img = (uint8_t *) src->img;
uint32_t p, i = src->width * src->height * 4;
if(src->length < i) return(-1);
for(p = 0; p < i; p += 4)
{
abitmap[0] += img[2];
abitmap[1] += img[1];
abitmap[2] += img[0];
abitmap += 3;
img += 4;
}
return(0);
}
int fswc_add_image_rgb24(src_t *src, avgbmp_t *abitmap)
{
uint8_t *img = (uint8_t *) src->img;
uint32_t i = src->width * src->height * 3;
if(src->length < i) return(-1);
while(i-- > 0) *(abitmap++) += *(img++);
return(0);
}
int fswc_add_image_bgr24(src_t *src, avgbmp_t *abitmap)
{
uint8_t *img = (uint8_t *) src->img;
uint32_t p, i = src->width * src->height * 3;
if(src->length < i) return(-1);
for(p = 0; p < src->length; p += 3)
{
abitmap[0] += img[2];
abitmap[1] += img[1];
abitmap[2] += img[0];
abitmap += 3;
img += 3;
}
return(0);
}
int fswc_add_image_rgb565(src_t *src, avgbmp_t *abitmap)
{
uint16_t *img = (uint16_t *) src->img;
uint32_t i = src->width * src->height;
if(src->length >> 1 < i) return(-1);
while(i-- > 0)
{
uint8_t r, g, b;
r = (*img & 0xF800) >> 8;
g = (*img & 0x7E0) >> 3;
b = (*img & 0x1F) << 3;
*(abitmap++) += r + (r >> 5);
*(abitmap++) += g + (g >> 6);
*(abitmap++) += b + (b >> 5);
img++;
}
return(0);
}
int fswc_add_image_rgb555(src_t *src, avgbmp_t *abitmap)
{
uint16_t *img = (uint16_t *) src->img;
uint32_t i = src->width * src->height;
if(src->length >> 1 < i) return(-1);
while(i-- > 0)
{
uint8_t r, g, b;
r = (*img & 0x7C00) >> 7;
g = (*img & 0x3E0) >> 2;
b = (*img & 0x1F) << 3;
*(abitmap++) += r + (r >> 5);
*(abitmap++) += g + (g >> 5);
*(abitmap++) += b + (b >> 5);
img++;
}
return(0);
}