tools.cpp
1007 字节
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
#include "tools.h"
#define is_leap_year(y) (((y) % 4 == 0 && (y) % 100 != 0) || (y) % 400 == 0)
/* 计算某个日期距1970年1月1日0时0分0秒的秒数 */
time_t calc_sec1970(int Y, int M, int D, int h, int m, int s)
{
int i = 0;
int sec = 0;
int days[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
/* 年计算 */
for (i = 1970; i < Y; i++)
{
if (is_leap_year(i))
sec += 366 * 24 * 60 * 60;
else
sec += 365 * 24 * 60 * 60;
}
/* 月计算 */
for (i = 1; i < M; i++)
{
sec += days[i] * 24 * 60 * 60;
if (i == 2 && is_leap_year(Y))
{
sec += 24 * 60 * 60;
}
}
/* 天计算 */
sec += (D - 1) * 24 * 60 * 60;
/* 时分秒计算 */
sec += h * 60 * 60 + m * 60 + s;
return sec;
}
void RGB2YUV(unsigned char r, unsigned char g, unsigned char b, unsigned char *y, unsigned char * u, unsigned char * v){
*y = (unsigned char)(0.30*r + 0.59*g + 0.11*b);
*u = (unsigned char)(0.493*(b - (*y)));
*v = (unsigned char)(0.877*(r - (*y)));
}