Ejemplo n.º 1
0
MemStream::MemStream(const MemStream &s)
{
    _pos = 0;
    _len = s.len();
    _maxLen = _len;
    _data = new unsigned char[_len];
    memcpy(_data, s.data(), _len);
}
Ejemplo n.º 2
0
bool AtlasChunk::readFromStream(AtlasChunk *ac, Stream *s)
{
   // First, read the size and allocate a buffer.
   
   // Let's do a sentinel check.
   U32 sent1;
   s->read(&sent1);
   AssertISV(sent1 == MakeFourCC('A', 'T', 'S', 'P'), "AtlasChunk::readFromStream - (sent1) invalid chunk master sentinel!");

   s->read(&ac->mChunkSize);

   // And now validate the chunk-type-sentinel.
   U32 sent2;
   s->read(&sent2);
   AssertISV(sent2 == ac->getHeadSentinel(), "AtlasChunk::readFromStream - (sent2) invalid chunk head sentinel!");

   // Get the chunk's data.  If it's already in memory, just reuse it.
   // Otherwise read it from the stream.

   bool isMemStream = false;
   U8 *data;
   U32 dataSize = ac->mChunkSize;
   
   if( dynamic_cast< MemStream* >( s ) )
   {
	   MemStream* memStream = ( MemStream* ) s;
	   U32 currentPos = memStream->getPosition();
	   isMemStream = true;
	   data = &( ( U8* ) memStream->getBuffer() )[ currentPos ];
	   memStream->setPosition( currentPos + dataSize );
   }
   else
   {
	   data = new U8[ dataSize ];

	   // Read next chunksize bytes into the buffer for later processing.
	   s->read( dataSize, data);
   }

   // Check end sentinel.
   U32 sent3;
   s->read(&sent3);
   AssertISV(sent3 == ac->getTailSentinel(), "AtlasChunk::readFromStream - (sent3) invalid chunk tail sentinel!");

   // And tell the chunk to read from that buffer...
   MemStream dataStream( dataSize, data );
   ac->read(&dataStream);

   // Clean up memory.
   if( !isMemStream )
	   delete[] data;

   // All done!
   return true;
}
Ejemplo n.º 3
0
    virtual void  Serialize(MemStream::Mode mode,
                            MemStream &buff,
                            avtIVPSolver *solver,
                            SerializeFlags serializeFlags)
    {
        // Have the base class serialize its part
        avtStateRecorderIntegralCurve::Serialize(mode, buff, solver, serializeFlags);

        buff.io(mode, numSteps);
        buff.io(mode, maxSteps);
        buff.io(mode, terminatedBecauseOfMaxSteps);
    }
    virtual void Serialize(MemStream::Mode mode, MemStream &buff,
                                avtIVPSolver *solver)

    {
        avtIntegralCurve::Serialize(mode, buff, solver);
        buff.io(mode, dist);
        buff.io(mode, idx[0]);
        buff.io(mode, idx[1]);
        buff.io(mode, last_loc[0]);
        buff.io(mode, last_loc[1]);
        buff.io(mode, numSteps);
    }
Ejemplo n.º 5
0
bool preflate_decode(std::vector<unsigned char>& unpacked_output,
                     std::vector<unsigned char>& preflate_diff,
                     uint64_t& deflate_size,
                     InputStream& deflate_raw,
                     std::function<void(void)> block_callback,
                     const size_t min_deflate_size,
                     const size_t metaBlockSize) {
  MemStream uncompressedOutput;
  bool result = preflate_decode(uncompressedOutput, preflate_diff, deflate_size, deflate_raw,
                                block_callback, min_deflate_size, metaBlockSize);
  unpacked_output = uncompressedOutput.extractData();
  return result;
}
Ejemplo n.º 6
0
	SYSCALL(int, maCreateData(MAHandle placeholder, int size)) {
#ifndef _android
		MemStream* ms = new MemStream(size);
#else
		char* b = SYSCALL_THIS->loadBinary(placeholder, size);
		if(b == NULL) return RES_OUT_OF_MEMORY;
		
		MemStream* ms = new MemStream(b, size);
#endif
		if(ms == 0) return RES_OUT_OF_MEMORY;
		if(ms->ptr()==0) { delete ms; return RES_OUT_OF_MEMORY; }

		return SYSCALL_THIS->resources.add_RT_BINARY(placeholder, ms);
	}
Ejemplo n.º 7
0
/*--------------------------------------------------------------testMemStream-+
|                                                                             |
+----------------------------------------------------------------------------*/
int testMemStream()
{
   int rc = 987654321;
   int const maxOutputSize = 7;
   cout << "--------------- testMemStream" << endl;
   MemStream rcAsString;
   rcAsString << "rc=" << rc;
   if (rcAsString.rdbuf()->in_avail() > maxOutputSize) {
      rcAsString.seekp(maxOutputSize);
      rcAsString << "...";
   }
   rcAsString << endl;
   cout << rcAsString.rdbuf();
   return 0;
}
Ejemplo n.º 8
0
void Map_ImportBuffer( char *buf ){
	Select_Deselect();

	Undo_Start( "import buffer" );

	MemStream stream;

	stream.Write( buf, strlen( buf ) );
	Map_Import( &stream, "xmap" );
	stream.Close();

	Sys_UpdateWindows( W_ALL );
	Sys_MarkMapModified();

	Undo_End();
}
Ejemplo n.º 9
0
// ****************************************************************************
//  Method: avtLCSIC::Serialize
//
//  Purpose:
//      Serializes a LCS so it can be sent to another processor.
//
//  Programmer: Allen Sanderson
//  Creation:   August 14, 2013
//
//  Modifications:
//
// ****************************************************************************
void avtLCSIC::Serialize(MemStream::Mode mode, MemStream &buff,
                          avtIVPSolver *solver, SerializeFlags serializeFlags)
{
    avtIntegralCurve::Serialize(mode,buff,solver,serializeFlags);

    buff.io(mode, numSteps);
    buff.io(mode, maxSteps);
    buff.io(mode, doDistance);
    buff.io(mode, maxDistance);
    buff.io(mode, doTime);
    buff.io(mode, maxTime);
    buff.io(mode, distance);
    buff.io(mode, terminatedBecauseOfMaxSteps);
    buff.io(mode, p_start);
    buff.io(mode, p_end);
}
void
avtStateRecorderIntegralCurve::Serialize(MemStream::Mode mode, MemStream &buff, 
                                         avtIVPSolver *solver, SerializeFlags serializeFlags)
{
    // Have the base class serialize its part
    avtIntegralCurve::Serialize(mode, buff, solver, serializeFlags);

    buff.io(mode, distance);

    buff.io(mode, historyMask);
    unsigned long saveSerializeFlags = serializeFlags | _serializeFlags;
    buff.io(mode, saveSerializeFlags);

    if (DebugStream::Level5())
    {
        debug5<<"  avtStateRecorderIntegralCurve::Serialize "<<(mode==MemStream::READ?"READ":"WRITE")<<" saveSerializeFlags= "<<saveSerializeFlags<<endl;
    }
    // R/W the steps.
    if (saveSerializeFlags & SERIALIZE_STEPS)
        buff.io(mode, history);

    if (saveSerializeFlags & SERIALIZE_INC_SEQ)
    {
        if (mode == MemStream::WRITE)
        {
            long seqCnt = sequenceCnt+1;
            buff.io(mode, seqCnt);
        }
        else
            buff.io(mode, sequenceCnt);
    }
    else
        buff.io(mode, sequenceCnt);

    if (DebugStream::Level5())
    {
        debug5 << "DONE: avtStateRecorderIntegralCurve::Serialize. sz= "<<buff.len() << endl;
    }
}
Ejemplo n.º 11
0
//--------------------------------------------------------------------------
static bool sWritePNG(GBitmap *bitmap, Stream &stream, U32 compressionLevel)
{
   U32 waterMark = FrameAllocator::getWaterMark();

   if ( compressionLevel < 10 )
   {
      bool retVal = _writePNG(bitmap, stream, compressionLevel, 0, PNG_ALL_FILTERS);
      FrameAllocator::setWaterMark(waterMark);
      return retVal;
   }

   // check all our methods of compression to find the best one and use it
   U8* buffer = new U8[1 << 22]; // 4 Megs.  Should be enough...
   MemStream* pMemStream = new MemStream(1 << 22, buffer, false, true);

   const U32 zStrategies[] = { Z_DEFAULT_STRATEGY,
      Z_FILTERED };
   const U32 pngFilters[]  = { PNG_FILTER_NONE,
      PNG_FILTER_SUB,
      PNG_FILTER_UP,
      PNG_FILTER_AVG,
      PNG_FILTER_PAETH,
      PNG_ALL_FILTERS };

   U32 minSize      = 0xFFFFFFFF;
   U32 bestStrategy = 0xFFFFFFFF;
   U32 bestFilter   = 0xFFFFFFFF;
   U32 bestCLevel   = 0xFFFFFFFF;

   for (U32 cl = 0; cl <=9; cl++) 
   {
      for (U32 zs = 0; zs < 2; zs++) 
      {
         for (U32 pf = 0; pf < 6; pf++) 
         {
            pMemStream->setPosition(0);

            U32 waterMarkInner = FrameAllocator::getWaterMark();

            if (_writePNG(bitmap, *pMemStream, cl, zStrategies[zs], pngFilters[pf]) == false)
               AssertFatal(false, "Handle this error!");

            FrameAllocator::setWaterMark(waterMarkInner);

            if (pMemStream->getPosition() < minSize) 
            {
               minSize = pMemStream->getPosition();
               bestStrategy = zs;
               bestFilter   = pf;
               bestCLevel   = cl;
            }
         }
      }
   }
   AssertFatal(minSize != 0xFFFFFFFF, "Error, no best found?");

   delete pMemStream;
   delete [] buffer;


   bool retVal = _writePNG(bitmap, stream,
      bestCLevel,
      zStrategies[bestStrategy],
      pngFilters[bestFilter]);
   FrameAllocator::setWaterMark(waterMark);

   return retVal;
}
Ejemplo n.º 12
0
void
avtIntegralCurve::Serialize(MemStream::Mode mode, MemStream &buff, 
                            avtIVPSolver *solver, SerializeFlags serializeFlags)
{
    if (DebugStream::Level5())
    {
        debug5 << "  avtIntegralCurve::Serialize "
               << (mode==MemStream::READ?"READ":"WRITE")<<endl;
    }
    buff.io(mode, id);
    buff.io(mode, direction);
    buff.io(mode, blockList);
    buff.io(mode, status);
    buff.io(mode, counter);
    buff.io(mode, originatingRank);
    
    if (solver)
    {
        if (mode == MemStream::WRITE)
        {
            avtIVPState solverState;

            ivp->GetState(solverState);
            solverState.Serialize(mode, buff);
        }
        else
        {
            // TODO:
            //ivp->Serialize( mode, buff );

            avtIVPState solverState;
            solverState.Serialize(mode, buff);

            if (ivp)
                delete ivp;

            ivp = solver->Clone();
            ivp->PutState(solverState);
        }
    }

    
#ifdef USE_IC_STATE_TRACKING
    if (mode == MemStream::WRITE)
    {
        trk<<"Serialize"<<endl;
        trk.close();
    }
    else
    {
        trk<<flush;
        trk.close();
        char tmp[64];
        sprintf(tmp, "IC_%d.txt", (int)id);
        trk.open(tmp, ofstream::app);
        trk<<"De-serialize"<<endl;
    }
#endif

    if (DebugStream::Level5())
    {
        debug5 << "avtIntegralCurve::Serialize() size is " 
               << buff.len() << endl;
    }
}