BlinkenArea - GitList
Repositories
Blog
Wiki
BlinkenLib
Code
Commits
Branches
Tags
Search
Tree:
f46f6ac
Branches
Tags
master
v0.1
v0.2
v0.3
v0.3.1
v0.4
v0.4.1
v0.5
v0.5.1
v0.5.2
v0.5.3
v0.5.4
v0.5.5
v0.6.0
v0.6.1
v0.6.2
v0.6.3
v0.6.4
v0.6.5
v0.6.6
v0.6.7
v0.6.8
v0.6.9
v0.7.0
v0.7.1
v0.7.10
v0.7.2
v0.7.3
v0.7.4
v0.7.5
v0.7.6
v0.7.7
v0.7.8
v0.7.9
v0.8.0
v0.8.1
BlinkenLib
BlinkenColorizer.c
BlinkenLib v.0.5.3 (2007-12-28)
Christian Heimke
commited
f46f6ac
at 2011-07-15 09:05:20
BlinkenColorizer.c
Blame
History
Raw
/* BlinkenLib * version 0.5.3 date 2007-12-28 * Copyright 2004-2007 Stefan Schuermans <stefan@schuermans.info> * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html * a blinkenarea.org project */ #include <string.h> #include "Tools.h" #include "BlinkenColorizer.h" unsigned char BlinkenColorizerSolid( int step, int channels, int y, int x, int c ) { int substep, updown, chan; step %= channels * 2 * 254; substep = step % 254; updown = (step / 254) % 2; chan = (step / 254) / 2; if( updown == 0 ) { if( c == chan ) return 255; else if( c == (chan + 1) % channels ) return substep; else return 0; } else { if( c == chan ) return 255 - substep; else if( c == (chan + 1) % channels ) return 255; else return 0; } y = x = 0; // keep compiler quiet } unsigned char BlinkenColorizerRainbow( int step, int channels, int y, int x, int c ) { return BlinkenColorizerSolid( step + ((x + y) * 64), channels, y, x, c ); } // type describing a colorizing modes typedef struct _BlinkenColorizingModeDesc { const char * name; unsigned char (* func)( int step, int channels, int y, int x, int c ); } BlinkenColorizingModeDesc; // supported colorizing modes static const BlinkenColorizingModeDesc BlinkenColorizingModeDescs[] = { { "solid", BlinkenColorizerSolid }, { "rainbow", BlinkenColorizerRainbow }, }; // convert string to colorizing mode // returns colorizing mode (>= 0) or -1 on error int BlinkenColorizerStr2Mode( const char * str ) { unsigned int i; for( i = 0; i < arr_cnt( BlinkenColorizingModeDescs ); i++ ) if( strcmp( str, BlinkenColorizingModeDescs[i].name ) == 0 ) break; if( i < arr_cnt( BlinkenColorizingModeDescs ) ) return i; return -1; } // convert colorizing mode to string const char * BlinkenColorizerMode2Str( int mode ) { if( mode < 0 || mode >= (int)arr_cnt( BlinkenColorizingModeDescs ) ) return "(unknown)"; return BlinkenColorizingModeDescs[mode].name; } // get color for colorizing unsigned char BlinkenColorizerGetColor( int channels, int mode, int step, int y, int x, int c ) { if( mode < 0 || mode >= (int)arr_cnt( BlinkenColorizingModeDescs ) ) return 255; return BlinkenColorizingModeDescs[mode].func( step, channels, y, x, c ); }