mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
12 lines
49 KiB
Go
12 lines
49 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 imageutil ;import (_ag "errors";_b "fmt";_d "github.com/unidoc/unipdf/v3/internal/bitwise";_fe "image";_ac "image/color";_f "image/draw";_e "math";);func _bfef (_cdbc *_fe .Gray16 ,_cfbg uint8 )*_fe .Gray {_adbb :=_cdbc .Bounds ();_dcbb :=_fe .NewGray (_adbb );for _gbeg :=0;_gbeg < _adbb .Dx ();_gbeg ++{for _bade :=0;_bade < _adbb .Dy ();_bade ++{_dcbc :=_cdbc .Gray16At (_gbeg ,_bade );_dcbb .SetGray (_gbeg ,_bade ,_ac .Gray {Y :_aaba (uint8 (_dcbc .Y /256),_cfbg )});};};return _dcbb ;};func _dged (_egcab CMYK ,_edff NRGBA ,_ecdg _fe .Rectangle ){for _eeag :=0;_eeag < _ecdg .Max .X ;_eeag ++{for _fgdd :=0;_fgdd < _ecdg .Max .Y ;_fgdd ++{_dadb :=_egcab .CMYKAt (_eeag ,_fgdd );_edff .SetNRGBA (_eeag ,_fgdd ,_db (_dadb ));};};};func _gead (_geda uint8 )bool {if _geda ==0||_geda ==255{return true ;};return false ;};func ColorAtGrayscale (x ,y ,bitsPerColor ,bytesPerLine int ,data []byte ,decode []float64 )(_ac .Color ,error ){switch bitsPerColor {case 1:return ColorAtGray1BPC (x ,y ,bytesPerLine ,data ,decode );case 2:return ColorAtGray2BPC (x ,y ,bytesPerLine ,data ,decode );case 4:return ColorAtGray4BPC (x ,y ,bytesPerLine ,data ,decode );case 8:return ColorAtGray8BPC (x ,y ,bytesPerLine ,data ,decode );case 16:return ColorAtGray16BPC (x ,y ,bytesPerLine ,data ,decode );default:return nil ,_b .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0067\u0072\u0061\u0079\u0020\u0073c\u0061\u006c\u0065\u0020\u0062\u0069\u0074s\u0020\u0070\u0065\u0072\u0020\u0063\u006f\u006c\u006f\u0072\u0020a\u006d\u006f\u0075\u006e\u0074\u003a\u0020\u0027\u0025\u0064\u0027",bitsPerColor );};};func (_df *CMYK32 )ColorAt (x ,y int )(_ac .Color ,error ){return ColorAtCMYK (x ,y ,_df .Width ,_df .Data ,_df .Decode );};func (_ecg *Monochrome )ColorAt (x ,y int )(_ac .Color ,error ){return ColorAtGray1BPC (x ,y ,_ecg .BytesPerLine ,_ecg .Data ,_ecg .Decode );};func _fefcb (){for _bdfb :=0;_bdfb < 256;_bdfb ++{_fabb [_bdfb ]=uint8 (_bdfb &0x1)+(uint8 (_bdfb >>1)&0x1)+(uint8 (_bdfb >>2)&0x1)+(uint8 (_bdfb >>3)&0x1)+(uint8 (_bdfb >>4)&0x1)+(uint8 (_bdfb >>5)&0x1)+(uint8 (_bdfb >>6)&0x1)+(uint8 (_bdfb >>7)&0x1);};};func ColorAtNRGBA32 (x ,y ,width int ,data ,alpha []byte ,decode []float64 )(_ac .NRGBA ,error ){_bggc :=y *width +x ;_adgae :=3*_bggc ;if _adgae +2>=len (data ){return _ac .NRGBA {},_b .Errorf ("\u0069\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006f\u0072\u0064\u0069\u006ea\u0074\u0065\u0073\u0020\u006f\u0075t\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065\u0020\u0028\u0025\u0064,\u0020\u0025\u0064\u0029",x ,y );};_gcfa :=uint8 (0xff);if alpha !=nil &&len (alpha )> _bggc {_gcfa =alpha [_bggc ];};_aadb ,_ebggd ,_bffb :=data [_adgae ],data [_adgae +1],data [_adgae +2];if len (decode )==6{_aadb =uint8 (uint32 (LinearInterpolate (float64 (_aadb ),0,255,decode [0],decode [1]))&0xff);_ebggd =uint8 (uint32 (LinearInterpolate (float64 (_ebggd ),0,255,decode [2],decode [3]))&0xff);_bffb =uint8 (uint32 (LinearInterpolate (float64 (_bffb ),0,255,decode [4],decode [5]))&0xff);};return _ac .NRGBA {R :_aadb ,G :_ebggd ,B :_bffb ,A :_gcfa },nil ;};type CMYK32 struct{ImageBase };var _ Image =&NRGBA32 {};func _fg (_cfbe _fe .Image )(Image ,error ){if _gd ,_ff :=_cfbe .(*CMYK32 );_ff {return _gd .Copy (),nil ;};_dga :=_cfbe .Bounds ();_dc ,_bcc :=NewImage (_dga .Max .X ,_dga .Max .Y ,8,4,nil ,nil ,nil );if _bcc !=nil {return nil ,_bcc ;};switch _ebb :=_cfbe .(type ){case CMYK :_fbe (_ebb ,_dc .(CMYK ),_dga );case Gray :_ad (_ebb ,_dc .(CMYK ),_dga );case NRGBA :_ef (_ebb ,_dc .(CMYK ),_dga );case RGBA :_ec (_ebb ,_dc .(CMYK ),_dga );default:_bef (_cfbe ,_dc ,_dga );};return _dc ,nil ;};func (_egb *Monochrome )setGray (_cda int ,_abg _ac .Gray ,_efa int ){if _abg .Y ==0{_egb .clearBit (_efa ,_cda );}else {_egb .setBit (_efa ,_cda );};};var _ _fe .Image =&NRGBA16 {};func (_cge *Gray4 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_cge .Width ,Y :_cge .Height }};};var _ _fe .Image =&Gray2 {};func ColorAtGray1BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_ac .Gray ,error ){_acf :=y *bytesPerLine +x >>3;if _acf >=len (data ){return _ac .Gray {},_b .Errorf ("\u0069\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006f\u0072\u0064\u0069\u006ea\u0074\u0065\u0073\u0020\u006f\u0075t\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065\u0020\u0028\u0025\u0064,\u0020\u0025\u0064\u0029",x ,y );};_ddf :=data [_acf ]>>uint (7-(x &7))&1;if len (decode )==2{_ddf =uint8 (LinearInterpolate (float64 (_ddf ),0.0,1.0,decode [0],decode [1]))&1;};return _ac .Gray {Y :_ddf *255},nil ;};func _dacd (_eebf *_fe .Gray )bool {for _afbc :=0;_afbc < len (_eebf .Pix );_afbc ++{if !_gead (_eebf .Pix [_afbc ]){return false ;};};return true ;};func (_cedd *NRGBA32 )Set (x ,y int ,c _ac .Color ){_edgaf :=y *_cedd .Width +x ;_dbc :=3*_edgaf ;if _dbc +2>=len (_cedd .Data ){return ;};_cgd :=_ac .NRGBAModel .Convert (c ).(_ac .NRGBA );_cedd .setRGBA (_edgaf ,_cgd );};func GrayHistogram (g Gray )(_deb [256]int ){switch _dgbe :=g .(type ){case Histogramer :return _dgbe .Histogram ();case _fe .Image :_gaeg :=_dgbe .Bounds ();for _gacec :=0;_gacec < _gaeg .Max .X ;_gacec ++{for _cde :=0;_cde < _gaeg .Max .Y ;_cde ++{_deb [g .GrayAt (_gacec ,_cde ).Y ]++;};};return _deb ;default:return [256]int {};};};var _ Gray =&Gray2 {};func (_cf *CMYK32 )Base ()*ImageBase {return &_cf .ImageBase };var _ Gray =&Gray4 {};func _faa (_cca ,_ebcg Gray ,_cdgb _fe .Rectangle ){for _cfac :=0;_cfac < _cdgb .Max .X ;_cfac ++{for _bcda :=0;_bcda < _cdgb .Max .Y ;_bcda ++{_ebcg .SetGray (_cfac ,_bcda ,_cca .GrayAt (_cfac ,_bcda ));};};};func ColorAtGray4BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_ac .Gray ,error ){_bbd :=y *bytesPerLine +x >>1;if _bbd >=len (data ){return _ac .Gray {},_b .Errorf ("\u0069\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006f\u0072\u0064\u0069\u006ea\u0074\u0065\u0073\u0020\u006f\u0075t\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065\u0020\u0028\u0025\u0064,\u0020\u0025\u0064\u0029",x ,y );};_gddg :=data [_bbd ]>>uint (4-(x &1)*4)&0xf;if len (decode )==2{_gddg =uint8 (uint32 (LinearInterpolate (float64 (_gddg ),0,15,decode [0],decode [1]))&0xf);};return _ac .Gray {Y :_gddg *17&0xff},nil ;};func (_cbgc *Monochrome )At (x ,y int )_ac .Color {_feg ,_ :=_cbgc .ColorAt (x ,y );return _feg };func (_gace *NRGBA64 )Copy ()Image {return &NRGBA64 {ImageBase :_gace .copy ()}};func _edc (_ege _fe .Image )(Image ,error ){if _bcab ,_faf :=_ege .(*Monochrome );_faf {return _bcab ,nil ;};_dcc ,_ddb :=_ege .(Gray );if !_ddb {_aacf ,_bee :=GrayConverter .Convert (_ege );if _bee !=nil {return nil ,_bee ;};_dcc =_aacf .(Gray );};_daa :=_ege .Bounds ();_fgd ,_cfe :=NewImage (_daa .Max .X ,_daa .Max .Y ,1,1,nil ,nil ,nil );if _cfe !=nil {return nil ,_cfe ;};_eff :=_fgd .(*Monochrome );_bbc :=AutoThresholdTriangle (GrayHistogram (_dcc ));for _fgg :=0;_fgg < _daa .Max .X ;_fgg ++{for _dad :=0;_dad < _daa .Max .Y ;_dad ++{_gef :=_eeg (_dcc .GrayAt (_fgg ,_dad ),monochromeModel (_bbc ));_eff .SetGray (_fgg ,_dad ,_gef );};};return _fgd ,nil ;};func ImgToGray (i _fe .Image )*_fe .Gray {if _dbgd ,_fecc :=i .(*_fe .Gray );_fecc {return _dbgd ;};_abgc :=i .Bounds ();_fceb :=_fe .NewGray (_abgc );for _egce :=0;_egce < _abgc .Max .X ;_egce ++{for _gcef :=0;_gcef < _abgc .Max .Y ;_gcef ++{_aedd :=i .At (_egce ,_gcef );_fceb .Set (_egce ,_gcef ,_aedd );};};return _fceb ;};var _ _fe .Image =&Gray16 {};func GetConverter (bitsPerComponent ,colorComponents int )(ColorConverter ,error ){switch colorComponents {case 1:switch bitsPerComponent {case 1:return MonochromeConverter ,nil ;case 2:return Gray2Converter ,nil ;case 4:return Gray4Converter ,nil ;case 8:return GrayConverter ,nil ;case 16:return Gray16Converter ,nil ;};case 3:switch bitsPerComponent {case 4:return NRGBA16Converter ,nil ;case 8:return NRGBAConverter ,nil ;case 16:return NRGBA64Converter ,nil ;};case 4:return CMYKConverter ,nil ;};return nil ,_b .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u0063\u006f\u006c\u006f\u0072\u0043o\u006e\u0076\u0065\u0072\u0074\u0065\u0072\u0020\u0070\u0061\u0072\u0061\u006d\u0065t\u0065\u0072\u0073\u002e\u0020\u0042\u0069\u0074\u0073\u0050\u0065\u0072\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074\u003a\u0020\u0025\u0064\u002c\u0020\u0043\u006f\u006co\u0072\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006et\u0073\u003a \u0025\u0064",bitsPerComponent ,colorComponents );};func _dge (_dd _ac .Gray )_ac .NRGBA {return _ac .NRGBA {R :_dd .Y ,G :_dd .Y ,B :_dd .Y ,A :0xff}};func ColorAtNRGBA16 (x ,y ,width ,bytesPerLine int ,data ,alpha []byte ,decode []float64 )(_ac .NRGBA ,error ){_bfeg :=y *bytesPerLine +x *3/2;if _bfeg +1>=len (data ){return _ac .NRGBA {},_bfbc (x ,y );};const (_edd =0xf;_dde =uint8 (0xff););_ddfe :=_dde ;if alpha !=nil {_aae :=y *BytesPerLine (width ,4,1);if _aae < len (alpha ){if x %2==0{_ddfe =(alpha [_aae ]>>uint (4))&_edd ;}else {_ddfe =alpha [_aae ]&_edd ;};_ddfe |=_ddfe <<4;};};var _adga ,_gdad ,_acab uint8 ;if x *3%2==0{_adga =(data [_bfeg ]>>uint (4))&_edd ;_gdad =data [_bfeg ]&_edd ;_acab =(data [_bfeg +1]>>uint (4))&_edd ;}else {_adga =data [_bfeg ]&_edd ;_gdad =(data [_bfeg +1]>>uint (4))&_edd ;_acab =data [_bfeg +1]&_edd ;};if len (decode )==6{_adga =uint8 (uint32 (LinearInterpolate (float64 (_adga ),0,15,decode [0],decode [1]))&0xf);_gdad =uint8 (uint32 (LinearInterpolate (float64 (_gdad ),0,15,decode [2],decode [3]))&0xf);_acab =uint8 (uint32 (LinearInterpolate (float64 (_acab ),0,15,decode [4],decode [5]))&0xf);};return _ac .NRGBA {R :(_adga <<4)|(_adga &0xf),G :(_gdad <<4)|(_gdad &0xf),B :(_acab <<4)|(_acab &0xf),A :_ddfe },nil ;};func (_edga *Gray2 )Base ()*ImageBase {return &_edga .ImageBase };func _eaf (_dcff _ac .Color )_ac .Color {_eaff :=_ac .GrayModel .Convert (_dcff ).(_ac .Gray );return _cdd (_eaff );};func (_eef *Gray2 )ColorModel ()_ac .Model {return Gray2Model };func (_bagf *Gray4 )ColorModel ()_ac .Model {return Gray4Model };func (_aec *Gray16 )ColorModel ()_ac .Model {return _ac .Gray16Model };func (_cbb *Gray4 )At (x ,y int )_ac .Color {_febf ,_ :=_cbb .ColorAt (x ,y );return _febf };func (_aag *Gray4 )GrayAt (x ,y int )_ac .Gray {_egf ,_ :=ColorAtGray4BPC (x ,y ,_aag .BytesPerLine ,_aag .Data ,_aag .Decode );return _egf ;};func ColorAt (x ,y ,width ,bitsPerColor ,colorComponents ,bytesPerLine int ,data ,alpha []byte ,decode []float64 )(_ac .Color ,error ){switch colorComponents {case 1:return ColorAtGrayscale (x ,y ,bitsPerColor ,bytesPerLine ,data ,decode );case 3:return ColorAtNRGBA (x ,y ,width ,bytesPerLine ,bitsPerColor ,data ,alpha ,decode );case 4:return ColorAtCMYK (x ,y ,width ,data ,decode );default:return nil ,_b .Errorf ("\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063o\u006c\u006f\u0072\u0020\u0063\u006f\u006dp\u006f\u006e\u0065\u006e\u0074\u0020\u0066\u006f\u0072\u0020\u0074h\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u003a\u0020\u0025\u0064",colorComponents );};};func ColorAtGray16BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_ac .Gray16 ,error ){_bdf :=(y *bytesPerLine /2+x )*2;if _bdf +1>=len (data ){return _ac .Gray16 {},_b .Errorf ("\u0069\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006f\u0072\u0064\u0069\u006ea\u0074\u0065\u0073\u0020\u006f\u0075t\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065\u0020\u0028\u0025\u0064,\u0020\u0025\u0064\u0029",x ,y );};_gffd :=uint16 (data [_bdf ])<<8|uint16 (data [_bdf +1]);if len (decode )==2{_gffd =uint16 (uint64 (LinearInterpolate (float64 (_gffd ),0,65535,decode [0],decode [1])));};return _ac .Gray16 {Y :_gffd },nil ;};func init (){_fefcb ()};func _fefc (_agf _ac .CMYK )_ac .Gray {_add ,_dfg ,_eaa :=_ac .CMYKToRGB (_agf .C ,_agf .M ,_agf .Y ,_agf .K );_agaa :=(19595*uint32 (_add )+38470*uint32 (_dfg )+7471*uint32 (_eaa )+1<<7)>>16;return _ac .Gray {Y :uint8 (_agaa )};};func _cdd (_cc _ac .Gray )_ac .Gray {_dgcd :=_cc .Y >>6;_dgcd |=_dgcd <<2;_cc .Y =_dgcd |_dgcd <<4;return _cc ;};func (_fgga *NRGBA32 )ColorAt (x ,y int )(_ac .Color ,error ){return ColorAtNRGBA32 (x ,y ,_fgga .Width ,_fgga .Data ,_fgga .Alpha ,_fgga .Decode );};type NRGBA32 struct{ImageBase };func (_gbg *NRGBA16 )Copy ()Image {return &NRGBA16 {ImageBase :_gbg .copy ()}};func ColorAtNRGBA64 (x ,y ,width int ,data ,alpha []byte ,decode []float64 )(_ac .NRGBA64 ,error ){_ggfg :=(y *width +x )*2;_afaef :=_ggfg *3;if _afaef +5>=len (data ){return _ac .NRGBA64 {},_b .Errorf ("\u0069\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006f\u0072\u0064\u0069\u006ea\u0074\u0065\u0073\u0020\u006f\u0075t\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065\u0020\u0028\u0025\u0064,\u0020\u0025\u0064\u0029",x ,y );};const _ffba =0xffff;_bfac :=uint16 (_ffba );if alpha !=nil &&len (alpha )> _ggfg +1{_bfac =uint16 (alpha [_ggfg ])<<8|uint16 (alpha [_ggfg +1]);};_adb :=uint16 (data [_afaef ])<<8|uint16 (data [_afaef +1]);_adgd :=uint16 (data [_afaef +2])<<8|uint16 (data [_afaef +3]);_ecdb :=uint16 (data [_afaef +4])<<8|uint16 (data [_afaef +5]);if len (decode )==6{_adb =uint16 (uint64 (LinearInterpolate (float64 (_adb ),0,65535,decode [0],decode [1]))&_ffba );_adgd =uint16 (uint64 (LinearInterpolate (float64 (_adgd ),0,65535,decode [2],decode [3]))&_ffba );_ecdb =uint16 (uint64 (LinearInterpolate (float64 (_ecdb ),0,65535,decode [4],decode [5]))&_ffba );};return _ac .NRGBA64 {R :_adb ,G :_adgd ,B :_ecdb ,A :_bfac },nil ;};var ErrInvalidImage =_ag .New ("i\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0069\u006da\u0067\u0065\u0020\u0064\u0061\u0074\u0061 s\u0069\u007a\u0065\u0020f\u006f\u0072\u0020\u0070\u0072\u006f\u0076\u0069\u0064ed\u0020\u0064i\u006d\u0065\u006e\u0073\u0069\u006f\u006e\u0073");func (_bgb *monochromeThresholdConverter )Convert (img _fe .Image )(Image ,error ){if _eae ,_fba :=img .(*Monochrome );_fba {return _eae .Copy (),nil ;};_bad :=img .Bounds ();_dee ,_fgge :=NewImage (_bad .Max .X ,_bad .Max .Y ,1,1,nil ,nil ,nil );if _fgge !=nil {return nil ,_fgge ;};_dee .(*Monochrome ).ModelThreshold =_bgb .Threshold ;for _gff :=0;_gff < _bad .Max .X ;_gff ++{for _cfbb :=0;_cfbb < _bad .Max .Y ;_cfbb ++{_gdc :=img .At (_gff ,_cfbb );_dee .Set (_gff ,_cfbb ,_gdc );};};return _dee ,nil ;};func (_fbgfd *Gray2 )Set (x ,y int ,c _ac .Color ){if x >=_fbgfd .Width ||y >=_fbgfd .Height {return ;};_ddfb :=Gray2Model .Convert (c ).(_ac .Gray );_agfa :=y *_fbgfd .BytesPerLine ;_afae :=_agfa +(x >>2);_bcg :=_ddfb .Y >>6;_fbgfd .Data [_afae ]=(_fbgfd .Data [_afae ]&(^(0xc0>>uint (2*((x )&3)))))|(_bcg <<uint (6-2*(x &3)));};func (_cbbe *Gray16 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_cbbe .Width ,Y :_cbbe .Height }};};type CMYK interface{CMYKAt (_c ,_fc int )_ac .CMYK ;SetCMYK (_bc ,_fd int ,_cg _ac .CMYK );};func _aaba (_bfaf ,_edgd uint8 )uint8 {if _bfaf < _edgd {return 255;};return 0;};func _gdgb (_ffaa CMYK ,_gee Gray ,_cbdb _fe .Rectangle ){for _cga :=0;_cga < _cbdb .Max .X ;_cga ++{for _dgff :=0;_dgff < _cbdb .Max .Y ;_dgff ++{_efe :=_fefc (_ffaa .CMYKAt (_cga ,_dgff ));_gee .SetGray (_cga ,_dgff ,_efe );};};};var _ Image =&NRGBA16 {};func NewImage (width ,height ,bitsPerComponent ,colorComponents int ,data ,alpha []byte ,decode []float64 )(Image ,error ){_eeda :=NewImageBase (width ,height ,bitsPerComponent ,colorComponents ,data ,alpha ,decode );var _cabe Image ;switch colorComponents {case 1:switch bitsPerComponent {case 1:_cabe =&Monochrome {ImageBase :_eeda ,ModelThreshold :0x0f};case 2:_cabe =&Gray2 {ImageBase :_eeda };case 4:_cabe =&Gray4 {ImageBase :_eeda };case 8:_cabe =&Gray8 {ImageBase :_eeda };case 16:_cabe =&Gray16 {ImageBase :_eeda };};case 3:switch bitsPerComponent {case 4:_cabe =&NRGBA16 {ImageBase :_eeda };case 8:_cabe =&NRGBA32 {ImageBase :_eeda };case 16:_cabe =&NRGBA64 {ImageBase :_eeda };};case 4:_cabe =&CMYK32 {ImageBase :_eeda };};if _cabe ==nil {return nil ,ErrInvalidImage ;};return _cabe ,nil ;};func ColorAtGray8BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_ac .Gray ,error ){_ddfd :=y *bytesPerLine +x ;if _ddfd >=len (data ){return _ac .Gray {},_b .Errorf ("\u0069\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006f\u0072\u0064\u0069\u006ea\u0074\u0065\u0073\u0020\u006f\u0075t\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065\u0020\u0028\u0025\u0064,\u0020\u0025\u0064\u0029",x ,y );};_ffa :=data [_ddfd ];if len (decode )==2{_ffa =uint8 (uint32 (LinearInterpolate (float64 (_ffa ),0,255,decode [0],decode [1]))&0xff);};return _ac .Gray {Y :_ffa },nil ;};var _ _fe .Image =&Gray4 {};type Gray2 struct{ImageBase };func _aab (_fbc _ac .RGBA )_ac .NRGBA {switch _fbc .A {case 0xff:return _ac .NRGBA {R :_fbc .R ,G :_fbc .G ,B :_fbc .B ,A :0xff};case 0x00:return _ac .NRGBA {};default:_eca ,_dgb ,_dec ,_cae :=_fbc .RGBA ();_eca =(_eca *0xffff)/_cae ;_dgb =(_dgb *0xffff)/_cae ;_dec =(_dec *0xffff)/_cae ;return _ac .NRGBA {R :uint8 (_eca >>8),G :uint8 (_dgb >>8),B :uint8 (_dec >>8),A :uint8 (_cae >>8)};};};func _gbf (_dea _ac .NRGBA64 )_ac .NRGBA {return _ac .NRGBA {R :uint8 (_dea .R >>8),G :uint8 (_dea .G >>8),B :uint8 (_dea .B >>8),A :uint8 (_dea .A >>8)};};func (_dba *Monochrome )Copy ()Image {return &Monochrome {ImageBase :_dba .ImageBase .copy (),ModelThreshold :_dba .ModelThreshold };};func _bfbc (_eade int ,_cddf int )error {return _b .Errorf ("\u0069\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006f\u0072\u0064\u0069\u006ea\u0074\u0065\u0073\u0020\u006f\u0075t\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065\u0020\u0028\u0025\u0064,\u0020\u0025\u0064\u0029",_eade ,_cddf );};func (_gfe *Gray8 )Copy ()Image {return &Gray8 {ImageBase :_gfe .copy ()}};func (_cgcc *ImageBase )Pix ()[]byte {return _cgcc .Data };func (_gdca *Gray2 )ColorAt (x ,y int )(_ac .Color ,error ){return ColorAtGray2BPC (x ,y ,_gdca .BytesPerLine ,_gdca .Data ,_gdca .Decode );};func (_ecb *Gray4 )Copy ()Image {return &Gray4 {ImageBase :_ecb .copy ()}};func (_fag *Monochrome )Histogram ()(_cfga [256]int ){for _ ,_fbgf :=range _fag .Data {_cfga [0xff]+=int (_fabb [_fag .Data [_fbgf ]]);};return _cfga ;};func _eeg (_bag _ac .Gray ,_bdb monochromeModel )_ac .Gray {if _bag .Y > uint8 (_bdb ){return _ac .Gray {Y :_e .MaxUint8 };};return _ac .Gray {};};func (_ccea *NRGBA16 )ColorAt (x ,y int )(_ac .Color ,error ){return ColorAtNRGBA16 (x ,y ,_ccea .Width ,_ccea .BytesPerLine ,_ccea .Data ,_ccea .Alpha ,_ccea .Decode );};var (MonochromeConverter =ConverterFunc (_edc );Gray2Converter =ConverterFunc (_dae );Gray4Converter =ConverterFunc (_ceba );GrayConverter =ConverterFunc (_fca );Gray16Converter =ConverterFunc (_bfa );NRGBA16Converter =ConverterFunc (_dgcf );NRGBAConverter =ConverterFunc (_dca );NRGBA64Converter =ConverterFunc (_eaffd );CMYKConverter =ConverterFunc (_fg ););func AutoThresholdTriangle (histogram [256]int )uint8 {var _abef ,_bfg ,_caag ,_fbggc int ;for _dcee :=0;_dcee < len (histogram );_dcee ++{if histogram [_dcee ]> 0{_abef =_dcee ;break ;};};if _abef > 0{_abef --;};for _eegb :=255;_eegb > 0;_eegb --{if histogram [_eegb ]> 0{_fbggc =_eegb ;break ;};};if _fbggc < 255{_fbggc ++;};for _fggg :=0;_fggg < 256;_fggg ++{if histogram [_fggg ]> _bfg {_caag =_fggg ;_bfg =histogram [_fggg ];};};var _gefb bool ;if (_caag -_abef )< (_fbggc -_caag ){_gefb =true ;var _cgeg int ;_cdaf :=255;for _cgeg < _cdaf {_dabc :=histogram [_cgeg ];histogram [_cgeg ]=histogram [_cdaf ];histogram [_cdaf ]=_dabc ;_cgeg ++;_cdaf --;};_abef =255-_fbggc ;_caag =255-_caag ;};if _abef ==_caag {return uint8 (_abef );};_ffbf :=float64 (histogram [_caag ]);_cage :=float64 (_abef -_caag );_fefg :=_e .Sqrt (_ffbf *_ffbf +_cage *_cage );_ffbf /=_fefg ;_cage /=_fefg ;_fefg =_ffbf *float64 (_abef )+_cage *float64 (histogram [_abef ]);_cgfc :=_abef ;var _ecfb float64 ;for _ddfa :=_abef +1;_ddfa <=_caag ;_ddfa ++{_cgca :=_ffbf *float64 (_ddfa )+_cage *float64 (histogram [_ddfa ])-_fefg ;if _cgca > _ecfb {_cgfc =_ddfa ;_ecfb =_cgca ;};};_cgfc --;if _gefb {var _fgfb int ;_gcca :=255;for _fgfb < _gcca {_bbcc :=histogram [_fgfb ];histogram [_fgfb ]=histogram [_gcca ];histogram [_gcca ]=_bbcc ;_fgfb ++;_gcca --;};return uint8 (255-_cgfc );};return uint8 (_cgfc );};func (_faad *NRGBA32 )setRGBA (_bafd int ,_fagd _ac .NRGBA ){_afad :=3*_bafd ;_faad .Data [_afad ]=_fagd .R ;_faad .Data [_afad +1]=_fagd .G ;_faad .Data [_afad +2]=_fagd .B ;if _bafd < len (_faad .Alpha ){_faad .Alpha [_bafd ]=_fagd .A ;};};type ImageBase struct{Width ,Height int ;BitsPerComponent ,ColorComponents int ;Data ,Alpha []byte ;Decode []float64 ;BytesPerLine int ;};func _ceba (_ggfb _fe .Image )(Image ,error ){if _fgf ,_fed :=_ggfb .(*Gray4 );_fed {return _fgf .Copy (),nil ;};_fdc :=_ggfb .Bounds ();_bddg ,_agag :=NewImage (_fdc .Max .X ,_fdc .Max .Y ,4,1,nil ,nil ,nil );if _agag !=nil {return nil ,_agag ;};_cgb (_ggfb ,_bddg ,_fdc );return _bddg ,nil ;};func (_fcg *NRGBA64 )Base ()*ImageBase {return &_fcg .ImageBase };func (_bba *Gray2 )At (x ,y int )_ac .Color {_cdcg ,_ :=_bba .ColorAt (x ,y );return _cdcg };func (_ca *CMYK32 )Set (x ,y int ,c _ac .Color ){_cb :=4*(y *_ca .Width +x );if _cb +3>=len (_ca .Data ){return ;};_acc :=_ac .CMYKModel .Convert (c ).(_ac .CMYK );_ca .Data [_cb ]=_acc .C ;_ca .Data [_cb +1]=_acc .M ;_ca .Data [_cb +2]=_acc .Y ;_ca .Data [_cb +3]=_acc .K ;};func _cfag (_fdb NRGBA ,_ceea Gray ,_aff _fe .Rectangle ){for _deea :=0;_deea < _aff .Max .X ;_deea ++{for _fdd :=0;_fdd < _aff .Max .Y ;_fdd ++{_bgg :=_dgc (_fdb .NRGBAAt (_deea ,_fdd ));_ceea .SetGray (_deea ,_fdd ,_bgg );};};};var _ Gray =&Monochrome {};func (_eb *CMYK32 )SetCMYK (x ,y int ,c _ac .CMYK ){_dg :=4*(y *_eb .Width +x );if _dg +3>=len (_eb .Data ){return ;};_eb .Data [_dg ]=c .C ;_eb .Data [_dg +1]=c .M ;_eb .Data [_dg +2]=c .Y ;_eb .Data [_dg +3]=c .K ;};var _ Gray =&Gray16 {};func (_ffgc *NRGBA64 )Validate ()error {if len (_ffgc .Data )!=3*2*_ffgc .Width *_ffgc .Height {return _ag .New ("i\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0069\u006da\u0067\u0065\u0020\u0064\u0061\u0074\u0061 s\u0069\u007a\u0065\u0020f\u006f\u0072\u0020\u0070\u0072\u006f\u0076\u0069\u0064ed\u0020\u0064i\u006d\u0065\u006e\u0073\u0069\u006f\u006e\u0073");};return nil ;};func (_dac *NRGBA16 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_dac .Width ,Y :_dac .Height }};};func ConverterFunc (converterFunc func (_ebg _fe .Image )(Image ,error ))ColorConverter {return colorConverter {_cfa :converterFunc };};func (_ebdc *NRGBA64 )setNRGBA64 (_dcce int ,_cbf _ac .NRGBA64 ,_fbcd int ){_ebdc .Data [_dcce ]=uint8 (_cbf .R >>8);_ebdc .Data [_dcce +1]=uint8 (_cbf .R &0xff);_ebdc .Data [_dcce +2]=uint8 (_cbf .G >>8);_ebdc .Data [_dcce +3]=uint8 (_cbf .G &0xff);_ebdc .Data [_dcce +4]=uint8 (_cbf .B >>8);_ebdc .Data [_dcce +5]=uint8 (_cbf .B &0xff);if _fbcd +1< len (_ebdc .Alpha ){_ebdc .Alpha [_fbcd ]=uint8 (_cbf .A >>8);_ebdc .Alpha [_fbcd +1]=uint8 (_cbf .A &0xff);};};func _eaffd (_ceed _fe .Image )(Image ,error ){if _dgac ,_adcg :=_ceed .(*NRGBA64 );_adcg {return _dgac .Copy (),nil ;};_dff ,_cbaa ,_fgab :=_edaf (_ceed ,2);_abgb ,_cbab :=NewImage (_dff .Max .X ,_dff .Max .Y ,16,3,nil ,_fgab ,nil );if _cbab !=nil {return nil ,_cbab ;};_dbff (_ceed ,_abgb ,_dff );if len (_fgab )!=0&&!_cbaa {if _aeee :=_gffe (_fgab ,_abgb );_aeee !=nil {return nil ,_aeee ;};};return _abgb ,nil ;};func (_aaa *Monochrome )Base ()*ImageBase {return &_aaa .ImageBase };func (_bcad *Gray4 )Histogram ()(_gfbb [256]int ){for _ccd :=0;_ccd < _bcad .Width ;_ccd ++{for _eac :=0;_eac < _bcad .Height ;_eac ++{_gfbb [_bcad .GrayAt (_ccd ,_eac ).Y ]++;};};return _gfbb ;};func FromGoImage (i _fe .Image )(Image ,error ){switch _ebce :=i .(type ){case Image :return _ebce .Copy (),nil ;case Gray :return GrayConverter .Convert (i );case *_fe .Gray16 :return Gray16Converter .Convert (i );case CMYK :return CMYKConverter .Convert (i );case *_fe .NRGBA64 :return NRGBA64Converter .Convert (i );default:return NRGBAConverter .Convert (i );};};type Gray interface{GrayAt (_gca ,_dbf int )_ac .Gray ;SetGray (_dcf ,_cdg int ,_aeec _ac .Gray );};func (_beee *Monochrome )setBit (_afd ,_ada int ){_beee .Data [_afd ]|=0x80>>uint (_ada &7)};func _cabc (_febe _ac .Gray )_ac .Gray {_febe .Y >>=4;_febe .Y |=_febe .Y <<4;return _febe };func (_edf *NRGBA16 )setNRGBA (_cba ,_fcfc ,_gac int ,_bgc _ac .NRGBA ){if _cba *3%2==0{_edf .Data [_gac ]=(_bgc .R >>4)<<4|(_bgc .G >>4);_edf .Data [_gac +1]=(_bgc .B >>4)<<4|(_edf .Data [_gac +1]&0xf);}else {_edf .Data [_gac ]=(_edf .Data [_gac ]&0xf0)|(_bgc .R >>4);_edf .Data [_gac +1]=(_bgc .G >>4)<<4|(_bgc .B >>4);};if _edf .Alpha !=nil {_eadb :=_fcfc *BytesPerLine (_edf .Width ,4,1);if _eadb < len (_edf .Alpha ){if _cba %2==0{_edf .Alpha [_eadb ]=(_bgc .A >>uint (4))<<uint (4)|(_edf .Alpha [_gac ]&0xf);}else {_edf .Alpha [_eadb ]=(_edf .Alpha [_eadb ]&0xf0)|(_bgc .A >>uint (4));};};};};func (_gae *Gray4 )Base ()*ImageBase {return &_gae .ImageBase };func _aeef (_efgf _ac .NRGBA )_ac .NRGBA {_efgf .R =_efgf .R >>4|(_efgf .R >>4)<<4;_efgf .G =_efgf .G >>4|(_efgf .G >>4)<<4;_efgf .B =_efgf .B >>4|(_efgf .B >>4)<<4;return _efgf ;};type Image interface{_f .Image ;Base ()*ImageBase ;Copy ()Image ;Pix ()[]byte ;ColorAt (_ggbc ,_age int )(_ac .Color ,error );Validate ()error ;};type monochromeModel uint8 ;var _ Image =&Gray16 {};type ColorConverter interface{Convert (_gda _fe .Image )(Image ,error );};var _ _fe .Image =&NRGBA32 {};func (_caa *ImageBase )copy ()ImageBase {_ebbe :=*_caa ;_ebbe .Data =make ([]byte ,len (_caa .Data ));copy (_ebbe .Data ,_caa .Data );return _ebbe ;};func IsGrayImgBlackAndWhite (i *_fe .Gray )bool {return _dacd (i )};var _ _fe .Image =&Monochrome {};func (_fffd *Gray4 )ColorAt (x ,y int )(_ac .Color ,error ){return ColorAtGray4BPC (x ,y ,_fffd .BytesPerLine ,_fffd .Data ,_fffd .Decode );};type Gray8 struct{ImageBase };func (_decbd *ImageBase )MakeAlpha (){_decbd .newAlpha ()};func _cgb (_dag _fe .Image ,_dcfb Image ,_aeed _fe .Rectangle ){switch _fcf :=_dag .(type ){case Gray :_faa (_fcf ,_dcfb .(Gray ),_aeed );case NRGBA :_cfag (_fcf ,_dcfb .(Gray ),_aeed );case CMYK :_gdgb (_fcf ,_dcfb .(Gray ),_aeed );case RGBA :_decb (_fcf ,_dcfb .(Gray ),_aeed );default:_bef (_dag ,_dcfb .(Image ),_aeed );};};type NRGBA16 struct{ImageBase };func (_dbe *Gray16 )SetGray (x ,y int ,g _ac .Gray ){_fdac :=(y *_dbe .BytesPerLine /2+x )*2;if _fdac +1>=len (_dbe .Data ){return ;};_dbe .Data [_fdac ]=g .Y ;_dbe .Data [_fdac +1]=g .Y ;};func (_aga *CMYK32 )ColorModel ()_ac .Model {return _ac .CMYKModel };func (_ebd *Monochrome )GrayAt (x ,y int )_ac .Gray {_acd ,_ :=ColorAtGray1BPC (x ,y ,_ebd .BytesPerLine ,_ebd .Data ,_ebd .Decode );return _acd ;};var _ _fe .Image =&NRGBA64 {};func (_cbe *NRGBA32 )Base ()*ImageBase {return &_cbe .ImageBase };func (_cddc *Gray16 )Copy ()Image {return &Gray16 {ImageBase :_cddc .copy ()}};func (_gfdb *Gray16 )Validate ()error {if len (_gfdb .Data )!=_gfdb .Height *_gfdb .BytesPerLine {return ErrInvalidImage ;};return nil ;};func (_acdg *Gray4 )SetGray (x ,y int ,g _ac .Gray ){if x >=_acdg .Width ||y >=_acdg .Height {return ;};g =_cabc (g );_acdg .setGray (x ,y ,g );};func (_bac *Gray8 )ColorModel ()_ac .Model {return _ac .GrayModel };func _deeb (_aage *_fe .Gray ,_eafe uint8 )*_fe .Gray {_gceab :=_aage .Bounds ();_cfbc :=_fe .NewGray (_gceab );for _abfgc :=0;_abfgc < _gceab .Dx ();_abfgc ++{for _fadg :=0;_fadg < _gceab .Dy ();_fadg ++{_cabg :=_aage .GrayAt (_abfgc ,_fadg );_cfbc .SetGray (_abfgc ,_fadg ,_ac .Gray {Y :_aaba (_cabg .Y ,_eafe )});};};return _cfbc ;};func _dgcf (_ebceg _fe .Image )(Image ,error ){if _dgga ,_gdcf :=_ebceg .(*NRGBA16 );_gdcf {return _dgga .Copy (),nil ;};_gfg :=_ebceg .Bounds ();_adgag ,_bbe :=NewImage (_gfg .Max .X ,_gfg .Max .Y ,4,3,nil ,nil ,nil );if _bbe !=nil {return nil ,_bbe ;};_bcf (_ebceg ,_adgag ,_gfg );return _adgag ,nil ;};func (_bdac *Monochrome )Set (x ,y int ,c _ac .Color ){_ggd :=y *_bdac .BytesPerLine +x >>3;if _ggd > len (_bdac .Data )-1{return ;};_bfe :=_bdac .ColorModel ().Convert (c ).(_ac .Gray );_bdac .setGray (x ,_bfe ,_ggd );};func (_gccdf *NRGBA16 )ColorModel ()_ac .Model {return NRGBA16Model };type nrgba64 interface{NRGBA64At (_edcf ,_fea int )_ac .NRGBA64 ;SetNRGBA64 (_ecga ,_fabg int ,_dfd _ac .NRGBA64 );};func (_gbd *ImageBase )GetAlpha ()[]byte {return _gbd .Alpha };func (_gga *NRGBA32 )SetNRGBA (x ,y int ,c _ac .NRGBA ){_gcg :=y *_gga .Width +x ;_afb :=3*_gcg ;if _afb +2>=len (_gga .Data ){return ;};_gga .setRGBA (_gcg ,c );return ;};func (_ggb *Gray8 )At (x ,y int )_ac .Color {_dgab ,_ :=_ggb .ColorAt (x ,y );return _dgab };var _ Image =&Gray8 {};func (_dgcg *Gray8 )Set (x ,y int ,c _ac .Color ){_fcb :=y *_dgcg .BytesPerLine +x ;if _fcb > len (_dgcg .Data )-1{return ;};_ffc :=_ac .GrayModel .Convert (c );_dgcg .Data [_fcb ]=_ffc .(_ac .Gray ).Y ;};type Gray4 struct{ImageBase };type Gray16 struct{ImageBase };func (_adaf *Gray4 )setGray (_cab int ,_dfc int ,_def _ac .Gray ){_fdg :=_dfc *_adaf .BytesPerLine ;_gcdg :=_fdg +(_cab >>1);if _gcdg >=len (_adaf .Data ){return ;};_ega :=_def .Y >>4;_adaf .Data [_gcdg ]=(_adaf .Data [_gcdg ]&(^(0xf0>>uint (4*(_cab &1)))))|(_ega <<uint (4-4*(_cab &1)));};func _fad (_ffcad *_fe .NYCbCrA ,_aebfg NRGBA ,_dada _fe .Rectangle ){for _gfad :=0;_gfad < _dada .Max .X ;_gfad ++{for _fadf :=0;_fadf < _dada .Max .Y ;_fadf ++{_cfgb :=_ffcad .NYCbCrAAt (_gfad ,_fadf );_aebfg .SetNRGBA (_gfad ,_fadf ,_ffg (_cfgb ));};};};func (_eedc *NRGBA64 )NRGBA64At (x ,y int )_ac .NRGBA64 {_abe ,_ :=ColorAtNRGBA64 (x ,y ,_eedc .Width ,_eedc .Data ,_eedc .Alpha ,_eedc .Decode );return _abe ;};func (_aad *Gray8 )SetGray (x ,y int ,g _ac .Gray ){_efd :=y *_aad .BytesPerLine +x ;if _efd > len (_aad .Data )-1{return ;};_aad .Data [_efd ]=g .Y ;};func (_fec *Gray8 )ColorAt (x ,y int )(_ac .Color ,error ){return ColorAtGray8BPC (x ,y ,_fec .BytesPerLine ,_fec .Data ,_fec .Decode );};func _fca (_egaf _fe .Image )(Image ,error ){if _gfd ,_aca :=_egaf .(*Gray8 );_aca {return _gfd .Copy (),nil ;};_fgc :=_egaf .Bounds ();_cfad ,_fecg :=NewImage (_fgc .Max .X ,_fgc .Max .Y ,8,1,nil ,nil ,nil );if _fecg !=nil {return nil ,_fecg ;};_cgb (_egaf ,_cfad ,_fgc );return _cfad ,nil ;};func _afdd (_dced ,_bea NRGBA ,_ggaa _fe .Rectangle ){for _aebf :=0;_aebf < _ggaa .Max .X ;_aebf ++{for _dagd :=0;_dagd < _ggaa .Max .Y ;_dagd ++{_bea .SetNRGBA (_aebf ,_dagd ,_dced .NRGBAAt (_aebf ,_dagd ));};};};func (_ga *CMYK32 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_ga .Width ,Y :_ga .Height }};};func (_ffgd *Gray8 )GrayAt (x ,y int )_ac .Gray {_fbf ,_ :=ColorAtGray8BPC (x ,y ,_ffgd .BytesPerLine ,_ffgd .Data ,_ffgd .Decode );return _fbf ;};var _ Image =&Monochrome {};func _ab (_fab _ac .RGBA )_ac .Gray {_bda :=(19595*uint32 (_fab .R )+38470*uint32 (_fab .G )+7471*uint32 (_fab .B )+1<<7)>>16;return _ac .Gray {Y :uint8 (_bda )};};func (_ddeb *NRGBA64 )ColorModel ()_ac .Model {return _ac .NRGBA64Model };func (_egg *Monochrome )clearBit (_fdf ,_dfab int ){_egg .Data [_fdf ]&=^(0x80>>uint (_dfab &7))};func _bfa (_deec _fe .Image )(Image ,error ){if _ccc ,_ccg :=_deec .(*Gray16 );_ccg {return _ccc .Copy (),nil ;};_ead :=_deec .Bounds ();_bffg ,_afdb :=NewImage (_ead .Max .X ,_ead .Max .Y ,16,1,nil ,nil ,nil );if _afdb !=nil {return nil ,_afdb ;};_cgb (_deec ,_bffg ,_ead );return _bffg ,nil ;};var _ NRGBA =&NRGBA16 {};func (_cgce *NRGBA32 )ColorModel ()_ac .Model {return _ac .NRGBAModel };func _fbe (_bdg ,_fef CMYK ,_gf _fe .Rectangle ){for _ffb :=0;_ffb < _gf .Max .X ;_ffb ++{for _bca :=0;_bca < _gf .Max .Y ;_bca ++{_fef .SetCMYK (_ffb ,_bca ,_bdg .CMYKAt (_ffb ,_bca ));};};};type SMasker interface{HasAlpha ()bool ;GetAlpha ()[]byte ;MakeAlpha ();};type colorConverter struct{_cfa func (_ea _fe .Image )(Image ,error );};func (_dgg monochromeModel )Convert (c _ac .Color )_ac .Color {_ged :=_ac .GrayModel .Convert (c ).(_ac .Gray );return _eeg (_ged ,_dgg );};var _ NRGBA =&NRGBA32 {};func (_afe *Gray8 )Base ()*ImageBase {return &_afe .ImageBase };func (_fga *NRGBA32 )Copy ()Image {return &NRGBA32 {ImageBase :_fga .copy ()}};func (_adg *Monochrome )Validate ()error {if len (_adg .Data )!=_adg .Height *_adg .BytesPerLine {return ErrInvalidImage ;};return nil ;};func (_bebf *NRGBA16 )Base ()*ImageBase {return &_bebf .ImageBase };func _decb (_abb RGBA ,_ffge Gray ,_cac _fe .Rectangle ){for _bacg :=0;_bacg < _cac .Max .X ;_bacg ++{for _egc :=0;_egc < _cac .Max .Y ;_egc ++{_gad :=_ab (_abb .RGBAAt (_bacg ,_egc ));_ffge .SetGray (_bacg ,_egc ,_gad );};};};func _fege (_aege nrgba64 ,_fdgc NRGBA ,_fcd _fe .Rectangle ){for _bgbgd :=0;_bgbgd < _fcd .Max .X ;_bgbgd ++{for _acfd :=0;_acfd < _fcd .Max .Y ;_acfd ++{_dfef :=_aege .NRGBA64At (_bgbgd ,_acfd );_fdgc .SetNRGBA (_bgbgd ,_acfd ,_gbf (_dfef ));};};};func (_gce *Monochrome )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_gce .Width ,Y :_gce .Height }};};var _fabb [256]uint8 ;func (_afcf *Gray16 )Histogram ()(_gbe [256]int ){for _abfg :=0;_abfg < _afcf .Width ;_abfg ++{for _acg :=0;_acg < _afcf .Height ;_acg ++{_gbe [_afcf .GrayAt (_abfg ,_acg ).Y ]++;};};return _gbe ;};func ColorAtNRGBA (x ,y ,width ,bytesPerLine ,bitsPerColor int ,data ,alpha []byte ,decode []float64 )(_ac .Color ,error ){switch bitsPerColor {case 4:return ColorAtNRGBA16 (x ,y ,width ,bytesPerLine ,data ,alpha ,decode );case 8:return ColorAtNRGBA32 (x ,y ,width ,data ,alpha ,decode );case 16:return ColorAtNRGBA64 (x ,y ,width ,data ,alpha ,decode );default:return nil ,_b .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006fr\u0074\u0065\u0064 \u0072\u0067\u0062\u0020b\u0069\u0074\u0073\u0020\u0070\u0065\u0072\u0020\u0063\u006f\u006c\u006f\u0072\u0020\u0061\u006d\u006f\u0075\u006e\u0074\u003a\u0020\u0027\u0025\u0064\u0027",bitsPerColor );};};func _dae (_bge _fe .Image )(Image ,error ){if _efac ,_ebc :=_bge .(*Gray2 );_ebc {return _efac .Copy (),nil ;};_dbfe :=_bge .Bounds ();_gfb ,_bfd :=NewImage (_dbfe .Max .X ,_dbfe .Max .Y ,2,1,nil ,nil ,nil );if _bfd !=nil {return nil ,_bfd ;};_cgb (_bge ,_gfb ,_dbfe );return _gfb ,nil ;};func (_feb *Gray4 )Validate ()error {if len (_feb .Data )!=_feb .Height *_feb .BytesPerLine {return ErrInvalidImage ;};return nil ;};func (_ecfg *NRGBA64 )ColorAt (x ,y int )(_ac .Color ,error ){return ColorAtNRGBA64 (x ,y ,_ecfg .Width ,_ecfg .Data ,_ecfg .Alpha ,_ecfg .Decode );};type Monochrome struct{ImageBase ;ModelThreshold uint8 ;};func _gdbb (_ccac _ac .Color )_ac .Color {_eedg :=_ac .NRGBAModel .Convert (_ccac ).(_ac .NRGBA );return _aeef (_eedg );};func _ffg (_cef _ac .NYCbCrA )_ac .NRGBA {_bccd :=int32 (_cef .Y )*0x10101;_dece :=int32 (_cef .Cb )-128;_faba :=int32 (_cef .Cr )-128;_gbcb :=_bccd +91881*_faba ;if uint32 (_gbcb )&0xff000000==0{_gbcb >>=8;}else {_gbcb =^(_gbcb >>31)&0xffff;};_gg :=_bccd -22554*_dece -46802*_faba ;if uint32 (_gg )&0xff000000==0{_gg >>=8;}else {_gg =^(_gg >>31)&0xffff;};_agd :=_bccd +116130*_dece ;if uint32 (_agd )&0xff000000==0{_agd >>=8;}else {_agd =^(_agd >>31)&0xffff;};return _ac .NRGBA {R :uint8 (_gbcb >>8),G :uint8 (_gg >>8),B :uint8 (_agd >>8),A :_cef .A };};func (_afdc *ImageBase )HasAlpha ()bool {if _afdc .Alpha ==nil {return false ;};for _ceg :=range _afdc .Alpha {if _afdc .Alpha [_ceg ]!=0xff{return true ;};};return false ;};func (_egdf *NRGBA64 )At (x ,y int )_ac .Color {_gcac ,_ :=_egdf .ColorAt (x ,y );return _gcac };func _aaf (_gcd _ac .NRGBA )_ac .CMYK {_eg ,_bg ,_efc ,_ :=_gcd .RGBA ();_fde ,_ceb ,_afa ,_ede :=_ac .RGBToCMYK (uint8 (_eg >>8),uint8 (_bg >>8),uint8 (_efc >>8));return _ac .CMYK {C :_fde ,M :_ceb ,Y :_afa ,K :_ede };};func (_fbag *Gray8 )Histogram ()(_fge [256]int ){for _bff :=0;_bff < len (_fbag .Data );_bff ++{_fge [_fbag .Data [_bff ]]++;};return _fge ;};func NewImageBase (width int ,height int ,bitsPerComponent int ,colorComponents int ,data []byte ,alpha []byte ,decode []float64 )ImageBase {_fbca :=ImageBase {Width :width ,Height :height ,BitsPerComponent :bitsPerComponent ,ColorComponents :colorComponents ,Data :data ,Alpha :alpha ,Decode :decode ,BytesPerLine :BytesPerLine (width ,bitsPerComponent ,colorComponents )};if data ==nil {_fbca .Data =make ([]byte ,height *_fbca .BytesPerLine );};return _fbca ;};func (_aadg *NRGBA32 )NRGBAAt (x ,y int )_ac .NRGBA {_baf ,_ :=ColorAtNRGBA32 (x ,y ,_aadg .Width ,_aadg .Data ,_aadg .Alpha ,_aadg .Decode );return _baf ;};func (_cbbf *NRGBA32 )At (x ,y int )_ac .Color {_bddac ,_ :=_cbbf .ColorAt (x ,y );return _bddac };func (_effg *NRGBA16 )At (x ,y int )_ac .Color {_caea ,_ :=_effg .ColorAt (x ,y );return _caea };func (_dggd *Monochrome )SetGray (x ,y int ,g _ac .Gray ){_aegf :=y *_dggd .BytesPerLine +x >>3;if _aegf > len (_dggd .Data )-1{return ;};g =_eeg (g ,monochromeModel (_dggd .ModelThreshold ));_dggd .setGray (x ,g ,_aegf );};func (_bcdd *Gray16 )At (x ,y int )_ac .Color {_cee ,_ :=_bcdd .ColorAt (x ,y );return _cee };func _dgc (_gbc _ac .NRGBA )_ac .Gray {_ee ,_bb ,_cbg ,_ :=_gbc .RGBA ();_dfa :=(19595*_ee +38470*_bb +7471*_cbg +1<<15)>>24;return _ac .Gray {Y :uint8 (_dfa )};};func (_bced *Gray8 )Validate ()error {if len (_bced .Data )!=_bced .Height *_bced .BytesPerLine {return ErrInvalidImage ;};return nil ;};func ColorAtGray2BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_ac .Gray ,error ){_fffc :=y *bytesPerLine +x >>2;if _fffc >=len (data ){return _ac .Gray {},_b .Errorf ("\u0069\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006f\u0072\u0064\u0069\u006ea\u0074\u0065\u0073\u0020\u006f\u0075t\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065\u0020\u0028\u0025\u0064,\u0020\u0025\u0064\u0029",x ,y );};_gec :=data [_fffc ]>>uint (6-(x &3)*2)&3;if len (decode )==2{_gec =uint8 (uint32 (LinearInterpolate (float64 (_gec ),0,3.0,decode [0],decode [1]))&3);};return _ac .Gray {Y :_gec *85},nil ;};type NRGBA64 struct{ImageBase };func (_deab *Gray2 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_deab .Width ,Y :_deab .Height }};};func (_cgc *CMYK32 )At (x ,y int )_ac .Color {_ba ,_ :=_cgc .ColorAt (x ,y );return _ba };var _ Image =&Gray4 {};func (_dgd *NRGBA64 )SetNRGBA64 (x ,y int ,c _ac .NRGBA64 ){_cbgcf :=(y *_dgd .Width +x )*2;_bbb :=_cbgcf *3;if _bbb +5>=len (_dgd .Data ){return ;};_dgd .setNRGBA64 (_bbb ,c ,_cbgcf );};func (_bdgc *NRGBA64 )Set (x ,y int ,c _ac .Color ){_fgfa :=(y *_bdgc .Width +x )*2;_gdbe :=_fgfa *3;if _gdbe +5>=len (_bdgc .Data ){return ;};_gea :=_ac .NRGBA64Model .Convert (c ).(_ac .NRGBA64 );_bdgc .setNRGBA64 (_gdbe ,_gea ,_fgfa );};func (_egd *Gray2 )Validate ()error {if len (_egd .Data )!=_egd .Height *_egd .BytesPerLine {return ErrInvalidImage ;};return nil ;};func (_bdd *Monochrome )ColorModel ()_ac .Model {return MonochromeModel (_bdd .ModelThreshold )};func (_ae *CMYK32 )CMYKAt (x ,y int )_ac .CMYK {_ed ,_ :=ColorAtCMYK (x ,y ,_ae .Width ,_ae .Data ,_ae .Decode );return _ed ;};func _db (_fda _ac .CMYK )_ac .NRGBA {_bf ,_cec ,_aeg :=_ac .CMYKToRGB (_fda .C ,_fda .M ,_fda .Y ,_fda .K );return _ac .NRGBA {R :_bf ,G :_cec ,B :_aeg ,A :0xff};};type monochromeThresholdConverter struct{Threshold uint8 ;};func _gedc (_bde RGBA ,_ggeg NRGBA ,_gbb _fe .Rectangle ){for _bbgb :=0;_bbgb < _gbb .Max .X ;_bbgb ++{for _bebd :=0;_bebd < _gbb .Max .Y ;_bebd ++{_dfeb :=_bde .RGBAAt (_bbgb ,_bebd );_ggeg .SetNRGBA (_bbgb ,_bebd ,_aab (_dfeb ));};};};func _bgf (_ecc _ac .Gray )_ac .CMYK {return _ac .CMYK {K :0xff-_ecc .Y }};func (_fbgg *NRGBA32 )Validate ()error {if len (_fbgg .Data )!=3*_fbgg .Width *_fbgg .Height {return _ag .New ("i\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0069\u006da\u0067\u0065\u0020\u0064\u0061\u0074\u0061 s\u0069\u007a\u0065\u0020f\u006f\u0072\u0020\u0070\u0072\u006f\u0076\u0069\u0064ed\u0020\u0064i\u006d\u0065\u006e\u0073\u0069\u006f\u006e\u0073");};return nil ;};var (Gray2Model =_ac .ModelFunc (_eaf );Gray4Model =_ac .ModelFunc (_ebcb );NRGBA16Model =_ac .ModelFunc (_gdbb ););func (_gdbf *NRGBA16 )Validate ()error {if len (_gdbf .Data )!=3*_gdbf .Width *_gdbf .Height /2{return _ag .New ("i\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0069\u006da\u0067\u0065\u0020\u0064\u0061\u0074\u0061 s\u0069\u007a\u0065\u0020f\u006f\u0072\u0020\u0070\u0072\u006f\u0076\u0069\u0064ed\u0020\u0064i\u006d\u0065\u006e\u0073\u0069\u006f\u006e\u0073");};return nil ;};func (_ecea *Gray2 )SetGray (x ,y int ,gray _ac .Gray ){_ebf :=_cdd (gray );_dfb :=y *_ecea .BytesPerLine ;_bab :=_dfb +(x >>2);if _bab >=len (_ecea .Data ){return ;};_cff :=_ebf .Y >>6;_ecea .Data [_bab ]=(_ecea .Data [_bab ]&(^(0xc0>>uint (2*((x )&3)))))|(_cff <<uint (6-2*(x &3)));};func (_cdf *Gray16 )ColorAt (x ,y int )(_ac .Color ,error ){return ColorAtGray16BPC (x ,y ,_cdf .BytesPerLine ,_cdf .Data ,_cdf .Decode );};func (_efff *Gray8 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_efff .Width ,Y :_efff .Height }};};func _gaec (_gdf _fe .Image ,_daed uint8 )*_fe .Gray {_bedf :=_gdf .Bounds ();_aba :=_fe .NewGray (_bedf );var (_gfge _ac .Color ;_eagd _ac .Gray ;);for _fae :=0;_fae < _bedf .Max .X ;_fae ++{for _cdca :=0;_cdca < _bedf .Max .Y ;_cdca ++{_gfge =_gdf .At (_fae ,_cdca );_aba .Set (_fae ,_cdca ,_gfge );_eagd =_aba .GrayAt (_fae ,_cdca );_aba .SetGray (_fae ,_cdca ,_ac .Gray {Y :_aaba (_eagd .Y ,_daed )});};};return _aba ;};func (_cgfa *NRGBA16 )Set (x ,y int ,c _ac .Color ){_fgbd :=y *_cgfa .BytesPerLine +x *3/2;if _fgbd +1>=len (_cgfa .Data ){return ;};_gfff :=NRGBA16Model .Convert (c ).(_ac .NRGBA );_cgfa .setNRGBA (x ,y ,_fgbd ,_gfff );};var _ Image =&CMYK32 {};func _ec (_aee RGBA ,_ece CMYK ,_bcb _fe .Rectangle ){for _ace :=0;_ace < _bcb .Max .X ;_ace ++{for _caf :=0;_caf < _bcb .Max .Y ;_caf ++{_ge :=_aee .RGBAAt (_ace ,_caf );_ece .SetCMYK (_ace ,_caf ,_aac (_ge ));};};};func (_ggbd *ImageBase )newAlpha (){_bcge :=BytesPerLine (_ggbd .Width ,_ggbd .BitsPerComponent ,1);_ggbd .Alpha =make ([]byte ,_ggbd .Height *_bcge );};func (_fgdg *Gray16 )Set (x ,y int ,c _ac .Color ){_efb :=(y *_fgdg .BytesPerLine /2+x )*2;if _efb +1>=len (_fgdg .Data ){return ;};_cdcf :=_ac .Gray16Model .Convert (c ).(_ac .Gray16 );_fgdg .Data [_efb ],_fgdg .Data [_efb +1]=uint8 (_cdcf .Y >>8),uint8 (_cdcf .Y &0xff);};func AddDataPadding (width ,height ,bitsPerComponent ,colorComponents int ,data []byte )([]byte ,error ){_aaad :=BytesPerLine (width ,bitsPerComponent ,colorComponents );if _aaad ==width *colorComponents *bitsPerComponent /8{return data ,nil ;};_efaf :=width *colorComponents *bitsPerComponent ;_egeb :=_aaad *8;_gade :=8-(_egeb -_efaf );_aed :=_d .NewReader (data );_ffca :=_aaad -1;_cad :=make ([]byte ,_ffca );_fgb :=make ([]byte ,height *_aaad );_agdf :=_d .NewWriterMSB (_fgb );var _edb uint64 ;var _bfae error ;for _gcdb :=0;_gcdb < height ;_gcdb ++{_ ,_bfae =_aed .Read (_cad );if _bfae !=nil {return nil ,_bfae ;};_ ,_bfae =_agdf .Write (_cad );if _bfae !=nil {return nil ,_bfae ;};_edb ,_bfae =_aed .ReadBits (byte (_gade ));if _bfae !=nil {return nil ,_bfae ;};_ ,_bfae =_agdf .WriteBits (_edb ,_gade );if _bfae !=nil {return nil ,_bfae ;};_agdf .FinishByte ();};return _fgb ,nil ;};type NRGBA interface{NRGBAAt (_eba ,_gdb int )_ac .NRGBA ;SetNRGBA (_ecf ,_fce int ,_fgca _ac .NRGBA );};func (_bd *CMYK32 )Copy ()Image {return &CMYK32 {ImageBase :_bd .copy ()}};func (_dbg *NRGBA16 )SetNRGBA (x ,y int ,c _ac .NRGBA ){_fbaf :=y *_dbg .BytesPerLine +x *3/2;if _fbaf +1>=len (_dbg .Data ){return ;};c =_aeef (c );_dbg .setNRGBA (x ,y ,_fbaf ,c );};var _ Gray =&Gray8 {};func _ebcb (_fagf _ac .Color )_ac .Color {_gefa :=_ac .GrayModel .Convert (_fagf ).(_ac .Gray );return _cabc (_gefa );};func _dca (_acae _fe .Image )(Image ,error ){if _afg ,_bdbb :=_acae .(*NRGBA32 );_bdbb {return _afg .Copy (),nil ;};_deg ,_cede ,_dbea :=_edaf (_acae ,1);_bggg ,_gddef :=NewImage (_deg .Max .X ,_deg .Max .Y ,8,3,nil ,_dbea ,nil );if _gddef !=nil {return nil ,_gddef ;};_bcf (_acae ,_bggg ,_deg );if len (_dbea )!=0&&!_cede {if _cefc :=_gffe (_dbea ,_bggg );_cefc !=nil {return nil ,_cefc ;};};return _bggg ,nil ;};type RGBA interface{RGBAAt (_ced ,_bdaf int )_ac .RGBA ;SetRGBA (_eace ,_gefaf int ,_faab _ac .RGBA );};func _ad (_fbg Gray ,_bcce CMYK ,_be _fe .Rectangle ){for _edg :=0;_edg < _be .Max .X ;_edg ++{for _cfg :=0;_cfg < _be .Max .Y ;_cfg ++{_gc :=_fbg .GrayAt (_edg ,_cfg );_bcce .SetCMYK (_edg ,_cfg ,_bgf (_gc ));};};};func (_cce *Gray2 )Histogram ()(_eda [256]int ){for _edeb :=0;_edeb < _cce .Width ;_edeb ++{for _addd :=0;_addd < _cce .Height ;_addd ++{_eda [_cce .GrayAt (_edeb ,_addd ).Y ]++;};};return _eda ;};func _dbff (_gffg _fe .Image ,_bbdc Image ,_bbcf _fe .Rectangle ){if _bagc ,_bgbg :=_gffg .(SMasker );_bgbg &&_bagc .HasAlpha (){_bbdc .(SMasker ).MakeAlpha ();};_bef (_gffg ,_bbdc ,_bbcf );};func _bcf (_afaf _fe .Image ,_baa Image ,_dcbe _fe .Rectangle ){if _fdfg ,_fgde :=_afaf .(SMasker );_fgde &&_fdfg .HasAlpha (){_baa .(SMasker ).MakeAlpha ();};switch _cebd :=_afaf .(type ){case Gray :_gag (_cebd ,_baa .(NRGBA ),_dcbe );case NRGBA :_afdd (_cebd ,_baa .(NRGBA ),_dcbe );case *_fe .NYCbCrA :_fad (_cebd ,_baa .(NRGBA ),_dcbe );case CMYK :_dged (_cebd ,_baa .(NRGBA ),_dcbe );case RGBA :_gedc (_cebd ,_baa .(NRGBA ),_dcbe );case nrgba64 :_fege (_cebd ,_baa .(NRGBA ),_dcbe );default:_bef (_afaf ,_baa ,_dcbe );};};var _ Image =&NRGBA64 {};func _gffe (_dgge []byte ,_dce Image )error {_aaga :=true ;for _cecg :=0;_cecg < len (_dgge );_cecg ++{if _dgge [_cecg ]!=0xff{_aaga =false ;break ;};};if _aaga {switch _gbfg :=_dce .(type ){case *NRGBA32 :_gbfg .Alpha =nil ;case *NRGBA64 :_gbfg .Alpha =nil ;default:return _b .Errorf ("i\u006ete\u0072n\u0061l\u0020\u0065\u0072\u0072\u006fr\u0020\u002d\u0020i\u006d\u0061\u0067\u0065\u0020s\u0068\u006f\u0075l\u0064\u0020\u0062\u0065\u0020\u006f\u0066\u0020\u0074\u0079\u0070e\u0020\u002a\u004eRGB\u0041\u0033\u0032\u0020\u006f\u0072 \u002a\u004e\u0052\u0047\u0042\u0041\u0036\u0034\u0020\u0062\u0075\u0074 \u0069s\u003a\u0020\u0025\u0054",_dce );};};return nil ;};func _gag (_agb Gray ,_dffc NRGBA ,_fcga _fe .Rectangle ){for _fcec :=0;_fcec < _fcga .Max .X ;_fcec ++{for _defd :=0;_defd < _fcga .Max .Y ;_defd ++{_cadc :=_agb .GrayAt (_fcec ,_defd );_dffc .SetNRGBA (_fcec ,_defd ,_dge (_cadc ));};};};func (_eag *Gray2 )Copy ()Image {return &Gray2 {ImageBase :_eag .copy ()}};func ColorAtCMYK (x ,y ,width int ,data []byte ,decode []float64 )(_ac .CMYK ,error ){_fb :=4*(y *width +x );if _fb +3>=len (data ){return _ac .CMYK {},_b .Errorf ("\u0069\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006f\u0072\u0064\u0069\u006ea\u0074\u0065\u0073\u0020\u006f\u0075t\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065\u0020\u0028\u0025\u0064,\u0020\u0025\u0064\u0029",x ,y );};C :=data [_fb ]&0xff;M :=data [_fb +1]&0xff;Y :=data [_fb +2]&0xff;K :=data [_fb +3]&0xff;if len (decode )==8{C =uint8 (uint32 (LinearInterpolate (float64 (C ),0,255,decode [0],decode [1]))&0xff);M =uint8 (uint32 (LinearInterpolate (float64 (M ),0,255,decode [2],decode [3]))&0xff);Y =uint8 (uint32 (LinearInterpolate (float64 (Y ),0,255,decode [4],decode [5]))&0xff);K =uint8 (uint32 (LinearInterpolate (float64 (K ),0,255,decode [6],decode [7]))&0xff);};return _ac .CMYK {C :C ,M :M ,Y :Y ,K :K },nil ;};func (_dab *NRGBA16 )NRGBAAt (x ,y int )_ac .NRGBA {_bed ,_ :=ColorAtNRGBA16 (x ,y ,_dab .Width ,_dab .BytesPerLine ,_dab .Data ,_dab .Alpha ,_dab .Decode );return _bed ;};func (_bcbg *NRGBA64 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_bcbg .Width ,Y :_bcbg .Height }};};func (_aeb *NRGBA32 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_aeb .Width ,Y :_aeb .Height }};};func _bef (_fff _fe .Image ,_de Image ,_gdg _fe .Rectangle ){for _gdd :=0;_gdd < _gdg .Max .X ;_gdd ++{for _ffbd :=0;_ffbd < _gdg .Max .Y ;_ffbd ++{_fcc :=_fff .At (_gdd ,_ffbd );_de .Set (_gdd ,_ffbd ,_fcc );};};};func (_gb colorConverter )Convert (src _fe .Image )(Image ,error ){return _gb ._cfa (src )};func _aac (_gfa _ac .RGBA )_ac .CMYK {_eeb ,_bce ,_fdab ,_gccd :=_ac .RGBToCMYK (_gfa .R ,_gfa .G ,_gfa .B );return _ac .CMYK {C :_eeb ,M :_bce ,Y :_fdab ,K :_gccd };};func _ef (_cd NRGBA ,_fbb CMYK ,_da _fe .Rectangle ){for _cgcf :=0;_cgcf < _da .Max .X ;_cgcf ++{for _aa :=0;_aa < _da .Max .Y ;_aa ++{_ce :=_cd .NRGBAAt (_cgcf ,_aa );_fbb .SetCMYK (_cgcf ,_aa ,_aaf (_ce ));};};};var _ _fe .Image =&Gray8 {};func LinearInterpolate (x ,xmin ,xmax ,ymin ,ymax float64 )float64 {if _e .Abs (xmax -xmin )< 0.000001{return ymin ;};_fecf :=ymin +(x -xmin )*(ymax -ymin )/(xmax -xmin );return _fecf ;};func (_cbd *Gray16 )Base ()*ImageBase {return &_cbd .ImageBase };var _ Image =&Gray2 {};func (_cgf *Gray16 )GrayAt (x ,y int )_ac .Gray {_aacfe ,_ :=_cgf .ColorAt (x ,y );return _ac .Gray {Y :uint8 (_aacfe .(_ac .Gray16 ).Y >>8)};};func ImgToBinary (i _fe .Image ,threshold uint8 )*_fe .Gray {switch _gbfge :=i .(type ){case *_fe .Gray :if _dacd (_gbfge ){return _gbfge ;};return _deeb (_gbfge ,threshold );case *_fe .Gray16 :return _bfef (_gbfge ,threshold );default:return _gaec (_gbfge ,threshold );};};func _edaf (_cadd _fe .Image ,_egca int )(_fe .Rectangle ,bool ,[]byte ){_feff :=_cadd .Bounds ();var (_ebcf bool ;_gcea []byte ;);switch _ffbc :=_cadd .(type ){case SMasker :_ebcf =_ffbc .HasAlpha ();case NRGBA ,RGBA ,*_fe .RGBA64 ,nrgba64 ,*_fe .NYCbCrA :_gcea =make ([]byte ,_feff .Max .X *_feff .Max .Y *_egca );};return _feff ,_ebcf ,_gcea ;};func MonochromeModel (threshold uint8 )_ac .Model {return monochromeModel (threshold )};func MonochromeThresholdConverter (threshold uint8 )ColorConverter {return &monochromeThresholdConverter {Threshold :threshold };};func BytesPerLine (width ,bitsPerComponent ,colorComponents int )int {return ((width *bitsPerComponent )*colorComponents +7)>>3;};func (_g *CMYK32 )Validate ()error {if len (_g .Data )!=4*_g .Width *_g .Height {return _ag .New ("i\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0069\u006da\u0067\u0065\u0020\u0064\u0061\u0074\u0061 s\u0069\u007a\u0065\u0020f\u006f\u0072\u0020\u0070\u0072\u006f\u0076\u0069\u0064ed\u0020\u0064i\u006d\u0065\u006e\u0073\u0069\u006f\u006e\u0073");};return nil ;};func (_dcd *Gray4 )Set (x ,y int ,c _ac .Color ){if x >=_dcd .Width ||y >=_dcd .Height {return ;};_dgeb :=Gray4Model .Convert (c ).(_ac .Gray );_dcd .setGray (x ,y ,_dgeb );};type Histogramer interface{Histogram ()[256]int ;};func (_ggf *Gray2 )GrayAt (x ,y int )_ac .Gray {_ebgg ,_ :=ColorAtGray2BPC (x ,y ,_ggf .BytesPerLine ,_ggf .Data ,_ggf .Decode );return _ebgg ;}; |