105 fprintf(stderr,
"\n\n -> Arithmetic coding error: ");
107 fputs(
"\n Execution terminated!\n", stderr);
155 AC_Error(
"encoder not initialized");
161 unsigned init_base =
base;
179 AC_Error(
"decoder not initialized");
201 AC_Error(
"encoder not initialized");
202 if((bits < 1) || (bits > 20))
204 if(data >= (1U << bits))
208 unsigned init_base =
base;
225 AC_Error(
"decoder not initialized");
226 if((bits < 1) || (bits > 20))
247 AC_Error(
"encoder not initialized");
256 unsigned init_base =
base;
275 AC_Error(
"decoder not initialized");
279 unsigned bit = (
value >= x);
303 AC_Error(
"encoder not initialized");
315 unsigned init_base =
base;
337 AC_Error(
"decoder not initialized");
341 unsigned bit = (
value >= x);
371 AC_Error(
"encoder not initialized");
376 unsigned x, init_base =
base;
406 AC_Error(
"decoder not initialized");
409 unsigned n, s, x, y =
length;
422 unsigned m = (s + n) >> 1;
454 }
while((m = (s + n) >> 1) != s);
474 AC_Error(
"encoder not initialized");
479 unsigned x, init_base =
base;
513 AC_Error(
"decoder not initialized");
516 unsigned n, s, x, y =
length;
529 unsigned m = (s + n) >> 1;
561 }
while((m = (s + n) >> 1) != s);
590 unsigned char *user_buffer)
605 unsigned char *user_buffer)
608 if((max_code_bytes < 16) || (max_code_bytes > 0x1000000U))
609 AC_Error(
"invalid codec buffer size");
611 AC_Error(
"cannot set buffer while encoding or decoding");
628 AC_Error(
"cannot assign memory for compressed data buffer");
674 unsigned shift = 0, code_bytes = 0;
679 if((file_byte = getc(code_file)) == EOF)
680 AC_Error(
"cannot read code from file");
681 code_bytes |= unsigned(file_byte & 0x7F) << shift;
683 }
while(file_byte & 0x80);
687 if(fread(
code_buffer, 1, code_bytes, code_file) != code_bytes)
688 AC_Error(
"cannot read code from file");
700 AC_Error(
"invalid to stop encoder");
703 unsigned init_base =
base;
734 unsigned header_bytes = 0, code_bytes =
stop_encoder(), nb = code_bytes;
739 int file_byte = int(nb & 0x7FU);
742 if(putc(file_byte, code_file) == EOF)
743 AC_Error(
"cannot write compressed data to file");
747 if(fwrite(
code_buffer, 1, code_bytes, code_file) != code_bytes)
748 AC_Error(
"cannot write compressed data to file");
750 return code_bytes + header_bytes;
760 AC_Error(
"invalid to stop decoder");
780 if((p0 < 0.0001) || (p0 > 0.9999))
781 AC_Error(
"invalid bit probability");
821 unsigned scale = 0x80000000U /
bit_count;
850 const double probability[])
852 if((number_of_symbols < 2) || (number_of_symbols > (1 << 11)))
853 AC_Error(
"invalid number of data symbols");
863 unsigned table_bits = 3;
878 AC_Error(
"cannot assign model memory");
888 if((p < 0.0001) || (p > 0.9999))
889 AC_Error(
"invalid symbol probability");
906 if((sum < 0.9999) || (sum > 1.0001))
937 if((number_of_symbols < 2) || (number_of_symbols > (1 << 13)))
938 AC_Error(
"invalid number of data symbols");
948 unsigned table_bits = 3;
964 AC_Error(
"cannot assign model memory");
985 unsigned k, sum = 0, s = 0;