Image Component Library (ICL)
ImageCompressor.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLIO/src/ICLIO/ImageCompressor.h **
10 ** Module : ICLIO **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLUtils/Uncopyable.h>
35 #include <ICLCore/Img.h>
36 
37 namespace icl{
38  namespace io{
40 
133  struct Data;
134  Data *m_data;
135 
137  int estimateEncodedBufferSize(const core::ImgBase *image, bool skipMetaData);
138 
140  int estimateRawDataSize(const core::ImgBase *image, bool skipMetaData);
141 
142  public:
145  explicit CompressionSpec(const std::string &mode=std::string(),
146  const std::string &quality=std::string()):mode(mode),quality(quality){}
147  std::string mode;
148  std::string quality;
149  };
150 
151  protected:
153  struct Header{
154  struct Params{
155  char magick[4];
156  char compressionMode[4];
169  int64_t timeStamp;
170  } params;
171 
172  const icl8u *data;
173  inline const char *metaBegin() const { return (char*)(data + sizeof(Params)); }
174  inline const icl8u *imageBegin() const { return (icl8u*)(metaBegin() + params.metaLen); }
175  inline int imageLen() const { return params.dataLen - sizeof(Params) - params.metaLen; }
176  inline std::string getMagickCode() const { return std::string(params.magick,params.magick+4); }
177  inline std::string getCompressionMode() const { return std::string(params.compressionMode,params.compressionMode+4); }
178  CompressionSpec compressionSpec() const;
179  void setupImage(core::ImgBase **image);
180  };
181 
182 
183 
185 
186  Header uncompressHeader(const icl8u *compressedData, int len);
187 
189  Header createHeader(const core::ImgBase *image, bool skipMetaData);
190 
191  public:
192 
193 
195 
198  CompressedData(icl8u *bytes=0,int len=0, float compressionRatio=0,
199  const CompressionSpec &compression=CompressionSpec()):
200  bytes(bytes),len(len),compressionRatio(compressionRatio),
201  compression(compression){}
202 
205 
207  int len;
208 
211 
214  };
215 
217  ImageCompressor(const CompressionSpec &spec=CompressionSpec("none"));
218 
220  ~ImageCompressor();
221 
223 
233  virtual void setCompression(const CompressionSpec &spec);
234 
236  virtual CompressionSpec getCompression() const;
237 
238 
239 
241 
242  utils::Time pickTimeStamp(const icl8u *compressedData);
243 
245 
246  const CompressedData compress(const core::ImgBase *image, bool skipMetaData=false);
247 
249  const core::ImgBase *uncompress(const icl8u *compressedData, int len, core::ImgBase **dst=0);
250  };
251 
252  } // namespace io
253 }
int64_t timeStamp
timestamp
Definition: ImageCompressor.h:169
Definition: ImageCompressor.h:154
Compressed image header.
Definition: ImageCompressor.h:153
undocument this line if you encounter any issues!
Definition: Any.h:37
Class interface for un-copyable classes.
Definition: Uncopyable.h:64
std::string mode
mode
Definition: ImageCompressor.h:147
Ipp8u icl8u
8Bit unsigned integer type for the ICL
Definition: BasicTypes.h:64
std::string quality
quality
Definition: ImageCompressor.h:148
std::string getCompressionMode() const
Definition: ImageCompressor.h:177
ICL Time class (taken from the Ice lib)
Definition: Time.h:52
icl32s compressionQuality
compression quality
Definition: ImageCompressor.h:157
compression specification
Definition: ImageCompressor.h:144
CompressionSpec compression
underlying compression mode
Definition: ImageCompressor.h:213
ICLQt_API ImgROI data(ImgQ &r)
creates full ROI ROI-struct
const icl8u * imageBegin() const
Definition: ImageCompressor.h:174
Ipp32s icl32s
32bit signed integer type for the ICL
Definition: BasicTypes.h:58
icl32s roiY
image roi y offset
Definition: ImageCompressor.h:161
most simple dyn-size array with given data and length
Definition: ImageCompressor.h:196
int imageLen() const
Definition: ImageCompressor.h:175
icl32s roiHeight
image roi width
Definition: ImageCompressor.h:163
Encoder class for optimized encoding of images.
Definition: ImageCompressor.h:132
#define ICLIO_API
Definition: CompatMacros.h:176
CompressionSpec(const std::string &mode=std::string(), const std::string &quality=std::string())
Definition: ImageCompressor.h:145
icl32s colorFormat
image color format
Definition: ImageCompressor.h:165
icl32s width
image width
Definition: ImageCompressor.h:158
const char * metaBegin() const
Definition: ImageCompressor.h:173
std::string getMagickCode() const
Definition: ImageCompressor.h:176
float compressionRatio
compression rate (1: no compression, 0.5: 50% compression , ...)
Definition: ImageCompressor.h:210
const icl8u * data
compressed data begin (data[0] = magick[0])
Definition: ImageCompressor.h:172
icl32s dataLen
length of data segment
Definition: ImageCompressor.h:167
CompressedData(icl8u *bytes=0, int len=0, float compressionRatio=0, const CompressionSpec &compression=CompressionSpec())
Constructor.
Definition: ImageCompressor.h:198
icl32s metaLen
length of meta data segemnt
Definition: ImageCompressor.h:168
icl32s channels
image channel count
Definition: ImageCompressor.h:164
icl32s roiX
image roi x offset
Definition: ImageCompressor.h:160
icl32s roiWidth
image roi width
Definition: ImageCompressor.h:162
icl32s height
image height
Definition: ImageCompressor.h:159
ImgBase is the Image-Interface class that provides save access to underlying Img-template .
Definition: ImgBase.h:131
Data * m_data
pimpl type
Definition: ImageCompressor.h:133
icl8u * bytes
data pointer
Definition: ImageCompressor.h:204
icl32s depth
image depth
Definition: ImageCompressor.h:166
int len
num elements
Definition: ImageCompressor.h:207