PAQ8/orig/paq8o10t.cpp
// Split n bytes into blocks by type.  For each block, output
// <type> <size> and call encode_X to convert to type X.
Split n bytes into blocks by type.  For each block, output
  and call encode_X to convert to type X.
Split n bytes into blocks by type . For each block output and call encode_X to convert to type X .
void encode(FILE* in, FILE* out, int n) {
  Filetype type=DEFAULT;
  long begin=ftell(in);
  while (n>0) {
    Filetype nextType=detect(in, n, type);
    long end=ftell(in);
    fseek(in, begin, SEEK_SET);
    int len=int(end-begin);
    if (len>0) {
      fprintf(out, "%c%c%c%c%c", type, len>>24, len>>16, len>>8, len);
      switch(type) {
        case JPEG: encode_jpeg(in, out, len); break;
        case BMPFILE1:
        case BMPFILE4:
		case BMPFILE8:
		case BMPFILE24:
			encode_bmp(in, out, len); break;
		case PGMFILE: encode_pgm(in, out, len); break;
		case RGBFILE: encode_rgb(in, out, len); break;
        case EXE:  encode_exe(in, out, len, begin); break;
        default:   encode_default(in, out, len); break;
      }
    }
    n-=len;
    type=nextType;
    begin=end;
  }
}
void encode ( FILE * in , FILE * out , int n ) { Filetype type = DEFAULT ; long begin = ftell ( in ) ; while ( n > 0 ) { Filetype nextType = detect ( in , n , type ) ; long end = ftell ( in ) ; fseek ( in , begin , SEEK_SET ) ; int len = int ( end - begin ) ; if ( len > 0 ) { fprintf ( out , " " , type , len >> 24 , len >> 16 , len >> 8 , len ) ; switch ( type ) { case JPEG : encode_jpeg ( in , out , len ) ; break ; case BMPFILE1 : case BMPFILE4 : case BMPFILE8 : case BMPFILE24 : encode_bmp ( in , out , len ) ; break ; case PGMFILE : encode_pgm ( in , out , len ) ; break ; case RGBFILE : encode_rgb ( in , out , len ) ; break ; case EXE : encode_exe ( in , out , len , begin ) ; break ; default : encode_default ( in , out , len ) ; break ; } } n -= len ; type = nextType ; begin = end ; } }
Split n bytes into blocks by type.
Split n bytes into blocks by type .