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 |
* History: |
* - 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 |
* 14.04.2002 added transfer_8to16sub2 |
* $Id$ |
32 |
* 07.01.2002 merge functions from compensate; rename functions |
* |
33 |
* 22.12.2001 transfer_8to8add16 limit fix |
****************************************************************************/ |
34 |
* 07.11.2001 initial version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
|
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_8TO16SUB2_PTR transfer_8to16sub2; |
TRANSFER_8TO16SUB2_PTR transfer_8to16sub2; |
45 |
TRANSFER_16TO8ADD_PTR transfer_16to8add; |
TRANSFER_16TO8ADD_PTR transfer_16to8add; |
46 |
|
|
47 |
// function pointers |
TRANSFER8X8_COPY_PTR transfer8x8_copy; |
48 |
|
|
49 |
|
|
50 |
/***************************************************************************** |
/***************************************************************************** |
51 |
* |
* |
52 |
TRANSFER_8TO16SUB_PTR transfer_8to16sub; |
* All these functions are used to transfer data from a 8 bit data array |
53 |
* to a 16 bit data array. |
* to a 16 bit data array. |
54 |
TRANSFER_16TO8ADD_PTR transfer_16to8add; |
* |
55 |
* This is typically used during motion compensation, that's why some |
* This is typically used during motion compensation, that's why some |
56 |
* functions also do the addition/substraction of another buffer during the |
* functions also do the addition/substraction of another buffer during the |
57 |
* so called transfer. |
* so called transfer. |
58 |
* |
* |
59 |
|
****************************************************************************/ |
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 |
*/ |
*/ |
70 |
|
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 |
dst[j * 8 + i] = (int16_t) src[j * stride + i]; |
dst[j * 8 + i] = (int16_t) src[j * stride + i]; |
80 |
} |
} |
81 |
} |
} |
90 |
* SRC (16bit) = SRC |
* SRC (16bit) = SRC |
91 |
* DST (8bit) = max(min(SRC, 255), 0) |
* DST (8bit) = max(min(SRC, 255), 0) |
92 |
*/ |
*/ |
93 |
|
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 |
|
|
100 |
|
for (j = 0; j < 8; j++) { |
101 |
|
for (i = 0; i < 8; i++) { |
102 |
int16_t pixel = src[j * 8 + i]; |
int16_t pixel = src[j * 8 + i]; |
103 |
|
|
104 |
if (pixel < 0) { |
if (pixel < 0) { |
124 |
* R (8bit) = R |
* R (8bit) = R |
125 |
* C (8bit) = R |
* C (8bit) = R |
126 |
* DCT (16bit) = C - R |
* DCT (16bit) = C - R |
|
perform motion compensation (and 8bit->16bit dct transfer) |
|
|
... with write back |
|
127 |
*/ |
*/ |
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 |
for (i = 0; i < 8; i++) { |
for (i = 0; i < 8; i++) { |
138 |
uint8_t c = cur[j * stride + i]; |
uint8_t c = cur[j * stride + i]; |
139 |
uint8_t r = ref[j * stride + i]; |
uint8_t r = ref[j * stride + i]; |
155 |
* |
* |
156 |
* R1 (8bit) = R1 |
* R1 (8bit) = R1 |
157 |
* R2 (8bit) = R2 |
* R2 (8bit) = R2 |
158 |
performs bi motion compensation (and 8bit->16bit dct transfer) |
* C (8bit) = C |
159 |
.. but does not write back |
* 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 |
for (j = 0; j < 8; j++) { |
for (j = 0; j < 8; j++) { |
171 |
for (i = 0; i < 8; i++) { |
for (i = 0; i < 8; i++) { |
172 |
uint8_t c = cur[j * stride + i]; |
uint8_t c = cur[j * stride + i]; |
191 |
* SRC (16bit) = SRC |
* SRC (16bit) = SRC |
192 |
* DST (8bit) = max(min(DST+SRC, 255), 0) |
* DST (8bit) = max(min(DST+SRC, 255), 0) |
193 |
*/ |
*/ |
194 |
|
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 |
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]; |
204 |
|
|
205 |
if (pixel < 0) { |
if (pixel < 0) { |
221 |
* SRC (8bit) = SRC |
* SRC (8bit) = SRC |
222 |
* DST (8bit) = SRC |
* DST (8bit) = SRC |
223 |
*/ |
*/ |
224 |
|
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 |
|
|
231 |
|
for (j = 0; j < 8; j++) { |
232 |
|
for (i = 0; i < 8; i++) { |
233 |
dst[j * stride + i] = src[j * stride + i]; |
dst[j * stride + i] = src[j * stride + i]; |
234 |
} |
} |
235 |
} |
} |