diff options
-rw-r--r-- | apps/recorder/bmp.c | 356 |
1 files changed, 0 insertions, 356 deletions
diff --git a/apps/recorder/bmp.c b/apps/recorder/bmp.c index a92d521ce0..a35884c94c 100644 --- a/apps/recorder/bmp.c +++ b/apps/recorder/bmp.c | |||
@@ -69,18 +69,6 @@ struct RGBQUAD | |||
69 | unsigned char rgbReserved; | 69 | unsigned char rgbReserved; |
70 | } STRUCT_PACKED; | 70 | } STRUCT_PACKED; |
71 | 71 | ||
72 | #ifdef STANDALONE | ||
73 | static id_str[256]; | ||
74 | static bool compress = false; | ||
75 | static bool assembly = false; | ||
76 | static unsigned char* converted_bmp; | ||
77 | static unsigned char* compressed_bmp; | ||
78 | static unsigned int width; | ||
79 | static unsigned int converted_size; | ||
80 | static unsigned int compressed_size; | ||
81 | static unsigned int rounded_width; | ||
82 | #endif | ||
83 | |||
84 | #ifdef LITTLE_ENDIAN | 72 | #ifdef LITTLE_ENDIAN |
85 | #define readshort(x) x | 73 | #define readshort(x) x |
86 | #define readlong(x) x | 74 | #define readlong(x) x |
@@ -223,31 +211,6 @@ int read_bmp_file(char* filename, | |||
223 | *get_width = bitmap_width; | 211 | *get_width = bitmap_width; |
224 | *get_height = bitmap_height; | 212 | *get_height = bitmap_height; |
225 | 213 | ||
226 | #if 0 | ||
227 | /* Now convert the bitmap into an array with 1 byte per pixel, | ||
228 | exactly the size of the image */ | ||
229 | for(row = 0;row < bitmap_height;row++) { | ||
230 | bit = 7; | ||
231 | byte = 0; | ||
232 | for(col = 0;col < bitmap_width;col++) { | ||
233 | if((bmp[(bitmap_height - row - 1) * PaddedWidth + byte] & | ||
234 | (1 << bit))) { | ||
235 | |||
236 | bitmap[ (row/8) * bitmap_width + col ] |= 1<<(row&7); | ||
237 | } | ||
238 | else { | ||
239 | bitmap[ (row/8) * bitmap_width + col ] &= ~ 1<<(row&7); | ||
240 | } | ||
241 | if(bit) { | ||
242 | bit--; | ||
243 | } | ||
244 | else { | ||
245 | bit = 7; | ||
246 | byte++; | ||
247 | } | ||
248 | } | ||
249 | } | ||
250 | #else | ||
251 | /* Now convert the bitmap into an array with 1 byte per pixel, | 214 | /* Now convert the bitmap into an array with 1 byte per pixel, |
252 | exactly the size of the image */ | 215 | exactly the size of the image */ |
253 | 216 | ||
@@ -262,7 +225,6 @@ int read_bmp_file(char* filename, | |||
262 | } | 225 | } |
263 | } | 226 | } |
264 | 227 | ||
265 | #endif | ||
266 | free(bmp); | 228 | free(bmp); |
267 | 229 | ||
268 | } | 230 | } |
@@ -270,322 +232,4 @@ int read_bmp_file(char* filename, | |||
270 | return 0; /* success */ | 232 | return 0; /* success */ |
271 | } | 233 | } |
272 | 234 | ||
273 | #ifdef STANDALONE | ||
274 | |||
275 | /********************************************************************* | ||
276 | ** read_next_converted_byte() | ||
277 | ** | ||
278 | ** Reads the next 6-pixel chunk from the 1-byte-per-pixel array, | ||
279 | ** padding the last byte with zeros if the size is not divisible by 6. | ||
280 | **********************************************/ | ||
281 | unsigned char read_next_converted_byte(void) | ||
282 | { | ||
283 | unsigned char dest; | ||
284 | unsigned int i; | ||
285 | static unsigned int row = 0, col = 0; | ||
286 | |||
287 | dest = 0; | ||
288 | for(i = 0;i < 6 && col < bitmap_width;i++,col++) | ||
289 | { | ||
290 | if(bitmap[row * bitmap_width + col]) | ||
291 | { | ||
292 | dest |= (unsigned char)(1 << (5-i)); | ||
293 | } | ||
294 | } | ||
295 | |||
296 | if(col >= bitmap_width) | ||
297 | { | ||
298 | col = 0; | ||
299 | row++; | ||
300 | } | ||
301 | |||
302 | return dest; | ||
303 | } | ||
304 | |||
305 | /********************************************************************* | ||
306 | ** convert_image() | ||
307 | ** | ||
308 | ** Converts the 1-byte-per-pixel array into a 6-pixel-per-byte array, | ||
309 | ** i.e the BMP_FORMAT_VANILLA format. | ||
310 | **********************************************/ | ||
311 | void convert_image(void) | ||
312 | { | ||
313 | int newsize; | ||
314 | unsigned int row, col; | ||
315 | |||
316 | rounded_width = fh.Width/6 + ((fh.Width%6)?1:0); | ||
317 | newsize = rounded_width * fh.Height; | ||
318 | |||
319 | converted_bmp = (unsigned char *)malloc(newsize); | ||
320 | |||
321 | for(row = 0;row < fh.Height;row++) | ||
322 | { | ||
323 | for(col = 0;col < rounded_width;col++) | ||
324 | { | ||
325 | converted_bmp[row * rounded_width + col] = read_next_converted_byte(); | ||
326 | } | ||
327 | } | ||
328 | converted_size = rounded_width * fh.Height; | ||
329 | } | ||
330 | |||
331 | #define COMPRESSED_ZEROS_AHEAD 0x40 | ||
332 | #define COMPRESSED_ONES_AHEAD 0x80 | ||
333 | |||
334 | /********************************************************************* | ||
335 | ** compress_image() | ||
336 | ** | ||
337 | ** Compresses the BMP_FORMAT_VANILLA format with a simple RLE | ||
338 | ** algorithm. The output is in the BMP_FORMAT_RLE format. | ||
339 | **********************************************/ | ||
340 | void compress_image(void) | ||
341 | { | ||
342 | unsigned int i, j, count; | ||
343 | unsigned int index = 0; | ||
344 | unsigned char val; | ||
345 | |||
346 | compressed_bmp = (unsigned char *)malloc(converted_size); | ||
347 | |||
348 | for(i = 0;i < converted_size;i++) | ||
349 | { | ||
350 | val = converted_bmp[i]; | ||
351 | |||
352 | if(val == 0|| val == 0x3f) | ||
353 | { | ||
354 | count = 0; | ||
355 | while(count < 0x4000 && (i + count) < converted_size && | ||
356 | converted_bmp[i+count] == val) | ||
357 | { | ||
358 | count++; | ||
359 | } | ||
360 | if(count > 2) | ||
361 | { | ||
362 | compressed_bmp[index++] = (unsigned char) | ||
363 | (((val == 0)?COMPRESSED_ZEROS_AHEAD:COMPRESSED_ONES_AHEAD) | | ||
364 | (count >> 8)); | ||
365 | compressed_bmp[index++] = (unsigned char)(count & 0xff); | ||
366 | } | ||
367 | else | ||
368 | { | ||
369 | for(j = 0;j < count;j++) | ||
370 | { | ||
371 | compressed_bmp[index++] = val; | ||
372 | } | ||
373 | } | ||
374 | i += count - 1; | ||
375 | } | ||
376 | else | ||
377 | { | ||
378 | compressed_bmp[index++] = val; | ||
379 | } | ||
380 | } | ||
381 | |||
382 | compressed_size = index; | ||
383 | } | ||
384 | |||
385 | /********************************************************************* | ||
386 | ** generate_c_source() | ||
387 | ** | ||
388 | ** Outputs a C source code with the converted/compressed bitmap in | ||
389 | ** an array, accompanied by some #define's | ||
390 | **********************************************/ | ||
391 | void generate_c_source(char *id, BOOL compressed) | ||
392 | { | ||
393 | FILE *f; | ||
394 | unsigned int i; | ||
395 | unsigned int size; | ||
396 | unsigned char *bmp; | ||
397 | |||
398 | size = compressed?compressed_size:converted_size; | ||
399 | bmp = compressed?compressed_bmp:converted_bmp; | ||
400 | |||
401 | f = stdout; | ||
402 | |||
403 | fprintf(f, "#define %s_WIDTH %d\n", id, rounded_width * 6); | ||
404 | fprintf(f, "#define %s_HEIGHT %d\n", id, fh.Height); | ||
405 | fprintf(f, "#define %s_SIZE %d\n", id, size + 6); | ||
406 | if(compressed) | ||
407 | { | ||
408 | fprintf(f, "#define %s_ORIGINAL_SIZE %d\n", id, converted_size); | ||
409 | } | ||
410 | fprintf(f, "#define %s_FORMAT %s\n", id, | ||
411 | compressed?"BMP_FORMAT_RLE":"BMP_FORMAT_VANILLA"); | ||
412 | fprintf(f, "\nconst unsigned char bmpdata_%s[] = {", id); | ||
413 | |||
414 | /* Header */ | ||
415 | fprintf(f, "\n %s, 0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,", | ||
416 | compressed?"BMP_FORMAT_RLE":"BMP_FORMAT_VANILLA", | ||
417 | size >> 8, size & 0xff, 2, fh.Height, rounded_width * 6); | ||
418 | |||
419 | for(i = 0;i < size;i++) | ||
420 | { | ||
421 | if(i % 10 == 0) | ||
422 | { | ||
423 | fprintf(f, "\n "); | ||
424 | } | ||
425 | fprintf(f, "0x%02x,", bmp[i]); | ||
426 | } | ||
427 | fprintf(f, "\n};"); | ||
428 | } | ||
429 | |||
430 | /********************************************************************* | ||
431 | ** generate_asm_source() | ||
432 | ** | ||
433 | ** Outputs an ASM source code with the converted/compressed bitmap in | ||
434 | ** an array, the first 2 bytes describing the X and Y size | ||
435 | **********************************************/ | ||
436 | void generate_asm_source(char *id, BOOL compressed) | ||
437 | { | ||
438 | FILE *f; | ||
439 | unsigned int i; | ||
440 | unsigned int size; | ||
441 | unsigned char *bmp; | ||
442 | |||
443 | size = compressed?compressed_size:converted_size; | ||
444 | bmp = compressed?compressed_bmp:converted_bmp; | ||
445 | |||
446 | f = stdout; | ||
447 | |||
448 | fprintf(f, "bmpdata_%s:\n", id); | ||
449 | /* Header */ | ||
450 | fprintf(f, "\n db %s, %.2xh,%.2xh,%.2xh,%.2xh,%.2xh,", | ||
451 | compressed?"1":"0", | ||
452 | size >> 8, size & 0xff, 2, fh.Height, rounded_width * 6); | ||
453 | |||
454 | for(i = 0;i < size;i++) | ||
455 | { | ||
456 | if(i % 10 == 0) | ||
457 | { | ||
458 | fprintf(f, "\n db "); | ||
459 | } | ||
460 | fprintf(f, "%.2xh,", bmp[i]); | ||
461 | } | ||
462 | fprintf(f, "\n"); | ||
463 | } | ||
464 | |||
465 | void print_usage(void) | ||
466 | { | ||
467 | printf("bmp2mt - Converts BMP files to MT Pro source code format\n"); | ||
468 | printf("build date: " __DATE__ "\n\n"); | ||
469 | printf("Usage: %s [-i <id>] [-c] [-a] <bitmap file>\n" | ||
470 | "-i <id> Bitmap ID (default is filename without extension)\n" | ||
471 | "-c Compress (BMP_FORMAT_RLE)\n" | ||
472 | "-f Frexx Format!!!\n" | ||
473 | "-a Assembly format source code\n", APPLICATION_NAME); | ||
474 | } | ||
475 | |||
476 | #pragma argsused | ||
477 | int main(int argc, char **argv) | ||
478 | { | ||
479 | char *bmp_filename = NULL; | ||
480 | char *id = NULL; | ||
481 | char errstr[80]; | ||
482 | int i; | ||
483 | |||
484 | for(i = 1;i < argc;i++) | ||
485 | { | ||
486 | if(argv[i][0] == '-') | ||
487 | { | ||
488 | switch(argv[i][1]) | ||
489 | { | ||
490 | case 'i': /* ID */ | ||
491 | if(argv[i][2]) | ||
492 | { | ||
493 | id = &argv[i][2]; | ||
494 | } | ||
495 | else if(argc > i+1) | ||
496 | { | ||
497 | id = argv[i+1]; | ||
498 | i++; | ||
499 | } | ||
500 | else | ||
501 | { | ||
502 | print_usage(); | ||
503 | exit(1); | ||
504 | } | ||
505 | break; | ||
506 | |||
507 | case 'c': /* Compressed */ | ||
508 | compress = true; | ||
509 | break; | ||
510 | |||
511 | case 'a': /* Assembly */ | ||
512 | assembly = true; | ||
513 | break; | ||
514 | |||
515 | default: | ||
516 | print_usage(); | ||
517 | exit(1); | ||
518 | break; | ||
519 | } | ||
520 | } | ||
521 | else | ||
522 | { | ||
523 | if(!bmp_filename) | ||
524 | { | ||
525 | bmp_filename = argv[i]; | ||
526 | } | ||
527 | else | ||
528 | { | ||
529 | print_usage(); | ||
530 | exit(1); | ||
531 | } | ||
532 | } | ||
533 | } | ||
534 | |||
535 | if(!bmp_filename) | ||
536 | { | ||
537 | print_usage(); | ||
538 | exit(1); | ||
539 | } | ||
540 | |||
541 | if(!id) | ||
542 | { | ||
543 | id = strdup(bmp_filename); | ||
544 | |||
545 | for(i = 0;id[i];i++) | ||
546 | { | ||
547 | if(id[i] == ' ') | ||
548 | { | ||
549 | id[i] = '_'; | ||
550 | } | ||
551 | else if(id[i] == '.') | ||
552 | { | ||
553 | id[i] = '\0'; | ||
554 | break; | ||
555 | } | ||
556 | else | ||
557 | { | ||
558 | id[i] = (char)toupper(id[i]); | ||
559 | } | ||
560 | } | ||
561 | } | ||
562 | |||
563 | read_bmp_file(bmp_filename); | ||
564 | convert_image(); | ||
565 | if(fh.Width % 6) | ||
566 | { | ||
567 | |||
568 | sprintf(errstr, "warning - width is not divisible by 6 (%d), " | ||
569 | "padding with zeros to %d\n", fh.Width, rounded_width*6); | ||
570 | print_error(errstr, 0); | ||
571 | } | ||
572 | |||
573 | if(compress) | ||
574 | { | ||
575 | compress_image(); | ||
576 | } | ||
577 | |||
578 | if(assembly) | ||
579 | { | ||
580 | generate_asm_source(id, compress); | ||
581 | } | ||
582 | else | ||
583 | { | ||
584 | generate_c_source(id, compress); | ||
585 | } | ||
586 | return 0; | ||
587 | } | ||
588 | |||
589 | #endif | ||
590 | |||
591 | #endif /* 0 */ | 235 | #endif /* 0 */ |