[go: up one dir, main page]

File: LZWDecoder.cpp

package info (click to toggle)
ancient 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,168 kB
  • sloc: cpp: 15,188; makefile: 217; sh: 31
file content (40 lines) | stat: -rw-r--r-- 851 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* Copyright (C) Teemu Suutari */

#include "LZWDecoder.hpp"
#include "common/Common.hpp"


namespace ancient::internal
{

LZWDecoder::LZWDecoder(uint32_t maxCode,uint32_t literalCodes,uint32_t stackLength,uint32_t firstCode) :
	_maxCode{maxCode},
	_literalCodes{literalCodes},
	_stackLength{stackLength},
	_freeIndex{literalCodes},
	_prevCode{firstCode},
	_prefix{std::make_unique<uint32_t[]>(maxCode-literalCodes)},
	_suffix{std::make_unique<uint8_t[]>(maxCode-literalCodes)},
	_stack{std::make_unique<uint8_t[]>(stackLength)}
{
	// nothing needed
}

void LZWDecoder::reset(uint32_t firstCode)
{
	_freeIndex=_literalCodes;
	_prevCode=firstCode;
}

void LZWDecoder::add(uint32_t code)
{
	if (_freeIndex<_maxCode)
	{
		_suffix[_freeIndex-_literalCodes]=_newCode;
		_prefix[_freeIndex-_literalCodes]=_prevCode;
		_freeIndex++;
	}
	_prevCode=code;
}

}