2023-01-08 22:34:27 +00:00

35 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 (_bb "fmt";_e "github.com/unidoc/unipdf/v3/common";_ed "github.com/unidoc/unipdf/v3/internal/bitwise";_dc "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_b "io";_ba "strings";);func (_cg *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_cg ._ff =1;
var _bbdc uint64 ;for _bbdc =0;_bbdc < codeLen ;_bbdc ++{stats .SetIndex (int32 (_cg ._ff ));_ge ,_aga :=_cg .DecodeBit (stats );if _aga !=nil {return 0,_aga ;};_cg ._ff =(_cg ._ff <<1)|int64 (_ge );};_edd :=_cg ._ff -(1<<codeLen );return _edd ,nil ;};
func (_gfc *Decoder )mpsExchange (_fa *DecoderStats ,_dfd int32 )int {_cda :=_fa ._fad [_fa ._gc ];if _gfc ._eg < _dd [_dfd ][0]{if _dd [_dfd ][3]==1{_fa .toggleMps ();};_fa .setEntry (int (_dd [_dfd ][2]));return int (1-_cda );};_fa .setEntry (int (_dd [_dfd ][1]));
return int (_cda );};func (_ad *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_c ,_edb int32 ;_bgc ,_dfe ,_g int ;_ee error ;);if stats ==nil {stats =NewStats (512,1);};_ad ._ff =1;_dfe ,_ee =_ad .decodeIntBit (stats );if _ee !=nil {return 0,_ee ;
};_bgc ,_ee =_ad .decodeIntBit (stats );if _ee !=nil {return 0,_ee ;};if _bgc ==1{_bgc ,_ee =_ad .decodeIntBit (stats );if _ee !=nil {return 0,_ee ;};if _bgc ==1{_bgc ,_ee =_ad .decodeIntBit (stats );if _ee !=nil {return 0,_ee ;};if _bgc ==1{_bgc ,_ee =_ad .decodeIntBit (stats );
if _ee !=nil {return 0,_ee ;};if _bgc ==1{_bgc ,_ee =_ad .decodeIntBit (stats );if _ee !=nil {return 0,_ee ;};if _bgc ==1{_g =32;_edb =4436;}else {_g =12;_edb =340;};}else {_g =8;_edb =84;};}else {_g =6;_edb =20;};}else {_g =4;_edb =4;};}else {_g =2;_edb =0;
};for _dg :=0;_dg < _g ;_dg ++{_bgc ,_ee =_ad .decodeIntBit (stats );if _ee !=nil {return 0,_ee ;};_c =(_c <<1)|int32 (_bgc );};_c +=_edb ;if _dfe ==0{return _c ,nil ;}else if _dfe ==1&&_c > 0{return -_c ,nil ;};return 0,_dc .ErrOOB ;};func (_bcb *Decoder )renormalize ()error {for {if _bcb ._bbb ==0{if _dfeg :=_bcb .readByte ();
_dfeg !=nil {return _dfeg ;};};_bcb ._eg <<=1;_bcb ._fe <<=1;_bcb ._bbb --;if (_bcb ._eg &0x8000)!=0{break ;};};_bcb ._fe &=0xffffffff;return nil ;};func (_ffe *Decoder )lpsExchange (_fbg *DecoderStats ,_adb int32 ,_ead uint32 )int {_fag :=_fbg .getMps ();
if _ffe ._eg < _ead {_fbg .setEntry (int (_dd [_adb ][1]));_ffe ._eg =_ead ;return int (_fag );};if _dd [_adb ][3]==1{_fbg .toggleMps ();};_fbg .setEntry (int (_dd [_adb ][2]));_ffe ._eg =_ead ;return int (1-_fag );};func (_fae *DecoderStats )Copy ()*DecoderStats {_fd :=&DecoderStats {_cdf :_fae ._cdf ,_gec :make ([]byte ,_fae ._cdf )};
copy (_fd ._gec ,_fae ._gec );return _fd ;};func (_ga *Decoder )init ()error {_ga ._da =_ga ._bf .StreamPosition ();_bfb ,_gf :=_ga ._bf .ReadByte ();if _gf !=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",_gf );
return _gf ;};_ga ._f =_bfb ;_ga ._fe =uint64 (_bfb )<<16;if _gf =_ga .readByte ();_gf !=nil {return _gf ;};_ga ._fe <<=7;_ga ._bbb -=7;_ga ._eg =0x8000;_ga ._bc ++;return nil ;};func (_fc *DecoderStats )Overwrite (dNew *DecoderStats ){for _ebc :=0;_ebc < len (_fc ._gec );
_ebc ++{_fc ._gec [_ebc ]=dNew ._gec [_ebc ];_fc ._fad [_ebc ]=dNew ._fad [_ebc ];};};func (_fafb *DecoderStats )toggleMps (){_fafb ._fad [_fafb ._gc ]^=1};var (_dd =[][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 (_eb *Decoder )decodeIntBit (_cdc *DecoderStats )(int ,error ){_cdc .SetIndex (int32 (_eb ._ff ));_db ,_ege :=_eb .DecodeBit (_cdc );if _ege !=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",_ege );
return _db ,_ege ;};if _eb ._ff < 256{_eb ._ff =((_eb ._ff <<uint64 (1))|int64 (_db ))&0x1ff;}else {_eb ._ff =(((_eb ._ff <<uint64 (1)|int64 (_db ))&511)|256)&0x1ff;};return _db ,nil ;};type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ;
_bf _ed .StreamReader ;_f uint8 ;_fe uint64 ;_eg uint32 ;_ff int64 ;_bbb int32 ;_bc int32 ;_da int64 ;};func (_bgd *DecoderStats )setEntry (_faf int ){_gcd :=byte (_faf &0x7f);_bgd ._gec [_bgd ._gc ]=_gcd };func (_adbc *DecoderStats )cx ()byte {return _adbc ._gec [_adbc ._gc ]};
func (_aec *DecoderStats )SetIndex (index int32 ){_aec ._gc =index };func (_a *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_be int ;_ag =_dd [stats .cx ()][0];_aa =int32 (stats .cx ()););defer func (){_a ._bc ++}();_a ._eg -=_ag ;if (_a ._fe >>16)< uint64 (_ag ){_be =_a .lpsExchange (stats ,_aa ,_ag );
if _bg :=_a .renormalize ();_bg !=nil {return 0,_bg ;};}else {_a ._fe -=uint64 (_ag )<<16;if (_a ._eg &0x8000)==0{_be =_a .mpsExchange (stats ,_aa );if _bbd :=_a .renormalize ();_bbd !=nil {return 0,_bbd ;};}else {_be =int (stats .getMps ());};};return _be ,nil ;
};func NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_gc :index ,_cdf :contextSize ,_gec :make ([]byte ,contextSize ),_fad :make ([]byte ,contextSize )};};func (_gb *DecoderStats )String ()string {_ggc :=&_ba .Builder {};
_ggc .WriteString (_bb .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_gb ._gec )));for _ddg ,_aac :=range _gb ._gec {if _aac !=0{_ggc .WriteString (_bb .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_ddg ,_aac ));
};};return _ggc .String ();};func (_cb *DecoderStats )Reset (){for _ae :=0;_ae < len (_cb ._gec );_ae ++{_cb ._gec [_ae ]=0;_cb ._fad [_ae ]=0;};};func (_cc *DecoderStats )getMps ()byte {return _cc ._fad [_cc ._gc ]};func (_gg *Decoder )readByte ()error {if _gg ._bf .StreamPosition ()> _gg ._da {if _ ,_dfc :=_gg ._bf .Seek (-1,_b .SeekCurrent );
_dfc !=nil {return _dfc ;};};_edc ,_ea :=_gg ._bf .ReadByte ();if _ea !=nil {return _ea ;};_gg ._f =_edc ;if _gg ._f ==0xFF{_eddd ,_cd :=_gg ._bf .ReadByte ();if _cd !=nil {return _cd ;};if _eddd > 0x8F{_gg ._fe +=0xFF00;_gg ._bbb =8;if _ ,_fb :=_gg ._bf .Seek (-2,_b .SeekCurrent );
_fb !=nil {return _fb ;};}else {_gg ._fe +=uint64 (_eddd )<<9;_gg ._bbb =7;};}else {_edc ,_ea =_gg ._bf .ReadByte ();if _ea !=nil {return _ea ;};_gg ._f =_edc ;_gg ._fe +=uint64 (_gg ._f )<<8;_gg ._bbb =8;};_gg ._fe &=0xFFFFFFFFFF;return nil ;};type DecoderStats struct{_gc int32 ;
_cdf int32 ;_gec []byte ;_fad []byte ;};func New (r _ed .StreamReader )(*Decoder ,error ){_df :=&Decoder {_bf :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};if _ec :=_df .init ();_ec !=nil {return nil ,_ec ;};return _df ,nil ;
};