[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 1583 - (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 : syskin 1583 * $Id: mem_transfer.c,v 1.12 2004-12-19 13:16:50 syskin 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 : edgomez 212
43 : edgomez 195 /*****************************************************************************
44 :     *
45 : edgomez 212 * All these functions are used to transfer data from a 8 bit data array
46 : edgomez 195 * to a 16 bit data array.
47 : edgomez 212 *
48 : edgomez 195 * This is typically used during motion compensation, that's why some
49 :     * functions also do the addition/substraction of another buffer during the
50 :     * so called transfer.
51 :     *
52 : edgomez 212 ****************************************************************************/
53 :    
54 :     /*
55 :     * SRC - the source buffer
56 :     * DST - the destination buffer
57 :     *
58 :     * Then the function does the 8->16 bit transfer and this serie of operations :
59 :     *
60 :     * SRC (8bit) = SRC
61 :     * DST (16bit) = SRC
62 : edgomez 195 */
63 : edgomez 212 void
64 :     transfer_8to16copy_c(int16_t * const dst,
65 :     const uint8_t * const src,
66 :     uint32_t stride)
67 :     {
68 :     uint32_t i, j;
69 :    
70 :     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 :     }
74 :     }
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 :     uint32_t i, j;
92 : edgomez 195
93 : edgomez 212 for (j = 0; j < 8; j++) {
94 :     for (i = 0; i < 8; i++) {
95 : edgomez 195 int16_t pixel = src[j * 8 + i];
96 :    
97 :     if (pixel < 0) {
98 :     pixel = 0;
99 :     } else if (pixel > 255) {
100 :     pixel = 255;
101 :     }
102 :     dst[j * stride + i] = (uint8_t) pixel;
103 :     }
104 :     }
105 :     }
106 :    
107 :    
108 :    
109 :    
110 :     /*
111 :     * C - the current buffer
112 :     * R - the reference buffer
113 :     * DCT - the dct coefficient buffer
114 :     *
115 :     * Then the function does the 8->16 bit transfer and this serie of operations :
116 :     *
117 :     * R (8bit) = R
118 :     * C (8bit) = R
119 :     * DCT (16bit) = C - R
120 : edgomez 212 */
121 :     void
122 :     transfer_8to16sub_c(int16_t * const dct,
123 :     uint8_t * const cur,
124 :     const uint8_t * ref,
125 :     const uint32_t stride)
126 :     {
127 :     uint32_t i, j;
128 :    
129 :     for (j = 0; j < 8; j++) {
130 : edgomez 195 for (i = 0; i < 8; i++) {
131 :     uint8_t c = cur[j * stride + i];
132 :     uint8_t r = ref[j * stride + i];
133 :    
134 :     cur[j * stride + i] = r;
135 :     dct[j * 8 + i] = (int16_t) c - (int16_t) r;
136 :     }
137 :     }
138 :     }
139 :    
140 :    
141 : edgomez 851 void
142 :     transfer_8to16subro_c(int16_t * const dct,
143 :     const uint8_t * const cur,
144 :     const uint8_t * ref,
145 :     const uint32_t stride)
146 :     {
147 :     uint32_t i, j;
148 :    
149 :     for (j = 0; j < 8; j++) {
150 :     for (i = 0; i < 8; i++) {
151 :     uint8_t c = cur[j * stride + i];
152 :     uint8_t r = ref[j * stride + i];
153 :     dct[j * 8 + i] = (int16_t) c - (int16_t) r;
154 :     }
155 :     }
156 :     }
157 :    
158 :    
159 :    
160 : edgomez 195 /*
161 :     * C - the current buffer
162 :     * R1 - the 1st reference buffer
163 :     * R2 - the 2nd reference buffer
164 :     * DCT - the dct coefficient buffer
165 :     *
166 :     * Then the function does the 8->16 bit transfer and this serie of operations :
167 :     *
168 :     * R1 (8bit) = R1
169 :     * R2 (8bit) = R2
170 : edgomez 1382 * R (temp) = min((R1 + R2)/2, 255)
171 :     * DCT (16bit)= C - R
172 :     * C (8bit) = R
173 : edgomez 212 */
174 :     void
175 :     transfer_8to16sub2_c(int16_t * const dct,
176 :     uint8_t * const cur,
177 :     const uint8_t * ref1,
178 :     const uint8_t * ref2,
179 :     const uint32_t stride)
180 :     {
181 :     uint32_t i, j;
182 :    
183 : edgomez 195 for (j = 0; j < 8; j++) {
184 :     for (i = 0; i < 8; i++) {
185 :     uint8_t c = cur[j * stride + i];
186 :     int r = (ref1[j * stride + i] + ref2[j * stride + i] + 1) / 2;
187 :    
188 :     if (r > 255) {
189 :     r = 255;
190 :     }
191 : edgomez 1382 cur[j * stride + i] = r;
192 : edgomez 195 dct[j * 8 + i] = (int16_t) c - (int16_t) r;
193 :     }
194 :     }
195 :     }
196 :    
197 : syskin 1583 void
198 :     transfer_8to16sub2ro_c(int16_t * const dct,
199 :     const uint8_t * const cur,
200 :     const uint8_t * ref1,
201 :     const uint8_t * ref2,
202 :     const uint32_t stride)
203 :     {
204 :     uint32_t i, j;
205 : edgomez 195
206 : syskin 1583 for (j = 0; j < 8; j++) {
207 :     for (i = 0; i < 8; i++) {
208 :     uint8_t c = cur[j * stride + i];
209 :     int r = (ref1[j * stride + i] + ref2[j * stride + i] + 1) / 2;
210 :     dct[j * 8 + i] = (int16_t) c - (int16_t) r;
211 :     }
212 :     }
213 :     }
214 :    
215 :    
216 : edgomez 195 /*
217 :     * SRC - the source buffer
218 :     * DST - the destination buffer
219 :     *
220 :     * Then the function does the 16->8 bit transfer and this serie of operations :
221 :     *
222 :     * SRC (16bit) = SRC
223 :     * DST (8bit) = max(min(DST+SRC, 255), 0)
224 :     */
225 : edgomez 212 void
226 :     transfer_16to8add_c(uint8_t * const dst,
227 :     const int16_t * const src,
228 :     uint32_t stride)
229 :     {
230 :     uint32_t i, j;
231 :    
232 :     for (j = 0; j < 8; j++) {
233 :     for (i = 0; i < 8; i++) {
234 : edgomez 195 int16_t pixel = (int16_t) dst[j * stride + i] + src[j * 8 + i];
235 :    
236 :     if (pixel < 0) {
237 :     pixel = 0;
238 :     } else if (pixel > 255) {
239 :     pixel = 255;
240 :     }
241 :     dst[j * stride + i] = (uint8_t) pixel;
242 :     }
243 :     }
244 :     }
245 :    
246 :     /*
247 :     * SRC - the source buffer
248 :     * DST - the destination buffer
249 :     *
250 :     * Then the function does the 8->8 bit transfer and this serie of operations :
251 :     *
252 :     * SRC (8bit) = SRC
253 :     * DST (8bit) = SRC
254 :     */
255 : edgomez 212 void
256 :     transfer8x8_copy_c(uint8_t * const dst,
257 :     const uint8_t * const src,
258 :     const uint32_t stride)
259 :     {
260 : edgomez 1492 uint32_t j;
261 : edgomez 195
262 : edgomez 212 for (j = 0; j < 8; j++) {
263 : edgomez 1492 uint32_t *d= (uint32_t*)(dst + j*stride);
264 :     const uint32_t *s = (const uint32_t*)(src + j*stride);
265 :     *(d+0) = *(s+0);
266 :     *(d+1) = *(s+1);
267 : edgomez 195 }
268 :     }

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