Parent Directory | Revision Log
Revision 1492 - (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 : | edgomez | 1492 | * $Id: mem_transfer.c,v 1.11 2004-07-14 23:26:06 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 | 1382 | * R (temp) = min((R1 + R2)/2, 255) |
170 : | * DCT (16bit)= C - R | ||
171 : | * C (8bit) = R | ||
172 : | edgomez | 212 | */ |
173 : | void | ||
174 : | transfer_8to16sub2_c(int16_t * const dct, | ||
175 : | uint8_t * const cur, | ||
176 : | const uint8_t * ref1, | ||
177 : | const uint8_t * ref2, | ||
178 : | const uint32_t stride) | ||
179 : | { | ||
180 : | uint32_t i, j; | ||
181 : | |||
182 : | edgomez | 195 | for (j = 0; j < 8; j++) { |
183 : | for (i = 0; i < 8; i++) { | ||
184 : | uint8_t c = cur[j * stride + i]; | ||
185 : | int r = (ref1[j * stride + i] + ref2[j * stride + i] + 1) / 2; | ||
186 : | |||
187 : | if (r > 255) { | ||
188 : | r = 255; | ||
189 : | } | ||
190 : | edgomez | 1382 | cur[j * stride + i] = r; |
191 : | edgomez | 195 | dct[j * 8 + i] = (int16_t) c - (int16_t) r; |
192 : | } | ||
193 : | } | ||
194 : | } | ||
195 : | |||
196 : | |||
197 : | /* | ||
198 : | * SRC - the source buffer | ||
199 : | * DST - the destination buffer | ||
200 : | * | ||
201 : | * Then the function does the 16->8 bit transfer and this serie of operations : | ||
202 : | * | ||
203 : | * SRC (16bit) = SRC | ||
204 : | * DST (8bit) = max(min(DST+SRC, 255), 0) | ||
205 : | */ | ||
206 : | edgomez | 212 | void |
207 : | transfer_16to8add_c(uint8_t * const dst, | ||
208 : | const int16_t * const src, | ||
209 : | uint32_t stride) | ||
210 : | { | ||
211 : | uint32_t i, j; | ||
212 : | |||
213 : | for (j = 0; j < 8; j++) { | ||
214 : | for (i = 0; i < 8; i++) { | ||
215 : | edgomez | 195 | int16_t pixel = (int16_t) dst[j * stride + i] + src[j * 8 + i]; |
216 : | |||
217 : | if (pixel < 0) { | ||
218 : | pixel = 0; | ||
219 : | } else if (pixel > 255) { | ||
220 : | pixel = 255; | ||
221 : | } | ||
222 : | dst[j * stride + i] = (uint8_t) pixel; | ||
223 : | } | ||
224 : | } | ||
225 : | } | ||
226 : | |||
227 : | /* | ||
228 : | * SRC - the source buffer | ||
229 : | * DST - the destination buffer | ||
230 : | * | ||
231 : | * Then the function does the 8->8 bit transfer and this serie of operations : | ||
232 : | * | ||
233 : | * SRC (8bit) = SRC | ||
234 : | * DST (8bit) = SRC | ||
235 : | */ | ||
236 : | edgomez | 212 | void |
237 : | transfer8x8_copy_c(uint8_t * const dst, | ||
238 : | const uint8_t * const src, | ||
239 : | const uint32_t stride) | ||
240 : | { | ||
241 : | edgomez | 1492 | uint32_t j; |
242 : | edgomez | 195 | |
243 : | edgomez | 212 | for (j = 0; j < 8; j++) { |
244 : | edgomez | 1492 | uint32_t *d= (uint32_t*)(dst + j*stride); |
245 : | const uint32_t *s = (const uint32_t*)(src + j*stride); | ||
246 : | *(d+0) = *(s+0); | ||
247 : | *(d+1) = *(s+1); | ||
248 : | edgomez | 195 | } |
249 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |