mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-05 19:30:30 +08:00
34 lines
7.8 KiB
Go
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 (_a "fmt";_aa "github.com/unidoc/unipdf/v3/common";_g "github.com/unidoc/unipdf/v3/internal/bitwise";_d "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_b "io";_be "strings";);func (_ggf *DecoderStats )SetIndex (index int32 ){_ggf ._aff =index };
|
|
func (_gbg *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_gbg ._bb =1;var _dfd uint64 ;for _dfd =0;_dfd < codeLen ;_dfd ++{stats .SetIndex (int32 (_gbg ._bb ));_de ,_cg :=_gbg .DecodeBit (stats );if _cg !=nil {return 0,_cg ;
|
|
};_gbg ._bb =(_gbg ._bb <<1)|int64 (_de );};_da :=_gbg ._bb -(1<<codeLen );return _da ,nil ;};func (_bd *Decoder )readByte ()error {if _bd ._fd .StreamPosition ()> _bd ._gb {if _ ,_cb :=_bd ._fd .Seek (-1,_b .SeekCurrent );_cb !=nil {return _cb ;};};_afa ,_cgd :=_bd ._fd .ReadByte ();
|
|
if _cgd !=nil {return _cgd ;};_bd ._c =_afa ;if _bd ._c ==0xFF{_ege ,_bea :=_bd ._fd .ReadByte ();if _bea !=nil {return _bea ;};if _ege > 0x8F{_bd ._cf +=0xFF00;_bd ._ag =8;if _ ,_ea :=_bd ._fd .Seek (-2,_b .SeekCurrent );_ea !=nil {return _ea ;};}else {_bd ._cf +=uint64 (_ege )<<9;
|
|
_bd ._ag =7;};}else {_afa ,_cgd =_bd ._fd .ReadByte ();if _cgd !=nil {return _cgd ;};_bd ._c =_afa ;_bd ._cf +=uint64 (_bd ._c )<<8;_bd ._ag =8;};_bd ._cf &=0xFFFFFFFFFF;return nil ;};func NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_aff :index ,_ee :contextSize ,_bc :make ([]byte ,contextSize ),_eff :make ([]byte ,contextSize )};
|
|
};func (_bf *DecoderStats )Reset (){for _cbc :=0;_cbc < len (_bf ._bc );_cbc ++{_bf ._bc [_cbc ]=0;_bf ._eff [_cbc ]=0;};};func (_ge *DecoderStats )Overwrite (dNew *DecoderStats ){for _abcb :=0;_abcb < len (_ge ._bc );_abcb ++{_ge ._bc [_abcb ]=dNew ._bc [_abcb ];
|
|
_ge ._eff [_abcb ]=dNew ._eff [_abcb ];};};func (_afd *Decoder )init ()error {_afd ._gb =_afd ._fd .StreamPosition ();_bg ,_gba :=_afd ._fd .ReadByte ();if _gba !=nil {_aa .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",_gba );
|
|
return _gba ;};_afd ._c =_bg ;_afd ._cf =uint64 (_bg )<<16;if _gba =_afd .readByte ();_gba !=nil {return _gba ;};_afd ._cf <<=7;_afd ._ag -=7;_afd ._db =0x8000;_afd ._gg ++;return nil ;};func (_cfbd *Decoder )lpsExchange (_cbg *DecoderStats ,_ef int32 ,_acb uint32 )int {_efe :=_cbg .getMps ();
|
|
if _cfbd ._db < _acb {_cbg .setEntry (int (_f [_ef ][1]));_cfbd ._db =_acb ;return int (_efe );};if _f [_ef ][3]==1{_cbg .toggleMps ();};_cbg .setEntry (int (_f [_ef ][2]));_cfbd ._db =_acb ;return int (1-_efe );};func (_ba *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_af int ;
|
|
_ec =_f [stats .cx ()][0];_afb =int32 (stats .cx ()););defer func (){_ba ._gg ++}();_ba ._db -=_ec ;if (_ba ._cf >>16)< uint64 (_ec ){_af =_ba .lpsExchange (stats ,_afb ,_ec );if _ab :=_ba .renormalize ();_ab !=nil {return 0,_ab ;};}else {_ba ._cf -=uint64 (_ec )<<16;
|
|
if (_ba ._db &0x8000)==0{_af =_ba .mpsExchange (stats ,_afb );if _dd :=_ba .renormalize ();_dd !=nil {return 0,_dd ;};}else {_af =int (stats .getMps ());};};return _af ,nil ;};type DecoderStats struct{_aff int32 ;_ee int32 ;_bc []byte ;_eff []byte ;};type Decoder struct{ContextSize []uint32 ;
|
|
ReferedToContextSize []uint32 ;_fd _g .StreamReader ;_c uint8 ;_cf uint64 ;_db uint32 ;_bb int64 ;_ag int32 ;_gg int32 ;_gb int64 ;};func (_agd *Decoder )mpsExchange (_egc *DecoderStats ,_gabf int32 )int {_bgf :=_egc ._eff [_egc ._aff ];if _agd ._db < _f [_gabf ][0]{if _f [_gabf ][3]==1{_egc .toggleMps ();
|
|
};_egc .setEntry (int (_f [_gabf ][2]));return int (1-_bgf );};_egc .setEntry (int (_f [_gabf ][1]));return int (_bgf );};func (_fbf *DecoderStats )setEntry (_gfb int ){_acc :=byte (_gfb &0x7f);_fbf ._bc [_fbf ._aff ]=_acc };func (_cfb *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_df ,_gab int32 ;
|
|
_cfg ,_fb ,_ae int ;_eg error ;);if stats ==nil {stats =NewStats (512,1);};_cfb ._bb =1;_fb ,_eg =_cfb .decodeIntBit (stats );if _eg !=nil {return 0,_eg ;};_cfg ,_eg =_cfb .decodeIntBit (stats );if _eg !=nil {return 0,_eg ;};if _cfg ==1{_cfg ,_eg =_cfb .decodeIntBit (stats );
|
|
if _eg !=nil {return 0,_eg ;};if _cfg ==1{_cfg ,_eg =_cfb .decodeIntBit (stats );if _eg !=nil {return 0,_eg ;};if _cfg ==1{_cfg ,_eg =_cfb .decodeIntBit (stats );if _eg !=nil {return 0,_eg ;};if _cfg ==1{_cfg ,_eg =_cfb .decodeIntBit (stats );if _eg !=nil {return 0,_eg ;
|
|
};if _cfg ==1{_ae =32;_gab =4436;}else {_ae =12;_gab =340;};}else {_ae =8;_gab =84;};}else {_ae =6;_gab =20;};}else {_ae =4;_gab =4;};}else {_ae =2;_gab =0;};for _fdd :=0;_fdd < _ae ;_fdd ++{_cfg ,_eg =_cfb .decodeIntBit (stats );if _eg !=nil {return 0,_eg ;
|
|
};_df =(_df <<1)|int32 (_cfg );};_df +=_gab ;if _fb ==0{return _df ,nil ;}else if _fb ==1&&_df > 0{return -_df ,nil ;};return 0,_d .ErrOOB ;};func (_bag *DecoderStats )toggleMps (){_bag ._eff [_bag ._aff ]^=1};func (_cbb *Decoder )decodeIntBit (_deb *DecoderStats )(int ,error ){_deb .SetIndex (int32 (_cbb ._bb ));
|
|
_deg ,_dea :=_cbb .DecodeBit (_deb );if _dea !=nil {_aa .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",_dea );
|
|
return _deg ,_dea ;};if _cbb ._bb < 256{_cbb ._bb =((_cbb ._bb <<uint64 (1))|int64 (_deg ))&0x1ff;}else {_cbb ._bb =(((_cbb ._bb <<uint64 (1)|int64 (_deg ))&511)|256)&0x1ff;};return _deg ,nil ;};func New (r _g .StreamReader )(*Decoder ,error ){_ga :=&Decoder {_fd :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};
|
|
if _ac :=_ga .init ();_ac !=nil {return nil ,_ac ;};return _ga ,nil ;};func (_eaa *DecoderStats )cx ()byte {return _eaa ._bc [_eaa ._aff ]};func (_ff *DecoderStats )getMps ()byte {return _ff ._eff [_ff ._aff ]};var (_f =[][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 (_dec *DecoderStats )String ()string {_dc :=&_be .Builder {};_dc .WriteString (_a .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_dec ._bc )));for _fa ,_dfg :=range _dec ._bc {if _dfg !=0{_dc .WriteString (_a .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_fa ,_dfg ));
|
|
};};return _dc .String ();};func (_gf *Decoder )renormalize ()error {for {if _gf ._ag ==0{if _egd :=_gf .readByte ();_egd !=nil {return _egd ;};};_gf ._db <<=1;_gf ._cf <<=1;_gf ._ag --;if (_gf ._db &0x8000)!=0{break ;};};_gf ._cf &=0xffffffff;return nil ;
|
|
};func (_bbd *DecoderStats )Copy ()*DecoderStats {_dbg :=&DecoderStats {_ee :_bbd ._ee ,_bc :make ([]byte ,_bbd ._ee )};for _abc :=0;_abc < len (_bbd ._bc );_abc ++{_dbg ._bc [_abc ]=_bbd ._bc [_abc ];};return _dbg ;}; |