//====================================================================== // Copyright (C) 2002 Daniel Heck // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. //====================================================================== #ifndef PX_VIDEO_HH_INCLUDED #define PX_VIDEO_HH_INCLUDED #include "pxfwd.hh" #include "drawable.hh" #include "SDL.h" //---------------------------------------- // Colors //---------------------------------------- namespace px { struct RGBA_Mask { RGBA_Mask(Uint32 rr=0, Uint32 gg=0, Uint32 bb=0, Uint32 aa=0) : r(rr), g(gg), b(bb), a(aa) {} Uint32 r,g,b,a; }; struct RGB { RGB(char rr=0, char gg=0, char bb=0) : r(rr), g(gg), b(bb) {} char r,g,b; }; struct RGBA { RGBA(char rr=0, char gg=0, char bb=0, char aa=0) : r(rr), g(gg), b(bb), a(aa) {} char r,g,b,a; }; } namespace px { class FrameBuffer { public: FrameBuffer (SDL_Surface *s) : m_surface(s), m_pitch(m_surface->pitch) {} virtual ~FrameBuffer() { SDL_FreeSurface(m_surface); } void* scanline_pointer(int y); void* pixel_pointer(int x, int y); void lock(); void unlock(); Uint32 map_color(int r, int g, int b, int a); Uint32 map_color(int r, int g, int b); void blit(int x, int y, Surface* s); void blit(int x, int y, Surface* s, const Rect& r); Uint32 pitch() const { return m_pitch; } int bypp() const { return m_surface->format->BytesPerPixel; } int bipp() const { return m_surface->format->BitsPerPixel; } SDL_Surface* get_surface() const { return m_surface; } int width() const { return m_surface->w; } int height() const { return m_surface->h; } Rect size() const { return Rect(0,0,m_surface->w, m_surface->h); } private: SDL_Surface *m_surface; Uint32 m_pitch; FrameBuffer(const FrameBuffer &); FrameBuffer& operator=(const FrameBuffer &); }; inline void* FrameBuffer::scanline_pointer(int y) { return (Uint8*)m_surface->pixels + y*pitch(); } inline void* FrameBuffer::pixel_pointer(int x, int y) { return static_cast(scanline_pointer(y)) + x*bypp(); } } //---------------------------------------- // Surface //---------------------------------------- namespace px { class Surface : public FrameBuffer { public: // Constructor. Surface (SDL_Surface* sfc); virtual ~Surface(); void set_color_key (int r, int g, int b); void set_alpha (int a); px::Drawable *get_drawable() { return drawable; } private: px::Drawable *drawable; }; } //---------------------------------------- // Screen //---------------------------------------- namespace px { class Screen : public Surface { public: Screen(SDL_Surface *s); void update_all(); void update_rect(const Rect& r); void flush_updates(); void set_caption(const char* str); private: RectList m_dirtyrects; bool update_all_p; Screen(const Screen&); Screen& operator=(const Screen&); }; } //---------------------------------------- // Functions //---------------------------------------- namespace px { Screen *OpenScreen (int w, int h, int bipp); Screen* DisplayFormat(Screen* s); Surface *MakeSurface(int w, int h, int bipp, const RGBA_Mask &mask = RGBA_Mask()); void TintRect(Surface *s, Rect rect, Uint8 r, Uint8 g, Uint8 b, Uint8 a); /* Create a surface from image data that is already somewhere in memory. */ Surface * MakeSurface(void* data, int w, int h, int bipp, int pitch, const RGBA_Mask &mask = RGBA_Mask()); Surface *Duplicate(Surface *s); Surface *Grab(Surface *s, Rect r); Surface* DisplayFormat(Surface* s); Surface* LoadImage(const char* filename); } #endif /* !PX_VIDEO_HH_INCLUDED */