1 /*
2 * test_cl_image.cpp - test cl image
3 *
4 * Copyright (c) 2014-2015 Intel Corporation
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Wind Yuan <feng.yuan@intel.com>
19 * Author: Yinhang Liu <yinhangx.liu@intel.com>
20 * Author: Wei Zong <wei.zong@intel.com>
21 */
22
23 #include "test_common.h"
24 #include "test_inline.h"
25 #include "image_file_handle.h"
26 #include "ocl/cl_device.h"
27 #include "ocl/cl_context.h"
28 #include "ocl/cl_demo_handler.h"
29 #include "ocl/cl_csc_handler.h"
30 #include "ocl/cl_bayer_pipe_handler.h"
31 #include "ocl/cl_yuv_pipe_handler.h"
32 #include "ocl/cl_tonemapping_handler.h"
33 #include "ocl/cl_retinex_handler.h"
34 #include "ocl/cl_gauss_handler.h"
35 #include "ocl/cl_wavelet_denoise_handler.h"
36 #include "ocl/cl_newwavelet_denoise_handler.h"
37 #include "ocl/cl_defog_dcp_handler.h"
38 #include "ocl/cl_3d_denoise_handler.h"
39 #include "ocl/cl_image_warp_handler.h"
40 #include "ocl/cl_fisheye_handler.h"
41 #include "ocl/cl_utils.h"
42
43 using namespace XCam;
44
45 enum TestHandlerType {
46 TestHandlerUnknown = 0,
47 TestHandlerDemo,
48 TestHandlerColorConversion,
49 TestHandlerBayerPipe,
50 TestHandlerYuvPipe,
51 TestHandlerTonemapping,
52 TestHandlerRetinex,
53 TestHandlerGauss,
54 TestHandlerHatWavelet,
55 TestHandlerHaarWavelet,
56 TestHandlerDefogDcp,
57 TestHandler3DDenoise,
58 TestHandlerImageWarp,
59 TestHandlerFisheye,
60 };
61
62 enum PsnrType {
63 PSNRY = 0,
64 PSNRR,
65 PSNRG,
66 PSNRB,
67 };
68
69 static XCamReturn
calculate_psnr(SmartPtr<VideoBuffer> & psnr_cur,SmartPtr<VideoBuffer> & psnr_ref,PsnrType psnr_type,float & psnr)70 calculate_psnr (SmartPtr<VideoBuffer> &psnr_cur, SmartPtr<VideoBuffer> &psnr_ref, PsnrType psnr_type, float &psnr)
71 {
72 const VideoBufferInfo info = psnr_cur->get_video_info ();
73 VideoBufferPlanarInfo planar;
74 uint8_t *cur_mem = NULL, *ref_mem = NULL;
75 XCamReturn ret = XCAM_RETURN_NO_ERROR;
76
77 int8_t interval = 1, index = 0;
78 if (PSNRY == psnr_type) {
79 interval = 1;
80 index = 0;
81 } else if (PSNRR == psnr_type) {
82 interval = 4;
83 index = 0;
84 } else if (PSNRG == psnr_type) {
85 interval = 4;
86 index = 1;
87 } else if (PSNRB == psnr_type) {
88 interval = 4;
89 index = 2;
90 }
91
92 cur_mem = psnr_cur->map ();
93 ref_mem = psnr_ref->map ();
94 if (!cur_mem || !ref_mem) {
95 XCAM_LOG_ERROR ("calculate_psnr map buffer failed");
96 return XCAM_RETURN_ERROR_MEM;
97 }
98
99 uint32_t sum = 0, pos = 0;
100 info.get_planar_info (planar, 0);
101 for (uint32_t i = 0; i < planar.height; i++) {
102 for (uint32_t j = 0; j < planar.width / interval; j++) {
103 pos = i * planar.width + j * interval + index;
104 sum += (cur_mem [pos] - ref_mem [pos]) * (cur_mem [pos] - ref_mem [pos]);
105 }
106 }
107 float mse = (float) sum / (planar.height * planar.width / interval) + 0.000001f;
108 psnr = 10 * log10 (255 * 255 / mse);
109
110 psnr_cur->unmap ();
111 psnr_ref->unmap ();
112
113 return ret;
114 }
115
116 static XCamReturn
kernel_loop(SmartPtr<CLImageHandler> & image_handler,SmartPtr<VideoBuffer> & input_buf,SmartPtr<VideoBuffer> & output_buf,uint32_t kernel_loop_count)117 kernel_loop(SmartPtr<CLImageHandler> &image_handler, SmartPtr<VideoBuffer> &input_buf, SmartPtr<VideoBuffer> &output_buf, uint32_t kernel_loop_count)
118 {
119 XCamReturn ret = XCAM_RETURN_NO_ERROR;
120 for (uint32_t i = 0; i < kernel_loop_count; i++) {
121 PROFILING_START(cl_kernel);
122 ret = image_handler->execute (input_buf, output_buf);
123 PROFILING_END(cl_kernel, kernel_loop_count)
124 }
125 return ret;
126 }
127
128 static void
print_help(const char * bin_name)129 print_help (const char *bin_name)
130 {
131 printf ("Usage: %s [-f format] -i input -o output\n"
132 "\t -t type specify image handler type\n"
133 "\t select from [demo, blacklevel, defect, demosaic, tonemapping, csc, hdr, wb, denoise,"
134 " gamma, snr, bnr, macc, ee, bayerpipe, yuvpipe, retinex, gauss, wavelet-hat, wavelet-haar, dcp, fisheye]\n"
135 "\t -f input_format specify a input format\n"
136 "\t -W image_width specify input image width\n"
137 "\t -H image_height specify input image height\n"
138 "\t -g output_format specify a output format\n"
139 "\t select from [NV12, BA10, RGBA, RGBA64]\n"
140 "\t -i input specify input file path\n"
141 "\t -o output specify output file path\n"
142 "\t -r refer specify reference file path\n"
143 "\t -k binary_kernel specify binary kernel path\n"
144 "\t -p count specify cl kernel loop count\n"
145 "\t -c csc_type specify csc type, default:rgba2nv12\n"
146 "\t select from [rgbatonv12, rgbatolab, rgba64torgba, yuyvtorgba, nv12torgba]\n"
147 "\t -b enable bayer-nr, default: disable\n"
148 "\t -P enable psnr calculation, default: disable\n"
149 "\t -h help\n"
150 , bin_name);
151
152 printf ("Note:\n"
153 "Usage of binary kernel:\n"
154 "1. generate binary kernel:\n"
155 " $ test-binary-kernel --src-kernel kernel_demo.cl --bin-kernel kernel_demo.cl.bin"
156 " --kernel-name kernel_demo\n"
157 "2. execute binary kernel:\n"
158 " $ test-cl-image -t demo -f BA10 -i input.raw -o output.raw -k kernel_demo.cl.bin\n");
159 }
160
main(int argc,char * argv[])161 int main (int argc, char *argv[])
162 {
163 uint32_t input_format = 0;
164 uint32_t output_format = V4L2_PIX_FMT_RGBA32;
165 uint32_t width = 1920;
166 uint32_t height = 1080;
167 uint32_t buf_count = 0;
168 int32_t kernel_loop_count = 0;
169 const char *input_file = NULL, *output_file = NULL, *refer_file = NULL;
170 const char *bin_kernel_path = NULL;
171 ImageFileHandle input_fp, output_fp, refer_fp;
172 const char *bin_name = argv[0];
173 TestHandlerType handler_type = TestHandlerUnknown;
174 XCamReturn ret = XCAM_RETURN_NO_ERROR;
175 SmartPtr<CLImageHandler> image_handler;
176 VideoBufferInfo input_buf_info;
177 SmartPtr<CLContext> context;
178 SmartPtr<BufferPool> buf_pool;
179 int opt = 0;
180 CLCscType csc_type = CL_CSC_TYPE_RGBATONV12;
181 bool enable_bnr = false;
182 bool enable_psnr = false;
183
184 while ((opt = getopt(argc, argv, "f:W:H:i:o:r:t:k:p:c:g:bPh")) != -1) {
185 switch (opt) {
186 case 'i':
187 input_file = optarg;
188 break;
189 case 'o':
190 output_file = optarg;
191 break;
192 case 'r':
193 refer_file = optarg;
194 break;
195
196 case 'f': {
197 if (!strcasecmp (optarg, "nv12"))
198 input_format = V4L2_PIX_FMT_NV12;
199 else if (!strcasecmp (optarg, "ba10"))
200 input_format = V4L2_PIX_FMT_SGRBG10;
201 else if (! strcasecmp (optarg, "rgba"))
202 input_format = V4L2_PIX_FMT_RGBA32;
203 else if (! strcasecmp (optarg, "rgba64"))
204 input_format = XCAM_PIX_FMT_RGBA64;
205 else if (!strcasecmp (optarg, "ba12"))
206 input_format = V4L2_PIX_FMT_SGRBG12;
207 else
208 print_help (bin_name);
209 break;
210 }
211 case 'W': {
212 width = atoi (optarg);
213 break;
214 }
215 case 'H': {
216 height = atoi (optarg);
217 break;
218 }
219 case 'g': {
220 if (!strcasecmp (optarg, "nv12"))
221 output_format = V4L2_PIX_FMT_NV12;
222 else if (!strcasecmp (optarg, "ba10"))
223 output_format = V4L2_PIX_FMT_SGRBG10;
224 else if (! strcasecmp (optarg, "rgba"))
225 output_format = V4L2_PIX_FMT_RGBA32;
226 else if (! strcasecmp (optarg, "rgba64"))
227 output_format = XCAM_PIX_FMT_RGBA64;
228
229 else
230 print_help (bin_name);
231 break;
232 }
233 case 't': {
234 if (!strcasecmp (optarg, "demo"))
235 handler_type = TestHandlerDemo;
236 else if (!strcasecmp (optarg, "csc"))
237 handler_type = TestHandlerColorConversion;
238 else if (!strcasecmp (optarg, "bayerpipe"))
239 handler_type = TestHandlerBayerPipe;
240 else if (!strcasecmp (optarg, "yuvpipe"))
241 handler_type = TestHandlerYuvPipe;
242 else if (!strcasecmp (optarg, "tonemapping"))
243 handler_type = TestHandlerTonemapping;
244 else if (!strcasecmp (optarg, "retinex"))
245 handler_type = TestHandlerRetinex;
246 else if (!strcasecmp (optarg, "gauss"))
247 handler_type = TestHandlerGauss;
248 else if (!strcasecmp (optarg, "wavelet-hat"))
249 handler_type = TestHandlerHatWavelet;
250 else if (!strcasecmp (optarg, "wavelet-haar"))
251 handler_type = TestHandlerHaarWavelet;
252 else if (!strcasecmp (optarg, "dcp"))
253 handler_type = TestHandlerDefogDcp;
254 else if (!strcasecmp (optarg, "3d-denoise"))
255 handler_type = TestHandler3DDenoise;
256 else if (!strcasecmp (optarg, "warp"))
257 handler_type = TestHandlerImageWarp;
258 else if (!strcasecmp (optarg, "fisheye"))
259 handler_type = TestHandlerFisheye;
260 else
261 print_help (bin_name);
262 break;
263 }
264 case 'k':
265 bin_kernel_path = optarg;
266 break;
267 case 'p':
268 kernel_loop_count = atoi (optarg);
269 XCAM_ASSERT (kernel_loop_count >= 0 && kernel_loop_count < INT32_MAX);
270 break;
271 case 'c':
272 if (!strcasecmp (optarg, "rgbatonv12"))
273 csc_type = CL_CSC_TYPE_RGBATONV12;
274 else if (!strcasecmp (optarg, "rgbatolab"))
275 csc_type = CL_CSC_TYPE_RGBATOLAB;
276 else if (!strcasecmp (optarg, "rgba64torgba"))
277 csc_type = CL_CSC_TYPE_RGBA64TORGBA;
278 else if (!strcasecmp (optarg, "yuyvtorgba"))
279 csc_type = CL_CSC_TYPE_YUYVTORGBA;
280 else if (!strcasecmp (optarg, "nv12torgba"))
281 csc_type = CL_CSC_TYPE_NV12TORGBA;
282 else
283 print_help (bin_name);
284 break;
285
286 case 'b':
287 enable_bnr = true;
288 break;
289
290 case 'P':
291 enable_psnr = true;
292 break;
293
294 case 'h':
295 print_help (bin_name);
296 return 0;
297
298 default:
299 print_help (bin_name);
300 return -1;
301 }
302 }
303
304 if (!input_format || !input_file || !output_file || (enable_psnr && !refer_file) || handler_type == TestHandlerUnknown) {
305 print_help (bin_name);
306 return -1;
307 }
308
309 ret = input_fp.open (input_file, "rb");
310 CHECK (ret, "open input file(%s) failed", XCAM_STR (input_file));
311 ret = output_fp.open (output_file, "wb");
312 CHECK (ret, "open output file(%s) failed", XCAM_STR (output_file));
313 if (enable_psnr) {
314 refer_fp.open (refer_file, "rb");
315 CHECK (ret, "open reference file(%s) failed", XCAM_STR (refer_file));
316 }
317
318 context = CLDevice::instance ()->get_context ();
319
320 switch (handler_type) {
321 case TestHandlerDemo:
322 if (!bin_kernel_path)
323 image_handler = create_cl_demo_image_handler (context);
324 else {
325 FileHandle file;
326 if (file.open (bin_kernel_path, "r") != XCAM_RETURN_NO_ERROR) {
327 XCAM_LOG_ERROR ("open binary kernel failed");
328 return -1;
329 }
330
331 size_t size;
332 if (file.get_file_size (size) != XCAM_RETURN_NO_ERROR) {
333 XCAM_LOG_ERROR ("get binary kernel size failed");
334 return -1;
335 }
336
337 uint8_t *binary = (uint8_t *) xcam_malloc0 (sizeof (uint8_t) * (size));
338 XCAM_ASSERT (binary);
339
340 if (file.read_file (binary, size) != XCAM_RETURN_NO_ERROR) {
341 XCAM_LOG_ERROR ("read binary kernel failed");
342 xcam_free (binary);
343 return -1;
344 }
345
346 image_handler = create_cl_binary_demo_image_handler (context, binary, size);
347 xcam_free (binary);
348 }
349 break;
350 case TestHandlerColorConversion: {
351 SmartPtr<CLCscImageHandler> csc_handler;
352 XCam3aResultColorMatrix color_matrix;
353 xcam_mem_clear (color_matrix);
354 double matrix_table[XCAM_COLOR_MATRIX_SIZE] = {0.299, 0.587, 0.114, -0.14713, -0.28886, 0.436, 0.615, -0.51499, -0.10001};
355 memcpy (color_matrix.matrix, matrix_table, sizeof(double)*XCAM_COLOR_MATRIX_SIZE);
356 image_handler = create_cl_csc_image_handler (context, csc_type);
357 csc_handler = image_handler.dynamic_cast_ptr<CLCscImageHandler> ();
358 XCAM_ASSERT (csc_handler.ptr ());
359 csc_handler->set_matrix(color_matrix);
360 break;
361 }
362 case TestHandlerBayerPipe: {
363 image_handler = create_cl_bayer_pipe_image_handler (context);
364 SmartPtr<CLBayerPipeImageHandler> bayer_pipe = image_handler.dynamic_cast_ptr<CLBayerPipeImageHandler> ();
365 XCAM_ASSERT (bayer_pipe.ptr ());
366 bayer_pipe->set_output_format (output_format);
367 bayer_pipe->enable_denoise (enable_bnr);
368 break;
369 }
370 case TestHandlerYuvPipe: {
371 image_handler = create_cl_yuv_pipe_image_handler (context);
372 SmartPtr<CLYuvPipeImageHandler> yuv_pipe = image_handler.dynamic_cast_ptr<CLYuvPipeImageHandler> ();
373 XCAM_ASSERT (yuv_pipe.ptr ());
374 break;
375 }
376 case TestHandlerTonemapping: {
377 image_handler = create_cl_tonemapping_image_handler (context);
378 SmartPtr<CLTonemappingImageHandler> tonemapping_pipe = image_handler.dynamic_cast_ptr<CLTonemappingImageHandler> ();
379 XCAM_ASSERT (tonemapping_pipe.ptr ());
380 break;
381 }
382 case TestHandlerRetinex: {
383 image_handler = create_cl_retinex_image_handler (context);
384 SmartPtr<CLRetinexImageHandler> retinex = image_handler.dynamic_cast_ptr<CLRetinexImageHandler> ();
385 XCAM_ASSERT (retinex.ptr ());
386 break;
387 }
388 case TestHandlerGauss: {
389 image_handler = create_cl_gauss_image_handler (context);
390 SmartPtr<CLGaussImageHandler> gauss = image_handler.dynamic_cast_ptr<CLGaussImageHandler> ();
391 XCAM_ASSERT (gauss.ptr ());
392 break;
393 }
394 case TestHandlerHatWavelet: {
395 image_handler = create_cl_wavelet_denoise_image_handler (context, CL_IMAGE_CHANNEL_UV);
396 SmartPtr<CLWaveletDenoiseImageHandler> wavelet = image_handler.dynamic_cast_ptr<CLWaveletDenoiseImageHandler> ();
397 XCAM_ASSERT (wavelet.ptr ());
398 XCam3aResultWaveletNoiseReduction wavelet_config;
399 xcam_mem_clear (wavelet_config);
400 wavelet_config.threshold[0] = 0.2;
401 wavelet_config.threshold[1] = 0.5;
402 wavelet_config.decomposition_levels = 4;
403 wavelet_config.analog_gain = 0.001;
404 wavelet->set_denoise_config (wavelet_config);
405 break;
406 }
407 case TestHandlerHaarWavelet: {
408 image_handler = create_cl_newwavelet_denoise_image_handler (context, CL_IMAGE_CHANNEL_UV | CL_IMAGE_CHANNEL_Y, false);
409 SmartPtr<CLNewWaveletDenoiseImageHandler> wavelet = image_handler.dynamic_cast_ptr<CLNewWaveletDenoiseImageHandler> ();
410 XCAM_ASSERT (wavelet.ptr ());
411 XCam3aResultWaveletNoiseReduction wavelet_config;
412 wavelet_config.threshold[0] = 0.2;
413 wavelet_config.threshold[1] = 0.5;
414 wavelet_config.decomposition_levels = 4;
415 wavelet_config.analog_gain = 0.001;
416 wavelet->set_denoise_config (wavelet_config);
417 break;
418 }
419 case TestHandlerDefogDcp: {
420 image_handler = create_cl_defog_dcp_image_handler (context);
421 XCAM_ASSERT (image_handler.ptr ());
422 break;
423 }
424 case TestHandler3DDenoise: {
425 uint8_t ref_count = 2;
426 image_handler = create_cl_3d_denoise_image_handler (context, CL_IMAGE_CHANNEL_Y | CL_IMAGE_CHANNEL_UV, ref_count);
427 SmartPtr<CL3DDenoiseImageHandler> denoise = image_handler.dynamic_cast_ptr<CL3DDenoiseImageHandler> ();
428 XCAM_ASSERT (denoise.ptr ());
429 XCam3aResultTemporalNoiseReduction denoise_config;
430 xcam_mem_clear (denoise_config);
431 denoise_config.threshold[0] = 0.05;
432 denoise_config.threshold[1] = 0.05;
433 denoise_config.gain = 0.6;
434 denoise->set_denoise_config (denoise_config);
435 break;
436 }
437 case TestHandlerImageWarp: {
438 image_handler = create_cl_image_warp_handler (context);
439 SmartPtr<CLImageWarpHandler> warp = image_handler.dynamic_cast_ptr<CLImageWarpHandler> ();
440 XCAM_ASSERT (warp.ptr ());
441 XCamDVSResult warp_config;
442 xcam_mem_clear (warp_config);
443 warp_config.frame_id = 1;
444 warp_config.frame_width = width;
445 warp_config.frame_height = height;
446
447 float theta = -10.0f;
448 float phi = 10.0f;
449
450 float shift_x = -0.2f * width;
451 float shift_y = 0.2f * height;
452 float scale_x = 2.0f;
453 float scale_y = 0.5f;
454 float shear_x = tan(theta * 3.1415926 / 180.0f);
455 float shear_y = tan(phi * 3.1415926 / 180.0f);
456 float project_x = 2.0f / width;
457 float project_y = -1.0f / height;
458
459 warp_config.proj_mat[0] = scale_x;
460 warp_config.proj_mat[1] = shear_x;
461 warp_config.proj_mat[2] = shift_x;
462 warp_config.proj_mat[3] = shear_y;
463 warp_config.proj_mat[4] = scale_y;
464 warp_config.proj_mat[5] = shift_y;
465 warp_config.proj_mat[6] = project_x;
466 warp_config.proj_mat[7] = project_y;
467 warp_config.proj_mat[8] = 1.0f;
468
469 warp->set_warp_config (warp_config);
470 break;
471 }
472 case TestHandlerFisheye: {
473 image_handler = create_fisheye_handler (context);
474 SmartPtr<CLFisheyeHandler> fisheye = image_handler.dynamic_cast_ptr<CLFisheyeHandler> ();
475 XCAM_ASSERT (fisheye.ptr ());
476 FisheyeInfo fisheye_info;
477 //fisheye0 {480.0f, 480.0f, 190.0f, 480.0f, -90.0f},
478 //fisheye1 {1440.0f, 480.0f, 190.0f, 480.0f, 90.0f}
479 fisheye_info.center_x = 480.0f;
480 fisheye_info.center_y = 480.0f;
481 fisheye_info.wide_angle = 190.0f;
482 fisheye_info.radius = 480.0f;
483 fisheye_info.rotate_angle = -90.0f;
484 fisheye->set_fisheye_info (fisheye_info);
485 fisheye->set_dst_range (210.0f, 180.0f);
486 fisheye->set_output_size (1120, 960);
487 break;
488 }
489 default:
490 XCAM_LOG_ERROR ("unsupported image handler type:%d", handler_type);
491 return -1;
492 }
493 if (!image_handler.ptr ()) {
494 XCAM_LOG_ERROR ("create image_handler failed");
495 return -1;
496 }
497
498 input_buf_info.init (input_format, width, height);
499
500 buf_pool = new CLVideoBufferPool ();
501 image_handler->set_pool_type (CLImageHandler::CLVideoPoolType);
502 buf_pool->set_video_info (input_buf_info);
503 if (!buf_pool->reserve (6)) {
504 XCAM_LOG_ERROR ("init buffer pool failed");
505 return -1;
506 }
507
508 SmartPtr<VideoBuffer> input_buf, output_buf, psnr_cur, psnr_ref;
509 while (true) {
510 input_buf = buf_pool->get_buffer (buf_pool);
511 XCAM_ASSERT (input_buf.ptr ());
512
513 ret = input_fp.read_buf (input_buf);
514 if (ret == XCAM_RETURN_BYPASS)
515 break;
516 if (ret == XCAM_RETURN_ERROR_FILE) {
517 XCAM_LOG_ERROR ("read buffer from %s failed", XCAM_STR (input_file));
518 return -1;
519 }
520
521 if (kernel_loop_count != 0)
522 {
523 kernel_loop (image_handler, input_buf, output_buf, kernel_loop_count);
524 CHECK (ret, "execute kernels failed");
525 return 0;
526 }
527
528 ret = image_handler->execute (input_buf, output_buf);
529 CHECK_EXP ((ret == XCAM_RETURN_NO_ERROR || ret == XCAM_RETURN_BYPASS), "execute kernels failed");
530 if (ret == XCAM_RETURN_BYPASS)
531 continue;
532 context->finish ();
533 XCAM_ASSERT (output_buf.ptr ());
534 ret = output_fp.write_buf (output_buf);
535 CHECK (ret, "write buffer to %s failed", XCAM_STR (output_file));
536 psnr_cur = output_buf;
537
538 ++buf_count;
539 }
540
541 XCAM_LOG_INFO ("processed %d buffers successfully", buf_count);
542
543 if (enable_psnr) {
544 buf_pool = new CLVideoBufferPool ();
545 XCAM_ASSERT (buf_pool.ptr ());
546 buf_pool->set_video_info (input_buf_info);
547 if (!buf_pool->reserve (6)) {
548 XCAM_LOG_ERROR ("init buffer pool failed");
549 return -1;
550 }
551
552 psnr_ref = buf_pool->get_buffer (buf_pool);
553 XCAM_ASSERT (psnr_ref.ptr ());
554
555 ret = refer_fp.read_buf (psnr_ref);
556 CHECK (ret, "read buffer from %s failed", refer_file);
557
558 float psnr = 0.0f;
559 ret = calculate_psnr (psnr_cur, psnr_ref, PSNRY, psnr);
560 CHECK (ret, "calculate PSNR_Y failed");
561 XCAM_LOG_INFO ("PSNR_Y: %.2f", psnr);
562
563 image_handler = create_cl_csc_image_handler (context, CL_CSC_TYPE_NV12TORGBA);
564 XCAM_ASSERT (image_handler.ptr ());
565
566 SmartPtr<VideoBuffer> psnr_cur_output, psnr_ref_output;
567 ret = image_handler->execute (psnr_cur, psnr_cur_output);
568 CHECK (ret, "execute kernels failed");
569 XCAM_ASSERT (psnr_cur_output.ptr ());
570
571 ret = image_handler->execute (psnr_ref, psnr_ref_output);
572 CHECK (ret, "execute kernels failed");
573 XCAM_ASSERT (psnr_ref_output.ptr ());
574
575 ret = calculate_psnr (psnr_cur_output, psnr_ref_output, PSNRR, psnr);
576 CHECK (ret, "calculate PSNR_R failed");
577 XCAM_LOG_INFO ("PSNR_R: %.2f", psnr);
578
579 ret = calculate_psnr (psnr_cur_output, psnr_ref_output, PSNRG, psnr);
580 CHECK (ret, "calculate PSNR_G failed");
581 XCAM_LOG_INFO ("PSNR_G: %.2f", psnr);
582
583 ret = calculate_psnr (psnr_cur_output, psnr_ref_output, PSNRB, psnr);
584 CHECK (ret, "calculate PSNR_B failed");
585 XCAM_LOG_INFO ("PSNR_B: %.2f", psnr);
586 }
587
588 return 0;
589 }
590