diff options
author | Mohamed Waheed <mohamedwaheedmohamed@gmail.com> | 2014-06-24 01:35:05 +0300 |
---|---|---|
committer | Mohamed Waheed <mohamedwaheedmohamed@gmail.com> | 2014-06-24 01:35:05 +0300 |
commit | 613e1d74c47cf3a756af9aff75575c7567699381 (patch) | |
tree | c0cd765cf6983c9be95b81e2aeefeadece9d2b27 /src/common/image.cpp | |
parent | 99cd015dd89f0928246d1178c5641ebe325fe997 (diff) | |
download | colobot-613e1d74c47cf3a756af9aff75575c7567699381.tar.gz colobot-613e1d74c47cf3a756af9aff75575c7567699381.tar.bz2 colobot-613e1d74c47cf3a756af9aff75575c7567699381.zip |
implemented savefile screenshot feature
Diffstat (limited to 'src/common/image.cpp')
-rw-r--r-- | src/common/image.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/common/image.cpp b/src/common/image.cpp index 8a876e3..ff5e42c 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -418,3 +418,43 @@ bool CImage::SavePNG(const std::string& fileName) return true; } +void CImage::SetDataPixels(void *pixels){ + + if (m_data != nullptr){ + + if (m_data->surface != nullptr) + { + if ( m_data->surface->pixels != nullptr ){ + unsigned int* pixels = static_cast<unsigned int*>(m_data->surface->pixels); + delete [] pixels; + m_data->surface->pixels = nullptr; + } + } + } + + m_data->surface->pixels = pixels; +} + +void CImage::flipVertical(){ + + SDL_Surface* result = SDL_CreateRGBSurface(m_data->surface->flags, m_data->surface->w, m_data->surface->h, + m_data->surface->format->BytesPerPixel * 8, m_data->surface->format->Rmask, m_data->surface->format->Gmask, + m_data->surface->format->Bmask, m_data->surface->format->Amask); + + assert(result != nullptr); + + Uint8* srcPixels = static_cast<Uint8*> (m_data->surface->pixels); + Uint8* resultPixels = static_cast<Uint8*> (result->pixels); + + Uint32 pitch = m_data->surface->pitch; + Uint32 pxLength = pitch*m_data->surface->h; + + for(int line = 0; line < m_data->surface->h; ++line) { + Uint32 pos = line * pitch; + memcpy(&resultPixels[pos], &srcPixels[(pxLength-pos)-pitch], pitch); + } + + SDL_FreeSurface(m_data->surface); + + m_data->surface = result; +}
\ No newline at end of file |