Changeset 2057
- Timestamp:
- Nov 25, 2007, 3:12:20 PM (13 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca/driver_cocoa.m
r2056 r2057 271 271 NSColor* color = nil; 272 272 #if USE_RGB12_FGBG 273 uint16_t bg = _cucul_attr_to_rgb12bg(*attrs);273 uint16_t bg = cucul_attr_to_rgb12_bg(*attrs); 274 274 if(bg) 275 275 { … … 289 289 #else 290 290 uint8_t argb[8]; 291 _cucul_attr_to_argb4(*attrs, argb);291 cucul_attr_to_argb64(*attrs, argb); 292 292 color = [NSColor colorWithCalibratedRed:((float)argb[1]) / 15.0 293 293 green:((float)argb[2]) / 15.0 … … 329 329 NSColor* color = nil; 330 330 #if USE_RGB12_FGBG 331 uint16_t fg = _cucul_attr_to_rgb12fg(*attrs);331 uint16_t fg = cucul_attr_to_rgb12_fg(*attrs); 332 332 # ifdef PRECACHE_WHOLE_COLOR_TABLE 333 333 color = _colorCache[fg]; … … 344 344 #else // USE_RGB12_FGBG 345 345 uint8_t argb[8]; 346 _cucul_attr_to_argb4(*attrs, argb);346 cucul_attr_to_argb64(*attrs, argb); 347 347 debug_log(@"x,y=[%d,%d] r,g,b back=[%u %u %u] front=[%u %u %u]", 348 348 x, y, argb[1], argb[2], argb[3], argb[5], argb[6], argb[7]); -
libcaca/trunk/caca/driver_gl.c
r2056 r2057 38 38 39 39 #include "cucul.h" 40 #include "cucul_internals.h"41 40 #include "caca.h" 42 41 #include "caca_internals.h" … … 228 227 for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width) 229 228 { 230 uint16_t bg = _cucul_attr_to_rgb12bg(*attrs++);229 uint16_t bg = cucul_attr_to_rgb12_bg(*attrs++); 231 230 232 231 glColor4b(((bg & 0xf00) >> 8) * 8, … … 280 279 - (uint32_t)dp->drv.p->blocks[i]]); 281 280 282 fg = _cucul_attr_to_rgb12fg(*attrs);281 fg = cucul_attr_to_rgb12_fg(*attrs); 283 282 glColor3b(((fg & 0xf00) >> 8) * 8, 284 283 ((fg & 0x0f0) >> 4) * 8, -
libcaca/trunk/caca/driver_x11.c
r2056 r2057 35 35 36 36 #include "cucul.h" 37 #include "cucul_internals.h"38 37 #include "caca.h" 39 38 #include "caca_internals.h" … … 305 304 { 306 305 uint32_t const *attrs = cvattrs + x + y * width; 307 uint16_t bg = _cucul_attr_to_rgb12bg(*attrs);306 uint16_t bg = cucul_attr_to_rgb12_bg(*attrs); 308 307 309 308 len = 1; 310 309 while(x + len < width 311 && _cucul_attr_to_rgb12bg(attrs[len]) == bg)310 && cucul_attr_to_rgb12_bg(attrs[len]) == bg) 312 311 len++; 313 312 … … 333 332 { 334 333 XSetForeground(dp->drv.p->dpy, dp->drv.p->gc, 335 dp->drv.p->colors[ _cucul_attr_to_rgb12fg(*attrs)]);334 dp->drv.p->colors[cucul_attr_to_rgb12_fg(*attrs)]); 336 335 337 336 x11_put_glyph(dp, x * dp->drv.p->font_width, -
libcaca/trunk/cucul/attr.c
r2043 r2057 25 25 26 26 static uint8_t nearest_ansi(uint16_t); 27 28 /* RGB colours for the ANSI palette. There is no real standard, so we 29 * use the same values as gnome-terminal. The 7th colour (brown) is a bit 30 * special: 0xfa50 instead of 0xfaa0. */ 31 static const uint16_t ansitab16[16] = 32 { 33 0xf000, 0xf00a, 0xf0a0, 0xf0aa, 0xfa00, 0xfa0a, 0xfa50, 0xfaaa, 34 0xf555, 0xf55f, 0xf5f5, 0xf5ff, 0xff55, 0xff5f, 0xfff5, 0xffff, 35 }; 36 37 /* Same table, except on 14 bits (3-4-4-3) */ 38 static const uint16_t ansitab14[16] = 39 { 40 0x3800, 0x3805, 0x3850, 0x3855, 0x3d00, 0x3d05, 0x3d28, 0x3d55, 41 0x3aaa, 0x3aaf, 0x3afa, 0x3aff, 0x3faa, 0x3faf, 0x3ffa, 0x3fff, 42 }; 27 43 28 44 /** \brief Get the text attribute at the given coordinates. … … 292 308 } 293 309 294 /* 295 * XXX: the following functions are local 296 */ 297 298 /* RGB colours for the ANSI palette. There is no real standard, so we 299 * use the same values as gnome-terminal. The 7th colour (brown) is a bit 300 * special: 0xfa50 instead of 0xfaa0. */ 301 static const uint16_t ansitab16[16] = 302 { 303 0xf000, 0xf00a, 0xf0a0, 0xf0aa, 0xfa00, 0xfa0a, 0xfa50, 0xfaaa, 304 0xf555, 0xf55f, 0xf5f5, 0xf5ff, 0xff55, 0xff5f, 0xfff5, 0xffff, 305 }; 306 307 /* Same table, except on 14 bits (3-4-4-3) */ 308 static const uint16_t ansitab14[16] = 309 { 310 0x3800, 0x3805, 0x3850, 0x3855, 0x3d00, 0x3d05, 0x3d28, 0x3d55, 311 0x3aaa, 0x3aaf, 0x3afa, 0x3aff, 0x3faa, 0x3faf, 0x3ffa, 0x3fff, 312 }; 313 314 static uint8_t nearest_ansi(uint16_t argb14) 315 { 316 unsigned int i, best, dist; 317 318 if(argb14 < (0x10 | 0x40)) 319 return argb14 ^ 0x40; 320 321 if(argb14 == (CUCUL_DEFAULT | 0x40) || argb14 == (CUCUL_TRANSPARENT | 0x40)) 322 return argb14 ^ 0x40; 323 324 if(argb14 < 0x0fff) /* too transparent */ 325 return CUCUL_TRANSPARENT; 326 327 best = CUCUL_DEFAULT; 328 dist = 0x3fff; 329 for(i = 0; i < 16; i++) 330 { 331 unsigned int d = 0; 332 int a, b; 333 334 a = (ansitab14[i] >> 7) & 0xf; 335 b = (argb14 >> 7) & 0xf; 336 d += (a - b) * (a - b); 337 338 a = (ansitab14[i] >> 3) & 0xf; 339 b = (argb14 >> 3) & 0xf; 340 d += (a - b) * (a - b); 341 342 a = (ansitab14[i] << 1) & 0xf; 343 b = (argb14 << 1) & 0xf; 344 d += (a - b) * (a - b); 345 346 if(d < dist) 347 { 348 dist = d; 349 best = i; 350 } 351 } 352 353 return best; 354 } 355 356 uint16_t _cucul_attr_to_rgb12fg(uint32_t attr) 310 /** \brief Get 12-bit RGB foreground information from attribute. 311 * 312 * Get the 12-bit foreground colour value for a given attribute. The returned 313 * value is a native-endian encoded integer with each red, green and blue 314 * values encoded on 8 bits in the following order: 315 * - 8-11 most significant bits: red 316 * - 4-7 most significant bits: green 317 * - least significant bits: blue 318 * 319 * This function never fails. If the attribute value is outside the expected 320 * 32-bit range, higher order bits are simply ignored. 321 * 322 * \param attr The requested attribute value. 323 * \return The corresponding 12-bit RGB foreground value. 324 */ 325 unsigned int cucul_attr_to_rgb12_fg(unsigned long int attr) 357 326 { 358 327 uint16_t fg = (attr >> 4) & 0x3fff; … … 370 339 } 371 340 372 uint16_t _cucul_attr_to_rgb12bg(uint32_t attr) 341 /** \brief Get 12-bit RGB background information from attribute. 342 * 343 * Get the 12-bit background colour value for a given attribute. The returned 344 * value is a native-endian encoded integer with each red, green and blue 345 * values encoded on 8 bits in the following order: 346 * - 8-11 most significant bits: red 347 * - 4-7 most significant bits: green 348 * - least significant bits: blue 349 * 350 * This function never fails. If the attribute value is outside the expected 351 * 32-bit range, higher order bits are simply ignored. 352 * 353 * \param attr The requested attribute value. 354 * \return The corresponding 12-bit RGB background value. 355 */ 356 unsigned int cucul_attr_to_rgb12_bg(unsigned long int attr) 373 357 { 374 358 uint16_t bg = attr >> 18; … … 386 370 } 387 371 388 #define RGB12TO24(i) \ 389 (((uint32_t)((i & 0xf00) >> 8) * 0x110000) \ 390 | ((uint32_t)((i & 0x0f0) >> 4) * 0x001100) \ 391 | ((uint32_t)(i & 0x00f) * 0x000011)) 392 393 uint32_t _cucul_attr_to_rgb24fg(uint32_t attr) 394 { 395 return RGB12TO24(_cucul_attr_to_rgb12fg(attr)); 396 } 397 398 uint32_t _cucul_attr_to_rgb24bg(uint32_t attr) 399 { 400 return RGB12TO24(_cucul_attr_to_rgb12bg(attr)); 401 } 402 403 void _cucul_attr_to_argb4(uint32_t attr, uint8_t argb[8]) 372 /** \brief Get 64-bit ARGB information from attribute. 373 * 374 * Get the 64-bit colour and alpha values for a given attribute. The values 375 * are written as 8-bit integers in the \e argb array in the following order: 376 * - \e argb[0]: background alpha value 377 * - \e argb[1]: background red value 378 * - \e argb[2]: background green value 379 * - \e argb[3]: background blue value 380 * - \e argb[4]: foreground alpha value 381 * - \e argb[5]: foreground red value 382 * - \e argb[6]: foreground green value 383 * - \e argb[7]: foreground blue value 384 * 385 * This function never fails. If the attribute value is outside the expected 386 * 32-bit range, higher order bits are simply ignored. 387 * 388 * \param attr The requested attribute value. 389 * \param argb An array of 8-bit integers. 390 */ 391 void cucul_attr_to_argb64(unsigned long int attr, unsigned char argb[8]) 404 392 { 405 393 uint16_t fg = (attr >> 4) & 0x3fff; … … 435 423 } 436 424 425 /* 426 * XXX: the following functions are local 427 */ 428 429 static uint8_t nearest_ansi(uint16_t argb14) 430 { 431 unsigned int i, best, dist; 432 433 if(argb14 < (0x10 | 0x40)) 434 return argb14 ^ 0x40; 435 436 if(argb14 == (CUCUL_DEFAULT | 0x40) || argb14 == (CUCUL_TRANSPARENT | 0x40)) 437 return argb14 ^ 0x40; 438 439 if(argb14 < 0x0fff) /* too transparent */ 440 return CUCUL_TRANSPARENT; 441 442 best = CUCUL_DEFAULT; 443 dist = 0x3fff; 444 for(i = 0; i < 16; i++) 445 { 446 unsigned int d = 0; 447 int a, b; 448 449 a = (ansitab14[i] >> 7) & 0xf; 450 b = (argb14 >> 7) & 0xf; 451 d += (a - b) * (a - b); 452 453 a = (ansitab14[i] >> 3) & 0xf; 454 b = (argb14 >> 3) & 0xf; 455 d += (a - b) * (a - b); 456 457 a = (ansitab14[i] << 1) & 0xf; 458 b = (argb14 << 1) & 0xf; 459 d += (a - b) * (a - b); 460 461 if(d < dist) 462 { 463 dist = d; 464 best = i; 465 } 466 } 467 468 return best; 469 } 470 471 #define RGB12TO24(i) \ 472 (((uint32_t)((i & 0xf00) >> 8) * 0x110000) \ 473 | ((uint32_t)((i & 0x0f0) >> 4) * 0x001100) \ 474 | ((uint32_t)(i & 0x00f) * 0x000011)) 475 476 uint32_t _cucul_attr_to_rgb24fg(uint32_t attr) 477 { 478 return RGB12TO24(cucul_attr_to_rgb12_fg(attr)); 479 } 480 481 uint32_t _cucul_attr_to_rgb24bg(uint32_t attr) 482 { 483 return RGB12TO24(cucul_attr_to_rgb12_bg(attr)); 484 } 485 -
libcaca/trunk/cucul/cucul.h
r2056 r2057 151 151 __extern unsigned char cucul_attr_to_ansi_fg(unsigned long int); 152 152 __extern unsigned char cucul_attr_to_ansi_bg(unsigned long int); 153 __extern unsigned int cucul_attr_to_rgb12_fg(unsigned long int); 154 __extern unsigned int cucul_attr_to_rgb12_bg(unsigned long int); 155 __extern void cucul_attr_to_argb64(unsigned long int, unsigned char[8]); 153 156 /* @} */ 154 157 -
libcaca/trunk/cucul/cucul_internals.h
r2055 r2057 65 65 66 66 /* Colour functions */ 67 extern uint16_t _cucul_attr_to_rgb12fg(uint32_t);68 extern uint16_t _cucul_attr_to_rgb12bg(uint32_t);69 67 extern uint32_t _cucul_attr_to_rgb24fg(uint32_t); 70 68 extern uint32_t _cucul_attr_to_rgb24bg(uint32_t); 71 extern void _cucul_attr_to_argb4(uint32_t, uint8_t[8]);72 69 73 70 /* Frames functions */ -
libcaca/trunk/cucul/export.c
r2043 r2057 395 395 if(cucul_attr_to_ansi_fg(lineattr[x]) < 0x10) 396 396 cur += sprintf(cur, ";color:#%.03x", 397 _cucul_attr_to_rgb12fg(lineattr[x]));397 cucul_attr_to_rgb12_fg(lineattr[x])); 398 398 if(cucul_attr_to_ansi_bg(lineattr[x]) < 0x10) 399 399 cur += sprintf(cur, ";background-color:#%.03x", 400 _cucul_attr_to_rgb12bg(lineattr[x]));400 cucul_attr_to_rgb12_bg(lineattr[x])); 401 401 if(lineattr[x] & CUCUL_BOLD) 402 402 cur += sprintf(cur, ";font-weight:bold"); … … 700 700 { 701 701 uint8_t argb[8]; 702 _cucul_attr_to_argb4(*lineattr++, argb);702 cucul_attr_to_argb64(*lineattr++, argb); 703 703 cur += sprintf(cur, "1 0 translate\n %f %f %f csquare\n", 704 704 (float)argb[1] * (1.0 / 0xf), … … 724 724 uint32_t ch = *linechar++; 725 725 726 _cucul_attr_to_argb4(*lineattr++, argb);726 cucul_attr_to_argb64(*lineattr++, argb); 727 727 728 728 cur += sprintf(cur, "newpath\n"); … … 795 795 cur += sprintf(cur, "<rect style=\"fill:#%.03x\" x=\"%d\" y=\"%d\"" 796 796 " width=\"6\" height=\"10\"/>\n", 797 _cucul_attr_to_rgb12bg(*lineattr++),797 cucul_attr_to_rgb12_bg(*lineattr++), 798 798 x * 6, y * 10); 799 799 } … … 818 818 cur += sprintf(cur, "<text style=\"fill:#%.03x\" " 819 819 "x=\"%d\" y=\"%d\">", 820 _cucul_attr_to_rgb12fg(*lineattr++),820 cucul_attr_to_rgb12_fg(*lineattr++), 821 821 x * 6, (y * 10) + 8); 822 822 -
libcaca/trunk/cucul/font.c
r2043 r2057 468 468 + ch - f->block_list[b].start]; 469 469 470 _cucul_attr_to_argb4(attr, argb);470 cucul_attr_to_argb64(attr, argb); 471 471 472 472 /* Step 1: unpack glyph */
Note: See TracChangeset
for help on using the changeset viewer.