[dad864]: decoder.cpp Maximize Restore History

Download this file

decoder.cpp    151 lines (130 with data), 4.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "stdafx.h"
#include <stdlib.h>
#include "decoder.h"
int CSubbandDecoder::init_decoder() {
int memory_size = (levels == 0)? 0: (3*(block_size >> 1) - 2);
if (memory_size) {
memory_buffer = (long*)calloc (memory_size, sizeof(long));
if (!memory_buffer) return 0;
}
return 1;
}
void CSubbandDecoder::decode_data (long* buffer, int blocks) {
if (!levels) return; // no levels - no work
long *buff_ptr = buffer,
*mem_ptr = memory_buffer;
int sb_size = block_size >> 1; // current subband size
blocks <<= 1;
sub_4d3fcc ((short*)mem_ptr, buff_ptr, sb_size, blocks);
mem_ptr += sb_size;
for (int i=0; i<blocks; i++)
buff_ptr [i*sb_size]++;
sb_size >>= 1;
blocks <<= 1;
while (sb_size != 0) {
sub_4d420c (mem_ptr, buff_ptr, sb_size, blocks);
mem_ptr += sb_size << 1;
sb_size >>= 1;
blocks <<= 1;
}
}
void CSubbandDecoder::sub_4d3fcc (short* memory, long* buffer, int sb_size, int blocks) {
long row_0, row_1, row_2, row_3, db_0, db_1;
int i;
int sb_size_2 = sb_size * 2,
sb_size_3 = sb_size * 3;
if (blocks == 2) {
for (i=0; i<sb_size; i++) {
row_0 = buffer[0];
row_1 = buffer[sb_size];
buffer [0] = buffer[0] + memory[0] + 2*memory[1];
buffer [sb_size] = 2*row_0 - memory[1] - buffer[sb_size];
memory [0] = (short) row_0;
memory [1] = (short) row_1;
memory += 2;
buffer++;
}
} else if (blocks == 4) {
for (i=0; i<sb_size; i++) {
row_0 = buffer[0];
row_1 = buffer[sb_size];
row_2 = buffer[sb_size_2];
row_3 = buffer[sb_size_3];
buffer [0] = memory[0] + 2*memory[1] + row_0;
buffer [sb_size] = -memory[1] + 2*row_0 - row_1;
buffer [sb_size_2] = row_0 + 2*row_1 + row_2;
buffer [sb_size_3] = -row_1 + 2*row_2 - row_3;
memory [0] = (short) row_2;
memory [1] = (short) row_3;
memory += 2;
buffer++;
}
} else {
for (i=0; i<sb_size; i++) {
long* buff_ptr = buffer;
if (blocks &2) {
row_0 = buff_ptr[0];
row_1 = buff_ptr[sb_size];
buff_ptr [0] = memory[0] + 2*memory[1] + row_0;
buff_ptr [sb_size] = -memory[1] + 2*row_0 - row_1;
buff_ptr += sb_size_2;
db_0 = row_0;
db_1 = row_1;
} else {
db_0 = memory[0];
db_1 = memory[1];
}
for (int j=0; j<blocks >> 2; j++) {
row_0 = buff_ptr[0]; buff_ptr [0] = db_0 + 2*db_1 + row_0; buff_ptr += sb_size;
row_1 = buff_ptr[0]; buff_ptr [0] = -db_1 + 2*row_0 - row_1; buff_ptr += sb_size;
row_2 = buff_ptr[0]; buff_ptr [0] = row_0 + 2*row_1 + row_2; buff_ptr += sb_size;
row_3 = buff_ptr[0]; buff_ptr [0] = -row_1 + 2*row_2 - row_3; buff_ptr += sb_size;
db_0 = row_2;
db_1 = row_3;
}
memory [0] = (short) row_2;
memory [1] = (short) row_3;
memory += 2;
buffer++;
}
}
}
void CSubbandDecoder::sub_4d420c (long *memory, long *buffer, int sb_size, int blocks) {
long row_0, row_1, row_2, row_3, db_0, db_1;
int i;
int sb_size_2 = sb_size * 2,
sb_size_3 = sb_size * 3;
if (blocks == 4) {
for (i=0; i<sb_size; i++) {
row_0 = buffer[0];
row_1 = buffer[sb_size];
row_2 = buffer[sb_size_2];
row_3 = buffer[sb_size_3];
buffer [0] = memory[0] + 2*memory[1] + row_0;
buffer [sb_size] = -memory[1] + 2*row_0 - row_1;
buffer [sb_size_2] = row_0 + 2*row_1 + row_2;
buffer [sb_size_3] = -row_1 + 2*row_2 - row_3;
memory [0] = row_2;
memory [1] = row_3;
memory += 2;
buffer++;
}
} else {
for (i=0; i<sb_size; i++) {
long* buff_ptr = buffer;
db_0 = memory[0]; db_1 = memory[1];
for (int j=0; j<blocks >> 2; j++) {
row_0 = buff_ptr[0]; buff_ptr [0] = db_0 + 2*db_1 + row_0; buff_ptr += sb_size;
row_1 = buff_ptr[0]; buff_ptr [0] = -db_1 + 2*row_0 - row_1; buff_ptr += sb_size;
row_2 = buff_ptr[0]; buff_ptr [0] = row_0 + 2*row_1 + row_2; buff_ptr += sb_size;
row_3 = buff_ptr[0]; buff_ptr [0] = -row_1 + 2*row_2 - row_3; buff_ptr += sb_size;
db_0 = row_2;
db_1 = row_3;
}
memory [0] = row_2;
memory [1] = row_3;
memory += 2;
buffer++;
}
}
}