Changeset 2602:f6e482947cde in roaraudio for libroarlight


Ignore:
Timestamp:
09/11/09 03:30:19 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

very basic function to convert colors to string

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroarlight/colors.c

    r1941 r2602  
    121121} 
    122122 
     123int roar_color_to_string  (struct roar_color * c, char * str, size_t len) { 
     124 size_t needlen; 
     125 
     126 if ( c == NULL || str == NULL || len == 0 ) 
     127  return -1; 
     128 
     129 // just to be sure: 
     130 if ( len >= 1 ) 
     131  *str = 0; 
     132 
     133 switch (c->system) { 
     134  case ROAR_COLORSYSTEM_NONE: needlen = 6; break; // '(none)' 
     135  case ROAR_COLORSYSTEM_RGB:  needlen = 7; break; // '#RRGGBB' 
     136  default: 
     137    return -1; 
     138 } 
     139 
     140 needlen++; // terminating \0 
     141 
     142 if ( needlen > len ) 
     143  return -1; 
     144 
     145 switch (c->system) { 
     146  case ROAR_COLORSYSTEM_NONE: 
     147    strcpy(str, "(none)"); 
     148   break; 
     149  case ROAR_COLORSYSTEM_RGB: 
     150    snprintf(str, 8, "#%.2X%.2X%.2X", c->color.rgb.r, c->color.rgb.g, c->color.rgb.b); 
     151   break; 
     152 } 
     153 
     154 return 0; 
     155} 
     156 
     157int roar_color_to_blob    (struct roar_color * c, char * blob, size_t len); 
     158int roar_color_from_blob  (struct roar_color * c, char * blob, size_t len); 
     159 
    123160//ll 
Note: See TracChangeset for help on using the changeset viewer.