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
00029
00030
00031
00032 #ifndef Image_INCUDE_DEFINE
00033 #define Image_INCUDE_DEFINE
00034
00035 #include <vlCore/String.hpp>
00036 #include <vlCore/Buffer.hpp>
00037 #include <vlCore/Vector4.hpp>
00038 #include <vlCore/vlnamespace.hpp>
00039 #include <vlCore/Rect.hpp>
00040 #include <vlCore/KeyValues.hpp>
00041 #include <vector>
00042
00043 namespace vl
00044 {
00045 class VirtualFile;
00046
00047
00048
00049
00054 class VLCORE_EXPORT Image: public Object
00055 {
00056 Image(const Image& other): Object(other) {}
00057 public:
00058 Image();
00059 Image(const String& path);
00060 Image(int x, int y, int z, int bytealign, EImageFormat format, EImageType type);
00061 virtual const char* className() { return "vl::Image"; }
00062 virtual ~Image();
00063 Image& operator=(const Image& other);
00064 bool isCubemap() const { return mIsCubemap; }
00065 bool isValid() const;
00066 EImageDimension dimension() const;
00067 void allocate();
00068 void allocate1D(int x, EImageFormat format, EImageType type);
00069 void allocate2D(int x, int y, int bytealign, EImageFormat format, EImageType type);
00070 void allocate3D(int x, int y, int z, int bytealign, EImageFormat format, EImageType type);
00071 void allocateCubemap(int x, int y, int bytealign, EImageFormat format, EImageType type);
00072
00073 void reset(int x, int y, int z, int bytealign, EImageFormat format, EImageType type, bool is_cubemap);
00074 void clear();
00075 int byteAlignment() const;
00076 void setByteAlignment(int bytealign);
00077 static int bitsPerPixel(EImageType type, EImageFormat format);
00078 int bitsPerPixel() const { return bitsPerPixel(type(),format()); }
00079 int requiredMemory() const;
00080 static int requiredMemory(int x, int y, int z, int bytealign, EImageFormat format, EImageType type, bool is_cubemap);
00081 static int requiredMemory1D(int x, EImageFormat format, EImageType type) { return requiredMemory(x, 0, 0, 1, format, type, false); }
00082 static int requiredMemory2D(int x, int y, int bytealign, EImageFormat format, EImageType type) { return requiredMemory(x, y, 0, bytealign, format, type, false); }
00083 static int requiredMemory3D(int x, int y, int z, int bytealign, EImageFormat format, EImageType type) { return requiredMemory(x, y, z, bytealign, format, type, false); }
00084 static int requiredMemoryCubemap(int x, int y, int bytealign, EImageFormat format, EImageType type) { return requiredMemory(x, y, 0, bytealign, format, type, true); }
00085 String print() const;
00086 String printType() const;
00087 String printFormat() const;
00088
00089 void setWidth(int x) { mWidth = x; updatePitch(); }
00090 void setHeight(int y) { mHeight = y; }
00091 void setDepth(int z) { mDepth = z; }
00092 void setFormat(EImageFormat format) { mFormat = format; updatePitch(); }
00093 void setType(EImageType type) { mType=type; updatePitch(); }
00094
00097 KeyValues* tags() const { return mTags.get(); }
00098
00100 void setTags(KeyValues* tags) { mTags = tags; }
00101
00103 void setImageBuffer(Buffer* buffer) { mPixels = buffer; }
00104
00106 Buffer* imageBuffer() { return mPixels.get(); }
00107
00109 const Buffer* imageBuffer() const { return mPixels.get(); }
00110
00111 const unsigned char* pixels() const { if (mPixels->bytesUsed()) return mPixels->ptr(); else return NULL; }
00112 unsigned char* pixels() { if (mPixels->bytesUsed()) return mPixels->ptr(); else return NULL; }
00113 bool empty() { return pixels() == NULL; }
00114 unsigned char* pixelsZSlice(int slice);
00115 unsigned char* pixelsXP();
00116 unsigned char* pixelsXN();
00117 unsigned char* pixelsYP();
00118 unsigned char* pixelsYN();
00119 unsigned char* pixelsZP();
00120 unsigned char* pixelsZN();
00121 void setMipmaps(const std::vector< ref<Image> >& mipmaps) { mMipmaps = mipmaps; };
00122 const std::vector< ref<Image> >& mipmaps() const { return mMipmaps; };
00123 void clearMipmaps() { mMipmaps.clear(); }
00124 int width() const { return mWidth; }
00125 int height() const { return mHeight; }
00126 int depth() const { return mDepth; }
00127 int pitch() const { return mPitch; }
00128 EImageFormat format() const { return mFormat; }
00129 EImageType type() const { return mType; }
00130 int alphaBits() const;
00131
00132 int isCompressedFormat(EImageFormat fmt);
00133
00134 void flipVertically();
00135
00161 ref<Image> convertType(EImageType new_type) const;
00162
00187 ref<Image> convertFormat(EImageFormat new_format) const;
00188
00190 bool equalize();
00191
00193 bool contrast(float black, float white);
00194
00196 bool contrastHounsfieldAuto();
00197
00199 bool contrastHounsfield(float center, float width, float intercept, float range);
00200
00202 fvec4 sampleLinear(double x) const;
00203
00205 fvec4 sampleLinear(double x, double y) const;
00206
00208 fvec4 sampleLinear(double x, double y, double z) const;
00209
00238 fvec4 sample(int x, int y=0, int z=0) const;
00239
00247 ref<Image> subImage(int xstart, int ystart, int width, int height);
00248
00253 void copySubImage(Image* img_src, RectI src, ivec2 dst);
00254
00267 void substituteColorRGB_RGBA(unsigned int before, unsigned int after);
00268
00279 void substituteColorRGB_RGB(unsigned int before, unsigned int after);
00280
00281 void substituteColorGreenKey(unsigned int col0, unsigned int col1);
00282
00283 protected:
00284 void updatePitch();
00285
00286 protected:
00287 ref<Buffer> mPixels;
00288 ref<KeyValues> mTags;
00289
00290 std::vector< ref<Image> > mMipmaps;
00291 int mWidth;
00292 int mHeight;
00293 int mDepth;
00294 int mPitch;
00295 int mByteAlign;
00296 EImageFormat mFormat;
00297 EImageType mType;
00298 bool mIsCubemap;
00299 };
00300
00302 ref<Image> createCubemap(const Image* xp, const Image* xn, const Image* yp, const Image* yn, const Image* zp, const Image* zn);
00303
00305 VLCORE_EXPORT ref<Image> loadCubemap(const String& xp_file, const String& xn_file, const String& yp_file, const String& yn_file, const String& zp_file, const String& zn_file);
00306
00311 VLCORE_EXPORT ref<Image> loadRAW(VirtualFile* file, long long file_offset, int width, int height, int depth, int bytealign, EImageFormat format, EImageType type);
00312
00314 VLCORE_EXPORT ref<Image> loadImage(VirtualFile* file);
00315
00317 VLCORE_EXPORT ref<Image> loadImage(const String& path);
00318
00320 VLCORE_EXPORT bool loadImagesFromDir(const String& dir_path, const String& ext, std::vector< ref<Image> >& images);
00321
00323 VLCORE_EXPORT ref<Image> assemble3DImage(const std::vector< ref<Image> >& images);
00324
00326 VLCORE_EXPORT bool saveImage(Image* img, VirtualFile* file);
00327
00329 VLCORE_EXPORT bool saveImage(Image* img, const String& path);
00330
00332 VLCORE_EXPORT ref<Image> makeNonUniformColorSpectrum(size_t width, size_t col_count, const fvec4* colors, const float* col_pos);
00333
00335 VLCORE_EXPORT ref<Image> makeNonUniformColorSpectrum(int width, const std::vector<fvec4>& colors, const std::vector<float>& col_pos);
00336
00338 VLCORE_EXPORT ref<Image> makeColorSpectrum(size_t width, const std::vector<fvec4>& colors);
00339
00341 VLCORE_EXPORT ref<Image> makeColorSpectrum(size_t width, const fvec4& c0, const fvec4& c1);
00342
00344 VLCORE_EXPORT ref<Image> makeColorSpectrum(size_t width, const fvec4& c0, const fvec4& c1, const fvec4& c2);
00345
00347 VLCORE_EXPORT ref<Image> makeColorSpectrum(size_t width, const fvec4& c0, const fvec4& c1, const fvec4& c2, const fvec4& c3);
00348
00350 VLCORE_EXPORT ref<Image> makeColorSpectrum(size_t width, const fvec4& c0, const fvec4& c1, const fvec4& c2, const fvec4& c3, const fvec4& c4);
00351 }
00352
00353 #endif