home *** CD-ROM | disk | FTP | other *** search
/ Hot Shareware 32 / hot34.iso / ficheros / DGRAF / FRAIN196.ZIP / TRU.C < prev    next >
C/C++ Source or Header  |  1996-08-25  |  2KB  |  73 lines

  1. /* 
  2.   Fractint writes the escape iteration of fractal to a 24 bit Targa file
  3.   called ITERATES.TGA. This program reads that file and recovers the
  4.   iteration value. You can write your own truecolor mapping algorithm. It
  5.   should go in the routine rgbmap().
  6. */
  7.  
  8. #include <stdio.h>
  9.  
  10. static long maxi = -1;
  11.  
  12. void rgbmap(long maxiter, long iter,
  13.    unsigned char *r, unsigned char *g, unsigned char *b)
  14. {
  15.    if(iter > maxi)
  16.       maxi = iter;
  17.    *b = iter & 0xff;
  18.    *g = (iter>>8) & 0xff;
  19.    *r = (iter>>16) & 0xff;
  20. }
  21.  
  22. main()
  23. {
  24.    int xdots, ydots, i, j, err;
  25.    long iter, maxiter;
  26.    char red, green, blue;
  27.    FILE *fpin, *fpout;
  28.    char buf1[12];
  29.    char buf2[2];
  30.  
  31.    if((fpin = fopen("iterates.tga","rb"))==NULL)
  32.    {
  33.       fprintf(stderr,"Can't open flat.out\n");
  34.       exit(1);
  35.    }
  36.    if((fpout = fopen("new.tga","wb"))==NULL)
  37.    {
  38.       fprintf(stderr,"Can't open new.tga\n");
  39.       exit(1);
  40.    }
  41.  
  42.    fread (buf1,   12,1,fpin);    /* read 12 bytes */
  43.    fread (&xdots,  2,1,fpin);    /* read xdots */
  44.    fread (&ydots,  2,1,fpin);    /* read ydots */
  45.    fread (buf2,    2,1,fpin);    /* read 2 bytes */
  46.    fread (&maxiter,4,1,fpin);    /* read 4 bytes */
  47.    buf1[0] = 0; /* were not writing maxiter */
  48.    fwrite (buf1,  12,1,fpout);   /* write 12 bytes */
  49.    fwrite (&xdots, 2,1,fpout);   /* write xdots */
  50.    fwrite (&ydots, 2,1,fpout);   /* write ydots */
  51.    fwrite (buf2,   2,1,fpout);   /* write 2 bytes */
  52.  
  53.    printf("xdots %d ydots %d maxiter %ld\n",xdots,ydots,maxiter);
  54.  
  55.    for(j=0;j<ydots;j++)
  56.    {
  57. //      printf("row %2d maxi %6ld   \r",j,maxi);
  58.       for(i=0;i<xdots;i++)
  59.       {
  60.          iter = 0;
  61.          if((err=fread(&iter,3,1,fpin))==0)
  62.             exit(1);
  63.          printf("row %2d iter %6ld   \r",j,iter);
  64.          /* map iterations to colors */
  65.          rgbmap(maxiter,iter,&red,&green,&blue);
  66.          fwrite(&blue, 1,1,fpout);
  67.          fwrite(&green,1,1,fpout);
  68.          fwrite(&red,  1,1,fpout);
  69.       }
  70.    }
  71. }
  72.  
  73.