1 /*
2 ===============================================================================
3 
4   FILE:  field_nir14.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 Nir14Base
37 {
38 protected:
39     struct ChannelCtx
40     {
41         int have_last_;
42         las::nir14 last_;
43         models::arithmetic used_model_;
44         std::array<models::arithmetic, 2> diff_model_;
45 
ChannelCtxlazperf::detail::Nir14Base::ChannelCtx46         ChannelCtx() : have_last_{false}, used_model_(4),
47             diff_model_{ models::arithmetic(256), models::arithmetic(256) }
48         {}
49     };
50 
51     std::array<ChannelCtx, 4> chan_ctxs_;
52     int last_channel_ = -1;
53 };
54 
55 class Nir14Compressor : public Nir14Base
56 {
57 public:
Nir14Compressor(OutCbStream & stream)58     Nir14Compressor(OutCbStream& stream) : stream_(stream), nir_enc_(false)
59     {}
60 
61     void writeSizes();
62     void writeData();
63     const char *compress(const char *buf, int& sc);
64 
65 private:
66     OutCbStream& stream_;
67     encoders::arithmetic<MemoryStream> nir_enc_;
68 };
69 
70 class Nir14Decompressor : public Nir14Base
71 {
72 public:
Nir14Decompressor(InCbStream & stream)73     Nir14Decompressor(InCbStream& stream) : stream_(stream)
74     {}
75 
76     void dumpSums();
77     void readSizes();
78     void readData();
79     char *decompress(char *buf, int& sc);
80 
81 private:
82     InCbStream& stream_;
83     uint32_t nir_cnt_;
84     decoders::arithmetic<MemoryStream> nir_dec_;
85     utils::Summer sumNir;
86 };
87 
88 } // namespace detail
89 } // namespace lazperf
90