mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
Kandinsky: Introduce KDColorRGB
Change-Id: Ic64f2ff9a441580940d37151e190fd0a3d954d8a
This commit is contained in:
@@ -8,7 +8,10 @@ objs += $(addprefix kandinsky/src/,\
|
||||
text.o\
|
||||
types.o\
|
||||
)
|
||||
tests += $(addprefix kandinsky/test/, set_pixel.c)
|
||||
tests += $(addprefix kandinsky/test/,\
|
||||
color.c\
|
||||
set_pixel.c\
|
||||
)
|
||||
|
||||
FREETYPE_PATH := /usr/local/Cellar/freetype/2.6.3
|
||||
# LIBPNG_PATH is optional. If LIBPNG_PATH is not defined, rasterizer will be
|
||||
|
||||
@@ -3,8 +3,21 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Kandinsky uses RGB565
|
||||
|
||||
typedef uint16_t KDColor;
|
||||
|
||||
#define KDColorRGB(r,g,b) ((KDColor)(((r&0x1F)<<11)&((g&0x3F)<<5)&(b&0x1F)))
|
||||
/* KDColorRGB takes a 32-bits RGB color and builds a KDColor from it.
|
||||
* Given KDColor is RGB565 and that we take 8-bit values for R, G, and B,
|
||||
* some shifting has to happen. */
|
||||
|
||||
#define KDColorRGB(r,g,b) ((KDColor)((((((uint16_t)(r))>>3)&0x1F)<<11)|(((((uint16_t)(g))>>2)&0x3F)<<5)|((((uint16_t)(b))>>3)&0x1F)))
|
||||
|
||||
#define KDColorBlack KDColorRGB(0x00, 0x00, 0x00)
|
||||
#define KDColorWhite KDColorRGB(0xFF, 0xFF, 0xFF)
|
||||
|
||||
#define KDColorRed KDColorRGB(0xFF, 0x00, 0x00)
|
||||
#define KDColorGreen KDColorRGB(0x00, 0xFF, 0x00)
|
||||
#define KDColorBlue KDColorRGB(0x00, 0x00, 0xFF)
|
||||
|
||||
#endif
|
||||
|
||||
18
kandinsky/test/color.c
Normal file
18
kandinsky/test/color.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <quiz.h>
|
||||
#include <kandinsky.h>
|
||||
#include <assert.h>
|
||||
|
||||
QUIZ_CASE(kandinsky_color_rgb) {
|
||||
KDColor foo = KDColorRGB(0xFF, 0, 0);
|
||||
assert(KDColorRGB(0xFF, 0, 0) == 0xF800);
|
||||
assert(KDColorRGB(0, 0xFF, 0) == 0x07E0);
|
||||
assert(KDColorRGB(0, 0, 0xFF) == 0x1F);
|
||||
/* R = 0x12 = 0b 0001 0010. 5 most important bits are 00010.
|
||||
* G = 0x34 = 0b 0011 0100. 6 most important bits are 001101.
|
||||
* B = 0x56 = 0b 0101 0110. 5 most important bits are 01010.
|
||||
* KDColor = 0b 00010 001101 01010
|
||||
* = 0b 0001 0001 1010 1010
|
||||
* = 0x 1 1 A A */
|
||||
assert(KDColorRGB(0x12, 0x34, 0x56) == 0x11AA);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user