2022-07-13 21:28:43 +00:00

36 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 (_ba "fmt";_d "github.com/unidoc/unipdf/v3/common";_e "github.com/unidoc/unipdf/v3/internal/bitwise";_c "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_b "io";_bf "strings";);var (_bd =[][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 (_fb *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_fb ._cg =1;var _fc uint64 ;for _fc =0;_fc < codeLen ;_fc ++{stats .SetIndex (int32 (_fb ._cg ));_gc ,_ace :=_fb .DecodeBit (stats );if _ace !=nil {return 0,_ace ;};
_fb ._cg =(_fb ._cg <<1)|int64 (_gc );};_ga :=_fb ._cg -(1<<codeLen );return _ga ,nil ;};func (_cda *DecoderStats )Reset (){for _ecd :=0;_ecd < len (_cda ._dc );_ecd ++{_cda ._dc [_ecd ]=0;_cda ._cgc [_ecd ]=0;};};func (_cga *DecoderStats )cx ()byte {return _cga ._dc [_cga ._ddb ]};
func (_cc *DecoderStats )SetIndex (index int32 ){_cc ._ddb =index };func (_fg *Decoder )readByte ()error {if _fg ._eg .StreamPosition ()> _fg ._bfdg {if _ ,_bed :=_fg ._eg .Seek (-1,_b .SeekCurrent );_bed !=nil {return _bed ;};};_ee ,_gf :=_fg ._eg .ReadByte ();
if _gf !=nil {return _gf ;};_fg ._gg =_ee ;if _fg ._gg ==0xFF{_ad ,_efd :=_fg ._eg .ReadByte ();if _efd !=nil {return _efd ;};if _ad > 0x8F{_fg ._bfd +=0xFF00;_fg ._gge =8;if _ ,_ag :=_fg ._eg .Seek (-2,_b .SeekCurrent );_ag !=nil {return _ag ;};}else {_fg ._bfd +=uint64 (_ad )<<9;
_fg ._gge =7;};}else {_ee ,_gf =_fg ._eg .ReadByte ();if _gf !=nil {return _gf ;};_fg ._gg =_ee ;_fg ._bfd +=uint64 (_fg ._gg )<<8;_fg ._gge =8;};_fg ._bfd &=0xFFFFFFFFFF;return nil ;};func (_ec *Decoder )init ()error {_ec ._bfdg =_ec ._eg .StreamPosition ();
_fce ,_ff :=_ec ._eg .ReadByte ();if _ff !=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",_ff );return _ff ;};_ec ._gg =_fce ;_ec ._bfd =uint64 (_fce )<<16;
if _ff =_ec .readByte ();_ff !=nil {return _ff ;};_ec ._bfd <<=7;_ec ._gge -=7;_ec ._bg =0x8000;_ec ._bdg ++;return nil ;};func (_ada *DecoderStats )Copy ()*DecoderStats {_efe :=&DecoderStats {_ggf :_ada ._ggf ,_dc :make ([]byte ,_ada ._ggf )};for _eee :=0;
_eee < len (_ada ._dc );_eee ++{_efe ._dc [_eee ]=_ada ._dc [_eee ];};return _efe ;};type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ;_eg _e .StreamReader ;_gg uint8 ;_bfd uint64 ;_bg uint32 ;_cg int64 ;_gge int32 ;_bdg int32 ;_bfdg int64 ;
};func (_ddg *DecoderStats )Overwrite (dNew *DecoderStats ){for _afd :=0;_afd < len (_ddg ._dc );_afd ++{_ddg ._dc [_afd ]=dNew ._dc [_afd ];_ddg ._cgc [_afd ]=dNew ._cgc [_afd ];};};func (_dce *DecoderStats )getMps ()byte {return _dce ._cgc [_dce ._ddb ]};
func (_bfa *Decoder )decodeIntBit (_cd *DecoderStats )(int ,error ){_cd .SetIndex (int32 (_bfa ._cg ));_bac ,_cf :=_bfa .DecodeBit (_cd );if _cf !=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",_cf );
return _bac ,_cf ;};if _bfa ._cg < 256{_bfa ._cg =((_bfa ._cg <<uint64 (1))|int64 (_bac ))&0x1ff;}else {_bfa ._cg =(((_bfa ._cg <<uint64 (1)|int64 (_bac ))&511)|256)&0x1ff;};return _bac ,nil ;};func (_cb *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_ge ,_fd int32 ;
_ce ,_ac ,_be int ;_gd error ;);if stats ==nil {stats =NewStats (512,1);};_cb ._cg =1;_ac ,_gd =_cb .decodeIntBit (stats );if _gd !=nil {return 0,_gd ;};_ce ,_gd =_cb .decodeIntBit (stats );if _gd !=nil {return 0,_gd ;};if _ce ==1{_ce ,_gd =_cb .decodeIntBit (stats );
if _gd !=nil {return 0,_gd ;};if _ce ==1{_ce ,_gd =_cb .decodeIntBit (stats );if _gd !=nil {return 0,_gd ;};if _ce ==1{_ce ,_gd =_cb .decodeIntBit (stats );if _gd !=nil {return 0,_gd ;};if _ce ==1{_ce ,_gd =_cb .decodeIntBit (stats );if _gd !=nil {return 0,_gd ;
};if _ce ==1{_be =32;_fd =4436;}else {_be =12;_fd =340;};}else {_be =8;_fd =84;};}else {_be =6;_fd =20;};}else {_be =4;_fd =4;};}else {_be =2;_fd =0;};for _fe :=0;_fe < _be ;_fe ++{_ce ,_gd =_cb .decodeIntBit (stats );if _gd !=nil {return 0,_gd ;};_ge =(_ge <<1)|int32 (_ce );
};_ge +=_fd ;if _ac ==0{return _ge ,nil ;}else if _ac ==1&&_ge > 0{return -_ge ,nil ;};return 0,_c .ErrOOB ;};func New (r _e .StreamReader )(*Decoder ,error ){_cge :=&Decoder {_eg :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};
if _a :=_cge .init ();_a !=nil {return nil ,_a ;};return _cge ,nil ;};func NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_ddb :index ,_ggf :contextSize ,_dc :make ([]byte ,contextSize ),_cgc :make ([]byte ,contextSize )};
};func (_cgb *DecoderStats )String ()string {_gcf :=&_bf .Builder {};_gcf .WriteString (_ba .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_cgb ._dc )));for _ffa ,_de :=range _cgb ._dc {if _de !=0{_gcf .WriteString (_ba .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_ffa ,_de ));
};};return _gcf .String ();};func (_bbc *DecoderStats )toggleMps (){_bbc ._cgc [_bbc ._ddb ]^=1};func (_fca *Decoder )renormalize ()error {for {if _fca ._gge ==0{if _bfc :=_fca .readByte ();_bfc !=nil {return _bfc ;};};_fca ._bg <<=1;_fca ._bfd <<=1;_fca ._gge --;
if (_fca ._bg &0x8000)!=0{break ;};};_fca ._bfd &=0xffffffff;return nil ;};type DecoderStats struct{_ddb int32 ;_ggf int32 ;_dc []byte ;_cgc []byte ;};func (_da *Decoder )mpsExchange (_cgf *DecoderStats ,_bedc int32 )int {_bdb :=_cgf ._cgc [_cgf ._ddb ];
if _da ._bg < _bd [_bedc ][0]{if _bd [_bedc ][3]==1{_cgf .toggleMps ();};_cgf .setEntry (int (_bd [_bedc ][2]));return int (1-_bdb );};_cgf .setEntry (int (_bd [_bedc ][1]));return int (_bdb );};func (_df *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_ae int ;
_ef =_bd [stats .cx ()][0];_f =int32 (stats .cx ()););defer func (){_df ._bdg ++}();_df ._bg -=_ef ;if (_df ._bfd >>16)< uint64 (_ef ){_ae =_df .lpsExchange (stats ,_f ,_ef );if _aa :=_df .renormalize ();_aa !=nil {return 0,_aa ;};}else {_df ._bfd -=uint64 (_ef )<<16;
if (_df ._bg &0x8000)==0{_ae =_df .mpsExchange (stats ,_f );if _af :=_df .renormalize ();_af !=nil {return 0,_af ;};}else {_ae =int (stats .getMps ());};};return _ae ,nil ;};func (_gb *Decoder )lpsExchange (_dd *DecoderStats ,_gcg int32 ,_ed uint32 )int {_bfdc :=_dd .getMps ();
if _gb ._bg < _ed {_dd .setEntry (int (_bd [_gcg ][1]));_gb ._bg =_ed ;return int (_bfdc );};if _bd [_gcg ][3]==1{_dd .toggleMps ();};_dd .setEntry (int (_bd [_gcg ][2]));_gb ._bg =_ed ;return int (1-_bfdc );};func (_gfg *DecoderStats )setEntry (_cbe int ){_dff :=byte (_cbe &0x7f);
_gfg ._dc [_gfg ._ddb ]=_dff };