当前位置: 首页>>代码示例>>C++>>正文


C++ Image::Data方法代码示例

本文整理汇总了C++中Image::Data方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::Data方法的具体用法?C++ Image::Data怎么用?C++ Image::Data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Image的用法示例。


在下文中一共展示了Image::Data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Apply

void CMeanFilter_GPU::Apply(const Image& input, Image& output)
{
	const int radius = CFilterParameterInterpreter<int>::Convert(_parameters->GetParameter("Radius"));
	const int width = input.Width();
	const int height = input.Height();
	const int NbPixel = width * height;
	const int depth = input.Depth();
	const unsigned char *image_data = input.Data();
	unsigned char *output_data = output.Data();

	//int *TempPix = new int[ NbPixel * 2 ];
	unsigned char *TempMask = new unsigned char[NbPixel];
	//memset( TempPix, 0, NbPixel * 2 * sizeof( int ) );
	memset(TempMask, 255, NbPixel * sizeof(unsigned char));

	auto current_device = OpenCLUtils::Instance()->GetCurrentDevice();
	const cl::Context Context = current_device.Context();

	cl_int Error;
	cl_mem_flags InOutMemFlags = CL_MEM_READ_WRITE;
	cl_mem_flags InMemFlags = CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR;
	cl_mem_flags OutMemFlags = CL_MEM_WRITE_ONLY;

	// If you ever change the local size, don't forget to change the size in the kernel
	// Global size must be a multiple of local size
	unsigned int GlobalSizeY = height;
	unsigned int GlobalSizeX = width;

	cl::Buffer ImBuffer(Context, InMemFlags, NbPixel * depth * sizeof(unsigned char), (void*)image_data, &Error);
	cl::Buffer MaskBuffer(Context, InMemFlags, NbPixel * sizeof(unsigned char), (void*)TempMask, &Error);
	cl::Buffer OutBuffer(Context, OutMemFlags, NbPixel * depth * sizeof(unsigned char), 0, &Error);

	cl::CommandQueue Queue = current_device.CommandQueue();
	cl::Event Event;

	// Horizontal pass
	int Index = 0;
	m_KernelH.setArg(Index++, ImBuffer);
	m_KernelH.setArg(Index++, MaskBuffer);
	m_KernelH.setArg(Index++, OutBuffer);
	m_KernelH.setArg(Index++, height);
	m_KernelH.setArg(Index++, width);
	m_KernelH.setArg(Index++, radius);

	Queue.enqueueNDRangeKernel(m_KernelH, cl::NullRange, cl::NDRange(GlobalSizeX, GlobalSizeY), cl::NullRange, 0, &Event);
	Event.wait();

	Queue.enqueueReadBuffer(OutBuffer, true, 0, NbPixel * depth * sizeof(unsigned char), (void*)output_data, 0, &Event);
	Event.wait();

	Queue.finish();

	delete[] TempMask;
}
开发者ID:SebGrenier,项目名称:OpenCLFilterPipeline,代码行数:54,代码来源:MeanFilters.cpp

示例2: BeginLoad

bool Texture::BeginLoad(Stream& source)
{
    loadImages.Clear();
    loadImages.Push(new Image());
    if (!loadImages[0]->Load(source))
    {
        loadImages.Clear();
        return false;
    }

    // If image uses unsupported format, decompress to RGBA now
    if (loadImages[0]->Format() >= FMT_ETC1)
    {
        Image* rgbaImage = new Image();
        rgbaImage->SetSize(loadImages[0]->Size(), FMT_RGBA8);
        loadImages[0]->DecompressLevel(rgbaImage->Data(), 0);
        loadImages[0] = rgbaImage; // This destroys the original compressed image
    }

    // Construct mip levels now if image is uncompressed
    if (!loadImages[0]->IsCompressed())
    {
        Image* mipImage = loadImages[0];

        while (mipImage->Width() > 1 || mipImage->Height() > 1)
        {
            loadImages.Push(new Image());
            mipImage->GenerateMipImage(*loadImages.Back());
            mipImage = loadImages.Back();
        }
    }
    
    return true;
}
开发者ID:valera-rozuvan,项目名称:turso3d,代码行数:34,代码来源:Texture.cpp


注:本文中的Image::Data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。