Пример #1
0
Error Plot::renderFromDisplay()
{
   // we can use our cached representation if we don't need an update and our 
   // rendered size is the same as the current graphics device size
   if ( !needsUpdate_ &&
        (renderedSize() == graphicsDevice_.displaySize()) )
   {
      return Success();
   }
    
   // generate a new storage uuid
   std::string storageUuid = core::system::generateUuid();
   
   // generate snapshot and image files
   Error error = graphicsDevice_.saveSnapshot(snapshotFilePath(storageUuid),
                                              imageFilePath(storageUuid));
   if (error)
      return Error(errc::PlotRenderingError, error, ERROR_LOCATION);
   
   // save rendered size
   renderedSize_ = graphicsDevice_.displaySize();
   
   // save manipulator (if any)
   saveManipulator(storageUuid);

   // delete existing files (if any)
   Error removeError = removeFiles();
        
   // update state
   storageUuid_ = storageUuid;
   needsUpdate_ = false;
   
   // return error status 
   return removeError;
}
bool GraphicsServerCommunication::LoadImageFromDisk(gtString& imageName, unsigned char*& pImageBuffer, unsigned long& imageSize)
{
    bool retVal = false;

    pImageBuffer = nullptr;
    osFilePath imageFilePath(osFilePath::OS_USER_DOCUMENTS);

    imageFilePath.setFileName(imageName);
    imageFilePath.setFileExtension(L"png");

    // load the image and return it in the buffer:
    if (imageFilePath.exists())
    {
        osFile imageFile(imageFilePath);
        bool rc = imageFile.getSize(imageSize);
        GT_IF_WITH_ASSERT(rc)
        {
            rc = imageFile.open(osChannel::OS_BINARY_CHANNEL);
            GT_IF_WITH_ASSERT(rc)
            {
                pImageBuffer = new unsigned char[imageSize];
                rc = imageFile.read((char*)pImageBuffer, imageSize);
                GT_IF_WITH_ASSERT(rc)
                {
                    retVal = true;
                }
                imageFile.close();
            }
        }
    }
Пример #3
0
Plot::Plot(const GraphicsDeviceFunctions& graphicsDevice,
           const FilePath& baseDirPath, 
           const std::string& storageUuid,
           const DisplaySize& renderedSize)
   : graphicsDevice_(graphicsDevice), 
     baseDirPath_(baseDirPath), 
     storageUuid_(storageUuid),
     renderedSize_(renderedSize),
     needsUpdate_(false),
     manipulator_()
{
   // invalidate if the image file doesn't exist (allows the server
   // to migrate between different image backends e.g. png, jpeg, svg)
   if (!imageFilePath(storageUuid_).exists())
      invalidate();
} 
Пример #4
0
Error Plot::removeFiles()
{
   // bail if we don't have any storage
   if (storageUuid_.empty())
      return Success();
   
   Error snapshotError = snapshotFilePath(storageUuid_).removeIfExists();
   Error imageError = imageFilePath(storageUuid_).removeIfExists();
   Error manipulatorError = manipulatorFilePath(storageUuid_).removeIfExists();
   
   if (snapshotError)
      return Error(errc::PlotFileError, snapshotError, ERROR_LOCATION);
   else if (imageError)
      return Error(errc::PlotFileError, imageError, ERROR_LOCATION);
   else if (manipulatorError)
      return Error(errc::PlotFileError, manipulatorError, ERROR_LOCATION);
   else
      return Success();
}
Пример #5
0
std::string Plot::imageFilename() const
{
   return imageFilePath(storageUuid()).filename();
}