mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
27 lines
4.5 KiB
Go
27 lines
4.5 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 sampling ;import (_ab "github.com/unidoc/unipdf/v3/internal/bitwise";_c "github.com/unidoc/unipdf/v3/internal/imageutil";_g "io";);func (_f *Reader )ReadSamples (samples []uint32 )(_ba error ){for _ac :=0;_ac < len (samples );_ac ++{samples [_ac ],_ba =_f .ReadSample ();
|
|
if _ba !=nil {return _ba ;};};return nil ;};func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _fe []uint32 ;_ce :=bitsPerOutputSample ;var _fb uint32 ;var _fcd uint32 ;_gg :=0;_ad :=0;_ed :=0;for _ed < len (data ){if _gg > 0{_gf :=_gg ;
|
|
if _ce < _gf {_gf =_ce ;};_fb =(_fb <<uint (_gf ))|(_fcd >>uint (bitsPerInputSample -_gf ));_gg -=_gf ;if _gg > 0{_fcd =_fcd <<uint (_gf );}else {_fcd =0;};_ce -=_gf ;if _ce ==0{_fe =append (_fe ,_fb );_ce =bitsPerOutputSample ;_fb =0;_ad ++;};}else {_ddf :=data [_ed ];
|
|
_ed ++;_eed :=bitsPerInputSample ;if _ce < _eed {_eed =_ce ;};_gg =bitsPerInputSample -_eed ;_fb =(_fb <<uint (_eed ))|(_ddf >>uint (_gg ));if _eed < bitsPerInputSample {_fcd =_ddf <<uint (_eed );};_ce -=_eed ;if _ce ==0{_fe =append (_fe ,_fb );_ce =bitsPerOutputSample ;
|
|
_fb =0;_ad ++;};};};for _gg >=bitsPerOutputSample {_gdb :=_gg ;if _ce < _gdb {_gdb =_ce ;};_fb =(_fb <<uint (_gdb ))|(_fcd >>uint (bitsPerInputSample -_gdb ));_gg -=_gdb ;if _gg > 0{_fcd =_fcd <<uint (_gdb );}else {_fcd =0;};_ce -=_gdb ;if _ce ==0{_fe =append (_fe ,_fb );
|
|
_ce =bitsPerOutputSample ;_fb =0;_ad ++;};};if _ce > 0&&_ce < bitsPerOutputSample {_fb <<=uint (_ce );_fe =append (_fe ,_fb );};return _fe ;};type SampleWriter interface{WriteSample (_gfd uint32 )error ;WriteSamples (_ag []uint32 )error ;};type Reader struct{_d _c .ImageBase ;
|
|
_e *_ab .Reader ;_b ,_ee ,_aa int ;_bd bool ;};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _ca []uint32 ;_bgf :=bitsPerSample ;var _bb uint32 ;var _eb byte ;_da :=0;_dd :=0;_fc :=0;for _fc < len (data ){if _da > 0{_dc :=_da ;if _bgf < _dc {_dc =_bgf ;
|
|
};_bb =(_bb <<uint (_dc ))|uint32 (_eb >>uint (8-_dc ));_da -=_dc ;if _da > 0{_eb =_eb <<uint (_dc );}else {_eb =0;};_bgf -=_dc ;if _bgf ==0{_ca =append (_ca ,_bb );_bgf =bitsPerSample ;_bb =0;_dd ++;};}else {_cf :=data [_fc ];_fc ++;_gb :=8;if _bgf < _gb {_gb =_bgf ;
|
|
};_da =8-_gb ;_bb =(_bb <<uint (_gb ))|uint32 (_cf >>uint (_da ));if _gb < 8{_eb =_cf <<uint (_gb );};_bgf -=_gb ;if _bgf ==0{_ca =append (_ca ,_bb );_bgf =bitsPerSample ;_bb =0;_dd ++;};};};for _da >=bitsPerSample {_gbe :=_da ;if _bgf < _gbe {_gbe =_bgf ;
|
|
};_bb =(_bb <<uint (_gbe ))|uint32 (_eb >>uint (8-_gbe ));_da -=_gbe ;if _da > 0{_eb =_eb <<uint (_gbe );}else {_eb =0;};_bgf -=_gbe ;if _bgf ==0{_ca =append (_ca ,_bb );_bgf =bitsPerSample ;_bb =0;_dd ++;};};return _ca ;};type Writer struct{_ga _c .ImageBase ;
|
|
_bf *_ab .Writer ;_df ,_ade int ;_bbf bool ;};func NewReader (img _c .ImageBase )*Reader {return &Reader {_e :_ab .NewReader (img .Data ),_d :img ,_aa :img .ColorComponents ,_bd :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };
|
|
};func (_gd *Reader )ReadSample ()(uint32 ,error ){if _gd ._ee ==_gd ._d .Height {return 0,_g .EOF ;};_bg ,_eeb :=_gd ._e .ReadBits (byte (_gd ._d .BitsPerComponent ));if _eeb !=nil {return 0,_eeb ;};_gd ._aa --;if _gd ._aa ==0{_gd ._aa =_gd ._d .ColorComponents ;
|
|
_gd ._b ++;};if _gd ._b ==_gd ._d .Width {if _gd ._bd {_gd ._e .ConsumeRemainingBits ();};_gd ._b =0;_gd ._ee ++;};return uint32 (_bg ),nil ;};func (_fba *Writer )WriteSample (sample uint32 )error {if _ ,_dad :=_fba ._bf .WriteBits (uint64 (sample ),_fba ._ga .BitsPerComponent );
|
|
_dad !=nil {return _dad ;};_fba ._ade --;if _fba ._ade ==0{_fba ._ade =_fba ._ga .ColorComponents ;_fba ._df ++;};if _fba ._df ==_fba ._ga .Width {if _fba ._bbf {_fba ._bf .FinishByte ();};_fba ._df =0;};return nil ;};type SampleReader interface{ReadSample ()(uint32 ,error );
|
|
ReadSamples (_cg []uint32 )error ;};func (_ddg *Writer )WriteSamples (samples []uint32 )error {for _cfb :=0;_cfb < len (samples );_cfb ++{if _ae :=_ddg .WriteSample (samples [_cfb ]);_ae !=nil {return _ae ;};};return nil ;};func NewWriter (img _c .ImageBase )*Writer {return &Writer {_bf :_ab .NewWriterMSB (img .Data ),_ga :img ,_ade :img .ColorComponents ,_bbf :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };
|
|
}; |