2024-04-30 12:24:05 +00:00

36 lines
7.7 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 (_ad "fmt";_e "github.com/unidoc/unipdf/v3/common";_ed "github.com/unidoc/unipdf/v3/internal/bitwise";_edf "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_g "io";_a "strings";);type Decoder struct{ContextSize []uint32 ;
ReferedToContextSize []uint32 ;_eb *_ed .Reader ;_dc uint8 ;_gg uint64 ;_b uint32 ;_c int64 ;_gf int32 ;_dcf int32 ;_be int64 ;};func (_abb *DecoderStats )toggleMps (){_abb ._bc [_abb ._gade ]^=1};func (_bdb *DecoderStats )SetIndex (index int32 ){_bdb ._gade =index };
func (_ffd *Decoder )mpsExchange (_bec *DecoderStats ,_cag int32 )int {_gdg :=_bec ._bc [_bec ._gade ];if _ffd ._b < _f [_cag ][0]{if _f [_cag ][3]==1{_bec .toggleMps ();};_bec .setEntry (int (_f [_cag ][2]));return int (1-_gdg );};_bec .setEntry (int (_f [_cag ][1]));
return int (_gdg );};func (_gae *DecoderStats )String ()string {_aac :=&_a .Builder {};_aac .WriteString (_ad .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_gae ._fg )));for _dcc ,_dfa :=range _gae ._fg {if _dfa !=0{_aac .WriteString (_ad .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_dcc ,_dfa ));
};};return _aac .String ();};func (_fgd *DecoderStats )Reset (){for _ab :=0;_ab < len (_fgd ._fg );_ab ++{_fgd ._fg [_ab ]=0;_fgd ._bc [_ab ]=0;};};func (_gge *Decoder )init ()error {_gge ._be =_gge ._eb .AbsolutePosition ();_bd ,_edff :=_gge ._eb .ReadByte ();
if _edff !=nil {_e .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",_edff );return _edff ;};_gge ._dc =_bd ;_gge ._gg =uint64 (_bd )<<16;if _edff =_gge .readByte ();
_edff !=nil {return _edff ;};_gge ._gg <<=7;_gge ._gf -=7;_gge ._b =0x8000;_gge ._dcf ++;return nil ;};func (_baa *DecoderStats )Overwrite (dNew *DecoderStats ){for _bdf :=0;_bdf < len (_baa ._fg );_bdf ++{_baa ._fg [_bdf ]=dNew ._fg [_bdf ];_baa ._bc [_bdf ]=dNew ._bc [_bdf ];
};};func (_af *Decoder )decodeIntBit (_ae *DecoderStats )(int ,error ){_ae .SetIndex (int32 (_af ._c ));_cbd ,_cg :=_af .DecodeBit (_ae );if _cg !=nil {_e .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",_cg );
return _cbd ,_cg ;};if _af ._c < 256{_af ._c =((_af ._c <<uint64 (1))|int64 (_cbd ))&0x1ff;}else {_af ._c =(((_af ._c <<uint64 (1)|int64 (_cbd ))&511)|256)&0x1ff;};return _cbd ,nil ;};func (_afd *DecoderStats )getMps ()byte {return _afd ._bc [_afd ._gade ]};
func (_cf *DecoderStats )setEntry (_deb int ){_bfg :=byte (_deb &0x7f);_cf ._fg [_cf ._gade ]=_bfg };func New (r *_ed .Reader )(*Decoder ,error ){_bb :=&Decoder {_eb :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};if _aa :=_bb .init ();
_aa !=nil {return nil ,_aa ;};return _bb ,nil ;};func (_bg *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_fc ,_gad int32 ;_cbe ,_ff ,_gc int ;_da error ;);if stats ==nil {stats =NewStats (512,1);};_bg ._c =1;_ff ,_da =_bg .decodeIntBit (stats );
if _da !=nil {return 0,_da ;};_cbe ,_da =_bg .decodeIntBit (stats );if _da !=nil {return 0,_da ;};if _cbe ==1{_cbe ,_da =_bg .decodeIntBit (stats );if _da !=nil {return 0,_da ;};if _cbe ==1{_cbe ,_da =_bg .decodeIntBit (stats );if _da !=nil {return 0,_da ;
};if _cbe ==1{_cbe ,_da =_bg .decodeIntBit (stats );if _da !=nil {return 0,_da ;};if _cbe ==1{_cbe ,_da =_bg .decodeIntBit (stats );if _da !=nil {return 0,_da ;};if _cbe ==1{_gc =32;_gad =4436;}else {_gc =12;_gad =340;};}else {_gc =8;_gad =84;};}else {_gc =6;
_gad =20;};}else {_gc =4;_gad =4;};}else {_gc =2;_gad =0;};for _ca :=0;_ca < _gc ;_ca ++{_cbe ,_da =_bg .decodeIntBit (stats );if _da !=nil {return 0,_da ;};_fc =(_fc <<1)|int32 (_cbe );};_fc +=_gad ;if _ff ==0{return _fc ,nil ;}else if _ff ==1&&_fc > 0{return -_fc ,nil ;
};return 0,_edf .ErrOOB ;};func (_fe *Decoder )readByte ()error {if _fe ._eb .AbsolutePosition ()> _fe ._be {if _ ,_ebd :=_fe ._eb .Seek (-1,_g .SeekCurrent );_ebd !=nil {return _ebd ;};};_bbb ,_ba :=_fe ._eb .ReadByte ();if _ba !=nil {return _ba ;};_fe ._dc =_bbb ;
if _fe ._dc ==0xFF{_fff ,_fed :=_fe ._eb .ReadByte ();if _fed !=nil {return _fed ;};if _fff > 0x8F{_fe ._gg +=0xFF00;_fe ._gf =8;if _ ,_bf :=_fe ._eb .Seek (-2,_g .SeekCurrent );_bf !=nil {return _bf ;};}else {_fe ._gg +=uint64 (_fff )<<9;_fe ._gf =7;};
}else {_bbb ,_ba =_fe ._eb .ReadByte ();if _ba !=nil {return _ba ;};_fe ._dc =_bbb ;_fe ._gg +=uint64 (_fe ._dc )<<8;_fe ._gf =8;};_fe ._gg &=0xFFFFFFFFFF;return nil ;};func (_cdc *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_cdc ._c =1;
var _fa uint64 ;for _fa =0;_fa < codeLen ;_fa ++{stats .SetIndex (int32 (_cdc ._c ));_df ,_gdf :=_cdc .DecodeBit (stats );if _gdf !=nil {return 0,_gdf ;};_cdc ._c =(_cdc ._c <<1)|int64 (_df );};_ag :=_cdc ._c -(1<<codeLen );return _ag ,nil ;};type DecoderStats struct{_gade int32 ;
_gcg int32 ;_fg []byte ;_bc []byte ;};func (_bfa *DecoderStats )Copy ()*DecoderStats {_ggb :=&DecoderStats {_gcg :_bfa ._gcg ,_fg :make ([]byte ,_bfa ._gcg )};copy (_ggb ._fg ,_bfa ._fg );return _ggb ;};func (_fcf *DecoderStats )cx ()byte {return _fcf ._fg [_fcf ._gade ]};
func (_gd *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_ef int ;_cb =_f [stats .cx ()][0];_cd =int32 (stats .cx ()););defer func (){_gd ._dcf ++}();_gd ._b -=_cb ;if (_gd ._gg >>16)< uint64 (_cb ){_ef =_gd .lpsExchange (stats ,_cd ,_cb );
if _ga :=_gd .renormalize ();_ga !=nil {return 0,_ga ;};}else {_gd ._gg -=uint64 (_cb )<<16;if (_gd ._b &0x8000)==0{_ef =_gd .mpsExchange (stats ,_cd );if _cba :=_gd .renormalize ();_cba !=nil {return 0,_cba ;};}else {_ef =int (stats .getMps ());};};return _ef ,nil ;
};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 (_bbbd *Decoder )renormalize ()error {for {if _bbbd ._gf ==0{if _ec :=_bbbd .readByte ();_ec !=nil {return _ec ;};};_bbbd ._b <<=1;_bbbd ._gg <<=1;_bbbd ._gf --;if (_bbbd ._b &0x8000)!=0{break ;};};_bbbd ._gg &=0xffffffff;return nil ;};func (_fca *Decoder )lpsExchange (_dea *DecoderStats ,_fd int32 ,_eda uint32 )int {_bbd :=_dea .getMps ();
if _fca ._b < _eda {_dea .setEntry (int (_f [_fd ][1]));_fca ._b =_eda ;return int (_bbd );};if _f [_fd ][3]==1{_dea .toggleMps ();};_dea .setEntry (int (_f [_fd ][2]));_fca ._b =_eda ;return int (1-_bbd );};func NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_gade :index ,_gcg :contextSize ,_fg :make ([]byte ,contextSize ),_bc :make ([]byte ,contextSize )};
};