You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					37 lines
				
				1.3 KiB
			
		
		
			
		
	
	
					37 lines
				
				1.3 KiB
			| 
											3 years ago
										 | #include "system/camerad/transforms/rgb_to_yuv.h"
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 | #include <cassert>
 | ||
|  | #include <cstdio>
 | ||
| 
											6 years ago
										 | 
 | ||
| 
											5 years ago
										 | Rgb2Yuv::Rgb2Yuv(cl_context ctx, cl_device_id device_id, int width, int height, int rgb_stride) {
 | ||
|  |   assert(width % 2 == 0 && height % 2 == 0);
 | ||
| 
											6 years ago
										 |   char args[1024];
 | ||
|  |   snprintf(args, sizeof(args),
 | ||
|  |            "-cl-fast-relaxed-math -cl-denorms-are-zero "
 | ||
|  | #ifdef CL_DEBUG
 | ||
|  |            "-DCL_DEBUG "
 | ||
|  | #endif
 | ||
|  |            "-DWIDTH=%d -DHEIGHT=%d -DUV_WIDTH=%d -DUV_HEIGHT=%d -DRGB_STRIDE=%d -DRGB_SIZE=%d",
 | ||
| 
											5 years ago
										 |            width, height, width / 2, height / 2, rgb_stride, width * height);
 | ||
| 
											6 years ago
										 | 
 | ||
| 
											5 years ago
										 |   cl_program prg = cl_program_from_file(ctx, device_id, "transforms/rgb_to_yuv.cl", args);
 | ||
|  |   krnl = CL_CHECK_ERR(clCreateKernel(prg, "rgb_to_yuv", &err));
 | ||
| 
											5 years ago
										 |   CL_CHECK(clReleaseProgram(prg));
 | ||
| 
											5 years ago
										 | 
 | ||
|  |   work_size[0] = (width + (width % 4 == 0 ? 0 : (4 - width % 4))) / 4;
 | ||
|  |   work_size[1] = (height + (height % 4 == 0 ? 0 : (4 - height % 4))) / 4;
 | ||
| 
											6 years ago
										 | }
 | ||
|  | 
 | ||
| 
											5 years ago
										 | Rgb2Yuv::~Rgb2Yuv() {
 | ||
|  |   CL_CHECK(clReleaseKernel(krnl));
 | ||
| 
											6 years ago
										 | }
 | ||
|  | 
 | ||
| 
											5 years ago
										 | void Rgb2Yuv::queue(cl_command_queue q, cl_mem rgb_cl, cl_mem yuv_cl) {
 | ||
|  |   CL_CHECK(clSetKernelArg(krnl, 0, sizeof(cl_mem), &rgb_cl));
 | ||
|  |   CL_CHECK(clSetKernelArg(krnl, 1, sizeof(cl_mem), &yuv_cl));
 | ||
| 
											6 years ago
										 |   cl_event event;
 | ||
| 
											5 years ago
										 |   CL_CHECK(clEnqueueNDRangeKernel(q, krnl, 2, NULL, &work_size[0], NULL, 0, 0, &event));
 | ||
| 
											5 years ago
										 |   CL_CHECK(clWaitForEvents(1, &event));
 | ||
|  |   CL_CHECK(clReleaseEvent(event));
 | ||
| 
											6 years ago
										 | }
 |