Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ImageCompressor.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLIO/src/ICLIO/ImageCompressor.h                      **
00010 ** Module : ICLIO                                                  **
00011 ** Authors: Christof Elbrechter                                    **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.GPL  **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <ICLCore/Img.h>
00034 #include <ICLUtils/Uncopyable.h>
00035 
00036 namespace icl{
00037   namespace io{
00039 
00125     class ImageCompressor : public utils::Uncopyable{
00126       struct Data;  
00127       Data *m_data; 
00128   
00130       int estimateEncodedBufferSize(const core::ImgBase *image, bool skipMetaData);
00131       
00133       int estimateRawDataSize(const core::ImgBase *image, bool skipMetaData);
00134       
00135       public:
00137       struct CompressionSpec{
00138         explicit CompressionSpec(const std::string &mode=std::string(),
00139                         const std::string &quality=std::string()):mode(mode),quality(quality){}
00140         std::string mode;    
00141         std::string quality; 
00142       };
00143   
00144       protected:
00146       struct Header{
00147         struct Params{
00148           char magick[4];            
00149           char compressionMode[4];   
00150           icl32s compressionQuality; 
00151           icl32s width;              
00152           icl32s height;             
00153           icl32s roiX;               
00154           icl32s roiY;               
00155           icl32s roiWidth;           
00156           icl32s roiHeight;          
00157           icl32s channels;           
00158           icl32s colorFormat;        
00159           icl32s depth;              
00160           icl32s dataLen;            
00161           icl32s metaLen;            
00162           int64_t timeStamp;         
00163         } params;
00164         
00165         const icl8u *data;           
00166         inline const char *metaBegin() const { return (char*)(data + sizeof(Params)); }
00167         inline const icl8u *imageBegin() const { return (icl8u*)(metaBegin() + params.metaLen); }
00168         inline int imageLen() const { return params.dataLen - sizeof(Params) - params.metaLen; }
00169         inline std::string getMagickCode() const { return std::string(params.magick,params.magick+4); }
00170         inline std::string getCompressionMode() const { return std::string(params.compressionMode,params.compressionMode+4); }
00171         CompressionSpec compressionSpec() const;
00172         void setupImage(core::ImgBase **image);  
00173       };
00174       
00175       
00176   
00178 
00179       Header uncompressHeader(const icl8u *compressedData, int len);
00180       
00182       Header createHeader(const core::ImgBase *image, bool skipMetaData);
00183   
00184       public:
00185   
00186       
00188 
00189       struct CompressedData{
00191         CompressedData(icl8u *bytes=0,int len=0, float compressionRatio=0, 
00192                        const CompressionSpec &compression=CompressionSpec()):
00193         bytes(bytes),len(len),compressionRatio(compressionRatio),
00194           compression(compression){}
00195         
00197         icl8u *bytes;
00198         
00200         int len;
00201       
00203         float compressionRatio;
00204         
00206         CompressionSpec compression;
00207       };
00208      
00210       ImageCompressor(const CompressionSpec &spec=CompressionSpec("none"));
00211   
00213       ~ImageCompressor();
00214       
00216 
00226       virtual void setCompression(const CompressionSpec &spec);
00227       
00229       virtual CompressionSpec getCompression() const;
00230         
00231     
00232   
00234 
00235       utils::Time pickTimeStamp(const icl8u *compressedData); 
00236       
00238 
00239       const CompressedData compress(const core::ImgBase *image, bool skipMetaData=false);
00240   
00242       const core::ImgBase *uncompress(const icl8u *compressedData, int len, core::ImgBase **dst=0);
00243     };
00244   
00245   } // namespace io
00246 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines