]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-libkmsxx.git/blob - libkms++util/color.cpp
kmsprint: print plane formats
[android/external-libkmsxx.git] / libkms++util / 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         :RGB(255, r, g, b)
13 {
14 }
16 RGB::RGB(uint8_t a, uint8_t r, uint8_t g, uint8_t b)
17 {
18         this->r = r;
19         this->g = g;
20         this->b = b;
21         this->a = a;
22 }
24 RGB::RGB(uint32_t argb)
25 {
26         this->b = (argb >> 0) & 0xff;
27         this->g = (argb >> 8) & 0xff;
28         this->r = (argb >> 16) & 0xff;
29         this->a = (argb >> 24) & 0xff;
30 }
32 uint32_t RGB::rgb888() const
33 {
34         return (r << 16) | (g << 8) | (b << 0);
35 }
37 uint32_t RGB::argb8888() const
38 {
39         return (a << 24) | (r << 16) | (g << 8) | (b << 0);
40 }
42 uint32_t RGB::abgr8888() const
43 {
44         return (a << 24) | (b << 16) | (g << 8) | (r << 0);
45 }
47 uint16_t RGB::rgb565() const
48 {
49         return ((r >> 3) << 11) | ((g >> 2) << 5) | ((b >> 3) << 0);
50 }
52 YUV RGB::yuv() const
53 {
54         return YUV(*this);
55 }
58 YUV::YUV()
59 {
60         y = u = v = a = 0;
61 }
63 YUV::YUV(uint8_t y, uint8_t u, uint8_t v)
64 {
65         this->y = y;
66         this->u = u;
67         this->v = v;
68         this->a = 0;
69 }
71 static inline uint8_t MAKE_YUV_601_Y(uint8_t r, uint8_t g, uint8_t b)
72 {
73         return (((66 * r + 129 * g +  25 * b + 128) >> 8) + 16);
74 }
76 static inline uint8_t MAKE_YUV_601_U(uint8_t r, uint8_t g, uint8_t b)
77 {
78         return (((-38 * r -  74 * g + 112 * b + 128) >> 8) + 128);
79 }
81 static inline uint8_t MAKE_YUV_601_V(uint8_t r, uint8_t g, uint8_t b)
82 {
83         return (((112 * r -  94 * g -  18 * b + 128) >> 8) + 128);
84 }
86 YUV::YUV(const RGB& rgb)
87 {
88         this->y = MAKE_YUV_601_Y(rgb.r, rgb.g, rgb.b);
89         this->u = MAKE_YUV_601_U(rgb.r, rgb.g, rgb.b);
90         this->v = MAKE_YUV_601_V(rgb.r, rgb.g, rgb.b);
91         this->a = rgb.a;
92 }
93 }