// // 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 (_e "fmt";_d "github.com/unidoc/unipdf/v3/common";_cf "github.com/unidoc/unipdf/v3/internal/bitwise";_df "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_c "io";_gf "strings";);func (_cb *Decoder )renormalize ()error {for {if _cb ._dd ==0{if _dff :=_cb .readByte (); _dff !=nil {return _dff ;};};_cb ._da <<=1;_cb ._a <<=1;_cb ._dd --;if (_cb ._da &0x8000)!=0{break ;};};_cb ._a &=0xffffffff;return nil ;};func (_ca *Decoder )mpsExchange (_fab *DecoderStats ,_gad int32 )int {_ag :=_fab ._gag [_fab ._bd ];if _ca ._da < _f [_gad ][0]{if _f [_gad ][3]==1{_fab .toggleMps (); };_fab .setEntry (int (_f [_gad ][2]));return int (1-_ag );};_fab .setEntry (int (_f [_gad ][1]));return int (_ag );};var (_f =[][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 (_gbe *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_bf ,_gfe int32 ;_eff ,_ee ,_bg int ;_dab error ;);if stats ==nil {stats =NewStats (512,1);};_gbe ._ad =1;_ee ,_dab =_gbe .decodeIntBit (stats );if _dab !=nil {return 0,_dab ;}; _eff ,_dab =_gbe .decodeIntBit (stats );if _dab !=nil {return 0,_dab ;};if _eff ==1{_eff ,_dab =_gbe .decodeIntBit (stats );if _dab !=nil {return 0,_dab ;};if _eff ==1{_eff ,_dab =_gbe .decodeIntBit (stats );if _dab !=nil {return 0,_dab ;};if _eff ==1{_eff ,_dab =_gbe .decodeIntBit (stats ); if _dab !=nil {return 0,_dab ;};if _eff ==1{_eff ,_dab =_gbe .decodeIntBit (stats );if _dab !=nil {return 0,_dab ;};if _eff ==1{_bg =32;_gfe =4436;}else {_bg =12;_gfe =340;};}else {_bg =8;_gfe =84;};}else {_bg =6;_gfe =20;};}else {_bg =4;_gfe =4;};}else {_bg =2; _gfe =0;};for _ae :=0;_ae < _bg ;_ae ++{_eff ,_dab =_gbe .decodeIntBit (stats );if _dab !=nil {return 0,_dab ;};_bf =(_bf <<1)|int32 (_eff );};_bf +=_gfe ;if _ee ==0{return _bf ,nil ;}else if _ee ==1&&_bf > 0{return -_bf ,nil ;};return 0,_df .ErrOOB ;}; func (_gff *DecoderStats )getMps ()byte {return _gff ._gag [_gff ._bd ]};func NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_bd :index ,_fde :contextSize ,_ac :make ([]byte ,contextSize ),_gag :make ([]byte ,contextSize )}; };func (_db *Decoder )init ()error {_db ._gb =_db ._dfg .StreamPosition ();_be ,_cdf :=_db ._dfg .ReadByte ();if _cdf !=nil {_d .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",_cdf ); return _cdf ;};_db ._ge =_be ;_db ._a =uint64 (_be )<<16;if _cdf =_db .readByte ();_cdf !=nil {return _cdf ;};_db ._a <<=7;_db ._dd -=7;_db ._da =0x8000;_db ._daa ++;return nil ;};func (_daaa *Decoder )readByte ()error {if _daaa ._dfg .StreamPosition ()> _daaa ._gb {if _ ,_af :=_daaa ._dfg .Seek (-1,_c .SeekCurrent ); _af !=nil {return _af ;};};_ba ,_bae :=_daaa ._dfg .ReadByte ();if _bae !=nil {return _bae ;};_daaa ._ge =_ba ;if _daaa ._ge ==0xFF{_fcb ,_bfe :=_daaa ._dfg .ReadByte ();if _bfe !=nil {return _bfe ;};if _fcb > 0x8F{_daaa ._a +=0xFF00;_daaa ._dd =8;if _ ,_cdfb :=_daaa ._dfg .Seek (-2,_c .SeekCurrent ); _cdfb !=nil {return _cdfb ;};}else {_daaa ._a +=uint64 (_fcb )<<9;_daaa ._dd =7;};}else {_ba ,_bae =_daaa ._dfg .ReadByte ();if _bae !=nil {return _bae ;};_daaa ._ge =_ba ;_daaa ._a +=uint64 (_daaa ._ge )<<8;_daaa ._dd =8;};_daaa ._a &=0xFFFFFFFFFF;return nil ; };func (_gfc *DecoderStats )Reset (){for _cff :=0;_cff < len (_gfc ._ac );_cff ++{_gfc ._ac [_cff ]=0;_gfc ._gag [_cff ]=0;};};func (_cd *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_gef int ;_b =_f [stats .cx ()][0];_bc =int32 (stats .cx ()); );defer func (){_cd ._daa ++}();_cd ._da -=_b ;if (_cd ._a >>16)< uint64 (_b ){_gef =_cd .lpsExchange (stats ,_bc ,_b );if _ef :=_cd .renormalize ();_ef !=nil {return 0,_ef ;};}else {_cd ._a -=uint64 (_b )<<16;if (_cd ._da &0x8000)==0{_gef =_cd .mpsExchange (stats ,_bc ); if _gefe :=_cd .renormalize ();_gefe !=nil {return 0,_gefe ;};}else {_gef =int (stats .getMps ());};};return _gef ,nil ;};func (_fec *DecoderStats )toggleMps (){_fec ._gag [_fec ._bd ]^=1};type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ; _dfg _cf .StreamReader ;_ge uint8 ;_a uint64 ;_da uint32 ;_ad int64 ;_dd int32 ;_daa int32 ;_gb int64 ;};func (_fb *Decoder )decodeIntBit (_fa *DecoderStats )(int ,error ){_fa .SetIndex (int32 (_fb ._ad ));_efe ,_daab :=_fb .DecodeBit (_fa );if _daab !=nil {_d .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",_daab ); return _efe ,_daab ;};if _fb ._ad < 256{_fb ._ad =((_fb ._ad <