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.
89 lines
2.5 KiB
89 lines
2.5 KiB
5 years ago
|
#include "model/processor/strategies/DynCont.h"
|
||
|
#include "model/processor/BIP.h"
|
||
|
#include <QPixmap>
|
||
|
#include <QImage>
|
||
|
|
||
|
DynCont::DynCont(const Context context,
|
||
|
const QString kernelPath,
|
||
|
const QObject *parent = Q_NULLPTR) :
|
||
|
IProcessStrategy(context, kernelPath, "DynCont", parent),
|
||
|
_kernelFunctor(KernelFunctor<Image2D, Image2D,
|
||
|
LocalSpaceArg, Buffer, DynCont_t>(_kernel))
|
||
|
{
|
||
|
memset(&_kernelParameters, 0, sizeof (DynCont_t));
|
||
|
}
|
||
|
|
||
|
void DynCont::cpuProcess(ScenGenOutput_t parameters)
|
||
|
{
|
||
|
if(parameters.dynContGain.isUpdated)
|
||
|
{
|
||
|
_kernelParameters.gain = parameters.dynContGain.value;
|
||
|
}
|
||
|
|
||
|
if(parameters.dynContSelector.isUpdated)
|
||
|
{
|
||
|
_kernelParameters.dynContSelector = parameters.dynContSelector.value;
|
||
|
}
|
||
|
|
||
|
|
||
|
if(parameters.compressionType.isUpdated)
|
||
|
{
|
||
|
_kernelParameters.compressionType = parameters.compressionType.value;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void DynCont::finalize()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
Image* DynCont::processKernel(Image *frames, Buffer* scratchPad)
|
||
|
{
|
||
|
auto format = frames->getImageInfo<CL_IMAGE_FORMAT>();
|
||
|
auto width = frames->getImageInfo<CL_IMAGE_WIDTH>();
|
||
|
auto height = frames->getImageInfo<CL_IMAGE_HEIGHT>();
|
||
|
|
||
|
auto imageOutput = new Image2D(_CLContext,
|
||
|
CL_MEM_READ_WRITE,
|
||
|
ImageFormat(format.image_channel_order, format.image_channel_data_type),
|
||
|
width,
|
||
|
height);
|
||
|
//width should be lass than CL_DEVICE_MAX_WORK_GROUP_SIZE(1024 for current machine) or this will break
|
||
|
cl::EnqueueArgs eargs(BIP::getInstance()->CLQueue, cl::NDRange(width, height), cl::NDRange(width, 1));
|
||
|
|
||
|
_kernelParameters.state = 1;
|
||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, DynCont_t>(_kernelFunctor,
|
||
|
eargs,
|
||
|
*static_cast<Image2D*>(frames),
|
||
|
*imageOutput,
|
||
|
Local(width * sizeof (myflt)),
|
||
|
*scratchPad,
|
||
|
_kernelParameters);
|
||
|
|
||
|
|
||
|
cl::EnqueueArgs eargs2(BIP::getInstance()->CLQueue, cl::NDRange(height, 1), cl::NDRange(height, 1));
|
||
|
|
||
|
_kernelParameters.state = 2;
|
||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, DynCont_t>(_kernelFunctor,
|
||
|
eargs2,
|
||
|
*static_cast<Image2D*>(frames),
|
||
|
*imageOutput,
|
||
|
Local(height * sizeof (myflt)),
|
||
|
*scratchPad,
|
||
|
_kernelParameters);
|
||
|
|
||
|
|
||
|
_kernelParameters.state = 3;
|
||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, DynCont_t>(_kernelFunctor,
|
||
|
eargs,
|
||
|
*static_cast<Image2D*>(frames),
|
||
|
*imageOutput,
|
||
|
Local(1),
|
||
|
*scratchPad,
|
||
|
_kernelParameters);
|
||
|
|
||
|
delete frames;
|
||
|
|
||
|
return imageOutput;
|
||
|
}
|