]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-libkmsxx.git/blob - libkmstest/color.cpp
b5b90019646b6b244bf5b70e1c5495cae8acecc0
[android/external-libkmsxx.git] / libkmstest / color.cpp
1 #include "color.h"
3 namespace kms
4 {
5 RGB::RGB()
6 {
7         r = g = b = a = 0;
8 }
10 RGB::RGB(uint8_t r, uint8_t g, uint8_t b)
11 {
12         this->r = r;
13         this->g = g;
14         this->b = b;
15         this->a = 0;
16 }
18 uint16_t RGB::rgb565() const
19 {
20         uint16_t r = (this->r >> 3) << 11;
21         uint16_t g = (this->g >> 2) << 5;
22         uint16_t b = (this->b >> 3) << 0;
23         return r | g | b;
24 }
26 YUV RGB::yuv() const
27 {
28         return YUV(*this);
29 }
32 YUV::YUV()
33 {
34         y = u = v = a = 0;
35 }
37 YUV::YUV(uint8_t y, uint8_t u, uint8_t v)
38 {
39         this->y = y;
40         this->u = u;
41         this->v = v;
42         this->a = 0;
43 }
45 static inline uint8_t MAKE_YUV_601_Y(uint8_t r, uint8_t g, uint8_t b)
46 {
47         return (((66 * r + 129 * g +  25 * b + 128) >> 8) + 16);
48 }
50 static inline uint8_t MAKE_YUV_601_U(uint8_t r, uint8_t g, uint8_t b)
51 {
52         return (((-38 * r -  74 * g + 112 * b + 128) >> 8) + 128);
53 }
55 static inline uint8_t MAKE_YUV_601_V(uint8_t r, uint8_t g, uint8_t b)
56 {
57         return (((112 * r -  94 * g -  18 * b + 128) >> 8) + 128);
58 }
60 YUV::YUV(const RGB& rgb)
61 {
62         this->y = MAKE_YUV_601_Y(rgb.r, rgb.g, rgb.b);
63         this->u = MAKE_YUV_601_U(rgb.r, rgb.g, rgb.b);
64         this->v = MAKE_YUV_601_V(rgb.r, rgb.g, rgb.b);
65         this->a = rgb.a;
66 }
67 }