2020-09-21 01:20:10 +00:00
|
|
|
package imageutil ;import (_ag "errors";_b "fmt";_d "github.com/unidoc/unipdf/v3/internal/bitwise";_fe "image";_ac "image/color";_f "image/draw";_e "math";);func _bfef (_cdbc *_fe .Gray16 ,_cfbg uint8 )*_fe .Gray {_adbb :=_cdbc .Bounds ();_dcbb :=_fe .NewGray (_adbb );for _gbeg :=0;_gbeg < _adbb .Dx ();_gbeg ++{for _bade :=0;_bade < _adbb .Dy ();_bade ++{_dcbc :=_cdbc .Gray16At (_gbeg ,_bade );_dcbb .SetGray (_gbeg ,_bade ,_ac .Gray {Y :_aaba (uint8 (_dcbc .Y /256),_cfbg )});};};return _dcbb ;};func _dged (_egcab CMYK ,_edff NRGBA ,_ecdg _fe .Rectangle ){for _eeag :=0;_eeag < _ecdg .Max .X ;_eeag ++{for _fgdd :=0;_fgdd < _ecdg .Max .Y ;_fgdd ++{_dadb :=_egcab .CMYKAt (_eeag ,_fgdd );_edff .SetNRGBA (_eeag ,_fgdd ,_db (_dadb ));};};};func _gead (_geda uint8 )bool {if _geda ==0||_geda ==255{return true ;};return false ;};func ColorAtGrayscale (x ,y ,bitsPerColor ,bytesPerLine int ,data []byte ,decode []float64 )(_ac .Color ,error ){switch bitsPerColor {case 1:return ColorAtGray1BPC (x ,y ,bytesPerLine ,data ,decode );case 2:return ColorAtGray2BPC (x ,y ,bytesPerLine ,data ,decode );case 4:return ColorAtGray4BPC (x ,y ,bytesPerLine ,data ,decode );case 8:return ColorAtGray8BPC (x ,y ,bytesPerLine ,data ,decode );case 16:return ColorAtGray16BPC (x ,y ,bytesPerLine ,data ,decode );default:return nil ,_b .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0067\u0072\u0061\u0079\u0020\u0073c\u0061\u006c\u0065\u0020\u0062\u0069\u0074s\u0020\u0070\u0065\u0072\u0020\u0063\u006f\u006c\u006f\u0072\u0020a\u006d\u006f\u0075\u006e\u0074\u003a\u0020\u0027\u0025\u0064\u0027",bitsPerColor );};};func (_df *CMYK32 )ColorAt (x ,y int )(_ac .Color ,error ){return ColorAtCMYK (x ,y ,_df .Width ,_df .Data ,_df .Decode );};func (_ecg *Monochrome )ColorAt (x ,y int )(_ac .Color ,error ){return ColorAtGray1BPC (x ,y ,_ecg .BytesPerLine ,_ecg .Data ,_ecg .Decode );};func _fefcb (){for _bdfb :=0;_bdfb < 256;_bdfb ++{_fabb [_bdfb ]=uint8 (_bdfb &0x1)+(uint8 (_bdfb >>1)&0x1)+(uint8 (_bdfb >>2)&0x1)+(uint8 (_bdfb >>3)&0x1)+(uint8 (_bdfb >>4)&0x1)+(uint8 (_bdfb >>5)&0x1)+(uint8 (_bdfb >>6)&0x1)+(uint8 (_bdfb >>7)&0x1);};};func ColorAtNRGBA32 (x ,y ,width int ,data ,alpha []byte ,decode []float64 )(_ac .NRGBA ,error ){_bggc :=y *width +x ;_adgae :=3*_bggc ;if _adgae +2>=len (data ){return _ac .NRGBA {},_b .Errorf ("\u0069\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006f\u0072\u0064\u0069\u006ea\u0074\u0065\u0073\u0020\u006f\u0075t\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065\u0020\u0028\u0025\u0064,\u0020\u0025\u0064\u0029",x ,y );};_gcfa :=uint8 (0xff);if alpha !=nil &&len (alpha )> _bggc {_gcfa =alpha [_bggc ];};_aadb ,_ebggd ,_bffb :=data [_adgae ],data [_adgae +1],data [_adgae +2];if len (decode )==6{_aadb =uint8 (uint32 (LinearInterpolate (float64 (_aadb ),0,255,decode [0],decode [1]))&0xff);_ebggd =uint8 (uint32 (LinearInterpolate (float64 (_ebggd ),0,255,decode [2],decode [3]))&0xff);_bffb =uint8 (uint32 (LinearInterpolate (float64 (_bffb ),0,255,decode [4],decode [5]))&0xff);};return _ac .NRGBA {R :_aadb ,G :_ebggd ,B :_bffb ,A :_gcfa },nil ;};type CMYK32 struct{ImageBase };var _ Image =&NRGBA32 {};func _fg (_cfbe _fe .Image )(Image ,error ){if _gd ,_ff :=_cfbe .(*CMYK32 );_ff {return _gd .Copy (),nil ;};_dga :=_cfbe .Bounds ();_dc ,_bcc :=NewImage (_dga .Max .X ,_dga .Max .Y ,8,4,nil ,nil ,nil );if _bcc !=nil {return nil ,_bcc ;};switch _ebb :=_cfbe .(type ){case CMYK :_fbe (_ebb ,_dc .(CMYK ),_dga );case Gray :_ad (_ebb ,_dc .(CMYK ),_dga );case NRGBA :_ef (_ebb ,_dc .(CMYK ),_dga );case RGBA :_ec (_ebb ,_dc .(CMYK ),_dga );default:_bef (_cfbe ,_dc ,_dga );};return _dc ,nil ;};func (_egb *Monochrome )setGray (_cda int ,_abg _ac .Gray ,_efa int ){if _abg .Y ==0{_egb .clearBit (_efa ,_cda );}else {_egb .setBit (_efa ,_cda );};};var _ _fe .Image =&NRGBA16 {};func (_cge *Gray4 )Bounds ()_fe .Rectangle {return _fe .Rectangle {Max :_fe .Point {X :_cge .Width ,Y :_cge .Height }};};var _ _fe .Image =&Gray2 {};func ColorAtGray1BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_ac .Gray ,error ){_acf :=
|