Path: blob/main/misc/emulator/xnes/snes9x/jma/lencoder.h
28798 views
/*1Copyright (C) 2005-2006 NSRT Team ( http://nsrt.edgeemu.com )2Copyright (C) 2002 Andrea Mazzoleni ( http://advancemame.sf.net )3Copyright (C) 2001-4 Igor Pavlov ( http://www.7-zip.org )45This library is free software; you can redistribute it and/or6modify it under the terms of the GNU Lesser General Public7License version 2.1 as published by the Free Software Foundation.89This library is distributed in the hope that it will be useful,10but WITHOUT ANY WARRANTY; without even the implied warranty of11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12Lesser General Public License for more details.1314You should have received a copy of the GNU Lesser General Public15License along with this library; if not, write to the Free Software16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA17*/1819#ifndef __LENCODER_H20#define __LENCODER_H2122#include "btreecd.h"2324namespace NLength {2526const UINT32 kNumPosStatesBitsMax = 4;27const int kNumPosStatesMax = (1 << kNumPosStatesBitsMax);282930const int kNumPosStatesBitsEncodingMax = 4;31const int kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);323334const int kNumMoveBits = 5;3536const int kNumLenBits = 3;37const int kNumLowSymbols = 1 << kNumLenBits;38const int kNumMidBits = 3;39const int kNumMidSymbols = 1 << kNumMidBits;4041const int kNumHighBits = 8;4243const int kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);4445const int kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;4647class CDecoder48{49CMyBitDecoder<kNumMoveBits> m_Choice;50CBitTreeDecoder<kNumMoveBits, kNumLenBits> m_LowCoder[kNumPosStatesMax];51CMyBitDecoder<kNumMoveBits> m_Choice2;52CBitTreeDecoder<kNumMoveBits, kNumMidBits> m_MidCoder[kNumPosStatesMax];53CBitTreeDecoder<kNumMoveBits, kNumHighBits> m_HighCoder;54UINT32 m_NumPosStates;55public:56void Create(UINT32 aNumPosStates)57{ m_NumPosStates = aNumPosStates; }58void Init()59{60m_Choice.Init();61for (UINT32 aPosState = 0; aPosState < m_NumPosStates; aPosState++)62{63m_LowCoder[aPosState].Init();64m_MidCoder[aPosState].Init();65}66m_Choice2.Init();67m_HighCoder.Init();68}69UINT32 Decode(CMyRangeDecoder *aRangeDecoder, UINT32 aPosState)70{71if(m_Choice.Decode(aRangeDecoder) == 0)72return m_LowCoder[aPosState].Decode(aRangeDecoder);73else74{75UINT32 aSymbol = kNumLowSymbols;76if(m_Choice2.Decode(aRangeDecoder) == 0)77aSymbol += m_MidCoder[aPosState].Decode(aRangeDecoder);78else79{80aSymbol += kNumMidSymbols;81aSymbol += m_HighCoder.Decode(aRangeDecoder);82}83return aSymbol;84}85}8687};8889}909192#endif939495