// // 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 (_eb "fmt";_ee "github.com/unidoc/unipdf/v3/common";_bd "github.com/unidoc/unipdf/v3/internal/bitwise";_e "io";_bb "math";_ea "strings";);func (_aa *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_aa ._cg =1;var _ca uint64 ;for _ca =0;_ca < codeLen ;_ca ++{stats .SetIndex (int32 (_aa ._cg ));_ga ,_cd :=_aa .DecodeBit (stats );if _cd !=nil {return 0,_cd ;};_aa ._cg =(_aa ._cg <<1)|int64 (_ga );};_bc :=_aa ._cg -(1<>16)< uint64 (_ge ){_a =_ebe .lpsExchange (stats ,_ab ,_ge );if _eba :=_ebe .renormalize ();_eba !=nil {return 0,_eba ;};}else {_ebe ._g -=uint64 (_ge )<<16;if (_ebe ._d &0x8000)==0{_a =_ebe .mpsExchange (stats ,_ab );if _ag :=_ebe .renormalize ();_ag !=nil {return 0,_ag ;};}else {_a =int (stats .getMps ());};};return _a ,nil ;};func (_dfa *Decoder )init ()error {_dfa ._cge =_dfa ._f .StreamPosition ();_ff ,_fb :=_dfa ._f .ReadByte ();if _fb !=nil {_ee .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",_fb );return _fb ;};_dfa ._bf =_ff ;_dfa ._g =uint64 (_ff )<<16;if _fb =_dfa .readByte ();_fb !=nil {return _fb ;};_dfa ._g <<=7;_dfa ._ef -=7;_dfa ._d =0x8000;_dfa ._fc ++;return nil ;};func (_gce *DecoderStats )toggleMps (){_gce ._de [_gce ._eg ]^=1};func (_egb *DecoderStats )Reset (){for _fe :=0;_fe < len (_egb ._bdg );_fe ++{_egb ._bdg [_fe ]=0;_egb ._de [_fe ]=0;};};func (_gfb *Decoder )decodeIntBit (_cef *DecoderStats )(int ,error ){_cef .SetIndex (int32 (_gfb ._cg ));_gfd ,_bcd :=_gfb .DecodeBit (_cef );if _bcd !=nil {_ee .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",_bcd );return _gfd ,_bcd ;};if _gfb ._cg < 256{_gfb ._cg =((_gfb ._cg < _cf ._cge {if _ ,_bg :=_cf ._f .Seek (-1,_e .SeekCurrent );_bg !=nil {return _bg ;};};_ebg ,_dbd :=_cf ._f .ReadByte ();if _dbd !=nil {return _dbd ;};_cf ._bf =_ebg ;if _cf ._bf ==0xFF{_gb ,_dab :=_cf ._f .ReadByte ();if _dab !=nil {return _dab ;};if _gb > 0x8F{_cf ._g +=0xFF00;_cf ._ef =8;if _ ,_gf :=_cf ._f .Seek (-2,_e .SeekCurrent );_gf !=nil {return _gf ;};}else {_cf ._g +=uint64 (_gb )<<9;_cf ._ef =7;};}else {_ebg ,_dbd =_cf ._f .ReadByte ();if _dbd !=nil {return _dbd ;};_cf ._bf =_ebg ;_cf ._g +=uint64 (_cf ._bf )<<8;_cf ._ef =8;};_cf ._g &=0xFFFFFFFFFF;return nil ;};func (_dfe *DecoderStats )setEntry (_bfd int ){_ed :=byte (_bfd &0x7f);_dfe ._bdg [_dfe ._eg ]=_ed };func (_ba *Decoder )mpsExchange (_dg *DecoderStats ,_gd int32 )int {_dfb :=_dg ._de [_dg ._eg ];if _ba ._d < _c [_gd ][0]{if _c [_gd ][3]==1{_dg .toggleMps ();};_dg .setEntry (int (_c [_gd ][2]));return int (1-_dfb );};_dg .setEntry (int (_c [_gd ][1]));return int (_dfb );};func (_deb *DecoderStats )Overwrite (dNew *DecoderStats ){for _gfc :=0;_gfc < len (_deb ._bdg );_gfc ++{_deb ._bdg [_gfc ]=dNew ._bdg [_gfc ];_deb ._de [_gfc ]=dNew ._de [_gfc ];};};func (_df *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_eab ,_ae int32 ;_cga ,_ad ,_ce int ;_dd error ;);if stats ==nil {stats =NewStats (512,1);};_df ._cg =1;_ad ,_dd =_df .decodeIntBit (stats );if _dd !=nil {return 0,_dd ;};_cga ,_dd =_df .decodeIntBit (stats );if _dd !=nil {return 0,_dd ;};if _cga ==1{_cga ,_dd =_df .decodeIntBit (stats );if _dd !=nil {return 0,_dd ;};if _cga ==1{_cga ,_dd =_df .decodeIntBit (stats );if _dd !=nil {return 0,_dd ;};if _cga ==1{_cga ,_dd =_df .decodeIntBit (stats );if _dd !=nil {return 0,_dd ;};if _cga ==1{_cga ,_dd =_df .decodeIntBit (stats );if _dd !=nil {return 0,_dd ;};if _cga ==1{_ce =32;_ae =4436;}else {_ce =12;_ae =340;};}else {_ce =8;_ae =84;};}else {_ce =6;_ae =20;};}else {_ce =4;_ae =4;};}else {_ce =2;_ae =0;};for _db :=0;_db < _ce ;_db ++{_cga ,_dd =_df .decodeIntBit (stats );if _dd !=nil {return 0,_dd ;};_eab =(_eab <<1)|int32 (_cga );};_eab +=_ae ;if _ad ==0{return _eab ,nil ;}else if _ad ==1&&_eab > 0{return -_eab ,nil ;};return _bb .MaxInt32 ,nil ;};func (_adaf *DecoderStats )SetIndex (index int32 ){_adaf ._eg =index };func (_fcg *DecoderStats )getMps ()byte {return _fcg ._de [_fcg ._eg ]};type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ;_f _bd .StreamReader ;_bf uint8 ;_g uint64 ;_d uint32 ;_cg int64 ;_ef int32 ;_fc int32 ;_cge int64 ;};type DecoderStats struct{_eg int32 ;_be int32 ;_bdg []byte ;_de []byte ;};func (_bda *DecoderStats )Copy ()*DecoderStats {_ffe :=&DecoderStats {_be :_bda ._be ,_bdg :make ([]byte ,_bda ._be )};for _gba :=0;_gba < len (_bda ._bdg );_gba ++{_ffe ._bdg [_gba ]=_bda ._bdg [_gba ];};return _ffe ;};func New (r _bd .StreamReader )(*Decoder ,error ){_da :=&Decoder {_f :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};if _gc :=_da .init ();_gc !=nil {return nil ,_gc ;};return _da ,nil ;};func (_dge *DecoderStats )cx ()byte {return _dge ._bdg [_dge ._eg ]};