BlinkenLib v.0.1.1 (2005-01-23)
Christian Heimke

Christian Heimke commited on 2011-07-15 09:00:54
Showing 10 changed files, with 2409 additions and 0 deletions.

... ...
@@ -0,0 +1,24 @@
1
+/* BlinkenLib
2
+ * version 0.1 date 2004-11-25
3
+ * Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info>
4
+ * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
5
+ * a blinkenarea.org project
6
+ * powered by eventphone.de
7
+ */
8
+
9
+#ifndef INC_BlinkenConstants
10
+#define INC_BlinkenConstants
11
+
12
+#define BlinkenHeightMin 1
13
+#define BlinkenHeightMax 1024
14
+#define BlinkenWidthMin 1
15
+#define BlinkenWidthMax 1024
16
+#define BlinkenChannelsMin 1
17
+#define BlinkenChannelsMax 16
18
+#define BlinkenMaxvalMin 1
19
+#define BlinkenMaxvalMax 255
20
+#define BlinkenDurationMin 1
21
+#define BlinkenDurationMax 65535
22
+
23
+#endif //#ifndef INC_BlinkenConstants
24
+
... ...
@@ -0,0 +1,65 @@
1
+/* BlinkenLib
2
+ * version 0.1 date 2004-11-25
3
+ * Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info>
4
+ * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
5
+ * a blinkenarea.org project
6
+ * powered by eventphone.de
7
+ */
8
+
9
+#include <stdio.h>
10
+#include <stdlib.h>
11
+
12
+#include "BlinkenMovie.h"
13
+
14
+int main( int argCnt, char * * args )
15
+{
16
+  stBlinkenMovie * pMovie;
17
+  char * str;
18
+
19
+  //print info
20
+  printf( "BlinkenLib\n"
21
+          "version 0.1 date 2004-11-25\n"
22
+          "Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info>\n"
23
+          "Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n"
24
+          "a blinkenarea.org project\n"
25
+          "powered by eventphone.de\n\n" );
26
+
27
+  //print syntax
28
+  if( argCnt <= 1 )
29
+  {
30
+    printf( "syntax: ./BlinkenConv <input-file> [<output-file>]\n\n"
31
+            "  - output files may be *.blm, *.bmm, *.bml, *.bbm\n\n" );
32
+  }
33
+
34
+  //no movie loaded
35
+  pMovie = NULL;
36
+
37
+  //read movie
38
+  if( argCnt >= 2 )
39
+    pMovie = BlinkenMovieLoad( args[1] );
40
+
41
+  //movie was loaded
42
+  if( pMovie != NULL )
43
+  {
44
+    //print movie
45
+    if( argCnt <= 2 )
46
+    {
47
+      str = BlinkenMovieToString( pMovie );
48
+      if( str != NULL )
49
+      {
50
+        printf( "%s", str );
51
+        free( str );
52
+      }
53
+    }
54
+
55
+    //save movie
56
+    if( argCnt >= 3 )
57
+      BlinkenMovieSave( pMovie, args[2] );
58
+
59
+    //free movie
60
+    BlinkenMovieFree( pMovie );
61
+    pMovie = NULL;
62
+  }
63
+
64
+  return 0;
65
+}
... ...
@@ -0,0 +1,461 @@
1
+/* BlinkenLib
2
+ * version 0.1 date 2004-11-25
3
+ * Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info>
4
+ * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
5
+ * a blinkenarea.org project
6
+ * powered by eventphone.de
7
+ */
8
+
9
+#include <stdio.h>
10
+#include <stdlib.h>
11
+#include <string.h>
12
+
13
+#include "BlinkenConstants.h"
14
+#include "BlinkenFrame.h"
15
+#include "Tools.h"
16
+
17
+struct sBlinkenFrame
18
+{
19
+  int height;
20
+  int width;
21
+  int channels;
22
+  int maxval;
23
+  int duration;
24
+  unsigned char * * * pppData;
25
+};
26
+
27
+stBlinkenFrame * BlinkenFrameNew( int height, int width, int channels, int maxval, int duration )
28
+{
29
+  stBlinkenFrame * pFrame;
30
+
31
+  if( height < BlinkenHeightMin ) height = BlinkenHeightMin;
32
+  if( height > BlinkenHeightMax ) height = BlinkenHeightMax;
33
+  if( width < BlinkenWidthMin ) width = BlinkenWidthMin;
34
+  if( width > BlinkenWidthMax ) width = BlinkenWidthMax;
35
+  if( channels < BlinkenChannelsMin ) channels = BlinkenChannelsMin;
36
+  if( channels > BlinkenChannelsMax ) channels = BlinkenMaxvalMax;
37
+  if( maxval < BlinkenMaxvalMin ) maxval = BlinkenMaxvalMin;
38
+  if( maxval > BlinkenMaxvalMax ) maxval = BlinkenMaxvalMax;
39
+  if( duration < BlinkenDurationMin ) duration = BlinkenDurationMin;
40
+  if( duration > BlinkenDurationMax ) duration = BlinkenDurationMax;
41
+
42
+  pFrame = (stBlinkenFrame *)malloc( sizeof( stBlinkenFrame ) );
43
+  if( pFrame == NULL )
44
+    return NULL;
45
+
46
+  pFrame->height = height;
47
+  pFrame->width = width;
48
+  pFrame->channels = channels;
49
+  pFrame->maxval = maxval;
50
+  pFrame->duration = duration;
51
+
52
+  pFrame->pppData = (unsigned char * * *)malloc3D( height, width, channels, sizeof( unsigned char ) );
53
+  if( pFrame->pppData == NULL )
54
+  {
55
+    free( pFrame );
56
+    return NULL;
57
+  }
58
+
59
+  return pFrame;
60
+}
61
+
62
+stBlinkenFrame * BlinkenFrameClone( stBlinkenFrame * pSrcFrame )
63
+{
64
+  int y, x, c;
65
+  stBlinkenFrame * pFrame;
66
+
67
+  if( pSrcFrame == NULL )
68
+    return NULL;
69
+
70
+  pFrame = BlinkenFrameNew( pSrcFrame->height, pSrcFrame->width,
71
+                            pSrcFrame->channels, pSrcFrame->maxval, pSrcFrame->duration );
72
+  if( pFrame == NULL )
73
+    return NULL;
74
+
75
+  for( y = 0; y < pFrame->height; y++ )
76
+    for( x = 0; x < pFrame->width; x++ )
77
+      for( c = 0; c < pFrame->channels; c++ )
78
+        pFrame->pppData[y][x][c] = pSrcFrame->pppData[y][x][c];
79
+
80
+  return pFrame;
81
+}
82
+
83
+void BlinkenFrameFree( stBlinkenFrame * pFrame )
84
+{
85
+  if( pFrame == NULL )
86
+    return;
87
+
88
+  free( pFrame->pppData );
89
+  free( pFrame );
90
+}
91
+
92
+void BlinkenFrameClear( stBlinkenFrame * pFrame )
93
+{
94
+  int y, x, c;
95
+
96
+  if( pFrame == NULL )
97
+    return;
98
+
99
+  for( y = 0; y < pFrame->height; y++ )
100
+    for( x = 0; x < pFrame->width; x++ )
101
+      for( c = 0; c < pFrame->channels; c++ )
102
+        pFrame->pppData[y][x][c] = 0;
103
+}
104
+
105
+int BlinkenFrameGetHeight( stBlinkenFrame * pFrame )
106
+{
107
+  if( pFrame == NULL )
108
+    return 0;
109
+
110
+  return pFrame->height;
111
+}
112
+
113
+int BlinkenFrameGetWidth( stBlinkenFrame * pFrame )
114
+{
115
+  if( pFrame == NULL )
116
+    return 0;
117
+
118
+  return pFrame->width;
119
+}
120
+
121
+int BlinkenFrameGetChannels( stBlinkenFrame * pFrame )
122
+{
123
+  if( pFrame == NULL )
124
+    return 0;
125
+
126
+  return pFrame->channels;
127
+}
128
+
129
+int BlinkenFrameGetMaxval( stBlinkenFrame * pFrame )
130
+{
131
+  if( pFrame == NULL )
132
+    return 0;
133
+
134
+  return pFrame->maxval;
135
+}
136
+
137
+int BlinkenFrameGetDuration( stBlinkenFrame * pFrame )
138
+{
139
+  if( pFrame == NULL )
140
+    return 0;
141
+
142
+  return pFrame->duration;
143
+}
144
+
145
+void BlinkenFrameSetDuration( stBlinkenFrame * pFrame, int duration )
146
+{
147
+  if( pFrame == NULL )
148
+    return;
149
+
150
+  if( duration < BlinkenDurationMin ) duration = BlinkenDurationMin;
151
+  if( duration > BlinkenDurationMax ) duration = BlinkenDurationMax;
152
+
153
+  pFrame->duration = duration;
154
+}
155
+
156
+unsigned char BlinkenFrameGetPixel( stBlinkenFrame * pFrame, int y, int x, int c )
157
+{
158
+  if( pFrame == NULL ||
159
+      y < 0 || y >= pFrame->height ||
160
+      x < 0 || x >= pFrame->width ||
161
+      c < 0 || c >= pFrame->channels )
162
+      return 0;
163
+
164
+  return pFrame->pppData[y][x][c];
165
+}
166
+
167
+void BlinkenFrameSetPixel( stBlinkenFrame * pFrame, int y, int x, int c, unsigned char val )
168
+{
169
+  if( pFrame == NULL ||
170
+      y < 0 || y >= pFrame->height ||
171
+      x < 0 || x >= pFrame->width ||
172
+      c < 0 || c >= pFrame->channels )
173
+      return;
174
+
175
+  if( val > pFrame->maxval )
176
+    val = pFrame->maxval;
177
+  pFrame->pppData[y][x][c] = val;
178
+}
179
+
180
+unsigned long BlinkenFrameGetColor( stBlinkenFrame * pFrame, int y, int x )
181
+{
182
+  if( pFrame == NULL ||
183
+      y < 0 || y >= pFrame->height ||
184
+      x < 0 || x >= pFrame->width )
185
+      return 0;
186
+
187
+  if( pFrame->channels == 1 )
188
+    return (((unsigned long)pFrame->pppData[y][x][0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 16 |
189
+           (((unsigned long)pFrame->pppData[y][x][0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 8 |
190
+           (((unsigned long)pFrame->pppData[y][x][0] * 255 + pFrame->maxval / 2) / pFrame->maxval);
191
+  if( pFrame->channels == 2 )
192
+    return (((unsigned long)pFrame->pppData[y][x][0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 16 |
193
+           (((unsigned long)pFrame->pppData[y][x][1] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 8;
194
+  return (((unsigned long)pFrame->pppData[y][x][0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 16 |
195
+         (((unsigned long)pFrame->pppData[y][x][1] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 8 |
196
+         (((unsigned long)pFrame->pppData[y][x][2] * 255 + pFrame->maxval / 2) / pFrame->maxval);
197
+}
198
+
199
+void BlinkenFrameSetColor( stBlinkenFrame * pFrame, int y, int x, unsigned long color )
200
+{
201
+  int alpha, alpha_, c;
202
+
203
+  if( pFrame == NULL ||
204
+      y < 0 || y >= pFrame->height ||
205
+      x < 0 || x >= pFrame->width )
206
+      return;
207
+
208
+  alpha = (color >> 24) & 0xFF;
209
+  alpha_ = 255 - alpha;
210
+  if( pFrame->channels >= 1 )
211
+    pFrame->pppData[y][x][0] = (unsigned char)(( ((((color >> 16) & 0xFF) * pFrame->maxval + 127) / 255) * alpha
212
+                                               + (unsigned long)pFrame->pppData[y][x][0] * alpha_
213
+                                               ) / 255);
214
+  if( pFrame->channels >= 2 )
215
+    pFrame->pppData[y][x][1] = (unsigned char)(( ((((color >> 8) & 0xFF) * pFrame->maxval + 127) / 255) * alpha
216
+                                               + (unsigned long)pFrame->pppData[y][x][1] * alpha_
217
+                                               ) / 255);
218
+  if( pFrame->channels >= 3 )
219
+    pFrame->pppData[y][x][2] = (unsigned char)(( (((color & 0xFF) * pFrame->maxval + 127) / 255) * alpha
220
+                                               + (unsigned long)pFrame->pppData[y][x][2] * alpha_
221
+                                               ) / 255);
222
+  for( c = 3; c < pFrame->channels; c++ )
223
+    pFrame->pppData[y][x][c] = (unsigned char)(( 0
224
+                                               + (unsigned long)pFrame->pppData[y][x][c] * alpha_
225
+                                               ) / 255);
226
+}
227
+
228
+void BlinkenFrameResize( stBlinkenFrame * pFrame, int height, int width, int channels, int maxval )
229
+{
230
+  unsigned char * * * pppData;
231
+  int y, x, c;
232
+  int emptyY, emptyX, skipY, skipX, rangeY, rangeX;
233
+  unsigned long val, div;
234
+
235
+  if( pFrame == NULL )
236
+    return;
237
+
238
+  if( height < BlinkenHeightMin ) height = BlinkenHeightMin;
239
+  if( height > BlinkenHeightMax ) height = BlinkenHeightMax;
240
+  if( width < BlinkenWidthMin ) width = BlinkenWidthMin;
241
+  if( width > BlinkenWidthMax ) width = BlinkenWidthMax;
242
+  if( channels < BlinkenChannelsMin ) channels = BlinkenChannelsMin;
243
+  if( channels > BlinkenChannelsMax ) channels = BlinkenMaxvalMax;
244
+  if( maxval < BlinkenMaxvalMin ) maxval = BlinkenMaxvalMin;
245
+  if( maxval > BlinkenMaxvalMax ) maxval = BlinkenMaxvalMax;
246
+
247
+  if( height == pFrame->height &&
248
+      width == pFrame->width &&
249
+      channels == pFrame->channels &&
250
+      maxval == pFrame->maxval )
251
+    return;
252
+
253
+  //allocate new data array
254
+  pppData = (unsigned char * * *)malloc3D( height, width, channels, sizeof( unsigned char ) );
255
+  if( pppData == NULL )
256
+    return;
257
+  for( y = 0; y < height; y++ )
258
+    for( x = 0; x < width; x++ )
259
+      for( c = 0; c < channels; c++ )
260
+        pppData[y][x][c] = 0;
261
+
262
+  //get number of pixels to skip / to leave empty in X and Y direction
263
+  if( height > pFrame->height )
264
+  {
265
+    emptyY = (height - pFrame->height) / 2; 
266
+    skipY = 0;
267
+    rangeY = pFrame->height;
268
+  }
269
+  else
270
+  {
271
+    emptyY = 0;
272
+    skipY = (pFrame->height - height) / 2;
273
+    rangeY = height;
274
+  }
275
+  if( width > pFrame->width )
276
+  {
277
+    emptyX = (width - pFrame->width) / 2; 
278
+    skipX = 0;
279
+    rangeX = pFrame->width;
280
+  }
281
+  else
282
+  {
283
+    emptyX = 0;
284
+    skipX = (pFrame->width - width) / 2;
285
+    rangeX = width;
286
+  }
287
+
288
+  //resize frame with help of calculated parameters
289
+  for( y = 0; y < rangeY; y++ )
290
+  {
291
+    for( x = 0; x < rangeX; x++ )
292
+    {
293
+      if( channels >= pFrame->channels ) //add channels: copy last channel into new channels
294
+      {
295
+        for( c = 0; c < pFrame->channels; c++ )
296
+          pppData[emptyY + y][emptyX + x][c] = (unsigned char)(((unsigned long)pFrame->pppData[skipY + y][skipX + x][c] * maxval + pFrame->maxval / 2) / pFrame->maxval);
297
+        for( ; c < channels; c++ )
298
+          pppData[emptyY + y][emptyX + x][c] = pppData[emptyY + y][emptyX + x][pFrame->channels - 1];
299
+      }
300
+      else //remove channels: merge leftover channels with last kept channel
301
+      {
302
+        val = 0;
303
+        for( c = 0; c < channels - 1; c++ )
304
+          pppData[emptyY + y][emptyX + x][c] = (unsigned char)(((unsigned long)pFrame->pppData[skipY + y][skipX + x][c] * maxval + pFrame->maxval / 2) / pFrame->maxval);
305
+        for( c = channels - 1; c < pFrame->channels; c++ )
306
+          val += (unsigned long)pFrame->pppData[skipY + y][skipX + x][c];
307
+        div = pFrame->maxval * (pFrame->channels - channels + 1);
308
+        pppData[emptyY + y][emptyX + x][channels - 1] = (unsigned char)((val * maxval + div / 2) / div);
309
+      }
310
+    }
311
+  }
312
+
313
+  pFrame->height = height;
314
+  pFrame->width = width;
315
+  pFrame->channels = channels;
316
+  pFrame->maxval = maxval;
317
+  free( pFrame->pppData );
318
+  pFrame->pppData = pppData;
319
+}
320
+
321
+void BlinkenFrameScale( stBlinkenFrame * pFrame, int height, int width )
322
+{
323
+  unsigned char * * * pppData;
324
+  double scaleHor, scaleVer, ox, oy, ox1, oy1, val;
325
+  int c, nx, ny, x, y, oxi, oyi, ox1i, oy1i;
326
+
327
+  if( pFrame == NULL )
328
+    return;
329
+
330
+  if( height < BlinkenHeightMin ) height = BlinkenHeightMin;
331
+  if( height > BlinkenHeightMax ) height = BlinkenHeightMax;
332
+  if( width < BlinkenWidthMin ) width = BlinkenWidthMin;
333
+  if( width > BlinkenWidthMax ) width = BlinkenWidthMax;
334
+
335
+  if( height == pFrame->height &&
336
+      width == pFrame->width )
337
+    return;
338
+
339
+  scaleHor = (double)width / (double)pFrame->width;
340
+  scaleVer = (double)height / (double)pFrame->height;
341
+
342
+  //allocate new data array
343
+  pppData = (unsigned char * * *)malloc3D( height, width, pFrame->channels, sizeof( unsigned char ) );
344
+  if( pppData == NULL )
345
+    return;
346
+
347
+  //scale every channel
348
+  for( c = 0; c < pFrame->channels; c++ )
349
+  {
350
+    for( ny = 0; ny < height; ny++ )
351
+    {
352
+      for( nx = 0; nx < width; nx++ )
353
+      {
354
+        oy = (double)ny / scaleVer; //sub-pixel exact range in old picture
355
+        ox = (double)nx / scaleHor;
356
+        oy1 = (double)(ny + 1) / scaleVer - 0.000001;
357
+        ox1 = (double)(nx + 1) / scaleHor - 0.000001;
358
+        if( oy < 0 || ox < 0 || oy1 >= pFrame->height || ox1 >= pFrame->width) //out of old picture
359
+          pppData[ny][nx][c] = 0;
360
+        else
361
+        {
362
+          oyi = (int)oy;
363
+          oxi = (int)ox;
364
+          oy1i = (int)oy1;
365
+          ox1i = (int)ox1;
366
+          if( oyi == oy1i )
367
+          {
368
+            if( oxi == ox1i) //one source pixel
369
+            {
370
+              val = (double)pFrame->pppData[oyi][oxi][c];
371
+            }
372
+            else //one line of source pixels
373
+            {
374
+              val = (double)pFrame->pppData[oyi][oxi][c] * (1 - ox + oxi)
375
+                  + (double)pFrame->pppData[oyi][ox1i][c] * (ox1 - ox1i);
376
+              for( x = oxi + 1; x < ox1i; x++ )
377
+                val += (double)pFrame->pppData[oyi][x][c];
378
+              val /= ox1 - ox;
379
+            }
380
+          }
381
+          else //one column of source pixels
382
+          {
383
+            if( oxi == ox1i )
384
+            {
385
+              val = (double)pFrame->pppData[oyi][oxi][c] * (1 - oy + oyi)
386
+                  + (double)pFrame->pppData[oy1i][oxi][c] * (oy1 - oy1i);
387
+              for( y = oyi + 1; y < oy1i; y++ )
388
+                val += (double)pFrame->pppData[y][oxi][c];
389
+              val /= oy1 - oy;
390
+            }
391
+            else //rectangle of source pixels
392
+            {
393
+              val = (double)pFrame->pppData[oyi][oxi][c] * (1 - oy + oyi) * (1 - ox + oxi)
394
+                  + (double)pFrame->pppData[oyi][ox1i][c] * (1 - oy + oyi) * (ox1 - ox1i)
395
+                  + (double)pFrame->pppData[oy1i][oxi][c] * (oy1 - oy1i) * (1 - ox + oxi)
396
+                  + (double)pFrame->pppData[oy1i][ox1i][c] * (oy1 - oy1i) * (ox1 - ox1i);
397
+              for( y = oyi + 1; y < oy1i; y++ )
398
+              {
399
+                val += (double)pFrame->pppData[y][oxi][c] * (1 - ox + oxi)
400
+                     + (double)pFrame->pppData[y][ox1i][c] * (ox1 - ox1i);
401
+              }
402
+              for( x = oxi + 1; x < ox1i; x++ )
403
+              {
404
+                val += (double)pFrame->pppData[oyi][x][c] * (1 - oy + oyi)
405
+                     + (double)pFrame->pppData[oy1i][x][c] * (oy1 - oy1i);
406
+              }
407
+              for( y = oyi + 1; y < oy1i; y++ )
408
+                for( x = oxi + 1; x < ox1i; x++ )
409
+                  val += (double)pFrame->pppData[y][x][c];
410
+              val /= (oy1 - oy) * (ox1 - ox);
411
+            }
412
+          }
413
+          pppData[ny][nx][c] = (unsigned char)(val + 0.5);
414
+        }
415
+      } //for( nx ...
416
+    } //for( ny ...
417
+  } //for( c ...
418
+
419
+  pFrame->height = height;
420
+  pFrame->width = width;
421
+  free( pFrame->pppData );
422
+  pFrame->pppData = pppData;
423
+}
424
+
425
+char * BlinkenFrameToString( stBlinkenFrame * pFrame )
426
+{
427
+  int size, y, x, c;
428
+  char * str, * ptr;
429
+  unsigned long val;
430
+
431
+  if( pFrame == NULL )
432
+    return NULL;
433
+
434
+  size = pFrame->height * (pFrame->width + 1) + 32;
435
+
436
+  str = (char *)malloc( size );
437
+  if( str == NULL )
438
+    return NULL;
439
+
440
+  ptr = str;
441
+  
442
+  for( y = 0; y < pFrame->height; y++ )
443
+  {
444
+    for( x = 0; x < pFrame->width; x++ )
445
+    {
446
+      val = 0;
447
+      for( val = 0, c = 0; c < pFrame->channels; c++ )
448
+        val += pFrame->pppData[y][x][c];
449
+      val = val * 7 / pFrame->maxval / pFrame->channels;
450
+      *ptr = " -+*%#&@"[val];
451
+      ptr++;
452
+    }
453
+    *ptr = '\n';
454
+    ptr++;
455
+  }
456
+
457
+  sprintf( ptr, "%u ms\n", pFrame->duration );
458
+
459
+  return str;
460
+}
461
+
... ...
@@ -0,0 +1,42 @@
1
+/* BlinkenLib
2
+ * version 0.1 date 2004-11-25
3
+ * Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info>
4
+ * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
5
+ * a blinkenarea.org project
6
+ * powered by eventphone.de
7
+ */
8
+
9
+#ifndef INC_BlinkenFrame
10
+#define INC_BlinkenFrame
11
+
12
+typedef struct sBlinkenFrame stBlinkenFrame;
13
+
14
+stBlinkenFrame * BlinkenFrameNew( int height, int width, int channels, int maxval, int duration );
15
+
16
+stBlinkenFrame * BlinkenFrameClone( stBlinkenFrame * pSrcFrame );
17
+
18
+void BlinkenFrameFree( stBlinkenFrame * pFrame );
19
+
20
+void BlinkenFrameClear( stBlinkenFrame * pFrame );
21
+
22
+int BlinkenFrameGetHeight( stBlinkenFrame * pFrame );
23
+int BlinkenFrameGetWidth( stBlinkenFrame * pFrame );
24
+int BlinkenFrameGetChannels( stBlinkenFrame * pFrame );
25
+int BlinkenFrameGetMaxval( stBlinkenFrame * pFrame );
26
+
27
+int BlinkenFrameGetDuration( stBlinkenFrame * pFrame );
28
+void BlinkenFrameSetDuration( stBlinkenFrame * pFrame, int duration );
29
+
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 );
32
+
33
+unsigned long BlinkenFrameGetColor( stBlinkenFrame * pFrame, int y, int x );
34
+void BlinkenFrameSetColor( stBlinkenFrame * pFrame, int y, int x, unsigned long color );
35
+
36
+void BlinkenFrameResize( stBlinkenFrame * pFrame, int height, int width, int channels, int maxval );
37
+void BlinkenFrameScale( stBlinkenFrame * pFrame, int height, int width );
38
+
39
+char * BlinkenFrameToString( stBlinkenFrame * pFrame );
40
+
41
+#endif //#ifndef INC_BlinkenFrame
42
+
... ...
@@ -0,0 +1,16 @@
1
+/* BlinkenLib
2
+ * version 0.1 date 2004-11-25
3
+ * Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info>
4
+ * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
5
+ * a blinkenarea.org project
6
+ * powered by eventphone.de
7
+ */
8
+
9
+#ifndef INC_BlinkenLib
10
+#define INC_BlinkenLib
11
+
12
+#include "BlinkenMovie.h"
13
+#include "BlinkenFrame.h"
14
+
15
+#endif //#ifndef INC_BlinkenLib
16
+
... ...
@@ -0,0 +1,1606 @@
1
+/* BlinkenLib
2
+ * version 0.1 date 2004-11-25
3
+ * Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info>
4
+ * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
5
+ * a blinkenarea.org project
6
+ * powered by eventphone.de
7
+ */
8
+
9
+#include <stdio.h>
10
+#include <stdlib.h>
11
+#include <string.h>
12
+
13
+#include "BlinkenConstants.h"
14
+#include "BlinkenFrame.h"
15
+#include "BlinkenMovie.h"
16
+#include "Tools.h"
17
+
18
+struct sBlinkenMovie
19
+{
20
+  int height;
21
+  int width;
22
+  int channels;
23
+  int maxval;
24
+  int infoCnt;
25
+  char * * * pppInfos;
26
+  int frameCnt;
27
+  stBlinkenFrame * * ppFrames;
28
+};
29
+
30
+stBlinkenMovie * BlinkenMovieNew( int height, int width, int channels, int maxval )
31
+{
32
+  stBlinkenMovie * pMovie;
33
+
34
+  if( height < BlinkenHeightMin ) height = BlinkenHeightMin;
35
+  if( height > BlinkenHeightMax ) height = BlinkenHeightMax;
36
+  if( width < BlinkenWidthMin ) width = BlinkenWidthMin;
37
+  if( width > BlinkenWidthMax ) width = BlinkenWidthMax;
38
+  if( channels < BlinkenChannelsMin ) channels = BlinkenChannelsMin;
39
+  if( channels > BlinkenChannelsMax ) channels = BlinkenMaxvalMax;
40
+  if( maxval < BlinkenMaxvalMin ) maxval = BlinkenMaxvalMin;
41
+  if( maxval > BlinkenMaxvalMax ) maxval = BlinkenMaxvalMax;
42
+
43
+  pMovie = (stBlinkenMovie *)malloc( sizeof( stBlinkenMovie ) );
44
+  if( pMovie == NULL )
45
+    return NULL;
46
+
47
+  pMovie->height = height;
48
+  pMovie->width = width;
49
+  pMovie->channels = channels;
50
+  pMovie->maxval = maxval;
51
+  pMovie->infoCnt = 0;
52
+  pMovie->pppInfos = (char * * *)malloc2D( 0, 2, sizeof( char * ) );
53
+  if( pMovie->pppInfos == NULL )
54
+  {
55
+    free( pMovie );
56
+    return NULL;
57
+  }
58
+  pMovie->frameCnt = 0;
59
+  pMovie->ppFrames = (stBlinkenFrame * *)malloc1D( 0, sizeof( stBlinkenFrame * ) );
60
+  if( pMovie->ppFrames == NULL )
61
+  {
62
+    free( pMovie->pppInfos );
63
+    free( pMovie );
64
+    return NULL;
65
+  }
66
+
67
+  return pMovie;
68
+}
69
+
70
+stBlinkenMovie * BlinkenMovieClone( stBlinkenMovie * pSrcMovie )
71
+{
72
+  stBlinkenMovie * pMovie;
73
+  int i;
74
+
75
+  pMovie = BlinkenMovieNew( pSrcMovie->height, pSrcMovie->width, pSrcMovie->channels, pSrcMovie->maxval );
76
+  if( pMovie == NULL )
77
+    return NULL;
78
+
79
+  for( i = 0; i < pSrcMovie->infoCnt; i++ )
80
+    BlinkenMovieAppendInfo( pMovie, pSrcMovie->pppInfos[i][0], pSrcMovie->pppInfos[i][1] );
81
+
82
+  for( i = 0; i < pSrcMovie->frameCnt; i++ )
83
+    BlinkenMovieAppendFrame( pMovie, BlinkenFrameClone( pSrcMovie->ppFrames[i] ) );
84
+
85
+  return pMovie;
86
+}
87
+
88
+void BlinkenMovieFree( stBlinkenMovie * pMovie )
89
+{
90
+  int i;
91
+
92
+  if( pMovie == NULL )
93
+    return;
94
+
95
+  for( i = 0; i < pMovie->infoCnt; i++ )
96
+  {
97
+    free( pMovie->pppInfos[i][0] );
98
+    free( pMovie->pppInfos[i][1] );
99
+  }
100
+  free( pMovie->pppInfos );
101
+
102
+  for( i = 0; i < pMovie->frameCnt; i++ )
103
+    BlinkenFrameFree( pMovie->ppFrames[i] );
104
+  free( pMovie->ppFrames );
105
+
106
+  free( pMovie );
107
+}
108
+
109
+int BlinkenMovieGetHeight( stBlinkenMovie * pMovie )
110
+{
111
+  if( pMovie == NULL )
112
+    return 0;
113
+
114
+  return pMovie->height;
115
+}
116
+
117
+int BlinkenMovieGetWidth( stBlinkenMovie * pMovie )
118
+{
119
+  if( pMovie == NULL )
120
+    return 0;
121
+
122
+  return pMovie->width;
123
+}
124
+
125
+int BlinkenMovieGetChannels( stBlinkenMovie * pMovie )
126
+{
127
+  if( pMovie == NULL )
128
+    return 0;
129
+
130
+  return pMovie->channels;
131
+}
132
+
133
+int BlinkenMovieGetMaxval( stBlinkenMovie * pMovie )
134
+{
135
+  if( pMovie == NULL )
136
+    return 0;
137
+
138
+  return pMovie->maxval;
139
+}
140
+
141
+int BlinkenMovieGetDuration( stBlinkenMovie * pMovie )
142
+{
143
+  int i, duration;
144
+
145
+  if( pMovie == NULL )
146
+    return 0;
147
+
148
+  duration = 0;
149
+  for( i = 0; i < pMovie->frameCnt; i++ )
150
+    duration += BlinkenFrameGetDuration( pMovie->ppFrames[i] );
151
+  return duration;
152
+}
153
+
154
+int BlinkenMovieGetInfoCnt( stBlinkenMovie * pMovie )
155
+{
156
+  if( pMovie == NULL )
157
+    return 0;
158
+
159
+  return pMovie->infoCnt;
160
+}
161
+
162
+char * BlinkenMovieGetInfoType( stBlinkenMovie * pMovie, int infoNo )
163
+{
164
+  if( pMovie == NULL || pMovie->infoCnt < 1 )
165
+    return "";
166
+
167
+  if( infoNo < 0 ) infoNo = 0;
168
+  if( infoNo >= pMovie->infoCnt ) infoNo = pMovie->infoCnt - 1;
169
+  return pMovie->pppInfos[infoNo][0];
170
+}
171
+
172
+char * BlinkenMovieGetInfoData( stBlinkenMovie * pMovie, int infoNo )
173
+{
174
+  if( pMovie == NULL || pMovie->infoCnt < 1 )
175
+    return "";
176
+
177
+  if( infoNo < 0 ) infoNo = 0;
178
+  if( infoNo >= pMovie->infoCnt ) infoNo = pMovie->infoCnt - 1;
179
+  return pMovie->pppInfos[infoNo][1];
180
+}
181
+
182
+void BlinkenMovieSetInfo( stBlinkenMovie * pMovie, int infoNo, char * pInfoType, char * pInfoData )
183
+{
184
+  char * pType, * pData;
185
+
186
+  if( pMovie == NULL || infoNo < 0 || infoNo >= pMovie->infoCnt )
187
+    return;
188
+
189
+  pType = strdup( pInfoType );
190
+  if( pType == NULL )
191
+    return;
192
+  pData = strdup( pInfoData );
193
+  if( pData == NULL )
194
+  {
195
+    free( pType );
196
+    return;
197
+  }
198
+
199
+  free( pMovie->pppInfos[infoNo][0] );
200
+  pMovie->pppInfos[infoNo][0] = pType;
201
+  free( pMovie->pppInfos[infoNo][1] );
202
+  pMovie->pppInfos[infoNo][1] = pData;
203
+}
204
+
205
+void BlinkenMovieInsertInfo( stBlinkenMovie * pMovie, int infoNo, char * pInfoType, char * pInfoData )
206
+{
207
+  char * * * pppNewInfos, * pType, * pData;
208
+  int i;
209
+
210
+  if( pMovie == NULL || infoNo < 0 || infoNo > pMovie->infoCnt )
211
+    return;
212
+
213
+  pppNewInfos = (char * * *)malloc2D( pMovie->infoCnt + 1, 2, sizeof( char * ) );
214
+  if( pppNewInfos == NULL )
215
+    return;
216
+
217
+  pType = strdup( pInfoType );
218
+  if( pType == NULL )
219
+  {
220
+    free( pppNewInfos );
221
+    return;
222
+  }
223
+  pData = strdup( pInfoData );
224
+  if( pData == NULL )
225
+  {
226
+    free( pppNewInfos );
227
+    free( pType );
228
+    return;
229
+  }
230
+
231
+  for( i = 0; i < infoNo; i++ )
232
+  {
233
+    pppNewInfos[i][0] = pMovie->pppInfos[i][0];
234
+    pppNewInfos[i][1] = pMovie->pppInfos[i][1];
235
+  }
236
+
237
+  pppNewInfos[infoNo][0] = pType;
238
+  pppNewInfos[infoNo][1] = pData;
239
+
240
+  for( i = infoNo; i < pMovie->infoCnt; i++ )
241
+  {
242
+    pppNewInfos[i+1][0] = pMovie->pppInfos[i][0];
243
+    pppNewInfos[i+1][1] = pMovie->pppInfos[i][1];
244
+  }
245
+
246
+  free( pMovie->pppInfos );
247
+  pMovie->pppInfos = pppNewInfos;
248
+  pMovie->infoCnt++;
249
+}
250
+
251
+void BlinkenMovieAppendInfo( stBlinkenMovie * pMovie, char * pInfoType, char * pInfoData )
252
+{
253
+  if( pMovie == NULL )
254
+    return;
255
+
256
+  BlinkenMovieInsertInfo( pMovie, pMovie->infoCnt, pInfoType, pInfoData );
257
+}
258
+
259
+void BlinkenMovieDeleteInfo( stBlinkenMovie * pMovie, int infoNo )
260
+{
261
+  char * * * pppNewInfos;
262
+  int i;
263
+
264
+  if( pMovie == NULL || infoNo < 0 || infoNo >= pMovie->infoCnt )
265
+    return;
266
+
267
+  pppNewInfos = (char * * *)malloc2D( pMovie->infoCnt - 1, 2, sizeof( char * ) );
268
+  if( pppNewInfos == NULL )
269
+    return;
270
+
271
+  for( i = 0; i < infoNo; i++ )
272
+  {
273
+    pppNewInfos[i][0] = pMovie->pppInfos[i][0];
274
+    pppNewInfos[i][1] = pMovie->pppInfos[i][1];
275
+  }
276
+
277
+  free( pMovie->pppInfos[infoNo][0] );
278
+  free( pMovie->pppInfos[infoNo][1] );
279
+
280
+  for( i = infoNo; i < pMovie->infoCnt - 1; i++ )
281
+  {
282
+    pppNewInfos[i][0] = pMovie->pppInfos[i+1][0];
283
+    pppNewInfos[i][1] = pMovie->pppInfos[i+1][1];
284
+  }
285
+
286
+  free( pMovie->pppInfos );
287
+  pMovie->pppInfos = pppNewInfos;
288
+  pMovie->infoCnt--;
289
+}
290
+
291
+void BlinkenMovieDeleteInfos( stBlinkenMovie * pMovie )
292
+{
293
+  char * * * pppNewInfos;
294
+  int i;
295
+
296
+  if( pMovie == NULL )
297
+    return;
298
+
299
+  pppNewInfos = (char * * *)malloc2D( 0, 2, sizeof( char * ) );
300
+  if( pppNewInfos == NULL )
301
+    return;
302
+
303
+  for( i = 0; i < pMovie->infoCnt; i++ )
304
+  {
305
+    free( pMovie->pppInfos[i][0] );
306
+    free( pMovie->pppInfos[i][1] );
307
+  }
308
+
309
+  free( pMovie->pppInfos );
310
+  pMovie->pppInfos = pppNewInfos;
311
+  pMovie->infoCnt = 0;
312
+}
313
+
314
+int BlinkenMovieGetFrameCnt( stBlinkenMovie * pMovie )
315
+{
316
+  if( pMovie == NULL )
317
+    return 0;
318
+
319
+  return pMovie->frameCnt;
320
+}
321
+
322
+stBlinkenFrame * BlinkenMovieGetFrame( stBlinkenMovie * pMovie, int frameNo )
323
+{
324
+  if( pMovie == NULL || pMovie->frameCnt < 1 )
325
+    return NULL;
326
+
327
+  if( frameNo < 0 ) frameNo = 0;
328
+  if( frameNo >= pMovie->frameCnt ) frameNo = pMovie->frameCnt - 1;
329
+  return pMovie->ppFrames[frameNo];
330
+}
331
+
332
+void BlinkenMovieSetFrame( stBlinkenMovie * pMovie, int frameNo, stBlinkenFrame * pFrame )
333
+{
334
+  if( pMovie == NULL || frameNo < 0 || frameNo >= pMovie->frameCnt )
335
+    return;
336
+
337
+  BlinkenFrameResize( pFrame, pMovie->height, pMovie->width, pMovie->channels, pMovie->maxval );
338
+  pMovie->ppFrames[frameNo] = pFrame;
339
+}
340
+
341
+void BlinkenMovieInsertFrame( stBlinkenMovie * pMovie, int frameNo, stBlinkenFrame * pFrame )
342
+{
343
+  stBlinkenFrame * * ppNewFrames;
344
+  int i;
345
+
346
+  if( pMovie == NULL || frameNo < 0 || frameNo > pMovie->frameCnt )
347
+    return;
348
+
349
+  ppNewFrames = (stBlinkenFrame * *)malloc1D( pMovie->frameCnt + 1, sizeof( stBlinkenFrame * ) );
350
+  if( ppNewFrames == NULL )
351
+    return;
352
+
353
+  for( i = 0; i < frameNo; i++ )
354
+    ppNewFrames[i] = pMovie->ppFrames[i];
355
+
356
+  BlinkenFrameResize( pFrame, pMovie->height, pMovie->width, pMovie->channels, pMovie->maxval );
357
+  ppNewFrames[frameNo] = pFrame;
358
+
359
+  for( i = frameNo; i < pMovie->frameCnt; i++ )
360
+    ppNewFrames[i+1] = pMovie->ppFrames[i];
361
+
362
+  free( pMovie->ppFrames );
363
+  pMovie->ppFrames = ppNewFrames;
364
+  pMovie->frameCnt++;
365
+}
366
+
367
+void BlinkenMovieAppendFrame( stBlinkenMovie * pMovie, stBlinkenFrame * pFrame )
368
+{
369
+  if( pMovie == NULL )
370
+    return;
371
+
372
+  BlinkenMovieInsertFrame( pMovie, pMovie->frameCnt, pFrame );
373
+}
374
+
375
+void BlinkenMovieDeleteFrame( stBlinkenMovie * pMovie, int frameNo )
376
+{
377
+  stBlinkenFrame * * ppNewFrames;
378
+  int i;
379
+
380
+  if( pMovie == NULL || frameNo < 0 || frameNo >= pMovie->frameCnt )
381
+    return;
382
+
383
+  ppNewFrames = (stBlinkenFrame * *)malloc1D( pMovie->frameCnt - 1, sizeof( stBlinkenFrame * ) );
384
+  if( ppNewFrames == NULL )
385
+    return;
386
+
387
+  for( i = 0; i < frameNo; i++ )
388
+    ppNewFrames[i] = pMovie->ppFrames[i];
389
+
390
+  BlinkenFrameFree( pMovie->ppFrames[frameNo] );
391
+
392
+  for( i = frameNo; i < pMovie->frameCnt - 1; i++ )
393
+    ppNewFrames[i] = pMovie->ppFrames[i+1];
394
+
395
+  free( pMovie->ppFrames );
396
+  pMovie->ppFrames = ppNewFrames;
397
+  pMovie->frameCnt--;
398
+}
399
+
400
+void BlinkenMovieDeleteFrames( stBlinkenMovie * pMovie )
401
+{
402
+  stBlinkenFrame * * ppNewFrames;
403
+  int i;
404
+
405
+  if( pMovie == NULL )
406
+    return;
407
+
408
+  ppNewFrames = (stBlinkenFrame * *)malloc1D( 0, sizeof( stBlinkenFrame * ) );
409
+  if( ppNewFrames == NULL )
410
+    return;
411
+
412
+  for( i = 0; i < pMovie->frameCnt; i++ )
413
+    BlinkenFrameFree( pMovie->ppFrames[i] );
414
+
415
+  free( pMovie->ppFrames );
416
+  pMovie->ppFrames = ppNewFrames;
417
+  pMovie->frameCnt = 0;
418
+}
419
+
420
+void BlinkenMovieResize( stBlinkenMovie * pMovie, int height, int width, int channels, int maxval )
421
+{
422
+  int i;
423
+
424
+  if( pMovie == NULL )
425
+    return;
426
+
427
+  if( height < BlinkenHeightMin ) height = BlinkenHeightMin;
428
+  if( height > BlinkenHeightMax ) height = BlinkenHeightMax;
429
+  if( width < BlinkenWidthMin ) width = BlinkenWidthMin;
430
+  if( width > BlinkenWidthMax ) width = BlinkenWidthMax;
431
+  if( channels < BlinkenChannelsMin ) channels = BlinkenChannelsMin;
432
+  if( channels > BlinkenChannelsMax ) channels = BlinkenMaxvalMax;
433
+  if( maxval < BlinkenMaxvalMin ) maxval = BlinkenMaxvalMin;
434
+  if( maxval > BlinkenMaxvalMax ) maxval = BlinkenMaxvalMax;
435
+
436
+  pMovie->height = height;
437
+  pMovie->width = width;
438
+  pMovie->channels = channels;
439
+  pMovie->maxval = maxval;
440
+
441
+  for( i = 0; i < pMovie->frameCnt; i++ )
442
+    BlinkenFrameResize( pMovie->ppFrames[i], height, width, channels, maxval );
443
+}
444
+
445
+void BlinkenMovieScale( stBlinkenMovie * pMovie, int height, int width )
446
+{
447
+  int i;
448
+
449
+  if( pMovie == NULL )
450
+    return;
451
+
452
+  if( height < BlinkenHeightMin ) height = BlinkenHeightMin;
453
+  if( height > BlinkenHeightMax ) height = BlinkenHeightMax;
454
+  if( width < BlinkenWidthMin ) width = BlinkenWidthMin;
455
+  if( width > BlinkenWidthMax ) width = BlinkenWidthMax;
456
+
457
+  pMovie->height = height;
458
+  pMovie->width = width;
459
+
460
+  for( i = 0; i < pMovie->frameCnt; i++ )
461
+    BlinkenFrameScale( pMovie->ppFrames[i], height, width );
462
+}
463
+
464
+char * BlinkenMovieToString( stBlinkenMovie * pMovie )
465
+{
466
+  char * * strs, * str, * ptr;
467
+  int i, size;
468
+
469
+  if( pMovie == NULL )
470
+    return NULL;
471
+
472
+  strs = (char * *)malloc1D( pMovie->frameCnt, sizeof( char * ) );
473
+  if( strs == NULL )
474
+    return NULL;
475
+
476
+  for( i = 0; i < pMovie->frameCnt; i++ )
477
+  {
478
+    strs[i] = BlinkenFrameToString( pMovie->ppFrames[i] );
479
+    if( strs[i] == NULL )
480
+    {
481
+      for( i--; i >= 0; i-- )
482
+        free( strs[i] );
483
+      free( strs );
484
+      return NULL;
485
+    }
486
+  }
487
+
488
+  size = 128;
489
+  for( i = 0; i < pMovie->infoCnt; i++ )
490
+    size += strlen( pMovie->pppInfos[i][0] ) + strlen( pMovie->pppInfos[i][1] ) + 8;
491
+  for( i = 0; i < pMovie->frameCnt; i++ )
492
+    size += strlen( strs[i] ) + 32;
493
+
494
+  str = (char *)malloc( size );
495
+  if( str == NULL )
496
+  {
497
+    for( i = 0; i < pMovie->frameCnt; i++ )
498
+      free( strs[i] );
499
+    free( strs );
500
+    return NULL;
501
+  }
502
+
503
+  ptr = str;
504
+
505
+  sprintf( ptr, "BlinkenMovie %ux%u-%u/%u\n", pMovie->width, pMovie->height, pMovie->channels, pMovie->maxval );
506
+  ptr += strlen( ptr );
507
+
508
+  for( i = 0; i < pMovie->infoCnt; i++ )
509
+  {
510
+    sprintf( ptr, "%s = %s\n", pMovie->pppInfos[i][0], pMovie->pppInfos[i][1] );
511
+    ptr += strlen( ptr );
512
+  }
513
+
514
+  for( i = 0; i < pMovie->frameCnt; i++ )
515
+  {
516
+    sprintf( ptr, "frame %u\n%s", i, strs[i] );
517
+    ptr += strlen( ptr );
518
+    free( strs[i] );
519
+  }
520
+  free( strs );
521
+
522
+  return str;  
523
+}
524
+
525
+stBlinkenMovie * BlinkenMovieLoadBlm( char * pFilename )
526
+{
527
+  FILE * pFile;
528
+  stBlinkenMovie * pMovie;
529
+  stBlinkenFrame * pFrame;
530
+  int width, height, y, x, chr, duration;
531
+  char infoType[256], infoData[1024], pixel[2];
532
+
533
+  if( pFilename == NULL )
534
+    return NULL;
535
+
536
+  //open file
537
+  pFile = fopen( pFilename, "rt" );
538
+
539
+  //read magic and size
540
+  if( fscanf( pFile, " # BlinkenLights Movie %ux%u", &width, &height ) != 2 )
541
+  {
542
+    fclose( pFile );
543
+    return NULL;
544
+  }
545
+
546
+  //allocate a new movie
547
+  pMovie = BlinkenMovieNew( height, width, 1, 1 );
548
+  if( pMovie == NULL )
549
+  {
550
+    fclose( pFile );
551
+    return NULL;
552
+  }
553
+
554
+  //no frame yet
555
+  pFrame = NULL;
556
+  y = 0;
557
+
558
+  //read frames
559
+  while( ! feof( pFile ) )
560
+  {
561
+    //skip rest of previous line (including newline)
562
+    while( (chr = fgetc( pFile )) != '\n' && chr != EOF );
563
+
564
+    //info line
565
+    if( fscanf( pFile, " # %255[A-Za-z0-9] %*[=:] %1023[^\n]", infoType, infoData ) == 2 )
566
+    {
567
+      BlinkenMovieAppendInfo( pMovie, infoType, infoData );
568
+    }
569
+
570
+    //start of frame
571
+    else if( fscanf( pFile, " @ %u", &duration ) == 1 )
572
+    {
573
+      //create new frame and append it to movie
574
+      pFrame = BlinkenFrameNew( height, width, 1, 1, duration );
575
+      if( pFrame != NULL )
576
+      {
577
+        BlinkenFrameClear( pFrame );
578
+        BlinkenMovieAppendFrame( pMovie, pFrame );
579
+        y = 0;
580
+      }
581
+    }
582
+
583
+    //data line
584
+    else if( fscanf( pFile, "%1[01]", pixel ) == 1 )
585
+    {
586
+      if( pFrame != NULL )
587
+      {
588
+        for( x = 0; ; x++ )
589
+        {
590
+          BlinkenFrameSetPixel( pFrame, y, x, 0, pixel[0] == '1' ? 1 : 0 ); //set pixel
591
+          if( fscanf( pFile, "%1[01]", pixel ) != 1 ) //read next pixel
592
+            break;
593
+        }  
594
+        y++; //next row
595
+      }
596
+    }
597
+
598
+  } //while( ! feof( pFile ) )
599
+
600
+  //close file
601
+  fclose( pFile );
602
+
603
+  return pMovie;
604
+}
605
+
606
+stBlinkenMovie * BlinkenMovieLoadBmm( char * pFilename )
607
+{
608
+  FILE * pFile;
609
+  stBlinkenMovie * pMovie;
610
+  stBlinkenFrame * pFrame;
611
+  int width, height, y, x, chr, duration, val;
612
+  char infoType[256], infoData[1024], pixel[8];
613
+
614
+  if( pFilename == NULL )
615
+    return NULL;
616
+
617
+  //open file
618
+  pFile = fopen( pFilename, "rt" );
619
+
620
+  //read magic and size
621
+  if( fscanf( pFile, " # BlinkenMini Movie %ux%u", &width, &height ) != 2 )
622
+  {
623
+    fclose( pFile );
624
+    return NULL;
625
+  }
626
+
627
+  //allocate a new movie
628
+  pMovie = BlinkenMovieNew( height, width, 1, 255 );
629
+  if( pMovie == NULL )
630
+  {
631
+    fclose( pFile );
632
+    return NULL;
633
+  }
634
+
635
+  //no frame yet
636
+  pFrame = NULL;
637
+  y = 0;
638
+
639
+  //read frames
640
+  while( ! feof( pFile ) )
641
+  {
642
+    //skip rest of previous line (including newline)
643
+    while( (chr = fgetc( pFile )) != '\n' && chr != EOF );
644
+
645
+    //info line
646
+    if( fscanf( pFile, " # %255[A-Za-z0-9] %*[=:] %1023[^\n]", infoType, infoData ) == 2 )
647
+    {
648
+      BlinkenMovieAppendInfo( pMovie, infoType, infoData );
649
+    }
650
+
651
+    //start of frame
652
+    else if( fscanf( pFile, " @ %u", &duration ) == 1 )
653
+    {
654
+      //create new frame and append it to movie
655
+      pFrame = BlinkenFrameNew( height, width, 1, 255, duration );
656
+      if( pFrame != NULL )
657
+      {
658
+        BlinkenFrameClear( pFrame );
659
+        BlinkenMovieAppendFrame( pMovie, pFrame );
660
+        y = 0;
661
+      }
662
+    }
663
+
664
+    //data line
665
+    else if( fscanf( pFile, "%7[0-9A-FXa-fx]", pixel ) == 1 )
666
+    {
667
+      if( pFrame != NULL )
668
+      {
669
+        for( x = 0; ; x++ )
670
+        {
671
+          if( sscanf( pixel, "%i", &val ) != 1 ) //convert pixel to number
672
+            break;
673
+          BlinkenFrameSetPixel( pFrame, y, x, 0, (unsigned char)val ); //set pixel
674
+          fscanf( pFile, "%*[ \t]" ); //kill space
675
+          if( fscanf( pFile, "%7[0-9A-FXa-fx]", pixel ) != 1 ) //read next pixel
676
+            break;
677
+        }  
678
+        y++; //next row
679
+      }
680
+    }
681
+
682
+  } //while( ! feof( pFile ) )
683
+
684
+  //close file
685
+  fclose( pFile );
686
+
687
+  return pMovie;
688
+}
689
+
690
+stBlinkenMovie * BlinkenMovieLoadBml( char * pFilename )
691
+{
692
+  FILE * pFile;
693
+  stBlinkenMovie * pMovie;
694
+  stBlinkenFrame * pFrame;
695
+  int width, height, channels, bits, maxval, chrs, y, x, c, duration, val;
696
+  char buffer[2048], infoType[256], infoData[1024], pixelFormat[16], pixel[8], * ptr, chr;
697
+
698
+  if( pFilename == NULL )
699
+    return NULL;
700
+
701
+  //open file
702
+  pFile = fopen( pFilename, "rt" );
703
+
704
+  //no movie yet - blm tag not yet found
705
+  pMovie = NULL;
706
+
707
+  //no frame yet
708
+  pFrame = NULL;
709
+  y = 0;
710
+
711
+  //read tags
712
+  maxval = 0;
713
+  while( ! feof( pFile ) )
714
+  {
715
+
716
+    //skip to just before beginning of next tag
717
+    fscanf( pFile, "%*[^<]" );
718
+    //skip beginning character of next tag
719
+    if( fgetc( pFile ) != '<' )
720
+      //end loop (no more tags)
721
+      break;
722
+
723
+    //no blm tag yet
724
+    if( pMovie == NULL )
725
+    {
726
+
727
+      //blm tag
728
+      if( fscanf( pFile, "blm%2047[^>]", buffer ) == 1 )
729
+      {
730
+        //get attributes
731
+        width = 0;
732
+        height = 0;
733
+        channels = 0;
734
+        bits = 0;
735
+        maxval = 0;
736
+        if( (ptr = strstr( buffer, "height=\"" )) != NULL ) //height
737
+          sscanf( ptr+8, "%u", &height );
738
+        if( (ptr = strstr( buffer, "width=\"" )) != NULL ) //width
739
+          sscanf( ptr+7, "%u", &width );
740
+        if( (ptr = strstr( buffer, "channels=\"" )) != NULL ) //channels
741
+          sscanf( ptr+10, "%u", &channels );
742
+        if( (ptr = strstr( buffer, "bits=\"" )) != NULL ) //bits
743
+          sscanf( ptr+6, "%u", &bits );
744
+        maxval = (1 << bits) - 1; //maxval
745
+
746
+        //allocate a new movie
747
+        pMovie = BlinkenMovieNew( height, width, channels, maxval );
748
+        if( pMovie == NULL )
749
+        {
750
+          fclose( pFile );
751
+          return NULL;
752
+        }
753
+
754
+        //get number of characters per channel
755
+        chrs = (bits + 3) >> 2;
756
+        //get fscanf formart string for reading a pixel
757
+        sprintf( pixelFormat, "%%%d[0-9A-Fa-f]", chrs > 4 ? 5 : chrs ); //read max 5 chars (2 already in use by prefix)
758
+        //initialize pixel buffer with hex prefix
759
+        strcpy( pixel, "0x" );
760
+      }
761
+
762
+    } //if( pMovie == NULL )
763
+
764
+    //blm tag was already found
765
+    else //if( pMovie == NULL )
766
+    {
767
+
768
+      //title tag
769
+      if( fscanf( pFile, "title>%2047[^<]", buffer ) == 1 )
770
+      {
771
+        //add info to movie
772
+        BlinkenMovieAppendInfo( pMovie, "title", buffer );
773
+      }
774
+
775
+      //description tag
776
+      else if( fscanf( pFile, "description>%2047[^<]", buffer ) == 1 )
777
+      {
778
+        //check if generic info
779
+        if( sscanf( buffer, "%255[A-Za-z0-9] %*[=:] %1023[^\n]", infoType, infoData ) == 2 )
780
+          //add info to movie
781
+          BlinkenMovieAppendInfo( pMovie, infoType, infoData );
782
+        else
783
+          //add info to movie
784
+          BlinkenMovieAppendInfo( pMovie, "description", buffer );
785
+      }
786
+
787
+      //creator tag
788
+      else if( fscanf( pFile, "creator>%2047[^<]", buffer ) == 1 )
789
+      {
790
+        //add info to movie
791
+        BlinkenMovieAppendInfo( pMovie, "creator", buffer );
792
+      }
793
+
794
+      //author tag
795
+      else if( fscanf( pFile, "author>%2047[^<]", buffer ) == 1 )
796
+      {
797
+        //add info to movie
798
+        BlinkenMovieAppendInfo( pMovie, "author", buffer );
799
+      }
800
+
801
+      //email tag
802
+      else if( fscanf( pFile, "email>%2047[^<]", buffer ) == 1 )
803
+      {
804
+        //add info to movie
805
+        BlinkenMovieAppendInfo( pMovie, "email", buffer );
806
+      }
807
+
808
+      //url tag
809
+      else if( fscanf( pFile, "url>%2047[^<]", buffer ) == 1 )
810
+      {
811
+        //add info to movie
812
+        BlinkenMovieAppendInfo( pMovie, "url", buffer );
813
+      }
814
+
815
+      //frame tag
816
+      else if( fscanf( pFile, "frame%2047[^>]", buffer ) == 1 )
817
+      {
818
+        //get attributes
819
+        duration = 0;
820
+        if( (ptr = strstr( buffer, "duration=\"" )) != NULL ) //duration
821
+          sscanf( ptr+10, "%u", &duration );
822
+        //create new frame and append it to movie
823
+        pFrame = BlinkenFrameNew( height, width, channels, maxval, duration );
824
+        if( pFrame != NULL )
825
+        {
826
+          BlinkenFrameClear( pFrame );
827
+          BlinkenMovieAppendFrame( pMovie, pFrame );
828
+          y = 0;
829
+        }
830
+      }
831
+
832
+      //row tag
833
+      else if( fscanf( pFile, "row%c", &chr ) == 1 && chr == '>' )
834
+      {
835
+        if( pFrame != NULL )
836
+        {
837
+          //parse row
838
+          for( x = 0; x < width; x++ )
839
+          {
840
+            for( c = 0; c < channels; c++ )
841
+            {
842
+              //read next pixel (one channel of pixel)
843
+              if( fscanf( pFile, pixelFormat, pixel+2 ) != 1 )
844
+              {
845
+                x = width; //also terminate x loop
846
+                break;
847
+              }
848
+              //convert pixel (one channel of pixel) to number
849
+              if( sscanf( pixel, "%i", &val ) != 1 )
850
+              {
851
+                x = width; //also terminate x loop
852
+                break;
853
+              }
854
+              //set pixel (one channel of pixel)
855
+              BlinkenFrameSetPixel( pFrame, y, x, c, (unsigned char)val );
856
+            }
857
+          }
858
+          y++; //next row
859
+        }
860
+      }
861
+
862
+    } //if( pMovie == NULL ) ... else
863
+
864
+  } //while( ! feof( pFile ) )
865
+
866
+  //close file
867
+  fclose( pFile );
868
+
869
+  return pMovie;
870
+}
871
+
872
+/*
873
+
874
+public boolean loadBml( String filename )
875
+{
876
+  Pattern blmTag, blmHeight, blmWidth, blmChannels, blmBits;
877
+  Pattern infoTitle, infoDescription, infoGeneric, infoCreator, infoAuthor, infoEmail, infoUrl;
878
+  Pattern frameTag, frameDuration, rowTag, tag;
879
+  BufferedReader file;
880
+  String line, data, row;
881
+  boolean blmTagFound;
882
+  Matcher matcher, submatcher;
883
+  int height, width, channels, bits, maxval, chrs, duration, y, x, c, len, i, val;
884
+  BlinkenFrame frame;
885
+
886
+  //initialize needed regexp patterns
887
+  blmTag = Pattern.compile( "^[^<]*<blm([^>]*)>" );
888
+  blmHeight = Pattern.compile( "height=\"?([0-9]*)\"?" );
889
+  blmWidth = Pattern.compile( "width=\"?([0-9]*)\"?" );
890
+  blmChannels = Pattern.compile( "channels=\"?([0-9]*)\"?" );
891
+  blmBits = Pattern.compile( "bits=\"?([0-9]*)\"?" );
892
+  infoTitle = Pattern.compile( "^[^<]*<title>([^<]*)</title>" );
893
+  infoDescription = Pattern.compile( "[^<]*<description>([^<]*)</description>" );
894
+  infoGeneric = Pattern.compile( "^([A-Za-z0-9]+)(?: *= *|: *)(.*)" );
895
+  infoCreator = Pattern.compile( "^[^<]*<creator>([^<]*)</creator>" );
896
+  infoAuthor = Pattern.compile( "^[^<]*<author>([^<]*)</author>" );
897
+  infoEmail = Pattern.compile( "^[^<]*<email>([^<]*)</email>" );
898
+  infoUrl = Pattern.compile( "^[^<]*<url>([^<]*)</url>" );
899
+  frameTag = Pattern.compile( "^[^<]*<frame([^>]*)>" );
900
+  frameDuration = Pattern.compile( "duration=\"?([0-9]*)\"?" );
901
+  rowTag = Pattern.compile( "^[^<]*<row>([0-9A-Fa-f]*)</row>" );
902
+  tag = Pattern.compile( "^[^<]*<[^>]*>" );
903
+
904
+  //delete all frames
905
+  deleteInfos( );
906
+  deleteFrames( );
907
+  resize( 0, 0, 0, 0 );
908
+
909
+  //try to read file
910
+  try
911
+  {
912
+    //open file
913
+    file = new BufferedReader( new FileReader( filename ) );
914
+
915
+    //create unused dummy frame for beginning
916
+    frame = new BlinkenFrame( 0, 0, 0, 0, 0 );
917
+    y = 0;
918
+    chrs = 1;
919
+
920
+    //read file
921
+    data = "";
922
+    blmTagFound = false;
923
+    while( (line = file.readLine( )) != null )
924
+    {
925
+      data += " " + line; //add new line to data
926
+
927
+      //match tags
928
+      while( true )
929
+      {
930
+
931
+        //no blm tag yet
932
+        if( ! blmTagFound )
933
+        {
934
+
935
+          //blm tag
936
+          if( (matcher = blmTag.matcher( data )).find( ) )
937
+          {
938
+            //remove matched part
939
+            data = data.substring( matcher.end( ) );
940
+            //get attributes
941
+            width = 0;
942
+            height = 0;
943
+            channels = 0;
944
+            bits = 0;
945
+            maxval = 0;
946
+            if( (submatcher = blmHeight.matcher( matcher.group( 1 ) )).find( ) ) //height
947
+              height = Integer.parseInt( submatcher.group( 1 ) );
948
+            if( (submatcher = blmWidth.matcher( matcher.group( 1 ) )).find( ) ) //width
949
+              width = Integer.parseInt( submatcher.group( 1 ) );
950
+            if( (submatcher = blmChannels.matcher( matcher.group( 1 ) )).find( ) ) //channels
951
+              channels = Integer.parseInt( submatcher.group( 1 ) );
952
+            if( (submatcher = blmBits.matcher( matcher.group( 1 ) )).find( ) ) //bits
953
+              maxval = (1 << (bits = Integer.parseInt( submatcher.group( 1 ) ))) - 1;
954
+            //remember that blm tag was found
955
+            blmTagFound = true;
956
+            //set movie size
957
+            resize( height, width, channels, maxval );
958
+            //get number of characters per channel
959
+            chrs = (bits + 3) >> 2;
960
+          }
961
+
962
+          //unknown tag
963
+          else if( (matcher = tag.matcher( data )).find( ) )
964
+            //remove matched part
965
+            data = data.substring( matcher.end( ) );
966
+
967
+          //nothing matches
968
+          else
969
+            //end loop
970
+            break;
971
+
972
+        } //if( ! blmTagFound )
973
+
974
+        //blm tag was already found
975
+        else
976
+        {
977
+
978
+          //title tag
979
+          if( (matcher = infoTitle.matcher( data )).find( ) )
980
+          {
981
+            //remove matched part
982
+            data = data.substring( matcher.end( ) );
983
+            //add info to movie
984
+            appendInfo( "title", matcher.group( 1 ) );
985
+          }
986
+
987
+          //description tag
988
+          else if( (matcher = infoDescription.matcher( data )).find( ) )
989
+          {
990
+            //remove matched part
991
+            data = data.substring( matcher.end( ) );
992
+            //check if generic info
993
+            if( (submatcher = infoGeneric.matcher( matcher.group( 1 ) )).find( ) )
994
+              //add info to movie
995
+              appendInfo( submatcher.group( 1 ), submatcher.group( 2 ) );
996
+            else
997
+              //add info to movie
998
+              appendInfo( "description", matcher.group( 1 ) );
999
+          }
1000
+
1001
+          //creator tag
1002
+          else if( (matcher = infoCreator.matcher( data )).find( ) )
1003
+          {
1004
+            //remove matched part
1005
+            data = data.substring( matcher.end( ) );
1006
+            //add info to movie
1007
+            appendInfo( "creator", matcher.group( 1 ) );
1008
+          }
1009
+
1010
+          //author tag
1011
+          else if( (matcher = infoAuthor.matcher( data )).find( ) )
1012
+          {
1013
+            //remove matched part
1014
+            data = data.substring( matcher.end( ) );
1015
+            //add info to movie
1016
+            appendInfo( "author", matcher.group( 1 ) );
1017
+          }
1018
+
1019
+          //email tag
1020
+          else if( (matcher = infoEmail.matcher( data )).find( ) )
1021
+          {
1022
+            //remove matched part
1023
+            data = data.substring( matcher.end( ) );
1024
+            //add info to movie
1025
+            appendInfo( "email", matcher.group( 1 ) );
1026
+          }
1027
+
1028
+          //url tag
1029
+          else if( (matcher = infoUrl.matcher( data )).find( ) )
1030
+          {
1031
+            //remove matched part
1032
+            data = data.substring( matcher.end( ) );
1033
+            //add info to movie
1034
+            appendInfo( "url", matcher.group( 1 ) );
1035
+          }
1036
+
1037
+          //frame tag
1038
+          else if( (matcher = frameTag.matcher( data )).find( ) )
1039
+          {
1040
+            //remove matched part
1041
+            data = data.substring( matcher.end( ) );
1042
+            //get attributes
1043
+            duration = 0;
1044
+            if( (submatcher = frameDuration.matcher( matcher.group( 1 ) )).find( ) ) //duration
1045
+              duration = Integer.parseInt( submatcher.group( 1 ) );
1046
+            //create new frame and append it to movie
1047
+            frame = new BlinkenFrame( this.height, this.width, this.channels, this.maxval, duration );
1048
+            frame.clear( );
1049
+            appendFrame( frame );
1050
+            y = 0;
1051
+          }
1052
+
1053
+          //row tag
1054
+          else if( (matcher = rowTag.matcher( data )).find( ) )
1055
+          {
1056
+            //remove matched part
1057
+            data = data.substring( matcher.end( ) );
1058
+            //parse row
1059
+            row = matcher.group( 1 );
1060
+            len = row.length( );
1061
+            i = 0;
1062
+            for( x = 0; x < this.width && i + chrs <= len; x++ )
1063
+            {
1064
+              for( c = 0; c < this.channels && i + chrs <= len; c++, i += chrs )
1065
+              {
1066
+                val = Integer.parseInt( row.substring( i, i + chrs ), 0x10 );
1067
+                frame.setPixel( y, x, c, (byte)val ); //set pixel
1068
+              }
1069
+            }
1070
+            y++; //next row
1071
+          }
1072
+
1073
+          //unknown tag
1074
+          else if( (matcher = tag.matcher( data )).find( ) )
1075
+            //remove matched part
1076
+            data = data.substring( matcher.end( ) );
1077
+
1078
+          //nothing matches
1079
+          else
1080
+            //end loop
1081
+            break;
1082
+
1083
+        } //if( ! blmTagFound ) ... else
1084
+
1085
+      } //while( true )
1086
+
1087
+    } //while( (line = ...
1088
+
1089
+    //close file
1090
+    file.close( );
1091
+
1092
+    //success
1093
+    return true;
1094
+  }
1095
+  catch( IOException e ) { }
1096
+
1097
+  //some error
1098
+  return false;
1099
+}
1100
+
1101
+*/
1102
+
1103
+stBlinkenMovie * BlinkenMovieLoadBbm( char * pFilename )
1104
+{
1105
+  FILE * pFile;
1106
+  stBlinkenMovie * pMovie;
1107
+  stBlinkenFrame * pFrame;
1108
+  unsigned char header[24], subHeader[6], frameStartMarker[4];
1109
+  unsigned long headerMagic, headerFrameCnt, headerDuration, headerFramePtr;
1110
+  unsigned short headerHeight, headerWidth, headerChannels, headerMaxval;
1111
+  unsigned long subHeaderMagic, frameStartMarkerMagic;
1112
+  unsigned short subHeaderSize;
1113
+  unsigned char * pInfoHeader, * pInfoHeaderX, * pFrameData;
1114
+  int len, duration, y, x, c, i;
1115
+
1116
+  if( pFilename == NULL )
1117
+    return NULL;
1118
+
1119
+  //open file
1120
+  pFile = fopen( pFilename, "rb" );
1121
+
1122
+  //read header
1123
+  if( fread( header, 1, 24, pFile ) != 24 )
1124
+  {
1125
+    fclose( pFile );
1126
+    return NULL;
1127
+  }
1128
+  headerMagic = (unsigned long)header[0] << 24 | (unsigned long)header[1] << 16 | (unsigned long)header[2] << 8 | (unsigned long)header[3];
1129
+  headerHeight = (unsigned short)header[4] << 8 | (unsigned short)header[5];
1130
+  headerWidth = (unsigned short)header[6] << 8 | (unsigned short)header[7];
1131
+  headerChannels = (unsigned short)header[8] << 8 | (unsigned short)header[9];
1132
+  headerMaxval = (unsigned short)header[10] << 8 | (unsigned short)header[11];
1133
+  headerFrameCnt = (unsigned long)header[12] << 24 | (unsigned long)header[13] << 16 | (unsigned long)header[14] << 8 | (unsigned long)header[15];
1134
+  headerDuration = (unsigned long)header[16] << 24 | (unsigned long)header[17] << 16 | (unsigned long)header[18] << 8 | (unsigned long)header[19];
1135
+  headerFramePtr = (unsigned long)header[20] << 24 | (unsigned long)header[21] << 16 | (unsigned long)header[22] << 8 | (unsigned long)header[23];
1136
+  //check magic
1137
+  if( headerMagic != 0x23542666 )
1138
+  {
1139
+    fclose( pFile );
1140
+    return NULL;
1141
+  }
1142
+
1143
+  //allocate a new movie
1144
+  pMovie = BlinkenMovieNew( headerHeight, headerWidth, headerChannels, headerMaxval );
1145
+  if( pMovie == NULL )
1146
+  {
1147
+    fclose( pFile );
1148
+    return NULL;
1149
+  }
1150
+
1151
+  //read subheaders
1152
+  while( ftell( pFile ) + 6 <= (long)headerFramePtr )
1153
+  {
1154
+    if( fread( subHeader, 1, 6, pFile ) != 6 )
1155
+    {
1156
+      BlinkenMovieFree( pMovie );
1157
+      fclose( pFile );
1158
+      return NULL;
1159
+    }
1160
+    subHeaderMagic = (unsigned long)subHeader[0] << 24 | (unsigned long)subHeader[1] << 16 | (unsigned long)subHeader[2] << 8 | (unsigned long)subHeader[3];
1161
+    subHeaderSize = (unsigned short)subHeader[4] << 8 | (unsigned short)subHeader[5];
1162
+
1163
+    //header fits into gap to frame start
1164
+    if( subHeaderSize >= 6 && ftell( pFile ) + subHeaderSize - 6 <= (long)headerFramePtr )
1165
+    {
1166
+      //info header
1167
+      if( subHeaderMagic == 0x696E666F ) //'i' 'n' 'f' 'o'
1168
+      {
1169
+        //read rest of info header
1170
+        pInfoHeader = (unsigned char *)malloc( subHeaderSize - 6 );
1171
+        if( pInfoHeader == NULL )
1172
+        {
1173
+          BlinkenMovieFree( pMovie );
1174
+          fclose( pFile );
1175
+          return NULL;
1176
+        }
1177
+        if( fread( pInfoHeader, 1, subHeaderSize - 6, pFile ) != (unsigned short)(subHeaderSize - 6) )
1178
+        {
1179
+          free( pInfoHeader );
1180
+          BlinkenMovieFree( pMovie );
1181
+          fclose( pFile );
1182
+          return NULL;
1183
+        }
1184
+        //parse information
1185
+        if( (pInfoHeaderX = memchr( pInfoHeader, 0, subHeaderSize - 6 )) != NULL )
1186
+        {
1187
+          pInfoHeaderX++;
1188
+          len = pInfoHeaderX - pInfoHeader;
1189
+          if( memchr( pInfoHeaderX, 0, subHeaderSize - 6 - len ) != NULL )
1190
+            BlinkenMovieAppendInfo( pMovie, pInfoHeader, pInfoHeaderX );
1191
+        }
1192
+        free( pInfoHeader );
1193
+      }
1194
+
1195
+      //unknown subHeader
1196
+      else
1197
+        //skip
1198
+        fseek( pFile, subHeaderSize - 6, SEEK_CUR );
1199
+
1200
+    } //if( ftell( pFile ) ...
1201
+  } //while( ftell( pFile ) ...
1202
+
1203
+  //seek to start of frames
1204
+  fseek( pFile, headerFramePtr, SEEK_SET );
1205
+
1206
+  //read frame start marker
1207
+  if( fread( frameStartMarker, 1, 4, pFile ) != 4 )
1208
+  {
1209
+    BlinkenMovieFree( pMovie );
1210
+    fclose( pFile );
1211
+    return NULL;
1212
+  }
1213
+  frameStartMarkerMagic = (unsigned long)frameStartMarker[0] << 24 | (unsigned long)frameStartMarker[1] << 16 | (unsigned long)frameStartMarker[2] << 8 | (unsigned long)frameStartMarker[3];
1214
+  if( frameStartMarkerMagic != 0x66726D73 ) //'f' 'r' 'm' 's'
1215
+  {
1216
+    BlinkenMovieFree( pMovie );
1217
+    fclose( pFile );
1218
+    return NULL;
1219
+  }
1220
+
1221
+  //allocate buffer for frame data
1222
+  len = 2 + headerHeight * headerWidth * headerChannels;
1223
+  pFrameData = (unsigned char *)malloc( len );
1224
+  if( pFrameData == NULL )
1225
+  {
1226
+    BlinkenMovieFree( pMovie );
1227
+    fclose( pFile );
1228
+    return NULL;
1229
+  }
1230
+
1231
+  //read frames
1232
+  for( ; ; )
1233
+  {
1234
+    //read frame
1235
+    if( fread( pFrameData, 1, len, pFile ) != (unsigned int)len )
1236
+      break;
1237
+    duration = (unsigned short)pFrameData[0] << 8 | (unsigned short)pFrameData[1];
1238
+    //build frame and append it to movie
1239
+    pFrame = BlinkenFrameNew( headerHeight, headerWidth, headerChannels, headerMaxval, duration );
1240
+    if( pFrame == NULL )
1241
+      break;
1242
+    i = 2;
1243
+    for( y = 0; y < headerHeight; y++ )
1244
+      for( x = 0; x < headerWidth; x++ )
1245
+        for( c = 0; c < headerChannels; c++, i++ )
1246
+          BlinkenFrameSetPixel( pFrame, y, x, c, pFrameData[i] );
1247
+    BlinkenMovieAppendFrame( pMovie, pFrame );
1248
+
1249
+  } //for( ; ; )
1250
+
1251
+  //free buffer for frame data
1252
+  free( pFrameData );
1253
+
1254
+  //close file
1255
+  fclose( pFile );
1256
+
1257
+  return pMovie;
1258
+}
1259
+
1260
+stBlinkenMovie * BlinkenMovieLoad( char * pFilename )
1261
+{
1262
+  int len;
1263
+
1264
+  if( pFilename == NULL )
1265
+    return NULL;
1266
+
1267
+  len = strlen( pFilename );
1268
+  if( len > 4 && strcmp( pFilename + len - 4, ".blm" ) == 0 )
1269
+    return BlinkenMovieLoadBlm( pFilename );
1270
+  if( len > 4 && strcmp( pFilename + len - 4, ".bmm" ) == 0 )
1271
+    return BlinkenMovieLoadBmm( pFilename );
1272
+  if( len > 4 && strcmp( pFilename + len - 4, ".bml" ) == 0 )
1273
+    return BlinkenMovieLoadBml( pFilename );
1274
+  if( len > 4 && strcmp( pFilename + len - 4, ".bbm" ) == 0 )
1275
+    return BlinkenMovieLoadBbm( pFilename );
1276
+  return NULL;
1277
+}
1278
+
1279
+int BlinkenMovieSaveBlm( stBlinkenMovie * pMovie, char * pFilename )
1280
+{
1281
+  stBlinkenMovie * pOutMovie;
1282
+  FILE * pFile;
1283
+  int i, y, x;
1284
+
1285
+  if( pMovie == NULL || pFilename == NULL )
1286
+    return -1;
1287
+
1288
+  //convert movie to suitable format
1289
+  pOutMovie = BlinkenMovieClone( pMovie );
1290
+  if( pOutMovie == NULL )
1291
+    return -1;
1292
+  BlinkenMovieResize( pOutMovie, pOutMovie->height, pOutMovie->width, 1, 1 );
1293
+
1294
+  //open file
1295
+  pFile = fopen( pFilename, "wt" );
1296
+  if( pFile == NULL )
1297
+  {
1298
+    BlinkenMovieFree( pOutMovie );
1299
+    return -1;
1300
+  }
1301
+
1302
+  //write header line
1303
+  fprintf( pFile, "# BlinkenLights Movie %ux%u\n", pOutMovie->width, pOutMovie->height );
1304
+
1305
+  //write information lines
1306
+  for( i = 0; i < pOutMovie->infoCnt; i++ )
1307
+    fprintf( pFile, "# %s = %s\n", pOutMovie->pppInfos[i][0], pOutMovie->pppInfos[i][1] );
1308
+
1309
+  //write frames
1310
+  for( i = 0; i < pOutMovie->frameCnt; i++ )
1311
+  {
1312
+    fprintf( pFile, "\n@%u\n", BlinkenFrameGetDuration( pOutMovie->ppFrames[i] ) );
1313
+    for( y = 0; y < pOutMovie->height; y++ )
1314
+    {
1315
+      for( x = 0; x < pOutMovie->width; x++ )
1316
+      {
1317
+        if( BlinkenFrameGetPixel( pOutMovie->ppFrames[i], y, x, 0 ) != 0 )
1318
+          fprintf( pFile, "1" );
1319
+        else
1320
+          fprintf( pFile, "0" );
1321
+      }
1322
+      fprintf( pFile, "\n" );
1323
+    }
1324
+  }
1325
+
1326
+  //close file
1327
+  fclose( pFile );
1328
+
1329
+  //free copied movie
1330
+  BlinkenMovieFree( pOutMovie );
1331
+
1332
+  //success
1333
+  return 0;
1334
+}
1335
+
1336
+int BlinkenMovieSaveBmm( stBlinkenMovie * pMovie, char * pFilename )
1337
+{
1338
+  stBlinkenMovie * pOutMovie;
1339
+  FILE * pFile;
1340
+  int i, y, x;
1341
+
1342
+  if( pMovie == NULL || pFilename == NULL )
1343
+    return -1;
1344
+
1345
+  //convert movie to suitable format
1346
+  pOutMovie = BlinkenMovieClone( pMovie );
1347
+  if( pOutMovie == NULL )
1348
+    return -1;
1349
+  BlinkenMovieResize( pOutMovie, pOutMovie->height, pOutMovie->width, 1, 255 );
1350
+
1351
+  //open file
1352
+  pFile = fopen( pFilename, "wt" );
1353
+  if( pFile == NULL )
1354
+  {
1355
+    BlinkenMovieFree( pOutMovie );
1356
+    return -1;
1357
+  }
1358
+
1359
+  //write header line
1360
+  fprintf( pFile, "# BlinkenMini Movie %ux%u\n", pOutMovie->width, pOutMovie->height );
1361
+
1362
+  //write information lines
1363
+  for( i = 0; i < pOutMovie->infoCnt; i++ )
1364
+    fprintf( pFile, "# %s = %s\n", pOutMovie->pppInfos[i][0], pOutMovie->pppInfos[i][1] );
1365
+
1366
+  //write frames
1367
+  for( i = 0; i < pOutMovie->frameCnt; i++ )
1368
+  {
1369
+    fprintf( pFile, "\n@%u\n", BlinkenFrameGetDuration( pOutMovie->ppFrames[i] ) );
1370
+    for( y = 0; y < pOutMovie->height; y++ )
1371
+    {
1372
+      fprintf( pFile, "0x%02X", BlinkenFrameGetPixel( pOutMovie->ppFrames[i], y, 0, 0 ) );
1373
+      for( x = 1; x < pOutMovie->width; x++ )
1374
+        fprintf( pFile, " 0x%02X", BlinkenFrameGetPixel( pOutMovie->ppFrames[i], y, x, 0 ) );
1375
+      fprintf( pFile, "\n" );
1376
+    }
1377
+  }
1378
+
1379
+  //close file
1380
+  fclose( pFile );
1381
+
1382
+  //free copied movie
1383
+  BlinkenMovieFree( pOutMovie );
1384
+
1385
+  //success
1386
+  return 0;
1387
+}
1388
+
1389
+int BlinkenMovieSaveBml( stBlinkenMovie * pMovie, char * pFilename )
1390
+{
1391
+  stBlinkenMovie * pOutMovie;
1392
+  FILE * pFile;
1393
+  int bits, val, i, y, x, c;
1394
+
1395
+  if( pMovie == NULL || pFilename == NULL )
1396
+    return -1;
1397
+
1398
+  //convert movie to suitable format
1399
+  pOutMovie = BlinkenMovieClone( pMovie );
1400
+  if( pOutMovie == NULL )
1401
+    return -1;
1402
+  val = pOutMovie->maxval; //get number of bits
1403
+  for( bits = 0; val != 0; val >>= 1, bits++ );
1404
+  BlinkenMovieResize( pOutMovie, pOutMovie->height, pOutMovie->width, pOutMovie->channels, (1 << bits) - 1 );
1405
+
1406
+  //open file
1407
+  pFile = fopen( pFilename, "wt" );
1408
+  if( pFile == NULL )
1409
+  {
1410
+    BlinkenMovieFree( pOutMovie );
1411
+    return -1;
1412
+  }
1413
+
1414
+  //write header line
1415
+  fprintf( pFile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
1416
+
1417
+  //write blm start tag
1418
+  fprintf( pFile, "<blm width=\"%u\" height=\"%u\" bits=\"%u\" channels=\"%u\">\n",
1419
+           pOutMovie->width, pOutMovie->height, bits, pOutMovie->channels );
1420
+
1421
+  //write information lines
1422
+  fprintf( pFile, "\t<header>\n" );
1423
+  for( i = 0; i < pOutMovie->infoCnt; i++ )
1424
+  {
1425
+    if( strcmp( pOutMovie->pppInfos[i][0], "title" ) == 0 )
1426
+      fprintf( pFile, "\t\t<title>%s</title>\n", pOutMovie->pppInfos[i][1] );
1427
+    else if( strcmp( pOutMovie->pppInfos[i][0], "description" ) == 0 )
1428
+      fprintf( pFile, "\t\t<description>%s</description>\n", pOutMovie->pppInfos[i][1] );
1429
+    else if( strcmp( pOutMovie->pppInfos[i][0], "creator" ) == 0 )
1430
+      fprintf( pFile, "\t\t<creator>%s</creator>\n", pOutMovie->pppInfos[i][1] );
1431
+    else if( strcmp( pOutMovie->pppInfos[i][0], "author" ) == 0)
1432
+      fprintf( pFile, "\t\t<author>%s</author>\n", pOutMovie->pppInfos[i][1] );
1433
+    else if( strcmp( pOutMovie->pppInfos[i][0], "email" ) == 0)
1434
+      fprintf( pFile, "\t\t<email>%s</email>\n", pOutMovie->pppInfos[i][1] );
1435
+    else if( strcmp( pOutMovie->pppInfos[i][0], "url" ) == 0)
1436
+      fprintf( pFile, "\t\t<url>%s</url>\n", pOutMovie->pppInfos[i][1] );
1437
+    else
1438
+      fprintf( pFile, "\t\t<description>%s: %s</description>\n", pOutMovie->pppInfos[i][0], pOutMovie->pppInfos[i][1] );
1439
+  }
1440
+  fprintf( pFile, "\t</header>\n" );
1441
+
1442
+  //write frames
1443
+  for( i = 0; i < pOutMovie->frameCnt; i++ )
1444
+  {
1445
+    fprintf( pFile, "\n\t<frame duration=\"%u\">\n", BlinkenFrameGetDuration( pOutMovie->ppFrames[i] ) );
1446
+    for( y = 0; y < pOutMovie->height; y++ )
1447
+    {
1448
+      fprintf( pFile, "\t\t<row>" );
1449
+      for( x = 0; x < pOutMovie->width; x++ )
1450
+        for( c = 0; c < pOutMovie->channels; c++ )
1451
+          fprintf( pFile, bits > 4 ? "%02X" : "%01X",
1452
+            BlinkenFrameGetPixel( pOutMovie->ppFrames[i], y, x, c ) );
1453
+      fprintf( pFile, "</row>\n" );
1454
+    }
1455
+    fprintf( pFile, "\t</frame>\n" );
1456
+  }
1457
+
1458
+  //write blm end tag
1459
+  fprintf( pFile, "</blm>\n" );
1460
+
1461
+  //close file
1462
+  fclose( pFile );
1463
+
1464
+  //free copied movie
1465
+  BlinkenMovieFree( pOutMovie );
1466
+
1467
+  //success
1468
+  return 0;
1469
+}
1470
+
1471
+int BlinkenMovieSaveBbm( stBlinkenMovie * pMovie, char * pFilename )
1472
+{
1473
+  unsigned char * pFrameData;
1474
+  FILE * pFile;
1475
+  unsigned char header[24], infoHeader[6], framePointer[4], frameStartMarker[4];
1476
+  int duration, len, len0, len1, i, j, y, x, c, val;
1477
+  long pos;
1478
+
1479
+  if( pMovie == NULL || pFilename == NULL )
1480
+    return -1;
1481
+
1482
+  //allocate frame data buffer
1483
+  pFrameData = (unsigned char *)malloc( 2 + pMovie->height * pMovie->width * pMovie->channels );
1484
+  if( pFrameData == NULL )
1485
+    return -1;
1486
+
1487
+  //open file
1488
+  pFile = fopen( pFilename, "wb" );
1489
+  if( pFile == NULL )
1490
+  {
1491
+    free( pFrameData );
1492
+    return -1;
1493
+  }
1494
+
1495
+  //write header
1496
+  header[0] = 0x23; //magic
1497
+  header[1] = 0x54;
1498
+  header[2] = 0x26;
1499
+  header[3] = 0x66;
1500
+  header[4] = (unsigned char)(pMovie->height >> 8);
1501
+  header[5] = (unsigned char)pMovie->height;
1502
+  header[6] = (unsigned char)(pMovie->width >> 8);
1503
+  header[7] = (unsigned char)pMovie->width;
1504
+  header[8] = (unsigned char)(pMovie->channels >> 8);
1505
+  header[9] = (unsigned char)pMovie->channels;
1506
+  header[10] = (unsigned char)(pMovie->maxval >> 8);
1507
+  header[11] = (unsigned char)pMovie->maxval;
1508
+  header[12] = (unsigned char)(pMovie->frameCnt >> 24);
1509
+  header[13] = (unsigned char)(pMovie->frameCnt >> 16);
1510
+  header[14] = (unsigned char)(pMovie->frameCnt >> 8);
1511
+  header[15] = (unsigned char)pMovie->frameCnt;
1512
+  duration = 0;
1513
+  for( i = 0; i < pMovie->frameCnt; i++ )
1514
+    duration += BlinkenFrameGetDuration( pMovie->ppFrames[i] ); 
1515
+  header[16] = (unsigned char)(duration >> 24);
1516
+  header[17] = (unsigned char)(duration >> 16);
1517
+  header[18] = (unsigned char)(duration >> 8);
1518
+  header[19] = (unsigned char)duration;
1519
+  header[20] = 0; //frame pointer is written later
1520
+  header[21] = 0;
1521
+  header[22] = 0;
1522
+  header[23] = 0;
1523
+  fwrite( header, 1, 24, pFile );
1524
+
1525
+  //write information
1526
+  for( i = 0; i < pMovie->infoCnt; i++ )
1527
+  {
1528
+    len0 = strlen( pMovie->pppInfos[i][0] );
1529
+    if( len0 > 32760 )
1530
+      len0 = 32760;
1531
+    len1 = strlen( pMovie->pppInfos[i][1] );
1532
+    if( len1 > 32760 )
1533
+      len1 = 32760;
1534
+    len = 8 + len0 + len1;
1535
+    infoHeader[0] = 0x69; //'i'
1536
+    infoHeader[1] = 0x6E; //'n'
1537
+    infoHeader[2] = 0x66; //'f'
1538
+    infoHeader[3] = 0x6F; //'o'
1539
+    infoHeader[4] = (unsigned char)(len >> 8);
1540
+    infoHeader[5] = (unsigned char)len;
1541
+    fwrite( infoHeader, 1, 6, pFile );
1542
+    fwrite( pMovie->pppInfos[i][0], 1, len0, pFile );
1543
+    fwrite( "\0", 1, 1, pFile );
1544
+    fwrite( pMovie->pppInfos[i][1], 1, len1, pFile );
1545
+    fwrite( "\0", 1, 1, pFile );
1546
+  }
1547
+
1548
+  //write frame pointer
1549
+  pos = ftell( pFile );
1550
+  framePointer[0] = (unsigned char)(pos >> 24);
1551
+  framePointer[1] = (unsigned char)(pos >> 16);
1552
+  framePointer[2] = (unsigned char)(pos >> 8);
1553
+  framePointer[3] = (unsigned char)pos;
1554
+  fseek( pFile, 20, SEEK_SET );
1555
+  fwrite( framePointer, 1, 4, pFile );
1556
+  fseek( pFile, pos, SEEK_SET );
1557
+
1558
+  //write frame start marker
1559
+  frameStartMarker[0] = 0x66; //'f'
1560
+  frameStartMarker[1] = 0x72; //'r'
1561
+  frameStartMarker[2] = 0x6D; //'m'
1562
+  frameStartMarker[3] = 0x73; //'s'
1563
+  fwrite( frameStartMarker, 1, 4, pFile );
1564
+
1565
+  //write frames
1566
+  for( i = 0; i < pMovie->frameCnt; i++ )
1567
+  {
1568
+    val = BlinkenFrameGetDuration( pMovie->ppFrames[i] );
1569
+    pFrameData[0] = (unsigned char)(val >> 8);
1570
+    pFrameData[1] = (unsigned char)val;
1571
+    for( j = 2, y = 0; y < pMovie->height; y++ )
1572
+      for( x = 0; x < pMovie->width; x++ )
1573
+        for( c = 0; c < pMovie->channels; c++, j++ )
1574
+          pFrameData[j] = BlinkenFrameGetPixel( pMovie->ppFrames[i], y, x, c );
1575
+    fwrite( pFrameData, 1, j, pFile );
1576
+  }
1577
+
1578
+  //free frame data buffer
1579
+  free( pFrameData );
1580
+
1581
+  //close file
1582
+  fclose( pFile );
1583
+
1584
+  //success
1585
+  return 0;
1586
+}
1587
+
1588
+int BlinkenMovieSave( stBlinkenMovie * pMovie, char * pFilename )
1589
+{
1590
+  int len;
1591
+
1592
+  if( pMovie == NULL || pFilename == NULL )
1593
+    return -1;
1594
+
1595
+  len = strlen( pFilename );
1596
+  if( len > 4 && strcmp( pFilename + len - 4, ".blm" ) == 0 )
1597
+    return BlinkenMovieSaveBlm( pMovie, pFilename );
1598
+  if( len > 4 && strcmp( pFilename + len - 4, ".bmm" ) == 0 )
1599
+    return BlinkenMovieSaveBmm( pMovie, pFilename );
1600
+  if( len > 4 && strcmp( pFilename + len - 4, ".bml" ) == 0 )
1601
+    return BlinkenMovieSaveBml( pMovie, pFilename );
1602
+  if( len > 4 && strcmp( pFilename + len - 4, ".bbm" ) == 0 )
1603
+    return BlinkenMovieSaveBbm( pMovie, pFilename );
1604
+  return -1;
1605
+}
1606
+
... ...
@@ -0,0 +1,63 @@
1
+/* BlinkenLib
2
+ * version 0.1 date 2004-11-25
3
+ * Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info>
4
+ * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
5
+ * a blinkenarea.org project
6
+ * powered by eventphone.de
7
+ */
8
+
9
+#ifndef INC_BlinkenMovie
10
+#define INC_BlinkenMovie
11
+
12
+#include "BlinkenFrame.h"
13
+
14
+typedef struct sBlinkenMovie stBlinkenMovie;
15
+
16
+stBlinkenMovie * BlinkenMovieNew( int height, int width, int channels, int maxval );
17
+
18
+stBlinkenMovie * BlinkenMovieClone( stBlinkenMovie * pSrcMovie );
19
+
20
+void BlinkenMovieFree( stBlinkenMovie * pMovie );
21
+
22
+int BlinkenMovieGetHeight( stBlinkenMovie * pMovie );
23
+int BlinkenMovieGetWidth( stBlinkenMovie * pMovie );
24
+int BlinkenMovieGetChannels( stBlinkenMovie * pMovie );
25
+int BlinkenMovieGetMaxval( stBlinkenMovie * pMovie );
26
+int BlinkenMovieGetDuration( stBlinkenMovie * pMovie );
27
+
28
+int BlinkenMovieGetInfoCnt( stBlinkenMovie * pMovie );
29
+char * BlinkenMovieGetInfoType( stBlinkenMovie * pMovie, int infoNo );
30
+char * BlinkenMovieGetInfoData( stBlinkenMovie * pMovie, int infoNo );
31
+void BlinkenMovieSetInfo( stBlinkenMovie * pMovie, int infoNo, char * pInfoType, char * pInfoData );
32
+void BlinkenMovieInsertInfo( stBlinkenMovie * pMovie, int infoNo, char * pInfoType, char * pInfoData );
33
+void BlinkenMovieAppendInfo( stBlinkenMovie * pMovie, char * pInfoType, char * pInfoData );
34
+void BlinkenMovieDeleteInfo( stBlinkenMovie * pMovie, int infoNo );
35
+void BlinkenMovieDeleteInfos( stBlinkenMovie * pMovie );
36
+
37
+int BlinkenMovieGetFrameCnt( stBlinkenMovie * pMovie );
38
+stBlinkenFrame * BlinkenMovieGetFrame( stBlinkenMovie * pMovie, int frameNo );
39
+void BlinkenMovieSetFrame( stBlinkenMovie * pMovie, int frameNo, stBlinkenFrame * pFrame );
40
+void BlinkenMovieInsertFrame( stBlinkenMovie * pMovie, int frameNo, stBlinkenFrame * pFrame );
41
+void BlinkenMovieAppendFrame( stBlinkenMovie * pMovie, stBlinkenFrame * pFrame );
42
+void BlinkenMovieDeleteFrame( stBlinkenMovie * pMovie, int frameNo );
43
+void BlinkenMovieDeleteFrames( stBlinkenMovie * pMovie );
44
+
45
+void BlinkenMovieResize( stBlinkenMovie * pMovie, int height, int width, int channels, int maxval );
46
+void BlinkenMovieScale( stBlinkenMovie * pMovie, int height, int width );
47
+
48
+char * BlinkenMovieToString( stBlinkenMovie * pMovie );
49
+
50
+stBlinkenMovie * BlinkenMovieLoadBlm( char * pFilename );
51
+stBlinkenMovie * BlinkenMovieLoadBmm( char * pFilename );
52
+stBlinkenMovie * BlinkenMovieLoadBml( char * pFilename );
53
+stBlinkenMovie * BlinkenMovieLoadBbm( char * pFilename );
54
+stBlinkenMovie * BlinkenMovieLoad( char * pFilename );
55
+
56
+int BlinkenMovieSaveBlm( stBlinkenMovie * pMovie, char * pFilename );
57
+int BlinkenMovieSaveBmm( stBlinkenMovie * pMovie, char * pFilename );
58
+int BlinkenMovieSaveBml( stBlinkenMovie * pMovie, char * pFilename );
59
+int BlinkenMovieSaveBbm( stBlinkenMovie * pMovie, char * pFilename );
60
+int BlinkenMovieSave( stBlinkenMovie * pMovie, char * pFilename );
61
+
62
+#endif //#ifndef INC_BlinkenMovie
63
+
... ...
@@ -0,0 +1,34 @@
1
+# BlinkenLib
2
+# version 0.1 date 2004-11-25
3
+# Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info>
4
+# Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
5
+# a blinkenarea.org project
6
+# powered by eventphone.de
7
+
8
+CC=gcc
9
+CFLAGS=-W -Wall -O2
10
+LFLAGS=
11
+AR=ar
12
+ARFLAGS=cr
13
+
14
+.phony: all clean
15
+
16
+all: BlinkenLib.a BlinkenConv
17
+
18
+BlinkenFrame.o: BlinkenFrame.c BlinkenFrame.h Tools.h
19
+	$(CC) $(CFLAGS) -c -o BlinkenFrame.o BlinkenFrame.c
20
+
21
+BlinkenMovie.o: BlinkenMovie.c BlinkenFrame.h BlinkenMovie.h Tools.h
22
+	$(CC) $(CFLAGS) -c -o BlinkenMovie.o BlinkenMovie.c
23
+
24
+Tools.o: Tools.c Tools.h
25
+	$(CC) $(CFLAGS) -c -o Tools.o Tools.c
26
+
27
+BlinkenLib.a: BlinkenFrame.o BlinkenMovie.o Tools.o
28
+	$(AR) $(ARFLAGS) BlinkenLib.a BlinkenFrame.o BlinkenMovie.o Tools.o
29
+
30
+BlinkenConv: BlinkenConv.c BlinkenMovie.h BlinkenLib.a
31
+	$(CC) $(LFLAGS) -o BlinkenConv BlinkenConv.c BlinkenLib.a
32
+
33
+clean:
34
+	rm -f *.o BlinkenLib.a BlinkenConv
... ...
@@ -0,0 +1,79 @@
1
+/* BlinkenLib
2
+ * version 0.1 date 2004-11-25
3
+ * Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info>
4
+ * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
5
+ * a blinkenarea.org project
6
+ * powered by eventphone.de
7
+ */
8
+
9
+#include <stdlib.h>
10
+
11
+#include "Tools.h"
12
+
13
+void * malloc1D( int count1, int size )
14
+{
15
+  if( count1 < 1 ) count1 = 1;
16
+  if( size < 1 )
17
+    return NULL;
18
+
19
+  return malloc( count1 * size );
20
+}
21
+
22
+void * * malloc2D( int count1, int count2, int size )
23
+{
24
+  int sz, i;
25
+  char * p;
26
+  void * * ptr;
27
+
28
+  if( count1 < 1 ) count1 = 1;
29
+  if( count2 < 1 ) count2 = 1;
30
+  if( size < 1 )
31
+    return NULL;
32
+
33
+  sz = count1 * sizeof( void * ) + count1 * count2 * size;
34
+  p = (char *)malloc( sz );
35
+  if( p == NULL )
36
+    return NULL;
37
+
38
+  ptr = (void * *)p;
39
+  p += count1 * sizeof( void * );
40
+  for( i = 0; i < count1; i++ )
41
+  {
42
+    ptr[i] = (void *)p;
43
+    p += count2 * size;
44
+  }
45
+  return ptr;
46
+}
47
+
48
+void * * * malloc3D( int count1, int count2, int count3, int size )
49
+{
50
+  int sz, i, j;
51
+  char * p;
52
+  void * * * ptr;
53
+
54
+  if( count1 < 1 ) count1 = 1;
55
+  if( count2 < 1 ) count2 = 1;
56
+  if( count3 < 1 ) count3 = 1;
57
+  if( size < 1 )
58
+    return NULL;
59
+
60
+  sz = count1 * sizeof( void * * ) + count1 * count2 * sizeof( void * ) + count1 * count2 * count3 * size;
61
+  p = (char *)malloc( sz );
62
+  if( p == NULL )
63
+    return NULL;
64
+
65
+  ptr = (void * * *)p;
66
+  p += count1 * sizeof( void * * );
67
+  for( i = 0; i < count1; i++ )
68
+  {
69
+    ptr[i] = (void * *)p;
70
+    p += count2 * sizeof( void * );
71
+  }
72
+  for( i = 0; i < count1; i++ )
73
+    for( j = 0; j < count2; j++ )
74
+    {
75
+      ptr[i][j] = (void *)p;
76
+      p += count3 * size;
77
+    }
78
+  return ptr;
79
+}
... ...
@@ -0,0 +1,19 @@
1
+/* BlinkenLib
2
+ * version 0.1 date 2004-11-25
3
+ * Copyright (C) 2004: Stefan Schuermans <1stein@schuermans.info>
4
+ * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
5
+ * a blinkenarea.org project
6
+ * powered by eventphone.de
7
+ */
8
+
9
+#ifndef INC_Tools
10
+#define INC_Tools
11
+
12
+void * malloc1D( int count1, int size );
13
+
14
+void * * malloc2D( int count1, int count2, int size );
15
+
16
+void * * * malloc3D( int count1, int count2, int count3, int size );
17
+
18
+#endif //#ifndef INC_Tools
19
+
0 20