2022-06-06 22:48:24 +00:00

35 lines
7.8 KiB
Go

//
// Copyright 2020 FoxyUtils ehf. All rights reserved.
//
// This is a commercial product and requires a license to operate.
// A trial license can be obtained at https://unidoc.io
//
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
//
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
package arithmetic ;import (_eg "fmt";_dd "github.com/unidoc/unipdf/v3/common";_f "github.com/unidoc/unipdf/v3/internal/bitwise";_c "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_e "io";_b "strings";);func (_cee *DecoderStats )SetIndex (index int32 ){_cee ._da =index };
func (_bdb *Decoder )decodeIntBit (_bda *DecoderStats )(int ,error ){_bda .SetIndex (int32 (_bdb ._a ));_cea ,_cge :=_bdb .DecodeBit (_bda );if _cge !=nil {_dd .Log .Debug ("\u0041\u0072\u0069\u0074\u0068\u006d\u0065t\u0069\u0063\u0044e\u0063\u006f\u0064e\u0072\u0020'\u0064\u0065\u0063\u006f\u0064\u0065I\u006etB\u0069\u0074\u0027\u002d\u003e\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0042\u0069\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u002e\u0020\u0025\u0076",_cge );
return _cea ,_cge ;};if _bdb ._a < 256{_bdb ._a =((_bdb ._a <<uint64 (1))|int64 (_cea ))&0x1ff;}else {_bdb ._a =(((_bdb ._a <<uint64 (1)|int64 (_cea ))&511)|256)&0x1ff;};return _cea ,nil ;};func (_cb *Decoder )readByte ()error {if _cb ._cg .StreamPosition ()> _cb ._g {if _ ,_ab :=_cb ._cg .Seek (-1,_e .SeekCurrent );
_ab !=nil {return _ab ;};};_ddb ,_fa :=_cb ._cg .ReadByte ();if _fa !=nil {return _fa ;};_cb ._cd =_ddb ;if _cb ._cd ==0xFF{_cda ,_bc :=_cb ._cg .ReadByte ();if _bc !=nil {return _bc ;};if _cda > 0x8F{_cb ._ca +=0xFF00;_cb ._cad =8;if _ ,_ee :=_cb ._cg .Seek (-2,_e .SeekCurrent );
_ee !=nil {return _ee ;};}else {_cb ._ca +=uint64 (_cda )<<9;_cb ._cad =7;};}else {_ddb ,_fa =_cb ._cg .ReadByte ();if _fa !=nil {return _fa ;};_cb ._cd =_ddb ;_cb ._ca +=uint64 (_cb ._cd )<<8;_cb ._cad =8;};_cb ._ca &=0xFFFFFFFFFF;return nil ;};func (_eed *DecoderStats )getMps ()byte {return _eed ._cfa [_eed ._da ]};
func New (r _f .StreamReader )(*Decoder ,error ){_ad :=&Decoder {_cg :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};if _ed :=_ad .init ();_ed !=nil {return nil ,_ed ;};return _ad ,nil ;};func (_ddbc *DecoderStats )setEntry (_fc int ){_cfae :=byte (_fc &0x7f);
_ddbc ._gggf [_ddbc ._da ]=_cfae ;};func (_cf *Decoder )init ()error {_cf ._g =_cf ._cg .StreamPosition ();_ag ,_bdf :=_cf ._cg .ReadByte ();if _bdf !=nil {_dd .Log .Debug ("B\u0075\u0066\u0066\u0065\u0072\u0030 \u0072\u0065\u0061\u0064\u0042\u0079\u0074\u0065\u0020f\u0061\u0069\u006ce\u0064.\u0020\u0025\u0076",_bdf );
return _bdf ;};_cf ._cd =_ag ;_cf ._ca =uint64 (_ag )<<16;if _bdf =_cf .readByte ();_bdf !=nil {return _bdf ;};_cf ._ca <<=7;_cf ._cad -=7;_cf ._eb =0x8000;_cf ._df ++;return nil ;};func (_cae *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_fb int ;
_bd =_dde [stats .cx ()][0];_fg =int32 (stats .cx ()););defer func (){_cae ._df ++}();_cae ._eb -=_bd ;if (_cae ._ca >>16)< uint64 (_bd ){_fb =_cae .lpsExchange (stats ,_fg ,_bd );if _be :=_cae .renormalize ();_be !=nil {return 0,_be ;};}else {_cae ._ca -=uint64 (_bd )<<16;
if (_cae ._eb &0x8000)==0{_fb =_cae .mpsExchange (stats ,_fg );if _gf :=_cae .renormalize ();_gf !=nil {return 0,_gf ;};}else {_fb =int (stats .getMps ());};};return _fb ,nil ;};func (_abf *Decoder )mpsExchange (_bfg *DecoderStats ,_cde int32 )int {_ggg :=_bfg ._cfa [_bfg ._da ];
if _abf ._eb < _dde [_cde ][0]{if _dde [_cde ][3]==1{_bfg .toggleMps ();};_bfg .setEntry (int (_dde [_cde ][2]));return int (1-_ggg );};_bfg .setEntry (int (_dde [_cde ][1]));return int (_ggg );};type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ;
_cg _f .StreamReader ;_cd uint8 ;_ca uint64 ;_eb uint32 ;_a int64 ;_cad int32 ;_df int32 ;_g int64 ;};func (_ga *DecoderStats )Copy ()*DecoderStats {_ac :=&DecoderStats {_abg :_ga ._abg ,_gggf :make ([]byte ,_ga ._abg )};for _gd :=0;_gd < len (_ga ._gggf );
_gd ++{_ac ._gggf [_gd ]=_ga ._gggf [_gd ];};return _ac ;};func (_bf *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_db ,_ge int32 ;_ae ,_gg ,_ce int ;_add error ;);if stats ==nil {stats =NewStats (512,1);};_bf ._a =1;_gg ,_add =_bf .decodeIntBit (stats );
if _add !=nil {return 0,_add ;};_ae ,_add =_bf .decodeIntBit (stats );if _add !=nil {return 0,_add ;};if _ae ==1{_ae ,_add =_bf .decodeIntBit (stats );if _add !=nil {return 0,_add ;};if _ae ==1{_ae ,_add =_bf .decodeIntBit (stats );if _add !=nil {return 0,_add ;
};if _ae ==1{_ae ,_add =_bf .decodeIntBit (stats );if _add !=nil {return 0,_add ;};if _ae ==1{_ae ,_add =_bf .decodeIntBit (stats );if _add !=nil {return 0,_add ;};if _ae ==1{_ce =32;_ge =4436;}else {_ce =12;_ge =340;};}else {_ce =8;_ge =84;};}else {_ce =6;
_ge =20;};}else {_ce =4;_ge =4;};}else {_ce =2;_ge =0;};for _edb :=0;_edb < _ce ;_edb ++{_ae ,_add =_bf .decodeIntBit (stats );if _add !=nil {return 0,_add ;};_db =(_db <<1)|int32 (_ae );};_db +=_ge ;if _gg ==0{return _db ,nil ;}else if _gg ==1&&_db > 0{return -_db ,nil ;
};return 0,_c .ErrOOB ;};type DecoderStats struct{_da int32 ;_abg int32 ;_gggf []byte ;_cfa []byte ;};func NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_da :index ,_abg :contextSize ,_gggf :make ([]byte ,contextSize ),_cfa :make ([]byte ,contextSize )};
};func (_bfa *DecoderStats )toggleMps (){_bfa ._cfa [_bfa ._da ]^=1};func (_cc *DecoderStats )Reset (){for _de :=0;_de < len (_cc ._gggf );_de ++{_cc ._gggf [_de ]=0;_cc ._cfa [_de ]=0;};};func (_ega *DecoderStats )Overwrite (dNew *DecoderStats ){for _edd :=0;
_edd < len (_ega ._gggf );_edd ++{_ega ._gggf [_edd ]=dNew ._gggf [_edd ];_ega ._cfa [_edd ]=dNew ._cfa [_edd ];};};func (_dag *DecoderStats )cx ()byte {return _dag ._gggf [_dag ._da ]};var (_dde =[][4]uint32 {{0x5601,1,1,1},{0x3401,2,6,0},{0x1801,3,9,0},{0x0AC1,4,12,0},{0x0521,5,29,0},{0x0221,38,33,0},{0x5601,7,6,1},{0x5401,8,14,0},{0x4801,9,14,0},{0x3801,10,14,0},{0x3001,11,17,0},{0x2401,12,18,0},{0x1C01,13,20,0},{0x1601,29,21,0},{0x5601,15,14,1},{0x5401,16,14,0},{0x5101,17,15,0},{0x4801,18,16,0},{0x3801,19,17,0},{0x3401,20,18,0},{0x3001,21,19,0},{0x2801,22,19,0},{0x2401,23,20,0},{0x2201,24,21,0},{0x1C01,25,22,0},{0x1801,26,23,0},{0x1601,27,24,0},{0x1401,28,25,0},{0x1201,29,26,0},{0x1101,30,27,0},{0x0AC1,31,28,0},{0x09C1,32,29,0},{0x08A1,33,30,0},{0x0521,34,31,0},{0x0441,35,32,0},{0x02A1,36,33,0},{0x0221,37,34,0},{0x0141,38,35,0},{0x0111,39,36,0},{0x0085,40,37,0},{0x0049,41,38,0},{0x0025,42,39,0},{0x0015,43,40,0},{0x0009,44,41,0},{0x0005,45,42,0},{0x0001,45,43,0},{0x5601,46,46,0}};
);func (_afe *DecoderStats )String ()string {_gb :=&_b .Builder {};_gb .WriteString (_eg .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_afe ._gggf )));for _fbe ,_gc :=range _afe ._gggf {if _gc !=0{_gb .WriteString (_eg .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_fbe ,_gc ));
};};return _gb .String ();};func (_bcc *Decoder )lpsExchange (_ege *DecoderStats ,_dg int32 ,_ea uint32 )int {_eag :=_ege .getMps ();if _bcc ._eb < _ea {_ege .setEntry (int (_dde [_dg ][1]));_bcc ._eb =_ea ;return int (_eag );};if _dde [_dg ][3]==1{_ege .toggleMps ();
};_ege .setEntry (int (_dde [_dg ][2]));_bcc ._eb =_ea ;return int (1-_eag );};func (_fd *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_fd ._a =1;var _fga uint64 ;for _fga =0;_fga < codeLen ;_fga ++{stats .SetIndex (int32 (_fd ._a ));
_cdb ,_gfd :=_fd .DecodeBit (stats );if _gfd !=nil {return 0,_gfd ;};_fd ._a =(_fd ._a <<1)|int64 (_cdb );};_dda :=_fd ._a -(1<<codeLen );return _dda ,nil ;};func (_ddec *Decoder )renormalize ()error {for {if _ddec ._cad ==0{if _ef :=_ddec .readByte ();
_ef !=nil {return _ef ;};};_ddec ._eb <<=1;_ddec ._ca <<=1;_ddec ._cad --;if (_ddec ._eb &0x8000)!=0{break ;};};_ddec ._ca &=0xffffffff;return nil ;};