/************************************************************************ * Copyright (c) 2005-2007 tok@openlinux.org.uk * * * * This software is provided as-is, without any express or implied * * warranty. In no event will the authors be held liable for any * * damages arising from the use of this software. * * * * Permission is granted to anyone to use this software for any purpose, * * including commercial applications, and to alter it and redistribute * * it freely, subject to the following restrictions: * * * * 1. The origin of this software must not be misrepresented; you must * * not claim that you wrote the original software. If you use this * * software in a product, an acknowledgment in the product documentation * * would be appreciated but is not required. * * * * 2. Altered source versions must be plainly marked as such, and must * * not be misrepresented as being the original software. * * * * 3. This notice may not be removed or altered from any source * * distribution. * ************************************************************************/ #include #include #include #include #ifdef DUMP_DELTA_DEBUG #include #include #include #endif #include "opengta.h" #include "dataholder.h" #include "m_exceptions.h" #include "set.h" SDL_Surface* image = NULL; void at_exit() { if (image) SDL_FreeSurface(image); PHYSFS_deinit(); SDL_Quit(); } void display_image(SDL_Surface* s) { SDL_Surface *screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF); SDL_Event event; SDL_BlitSurface(s, NULL, screen, NULL); SDL_Flip(screen); while (1) { while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: return; case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_ESCAPE) return; default: break; } } SDL_Delay(100); } } SDL_Surface* get_image(unsigned char* rp, unsigned int w, unsigned int h) { #if SDL_BYTEORDER == SDL_BIG_ENDIAN #define rmask 0xff000000 #define gmask 0x00ff0000 #define bmask 0x0000ff00 #define amask 0x000000ff #else #define rmask 0x000000ff #define gmask 0x0000ff00 #define bmask 0x00ff0000 #define amask 0xff000000 #endif SDL_Surface* s = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA, w, h, 32, rmask, gmask, bmask, amask); SDL_LockSurface(s); unsigned char* dst = static_cast(s->pixels); for (unsigned int i=0; iw) << "x" << int(sprite->h) << " with " << int(sprite->deltaCount) << " deltas" << std::endl; image = get_image(graphics.getSpriteBitmap(idx, remap, delta), sprite->w, sprite->h); #ifdef DUMP_DELTA_DEBUG if (delta && !delta_set) { std::cout << "dumping delta" << std::endl; OpenGTA::GraphicsBase::DeltaInfo & dinfo = sprite->delta[delta-1]; int dump_fd = open("delta.raw", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); write(dump_fd, dinfo.ptr, dinfo.size); close(dump_fd); } #endif break; } if (!image) { std::cerr << "Error: image pointer is NULL; aborting" << std::endl; return 1; } if (mode & 1) { display_image(image); } if (mode & 2) { SDL_SaveBMP(image, "out.bmp"); } } catch (Exception & e) { std::cerr << "Exception occured: " << e.what() << std::endl; return 1; } return 0; }