formatting and enhancements for savefile screenshot feature

dev-mp
Mohamed Waheed 2014-06-24 20:27:31 +03:00
parent 613e1d74c4
commit b7125a5b24
5 changed files with 24 additions and 27 deletions

View File

@ -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);

View File

@ -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);

View File

@ -428,7 +428,7 @@ bool CEngine::WriteScreenShot(const std::string& fileName, int width, int height
CImage img({width,height});
img.SetDataPixels(pixels);
img.flipVertical();
img.flipVertically();
if ( img.SavePNG(fileName.c_str()) ){
GetLogger()->Info("Save SceenShot Saved Successfully!\n");

View File

@ -1793,17 +1793,13 @@ FillMode CGLDevice::GetFillMode()
void* CGLDevice::GetFrameBufferPixels()const{
SDL_Surface* surface = SDL_GetVideoSurface();
assert(surface != nullptr);
GLubyte* pixels = new GLubyte [4 * surface->h * surface->w];
GLubyte* pixels = new GLubyte [4 * m_config.size.x * m_config.size.y];
glReadPixels(0,0,surface->w,surface->h,GL_RGBA,GL_UNSIGNED_BYTE,pixels);
glReadPixels(0, 0, m_config.size.x, m_config.size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
unsigned int* p = static_cast<unsigned int*> ( static_cast<void*>(pixels) );
for (int i = 0; i < surface->h * surface->w; ++i)
for (int i = 0; i < m_config.size.x * m_config.size.y; ++i)
p[i] |= 0xFF000000;
return static_cast<void*>(p);

View File

@ -2076,9 +2076,9 @@ bool CMainDialog::EventProcess(const Event &event)
m_shotDelay --;
if ( m_shotDelay == 0 )
{
Math::IntPoint screenSize = m_app->GetVideoConfig().size;
Math::IntPoint windowSize = m_engine->GetWindowSize();
m_engine->WriteScreenShot(m_shotName, screenSize.x, screenSize.y);
m_engine->WriteScreenShot(m_shotName, windowSize.x, windowSize.y);
}
}