Пример #1
0
void QRasterWindowSurface::beginPaint(const QRegion &rgn)
{
#if defined(Q_WS_X11) && !defined(QT_NO_MITSHM)
    syncX();
#endif

#if (defined(Q_WS_X11) && !defined(QT_NO_XRENDER)) || defined(Q_WS_WIN)
    if (!qt_widget_private(window())->isOpaque && window()->testAttribute(Qt::WA_TranslucentBackground)) {

#if defined(Q_WS_WIN)
        if (d_ptr->image->image.format() != QImage::Format_ARGB32_Premultiplied)
            prepareBuffer(QImage::Format_ARGB32_Premultiplied, window());
#endif

        QPainter p(&d_ptr->image->image);
        p.setCompositionMode(QPainter::CompositionMode_Source);
        const QVector<QRect> rects = rgn.rects();
        const QColor blank = Qt::transparent;
        for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) {
            p.fillRect(*it, blank);
        }
    }
#else
    Q_UNUSED(rgn);
#endif
}
Пример #2
0
void ServerConnection::ReadBandTable(const std::string &msFilename, BandInfo &band)
{
	_band = &band;
	
	std::cout << "Requesting band table from " << Hostname() << "...\n";
	std::stringstream reqBuffer;
	
	RequestBlock requestBlock;
	ReadBandTableRequestOptions options;
	
	requestBlock.blockIdentifier = RequestId;
	requestBlock.blockSize = sizeof(requestBlock);
	requestBlock.dataSize = sizeof(options.flags) + msFilename.size();
	requestBlock.request = ReadBandTableRequest;
	reqBuffer.write(reinterpret_cast<char *>(&requestBlock), sizeof(requestBlock));
	
	options.flags = 0;
	options.msFilename = msFilename;
	reqBuffer.write(reinterpret_cast<char *>(&options.flags), sizeof(options.flags));
	reqBuffer.write(reinterpret_cast<const char *>(options.msFilename.c_str()), options.msFilename.size());
	
	boost::asio::write(_socket, boost::asio::buffer(reqBuffer.str()));
	
	prepareBuffer(sizeof(GenericReadResponseHeader));
	boost::asio::async_read(_socket, boost::asio::buffer(_buffer, sizeof(GenericReadResponseHeader)),
		boost::bind(&ServerConnection::onReceiveBandTableResponseHeader, shared_from_this()));
}
Пример #3
0
void ServerConnection::ReadDataRows(const std::string &msFilename, size_t rowStart, size_t rowCount, MSRowDataExt *destinationArray)
{
	_readRowData = destinationArray;
	
	std::stringstream reqBuffer;
	
	RequestBlock requestBlock;
	ReadDataRowsRequestOptions options;
	
	requestBlock.blockIdentifier = RequestId;
	requestBlock.blockSize = sizeof(requestBlock);
	requestBlock.dataSize = sizeof(options.flags) + msFilename.size() + sizeof(options.startRow) + sizeof(options.rowCount);
	requestBlock.request = ReadDataRowsRequest;
	reqBuffer.write(reinterpret_cast<char *>(&requestBlock), sizeof(requestBlock));
	
	options.flags = 0;
	options.msFilename = msFilename;
	options.startRow = rowStart;
	options.rowCount = rowCount;
	
	reqBuffer.write(reinterpret_cast<char *>(&options.flags), sizeof(options.flags));
	reqBuffer.write(reinterpret_cast<const char *>(options.msFilename.c_str()), options.msFilename.size());
	reqBuffer.write(reinterpret_cast<const char *>(&options.startRow), sizeof(options.startRow));
	reqBuffer.write(reinterpret_cast<const char *>(&options.rowCount), sizeof(options.rowCount));
	
	boost::asio::write(_socket, boost::asio::buffer(reqBuffer.str()));
	
	prepareBuffer(sizeof(GenericReadResponseHeader));
	boost::asio::async_read(_socket, boost::asio::buffer(_buffer, sizeof(GenericReadResponseHeader)),
		boost::bind(&ServerConnection::onReceiveReadDataRowsResponseHeader, shared_from_this()));
}
Пример #4
0
void ServerConnection::ReadQualityTables(const std::string &msFilename, StatisticsCollection &collection, HistogramCollection &histogramCollection)
{
	_collection = &collection;
	_histogramCollection = &histogramCollection;
	
	std::stringstream reqBuffer;
	
	RequestBlock requestBlock;
	ReadQualityTablesRequestOptions options;
	
	requestBlock.blockIdentifier = RequestId;
	requestBlock.blockSize = sizeof(requestBlock);
	requestBlock.dataSize = sizeof(options.flags) + msFilename.size();
	requestBlock.request = ReadQualityTablesRequest;
	reqBuffer.write(reinterpret_cast<char *>(&requestBlock), sizeof(requestBlock));
	
	options.flags = 0;
	options.msFilename = msFilename;
	reqBuffer.write(reinterpret_cast<char *>(&options.flags), sizeof(options.flags));
	reqBuffer.write(reinterpret_cast<const char *>(options.msFilename.c_str()), options.msFilename.size());
	
	boost::asio::write(_socket, boost::asio::buffer(reqBuffer.str()));
	
	prepareBuffer(sizeof(GenericReadResponseHeader));
	boost::asio::async_read(_socket, boost::asio::buffer(_buffer, sizeof(GenericReadResponseHeader)),
		boost::bind(&ServerConnection::onReceiveQualityTablesResponseHeader, shared_from_this()));
}
Пример #5
0
    const csvsqldb::Values* getNextRow()
    {
        if(!_block) {
            prepareBuffer();
        }

        return _iterator->getNextRow();
    }
Пример #6
0
void UDPThread::run() {
  fd_set readfds;
  ssize_t receivedBytes;
  uint8_t buffer[RECEIVE_BUFFER_SIZE];
  struct sockaddr_in clientAddr;
  socklen_t clientAddrLen = sizeof(struct sockaddr_in);

  /* Set interval to m_timeout */
  m_transmitTimer.adjust(m_timeout, m_timeout);
  m_blockTimer.adjust(SELECT_TIMEOUT, SELECT_TIMEOUT);

  linfo << "UDPThread up and running" << std::endl;
  while (m_started) {
    /* Prepare readfds */
    FD_ZERO(&readfds);
    FD_SET(m_socket, &readfds);
    FD_SET(m_transmitTimer.getFd(), &readfds);
    FD_SET(m_blockTimer.getFd(), &readfds);

    int ret = select(std::max({m_socket, m_transmitTimer.getFd(), m_blockTimer.getFd()})+1,
                     &readfds, NULL, NULL, NULL);
    if (ret < 0) {
      lerror << "select error" << std::endl;
      break;
    }
    if (FD_ISSET(m_transmitTimer.getFd(), &readfds)) {
      if (m_transmitTimer.read() > 0) {
        if (m_frameBuffer->getFrameBufferSize())
          prepareBuffer();
        else {
          m_transmitTimer.disable();
        }
      }
    }
    if (FD_ISSET(m_blockTimer.getFd(), &readfds)) {
      m_blockTimer.read();
    }
    if (FD_ISSET(m_socket, &readfds)) {
      /* Clear buffer */
      memset(buffer, 0, RECEIVE_BUFFER_SIZE);
      receivedBytes = recvfrom(m_socket, buffer, RECEIVE_BUFFER_SIZE,
          0, (struct sockaddr *) &clientAddr, &clientAddrLen);
      if (receivedBytes < 0) {
        lerror << "recvfrom error." << std::endl;
        continue;
      } else if (receivedBytes > 0) {
        parsePacket(buffer, receivedBytes, clientAddr);
      }
    }
  }
  if (m_debugOptions.buffer) {
    m_frameBuffer->debug();
  }
  linfo << "Shutting down. UDP Transmission Summary: TX: " << m_txCount << " RX: " << m_rxCount << std::endl;
  shutdown(m_socket, SHUT_RDWR);
  close(m_socket);
}
void QRasterWindowSurface::setGeometry(const QRect &rect)
{
    QWindowSurface::setGeometry(rect);
    Q_D(QRasterWindowSurface);
    d->inSetGeometry = true;
    if (d->image == 0 || d->image->width() < rect.width() || d->image->height() < rect.height()) {
#if (defined(Q_WS_X11) && !defined(QT_NO_XRENDER)) || (defined(Q_WS_WIN) && !defined(Q_WS_WINCE))
#ifndef Q_WS_WIN
        if (d_ptr->translucentBackground)
#else
        if (!qt_widget_private(window())->isOpaque)
#endif
            prepareBuffer(QImage::Format_ARGB32_Premultiplied, window());
        else
#endif
            prepareBuffer(QNativeImage::systemFormat(), window());
    }
    d->inSetGeometry = false;
}
void QUnifiedToolbarSurface::setGeometry(const QRect &rect)
{
    QWindowSurface::setGeometry(rect);
    Q_D(QUnifiedToolbarSurface);
    d->inSetGeometry = true;
    if (d->image == 0 || d->image->width() < rect.width() || d->image->height() < rect.height())
            prepareBuffer(QImage::Format_ARGB32_Premultiplied, window());
    d->inSetGeometry = false;

    // FIXME: set unified toolbar height.
}
Пример #9
0
status_t GuiExtPoolItem::prepareBuffer(uint32_t gralloc_usage)
{
    status_t err = NO_ERROR;

    //err = prepareBuffer(mGPUUsedProducer, GUI_EXT_USAGE_GPU, 0, gralloc_usage, mGpuUsedBufNum);
    //GUIEXT_LOGV("    prepare %s buffer done", szUsageName[GUI_EXT_USAGE_GPU]);

    if (mIsHwcNeeded) {
#if SUPPORT_MULTIBQ_FOR_HWC
        for (uint32_t i = 0; i < mHwcUsedBqList.size(); i++) {
            err = prepareBuffer(mHwcUsedBqList[i]->mProducer, GUI_EXT_USAGE_HWC, mHwcUsedBqList[i]->type, gralloc_usage, mHwcUsedBqList[i]->bufNum);
            GUIEXT_LOGV("    prepare %s buffer, type=%d done", szUsageName[GUI_EXT_USAGE_HWC], mHwcUsedBqList[i]->type);
        }
#else
        err = prepareBuffer(mHwcUsedBq, GUI_EXT_USAGE_HWC, 0, gralloc_usage, mHwcUsedBqList[i]->bufNum);
        GUIEXT_LOGV("    prepare %s buffer done", szUsageName[GUI_EXT_USAGE_HWC]);
#endif
    }

    return err;
}
Пример #10
0
uint32_t GraphicsContext3DPrivate::copyToGraphicsSurface()
{
    createGraphicsSurface();

    if (!m_graphicsSurface || m_context->m_layerComposited || !prepareBuffer())
        return 0;

    m_graphicsSurface->copyFromTexture(m_context->m_texture, m_targetRect);
    makeContextCurrent();

    return m_graphicsSurface->frontBuffer();
}
Пример #11
0
void ServerConnection::Start()
{
	InitialBlock initialBlock;
	initialBlock.blockIdentifier = InitialId;
	initialBlock.blockSize = sizeof(initialBlock);
	initialBlock.options = 0;
	initialBlock.protocolVersion = AO_REMOTE_PROTOCOL_VERSION;
	
	boost::asio::write(_socket, boost::asio::buffer(&initialBlock, sizeof(initialBlock)));
	
	prepareBuffer(sizeof(InitialResponseBlock));
	boost::asio::async_read(_socket, boost::asio::buffer(_buffer, sizeof(InitialResponseBlock)), boost::bind(&ServerConnection::onReceiveInitialResponse, shared_from_this()));
}
Пример #12
0
void QRasterWindowSurface::setGeometry(const QRect &rect)
{
    QWindowSurface::setGeometry(rect);
    Q_D(QRasterWindowSurface);
    d->inSetGeometry = true;
    if (d->image == 0 || d->image->width() < rect.width() || d->image->height() < rect.height()) {
#if (defined(Q_WS_X11) && !defined(QT_NO_XRENDER)) || (defined(Q_WS_WIN))

#ifndef Q_WS_WIN
        if (d_ptr->translucentBackground)
#else
        if (!qt_widget_private(window())->isOpaque)
#endif
            prepareBuffer(QImage::Format_ARGB32_Premultiplied, window());
        else
#endif
            prepareBuffer(QNativeImage::systemFormat(), window());
    }
    d->inSetGeometry = false;

#if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA)
    QMainWindow* mWindow = qobject_cast<QMainWindow*>(window());
    if (mWindow) {
        QMainWindowLayout *mLayout = qobject_cast<QMainWindowLayout*>(mWindow->layout());
        QList<QToolBar *> toolbarList = mLayout->qtoolbarsInUnifiedToolbarList;

        for (int i = 0; i < toolbarList.size(); ++i) {
            QToolBar* toolbar = toolbarList.at(i);
            if (mLayout->toolBarArea(toolbar) == Qt::TopToolBarArea) {
                QWidget* tbWidget = (QWidget*) toolbar;
                if (tbWidget->d_func()->unifiedSurface) {
                    tbWidget->d_func()->unifiedSurface->setGeometry(rect);
                }
            }
        }
    }
#endif // Q_WS_MAC && QT_MAC_USE_COCOA

}
Пример #13
0
void ServerConnection::onReceiveReadDataRowsResponseHeader()
{
	GenericReadResponseHeader responseHeader = *reinterpret_cast<GenericReadResponseHeader*>(_buffer);
	if(responseHeader.blockIdentifier != GenericReadResponseHeaderId || responseHeader.blockSize != sizeof(responseHeader))
	{
		_onError(shared_from_this(), "Bad response from client upon read data rows request");
		StopClient();
	}
	else if(responseHeader.errorCode != NoError)
	{
		handleError(responseHeader);
		_onAwaitingCommand(shared_from_this());
	}
	else {
		prepareBuffer(responseHeader.dataSize);
		boost::asio::async_read(_socket, boost::asio::buffer(_buffer, responseHeader.dataSize),
			boost::bind(&ServerConnection::onReceiveReadDataRowsResponseData, shared_from_this(), responseHeader.dataSize));
	}
}
Пример #14
0
void ServerConnection::WriteDataRows(const std::string &msFilename, size_t rowStart, size_t rowCount, const MSRowDataExt *rowArray)
{
	_writeRowData = rowArray;
	
	std::stringstream reqBuffer;
	
	RequestBlock requestBlock;
	WriteDataRowsRequestOptions options;
	
	requestBlock.blockIdentifier = RequestId;
	requestBlock.blockSize = sizeof(requestBlock);
	requestBlock.dataSize = sizeof(options.flags) + msFilename.size() + sizeof(options.startRow) + sizeof(options.rowCount) + sizeof(options.dataSize);
	requestBlock.request = WriteDataRowsRequest;
	reqBuffer.write(reinterpret_cast<char *>(&requestBlock), sizeof(requestBlock));
	
	std::ostringstream dataBuffer;
	// Serialize the rows
	for(size_t rowIndex=0; rowIndex != rowCount; ++rowIndex) {
		rowArray[rowIndex].Serialize(dataBuffer);
	}
	std::string dataBufferStr = dataBuffer.str();

	options.flags = 0;
	options.msFilename = msFilename;
	options.startRow = rowStart;
	options.rowCount = rowCount;
	options.dataSize = dataBufferStr.size();
	
	reqBuffer.write(reinterpret_cast<char *>(&options.flags), sizeof(options.flags));
	reqBuffer.write(reinterpret_cast<const char *>(options.msFilename.c_str()), options.msFilename.size());
	reqBuffer.write(reinterpret_cast<const char *>(&options.startRow), sizeof(options.startRow));
	reqBuffer.write(reinterpret_cast<const char *>(&options.rowCount), sizeof(options.rowCount));
	reqBuffer.write(reinterpret_cast<const char *>(&options.dataSize), sizeof(options.dataSize));
	
	boost::asio::write(_socket, boost::asio::buffer(reqBuffer.str()));
	boost::asio::write(_socket, boost::asio::buffer(dataBufferStr));
	
	prepareBuffer(sizeof(GenericReadResponseHeader));
	boost::asio::async_read(_socket, boost::asio::buffer(_buffer, sizeof(GenericReadResponseHeader)),
		boost::bind(&ServerConnection::onReceiveWriteDataRowsResponseHeader, shared_from_this()));
}
Пример #15
0
void QRasterWindowSurface::beginPaint(const QRegion &rgn)
{
#if (defined(Q_WS_X11) && !defined(QT_NO_XRENDER)) || (defined(Q_WS_WIN) && !defined(Q_OS_WINCE))
    if (!qt_widget_private(window())->isOpaque) {
#if defined(Q_WS_WIN) && !defined(Q_OS_WINCE)
        if (d_ptr->image->image.format() != QImage::Format_ARGB32_Premultiplied
            && d_ptr->canUseLayeredWindow)
            prepareBuffer(QImage::Format_ARGB32_Premultiplied, window());
#endif
        QPainter p(&d_ptr->image->image);
        p.setCompositionMode(QPainter::CompositionMode_Source);
        const QVector<QRect> rects = rgn.rects();
        const QColor blank = Qt::transparent;
        for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) {
            p.fillRect(*it, blank);
        }
    }
#endif
#if defined(Q_OS_WINCE)
    Q_UNUSED(rgn);
#endif
}
Пример #16
0
void sendBuffer(hid_device *display, const unsigned char *sequence) {
  prepareBuffer(sequence, strlen(sequence));
  hid_write(display, buffer, BA6X_LEN);
}
Пример #17
0
void
TextPainter::redrawText(const util::rect<double>& roi, const util::point<double>& resolution) {

	// make a copy of the data needed to draw the text
	string __text;
	double __textSize;
	double __padding;
	std::vector<double> __textColor;

	{
		boost::mutex::scoped_lock lock(_dataMutex);

		__text      = _text;
		__textSize  = _textSize;
		__padding   = _padding;
		__textColor = _textColor;
	}

	LOG_ALL(textpainterlog) << "[redrawText] redrawing text..." << std::endl;

	// Each Gl unit represents resolution.* pixels. This gives the target pixel
	// size. [cu]

	util::rect<double>  cairoSize        = _glSize*resolution;
	util::point<double> cairoPadding     = _glPadding*resolution;
	util::point<double> glToCairoScale   = resolution;
	util::point<double> textToGlScale(1.0, 1.0);
	util::point<double> textToCairoScale = textToGlScale*glToCairoScale;

	LOG_ALL(textpainterlog) << "[redrawText] according to current resolution ("
	                     << resolution << "), this is " << cairoSize << "[cu]"
	                     << std::endl;

	_glRoi = roi;

	LOG_ALL(textpainterlog) << "[redrawText] ROI is " << _glRoi << "[gu]" << std::endl;

	// Find portion of target region that is within ROI. [gu]
	_glRoi.minX = std::max(_glRoi.minX, _glSize.minX);
	_glRoi.minY = std::max(_glRoi.minY, _glSize.minY);
	_glRoi.maxX = std::min(_glRoi.maxX, _glSize.maxX);
	_glRoi.maxY = std::min(_glRoi.maxY, _glSize.maxY);

	// Determine ROI region of target region. [cu]
	util::rect<double> cairoRoi = _glRoi*glToCairoScale;

	LOG_ALL(textpainterlog) << "[redrawText] relevant part is " << cairoRoi << "[cu]" << std::endl;

	if (cairoRoi.width() <= 0 || cairoRoi.height() <= 0)
		return;

	// The target size. [cu]
	_cairoWidth  = (int)round(cairoRoi.width());
	_cairoHeight = (int)round(cairoRoi.height());

	LOG_ALL(textpainterlog) << "[redrawText] rounded, this is " << _cairoWidth << "x"
	                     << _cairoHeight << " pixels" << std::endl;

	LOG_ALL(textpainterlog) << "[redrawText] scaling is " << textToCairoScale << std::endl;

	// Next, we prepare the cairo surface for the text.
	if (!prepareBuffer()) {

		LOG_DEBUG(textpainterlog) << "[redrawText] failed to create buffer" << std::endl;
		return;
	}

	LOG_ALL(textpainterlog) << "[redrawText] prepared new cairo surface" << std::endl;

	// Scale the cairo text to fill the scaled surface.
	_cairoTextSize = __textSize*textToCairoScale.x; // this will be incorrect for anisotropic resolutions
	setFont(_context, __textColor);

	LOG_ALL(textpainterlog) << "[redrawText] cairo text size is now " << _cairoTextSize << std::endl;

	// Determine the starting point of the text drawing with respect to padding.
	// [ncu]
	util::point<double> textStart(-_extents.x_bearing, -_extents.y_bearing);

	LOG_ALL(textpainterlog) << "[redrawText] text starting point according to bearing is " << textStart << "[ncu]" << std::endl;

	textStart += util::point<double>(_padding, _padding);

	LOG_ALL(textpainterlog) << "[redrawText] with padding this makes " << textStart << "[ncu]" << std::endl;

	// Determine the starting point of the text drawing relative to ROI [cu].
	util::point<double> cairoRoiStart = textStart*textToCairoScale;

	LOG_ALL(textpainterlog) << "[redrawText] in target units this is " << cairoRoiStart << "[cu]" << std::endl;

	cairoRoiStart -= util::point<double>(cairoRoi.minX - cairoSize.minX, cairoRoi.minY - cairoSize.minY);

	LOG_ALL(textpainterlog) << "[redrawText] taking into account the ROI, we have finally " << cairoRoiStart << "[cu]" << std::endl;

	// We have to draw upside down to be OpenGl compatible
	cairo_scale(_context, 1.0, -1.0);

	// Move to the starting point.
	cairo_move_to(
			_context,
			 cairoRoiStart.x,
			 cairoRoiStart.y - _cairoHeight);

	// Draw the text.
	cairo_show_text(_context, __text.c_str());

	finishBuffer();
}
Пример #18
0
void
TextPainter::computeSize(
		const util::rect<double>&  roi,
		const util::point<double>& resolution) {

	LOG_ALL(textpainterlog) << "[computeSize] computing size..." << std::endl;

	// TODO: we call this just to get a valid context -- create a dummy context
	// instead and use that
	_glRoi.minX  = 0;
	_glRoi.minY  = 0;
	_cairoWidth  = 1;
	_cairoHeight = 1;

	if (!prepareBuffer()) {

		LOG_DEBUG(textpainterlog) << "[computeSize] failed to create dummy buffer" << std::endl;
		return;
	}

	// set font and color
	LOG_ALL(textpainterlog) << "[computeSize] drawing cairo text with size " << _textSize << std::endl;
	_cairoTextSize = _textSize;
	setFont(_context, _textColor);

	// ncu ... normalized cairo units
	//  gu ... open gl units
	//  cu ... scaled cairo units

	// Determine the extents of the text to draw in cairo pixels, when cairo
	// text size is set to textSize. [ncu]
	cairo_text_extents(_context, _text.c_str(), &_extents);

	finishBuffer();

	util::rect<double> textSize(0.0, 0.0, _extents.width, _extents.height);

	LOG_ALL(textpainterlog) << "[computeSize] text would have size " << textSize << ", when drawn with " << _cairoTextSize << std::endl;

	// Add some padding. [ncu]
	textSize.minX -= _padding;
	textSize.minY -= _padding;
	textSize.maxX += _padding;
	textSize.maxY += _padding;

	LOG_ALL(textpainterlog) << "[computeSize] with some padding of " << _padding << " [ncu], this is " << textSize << "[ncu]" << std::endl;

	// Now we have to determine the target size according to the current
	// resolution. [cu]

	// Let's say one cairo pixel is one Gl unit. We need to know the target
	// size in Gl units. [ncu] -> [gu]

	_glSize    = textSize;
	_glPadding = util::point<double>(_padding, _padding);

	LOG_ALL(textpainterlog) << "[computeSize] in Gl coordinates " << _glSize << "[gu]" << std::endl;

	// Despite the possible ROI cropping, our size is glSize
	setSize(_glSize.minX, _glSize.minY, _glSize.maxX, _glSize.maxY);
}
Пример #19
0
GLuint BufferManager::addBuffer(const std::string& bufferName, std::vector<T>& bufferData) {
    GLuint bufferId = prepareBuffer(bufferData);
    bufferResourceManager.addResource(bufferName, bufferId);
    return bufferId;
}
Пример #20
0
int SRAD_GPU(IplImage *imgSrc, IplImage* imgDes, int iterTime){
    cl_int ret;
    size_t iSize    = (imgSrc->width * imgSrc->height);
    int iWidth      = imgSrc->width;
    int iHeight     = imgSrc->height;
    int iStep       = imgSrc->widthStep;
    printf("Image size is %dx%d=%d\n", imgSrc->width,imgSrc->height,iSize);
    /*
     if(iSize>254*254*254){
     fprintf(stderr,"image size is too large\n");
     system("pause");
     exit(-1);
     }
     */
    openclInit();

    prepareBuffer(imgSrc,iterTime);

    cl_program  program1,program2;
    cl_kernel   kernelCQ,kernelSRAD;
    openclCreateKernelFromFile(&program1,&kernelCQ,KERNEL_FILE,"CQ");
    openclCreateKernelFromFile(&program2,&kernelSRAD,KERNEL_FILE,"SRAD");
   
    size_t global_work_size[]={2,2,1};
    if(iSize<255)
    {
        
    global_work_size[0]=iSize;
    }
    else
    {
        global_work_size[0]=256;
        if(iSize<256*256)
        {
            global_work_size[1]=(size_t)ceil(double(iSize)/256);
        }
        else
        {
            global_work_size[1]=256;
            global_work_size[2]=size_t(ceil(double(iSize)/256/256));
        }
    }
    size_t local_work_size[]={1,1,1};
    printf("global work size %zu %zu %zu\n",global_work_size[0],global_work_size[1],global_work_size[2]);
    printf("local work size %zu %zu %zu\n",local_work_size[0],local_work_size[1],local_work_size[2]);

    /*
     global_work_size[0]=254;
     global_work_size[1]=254;
     global_work_size[2]=1;
     local_work_size[0]=254;
     local_work_size[1]=1;
     local_work_size[2]=1;
     */
    struct param parSwap;
    for(int i=1;i<=iterTime;i++){
        printf("Run %d times iteration\n",i);
        
        openclRetTackle(clSetKernelArg(kernelCQ,0,sizeof(cl_mem),&cmPar),"clSetKernelArg 0");
        openclRetTackle(clSetKernelArg(kernelCQ,1,sizeof(cl_mem),&cmImgSrc),"clSetKernelArg 1");
        openclRetTackle(clSetKernelArg(kernelCQ,2,sizeof(cl_mem),&cmCqM),"clSetKernelArg 2");
        openclRetTackle(clEnqueueNDRangeKernel(cqCommandQueue,kernelCQ,3,0,global_work_size,NULL,0,0,0),"clEnqueueNDRangeKernel cq");
        openclRetTackle(clFinish(cqCommandQueue),"clFinish");
        
        
        struct param* hostmap=(struct param*)clEnqueueMapBuffer(cqCommandQueue,cmPar,CL_TRUE,CL_MAP_WRITE,0,sizeof(struct param),0,0,0,&ret);
        hostmap->it=i;
        clEnqueueUnmapMemObject(cqCommandQueue,cmPar,hostmap,0,0,0);
        
        openclRetTackle(clSetKernelArg(kernelSRAD,0,sizeof(cl_mem),&cmPar),"clSetKernelArg 0");
        openclRetTackle(clSetKernelArg(kernelSRAD,1,sizeof(cl_mem),&cmCqM),"clSetKernelArg 1");
        openclRetTackle(clSetKernelArg(kernelSRAD,2,sizeof(cl_mem),&cmImgSrc),"clSetKernelArg 2");
        openclRetTackle(clSetKernelArg(kernelSRAD,3,sizeof(cl_mem),&cmImgDes),"clSetKernelArg 3");
        openclRetTackle(clEnqueueNDRangeKernel(cqCommandQueue,kernelSRAD,3,0,global_work_size,NULL,0,0,0),"clEnqueueNDRangeKernel SRAD");
        openclRetTackle(clFinish(cqCommandQueue),"clFinish");
        
        cl_mem tmp;
        tmp         = cmImgSrc;
        cmImgSrc    = cmImgDes;
        cmImgDes    = tmp;
    }
    
    float* outBuffer=(float*)malloc(sizeof(float)*iSize);
    memset(outBuffer,0,sizeof(float)*iSize);
    clEnqueueReadBuffer(cqCommandQueue,cmImgSrc,CL_TRUE,0,sizeof(float)*iSize,outBuffer,0,0,0);
    printf("%f %f %f\n",outBuffer[2*iWidth+2],outBuffer[2*iWidth+3],outBuffer[2*iWidth+4]);
    
    for(int i=0;i<iHeight;i++)
    {
        for(int j=0;j<iWidth;j++)
        {
            imgDes->imageData[i*iStep+j]=(unsigned char)(outBuffer[i*iWidth+j]);
        }
    }
    
    return 0;
}