home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Tex / Dvi / shdvi10b.zoo / src / imginfo.c < prev   
C/C++ Source or Header  |  1990-07-16  |  4KB  |  145 lines

  1. /*
  2.  *    IMGinfo program.
  3.  *
  4.  *        Displays statistics about GEM IMG-files.
  5.  *
  6.  *    This program is freely redistributable. You may modify and use this
  7.  *    program to your heart's content, so long as you send modifications
  8.  *    to Robert Stabl. It can be included in any distribution, commercial 
  9.  *    or otherwise, so long as the banner string defined in the constant
  10.  *    HEADER is not modified (except for the version number) and this banner
  11.  *    is printed on programs invocation, or can be printed on programs
  12.  *    invocation with the -? option.
  13.  *
  14.  *    For further information read the README file.
  15.  *
  16.  *      15.01.89        (C) copyright Robert Stabl.
  17.  *
  18.  *    15.07.90 v1.01  few changes for release (rbs)
  19.  */
  20.  
  21. #define VERSION        "1.01"
  22. #define HEADER        "IMGinfo - Version %s \275 1989/90 Robert Stabl\n"
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <tos.h>
  28.  
  29. int imgversion;
  30. int headlength;
  31. int nrplanes;
  32. int patlen;
  33. int pixelwidth;
  34. int pixelheight;
  35. int scpixwidth;
  36. int sclinenr;
  37. int scbytewidth;
  38. double cmwidth1;
  39. double cmheigh1;
  40. double cmwidth3;
  41. double cmheigh3;
  42. double inwidth1;
  43. double inheigh1;
  44. double inwidth3;
  45. double inheigh3;
  46.  
  47. static void usage(void)
  48. {
  49.  fprintf(stderr, HEADER, VERSION);
  50.  fprintf(stderr, "usage: IMGinfo imgfile ...\n");
  51. }
  52.  
  53. unsigned int ReadInt(FILE *fp)
  54. {
  55.  register unsigned int x = 0;
  56.  
  57.  x = fgetc(fp);
  58.  x <<= 8;
  59.  x |= fgetc(fp);
  60.  
  61.  return(x);
  62. }
  63.  
  64. void ReadHeader(FILE *fp)
  65. {
  66.  int i;
  67.  
  68.  imgversion  = (int)ReadInt(fp);
  69.  headlength  = (int)ReadInt(fp);
  70.  nrplanes    = (int)ReadInt(fp);
  71.  patlen      = (int)ReadInt(fp);
  72.  pixelwidth  = (int)ReadInt(fp);
  73.  pixelheight = (int)ReadInt(fp);
  74.  scpixwidth  = (int)ReadInt(fp);
  75.  sclinenr    = (int)ReadInt(fp);
  76.  
  77.  if (headlength >8)
  78.   {
  79.    fprintf(stderr, "Headlength (%d) too long",headlength);
  80.    for (i=8; i<= headlength; i++)
  81.     {
  82.      fgetc(fp);
  83.     }
  84.   }
  85.  cmwidth1  = (double)(((double)scpixwidth / 100) * 2.54);
  86.  cmheigh1  = (double)(((double)sclinenr / 100) * 2.54);
  87.  cmwidth3  = (double)(((double)scpixwidth / 300) * 2.54);
  88.  cmheigh3  = (double)(((double)sclinenr / 300) * 2.54);
  89.  inwidth1  = (double)(((double)scpixwidth / 100));
  90.  inheigh1  = (double)(((double)sclinenr / 100));
  91.  inwidth3  = (double)(((double)scpixwidth / 300));
  92.  inheigh3  = (double)(((double)sclinenr / 300));
  93. }
  94.  
  95. void PrintHeader(void)
  96. {
  97.  fprintf(stdout," measure in pixels:\n");
  98.  fprintf(stdout,"             width: %6d height: %6d\n\n",
  99.          scpixwidth, sclinenr);
  100.  fprintf(stdout," measure in cm:\n");
  101.  fprintf(stdout,"  300 dpi -- width: %6.3Lf height: %6.3Lf\n",
  102.          cmwidth3, cmheigh3);
  103.  fprintf(stdout,"  100 dpi -- width: %6.3Lf height: %6.3Lf\n\n",
  104.          cmwidth1, cmheigh1);
  105.  fprintf(stdout," measure in inch:\n");
  106.  fprintf(stdout,"  300 dpi -- width: %6.3Lf height: %6.3Lf\n",
  107.          inwidth3, inheigh3);
  108.  fprintf(stdout,"  100 dpi -- width: %6.3Lf height: %6.3Lf\n\n",
  109.          inwidth1, inheigh1);
  110.  fprintf(stdout," IMG statistics:\n");
  111.  fprintf(stdout,"  version number    : %d\n",imgversion);
  112.  fprintf(stdout,"  number of planes  : %d\n",nrplanes);
  113.  fprintf(stdout,"  width of 1 pixel  : %d\n",pixelwidth);
  114.  fprintf(stdout,"  height of 1 pixel : %d\n",pixelheight);
  115. }
  116.  
  117. main(int argc, char *argv[])
  118. {
  119.  FILE *imgfile;
  120.  int i;
  121.   
  122.  if (argc < 2)
  123.   {
  124.    usage();
  125.    return(1);
  126.   }
  127.  
  128.  fprintf(stdout, HEADER, VERSION);
  129.  
  130.  for (i=1; i<argc; i++)
  131.   {
  132.    imgfile = fopen(argv[i],"rb");
  133.    if (imgfile == NULL)
  134.     {
  135.      fprintf(stderr, "Can't open IMG file %s\n", argv[i]);
  136.      continue;
  137.     }
  138.    ReadHeader(imgfile);
  139.    fprintf(stdout, "Statistics for IMG file %s:\n", argv[i]);
  140.    PrintHeader();
  141.    fclose(imgfile);
  142.   }
  143.  return(0);
  144. }
  145.