📄 image.c
字号:
interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width2, rounding);
interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width2, rounding);
interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width2, rounding);
n_ptr += 8;
h_ptr += 8;
v_ptr += 8;
hv_ptr += 8;
}
h_ptr += stride_add2;
v_ptr += stride_add2;
hv_ptr += stride_add2;
n_ptr += stride_add2;
}
#endif
*/
/*
interpolate_halfpel_h(
refh->y - offset,
refn->y - offset,
edged_width, edged_height,
rounding);
interpolate_halfpel_v(
refv->y - offset,
refn->y - offset,
edged_width, edged_height,
rounding);
interpolate_halfpel_hv(
refhv->y - offset,
refn->y - offset,
edged_width, edged_height,
rounding);
*/
/* uv-image-based compensation
offset = EDGE_SIZE2 * (edged_width / 2 + 1);
interpolate_halfpel_h(
refh->u - offset,
refn->u - offset,
edged_width / 2, edged_height / 2,
rounding);
interpolate_halfpel_v(
refv->u - offset,
refn->u - offset,
edged_width / 2, edged_height / 2,
rounding);
interpolate_halfpel_hv(
refhv->u - offset,
refn->u - offset,
edged_width / 2, edged_height / 2,
rounding);
interpolate_halfpel_h(
refh->v - offset,
refn->v - offset,
edged_width / 2, edged_height / 2,
rounding);
interpolate_halfpel_v(
refv->v - offset,
refn->v - offset,
edged_width / 2, edged_height / 2,
rounding);
interpolate_halfpel_hv(
refhv->v - offset,
refn->v - offset,
edged_width / 2, edged_height / 2,
rounding);
*/
}
/*
chroma optimize filter, invented by mf
a chroma pixel is average from the surrounding pixels, when the
correpsonding luma pixels are pure black or white.
*/
void
image_chroma_optimize(IMAGE * img, int width, int height, int edged_width)
{
int x,y;
int pixels = 0;
for (y = 1; y < height/2 - 1; y++)
for (x = 1; x < width/2 - 1; x++)
{
#define IS_PURE(a) ((a)<=16||(a)>=235)
#define IMG_Y(Y,X) img->y[(Y)*edged_width + (X)]
#define IMG_U(Y,X) img->u[(Y)*edged_width/2 + (X)]
#define IMG_V(Y,X) img->v[(Y)*edged_width/2 + (X)]
if (IS_PURE(IMG_Y(y*2 ,x*2 )) &&
IS_PURE(IMG_Y(y*2 ,x*2+1)) &&
IS_PURE(IMG_Y(y*2+1,x*2 )) &&
IS_PURE(IMG_Y(y*2+1,x*2+1)))
{
IMG_U(y,x) = (IMG_U(y,x-1) + IMG_U(y-1, x) + IMG_U(y, x+1) + IMG_U(y+1, x)) / 4;
IMG_V(y,x) = (IMG_V(y,x-1) + IMG_V(y-1, x) + IMG_V(y, x+1) + IMG_V(y+1, x)) / 4;
pixels++;
}
#undef IS_PURE
#undef IMG_Y
#undef IMG_U
#undef IMG_V
}
DPRINTF(XVID_DEBUG_DEBUG,"chroma_optimized_pixels = %i/%i\n", pixels, width*height/4);
}
/*
perform safe packed colorspace conversion, by splitting
the image up into an optimized area (pixel width divisible by 16),
and two unoptimized/plain-c areas (pixel width divisible by 2)
*/
static void
safe_packed_conv(uint8_t * x_ptr, int x_stride,
uint8_t * y_ptr, uint8_t * u_ptr, uint8_t * v_ptr,
int y_stride, int uv_stride,
int width, int height, int vflip,
packedFunc * func_opt, packedFunc func_c, int size)
{
int width_opt, width_c;
if (func_opt != func_c && x_stride < size*((width+15)/16)*16)
{
width_opt = width & (~15);
width_c = width - width_opt;
}
else
{
width_opt = width;
width_c = 0;
};
// func_opt(x_ptr, x_stride,
// y_ptr, u_ptr, v_ptr, y_stride, uv_stride,
// width_opt, height, vflip);
////////////////////////////////////////////////////////
UYVYtoYYUV( x_ptr, x_stride,
y_ptr, u_ptr, v_ptr, y_stride, uv_stride,
width_opt, height, vflip);
////////////////////////////////////////////////////////
if (width_c)
{
func_c(x_ptr + size*width_opt, x_stride,
y_ptr + width_opt, u_ptr + width_opt/2, v_ptr + width_opt/2,
y_stride, uv_stride, width_c, height, vflip);
}
}
int
image_input(IMAGE * image,
uint32_t width,
int height,
uint32_t edged_width,
uint8_t * src[4],
int src_stride[4],
int csp,
int interlacing)
{
const int edged_width2 = edged_width/2;
const int width2 = width/2;
const int height2 = height/2;
#if 0
const int height_signed = (csp & XVID_CSP_VFLIP) ? -height : height;
#endif
switch (csp & ~XVID_CSP_VFLIP) {
case XVID_CSP_RGB555:
safe_packed_conv(
src[0], src_stride[0], image->y, image->u, image->v,
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
interlacing?rgb555i_to_yv12 :rgb555_to_yv12,
interlacing?rgb555i_to_yv12_c:rgb555_to_yv12_c, 2);
break;
case XVID_CSP_RGB565:
safe_packed_conv(
src[0], src_stride[0], image->y, image->u, image->v,
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
interlacing?rgb565i_to_yv12 :rgb565_to_yv12,
interlacing?rgb565i_to_yv12_c:rgb565_to_yv12_c, 2);
break;
case XVID_CSP_BGR:
safe_packed_conv(
src[0], src_stride[0], image->y, image->u, image->v,
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
interlacing?bgri_to_yv12 :bgr_to_yv12,
interlacing?bgri_to_yv12_c:bgr_to_yv12_c, 3);
break;
case XVID_CSP_BGRA:
safe_packed_conv(
src[0], src_stride[0], image->y, image->u, image->v,
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
interlacing?bgrai_to_yv12 :bgra_to_yv12,
interlacing?bgrai_to_yv12_c:bgra_to_yv12_c, 4);
break;
case XVID_CSP_ABGR :
safe_packed_conv(
src[0], src_stride[0], image->y, image->u, image->v,
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
interlacing?abgri_to_yv12 :abgr_to_yv12,
interlacing?abgri_to_yv12_c:abgr_to_yv12_c, 4);
break;
case XVID_CSP_RGBA :
safe_packed_conv(
src[0], src_stride[0], image->y, image->u, image->v,
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
interlacing?rgbai_to_yv12 :rgba_to_yv12,
interlacing?rgbai_to_yv12_c:rgba_to_yv12_c, 4);
break;
case XVID_CSP_ARGB:
safe_packed_conv(
src[0], src_stride[0], image->y, image->u, image->v,
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
interlacing?argbi_to_yv12 : argb_to_yv12,
interlacing?argbi_to_yv12_c: argb_to_yv12_c, 4);
break;
case XVID_CSP_YUY2:
safe_packed_conv(
src[0], src_stride[0], image->y, image->u, image->v,
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
interlacing?yuyvi_to_yv12 :yuyv_to_yv12,
interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2);
break;
case XVID_CSP_YVYU: /* u/v swapped */
safe_packed_conv(
src[0], src_stride[0], image->y, image->v, image->u,
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
interlacing?yuyvi_to_yv12 :yuyv_to_yv12,
interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2);
break;
case XVID_CSP_UYVY:
safe_packed_conv(
src[0], src_stride[0], image->y, image->u, image->v,
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
interlacing?uyvyi_to_yv12 :uyvy_to_yv12,
interlacing?uyvyi_to_yv12_c:uyvy_to_yv12_c, 2);
break;
case XVID_CSP_I420: /* YCbCr == YUV == internal colorspace for MPEG */
yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2,
src[0], src[0] + src_stride[0]*height, src[0] + src_stride[0]*height + (src_stride[0]/2)*height2,
src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP));
break;
case XVID_CSP_YV12: /* YCrCb == YVA == U and V plane swapped */
yv12_to_yv12(image->y, image->v, image->u, edged_width, edged_width2,
src[0], src[0] + src_stride[0]*height, src[0] + src_stride[0]*height + (src_stride[0]/2)*height2,
src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP));
break;
case XVID_CSP_PLANAR: /* YCbCr with arbitrary pointers and different strides for Y and UV */
yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2,
src[0], src[1], src[2], src_stride[0], src_stride[1], /* v: dst_stride[2] not yet supported */
width, height, (csp & XVID_CSP_VFLIP));
break;
case XVID_CSP_NULL:
break;
default :
return -1;
}
/* pad out image when the width and/or height is not a multiple of 16 */
if (width & 15)
{
int i;
int pad_width = 16 - (width&15);
for (i = 0; i < height; i++)
{
memset(image->y + i*edged_width + width,
*(image->y + i*edged_width + width - 1), pad_width);
}
for (i = 0; i < height/2; i++)
{
memset(image->u + i*edged_width2 + width2,
*(image->u + i*edged_width2 + width2 - 1),pad_width/2);
memset(image->v + i*edged_width2 + width2,
*(image->v + i*edged_width2 + width2 - 1),pad_width/2);
}
}
if (height & 15)
{
int pad_height = 16 - (height&15);
int length = ((width+15)/16)*16;
int i;
for (i = 0; i < pad_height; i++)
{
memcpy(image->y + (height+i)*edged_width,
image->y + (height-1)*edged_width,length);
}
for (i = 0; i < pad_height/2; i++)
{
memcpy(image->u + (height2+i)*edged_width2,
image->u + (height2-1)*edged_width2,length/2);
memcpy(image->v + (height2+i)*edged_width2,
image->v + (height2-1)*edged_width2,length/2);
}
}
/*
if (interlacing)
image_printf(image, edged_width, height, 5,5, "[i]");
image_dump_yuvpgm(image, edged_width, ((width+15)/16)*16, ((height+15)/16)*16, "\\encode.pgm");
*/
return 0;
}
int
image_output(IMAGE * image,
uint32_t width,
int height,
uint32_t edged_width,
uint8_t * dst[4],
uint32_t dst_stride[4],
int csp,
int interlacing)
{
const int edged_width2 = edged_width/2;
int height2 = height/2;
/*
if (interlacing)
image_printf(image, edged_width, height, 5,100, "[i]=%i,%i",width,height);
image_dump_yuvpgm(image, edged_width, width, height, "\\decode.pgm");
*/
switch (csp & ~XVID_CSP_VFLIP) {
case XVID_CSP_RGB555:
safe_packed_conv(
dst[0], dst_stride[0], image->y, image->u, image->v,
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
interlacing?yv12_to_rgb555i :yv12_to_rgb555,
interlacing?yv12_to_rgb555i_c:yv12_to_rgb555_c, 2);
return 0;
case XVID_CSP_RGB565:
safe_packed_conv(
dst[0], dst_stride[0], image->y, image->u, image->v,
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
interlacing?yv12_to_rgb565i :yv12_to_rgb565,
interlacing?yv12_to_rgb565i_c:yv12_to_rgb565_c, 2);
return 0;
case XVID_CSP_BGR:
safe_packed_conv(
dst[0], dst_stride[0], image->y, image->u, image->v,
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
interlacing?yv12_to_bgri :yv12_to_bgr,
interlacing?yv12_to_bgri_c:yv12_to_bgr_c, 3);
return 0;
case XVID_CSP_BGRA:
safe_packed_conv(
dst[0], dst_stride[0], image->y, image->u, image->v,
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
interlacing?yv12_to_bgrai :yv12_to_bgra,
interlacing?yv12_to_bgrai_c:yv12_to_bgra_c, 4);
return 0;
case XVID_CSP_ABGR:
safe_packed_conv(
dst[0], dst_stride[0], image->y, image->u, image->v,
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
interlacing?yv12_to_abgri :yv12_to_abgr,
interlacing?yv12_to_abgri_c:yv12_to_abgr_c, 4);
return 0;
case XVID_CSP_RGBA:
safe_packed_conv(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -