summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorMohamed Waheed <mohamedwaheedmohamed@gmail.com>2014-06-24 20:27:31 +0300
committerMohamed Waheed <mohamedwaheedmohamed@gmail.com>2014-06-24 20:27:31 +0300
commitb7125a5b24bc6d2581bec0d3f792ba948e0e7edd (patch)
tree4770e1157e82b584611560b4f43a506571a88397 /src/common
parent613e1d74c47cf3a756af9aff75575c7567699381 (diff)
downloadcolobot-b7125a5b24bc6d2581bec0d3f792ba948e0e7edd.tar.gz
colobot-b7125a5b24bc6d2581bec0d3f792ba948e0e7edd.tar.bz2
colobot-b7125a5b24bc6d2581bec0d3f792ba948e0e7edd.zip
formatting and enhancements for savefile screenshot feature
Diffstat (limited to 'src/common')
-rw-r--r--src/common/image.cpp33
-rw-r--r--src/common/image.h2
2 files changed, 18 insertions, 17 deletions
diff --git a/src/common/image.cpp b/src/common/image.cpp
index ff5e42c..e3d1ef7 100644
--- a/src/common/image.cpp
+++ b/src/common/image.cpp
@@ -420,26 +420,27 @@ bool CImage::SavePNG(const std::string& fileName)
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;
- }
- }
+ 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);
}
-
- m_data->surface->pixels = pixels;
}
-void CImage::flipVertical(){
+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);
+ 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);
diff --git a/src/common/image.h b/src/common/image.h
index afbebc2..b93f2f9 100644
--- a/src/common/image.h
+++ b/src/common/image.h
@@ -110,7 +110,7 @@ public:
std::string GetError();
//! Flips the image vertically
- void flipVertical();
+ void flipVertically();
//! sets/replaces the pixels from the surface
void SetDataPixels(void *pixels);