BlinkenArea - GitList
Repositories
Blog
Wiki
BlinkenLib
Code
Commits
Branches
Tags
Search
Tree:
c9469b6
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
tools
BlinkenConv.c
restructure directories
Stefan Schuermans
commited
c9469b6
at 2019-05-30 18:28:57
BlinkenConv.c
Blame
History
Raw
/* BlinkenLib Copyright 2004-2016 Stefan Schuermans <stefan@schuermans.info> 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> /** * @brief generate test movie * @param[in,out] *pMovie pointer to old/new/changed movie * @param[in] str_format format of new video to generate, * may be NULL for appending to video * @param[in] str_mode test movie mode: black, white, dots, lines, trans, * rainbow * @param[in] str_duration duration of each frame in ms (as string) */ 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, ModeBlack, ModeWhite, ModeGradient, ModeDots, ModeLines, ModeTrans, ModeRainbow, } mode = ModeNone; int fmt_ok, append, duration; //format if (str_format == NULL) { if (*ppMovie == NULL) { str_format = "<none>"; fmt_ok = 0; append = 0; } else { height = BlinkenMovieGetHeight(*ppMovie); width = BlinkenMovieGetWidth(*ppMovie); channels = BlinkenMovieGetChannels(*ppMovie); colors = BlinkenMovieGetMaxval(*ppMovie) + 1; fmt_ok = 1; append = 1; } } else { fmt_ok = sscanf(str_format, "%ux%u-%u/%u", &width, &height, &channels, &colors) == 4; append = 0; } //mode if (strcmp(str_mode, "black") == 0) mode = ModeBlack; else if (strcmp(str_mode, "white") == 0) mode = ModeWhite; else if (strcmp(str_mode, "gradient") == 0) mode = ModeGradient; else if (strcmp(str_mode, "dots") == 0) mode = ModeDots; else if (strcmp(str_mode, "lines") == 0) mode = ModeLines; else if (strcmp(str_mode, "trans") == 0) mode = ModeTrans; else if (strcmp(str_mode, "rainbow") == 0) mode = ModeRainbow; //check if (! fmt_ok) printf("invalid movie format \"%s\" for \"-t\" or \"-ta\"\n", str_format); else if (mode == ModeNone) printf("invalid test mode \"%s\" for \"-t\" or \"-ta\"\n", str_mode); else if (sscanf(str_duration, "%u", &duration) != 1) printf("invalid duration \"%s\" for \"-t\" or \"-ta\"\n", str_duration); else { if (! append) { 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\"" " for \"-t\" or \"-ta\"\n", width, height, channels, colors); } if (*ppMovie != NULL) { unsigned int y, x, c, c2, c3, o, b, yy, xx, cc, ccc, oo; float fx, fy, fc; stBlinkenFrame *pFrame; height = BlinkenMovieGetHeight(*ppMovie); width = BlinkenMovieGetWidth(*ppMovie); channels = BlinkenMovieGetChannels(*ppMovie); colors = BlinkenMovieGetMaxval(*ppMovie) + 1; switch (mode) { case ModeNone: break; case ModeBlack: 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, 0); BlinkenMovieAppendFrame(*ppMovie, pFrame); break; case ModeWhite: 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, colors - 1); BlinkenMovieAppendFrame(*ppMovie, pFrame); break; case ModeGradient: pFrame = BlinkenFrameNew(height, width, channels, colors - 1, duration); for (yy = 0; yy < height; yy++) { fy = (float)yy / (float)(height - 1); for (xx = 0; xx < width; xx++) { fx = (float)xx / (float)(width - 1); for (cc = 0, ccc = 0; cc < channels; cc++) { switch (ccc) { case 0: fc = fx; ccc = 1; break; case 1: fc = fy; ccc = 2; break; case 2: fc = 1.0f - 0.5f * (fx + fy); ccc = 0; break; default: fc = 0.0f; ccc = 0; break; } BlinkenFrameSetPixel(pFrame, yy, xx, cc, (int)(fc * (float)(colors - 1) + .5f)); } } } BlinkenMovieAppendFrame(*ppMovie, pFrame); 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; case ModeTrans: for (c = 0; c < channels; c++) for (b = 0; b < 2; b++) for (c2 = 0; c2 < channels; c2++) for (o = 0; o < colors - 1; o++) { pFrame = BlinkenFrameNew(height, width, channels, colors - 1, duration); for (cc = 0; cc < channels; cc++) { c3 = (cc + channels - c) % channels; oo = b ? (c3 < c2 ? 0 : c3 > c2 ? colors - 1 : colors - 1 - o) : (c3 < c2 ? colors - 1 : c3 > c2 ? 0 : o); for (yy = 0; yy < height; yy++) for (xx = 0; xx < width; xx++) BlinkenFrameSetPixel(pFrame, yy, xx, cc, oo); } BlinkenMovieAppendFrame(*ppMovie, pFrame); } break; case ModeRainbow: for (b = 0; b < width * height; b++) { 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++) { y = b + yy + xx + cc * 8; switch (y % 24) { case 0: oo = 0; break; case 1: oo = 1; break; case 2: oo = 2; break; case 3: oo = 3; break; case 4: oo = 4; break; case 5: oo = 4; break; case 6: oo = 4; break; case 7: oo = 4; break; case 8: oo = 4; break; case 9: oo = 4; break; case 10: oo = 4; break; case 11: oo = 4; break; case 12: oo = 4; break; case 13: oo = 3; break; case 14: oo = 2; break; case 15: oo = 1; break; default: oo = 0; break; } oo = oo * colors / 4; if (oo > colors - 1) oo = colors - 1; BlinkenFrameSetPixel(pFrame, yy, xx, cc, oo); } } } 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 } static void copy_rect(stBlinkenMovie *pMovie, char *str_file, const char *str_src_pos, const char *str_dim, const char *str_dest_pos) { unsigned int sy, sx, h, w, dy, dx; stBlinkenMovie *pSrcMovie; if (sscanf(str_src_pos, "%u,%u", &sx, &sy) != 2) printf("invalid source position \"%s\" for \"-C\"\n", str_src_pos); else if (sscanf(str_dim, "%ux%u", &w, &h) != 2) printf("invalid dimensions \"%s\" for \"-C\"\n", str_dim); else if (sscanf(str_dest_pos, "%u,%u", &dx, &dy) != 2) printf("invalid destination position \"%s\" for \"-C\"\n", str_dest_pos); else { pSrcMovie = BlinkenMovieLoad(str_file); if (pSrcMovie == NULL) printf("could not read movie \"%s\"\n", str_file); else { BlinkenMovieCopyRect(pMovie, dy, dx, pSrcMovie, sy, sx, h, w); BlinkenMovieFree(pSrcMovie); printf("copied %ux%u pixels from movie \"%s\" %u,%u to %u,%u\n", w, h, str_file, sx, sy, dx, dy ); } } } static stBlinkenMovie * scroll(stBlinkenMovie *pMovie, const char * str_direction, const char * str_width_height, const char * str_duration) { enum { DirNone, DirLeft, DirRight, DirUp, DirDown, } dir = DirNone; int width_height, duration, height, width, channels, maxval, new_height, new_width, sy, sx, dy, dx, steps, step; stBlinkenFrame *pScroll, *pFrame; // direction if (strcmp(str_direction, "left") == 0) dir = DirLeft; else if (strcmp(str_direction, "right") == 0) dir = DirRight; else if (strcmp(str_direction, "up") == 0) dir = DirUp; else if (strcmp(str_direction, "down") == 0) dir = DirDown; // check if (dir == DirNone) { printf("invalid direction \"%s\" for \"-S\" (left, right, up, down)\n", str_direction); return pMovie; } if (sscanf(str_width_height, "%u", &width_height) != 1 || width_height < 1) { printf("invalid width/height \"%s\" for \"-S\"\n", str_width_height); return pMovie; } if (sscanf(str_duration, "%u", &duration) != 1 || duration < 1) { printf("invalid duration \"%s\" for \"-S\"\n", str_duration); return pMovie; } if (BlinkenMovieGetFrameCnt(pMovie) < 1) { printf("empty movie not allowed for \"-S\"\n"); return pMovie; } // get number of steps height = BlinkenMovieGetHeight(pMovie); width = BlinkenMovieGetWidth(pMovie); channels = BlinkenMovieGetChannels(pMovie); maxval = BlinkenMovieGetMaxval(pMovie); new_height = height; new_width = width; sy = 0; sx = 0; dy = 1; dx = 1; switch (dir) { case DirNone: return pMovie; case DirRight: sx = 1; // prepare for sx *= steps dx = -1; // fall through case DirLeft: dy = 0; steps = width - width_height + 1; sx *= (steps - 1); // before this line, sx was 0 or 1 if (steps < 1) { printf("invalid width %u for \"-S left/right\" on movie of width %u\n", width_height, width); return pMovie; } new_width = width_height; break; case DirDown: sy = 1; // prepare for sy *= steps dy = -1; // fall through case DirUp: dx = 0; steps = height - width_height + 1; sy *= (steps - 1); // before this line, sy was 0 or 1 if (steps < 1) { printf("invalid height %u for \"-S up/down\" on movie of height %u\n", width_height, width); return pMovie; } new_height = width_height; break; } // get copy of first frame pScroll = BlinkenFrameClone(BlinkenMovieGetFrame(pMovie, 1)); BlinkenFrameSetDuration(pScroll, duration); // free old movie BlinkenMovieFree(pMovie); // create new movie scrolling the frame pMovie = BlinkenMovieNew(new_height, new_width, channels, maxval); for (step = 0; step < steps; ++step, sy += dy, sx += dx) { pFrame = BlinkenFrameClone(pScroll); BlinkenFrameCrop(pFrame, sy, sx, new_height, new_width); BlinkenMovieAppendFrame(pMovie, pFrame); } // free scrolled frame BlinkenFrameFree(pScroll); printf("scrolled %ux%u-%u/%u frame to %ux%u-%u/%u movie (direction %s)\n", width, height, channels, maxval + 1, new_width, new_height, channels, maxval + 1, str_direction); return pMovie; } int main(int argCnt, char **args) { stBlinkenMovie *pMovie; int i; char *str; unsigned int height, width, channels, colors, times, top, left; int mode; // print info printf("BlinkenLib - BlinkenConv\n" "version %d.%d.%d\n" "config " BLINKENLIB_CONFIG "\n" "Copyright 2004-2016 Stefan Schuermans <stefan@schuermans.info>\n" "Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html\n" "a blinkenarea.org project\n\n", BLINKENLIB_VERSION_MAJOR, BLINKENLIB_VERSION_MINOR, BLINKENLIB_VERSION_REVISION); // print syntax if (argCnt <= 1) { #ifdef BLINKENLIB_CFG_MNG # define MNGEXT ", *.mng" #else # define MNGEXT #endif #ifdef BLINKENLIB_CFG_GIF # define GIFEXT ", *.gif" #else # define GIFEXT #endif printf("syntax: %s <parameter> [...]\n\n" "parameters:\n" " -i <file>\n" " read movie from file (*.blm, *.bmm, *.bml, *.bbm" MNGEXT GIFEXT ")\n" " -a <file>\n" " append movie from file (*.blm, *.bmm, *.bml, *.bbm" MNGEXT GIFEXT ")\n" " -l <number>\n" " loop video a number of times\n" " -f\n" " output format, frame count and duration of movie\n" " -p\n" " print movie\n" " -r <width>x<height>-<channels>/<colors>\n" " resize movie\n" " -cr <src-x>,<src-y> <width>x<height>\n" " crop movie\n" " -s <width>x<height>\n" " scale movie\n" " -c <channels> [solid|rainbow]\n" " colorize movie\n" " -R\n" " reverse movie\n" " -ct <begin> <end>\n" " cut movie to time span from begin (in ms) till end (in ms)\n" " -dur <duration>\n" " adapt duration (in ms) of movie\n" " -maxframedur <duration>\n" " adapt maximum duration (in ms) per frame\n" " -d <first> <count>\n" " delete frames\n" " -t <width>x<height>-<channels>/<colors> <test_mode> <duration>\n" " generate a test movie (duration in ms)\n" " -ta <test_mode> <duration>\n" " generate a test movie and append it to current video\n" " -C <file> <src-x>,<src-y> <width>x<height> <dest-x>,<dest-y>\n" " copy rectangular section of other movie\n" " -S {left|right|up|down} <width/height> <duration>\n" " scroll first frame of current movie (duration in ms)\n" " -Rcw\n" " rotate movie 90 degrees clockwise\n" " -Rccw\n" " rotate movie 90 degrees counter-clockwise\n" " -Rh\n" " rotate movie 180 degrees\n" " -Mh\n" " mirror movie horizontally\n" " -Mv\n" " mirror movie vertically\n" " -Md\n" " mirror movie diagonally (\\)\n" " -Md2\n" " mirror movie diagonally (/)\n" " -o <file>\n" " write movie to file (*.blm, *.bmm, *.bml, *.bbm" MNGEXT GIFEXT ")\n\n" "test_modes: black, white, gradient, dots, lines, trans, rainbow\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"); } // append movie else if (strcmp(args[i], "-a") == 0) { if (i + 1 < argCnt) { i++; if (pMovie == NULL) printf("no movie loaded to append to\n"); else { stBlinkenMovie *pMovie2; pMovie2 = BlinkenMovieLoad(args[i]); if (pMovie2 == NULL) printf("could not read movie \"%s\"\n", args[i]); else { if (BlinkenMovieConcat(pMovie, pMovie2) < 0) { BlinkenMovieFree(pMovie2); printf("movie read from \"%s\" could not be appended\n", args[i]); } else printf("movie \"%s\" read and appended\n", args[i]); } } } else printf("missing input filename for \"-a\"\n"); } // loop movie else if (strcmp(args[i], "-l") == 0) { if (i + 1 < argCnt) { i++; if (sscanf(args[i], "%u", ×) != 1 || times < 1) printf("invalid number of times \"%s\"\n", args[i]); else if (pMovie == NULL) printf("no movie loaded to loop\n"); else { stBlinkenMovie *pMovie2, *pMovie3; int err = 0; unsigned int t; pMovie2 = BlinkenMovieClone(pMovie); if (pMovie2 == NULL) err = 1; else { for (t = 1 /* loop one time means nothing to do */ ; t < times; t++) { pMovie3 = BlinkenMovieClone(pMovie2); if (pMovie3 == NULL) err = 1; else { if (BlinkenMovieConcat(pMovie, pMovie3) < 0) { BlinkenMovieFree(pMovie3); err = 1; } } } BlinkenMovieFree(pMovie2); } if (err) printf("could not loop movie\n"); else printf("movie looped %u times\n", times); } } else printf("missing loop count for \"-l\"\n"); } // output format, frame count and duration of movie else if (strcmp(args[i], "-f") == 0) { if (pMovie == NULL) printf ("no movie loaded to output format, frame count and duration of\n"); else printf ("format: %ux%u-%u/%u\nframe count: %u\nduration: %u ms\n", BlinkenMovieGetWidth(pMovie), BlinkenMovieGetHeight(pMovie), BlinkenMovieGetChannels(pMovie), BlinkenMovieGetMaxval(pMovie) + 1, BlinkenMovieGetFrameCnt(pMovie), BlinkenMovieGetDuration(pMovie)); } // 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"); } // crop movie else if (strcmp(args[i], "-cr") == 0) { if (i + 2 < argCnt) { const char *topleft, *dimensions; i++; topleft = args[i]; i++; dimensions = args[i]; if (sscanf (topleft, "%u,%u", &left, &top) != 2) printf("invalid top-left position \"%s\"\n", topleft); else if (sscanf (dimensions, "%ux%u", &width, &height) != 2) printf("invalid movie dimensions \"%s\"\n", dimensions); else if (pMovie == NULL) printf("no movie loaded to crop\n"); else { BlinkenMovieCrop(pMovie, top, left, height, width); printf("movie cropped to %u,%u %ux%u\n", left, top, width, height); } } else if (i + 1 < argCnt) { printf("missing dimensions for \"-cr\"\n"); i++; } else printf("missing top-left position for \"-cr\"\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", str_channels); else { mode = BlinkenColorizerStr2Mode(str_mode); if (mode < 0) printf("invalid colorizing mode \"%s\"\n", str_mode); 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"); } // reverse movie else if (strcmp(args[i], "-R") == 0) { if (pMovie == NULL) printf("no movie loaded to reverse\n"); else { BlinkenMovieReverse(pMovie); printf("movie reversed\n"); } } // cut movie to time span else if (strcmp(args[i], "-ct") == 0) { if (i + 2 < argCnt) { const char *str_begin, *str_end; unsigned int begin, end; i++; str_begin = args[i]; i++; str_end = args[i]; if (sscanf(str_begin, "%u", &begin) != 1) printf("invalid begin time \"%s\"\n", str_begin); else if (sscanf(str_end, "%u", &end) != 1) printf("invalid end time \"%s\"\n", str_end); else if (pMovie == NULL) printf("no movie loaded to cut to time span\n"); else { BlinkenMovieCutTime(pMovie, begin, end); printf("movie cut to time %u-%u\n", begin, end); } } else if (i + 1 < argCnt) { printf("missing end time for \"-ct\"\n"); i++; } else printf("missing begin time for \"-ct\"\n"); } // adapt duration of movie else if (strcmp(args[i], "-dur") == 0) { if (i + 1 < argCnt) { unsigned int duration; i++; if (sscanf(args[i], "%u", &duration) != 1) printf("invalid duration \"%s\"\n", args[i]); else if (pMovie == NULL) printf("no movie loaded to adapt duration of\n"); else { BlinkenMovieAdaptDuration(pMovie, duration); printf("duration adapted to %u ms\n", duration); } } else printf("missing new duration for movie for \"-dur\"\n"); } // adapt maximum frame duration else if (strcmp(args[i], "-maxframedur") == 0) { if (i + 1 < argCnt) { unsigned int duration; i++; if (sscanf(args[i], "%u", &duration) != 1) printf("invalid duration \"%s\"\n", args[i]); else if (pMovie == NULL) printf("no movie loaded to adapt maximum frame duration of\n"); else { BlinkenMovieAdaptMaxFrameDuration(pMovie, duration); printf("maximum frame duration adapted to %u ms\n", duration); } } else printf("missing maximum frame duration for \"-maxframedur\"\n"); } // delete frames else if (strcmp(args[i], "-d") == 0) { if (i + 2 < argCnt) { const char *str_first, *str_count; unsigned int first, count, c; i++; str_first = args[i]; i++; str_count = args[i]; if (sscanf(str_first, "%u", &first) != 1) printf("invalid number of first frame \"%s\"\n", str_first); else { if (sscanf(str_count, "%u", &count) != 1) printf("invalid number of frames \"%s\"\n", str_count); else if (pMovie == NULL) printf("no movie loaded to delete frames from\n"); else if (first + count > (unsigned int)BlinkenMovieGetFrameCnt(pMovie)) printf ("invalid frame range (%u-%u) for deletion from %u frames\n", first, first + count, (unsigned int)BlinkenMovieGetFrameCnt(pMovie)); else { for (c = 0; c < count; c++) BlinkenMovieDeleteFrame(pMovie, first); printf("deleted frames %u-%u\n", first, first + count); } } } else if (i + 1 < argCnt) { printf("missing number of frames for \"-d\"\n"); i++; } else printf("missing number of first frame for \"-d\"\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"); } // generate test movie and append it to current video else if (strcmp(args[i], "-ta") == 0) { if (i + 2 < argCnt) { const char *str_mode, *str_duration; i++; str_mode = args[i]; i++; str_duration = args[i]; if (pMovie == NULL) printf("no movie loaded to append to\n"); else gen_test_movie(&pMovie, NULL /* append */, str_mode, str_duration); } else if (i + 1 < argCnt) { printf("missing duration for \"-ta\"\n"); i += 1; } else if (i < argCnt) printf("missing test mode for \"-ta\"\n"); } // copy rectangular section of other movie else if (strcmp(args[i], "-C") == 0) { if (i + 4 < argCnt) { char *str_file; const char *str_src_pos, *str_dim, *str_dest_pos; i++; str_file = args[i]; i++; str_src_pos = args[i]; i++; str_dim = args[i]; i++; str_dest_pos = args[i]; copy_rect(pMovie, str_file, str_src_pos, str_dim, str_dest_pos); } else if (i + 3 < argCnt) { printf("missing destination position for \"-C\"\n"); i += 3; } else if (i + 2 < argCnt) { printf("missing dimensions for \"-C\"\n"); i += 2; } else if (i + 1 < argCnt) { printf("missing source position for \"-C\"\n"); i++; } else printf("missing file name of source movie for \"-C\"\n"); } // scroll first frame of current movie else if (strcmp(args[i], "-S") == 0) { if (i + 3 < argCnt) { const char *str_direction, *str_width_height, *str_duration; i++; str_direction = args[i]; i++; str_width_height = args[i]; i++; str_duration = args[i]; pMovie = scroll(pMovie, str_direction, str_width_height, str_duration); } else if (i + 2 < argCnt) { printf("missing duration for \"-S\"\n"); i += 2; } else if (i + 1 < argCnt) { printf("missing width/height for \"-S\"\n"); i++; } else printf("missing direction (left, right, up, down) for \"-S\"\n"); } // rotate movie 90 degrees clockwise else if (strcmp(args[i], "-Rcw") == 0) { if (pMovie == NULL) printf("no movie loaded to rotate\n"); else { BlinkenMovieRotateCw(pMovie); printf("movie rotated 90 degrees clockwise\n"); } } // rotate movie 90 degrees counter-clockwise else if (strcmp(args[i], "-Rccw") == 0) { if (pMovie == NULL) printf("no movie loaded to rotate\n"); else { BlinkenMovieRotateCcw(pMovie); printf("movie rotated 90 degrees counter-clockwise\n"); } } // rotate movie 180 degrees else if (strcmp(args[i], "-Rh") == 0) { if (pMovie == NULL) printf("no movie loaded to rotate\n"); else { BlinkenMovieRotateHalf(pMovie); printf("movie rotated 180 degrees\n"); } } // mirror movie horizontally else if (strcmp(args[i], "-Mh") == 0) { if (pMovie == NULL) printf("no movie loaded to mirror\n"); else { BlinkenMovieMirrorHor(pMovie); printf("movie mirrored horizontally\n"); } } // mirror movie vertically else if (strcmp(args[i], "-Mv") == 0) { if (pMovie == NULL) printf("no movie loaded to mirror\n"); else { BlinkenMovieMirrorVer(pMovie); printf("movie mirrored vertically\n"); } } // mirror movie diagonally else if (strcmp(args[i], "-Md") == 0) { if (pMovie == NULL) printf("no movie loaded to mirror\n"); else { BlinkenMovieMirrorDiag(pMovie); printf("movie mirrored diagonally (\\)\n"); } } // mirror movie diagonally else if (strcmp(args[i], "-Md2") == 0) { if (pMovie == NULL) printf("no movie loaded to mirror\n"); else { BlinkenMovieMirrorDiag2(pMovie); printf("movie mirrored diagonally (/)\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; }