2021-04-17 13:46:54 +00:00

36 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 (_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 <<uint64 (1))|int64 (_efe ))&0x1ff;}else {_fb ._ad =(((_fb ._ad <<uint64 (1)|int64 (_efe ))&511)|256)&0x1ff;};return _efe ,nil ;};func (_bec *DecoderStats )String ()string {_ecf :=&_gf .Builder {};
_ecf .WriteString (_e .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_bec ._ac )));for _dgf ,_ace :=range _bec ._ac {if _ace !=0{_ecf .WriteString (_e .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_dgf ,_ace ));
};};return _ecf .String ();};func (_cg *DecoderStats )SetIndex (index int32 ){_cg ._bd =index };func New (r _cf .StreamReader )(*Decoder ,error ){_fd :=&Decoder {_dfg :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};if _fe :=_fd .init ();
_fe !=nil {return nil ,_fe ;};return _fd ,nil ;};func (_def *Decoder )lpsExchange (_agf *DecoderStats ,_abg int32 ,_dg uint32 )int {_gbd :=_agf .getMps ();if _def ._da < _dg {_agf .setEntry (int (_f [_abg ][1]));_def ._da =_dg ;return int (_gbd );};if _f [_abg ][3]==1{_agf .toggleMps ();
};_agf .setEntry (int (_f [_abg ][2]));_def ._da =_dg ;return int (1-_gbd );};func (_fce *DecoderStats )Copy ()*DecoderStats {_ded :=&DecoderStats {_fde :_fce ._fde ,_ac :make ([]byte ,_fce ._fde )};for _aa :=0;_aa < len (_fce ._ac );_aa ++{_ded ._ac [_aa ]=_fce ._ac [_aa ];
};return _ded ;};func (_gc *DecoderStats )Overwrite (dNew *DecoderStats ){for _ec :=0;_ec < len (_gc ._ac );_ec ++{_gc ._ac [_ec ]=dNew ._ac [_ec ];_gc ._gag [_ec ]=dNew ._gag [_ec ];};};func (_bca *DecoderStats )cx ()byte {return _bca ._ac [_bca ._bd ]};
func (_gea *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_gea ._ad =1;var _fc uint64 ;for _fc =0;_fc < codeLen ;_fc ++{stats .SetIndex (int32 (_gea ._ad ));_gec ,_ga :=_gea .DecodeBit (stats );if _ga !=nil {return 0,_ga ;};
_gea ._ad =(_gea ._ad <<1)|int64 (_gec );};_de :=_gea ._ad -(1<<codeLen );return _de ,nil ;};type DecoderStats struct{_bd int32 ;_fde int32 ;_ac []byte ;_gag []byte ;};func (_acb *DecoderStats )setEntry (_aced int ){_adb :=byte (_aced &0x7f);_acb ._ac [_acb ._bd ]=_adb };