Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

pixelformat.h

00001 /* 00002 libwftk - Worldforge Toolkit - a widget library 00003 Copyright (C) 2002 Malcolm Walker <malcolm@worldforge.org> 00004 Based on code copyright (C) 1999-2002 Karsten Laux 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the 00018 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, SA. 00020 */ 00021 // written by Karsten Laux, June 1999 00022 00023 #ifndef _PIXELFORMAT_H_ 00024 #define _PIXELFORMAT_H_ 00025 00026 #include <wftk/color.h> 00027 00028 //just for typedefs ... 00029 #include <SDL/SDL.h> 00030 #include <iosfwd> 00031 #include <string> 00032 00033 namespace wftk { 00034 00046 class Pixelformat 00047 { 00048 public: 00052 enum Format {ABGR8888 , RGBA8888 , ARGB8888 , 00053 BGRA8888 , RGB888 , BGR888 , 00054 RGB0888 , BGR0888 , RGB565 , 00055 RGB555 , IND8 , NUM_FORMATS}; 00057 Pixelformat() : surface_(0), format_(0) {} 00059 Pixelformat(Format format); 00061 Pixelformat(const Pixelformat& other); 00063 00068 Pixelformat(SDL_Surface* surface); 00070 ~Pixelformat(); 00071 00073 operator const SDL_PixelFormat&() const; 00074 00076 Pixelformat& operator=(const Pixelformat& pf); 00078 Pixelformat& operator=(Format); 00079 00081 std::string asString() const; 00083 friend std::ostream& operator<<(std::ostream&, const Pixelformat&); 00085 bool operator==(const Pixelformat& pf) const 00086 {return pf.format_ ? operator==(*pf.format_) : !format_;} 00088 bool operator==(const SDL_PixelFormat&) const; 00090 friend bool operator==(const SDL_PixelFormat& f1, const Pixelformat& f2) 00091 {return f2 == f1;} 00093 bool operator!=(const Pixelformat& pf) const {return !operator==(pf);} 00095 bool operator!=(const SDL_PixelFormat& format) const {return !operator==(format);} 00097 friend bool operator!=(const SDL_PixelFormat& f1, const Pixelformat& f2) 00098 {return !(f2 == f1);} 00100 Uint32 mapToPixel(const Color& col) const; 00102 Color mapToColor(Uint32 pixel) const; 00104 bool valid() const {return format_ != 0;} 00106 const SDL_Palette* getPalette() const {return format_ ? format_->palette : 0;} 00108 Color getColor(unsigned color_num) const; 00109 00111 int bpp() const {return format_ ? format_->BytesPerPixel : 0;} 00113 int bitspp() const {return format_ ? format_->BitsPerPixel : 0;} 00115 Uint32 rMask() const {return format_ ? format_->Rmask : 0;} 00117 Uint32 gMask() const {return format_ ? format_->Gmask : 0;} 00119 Uint32 bMask() const {return format_ ? format_->Bmask : 0;} 00121 Uint32 aMask() const {return format_ ? format_->Amask : 0;} 00122 00124 static Pixelformat displayFormat; 00125 00126 private: 00127 00129 SDL_Surface* surface_; 00131 const SDL_PixelFormat* format_; 00132 }; 00133 00134 } 00135 00136 00137 #endif

Generated Wed Jul 28 17:28:43 2004.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.