changed indenting to be more standard
Stefan Schuermans

Stefan Schuermans commited on 2011-10-16 11:26:43
Showing 18 changed files, with 1340 additions and 1326 deletions.

... ...
@@ -1,15 +1,14 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #include <string.h>
8 6
 
9 7
 #include <BlinkenLib/Tools.h>
10 8
 #include <BlinkenLib/BlinkenColorizer.h>
11 9
 
12
-unsigned char BlinkenColorizerSolid( int step, int channels, int y, int x, int c )
10
+unsigned char BlinkenColorizerSolid(int step, int channels, int y, int x,
11
+                                    int c)
13 12
 {
14 13
   int substep, updown, chan;
15 14
   step %= channels * 2 * 254;
... ...
@@ -34,14 +33,14 @@ unsigned char BlinkenColorizerSolid( int step, int channels, int y, int x, int c
34 33
   y = x = 0;    // keep compiler quiet
35 34
 }
36 35
 
37
-unsigned char BlinkenColorizerRainbow( int step, int channels, int y, int x, int c )
36
+unsigned char BlinkenColorizerRainbow(int step, int channels, int y, int x,
37
+                                      int c)
38 38
 {
39 39
   return BlinkenColorizerSolid(step + ((x + y) * 64), channels, y, x, c);
40 40
 }
41 41
 
42 42
 // type describing a colorizing modes
43
-typedef struct _BlinkenColorizingModeDesc
44
-{
43
+typedef struct _BlinkenColorizingModeDesc {
45 44
   const char *name;
46 45
   unsigned char (*func) (int step, int channels, int y, int x, int c);
47 46
 } BlinkenColorizingModeDesc;
... ...
@@ -74,7 +73,8 @@ const char * BlinkenColorizerMode2Str( int mode )
74 73
 }
75 74
 
76 75
 // get color for colorizing
77
-unsigned char BlinkenColorizerGetColor( int channels, int mode, int step, int y, int x, int c )
76
+unsigned char BlinkenColorizerGetColor(int channels, int mode, int step,
77
+                                       int y, int x, int c)
78 78
 {
79 79
   if (mode < 0 || mode >= (int)arr_cnt(BlinkenColorizingModeDescs))
80 80
     return 255;
... ...
@@ -1,8 +1,6 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #ifndef INC_BlinkenLib_BlinkenColorizer
8 6
 #define INC_BlinkenLib_BlinkenColorizer
... ...
@@ -15,7 +13,7 @@ int BlinkenColorizerStr2Mode( const char * str );
15 13
 const char *BlinkenColorizerMode2Str(int mode);
16 14
 
17 15
 // get color for colorizing
18
-unsigned char BlinkenColorizerGetColor( int channels, int mode, int step, int y, int x, int c );
16
+unsigned char BlinkenColorizerGetColor(int channels, int mode, int step,
17
+                                       int y, int x, int c);
19 18
 
20 19
 #endif // #ifndef INC_BlinkenLib_BlinkenColorizer
21
-
... ...
@@ -1,8 +1,6 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #ifndef INC_BlinkenLib_BlinkenConstants
8 6
 #define INC_BlinkenLib_BlinkenConstants
... ...
@@ -1,8 +1,6 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #include <stdio.h>
8 6
 #include <stdlib.h>
... ...
@@ -10,7 +8,8 @@
10 8
 
11 9
 #include <BlinkenLib/BlinkenLib.h>
12 10
 
13
-static void gen_test_movie( stBlinkenMovie * * ppMovie, const char * str_format, const char * str_mode, const char * str_duration )
11
+static void gen_test_movie(stBlinkenMovie ** ppMovie, const char *str_format,
12
+                           const char *str_mode, const char *str_duration)
14 13
 {
15 14
   unsigned int height, width, channels, colors;
16 15
   enum { ModeNone, ModeDots, ModeLines, ModeTrans } mode = ModeNone;
... ...
@@ -22,22 +21,22 @@ static void gen_test_movie( stBlinkenMovie * * ppMovie, const char * str_format,
22 21
     mode = ModeLines;
23 22
   if (strcmp(str_mode, "trans") == 0)
24 23
     mode = ModeTrans;
25
-  if( sscanf( str_format, "%ux%u-%u/%u", &width, &height, &channels, &colors ) != 4 )
24
+  if (sscanf(str_format, "%ux%u-%u/%u", &width, &height, &channels, &colors)
25
+      != 4)
26 26
     printf("invalid movie format \"%s\"\n", str_format);
27 27
   else if (mode == ModeNone)
28 28
     printf("invalid test mode \"%s\"\n", str_mode);
29 29
   else if (sscanf(str_duration, "%u", &duration) != 1)
30 30
     printf("invalid duration \"%s\"\n", str_duration);
31
-  else
32
-  {
31
+  else {
33 32
 
34 33
     if (*ppMovie != NULL)
35 34
       BlinkenMovieFree(*ppMovie);
36 35
     *ppMovie = BlinkenMovieNew(height, width, channels, colors - 1);
37 36
     if (*ppMovie == NULL)
38
-      printf( "could not create movie with format \"%ux%u-%x/%u\"\n", width, height, channels, colors );
39
-    else
40
-    {
37
+      printf("could not create movie with format \"%ux%u-%x/%u\"\n", width,
38
+             height, channels, colors);
39
+    else {
41 40
 
42 41
       unsigned int y, x, c, c2, c3, o, b, yy, xx, cc, oo;
43 42
       stBlinkenFrame *pFrame;
... ...
@@ -54,12 +53,15 @@ static void gen_test_movie( stBlinkenMovie * * ppMovie, const char * str_format,
54 53
         for (c = 0; c < channels; c++)
55 54
           for (y = 0; y < height; y++)
56 55
             for (x = 0; x < width; x++) {
57
-            pFrame = BlinkenFrameNew( height, width, channels, colors - 1, duration );
56
+              pFrame =
57
+                  BlinkenFrameNew(height, width, channels, colors - 1,
58
+                                  duration);
58 59
               for (yy = 0; yy < height; yy++)
59 60
                 for (xx = 0; xx < width; xx++)
60 61
                   for (cc = 0; cc < channels; cc++)
61 62
                     BlinkenFrameSetPixel(pFrame, yy, xx, cc,
62
-                yy == y && xx == x && cc == c ? colors - 1 : 0 );
63
+                                         yy == y && xx == x
64
+                                         && cc == c ? colors - 1 : 0);
63 65
               BlinkenMovieAppendFrame(*ppMovie, pFrame);
64 66
             }
65 67
         break;
... ...
@@ -67,7 +69,9 @@ static void gen_test_movie( stBlinkenMovie * * ppMovie, const char * str_format,
67 69
       case ModeLines:
68 70
         for (c = 0; c < channels; c++) {
69 71
           for (x = 0; x < width; x++) {
70
-              pFrame = BlinkenFrameNew( height, width, channels, colors - 1, duration );
72
+            pFrame =
73
+                BlinkenFrameNew(height, width, channels, colors - 1,
74
+                                duration);
71 75
             for (yy = 0; yy < height; yy++)
72 76
               for (xx = 0; xx < width; xx++)
73 77
                 for (cc = 0; cc < channels; cc++)
... ...
@@ -76,7 +80,9 @@ static void gen_test_movie( stBlinkenMovie * * ppMovie, const char * str_format,
76 80
             BlinkenMovieAppendFrame(*ppMovie, pFrame);
77 81
           }
78 82
           for (y = 0; y < height; y++) {
79
-              pFrame = BlinkenFrameNew( height, width, channels, colors - 1, duration );
83
+            pFrame =
84
+                BlinkenFrameNew(height, width, channels, colors - 1,
85
+                                duration);
80 86
             for (yy = 0; yy < height; yy++)
81 87
               for (xx = 0; xx < width; xx++)
82 88
                 for (cc = 0; cc < channels; cc++)
... ...
@@ -92,10 +98,13 @@ static void gen_test_movie( stBlinkenMovie * * ppMovie, const char * str_format,
92 98
           for (b = 0; b < 2; b++)
93 99
             for (c2 = 0; c2 < channels; c2++)
94 100
               for (o = 0; o < colors - 1; o++) {
95
-            pFrame = BlinkenFrameNew( height, width, channels, colors - 1, duration );
101
+                pFrame =
102
+                    BlinkenFrameNew(height, width, channels, colors - 1,
103
+                                    duration);
96 104
                 for (cc = 0; cc < channels; cc++) {
97 105
                   c3 = (cc + channels - c) % channels;
98
-              oo = b ? (c3 < c2 ? 0          : c3 > c2 ? colors - 1 : colors - 1 - o)
106
+                  oo = b ? (c3 < c2 ? 0 : c3 >
107
+                            c2 ? colors - 1 : colors - 1 - o)
99 108
                       : (c3 < c2 ? colors - 1 : c3 > c2 ? 0 : o);
100 109
                   for (yy = 0; yy < height; yy++)
101 110
                     for (xx = 0; xx < width; xx++)
... ...
@@ -130,11 +139,11 @@ int main( int argCnt, char * * args )
130 139
          "Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>\n"
131 140
          "Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n"
132 141
          "a blinkenarea.org project\n\n",
133
-          BLINKENLIB_VERSION_MAJOR, BLINKENLIB_VERSION_MINOR, BLINKENLIB_VERSION_REVISION );
142
+         BLINKENLIB_VERSION_MAJOR, BLINKENLIB_VERSION_MINOR,
143
+         BLINKENLIB_VERSION_REVISION);
134 144
 
135 145
   // print syntax
136
-  if( argCnt <= 1 )
137
-  {
146
+  if (argCnt <= 1) {
138 147
     printf("syntax: %s <parameter> [...]\n\n"
139 148
            "parameters:\n"
140 149
            "  -i <file>\n"
... ...
@@ -170,14 +178,11 @@ int main( int argCnt, char * * args )
170 178
   pMovie = NULL;
171 179
 
172 180
   // process parameters
173
-  for( i = 1; i < argCnt; i++ )
174
-  {
181
+  for (i = 1; i < argCnt; i++) {
175 182
 
176 183
     // read movie
177
-    if( strcmp( args[i], "-i" ) == 0 )
178
-    {
179
-      if( i + 1 < argCnt )
180
-      {
184
+    if (strcmp(args[i], "-i") == 0) {
185
+      if (i + 1 < argCnt) {
181 186
         i++;
182 187
         if (pMovie != NULL)
183 188
           BlinkenMovieFree(pMovie);
... ...
@@ -186,16 +191,12 @@ int main( int argCnt, char * * args )
186 191
           printf("could not read movie \"%s\"\n", args[i]);
187 192
         else
188 193
           printf("movie \"%s\" read\n", args[i]);
189
-      }
190
-      else
194
+      } else
191 195
         printf("missing input filename for \"-i\"\n");
192 196
     }
193
-
194 197
     // append movie
195
-    else if( strcmp( args[i], "-a" ) == 0 )
196
-    {
197
-      if( i + 1 < argCnt )
198
-      {
198
+    else if (strcmp(args[i], "-a") == 0) {
199
+      if (i + 1 < argCnt) {
199 200
         i++;
200 201
         if (pMovie == NULL)
201 202
           printf("no movie loaded to append to\n");
... ...
@@ -207,28 +208,24 @@ int main( int argCnt, char * * args )
207 208
           else {
208 209
             if (BlinkenMovieConcat(pMovie, pMovie2) < 0) {
209 210
               BlinkenMovieFree(pMovie2);
210
-              printf( "movie read from \"%s\" could not be appended\n", args[i] );
211
+              printf("movie read from \"%s\" could not be appended\n",
212
+                     args[i]);
211 213
             } else
212 214
               printf("movie \"%s\" read and appended\n", args[i]);
213 215
           }
214 216
         }
215
-      }
216
-      else
217
+      } else
217 218
         printf("missing input filename for \"-a\"\n");
218 219
     }
219
-
220 220
     // loop movie
221
-    else if( strcmp( args[i], "-l" ) == 0 )
222
-    {
223
-      if( i + 1 < argCnt )
224
-      {
221
+    else if (strcmp(args[i], "-l") == 0) {
222
+      if (i + 1 < argCnt) {
225 223
         i++;
226 224
         if (sscanf(args[i], "%u", &times) != 1 || times < 1)
227 225
           printf("invalid number of times \"%s\"\n", args[i]);
228 226
         else if (pMovie == NULL)
229 227
           printf("no movie loaded to loop\n");
230
-        else
231
-        {
228
+        else {
232 229
           stBlinkenMovie *pMovie2, *pMovie3;
233 230
           int err = 0;
234 231
           unsigned int t;
... ...
@@ -236,7 +233,8 @@ int main( int argCnt, char * * args )
236 233
           if (pMovie2 == NULL)
237 234
             err = 1;
238 235
           else {
239
-            for( t = 1 /* loop one time means nothing to do */; t < times; t++ ) {
236
+            for (t = 1 /* loop one time means nothing to do */ ; t < times;
237
+                 t++) {
240 238
               pMovie3 = BlinkenMovieClone(pMovie2);
241 239
               if (pMovie3 == NULL)
242 240
                 err = 1;
... ...
@@ -254,89 +252,73 @@ int main( int argCnt, char * * args )
254 252
           else
255 253
             printf("movie looped %u times\n", times);
256 254
         }
257
-      }
258
-      else
255
+      } else
259 256
         printf("missing movie format for \"-r\"\n");
260 257
     }
261
-
262 258
     // output format, frame count and duration of movie
263
-    else if( strcmp( args[i], "-f" ) == 0 )
264
-    {
259
+    else if (strcmp(args[i], "-f") == 0) {
265 260
       if (pMovie == NULL)
266
-        printf( "no movie loaded to output format, frame count and duration of\n" );
261
+        printf
262
+            ("no movie loaded to output format, frame count and duration of\n");
267 263
       else
268
-        printf( "format:      %ux%u-%u/%u\nframe count: %u\nduration:    %u ms\n",
269
-               BlinkenMovieGetWidth( pMovie ),
270
-               BlinkenMovieGetHeight( pMovie ),
264
+        printf
265
+            ("format:      %ux%u-%u/%u\nframe count: %u\nduration:    %u ms\n",
266
+             BlinkenMovieGetWidth(pMovie), BlinkenMovieGetHeight(pMovie),
271 267
              BlinkenMovieGetChannels(pMovie),
272 268
              BlinkenMovieGetMaxval(pMovie) + 1,
273 269
              BlinkenMovieGetFrameCnt(pMovie),
274 270
              BlinkenMovieGetDuration(pMovie));
275 271
     }
276
-
277 272
     // print movie
278
-    else if( strcmp( args[i], "-p" ) == 0 )
279
-    {
273
+    else if (strcmp(args[i], "-p") == 0) {
280 274
       if (pMovie == NULL)
281 275
         printf("no movie loaded to print\n");
282
-      else
283
-      {
276
+      else {
284 277
         str = BlinkenMovieToString(pMovie);
285 278
         if (str == NULL)
286 279
           printf("could not print movie\n");
287
-        else
288
-        {
280
+        else {
289 281
           printf("%s", str);
290 282
           free(str);
291 283
         }
292 284
       }
293 285
     }
294
-
295 286
     // resize movie
296
-    else if( strcmp( args[i], "-r" ) == 0 )
297
-    {
298
-      if( i + 1 < argCnt )
299
-      {
287
+    else if (strcmp(args[i], "-r") == 0) {
288
+      if (i + 1 < argCnt) {
300 289
         i++;
301
-        if( sscanf( args[i], "%ux%u-%u/%u", &width, &height, &channels, &colors ) != 4 )
290
+        if (sscanf
291
+            (args[i], "%ux%u-%u/%u", &width, &height, &channels,
292
+             &colors) != 4)
302 293
           printf("invalid movie format \"%s\"\n", args[i]);
303 294
         else if (pMovie == NULL)
304 295
           printf("no movie loaded to resize\n");
305
-        else
306
-        {
296
+        else {
307 297
           BlinkenMovieResize(pMovie, height, width, channels, colors - 1);
308
-          printf( "movie resized to %ux%u-%u/%u\n", width, height, channels, colors );
309
-        }
298
+          printf("movie resized to %ux%u-%u/%u\n", width, height, channels,
299
+                 colors);
310 300
         }
311
-      else
301
+      } else
312 302
         printf("missing movie format for \"-r\"\n");
313 303
     }
314
-
315 304
     // scale movie
316
-    else if( strcmp( args[i], "-s" ) == 0 )
317
-    {
318
-      if( i + 1 < argCnt )
319
-      {
305
+    else if (strcmp(args[i], "-s") == 0) {
306
+      if (i + 1 < argCnt) {
320 307
         i++;
321 308
         if (sscanf(args[i], "%ux%u", &width, &height) != 2)
322 309
           printf("invalid movie dimensions \"%s\"\n", args[i]);
323 310
         else if (pMovie == NULL)
324 311
           printf("no movie loaded to scale\n");
325
-        else
326
-        {
312
+        else {
327 313
           BlinkenMovieScale(pMovie, height, width);
328 314
           printf("movie scaled to %ux%u\n", width, height);
329 315
         }
330
-      }
331
-      else
316
+      } else
332 317
         printf("missing movie dimensions for \"-s\"\n");
333 318
     }
334
-
335 319
     // colorize movie
336
-    else if( strcmp( args[i], "-c" ) == 0 )
337
-    {
338
-      if( i + 2 < argCnt )
339
-      {
320
+    else if (strcmp(args[i], "-c") == 0) {
321
+      if (i + 2 < argCnt) {
340 322
         const char *str_channels, *str_mode;
341 323
         i++;
342 324
         str_channels = args[i];
... ...
@@ -344,32 +326,26 @@ int main( int argCnt, char * * args )
344 326
         str_mode = args[i];
345 327
         if (sscanf(str_channels, "%u", &channels) != 1)
346 328
           printf("invalid number of channels \"%s\"\n", str_channels);
347
-        else
348
-        {
329
+        else {
349 330
           mode = BlinkenColorizerStr2Mode(str_mode);
350 331
           if (mode < 0)
351 332
             printf("invalid colorizing mode \"%s\"\n", str_mode);
352 333
           else if (pMovie == NULL)
353 334
             printf("no movie loaded to colorize\n");
354
-          else
355
-          {
335
+          else {
356 336
             BlinkenMovieColorize(pMovie, channels, mode);
357
-            printf( "movie colorized to %u channels using mode %s\n", channels, BlinkenColorizerMode2Str( mode ) );
337
+            printf("movie colorized to %u channels using mode %s\n", channels,
338
+                   BlinkenColorizerMode2Str(mode));
358 339
           }
359 340
         }
360
-      }
361
-      else if( i + 1 < argCnt )
362
-      {
341
+      } else if (i + 1 < argCnt) {
363 342
         printf("missing colorizing mode for \"-c\"\n");
364 343
         i++;
365
-      }
366
-      else
344
+      } else
367 345
         printf("missing number of channels for \"-c\"\n");
368 346
     }
369
-
370 347
     // reverse movie
371
-    else if( strcmp( args[i], "-R" ) == 0 )
372
-    {
348
+    else if (strcmp(args[i], "-R") == 0) {
373 349
       if (pMovie == NULL)
374 350
         printf("no movie loaded to reverse\n");
375 351
       else {
... ...
@@ -377,12 +353,9 @@ int main( int argCnt, char * * args )
377 353
         printf("movie reversed\n");
378 354
       }
379 355
     }
380
-
381 356
     // delete frames
382
-    else if( strcmp( args[i], "-d" ) == 0 )
383
-    {
384
-      if( i + 2 < argCnt )
385
-      {
357
+    else if (strcmp(args[i], "-d") == 0) {
358
+      if (i + 2 < argCnt) {
386 359
         const char *str_first, *str_count;
387 360
         unsigned int first, count, c;
388 361
         i++;
... ...
@@ -396,30 +369,27 @@ int main( int argCnt, char * * args )
396 369
             printf("invalid number of frames \"%s\"\n", str_count);
397 370
           else if (pMovie == NULL)
398 371
             printf("no movie loaded to delete frames from\n");
399
-          else if( first + count > (unsigned int)BlinkenMovieGetFrameCnt( pMovie ) )
400
-            printf( "invalid frame range (%u-%u) for deletion from %u frames\n",
401
-                    first, first + count, (unsigned int)BlinkenMovieGetFrameCnt( pMovie ) );
372
+          else if (first + count >
373
+                   (unsigned int)BlinkenMovieGetFrameCnt(pMovie))
374
+            printf
375
+                ("invalid frame range (%u-%u) for deletion from %u frames\n",
376
+                 first, first + count,
377
+                 (unsigned int)BlinkenMovieGetFrameCnt(pMovie));
402 378
           else {
403 379
             for (c = 0; c < count; c++)
404 380
               BlinkenMovieDeleteFrame(pMovie, first);
405 381
             printf("deleted frames %u-%u\n", first, first + count);
406 382
           }
407 383
         }
408
-      }
409
-      else if( i + 1 < argCnt )
410
-      {
384
+      } else if (i + 1 < argCnt) {
411 385
         printf("missing colorizing mode for \"-c\"\n");
412 386
         i++;
413
-      }
414
-      else
387
+      } else
415 388
         printf("missing number of channels for \"-c\"\n");
416 389
     }
417
-
418 390
     // generate test movie
419
-    else if( strcmp( args[i], "-t" ) == 0 )
420
-    {
421
-      if( i + 3 < argCnt )
422
-      {
391
+    else if (strcmp(args[i], "-t") == 0) {
392
+      if (i + 3 < argCnt) {
423 393
         const char *str_format, *str_mode, *str_duration;
424 394
         i++;
425 395
         str_format = args[i];
... ...
@@ -428,43 +398,32 @@ int main( int argCnt, char * * args )
428 398
         i++;
429 399
         str_duration = args[i];
430 400
         gen_test_movie(&pMovie, str_format, str_mode, str_duration);
431
-      }
432
-      else if( i + 2 < argCnt )
433
-      {
401
+      } else if (i + 2 < argCnt) {
434 402
         printf("missing duration for \"-t\"\n");
435 403
         i += 2;
436
-      }
437
-      else if( i + 1 < argCnt )
438
-      {
404
+      } else if (i + 1 < argCnt) {
439 405
         printf("missing test mode for \"-t\"\n");
440 406
         i++;
441
-      }
442
-      else
407
+      } else
443 408
         printf("missing format for \"-t\"\n");
444 409
     }
445
-
446 410
     // write movie
447
-    else if( strcmp( args[i], "-o" ) == 0 )
448
-    {
449
-      if( i + 1 < argCnt )
450
-      {
411
+    else if (strcmp(args[i], "-o") == 0) {
412
+      if (i + 1 < argCnt) {
451 413
         i++;
452 414
         if (pMovie == NULL)
453 415
           printf("no movie loaded to write to \"%s\"\n", args[i]);
454
-        else
455
-          if( BlinkenMovieSave( pMovie, args[i] ) < 0 )
416
+        else if (BlinkenMovieSave(pMovie, args[i]) < 0)
456 417
           printf("could not write movie \"%s\"\n", args[i]);
457 418
         else
458 419
           printf("movie \"%s\" written\n", args[i]);
459
-      }
460
-      else
420
+      } else
461 421
         printf("missing output filename for \"-o\"\n");
462 422
     }
463
-
464 423
     // old style input filename
465
-    else if( i == 1 && args[i][0] != '-' )
466
-    {
467
-      printf( "old style input filename \"%s\", better use \"-i %s\"\n", args[i], args[i] );
424
+    else if (i == 1 && args[i][0] != '-') {
425
+      printf("old style input filename \"%s\", better use \"-i %s\"\n",
426
+             args[i], args[i]);
468 427
       if (pMovie != NULL)
469 428
         BlinkenMovieFree(pMovie);
470 429
       pMovie = BlinkenMovieLoad(args[i]);
... ...
@@ -473,34 +432,31 @@ int main( int argCnt, char * * args )
473 432
       else
474 433
         printf("movie \"%s\" read\n", args[i]);
475 434
     }
476
-
477 435
     // old style output filename
478
-    else if( i == 2 && args[i][0] != '-' )
479
-    {
480
-      printf( "old style output filename \"%s\", better use \"-o %s\"\n", args[i], args[i] );
436
+    else if (i == 2 && args[i][0] != '-') {
437
+      printf("old style output filename \"%s\", better use \"-o %s\"\n",
438
+             args[i], args[i]);
481 439
       if (pMovie == NULL)
482 440
         printf("no movie loaded to write to \"%s\"\n", args[i]);
483
-      else
484
-        if( BlinkenMovieSave( pMovie, args[i] ) < 0 )
441
+      else if (BlinkenMovieSave(pMovie, args[i]) < 0)
485 442
         printf("could not write movie \"%s\"\n", args[i]);
486 443
       else
487 444
         printf("movie \"%s\" written\n", args[i]);
488 445
     }
489
-
490 446
     // unknown parameter
491 447
     else
492
-      printf( "unknown parameter \"%s\", call without parameters to get help\n", args[i] );
448
+      printf
449
+          ("unknown parameter \"%s\", call without parameters to get help\n",
450
+           args[i]);
493 451
 
494 452
   }     // for( i ...
495 453
 
496 454
   // old style print
497
-  if( argCnt == 2 && pMovie != NULL )
498
-  {
455
+  if (argCnt == 2 && pMovie != NULL) {
499 456
     str = BlinkenMovieToString(pMovie);
500 457
     if (str == NULL)
501 458
       printf("could not print movie\n");
502
-    else
503
-    {
459
+    else {
504 460
       printf("%s", str);
505 461
       free(str);
506 462
     }
... ...
@@ -1,8 +1,6 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #include <stdio.h>
8 6
 #include <stdlib.h>
... ...
@@ -22,8 +20,7 @@ typedef DWORD uint32_t;
22 20
 #include <BlinkenLib/BlinkenFrame.h>
23 21
 #include <BlinkenLib/Tools.h>
24 22
 
25
-struct sBlinkenFrame
26
-{
23
+struct sBlinkenFrame {
27 24
   int height;
28 25
   int width;
29 26
   int channels;
... ...
@@ -33,24 +30,21 @@ struct sBlinkenFrame
33 30
 };
34 31
 
35 32
 // blinken protocol headers
36
-typedef struct sBlinkenProtoBlpHdr
37
-{
33
+typedef struct sBlinkenProtoBlpHdr {
38 34
   uint32_t magic;
39 35
   uint32_t frameNo;
40 36
   uint16_t width;
41 37
   uint16_t height;
42 38
 } stBlinkenProtoBlpHdr;
43 39
 #define BlinkenProtoBlpMagic 0xDEADBEEF
44
-typedef struct sBlinkenProtoEblpHdr
45
-{
40
+typedef struct sBlinkenProtoEblpHdr {
46 41
   uint32_t magic;
47 42
   uint32_t frameNo;
48 43
   uint16_t width;
49 44
   uint16_t height;
50 45
 } stBlinkenProtoEblpHdr;
51 46
 #define BlinkenProtoEblpMagic 0xFEEDBEEF
52
-typedef struct sBlinkenProtoMcufHdr
53
-{
47
+typedef struct sBlinkenProtoMcufHdr {
54 48
   uint32_t magic;
55 49
   uint16_t height;
56 50
   uint16_t width;
... ...
@@ -59,20 +53,31 @@ typedef struct sBlinkenProtoMcufHdr
59 53
 } stBlinkenProtoMcufHdr;
60 54
 #define BlinkenProtoMcufMagic 0x23542666
61 55
 
62
-stBlinkenFrame * BlinkenFrameNew( int height, int width, int channels, int maxval, int duration )
56
+stBlinkenFrame *BlinkenFrameNew(int height, int width, int channels,
57
+                                int maxval, int duration)
63 58
 {
64 59
   stBlinkenFrame *pFrame;
65 60
 
66
-  if( height < BlinkenHeightMin ) height = BlinkenHeightMin;
67
-  if( height > BlinkenHeightMax ) height = BlinkenHeightMax;
68
-  if( width < BlinkenWidthMin ) width = BlinkenWidthMin;
69
-  if( width > BlinkenWidthMax ) width = BlinkenWidthMax;
70
-  if( channels < BlinkenChannelsMin ) channels = BlinkenChannelsMin;
71
-  if( channels > BlinkenChannelsMax ) channels = BlinkenMaxvalMax;
72
-  if( maxval < BlinkenMaxvalMin ) maxval = BlinkenMaxvalMin;
73
-  if( maxval > BlinkenMaxvalMax ) maxval = BlinkenMaxvalMax;
74
-  if( duration < BlinkenDurationMin ) duration = BlinkenDurationMin;
75
-  if( duration > BlinkenDurationMax ) duration = BlinkenDurationMax;
61
+  if (height < BlinkenHeightMin)
62
+    height = BlinkenHeightMin;
63
+  if (height > BlinkenHeightMax)
64
+    height = BlinkenHeightMax;
65
+  if (width < BlinkenWidthMin)
66
+    width = BlinkenWidthMin;
67
+  if (width > BlinkenWidthMax)
68
+    width = BlinkenWidthMax;
69
+  if (channels < BlinkenChannelsMin)
70
+    channels = BlinkenChannelsMin;
71
+  if (channels > BlinkenChannelsMax)
72
+    channels = BlinkenMaxvalMax;
73
+  if (maxval < BlinkenMaxvalMin)
74
+    maxval = BlinkenMaxvalMin;
75
+  if (maxval > BlinkenMaxvalMax)
76
+    maxval = BlinkenMaxvalMax;
77
+  if (duration < BlinkenDurationMin)
78
+    duration = BlinkenDurationMin;
79
+  if (duration > BlinkenDurationMax)
80
+    duration = BlinkenDurationMax;
76 81
 
77 82
   pFrame = (stBlinkenFrame *) malloc(sizeof(stBlinkenFrame));
78 83
   if (pFrame == NULL)
... ...
@@ -84,9 +89,10 @@ stBlinkenFrame * BlinkenFrameNew( int height, int width, int channels, int maxva
84 89
   pFrame->maxval = maxval;
85 90
   pFrame->duration = duration;
86 91
 
87
-  pFrame->ppData = (unsigned char * *)malloc2D( height, width * channels, sizeof( unsigned char ) );
88
-  if( pFrame->ppData == NULL )
89
-  {
92
+  pFrame->ppData =
93
+      (unsigned char **)malloc2D(height, width * channels,
94
+                                 sizeof(unsigned char));
95
+  if (pFrame->ppData == NULL) {
90 96
     free(pFrame);
91 97
     return NULL;
92 98
   }
... ...
@@ -103,7 +109,8 @@ stBlinkenFrame * BlinkenFrameClone( stBlinkenFrame * pSrcFrame )
103 109
     return NULL;
104 110
 
105 111
   pFrame = BlinkenFrameNew(pSrcFrame->height, pSrcFrame->width,
106
-                            pSrcFrame->channels, pSrcFrame->maxval, pSrcFrame->duration );
112
+                           pSrcFrame->channels, pSrcFrame->maxval,
113
+                           pSrcFrame->duration);
107 114
   if (pFrame == NULL)
108 115
     return NULL;
109 116
 
... ...
@@ -182,29 +189,31 @@ void BlinkenFrameSetDuration( stBlinkenFrame * pFrame, int duration )
182 189
   if (pFrame == NULL)
183 190
     return;
184 191
 
185
-  if( duration < BlinkenDurationMin ) duration = BlinkenDurationMin;
186
-  if( duration > BlinkenDurationMax ) duration = BlinkenDurationMax;
192
+  if (duration < BlinkenDurationMin)
193
+    duration = BlinkenDurationMin;
194
+  if (duration > BlinkenDurationMax)
195
+    duration = BlinkenDurationMax;
187 196
 
188 197
   pFrame->duration = duration;
189 198
 }
190 199
 
191
-unsigned char BlinkenFrameGetPixel( stBlinkenFrame * pFrame, int y, int x, int c )
200
+unsigned char BlinkenFrameGetPixel(stBlinkenFrame * pFrame, int y, int x,
201
+                                   int c)
192 202
 {
193 203
   if (pFrame == NULL ||
194 204
       y < 0 || y >= pFrame->height ||
195
-      x < 0 || x >= pFrame->width ||
196
-      c < 0 || c >= pFrame->channels )
205
+      x < 0 || x >= pFrame->width || c < 0 || c >= pFrame->channels)
197 206
     return 0;
198 207
 
199 208
   return pFrame->ppData[y][x * pFrame->channels + c];
200 209
 }
201 210
 
202
-void BlinkenFrameSetPixel( stBlinkenFrame * pFrame, int y, int x, int c, unsigned char val )
211
+void BlinkenFrameSetPixel(stBlinkenFrame * pFrame, int y, int x, int c,
212
+                          unsigned char val)
203 213
 {
204 214
   if (pFrame == NULL ||
205 215
       y < 0 || y >= pFrame->height ||
206
-      x < 0 || x >= pFrame->width ||
207
-      c < 0 || c >= pFrame->channels )
216
+      x < 0 || x >= pFrame->width || c < 0 || c >= pFrame->channels)
208 217
     return;
209 218
 
210 219
   if (val > pFrame->maxval)
... ...
@@ -217,31 +226,49 @@ unsigned long BlinkenFrameGetColor( stBlinkenFrame * pFrame, int y, int x )
217 226
   int i;
218 227
 
219 228
   if (pFrame == NULL ||
220
-      y < 0 || y >= pFrame->height ||
221
-      x < 0 || x >= pFrame->width )
229
+      y < 0 || y >= pFrame->height || x < 0 || x >= pFrame->width)
222 230
     return 0;
223 231
 
224 232
   i = x * pFrame->channels;
225 233
 
226 234
   if (pFrame->channels == 1)
227
-    return (((unsigned long)pFrame->ppData[y][i + 0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 16 |
228
-           (((unsigned long)pFrame->ppData[y][i + 0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 8 |
229
-           (((unsigned long)pFrame->ppData[y][i + 0] * 255 + pFrame->maxval / 2) / pFrame->maxval);
235
+    return (((unsigned long)pFrame->ppData[y][i + 0] * 255 +
236
+             pFrame->maxval / 2) /
237
+            pFrame->
238
+            maxval) << 16 | (((unsigned long)pFrame->ppData[y][i + 0] * 255 +
239
+                              pFrame->maxval / 2) /
240
+                             pFrame->maxval) << 8 | (((unsigned long)
241
+                                                      pFrame->ppData[y][i +
242
+                                                                        0] *
243
+                                                      255 +
244
+                                                      pFrame->maxval / 2) /
245
+                                                     pFrame->maxval);
230 246
   if (pFrame->channels == 2)
231
-    return (((unsigned long)pFrame->ppData[y][i + 0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 16 |
232
-           (((unsigned long)pFrame->ppData[y][i + 1] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 8;
233
-  return (((unsigned long)pFrame->ppData[y][i + 0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 16 |
234
-         (((unsigned long)pFrame->ppData[y][i + 1] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 8 |
235
-         (((unsigned long)pFrame->ppData[y][i + 2] * 255 + pFrame->maxval / 2) / pFrame->maxval);
236
-}
237
-
238
-void BlinkenFrameSetColor( stBlinkenFrame * pFrame, int y, int x, unsigned long color )
247
+    return (((unsigned long)pFrame->ppData[y][i + 0] * 255 +
248
+             pFrame->maxval / 2) /
249
+            pFrame->
250
+            maxval) << 16 | (((unsigned long)pFrame->ppData[y][i + 1] * 255 +
251
+                              pFrame->maxval / 2) / pFrame->maxval) << 8;
252
+  return (((unsigned long)pFrame->ppData[y][i + 0] * 255 +
253
+           pFrame->maxval / 2) /
254
+          pFrame->maxval) << 16 | (((unsigned long)pFrame->ppData[y][i + 1] *
255
+                                    255 +
256
+                                    pFrame->maxval / 2) /
257
+                                   pFrame->maxval) << 8 | (((unsigned long)
258
+                                                            pFrame->ppData[y]
259
+                                                            [i + 2] * 255 +
260
+                                                            pFrame->maxval /
261
+                                                            2) /
262
+                                                           pFrame->maxval);
263
+}
264
+
265
+void BlinkenFrameSetColor(stBlinkenFrame * pFrame, int y, int x,
266
+                          unsigned long color)
239 267
 {
240 268
   int i, alpha, alpha_, c;
241 269
 
242 270
   if (pFrame == NULL ||
243
-      y < 0 || y >= pFrame->height ||
244
-      x < 0 || x >= pFrame->width )
271
+      y < 0 || y >= pFrame->height || x < 0 || x >= pFrame->width)
245 272
     return;
246 273
 
247 274
   i = x * pFrame->channels;
... ...
@@ -249,21 +276,31 @@ void BlinkenFrameSetColor( stBlinkenFrame * pFrame, int y, int x, unsigned long
249 276
   alpha = (color >> 24) & 0xFF;
250 277
   alpha_ = 255 - alpha;
251 278
   if (pFrame->channels >= 1)
252
-    pFrame->ppData[y][i + 0] = (unsigned char)(( ((((color >> 16) & 0xFF) * pFrame->maxval + 127) / 255) * alpha
253
-                                               + (unsigned long)pFrame->ppData[y][i + 0] * alpha_
254
-                                               ) / 255);
279
+    pFrame->ppData[y][i + 0] =
280
+        (unsigned
281
+         char)((((((color >> 16) & 0xFF) * pFrame->maxval +
282
+                  127) / 255) * alpha + (unsigned long)pFrame->ppData[y][i +
283
+                                                                         0] *
284
+                alpha_) / 255);
255 285
   if (pFrame->channels >= 2)
256
-    pFrame->ppData[y][i + 1] = (unsigned char)(( ((((color >> 8) & 0xFF) * pFrame->maxval + 127) / 255) * alpha
257
-                                               + (unsigned long)pFrame->ppData[y][i + 1] * alpha_
258
-                                               ) / 255);
286
+    pFrame->ppData[y][i + 1] =
287
+        (unsigned
288
+         char)((((((color >> 8) & 0xFF) * pFrame->maxval +
289
+                  127) / 255) * alpha + (unsigned long)pFrame->ppData[y][i +
290
+                                                                         1] *
291
+                alpha_) / 255);
259 292
   if (pFrame->channels >= 3)
260
-    pFrame->ppData[y][i + 2] = (unsigned char)(( (((color & 0xFF) * pFrame->maxval + 127) / 255) * alpha
261
-                                               + (unsigned long)pFrame->ppData[y][i + 2] * alpha_
262
-                                               ) / 255);
293
+    pFrame->ppData[y][i + 2] =
294
+        (unsigned
295
+         char)(((((color & 0xFF) * pFrame->maxval + 127) / 255) * alpha +
296
+                (unsigned long)pFrame->ppData[y][i + 2] * alpha_) / 255);
263 297
   for (c = 3; c < pFrame->channels; c++)
264 298
     pFrame->ppData[y][i + c] = (unsigned char)((0
265
-                                               + (unsigned long)pFrame->ppData[y][i + c] * alpha_
266
-                                               ) / 255);
299
+                                                +
300
+                                                (unsigned long)
301
+                                                pFrame->ppData[y][i +
302
+                                                                  c] *
303
+                                                alpha_) / 255);
267 304
 }
268 305
 
269 306
 int BlinkenFrameIsEmpty(stBlinkenFrame * pFrame)
... ...
@@ -315,7 +352,9 @@ int BlinkenFrameCompare( stBlinkenFrame * pFrame1, stBlinkenFrame * pFrame2 )
315 352
     return 1;
316 353
 
317 354
   for (y = 0; y < pFrame1->height; y++) {
318
-    cmp = memcmp( pFrame1->ppData[y], pFrame2->ppData[y], pFrame1->width * pFrame2->channels );
355
+    cmp =
356
+        memcmp(pFrame1->ppData[y], pFrame2->ppData[y],
357
+               pFrame1->width * pFrame2->channels);
319 358
     if (cmp != 0)
320 359
       return cmp;
321 360
   }
... ...
@@ -323,7 +362,8 @@ int BlinkenFrameCompare( stBlinkenFrame * pFrame1, stBlinkenFrame * pFrame2 )
323 362
   return 0;
324 363
 }
325 364
 
326
-void BlinkenFrameResize( stBlinkenFrame * pFrame, int height, int width, int channels, int maxval )
365
+void BlinkenFrameResize(stBlinkenFrame * pFrame, int height, int width,
366
+                        int channels, int maxval)
327 367
 {
328 368
   unsigned char **ppData;
329 369
   int y, x, c, i, j;
... ...
@@ -333,23 +373,32 @@ void BlinkenFrameResize( stBlinkenFrame * pFrame, int height, int width, int cha
333 373
   if (pFrame == NULL)
334 374
     return;
335 375
 
336
-  if( height < BlinkenHeightMin ) height = BlinkenHeightMin;
337
-  if( height > BlinkenHeightMax ) height = BlinkenHeightMax;
338
-  if( width < BlinkenWidthMin ) width = BlinkenWidthMin;
339
-  if( width > BlinkenWidthMax ) width = BlinkenWidthMax;
340
-  if( channels < BlinkenChannelsMin ) channels = BlinkenChannelsMin;
341
-  if( channels > BlinkenChannelsMax ) channels = BlinkenMaxvalMax;
342
-  if( maxval < BlinkenMaxvalMin ) maxval = BlinkenMaxvalMin;
343
-  if( maxval > BlinkenMaxvalMax ) maxval = BlinkenMaxvalMax;
376
+  if (height < BlinkenHeightMin)
377
+    height = BlinkenHeightMin;
378
+  if (height > BlinkenHeightMax)
379
+    height = BlinkenHeightMax;
380
+  if (width < BlinkenWidthMin)
381
+    width = BlinkenWidthMin;
382
+  if (width > BlinkenWidthMax)
383
+    width = BlinkenWidthMax;
384
+  if (channels < BlinkenChannelsMin)
385
+    channels = BlinkenChannelsMin;
386
+  if (channels > BlinkenChannelsMax)
387
+    channels = BlinkenMaxvalMax;
388
+  if (maxval < BlinkenMaxvalMin)
389
+    maxval = BlinkenMaxvalMin;
390
+  if (maxval > BlinkenMaxvalMax)
391
+    maxval = BlinkenMaxvalMax;
344 392
 
345 393
   if (height == pFrame->height &&
346 394
       width == pFrame->width &&
347
-      channels == pFrame->channels &&
348
-      maxval == pFrame->maxval )
395
+      channels == pFrame->channels && maxval == pFrame->maxval)
349 396
     return;
350 397
 
351 398
   // allocate new data array
352
-  ppData = (unsigned char * *)malloc2D( height, width * channels, sizeof( unsigned char ) );
399
+  ppData =
400
+      (unsigned char **)malloc2D(height, width * channels,
401
+                                 sizeof(unsigned char));
353 402
   if (ppData == NULL)
354 403
     return;
355 404
   for (y = 0; y < height; y++)
... ...
@@ -358,54 +407,54 @@ void BlinkenFrameResize( stBlinkenFrame * pFrame, int height, int width, int cha
358 407
         ppData[y][i] = 0;
359 408
 
360 409
   // get number of pixels to skip / to leave empty in X and Y direction
361
-  if( height > pFrame->height )
362
-  {
410
+  if (height > pFrame->height) {
363 411
     emptyY = (height - pFrame->height) / 2;
364 412
     skipY = 0;
365 413
     rangeY = pFrame->height;
366
-  }
367
-  else
368
-  {
414
+  } else {
369 415
     emptyY = 0;
370 416
     skipY = (pFrame->height - height) / 2;
371 417
     rangeY = height;
372 418
   }
373
-  if( width > pFrame->width )
374
-  {
419
+  if (width > pFrame->width) {
375 420
     emptyX = (width - pFrame->width) / 2;
376 421
     skipX = 0;
377 422
     rangeX = pFrame->width;
378
-  }
379
-  else
380
-  {
423
+  } else {
381 424
     emptyX = 0;
382 425
     skipX = (pFrame->width - width) / 2;
383 426
     rangeX = width;
384 427
   }
385 428
 
386 429
   // resize frame with help of calculated parameters
387
-  for( y = 0; y < rangeY; y++ )
388
-  {
389
-    for( x = 0; x < rangeX; x++ )
390
-    {
430
+  for (y = 0; y < rangeY; y++) {
431
+    for (x = 0; x < rangeX; x++) {
391 432
       i = (skipX + x) * pFrame->channels;
392 433
       j = (emptyX + x) * channels;
393
-      if( channels >= pFrame->channels ) //add channels: copy last channel into new channels
434
+      if (channels >= pFrame->channels) // add channels: copy last channel
435
+        // into new channels
394 436
       {
395 437
         for (c = 0; c < pFrame->channels; c++, i++, j++)
396
-          ppData[emptyY + y][j] = (unsigned char)(((unsigned long)pFrame->ppData[skipY + y][i] * maxval + pFrame->maxval / 2) / pFrame->maxval);
438
+          ppData[emptyY + y][j] =
439
+              (unsigned
440
+               char)(((unsigned long)pFrame->ppData[skipY + y][i] * maxval +
441
+                      pFrame->maxval / 2) / pFrame->maxval);
397 442
         for (; c < channels; c++, j++)
398 443
           ppData[emptyY + y][j] = ppData[emptyY + y][j - 1];
399
-      }
400
-      else //remove channels: merge leftover channels with last kept channel
444
+      } else    // remove channels: merge leftover channels with last kept
445
+        // channel
401 446
       {
402 447
         val = 0;
403 448
         for (c = 0; c < channels - 1; c++, i++, j++)
404
-          ppData[emptyY + y][j] = (unsigned char)(((unsigned long)pFrame->ppData[skipY + y][i] * maxval + pFrame->maxval / 2) / pFrame->maxval);
449
+          ppData[emptyY + y][j] =
450
+              (unsigned
451
+               char)(((unsigned long)pFrame->ppData[skipY + y][i] * maxval +
452
+                      pFrame->maxval / 2) / pFrame->maxval);
405 453
         for (c = channels - 1; c < pFrame->channels; c++, i++)
406 454
           val += (unsigned long)pFrame->ppData[skipY + y][i];
407 455
         div = pFrame->maxval * (pFrame->channels - channels + 1);
408
-        ppData[emptyY + y][j++] = (unsigned char)((val * maxval + div / 2) / div);
456
+        ppData[emptyY + y][j++] =
457
+            (unsigned char)((val * maxval + div / 2) / div);
409 458
       }
410 459
     }
411 460
   }
... ...
@@ -427,83 +476,104 @@ void BlinkenFrameScale( stBlinkenFrame * pFrame, int height, int width )
427 476
   if (pFrame == NULL)
428 477
     return;
429 478
 
430
-  if( height < BlinkenHeightMin ) height = BlinkenHeightMin;
431
-  if( height > BlinkenHeightMax ) height = BlinkenHeightMax;
432
-  if( width < BlinkenWidthMin ) width = BlinkenWidthMin;
433
-  if( width > BlinkenWidthMax ) width = BlinkenWidthMax;
479
+  if (height < BlinkenHeightMin)
480
+    height = BlinkenHeightMin;
481
+  if (height > BlinkenHeightMax)
482
+    height = BlinkenHeightMax;
483
+  if (width < BlinkenWidthMin)
484
+    width = BlinkenWidthMin;
485
+  if (width > BlinkenWidthMax)
486
+    width = BlinkenWidthMax;
434 487
 
435
-  if( height == pFrame->height &&
436
-      width == pFrame->width )
488
+  if (height == pFrame->height && width == pFrame->width)
437 489
     return;
438 490
 
439 491
   scaleHor = (double)width / (double)pFrame->width;
440 492
   scaleVer = (double)height / (double)pFrame->height;
441 493
 
442 494
   // allocate new data array
443
-  ppData = (unsigned char * *)malloc2D( height, width * pFrame->channels, sizeof( unsigned char ) );
495
+  ppData =
496
+      (unsigned char **)malloc2D(height, width * pFrame->channels,
497
+                                 sizeof(unsigned char));
444 498
   if (ppData == NULL)
445 499
     return;
446 500
 
447 501
   // scale every channel
448 502
   chans = pFrame->channels;
449
-  for( c = 0; c < chans; c++ )
450
-  {
451
-    for( ny = 0; ny < height; ny++ )
452
-    {
453
-      for( nx = 0; nx < width; nx++ )
454
-      {
455
-        oy = (double)ny / scaleVer; //sub-pixel exact range in old picture
503
+  for (c = 0; c < chans; c++) {
504
+    for (ny = 0; ny < height; ny++) {
505
+      for (nx = 0; nx < width; nx++) {
506
+        oy = (double)ny / scaleVer;     // sub-pixel exact range in old
507
+        // picture
456 508
         ox = (double)nx / scaleHor;
457 509
         oy1 = (double)(ny + 1) / scaleVer - 0.000001;
458 510
         ox1 = (double)(nx + 1) / scaleHor - 0.000001;
459
-        if( oy < 0 || ox < 0 || oy1 >= pFrame->height || ox1 >= pFrame->width) //out of old picture
511
+        if (oy < 0 || ox < 0 || oy1 >= pFrame->height || ox1 >= pFrame->width)  // out 
512
+                                                                                // 
513
+          // of 
514
+          // old 
515
+          // picture
460 516
           ppData[ny][nx * chans + c] = 0;
461
-        else
462
-        {
517
+        else {
463 518
           oyi = (int)oy;
464 519
           oxi = (int)ox;
465 520
           oy1i = (int)oy1;
466 521
           ox1i = (int)ox1;
467
-          if( oyi == oy1i )
468
-          {
522
+          if (oyi == oy1i) {
469 523
             if (oxi == ox1i)    // one source pixel
470 524
             {
471 525
               val = (double)pFrame->ppData[oyi][oxi * chans + c];
472
-            }
473
-            else //one line of source pixels
526
+            } else      // one line of source pixels
474 527
             {
475
-              val = (double)pFrame->ppData[oyi][oxi * chans + c] * (1 - ox + oxi)
476
-                  + (double)pFrame->ppData[oyi][ox1i * chans + c] * (ox1 - ox1i);
528
+              val =
529
+                  (double)pFrame->ppData[oyi][oxi * chans + c] * (1 - ox +
530
+                                                                  oxi)
531
+                  + (double)pFrame->ppData[oyi][ox1i * chans + c] * (ox1 -
532
+                                                                     ox1i);
477 533
               for (x = oxi + 1; x < ox1i; x++)
478 534
                 val += (double)pFrame->ppData[oyi][x * chans + c];
479 535
               val /= ox1 - ox;
480 536
             }
481
-          }
482
-          else //one column of source pixels
483
-          {
484
-            if( oxi == ox1i )
537
+          } else        // one column of source pixels
485 538
           {
486
-              val = (double)pFrame->ppData[oyi][oxi * chans + c] * (1 - oy + oyi)
487
-                  + (double)pFrame->ppData[oy1i][oxi * chans + c] * (oy1 - oy1i);
539
+            if (oxi == ox1i) {
540
+              val =
541
+                  (double)pFrame->ppData[oyi][oxi * chans + c] * (1 - oy +
542
+                                                                  oyi)
543
+                  + (double)pFrame->ppData[oy1i][oxi * chans + c] * (oy1 -
544
+                                                                     oy1i);
488 545
               for (y = oyi + 1; y < oy1i; y++)
489 546
                 val += (double)pFrame->ppData[y][oxi * chans + c];
490 547
               val /= oy1 - oy;
491
-            }
492
-            else //rectangle of source pixels
493
-            {
494
-              val = (double)pFrame->ppData[oyi][oxi* chans + c] * (1 - oy + oyi) * (1 - ox + oxi)
495
-                  + (double)pFrame->ppData[oyi][ox1i * chans + c] * (1 - oy + oyi) * (ox1 - ox1i)
496
-                  + (double)pFrame->ppData[oy1i][oxi * chans + c] * (oy1 - oy1i) * (1 - ox + oxi)
497
-                  + (double)pFrame->ppData[oy1i][ox1i * chans + c] * (oy1 - oy1i) * (ox1 - ox1i);
498
-              for( y = oyi + 1; y < oy1i; y++ )
499
-              {
500
-                val += (double)pFrame->ppData[y][oxi * chans + c] * (1 - ox + oxi)
501
-                     + (double)pFrame->ppData[y][ox1i * chans + c] * (ox1 - ox1i);
502
-              }
503
-              for( x = oxi + 1; x < ox1i; x++ )
504
-              {
505
-                val += (double)pFrame->ppData[oyi][x * chans + c] * (1 - oy + oyi)
506
-                     + (double)pFrame->ppData[oy1i][x * chans + c] * (oy1 - oy1i);
548
+            } else      // rectangle of source pixels
549
+            {
550
+              val =
551
+                  (double)pFrame->ppData[oyi][oxi * chans + c] * (1 - oy +
552
+                                                                  oyi) * (1 -
553
+                                                                          ox +
554
+                                                                          oxi)
555
+                  + (double)pFrame->ppData[oyi][ox1i * chans + c] * (1 - oy +
556
+                                                                     oyi) *
557
+                  (ox1 - ox1i)
558
+                  + (double)pFrame->ppData[oy1i][oxi * chans + c] * (oy1 -
559
+                                                                     oy1i) *
560
+                  (1 - ox + oxi)
561
+                  + (double)pFrame->ppData[oy1i][ox1i * chans + c] * (oy1 -
562
+                                                                      oy1i) *
563
+                  (ox1 - ox1i);
564
+              for (y = oyi + 1; y < oy1i; y++) {
565
+                val +=
566
+                    (double)pFrame->ppData[y][oxi * chans + c] * (1 - ox +
567
+                                                                  oxi)
568
+                    + (double)pFrame->ppData[y][ox1i * chans + c] * (ox1 -
569
+                                                                     ox1i);
570
+              }
571
+              for (x = oxi + 1; x < ox1i; x++) {
572
+                val +=
573
+                    (double)pFrame->ppData[oyi][x * chans + c] * (1 - oy +
574
+                                                                  oyi)
575
+                    + (double)pFrame->ppData[oy1i][x * chans + c] * (oy1 -
576
+                                                                     oy1i);
507 577
               }
508 578
               for (y = oyi + 1; y < oy1i; y++)
509 579
                 for (x = oxi + 1; x < ox1i; x++)
... ...
@@ -523,7 +593,8 @@ void BlinkenFrameScale( stBlinkenFrame * pFrame, int height, int width )
523 593
   pFrame->ppData = ppData;
524 594
 }
525 595
 
526
-void BlinkenFrameColorize( stBlinkenFrame * pFrame, int channels, int mode, int step )
596
+void BlinkenFrameColorize(stBlinkenFrame * pFrame, int channels, int mode,
597
+                          int step)
527 598
 {
528 599
   unsigned char **ppData;
529 600
   int y, x, c, i, j;
... ...
@@ -532,11 +603,15 @@ void BlinkenFrameColorize( stBlinkenFrame * pFrame, int channels, int mode, int
532 603
   if (pFrame == NULL)
533 604
     return;
534 605
 
535
-  if( channels < BlinkenChannelsMin ) channels = BlinkenChannelsMin;
536
-  if( channels > BlinkenChannelsMax ) channels = BlinkenMaxvalMax;
606
+  if (channels < BlinkenChannelsMin)
607
+    channels = BlinkenChannelsMin;
608
+  if (channels > BlinkenChannelsMax)
609
+    channels = BlinkenMaxvalMax;
537 610
 
538 611
   // allocate new data array
539
-  ppData = (unsigned char * *)malloc2D( pFrame->height, pFrame->width * channels, sizeof( unsigned char ) );
612
+  ppData =
613
+      (unsigned char **)malloc2D(pFrame->height, pFrame->width * channels,
614
+                                 sizeof(unsigned char));
540 615
   if (ppData == NULL)
541 616
     return;
542 617
   for (y = 0; y < pFrame->height; y++)
... ...
@@ -545,10 +620,8 @@ void BlinkenFrameColorize( stBlinkenFrame * pFrame, int channels, int mode, int
545 620
         ppData[y][i] = 0;
546 621
 
547 622
   // colorize frame
548
-  for( y = 0; y < pFrame->height; y++ )
549
-  {
550
-    for( x = 0; x < pFrame->width; x++ )
551
-    {
623
+  for (y = 0; y < pFrame->height; y++) {
624
+    for (x = 0; x < pFrame->width; x++) {
552 625
       i = x * pFrame->channels;
553 626
       // merge channels
554 627
       val = 0;
... ...
@@ -588,10 +661,8 @@ char * BlinkenFrameToString( stBlinkenFrame * pFrame )
588 661
 
589 662
   ptr = str;
590 663
 
591
-  for( y = 0; y < pFrame->height; y++ )
592
-  {
593
-    for( x = 0, i = 0; x < pFrame->width; x++ )
594
-    {
664
+  for (y = 0; y < pFrame->height; y++) {
665
+    for (x = 0, i = 0; x < pFrame->width; x++) {
595 666
       val = 0;
596 667
       for (val = 0, c = 0; c < pFrame->channels; c++, i++)
597 668
         val += pFrame->ppData[y][i];
... ...
@@ -608,7 +679,8 @@ char * BlinkenFrameToString( stBlinkenFrame * pFrame )
608 679
   return str;
609 680
 }
610 681
 
611
-int BlinkenFrameToNetwork( stBlinkenFrame * pFrame, etBlinkenProto proto, char * pData, int maxLength )
682
+int BlinkenFrameToNetwork(stBlinkenFrame * pFrame, etBlinkenProto proto,
683
+                          char *pData, int maxLength)
612 684
 // returns length or -1 on error
613 685
 {
614 686
   int y, x, c, i, j, val;
... ...
@@ -616,62 +688,81 @@ int BlinkenFrameToNetwork( stBlinkenFrame * pFrame, etBlinkenProto proto, char *
616 688
   if (pFrame == NULL)
617 689
     return -1;
618 690
 
619
-  switch( proto )
620
-  {
691
+  switch (proto) {
621 692
 
622 693
   case BlinkenProtoNone:
623 694
     return 0;
624 695
 
625 696
   case BlinkenProtoBlp:
626
-      if( maxLength < (int)sizeof( stBlinkenProtoBlpHdr ) + pFrame->height * pFrame->width ) //buffer too short
697
+    if (maxLength < (int)sizeof(stBlinkenProtoBlpHdr) + pFrame->height * pFrame->width) // buffer 
698
+                                                                                        // 
699
+      // too 
700
+      // short
627 701
       return -1;
628
-      ((stBlinkenProtoBlpHdr *)pData)->magic = htonl( BlinkenProtoBlpMagic ); //build header
702
+    ((stBlinkenProtoBlpHdr *) pData)->magic = htonl(BlinkenProtoBlpMagic);      // build 
703
+                                                                                // 
704
+    // header
629 705
     ((stBlinkenProtoBlpHdr *) pData)->frameNo = htonl(0);
630 706
     ((stBlinkenProtoBlpHdr *) pData)->width = htons((uint16_t) pFrame->width);
631
-      ((stBlinkenProtoBlpHdr *)pData)->height = htons( (uint16_t)pFrame->height );
707
+    ((stBlinkenProtoBlpHdr *) pData)->height =
708
+        htons((uint16_t) pFrame->height);
632 709
     i = sizeof(stBlinkenProtoBlpHdr);   // put data into packet
633
-      for( y = 0; y < pFrame->height; y++ )
634
-      {
635
-        for( x = 0, j = 0; x < pFrame->width; x++, i++ )
636
-        {
710
+    for (y = 0; y < pFrame->height; y++) {
711
+      for (x = 0, j = 0; x < pFrame->width; x++, i++) {
637 712
         val = 0;
638 713
         for (c = 0; c < pFrame->channels; c++, j++)
639 714
           val += pFrame->ppData[y][j];
640
-           pData[i] = (val >= pFrame->channels * pFrame->maxval / 2 ? 0x01 : 0x00);
715
+        pData[i] =
716
+            (val >= pFrame->channels * pFrame->maxval / 2 ? 0x01 : 0x00);
641 717
       }
642 718
     }
643 719
     return i;   // return length
644 720
 
645 721
   case BlinkenProtoEblp:
646
-      if( maxLength < (int)sizeof( stBlinkenProtoEblpHdr ) + pFrame->height * pFrame->width ) //buffer too short
722
+    if (maxLength < (int)sizeof(stBlinkenProtoEblpHdr) + pFrame->height * pFrame->width)        // buffer 
723
+                                                                                                // 
724
+      // too 
725
+      // short
647 726
       return -1;
648
-      ((stBlinkenProtoEblpHdr *)pData)->magic = htonl( BlinkenProtoEblpMagic ); //build header
727
+    ((stBlinkenProtoEblpHdr *) pData)->magic = htonl(BlinkenProtoEblpMagic);    // build 
728
+                                                                                // 
729
+    // header
649 730
     ((stBlinkenProtoEblpHdr *) pData)->frameNo = htonl(0);
650
-      ((stBlinkenProtoEblpHdr *)pData)->width = htons( (uint16_t)pFrame->width );
651
-      ((stBlinkenProtoEblpHdr *)pData)->height = htons( (uint16_t)pFrame->height );
731
+    ((stBlinkenProtoEblpHdr *) pData)->width =
732
+        htons((uint16_t) pFrame->width);
733
+    ((stBlinkenProtoEblpHdr *) pData)->height =
734
+        htons((uint16_t) pFrame->height);
652 735
     i = sizeof(stBlinkenProtoEblpHdr);  // put data into packet
653
-      for( y = 0; y < pFrame->height; y++ )
654
-      {
655
-        for( x = 0, j = 0; x < pFrame->width; x++, i++ )
656
-        {
736
+    for (y = 0; y < pFrame->height; y++) {
737
+      for (x = 0, j = 0; x < pFrame->width; x++, i++) {
657 738
         val = 0;
658 739
         for (c = 0; c < pFrame->channels; c++, j++)
659 740
           val += pFrame->ppData[y][j];
660 741
         val /= pFrame->channels;
661 742
         pData[i] = (pFrame->maxval == 255 ? (unsigned char)val
662
-                                             : (unsigned char)((val * 255 + pFrame->maxval / 2) / pFrame->maxval));
743
+                    : (unsigned char)((val * 255 + pFrame->maxval / 2) /
744
+                                      pFrame->maxval));
663 745
       }
664 746
     }
665 747
     return i;   // return length
666 748
 
667 749
   case BlinkenProtoMcuf:
668
-      if( maxLength < (int)sizeof( stBlinkenProtoMcufHdr ) + pFrame->height * pFrame->width * pFrame->channels ) //buffer too short
750
+    if (maxLength < (int)sizeof(stBlinkenProtoMcufHdr) + pFrame->height * pFrame->width * pFrame->channels)     // buffer 
751
+                                                                                                                // 
752
+      // too 
753
+      // short
669 754
       return -1;
670
-      ((stBlinkenProtoMcufHdr *)pData)->magic = htonl( BlinkenProtoMcufMagic ); //build header
671
-      ((stBlinkenProtoMcufHdr *)pData)->height = htons( (uint16_t)pFrame->height );
672
-      ((stBlinkenProtoMcufHdr *)pData)->width = htons( (uint16_t)pFrame->width );
673
-      ((stBlinkenProtoMcufHdr *)pData)->channels = htons( (uint16_t)pFrame->channels );
674
-      ((stBlinkenProtoMcufHdr *)pData)->maxval = htons( (uint16_t)pFrame->maxval );
755
+    ((stBlinkenProtoMcufHdr *) pData)->magic = htonl(BlinkenProtoMcufMagic);    // build 
756
+                                                                                // 
757
+    // header
758
+    ((stBlinkenProtoMcufHdr *) pData)->height =
759
+        htons((uint16_t) pFrame->height);
760
+    ((stBlinkenProtoMcufHdr *) pData)->width =
761
+        htons((uint16_t) pFrame->width);
762
+    ((stBlinkenProtoMcufHdr *) pData)->channels =
763
+        htons((uint16_t) pFrame->channels);
764
+    ((stBlinkenProtoMcufHdr *) pData)->maxval =
765
+        htons((uint16_t) pFrame->maxval);
675 766
     i = sizeof(stBlinkenProtoMcufHdr);  // put data into packet
676 767
     for (y = 0; y < pFrame->height; y++)
677 768
       for (x = 0, j = 0; x < pFrame->width; x++)
... ...
@@ -685,7 +776,8 @@ int BlinkenFrameToNetwork( stBlinkenFrame * pFrame, etBlinkenProto proto, char *
685 776
   }
686 777
 }
687 778
 
688
-stBlinkenFrame * BlinkenFrameFromNetwork( char * pData, int length, etBlinkenProto * pProto )
779
+stBlinkenFrame *BlinkenFrameFromNetwork(char *pData, int length,
780
+                                        etBlinkenProto * pProto)
689 781
 // returns protocol in *pProto if pProto not NULL
690 782
 {
691 783
   stBlinkenFrame *pFrame;
... ...
@@ -696,14 +788,25 @@ stBlinkenFrame * BlinkenFrameFromNetwork( char * pData, int length, etBlinkenPro
696 788
   {
697 789
     if (pProto != NULL) // return protocol
698 790
       *pProto = BlinkenProtoBlp;
699
-    height = ntohs( ((stBlinkenProtoBlpHdr *)pData)->height ); //get header data
791
+    height = ntohs(((stBlinkenProtoBlpHdr *) pData)->height);   // get header 
792
+                                                                // 
793
+    // data
700 794
     width = ntohs(((stBlinkenProtoBlpHdr *) pData)->width);
701
-    if( length < (int)sizeof( stBlinkenProtoBlpHdr ) + height * width ) //check length of packet
795
+    if (length < (int)sizeof(stBlinkenProtoBlpHdr) + height * width)    // check 
796
+                                                                        // 
797
+      // length 
798
+      // of 
799
+      // packet
702 800
       return NULL;
703
-    if( height < BlinkenHeightMin || height > BlinkenHeightMax || //check header data
801
+    if (height < BlinkenHeightMin || height > BlinkenHeightMax ||       // check 
802
+                                                                        // 
803
+        // header 
804
+        // data
704 805
         width < BlinkenWidthMin || width > BlinkenWidthMax)
705 806
       return NULL;
706
-    pFrame = BlinkenFrameNew( height, width, 1, 1, 0 ); //create frame according to header data
807
+    pFrame = BlinkenFrameNew(height, width, 1, 1, 0);   // create frame
808
+    // according to
809
+    // header data
707 810
     if (pFrame == NULL)
708 811
       return NULL;
709 812
     i = sizeof(stBlinkenProtoBlpHdr);   // put data into frame
... ...
@@ -714,18 +817,29 @@ stBlinkenFrame * BlinkenFrameFromNetwork( char * pData, int length, etBlinkenPro
714 817
   }
715 818
 
716 819
   if (length >= (int)sizeof(stBlinkenProtoEblpHdr) &&
717
-      ((stBlinkenProtoEblpHdr *)pData)->magic == htonl( BlinkenProtoEblpMagic ) )
718
-  {
820
+      ((stBlinkenProtoEblpHdr *) pData)->magic ==
821
+      htonl(BlinkenProtoEblpMagic)) {
719 822
     if (pProto != NULL) // return protocol
720 823
       *pProto = BlinkenProtoEblp;
721
-    height = ntohs( ((stBlinkenProtoEblpHdr *)pData)->height ); //get header data
824
+    height = ntohs(((stBlinkenProtoEblpHdr *) pData)->height);  // get header 
825
+                                                                // 
826
+    // data
722 827
     width = ntohs(((stBlinkenProtoEblpHdr *) pData)->width);
723
-    if( length < (int)sizeof( stBlinkenProtoEblpHdr ) + width * height ) //check length of packet
828
+    if (length < (int)sizeof(stBlinkenProtoEblpHdr) + width * height)   // check 
829
+                                                                        // 
830
+      // length 
831
+      // of 
832
+      // packet
724 833
       return NULL;
725
-    if( height < BlinkenHeightMin || height > BlinkenHeightMax || //check header data
834
+    if (height < BlinkenHeightMin || height > BlinkenHeightMax ||       // check 
835
+                                                                        // 
836
+        // header 
837
+        // data
726 838
         width < BlinkenWidthMin || width > BlinkenWidthMax)
727 839
       return NULL;
728
-    pFrame = BlinkenFrameNew( height, width, 1, 255, 0 ); //create frame according to header data
840
+    pFrame = BlinkenFrameNew(height, width, 1, 255, 0); // create frame
841
+    // according to
842
+    // header data
729 843
     if (pFrame == NULL)
730 844
       return NULL;
731 845
     i = sizeof(stBlinkenProtoEblpHdr);  // put data into frame
... ...
@@ -736,22 +850,37 @@ stBlinkenFrame * BlinkenFrameFromNetwork( char * pData, int length, etBlinkenPro
736 850
   }
737 851
 
738 852
   if (length >= (int)sizeof(stBlinkenProtoMcufHdr) &&
739
-      ((stBlinkenProtoMcufHdr *)pData)->magic == htonl( BlinkenProtoMcufMagic ) )
740
-  {
853
+      ((stBlinkenProtoMcufHdr *) pData)->magic ==
854
+      htonl(BlinkenProtoMcufMagic)) {
741 855
     if (pProto != NULL) // return protocol
742 856
       *pProto = BlinkenProtoMcuf;
743
-    height = ntohs( ((stBlinkenProtoMcufHdr *)pData)->height ); //get header data
857
+    height = ntohs(((stBlinkenProtoMcufHdr *) pData)->height);  // get header 
858
+                                                                // 
859
+    // data
744 860
     width = ntohs(((stBlinkenProtoMcufHdr *) pData)->width);
745 861
     channels = ntohs(((stBlinkenProtoMcufHdr *) pData)->channels);
746 862
     maxval = ntohs(((stBlinkenProtoMcufHdr *) pData)->maxval);
747
-    if( length < (int)sizeof( stBlinkenProtoMcufHdr ) + height * width * channels ) //check length of packet
863
+    if (length < (int)sizeof(stBlinkenProtoMcufHdr) + height * width * channels)        // check 
864
+                                                                                        // 
865
+      // length 
866
+      // of 
867
+      // packet
748 868
       return NULL;
749
-    if( height < BlinkenHeightMin || height > BlinkenHeightMax || //check header data
869
+    if (height < BlinkenHeightMin || height > BlinkenHeightMax ||       // check 
870
+                                                                        // 
871
+        // header 
872
+        // data
750 873
         width < BlinkenWidthMin || width > BlinkenWidthMax ||
751 874
         channels < BlinkenChannelsMin || channels > BlinkenChannelsMax ||
752 875
         maxval < BlinkenMaxvalMin || maxval > BlinkenMaxvalMax)
753 876
       return NULL;
754
-    pFrame = BlinkenFrameNew( height, width, channels, maxval, 0 ); //create frame according to header data
877
+    pFrame = BlinkenFrameNew(height, width, channels, maxval, 0);       // create 
878
+                                                                        // 
879
+    // frame 
880
+    // according 
881
+    // to 
882
+    // header 
883
+    // data
755 884
     if (pFrame == NULL)
756 885
       return NULL;
757 886
     i = sizeof(stBlinkenProtoMcufHdr);  // put data into frame
... ...
@@ -1,17 +1,18 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #ifndef INC_BlinkenLib_BlinkenFrame
8 6
 #define INC_BlinkenLib_BlinkenFrame
9 7
 
10 8
 typedef struct sBlinkenFrame stBlinkenFrame;
11 9
 
12
-typedef enum eBlinkenProto { BlinkenProtoNone, BlinkenProtoBlp, BlinkenProtoEblp, BlinkenProtoMcuf } etBlinkenProto;
10
+typedef enum eBlinkenProto { BlinkenProtoNone, BlinkenProtoBlp,
11
+  BlinkenProtoEblp, BlinkenProtoMcuf
12
+} etBlinkenProto;
13 13
 
14
-stBlinkenFrame * BlinkenFrameNew( int height, int width, int channels, int maxval, int duration );
14
+stBlinkenFrame *BlinkenFrameNew(int height, int width, int channels,
15
+                                int maxval, int duration);
15 16
 
16 17
 stBlinkenFrame *BlinkenFrameClone(stBlinkenFrame * pSrcFrame);
17 18
 
... ...
@@ -27,11 +28,14 @@ int BlinkenFrameGetMaxval( stBlinkenFrame * pFrame );
27 28
 int BlinkenFrameGetDuration(stBlinkenFrame * pFrame);
28 29
 void BlinkenFrameSetDuration(stBlinkenFrame * pFrame, int duration);
29 30
 
30
-unsigned char BlinkenFrameGetPixel( stBlinkenFrame * pFrame, int y, int x, int c );
31
-void BlinkenFrameSetPixel( stBlinkenFrame * pFrame, int y, int x, int c, unsigned char val );
31
+unsigned char BlinkenFrameGetPixel(stBlinkenFrame * pFrame, int y, int x,
32
+                                   int c);
33
+void BlinkenFrameSetPixel(stBlinkenFrame * pFrame, int y, int x, int c,
34
+                          unsigned char val);
32 35
 
33 36
 unsigned long BlinkenFrameGetColor(stBlinkenFrame * pFrame, int y, int x);
34
-void BlinkenFrameSetColor( stBlinkenFrame * pFrame, int y, int x, unsigned long color );
37
+void BlinkenFrameSetColor(stBlinkenFrame * pFrame, int y, int x,
38
+                          unsigned long color);
35 39
 
36 40
 int BlinkenFrameIsEmpty(stBlinkenFrame * pFrame);
37 41
 // returns 1 if frame is empty (i.e. black), returns 0 otherwise
... ...
@@ -39,16 +43,20 @@ int BlinkenFrameIsEmpty( stBlinkenFrame * pFrame );
39 43
 int BlinkenFrameCompare(stBlinkenFrame * pFrame1, stBlinkenFrame * pFrame2);
40 44
 // returns -1 for frame1 smaller, 0 for equal, 1 for frame2 smaller
41 45
 
42
-void BlinkenFrameResize( stBlinkenFrame * pFrame, int height, int width, int channels, int maxval );
46
+void BlinkenFrameResize(stBlinkenFrame * pFrame, int height, int width,
47
+                        int channels, int maxval);
43 48
 void BlinkenFrameScale(stBlinkenFrame * pFrame, int height, int width);
44
-void BlinkenFrameColorize( stBlinkenFrame * pFrame, int channels, int mode, int step );
49
+void BlinkenFrameColorize(stBlinkenFrame * pFrame, int channels, int mode,
50
+                          int step);
45 51
 
46 52
 char *BlinkenFrameToString(stBlinkenFrame * pFrame);
47 53
 
48
-int BlinkenFrameToNetwork( stBlinkenFrame * pFrame, etBlinkenProto proto, char * pData, int maxLength );
54
+int BlinkenFrameToNetwork(stBlinkenFrame * pFrame, etBlinkenProto proto,
55
+                          char *pData, int maxLength);
49 56
 // returns length or -1 on error
50 57
 
51
-stBlinkenFrame * BlinkenFrameFromNetwork( char * pData, int length, etBlinkenProto * pProto );
58
+stBlinkenFrame *BlinkenFrameFromNetwork(char *pData, int length,
59
+                                        etBlinkenProto * pProto);
52 60
 // returns protocol in *pProto if pProto not NULL
53 61
 
54 62
 #endif // #ifndef INC_BlinkenLib_BlinkenFrame
... ...
@@ -1,8 +1,6 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #ifndef INC_BlinkenLib_BlinkenLib
8 6
 #define INC_BlinkenLib_BlinkenLib
... ...
@@ -1,8 +1,6 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #include <stdio.h>
8 6
 #include <stdlib.h>
... ...
@@ -28,9 +26,11 @@ typedef struct _BlMng_userdata {
28 26
   FILE *hFile;  // handle of open file
29 27
   unsigned int width;   // size of canvas
30 28
   unsigned int height;
31
-  unsigned char * canvas; // canvas (i.e. pixel data, size is height * width * 3)
29
+  unsigned char *canvas;        // canvas (i.e. pixel data, size is height *
30
+  // width * 3)
32 31
   unsigned int counter_msec;    // current number of milliseconds
33
-  unsigned int timer_msec; // the MNG library will be called after this number of milliseconds
32
+  unsigned int timer_msec;      // the MNG library will be called after this
33
+  // number of milliseconds
34 34
   stBlinkenMovie *movie;        // movie being created
35 35
 } BlMng_userdata;
36 36
 
... ...
@@ -58,7 +58,8 @@ mng_bool BlMng_closestream( mng_handle __attribute__(( unused )) hMNG )
58 58
 }
59 59
 
60 60
 // read data from the open file
61
-mng_bool BlMng_readdata( mng_handle hMNG, mng_ptr pBuf, mng_uint32 iSize, mng_uint32 * iRead )
61
+mng_bool BlMng_readdata(mng_handle hMNG, mng_ptr pBuf, mng_uint32 iSize,
62
+                        mng_uint32 * iRead)
62 63
 {
63 64
   BlMng_userdata *data = (BlMng_userdata *) mng_get_userdata(hMNG);
64 65
   *iRead = fread(pBuf, 1, iSize, data->hFile);
... ...
@@ -66,7 +67,8 @@ mng_bool BlMng_readdata( mng_handle hMNG, mng_ptr pBuf, mng_uint32 iSize, mng_ui
66 67
 }
67 68
 
68 69
 // write data to the open file
69
-mng_bool BlMng_writedata( mng_handle hMNG, mng_ptr pBuf, mng_uint32 iSize, mng_uint32 * iWritten )
70
+mng_bool BlMng_writedata(mng_handle hMNG, mng_ptr pBuf, mng_uint32 iSize,
71
+                         mng_uint32 * iWritten)
70 72
 {
71 73
   BlMng_userdata *data = (BlMng_userdata *) mng_get_userdata(hMNG);
72 74
   *iWritten = fwrite(pBuf, 1, iSize, data->hFile);
... ...
@@ -74,7 +76,8 @@ mng_bool BlMng_writedata( mng_handle hMNG, mng_ptr pBuf, mng_uint32 iSize, mng_u
74 76
 }
75 77
 
76 78
 // MNG library has processed the header information
77
-mng_bool BlMng_processheader( mng_handle hMNG, mng_uint32 iWidth, mng_uint32 iHeight )
79
+mng_bool BlMng_processheader(mng_handle hMNG, mng_uint32 iWidth,
80
+                             mng_uint32 iHeight)
78 81
 {
79 82
   BlMng_userdata *data = (BlMng_userdata *) mng_get_userdata(hMNG);
80 83
 
... ...
@@ -101,7 +102,8 @@ mng_bool BlMng_processheader( mng_handle hMNG, mng_uint32 iWidth, mng_uint32 iHe
101 102
   data->timer_msec = 0;
102 103
 
103 104
   // create new empty movie
104
-  data->movie = BlinkenMovieNew( iHeight, iWidth, 3, 255 ); // always 24 bit RGB
105
+  data->movie = BlinkenMovieNew(iHeight, iWidth, 3, 255);       // always 24
106
+  // bit RGB
105 107
   if (data->movie == NULL)
106 108
     return MNG_FALSE;
107 109
 
... ...
@@ -121,9 +123,14 @@ mng_ptr BlMng_getcanvasline( mng_handle hMNG, mng_uint32 iLinenr )
121 123
 }
122 124
 
123 125
 // the MNG library thinks that (a part of) the canvas should be shown
124
-mng_bool BlMng_refresh( mng_handle __attribute__(( unused )) hMNG, mng_uint32 __attribute__(( unused )) iX, mng_uint32 __attribute__(( unused )) iY, mng_uint32 __attribute__(( unused )) iWidth, mng_uint32 __attribute__(( unused )) iHeight )
126
+mng_bool BlMng_refresh(mng_handle __attribute__ ((unused)) hMNG, mng_uint32
127
+                       __attribute__ ((unused)) iX, mng_uint32
128
+                       __attribute__ ((unused)) iY, mng_uint32
129
+                       __attribute__ ((unused)) iWidth, mng_uint32
130
+                       __attribute__ ((unused)) iHeight)
125 131
 {
126
-  // nothing to do here for BlinkenLib as we are only converting and not displaying
132
+  // nothing to do here for BlinkenLib as we are only converting and not
133
+  // displaying
127 134
   return MNG_TRUE;
128 135
 }
129 136
 
... ...
@@ -132,7 +139,8 @@ mng_uint32 BlMng_gettickcount( mng_handle hMNG )
132 139
 {
133 140
   BlMng_userdata *data = (BlMng_userdata *) mng_get_userdata(hMNG);
134 141
 
135
-  // just return the current number of milliseconds (only converting, do not use real time for this)
142
+  // just return the current number of milliseconds (only converting, do not
143
+  // use real time for this)
136 144
   return data->counter_msec;
137 145
 }
138 146
 
... ...
@@ -148,7 +156,9 @@ mng_bool BlMng_settimer( mng_handle hMNG, mng_uint32 iMsecs )
148 156
 }
149 157
 
150 158
 // save as new frame to current movie
151
-void BlMng_save_frame( stBlinkenMovie * movie, unsigned int msec, unsigned int width, unsigned int height, unsigned char * data )
159
+void BlMng_save_frame(stBlinkenMovie * movie, unsigned int msec,
160
+                      unsigned int width, unsigned int height,
161
+                      unsigned char *data)
152 162
 {
153 163
   stBlinkenFrame *frame;
154 164
   unsigned int c, x, y;
... ...
@@ -178,11 +188,13 @@ void BlMng_save_frame( stBlinkenMovie * movie, unsigned int msec, unsigned int w
178 188
 }
179 189
 
180 190
 // compress pixel data in a frame
181
-void BlMng_compress_frame( stBlinkenFrame * frame, unsigned char * * p_out_ptr, unsigned int * p_out_len )
191
+void BlMng_compress_frame(stBlinkenFrame * frame, unsigned char **p_out_ptr,
192
+                          unsigned int *p_out_len)
182 193
 {
183 194
   unsigned int width = BlinkenFrameGetWidth(frame);
184 195
   unsigned int height = BlinkenFrameGetHeight(frame);
185
-  // channels is always 3, maxval is always 255 - this function is only called with frames from moivies with those parameters
196
+  // channels is always 3, maxval is always 255 - this function is only
197
+  // called with frames from moivies with those parameters
186 198
   unsigned int row_stride, raw_len, y, x, c;
187 199
   unsigned char *raw_ptr, *ptr, *out_ptr;
188 200
   unsigned long out_len;
... ...
@@ -206,7 +218,9 @@ void BlMng_compress_frame( stBlinkenFrame * frame, unsigned char * * p_out_ptr,
206 218
   }     // for( y ...
207 219
 
208 220
   // compress data
209
-  out_len = raw_len + (raw_len + 999) / 1000 + 12; // must be at least <source length> * 1.001 + 12
221
+  out_len = raw_len + (raw_len + 999) / 1000 + 12;      // must be at least
222
+  // <source length> *
223
+  // 1.001 + 12
210 224
   out_ptr = (unsigned char *)malloc(out_len);
211 225
   compress2(out_ptr, &out_len, raw_ptr, raw_len, Z_BEST_COMPRESSION);
212 226
   free(raw_ptr);
... ...
@@ -242,7 +254,8 @@ stBlinkenMovie * BlinkenMngLoad( char * pFilename )
242 254
     if (data->hFile != NULL) {
243 255
 
244 256
       // initialize MNG library
245
-      hMNG = mng_initialize( (mng_ptr)data, BlMng_alloc, BlMng_free, MNG_NULL );
257
+      hMNG =
258
+          mng_initialize((mng_ptr) data, BlMng_alloc, BlMng_free, MNG_NULL);
246 259
       if (hMNG) {
247 260
 
248 261
         // set MNG callbacks
... ...
@@ -270,7 +283,8 @@ stBlinkenMovie * BlinkenMngLoad( char * pFilename )
270 283
               while (iRC == MNG_NEEDTIMERWAIT && data->timer_msec > 0) {
271 284
 
272 285
                 // save fame to movie
273
-                BlMng_save_frame( data->movie, data->timer_msec, data->width, data->height, data->canvas );
286
+                BlMng_save_frame(data->movie, data->timer_msec, data->width,
287
+                                 data->height, data->canvas);
274 288
                 b_saved = 1;
275 289
                 ++frame_idx;
276 290
 
... ...
@@ -285,18 +299,28 @@ stBlinkenMovie * BlinkenMngLoad( char * pFilename )
285 299
 
286 300
               } // while( iRC == MNG_NEEDTIMERWAIT && data->timer_msec > 0 )
287 301
 
288
-              // save single frame if no frame saved yet (i.e. not an animated MNG image)
302
+              // save single frame if no frame saved yet (i.e. not an
303
+              // animated MNG image)
289 304
               if (!b_saved)
290
-                BlMng_save_frame( data->movie, data->timer_msec, data->width, data->height, data->canvas );
291
-
292
-              // if movie has more than one frame and the last frame is empty with duration of 1ms, remove last frame
293
-              //  - a black frame with 1ms duration is inserted by MNG library when MNG requests to clean canvas after displaying
294
-              //    - the reqauest to clear canvas after end of MNG anmation is needed to preserve duration of last frame (when converting from native format to MNG)
295
-              //  - remove this frame that is created by the described side effect
305
+                BlMng_save_frame(data->movie, data->timer_msec, data->width,
306
+                                 data->height, data->canvas);
307
+
308
+              // if movie has more than one frame and the last frame is empty 
309
+              // 
310
+              // with duration of 1ms, remove last frame
311
+              // - a black frame with 1ms duration is inserted by MNG library 
312
+              // 
313
+              // when MNG requests to clean canvas after displaying
314
+              // - the reqauest to clear canvas after end of MNG anmation is
315
+              // needed to preserve duration of last frame (when converting
316
+              // from native format to MNG)
317
+              // - remove this frame that is created by the described side
318
+              // effect
296 319
               {
297 320
                 unsigned int frame_cnt = BlinkenMovieGetFrameCnt(data->movie);
298 321
                 if (frame_cnt >= 1) {
299
-                  stBlinkenFrame * frame = BlinkenMovieGetFrame( data->movie, frame_cnt - 1 );
322
+                  stBlinkenFrame *frame =
323
+                      BlinkenMovieGetFrame(data->movie, frame_cnt - 1);
300 324
                   if (frame != NULL && BlinkenFrameIsEmpty(frame))
301 325
                     BlinkenMovieDeleteFrame(data->movie, frame_cnt - 1);
302 326
                 }
... ...
@@ -363,7 +387,8 @@ int BlinkenMngSave( stBlinkenMovie * pMovie, char * pFilename )
363 387
       if (data->hFile != NULL) {
364 388
 
365 389
         // initialize MNG library
366
-        hMNG = mng_initialize( (mng_ptr)data, BlMng_alloc, BlMng_free, MNG_NULL );
390
+        hMNG =
391
+            mng_initialize((mng_ptr) data, BlMng_alloc, BlMng_free, MNG_NULL);
367 392
         if (hMNG) {
368 393
 
369 394
           // set MNG callbacks
... ...
@@ -377,29 +402,44 @@ int BlinkenMngSave( stBlinkenMovie * pMovie, char * pFilename )
377 402
               // write MNG chunks
378 403
               do {
379 404
                 unsigned int frame_cnt = BlinkenMovieGetFrameCnt(data->movie);
380
-                unsigned int total_duration = BlinkenMovieGetDuration( data->movie );
405
+                unsigned int total_duration =
406
+                    BlinkenMovieGetDuration(data->movie);
381 407
                 unsigned int frame_no;
382 408
 
383 409
                 // write MG header chunks
384
-                if( mng_putchunk_mhdr( hMNG,
385
-                                       data->width, data->height, // dimensions
386
-                                       1000, 0, frame_cnt, total_duration, // ticks per second, layer, frame count, duration
410
+                if (mng_putchunk_mhdr(hMNG, data->width, data->height,  // dimensions
411
+                                      1000, 0, frame_cnt, total_duration,       // ticks 
412
+                                                                                // 
413
+                                      // per 
414
+                                      // second, 
415
+                                      // layer, 
416
+                                      // frame 
417
+                                      // count, 
418
+                                      // duration
387 419
                                       MNG_SIMPLICITY_VALID | MNG_SIMPLICITY_SIMPLEFEATURES | MNG_SIMPLICITY_COMPLEXFEATURES     // simplicity
388 420
                     ) != 0)
389 421
                   break;
390 422
 
391
-                if( mng_putchunk_save( hMNG,
392
-                                       MNG_TRUE, // empty SAVE chunk
423
+                if (mng_putchunk_save(hMNG, MNG_TRUE,   // empty SAVE chunk
393 424
                                       0, 0      // no offset, no count
394 425
                     ) != 0)
395 426
                   break;
396 427
 
397 428
                 // tell MNG player to clear canvas after end of MNG animation
398 429
                 // - this is needed to preserve duration of last frame
399
-                //  - this results in a black frame with 1ms duration at the end of the MNG as side effect
400
-                if( mng_putchunk_term( hMNG,
401
-                                       MNG_TERMACTION_CLEAR, MNG_ITERACTION_CLEAR, // show last frame forever after end of animation
402
-                                       0, 0 // no repeat delay, no maximum iteration count
430
+                // - this results in a black frame with 1ms duration at the
431
+                // end of the MNG as side effect
432
+                if (mng_putchunk_term(hMNG, MNG_TERMACTION_CLEAR, MNG_ITERACTION_CLEAR, // show 
433
+                                                                                        // 
434
+                                      // last 
435
+                                      // frame 
436
+                                      // forever 
437
+                                      // after 
438
+                                      // end 
439
+                                      // of 
440
+                                      // animation
441
+                                      0, 0      // no repeat delay, no
442
+                                      // maximum iteration count
403 443
                     ) != 0)
404 444
                   break;
405 445
 
... ...
@@ -407,35 +447,57 @@ int BlinkenMngSave( stBlinkenMovie * pMovie, char * pFilename )
407 447
                 for (frame_no = 0; frame_no < frame_cnt; frame_no++) {
408 448
 
409 449
                   // get current frame
410
-                  stBlinkenFrame * frame = BlinkenMovieGetFrame( data->movie, frame_no );
411
-                  unsigned int frame_duration = BlinkenFrameGetDuration( frame );
450
+                  stBlinkenFrame *frame =
451
+                      BlinkenMovieGetFrame(data->movie, frame_no);
452
+                  unsigned int frame_duration =
453
+                      BlinkenFrameGetDuration(frame);
412 454
 
413 455
                   // write MNG frame header chunks
414
-                  if( mng_putchunk_seek( hMNG,
415
-                                         0, MNG_NULL // no name
456
+                  if (mng_putchunk_seek(hMNG, 0, MNG_NULL       // no name
416 457
                       ) != 0)
417 458
                     break;
418 459
 
419
-                  if( mng_putchunk_fram( hMNG,
420
-                                         MNG_FALSE, frame_no == 0 ? MNG_FRAMINGMODE_1 : MNG_FRAMINGMODE_NOCHANGE, // empty, mode
460
+                  if (mng_putchunk_fram(hMNG, MNG_FALSE, frame_no == 0 ? MNG_FRAMINGMODE_1 : MNG_FRAMINGMODE_NOCHANGE,  // empty, 
461
+                                                                                                                        // 
462
+                                        // mode
421 463
                                         0, MNG_NULL,    // frame name
422
-                                         MNG_CHANGEDELAY_DEFAULT, MNG_CHANGETIMOUT_NO, MNG_CHANGECLIPPING_NO, MNG_CHANGESYNCID_NO, // changing only delay
423
-                                         frame_duration, 0, // new delay, no new timeout
464
+                                        MNG_CHANGEDELAY_DEFAULT, MNG_CHANGETIMOUT_NO, MNG_CHANGECLIPPING_NO, MNG_CHANGESYNCID_NO,       // changing 
465
+                                                                                                                                        // 
466
+                                        // only 
467
+                                        // delay
468
+                                        frame_duration, 0,      // new delay, 
469
+                                                                // 
470
+                                        // no new
471
+                                        // timeout
424 472
                                         0, 0, 0, 0, 0,  // no new boundary
425 473
                                         0, 0    // no count, no IDs
426 474
                       ) != 0)
427 475
                     break;
428 476
 
429
-                  if( mng_putchunk_defi( hMNG,
430
-                                         0, MNG_DONOTSHOW_VISIBLE, MNG_ABSTRACT, // no ID, visible, abstract
477
+                  if (mng_putchunk_defi(hMNG, 0, MNG_DONOTSHOW_VISIBLE, MNG_ABSTRACT,   // no 
478
+                                                                                        // 
479
+                                        // ID, 
480
+                                        // visible, 
481
+                                        // abstract
431 482
                                         MNG_TRUE, 0, 0, // top left location
432
-                                         MNG_FALSE, 0, 0, 0, 0 // no clipping
483
+                                        MNG_FALSE, 0, 0, 0, 0   // no
484
+                                        // clipping
433 485
                       ) != 0)
434 486
                     break;
435 487
 
436
-                  if( mng_putchunk_ihdr( hMNG,
437
-                                         data->width, data->height, 8, MNG_COLORTYPE_RGB, // dimensions and 8 bit RGB
438
-                                         MNG_COMPRESSION_DEFLATE, MNG_FILTER_ADAPTIVE, MNG_INTERLACE_NONE // deflate compression, adaptive filter, no interlacing
488
+                  if (mng_putchunk_ihdr(hMNG, data->width, data->height, 8, MNG_COLORTYPE_RGB,  // dimensions 
489
+                                                                                                // 
490
+                                        // and 
491
+                                        // 8 
492
+                                        // bit 
493
+                                        // RGB
494
+                                        MNG_COMPRESSION_DEFLATE, MNG_FILTER_ADAPTIVE, MNG_INTERLACE_NONE        // deflate 
495
+                                                                                                                // 
496
+                                        // compression, 
497
+                                        // adaptive 
498
+                                        // filter, 
499
+                                        // no 
500
+                                        // interlacing
439 501
                       ) != 0)
440 502
                     break;
441 503
 
... ...
@@ -447,7 +509,9 @@ int BlinkenMngSave( stBlinkenMovie * pMovie, char * pFilename )
447 509
 
448 510
                     BlMng_compress_frame(frame, &ptr, &len);
449 511
 
450
-                    iRC = mng_putchunk_idat( hMNG, (mng_uint32)len, (mng_ptr)ptr );
512
+                    iRC =
513
+                        mng_putchunk_idat(hMNG, (mng_uint32) len,
514
+                                          (mng_ptr) ptr);
451 515
                     free(ptr);
452 516
                     if (iRC != 0)
453 517
                       break;
... ...
@@ -458,7 +522,9 @@ int BlinkenMngSave( stBlinkenMovie * pMovie, char * pFilename )
458 522
                     break;
459 523
 
460 524
                 }       // for( frame ...
461
-                if( frame_no < frame_cnt ) // if not all frames have been processed there was en error
525
+                if (frame_no < frame_cnt)       // if not all frames have
526
+                  // been processed there was
527
+                  // en error
462 528
                   break;
463 529
 
464 530
                 // output MNG end chunk
... ...
@@ -1,8 +1,6 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #ifndef INC_BlinkenLib_BlinkenMng
8 6
 #define INC_BlinkenLib_BlinkenMng
... ...
@@ -1,8 +1,6 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #include <stdio.h>
8 6
 #include <stdlib.h>
... ...
@@ -26,8 +24,7 @@
26 24
 #include <BlinkenLib/BlinkenMng.h>
27 25
 #endif // #ifdef BLINKENLIB_CFG_MNG
28 26
 
29
-struct sBlinkenMovie
30
-{
27
+struct sBlinkenMovie {
31 28
   int height;
32 29
   int width;
33 30
   int channels;
... ...
@@ -66,18 +63,27 @@ static unsigned int get_ms( )
66 63
 
67 64
 #endif
68 65
 
69
-stBlinkenMovie * BlinkenMovieNew( int height, int width, int channels, int maxval )
66
+stBlinkenMovie *BlinkenMovieNew(int height, int width, int channels,
67
+                                int maxval)
70 68
 {
71 69
   stBlinkenMovie *pMovie;
72 70
 
73
-  if( height < BlinkenHeightMin ) height = BlinkenHeightMin;
74
-  if( height > BlinkenHeightMax ) height = BlinkenHeightMax;
75
-  if( width < BlinkenWidthMin ) width = BlinkenWidthMin;
76
-  if( width > BlinkenWidthMax ) width = BlinkenWidthMax;
77
-  if( channels < BlinkenChannelsMin ) channels = BlinkenChannelsMin;
78
-  if( channels > BlinkenChannelsMax ) channels = BlinkenMaxvalMax;
79
-  if( maxval < BlinkenMaxvalMin ) maxval = BlinkenMaxvalMin;
80
-  if( maxval > BlinkenMaxvalMax ) maxval = BlinkenMaxvalMax;
71
+  if (height < BlinkenHeightMin)
72
+    height = BlinkenHeightMin;
73
+  if (height > BlinkenHeightMax)
74
+    height = BlinkenHeightMax;
75
+  if (width < BlinkenWidthMin)
76
+    width = BlinkenWidthMin;
77
+  if (width > BlinkenWidthMax)
78
+    width = BlinkenWidthMax;
79
+  if (channels < BlinkenChannelsMin)
80
+    channels = BlinkenChannelsMin;
81
+  if (channels > BlinkenChannelsMax)
82
+    channels = BlinkenMaxvalMax;
83
+  if (maxval < BlinkenMaxvalMin)
84
+    maxval = BlinkenMaxvalMin;
85
+  if (maxval > BlinkenMaxvalMax)
86
+    maxval = BlinkenMaxvalMax;
81 87
 
82 88
   pMovie = (stBlinkenMovie *) malloc(sizeof(stBlinkenMovie));
83 89
   if (pMovie == NULL)
... ...
@@ -89,15 +95,14 @@ stBlinkenMovie * BlinkenMovieNew( int height, int width, int channels, int maxva
89 95
   pMovie->maxval = maxval;
90 96
   pMovie->infoCnt = 0;
91 97
   pMovie->pppInfos = (char ***)malloc2D(0, 2, sizeof(char *));
92
-  if( pMovie->pppInfos == NULL )
93
-  {
98
+  if (pMovie->pppInfos == NULL) {
94 99
     free(pMovie);
95 100
     return NULL;
96 101
   }
97 102
   pMovie->frameCnt = 0;
98
-  pMovie->ppFrames = (stBlinkenFrame * *)malloc1D( 0, sizeof( stBlinkenFrame * ) );
99
-  if( pMovie->ppFrames == NULL )
100
-  {
103
+  pMovie->ppFrames =
104
+      (stBlinkenFrame **) malloc1D(0, sizeof(stBlinkenFrame *));
105
+  if (pMovie->ppFrames == NULL) {
101 106
     free(pMovie->pppInfos);
102 107
     free(pMovie);
103 108
     return NULL;
... ...
@@ -112,15 +117,17 @@ stBlinkenMovie * BlinkenMovieClone( stBlinkenMovie * pSrcMovie )
112 117
   stBlinkenFrame *pFrame;
113 118
   int i;
114 119
 
115
-  pMovie = BlinkenMovieNew( pSrcMovie->height, pSrcMovie->width, pSrcMovie->channels, pSrcMovie->maxval );
120
+  pMovie =
121
+      BlinkenMovieNew(pSrcMovie->height, pSrcMovie->width,
122
+                      pSrcMovie->channels, pSrcMovie->maxval);
116 123
   if (pMovie == NULL)
117 124
     return NULL;
118 125
 
119 126
   for (i = 0; i < pSrcMovie->infoCnt; i++)
120
-    BlinkenMovieAppendInfo( pMovie, pSrcMovie->pppInfos[i][0], pSrcMovie->pppInfos[i][1] );
127
+    BlinkenMovieAppendInfo(pMovie, pSrcMovie->pppInfos[i][0],
128
+                           pSrcMovie->pppInfos[i][1]);
121 129
 
122
-  for( i = 0; i < pSrcMovie->frameCnt; i++ )
123
-  {
130
+  for (i = 0; i < pSrcMovie->frameCnt; i++) {
124 131
     pFrame = BlinkenFrameClone(pSrcMovie->ppFrames[i]);
125 132
     if (BlinkenMovieAppendFrame(pMovie, pFrame) != 0)
126 133
       BlinkenFrameFree(pFrame);
... ...
@@ -136,8 +143,7 @@ void BlinkenMovieFree( stBlinkenMovie * pMovie )
136 143
   if (pMovie == NULL)
137 144
     return;
138 145
 
139
-  for( i = 0; i < pMovie->infoCnt; i++ )
140
-  {
146
+  for (i = 0; i < pMovie->infoCnt; i++) {
141 147
     free(pMovie->pppInfos[i][0]);
142 148
     free(pMovie->pppInfos[i][1]);
143 149
   }
... ...
@@ -208,8 +214,10 @@ char * BlinkenMovieGetInfoType( stBlinkenMovie * pMovie, int infoNo )
208 214
   if (pMovie == NULL || pMovie->infoCnt < 1)
209 215
     return "";
210 216
 
211
-  if( infoNo < 0 ) infoNo = 0;
212
-  if( infoNo >= pMovie->infoCnt ) infoNo = pMovie->infoCnt - 1;
217
+  if (infoNo < 0)
218
+    infoNo = 0;
219
+  if (infoNo >= pMovie->infoCnt)
220
+    infoNo = pMovie->infoCnt - 1;
213 221
   return pMovie->pppInfos[infoNo][0];
214 222
 }
215 223
 
... ...
@@ -218,12 +226,15 @@ char * BlinkenMovieGetInfoData( stBlinkenMovie * pMovie, int infoNo )
218 226
   if (pMovie == NULL || pMovie->infoCnt < 1)
219 227
     return "";
220 228
 
221
-  if( infoNo < 0 ) infoNo = 0;
222
-  if( infoNo >= pMovie->infoCnt ) infoNo = pMovie->infoCnt - 1;
229
+  if (infoNo < 0)
230
+    infoNo = 0;
231
+  if (infoNo >= pMovie->infoCnt)
232
+    infoNo = pMovie->infoCnt - 1;
223 233
   return pMovie->pppInfos[infoNo][1];
224 234
 }
225 235
 
226
-void BlinkenMovieSetInfo( stBlinkenMovie * pMovie, int infoNo, char * pInfoType, char * pInfoData )
236
+void BlinkenMovieSetInfo(stBlinkenMovie * pMovie, int infoNo, char *pInfoType,
237
+                         char *pInfoData)
227 238
 {
228 239
   char *pType, *pData;
229 240
 
... ...
@@ -234,8 +245,7 @@ void BlinkenMovieSetInfo( stBlinkenMovie * pMovie, int infoNo, char * pInfoType,
234 245
   if (pType == NULL)
235 246
     return;
236 247
   pData = strdup(pInfoData);
237
-  if( pData == NULL )
238
-  {
248
+  if (pData == NULL) {
239 249
     free(pType);
240 250
     return;
241 251
   }
... ...
@@ -246,7 +256,8 @@ void BlinkenMovieSetInfo( stBlinkenMovie * pMovie, int infoNo, char * pInfoType,
246 256
   pMovie->pppInfos[infoNo][1] = pData;
247 257
 }
248 258
 
249
-void BlinkenMovieInsertInfo( stBlinkenMovie * pMovie, int infoNo, char * pInfoType, char * pInfoData )
259
+void BlinkenMovieInsertInfo(stBlinkenMovie * pMovie, int infoNo,
260
+                            char *pInfoType, char *pInfoData)
250 261
 {
251 262
   char ***pppNewInfos, *pType, *pData;
252 263
   int i;
... ...
@@ -259,21 +270,18 @@ void BlinkenMovieInsertInfo( stBlinkenMovie * pMovie, int infoNo, char * pInfoTy
259 270
     return;
260 271
 
261 272
   pType = strdup(pInfoType);
262
-  if( pType == NULL )
263
-  {
273
+  if (pType == NULL) {
264 274
     free(pppNewInfos);
265 275
     return;
266 276
   }
267 277
   pData = strdup(pInfoData);
268
-  if( pData == NULL )
269
-  {
278
+  if (pData == NULL) {
270 279
     free(pppNewInfos);
271 280
     free(pType);
272 281
     return;
273 282
   }
274 283
 
275
-  for( i = 0; i < infoNo; i++ )
276
-  {
284
+  for (i = 0; i < infoNo; i++) {
277 285
     pppNewInfos[i][0] = pMovie->pppInfos[i][0];
278 286
     pppNewInfos[i][1] = pMovie->pppInfos[i][1];
279 287
   }
... ...
@@ -281,8 +289,7 @@ void BlinkenMovieInsertInfo( stBlinkenMovie * pMovie, int infoNo, char * pInfoTy
281 289
   pppNewInfos[infoNo][0] = pType;
282 290
   pppNewInfos[infoNo][1] = pData;
283 291
 
284
-  for( i = infoNo; i < pMovie->infoCnt; i++ )
285
-  {
292
+  for (i = infoNo; i < pMovie->infoCnt; i++) {
286 293
     pppNewInfos[i + 1][0] = pMovie->pppInfos[i][0];
287 294
     pppNewInfos[i + 1][1] = pMovie->pppInfos[i][1];
288 295
   }
... ...
@@ -292,7 +299,8 @@ void BlinkenMovieInsertInfo( stBlinkenMovie * pMovie, int infoNo, char * pInfoTy
292 299
   pMovie->infoCnt++;
293 300
 }
294 301
 
295
-void BlinkenMovieAppendInfo( stBlinkenMovie * pMovie, char * pInfoType, char * pInfoData )
302
+void BlinkenMovieAppendInfo(stBlinkenMovie * pMovie, char *pInfoType,
303
+                            char *pInfoData)
296 304
 {
297 305
   if (pMovie == NULL)
298 306
     return;
... ...
@@ -312,8 +320,7 @@ void BlinkenMovieDeleteInfo( stBlinkenMovie * pMovie, int infoNo )
312 320
   if (pppNewInfos == NULL)
313 321
     return;
314 322
 
315
-  for( i = 0; i < infoNo; i++ )
316
-  {
323
+  for (i = 0; i < infoNo; i++) {
317 324
     pppNewInfos[i][0] = pMovie->pppInfos[i][0];
318 325
     pppNewInfos[i][1] = pMovie->pppInfos[i][1];
319 326
   }
... ...
@@ -321,8 +328,7 @@ void BlinkenMovieDeleteInfo( stBlinkenMovie * pMovie, int infoNo )
321 328
   free(pMovie->pppInfos[infoNo][0]);
322 329
   free(pMovie->pppInfos[infoNo][1]);
323 330
 
324
-  for( i = infoNo; i < pMovie->infoCnt - 1; i++ )
325
-  {
331
+  for (i = infoNo; i < pMovie->infoCnt - 1; i++) {
326 332
     pppNewInfos[i][0] = pMovie->pppInfos[i + 1][0];
327 333
     pppNewInfos[i][1] = pMovie->pppInfos[i + 1][1];
328 334
   }
... ...
@@ -344,8 +350,7 @@ void BlinkenMovieDeleteInfos( stBlinkenMovie * pMovie )
344 350
   if (pppNewInfos == NULL)
345 351
     return;
346 352
 
347
-  for( i = 0; i < pMovie->infoCnt; i++ )
348
-  {
353
+  for (i = 0; i < pMovie->infoCnt; i++) {
349 354
     free(pMovie->pppInfos[i][0]);
350 355
     free(pMovie->pppInfos[i][1]);
351 356
   }
... ...
@@ -368,21 +373,26 @@ stBlinkenFrame * BlinkenMovieGetFrame( stBlinkenMovie * pMovie, int frameNo )
368 373
   if (pMovie == NULL || pMovie->frameCnt < 1)
369 374
     return NULL;
370 375
 
371
-  if( frameNo < 0 ) frameNo = 0;
372
-  if( frameNo >= pMovie->frameCnt ) frameNo = pMovie->frameCnt - 1;
376
+  if (frameNo < 0)
377
+    frameNo = 0;
378
+  if (frameNo >= pMovie->frameCnt)
379
+    frameNo = pMovie->frameCnt - 1;
373 380
   return pMovie->ppFrames[frameNo];
374 381
 }
375 382
 
376
-void BlinkenMovieSetFrame( stBlinkenMovie * pMovie, int frameNo, stBlinkenFrame * pFrame )
383
+void BlinkenMovieSetFrame(stBlinkenMovie * pMovie, int frameNo,
384
+                          stBlinkenFrame * pFrame)
377 385
 {
378 386
   if (pMovie == NULL || frameNo < 0 || frameNo >= pMovie->frameCnt)
379 387
     return;
380 388
 
381
-  BlinkenFrameResize( pFrame, pMovie->height, pMovie->width, pMovie->channels, pMovie->maxval );
389
+  BlinkenFrameResize(pFrame, pMovie->height, pMovie->width, pMovie->channels,
390
+                     pMovie->maxval);
382 391
   pMovie->ppFrames[frameNo] = pFrame;
383 392
 }
384 393
 
385
-int BlinkenMovieInsertFrame( stBlinkenMovie * pMovie, int frameNo, stBlinkenFrame * pFrame )
394
+int BlinkenMovieInsertFrame(stBlinkenMovie * pMovie, int frameNo,
395
+                            stBlinkenFrame * pFrame)
386 396
 {
387 397
   stBlinkenFrame **ppNewFrames;
388 398
   int i;
... ...
@@ -390,14 +400,17 @@ int BlinkenMovieInsertFrame( stBlinkenMovie * pMovie, int frameNo, stBlinkenFram
390 400
   if (pMovie == NULL || frameNo < 0 || frameNo > pMovie->frameCnt)
391 401
     return -1;
392 402
 
393
-  ppNewFrames = (stBlinkenFrame * *)malloc1D( pMovie->frameCnt + 1, sizeof( stBlinkenFrame * ) );
403
+  ppNewFrames =
404
+      (stBlinkenFrame **) malloc1D(pMovie->frameCnt + 1,
405
+                                   sizeof(stBlinkenFrame *));
394 406
   if (ppNewFrames == NULL)
395 407
     return -1;
396 408
 
397 409
   for (i = 0; i < frameNo; i++)
398 410
     ppNewFrames[i] = pMovie->ppFrames[i];
399 411
 
400
-  BlinkenFrameResize( pFrame, pMovie->height, pMovie->width, pMovie->channels, pMovie->maxval );
412
+  BlinkenFrameResize(pFrame, pMovie->height, pMovie->width, pMovie->channels,
413
+                     pMovie->maxval);
401 414
   ppNewFrames[frameNo] = pFrame;
402 415
 
403 416
   for (i = frameNo; i < pMovie->frameCnt; i++)
... ...
@@ -425,7 +438,9 @@ void BlinkenMovieDeleteFrame( stBlinkenMovie * pMovie, int frameNo )
425 438
   if (pMovie == NULL || frameNo < 0 || frameNo >= pMovie->frameCnt)
426 439
     return;
427 440
 
428
-  ppNewFrames = (stBlinkenFrame * *)malloc1D( pMovie->frameCnt - 1, sizeof( stBlinkenFrame * ) );
441
+  ppNewFrames =
442
+      (stBlinkenFrame **) malloc1D(pMovie->frameCnt - 1,
443
+                                   sizeof(stBlinkenFrame *));
429 444
   if (ppNewFrames == NULL)
430 445
     return;
431 446
 
... ...
@@ -462,7 +477,10 @@ void BlinkenMovieDeleteFrames( stBlinkenMovie * pMovie )
462 477
   pMovie->frameCnt = 0;
463 478
 }
464 479
 
465
-int BlinkenMovieConcat( stBlinkenMovie * pMovie, stBlinkenMovie * pMovie2 /* appended and freed */ )
480
+int BlinkenMovieConcat(stBlinkenMovie * pMovie, stBlinkenMovie * pMovie2        /* appended 
481
+                                                                                   and 
482
+                                                                                   freed 
483
+                                                                                 */ )
466 484
 {
467 485
   stBlinkenFrame **ppNewFrames, **ppNewFrames2;
468 486
   int i;
... ...
@@ -470,9 +488,12 @@ int BlinkenMovieConcat( stBlinkenMovie * pMovie, stBlinkenMovie * pMovie2 /* app
470 488
   if (pMovie == NULL || pMovie2 == NULL)
471 489
     return -1;
472 490
 
473
-  BlinkenMovieResize( pMovie2, pMovie->height, pMovie->width, pMovie->channels, pMovie->maxval );
491
+  BlinkenMovieResize(pMovie2, pMovie->height, pMovie->width, pMovie->channels,
492
+                     pMovie->maxval);
474 493
 
475
-  ppNewFrames = (stBlinkenFrame * *)malloc1D( pMovie->frameCnt + pMovie2->frameCnt, sizeof( stBlinkenFrame * ) );
494
+  ppNewFrames =
495
+      (stBlinkenFrame **) malloc1D(pMovie->frameCnt + pMovie2->frameCnt,
496
+                                   sizeof(stBlinkenFrame *));
476 497
   if (ppNewFrames == NULL)
477 498
     return -1;
478 499
   ppNewFrames2 = (stBlinkenFrame **) malloc1D(0, sizeof(stBlinkenFrame *));
... ...
@@ -511,21 +532,30 @@ void BlinkenMovieReverse( stBlinkenMovie * pMovie )
511 532
   }
512 533
 }
513 534
 
514
-void BlinkenMovieResize( stBlinkenMovie * pMovie, int height, int width, int channels, int maxval )
535
+void BlinkenMovieResize(stBlinkenMovie * pMovie, int height, int width,
536
+                        int channels, int maxval)
515 537
 {
516 538
   int i;
517 539
 
518 540
   if (pMovie == NULL)
519 541
     return;
520 542
 
521
-  if( height < BlinkenHeightMin ) height = BlinkenHeightMin;
522
-  if( height > BlinkenHeightMax ) height = BlinkenHeightMax;
523
-  if( width < BlinkenWidthMin ) width = BlinkenWidthMin;
524
-  if( width > BlinkenWidthMax ) width = BlinkenWidthMax;
525
-  if( channels < BlinkenChannelsMin ) channels = BlinkenChannelsMin;
526
-  if( channels > BlinkenChannelsMax ) channels = BlinkenMaxvalMax;
527
-  if( maxval < BlinkenMaxvalMin ) maxval = BlinkenMaxvalMin;
528
-  if( maxval > BlinkenMaxvalMax ) maxval = BlinkenMaxvalMax;
543
+  if (height < BlinkenHeightMin)
544
+    height = BlinkenHeightMin;
545
+  if (height > BlinkenHeightMax)
546
+    height = BlinkenHeightMax;
547
+  if (width < BlinkenWidthMin)
548
+    width = BlinkenWidthMin;
549
+  if (width > BlinkenWidthMax)
550
+    width = BlinkenWidthMax;
551
+  if (channels < BlinkenChannelsMin)
552
+    channels = BlinkenChannelsMin;
553
+  if (channels > BlinkenChannelsMax)
554
+    channels = BlinkenMaxvalMax;
555
+  if (maxval < BlinkenMaxvalMin)
556
+    maxval = BlinkenMaxvalMin;
557
+  if (maxval > BlinkenMaxvalMax)
558
+    maxval = BlinkenMaxvalMax;
529 559
 
530 560
   pMovie->height = height;
531 561
   pMovie->width = width;
... ...
@@ -543,10 +573,14 @@ void BlinkenMovieScale( stBlinkenMovie * pMovie, int height, int width )
543 573
   if (pMovie == NULL)
544 574
     return;
545 575
 
546
-  if( height < BlinkenHeightMin ) height = BlinkenHeightMin;
547
-  if( height > BlinkenHeightMax ) height = BlinkenHeightMax;
548
-  if( width < BlinkenWidthMin ) width = BlinkenWidthMin;
549
-  if( width > BlinkenWidthMax ) width = BlinkenWidthMax;
576
+  if (height < BlinkenHeightMin)
577
+    height = BlinkenHeightMin;
578
+  if (height > BlinkenHeightMax)
579
+    height = BlinkenHeightMax;
580
+  if (width < BlinkenWidthMin)
581
+    width = BlinkenWidthMin;
582
+  if (width > BlinkenWidthMax)
583
+    width = BlinkenWidthMax;
550 584
 
551 585
   pMovie->height = height;
552 586
   pMovie->width = width;
... ...
@@ -562,15 +596,16 @@ void BlinkenMovieColorize( stBlinkenMovie * pMovie, int channels, int mode )
562 596
   if (pMovie == NULL)
563 597
     return;
564 598
 
565
-  if( channels < BlinkenChannelsMin ) channels = BlinkenChannelsMin;
566
-  if( channels > BlinkenChannelsMax ) channels = BlinkenMaxvalMax;
599
+  if (channels < BlinkenChannelsMin)
600
+    channels = BlinkenChannelsMin;
601
+  if (channels > BlinkenChannelsMax)
602
+    channels = BlinkenMaxvalMax;
567 603
 
568 604
   pMovie->channels = channels;
569 605
   pMovie->maxval = BlinkenMaxvalMax;
570 606
 
571 607
   step = 0;
572
-  for( i = 0; i < pMovie->frameCnt; i++ )
573
-  {
608
+  for (i = 0; i < pMovie->frameCnt; i++) {
574 609
     BlinkenFrameColorize(pMovie->ppFrames[i], channels, mode, step);
575 610
     step += BlinkenFrameGetDuration(pMovie->ppFrames[i]);
576 611
   }
... ...
@@ -588,11 +623,9 @@ char * BlinkenMovieToString( stBlinkenMovie * pMovie )
588 623
   if (strs == NULL)
589 624
     return NULL;
590 625
 
591
-  for( i = 0; i < pMovie->frameCnt; i++ )
592
-  {
626
+  for (i = 0; i < pMovie->frameCnt; i++) {
593 627
     strs[i] = BlinkenFrameToString(pMovie->ppFrames[i]);
594
-    if( strs[i] == NULL )
595
-    {
628
+    if (strs[i] == NULL) {
596 629
       for (i--; i >= 0; i--)
597 630
         free(strs[i]);
598 631
       free(strs);
... ...
@@ -602,13 +635,13 @@ char * BlinkenMovieToString( stBlinkenMovie * pMovie )
602 635
 
603 636
   size = 128;
604 637
   for (i = 0; i < pMovie->infoCnt; i++)
605
-    size += strlen( pMovie->pppInfos[i][0] ) + strlen( pMovie->pppInfos[i][1] ) + 8;
638
+    size +=
639
+        strlen(pMovie->pppInfos[i][0]) + strlen(pMovie->pppInfos[i][1]) + 8;
606 640
   for (i = 0; i < pMovie->frameCnt; i++)
607 641
     size += strlen(strs[i]) + 32;
608 642
 
609 643
   str = (char *)malloc(size);
610
-  if( str == NULL )
611
-  {
644
+  if (str == NULL) {
612 645
     for (i = 0; i < pMovie->frameCnt; i++)
613 646
       free(strs[i]);
614 647
     free(strs);
... ...
@@ -617,17 +650,16 @@ char * BlinkenMovieToString( stBlinkenMovie * pMovie )
617 650
 
618 651
   ptr = str;
619 652
 
620
-  sprintf( ptr, "BlinkenMovie %ux%u-%u/%u\n", pMovie->width, pMovie->height, pMovie->channels, pMovie->maxval + 1 );
653
+  sprintf(ptr, "BlinkenMovie %ux%u-%u/%u\n", pMovie->width, pMovie->height,
654
+          pMovie->channels, pMovie->maxval + 1);
621 655
   ptr += strlen(ptr);
622 656
 
623
-  for( i = 0; i < pMovie->infoCnt; i++ )
624
-  {
657
+  for (i = 0; i < pMovie->infoCnt; i++) {
625 658
     sprintf(ptr, "%s = %s\n", pMovie->pppInfos[i][0], pMovie->pppInfos[i][1]);
626 659
     ptr += strlen(ptr);
627 660
   }
628 661
 
629
-  for( i = 0; i < pMovie->frameCnt; i++ )
630
-  {
662
+  for (i = 0; i < pMovie->frameCnt; i++) {
631 663
     sprintf(ptr, "frame %u\n%s", i, strs[i]);
632 664
     ptr += strlen(ptr);
633 665
     free(strs[i]);
... ...
@@ -654,16 +686,13 @@ stBlinkenMovie * BlinkenMovieLoadBlm( char * pFilename )
654 686
     return NULL;
655 687
 
656 688
   // read magic and size
657
-  if( fscanf( pFile, " # BlinkenLights Movie %ux%u", &width, &height ) != 2 )
658
-  {
689
+  if (fscanf(pFile, " # BlinkenLights Movie %ux%u", &width, &height) != 2) {
659 690
     fclose(pFile);
660 691
     return NULL;
661 692
   }
662
-
663 693
   // allocate a new movie
664 694
   pMovie = BlinkenMovieNew(height, width, 1, 1);
665
-  if( pMovie == NULL )
666
-  {
695
+  if (pMovie == NULL) {
667 696
     fclose(pFile);
668 697
     return NULL;
669 698
   }
... ...
@@ -673,42 +701,36 @@ stBlinkenMovie * BlinkenMovieLoadBlm( char * pFilename )
673 701
   y = 0;
674 702
 
675 703
   // read frames
676
-  while( ! feof( pFile ) )
677
-  {
704
+  while (!feof(pFile)) {
678 705
     // skip rest of previous line (including newline)
679 706
     while ((chr = fgetc(pFile)) != '\n' && chr != EOF) ;
680 707
 
681 708
     // info line
682
-    if( fscanf( pFile, " # %255[A-Za-z0-9] %*[=:] %1023[^\n]", infoType, infoData ) == 2 )
683
-    {
709
+    if (fscanf
710
+        (pFile, " # %255[A-Za-z0-9] %*[=:] %1023[^\n]", infoType,
711
+         infoData) == 2) {
684 712
       BlinkenMovieAppendInfo(pMovie, infoType, infoData);
685 713
     }
686
-
687 714
     // start of frame
688
-    else if( fscanf( pFile, " @ %u", &duration ) == 1 )
689
-    {
715
+    else if (fscanf(pFile, " @ %u", &duration) == 1) {
690 716
       // create new frame and append it to movie
691 717
       pFrame = BlinkenFrameNew(height, width, 1, 1, duration);
692
-      if( pFrame != NULL )
693
-      {
718
+      if (pFrame != NULL) {
694 719
         BlinkenFrameClear(pFrame);
695
-        if( BlinkenMovieAppendFrame( pMovie, pFrame ) != 0 )
696
-        {
720
+        if (BlinkenMovieAppendFrame(pMovie, pFrame) != 0) {
697 721
           BlinkenFrameFree(pFrame);
698 722
           pFrame = NULL;
699 723
         }
700 724
         y = 0;
701 725
       }
702 726
     }
703
-
704 727
     // data line
705
-    else if( fscanf( pFile, "%1[01]", pixel ) == 1 )
706
-    {
707
-      if( pFrame != NULL )
708
-      {
709
-        for( x = 0; ; x++ )
710
-        {
711
-          BlinkenFrameSetPixel( pFrame, y, x, 0, (unsigned char)(pixel[0] == '1' ? 1 : 0) ); //set pixel
728
+    else if (fscanf(pFile, "%1[01]", pixel) == 1) {
729
+      if (pFrame != NULL) {
730
+        for (x = 0;; x++) {
731
+          BlinkenFrameSetPixel(pFrame, y, x, 0, (unsigned char)(pixel[0] == '1' ? 1 : 0));      // set 
732
+                                                                                                // 
733
+          // pixel
712 734
           if (fscanf(pFile, "%1[01]", pixel) != 1)      // read next pixel
713 735
             break;
714 736
         }
... ...
@@ -741,16 +763,13 @@ stBlinkenMovie * BlinkenMovieLoadBmm( char * pFilename )
741 763
     return NULL;
742 764
 
743 765
   // read magic and size
744
-  if( fscanf( pFile, " # BlinkenMini Movie %ux%u", &width, &height ) != 2 )
745
-  {
766
+  if (fscanf(pFile, " # BlinkenMini Movie %ux%u", &width, &height) != 2) {
746 767
     fclose(pFile);
747 768
     return NULL;
748 769
   }
749
-
750 770
   // allocate a new movie
751 771
   pMovie = BlinkenMovieNew(height, width, 1, 255);
752
-  if( pMovie == NULL )
753
-  {
772
+  if (pMovie == NULL) {
754 773
     fclose(pFile);
755 774
     return NULL;
756 775
   }
... ...
@@ -760,46 +778,41 @@ stBlinkenMovie * BlinkenMovieLoadBmm( char * pFilename )
760 778
   y = 0;
761 779
 
762 780
   // read frames
763
-  while( ! feof( pFile ) )
764
-  {
781
+  while (!feof(pFile)) {
765 782
     // skip rest of previous line (including newline)
766 783
     while ((chr = fgetc(pFile)) != '\n' && chr != EOF) ;
767 784
 
768 785
     // info line
769
-    if( fscanf( pFile, " # %255[A-Za-z0-9] %*[=:] %1023[^\n]", infoType, infoData ) == 2 )
770
-    {
786
+    if (fscanf
787
+        (pFile, " # %255[A-Za-z0-9] %*[=:] %1023[^\n]", infoType,
788
+         infoData) == 2) {
771 789
       BlinkenMovieAppendInfo(pMovie, infoType, infoData);
772 790
     }
773
-
774 791
     // start of frame
775
-    else if( fscanf( pFile, " @ %u", &duration ) == 1 )
776
-    {
792
+    else if (fscanf(pFile, " @ %u", &duration) == 1) {
777 793
       // create new frame and append it to movie
778 794
       pFrame = BlinkenFrameNew(height, width, 1, 255, duration);
779
-      if( pFrame != NULL )
780
-      {
795
+      if (pFrame != NULL) {
781 796
         BlinkenFrameClear(pFrame);
782
-        if( BlinkenMovieAppendFrame( pMovie, pFrame ) != 0 )
783
-        {
797
+        if (BlinkenMovieAppendFrame(pMovie, pFrame) != 0) {
784 798
           BlinkenFrameFree(pFrame);
785 799
           pFrame = NULL;
786 800
         }
787 801
         y = 0;
788 802
       }
789 803
     }
790
-
791 804
     // data line
792
-    else if( fscanf( pFile, "%7[0-9A-FXa-fx]", pixel ) == 1 )
793
-    {
794
-      if( pFrame != NULL )
795
-      {
796
-        for( x = 0; ; x++ )
797
-        {
805
+    else if (fscanf(pFile, "%7[0-9A-FXa-fx]", pixel) == 1) {
806
+      if (pFrame != NULL) {
807
+        for (x = 0;; x++) {
798 808
           if (sscanf(pixel, "%i", &val) != 1)   // convert pixel to number
799 809
             break;
800
-          BlinkenFrameSetPixel( pFrame, y, x, 0, (unsigned char)val ); //set pixel
810
+          BlinkenFrameSetPixel(pFrame, y, x, 0, (unsigned char)val);    // set 
811
+                                                                        // 
812
+          // pixel
801 813
           fscanf(pFile, "%*[ \t]");     // kill space
802
-          if( fscanf( pFile, "%7[0-9A-FXa-fx]", pixel ) != 1 ) //read next pixel
814
+          if (fscanf(pFile, "%7[0-9A-FXa-fx]", pixel) != 1)     // read next
815
+            // pixel
803 816
             break;
804 817
         }
805 818
         y++;    // next row
... ...
@@ -820,7 +833,8 @@ stBlinkenMovie * BlinkenMovieLoadBml( char * pFilename )
820 833
   stBlinkenMovie *pMovie;
821 834
   stBlinkenFrame *pFrame;
822 835
   int width, height, channels, bits, maxval, chrs, y, x, c, duration, val;
823
-  char buffer[2048], infoType[256], infoData[1024], pixelFormat[16], pixel[8], * ptr, chr;
836
+  char buffer[2048], infoType[256], infoData[1024], pixelFormat[16], pixel[8],
837
+      *ptr, chr;
824 838
 
825 839
   if (pFilename == NULL)
826 840
     return NULL;
... ...
@@ -839,8 +853,7 @@ stBlinkenMovie * BlinkenMovieLoadBml( char * pFilename )
839 853
 
840 854
   // read tags
841 855
   maxval = 0;
842
-  while( ! feof( pFile ) )
843
-  {
856
+  while (!feof(pFile)) {
844 857
 
845 858
     // skip to just before beginning of next tag
846 859
     fscanf(pFile, "%*[^<]");
... ...
@@ -850,12 +863,10 @@ stBlinkenMovie * BlinkenMovieLoadBml( char * pFilename )
850 863
       break;
851 864
 
852 865
     // no blm tag yet
853
-    if( pMovie == NULL )
854
-    {
866
+    if (pMovie == NULL) {
855 867
 
856 868
       // blm tag
857
-      if( fscanf( pFile, "blm%2047[^>]", buffer ) == 1 )
858
-      {
869
+      if (fscanf(pFile, "blm%2047[^>]", buffer) == 1) {
859 870
         // get attributes
860 871
         width = 0;
861 872
         height = 0;
... ...
@@ -874,8 +885,7 @@ stBlinkenMovie * BlinkenMovieLoadBml( char * pFilename )
874 885
 
875 886
         // allocate a new movie
876 887
         pMovie = BlinkenMovieNew(height, width, channels, maxval);
877
-        if( pMovie == NULL )
878
-        {
888
+        if (pMovie == NULL) {
879 889
           fclose(pFile);
880 890
           return NULL;
881 891
         }
... ...
@@ -883,7 +892,17 @@ stBlinkenMovie * BlinkenMovieLoadBml( char * pFilename )
883 892
         // get number of characters per channel
884 893
         chrs = (bits + 3) >> 2;
885 894
         // get fscanf formart string for reading a pixel
886
-        sprintf( pixelFormat, "%%%d[0-9A-Fa-f]", chrs > 4 ? 5 : chrs ); //read max 5 chars (2 already in use by prefix)
895
+        sprintf(pixelFormat, "%%%d[0-9A-Fa-f]", chrs > 4 ? 5 : chrs);   // read 
896
+                                                                        // 
897
+        // max 
898
+        // 5
899
+        // chars 
900
+        // (2 
901
+        // already 
902
+        // in 
903
+        // use 
904
+        // by 
905
+        // prefix)
887 906
         // initialize pixel buffer with hex prefix
888 907
         strcpy(pixel, "0x");
889 908
       }
... ...
@@ -895,92 +914,72 @@ stBlinkenMovie * BlinkenMovieLoadBml( char * pFilename )
895 914
     {
896 915
 
897 916
       // title tag
898
-      if( fscanf( pFile, "title>%2047[^<]", buffer ) == 1 )
899
-      {
917
+      if (fscanf(pFile, "title>%2047[^<]", buffer) == 1) {
900 918
         // add info to movie
901 919
         BlinkenMovieAppendInfo(pMovie, "title", buffer);
902 920
       }
903
-
904 921
       // description tag
905
-      else if( fscanf( pFile, "description>%2047[^<]", buffer ) == 1 )
906
-      {
922
+      else if (fscanf(pFile, "description>%2047[^<]", buffer) == 1) {
907 923
         // check if generic info
908
-        if( sscanf( buffer, "%255[A-Za-z0-9] %*[=:] %1023[^\n]", infoType, infoData ) == 2 )
924
+        if (sscanf
925
+            (buffer, "%255[A-Za-z0-9] %*[=:] %1023[^\n]", infoType,
926
+             infoData) == 2)
909 927
           // add info to movie
910 928
           BlinkenMovieAppendInfo(pMovie, infoType, infoData);
911 929
         else
912 930
           // add info to movie
913 931
           BlinkenMovieAppendInfo(pMovie, "description", buffer);
914 932
       }
915
-
916 933
       // creator tag
917
-      else if( fscanf( pFile, "creator>%2047[^<]", buffer ) == 1 )
918
-      {
934
+      else if (fscanf(pFile, "creator>%2047[^<]", buffer) == 1) {
919 935
         // add info to movie
920 936
         BlinkenMovieAppendInfo(pMovie, "creator", buffer);
921 937
       }
922
-
923 938
       // author tag
924
-      else if( fscanf( pFile, "author>%2047[^<]", buffer ) == 1 )
925
-      {
939
+      else if (fscanf(pFile, "author>%2047[^<]", buffer) == 1) {
926 940
         // add info to movie
927 941
         BlinkenMovieAppendInfo(pMovie, "author", buffer);
928 942
       }
929
-
930 943
       // email tag
931
-      else if( fscanf( pFile, "email>%2047[^<]", buffer ) == 1 )
932
-      {
944
+      else if (fscanf(pFile, "email>%2047[^<]", buffer) == 1) {
933 945
         // add info to movie
934 946
         BlinkenMovieAppendInfo(pMovie, "email", buffer);
935 947
       }
936
-
937 948
       // url tag
938
-      else if( fscanf( pFile, "url>%2047[^<]", buffer ) == 1 )
939
-      {
949
+      else if (fscanf(pFile, "url>%2047[^<]", buffer) == 1) {
940 950
         // add info to movie
941 951
         BlinkenMovieAppendInfo(pMovie, "url", buffer);
942 952
       }
943
-
944 953
       // frame tag
945
-      else if( fscanf( pFile, "frame%2047[^>]", buffer ) == 1 )
946
-      {
954
+      else if (fscanf(pFile, "frame%2047[^>]", buffer) == 1) {
947 955
         // get attributes
948 956
         duration = 0;
949 957
         if ((ptr = strstr(buffer, "duration=\"")) != NULL)      // duration
950 958
           sscanf(ptr + 10, "%u", &duration);
951 959
         // create new frame and append it to movie
952 960
         pFrame = BlinkenFrameNew(height, width, channels, maxval, duration);
953
-        if( pFrame != NULL )
954
-        {
961
+        if (pFrame != NULL) {
955 962
           BlinkenFrameClear(pFrame);
956
-          if( BlinkenMovieAppendFrame( pMovie, pFrame ) != 0 )
957
-          {
963
+          if (BlinkenMovieAppendFrame(pMovie, pFrame) != 0) {
958 964
             BlinkenFrameFree(pFrame);
959 965
             pFrame = NULL;
960 966
           }
961 967
           y = 0;
962 968
         }
963 969
       }
964
-
965 970
       // row tag
966
-      else if( fscanf( pFile, "row%c", &chr ) == 1 && chr == '>' )
967
-      {
968
-        if( pFrame != NULL )
969
-        {
971
+      else if (fscanf(pFile, "row%c", &chr) == 1 && chr == '>') {
972
+        if (pFrame != NULL) {
970 973
           // parse row
971
-          for( x = 0; x < width; x++ )
972
-          {
973
-            for( c = 0; c < channels; c++ )
974
-            {
974
+          for (x = 0; x < width; x++) {
975
+            for (c = 0; c < channels; c++) {
975 976
               // read next pixel (one channel of pixel)
976
-              if( fscanf( pFile, pixelFormat, pixel+2 ) != 1 )
977
-              {
977
+              if (fscanf(pFile, pixelFormat, pixel + 2) != 1) {
978 978
                 x = width;      // also terminate x loop
979 979
                 break;
980 980
               }
981 981
               // convert pixel (one channel of pixel) to number
982
-              if( sscanf( pixel, "%i", &val ) != 1 )
983
-              {
982
+              if (sscanf(pixel, "%i", &val) != 1) {
984 983
                 x = width;      // also terminate x loop
985 984
                 break;
986 985
               }
... ...
@@ -1025,70 +1024,75 @@ stBlinkenMovie * BlinkenMovieLoadBbm( char * pFilename )
1025 1024
     return NULL;
1026 1025
 
1027 1026
   // read header
1028
-  if( fread( header, 1, 24, pFile ) != 24 )
1029
-  {
1027
+  if (fread(header, 1, 24, pFile) != 24) {
1030 1028
     fclose(pFile);
1031 1029
     return NULL;
1032 1030
   }
1033
-  headerMagic = (unsigned long)header[0] << 24 | (unsigned long)header[1] << 16 | (unsigned long)header[2] << 8 | (unsigned long)header[3];
1031
+  headerMagic =
1032
+      (unsigned long)header[0] << 24 | (unsigned long)header[1] << 16 |
1033
+      (unsigned long)header[2] << 8 | (unsigned long)header[3];
1034 1034
   headerHeight = (unsigned short)header[4] << 8 | (unsigned short)header[5];
1035 1035
   headerWidth = (unsigned short)header[6] << 8 | (unsigned short)header[7];
1036 1036
   headerChannels = (unsigned short)header[8] << 8 | (unsigned short)header[9];
1037 1037
   headerMaxval = (unsigned short)header[10] << 8 | (unsigned short)header[11];
1038
-  headerFrameCnt = (unsigned long)header[12] << 24 | (unsigned long)header[13] << 16 | (unsigned long)header[14] << 8 | (unsigned long)header[15];
1039
-  headerDuration = (unsigned long)header[16] << 24 | (unsigned long)header[17] << 16 | (unsigned long)header[18] << 8 | (unsigned long)header[19];
1040
-  headerFramePtr = (unsigned long)header[20] << 24 | (unsigned long)header[21] << 16 | (unsigned long)header[22] << 8 | (unsigned long)header[23];
1038
+  headerFrameCnt =
1039
+      (unsigned long)header[12] << 24 | (unsigned long)header[13] << 16 |
1040
+      (unsigned long)header[14] << 8 | (unsigned long)header[15];
1041
+  headerDuration =
1042
+      (unsigned long)header[16] << 24 | (unsigned long)header[17] << 16 |
1043
+      (unsigned long)header[18] << 8 | (unsigned long)header[19];
1044
+  headerFramePtr =
1045
+      (unsigned long)header[20] << 24 | (unsigned long)header[21] << 16 |
1046
+      (unsigned long)header[22] << 8 | (unsigned long)header[23];
1041 1047
   // check magic
1042
-  if( headerMagic != 0x23542666 )
1043
-  {
1048
+  if (headerMagic != 0x23542666) {
1044 1049
     fclose(pFile);
1045 1050
     return NULL;
1046 1051
   }
1047
-
1048 1052
   // allocate a new movie
1049
-  pMovie = BlinkenMovieNew( headerHeight, headerWidth, headerChannels, headerMaxval );
1050
-  if( pMovie == NULL )
1051
-  {
1053
+  pMovie =
1054
+      BlinkenMovieNew(headerHeight, headerWidth, headerChannels,
1055
+                      headerMaxval);
1056
+  if (pMovie == NULL) {
1052 1057
     fclose(pFile);
1053 1058
     return NULL;
1054 1059
   }
1055
-
1056 1060
   // read subheaders
1057
-  while( ftell( pFile ) + 6 <= (long)headerFramePtr )
1058
-  {
1059
-    if( fread( subHeader, 1, 6, pFile ) != 6 )
1060
-    {
1061
+  while (ftell(pFile) + 6 <= (long)headerFramePtr) {
1062
+    if (fread(subHeader, 1, 6, pFile) != 6) {
1061 1063
       BlinkenMovieFree(pMovie);
1062 1064
       fclose(pFile);
1063 1065
       return NULL;
1064 1066
     }
1065
-    subHeaderMagic = (unsigned long)subHeader[0] << 24 | (unsigned long)subHeader[1] << 16 | (unsigned long)subHeader[2] << 8 | (unsigned long)subHeader[3];
1066
-    subHeaderSize = (unsigned short)subHeader[4] << 8 | (unsigned short)subHeader[5];
1067
+    subHeaderMagic =
1068
+        (unsigned long)subHeader[0] << 24 | (unsigned long)subHeader[1] << 16
1069
+        | (unsigned long)subHeader[2] << 8 | (unsigned long)subHeader[3];
1070
+    subHeaderSize =
1071
+        (unsigned short)subHeader[4] << 8 | (unsigned short)subHeader[5];
1067 1072
 
1068 1073
     // header fits into gap to frame start
1069
-    if( subHeaderSize >= 6 && ftell( pFile ) + subHeaderSize - 6 <= (long)headerFramePtr )
1070
-    {
1074
+    if (subHeaderSize >= 6
1075
+        && ftell(pFile) + subHeaderSize - 6 <= (long)headerFramePtr) {
1071 1076
       // info header
1072 1077
       if (subHeaderMagic == 0x696E666F) // 'i' 'n' 'f' 'o'
1073 1078
       {
1074 1079
         // read rest of info header
1075 1080
         pInfoHeader = (char *)malloc(subHeaderSize - 6);
1076
-        if( pInfoHeader == NULL )
1077
-        {
1081
+        if (pInfoHeader == NULL) {
1078 1082
           BlinkenMovieFree(pMovie);
1079 1083
           fclose(pFile);
1080 1084
           return NULL;
1081 1085
         }
1082
-        if( fread( pInfoHeader, 1, subHeaderSize - 6, pFile ) != (unsigned short)(subHeaderSize - 6) )
1083
-        {
1086
+        if (fread(pInfoHeader, 1, subHeaderSize - 6, pFile) !=
1087
+            (unsigned short)(subHeaderSize - 6)) {
1084 1088
           free(pInfoHeader);
1085 1089
           BlinkenMovieFree(pMovie);
1086 1090
           fclose(pFile);
1087 1091
           return NULL;
1088 1092
         }
1089 1093
         // parse information
1090
-        if( (pInfoHeaderX = memchr( pInfoHeader, 0, subHeaderSize - 6 )) != NULL )
1091
-        {
1094
+        if ((pInfoHeaderX =
1095
+             memchr(pInfoHeader, 0, subHeaderSize - 6)) != NULL) {
1092 1096
           pInfoHeaderX++;
1093 1097
           len = pInfoHeaderX - pInfoHeader;
1094 1098
           if (memchr(pInfoHeaderX, 0, subHeaderSize - 6 - len) != NULL)
... ...
@@ -1109,13 +1112,15 @@ stBlinkenMovie * BlinkenMovieLoadBbm( char * pFilename )
1109 1112
   fseek(pFile, headerFramePtr, SEEK_SET);
1110 1113
 
1111 1114
   // read frame start marker
1112
-  if( fread( frameStartMarker, 1, 4, pFile ) != 4 )
1113
-  {
1115
+  if (fread(frameStartMarker, 1, 4, pFile) != 4) {
1114 1116
     BlinkenMovieFree(pMovie);
1115 1117
     fclose(pFile);
1116 1118
     return NULL;
1117 1119
   }
1118
-  frameStartMarkerMagic = (unsigned long)frameStartMarker[0] << 24 | (unsigned long)frameStartMarker[1] << 16 | (unsigned long)frameStartMarker[2] << 8 | (unsigned long)frameStartMarker[3];
1120
+  frameStartMarkerMagic =
1121
+      (unsigned long)frameStartMarker[0] << 24 | (unsigned long)
1122
+      frameStartMarker[1] << 16 | (unsigned long)frameStartMarker[2] << 8 |
1123
+      (unsigned long)frameStartMarker[3];
1119 1124
   if (frameStartMarkerMagic != 0x66726D73)      // 'f' 'r' 'm' 's'
1120 1125
   {
1121 1126
     BlinkenMovieFree(pMovie);
... ...
@@ -1126,22 +1130,22 @@ stBlinkenMovie * BlinkenMovieLoadBbm( char * pFilename )
1126 1130
   // allocate buffer for frame data
1127 1131
   len = 2 + headerHeight * headerWidth * headerChannels;
1128 1132
   pFrameData = (unsigned char *)malloc(len);
1129
-  if( pFrameData == NULL )
1130
-  {
1133
+  if (pFrameData == NULL) {
1131 1134
     BlinkenMovieFree(pMovie);
1132 1135
     fclose(pFile);
1133 1136
     return NULL;
1134 1137
   }
1135
-
1136 1138
   // read frames
1137
-  for( ; ; )
1138
-  {
1139
+  for (;;) {
1139 1140
     // read frame
1140 1141
     if (fread(pFrameData, 1, len, pFile) != (unsigned int)len)
1141 1142
       break;
1142
-    duration = (unsigned short)pFrameData[0] << 8 | (unsigned short)pFrameData[1];
1143
+    duration =
1144
+        (unsigned short)pFrameData[0] << 8 | (unsigned short)pFrameData[1];
1143 1145
     // build frame and append it to movie
1144
-    pFrame = BlinkenFrameNew( headerHeight, headerWidth, headerChannels, headerMaxval, duration );
1146
+    pFrame =
1147
+        BlinkenFrameNew(headerHeight, headerWidth, headerChannels,
1148
+                        headerMaxval, duration);
1145 1149
     if (pFrame == NULL)
1146 1150
       break;
1147 1151
     i = 2;
... ...
@@ -1149,8 +1153,7 @@ stBlinkenMovie * BlinkenMovieLoadBbm( char * pFilename )
1149 1153
       for (x = 0; x < headerWidth; x++)
1150 1154
         for (c = 0; c < headerChannels; c++, i++)
1151 1155
           BlinkenFrameSetPixel(pFrame, y, x, c, pFrameData[i]);
1152
-    if( BlinkenMovieAppendFrame( pMovie, pFrame ) != 0 )
1153
-    {
1156
+    if (BlinkenMovieAppendFrame(pMovie, pFrame) != 0) {
1154 1157
       BlinkenFrameFree(pFrame);
1155 1158
       pFrame = NULL;
1156 1159
     }
... ...
@@ -1215,27 +1218,25 @@ int BlinkenMovieSaveBlm( stBlinkenMovie * pMovie, char * pFilename )
1215 1218
 
1216 1219
   // open file
1217 1220
   pFile = fopen(pFilename, "wt");
1218
-  if( pFile == NULL )
1219
-  {
1221
+  if (pFile == NULL) {
1220 1222
     BlinkenMovieFree(pOutMovie);
1221 1223
     return -1;
1222 1224
   }
1223
-
1224 1225
   // write header line
1225
-  fprintf( pFile, "# BlinkenLights Movie %ux%u\n", pOutMovie->width, pOutMovie->height );
1226
+  fprintf(pFile, "# BlinkenLights Movie %ux%u\n", pOutMovie->width,
1227
+          pOutMovie->height);
1226 1228
 
1227 1229
   // write information lines
1228 1230
   for (i = 0; i < pOutMovie->infoCnt; i++)
1229
-    fprintf( pFile, "# %s = %s\n", pOutMovie->pppInfos[i][0], pOutMovie->pppInfos[i][1] );
1231
+    fprintf(pFile, "# %s = %s\n", pOutMovie->pppInfos[i][0],
1232
+            pOutMovie->pppInfos[i][1]);
1230 1233
 
1231 1234
   // write frames
1232
-  for( i = 0; i < pOutMovie->frameCnt; i++ )
1233
-  {
1234
-    fprintf( pFile, "\n@%u\n", BlinkenFrameGetDuration( pOutMovie->ppFrames[i] ) );
1235
-    for( y = 0; y < pOutMovie->height; y++ )
1236
-    {
1237
-      for( x = 0; x < pOutMovie->width; x++ )
1238
-      {
1235
+  for (i = 0; i < pOutMovie->frameCnt; i++) {
1236
+    fprintf(pFile, "\n@%u\n",
1237
+            BlinkenFrameGetDuration(pOutMovie->ppFrames[i]));
1238
+    for (y = 0; y < pOutMovie->height; y++) {
1239
+      for (x = 0; x < pOutMovie->width; x++) {
1239 1240
         if (BlinkenFrameGetPixel(pOutMovie->ppFrames[i], y, x, 0) != 0)
1240 1241
           fprintf(pFile, "1");
1241 1242
         else
... ...
@@ -1272,28 +1273,29 @@ int BlinkenMovieSaveBmm( stBlinkenMovie * pMovie, char * pFilename )
1272 1273
 
1273 1274
   // open file
1274 1275
   pFile = fopen(pFilename, "wt");
1275
-  if( pFile == NULL )
1276
-  {
1276
+  if (pFile == NULL) {
1277 1277
     BlinkenMovieFree(pOutMovie);
1278 1278
     return -1;
1279 1279
   }
1280
-
1281 1280
   // write header line
1282
-  fprintf( pFile, "# BlinkenMini Movie %ux%u\n", pOutMovie->width, pOutMovie->height );
1281
+  fprintf(pFile, "# BlinkenMini Movie %ux%u\n", pOutMovie->width,
1282
+          pOutMovie->height);
1283 1283
 
1284 1284
   // write information lines
1285 1285
   for (i = 0; i < pOutMovie->infoCnt; i++)
1286
-    fprintf( pFile, "# %s = %s\n", pOutMovie->pppInfos[i][0], pOutMovie->pppInfos[i][1] );
1286
+    fprintf(pFile, "# %s = %s\n", pOutMovie->pppInfos[i][0],
1287
+            pOutMovie->pppInfos[i][1]);
1287 1288
 
1288 1289
   // write frames
1289
-  for( i = 0; i < pOutMovie->frameCnt; i++ )
1290
-  {
1291
-    fprintf( pFile, "\n@%u\n", BlinkenFrameGetDuration( pOutMovie->ppFrames[i] ) );
1292
-    for( y = 0; y < pOutMovie->height; y++ )
1293
-    {
1294
-      fprintf( pFile, "0x%02X", BlinkenFrameGetPixel( pOutMovie->ppFrames[i], y, 0, 0 ) );
1290
+  for (i = 0; i < pOutMovie->frameCnt; i++) {
1291
+    fprintf(pFile, "\n@%u\n",
1292
+            BlinkenFrameGetDuration(pOutMovie->ppFrames[i]));
1293
+    for (y = 0; y < pOutMovie->height; y++) {
1294
+      fprintf(pFile, "0x%02X",
1295
+              BlinkenFrameGetPixel(pOutMovie->ppFrames[i], y, 0, 0));
1295 1296
       for (x = 1; x < pOutMovie->width; x++)
1296
-        fprintf( pFile, " 0x%02X", BlinkenFrameGetPixel( pOutMovie->ppFrames[i], y, x, 0 ) );
1297
+        fprintf(pFile, " 0x%02X",
1298
+                BlinkenFrameGetPixel(pOutMovie->ppFrames[i], y, x, 0));
1297 1299
       fprintf(pFile, "\n");
1298 1300
     }
1299 1301
   }
... ...
@@ -1323,12 +1325,12 @@ int BlinkenMovieSaveBml( stBlinkenMovie * pMovie, char * pFilename )
1323 1325
     return -1;
1324 1326
   val = pOutMovie->maxval;      // get number of bits
1325 1327
   for (bits = 0; val != 0; val >>= 1, bits++) ;
1326
-  BlinkenMovieResize( pOutMovie, pOutMovie->height, pOutMovie->width, pOutMovie->channels, (1 << bits) - 1 );
1328
+  BlinkenMovieResize(pOutMovie, pOutMovie->height, pOutMovie->width,
1329
+                     pOutMovie->channels, (1 << bits) - 1);
1327 1330
 
1328 1331
   // open file
1329 1332
   pFile = fopen(pFilename, "wt");
1330
-  if( pFile == NULL )
1331
-  {
1333
+  if (pFile == NULL) {
1332 1334
     BlinkenMovieFree(pOutMovie);
1333 1335
     return -1;
1334 1336
   }
... ...
@@ -1337,19 +1338,21 @@ int BlinkenMovieSaveBml( stBlinkenMovie * pMovie, char * pFilename )
1337 1338
   fprintf(pFile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1338 1339
 
1339 1340
   // write blm start tag
1340
-  fprintf( pFile, "<blm width=\"%u\" height=\"%u\" bits=\"%u\" channels=\"%u\">\n",
1341
+  fprintf(pFile,
1342
+          "<blm width=\"%u\" height=\"%u\" bits=\"%u\" channels=\"%u\">\n",
1341 1343
           pOutMovie->width, pOutMovie->height, bits, pOutMovie->channels);
1342 1344
 
1343 1345
   // write information lines
1344 1346
   fprintf(pFile, "\t<header>\n");
1345
-  for( i = 0; i < pOutMovie->infoCnt; i++ )
1346
-  {
1347
+  for (i = 0; i < pOutMovie->infoCnt; i++) {
1347 1348
     if (strcmp(pOutMovie->pppInfos[i][0], "title") == 0)
1348 1349
       fprintf(pFile, "\t\t<title>%s</title>\n", pOutMovie->pppInfos[i][1]);
1349 1350
     else if (strcmp(pOutMovie->pppInfos[i][0], "description") == 0)
1350
-      fprintf( pFile, "\t\t<description>%s</description>\n", pOutMovie->pppInfos[i][1] );
1351
+      fprintf(pFile, "\t\t<description>%s</description>\n",
1352
+              pOutMovie->pppInfos[i][1]);
1351 1353
     else if (strcmp(pOutMovie->pppInfos[i][0], "creator") == 0)
1352
-      fprintf( pFile, "\t\t<creator>%s</creator>\n", pOutMovie->pppInfos[i][1] );
1354
+      fprintf(pFile, "\t\t<creator>%s</creator>\n",
1355
+              pOutMovie->pppInfos[i][1]);
1353 1356
     else if (strcmp(pOutMovie->pppInfos[i][0], "author") == 0)
1354 1357
       fprintf(pFile, "\t\t<author>%s</author>\n", pOutMovie->pppInfos[i][1]);
1355 1358
     else if (strcmp(pOutMovie->pppInfos[i][0], "email") == 0)
... ...
@@ -1357,16 +1360,16 @@ int BlinkenMovieSaveBml( stBlinkenMovie * pMovie, char * pFilename )
1357 1360
     else if (strcmp(pOutMovie->pppInfos[i][0], "url") == 0)
1358 1361
       fprintf(pFile, "\t\t<url>%s</url>\n", pOutMovie->pppInfos[i][1]);
1359 1362
     else
1360
-      fprintf( pFile, "\t\t<description>%s: %s</description>\n", pOutMovie->pppInfos[i][0], pOutMovie->pppInfos[i][1] );
1363
+      fprintf(pFile, "\t\t<description>%s: %s</description>\n",
1364
+              pOutMovie->pppInfos[i][0], pOutMovie->pppInfos[i][1]);
1361 1365
   }
1362 1366
   fprintf(pFile, "\t</header>\n");
1363 1367
 
1364 1368
   // write frames
1365
-  for( i = 0; i < pOutMovie->frameCnt; i++ )
1366
-  {
1367
-    fprintf( pFile, "\n\t<frame duration=\"%u\">\n", BlinkenFrameGetDuration( pOutMovie->ppFrames[i] ) );
1368
-    for( y = 0; y < pOutMovie->height; y++ )
1369
-    {
1369
+  for (i = 0; i < pOutMovie->frameCnt; i++) {
1370
+    fprintf(pFile, "\n\t<frame duration=\"%u\">\n",
1371
+            BlinkenFrameGetDuration(pOutMovie->ppFrames[i]));
1372
+    for (y = 0; y < pOutMovie->height; y++) {
1370 1373
       fprintf(pFile, "\t\t<row>");
1371 1374
       for (x = 0; x < pOutMovie->width; x++)
1372 1375
         for (c = 0; c < pOutMovie->channels; c++)
... ...
@@ -1394,7 +1397,8 @@ int BlinkenMovieSaveBbm( stBlinkenMovie * pMovie, char * pFilename )
1394 1397
 {
1395 1398
   unsigned char *pFrameData;
1396 1399
   FILE *pFile;
1397
-  unsigned char header[24], infoHeader[6], framePointer[4], frameStartMarker[4];
1400
+  unsigned char header[24], infoHeader[6], framePointer[4],
1401
+      frameStartMarker[4];
1398 1402
   int duration, len, len0, len1, i, j, y, x, c, val;
1399 1403
   long pos;
1400 1404
 
... ...
@@ -1402,14 +1406,16 @@ int BlinkenMovieSaveBbm( stBlinkenMovie * pMovie, char * pFilename )
1402 1406
     return -1;
1403 1407
 
1404 1408
   // allocate frame data buffer
1405
-  pFrameData = (unsigned char *)malloc( 2 + pMovie->height * pMovie->width * pMovie->channels );
1409
+  pFrameData =
1410
+      (unsigned char *)malloc(2 +
1411
+                              pMovie->height * pMovie->width *
1412
+                              pMovie->channels);
1406 1413
   if (pFrameData == NULL)
1407 1414
     return -1;
1408 1415
 
1409 1416
   // open file
1410 1417
   pFile = fopen(pFilename, "wb");
1411
-  if( pFile == NULL )
1412
-  {
1418
+  if (pFile == NULL) {
1413 1419
     free(pFrameData);
1414 1420
     return -1;
1415 1421
   }
... ...
@@ -1445,8 +1450,7 @@ int BlinkenMovieSaveBbm( stBlinkenMovie * pMovie, char * pFilename )
1445 1450
   fwrite(header, 1, 24, pFile);
1446 1451
 
1447 1452
   // write information
1448
-  for( i = 0; i < pMovie->infoCnt; i++ )
1449
-  {
1453
+  for (i = 0; i < pMovie->infoCnt; i++) {
1450 1454
     len0 = strlen(pMovie->pppInfos[i][0]);
1451 1455
     if (len0 > 32760)
1452 1456
       len0 = 32760;
... ...
@@ -1485,8 +1489,7 @@ int BlinkenMovieSaveBbm( stBlinkenMovie * pMovie, char * pFilename )
1485 1489
   fwrite(frameStartMarker, 1, 4, pFile);
1486 1490
 
1487 1491
   // write frames
1488
-  for( i = 0; i < pMovie->frameCnt; i++ )
1489
-  {
1492
+  for (i = 0; i < pMovie->frameCnt; i++) {
1490 1493
     val = BlinkenFrameGetDuration(pMovie->ppFrames[i]);
1491 1494
     pFrameData[0] = (unsigned char)(val >> 8);
1492 1495
     pFrameData[1] = (unsigned char)val;
... ...
@@ -1539,16 +1542,19 @@ int BlinkenMovieSave( stBlinkenMovie * pMovie, char * pFilename )
1539 1542
   return -1;
1540 1543
 }
1541 1544
 
1542
-void BlinkenMovieSend( stBlinkenMovie * pMovie, SOCKET udpSocket, etBlinkenProto proto, int maxidle )
1545
+void BlinkenMovieSend(stBlinkenMovie * pMovie, SOCKET udpSocket,
1546
+                      etBlinkenProto proto, int maxidle)
1543 1547
 // udp socket must be "connected"
1544
-//maxidle is the maximum idle time between two frames in ms (last frame is repeated after this time), use 0 to turn off this feature
1548
+// maxidle is the maximum idle time between two frames in ms (last frame is
1549
+// repeated after this time), use 0 to turn off this feature
1545 1550
 {
1546 1551
   int i, len, duration, dur;
1547 1552
   char buffer[65536];   // 64kB is more than maximum UDP size
1548 1553
 
1549
-  for( i = 0; i < pMovie->frameCnt; i++ )
1550
-  {
1551
-    len = BlinkenFrameToNetwork( pMovie->ppFrames[i], proto, buffer, sizeof( buffer ) );
1554
+  for (i = 0; i < pMovie->frameCnt; i++) {
1555
+    len =
1556
+        BlinkenFrameToNetwork(pMovie->ppFrames[i], proto, buffer,
1557
+                              sizeof(buffer));
1552 1558
     duration = BlinkenFrameGetDuration(pMovie->ppFrames[i]);
1553 1559
     if (len > 0) {
1554 1560
       while (duration > 0) {
... ...
@@ -1561,7 +1567,8 @@ void BlinkenMovieSend( stBlinkenMovie * pMovie, SOCKET udpSocket, etBlinkenProto
1561 1567
   }
1562 1568
 }
1563 1569
 
1564
-stBlinkenMovie * BlinkenMovieReceive( SOCKET udpSocket, int timeout, etBlinkenProto * pProto )
1570
+stBlinkenMovie *BlinkenMovieReceive(SOCKET udpSocket, int timeout,
1571
+                                    etBlinkenProto * pProto)
1565 1572
 // udp socket must be "bound" and should be "connected"
1566 1573
 // after timeout ms of no reception, the movie is considered to be complete
1567 1574
 // returns protocol in *pProto if pProto not NULL
... ...
@@ -1584,14 +1591,16 @@ stBlinkenMovie * BlinkenMovieReceive( SOCKET udpSocket, int timeout, etBlinkenPr
1584 1591
   proto = BlinkenProtoNone;
1585 1592
   pLastFrame = NULL;
1586 1593
   lastTime = get_ms();
1587
-  for( ; ; )
1588
-  {
1594
+  for (;;) {
1589 1595
     // wait for next frame
1590 1596
     FD_ZERO(&readFds);
1591 1597
     FD_SET(udpSocket, &readFds);
1592 1598
     timeo.tv_sec = timeout / 1000;
1593 1599
     timeo.tv_usec = (timeout % 1000) * 1000;
1594
-    if( select( udpSocket + 1, &readFds, NULL, NULL, &timeo ) <= 0 ) //timeout or error
1600
+    if (select(udpSocket + 1, &readFds, NULL, NULL, &timeo) <= 0)       // timeout 
1601
+                                                                        // 
1602
+      // or 
1603
+      // error
1595 1604
       break;
1596 1605
 
1597 1606
     // fetch data
... ...
@@ -1601,43 +1610,36 @@ stBlinkenMovie * BlinkenMovieReceive( SOCKET udpSocket, int timeout, etBlinkenPr
1601 1610
 
1602 1611
     // get frame from data
1603 1612
     pFrame = BlinkenFrameFromNetwork(buffer, len, &p);
1604
-    if( pFrame != NULL )
1605
-    {
1613
+    if (pFrame != NULL) {
1606 1614
       // valid protocol
1607
-      if( p != BlinkenProtoNone )
1608
-      {
1615
+      if (p != BlinkenProtoNone) {
1609 1616
         // first frame
1610 1617
         if (proto == BlinkenProtoNone)
1611 1618
           proto = p;    // use this protocol
1612 1619
         // protocol matches
1613
-        if( p == proto )
1614
-        {
1620
+        if (p == proto) {
1615 1621
           // no movie yet
1616
-          if( pMovie == NULL )
1617
-          {
1622
+          if (pMovie == NULL) {
1618 1623
             // allocate a new movie
1619 1624
             pMovie = BlinkenMovieNew(BlinkenFrameGetHeight(pFrame),
1620 1625
                                      BlinkenFrameGetWidth(pFrame),
1621 1626
                                      BlinkenFrameGetChannels(pFrame),
1622 1627
                                      BlinkenFrameGetMaxval(pFrame));
1623
-            if( pMovie == NULL )
1624
-            {
1628
+            if (pMovie == NULL) {
1625 1629
               BlinkenFrameFree(pFrame);
1626 1630
               break;
1627 1631
             }
1628 1632
           }
1629
-
1630 1633
           // ignore frame if it is equal to last one
1631 1634
           if (pMovie->frameCnt > 0) {
1632
-            if( BlinkenFrameCompare( pFrame, pMovie->ppFrames[pMovie->frameCnt - 1] ) == 0 ) {
1635
+            if (BlinkenFrameCompare
1636
+                (pFrame, pMovie->ppFrames[pMovie->frameCnt - 1]) == 0) {
1633 1637
               BlinkenFrameFree(pFrame);
1634 1638
               continue;
1635 1639
             }
1636 1640
           }
1637
-
1638 1641
           // append frame to movie
1639
-          if( BlinkenMovieAppendFrame( pMovie, pFrame ) == 0 )
1640
-          {
1642
+          if (BlinkenMovieAppendFrame(pMovie, pFrame) == 0) {
1641 1643
             // get current time
1642 1644
             curTime = get_ms();
1643 1645
             // set duration of last frame
... ...
@@ -1,8 +1,6 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #ifndef INC_BlinkenLib_BlinkenMovie
8 6
 #define INC_BlinkenLib_BlinkenMovie
... ...
@@ -19,7 +17,8 @@
19 17
 
20 18
 typedef struct sBlinkenMovie stBlinkenMovie;
21 19
 
22
-stBlinkenMovie * BlinkenMovieNew( int height, int width, int channels, int maxval );
20
+stBlinkenMovie *BlinkenMovieNew(int height, int width, int channels,
21
+                                int maxval);
23 22
 
24 23
 stBlinkenMovie *BlinkenMovieClone(stBlinkenMovie * pSrcMovie);
25 24
 
... ...
@@ -34,24 +33,33 @@ int BlinkenMovieGetDuration( stBlinkenMovie * pMovie );
34 33
 int BlinkenMovieGetInfoCnt(stBlinkenMovie * pMovie);
35 34
 char *BlinkenMovieGetInfoType(stBlinkenMovie * pMovie, int infoNo);
36 35
 char *BlinkenMovieGetInfoData(stBlinkenMovie * pMovie, int infoNo);
37
-void BlinkenMovieSetInfo( stBlinkenMovie * pMovie, int infoNo, char * pInfoType, char * pInfoData );
38
-void BlinkenMovieInsertInfo( stBlinkenMovie * pMovie, int infoNo, char * pInfoType, char * pInfoData );
39
-void BlinkenMovieAppendInfo( stBlinkenMovie * pMovie, char * pInfoType, char * pInfoData );
36
+void BlinkenMovieSetInfo(stBlinkenMovie * pMovie, int infoNo, char *pInfoType,
37
+                         char *pInfoData);
38
+void BlinkenMovieInsertInfo(stBlinkenMovie * pMovie, int infoNo,
39
+                            char *pInfoType, char *pInfoData);
40
+void BlinkenMovieAppendInfo(stBlinkenMovie * pMovie, char *pInfoType,
41
+                            char *pInfoData);
40 42
 void BlinkenMovieDeleteInfo(stBlinkenMovie * pMovie, int infoNo);
41 43
 void BlinkenMovieDeleteInfos(stBlinkenMovie * pMovie);
42 44
 
43 45
 int BlinkenMovieGetFrameCnt(stBlinkenMovie * pMovie);
44 46
 stBlinkenFrame *BlinkenMovieGetFrame(stBlinkenMovie * pMovie, int frameNo);
45
-void BlinkenMovieSetFrame( stBlinkenMovie * pMovie, int frameNo, stBlinkenFrame * pFrame );
46
-int BlinkenMovieInsertFrame( stBlinkenMovie * pMovie, int frameNo, stBlinkenFrame * pFrame );
47
+void BlinkenMovieSetFrame(stBlinkenMovie * pMovie, int frameNo,
48
+                          stBlinkenFrame * pFrame);
49
+int BlinkenMovieInsertFrame(stBlinkenMovie * pMovie, int frameNo,
50
+                            stBlinkenFrame * pFrame);
47 51
 int BlinkenMovieAppendFrame(stBlinkenMovie * pMovie, stBlinkenFrame * pFrame);
48 52
 void BlinkenMovieDeleteFrame(stBlinkenMovie * pMovie, int frameNo);
49 53
 void BlinkenMovieDeleteFrames(stBlinkenMovie * pMovie);
50 54
 
51
-int BlinkenMovieConcat( stBlinkenMovie * pMovie, stBlinkenMovie * pMovie2 /* appended and freed */ );
55
+int BlinkenMovieConcat(stBlinkenMovie * pMovie, stBlinkenMovie * pMovie2        /* appended 
56
+                                                                                   and 
57
+                                                                                   freed 
58
+                                                                                 */ );
52 59
 void BlinkenMovieReverse(stBlinkenMovie * pMovie);
53 60
 
54
-void BlinkenMovieResize( stBlinkenMovie * pMovie, int height, int width, int channels, int maxval );
61
+void BlinkenMovieResize(stBlinkenMovie * pMovie, int height, int width,
62
+                        int channels, int maxval);
55 63
 void BlinkenMovieScale(stBlinkenMovie * pMovie, int height, int width);
56 64
 void BlinkenMovieColorize(stBlinkenMovie * pMovie, int channels, int mode);
57 65
 
... ...
@@ -75,11 +83,14 @@ int BlinkenMovieSaveMng( stBlinkenMovie * pMovie, char * pFilename );
75 83
 #endif // #ifdef BLINKENLIB_CFG_MNG
76 84
 int BlinkenMovieSave(stBlinkenMovie * pMovie, char *pFilename);
77 85
 
78
-void BlinkenMovieSend( stBlinkenMovie * pMovie, SOCKET udpSocket, etBlinkenProto proto, int maxidle );
86
+void BlinkenMovieSend(stBlinkenMovie * pMovie, SOCKET udpSocket,
87
+                      etBlinkenProto proto, int maxidle);
79 88
 // udp socket must be "connected"
80
-//maxidle is the maximum idle time between two frames in ms (last frame is repeated after this time), use 0 to turn off this feature
89
+// maxidle is the maximum idle time between two frames in ms (last frame is
90
+// repeated after this time), use 0 to turn off this feature
81 91
 
82
-stBlinkenMovie * BlinkenMovieReceive( SOCKET udpSocket, int timeout, etBlinkenProto * pProto );
92
+stBlinkenMovie *BlinkenMovieReceive(SOCKET udpSocket, int timeout,
93
+                                    etBlinkenProto * pProto);
83 94
 // udp socket must be "bound" and should be "connected"
84 95
 // after timeout ms of no reception, the movie is considered to be complete
85 96
 // returns protocol in *pProto if pProto not NULL
... ...
@@ -1,10 +1,7 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- *
6
- * OS X support by Manfred Wuits <manfred@werkzeugH.at>
7
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project OS X support by Manfred Wuits
4
+   <manfred@werkzeugH.at> */
8 5
 
9 6
 #include <errno.h>
10 7
 #include <fcntl.h>
... ...
@@ -34,48 +31,63 @@ static int serial_settings_parse( char * str, int * settings, int * speed )
34 31
     return 0;
35 32
 
36 33
   // baud rate
37
-  if( baud == 300 ) sp = B300;
38
-  else if( baud == 600 ) sp = B600;
39
-  else if( baud == 1200 ) sp = B1200;
40
-  else if( baud == 2400 ) sp = B2400;
41
-  else if( baud == 4800 ) sp = B4800;
42
-  else if( baud == 9600 ) sp = B9600;
43
-  else if( baud == 19200 ) sp = B19200;
44
-  else if( baud == 38400 ) sp = B38400;
45
-  else if( baud == 57600 ) sp = B57600;
46
-  else if( baud == 115200 ) sp = B115200;
47
-  else
48
-  {
34
+  if (baud == 300)
35
+    sp = B300;
36
+  else if (baud == 600)
37
+    sp = B600;
38
+  else if (baud == 1200)
39
+    sp = B1200;
40
+  else if (baud == 2400)
41
+    sp = B2400;
42
+  else if (baud == 4800)
43
+    sp = B4800;
44
+  else if (baud == 9600)
45
+    sp = B9600;
46
+  else if (baud == 19200)
47
+    sp = B19200;
48
+  else if (baud == 38400)
49
+    sp = B38400;
50
+  else if (baud == 57600)
51
+    sp = B57600;
52
+  else if (baud == 115200)
53
+    sp = B115200;
54
+  else {
49 55
     printf("illegal baudrate: %d\n", baud);
50 56
     return 0;
51 57
   }
52 58
 
53 59
   // parity
54
-  if( parity == 'n' || parity == 'N' ) set |= 0;
55
-  else if( parity == 'e' || parity == 'E' ) set |= PARENB;
56
-  else if( parity == 'o' || parity == 'O' ) set |= PARENB | PARODD;
57
-  else
58
-  {
60
+  if (parity == 'n' || parity == 'N')
61
+    set |= 0;
62
+  else if (parity == 'e' || parity == 'E')
63
+    set |= PARENB;
64
+  else if (parity == 'o' || parity == 'O')
65
+    set |= PARENB | PARODD;
66
+  else {
59 67
     printf("invalid parity: %c\n", parity);
60 68
     return 0;
61 69
   }
62 70
 
63 71
   // data bits
64
-  if( data == 5 ) set |= CS5;
65
-  else if( data == 6 ) set |= CS6;
66
-  else if( data == 7 ) set |= CS7;
67
-  else if( data == 8 ) set |= CS8;
68
-  else
69
-  {
72
+  if (data == 5)
73
+    set |= CS5;
74
+  else if (data == 6)
75
+    set |= CS6;
76
+  else if (data == 7)
77
+    set |= CS7;
78
+  else if (data == 8)
79
+    set |= CS8;
80
+  else {
70 81
     printf("illegal number of data bits: %d\n", data);
71 82
     return 0;
72 83
   }
73 84
 
74 85
   // stop bits
75
-  if( stop == 1 ) set |= 0;
76
-  else if( stop == 2 ) set |= CSTOPB;
77
-  else
78
-  {
86
+  if (stop == 1)
87
+    set |= 0;
88
+  else if (stop == 2)
89
+    set |= CSTOPB;
90
+  else {
79 91
     printf("illegal number of stop bits: %d\n", stop);
80 92
     return 0;
81 93
   }
... ...
@@ -87,40 +99,62 @@ static int serial_settings_parse( char * str, int * settings, int * speed )
87 99
 }
88 100
 
89 101
 // convert serial settings to text
90
-static void serial_settings_to_str( int settings, char * buf, unsigned int maxlen )
102
+static void serial_settings_to_str(int settings, char *buf,
103
+                                   unsigned int maxlen)
91 104
 {
92 105
   int baud, data, stop;
93 106
   char parity;
94 107
 
95 108
   // baud rate
96
-  if( settings & B300 ) baud = 300;
97
-  else if( settings & B600 ) baud = 600;
98
-  else if( settings & B1200 ) baud = 1200;
99
-  else if( settings & B2400 ) baud = 2400;
100
-  else if( settings & B4800 ) baud = 4800;
101
-  else if( settings & B9600 ) baud = 9600;
102
-  else if( settings & B19200 ) baud = 19200;
103
-  else if( settings & B38400 ) baud = 38400;
104
-  else if( settings & B57600 ) baud = 57600;
105
-  else if( settings & B115200 ) baud = 115200;
106
-  else baud = 0;
109
+  if (settings & B300)
110
+    baud = 300;
111
+  else if (settings & B600)
112
+    baud = 600;
113
+  else if (settings & B1200)
114
+    baud = 1200;
115
+  else if (settings & B2400)
116
+    baud = 2400;
117
+  else if (settings & B4800)
118
+    baud = 4800;
119
+  else if (settings & B9600)
120
+    baud = 9600;
121
+  else if (settings & B19200)
122
+    baud = 19200;
123
+  else if (settings & B38400)
124
+    baud = 38400;
125
+  else if (settings & B57600)
126
+    baud = 57600;
127
+  else if (settings & B115200)
128
+    baud = 115200;
129
+  else
130
+    baud = 0;
107 131
 
108 132
   // parity
109 133
   if (settings & PARENB)
110
-    if( settings & PARODD) parity = 'O';
111
-    else parity = 'E';
112
-  else parity = 'N';
134
+    if (settings & PARODD)
135
+      parity = 'O';
136
+    else
137
+      parity = 'E';
138
+  else
139
+    parity = 'N';
113 140
 
114 141
   // data bits
115
-  if( settings & CS5) data = 5;
116
-  else if( settings & CS6) data = 6;
117
-  else if( settings & CS7) data = 7;
118
-  else if( settings & CS8) data = 8;
119
-  else data = 0;
142
+  if (settings & CS5)
143
+    data = 5;
144
+  else if (settings & CS6)
145
+    data = 6;
146
+  else if (settings & CS7)
147
+    data = 7;
148
+  else if (settings & CS8)
149
+    data = 8;
150
+  else
151
+    data = 0;
120 152
 
121 153
   // stop bits
122
-  if( settings & CSTOPB ) stop = 2;
123
-  else stop = 1;
154
+  if (settings & CSTOPB)
155
+    stop = 2;
156
+  else
157
+    stop = 1;
124 158
 
125 159
   snprintf(buf, maxlen, "%d,%c,%d,%d", baud, parity, data, stop);
126 160
 }
... ...
@@ -140,8 +174,7 @@ static int serial_settings_set( int fd, int settings, int speed )
140 174
   tio.c_cc[VMIN] = 0;   // return on single char read
141 175
 
142 176
 #ifdef BLINKENLIB_CFG_OSX
143
-  if( cfsetspeed( &tio, speed ) == - 1 )
144
-  {
177
+  if (cfsetspeed(&tio, speed) == -1) {
145 178
     printf("cfsetspeed: error: %s\n", strerror(errno));
146 179
     return 0;
147 180
   }
... ...
@@ -149,8 +182,7 @@ static int serial_settings_set( int fd, int settings, int speed )
149 182
   tio.c_cflag |= speed;
150 183
 #endif // #ifdef BLINKENLIB_CFG_OSX
151 184
 
152
-  if( tcsetattr( fd, TCSANOW, &tio ) == -1 )
153
-  {
185
+  if (tcsetattr(fd, TCSANOW, &tio) == -1) {
154 186
     printf("tcsetattr: error: %s\n", strerror(errno));
155 187
     return 0;
156 188
   }
... ...
@@ -166,8 +197,8 @@ static int recv_and_out( SOCKET udpSocket, int dev_fd,
166 197
                         int *p_device_output_active,
167 198
                         unsigned int format_change,
168 199
                         unsigned int format_height, unsigned int format_width,
169
-                         unsigned int format_channels, unsigned int format_colors,
170
-                         etBlinkenProto proto,
200
+                        unsigned int format_channels,
201
+                        unsigned int format_colors, etBlinkenProto proto,
171 202
                         int use_msecs, unsigned int msecs)
172 203
 {
173 204
   fd_set readFds, errFds;
... ...
@@ -177,8 +208,7 @@ static int recv_and_out( SOCKET udpSocket, int dev_fd,
177 208
   struct timeval start, timeout, *p_timeout, end;
178 209
 
179 210
   dev_eof = 0;
180
-  for( ; ; )
181
-  {
211
+  for (;;) {
182 212
     // wait for next frame
183 213
     FD_ZERO(&readFds);
184 214
     FD_SET(udpSocket, &readFds);
... ...
@@ -199,35 +229,28 @@ static int recv_and_out( SOCKET udpSocket, int dev_fd,
199 229
       timeout.tv_sec = msecs / 1000;
200 230
       timeout.tv_usec = msecs % 1000 * 1000;
201 231
       p_timeout = &timeout;
202
-    }
203
-    else
232
+    } else
204 233
       p_timeout = NULL;
205 234
     if (select(maxFd + 1, &readFds, NULL, &errFds, p_timeout) < 0)      // error
206 235
     {
207 236
       printf("error during select: %s\n", strerror(errno));
208 237
       return -1;
209 238
     }
210
-
211 239
     // error on socket or device
212
-    if( FD_ISSET( udpSocket, &errFds ) )
213
-    {
240
+    if (FD_ISSET(udpSocket, &errFds)) {
214 241
       printf("error on socket\n");
215 242
       return -1;
216 243
     }
217
-    if( dev_fd != -1 && FD_ISSET( dev_fd, &errFds ) )
218
-    {
244
+    if (dev_fd != -1 && FD_ISSET(dev_fd, &errFds)) {
219 245
       if (*p_device_output_active)
220 246
         printf("error on device\n");
221 247
       break;
222 248
     }
223
-
224 249
     // received frame
225
-    if( FD_ISSET( udpSocket, &readFds ) )
226
-    {
250
+    if (FD_ISSET(udpSocket, &readFds)) {
227 251
       // fetch data
228 252
       len = recv(udpSocket, buffer, sizeof(buffer), 0);
229
-      if( len < 0 )
230
-      {
253
+      if (len < 0) {
231 254
         printf("could not read from socket\n");
232 255
         return -1;
233 256
       }
... ...
@@ -236,11 +259,11 @@ static int recv_and_out( SOCKET udpSocket, int dev_fd,
236 259
 
237 260
       // get frame from data
238 261
       pFrame = BlinkenFrameFromNetwork(buffer, len, NULL);
239
-      if( pFrame != NULL )
240
-      {
262
+      if (pFrame != NULL) {
241 263
         // change format
242 264
         if (format_change)
243
-          BlinkenFrameResize( pFrame, format_height, format_width, format_channels, format_colors - 1 );
265
+          BlinkenFrameResize(pFrame, format_height, format_width,
266
+                             format_channels, format_colors - 1);
244 267
 
245 268
         // create output data from frame
246 269
         len = BlinkenFrameToNetwork(pFrame, proto, buffer, sizeof(buffer));
... ...
@@ -249,10 +272,8 @@ static int recv_and_out( SOCKET udpSocket, int dev_fd,
249 272
         BlinkenFrameFree(pFrame);
250 273
 
251 274
         // output data to device
252
-        if( dev_fd != -1 && len > 0 )
253
-        {
254
-          if( write( dev_fd, buffer, len ) != len )
255
-          {
275
+        if (dev_fd != -1 && len > 0) {
276
+          if (write(dev_fd, buffer, len) != len) {
256 277
             if (*p_device_output_active)
257 278
               printf("error writing to device\n");
258 279
             break;
... ...
@@ -264,14 +285,11 @@ static int recv_and_out( SOCKET udpSocket, int dev_fd,
264 285
         }
265 286
       }
266 287
     }
267
-
268 288
     // received data from device
269
-    if( dev_fd != -1 && FD_ISSET( dev_fd, &readFds ) )
270
-    {
289
+    if (dev_fd != -1 && FD_ISSET(dev_fd, &readFds)) {
271 290
       // read data
272 291
       len = read(dev_fd, buffer, sizeof(buffer));
273
-      if( len < 0 )
274
-      {
292
+      if (len < 0) {
275 293
         if (*p_device_output_active)
276 294
           printf("error reading from device\n");
277 295
         break;
... ...
@@ -279,18 +297,15 @@ static int recv_and_out( SOCKET udpSocket, int dev_fd,
279 297
       if (len == 0)
280 298
         dev_eof = 1;
281 299
     }
282
-
283 300
     // using time limit
284
-    if( use_msecs )
285
-    {
301
+    if (use_msecs) {
286 302
       // get time elapsed
287 303
       int sec, usec;
288 304
       unsigned int msec;
289 305
       gettimeofday(&end, NULL);
290 306
       sec = end.tv_sec - start.tv_sec;
291 307
       usec = end.tv_usec - start.tv_usec;
292
-      if( usec < 0 )
293
-      {
308
+      if (usec < 0) {
294 309
         usec += 1000000;
295 310
         sec--;
296 311
       }
... ...
@@ -314,31 +329,27 @@ static int recv_and_out( SOCKET udpSocket, int dev_fd,
314 329
 // returns error code (not for device-errors, 0 for success)
315 330
 static int open_and_output(SOCKET udpSocket, char *device,
316 331
                            int *p_device_output_active,
317
-                            int serial_settings_change, int serial_settings, int serial_speed,
318
-                            unsigned int format_change,
319
-                            unsigned int format_height, unsigned int format_width,
320
-                            unsigned int format_channels, unsigned int format_colors,
321
-                            etBlinkenProto proto )
332
+                           int serial_settings_change, int serial_settings,
333
+                           int serial_speed, unsigned int format_change,
334
+                           unsigned int format_height,
335
+                           unsigned int format_width,
336
+                           unsigned int format_channels,
337
+                           unsigned int format_colors, etBlinkenProto proto)
322 338
 {
323 339
   int dev_fd, err;
324 340
   char txt[64];
325 341
 
326 342
   // open device
327 343
   dev_fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK);
328
-  if( dev_fd == -1 )
329
-  {
344
+  if (dev_fd == -1) {
330 345
     if (*p_device_output_active)
331 346
       printf("could not open \"%s\": error: %s\n", device, strerror(errno));
332 347
     return 0;
333 348
   }
334
-
335 349
   // setup serial port
336
-  if( serial_settings_change )
337
-  {
338
-    if( ! serial_settings_set( dev_fd, serial_settings, serial_speed ) )
339
-    {
340
-      if( *p_device_output_active )
341
-      {
350
+  if (serial_settings_change) {
351
+    if (!serial_settings_set(dev_fd, serial_settings, serial_speed)) {
352
+      if (*p_device_output_active) {
342 353
         serial_settings_to_str(serial_settings, txt, sizeof(txt));
343 354
         printf("could not set serial port to \"%s\"\n", txt);
344 355
       }
... ...
@@ -346,11 +357,10 @@ static int open_and_output( SOCKET udpSocket, char * device,
346 357
       return 0;
347 358
     }
348 359
   }
349
-
350 360
   // receive frames and output to device
351 361
   err = recv_and_out(udpSocket, dev_fd, p_device_output_active,
352
-                      format_change, format_height, format_width, format_channels, format_colors,
353
-                      proto, 0, 0 );
362
+                     format_change, format_height, format_width,
363
+                     format_channels, format_colors, proto, 0, 0);
354 364
 
355 365
   // close device
356 366
   close(dev_fd);
... ...
@@ -361,11 +371,15 @@ static int open_and_output( SOCKET udpSocket, char * device,
361 371
 // open device and output frames in a loop
362 372
 // returns error code (not for device-errors, 0 for success)
363 373
 static int open_and_output_loop(SOCKET udpSocket, char *device,
364
-                                 int serial_settings_change, int serial_settings, int serial_speed,
365
-                                 int reopen_device, unsigned int reopen_device_ms,
374
+                                int serial_settings_change,
375
+                                int serial_settings, int serial_speed,
376
+                                int reopen_device,
377
+                                unsigned int reopen_device_ms,
366 378
                                 unsigned int format_change,
367
-                                 unsigned int format_height, unsigned int format_width,
368
-                                 unsigned int format_channels, unsigned int format_colors,
379
+                                unsigned int format_height,
380
+                                unsigned int format_width,
381
+                                unsigned int format_channels,
382
+                                unsigned int format_colors,
369 383
                                 etBlinkenProto proto)
370 384
 {
371 385
   int device_output_active, err;
... ...
@@ -373,14 +387,14 @@ static int open_and_output_loop( SOCKET udpSocket, char * device,
373 387
   printf("receiving frames and outputting them to \"%s\"...\n", device);
374 388
   device_output_active = 1;
375 389
 
376
-  for( ; ; )
377
-  {
390
+  for (;;) {
378 391
 
379 392
     // try to open device and output frames
380 393
     err = open_and_output(udpSocket, device,
381 394
                           &device_output_active,
382
-                           serial_settings_change, serial_settings, serial_speed,
383
-                           format_change, format_height, format_width, format_channels, format_colors,
395
+                          serial_settings_change, serial_settings,
396
+                          serial_speed, format_change, format_height,
397
+                          format_width, format_channels, format_colors,
384 398
                           proto);
385 399
     if (err != 0 || !reopen_device)
386 400
       break;
... ...
@@ -392,8 +406,9 @@ static int open_and_output_loop( SOCKET udpSocket, char * device,
392 406
 
393 407
     // only fetch data from socket for a short time
394 408
     err = recv_and_out(udpSocket, -1, &device_output_active,
395
-                        format_change, format_height, format_width, format_channels, format_colors,
396
-                        proto, 1, reopen_device_ms );
409
+                       format_change, format_height, format_width,
410
+                       format_channels, format_colors, proto, 1,
411
+                       reopen_device_ms);
397 412
     if (err != 0)
398 413
       break;;
399 414
 
... ...
@@ -412,7 +427,8 @@ int main( int argCnt, char * * args )
412 427
   int i, bound, serial_settings, serial_speed;
413 428
   SOCKET udpSocket;
414 429
   etBlinkenProto proto;
415
-  unsigned int format_change, format_height, format_width, format_channels, format_colors;
430
+  unsigned int format_change, format_height, format_width, format_channels,
431
+      format_colors;
416 432
   unsigned int height, width, channels, colors, reopen_device_ms;
417 433
   int serial_settings_change, reopen_device;
418 434
   char txt[64];
... ...
@@ -427,11 +443,11 @@ int main( int argCnt, char * * args )
427 443
          "Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>\n"
428 444
          "Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n"
429 445
          "a blinkenarea.org project\n\n",
430
-          BLINKENLIB_VERSION_MAJOR, BLINKENLIB_VERSION_MINOR, BLINKENLIB_VERSION_REVISION );
446
+         BLINKENLIB_VERSION_MAJOR, BLINKENLIB_VERSION_MINOR,
447
+         BLINKENLIB_VERSION_REVISION);
431 448
 
432 449
   // print syntax
433
-  if( argCnt <= 1 )
434
-  {
450
+  if (argCnt <= 1) {
435 451
     printf("syntax: %s <parameter> [...]\n\n"
436 452
            "parameters:\n"
437 453
            "  -l [<ip>:]<port>\n"
... ...
@@ -449,15 +465,12 @@ int main( int argCnt, char * * args )
449 465
            "     settings to use for serial devices (defaults to no change)\n"
450 466
            "  -o <milliseconds>\n"
451 467
            "     reopen device after short time on error (defaults to not reopen)\n"
452
-            "\n",
453
-            args[0] );
468
+           "\n", args[0]);
454 469
     return 0;
455 470
   }
456
-
457 471
   // create udp socket
458 472
   udpSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
459
-  if( udpSocket == INVALID_SOCKET )
460
-  {
473
+  if (udpSocket == INVALID_SOCKET) {
461 474
     printf("cannot create UDP socket\n");
462 475
     return -1;
463 476
   }
... ...
@@ -475,17 +488,13 @@ int main( int argCnt, char * * args )
475 488
   serial_speed = 0;
476 489
   serial_settings_change = 0;
477 490
   reopen_device = 0;
478
-  for( i = 1; i < argCnt; i++ )
479
-  {
491
+  for (i = 1; i < argCnt; i++) {
480 492
 
481 493
     // local address
482
-    if( strcmp( args[i], "-l" ) == 0 )
483
-    {
484
-      if( i + 1 < argCnt )
485
-      {
494
+    if (strcmp(args[i], "-l") == 0) {
495
+      if (i + 1 < argCnt) {
486 496
         i++;
487
-        if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 )
488
-        {
497
+        if (sscanf(args[i], "%32[0-9.]:%hu", txt, &port) == 2) {
489 498
           addr.sin_family = AF_INET;
490 499
           addr.sin_port = htons(port);
491 500
           addr.sin_addr.s_addr = inet_addr(txt);
... ...
@@ -493,9 +502,7 @@ int main( int argCnt, char * * args )
493 502
             printf("could not set local address to \"%s\"\n", args[i]);
494 503
           else
495 504
             bound = 1;
496
-        }
497
-        else if( sscanf( args[i], "%hu", &port ) == 1 )
498
-        {
505
+        } else if (sscanf(args[i], "%hu", &port) == 1) {
499 506
           addr.sin_family = AF_INET;
500 507
           addr.sin_port = htons(port);
501 508
           addr.sin_addr.s_addr = htonl(INADDR_ANY);
... ...
@@ -503,48 +510,35 @@ int main( int argCnt, char * * args )
503 510
             printf("could not set local address to \"%s\"\n", args[i]);
504 511
           else
505 512
             bound = 1;
506
-        }
507
-        else
513
+        } else
508 514
           printf("invalid local address \"%s\"\n", args[i]);
509
-      }
510
-      else
515
+      } else
511 516
         printf("missing local address for \"-l\"\n");
512 517
     }
513
-
514 518
     // remote address
515
-    else if( strcmp( args[i], "-r" ) == 0 )
516
-    {
517
-      if( i + 1 < argCnt )
518
-      {
519
+    else if (strcmp(args[i], "-r") == 0) {
520
+      if (i + 1 < argCnt) {
519 521
         i++;
520
-        if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 )
521
-        {
522
+        if (sscanf(args[i], "%32[0-9.]:%hu", txt, &port) == 2) {
522 523
           addr.sin_family = AF_INET;
523 524
           addr.sin_port = htons(port);
524 525
           addr.sin_addr.s_addr = inet_addr(txt);
525 526
           if (connect(udpSocket, (struct sockaddr *)&addr, sizeof(addr)) != 0)
526 527
             printf("could not set remote address to \"%s\"\n", args[i]);
527
-        }
528
-        else if( sscanf( args[i], "%32[0-9.]", txt ) == 1 )
529
-        {
528
+        } else if (sscanf(args[i], "%32[0-9.]", txt) == 1) {
530 529
           addr.sin_family = AF_INET;
531 530
           addr.sin_port = htons(23230);
532 531
           addr.sin_addr.s_addr = inet_addr(txt);
533 532
           if (connect(udpSocket, (struct sockaddr *)&addr, sizeof(addr)) != 0)
534 533
             printf("could not set remote address to \"%s\"\n", args[i]);
535
-        }
536
-        else
534
+        } else
537 535
           printf("invalid remote address \"%s\"\n", args[i]);
538
-      }
539
-      else
536
+      } else
540 537
         printf("missing remote address for \"-r\"\n");
541 538
     }
542
-
543 539
     // protocol to output frames in
544
-    else if( strcmp( args[i], "-p" ) == 0 )
545
-    {
546
-      if( i + 1 < argCnt )
547
-      {
540
+    else if (strcmp(args[i], "-p") == 0) {
541
+      if (i + 1 < argCnt) {
548 542
         i++;
549 543
         if (strcasecmp(args[i], "BLP") == 0)
550 544
           proto = BlinkenProtoBlp;
... ...
@@ -554,87 +548,68 @@ int main( int argCnt, char * * args )
554 548
           proto = BlinkenProtoMcuf;
555 549
         else
556 550
           printf("unknown protocol \"%s\"\n", args[i]);
557
-      }
558
-      else
551
+      } else
559 552
         printf("missing protocol for \"-p\"\n");
560 553
     }
561
-
562 554
     // format to output frames in
563
-    else if( strcmp( args[i], "-f" ) == 0 )
564
-    {
565
-      if( i + 1 < argCnt )
566
-      {
555
+    else if (strcmp(args[i], "-f") == 0) {
556
+      if (i + 1 < argCnt) {
567 557
         i++;
568
-        if( sscanf( args[i], "%ux%u-%u/%u", &width, &height, &channels, &colors ) == 4 &&
569
-            width > 0 && width < 1000 && height > 0 && height < 1000 &&
570
-            channels > 0 && channels < 20 && colors > 1 && colors <= 256 )
571
-        {
558
+        if (sscanf
559
+            (args[i], "%ux%u-%u/%u", &width, &height, &channels, &colors) == 4
560
+            && width > 0 && width < 1000 && height > 0 && height < 1000
561
+            && channels > 0 && channels < 20 && colors > 1 && colors <= 256) {
572 562
           format_change = 1;
573 563
           format_height = height;
574 564
           format_width = width;
575 565
           format_channels = channels;
576 566
           format_colors = colors;
577
-        }
578
-        else
567
+        } else
579 568
           printf("invalid frame format \"%s\"\n", args[i]);
580
-      }
581
-      else
569
+      } else
582 570
         printf("missing frame format for \"-r\"\n");
583 571
     }
584
-
585 572
     // device to output frames to
586
-    else if( strcmp( args[i], "-d" ) == 0 )
587
-    {
588
-      if( i + 1 < argCnt )
589
-      {
573
+    else if (strcmp(args[i], "-d") == 0) {
574
+      if (i + 1 < argCnt) {
590 575
         i++;
591 576
         device = args[i];
592
-      }
593
-      else
577
+      } else
594 578
         printf("missing device name for \"-d\"\n");
595 579
     }
596
-
597 580
     // settings for serial output devices
598
-    else if( strcmp( args[i], "-s" ) == 0 )
599
-    {
600
-      if( i + 1 < argCnt )
601
-      {
581
+    else if (strcmp(args[i], "-s") == 0) {
582
+      if (i + 1 < argCnt) {
602 583
         i++;
603
-        if( serial_settings_parse( args[i], &serial_settings, &serial_speed ) )
604
-        {
584
+        if (serial_settings_parse(args[i], &serial_settings, &serial_speed)) {
605 585
           serial_settings_change = 1;
606
-        }
607
-        else
586
+        } else
608 587
           printf("invalid serial settings \"%s\"\n", args[i]);
609
-      }
610
-      else
588
+      } else
611 589
         printf("missing serial settings for \"-s\"\n");
612 590
     }
613
-
614 591
     // reopen device on error after some time
615
-    else if( strcmp( args[i], "-o" ) == 0 )
616
-    {
617
-      if( i + 1 < argCnt )
618
-      {
592
+    else if (strcmp(args[i], "-o") == 0) {
593
+      if (i + 1 < argCnt) {
619 594
         i++;
620
-        if( sscanf( args[i], "%u", &reopen_device_ms ) == 1 && reopen_device_ms >= 1 )
595
+        if (sscanf(args[i], "%u", &reopen_device_ms) == 1
596
+            && reopen_device_ms >= 1)
621 597
           reopen_device = 1;
622 598
         else
623 599
           printf("invalid number of milliseconds \"%s\"\n", args[i]);
624
-      }
625
-      else
600
+      } else
626 601
         printf("missing time for \"-o\"\n");
627 602
     }
628
-
629 603
     // unknown parameter
630 604
     else
631
-      printf( "unknown parameter \"%s\", call without parameters to get help\n", args[i] );
605
+      printf
606
+          ("unknown parameter \"%s\", call without parameters to get help\n",
607
+           args[i]);
632 608
 
633 609
   }     // for( i ...
634 610
 
635 611
   // try to bind if not bound
636
-  if( ! bound )
637
-  {
612
+  if (!bound) {
638 613
     printf("no local address to receive frames on,\n"
639 614
            "  using default local address \"0.0.0.0:2323\"\n");
640 615
     addr.sin_family = AF_INET;
... ...
@@ -642,8 +617,7 @@ int main( int argCnt, char * * args )
642 617
     addr.sin_addr.s_addr = htonl(INADDR_ANY);
643 618
     if (bind(udpSocket, (struct sockaddr *)&addr, sizeof(addr)) == 0)
644 619
       bound = 1;
645
-    else
646
-    {
620
+    else {
647 621
       printf("could not set local address to \"0.0.0.0:2323\"\n");
648 622
       close(udpSocket);
649 623
       return -1;
... ...
@@ -654,8 +627,8 @@ int main( int argCnt, char * * args )
654 627
   open_and_output_loop(udpSocket, device,
655 628
                        serial_settings_change, serial_settings, serial_speed,
656 629
                        reopen_device, reopen_device_ms,
657
-                        format_change, format_height, format_width, format_channels, format_colors,
658
-                        proto );
630
+                       format_change, format_height, format_width,
631
+                       format_channels, format_colors, proto);
659 632
 
660 633
   // close socket
661 634
   close(udpSocket);
... ...
@@ -1,8 +1,6 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #include <fcntl.h>
8 6
 #include <stdlib.h>
... ...
@@ -31,38 +29,23 @@ static int serial_settings_parse( char * str )
31 29
       baud != 2400 &&
32 30
       baud != 4800 &&
33 31
       baud != 9600 &&
34
-      baud != 19200 &&
35
-      baud != 38400 &&
36
-      baud != 57600 &&
37
-      baud != 115200 )
38
-  {
32
+      baud != 19200 && baud != 38400 && baud != 57600 && baud != 115200) {
39 33
     printf("illegal baudrate: %d\n", baud);
40 34
     return 0;
41 35
   }
42
-
43 36
   // parity
44 37
   if (parity != 'n' && parity != 'N' &&
45
-      parity != 'e' && parity != 'E' &&
46
-      parity != 'o' && parity != 'O' )
47
-  {
38
+      parity != 'e' && parity != 'E' && parity != 'o' && parity != 'O') {
48 39
     printf("invalid parity: %c\n", parity);
49 40
     return 0;
50 41
   }
51
-
52 42
   // data bits
53
-  if( data != 5 &&
54
-      data != 6 &&
55
-      data != 7 &&
56
-      data != 8 )
57
-  {
43
+  if (data != 5 && data != 6 && data != 7 && data != 8) {
58 44
     printf("illegal number of data bits: %d\n", data);
59 45
     return 0;
60 46
   }
61
-
62 47
   // stop bits
63
-  if( stop != 1 &&
64
-      stop == 2 )
65
-  {
48
+  if (stop != 1 && stop == 2) {
66 49
     printf("illegal number of stop bits: %d\n", stop);
67 50
     return 0;
68 51
   }
... ...
@@ -78,25 +60,22 @@ static int serial_settings_set( HANDLE hDev, char * settings )
78 60
   COMMTIMEOUTS CommTimeouts;
79 61
 
80 62
   // set serial parameters
81
-  if( ! GetCommState( hDev, &PortDcb ) )
82
-  {
63
+  if (!GetCommState(hDev, &PortDcb)) {
83 64
     printf("error getting device comm state: error %u\n", GetLastError());
84 65
     return 0;
85 66
   }
86
-  if( ! BuildCommDCB( hDev, &PortDcb ) )
87
-  {
67
+  if (!BuildCommDCB(hDev, &PortDcb)) {
88 68
     printf("error building comm state: error %u\n", GetLastError());
89 69
     return 0;
90 70
   }
91
-  if( ! SetCommState( hDev, &PortDcb ) )
92
-  {
71
+  if (!SetCommState(hDev, &PortDcb)) {
93 72
     printf("error setting device comm state: error %u\n", GetLastError());
94 73
     return 0;
95 74
   }
96
-
97 75
   // set timeout parameters
98 76
   // maximum time between arrival of two characters: 10 ms
99
-  //if this time elapses, read command will return even if buffer is not filled completely
77
+  // if this time elapses, read command will return even if buffer is not
78
+  // filled completely
100 79
   CommTimeouts.ReadIntervalTimeout = 10;
101 80
   // disable read timeouts
102 81
   CommTimeouts.ReadTotalTimeoutConstant = 0;
... ...
@@ -104,12 +83,11 @@ static int serial_settings_set( HANDLE hDev, char * settings )
104 83
   // disable write timeouts
105 84
   CommTimeouts.WriteTotalTimeoutConstant = 0;
106 85
   CommTimeouts.WriteTotalTimeoutMultiplier = 0;
107
-  if( ! SetCommTimeouts( hDev, &CommTimeouts ) )
108
-  {
109
-    printf( "error setting device timeout parameters: error %u\n", GetLastError( ) );
86
+  if (!SetCommTimeouts(hDev, &CommTimeouts)) {
87
+    printf("error setting device timeout parameters: error %u\n",
88
+           GetLastError());
110 89
     return 0;
111 90
   }
112
-
113 91
   // success
114 92
   return 1;
115 93
 }
... ...
@@ -121,9 +99,10 @@ static int recv_and_out( SOCKET udpSocket, HANDLE hDev,
121 99
                         int *p_device_output_active,
122 100
                         unsigned int format_change,
123 101
                         unsigned int format_height, unsigned int format_width,
124
-                         unsigned int format_channels, unsigned int format_colors,
125
-                         etBlinkenProto proto,
126
-                         int use_msecs, unsigned int msecs, int is_serial_device )
102
+                        unsigned int format_channels,
103
+                        unsigned int format_colors, etBlinkenProto proto,
104
+                        int use_msecs, unsigned int msecs,
105
+                        int is_serial_device)
127 106
 {
128 107
   fd_set readFds, errFds;
129 108
   stBlinkenFrame *pFrame;
... ...
@@ -134,8 +113,7 @@ static int recv_and_out( SOCKET udpSocket, HANDLE hDev,
134 113
   COMSTAT ComStat;
135 114
 
136 115
   dev_eof = 0;
137
-  for( ; ; )
138
-  {
116
+  for (;;) {
139 117
     // wait for next frame
140 118
     FD_ZERO(&readFds);
141 119
     FD_SET(udpSocket, &readFds);
... ...
@@ -147,29 +125,23 @@ static int recv_and_out( SOCKET udpSocket, HANDLE hDev,
147 125
       timeout.tv_sec = msecs / 1000;
148 126
       timeout.tv_usec = msecs % 1000 * 1000;
149 127
       p_timeout = &timeout;
150
-    }
151
-    else
128
+    } else
152 129
       p_timeout = NULL;
153 130
     if (select(0, &readFds, NULL, &errFds, p_timeout) < 0)      // error
154 131
     {
155 132
       printf("error during select: %s\n", strerror(errno));
156 133
       return -1;
157 134
     }
158
-
159 135
     // error on socket
160
-    if( FD_ISSET( udpSocket, &errFds ) )
161
-    {
136
+    if (FD_ISSET(udpSocket, &errFds)) {
162 137
       printf("error on socket\n");
163 138
       return -1;
164 139
     }
165
-
166 140
     // received frame
167
-    if( FD_ISSET( udpSocket, &readFds ) )
168
-    {
141
+    if (FD_ISSET(udpSocket, &readFds)) {
169 142
       // fetch data
170 143
       len = recv(udpSocket, buffer, sizeof(buffer), 0);
171
-      if( len < 0 )
172
-      {
144
+      if (len < 0) {
173 145
         printf("could not read from socket\n");
174 146
         return -1;
175 147
       }
... ...
@@ -178,11 +150,11 @@ static int recv_and_out( SOCKET udpSocket, HANDLE hDev,
178 150
 
179 151
       // get frame from data
180 152
       pFrame = BlinkenFrameFromNetwork(buffer, len, NULL);
181
-      if( pFrame != NULL )
182
-      {
153
+      if (pFrame != NULL) {
183 154
         // change format
184 155
         if (format_change)
185
-          BlinkenFrameResize( pFrame, format_height, format_width, format_channels, format_colors - 1 );
156
+          BlinkenFrameResize(pFrame, format_height, format_width,
157
+                             format_channels, format_colors - 1);
186 158
 
187 159
         // create output data from frame
188 160
         len = BlinkenFrameToNetwork(pFrame, proto, buffer, sizeof(buffer));
... ...
@@ -191,10 +163,9 @@ static int recv_and_out( SOCKET udpSocket, HANDLE hDev,
191 163
         BlinkenFrameFree(pFrame);
192 164
 
193 165
         // output data to device
194
-        if( hDev != INVALID_HANDLE_VALUE && len > 0 )
195
-        {
196
-          if( ! WriteFile( hDev, buffer, len, &DevWrLen, NULL ) || (int)DevWrLen != len )
197
-          {
166
+        if (hDev != INVALID_HANDLE_VALUE && len > 0) {
167
+          if (!WriteFile(hDev, buffer, len, &DevWrLen, NULL)
168
+              || (int)DevWrLen != len) {
198 169
             if (*p_device_output_active)
199 170
               printf("error writing to device: error %lu\n", GetLastError());
200 171
             break;
... ...
@@ -206,23 +177,18 @@ static int recv_and_out( SOCKET udpSocket, HANDLE hDev,
206 177
         }
207 178
       }
208 179
     }
209
-
210 180
     // get state of serial device
211
-    if( hDev != INVALID_HANDLE_VALUE && is_serial_device )
212
-	{
181
+    if (hDev != INVALID_HANDLE_VALUE && is_serial_device) {
213 182
       ClearCommError(hDev, &Err, &ComStat);
214 183
       // reception error
215
-	  if( Err & (CE_BREAK | CE_FRAME | CE_OVERRUN | CE_RXOVER | CE_RXPARITY) )
216
-	  {
184
+      if (Err & (CE_BREAK | CE_FRAME | CE_OVERRUN | CE_RXOVER | CE_RXPARITY)) {
217 185
         if (*p_device_output_active)
218 186
           printf("error reading from device (comm err=%X)\n", Err);
219 187
         break;
220 188
       }
221 189
     }
222
-
223 190
     // using time limit
224
-    if( use_msecs )
225
-    {
191
+    if (use_msecs) {
226 192
       unsigned int msec;
227 193
       // get time elapsed
228 194
       end = GetTickCount();
... ...
@@ -244,38 +210,37 @@ static int open_and_output( SOCKET udpSocket, char * device,
244 210
                            int *p_device_output_active,
245 211
                            int serial_settings_change, char *serial_settings,
246 212
                            unsigned int format_change,
247
-                            unsigned int format_height, unsigned int format_width,
248
-                            unsigned int format_channels, unsigned int format_colors,
249
-                            etBlinkenProto proto )
213
+                           unsigned int format_height,
214
+                           unsigned int format_width,
215
+                           unsigned int format_channels,
216
+                           unsigned int format_colors, etBlinkenProto proto)
250 217
 {
251 218
   HANDLE hDev;
252 219
   int err;
253 220
 
254 221
   // open device
255
-  hDev = CreateFile( device, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );
256
-  if( hDev == INVALID_HANDLE_VALUE )
257
-  {
222
+  hDev =
223
+      CreateFile(device, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
224
+                 0, NULL);
225
+  if (hDev == INVALID_HANDLE_VALUE) {
258 226
     if (*p_device_output_active)
259 227
       printf("could not open \"%s\": error %u\n", device, GetLastError());
260 228
     return 0;
261 229
   }
262
-
263 230
   // setup serial port
264
-  if( serial_settings_change )
265
-  {
266
-    if( ! serial_settings_set( hDev, serial_settings ) )
267
-    {
231
+  if (serial_settings_change) {
232
+    if (!serial_settings_set(hDev, serial_settings)) {
268 233
       if (*p_device_output_active)
269 234
         printf("could not set serial port to \"%s\"\n", serial_settings);
270 235
       CloseHandle(hDev);
271 236
       return 0;
272 237
     }
273 238
   }
274
-
275 239
   // receive frames and output to device
276 240
   err = recv_and_out(udpSocket, hDev, p_device_output_active,
277
-                      format_change, format_height, format_width, format_channels, format_colors,
278
-                      proto, 0, 0, serial_settings_change );
241
+                     format_change, format_height, format_width,
242
+                     format_channels, format_colors, proto, 0, 0,
243
+                     serial_settings_change);
279 244
 
280 245
   // close device
281 246
   CloseHandle(hDev);
... ...
@@ -286,11 +251,14 @@ static int open_and_output( SOCKET udpSocket, char * device,
286 251
 // open device and output frames in a loop
287 252
 // returns error code (not for device-errors, 0 for success)
288 253
 static int open_and_output_loop(SOCKET udpSocket, char *device,
289
-                                 int serial_settings_change, char * serial_settings,
290
-                                 int reopen_device, unsigned int reopen_device_ms,
254
+                                int serial_settings_change,
255
+                                char *serial_settings, int reopen_device,
256
+                                unsigned int reopen_device_ms,
291 257
                                 unsigned int format_change,
292
-                                 unsigned int format_height, unsigned int format_width,
293
-                                 unsigned int format_channels, unsigned int format_colors,
258
+                                unsigned int format_height,
259
+                                unsigned int format_width,
260
+                                unsigned int format_channels,
261
+                                unsigned int format_colors,
294 262
                                 etBlinkenProto proto)
295 263
 {
296 264
   int device_output_active, err;
... ...
@@ -298,15 +266,14 @@ static int open_and_output_loop( SOCKET udpSocket, char * device,
298 266
   printf("receiving frames and outputting them to \"%s\"...\n", device);
299 267
   device_output_active = 1;
300 268
 
301
-  for( ; ; )
302
-  {
269
+  for (;;) {
303 270
 
304 271
     // try to open device and output frames
305 272
     err = open_and_output(udpSocket, device,
306 273
                           &device_output_active,
307 274
                           serial_settings_change, serial_settings,
308
-                           format_change, format_height, format_width, format_channels, format_colors,
309
-                           proto );
275
+                          format_change, format_height, format_width,
276
+                          format_channels, format_colors, proto);
310 277
     if (err != 0 || !reopen_device)
311 278
       break;
312 279
 
... ...
@@ -317,8 +284,9 @@ static int open_and_output_loop( SOCKET udpSocket, char * device,
317 284
 
318 285
     // only fetch data from socket for a short time
319 286
     err = recv_and_out(udpSocket, INVALID_HANDLE_VALUE, &device_output_active,
320
-                        format_change, format_height, format_width, format_channels, format_colors,
321
-                        proto, 1, reopen_device_ms, serial_settings_change );
287
+                       format_change, format_height, format_width,
288
+                       format_channels, format_colors, proto, 1,
289
+                       reopen_device_ms, serial_settings_change);
322 290
     if (err != 0)
323 291
       break;
324 292
 
... ...
@@ -339,7 +307,8 @@ int main( int argCnt, char * * args )
339 307
   SOCKET udpSocket;
340 308
   char *serial_settings;
341 309
   etBlinkenProto proto;
342
-  unsigned int format_change, format_height, format_width, format_channels, format_colors;
310
+  unsigned int format_change, format_height, format_width, format_channels,
311
+      format_colors;
343 312
   unsigned int height, width, channels, colors, reopen_device_ms;
344 313
   int serial_settings_change, reopen_device, unblock;
345 314
   char txt[64];
... ...
@@ -354,8 +323,7 @@ int main( int argCnt, char * * args )
354 323
          "a blinkenarea.org project\n\n");
355 324
 
356 325
   // print syntax
357
-  if( argCnt <= 1 )
358
-  {
326
+  if (argCnt <= 1) {
359 327
     printf("syntax: %s <parameter> [...]\n\n"
360 328
            "parameters:\n"
361 329
            "  -l [<ip>:]<port>\n"
... ...
@@ -373,8 +341,7 @@ int main( int argCnt, char * * args )
373 341
            "     settings to use for serial devices (defaults to no change)\n"
374 342
            "  -o <milliseconds>\n"
375 343
            "     reopen device after short time on error (defaults to not reopen)\n"
376
-            "\n",
377
-            args[0] );
344
+           "\n", args[0]);
378 345
     return 0;
379 346
   }
380 347
 
... ...
@@ -382,8 +349,7 @@ int main( int argCnt, char * * args )
382 349
 
383 350
   // create udp socket
384 351
   udpSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
385
-  if( udpSocket == INVALID_SOCKET )
386
-  {
352
+  if (udpSocket == INVALID_SOCKET) {
387 353
     printf("cannot create UDP socket: error %lu\n", WSAGetLastError());
388 354
     WSACleanup();
389 355
     return -1;
... ...
@@ -392,8 +358,7 @@ int main( int argCnt, char * * args )
392 358
 
393 359
   // unblock udp socket
394 360
   unblock = 1;
395
-  if( ioctlsocket( udpSocket, FIONBIO, &unblock ) == SOCKET_ERROR )
396
-  {
361
+  if (ioctlsocket(udpSocket, FIONBIO, &unblock) == SOCKET_ERROR) {
397 362
     printf("cannot unblock UDP socket: error %lu\n", WSAGetLastError());
398 363
     closesocket(udpSocket);
399 364
     WSACleanup();
... ...
@@ -410,17 +374,13 @@ int main( int argCnt, char * * args )
410 374
   device = "NUL";
411 375
   serial_settings_change = 0;
412 376
   reopen_device = 0;
413
-  for( i = 1; i < argCnt; i++ )
414
-  {
377
+  for (i = 1; i < argCnt; i++) {
415 378
 
416 379
     // local address
417
-    if( strcmp( args[i], "-l" ) == 0 )
418
-    {
419
-      if( i + 1 < argCnt )
420
-      {
380
+    if (strcmp(args[i], "-l") == 0) {
381
+      if (i + 1 < argCnt) {
421 382
         i++;
422
-        if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 )
423
-        {
383
+        if (sscanf(args[i], "%32[0-9.]:%hu", txt, &port) == 2) {
424 384
           addr.sin_family = AF_INET;
425 385
           addr.sin_port = htons(port);
426 386
           addr.sin_addr.s_addr = inet_addr(txt);
... ...
@@ -428,9 +388,7 @@ int main( int argCnt, char * * args )
428 388
             printf("could not set local address to \"%s\"\n", args[i]);
429 389
           else
430 390
             bound = 1;
431
-        }
432
-        else if( sscanf( args[i], "%hu", &port ) == 1 )
433
-        {
391
+        } else if (sscanf(args[i], "%hu", &port) == 1) {
434 392
           addr.sin_family = AF_INET;
435 393
           addr.sin_port = htons(port);
436 394
           addr.sin_addr.s_addr = htonl(INADDR_ANY);
... ...
@@ -438,48 +396,35 @@ int main( int argCnt, char * * args )
438 396
             printf("could not set local address to \"%s\"\n", args[i]);
439 397
           else
440 398
             bound = 1;
441
-        }
442
-        else
399
+        } else
443 400
           printf("invalid local address \"%s\"\n", args[i]);
444
-      }
445
-      else
401
+      } else
446 402
         printf("missing local address for \"-l\"\n");
447 403
     }
448
-
449 404
     // remote address
450
-    else if( strcmp( args[i], "-r" ) == 0 )
451
-    {
452
-      if( i + 1 < argCnt )
453
-      {
405
+    else if (strcmp(args[i], "-r") == 0) {
406
+      if (i + 1 < argCnt) {
454 407
         i++;
455
-        if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 )
456
-        {
408
+        if (sscanf(args[i], "%32[0-9.]:%hu", txt, &port) == 2) {
457 409
           addr.sin_family = AF_INET;
458 410
           addr.sin_port = htons(port);
459 411
           addr.sin_addr.s_addr = inet_addr(txt);
460 412
           if (connect(udpSocket, (struct sockaddr *)&addr, sizeof(addr)) != 0)
461 413
             printf("could not set remote address to \"%s\"\n", args[i]);
462
-        }
463
-        else if( sscanf( args[i], "%32[0-9.]", txt ) == 1 )
464
-        {
414
+        } else if (sscanf(args[i], "%32[0-9.]", txt) == 1) {
465 415
           addr.sin_family = AF_INET;
466 416
           addr.sin_port = htons(23230);
467 417
           addr.sin_addr.s_addr = inet_addr(txt);
468 418
           if (connect(udpSocket, (struct sockaddr *)&addr, sizeof(addr)) != 0)
469 419
             printf("could not set remote address to \"%s\"\n", args[i]);
470
-        }
471
-        else
420
+        } else
472 421
           printf("invalid remote address \"%s\"\n", args[i]);
473
-      }
474
-      else
422
+      } else
475 423
         printf("missing remote address for \"-r\"\n");
476 424
     }
477
-
478 425
     // protocol to output frames in
479
-    else if( strcmp( args[i], "-p" ) == 0 )
480
-    {
481
-      if( i + 1 < argCnt )
482
-      {
426
+    else if (strcmp(args[i], "-p") == 0) {
427
+      if (i + 1 < argCnt) {
483 428
         i++;
484 429
         if (stricmp(args[i], "BLP") == 0)
485 430
           proto = BlinkenProtoBlp;
... ...
@@ -489,88 +434,69 @@ int main( int argCnt, char * * args )
489 434
           proto = BlinkenProtoMcuf;
490 435
         else
491 436
           printf("unknown protocol \"%s\"\n", args[i]);
492
-      }
493
-      else
437
+      } else
494 438
         printf("missing protocol for \"-p\"\n");
495 439
     }
496
-
497 440
     // format to output frames in
498
-    else if( strcmp( args[i], "-f" ) == 0 )
499
-    {
500
-      if( i + 1 < argCnt )
501
-      {
441
+    else if (strcmp(args[i], "-f") == 0) {
442
+      if (i + 1 < argCnt) {
502 443
         i++;
503
-        if( sscanf( args[i], "%ux%u-%u/%u", &width, &height, &channels, &colors ) == 4 &&
504
-            width > 0 && width < 1000 && height > 0 && height < 1000 &&
505
-            channels > 0 && channels < 20 && colors > 1 && colors <= 256 )
506
-        {
444
+        if (sscanf
445
+            (args[i], "%ux%u-%u/%u", &width, &height, &channels, &colors) == 4
446
+            && width > 0 && width < 1000 && height > 0 && height < 1000
447
+            && channels > 0 && channels < 20 && colors > 1 && colors <= 256) {
507 448
           format_change = 1;
508 449
           format_height = height;
509 450
           format_width = width;
510 451
           format_channels = channels;
511 452
           format_colors = colors;
512
-        }
513
-        else
453
+        } else
514 454
           printf("invalid frame format \"%s\"\n", args[i]);
515
-      }
516
-      else
455
+      } else
517 456
         printf("missing frame format for \"-r\"\n");
518 457
     }
519
-
520 458
     // device to output frames to
521
-    else if( strcmp( args[i], "-d" ) == 0 )
522
-    {
523
-      if( i + 1 < argCnt )
524
-      {
459
+    else if (strcmp(args[i], "-d") == 0) {
460
+      if (i + 1 < argCnt) {
525 461
         i++;
526 462
         device = args[i];
527
-      }
528
-      else
463
+      } else
529 464
         printf("missing device name for \"-d\"\n");
530 465
     }
531
-
532 466
     // settings for serial output devices
533
-    else if( strcmp( args[i], "-s" ) == 0 )
534
-    {
535
-      if( i + 1 < argCnt )
536
-      {
467
+    else if (strcmp(args[i], "-s") == 0) {
468
+      if (i + 1 < argCnt) {
537 469
         i++;
538
-        if( serial_settings_parse( args[i] ) )
539
-        {
470
+        if (serial_settings_parse(args[i])) {
540 471
           serial_settings_change = 1;
541 472
           serial_settings = args[i];
542
-        }
543
-        else
473
+        } else
544 474
           printf("invalid serial settings \"%s\"\n", args[i]);
545
-      }
546
-      else
475
+      } else
547 476
         printf("missing serial settings for \"-s\"\n");
548 477
     }
549
-
550 478
     // reopen device on error after some time
551
-    else if( strcmp( args[i], "-o" ) == 0 )
552
-    {
553
-      if( i + 1 < argCnt )
554
-      {
479
+    else if (strcmp(args[i], "-o") == 0) {
480
+      if (i + 1 < argCnt) {
555 481
         i++;
556
-        if( sscanf( args[i], "%u", &reopen_device_ms ) == 1 && reopen_device_ms >= 1 )
482
+        if (sscanf(args[i], "%u", &reopen_device_ms) == 1
483
+            && reopen_device_ms >= 1)
557 484
           reopen_device = 1;
558 485
         else
559 486
           printf("invalid number of milliseconds \"%s\"\n", args[i]);
560
-      }
561
-      else
487
+      } else
562 488
         printf("missing time for \"-o\"\n");
563 489
     }
564
-
565 490
     // unknown parameter
566 491
     else
567
-      printf( "unknown parameter \"%s\", call without parameters to get help\n", args[i] );
492
+      printf
493
+          ("unknown parameter \"%s\", call without parameters to get help\n",
494
+           args[i]);
568 495
 
569 496
   }     // for( i ...
570 497
 
571 498
   // try to bind if not bound
572
-  if( ! bound )
573
-  {
499
+  if (!bound) {
574 500
     printf("no local address to receive frames on,\n"
575 501
            "  using default local address \"0.0.0.0:2323\"\n");
576 502
     addr.sin_family = AF_INET;
... ...
@@ -578,8 +504,7 @@ int main( int argCnt, char * * args )
578 504
     addr.sin_addr.s_addr = htonl(INADDR_ANY);
579 505
     if (bind(udpSocket, (struct sockaddr *)&addr, sizeof(addr)) == 0)
580 506
       bound = 1;
581
-    else
582
-    {
507
+    else {
583 508
       printf("could not set local address to \"0.0.0.0:2323\"\n");
584 509
       closesocket(udpSocket);
585 510
       return -1;
... ...
@@ -590,8 +514,8 @@ int main( int argCnt, char * * args )
590 514
   open_and_output_loop(udpSocket, device,
591 515
                        serial_settings_change, serial_settings,
592 516
                        reopen_device, reopen_device_ms,
593
-                        format_change, format_height, format_width, format_channels, format_colors,
594
-                        proto );
517
+                       format_change, format_height, format_width,
518
+                       format_channels, format_colors, proto);
595 519
 
596 520
   // close socket
597 521
   closesocket(udpSocket);
... ...
@@ -1,8 +1,6 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #include <stdio.h>
8 6
 #include <stdlib.h>
... ...
@@ -36,11 +34,11 @@ int main( int argCnt, char * * args )
36 34
          "Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>\n"
37 35
          "Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n"
38 36
          "a blinkenarea.org project\n\n",
39
-          BLINKENLIB_VERSION_MAJOR, BLINKENLIB_VERSION_MINOR, BLINKENLIB_VERSION_REVISION );
37
+         BLINKENLIB_VERSION_MAJOR, BLINKENLIB_VERSION_MINOR,
38
+         BLINKENLIB_VERSION_REVISION);
40 39
 
41 40
   // print syntax
42
-  if( argCnt <= 1 )
43
-  {
41
+  if (argCnt <= 1) {
44 42
     printf("syntax: %s <parameter> [...]\n\n"
45 43
            "parameters:\n"
46 44
            "  -l [<ip>:]<port>\n"
... ...
@@ -65,8 +62,7 @@ int main( int argCnt, char * * args )
65 62
 
66 63
   // create udp socket
67 64
   udpSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
68
-  if( udpSocket == INVALID_SOCKET )
69
-  {
65
+  if (udpSocket == INVALID_SOCKET) {
70 66
     printf("cannot create UDP socket\n");
71 67
 #ifdef WIN32
72 68
     WSACleanup();
... ...
@@ -77,17 +73,13 @@ int main( int argCnt, char * * args )
77 73
 
78 74
   // process parameters
79 75
   timeout = 5000;
80
-  for( i = 1; i < argCnt; i++ )
81
-  {
76
+  for (i = 1; i < argCnt; i++) {
82 77
 
83 78
     // local address
84
-    if( strcmp( args[i], "-l" ) == 0 )
85
-    {
86
-      if( i + 1 < argCnt )
87
-      {
79
+    if (strcmp(args[i], "-l") == 0) {
80
+      if (i + 1 < argCnt) {
88 81
         i++;
89
-        if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 )
90
-        {
82
+        if (sscanf(args[i], "%32[0-9.]:%hu", txt, &port) == 2) {
91 83
           addr.sin_family = AF_INET;
92 84
           addr.sin_port = htons(port);
93 85
           addr.sin_addr.s_addr = inet_addr(txt);
... ...
@@ -95,9 +87,7 @@ int main( int argCnt, char * * args )
95 87
             printf("could not set local address to \"%s\"\n", args[i]);
96 88
           else
97 89
             bound = 1;
98
-        }
99
-        else if( sscanf( args[i], "%hu", &port ) == 1 )
100
-        {
90
+        } else if (sscanf(args[i], "%hu", &port) == 1) {
101 91
           addr.sin_family = AF_INET;
102 92
           addr.sin_port = htons(port);
103 93
           addr.sin_addr.s_addr = htonl(INADDR_ANY);
... ...
@@ -105,63 +95,46 @@ int main( int argCnt, char * * args )
105 95
             printf("could not set local address to \"%s\"\n", args[i]);
106 96
           else
107 97
             bound = 1;
108
-        }
109
-        else
98
+        } else
110 99
           printf("invalid local address \"%s\"\n", args[i]);
111
-      }
112
-      else
100
+      } else
113 101
         printf("missing local address for \"-l\"\n");
114 102
     }
115
-
116 103
     // remote address
117
-    else if( strcmp( args[i], "-r" ) == 0 )
118
-    {
119
-      if( i + 1 < argCnt )
120
-      {
104
+    else if (strcmp(args[i], "-r") == 0) {
105
+      if (i + 1 < argCnt) {
121 106
         i++;
122
-        if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 )
123
-        {
107
+        if (sscanf(args[i], "%32[0-9.]:%hu", txt, &port) == 2) {
124 108
           addr.sin_family = AF_INET;
125 109
           addr.sin_port = htons(port);
126 110
           addr.sin_addr.s_addr = inet_addr(txt);
127 111
           if (connect(udpSocket, (struct sockaddr *)&addr, sizeof(addr)) != 0)
128 112
             printf("could not set remote address to \"%s\"\n", args[i]);
129
-        }
130
-        else if( sscanf( args[i], "%32[0-9.]", txt ) == 1 )
131
-        {
113
+        } else if (sscanf(args[i], "%32[0-9.]", txt) == 1) {
132 114
           addr.sin_family = AF_INET;
133 115
           addr.sin_port = htons(23230);
134 116
           addr.sin_addr.s_addr = inet_addr(txt);
135 117
           if (connect(udpSocket, (struct sockaddr *)&addr, sizeof(addr)) != 0)
136 118
             printf("could not set remote address to \"%s\"\n", args[i]);
137
-        }
138
-        else
119
+        } else
139 120
           printf("invalid remote address \"%s\"\n", args[i]);
140
-      }
141
-      else
121
+      } else
142 122
         printf("missing remote address for \"-r\"\n");
143 123
     }
144
-
145 124
     // timeout
146
-    else if( strcmp( args[i], "-t" ) == 0 )
147
-    {
148
-      if( i + 1 < argCnt )
149
-      {
125
+    else if (strcmp(args[i], "-t") == 0) {
126
+      if (i + 1 < argCnt) {
150 127
         i++;
151 128
         if (sscanf(args[i], "%u", &val) == 1)
152 129
           timeout = val;
153 130
         else
154 131
           printf("invalid timeout value \"%s\"\n", args[i]);
155
-      }
156
-      else
132
+      } else
157 133
         printf("missing timeout value for \"-t\"\n");
158 134
     }
159
-
160 135
     // receive movie and write it to file
161
-    else if( strcmp( args[i], "-o" ) == 0 )
162
-    {
163
-      if( i + 1 < argCnt )
164
-      {
136
+    else if (strcmp(args[i], "-o") == 0) {
137
+      if (i + 1 < argCnt) {
165 138
         i++;
166 139
         if (!bound)     // try to bind if not bound
167 140
         {
... ...
@@ -175,31 +148,29 @@ int main( int argCnt, char * * args )
175 148
           else
176 149
             bound = 1;
177 150
         }
178
-        if( bound )
179
-        {
151
+        if (bound) {
180 152
           printf("receiving movie for file \"%s\"...\n", args[i]);
181 153
           pMovie = BlinkenMovieReceive(udpSocket, timeout, NULL);
182 154
           if (pMovie == NULL)
183 155
             printf("could not receive movie for file \"%s\"\n", args[i]);
184
-          else
185
-          {
156
+          else {
186 157
             if (BlinkenMovieSave(pMovie, args[i]) < 0)
187 158
               printf("could not write movie \"%s\"\n", args[i]);
188 159
             else
189 160
               printf("movie \"%s\" written\n", args[i]);
190 161
             BlinkenMovieFree(pMovie);
191 162
           }
192
-        }
193
-        else
194
-          printf( "no local address set to receive movie for file \"%s\" on\n", args[i] );
195
-      }
196
-      else
163
+        } else
164
+          printf("no local address set to receive movie for file \"%s\" on\n",
165
+                 args[i]);
166
+      } else
197 167
         printf("missing output filename for \"-o\"\n");
198 168
     }
199
-
200 169
     // unknown parameter
201 170
     else
202
-      printf( "unknown parameter \"%s\", call without parameters to get help\n", args[i] );
171
+      printf
172
+          ("unknown parameter \"%s\", call without parameters to get help\n",
173
+           args[i]);
203 174
 
204 175
   }     // for( i ...
205 176
 
... ...
@@ -1,8 +1,6 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #include <stdio.h>
8 6
 #include <stdlib.h>
... ...
@@ -39,11 +37,11 @@ int main( int argCnt, char * * args )
39 37
          "Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>\n"
40 38
          "Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n"
41 39
          "a blinkenarea.org project\n\n",
42
-          BLINKENLIB_VERSION_MAJOR, BLINKENLIB_VERSION_MINOR, BLINKENLIB_VERSION_REVISION );
40
+         BLINKENLIB_VERSION_MAJOR, BLINKENLIB_VERSION_MINOR,
41
+         BLINKENLIB_VERSION_REVISION);
43 42
 
44 43
   // print syntax
45
-  if( argCnt <= 1 )
46
-  {
44
+  if (argCnt <= 1) {
47 45
     printf("syntax: %s <parameter> [...]\n\n"
48 46
            "parameters:\n"
49 47
            "  -s [<ip>:]<port>\n"
... ...
@@ -74,19 +71,16 @@ int main( int argCnt, char * * args )
74 71
 
75 72
   // create udp socket
76 73
   udpSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
77
-  if( udpSocket == INVALID_SOCKET )
78
-  {
74
+  if (udpSocket == INVALID_SOCKET) {
79 75
     printf("cannot create UDP socket\n");
80 76
 #ifdef WIN32
81 77
     WSACleanup();
82 78
 #endif
83 79
     return -1;
84 80
   }
85
-
86 81
   // loop
87 82
   loop_cnt = 1;
88
-  for( loop = 0; loop < loop_cnt || loop_cnt == 0; loop++ )
89
-  {
83
+  for (loop = 0; loop < loop_cnt || loop_cnt == 0; loop++) {
90 84
 
91 85
     // print loop message
92 86
     if (loop_cnt > 1)
... ...
@@ -99,76 +93,61 @@ int main( int argCnt, char * * args )
99 93
     proto = BlinkenProtoMcuf;
100 94
     maxidle = 3000;
101 95
     send_cnt = 1;
102
-    for( i = 1; i < argCnt; i++ )
103
-    {
96
+    for (i = 1; i < argCnt; i++) {
104 97
 
105 98
       // source address
106
-      if( strcmp( args[i], "-s" ) == 0 )
107
-      {
108
-        if( i + 1 < argCnt )
109
-        {
99
+      if (strcmp(args[i], "-s") == 0) {
100
+        if (i + 1 < argCnt) {
110 101
           i++;
111
-          if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 )
112
-          {
102
+          if (sscanf(args[i], "%32[0-9.]:%hu", txt, &port) == 2) {
113 103
             addr.sin_family = AF_INET;
114 104
             addr.sin_port = htons(port);
115 105
             addr.sin_addr.s_addr = inet_addr(txt);
116 106
             if (bind(udpSocket, (struct sockaddr *)&addr, sizeof(addr)) != 0)
117 107
               printf("could not set source address to \"%s\"\n", args[i]);
118
-          }
119
-          else if( sscanf( args[i], "%hu", &port ) == 1 )
120
-          {
108
+          } else if (sscanf(args[i], "%hu", &port) == 1) {
121 109
             addr.sin_family = AF_INET;
122 110
             addr.sin_port = htons(port);
123 111
             addr.sin_addr.s_addr = htonl(INADDR_ANY);
124 112
             if (bind(udpSocket, (struct sockaddr *)&addr, sizeof(addr)) != 0)
125 113
               printf("could not set source address to \"%s\"\n", args[i]);
126
-          }
127
-          else
114
+          } else
128 115
             printf("invalid source address \"%s\"\n", args[i]);
129
-        }
130
-        else
116
+        } else
131 117
           printf("missing source address for \"-s\"\n");
132 118
       }
133
-
134 119
       // destination address
135
-      else if( strcmp( args[i], "-d" ) == 0 )
136
-      {
137
-        if( i + 1 < argCnt )
138
-        {
120
+      else if (strcmp(args[i], "-d") == 0) {
121
+        if (i + 1 < argCnt) {
139 122
           i++;
140
-          if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 )
141
-          {
123
+          if (sscanf(args[i], "%32[0-9.]:%hu", txt, &port) == 2) {
142 124
             addr.sin_family = AF_INET;
143 125
             addr.sin_port = htons(port);
144 126
             addr.sin_addr.s_addr = inet_addr(txt);
145
-            if( connect( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 )
146
-              printf( "could not set destination address to \"%s\"\n", args[i] );
127
+            if (connect(udpSocket, (struct sockaddr *)&addr, sizeof(addr)) !=
128
+                0)
129
+              printf("could not set destination address to \"%s\"\n",
130
+                     args[i]);
147 131
             else
148 132
               connected = 1;
149
-          }
150
-          else if( sscanf( args[i], "%32[0-9.]", txt ) == 1 )
151
-          {
133
+          } else if (sscanf(args[i], "%32[0-9.]", txt) == 1) {
152 134
             addr.sin_family = AF_INET;
153 135
             addr.sin_port = htons(2323);
154 136
             addr.sin_addr.s_addr = inet_addr(txt);
155
-            if( connect( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 )
156
-              printf( "could not set destination address to \"%s\"\n", args[i] );
137
+            if (connect(udpSocket, (struct sockaddr *)&addr, sizeof(addr)) !=
138
+                0)
139
+              printf("could not set destination address to \"%s\"\n",
140
+                     args[i]);
157 141
             else
158 142
               connected = 1;
159
-          }
160
-          else
143
+          } else
161 144
             printf("invalid destination address \"%s\"\n", args[i]);
162
-        }
163
-        else
145
+        } else
164 146
           printf("missing destination address for \"-d\"\n");
165 147
       }
166
-
167 148
       // protocol to use
168
-      else if( strcmp( args[i], "-p" ) == 0 )
169
-      {
170
-        if( i + 1 < argCnt )
171
-        {
149
+      else if (strcmp(args[i], "-p") == 0) {
150
+        if (i + 1 < argCnt) {
172 151
           i++;
173 152
           if (strcasecmp(args[i], "BLP") == 0)
174 153
             proto = BlinkenProtoBlp;
... ...
@@ -178,101 +157,86 @@ int main( int argCnt, char * * args )
178 157
             proto = BlinkenProtoMcuf;
179 158
           else
180 159
             printf("unknown protocol \"%s\"\n", args[i]);
181
-        }
182
-        else
160
+        } else
183 161
           printf("missing protocol for \"-p\"\n");
184 162
       }
185
-
186 163
       // maximum idle time
187
-      else if( strcmp( args[i], "-t" ) == 0 )
188
-      {
189
-        if( i + 1 < argCnt )
190
-        {
164
+      else if (strcmp(args[i], "-t") == 0) {
165
+        if (i + 1 < argCnt) {
191 166
           i++;
192 167
           if (sscanf(args[i], "%u", &ui) == 1)
193 168
             maxidle = ui;
194 169
           else
195 170
             printf("invalid maximum idle time value \"%s\"\n", args[i]);
196
-        }
197
-        else
171
+        } else
198 172
           printf("missing maximum idle time value for \"-t\"\n");
199 173
       }
200
-
201 174
       // number of times to send movies
202
-      else if( strcmp( args[i], "-n" ) == 0 )
203
-      {
204
-        if( i + 1 < argCnt )
205
-        {
175
+      else if (strcmp(args[i], "-n") == 0) {
176
+        if (i + 1 < argCnt) {
206 177
           i++;
207 178
           if (sscanf(args[i], "%u", &ui) == 1 && ui > 0)
208 179
             send_cnt = ui;
209 180
           else
210 181
             printf("invalid number \"%s\"\n", args[i]);
211
-        }
212
-        else
182
+        } else
213 183
           printf("missing number for \"-n\"\n");
214 184
       }
215
-
216 185
       // read movie and send it
217
-      else if( strcmp( args[i], "-i" ) == 0 )
218
-      {
219
-        if( i + 1 < argCnt )
220
-        {
186
+      else if (strcmp(args[i], "-i") == 0) {
187
+        if (i + 1 < argCnt) {
221 188
           i++;
222 189
           if (!connected)       // try to connect if not yet connected
223 190
           {
224 191
             printf("no destination address to sent movie \"%s\" to,\n"
225
-                    "  using default destination address \"127.0.0.1:2323\"\n", args[i] );
192
+                   "  using default destination address \"127.0.0.1:2323\"\n",
193
+                   args[i]);
226 194
             addr.sin_family = AF_INET;
227 195
             addr.sin_port = htons(2323);
228 196
             addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
229
-            if( connect( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 )
230
-              printf( "could not set destination address to \"127.0.0.1:2323\"\n" );
197
+            if (connect(udpSocket, (struct sockaddr *)&addr, sizeof(addr)) !=
198
+                0)
199
+              printf
200
+                  ("could not set destination address to \"127.0.0.1:2323\"\n");
231 201
             else
232 202
               connected = 1;
233 203
           }
234
-          if( connected )
235
-          {
204
+          if (connected) {
236 205
             pMovie = BlinkenMovieLoad(args[i]);
237 206
             if (pMovie == NULL)
238 207
               printf("could not read movie \"%s\"\n", args[i]);
239
-            else
240
-            {
208
+            else {
241 209
               printf("movie \"%s\" read\n", args[i]);
242
-              for( ui = 0; ui < send_cnt; ui++ )
243
-              {
244
-                printf( "sending movie \"%s\" (%u/%u)...\n", args[i], ui + 1, send_cnt );
210
+              for (ui = 0; ui < send_cnt; ui++) {
211
+                printf("sending movie \"%s\" (%u/%u)...\n", args[i], ui + 1,
212
+                       send_cnt);
245 213
                 BlinkenMovieSend(pMovie, udpSocket, proto, maxidle);
246 214
                 printf("movie \"%s\" sent\n", args[i]);
247 215
               }
248 216
               BlinkenMovieFree(pMovie);
249 217
             }
250
-          }
251
-          else
252
-            printf( "no destination address to sent movie \"%s\" to\n", args[i] );
253
-        }
254
-        else
218
+          } else
219
+            printf("no destination address to sent movie \"%s\" to\n",
220
+                   args[i]);
221
+        } else
255 222
           printf("missing input filename for \"-i\"\n");
256 223
       }
257
-
258 224
       // number of times to loop
259
-      else if( strcmp( args[i], "-l" ) == 0 )
260
-      {
261
-        if( i + 1 < argCnt )
262
-        {
225
+      else if (strcmp(args[i], "-l") == 0) {
226
+        if (i + 1 < argCnt) {
263 227
           i++;
264 228
           if (sscanf(args[i], "%u", &ui) == 1)
265 229
             loop_cnt = ui;
266 230
           else
267 231
             printf("invalid number \"%s\"\n", args[i]);
268
-        }
269
-        else
232
+        } else
270 233
           printf("missing number for \"-l\"\n");
271 234
       }
272
-
273 235
       // unknown parameter
274 236
       else
275
-        printf( "unknown parameter \"%s\", call without parameters to get help\n", args[i] );
237
+        printf
238
+            ("unknown parameter \"%s\", call without parameters to get help\n",
239
+             args[i]);
276 240
 
277 241
     }   // for( i ...
278 242
 
... ...
@@ -1,8 +1,6 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #include <stdlib.h>
8 6
 
... ...
@@ -10,7 +8,8 @@
10 8
 
11 9
 void *malloc1D(int count1, int size)
12 10
 {
13
-  if( count1 < 1 ) count1 = 1;
11
+  if (count1 < 1)
12
+    count1 = 1;
14 13
   if (size < 1)
15 14
     return NULL;
16 15
 
... ...
@@ -23,8 +22,10 @@ void * * malloc2D( int count1, int count2, int size )
23 22
   char *p;
24 23
   void **ptr;
25 24
 
26
-  if( count1 < 1 ) count1 = 1;
27
-  if( count2 < 1 ) count2 = 1;
25
+  if (count1 < 1)
26
+    count1 = 1;
27
+  if (count2 < 1)
28
+    count2 = 1;
28 29
   if (size < 1)
29 30
     return NULL;
30 31
 
... ...
@@ -35,8 +36,7 @@ void * * malloc2D( int count1, int count2, int size )
35 36
 
36 37
   ptr = (void **)p;
37 38
   p += count1 * sizeof(void *);
38
-  for( i = 0; i < count1; i++ )
39
-  {
39
+  for (i = 0; i < count1; i++) {
40 40
     ptr[i] = (void *)p;
41 41
     p += count2 * size;
42 42
   }
... ...
@@ -1,8 +1,6 @@
1
-/* BlinkenLib
2
- * Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
3
- * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4
- * a blinkenarea.org project
5
- */
1
+/* BlinkenLib Copyright 2004-2011 Stefan Schuermans <stefan@blinkenarea.org>
2
+   Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html a
3
+   blinkenarea.org project */
6 4
 
7 5
 #ifndef INC_BlinkenLib_Tools
8 6
 #define INC_BlinkenLib_Tools
... ...
@@ -14,7 +14,8 @@ void my_mng_free( mng_ptr pPtr, mng_size_t __attribute__(( unused )) iSize )
14 14
 
15 15
 int main()
16 16
 {
17
-  mng_handle hMNG = mng_initialize( MNG_NULL, my_mng_alloc, my_mng_free, MNG_NULL ); 
17
+  mng_handle hMNG =
18
+      mng_initialize(MNG_NULL, my_mng_alloc, my_mng_free, MNG_NULL);
18 19
   mng_cleanup(&hMNG);
19 20
 
20 21
   return 0;
21 22