?? image.c
字號:
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);
*/
}
int image_input(IMAGE * image, uint32_t width, int height,
uint32_t edged_width, uint8_t * src, int csp)
{
/* if (csp & XVID_CSP_VFLIP)
{
height = -height;
}
*/
switch(csp & ~XVID_CSP_VFLIP)
{
case XVID_CSP_RGB555 :
rgb555_to_yv12(image->y, image->u, image->v, src,
width, height, edged_width);
return 0;
case XVID_CSP_RGB565 :
rgb565_to_yv12(image->y, image->u, image->v, src,
width, height, edged_width);
return 0;
case XVID_CSP_RGB24 :
rgb24_to_yv12(image->y, image->u, image->v, src,
width, height, edged_width);
return 0;
case XVID_CSP_RGB32 :
rgb32_to_yv12(image->y, image->u, image->v, src,
width, height, edged_width);
return 0;
case XVID_CSP_I420 :
yuv_to_yv12(image->y, image->u, image->v, src,
width, height, edged_width);
return 0;
case XVID_CSP_YV12 : /* u/v swapped */
yuv_to_yv12(image->y, image->v, image->u, src,
width, height, edged_width);
return 0;
case XVID_CSP_YUY2 :
yuyv_to_yv12(image->y, image->u, image->v, src,
width, height, edged_width);
return 0;
case XVID_CSP_YVYU : /* u/v swapped */
yuyv_to_yv12(image->y, image->v, image->u, src,
width, height, edged_width);
return 0;
case XVID_CSP_UYVY :
uyvy_to_yv12(image->y, image->u, image->v, src,
width, height, edged_width);
return 0;
case XVID_CSP_NULL :
break;
}
return -1;
}
int image_output(IMAGE * image, uint32_t width, int height, uint32_t edged_width,
uint8_t * dst, uint32_t dst_stride, int csp)
{
if (csp & XVID_CSP_VFLIP)
{
height = -height;
}
switch(csp & ~XVID_CSP_VFLIP)
{
case XVID_CSP_RGB555 :
yv12_to_rgb555(dst, dst_stride,
image->y, image->u, image->v, edged_width, edged_width / 2,
width, height);
return 0;
case XVID_CSP_RGB565 :
yv12_to_rgb565(dst, dst_stride,
image->y, image->u, image->v, edged_width, edged_width / 2,
width, height);
return 0;
case XVID_CSP_RGB24 :
yv12_to_rgb24(dst, dst_stride,
image->y, image->u, image->v, edged_width, edged_width / 2,
width, height);
return 0;
case XVID_CSP_RGB32 :
yv12_to_rgb32(dst, dst_stride,
image->y, image->u, image->v, edged_width, edged_width / 2,
width, height);
return 0;
case XVID_CSP_I420 :
yv12_to_yuv(dst, dst_stride,
image->y, image->u, image->v, edged_width, edged_width / 2,
width, height);
return 0;
case XVID_CSP_YV12 : // u,v swapped
yv12_to_yuv(dst, dst_stride,
image->y, image->v, image->u, edged_width, edged_width / 2,
width, height);
return 0;
case XVID_CSP_YUY2 :
yv12_to_yuyv(dst, dst_stride,
image->y, image->u, image->v, edged_width, edged_width / 2,
width, height);
return 0;
case XVID_CSP_YVYU : // u,v swapped
yv12_to_yuyv(dst, dst_stride,
image->y, image->v, image->u, edged_width, edged_width / 2,
width, height);
return 0;
case XVID_CSP_UYVY :
yv12_to_uyvy(dst, dst_stride,
image->y, image->u, image->v, edged_width, edged_width / 2,
width, height);
return 0;
case XVID_CSP_USER :
((DEC_PICTURE*)dst)->y = image->y;
((DEC_PICTURE*)dst)->u = image->u;
((DEC_PICTURE*)dst)->v = image->v;
((DEC_PICTURE*)dst)->stride_y = edged_width;
((DEC_PICTURE*)dst)->stride_uv = edged_width/2;
return 0;
case XVID_CSP_NULL :
return 0;
}
return -1;
}
float image_psnr(IMAGE *orig_image, IMAGE *recon_image,
uint16_t stride, uint16_t width, uint16_t height)
{
int32_t diff, x, y, quad = 0;
uint8_t *orig = orig_image->y;
uint8_t *recon = recon_image->y;
float psnr_y;
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
diff = *(orig + x) - *(recon + x);
quad += diff*diff;
}
orig += stride;
recon += stride;
}
psnr_y = (float) quad / (float) (width * height);
if (psnr_y) {
psnr_y = (float) (255 * 255) / psnr_y;
psnr_y = 10 * (float) log10 (psnr_y);
}
else
psnr_y = (float) 99.99;
return psnr_y;
}
#include <stdio.h>
#include <string.h>
int image_dump_pgm(uint8_t * bmp, uint32_t width, uint32_t height, char * filename)
{
FILE * f;
char hdr[1024];
f = fopen(filename, "wb");
if ( f == NULL)
{
return -1;
}
sprintf(hdr, "P5\n#xvid\n%i %i\n255\n", width, height);
fwrite(hdr, strlen(hdr), 1, f);
fwrite(bmp, width, height, f);
fclose(f);
return 0;
}
/* dump image+edges to yuv pgm files */
int image_dump(IMAGE * image, uint32_t edged_width, uint32_t edged_height, char * path, int number)
{
char filename[1024];
sprintf(filename, "%s_%i_%c.pgm", path, number, 'y');
image_dump_pgm(
image->y - (EDGE_SIZE * edged_width + EDGE_SIZE),
edged_width, edged_height, filename);
sprintf(filename, "%s_%i_%c.pgm", path, number, 'u');
image_dump_pgm(
image->u - (EDGE_SIZE2 * edged_width / 2 + EDGE_SIZE2),
edged_width / 2, edged_height / 2, filename);
sprintf(filename, "%s_%i_%c.pgm", path, number, 'v');
image_dump_pgm(
image->v - (EDGE_SIZE2 * edged_width / 2 + EDGE_SIZE2),
edged_width / 2, edged_height / 2, filename);
return 0;
}
#ifdef MPEG4IP
int yuv_input(
IMAGE * image,
uint32_t width,
uint32_t height,
uint32_t stride_out,
uint8_t *y_in,
uint8_t *u_in,
uint8_t *v_in,
uint32_t stride_in,
int csp)
{
uint8_t* y_out = image->y;
uint8_t* u_out = image->u;
uint8_t* v_out = image->v;
uint32_t stridein2 = stride_in >> 1;
uint32_t strideout2 = stride_out >> 1;
uint32_t width2 = width >> 1;
uint32_t y;
for (y = height; y; y--) {
memcpy(y_out, y_in, width);
y_in += stride_in;
y_out += stride_out;
}
for (y = height >> 1; y; y--) {
memcpy(u_out, u_in, width2);
u_in += stridein2;
u_out += strideout2;
}
for (y = height >> 1; y; y--) {
memcpy(v_out, v_in, width2);
v_in += stridein2;
v_out+= strideout2;
}
return 0;
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -