mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-26 13:48:55 +08:00
12 lines
7.7 KiB
Go
12 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 (_c "fmt";_cd "github.com/unidoc/unipdf/v3/common";_ca "github.com/unidoc/unipdf/v3/internal/bitwise";_e "io";_b "math";_d "strings";);type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ;_cad _ca .StreamReader ;_be uint8 ;_a uint64 ;_ee uint32 ;_bc int64 ;_ae int32 ;_ad int32 ;_bb int64 ;};func (_cf *DecoderStats )String ()string {_cea :=&_d .Builder {};_cea .WriteString (_c .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_cf ._de )));for _fde ,_cadb :=range _cf ._de {if _cadb !=0{_cea .WriteString (_c .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_fde ,_cadb ));};};return _cea .String ();};func (_gd *DecoderStats )SetIndex (index int32 ){_gd ._fgb =index };func (_adf *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_ff ,_aed int32 ;_bf ,_gc ,_ab int ;_ag error ;);if stats ==nil {stats =NewStats (512,1);};_adf ._bc =1;_gc ,_ag =_adf .decodeIntBit (stats );if _ag !=nil {return 0,_ag ;};_bf ,_ag =_adf .decodeIntBit (stats );if _ag !=nil {return 0,_ag ;};if _bf ==1{_bf ,_ag =_adf .decodeIntBit (stats );if _ag !=nil {return 0,_ag ;};if _bf ==1{_bf ,_ag =_adf .decodeIntBit (stats );if _ag !=nil {return 0,_ag ;};if _bf ==1{_bf ,_ag =_adf .decodeIntBit (stats );if _ag !=nil {return 0,_ag ;};if _bf ==1{_bf ,_ag =_adf .decodeIntBit (stats );if _ag !=nil {return 0,_ag ;};if _bf ==1{_ab =32;_aed =4436;}else {_ab =12;_aed =340;};}else {_ab =8;_aed =84;};}else {_ab =6;_aed =20;};}else {_ab =4;_aed =4;};}else {_ab =2;_aed =0;};for _fd :=0;_fd < _ab ;_fd ++{_bf ,_ag =_adf .decodeIntBit (stats );if _ag !=nil {return 0,_ag ;};_ff =(_ff <<1)|int32 (_bf );};_ff +=_aed ;if _gc ==0{return _ff ,nil ;}else if _gc ==1&&_ff > 0{return -_ff ,nil ;};return _b .MaxInt32 ,nil ;};func (_bd *DecoderStats )Overwrite (dNew *DecoderStats ){for _db :=0;_db < len (_bd ._de );_db ++{_bd ._de [_db ]=dNew ._de [_db ];_bd ._eag [_db ]=dNew ._eag [_db ];};};func (_cef *Decoder )mpsExchange (_bff *DecoderStats ,_efg int32 )int {_gag :=_bff ._eag [_bff ._fgb ];if _cef ._ee < _ef [_efg ][0]{if _ef [_efg ][3]==1{_bff .toggleMps ();};_bff .setEntry (int (_ef [_efg ][2]));return int (1-_gag );};_bff .setEntry (int (_ef [_efg ][1]));return int (_gag );};func (_dc *Decoder )init ()error {_dc ._bb =_dc ._cad .StreamPosition ();_eg ,_egg :=_dc ._cad .ReadByte ();if _egg !=nil {_cd .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",_egg );return _egg ;};_dc ._be =_eg ;_dc ._a =uint64 (_eg )<<16;if _egg =_dc .readByte ();_egg !=nil {return _egg ;};_dc ._a <<=7;_dc ._ae -=7;_dc ._ee =0x8000;_dc ._ad ++;return nil ;};func New (r _ca .StreamReader )(*Decoder ,error ){_ed :=&Decoder {_cad :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};if _aa :=_ed .init ();_aa !=nil {return nil ,_aa ;};return _ed ,nil ;};func (_gg *DecoderStats )setEntry (_eec int ){_dgef :=byte (_eec &0x7f);_gg ._de [_gg ._fgb ]=_dgef };func (_cg *DecoderStats )getMps ()byte {return _cg ._eag [_cg ._fgb ]};var (_ef =[][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 (_ga *Decoder )readByte ()error {if _ga ._cad .StreamPosition ()> _ga ._bb {if _ ,_ge :=_ga ._cad .Seek (-1,_e .SeekCurrent );_ge !=nil {return _ge ;};};_cag ,_ce :=_ga ._cad .ReadByte ();if _ce !=nil {return _ce ;};_ga ._be =_cag ;if _ga ._be ==0xFF{_eee ,_caf :=_ga ._cad .ReadByte ();if _caf !=nil {return _caf ;};if _eee > 0x8F{_ga ._a +=0xFF00;_ga ._ae =8;if _ ,_bbg :=_ga ._cad .Seek (-2,_e .SeekCurrent );_bbg !=nil {return _bbg ;};}else {_ga ._a +=uint64 (_eee )<<9;_ga ._ae =7;};}else {_cag ,_ce =_ga ._cad .ReadByte ();if _ce !=nil {return _ce ;};_ga ._be =_cag ;_ga ._a +=uint64 (_ga ._be )<<8;_ga ._ae =8;};_ga ._a &=0xFFFFFFFFFF;return nil ;};func (_aea *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_f int ;_cdc =_ef [stats .cx ()][0];_fa =int32 (stats .cx ()););defer func (){_aea ._ad ++}();_aea ._ee -=_cdc ;if (_aea ._a >>16)< uint64 (_cdc ){_f =_aea .lpsExchange (stats ,_fa ,_cdc );if _eb :=_aea .renormalize ();_eb !=nil {return 0,_eb ;};}else {_aea ._a -=uint64 (_cdc )<<16;if (_aea ._ee &0x8000)==0{_f =_aea .mpsExchange (stats ,_fa );if _ea :=_aea .renormalize ();_ea !=nil {return 0,_ea ;};}else {_f =int (stats .getMps ());};};return _f ,nil ;};func (_dd *Decoder )lpsExchange (_egge *DecoderStats ,_fdg int32 ,_fga uint32 )int {_da :=_egge .getMps ();if _dd ._ee < _fga {_egge .setEntry (int (_ef [_fdg ][1]));_dd ._ee =_fga ;return int (_da );};if _ef [_fdg ][3]==1{_egge .toggleMps ();};_egge .setEntry (int (_ef [_fdg ][2]));_dd ._ee =_fga ;return int (1-_da );};func (_afd *DecoderStats )Copy ()*DecoderStats {_efa :=&DecoderStats {_af :_afd ._af ,_de :make ([]byte ,_afd ._af )};for _dee :=0;_dee < len (_afd ._de );_dee ++{_efa ._de [_dee ]=_afd ._de [_dee ];};return _efa ;};func (_ade *DecoderStats )cx ()byte {return _ade ._de [_ade ._fgb ]};func NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_fgb :index ,_af :contextSize ,_de :make ([]byte ,contextSize ),_eag :make ([]byte ,contextSize )};};func (_fe *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_fe ._bc =1;var _dg uint64 ;for _dg =0;_dg < codeLen ;_dg ++{stats .SetIndex (int32 (_fe ._bc ));_ba ,_aaa :=_fe .DecodeBit (stats );if _aaa !=nil {return 0,_aaa ;};_fe ._bc =(_fe ._bc <<1)|int64 (_ba );};_eeb :=_fe ._bc -(1<<codeLen );return _eeb ,nil ;};func (_abg *Decoder )decodeIntBit (_fg *DecoderStats )(int ,error ){_fg .SetIndex (int32 (_abg ._bc ));_ec ,_eaf :=_abg .DecodeBit (_fg );if _eaf !=nil {_cd .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",_eaf );return _ec ,_eaf ;};if _abg ._bc < 256{_abg ._bc =((_abg ._bc <<uint64 (1))|int64 (_ec ))&0x1ff;}else {_abg ._bc =(((_abg ._bc <<uint64 (1)|int64 (_ec ))&511)|256)&0x1ff;};return _ec ,nil ;};func (_fef *DecoderStats )toggleMps (){_fef ._eag [_fef ._fgb ]^=1};func (_cagf *DecoderStats )Reset (){for _fea :=0;_fea < len (_cagf ._de );_fea ++{_cagf ._de [_fea ]=0;_cagf ._eag [_fea ]=0;};};type DecoderStats struct{_fgb int32 ;_af int32 ;_de []byte ;_eag []byte ;};func (_baf *Decoder )renormalize ()error {for {if _baf ._ae ==0{if _ffc :=_baf .readByte ();_ffc !=nil {return _ffc ;};};_baf ._ee <<=1;_baf ._a <<=1;_baf ._ae --;if (_baf ._ee &0x8000)!=0{break ;};};_baf ._a &=0xffffffff;return nil ;}; |