#include <stdio.h>


FILE *ip, *op;
int red, green, blue, color, red1, green1, blue1;


void fskip(FILE *ip, int num_bytes)
{
  int i;
  for (i=0; i<num_bytes; i++)
    fgetc(ip);
}
  

int main (int argc, char *argv[])
{
 
  if ((ip = fopen (argv[1], "rb")) == NULL) 
    {
      printf("Cannot open input \n", argv[1]);
      return(1);
    }
  if ((op = fopen(argv[2], "wb")) == NULL)
    {
      printf("Cannont open output \n", argv[2]);
      return(2);
    }
    
  fskip(ip, 15);
    
  do
    {
      red1 = fgetc(ip);
      green1 = fgetc(ip);
      blue1 = fgetc(ip);
      
      red = red1 & 0xE0;
      green = green1 & 0xE0;
      green = green >> 3;
      blue = blue1 & 0xC0;
      blue = blue >> 6;
      
      color = red | green | blue;
      fputc(color, op);
            
    }while ((red1!=EOF) | (green1!=EOF) | (blue1!=EOF));
  printf("DONE \n");
  fclose(ip);
  fclose(op);
  return(0);
  
}
