mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-30 13:48:51 +08:00
403 lines
115 KiB
Go
403 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 (_ce "encoding/binary";_f "errors";_dc "fmt";_cb "github.com/unidoc/unipdf/v3/common";_cc "github.com/unidoc/unipdf/v3/internal/bitwise";_b "image";_df "image/color";_e "image/draw";_c "math";);func _fgfg (){for _cbad :=0;_cbad < 256;
|
|
_cbad ++{_bgge [_cbad ]=uint8 (_cbad &0x1)+(uint8 (_cbad >>1)&0x1)+(uint8 (_cbad >>2)&0x1)+(uint8 (_cbad >>3)&0x1)+(uint8 (_cbad >>4)&0x1)+(uint8 (_cbad >>5)&0x1)+(uint8 (_cbad >>6)&0x1)+(uint8 (_cbad >>7)&0x1);};};func _abg (_addc _df .Gray )_df .Gray {_addc .Y >>=4;
|
|
_addc .Y |=_addc .Y <<4;return _addc };func (_bacd *ImageBase )HasAlpha ()bool {if _bacd .Alpha ==nil {return false ;};for _dfde :=range _bacd .Alpha {if _bacd .Alpha [_dfde ]!=0xff{return true ;};};return false ;};func _cdf (_gdd _b .Image ,_dccg Image ,_aacg _b .Rectangle ){for _edf :=0;
|
|
_edf < _aacg .Max .X ;_edf ++{for _fdc :=0;_fdc < _aacg .Max .Y ;_fdc ++{_ebcb :=_gdd .At (_edf ,_fdc );_dccg .Set (_edf ,_fdc ,_ebcb );};};};func (_ecgf *Gray4 )Histogram ()(_ebb [256]int ){for _abdf :=0;_abdf < _ecgf .Width ;_abdf ++{for _fed :=0;_fed < _ecgf .Height ;
|
|
_fed ++{_ebb [_ecgf .GrayAt (_abdf ,_fed ).Y ]++;};};return _ebb ;};func (_dfee *Gray16 )SetGray (x ,y int ,g _df .Gray ){_ecdg :=(y *_dfee .BytesPerLine /2+x )*2;if _ecdg +1>=len (_dfee .Data ){return ;};_dfee .Data [_ecdg ]=g .Y ;_dfee .Data [_ecdg +1]=g .Y ;
|
|
};func BytesPerLine (width ,bitsPerComponent ,colorComponents int )int {return ((width *bitsPerComponent )*colorComponents +7)>>3;};func _dcgb (_ege NRGBA ,_cefc CMYK ,_abe _b .Rectangle ){for _ggcgb :=0;_ggcgb < _abe .Max .X ;_ggcgb ++{for _cfe :=0;_cfe < _abe .Max .Y ;
|
|
_cfe ++{_acef :=_ege .NRGBAAt (_ggcgb ,_cfe );_cefc .SetCMYK (_ggcgb ,_cfe ,_bfg (_acef ));};};};func _gbe (_cgcdf _df .NYCbCrA )_df .RGBA {_cbd ,_dae ,_aea ,_cged :=_abdb (_cgcdf ).RGBA ();return _df .RGBA {R :uint8 (_cbd >>8),G :uint8 (_dae >>8),B :uint8 (_aea >>8),A :uint8 (_cged >>8)};
|
|
};func _bgda (_acee int ,_fdbcb int )error {return _dc .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",_acee ,_fdbcb );
|
|
};func _edc (_gcg ,_ffg *Monochrome ,_agg []byte ,_febf int )(_aac error ){var (_bgcd ,_eedg ,_agc ,_fba ,_bgec ,_dde ,_gab ,_dda int ;_bca ,_bga ,_cbe ,_cde uint32 ;_gcd ,_gbg byte ;_cfd uint16 ;);_fbe :=make ([]byte ,4);_dfdb :=make ([]byte ,4);for _agc =0;
|
|
_agc < _gcg .Height -1;_agc ,_fba =_agc +2,_fba +1{_bgcd =_agc *_gcg .BytesPerLine ;_eedg =_fba *_ffg .BytesPerLine ;for _bgec ,_dde =0,0;_bgec < _febf ;_bgec ,_dde =_bgec +4,_dde +1{for _gab =0;_gab < 4;_gab ++{_dda =_bgcd +_bgec +_gab ;if _dda <=len (_gcg .Data )-1&&_dda < _bgcd +_gcg .BytesPerLine {_fbe [_gab ]=_gcg .Data [_dda ];
|
|
}else {_fbe [_gab ]=0x00;};_dda =_bgcd +_gcg .BytesPerLine +_bgec +_gab ;if _dda <=len (_gcg .Data )-1&&_dda < _bgcd +(2*_gcg .BytesPerLine ){_dfdb [_gab ]=_gcg .Data [_dda ];}else {_dfdb [_gab ]=0x00;};};_bca =_ce .BigEndian .Uint32 (_fbe );_bga =_ce .BigEndian .Uint32 (_dfdb );
|
|
_cbe =_bca &_bga ;_cbe |=_cbe <<1;_cde =_bca |_bga ;_cde &=_cde <<1;_bga =_cbe &_cde ;_bga &=0xaaaaaaaa;_bca =_bga |(_bga <<7);_gcd =byte (_bca >>24);_gbg =byte ((_bca >>8)&0xff);_dda =_eedg +_dde ;if _dda +1==len (_ffg .Data )-1||_dda +1>=_eedg +_ffg .BytesPerLine {if _aac =_ffg .setByte (_dda ,_agg [_gcd ]);
|
|
_aac !=nil {return _dc .Errorf ("\u0069n\u0064\u0065\u0078\u003a\u0020\u0025d",_dda );};}else {_cfd =(uint16 (_agg [_gcd ])<<8)|uint16 (_agg [_gbg ]);if _aac =_ffg .setTwoBytes (_dda ,_cfd );_aac !=nil {return _dc .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",_dda );
|
|
};_dde ++;};};};return nil ;};func _fcg (_ced ,_fac *Monochrome ,_bdcg []byte ,_gegd int )(_bae error ){var (_bef ,_dgdc ,_bdcf ,_gdb ,_eaa ,_cad ,_cacd ,_gecb int ;_add ,_feg uint32 ;_gge ,_bbe byte ;_adaa uint16 ;);_acc :=make ([]byte ,4);_dff :=make ([]byte ,4);
|
|
for _bdcf =0;_bdcf < _ced .Height -1;_bdcf ,_gdb =_bdcf +2,_gdb +1{_bef =_bdcf *_ced .BytesPerLine ;_dgdc =_gdb *_fac .BytesPerLine ;for _eaa ,_cad =0,0;_eaa < _gegd ;_eaa ,_cad =_eaa +4,_cad +1{for _cacd =0;_cacd < 4;_cacd ++{_gecb =_bef +_eaa +_cacd ;
|
|
if _gecb <=len (_ced .Data )-1&&_gecb < _bef +_ced .BytesPerLine {_acc [_cacd ]=_ced .Data [_gecb ];}else {_acc [_cacd ]=0x00;};_gecb =_bef +_ced .BytesPerLine +_eaa +_cacd ;if _gecb <=len (_ced .Data )-1&&_gecb < _bef +(2*_ced .BytesPerLine ){_dff [_cacd ]=_ced .Data [_gecb ];
|
|
}else {_dff [_cacd ]=0x00;};};_add =_ce .BigEndian .Uint32 (_acc );_feg =_ce .BigEndian .Uint32 (_dff );_feg &=_add ;_feg &=_feg <<1;_feg &=0xaaaaaaaa;_add =_feg |(_feg <<7);_gge =byte (_add >>24);_bbe =byte ((_add >>8)&0xff);_gecb =_dgdc +_cad ;if _gecb +1==len (_fac .Data )-1||_gecb +1>=_dgdc +_fac .BytesPerLine {_fac .Data [_gecb ]=_bdcg [_gge ];
|
|
if _bae =_fac .setByte (_gecb ,_bdcg [_gge ]);_bae !=nil {return _dc .Errorf ("\u0069n\u0064\u0065\u0078\u003a\u0020\u0025d",_gecb );};}else {_adaa =(uint16 (_bdcg [_gge ])<<8)|uint16 (_bdcg [_bbe ]);if _bae =_fac .setTwoBytes (_gecb ,_adaa );_bae !=nil {return _dc .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",_gecb );
|
|
};_cad ++;};};};return nil ;};func _gedab (_aaab ,_gacd RGBA ,_bgdf _b .Rectangle ){for _cdeb :=0;_cdeb < _bgdf .Max .X ;_cdeb ++{for _gfed :=0;_gfed < _bgdf .Max .Y ;_gfed ++{_gacd .SetRGBA (_cdeb ,_gfed ,_aaab .RGBAAt (_cdeb ,_gfed ));};};};func _cfbec (_gdf ,_fccfa NRGBA ,_ecda _b .Rectangle ){for _dbad :=0;
|
|
_dbad < _ecda .Max .X ;_dbad ++{for _acdf :=0;_acdf < _ecda .Max .Y ;_acdf ++{_fccfa .SetNRGBA (_dbad ,_acdf ,_gdf .NRGBAAt (_dbad ,_acdf ));};};};func (_bbgf *Gray16 )Validate ()error {if len (_bbgf .Data )!=_bbgf .Height *_bbgf .BytesPerLine {return ErrInvalidImage ;
|
|
};return nil ;};func (_fbca *NRGBA16 )Base ()*ImageBase {return &_fbca .ImageBase };func (_fgd *NRGBA64 )At (x ,y int )_df .Color {_egeea ,_ :=_fgd .ColorAt (x ,y );return _egeea };type NRGBA32 struct{ImageBase };func (_gffc *NRGBA16 )ColorAt (x ,y int )(_df .Color ,error ){return ColorAtNRGBA16 (x ,y ,_gffc .Width ,_gffc .BytesPerLine ,_gffc .Data ,_gffc .Alpha ,_gffc .Decode );
|
|
};func (_cca *CMYK32 )ColorModel ()_df .Model {return _df .CMYKModel };var _ Image =&Gray4 {};type NRGBA interface{NRGBAAt (_dfdg ,_dcec int )_df .NRGBA ;SetNRGBA (_febfa ,_ccgg int ,_caff _df .NRGBA );};func (_cdag *Gray4 )GrayAt (x ,y int )_df .Gray {_caf ,_ :=ColorAtGray4BPC (x ,y ,_cdag .BytesPerLine ,_cdag .Data ,_cdag .Decode );
|
|
return _caf ;};func ColorAtGray16BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_df .Gray16 ,error ){_ffcd :=(y *bytesPerLine /2+x )*2;if _ffcd +1>=len (data ){return _df .Gray16 {},_dc .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 );
|
|
};_fffd :=uint16 (data [_ffcd ])<<8|uint16 (data [_ffcd +1]);if len (decode )==2{_fffd =uint16 (uint64 (LinearInterpolate (float64 (_fffd ),0,65535,decode [0],decode [1])));};return _df .Gray16 {Y :_fffd },nil ;};func (_cbbc *Gray16 )Histogram ()(_gdbe [256]int ){for _eeb :=0;
|
|
_eeb < _cbbc .Width ;_eeb ++{for _aabd :=0;_aabd < _cbbc .Height ;_aabd ++{_gdbe [_cbbc .GrayAt (_eeb ,_aabd ).Y ]++;};};return _gdbe ;};func (_eacge *Gray4 )Set (x ,y int ,c _df .Color ){if x >=_eacge .Width ||y >=_eacge .Height {return ;};_aef :=Gray4Model .Convert (c ).(_df .Gray );
|
|
_eacge .setGray (x ,y ,_aef );};func (_ebae *Gray8 )Base ()*ImageBase {return &_ebae .ImageBase };func _cdg (_ccde _b .Image ,_acdd Image ,_gadc _b .Rectangle ){if _aaaa ,_bedd :=_ccde .(SMasker );_bedd &&_aaaa .HasAlpha (){_acdd .(SMasker ).MakeAlpha ();
|
|
};_cdf (_ccde ,_acdd ,_gadc );};func _afce (_bdeg _b .Image )(Image ,error ){if _babbe ,_cbef :=_bdeg .(*Gray8 );_cbef {return _babbe .Copy (),nil ;};_gffa :=_bdeg .Bounds ();_cdaa ,_cedb :=NewImage (_gffa .Max .X ,_gffa .Max .Y ,8,1,nil ,nil ,nil );if _cedb !=nil {return nil ,_cedb ;
|
|
};_dbfg (_bdeg ,_cdaa ,_gffa );return _cdaa ,nil ;};func (_dba *Gray2 )ColorModel ()_df .Model {return Gray2Model };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 ,_dc .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 (_fbgg *NRGBA32 )Base ()*ImageBase {return &_fbgg .ImageBase };func _afc (_gfa _df .Color )_df .Color {_egdd :=_df .GrayModel .Convert (_gfa ).(_df .Gray );return _abg (_egdd );};var _ Gray =&Monochrome {};func ImgToBinary (i _b .Image ,threshold uint8 )*_b .Gray {switch _bddfa :=i .(type ){case *_b .Gray :if _fafg (_bddfa ){return _bddfa ;
|
|
};return _gdcf (_bddfa ,threshold );case *_b .Gray16 :return _aede (_bddfa ,threshold );default:return _cdd (_bddfa ,threshold );};};func (_gffb *CMYK32 )Validate ()error {if len (_gffb .Data )!=4*_gffb .Width *_gffb .Height {return _f .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 (_efdb *NRGBA32 )ColorModel ()_df .Model {return _df .NRGBAModel };var _ _b .Image =&Monochrome {};func (_cbdd *Monochrome )Base ()*ImageBase {return &_cbdd .ImageBase };func ColorAtCMYK (x ,y ,width int ,data []byte ,decode []float64 )(_df .CMYK ,error ){_fdb :=4*(y *width +x );
|
|
if _fdb +3>=len (data ){return _df .CMYK {},_dc .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 [_fdb ]&0xff;M :=data [_fdb +1]&0xff;Y :=data [_fdb +2]&0xff;K :=data [_fdb +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 _df .CMYK {C :C ,M :M ,Y :Y ,K :K },nil ;};func (_ccda *Gray16 )GrayAt (x ,y int )_df .Gray {_afgfg ,_ :=_ccda .ColorAt (x ,y );
|
|
return _df .Gray {Y :uint8 (_afgfg .(_df .Gray16 ).Y >>8)};};func _dbce (_gfbd _df .NRGBA64 )_df .RGBA {_eacg ,_cdfa ,_egag ,_adf :=_gfbd .RGBA ();return _df .RGBA {R :uint8 (_eacg >>8),G :uint8 (_cdfa >>8),B :uint8 (_egag >>8),A :uint8 (_adf >>8)};};func ColorAtNRGBA64 (x ,y ,width int ,data ,alpha []byte ,decode []float64 )(_df .NRGBA64 ,error ){_bbef :=(y *width +x )*2;
|
|
_ddaa :=_bbef *3;if _ddaa +5>=len (data ){return _df .NRGBA64 {},_dc .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 _gbgd =0xffff;_afde :=uint16 (_gbgd );if alpha !=nil &&len (alpha )> _bbef +1{_afde =uint16 (alpha [_bbef ])<<8|uint16 (alpha [_bbef +1]);};_dced :=uint16 (data [_ddaa ])<<8|uint16 (data [_ddaa +1]);_dee :=uint16 (data [_ddaa +2])<<8|uint16 (data [_ddaa +3]);
|
|
_aacb :=uint16 (data [_ddaa +4])<<8|uint16 (data [_ddaa +5]);if len (decode )==6{_dced =uint16 (uint64 (LinearInterpolate (float64 (_dced ),0,65535,decode [0],decode [1]))&_gbgd );_dee =uint16 (uint64 (LinearInterpolate (float64 (_dee ),0,65535,decode [2],decode [3]))&_gbgd );
|
|
_aacb =uint16 (uint64 (LinearInterpolate (float64 (_aacb ),0,65535,decode [4],decode [5]))&_gbgd );};return _df .NRGBA64 {R :_dced ,G :_dee ,B :_aacb ,A :_afde },nil ;};func (_bagc *Monochrome )Histogram ()(_ggfb [256]int ){for _ ,_baca :=range _bagc .Data {_ggfb [0xff]+=int (_bgge [_bagc .Data [_baca ]]);
|
|
};return _ggfb ;};func _bcca (_ffgb _b .Image ,_agbbd Image ,_cdfd _b .Rectangle ){if _cbbcg ,_cbfa :=_ffgb .(SMasker );_cbfa &&_cbbcg .HasAlpha (){_agbbd .(SMasker ).MakeAlpha ();};switch _edee :=_ffgb .(type ){case Gray :_dead (_edee ,_agbbd .(NRGBA ),_cdfd );
|
|
case NRGBA :_cfbec (_edee ,_agbbd .(NRGBA ),_cdfd );case *_b .NYCbCrA :_dbgg (_edee ,_agbbd .(NRGBA ),_cdfd );case CMYK :_dfcd (_edee ,_agbbd .(NRGBA ),_cdfd );case RGBA :_fgbd (_edee ,_agbbd .(NRGBA ),_cdfd );case nrgba64 :_agcb (_edee ,_agbbd .(NRGBA ),_cdfd );
|
|
default:_cdf (_ffgb ,_agbbd ,_cdfd );};};func (_fgb *Gray2 )Copy ()Image {return &Gray2 {ImageBase :_fgb .copy ()}};func _ddabe (_bcgaf *Monochrome ,_efae ,_cbdg ,_cfdd ,_cedc int ,_fecf RasterOperator ,_dabdb *Monochrome ,_gaca ,_fegd int )error {if _bcgaf ==nil {return _f .New ("\u006e\u0069\u006c\u0020\u0027\u0064\u0065\u0073\u0074\u0027\u0020\u0042i\u0074\u006d\u0061\u0070");
|
|
};if _fecf ==PixDst {return nil ;};switch _fecf {case PixClr ,PixSet ,PixNotDst :_dgdcc (_bcgaf ,_efae ,_cbdg ,_cfdd ,_cedc ,_fecf );return nil ;};if _dabdb ==nil {_cb .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 _f .New ("\u006e\u0069l\u0020\u0027\u0073r\u0063\u0027\u0020\u0062\u0069\u0074\u006d\u0061\u0070");};if _dbfa :=_ddfb (_bcgaf ,_efae ,_cbdg ,_cfdd ,_cedc ,_fecf ,_dabdb ,_gaca ,_fegd );_dbfa !=nil {return _dbfa ;};return nil ;};func (_egagb *Gray2 )Histogram ()(_ede [256]int ){for _aaec :=0;
|
|
_aaec < _egagb .Width ;_aaec ++{for _acgca :=0;_acgca < _egagb .Height ;_acgca ++{_ede [_egagb .GrayAt (_aaec ,_acgca ).Y ]++;};};return _ede ;};func (_badd *Gray4 )Copy ()Image {return &Gray4 {ImageBase :_badd .copy ()}};func NewImage (width ,height ,bitsPerComponent ,colorComponents int ,data ,alpha []byte ,decode []float64 )(Image ,error ){_faa :=NewImageBase (width ,height ,bitsPerComponent ,colorComponents ,data ,alpha ,decode );
|
|
var _dcdb Image ;switch colorComponents {case 1:switch bitsPerComponent {case 1:_dcdb =&Monochrome {ImageBase :_faa ,ModelThreshold :0x0f};case 2:_dcdb =&Gray2 {ImageBase :_faa };case 4:_dcdb =&Gray4 {ImageBase :_faa };case 8:_dcdb =&Gray8 {ImageBase :_faa };
|
|
case 16:_dcdb =&Gray16 {ImageBase :_faa };};case 3:switch bitsPerComponent {case 4:_dcdb =&NRGBA16 {ImageBase :_faa };case 8:_dcdb =&NRGBA32 {ImageBase :_faa };case 16:_dcdb =&NRGBA64 {ImageBase :_faa };};case 4:_dcdb =&CMYK32 {ImageBase :_faa };};if _dcdb ==nil {return nil ,ErrInvalidImage ;
|
|
};return _dcdb ,nil ;};func (_beg *Gray2 )Base ()*ImageBase {return &_beg .ImageBase };var _ RGBA =&RGBA32 {};func (_gef *Gray16 )Copy ()Image {return &Gray16 {ImageBase :_gef .copy ()}};var (_ddf =_cd ();_ggc =_fcb ();_acf =_ccca (););func _fgac (_fffbb *Monochrome ,_bfae ,_dge ,_bdad ,_cabb int ,_dafg RasterOperator ,_bcaae *Monochrome ,_aeg ,_fgcf int )error {var (_aabg byte ;
|
|
_acfa int ;_ffge int ;_ffddc ,_bgca int ;_adcc ,_eeef int ;);_fccc :=_bdad >>3;_dagd :=_bdad &7;if _dagd > 0{_aabg =_cdcc [_dagd ];};_acfa =_bcaae .BytesPerLine *_fgcf +(_aeg >>3);_ffge =_fffbb .BytesPerLine *_dge +(_bfae >>3);switch _dafg {case PixSrc :for _adcc =0;
|
|
_adcc < _cabb ;_adcc ++{_ffddc =_acfa +_adcc *_bcaae .BytesPerLine ;_bgca =_ffge +_adcc *_fffbb .BytesPerLine ;for _eeef =0;_eeef < _fccc ;_eeef ++{_fffbb .Data [_bgca ]=_bcaae .Data [_ffddc ];_bgca ++;_ffddc ++;};if _dagd > 0{_fffbb .Data [_bgca ]=_cgdg (_fffbb .Data [_bgca ],_bcaae .Data [_ffddc ],_aabg );
|
|
};};case PixNotSrc :for _adcc =0;_adcc < _cabb ;_adcc ++{_ffddc =_acfa +_adcc *_bcaae .BytesPerLine ;_bgca =_ffge +_adcc *_fffbb .BytesPerLine ;for _eeef =0;_eeef < _fccc ;_eeef ++{_fffbb .Data [_bgca ]=^(_bcaae .Data [_ffddc ]);_bgca ++;_ffddc ++;};if _dagd > 0{_fffbb .Data [_bgca ]=_cgdg (_fffbb .Data [_bgca ],^_bcaae .Data [_ffddc ],_aabg );
|
|
};};case PixSrcOrDst :for _adcc =0;_adcc < _cabb ;_adcc ++{_ffddc =_acfa +_adcc *_bcaae .BytesPerLine ;_bgca =_ffge +_adcc *_fffbb .BytesPerLine ;for _eeef =0;_eeef < _fccc ;_eeef ++{_fffbb .Data [_bgca ]|=_bcaae .Data [_ffddc ];_bgca ++;_ffddc ++;};if _dagd > 0{_fffbb .Data [_bgca ]=_cgdg (_fffbb .Data [_bgca ],_bcaae .Data [_ffddc ]|_fffbb .Data [_bgca ],_aabg );
|
|
};};case PixSrcAndDst :for _adcc =0;_adcc < _cabb ;_adcc ++{_ffddc =_acfa +_adcc *_bcaae .BytesPerLine ;_bgca =_ffge +_adcc *_fffbb .BytesPerLine ;for _eeef =0;_eeef < _fccc ;_eeef ++{_fffbb .Data [_bgca ]&=_bcaae .Data [_ffddc ];_bgca ++;_ffddc ++;};if _dagd > 0{_fffbb .Data [_bgca ]=_cgdg (_fffbb .Data [_bgca ],_bcaae .Data [_ffddc ]&_fffbb .Data [_bgca ],_aabg );
|
|
};};case PixSrcXorDst :for _adcc =0;_adcc < _cabb ;_adcc ++{_ffddc =_acfa +_adcc *_bcaae .BytesPerLine ;_bgca =_ffge +_adcc *_fffbb .BytesPerLine ;for _eeef =0;_eeef < _fccc ;_eeef ++{_fffbb .Data [_bgca ]^=_bcaae .Data [_ffddc ];_bgca ++;_ffddc ++;};if _dagd > 0{_fffbb .Data [_bgca ]=_cgdg (_fffbb .Data [_bgca ],_bcaae .Data [_ffddc ]^_fffbb .Data [_bgca ],_aabg );
|
|
};};case PixNotSrcOrDst :for _adcc =0;_adcc < _cabb ;_adcc ++{_ffddc =_acfa +_adcc *_bcaae .BytesPerLine ;_bgca =_ffge +_adcc *_fffbb .BytesPerLine ;for _eeef =0;_eeef < _fccc ;_eeef ++{_fffbb .Data [_bgca ]|=^(_bcaae .Data [_ffddc ]);_bgca ++;_ffddc ++;
|
|
};if _dagd > 0{_fffbb .Data [_bgca ]=_cgdg (_fffbb .Data [_bgca ],^(_bcaae .Data [_ffddc ])|_fffbb .Data [_bgca ],_aabg );};};case PixNotSrcAndDst :for _adcc =0;_adcc < _cabb ;_adcc ++{_ffddc =_acfa +_adcc *_bcaae .BytesPerLine ;_bgca =_ffge +_adcc *_fffbb .BytesPerLine ;
|
|
for _eeef =0;_eeef < _fccc ;_eeef ++{_fffbb .Data [_bgca ]&=^(_bcaae .Data [_ffddc ]);_bgca ++;_ffddc ++;};if _dagd > 0{_fffbb .Data [_bgca ]=_cgdg (_fffbb .Data [_bgca ],^(_bcaae .Data [_ffddc ])&_fffbb .Data [_bgca ],_aabg );};};case PixSrcOrNotDst :for _adcc =0;
|
|
_adcc < _cabb ;_adcc ++{_ffddc =_acfa +_adcc *_bcaae .BytesPerLine ;_bgca =_ffge +_adcc *_fffbb .BytesPerLine ;for _eeef =0;_eeef < _fccc ;_eeef ++{_fffbb .Data [_bgca ]=_bcaae .Data [_ffddc ]|^(_fffbb .Data [_bgca ]);_bgca ++;_ffddc ++;};if _dagd > 0{_fffbb .Data [_bgca ]=_cgdg (_fffbb .Data [_bgca ],_bcaae .Data [_ffddc ]|^(_fffbb .Data [_bgca ]),_aabg );
|
|
};};case PixSrcAndNotDst :for _adcc =0;_adcc < _cabb ;_adcc ++{_ffddc =_acfa +_adcc *_bcaae .BytesPerLine ;_bgca =_ffge +_adcc *_fffbb .BytesPerLine ;for _eeef =0;_eeef < _fccc ;_eeef ++{_fffbb .Data [_bgca ]=_bcaae .Data [_ffddc ]&^(_fffbb .Data [_bgca ]);
|
|
_bgca ++;_ffddc ++;};if _dagd > 0{_fffbb .Data [_bgca ]=_cgdg (_fffbb .Data [_bgca ],_bcaae .Data [_ffddc ]&^(_fffbb .Data [_bgca ]),_aabg );};};case PixNotPixSrcOrDst :for _adcc =0;_adcc < _cabb ;_adcc ++{_ffddc =_acfa +_adcc *_bcaae .BytesPerLine ;_bgca =_ffge +_adcc *_fffbb .BytesPerLine ;
|
|
for _eeef =0;_eeef < _fccc ;_eeef ++{_fffbb .Data [_bgca ]=^(_bcaae .Data [_ffddc ]|_fffbb .Data [_bgca ]);_bgca ++;_ffddc ++;};if _dagd > 0{_fffbb .Data [_bgca ]=_cgdg (_fffbb .Data [_bgca ],^(_bcaae .Data [_ffddc ]|_fffbb .Data [_bgca ]),_aabg );};};
|
|
case PixNotPixSrcAndDst :for _adcc =0;_adcc < _cabb ;_adcc ++{_ffddc =_acfa +_adcc *_bcaae .BytesPerLine ;_bgca =_ffge +_adcc *_fffbb .BytesPerLine ;for _eeef =0;_eeef < _fccc ;_eeef ++{_fffbb .Data [_bgca ]=^(_bcaae .Data [_ffddc ]&_fffbb .Data [_bgca ]);
|
|
_bgca ++;_ffddc ++;};if _dagd > 0{_fffbb .Data [_bgca ]=_cgdg (_fffbb .Data [_bgca ],^(_bcaae .Data [_ffddc ]&_fffbb .Data [_bgca ]),_aabg );};};case PixNotPixSrcXorDst :for _adcc =0;_adcc < _cabb ;_adcc ++{_ffddc =_acfa +_adcc *_bcaae .BytesPerLine ;_bgca =_ffge +_adcc *_fffbb .BytesPerLine ;
|
|
for _eeef =0;_eeef < _fccc ;_eeef ++{_fffbb .Data [_bgca ]=^(_bcaae .Data [_ffddc ]^_fffbb .Data [_bgca ]);_bgca ++;_ffddc ++;};if _dagd > 0{_fffbb .Data [_bgca ]=_cgdg (_fffbb .Data [_bgca ],^(_bcaae .Data [_ffddc ]^_fffbb .Data [_bgca ]),_aabg );};};
|
|
default:_cb .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",_dafg );return _f .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 =&NRGBA32 {};func (_cgfe *RGBA32 )ColorAt (x ,y int )(_df .Color ,error ){return ColorAtRGBA32 (x ,y ,_cgfe .Width ,_cgfe .Data ,_cgfe .Alpha ,_cgfe .Decode );};func (_bag *Monochrome )Validate ()error {if len (_bag .Data )!=_bag .Height *_bag .BytesPerLine {return ErrInvalidImage ;
|
|
};return nil ;};func (_efc *Monochrome )GrayAt (x ,y int )_df .Gray {_dfa ,_ :=ColorAtGray1BPC (x ,y ,_efc .BytesPerLine ,_efc .Data ,_efc .Decode );return _dfa ;};func _gffeb (_efd _df .Gray )_df .RGBA {return _df .RGBA {R :_efd .Y ,G :_efd .Y ,B :_efd .Y ,A :0xff}};
|
|
func NextPowerOf2 (n uint )uint {if IsPowerOf2 (n ){return n ;};return 1<<(_fbcg (n )+1);};func _bfg (_cdc _df .NRGBA )_df .CMYK {_accf ,_daae ,_geca ,_ :=_cdc .RGBA ();_edcd ,_efa ,_dabd ,_dgca :=_df .RGBToCMYK (uint8 (_accf >>8),uint8 (_daae >>8),uint8 (_geca >>8));
|
|
return _df .CMYK {C :_edcd ,M :_efa ,Y :_dabd ,K :_dgca };};var (MonochromeConverter =ConverterFunc (_cfa );Gray2Converter =ConverterFunc (_dgce );Gray4Converter =ConverterFunc (_ead );GrayConverter =ConverterFunc (_afce );Gray16Converter =ConverterFunc (_cfgg );
|
|
NRGBA16Converter =ConverterFunc (_fbfb );NRGBAConverter =ConverterFunc (_bcdab );NRGBA64Converter =ConverterFunc (_fbec );RGBAConverter =ConverterFunc (_bafd );CMYKConverter =ConverterFunc (_adb ););func (_ccae *Monochrome )Set (x ,y int ,c _df .Color ){_bace :=y *_ccae .BytesPerLine +x >>3;
|
|
if _bace > len (_ccae .Data )-1{return ;};_egfd :=_ccae .ColorModel ().Convert (c ).(_df .Gray );_ccae .setGray (x ,_egfd ,_bace );};func (_dcgc *RGBA32 )setRGBA (_fdaa int ,_acbc _df .RGBA ){_egba :=3*_fdaa ;_dcgc .Data [_egba ]=_acbc .R ;_dcgc .Data [_egba +1]=_acbc .G ;
|
|
_dcgc .Data [_egba +2]=_acbc .B ;if _fdaa < len (_dcgc .Alpha ){_dcgc .Alpha [_fdaa ]=_acbc .A ;};};func _egfde (_dcfeb _df .Gray ,_fdcc monochromeModel )_df .Gray {if _dcfeb .Y > uint8 (_fdcc ){return _df .Gray {Y :_c .MaxUint8 };};return _df .Gray {};
|
|
};var _ _b .Image =&NRGBA16 {};func ColorAtRGBA32 (x ,y ,width int ,data ,alpha []byte ,decode []float64 )(_df .RGBA ,error ){_daee :=y *width +x ;_agdf :=3*_daee ;if _agdf +2>=len (data ){return _df .RGBA {},_dc .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 );
|
|
};_decf :=uint8 (0xff);if alpha !=nil &&len (alpha )> _daee {_decf =alpha [_daee ];};_ecdb ,_gdfg ,_dccge :=data [_agdf ],data [_agdf +1],data [_agdf +2];if len (decode )==6{_ecdb =uint8 (uint32 (LinearInterpolate (float64 (_ecdb ),0,255,decode [0],decode [1]))&0xff);
|
|
_gdfg =uint8 (uint32 (LinearInterpolate (float64 (_gdfg ),0,255,decode [2],decode [3]))&0xff);_dccge =uint8 (uint32 (LinearInterpolate (float64 (_dccge ),0,255,decode [4],decode [5]))&0xff);};return _df .RGBA {R :_ecdb ,G :_gdfg ,B :_dccge ,A :_decf },nil ;
|
|
};func (_fceb *Monochrome )ReduceBinary (factor float64 )(*Monochrome ,error ){_aaa :=_fbcg (uint (factor ));if !IsPowerOf2 (uint (factor )){_aaa ++;};_cgcb :=make ([]int ,_aaa );for _ggeb :=range _cgcb {_cgcb [_ggeb ]=4;};_dggc ,_gaee :=_cec (_fceb ,_cgcb ...);
|
|
if _gaee !=nil {return nil ,_gaee ;};return _dggc ,nil ;};func init (){_fgfg ()};func (_gceg monochromeModel )Convert (c _df .Color )_df .Color {_bee :=_df .GrayModel .Convert (c ).(_df .Gray );return _egfde (_bee ,_gceg );};func (_dadg *NRGBA64 )ColorModel ()_df .Model {return _df .NRGBA64Model };
|
|
func _gbce (_cdfg Gray ,_ebddf RGBA ,_gcad _b .Rectangle ){for _fdgd :=0;_fdgd < _gcad .Max .X ;_fdgd ++{for _cafe :=0;_cafe < _gcad .Max .Y ;_cafe ++{_ggdb :=_cdfg .GrayAt (_fdgd ,_cafe );_ebddf .SetRGBA (_fdgd ,_cafe ,_gffeb (_ggdb ));};};};func _ead (_bff _b .Image )(Image ,error ){if _bgce ,_daad :=_bff .(*Gray4 );
|
|
_daad {return _bgce .Copy (),nil ;};_dag :=_bff .Bounds ();_gee ,_bcda :=NewImage (_dag .Max .X ,_dag .Max .Y ,4,1,nil ,nil ,nil );if _bcda !=nil {return nil ,_bcda ;};_dbfg (_bff ,_gee ,_dag );return _gee ,nil ;};func _cd ()(_bfd [256]uint16 ){for _bgga :=0;
|
|
_bgga < 256;_bgga ++{if _bgga &0x01!=0{_bfd [_bgga ]|=0x3;};if _bgga &0x02!=0{_bfd [_bgga ]|=0xc;};if _bgga &0x04!=0{_bfd [_bgga ]|=0x30;};if _bgga &0x08!=0{_bfd [_bgga ]|=0xc0;};if _bgga &0x10!=0{_bfd [_bgga ]|=0x300;};if _bgga &0x20!=0{_bfd [_bgga ]|=0xc00;
|
|
};if _bgga &0x40!=0{_bfd [_bgga ]|=0x3000;};if _bgga &0x80!=0{_bfd [_bgga ]|=0xc000;};};return _bfd ;};func _eagg (_gag ,_abcg Gray ,_cbbb _b .Rectangle ){for _gddf :=0;_gddf < _cbbb .Max .X ;_gddf ++{for _adda :=0;_adda < _cbbb .Max .Y ;_adda ++{_abcg .SetGray (_gddf ,_adda ,_gag .GrayAt (_gddf ,_adda ));
|
|
};};};type monochromeThresholdConverter struct{Threshold uint8 ;};func _bde (_gffe _df .Gray )_df .NRGBA {return _df .NRGBA {R :_gffe .Y ,G :_gffe .Y ,B :_gffe .Y ,A :0xff}};func (_gdda *Gray16 )Base ()*ImageBase {return &_gdda .ImageBase };func (_eca *Monochrome )IsUnpadded ()bool {return (_eca .Width *_eca .Height )==len (_eca .Data )};
|
|
func (_gffd *Monochrome )ColorModel ()_df .Model {return MonochromeModel (_gffd .ModelThreshold )};var _ _b .Image =&NRGBA32 {};func (_gfge *Gray2 )Bounds ()_b .Rectangle {return _b .Rectangle {Max :_b .Point {X :_gfge .Width ,Y :_gfge .Height }};};func _gbfa (_ffdb _df .NRGBA64 )_df .NRGBA {return _df .NRGBA {R :uint8 (_ffdb .R >>8),G :uint8 (_ffdb .G >>8),B :uint8 (_ffdb .B >>8),A :uint8 (_ffdb .A >>8)};
|
|
};func _dcfe (_caae ,_ecg CMYK ,_acgcg _b .Rectangle ){for _fdd :=0;_fdd < _acgcg .Max .X ;_fdd ++{for _ccg :=0;_ccg < _acgcg .Max .Y ;_ccg ++{_ecg .SetCMYK (_fdd ,_ccg ,_caae .CMYKAt (_fdd ,_ccg ));};};};func _fbfb (_fddde _b .Image )(Image ,error ){if _ebed ,_bcbgb :=_fddde .(*NRGBA16 );
|
|
_bcbgb {return _ebed .Copy (),nil ;};_cdbc :=_fddde .Bounds ();_ebcba ,_gbec :=NewImage (_cdbc .Max .X ,_cdbc .Max .Y ,4,3,nil ,nil ,nil );if _gbec !=nil {return nil ,_gbec ;};_bcca (_fddde ,_ebcba ,_cdbc );return _ebcba ,nil ;};func _ecbc (_gdec []byte ,_bcffa Image )error {_ceca :=true ;
|
|
for _ffdg :=0;_ffdg < len (_gdec );_ffdg ++{if _gdec [_ffdg ]!=0xff{_ceca =false ;break ;};};if _ceca {switch _ggga :=_bcffa .(type ){case *NRGBA32 :_ggga .Alpha =nil ;case *NRGBA64 :_ggga .Alpha =nil ;default:return _dc .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",_bcffa );
|
|
};};return nil ;};var _ Gray =&Gray2 {};func (_baf *Gray16 )ColorAt (x ,y int )(_df .Color ,error ){return ColorAtGray16BPC (x ,y ,_baf .BytesPerLine ,_baf .Data ,_baf .Decode );};func (_ceeg *Monochrome )SetGray (x ,y int ,g _df .Gray ){_bdcbc :=y *_ceeg .BytesPerLine +x >>3;
|
|
if _bdcbc > len (_ceeg .Data )-1{return ;};g =_egfde (g ,monochromeModel (_ceeg .ModelThreshold ));_ceeg .setGray (x ,g ,_bdcbc );};func (_acgc *CMYK32 )Copy ()Image {return &CMYK32 {ImageBase :_acgc .copy ()}};func (_egedb *Gray4 )Validate ()error {if len (_egedb .Data )!=_egedb .Height *_egedb .BytesPerLine {return ErrInvalidImage ;
|
|
};return nil ;};func _gegg (_dgdf _df .NRGBA )_df .RGBA {_bgdg ,_caad ,_aece ,_ffgd :=_dgdf .RGBA ();return _df .RGBA {R :uint8 (_bgdg >>8),G :uint8 (_caad >>8),B :uint8 (_aece >>8),A :uint8 (_ffgd >>8)};};func AddDataPadding (width ,height ,bitsPerComponent ,colorComponents int ,data []byte )([]byte ,error ){_egede :=BytesPerLine (width ,bitsPerComponent ,colorComponents );
|
|
if _egede ==width *colorComponents *bitsPerComponent /8{return data ,nil ;};_ddda :=width *colorComponents *bitsPerComponent ;_gea :=_egede *8;_gege :=8-(_gea -_ddda );_eada :=_cc .NewReader (data );_fdfb :=_egede -1;_fcfe :=make ([]byte ,_fdfb );_eaab :=make ([]byte ,height *_egede );
|
|
_defa :=_cc .NewWriterMSB (_eaab );var _cbddf uint64 ;var _efbe error ;for _ccgbd :=0;_ccgbd < height ;_ccgbd ++{_ ,_efbe =_eada .Read (_fcfe );if _efbe !=nil {return nil ,_efbe ;};_ ,_efbe =_defa .Write (_fcfe );if _efbe !=nil {return nil ,_efbe ;};_cbddf ,_efbe =_eada .ReadBits (byte (_gege ));
|
|
if _efbe !=nil {return nil ,_efbe ;};_ ,_efbe =_defa .WriteBits (_cbddf ,_gege );if _efbe !=nil {return nil ,_efbe ;};_defa .FinishByte ();};return _eaab ,nil ;};func (_gbcfb *NRGBA64 )ColorAt (x ,y int )(_df .Color ,error ){return ColorAtNRGBA64 (x ,y ,_gbcfb .Width ,_gbcfb .Data ,_gbcfb .Alpha ,_gbcfb .Decode );
|
|
};func _efgg (_ebcc ,_gaed int )*Monochrome {return &Monochrome {ImageBase :NewImageBase (_ebcc ,_gaed ,1,1,nil ,nil ,nil ),ModelThreshold :0x0f};};func (_gcac *Gray2 )ColorAt (x ,y int )(_df .Color ,error ){return ColorAtGray2BPC (x ,y ,_gcac .BytesPerLine ,_gcac .Data ,_gcac .Decode );
|
|
};func _cda (_febd _df .RGBA )_df .Gray {_agea :=(19595*uint32 (_febd .R )+38470*uint32 (_febd .G )+7471*uint32 (_febd .B )+1<<7)>>16;return _df .Gray {Y :uint8 (_agea )};};const (_bdge shift =iota ;_ecgfe ;);func _fgf (_aefd CMYK ,_afac Gray ,_beae _b .Rectangle ){for _ddfe :=0;
|
|
_ddfe < _beae .Max .X ;_ddfe ++{for _bdegd :=0;_bdegd < _beae .Max .Y ;_bdegd ++{_gecd :=_befa (_aefd .CMYKAt (_ddfe ,_bdegd ));_afac .SetGray (_ddfe ,_bdegd ,_gecd );};};};func (_cbdag *Monochrome )AddPadding ()(_ecac error ){if _eaf :=((_cbdag .Width *_cbdag .Height )+7)>>3;
|
|
len (_cbdag .Data )< _eaf {return _dc .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 (_cbdag .Data ),_eaf );
|
|
};_fef :=_cbdag .Width %8;if _fef ==0{return nil ;};_cbge :=_cbdag .Width /8;_cfff :=_cc .NewReader (_cbdag .Data );_bfgg :=make ([]byte ,_cbdag .Height *_cbdag .BytesPerLine );_acge :=_cc .NewWriterMSB (_bfgg );_acfg :=make ([]byte ,_cbge );var (_eeeg int ;
|
|
_eec uint64 ;);for _eeeg =0;_eeeg < _cbdag .Height ;_eeeg ++{if _ ,_ecac =_cfff .Read (_acfg );_ecac !=nil {return _ecac ;};if _ ,_ecac =_acge .Write (_acfg );_ecac !=nil {return _ecac ;};if _eec ,_ecac =_cfff .ReadBits (byte (_fef ));_ecac !=nil {return _ecac ;
|
|
};if _ecac =_acge .WriteByte (byte (_eec )<<uint (8-_fef ));_ecac !=nil {return _ecac ;};};_cbdag .Data =_acge .Data ();return nil ;};func (_dgcg *CMYK32 )CMYKAt (x ,y int )_df .CMYK {_gbc ,_ :=ColorAtCMYK (x ,y ,_dgcg .Width ,_dgcg .Data ,_dgcg .Decode );
|
|
return _gbc ;};type Gray4 struct{ImageBase };func _ffgc (_fgg NRGBA ,_ebdg RGBA ,_bagb _b .Rectangle ){for _dabb :=0;_dabb < _bagb .Max .X ;_dabb ++{for _cdeg :=0;_cdeg < _bagb .Max .Y ;_cdeg ++{_gabcb :=_fgg .NRGBAAt (_dabb ,_cdeg );_ebdg .SetRGBA (_dabb ,_cdeg ,_gegg (_gabcb ));
|
|
};};};func (_bcgb *Gray2 )GrayAt (x ,y int )_df .Gray {_ddee ,_ :=ColorAtGray2BPC (x ,y ,_bcgb .BytesPerLine ,_bcgb .Data ,_bcgb .Decode );return _ddee ;};var _ _b .Image =&NRGBA64 {};func (_aca *Gray8 )Bounds ()_b .Rectangle {return _b .Rectangle {Max :_b .Point {X :_aca .Width ,Y :_aca .Height }};
|
|
};func _bfca (_fdf _df .Gray )_df .Gray {_ffff :=_fdf .Y >>6;_ffff |=_ffff <<2;_fdf .Y =_ffff |_ffff <<4;return _fdf ;};func (_bbca *RGBA32 )Bounds ()_b .Rectangle {return _b .Rectangle {Max :_b .Point {X :_bbca .Width ,Y :_bbca .Height }};};func _gfdf (_agebc _df .Color )_df .Color {_ggebf :=_df .NRGBAModel .Convert (_agebc ).(_df .NRGBA );
|
|
return _gfe (_ggebf );};type Gray8 struct{ImageBase };func (_cgc *CMYK32 )At (x ,y int )_df .Color {_bgd ,_ :=_cgc .ColorAt (x ,y );return _bgd };func (_agb *CMYK32 )SetCMYK (x ,y int ,c _df .CMYK ){_eaga :=4*(y *_agb .Width +x );if _eaga +3>=len (_agb .Data ){return ;
|
|
};_agb .Data [_eaga ]=c .C ;_agb .Data [_eaga +1]=c .M ;_agb .Data [_eaga +2]=c .Y ;_agb .Data [_eaga +3]=c .K ;};type nrgba64 interface{NRGBA64At (_ebaed ,_gefc int )_df .NRGBA64 ;SetNRGBA64 (_cdca ,_beef int ,_dcda _df .NRGBA64 );};func (_dfac *RGBA32 )SetRGBA (x ,y int ,c _df .RGBA ){_gcdd :=y *_dfac .Width +x ;
|
|
_fddb :=3*_gcdd ;if _fddb +2>=len (_dfac .Data ){return ;};_dfac .setRGBA (_gcdd ,c );};func (_gadf *NRGBA32 )setRGBA (_gcdg int ,_aabcc _df .NRGBA ){_feeaa :=3*_gcdg ;_gadf .Data [_feeaa ]=_aabcc .R ;_gadf .Data [_feeaa +1]=_aabcc .G ;_gadf .Data [_feeaa +2]=_aabcc .B ;
|
|
if _gcdg < len (_gadf .Alpha ){_gadf .Alpha [_gcdg ]=_aabcc .A ;};};func (_aae *Monochrome )Copy ()Image {return &Monochrome {ImageBase :_aae .ImageBase .copy (),ModelThreshold :_aae .ModelThreshold };};func _bcc (_adc ,_ffc *Monochrome ,_gaae []byte ,_bad int )(_dcc error ){var (_gaag ,_gcaf ,_dca ,_ddde ,_gce ,_bbg ,_afg ,_gfd int ;
|
|
_fcbf ,_caca uint32 ;_fbg ,_aab byte ;_ega uint16 ;);_bbda :=make ([]byte ,4);_ag :=make ([]byte ,4);for _dca =0;_dca < _adc .Height -1;_dca ,_ddde =_dca +2,_ddde +1{_gaag =_dca *_adc .BytesPerLine ;_gcaf =_ddde *_ffc .BytesPerLine ;for _gce ,_bbg =0,0;
|
|
_gce < _bad ;_gce ,_bbg =_gce +4,_bbg +1{for _afg =0;_afg < 4;_afg ++{_gfd =_gaag +_gce +_afg ;if _gfd <=len (_adc .Data )-1&&_gfd < _gaag +_adc .BytesPerLine {_bbda [_afg ]=_adc .Data [_gfd ];}else {_bbda [_afg ]=0x00;};_gfd =_gaag +_adc .BytesPerLine +_gce +_afg ;
|
|
if _gfd <=len (_adc .Data )-1&&_gfd < _gaag +(2*_adc .BytesPerLine ){_ag [_afg ]=_adc .Data [_gfd ];}else {_ag [_afg ]=0x00;};};_fcbf =_ce .BigEndian .Uint32 (_bbda );_caca =_ce .BigEndian .Uint32 (_ag );_caca |=_fcbf ;_caca |=_caca <<1;_caca &=0xaaaaaaaa;
|
|
_fcbf =_caca |(_caca <<7);_fbg =byte (_fcbf >>24);_aab =byte ((_fcbf >>8)&0xff);_gfd =_gcaf +_bbg ;if _gfd +1==len (_ffc .Data )-1||_gfd +1>=_gcaf +_ffc .BytesPerLine {_ffc .Data [_gfd ]=_gaae [_fbg ];}else {_ega =(uint16 (_gaae [_fbg ])<<8)|uint16 (_gaae [_aab ]);
|
|
if _dcc =_ffc .setTwoBytes (_gfd ,_ega );_dcc !=nil {return _dc .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",_gfd );
|
|
};_bbg ++;};};};return nil ;};var _ _b .Image =&Gray2 {};var ErrInvalidImage =_f .New ("i\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0069\u006da\u0067\u0065\u0020\u0064\u0061\u0074\u0061 s\u0069\u007a\u0065\u0020f\u006f\u0072\u0020\u0070\u0072\u006f\u0076\u0069\u0064ed\u0020\u0064i\u006d\u0065\u006e\u0073\u0069\u006f\u006e\u0073");
|
|
func _ecdd (_fdbb *Monochrome ,_bddf ,_dbfec int ,_adef ,_ebeg int ,_caee RasterOperator ){var (_gecf bool ;_gggg bool ;_cdcfb int ;_cfffd int ;_cbbd int ;_ebdd int ;_ggbb bool ;_bddb byte ;);_dgbd :=8-(_bddf &7);_ffdc :=_ddag [_dgbd ];_fbcf :=_fdbb .BytesPerLine *_dbfec +(_bddf >>3);
|
|
if _adef < _dgbd {_gecf =true ;_ffdc &=_cdcc [8-_dgbd +_adef ];};if !_gecf {_cdcfb =(_adef -_dgbd )>>3;if _cdcfb !=0{_gggg =true ;_cfffd =_fbcf +1;};};_cbbd =(_bddf +_adef )&7;if !(_gecf ||_cbbd ==0){_ggbb =true ;_bddb =_cdcc [_cbbd ];_ebdd =_fbcf +1+_cdcfb ;
|
|
};var _caed ,_fdbed int ;switch _caee {case PixClr :for _caed =0;_caed < _ebeg ;_caed ++{_fdbb .Data [_fbcf ]=_cgdg (_fdbb .Data [_fbcf ],0x0,_ffdc );_fbcf +=_fdbb .BytesPerLine ;};if _gggg {for _caed =0;_caed < _ebeg ;_caed ++{for _fdbed =0;_fdbed < _cdcfb ;
|
|
_fdbed ++{_fdbb .Data [_cfffd +_fdbed ]=0x0;};_cfffd +=_fdbb .BytesPerLine ;};};if _ggbb {for _caed =0;_caed < _ebeg ;_caed ++{_fdbb .Data [_ebdd ]=_cgdg (_fdbb .Data [_ebdd ],0x0,_bddb );_ebdd +=_fdbb .BytesPerLine ;};};case PixSet :for _caed =0;_caed < _ebeg ;
|
|
_caed ++{_fdbb .Data [_fbcf ]=_cgdg (_fdbb .Data [_fbcf ],0xff,_ffdc );_fbcf +=_fdbb .BytesPerLine ;};if _gggg {for _caed =0;_caed < _ebeg ;_caed ++{for _fdbed =0;_fdbed < _cdcfb ;_fdbed ++{_fdbb .Data [_cfffd +_fdbed ]=0xff;};_cfffd +=_fdbb .BytesPerLine ;
|
|
};};if _ggbb {for _caed =0;_caed < _ebeg ;_caed ++{_fdbb .Data [_ebdd ]=_cgdg (_fdbb .Data [_ebdd ],0xff,_bddb );_ebdd +=_fdbb .BytesPerLine ;};};case PixNotDst :for _caed =0;_caed < _ebeg ;_caed ++{_fdbb .Data [_fbcf ]=_cgdg (_fdbb .Data [_fbcf ],^_fdbb .Data [_fbcf ],_ffdc );
|
|
_fbcf +=_fdbb .BytesPerLine ;};if _gggg {for _caed =0;_caed < _ebeg ;_caed ++{for _fdbed =0;_fdbed < _cdcfb ;_fdbed ++{_fdbb .Data [_cfffd +_fdbed ]=^(_fdbb .Data [_cfffd +_fdbed ]);};_cfffd +=_fdbb .BytesPerLine ;};};if _ggbb {for _caed =0;_caed < _ebeg ;
|
|
_caed ++{_fdbb .Data [_ebdd ]=_cgdg (_fdbb .Data [_ebdd ],^_fdbb .Data [_ebdd ],_bddb );_ebdd +=_fdbb .BytesPerLine ;};};};};func (_ccdd *RGBA32 )At (x ,y int )_df .Color {_gabc ,_ :=_ccdd .ColorAt (x ,y );return _gabc };func _ef (_fa *Monochrome ,_ge int )(*Monochrome ,error ){if _fa ==nil {return nil ,_f .New ("\u0073o\u0075r\u0063\u0065\u0020\u006e\u006ft\u0020\u0064e\u0066\u0069\u006e\u0065\u0064");
|
|
};if _ge ==1{return _fa .copy (),nil ;};if !IsPowerOf2 (uint (_ge )){return nil ,_dc .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",_ge );
|
|
};_bf :=_geg (_ge );return _ee (_fa ,_ge ,_bf );};func (_cced *RGBA32 )Set (x ,y int ,c _df .Color ){_bfeag :=y *_cced .Width +x ;_dacd :=3*_bfeag ;if _dacd +2>=len (_cced .Data ){return ;};_daef :=_df .RGBAModel .Convert (c ).(_df .RGBA );_cced .setRGBA (_bfeag ,_daef );
|
|
};type Image interface{_e .Image ;Base ()*ImageBase ;Copy ()Image ;Pix ()[]byte ;ColorAt (_aedg ,_fega int )(_df .Color ,error );Validate ()error ;};func _bcd (_bcbg _df .Color )_df .Color {_bacag :=_df .GrayModel .Convert (_bcbg ).(_df .Gray );return _bfca (_bacag );
|
|
};type Gray16 struct{ImageBase };func _dgce (_bcdd _b .Image )(Image ,error ){if _egd ,_feeg :=_bcdd .(*Gray2 );_feeg {return _egd .Copy (),nil ;};_bbbb :=_bcdd .Bounds ();_aaba ,_ecbe :=NewImage (_bbbb .Max .X ,_bbbb .Max .Y ,2,1,nil ,nil ,nil );if _ecbe !=nil {return nil ,_ecbe ;
|
|
};_dbfg (_bcdd ,_aaba ,_bbbb );return _aaba ,nil ;};func (_ccgd *Gray8 )Copy ()Image {return &Gray8 {ImageBase :_ccgd .copy ()}};func (_bdg *ImageBase )newAlpha (){_cdaga :=BytesPerLine (_bdg .Width ,_bdg .BitsPerComponent ,1);_bdg .Alpha =make ([]byte ,_bdg .Height *_cdaga );
|
|
};func (_gddb *Gray8 )Validate ()error {if len (_gddb .Data )!=_gddb .Height *_gddb .BytesPerLine {return ErrInvalidImage ;};return nil ;};func ColorAtNRGBA (x ,y ,width ,bytesPerLine ,bitsPerColor int ,data ,alpha []byte ,decode []float64 )(_df .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 ,_dc .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 _fbbc (_ecfb int ,_dcba int )int {if _ecfb < _dcba {return _ecfb ;};return _dcba ;};func _dddg (_bcf _df .NRGBA )_df .Gray {var _dcfd _df .NRGBA ;if _bcf ==_dcfd {return _df .Gray {Y :0xff};};_gbb ,_bcb ,_gedf ,_ :=_bcf .RGBA ();_fbf :=(19595*_gbb +38470*_bcb +7471*_gedf +1<<15)>>24;
|
|
return _df .Gray {Y :uint8 (_fbf )};};func (_fdae *ImageBase )setByte (_eaadf int ,_cfed byte )error {if _eaadf > len (_fdae .Data )-1{return _f .New ("\u0069n\u0064e\u0078\u0020\u006f\u0075\u0074 \u006f\u0066 \u0072\u0061\u006e\u0067\u0065");};_fdae .Data [_eaadf ]=_cfed ;
|
|
return nil ;};func _gfe (_agca _df .NRGBA )_df .NRGBA {_agca .R =_agca .R >>4|(_agca .R >>4)<<4;_agca .G =_agca .G >>4|(_agca .G >>4)<<4;_agca .B =_agca .B >>4|(_agca .B >>4)<<4;return _agca ;};func _ebbff (_debb _b .Image ,_cfcd Image ,_geabc _b .Rectangle ){if _ffdcd ,_abdg :=_debb .(SMasker );
|
|
_abdg &&_ffdcd .HasAlpha (){_cfcd .(SMasker ).MakeAlpha ();};switch _cagf :=_debb .(type ){case Gray :_gbce (_cagf ,_cfcd .(RGBA ),_geabc );case NRGBA :_ffgc (_cagf ,_cfcd .(RGBA ),_geabc );case *_b .NYCbCrA :_fdfbe (_cagf ,_cfcd .(RGBA ),_geabc );case CMYK :_dfge (_cagf ,_cfcd .(RGBA ),_geabc );
|
|
case RGBA :_gedab (_cagf ,_cfcd .(RGBA ),_geabc );case nrgba64 :_faba (_cagf ,_cfcd .(RGBA ),_geabc );default:_cdf (_debb ,_cfcd ,_geabc );};};func _ade (_eef _df .NRGBA64 )_df .Gray {var _cbg _df .NRGBA64 ;if _eef ==_cbg {return _df .Gray {Y :0xff};};
|
|
_efb ,_gfg ,_eggd ,_ :=_eef .RGBA ();_febe :=(19595*_efb +38470*_gfg +7471*_eggd +1<<15)>>24;return _df .Gray {Y :uint8 (_febe )};};type NRGBA64 struct{ImageBase };func _gbag (_geef _b .Image ,_efga int )(_b .Rectangle ,bool ,[]byte ){_ddeb :=_geef .Bounds ();
|
|
var (_cecg bool ;_fdce []byte ;);switch _eafdc :=_geef .(type ){case SMasker :_cecg =_eafdc .HasAlpha ();case NRGBA ,RGBA ,*_b .RGBA64 ,nrgba64 ,*_b .NYCbCrA :_fdce =make ([]byte ,_ddeb .Max .X *_ddeb .Max .Y *_efga );case *_b .Paletted :var _ddec bool ;
|
|
for _ ,_efgga :=range _eafdc .Palette {_gbae ,_gbcf ,_dcca ,_cbbcf :=_efgga .RGBA ();if _gbae ==0&&_gbcf ==0&&_dcca ==0&&_cbbcf !=0{_ddec =true ;break ;};};if _ddec {_fdce =make ([]byte ,_ddeb .Max .X *_ddeb .Max .Y *_efga );};};return _ddeb ,_cecg ,_fdce ;
|
|
};func (_cgda *ImageBase )setTwoBytes (_eeg int ,_eage uint16 )error {if _eeg +1> len (_cgda .Data )-1{return _f .New ("\u0069n\u0064e\u0078\u0020\u006f\u0075\u0074 \u006f\u0066 \u0072\u0061\u006e\u0067\u0065");};_cgda .Data [_eeg ]=byte ((_eage &0xff00)>>8);
|
|
_cgda .Data [_eeg +1]=byte (_eage &0xff);return nil ;};func _gabd (_ccbfc NRGBA ,_afgb Gray ,_bcgac _b .Rectangle ){for _cfag :=0;_cfag < _bcgac .Max .X ;_cfag ++{for _gac :=0;_gac < _bcgac .Max .Y ;_gac ++{_gad :=_cdee (_ccbfc .NRGBAAt (_cfag ,_gac ));
|
|
_afgb .SetGray (_cfag ,_gac ,_gad );};};};func (_gfgbe *NRGBA64 )Set (x ,y int ,c _df .Color ){_dacb :=(y *_gfgbe .Width +x )*2;_dffc :=_dacb *3;if _dffc +5>=len (_gfgbe .Data ){return ;};_ece :=_df .NRGBA64Model .Convert (c ).(_df .NRGBA64 );_gfgbe .setNRGBA64 (_dffc ,_ece ,_dacb );
|
|
};func _dgb (_gga *Monochrome ,_ccgf ,_egff int ,_ccfa ,_ddgb int ,_aacd RasterOperator ){var (_bbge int ;_dac byte ;_ddc ,_dbbb int ;_bgb int ;);_aecee :=_ccfa >>3;_bcbgd :=_ccfa &7;if _bcbgd > 0{_dac =_cdcc [_bcbgd ];};_bbge =_gga .BytesPerLine *_egff +(_ccgf >>3);
|
|
switch _aacd {case PixClr :for _ddc =0;_ddc < _ddgb ;_ddc ++{_bgb =_bbge +_ddc *_gga .BytesPerLine ;for _dbbb =0;_dbbb < _aecee ;_dbbb ++{_gga .Data [_bgb ]=0x0;_bgb ++;};if _bcbgd > 0{_gga .Data [_bgb ]=_cgdg (_gga .Data [_bgb ],0x0,_dac );};};case PixSet :for _ddc =0;
|
|
_ddc < _ddgb ;_ddc ++{_bgb =_bbge +_ddc *_gga .BytesPerLine ;for _dbbb =0;_dbbb < _aecee ;_dbbb ++{_gga .Data [_bgb ]=0xff;_bgb ++;};if _bcbgd > 0{_gga .Data [_bgb ]=_cgdg (_gga .Data [_bgb ],0xff,_dac );};};case PixNotDst :for _ddc =0;_ddc < _ddgb ;_ddc ++{_bgb =_bbge +_ddc *_gga .BytesPerLine ;
|
|
for _dbbb =0;_dbbb < _aecee ;_dbbb ++{_gga .Data [_bgb ]=^_gga .Data [_bgb ];_bgb ++;};if _bcbgd > 0{_gga .Data [_bgb ]=_cgdg (_gga .Data [_bgb ],^_gga .Data [_bgb ],_dac );};};};};func (_afab *NRGBA16 )SetNRGBA (x ,y int ,c _df .NRGBA ){_feeb :=y *_afab .BytesPerLine +x *3/2;
|
|
if _feeb +1>=len (_afab .Data ){return ;};c =_gfe (c );_afab .setNRGBA (x ,y ,_feeb ,c );};func (_bbad *Gray4 )Base ()*ImageBase {return &_bbad .ImageBase };func _dfge (_dage CMYK ,_dcce RGBA ,_eabf _b .Rectangle ){for _dccae :=0;_dccae < _eabf .Max .X ;
|
|
_dccae ++{for _gebbb :=0;_gebbb < _eabf .Max .Y ;_gebbb ++{_dddaa :=_dage .CMYKAt (_dccae ,_gebbb );_dcce .SetRGBA (_dccae ,_gebbb ,_dab (_dddaa ));};};};func (_fafd *Monochrome )getBitAt (_aabc ,_egec int )bool {_bece :=_egec *_fafd .BytesPerLine +(_aabc >>3);
|
|
_aabb :=_aabc &0x07;_fddd :=uint (7-_aabb );if _bece > len (_fafd .Data )-1{return false ;};if (_fafd .Data [_bece ]>>_fddd )&0x01>=1{return true ;};return false ;};func (_cabc *Gray16 )At (x ,y int )_df .Color {_bdbg ,_ :=_cabc .ColorAt (x ,y );return _bdbg };
|
|
func _dgdcc (_afdb *Monochrome ,_beeb ,_cfbe ,_fcfa ,_ebf int ,_cdfef RasterOperator ){if _beeb < 0{_fcfa +=_beeb ;_beeb =0;};_ddb :=_beeb +_fcfa -_afdb .Width ;if _ddb > 0{_fcfa -=_ddb ;};if _cfbe < 0{_ebf +=_cfbe ;_cfbe =0;};_dgcf :=_cfbe +_ebf -_afdb .Height ;
|
|
if _dgcf > 0{_ebf -=_dgcf ;};if _fcfa <=0||_ebf <=0{return ;};if (_beeb &7)==0{_dgb (_afdb ,_beeb ,_cfbe ,_fcfa ,_ebf ,_cdfef );}else {_ecdd (_afdb ,_beeb ,_cfbe ,_fcfa ,_ebf ,_cdfef );};};func _cce (_bbb ,_ddd int ,_bge []byte )*Monochrome {_cgd :=_efgg (_bbb ,_ddd );
|
|
_cgd .Data =_bge ;return _cgd ;};var _ Image =&CMYK32 {};func (_gbge *ImageBase )getByte (_fefd int )(byte ,error ){if _fefd > len (_gbge .Data )-1||_fefd < 0{return 0,_dc .Errorf ("\u0069\u006e\u0064\u0065x:\u0020\u0025\u0064\u0020\u006f\u0075\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006eg\u0065",_fefd );
|
|
};return _gbge .Data [_fefd ],nil ;};func (_ffca *Gray16 )Set (x ,y int ,c _df .Color ){_acd :=(y *_ffca .BytesPerLine /2+x )*2;if _acd +1>=len (_ffca .Data ){return ;};_daaa :=_df .Gray16Model .Convert (c ).(_df .Gray16 );_ffca .Data [_acd ],_ffca .Data [_acd +1]=uint8 (_daaa .Y >>8),uint8 (_daaa .Y &0xff);
|
|
};func _ddfb (_dbfe *Monochrome ,_bgdgd ,_cccde int ,_ggea ,_ggcbe int ,_gbbb RasterOperator ,_feed *Monochrome ,_aade ,_dfcf int )error {var _ceef ,_bfde ,_fde ,_cbeff int ;if _bgdgd < 0{_aade -=_bgdgd ;_ggea +=_bgdgd ;_bgdgd =0;};if _aade < 0{_bgdgd -=_aade ;
|
|
_ggea +=_aade ;_aade =0;};_ceef =_bgdgd +_ggea -_dbfe .Width ;if _ceef > 0{_ggea -=_ceef ;};_bfde =_aade +_ggea -_feed .Width ;if _bfde > 0{_ggea -=_bfde ;};if _cccde < 0{_dfcf -=_cccde ;_ggcbe +=_cccde ;_cccde =0;};if _dfcf < 0{_cccde -=_dfcf ;_ggcbe +=_dfcf ;
|
|
_dfcf =0;};_fde =_cccde +_ggcbe -_dbfe .Height ;if _fde > 0{_ggcbe -=_fde ;};_cbeff =_dfcf +_ggcbe -_feed .Height ;if _cbeff > 0{_ggcbe -=_cbeff ;};if _ggea <=0||_ggcbe <=0{return nil ;};var _cbce error ;switch {case _bgdgd &7==0&&_aade &7==0:_cbce =_fgac (_dbfe ,_bgdgd ,_cccde ,_ggea ,_ggcbe ,_gbbb ,_feed ,_aade ,_dfcf );
|
|
case _bgdgd &7==_aade &7:_cbce =_fgcb (_dbfe ,_bgdgd ,_cccde ,_ggea ,_ggcbe ,_gbbb ,_feed ,_aade ,_dfcf );default:_cbce =_bdbb (_dbfe ,_bgdgd ,_cccde ,_ggea ,_ggcbe ,_gbbb ,_feed ,_aade ,_dfcf );};if _cbce !=nil {return _cbce ;};return nil ;};func (_abfdd *NRGBA32 )At (x ,y int )_df .Color {_bfdeg ,_ :=_abfdd .ColorAt (x ,y );
|
|
return _bfdeg };func (_cacaf *Gray16 )ColorModel ()_df .Model {return _df .Gray16Model };var _ Image =&NRGBA64 {};func _cgeg (_cbda Gray ,_bada nrgba64 ,_fbc _b .Rectangle ){for _edad :=0;_edad < _fbc .Max .X ;_edad ++{for _gcga :=0;_gcga < _fbc .Max .Y ;
|
|
_gcga ++{_bfbc :=_ade (_bada .NRGBA64At (_edad ,_gcga ));_cbda .SetGray (_edad ,_gcga ,_bfbc );};};};func (_bfbg *monochromeThresholdConverter )Convert (img _b .Image )(Image ,error ){if _adg ,_gdac :=img .(*Monochrome );_gdac {return _adg .Copy (),nil ;
|
|
};_ccbf :=img .Bounds ();_bfgc ,_bfe :=NewImage (_ccbf .Max .X ,_ccbf .Max .Y ,1,1,nil ,nil ,nil );if _bfe !=nil {return nil ,_bfe ;};_bfgc .(*Monochrome ).ModelThreshold =_bfbg .Threshold ;for _fdcd :=0;_fdcd < _ccbf .Max .X ;_fdcd ++{for _abb :=0;_abb < _ccbf .Max .Y ;
|
|
_abb ++{_cbee :=img .At (_fdcd ,_abb );_bfgc .Set (_fdcd ,_abb ,_cbee );};};return _bfgc ,nil ;};type NRGBA16 struct{ImageBase };func _adb (_agf _b .Image )(Image ,error ){if _gaf ,_bdcea :=_agf .(*CMYK32 );_bdcea {return _gaf .Copy (),nil ;};_cadb :=_agf .Bounds ();
|
|
_edd ,_dfdd :=NewImage (_cadb .Max .X ,_cadb .Max .Y ,8,4,nil ,nil ,nil );if _dfdd !=nil {return nil ,_dfdd ;};switch _aag :=_agf .(type ){case CMYK :_dcfe (_aag ,_edd .(CMYK ),_cadb );case Gray :_edce (_aag ,_edd .(CMYK ),_cadb );case NRGBA :_dcgb (_aag ,_edd .(CMYK ),_cadb );
|
|
case RGBA :_dfc (_aag ,_edd .(CMYK ),_cadb );default:_cdf (_agf ,_edd ,_cadb );};return _edd ,nil ;};func (_cdae *Monochrome )InverseData ()error {return _cdae .RasterOperation (0,0,_cdae .Width ,_cdae .Height ,PixNotDst ,nil ,0,0);};func _cfa (_aabf _b .Image )(Image ,error ){if _gaad ,_cggb :=_aabf .(*Monochrome );
|
|
_cggb {return _gaad ,nil ;};_fcgf :=_aabf .Bounds ();var _gedb Gray ;switch _cefe :=_aabf .(type ){case Gray :_gedb =_cefe ;case NRGBA :_gedb =&Gray8 {ImageBase :NewImageBase (_fcgf .Max .X ,_fcgf .Max .Y ,8,1,nil ,nil ,nil )};_gda (_gedb ,_cefe ,_fcgf );
|
|
case nrgba64 :_gedb =&Gray8 {ImageBase :NewImageBase (_fcgf .Max .X ,_fcgf .Max .Y ,8,1,nil ,nil ,nil )};_cgeg (_gedb ,_cefe ,_fcgf );default:_edb ,_ccb :=GrayConverter .Convert (_aabf );if _ccb !=nil {return nil ,_ccb ;};_gedb =_edb .(Gray );};_daab ,_egee :=NewImage (_fcgf .Max .X ,_fcgf .Max .Y ,1,1,nil ,nil ,nil );
|
|
if _egee !=nil {return nil ,_egee ;};_abc :=_daab .(*Monochrome );_eaad :=AutoThresholdTriangle (GrayHistogram (_gedb ));for _bec :=0;_bec < _fcgf .Max .X ;_bec ++{for _ggb :=0;_ggb < _fcgf .Max .Y ;_ggb ++{_cdba :=_egfde (_gedb .GrayAt (_bec ,_ggb ),monochromeModel (_eaad ));
|
|
_abc .SetGray (_bec ,_ggb ,_cdba );};};return _daab ,nil ;};func (_dcd *Monochrome )Scale (scale float64 )(*Monochrome ,error ){var _daeb bool ;_gdcb :=scale ;if scale < 1{_gdcb =1/scale ;_daeb =true ;};_agbf :=NextPowerOf2 (uint (_gdcb ));if InDelta (float64 (_agbf ),_gdcb ,0.001){if _daeb {return _dcd .ReduceBinary (_gdcb );
|
|
};return _dcd .ExpandBinary (int (_agbf ));};_bcg :=int (_c .RoundToEven (float64 (_dcd .Width )*scale ));_cebf :=int (_c .RoundToEven (float64 (_dcd .Height )*scale ));return _dcd .ScaleLow (_bcg ,_cebf );};func _bfed (_ebbc RGBA ,_ccbb Gray ,_cbgg _b .Rectangle ){for _ggcb :=0;
|
|
_ggcb < _cbgg .Max .X ;_ggcb ++{for _ccgb :=0;_ccgb < _cbgg .Max .Y ;_ccgb ++{_gfbf :=_cda (_ebbc .RGBAAt (_ggcb ,_ccgb ));_ccbb .SetGray (_ggcb ,_ccgb ,_gfbf );};};};type Gray2 struct{ImageBase };type Histogramer interface{Histogram ()[256]int ;};func (_aace *NRGBA32 )NRGBAAt (x ,y int )_df .NRGBA {_ageff ,_ :=ColorAtNRGBA32 (x ,y ,_aace .Width ,_aace .Data ,_aace .Alpha ,_aace .Decode );
|
|
return _ageff ;};func _dbgg (_gffdc *_b .NYCbCrA ,_bggd NRGBA ,_fdccc _b .Rectangle ){for _acfge :=0;_acfge < _fdccc .Max .X ;_acfge ++{for _fgae :=0;_fgae < _fdccc .Max .Y ;_fgae ++{_gecc :=_gffdc .NYCbCrAAt (_acfge ,_fgae );_bggd .SetNRGBA (_acfge ,_fgae ,_abdb (_gecc ));
|
|
};};};func _ccca ()(_abd [256]uint64 ){for _efe :=0;_efe < 256;_efe ++{if _efe &0x01!=0{_abd [_efe ]|=0xff;};if _efe &0x02!=0{_abd [_efe ]|=0xff00;};if _efe &0x04!=0{_abd [_efe ]|=0xff0000;};if _efe &0x08!=0{_abd [_efe ]|=0xff000000;};if _efe &0x10!=0{_abd [_efe ]|=0xff00000000;
|
|
};if _efe &0x20!=0{_abd [_efe ]|=0xff0000000000;};if _efe &0x40!=0{_abd [_efe ]|=0xff000000000000;};if _efe &0x80!=0{_abd [_efe ]|=0xff00000000000000;};};return _abd ;};func IsGrayImgBlackAndWhite (i *_b .Gray )bool {return _fafg (i )};func ColorAtGrayscale (x ,y ,bitsPerColor ,bytesPerLine int ,data []byte ,decode []float64 )(_df .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 ,_dc .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 );
|
|
};};type CMYK32 struct{ImageBase };type RGBA32 struct{ImageBase };func (_aagac *NRGBA16 )At (x ,y int )_df .Color {_cccc ,_ :=_aagac .ColorAt (x ,y );return _cccc };func _cff (_ada *Monochrome ,_ca ,_bb int )(*Monochrome ,error ){if _ada ==nil {return nil ,_f .New ("\u0073o\u0075r\u0063\u0065\u0020\u006e\u006ft\u0020\u0064e\u0066\u0069\u006e\u0065\u0064");
|
|
};if _ca <=0||_bb <=0{return nil ,_f .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 _ca ==_bb {if _ca ==1{return _ada .copy (),nil ;};if _ca ==2||_ca ==4||_ca ==8{_dcf ,_bdc :=_ef (_ada ,_ca );
|
|
if _bdc !=nil {return nil ,_bdc ;};return _dcf ,nil ;};};_ff :=_ca *_ada .Width ;_eb :=_bb *_ada .Height ;_acg :=_efgg (_ff ,_eb );_eda :=_acg .BytesPerLine ;var (_dbg ,_gbd ,_daf ,_cac ,_dfg int ;_edg byte ;_ea error ;);for _gbd =0;_gbd < _ada .Height ;
|
|
_gbd ++{_dbg =_bb *_gbd *_eda ;for _daf =0;_daf < _ada .Width ;_daf ++{if _gaa :=_ada .getBitAt (_daf ,_gbd );_gaa {_dfg =_ca *_daf ;for _cac =0;_cac < _ca ;_cac ++{_acg .setIndexedBit (_dbg *8+_dfg +_cac );};};};for _cac =1;_cac < _bb ;_cac ++{_gca :=_dbg +_cac *_eda ;
|
|
for _dbd :=0;_dbd < _eda ;_dbd ++{if _edg ,_ea =_acg .getByte (_dbg +_dbd );_ea !=nil {return nil ,_ea ;};if _ea =_acg .setByte (_gca +_dbd ,_edg );_ea !=nil {return nil ,_ea ;};};};};return _acg ,nil ;};func (_cbcf *Gray4 )At (x ,y int )_df .Color {_dfgg ,_ :=_cbcf .ColorAt (x ,y );
|
|
return _dfgg };func (_bgcb *NRGBA32 )Validate ()error {if len (_bgcb .Data )!=3*_bgcb .Width *_bgcb .Height {return _f .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 _bdbb (_ccdf *Monochrome ,_geb ,_dfec ,_afbe ,_eeca int ,_faef RasterOperator ,_cfagd *Monochrome ,_eaeba ,_abef int )error {var (_abfd bool ;_bffe bool ;_eab byte ;_eacf int ;_fdbe int ;_agfb int ;_bgad int ;_cbf bool ;_afbc int ;
|
|
_dfdf int ;_ccge int ;_gbfg bool ;_bdcd byte ;_cfda int ;_geaa int ;_cdcf int ;_bdde byte ;_fgba int ;_gbff int ;_ecgg uint ;_agee uint ;_ecff byte ;_aegd shift ;_bbec bool ;_cacaa bool ;_geab ,_cdbb int ;);if _eaeba &7!=0{_gbff =8-(_eaeba &7);};if _geb &7!=0{_fdbe =8-(_geb &7);
|
|
};if _gbff ==0&&_fdbe ==0{_ecff =_ddag [0];}else {if _fdbe > _gbff {_ecgg =uint (_fdbe -_gbff );}else {_ecgg =uint (8-(_gbff -_fdbe ));};_agee =8-_ecgg ;_ecff =_ddag [_ecgg ];};if (_geb &7)!=0{_abfd =true ;_eacf =8-(_geb &7);_eab =_ddag [_eacf ];_agfb =_ccdf .BytesPerLine *_dfec +(_geb >>3);
|
|
_bgad =_cfagd .BytesPerLine *_abef +(_eaeba >>3);_fgba =8-(_eaeba &7);if _eacf > _fgba {_aegd =_bdge ;if _afbe >=_gbff {_bbec =true ;};}else {_aegd =_ecgfe ;};};if _afbe < _eacf {_bffe =true ;_eab &=_cdcc [8-_eacf +_afbe ];};if !_bffe {_afbc =(_afbe -_eacf )>>3;
|
|
if _afbc !=0{_cbf =true ;_dfdf =_ccdf .BytesPerLine *_dfec +((_geb +_fdbe )>>3);_ccge =_cfagd .BytesPerLine *_abef +((_eaeba +_fdbe )>>3);};};_cfda =(_geb +_afbe )&7;if !(_bffe ||_cfda ==0){_gbfg =true ;_bdcd =_cdcc [_cfda ];_geaa =_ccdf .BytesPerLine *_dfec +((_geb +_fdbe )>>3)+_afbc ;
|
|
_cdcf =_cfagd .BytesPerLine *_abef +((_eaeba +_fdbe )>>3)+_afbc ;if _cfda > int (_agee ){_cacaa =true ;};};switch _faef {case PixSrc :if _abfd {for _geab =0;_geab < _eeca ;_geab ++{if _aegd ==_bdge {_bdde =_cfagd .Data [_bgad ]<<_ecgg ;if _bbec {_bdde =_cgdg (_bdde ,_cfagd .Data [_bgad +1]>>_agee ,_ecff );
|
|
};}else {_bdde =_cfagd .Data [_bgad ]>>_agee ;};_ccdf .Data [_agfb ]=_cgdg (_ccdf .Data [_agfb ],_bdde ,_eab );_agfb +=_ccdf .BytesPerLine ;_bgad +=_cfagd .BytesPerLine ;};};if _cbf {for _geab =0;_geab < _eeca ;_geab ++{for _cdbb =0;_cdbb < _afbc ;_cdbb ++{_bdde =_cgdg (_cfagd .Data [_ccge +_cdbb ]<<_ecgg ,_cfagd .Data [_ccge +_cdbb +1]>>_agee ,_ecff );
|
|
_ccdf .Data [_dfdf +_cdbb ]=_bdde ;};_dfdf +=_ccdf .BytesPerLine ;_ccge +=_cfagd .BytesPerLine ;};};if _gbfg {for _geab =0;_geab < _eeca ;_geab ++{_bdde =_cfagd .Data [_cdcf ]<<_ecgg ;if _cacaa {_bdde =_cgdg (_bdde ,_cfagd .Data [_cdcf +1]>>_agee ,_ecff );
|
|
};_ccdf .Data [_geaa ]=_cgdg (_ccdf .Data [_geaa ],_bdde ,_bdcd );_geaa +=_ccdf .BytesPerLine ;_cdcf +=_cfagd .BytesPerLine ;};};case PixNotSrc :if _abfd {for _geab =0;_geab < _eeca ;_geab ++{if _aegd ==_bdge {_bdde =_cfagd .Data [_bgad ]<<_ecgg ;if _bbec {_bdde =_cgdg (_bdde ,_cfagd .Data [_bgad +1]>>_agee ,_ecff );
|
|
};}else {_bdde =_cfagd .Data [_bgad ]>>_agee ;};_ccdf .Data [_agfb ]=_cgdg (_ccdf .Data [_agfb ],^_bdde ,_eab );_agfb +=_ccdf .BytesPerLine ;_bgad +=_cfagd .BytesPerLine ;};};if _cbf {for _geab =0;_geab < _eeca ;_geab ++{for _cdbb =0;_cdbb < _afbc ;_cdbb ++{_bdde =_cgdg (_cfagd .Data [_ccge +_cdbb ]<<_ecgg ,_cfagd .Data [_ccge +_cdbb +1]>>_agee ,_ecff );
|
|
_ccdf .Data [_dfdf +_cdbb ]=^_bdde ;};_dfdf +=_ccdf .BytesPerLine ;_ccge +=_cfagd .BytesPerLine ;};};if _gbfg {for _geab =0;_geab < _eeca ;_geab ++{_bdde =_cfagd .Data [_cdcf ]<<_ecgg ;if _cacaa {_bdde =_cgdg (_bdde ,_cfagd .Data [_cdcf +1]>>_agee ,_ecff );
|
|
};_ccdf .Data [_geaa ]=_cgdg (_ccdf .Data [_geaa ],^_bdde ,_bdcd );_geaa +=_ccdf .BytesPerLine ;_cdcf +=_cfagd .BytesPerLine ;};};case PixSrcOrDst :if _abfd {for _geab =0;_geab < _eeca ;_geab ++{if _aegd ==_bdge {_bdde =_cfagd .Data [_bgad ]<<_ecgg ;if _bbec {_bdde =_cgdg (_bdde ,_cfagd .Data [_bgad +1]>>_agee ,_ecff );
|
|
};}else {_bdde =_cfagd .Data [_bgad ]>>_agee ;};_ccdf .Data [_agfb ]=_cgdg (_ccdf .Data [_agfb ],_bdde |_ccdf .Data [_agfb ],_eab );_agfb +=_ccdf .BytesPerLine ;_bgad +=_cfagd .BytesPerLine ;};};if _cbf {for _geab =0;_geab < _eeca ;_geab ++{for _cdbb =0;
|
|
_cdbb < _afbc ;_cdbb ++{_bdde =_cgdg (_cfagd .Data [_ccge +_cdbb ]<<_ecgg ,_cfagd .Data [_ccge +_cdbb +1]>>_agee ,_ecff );_ccdf .Data [_dfdf +_cdbb ]|=_bdde ;};_dfdf +=_ccdf .BytesPerLine ;_ccge +=_cfagd .BytesPerLine ;};};if _gbfg {for _geab =0;_geab < _eeca ;
|
|
_geab ++{_bdde =_cfagd .Data [_cdcf ]<<_ecgg ;if _cacaa {_bdde =_cgdg (_bdde ,_cfagd .Data [_cdcf +1]>>_agee ,_ecff );};_ccdf .Data [_geaa ]=_cgdg (_ccdf .Data [_geaa ],_bdde |_ccdf .Data [_geaa ],_bdcd );_geaa +=_ccdf .BytesPerLine ;_cdcf +=_cfagd .BytesPerLine ;
|
|
};};case PixSrcAndDst :if _abfd {for _geab =0;_geab < _eeca ;_geab ++{if _aegd ==_bdge {_bdde =_cfagd .Data [_bgad ]<<_ecgg ;if _bbec {_bdde =_cgdg (_bdde ,_cfagd .Data [_bgad +1]>>_agee ,_ecff );};}else {_bdde =_cfagd .Data [_bgad ]>>_agee ;};_ccdf .Data [_agfb ]=_cgdg (_ccdf .Data [_agfb ],_bdde &_ccdf .Data [_agfb ],_eab );
|
|
_agfb +=_ccdf .BytesPerLine ;_bgad +=_cfagd .BytesPerLine ;};};if _cbf {for _geab =0;_geab < _eeca ;_geab ++{for _cdbb =0;_cdbb < _afbc ;_cdbb ++{_bdde =_cgdg (_cfagd .Data [_ccge +_cdbb ]<<_ecgg ,_cfagd .Data [_ccge +_cdbb +1]>>_agee ,_ecff );_ccdf .Data [_dfdf +_cdbb ]&=_bdde ;
|
|
};_dfdf +=_ccdf .BytesPerLine ;_ccge +=_cfagd .BytesPerLine ;};};if _gbfg {for _geab =0;_geab < _eeca ;_geab ++{_bdde =_cfagd .Data [_cdcf ]<<_ecgg ;if _cacaa {_bdde =_cgdg (_bdde ,_cfagd .Data [_cdcf +1]>>_agee ,_ecff );};_ccdf .Data [_geaa ]=_cgdg (_ccdf .Data [_geaa ],_bdde &_ccdf .Data [_geaa ],_bdcd );
|
|
_geaa +=_ccdf .BytesPerLine ;_cdcf +=_cfagd .BytesPerLine ;};};case PixSrcXorDst :if _abfd {for _geab =0;_geab < _eeca ;_geab ++{if _aegd ==_bdge {_bdde =_cfagd .Data [_bgad ]<<_ecgg ;if _bbec {_bdde =_cgdg (_bdde ,_cfagd .Data [_bgad +1]>>_agee ,_ecff );
|
|
};}else {_bdde =_cfagd .Data [_bgad ]>>_agee ;};_ccdf .Data [_agfb ]=_cgdg (_ccdf .Data [_agfb ],_bdde ^_ccdf .Data [_agfb ],_eab );_agfb +=_ccdf .BytesPerLine ;_bgad +=_cfagd .BytesPerLine ;};};if _cbf {for _geab =0;_geab < _eeca ;_geab ++{for _cdbb =0;
|
|
_cdbb < _afbc ;_cdbb ++{_bdde =_cgdg (_cfagd .Data [_ccge +_cdbb ]<<_ecgg ,_cfagd .Data [_ccge +_cdbb +1]>>_agee ,_ecff );_ccdf .Data [_dfdf +_cdbb ]^=_bdde ;};_dfdf +=_ccdf .BytesPerLine ;_ccge +=_cfagd .BytesPerLine ;};};if _gbfg {for _geab =0;_geab < _eeca ;
|
|
_geab ++{_bdde =_cfagd .Data [_cdcf ]<<_ecgg ;if _cacaa {_bdde =_cgdg (_bdde ,_cfagd .Data [_cdcf +1]>>_agee ,_ecff );};_ccdf .Data [_geaa ]=_cgdg (_ccdf .Data [_geaa ],_bdde ^_ccdf .Data [_geaa ],_bdcd );_geaa +=_ccdf .BytesPerLine ;_cdcf +=_cfagd .BytesPerLine ;
|
|
};};case PixNotSrcOrDst :if _abfd {for _geab =0;_geab < _eeca ;_geab ++{if _aegd ==_bdge {_bdde =_cfagd .Data [_bgad ]<<_ecgg ;if _bbec {_bdde =_cgdg (_bdde ,_cfagd .Data [_bgad +1]>>_agee ,_ecff );};}else {_bdde =_cfagd .Data [_bgad ]>>_agee ;};_ccdf .Data [_agfb ]=_cgdg (_ccdf .Data [_agfb ],^_bdde |_ccdf .Data [_agfb ],_eab );
|
|
_agfb +=_ccdf .BytesPerLine ;_bgad +=_cfagd .BytesPerLine ;};};if _cbf {for _geab =0;_geab < _eeca ;_geab ++{for _cdbb =0;_cdbb < _afbc ;_cdbb ++{_bdde =_cgdg (_cfagd .Data [_ccge +_cdbb ]<<_ecgg ,_cfagd .Data [_ccge +_cdbb +1]>>_agee ,_ecff );_ccdf .Data [_dfdf +_cdbb ]|=^_bdde ;
|
|
};_dfdf +=_ccdf .BytesPerLine ;_ccge +=_cfagd .BytesPerLine ;};};if _gbfg {for _geab =0;_geab < _eeca ;_geab ++{_bdde =_cfagd .Data [_cdcf ]<<_ecgg ;if _cacaa {_bdde =_cgdg (_bdde ,_cfagd .Data [_cdcf +1]>>_agee ,_ecff );};_ccdf .Data [_geaa ]=_cgdg (_ccdf .Data [_geaa ],^_bdde |_ccdf .Data [_geaa ],_bdcd );
|
|
_geaa +=_ccdf .BytesPerLine ;_cdcf +=_cfagd .BytesPerLine ;};};case PixNotSrcAndDst :if _abfd {for _geab =0;_geab < _eeca ;_geab ++{if _aegd ==_bdge {_bdde =_cfagd .Data [_bgad ]<<_ecgg ;if _bbec {_bdde =_cgdg (_bdde ,_cfagd .Data [_bgad +1]>>_agee ,_ecff );
|
|
};}else {_bdde =_cfagd .Data [_bgad ]>>_agee ;};_ccdf .Data [_agfb ]=_cgdg (_ccdf .Data [_agfb ],^_bdde &_ccdf .Data [_agfb ],_eab );_agfb +=_ccdf .BytesPerLine ;_bgad +=_cfagd .BytesPerLine ;};};if _cbf {for _geab =0;_geab < _eeca ;_geab ++{for _cdbb =0;
|
|
_cdbb < _afbc ;_cdbb ++{_bdde =_cgdg (_cfagd .Data [_ccge +_cdbb ]<<_ecgg ,_cfagd .Data [_ccge +_cdbb +1]>>_agee ,_ecff );_ccdf .Data [_dfdf +_cdbb ]&=^_bdde ;};_dfdf +=_ccdf .BytesPerLine ;_ccge +=_cfagd .BytesPerLine ;};};if _gbfg {for _geab =0;_geab < _eeca ;
|
|
_geab ++{_bdde =_cfagd .Data [_cdcf ]<<_ecgg ;if _cacaa {_bdde =_cgdg (_bdde ,_cfagd .Data [_cdcf +1]>>_agee ,_ecff );};_ccdf .Data [_geaa ]=_cgdg (_ccdf .Data [_geaa ],^_bdde &_ccdf .Data [_geaa ],_bdcd );_geaa +=_ccdf .BytesPerLine ;_cdcf +=_cfagd .BytesPerLine ;
|
|
};};case PixSrcOrNotDst :if _abfd {for _geab =0;_geab < _eeca ;_geab ++{if _aegd ==_bdge {_bdde =_cfagd .Data [_bgad ]<<_ecgg ;if _bbec {_bdde =_cgdg (_bdde ,_cfagd .Data [_bgad +1]>>_agee ,_ecff );};}else {_bdde =_cfagd .Data [_bgad ]>>_agee ;};_ccdf .Data [_agfb ]=_cgdg (_ccdf .Data [_agfb ],_bdde |^_ccdf .Data [_agfb ],_eab );
|
|
_agfb +=_ccdf .BytesPerLine ;_bgad +=_cfagd .BytesPerLine ;};};if _cbf {for _geab =0;_geab < _eeca ;_geab ++{for _cdbb =0;_cdbb < _afbc ;_cdbb ++{_bdde =_cgdg (_cfagd .Data [_ccge +_cdbb ]<<_ecgg ,_cfagd .Data [_ccge +_cdbb +1]>>_agee ,_ecff );_ccdf .Data [_dfdf +_cdbb ]=_bdde |^_ccdf .Data [_dfdf +_cdbb ];
|
|
};_dfdf +=_ccdf .BytesPerLine ;_ccge +=_cfagd .BytesPerLine ;};};if _gbfg {for _geab =0;_geab < _eeca ;_geab ++{_bdde =_cfagd .Data [_cdcf ]<<_ecgg ;if _cacaa {_bdde =_cgdg (_bdde ,_cfagd .Data [_cdcf +1]>>_agee ,_ecff );};_ccdf .Data [_geaa ]=_cgdg (_ccdf .Data [_geaa ],_bdde |^_ccdf .Data [_geaa ],_bdcd );
|
|
_geaa +=_ccdf .BytesPerLine ;_cdcf +=_cfagd .BytesPerLine ;};};case PixSrcAndNotDst :if _abfd {for _geab =0;_geab < _eeca ;_geab ++{if _aegd ==_bdge {_bdde =_cfagd .Data [_bgad ]<<_ecgg ;if _bbec {_bdde =_cgdg (_bdde ,_cfagd .Data [_bgad +1]>>_agee ,_ecff );
|
|
};}else {_bdde =_cfagd .Data [_bgad ]>>_agee ;};_ccdf .Data [_agfb ]=_cgdg (_ccdf .Data [_agfb ],_bdde &^_ccdf .Data [_agfb ],_eab );_agfb +=_ccdf .BytesPerLine ;_bgad +=_cfagd .BytesPerLine ;};};if _cbf {for _geab =0;_geab < _eeca ;_geab ++{for _cdbb =0;
|
|
_cdbb < _afbc ;_cdbb ++{_bdde =_cgdg (_cfagd .Data [_ccge +_cdbb ]<<_ecgg ,_cfagd .Data [_ccge +_cdbb +1]>>_agee ,_ecff );_ccdf .Data [_dfdf +_cdbb ]=_bdde &^_ccdf .Data [_dfdf +_cdbb ];};_dfdf +=_ccdf .BytesPerLine ;_ccge +=_cfagd .BytesPerLine ;};};if _gbfg {for _geab =0;
|
|
_geab < _eeca ;_geab ++{_bdde =_cfagd .Data [_cdcf ]<<_ecgg ;if _cacaa {_bdde =_cgdg (_bdde ,_cfagd .Data [_cdcf +1]>>_agee ,_ecff );};_ccdf .Data [_geaa ]=_cgdg (_ccdf .Data [_geaa ],_bdde &^_ccdf .Data [_geaa ],_bdcd );_geaa +=_ccdf .BytesPerLine ;_cdcf +=_cfagd .BytesPerLine ;
|
|
};};case PixNotPixSrcOrDst :if _abfd {for _geab =0;_geab < _eeca ;_geab ++{if _aegd ==_bdge {_bdde =_cfagd .Data [_bgad ]<<_ecgg ;if _bbec {_bdde =_cgdg (_bdde ,_cfagd .Data [_bgad +1]>>_agee ,_ecff );};}else {_bdde =_cfagd .Data [_bgad ]>>_agee ;};_ccdf .Data [_agfb ]=_cgdg (_ccdf .Data [_agfb ],^(_bdde |_ccdf .Data [_agfb ]),_eab );
|
|
_agfb +=_ccdf .BytesPerLine ;_bgad +=_cfagd .BytesPerLine ;};};if _cbf {for _geab =0;_geab < _eeca ;_geab ++{for _cdbb =0;_cdbb < _afbc ;_cdbb ++{_bdde =_cgdg (_cfagd .Data [_ccge +_cdbb ]<<_ecgg ,_cfagd .Data [_ccge +_cdbb +1]>>_agee ,_ecff );_ccdf .Data [_dfdf +_cdbb ]=^(_bdde |_ccdf .Data [_dfdf +_cdbb ]);
|
|
};_dfdf +=_ccdf .BytesPerLine ;_ccge +=_cfagd .BytesPerLine ;};};if _gbfg {for _geab =0;_geab < _eeca ;_geab ++{_bdde =_cfagd .Data [_cdcf ]<<_ecgg ;if _cacaa {_bdde =_cgdg (_bdde ,_cfagd .Data [_cdcf +1]>>_agee ,_ecff );};_ccdf .Data [_geaa ]=_cgdg (_ccdf .Data [_geaa ],^(_bdde |_ccdf .Data [_geaa ]),_bdcd );
|
|
_geaa +=_ccdf .BytesPerLine ;_cdcf +=_cfagd .BytesPerLine ;};};case PixNotPixSrcAndDst :if _abfd {for _geab =0;_geab < _eeca ;_geab ++{if _aegd ==_bdge {_bdde =_cfagd .Data [_bgad ]<<_ecgg ;if _bbec {_bdde =_cgdg (_bdde ,_cfagd .Data [_bgad +1]>>_agee ,_ecff );
|
|
};}else {_bdde =_cfagd .Data [_bgad ]>>_agee ;};_ccdf .Data [_agfb ]=_cgdg (_ccdf .Data [_agfb ],^(_bdde &_ccdf .Data [_agfb ]),_eab );_agfb +=_ccdf .BytesPerLine ;_bgad +=_cfagd .BytesPerLine ;};};if _cbf {for _geab =0;_geab < _eeca ;_geab ++{for _cdbb =0;
|
|
_cdbb < _afbc ;_cdbb ++{_bdde =_cgdg (_cfagd .Data [_ccge +_cdbb ]<<_ecgg ,_cfagd .Data [_ccge +_cdbb +1]>>_agee ,_ecff );_ccdf .Data [_dfdf +_cdbb ]=^(_bdde &_ccdf .Data [_dfdf +_cdbb ]);};_dfdf +=_ccdf .BytesPerLine ;_ccge +=_cfagd .BytesPerLine ;};};
|
|
if _gbfg {for _geab =0;_geab < _eeca ;_geab ++{_bdde =_cfagd .Data [_cdcf ]<<_ecgg ;if _cacaa {_bdde =_cgdg (_bdde ,_cfagd .Data [_cdcf +1]>>_agee ,_ecff );};_ccdf .Data [_geaa ]=_cgdg (_ccdf .Data [_geaa ],^(_bdde &_ccdf .Data [_geaa ]),_bdcd );_geaa +=_ccdf .BytesPerLine ;
|
|
_cdcf +=_cfagd .BytesPerLine ;};};case PixNotPixSrcXorDst :if _abfd {for _geab =0;_geab < _eeca ;_geab ++{if _aegd ==_bdge {_bdde =_cfagd .Data [_bgad ]<<_ecgg ;if _bbec {_bdde =_cgdg (_bdde ,_cfagd .Data [_bgad +1]>>_agee ,_ecff );};}else {_bdde =_cfagd .Data [_bgad ]>>_agee ;
|
|
};_ccdf .Data [_agfb ]=_cgdg (_ccdf .Data [_agfb ],^(_bdde ^_ccdf .Data [_agfb ]),_eab );_agfb +=_ccdf .BytesPerLine ;_bgad +=_cfagd .BytesPerLine ;};};if _cbf {for _geab =0;_geab < _eeca ;_geab ++{for _cdbb =0;_cdbb < _afbc ;_cdbb ++{_bdde =_cgdg (_cfagd .Data [_ccge +_cdbb ]<<_ecgg ,_cfagd .Data [_ccge +_cdbb +1]>>_agee ,_ecff );
|
|
_ccdf .Data [_dfdf +_cdbb ]=^(_bdde ^_ccdf .Data [_dfdf +_cdbb ]);};_dfdf +=_ccdf .BytesPerLine ;_ccge +=_cfagd .BytesPerLine ;};};if _gbfg {for _geab =0;_geab < _eeca ;_geab ++{_bdde =_cfagd .Data [_cdcf ]<<_ecgg ;if _cacaa {_bdde =_cgdg (_bdde ,_cfagd .Data [_cdcf +1]>>_agee ,_ecff );
|
|
};_ccdf .Data [_geaa ]=_cgdg (_ccdf .Data [_geaa ],^(_bdde ^_ccdf .Data [_geaa ]),_bdcd );_geaa +=_ccdf .BytesPerLine ;_cdcf +=_cfagd .BytesPerLine ;};};default:_cb .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",_faef );
|
|
return _f .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 _gdcf (_cceda *_b .Gray ,_gaab uint8 )*_b .Gray {_gbdc :=_cceda .Bounds ();
|
|
_acefe :=_b .NewGray (_gbdc );for _afdd :=0;_afdd < _gbdc .Dx ();_afdd ++{for _ebec :=0;_ebec < _gbdc .Dy ();_ebec ++{_dcfba :=_cceda .GrayAt (_afdd ,_ebec );_acefe .SetGray (_afdd ,_ebec ,_df .Gray {Y :_gbdg (_dcfba .Y ,_gaab )});};};return _acefe ;};
|
|
type Gray interface{GrayAt (_cfeb ,_gcef int )_df .Gray ;SetGray (_bac ,_bcfc int ,_gbca _df .Gray );};func (_gcdc *CMYK32 )Set (x ,y int ,c _df .Color ){_deg :=4*(y *_gcdc .Width +x );if _deg +3>=len (_gcdc .Data ){return ;};_fbab :=_df .CMYKModel .Convert (c ).(_df .CMYK );
|
|
_gcdc .Data [_deg ]=_fbab .C ;_gcdc .Data [_deg +1]=_fbab .M ;_gcdc .Data [_deg +2]=_fbab .Y ;_gcdc .Data [_deg +3]=_fbab .K ;};func (_fbb *CMYK32 )Base ()*ImageBase {return &_fbb .ImageBase };var _ NRGBA =&NRGBA32 {};func (_ffe *Gray2 )SetGray (x ,y int ,gray _df .Gray ){_cggc :=_bfca (gray );
|
|
_dbbe :=y *_ffe .BytesPerLine ;_ddab :=_dbbe +(x >>2);if _ddab >=len (_ffe .Data ){return ;};_acec :=_cggc .Y >>6;_ffe .Data [_ddab ]=(_ffe .Data [_ddab ]&(^(0xc0>>uint (2*((x )&3)))))|(_acec <<uint (6-2*(x &3)));};func ConverterFunc (converterFunc func (_cgf _b .Image )(Image ,error ))ColorConverter {return colorConverter {_cba :converterFunc };
|
|
};type RasterOperator int ;func (_cbc *Monochrome )ScaleLow (width ,height int )(*Monochrome ,error ){if width < 0||height < 0{return nil ,_f .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");
|
|
};_dbdg :=_efgg (width ,height );_dcbb :=make ([]int ,height );_addd :=make ([]int ,width );_cdce :=float64 (_cbc .Width )/float64 (width );_gbef :=float64 (_cbc .Height )/float64 (height );for _bcga :=0;_bcga < height ;_bcga ++{_dcbb [_bcga ]=int (_c .Min (_gbef *float64 (_bcga )+0.5,float64 (_cbc .Height -1)));
|
|
};for _cacdc :=0;_cacdc < width ;_cacdc ++{_addd [_cacdc ]=int (_c .Min (_cdce *float64 (_cacdc )+0.5,float64 (_cbc .Width -1)));};_aagd :=-1;_edba :=byte (0);for _edgc :=0;_edgc < height ;_edgc ++{_gba :=_dcbb [_edgc ]*_cbc .BytesPerLine ;_eaade :=_edgc *_dbdg .BytesPerLine ;
|
|
for _bdd :=0;_bdd < width ;_bdd ++{_aaf :=_addd [_bdd ];if _aaf !=_aagd {_edba =_cbc .getBit (_gba ,_aaf );if _edba !=0{_dbdg .setBit (_eaade ,_bdd );};_aagd =_aaf ;}else {if _edba !=0{_dbdg .setBit (_eaade ,_bdd );};};};};return _dbdg ,nil ;};func (_egda *NRGBA64 )Validate ()error {if len (_egda .Data )!=3*2*_egda .Width *_egda .Height {return _f .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 _fdfbe (_edaf *_b .NYCbCrA ,_cea RGBA ,_facc _b .Rectangle ){for _abgb :=0;_abgb < _facc .Max .X ;_abgb ++{for _ddeg :=0;_ddeg < _facc .Max .Y ;_ddeg ++{_edgfc :=_edaf .NYCbCrAAt (_abgb ,_ddeg );_cea .SetRGBA (_abgb ,_ddeg ,_gbe (_edgfc ));
|
|
};};};func (_fgfd *ImageBase )setEightPartlyBytes (_abf ,_bdec int ,_daaab uint64 )(_cga error ){var (_bcdc byte ;_aacc int ;);for _gdaa :=1;_gdaa <=_bdec ;_gdaa ++{_aacc =64-_gdaa *8;_bcdc =byte (_daaab >>uint (_aacc )&0xff);if _cga =_fgfd .setByte (_abf +_gdaa -1,_bcdc );
|
|
_cga !=nil {return _cga ;};};_bead :=_fgfd .BytesPerLine *8-_fgfd .Width ;if _bead ==0{return nil ;};_aacc -=8;_bcdc =byte (_daaab >>uint (_aacc )&0xff)<<uint (_bead );if _cga =_fgfd .setByte (_abf +_bdec ,_bcdc );_cga !=nil {return _cga ;};return nil ;
|
|
};type SMasker interface{HasAlpha ()bool ;GetAlpha ()[]byte ;MakeAlpha ();};func _cgdg (_ccga ,_dce ,_adcb byte )byte {return (_ccga &^(_adcb ))|(_dce &_adcb )};func (_efbd *NRGBA16 )setNRGBA (_gdbef ,_gdaad ,_afgfgf int ,_dgba _df .NRGBA ){if _gdbef *3%2==0{_efbd .Data [_afgfgf ]=(_dgba .R >>4)<<4|(_dgba .G >>4);
|
|
_efbd .Data [_afgfgf +1]=(_dgba .B >>4)<<4|(_efbd .Data [_afgfgf +1]&0xf);}else {_efbd .Data [_afgfgf ]=(_efbd .Data [_afgfgf ]&0xf0)|(_dgba .R >>4);_efbd .Data [_afgfgf +1]=(_dgba .G >>4)<<4|(_dgba .B >>4);};if _efbd .Alpha !=nil {_cefce :=_gdaad *BytesPerLine (_efbd .Width ,4,1);
|
|
if _cefce < len (_efbd .Alpha ){if _gdbef %2==0{_efbd .Alpha [_cefce ]=(_dgba .A >>uint (4))<<uint (4)|(_efbd .Alpha [_afgfgf ]&0xf);}else {_efbd .Alpha [_cefce ]=(_efbd .Alpha [_cefce ]&0xf0)|(_dgba .A >>uint (4));};};};};func _aede (_bbadd *_b .Gray16 ,_bfce uint8 )*_b .Gray {_bbdae :=_bbadd .Bounds ();
|
|
_fgag :=_b .NewGray (_bbdae );for _gefd :=0;_gefd < _bbdae .Dx ();_gefd ++{for _gaagf :=0;_gaagf < _bbdae .Dy ();_gaagf ++{_cgbc :=_bbadd .Gray16At (_gefd ,_gaagf );_fgag .SetGray (_gefd ,_gaagf ,_df .Gray {Y :_gbdg (uint8 (_cgbc .Y /256),_bfce )});};};
|
|
return _fgag ;};func InDelta (expected ,current ,delta float64 )bool {_cegb :=expected -current ;if _cegb <=-delta ||_cegb >=delta {return false ;};return true ;};func (_deb *Monochrome )Bounds ()_b .Rectangle {return _b .Rectangle {Max :_b .Point {X :_deb .Width ,Y :_deb .Height }};
|
|
};func _befa (_eae _df .CMYK )_df .Gray {_fca ,_afd ,_egf :=_df .CMYKToRGB (_eae .C ,_eae .M ,_eae .Y ,_eae .K );_bfbb :=(19595*uint32 (_fca )+38470*uint32 (_afd )+7471*uint32 (_egf )+1<<7)>>16;return _df .Gray {Y :uint8 (_bfbb )};};func (_adbd *Gray8 )Histogram ()(_ffcb [256]int ){for _ebe :=0;
|
|
_ebe < len (_adbd .Data );_ebe ++{_ffcb [_adbd .Data [_ebe ]]++;};return _ffcb ;};func (_gacg *ImageBase )copy ()ImageBase {_bbde :=*_gacg ;_bbde .Data =make ([]byte ,len (_gacg .Data ));copy (_bbde .Data ,_gacg .Data );return _bbde ;};func (_gde *NRGBA16 )Validate ()error {if len (_gde .Data )!=3*_gde .Width *_gde .Height /2{return _f .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 (_dgf *RGBA32 )Base ()*ImageBase {return &_dgf .ImageBase };func (_fbea *Gray2 )At (x ,y int )_df .Color {_dgcac ,_ :=_fbea .ColorAt (x ,y );return _dgcac };func (_edgf *Gray2 )Set (x ,y int ,c _df .Color ){if x >=_edgf .Width ||y >=_edgf .Height {return ;
|
|
};_fgc :=Gray2Model .Convert (c ).(_df .Gray );_dcad :=y *_edgf .BytesPerLine ;_aadb :=_dcad +(x >>2);_bbfa :=_fgc .Y >>6;_edgf .Data [_aadb ]=(_edgf .Data [_aadb ]&(^(0xc0>>uint (2*((x )&3)))))|(_bbfa <<uint (6-2*(x &3)));};func _bcdab (_fag _b .Image )(Image ,error ){if _bdfe ,_bgcdf :=_fag .(*NRGBA32 );
|
|
_bgcdf {return _bdfe .Copy (),nil ;};_gagg ,_gbcb ,_cagd :=_gbag (_fag ,1);_gbfd ,_gfgb :=NewImage (_gagg .Max .X ,_gagg .Max .Y ,8,3,nil ,_cagd ,nil );if _gfgb !=nil {return nil ,_gfgb ;};_bcca (_fag ,_gbfd ,_gagg );if len (_cagd )!=0&&!_gbcb {if _adgd :=_ecbc (_cagd ,_gbfd );
|
|
_adgd !=nil {return nil ,_adgd ;};};return _gbfd ,nil ;};func _bafd (_cgbe _b .Image )(Image ,error ){if _dbdc ,_dcbf :=_cgbe .(*RGBA32 );_dcbf {return _dbdc .Copy (),nil ;};_gfeb ,_adbc ,_efge :=_gbag (_cgbe ,1);_dadb :=&RGBA32 {ImageBase :NewImageBase (_gfeb .Max .X ,_gfeb .Max .Y ,8,3,nil ,_efge ,nil )};
|
|
_ebbff (_cgbe ,_dadb ,_gfeb );if len (_efge )!=0&&!_adbc {if _bccc :=_ecbc (_efge ,_dadb );_bccc !=nil {return nil ,_bccc ;};};return _dadb ,nil ;};type ImageBase struct{Width ,Height int ;BitsPerComponent ,ColorComponents int ;Data ,Alpha []byte ;Decode []float64 ;
|
|
BytesPerLine int ;};func _ga (_fd ,_gec *Monochrome )(_a error ){_gc :=_gec .BytesPerLine ;_fae :=_fd .BytesPerLine ;var (_ae byte ;_de uint16 ;_be ,_cee ,_gae ,_cef ,_aa int ;);for _gae =0;_gae < _gec .Height ;_gae ++{_be =_gae *_gc ;_cee =2*_gae *_fae ;
|
|
for _cef =0;_cef < _gc ;_cef ++{_ae =_gec .Data [_be +_cef ];_de =_ddf [_ae ];_aa =_cee +_cef *2;if _fd .BytesPerLine !=_gec .BytesPerLine *2&&(_cef +1)*2> _fd .BytesPerLine {_a =_fd .setByte (_aa ,byte (_de >>8));}else {_a =_fd .setTwoBytes (_aa ,_de );
|
|
};if _a !=nil {return _a ;};};for _cef =0;_cef < _fae ;_cef ++{_aa =_cee +_fae +_cef ;_ae =_fd .Data [_cee +_cef ];if _a =_fd .setByte (_aa ,_ae );_a !=nil {return _a ;};};};return nil ;};func (_cfg *CMYK32 )Bounds ()_b .Rectangle {return _b .Rectangle {Max :_b .Point {X :_cfg .Width ,Y :_cfg .Height }};
|
|
};func _baaf (_affc uint8 )bool {if _affc ==0||_affc ==255{return true ;};return false ;};func _fcb ()(_fbd [256]uint32 ){for _egb :=0;_egb < 256;_egb ++{if _egb &0x01!=0{_fbd [_egb ]|=0xf;};if _egb &0x02!=0{_fbd [_egb ]|=0xf0;};if _egb &0x04!=0{_fbd [_egb ]|=0xf00;
|
|
};if _egb &0x08!=0{_fbd [_egb ]|=0xf000;};if _egb &0x10!=0{_fbd [_egb ]|=0xf0000;};if _egb &0x20!=0{_fbd [_egb ]|=0xf00000;};if _egb &0x40!=0{_fbd [_egb ]|=0xf000000;};if _egb &0x80!=0{_fbd [_egb ]|=0xf0000000;};};return _fbd ;};func (_eafb *Monochrome )RasterOperation (dx ,dy ,dw ,dh int ,op RasterOperator ,src *Monochrome ,sx ,sy int )error {return _ddabe (_eafb ,dx ,dy ,dw ,dh ,op ,src ,sx ,sy );
|
|
};func (_ffdfb *ImageBase )GetAlpha ()[]byte {return _ffdfb .Alpha };type Monochrome struct{ImageBase ;ModelThreshold uint8 ;};var _ Image =&Gray8 {};func _dab (_aec _df .CMYK )_df .RGBA {_bda ,_dbb ,_bcee :=_df .CMYKToRGB (_aec .C ,_aec .M ,_aec .Y ,_aec .K );
|
|
return _df .RGBA {R :_bda ,G :_dbb ,B :_bcee ,A :0xff};};var _ NRGBA =&NRGBA16 {};func (_cccdf *NRGBA16 )NRGBAAt (x ,y int )_df .NRGBA {_dggg ,_ :=ColorAtNRGBA16 (x ,y ,_cccdf .Width ,_cccdf .BytesPerLine ,_cccdf .Data ,_cccdf .Alpha ,_cccdf .Decode );
|
|
return _dggg ;};func _dbfg (_eead _b .Image ,_feea Image ,_ebac _b .Rectangle ){switch _dea :=_eead .(type ){case Gray :_eagg (_dea ,_feea .(Gray ),_ebac );case NRGBA :_gabd (_dea ,_feea .(Gray ),_ebac );case CMYK :_fgf (_dea ,_feea .(Gray ),_ebac );case RGBA :_bfed (_dea ,_feea .(Gray ),_ebac );
|
|
default:_cdf (_eead ,_feea .(Image ),_ebac );};};var _ Image =&NRGBA16 {};func _fgcb (_gcgc *Monochrome ,_dcdd ,_cbcfd ,_cffb ,_fgbb int ,_fdgb RasterOperator ,_fgec *Monochrome ,_fbcd ,_ebbf int )error {var (_caec bool ;_faee bool ;_gedbd int ;_bbag int ;
|
|
_bdgg int ;_gcafa bool ;_eafa byte ;_bddd int ;_fbbb int ;_fcdb int ;_fcdbf ,_bgfd int ;);_fgce :=8-(_dcdd &7);_daabg :=_ddag [_fgce ];_fdccg :=_gcgc .BytesPerLine *_cbcfd +(_dcdd >>3);_dcbc :=_fgec .BytesPerLine *_ebbf +(_fbcd >>3);if _cffb < _fgce {_caec =true ;
|
|
_daabg &=_cdcc [8-_fgce +_cffb ];};if !_caec {_gedbd =(_cffb -_fgce )>>3;if _gedbd > 0{_faee =true ;_bbag =_fdccg +1;_bdgg =_dcbc +1;};};_bddd =(_dcdd +_cffb )&7;if !(_caec ||_bddd ==0){_gcafa =true ;_eafa =_cdcc [_bddd ];_fbbb =_fdccg +1+_gedbd ;_fcdb =_dcbc +1+_gedbd ;
|
|
};switch _fdgb {case PixSrc :for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fdccg ]=_cgdg (_gcgc .Data [_fdccg ],_fgec .Data [_dcbc ],_daabg );_fdccg +=_gcgc .BytesPerLine ;_dcbc +=_fgec .BytesPerLine ;};if _faee {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{for _bgfd =0;
|
|
_bgfd < _gedbd ;_bgfd ++{_gcgc .Data [_bbag +_bgfd ]=_fgec .Data [_bdgg +_bgfd ];};_bbag +=_gcgc .BytesPerLine ;_bdgg +=_fgec .BytesPerLine ;};};if _gcafa {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fbbb ]=_cgdg (_gcgc .Data [_fbbb ],_fgec .Data [_fcdb ],_eafa );
|
|
_fbbb +=_gcgc .BytesPerLine ;_fcdb +=_fgec .BytesPerLine ;};};case PixNotSrc :for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fdccg ]=_cgdg (_gcgc .Data [_fdccg ],^_fgec .Data [_dcbc ],_daabg );_fdccg +=_gcgc .BytesPerLine ;_dcbc +=_fgec .BytesPerLine ;
|
|
};if _faee {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{for _bgfd =0;_bgfd < _gedbd ;_bgfd ++{_gcgc .Data [_bbag +_bgfd ]=^_fgec .Data [_bdgg +_bgfd ];};_bbag +=_gcgc .BytesPerLine ;_bdgg +=_fgec .BytesPerLine ;};};if _gcafa {for _fcdbf =0;_fcdbf < _fgbb ;
|
|
_fcdbf ++{_gcgc .Data [_fbbb ]=_cgdg (_gcgc .Data [_fbbb ],^_fgec .Data [_fcdb ],_eafa );_fbbb +=_gcgc .BytesPerLine ;_fcdb +=_fgec .BytesPerLine ;};};case PixSrcOrDst :for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fdccg ]=_cgdg (_gcgc .Data [_fdccg ],_fgec .Data [_dcbc ]|_gcgc .Data [_fdccg ],_daabg );
|
|
_fdccg +=_gcgc .BytesPerLine ;_dcbc +=_fgec .BytesPerLine ;};if _faee {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{for _bgfd =0;_bgfd < _gedbd ;_bgfd ++{_gcgc .Data [_bbag +_bgfd ]|=_fgec .Data [_bdgg +_bgfd ];};_bbag +=_gcgc .BytesPerLine ;_bdgg +=_fgec .BytesPerLine ;
|
|
};};if _gcafa {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fbbb ]=_cgdg (_gcgc .Data [_fbbb ],_fgec .Data [_fcdb ]|_gcgc .Data [_fbbb ],_eafa );_fbbb +=_gcgc .BytesPerLine ;_fcdb +=_fgec .BytesPerLine ;};};case PixSrcAndDst :for _fcdbf =0;_fcdbf < _fgbb ;
|
|
_fcdbf ++{_gcgc .Data [_fdccg ]=_cgdg (_gcgc .Data [_fdccg ],_fgec .Data [_dcbc ]&_gcgc .Data [_fdccg ],_daabg );_fdccg +=_gcgc .BytesPerLine ;_dcbc +=_fgec .BytesPerLine ;};if _faee {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{for _bgfd =0;_bgfd < _gedbd ;
|
|
_bgfd ++{_gcgc .Data [_bbag +_bgfd ]&=_fgec .Data [_bdgg +_bgfd ];};_bbag +=_gcgc .BytesPerLine ;_bdgg +=_fgec .BytesPerLine ;};};if _gcafa {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fbbb ]=_cgdg (_gcgc .Data [_fbbb ],_fgec .Data [_fcdb ]&_gcgc .Data [_fbbb ],_eafa );
|
|
_fbbb +=_gcgc .BytesPerLine ;_fcdb +=_fgec .BytesPerLine ;};};case PixSrcXorDst :for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fdccg ]=_cgdg (_gcgc .Data [_fdccg ],_fgec .Data [_dcbc ]^_gcgc .Data [_fdccg ],_daabg );_fdccg +=_gcgc .BytesPerLine ;
|
|
_dcbc +=_fgec .BytesPerLine ;};if _faee {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{for _bgfd =0;_bgfd < _gedbd ;_bgfd ++{_gcgc .Data [_bbag +_bgfd ]^=_fgec .Data [_bdgg +_bgfd ];};_bbag +=_gcgc .BytesPerLine ;_bdgg +=_fgec .BytesPerLine ;};};if _gcafa {for _fcdbf =0;
|
|
_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fbbb ]=_cgdg (_gcgc .Data [_fbbb ],_fgec .Data [_fcdb ]^_gcgc .Data [_fbbb ],_eafa );_fbbb +=_gcgc .BytesPerLine ;_fcdb +=_fgec .BytesPerLine ;};};case PixNotSrcOrDst :for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fdccg ]=_cgdg (_gcgc .Data [_fdccg ],^(_fgec .Data [_dcbc ])|_gcgc .Data [_fdccg ],_daabg );
|
|
_fdccg +=_gcgc .BytesPerLine ;_dcbc +=_fgec .BytesPerLine ;};if _faee {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{for _bgfd =0;_bgfd < _gedbd ;_bgfd ++{_gcgc .Data [_bbag +_bgfd ]|=^(_fgec .Data [_bdgg +_bgfd ]);};_bbag +=_gcgc .BytesPerLine ;_bdgg +=_fgec .BytesPerLine ;
|
|
};};if _gcafa {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fbbb ]=_cgdg (_gcgc .Data [_fbbb ],^(_fgec .Data [_fcdb ])|_gcgc .Data [_fbbb ],_eafa );_fbbb +=_gcgc .BytesPerLine ;_fcdb +=_fgec .BytesPerLine ;};};case PixNotSrcAndDst :for _fcdbf =0;
|
|
_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fdccg ]=_cgdg (_gcgc .Data [_fdccg ],^(_fgec .Data [_dcbc ])&_gcgc .Data [_fdccg ],_daabg );_fdccg +=_gcgc .BytesPerLine ;_dcbc +=_fgec .BytesPerLine ;};if _faee {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{for _bgfd =0;
|
|
_bgfd < _gedbd ;_bgfd ++{_gcgc .Data [_bbag +_bgfd ]&=^_fgec .Data [_bdgg +_bgfd ];};_bbag +=_gcgc .BytesPerLine ;_bdgg +=_fgec .BytesPerLine ;};};if _gcafa {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fbbb ]=_cgdg (_gcgc .Data [_fbbb ],^(_fgec .Data [_fcdb ])&_gcgc .Data [_fbbb ],_eafa );
|
|
_fbbb +=_gcgc .BytesPerLine ;_fcdb +=_fgec .BytesPerLine ;};};case PixSrcOrNotDst :for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fdccg ]=_cgdg (_gcgc .Data [_fdccg ],_fgec .Data [_dcbc ]|^(_gcgc .Data [_fdccg ]),_daabg );_fdccg +=_gcgc .BytesPerLine ;
|
|
_dcbc +=_fgec .BytesPerLine ;};if _faee {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{for _bgfd =0;_bgfd < _gedbd ;_bgfd ++{_gcgc .Data [_bbag +_bgfd ]=_fgec .Data [_bdgg +_bgfd ]|^(_gcgc .Data [_bbag +_bgfd ]);};_bbag +=_gcgc .BytesPerLine ;_bdgg +=_fgec .BytesPerLine ;
|
|
};};if _gcafa {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fbbb ]=_cgdg (_gcgc .Data [_fbbb ],_fgec .Data [_fcdb ]|^(_gcgc .Data [_fbbb ]),_eafa );_fbbb +=_gcgc .BytesPerLine ;_fcdb +=_fgec .BytesPerLine ;};};case PixSrcAndNotDst :for _fcdbf =0;
|
|
_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fdccg ]=_cgdg (_gcgc .Data [_fdccg ],_fgec .Data [_dcbc ]&^(_gcgc .Data [_fdccg ]),_daabg );_fdccg +=_gcgc .BytesPerLine ;_dcbc +=_fgec .BytesPerLine ;};if _faee {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{for _bgfd =0;
|
|
_bgfd < _gedbd ;_bgfd ++{_gcgc .Data [_bbag +_bgfd ]=_fgec .Data [_bdgg +_bgfd ]&^(_gcgc .Data [_bbag +_bgfd ]);};_bbag +=_gcgc .BytesPerLine ;_bdgg +=_fgec .BytesPerLine ;};};if _gcafa {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fbbb ]=_cgdg (_gcgc .Data [_fbbb ],_fgec .Data [_fcdb ]&^(_gcgc .Data [_fbbb ]),_eafa );
|
|
_fbbb +=_gcgc .BytesPerLine ;_fcdb +=_fgec .BytesPerLine ;};};case PixNotPixSrcOrDst :for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fdccg ]=_cgdg (_gcgc .Data [_fdccg ],^(_fgec .Data [_dcbc ]|_gcgc .Data [_fdccg ]),_daabg );_fdccg +=_gcgc .BytesPerLine ;
|
|
_dcbc +=_fgec .BytesPerLine ;};if _faee {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{for _bgfd =0;_bgfd < _gedbd ;_bgfd ++{_gcgc .Data [_bbag +_bgfd ]=^(_fgec .Data [_bdgg +_bgfd ]|_gcgc .Data [_bbag +_bgfd ]);};_bbag +=_gcgc .BytesPerLine ;_bdgg +=_fgec .BytesPerLine ;
|
|
};};if _gcafa {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fbbb ]=_cgdg (_gcgc .Data [_fbbb ],^(_fgec .Data [_fcdb ]|_gcgc .Data [_fbbb ]),_eafa );_fbbb +=_gcgc .BytesPerLine ;_fcdb +=_fgec .BytesPerLine ;};};case PixNotPixSrcAndDst :for _fcdbf =0;
|
|
_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fdccg ]=_cgdg (_gcgc .Data [_fdccg ],^(_fgec .Data [_dcbc ]&_gcgc .Data [_fdccg ]),_daabg );_fdccg +=_gcgc .BytesPerLine ;_dcbc +=_fgec .BytesPerLine ;};if _faee {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{for _bgfd =0;
|
|
_bgfd < _gedbd ;_bgfd ++{_gcgc .Data [_bbag +_bgfd ]=^(_fgec .Data [_bdgg +_bgfd ]&_gcgc .Data [_bbag +_bgfd ]);};_bbag +=_gcgc .BytesPerLine ;_bdgg +=_fgec .BytesPerLine ;};};if _gcafa {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fbbb ]=_cgdg (_gcgc .Data [_fbbb ],^(_fgec .Data [_fcdb ]&_gcgc .Data [_fbbb ]),_eafa );
|
|
_fbbb +=_gcgc .BytesPerLine ;_fcdb +=_fgec .BytesPerLine ;};};case PixNotPixSrcXorDst :for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fdccg ]=_cgdg (_gcgc .Data [_fdccg ],^(_fgec .Data [_dcbc ]^_gcgc .Data [_fdccg ]),_daabg );_fdccg +=_gcgc .BytesPerLine ;
|
|
_dcbc +=_fgec .BytesPerLine ;};if _faee {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{for _bgfd =0;_bgfd < _gedbd ;_bgfd ++{_gcgc .Data [_bbag +_bgfd ]=^(_fgec .Data [_bdgg +_bgfd ]^_gcgc .Data [_bbag +_bgfd ]);};_bbag +=_gcgc .BytesPerLine ;_bdgg +=_fgec .BytesPerLine ;
|
|
};};if _gcafa {for _fcdbf =0;_fcdbf < _fgbb ;_fcdbf ++{_gcgc .Data [_fbbb ]=_cgdg (_gcgc .Data [_fbbb ],^(_fgec .Data [_fcdb ]^_gcgc .Data [_fbbb ]),_eafa );_fbbb +=_gcgc .BytesPerLine ;_fcdb +=_fgec .BytesPerLine ;};};default:_cb .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",_fdgb );
|
|
return _f .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 (_becf *NRGBA64 )NRGBA64At (x ,y int )_df .NRGBA64 {_bage ,_ :=ColorAtNRGBA64 (x ,y ,_becf .Width ,_becf .Data ,_becf .Alpha ,_becf .Decode );
|
|
return _bage ;};type ColorConverter interface{Convert (_bgdd _b .Image )(Image ,error );};func (_bfcd *NRGBA32 )SetNRGBA (x ,y int ,c _df .NRGBA ){_bbab :=y *_bfcd .Width +x ;_bccb :=3*_bbab ;if _bccb +2>=len (_bfcd .Data ){return ;};_bfcd .setRGBA (_bbab ,c );
|
|
};func (_gebb *NRGBA64 )SetNRGBA64 (x ,y int ,c _df .NRGBA64 ){_dacg :=(y *_gebb .Width +x )*2;_cbab :=_dacg *3;if _cbab +5>=len (_gebb .Data ){return ;};_gebb .setNRGBA64 (_cbab ,c ,_dacg );};func ColorAtNRGBA16 (x ,y ,width ,bytesPerLine int ,data ,alpha []byte ,decode []float64 )(_df .NRGBA ,error ){_fbgc :=y *bytesPerLine +x *3/2;
|
|
if _fbgc +1>=len (data ){return _df .NRGBA {},_bgda (x ,y );};const (_fegde =0xf;_aaaf =uint8 (0xff););_gfdfb :=_aaaf ;if alpha !=nil {_eeegc :=y *BytesPerLine (width ,4,1);if _eeegc < len (alpha ){if x %2==0{_gfdfb =(alpha [_eeegc ]>>uint (4))&_fegde ;
|
|
}else {_gfdfb =alpha [_eeegc ]&_fegde ;};_gfdfb |=_gfdfb <<4;};};var _cbefff ,_ggff ,_edge uint8 ;if x *3%2==0{_cbefff =(data [_fbgc ]>>uint (4))&_fegde ;_ggff =data [_fbgc ]&_fegde ;_edge =(data [_fbgc +1]>>uint (4))&_fegde ;}else {_cbefff =data [_fbgc ]&_fegde ;
|
|
_ggff =(data [_fbgc +1]>>uint (4))&_fegde ;_edge =data [_fbgc +1]&_fegde ;};if len (decode )==6{_cbefff =uint8 (uint32 (LinearInterpolate (float64 (_cbefff ),0,15,decode [0],decode [1]))&0xf);_ggff =uint8 (uint32 (LinearInterpolate (float64 (_ggff ),0,15,decode [2],decode [3]))&0xf);
|
|
_edge =uint8 (uint32 (LinearInterpolate (float64 (_edge ),0,15,decode [4],decode [5]))&0xf);};return _df .NRGBA {R :(_cbefff <<4)|(_cbefff &0xf),G :(_ggff <<4)|(_ggff &0xf),B :(_edge <<4)|(_edge &0xf),A :_gfdfb },nil ;};type RGBA interface{RGBAAt (_gffbc ,_beb int )_df .RGBA ;
|
|
SetRGBA (_bdea ,_eace int ,_ccba _df .RGBA );};func (_eeed *Monochrome )ResolveDecode ()error {if len (_eeed .Decode )!=2{return nil ;};if _eeed .Decode [0]==1&&_eeed .Decode [1]==0{if _dfdc :=_eeed .InverseData ();_dfdc !=nil {return _dfdc ;};_eeed .Decode =nil ;
|
|
};return nil ;};func _dgg ()(_dafc []byte ){_dafc =make ([]byte ,256);for _afa :=0;_afa < 256;_afa ++{_fge :=byte (_afa );_dafc [_fge ]=(_fge &0x01)|((_fge &0x04)>>1)|((_fge &0x10)>>2)|((_fge &0x40)>>3)|((_fge &0x02)<<3)|((_fge &0x08)<<2)|((_fge &0x20)<<1)|(_fge &0x80);
|
|
};return _dafc ;};func (_badc *Gray8 )SetGray (x ,y int ,g _df .Gray ){_eggf :=y *_badc .BytesPerLine +x ;if _eggf > len (_badc .Data )-1{return ;};_badc .Data [_eggf ]=g .Y ;};func (_age colorConverter )Convert (src _b .Image )(Image ,error ){return _age ._cba (src )};
|
|
func _egfg (_dbbd _df .Gray )_df .CMYK {return _df .CMYK {K :0xff-_dbbd .Y }};func _dead (_gdbbb Gray ,_cfea NRGBA ,_bbdb _b .Rectangle ){for _fgcba :=0;_fgcba < _bbdb .Max .X ;_fgcba ++{for _bfbd :=0;_bfbd < _bbdb .Max .Y ;_bfbd ++{_gcbg :=_gdbbb .GrayAt (_fgcba ,_bfbd );
|
|
_cfea .SetNRGBA (_fgcba ,_bfbd ,_bde (_gcbg ));};};};var _bgge [256]uint8 ;func (_ffdf *Gray4 )setGray (_edbbb int ,_fccf int ,_dbde _df .Gray ){_cfb :=_fccf *_ffdf .BytesPerLine ;_daabc :=_cfb +(_edbbb >>1);if _daabc >=len (_ffdf .Data ){return ;};_fcaf :=_dbde .Y >>4;
|
|
_ffdf .Data [_daabc ]=(_ffdf .Data [_daabc ]&(^(0xf0>>uint (4*(_edbbb &1)))))|(_fcaf <<uint (4-4*(_edbbb &1)));};func (_dcdf *ImageBase )setEightFullBytes (_aecd int ,_gaafd uint64 )error {if _aecd +7> len (_dcdf .Data )-1{return _f .New ("\u0069n\u0064e\u0078\u0020\u006f\u0075\u0074 \u006f\u0066 \u0072\u0061\u006e\u0067\u0065");
|
|
};_dcdf .Data [_aecd ]=byte ((_gaafd &0xff00000000000000)>>56);_dcdf .Data [_aecd +1]=byte ((_gaafd &0xff000000000000)>>48);_dcdf .Data [_aecd +2]=byte ((_gaafd &0xff0000000000)>>40);_dcdf .Data [_aecd +3]=byte ((_gaafd &0xff00000000)>>32);_dcdf .Data [_aecd +4]=byte ((_gaafd &0xff000000)>>24);
|
|
_dcdf .Data [_aecd +5]=byte ((_gaafd &0xff0000)>>16);_dcdf .Data [_aecd +6]=byte ((_gaafd &0xff00)>>8);_dcdf .Data [_aecd +7]=byte (_gaafd &0xff);return nil ;};func _abad (_cgcd _df .RGBA )_df .NRGBA {switch _cgcd .A {case 0xff:return _df .NRGBA {R :_cgcd .R ,G :_cgcd .G ,B :_cgcd .B ,A :0xff};
|
|
case 0x00:return _df .NRGBA {};default:_bed ,_fcba ,_fecd ,_bba :=_cgcd .RGBA ();_bed =(_bed *0xffff)/_bba ;_fcba =(_fcba *0xffff)/_bba ;_fecd =(_fecd *0xffff)/_bba ;return _df .NRGBA {R :uint8 (_bed >>8),G :uint8 (_fcba >>8),B :uint8 (_fecd >>8),A :uint8 (_bba >>8)};
|
|
};};var _ _b .Image =&RGBA32 {};func MonochromeModel (threshold uint8 )_df .Model {return monochromeModel (threshold )};func (_bacg *Monochrome )copy ()*Monochrome {_dfb :=_efgg (_bacg .Width ,_bacg .Height );_dfb .ModelThreshold =_bacg .ModelThreshold ;
|
|
_dfb .Data =make ([]byte ,len (_bacg .Data ));copy (_dfb .Data ,_bacg .Data );if len (_bacg .Decode )!=0{_dfb .Decode =make ([]float64 ,len (_bacg .Decode ));copy (_dfb .Decode ,_bacg .Decode );};if len (_bacg .Alpha )!=0{_dfb .Alpha =make ([]byte ,len (_bacg .Alpha ));
|
|
copy (_dfb .Alpha ,_bacg .Alpha );};return _dfb ;};var _ Gray =&Gray8 {};func (_gdca *Monochrome )setIndexedBit (_ceba int ){_gdca .Data [(_ceba >>3)]|=0x80>>uint (_ceba &7)};func (_bdb *Monochrome )setGrayBit (_cgcc ,_cedd int ){_bdb .Data [_cgcc ]|=0x80>>uint (_cedd &7)};
|
|
func _cfgg (_bdab _b .Image )(Image ,error ){if _fccd ,_gdbc :=_bdab .(*Gray16 );_gdbc {return _fccd .Copy (),nil ;};_bfea :=_bdab .Bounds ();_bea ,_cae :=NewImage (_bfea .Max .X ,_bfea .Max .Y ,16,1,nil ,nil ,nil );if _cae !=nil {return nil ,_cae ;};_dbfg (_bdab ,_bea ,_bfea );
|
|
return _bea ,nil ;};func (_baba *NRGBA16 )Copy ()Image {return &NRGBA16 {ImageBase :_baba .copy ()}};type shift int ;var _ Image =&Monochrome {};func MonochromeThresholdConverter (threshold uint8 )ColorConverter {return &monochromeThresholdConverter {Threshold :threshold };
|
|
};var _ _b .Image =&Gray4 {};func _aba (_faf ,_aed *Monochrome ,_dfgc []byte ,_bab int )(_feb error ){var (_bccf ,_ace ,_dgc ,_cge ,_dgd ,_dbf ,_ffa ,_gff int ;_acfe ,_fdg ,_bfb ,_eac uint32 ;_egbf ,_bdce byte ;_ecbg uint16 ;);_gega :=make ([]byte ,4);
|
|
_ebd :=make ([]byte ,4);for _dgc =0;_dgc < _faf .Height -1;_dgc ,_cge =_dgc +2,_cge +1{_bccf =_dgc *_faf .BytesPerLine ;_ace =_cge *_aed .BytesPerLine ;for _dgd ,_dbf =0,0;_dgd < _bab ;_dgd ,_dbf =_dgd +4,_dbf +1{for _ffa =0;_ffa < 4;_ffa ++{_gff =_bccf +_dgd +_ffa ;
|
|
if _gff <=len (_faf .Data )-1&&_gff < _bccf +_faf .BytesPerLine {_gega [_ffa ]=_faf .Data [_gff ];}else {_gega [_ffa ]=0x00;};_gff =_bccf +_faf .BytesPerLine +_dgd +_ffa ;if _gff <=len (_faf .Data )-1&&_gff < _bccf +(2*_faf .BytesPerLine ){_ebd [_ffa ]=_faf .Data [_gff ];
|
|
}else {_ebd [_ffa ]=0x00;};};_acfe =_ce .BigEndian .Uint32 (_gega );_fdg =_ce .BigEndian .Uint32 (_ebd );_bfb =_acfe &_fdg ;_bfb |=_bfb <<1;_eac =_acfe |_fdg ;_eac &=_eac <<1;_fdg =_bfb |_eac ;_fdg &=0xaaaaaaaa;_acfe =_fdg |(_fdg <<7);_egbf =byte (_acfe >>24);
|
|
_bdce =byte ((_acfe >>8)&0xff);_gff =_ace +_dbf ;if _gff +1==len (_aed .Data )-1||_gff +1>=_ace +_aed .BytesPerLine {if _feb =_aed .setByte (_gff ,_dfgc [_egbf ]);_feb !=nil {return _dc .Errorf ("\u0069n\u0064\u0065\u0078\u003a\u0020\u0025d",_gff );};}else {_ecbg =(uint16 (_dfgc [_egbf ])<<8)|uint16 (_dfgc [_bdce ]);
|
|
if _feb =_aed .setTwoBytes (_gff ,_ecbg );_feb !=nil {return _dc .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",_gff );
|
|
};_dbf ++;};};};return nil ;};func (_cage *Gray16 )Bounds ()_b .Rectangle {return _b .Rectangle {Max :_b .Point {X :_cage .Width ,Y :_cage .Height }};};func (_dafcc *Gray8 )ColorAt (x ,y int )(_df .Color ,error ){return ColorAtGray8BPC (x ,y ,_dafcc .BytesPerLine ,_dafcc .Data ,_dafcc .Decode );
|
|
};func (_adfb *ImageBase )MakeAlpha (){_adfb .newAlpha ()};func GrayHistogram (g Gray )(_cfec [256]int ){switch _ebag :=g .(type ){case Histogramer :return _ebag .Histogram ();case _b .Image :_bbcd :=_ebag .Bounds ();for _cfac :=0;_cfac < _bbcd .Max .X ;
|
|
_cfac ++{for _aff :=0;_aff < _bbcd .Max .Y ;_aff ++{_cfec [g .GrayAt (_cfac ,_aff ).Y ]++;};};return _cfec ;default:return [256]int {};};};func (_eea *Monochrome )ExpandBinary (factor int )(*Monochrome ,error ){if !IsPowerOf2 (uint (factor )){return nil ,_dc .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 _ef (_eea ,factor );};func (_fegea *RGBA32 )ColorModel ()_df .Model {return _df .NRGBAModel };var (_cdcc =[]byte {0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,0xFF};_ddag =[]byte {0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF};);func (_bfa *Monochrome )At (x ,y int )_df .Color {_afgd ,_ :=_bfa .ColorAt (x ,y );
|
|
return _afgd };func (_bcff *Monochrome )setGray (_fgef int ,_edag _df .Gray ,_fcaa int ){if _edag .Y ==0{_bcff .clearBit (_fcaa ,_fgef );}else {_bcff .setGrayBit (_fcaa ,_fgef );};};func _fgbd (_dcfb RGBA ,_fbabe NRGBA ,_becc _b .Rectangle ){for _agec :=0;
|
|
_agec < _becc .Max .X ;_agec ++{for _cfge :=0;_cfge < _becc .Max .Y ;_cfge ++{_gceb :=_dcfb .RGBAAt (_agec ,_cfge );_fbabe .SetNRGBA (_agec ,_cfge ,_abad (_gceb ));};};};func (_gcgg *Gray4 )Bounds ()_b .Rectangle {return _b .Rectangle {Max :_b .Point {X :_gcgg .Width ,Y :_gcgg .Height }};
|
|
};func _cdd (_dfga _b .Image ,_fgea uint8 )*_b .Gray {_fgdg :=_dfga .Bounds ();_dgbe :=_b .NewGray (_fgdg );var (_fedc _df .Color ;_cdgb _df .Gray ;);for _ebega :=0;_ebega < _fgdg .Max .X ;_ebega ++{for _aeda :=0;_aeda < _fgdg .Max .Y ;_aeda ++{_fedc =_dfga .At (_ebega ,_aeda );
|
|
_dgbe .Set (_ebega ,_aeda ,_fedc );_cdgb =_dgbe .GrayAt (_ebega ,_aeda );_dgbe .SetGray (_ebega ,_aeda ,_df .Gray {Y :_gbdg (_cdgb .Y ,_fgea )});};};return _dgbe ;};type colorConverter struct{_cba func (_dcbe _b .Image )(Image ,error );};func (_cabe *NRGBA64 )Bounds ()_b .Rectangle {return _b .Rectangle {Max :_b .Point {X :_cabe .Width ,Y :_cabe .Height }};
|
|
};func (_babdg *RGBA32 )Copy ()Image {return &RGBA32 {ImageBase :_babdg .copy ()}};var _ Gray =&Gray16 {};func (_fad *Gray4 )ColorModel ()_df .Model {return Gray4Model };func (_dcbg *CMYK32 )ColorAt (x ,y int )(_df .Color ,error ){return ColorAtCMYK (x ,y ,_dcbg .Width ,_dcbg .Data ,_dcbg .Decode );
|
|
};func ColorAt (x ,y ,width ,bitsPerColor ,colorComponents ,bytesPerLine int ,data ,alpha []byte ,decode []float64 )(_df .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 ,_dc .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 );
|
|
};};var (Gray2Model =_df .ModelFunc (_bcd );Gray4Model =_df .ModelFunc (_afc );NRGBA16Model =_df .ModelFunc (_gfdf ););func (_cbcc *NRGBA64 )setNRGBA64 (_dgbdc int ,_efbg _df .NRGBA64 ,_agcf int ){_cbcc .Data [_dgbdc ]=uint8 (_efbg .R >>8);_cbcc .Data [_dgbdc +1]=uint8 (_efbg .R &0xff);
|
|
_cbcc .Data [_dgbdc +2]=uint8 (_efbg .G >>8);_cbcc .Data [_dgbdc +3]=uint8 (_efbg .G &0xff);_cbcc .Data [_dgbdc +4]=uint8 (_efbg .B >>8);_cbcc .Data [_dgbdc +5]=uint8 (_efbg .B &0xff);if _agcf +1< len (_cbcc .Alpha ){_cbcc .Alpha [_agcf ]=uint8 (_efbg .A >>8);
|
|
_cbcc .Alpha [_agcf +1]=uint8 (_efbg .A &0xff);};};func (_fege *NRGBA32 )Bounds ()_b .Rectangle {return _b .Rectangle {Max :_b .Point {X :_fege .Width ,Y :_fege .Height }};};func _fbec (_eeba _b .Image )(Image ,error ){if _dccd ,_aeeb :=_eeba .(*NRGBA64 );
|
|
_aeeb {return _dccd .Copy (),nil ;};_fgda ,_becfe ,_dddc :=_gbag (_eeba ,2);_effb ,_efcf :=NewImage (_fgda .Max .X ,_fgda .Max .Y ,16,3,nil ,_dddc ,nil );if _efcf !=nil {return nil ,_efcf ;};_cdg (_eeba ,_effb ,_fgda );if len (_dddc )!=0&&!_becfe {if _fgcg :=_ecbc (_dddc ,_effb );
|
|
_fgcg !=nil {return nil ,_fgcg ;};};return _effb ,nil ;};var _ _b .Image =&Gray8 {};func (_agd *Monochrome )setBit (_agbe ,_gcf int ){_agd .Data [_agbe +(_gcf >>3)]|=0x80>>uint (_gcf &7)};func _dfcd (_abcb CMYK ,_dgae NRGBA ,_adec _b .Rectangle ){for _dcff :=0;
|
|
_dcff < _adec .Max .X ;_dcff ++{for _gabb :=0;_gabb < _adec .Max .Y ;_gabb ++{_dfbe :=_abcb .CMYKAt (_dcff ,_gabb );_dgae .SetNRGBA (_dcff ,_gabb ,_egged (_dfbe ));};};};func (_dbea *NRGBA64 )Base ()*ImageBase {return &_dbea .ImageBase };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 ;);var _ Gray =&Gray4 {};func ColorAtGray1BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_df .Gray ,error ){_gbba :=y *bytesPerLine +x >>3;if _gbba >=len (data ){return _df .Gray {},_dc .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 );
|
|
};_aaga :=data [_gbba ]>>uint (7-(x &7))&1;if len (decode )==2{_aaga =uint8 (LinearInterpolate (float64 (_aaga ),0.0,1.0,decode [0],decode [1]))&1;};return _df .Gray {Y :_aaga *255},nil ;};func ColorAtNRGBA32 (x ,y ,width int ,data ,alpha []byte ,decode []float64 )(_df .NRGBA ,error ){_gaadb :=y *width +x ;
|
|
_fecc :=3*_gaadb ;if _fecc +2>=len (data ){return _df .NRGBA {},_dc .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 );
|
|
};_gaedd :=uint8 (0xff);if alpha !=nil &&len (alpha )> _gaadb {_gaedd =alpha [_gaadb ];};_gfbe ,_deaf ,_gcfgb :=data [_fecc ],data [_fecc +1],data [_fecc +2];if len (decode )==6{_gfbe =uint8 (uint32 (LinearInterpolate (float64 (_gfbe ),0,255,decode [0],decode [1]))&0xff);
|
|
_deaf =uint8 (uint32 (LinearInterpolate (float64 (_deaf ),0,255,decode [2],decode [3]))&0xff);_gcfgb =uint8 (uint32 (LinearInterpolate (float64 (_gcfgb ),0,255,decode [4],decode [5]))&0xff);};return _df .NRGBA {R :_gfbe ,G :_deaf ,B :_gcfgb ,A :_gaedd },nil ;
|
|
};func AutoThresholdTriangle (histogram [256]int )uint8 {var _fdfd ,_ebaf ,_fdac ,_gdfd int ;for _baa :=0;_baa < len (histogram );_baa ++{if histogram [_baa ]> 0{_fdfd =_baa ;break ;};};if _fdfd > 0{_fdfd --;};for _agfgb :=255;_agfgb > 0;_agfgb --{if histogram [_agfgb ]> 0{_gdfd =_agfgb ;
|
|
break ;};};if _gdfd < 255{_gdfd ++;};for _bdfg :=0;_bdfg < 256;_bdfg ++{if histogram [_bdfg ]> _ebaf {_fdac =_bdfg ;_ebaf =histogram [_bdfg ];};};var _eeab bool ;if (_fdac -_fdfd )< (_gdfd -_fdac ){_eeab =true ;var _dgec int ;_addf :=255;for _dgec < _addf {_gcfc :=histogram [_dgec ];
|
|
histogram [_dgec ]=histogram [_addf ];histogram [_addf ]=_gcfc ;_dgec ++;_addf --;};_fdfd =255-_gdfd ;_fdac =255-_fdac ;};if _fdfd ==_fdac {return uint8 (_fdfd );};_cdege :=float64 (histogram [_fdac ]);_cecgb :=float64 (_fdfd -_fdac );_cdbe :=_c .Sqrt (_cdege *_cdege +_cecgb *_cecgb );
|
|
_cdege /=_cdbe ;_cecgb /=_cdbe ;_cdbe =_cdege *float64 (_fdfd )+_cecgb *float64 (histogram [_fdfd ]);_dcga :=_fdfd ;var _fdge float64 ;for _eeafe :=_fdfd +1;_eeafe <=_fdac ;_eeafe ++{_cecgd :=_cdege *float64 (_eeafe )+_cecgb *float64 (histogram [_eeafe ])-_cdbe ;
|
|
if _cecgd > _fdge {_dcga =_eeafe ;_fdge =_cecgd ;};};_dcga --;if _eeab {var _abgc int ;_aaaac :=255;for _abgc < _aaaac {_ccdg :=histogram [_abgc ];histogram [_abgc ]=histogram [_aaaac ];histogram [_aaaac ]=_ccdg ;_abgc ++;_aaaac --;};return uint8 (255-_dcga );
|
|
};return uint8 (_dcga );};func (_ffb *RGBA32 )Validate ()error {if len (_ffb .Data )!=3*_ffb .Width *_ffb .Height {return _f .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 (_ecgff *Gray8 )Set (x ,y int ,c _df .Color ){_fcag :=y *_ecgff .BytesPerLine +x ;if _fcag > len (_ecgff .Data )-1{return ;};_dad :=_df .GrayModel .Convert (c );_ecgff .Data [_fcag ]=_dad .(_df .Gray ).Y ;};func ColorAtGray2BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_df .Gray ,error ){_ceg :=y *bytesPerLine +x >>2;
|
|
if _ceg >=len (data ){return _df .Gray {},_dc .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 );
|
|
};_ffac :=data [_ceg ]>>uint (6-(x &3)*2)&3;if len (decode )==2{_ffac =uint8 (uint32 (LinearInterpolate (float64 (_ffac ),0,3.0,decode [0],decode [1]))&3);};return _df .Gray {Y :_ffac *85},nil ;};func LinearInterpolate (x ,xmin ,xmax ,ymin ,ymax float64 )float64 {if _c .Abs (xmax -xmin )< 0.000001{return ymin ;
|
|
};_bcaa :=ymin +(x -xmin )*(ymax -ymin )/(xmax -xmin );return _bcaa ;};func _cdee (_fcf _df .NRGBA )_df .Gray {_egge ,_dbef ,_fcd ,_ :=_fcf .RGBA ();_ddg :=(19595*_egge +38470*_dbef +7471*_fcd +1<<15)>>24;return _df .Gray {Y :uint8 (_ddg )};};func (_dbbdb *Gray2 )Validate ()error {if len (_dbbdb .Data )!=_dbbdb .Height *_dbbdb .BytesPerLine {return ErrInvalidImage ;
|
|
};return nil ;};func ImgToGray (i _b .Image )*_b .Gray {if _faea ,_ddgg :=i .(*_b .Gray );_ddgg {return _faea ;};_cebe :=i .Bounds ();_cebfe :=_b .NewGray (_cebe );for _egfc :=0;_egfc < _cebe .Max .X ;_egfc ++{for _cbbcfd :=0;_cbbcfd < _cebe .Max .Y ;_cbbcfd ++{_gbaf :=i .At (_egfc ,_cbbcfd );
|
|
_cebfe .Set (_egfc ,_cbbcfd ,_gbaf );};};return _cebfe ;};func (_agde *NRGBA32 )Copy ()Image {return &NRGBA32 {ImageBase :_agde .copy ()}};var _ Image =&Gray2 {};var _ _b .Image =&Gray16 {};var _ Image =&Gray16 {};func (_eafd *NRGBA32 )ColorAt (x ,y int )(_df .Color ,error ){return ColorAtNRGBA32 (x ,y ,_eafd .Width ,_eafd .Data ,_eafd .Alpha ,_eafd .Decode );
|
|
};func _abdb (_afgf _df .NYCbCrA )_df .NRGBA {_febed :=int32 (_afgf .Y )*0x10101;_gbbd :=int32 (_afgf .Cb )-128;_gaeb :=int32 (_afgf .Cr )-128;_agfg :=_febed +91881*_gaeb ;if uint32 (_agfg )&0xff000000==0{_agfg >>=8;}else {_agfg =^(_agfg >>31)&0xffff;};
|
|
_agef :=_febed -22554*_gbbd -46802*_gaeb ;if uint32 (_agef )&0xff000000==0{_agef >>=8;}else {_agef =^(_agef >>31)&0xffff;};_gaaf :=_febed +116130*_gbbd ;if uint32 (_gaaf )&0xff000000==0{_gaaf >>=8;}else {_gaaf =^(_gaaf >>31)&0xffff;};return _df .NRGBA {R :uint8 (_agfg >>8),G :uint8 (_agef >>8),B :uint8 (_gaaf >>8),A :_afgf .A };
|
|
};func (_fgab *Gray8 )At (x ,y int )_df .Color {_bcfd ,_ :=_fgab .ColorAt (x ,y );return _bcfd };func _faba (_fcafd nrgba64 ,_abgd RGBA ,_daged _b .Rectangle ){for _bgbb :=0;_bgbb < _daged .Max .X ;_bgbb ++{for _debd :=0;_debd < _daged .Max .Y ;_debd ++{_dbcc :=_fcafd .NRGBA64At (_bgbb ,_debd );
|
|
_abgd .SetRGBA (_bgbb ,_debd ,_dbce (_dbcc ));};};};func (_fegb *NRGBA16 )Bounds ()_b .Rectangle {return _b .Rectangle {Max :_b .Point {X :_fegb .Width ,Y :_fegb .Height }};};func (_bacab *Gray4 )SetGray (x ,y int ,g _df .Gray ){if x >=_bacab .Width ||y >=_bacab .Height {return ;
|
|
};g =_abg (g );_bacab .setGray (x ,y ,g );};func _acgf (_bgde _df .RGBA )_df .CMYK {_babb ,_cbb ,_ecce ,_babd :=_df .RGBToCMYK (_bgde .R ,_bgde .G ,_bgde .B );return _df .CMYK {C :_babb ,M :_cbb ,Y :_ecce ,K :_babd };};func (_fbegd *NRGBA16 )ColorModel ()_df .Model {return NRGBA16Model };
|
|
func _agcb (_eacd nrgba64 ,_dfddc NRGBA ,_ageab _b .Rectangle ){for _ceea :=0;_ceea < _ageab .Max .X ;_ceea ++{for _afe :=0;_afe < _ageab .Max .Y ;_afe ++{_dafa :=_eacd .NRGBA64At (_ceea ,_afe );_dfddc .SetNRGBA (_ceea ,_afe ,_gbfa (_dafa ));};};};func IsPowerOf2 (n uint )bool {return n > 0&&(n &(n -1))==0};
|
|
func _edce (_dddf Gray ,_bbfd CMYK ,_bgab _b .Rectangle ){for _gcbf :=0;_gcbf < _bgab .Max .X ;_gcbf ++{for _eba :=0;_eba < _bgab .Max .Y ;_eba ++{_dga :=_dddf .GrayAt (_gcbf ,_eba );_bbfd .SetCMYK (_gcbf ,_eba ,_egfg (_dga ));};};};func FromGoImage (i _b .Image )(Image ,error ){switch _eeegd :=i .(type ){case Image :return _eeegd .Copy (),nil ;
|
|
case Gray :return GrayConverter .Convert (i );case *_b .Gray16 :return Gray16Converter .Convert (i );case CMYK :return CMYKConverter .Convert (i );case *_b .NRGBA64 :return NRGBA64Converter .Convert (i );default:return NRGBAConverter .Convert (i );};};
|
|
func (_fdbc *NRGBA16 )Set (x ,y int ,c _df .Color ){_addcg :=y *_fdbc .BytesPerLine +x *3/2;if _addcg +1>=len (_fdbc .Data ){return ;};_geag :=NRGBA16Model .Convert (c ).(_df .NRGBA );_fdbc .setNRGBA (x ,y ,_addcg ,_geag );};func _fbcg (_edae uint )uint {var _gcfd uint ;
|
|
for _edae !=0{_edae >>=1;_gcfd ++;};return _gcfd -1;};func _def (_db ,_bc *Monochrome )(_ggf error ){_cg :=_bc .BytesPerLine ;_dg :=_db .BytesPerLine ;_bgg :=_bc .BytesPerLine *4-_db .BytesPerLine ;var (_af ,_ccd byte ;_ab uint32 ;_efg ,_ad ,_fc ,_eee ,_ac ,_gf ,_gb int ;
|
|
);for _fc =0;_fc < _bc .Height ;_fc ++{_efg =_fc *_cg ;_ad =4*_fc *_dg ;for _eee =0;_eee < _cg ;_eee ++{_af =_bc .Data [_efg +_eee ];_ab =_ggc [_af ];_gf =_ad +_eee *4;if _bgg !=0&&(_eee +1)*4> _db .BytesPerLine {for _ac =_bgg ;_ac > 0;_ac --{_ccd =byte ((_ab >>uint (_ac *8))&0xff);
|
|
_gb =_gf +(_bgg -_ac );if _ggf =_db .setByte (_gb ,_ccd );_ggf !=nil {return _ggf ;};};}else if _ggf =_db .setFourBytes (_gf ,_ab );_ggf !=nil {return _ggf ;};if _ggf =_db .setFourBytes (_ad +_eee *4,_ggc [_bc .Data [_efg +_eee ]]);_ggf !=nil {return _ggf ;
|
|
};};for _ac =1;_ac < 4;_ac ++{for _eee =0;_eee < _dg ;_eee ++{if _ggf =_db .setByte (_ad +_ac *_dg +_eee ,_db .Data [_ad +_eee ]);_ggf !=nil {return _ggf ;};};};};return nil ;};func (_bdbd *ImageBase )setFourBytes (_ffdd int ,_dcae uint32 )error {if _ffdd +3> len (_bdbd .Data )-1{return _dc .Errorf ("\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",_ffdd );
|
|
};_bdbd .Data [_ffdd ]=byte ((_dcae &0xff000000)>>24);_bdbd .Data [_ffdd +1]=byte ((_dcae &0xff0000)>>16);_bdbd .Data [_ffdd +2]=byte ((_dcae &0xff00)>>8);_bdbd .Data [_ffdd +3]=byte (_dcae &0xff);return nil ;};func (_gdbb *Monochrome )ColorAt (x ,y int )(_df .Color ,error ){return ColorAtGray1BPC (x ,y ,_gdbb .BytesPerLine ,_gdbb .Data ,_gdbb .Decode );
|
|
};func _gda (_addg Gray ,_egea NRGBA ,_gbfc _b .Rectangle ){for _fffb :=0;_fffb < _gbfc .Max .X ;_fffb ++{for _cgb :=0;_cgb < _gbfc .Max .Y ;_cgb ++{_bdf :=_dddg (_egea .NRGBAAt (_fffb ,_cgb ));_addg .SetGray (_fffb ,_cgb ,_bdf );};};};func _ee (_fe *Monochrome ,_ccc int ,_fee []uint )(*Monochrome ,error ){_bg :=_ccc *_fe .Width ;
|
|
_fg :=_ccc *_fe .Height ;_fga :=_efgg (_bg ,_fg );for _da ,_ec :=range _fee {var _cccd error ;switch _ec {case 2:_cccd =_ga (_fga ,_fe );case 4:_cccd =_def (_fga ,_fe );case 8:_cccd =_ed (_fga ,_fe );};if _cccd !=nil {return nil ,_cccd ;};if _da !=len (_fee )-1{_fe =_fga .copy ();
|
|
};};return _fga ,nil ;};func _fec (_ecb *Monochrome ,_cdb int ,_ecf []byte )(_dcg *Monochrome ,_ffd error ){const _bceg ="\u0072\u0065d\u0075\u0063\u0065R\u0061\u006e\u006b\u0042\u0069\u006e\u0061\u0072\u0079";if _ecb ==nil {return nil ,_f .New ("\u0073o\u0075\u0072\u0063\u0065 \u0062\u0069\u0074\u006d\u0061p\u0020n\u006ft\u0020\u0064\u0065\u0066\u0069\u006e\u0065d");
|
|
};if _cdb < 1||_cdb > 4{return nil ,_f .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 _ecb .Height <=1{return nil ,_f .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");
|
|
};_dcg =_efgg (_ecb .Width /2,_ecb .Height /2);if _ecf ==nil {_ecf =_dgg ();};_bgc :=_fbbc (_ecb .BytesPerLine ,2*_dcg .BytesPerLine );switch _cdb {case 1:_ffd =_bcc (_ecb ,_dcg ,_ecf ,_bgc );case 2:_ffd =_aba (_ecb ,_dcg ,_ecf ,_bgc );case 3:_ffd =_edc (_ecb ,_dcg ,_ecf ,_bgc );
|
|
case 4:_ffd =_fcg (_ecb ,_dcg ,_ecf ,_bgc );};if _ffd !=nil {return nil ,_ffd ;};return _dcg ,nil ;};func _fafg (_dbfc *_b .Gray )bool {for _bacb :=0;_bacb < len (_dbfc .Pix );_bacb ++{if !_baaf (_dbfc .Pix [_bacb ]){return false ;};};return true ;};var _ Image =&RGBA32 {};
|
|
func _gbdg (_afaa ,_agcc uint8 )uint8 {if _afaa < _agcc {return 255;};return 0;};func (_gcae *Gray8 )GrayAt (x ,y int )_df .Gray {_dcgg ,_ :=ColorAtGray8BPC (x ,y ,_gcae .BytesPerLine ,_gcae .Data ,_gcae .Decode );return _dcgg ;};type CMYK interface{CMYKAt (_baeg ,_ggg int )_df .CMYK ;
|
|
SetCMYK (_acfc ,_dfe int ,_fda _df .CMYK );};func (_bggb *Monochrome )clearBit (_geda ,_bagg int ){_bggb .Data [_geda ]&=^(0x80>>uint (_bagg &7))};func (_fefg *Gray4 )ColorAt (x ,y int )(_df .Color ,error ){return ColorAtGray4BPC (x ,y ,_fefg .BytesPerLine ,_fefg .Data ,_fefg .Decode );
|
|
};func (_cdaab *ImageBase )setEightBytes (_dddd int ,_cfdg uint64 )error {_acb :=_cdaab .BytesPerLine -(_dddd %_cdaab .BytesPerLine );if _cdaab .BytesPerLine !=_cdaab .Width >>3{_acb --;};if _acb >=8{return _cdaab .setEightFullBytes (_dddd ,_cfdg );};return _cdaab .setEightPartlyBytes (_dddd ,_acb ,_cfdg );
|
|
};func _geg (_cacf int )[]uint {var _eag []uint ;_ggcg :=_cacf ;_gcb :=_ggcg /8;if _gcb !=0{for _fff :=0;_fff < _gcb ;_fff ++{_eag =append (_eag ,8);};_gfb :=_ggcg %8;_ggcg =0;if _gfb !=0{_ggcg =_gfb ;};};_fce :=_ggcg /4;if _fce !=0{for _ecc :=0;_ecc < _fce ;
|
|
_ecc ++{_eag =append (_eag ,4);};_eed :=_ggcg %4;_ggcg =0;if _eed !=0{_ggcg =_eed ;};};_gcbb :=_ggcg /2;if _gcbb !=0{for _dec :=0;_dec < _gcbb ;_dec ++{_eag =append (_eag ,2);};};return _eag ;};func (_bafe *NRGBA64 )Copy ()Image {return &NRGBA64 {ImageBase :_bafe .copy ()}};
|
|
func (_eadf *Gray8 )ColorModel ()_df .Model {return _df .GrayModel };func _cec (_bbf *Monochrome ,_bbd ...int )(_egg *Monochrome ,_fab error ){if _bbf ==nil {return nil ,_f .New ("\u0073o\u0075\u0072\u0063\u0065 \u0062\u0069\u0074\u006d\u0061p\u0020n\u006ft\u0020\u0064\u0065\u0066\u0069\u006e\u0065d");
|
|
};if len (_bbd )==0{return nil ,_f .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");
|
|
};_caa :=_dgg ();_egg =_bbf ;for _ ,_gd :=range _bbd {if _gd <=0{break ;};_egg ,_fab =_fec (_egg ,_gd ,_caa );if _fab !=nil {return nil ,_fab ;};};return _egg ,nil ;};func ColorAtGray4BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_df .Gray ,error ){_bded :=y *bytesPerLine +x >>1;
|
|
if _bded >=len (data ){return _df .Gray {},_dc .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 );
|
|
};_eaeb :=data [_bded ]>>uint (4-(x &1)*4)&0xf;if len (decode )==2{_eaeb =uint8 (uint32 (LinearInterpolate (float64 (_eaeb ),0,15,decode [0],decode [1]))&0xf);};return _df .Gray {Y :_eaeb *17&0xff},nil ;};func (_cabbc *RGBA32 )RGBAAt (x ,y int )_df .RGBA {_dfaa ,_ :=ColorAtRGBA32 (x ,y ,_cabbc .Width ,_cabbc .Data ,_cabbc .Alpha ,_cabbc .Decode );
|
|
return _dfaa ;};func (_abbb *NRGBA32 )Set (x ,y int ,c _df .Color ){_dabdg :=y *_abbb .Width +x ;_agbb :=3*_dabdg ;if _agbb +2>=len (_abbb .Data ){return ;};_ebeb :=_df .NRGBAModel .Convert (c ).(_df .NRGBA );_abbb .setRGBA (_dabdg ,_ebeb );};func (_cdfe *ImageBase )Pix ()[]byte {return _cdfe .Data };
|
|
func _dfc (_fecb RGBA ,_cag CMYK ,_dbe _b .Rectangle ){for _aad :=0;_aad < _dbe .Max .X ;_aad ++{for _bdcb :=0;_bdcb < _dbe .Max .Y ;_bdcb ++{_ffaf :=_fecb .RGBAAt (_aad ,_bdcb );_cag .SetCMYK (_aad ,_bdcb ,_acgf (_ffaf ));};};};type monochromeModel uint8 ;
|
|
func _ed (_bce ,_ecd *Monochrome )(_ba error ){_dd :=_ecd .BytesPerLine ;_dcb :=_bce .BytesPerLine ;var _bd ,_afb ,_dfd ,_eg ,_ged int ;for _dfd =0;_dfd < _ecd .Height ;_dfd ++{_bd =_dfd *_dd ;_afb =8*_dfd *_dcb ;for _eg =0;_eg < _dd ;_eg ++{if _ba =_bce .setEightBytes (_afb +_eg *8,_acf [_ecd .Data [_bd +_eg ]]);
|
|
_ba !=nil {return _ba ;};};for _ged =1;_ged < 8;_ged ++{for _eg =0;_eg < _dcb ;_eg ++{if _ba =_bce .setByte (_afb +_ged *_dcb +_eg ,_bce .Data [_afb +_eg ]);_ba !=nil {return _ba ;};};};};return nil ;};func _egged (_ggd _df .CMYK )_df .NRGBA {_efbf ,_ceb ,_fbeg :=_df .CMYKToRGB (_ggd .C ,_ggd .M ,_ggd .Y ,_ggd .K );
|
|
return _df .NRGBA {R :_efbf ,G :_ceb ,B :_fbeg ,A :0xff};};func (_bddg *Monochrome )getBit (_edbb ,_eged int )uint8 {return _bddg .Data [_edbb +(_eged >>3)]>>uint (7-(_eged &7))&1;};func ScaleAlphaToMonochrome (data []byte ,width ,height int )([]byte ,error ){_g :=BytesPerLine (width ,8,1);
|
|
if len (data )< _g *height {return nil ,nil ;};_cf :=&Gray8 {NewImageBase (width ,height ,8,1,data ,nil ,nil )};_gg ,_fb :=MonochromeConverter .Convert (_cf );if _fb !=nil {return nil ,_fb ;};return _gg .Base ().Data ,nil ;};func ColorAtGray8BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_df .Gray ,error ){_dcac :=y *bytesPerLine +x ;
|
|
if _dcac >=len (data ){return _df .Gray {},_dc .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 );
|
|
};_fcef :=data [_dcac ];if len (decode )==2{_fcef =uint8 (uint32 (LinearInterpolate (float64 (_fcef ),0,255,decode [0],decode [1]))&0xff);};return _df .Gray {Y :_fcef },nil ;};func RasterOperation (dest *Monochrome ,dx ,dy ,dw ,dh int ,op RasterOperator ,src *Monochrome ,sx ,sy int )error {return _ddabe (dest ,dx ,dy ,dw ,dh ,op ,src ,sx ,sy );
|
|
};func NewImageBase (width int ,height int ,bitsPerComponent int ,colorComponents int ,data []byte ,alpha []byte ,decode []float64 )ImageBase {_aecf :=ImageBase {Width :width ,Height :height ,BitsPerComponent :bitsPerComponent ,ColorComponents :colorComponents ,Data :data ,Alpha :alpha ,Decode :decode ,BytesPerLine :BytesPerLine (width ,bitsPerComponent ,colorComponents )};
|
|
if data ==nil {_aecf .Data =make ([]byte ,height *_aecf .BytesPerLine );};return _aecf ;}; |