Parent Directory | Revision Log
Revision 654 - (view) (download)
1 : | edgomez | 212 | /***************************************************************************** |
2 : | edgomez | 195 | * |
3 : | edgomez | 212 | * XVID MPEG-4 VIDEO CODEC |
4 : | edgomez | 416 | * - 8bit<->16bit transfer - |
5 : | edgomez | 195 | * |
6 : | suxen_drol | 499 | * Copyright(C) 2001-2002 Peter Ross <pross@xvid.org> |
7 : | edgomez | 416 | * |
8 : | edgomez | 654 | * This file is part of XviD, a free MPEG-4 video encoder/decoder |
9 : | edgomez | 416 | * |
10 : | edgomez | 654 | * XviD is free software; you can redistribute it and/or modify it |
11 : | * under the terms of the GNU General Public License as published by | ||
12 : | edgomez | 416 | * the Free Software Foundation; either version 2 of the License, or |
13 : | edgomez | 212 | * (at your option) any later version. |
14 : | edgomez | 195 | * |
15 : | edgomez | 212 | * This program is distributed in the hope that it will be useful, |
16 : | edgomez | 416 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 : | edgomez | 212 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 : | * GNU General Public License for more details. | ||
19 : | edgomez | 195 | * |
20 : | edgomez | 212 | * You should have received a copy of the GNU General Public License |
21 : | edgomez | 416 | * along with this program; if not, write to the Free Software |
22 : | edgomez | 212 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 : | edgomez | 195 | * |
24 : | edgomez | 654 | * Under section 8 of the GNU General Public License, the copyright |
25 : | * holders of XVID explicitly forbid distribution in the following | ||
26 : | * countries: | ||
27 : | edgomez | 195 | * |
28 : | edgomez | 654 | * - Japan |
29 : | * - United States of America | ||
30 : | * | ||
31 : | * Linking XviD statically or dynamically with other modules is making a | ||
32 : | * combined work based on XviD. Thus, the terms and conditions of the | ||
33 : | * GNU General Public License cover the whole combination. | ||
34 : | * | ||
35 : | * As a special exception, the copyright holders of XviD give you | ||
36 : | * permission to link XviD with independent modules that communicate with | ||
37 : | * XviD solely through the VFW1.1 and DShow interfaces, regardless of the | ||
38 : | * license terms of these independent modules, and to copy and distribute | ||
39 : | * the resulting combined work under terms of your choice, provided that | ||
40 : | * every copy of the combined work is accompanied by a complete copy of | ||
41 : | * the source code of XviD (the version of XviD used to produce the | ||
42 : | * combined work), being distributed under the terms of the GNU General | ||
43 : | * Public License plus this exception. An independent module is a module | ||
44 : | * which is not derived from or based on XviD. | ||
45 : | * | ||
46 : | * Note that people who make modified versions of XviD are not obligated | ||
47 : | * to grant this special exception for their modified versions; it is | ||
48 : | * their choice whether to do so. The GNU General Public License gives | ||
49 : | * permission to release a modified version without this exception; this | ||
50 : | * exception also makes it possible to release a modified version which | ||
51 : | * carries forward this exception. | ||
52 : | * | ||
53 : | * $Id: mem_transfer.c,v 1.7 2002-11-17 00:51:11 edgomez Exp $ | ||
54 : | * | ||
55 : | edgomez | 212 | ****************************************************************************/ |
56 : | edgomez | 195 | |
57 : | edgomez | 212 | #include "../global.h" |
58 : | #include "mem_transfer.h" | ||
59 : | edgomez | 195 | |
60 : | edgomez | 212 | /* Function pointers - Initialized in the xvid.c module */ |
61 : | |||
62 : | TRANSFER_8TO16COPY_PTR transfer_8to16copy; | ||
63 : | TRANSFER_16TO8COPY_PTR transfer_16to8copy; | ||
64 : | |||
65 : | edgomez | 195 | TRANSFER_8TO16SUB_PTR transfer_8to16sub; |
66 : | TRANSFER_8TO16SUB2_PTR transfer_8to16sub2; | ||
67 : | TRANSFER_16TO8ADD_PTR transfer_16to8add; | ||
68 : | |||
69 : | edgomez | 212 | TRANSFER8X8_COPY_PTR transfer8x8_copy; |
70 : | edgomez | 195 | |
71 : | edgomez | 212 | |
72 : | edgomez | 195 | /***************************************************************************** |
73 : | * | ||
74 : | edgomez | 212 | * All these functions are used to transfer data from a 8 bit data array |
75 : | edgomez | 195 | * to a 16 bit data array. |
76 : | edgomez | 212 | * |
77 : | edgomez | 195 | * This is typically used during motion compensation, that's why some |
78 : | * functions also do the addition/substraction of another buffer during the | ||
79 : | * so called transfer. | ||
80 : | * | ||
81 : | edgomez | 212 | ****************************************************************************/ |
82 : | |||
83 : | /* | ||
84 : | * SRC - the source buffer | ||
85 : | * DST - the destination buffer | ||
86 : | * | ||
87 : | * Then the function does the 8->16 bit transfer and this serie of operations : | ||
88 : | * | ||
89 : | * SRC (8bit) = SRC | ||
90 : | * DST (16bit) = SRC | ||
91 : | edgomez | 195 | */ |
92 : | edgomez | 212 | void |
93 : | transfer_8to16copy_c(int16_t * const dst, | ||
94 : | const uint8_t * const src, | ||
95 : | uint32_t stride) | ||
96 : | { | ||
97 : | uint32_t i, j; | ||
98 : | |||
99 : | for (j = 0; j < 8; j++) { | ||
100 : | for (i = 0; i < 8; i++) { | ||
101 : | edgomez | 195 | dst[j * 8 + i] = (int16_t) src[j * stride + i]; |
102 : | } | ||
103 : | } | ||
104 : | } | ||
105 : | |||
106 : | /* | ||
107 : | * SRC - the source buffer | ||
108 : | * DST - the destination buffer | ||
109 : | * | ||
110 : | * Then the function does the 8->16 bit transfer and this serie of operations : | ||
111 : | * | ||
112 : | * SRC (16bit) = SRC | ||
113 : | * DST (8bit) = max(min(SRC, 255), 0) | ||
114 : | */ | ||
115 : | edgomez | 212 | void |
116 : | transfer_16to8copy_c(uint8_t * const dst, | ||
117 : | const int16_t * const src, | ||
118 : | uint32_t stride) | ||
119 : | { | ||
120 : | uint32_t i, j; | ||
121 : | edgomez | 195 | |
122 : | edgomez | 212 | for (j = 0; j < 8; j++) { |
123 : | for (i = 0; i < 8; i++) { | ||
124 : | edgomez | 195 | int16_t pixel = src[j * 8 + i]; |
125 : | |||
126 : | if (pixel < 0) { | ||
127 : | pixel = 0; | ||
128 : | } else if (pixel > 255) { | ||
129 : | pixel = 255; | ||
130 : | } | ||
131 : | dst[j * stride + i] = (uint8_t) pixel; | ||
132 : | } | ||
133 : | } | ||
134 : | } | ||
135 : | |||
136 : | |||
137 : | |||
138 : | |||
139 : | /* | ||
140 : | * C - the current buffer | ||
141 : | * R - the reference buffer | ||
142 : | * DCT - the dct coefficient buffer | ||
143 : | * | ||
144 : | * Then the function does the 8->16 bit transfer and this serie of operations : | ||
145 : | * | ||
146 : | * R (8bit) = R | ||
147 : | * C (8bit) = R | ||
148 : | * DCT (16bit) = C - R | ||
149 : | edgomez | 212 | */ |
150 : | void | ||
151 : | transfer_8to16sub_c(int16_t * const dct, | ||
152 : | uint8_t * const cur, | ||
153 : | const uint8_t * ref, | ||
154 : | const uint32_t stride) | ||
155 : | { | ||
156 : | uint32_t i, j; | ||
157 : | |||
158 : | for (j = 0; j < 8; j++) { | ||
159 : | edgomez | 195 | for (i = 0; i < 8; i++) { |
160 : | uint8_t c = cur[j * stride + i]; | ||
161 : | uint8_t r = ref[j * stride + i]; | ||
162 : | |||
163 : | cur[j * stride + i] = r; | ||
164 : | dct[j * 8 + i] = (int16_t) c - (int16_t) r; | ||
165 : | } | ||
166 : | } | ||
167 : | } | ||
168 : | |||
169 : | |||
170 : | /* | ||
171 : | * C - the current buffer | ||
172 : | * R1 - the 1st reference buffer | ||
173 : | * R2 - the 2nd reference buffer | ||
174 : | * DCT - the dct coefficient buffer | ||
175 : | * | ||
176 : | * Then the function does the 8->16 bit transfer and this serie of operations : | ||
177 : | * | ||
178 : | * R1 (8bit) = R1 | ||
179 : | * R2 (8bit) = R2 | ||
180 : | edgomez | 212 | * C (8bit) = C |
181 : | * DCT (16bit)= C - min((R1 + R2)/2, 255) | ||
182 : | */ | ||
183 : | void | ||
184 : | transfer_8to16sub2_c(int16_t * const dct, | ||
185 : | uint8_t * const cur, | ||
186 : | const uint8_t * ref1, | ||
187 : | const uint8_t * ref2, | ||
188 : | const uint32_t stride) | ||
189 : | { | ||
190 : | uint32_t i, j; | ||
191 : | |||
192 : | edgomez | 195 | for (j = 0; j < 8; j++) { |
193 : | for (i = 0; i < 8; i++) { | ||
194 : | uint8_t c = cur[j * stride + i]; | ||
195 : | int r = (ref1[j * stride + i] + ref2[j * stride + i] + 1) / 2; | ||
196 : | |||
197 : | if (r > 255) { | ||
198 : | r = 255; | ||
199 : | } | ||
200 : | //cur[j * stride + i] = r; | ||
201 : | dct[j * 8 + i] = (int16_t) c - (int16_t) r; | ||
202 : | } | ||
203 : | } | ||
204 : | } | ||
205 : | |||
206 : | |||
207 : | /* | ||
208 : | * SRC - the source buffer | ||
209 : | * DST - the destination buffer | ||
210 : | * | ||
211 : | * Then the function does the 16->8 bit transfer and this serie of operations : | ||
212 : | * | ||
213 : | * SRC (16bit) = SRC | ||
214 : | * DST (8bit) = max(min(DST+SRC, 255), 0) | ||
215 : | */ | ||
216 : | edgomez | 212 | void |
217 : | transfer_16to8add_c(uint8_t * const dst, | ||
218 : | const int16_t * const src, | ||
219 : | uint32_t stride) | ||
220 : | { | ||
221 : | uint32_t i, j; | ||
222 : | |||
223 : | for (j = 0; j < 8; j++) { | ||
224 : | for (i = 0; i < 8; i++) { | ||
225 : | edgomez | 195 | int16_t pixel = (int16_t) dst[j * stride + i] + src[j * 8 + i]; |
226 : | |||
227 : | if (pixel < 0) { | ||
228 : | pixel = 0; | ||
229 : | } else if (pixel > 255) { | ||
230 : | pixel = 255; | ||
231 : | } | ||
232 : | dst[j * stride + i] = (uint8_t) pixel; | ||
233 : | } | ||
234 : | } | ||
235 : | } | ||
236 : | |||
237 : | /* | ||
238 : | * SRC - the source buffer | ||
239 : | * DST - the destination buffer | ||
240 : | * | ||
241 : | * Then the function does the 8->8 bit transfer and this serie of operations : | ||
242 : | * | ||
243 : | * SRC (8bit) = SRC | ||
244 : | * DST (8bit) = SRC | ||
245 : | */ | ||
246 : | edgomez | 212 | void |
247 : | transfer8x8_copy_c(uint8_t * const dst, | ||
248 : | const uint8_t * const src, | ||
249 : | const uint32_t stride) | ||
250 : | { | ||
251 : | uint32_t i, j; | ||
252 : | edgomez | 195 | |
253 : | edgomez | 212 | for (j = 0; j < 8; j++) { |
254 : | for (i = 0; i < 8; i++) { | ||
255 : | edgomez | 195 | dst[j * stride + i] = src[j * stride + i]; |
256 : | } | ||
257 : | } | ||
258 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |