#include <stdio.h>

//#define BLOCK_LEN 318
#define BLOCK_LEN 424
//#define SKIP (8*636+318)
#define SKIP 5830
//#define SKIP 0
int main(int argc, char *argv[]) {
  FILE *out[3];
  FILE *input = fopen(argv[1], "r");
  if (!input) {
    perror("fopen");
    return 1;
  }
  if (fseek(input, SKIP, SEEK_SET) < 0) {
    perror("seek");
    return 1;
  }

  out[0] = fopen("g.raw", "w");
  if (!out[0]) {
    perror("fopen");
    return 1;
  }
  out[1] = fopen("b.raw", "w");
  if (!out[1]) {
    perror("fopen");
    return 1;
  }
  out[2] = fopen("r.raw", "w");
  if (!out[2]) {
    perror("fopen");
    return 1;
  }
  char buf[BLOCK_LEN];
  int i = 0;
  while (!feof(input)) {
    fread(buf, BLOCK_LEN, 1, input);
    fwrite(buf, BLOCK_LEN, 1, out[i++]);
    if (i > 2)
      i = 0;
  }

  fclose(out[2]);
  fclose(out[1]);
  fclose(out[0]);
  fclose(input);
  return 0;
}

