[svn] / trunk / xvidcore / src / utils / mem_transfer.c Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/src/utils/mem_transfer.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1627 - (view) (download)

1 : edgomez 212 /*****************************************************************************
2 : edgomez 195 *
3 : edgomez 212 * XVID MPEG-4 VIDEO CODEC
4 : edgomez 851 * - 8bit<->16bit transfer -
5 : edgomez 195 *
6 : edgomez 1382 * Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
7 :     *
8 : edgomez 851 * This program is free software ; you can redistribute it and/or modify
9 :     * it under the terms of the GNU General Public License as published by
10 :     * the Free Software Foundation ; either version 2 of the License, or
11 : edgomez 212 * (at your option) any later version.
12 : edgomez 195 *
13 : edgomez 212 * This program is distributed in the hope that it will be useful,
14 : edgomez 851 * but WITHOUT ANY WARRANTY ; without even the implied warranty of
15 : edgomez 212 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 :     * GNU General Public License for more details.
17 : edgomez 195 *
18 : edgomez 212 * You should have received a copy of the GNU General Public License
19 : edgomez 851 * along with this program ; if not, write to the Free Software
20 : edgomez 212 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 : edgomez 195 *
22 : Isibaar 1627 * $Id: mem_transfer.c,v 1.15 2005-08-01 10:53:46 Isibaar Exp $
23 : edgomez 195 *
24 : edgomez 212 ****************************************************************************/
25 : edgomez 195
26 : edgomez 212 #include "../global.h"
27 :     #include "mem_transfer.h"
28 : edgomez 195
29 : edgomez 212 /* Function pointers - Initialized in the xvid.c module */
30 :    
31 :     TRANSFER_8TO16COPY_PTR transfer_8to16copy;
32 :     TRANSFER_16TO8COPY_PTR transfer_16to8copy;
33 :    
34 : edgomez 195 TRANSFER_8TO16SUB_PTR transfer_8to16sub;
35 : edgomez 851 TRANSFER_8TO16SUBRO_PTR transfer_8to16subro;
36 : edgomez 195 TRANSFER_8TO16SUB2_PTR transfer_8to16sub2;
37 : syskin 1583 TRANSFER_8TO16SUB2RO_PTR transfer_8to16sub2ro;
38 : edgomez 195 TRANSFER_16TO8ADD_PTR transfer_16to8add;
39 :    
40 : edgomez 212 TRANSFER8X8_COPY_PTR transfer8x8_copy;
41 : edgomez 195
42 : Skal 1620 #define USE_REFERENCE_C
43 : edgomez 212
44 : edgomez 195 /*****************************************************************************
45 :     *
46 : edgomez 212 * All these functions are used to transfer data from a 8 bit data array
47 : edgomez 195 * to a 16 bit data array.
48 : edgomez 212 *
49 : edgomez 195 * This is typically used during motion compensation, that's why some
50 :     * functions also do the addition/substraction of another buffer during the
51 :     * so called transfer.
52 :     *
53 : edgomez 212 ****************************************************************************/
54 :    
55 :     /*
56 :     * SRC - the source buffer
57 :     * DST - the destination buffer
58 :     *
59 :     * Then the function does the 8->16 bit transfer and this serie of operations :
60 :     *
61 :     * SRC (8bit) = SRC
62 :     * DST (16bit) = SRC
63 : edgomez 195 */
64 : edgomez 212 void
65 :     transfer_8to16copy_c(int16_t * const dst,
66 :     const uint8_t * const src,
67 :     uint32_t stride)
68 :     {
69 : Skal 1620 int i, j;
70 : edgomez 212 for (j = 0; j < 8; j++) {
71 :     for (i = 0; i < 8; i++) {
72 : edgomez 195 dst[j * 8 + i] = (int16_t) src[j * stride + i];
73 : Isibaar 1627 }
74 : edgomez 195 }
75 :     }
76 :    
77 :     /*
78 :     * SRC - the source buffer
79 :     * DST - the destination buffer
80 :     *
81 :     * Then the function does the 8->16 bit transfer and this serie of operations :
82 :     *
83 :     * SRC (16bit) = SRC
84 :     * DST (8bit) = max(min(SRC, 255), 0)
85 :     */
86 : edgomez 212 void
87 :     transfer_16to8copy_c(uint8_t * const dst,
88 :     const int16_t * const src,
89 :     uint32_t stride)
90 :     {
91 : Skal 1620 int i, j;
92 : edgomez 195
93 : edgomez 212 for (j = 0; j < 8; j++) {
94 :     for (i = 0; i < 8; i++) {
95 : Skal 1620 #ifdef USE_REFERENCE_C
96 : edgomez 195 int16_t pixel = src[j * 8 + i];
97 :    
98 :     if (pixel < 0) {
99 :     pixel = 0;
100 :     } else if (pixel > 255) {
101 :     pixel = 255;
102 :     }
103 :     dst[j * stride + i] = (uint8_t) pixel;
104 : Skal 1620 #else
105 :     const int16_t pixel = src[j * 8 + i];
106 :     const uint8_t value = (uint8_t)( (pixel&~255) ? (-pixel)>>(8*sizeof(pixel)-1) : pixel );
107 :     dst[j*stride + i] = value;
108 :     #endif
109 :     }
110 : edgomez 195 }
111 :     }
112 :    
113 :    
114 :    
115 :    
116 :     /*
117 :     * C - the current buffer
118 :     * R - the reference buffer
119 :     * DCT - the dct coefficient buffer
120 :     *
121 :     * Then the function does the 8->16 bit transfer and this serie of operations :
122 :     *
123 :     * R (8bit) = R
124 :     * C (8bit) = R
125 :     * DCT (16bit) = C - R
126 : edgomez 212 */
127 :     void
128 :     transfer_8to16sub_c(int16_t * const dct,
129 :     uint8_t * const cur,
130 :     const uint8_t * ref,
131 :     const uint32_t stride)
132 :     {
133 : Skal 1620 int i, j;
134 : edgomez 212
135 :     for (j = 0; j < 8; j++) {
136 : edgomez 195 for (i = 0; i < 8; i++) {
137 : Skal 1620 const uint8_t c = cur[j * stride + i];
138 :     const uint8_t r = ref[j * stride + i];
139 : edgomez 195
140 :     cur[j * stride + i] = r;
141 :     dct[j * 8 + i] = (int16_t) c - (int16_t) r;
142 :     }
143 :     }
144 :     }
145 :    
146 :    
147 : edgomez 851 void
148 :     transfer_8to16subro_c(int16_t * const dct,
149 :     const uint8_t * const cur,
150 :     const uint8_t * ref,
151 :     const uint32_t stride)
152 :     {
153 : Skal 1620 int i, j;
154 : edgomez 851
155 :     for (j = 0; j < 8; j++) {
156 :     for (i = 0; i < 8; i++) {
157 : Skal 1620 const uint8_t c = cur[j * stride + i];
158 :     const uint8_t r = ref[j * stride + i];
159 : edgomez 851 dct[j * 8 + i] = (int16_t) c - (int16_t) r;
160 :     }
161 :     }
162 :     }
163 :    
164 :    
165 :    
166 : edgomez 195 /*
167 :     * C - the current buffer
168 :     * R1 - the 1st reference buffer
169 :     * R2 - the 2nd reference buffer
170 :     * DCT - the dct coefficient buffer
171 :     *
172 :     * Then the function does the 8->16 bit transfer and this serie of operations :
173 :     *
174 :     * R1 (8bit) = R1
175 :     * R2 (8bit) = R2
176 : edgomez 1382 * R (temp) = min((R1 + R2)/2, 255)
177 :     * DCT (16bit)= C - R
178 :     * C (8bit) = R
179 : edgomez 212 */
180 :     void
181 :     transfer_8to16sub2_c(int16_t * const dct,
182 :     uint8_t * const cur,
183 :     const uint8_t * ref1,
184 :     const uint8_t * ref2,
185 :     const uint32_t stride)
186 :     {
187 :     uint32_t i, j;
188 :    
189 : edgomez 195 for (j = 0; j < 8; j++) {
190 :     for (i = 0; i < 8; i++) {
191 : Skal 1620 const uint8_t c = cur[j * stride + i];
192 :     const uint8_t r = (ref1[j * stride + i] + ref2[j * stride + i] + 1) >> 1;
193 : edgomez 1382 cur[j * stride + i] = r;
194 : edgomez 195 dct[j * 8 + i] = (int16_t) c - (int16_t) r;
195 :     }
196 :     }
197 :     }
198 :    
199 : syskin 1583 void
200 :     transfer_8to16sub2ro_c(int16_t * const dct,
201 :     const uint8_t * const cur,
202 :     const uint8_t * ref1,
203 :     const uint8_t * ref2,
204 :     const uint32_t stride)
205 :     {
206 :     uint32_t i, j;
207 : edgomez 195
208 : syskin 1583 for (j = 0; j < 8; j++) {
209 :     for (i = 0; i < 8; i++) {
210 : Skal 1620 const uint8_t c = cur[j * stride + i];
211 :     const uint8_t r = (ref1[j * stride + i] + ref2[j * stride + i] + 1) >> 1;
212 : syskin 1583 dct[j * 8 + i] = (int16_t) c - (int16_t) r;
213 :     }
214 :     }
215 :     }
216 :    
217 :    
218 : edgomez 195 /*
219 :     * SRC - the source buffer
220 :     * DST - the destination buffer
221 :     *
222 :     * Then the function does the 16->8 bit transfer and this serie of operations :
223 :     *
224 :     * SRC (16bit) = SRC
225 :     * DST (8bit) = max(min(DST+SRC, 255), 0)
226 :     */
227 : edgomez 212 void
228 :     transfer_16to8add_c(uint8_t * const dst,
229 :     const int16_t * const src,
230 :     uint32_t stride)
231 :     {
232 : Skal 1620 int i, j;
233 : edgomez 212
234 :     for (j = 0; j < 8; j++) {
235 :     for (i = 0; i < 8; i++) {
236 : Skal 1620 #ifdef USE_REFERENCE_C
237 : edgomez 195 int16_t pixel = (int16_t) dst[j * stride + i] + src[j * 8 + i];
238 :    
239 :     if (pixel < 0) {
240 :     pixel = 0;
241 :     } else if (pixel > 255) {
242 :     pixel = 255;
243 :     }
244 :     dst[j * stride + i] = (uint8_t) pixel;
245 : Skal 1620 #else
246 :     const int16_t pixel = (int16_t) dst[j * stride + i] + src[j * 8 + i];
247 :     const uint8_t value = (uint8_t)( (pixel&~255) ? (-pixel)>>(8*sizeof(pixel)-1) : pixel );
248 :     dst[j*stride + i] = value;
249 :     #endif
250 :    
251 : edgomez 195 }
252 :     }
253 :     }
254 :    
255 :     /*
256 :     * SRC - the source buffer
257 :     * DST - the destination buffer
258 :     *
259 :     * Then the function does the 8->8 bit transfer and this serie of operations :
260 :     *
261 :     * SRC (8bit) = SRC
262 :     * DST (8bit) = SRC
263 :     */
264 : edgomez 212 void
265 :     transfer8x8_copy_c(uint8_t * const dst,
266 :     const uint8_t * const src,
267 :     const uint32_t stride)
268 :     {
269 : Skal 1620 int j, i;
270 : edgomez 195
271 : Isibaar 1612 for (j = 0; j < 8; ++j) {
272 :     uint8_t *d = dst + j*stride;
273 :     const uint8_t *s = src + j*stride;
274 :    
275 :     for (i = 0; i < 8; ++i)
276 :     {
277 :     *d++ = *s++;
278 :     }
279 : edgomez 195 }
280 :     }

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4