2022-02-05 21:34:53 +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 (_a "fmt";_ae "github.com/unidoc/unipdf/v3/common";_gc "github.com/unidoc/unipdf/v3/internal/bitwise";_af "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_e "io";_g "strings";);type DecoderStats struct{_cbdd int32 ;_gce int32 ;
_feg []byte ;_fd []byte ;};func (_bfa *Decoder )lpsExchange (_cdf *DecoderStats ,_bge int32 ,_gea uint32 )int {_bdb :=_cdf .getMps ();if _bfa ._c < _gea {_cdf .setEntry (int (_bf [_bge ][1]));_bfa ._c =_gea ;return int (_bdb );};if _bf [_bge ][3]==1{_cdf .toggleMps ();
};_cdf .setEntry (int (_bf [_bge ][2]));_bfa ._c =_gea ;return int (1-_bdb );};func (_gcg *DecoderStats )Overwrite (dNew *DecoderStats ){for _aad :=0;_aad < len (_gcg ._feg );_aad ++{_gcg ._feg [_aad ]=dNew ._feg [_aad ];_gcg ._fd [_aad ]=dNew ._fd [_aad ];
};};func (_dc *DecoderStats )Reset (){for _fc :=0;_fc < len (_dc ._feg );_fc ++{_dc ._feg [_fc ]=0;_dc ._fd [_fc ]=0;};};var (_bf =[][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 {_cbdd :index ,_gce :contextSize ,_feg :make ([]byte ,contextSize ),_fd :make ([]byte ,contextSize )};};func (_fg *Decoder )init ()error {_fg ._ba =_fg ._f .StreamPosition ();
_de ,_eba :=_fg ._f .ReadByte ();if _eba !=nil {_ae .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",_eba );return _eba ;};_fg ._aed =_de ;_fg ._gb =uint64 (_de )<<16;
if _eba =_fg .readByte ();_eba !=nil {return _eba ;};_fg ._gb <<=7;_fg ._eb -=7;_fg ._c =0x8000;_fg ._fa ++;return nil ;};func (_ebd *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_fe int ;_ea =_bf [stats .cx ()][0];_ec =int32 (stats .cx ());
);defer func (){_ebd ._fa ++}();_ebd ._c -=_ea ;if (_ebd ._gb >>16)< uint64 (_ea ){_fe =_ebd .lpsExchange (stats ,_ec ,_ea );if _bd :=_ebd .renormalize ();_bd !=nil {return 0,_bd ;};}else {_ebd ._gb -=uint64 (_ea )<<16;if (_ebd ._c &0x8000)==0{_fe =_ebd .mpsExchange (stats ,_ec );
if _fae :=_ebd .renormalize ();_fae !=nil {return 0,_fae ;};}else {_fe =int (stats .getMps ());};};return _fe ,nil ;};func (_aa *DecoderStats )Copy ()*DecoderStats {_ebg :=&DecoderStats {_gce :_aa ._gce ,_feg :make ([]byte ,_aa ._gce )};for _bfd :=0;_bfd < len (_aa ._feg );
_bfd ++{_ebg ._feg [_bfd ]=_aa ._feg [_bfd ];};return _ebg ;};func (_bgf *DecoderStats )cx ()byte {return _bgf ._feg [_bgf ._cbdd ]};func (_eaa *Decoder )readByte ()error {if _eaa ._f .StreamPosition ()> _eaa ._ba {if _ ,_fgg :=_eaa ._f .Seek (-1,_e .SeekCurrent );
_fgg !=nil {return _fgg ;};};_caac ,_cc :=_eaa ._f .ReadByte ();if _cc !=nil {return _cc ;};_eaa ._aed =_caac ;if _eaa ._aed ==0xFF{_ggc ,_cb :=_eaa ._f .ReadByte ();if _cb !=nil {return _cb ;};if _ggc > 0x8F{_eaa ._gb +=0xFF00;_eaa ._eb =8;if _ ,_fggc :=_eaa ._f .Seek (-2,_e .SeekCurrent );
_fggc !=nil {return _fggc ;};}else {_eaa ._gb +=uint64 (_ggc )<<9;_eaa ._eb =7;};}else {_caac ,_cc =_eaa ._f .ReadByte ();if _cc !=nil {return _cc ;};_eaa ._aed =_caac ;_eaa ._gb +=uint64 (_eaa ._aed )<<8;_eaa ._eb =8;};_eaa ._gb &=0xFFFFFFFFFF;return nil ;
};func (_dd *Decoder )mpsExchange (_cba *DecoderStats ,_cbd int32 )int {_cec :=_cba ._fd [_cba ._cbdd ];if _dd ._c < _bf [_cbd ][0]{if _bf [_cbd ][3]==1{_cba .toggleMps ();};_cba .setEntry (int (_bf [_cbd ][2]));return int (1-_cec );};_cba .setEntry (int (_bf [_cbd ][1]));
return int (_cec );};func New (r _gc .StreamReader )(*Decoder ,error ){_ad :=&Decoder {_f :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};if _ag :=_ad .init ();_ag !=nil {return nil ,_ag ;};return _ad ,nil ;};func (_caa *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_caa ._d =1;
var _cd uint64 ;for _cd =0;_cd < codeLen ;_cd ++{stats .SetIndex (int32 (_caa ._d ));_bg ,_bcd :=_caa .DecodeBit (stats );if _bcd !=nil {return 0,_bcd ;};_caa ._d =(_caa ._d <<1)|int64 (_bg );};_gbe :=_caa ._d -(1<<codeLen );return _gbe ,nil ;};func (_df *DecoderStats )toggleMps (){_df ._fd [_df ._cbdd ]^=1};
func (_aeb *DecoderStats )SetIndex (index int32 ){_aeb ._cbdd =index };func (_ged *Decoder )decodeIntBit (_gfe *DecoderStats )(int ,error ){_gfe .SetIndex (int32 (_ged ._d ));_ef ,_ce :=_ged .DecodeBit (_gfe );if _ce !=nil {_ae .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",_ce );
return _ef ,_ce ;};if _ged ._d < 256{_ged ._d =((_ged ._d <<uint64 (1))|int64 (_ef ))&0x1ff;}else {_ged ._d =(((_ged ._d <<uint64 (1)|int64 (_ef ))&511)|256)&0x1ff;};return _ef ,nil ;};type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ;
_f _gc .StreamReader ;_aed uint8 ;_gb uint64 ;_c uint32 ;_d int64 ;_eb int32 ;_fa int32 ;_ba int64 ;};func (_ca *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_agb ,_eag int32 ;_ge ,_ff ,_bc int ;_gg error ;);if stats ==nil {stats =NewStats (512,1);
};_ca ._d =1;_ff ,_gg =_ca .decodeIntBit (stats );if _gg !=nil {return 0,_gg ;};_ge ,_gg =_ca .decodeIntBit (stats );if _gg !=nil {return 0,_gg ;};if _ge ==1{_ge ,_gg =_ca .decodeIntBit (stats );if _gg !=nil {return 0,_gg ;};if _ge ==1{_ge ,_gg =_ca .decodeIntBit (stats );
if _gg !=nil {return 0,_gg ;};if _ge ==1{_ge ,_gg =_ca .decodeIntBit (stats );if _gg !=nil {return 0,_gg ;};if _ge ==1{_ge ,_gg =_ca .decodeIntBit (stats );if _gg !=nil {return 0,_gg ;};if _ge ==1{_bc =32;_eag =4436;}else {_bc =12;_eag =340;};}else {_bc =8;
_eag =84;};}else {_bc =6;_eag =20;};}else {_bc =4;_eag =4;};}else {_bc =2;_eag =0;};for _fb :=0;_fb < _bc ;_fb ++{_ge ,_gg =_ca .decodeIntBit (stats );if _gg !=nil {return 0,_gg ;};_agb =(_agb <<1)|int32 (_ge );};_agb +=_eag ;if _ff ==0{return _agb ,nil ;
}else if _ff ==1&&_agb > 0{return -_agb ,nil ;};return 0,_af .ErrOOB ;};func (_deb *DecoderStats )getMps ()byte {return _deb ._fd [_deb ._cbdd ]};func (_ee *Decoder )renormalize ()error {for {if _ee ._eb ==0{if _gf :=_ee .readByte ();_gf !=nil {return _gf ;
};};_ee ._c <<=1;_ee ._gb <<=1;_ee ._eb --;if (_ee ._c &0x8000)!=0{break ;};};_ee ._gb &=0xffffffff;return nil ;};func (_da *DecoderStats )String ()string {_gfc :=&_g .Builder {};_gfc .WriteString (_a .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_da ._feg )));
for _dcf ,_fce :=range _da ._feg {if _fce !=0{_gfc .WriteString (_a .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_dcf ,_fce ));};};return _gfc .String ();};func (_gbc *DecoderStats )setEntry (_fcb int ){_gfcb :=byte (_fcb &0x7f);
_gbc ._feg [_gbc ._cbdd ]=_gfcb ;};