mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-30 13:48:51 +08:00
401 lines
115 KiB
Go
401 lines
115 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 (_b "encoding/binary";_e "errors";_d "fmt";_ba "github.com/unidoc/unipdf/v3/common";_fg "github.com/unidoc/unipdf/v3/internal/bitwise";_fe "image";_fc "image/color";_ee "image/draw";_ea "math";);type Monochrome struct{ImageBase ;
|
|
ModelThreshold uint8 ;};type monochromeModel uint8 ;func _faee (_aegf RGBA ,_cgfg CMYK ,_bbgc _fe .Rectangle ){for _bbfb :=0;_bbfb < _bbgc .Max .X ;_bbfb ++{for _cgac :=0;_cgac < _bbgc .Max .Y ;_cgac ++{_cba :=_aegf .RGBAAt (_bbfb ,_cgac );_cgfg .SetCMYK (_bbfb ,_cgac ,_afacb (_cba ));
|
|
};};};func (_dcdag *NRGBA16 )setNRGBA (_fbbf ,_bfcd ,_gfbe int ,_cada _fc .NRGBA ){if _fbbf *3%2==0{_dcdag .Data [_gfbe ]=(_cada .R >>4)<<4|(_cada .G >>4);_dcdag .Data [_gfbe +1]=(_cada .B >>4)<<4|(_dcdag .Data [_gfbe +1]&0xf);}else {_dcdag .Data [_gfbe ]=(_dcdag .Data [_gfbe ]&0xf0)|(_cada .R >>4);
|
|
_dcdag .Data [_gfbe +1]=(_cada .G >>4)<<4|(_cada .B >>4);};if _dcdag .Alpha !=nil {_fefa :=_bfcd *BytesPerLine (_dcdag .Width ,4,1);if _fefa < len (_dcdag .Alpha ){if _fbbf %2==0{_dcdag .Alpha [_fefa ]=(_cada .A >>uint (4))<<uint (4)|(_dcdag .Alpha [_gfbe ]&0xf);
|
|
}else {_dcdag .Alpha [_fefa ]=(_dcdag .Alpha [_fefa ]&0xf0)|(_cada .A >>uint (4));};};};};func _ffd (_aadf _fc .NYCbCrA )_fc .RGBA {_fgb ,_ceb ,_gbba ,_afgf :=_aead (_aadf ).RGBA ();return _fc .RGBA {R :uint8 (_fgb >>8),G :uint8 (_ceb >>8),B :uint8 (_gbba >>8),A :uint8 (_afgf >>8)};
|
|
};func (_gbbb *monochromeThresholdConverter )Convert (img _fe .Image )(Image ,error ){if _fdbf ,_fbd :=img .(*Monochrome );_fbd {return _fdbf .Copy (),nil ;};_bed :=img .Bounds ();_ecc ,_defb :=NewImage (_bed .Max .X ,_bed .Max .Y ,1,1,nil ,nil ,nil );
|
|
if _defb !=nil {return nil ,_defb ;};_ecc .(*Monochrome ).ModelThreshold =_gbbb .Threshold ;for _egbae :=0;_egbae < _bed .Max .X ;_egbae ++{for _baa :=0;_baa < _bed .Max .Y ;_baa ++{_eab :=img .At (_egbae ,_baa );_ecc .Set (_egbae ,_baa ,_eab );};};return _ecc ,nil ;
|
|
};func (_bgaf *Gray16 )Histogram ()(_faag [256]int ){for _bgee :=0;_bgee < _bgaf .Width ;_bgee ++{for _gffa :=0;_gffa < _bgaf .Height ;_gffa ++{_faag [_bgaf .GrayAt (_bgee ,_gffa ).Y ]++;};};return _faag ;};func (_badd *NRGBA64 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_badd .Width ,Y :_badd .Height }};
|
|
};func (_ecda *Gray16 )At (x ,y int )_fc .Color {_cfcb ,_ :=_ecda .ColorAt (x ,y );return _cfcb };func NextPowerOf2 (n uint )uint {if IsPowerOf2 (n ){return n ;};return 1<<(_aab (n )+1);};func (_edef *ImageBase )setByte (_ebba int ,_ccgf byte )error {if _ebba > len (_edef .Data )-1{return _e .New ("\u0069n\u0064e\u0078\u0020\u006f\u0075\u0074 \u006f\u0066 \u0072\u0061\u006e\u0067\u0065");
|
|
};_edef .Data [_ebba ]=_ccgf ;return nil ;};func _fead (_gcdf _fc .Gray )_fc .RGBA {return _fc .RGBA {R :_gcdf .Y ,G :_gcdf .Y ,B :_gcdf .Y ,A :0xff}};func (_dgabe *NRGBA32 )Validate ()error {if len (_dgabe .Data )!=3*_dgabe .Width *_dgabe .Height {return _e .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 =_fc .ModelFunc (_afab );Gray4Model =_fc .ModelFunc (_eedf );NRGBA16Model =_fc .ModelFunc (_cgea ););func _cabe (_beagd []byte ,_bcca Image )error {_abgf :=true ;for _aeab :=0;_aeab < len (_beagd );_aeab ++{if _beagd [_aeab ]!=0xff{_abgf =false ;
|
|
break ;};};if _abgf {switch _ffca :=_bcca .(type ){case *NRGBA32 :_ffca .Alpha =nil ;case *NRGBA64 :_ffca .Alpha =nil ;default:return _d .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",_bcca );
|
|
};};return nil ;};func (_eecdb *NRGBA32 )ColorAt (x ,y int )(_fc .Color ,error ){return ColorAtNRGBA32 (x ,y ,_eecdb .Width ,_eecdb .Data ,_eecdb .Alpha ,_eecdb .Decode );};func _dcbd (_ggcca ,_egdad Gray ,_gbea _fe .Rectangle ){for _abggf :=0;_abggf < _gbea .Max .X ;
|
|
_abggf ++{for _dabf :=0;_dabf < _gbea .Max .Y ;_dabf ++{_egdad .SetGray (_abggf ,_dabf ,_ggcca .GrayAt (_abggf ,_dabf ));};};};func _bgbf (_agdd int ,_bdad int )error {return _d .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",_agdd ,_bdad );
|
|
};var _ _fe .Image =&Monochrome {};func _afab (_gdbbe _fc .Color )_fc .Color {_ddcf :=_fc .GrayModel .Convert (_gdbbe ).(_fc .Gray );return _gbbe (_ddcf );};func ColorAtGray8BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_fc .Gray ,error ){_ecg :=y *bytesPerLine +x ;
|
|
if _ecg >=len (data ){return _fc .Gray {},_d .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 );
|
|
};_bgeb :=data [_ecg ];if len (decode )==2{_bgeb =uint8 (uint32 (LinearInterpolate (float64 (_bgeb ),0,255,decode [0],decode [1]))&0xff);};return _fc .Gray {Y :_bgeb },nil ;};func _bc (_bcf ,_bcc *Monochrome )(_fea error ){_ag :=_bcc .BytesPerLine ;_dbd :=_bcf .BytesPerLine ;
|
|
var _dcd ,_dd ,_ca ,_cde ,_cea int ;for _ca =0;_ca < _bcc .Height ;_ca ++{_dcd =_ca *_ag ;_dd =8*_ca *_dbd ;for _cde =0;_cde < _ag ;_cde ++{if _fea =_bcf .setEightBytes (_dd +_cde *8,_ege [_bcc .Data [_dcd +_cde ]]);_fea !=nil {return _fea ;};};for _cea =1;
|
|
_cea < 8;_cea ++{for _cde =0;_cde < _dbd ;_cde ++{if _fea =_bcf .setByte (_dd +_cea *_dbd +_cde ,_bcf .Data [_dd +_cde ]);_fea !=nil {return _fea ;};};};};return nil ;};func (_dfba *Monochrome )AddPadding ()(_daeg error ){if _fag :=((_dfba .Width *_dfba .Height )+7)>>3;
|
|
len (_dfba .Data )< _fag {return _d .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0064a\u0074\u0061\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u003a\u0020\u0027\u0025\u0064\u0027\u002e\u0020\u0054\u0068\u0065\u0020\u0064\u0061t\u0061\u0020s\u0068\u006fu\u006c\u0064\u0020\u0063\u006f\u006e\u0074\u0061\u0069\u006e\u0020\u0061\u0074 l\u0065\u0061\u0073\u0074\u003a\u0020\u0027\u0025\u0064'\u0020\u0062\u0079\u0074\u0065\u0073",len (_dfba .Data ),_fag );
|
|
};_gecf :=_dfba .Width %8;if _gecf ==0{return nil ;};_daegf :=_dfba .Width /8;_abff :=_fg .NewReader (_dfba .Data );_dffe :=make ([]byte ,_dfba .Height *_dfba .BytesPerLine );_ebe :=_fg .NewWriterMSB (_dffe );_dgad :=make ([]byte ,_daegf );var (_bfec int ;
|
|
_gbfa uint64 ;);for _bfec =0;_bfec < _dfba .Height ;_bfec ++{if _ ,_daeg =_abff .Read (_dgad );_daeg !=nil {return _daeg ;};if _ ,_daeg =_ebe .Write (_dgad );_daeg !=nil {return _daeg ;};if _gbfa ,_daeg =_abff .ReadBits (byte (_gecf ));_daeg !=nil {return _daeg ;
|
|
};if _daeg =_ebe .WriteByte (byte (_gbfa )<<uint (8-_gecf ));_daeg !=nil {return _daeg ;};};_dfba .Data =_ebe .Data ();return nil ;};func (_egda *Gray2 )GrayAt (x ,y int )_fc .Gray {_dddg ,_ :=ColorAtGray2BPC (x ,y ,_egda .BytesPerLine ,_egda .Data ,_egda .Decode );
|
|
return _dddg ;};func (_ebge *Gray2 )At (x ,y int )_fc .Color {_dcfe ,_ :=_ebge .ColorAt (x ,y );return _dcfe };func _cdcb (_cbbfa nrgba64 ,_gdee NRGBA ,_ccba _fe .Rectangle ){for _ccda :=0;_ccda < _ccba .Max .X ;_ccda ++{for _debc :=0;_debc < _ccba .Max .Y ;
|
|
_debc ++{_babgf :=_cbbfa .NRGBA64At (_ccda ,_debc );_gdee .SetNRGBA (_ccda ,_debc ,_efgb (_babgf ));};};};func (_aggg *Gray8 )ColorModel ()_fc .Model {return _fc .GrayModel };const (PixSrc RasterOperator =0xc;PixDst RasterOperator =0xa;PixNotSrc RasterOperator =0x3;
|
|
PixNotDst RasterOperator =0x5;PixClr RasterOperator =0x0;PixSet RasterOperator =0xf;PixSrcOrDst RasterOperator =0xe;PixSrcAndDst RasterOperator =0x8;PixSrcXorDst RasterOperator =0x6;PixNotSrcOrDst RasterOperator =0xb;PixNotSrcAndDst RasterOperator =0x2;
|
|
PixSrcOrNotDst RasterOperator =0xd;PixSrcAndNotDst RasterOperator =0x4;PixNotPixSrcOrDst RasterOperator =0x1;PixNotPixSrcAndDst RasterOperator =0x7;PixNotPixSrcXorDst RasterOperator =0x9;PixPaint =PixSrcOrDst ;PixSubtract =PixNotSrcAndDst ;PixMask =PixSrcAndDst ;
|
|
);func _cca (_eadg ,_fgf *Monochrome ,_fef []byte ,_gbcb int )(_eec error ){var (_fgea ,_bgb ,_degc ,_dag ,_bgbb ,_gef ,_dfgb ,_fd int ;_ffc ,_cbf ,_aeb ,_dgae uint32 ;_ada ,_ccd byte ;_acf uint16 ;);_cgb :=make ([]byte ,4);_aff :=make ([]byte ,4);for _degc =0;
|
|
_degc < _eadg .Height -1;_degc ,_dag =_degc +2,_dag +1{_fgea =_degc *_eadg .BytesPerLine ;_bgb =_dag *_fgf .BytesPerLine ;for _bgbb ,_gef =0,0;_bgbb < _gbcb ;_bgbb ,_gef =_bgbb +4,_gef +1{for _dfgb =0;_dfgb < 4;_dfgb ++{_fd =_fgea +_bgbb +_dfgb ;if _fd <=len (_eadg .Data )-1&&_fd < _fgea +_eadg .BytesPerLine {_cgb [_dfgb ]=_eadg .Data [_fd ];
|
|
}else {_cgb [_dfgb ]=0x00;};_fd =_fgea +_eadg .BytesPerLine +_bgbb +_dfgb ;if _fd <=len (_eadg .Data )-1&&_fd < _fgea +(2*_eadg .BytesPerLine ){_aff [_dfgb ]=_eadg .Data [_fd ];}else {_aff [_dfgb ]=0x00;};};_ffc =_b .BigEndian .Uint32 (_cgb );_cbf =_b .BigEndian .Uint32 (_aff );
|
|
_aeb =_ffc &_cbf ;_aeb |=_aeb <<1;_dgae =_ffc |_cbf ;_dgae &=_dgae <<1;_cbf =_aeb |_dgae ;_cbf &=0xaaaaaaaa;_ffc =_cbf |(_cbf <<7);_ada =byte (_ffc >>24);_ccd =byte ((_ffc >>8)&0xff);_fd =_bgb +_gef ;if _fd +1==len (_fgf .Data )-1||_fd +1>=_bgb +_fgf .BytesPerLine {if _eec =_fgf .setByte (_fd ,_fef [_ada ]);
|
|
_eec !=nil {return _d .Errorf ("\u0069n\u0064\u0065\u0078\u003a\u0020\u0025d",_fd );};}else {_acf =(uint16 (_fef [_ada ])<<8)|uint16 (_fef [_ccd ]);if _eec =_fgf .setTwoBytes (_fd ,_acf );_eec !=nil {return _d .Errorf ("s\u0065\u0074\u0074\u0069\u006e\u0067 \u0074\u0077\u006f\u0020\u0062\u0079t\u0065\u0073\u0020\u0066\u0061\u0069\u006ce\u0064\u002c\u0020\u0069\u006e\u0064\u0065\u0078\u003a\u0020%\u0064",_fd );
|
|
};_gef ++;};};};return nil ;};type RGBA interface{RGBAAt (_dede ,_bccef int )_fc .RGBA ;SetRGBA (_bece ,_bdf int ,_cfeg _fc .RGBA );};type NRGBA16 struct{ImageBase };func ScaleAlphaToMonochrome (data []byte ,width ,height int )([]byte ,error ){_g :=BytesPerLine (width ,8,1);
|
|
if len (data )< _g *height {return nil ,nil ;};_c :=&Gray8 {NewImageBase (width ,height ,8,1,data ,nil ,nil )};_bg ,_ed :=MonochromeConverter .Convert (_c );if _ed !=nil {return nil ,_ed ;};return _bg .Base ().Data ,nil ;};type CMYK32 struct{ImageBase };
|
|
func _fcde (_agec *Monochrome ,_agac ,_dgf ,_fabcf ,_abd int ,_cbbf RasterOperator ,_bgdb *Monochrome ,_affa ,_aegb int )error {if _agec ==nil {return _e .New ("\u006e\u0069\u006c\u0020\u0027\u0064\u0065\u0073\u0074\u0027\u0020\u0042i\u0074\u006d\u0061\u0070");
|
|
};if _cbbf ==PixDst {return nil ;};switch _cbbf {case PixClr ,PixSet ,PixNotDst :_gcgf (_agec ,_agac ,_dgf ,_fabcf ,_abd ,_cbbf );return nil ;};if _bgdb ==nil {_ba .Log .Debug ("\u0052a\u0073\u0074e\u0072\u004f\u0070\u0065r\u0061\u0074\u0069o\u006e\u0020\u0073\u006f\u0075\u0072\u0063\u0065\u0020bi\u0074\u006d\u0061p\u0020\u0069s\u0020\u006e\u006f\u0074\u0020\u0064e\u0066\u0069n\u0065\u0064");
|
|
return _e .New ("\u006e\u0069l\u0020\u0027\u0073r\u0063\u0027\u0020\u0062\u0069\u0074\u006d\u0061\u0070");};if _fecb :=_dbe (_agec ,_agac ,_dgf ,_fabcf ,_abd ,_cbbf ,_bgdb ,_affa ,_aegb );_fecb !=nil {return _fecb ;};return nil ;};func (_cabg *Monochrome )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_cabg .Width ,Y :_cabg .Height }};
|
|
};func (_gac *CMYK32 )ColorAt (x ,y int )(_fc .Color ,error ){return ColorAtCMYK (x ,y ,_gac .Width ,_gac .Data ,_gac .Decode );};var _ Image =&Gray2 {};func (_becc *Monochrome )Base ()*ImageBase {return &_becc .ImageBase };func _aacg (_gcgea *_fe .NYCbCrA ,_fgac RGBA ,_egdfg _fe .Rectangle ){for _bffcg :=0;
|
|
_bffcg < _egdfg .Max .X ;_bffcg ++{for _cbfea :=0;_cbfea < _egdfg .Max .Y ;_cbfea ++{_ceeed :=_gcgea .NYCbCrAAt (_bffcg ,_cbfea );_fgac .SetRGBA (_bffcg ,_cbfea ,_ffd (_ceeed ));};};};func ColorAt (x ,y ,width ,bitsPerColor ,colorComponents ,bytesPerLine int ,data ,alpha []byte ,decode []float64 )(_fc .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 ,_d .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 );
|
|
};};type NRGBA interface{NRGBAAt (_bcga ,_dea int )_fc .NRGBA ;SetNRGBA (_ebd ,_ddga int ,_dcdab _fc .NRGBA );};func (_ebec *Gray2 )Base ()*ImageBase {return &_ebec .ImageBase };func _gdg (_cgf ,_cfeb int )*Monochrome {return &Monochrome {ImageBase :NewImageBase (_cgf ,_cfeb ,1,1,nil ,nil ,nil ),ModelThreshold :0x0f};
|
|
};func _daca (_gdbbf CMYK ,_gabb RGBA ,_fgbb _fe .Rectangle ){for _gaad :=0;_gaad < _fgbb .Max .X ;_gaad ++{for _gffag :=0;_gffag < _fgbb .Max .Y ;_gffag ++{_fgbe :=_gdbbf .CMYKAt (_gaad ,_gffag );_gabb .SetRGBA (_gaad ,_gffag ,_edda (_fgbe ));};};};func _efgb (_efgg _fc .NRGBA64 )_fc .NRGBA {return _fc .NRGBA {R :uint8 (_efgg .R >>8),G :uint8 (_efgg .G >>8),B :uint8 (_efgg .B >>8),A :uint8 (_efgg .A >>8)};
|
|
};func _ebaa (_cecd ,_cbde ,_fgbd byte )byte {return (_cecd &^(_fgbd ))|(_cbde &_fgbd )};func (_ddcc *ImageBase )setTwoBytes (_debd int ,_dfgcd uint16 )error {if _debd +1> len (_ddcc .Data )-1{return _e .New ("\u0069n\u0064e\u0078\u0020\u006f\u0075\u0074 \u006f\u0066 \u0072\u0061\u006e\u0067\u0065");
|
|
};_ddcc .Data [_debd ]=byte ((_dfgcd &0xff00)>>8);_ddcc .Data [_debd +1]=byte (_dfgcd &0xff);return nil ;};func (_abfd *Gray2 )Copy ()Image {return &Gray2 {ImageBase :_abfd .copy ()}};func _ccde (_gab _fc .RGBA )_fc .NRGBA {switch _gab .A {case 0xff:return _fc .NRGBA {R :_gab .R ,G :_gab .G ,B :_gab .B ,A :0xff};
|
|
case 0x00:return _fc .NRGBA {};default:_bbdc ,_bdcd ,_cffe ,_dfbb :=_gab .RGBA ();_bbdc =(_bbdc *0xffff)/_dfbb ;_bdcd =(_bdcd *0xffff)/_dfbb ;_cffe =(_cffe *0xffff)/_dfbb ;return _fc .NRGBA {R :uint8 (_bbdc >>8),G :uint8 (_bdcd >>8),B :uint8 (_cffe >>8),A :uint8 (_dfbb >>8)};
|
|
};};func (_fgbc *Gray16 )SetGray (x ,y int ,g _fc .Gray ){_dgdcd :=(y *_fgbc .BytesPerLine /2+x )*2;if _dgdcd +1>=len (_fgbc .Data ){return ;};_fgbc .Data [_dgdcd ]=g .Y ;_fgbc .Data [_dgdcd +1]=g .Y ;};type RasterOperator int ;func _bfb (_eee ,_aeg *Monochrome ,_gc []byte ,_fcf int )(_dfga error ){var (_beb ,_ggd ,_dgdg ,_geg ,_cfec ,_bca ,_bbfc ,_bgg int ;
|
|
_bcaa ,_fdb uint32 ;_ccb ,_gdad byte ;_dgcb uint16 ;);_fbbd :=make ([]byte ,4);_cfa :=make ([]byte ,4);for _dgdg =0;_dgdg < _eee .Height -1;_dgdg ,_geg =_dgdg +2,_geg +1{_beb =_dgdg *_eee .BytesPerLine ;_ggd =_geg *_aeg .BytesPerLine ;for _cfec ,_bca =0,0;
|
|
_cfec < _fcf ;_cfec ,_bca =_cfec +4,_bca +1{for _bbfc =0;_bbfc < 4;_bbfc ++{_bgg =_beb +_cfec +_bbfc ;if _bgg <=len (_eee .Data )-1&&_bgg < _beb +_eee .BytesPerLine {_fbbd [_bbfc ]=_eee .Data [_bgg ];}else {_fbbd [_bbfc ]=0x00;};_bgg =_beb +_eee .BytesPerLine +_cfec +_bbfc ;
|
|
if _bgg <=len (_eee .Data )-1&&_bgg < _beb +(2*_eee .BytesPerLine ){_cfa [_bbfc ]=_eee .Data [_bgg ];}else {_cfa [_bbfc ]=0x00;};};_bcaa =_b .BigEndian .Uint32 (_fbbd );_fdb =_b .BigEndian .Uint32 (_cfa );_fdb &=_bcaa ;_fdb &=_fdb <<1;_fdb &=0xaaaaaaaa;
|
|
_bcaa =_fdb |(_fdb <<7);_ccb =byte (_bcaa >>24);_gdad =byte ((_bcaa >>8)&0xff);_bgg =_ggd +_bca ;if _bgg +1==len (_aeg .Data )-1||_bgg +1>=_ggd +_aeg .BytesPerLine {_aeg .Data [_bgg ]=_gc [_ccb ];if _dfga =_aeg .setByte (_bgg ,_gc [_ccb ]);_dfga !=nil {return _d .Errorf ("\u0069n\u0064\u0065\u0078\u003a\u0020\u0025d",_bgg );
|
|
};}else {_dgcb =(uint16 (_gc [_ccb ])<<8)|uint16 (_gc [_gdad ]);if _dfga =_aeg .setTwoBytes (_bgg ,_dgcb );_dfga !=nil {return _d .Errorf ("s\u0065\u0074\u0074\u0069\u006e\u0067 \u0074\u0077\u006f\u0020\u0062\u0079t\u0065\u0073\u0020\u0066\u0061\u0069\u006ce\u0064\u002c\u0020\u0069\u006e\u0064\u0065\u0078\u003a\u0020%\u0064",_bgg );
|
|
};_bca ++;};};};return nil ;};func _gdce (_dfe _fe .Image ,_def Image ,_acbg _fe .Rectangle ){for _adf :=0;_adf < _acbg .Max .X ;_adf ++{for _gec :=0;_gec < _acbg .Max .Y ;_gec ++{_efa :=_dfe .At (_adf ,_gec );_def .Set (_adf ,_gec ,_efa );};};};type Image interface{_ee .Image ;
|
|
Base ()*ImageBase ;Copy ()Image ;Pix ()[]byte ;ColorAt (_dcda ,_agfg int )(_fc .Color ,error );Validate ()error ;};func _fcb (_bbc _fc .CMYK )_fc .Gray {_cbba ,_ggb ,_bag :=_fc .CMYKToRGB (_bbc .C ,_bbc .M ,_bbc .Y ,_bbc .K );_bgdg :=(19595*uint32 (_cbba )+38470*uint32 (_ggb )+7471*uint32 (_bag )+1<<7)>>16;
|
|
return _fc .Gray {Y :uint8 (_bgdg )};};var _ Gray =&Monochrome {};func _fdbg (_dgdf _fe .Image )(Image ,error ){if _ffa ,_aece :=_dgdf .(*CMYK32 );_aece {return _ffa .Copy (),nil ;};_dcg :=_dgdf .Bounds ();_ddb ,_bbgd :=NewImage (_dcg .Max .X ,_dcg .Max .Y ,8,4,nil ,nil ,nil );
|
|
if _bbgd !=nil {return nil ,_bbgd ;};switch _ddd :=_dgdf .(type ){case CMYK :_cgff (_ddd ,_ddb .(CMYK ),_dcg );case Gray :_bgbe (_ddd ,_ddb .(CMYK ),_dcg );case NRGBA :_degce (_ddd ,_ddb .(CMYK ),_dcg );case RGBA :_faee (_ddd ,_ddb .(CMYK ),_dcg );default:_gdce (_dgdf ,_ddb ,_dcg );
|
|
};return _ddb ,nil ;};func _defd (_dcgg int ,_fgbge int )int {if _dcgg < _fgbge {return _dcgg ;};return _fgbge ;};func (_fcca *Monochrome )setGray (_gfd int ,_edg _fc .Gray ,_badfb int ){if _edg .Y ==0{_fcca .clearBit (_badfb ,_gfd );}else {_fcca .setGrayBit (_badfb ,_gfd );
|
|
};};func (_adfg *Monochrome )At (x ,y int )_fc .Color {_fgff ,_ :=_adfg .ColorAt (x ,y );return _fgff };func _cdaa (_gdac ,_bgbc *Monochrome ,_abe []byte ,_eed int )(_agd error ){var (_dbac ,_fabb ,_ede ,_bec ,_eca ,_cge ,_fdg ,_egd int ;_ageb ,_acb ,_cbda ,_dce uint32 ;
|
|
_efbc ,_agdf byte ;_edd uint16 ;);_fgef :=make ([]byte ,4);_fefb :=make ([]byte ,4);for _ede =0;_ede < _gdac .Height -1;_ede ,_bec =_ede +2,_bec +1{_dbac =_ede *_gdac .BytesPerLine ;_fabb =_bec *_bgbc .BytesPerLine ;for _eca ,_cge =0,0;_eca < _eed ;_eca ,_cge =_eca +4,_cge +1{for _fdg =0;
|
|
_fdg < 4;_fdg ++{_egd =_dbac +_eca +_fdg ;if _egd <=len (_gdac .Data )-1&&_egd < _dbac +_gdac .BytesPerLine {_fgef [_fdg ]=_gdac .Data [_egd ];}else {_fgef [_fdg ]=0x00;};_egd =_dbac +_gdac .BytesPerLine +_eca +_fdg ;if _egd <=len (_gdac .Data )-1&&_egd < _dbac +(2*_gdac .BytesPerLine ){_fefb [_fdg ]=_gdac .Data [_egd ];
|
|
}else {_fefb [_fdg ]=0x00;};};_ageb =_b .BigEndian .Uint32 (_fgef );_acb =_b .BigEndian .Uint32 (_fefb );_cbda =_ageb &_acb ;_cbda |=_cbda <<1;_dce =_ageb |_acb ;_dce &=_dce <<1;_acb =_cbda &_dce ;_acb &=0xaaaaaaaa;_ageb =_acb |(_acb <<7);_efbc =byte (_ageb >>24);
|
|
_agdf =byte ((_ageb >>8)&0xff);_egd =_fabb +_cge ;if _egd +1==len (_bgbc .Data )-1||_egd +1>=_fabb +_bgbc .BytesPerLine {if _agd =_bgbc .setByte (_egd ,_abe [_efbc ]);_agd !=nil {return _d .Errorf ("\u0069n\u0064\u0065\u0078\u003a\u0020\u0025d",_egd );
|
|
};}else {_edd =(uint16 (_abe [_efbc ])<<8)|uint16 (_abe [_agdf ]);if _agd =_bgbc .setTwoBytes (_egd ,_edd );_agd !=nil {return _d .Errorf ("s\u0065\u0074\u0074\u0069\u006e\u0067 \u0074\u0077\u006f\u0020\u0062\u0079t\u0065\u0073\u0020\u0066\u0061\u0069\u006ce\u0064\u002c\u0020\u0069\u006e\u0064\u0065\u0078\u003a\u0020%\u0064",_egd );
|
|
};_cge ++;};};};return nil ;};func FromGoImage (i _fe .Image )(Image ,error ){switch _ebca :=i .(type ){case Image :return _ebca .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 );};};var _ Image =&NRGBA16 {};func (_ebb *Monochrome )clearBit (_dbcg ,_egca int ){_ebb .Data [_dbcg ]&=^(0x80>>uint (_egca &7))};var _ Gray =&Gray2 {};
|
|
func (_efc *Gray4 )At (x ,y int )_fc .Color {_fee ,_ :=_efc .ColorAt (x ,y );return _fee };func ColorAtCMYK (x ,y ,width int ,data []byte ,decode []float64 )(_fc .CMYK ,error ){_accg :=4*(y *width +x );if _accg +3>=len (data ){return _fc .CMYK {},_d .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 [_accg ]&0xff;M :=data [_accg +1]&0xff;Y :=data [_accg +2]&0xff;K :=data [_accg +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 _fc .CMYK {C :C ,M :M ,Y :Y ,K :K },nil ;};func (_gfeg *Monochrome )getBit (_gdaccf ,_dge int )uint8 {return _gfeg .Data [_gdaccf +(_dge >>3)]>>uint (7-(_dge &7))&1;
|
|
};func (_cebc *Gray8 )Base ()*ImageBase {return &_cebc .ImageBase };func init (){_edcb ()};func _cdac (_egbd _fc .NRGBA )_fc .RGBA {_afac ,_agcd ,_cae ,_gbge :=_egbd .RGBA ();return _fc .RGBA {R :uint8 (_afac >>8),G :uint8 (_agcd >>8),B :uint8 (_cae >>8),A :uint8 (_gbge >>8)};
|
|
};func (_dab *Gray16 )Base ()*ImageBase {return &_dab .ImageBase };func (_ggfg *RGBA32 )ColorModel ()_fc .Model {return _fc .NRGBAModel };func (_fbae *NRGBA32 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_fbae .Width ,Y :_fbae .Height }};
|
|
};func _gdgca (_gaee _fc .NRGBA )_fc .NRGBA {_gaee .R =_gaee .R >>4|(_gaee .R >>4)<<4;_gaee .G =_gaee .G >>4|(_gaee .G >>4)<<4;_gaee .B =_gaee .B >>4|(_gaee .B >>4)<<4;return _gaee ;};var (MonochromeConverter =ConverterFunc (_afe );Gray2Converter =ConverterFunc (_dgdc );
|
|
Gray4Converter =ConverterFunc (_abffa );GrayConverter =ConverterFunc (_bfce );Gray16Converter =ConverterFunc (_fabc );NRGBA16Converter =ConverterFunc (_cgaca );NRGBAConverter =ConverterFunc (_fegda );NRGBA64Converter =ConverterFunc (_ecegc );RGBAConverter =ConverterFunc (_gcge );
|
|
CMYKConverter =ConverterFunc (_fdbg ););func (_dgadg *Monochrome )ResolveDecode ()error {if len (_dgadg .Decode )!=2{return nil ;};if _dgadg .Decode [0]==1&&_dgadg .Decode [1]==0{if _dbgc :=_dgadg .InverseData ();_dbgc !=nil {return _dbgc ;};_dgadg .Decode =nil ;
|
|
};return nil ;};func _gdadc (_adceg _fe .Image ,_bdfb uint8 )*_fe .Gray {_fbaeg :=_adceg .Bounds ();_fagg :=_fe .NewGray (_fbaeg );var (_dbbc _fc .Color ;_dcbc _fc .Gray ;);for _dfgag :=0;_dfgag < _fbaeg .Max .X ;_dfgag ++{for _edffcd :=0;_edffcd < _fbaeg .Max .Y ;
|
|
_edffcd ++{_dbbc =_adceg .At (_dfgag ,_edffcd );_fagg .Set (_dfgag ,_edffcd ,_dbbc );_dcbc =_fagg .GrayAt (_dfgag ,_edffcd );_fagg .SetGray (_dfgag ,_edffcd ,_fc .Gray {Y :_ecegg (_dcbc .Y ,_bdfb )});};};return _fagg ;};func (_eaae *NRGBA32 )NRGBAAt (x ,y int )_fc .NRGBA {_ecbe ,_ :=ColorAtNRGBA32 (x ,y ,_eaae .Width ,_eaae .Data ,_eaae .Alpha ,_eaae .Decode );
|
|
return _ecbe ;};var _ Gray =&Gray8 {};func (_cbdde *Monochrome )ExpandBinary (factor int )(*Monochrome ,error ){if !IsPowerOf2 (uint (factor )){return nil ,_d .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0065\u0078\u0070\u0061\u006e\u0064\u0020b\u0069n\u0061\u0072\u0079\u0020\u0066\u0061\u0063\u0074\u006f\u0072\u003a\u0020\u0025\u0064",factor );
|
|
};return _cc (_cbdde ,factor );};func (_begg *ImageBase )setEightPartlyBytes (_fbac ,_fgfg int ,_fec uint64 )(_bbcb error ){var (_aggd byte ;_decf int ;);for _eedgc :=1;_eedgc <=_fgfg ;_eedgc ++{_decf =64-_eedgc *8;_aggd =byte (_fec >>uint (_decf )&0xff);
|
|
if _bbcb =_begg .setByte (_fbac +_eedgc -1,_aggd );_bbcb !=nil {return _bbcb ;};};_abab :=_begg .BytesPerLine *8-_begg .Width ;if _abab ==0{return nil ;};_decf -=8;_aggd =byte (_fec >>uint (_decf )&0xff)<<uint (_abab );if _bbcb =_begg .setByte (_fbac +_fgfg ,_aggd );
|
|
_bbcb !=nil {return _bbcb ;};return nil ;};var _ _fe .Image =&NRGBA64 {};func _befc (_adfed *Monochrome ,_efggc ,_fegd ,_daga ,_eaga int ,_cdb RasterOperator ,_gdgc *Monochrome ,_efab ,_aee int )error {var (_eece bool ;_fcea bool ;_agfd byte ;_feag int ;
|
|
_gfba int ;_cbff int ;_bgdf int ;_dbad bool ;_aedde int ;_aca int ;_fbfd int ;_gdcgab bool ;_accec byte ;_dbgb int ;_ggfc int ;_agad int ;_debf byte ;_bbba int ;_bfeca int ;_fbge uint ;_efbb uint ;_gbad byte ;_gcc shift ;_dbdd bool ;_gaea bool ;_dffg ,_fccg int ;
|
|
);if _efab &7!=0{_bfeca =8-(_efab &7);};if _efggc &7!=0{_gfba =8-(_efggc &7);};if _bfeca ==0&&_gfba ==0{_gbad =_dedd [0];}else {if _gfba > _bfeca {_fbge =uint (_gfba -_bfeca );}else {_fbge =uint (8-(_bfeca -_gfba ));};_efbb =8-_fbge ;_gbad =_dedd [_fbge ];
|
|
};if (_efggc &7)!=0{_eece =true ;_feag =8-(_efggc &7);_agfd =_dedd [_feag ];_cbff =_adfed .BytesPerLine *_fegd +(_efggc >>3);_bgdf =_gdgc .BytesPerLine *_aee +(_efab >>3);_bbba =8-(_efab &7);if _feag > _bbba {_gcc =_cfbg ;if _daga >=_bfeca {_dbdd =true ;
|
|
};}else {_gcc =_agadd ;};};if _daga < _feag {_fcea =true ;_agfd &=_cgd [8-_feag +_daga ];};if !_fcea {_aedde =(_daga -_feag )>>3;if _aedde !=0{_dbad =true ;_aca =_adfed .BytesPerLine *_fegd +((_efggc +_gfba )>>3);_fbfd =_gdgc .BytesPerLine *_aee +((_efab +_gfba )>>3);
|
|
};};_dbgb =(_efggc +_daga )&7;if !(_fcea ||_dbgb ==0){_gdcgab =true ;_accec =_cgd [_dbgb ];_ggfc =_adfed .BytesPerLine *_fegd +((_efggc +_gfba )>>3)+_aedde ;_agad =_gdgc .BytesPerLine *_aee +((_efab +_gfba )>>3)+_aedde ;if _dbgb > int (_efbb ){_gaea =true ;
|
|
};};switch _cdb {case PixSrc :if _eece {for _dffg =0;_dffg < _eaga ;_dffg ++{if _gcc ==_cfbg {_debf =_gdgc .Data [_bgdf ]<<_fbge ;if _dbdd {_debf =_ebaa (_debf ,_gdgc .Data [_bgdf +1]>>_efbb ,_gbad );};}else {_debf =_gdgc .Data [_bgdf ]>>_efbb ;};_adfed .Data [_cbff ]=_ebaa (_adfed .Data [_cbff ],_debf ,_agfd );
|
|
_cbff +=_adfed .BytesPerLine ;_bgdf +=_gdgc .BytesPerLine ;};};if _dbad {for _dffg =0;_dffg < _eaga ;_dffg ++{for _fccg =0;_fccg < _aedde ;_fccg ++{_debf =_ebaa (_gdgc .Data [_fbfd +_fccg ]<<_fbge ,_gdgc .Data [_fbfd +_fccg +1]>>_efbb ,_gbad );_adfed .Data [_aca +_fccg ]=_debf ;
|
|
};_aca +=_adfed .BytesPerLine ;_fbfd +=_gdgc .BytesPerLine ;};};if _gdcgab {for _dffg =0;_dffg < _eaga ;_dffg ++{_debf =_gdgc .Data [_agad ]<<_fbge ;if _gaea {_debf =_ebaa (_debf ,_gdgc .Data [_agad +1]>>_efbb ,_gbad );};_adfed .Data [_ggfc ]=_ebaa (_adfed .Data [_ggfc ],_debf ,_accec );
|
|
_ggfc +=_adfed .BytesPerLine ;_agad +=_gdgc .BytesPerLine ;};};case PixNotSrc :if _eece {for _dffg =0;_dffg < _eaga ;_dffg ++{if _gcc ==_cfbg {_debf =_gdgc .Data [_bgdf ]<<_fbge ;if _dbdd {_debf =_ebaa (_debf ,_gdgc .Data [_bgdf +1]>>_efbb ,_gbad );};}else {_debf =_gdgc .Data [_bgdf ]>>_efbb ;
|
|
};_adfed .Data [_cbff ]=_ebaa (_adfed .Data [_cbff ],^_debf ,_agfd );_cbff +=_adfed .BytesPerLine ;_bgdf +=_gdgc .BytesPerLine ;};};if _dbad {for _dffg =0;_dffg < _eaga ;_dffg ++{for _fccg =0;_fccg < _aedde ;_fccg ++{_debf =_ebaa (_gdgc .Data [_fbfd +_fccg ]<<_fbge ,_gdgc .Data [_fbfd +_fccg +1]>>_efbb ,_gbad );
|
|
_adfed .Data [_aca +_fccg ]=^_debf ;};_aca +=_adfed .BytesPerLine ;_fbfd +=_gdgc .BytesPerLine ;};};if _gdcgab {for _dffg =0;_dffg < _eaga ;_dffg ++{_debf =_gdgc .Data [_agad ]<<_fbge ;if _gaea {_debf =_ebaa (_debf ,_gdgc .Data [_agad +1]>>_efbb ,_gbad );
|
|
};_adfed .Data [_ggfc ]=_ebaa (_adfed .Data [_ggfc ],^_debf ,_accec );_ggfc +=_adfed .BytesPerLine ;_agad +=_gdgc .BytesPerLine ;};};case PixSrcOrDst :if _eece {for _dffg =0;_dffg < _eaga ;_dffg ++{if _gcc ==_cfbg {_debf =_gdgc .Data [_bgdf ]<<_fbge ;if _dbdd {_debf =_ebaa (_debf ,_gdgc .Data [_bgdf +1]>>_efbb ,_gbad );
|
|
};}else {_debf =_gdgc .Data [_bgdf ]>>_efbb ;};_adfed .Data [_cbff ]=_ebaa (_adfed .Data [_cbff ],_debf |_adfed .Data [_cbff ],_agfd );_cbff +=_adfed .BytesPerLine ;_bgdf +=_gdgc .BytesPerLine ;};};if _dbad {for _dffg =0;_dffg < _eaga ;_dffg ++{for _fccg =0;
|
|
_fccg < _aedde ;_fccg ++{_debf =_ebaa (_gdgc .Data [_fbfd +_fccg ]<<_fbge ,_gdgc .Data [_fbfd +_fccg +1]>>_efbb ,_gbad );_adfed .Data [_aca +_fccg ]|=_debf ;};_aca +=_adfed .BytesPerLine ;_fbfd +=_gdgc .BytesPerLine ;};};if _gdcgab {for _dffg =0;_dffg < _eaga ;
|
|
_dffg ++{_debf =_gdgc .Data [_agad ]<<_fbge ;if _gaea {_debf =_ebaa (_debf ,_gdgc .Data [_agad +1]>>_efbb ,_gbad );};_adfed .Data [_ggfc ]=_ebaa (_adfed .Data [_ggfc ],_debf |_adfed .Data [_ggfc ],_accec );_ggfc +=_adfed .BytesPerLine ;_agad +=_gdgc .BytesPerLine ;
|
|
};};case PixSrcAndDst :if _eece {for _dffg =0;_dffg < _eaga ;_dffg ++{if _gcc ==_cfbg {_debf =_gdgc .Data [_bgdf ]<<_fbge ;if _dbdd {_debf =_ebaa (_debf ,_gdgc .Data [_bgdf +1]>>_efbb ,_gbad );};}else {_debf =_gdgc .Data [_bgdf ]>>_efbb ;};_adfed .Data [_cbff ]=_ebaa (_adfed .Data [_cbff ],_debf &_adfed .Data [_cbff ],_agfd );
|
|
_cbff +=_adfed .BytesPerLine ;_bgdf +=_gdgc .BytesPerLine ;};};if _dbad {for _dffg =0;_dffg < _eaga ;_dffg ++{for _fccg =0;_fccg < _aedde ;_fccg ++{_debf =_ebaa (_gdgc .Data [_fbfd +_fccg ]<<_fbge ,_gdgc .Data [_fbfd +_fccg +1]>>_efbb ,_gbad );_adfed .Data [_aca +_fccg ]&=_debf ;
|
|
};_aca +=_adfed .BytesPerLine ;_fbfd +=_gdgc .BytesPerLine ;};};if _gdcgab {for _dffg =0;_dffg < _eaga ;_dffg ++{_debf =_gdgc .Data [_agad ]<<_fbge ;if _gaea {_debf =_ebaa (_debf ,_gdgc .Data [_agad +1]>>_efbb ,_gbad );};_adfed .Data [_ggfc ]=_ebaa (_adfed .Data [_ggfc ],_debf &_adfed .Data [_ggfc ],_accec );
|
|
_ggfc +=_adfed .BytesPerLine ;_agad +=_gdgc .BytesPerLine ;};};case PixSrcXorDst :if _eece {for _dffg =0;_dffg < _eaga ;_dffg ++{if _gcc ==_cfbg {_debf =_gdgc .Data [_bgdf ]<<_fbge ;if _dbdd {_debf =_ebaa (_debf ,_gdgc .Data [_bgdf +1]>>_efbb ,_gbad );
|
|
};}else {_debf =_gdgc .Data [_bgdf ]>>_efbb ;};_adfed .Data [_cbff ]=_ebaa (_adfed .Data [_cbff ],_debf ^_adfed .Data [_cbff ],_agfd );_cbff +=_adfed .BytesPerLine ;_bgdf +=_gdgc .BytesPerLine ;};};if _dbad {for _dffg =0;_dffg < _eaga ;_dffg ++{for _fccg =0;
|
|
_fccg < _aedde ;_fccg ++{_debf =_ebaa (_gdgc .Data [_fbfd +_fccg ]<<_fbge ,_gdgc .Data [_fbfd +_fccg +1]>>_efbb ,_gbad );_adfed .Data [_aca +_fccg ]^=_debf ;};_aca +=_adfed .BytesPerLine ;_fbfd +=_gdgc .BytesPerLine ;};};if _gdcgab {for _dffg =0;_dffg < _eaga ;
|
|
_dffg ++{_debf =_gdgc .Data [_agad ]<<_fbge ;if _gaea {_debf =_ebaa (_debf ,_gdgc .Data [_agad +1]>>_efbb ,_gbad );};_adfed .Data [_ggfc ]=_ebaa (_adfed .Data [_ggfc ],_debf ^_adfed .Data [_ggfc ],_accec );_ggfc +=_adfed .BytesPerLine ;_agad +=_gdgc .BytesPerLine ;
|
|
};};case PixNotSrcOrDst :if _eece {for _dffg =0;_dffg < _eaga ;_dffg ++{if _gcc ==_cfbg {_debf =_gdgc .Data [_bgdf ]<<_fbge ;if _dbdd {_debf =_ebaa (_debf ,_gdgc .Data [_bgdf +1]>>_efbb ,_gbad );};}else {_debf =_gdgc .Data [_bgdf ]>>_efbb ;};_adfed .Data [_cbff ]=_ebaa (_adfed .Data [_cbff ],^_debf |_adfed .Data [_cbff ],_agfd );
|
|
_cbff +=_adfed .BytesPerLine ;_bgdf +=_gdgc .BytesPerLine ;};};if _dbad {for _dffg =0;_dffg < _eaga ;_dffg ++{for _fccg =0;_fccg < _aedde ;_fccg ++{_debf =_ebaa (_gdgc .Data [_fbfd +_fccg ]<<_fbge ,_gdgc .Data [_fbfd +_fccg +1]>>_efbb ,_gbad );_adfed .Data [_aca +_fccg ]|=^_debf ;
|
|
};_aca +=_adfed .BytesPerLine ;_fbfd +=_gdgc .BytesPerLine ;};};if _gdcgab {for _dffg =0;_dffg < _eaga ;_dffg ++{_debf =_gdgc .Data [_agad ]<<_fbge ;if _gaea {_debf =_ebaa (_debf ,_gdgc .Data [_agad +1]>>_efbb ,_gbad );};_adfed .Data [_ggfc ]=_ebaa (_adfed .Data [_ggfc ],^_debf |_adfed .Data [_ggfc ],_accec );
|
|
_ggfc +=_adfed .BytesPerLine ;_agad +=_gdgc .BytesPerLine ;};};case PixNotSrcAndDst :if _eece {for _dffg =0;_dffg < _eaga ;_dffg ++{if _gcc ==_cfbg {_debf =_gdgc .Data [_bgdf ]<<_fbge ;if _dbdd {_debf =_ebaa (_debf ,_gdgc .Data [_bgdf +1]>>_efbb ,_gbad );
|
|
};}else {_debf =_gdgc .Data [_bgdf ]>>_efbb ;};_adfed .Data [_cbff ]=_ebaa (_adfed .Data [_cbff ],^_debf &_adfed .Data [_cbff ],_agfd );_cbff +=_adfed .BytesPerLine ;_bgdf +=_gdgc .BytesPerLine ;};};if _dbad {for _dffg =0;_dffg < _eaga ;_dffg ++{for _fccg =0;
|
|
_fccg < _aedde ;_fccg ++{_debf =_ebaa (_gdgc .Data [_fbfd +_fccg ]<<_fbge ,_gdgc .Data [_fbfd +_fccg +1]>>_efbb ,_gbad );_adfed .Data [_aca +_fccg ]&=^_debf ;};_aca +=_adfed .BytesPerLine ;_fbfd +=_gdgc .BytesPerLine ;};};if _gdcgab {for _dffg =0;_dffg < _eaga ;
|
|
_dffg ++{_debf =_gdgc .Data [_agad ]<<_fbge ;if _gaea {_debf =_ebaa (_debf ,_gdgc .Data [_agad +1]>>_efbb ,_gbad );};_adfed .Data [_ggfc ]=_ebaa (_adfed .Data [_ggfc ],^_debf &_adfed .Data [_ggfc ],_accec );_ggfc +=_adfed .BytesPerLine ;_agad +=_gdgc .BytesPerLine ;
|
|
};};case PixSrcOrNotDst :if _eece {for _dffg =0;_dffg < _eaga ;_dffg ++{if _gcc ==_cfbg {_debf =_gdgc .Data [_bgdf ]<<_fbge ;if _dbdd {_debf =_ebaa (_debf ,_gdgc .Data [_bgdf +1]>>_efbb ,_gbad );};}else {_debf =_gdgc .Data [_bgdf ]>>_efbb ;};_adfed .Data [_cbff ]=_ebaa (_adfed .Data [_cbff ],_debf |^_adfed .Data [_cbff ],_agfd );
|
|
_cbff +=_adfed .BytesPerLine ;_bgdf +=_gdgc .BytesPerLine ;};};if _dbad {for _dffg =0;_dffg < _eaga ;_dffg ++{for _fccg =0;_fccg < _aedde ;_fccg ++{_debf =_ebaa (_gdgc .Data [_fbfd +_fccg ]<<_fbge ,_gdgc .Data [_fbfd +_fccg +1]>>_efbb ,_gbad );_adfed .Data [_aca +_fccg ]=_debf |^_adfed .Data [_aca +_fccg ];
|
|
};_aca +=_adfed .BytesPerLine ;_fbfd +=_gdgc .BytesPerLine ;};};if _gdcgab {for _dffg =0;_dffg < _eaga ;_dffg ++{_debf =_gdgc .Data [_agad ]<<_fbge ;if _gaea {_debf =_ebaa (_debf ,_gdgc .Data [_agad +1]>>_efbb ,_gbad );};_adfed .Data [_ggfc ]=_ebaa (_adfed .Data [_ggfc ],_debf |^_adfed .Data [_ggfc ],_accec );
|
|
_ggfc +=_adfed .BytesPerLine ;_agad +=_gdgc .BytesPerLine ;};};case PixSrcAndNotDst :if _eece {for _dffg =0;_dffg < _eaga ;_dffg ++{if _gcc ==_cfbg {_debf =_gdgc .Data [_bgdf ]<<_fbge ;if _dbdd {_debf =_ebaa (_debf ,_gdgc .Data [_bgdf +1]>>_efbb ,_gbad );
|
|
};}else {_debf =_gdgc .Data [_bgdf ]>>_efbb ;};_adfed .Data [_cbff ]=_ebaa (_adfed .Data [_cbff ],_debf &^_adfed .Data [_cbff ],_agfd );_cbff +=_adfed .BytesPerLine ;_bgdf +=_gdgc .BytesPerLine ;};};if _dbad {for _dffg =0;_dffg < _eaga ;_dffg ++{for _fccg =0;
|
|
_fccg < _aedde ;_fccg ++{_debf =_ebaa (_gdgc .Data [_fbfd +_fccg ]<<_fbge ,_gdgc .Data [_fbfd +_fccg +1]>>_efbb ,_gbad );_adfed .Data [_aca +_fccg ]=_debf &^_adfed .Data [_aca +_fccg ];};_aca +=_adfed .BytesPerLine ;_fbfd +=_gdgc .BytesPerLine ;};};if _gdcgab {for _dffg =0;
|
|
_dffg < _eaga ;_dffg ++{_debf =_gdgc .Data [_agad ]<<_fbge ;if _gaea {_debf =_ebaa (_debf ,_gdgc .Data [_agad +1]>>_efbb ,_gbad );};_adfed .Data [_ggfc ]=_ebaa (_adfed .Data [_ggfc ],_debf &^_adfed .Data [_ggfc ],_accec );_ggfc +=_adfed .BytesPerLine ;
|
|
_agad +=_gdgc .BytesPerLine ;};};case PixNotPixSrcOrDst :if _eece {for _dffg =0;_dffg < _eaga ;_dffg ++{if _gcc ==_cfbg {_debf =_gdgc .Data [_bgdf ]<<_fbge ;if _dbdd {_debf =_ebaa (_debf ,_gdgc .Data [_bgdf +1]>>_efbb ,_gbad );};}else {_debf =_gdgc .Data [_bgdf ]>>_efbb ;
|
|
};_adfed .Data [_cbff ]=_ebaa (_adfed .Data [_cbff ],^(_debf |_adfed .Data [_cbff ]),_agfd );_cbff +=_adfed .BytesPerLine ;_bgdf +=_gdgc .BytesPerLine ;};};if _dbad {for _dffg =0;_dffg < _eaga ;_dffg ++{for _fccg =0;_fccg < _aedde ;_fccg ++{_debf =_ebaa (_gdgc .Data [_fbfd +_fccg ]<<_fbge ,_gdgc .Data [_fbfd +_fccg +1]>>_efbb ,_gbad );
|
|
_adfed .Data [_aca +_fccg ]=^(_debf |_adfed .Data [_aca +_fccg ]);};_aca +=_adfed .BytesPerLine ;_fbfd +=_gdgc .BytesPerLine ;};};if _gdcgab {for _dffg =0;_dffg < _eaga ;_dffg ++{_debf =_gdgc .Data [_agad ]<<_fbge ;if _gaea {_debf =_ebaa (_debf ,_gdgc .Data [_agad +1]>>_efbb ,_gbad );
|
|
};_adfed .Data [_ggfc ]=_ebaa (_adfed .Data [_ggfc ],^(_debf |_adfed .Data [_ggfc ]),_accec );_ggfc +=_adfed .BytesPerLine ;_agad +=_gdgc .BytesPerLine ;};};case PixNotPixSrcAndDst :if _eece {for _dffg =0;_dffg < _eaga ;_dffg ++{if _gcc ==_cfbg {_debf =_gdgc .Data [_bgdf ]<<_fbge ;
|
|
if _dbdd {_debf =_ebaa (_debf ,_gdgc .Data [_bgdf +1]>>_efbb ,_gbad );};}else {_debf =_gdgc .Data [_bgdf ]>>_efbb ;};_adfed .Data [_cbff ]=_ebaa (_adfed .Data [_cbff ],^(_debf &_adfed .Data [_cbff ]),_agfd );_cbff +=_adfed .BytesPerLine ;_bgdf +=_gdgc .BytesPerLine ;
|
|
};};if _dbad {for _dffg =0;_dffg < _eaga ;_dffg ++{for _fccg =0;_fccg < _aedde ;_fccg ++{_debf =_ebaa (_gdgc .Data [_fbfd +_fccg ]<<_fbge ,_gdgc .Data [_fbfd +_fccg +1]>>_efbb ,_gbad );_adfed .Data [_aca +_fccg ]=^(_debf &_adfed .Data [_aca +_fccg ]);};
|
|
_aca +=_adfed .BytesPerLine ;_fbfd +=_gdgc .BytesPerLine ;};};if _gdcgab {for _dffg =0;_dffg < _eaga ;_dffg ++{_debf =_gdgc .Data [_agad ]<<_fbge ;if _gaea {_debf =_ebaa (_debf ,_gdgc .Data [_agad +1]>>_efbb ,_gbad );};_adfed .Data [_ggfc ]=_ebaa (_adfed .Data [_ggfc ],^(_debf &_adfed .Data [_ggfc ]),_accec );
|
|
_ggfc +=_adfed .BytesPerLine ;_agad +=_gdgc .BytesPerLine ;};};case PixNotPixSrcXorDst :if _eece {for _dffg =0;_dffg < _eaga ;_dffg ++{if _gcc ==_cfbg {_debf =_gdgc .Data [_bgdf ]<<_fbge ;if _dbdd {_debf =_ebaa (_debf ,_gdgc .Data [_bgdf +1]>>_efbb ,_gbad );
|
|
};}else {_debf =_gdgc .Data [_bgdf ]>>_efbb ;};_adfed .Data [_cbff ]=_ebaa (_adfed .Data [_cbff ],^(_debf ^_adfed .Data [_cbff ]),_agfd );_cbff +=_adfed .BytesPerLine ;_bgdf +=_gdgc .BytesPerLine ;};};if _dbad {for _dffg =0;_dffg < _eaga ;_dffg ++{for _fccg =0;
|
|
_fccg < _aedde ;_fccg ++{_debf =_ebaa (_gdgc .Data [_fbfd +_fccg ]<<_fbge ,_gdgc .Data [_fbfd +_fccg +1]>>_efbb ,_gbad );_adfed .Data [_aca +_fccg ]=^(_debf ^_adfed .Data [_aca +_fccg ]);};_aca +=_adfed .BytesPerLine ;_fbfd +=_gdgc .BytesPerLine ;};};if _gdcgab {for _dffg =0;
|
|
_dffg < _eaga ;_dffg ++{_debf =_gdgc .Data [_agad ]<<_fbge ;if _gaea {_debf =_ebaa (_debf ,_gdgc .Data [_agad +1]>>_efbb ,_gbad );};_adfed .Data [_ggfc ]=_ebaa (_adfed .Data [_ggfc ],^(_debf ^_adfed .Data [_ggfc ]),_accec );_ggfc +=_adfed .BytesPerLine ;
|
|
_agad +=_gdgc .BytesPerLine ;};};default:_ba .Log .Debug ("\u004f\u0070e\u0072\u0061\u0074\u0069\u006f\u006e\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006e\u006f\u0074\u0020\u0070\u0065\u0072\u006d\u0069tt\u0065\u0064",_cdb );return _e .New ("\u0072\u0061\u0073\u0074\u0065\u0072\u0020\u006f\u0070\u0065r\u0061\u0074\u0069\u006f\u006e\u0020\u006eo\u0074\u0020\u0070\u0065\u0072\u006d\u0069\u0074\u0074\u0065\u0064");
|
|
};return nil ;};func _bafg (_fbaa _fe .Image ,_gaab int )(_fe .Rectangle ,bool ,[]byte ){_gace :=_fbaa .Bounds ();var (_cgcd bool ;_dcac []byte ;);switch _acbfe :=_fbaa .(type ){case SMasker :_cgcd =_acbfe .HasAlpha ();case NRGBA ,RGBA ,*_fe .RGBA64 ,nrgba64 ,*_fe .NYCbCrA :_dcac =make ([]byte ,_gace .Max .X *_gace .Max .Y *_gaab );
|
|
case *_fe .Paletted :var _gcded bool ;for _ ,_gcec :=range _acbfe .Palette {_ceaf ,_cfce ,_dcfda ,_ffdb :=_gcec .RGBA ();if _ceaf ==0&&_cfce ==0&&_dcfda ==0&&_ffdb !=0{_gcded =true ;break ;};};if _gcded {_dcac =make ([]byte ,_gace .Max .X *_gace .Max .Y *_gaab );
|
|
};};return _gace ,_cgcd ,_dcac ;};func (_dcbb *Monochrome )Scale (scale float64 )(*Monochrome ,error ){var _cce bool ;_aedf :=scale ;if scale < 1{_aedf =1/scale ;_cce =true ;};_adfe :=NextPowerOf2 (uint (_aedf ));if InDelta (float64 (_adfe ),_aedf ,0.001){if _cce {return _dcbb .ReduceBinary (_aedf );
|
|
};return _dcbb .ExpandBinary (int (_adfe ));};_aga :=int (_ea .RoundToEven (float64 (_dcbb .Width )*scale ));_dfcb :=int (_ea .RoundToEven (float64 (_dcbb .Height )*scale ));return _dcbb .ScaleLow (_aga ,_dfcb );};func (_ceee *Gray8 )Validate ()error {if len (_ceee .Data )!=_ceee .Height *_ceee .BytesPerLine {return ErrInvalidImage ;
|
|
};return nil ;};func (_bdcdb *Gray2 )Set (x ,y int ,c _fc .Color ){if x >=_bdcdb .Width ||y >=_bdcdb .Height {return ;};_dbacf :=Gray2Model .Convert (c ).(_fc .Gray );_abac :=y *_bdcdb .BytesPerLine ;_bfc :=_abac +(x >>2);_deeg :=_dbacf .Y >>6;_bdcdb .Data [_bfc ]=(_bdcdb .Data [_bfc ]&(^(0xc0>>uint (2*((x )&3)))))|(_deeg <<uint (6-2*(x &3)));
|
|
};var _ Image =&Gray4 {};func (_cfff *Monochrome )Histogram ()(_gfac [256]int ){for _ ,_ffad :=range _cfff .Data {_gfac [0xff]+=int (_bgff [_cfff .Data [_ffad ]]);};return _gfac ;};func (_dbfce *Gray4 )SetGray (x ,y int ,g _fc .Gray ){if x >=_dbfce .Width ||y >=_dbfce .Height {return ;
|
|
};g =_bggba (g );_dbfce .setGray (x ,y ,g );};func (_deb *Monochrome )IsUnpadded ()bool {return (_deb .Width *_deb .Height )==len (_deb .Data )};func (_fbc *Gray2 )SetGray (x ,y int ,gray _fc .Gray ){_ebgg :=_gbbe (gray );_afcg :=y *_fbc .BytesPerLine ;
|
|
_geag :=_afcg +(x >>2);if _geag >=len (_fbc .Data ){return ;};_bga :=_ebgg .Y >>6;_fbc .Data [_geag ]=(_fbc .Data [_geag ]&(^(0xc0>>uint (2*((x )&3)))))|(_bga <<uint (6-2*(x &3)));};var _ Image =&Gray16 {};func _ggdb (_bacf ,_cgbb NRGBA ,_accbd _fe .Rectangle ){for _ccbg :=0;
|
|
_ccbg < _accbd .Max .X ;_ccbg ++{for _dbba :=0;_dbba < _accbd .Max .Y ;_dbba ++{_cgbb .SetNRGBA (_ccbg ,_dbba ,_bacf .NRGBAAt (_ccbg ,_dbba ));};};};func ConverterFunc (converterFunc func (_gaa _fe .Image )(Image ,error ))ColorConverter {return colorConverter {_aedd :converterFunc };
|
|
};func (_gca *Gray2 )ColorAt (x ,y int )(_fc .Color ,error ){return ColorAtGray2BPC (x ,y ,_gca .BytesPerLine ,_gca .Data ,_gca .Decode );};func NewImage (width ,height ,bitsPerComponent ,colorComponents int ,data ,alpha []byte ,decode []float64 )(Image ,error ){_fac :=NewImageBase (width ,height ,bitsPerComponent ,colorComponents ,data ,alpha ,decode );
|
|
var _ggddb Image ;switch colorComponents {case 1:switch bitsPerComponent {case 1:_ggddb =&Monochrome {ImageBase :_fac ,ModelThreshold :0x0f};case 2:_ggddb =&Gray2 {ImageBase :_fac };case 4:_ggddb =&Gray4 {ImageBase :_fac };case 8:_ggddb =&Gray8 {ImageBase :_fac };
|
|
case 16:_ggddb =&Gray16 {ImageBase :_fac };};case 3:switch bitsPerComponent {case 4:_ggddb =&NRGBA16 {ImageBase :_fac };case 8:_ggddb =&NRGBA32 {ImageBase :_fac };case 16:_ggddb =&NRGBA64 {ImageBase :_fac };};case 4:_ggddb =&CMYK32 {ImageBase :_fac };};
|
|
if _ggddb ==nil {return nil ,ErrInvalidImage ;};return _ggddb ,nil ;};var ErrInvalidImage =_e .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");
|
|
type NRGBA32 struct{ImageBase };var _ NRGBA =&NRGBA16 {};func (_gdcg *CMYK32 )SetCMYK (x ,y int ,c _fc .CMYK ){_fae :=4*(y *_gdcg .Width +x );if _fae +3>=len (_gdcg .Data ){return ;};_gdcg .Data [_fae ]=c .C ;_gdcg .Data [_fae +1]=c .M ;_gdcg .Data [_fae +2]=c .Y ;
|
|
_gdcg .Data [_fae +3]=c .K ;};func (_cbe *CMYK32 )Copy ()Image {return &CMYK32 {ImageBase :_cbe .copy ()}};func _deac (_cagb Gray ,_bgfdf RGBA ,_cgef _fe .Rectangle ){for _fdfda :=0;_fdfda < _cgef .Max .X ;_fdfda ++{for _aaeg :=0;_aaeg < _cgef .Max .Y ;
|
|
_aaeg ++{_bgbba :=_cagb .GrayAt (_fdfda ,_aaeg );_bgfdf .SetRGBA (_fdfda ,_aaeg ,_fead (_bgbba ));};};};func (_cefd *Gray8 )ColorAt (x ,y int )(_fc .Color ,error ){return ColorAtGray8BPC (x ,y ,_cefd .BytesPerLine ,_cefd .Data ,_cefd .Decode );};func IsGrayImgBlackAndWhite (i *_fe .Gray )bool {return _edfe (i )};
|
|
func (_bbcg *Monochrome )setBit (_fegb ,_ggc int ){_bbcg .Data [_fegb +(_ggc >>3)]|=0x80>>uint (_ggc &7)};type Gray4 struct{ImageBase };func _afeaa (_faafg CMYK ,_addc NRGBA ,_fdfg _fe .Rectangle ){for _ggeb :=0;_ggeb < _fdfg .Max .X ;_ggeb ++{for _ecacf :=0;
|
|
_ecacf < _fdfg .Max .Y ;_ecacf ++{_gdd :=_faafg .CMYKAt (_ggeb ,_ecacf );_addc .SetNRGBA (_ggeb ,_ecacf ,_ddbe (_gdd ));};};};func _eecg (_dbab _fc .Gray ,_gdea monochromeModel )_fc .Gray {if _dbab .Y > uint8 (_gdea ){return _fc .Gray {Y :_ea .MaxUint8 };
|
|
};return _fc .Gray {};};func (_gdbb *Monochrome )ScaleLow (width ,height int )(*Monochrome ,error ){if width < 0||height < 0{return nil ,_e .New ("\u0070\u0072\u006f\u0076\u0069\u0064e\u0064\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0077\u0069\u0064t\u0068\u0020\u0061\u006e\u0064\u0020\u0068e\u0069\u0067\u0068\u0074");
|
|
};_befa :=_gdg (width ,height );_afea :=make ([]int ,height );_eeda :=make ([]int ,width );_dgdb :=float64 (_gdbb .Width )/float64 (width );_aadb :=float64 (_gdbb .Height )/float64 (height );for _fedd :=0;_fedd < height ;_fedd ++{_afea [_fedd ]=int (_ea .Min (_aadb *float64 (_fedd )+0.5,float64 (_gdbb .Height -1)));
|
|
};for _ccc :=0;_ccc < width ;_ccc ++{_eeda [_ccc ]=int (_ea .Min (_dgdb *float64 (_ccc )+0.5,float64 (_gdbb .Width -1)));};_cbgf :=-1;_dad :=byte (0);for _dcfd :=0;_dcfd < height ;_dcfd ++{_cbddc :=_afea [_dcfd ]*_gdbb .BytesPerLine ;_bee :=_dcfd *_befa .BytesPerLine ;
|
|
for _cbdf :=0;_cbdf < width ;_cbdf ++{_bfff :=_eeda [_cbdf ];if _bfff !=_cbgf {_dad =_gdbb .getBit (_cbddc ,_bfff );if _dad !=0{_befa .setBit (_bee ,_cbdf );};_cbgf =_bfff ;}else {if _dad !=0{_befa .setBit (_bee ,_cbdf );};};};};return _befa ,nil ;};func _bde ()(_dbga [256]uint16 ){for _fgc :=0;
|
|
_fgc < 256;_fgc ++{if _fgc &0x01!=0{_dbga [_fgc ]|=0x3;};if _fgc &0x02!=0{_dbga [_fgc ]|=0xc;};if _fgc &0x04!=0{_dbga [_fgc ]|=0x30;};if _fgc &0x08!=0{_dbga [_fgc ]|=0xc0;};if _fgc &0x10!=0{_dbga [_fgc ]|=0x300;};if _fgc &0x20!=0{_dbga [_fgc ]|=0xc00;};
|
|
if _fgc &0x40!=0{_dbga [_fgc ]|=0x3000;};if _fgc &0x80!=0{_dbga [_fgc ]|=0xc000;};};return _dbga ;};func _fcg (_dgdgd CMYK ,_aeca Gray ,_ffaa _fe .Rectangle ){for _gbce :=0;_gbce < _ffaa .Max .X ;_gbce ++{for _fgbg :=0;_fgbg < _ffaa .Max .Y ;_fgbg ++{_acce :=_fcb (_dgdgd .CMYKAt (_gbce ,_fgbg ));
|
|
_aeca .SetGray (_gbce ,_fgbg ,_acce );};};};func (_bcbb *RGBA32 )setRGBA (_gbff int ,_egdf _fc .RGBA ){_cfegb :=3*_gbff ;_bcbb .Data [_cfegb ]=_egdf .R ;_bcbb .Data [_cfegb +1]=_egdf .G ;_bcbb .Data [_cfegb +2]=_egdf .B ;if _gbff < len (_bcbb .Alpha ){_bcbb .Alpha [_gbff ]=_egdf .A ;
|
|
};};func _fdgc (_agcddc *_fe .Gray16 ,_bbdcb uint8 )*_fe .Gray {_fafg :=_agcddc .Bounds ();_dgba :=_fe .NewGray (_fafg );for _cfgaa :=0;_cfgaa < _fafg .Dx ();_cfgaa ++{for _dadab :=0;_dadab < _fafg .Dy ();_dadab ++{_acgc :=_agcddc .Gray16At (_cfgaa ,_dadab );
|
|
_dgba .SetGray (_cfgaa ,_dadab ,_fc .Gray {Y :_ecegg (uint8 (_acgc .Y /256),_bbdcb )});};};return _dgba ;};func _ecegg (_baaf ,_fceab uint8 )uint8 {if _baaf < _fceab {return 255;};return 0;};func _af (_efg ,_afa int ,_fab []byte )*Monochrome {_aa :=_gdg (_efg ,_afa );
|
|
_aa .Data =_fab ;return _aa ;};func RasterOperation (dest *Monochrome ,dx ,dy ,dw ,dh int ,op RasterOperator ,src *Monochrome ,sx ,sy int )error {return _fcde (dest ,dx ,dy ,dw ,dh ,op ,src ,sx ,sy );};func (_ccbff *Gray8 )SetGray (x ,y int ,g _fc .Gray ){_bgab :=y *_ccbff .BytesPerLine +x ;
|
|
if _bgab > len (_ccbff .Data )-1{return ;};_ccbff .Data [_bgab ]=g .Y ;};func (_bebc *ImageBase )newAlpha (){_edbe :=BytesPerLine (_bebc .Width ,_bebc .BitsPerComponent ,1);_bebc .Alpha =make ([]byte ,_bebc .Height *_edbe );};func IsPowerOf2 (n uint )bool {return n > 0&&(n &(n -1))==0};
|
|
var (_cgd =[]byte {0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,0xFF};_dedd =[]byte {0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF};);func _gbca (_ddc _fc .NRGBA64 )_fc .Gray {var _fdef _fc .NRGBA64 ;if _ddc ==_fdef {return _fc .Gray {Y :0xff};};_ddg ,_agcf ,_fbea ,_ :=_ddc .RGBA ();
|
|
_gcb :=(19595*_ddg +38470*_agcf +7471*_fbea +1<<15)>>24;return _fc .Gray {Y :uint8 (_gcb )};};var _bgff [256]uint8 ;func _eedf (_cfg _fc .Color )_fc .Color {_ggcd :=_fc .GrayModel .Convert (_cfg ).(_fc .Gray );return _bggba (_ggcd );};func (_dbbe *ImageBase )setEightBytes (_ffaab int ,_fged uint64 )error {_egg :=_dbbe .BytesPerLine -(_ffaab %_dbbe .BytesPerLine );
|
|
if _dbbe .BytesPerLine !=_dbbe .Width >>3{_egg --;};if _egg >=8{return _dbbe .setEightFullBytes (_ffaab ,_fged );};return _dbbe .setEightPartlyBytes (_ffaab ,_egg ,_fged );};func _cc (_gf *Monochrome ,_a int )(*Monochrome ,error ){if _gf ==nil {return nil ,_e .New ("\u0073o\u0075r\u0063\u0065\u0020\u006e\u006ft\u0020\u0064e\u0066\u0069\u006e\u0065\u0064");
|
|
};if _a ==1{return _gf .copy (),nil ;};if !IsPowerOf2 (uint (_a )){return nil ,_d .Errorf ("\u0070\u0072\u006fvi\u0064\u0065\u0064\u0020\u0069\u006e\u0076\u0061\u006ci\u0064 \u0065x\u0070a\u006e\u0064\u0020\u0066\u0061\u0063\u0074\u006f\u0072\u003a\u0020\u0025\u0064",_a );
|
|
};_db :=_bdc (_a );return _fa (_gf ,_a ,_db );};func ColorAtNRGBA32 (x ,y ,width int ,data ,alpha []byte ,decode []float64 )(_fc .NRGBA ,error ){_gdcdc :=y *width +x ;_agdb :=3*_gdcdc ;if _agdb +2>=len (data ){return _fc .NRGBA {},_d .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 );
|
|
};_gcca :=uint8 (0xff);if alpha !=nil &&len (alpha )> _gdcdc {_gcca =alpha [_gdcdc ];};_dagg ,_fece ,_agbb :=data [_agdb ],data [_agdb +1],data [_agdb +2];if len (decode )==6{_dagg =uint8 (uint32 (LinearInterpolate (float64 (_dagg ),0,255,decode [0],decode [1]))&0xff);
|
|
_fece =uint8 (uint32 (LinearInterpolate (float64 (_fece ),0,255,decode [2],decode [3]))&0xff);_agbb =uint8 (uint32 (LinearInterpolate (float64 (_agbb ),0,255,decode [4],decode [5]))&0xff);};return _fc .NRGBA {R :_dagg ,G :_fece ,B :_agbb ,A :_gcca },nil ;
|
|
};func _cgaca (_bdeg _fe .Image )(Image ,error ){if _dcbe ,_dbcf :=_bdeg .(*NRGBA16 );_dbcf {return _dcbe .Copy (),nil ;};_deea :=_bdeg .Bounds ();_aeeg ,_bbef :=NewImage (_deea .Max .X ,_deea .Max .Y ,4,3,nil ,nil ,nil );if _bbef !=nil {return nil ,_bbef ;
|
|
};_gbeb (_bdeg ,_aeeg ,_deea );return _aeeg ,nil ;};type ColorConverter interface{Convert (_aed _fe .Image )(Image ,error );};func (_cabd *NRGBA16 )ColorModel ()_fc .Model {return NRGBA16Model };func _fabc (_cgbf _fe .Image )(Image ,error ){if _ecae ,_ace :=_cgbf .(*Gray16 );
|
|
_ace {return _ecae .Copy (),nil ;};_eafe :=_cgbf .Bounds ();_eeec ,_bfa :=NewImage (_eafe .Max .X ,_eafe .Max .Y ,16,1,nil ,nil ,nil );if _bfa !=nil {return nil ,_bfa ;};_acdg (_cgbf ,_eeec ,_eafe );return _eeec ,nil ;};func _afe (_aecd _fe .Image )(Image ,error ){if _acga ,_gaec :=_aecd .(*Monochrome );
|
|
_gaec {return _acga ,nil ;};_bcea :=_aecd .Bounds ();var _aefb Gray ;switch _adga :=_aecd .(type ){case Gray :_aefb =_adga ;case NRGBA :_aefb =&Gray8 {ImageBase :NewImageBase (_bcea .Max .X ,_bcea .Max .Y ,8,1,nil ,nil ,nil )};_gcee (_aefb ,_adga ,_bcea );
|
|
case nrgba64 :_aefb =&Gray8 {ImageBase :NewImageBase (_bcea .Max .X ,_bcea .Max .Y ,8,1,nil ,nil ,nil )};_efd (_aefb ,_adga ,_bcea );default:_aac ,_bbgb :=GrayConverter .Convert (_aecd );if _bbgb !=nil {return nil ,_bbgb ;};_aefb =_aac .(Gray );};_eeg ,_cdad :=NewImage (_bcea .Max .X ,_bcea .Max .Y ,1,1,nil ,nil ,nil );
|
|
if _cdad !=nil {return nil ,_cdad ;};_accc :=_eeg .(*Monochrome );_edce :=AutoThresholdTriangle (GrayHistogram (_aefb ));for _fed :=0;_fed < _bcea .Max .X ;_fed ++{for _cgg :=0;_cgg < _bcea .Max .Y ;_cgg ++{_edee :=_eecg (_aefb .GrayAt (_fed ,_cgg ),monochromeModel (_edce ));
|
|
_accc .SetGray (_fed ,_cgg ,_edee );};};return _eeg ,nil ;};func (_fgd *NRGBA64 )ColorAt (x ,y int )(_fc .Color ,error ){return ColorAtNRGBA64 (x ,y ,_fgd .Width ,_fgd .Data ,_fgd .Alpha ,_fgd .Decode );};var _ _fe .Image =&Gray2 {};func _aggb (_eged RGBA ,_fgba NRGBA ,_eeee _fe .Rectangle ){for _gcgde :=0;
|
|
_gcgde < _eeee .Max .X ;_gcgde ++{for _baga :=0;_baga < _eeee .Max .Y ;_baga ++{_aegbd :=_eged .RGBAAt (_gcgde ,_baga );_fgba .SetNRGBA (_gcgde ,_baga ,_ccde (_aegbd ));};};};func _bggba (_bgce _fc .Gray )_fc .Gray {_bgce .Y >>=4;_bgce .Y |=_bgce .Y <<4;
|
|
return _bgce };func _edda (_gdcc _fc .CMYK )_fc .RGBA {_abef ,_ecf ,_gaeb :=_fc .CMYKToRGB (_gdcc .C ,_gdcc .M ,_gdcc .Y ,_gdcc .K );return _fc .RGBA {R :_abef ,G :_ecf ,B :_gaeb ,A :0xff};};func _degce (_aba NRGBA ,_cfece CMYK ,_edb _fe .Rectangle ){for _bce :=0;
|
|
_bce < _edb .Max .X ;_bce ++{for _gedc :=0;_gedc < _edb .Max .Y ;_gedc ++{_ebg :=_aba .NRGBAAt (_bce ,_gedc );_cfece .SetCMYK (_bce ,_gedc ,_gbg (_ebg ));};};};var _ NRGBA =&NRGBA32 {};func (_cdcf *NRGBA16 )Copy ()Image {return &NRGBA16 {ImageBase :_cdcf .copy ()}};
|
|
func _ddbe (_dbgaa _fc .CMYK )_fc .NRGBA {_dbf ,_adc ,_gbaf :=_fc .CMYKToRGB (_dbgaa .C ,_dbgaa .M ,_dbgaa .Y ,_dbgaa .K );return _fc .NRGBA {R :_dbf ,G :_adc ,B :_gbaf ,A :0xff};};func _ce (_df ,_ccf *Monochrome )(_edc error ){_cec :=_ccf .BytesPerLine ;
|
|
_dfa :=_df .BytesPerLine ;var (_feg byte ;_dcb uint16 ;_fad ,_cda ,_ef ,_de ,_dbg int ;);for _ef =0;_ef < _ccf .Height ;_ef ++{_fad =_ef *_cec ;_cda =2*_ef *_dfa ;for _de =0;_de < _cec ;_de ++{_feg =_ccf .Data [_fad +_de ];_dcb =_gffc [_feg ];_dbg =_cda +_de *2;
|
|
if _df .BytesPerLine !=_ccf .BytesPerLine *2&&(_de +1)*2> _df .BytesPerLine {_edc =_df .setByte (_dbg ,byte (_dcb >>8));}else {_edc =_df .setTwoBytes (_dbg ,_dcb );};if _edc !=nil {return _edc ;};};for _de =0;_de < _dfa ;_de ++{_dbg =_cda +_dfa +_de ;_feg =_df .Data [_cda +_de ];
|
|
if _edc =_df .setByte (_dbg ,_feg );_edc !=nil {return _edc ;};};};return nil ;};func (_dbfd *Gray16 )Validate ()error {if len (_dbfd .Data )!=_dbfd .Height *_dbfd .BytesPerLine {return ErrInvalidImage ;};return nil ;};type ImageBase struct{Width ,Height int ;
|
|
BitsPerComponent ,ColorComponents int ;Data ,Alpha []byte ;Decode []float64 ;BytesPerLine int ;};const (_cfbg shift =iota ;_agadd ;);func (_afef *Monochrome )getBitAt (_ggf ,_ecag int )bool {_ddeg :=_ecag *_afef .BytesPerLine +(_ggf >>3);_ggda :=_ggf &0x07;
|
|
_gbfb :=uint (7-_ggda );if _ddeg > len (_afef .Data )-1{return false ;};if (_afef .Data [_ddeg ]>>_gbfb )&0x01>=1{return true ;};return false ;};var _ _fe .Image =&NRGBA32 {};func _defa (_gfdb Gray ,_aecg NRGBA ,_gdef _fe .Rectangle ){for _faddb :=0;_faddb < _gdef .Max .X ;
|
|
_faddb ++{for _bedf :=0;_bedf < _gdef .Max .Y ;_bedf ++{_fede :=_gfdb .GrayAt (_faddb ,_bedf );_aecg .SetNRGBA (_faddb ,_bedf ,_cdaf (_fede ));};};};type shift int ;func _bf ()(_cdc [256]uint32 ){for _gbc :=0;_gbc < 256;_gbc ++{if _gbc &0x01!=0{_cdc [_gbc ]|=0xf;
|
|
};if _gbc &0x02!=0{_cdc [_gbc ]|=0xf0;};if _gbc &0x04!=0{_cdc [_gbc ]|=0xf00;};if _gbc &0x08!=0{_cdc [_gbc ]|=0xf000;};if _gbc &0x10!=0{_cdc [_gbc ]|=0xf0000;};if _gbc &0x20!=0{_cdc [_gbc ]|=0xf00000;};if _gbc &0x40!=0{_cdc [_gbc ]|=0xf000000;};if _gbc &0x80!=0{_cdc [_gbc ]|=0xf0000000;
|
|
};};return _cdc ;};func (_fadf *NRGBA16 )At (x ,y int )_fc .Color {_bdg ,_ :=_fadf .ColorAt (x ,y );return _bdg };func _fadd ()(_cad []byte ){_cad =make ([]byte ,256);for _cadd :=0;_cadd < 256;_cadd ++{_efbf :=byte (_cadd );_cad [_efbf ]=(_efbf &0x01)|((_efbf &0x04)>>1)|((_efbf &0x10)>>2)|((_efbf &0x40)>>3)|((_efbf &0x02)<<3)|((_efbf &0x08)<<2)|((_efbf &0x20)<<1)|(_efbf &0x80);
|
|
};return _cad ;};func (_gdaf *NRGBA16 )NRGBAAt (x ,y int )_fc .NRGBA {_faec ,_ :=ColorAtNRGBA16 (x ,y ,_gdaf .Width ,_gdaf .BytesPerLine ,_gdaf .Data ,_gdaf .Alpha ,_gdaf .Decode );return _faec ;};func (_ecdf *ImageBase )Pix ()[]byte {return _ecdf .Data };
|
|
func (_adaa *Gray16 )ColorAt (x ,y int )(_fc .Color ,error ){return ColorAtGray16BPC (x ,y ,_adaa .BytesPerLine ,_adaa .Data ,_adaa .Decode );};func (_gecg *Monochrome )Set (x ,y int ,c _fc .Color ){_aegfg :=y *_gecg .BytesPerLine +x >>3;if _aegfg > len (_gecg .Data )-1{return ;
|
|
};_cead :=_gecg .ColorModel ().Convert (c ).(_fc .Gray );_gecg .setGray (x ,_cead ,_aegfg );};func MonochromeThresholdConverter (threshold uint8 )ColorConverter {return &monochromeThresholdConverter {Threshold :threshold };};func (_cfeceb *NRGBA64 )ColorModel ()_fc .Model {return _fc .NRGBA64Model };
|
|
func AddDataPadding (width ,height ,bitsPerComponent ,colorComponents int ,data []byte )([]byte ,error ){_gfag :=BytesPerLine (width ,bitsPerComponent ,colorComponents );if _gfag ==width *colorComponents *bitsPerComponent /8{return data ,nil ;};_bfae :=width *colorComponents *bitsPerComponent ;
|
|
_ecfd :=_gfag *8;_cbfag :=8-(_ecfd -_bfae );_cgge :=_fg .NewReader (data );_ggcdb :=_gfag -1;_eacb :=make ([]byte ,_ggcdb );_fcaa :=make ([]byte ,height *_gfag );_dfdc :=_fg .NewWriterMSB (_fcaa );var _ccdf uint64 ;var _bcac error ;for _feddg :=0;_feddg < height ;
|
|
_feddg ++{_ ,_bcac =_cgge .Read (_eacb );if _bcac !=nil {return nil ,_bcac ;};_ ,_bcac =_dfdc .Write (_eacb );if _bcac !=nil {return nil ,_bcac ;};_ccdf ,_bcac =_cgge .ReadBits (byte (_cbfag ));if _bcac !=nil {return nil ,_bcac ;};_ ,_bcac =_dfdc .WriteBits (_ccdf ,_cbfag );
|
|
if _bcac !=nil {return nil ,_bcac ;};_dfdc .FinishByte ();};return _fcaa ,nil ;};type Gray8 struct{ImageBase };func (_agba *Gray4 )GrayAt (x ,y int )_fc .Gray {_fff ,_ :=ColorAtGray4BPC (x ,y ,_agba .BytesPerLine ,_agba .Data ,_agba .Decode );return _fff ;
|
|
};func _gcee (_eaea Gray ,_dde NRGBA ,_cfdc _fe .Rectangle ){for _bddb :=0;_bddb < _cfdc .Max .X ;_bddb ++{for _dbcd :=0;_dbcd < _cfdc .Max .Y ;_dbcd ++{_cedb :=_dee (_dde .NRGBAAt (_bddb ,_dbcd ));_eaea .SetGray (_bddb ,_dbcd ,_cedb );};};};func (_eecf *Gray16 )Set (x ,y int ,c _fc .Color ){_gagb :=(y *_eecf .BytesPerLine /2+x )*2;
|
|
if _gagb +1>=len (_eecf .Data ){return ;};_feec :=_fc .Gray16Model .Convert (c ).(_fc .Gray16 );_eecf .Data [_gagb ],_eecf .Data [_gagb +1]=uint8 (_feec .Y >>8),uint8 (_feec .Y &0xff);};func (_dfee *Gray2 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_dfee .Width ,Y :_dfee .Height }};
|
|
};var _ _fe .Image =&NRGBA16 {};func _eeeea (_bfba nrgba64 ,_bade RGBA ,_ffadb _fe .Rectangle ){for _dfeea :=0;_dfeea < _ffadb .Max .X ;_dfeea ++{for _dfde :=0;_dfde < _ffadb .Max .Y ;_dfde ++{_bebb :=_bfba .NRGBA64At (_dfeea ,_dfde );_bade .SetRGBA (_dfeea ,_dfde ,_bgf (_bebb ));
|
|
};};};func (_eeb monochromeModel )Convert (c _fc .Color )_fc .Color {_ecd :=_fc .GrayModel .Convert (c ).(_fc .Gray );return _eecg (_ecd ,_eeb );};func (_gage *ImageBase )copy ()ImageBase {_ceff :=*_gage ;_ceff .Data =make ([]byte ,len (_gage .Data ));
|
|
copy (_ceff .Data ,_gage .Data );return _ceff ;};func (_bgeg *Gray8 )Copy ()Image {return &Gray8 {ImageBase :_bgeg .copy ()}};func (_eeff *RGBA32 )Base ()*ImageBase {return &_eeff .ImageBase };func _bbda (_bgc ,_cff *Monochrome ,_afg []byte ,_aae int )(_cacf error ){var (_fcd ,_ece ,_ebc ,_bff ,_gda ,_cbd ,_ecb ,_gba int ;
|
|
_dfb ,_acg uint32 ;_eceg ,_abf byte ;_efb uint16 ;);_fce :=make ([]byte ,4);_dgc :=make ([]byte ,4);for _ebc =0;_ebc < _bgc .Height -1;_ebc ,_bff =_ebc +2,_bff +1{_fcd =_ebc *_bgc .BytesPerLine ;_ece =_bff *_cff .BytesPerLine ;for _gda ,_cbd =0,0;_gda < _aae ;
|
|
_gda ,_cbd =_gda +4,_cbd +1{for _ecb =0;_ecb < 4;_ecb ++{_gba =_fcd +_gda +_ecb ;if _gba <=len (_bgc .Data )-1&&_gba < _fcd +_bgc .BytesPerLine {_fce [_ecb ]=_bgc .Data [_gba ];}else {_fce [_ecb ]=0x00;};_gba =_fcd +_bgc .BytesPerLine +_gda +_ecb ;if _gba <=len (_bgc .Data )-1&&_gba < _fcd +(2*_bgc .BytesPerLine ){_dgc [_ecb ]=_bgc .Data [_gba ];
|
|
}else {_dgc [_ecb ]=0x00;};};_dfb =_b .BigEndian .Uint32 (_fce );_acg =_b .BigEndian .Uint32 (_dgc );_acg |=_dfb ;_acg |=_acg <<1;_acg &=0xaaaaaaaa;_dfb =_acg |(_acg <<7);_eceg =byte (_dfb >>24);_abf =byte ((_dfb >>8)&0xff);_gba =_ece +_cbd ;if _gba +1==len (_cff .Data )-1||_gba +1>=_ece +_cff .BytesPerLine {_cff .Data [_gba ]=_afg [_eceg ];
|
|
}else {_efb =(uint16 (_afg [_eceg ])<<8)|uint16 (_afg [_abf ]);if _cacf =_cff .setTwoBytes (_gba ,_efb );_cacf !=nil {return _d .Errorf ("s\u0065\u0074\u0074\u0069\u006e\u0067 \u0074\u0077\u006f\u0020\u0062\u0079t\u0065\u0073\u0020\u0066\u0061\u0069\u006ce\u0064\u002c\u0020\u0069\u006e\u0064\u0065\u0078\u003a\u0020%\u0064",_gba );
|
|
};_cbd ++;};};};return nil ;};func ColorAtGrayscale (x ,y ,bitsPerColor ,bytesPerLine int ,data []byte ,decode []float64 )(_fc .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 ,_d .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 _fegda (_bdbb _fe .Image )(Image ,error ){if _eedb ,_ffec :=_bdbb .(*NRGBA32 );_ffec {return _eedb .Copy (),nil ;};_gdccd ,_beab ,_dcfeg :=_bafg (_bdbb ,1);_ccefd ,_eegf :=NewImage (_gdccd .Max .X ,_gdccd .Max .Y ,8,3,nil ,_dcfeg ,nil );if _eegf !=nil {return nil ,_eegf ;
|
|
};_gbeb (_bdbb ,_ccefd ,_gdccd );if len (_dcfeg )!=0&&!_beab {if _dbcc :=_cabe (_dcfeg ,_ccefd );_dbcc !=nil {return nil ,_dbcc ;};};return _ccefd ,nil ;};func (_bfcc *RGBA32 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_bfcc .Width ,Y :_bfcc .Height }};
|
|
};func _agea (_gae _fc .NRGBA )_fc .Gray {_ceg ,_eedg ,_eae ,_ :=_gae .RGBA ();_ffab :=(19595*_ceg +38470*_eedg +7471*_eae +1<<15)>>24;return _fc .Gray {Y :uint8 (_ffab )};};func _edcb (){for _abee :=0;_abee < 256;_abee ++{_bgff [_abee ]=uint8 (_abee &0x1)+(uint8 (_abee >>1)&0x1)+(uint8 (_abee >>2)&0x1)+(uint8 (_abee >>3)&0x1)+(uint8 (_abee >>4)&0x1)+(uint8 (_abee >>5)&0x1)+(uint8 (_abee >>6)&0x1)+(uint8 (_abee >>7)&0x1);
|
|
};};type NRGBA64 struct{ImageBase };type Gray2 struct{ImageBase };func (_aeag *Gray4 )ColorAt (x ,y int )(_fc .Color ,error ){return ColorAtGray4BPC (x ,y ,_aeag .BytesPerLine ,_aeag .Data ,_aeag .Decode );};func (_abeec *ImageBase )setFourBytes (_gbgd int ,_bbcf uint32 )error {if _gbgd +3> len (_abeec .Data )-1{return _d .Errorf ("\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",_gbgd );
|
|
};_abeec .Data [_gbgd ]=byte ((_bbcf &0xff000000)>>24);_abeec .Data [_gbgd +1]=byte ((_bbcf &0xff0000)>>16);_abeec .Data [_gbgd +2]=byte ((_bbcf &0xff00)>>8);_abeec .Data [_gbgd +3]=byte (_bbcf &0xff);return nil ;};func ColorAtGray2BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_fc .Gray ,error ){_aadfd :=y *bytesPerLine +x >>2;
|
|
if _aadfd >=len (data ){return _fc .Gray {},_d .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 );
|
|
};_acge :=data [_aadfd ]>>uint (6-(x &3)*2)&3;if len (decode )==2{_acge =uint8 (uint32 (LinearInterpolate (float64 (_acge ),0,3.0,decode [0],decode [1]))&3);};return _fc .Gray {Y :_acge *85},nil ;};func (_ggdd colorConverter )Convert (src _fe .Image )(Image ,error ){return _ggdd ._aedd (src )};
|
|
func (_egcag *RGBA32 )Validate ()error {if len (_egcag .Data )!=3*_egcag .Width *_egcag .Height {return _e .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 (_eacc *NRGBA32 )Set (x ,y int ,c _fc .Color ){_effd :=y *_eacc .Width +x ;_cgda :=3*_effd ;if _cgda +2>=len (_eacc .Data ){return ;};_cdace :=_fc .NRGBAModel .Convert (c ).(_fc .NRGBA );_eacc .setRGBA (_effd ,_cdace );};var _ Image =&NRGBA64 {};
|
|
func _dgdc (_fbf _fe .Image )(Image ,error ){if _ddegb ,_gaaa :=_fbf .(*Gray2 );_gaaa {return _ddegb .Copy (),nil ;};_gbe :=_fbf .Bounds ();_eagg ,_fdeb :=NewImage (_gbe .Max .X ,_gbe .Max .Y ,2,1,nil ,nil ,nil );if _fdeb !=nil {return nil ,_fdeb ;};_acdg (_fbf ,_eagg ,_gbe );
|
|
return _eagg ,nil ;};func BytesPerLine (width ,bitsPerComponent ,colorComponents int )int {return ((width *bitsPerComponent )*colorComponents +7)>>3;};func _gbeb (_dgbg _fe .Image ,_fggg Image ,_dcdaa _fe .Rectangle ){if _cbc ,_bacg :=_dgbg .(SMasker );
|
|
_bacg &&_cbc .HasAlpha (){_fggg .(SMasker ).MakeAlpha ();};switch _edgb :=_dgbg .(type ){case Gray :_defa (_edgb ,_fggg .(NRGBA ),_dcdaa );case NRGBA :_ggdb (_edgb ,_fggg .(NRGBA ),_dcdaa );case *_fe .NYCbCrA :_ggebf (_edgb ,_fggg .(NRGBA ),_dcdaa );case CMYK :_afeaa (_edgb ,_fggg .(NRGBA ),_dcdaa );
|
|
case RGBA :_aggb (_edgb ,_fggg .(NRGBA ),_dcdaa );case nrgba64 :_cdcb (_edgb ,_fggg .(NRGBA ),_dcdaa );default:_gdce (_dgbg ,_fggg ,_dcdaa );};};func _bab (_fdfd *Monochrome ,_bgfe ,_cddd int ,_bfed ,_cdag int ,_cfcf RasterOperator ){var (_fagf int ;_cfb byte ;
|
|
_cbga ,_eebc int ;_ebgcb int ;);_ddde :=_bfed >>3;_ccff :=_bfed &7;if _ccff > 0{_cfb =_cgd [_ccff ];};_fagf =_fdfd .BytesPerLine *_cddd +(_bgfe >>3);switch _cfcf {case PixClr :for _cbga =0;_cbga < _cdag ;_cbga ++{_ebgcb =_fagf +_cbga *_fdfd .BytesPerLine ;
|
|
for _eebc =0;_eebc < _ddde ;_eebc ++{_fdfd .Data [_ebgcb ]=0x0;_ebgcb ++;};if _ccff > 0{_fdfd .Data [_ebgcb ]=_ebaa (_fdfd .Data [_ebgcb ],0x0,_cfb );};};case PixSet :for _cbga =0;_cbga < _cdag ;_cbga ++{_ebgcb =_fagf +_cbga *_fdfd .BytesPerLine ;for _eebc =0;
|
|
_eebc < _ddde ;_eebc ++{_fdfd .Data [_ebgcb ]=0xff;_ebgcb ++;};if _ccff > 0{_fdfd .Data [_ebgcb ]=_ebaa (_fdfd .Data [_ebgcb ],0xff,_cfb );};};case PixNotDst :for _cbga =0;_cbga < _cdag ;_cbga ++{_ebgcb =_fagf +_cbga *_fdfd .BytesPerLine ;for _eebc =0;
|
|
_eebc < _ddde ;_eebc ++{_fdfd .Data [_ebgcb ]=^_fdfd .Data [_ebgcb ];_ebgcb ++;};if _ccff > 0{_fdfd .Data [_ebgcb ]=_ebaa (_fdfd .Data [_ebgcb ],^_fdfd .Data [_ebgcb ],_cfb );};};};};func GrayHistogram (g Gray )(_affe [256]int ){switch _afeb :=g .(type ){case Histogramer :return _afeb .Histogram ();
|
|
case _fe .Image :_fdfc :=_afeb .Bounds ();for _caaa :=0;_caaa < _fdfc .Max .X ;_caaa ++{for _bded :=0;_bded < _fdfc .Max .Y ;_bded ++{_affe [g .GrayAt (_caaa ,_bded ).Y ]++;};};return _affe ;default:return [256]int {};};};func _gcgf (_aeaa *Monochrome ,_bfee ,_ddgb ,_dgcc ,_afcgd int ,_cfga RasterOperator ){if _bfee < 0{_dgcc +=_bfee ;
|
|
_bfee =0;};_gfec :=_bfee +_dgcc -_aeaa .Width ;if _gfec > 0{_dgcc -=_gfec ;};if _ddgb < 0{_afcgd +=_ddgb ;_ddgb =0;};_bgfg :=_ddgb +_afcgd -_aeaa .Height ;if _bgfg > 0{_afcgd -=_bgfg ;};if _dgcc <=0||_afcgd <=0{return ;};if (_bfee &7)==0{_bab (_aeaa ,_bfee ,_ddgb ,_dgcc ,_afcgd ,_cfga );
|
|
}else {_cbec (_aeaa ,_bfee ,_ddgb ,_dgcc ,_afcgd ,_cfga );};};func _aad (_gag _fc .RGBA )_fc .Gray {_ggea :=(19595*uint32 (_gag .R )+38470*uint32 (_gag .G )+7471*uint32 (_gag .B )+1<<7)>>16;return _fc .Gray {Y :uint8 (_ggea )};};func _dfffa (_gfagb NRGBA ,_geab RGBA ,_eebd _fe .Rectangle ){for _ggab :=0;
|
|
_ggab < _eebd .Max .X ;_ggab ++{for _agee :=0;_agee < _eebd .Max .Y ;_agee ++{_faafcb :=_gfagb .NRGBAAt (_ggab ,_agee );_geab .SetRGBA (_ggab ,_agee ,_cdac (_faafcb ));};};};func _gcge (_gcgg _fe .Image )(Image ,error ){if _gffce ,_bggf :=_gcgg .(*RGBA32 );
|
|
_bggf {return _gffce .Copy (),nil ;};_gbdd ,_bfebb ,_abbda :=_bafg (_gcgg ,1);_cbbe :=&RGBA32 {ImageBase :NewImageBase (_gbdd .Max .X ,_gbdd .Max .Y ,8,3,nil ,_abbda ,nil )};_egbdg (_gcgg ,_cbbe ,_gbdd );if len (_abbda )!=0&&!_bfebb {if _adce :=_cabe (_abbda ,_cbbe );
|
|
_adce !=nil {return nil ,_adce ;};};return _cbbe ,nil ;};func LinearInterpolate (x ,xmin ,xmax ,ymin ,ymax float64 )float64 {if _ea .Abs (xmax -xmin )< 0.000001{return ymin ;};_dfff :=ymin +(x -xmin )*(ymax -ymin )/(xmax -xmin );return _dfff ;};func _aab (_ccef uint )uint {var _fbegf uint ;
|
|
for _ccef !=0{_ccef >>=1;_fbegf ++;};return _fbegf -1;};func (_caga *RGBA32 )SetRGBA (x ,y int ,c _fc .RGBA ){_egf :=y *_caga .Width +x ;_bccb :=3*_egf ;if _bccb +2>=len (_caga .Data ){return ;};_caga .setRGBA (_egf ,c );};func (_ccad *RGBA32 )ColorAt (x ,y int )(_fc .Color ,error ){return ColorAtRGBA32 (x ,y ,_ccad .Width ,_ccad .Data ,_ccad .Alpha ,_ccad .Decode );
|
|
};func (_fecc *NRGBA64 )Copy ()Image {return &NRGBA64 {ImageBase :_fecc .copy ()}};func (_caca *NRGBA64 )Base ()*ImageBase {return &_caca .ImageBase };func (_cbac *Gray4 )ColorModel ()_fc .Model {return Gray4Model };func (_dec *ImageBase )GetAlpha ()[]byte {return _dec .Alpha };
|
|
func (_fdbc *ImageBase )HasAlpha ()bool {if _fdbc .Alpha ==nil {return false ;};for _fbeb :=range _fdbc .Alpha {if _fdbc .Alpha [_fbeb ]!=0xff{return true ;};};return false ;};func _egbdg (_ffga _fe .Image ,_ebcf Image ,_feccd _fe .Rectangle ){if _faafc ,_fggab :=_ffga .(SMasker );
|
|
_fggab &&_faafc .HasAlpha (){_ebcf .(SMasker ).MakeAlpha ();};switch _fada :=_ffga .(type ){case Gray :_deac (_fada ,_ebcf .(RGBA ),_feccd );case NRGBA :_dfffa (_fada ,_ebcf .(RGBA ),_feccd );case *_fe .NYCbCrA :_aacg (_fada ,_ebcf .(RGBA ),_feccd );case CMYK :_daca (_fada ,_ebcf .(RGBA ),_feccd );
|
|
case RGBA :_eabb (_fada ,_ebcf .(RGBA ),_feccd );case nrgba64 :_eeeea (_fada ,_ebcf .(RGBA ),_feccd );default:_gdce (_ffga ,_ebcf ,_feccd );};};func (_abbd *NRGBA32 )Copy ()Image {return &NRGBA32 {ImageBase :_abbd .copy ()}};func _cgea (_eeabg _fc .Color )_fc .Color {_dfcc :=_fc .NRGBAModel .Convert (_eeabg ).(_fc .NRGBA );
|
|
return _gdgca (_dfcc );};func _aea ()(_dgd [256]uint64 ){for _dega :=0;_dega < 256;_dega ++{if _dega &0x01!=0{_dgd [_dega ]|=0xff;};if _dega &0x02!=0{_dgd [_dega ]|=0xff00;};if _dega &0x04!=0{_dgd [_dega ]|=0xff0000;};if _dega &0x08!=0{_dgd [_dega ]|=0xff000000;
|
|
};if _dega &0x10!=0{_dgd [_dega ]|=0xff00000000;};if _dega &0x20!=0{_dgd [_dega ]|=0xff0000000000;};if _dega &0x40!=0{_dgd [_dega ]|=0xff000000000000;};if _dega &0x80!=0{_dgd [_dega ]|=0xff00000000000000;};};return _dgd ;};var _ Image =&CMYK32 {};func (_afd *Monochrome )InverseData ()error {return _afd .RasterOperation (0,0,_afd .Width ,_afd .Height ,PixNotDst ,nil ,0,0);
|
|
};var (_gffc =_bde ();_egc =_bf ();_ege =_aea (););func (_ebbb *Gray8 )Set (x ,y int ,c _fc .Color ){_gcdfe :=y *_ebbb .BytesPerLine +x ;if _gcdfe > len (_ebbb .Data )-1{return ;};_cdacg :=_fc .GrayModel .Convert (c );_ebbb .Data [_gcdfe ]=_cdacg .(_fc .Gray ).Y ;
|
|
};func _eecdg (_agcg *Monochrome ,_ddf ,_bffc ,_cggcd ,_gbga int ,_gcba RasterOperator ,_egbc *Monochrome ,_ebgc ,_bba int )error {var (_aegfb bool ;_cdeb bool ;_gcac int ;_ggeaf int ;_gdbf int ;_bdcc bool ;_gagbf byte ;_aace int ;_abffe int ;_dbgd int ;
|
|
_bgfd ,_gdcd int ;);_efe :=8-(_ddf &7);_bddc :=_dedd [_efe ];_cafc :=_agcg .BytesPerLine *_bffc +(_ddf >>3);_cfae :=_egbc .BytesPerLine *_bba +(_ebgc >>3);if _cggcd < _efe {_aegfb =true ;_bddc &=_cgd [8-_efe +_cggcd ];};if !_aegfb {_gcac =(_cggcd -_efe )>>3;
|
|
if _gcac > 0{_cdeb =true ;_ggeaf =_cafc +1;_gdbf =_cfae +1;};};_aace =(_ddf +_cggcd )&7;if !(_aegfb ||_aace ==0){_bdcc =true ;_gagbf =_cgd [_aace ];_abffe =_cafc +1+_gcac ;_dbgd =_cfae +1+_gcac ;};switch _gcba {case PixSrc :for _bgfd =0;_bgfd < _gbga ;
|
|
_bgfd ++{_agcg .Data [_cafc ]=_ebaa (_agcg .Data [_cafc ],_egbc .Data [_cfae ],_bddc );_cafc +=_agcg .BytesPerLine ;_cfae +=_egbc .BytesPerLine ;};if _cdeb {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{for _gdcd =0;_gdcd < _gcac ;_gdcd ++{_agcg .Data [_ggeaf +_gdcd ]=_egbc .Data [_gdbf +_gdcd ];
|
|
};_ggeaf +=_agcg .BytesPerLine ;_gdbf +=_egbc .BytesPerLine ;};};if _bdcc {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_abffe ]=_ebaa (_agcg .Data [_abffe ],_egbc .Data [_dbgd ],_gagbf );_abffe +=_agcg .BytesPerLine ;_dbgd +=_egbc .BytesPerLine ;
|
|
};};case PixNotSrc :for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_cafc ]=_ebaa (_agcg .Data [_cafc ],^_egbc .Data [_cfae ],_bddc );_cafc +=_agcg .BytesPerLine ;_cfae +=_egbc .BytesPerLine ;};if _cdeb {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{for _gdcd =0;
|
|
_gdcd < _gcac ;_gdcd ++{_agcg .Data [_ggeaf +_gdcd ]=^_egbc .Data [_gdbf +_gdcd ];};_ggeaf +=_agcg .BytesPerLine ;_gdbf +=_egbc .BytesPerLine ;};};if _bdcc {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_abffe ]=_ebaa (_agcg .Data [_abffe ],^_egbc .Data [_dbgd ],_gagbf );
|
|
_abffe +=_agcg .BytesPerLine ;_dbgd +=_egbc .BytesPerLine ;};};case PixSrcOrDst :for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_cafc ]=_ebaa (_agcg .Data [_cafc ],_egbc .Data [_cfae ]|_agcg .Data [_cafc ],_bddc );_cafc +=_agcg .BytesPerLine ;_cfae +=_egbc .BytesPerLine ;
|
|
};if _cdeb {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{for _gdcd =0;_gdcd < _gcac ;_gdcd ++{_agcg .Data [_ggeaf +_gdcd ]|=_egbc .Data [_gdbf +_gdcd ];};_ggeaf +=_agcg .BytesPerLine ;_gdbf +=_egbc .BytesPerLine ;};};if _bdcc {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_abffe ]=_ebaa (_agcg .Data [_abffe ],_egbc .Data [_dbgd ]|_agcg .Data [_abffe ],_gagbf );
|
|
_abffe +=_agcg .BytesPerLine ;_dbgd +=_egbc .BytesPerLine ;};};case PixSrcAndDst :for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_cafc ]=_ebaa (_agcg .Data [_cafc ],_egbc .Data [_cfae ]&_agcg .Data [_cafc ],_bddc );_cafc +=_agcg .BytesPerLine ;_cfae +=_egbc .BytesPerLine ;
|
|
};if _cdeb {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{for _gdcd =0;_gdcd < _gcac ;_gdcd ++{_agcg .Data [_ggeaf +_gdcd ]&=_egbc .Data [_gdbf +_gdcd ];};_ggeaf +=_agcg .BytesPerLine ;_gdbf +=_egbc .BytesPerLine ;};};if _bdcc {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_abffe ]=_ebaa (_agcg .Data [_abffe ],_egbc .Data [_dbgd ]&_agcg .Data [_abffe ],_gagbf );
|
|
_abffe +=_agcg .BytesPerLine ;_dbgd +=_egbc .BytesPerLine ;};};case PixSrcXorDst :for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_cafc ]=_ebaa (_agcg .Data [_cafc ],_egbc .Data [_cfae ]^_agcg .Data [_cafc ],_bddc );_cafc +=_agcg .BytesPerLine ;_cfae +=_egbc .BytesPerLine ;
|
|
};if _cdeb {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{for _gdcd =0;_gdcd < _gcac ;_gdcd ++{_agcg .Data [_ggeaf +_gdcd ]^=_egbc .Data [_gdbf +_gdcd ];};_ggeaf +=_agcg .BytesPerLine ;_gdbf +=_egbc .BytesPerLine ;};};if _bdcc {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_abffe ]=_ebaa (_agcg .Data [_abffe ],_egbc .Data [_dbgd ]^_agcg .Data [_abffe ],_gagbf );
|
|
_abffe +=_agcg .BytesPerLine ;_dbgd +=_egbc .BytesPerLine ;};};case PixNotSrcOrDst :for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_cafc ]=_ebaa (_agcg .Data [_cafc ],^(_egbc .Data [_cfae ])|_agcg .Data [_cafc ],_bddc );_cafc +=_agcg .BytesPerLine ;
|
|
_cfae +=_egbc .BytesPerLine ;};if _cdeb {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{for _gdcd =0;_gdcd < _gcac ;_gdcd ++{_agcg .Data [_ggeaf +_gdcd ]|=^(_egbc .Data [_gdbf +_gdcd ]);};_ggeaf +=_agcg .BytesPerLine ;_gdbf +=_egbc .BytesPerLine ;};};if _bdcc {for _bgfd =0;
|
|
_bgfd < _gbga ;_bgfd ++{_agcg .Data [_abffe ]=_ebaa (_agcg .Data [_abffe ],^(_egbc .Data [_dbgd ])|_agcg .Data [_abffe ],_gagbf );_abffe +=_agcg .BytesPerLine ;_dbgd +=_egbc .BytesPerLine ;};};case PixNotSrcAndDst :for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_cafc ]=_ebaa (_agcg .Data [_cafc ],^(_egbc .Data [_cfae ])&_agcg .Data [_cafc ],_bddc );
|
|
_cafc +=_agcg .BytesPerLine ;_cfae +=_egbc .BytesPerLine ;};if _cdeb {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{for _gdcd =0;_gdcd < _gcac ;_gdcd ++{_agcg .Data [_ggeaf +_gdcd ]&=^_egbc .Data [_gdbf +_gdcd ];};_ggeaf +=_agcg .BytesPerLine ;_gdbf +=_egbc .BytesPerLine ;
|
|
};};if _bdcc {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_abffe ]=_ebaa (_agcg .Data [_abffe ],^(_egbc .Data [_dbgd ])&_agcg .Data [_abffe ],_gagbf );_abffe +=_agcg .BytesPerLine ;_dbgd +=_egbc .BytesPerLine ;};};case PixSrcOrNotDst :for _bgfd =0;
|
|
_bgfd < _gbga ;_bgfd ++{_agcg .Data [_cafc ]=_ebaa (_agcg .Data [_cafc ],_egbc .Data [_cfae ]|^(_agcg .Data [_cafc ]),_bddc );_cafc +=_agcg .BytesPerLine ;_cfae +=_egbc .BytesPerLine ;};if _cdeb {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{for _gdcd =0;_gdcd < _gcac ;
|
|
_gdcd ++{_agcg .Data [_ggeaf +_gdcd ]=_egbc .Data [_gdbf +_gdcd ]|^(_agcg .Data [_ggeaf +_gdcd ]);};_ggeaf +=_agcg .BytesPerLine ;_gdbf +=_egbc .BytesPerLine ;};};if _bdcc {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_abffe ]=_ebaa (_agcg .Data [_abffe ],_egbc .Data [_dbgd ]|^(_agcg .Data [_abffe ]),_gagbf );
|
|
_abffe +=_agcg .BytesPerLine ;_dbgd +=_egbc .BytesPerLine ;};};case PixSrcAndNotDst :for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_cafc ]=_ebaa (_agcg .Data [_cafc ],_egbc .Data [_cfae ]&^(_agcg .Data [_cafc ]),_bddc );_cafc +=_agcg .BytesPerLine ;
|
|
_cfae +=_egbc .BytesPerLine ;};if _cdeb {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{for _gdcd =0;_gdcd < _gcac ;_gdcd ++{_agcg .Data [_ggeaf +_gdcd ]=_egbc .Data [_gdbf +_gdcd ]&^(_agcg .Data [_ggeaf +_gdcd ]);};_ggeaf +=_agcg .BytesPerLine ;_gdbf +=_egbc .BytesPerLine ;
|
|
};};if _bdcc {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_abffe ]=_ebaa (_agcg .Data [_abffe ],_egbc .Data [_dbgd ]&^(_agcg .Data [_abffe ]),_gagbf );_abffe +=_agcg .BytesPerLine ;_dbgd +=_egbc .BytesPerLine ;};};case PixNotPixSrcOrDst :for _bgfd =0;
|
|
_bgfd < _gbga ;_bgfd ++{_agcg .Data [_cafc ]=_ebaa (_agcg .Data [_cafc ],^(_egbc .Data [_cfae ]|_agcg .Data [_cafc ]),_bddc );_cafc +=_agcg .BytesPerLine ;_cfae +=_egbc .BytesPerLine ;};if _cdeb {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{for _gdcd =0;_gdcd < _gcac ;
|
|
_gdcd ++{_agcg .Data [_ggeaf +_gdcd ]=^(_egbc .Data [_gdbf +_gdcd ]|_agcg .Data [_ggeaf +_gdcd ]);};_ggeaf +=_agcg .BytesPerLine ;_gdbf +=_egbc .BytesPerLine ;};};if _bdcc {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_abffe ]=_ebaa (_agcg .Data [_abffe ],^(_egbc .Data [_dbgd ]|_agcg .Data [_abffe ]),_gagbf );
|
|
_abffe +=_agcg .BytesPerLine ;_dbgd +=_egbc .BytesPerLine ;};};case PixNotPixSrcAndDst :for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_cafc ]=_ebaa (_agcg .Data [_cafc ],^(_egbc .Data [_cfae ]&_agcg .Data [_cafc ]),_bddc );_cafc +=_agcg .BytesPerLine ;
|
|
_cfae +=_egbc .BytesPerLine ;};if _cdeb {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{for _gdcd =0;_gdcd < _gcac ;_gdcd ++{_agcg .Data [_ggeaf +_gdcd ]=^(_egbc .Data [_gdbf +_gdcd ]&_agcg .Data [_ggeaf +_gdcd ]);};_ggeaf +=_agcg .BytesPerLine ;_gdbf +=_egbc .BytesPerLine ;
|
|
};};if _bdcc {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_abffe ]=_ebaa (_agcg .Data [_abffe ],^(_egbc .Data [_dbgd ]&_agcg .Data [_abffe ]),_gagbf );_abffe +=_agcg .BytesPerLine ;_dbgd +=_egbc .BytesPerLine ;};};case PixNotPixSrcXorDst :for _bgfd =0;
|
|
_bgfd < _gbga ;_bgfd ++{_agcg .Data [_cafc ]=_ebaa (_agcg .Data [_cafc ],^(_egbc .Data [_cfae ]^_agcg .Data [_cafc ]),_bddc );_cafc +=_agcg .BytesPerLine ;_cfae +=_egbc .BytesPerLine ;};if _cdeb {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{for _gdcd =0;_gdcd < _gcac ;
|
|
_gdcd ++{_agcg .Data [_ggeaf +_gdcd ]=^(_egbc .Data [_gdbf +_gdcd ]^_agcg .Data [_ggeaf +_gdcd ]);};_ggeaf +=_agcg .BytesPerLine ;_gdbf +=_egbc .BytesPerLine ;};};if _bdcc {for _bgfd =0;_bgfd < _gbga ;_bgfd ++{_agcg .Data [_abffe ]=_ebaa (_agcg .Data [_abffe ],^(_egbc .Data [_dbgd ]^_agcg .Data [_abffe ]),_gagbf );
|
|
_abffe +=_agcg .BytesPerLine ;_dbgd +=_egbc .BytesPerLine ;};};default:_ba .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u0072\u0061\u0073\u0074\u0065\u0072\u0020\u006f\u0070e\u0072\u0061\u0074o\u0072:\u0020\u0025\u0064",_gcba );return _e .New ("\u0069\u006e\u0076al\u0069\u0064\u0020\u0072\u0061\u0073\u0074\u0065\u0072\u0020\u006f\u0070\u0065\u0072\u0061\u0074\u006f\u0072");
|
|
};return nil ;};var _ Image =&Gray8 {};func _cgc (_bbdb *Monochrome ,_dff int ,_badf []byte )(_gde *Monochrome ,_ff error ){const _dgac ="\u0072\u0065d\u0075\u0063\u0065R\u0061\u006e\u006b\u0042\u0069\u006e\u0061\u0072\u0079";if _bbdb ==nil {return nil ,_e .New ("\u0073o\u0075\u0072\u0063\u0065 \u0062\u0069\u0074\u006d\u0061p\u0020n\u006ft\u0020\u0064\u0065\u0066\u0069\u006e\u0065d");
|
|
};if _dff < 1||_dff > 4{return nil ,_e .New ("\u006c\u0065\u0076\u0065\u006c\u0020\u006d\u0075\u0073\u0074 \u0062\u0065\u0020\u0069\u006e\u0020\u0073e\u0074\u0020\u007b\u0031\u002c\u0032\u002c\u0033\u002c\u0034\u007d");};if _bbdb .Height <=1{return nil ,_e .New ("\u0073\u006f\u0075rc\u0065\u0020\u0068\u0065\u0069\u0067\u0068\u0074\u0020m\u0075s\u0074 \u0062e\u0020\u0061\u0074\u0020\u006c\u0065\u0061\u0073\u0074\u0020\u0027\u0032\u0027");
|
|
};_gde =_gdg (_bbdb .Width /2,_bbdb .Height /2);if _badf ==nil {_badf =_fadd ();};_aef :=_defd (_bbdb .BytesPerLine ,2*_gde .BytesPerLine );switch _dff {case 1:_ff =_bbda (_bbdb ,_gde ,_badf ,_aef );case 2:_ff =_cca (_bbdb ,_gde ,_badf ,_aef );case 3:_ff =_cdaa (_bbdb ,_gde ,_badf ,_aef );
|
|
case 4:_ff =_bfb (_bbdb ,_gde ,_badf ,_aef );};if _ff !=nil {return nil ,_ff ;};return _gde ,nil ;};func _fbe (_age *Monochrome ,_eg ,_fge int )(*Monochrome ,error ){if _age ==nil {return nil ,_e .New ("\u0073o\u0075r\u0063\u0065\u0020\u006e\u006ft\u0020\u0064e\u0066\u0069\u006e\u0065\u0064");
|
|
};if _eg <=0||_fge <=0{return nil ,_e .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0073\u0063\u0061l\u0065\u0020\u0066\u0061\u0063\u0074\u006f\u0072\u003a\u0020<\u003d\u0020\u0030");};if _eg ==_fge {if _eg ==1{return _age .copy (),nil ;};if _eg ==2||_eg ==4||_eg ==8{_gff ,_acc :=_cc (_age ,_eg );
|
|
if _acc !=nil {return nil ,_acc ;};return _gff ,nil ;};};_gdf :=_eg *_age .Width ;_cfe :=_fge *_age .Height ;_bbd :=_gdg (_gdf ,_cfe );_fbb :=_bbd .BytesPerLine ;var (_egb ,_ge ,_eea ,_bcb ,_cef int ;_egba byte ;_bd error ;);for _ge =0;_ge < _age .Height ;
|
|
_ge ++{_egb =_fge *_ge *_fbb ;for _eea =0;_eea < _age .Width ;_eea ++{if _bccf :=_age .getBitAt (_eea ,_ge );_bccf {_cef =_eg *_eea ;for _bcb =0;_bcb < _eg ;_bcb ++{_bbd .setIndexedBit (_egb *8+_cef +_bcb );};};};for _bcb =1;_bcb < _fge ;_bcb ++{_ae :=_egb +_bcb *_fbb ;
|
|
for _gfeb :=0;_gfeb < _fbb ;_gfeb ++{if _egba ,_bd =_bbd .getByte (_egb +_gfeb );_bd !=nil {return nil ,_bd ;};if _bd =_bbd .setByte (_ae +_gfeb ,_egba );_bd !=nil {return nil ,_bd ;};};};};return _bbd ,nil ;};func (_ceeb *Gray4 )setGray (_dbaf int ,_ecef int ,_ffb _fc .Gray ){_eddd :=_ecef *_ceeb .BytesPerLine ;
|
|
_dfac :=_eddd +(_dbaf >>1);if _dfac >=len (_ceeb .Data ){return ;};_cggc :=_ffb .Y >>4;_ceeb .Data [_dfac ]=(_ceeb .Data [_dfac ]&(^(0xf0>>uint (4*(_dbaf &1)))))|(_cggc <<uint (4-4*(_dbaf &1)));};func (_dfcbb *NRGBA32 )SetNRGBA (x ,y int ,c _fc .NRGBA ){_eecee :=y *_dfcbb .Width +x ;
|
|
_fbbde :=3*_eecee ;if _fbbde +2>=len (_dfcbb .Data ){return ;};_dfcbb .setRGBA (_eecee ,c );};type colorConverter struct{_aedd func (_gefa _fe .Image )(Image ,error );};func (_agc *CMYK32 )Base ()*ImageBase {return &_agc .ImageBase };func _bdcb (_fbeg _fc .Gray )_fc .CMYK {return _fc .CMYK {K :0xff-_fbeg .Y }};
|
|
func _gbg (_bgbeg _fc .NRGBA )_fc .CMYK {_gcfg ,_bdee ,_fca ,_ :=_bgbeg .RGBA ();_eaa ,_eeae ,_ega ,_dedb :=_fc .RGBToCMYK (uint8 (_gcfg >>8),uint8 (_bdee >>8),uint8 (_fca >>8));return _fc .CMYK {C :_eaa ,M :_eeae ,Y :_ega ,K :_dedb };};func (_dbbf *ImageBase )getByte (_beef int )(byte ,error ){if _beef > len (_dbbf .Data )-1||_beef < 0{return 0,_d .Errorf ("\u0069\u006e\u0064\u0065x:\u0020\u0025\u0064\u0020\u006f\u0075\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006eg\u0065",_beef );
|
|
};return _dbbf .Data [_beef ],nil ;};type Histogramer interface{Histogram ()[256]int ;};func (_eef *Monochrome )copy ()*Monochrome {_fba :=_gdg (_eef .Width ,_eef .Height );_fba .ModelThreshold =_eef .ModelThreshold ;_fba .Data =make ([]byte ,len (_eef .Data ));
|
|
copy (_fba .Data ,_eef .Data );if len (_eef .Decode )!=0{_fba .Decode =make ([]float64 ,len (_eef .Decode ));copy (_fba .Decode ,_eef .Decode );};if len (_eef .Alpha )!=0{_fba .Alpha =make ([]byte ,len (_eef .Alpha ));copy (_fba .Alpha ,_eef .Alpha );};
|
|
return _fba ;};func ColorAtNRGBA64 (x ,y ,width int ,data ,alpha []byte ,decode []float64 )(_fc .NRGBA64 ,error ){_agcdd :=(y *width +x )*2;_debe :=_agcdd *3;if _debe +5>=len (data ){return _fc .NRGBA64 {},_d .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 _acbgd =0xffff;_agbf :=uint16 (_acbgd );if alpha !=nil &&len (alpha )> _agcdd +1{_agbf =uint16 (alpha [_agcdd ])<<8|uint16 (alpha [_agcdd +1]);};_afda :=uint16 (data [_debe ])<<8|uint16 (data [_debe +1]);_gbfac :=uint16 (data [_debe +2])<<8|uint16 (data [_debe +3]);
|
|
_eega :=uint16 (data [_debe +4])<<8|uint16 (data [_debe +5]);if len (decode )==6{_afda =uint16 (uint64 (LinearInterpolate (float64 (_afda ),0,65535,decode [0],decode [1]))&_acbgd );_gbfac =uint16 (uint64 (LinearInterpolate (float64 (_gbfac ),0,65535,decode [2],decode [3]))&_acbgd );
|
|
_eega =uint16 (uint64 (LinearInterpolate (float64 (_eega ),0,65535,decode [4],decode [5]))&_acbgd );};return _fc .NRGBA64 {R :_afda ,G :_gbfac ,B :_eega ,A :_agbf },nil ;};func _cbec (_bdef *Monochrome ,_beec ,_bea int ,_bbea ,_cafa int ,_abb RasterOperator ){var (_gbcg bool ;
|
|
_dcae bool ;_fdfde int ;_accb int ;_dcc int ;_add int ;_ceda bool ;_edbg byte ;);_gccd :=8-(_beec &7);_bbfbg :=_dedd [_gccd ];_agacg :=_bdef .BytesPerLine *_bea +(_beec >>3);if _bbea < _gccd {_gbcg =true ;_bbfbg &=_cgd [8-_gccd +_bbea ];};if !_gbcg {_fdfde =(_bbea -_gccd )>>3;
|
|
if _fdfde !=0{_dcae =true ;_accb =_agacg +1;};};_dcc =(_beec +_bbea )&7;if !(_gbcg ||_dcc ==0){_ceda =true ;_edbg =_cgd [_dcc ];_add =_agacg +1+_fdfde ;};var _bac ,_fdgbe int ;switch _abb {case PixClr :for _bac =0;_bac < _cafa ;_bac ++{_bdef .Data [_agacg ]=_ebaa (_bdef .Data [_agacg ],0x0,_bbfbg );
|
|
_agacg +=_bdef .BytesPerLine ;};if _dcae {for _bac =0;_bac < _cafa ;_bac ++{for _fdgbe =0;_fdgbe < _fdfde ;_fdgbe ++{_bdef .Data [_accb +_fdgbe ]=0x0;};_accb +=_bdef .BytesPerLine ;};};if _ceda {for _bac =0;_bac < _cafa ;_bac ++{_bdef .Data [_add ]=_ebaa (_bdef .Data [_add ],0x0,_edbg );
|
|
_add +=_bdef .BytesPerLine ;};};case PixSet :for _bac =0;_bac < _cafa ;_bac ++{_bdef .Data [_agacg ]=_ebaa (_bdef .Data [_agacg ],0xff,_bbfbg );_agacg +=_bdef .BytesPerLine ;};if _dcae {for _bac =0;_bac < _cafa ;_bac ++{for _fdgbe =0;_fdgbe < _fdfde ;_fdgbe ++{_bdef .Data [_accb +_fdgbe ]=0xff;
|
|
};_accb +=_bdef .BytesPerLine ;};};if _ceda {for _bac =0;_bac < _cafa ;_bac ++{_bdef .Data [_add ]=_ebaa (_bdef .Data [_add ],0xff,_edbg );_add +=_bdef .BytesPerLine ;};};case PixNotDst :for _bac =0;_bac < _cafa ;_bac ++{_bdef .Data [_agacg ]=_ebaa (_bdef .Data [_agacg ],^_bdef .Data [_agacg ],_bbfbg );
|
|
_agacg +=_bdef .BytesPerLine ;};if _dcae {for _bac =0;_bac < _cafa ;_bac ++{for _fdgbe =0;_fdgbe < _fdfde ;_fdgbe ++{_bdef .Data [_accb +_fdgbe ]=^(_bdef .Data [_accb +_fdgbe ]);};_accb +=_bdef .BytesPerLine ;};};if _ceda {for _bac =0;_bac < _cafa ;_bac ++{_bdef .Data [_add ]=_ebaa (_bdef .Data [_add ],^_bdef .Data [_add ],_edbg );
|
|
_add +=_bdef .BytesPerLine ;};};};};func _aead (_faed _fc .NYCbCrA )_fc .NRGBA {_bgcc :=int32 (_faed .Y )*0x10101;_gfa :=int32 (_faed .Cb )-128;_ffg :=int32 (_faed .Cr )-128;_cfd :=_bgcc +91881*_ffg ;if uint32 (_cfd )&0xff000000==0{_cfd >>=8;}else {_cfd =^(_cfd >>31)&0xffff;
|
|
};_egec :=_bgcc -22554*_gfa -46802*_ffg ;if uint32 (_egec )&0xff000000==0{_egec >>=8;}else {_egec =^(_egec >>31)&0xffff;};_gcde :=_bgcc +116130*_gfa ;if uint32 (_gcde )&0xff000000==0{_gcde >>=8;}else {_gcde =^(_gcde >>31)&0xffff;};return _fc .NRGBA {R :uint8 (_cfd >>8),G :uint8 (_egec >>8),B :uint8 (_gcde >>8),A :_faed .A };
|
|
};func _ggce (_gdacb *Monochrome ,_adfdc ,_edff ,_gafc ,_fbgd int ,_deed RasterOperator ,_cecc *Monochrome ,_edbf ,_gfg int )error {var (_geff byte ;_daef int ;_cbedb int ;_gcbg ,_dfda int ;_baac ,_caff int ;);_dbfg :=_gafc >>3;_cfdb :=_gafc &7;if _cfdb > 0{_geff =_cgd [_cfdb ];
|
|
};_daef =_cecc .BytesPerLine *_gfg +(_edbf >>3);_cbedb =_gdacb .BytesPerLine *_edff +(_adfdc >>3);switch _deed {case PixSrc :for _baac =0;_baac < _fbgd ;_baac ++{_gcbg =_daef +_baac *_cecc .BytesPerLine ;_dfda =_cbedb +_baac *_gdacb .BytesPerLine ;for _caff =0;
|
|
_caff < _dbfg ;_caff ++{_gdacb .Data [_dfda ]=_cecc .Data [_gcbg ];_dfda ++;_gcbg ++;};if _cfdb > 0{_gdacb .Data [_dfda ]=_ebaa (_gdacb .Data [_dfda ],_cecc .Data [_gcbg ],_geff );};};case PixNotSrc :for _baac =0;_baac < _fbgd ;_baac ++{_gcbg =_daef +_baac *_cecc .BytesPerLine ;
|
|
_dfda =_cbedb +_baac *_gdacb .BytesPerLine ;for _caff =0;_caff < _dbfg ;_caff ++{_gdacb .Data [_dfda ]=^(_cecc .Data [_gcbg ]);_dfda ++;_gcbg ++;};if _cfdb > 0{_gdacb .Data [_dfda ]=_ebaa (_gdacb .Data [_dfda ],^_cecc .Data [_gcbg ],_geff );};};case PixSrcOrDst :for _baac =0;
|
|
_baac < _fbgd ;_baac ++{_gcbg =_daef +_baac *_cecc .BytesPerLine ;_dfda =_cbedb +_baac *_gdacb .BytesPerLine ;for _caff =0;_caff < _dbfg ;_caff ++{_gdacb .Data [_dfda ]|=_cecc .Data [_gcbg ];_dfda ++;_gcbg ++;};if _cfdb > 0{_gdacb .Data [_dfda ]=_ebaa (_gdacb .Data [_dfda ],_cecc .Data [_gcbg ]|_gdacb .Data [_dfda ],_geff );
|
|
};};case PixSrcAndDst :for _baac =0;_baac < _fbgd ;_baac ++{_gcbg =_daef +_baac *_cecc .BytesPerLine ;_dfda =_cbedb +_baac *_gdacb .BytesPerLine ;for _caff =0;_caff < _dbfg ;_caff ++{_gdacb .Data [_dfda ]&=_cecc .Data [_gcbg ];_dfda ++;_gcbg ++;};if _cfdb > 0{_gdacb .Data [_dfda ]=_ebaa (_gdacb .Data [_dfda ],_cecc .Data [_gcbg ]&_gdacb .Data [_dfda ],_geff );
|
|
};};case PixSrcXorDst :for _baac =0;_baac < _fbgd ;_baac ++{_gcbg =_daef +_baac *_cecc .BytesPerLine ;_dfda =_cbedb +_baac *_gdacb .BytesPerLine ;for _caff =0;_caff < _dbfg ;_caff ++{_gdacb .Data [_dfda ]^=_cecc .Data [_gcbg ];_dfda ++;_gcbg ++;};if _cfdb > 0{_gdacb .Data [_dfda ]=_ebaa (_gdacb .Data [_dfda ],_cecc .Data [_gcbg ]^_gdacb .Data [_dfda ],_geff );
|
|
};};case PixNotSrcOrDst :for _baac =0;_baac < _fbgd ;_baac ++{_gcbg =_daef +_baac *_cecc .BytesPerLine ;_dfda =_cbedb +_baac *_gdacb .BytesPerLine ;for _caff =0;_caff < _dbfg ;_caff ++{_gdacb .Data [_dfda ]|=^(_cecc .Data [_gcbg ]);_dfda ++;_gcbg ++;};
|
|
if _cfdb > 0{_gdacb .Data [_dfda ]=_ebaa (_gdacb .Data [_dfda ],^(_cecc .Data [_gcbg ])|_gdacb .Data [_dfda ],_geff );};};case PixNotSrcAndDst :for _baac =0;_baac < _fbgd ;_baac ++{_gcbg =_daef +_baac *_cecc .BytesPerLine ;_dfda =_cbedb +_baac *_gdacb .BytesPerLine ;
|
|
for _caff =0;_caff < _dbfg ;_caff ++{_gdacb .Data [_dfda ]&=^(_cecc .Data [_gcbg ]);_dfda ++;_gcbg ++;};if _cfdb > 0{_gdacb .Data [_dfda ]=_ebaa (_gdacb .Data [_dfda ],^(_cecc .Data [_gcbg ])&_gdacb .Data [_dfda ],_geff );};};case PixSrcOrNotDst :for _baac =0;
|
|
_baac < _fbgd ;_baac ++{_gcbg =_daef +_baac *_cecc .BytesPerLine ;_dfda =_cbedb +_baac *_gdacb .BytesPerLine ;for _caff =0;_caff < _dbfg ;_caff ++{_gdacb .Data [_dfda ]=_cecc .Data [_gcbg ]|^(_gdacb .Data [_dfda ]);_dfda ++;_gcbg ++;};if _cfdb > 0{_gdacb .Data [_dfda ]=_ebaa (_gdacb .Data [_dfda ],_cecc .Data [_gcbg ]|^(_gdacb .Data [_dfda ]),_geff );
|
|
};};case PixSrcAndNotDst :for _baac =0;_baac < _fbgd ;_baac ++{_gcbg =_daef +_baac *_cecc .BytesPerLine ;_dfda =_cbedb +_baac *_gdacb .BytesPerLine ;for _caff =0;_caff < _dbfg ;_caff ++{_gdacb .Data [_dfda ]=_cecc .Data [_gcbg ]&^(_gdacb .Data [_dfda ]);
|
|
_dfda ++;_gcbg ++;};if _cfdb > 0{_gdacb .Data [_dfda ]=_ebaa (_gdacb .Data [_dfda ],_cecc .Data [_gcbg ]&^(_gdacb .Data [_dfda ]),_geff );};};case PixNotPixSrcOrDst :for _baac =0;_baac < _fbgd ;_baac ++{_gcbg =_daef +_baac *_cecc .BytesPerLine ;_dfda =_cbedb +_baac *_gdacb .BytesPerLine ;
|
|
for _caff =0;_caff < _dbfg ;_caff ++{_gdacb .Data [_dfda ]=^(_cecc .Data [_gcbg ]|_gdacb .Data [_dfda ]);_dfda ++;_gcbg ++;};if _cfdb > 0{_gdacb .Data [_dfda ]=_ebaa (_gdacb .Data [_dfda ],^(_cecc .Data [_gcbg ]|_gdacb .Data [_dfda ]),_geff );};};case PixNotPixSrcAndDst :for _baac =0;
|
|
_baac < _fbgd ;_baac ++{_gcbg =_daef +_baac *_cecc .BytesPerLine ;_dfda =_cbedb +_baac *_gdacb .BytesPerLine ;for _caff =0;_caff < _dbfg ;_caff ++{_gdacb .Data [_dfda ]=^(_cecc .Data [_gcbg ]&_gdacb .Data [_dfda ]);_dfda ++;_gcbg ++;};if _cfdb > 0{_gdacb .Data [_dfda ]=_ebaa (_gdacb .Data [_dfda ],^(_cecc .Data [_gcbg ]&_gdacb .Data [_dfda ]),_geff );
|
|
};};case PixNotPixSrcXorDst :for _baac =0;_baac < _fbgd ;_baac ++{_gcbg =_daef +_baac *_cecc .BytesPerLine ;_dfda =_cbedb +_baac *_gdacb .BytesPerLine ;for _caff =0;_caff < _dbfg ;_caff ++{_gdacb .Data [_dfda ]=^(_cecc .Data [_gcbg ]^_gdacb .Data [_dfda ]);
|
|
_dfda ++;_gcbg ++;};if _cfdb > 0{_gdacb .Data [_dfda ]=_ebaa (_gdacb .Data [_dfda ],^(_cecc .Data [_gcbg ]^_gdacb .Data [_dfda ]),_geff );};};default:_ba .Log .Debug ("\u0050\u0072ov\u0069\u0064\u0065d\u0020\u0069\u006e\u0076ali\u0064 r\u0061\u0073\u0074\u0065\u0072\u0020\u006fpe\u0072\u0061\u0074\u006f\u0072\u003a\u0020%\u0076",_deed );
|
|
return _e .New ("\u0069\u006e\u0076al\u0069\u0064\u0020\u0072\u0061\u0073\u0074\u0065\u0072\u0020\u006f\u0070\u0065\u0072\u0061\u0074\u006f\u0072");};return nil ;};func (_bccfe *NRGBA32 )ColorModel ()_fc .Model {return _fc .NRGBAModel };func (_agb *Monochrome )Copy ()Image {return &Monochrome {ImageBase :_agb .ImageBase .copy (),ModelThreshold :_agb .ModelThreshold };
|
|
};func (_gea *Monochrome )ReduceBinary (factor float64 )(*Monochrome ,error ){_ccbf :=_aab (uint (factor ));if !IsPowerOf2 (uint (factor )){_ccbf ++;};_bcg :=make ([]int ,_ccbf );for _gaebg :=range _bcg {_bcg [_gaebg ]=4;};_dfd ,_dfc :=_bbg (_gea ,_bcg ...);
|
|
if _dfc !=nil {return nil ,_dfc ;};return _dfd ,nil ;};func (_eebf *RGBA32 )RGBAAt (x ,y int )_fc .RGBA {_decfg ,_ :=ColorAtRGBA32 (x ,y ,_eebf .Width ,_eebf .Data ,_eebf .Alpha ,_eebf .Decode );return _decfg ;};func (_eefb *Gray4 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_eefb .Width ,Y :_eefb .Height }};
|
|
};func InDelta (expected ,current ,delta float64 )bool {_fdgb :=expected -current ;if _fdgb <=-delta ||_fdgb >=delta {return false ;};return true ;};func (_cbfe *Gray4 )Validate ()error {if len (_cbfe .Data )!=_cbfe .Height *_cbfe .BytesPerLine {return ErrInvalidImage ;
|
|
};return nil ;};func (_ccbd *Monochrome )SetGray (x ,y int ,g _fc .Gray ){_daa :=y *_ccbd .BytesPerLine +x >>3;if _daa > len (_ccbd .Data )-1{return ;};g =_eecg (g ,monochromeModel (_ccbd .ModelThreshold ));_ccbd .setGray (x ,g ,_daa );};var _ Image =&NRGBA32 {};
|
|
func _fa (_dc *Monochrome ,_bad int ,_dbc []uint )(*Monochrome ,error ){_baf :=_bad *_dc .Width ;_gd :=_bad *_dc .Height ;_cd :=_gdg (_baf ,_gd );for _dg ,_da :=range _dbc {var _dba error ;switch _da {case 2:_dba =_ce (_cd ,_dc );case 4:_dba =_ac (_cd ,_dc );
|
|
case 8:_dba =_bc (_cd ,_dc );};if _dba !=nil {return nil ,_dba ;};if _dg !=len (_dbc )-1{_dc =_cd .copy ();};};return _cd ,nil ;};func (_eecc *Gray8 )GrayAt (x ,y int )_fc .Gray {_aaa ,_ :=ColorAtGray8BPC (x ,y ,_eecc .BytesPerLine ,_eecc .Data ,_eecc .Decode );
|
|
return _aaa ;};func (_cbdd *CMYK32 )CMYKAt (x ,y int )_fc .CMYK {_fgfe ,_ :=ColorAtCMYK (x ,y ,_cbdd .Width ,_cbdd .Data ,_cbdd .Decode );return _fgfe ;};func (_cbg *CMYK32 )Validate ()error {if len (_cbg .Data )!=4*_cbg .Width *_cbg .Height {return _e .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 _ Image =&Monochrome {};func (_ddbf *Monochrome )Validate ()error {if len (_ddbf .Data )!=_ddbf .Height *_ddbf .BytesPerLine {return ErrInvalidImage ;};return nil ;};func _dee (_eaff _fc .NRGBA )_fc .Gray {var _gce _fc .NRGBA ;if _eaff ==_gce {return _fc .Gray {Y :0xff};
|
|
};_bdd ,_gge ,_egeb ,_ :=_eaff .RGBA ();_gceg :=(19595*_bdd +38470*_gge +7471*_egeb +1<<15)>>24;return _fc .Gray {Y :uint8 (_gceg )};};func (_acbf *Monochrome )setIndexedBit (_gdab int ){_acbf .Data [(_gdab >>3)]|=0x80>>uint (_gdab &7)};func (_fgga *Monochrome )GrayAt (x ,y int )_fc .Gray {_dbfc ,_ :=ColorAtGray1BPC (x ,y ,_fgga .BytesPerLine ,_fgga .Data ,_fgga .Decode );
|
|
return _dbfc ;};var _ _fe .Image =&RGBA32 {};func (_cccb *ImageBase )MakeAlpha (){_cccb .newAlpha ()};type Gray16 struct{ImageBase };func (_aeda *NRGBA32 )setRGBA (_caaf int ,_ecca _fc .NRGBA ){_feb :=3*_caaf ;_aeda .Data [_feb ]=_ecca .R ;_aeda .Data [_feb +1]=_ecca .G ;
|
|
_aeda .Data [_feb +2]=_ecca .B ;if _caaf < len (_aeda .Alpha ){_aeda .Alpha [_caaf ]=_ecca .A ;};};func _bgf (_ddgg _fc .NRGBA64 )_fc .RGBA {_gfcc ,_cee ,_cfda ,_agcfa :=_ddgg .RGBA ();return _fc .RGBA {R :uint8 (_gfcc >>8),G :uint8 (_cee >>8),B :uint8 (_cfda >>8),A :uint8 (_agcfa >>8)};
|
|
};func ColorAtRGBA32 (x ,y ,width int ,data ,alpha []byte ,decode []float64 )(_fc .RGBA ,error ){_edffc :=y *width +x ;_ddec :=3*_edffc ;if _ddec +2>=len (data ){return _fc .RGBA {},_d .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 );
|
|
};_dafd :=uint8 (0xff);if alpha !=nil &&len (alpha )> _edffc {_dafd =alpha [_edffc ];};_cbbd ,_fagce ,_fgdb :=data [_ddec ],data [_ddec +1],data [_ddec +2];if len (decode )==6{_cbbd =uint8 (uint32 (LinearInterpolate (float64 (_cbbd ),0,255,decode [0],decode [1]))&0xff);
|
|
_fagce =uint8 (uint32 (LinearInterpolate (float64 (_fagce ),0,255,decode [2],decode [3]))&0xff);_fgdb =uint8 (uint32 (LinearInterpolate (float64 (_fgdb ),0,255,decode [4],decode [5]))&0xff);};return _fc .RGBA {R :_cbbd ,G :_fagce ,B :_fgdb ,A :_dafd },nil ;
|
|
};func ImgToBinary (i _fe .Image ,threshold uint8 )*_fe .Gray {switch _dcba :=i .(type ){case *_fe .Gray :if _edfe (_dcba ){return _dcba ;};return _ffaag (_dcba ,threshold );case *_fe .Gray16 :return _fdgc (_dcba ,threshold );default:return _gdadc (_dcba ,threshold );
|
|
};};func (_abae *NRGBA16 )SetNRGBA (x ,y int ,c _fc .NRGBA ){_gcddcd :=y *_abae .BytesPerLine +x *3/2;if _gcddcd +1>=len (_abae .Data ){return ;};c =_gdgca (c );_abae .setNRGBA (x ,y ,_gcddcd ,c );};func (_gdgf *Gray16 )GrayAt (x ,y int )_fc .Gray {_bbge ,_ :=_gdgf .ColorAt (x ,y );
|
|
return _fc .Gray {Y :uint8 (_bbge .(_fc .Gray16 ).Y >>8)};};func _bfce (_bcd _fe .Image )(Image ,error ){if _daege ,_daf :=_bcd .(*Gray8 );_daf {return _daege .Copy (),nil ;};_cgaf :=_bcd .Bounds ();_fbeaa ,_ade :=NewImage (_cgaf .Max .X ,_cgaf .Max .Y ,8,1,nil ,nil ,nil );
|
|
if _ade !=nil {return nil ,_ade ;};_acdg (_bcd ,_fbeaa ,_cgaf );return _fbeaa ,nil ;};func (_gcg *Gray8 )At (x ,y int )_fc .Color {_bbfd ,_ :=_gcg .ColorAt (x ,y );return _bbfd };func (_acgeb *NRGBA64 )setNRGBA64 (_adad int ,_debag _fc .NRGBA64 ,_fegg int ){_acgeb .Data [_adad ]=uint8 (_debag .R >>8);
|
|
_acgeb .Data [_adad +1]=uint8 (_debag .R &0xff);_acgeb .Data [_adad +2]=uint8 (_debag .G >>8);_acgeb .Data [_adad +3]=uint8 (_debag .G &0xff);_acgeb .Data [_adad +4]=uint8 (_debag .B >>8);_acgeb .Data [_adad +5]=uint8 (_debag .B &0xff);if _fegg +1< len (_acgeb .Alpha ){_acgeb .Alpha [_fegg ]=uint8 (_debag .A >>8);
|
|
_acgeb .Alpha [_fegg +1]=uint8 (_debag .A &0xff);};};func MonochromeModel (threshold uint8 )_fc .Model {return monochromeModel (threshold )};func (_acgb *NRGBA64 )NRGBA64At (x ,y int )_fc .NRGBA64 {_ccac ,_ :=ColorAtNRGBA64 (x ,y ,_acgb .Width ,_acgb .Data ,_acgb .Alpha ,_acgb .Decode );
|
|
return _ccac ;};func (_efce *Gray8 )Histogram ()(_edfa [256]int ){for _caf :=0;_caf < len (_efce .Data );_caf ++{_edfa [_efce .Data [_caf ]]++;};return _edfa ;};func (_fga *NRGBA16 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_fga .Width ,Y :_fga .Height }};
|
|
};func (_cbdfd *Gray4 )Set (x ,y int ,c _fc .Color ){if x >=_cbdfd .Width ||y >=_cbdfd .Height {return ;};_ffe :=Gray4Model .Convert (c ).(_fc .Gray );_cbdfd .setGray (x ,y ,_ffe );};type CMYK interface{CMYKAt (_fdf ,_bbe int )_fc .CMYK ;SetCMYK (_eag ,_aec int ,_bbga _fc .CMYK );
|
|
};var _ Gray =&Gray4 {};func _ffaag (_fgbbc *_fe .Gray ,_abde uint8 )*_fe .Gray {_eadf :=_fgbbc .Bounds ();_fcaf :=_fe .NewGray (_eadf );for _ccdeg :=0;_ccdeg < _eadf .Dx ();_ccdeg ++{for _gccg :=0;_gccg < _eadf .Dy ();_gccg ++{_gcgee :=_fgbbc .GrayAt (_ccdeg ,_gccg );
|
|
_fcaf .SetGray (_ccdeg ,_gccg ,_fc .Gray {Y :_ecegg (_gcgee .Y ,_abde )});};};return _fcaf ;};func ColorAtGray1BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_fc .Gray ,error ){_bddbb :=y *bytesPerLine +x >>3;if _bddbb >=len (data ){return _fc .Gray {},_d .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 );
|
|
};_bdda :=data [_bddbb ]>>uint (7-(x &7))&1;if len (decode )==2{_bdda =uint8 (LinearInterpolate (float64 (_bdda ),0.0,1.0,decode [0],decode [1]))&1;};return _fc .Gray {Y :_bdda *255},nil ;};func _ggebf (_efddg *_fe .NYCbCrA ,_dcdg NRGBA ,_cbbfg _fe .Rectangle ){for _cbfae :=0;
|
|
_cbfae < _cbbfg .Max .X ;_cbfae ++{for _efgc :=0;_efgc < _cbbfg .Max .Y ;_efgc ++{_bbgf :=_efddg .NYCbCrAAt (_cbfae ,_efgc );_dcdg .SetNRGBA (_cbfae ,_efgc ,_aead (_bbgf ));};};};func _ac (_gfe ,_bb *Monochrome )(_ead error ){_gdc :=_bb .BytesPerLine ;
|
|
_eaf :=_gfe .BytesPerLine ;_cf :=_bb .BytesPerLine *4-_gfe .BytesPerLine ;var (_cb ,_gb byte ;_dga uint32 ;_deg ,_cg ,_eb ,_bbf ,_fb ,_dca ,_be int ;);for _eb =0;_eb < _bb .Height ;_eb ++{_deg =_eb *_gdc ;_cg =4*_eb *_eaf ;for _bbf =0;_bbf < _gdc ;_bbf ++{_cb =_bb .Data [_deg +_bbf ];
|
|
_dga =_egc [_cb ];_dca =_cg +_bbf *4;if _cf !=0&&(_bbf +1)*4> _gfe .BytesPerLine {for _fb =_cf ;_fb > 0;_fb --{_gb =byte ((_dga >>uint (_fb *8))&0xff);_be =_dca +(_cf -_fb );if _ead =_gfe .setByte (_be ,_gb );_ead !=nil {return _ead ;};};}else if _ead =_gfe .setFourBytes (_dca ,_dga );
|
|
_ead !=nil {return _ead ;};if _ead =_gfe .setFourBytes (_cg +_bbf *4,_egc [_bb .Data [_deg +_bbf ]]);_ead !=nil {return _ead ;};};for _fb =1;_fb < 4;_fb ++{for _bbf =0;_bbf < _eaf ;_bbf ++{if _ead =_gfe .setByte (_cg +_fb *_eaf +_bbf ,_gfe .Data [_cg +_bbf ]);
|
|
_ead !=nil {return _ead ;};};};};return nil ;};func ImgToGray (i _fe .Image )*_fe .Gray {if _dcee ,_fcef :=i .(*_fe .Gray );_fcef {return _dcee ;};_cgfd :=i .Bounds ();_fegc :=_fe .NewGray (_cgfd );for _cgdc :=0;_cgdc < _cgfd .Max .X ;_cgdc ++{for _defbc :=0;
|
|
_defbc < _cgfd .Max .Y ;_defbc ++{_aabe :=i .At (_cgdc ,_defbc );_fegc .Set (_cgdc ,_defbc ,_aabe );};};return _fegc ;};func (_bdb *Monochrome )ColorModel ()_fc .Model {return MonochromeModel (_bdb .ModelThreshold )};type SMasker interface{HasAlpha ()bool ;
|
|
GetAlpha ()[]byte ;MakeAlpha ();};var _ _fe .Image =&Gray4 {};func (_ffdc *NRGBA16 )Base ()*ImageBase {return &_ffdc .ImageBase };func (_dfag *Monochrome )setGrayBit (_cccc ,_bda int ){_dfag .Data [_cccc ]|=0x80>>uint (_bda &7)};func ColorAtNRGBA16 (x ,y ,width ,bytesPerLine int ,data ,alpha []byte ,decode []float64 )(_fc .NRGBA ,error ){_fcbf :=y *bytesPerLine +x *3/2;
|
|
if _fcbf +1>=len (data ){return _fc .NRGBA {},_bgbf (x ,y );};const (_eagga =0xf;_dgab =uint8 (0xff););_afb :=_dgab ;if alpha !=nil {_fgefe :=y *BytesPerLine (width ,4,1);if _fgefe < len (alpha ){if x %2==0{_afb =(alpha [_fgefe ]>>uint (4))&_eagga ;}else {_afb =alpha [_fgefe ]&_eagga ;
|
|
};_afb |=_afb <<4;};};var _eaag ,_ceada ,_aefbb uint8 ;if x *3%2==0{_eaag =(data [_fcbf ]>>uint (4))&_eagga ;_ceada =data [_fcbf ]&_eagga ;_aefbb =(data [_fcbf +1]>>uint (4))&_eagga ;}else {_eaag =data [_fcbf ]&_eagga ;_ceada =(data [_fcbf +1]>>uint (4))&_eagga ;
|
|
_aefbb =data [_fcbf +1]&_eagga ;};if len (decode )==6{_eaag =uint8 (uint32 (LinearInterpolate (float64 (_eaag ),0,15,decode [0],decode [1]))&0xf);_ceada =uint8 (uint32 (LinearInterpolate (float64 (_ceada ),0,15,decode [2],decode [3]))&0xf);_aefbb =uint8 (uint32 (LinearInterpolate (float64 (_aefbb ),0,15,decode [4],decode [5]))&0xf);
|
|
};return _fc .NRGBA {R :(_eaag <<4)|(_eaag &0xf),G :(_ceada <<4)|(_ceada &0xf),B :(_aefbb <<4)|(_aefbb &0xf),A :_afb },nil ;};func (_feaf *NRGBA64 )Set (x ,y int ,c _fc .Color ){_gcgd :=(y *_feaf .Width +x )*2;_ecdc :=_gcgd *3;if _ecdc +5>=len (_feaf .Data ){return ;
|
|
};_cgdag :=_fc .NRGBA64Model .Convert (c ).(_fc .NRGBA64 );_feaf .setNRGBA64 (_ecdc ,_cgdag ,_gcgd );};func _bbg (_ec *Monochrome ,_cac ...int )(_gg *Monochrome ,_dae error ){if _ec ==nil {return nil ,_e .New ("\u0073o\u0075\u0072\u0063\u0065 \u0062\u0069\u0074\u006d\u0061p\u0020n\u006ft\u0020\u0064\u0065\u0066\u0069\u006e\u0065d");
|
|
};if len (_cac )==0{return nil ,_e .New ("\u0074h\u0065\u0072e\u0020\u006d\u0075s\u0074\u0020\u0062\u0065\u0020\u0061\u0074 \u006c\u0065\u0061\u0073\u0074\u0020o\u006e\u0065\u0020\u006c\u0065\u0076\u0065\u006c\u0020\u006f\u0066 \u0072\u0065\u0064\u0075\u0063\u0074\u0069\u006f\u006e");
|
|
};_ab :=_fadd ();_gg =_ec ;for _ ,_dfg :=range _cac {if _dfg <=0{break ;};_gg ,_dae =_cgc (_gg ,_dfg ,_ab );if _dae !=nil {return nil ,_dae ;};};return _gg ,nil ;};func (_cegg *Gray2 )ColorModel ()_fc .Model {return Gray2Model };func (_ebef *NRGBA16 )ColorAt (x ,y int )(_fc .Color ,error ){return ColorAtNRGBA16 (x ,y ,_ebef .Width ,_ebef .BytesPerLine ,_ebef .Data ,_ebef .Alpha ,_ebef .Decode );
|
|
};func (_abg *Gray4 )Base ()*ImageBase {return &_abg .ImageBase };func _afacb (_cdca _fc .RGBA )_fc .CMYK {_faaf ,_ggef ,_afc ,_gffe :=_fc .RGBToCMYK (_cdca .R ,_cdca .G ,_cdca .B );return _fc .CMYK {C :_faaf ,M :_ggef ,Y :_afc ,K :_gffe };};func (_ebdc *NRGBA32 )At (x ,y int )_fc .Color {_ggcb ,_ :=_ebdc .ColorAt (x ,y );
|
|
return _ggcb };func _dbe (_cdacb *Monochrome ,_egbdf ,_cdf int ,_cfcc ,_gdcga int ,_afae RasterOperator ,_gdbba *Monochrome ,_aeacd ,_edcf int )error {var _dabd ,_ddcb ,_agga ,_ebbd int ;if _egbdf < 0{_aeacd -=_egbdf ;_cfcc +=_egbdf ;_egbdf =0;};if _aeacd < 0{_egbdf -=_aeacd ;
|
|
_cfcc +=_aeacd ;_aeacd =0;};_dabd =_egbdf +_cfcc -_cdacb .Width ;if _dabd > 0{_cfcc -=_dabd ;};_ddcb =_aeacd +_cfcc -_gdbba .Width ;if _ddcb > 0{_cfcc -=_ddcb ;};if _cdf < 0{_edcf -=_cdf ;_gdcga +=_cdf ;_cdf =0;};if _edcf < 0{_cdf -=_edcf ;_gdcga +=_edcf ;
|
|
_edcf =0;};_agga =_cdf +_gdcga -_cdacb .Height ;if _agga > 0{_gdcga -=_agga ;};_ebbd =_edcf +_gdcga -_gdbba .Height ;if _ebbd > 0{_gdcga -=_ebbd ;};if _cfcc <=0||_gdcga <=0{return nil ;};var _bfeb error ;switch {case _egbdf &7==0&&_aeacd &7==0:_bfeb =_ggce (_cdacb ,_egbdf ,_cdf ,_cfcc ,_gdcga ,_afae ,_gdbba ,_aeacd ,_edcf );
|
|
case _egbdf &7==_aeacd &7:_bfeb =_eecdg (_cdacb ,_egbdf ,_cdf ,_cfcc ,_gdcga ,_afae ,_gdbba ,_aeacd ,_edcf );default:_bfeb =_befc (_cdacb ,_egbdf ,_cdf ,_cfcc ,_gdcga ,_afae ,_gdbba ,_aeacd ,_edcf );};if _bfeb !=nil {return _bfeb ;};return nil ;};func (_ddbb *Gray2 )Validate ()error {if len (_ddbb .Data )!=_ddbb .Height *_ddbb .BytesPerLine {return ErrInvalidImage ;
|
|
};return nil ;};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 ,_d .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 _bgbe (_bef Gray ,_fde CMYK ,_ded _fe .Rectangle ){for _fdd :=0;_fdd < _ded .Max .X ;_fdd ++{for _eagb :=0;_eagb < _ded .Max .Y ;_eagb ++{_cecg :=_bef .GrayAt (_fdd ,_eagb );_fde .SetCMYK (_fdd ,_eagb ,_bdcb (_cecg ));};};};func (_fabgg *Monochrome )RasterOperation (dx ,dy ,dw ,dh int ,op RasterOperator ,src *Monochrome ,sx ,sy int )error {return _fcde (_fabgg ,dx ,dy ,dw ,dh ,op ,src ,sx ,sy );
|
|
};func (_agf *Gray4 )Histogram ()(_befb [256]int ){for _eff :=0;_eff < _agf .Width ;_eff ++{for _ggec :=0;_ggec < _agf .Height ;_ggec ++{_befb [_agf .GrayAt (_eff ,_ggec ).Y ]++;};};return _befb ;};func (_ddge *Gray16 )ColorModel ()_fc .Model {return _fc .Gray16Model };
|
|
func NewImageBase (width int ,height int ,bitsPerComponent int ,colorComponents int ,data []byte ,alpha []byte ,decode []float64 )ImageBase {_gfege :=ImageBase {Width :width ,Height :height ,BitsPerComponent :bitsPerComponent ,ColorComponents :colorComponents ,Data :data ,Alpha :alpha ,Decode :decode ,BytesPerLine :BytesPerLine (width ,bitsPerComponent ,colorComponents )};
|
|
if data ==nil {_gfege .Data =make ([]byte ,height *_gfege .BytesPerLine );};return _gfege ;};func (_ced *CMYK32 )Set (x ,y int ,c _fc .Color ){_ffcc :=4*(y *_ced .Width +x );if _ffcc +3>=len (_ced .Data ){return ;};_fcc :=_fc .CMYKModel .Convert (c ).(_fc .CMYK );
|
|
_ced .Data [_ffcc ]=_fcc .C ;_ced .Data [_ffcc +1]=_fcc .M ;_ced .Data [_ffcc +2]=_fcc .Y ;_ced .Data [_ffcc +3]=_fcc .K ;};func _acdg (_acba _fe .Image ,_adfd Image ,_acgd _fe .Rectangle ){switch _bgabd :=_acba .(type ){case Gray :_dcbd (_bgabd ,_adfd .(Gray ),_acgd );
|
|
case NRGBA :_fbdc (_bgabd ,_adfd .(Gray ),_acgd );case CMYK :_fcg (_bgabd ,_adfd .(Gray ),_acgd );case RGBA :_gcbe (_bgabd ,_adfd .(Gray ),_acgd );default:_gdce (_acba ,_adfd ,_acgd );};};type nrgba64 interface{NRGBA64At (_fadda ,_deba int )_fc .NRGBA64 ;
|
|
SetNRGBA64 (_ddcfc ,_bged int ,_gcbgd _fc .NRGBA64 );};func _abffa (_cbgb _fe .Image )(Image ,error ){if _ggdg ,_eegb :=_cbgb .(*Gray4 );_eegb {return _ggdg .Copy (),nil ;};_eac :=_cbgb .Bounds ();_gefe ,_dbb :=NewImage (_eac .Max .X ,_eac .Max .Y ,4,1,nil ,nil ,nil );
|
|
if _dbb !=nil {return nil ,_dbb ;};_acdg (_cbgb ,_gefe ,_eac );return _gefe ,nil ;};var _ Image =&RGBA32 {};func ColorAtGray16BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_fc .Gray16 ,error ){_caa :=(y *bytesPerLine /2+x )*2;if _caa +1>=len (data ){return _fc .Gray16 {},_d .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 );
|
|
};_eecd :=uint16 (data [_caa ])<<8|uint16 (data [_caa +1]);if len (decode )==2{_eecd =uint16 (uint64 (LinearInterpolate (float64 (_eecd ),0,65535,decode [0],decode [1])));};return _fc .Gray16 {Y :_eecd },nil ;};func _bdc (_dcaf int )[]uint {var _gdb []uint ;
|
|
_gfc :=_dcaf ;_fbg :=_gfc /8;if _fbg !=0{for _faa :=0;_faa < _fbg ;_faa ++{_gdb =append (_gdb ,8);};_faf :=_gfc %8;_gfc =0;if _faf !=0{_gfc =_faf ;};};_ad :=_gfc /4;if _ad !=0{for _cab :=0;_cab < _ad ;_cab ++{_gdb =append (_gdb ,4);};_ga :=_gfc %4;_gfc =0;
|
|
if _ga !=0{_gfc =_ga ;};};_cga :=_gfc /2;if _cga !=0{for _acd :=0;_acd < _cga ;_acd ++{_gdb =append (_gdb ,2);};};return _gdb ;};func ColorAtNRGBA (x ,y ,width ,bytesPerLine ,bitsPerColor int ,data ,alpha []byte ,decode []float64 )(_fc .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 ,_d .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 (_cdd *Gray4 )Copy ()Image {return &Gray4 {ImageBase :_cdd .copy ()}};func (_bcgaa *NRGBA16 )Validate ()error {if len (_bcgaa .Data )!=3*_bcgaa .Width *_bcgaa .Height /2{return _e .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 (_cbfa *Gray2 )Histogram ()(_dbde [256]int ){for _fcff :=0;_fcff < _cbfa .Width ;_fcff ++{for _defg :=0;_defg < _cbfa .Height ;_defg ++{_dbde [_cbfa .GrayAt (_fcff ,_defg ).Y ]++;};};return _dbde ;};func _gcbe (_gaf RGBA ,_ccg Gray ,_gagbc _fe .Rectangle ){for _fcfc :=0;
|
|
_fcfc < _gagbc .Max .X ;_fcfc ++{for _fggaf :=0;_fggaf < _gagbc .Max .Y ;_fggaf ++{_gaac :=_aad (_gaf .RGBAAt (_fcfc ,_fggaf ));_ccg .SetGray (_fcfc ,_fggaf ,_gaac );};};};func (_baab *RGBA32 )Copy ()Image {return &RGBA32 {ImageBase :_baab .copy ()}};func _efd (_bbb Gray ,_ffge nrgba64 ,_bcce _fe .Rectangle ){for _gcdd :=0;
|
|
_gcdd < _bcce .Max .X ;_gcdd ++{for _cfc :=0;_cfc < _bcce .Max .Y ;_cfc ++{_cgbc :=_gbca (_ffge .NRGBA64At (_gcdd ,_cfc ));_bbb .SetGray (_gcdd ,_cfc ,_cgbc );};};};func (_eege *NRGBA32 )Base ()*ImageBase {return &_eege .ImageBase };func (_gdfg *ImageBase )setEightFullBytes (_ebgd int ,_dcbg uint64 )error {if _ebgd +7> len (_gdfg .Data )-1{return _e .New ("\u0069n\u0064e\u0078\u0020\u006f\u0075\u0074 \u006f\u0066 \u0072\u0061\u006e\u0067\u0065");
|
|
};_gdfg .Data [_ebgd ]=byte ((_dcbg &0xff00000000000000)>>56);_gdfg .Data [_ebgd +1]=byte ((_dcbg &0xff000000000000)>>48);_gdfg .Data [_ebgd +2]=byte ((_dcbg &0xff0000000000)>>40);_gdfg .Data [_ebgd +3]=byte ((_dcbg &0xff00000000)>>32);_gdfg .Data [_ebgd +4]=byte ((_dcbg &0xff000000)>>24);
|
|
_gdfg .Data [_ebgd +5]=byte ((_dcbg &0xff0000)>>16);_gdfg .Data [_ebgd +6]=byte ((_dcbg &0xff00)>>8);_gdfg .Data [_ebgd +7]=byte (_dcbg &0xff);return nil ;};func (_bcae *NRGBA64 )Validate ()error {if len (_bcae .Data )!=3*2*_bcae .Width *_bcae .Height {return _e .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 (_decb *RGBA32 )At (x ,y int )_fc .Color {_fccgf ,_ :=_decb .ColorAt (x ,y );return _fccgf };type RGBA32 struct{ImageBase };type monochromeThresholdConverter struct{Threshold uint8 ;};func _cgff (_cbb ,_dgb CMYK ,_gcd _fe .Rectangle ){for _edeb :=0;
|
|
_edeb < _gcd .Max .X ;_edeb ++{for _cgffc :=0;_cgffc < _gcd .Max .Y ;_cgffc ++{_dgb .SetCMYK (_edeb ,_cgffc ,_cbb .CMYKAt (_edeb ,_cgffc ));};};};var _ RGBA =&RGBA32 {};var _ Gray =&Gray16 {};func _gbbe (_gcege _fc .Gray )_fc .Gray {_ggcc :=_gcege .Y >>6;
|
|
_ggcc |=_ggcc <<2;_gcege .Y =_ggcc |_ggcc <<4;return _gcege ;};func _ecegc (_agcb _fe .Image )(Image ,error ){if _cfccb ,_dggc :=_agcb .(*NRGBA64 );_dggc {return _cfccb .Copy (),nil ;};_cafd ,_cfdg ,_adag :=_bafg (_agcb ,2);_feee ,_cafab :=NewImage (_cafd .Max .X ,_cafd .Max .Y ,16,3,nil ,_adag ,nil );
|
|
if _cafab !=nil {return nil ,_cafab ;};_cag (_agcb ,_feee ,_cafd );if len (_adag )!=0&&!_cfdg {if _affd :=_cabe (_adag ,_feee );_affd !=nil {return nil ,_affd ;};};return _feee ,nil ;};func ColorAtGray4BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_fc .Gray ,error ){_cddg :=y *bytesPerLine +x >>1;
|
|
if _cddg >=len (data ){return _fc .Gray {},_d .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 );
|
|
};_cdce :=data [_cddg ]>>uint (4-(x &1)*4)&0xf;if len (decode )==2{_cdce =uint8 (uint32 (LinearInterpolate (float64 (_cdce ),0,15,decode [0],decode [1]))&0xf);};return _fc .Gray {Y :_cdce *17&0xff},nil ;};func (_dcfa *Gray16 )Copy ()Image {return &Gray16 {ImageBase :_dcfa .copy ()}};
|
|
func AutoThresholdTriangle (histogram [256]int )uint8 {var _cgcb ,_ccab ,_abfda ,_cgbd int ;for _aag :=0;_aag < len (histogram );_aag ++{if histogram [_aag ]> 0{_cgcb =_aag ;break ;};};if _cgcb > 0{_cgcb --;};for _bfced :=255;_bfced > 0;_bfced --{if histogram [_bfced ]> 0{_cgbd =_bfced ;
|
|
break ;};};if _cgbd < 255{_cgbd ++;};for _dfgce :=0;_dfgce < 256;_dfgce ++{if histogram [_dfgce ]> _ccab {_abfda =_dfgce ;_ccab =histogram [_dfgce ];};};var _bgbff bool ;if (_abfda -_cgcb )< (_cgbd -_abfda ){_bgbff =true ;var _cafcd int ;_fbab :=255;for _cafcd < _fbab {_addca :=histogram [_cafcd ];
|
|
histogram [_cafcd ]=histogram [_fbab ];histogram [_fbab ]=_addca ;_cafcd ++;_fbab --;};_cgcb =255-_cgbd ;_abfda =255-_abfda ;};if _cgcb ==_abfda {return uint8 (_cgcb );};_cagc :=float64 (histogram [_abfda ]);_ecaed :=float64 (_cgcb -_abfda );_cgafg :=_ea .Sqrt (_cagc *_cagc +_ecaed *_ecaed );
|
|
_cagc /=_cgafg ;_ecaed /=_cgafg ;_cgafg =_cagc *float64 (_cgcb )+_ecaed *float64 (histogram [_cgcb ]);_abffad :=_cgcb ;var _defgd float64 ;for _fcbd :=_cgcb +1;_fcbd <=_abfda ;_fcbd ++{_bgbd :=_cagc *float64 (_fcbd )+_ecaed *float64 (histogram [_fcbd ])-_cgafg ;
|
|
if _bgbd > _defgd {_abffad =_fcbd ;_defgd =_bgbd ;};};_abffad --;if _bgbff {var _eacbc int ;_cace :=255;for _eacbc < _cace {_bfd :=histogram [_eacbc ];histogram [_eacbc ]=histogram [_cace ];histogram [_cace ]=_bfd ;_eacbc ++;_cace --;};return uint8 (255-_abffad );
|
|
};return uint8 (_abffad );};func (_dfbc *Gray8 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_dfbc .Width ,Y :_dfbc .Height }};};func (_gfbef *NRGBA64 )SetNRGBA64 (x ,y int ,c _fc .NRGBA64 ){_dadad :=(y *_gfbef .Width +x )*2;_feed :=_dadad *3;
|
|
if _feed +5>=len (_gfbef .Data ){return ;};_gfbef .setNRGBA64 (_feed ,c ,_dadad );};func (_eacbe *NRGBA16 )Set (x ,y int ,c _fc .Color ){_gcaf :=y *_eacbe .BytesPerLine +x *3/2;if _gcaf +1>=len (_eacbe .Data ){return ;};_gafd :=NRGBA16Model .Convert (c ).(_fc .NRGBA );
|
|
_eacbe .setNRGBA (x ,y ,_gcaf ,_gafd );};func (_gbb *CMYK32 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_gbb .Width ,Y :_gbb .Height }};};func (_cdbc *NRGBA64 )At (x ,y int )_fc .Color {_ffac ,_ :=_cdbc .ColorAt (x ,y );return _ffac };
|
|
func (_bcgd *RGBA32 )Set (x ,y int ,c _fc .Color ){_aaef :=y *_bcgd .Width +x ;_aggbc :=3*_aaef ;if _aggbc +2>=len (_bcgd .Data ){return ;};_bcaef :=_fc .RGBAModel .Convert (c ).(_fc .RGBA );_bcgd .setRGBA (_aaef ,_bcaef );};func (_bgd *CMYK32 )At (x ,y int )_fc .Color {_gdacc ,_ :=_bgd .ColorAt (x ,y );
|
|
return _gdacc };func (_bfe *CMYK32 )ColorModel ()_fc .Model {return _fc .CMYKModel };var _ _fe .Image =&Gray8 {};func _cag (_bgbfc _fe .Image ,_bccac Image ,_ggeg _fe .Rectangle ){if _ccbfb ,_afcf :=_bgbfc .(SMasker );_afcf &&_ccbfb .HasAlpha (){_bccac .(SMasker ).MakeAlpha ();
|
|
};_gdce (_bgbfc ,_bccac ,_ggeg );};type Gray interface{GrayAt (_agg ,_feade int )_fc .Gray ;SetGray (_cbed ,_bgda int ,_dcf _fc .Gray );};func _fbdc (_dceg NRGBA ,_acca Gray ,_cefg _fe .Rectangle ){for _bgeef :=0;_bgeef < _cefg .Max .X ;_bgeef ++{for _eadgd :=0;
|
|
_eadgd < _cefg .Max .Y ;_eadgd ++{_gee :=_agea (_dceg .NRGBAAt (_bgeef ,_eadgd ));_acca .SetGray (_bgeef ,_eadgd ,_gee );};};};func _edfe (_cdg *_fe .Gray )bool {for _acdge :=0;_acdge < len (_cdg .Pix );_acdge ++{if !_aaf (_cdg .Pix [_acdge ]){return false ;
|
|
};};return true ;};var _ _fe .Image =&Gray16 {};func _eabb (_dgeg ,_gafce RGBA ,_ecefe _fe .Rectangle ){for _fcdea :=0;_fcdea < _ecefe .Max .X ;_fcdea ++{for _bfffg :=0;_bfffg < _ecefe .Max .Y ;_bfffg ++{_gafce .SetRGBA (_fcdea ,_bfffg ,_dgeg .RGBAAt (_fcdea ,_bfffg ));
|
|
};};};func _cdaf (_bggb _fc .Gray )_fc .NRGBA {return _fc .NRGBA {R :_bggb .Y ,G :_bggb .Y ,B :_bggb .Y ,A :0xff}};func (_ffag *Monochrome )ColorAt (x ,y int )(_fc .Color ,error ){return ColorAtGray1BPC (x ,y ,_ffag .BytesPerLine ,_ffag .Data ,_ffag .Decode );
|
|
};func _aaf (_dcegf uint8 )bool {if _dcegf ==0||_dcegf ==255{return true ;};return false ;};func (_eaeg *Gray16 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_eaeg .Width ,Y :_eaeg .Height }};}; |