# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlCore/Image.hpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.com                                               */
    00005 /*                                                                                    */
    00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
    00007 /*  All rights reserved.                                                              */
    00008 /*                                                                                    */
    00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
    00010 /*  are permitted provided that the following conditions are met:                     */
    00011 /*                                                                                    */
    00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
    00013 /*  list of conditions and the following disclaimer.                                  */
    00014 /*                                                                                    */
    00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
    00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
    00017 /*  other materials provided with the distribution.                                   */
    00018 /*                                                                                    */
    00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
    00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
    00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
    00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
    00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
    00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
    00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
    00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
    00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
    00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
    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   // Image
    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     // just sets up the image configuration & clears the local storage
    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

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:20.
Permission is granted to use this page to write and publish articles regarding Visualization Library.