int decode(SchroBuffer *buffer, int n, OilProfile *prof, int type) { SchroArith *a; int i; int j; int x = 0; oil_profile_init (prof); for(j=0;j<10;j++){ a = schro_arith_new(); schro_arith_decode_init (a, buffer); switch (type) { case 0: oil_profile_start (prof); for(i=0;i<n;i++){ x += orig_arith_decode_bit (a, 0); } oil_profile_stop (prof); break; case 1: oil_profile_start (prof); for(i=0;i<n;i++){ x += ref_arith_decode_bit (a, 0); } oil_profile_stop (prof); break; case 2: oil_profile_start (prof); for(i=0;i<n;i++){ x += test_arith_decode_bit (a, 0); } oil_profile_stop (prof); break; } a->buffer = NULL; schro_arith_free(a); } return x; }
void encode (SchroBuffer *buffer, int n, int freq) { SchroArith *a; int i; int bit; a = schro_arith_new(); schro_arith_encode_init (a, buffer); for(i=0;i<n;i++){ bit = oil_rand_u8() < freq; schro_arith_encode_bit (a, 0, bit); } schro_arith_flush (a); a->buffer = NULL; schro_arith_free(a); }
static double schro_encoder_estimate_subband_arith (SchroEncoderFrame *frame, int component, int index, int quant_index) { int i; int j; int16_t *data; int16_t *line; int stride; int width; int height; int q; int quant_factor; int quant_offset; int estimated_entropy; SchroArith *arith; int position; arith = schro_arith_new (); schro_arith_estimate_init (arith); position = schro_subband_get_position (index); schro_subband_get (frame->iwt_frame, component, position, &frame->params, &data, &stride, &width, &height); quant_factor = schro_table_quant[quant_index]; quant_offset = schro_table_offset_1_2[quant_index]; if (index == 0) { for(j=0;j<height;j++) { line = OFFSET(data, j*stride); schro_arith_estimate_sint (arith, SCHRO_CTX_ZPZN_F1, SCHRO_CTX_COEFF_DATA, SCHRO_CTX_SIGN_ZERO, 0); for(i=1;i<width;i++) { q = schro_quantise(line[i] - line[i-1], quant_factor, quant_offset); schro_arith_estimate_sint (arith, SCHRO_CTX_ZPZN_F1, SCHRO_CTX_COEFF_DATA, SCHRO_CTX_SIGN_ZERO, q); } } } else { for(j=0;j<height;j++) { line = OFFSET(data, j*stride); for(i=0;i<width;i++) { q = schro_quantise(line[i], quant_factor, quant_offset); schro_arith_estimate_sint (arith, SCHRO_CTX_ZPZN_F1, SCHRO_CTX_COEFF_DATA, SCHRO_CTX_SIGN_ZERO, q); } } } estimated_entropy = 0; estimated_entropy += arith->contexts[SCHRO_CTX_ZPZN_F1].n_bits; estimated_entropy += arith->contexts[SCHRO_CTX_ZP_F2].n_bits; estimated_entropy += arith->contexts[SCHRO_CTX_ZP_F3].n_bits; estimated_entropy += arith->contexts[SCHRO_CTX_ZP_F4].n_bits; estimated_entropy += arith->contexts[SCHRO_CTX_ZP_F5].n_bits; estimated_entropy += arith->contexts[SCHRO_CTX_ZP_F6p].n_bits; estimated_entropy += arith->contexts[SCHRO_CTX_COEFF_DATA].n_bits; estimated_entropy += arith->contexts[SCHRO_CTX_SIGN_ZERO].n_bits; schro_arith_free (arith); return estimated_entropy; }