]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-libkmsxx.git/blob - libkmstest/color.cpp
Add support for YVYU and VYUY
[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 uint32_t RGB::rgb888() const
19 {
20         return (r << 16) | (g << 8) | (b << 0);
21 }
23 uint32_t RGB::bgr888() const
24 {
25         return (b << 16) | (g << 8) | (r << 0);
26 }
28 uint16_t RGB::rgb565() const
29 {
30         return ((r >> 3) << 11) | ((g >> 2) << 5) | ((b >> 3) << 0);
31 }
33 YUV RGB::yuv() const
34 {
35         return YUV(*this);
36 }
39 YUV::YUV()
40 {
41         y = u = v = a = 0;
42 }
44 YUV::YUV(uint8_t y, uint8_t u, uint8_t v)
45 {
46         this->y = y;
47         this->u = u;
48         this->v = v;
49         this->a = 0;
50 }
52 static inline uint8_t MAKE_YUV_601_Y(uint8_t r, uint8_t g, uint8_t b)
53 {
54         return (((66 * r + 129 * g +  25 * b + 128) >> 8) + 16);
55 }
57 static inline uint8_t MAKE_YUV_601_U(uint8_t r, uint8_t g, uint8_t b)
58 {
59         return (((-38 * r -  74 * g + 112 * b + 128) >> 8) + 128);
60 }
62 static inline uint8_t MAKE_YUV_601_V(uint8_t r, uint8_t g, uint8_t b)
63 {
64         return (((112 * r -  94 * g -  18 * b + 128) >> 8) + 128);
65 }
67 YUV::YUV(const RGB& rgb)
68 {
69         this->y = MAKE_YUV_601_Y(rgb.r, rgb.g, rgb.b);
70         this->u = MAKE_YUV_601_U(rgb.r, rgb.g, rgb.b);
71         this->v = MAKE_YUV_601_V(rgb.r, rgb.g, rgb.b);
72         this->a = rgb.a;
73 }
74 }