Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

rasterheader.cc

Go to the documentation of this file.
00001 /* gcc -O rasterheader.c  -o rasterheader
00002  prog to create a header...
00003 */
00004 
00005 using namespace std;
00006 #include <cstdio>
00007 #include <unistd.h>
00008 #include <cstdlib>
00009 #include <netinet/in.h>                 // ntohl byteorder x86-HP unix
00010 
00011 int main (int argc,char *argv[])
00012 {
00013   FILE *ofp;
00014   int c;
00015   //int bflg, aflg, errflg;
00016   extern char *optarg;
00017   //extern int optind, optopt;
00018 
00019   int header[8];
00020   int width,height,depth,datatype,length,maplength,maptype;
00021 
00022   int wrong=0;
00023   int computelength=1;
00024 
00025   /* defaults */
00026   width       = 0;
00027   height      = 0;
00028   depth       = 8;
00029   length      = 0;
00030   datatype    = 0;
00031   maplength   = 0;
00032   maptype     = 0;
00033 
00034   while ((c = getopt(argc, argv, "w:h:d:t:l:L:m:")) != -1)
00035     {
00036     switch (c)
00037       {
00038       case 'w':
00039                        width  = atoi(optarg);
00040                        break;
00041       case 'h':
00042                        height = atoi(optarg);
00043                        break;
00044       case 'd':
00045                        depth  = atoi(optarg);
00046                        break;
00047       case 't':
00048                        datatype  = atoi(optarg);
00049                        break;
00050       case 'l':
00051                        maplength = atoi(optarg);
00052                        break;
00053       case 'L':
00054                        length = atoi(optarg);
00055                        computelength = 0;
00056                        break;
00057       case 'm':
00058                        maptype = atoi(optarg);
00059                        break;
00060       case '?':
00061                        wrong = 1;
00062                        break;
00063     }
00064   }
00065   if ( width  == 0 ) wrong=1;
00066   if ( height == 0 ) wrong=1;
00067   /* check input */
00068   if ( wrong == 1 ) 
00069     {
00070     fprintf(stderr, "PROG: write header for sunraster file\n");
00071     fprintf(stderr, "  can be used together with cat.\n");
00072     fprintf(stderr, "  e.g. 1) make header\n");
00073     fprintf(stderr, "       2) cat header datafile > sunrasterfile.ras\n");
00074     fprintf(stderr, "\n");
00075     fprintf(stderr, "SYNOPSIS: prog -w width -h height [-ddepth]\n");
00076     fprintf(stderr, "               [-Ldatalength] [-tdatatype] [-mmaptype]\n");
00077     fprintf(stderr, "               [-lmaplength]\n");
00078     fprintf(stderr, "\n");
00079     fprintf(stderr, "USAGE (a SUNraster header is defined as 8 integers):\n");
00080     fprintf(stderr, "    ras_magic:     [0x59a66a95] magic number\n");
00081     fprintf(stderr, " -w ras_width:     [0]          width (pixels) of image\n");
00082     fprintf(stderr, " -h ras_height:    [0]          height (pixels) of image\n");
00083     fprintf(stderr, " -d ras_depth:     [8]          depth (1, 8, or 24 bits) of pixel\n");
00084     fprintf(stderr, " -L ras_length:    [computed]   length (bytes) of image\n");
00085     fprintf(stderr, " -t ras_type:      [0]          type of file; see RT_* below\n");
00086     fprintf(stderr, " -m ras_maptype:   [0]          type of colormap; see RMT_* below\n");
00087     fprintf(stderr, " -l ras_maplength: [0]          length (bytes) of following map\n");
00088     fprintf(stderr, "\n");
00089 
00090     fprintf(stderr, "   /* Sun supported ras_type's RT_ */\n");
00091     fprintf(stderr, "0       Raw pixrect image in 68000 byte order \n");
00092     fprintf(stderr, "1       Raw pixrect image in 68000 byte order \n");
00093     fprintf(stderr, "2       Run-length compression of bytes \n");
00094     fprintf(stderr, "3       XRGB or RGB instead of XBGR or BGR \n");
00095     fprintf(stderr, "4       tiff <-> standard rasterfile \n");
00096     fprintf(stderr, "5       iff (TAAC format) <-> standard rasterfile \n");
00097     fprintf(stderr, "0xffff  Reserved for testing \n");
00098     fprintf(stderr, "\n");
00099     fprintf(stderr, "   /* Sun registered ras_maptype's RMT_ */ \n");
00100     fprintf(stderr, "0       ras_maplength is expected to be 0 \n");
00101     fprintf(stderr, "1       red[ras_maplength/3],green[],blue[] \n");
00102     fprintf(stderr, "2       RMT_RAW \n");
00103     fprintf(stderr, "\n");
00104 
00105     exit(1);
00106     }
00107 
00108   if (computelength==1) length = width * height * (int)(depth/8);
00109   fprintf(stderr, "\n");
00110   fprintf(stderr, "arguments used:");
00111   fprintf(stderr, "\n  width:     %i", width);
00112   fprintf(stderr, "\n  height:    %i", height);
00113   fprintf(stderr, "\n  depth:     %i", depth);
00114   fprintf(stderr, "\n  length:    %i", length);
00115   fprintf(stderr, "\n  datatype:  %i", datatype);
00116   fprintf(stderr, "\n  maptype:   %i", maptype);
00117   fprintf(stderr, "\n  maplength: %i", maplength);
00118   fprintf(stderr, "\n");
00119 
00120   header[0] = ntohl(0x59a66a95);        /* magic number, always same(?) */
00121   header[1] = ntohl(width);             /* #columns */
00122   header[2] = ntohl(height);            /* #rows */
00123   header[3] = ntohl(depth);             /* in bits  email s suchandt */
00124   header[4] = ntohl(length);            /* in bytes */
00125   header[5] = ntohl(datatype);          /* email s suchandt */
00126   header[6] = ntohl(maptype);           /* ... */
00127   header[7] = ntohl(maplength);         /* ... */
00128 
00129   /* Write SUN raster file */
00130   ofp=fopen("sunrasterheader","w");
00131   fwrite(header, sizeof(int), 8, ofp);
00132   fclose(ofp);
00133   free(header);
00134   return 0;
00135 }
00136 
00137 
00138 

Generated on Fri Apr 22 15:57:58 2005 for Doris by doxygen 1.3.6