static void schro_decoder_decode_slice (SchroPicture *picture, SchroLowDelay *lowdelay, int slice_x, int slice_y, int offset, int slice_bytes) { SchroParams *params = &picture->params; SchroUnpack y_unpack; SchroUnpack uv_unpack; int quant_index; int base_index; int length_bits; int slice_y_length; int i; int j; int x,y; int value; schro_unpack_init_with_data (&y_unpack, OFFSET(picture->lowdelay_buffer->data, offset), slice_bytes, 1); base_index = schro_unpack_decode_bits (&y_unpack, 7); length_bits = ilog2up(8*slice_bytes); slice_y_length = schro_unpack_decode_bits (&y_unpack, length_bits); schro_unpack_copy (&uv_unpack, &y_unpack); schro_unpack_limit_bits_remaining (&y_unpack, slice_y_length); schro_unpack_skip_bits (&uv_unpack, slice_y_length); j = 0; for(i=0;i<1+3*params->transform_depth;i++) { int quant_factor; int quant_offset; int16_t *line; SchroFrameData block; schro_frame_data_get_codeblock (&block, lowdelay->luma_subbands + i, slice_x, slice_y, lowdelay->n_horiz_slices, lowdelay->n_vert_slices); quant_index = CLAMP(base_index - params->quant_matrix[i], 0, 60); 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++){ value = schro_unpack_decode_sint (&y_unpack); line[x] = schro_dequantise (value, quant_factor, quant_offset); } } } j = 0; for(i=0;i<1+3*params->transform_depth;i++) { int quant_factor; int quant_offset; int16_t *line1; int16_t *line2; SchroFrameData block1; SchroFrameData block2; schro_frame_data_get_codeblock (&block1, lowdelay->chroma1_subbands + i, slice_x, slice_y, lowdelay->n_horiz_slices, lowdelay->n_vert_slices); schro_frame_data_get_codeblock (&block2, lowdelay->chroma2_subbands + i, slice_x, slice_y, lowdelay->n_horiz_slices, lowdelay->n_vert_slices); quant_index = CLAMP(base_index - params->quant_matrix[i], 0, 60); quant_factor = schro_table_quant[quant_index]; quant_offset = schro_table_offset_1_2[quant_index]; for(y=0;y<block1.height;y++){ line1 = OFFSET(block1.data, block1.stride * y); line2 = OFFSET(block2.data, block2.stride * y); for (x=0; x<block1.width; x++){ value = schro_unpack_decode_sint (&uv_unpack); line1[x] = schro_dequantise (value, quant_factor, quant_offset); value = schro_unpack_decode_sint (&uv_unpack); line2[x] = schro_dequantise (value, quant_factor, quant_offset); } } } }
int test3 (void) { SchroBuffer *buffer = schro_buffer_new_and_alloc (1000); SchroPack *pack; SchroUnpack unpack; SchroUnpack unpack2; int i; int ref[100]; int x; int n_bytes; int n_bits = 0; int n_bits2 = 0; memset (buffer->data, 0, 1000); for(i=0;i<100;i++){ ref[i] = (rand()&0xff) - 128; } pack = schro_pack_new (); schro_pack_encode_init (pack, buffer); n_bits = 0; for(i=0;i<50;i++){ schro_pack_encode_sint (pack, ref[i]); n_bits += schro_pack_estimate_sint (ref[i]); } n_bits2 = 0; for(i=50;i<100;i++){ schro_pack_encode_sint (pack, ref[i]); n_bits2 += schro_pack_estimate_sint (ref[i]); } schro_pack_flush(pack); n_bytes = schro_pack_get_offset (pack); schro_pack_free (pack); schro_unpack_init_with_data (&unpack, buffer->data, n_bytes, 1); schro_unpack_copy (&unpack2, &unpack); schro_unpack_limit_bits_remaining (&unpack, n_bits); for(i=0;i<50;i++){ x = schro_unpack_decode_sint (&unpack); if (x != ref[i]) { SCHRO_ERROR("test3 failed at symbol %d (%d should be %d)", i, x, ref[i]); schro_unpack_dump(&unpack); return 0; } } for(i=0;i<10;i++){ x = schro_unpack_decode_sint (&unpack); if (x != 0) { SCHRO_ERROR("test3 failed at symbol %d (%d should be 0)", i, x); schro_unpack_dump(&unpack); return 0; } } schro_unpack_skip_bits (&unpack2, n_bits); schro_unpack_limit_bits_remaining (&unpack2, n_bits2); for(i=50;i<100;i++){ x = schro_unpack_decode_sint (&unpack2); if (x != ref[i]) { SCHRO_ERROR("test3 failed at symbol %d (%d should be %d)", i, x, ref[i]); schro_unpack_dump(&unpack2); return 0; } } for(i=0;i<10;i++){ x = schro_unpack_decode_sint (&unpack2); if (x != 0) { SCHRO_ERROR("test3 failed at symbol %d (%d should be 0)", i, x); schro_unpack_dump(&unpack2); return 0; } } schro_buffer_unref (buffer); return 1; }