From 613e1d74c47cf3a756af9aff75575c7567699381 Mon Sep 17 00:00:00 2001 From: Mohamed Waheed Date: Tue, 24 Jun 2014 01:35:05 +0300 Subject: implemented savefile screenshot feature --- src/common/image.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/common/image.cpp') 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(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 (m_data->surface->pixels); + Uint8* resultPixels = static_cast (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 -- cgit v1.2.3-1-g7c22 From b7125a5b24bc6d2581bec0d3f792ba948e0e7edd Mon Sep 17 00:00:00 2001 From: Mohamed Waheed Date: Tue, 24 Jun 2014 20:27:31 +0300 Subject: formatting and enhancements for savefile screenshot feature --- src/common/image.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/common/image.cpp') 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(m_data->surface->pixels); - delete [] pixels; - m_data->surface->pixels = nullptr; - } - } + Uint8* srcPixels = static_cast (pixels); + Uint8* resultPixels = static_cast (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); -- cgit v1.2.3-1-g7c22