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

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