Changeset 2057


Ignore:
Timestamp:
Nov 25, 2007, 3:12:20 PM (12 years ago)
Author:
Sam Hocevar
Message:
  • Export cucul_attr_to_rgb12_bg(), cucul_attr_to_rgb12_fg() and cucul_attr_to_argb64() (previously _cucul_attr_to_rgb12bg, _cucul_attr_to_rgb12fg and _cucul_attr_to_argb4) in the official libcucul API.
  • Cleanup complete: libcaca no longer depends on "cucul_internals.h".
Location:
libcaca/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/driver_cocoa.m

    r2056 r2057  
    271271                NSColor* color = nil;
    272272#if USE_RGB12_FGBG
    273                 uint16_t bg = _cucul_attr_to_rgb12bg(*attrs);
     273                uint16_t bg = cucul_attr_to_rgb12_bg(*attrs);
    274274                if(bg)
    275275                {
     
    289289#else
    290290                uint8_t argb[8];
    291                 _cucul_attr_to_argb4(*attrs, argb);
     291                cucul_attr_to_argb64(*attrs, argb);
    292292                color =  [NSColor colorWithCalibratedRed:((float)argb[1]) / 15.0
    293293                                  green:((float)argb[2]) / 15.0
     
    329329                    NSColor* color = nil;
    330330#if USE_RGB12_FGBG
    331                     uint16_t fg = _cucul_attr_to_rgb12fg(*attrs);
     331                    uint16_t fg = cucul_attr_to_rgb12_fg(*attrs);
    332332#   ifdef PRECACHE_WHOLE_COLOR_TABLE
    333333                    color = _colorCache[fg];
     
    344344#else // USE_RGB12_FGBG
    345345                    uint8_t argb[8];
    346                     _cucul_attr_to_argb4(*attrs, argb);
     346                    cucul_attr_to_argb64(*attrs, argb);
    347347                    debug_log(@"x,y=[%d,%d] r,g,b back=[%u %u %u] front=[%u %u %u]",
    348348                              x, y, argb[1], argb[2], argb[3], argb[5], argb[6], argb[7]);
  • libcaca/trunk/caca/driver_gl.c

    r2056 r2057  
    3838
    3939#include "cucul.h"
    40 #include "cucul_internals.h"
    4140#include "caca.h"
    4241#include "caca_internals.h"
     
    228227        for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width)
    229228        {
    230             uint16_t bg = _cucul_attr_to_rgb12bg(*attrs++);
     229            uint16_t bg = cucul_attr_to_rgb12_bg(*attrs++);
    231230
    232231            glColor4b(((bg & 0xf00) >> 8) * 8,
     
    280279                                        - (uint32_t)dp->drv.p->blocks[i]]);
    281280
    282                 fg = _cucul_attr_to_rgb12fg(*attrs);
     281                fg = cucul_attr_to_rgb12_fg(*attrs);
    283282                glColor3b(((fg & 0xf00) >> 8) * 8,
    284283                          ((fg & 0x0f0) >> 4) * 8,
  • libcaca/trunk/caca/driver_x11.c

    r2056 r2057  
    3535
    3636#include "cucul.h"
    37 #include "cucul_internals.h"
    3837#include "caca.h"
    3938#include "caca_internals.h"
     
    305304        {
    306305            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);
    308307
    309308            len = 1;
    310309            while(x + len < width
    311                    && _cucul_attr_to_rgb12bg(attrs[len]) == bg)
     310                   && cucul_attr_to_rgb12_bg(attrs[len]) == bg)
    312311                len++;
    313312
     
    333332        {
    334333            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)]);
    336335
    337336            x11_put_glyph(dp, x * dp->drv.p->font_width,
  • libcaca/trunk/cucul/attr.c

    r2043 r2057  
    2525
    2626static 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. */
     31static 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) */
     38static 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};
    2743
    2844/** \brief Get the text attribute at the given coordinates.
     
    292308}
    293309
    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 */
     325unsigned int cucul_attr_to_rgb12_fg(unsigned long int attr)
    357326{
    358327    uint16_t fg = (attr >> 4) & 0x3fff;
     
    370339}
    371340
    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 */
     356unsigned int cucul_attr_to_rgb12_bg(unsigned long int attr)
    373357{
    374358    uint16_t bg = attr >> 18;
     
    386370}
    387371
    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 */
     391void cucul_attr_to_argb64(unsigned long int attr, unsigned char argb[8])
    404392{
    405393    uint16_t fg = (attr >> 4) & 0x3fff;
     
    435423}
    436424
     425/*
     426 * XXX: the following functions are local
     427 */
     428
     429static 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
     476uint32_t _cucul_attr_to_rgb24fg(uint32_t attr)
     477{
     478    return RGB12TO24(cucul_attr_to_rgb12_fg(attr));
     479}
     480
     481uint32_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  
    151151__extern unsigned char cucul_attr_to_ansi_fg(unsigned long int);
    152152__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]);
    153156/*  @} */
    154157
  • libcaca/trunk/cucul/cucul_internals.h

    r2055 r2057  
    6565
    6666/* Colour functions */
    67 extern uint16_t _cucul_attr_to_rgb12fg(uint32_t);
    68 extern uint16_t _cucul_attr_to_rgb12bg(uint32_t);
    6967extern uint32_t _cucul_attr_to_rgb24fg(uint32_t);
    7068extern uint32_t _cucul_attr_to_rgb24bg(uint32_t);
    71 extern void _cucul_attr_to_argb4(uint32_t, uint8_t[8]);
    7269
    7370/* Frames functions */
  • libcaca/trunk/cucul/export.c

    r2043 r2057  
    395395            if(cucul_attr_to_ansi_fg(lineattr[x]) < 0x10)
    396396                cur += sprintf(cur, ";color:#%.03x",
    397                                _cucul_attr_to_rgb12fg(lineattr[x]));
     397                               cucul_attr_to_rgb12_fg(lineattr[x]));
    398398            if(cucul_attr_to_ansi_bg(lineattr[x]) < 0x10)
    399399                cur += sprintf(cur, ";background-color:#%.03x",
    400                                _cucul_attr_to_rgb12bg(lineattr[x]));
     400                               cucul_attr_to_rgb12_bg(lineattr[x]));
    401401            if(lineattr[x] & CUCUL_BOLD)
    402402                cur += sprintf(cur, ";font-weight:bold");
     
    700700        {
    701701            uint8_t argb[8];
    702             _cucul_attr_to_argb4(*lineattr++, argb);
     702            cucul_attr_to_argb64(*lineattr++, argb);
    703703            cur += sprintf(cur, "1 0 translate\n %f %f %f csquare\n",
    704704                           (float)argb[1] * (1.0 / 0xf),
     
    724724            uint32_t ch = *linechar++;
    725725
    726             _cucul_attr_to_argb4(*lineattr++, argb);
     726            cucul_attr_to_argb64(*lineattr++, argb);
    727727
    728728            cur += sprintf(cur, "newpath\n");
     
    795795            cur += sprintf(cur, "<rect style=\"fill:#%.03x\" x=\"%d\" y=\"%d\""
    796796                                " width=\"6\" height=\"10\"/>\n",
    797                                 _cucul_attr_to_rgb12bg(*lineattr++),
     797                                cucul_attr_to_rgb12_bg(*lineattr++),
    798798                                x * 6, y * 10);
    799799        }
     
    818818            cur += sprintf(cur, "<text style=\"fill:#%.03x\" "
    819819                                "x=\"%d\" y=\"%d\">",
    820                                 _cucul_attr_to_rgb12fg(*lineattr++),
     820                                cucul_attr_to_rgb12_fg(*lineattr++),
    821821                                x * 6, (y * 10) + 8);
    822822
  • libcaca/trunk/cucul/font.c

    r2043 r2057  
    468468                                + ch - f->block_list[b].start];
    469469
    470             _cucul_attr_to_argb4(attr, argb);
     470            cucul_attr_to_argb64(attr, argb);
    471471
    472472            /* Step 1: unpack glyph */
Note: See TracChangeset for help on using the changeset viewer.