home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / dem2pov.zip / dem2pov.old < prev    next >
Text File  |  1997-11-15  |  20KB  |  583 lines

  1. /*        DEM2POV.C  v1.2a
  2.       convert dem to tga height-field for POV.
  3.       code modified by W. D. Kirby, 10 Aug. 96.
  4.       hacked from dem2xyz.c
  5.       converts 3 arc second to lat/long,  sol katz, mar. 94.
  6.       added sampling and cutting to size, sol katz, apr 94.
  7.       changed the calculation of start position in sampling code,
  8.       sol katz, jan 95.
  9.  
  10.       Persistence of Vision (POV) raytracer can use a height-field
  11.       defined in a Targa (.TGA) image file format where the RGB pixel values
  12.       are 24 bits (3 bytes). A 16 bit unsigned integer height-field value
  13.       is assigned as follows:
  14.  
  15.            Red     high byte
  16.            Green   low byte
  17.            Blue    empty
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <math.h>
  23.  
  24. void    getheader(FILE *);
  25. void    processProfiles(FILE *, FILE *);
  26. void    writeFile(FILE *, double, double);
  27. void    writeCount();
  28. void    writeHeader(FILE *);
  29.  
  30. #define     YMAX     2048          /*  max length of an NCIC scan line */
  31. #define     XMAX     2048          /*  max # of NCIC scan lines */
  32. #define MIN(x,y)     (((x) < (y)) ? (x) : (y))
  33. #define MAX(x,y)     (((x) > (y)) ? (x) : (y))
  34. #define SW     0
  35. #define NW     1
  36. #define NE     2
  37. #define SE     3
  38.  
  39. #ifndef M_PI
  40. #define M_PI        3.14159265358979323846
  41. #endif
  42.  
  43. int             base[XMAX];           /* array of base elevations */
  44. int             image[YMAX];          /* array for height-field */
  45. double          defaultElev = 0;      /* elevation for empty points */
  46. int             width, height;        /* height-field image width and height */
  47. int             hfType;               /* height-field type */
  48. double          hfBias, hfNorm = 1.0;
  49. double          verticalScale=1.0;    /* to stretch or shrink elevations */
  50. double          minValue=50000., maxValue=-50000.;
  51. char            mapLabel[145];
  52. int             DEMlevel, elevationPattern, groundSystem, groundZone;
  53. double          projectParams[15];
  54. int             planeUnitOfMeasure, elevUnitOfMeasure, polygonSizes;
  55. double          groundCoords[4][2], elevBounds[2], localRotation;
  56. int             accuracyCode;
  57. double          spatialResolution[3];
  58. int             profileDimension[2];
  59. int             firstRow, lastRow;
  60. int             wcount = 0, hcount;
  61. double          deltaY;
  62. char            inText[24], **junk;
  63. double          eastMost, westMost, southMost, northMost;
  64. int             eastMostSample,  westMostSample, southMostSample, northMostSample;
  65. int             rowCount, columnCount, r, c;
  66. long int        cellCount = 0 ;
  67. int             rowStr,rowEnd, colStr, colEnd, colInt=1, rowInt=1, outType=0 ;
  68.  
  69. int main(argc, argv)
  70. int argc;
  71. char *argv[];
  72. {
  73.    FILE       *inf, *outf;
  74.    double     comp;
  75.  
  76.    if (argc < 2) {
  77.       fprintf(stderr,"DEM to POV height-field v1.2 by W. D. Kirby 1/30/96 \n");
  78.       fprintf(stderr,"  based on DEM to x,y,z ascii file, ver 3.1, 1-95 -- Sol Katz, BLM \n\n");
  79.       (void) fprintf(stderr, "Usage: dem2pov dem_name [tga_file]\n");
  80.       (void) fprintf(stderr, "            dem_name only for header info\n");
  81.       exit(1);
  82.    }
  83.  
  84.    if ((inf = fopen(argv[1], "r")) == NULL) {
  85.       perror(argv[1]);
  86.       exit(1);
  87.    }
  88.    fprintf(stderr,"DEM to POV height-field v1.2 by W. D. Kirby 1/30/96 \n");
  89.    fprintf(stderr,"  based on DEM to x,y,z ascii file, ver 3.1, 1-95 -- Sol Katz, BLM \n");
  90.  
  91.    (void)getheader(inf);
  92.  
  93.    /* 3 second DEMs overlap next one by one row and column, others don't */
  94.  
  95.    if (spatialResolution[0] == 3.0) {
  96.       comp   = spatialResolution[0] - 1.0 ; 
  97.       deltaY = spatialResolution[1] / 3600.  ;
  98.    }
  99.    else {
  100.       comp   = 0.;
  101.       deltaY = spatialResolution[1] ;
  102.    }
  103.  
  104.    eastMost  = MAX(groundCoords[NE][0], groundCoords[SE][0]);
  105.    westMost  = MIN(groundCoords[NW][0], groundCoords[SW][0]);
  106.    northMost = MAX(groundCoords[NE][1], groundCoords[NW][1]);
  107.    southMost = MIN(groundCoords[SW][1], groundCoords[SE][1]);
  108.    eastMostSample =  ((int) (eastMost / spatialResolution[0]))
  109.       * (int) spatialResolution[0];
  110.    westMostSample =  ((int) (westMost / spatialResolution[0]))
  111.       * (int) spatialResolution[0] ;
  112.    northMostSample = ((int) (northMost / spatialResolution[1]))
  113.       * (int) spatialResolution[1] ;
  114.    southMostSample = ((int) (southMost / spatialResolution[1]))
  115.       * (int) spatialResolution[1] ;
  116.  
  117.    if (spatialResolution[0] == 3.0) { /* then it's a 1x1 degree DEM */
  118.       printf("eastMostSample  %10f, westMostSample  %10f\n",
  119.      eastMostSample/3600., westMostSample/3600.);
  120.       printf("northMostSample %10f, southMostSample %10f\n",
  121.      northMostSample/3600., southMostSample/3600.);
  122.    }
  123.  
  124.  
  125.    columnCount = (eastMostSample  - westMostSample)
  126.       / (int) spatialResolution[0] + 1;
  127.    rowCount    = (northMostSample - southMostSample)
  128.       / (int) spatialResolution[1] + 1;
  129.  
  130.    if (columnCount != profileDimension[1]) {
  131.       printf("       CALCULATED column Count %d != HEADER %d \n",
  132.      columnCount, profileDimension[1]);
  133.       printf("       will use SMALLER column Count \n");
  134.       columnCount =MIN( profileDimension[1], columnCount);
  135.    }
  136.  
  137.    printf("number of rows %d, number of columns %d\n",
  138.       rowCount, columnCount);
  139.  
  140.    if (argc > 2) {
  141.       if ((outf = fopen(argv[2], "wb")) == NULL) {
  142.      (void) fprintf(stderr, "can't open output file %s\n", argv[2]);
  143.      exit(1);
  144.       }
  145.    }
  146.    else { exit(0); }
  147.  
  148.       /* Interactive option entries */
  149.       colInt = 1 ;
  150.    rowInt = 1 ;
  151.    fprintf(stderr,"Enter 0 for all,  1 for samples,  2 for subset : ");
  152.    scanf("%d",&outType);
  153.  
  154.    /* default height-field image width and height */
  155.    width = rowCount;
  156.    height = columnCount;
  157.  
  158.    if ( outType == 1)   /* sample DEM file */
  159.    {
  160.       fprintf(stderr,"Enter column sample interval :");
  161.       scanf("%d",&colInt);
  162.       fprintf(stderr,"Enter row    sample interval :");
  163.       scanf("%d",&rowInt);
  164.       /* adjust deltaY */
  165.       deltaY = deltaY * rowInt;
  166.       /* image size */
  167.       width = rowCount/rowInt;
  168.       height = columnCount/colInt;
  169.    }
  170.    else if ( outType == 2)  /* output subset of DEM file */
  171.    {
  172.       fprintf(stderr,"Enter start column  :");
  173.       scanf("%d",&colStr);
  174.       fprintf(stderr,"Enter end   column  :");
  175.       scanf("%d",&colEnd);
  176.       fprintf(stderr,"Enter start row     :");
  177.       scanf("%d",&rowStr);
  178.       fprintf(stderr,"Enter end   row     :");
  179.       scanf("%d",&rowEnd);
  180.       /* image size */
  181.       width = rowEnd - rowStr + 1;
  182.       height = colEnd - colStr + 1;
  183.       rowStr--;   /* correct for 0 start index */
  184.       colStr--;
  185.    }
  186.  
  187.    fprintf(stderr,"Height-field type (0) Actual heights (1) Normalized : ");
  188.    scanf("%i",&hfType);
  189.  
  190.    /* For actual height-field values only */
  191.    if ( hfType == 0 ) {
  192.       fprintf(stderr,"Enter a vertical scaling factor : ");
  193.       scanf("%lf",&verticalScale);
  194.    }
  195.  
  196.    /* Since output must be unsigned */
  197.    if ( elevBounds[0] < 0.0 )
  198.       fprintf(stderr," Warning negative elevation values in input \n");
  199.  
  200.    fprintf(stderr,"Enter elevation bias: ");
  201.    scanf("%lf",&hfBias);
  202.  
  203.    fprintf(stderr,"Enter default elevation (final output units) : ");
  204.    scanf("%lf",&defaultElev);
  205.    if (defaultElev < 0.0) {
  206.       fprintf(stderr,"\nDefualt elevation must be => 0 \n");
  207.       exit(1);
  208.    }
  209.    fprintf(stderr,"\n");
  210.  
  211.    /* Normalize using max value of unsigned short integer (16 bit) */
  212.    if (hfType == 1) hfNorm = 65535.0/(elevBounds[1] + hfBias);
  213.  
  214.    /* adjust the end of the file */
  215.    if ( outType == 2 && columnCount > colEnd ) columnCount = colEnd;
  216.  
  217.    /* write TGA image file header */
  218.    (void) writeHeader(outf);
  219.  
  220.  
  221.    /* have to read everything */
  222.    (void) processProfiles(inf,outf);
  223.  
  224.    fprintf(stderr,"\n  %ld pixels were written to the file. \n",cellCount);
  225.    /*    writeCount(); */
  226.  
  227.    fprintf(stderr," For converted data points: \n");
  228.    fprintf(stderr,"      MinValue = %10.3f MaxValue = %10.3f \n", minValue, maxValue);
  229.  
  230.  
  231.    return 0;
  232. }
  233.  
  234. /*
  235.  * read profiles
  236.  */
  237.  
  238. void processProfiles(inputFile,outputFile)
  239. FILE           *inputFile,*outputFile;
  240. {
  241.    int             c, r, mod ;
  242.    int             count, tempInt, lastProfile = 0;
  243.  
  244.    int             profileID[2], profileSize[2];
  245.    double          planCoords[2], localElevation, elevExtremea[2];
  246.  
  247.    for (c = 1; c <= columnCount; c++) {
  248.       count = fscanf(inputFile, "%6d%6d%6d%6d",
  249.      &profileID[0],        /* 1 */
  250.      &profileID[1],        /* 1 */
  251.      &profileSize[0],      /* 2 */
  252.      &profileSize[1]);     /* 2 */
  253.       if (count != 4) {
  254.      fprintf(stderr, "\nshort read of %d on column %d\n",count, c);
  255.      fprintf(stderr,"\n  %ld pixels were written to the file. \n",cellCount);
  256.      /*      writeCount(); */
  257.      exit (1);
  258.       }
  259.       fscanf(inputFile,"%24c", inText);
  260.       inText[20] = 'E';
  261.       planCoords[0]   = strtod(inText,junk);     /* 3 */
  262.       fscanf(inputFile,"%24c", inText);
  263.       inText[20] = 'E';
  264.       planCoords[1]   = strtod(inText,junk);     /* 3 */
  265.       fscanf(inputFile,"%24c", inText);
  266.       inText[20] = 'E';
  267.       localElevation  = strtod(inText,junk);     /* 4 */
  268.       fscanf(inputFile,"%24c", inText);
  269.       inText[20] = 'E';
  270.       elevExtremea[0] = strtod(inText,junk);     /* 5 */
  271.       fscanf(inputFile,"%24c", inText);
  272.       inText[20] = 'E';
  273.       elevExtremea[1] = strtod(inText,junk);     /* 5 */
  274.  
  275.       /*     next 2 lines are a kludge to force the end of processing */
  276.       if ( profileID[1]-1 != lastProfile )
  277.       {
  278.      fprintf(stderr,"\n  %ld pixels were written to the file. \n",cellCount);
  279.      /* writeCount(); */
  280.      exit(0);
  281.       }
  282.       lastProfile =  profileID[1];
  283.       /*
  284.       printf("Column %d has %d samples              \r",
  285.                  profileID[1], profileSize[0]);
  286. */
  287.       firstRow = ((int) (planCoords[1] - southMostSample))
  288.      / (int) spatialResolution[1];
  289.       lastRow = firstRow + profileSize[0] - 1;
  290.  
  291.  
  292.       for ( r = 0 ; r < firstRow  ; r++ ) base[r] = defaultElev;
  293.  
  294.  
  295.       /* read in all the data for this column */
  296.       for (r = firstRow; r <= lastRow; r++ )
  297.       {
  298.      count = fscanf(inputFile, "%6d", &tempInt);
  299.      base[r] = tempInt;
  300.       }
  301.  
  302.       /* if cutting out a section, adjust the rows */
  303.       if ( outType == 2 )
  304.       {
  305.      if ( firstRow < rowStr )
  306.      {
  307.         firstRow = rowStr ;
  308.         /* adjust the ycoord */
  309.         /* suggested change */
  310.         planCoords[1] = planCoords[1] + ( firstRow - 1 ) * (deltaY);
  311.         /* ssk jan 3, 95:   i haven't checked if we need (deltaY / 3600.);*/
  312.         /* old version planCoords[1] = planCoords[1] + ( rowInt - 1 ) * deltaY;*/
  313.      }
  314.      if ( lastRow  > rowEnd ) lastRow  = rowEnd ;
  315.       }
  316.       mod = c % colInt;
  317.       if ( mod == 0 && c >= colStr )
  318.       {
  319.      /*         fprintf(stderr,"\n profile = %d , colINt = %d, mod = %d\n",c, mod); */
  320.  
  321.      writeFile(outputFile, planCoords[0], planCoords[1]);
  322.  
  323.       }
  324.    }
  325. }
  326.  
  327. /*
  328.  * write data to height-field file
  329.  *
  330.  */
  331.  
  332. void writeFile(outputFile, XCoord, YCoord)
  333. FILE           *outputFile;
  334. double         XCoord, YCoord;
  335. {
  336.    int             r, i;
  337.    double          tempFloat;
  338.  
  339.    /*   fprintf(stderr,"\n in writeFile %d %d %d %d \n",firstRow,lastRow,rowInt,wcount); */
  340.  
  341.    hcount = 0;
  342.  
  343.    /* fill empty cells */
  344.    if( firstRow > rowStr ) {
  345.       /* write leading empty pixels this DEM column as default elevation */
  346.       for (r = rowStr; r < firstRow; r += rowInt) {
  347.      putc((char)0, outputFile);                        /* Blue  empty     */
  348.      putc((char)((int)defaultElev % 256), outputFile); /* Green low byte  */
  349.      putc((char)((int)defaultElev / 256), outputFile); /* Red   high byte */
  350.      cellCount++ ;
  351.      hcount++;
  352.       }
  353.    }
  354.  
  355.    for (r = firstRow; r <= lastRow; r += rowInt) {
  356.  
  357.       /* now, scale the raw value */
  358.  
  359.       tempFloat = ( (float) base[r]  * verticalScale ) + hfBias;
  360.  
  361.       /* Normalize */
  362.       tempFloat *= hfNorm;
  363.       if(tempFloat < 0.0) tempFloat = 0.0;
  364.       if(tempFloat > 65535.0) tempFloat = 65535.0;
  365.  
  366.       if(tempFloat>maxValue) maxValue = tempFloat;
  367.       if(tempFloat<minValue) minValue = tempFloat;
  368.  
  369.       /* write pixel */
  370.       putc((char)0, outputFile);                       /* Blue  empty     */
  371.       putc((char)((int) tempFloat % 256), outputFile); /* Green low byte  */
  372.       putc((char)((int) tempFloat / 256), outputFile); /* Red   high byte */
  373.  
  374.       cellCount++ ;
  375.       /*    move up the delta y distance */
  376.       YCoord += deltaY;
  377.       hcount++;
  378.    }
  379.  
  380.  
  381.    /* write remaining pixels this column as default elevation */
  382.    if( hcount < width ) {
  383.       for (i = hcount; i < width; ++i) {
  384.      putc((char)0, outputFile);                        /* Blue  empty     */
  385.      putc((char)((int)defaultElev % 256), outputFile); /* Green low byte  */
  386.      putc((char)((int)defaultElev / 256), outputFile); /* Red   high byte */                 
  387.      cellCount++ ;
  388.       }
  389.    }
  390.  
  391.    wcount++;
  392. }
  393.  
  394. /*                                                               */
  395. /* Ref: USGS Digital Elevation Models - Data Users Guide 5, 1993 */
  396. /* Operates on old and new DEM header format.                    */
  397. /* However, new header format extention items are skipped over.  */
  398.  
  399. void getheader(inputFile)
  400. FILE           *inputFile;
  401. {
  402.      int             count,k,l;
  403.    int             profileID[2];
  404.  
  405.    count = fscanf(inputFile, "%144c%6i%6i%6i%6i",
  406.       mapLabel,              /* 1 and 2*/
  407.       &DEMlevel,             /* 3 */
  408.       &elevationPattern,     /* 4 */
  409.       &groundSystem,         /* 5 */
  410.       &groundZone );         /* 6 */
  411.    /*   printf(" 5 there were %d items read from the header\n", count); */
  412.  
  413.  
  414.    for ( k=0; k<15 ; k++) {
  415.       fscanf(inputFile,"%24c", inText);    /* 7 - Map projection parameters */
  416.       inText[20] = 'E';
  417.       projectParams[k]  = strtod(inText,junk);
  418.    }
  419.  
  420.    count = fscanf(inputFile,"%6i%6i%6i",
  421.       &planeUnitOfMeasure,   /* 8 */
  422.       &elevUnitOfMeasure,    /* 9 */
  423.       &polygonSizes);        /* 10 */
  424.    /*   printf("3 there were %d items read from the header\n", count); */
  425.  
  426.    for ( k=0; k < 4 ; k++) {         /* SW, NW, NE, SE corners */
  427.       for ( l=0; l < 2 ; l++) {      /* eastings then northings */
  428.     fscanf(inputFile,"%24c", inText);
  429.     inText[20] = 'E';
  430.     groundCoords[k][l] = strtod(inText,junk);  /* 11 */
  431.       }
  432.    }
  433.  
  434.    fscanf(inputFile,"%24c", inText);
  435.    inText[20] = 'E';
  436.    elevBounds[0] = strtod(inText,junk);      /* 12 */
  437.    fscanf(inputFile,"%24c", inText);
  438.    inText[20] = 'E';
  439.    elevBounds[1] = strtod(inText,junk);      /* 12 */
  440.    fscanf(inputFile,"%24c", inText);
  441.    inText[20] = 'E';
  442.    localRotation  = strtod(inText,junk);     /* 13 */
  443.  
  444.    /*   printf("11 there were %d items read from the header\n", count); */
  445.    fscanf(inputFile,"%6c", inText);
  446.    inText[6] = '\0';
  447.    accuracyCode = atoi(inText);                      /* 14 */
  448.    inText[12] = '\0';    /* terminate string buffer */
  449.    fscanf(inputFile,"%12c", inText);
  450.    spatialResolution[0] = (double) atof(inText);     /* 15 */
  451.    fscanf(inputFile,"%12c", inText);
  452.    spatialResolution[1] = (double) atof(inText);     /* 15 */
  453.    fscanf(inputFile,"%12c", inText);
  454.    spatialResolution[2] = (double) atof(inText);     /* 15 */
  455.    fscanf(inputFile,"%6d", &profileDimension[0]);    /* 16 */
  456.    fscanf(inputFile,"%6d", &profileDimension[1]);    /* 16 */
  457.    /*   printf("6 there were %d items read from the header\n",count); */
  458.  
  459.  
  460.    /* Skip over new header format extention items */
  461.  
  462.    /* Test for column and row data start */   
  463.    fscanf(inputFile, "%6d%6d",
  464.       &profileID[0],        /* 1 */
  465.       &profileID[1]);       /* 1 */
  466.    
  467.    if((profileID[0]!=1)||(profileID[1]!=1)) {
  468.       fseek(inputFile, 1024, 0);  /* new format */
  469.       printf("DEM Header Format: New \n");
  470.    }
  471.    else {
  472.       fseek(inputFile, 864, 0); /* old format */
  473.       printf("DEM Header Format: Old \n");;
  474.    }
  475.    
  476.    printf("[1&2] Map label: %s\n",mapLabel);        /* 1 and 2 */
  477.    printf("[ 3] DEM level:  %i\n",DEMlevel );
  478.    printf("[ 4] elevation pattern: %i  ",elevationPattern);
  479.    switch (elevationPattern) {
  480.    case 1:
  481.       printf("(=>regular) \n"); break;
  482.    case 2:
  483.       printf("(=>random ) \n"); break;
  484.    default:
  485.       printf("(=>?%i?   ) \n", elevationPattern);
  486.    }
  487.  
  488.    printf("[ 5] planimetric reference system: %i ", groundSystem);
  489.    switch (groundSystem) {
  490.    case 0:
  491.       printf("(=>georgraphic) \n"); break;
  492.    case 1:
  493.       printf("(=>UTM        ) \n"); break;
  494.    case 2:
  495.       printf("(=>State Plane) \n"); break;
  496.    default:
  497.       printf("(=>?%i?       ) \n", groundSystem);
  498.    }
  499.  
  500.    printf("[ 6] ground zone: %i\n", groundZone);
  501.    printf("[ 7] proj: %15.7f %15.7f %15.7f\n",
  502.       projectParams[0], projectParams[1], projectParams[2]);
  503.    printf("[ 7] proj: %15.7f %15.7f %15.7f\n",
  504.       projectParams[3], projectParams[4], projectParams[5]);
  505.    printf("[ 7] proj: %15.7f %15.7f %15.7f\n",
  506.       projectParams[6], projectParams[7], projectParams[8]);
  507.    printf("[ 7] proj: %15.7f %15.7f %15.7f\n",
  508.       projectParams[9], projectParams[10], projectParams[11]);
  509.    printf("[ 7] proj: %15.7f %15.7f %15.7f\n",
  510.       projectParams[12], projectParams[13], projectParams[14]);
  511.    printf("[ 8] plane unit of measure: %i ",planeUnitOfMeasure );
  512.  
  513.    switch(planeUnitOfMeasure) {
  514.    case 0:
  515.       printf("(=>radians )\n"); break;
  516.    case 1:
  517.       printf("(=>feet    )\n"); break;
  518.    case 2:
  519.       printf("(=>meters  )\n"); break;
  520.    case 3:
  521.       printf("(=>arc-sec )\n"); break;
  522.    default:
  523.       printf("(=>?%d?    )\n", planeUnitOfMeasure);
  524.    }
  525.  
  526.    printf("[ 9] elevation measurement units code: %i ",
  527.       elevUnitOfMeasure);
  528.    switch(elevUnitOfMeasure) {
  529.    case 1:
  530.       printf("(=>feet )\n"); break;
  531.    case 2:
  532.       printf("(=>meter   )\n"); break;
  533.    default:
  534.       printf("(=>?%d?   )\n", elevUnitOfMeasure); break;
  535.    }
  536.  
  537.    printf("[10] polygon sides: %i\n",polygonSizes );
  538.    printf("[11] ground coordinates\n");
  539.    printf("     NW (%14.5f, %14.5f)  NE (%14.5f, %14.5f)\n",
  540.       groundCoords[1][0], groundCoords[1][1],
  541.       groundCoords[2][0], groundCoords[2][1]);
  542.    printf("     SW (%14.5f, %14.5f)  SE (%14.5f, %14.5f)\n",
  543.       groundCoords[0][0], groundCoords[0][1],
  544.       groundCoords[3][0], groundCoords[3][1]);
  545.    printf("[12] elev. min: %15.5f, max: %15.5f, [14] accuracy code: %i\n",
  546.       elevBounds[0],elevBounds[1],accuracyCode);
  547.    printf("[13] rotation: %14.5f degrees\n", localRotation * 180.0/M_PI);
  548.    printf("[15] spatial resolution: %15.5f, %15.5f, %15.5f \n",
  549.       spatialResolution[0],spatialResolution[1],spatialResolution[2]);
  550.  
  551.    printf("[16] map size is %i x %i (row x columns)\n",
  552.       profileDimension[0], profileDimension[1]);
  553. }
  554.  
  555. void writeHeader(outputFile)
  556. FILE *outputFile;
  557. {
  558.    int i;
  559.  
  560.    fprintf(stderr," TGA header width = %i  height = %i \n", width, height);
  561.  
  562.    /* Write TGA image header */
  563.    for (i = 0; i < 10; i++)      /* 00, 00, 02, then 7 00's... */
  564.       if (i == 2)
  565.      putc((short)i, outputFile);
  566.       else
  567.      putc(0, outputFile);
  568.  
  569.    putc(0, outputFile); /* y origin set to "First_Line" */
  570.    putc(0, outputFile);
  571.  
  572.    putc((short)(width % 256), outputFile);  /* write width and height */
  573.    putc((short)(width / 256), outputFile);
  574.    putc((short)(height % 256), outputFile);
  575.    putc((short)(height / 256), outputFile);
  576.    putc(24, outputFile);  /* 24 bits/pixel (16 million colors!) */
  577.    putc(32, outputFile);  /* Bitmask, pertinent bit: top-down raster */
  578. }
  579.  
  580.  
  581.  
  582.  
  583.