00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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:
00059
00060
typedef std::istream IStream;
00061
typedef std::ostream OStream;
00062
00063
typedef unsigned char * (*LoadFuncPointer)(
00064 UImageIO * imageIOA,
00065 IStream & streamA,
00066 std::string * commentA,
00067
int * widthA,
00068
int * heightA,
00069
int * componentsA
00070 );
00071
00072
typedef bool (*SaveFuncPointer) (
00073 UImageIO * imageIO,
00074 OStream & streamA
00075 );
00077 enum FilterRule {
00078 NoFilterRule = 0,
00079 AlphaLayer = 1,
00080 ColorTypeRGB = 2,
00081 ColorTypeRGBA = ColorTypeRGB | AlphaLayer,
00082 ColorTypeGray = 4,
00083 ColorTypeGrayAlpha = ColorTypeGray | AlphaLayer,
00084 FlipX = 8,
00085 FlipY = 16
00086 };
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
public:
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:
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:
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
00179
00180
00181
00182
public:
00183
00190
bool save(
const std::string & fileNameA);
00198
bool save(UImageIO::OStream & streamA,
const std::string & extensionA);
00199
00200
public:
00211
00215
00216
00217
00222
00223
00224
public:
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:
00281
virtual std::ostream & paramString(std::ostream & os)
const;
00282
00283
public:
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:
00302 std::string m_comment;
00303
unsigned char * m_data;
00304
UDimension m_size;
00305
int m_components;
00306
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 }
00315
00316
#endif // UIMAGEIO_HPP