Changeset 1254
- Timestamp:
- Oct 29, 2006, 1:53:46 AM (14 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca/caca0.h
r1015 r1254 131 131 132 132 #define caca_set_color(x, y) \ 133 (__caca0_fg = (x), __caca0_bg = (y), cucul_set_color(__caca0_cv, x, y)) 133 (__caca0_fg = (x), __caca0_bg = (y), \ 134 cucul_set_attr_ansi(__caca0_cv, x, y, 0)) 134 135 #define caca_get_fg_color() __caca0_fg 135 136 #define caca_get_bg_color() __caca0_bg -
libcaca/trunk/caca/driver_conio.c
r1218 r1254 98 98 { 99 99 char *screen = dp->drv.p->screen; 100 uint32_t *attr = dp->cv->attr;100 uint32_t *attrs = dp->cv->attrs; 101 101 uint32_t *chars = dp->cv->chars; 102 102 unsigned int n; … … 108 108 { 109 109 *screen++ = '['; 110 *screen++ = _cucul_a rgb32_to_ansi8(*attr++);110 *screen++ = _cucul_attr_to_ansi8(*attrs++); 111 111 ch = ']'; 112 112 chars++; … … 114 114 } 115 115 *screen++ = ch; 116 *screen++ = _cucul_a rgb32_to_ansi8(*attr++);116 *screen++ = _cucul_attr_to_ansi8(*attrs++); 117 117 } 118 118 # if defined(SCREENUPDATE_IN_PC_H) -
libcaca/trunk/caca/driver_gl.c
r1233 r1254 215 215 for(y = 0; y < dp->drv.p->height; y += dp->drv.p->font_height) 216 216 { 217 uint32_t *attr = dp->cv->attr+ line * dp->cv->width;217 uint32_t *attrs = dp->cv->attrs + line * dp->cv->width; 218 218 219 219 /* FIXME: optimise using stride */ 220 220 for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width) 221 221 { 222 uint16_t bg = _cucul_a rgb32_to_rgb12bg(*attr++);222 uint16_t bg = _cucul_attr_to_rgb12bg(*attrs++); 223 223 224 224 glColor4b(((bg & 0xf00) >> 8) * 8, … … 245 245 for(y = 0; y < dp->drv.p->height; y += dp->drv.p->font_height, line++) 246 246 { 247 uint32_t *attr = dp->cv->attr+ line * dp->cv->width;247 uint32_t *attrs = dp->cv->attrs + line * dp->cv->width; 248 248 uint32_t *chars = dp->cv->chars + line * dp->cv->width; 249 249 250 for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width, attr ++)250 for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width, attrs++) 251 251 { 252 252 uint32_t ch = *chars++; … … 272 272 - (uint32_t)dp->drv.p->blocks[i]]); 273 273 274 fg = _cucul_a rgb32_to_rgb12fg(*attr);274 fg = _cucul_attr_to_rgb12fg(*attrs); 275 275 glColor3b(((fg & 0xf00) >> 8) * 8, 276 276 ((fg & 0x0f0) >> 4) * 8, … … 292 292 if(fullwidth) 293 293 { 294 chars++; attr ++; x += dp->drv.p->font_width;294 chars++; attrs++; x += dp->drv.p->font_width; 295 295 } 296 296 } -
libcaca/trunk/caca/driver_ncurses.c
r1218 r1254 197 197 { 198 198 int x, y; 199 uint32_t *attr = dp->cv->attr;199 uint32_t *attrs = dp->cv->attrs; 200 200 uint32_t *chars = dp->cv->chars; 201 201 for(y = 0; y < (int)dp->cv->height; y++) … … 204 204 for(x = dp->cv->width; x--; ) 205 205 { 206 attrset(dp->drv.p->attr[_cucul_a rgb32_to_ansi8(*attr++)]);206 attrset(dp->drv.p->attr[_cucul_attr_to_ansi8(*attrs++)]); 207 207 ncurses_write_utf32(*chars++); 208 208 } -
libcaca/trunk/caca/driver_slang.c
r1218 r1254 202 202 { 203 203 int x, y; 204 uint32_t *attr = dp->cv->attr;204 uint32_t *attrs = dp->cv->attrs; 205 205 uint32_t *chars = dp->cv->chars; 206 206 for(y = 0; y < (int)dp->cv->height; y++) … … 218 218 * bright backgrounds, it's just fucked up. */ 219 219 #if 0 220 uint8_t fgcolor = _cucul_a rgb32_to_ansi4fg(*attr);221 uint8_t bgcolor = _cucul_a rgb32_to_ansi4bg(*attr);220 uint8_t fgcolor = _cucul_attr_to_ansi4fg(*attrs); 221 uint8_t bgcolor = _cucul_attr_to_ansi4bg(*attrs); 222 222 223 223 if(fgcolor == bgcolor) … … 232 232 SLsmg_set_color(slang_assoc[fgcolor + 16 * bgcolor]); 233 233 SLsmg_write_char(' '); 234 attr ++;234 attrs++; 235 235 } 236 236 else 237 237 #endif 238 238 { 239 SLsmg_set_color(slang_assoc[_cucul_a rgb32_to_ansi8(*attr++)]);239 SLsmg_set_color(slang_assoc[_cucul_attr_to_ansi8(*attrs++)]); 240 240 slang_write_utf32(ch); 241 241 } 242 242 #else 243 SLsmg_set_color(_cucul_a rgb32_to_ansi8(*attr++));243 SLsmg_set_color(_cucul_attr_to_ansi8(*attrs++)); 244 244 slang_write_utf32(ch); 245 245 #endif -
libcaca/trunk/caca/driver_vga.c
r1218 r1254 116 116 { 117 117 char *screen = (char *)(intptr_t)0x000b8000; 118 uint32_t *attr = dp->cv->attr;118 uint32_t *attrs = dp->cv->attrs; 119 119 uint32_t *chars = dp->cv->chars; 120 120 int n; … … 126 126 { 127 127 *screen++ = '['; 128 *screen++ = _cucul_a rgb32_to_ansi8(*attr++);128 *screen++ = _cucul_attr_to_ansi8(*attrs++); 129 129 ch = ']'; 130 130 chars++; … … 132 132 } 133 133 *screen++ = ch; 134 *screen++ = _cucul_a rgb32_to_ansi8(*attr++);134 *screen++ = _cucul_attr_to_ansi8(*attrs++); 135 135 } 136 136 } -
libcaca/trunk/caca/driver_win32.c
r1233 r1254 191 191 SMALL_RECT rect; 192 192 CHAR_INFO *buffer = dp->drv.p->buffer; 193 uint32_t *attr = dp->cv->attr;193 uint32_t *attrs = dp->cv->attrs; 194 194 uint32_t *chars = dp->cv->chars; 195 195 unsigned int n; … … 215 215 216 216 buffer->Attributes = 217 win32_fg_palette[_cucul_a rgb32_to_ansi4fg(*attr)]218 | win32_bg_palette[_cucul_a rgb32_to_ansi4bg(*attr)];219 attr ++;217 win32_fg_palette[_cucul_attr_to_ansi4fg(*attrs)] 218 | win32_bg_palette[_cucul_attr_to_ansi4bg(*attrs)]; 219 attrs++; 220 220 buffer++; 221 221 } -
libcaca/trunk/caca/driver_x11.c
r1233 r1254 247 247 for(x = 0; x < dp->cv->width; x += len) 248 248 { 249 uint32_t *attr = dp->cv->attr+ x + y * dp->cv->width;250 uint16_t bg = _cucul_a rgb32_to_rgb12bg(*attr);249 uint32_t *attrs = dp->cv->attrs + x + y * dp->cv->width; 250 uint16_t bg = _cucul_attr_to_rgb12bg(*attrs); 251 251 252 252 len = 1; 253 253 while(x + len < dp->cv->width 254 && _cucul_a rgb32_to_rgb12bg(attr[len]) == bg)254 && _cucul_attr_to_rgb12bg(attrs[len]) == bg) 255 255 len++; 256 256 … … 272 272 for(x = 0; x < dp->cv->width; x++, chars++) 273 273 { 274 uint32_t *attr = dp->cv->attr+ x + y * dp->cv->width;274 uint32_t *attrs = dp->cv->attrs + x + y * dp->cv->width; 275 275 276 276 /* Skip spaces */ … … 282 282 283 283 XSetForeground(dp->drv.p->dpy, dp->drv.p->gc, 284 dp->drv.p->colors[_cucul_a rgb32_to_rgb12fg(*attr)]);284 dp->drv.p->colors[_cucul_attr_to_rgb12fg(*attrs)]); 285 285 286 286 /* Plain ASCII, no problem. */ -
libcaca/trunk/cucul/canvas.c
r1231 r1254 87 87 88 88 curchar = cv->chars + x + y * cv->width; 89 curattr = cv->attr + x + y * cv->width;90 attr = (cv->bgcolor << 16) | cv->fgcolor;89 curattr = cv->attrs + x + y * cv->width; 90 attr = cv->curattr; 91 91 92 92 /* When overwriting the right part of a fullwidth character, … … 254 254 int cucul_clear_canvas(cucul_canvas_t *cv) 255 255 { 256 uint32_t color = (cv->bgcolor << 16) | cv->fgcolor;256 uint32_t attr = cv->curattr; 257 257 unsigned int n; 258 258 … … 260 260 { 261 261 cv->chars[n] = (uint32_t)' '; 262 cv->attr [n] = color;262 cv->attrs[n] = attr; 263 263 } 264 264 … … 326 326 327 327 dst->chars[dstix + i] = src->chars[srcix + i]; 328 dst->attr [dstix + i] = src->attr[srcix + i];328 dst->attrs[dstix + i] = src->attrs[srcix + i]; 329 329 } 330 330 } 331 331 else 332 332 { 333 memcpy(dst->chars + dstix, src->chars + srcix, (stride)* 4);334 memcpy(dst->attr + dstix, src->attr + srcix, (stride)* 4);333 memcpy(dst->chars + dstix, src->chars + srcix, stride * 4); 334 memcpy(dst->attrs + dstix, src->attrs + srcix, stride * 4); 335 335 } 336 336 … … 393 393 394 394 free(cv->allchars[f]); 395 free(cv->allattr [f]);395 free(cv->allattrs[f]); 396 396 } 397 397 free(cv->allchars); 398 free(cv->allattr );398 free(cv->allattrs); 399 399 400 400 memcpy(cv, new, sizeof(cucul_canvas_t)); -
libcaca/trunk/cucul/colour.c
r1231 r1254 29 29 /* RGB colours for the ANSI palette. There is no real standard, so we 30 30 * use the same values as gnome-terminal. The 7th colour (brown) is a bit 31 * special . */31 * special: 0xfa50 instead of 0xfaa0. */ 32 32 static const uint16_t ansitab[16] = 33 33 { … … 36 36 }; 37 37 38 /** \brief Set the default colour pair. 39 * 40 * Set the default ANSI colour pair for drawing. String functions such as 38 /** \brief Set the default character attribute. 39 * 40 * Set the default character attribute for drawing. Attributes define 41 * foreground and background colour, transparency, bold, italics and 42 * underline styles, as well as blink. String functions such as 41 43 * caca_printf() and graphical primitive functions such as caca_draw_line() 42 * will use these colours. 43 * 44 * Color values are those defined in cucul.h, such as CUCUL_COLOR_RED 45 * or CUCUL_COLOR_TRANSPARENT. 44 * will use this attribute. 45 * 46 * The attribute value is a 32-bit integer as returned by cucul_get_attr(). 47 * For more user-friendly versions of this function, see cucul_set_attr_ansi() 48 * and cucul_set_attr_argb(). 46 49 * 47 50 * If an error occurs, -1 is returned and \b errno is set accordingly: 48 * - \c EINVAL At least one of the colour values is invalid.51 * - \c EINVAL The attribute value is out of the 32-bit range. 49 52 * 50 53 * \param cv A handle to the libcucul canvas. 51 * \param fg The requested foreground colour. 52 * \param bg The requested background colour. 54 * \param attr The requested attribute value. 53 55 * \return 0 in case of success, -1 if an error occurred. 54 56 */ 55 int cucul_set_ color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)56 { 57 if( fg > 0x20 || bg > 0x20)57 int cucul_set_attr(cucul_canvas_t *cv, unsigned long int attr) 58 { 59 if(sizeof(unsigned long int) > sizeof(uint32_t) && attr > 0xffffffff) 58 60 { 59 61 #if defined(HAVE_ERRNO_H) … … 63 65 } 64 66 65 cv->fgcolor = fg; 66 cv->bgcolor = bg; 67 cv->curattr = attr; 67 68 68 69 return 0; 69 70 } 70 71 71 /** \brief Set the default colour pair (truecolor version). 72 * 73 * Set the default colour pair for drawing. String functions such as 74 * caca_printf() and graphical primitive functions such as caca_draw_line() 75 * will use these colours. 76 * 77 * Colors are 16-bit ARGB values, each component being coded on 4 bits. For 78 * instance, 0xf088 is solid dark cyan (A=15 R=0 G=8 B=8), and 0x8fff is 79 * white with 50% alpha (A=8 R=15 G=15 B=15). 72 /** \brief Set the default colour pair and text style (ANSI version). 73 * 74 * Set the default ANSI colour pair and text style for drawing. String 75 * functions such as caca_printf() and graphical primitive functions such as 76 * caca_draw_line() will use these attributes. 77 * 78 * Color values are those defined in cucul.h, such as CUCUL_COLOR_RED 79 * or CUCUL_COLOR_TRANSPARENT. 80 * 81 * Style values are those defined in cucul.h, such as CUCUL_STYLE_UNDERLINE 82 * or CUCUL_STYLE_BLINK. The values can be ORed to set several styles at 83 * the same time. 80 84 * 81 85 * If an error occurs, -1 is returned and \b errno is set accordingly: 82 * - \c EINVAL At least one of the colour values isinvalid.86 * - \c EINVAL The colour values and/or the style mask are invalid. 83 87 * 84 88 * \param cv A handle to the libcucul canvas. 85 89 * \param fg The requested foreground colour. 86 90 * \param bg The requested background colour. 91 * \param style The requested text styles. 87 92 * \return 0 in case of success, -1 if an error occurred. 88 93 */ 89 int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg) 90 { 91 if(fg > 0xffff || bg > 0xffff) 94 int cucul_set_attr_ansi(cucul_canvas_t *cv, unsigned char fg, unsigned char bg, 95 unsigned char style) 96 { 97 uint32_t attr; 98 99 if(fg > 0x20 || bg > 0x20 || style > 0x0f) 92 100 { 93 101 #if defined(HAVE_ERRNO_H) … … 97 105 } 98 106 107 attr = ((uint32_t)bg << 20) | ((uint32_t)fg << 4); 108 109 if(style) 110 attr |= (0x02004801 * style) & 0x10011001; 111 112 cv->curattr = attr; 113 114 return 0; 115 } 116 117 /* Legacy function for old programs */ 118 int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg) 119 { 120 return cucul_set_attr_ansi(cv, fg, bg, 0); 121 } 122 123 /** \brief Set the default colour pair and text style (truecolor version). 124 * 125 * Set the default colour pair and text style for drawing. String 126 * functions such as caca_printf() and graphical primitive functions such as 127 * caca_draw_line() will use these attributes. 128 * 129 * Colors are 16-bit ARGB values, each component being coded on 4 bits. For 130 * instance, 0xf088 is solid dark cyan (A=15 R=0 G=8 B=8), and 0x8fff is 131 * white with 50% alpha (A=8 R=15 G=15 B=15). 132 * 133 * Style values are those defined in cucul.h, such as CUCUL_STYLE_UNDERLINE 134 * or CUCUL_STYLE_BLINK. The values can be ORed to set several styles at 135 * the same time. 136 * 137 * If an error occurs, -1 is returned and \b errno is set accordingly: 138 * - \c EINVAL At least one of the colour values is invalid. 139 * 140 * \param cv A handle to the libcucul canvas. 141 * \param fg The requested foreground colour. 142 * \param bg The requested background colour. 143 * \param style The requested text styles. 144 * \return 0 in case of success, -1 if an error occurred. 145 */ 146 int cucul_set_attr_argb(cucul_canvas_t *cv, unsigned int fg, unsigned int bg, 147 unsigned char style) 148 { 149 uint32_t attr; 150 151 if(fg > 0xffff || bg > 0xffff || style > 0x0f) 152 { 153 #if defined(HAVE_ERRNO_H) 154 errno = EINVAL; 155 #endif 156 return -1; 157 } 158 99 159 if(fg < 0x100) 100 160 fg += 0x100; … … 103 163 bg += 0x100; 104 164 105 cv->fgcolor = fg; 106 cv->bgcolor = bg; 165 attr = (((uint32_t)bg << 16) | (uint32_t)fg) & 0xeffeeffe; 166 167 if(style) 168 attr |= (0x02004801 * style) & 0x10011001; 169 170 cv->curattr = attr; 107 171 108 172 return 0; 109 173 } 110 174 111 /** \brief Get the colour pair at the given coordinates. 112 * 113 * Get the internal \e libcucul colour pair value of the character at the 114 * given coordinates. The colour pair value has 32 significant bits: the 115 * lower 16 bits are for the foreground colour, the higher 16 bits are for 116 * the background. 117 * 118 * If the coordinates are outside the canvas boundaries, the current colour 119 * pair is returned. 175 /* Legacy function for old programs */ 176 int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg) 177 { 178 return cucul_set_attr_argb(cv, fg, bg, 0); 179 } 180 181 /** \brief Get the text attribute at the given coordinates. 182 * 183 * Get the internal \e libcucul attribute value of the character at the 184 * given coordinates. The attribute value has 32 significant bits, 185 * organised as follows from MSB to LSB: 186 * - 3 bits for the background alpha 187 * - 1 bit for the blink flag 188 * - 4 bits for the background red component 189 * - 4 bits for the background green component 190 * - 3 bits for the background blue component 191 * - 1 bit for the underline flag 192 * - 3 bits for the foreground alpha 193 * - 1 bit for the italics flag 194 * - 4 bits for the foreground red component 195 * - 4 bits for the foreground green component 196 * - 3 bits for the foreground blue component 197 * - 1 bit for the bold flag 198 * 199 * If the coordinates are outside the canvas boundaries, the current 200 * attribute is returned. 120 201 * 121 202 * This function never fails. … … 124 205 * \param x X coordinate. 125 206 * \param y Y coordinate. 126 * \param ch The requested colour pair value. 127 * \return The character always returns 0. 128 */ 129 unsigned long int cucul_get_color(cucul_canvas_t *cv, int x, int y) 207 * \return The requested attribute. 208 */ 209 unsigned long int cucul_get_attr(cucul_canvas_t *cv, int x, int y) 130 210 { 131 211 if(x < 0 || x >= (int)cv->width || y < 0 || y >= (int)cv->height) 132 return ((uint32_t)cv->bgcolor << 16) | (uint32_t)cv->fgcolor; 133 134 return (unsigned long int)cv->attr[x + y * cv->width]; 135 } 136 212 return (unsigned long int)cv->curattr; 213 214 return (unsigned long int)cv->attrs[x + y * cv->width]; 215 } 137 216 138 217 /* … … 144 223 unsigned int i, best, dist; 145 224 146 if(argb16 < CUCUL_COLOR_DEFAULT) 147 return argb16; 148 149 if(argb16 == CUCUL_COLOR_DEFAULT || argb16 == CUCUL_COLOR_TRANSPARENT) 225 if(argb16 == (argb16 & 0x00f0)) 226 return argb16 >> 4; 227 228 if(argb16 == (CUCUL_COLOR_DEFAULT << 4) 229 || argb16 == (CUCUL_COLOR_TRANSPARENT << 4)) 150 230 return def; 151 231 152 if(argb16 < 0x 5fff) /* too transparent, return default colour */232 if(argb16 < 0x6fff) /* too transparent, return default colour */ 153 233 return def; 154 234 … … 182 262 } 183 263 184 uint8_t _cucul_a rgb32_to_ansi8(uint32_t ch)185 { 186 uint16_t fg = ch & 0xffff;187 uint16_t bg = ch >> 16;264 uint8_t _cucul_attr_to_ansi8(uint32_t attr) 265 { 266 uint16_t fg = attr & 0xeffe; 267 uint16_t bg = (attr >> 16) & 0xeffe; 188 268 189 269 return nearest_ansi(fg, CUCUL_COLOR_LIGHTGRAY) … … 191 271 } 192 272 193 uint8_t _cucul_a rgb32_to_ansi4fg(uint32_t ch)194 { 195 return nearest_ansi( ch & 0xffff, CUCUL_COLOR_LIGHTGRAY);196 } 197 198 uint8_t _cucul_a rgb32_to_ansi4bg(uint32_t ch)199 { 200 return nearest_ansi( ch >> 16, CUCUL_COLOR_BLACK);201 } 202 203 uint16_t _cucul_a rgb32_to_rgb12fg(uint32_t ch)204 { 205 uint16_t fg = ch & 0xffff;206 207 if(fg < CUCUL_COLOR_DEFAULT)208 return ansitab[fg ] & 0x0fff;209 210 if(fg == CUCUL_COLOR_DEFAULT)273 uint8_t _cucul_attr_to_ansi4fg(uint32_t attr) 274 { 275 return nearest_ansi(attr & 0xeffe, CUCUL_COLOR_LIGHTGRAY); 276 } 277 278 uint8_t _cucul_attr_to_ansi4bg(uint32_t attr) 279 { 280 return nearest_ansi((attr >> 16) & 0xeffe, CUCUL_COLOR_BLACK); 281 } 282 283 uint16_t _cucul_attr_to_rgb12fg(uint32_t attr) 284 { 285 uint16_t fg = attr & 0xeffe; 286 287 if(fg == (fg & 0x00f0)) 288 return ansitab[fg >> 4] & 0x0fff; 289 290 if(fg == (CUCUL_COLOR_DEFAULT << 4)) 211 291 return ansitab[CUCUL_COLOR_LIGHTGRAY] & 0x0fff; 212 292 213 if(fg == CUCUL_COLOR_TRANSPARENT)293 if(fg == (CUCUL_COLOR_TRANSPARENT << 4)) 214 294 return ansitab[CUCUL_COLOR_LIGHTGRAY] & 0x0fff; 215 295 … … 217 297 } 218 298 219 uint16_t _cucul_a rgb32_to_rgb12bg(uint32_t ch)220 { 221 uint16_t bg = ch >> 16;222 223 if(bg < CUCUL_COLOR_DEFAULT)224 return ansitab[bg ] & 0x0fff;225 226 if(bg == CUCUL_COLOR_DEFAULT)299 uint16_t _cucul_attr_to_rgb12bg(uint32_t attr) 300 { 301 uint16_t bg = (attr >> 16) & 0xeffe; 302 303 if(bg == (bg & 0x00f0)) 304 return ansitab[bg >> 4] & 0x0fff; 305 306 if(bg == (CUCUL_COLOR_DEFAULT << 4)) 227 307 return ansitab[CUCUL_COLOR_BLACK] & 0x0fff; 228 308 229 if(bg == CUCUL_COLOR_TRANSPARENT)309 if(bg == (CUCUL_COLOR_TRANSPARENT << 4)) 230 310 return ansitab[CUCUL_COLOR_BLACK] & 0x0fff; 231 311 … … 238 318 | ((uint32_t)(i & 0x00f) * 0x000011)) 239 319 240 uint32_t _cucul_a rgb32_to_rgb24fg(uint32_t ch)241 { 242 return RGB12TO24(_cucul_a rgb32_to_rgb12fg(ch));243 } 244 245 uint32_t _cucul_a rgb32_to_rgb24bg(uint32_t ch)246 { 247 return RGB12TO24(_cucul_a rgb32_to_rgb12bg(ch));248 } 249 250 void _cucul_a rgb32_to_argb4(uint32_t ch, uint8_t argb[8])251 { 252 uint16_t fg = ch & 0xffff;253 uint16_t bg = ch >> 16;254 255 if(fg < CUCUL_COLOR_DEFAULT)256 fg = ansitab[fg ];257 else if(fg == CUCUL_COLOR_DEFAULT)320 uint32_t _cucul_attr_to_rgb24fg(uint32_t attr) 321 { 322 return RGB12TO24(_cucul_attr_to_rgb12fg(attr)); 323 } 324 325 uint32_t _cucul_attr_to_rgb24bg(uint32_t attr) 326 { 327 return RGB12TO24(_cucul_attr_to_rgb12bg(attr)); 328 } 329 330 void _cucul_attr_to_argb4(uint32_t attr, uint8_t argb[8]) 331 { 332 uint16_t fg = attr & 0xeffe; 333 uint16_t bg = (attr >> 16) & 0xeffe; 334 335 if(fg == (fg & 0x00f0)) 336 fg = ansitab[fg >> 4]; 337 else if(fg == (CUCUL_COLOR_DEFAULT << 4)) 258 338 fg = ansitab[CUCUL_COLOR_LIGHTGRAY]; 259 else if(fg == CUCUL_COLOR_TRANSPARENT)339 else if(fg == (CUCUL_COLOR_TRANSPARENT << 4)) 260 340 fg = 0x0fff; 261 341 262 if(bg < CUCUL_COLOR_DEFAULT)263 bg = ansitab[bg ];264 else if(bg == CUCUL_COLOR_DEFAULT)342 if(bg == (bg & 0x00f0)) 343 bg = ansitab[bg >> 4]; 344 else if(bg == (CUCUL_COLOR_DEFAULT << 4)) 265 345 bg = ansitab[CUCUL_COLOR_BLACK]; 266 else if(bg == CUCUL_COLOR_TRANSPARENT)346 else if(bg == (CUCUL_COLOR_TRANSPARENT << 4)) 267 347 bg = 0x0fff; 268 348 -
libcaca/trunk/cucul/cucul.c
r1233 r1254 60 60 cv->refcount = 0; 61 61 62 cv->fgcolor = CUCUL_COLOR_DEFAULT; 63 cv->bgcolor = CUCUL_COLOR_TRANSPARENT; 62 cv->curattr = (CUCUL_COLOR_DEFAULT << 20) | (CUCUL_COLOR_TRANSPARENT < 4); 64 63 65 64 cv->width = cv->height = 0; 66 65 cv->chars = NULL; 67 cv->attr = NULL;66 cv->attrs = NULL; 68 67 69 68 cv->frame = 0; … … 75 74 goto nomem; 76 75 } 77 cv->allattr = malloc(sizeof(uint32_t *));78 if(!cv->allattr )76 cv->allattrs = malloc(sizeof(uint32_t *)); 77 if(!cv->allattrs) 79 78 { 80 79 free(cv->allchars); … … 83 82 } 84 83 cv->allchars[0] = NULL; 85 cv->allattr [0] = NULL;84 cv->allattrs[0] = NULL; 86 85 87 86 if(_cucul_set_canvas_size(cv, width, height) < 0) … … 90 89 int saved_errno = errno; 91 90 #endif 92 free(cv->allattr );91 free(cv->allattrs); 93 92 free(cv->allchars); 94 93 free(cv); … … 247 246 { 248 247 free(cv->allchars[f]); 249 free(cv->allattr [f]);248 free(cv->allattrs[f]); 250 249 } 251 250 252 251 free(cv->allchars); 253 free(cv->allattr );252 free(cv->allattrs); 254 253 free(cv); 255 254 … … 305 304 cv->allchars[f] = realloc(cv->allchars[f], 306 305 new_size * sizeof(uint32_t)); 307 cv->allattr [f] = realloc(cv->allattr[f],306 cv->allattrs[f] = realloc(cv->allattrs[f], 308 307 new_size * sizeof(uint32_t)); 309 if(!cv->allchars[f] || !cv->allattr [f])308 if(!cv->allchars[f] || !cv->allattrs[f]) 310 309 { 311 310 #if defined(HAVE_ERRNO_H) … … 331 330 { 332 331 uint32_t *chars = cv->allchars[f]; 333 uint32_t *attr = cv->allattr[f];332 uint32_t *attrs = cv->allattrs[f]; 334 333 335 334 for(y = height < old_height ? height : old_height; y--; ) 336 335 { 337 uint32_t color = (cv->bgcolor << 16) | cv->fgcolor;336 uint32_t attr = cv->curattr; 338 337 339 338 for(x = old_width; x--; ) 340 339 { 341 340 chars[y * width + x] = chars[y * old_width + x]; 342 attr [y * width + x] = attr[y * old_width + x];341 attrs[y * width + x] = attrs[y * old_width + x]; 343 342 } 344 343 … … 347 346 { 348 347 chars[y * width + old_width + x] = (uint32_t)' '; 349 attr [y * width + old_width + x] = color;348 attrs[y * width + old_width + x] = attr; 350 349 } 351 350 } … … 361 360 { 362 361 uint32_t *chars = cv->allchars[f]; 363 uint32_t *attr = cv->allattr[f];362 uint32_t *attrs = cv->allattrs[f]; 364 363 365 364 for(y = 1; y < lines; y++) … … 368 367 { 369 368 chars[y * width + x] = chars[y * old_width + x]; 370 attr [y * width + x] = attr[y * old_width + x];369 attrs[y * width + x] = attrs[y * old_width + x]; 371 370 } 372 371 } … … 380 379 { 381 380 uint32_t *chars = cv->allchars[f]; 382 uint32_t *attr = cv->allattr[f];383 uint32_t color = (cv->bgcolor << 16) | cv->fgcolor;381 uint32_t *attrs = cv->allattrs[f]; 382 uint32_t attr = cv->curattr; 384 383 385 384 /* Zero the bottom of the screen */ … … 387 386 { 388 387 chars[old_height * width + x] = (uint32_t)' '; 389 attr [old_height * width + x] = color;388 attrs[old_height * width + x] = attr; 390 389 } 391 390 } … … 399 398 cv->allchars[f] = realloc(cv->allchars[f], 400 399 new_size * sizeof(uint32_t)); 401 cv->allattr [f] = realloc(cv->allattr[f],400 cv->allattrs[f] = realloc(cv->allattrs[f], 402 401 new_size * sizeof(uint32_t)); 403 if(!cv->allchars[f] || !cv->allattr [f])402 if(!cv->allchars[f] || !cv->allattrs[f]) 404 403 { 405 404 #if defined(HAVE_ERRNO_H) … … 413 412 /* Reset the current frame shortcut */ 414 413 cv->chars = cv->allchars[cv->frame]; 415 cv->attr = cv->allattr[cv->frame];414 cv->attrs = cv->allattrs[cv->frame]; 416 415 417 416 return 0; -
libcaca/trunk/cucul/cucul.h
r1218 r1254 41 41 typedef struct cucul_font cucul_font_t; 42 42 43 /** \defgroup colour libcucul colour definitions 44 * 45 * Colours that can be used with cucul_set_color(). 43 /** \defgroup attributes libcucul attribute definitions 44 * 45 * Colours and styles that can be used with cucul_set_attr_ansi() and 46 * cucul_set_attr_argb(). 46 47 * 47 48 * @{ */ … … 64 65 #define CUCUL_COLOR_DEFAULT 0x10 /**< The output driver's default colour. */ 65 66 #define CUCUL_COLOR_TRANSPARENT 0x20 /**< The transparent colour. */ 67 68 #define CUCUL_STYLE_BOLD 0x01 /**< The style mask for bold. */ 69 #define CUCUL_STYLE_ITALICS 0x02 /**< The style mask for italics. */ 70 #define CUCUL_STYLE_UNDERLINE 0x04 /**< The style mask for underline. */ 71 #define CUCUL_STYLE_BLINK 0x08 /**< The style mask for blink. */ 66 72 /* @} */ 67 73 … … 99 105 * @{ */ 100 106 #define CUCUL_MAGIC_FULLWIDTH 0x000ffffe /**< Used to indicate that the previous character was a fullwidth glyph. */ 101 int cucul_set_color(cucul_canvas_t *, unsigned char, unsigned char); 102 int cucul_set_truecolor(cucul_canvas_t *, unsigned int, unsigned int); 103 unsigned long int cucul_get_color(cucul_canvas_t *, int, int); 107 int cucul_set_attr(cucul_canvas_t *, unsigned long int); 108 int cucul_set_attr_ansi(cucul_canvas_t *, unsigned char, unsigned char, 109 unsigned char); 110 int cucul_set_attr_argb(cucul_canvas_t *, unsigned int, unsigned int, 111 unsigned char); 112 unsigned long int cucul_get_attr(cucul_canvas_t *, int, int); 104 113 char const *cucul_get_color_name(unsigned int); 105 114 int cucul_putchar(cucul_canvas_t *, int, int, unsigned long int); … … 112 121 int cucul_set_canvas_boundaries(cucul_canvas_t *, int, int, 113 122 unsigned int, unsigned int); 123 /* Legacy stuff */ 124 int cucul_set_color(cucul_canvas_t *, unsigned char, unsigned char); 125 int cucul_set_truecolor(cucul_canvas_t *, unsigned int, unsigned int); 114 126 /* @} */ 115 127 -
libcaca/trunk/cucul/cucul_internals.h
r1218 r1254 26 26 /* Shortcut to the active frame */ 27 27 uint32_t *chars; 28 uint32_t *attr ;28 uint32_t *attrs; 29 29 30 30 /* Frame information */ 31 31 unsigned int frame, framecount; 32 32 uint32_t **allchars; 33 uint32_t **allattr ;33 uint32_t **allattrs; 34 34 35 35 /* Painting context */ 36 uint16_t fgcolor; 37 uint16_t bgcolor; 36 uint32_t curattr; 38 37 39 38 unsigned int refcount; … … 59 58 60 59 /* Colour functions */ 61 uint8_t _cucul_a rgb32_to_ansi8(uint32_t);62 uint8_t _cucul_a rgb32_to_ansi4fg(uint32_t);63 uint8_t _cucul_a rgb32_to_ansi4bg(uint32_t);64 uint16_t _cucul_a rgb32_to_rgb12fg(uint32_t);65 uint16_t _cucul_a rgb32_to_rgb12bg(uint32_t);66 uint32_t _cucul_a rgb32_to_rgb24fg(uint32_t);67 uint32_t _cucul_a rgb32_to_rgb24bg(uint32_t);68 void _cucul_a rgb32_to_argb4(uint32_t, uint8_t[8]);60 uint8_t _cucul_attr_to_ansi8(uint32_t); 61 uint8_t _cucul_attr_to_ansi4fg(uint32_t); 62 uint8_t _cucul_attr_to_ansi4bg(uint32_t); 63 uint16_t _cucul_attr_to_rgb12fg(uint32_t); 64 uint16_t _cucul_attr_to_rgb12bg(uint32_t); 65 uint32_t _cucul_attr_to_rgb24fg(uint32_t); 66 uint32_t _cucul_attr_to_rgb24bg(uint32_t); 67 void _cucul_attr_to_argb4(uint32_t, uint8_t[8]); 69 68 70 69 #endif /* __CUCUL_INTERNALS_H__ */ -
libcaca/trunk/cucul/export.c
r1239 r1254 154 154 static int export_caca(cucul_canvas_t *cv, cucul_buffer_t *ex) 155 155 { 156 uint32_t *attr = cv->attr;156 uint32_t *attrs = cv->attrs; 157 157 uint32_t *chars = cv->chars; 158 158 char *cur; … … 178 178 { 179 179 uint32_t ch = *chars++; 180 uint32_t a = *attr ++;180 uint32_t a = *attrs++; 181 181 182 182 *cur++ = ch >> 24; … … 216 216 for(y = 0; y < cv->height; y++) 217 217 { 218 uint32_t *lineattr = cv->attr + y * cv->width;218 uint32_t *lineattr = cv->attrs + y * cv->width; 219 219 uint32_t *linechar = cv->chars + y * cv->width; 220 220 … … 231 231 continue; 232 232 233 fg = ((attr & 0x ffff) == CUCUL_COLOR_DEFAULT) ?234 0x10 : palette[_cucul_a rgb32_to_ansi4fg(attr)];235 bg = (( attr >> 16) == CUCUL_COLOR_TRANSPARENT) ?236 0x10 : palette[_cucul_a rgb32_to_ansi4bg(attr)];233 fg = ((attr & 0xeffe) == (CUCUL_COLOR_DEFAULT << 4)) ? 234 0x10 : palette[_cucul_attr_to_ansi4fg(attr)]; 235 bg = (((attr >> 16) & 0xeffe) == (CUCUL_COLOR_TRANSPARENT << 4)) ? 236 0x10 : palette[_cucul_attr_to_ansi4bg(attr)]; 237 237 238 238 /* TODO: the [0 could be omitted in some cases */ … … 298 298 for(y = 0; y < cv->height; y++) 299 299 { 300 uint32_t *lineattr = cv->attr + y * cv->width;300 uint32_t *lineattr = cv->attrs + y * cv->width; 301 301 uint32_t *linechar = cv->chars + y * cv->width; 302 302 303 303 for(x = 0; x < cv->width; x++) 304 304 { 305 uint8_t fg = palette[_cucul_a rgb32_to_ansi4fg(lineattr[x])];306 uint8_t bg = palette[_cucul_a rgb32_to_ansi4bg(lineattr[x])];305 uint8_t fg = palette[_cucul_attr_to_ansi4fg(lineattr[x])]; 306 uint8_t bg = palette[_cucul_attr_to_ansi4bg(lineattr[x])]; 307 307 uint32_t ch = linechar[x]; 308 308 … … 377 377 for(y = 0; y < cv->height; y++) 378 378 { 379 uint32_t *lineattr = cv->attr + y * cv->width;379 uint32_t *lineattr = cv->attrs + y * cv->width; 380 380 uint32_t *linechar = cv->chars + y * cv->width; 381 381 … … 384 384 cur += sprintf(cur, "<span style=\"color:#%.03x;" 385 385 "background-color:#%.03x\">", 386 _cucul_a rgb32_to_rgb12fg(lineattr[x]),387 _cucul_a rgb32_to_rgb12bg(lineattr[x]));386 _cucul_attr_to_rgb12fg(lineattr[x]), 387 _cucul_attr_to_rgb12bg(lineattr[x])); 388 388 389 389 for(len = 0; … … 442 442 for(y = 0; y < cv->height; y++) 443 443 { 444 uint32_t *lineattr = cv->attr + y * cv->width;444 uint32_t *lineattr = cv->attrs + y * cv->width; 445 445 uint32_t *linechar = cv->chars + y * cv->width; 446 446 … … 458 458 459 459 cur += sprintf(cur, "<td bgcolor=#%.06lx", (unsigned long int) 460 _cucul_a rgb32_to_rgb24bg(lineattr[x]));460 _cucul_attr_to_rgb24bg(lineattr[x])); 461 461 462 462 if(len > 1) … … 464 464 465 465 cur += sprintf(cur, "><font color=#%.06lx>", (unsigned long int) 466 _cucul_a rgb32_to_rgb24fg(lineattr[x]));466 _cucul_attr_to_rgb24fg(lineattr[x])); 467 467 468 468 for(i = 0; i < len; i++) … … 522 522 for(y = 0; y < cv->height; y++) 523 523 { 524 uint32_t *lineattr = cv->attr + y * cv->width;524 uint32_t *lineattr = cv->attrs + y * cv->width; 525 525 uint32_t *linechar = cv->chars + y * cv->width; 526 526 … … 531 531 { 532 532 uint32_t attr = lineattr[x]; 533 uint8_t fg = palette[_cucul_a rgb32_to_ansi4fg(attr)];534 uint8_t bg = palette[_cucul_a rgb32_to_ansi4bg(attr)];533 uint8_t fg = palette[_cucul_attr_to_ansi4fg(attr)]; 534 uint8_t bg = palette[_cucul_attr_to_ansi4bg(attr)]; 535 535 uint32_t ch = linechar[x]; 536 536 … … 538 538 continue; 539 539 540 if((attr & 0x ffff) == CUCUL_COLOR_DEFAULT)540 if((attr & 0xeffe) == (CUCUL_COLOR_DEFAULT << 4)) 541 541 fg = 0x10; 542 542 543 if(( attr >> 16) == CUCUL_COLOR_TRANSPARENT)543 if(((attr >> 16) & 0xeffe) == (CUCUL_COLOR_TRANSPARENT << 4)) 544 544 bg = 0x10; 545 545 … … 645 645 for(y = cv->height; y--; ) 646 646 { 647 uint32_t *lineattr = cv->attr + y * cv->width;647 uint32_t *lineattr = cv->attrs + y * cv->width; 648 648 649 649 for(x = 0; x < cv->width; x++) 650 650 { 651 651 uint8_t argb[8]; 652 _cucul_a rgb32_to_argb4(*lineattr++, argb);652 _cucul_attr_to_argb4(*lineattr++, argb); 653 653 cur += sprintf(cur, "1 0 translate\n %f %f %f csquare\n", 654 654 (float)argb[1] * (1.0 / 0xf), … … 666 666 for(y = cv->height; y--; ) 667 667 { 668 uint32_t *lineattr = cv->attr + (cv->height - y - 1) * cv->width;668 uint32_t *lineattr = cv->attrs + (cv->height - y - 1) * cv->width; 669 669 uint32_t *linechar = cv->chars + (cv->height - y - 1) * cv->width; 670 670 … … 674 674 uint32_t ch = *linechar++; 675 675 676 _cucul_a rgb32_to_argb4(*lineattr++, argb);676 _cucul_attr_to_argb4(*lineattr++, argb); 677 677 678 678 cur += sprintf(cur, "newpath\n"); … … 739 739 for(y = 0; y < cv->height; y++) 740 740 { 741 uint32_t *lineattr = cv->attr + y * cv->width;741 uint32_t *lineattr = cv->attrs + y * cv->width; 742 742 743 743 for(x = 0; x < cv->width; x++) … … 745 745 cur += sprintf(cur, "<rect style=\"fill:#%.03x\" x=\"%d\" y=\"%d\"" 746 746 " width=\"6\" height=\"10\"/>\n", 747 _cucul_a rgb32_to_rgb12bg(*lineattr++),747 _cucul_attr_to_rgb12bg(*lineattr++), 748 748 x * 6, y * 10); 749 749 } … … 753 753 for(y = 0; y < cv->height; y++) 754 754 { 755 uint32_t *lineattr = cv->attr + y * cv->width;755 uint32_t *lineattr = cv->attrs + y * cv->width; 756 756 uint32_t *linechar = cv->chars + y * cv->width; 757 757 … … 768 768 cur += sprintf(cur, "<text style=\"fill:#%.03x\" " 769 769 "x=\"%d\" y=\"%d\">", 770 _cucul_a rgb32_to_rgb12fg(*lineattr++),770 _cucul_attr_to_rgb12fg(*lineattr++), 771 771 x * 6, (y * 10) + 8); 772 772 -
libcaca/trunk/cucul/font.c
r1072 r1254 421 421 unsigned int startx = x * f->header.width; 422 422 uint32_t ch = cv->chars[y * cv->width + x]; 423 uint32_t attr = cv->attr [y * cv->width + x];423 uint32_t attr = cv->attrs[y * cv->width + x]; 424 424 unsigned int b, i, j; 425 425 struct glyph_info *g; … … 445 445 + ch - f->block_list[b].start]; 446 446 447 _cucul_a rgb32_to_argb4(attr, argb);447 _cucul_attr_to_argb4(attr, argb); 448 448 449 449 /* Step 1: unpack glyph */ -
libcaca/trunk/cucul/import.c
r1248 r1254 173 173 | ((uint32_t)buf[16 + 2 + 8 * n] << 8) 174 174 | (uint32_t)buf[16 + 3 + 8 * n]; 175 cv->attr [n] = ((uint32_t)buf[16 + 4 + 8 * n] << 24)175 cv->attrs[n] = ((uint32_t)buf[16 + 4 + 8 * n] << 24) 176 176 | ((uint32_t)buf[16 + 5 + 8 * n] << 16) 177 177 | ((uint32_t)buf[16 + 6 + 8 * n] << 8) -
libcaca/trunk/cucul/sprite.c
r1231 r1254 73 73 74 74 cv->chars = cv->allchars[cv->frame]; 75 cv->attr = cv->allattr[cv->frame];75 cv->attrs = cv->allattrs[cv->frame]; 76 76 77 77 return 0; … … 108 108 cv->framecount++; 109 109 cv->allchars = realloc(cv->allchars, sizeof(uint32_t *) * cv->framecount); 110 cv->allattr = realloc(cv->allattr, sizeof(uint32_t *) * cv->framecount);110 cv->allattrs = realloc(cv->allattrs, sizeof(uint32_t *) * cv->framecount); 111 111 112 112 for(f = cv->framecount - 1; f > frame; f--) 113 113 { 114 114 cv->allchars[f] = cv->allchars[f - 1]; 115 cv->allattr [f] = cv->allattr[f - 1];115 cv->allattrs[f] = cv->allattrs[f - 1]; 116 116 } 117 117 118 118 cv->allchars[frame] = malloc(size); 119 119 memcpy(cv->allchars[frame], cv->chars, size); 120 cv->allattr [frame] = malloc(size);121 memcpy(cv->allattr [frame], cv->attr, size);120 cv->allattrs[frame] = malloc(size); 121 memcpy(cv->allattrs[frame], cv->attrs, size); 122 122 123 123 if(cv->frame >= frame) … … 125 125 126 126 cv->chars = cv->allchars[cv->frame]; 127 cv->attr = cv->allattr[cv->frame];127 cv->attrs = cv->allattrs[cv->frame]; 128 128 129 129 return 0; … … 172 172 173 173 free(cv->allchars[frame]); 174 free(cv->allattr [frame]);174 free(cv->allattrs[frame]); 175 175 176 176 for(f = frame + 1; f < cv->framecount; f++) 177 177 { 178 178 cv->allchars[f - 1] = cv->allchars[f]; 179 cv->allattr [f - 1] = cv->allattr[f];179 cv->allattrs[f - 1] = cv->allattrs[f]; 180 180 } 181 181 182 182 cv->framecount--; 183 183 cv->allchars = realloc(cv->allchars, sizeof(uint32_t *) * cv->framecount); 184 cv->allattr = realloc(cv->allattr, sizeof(uint32_t *) * cv->framecount);184 cv->allattrs = realloc(cv->allattrs, sizeof(uint32_t *) * cv->framecount); 185 185 186 186 if(cv->frame > frame) … … 190 190 191 191 cv->chars = cv->allchars[cv->frame]; 192 cv->attr = cv->allattr[cv->frame];192 cv->attrs = cv->allattrs[cv->frame]; 193 193 194 194 return 0; -
libcaca/trunk/cucul/transform.c
r1231 r1254 41 41 int cucul_invert(cucul_canvas_t *cv) 42 42 { 43 uint32_t *attr = cv->attr;43 uint32_t *attrs = cv->attrs; 44 44 unsigned int i; 45 45 46 46 for(i = cv->height * cv->width; i--; ) 47 47 { 48 *attr = *attr^ 0x000f000f;49 attr ++;48 *attrs = *attrs ^ 0x000f000f; 49 attrs++; 50 50 } 51 51 … … 71 71 uint32_t *cleft = cv->chars + y * cv->width; 72 72 uint32_t *cright = cleft + cv->width - 1; 73 uint32_t *aleft = cv->attr + y * cv->width;73 uint32_t *aleft = cv->attrs + y * cv->width; 74 74 uint32_t *aright = aleft + cv->width - 1; 75 75 … … 128 128 uint32_t *ctop = cv->chars + x; 129 129 uint32_t *cbottom = ctop + cv->width * (cv->height - 1); 130 uint32_t *atop = cv->attr + x;130 uint32_t *atop = cv->attrs + x; 131 131 uint32_t *abottom = atop + cv->width * (cv->height - 1); 132 132 … … 167 167 uint32_t *cbegin = cv->chars; 168 168 uint32_t *cend = cbegin + cv->width * cv->height - 1; 169 uint32_t *abegin = cv->attr ;169 uint32_t *abegin = cv->attrs; 170 170 uint32_t *aend = abegin + cv->width * cv->height - 1; 171 171 unsigned int y;
Note: See TracChangeset
for help on using the changeset viewer.