diff options
author | Piotr Dziwiński <piotrdz@gmail.com> | 2014-06-24 19:42:25 +0200 |
---|---|---|
committer | Piotr Dziwiński <piotrdz@gmail.com> | 2014-06-24 19:42:25 +0200 |
commit | ae13e0a62121d7fc8fa5ec5769ea5e7125443146 (patch) | |
tree | e2d5883e04bd01342f51d6457a130d663fc5eafd /src/common | |
parent | 52cf9e2815688481f689e03e67c5fc983ed1351b (diff) | |
parent | f5ba2a27d4422401317d814c60048121f9804429 (diff) | |
download | colobot-ae13e0a62121d7fc8fa5ec5769ea5e7125443146.tar.gz colobot-ae13e0a62121d7fc8fa5ec5769ea5e7125443146.tar.bz2 colobot-ae13e0a62121d7fc8fa5ec5769ea5e7125443146.zip |
Merge pull request #304 from MohamedWaheed/dev
Savefile screenshot implementation and screenshot loading bug fix
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/image.cpp | 41 | ||||
-rw-r--r-- | src/common/image.h | 6 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/common/image.cpp b/src/common/image.cpp index 8a876e3..e3d1ef7 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -418,3 +418,44 @@ bool CImage::SavePNG(const std::string& fileName) return true; } +void CImage::SetDataPixels(void *pixels){ + + Uint8* srcPixels = static_cast<Uint8*> (pixels); + Uint8* resultPixels = static_cast<Uint8*> (m_data->surface->pixels); + + Uint32 pitch = m_data->surface->pitch; + + for(int line = 0; line < m_data->surface->h; ++line) { + Uint32 pos = line * pitch; + memcpy(&resultPixels[pos], &srcPixels[pos], pitch); + } +} + +void CImage::flipVertically(){ + + 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 diff --git a/src/common/image.h b/src/common/image.h index 31dab2d..b93f2f9 100644 --- a/src/common/image.h +++ b/src/common/image.h @@ -109,6 +109,12 @@ public: //! Returns the last error std::string GetError(); + //! Flips the image vertically + void flipVertically(); + + //! sets/replaces the pixels from the surface + void SetDataPixels(void *pixels); + private: //! Blit to new RGBA surface with given size void BlitToNewRGBASurface(int width, int height); |