home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / windows / x / 21051 < prev    next >
Encoding:
Text File  |  1993-01-12  |  4.9 KB  |  195 lines

  1. Path: sparky!uunet!ogicse!emory!gatech!concert!duke!khera
  2. From: khera@cs.duke.edu (Vivek Khera)
  3. Newsgroups: comp.windows.x
  4. Subject: Re: convert Sun suntool/xview icon image
  5. Message-ID: <KHERA.93Jan12104853@thneed.cs.duke.edu>
  6. Date: 12 Jan 93 15:48:53 GMT
  7. Article-I.D.: thneed.KHERA.93Jan12104853
  8. References: <1ithqiINN57p@guinan.cs.purdue.edu>
  9. Sender: news@duke.cs.duke.edu
  10. Followup-To: comp.windows.x
  11. Organization: Duke University CS Dept., Durham, NC
  12. Lines: 178
  13. Nntp-Posting-Host: thneed.cs.duke.edu
  14. In-reply-to: tzheng@cs.purdue.edu's message of 12 Jan 93 04:35:30 GMT
  15. X-Md4-Signature: 160bb85e9f7bcb17b1ce9c98c36e4dd5
  16.  
  17. In article <1ithqiINN57p@guinan.cs.purdue.edu> tzheng@cs.purdue.edu (Tom Zheng) writes:
  18.  
  19.    How can I convert icon image file in SunView/XVIEW to bitmap
  20.    or pixmap?
  21.  
  22. i wrote a program to convert all my old suntools (now known as
  23. SunView) icons into X bitmap format quite some time ago.  here it is
  24. for your enjoyment (run flex then gcc the result).  the conversion
  25. works on any sized sunview icon, but the output claims them all to be
  26. the stock 64x64.  just edit the output file to change the sizes
  27. defined and it will be fine.
  28.  
  29. --cut here--
  30.  /* flex portion of converter. V. Khera  07-JUL-1988
  31.   * assumes run through flex and gcc.
  32.   */
  33. %%
  34. "/*"    {    /* skip comments */
  35.         loop:
  36.         while (input() != '*');
  37.         switch (input()) {
  38.             case '/': break;
  39.             case '*': unput('*');
  40.             default: goto loop;
  41.         }
  42.     }
  43.  
  44. 0x[0-9A-F]+ {    /* convert each hex number into two with bits reversed */
  45.     static unsigned short num;
  46.     unsigned char hi,lo;    /* parts of bitmap */
  47.     extern int icount;
  48.     void flip_bits(unsigned char *);
  49.  
  50.     sscanf(yytext,"0x%hx",&num);    /* get into manipulable forms */
  51.     hi = (unsigned char)((num & 0xff00) >> 8);
  52.     lo = (unsigned char)(num & 0x00ff);
  53.     flip_bits(&hi);
  54.     flip_bits(&lo);
  55.     if (icount == 0) {
  56.         printf("   0x%02x, 0x%02x",hi,lo);
  57.     } else {
  58.         printf(",");
  59.         printf((icount % 12) ? " " : "\n   ");
  60.         printf("0x%02x, 0x%02x",hi,lo);
  61.     }
  62.     icount += 2;
  63.     }
  64.  
  65. .    /* ignore the rest */;
  66. \n    ;
  67.  
  68. %%
  69.  
  70. /*
  71.  * program to convert sun icon format files into X bitmap format files
  72.  *
  73.  * V. Khera    08-JUL-1988
  74.  */
  75.  
  76. static char rcs_id[] = "$Id: suntox.lex,v 1.5 90/10/22 13:00:58 khera Exp $";
  77.  
  78. #define BITMAP_EXT    ".xbm"
  79.  
  80. char outfile[1024];    /* long enough, i hope */
  81. char *infile;        /* points to argv[i] */
  82. int icount = 0;        /* count number of items output per file */
  83.  
  84. #include <string.h>
  85. char *rindex(const char *, char);
  86. void convert(const char*, char*);
  87.  
  88. main(int argc, char **argv)
  89. {
  90.     char *i;
  91.  
  92.     if (argc < 2) {
  93.         fprintf(stderr,"usage:%s <icon file> ...\n",argv[0]);
  94.         fprintf(stderr,
  95.             "Convert Sun icon format files into X bitmap files\n");
  96.         exit (1);
  97.     }
  98.  
  99.     for (++argv ;infile = *argv; argv++) {
  100.         strcpy(outfile,infile);
  101.         if (i=rindex(outfile,'.')) *i = '\0';
  102.         strcat(outfile,BITMAP_EXT);
  103.  
  104.         convert(infile,outfile);
  105.     }
  106.     return 0;
  107. }
  108.  
  109. /*
  110.  * converts each word read in into 2 chars with bit order reversed.
  111.  */
  112.  
  113. void convert(const char *infname, char *outfname)
  114. {
  115.     int Xwidth = 64;    /* default width */
  116.     int Xheight = 64;    /* default height */
  117.     int Swidth = -1;    /* Sun icon width */
  118.     int Sheight = -1;    /* Sun icon height */
  119.     register int i;
  120.     char *p;
  121.  
  122.     fprintf(stderr,"converting %s to %s\n",infname,outfname);
  123.     if ((freopen(infname,"r",stdin)) == NULL) {
  124.         fprintf(stderr,"cannot open %s\n",infname);
  125.         return;
  126.     }
  127.     if ((freopen(outfname,"w",stdout)) == NULL) {
  128.         fprintf(stderr,"cannot open %s\n",outfname);
  129.         return;
  130.     }
  131.  
  132.     /*
  133.      * get size information from Sun icon header
  134.      */
  135.     do {
  136.         i = fscanf(stdin, "%*[^HW*]");
  137.         if (i == EOF)
  138.             break;
  139.         switch(i = getc(stdin)) {
  140.         case 'H':
  141.             fscanf(stdin, "eight=%d", &Sheight);
  142.             break;
  143.         case 'W':
  144.             fscanf(stdin, "idth=%d", &Swidth);
  145.             break;
  146.         case '*':
  147.             if ((i = getc(stdin)) == '/')
  148.                 i = 0;
  149.             else
  150.                 ungetc(i, stdin);
  151.             break;
  152.         }
  153.     } while (i != 0 && i != EOF);
  154.  
  155.     if (Sheight > 0) Xheight = Sheight;
  156.     if (Swidth > 0) Xwidth = Swidth;
  157.  
  158.     rewind(stdin);    /* confuses lex otherwise */
  159.  
  160.     /* we know that the name has a ".xbm" extension */
  161.     *(rindex(outfname,'.')) = '\0';    /* use for naming parts of structure */
  162.     if (p = rindex(outfname,'/')) outfname = p+1;    /* remove path name */
  163.  
  164.     icount = 0;
  165.     printf("#define %s_width %d\n",outfname, Xwidth);
  166.     printf("#define %s_height %d\n",outfname, Xheight);
  167.     printf("static char %s_bits[] = {\n",outfname);
  168.  
  169.     yylex();    /* do the grunt work */
  170.  
  171.     printf("};\n");    /* close up */
  172.  
  173. }
  174.  
  175. #define BIT (unsigned char)0x01
  176. #define BITSPERBYTE    8
  177.  
  178. void flip_bits(unsigned char *c)
  179. {
  180.     register unsigned char t = *c;    /* to play with */
  181.     register int count;
  182.  
  183.     *c = '\0';
  184.     for (count = 1; count <= BITSPERBYTE; count++) {
  185.         *c |= (t & BIT)<<(BITSPERBYTE-count);
  186.         t >>= 1;    /* shift bits over one */
  187.     }
  188. }
  189. --cut here--
  190. --
  191. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  192. Vivek Khera, Gradual Student/Systems Guy  Department of Computer Science
  193. Internet:   khera@cs.duke.edu             Box 90129
  194.             (MIME mail accepted)          Durham, NC 27708-0129 (919)660-6528
  195.