BlinkenArea - GitList
Repositories
Blog
Wiki
BlinkenLib
Code
Commits
Branches
Tags
Search
Tree:
a12f8ff
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
BlinkenLib
BlinkenConv.c
BlinkenLib v.0.6.3 (2009-12-20)
Christian Heimke
commited
a12f8ff
at 2011-07-15 09:09:34
BlinkenConv.c
Blame
History
Raw
/* BlinkenLib * version 0.6.3 date 2009-12-20 * Copyright 2004-2009 Stefan Schuermans <stefan@blinkenarea.org> * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html * a blinkenarea.org project */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <BlinkenLib/BlinkenLib.h> static void gen_test_movie( stBlinkenMovie * * ppMovie, const char * str_format, const char * str_mode, const char * str_duration ) { unsigned int height, width, channels, colors; enum { ModeNone, ModeDots, ModeLines } mode = ModeNone; int duration; if( strcmp( str_mode, "dots" ) == 0 ) mode = ModeDots; if( strcmp( str_mode, "lines" ) == 0 ) mode = ModeLines; if( sscanf( str_format, "%ux%u-%u/%u", &width, &height, &channels, &colors ) != 4 ) printf( "invalid movie format \"%s\"\n", str_format ); else if( mode == ModeNone ) printf( "invalid test mode \"%s\"\n", str_mode ); else if( sscanf( str_duration, "%u", &duration ) != 1 ) printf( "invalid duration \"%s\"\n", str_duration ); else { if( *ppMovie != NULL ) BlinkenMovieFree( *ppMovie ); *ppMovie = BlinkenMovieNew( height, width, channels, colors - 1 ); if( *ppMovie == NULL ) printf( "could not create movie with format \"%ux%u-%x/%u\"\n", width, height, channels, colors ); else { unsigned int y, x, c, yy, xx, cc; stBlinkenFrame * pFrame; height = BlinkenMovieGetHeight( *ppMovie ); width = BlinkenMovieGetWidth( *ppMovie ); channels = BlinkenMovieGetChannels( *ppMovie ); colors = BlinkenMovieGetMaxval( *ppMovie ) + 1; switch( mode ) { case ModeNone: break; case ModeDots: for( c = 0; c < channels; c++ ) for( y = 0; y < height; y++ ) for( x = 0; x < width; x++ ) { pFrame = BlinkenFrameNew( height, width, channels, colors - 1, duration ); for( yy = 0; yy < height; yy++ ) for( xx = 0; xx < width; xx++ ) for( cc = 0; cc < channels; cc++ ) BlinkenFrameSetPixel( pFrame, yy, xx, cc, yy == y && xx == x && cc == c ? colors - 1 : 0 ); BlinkenMovieAppendFrame( *ppMovie, pFrame ); } break; case ModeLines: for( c = 0; c < channels; c++ ) { for( x = 0; x < width; x++ ) { pFrame = BlinkenFrameNew( height, width, channels, colors - 1, duration ); for( yy = 0; yy < height; yy++ ) for( xx = 0; xx < width; xx++ ) for( cc = 0; cc < channels; cc++ ) BlinkenFrameSetPixel( pFrame, yy, xx, cc, xx == x && cc == c ? colors - 1 : 0 ); BlinkenMovieAppendFrame( *ppMovie, pFrame ); } for( y = 0; y < height; y++ ) { pFrame = BlinkenFrameNew( height, width, channels, colors - 1, duration ); for( yy = 0; yy < height; yy++ ) for( xx = 0; xx < width; xx++ ) for( cc = 0; cc < channels; cc++ ) BlinkenFrameSetPixel( pFrame, yy, xx, cc, yy == y && cc == c ? colors - 1 : 0 ); BlinkenMovieAppendFrame( *ppMovie, pFrame ); } } break; } //switch( mode ) printf( "test movie generated, using format %ux%u-%u/%u and mode %s\n", width, height, channels, colors, str_mode ); } //if( *ppMovie == NULL ) ... else } //else } int main( int argCnt, char * * args ) { stBlinkenMovie * pMovie; int i; char * str; unsigned int height, width, channels, colors; int mode; //print info printf( "BlinkenLib - BlinkenConv\n" "version 0.6.3 date 2009-12-20\n" "config "BLINKENLIB_CONFIG"\n" "Copyright 2004-2009 Stefan Schuermans <stefan@blinkenarea.org>\n" "Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n" "a blinkenarea.org project\n\n" ); //print syntax if( argCnt <= 1 ) { printf( "syntax: %s <parameter> [...]\n\n" "parameters:\n" " -i <file>\n" " read movie from file (*.blm, *.bmm, *.bml, *.bbm)\n" " -p\n" " print movie\n" " -r <width>x<height>-<channels>/<colors>\n" " resize movie\n" " -s <width>x<height>\n" " scale movie\n" " -c <channels> [solid|rainbow]\n" " colorize movie\n" " -t <width>x<height>-<channels>/<colors> [dots|lines] <duration>\n" " generate a test movie\n" " -o <file>\n" " write movie to file (*.blm, *.bmm, *.bml, *.bbm)\n\n" "old syntax: %s <input-file> [<output-file>]\n\n", args[0], args[0] ); return 0; } //no movie loaded pMovie = NULL; //process parameters for( i = 1; i < argCnt; i++ ) { //read movie if( strcmp( args[i], "-i" ) == 0 ) { if( i + 1 < argCnt ) { i++; if( pMovie != NULL ) BlinkenMovieFree( pMovie ); pMovie = BlinkenMovieLoad( args[i] ); if( pMovie == NULL ) printf( "could not read movie \"%s\"\n", args[i] ); else printf( "movie \"%s\" read\n", args[i] ); } else printf( "missing input filename for \"-i\"\n" ); } //print movie else if( strcmp( args[i], "-p" ) == 0 ) { if( pMovie == NULL ) printf( "no movie loaded to print\n" ); else { str = BlinkenMovieToString( pMovie ); if( str == NULL ) printf( "could not print movie\n" ); else { printf( "%s", str ); free( str ); } } } //resize movie else if( strcmp( args[i], "-r" ) == 0 ) { if( i + 1 < argCnt ) { i++; if( sscanf( args[i], "%ux%u-%u/%u", &width, &height, &channels, &colors ) != 4 ) printf( "invalid movie format \"%s\"\n", args[i] ); else if( pMovie == NULL ) printf( "no movie loaded to resize\n" ); else { BlinkenMovieResize( pMovie, height, width, channels, colors - 1 ); printf( "movie resized to %ux%u-%u/%u\n", width, height, channels, colors ); } } else printf( "missing movie format for \"-r\"\n" ); } //scale movie else if( strcmp( args[i], "-s" ) == 0 ) { if( i + 1 < argCnt ) { i++; if( sscanf( args[i], "%ux%u", &width, &height ) != 2 ) printf( "invalid movie dimensions \"%s\"\n", args[i] ); else if( pMovie == NULL ) printf( "no movie loaded to scale\n" ); else { BlinkenMovieScale( pMovie, height, width ); printf( "movie scaled to %ux%u\n", width, height ); } } else printf( "missing movie dimensions for \"-s\"\n" ); } //colorize movie else if( strcmp( args[i], "-c" ) == 0 ) { if( i + 2 < argCnt ) { const char * str_channels, * str_mode; i++; str_channels = args[i]; i++; str_mode = args[i]; if( sscanf( str_channels, "%u", &channels ) != 1 ) printf( "invalid number of channels \"%s\"\n", args[i] ); else { mode = BlinkenColorizerStr2Mode( str_mode ); if( mode < 0 ) printf( "invalid colorizing mode \"%s\"\n", args[i] ); else if( pMovie == NULL ) printf( "no movie loaded to colorize\n" ); else { BlinkenMovieColorize( pMovie, channels, mode ); printf( "movie colorized to %u channels using mode %s\n", channels, BlinkenColorizerMode2Str( mode ) ); } } } else if( i + 1 < argCnt ) { printf( "missing colorizing mode for \"-c\"\n" ); i++; } else printf( "missing number of channels for \"-c\"\n" ); } //generate test movie else if( strcmp( args[i], "-t" ) == 0 ) { if( i + 3 < argCnt ) { const char * str_format, * str_mode, * str_duration; i++; str_format = args[i]; i++; str_mode = args[i]; i++; str_duration = args[i]; gen_test_movie( &pMovie, str_format, str_mode, str_duration ); } else if( i + 2 < argCnt ) { printf( "missing duration for \"-t\"\n" ); i += 2; } else if( i + 1 < argCnt ) { printf( "missing test mode for \"-t\"\n" ); i++; } else printf( "missing format for \"-t\"\n" ); } //write movie else if( strcmp( args[i], "-o" ) == 0 ) { if( i + 1 < argCnt ) { i++; if( pMovie == NULL ) printf( "no movie loaded to write to \"%s\"\n", args[i] ); else if( BlinkenMovieSave( pMovie, args[i] ) < 0 ) printf( "could not write movie \"%s\"\n", args[i] ); else printf( "movie \"%s\" written\n", args[i] ); } else printf( "missing output filename for \"-o\"\n" ); } //old style input filename else if( i == 1 && args[i][0] != '-' ) { printf( "old style input filename \"%s\", better use \"-i %s\"\n", args[i], args[i] ); if( pMovie != NULL ) BlinkenMovieFree( pMovie ); pMovie = BlinkenMovieLoad( args[i] ); if( pMovie == NULL ) printf( "could not read movie \"%s\"\n", args[i] ); else printf( "movie \"%s\" read\n", args[i] ); } //old style output filename else if( i == 2 && args[i][0] != '-' ) { printf( "old style output filename \"%s\", better use \"-o %s\"\n", args[i], args[i] ); if( pMovie == NULL ) printf( "no movie loaded to write to \"%s\"\n", args[i] ); else if( BlinkenMovieSave( pMovie, args[i] ) < 0 ) printf( "could not write movie \"%s\"\n", args[i] ); else printf( "movie \"%s\" written\n", args[i] ); } //unknown parameter else printf( "unknown parameter \"%s\", call without parameters to get help\n", args[i] ); } //for( i ... //old style print if( argCnt == 2 && pMovie != NULL ) { str = BlinkenMovieToString( pMovie ); if( str == NULL ) printf( "could not print movie\n" ); else { printf( "%s", str ); free( str ); } } //free movie if( pMovie != NULL ) BlinkenMovieFree( pMovie ); return 0; }