Changeset 778 for libcaca/trunk/cucul/colour.c
- Timestamp:
- Apr 16, 2006, 11:26:25 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/colour.c
r769 r778 27 27 0xf444, 0xf44f, 0xf4f4, 0xf4ff, 0xff44, 0xff4f, 0xfff4, 0xffff, 28 28 }; 29 30 /** \brief Set the default colour pair. 31 * 32 * This function sets the default ANSI colour pair. String functions such as 33 * caca_printf() and graphical primitive functions such as caca_draw_line() 34 * will use these colours. 35 * 36 * Color values are those defined in \e cucul.h, such as CUCUL_COLOR_RED 37 * or CUCUL_COLOR_TRANSPARENT. 38 * 39 * \param qq A handle to the libcucul canvas. 40 * \param fg The requested foreground colour. 41 * \param bg The requested background colour. 42 */ 43 void cucul_set_color(cucul_t *qq, unsigned char fg, unsigned char bg) 44 { 45 if(fg > 0x20 || bg > 0x20) 46 return; 47 48 qq->fgcolor = fg; 49 qq->bgcolor = bg; 50 } 51 52 /** \brief Set the default colour pair (truecolor version). 53 * 54 * This function sets the default colour pair. String functions such as 55 * caca_printf() and graphical primitive functions such as caca_draw_line() 56 * will use these colours. 57 * 58 * Colors are 16-bit ARGB values, each component being coded on 4 bits. For 59 * instance, 0xf088 is solid dark cyan (A=15 R=0 G=8 B=8), and 0x8fff is 60 * white with 50% alpha (A=8 R=15 G=15 B=15). 61 * 62 * \param qq A handle to the libcucul canvas. 63 * \param fg The requested foreground colour. 64 * \param bg The requested background colour. 65 */ 66 void cucul_set_truecolor(cucul_t *qq, unsigned int fg, unsigned int bg) 67 { 68 if(fg > 0xffff || bg > 0xffff) 69 return; 70 71 if(fg < 0x100) 72 fg += 0x100; 73 74 if(bg < 0x100) 75 bg += 0x100; 76 77 qq->fgcolor = fg; 78 qq->bgcolor = bg; 79 } 80 81 /* 82 * XXX: the following functions are local 83 */ 29 84 30 85 static uint8_t nearest_ansi(uint16_t argb16, uint8_t def) … … 89 144 } 90 145 146 uint16_t _cucul_argb32_to_rgb12fg(uint32_t c) 147 { 148 uint16_t fg = c & 0xffff; 149 150 if(fg < CUCUL_COLOR_DEFAULT) 151 return ansitab[fg] & 0x0fff; 152 153 if(fg == CUCUL_COLOR_DEFAULT) 154 return ansitab[CUCUL_COLOR_LIGHTGRAY] & 0x0fff; 155 156 if(fg == CUCUL_COLOR_TRANSPARENT) 157 return 0x0fff; 158 159 return fg & 0x0fff; 160 } 161 162 uint16_t _cucul_argb32_to_rgb12bg(uint32_t c) 163 { 164 uint16_t bg = c >> 16; 165 166 if(bg < CUCUL_COLOR_DEFAULT) 167 return ansitab[bg] & 0x0fff; 168 169 if(bg == CUCUL_COLOR_DEFAULT) 170 return ansitab[CUCUL_COLOR_BLACK] & 0x0fff; 171 172 if(bg == CUCUL_COLOR_TRANSPARENT) 173 return 0x0fff; 174 175 return bg & 0x0fff; 176 } 177 91 178 void _cucul_argb32_to_argb4(uint32_t c, uint8_t argb[8]) 92 179 {
Note: See TracChangeset
for help on using the changeset viewer.