github.com/unidoc/unipdf/v3@v3.55.0/internal/sampling/sampling.go (about)

     1  //
     2  // Copyright 2020 FoxyUtils ehf. All rights reserved.
     3  //
     4  // This is a commercial product and requires a license to operate.
     5  // A trial license can be obtained at https://unidoc.io
     6  //
     7  // DO NOT EDIT: generated by unitwist Go source code obfuscator.
     8  //
     9  // Use of this source code is governed by the UniDoc End User License Agreement
    10  // terms that can be accessed at https://unidoc.io/eula/
    11  
    12  package sampling ;import (_e "github.com/unidoc/unipdf/v3/internal/bitwise";_c "github.com/unidoc/unipdf/v3/internal/imageutil";_a "io";);func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _ega []uint32 ;
    13  _egab :=bitsPerOutputSample ;var _cd uint32 ;var _ba uint32 ;_gb :=0;_gdb :=0;_abd :=0;for _abd < len (data ){if _gb > 0{_eec :=_gb ;if _egab < _eec {_eec =_egab ;};_cd =(_cd <<uint (_eec ))|(_ba >>uint (bitsPerInputSample -_eec ));_gb -=_eec ;if _gb > 0{_ba =_ba <<uint (_eec );
    14  }else {_ba =0;};_egab -=_eec ;if _egab ==0{_ega =append (_ega ,_cd );_egab =bitsPerOutputSample ;_cd =0;_gdb ++;};}else {_fb :=data [_abd ];_abd ++;_fbb :=bitsPerInputSample ;if _egab < _fbb {_fbb =_egab ;};_gb =bitsPerInputSample -_fbb ;_cd =(_cd <<uint (_fbb ))|(_fb >>uint (_gb ));
    15  if _fbb < bitsPerInputSample {_ba =_fb <<uint (_fbb );};_egab -=_fbb ;if _egab ==0{_ega =append (_ega ,_cd );_egab =bitsPerOutputSample ;_cd =0;_gdb ++;};};};for _gb >=bitsPerOutputSample {_gdd :=_gb ;if _egab < _gdd {_gdd =_egab ;};_cd =(_cd <<uint (_gdd ))|(_ba >>uint (bitsPerInputSample -_gdd ));
    16  _gb -=_gdd ;if _gb > 0{_ba =_ba <<uint (_gdd );}else {_ba =0;};_egab -=_gdd ;if _egab ==0{_ega =append (_ega ,_cd );_egab =bitsPerOutputSample ;_cd =0;_gdb ++;};};if _egab > 0&&_egab < bitsPerOutputSample {_cd <<=uint (_egab );_ega =append (_ega ,_cd );
    17  };return _ega ;};func (_gd *Reader )ReadSamples (samples []uint32 )(_ca error ){for _ce :=0;_ce < len (samples );_ce ++{samples [_ce ],_ca =_gd .ReadSample ();if _ca !=nil {return _ca ;};};return nil ;};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _cgf []uint32 ;
    18  _fc :=bitsPerSample ;var _dd uint32 ;var _ee byte ;_da :=0;_gf :=0;_eeg :=0;for _eeg < len (data ){if _da > 0{_ede :=_da ;if _fc < _ede {_ede =_fc ;};_dd =(_dd <<uint (_ede ))|uint32 (_ee >>uint (8-_ede ));_da -=_ede ;if _da > 0{_ee =_ee <<uint (_ede );
    19  }else {_ee =0;};_fc -=_ede ;if _fc ==0{_cgf =append (_cgf ,_dd );_fc =bitsPerSample ;_dd =0;_gf ++;};}else {_ab :=data [_eeg ];_eeg ++;_gg :=8;if _fc < _gg {_gg =_fc ;};_da =8-_gg ;_dd =(_dd <<uint (_gg ))|uint32 (_ab >>uint (_da ));if _gg < 8{_ee =_ab <<uint (_gg );
    20  };_fc -=_gg ;if _fc ==0{_cgf =append (_cgf ,_dd );_fc =bitsPerSample ;_dd =0;_gf ++;};};};for _da >=bitsPerSample {_cgb :=_da ;if _fc < _cgb {_cgb =_fc ;};_dd =(_dd <<uint (_cgb ))|uint32 (_ee >>uint (8-_cgb ));_da -=_cgb ;if _da > 0{_ee =_ee <<uint (_cgb );
    21  }else {_ee =0;};_fc -=_cgb ;if _fc ==0{_cgf =append (_cgf ,_dd );_fc =bitsPerSample ;_dd =0;_gf ++;};};return _cgf ;};func (_ga *Writer )WriteSamples (samples []uint32 )error {for _af :=0;_af < len (samples );_af ++{if _fca :=_ga .WriteSample (samples [_af ]);
    22  _fca !=nil {return _fca ;};};return nil ;};func NewReader (img _c .ImageBase )*Reader {return &Reader {_cf :_e .NewReader (img .Data ),_f :img ,_d :img .ColorComponents ,_de :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };
    23  };type Writer struct{_cc _c .ImageBase ;_dbd *_e .Writer ;_ge ,_ec int ;_ecg bool ;};type SampleWriter interface{WriteSample (_db uint32 )error ;WriteSamples (_dbc []uint32 )error ;};func (_g *Reader )ReadSample ()(uint32 ,error ){if _g ._ad ==_g ._f .Height {return 0,_a .EOF ;
    24  };_ed ,_eb :=_g ._cf .ReadBits (byte (_g ._f .BitsPerComponent ));if _eb !=nil {return 0,_eb ;};_g ._d --;if _g ._d ==0{_g ._d =_g ._f .ColorComponents ;_g ._cg ++;};if _g ._cg ==_g ._f .Width {if _g ._de {_g ._cf .ConsumeRemainingBits ();};_g ._cg =0;
    25  _g ._ad ++;};return uint32 (_ed ),nil ;};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_eg []uint32 )error ;};func NewWriter (img _c .ImageBase )*Writer {return &Writer {_dbd :_e .NewWriterMSB (img .Data ),_cc :img ,_ec :img .ColorComponents ,_ecg :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };
    26  };type Reader struct{_f _c .ImageBase ;_cf *_e .Reader ;_cg ,_ad ,_d int ;_de bool ;};func (_eeb *Writer )WriteSample (sample uint32 )error {if _ ,_dg :=_eeb ._dbd .WriteBits (uint64 (sample ),_eeb ._cc .BitsPerComponent );_dg !=nil {return _dg ;};_eeb ._ec --;
    27  if _eeb ._ec ==0{_eeb ._ec =_eeb ._cc .ColorComponents ;_eeb ._ge ++;};if _eeb ._ge ==_eeb ._cc .Width {if _eeb ._ecg {_eeb ._dbd .FinishByte ();};_eeb ._ge =0;};return nil ;};