Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

ImageArchiveMemory.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Array_ImageArchiveMemory_h
00002 #define Impala_Core_Array_ImageArchiveMemory_h
00003 
00004 #include "Core/Array/ImageArchive.h"
00005 #include "Core/Array/ArrayListDelete.h"
00006 
00007 namespace Impala
00008 {
00009 namespace Core
00010 {
00011 namespace Array
00012 {
00013 
00014 
00015 // For now, this is only a wrapper around an imList.
00016 // Should be upgraded to a real class after deprecation of REPOSITORY_USED
00017 // I.e. (all) usage of std::vector<Array::Array2dScalarUInt8*> should be
00018 // replaced with this class
00019 class ImageArchiveMemory : public ImageArchive
00020 {
00021 public:
00022 
00023     ImageArchiveMemory(std::vector<Array::Array2dScalarUInt8*>* imList)
00024     {
00025         mImList = imList;
00026         mIsWrapper = true;
00027     }
00028 
00029     virtual
00030     ~ImageArchiveMemory()
00031     {
00032         if (!mIsWrapper)
00033             ArrayListDelete(mImList);
00034     }
00035 
00036     bool
00037     Valid()
00038     {
00039         return NrImages() != 0;
00040     }
00041 
00042     int
00043     NrImages()
00044     {
00045         return (*mImList).size();
00046     }
00047 
00048     // Construct an image for given index, ownership lies with caller
00049     Array2dVec3UInt8*
00050     ReadImage(int idx)
00051     {
00052         if (!Valid())
00053         {
00054             ILOG_ERROR("Cannot ReadImage: archive not valid");
00055             return 0;
00056         }
00057 
00058         size_t blockSize = 0;
00059         UInt8* data = GetImageData(idx, blockSize);
00060         Array2dVec3UInt8* im = 0;
00061         ReadImageFromMemory(im, (char*) data, blockSize);
00062         delete data;
00063         return im;
00064     }
00065 
00066     // Obtain a copy of image data for given index, ownership lies with caller
00067     UInt8*
00068     GetImageData(int idx, size_t& blockSize)
00069     {
00070         if (!Valid())
00071         {
00072             ILOG_ERROR("Cannot GetImageData: archive not valid");
00073             return 0;
00074         }
00075         if (idx >= NrImages())
00076         {
00077             ILOG_ERROR("Index out of bounds: " << idx << " vs. " << NrImages());
00078             return 0;
00079         }
00080 
00081         /* Todo
00082         mIOBuffer->SetPosition(mFileOffset[idx]);
00083         char buf[200];
00084         int width;
00085         int height;
00086         mIOBuffer->Read(buf, 20);
00087         sscanf(buf, "%d %d ", &width, &height);
00088         blockSize = width*height;
00089         UInt8* data = new UInt8[blockSize];
00090         size_t nrRead = mIOBuffer->Read(data, blockSize);
00091         if (nrRead != blockSize)
00092             ILOG_ERROR("GetImageData: read " << nrRead
00093                         << " bytes instead of " << blockSize);
00094         return data;
00095         */
00096         ILOG_ERROR("GetImageData not implemented yet");
00097         return 0;
00098     }
00099 
00100     std::vector<Array::Array2dScalarUInt8*>*
00101     GetImageDataList()
00102     {
00103         return mImList;
00104     }
00105 
00106 private:
00107 
00108     std::vector<Array::Array2dScalarUInt8*>* mImList;
00109     bool                                     mIsWrapper;
00110 
00111     ILOG_VAR_DEC;
00112 };
00113 
00114 ILOG_VAR_INIT(ImageArchiveMemory, Impala.Core.Array);
00115 
00116 } // namespace Array
00117 } // namespace Core
00118 } // namespace Impala
00119 
00120 #endif

Generated on Fri Mar 19 09:30:46 2010 for ImpalaSrc by  doxygen 1.5.1