// // 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 (_c "fmt";_e "github.com/unidoc/unipdf/v3/common";_be "github.com/unidoc/unipdf/v3/internal/bitwise";_ee "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_ac "io";_b "strings";);func (_dd *Decoder )mpsExchange (_aaf *DecoderStats ,_ace int32 )int {_eg :=_aaf ._cgcg [_aaf ._aafg ]; if _dd ._dc < _d [_ace ][0]{if _d [_ace ][3]==1{_aaf .toggleMps ();};_aaf .setEntry (int (_d [_ace ][2]));return int (1-_eg );};_aaf .setEntry (int (_d [_ace ][1]));return int (_eg );};func (_bb *Decoder )readByte ()error {if _bb ._df .StreamPosition ()> _bb ._edc {if _ ,_gg :=_bb ._df .Seek (-1,_ac .SeekCurrent ); _gg !=nil {return _gg ;};};_baf ,_adf :=_bb ._df .ReadByte ();if _adf !=nil {return _adf ;};_bb ._ed =_baf ;if _bb ._ed ==0xFF{_cd ,_gaa :=_bb ._df .ReadByte ();if _gaa !=nil {return _gaa ;};if _cd > 0x8F{_bb ._dg +=0xFF00;_bb ._ad =8;if _ ,_ccg :=_bb ._df .Seek (-2,_ac .SeekCurrent ); _ccg !=nil {return _ccg ;};}else {_bb ._dg +=uint64 (_cd )<<9;_bb ._ad =7;};}else {_baf ,_adf =_bb ._df .ReadByte ();if _adf !=nil {return _adf ;};_bb ._ed =_baf ;_bb ._dg +=uint64 (_bb ._ed )<<8;_bb ._ad =8;};_bb ._dg &=0xFFFFFFFFFF;return nil ;};func (_ce *DecoderStats )setEntry (_bfb int ){_bdf :=byte (_bfb &0x7f); _ce ._cgdc [_ce ._aafg ]=_bdf };func (_ecg *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_f int ;_dge =_d [stats .cx ()][0];_ag =int32 (stats .cx ()););defer func (){_ecg ._ab ++}();_ecg ._dc -=_dge ;if (_ecg ._dg >>16)< uint64 (_dge ){_f =_ecg .lpsExchange (stats ,_ag ,_dge ); if _ade :=_ecg .renormalize ();_ade !=nil {return 0,_ade ;};}else {_ecg ._dg -=uint64 (_dge )<<16;if (_ecg ._dc &0x8000)==0{_f =_ecg .mpsExchange (stats ,_ag );if _bf :=_ecg .renormalize ();_bf !=nil {return 0,_bf ;};}else {_f =int (stats .getMps ());}; };return _f ,nil ;};func (_abf *DecoderStats )getMps ()byte {return _abf ._cgcg [_abf ._aafg ]};type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ;_df _be .StreamReader ;_ed uint8 ;_dg uint64 ;_dc uint32 ;_g int64 ;_ad int32 ;_ab int32 ; _edc int64 ;};func (_aad *Decoder )init ()error {_aad ._edc =_aad ._df .StreamPosition ();_gfc ,_fa :=_aad ._df .ReadByte ();if _fa !=nil {_e .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",_fa ); return _fa ;};_aad ._ed =_gfc ;_aad ._dg =uint64 (_gfc )<<16;if _fa =_aad .readByte ();_fa !=nil {return _fa ;};_aad ._dg <<=7;_aad ._ad -=7;_aad ._dc =0x8000;_aad ._ab ++;return nil ;};type DecoderStats struct{_aafg int32 ;_cgce int32 ;_cgdc []byte ;_cgcg []byte ; };func (_ccgb *Decoder )decodeIntBit (_ea *DecoderStats )(int ,error ){_ea .SetIndex (int32 (_ccgb ._g ));_fd ,_af :=_ccgb .DecodeBit (_ea );if _af !=nil {_e .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",_af ); return _fd ,_af ;};if _ccgb ._g < 256{_ccgb ._g =((_ccgb ._g < 0{return -_dcf ,nil ;};return 0,_ee .ErrOOB ;};func (_ga *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_ga ._g =1;var _agf uint64 ; for _agf =0;_agf < codeLen ;_agf ++{stats .SetIndex (int32 (_ga ._g ));_fg ,_adee :=_ga .DecodeBit (stats );if _adee !=nil {return 0,_adee ;};_ga ._g =(_ga ._g <<1)|int64 (_fg );};_cg :=_ga ._g -(1<