21 FUNCTION_NAME(IMAGETYPE &dest,
const IMAGETYPE &source,
22 float width, FilterFunction *make_filter,
int channel) {
23 if (!dest.is_valid() || !source.is_valid()) {
31 typedef StoreType *StoreTypeP;
32 StoreType **matrix = (StoreType **)PANDA_MALLOC_ARRAY(dest.ASIZE() *
sizeof(StoreType *));
33 StoreType **matrix_weight = (StoreType **)PANDA_MALLOC_ARRAY(dest.ASIZE() *
sizeof(StoreType *));
37 for (a=0; a<dest.ASIZE(); a++) {
38 matrix[a] = (StoreType *)PANDA_MALLOC_ARRAY(source.BSIZE() *
sizeof(StoreType));
39 matrix_weight[a] = (StoreType *)PANDA_MALLOC_ARRAY(source.BSIZE() *
sizeof(StoreType));
44 StoreType *temp_source, *temp_source_weight, *temp_dest, *temp_dest_weight;
46 scale = (float)dest.ASIZE() / (float)source.ASIZE();
47 temp_source = (StoreType *)PANDA_MALLOC_ARRAY(source.ASIZE() *
sizeof(StoreType));
48 temp_source_weight = (StoreType *)PANDA_MALLOC_ARRAY(source.ASIZE() *
sizeof(StoreType));
49 temp_dest = (StoreType *)PANDA_MALLOC_ARRAY(dest.ASIZE() *
sizeof(StoreType));
50 temp_dest_weight = (StoreType *)PANDA_MALLOC_ARRAY(dest.ASIZE() *
sizeof(StoreType));
55 make_filter(scale, width, filter, filter_width);
57 for (b = 0; b < source.BSIZE(); b++) {
58 memset(temp_source_weight, 0, source.ASIZE() *
sizeof(StoreType));
59 for (a = 0; a < source.ASIZE(); a++) {
60 if (source.HASVAL(a, b)) {
61 temp_source[a] = (StoreType)(source_max * source.GETVAL(a, b, channel));
62 temp_source_weight[a] = filter_max;
66 filter_sparse_row(temp_dest, temp_dest_weight, dest.ASIZE(),
67 temp_source, temp_source_weight, source.ASIZE(),
69 filter, filter_width);
71 for (a = 0; a < dest.ASIZE(); a++) {
72 matrix[a][b] = temp_dest[a];
73 matrix_weight[a][b] = temp_dest_weight[a];
77 PANDA_FREE_ARRAY(temp_source);
78 PANDA_FREE_ARRAY(temp_source_weight);
79 PANDA_FREE_ARRAY(temp_dest);
80 PANDA_FREE_ARRAY(temp_dest_weight);
81 PANDA_FREE_ARRAY(filter);
84 scale = (float)dest.BSIZE() / (float)source.BSIZE();
85 temp_dest = (StoreType *)PANDA_MALLOC_ARRAY(dest.BSIZE() *
sizeof(StoreType));
86 temp_dest_weight = (StoreType *)PANDA_MALLOC_ARRAY(dest.BSIZE() *
sizeof(StoreType));
88 make_filter(scale, width, filter, filter_width);
90 for (a = 0; a < dest.ASIZE(); a++) {
91 filter_sparse_row(temp_dest, temp_dest_weight, dest.BSIZE(),
92 matrix[a], matrix_weight[a], source.BSIZE(),
94 filter, filter_width);
96 for (b = 0; b < dest.BSIZE(); b++) {
97 if (temp_dest_weight[b] != 0) {
98 dest.SETVAL(a, b, channel, (
float)temp_dest[b]/(
float)source_max);
103 PANDA_FREE_ARRAY(temp_dest);
104 PANDA_FREE_ARRAY(temp_dest_weight);
105 PANDA_FREE_ARRAY(filter);
109 for (a = 0; a < dest.ASIZE(); a++) {
110 PANDA_FREE_ARRAY(matrix[a]);
111 PANDA_FREE_ARRAY(matrix_weight[a]);
113 PANDA_FREE_ARRAY(matrix);
114 PANDA_FREE_ARRAY(matrix_weight);