-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcolor_format.hpp
More file actions
39 lines (31 loc) · 828 Bytes
/
color_format.hpp
File metadata and controls
39 lines (31 loc) · 828 Bytes
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
33
34
35
36
37
38
39
#pragma once
#include <cstdint>
namespace color_format {
uint32_t argb8888(uint8_t a, uint8_t r, uint8_t g, uint8_t b)
{
return (a << 24) | (r << 16) | (g << 8) | (b << 0);
}
uint16_t argb4444(uint8_t a, uint8_t r, uint8_t g, uint8_t b)
{
int a4 = (a >> 4) & 15;
int r4 = (r >> 4) & 15;
int g4 = (g >> 4) & 15;
int b4 = (b >> 4) & 15;
return (a4 << 12) | (r4 << 8) | (g4 << 4) | (b4 << 0);
}
uint16_t argb1555(uint8_t a, uint8_t r, uint8_t g, uint8_t b)
{
int a1 = (a >> 7) & 1;
int r5 = (r >> 3) & 31;
int g5 = (g >> 3) & 31;
int b5 = (b >> 3) & 31;
return (a1 << 15) | (r5 << 10) | (g5 << 5) | (b5 << 0);
}
uint16_t rgb565(uint8_t a, uint8_t r, uint8_t g, uint8_t b)
{
int r5 = (r >> 3) & 31;
int g6 = (g >> 2) & 63;
int b5 = (b >> 3) & 31;
return (r5 << 11) | (g6 << 5) | (b5 << 0);
}
}