2020-10-12 14:17:59 +00:00

12 lines
7.7 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 (_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<<codeLen );return _bc ,nil ;};var (_c =[][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 NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_eg :index ,_be :contextSize ,_bdg :make ([]byte ,contextSize ),_de :make ([]byte ,contextSize )};};func (_gff *Decoder )renormalize ()error {for {if _gff ._ef ==0{if _aeg :=_gff .readByte ();_aeg !=nil {return _aeg ;};};_gff ._d <<=1;_gff ._g <<=1;_gff ._ef --;if (_gff ._d &0x8000)!=0{break ;};};_gff ._g &=0xffffffff;return nil ;};func (_cae *Decoder )lpsExchange (_daf *DecoderStats ,_ada int32 ,_eee uint32 )int {_fbc :=_daf .getMps ();if _cae ._d < _eee {_daf .setEntry (int (_c [_ada ][1]));_cae ._d =_eee ;return int (_fbc );};if _c [_ada ][3]==1{_daf .toggleMps ();};_daf .setEntry (int (_c [_ada ][2]));_cae ._d =_eee ;return int (1-_fbc );};func (_ebe *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_a int ;_ge =_c [stats .cx ()][0];_ab =int32 (stats .cx ()););defer func (){_ebe ._fc ++}();_ebe ._d -=_ge ;if (_ebe ._g >>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 <<uint64 (1))|int64 (_gfd ))&0x1ff;}else {_gfb ._cg =(((_gfb ._cg <<uint64 (1)|int64 (_gfd ))&511)|256)&0x1ff;};return _gfd ,nil ;};func (_ac *DecoderStats )String ()string {_feg :=&_ea .Builder {};_feg .WriteString (_eb .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_ac ._bdg )));for _cff ,_cdc :=range _ac ._bdg {if _cdc !=0{_feg .WriteString (_eb .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_cff ,_cdc ));};};return _feg .String ();};func (_cf *Decoder )readByte ()error {if _cf ._f .StreamPosition ()> _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 ]};