entropy_range_coder.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2011, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  *
00035  * Range Coder based on Dmitry Subbotin's carry-less implementation (http://www.compression.ru/ds/)
00036  * Added optimized symbol lookup and added implementation for static range coding (uses fixed precomputed frequency table)
00037  *
00038  * Author: Julius Kammerl (julius@kammerl.de)
00039  */
00040 
00041 #ifndef __PCL_IO_RANGECODING__
00042 #define __PCL_IO_RANGECODING__
00043 
00044 #include <map>
00045 #include <iostream>
00046 #include <vector>
00047 #include <string>
00048 #include <cmath>
00049 #include <algorithm>
00050 #include <stdio.h>
00051 #include <boost/cstdint.hpp>
00052 
00053 namespace pcl
00054 {
00055 
00056   using boost::uint8_t;
00057   using boost::uint32_t;
00058   using boost::uint64_t;
00059 
00061 
00067 
00068   class AdaptiveRangeCoder
00069   {
00070 
00071   public:
00072 
00074     AdaptiveRangeCoder () : outputCharVector_ ()
00075     {
00076     }
00077 
00079     virtual
00080     ~AdaptiveRangeCoder ()
00081     {
00082     }
00083 
00089     unsigned long
00090     encodeCharVectorToStream (const std::vector<char>& inputByteVector_arg, std::ostream& outputByteStream_arg);
00091 
00097     unsigned long
00098     decodeStreamToCharVector (std::istream& inputByteStream_arg, std::vector<char>& outputByteVector_arg);
00099 
00100   protected:
00101     typedef boost::uint32_t DWord; // 4 bytes
00102 
00103   private:
00106     std::vector<char> outputCharVector_;
00107 
00108   };
00109 
00111 
00117 
00118   class StaticRangeCoder
00119   {
00120     public:
00122       StaticRangeCoder () :
00123         cFreqTable_ (65537), outputCharVector_ ()
00124       {
00125       }
00126 
00128       virtual
00129       ~StaticRangeCoder ()
00130       {
00131       }
00132 
00138       unsigned long
00139       encodeIntVectorToStream (std::vector<unsigned int>& inputIntVector_arg, std::ostream& outputByterStream_arg);
00140 
00146       unsigned long
00147       decodeStreamToIntVector (std::istream& inputByteStream_arg, std::vector<unsigned int>& outputIntVector_arg);
00148 
00154       unsigned long
00155       encodeCharVectorToStream (const std::vector<char>& inputByteVector_arg, std::ostream& outputByteStream_arg);
00156 
00162       unsigned long
00163       decodeStreamToCharVector (std::istream& inputByteStream_arg, std::vector<char>& outputByteVector_arg);
00164 
00165     protected:
00166       typedef boost::uint32_t DWord; // 4 bytes
00167 
00172       inline double
00173       Log2 (double n_arg)
00174       {
00175         return log (n_arg) / log (2.0);
00176       }
00177 
00178     private:
00180       std::vector<uint64_t> cFreqTable_;
00181 
00183       std::vector<char> outputCharVector_;
00184 
00185   };
00186 }
00187 
00188 
00189 //#include "impl/entropy_range_coder.hpp"
00190 
00191 #endif
00192 


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:14:51