summaryrefslogtreecommitdiffstats
path: root/src/common/image.cpp
diff options
context:
space:
mode:
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;
+}