📄 mvimage.c
字号:
#include "MVGlobal.h"
#include "MVImage.h"#include "MVMemoryalloc.h"#include <memory.h>
#include <string.h>
void image_null(IMAGE * image)
{
image->y = image->u = image->v = NULL;
}
int32_t image_create(IMAGE * image, uint32_t edged_width, uint32_t edged_height){ const uint32_t edged_width2 = edged_width / 2; const uint32_t edged_height2 = edged_height / 2; image->y = (uint8_t *) xvid_malloc(edged_width * (edged_height + 1) + SAFETY, CACHE_LINE); if (image->y == NULL)
{ return -1; } memset(image->y, 0, edged_width * (edged_height + 1) + SAFETY); image->u = (uint8_t *) xvid_malloc(edged_width2 * edged_height2 + SAFETY, CACHE_LINE); if (image->u == NULL)
{ xvid_free(image->y); image->y = NULL; return -1; } memset(image->u, 0, edged_width2 * edged_height2 + SAFETY); image->v = (uint8_t *) xvid_malloc(edged_width2 * edged_height2 + SAFETY, CACHE_LINE); if (image->v == NULL)
{ xvid_free((void *)image->u); image->u = NULL; xvid_free((void *)image->y); image->y = NULL; return -1; } memset(image->v, 0, edged_width2 * edged_height2 + SAFETY); image->y += EDGE_SIZE * edged_width + EDGE_SIZE; image->u += EDGE_SIZE2 * edged_width2 + EDGE_SIZE2; image->v += EDGE_SIZE2 * edged_width2 + EDGE_SIZE2; return 0;}void image_destroy(IMAGE * image, uint32_t edged_width, uint32_t edged_height){ const uint32_t edged_width2 = edged_width / 2; if (image->y)
{ xvid_free((void *)(image->y - (EDGE_SIZE * edged_width + EDGE_SIZE))); image->y = NULL; } if (image->u)
{ xvid_free((void *)(image->u - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2))); image->u = NULL; } if (image->v)
{ xvid_free((void *)(image->v - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2))); image->v = NULL; }}
/* after decoded. the frame picture is copyed to user buffer,
* the function is implement the work yuv420->yuv420
* wuhaibin 20070122
*/static void yv12_to_yv12(uint8_t * y_dst, uint8_t * u_dst, uint8_t * v_dst,
int y_dst_stride, int uv_dst_stride,
uint8_t * y_src, uint8_t * u_src, uint8_t * v_src,
int y_src_stride, int uv_src_stride,
int width, int height, uint32_t *out_len)
{
int width2 = width / 2;
int height2 = height / 2;
int y;
for (y = height; y; y--)
{
memcpy(y_dst, y_src, width);
y_src += y_src_stride;
y_dst += y_dst_stride;
}
for (y = height2; y; y--)
{
memcpy(u_dst, u_src, width2);
u_src += uv_src_stride;
u_dst += uv_dst_stride;
}
for (y = height2; y; y--)
{
memcpy(v_dst, v_src, width2);
v_src += uv_src_stride;
v_dst += uv_dst_stride;
}
*out_len = height * width * 3 / 2;
return ;
}
int image_output(IMAGE * image, uint32_t width, int height,
uint32_t edged_width, uint8_t * dst, int dst_stride,
uint32_t *out_len, uint32_t type)
{ int edged_width2 = edged_width/2; int height2 = height/2;
yv12_to_yv12(dst, dst + dst_stride * height,
dst + dst_stride * height + (dst_stride/2)*height2,
dst_stride, dst_stride/2, image->y, image->u, image->v,
edged_width, edged_width2, width, height, out_len);
return 0;}void image_setedges(IMAGE * image, uint32_t edged_width, uint32_t edged_height, uint32_t width, uint32_t height, int bs_version){ const uint32_t edged_width2 = edged_width / 2; uint32_t width2; uint32_t i; uint8_t *dst; uint8_t *src; dst = image->y - (EDGE_SIZE + EDGE_SIZE * edged_width); src = image->y; /*if (bs_version == 0 || bs_version >= SETEDGES_BUG_BEFORE) { width = (width+15)&~15; height = (height+15)&~15; }*/ width2 = width/2; for (i = 0; i < EDGE_SIZE; i++) { memset(dst, *src, EDGE_SIZE); memcpy(dst + EDGE_SIZE, src, width); memset(dst + edged_width - EDGE_SIZE, *(src + width - 1), EDGE_SIZE); dst += edged_width; } for (i = 0; i < height; i++) { memset(dst, *src, EDGE_SIZE); memset(dst + edged_width - EDGE_SIZE, src[width - 1], EDGE_SIZE); dst += edged_width; src += edged_width; } src -= edged_width; for (i = 0; i < EDGE_SIZE; i++) { memset(dst, *src, EDGE_SIZE); memcpy(dst + EDGE_SIZE, src, width); memset(dst + edged_width - EDGE_SIZE, *(src + width - 1), EDGE_SIZE); dst += edged_width; } /* U */ dst = image->u - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2); src = image->u; for (i = 0; i < EDGE_SIZE2; i++) { memset(dst, *src, EDGE_SIZE2); memcpy(dst + EDGE_SIZE2, src, width2); memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1), EDGE_SIZE2); dst += edged_width2; } for (i = 0; i < height / 2; i++) { memset(dst, *src, EDGE_SIZE2); memset(dst + edged_width2 - EDGE_SIZE2, src[width2 - 1], EDGE_SIZE2); dst += edged_width2; src += edged_width2; } src -= edged_width2; for (i = 0; i < EDGE_SIZE2; i++) { memset(dst, *src, EDGE_SIZE2); memcpy(dst + EDGE_SIZE2, src, width2); memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1), EDGE_SIZE2); dst += edged_width2; } /* V */ dst = image->v - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2); src = image->v; for (i = 0; i < EDGE_SIZE2; i++) { memset(dst, *src, EDGE_SIZE2); memcpy(dst + EDGE_SIZE2, src, width2); memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1), EDGE_SIZE2); dst += edged_width2; } for (i = 0; i < height / 2; i++) { memset(dst, *src, EDGE_SIZE2); memset(dst + edged_width2 - EDGE_SIZE2, src[width2 - 1], EDGE_SIZE2); dst += edged_width2; src += edged_width2; } src -= edged_width2; for (i = 0; i < EDGE_SIZE2; i++) { memset(dst, *src, EDGE_SIZE2); memcpy(dst + EDGE_SIZE2, src, width2); memset(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1), EDGE_SIZE2); dst += edged_width2; } }void image_clear(IMAGE * img, int width, int height, int edged_width, int y, int u, int v){ uint8_t * p; int i; p = img->y; for (i = 0; i < height; i++) { memset(p, y, width); p += edged_width; } p = img->u; for (i = 0; i < height/2; i++) { memset(p, u, width/2); p += edged_width/2; } p = img->v; for (i = 0; i < height/2; i++) { memset(p, v, width/2); p += edged_width/2; }}void image_swap(IMAGE * image1,IMAGE * image2){ SWAP(uint8_t*, image1->y, image2->y); SWAP(uint8_t*, image1->u, image2->u); SWAP(uint8_t*, image1->v, image2->v);}
void image_copy(IMAGE * image1,
IMAGE * image2,
uint32_t edged_width,
uint32_t height)
{
memcpy(image1->y, image2->y, edged_width * height);
memcpy(image1->u, image2->u, edged_width * height / 4);
memcpy(image1->v, image2->v, edged_width * height / 4);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -