2021-03-13 21:28:23 +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 (_c "fmt";_e "github.com/unidoc/unipdf/v3/common";_be "github.com/unidoc/unipdf/v3/internal/bitwise";_ee "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_ac "io";_b "strings";);func (_dd *Decoder )mpsExchange (_aaf *DecoderStats ,_ace int32 )int {_eg :=_aaf ._cgcg [_aaf ._aafg ];
if _dd ._dc < _d [_ace ][0]{if _d [_ace ][3]==1{_aaf .toggleMps ();};_aaf .setEntry (int (_d [_ace ][2]));return int (1-_eg );};_aaf .setEntry (int (_d [_ace ][1]));return int (_eg );};func (_bb *Decoder )readByte ()error {if _bb ._df .StreamPosition ()> _bb ._edc {if _ ,_gg :=_bb ._df .Seek (-1,_ac .SeekCurrent );
_gg !=nil {return _gg ;};};_baf ,_adf :=_bb ._df .ReadByte ();if _adf !=nil {return _adf ;};_bb ._ed =_baf ;if _bb ._ed ==0xFF{_cd ,_gaa :=_bb ._df .ReadByte ();if _gaa !=nil {return _gaa ;};if _cd > 0x8F{_bb ._dg +=0xFF00;_bb ._ad =8;if _ ,_ccg :=_bb ._df .Seek (-2,_ac .SeekCurrent );
_ccg !=nil {return _ccg ;};}else {_bb ._dg +=uint64 (_cd )<<9;_bb ._ad =7;};}else {_baf ,_adf =_bb ._df .ReadByte ();if _adf !=nil {return _adf ;};_bb ._ed =_baf ;_bb ._dg +=uint64 (_bb ._ed )<<8;_bb ._ad =8;};_bb ._dg &=0xFFFFFFFFFF;return nil ;};func (_ce *DecoderStats )setEntry (_bfb int ){_bdf :=byte (_bfb &0x7f);
_ce ._cgdc [_ce ._aafg ]=_bdf };func (_ecg *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_f int ;_dge =_d [stats .cx ()][0];_ag =int32 (stats .cx ()););defer func (){_ecg ._ab ++}();_ecg ._dc -=_dge ;if (_ecg ._dg >>16)< uint64 (_dge ){_f =_ecg .lpsExchange (stats ,_ag ,_dge );
if _ade :=_ecg .renormalize ();_ade !=nil {return 0,_ade ;};}else {_ecg ._dg -=uint64 (_dge )<<16;if (_ecg ._dc &0x8000)==0{_f =_ecg .mpsExchange (stats ,_ag );if _bf :=_ecg .renormalize ();_bf !=nil {return 0,_bf ;};}else {_f =int (stats .getMps ());};
};return _f ,nil ;};func (_abf *DecoderStats )getMps ()byte {return _abf ._cgcg [_abf ._aafg ]};type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ;_df _be .StreamReader ;_ed uint8 ;_dg uint64 ;_dc uint32 ;_g int64 ;_ad int32 ;_ab int32 ;
_edc int64 ;};func (_aad *Decoder )init ()error {_aad ._edc =_aad ._df .StreamPosition ();_gfc ,_fa :=_aad ._df .ReadByte ();if _fa !=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",_fa );
return _fa ;};_aad ._ed =_gfc ;_aad ._dg =uint64 (_gfc )<<16;if _fa =_aad .readByte ();_fa !=nil {return _fa ;};_aad ._dg <<=7;_aad ._ad -=7;_aad ._dc =0x8000;_aad ._ab ++;return nil ;};type DecoderStats struct{_aafg int32 ;_cgce int32 ;_cgdc []byte ;_cgcg []byte ;
};func (_ccgb *Decoder )decodeIntBit (_ea *DecoderStats )(int ,error ){_ea .SetIndex (int32 (_ccgb ._g ));_fd ,_af :=_ccgb .DecodeBit (_ea );if _af !=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",_af );
return _fd ,_af ;};if _ccgb ._g < 256{_ccgb ._g =((_ccgb ._g <<uint64 (1))|int64 (_fd ))&0x1ff;}else {_ccgb ._g =(((_ccgb ._g <<uint64 (1)|int64 (_fd ))&511)|256)&0x1ff;};return _fd ,nil ;};func (_gb *Decoder )lpsExchange (_ff *DecoderStats ,_gff int32 ,_add uint32 )int {_ada :=_ff .getMps ();
if _gb ._dc < _add {_ff .setEntry (int (_d [_gff ][1]));_gb ._dc =_add ;return int (_ada );};if _d [_gff ][3]==1{_ff .toggleMps ();};_ff .setEntry (int (_d [_gff ][2]));_gb ._dc =_add ;return int (1-_ada );};var (_d =[][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 {_aafg :index ,_cgce :contextSize ,_cgdc :make ([]byte ,contextSize ),_cgcg :make ([]byte ,contextSize )};};func (_dcc *DecoderStats )Overwrite (dNew *DecoderStats ){for _fc :=0;
_fc < len (_dcc ._cgdc );_fc ++{_dcc ._cgdc [_fc ]=dNew ._cgdc [_fc ];_dcc ._cgcg [_fc ]=dNew ._cgcg [_fc ];};};func (_dgc *DecoderStats )cx ()byte {return _dgc ._cgdc [_dgc ._aafg ]};func (_ge *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_dcf ,_gf int32 ;
_bd ,_aa ,_ecb int ;_cc error ;);if stats ==nil {stats =NewStats (512,1);};_ge ._g =1;_aa ,_cc =_ge .decodeIntBit (stats );if _cc !=nil {return 0,_cc ;};_bd ,_cc =_ge .decodeIntBit (stats );if _cc !=nil {return 0,_cc ;};if _bd ==1{_bd ,_cc =_ge .decodeIntBit (stats );
if _cc !=nil {return 0,_cc ;};if _bd ==1{_bd ,_cc =_ge .decodeIntBit (stats );if _cc !=nil {return 0,_cc ;};if _bd ==1{_bd ,_cc =_ge .decodeIntBit (stats );if _cc !=nil {return 0,_cc ;};if _bd ==1{_bd ,_cc =_ge .decodeIntBit (stats );if _cc !=nil {return 0,_cc ;
};if _bd ==1{_ecb =32;_gf =4436;}else {_ecb =12;_gf =340;};}else {_ecb =8;_gf =84;};}else {_ecb =6;_gf =20;};}else {_ecb =4;_gf =4;};}else {_ecb =2;_gf =0;};for _gc :=0;_gc < _ecb ;_gc ++{_bd ,_cc =_ge .decodeIntBit (stats );if _cc !=nil {return 0,_cc ;
};_dcf =(_dcf <<1)|int32 (_bd );};_dcf +=_gf ;if _aa ==0{return _dcf ,nil ;}else if _aa ==1&&_dcf > 0{return -_dcf ,nil ;};return 0,_ee .ErrOOB ;};func (_ga *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_ga ._g =1;var _agf uint64 ;
for _agf =0;_agf < codeLen ;_agf ++{stats .SetIndex (int32 (_ga ._g ));_fg ,_adee :=_ga .DecodeBit (stats );if _adee !=nil {return 0,_adee ;};_ga ._g =(_ga ._g <<1)|int64 (_fg );};_cg :=_ga ._g -(1<<codeLen );return _cg ,nil ;};func (_cf *DecoderStats )Reset (){for _fe :=0;
_fe < len (_cf ._cgdc );_fe ++{_cf ._cgdc [_fe ]=0;_cf ._cgcg [_fe ]=0;};};func (_geb *DecoderStats )Copy ()*DecoderStats {_cdd :=&DecoderStats {_cgce :_geb ._cgce ,_cgdc :make ([]byte ,_geb ._cgce )};for _fgg :=0;_fgg < len (_geb ._cgdc );_fgg ++{_cdd ._cgdc [_fgg ]=_geb ._cgdc [_fgg ];
};return _cdd ;};func (_ef *DecoderStats )String ()string {_eff :=&_b .Builder {};_eff .WriteString (_c .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_ef ._cgdc )));for _bc ,_gab :=range _ef ._cgdc {if _gab !=0{_eff .WriteString (_c .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_bc ,_gab ));
};};return _eff .String ();};func (_adde *DecoderStats )toggleMps (){_adde ._cgcg [_adde ._aafg ]^=1};func (_da *DecoderStats )SetIndex (index int32 ){_da ._aafg =index };func New (r _be .StreamReader )(*Decoder ,error ){_ec :=&Decoder {_df :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};
if _ba :=_ec .init ();_ba !=nil {return nil ,_ba ;};return _ec ,nil ;};func (_cgc *Decoder )renormalize ()error {for {if _cgc ._ad ==0{if _cgd :=_cgc .readByte ();_cgd !=nil {return _cgd ;};};_cgc ._dc <<=1;_cgc ._dg <<=1;_cgc ._ad --;if (_cgc ._dc &0x8000)!=0{break ;
};};_cgc ._dg &=0xffffffff;return nil ;};