34 |
#include "interpolate8x8.h" |
#include "interpolate8x8.h" |
35 |
#include "../utils/mem_align.h" |
#include "../utils/mem_align.h" |
36 |
#include "../motion/sad.h" |
#include "../motion/sad.h" |
37 |
|
#include "../utils/emms.h" |
38 |
|
|
39 |
#include "font.h" /* XXX: remove later */ |
#include "font.h" /* XXX: remove later */ |
40 |
|
|
237 |
} |
} |
238 |
} |
} |
239 |
|
|
|
/* bframe encoding requires image-based u,v interpolation */ |
|
240 |
void |
void |
241 |
image_interpolate(const IMAGE * refn, |
image_interpolate(const uint8_t * refn, |
242 |
IMAGE * refh, |
uint8_t * refh, |
243 |
IMAGE * refv, |
uint8_t * refv, |
244 |
IMAGE * refhv, |
uint8_t * refhv, |
245 |
uint32_t edged_width, |
uint32_t edged_width, |
246 |
uint32_t edged_height, |
uint32_t edged_height, |
247 |
uint32_t quarterpel, |
uint32_t quarterpel, |
250 |
const uint32_t offset = EDGE_SIZE2 * (edged_width + 1); /* we only interpolate half of the edge area */ |
const uint32_t offset = EDGE_SIZE2 * (edged_width + 1); /* we only interpolate half of the edge area */ |
251 |
const uint32_t stride_add = 7 * edged_width; |
const uint32_t stride_add = 7 * edged_width; |
252 |
|
|
253 |
uint8_t *n_ptr, *h_ptr, *v_ptr, *hv_ptr; |
uint8_t *n_ptr; |
254 |
|
uint8_t *h_ptr, *v_ptr, *hv_ptr; |
255 |
uint32_t x, y; |
uint32_t x, y; |
256 |
|
|
257 |
|
n_ptr = (uint8_t*)refn; |
258 |
n_ptr = refn->y; |
h_ptr = refh; |
259 |
h_ptr = refh->y; |
v_ptr = refv; |
|
v_ptr = refv->y; |
|
260 |
|
|
261 |
n_ptr -= offset; |
n_ptr -= offset; |
262 |
h_ptr -= offset; |
h_ptr -= offset; |
285 |
n_ptr += stride_add; |
n_ptr += stride_add; |
286 |
} |
} |
287 |
|
|
288 |
h_ptr = refh->y + (edged_height - EDGE_SIZE - EDGE_SIZE2)*edged_width - EDGE_SIZE2; |
h_ptr = refh + (edged_height - EDGE_SIZE - EDGE_SIZE2)*edged_width - EDGE_SIZE2; |
289 |
hv_ptr = refhv->y + (edged_height - EDGE_SIZE - EDGE_SIZE2)*edged_width - EDGE_SIZE2; |
hv_ptr = refhv + (edged_height - EDGE_SIZE - EDGE_SIZE2)*edged_width - EDGE_SIZE2; |
290 |
|
|
291 |
for (y = 0; y < (edged_height - EDGE_SIZE); y = y + 8) { |
for (y = 0; y < (edged_height - EDGE_SIZE); y = y + 8) { |
292 |
hv_ptr -= stride_add; |
hv_ptr -= stride_add; |
302 |
} |
} |
303 |
} else { |
} else { |
304 |
|
|
305 |
hv_ptr = refhv->y; |
hv_ptr = refhv; |
306 |
hv_ptr -= offset; |
hv_ptr -= offset; |
307 |
|
|
308 |
for (y = 0; y < (edged_height - EDGE_SIZE); y += 8) { |
for (y = 0; y < (edged_height - EDGE_SIZE); y += 8) { |
1015 |
p += edged_width/2; |
p += edged_width/2; |
1016 |
} |
} |
1017 |
} |
} |
1018 |
|
|
1019 |
|
/****************************************************************************/ |
1020 |
|
|
1021 |
|
static void (*deintl_core)(uint8_t *, int width, int height, const int stride) = 0; |
1022 |
|
extern void xvid_deinterlace_sse(uint8_t *, int width, int height, const int stride); |
1023 |
|
|
1024 |
|
#define CLIP_255(x) ( ((x)&~255) ? ((-(x)) >> (8*sizeof((x))-1))&0xff : (x) ) |
1025 |
|
|
1026 |
|
static void deinterlace_c(uint8_t *pix, int width, int height, const int bps) |
1027 |
|
{ |
1028 |
|
pix += bps; |
1029 |
|
while(width-->0) |
1030 |
|
{ |
1031 |
|
int p1 = pix[-bps]; |
1032 |
|
int p2 = pix[0]; |
1033 |
|
int p0 = p2; |
1034 |
|
int j = (height>>1) - 1; |
1035 |
|
int V; |
1036 |
|
unsigned char *P = pix++; |
1037 |
|
while(j-->0) |
1038 |
|
{ |
1039 |
|
const int p3 = P[ bps]; |
1040 |
|
const int p4 = P[2*bps]; |
1041 |
|
V = ((p1+p3+1)>>1) + ((p2 - ((p0+p4+1)>>1)) >> 2); |
1042 |
|
P[0] = CLIP_255( V ); |
1043 |
|
p0 = p2; |
1044 |
|
p1 = p3; |
1045 |
|
p2 = p4; |
1046 |
|
P += 2*bps; |
1047 |
|
} |
1048 |
|
V = ((p1+p1+1)>>1) + ((p2 - ((p0+p2+1)>>1)) >> 2); |
1049 |
|
P[0] = CLIP_255( V ); |
1050 |
|
} |
1051 |
|
} |
1052 |
|
#undef CLIP_255 |
1053 |
|
|
1054 |
|
int xvid_image_deinterlace(xvid_image_t* img, int width, int height, int bottom_first) |
1055 |
|
{ |
1056 |
|
if (height&1) |
1057 |
|
return 0; |
1058 |
|
if (img->csp!=XVID_CSP_PLANAR && img->csp!=XVID_CSP_I420 && img->csp!=XVID_CSP_YV12) |
1059 |
|
return 0; /* not yet supported */ |
1060 |
|
if (deintl_core==0) { |
1061 |
|
const int cpu_flags = check_cpu_features(); |
1062 |
|
deintl_core = deinterlace_c; |
1063 |
|
#ifdef ARCH_IS_IA32 |
1064 |
|
if (cpu_flags & XVID_CPU_MMX) |
1065 |
|
deintl_core = xvid_deinterlace_sse; |
1066 |
|
#endif |
1067 |
|
} |
1068 |
|
if (!bottom_first) { |
1069 |
|
deintl_core(img->plane[0], width, height, img->stride[0]); |
1070 |
|
deintl_core(img->plane[1], width>>1, height>>1, img->stride[1]); |
1071 |
|
deintl_core(img->plane[2], width>>1, height>>1, img->stride[2]); |
1072 |
|
} |
1073 |
|
else { |
1074 |
|
deintl_core((uint8_t *)img->plane[0] + ( height -1)*img->stride[0], width, height, -img->stride[0]); |
1075 |
|
deintl_core((uint8_t *)img->plane[1] + ((height>>1)-1)*img->stride[1], width>>1, height>>1, -img->stride[1]); |
1076 |
|
deintl_core((uint8_t *)img->plane[2] + ((height>>1)-1)*img->stride[2], width>>1, height>>1, -img->stride[2]); |
1077 |
|
} |
1078 |
|
emms(); |
1079 |
|
|
1080 |
|
return 1; |
1081 |
|
} |
1082 |
|
|