home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d01xx / d0165.lha / Parsnag / separate.c < prev   
C/C++ Source or Header  |  1988-11-22  |  2KB  |  88 lines

  1. /* separate.c; Epson color seperator - (c) 1987 DJH
  2.  
  3.     Use this program with files grabbed with PARSNAG to perform color
  4. separations on dithered color prints. Separate claims only to work on files
  5. created using Mike Paul's JX-80.12a printer driver. Quick hack; assumes all
  6. Epson cmds are 2-bytes except for the SET_GRAPHICS cmd, which is always
  7. preceded by a SET_COLOR.
  8.  
  9. */
  10.  
  11. #define ESC 0x1b
  12. #define SET_COLOR 0x72
  13. #define SET_GRAPHICS 0x4c
  14.  
  15. main(argc,argv)
  16. int argc;
  17. char *argv[];
  18. {
  19.   FILE *input,*output;
  20.   unsigned char buf,color;
  21.   short i;
  22.  
  23.   if (argc<3) { puts("Separate color[0,1,2,4] <input> <output>"); exit(0); }
  24.  
  25.   color=argv[1][0]-'0';
  26.  
  27.   input=fopen(argv[2],"r"); output=fopen(argv[3],"w");
  28.  
  29.   if (!input) { puts("input error!"); exit(0); }
  30.   if (!output) { puts("output error!"); fclose(input); exit(0); }
  31.  
  32.   while (fread(&buf,1,1,input)) { /* any characters left? */
  33.     if (buf!=ESC) {
  34.       fwrite(&buf,1,1,output);
  35.       continue;
  36.     }
  37.  
  38.     fread(&buf,1,1,input); /* ESC found, fetch command */
  39.  
  40.     if (buf!=SET_COLOR) {
  41.       putc(ESC,output); /* restore consumed ESC */
  42.  
  43.       fwrite(&buf,1,1,output); /* copy command */
  44.  
  45.       fread(&buf,1,1,input);   /* copy command's args */
  46.       fwrite(&buf,1,1,output); /* done, stream sync intact */
  47.  
  48.       continue;
  49.     }
  50.  
  51.    fread(&buf,1,1,input); /* ESC & SET_COLOR found, fetch argument */
  52.  
  53.    if (buf!=color) { /* filter this color? */
  54.      fread(&buf,1,1,input); /* skip over ESC */
  55.      fread(&buf,1,1,input); /* skip over SET_GRAPHICS */
  56.  
  57.      fread(&buf,1,1,input); /* fetch count lsb */
  58.  
  59.      i=buf;
  60.  
  61.      fread(&buf,1,1,input); /* fetch count msb */
  62.  
  63.      i+=(buf*256);
  64.  
  65.      fseek(input,i,1); /* skip graphics dump */
  66.    }
  67.    else { /* color found! */
  68.      putc(ESC,output); /* restore consumed chars */
  69.      putc(SET_COLOR,output);
  70.      putc(color,output);
  71.  
  72.      /* copy following ESC/SET_GRAPHICS/LSB */
  73.  
  74.      for (i=0;i<3;i++) { fread(&buf,1,1,input); fwrite(&buf,1,1,output); }
  75.  
  76.      i=buf; /* fetch lsb */
  77.  
  78.      fread(&buf,1,1,input); fwrite(&buf,1,1,output); /* fetch msb */
  79.  
  80.      for (i+=(buf*256);i;--i) { /* copy graphics dump */
  81.        fread(&buf,1,1,input); fwrite(&buf,1,1,output);
  82.      }
  83.    }
  84.   }
  85.  
  86.   fclose(input); fclose(output);
  87. }
  88.