aboutsummaryrefslogtreecommitdiff
path: root/src/lzsshuffman/lzsshuffmanencoder.nim
diff options
context:
space:
mode:
authorpacien2018-12-02 00:22:56 +0100
committerpacien2018-12-02 00:22:56 +0100
commit5cc4256a931b98ea167291397421d0db60c5d40c (patch)
tree54c7ba39e69fb31322db431a82dbf31aedbb53b9 /src/lzsshuffman/lzsshuffmanencoder.nim
parent1850acb5b77aabbf4e9ba24ae6d5314c3d4d896a (diff)
downloadgziplike-5cc4256a931b98ea167291397421d0db60c5d40c.tar.gz
implement lzss block
Diffstat (limited to 'src/lzsshuffman/lzsshuffmanencoder.nim')
-rw-r--r--src/lzsshuffman/lzsshuffmanencoder.nim34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lzsshuffman/lzsshuffmanencoder.nim b/src/lzsshuffman/lzsshuffmanencoder.nim
new file mode 100644
index 0000000..ea89f85
--- /dev/null
+++ b/src/lzsshuffman/lzsshuffmanencoder.nim
@@ -0,0 +1,34 @@
1# gzip-like LZSS compressor
2# Copyright (C) 2018 Pacien TRAN-GIRARD
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as
6# published by the Free Software Foundation, either version 3 of the
7# License, or (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17import lists
18import ../bitio/bitwriter
19import ../lzss/listpolyfill, ../lzss/lzssnode, ../lzss/lzsschain, ../lzss/lzssencoder
20import ../huffman/huffmantree, ../huffman/huffmantreebuilder, ../huffman/huffmanencoder
21import lzsshuffmansymbol
22
23proc writeSymbol(bitWriter: BitWriter, encodedSymbol: tuple[bitLength: int, value: uint16]) =
24 bitWriter.writeBits(encodedSymbol.bitLength, encodedSymbol.value)
25
26proc writeChain*(lzssChain: LzssChain, symbolEncoder, positionEncoder: HuffmanEncoder[uint16, uint16], bitWriter: BitWriter) =
27 for node in lzssChain.items:
28 case node.kind:
29 of character:
30 bitWriter.writeSymbol(symbolEncoder.encode(node.character))
31 of reference:
32 bitWriter.writeSymbol(symbolEncoder.encode(shiftLzssLength(node.length)))
33 bitWriter.writeSymbol(positionEncoder.encode(node.relativePos.uint16))
34 bitWriter.writeSymbol(symbolEncoder.encode(endSymbol))