Stefan Schuermans commited on 2014-05-10 12:27:33
Showing 2 changed files, with 63 additions and 10 deletions.
| ... | ... |
@@ -9,6 +9,14 @@ |
| 9 | 9 |
|
| 10 | 10 |
#include <BlinkenLib/BlinkenLib.h> |
| 11 | 11 |
|
| 12 |
+/** |
|
| 13 |
+ * @brief generate test movie |
|
| 14 |
+ * @param[in,out] *pMovie pointer to old/new/changed movie |
|
| 15 |
+ * @param[in] str_format format of new video to generate, |
|
| 16 |
+ * may be NULL for appending to video |
|
| 17 |
+ * @param[in] str_mode test movie mode: black, white, dots, lines, trans |
|
| 18 |
+ * @param[in] str_duration duration of each frame in ms (as string) |
|
| 19 |
+ */ |
|
| 12 | 20 |
static void gen_test_movie(stBlinkenMovie **ppMovie, const char *str_format, |
| 13 | 21 |
const char *str_mode, const char *str_duration) |
| 14 | 22 |
{
|
| ... | ... |
@@ -16,8 +24,28 @@ static void gen_test_movie(stBlinkenMovie **ppMovie, const char *str_format, |
| 16 | 24 |
enum {
|
| 17 | 25 |
ModeNone, ModeBlack, ModeWhite, ModeDots, ModeLines, ModeTrans |
| 18 | 26 |
} mode = ModeNone; |
| 19 |
- int duration; |
|
| 27 |
+ int fmt_ok, append, duration; |
|
| 20 | 28 |
|
| 29 |
+ //format |
|
| 30 |
+ if (str_format == NULL) {
|
|
| 31 |
+ if (*ppMovie == NULL) {
|
|
| 32 |
+ str_format = "<none>"; |
|
| 33 |
+ fmt_ok = 0; |
|
| 34 |
+ append = 0; |
|
| 35 |
+ } else {
|
|
| 36 |
+ height = BlinkenMovieGetHeight(*ppMovie); |
|
| 37 |
+ width = BlinkenMovieGetWidth(*ppMovie); |
|
| 38 |
+ channels = BlinkenMovieGetChannels(*ppMovie); |
|
| 39 |
+ colors = BlinkenMovieGetMaxval(*ppMovie) + 1; |
|
| 40 |
+ fmt_ok = 1; |
|
| 41 |
+ append = 1; |
|
| 42 |
+ } |
|
| 43 |
+ } else {
|
|
| 44 |
+ fmt_ok = sscanf(str_format, "%ux%u-%u/%u", |
|
| 45 |
+ &width, &height, &channels, &colors) == 4; |
|
| 46 |
+ append = 0; |
|
| 47 |
+ } |
|
| 48 |
+ //mode |
|
| 21 | 49 |
if (strcmp(str_mode, "black") == 0) |
| 22 | 50 |
mode = ModeBlack; |
| 23 | 51 |
if (strcmp(str_mode, "white") == 0) |
| ... | ... |
@@ -28,22 +56,26 @@ static void gen_test_movie(stBlinkenMovie **ppMovie, const char *str_format, |
| 28 | 56 |
mode = ModeLines; |
| 29 | 57 |
if (strcmp(str_mode, "trans") == 0) |
| 30 | 58 |
mode = ModeTrans; |
| 31 |
- if (sscanf(str_format, "%ux%u-%u/%u", &width, &height, &channels, &colors) |
|
| 32 |
- != 4) |
|
| 33 |
- printf("invalid movie format \"%s\" for \"-t\"\n", str_format);
|
|
| 59 |
+ //check |
|
| 60 |
+ if (! fmt_ok) |
|
| 61 |
+ printf("invalid movie format \"%s\" for \"-t\" or \"-ta\"\n", str_format);
|
|
| 34 | 62 |
else if (mode == ModeNone) |
| 35 |
- printf("invalid test mode \"%s\" for \"-t\"\n", str_mode);
|
|
| 63 |
+ printf("invalid test mode \"%s\" for \"-t\" or \"-ta\"\n", str_mode);
|
|
| 36 | 64 |
else if (sscanf(str_duration, "%u", &duration) != 1) |
| 37 |
- printf("invalid duration \"%s\" for \"-t\"\n", str_duration);
|
|
| 65 |
+ printf("invalid duration \"%s\" for \"-t\" or \"-ta\"\n", str_duration);
|
|
| 38 | 66 |
else {
|
| 39 | 67 |
|
| 68 |
+ if (! append) {
|
|
| 40 | 69 |
if (*ppMovie != NULL) |
| 41 | 70 |
BlinkenMovieFree(*ppMovie); |
| 42 | 71 |
*ppMovie = BlinkenMovieNew(height, width, channels, colors - 1); |
| 43 | 72 |
if (*ppMovie == NULL) |
| 44 |
- printf("could not create movie with format \"%ux%u-%x/%u\" for \"-t\"\n",
|
|
| 73 |
+ printf("could not create movie with format \"%ux%u-%x/%u\""
|
|
| 74 |
+ " for \"-t\" or \"-ta\"\n", |
|
| 45 | 75 |
width, height, channels, colors); |
| 46 |
- else {
|
|
| 76 |
+ } |
|
| 77 |
+ |
|
| 78 |
+ if (*ppMovie != NULL) {
|
|
| 47 | 79 |
|
| 48 | 80 |
unsigned int y, x, c, c2, c3, o, b, yy, xx, cc, oo; |
| 49 | 81 |
stBlinkenFrame *pFrame; |
| ... | ... |
@@ -229,9 +261,10 @@ int main(int argCnt, char **args) |
| 229 | 261 |
" reverse movie\n" |
| 230 | 262 |
" -d <first> <count>\n" |
| 231 | 263 |
" delete frames\n" |
| 232 |
- " -t <width>x<height>-<channels>/<colors>\n" |
|
| 233 |
- " [black|white|dots|lines|trans] <duration>\n" |
|
| 264 |
+ " -t <width>x<height>-<channels>/<colors> <test_mode> <duration>\n" |
|
| 234 | 265 |
" generate a test movie\n" |
| 266 |
+ " -ta <test_mode> <duration>\n" |
|
| 267 |
+ " generate a test movie and append it to current video\n" |
|
| 235 | 268 |
" -C <file> <src-x>,<src-y> <width>x<height> <dest-x>,<dest-y>\n" |
| 236 | 269 |
" copy rectangular section of other movie\n" |
| 237 | 270 |
" -Rcw\n" |
| ... | ... |
@@ -250,6 +283,7 @@ int main(int argCnt, char **args) |
| 250 | 283 |
" mirror movie diagonally (/)\n" |
| 251 | 284 |
" -o <file>\n" |
| 252 | 285 |
" write movie to file (*.blm, *.bmm, *.bml, *.bbm)\n\n" |
| 286 |
+ "test_modes: black, white, dots, lines, trans\n\n" |
|
| 253 | 287 |
"old syntax: %s <input-file> [<output-file>]\n\n", |
| 254 | 288 |
args[0], args[0]); |
| 255 | 289 |
return 0; |
| ... | ... |
@@ -487,6 +521,24 @@ int main(int argCnt, char **args) |
| 487 | 521 |
} else |
| 488 | 522 |
printf("missing format for \"-t\"\n");
|
| 489 | 523 |
} |
| 524 |
+ // generate test movie and append it to current video |
|
| 525 |
+ else if (strcmp(args[i], "-ta") == 0) {
|
|
| 526 |
+ if (i + 2 < argCnt) {
|
|
| 527 |
+ const char *str_mode, *str_duration; |
|
| 528 |
+ i++; |
|
| 529 |
+ str_mode = args[i]; |
|
| 530 |
+ i++; |
|
| 531 |
+ str_duration = args[i]; |
|
| 532 |
+ if (pMovie == NULL) |
|
| 533 |
+ printf("no movie loaded to append to\n");
|
|
| 534 |
+ else |
|
| 535 |
+ gen_test_movie(&pMovie, NULL /* append */, str_mode, str_duration); |
|
| 536 |
+ } else if (i + 1 < argCnt) {
|
|
| 537 |
+ printf("missing duration for \"-ta\"\n");
|
|
| 538 |
+ i += 1; |
|
| 539 |
+ } else if (i < argCnt) |
|
| 540 |
+ printf("missing test mode for \"-ta\"\n");
|
|
| 541 |
+ } |
|
| 490 | 542 |
// copy rectangular section of other movie |
| 491 | 543 |
else if (strcmp(args[i], "-C") == 0) {
|
| 492 | 544 |
if (i + 4 < argCnt) {
|
| 493 | 545 |