-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfunctions.cpp
More file actions
39 lines (32 loc) · 797 Bytes
/
functions.cpp
File metadata and controls
39 lines (32 loc) · 797 Bytes
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
#include "functions.h"
CPoint rgb2yuv(CPoint rgb)
{
double y = 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2];
double u = -0.169 * rgb[0] - 0.331 * rgb[1] + 0.5 * rgb[2] + 0.5;
double v = 0.5 * rgb[0] - 0.419 * rgb[1] - 0.081 * rgb[2] + 0.5;
return CPoint(y, u, v);
}
CPoint yuv2rgb(CPoint yuv)
{
double r = yuv[0] + 1.13983 * (yuv[2] - 0.5);
double g = yuv[0] - 0.39465 * (yuv[1] - 0.5) - 0.58060 * (yuv[2] - 0.5);
double b = yuv[0] + 2.03221 * (yuv[1] - 0.5);
return CPoint(r, g, b);
}
int power(int x, int y)
{
int z = 1;
for (int i = 0; i < y; i++)
{
z *= x;
}
return z;
}
double distance(QPoint p, QPoint q)
{
return sqrt((p.rx() - q.rx()) * (p.rx() - q.rx()) + (p.ry() - q.ry()) * (p.ry() - q.ry()));
}
double distance(CPoint p, CPoint q)
{
return (p - q).norm();
}