mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
12 lines
4.6 KiB
Go
12 lines
4.6 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 (_a "github.com/unidoc/unipdf/v3/internal/bitwise";_g "github.com/unidoc/unipdf/v3/internal/imageutil";_e "io";);func (_eg *Reader )ReadSamples (samples []uint32 )(_fd error ){for _c :=0;_c < len (samples );_c ++{samples [_c ],_fd =_eg .ReadSample ();if _fd !=nil {return _fd ;};};return nil ;};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _ff []uint32 ;_ab :=bitsPerSample ;var _ef uint32 ;var _ggd byte ;_bd :=0;_bf :=0;_ed :=0;for _ed < len (data ){if _bd > 0{_aff :=_bd ;if _ab < _aff {_aff =_ab ;};_ef =(_ef <<uint (_aff ))|uint32 (_ggd >>uint (8-_aff ));_bd -=_aff ;if _bd > 0{_ggd =_ggd <<uint (_aff );}else {_ggd =0;};_ab -=_aff ;if _ab ==0{_ff =append (_ff ,_ef );_ab =bitsPerSample ;_ef =0;_bf ++;};}else {_bb :=data [_ed ];_ed ++;_fef :=8;if _ab < _fef {_fef =_ab ;};_bd =8-_fef ;_ef =(_ef <<uint (_fef ))|uint32 (_bb >>uint (_bd ));if _fef < 8{_ggd =_bb <<uint (_fef );};_ab -=_fef ;if _ab ==0{_ff =append (_ff ,_ef );_ab =bitsPerSample ;_ef =0;_bf ++;};};};for _bd >=bitsPerSample {_ce :=_bd ;if _ab < _ce {_ce =_ab ;};_ef =(_ef <<uint (_ce ))|uint32 (_ggd >>uint (8-_ce ));_bd -=_ce ;if _bd > 0{_ggd =_ggd <<uint (_ce );}else {_ggd =0;};_ab -=_ce ;if _ab ==0{_ff =append (_ff ,_ef );_ab =bitsPerSample ;_ef =0;_bf ++;};};return _ff ;};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_ea []uint32 )error ;};func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _dd []uint32 ;_efe :=bitsPerOutputSample ;var _gd uint32 ;var _ca uint32 ;_ag :=0;_ae :=0;_db :=0;for _db < len (data ){if _ag > 0{_ege :=_ag ;if _efe < _ege {_ege =_efe ;};_gd =(_gd <<uint (_ege ))|uint32 (_ca >>uint (bitsPerInputSample -_ege ));_ag -=_ege ;if _ag > 0{_ca =_ca <<uint (_ege );}else {_ca =0;};_efe -=_ege ;if _efe ==0{_dd =append (_dd ,_gd );_efe =bitsPerOutputSample ;_gd =0;_ae ++;};}else {_dg :=data [_db ];_db ++;_bbe :=bitsPerInputSample ;if _efe < _bbe {_bbe =_efe ;};_ag =bitsPerInputSample -_bbe ;_gd =(_gd <<uint (_bbe ))|uint32 (_dg >>uint (_ag ));if _bbe < bitsPerInputSample {_ca =_dg <<uint (_bbe );};_efe -=_bbe ;if _efe ==0{_dd =append (_dd ,_gd );_efe =bitsPerOutputSample ;_gd =0;_ae ++;};};};for _ag >=bitsPerOutputSample {_eac :=_ag ;if _efe < _eac {_eac =_efe ;};_gd =(_gd <<uint (_eac ))|uint32 (_ca >>uint (bitsPerInputSample -_eac ));_ag -=_eac ;if _ag > 0{_ca =_ca <<uint (_eac );}else {_ca =0;};_efe -=_eac ;if _efe ==0{_dd =append (_dd ,_gd );_efe =bitsPerOutputSample ;_gd =0;_ae ++;};};if _efe > 0&&_efe < bitsPerOutputSample {_gd <<=uint (_efe );_dd =append (_dd ,_gd );};return _dd ;};func (_bbb *Writer )WriteSample (sample uint32 )error {if _ ,_geg :=_bbb ._cc .WriteBits (uint64 (sample ),_bbb ._afb .BitsPerComponent );_geg !=nil {return _geg ;};_bbb ._ggf --;if _bbb ._ggf ==0{_bbb ._ggf =_bbb ._afb .ColorComponents ;_bbb ._cec ++;};if _bbb ._cec ==_bbb ._afb .Width {if _bbb ._fbd {_bbb ._cc .FinishByte ();};_bbb ._cec =0;};return nil ;};type SampleWriter interface{WriteSample (_gdf uint32 )error ;WriteSamples (_ge []uint32 )error ;};func (_aa *Writer )WriteSamples (samples []uint32 )error {for _fbc :=0;_fbc < len (samples );_fbc ++{if _fed :=_aa .WriteSample (samples [_fbc ]);_fed !=nil {return _fed ;};};return nil ;};func NewReader (img _g .ImageBase )*Reader {return &Reader {_fe :_a .NewReader (img .Data ),_f :img ,_ga :img .ColorComponents ,_dc :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};type Reader struct{_f _g .ImageBase ;_fe *_a .Reader ;_b ,_gg ,_ga int ;_dc bool ;};func (_fb *Reader )ReadSample ()(uint32 ,error ){if _fb ._gg ==_fb ._f .Height {return 0,_e .EOF ;};_fg ,_af :=_fb ._fe .ReadBits (byte (_fb ._f .BitsPerComponent ));if _af !=nil {return 0,_af ;};_fb ._ga --;if _fb ._ga ==0{_fb ._ga =_fb ._f .ColorComponents ;_fb ._b ++;};if _fb ._b ==_fb ._f .Width {if _fb ._dc {_fb ._fe .ConsumeRemainingBits ();};_fb ._b =0;_fb ._gg ++;};return uint32 (_fg ),nil ;};type Writer struct{_afb _g .ImageBase ;_cc *_a .Writer ;_cec ,_ggf int ;_fbd bool ;};func NewWriter (img _g .ImageBase )*Writer {return &Writer {_cc :_a .NewWriterMSB (img .Data ),_afb :img ,_ggf :img .ColorComponents ,_fbd :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };}; |