- Copyright (C) Arturo San Emeterio Campos 1999. All rights reserved.
- Permission is granted to make verbatim copies of this file for private
- use only. There is ABSOLUTELY NO WARRANTY. Use it at your OWN RISK.
+ Copyright (C) Arturo San Emeterio Campos 1999. All rights reserved.
+ Permission is granted to make verbatim copies of this file for private
+ use only. There is ABSOLUTELY NO WARRANTY. Use it at your OWN RISK.
- This file is: "ppmcmain.c"
- Email: arturo@arturocampos.com
- Web: http://www.arturocampos.com
+ This file is: "ppmcmain.c"
+Email: arturo@arturocampos.com
+Web: http://www.arturocampos.com
- This module is the main module and calls the different modules to do
- the encoding of a file. When done prints bpb and kbyps.
+This module is the main module and calls the different modules to do
+the encoding of a file. When done prints bpb and kbyps.
- unsigned long counter, //temporal counter for loops like for or while
- counter2, //another temporal counter for sub loops
- size_file_input; //the size of the input file
+ unsigned long counter, //temporal counter for loops like for or while
+ counter2, //another temporal counter for sub loops
+ size_file_input; //the size of the input file
- // Print title, version and copyright
- printf("PPMC using range coder. (without exclusion)\n");
- printf("Copyright (C) Arturo San Emeterio Campos 1999. All rights reserved.\n");
- printf("Permission is granted to make verbatim copies of this program for private\n");
- printf("use only. There is ABSOLUTELY NO WARRANTY. Use it at your OWN RISK.\n");
+ // Print title, version and copyright
+ printf("PPMC using range coder. (without exclusion)\n");
+ printf("Copyright (C) Arturo San Emeterio Campos 1999. All rights reserved.\n");
+ printf("Permission is granted to make verbatim copies of this program for private\n");
+ printf("use only. There is ABSOLUTELY NO WARRANTY. Use it at your OWN RISK.\n");
- // Try to open input and output files
- if((file_input=fopen(argv[1],"r+b"))==NULL)
- {
- printf("Couldn't open %s.\n",argv[1]);
- exit(1);
- }
+ // Try to open input and output files
+ if((file_input=fopen(argv[1],"r+b"))==NULL)
+ {
+ printf("Couldn't open %s.\n",argv[1]);
+ exit(1);
+ }
- if((file_output=fopen(argv[2],"w+b"))==NULL)
- {
- printf("Couldn't create %s.\n",argv[2]);
- exit(1);
- }
+ if((file_output=fopen(argv[2],"w+b"))==NULL)
+ {
+ printf("Couldn't create %s.\n",argv[2]);
+ exit(1);
+ }
- // First output file length
- fwrite(&size_file_input,1,4,file_output); //input length
+ // First output file length
+ fwrite(&size_file_input,1,4,file_output); //input length
- // Initialize ppmc encoder
- ppmc_alloc_memory(); //get memory
- ppmc_initialize_contexts(); //initialize model
- ppmc_encoder_initialize();
+ // Initialize ppmc encoder
+ ppmc_alloc_memory(); //get memory
+ ppmc_initialize_contexts(); //initialize model
+ ppmc_encoder_initialize();
- // Initialize range coder
- range_coder_init(&rc_coder,file_output);
+ // Initialize range coder
+ range_coder_init(&rc_coder,file_output);
- // Try to code current byte under order-4 if possible then go to lower orders
- if(ppmc_code_byte_order4()==0)
- if(ppmc_code_byte_order3()==0)
- if(ppmc_code_byte_order2()==0)
- if(ppmc_code_byte_order1()==0)
- if(ppmc_code_byte_order0()==0) //else try to code under order-0
- {
- // Code under order-(-1)
- ppmc_get_prob_ordern1();
- range_coder_encode(&rc_coder,total_cump,symb_cump,symb_prob);
- coded_in_order=0; //update all the tables (unless order-(-1))
- }
+ // Try to code current byte under order-4 if possible then go to lower orders
+ if(ppmc_code_byte_order4()==0)
+ if(ppmc_code_byte_order3()==0)
+ if(ppmc_code_byte_order2()==0)
+ if(ppmc_code_byte_order1()==0)
+ if(ppmc_code_byte_order0()==0) //else try to code under order-0
+ {
+ // Code under order-(-1)
+ ppmc_get_prob_ordern1();
+ range_coder_encode(&rc_coder,total_cump,symb_cump,symb_prob);
+ coded_in_order=0; //update all the tables (unless order-(-1))
+ }
- switch(coded_in_order)
- {
- case 0: ppmc_update_order0(); //update only order-0
- case 1: ppmc_update_order1(); //update order-0 and order-1
- case 2: ppmc_update_order2(); //update order-2 1 and 0...
- case 3: ppmc_update_order3();
- case 4: ppmc_update_order4();
- default: break;
- };
+ switch(coded_in_order)
+ {
+ case 0: ppmc_update_order0(); //update only order-0
+ case 1: ppmc_update_order1(); //update order-0 and order-1
+ case 2: ppmc_update_order2(); //update order-2 1 and 0...
+ case 3: ppmc_update_order3();
+ case 4: ppmc_update_order4();
+ default: break;
+ };
- curpos = ftell(stream);
- fseek(stream, 0L, SEEK_END);
- length = ftell(stream);
- fseek(stream, curpos, SEEK_SET);
- return length;
+ curpos = ftell(stream);
+ fseek(stream, 0L, SEEK_END);
+ length = ftell(stream);
+ fseek(stream, curpos, SEEK_SET);
+ return length;