Repository navigation
Expand file tree
/
Copy pathSingleFrame.cpp
More file actions
113 lines (92 loc) · 3.09 KB
/
Copy pathSingleFrame.cpp
File metadata and controls
113 lines (92 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* Deathray - An Avisynth plug-in filter for spatial/temporal non-local means de-noising.
*
* version 1.04
*
* Copyright 2013, Jawed Ashraf - Deathray@cupidity.f9.co.uk
*/
#include "SingleFrame.h"
#include "device.h"
#include "buffer_map.h"
extern int g_device_count;
extern device *g_devices;
extern int g_gaussian;
SingleFrame::SingleFrame() {
device_id_ = 0;
width_ = 0;
height_ = 0;
src_pitch_ = 0;
dst_pitch_ = 0;
source_plane_ = 0;
dest_plane_ = 0;
}
result SingleFrame::Init(
const int &device_id,
const int &width,
const int &height,
const int &src_pitch,
const int &dst_pitch,
const float &h,
const int &sample_expand,
const int &linear,
const int &correction,
const int &target_min,
const int &balanced) {
if (device_id >= g_device_count) return FILTER_ERROR;
result status = FILTER_OK;
device_id_ = device_id;
width_ = width;
height_ = height;
src_pitch_ = src_pitch;
dst_pitch_ = dst_pitch;
cq_ = g_devices[device_id_].cq();
if (width_ == 0 || height_ == 0 || src_pitch_ == 0 || dst_pitch_ == 0 || h == 0 ) return FILTER_INVALID_PARAMETER;
status = g_devices[device_id_].buffers_.AllocPlane(cq_, width_, height_, &source_plane_);
if (status != FILTER_OK) return status;
status = g_devices[device_id_].buffers_.AllocPlane(cq_, width_, height_, &dest_plane_);
if (status != FILTER_OK) return status;
kernel_ = CLKernel(device_id_, "NLMSingleFrameFourPixel");
kernel_.SetArg(sizeof(cl_mem), g_devices[device_id_].buffers_.ptr(source_plane_));
kernel_.SetArg(sizeof(int), &width_);
kernel_.SetArg(sizeof(int), &height_);
kernel_.SetArg(sizeof(float), &h);
kernel_.SetArg(sizeof(int), &sample_expand);
kernel_.SetArg(sizeof(cl_mem), g_devices[device_id_].buffers_.ptr(g_gaussian));
kernel_.SetArg(sizeof(int), &linear);
kernel_.SetArg(sizeof(int), &correction);
kernel_.SetArg(sizeof(int), &target_min);
kernel_.SetArg(sizeof(int), &balanced);
kernel_.SetArg(sizeof(cl_mem), g_devices[device_id_].buffers_.ptr(dest_plane_));
if (kernel_.arguments_valid()) {
kernel_.set_work_dim(2);
const size_t set_local_work_size[2] = {8, 32};
const size_t set_scalar_global_size[2] = {width_, height_};
const size_t set_scalar_item_size[2] = {4, 1};
kernel_.set_local_work_size(set_local_work_size);
kernel_.set_scalar_global_size(set_scalar_global_size);
kernel_.set_scalar_item_size(set_scalar_item_size);
return FILTER_OK;
}
return FILTER_KERNEL_ARGUMENT_ERROR;
}
result SingleFrame::CopyTo(const unsigned char *source) {
return g_devices[device_id_].buffers_.CopyToPlaneAsynch(source_plane_,
*source,
width_,
height_,
src_pitch_,
&copied_to_);
}
result SingleFrame::Execute() {
return kernel_.ExecuteAsynch(cq_, &copied_to_, &executed_);
}
result SingleFrame::CopyFrom(
unsigned char *dest,
cl_event *returned) {
return g_devices[device_id_].buffers_.CopyFromPlaneAsynch(dest_plane_,
width_,
height_,
dst_pitch_,
&executed_,
returned,
dest);
}