- Your Widget Set For OpenGL
Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Related Pages

uimageio.hpp

00001 /*************************************************************************** 00002 LibUFO - UI For OpenGL 00003 copyright : (C) 2001-2005 by Johannes Schmidt 00004 email : schmidtjf at users.sourceforge.net 00005 ------------------- 00006 00007 file : include/ufo/image/uimageio.hpp 00008 begin : Fri Oct 5 2001 00009 $Id: uimageio.hpp,v 1.11 2005/05/21 15:17:23 schmidtjf Exp $ 00010 ***************************************************************************/ 00011 00012 /*************************************************************************** 00013 * This library is free software; you can redistribute it and/or * 00014 * modify it under the terms of the GNU Lesser General Public * 00015 * License as published by the Free Software Foundation; either * 00016 * version 2.1 of the License, or (at your option) any later version. * 00017 * * 00018 * This library is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00021 * Lesser General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU Lesser General Public * 00024 * License along with this library; if not, write to the Free Software * 00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 00026 ***************************************************************************/ 00027 00028 #ifndef UIMAGEIO_HPP 00029 #define UIMAGEIO_HPP 00030 00031 #include "../uobject.hpp" 00032 00033 #include "../util/udimension.hpp" 00034 00035 #include <vector> 00036 #include <map> 00037 00038 #include <fstream> 00039 00040 namespace ufo { 00041 00042 00056 class UFO_EXPORT UImageIO : public UObject { 00057 UFO_DECLARE_DYNAMIC_CLASS(UImageIO) 00058 public: // Public types 00059 00060 typedef std::istream IStream; 00061 typedef std::ostream OStream; 00062 00063 typedef unsigned char * (*LoadFuncPointer)( 00064 UImageIO * imageIOA, // image io which should contain the image 00065 IStream & streamA, // the stream to load from 00066 std::string * commentA, // a comment 00067 int * widthA, // the width in pixels 00068 int * heightA, // the height in pixels 00069 int * componentsA // the amount of color components (1..4) 00070 ); 00071 00072 typedef bool (*SaveFuncPointer) ( 00073 UImageIO * imageIO, // image io which contains the image 00074 OStream & streamA // the stream to save to 00075 ); 00077 enum FilterRule { 00078 NoFilterRule = 0, 00079 AlphaLayer = 1, // add an alpha layer 00080 ColorTypeRGB = 2, 00081 ColorTypeRGBA = ColorTypeRGB | AlphaLayer, 00082 ColorTypeGray = 4, 00083 ColorTypeGrayAlpha = ColorTypeGray | AlphaLayer, 00084 FlipX = 8, 00085 FlipY = 16 00086 }; 00087 00088 /* 00089 enum ColorType { 00090 Alpha, 00091 Red, 00092 Green, 00093 Blue, 00094 Luminance, 00095 LuminanceAlpha, 00096 RGB, 00097 BGR, 00098 RGBA, 00099 BGRA 00100 };*/ 00101 00102 public: // c'tors 00105 UImageIO(); 00110 UImageIO(const std::string & fileNameA); 00117 UImageIO(IStream & streamA, const std::string & extensionA); 00120 UImageIO(unsigned char * dataA, int widthA, int heightA, int componentsA); 00124 UImageIO(int widthA, int heightA, int componentsA); 00125 virtual ~UImageIO(); 00126 00127 00128 public: // general accessors 00137 unsigned char * getPixels(); 00138 00139 int getWidth(); 00140 int getHeight(); 00141 const UDimension & getSize(); 00142 00144 std::string getComment(); 00145 00154 int getImageComponents(); 00155 00156 public: // Image loading methods 00157 00161 bool load(const std::string & fileNameA); 00162 00168 bool loadFromArchive(const std::string & fileNameA); 00169 00177 bool load(UImageIO::IStream & streamA, const std::string & extensionA); 00178 //bool load(std::basic_istream<unsigned char> & streamA, 00179 // std::string extensionA); 00180 00181 00182 public: // Image saving methods 00183 00190 bool save(const std::string & fileNameA); 00198 bool save(UImageIO::OStream & streamA, const std::string & extensionA); 00199 00200 public: // filter rules 00211 //void setFilterRule(UImageIO::FilterRule filterRule); 00215 //UImageIO::FilterRule getFilterRule(); 00216 00217 00222 //void apply(); 00223 00224 public: // Public static methods 00228 static std::vector<std::string> getAvailableLoadingExtensions(); 00240 static UImageIO::LoadFuncPointer registerLoader( 00241 UImageIO::LoadFuncPointer loaderA, 00242 const std::string & extensionA); 00247 static void unregisterLoader(UImageIO::LoadFuncPointer saverA, 00248 const std::string & extensionA); 00249 00250 00254 static std::vector<std::string> getAvailableSavingExtensions(); 00266 static UImageIO::SaveFuncPointer registerSaver(UImageIO::SaveFuncPointer saverA, 00267 const std::string & extensionA); 00272 static void unregisterSaver(UImageIO::SaveFuncPointer saverA, 00273 const std::string & extensionA); 00274 00278 static void init(); 00279 00280 protected: // Overrides UObject 00281 virtual std::ostream & paramString(std::ostream & os) const; 00282 00283 public: // Public attributes 00284 00285 static const int ALPHA_LAYER; 00286 00287 static const int COLOR_TYPE_RGB; 00290 static const int COLOR_TYPE_RGB_ALPHA; 00291 00292 static const int COLOR_TYPE_GRAY; 00293 00296 static const int COLOR_TYPE_GRAY_ALPHA; 00297 00298 static const int FLIP_X; 00299 static const int FLIP_Y; 00300 00301 private: // Private attributes 00302 std::string m_comment; 00303 unsigned char * m_data; 00304 UDimension m_size; 00305 int m_components; 00306 //FilterRule m_filterRule; 00307 00308 typedef std::map<std::string, LoadFuncPointer> LoadMap_t; 00309 typedef std::map<std::string, SaveFuncPointer> SaveMap_t; 00310 static LoadMap_t m_loadFuncs; 00311 static SaveMap_t m_saveFuncs; 00312 }; 00313 00314 } // namespace ufo 00315 00316 #endif // UIMAGEIO_HPP

The libUFO Project - written by Johannes Schmidt