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.LGPL **
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 <ICLUtils/CompatMacros.h>
00034 #include <ICLUtils/Uncopyable.h>
00035 #include <ICLCore/Img.h>
00036 
00037 namespace icl{
00038   namespace io{
00040 
00126     class ICLIO_API ImageCompressor : public utils::Uncopyable{
00127       struct Data;  
00128       Data *m_data; 
00129   
00131       int estimateEncodedBufferSize(const core::ImgBase *image, bool skipMetaData);
00132       
00134       int estimateRawDataSize(const core::ImgBase *image, bool skipMetaData);
00135       
00136       public:
00138       struct ICLIO_API CompressionSpec{
00139         explicit CompressionSpec(const std::string &mode=std::string(),
00140                         const std::string &quality=std::string()):mode(mode),quality(quality){}
00141         std::string mode;    
00142         std::string quality; 
00143       };
00144   
00145       protected:
00147       struct Header{
00148         struct Params{
00149           char magick[4];            
00150           char compressionMode[4];   
00151           icl32s compressionQuality; 
00152           icl32s width;              
00153           icl32s height;             
00154           icl32s roiX;               
00155           icl32s roiY;               
00156           icl32s roiWidth;           
00157           icl32s roiHeight;          
00158           icl32s channels;           
00159           icl32s colorFormat;        
00160           icl32s depth;              
00161           icl32s dataLen;            
00162           icl32s metaLen;            
00163           int64_t timeStamp;         
00164         } params;
00165         
00166         const icl8u *data;           
00167         inline const char *metaBegin() const { return (char*)(data + sizeof(Params)); }
00168         inline const icl8u *imageBegin() const { return (icl8u*)(metaBegin() + params.metaLen); }
00169         inline int imageLen() const { return params.dataLen - sizeof(Params) - params.metaLen; }
00170         inline std::string getMagickCode() const { return std::string(params.magick,params.magick+4); }
00171         inline std::string getCompressionMode() const { return std::string(params.compressionMode,params.compressionMode+4); }
00172         CompressionSpec compressionSpec() const;
00173         void setupImage(core::ImgBase **image);  
00174       };
00175       
00176       
00177   
00179 
00180       Header uncompressHeader(const icl8u *compressedData, int len);
00181       
00183       Header createHeader(const core::ImgBase *image, bool skipMetaData);
00184   
00185       public:
00186   
00187       
00189 
00190       struct ICLIO_API CompressedData{
00192         CompressedData(icl8u *bytes=0,int len=0, float compressionRatio=0, 
00193                        const CompressionSpec &compression=CompressionSpec()):
00194         bytes(bytes),len(len),compressionRatio(compressionRatio),
00195           compression(compression){}
00196         
00198         icl8u *bytes;
00199         
00201         int len;
00202       
00204         float compressionRatio;
00205         
00207         CompressionSpec compression;
00208       };
00209      
00211       ImageCompressor(const CompressionSpec &spec=CompressionSpec("none"));
00212   
00214       ~ImageCompressor();
00215       
00217 
00227       virtual void setCompression(const CompressionSpec &spec);
00228       
00230       virtual CompressionSpec getCompression() const;
00231         
00232     
00233   
00235 
00236       utils::Time pickTimeStamp(const icl8u *compressedData); 
00237       
00239 
00240       const CompressedData compress(const core::ImgBase *image, bool skipMetaData=false);
00241   
00243       const core::ImgBase *uncompress(const icl8u *compressedData, int len, core::ImgBase **dst=0);
00244     };
00245   
00246   } // namespace io
00247 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines