2021-09-23 22:37:42 +00:00

34 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 (_d "fmt";_cg "github.com/unidoc/unipdf/v3/common";_e "github.com/unidoc/unipdf/v3/internal/bitwise";_de "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_c "io";_ge "strings";);type Decoder struct{ContextSize []uint32 ;
ReferedToContextSize []uint32 ;_ga _e .StreamReader ;_f uint8 ;_a uint64 ;_cf uint32 ;_ca int64 ;_ac int32 ;_cff int32 ;_eb int64 ;};func (_dbg *DecoderStats )Overwrite (dNew *DecoderStats ){for _ecc :=0;_ecc < len (_dbg ._ebff );_ecc ++{_dbg ._ebff [_ecc ]=dNew ._ebff [_ecc ];
_dbg ._ffc [_ecc ]=dNew ._ffc [_ecc ];};};func (_bfe *Decoder )renormalize ()error {for {if _bfe ._ac ==0{if _bd :=_bfe .readByte ();_bd !=nil {return _bd ;};};_bfe ._cf <<=1;_bfe ._a <<=1;_bfe ._ac --;if (_bfe ._cf &0x8000)!=0{break ;};};_bfe ._a &=0xffffffff;
return nil ;};func (_ebe *DecoderStats )SetIndex (index int32 ){_ebe ._bbf =index };func (_cde *Decoder )decodeIntBit (_dc *DecoderStats )(int ,error ){_dc .SetIndex (int32 (_cde ._ca ));_ebfg ,_bb :=_cde .DecodeBit (_dc );if _bb !=nil {_cg .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",_bb );
return _ebfg ,_bb ;};if _cde ._ca < 256{_cde ._ca =((_cde ._ca <<uint64 (1))|int64 (_ebfg ))&0x1ff;}else {_cde ._ca =(((_cde ._ca <<uint64 (1)|int64 (_ebfg ))&511)|256)&0x1ff;};return _ebfg ,nil ;};func (_dca *Decoder )mpsExchange (_fce *DecoderStats ,_da int32 )int {_gf :=_fce ._ffc [_fce ._bbf ];
if _dca ._cf < _ec [_da ][0]{if _ec [_da ][3]==1{_fce .toggleMps ();};_fce .setEntry (int (_ec [_da ][2]));return int (1-_gf );};_fce .setEntry (int (_ec [_da ][1]));return int (_gf );};func (_be *Decoder )init ()error {_be ._eb =_be ._ga .StreamPosition ();
_cdc ,_fbf :=_be ._ga .ReadByte ();if _fbf !=nil {_cg .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",_fbf );return _fbf ;};_be ._f =_cdc ;_be ._a =uint64 (_cdc )<<16;
if _fbf =_be .readByte ();_fbf !=nil {return _fbf ;};_be ._a <<=7;_be ._ac -=7;_be ._cf =0x8000;_be ._cff ++;return nil ;};func (_ae *Decoder )lpsExchange (_ea *DecoderStats ,_bfeg int32 ,_gfd uint32 )int {_cdb :=_ea .getMps ();if _ae ._cf < _gfd {_ea .setEntry (int (_ec [_bfeg ][1]));
_ae ._cf =_gfd ;return int (_cdb );};if _ec [_bfeg ][3]==1{_ea .toggleMps ();};_ea .setEntry (int (_ec [_bfeg ][2]));_ae ._cf =_gfd ;return int (1-_cdb );};func (_dff *DecoderStats )getMps ()byte {return _dff ._ffc [_dff ._bbf ]};var (_ec =[][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 (_agg *DecoderStats )Copy ()*DecoderStats {_gb :=&DecoderStats {_fa :_agg ._fa ,_ebff :make ([]byte ,_agg ._fa )};for _fg :=0;_fg < len (_agg ._ebff );_fg ++{_gb ._ebff [_fg ]=_agg ._ebff [_fg ];};return _gb ;};func (_bf *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_bf ._ca =1;
var _ebf uint64 ;for _ebf =0;_ebf < codeLen ;_ebf ++{stats .SetIndex (int32 (_bf ._ca ));_db ,_abf :=_bf .DecodeBit (stats );if _abf !=nil {return 0,_abf ;};_bf ._ca =(_bf ._ca <<1)|int64 (_db );};_cbg :=_bf ._ca -(1<<codeLen );return _cbg ,nil ;};func (_gea *DecoderStats )setEntry (_cdg int ){_abd :=byte (_cdg &0x7f);
_gea ._ebff [_gea ._bbf ]=_abd };func (_gdb *DecoderStats )String ()string {_gg :=&_ge .Builder {};_gg .WriteString (_d .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_gdb ._ebff )));for _age ,_bbb :=range _gdb ._ebff {if _bbb !=0{_gg .WriteString (_d .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_age ,_bbb ));
};};return _gg .String ();};func NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_bbf :index ,_fa :contextSize ,_ebff :make ([]byte ,contextSize ),_ffc :make ([]byte ,contextSize )};};func (_b *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_ed int ;
_fe =_ec [stats .cx ()][0];_cb =int32 (stats .cx ()););defer func (){_b ._cff ++}();_b ._cf -=_fe ;if (_b ._a >>16)< uint64 (_fe ){_ed =_b .lpsExchange (stats ,_cb ,_fe );if _bg :=_b .renormalize ();_bg !=nil {return 0,_bg ;};}else {_b ._a -=uint64 (_fe )<<16;
if (_b ._cf &0x8000)==0{_ed =_b .mpsExchange (stats ,_cb );if _cfd :=_b .renormalize ();_cfd !=nil {return 0,_cfd ;};}else {_ed =int (stats .getMps ());};};return _ed ,nil ;};func (_dcd *DecoderStats )cx ()byte {return _dcd ._ebff [_dcd ._bbf ]};func (_gd *Decoder )readByte ()error {if _gd ._ga .StreamPosition ()> _gd ._eb {if _ ,_fbd :=_gd ._ga .Seek (-1,_c .SeekCurrent );
_fbd !=nil {return _fbd ;};};_edf ,_fc :=_gd ._ga .ReadByte ();if _fc !=nil {return _fc ;};_gd ._f =_edf ;if _gd ._f ==0xFF{_ce ,_ff :=_gd ._ga .ReadByte ();if _ff !=nil {return _ff ;};if _ce > 0x8F{_gd ._a +=0xFF00;_gd ._ac =8;if _ ,_ceg :=_gd ._ga .Seek (-2,_c .SeekCurrent );
_ceg !=nil {return _ceg ;};}else {_gd ._a +=uint64 (_ce )<<9;_gd ._ac =7;};}else {_edf ,_fc =_gd ._ga .ReadByte ();if _fc !=nil {return _fc ;};_gd ._f =_edf ;_gd ._a +=uint64 (_gd ._f )<<8;_gd ._ac =8;};_gd ._a &=0xFFFFFFFFFF;return nil ;};func (_bed *DecoderStats )toggleMps (){_bed ._ffc [_bed ._bbf ]^=1};
func (_cfg *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_ab ,_dec int32 ;_dg ,_dgb ,_cd int ;_bgg error ;);if stats ==nil {stats =NewStats (512,1);};_cfg ._ca =1;_dgb ,_bgg =_cfg .decodeIntBit (stats );if _bgg !=nil {return 0,_bgg ;};
_dg ,_bgg =_cfg .decodeIntBit (stats );if _bgg !=nil {return 0,_bgg ;};if _dg ==1{_dg ,_bgg =_cfg .decodeIntBit (stats );if _bgg !=nil {return 0,_bgg ;};if _dg ==1{_dg ,_bgg =_cfg .decodeIntBit (stats );if _bgg !=nil {return 0,_bgg ;};if _dg ==1{_dg ,_bgg =_cfg .decodeIntBit (stats );
if _bgg !=nil {return 0,_bgg ;};if _dg ==1{_dg ,_bgg =_cfg .decodeIntBit (stats );if _bgg !=nil {return 0,_bgg ;};if _dg ==1{_cd =32;_dec =4436;}else {_cd =12;_dec =340;};}else {_cd =8;_dec =84;};}else {_cd =6;_dec =20;};}else {_cd =4;_dec =4;};}else {_cd =2;
_dec =0;};for _df :=0;_df < _cd ;_df ++{_dg ,_bgg =_cfg .decodeIntBit (stats );if _bgg !=nil {return 0,_bgg ;};_ab =(_ab <<1)|int32 (_dg );};_ab +=_dec ;if _dgb ==0{return _ab ,nil ;}else if _dgb ==1&&_ab > 0{return -_ab ,nil ;};return 0,_de .ErrOOB ;};
func (_dd *DecoderStats )Reset (){for _dad :=0;_dad < len (_dd ._ebff );_dad ++{_dd ._ebff [_dad ]=0;_dd ._ffc [_dad ]=0;};};func New (r _e .StreamReader )(*Decoder ,error ){_ag :=&Decoder {_ga :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};
if _fb :=_ag .init ();_fb !=nil {return nil ,_fb ;};return _ag ,nil ;};type DecoderStats struct{_bbf int32 ;_fa int32 ;_ebff []byte ;_ffc []byte ;};