?? image.c
字號:
#include <stdlib.h>#include <string.h> // memcpy, memset#include <math.h>#include "../portab.h"#include "image.h"//#include "../divx4.h"//#include "utils/mem_align.h"#include "../define.h"#define SAFETY 64#define EDGE_SIZE2 (EDGE_SIZE/2)#if 0int32_timage_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 = mp4_malloc(edged_width * (edged_height + 1) + SAFETY, CACHE_LINE); if (image->y == NULL) { return -1; }#ifdef fpga// for (i = 0; i < edged_width * edged_height + SAFETY; i++) {// image->y[i] = 0;// }#endif image->u = mp4_malloc(edged_width2 * edged_height2 + 4*SAFETY, CACHE_LINE); if (image->u == NULL) { mp4_free(image->y); return -1; }#ifdef fpga // for (i = 0; i < edged_width2 * edged_height2 + 4*SAFETY; i++) {// image->u[i] = 0;// }#endif image->v = mp4_malloc(edged_width2 * edged_height2 + 4*SAFETY, CACHE_LINE); if (image->v == NULL) { mp4_free(image->u); mp4_free(image->y); return -1; }#ifdef fpga// for (i = 0; i < edged_width2 * edged_height2 + 4*SAFETY; i++) {// image->v[i] = 0;// }#endif 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;}voidimage_destroy(IMAGE * image, uint32_t edged_width, uint32_t edged_height){ const uint32_t edged_width2 = edged_width / 2; if (image->y) { mp4_free(image->y - (EDGE_SIZE * edged_width + EDGE_SIZE)); } if (image->u) { mp4_free(image->u - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2)); } if (image->v) { mp4_free(image->v - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2)); }}#endif/*size creat: EDGE_SIZE mb_width * PIXEL_Y | / \ / \/ \ ------------------------------------- | | |\ | | | EDGE_SIZE | | |/ ------------------------------------- | |\ | | \ | | | | | | | | | | mb_height * PIXEL_Y | | | | | | | | / | |/ ------------------------------------- | | |\ | | | EDGE_SIZE | | |/ ------------------------------------- \ / EDGE_SIZE*/int32_timage_create(IMAGE * image, uint32_t mbwidth, uint32_t mbheight, DECODER * ptdec){ DMA_MALLOC_PTR pfnDmaMalloc = ptdec->pfnDmaMalloc; DMA_FREE_PTR pfnDmaFree = ptdec->pfnDmaFree; uint8_t u8align = ptdec->u32CacheAlign; image->y_virt = (uint8_t *)pfnDmaMalloc( mbwidth * (2 + mbheight) * PIXEL_Y * PIXEL_Y+ 2 * EDGE_SIZE * EDGE_SIZE, u8align, u8align, (void **)&image->y_phy); if (image->y_virt == NULL) { return -1; } image->u_virt = (uint8_t *)pfnDmaMalloc( mbwidth * (2 + mbheight) * PIXEL_U * PIXEL_U + 2 * EDGE_SIZE2 * EDGE_SIZE2, u8align, u8align, (void **)&image->u_phy); if (image->u_virt == NULL) { pfnDmaFree(image->y_virt, image->y_phy); return -1; } image->v_virt = (uint8_t *)pfnDmaMalloc( mbwidth * (2 + mbheight) * PIXEL_V * PIXEL_V + 2 * EDGE_SIZE2 * EDGE_SIZE2, u8align, u8align, (void **)&image->v_phy); if (image->v_virt == NULL) { pfnDmaFree(image->y_virt, image->y_phy); pfnDmaFree(image->u_virt, image->u_phy); return -1; } image->y_virt += mbwidth * PIXEL_Y * EDGE_SIZE + EDGE_SIZE * EDGE_SIZE; image->u_virt += mbwidth * PIXEL_U * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2; image->v_virt += mbwidth * PIXEL_V * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2; image->y_phy += mbwidth * PIXEL_Y * EDGE_SIZE + EDGE_SIZE * EDGE_SIZE; image->u_phy += mbwidth * PIXEL_U * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2; image->v_phy += mbwidth * PIXEL_V * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2; return 0;}voidimage_destroy(IMAGE * image, uint32_t mbwidth, DECODER * ptdec){ DMA_FREE_PTR pfnDmaFree = ptdec->pfnDmaFree; if (image->y_virt) { pfnDmaFree(image->y_virt - (mbwidth * PIXEL_Y * EDGE_SIZE + EDGE_SIZE * EDGE_SIZE), image->y_phy- (mbwidth * PIXEL_Y * EDGE_SIZE + EDGE_SIZE * EDGE_SIZE)); } if (image->u_virt) { pfnDmaFree(image->u_virt - (mbwidth * PIXEL_U * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2), image->u_phy - (mbwidth * PIXEL_U * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2)); } if (image->v_virt) { pfnDmaFree(image->v_virt - (mbwidth * PIXEL_V * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2), image->v_phy - (mbwidth * PIXEL_V * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2)); }}voidimage_swap_dec(IMAGE * image1, IMAGE * image2){ uint8_t *tmp; tmp = image1->y_virt; image1->y_virt = image2->y_virt; image2->y_virt = tmp; tmp = image1->u_virt; image1->u_virt = image2->u_virt; image2->u_virt = tmp; tmp = image1->v_virt; image1->v_virt = image2->v_virt; image2->v_virt = tmp; tmp = image1->y_phy; image1->y_phy = image2->y_phy; image2->y_phy = tmp; tmp = image1->u_phy; image1->u_phy = image2->u_phy; image2->u_phy = tmp; tmp = image1->v_phy; image1->v_phy = image2->v_phy; image2->v_phy = tmp;}#if 0voidimage_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);}#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -