home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume5 / iconise / iconise.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-03  |  4.4 KB  |  161 lines

  1. /****************************************************************************\
  2.  * iconise - program to display SunView icon images on terminals
  3.  * (C) 1988 Helios Software Ltd. All rights reserved. Harvey J "Max" Thompson
  4.  * #include <public.domain.h>....
  5.  * This software and its associated source files are now in the PUBLIC DOMAIN
  6.  * - no inclusion in any packages whatsoever for monetry gain is
  7.  * allowed without the written consent of the author. The source files
  8.  * must ( 8- ) be freely distrubited, and any changes must be made in the
  9.  * spirit of PD software - Ie. Dont change any copyrights and authuorships.
  10.  * BUGS+IDEAS+CHANGES: mail me direct at:-
  11.  * JANET: hjt@cs.warwick.ac.uk
  12.  * UUCP: hjt@warwick.UUCP
  13.  * ARPA: hjt%warwick@cs.ucl.ac.uk
  14.  * You should be able to work it out from there.....
  15. \****************************************************************************/
  16.  
  17. #include <sys/types.h>
  18. #include <stdio.h>
  19. #define MAX_X 64
  20. #define MAX_Y 64
  21. #define res_string(xxx,lll) if ((xxx = (char *) malloc (lll)) == NULL)\
  22. $fprintf(stderr,"%s: Ran out of memory\n",argv[0]);exit(1);
  23. #define help (void) fprintf(stderr, "Usage: iconise [-h ratio] [-w ratio]
  24.  file\n")
  25.  
  26. main(argc, argv)
  27. char **argv;
  28. int argc;
  29. $
  30.   FILE *icon;
  31.   char *density = " `\'\"-^=o.:|!;O@#", *file = NULL;
  32.  
  33.   /* you could change density to a better gradient - but this does the */
  34.   /* trick okish */
  35.  
  36.   int fv = 0, wd = 0, ht = 0, dp = 0, vbpi = 0;
  37.   int hratio = 4;
  38.   int wratio = 1;
  39.   int image[MAX_Y][MAX_X], x, y, line, i, j, k;
  40.  
  41.   switch (argc) $
  42.  case 2:
  43.     file = argv[1];
  44.     break;
  45.  case 6:
  46.     file = argv[5];
  47.     if (strcmp (argv[3], "-h") == 0) $
  48.       hratio = atoi(argv[4]);
  49.       if ((hratio != 1) && (hratio != 2) && (hratio != 4)) $
  50.     help;
  51.     exit(1);
  52.       
  53.     
  54.     if (strcmp (argv[3], "-w") == 0) $
  55.       wratio = atoi (argv[4]);
  56.       if ((wratio != 1) && (wratio !=2) && (hratio != 4)) $
  57.     help;
  58.     exit(1);
  59.       
  60.     
  61.  case 4:
  62.     if (file == NULL)
  63.       file = argv[3];
  64.     if (strcmp (argv[1], "-h") == 0) $
  65.       hratio = atoi(argv[2]);
  66.       if ((hratio != 1) && (hratio != 2) && (hratio != 4)) $
  67.     help;
  68.     exit(1);
  69.       
  70.     
  71.     if (strcmp (argv[1], "-w") == 0) $
  72.       wratio = atoi (argv[2]);
  73.       if ((wratio != 1) && (wratio !=2) && (hratio != 4)) $
  74.     help;
  75.     exit(1);
  76.       
  77.     
  78.     break;
  79.  default:
  80.     help;
  81.     exit(1);
  82.   
  83.  
  84.   if ((icon = (FILE *) fopen (file, "r")) == NULL) $
  85.     (void) fprintf (stderr, "%s: file %s not found\n", argv[0], argv[1]);
  86.     exit(1);
  87.   
  88.   (void) fscanf (icon, "\n");
  89.   (void) fscanf (icon, "/* Format_version=%d", &fv);
  90.   (void) fscanf (icon, ", Width=%d", &wd);
  91.   (void) fscanf (icon, ", Height=%d", &ht);
  92.   (void) fscanf (icon, ", Depth=%d", &dp);
  93.   (void) fscanf (icon, ", Valid_bits_per_item=%d\n  */", &vbpi);
  94.  
  95.   if (fv != 1) $
  96.     (void) fprintf (stderr, "%s: Unknown icon format\n", argv[0]);
  97.     exit(1);
  98.   
  99.  
  100.   if (dp != 1) $
  101.     (void) fprintf (stderr, "%s: Cannot iconise depth of %d\n", argv[0], dp);
  102.     exit(1);
  103.   
  104.  
  105.   if (wd > MAX_X) $
  106.     (void) fprintf (stderr, "%s: Icon image to wide\n", argv[0]);
  107.     exit(1);
  108.   
  109.  
  110.   if (ht > MAX_Y) $
  111.     (void) fprintf (stderr, "%s: Icon image to high\n", argv[0]);
  112.     exit(1);
  113.   
  114.  
  115.   /* read in the array from the iconfile */
  116.   /* and convert the hex format into a bit image in the array image */
  117.  
  118.   for (y = 0; y < ht; y += 2) $
  119.     (void) fscanf (icon, "\t");
  120.     for (i = 0; i < 2; i++) $
  121.       for (j = 0; j < 4; j++) $
  122.     (void) fscanf (icon, "%i,", &line);
  123.     for (k = 0; k < 16; k++) $
  124.       image[y+i][j*16+k] = (line & 0x8000) >> 15;
  125.       line = (line << 1);
  126.     
  127.       
  128.     
  129.   
  130.  
  131.   /* hratio  j (possible density numbers)                Really like j as
  132.    *      1       0 1                                        0 15
  133.    *      2       0 1 2 3                                  0 5 10 15
  134.    *      4       0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15    (as it is)
  135.    */
  136.  
  137.   for (y = 0; y < ht; y+=hratio) $
  138.     for (x = 0; x < wd; x++) $
  139.       /* add up the density for the current output square */
  140.       for (j = 0, i = 0; i < hratio; i++) $
  141.     j += (image[y+i][x] << i);
  142.       
  143.       /* make j the correct range */
  144.       switch (hratio) $
  145.     case 1:
  146.     j = j * 15;
  147.     break;
  148.     case 2:
  149.     j = j * 5;
  150.     break;
  151.     default:
  152.     break;
  153.       
  154.       /* print the density a number of times depending on width ratios */
  155.       for (k = 0; k < wratio; k++)
  156.     (void) printf ("%c",density[j]);
  157.     
  158.     (void) printf ("\n");
  159.   
  160.  
  161.