Esempio n. 1
0
void QgsComposerItem::drawSelectionBoxes( QPainter* p )
{

  if ( !mComposition )
  {
    return;
  }

  if ( mComposition->plotStyle() == QgsComposition::Preview )
  {
    double sizeLockSymbol = lockSymbolSize();

    if ( mItemPositionLocked )
    {
      //draw lock symbol at upper left edge. Use QImage to be independent of the graphic system
      QString lockIconPath = QgsApplication::activeThemePath() + "/mIconLock.png";
      if ( !QFile::exists( lockIconPath ) )
      {
        lockIconPath = QgsApplication::defaultThemePath() + "/mIconLock.png";
      }

      QImage lockImage( lockIconPath );
      if ( !lockImage.isNull() )
      {
        p->drawImage( QRectF( 0, 0, sizeLockSymbol, sizeLockSymbol ), lockImage, QRectF( 0, 0, lockImage.width(), lockImage.height() ) );
      }
    }
  }
}
Esempio n. 2
0
void Block::drawBlock()
{
	lockImage();
	if(myImage)
	{
		delete myImage;
	}
	myImage = new Image(Image::ARGB,120,120,true); // cells are 30 wide by 30 high, so always 80x80
	int drawn = 0; 
	Graphics g(*myImage);

	StringArray shape = *(getBlockShape());
	int x = 0;
	int y = 0;
	int width = 30;
	int height = 30;
	g.setColour(blockColour);
	for(int i = 0; i < 4; i++)
	{
		x = 0;
		for(int j = 0; j < 4 && drawn < 4; j++)
		{
			if(shape[i][j] == 'a')
			{
				drawn++;
				g.fillRect(x,y,width,height);
				g.drawBevel(x,y,width,height,width,blockColour.brighter(.75f),blockColour.darker(.75f),true);
			}
			x += width;
		}
		y += height;
	}
	unlockImage();
}
Esempio n. 3
0
JpegReceiver::~JpegReceiver()
{
	stop();
	lockImage();
	if (lock_image)			::CloseHandle(lock_image);
	if (event_abort)		::CloseHandle(event_abort);
}
Esempio n. 4
0
JpegWrap JpegReceiver::getNextFrame()
{
	lockImage();
	JpegWrap pic(currentPic.pic.get(), currentPic.length);
	releaseImage();
	return pic;
}
Esempio n. 5
0
Picture JpegReceiver::nextPic()
{
	createNextPicture();
	lockImage();
	Picture nextPicture = curPic.clone();
	releaseImage();
	return nextPicture;
}
Esempio n. 6
0
void JpegReceiver::createNextPicture()
{
	JpegWrap frame = getNextFrame();
	if (frame.length == 0) return;
	DWORD tm = GetTickCount();
	CxImage* image = new CxImage(frame.pic.get(), frame.length, CXIMAGE_FORMAT_JPG);
	Picture pic = Picture::createFromCxImage(image);
	delete image;
//	Capture_Log::getInstance()->log_write("Time is %d\n", GetTickCount() - tm);
	lockImage();
	curPic = pic;
	releaseImage();
}
Esempio n. 7
0
already_AddRefed<SourceSurface>
BasicImageLayer::GetAsSourceSurface()
{
  if (!mContainer) {
    return nullptr;
  }

  AutoLockImage lockImage(mContainer);
  Image* image = lockImage.GetImage();
  if (!image) {
    return nullptr;
  }
  return image->GetAsSourceSurface();
}
Esempio n. 8
0
void JpegReceiver::nextStep()
{
	while (bufferLength < headerPrediction)
	{
		receivePacket();
	}
	std::string firstPart((char*)(buffer.get() + bufferStartPoint), headerPrediction);
	std::string lengthBorderBig = "Content-Length: ";
	std::string lengthBorderSmall = "Content-length: ";
	int placeBig = firstPart.find(lengthBorderBig);
	int placeSmall = firstPart.find(lengthBorderSmall);
	int startLen = std::max(placeBig, placeSmall) + lengthBorderBig.length();
	int endLen = startLen;
	while (firstPart.at(endLen) >= '0' && firstPart.at(endLen) <= '9')
	{
		endLen++;
	}
	int jpegLength = atoi(firstPart.substr(startLen, endLen - startLen).c_str());
	while (firstPart.at(endLen) == ' ' || firstPart.at(endLen) == '\n' || firstPart.at(endLen) == '\r')
	{
		++endLen;
	}
	if (placeSmall != -1) endLen += 28;
	while (bufferLength - endLen < jpegLength)
	{
		receivePacket();
	}
	lockImage();
	currentPic = JpegWrap(buffer.get() + (bufferStartPoint + endLen) * sizeof(unsigned char), jpegLength);
//	createNextBmp();
	releaseImage();
//	createNextPicture();

	//jpegWrap.pic = sh_ptr_uch(new unsigned char[jpegWrap.length]);
	//memcpy(jpegWrap.pic.get(), buffer.get() + (bufferStartPoint + endLen) * sizeof(unsigned char), jpegWrap.length * sizeof(unsigned char));
/*	for (int i = 0; i < jpegLength; ++i)
	{
		data.get()[i] = buffer.get()[bufferStartPoint + endLen + i];
	}*/
	shiftBuffer(bufferStartPoint + endLen + jpegLength);
}
Esempio n. 9
0
void QgsComposerItem::drawSelectionBoxes( QPainter* p )
{
    if ( !mComposition )
    {
        return;
    }

    if ( mComposition->plotStyle() == QgsComposition::Preview )
    {
        //size of symbol boxes depends on zoom level in composer view
        double rectHandlerSize = rectHandlerBorderTolerance();
        double sizeLockSymbol = lockSymbolSize();

        if ( mItemPositionLocked )
        {
            //draw lock symbol at upper left edge. Use QImage to be independent of the graphic system
            QString lockIconPath = QgsApplication::activeThemePath() + "/mIconLock.png";
            if ( !QFile::exists( lockIconPath ) )
            {
                lockIconPath = QgsApplication::defaultThemePath() + "/mIconLock.png";
            }

            QImage lockImage( lockIconPath );
            if ( !lockImage.isNull() )
            {
                p->drawImage( QRectF( 0, 0, sizeLockSymbol, sizeLockSymbol ), lockImage, QRectF( 0, 0, lockImage.width(), lockImage.height() ) );
            }
        }
        else //draw blue squares
        {
            p->setPen( QColor( 50, 100, 120, 200 ) );
            p->setBrush( QColor( 200, 200, 210, 120 ) );
            p->drawRect( QRectF( 0, 0, rectHandlerSize, rectHandlerSize ) );
            p->drawRect( QRectF( rect().width() - rectHandlerSize, 0, rectHandlerSize, rectHandlerSize ) );
            p->drawRect( QRectF( rect().width() - rectHandlerSize, rect().height() - rectHandlerSize, rectHandlerSize, rectHandlerSize ) );
            p->drawRect( QRectF( 0, rect().height() - rectHandlerSize, rectHandlerSize, rectHandlerSize ) );
        }
    }
}
Esempio n. 10
0
// drawGrid iterates over all the grid cells, drawing blocks where possible.
void TetrisGrid::drawGrid()
{
	lockImage();
	if(myImage != 0)
	{
		delete myImage;
	}
	myImage = new Image(Image::ARGB,outerRect.getWidth(), outerRect.getHeight(),false);
	Graphics g(*myImage);
	g.fillAll(Colours::darkgrey);

	g.setOrigin(5,0); // move the origin to (5,0), so we have a border on the edges

	int x = 0;
	int y = 0;

	for(int i = 0; i < GRID_HEIGHT; i++)
	{
		x = 0;
		for(int j = 0; j < GRID_WIDTH; j++)
		{
			Colour c(Colours::white);
			jassert(grid[i]->length() == 10);
			if((*(grid[i]))[j] == 'a')
			{
				c = Colours::darkgrey;
			}
			g.setColour(c);
			g.fillRect(x,y,cellWidth,cellHeight);
			x += cellWidth;	
		}
		y += cellHeight;
	}
	unlockImage();
	updatedImage = true;
}
Esempio n. 11
0
// =======================================================
// may raise ERR_OPENED, ERR_EXIST, errno
void CImageDisk::openWriting() // [Main-Thread]
{
#ifdef HAVE_FSTAT64
  struct stat64 fStat;
#else
  struct stat fStat;
#endif
  int flags;
  int nRes;
  char szShortName[32]; // DOS short filenames
  char szPathDir[MAXPATHLEN];

  BEGIN;

  showDebug(1, "ALREADY=%lld\n", m_qwTotal);

  if (m_bIsOpened == true)
    THROW(ERR_OPENED);
  
  SNPRINTF(szShortName, "pi%.8x", (DWORD)generateIdentificator());
  extractFilepathFromFullPath(m_szImageFilename, szPathDir); // filepath without filename
  if (access(szPathDir, R_OK) == -1) mkdir(szPathDir, 0755);
  snprintf(m_szSpaceFilename, MAXPATHLEN, "%s/%8s.tmp", szPathDir, szShortName);
  showDebug(1, "TEMP=[%s]\n", m_szSpaceFilename);

  if (strcmp(m_szImageFilename, "stdout"))
    { // we create spacefile only if imagefile is not stdout
      errno = 0;
      nRes = createSpaceFile();
      if (nRes == -1)
        {
          if (errno == ENOSPC)
    	    {
	      showDebug(1, "No space left -> cannot create file [%s]\n",
                 m_szSpaceFilename);
	      THROW(ERR_CREATESPACEFILENOSPC, szPathDir);
    	    }
          else if (errno == EACCES)
            {
              showDebug(1, "Permission denied -> cannot create file [%s]\n",
                 m_szSpaceFilename);
	      THROW(ERR_CREATESPACEFILEDENIED, szPathDir);
    	    }
          else
	    {
	      showDebug(1, "Cannot create SpaceFile[%s]\n", m_szSpaceFilename); 
	      THROW(ERR_CREATESPACEFILE, m_szSpaceFilename);
	    }
        }
    }

  if (strcmp(m_szImageFilename, "stdout"))
    {
      errno = 0;
      flags = O_CREAT | O_WRONLY | O_NOFOLLOW;
    #ifdef OS_LINUX
      flags |= O_LARGEFILE;
    #endif
      if (m_options.bOverwrite != true)
        flags |= O_EXCL;

    #ifdef HAVE_OPEN64
      m_nImageFd = open64(m_szImageFilename, flags, S_IREAD | S_IWRITE);
    #else
      m_nImageFd = open(m_szImageFilename, flags, S_IREAD | S_IWRITE);
    #endif
      if ((m_nImageFd == -1))
	  {
        if (errno == EEXIST)
          THROW(ERR_EXIST);
        else
          THROW(ERR_ERRNO, errno);
	  }
      // ---- avoid RACE CONDITIONS security problems:
    #ifdef HAVE_FSTAT64
      if (fstat64(m_nImageFd, &fStat) == -1)
    #else
      if (fstat(m_nImageFd, &fStat) == -1)
    #endif
        THROW(ERR_ERRNO, errno);
  
      if (!S_ISREG(fStat.st_mode)) // not a regular file
        THROW(ERR_NOTAREGULARFILE, m_szImageFilename);

      // lock the image file
      if (lockImage(LOCK_EX, m_nImageFd, m_szImageFilename) == -1)
        THROW(ERR_LOCKED, m_szImageFilename);

/* FIXME: this fails when using LUFS. Is it required?
      // truncate the file (now, we can because it's not a symlink)
      if (ftruncate(m_nImageFd, 0L) == -1)
        THROW(ERR_ERRNO, errno);
*/

      showDebug(1, "open std\n");
      m_fImageFile = fdopen(m_nImageFd, "wb");
      if (m_fImageFile == NULL)
        {
          showDebug(1, "error:%d %s\n", errno, strerror(errno));
          THROW(ERR_ERRNO, errno);
        }
    }
  else // it's stdout
    {
      m_fImageFile = stdout;
      showDebug(1, "image will be on stdout\n");
    }

  m_bIsOpened = true;
  m_qwVolSize = 0LL;

  showDebug(1, "end of CImageDisk::openWriting(), return = ok\n");
}
Esempio n. 12
0
// =======================================================
// may throw ERR_OPENED, ERR_NOTFOUND, errno, comp
void CImageDisk::openReading() // [Main-Thread]
{
  //int nRes;
#ifdef HAVE_FSTAT64
  struct stat64 fStat;
#else
  struct stat fStat;
#endif

  BEGIN;
  showDebug(1, "ALREADY=%llu\n", m_qwTotal);
  m_qwTotal=0LL;
  if (m_bIsOpened == true)
    THROW(ERR_OPENED);

  if (strcmp(m_szImageFilename, "stdin"))
    {
      // check the file exists
      errno = 0;
      if (access(m_szImageFilename, F_OK) == -1) // if the file doesn't exists
        THROW(ERR_NOTFOUND);
  
      showDebug(1, "openReading[%s]\n", m_szImageFilename);

    #ifdef OS_LINUX
      #ifdef HAVE_OPEN64
        m_nImageFd = open64(m_szImageFilename, O_RDONLY | O_LARGEFILE | O_NOFOLLOW);
      #else
        m_nImageFd = open(m_szImageFilename, O_RDONLY | O_LARGEFILE | O_NOFOLLOW);
      #endif
    #endif
    #ifdef OS_FBSD
      m_nImageFd = open(m_szImageFilename, O_RDONLY | O_NOFOLLOW);
    #endif
      if (m_nImageFd == -1)
        THROW(ERR_ERRNO, errno);
      else 
        showDebug(1, "preopen successfull for %s\n", m_szImageFilename);

      // ---- avoid RACE CONDITIONS security problems:
      errno = 0;
    #ifdef HAVE_FSTAT64
      if (fstat64(m_nImageFd, &fStat) == -1)
    #else
      if (fstat(m_nImageFd, &fStat) == -1)
    #endif
        {
          showDebug(1, "fstat() returned -1 and errno=%d=[%s]\n", errno, strerror(errno));
          THROW(ERR_ERRNO, errno);
        }

      if (!S_ISREG(fStat.st_mode)) // not a regular file
        THROW(ERR_NOTAREGULARFILE, m_szImageFilename); //BIGH
  
      // ---- lock the image file
      if (lockImage(LOCK_SH, m_nImageFd, m_szImageFilename) == -1)
        THROW(ERR_LOCKED, m_szImageFilename);
  
      m_fImageFile = fdopen(m_nImageFd, "rb");
      if (m_fImageFile == NULL)
        THROW( errno);
      else
        showDebug(1, "open\n");
      showDebug(1, "file %s opened ok\n", m_szImageFilename);
    } // stdin?
  else
    { 
      m_fImageFile = stdin;
      showDebug(1, "stdin opened for reading\n");
    }
	
  m_bIsOpened = true;
}