From 1602705ea4d3f44c374056e440ba21c45b2c1058 Mon Sep 17 00:00:00 2001 From: Zhao Halley Date: Wed, 5 Sep 2012 17:23:22 +0800 Subject: [PATCH] test: add color conversion test option in putsurface - command line: ./putsurface --fmt1 format1 --fmt2 format2 or ./putsurface -1 format1 -2 format2 - example: ./putsurface -1 NV12 -2 YV12 - implementation: - vaSurface is created with fmt1 - get image (with fmt2) from vaSurface, it leads to color conversion - put the above image to a temp surface color conversion may happen - render the above temp surface instead of original one --- test/putsurface/putsurface_common.c | 233 +++++++++++++++++++++++++++++++++--- 1 file changed, 217 insertions(+), 16 deletions(-) mode change 100644 => 100755 test/putsurface/putsurface_common.c diff --git a/test/putsurface/putsurface_common.c b/test/putsurface/putsurface_common.c old mode 100644 new mode 100755 index 54ae8d3..e461683 --- a/test/putsurface/putsurface_common.c +++ b/test/putsurface/putsurface_common.c @@ -59,6 +59,7 @@ if (va_status != VA_STATUS_SUCCESS) { \ static void *win_display; static VADisplay va_dpy; +static VAConfigID config_id; static VASurfaceID surface_id[SURFACE_NUM]; static pthread_mutex_t surface_mutex[SURFACE_NUM]; @@ -76,6 +77,130 @@ static pthread_mutex_t gmutex; static int box_width = 32; static int multi_thread = 0; static int verbose = 0; +static int test_color_conversion = 0; +static int csc_src_fourcc = 0, csc_dst_fourcc = 0; +static VAImage csc_dst_fourcc_image; +static VASurfaceID csc_render_surface; + + +typedef struct { + char* fmt_str; + unsigned int fourcc; +} fourcc_map; +fourcc_map va_fourcc_map[] = { + {"YUYV", VA_FOURCC_YUY2}, + {"YUY2", VA_FOURCC_YUY2}, + {"NV12", VA_FOURCC_NV12}, + {"YV12", VA_FOURCC_YV12}, + {"BGRA", VA_FOURCC_BGRA}, + {"RGBA", VA_FOURCC_RGBA}, + {"BGRX", VA_FOURCC_BGRX}, + {"RGBX", VA_FOURCC_RGBX}, +}; +unsigned int map_str_to_vafourcc (char * str) +{ + int i; + for (i=0; i< sizeof(va_fourcc_map)/sizeof(fourcc_map); i++) { + if (!strcmp(va_fourcc_map[i].fmt_str, str)) { + return va_fourcc_map[i].fourcc; + } + } + + return 0; + +} +char* map_vafourcc_to_str (unsigned int format) +{ + static char unknown_format[] = "unknown-format"; + int i; + for (i=0; i< sizeof(va_fourcc_map)/sizeof(fourcc_map); i++) { + if (va_fourcc_map[i].fourcc == format) { + return va_fourcc_map[i].fmt_str; + } + } + + return unknown_format; + +} + +int csc_preparation () +{ + VAStatus va_status; + int i; + + // 1. make sure dst fourcc is supported for vaImage + #define MAX_IMAGE_FORMAT_COUNT 10 + VAImageFormat format_list[MAX_IMAGE_FORMAT_COUNT]; + int num_formats = 0, find_dst_fourcc = 0; + + va_status = vaQueryImageFormats(va_dpy, format_list,&num_formats); + printf("num_formats: %d\n", num_formats); + assert(num_formats\n"); @@ -269,6 +429,10 @@ int main(int argc,char **argv) printf(" -t multi-threads\n"); printf(" -c test clipbox\n"); printf(" -f <1/2> top field, or bottom field\n"); + printf(" -1 source format (fourcc) for color conversion test\n"); + printf(" -2 dest format (fourcc) for color conversion test\n"); + printf(" --fmt1 same to -1\n"); + printf(" --fmt2 same to -2\n"); printf(" -v verbose output\n"); exit(0); break; @@ -319,6 +483,24 @@ int main(int argc,char **argv) } else printf("The validate input for -f is: 1(top field)/2(bottom field)\n"); break; + case '1': + sscanf(optarg, "%s", str_src_fmt); + csc_src_fourcc = map_str_to_vafourcc (str_src_fmt); + + if (!csc_src_fourcc) { + printf("invalid fmt1: %s\n", str_src_fmt ); + exit(0); + } + break; + case '2': + sscanf(optarg, "%s", str_dst_fmt); + csc_dst_fourcc = map_str_to_vafourcc (str_dst_fmt); + + if (!csc_dst_fourcc) { + printf("invalid fmt1: %s\n", str_dst_fmt ); + exit(0); + } + break; case 'v': verbose = 1; printf("Enable verbose output\n"); @@ -326,6 +508,10 @@ int main(int argc,char **argv) } } + if (csc_src_fourcc && csc_dst_fourcc) { + test_color_conversion = 1; + } + win_display = (void *)open_display(); if (win_display == NULL) { fprintf(stderr, "Can't open the connection of display!\n"); @@ -337,12 +523,17 @@ int main(int argc,char **argv) va_status = vaInitialize(va_dpy, &major_ver, &minor_ver); CHECK_VASTATUS(va_status, "vaInitialize"); - va_status = vaCreateSurfaces( - va_dpy, - VA_RT_FORMAT_YUV420, surface_width, surface_height, - &surface_id[0], SURFACE_NUM, - NULL, 0 - ); + if (test_color_conversion) { + ret = csc_preparation(); + } + if (!test_color_conversion || !ret ) { + va_status = vaCreateSurfaces( + va_dpy, + VA_RT_FORMAT_YUV420, surface_width, surface_height, + &surface_id[0], SURFACE_NUM, + NULL, 0 + ); + } CHECK_VASTATUS(va_status, "vaCreateSurfaces"); if (multi_thread == 0) /* upload the content for all surfaces */ upload_source_YUV_once_for_all(); @@ -361,6 +552,16 @@ int main(int argc,char **argv) if (multi_thread == 1) pthread_join(thread1, (void **)&ret); printf("thread1 is free\n"); + + if (test_color_conversion) { + // destroy temp surface/image + va_status = vaDestroySurfaces(va_dpy, &csc_render_surface, 1); + CHECK_VASTATUS(va_status,"vaDestroySurfaces"); + + va_status = vaDestroyImage(va_dpy, csc_dst_fourcc_image.image_id); + CHECK_VASTATUS(va_status,"vaDestroyImage"); + vaDestroyConfig (va_dpy, config_id); + } vaDestroySurfaces(va_dpy,&surface_id[0],SURFACE_NUM); vaTerminate(va_dpy); -- 2.7.4