1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* 8bit<->16bit transfer |
* - 8bit<->16bit transfer - |
|
* |
|
|
* This program is an implementation of a part of one or more MPEG-4 |
|
|
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
|
|
* to use this software module in hardware or software products are |
|
|
* advised that its use may infringe existing patents or copyrights, and |
|
|
* any such use would be at such party's own risk. The original |
|
|
* developer of this software module and his/her company, and subsequent |
|
|
* editors and their companies, will have no liability for use of this |
|
|
* software or modifications or derivatives thereof. |
|
5 |
* |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
* 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 |
* it under the terms of the GNU General Public License as published by |
15 |
* |
* |
16 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
* |
* |
20 |
*************************************************************************/ |
****************************************************************************/ |
21 |
|
/***************************************************************************** |
22 |
/************************************************************************** |
* |
23 |
|
* History |
24 |
|
* |
25 |
|
* - 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 |
* |
* |
31 |
* History: |
* $Id: mem_transfer.c,v 1.9 2003-02-15 15:22:19 edgomez Exp $ |
32 |
* |
* |
33 |
* 14.04.2002 added transfer_8to16sub2 |
****************************************************************************/ |
|
* 07.01.2002 merge functions from compensate; rename functions |
|
|
* 22.12.2001 transfer_8to8add16 limit fix |
|
|
* 07.11.2001 initial version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
|
34 |
|
|
35 |
*************************************************************************/ |
#include "../global.h" |
36 |
|
#include "mem_transfer.h" |
37 |
|
|
38 |
|
/* Function pointers - Initialized in the xvid.c module */ |
39 |
|
|
40 |
|
TRANSFER_8TO16COPY_PTR transfer_8to16copy; |
41 |
|
TRANSFER_16TO8COPY_PTR transfer_16to8copy; |
42 |
|
|
43 |
TRANSFER_8TO16SUB_PTR transfer_8to16sub; |
TRANSFER_8TO16SUB_PTR transfer_8to16sub; |
44 |
|
TRANSFER_8TO16SUBRO_PTR transfer_8to16subro; |
45 |
TRANSFER_8TO16SUB2_PTR transfer_8to16sub2; |
TRANSFER_8TO16SUB2_PTR transfer_8to16sub2; |
46 |
TRANSFER_16TO8ADD_PTR transfer_16to8add; |
TRANSFER_16TO8ADD_PTR transfer_16to8add; |
47 |
|
|
48 |
// function pointers |
TRANSFER8X8_COPY_PTR transfer8x8_copy; |
49 |
|
|
50 |
|
|
51 |
/***************************************************************************** |
/***************************************************************************** |
52 |
* |
* |
53 |
TRANSFER_8TO16SUB_PTR transfer_8to16sub; |
* All these functions are used to transfer data from a 8 bit data array |
54 |
* to a 16 bit data array. |
* to a 16 bit data array. |
55 |
TRANSFER_16TO8ADD_PTR transfer_16to8add; |
* |
56 |
* This is typically used during motion compensation, that's why some |
* This is typically used during motion compensation, that's why some |
57 |
* functions also do the addition/substraction of another buffer during the |
* functions also do the addition/substraction of another buffer during the |
58 |
* so called transfer. |
* so called transfer. |
59 |
* |
* |
60 |
|
****************************************************************************/ |
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 |
*/ |
*/ |
71 |
|
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 |
dst[j * 8 + i] = (int16_t) src[j * stride + i]; |
dst[j * 8 + i] = (int16_t) src[j * stride + i]; |
81 |
} |
} |
82 |
} |
} |
91 |
* SRC (16bit) = SRC |
* SRC (16bit) = SRC |
92 |
* DST (8bit) = max(min(SRC, 255), 0) |
* DST (8bit) = max(min(SRC, 255), 0) |
93 |
*/ |
*/ |
94 |
|
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 |
|
|
101 |
|
for (j = 0; j < 8; j++) { |
102 |
|
for (i = 0; i < 8; i++) { |
103 |
int16_t pixel = src[j * 8 + i]; |
int16_t pixel = src[j * 8 + i]; |
104 |
|
|
105 |
if (pixel < 0) { |
if (pixel < 0) { |
125 |
* R (8bit) = R |
* R (8bit) = R |
126 |
* C (8bit) = R |
* C (8bit) = R |
127 |
* DCT (16bit) = C - R |
* DCT (16bit) = C - R |
|
perform motion compensation (and 8bit->16bit dct transfer) |
|
|
... with write back |
|
128 |
*/ |
*/ |
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 |
for (i = 0; i < 8; i++) { |
for (i = 0; i < 8; i++) { |
139 |
uint8_t c = cur[j * stride + i]; |
uint8_t c = cur[j * stride + i]; |
140 |
uint8_t r = ref[j * stride + i]; |
uint8_t r = ref[j * stride + i]; |
146 |
} |
} |
147 |
|
|
148 |
|
|
149 |
|
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 |
/* |
/* |
169 |
* C - the current buffer |
* C - the current buffer |
170 |
* R1 - the 1st reference buffer |
* R1 - the 1st reference buffer |
175 |
* |
* |
176 |
* R1 (8bit) = R1 |
* R1 (8bit) = R1 |
177 |
* R2 (8bit) = R2 |
* R2 (8bit) = R2 |
178 |
performs bi motion compensation (and 8bit->16bit dct transfer) |
* C (8bit) = C |
179 |
.. but does not write back |
* 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 |
for (j = 0; j < 8; j++) { |
for (j = 0; j < 8; j++) { |
191 |
for (i = 0; i < 8; i++) { |
for (i = 0; i < 8; i++) { |
192 |
uint8_t c = cur[j * stride + i]; |
uint8_t c = cur[j * stride + i]; |
211 |
* SRC (16bit) = SRC |
* SRC (16bit) = SRC |
212 |
* DST (8bit) = max(min(DST+SRC, 255), 0) |
* DST (8bit) = max(min(DST+SRC, 255), 0) |
213 |
*/ |
*/ |
214 |
|
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 |
int16_t pixel = (int16_t) dst[j * stride + i] + src[j * 8 + i]; |
int16_t pixel = (int16_t) dst[j * stride + i] + src[j * 8 + i]; |
224 |
|
|
225 |
if (pixel < 0) { |
if (pixel < 0) { |
241 |
* SRC (8bit) = SRC |
* SRC (8bit) = SRC |
242 |
* DST (8bit) = SRC |
* DST (8bit) = SRC |
243 |
*/ |
*/ |
244 |
|
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 |
|
|
251 |
|
for (j = 0; j < 8; j++) { |
252 |
|
for (i = 0; i < 8; i++) { |
253 |
dst[j * stride + i] = src[j * stride + i]; |
dst[j * stride + i] = src[j * stride + i]; |
254 |
} |
} |
255 |
} |
} |