home *** CD-ROM | disk | FTP | other *** search
/ CD-X 3 / cdx_03.iso / melyviz / crosfade.arj / CROSMAKE.ZIP / CROSMAKE.C next >
Encoding:
C/C++ Source or Header  |  1994-09-29  |  2.4 KB  |  122 lines

  1. #include "alloc.h"
  2. #include "io.h"
  3. #include "fcntl.h"
  4. #include "conio.h"
  5. #include "sys/stat.h"
  6.  
  7.  
  8.  
  9.  
  10.  
  11. char pal[48];
  12. char pal2[48];
  13.  
  14.  
  15. int readstuff(const char *filename,void far *buf,unsigned length)
  16. {
  17.    int handle, bytes;
  18.  
  19.  
  20.    if ((handle =
  21.       sopen(filename, O_RDONLY | O_BINARY, S_IWRITE | S_IREAD)) == -1)
  22.    {
  23.       printf("Error Opening File\n");
  24.       exit(1);
  25.    }
  26.  
  27.    if ((bytes = read(handle, buf, length)) == -1) {
  28.       printf("Read Failed.\n");
  29.       exit(1);
  30.    }
  31.    close(handle);
  32.    return 0;
  33. }
  34.  
  35.  
  36.  
  37. void main()
  38. {  unsigned n,n2,n3;
  39.    int handle;
  40.    char ch[2];
  41.    char string[20];
  42.    char far *firstimage,*secondimage,*workingbuffer;
  43.  
  44.  
  45.  
  46.    workingbuffer=farmalloc(65000);
  47.  
  48.    printf("First RAW image file?\n");
  49.    gets(string);
  50.    firstimage=farmalloc(65000);
  51.    readstuff(&string,firstimage,64000);
  52.  
  53.    printf("First Palette file?\n");
  54.    gets(string);
  55.    readstuff(&string,&pal,48);
  56.  
  57.    printf("Second RAW image file?\n");
  58.    gets(string);
  59.    secondimage=farmalloc(65000);
  60.    readstuff(&string,secondimage,64000);
  61.  
  62.    printf("Second Palette file?\n");
  63.    gets(string);
  64.    readstuff(&string,&pal2,48);
  65.  
  66.  
  67.    printf("Output raw file name?\n");
  68.    gets(string);
  69.  
  70.  
  71. /* Now we loaded all the data, let's begin processing */
  72.  
  73.    if ((handle = creat(string, S_IREAD | S_IWRITE)) != -1)
  74.    {
  75.     for(n=0;n<64000;++n)
  76.     { ch[0]=firstimage[n]<<4;
  77.       ch[0]=ch[0]+secondimage[n];
  78.       workingbuffer[n]=ch[0];
  79.     }
  80.  
  81.     /* Save the processed bitmap image */
  82.     _write(handle,workingbuffer,64000);
  83.     close(handle);
  84.  
  85.     handle=open("pal1.pal", O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  86.     n2=0;
  87.     for(n3=0;n3<16;++n3)
  88.      for(n=0;n<16;++n)
  89.      {workingbuffer[n2]=pal[n3*3];
  90.       ++n2;
  91.       workingbuffer[n2]=pal[n3*3+1];
  92.       ++n2;
  93.       workingbuffer[n2]=pal[n3*3+2];
  94.       ++n2;
  95.      }
  96.     /* Save Palette 1 */
  97.     _write(handle,workingbuffer,768);
  98.     close(handle);
  99.  
  100.     handle=open("pal2.pal", O_WRONLY | O_CREAT | O_TRUNC,S_IREAD | S_IWRITE);
  101.  
  102.     for(n2=0;n2<16;++n2)
  103.     {for(n=0;n<48;++n)
  104.       { workingbuffer[n2*48+n]=pal2[n];
  105.  
  106.       }
  107.     }
  108.     /* Save Palette 2 */
  109.     _write(handle,workingbuffer,768);
  110.     close(handle);
  111.  
  112.     farfree(workingbuffer);
  113.     farfree(firstimage);
  114.     farfree(secondimage);
  115.     printf("DONE.\n");
  116.    }
  117.    else
  118.     printf("file create error!\n");
  119.  
  120.    printf("crosfade.exe written by Esak 1994");
  121. }
  122.