void get_chroma_buffer(void *output, struct yuv *yuv) { #if 0 int width = 0; int height = 0; int pitch = 0; struct yuv_neon_arg yuv_neon; if (yuv->format == YUV_FORMAT_YUV420) { width = yuv->width / 2; height = yuv->height / 2; pitch = yuv->pitch / 2; yuv_neon.in = yuv->uv_addr_offset; yuv_neon.row = height; yuv_neon.col = yuv->width; yuv_neon.pitch = yuv->pitch; if (yuv->sub_format == YUV420_YV12) { // YV12 format (YYYYYYYYVVUU) yuv_neon.u = output + width * height; yuv_neon.v = output; chrome_convert(&yuv_neon); } else if (yuv->sub_format == YUV420_IYUV) { // IYUV (I420) format (YYYYYYYYUUVV) yuv_neon.u = output; yuv_neon.v = output + width * height; chrome_convert(&yuv_neon); } else { if (yuv->sub_format != YUV420_NV12) { INFO("Change output format back to NV12 for encode!\n"); yuv->sub_format = YUV420_NV12; } // NV12 format (YYYYYYYYUVUV) input = yuv->uv_addr_offset; for (i = 0; i < height; ++i) { memcpy(output + i * width * 2, input + i * pitch * 2, width * 2); } } } else if (yuv->format == YUV422) { width = yuv->width / 2; height = yuv->height; pitch = yuv->pitch / 2; yuv_neon.in = yuv->uv_addr_offset; yuv_neon.row = height; yuv_neon.col = yuv->width; yuv_neon.pitch = yuv->pitch; if (yuv->sub_format == YUV422_YU16) { yuv_neon.u = output; yuv_neon.v = output + width * height; } else { if (yuv->sub_format != YUV422_YV16) { printf("Change output format back to YV16 for preview!\n"); yuv->sub_format = YUV422_YV16; } yuv_neon.u = output + width * height; yuv_neon.v = output; } chrome_convert(&yuv_neon); } else { printf("Error: Unsupported YUV input format!\n"); } #endif }
static int init_image_mem(char *file_input, int width, int height) { int fd_input = -1; int size_input = 0; int u_offset = 0; int size_u = 0,size_v = 0; int read_input = 0; u8 *image_chrome = NULL; struct timeval time1, time2; yuv_neon_arg yuv_arg; if ((filename_yuv[0] == '\0') || (width <= 0) ||(height <= 0) ) { printf("Please set right yuv file, width, height\n"); return -1; } size_input = width * height * 3/2; u_offset = width * height; size_u = width * height / 4; size_v = size_u; if ((fd_input = open(file_input, O_RDONLY )) < 0) { printf("Failed to open file [%s].\n", file_input); return -1; } do { image_data.buffer = (u8*) malloc(size_input); if (!image_data.buffer) { printf("Not enough memory for image buffer.\n"); break; } memset(image_data.buffer, 0, size_input); read_input = read(fd_input, image_data.buffer, size_input); if (read_input != size_input) { printf("Read %s error\n", file_input); read_input = -1; } if (image_data.format == NV12) { image_chrome = (u8*)malloc(size_u + size_v); if (image_chrome == NULL) { printf("Not enough memory for image_u or image_v.\n"); return -1;; } if (verbose) { gettimeofday(&time1, NULL); } yuv_arg.in = image_data.buffer + u_offset; yuv_arg.u = image_chrome; yuv_arg.v = image_chrome + size_u; yuv_arg.row = height / 2; yuv_arg.col = width; yuv_arg.pitch = width; chrome_convert(&yuv_arg); memcpy(image_data.buffer + u_offset, yuv_arg.u, size_u + size_v); if (verbose) { gettimeofday(&time2, NULL); printf("NV12 to IYUV takes time %ld ms\n",(time2.tv_usec - time1.tv_usec)/1000L +(time2.tv_sec - time1.tv_sec) * 1000L); } } } while(0); if (image_chrome != NULL) { free(image_chrome); image_chrome = NULL; } close(fd_input); fd_input = -1; return read_input; }