2021-08-13 01:33:42 +00:00

35 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";_ee "github.com/unidoc/unipdf/v3/common";_c "github.com/unidoc/unipdf/v3/internal/bitwise";_dc "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_b "io";_d "strings";);func (_bga *Decoder )readByte ()error {if _bga ._f .StreamPosition ()> _bga ._bb {if _ ,_cd :=_bga ._f .Seek (-1,_b .SeekCurrent );
_cd !=nil {return _cd ;};};_ea ,_fd :=_bga ._f .ReadByte ();if _fd !=nil {return _fd ;};_bga ._ca =_ea ;if _bga ._ca ==0xFF{_ge ,_gfa :=_bga ._f .ReadByte ();if _gfa !=nil {return _gfa ;};if _ge > 0x8F{_bga ._de +=0xFF00;_bga ._ed =8;if _ ,_bf :=_bga ._f .Seek (-2,_b .SeekCurrent );
_bf !=nil {return _bf ;};}else {_bga ._de +=uint64 (_ge )<<9;_bga ._ed =7;};}else {_ea ,_fd =_bga ._f .ReadByte ();if _fd !=nil {return _fd ;};_bga ._ca =_ea ;_bga ._de +=uint64 (_bga ._ca )<<8;_bga ._ed =8;};_bga ._de &=0xFFFFFFFFFF;return nil ;};var (_gc =[][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 (_gbd *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_gbd ._dd =1;var _gf uint64 ;for _gf =0;_gf < codeLen ;_gf ++{stats .SetIndex (int32 (_gbd ._dd ));_fb ,_gcb :=_gbd .DecodeBit (stats );if _gcb !=nil {return 0,_gcb ;
};_gbd ._dd =(_gbd ._dd <<1)|int64 (_fb );};_deb :=_gbd ._dd -(1<<codeLen );return _deb ,nil ;};func (_cdc *Decoder )lpsExchange (_gfab *DecoderStats ,_cdg int32 ,_dcd uint32 )int {_gbc :=_gfab .getMps ();if _cdc ._cc < _dcd {_gfab .setEntry (int (_gc [_cdg ][1]));
_cdc ._cc =_dcd ;return int (_gbc );};if _gc [_cdg ][3]==1{_gfab .toggleMps ();};_gfab .setEntry (int (_gc [_cdg ][2]));_cdc ._cc =_dcd ;return int (1-_gbc );};func (_gbca *DecoderStats )getMps ()byte {return _gbca ._aff [_gbca ._dg ]};func (_ce *DecoderStats )Copy ()*DecoderStats {_ged :=&DecoderStats {_efb :_ce ._efb ,_ddf :make ([]byte ,_ce ._efb )};
for _be :=0;_be < len (_ce ._ddf );_be ++{_ged ._ddf [_be ]=_ce ._ddf [_be ];};return _ged ;};func (_da *Decoder )init ()error {_da ._bb =_da ._f .StreamPosition ();_bbf ,_bg :=_da ._f .ReadByte ();if _bg !=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",_bg );
return _bg ;};_da ._ca =_bbf ;_da ._de =uint64 (_bbf )<<16;if _bg =_da .readByte ();_bg !=nil {return _bg ;};_da ._de <<=7;_da ._ed -=7;_da ._cc =0x8000;_da ._a ++;return nil ;};func (_eba *Decoder )renormalize ()error {for {if _eba ._ed ==0{if _caa :=_eba .readByte ();
_caa !=nil {return _caa ;};};_eba ._cc <<=1;_eba ._de <<=1;_eba ._ed --;if (_eba ._cc &0x8000)!=0{break ;};};_eba ._de &=0xffffffff;return nil ;};type DecoderStats struct{_dg int32 ;_efb int32 ;_ddf []byte ;_aff []byte ;};func NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_dg :index ,_efb :contextSize ,_ddf :make ([]byte ,contextSize ),_aff :make ([]byte ,contextSize )};
};func (_bcba *DecoderStats )toggleMps (){_bcba ._aff [_bcba ._dg ]^=1};func New (r _c .StreamReader )(*Decoder ,error ){_cg :=&Decoder {_f :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};if _dee :=_cg .init ();_dee !=nil {return nil ,_dee ;
};return _cg ,nil ;};func (_bcc *DecoderStats )Reset (){for _ebd :=0;_ebd < len (_bcc ._ddf );_ebd ++{_bcc ._ddf [_ebd ]=0;_bcc ._aff [_ebd ]=0;};};func (_aaa *DecoderStats )setEntry (_feb int ){_cbb :=byte (_feb &0x7f);_aaa ._ddf [_aaa ._dg ]=_cbb };func (_bge *DecoderStats )Overwrite (dNew *DecoderStats ){for _gd :=0;
_gd < len (_bge ._ddf );_gd ++{_bge ._ddf [_gd ]=dNew ._ddf [_gd ];_bge ._aff [_gd ]=dNew ._aff [_gd ];};};type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ;_f _c .StreamReader ;_ca uint8 ;_de uint64 ;_cc uint32 ;_dd int64 ;_ed int32 ;
_a int32 ;_bb int64 ;};func (_gaa *DecoderStats )cx ()byte {return _gaa ._ddf [_gaa ._dg ]};func (_eb *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_bcb ,_fe int32 ;_ef ,_af ,_aa int ;_cca error ;);if stats ==nil {stats =NewStats (512,1);
};_eb ._dd =1;_af ,_cca =_eb .decodeIntBit (stats );if _cca !=nil {return 0,_cca ;};_ef ,_cca =_eb .decodeIntBit (stats );if _cca !=nil {return 0,_cca ;};if _ef ==1{_ef ,_cca =_eb .decodeIntBit (stats );if _cca !=nil {return 0,_cca ;};if _ef ==1{_ef ,_cca =_eb .decodeIntBit (stats );
if _cca !=nil {return 0,_cca ;};if _ef ==1{_ef ,_cca =_eb .decodeIntBit (stats );if _cca !=nil {return 0,_cca ;};if _ef ==1{_ef ,_cca =_eb .decodeIntBit (stats );if _cca !=nil {return 0,_cca ;};if _ef ==1{_aa =32;_fe =4436;}else {_aa =12;_fe =340;};}else {_aa =8;
_fe =84;};}else {_aa =6;_fe =20;};}else {_aa =4;_fe =4;};}else {_aa =2;_fe =0;};for _cgg :=0;_cgg < _aa ;_cgg ++{_ef ,_cca =_eb .decodeIntBit (stats );if _cca !=nil {return 0,_cca ;};_bcb =(_bcb <<1)|int32 (_ef );};_bcb +=_fe ;if _af ==0{return _bcb ,nil ;
}else if _af ==1&&_bcb > 0{return -_bcb ,nil ;};return 0,_dc .ErrOOB ;};func (_ega *DecoderStats )String ()string {_fdg :=&_d .Builder {};_fdg .WriteString (_e .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_ega ._ddf )));
for _cce ,_cb :=range _ega ._ddf {if _cb !=0{_fdg .WriteString (_e .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_cce ,_cb ));};};return _fdg .String ();};func (_bc *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_cf int ;
_ag =_gc [stats .cx ()][0];_fa =int32 (stats .cx ()););defer func (){_bc ._a ++}();_bc ._cc -=_ag ;if (_bc ._de >>16)< uint64 (_ag ){_cf =_bc .lpsExchange (stats ,_fa ,_ag );if _dea :=_bc .renormalize ();_dea !=nil {return 0,_dea ;};}else {_bc ._de -=uint64 (_ag )<<16;
if (_bc ._cc &0x8000)==0{_cf =_bc .mpsExchange (stats ,_fa );if _gb :=_bc .renormalize ();_gb !=nil {return 0,_gb ;};}else {_cf =int (stats .getMps ());};};return _cf ,nil ;};func (_bff *Decoder )mpsExchange (_ddb *DecoderStats ,_ba int32 )int {_bfa :=_ddb ._aff [_ddb ._dg ];
if _bff ._cc < _gc [_ba ][0]{if _gc [_ba ][3]==1{_ddb .toggleMps ();};_ddb .setEntry (int (_gc [_ba ][2]));return int (1-_bfa );};_ddb .setEntry (int (_gc [_ba ][1]));return int (_bfa );};func (_ae *Decoder )decodeIntBit (_fad *DecoderStats )(int ,error ){_fad .SetIndex (int32 (_ae ._dd ));
_eg ,_bd :=_ae .DecodeBit (_fad );if _bd !=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",_bd );
return _eg ,_bd ;};if _ae ._dd < 256{_ae ._dd =((_ae ._dd <<uint64 (1))|int64 (_eg ))&0x1ff;}else {_ae ._dd =(((_ae ._dd <<uint64 (1)|int64 (_eg ))&511)|256)&0x1ff;};return _eg ,nil ;};func (_ff *DecoderStats )SetIndex (index int32 ){_ff ._dg =index };