-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPixelsTransform.cpp
More file actions
32 lines (28 loc) · 1.17 KB
/
PixelsTransform.cpp
File metadata and controls
32 lines (28 loc) · 1.17 KB
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
#include "PixelsTransform.h"
// TODO: Comment this
RGBPixel* YUVToRGB(YUVPixel *px){
RGBPixel* res = new RGBPixel();
res->red = px->Y + 1.402 * px->Cr - 179.456;
res->green = px->Y - 0.34414 * px->Cb - 0.71414 * px->Cr + 135.45984;
res->blue = px->Y + 1.772 * px->Cb - 226.816;
return res;
}
YUVPixel* RGBToYUV(RGBPixel *px){
YUVPixel* res = new YUVPixel();
res->Y = (77.0 / 256) * px->red + (150.0 / 256) * px->green + (29.0 / 256) * px->blue;
res->Cr = (131.0 / 256) * px->red - (110.0 / 256) * px->green - (21.0 / 256) * px->blue + 128;
res->Cb = -(44.0 / 256) * px->red - (87.0 / 256) * px->green + (131.0 / 256) * px->blue + 128;
return res;
}
YUVPixelSet* RGBSetToYUVSet(RGBPixelSet *rgbSet){
YUVPixelSet *res = new YUVPixelSet(rgbSet->getWidth(), rgbSet->getHeight());
for(int i = 0; i < rgbSet->getSize(); i++)
res->addPixel(*RGBToYUV(rgbSet->getPixel(i)));
return res;
}
RGBPixelSet* YUVSetToRGBSet(YUVPixelSet *yuvSet){
RGBPixelSet *res = new RGBPixelSet(yuvSet->getWidth(), yuvSet->getHeight());
for(int i = 0; i < yuvSet->getSize(); i++)
res->addPixel(*YUVToRGB(yuvSet->getPixel(i)));
return res;
}