36 lines
7.8 KiB
Go
Raw Normal View History

2020-08-27 21:45:09 +00:00
//
// 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/
2021-05-31 17:17:31 +00:00
package arithmetic ;import (_a "fmt";_fd "github.com/unidoc/unipdf/v3/common";_g "github.com/unidoc/unipdf/v3/internal/bitwise";_fdf "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_f "io";_cf "strings";);func (_be *Decoder )lpsExchange (_cfb *DecoderStats ,_cg int32 ,_dgg uint32 )int {_fcc :=_cfb .getMps ();
if _be ._b < _dgg {_cfb .setEntry (int (_cc [_cg ][1]));_be ._b =_dgg ;return int (_fcc );};if _cc [_cg ][3]==1{_cfb .toggleMps ();};_cfb .setEntry (int (_cc [_cg ][2]));_be ._b =_dgg ;return int (1-_fcc );};func (_dgd *DecoderStats )Overwrite (dNew *DecoderStats ){for _ed :=0;
_ed < len (_dgd ._agf );_ed ++{_dgd ._agf [_ed ]=dNew ._agf [_ed ];_dgd ._bea [_ed ]=dNew ._bea [_ed ];};};func NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_acg :index ,_gf :contextSize ,_agf :make ([]byte ,contextSize ),_bea :make ([]byte ,contextSize )};
};func (_dfa *DecoderStats )Reset (){for _aed :=0;_aed < len (_dfa ._agf );_aed ++{_dfa ._agf [_aed ]=0;_dfa ._bea [_aed ]=0;};};func (_aff *DecoderStats )Copy ()*DecoderStats {_cbg :=&DecoderStats {_gf :_aff ._gf ,_agf :make ([]byte ,_aff ._gf )};for _ad :=0;
_ad < len (_aff ._agf );_ad ++{_cbg ._agf [_ad ]=_aff ._agf [_ad ];};return _cbg ;};func (_aab *Decoder )readByte ()error {if _aab ._ga .StreamPosition ()> _aab ._gb {if _ ,_fgd :=_aab ._ga .Seek (-1,_f .SeekCurrent );_fgd !=nil {return _fgd ;};};_dc ,_fc :=_aab ._ga .ReadByte ();
if _fc !=nil {return _fc ;};_aab ._gab =_dc ;if _aab ._gab ==0xFF{_gaa ,_bce :=_aab ._ga .ReadByte ();if _bce !=nil {return _bce ;};if _gaa > 0x8F{_aab ._d +=0xFF00;_aab ._bf =8;if _ ,_dec :=_aab ._ga .Seek (-2,_f .SeekCurrent );_dec !=nil {return _dec ;
};}else {_aab ._d +=uint64 (_gaa )<<9;_aab ._bf =7;};}else {_dc ,_fc =_aab ._ga .ReadByte ();if _fc !=nil {return _fc ;};_aab ._gab =_dc ;_aab ._d +=uint64 (_aab ._gab )<<8;_aab ._bf =8;};_aab ._d &=0xFFFFFFFFFF;return nil ;};func (_dfb *Decoder )init ()error {_dfb ._gb =_dfb ._ga .StreamPosition ();
_acf ,_af :=_dfb ._ga .ReadByte ();if _af !=nil {_fd .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",_af );return _af ;};_dfb ._gab =_acf ;_dfb ._d =uint64 (_acf )<<16;
if _af =_dfb .readByte ();_af !=nil {return _af ;};_dfb ._d <<=7;_dfb ._bf -=7;_dfb ._b =0x8000;_dfb ._e ++;return nil ;};func (_ddf *DecoderStats )SetIndex (index int32 ){_ddf ._acg =index };type DecoderStats struct{_acg int32 ;_gf int32 ;_agf []byte ;
_bea []byte ;};func (_ab *DecoderStats )setEntry (_cbd int ){_eg :=byte (_cbd &0x7f);_ab ._agf [_ab ._acg ]=_eg };func (_gg *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_gg ._ac =1;var _bda uint64 ;for _bda =0;_bda < codeLen ;
_bda ++{stats .SetIndex (int32 (_gg ._ac ));_ba ,_dg :=_gg .DecodeBit (stats );if _dg !=nil {return 0,_dg ;};_gg ._ac =(_gg ._ac <<1)|int64 (_ba );};_fge :=_gg ._ac -(1<<codeLen );return _fge ,nil ;};func (_afcf *DecoderStats )getMps ()byte {return _afcf ._bea [_afcf ._acg ]};
func (_dcb *DecoderStats )String ()string {_ee :=&_cf .Builder {};_ee .WriteString (_a .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_dcb ._agf )));for _ce ,_ead :=range _dcb ._agf {if _ead !=0{_ee .WriteString (_a .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_ce ,_ead ));
};};return _ee .String ();};type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ;_ga _g .StreamReader ;_gab uint8 ;_d uint64 ;_b uint32 ;_ac int64 ;_bf int32 ;_e int32 ;_gb int64 ;};func (_afc *Decoder )decodeIntBit (_cba *DecoderStats )(int ,error ){_cba .SetIndex (int32 (_afc ._ac ));
_aad ,_eb :=_afc .DecodeBit (_cba );if _eb !=nil {_fd .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",_eb );
return _aad ,_eb ;};if _afc ._ac < 256{_afc ._ac =((_afc ._ac <<uint64 (1))|int64 (_aad ))&0x1ff;}else {_afc ._ac =(((_afc ._ac <<uint64 (1)|int64 (_aad ))&511)|256)&0x1ff;};return _aad ,nil ;};func (_bg *Decoder )renormalize ()error {for {if _bg ._bf ==0{if _bgf :=_bg .readByte ();
_bgf !=nil {return _bgf ;};};_bg ._b <<=1;_bg ._d <<=1;_bg ._bf --;if (_bg ._b &0x8000)!=0{break ;};};_bg ._d &=0xffffffff;return nil ;};func (_ff *DecoderStats )toggleMps (){_ff ._bea [_ff ._acg ]^=1};func (_de *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_aa int ;
_bd =_cc [stats .cx ()][0];_fa =int32 (stats .cx ()););defer func (){_de ._e ++}();_de ._b -=_bd ;if (_de ._d >>16)< uint64 (_bd ){_aa =_de .lpsExchange (stats ,_fa ,_bd );if _ea :=_de .renormalize ();_ea !=nil {return 0,_ea ;};}else {_de ._d -=uint64 (_bd )<<16;
if (_de ._b &0x8000)==0{_aa =_de .mpsExchange (stats ,_fa );if _bfg :=_de .renormalize ();_bfg !=nil {return 0,_bfg ;};}else {_aa =int (stats .getMps ());};};return _aa ,nil ;};func (_eaf *DecoderStats )cx ()byte {return _eaf ._agf [_eaf ._acg ]};func (_aca *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_cb ,_gbb int32 ;
_bc ,_dd ,_ag int ;_bca error ;);if stats ==nil {stats =NewStats (512,1);};_aca ._ac =1;_dd ,_bca =_aca .decodeIntBit (stats );if _bca !=nil {return 0,_bca ;};_bc ,_bca =_aca .decodeIntBit (stats );if _bca !=nil {return 0,_bca ;};if _bc ==1{_bc ,_bca =_aca .decodeIntBit (stats );
if _bca !=nil {return 0,_bca ;};if _bc ==1{_bc ,_bca =_aca .decodeIntBit (stats );if _bca !=nil {return 0,_bca ;};if _bc ==1{_bc ,_bca =_aca .decodeIntBit (stats );if _bca !=nil {return 0,_bca ;};if _bc ==1{_bc ,_bca =_aca .decodeIntBit (stats );if _bca !=nil {return 0,_bca ;
};if _bc ==1{_ag =32;_gbb =4436;}else {_ag =12;_gbb =340;};}else {_ag =8;_gbb =84;};}else {_ag =6;_gbb =20;};}else {_ag =4;_gbb =4;};}else {_ag =2;_gbb =0;};for _ccb :=0;_ccb < _ag ;_ccb ++{_bc ,_bca =_aca .decodeIntBit (stats );if _bca !=nil {return 0,_bca ;
};_cb =(_cb <<1)|int32 (_bc );};_cb +=_gbb ;if _dd ==0{return _cb ,nil ;}else if _dd ==1&&_cb > 0{return -_cb ,nil ;};return 0,_fdf .ErrOOB ;};func New (r _g .StreamReader )(*Decoder ,error ){_df :=&Decoder {_ga :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};
if _fg :=_df .init ();_fg !=nil {return nil ,_fg ;};return _df ,nil ;};var (_cc =[][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 (_cbc *Decoder )mpsExchange (_bab *DecoderStats ,_ec int32 )int {_ae :=_bab ._bea [_bab ._acg ];if _cbc ._b < _cc [_ec ][0]{if _cc [_ec ][3]==1{_bab .toggleMps ();};_bab .setEntry (int (_cc [_ec ][2]));return int (1-_ae );};_bab .setEntry (int (_cc [_ec ][1]));
return int (_ae );};