Example #1
0
void Snapshotable::Stream(Snapshotable* snapshotable)
{
	stringstream stream;
	if(_saving) {
		snapshotable->SaveSnapshot(&stream);
		uint32_t size = (uint32_t)stream.tellp();
		stream.seekg(0, ios::beg);
		stream.seekp(0, ios::beg);

		uint8_t *buffer = new uint8_t[size];
		stream.read((char*)buffer, size);
		InternalStream(size);
		ArrayInfo<uint8_t> arrayInfo = { buffer, size };
		InternalStream(arrayInfo);
		delete[] buffer;
	} else {
		uint32_t size = 0;
		InternalStream(size);

		uint8_t *buffer = new uint8_t[size];
		ArrayInfo<uint8_t> arrayInfo = { buffer, size };
		InternalStream(arrayInfo);

		stream.write((char*)buffer, size);
		stream.seekg(0, ios::beg);
		stream.seekp(0, ios::beg);
		snapshotable->LoadSnapshot(&stream, _stateVersion);
		delete[] buffer;
	}
}
Example #2
0
void Snapshotable::StreamEndBlock()
{
	_inBlock = false;
	if(_saving) {
		InternalStream(_blockPosition);
		ArrayInfo<uint8_t> arrayInfo = { _blockBuffer, _blockPosition };
		InternalStream(arrayInfo);
	}

	delete[] _blockBuffer;
	_blockBuffer = nullptr;
}
Example #3
0
void Snapshotable::StreamStartBlock()
{
	if(_inBlock) {
		throw new std::runtime_error("Cannot start a new block before ending the last block");
	}

	if(!_saving) {
		InternalStream(_blockSize);
		_blockSize = std::min(_blockSize, (uint32_t)0xFFFFF);
		_blockBuffer = new uint8_t[_blockSize];
		ArrayInfo<uint8_t> arrayInfo = { _blockBuffer, _blockSize };
		InternalStream(arrayInfo);
	} else {
		_blockSize = 0x100;
		_blockBuffer = new uint8_t[_blockSize];
	}
	_blockPosition = 0;
	_inBlock = true;
}
Example #4
0
/// Reads an image cache including images, cursors and colours.
/// @param bBinaryRead if true means read from an external binary file.  
///   otherwise the data is taken from a compiled in block of memory.
/// @param bOkIfNotFound if true means do not report absent file.
/// @return true iff we loaded the images.
bool ThemeBase::ReadImageCache( bool bBinaryRead, bool bOkIfNotFound)
{
   EnsureInitialised();
   wxImage ImageCache;
   wxBusyCursor busy;

   // Ensure we have an alpha channel...
//   if( !ImageCache.HasAlpha() )
//   {
//      ImageCache.InitAlpha();
//   }

   // IF bBinary read THEN a normal read from a PNG file
   if(  bBinaryRead )
   {
      wxString FileName = FileNames::ThemeCachePng();
      if( !wxFileExists( FileName ))
      {  
         if( bOkIfNotFound )
            return false; // did not load the images, so return false.
         wxMessageBox(
            wxString::Format( 
            _("Audacity could not find file:\n  %s.\nTheme not loaded."),
               FileName.c_str() ));
         return false;
      }
      if( !ImageCache.LoadFile( FileName, wxBITMAP_TYPE_PNG ))
      {
         wxMessageBox(
            wxString::Format( 
            _("Audacity could not load file:\n  %s.\nBad png format perhaps?"),
               FileName.c_str() ));
         return false;
      }
   }
   // ELSE we are reading from internal storage.
   else
   {  
      wxMemoryInputStream InternalStream(
         (char *)ImageCacheAsData, sizeof(ImageCacheAsData));
      if( !ImageCache.LoadFile( InternalStream, wxBITMAP_TYPE_PNG ))
      {
         // If we get this message, it means that the data in file
         // was not a valid png image.
         // Most likely someone edited it by mistake, 
         // Or some experiment is being tried with new formats for it.
         wxMessageBox(_("Audacity could not read its default theme.\nPlease report the problem."));
         return false;
      }
   }

   int i;
   mFlow.Init(ImageCacheWidth);
   // Load the bitmaps
   for(i=0;i<(int)mImages.GetCount();i++)
   {
      wxImage &Image = mImages[i];
      mFlow.mFlags = mBitmapFlags[i];
      if( (mBitmapFlags[i] & resFlagInternal)==0)
      {
         mFlow.GetNextPosition( Image.GetWidth(),Image.GetHeight() );
         //      wxLogDebug(wxT("Copy at %i %i (%i,%i)"), mxPos, myPos, xWidth1, yHeight1 );
         Image = GetSubImageWithAlpha( ImageCache, mFlow.Rect());
         mBitmaps[i] = wxBitmap(Image);
      }
   }

//   return true; //To not load colours..
   // Now load the colours.
   int x,y;
   mFlow.SetNewGroup(1);
   wxColour TempColour;
   const int iColSize=10;
   mFlow.myHeight = iColSize+1;
   for(i=0;i<(int)mColours.GetCount();i++)
   {
      mFlow.GetNextPosition( iColSize, iColSize );
      mFlow.RectMid( x, y );
      // Only change the colour if the alpha is opaque.
      // This allows us to add new colours more easily.
      if( ImageCache.GetAlpha(x,y ) > 128 )
      {
         TempColour = wxColour( 
            ImageCache.GetRed( x,y), 
            ImageCache.GetGreen( x,y), 
            ImageCache.GetBlue(x,y));
         /// \todo revisit this hack which makes adding new colours easier
         /// but which prevents a colour of (1,1,1) from being added.
         /// find an alternative way to make adding new colours easier.
         /// e.g. initialise the background to translucent, perhaps.
         if( TempColour != wxColour(1,1,1) )
            mColours[i] = TempColour;
      }
   }
   return true;
}