Parent Directory | Revision Log
Revision 392 - (view) (download)
1 : | edgomez | 212 | /***************************************************************************** |
2 : | edgomez | 195 | * |
3 : | edgomez | 212 | * XVID MPEG-4 VIDEO CODEC |
4 : | * - 8bit<->16bit transfer - | ||
5 : | edgomez | 195 | * |
6 : | edgomez | 212 | * 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 : | * (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 : | * but WITHOUT ANY WARRANTY ; without even the implied warranty of | ||
13 : | * 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 : | * along with this program ; if not, write to the Free Software | ||
18 : | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 : | edgomez | 195 | * |
20 : | edgomez | 212 | ****************************************************************************/ |
21 : | /***************************************************************************** | ||
22 : | edgomez | 195 | * |
23 : | edgomez | 212 | * History |
24 : | edgomez | 195 | * |
25 : | edgomez | 212 | * - 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 | 195 | * |
31 : | edgomez | 212 | * $Id: mem_transfer.c,v 1.4 2002-06-15 22:15:57 edgomez Exp $ |
32 : | * | ||
33 : | ****************************************************************************/ | ||
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 : | TRANSFER_8TO16SUB2_PTR transfer_8to16sub2; | ||
45 : | TRANSFER_16TO8ADD_PTR transfer_16to8add; | ||
46 : | |||
47 : | edgomez | 212 | TRANSFER8X8_COPY_PTR transfer8x8_copy; |
48 : | edgomez | 195 | |
49 : | edgomez | 212 | |
50 : | edgomez | 195 | /***************************************************************************** |
51 : | * | ||
52 : | edgomez | 212 | * All these functions are used to transfer data from a 8 bit data array |
53 : | edgomez | 195 | * to a 16 bit data array. |
54 : | edgomez | 212 | * |
55 : | edgomez | 195 | * This is typically used during motion compensation, that's why some |
56 : | * functions also do the addition/substraction of another buffer during the | ||
57 : | * so called transfer. | ||
58 : | * | ||
59 : | edgomez | 212 | ****************************************************************************/ |
60 : | |||
61 : | /* | ||
62 : | * SRC - the source buffer | ||
63 : | * DST - the destination buffer | ||
64 : | * | ||
65 : | * Then the function does the 8->16 bit transfer and this serie of operations : | ||
66 : | * | ||
67 : | * SRC (8bit) = SRC | ||
68 : | * DST (16bit) = SRC | ||
69 : | edgomez | 195 | */ |
70 : | edgomez | 212 | void |
71 : | transfer_8to16copy_c(int16_t * const dst, | ||
72 : | const uint8_t * const src, | ||
73 : | uint32_t stride) | ||
74 : | { | ||
75 : | uint32_t i, j; | ||
76 : | |||
77 : | for (j = 0; j < 8; j++) { | ||
78 : | for (i = 0; i < 8; i++) { | ||
79 : | edgomez | 195 | dst[j * 8 + i] = (int16_t) src[j * stride + i]; |
80 : | } | ||
81 : | } | ||
82 : | } | ||
83 : | |||
84 : | /* | ||
85 : | * SRC - the source buffer | ||
86 : | * DST - the destination buffer | ||
87 : | * | ||
88 : | * Then the function does the 8->16 bit transfer and this serie of operations : | ||
89 : | * | ||
90 : | * SRC (16bit) = SRC | ||
91 : | * DST (8bit) = max(min(SRC, 255), 0) | ||
92 : | */ | ||
93 : | edgomez | 212 | void |
94 : | transfer_16to8copy_c(uint8_t * const dst, | ||
95 : | const int16_t * const src, | ||
96 : | uint32_t stride) | ||
97 : | { | ||
98 : | uint32_t i, j; | ||
99 : | edgomez | 195 | |
100 : | edgomez | 212 | for (j = 0; j < 8; j++) { |
101 : | for (i = 0; i < 8; i++) { | ||
102 : | edgomez | 195 | int16_t pixel = src[j * 8 + i]; |
103 : | |||
104 : | if (pixel < 0) { | ||
105 : | pixel = 0; | ||
106 : | } else if (pixel > 255) { | ||
107 : | pixel = 255; | ||
108 : | } | ||
109 : | dst[j * stride + i] = (uint8_t) pixel; | ||
110 : | } | ||
111 : | } | ||
112 : | } | ||
113 : | |||
114 : | |||
115 : | |||
116 : | |||
117 : | /* | ||
118 : | * C - the current buffer | ||
119 : | * R - the reference buffer | ||
120 : | * DCT - the dct coefficient buffer | ||
121 : | * | ||
122 : | * Then the function does the 8->16 bit transfer and this serie of operations : | ||
123 : | * | ||
124 : | * R (8bit) = R | ||
125 : | * C (8bit) = R | ||
126 : | * DCT (16bit) = C - R | ||
127 : | edgomez | 212 | */ |
128 : | void | ||
129 : | transfer_8to16sub_c(int16_t * const dct, | ||
130 : | uint8_t * const cur, | ||
131 : | const uint8_t * ref, | ||
132 : | const uint32_t stride) | ||
133 : | { | ||
134 : | uint32_t i, j; | ||
135 : | |||
136 : | for (j = 0; j < 8; j++) { | ||
137 : | edgomez | 195 | for (i = 0; i < 8; i++) { |
138 : | uint8_t c = cur[j * stride + i]; | ||
139 : | uint8_t r = ref[j * stride + i]; | ||
140 : | |||
141 : | cur[j * stride + i] = r; | ||
142 : | dct[j * 8 + i] = (int16_t) c - (int16_t) r; | ||
143 : | } | ||
144 : | } | ||
145 : | } | ||
146 : | |||
147 : | |||
148 : | /* | ||
149 : | * C - the current buffer | ||
150 : | * R1 - the 1st reference buffer | ||
151 : | * R2 - the 2nd reference buffer | ||
152 : | * DCT - the dct coefficient buffer | ||
153 : | * | ||
154 : | * Then the function does the 8->16 bit transfer and this serie of operations : | ||
155 : | * | ||
156 : | * R1 (8bit) = R1 | ||
157 : | * R2 (8bit) = R2 | ||
158 : | edgomez | 212 | * C (8bit) = C |
159 : | * DCT (16bit)= C - min((R1 + R2)/2, 255) | ||
160 : | */ | ||
161 : | void | ||
162 : | transfer_8to16sub2_c(int16_t * const dct, | ||
163 : | uint8_t * const cur, | ||
164 : | const uint8_t * ref1, | ||
165 : | const uint8_t * ref2, | ||
166 : | const uint32_t stride) | ||
167 : | { | ||
168 : | uint32_t i, j; | ||
169 : | |||
170 : | edgomez | 195 | for (j = 0; j < 8; j++) { |
171 : | for (i = 0; i < 8; i++) { | ||
172 : | uint8_t c = cur[j * stride + i]; | ||
173 : | int r = (ref1[j * stride + i] + ref2[j * stride + i] + 1) / 2; | ||
174 : | |||
175 : | if (r > 255) { | ||
176 : | r = 255; | ||
177 : | } | ||
178 : | //cur[j * stride + i] = r; | ||
179 : | dct[j * 8 + i] = (int16_t) c - (int16_t) r; | ||
180 : | } | ||
181 : | } | ||
182 : | } | ||
183 : | |||
184 : | |||
185 : | /* | ||
186 : | * SRC - the source buffer | ||
187 : | * DST - the destination buffer | ||
188 : | * | ||
189 : | * Then the function does the 16->8 bit transfer and this serie of operations : | ||
190 : | * | ||
191 : | * SRC (16bit) = SRC | ||
192 : | * DST (8bit) = max(min(DST+SRC, 255), 0) | ||
193 : | */ | ||
194 : | edgomez | 212 | void |
195 : | transfer_16to8add_c(uint8_t * const dst, | ||
196 : | const int16_t * const src, | ||
197 : | uint32_t stride) | ||
198 : | { | ||
199 : | uint32_t i, j; | ||
200 : | |||
201 : | for (j = 0; j < 8; j++) { | ||
202 : | for (i = 0; i < 8; i++) { | ||
203 : | edgomez | 195 | int16_t pixel = (int16_t) dst[j * stride + i] + src[j * 8 + i]; |
204 : | |||
205 : | if (pixel < 0) { | ||
206 : | pixel = 0; | ||
207 : | } else if (pixel > 255) { | ||
208 : | pixel = 255; | ||
209 : | } | ||
210 : | dst[j * stride + i] = (uint8_t) pixel; | ||
211 : | } | ||
212 : | } | ||
213 : | } | ||
214 : | |||
215 : | /* | ||
216 : | * SRC - the source buffer | ||
217 : | * DST - the destination buffer | ||
218 : | * | ||
219 : | * Then the function does the 8->8 bit transfer and this serie of operations : | ||
220 : | * | ||
221 : | * SRC (8bit) = SRC | ||
222 : | * DST (8bit) = SRC | ||
223 : | */ | ||
224 : | edgomez | 212 | void |
225 : | transfer8x8_copy_c(uint8_t * const dst, | ||
226 : | const uint8_t * const src, | ||
227 : | const uint32_t stride) | ||
228 : | { | ||
229 : | uint32_t i, j; | ||
230 : | edgomez | 195 | |
231 : | edgomez | 212 | for (j = 0; j < 8; j++) { |
232 : | for (i = 0; i < 8; i++) { | ||
233 : | edgomez | 195 | dst[j * stride + i] = src[j * stride + i]; |
234 : | } | ||
235 : | } | ||
236 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |