]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-libkmsxx.git/blob - libkmstest/color.cpp
libkmstest: disable draw perf prints
[android/external-libkmsxx.git] / libkmstest / color.cpp
1 #include "color.h"
3 namespace kms
4 {
5 RGB::RGB()
6 {
7         r = g = b = 0;
8         a = 255;
9 }
11 RGB::RGB(uint8_t r, uint8_t g, uint8_t b)
12 {
13         this->r = r;
14         this->g = g;
15         this->b = b;
16         this->a = 255;
17 }
19 uint32_t RGB::rgb888() const
20 {
21         return (a << 24) | (r << 16) | (g << 8) | (b << 0);
22 }
24 uint32_t RGB::bgr888() const
25 {
26         return (a << 24) | (b << 16) | (g << 8) | (r << 0);
27 }
29 uint16_t RGB::rgb565() const
30 {
31         return ((r >> 3) << 11) | ((g >> 2) << 5) | ((b >> 3) << 0);
32 }
34 YUV RGB::yuv() const
35 {
36         return YUV(*this);
37 }
40 YUV::YUV()
41 {
42         y = u = v = a = 0;
43 }
45 YUV::YUV(uint8_t y, uint8_t u, uint8_t v)
46 {
47         this->y = y;
48         this->u = u;
49         this->v = v;
50         this->a = 0;
51 }
53 static inline uint8_t MAKE_YUV_601_Y(uint8_t r, uint8_t g, uint8_t b)
54 {
55         return (((66 * r + 129 * g +  25 * b + 128) >> 8) + 16);
56 }
58 static inline uint8_t MAKE_YUV_601_U(uint8_t r, uint8_t g, uint8_t b)
59 {
60         return (((-38 * r -  74 * g + 112 * b + 128) >> 8) + 128);
61 }
63 static inline uint8_t MAKE_YUV_601_V(uint8_t r, uint8_t g, uint8_t b)
64 {
65         return (((112 * r -  94 * g -  18 * b + 128) >> 8) + 128);
66 }
68 YUV::YUV(const RGB& rgb)
69 {
70         this->y = MAKE_YUV_601_Y(rgb.r, rgb.g, rgb.b);
71         this->u = MAKE_YUV_601_U(rgb.r, rgb.g, rgb.b);
72         this->v = MAKE_YUV_601_V(rgb.r, rgb.g, rgb.b);
73         this->a = rgb.a;
74 }
75 }