Christian Heimke commited on 2011-07-15 09:02:58
Showing 13 changed files, with 510 additions and 105 deletions.
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
/* BlinkenLib |
2 |
- * version 0.3.1 date 2005-03-05 |
|
2 |
+ * version 0.4 date 2005-07-02 |
|
3 | 3 |
* Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
* a blinkenarea.org project |
... | ... |
@@ -8,6 +8,7 @@ |
8 | 8 |
|
9 | 9 |
#include <stdio.h> |
10 | 10 |
#include <stdlib.h> |
11 |
+#include <string.h> |
|
11 | 12 |
|
12 | 13 |
#include "BlinkenLib.h" |
13 | 14 |
|
... | ... |
@@ -20,7 +21,7 @@ int main( int argCnt, char * * args ) |
20 | 21 |
|
21 | 22 |
//print info |
22 | 23 |
printf( "BlinkenLib - BlinkenConv\n" |
23 |
- "version 0.3.1 date 2005-03-05\n" |
|
24 |
+ "version 0.4 date 2005-07-02\n" |
|
24 | 25 |
"Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info>\n" |
25 | 26 |
"Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n" |
26 | 27 |
"a blinkenarea.org project\n" |
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
/* BlinkenLib |
2 |
- * version 0.3.1 date 2005-03-05 |
|
2 |
+ * version 0.4 date 2005-07-02 |
|
3 | 3 |
* Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
4 | 4 |
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
* a blinkenarea.org project |
... | ... |
@@ -23,7 +23,7 @@ struct sBlinkenFrame |
23 | 23 |
int channels; |
24 | 24 |
int maxval; |
25 | 25 |
int duration; |
26 |
- unsigned char * * * pppData; |
|
26 |
+ unsigned char * * ppData; |
|
27 | 27 |
}; |
28 | 28 |
|
29 | 29 |
//blinken protocol headers |
... | ... |
@@ -78,8 +78,8 @@ stBlinkenFrame * BlinkenFrameNew( int height, int width, int channels, int maxva |
78 | 78 |
pFrame->maxval = maxval; |
79 | 79 |
pFrame->duration = duration; |
80 | 80 |
|
81 |
- pFrame->pppData = (unsigned char * * *)malloc3D( height, width, channels, sizeof( unsigned char ) ); |
|
82 |
- if( pFrame->pppData == NULL ) |
|
81 |
+ pFrame->ppData = (unsigned char * *)malloc2D( height, width * channels, sizeof( unsigned char ) ); |
|
82 |
+ if( pFrame->ppData == NULL ) |
|
83 | 83 |
{ |
84 | 84 |
free( pFrame ); |
85 | 85 |
return NULL; |
... | ... |
@@ -90,7 +90,7 @@ stBlinkenFrame * BlinkenFrameNew( int height, int width, int channels, int maxva |
90 | 90 |
|
91 | 91 |
stBlinkenFrame * BlinkenFrameClone( stBlinkenFrame * pSrcFrame ) |
92 | 92 |
{ |
93 |
- int y, x, c; |
|
93 |
+ int y, x, c, i; |
|
94 | 94 |
stBlinkenFrame * pFrame; |
95 | 95 |
|
96 | 96 |
if( pSrcFrame == NULL ) |
... | ... |
@@ -102,9 +102,9 @@ stBlinkenFrame * BlinkenFrameClone( stBlinkenFrame * pSrcFrame ) |
102 | 102 |
return NULL; |
103 | 103 |
|
104 | 104 |
for( y = 0; y < pFrame->height; y++ ) |
105 |
- for( x = 0; x < pFrame->width; x++ ) |
|
106 |
- for( c = 0; c < pFrame->channels; c++ ) |
|
107 |
- pFrame->pppData[y][x][c] = pSrcFrame->pppData[y][x][c]; |
|
105 |
+ for( x = 0, i = 0; x < pFrame->width; x++ ) |
|
106 |
+ for( c = 0; c < pFrame->channels; c++, i++ ) |
|
107 |
+ pFrame->ppData[y][i] = pSrcFrame->ppData[y][i]; |
|
108 | 108 |
|
109 | 109 |
return pFrame; |
110 | 110 |
} |
... | ... |
@@ -114,21 +114,21 @@ void BlinkenFrameFree( stBlinkenFrame * pFrame ) |
114 | 114 |
if( pFrame == NULL ) |
115 | 115 |
return; |
116 | 116 |
|
117 |
- free( pFrame->pppData ); |
|
117 |
+ free( pFrame->ppData ); |
|
118 | 118 |
free( pFrame ); |
119 | 119 |
} |
120 | 120 |
|
121 | 121 |
void BlinkenFrameClear( stBlinkenFrame * pFrame ) |
122 | 122 |
{ |
123 |
- int y, x, c; |
|
123 |
+ int y, x, c, i; |
|
124 | 124 |
|
125 | 125 |
if( pFrame == NULL ) |
126 | 126 |
return; |
127 | 127 |
|
128 | 128 |
for( y = 0; y < pFrame->height; y++ ) |
129 |
- for( x = 0; x < pFrame->width; x++ ) |
|
130 |
- for( c = 0; c < pFrame->channels; c++ ) |
|
131 |
- pFrame->pppData[y][x][c] = 0; |
|
129 |
+ for( x = 0, i = 0; x < pFrame->width; x++ ) |
|
130 |
+ for( c = 0; c < pFrame->channels; c++, i++ ) |
|
131 |
+ pFrame->ppData[y][i] = 0; |
|
132 | 132 |
} |
133 | 133 |
|
134 | 134 |
int BlinkenFrameGetHeight( stBlinkenFrame * pFrame ) |
... | ... |
@@ -190,7 +190,7 @@ unsigned char BlinkenFrameGetPixel( stBlinkenFrame * pFrame, int y, int x, int c |
190 | 190 |
c < 0 || c >= pFrame->channels ) |
191 | 191 |
return 0; |
192 | 192 |
|
193 |
- return pFrame->pppData[y][x][c]; |
|
193 |
+ return pFrame->ppData[y][x * pFrame->channels + c]; |
|
194 | 194 |
} |
195 | 195 |
|
196 | 196 |
void BlinkenFrameSetPixel( stBlinkenFrame * pFrame, int y, int x, int c, unsigned char val ) |
... | ... |
@@ -203,7 +203,7 @@ void BlinkenFrameSetPixel( stBlinkenFrame * pFrame, int y, int x, int c, unsigne |
203 | 203 |
|
204 | 204 |
if( val > pFrame->maxval ) |
205 | 205 |
val = pFrame->maxval; |
206 |
- pFrame->pppData[y][x][c] = val; |
|
206 |
+ pFrame->ppData[y][x * pFrame->channels + c] = val; |
|
207 | 207 |
} |
208 | 208 |
|
209 | 209 |
unsigned long BlinkenFrameGetColor( stBlinkenFrame * pFrame, int y, int x ) |
... | ... |
@@ -213,16 +213,18 @@ unsigned long BlinkenFrameGetColor( stBlinkenFrame * pFrame, int y, int x ) |
213 | 213 |
x < 0 || x >= pFrame->width ) |
214 | 214 |
return 0; |
215 | 215 |
|
216 |
+ int i = x * pFrame->channels; |
|
217 |
+ |
|
216 | 218 |
if( pFrame->channels == 1 ) |
217 |
- return (((unsigned long)pFrame->pppData[y][x][0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 16 | |
|
218 |
- (((unsigned long)pFrame->pppData[y][x][0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 8 | |
|
219 |
- (((unsigned long)pFrame->pppData[y][x][0] * 255 + pFrame->maxval / 2) / pFrame->maxval); |
|
219 |
+ return (((unsigned long)pFrame->ppData[y][i + 0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 16 | |
|
220 |
+ (((unsigned long)pFrame->ppData[y][i + 0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 8 | |
|
221 |
+ (((unsigned long)pFrame->ppData[y][i + 0] * 255 + pFrame->maxval / 2) / pFrame->maxval); |
|
220 | 222 |
if( pFrame->channels == 2 ) |
221 |
- return (((unsigned long)pFrame->pppData[y][x][0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 16 | |
|
222 |
- (((unsigned long)pFrame->pppData[y][x][1] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 8; |
|
223 |
- return (((unsigned long)pFrame->pppData[y][x][0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 16 | |
|
224 |
- (((unsigned long)pFrame->pppData[y][x][1] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 8 | |
|
225 |
- (((unsigned long)pFrame->pppData[y][x][2] * 255 + pFrame->maxval / 2) / pFrame->maxval); |
|
223 |
+ return (((unsigned long)pFrame->ppData[y][i + 0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 16 | |
|
224 |
+ (((unsigned long)pFrame->ppData[y][i + 1] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 8; |
|
225 |
+ return (((unsigned long)pFrame->ppData[y][i + 0] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 16 | |
|
226 |
+ (((unsigned long)pFrame->ppData[y][i + 1] * 255 + pFrame->maxval / 2) / pFrame->maxval) << 8 | |
|
227 |
+ (((unsigned long)pFrame->ppData[y][i + 2] * 255 + pFrame->maxval / 2) / pFrame->maxval); |
|
226 | 228 |
} |
227 | 229 |
|
228 | 230 |
void BlinkenFrameSetColor( stBlinkenFrame * pFrame, int y, int x, unsigned long color ) |
... | ... |
@@ -234,30 +236,32 @@ void BlinkenFrameSetColor( stBlinkenFrame * pFrame, int y, int x, unsigned long |
234 | 236 |
x < 0 || x >= pFrame->width ) |
235 | 237 |
return; |
236 | 238 |
|
239 |
+ int i = x * pFrame->channels; |
|
240 |
+ |
|
237 | 241 |
alpha = (color >> 24) & 0xFF; |
238 | 242 |
alpha_ = 255 - alpha; |
239 | 243 |
if( pFrame->channels >= 1 ) |
240 |
- pFrame->pppData[y][x][0] = (unsigned char)(( ((((color >> 16) & 0xFF) * pFrame->maxval + 127) / 255) * alpha |
|
241 |
- + (unsigned long)pFrame->pppData[y][x][0] * alpha_ |
|
244 |
+ pFrame->ppData[y][i + 0] = (unsigned char)(( ((((color >> 16) & 0xFF) * pFrame->maxval + 127) / 255) * alpha |
|
245 |
+ + (unsigned long)pFrame->ppData[y][i + 0] * alpha_ |
|
242 | 246 |
) / 255); |
243 | 247 |
if( pFrame->channels >= 2 ) |
244 |
- pFrame->pppData[y][x][1] = (unsigned char)(( ((((color >> 8) & 0xFF) * pFrame->maxval + 127) / 255) * alpha |
|
245 |
- + (unsigned long)pFrame->pppData[y][x][1] * alpha_ |
|
248 |
+ pFrame->ppData[y][i + 1] = (unsigned char)(( ((((color >> 8) & 0xFF) * pFrame->maxval + 127) / 255) * alpha |
|
249 |
+ + (unsigned long)pFrame->ppData[y][i + 1] * alpha_ |
|
246 | 250 |
) / 255); |
247 | 251 |
if( pFrame->channels >= 3 ) |
248 |
- pFrame->pppData[y][x][2] = (unsigned char)(( (((color & 0xFF) * pFrame->maxval + 127) / 255) * alpha |
|
249 |
- + (unsigned long)pFrame->pppData[y][x][2] * alpha_ |
|
252 |
+ pFrame->ppData[y][i + 2] = (unsigned char)(( (((color & 0xFF) * pFrame->maxval + 127) / 255) * alpha |
|
253 |
+ + (unsigned long)pFrame->ppData[y][i + 2] * alpha_ |
|
250 | 254 |
) / 255); |
251 | 255 |
for( c = 3; c < pFrame->channels; c++ ) |
252 |
- pFrame->pppData[y][x][c] = (unsigned char)(( 0 |
|
253 |
- + (unsigned long)pFrame->pppData[y][x][c] * alpha_ |
|
256 |
+ pFrame->ppData[y][i + c] = (unsigned char)(( 0 |
|
257 |
+ + (unsigned long)pFrame->ppData[y][i + c] * alpha_ |
|
254 | 258 |
) / 255); |
255 | 259 |
} |
256 | 260 |
|
257 | 261 |
void BlinkenFrameResize( stBlinkenFrame * pFrame, int height, int width, int channels, int maxval ) |
258 | 262 |
{ |
259 |
- unsigned char * * * pppData; |
|
260 |
- int y, x, c; |
|
263 |
+ unsigned char * * ppData; |
|
264 |
+ int y, x, c, i, j; |
|
261 | 265 |
int emptyY, emptyX, skipY, skipX, rangeY, rangeX; |
262 | 266 |
unsigned long val, div; |
263 | 267 |
|
... | ... |
@@ -280,13 +284,13 @@ void BlinkenFrameResize( stBlinkenFrame * pFrame, int height, int width, int cha |
280 | 284 |
return; |
281 | 285 |
|
282 | 286 |
//allocate new data array |
283 |
- pppData = (unsigned char * * *)malloc3D( height, width, channels, sizeof( unsigned char ) ); |
|
284 |
- if( pppData == NULL ) |
|
287 |
+ ppData = (unsigned char * *)malloc2D( height, width * channels, sizeof( unsigned char ) ); |
|
288 |
+ if( ppData == NULL ) |
|
285 | 289 |
return; |
286 | 290 |
for( y = 0; y < height; y++ ) |
287 |
- for( x = 0; x < width; x++ ) |
|
288 |
- for( c = 0; c < channels; c++ ) |
|
289 |
- pppData[y][x][c] = 0; |
|
291 |
+ for( x = 0, i = 0; x < width; x++ ) |
|
292 |
+ for( c = 0; c < channels; c++, i++ ) |
|
293 |
+ ppData[y][i] = 0; |
|
290 | 294 |
|
291 | 295 |
//get number of pixels to skip / to leave empty in X and Y direction |
292 | 296 |
if( height > pFrame->height ) |
... | ... |
@@ -319,22 +323,24 @@ void BlinkenFrameResize( stBlinkenFrame * pFrame, int height, int width, int cha |
319 | 323 |
{ |
320 | 324 |
for( x = 0; x < rangeX; x++ ) |
321 | 325 |
{ |
326 |
+ i = (skipX + x) * pFrame->channels; |
|
327 |
+ j = (emptyX + x) * channels; |
|
322 | 328 |
if( channels >= pFrame->channels ) //add channels: copy last channel into new channels |
323 | 329 |
{ |
324 |
- for( c = 0; c < pFrame->channels; c++ ) |
|
325 |
- pppData[emptyY + y][emptyX + x][c] = (unsigned char)(((unsigned long)pFrame->pppData[skipY + y][skipX + x][c] * maxval + pFrame->maxval / 2) / pFrame->maxval); |
|
326 |
- for( ; c < channels; c++ ) |
|
327 |
- pppData[emptyY + y][emptyX + x][c] = pppData[emptyY + y][emptyX + x][pFrame->channels - 1]; |
|
330 |
+ for( c = 0; c < pFrame->channels; c++, i++, j++ ) |
|
331 |
+ ppData[emptyY + y][j] = (unsigned char)(((unsigned long)pFrame->ppData[skipY + y][i] * maxval + pFrame->maxval / 2) / pFrame->maxval); |
|
332 |
+ for( ; c < channels; c++, j++ ) |
|
333 |
+ ppData[emptyY + y][j] = ppData[emptyY + y][j - 1]; |
|
328 | 334 |
} |
329 | 335 |
else //remove channels: merge leftover channels with last kept channel |
330 | 336 |
{ |
331 | 337 |
val = 0; |
332 |
- for( c = 0; c < channels - 1; c++ ) |
|
333 |
- pppData[emptyY + y][emptyX + x][c] = (unsigned char)(((unsigned long)pFrame->pppData[skipY + y][skipX + x][c] * maxval + pFrame->maxval / 2) / pFrame->maxval); |
|
334 |
- for( c = channels - 1; c < pFrame->channels; c++ ) |
|
335 |
- val += (unsigned long)pFrame->pppData[skipY + y][skipX + x][c]; |
|
338 |
+ for( c = 0; c < channels - 1; c++, i++, j++ ) |
|
339 |
+ ppData[emptyY + y][j] = (unsigned char)(((unsigned long)pFrame->ppData[skipY + y][i] * maxval + pFrame->maxval / 2) / pFrame->maxval); |
|
340 |
+ for( c = channels - 1; c < pFrame->channels; c++, i++ ) |
|
341 |
+ val += (unsigned long)pFrame->ppData[skipY + y][i]; |
|
336 | 342 |
div = pFrame->maxval * (pFrame->channels - channels + 1); |
337 |
- pppData[emptyY + y][emptyX + x][channels - 1] = (unsigned char)((val * maxval + div / 2) / div); |
|
343 |
+ ppData[emptyY + y][j++] = (unsigned char)((val * maxval + div / 2) / div); |
|
338 | 344 |
} |
339 | 345 |
} |
340 | 346 |
} |
... | ... |
@@ -343,15 +349,15 @@ void BlinkenFrameResize( stBlinkenFrame * pFrame, int height, int width, int cha |
343 | 349 |
pFrame->width = width; |
344 | 350 |
pFrame->channels = channels; |
345 | 351 |
pFrame->maxval = maxval; |
346 |
- free( pFrame->pppData ); |
|
347 |
- pFrame->pppData = pppData; |
|
352 |
+ free( pFrame->ppData ); |
|
353 |
+ pFrame->ppData = ppData; |
|
348 | 354 |
} |
349 | 355 |
|
350 | 356 |
void BlinkenFrameScale( stBlinkenFrame * pFrame, int height, int width ) |
351 | 357 |
{ |
352 |
- unsigned char * * * pppData; |
|
358 |
+ unsigned char * * ppData; |
|
353 | 359 |
double scaleHor, scaleVer, ox, oy, ox1, oy1, val; |
354 |
- int c, nx, ny, x, y, oxi, oyi, ox1i, oy1i; |
|
360 |
+ int chans, c, nx, ny, x, y, oxi, oyi, ox1i, oy1i; |
|
355 | 361 |
|
356 | 362 |
if( pFrame == NULL ) |
357 | 363 |
return; |
... | ... |
@@ -369,12 +375,13 @@ void BlinkenFrameScale( stBlinkenFrame * pFrame, int height, int width ) |
369 | 375 |
scaleVer = (double)height / (double)pFrame->height; |
370 | 376 |
|
371 | 377 |
//allocate new data array |
372 |
- pppData = (unsigned char * * *)malloc3D( height, width, pFrame->channels, sizeof( unsigned char ) ); |
|
373 |
- if( pppData == NULL ) |
|
378 |
+ ppData = (unsigned char * *)malloc2D( height, width * pFrame->channels, sizeof( unsigned char ) ); |
|
379 |
+ if( ppData == NULL ) |
|
374 | 380 |
return; |
375 | 381 |
|
376 | 382 |
//scale every channel |
377 |
- for( c = 0; c < pFrame->channels; c++ ) |
|
383 |
+ chans = pFrame->channels; |
|
384 |
+ for( c = 0; c < chans; c++ ) |
|
378 | 385 |
{ |
379 | 386 |
for( ny = 0; ny < height; ny++ ) |
380 | 387 |
{ |
... | ... |
@@ -385,7 +392,7 @@ void BlinkenFrameScale( stBlinkenFrame * pFrame, int height, int width ) |
385 | 392 |
oy1 = (double)(ny + 1) / scaleVer - 0.000001; |
386 | 393 |
ox1 = (double)(nx + 1) / scaleHor - 0.000001; |
387 | 394 |
if( oy < 0 || ox < 0 || oy1 >= pFrame->height || ox1 >= pFrame->width) //out of old picture |
388 |
- pppData[ny][nx][c] = 0; |
|
395 |
+ ppData[ny][nx * chans + c] = 0; |
|
389 | 396 |
else |
390 | 397 |
{ |
391 | 398 |
oyi = (int)oy; |
... | ... |
@@ -396,14 +403,14 @@ void BlinkenFrameScale( stBlinkenFrame * pFrame, int height, int width ) |
396 | 403 |
{ |
397 | 404 |
if( oxi == ox1i) //one source pixel |
398 | 405 |
{ |
399 |
- val = (double)pFrame->pppData[oyi][oxi][c]; |
|
406 |
+ val = (double)pFrame->ppData[oyi][oxi * chans + c]; |
|
400 | 407 |
} |
401 | 408 |
else //one line of source pixels |
402 | 409 |
{ |
403 |
- val = (double)pFrame->pppData[oyi][oxi][c] * (1 - ox + oxi) |
|
404 |
- + (double)pFrame->pppData[oyi][ox1i][c] * (ox1 - ox1i); |
|
410 |
+ val = (double)pFrame->ppData[oyi][oxi * chans + c] * (1 - ox + oxi) |
|
411 |
+ + (double)pFrame->ppData[oyi][ox1i * chans + c] * (ox1 - ox1i); |
|
405 | 412 |
for( x = oxi + 1; x < ox1i; x++ ) |
406 |
- val += (double)pFrame->pppData[oyi][x][c]; |
|
413 |
+ val += (double)pFrame->ppData[oyi][x * chans + c]; |
|
407 | 414 |
val /= ox1 - ox; |
408 | 415 |
} |
409 | 416 |
} |
... | ... |
@@ -411,35 +418,35 @@ void BlinkenFrameScale( stBlinkenFrame * pFrame, int height, int width ) |
411 | 418 |
{ |
412 | 419 |
if( oxi == ox1i ) |
413 | 420 |
{ |
414 |
- val = (double)pFrame->pppData[oyi][oxi][c] * (1 - oy + oyi) |
|
415 |
- + (double)pFrame->pppData[oy1i][oxi][c] * (oy1 - oy1i); |
|
421 |
+ val = (double)pFrame->ppData[oyi][oxi * chans + c] * (1 - oy + oyi) |
|
422 |
+ + (double)pFrame->ppData[oy1i][oxi * chans + c] * (oy1 - oy1i); |
|
416 | 423 |
for( y = oyi + 1; y < oy1i; y++ ) |
417 |
- val += (double)pFrame->pppData[y][oxi][c]; |
|
424 |
+ val += (double)pFrame->ppData[y][oxi * chans + c]; |
|
418 | 425 |
val /= oy1 - oy; |
419 | 426 |
} |
420 | 427 |
else //rectangle of source pixels |
421 | 428 |
{ |
422 |
- val = (double)pFrame->pppData[oyi][oxi][c] * (1 - oy + oyi) * (1 - ox + oxi) |
|
423 |
- + (double)pFrame->pppData[oyi][ox1i][c] * (1 - oy + oyi) * (ox1 - ox1i) |
|
424 |
- + (double)pFrame->pppData[oy1i][oxi][c] * (oy1 - oy1i) * (1 - ox + oxi) |
|
425 |
- + (double)pFrame->pppData[oy1i][ox1i][c] * (oy1 - oy1i) * (ox1 - ox1i); |
|
429 |
+ val = (double)pFrame->ppData[oyi][oxi* chans + c] * (1 - oy + oyi) * (1 - ox + oxi) |
|
430 |
+ + (double)pFrame->ppData[oyi][ox1i * chans + c] * (1 - oy + oyi) * (ox1 - ox1i) |
|
431 |
+ + (double)pFrame->ppData[oy1i][oxi * chans + c] * (oy1 - oy1i) * (1 - ox + oxi) |
|
432 |
+ + (double)pFrame->ppData[oy1i][ox1i * chans + c] * (oy1 - oy1i) * (ox1 - ox1i); |
|
426 | 433 |
for( y = oyi + 1; y < oy1i; y++ ) |
427 | 434 |
{ |
428 |
- val += (double)pFrame->pppData[y][oxi][c] * (1 - ox + oxi) |
|
429 |
- + (double)pFrame->pppData[y][ox1i][c] * (ox1 - ox1i); |
|
435 |
+ val += (double)pFrame->ppData[y][oxi * chans + c] * (1 - ox + oxi) |
|
436 |
+ + (double)pFrame->ppData[y][ox1i * chans + c] * (ox1 - ox1i); |
|
430 | 437 |
} |
431 | 438 |
for( x = oxi + 1; x < ox1i; x++ ) |
432 | 439 |
{ |
433 |
- val += (double)pFrame->pppData[oyi][x][c] * (1 - oy + oyi) |
|
434 |
- + (double)pFrame->pppData[oy1i][x][c] * (oy1 - oy1i); |
|
440 |
+ val += (double)pFrame->ppData[oyi][x * chans + c] * (1 - oy + oyi) |
|
441 |
+ + (double)pFrame->ppData[oy1i][x * chans + c] * (oy1 - oy1i); |
|
435 | 442 |
} |
436 | 443 |
for( y = oyi + 1; y < oy1i; y++ ) |
437 | 444 |
for( x = oxi + 1; x < ox1i; x++ ) |
438 |
- val += (double)pFrame->pppData[y][x][c]; |
|
445 |
+ val += (double)pFrame->ppData[y][x * chans + c]; |
|
439 | 446 |
val /= (oy1 - oy) * (ox1 - ox); |
440 | 447 |
} |
441 | 448 |
} |
442 |
- pppData[ny][nx][c] = (unsigned char)(val + 0.5); |
|
449 |
+ ppData[ny][nx * chans + c] = (unsigned char)(val + 0.5); |
|
443 | 450 |
} |
444 | 451 |
} //for( nx ... |
445 | 452 |
} //for( ny ... |
... | ... |
@@ -447,13 +454,13 @@ void BlinkenFrameScale( stBlinkenFrame * pFrame, int height, int width ) |
447 | 454 |
|
448 | 455 |
pFrame->height = height; |
449 | 456 |
pFrame->width = width; |
450 |
- free( pFrame->pppData ); |
|
451 |
- pFrame->pppData = pppData; |
|
457 |
+ free( pFrame->ppData ); |
|
458 |
+ pFrame->ppData = ppData; |
|
452 | 459 |
} |
453 | 460 |
|
454 | 461 |
char * BlinkenFrameToString( stBlinkenFrame * pFrame ) |
455 | 462 |
{ |
456 |
- int size, y, x, c; |
|
463 |
+ int size, y, x, c, i; |
|
457 | 464 |
char * str, * ptr; |
458 | 465 |
unsigned long val; |
459 | 466 |
|
... | ... |
@@ -470,11 +477,11 @@ char * BlinkenFrameToString( stBlinkenFrame * pFrame ) |
470 | 477 |
|
471 | 478 |
for( y = 0; y < pFrame->height; y++ ) |
472 | 479 |
{ |
473 |
- for( x = 0; x < pFrame->width; x++ ) |
|
480 |
+ for( x = 0, i = 0; x < pFrame->width; x++ ) |
|
474 | 481 |
{ |
475 | 482 |
val = 0; |
476 |
- for( val = 0, c = 0; c < pFrame->channels; c++ ) |
|
477 |
- val += pFrame->pppData[y][x][c]; |
|
483 |
+ for( val = 0, c = 0; c < pFrame->channels; c++, i++ ) |
|
484 |
+ val += pFrame->ppData[y][i]; |
|
478 | 485 |
val = val * 7 / pFrame->maxval / pFrame->channels; |
479 | 486 |
*ptr = " -+*%#&@"[val]; |
480 | 487 |
ptr++; |
... | ... |
@@ -491,7 +498,7 @@ char * BlinkenFrameToString( stBlinkenFrame * pFrame ) |
491 | 498 |
int BlinkenFrameToNetwork( stBlinkenFrame * pFrame, etBlinkenProto proto, char * pData, int maxLength ) |
492 | 499 |
//returns length or -1 on error |
493 | 500 |
{ |
494 |
- int y, x, c, i, val; |
|
501 |
+ int y, x, c, i, j, val; |
|
495 | 502 |
|
496 | 503 |
if( pFrame == NULL ) |
497 | 504 |
return -1; |
... | ... |
@@ -512,11 +519,11 @@ int BlinkenFrameToNetwork( stBlinkenFrame * pFrame, etBlinkenProto proto, char * |
512 | 519 |
i = sizeof( stBlinkenProtoBlpHdr ); //put data into packet |
513 | 520 |
for( y = 0; y < pFrame->height; y++ ) |
514 | 521 |
{ |
515 |
- for( x = 0; x < pFrame->width; x++, i++ ) |
|
522 |
+ for( x = 0, j = 0; x < pFrame->width; x++, i++ ) |
|
516 | 523 |
{ |
517 | 524 |
val = 0; |
518 |
- for( c = 0; c < pFrame->channels; c++ ) |
|
519 |
- val += pFrame->pppData[y][x][c]; |
|
525 |
+ for( c = 0; c < pFrame->channels; c++, j++ ) |
|
526 |
+ val += pFrame->ppData[y][j]; |
|
520 | 527 |
pData[i] = (val >= pFrame->channels * pFrame->maxval / 2 ? 0x01 : 0x00); |
521 | 528 |
} |
522 | 529 |
} |
... | ... |
@@ -532,11 +539,11 @@ int BlinkenFrameToNetwork( stBlinkenFrame * pFrame, etBlinkenProto proto, char * |
532 | 539 |
i = sizeof( stBlinkenProtoEblpHdr ); //put data into packet |
533 | 540 |
for( y = 0; y < pFrame->height; y++ ) |
534 | 541 |
{ |
535 |
- for( x = 0; x < pFrame->width; x++, i++ ) |
|
542 |
+ for( x = 0, j = 0; x < pFrame->width; x++, i++ ) |
|
536 | 543 |
{ |
537 | 544 |
val = 0; |
538 |
- for( c = 0; c < pFrame->channels; c++ ) |
|
539 |
- val += pFrame->pppData[y][x][c]; |
|
545 |
+ for( c = 0; c < pFrame->channels; c++, j++ ) |
|
546 |
+ val += pFrame->ppData[y][j]; |
|
540 | 547 |
val /= pFrame->channels; |
541 | 548 |
pData[i] = (pFrame->maxval == 255 ? (unsigned char)val |
542 | 549 |
: (unsigned char)((val * 255 + pFrame->maxval / 2) / pFrame->maxval)); |
... | ... |
@@ -554,9 +561,9 @@ int BlinkenFrameToNetwork( stBlinkenFrame * pFrame, etBlinkenProto proto, char * |
554 | 561 |
((stBlinkenProtoMcufHdr *)pData)->maxval = htons( pFrame->maxval ); |
555 | 562 |
i = sizeof( stBlinkenProtoMcufHdr ); //put data into packet |
556 | 563 |
for( y = 0; y < pFrame->height; y++ ) |
557 |
- for( x = 0; x < pFrame->width; x++ ) |
|
558 |
- for( c = 0; c < pFrame->channels; c++, i++ ) |
|
559 |
- pData[i] = pFrame->pppData[y][x][c]; |
|
564 |
+ for( x = 0, j = 0; x < pFrame->width; x++ ) |
|
565 |
+ for( c = 0; c < pFrame->channels; c++, i++, j++ ) |
|
566 |
+ pData[i] = pFrame->ppData[y][j]; |
|
560 | 567 |
return i; //return length |
561 | 568 |
|
562 | 569 |
default: |
... | ... |
@@ -569,7 +576,7 @@ stBlinkenFrame * BlinkenFrameFromNetwork( char * pData, int length, etBlinkenPro |
569 | 576 |
//returns protocol in *pProto if pProto not NULL |
570 | 577 |
{ |
571 | 578 |
stBlinkenFrame * pFrame; |
572 |
- int height, width, channels, maxval, y, x, c, i; |
|
579 |
+ int height, width, channels, maxval, y, x, c, i, j; |
|
573 | 580 |
|
574 | 581 |
if( length >= (int)sizeof( stBlinkenProtoBlpHdr ) && |
575 | 582 |
((stBlinkenProtoBlpHdr *)pData)->magic == htonl( BlinkenProtoBlpMagic ) ) |
... | ... |
@@ -586,10 +593,10 @@ stBlinkenFrame * BlinkenFrameFromNetwork( char * pData, int length, etBlinkenPro |
586 | 593 |
pFrame = BlinkenFrameNew( height, width, 1, 1, 0 ); //create frame according to header data |
587 | 594 |
if( pFrame == NULL ) |
588 | 595 |
return NULL; |
589 |
- i = sizeof( stBlinkenProtoEblpHdr ); //put data into frame |
|
596 |
+ i = sizeof( stBlinkenProtoBlpHdr ); //put data into frame |
|
590 | 597 |
for( y = 0; y < pFrame->height; y++ ) |
591 | 598 |
for( x = 0; x < pFrame->width; x++, i++ ) |
592 |
- pFrame->pppData[y][x][0] = pData[i]; |
|
599 |
+ pFrame->ppData[y][x * 1 + 0] = pData[i]; |
|
593 | 600 |
return pFrame; |
594 | 601 |
} |
595 | 602 |
|
... | ... |
@@ -611,7 +618,7 @@ stBlinkenFrame * BlinkenFrameFromNetwork( char * pData, int length, etBlinkenPro |
611 | 618 |
i = sizeof( stBlinkenProtoEblpHdr ); //put data into frame |
612 | 619 |
for( y = 0; y < pFrame->height; y++ ) |
613 | 620 |
for( x = 0; x < pFrame->width; x++, i++ ) |
614 |
- pFrame->pppData[y][x][0] = pData[i]; |
|
621 |
+ pFrame->ppData[y][x * 1 + 0] = pData[i]; |
|
615 | 622 |
return pFrame; |
616 | 623 |
} |
617 | 624 |
|
... | ... |
@@ -636,9 +643,9 @@ stBlinkenFrame * BlinkenFrameFromNetwork( char * pData, int length, etBlinkenPro |
636 | 643 |
return NULL; |
637 | 644 |
i = sizeof( stBlinkenProtoMcufHdr ); //put data into frame |
638 | 645 |
for( y = 0; y < pFrame->height; y++ ) |
639 |
- for( x = 0; x < pFrame->width; x++ ) |
|
640 |
- for( c = 0; c < pFrame->channels; c++, i++ ) |
|
641 |
- pFrame->pppData[y][x][c] = pData[i]; |
|
646 |
+ for( x = 0, j = 0; x < pFrame->width; x++ ) |
|
647 |
+ for( c = 0; c < pFrame->channels; c++, i++, j++ ) |
|
648 |
+ pFrame->ppData[y][j] = pData[i]; |
|
642 | 649 |
return pFrame; |
643 | 650 |
} |
644 | 651 |
|
... | ... |
@@ -0,0 +1,194 @@ |
1 |
+/* BlinkenLib |
|
2 |
+ * version 0.4 date 2005-07-02 |
|
3 |
+ * Copyright 2004-2005 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 |
+#include <sys/types.h> |
|
13 |
+#include <sys/socket.h> |
|
14 |
+#include <netinet/in.h> |
|
15 |
+#include <arpa/inet.h> |
|
16 |
+ |
|
17 |
+#include "BlinkenLib.h" |
|
18 |
+ |
|
19 |
+int main( int argCnt, char * * args ) |
|
20 |
+{ |
|
21 |
+ int i, udpSocket, bound, val, timeout; |
|
22 |
+ char txt[64]; |
|
23 |
+ unsigned short port; |
|
24 |
+ struct sockaddr_in addr; |
|
25 |
+ stBlinkenMovie * pMovie; |
|
26 |
+ |
|
27 |
+ //print info |
|
28 |
+ printf( "BlinkenLib - BlinkenRecv\n" |
|
29 |
+ "version 0.4 date 2005-07-02\n" |
|
30 |
+ "Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info>\n" |
|
31 |
+ "Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n" |
|
32 |
+ "a blinkenarea.org project\n" |
|
33 |
+ "powered by eventphone.de\n\n" ); |
|
34 |
+ |
|
35 |
+ //print syntax |
|
36 |
+ if( argCnt <= 1 ) |
|
37 |
+ { |
|
38 |
+ printf( "syntax: %s <parameter> [...]\n\n" |
|
39 |
+ "parameters:\n" |
|
40 |
+ " -l [<ip>:]<port>\n" |
|
41 |
+ " local address (defaults to 0.0.0.0:2323)\n" |
|
42 |
+ " must occur before -r and -o, may only occur once\n" |
|
43 |
+ " -r <ip>[:<port>]\n" |
|
44 |
+ " remote addess (defaults to every remote address)\n" |
|
45 |
+ " -t <milliseconds>\n" |
|
46 |
+ " set timeout (to detect movie end, defaults to 5000)\n" |
|
47 |
+ " -o <file>\n" |
|
48 |
+ " receive movie and write it to file (*.blm, *.bmm, *.bml, *.bbm)\n\n", |
|
49 |
+ args[0] ); |
|
50 |
+ return 0; |
|
51 |
+ } |
|
52 |
+ |
|
53 |
+ //create udp socket |
|
54 |
+ udpSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); |
|
55 |
+ if( udpSocket == -1 ) |
|
56 |
+ { |
|
57 |
+ printf( "cannot create UDP socket\n" ); |
|
58 |
+ return -1; |
|
59 |
+ } |
|
60 |
+ bound = 0; |
|
61 |
+ |
|
62 |
+ //process parameters |
|
63 |
+ timeout = 5000; |
|
64 |
+ for( i = 1; i < argCnt; i++ ) |
|
65 |
+ { |
|
66 |
+ |
|
67 |
+ //local address |
|
68 |
+ if( strcmp( args[i], "-l" ) == 0 ) |
|
69 |
+ { |
|
70 |
+ if( i + 1 < argCnt ) |
|
71 |
+ { |
|
72 |
+ i++; |
|
73 |
+ if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 ) |
|
74 |
+ { |
|
75 |
+ addr.sin_family = AF_INET; |
|
76 |
+ addr.sin_port = htons( port ); |
|
77 |
+ addr.sin_addr.s_addr = inet_addr( txt ); |
|
78 |
+ if( bind( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) |
|
79 |
+ printf( "could not set local address to \"%s\"\n", args[i] ); |
|
80 |
+ else |
|
81 |
+ bound = 1; |
|
82 |
+ } |
|
83 |
+ else if( sscanf( args[i], "%hu", &port ) == 1 ) |
|
84 |
+ { |
|
85 |
+ addr.sin_family = AF_INET; |
|
86 |
+ addr.sin_port = htons( port ); |
|
87 |
+ addr.sin_addr.s_addr = htonl( INADDR_ANY ); |
|
88 |
+ if( bind( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) |
|
89 |
+ printf( "could not set local address to \"%s\"\n", args[i] ); |
|
90 |
+ else |
|
91 |
+ bound = 1; |
|
92 |
+ } |
|
93 |
+ else |
|
94 |
+ printf( "invalid local address \"%s\"\n", args[i] ); |
|
95 |
+ } |
|
96 |
+ else |
|
97 |
+ printf( "missing local address for \"-l\"\n" ); |
|
98 |
+ } |
|
99 |
+ |
|
100 |
+ //remote address |
|
101 |
+ else if( strcmp( args[i], "-r" ) == 0 ) |
|
102 |
+ { |
|
103 |
+ if( i + 1 < argCnt ) |
|
104 |
+ { |
|
105 |
+ i++; |
|
106 |
+ if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 ) |
|
107 |
+ { |
|
108 |
+ addr.sin_family = AF_INET; |
|
109 |
+ addr.sin_port = htons( port ); |
|
110 |
+ addr.sin_addr.s_addr = inet_addr( txt ); |
|
111 |
+ if( connect( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) |
|
112 |
+ printf( "could not set remote address to \"%s\"\n", args[i] ); |
|
113 |
+ } |
|
114 |
+ else if( sscanf( args[i], "%32[0-9.]", txt ) == 1 ) |
|
115 |
+ { |
|
116 |
+ addr.sin_family = AF_INET; |
|
117 |
+ addr.sin_port = htons( 23230 ); |
|
118 |
+ addr.sin_addr.s_addr = inet_addr( txt ); |
|
119 |
+ if( connect( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) |
|
120 |
+ printf( "could not set remote address to \"%s\"\n", args[i] ); |
|
121 |
+ } |
|
122 |
+ else |
|
123 |
+ printf( "invalid remote address \"%s\"\n", args[i] ); |
|
124 |
+ } |
|
125 |
+ else |
|
126 |
+ printf( "missing remote address for \"-r\"\n" ); |
|
127 |
+ } |
|
128 |
+ |
|
129 |
+ //timeout |
|
130 |
+ else if( strcmp( args[i], "-t" ) == 0 ) |
|
131 |
+ { |
|
132 |
+ if( i + 1 < argCnt ) |
|
133 |
+ { |
|
134 |
+ i++; |
|
135 |
+ if( sscanf( args[i], "%hu", &val ) == 1 ) |
|
136 |
+ timeout = val; |
|
137 |
+ else |
|
138 |
+ printf( "invalid timeout value \"%s\"\n", args[i] ); |
|
139 |
+ } |
|
140 |
+ else |
|
141 |
+ printf( "missing timeout value for \"-t\"\n" ); |
|
142 |
+ } |
|
143 |
+ |
|
144 |
+ //receive movie and write it to file |
|
145 |
+ else if( strcmp( args[i], "-o" ) == 0 ) |
|
146 |
+ { |
|
147 |
+ if( i + 1 < argCnt ) |
|
148 |
+ { |
|
149 |
+ i++; |
|
150 |
+ if( ! bound ) //try to bind if not bound |
|
151 |
+ { |
|
152 |
+ printf( "no local address to receive movie for file \"%s\" to,\n" |
|
153 |
+ " using default local address \"0.0.0.0:2323\"\n", args[i] ); |
|
154 |
+ addr.sin_family = AF_INET; |
|
155 |
+ addr.sin_port = htons( 2323 ); |
|
156 |
+ addr.sin_addr.s_addr = htonl( INADDR_ANY ); |
|
157 |
+ if( bind( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) |
|
158 |
+ printf( "could not set local address to \"0.0.0.0:2323\"\n" ); |
|
159 |
+ else |
|
160 |
+ bound = 1; |
|
161 |
+ } |
|
162 |
+ if( bound ) |
|
163 |
+ { |
|
164 |
+ printf( "receiving movie for file \"%s\"...\n", args[i] ); |
|
165 |
+ pMovie = BlinkenMovieReceive( udpSocket, timeout, NULL ); |
|
166 |
+ if( pMovie == NULL ) |
|
167 |
+ printf( "could not receive movie for file \"%s\"\n", args[i] ); |
|
168 |
+ else |
|
169 |
+ { |
|
170 |
+ if( BlinkenMovieSave( pMovie, args[i] ) < 0 ) |
|
171 |
+ printf( "could not write movie \"%s\"\n", args[i] ); |
|
172 |
+ else |
|
173 |
+ printf( "movie \"%s\" written\n", args[i] ); |
|
174 |
+ BlinkenMovieFree( pMovie ); |
|
175 |
+ } |
|
176 |
+ } |
|
177 |
+ else |
|
178 |
+ printf( "no local address set to receive movie for file \"%s\" on\n", args[i] ); |
|
179 |
+ } |
|
180 |
+ else |
|
181 |
+ printf( "missing output filename for \"-o\"\n" ); |
|
182 |
+ } |
|
183 |
+ |
|
184 |
+ //unknown parameter |
|
185 |
+ else |
|
186 |
+ printf( "unknown parameter \"%s\", call without parameters to get help\n", args[i] ); |
|
187 |
+ |
|
188 |
+ } //for( i ... |
|
189 |
+ |
|
190 |
+ //close socket |
|
191 |
+ close( udpSocket ); |
|
192 |
+ |
|
193 |
+ return 0; |
|
194 |
+} |
... | ... |
@@ -0,0 +1,197 @@ |
1 |
+/* BlinkenLib |
|
2 |
+ * version 0.4 date 2005-07-02 |
|
3 |
+ * Copyright 2004-2005 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 |
+#include <sys/types.h> |
|
13 |
+#include <sys/socket.h> |
|
14 |
+#include <netinet/in.h> |
|
15 |
+#include <arpa/inet.h> |
|
16 |
+ |
|
17 |
+#include "BlinkenLib.h" |
|
18 |
+ |
|
19 |
+int main( int argCnt, char * * args ) |
|
20 |
+{ |
|
21 |
+ int i, udpSocket, connected; |
|
22 |
+ etBlinkenProto proto; |
|
23 |
+ char txt[64]; |
|
24 |
+ unsigned short port; |
|
25 |
+ struct sockaddr_in addr; |
|
26 |
+ stBlinkenMovie * pMovie; |
|
27 |
+ |
|
28 |
+ //print info |
|
29 |
+ printf( "BlinkenLib - BlinkenSend\n" |
|
30 |
+ "version 0.4 date 2005-07-02\n" |
|
31 |
+ "Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info>\n" |
|
32 |
+ "Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n" |
|
33 |
+ "a blinkenarea.org project\n" |
|
34 |
+ "powered by eventphone.de\n\n" ); |
|
35 |
+ |
|
36 |
+ //print syntax |
|
37 |
+ if( argCnt <= 1 ) |
|
38 |
+ { |
|
39 |
+ printf( "syntax: %s <parameter> [...]\n\n" |
|
40 |
+ "parameters:\n" |
|
41 |
+ " -s [<ip>:]<port>\n" |
|
42 |
+ " source address (defaults to 0.0.0.0:0)\n" |
|
43 |
+ " must occur before -d and -i, may only occur once\n" |
|
44 |
+ " -d <ip>[:<port>]\n" |
|
45 |
+ " destination addess (defaults to 127.0.0.1:2323)\n" |
|
46 |
+ " -p [BLP|EBLP|MCUF]\n" |
|
47 |
+ " protocol to use (defaults to MCUF)\n" |
|
48 |
+ " -i <file>\n" |
|
49 |
+ " read movie from file (*.blm, *.bmm, *.bml, *.bbm) and send it\n\n", |
|
50 |
+ args[0] ); |
|
51 |
+ return 0; |
|
52 |
+ } |
|
53 |
+ |
|
54 |
+ //create udp socket |
|
55 |
+ udpSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); |
|
56 |
+ if( udpSocket == -1 ) |
|
57 |
+ { |
|
58 |
+ printf( "cannot create UDP socket\n" ); |
|
59 |
+ return -1; |
|
60 |
+ } |
|
61 |
+ connected = 0; |
|
62 |
+ |
|
63 |
+ //process parameters |
|
64 |
+ proto = BlinkenProtoMcuf; |
|
65 |
+ for( i = 1; i < argCnt; i++ ) |
|
66 |
+ { |
|
67 |
+ |
|
68 |
+ //source address |
|
69 |
+ if( strcmp( args[i], "-s" ) == 0 ) |
|
70 |
+ { |
|
71 |
+ if( i + 1 < argCnt ) |
|
72 |
+ { |
|
73 |
+ i++; |
|
74 |
+ if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 ) |
|
75 |
+ { |
|
76 |
+ addr.sin_family = AF_INET; |
|
77 |
+ addr.sin_port = htons( port ); |
|
78 |
+ addr.sin_addr.s_addr = inet_addr( txt ); |
|
79 |
+ if( bind( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) |
|
80 |
+ printf( "could not set source address to \"%s\"\n", args[i] ); |
|
81 |
+ } |
|
82 |
+ else if( sscanf( args[i], "%hu", &port ) == 1 ) |
|
83 |
+ { |
|
84 |
+ addr.sin_family = AF_INET; |
|
85 |
+ addr.sin_port = htons( port ); |
|
86 |
+ addr.sin_addr.s_addr = htonl( INADDR_ANY ); |
|
87 |
+ if( bind( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) |
|
88 |
+ printf( "could not set source address to \"%s\"\n", args[i] ); |
|
89 |
+ } |
|
90 |
+ else |
|
91 |
+ printf( "invalid source address \"%s\"\n", args[i] ); |
|
92 |
+ } |
|
93 |
+ else |
|
94 |
+ printf( "missing source address for \"-s\"\n" ); |
|
95 |
+ } |
|
96 |
+ |
|
97 |
+ //destination address |
|
98 |
+ else if( strcmp( args[i], "-d" ) == 0 ) |
|
99 |
+ { |
|
100 |
+ if( i + 1 < argCnt ) |
|
101 |
+ { |
|
102 |
+ i++; |
|
103 |
+ if( sscanf( args[i], "%32[0-9.]:%hu", txt, &port ) == 2 ) |
|
104 |
+ { |
|
105 |
+ addr.sin_family = AF_INET; |
|
106 |
+ addr.sin_port = htons( port ); |
|
107 |
+ addr.sin_addr.s_addr = inet_addr( txt ); |
|
108 |
+ if( connect( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) |
|
109 |
+ printf( "could not set destination address to \"%s\"\n", args[i] ); |
|
110 |
+ else |
|
111 |
+ connected = 1; |
|
112 |
+ } |
|
113 |
+ else if( sscanf( args[i], "%32[0-9.]", txt ) == 1 ) |
|
114 |
+ { |
|
115 |
+ addr.sin_family = AF_INET; |
|
116 |
+ addr.sin_port = htons( 2323 ); |
|
117 |
+ addr.sin_addr.s_addr = inet_addr( txt ); |
|
118 |
+ if( connect( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) |
|
119 |
+ printf( "could not set destination address to \"%s\"\n", args[i] ); |
|
120 |
+ else |
|
121 |
+ connected = 1; |
|
122 |
+ } |
|
123 |
+ else |
|
124 |
+ printf( "invalid destination address \"%s\"\n", args[i] ); |
|
125 |
+ } |
|
126 |
+ else |
|
127 |
+ printf( "missing destination address for \"-d\"\n" ); |
|
128 |
+ } |
|
129 |
+ |
|
130 |
+ //protocol to use |
|
131 |
+ else if( strcmp( args[i], "-p" ) == 0 ) |
|
132 |
+ { |
|
133 |
+ if( i + 1 < argCnt ) |
|
134 |
+ { |
|
135 |
+ i++; |
|
136 |
+ if( strcasecmp( args[i], "BLP" ) == 0 ) |
|
137 |
+ proto = BlinkenProtoBlp; |
|
138 |
+ else if( strcasecmp( args[i], "EBLP" ) == 0 ) |
|
139 |
+ proto = BlinkenProtoEblp; |
|
140 |
+ else if( strcasecmp( args[i], "MCUF" ) == 0 ) |
|
141 |
+ proto = BlinkenProtoMcuf; |
|
142 |
+ else |
|
143 |
+ printf( "unknown protocol \"%s\"\n", args[i] ); |
|
144 |
+ } |
|
145 |
+ else |
|
146 |
+ printf( "missing protocol for \"-p\"\n" ); |
|
147 |
+ } |
|
148 |
+ |
|
149 |
+ //read movie and sent it |
|
150 |
+ else if( strcmp( args[i], "-i" ) == 0 ) |
|
151 |
+ { |
|
152 |
+ if( i + 1 < argCnt ) |
|
153 |
+ { |
|
154 |
+ i++; |
|
155 |
+ if( ! connected ) //try to connect if not yet connected |
|
156 |
+ { |
|
157 |
+ printf( "no destination address to sent movie \"%s\" to,\n" |
|
158 |
+ " using default destination address \"127.0.0.1:2323\"\n", args[i] ); |
|
159 |
+ addr.sin_family = AF_INET; |
|
160 |
+ addr.sin_port = htons( 2323 ); |
|
161 |
+ addr.sin_addr.s_addr = htonl( INADDR_LOOPBACK ); |
|
162 |
+ if( connect( udpSocket, (struct sockaddr *)&addr, sizeof( addr ) ) != 0 ) |
|
163 |
+ printf( "could not set destination address to \"127.0.0.1:2323\"\n" ); |
|
164 |
+ else |
|
165 |
+ connected = 1; |
|
166 |
+ } |
|
167 |
+ if( connected ) |
|
168 |
+ { |
|
169 |
+ pMovie = BlinkenMovieLoad( args[i] ); |
|
170 |
+ if( pMovie == NULL ) |
|
171 |
+ printf( "could not read movie \"%s\"\n", args[i] ); |
|
172 |
+ else |
|
173 |
+ { |
|
174 |
+ printf( "movie \"%s\" read - sending...\n", args[i] ); |
|
175 |
+ BlinkenMovieSend( pMovie, udpSocket, proto ); |
|
176 |
+ printf( "movie \"%s\" sent\n", args[i] ); |
|
177 |
+ BlinkenMovieFree( pMovie ); |
|
178 |
+ } |
|
179 |
+ } |
|
180 |
+ else |
|
181 |
+ printf( "no destination address to sent movie \"%s\" to\n", args[i] ); |
|
182 |
+ } |
|
183 |
+ else |
|
184 |
+ printf( "missing input filename for \"-i\"\n" ); |
|
185 |
+ } |
|
186 |
+ |
|
187 |
+ //unknown parameter |
|
188 |
+ else |
|
189 |
+ printf( "unknown parameter \"%s\", call without parameters to get help\n", args[i] ); |
|
190 |
+ |
|
191 |
+ } //for( i ... |
|
192 |
+ |
|
193 |
+ //close socket |
|
194 |
+ close( udpSocket ); |
|
195 |
+ |
|
196 |
+ return 0; |
|
197 |
+} |
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
# BlinkenLib |
2 |
-# version 0.3.1 date 2005-03-05 |
|
2 |
+# version 0.4 date 2005-07-02 |
|
3 | 3 |
# Copyright 2004-2005 Stefan Schuermans <1stein@schuermans.info> |
4 | 4 |
# Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
# a blinkenarea.org project |
... | ... |
@@ -10,6 +10,7 @@ CFLAGS=-W -Wall -O2 |
10 | 10 |
LFLAGS= |
11 | 11 |
AR=ar |
12 | 12 |
ARFLAGS=cr |
13 |
+RANLIB=ranlib |
|
13 | 14 |
|
14 | 15 |
.phony: all clean |
15 | 16 |
|
... | ... |
@@ -26,6 +27,7 @@ Tools.o: Tools.c Tools.h |
26 | 27 |
|
27 | 28 |
BlinkenLib.a: BlinkenFrame.o BlinkenMovie.o Tools.o |
28 | 29 |
$(AR) $(ARFLAGS) BlinkenLib.a BlinkenFrame.o BlinkenMovie.o Tools.o |
30 |
+ $(RANLIB) BlinkenLib.a |
|
29 | 31 |
|
30 | 32 |
BlinkenConv: BlinkenConv.c BlinkenLib.h BlinkenLib.a |
31 | 33 |
$(CC) $(LFLAGS) -o BlinkenConv BlinkenConv.c BlinkenLib.a |