1 /*
2 ===============================================================================
3 
4   FILE:  field_byte14.hpp
5 
6   CONTENTS:
7 
8 
9   PROGRAMMERS:
10 
11     martin.isenburg@rapidlasso.com  -  http://rapidlasso.com
12     uday.karan@gmail.com - Hobu, Inc.
13 
14   COPYRIGHT:
15 
16     (c) 2007-2014, martin isenburg, rapidlasso - tools to catch reality
17     (c) 2014, Uday Verma, Hobu, Inc.
18 
19     This is free software; you can redistribute and/or modify it under the
20     terms of the GNU Lesser General Licence as published by the Free Software
21     Foundation. See the COPYING file for more information.
22 
23     This software is distributed WITHOUT ANY WARRANTY and without even the
24     implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25 
26   CHANGE HISTORY:
27 
28 ===============================================================================
29 */
30 
31 namespace lazperf
32 {
33 namespace detail
34 {
35 
36 class Byte14Base
37 {
38 protected:
39     struct ChannelCtx
40     {
41         int have_last_;
42         las::byte14 last_;
43         std::vector<models::arithmetic> byte_model_;
44 
ChannelCtxlazperf::detail::Byte14Base::ChannelCtx45         ChannelCtx(size_t count) : have_last_(false), last_(count),
46             byte_model_(count, models::arithmetic(256))
47         {}
48     };
49 
50 public:
51     size_t count() const;
52 
53 protected:
54     Byte14Base(size_t count);
55 
56     size_t count_;
57     int last_channel_;
58     std::array<ChannelCtx, 4> chan_ctxs_;
59     std::vector<decoders::arithmetic<MemoryStream>> byte_dec_;
60 };
61 
62 class Byte14Compressor : public Byte14Base
63 {
64 public:
65     Byte14Compressor(OutCbStream& stream, size_t count);
66 
67     void writeSizes();
68     void writeData();
69     const char *compress(const char *buf, int& sc);
70 
71 private:
72     OutCbStream& stream_;
73     std::vector<bool> valid_;
74     std::vector<encoders::arithmetic<MemoryStream>> byte_enc_;
75 };
76 
77 class Byte14Decompressor : public Byte14Base
78 {
79 public:
80     Byte14Decompressor(InCbStream& stream, size_t count);
81 
82     void dumpSums();
83     void readSizes();
84     void readData();
85     char *decompress(char *buf, int& sc);
86 
87 private:
88     InCbStream& stream_;
89     std::vector<uint32_t> byte_cnt_;
90     std::vector<decoders::arithmetic<MemoryStream>> byte_dec_;
91     utils::Summer sumByte;
92 };
93 
94 } // namespace detail
95 } // namespace lazperf
96