~kamalmostafa/ubuntu/lucid/pdp/fix-504941-ftbfs

« back to all changes in this revision

Viewing changes to system/image/pdp_resample.c

  • Committer: Bazaar Package Importer
  • Author(s): Guenter Geiger (Debian/GNU)
  • Date: 2005-03-15 22:21:05 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050315222105-1q287rsihmd9j1tb
Tags: 1:0.12.4-2
* fixed the hardcoded depends
* added 3dp library

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *   Pure Data Packet system file. - image resampling routines
3
 
 *   Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
4
 
 *
5
 
 *   This program is free software; you can redistribute it and/or modify
6
 
 *   it under the terms of the GNU General Public License as published by
7
 
 *   the Free Software Foundation; either version 2 of the License, or
8
 
 *   (at your option) any later version.
9
 
 *
10
 
 *   This program is distributed in the hope that it will be useful,
11
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *   GNU General Public License for more details.
14
 
 *
15
 
 *   You should have received a copy of the GNU General Public License
16
 
 *   along with this program; if not, write to the Free Software
17
 
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
 
 *
19
 
 */
20
 
 
21
 
 
22
 
#include <string.h>
23
 
#include "pdp_resample.h"
24
 
 
25
 
 
26
 
/*
27
 
 
28
 
efficient bilinear resampling ??
29
 
performance: how to eliminate divides? -> virtual coordinates 2^k x 2^k (conf. opengl)
30
 
 
31
 
i.e. 16 bit virtual coordinates: easy modular addressing
32
 
 
33
 
*/
34
 
 
35
 
 
36
 
/* code in this file should go out to be replaced by code in pdp_imageproc */
37
 
 
38
 
static s32 pdp_resample_bilin(s16 *image, s32 width, s32 height, s32 virt_x, s32 virt_y)
39
 
{
40
 
 
41
 
    s32 fp_x, fp_y, frac_x, frac_y, f, offset, r_1, r_2;
42
 
 
43
 
    virt_x &= 0xffff;
44
 
    virt_y &= 0xffff;
45
 
 
46
 
    fp_x = virt_x * (width - 1);
47
 
    fp_y = virt_y * (height - 1);
48
 
 
49
 
    frac_x = fp_x & (0xffff);
50
 
    frac_y = fp_y & (0xffff);
51
 
 
52
 
    offset = (fp_x >> 16) + (fp_y >> 16) * width;
53
 
    image += offset;
54
 
 
55
 
    f = 0x10000 - frac_x;
56
 
 
57
 
    r_1 = ((f * (s32)(image[0])  +  frac_x * (s32)(image[1])))>>16;
58
 
 
59
 
    image += width;
60
 
 
61
 
    r_2 = ((f * (s32)(image[0])  +  frac_x * (s32)(image[1])))>>16;
62
 
 
63
 
    f = 0x10000 - frac_y;
64
 
 
65
 
    return ((f * r_1 + frac_y * r_2)>>16);
66
 
    
67
 
}
68
 
 
69
 
 
70
 
void pdp_resample_scale_bilin(s16 *src_image, s16 *dst_image, s32 src_w, s32 src_h, s32 dst_w, s32 dst_h)
71
 
{
72
 
    s32 i,j;
73
 
    s32 virt_x=0;
74
 
    s32 virt_y=0; /* virtual coordinates in 30 bit */
75
 
    s32 scale_x = 0x40000000 / dst_w;
76
 
    s32 scale_y = 0x40000000 / dst_h;
77
 
 
78
 
    for (j=0; j<dst_h; j++){
79
 
        for (i=0; i<dst_w; i++){
80
 
            *dst_image++ = pdp_resample_bilin(src_image, src_w, src_h, virt_x>>14, virt_y>>14);
81
 
            virt_x += scale_x;
82
 
        }
83
 
        virt_x = 0;
84
 
        virt_y += scale_y;
85
 
    }
86
 
 
87
 
}
88
 
 
89
 
void pdp_resample_scale_nn(s16 *src_image, s16 *dst_image, s32 src_w, s32 src_h, s32 dst_w, s32 dst_h)
90
 
{
91
 
    s32 i,j;
92
 
    s32 x=0;
93
 
    s32 y=0;
94
 
    s32 frac_x=0;
95
 
    s32 frac_y=0;
96
 
    s32 scale_x = (src_w << 20 ) / dst_w;
97
 
    s32 scale_y = (src_h << 20 ) / dst_h;
98
 
 
99
 
    for (j=0; j<dst_h; j++){
100
 
        for (i=0; i<dst_w; i++){
101
 
            *dst_image++ = src_image[x+y];
102
 
            frac_x += scale_x;
103
 
            x = frac_x >> 20;
104
 
        }
105
 
        x = 0;
106
 
        frac_x = 0;
107
 
        frac_y += scale_y;
108
 
        y = (frac_y >> 20) * src_w;
109
 
    }
110
 
 
111
 
}
112
 
 
113
 
/* USE pdp_resample_affinemap
114
 
void pdp_resample_zoom_tiled_bilin(s16 *src_image, s16 *dst_image, s32 w, s32 h, 
115
 
                                   float zoom_x, float zoom_y, float center_x_relative, float center_y_relative)
116
 
{
117
 
    float izx = 1.0f / zoom_x;
118
 
    float izy = 1.0f / zoom_y;
119
 
    s32 scale_x = (s32)((float)0x100000 * izx / (float)w);
120
 
    s32 scale_y = (s32)((float)0x100000 * izy / (float)h);
121
 
 
122
 
    s32 top_virt_x = (s32)((1.0f - izx) * (float)0x100000 * center_x_relative);
123
 
    s32 top_virt_y = (s32)((1.0f - izy) * (float)0x100000 * center_y_relative);
124
 
 
125
 
    s32 virt_x = top_virt_x;
126
 
    s32 virt_y = top_virt_y; 
127
 
 
128
 
    s32 i,j;
129
 
 
130
 
    for (j=0; j<h; j++){
131
 
        for (i=0; i<w; i++){
132
 
            *dst_image++ = pdp_resample_bilin(src_image, w, h, virt_x>>4, virt_y>>4);
133
 
            virt_x += scale_x;
134
 
        }
135
 
        virt_x = top_virt_x;
136
 
        virt_y += scale_y;
137
 
    }
138
 
 
139
 
}
140
 
*/
141
 
 
142
 
void pdp_resample_halve(s16 *src_image, s16 *dst_image, s32 src_w, s32 src_h)
143
 
{
144
 
 
145
 
    int dst_x,dst_y;
146
 
    int src_x = 0;
147
 
    int src_y = 0;
148
 
    int dst_w = src_w >> 1;
149
 
    int dst_h = src_h >> 1;
150
 
    s32 tmp1,tmp2,tmp3,tmp4;
151
 
 
152
 
    //post("%x %x %d %d\n", src_image, dst_image, src_w, src_h);
153
 
 
154
 
    for(dst_y = 0; dst_y < dst_h * dst_w; dst_y += dst_w){
155
 
        for (dst_x = 0; dst_x < dst_w; dst_x++){
156
 
 
157
 
            tmp1 = (s32)src_image[src_y + src_x];
158
 
            tmp2 = (s32)src_image[src_y + src_x + 1];
159
 
            tmp3 = (s32)src_image[src_y + src_x + src_w];
160
 
            tmp4 = (s32)src_image[src_y + src_x + src_w + 1];
161
 
 
162
 
            tmp1 += tmp2;
163
 
            tmp3 += tmp4;
164
 
 
165
 
            src_x += 2;
166
 
 
167
 
            dst_image[dst_x+dst_y] = (s16)((tmp1 + tmp3)>>2);
168
 
        }
169
 
        src_y += src_w << 1;
170
 
        src_x = 0;
171
 
    }
172
 
}
173
 
 
174
 
void pdp_resample_double(s16 *src_image, s16 *dst_image, s32 src_w, s32 src_h)
175
 
{
176
 
    int src_x = 0;
177
 
    int src_y = 0;
178
 
    int dst = 0;
179
 
    int dst_w = src_w << 1;
180
 
 
181
 
    s16 tmp;
182
 
 
183
 
    for(src_y = 0; src_y < src_h * src_w; src_y += src_w){
184
 
        for (src_x = 0; src_x < src_w; src_x++){
185
 
 
186
 
            tmp = *src_image++;
187
 
            dst = (src_y << 2) + (src_x << 1);
188
 
            dst_image[dst]   = tmp;
189
 
            dst_image[dst+1] = tmp;
190
 
            dst+=dst_w;
191
 
            dst_image[dst]   = tmp;
192
 
            dst_image[dst+1] = tmp;
193
 
        }
194
 
    }
195
 
}
196
 
 
197
 
/* $$$TODO: finish this */
198
 
void pdp_resample_padcrop(s16 *src_image, s16 *dst_image, s32 src_w, s32 src_h, s32 dst_w, s32 dst_h)
199
 
{
200
 
 
201
 
    int shift_x = (dst_w - src_w) / 2;
202
 
    int shift_y = (dst_h - src_h) / 2;
203
 
}
204