mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-05 19:30:30 +08:00
36 lines
7.7 KiB
Go
36 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 (_ec "fmt";_ea "github.com/unidoc/unipdf/v3/common";_a "github.com/unidoc/unipdf/v3/internal/bitwise";_ecf "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_e "io";_ef "strings";);func (_bbc *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_bbc ._bb =1;
|
|
var _ecb uint64 ;for _ecb =0;_ecb < codeLen ;_ecb ++{stats .SetIndex (int32 (_bbc ._bb ));_aef ,_ee :=_bbc .DecodeBit (stats );if _ee !=nil {return 0,_ee ;};_bbc ._bb =(_bbc ._bb <<1)|int64 (_aef );};_aefe :=_bbc ._bb -(1<<codeLen );return _aefe ,nil ;
|
|
};func (_eba *DecoderStats )setEntry (_bc int ){_gg :=byte (_bc &0x7f);_eba ._beg [_eba ._ag ]=_gg };func (_bfd *Decoder )readByte ()error {if _bfd ._be .AbsolutePosition ()> _bfd ._efb {if _ ,_gb :=_bfd ._be .Seek (-1,_e .SeekCurrent );_gb !=nil {return _gb ;
|
|
};};_fge ,_ga :=_bfd ._be .ReadByte ();if _ga !=nil {return _ga ;};_bfd ._ed =_fge ;if _bfd ._ed ==0xFF{_bef ,_gbc :=_bfd ._be .ReadByte ();if _gbc !=nil {return _gbc ;};if _bef > 0x8F{_bfd ._eb +=0xFF00;_bfd ._ba =8;if _ ,_cc :=_bfd ._be .Seek (-2,_e .SeekCurrent );
|
|
_cc !=nil {return _cc ;};}else {_bfd ._eb +=uint64 (_bef )<<9;_bfd ._ba =7;};}else {_fge ,_ga =_bfd ._be .ReadByte ();if _ga !=nil {return _ga ;};_bfd ._ed =_fge ;_bfd ._eb +=uint64 (_bfd ._ed )<<8;_bfd ._ba =8;};_bfd ._eb &=0xFFFFFFFFFF;return nil ;};
|
|
func (_fbb *DecoderStats )Copy ()*DecoderStats {_gdg :=&DecoderStats {_ebf :_fbb ._ebf ,_beg :make ([]byte ,_fbb ._ebf )};copy (_gdg ._beg ,_fbb ._beg );return _gdg ;};func (_aac *Decoder )decodeIntBit (_cga *DecoderStats )(int ,error ){_cga .SetIndex (int32 (_aac ._bb ));
|
|
_geb ,_gae :=_aac .DecodeBit (_cga );if _gae !=nil {_ea .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",_gae );
|
|
return _geb ,_gae ;};if _aac ._bb < 256{_aac ._bb =((_aac ._bb <<uint64 (1))|int64 (_geb ))&0x1ff;}else {_aac ._bb =(((_aac ._bb <<uint64 (1)|int64 (_geb ))&511)|256)&0x1ff;};return _geb ,nil ;};func (_cf *Decoder )mpsExchange (_bdf *DecoderStats ,_cb int32 )int {_df :=_bdf ._bae [_bdf ._ag ];
|
|
if _cf ._g < _bg [_cb ][0]{if _bg [_cb ][3]==1{_bdf .toggleMps ();};_bdf .setEntry (int (_bg [_cb ][2]));return int (1-_df );};_bdf .setEntry (int (_bg [_cb ][1]));return int (_df );};func (_eab *Decoder )init ()error {_eab ._efb =_eab ._be .AbsolutePosition ();
|
|
_bed ,_gd :=_eab ._be .ReadByte ();if _gd !=nil {_ea .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",_gd );return _gd ;};_eab ._ed =_bed ;_eab ._eb =uint64 (_bed )<<16;
|
|
if _gd =_eab .readByte ();_gd !=nil {return _gd ;};_eab ._eb <<=7;_eab ._ba -=7;_eab ._g =0x8000;_eab ._c ++;return nil ;};type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ;_be *_a .Reader ;_ed uint8 ;_eb uint64 ;_g uint32 ;_bb int64 ;
|
|
_ba int32 ;_c int32 ;_efb int64 ;};func (_cdb *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_ge int ;_eg =_bg [stats .cx ()][0];_gc =int32 (stats .cx ()););defer func (){_cdb ._c ++}();_cdb ._g -=_eg ;if (_cdb ._eb >>16)< uint64 (_eg ){_ge =_cdb .lpsExchange (stats ,_gc ,_eg );
|
|
if _aa :=_cdb .renormalize ();_aa !=nil {return 0,_aa ;};}else {_cdb ._eb -=uint64 (_eg )<<16;if (_cdb ._g &0x8000)==0{_ge =_cdb .mpsExchange (stats ,_gc );if _bf :=_cdb .renormalize ();_bf !=nil {return 0,_bf ;};}else {_ge =int (stats .getMps ());};};
|
|
return _ge ,nil ;};func (_ad *DecoderStats )SetIndex (index int32 ){_ad ._ag =index };func New (r *_a .Reader )(*Decoder ,error ){_cd :=&Decoder {_be :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};if _ae :=_cd .init ();
|
|
_ae !=nil {return nil ,_ae ;};return _cd ,nil ;};func (_cdc *Decoder )lpsExchange (_beb *DecoderStats ,_ca int32 ,_fd uint32 )int {_fb :=_beb .getMps ();if _cdc ._g < _fd {_beb .setEntry (int (_bg [_ca ][1]));_cdc ._g =_fd ;return int (_fb );};if _bg [_ca ][3]==1{_beb .toggleMps ();
|
|
};_beb .setEntry (int (_bg [_ca ][2]));_cdc ._g =_fd ;return int (1-_fb );};func (_efgg *DecoderStats )Overwrite (dNew *DecoderStats ){for _ff :=0;_ff < len (_efgg ._beg );_ff ++{_efgg ._beg [_ff ]=dNew ._beg [_ff ];_efgg ._bae [_ff ]=dNew ._bae [_ff ];
|
|
};};func (_gf *DecoderStats )String ()string {_bgg :=&_ef .Builder {};_bgg .WriteString (_ec .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_gf ._beg )));for _eae ,_bea :=range _gf ._beg {if _bea !=0{_bgg .WriteString (_ec .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_eae ,_bea ));
|
|
};};return _bgg .String ();};func (_aeg *DecoderStats )Reset (){for _fef :=0;_fef < len (_aeg ._beg );_fef ++{_aeg ._beg [_fef ]=0;_aeg ._bae [_fef ]=0;};};func (_ebd *DecoderStats )toggleMps (){_ebd ._bae [_ebd ._ag ]^=1};func (_ab *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_efg ,_d int32 ;
|
|
_bga ,_f ,_ac int ;_bbd error ;);if stats ==nil {stats =NewStats (512,1);};_ab ._bb =1;_f ,_bbd =_ab .decodeIntBit (stats );if _bbd !=nil {return 0,_bbd ;};_bga ,_bbd =_ab .decodeIntBit (stats );if _bbd !=nil {return 0,_bbd ;};if _bga ==1{_bga ,_bbd =_ab .decodeIntBit (stats );
|
|
if _bbd !=nil {return 0,_bbd ;};if _bga ==1{_bga ,_bbd =_ab .decodeIntBit (stats );if _bbd !=nil {return 0,_bbd ;};if _bga ==1{_bga ,_bbd =_ab .decodeIntBit (stats );if _bbd !=nil {return 0,_bbd ;};if _bga ==1{_bga ,_bbd =_ab .decodeIntBit (stats );if _bbd !=nil {return 0,_bbd ;
|
|
};if _bga ==1{_ac =32;_d =4436;}else {_ac =12;_d =340;};}else {_ac =8;_d =84;};}else {_ac =6;_d =20;};}else {_ac =4;_d =4;};}else {_ac =2;_d =0;};for _fg :=0;_fg < _ac ;_fg ++{_bga ,_bbd =_ab .decodeIntBit (stats );if _bbd !=nil {return 0,_bbd ;};_efg =(_efg <<1)|int32 (_bga );
|
|
};_efg +=_d ;if _f ==0{return _efg ,nil ;}else if _f ==1&&_efg > 0{return -_efg ,nil ;};return 0,_ecf .ErrOOB ;};type DecoderStats struct{_ag int32 ;_ebf int32 ;_beg []byte ;_bae []byte ;};var (_bg =[][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 (_db *DecoderStats )getMps ()byte {return _db ._bae [_db ._ag ]};func NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_ag :index ,_ebf :contextSize ,_beg :make ([]byte ,contextSize ),_bae :make ([]byte ,contextSize )};
|
|
};func (_bfg *DecoderStats )cx ()byte {return _bfg ._beg [_bfg ._ag ]};func (_aec *Decoder )renormalize ()error {for {if _aec ._ba ==0{if _bd :=_aec .readByte ();_bd !=nil {return _bd ;};};_aec ._g <<=1;_aec ._eb <<=1;_aec ._ba --;if (_aec ._g &0x8000)!=0{break ;
|
|
};};_aec ._eb &=0xffffffff;return nil ;}; |