2021-04-06 22:35:37 +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 (_d "fmt";_b "github.com/unidoc/unipdf/v3/common";_ce "github.com/unidoc/unipdf/v3/internal/bitwise";_a "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_c "io";_cd "strings";);func New (r _ce .StreamReader )(*Decoder ,error ){_fb :=&Decoder {_df :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};
if _cdd :=_fb .init ();_cdd !=nil {return nil ,_cdd ;};return _fb ,nil ;};func (_fcg *DecoderStats )Overwrite (dNew *DecoderStats ){for _gdc :=0;_gdc < len (_fcg ._gbb );_gdc ++{_fcg ._gbb [_gdc ]=dNew ._gbb [_gdc ];_fcg ._adb [_gdc ]=dNew ._adb [_gdc ];
};};func NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_fbe :index ,_bb :contextSize ,_gbb :make ([]byte ,contextSize ),_adb :make ([]byte ,contextSize )};};func (_gb *Decoder )readByte ()error {if _gb ._df .StreamPosition ()> _gb ._bee {if _ ,_cad :=_gb ._df .Seek (-1,_c .SeekCurrent );
_cad !=nil {return _cad ;};};_cee ,_afb :=_gb ._df .ReadByte ();if _afb !=nil {return _afb ;};_gb ._be =_cee ;if _gb ._be ==0xFF{_fe ,_gg :=_gb ._df .ReadByte ();if _gg !=nil {return _gg ;};if _fe > 0x8F{_gb ._ec +=0xFF00;_gb ._dg =8;if _ ,_fge :=_gb ._df .Seek (-2,_c .SeekCurrent );
_fge !=nil {return _fge ;};}else {_gb ._ec +=uint64 (_fe )<<9;_gb ._dg =7;};}else {_cee ,_afb =_gb ._df .ReadByte ();if _afb !=nil {return _afb ;};_gb ._be =_cee ;_gb ._ec +=uint64 (_gb ._be )<<8;_gb ._dg =8;};_gb ._ec &=0xFFFFFFFFFF;return nil ;};func (_ggc *Decoder )decodeIntBit (_fgeg *DecoderStats )(int ,error ){_fgeg .SetIndex (int32 (_ggc ._dc ));
_fc ,_cb :=_ggc .DecodeBit (_fgeg );if _cb !=nil {_b .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",_cb );
return _fc ,_cb ;};if _ggc ._dc < 256{_ggc ._dc =((_ggc ._dc <<uint64 (1))|int64 (_fc ))&0x1ff;}else {_ggc ._dc =(((_ggc ._dc <<uint64 (1)|int64 (_fc ))&511)|256)&0x1ff;};return _fc ,nil ;};type DecoderStats struct{_fbe int32 ;_bb int32 ;_gbb []byte ;_adb []byte ;
};func (_ege *Decoder )init ()error {_ege ._bee =_ege ._df .StreamPosition ();_gd ,_bd :=_ege ._df .ReadByte ();if _bd !=nil {_b .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",_bd );
return _bd ;};_ege ._be =_gd ;_ege ._ec =uint64 (_gd )<<16;if _bd =_ege .readByte ();_bd !=nil {return _bd ;};_ege ._ec <<=7;_ege ._dg -=7;_ege ._ag =0x8000;_ege ._g ++;return nil ;};func (_ef *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_ef ._dc =1;
var _aa uint64 ;for _aa =0;_aa < codeLen ;_aa ++{stats .SetIndex (int32 (_ef ._dc ));_eae ,_eg :=_ef .DecodeBit (stats );if _eg !=nil {return 0,_eg ;};_ef ._dc =(_ef ._dc <<1)|int64 (_eae );};_fa :=_ef ._dc -(1<<codeLen );return _fa ,nil ;};func (_fgc *DecoderStats )String ()string {_agd :=&_cd .Builder {};
_agd .WriteString (_d .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_fgc ._gbb )));for _gcg ,_ac :=range _fgc ._gbb {if _ac !=0{_agd .WriteString (_d .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_gcg ,_ac ));
};};return _agd .String ();};func (_bf *DecoderStats )setEntry (_ba int ){_eee :=byte (_ba &0x7f);_bf ._gbb [_bf ._fbe ]=_eee };func (_ega *DecoderStats )toggleMps (){_ega ._adb [_ega ._fbe ]^=1};func (_fbd *DecoderStats )Copy ()*DecoderStats {_ff :=&DecoderStats {_bb :_fbd ._bb ,_gbb :make ([]byte ,_fbd ._bb )};
for _fca :=0;_fca < len (_fbd ._gbb );_fca ++{_ff ._gbb [_fca ]=_fbd ._gbb [_fca ];};return _ff ;};func (_ca *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_fgd ,_beb int32 ;_gc ,_ea ,_af int ;_ad error ;);if stats ==nil {stats =NewStats (512,1);
};_ca ._dc =1;_ea ,_ad =_ca .decodeIntBit (stats );if _ad !=nil {return 0,_ad ;};_gc ,_ad =_ca .decodeIntBit (stats );if _ad !=nil {return 0,_ad ;};if _gc ==1{_gc ,_ad =_ca .decodeIntBit (stats );if _ad !=nil {return 0,_ad ;};if _gc ==1{_gc ,_ad =_ca .decodeIntBit (stats );
if _ad !=nil {return 0,_ad ;};if _gc ==1{_gc ,_ad =_ca .decodeIntBit (stats );if _ad !=nil {return 0,_ad ;};if _gc ==1{_gc ,_ad =_ca .decodeIntBit (stats );if _ad !=nil {return 0,_ad ;};if _gc ==1{_af =32;_beb =4436;}else {_af =12;_beb =340;};}else {_af =8;
_beb =84;};}else {_af =6;_beb =20;};}else {_af =4;_beb =4;};}else {_af =2;_beb =0;};for _adf :=0;_adf < _af ;_adf ++{_gc ,_ad =_ca .decodeIntBit (stats );if _ad !=nil {return 0,_ad ;};_fgd =(_fgd <<1)|int32 (_gc );};_fgd +=_beb ;if _ea ==0{return _fgd ,nil ;
}else if _ea ==1&&_fgd > 0{return -_fgd ,nil ;};return 0,_a .ErrOOB ;};func (_ddd *Decoder )renormalize ()error {for {if _ddd ._dg ==0{if _adg :=_ddd .readByte ();_adg !=nil {return _adg ;};};_ddd ._ag <<=1;_ddd ._ec <<=1;_ddd ._dg --;if (_ddd ._ag &0x8000)!=0{break ;
};};_ddd ._ec &=0xffffffff;return nil ;};func (_fbg *DecoderStats )Reset (){for _fdc :=0;_fdc < len (_fbg ._gbb );_fdc ++{_fbg ._gbb [_fdc ]=0;_fbg ._adb [_fdc ]=0;};};func (_ga *Decoder )lpsExchange (_ee *DecoderStats ,_dfc int32 ,_bea uint32 )int {_dba :=_ee .getMps ();
if _ga ._ag < _bea {_ee .setEntry (int (_e [_dfc ][1]));_ga ._ag =_bea ;return int (_dba );};if _e [_dfc ][3]==1{_ee .toggleMps ();};_ee .setEntry (int (_e [_dfc ][2]));_ga ._ag =_bea ;return int (1-_dba );};func (_fbgb *DecoderStats )SetIndex (index int32 ){_fbgb ._fbe =index };
func (_ddg *DecoderStats )getMps ()byte {return _ddg ._adb [_ddg ._fbe ]};func (_egd *Decoder )mpsExchange (_eda *DecoderStats ,_agg int32 )int {_eaf :=_eda ._adb [_eda ._fbe ];if _egd ._ag < _e [_agg ][0]{if _e [_agg ][3]==1{_eda .toggleMps ();};_eda .setEntry (int (_e [_agg ][2]));
return int (1-_eaf );};_eda .setEntry (int (_e [_agg ][1]));return int (_eaf );};func (_cg *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_eb int ;_dd =_e [stats .cx ()][0];_fg =int32 (stats .cx ()););defer func (){_cg ._g ++}();_cg ._ag -=_dd ;
if (_cg ._ec >>16)< uint64 (_dd ){_eb =_cg .lpsExchange (stats ,_fg ,_dd );if _fd :=_cg .renormalize ();_fd !=nil {return 0,_fd ;};}else {_cg ._ec -=uint64 (_dd )<<16;if (_cg ._ag &0x8000)==0{_eb =_cg .mpsExchange (stats ,_fg );if _ed :=_cg .renormalize ();
_ed !=nil {return 0,_ed ;};}else {_eb =int (stats .getMps ());};};return _eb ,nil ;};var (_e =[][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}};
);type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ;_df _ce .StreamReader ;_be uint8 ;_ec uint64 ;_ag uint32 ;_dc int64 ;_dg int32 ;_g int32 ;_bee int64 ;};func (_gdb *DecoderStats )cx ()byte {return _gdb ._gbb [_gdb ._fbe ]};