static double measure_error_subband (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 skip = 1; double error = 0; int q; int quant_factor; int quant_offset; int value; int position; 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]; if (frame->params.num_refs > 0) { quant_offset = schro_table_offset_3_8[quant_index]; } else { quant_offset = schro_table_offset_1_2[quant_index]; } error = 0; if (index == 0) { for(j=0;j<height;j+=skip){ line = OFFSET(data, j*stride); for(i=1;i<width;i+=skip){ q = schro_quantise(abs(line[i] - line[i-1]), quant_factor, quant_offset); value = schro_dequantise(q, quant_factor, quant_offset); error += pow2(value - abs(line[i] - line[i-1])); } } } else { for(j=0;j<height;j+=skip){ line = OFFSET(data, j*stride); for(i=0;i<width;i+=skip){ q = schro_quantise(line[i], quant_factor, quant_offset); value = schro_dequantise(q, quant_factor, quant_offset); error += pow2(value - line[i]); } } } error *= skip*skip; return error; }
static void quantise_dc_block (SchroFrameData *block, int16_t *quant_data, int quant_index, int slice_x, int slice_y) { int quant_factor; int quant_offset; int x,y; int n = 0; int pred_value; int16_t *line; quant_factor = schro_table_quant[quant_index]; quant_offset = schro_table_offset_1_2[quant_index]; for(y=0;y<block->height;y++){ line = OFFSET(block->data, block->stride * y); for (x=0; x<block->width; x++){ pred_value = schro_dc_predict (line + x, block->stride, slice_x + x, slice_y + y); quant_data[n] = schro_quantise (line[x] - pred_value, quant_factor, quant_offset); line[x] = pred_value + schro_dequantise (quant_data[n], quant_factor, quant_offset); n++; } } }
static double error_pow(int x, void *priv) { ErrorFuncInfo *efi = priv; int q; int value; int y; q = schro_quantise (x, efi->quant_factor, efi->quant_offset); value = schro_dequantise (q, efi->quant_factor, efi->quant_offset); y = abs (value - x); return pow (y, efi->power); }
static void quantise_block (SchroFrameData *block, int16_t *quant_data, int quant_index) { int quant_factor; int quant_offset; int x,y; int n = 0; int16_t *line; quant_factor = schro_table_quant[quant_index]; quant_offset = schro_table_offset_1_2[quant_index]; for(y=0;y<block->height;y++){ line = OFFSET(block->data, block->stride * y); for (x=0; x<block->width; x++){ quant_data[n] = schro_quantise (line[x], quant_factor, quant_offset); n++; } } }
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; }