gradient test movie mode
Stefan Schuermans

Stefan Schuermans commited on 2016-12-18 13:33:31
Showing 1 changed files, with 38 additions and 7 deletions.

... ...
@@ -22,7 +22,8 @@ static void gen_test_movie(stBlinkenMovie **ppMovie, const char *str_format,
22 22
 {
23 23
   unsigned int height, width, channels, colors;
24 24
   enum {
25
-    ModeNone, ModeBlack, ModeWhite, ModeDots, ModeLines, ModeTrans
25
+    ModeNone, ModeBlack, ModeWhite, ModeGradient,
26
+    ModeDots, ModeLines, ModeTrans
26 27
   } mode = ModeNone;
27 28
   int fmt_ok, append, duration;
28 29
 
... ...
@@ -48,13 +49,15 @@ static void gen_test_movie(stBlinkenMovie **ppMovie, const char *str_format,
48 49
   //mode
49 50
   if (strcmp(str_mode, "black") == 0)
50 51
     mode = ModeBlack;
51
-  if (strcmp(str_mode, "white") == 0)
52
+  else if (strcmp(str_mode, "white") == 0)
52 53
     mode = ModeWhite;
53
-  if (strcmp(str_mode, "dots") == 0)
54
+  else if (strcmp(str_mode, "gradient") == 0)
55
+    mode = ModeGradient;
56
+  else if (strcmp(str_mode, "dots") == 0)
54 57
     mode = ModeDots;
55
-  if (strcmp(str_mode, "lines") == 0)
58
+  else if (strcmp(str_mode, "lines") == 0)
56 59
     mode = ModeLines;
57
-  if (strcmp(str_mode, "trans") == 0)
60
+  else if (strcmp(str_mode, "trans") == 0)
58 61
     mode = ModeTrans;
59 62
   //check
60 63
   if (! fmt_ok)
... ...
@@ -77,7 +80,8 @@ static void gen_test_movie(stBlinkenMovie **ppMovie, const char *str_format,
77 80
 
78 81
     if (*ppMovie != NULL) {
79 82
 
80
-      unsigned int y, x, c, c2, c3, o, b, yy, xx, cc, oo;
83
+      unsigned int y, x, c, c2, c3, o, b, yy, xx, cc, ccc, oo;
84
+      float fx, fy, fc;
81 85
       stBlinkenFrame *pFrame;
82 86
       height = BlinkenMovieGetHeight(*ppMovie);
83 87
       width = BlinkenMovieGetWidth(*ppMovie);
... ...
@@ -110,6 +114,29 @@ static void gen_test_movie(stBlinkenMovie **ppMovie, const char *str_format,
110 114
         BlinkenMovieAppendFrame(*ppMovie, pFrame);
111 115
         break;
112 116
 
117
+      case ModeGradient:
118
+        pFrame =
119
+            BlinkenFrameNew(height, width, channels, colors - 1,
120
+                            duration);
121
+        for (yy = 0; yy < height; yy++) {
122
+          fy = (float)yy / (float)(height - 1);
123
+          for (xx = 0; xx < width; xx++) {
124
+            fx = (float)xx / (float)(width - 1);
125
+            for (cc = 0, ccc = 0; cc < channels; cc++) {
126
+              switch (ccc) {
127
+                case 0:  fc = fx;                      ccc = 1; break;
128
+                case 1:  fc = fy;                      ccc = 2; break;
129
+                case 2:  fc = 1.0f - 0.5f * (fx + fy); ccc = 0; break;
130
+                default: fc = 0.0f;                    ccc = 0; break;
131
+              }
132
+              BlinkenFrameSetPixel(pFrame, yy, xx, cc,
133
+                                   (int)(fc * (float)(colors - 1) + .5f));
134
+            }
135
+          }
136
+        }
137
+        BlinkenMovieAppendFrame(*ppMovie, pFrame);
138
+        break;
139
+
113 140
       case ModeDots:
114 141
         for (c = 0; c < channels; c++)
115 142
           for (y = 0; y < height; y++)
... ...
@@ -319,6 +346,10 @@ static stBlinkenMovie * scroll(stBlinkenMovie *pMovie,
319 346
   // free scrolled frame
320 347
   BlinkenFrameFree(pScroll);
321 348
 
349
+  printf("scrolled %ux%u-%u/%u frame to %ux%u-%u/%u movie (direction %s)\n",
350
+         width, height, channels, maxval + 1,
351
+         new_width, new_height, channels, maxval + 1, str_direction);
352
+
322 353
   return pMovie;
323 354
 }
324 355
 
... ...
@@ -399,7 +430,7 @@ int main(int argCnt, char **args)
399 430
            "     mirror movie diagonally (/)\n"
400 431
            "  -o <file>\n"
401 432
            "     write movie to file (*.blm, *.bmm, *.bml, *.bbm)\n\n"
402
-           "test_modes: black, white, dots, lines, trans\n\n"
433
+           "test_modes: black, white, gradient, dots, lines, trans\n\n"
403 434
            "old syntax: %s <input-file> [<output-file>]\n\n",
404 435
            args[0], args[0]);
405 436
     return 0;
406 437