summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorMohamed Waheed <mohamedwaheedmohamed@gmail.com>2014-06-24 01:35:05 +0300
committerMohamed Waheed <mohamedwaheedmohamed@gmail.com>2014-06-24 01:35:05 +0300
commit613e1d74c47cf3a756af9aff75575c7567699381 (patch)
treec0cd765cf6983c9be95b81e2aeefeadece9d2b27 /src/common
parent99cd015dd89f0928246d1178c5641ebe325fe997 (diff)
downloadcolobot-613e1d74c47cf3a756af9aff75575c7567699381.tar.gz
colobot-613e1d74c47cf3a756af9aff75575c7567699381.tar.bz2
colobot-613e1d74c47cf3a756af9aff75575c7567699381.zip
implemented savefile screenshot feature
Diffstat (limited to 'src/common')
-rw-r--r--src/common/image.cpp40
-rw-r--r--src/common/image.h6
2 files changed, 46 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
diff --git a/src/common/image.h b/src/common/image.h
index 31dab2d..afbebc2 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 flipVertical();
+
+ //! 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);