summaryrefslogtreecommitdiffstats
path: root/src/common/image.cpp
diff options
context:
space:
mode:
authorkrzys-h <krzys_h@interia.pl>2014-07-11 15:24:44 +0200
committerkrzys-h <krzys_h@interia.pl>2014-07-11 15:24:44 +0200
commit96d49d84aafecd78c902681f20de6207badf7e85 (patch)
tree7a835fce4f264c6c0886441c4f79e02cdf47582c /src/common/image.cpp
parent5223ef1fb116780298495a4d2f63e6c2c39fdfbd (diff)
parent852223262055440569ecca70f1b9da46089424c4 (diff)
downloadcolobot-96d49d84aafecd78c902681f20de6207badf7e85.tar.gz
colobot-96d49d84aafecd78c902681f20de6207badf7e85.tar.bz2
colobot-96d49d84aafecd78c902681f20de6207badf7e85.zip
Merge branch 'dev' into dev-physfs
Conflicts: data src/app/gamedata.cpp src/ui/control.cpp src/ui/edit.cpp src/ui/maindialog.cpp
Diffstat (limited to 'src/common/image.cpp')
-rw-r--r--src/common/image.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/common/image.cpp b/src/common/image.cpp
index 9916c8f..dd905a7 100644
--- a/src/common/image.cpp
+++ b/src/common/image.cpp
@@ -428,3 +428,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;
+}