?? image.c
字號:
#include <stdlib.h>#include <string.h> // memcpy, memset#include <math.h>#include "../portab.h"#include "../xvid.h" // XVID_CSP_XXX's#include "image.h"#include "colorspace.h"#include "../divx4.h"#include "../utils/mem_align.h"#define SAFETY 64#define EDGE_SIZE2 (EDGE_SIZE/2)int32_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 = xvid_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 = xvid_malloc(edged_width2 * edged_height2 + 4*SAFETY, CACHE_LINE); if (image->u == NULL) { xvid_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 = xvid_malloc(edged_width2 * edged_height2 + 4*SAFETY, CACHE_LINE); if (image->v == NULL) { xvid_free(image->u); xvid_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) { xvid_free(image->y - (EDGE_SIZE * edged_width + EDGE_SIZE)); } if (image->u) { xvid_free(image->u - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2)); } if (image->v) { xvid_free(image->v - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2)); }}/*size creat: ------------------------------------- | | | | | | ------------------------------------- | | | | | | | | | | | | | | | | | | | | | | | | ------------------------------------- | | | | | | -------------------------------------*/int32_timage_create_ben(IMAGE * image, uint32_t width, uint32_t height){ const uint32_t width2 = width / 2; const uint32_t height2 = height/ 2;#if 1 if ((image->y = (uint8_t *)xvid_dma_malloc(width * (2 * EDGE_SIZE + height) + 2 * EDGE_SIZE * EDGE_SIZE, CACHE_LINE, (void *)&image->y_phy)) == NULL) return -1; if ((image->u = (uint8_t *)xvid_dma_malloc(width2 * (2 * EDGE_SIZE2 + height2) + 2 * EDGE_SIZE2 * EDGE_SIZE2, CACHE_LINE, (void *)&image->u_phy)) == NULL) { xvid_dma_free (image->y, image->y_phy); return -1; } if ((image->v = (uint8_t *)xvid_dma_malloc(width2 * (2 * EDGE_SIZE2 + height2) + 2 * EDGE_SIZE2 * EDGE_SIZE2, CACHE_LINE, (void *)&image->v_phy)) == NULL) { xvid_dma_free (image->y, image->y_phy); xvid_dma_free (image->u, image->u_phy); return -1; }#else image->y = xvid_malloc(width * (2 * EDGE_SIZE + height) + 2 * EDGE_SIZE * EDGE_SIZE, CACHE_LINE); if (image->y == NULL) return -1; image->u = xvid_malloc(width2 * (2 * EDGE_SIZE2 + height2) + 2 * EDGE_SIZE2 * EDGE_SIZE2, CACHE_LINE); if (image->u == NULL) { xvid_free(image->y); return -1; } image->v = xvid_malloc(width2 * (2 * EDGE_SIZE2 + height2) + 2 * EDGE_SIZE2 * EDGE_SIZE2, CACHE_LINE); if (image->v == NULL) { xvid_free(image->u); xvid_free(image->y); return -1; }#ifdef fpga for (i = 0; i < width * height + SAFETY; i++) { image->y[i] = 0; } for (i = 0; i < width2 * height2 + 4*SAFETY; i++) { image->u[i] = 0; } for (i = 0; i < width2 * height2 + 4*SAFETY; i++) { image->v[i] = 0; }#endif#endif image->y = (uint8_t *)((uint32_t)image->y + EDGE_SIZE * width + EDGE_SIZE * EDGE_SIZE); image->u = (uint8_t *)((uint32_t)image->u + EDGE_SIZE2 * width2 + EDGE_SIZE2 * EDGE_SIZE2); image->v = (uint8_t *)((uint32_t)image->v + EDGE_SIZE2 * width2 + EDGE_SIZE2 * EDGE_SIZE2); image->y_phy = (uint8_t *)((uint32_t)image->y_phy + EDGE_SIZE * width + EDGE_SIZE * EDGE_SIZE); image->u_phy = (uint8_t *)((uint32_t)image->u_phy + EDGE_SIZE2 * width2 + EDGE_SIZE2 * EDGE_SIZE2); image->v_phy = (uint8_t *)((uint32_t)image->v_phy + EDGE_SIZE2 * width2 + EDGE_SIZE2 * EDGE_SIZE2); return 0;}voidimage_destroy_ben(IMAGE * image, uint32_t width){ const uint32_t width2 = width / 2;#if 1 if (image->y) xvid_dma_free(image->y - (EDGE_SIZE * width + EDGE_SIZE * EDGE_SIZE), image->y_phy - (EDGE_SIZE * width + EDGE_SIZE * EDGE_SIZE)); if (image->u) xvid_dma_free(image->u - (EDGE_SIZE2 * width2 + EDGE_SIZE2 * EDGE_SIZE2), image->u_phy - (EDGE_SIZE2 * width2 + EDGE_SIZE2 * EDGE_SIZE2)); if (image->v) xvid_dma_free(image->v - (EDGE_SIZE2 * width2 + EDGE_SIZE2 * EDGE_SIZE2), image->v_phy - (EDGE_SIZE2 * width2 + EDGE_SIZE2 * EDGE_SIZE2));#else if (image->y) { xvid_free(image->y - (EDGE_SIZE * width + EDGE_SIZE * EDGE_SIZE)); } if (image->u) { xvid_free(image->u - (EDGE_SIZE2 * width2 + EDGE_SIZE2 * EDGE_SIZE2)); } if (image->v) { xvid_free(image->v - (EDGE_SIZE2 * width2 + EDGE_SIZE2 * EDGE_SIZE2)); }#endif}voidimage_swap(IMAGE * image1, IMAGE * image2){ uint8_t *tmp; tmp = image1->y; image1->y = image2->y; image2->y = tmp; tmp = image1->u; image1->u = image2->u; image2->u = tmp; tmp = image1->v; image1->v = image2->v; image2->v = 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);}void seq2d(int xdim, int ydim, unsigned char *y_src, unsigned char *u_src, unsigned char *v_src, unsigned char *t_out1){ int x,y,m,n; unsigned char t_data; unsigned char *t_out; int format = 0; unsigned int output_ybase; unsigned int output_ubase; unsigned int output_vbase; int uv_width; int uv_height; switch(format) { case 0: /// 4:2:0 (ㄤ龜琌 4:1:1) output_ybase = 0; output_ubase = xdim*ydim; output_vbase = xdim*ydim*5/4; uv_width = 8; uv_height = 8; break; case 1: /// 4:2:2 output_ybase = 0; output_ubase = xdim*ydim; output_vbase = xdim*ydim*3/2; uv_width = 8; uv_height = 16; break; case 2: /// 4:2:0 output_ybase = 0; output_ubase = xdim*ydim; output_vbase = xdim*ydim*5/4; uv_width = 8; uv_height = 8; break; } t_out = (t_out1 + output_ybase); // -------------------------------------------------------------------- // 鑼 Y // -------------------------------------------------------------------- for(y=0;y<ydim/8;y++) { for(x=0;x<xdim/8;x++) { for(m=0;m<8;m++) { for(n=0;n<8;n++) { t_data = *y_src++; t_out[y*xdim*0x8+x*0x8+m*xdim+n] = t_data; } } } } // -------------------------------------------------------------------- // 鑼 U // -------------------------------------------------------------------- t_out = (t_out1 + output_ubase); for(y=0;y<ydim/16;y++) { for(x=0;x<xdim/16;x++) { for(m=0; m<uv_height; m++) { for(n=0; n<uv_width; n++) { t_data = *u_src++; t_out[ (y*uv_height + m) * ((xdim/16)*uv_width) + x*uv_width + n ] = t_data; } } } } // -------------------------------------------------------------------- // 鑼 V // -------------------------------------------------------------------- t_out = (t_out1 + output_vbase); for(y=0;y<ydim/16;y++) { for(x=0;x<xdim/16;x++) { for(m=0; m<uv_height; m++) { for(n=0; n<uv_width; n++) { t_data = *v_src++; t_out[ (y*uv_height + m) * ((xdim/16)*uv_width) + x*uv_width + n ] = t_data; } } } }}char tmp_buffer[352*288*2];intimage_output(IMAGE * image, uint32_t width, int height, uint32_t edged_width, uint8_t * dst, uint32_t dst_stride, int csp){ extern int log_file; switch (csp & ~XVID_CSP_VFLIP) { case XVID_CSP_RGB555: seq2d(width, height, image->y, image->u, image->v, tmp_buffer);#ifdef CHECK_YUV_OUT write(log_file, tmp_buffer, width*height*3/2); /// xvid_write(tmp_buffer, width*height*3/2);#endif ///yv12_to_rgb555(dst, dst_stride, image->y, image->u, image->v, edged_width, edged_width / 2, width, height); ///yv12_to_rgb555(dst, dst_stride, tmp_buffer, &tmp_buffer[width*height], &tmp_buffer[width*height*5/4], edged_width, edged_width / 2, width, height); yv12_to_rgb555(dst, dst_stride, tmp_buffer, &tmp_buffer[width*height], &tmp_buffer[width*height*5/4], width, 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; } return 0;}#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -