// // 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 (_a "fmt";_aa "github.com/unidoc/unipdf/v3/common";_g "github.com/unidoc/unipdf/v3/internal/bitwise";_d "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_b "io";_be "strings";);func (_ggf *DecoderStats )SetIndex (index int32 ){_ggf ._aff =index }; func (_gbg *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_gbg ._bb =1;var _dfd uint64 ;for _dfd =0;_dfd < codeLen ;_dfd ++{stats .SetIndex (int32 (_gbg ._bb ));_de ,_cg :=_gbg .DecodeBit (stats );if _cg !=nil {return 0,_cg ; };_gbg ._bb =(_gbg ._bb <<1)|int64 (_de );};_da :=_gbg ._bb -(1< _bd ._gb {if _ ,_cb :=_bd ._fd .Seek (-1,_b .SeekCurrent );_cb !=nil {return _cb ;};};_afa ,_cgd :=_bd ._fd .ReadByte (); if _cgd !=nil {return _cgd ;};_bd ._c =_afa ;if _bd ._c ==0xFF{_ege ,_bea :=_bd ._fd .ReadByte ();if _bea !=nil {return _bea ;};if _ege > 0x8F{_bd ._cf +=0xFF00;_bd ._ag =8;if _ ,_ea :=_bd ._fd .Seek (-2,_b .SeekCurrent );_ea !=nil {return _ea ;};}else {_bd ._cf +=uint64 (_ege )<<9; _bd ._ag =7;};}else {_afa ,_cgd =_bd ._fd .ReadByte ();if _cgd !=nil {return _cgd ;};_bd ._c =_afa ;_bd ._cf +=uint64 (_bd ._c )<<8;_bd ._ag =8;};_bd ._cf &=0xFFFFFFFFFF;return nil ;};func NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_aff :index ,_ee :contextSize ,_bc :make ([]byte ,contextSize ),_eff :make ([]byte ,contextSize )}; };func (_bf *DecoderStats )Reset (){for _cbc :=0;_cbc < len (_bf ._bc );_cbc ++{_bf ._bc [_cbc ]=0;_bf ._eff [_cbc ]=0;};};func (_ge *DecoderStats )Overwrite (dNew *DecoderStats ){for _abcb :=0;_abcb < len (_ge ._bc );_abcb ++{_ge ._bc [_abcb ]=dNew ._bc [_abcb ]; _ge ._eff [_abcb ]=dNew ._eff [_abcb ];};};func (_afd *Decoder )init ()error {_afd ._gb =_afd ._fd .StreamPosition ();_bg ,_gba :=_afd ._fd .ReadByte ();if _gba !=nil {_aa .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",_gba ); return _gba ;};_afd ._c =_bg ;_afd ._cf =uint64 (_bg )<<16;if _gba =_afd .readByte ();_gba !=nil {return _gba ;};_afd ._cf <<=7;_afd ._ag -=7;_afd ._db =0x8000;_afd ._gg ++;return nil ;};func (_cfbd *Decoder )lpsExchange (_cbg *DecoderStats ,_ef int32 ,_acb uint32 )int {_efe :=_cbg .getMps (); if _cfbd ._db < _acb {_cbg .setEntry (int (_f [_ef ][1]));_cfbd ._db =_acb ;return int (_efe );};if _f [_ef ][3]==1{_cbg .toggleMps ();};_cbg .setEntry (int (_f [_ef ][2]));_cfbd ._db =_acb ;return int (1-_efe );};func (_ba *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_af int ; _ec =_f [stats .cx ()][0];_afb =int32 (stats .cx ()););defer func (){_ba ._gg ++}();_ba ._db -=_ec ;if (_ba ._cf >>16)< uint64 (_ec ){_af =_ba .lpsExchange (stats ,_afb ,_ec );if _ab :=_ba .renormalize ();_ab !=nil {return 0,_ab ;};}else {_ba ._cf -=uint64 (_ec )<<16; if (_ba ._db &0x8000)==0{_af =_ba .mpsExchange (stats ,_afb );if _dd :=_ba .renormalize ();_dd !=nil {return 0,_dd ;};}else {_af =int (stats .getMps ());};};return _af ,nil ;};type DecoderStats struct{_aff int32 ;_ee int32 ;_bc []byte ;_eff []byte ;};type Decoder struct{ContextSize []uint32 ; ReferedToContextSize []uint32 ;_fd _g .StreamReader ;_c uint8 ;_cf uint64 ;_db uint32 ;_bb int64 ;_ag int32 ;_gg int32 ;_gb int64 ;};func (_agd *Decoder )mpsExchange (_egc *DecoderStats ,_gabf int32 )int {_bgf :=_egc ._eff [_egc ._aff ];if _agd ._db < _f [_gabf ][0]{if _f [_gabf ][3]==1{_egc .toggleMps (); };_egc .setEntry (int (_f [_gabf ][2]));return int (1-_bgf );};_egc .setEntry (int (_f [_gabf ][1]));return int (_bgf );};func (_fbf *DecoderStats )setEntry (_gfb int ){_acc :=byte (_gfb &0x7f);_fbf ._bc [_fbf ._aff ]=_acc };func (_cfb *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_df ,_gab int32 ; _cfg ,_fb ,_ae int ;_eg error ;);if stats ==nil {stats =NewStats (512,1);};_cfb ._bb =1;_fb ,_eg =_cfb .decodeIntBit (stats );if _eg !=nil {return 0,_eg ;};_cfg ,_eg =_cfb .decodeIntBit (stats );if _eg !=nil {return 0,_eg ;};if _cfg ==1{_cfg ,_eg =_cfb .decodeIntBit (stats ); if _eg !=nil {return 0,_eg ;};if _cfg ==1{_cfg ,_eg =_cfb .decodeIntBit (stats );if _eg !=nil {return 0,_eg ;};if _cfg ==1{_cfg ,_eg =_cfb .decodeIntBit (stats );if _eg !=nil {return 0,_eg ;};if _cfg ==1{_cfg ,_eg =_cfb .decodeIntBit (stats );if _eg !=nil {return 0,_eg ; };if _cfg ==1{_ae =32;_gab =4436;}else {_ae =12;_gab =340;};}else {_ae =8;_gab =84;};}else {_ae =6;_gab =20;};}else {_ae =4;_gab =4;};}else {_ae =2;_gab =0;};for _fdd :=0;_fdd < _ae ;_fdd ++{_cfg ,_eg =_cfb .decodeIntBit (stats );if _eg !=nil {return 0,_eg ; };_df =(_df <<1)|int32 (_cfg );};_df +=_gab ;if _fb ==0{return _df ,nil ;}else if _fb ==1&&_df > 0{return -_df ,nil ;};return 0,_d .ErrOOB ;};func (_bag *DecoderStats )toggleMps (){_bag ._eff [_bag ._aff ]^=1};func (_cbb *Decoder )decodeIntBit (_deb *DecoderStats )(int ,error ){_deb .SetIndex (int32 (_cbb ._bb )); _deg ,_dea :=_cbb .DecodeBit (_deb );if _dea !=nil {_aa .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",_dea ); return _deg ,_dea ;};if _cbb ._bb < 256{_cbb ._bb =((_cbb ._bb <