home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************\
- * iconise - program to display SunView icon images on terminals
- * (C) 1988 Helios Software Ltd. All rights reserved. Harvey J "Max" Thompson
- * #include <public.domain.h>....
- * This software and its associated source files are now in the PUBLIC DOMAIN
- * - no inclusion in any packages whatsoever for monetry gain is
- * allowed without the written consent of the author. The source files
- * must ( 8- ) be freely distrubited, and any changes must be made in the
- * spirit of PD software - Ie. Dont change any copyrights and authuorships.
- * BUGS+IDEAS+CHANGES: mail me direct at:-
- * JANET: hjt@cs.warwick.ac.uk
- * UUCP: hjt@warwick.UUCP
- * ARPA: hjt%warwick@cs.ucl.ac.uk
- * You should be able to work it out from there.....
- \****************************************************************************/
-
- #include <sys/types.h>
- #include <stdio.h>
- #define MAX_X 64
- #define MAX_Y 64
- #define res_string(xxx,lll) if ((xxx = (char *) malloc (lll)) == NULL)\
- $fprintf(stderr,"%s: Ran out of memory\n",argv[0]);exit(1);
- #define help (void) fprintf(stderr, "Usage: iconise [-h ratio] [-w ratio]
- file\n")
-
- main(argc, argv)
- char **argv;
- int argc;
- $
- FILE *icon;
- char *density = " `\'\"-^=o.:|!;O@#", *file = NULL;
-
- /* you could change density to a better gradient - but this does the */
- /* trick okish */
-
- int fv = 0, wd = 0, ht = 0, dp = 0, vbpi = 0;
- int hratio = 4;
- int wratio = 1;
- int image[MAX_Y][MAX_X], x, y, line, i, j, k;
-
- switch (argc) $
- case 2:
- file = argv[1];
- break;
- case 6:
- file = argv[5];
- if (strcmp (argv[3], "-h") == 0) $
- hratio = atoi(argv[4]);
- if ((hratio != 1) && (hratio != 2) && (hratio != 4)) $
- help;
- exit(1);
-
-
- if (strcmp (argv[3], "-w") == 0) $
- wratio = atoi (argv[4]);
- if ((wratio != 1) && (wratio !=2) && (hratio != 4)) $
- help;
- exit(1);
-
-
- case 4:
- if (file == NULL)
- file = argv[3];
- if (strcmp (argv[1], "-h") == 0) $
- hratio = atoi(argv[2]);
- if ((hratio != 1) && (hratio != 2) && (hratio != 4)) $
- help;
- exit(1);
-
-
- if (strcmp (argv[1], "-w") == 0) $
- wratio = atoi (argv[2]);
- if ((wratio != 1) && (wratio !=2) && (hratio != 4)) $
- help;
- exit(1);
-
-
- break;
- default:
- help;
- exit(1);
-
-
- if ((icon = (FILE *) fopen (file, "r")) == NULL) $
- (void) fprintf (stderr, "%s: file %s not found\n", argv[0], argv[1]);
- exit(1);
-
- (void) fscanf (icon, "\n");
- (void) fscanf (icon, "/* Format_version=%d", &fv);
- (void) fscanf (icon, ", Width=%d", &wd);
- (void) fscanf (icon, ", Height=%d", &ht);
- (void) fscanf (icon, ", Depth=%d", &dp);
- (void) fscanf (icon, ", Valid_bits_per_item=%d\n */", &vbpi);
-
- if (fv != 1) $
- (void) fprintf (stderr, "%s: Unknown icon format\n", argv[0]);
- exit(1);
-
-
- if (dp != 1) $
- (void) fprintf (stderr, "%s: Cannot iconise depth of %d\n", argv[0], dp);
- exit(1);
-
-
- if (wd > MAX_X) $
- (void) fprintf (stderr, "%s: Icon image to wide\n", argv[0]);
- exit(1);
-
-
- if (ht > MAX_Y) $
- (void) fprintf (stderr, "%s: Icon image to high\n", argv[0]);
- exit(1);
-
-
- /* read in the array from the iconfile */
- /* and convert the hex format into a bit image in the array image */
-
- for (y = 0; y < ht; y += 2) $
- (void) fscanf (icon, "\t");
- for (i = 0; i < 2; i++) $
- for (j = 0; j < 4; j++) $
- (void) fscanf (icon, "%i,", &line);
- for (k = 0; k < 16; k++) $
- image[y+i][j*16+k] = (line & 0x8000) >> 15;
- line = (line << 1);
-
-
-
-
-
- /* hratio j (possible density numbers) Really like j as
- * 1 0 1 0 15
- * 2 0 1 2 3 0 5 10 15
- * 4 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 (as it is)
- */
-
- for (y = 0; y < ht; y+=hratio) $
- for (x = 0; x < wd; x++) $
- /* add up the density for the current output square */
- for (j = 0, i = 0; i < hratio; i++) $
- j += (image[y+i][x] << i);
-
- /* make j the correct range */
- switch (hratio) $
- case 1:
- j = j * 15;
- break;
- case 2:
- j = j * 5;
- break;
- default:
- break;
-
- /* print the density a number of times depending on width ratios */
- for (k = 0; k < wratio; k++)
- (void) printf ("%c",density[j]);
-
- (void) printf ("\n");
-
-
-