Skip to content

Commit

Permalink
Allow creating BlockData with no backing storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfpld committed Mar 5, 2014
1 parent 1bc0e1f commit 84ad2e4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
22 changes: 20 additions & 2 deletions BlockData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,29 @@ BlockData::BlockData( const char* fn, const v2i& size )
m_data = OpenForWriting( fn, m_maplen, m_size, &m_file );
}

BlockData::BlockData( const v2i& size )
: m_size( size )
, m_done( false )
, m_dataOffset( 52 )
, m_file( nullptr )
, m_maplen( 52 + m_size.x*m_size.y/2 )
{
assert( m_size.x%4 == 0 && m_size.y%4 == 0 );
m_data = new uint8[m_maplen];
}

BlockData::~BlockData()
{
if( !m_done ) Finish();
munmap( m_data, m_maplen );
fclose( m_file );
if( m_file )
{
munmap( m_data, m_maplen );
fclose( m_file );
}
else
{
delete[] m_data;
}
}

void BlockData::Process( const uint8* src, uint32 blocks, size_t offset, uint quality, Channels type )
Expand Down
1 change: 1 addition & 0 deletions BlockData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class BlockData
BlockData( const char* fn );
BlockData( const char* fn, const BlockBitmapPtr& bitmap, uint quality );
BlockData( const char* fn, const v2i& size );
BlockData( const v2i& size );
~BlockData();

BitmapPtr Decode();
Expand Down

0 comments on commit 84ad2e4

Please sign in to comment.