2021-06-21 14:01:56 +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 (_b "fmt";_ge "github.com/unidoc/unipdf/v3/common";_c "github.com/unidoc/unipdf/v3/internal/bitwise";_bd "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_a "io";_d "strings";);type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ;
_bf _c .StreamReader ;_e uint8 ;_ab uint64 ;_bb uint32 ;_af int64 ;_cg int32 ;_f int32 ;_fg int64 ;};var (_gb =[][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 {_aac :index ,_gcb :contextSize ,_aeb :make ([]byte ,contextSize ),_edgb :make ([]byte ,contextSize )};};func (_be *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_be ._af =1;
var _afc uint64 ;for _afc =0;_afc < codeLen ;_afc ++{stats .SetIndex (int32 (_be ._af ));_fc ,_cga :=_be .DecodeBit (stats );if _cga !=nil {return 0,_cga ;};_be ._af =(_be ._af <<1)|int64 (_fc );};_bde :=_be ._af -(1<<codeLen );return _bde ,nil ;};func (_aaf *DecoderStats )String ()string {_dff :=&_d .Builder {};
_dff .WriteString (_b .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_aaf ._aeb )));for _fcd ,_ffg :=range _aaf ._aeb {if _ffg !=0{_dff .WriteString (_b .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_fcd ,_ffg ));
};};return _dff .String ();};func New (r _c .StreamReader )(*Decoder ,error ){_ae :=&Decoder {_bf :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};if _cc :=_ae .init ();_cc !=nil {return nil ,_cc ;};return _ae ,nil ;};func (_ba *Decoder )init ()error {_ba ._fg =_ba ._bf .StreamPosition ();
_cge ,_bef :=_ba ._bf .ReadByte ();if _bef !=nil {_ge .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",_bef );return _bef ;};_ba ._e =_cge ;_ba ._ab =uint64 (_cge )<<16;
if _bef =_ba .readByte ();_bef !=nil {return _bef ;};_ba ._ab <<=7;_ba ._cg -=7;_ba ._bb =0x8000;_ba ._f ++;return nil ;};func (_cfc *DecoderStats )setEntry (_eba int ){_dfc :=byte (_eba &0x7f);_cfc ._aeb [_cfc ._aac ]=_dfc };func (_cf *DecoderStats )Copy ()*DecoderStats {_cb :=&DecoderStats {_gcb :_cf ._gcb ,_aeb :make ([]byte ,_cf ._gcb )};
for _bdf :=0;_bdf < len (_cf ._aeb );_bdf ++{_cb ._aeb [_bdf ]=_cf ._aeb [_bdf ];};return _cb ;};func (_ga *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_dcd ,_fe int32 ;_ce ,_gag ,_eb int ;_gd error ;);if stats ==nil {stats =NewStats (512,1);
};_ga ._af =1;_gag ,_gd =_ga .decodeIntBit (stats );if _gd !=nil {return 0,_gd ;};_ce ,_gd =_ga .decodeIntBit (stats );if _gd !=nil {return 0,_gd ;};if _ce ==1{_ce ,_gd =_ga .decodeIntBit (stats );if _gd !=nil {return 0,_gd ;};if _ce ==1{_ce ,_gd =_ga .decodeIntBit (stats );
if _gd !=nil {return 0,_gd ;};if _ce ==1{_ce ,_gd =_ga .decodeIntBit (stats );if _gd !=nil {return 0,_gd ;};if _ce ==1{_ce ,_gd =_ga .decodeIntBit (stats );if _gd !=nil {return 0,_gd ;};if _ce ==1{_eb =32;_fe =4436;}else {_eb =12;_fe =340;};}else {_eb =8;
_fe =84;};}else {_eb =6;_fe =20;};}else {_eb =4;_fe =4;};}else {_eb =2;_fe =0;};for _afd :=0;_afd < _eb ;_afd ++{_ce ,_gd =_ga .decodeIntBit (stats );if _gd !=nil {return 0,_gd ;};_dcd =(_dcd <<1)|int32 (_ce );};_dcd +=_fe ;if _gag ==0{return _dcd ,nil ;
}else if _gag ==1&&_dcd > 0{return -_dcd ,nil ;};return 0,_bd .ErrOOB ;};type DecoderStats struct{_aac int32 ;_gcb int32 ;_aeb []byte ;_edgb []byte ;};func (_bc *DecoderStats )Reset (){for _ac :=0;_ac < len (_bc ._aeb );_ac ++{_bc ._aeb [_ac ]=0;_bc ._edgb [_ac ]=0;
};};func (_fcg *DecoderStats )toggleMps (){_fcg ._edgb [_fcg ._aac ]^=1};func (_gec *Decoder )renormalize ()error {for {if _gec ._cg ==0{if _dfg :=_gec .readByte ();_dfg !=nil {return _dfg ;};};_gec ._bb <<=1;_gec ._ab <<=1;_gec ._cg --;if (_gec ._bb &0x8000)!=0{break ;
};};_gec ._ab &=0xffffffff;return nil ;};func (_ec *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_df int ;_ff =_gb [stats .cx ()][0];_de =int32 (stats .cx ()););defer func (){_ec ._f ++}();_ec ._bb -=_ff ;if (_ec ._ab >>16)< uint64 (_ff ){_df =_ec .lpsExchange (stats ,_de ,_ff );
if _ed :=_ec .renormalize ();_ed !=nil {return 0,_ed ;};}else {_ec ._ab -=uint64 (_ff )<<16;if (_ec ._bb &0x8000)==0{_df =_ec .mpsExchange (stats ,_de );if _dc :=_ec .renormalize ();_dc !=nil {return 0,_dc ;};}else {_df =int (stats .getMps ());};};return _df ,nil ;
};func (_gc *Decoder )lpsExchange (_dbda *DecoderStats ,_bff int32 ,_egc uint32 )int {_edg :=_dbda .getMps ();if _gc ._bb < _egc {_dbda .setEntry (int (_gb [_bff ][1]));_gc ._bb =_egc ;return int (_edg );};if _gb [_bff ][3]==1{_dbda .toggleMps ();};_dbda .setEntry (int (_gb [_bff ][2]));
_gc ._bb =_egc ;return int (1-_edg );};func (_deg *DecoderStats )Overwrite (dNew *DecoderStats ){for _cd :=0;_cd < len (_deg ._aeb );_cd ++{_deg ._aeb [_cd ]=dNew ._aeb [_cd ];_deg ._edgb [_cd ]=dNew ._edgb [_cd ];};};func (_cbf *DecoderStats )cx ()byte {return _cbf ._aeb [_cbf ._aac ]};
func (_dbd *Decoder )decodeIntBit (_aa *DecoderStats )(int ,error ){_aa .SetIndex (int32 (_dbd ._af ));_ad ,_dfb :=_dbd .DecodeBit (_aa );if _dfb !=nil {_ge .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",_dfb );
return _ad ,_dfb ;};if _dbd ._af < 256{_dbd ._af =((_dbd ._af <<uint64 (1))|int64 (_ad ))&0x1ff;}else {_dbd ._af =(((_dbd ._af <<uint64 (1)|int64 (_ad ))&511)|256)&0x1ff;};return _ad ,nil ;};func (_aeg *DecoderStats )getMps ()byte {return _aeg ._edgb [_aeg ._aac ]};
func (_gba *Decoder )readByte ()error {if _gba ._bf .StreamPosition ()> _gba ._fg {if _ ,_ca :=_gba ._bf .Seek (-1,_a .SeekCurrent );_ca !=nil {return _ca ;};};_bg ,_gdc :=_gba ._bf .ReadByte ();if _gdc !=nil {return _gdc ;};_gba ._e =_bg ;if _gba ._e ==0xFF{_da ,_db :=_gba ._bf .ReadByte ();
if _db !=nil {return _db ;};if _da > 0x8F{_gba ._ab +=0xFF00;_gba ._cg =8;if _ ,_dea :=_gba ._bf .Seek (-2,_a .SeekCurrent );_dea !=nil {return _dea ;};}else {_gba ._ab +=uint64 (_da )<<9;_gba ._cg =7;};}else {_bg ,_gdc =_gba ._bf .ReadByte ();if _gdc !=nil {return _gdc ;
};_gba ._e =_bg ;_gba ._ab +=uint64 (_gba ._e )<<8;_gba ._cg =8;};_gba ._ab &=0xFFFFFFFFFF;return nil ;};func (_ccb *DecoderStats )SetIndex (index int32 ){_ccb ._aac =index };func (_dg *Decoder )mpsExchange (_bbe *DecoderStats ,_bfg int32 )int {_eg :=_bbe ._edgb [_bbe ._aac ];
if _dg ._bb < _gb [_bfg ][0]{if _gb [_bfg ][3]==1{_bbe .toggleMps ();};_bbe .setEntry (int (_gb [_bfg ][2]));return int (1-_eg );};_bbe .setEntry (int (_gb [_bfg ][1]));return int (_eg );};