36 lines
7.8 KiB
Go
Raw Normal View History

2020-08-27 21:45:09 +00:00
//
// 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/
2022-09-10 15:35:04 +00:00
package arithmetic ;import (_da "fmt";_f "github.com/unidoc/unipdf/v3/common";_c "github.com/unidoc/unipdf/v3/internal/bitwise";_e "github.com/unidoc/unipdf/v3/internal/jbig2/internal";_bc "io";_d "strings";);func (_dagf *DecoderStats )Reset (){for _cdd :=0;
_cdd < len (_dagf ._cgb );_cdd ++{_dagf ._cgb [_cdd ]=0;_dagf ._bca [_cdd ]=0;};};func New (r _c .StreamReader )(*Decoder ,error ){_fg :=&Decoder {_dg :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}};if _cf :=_fg .init ();
_cf !=nil {return nil ,_cf ;};return _fg ,nil ;};func (_aba *Decoder )renormalize ()error {for {if _aba ._g ==0{if _fa :=_aba .readByte ();_fa !=nil {return _fa ;};};_aba ._fc <<=1;_aba ._bcg <<=1;_aba ._g --;if (_aba ._fc &0x8000)!=0{break ;};};_aba ._bcg &=0xffffffff;
return nil ;};func (_ecc *DecoderStats )setEntry (_fgg int ){_cfe :=byte (_fgg &0x7f);_ecc ._cgb [_ecc ._ae ]=_cfe };func (_cga *DecoderStats )String ()string {_fedf :=&_d .Builder {};_fedf .WriteString (_da .Sprintf ("S\u0074\u0061\u0074\u0073\u003a\u0020\u0020\u0025\u0064\u000a",len (_cga ._cgb )));
for _fea ,_fd :=range _cga ._cgb {if _fd !=0{_fedf .WriteString (_da .Sprintf ("N\u006f\u0074\u0020\u007aer\u006f \u0061\u0074\u003a\u0020\u0025d\u0020\u002d\u0020\u0025\u0064\u000a",_fea ,_fd ));};};return _fedf .String ();};func (_ff *Decoder )DecodeIAID (codeLen uint64 ,stats *DecoderStats )(int64 ,error ){_ff ._dgg =1;
var _efg uint64 ;for _efg =0;_efg < codeLen ;_efg ++{stats .SetIndex (int32 (_ff ._dgg ));_ac ,_cg :=_ff .DecodeBit (stats );if _cg !=nil {return 0,_cg ;};_ff ._dgg =(_ff ._dgg <<1)|int64 (_ac );};_fe :=_ff ._dgg -(1<<codeLen );return _fe ,nil ;};func (_gg *Decoder )init ()error {_gg ._bg =_gg ._dg .StreamPosition ();
_ag ,_cfa :=_gg ._dg .ReadByte ();if _cfa !=nil {_f .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",_cfa );return _cfa ;};_gg ._cb =_ag ;_gg ._bcg =uint64 (_ag )<<16;
if _cfa =_gg .readByte ();_cfa !=nil {return _cfa ;};_gg ._bcg <<=7;_gg ._g -=7;_gg ._fc =0x8000;_gg ._de ++;return nil ;};func (_eea *DecoderStats )SetIndex (index int32 ){_eea ._ae =index };type DecoderStats struct{_ae int32 ;_ged int32 ;_cgb []byte ;
_bca []byte ;};func (_ebe *DecoderStats )Copy ()*DecoderStats {_gda :=&DecoderStats {_ged :_ebe ._ged ,_cgb :make ([]byte ,_ebe ._ged )};for _ceg :=0;_ceg < len (_ebe ._cgb );_ceg ++{_gda ._cgb [_ceg ]=_ebe ._cgb [_ceg ];};return _gda ;};type Decoder struct{ContextSize []uint32 ;
ReferedToContextSize []uint32 ;_dg _c .StreamReader ;_cb uint8 ;_bcg uint64 ;_fc uint32 ;_dgg int64 ;_g int32 ;_de int32 ;_bg int64 ;};func (_gc *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_a int ;_ab =_ef [stats .cx ()][0];_aa =int32 (stats .cx ());
);defer func (){_gc ._de ++}();_gc ._fc -=_ab ;if (_gc ._bcg >>16)< uint64 (_ab ){_a =_gc .lpsExchange (stats ,_aa ,_ab );if _gb :=_gc .renormalize ();_gb !=nil {return 0,_gb ;};}else {_gc ._bcg -=uint64 (_ab )<<16;if (_gc ._fc &0x8000)==0{_a =_gc .mpsExchange (stats ,_aa );
if _ce :=_gc .renormalize ();_ce !=nil {return 0,_ce ;};}else {_a =int (stats .getMps ());};};return _a ,nil ;};func (_agd *DecoderStats )getMps ()byte {return _agd ._bca [_agd ._ae ]};func (_cbe *DecoderStats )cx ()byte {return _cbe ._cgb [_cbe ._ae ]};
func (_ead *DecoderStats )Overwrite (dNew *DecoderStats ){for _eef :=0;_eef < len (_ead ._cgb );_eef ++{_ead ._cgb [_eef ]=dNew ._cgb [_eef ];_ead ._bca [_eef ]=dNew ._bca [_eef ];};};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 (_aad *Decoder )readByte ()error {if _aad ._dg .StreamPosition ()> _aad ._bg {if _ ,_bd :=_aad ._dg .Seek (-1,_bc .SeekCurrent );_bd !=nil {return _bd ;};};_gd ,_ace :=_aad ._dg .ReadByte ();if _ace !=nil {return _ace ;};_aad ._cb =_gd ;if _aad ._cb ==0xFF{_cdc ,_efb :=_aad ._dg .ReadByte ();
if _efb !=nil {return _efb ;};if _cdc > 0x8F{_aad ._bcg +=0xFF00;_aad ._g =8;if _ ,_eb :=_aad ._dg .Seek (-2,_bc .SeekCurrent );_eb !=nil {return _eb ;};}else {_aad ._bcg +=uint64 (_cdc )<<9;_aad ._g =7;};}else {_gd ,_ace =_aad ._dg .ReadByte ();if _ace !=nil {return _ace ;
};_aad ._cb =_gd ;_aad ._bcg +=uint64 (_aad ._cb )<<8;_aad ._g =8;};_aad ._bcg &=0xFFFFFFFFFF;return nil ;};func (_ga *Decoder )DecodeInt (stats *DecoderStats )(int32 ,error ){var (_gbe ,_cd int32 ;_dag ,_fcg ,_gcb int ;_ge error ;);if stats ==nil {stats =NewStats (512,1);
};_ga ._dgg =1;_fcg ,_ge =_ga .decodeIntBit (stats );if _ge !=nil {return 0,_ge ;};_dag ,_ge =_ga .decodeIntBit (stats );if _ge !=nil {return 0,_ge ;};if _dag ==1{_dag ,_ge =_ga .decodeIntBit (stats );if _ge !=nil {return 0,_ge ;};if _dag ==1{_dag ,_ge =_ga .decodeIntBit (stats );
if _ge !=nil {return 0,_ge ;};if _dag ==1{_dag ,_ge =_ga .decodeIntBit (stats );if _ge !=nil {return 0,_ge ;};if _dag ==1{_dag ,_ge =_ga .decodeIntBit (stats );if _ge !=nil {return 0,_ge ;};if _dag ==1{_gcb =32;_cd =4436;}else {_gcb =12;_cd =340;};}else {_gcb =8;
_cd =84;};}else {_gcb =6;_cd =20;};}else {_gcb =4;_cd =4;};}else {_gcb =2;_cd =0;};for _ca :=0;_ca < _gcb ;_ca ++{_dag ,_ge =_ga .decodeIntBit (stats );if _ge !=nil {return 0,_ge ;};_gbe =(_gbe <<1)|int32 (_dag );};_gbe +=_cd ;if _fcg ==0{return _gbe ,nil ;
}else if _fcg ==1&&_gbe > 0{return -_gbe ,nil ;};return 0,_e .ErrOOB ;};func (_ec *Decoder )lpsExchange (_ea *DecoderStats ,_be int32 ,_bef uint32 )int {_ebg :=_ea .getMps ();if _ec ._fc < _bef {_ea .setEntry (int (_ef [_be ][1]));_ec ._fc =_bef ;return int (_ebg );
};if _ef [_be ][3]==1{_ea .toggleMps ();};_ea .setEntry (int (_ef [_be ][2]));_ec ._fc =_bef ;return int (1-_ebg );};func (_aec *DecoderStats )toggleMps (){_aec ._bca [_aec ._ae ]^=1};func (_fed *Decoder )decodeIntBit (_ee *DecoderStats )(int ,error ){_ee .SetIndex (int32 (_fed ._dgg ));
_fge ,_efa :=_fed .DecodeBit (_ee );if _efa !=nil {_f .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",_efa );
return _fge ,_efa ;};if _fed ._dgg < 256{_fed ._dgg =((_fed ._dgg <<uint64 (1))|int64 (_fge ))&0x1ff;}else {_fed ._dgg =(((_fed ._dgg <<uint64 (1)|int64 (_fge ))&511)|256)&0x1ff;};return _fge ,nil ;};func (_geg *Decoder )mpsExchange (_geb *DecoderStats ,_dd int32 )int {_ffa :=_geb ._bca [_geb ._ae ];
if _geg ._fc < _ef [_dd ][0]{if _ef [_dd ][3]==1{_geb .toggleMps ();};_geb .setEntry (int (_ef [_dd ][2]));return int (1-_ffa );};_geb .setEntry (int (_ef [_dd ][1]));return int (_ffa );};func NewStats (contextSize int32 ,index int32 )*DecoderStats {return &DecoderStats {_ae :index ,_ged :contextSize ,_cgb :make ([]byte ,contextSize ),_bca :make ([]byte ,contextSize )};
};