[svn] / branches / dev-api-4 / xvidcore / src / utils / mem_transfer.c Repository:
ViewVC logotype

Annotation of /branches/dev-api-4/xvidcore/src/utils/mem_transfer.c

Parent Directory Parent Directory | Revision Log Revision Log


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

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