unipdf/internal/imageutil/imageutil.go

12 lines
46 KiB
Go
Raw Normal View History

2020-08-27 21:45:09 +00:00
//
// 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/
2020-09-14 09:32:45 +00:00
package imageutil ;import (_b "errors";_g "fmt";_gd "github.com/unidoc/unipdf/v3/internal/bitwise";_d "image";_bf "image/color";_fb "image/draw";_f "math";);func (_fbe *Gray2 )ColorModel ()_bf .Model {return Gray2Model };func MonochromeThresholdConverter (threshold uint8 )ColorConverter {return &monochromeThresholdConverter {Threshold :threshold };};var _ Image =&Gray16 {};func _cde (_cddf _bf .Gray ,_bce monochromeModel )_bf .Gray {if _cddf .Y > uint8 (_bce ){return _bf .Gray {Y :_f .MaxUint8 };};return _bf .Gray {};};func _bec (_eae _d .Image ,_becc Image ,_gbdf _d .Rectangle ){for _ede :=0;_ede < _gbdf .Max .X ;_ede ++{for _fad :=0;_fad < _gbdf .Max .Y ;_fad ++{_cf :=_eae .At (_ede ,_fad );_becc .Set (_ede ,_fad ,_cf );};};};func (_cc *CMYK32 )SetCMYK (x ,y int ,c _bf .CMYK ){_ba :=4*(y *_cc .Width +x );if _ba +3>=len (_cc .Data ){return ;};_cc .Data [_ba ]=c .C ;_cc .Data [_ba +1]=c .M ;_cc .Data [_ba +2]=c .Y ;_cc .Data [_ba +3]=c .K ;};func (_cad *Monochrome )clearBit (_beb ,_dcgc int ){_cad .Data [_beb ]&=^(0x80>>uint (_dcgc &7))};type SMasker interface{HasAlpha ()bool ;GetAlpha ()[]byte ;MakeAlpha ();};func (_ega *NRGBA32 )setRGBA (_cge int ,_fadaf _bf .NRGBA ){_dgae :=3*_cge ;_ega .Data [_dgae ]=_fadaf .R ;_ega .Data [_dgae +1]=_fadaf .G ;_ega .Data [_dgae +2]=_fadaf .B ;if _cge < len (_ega .Alpha ){_ega .Alpha [_cge ]=_fadaf .A ;};};func (_bbeb *ImageBase )HasAlpha ()bool {return _bbeb .Alpha !=nil };func ImgToBinary (i _d .Image ,threshold uint8 )*_d .Gray {switch _gedg :=i .(type ){case *_d .Gray :if _fde (_gedg ){return _gedg ;};return _aaega (_gedg ,threshold );case *_d .Gray16 :return _cgfc (_gedg ,threshold );default:return _gfdf (_gedg ,threshold );};};func (_bgc *ImageBase )GetAlpha ()[]byte {return _bgc .Alpha };type colorConverter struct{_df func (_faab _d .Image )(Image ,error );};func (_gcf *NRGBA16 )Set (x ,y int ,c _bf .Color ){_dcbb :=y *_gcf .BytesPerLine +x *3/2;if _dcbb +1>=len (_gcf .Data ){return ;};_aaeg :=NRGBA16Model .Convert (c ).(_bf .NRGBA );_gcf .setNRGBA (x ,y ,_dcbb ,_aaeg );};func ConverterFunc (converterFunc func (_egb _d .Image )(Image ,error ))ColorConverter {return colorConverter {_df :converterFunc };};func (_bbdd *Monochrome )Set (x ,y int ,c _bf .Color ){_fec :=y *_bbdd .BytesPerLine +x >>3;if _fec > len (_bbdd .Data )-1{return ;};_adb :=_bbdd .ColorModel ().Convert (c ).(_bf .Gray );_bbdd .setGray (x ,_adb ,_fec );};func _dffd (_agag _bf .Color )_bf .Color {_def :=_bf .GrayModel .Convert (_agag ).(_bf .Gray );return _eefe (_def );};func ColorAtNRGBA16 (x ,y ,width ,bytesPerLine int ,data ,alpha []byte ,decode []float64 )(_bf .NRGBA ,error ){_bdfc :=y *bytesPerLine +x *3/2;if _bdfc +1>=len (data ){return _bf .NRGBA {},_fgb (x ,y );};const (_ebfd =0xf;_debe =uint8 (0xff););_fdab :=_debe ;if alpha !=nil {_bfee :=y *BytesPerLine (width ,4,1);if _bfee < len (alpha ){if x %2==0{_fdab =(alpha [_bfee ]>>uint (4))&_ebfd ;}else {_fdab =alpha [_bfee ]&_ebfd ;};_fdab |=_fdab <<4;};};var _faed ,_edfd ,_gcg uint8 ;if x *3%2==0{_faed =(data [_bdfc ]>>uint (4))&_ebfd ;_edfd =data [_bdfc ]&_ebfd ;_gcg =(data [_bdfc +1]>>uint (4))&_ebfd ;}else {_faed =data [_bdfc ]&_ebfd ;_edfd =(data [_bdfc +1]>>uint (4))&_ebfd ;_gcg =data [_bdfc +1]&_ebfd ;};if len (decode )==6{_faed =uint8 (uint32 (LinearInterpolate (float64 (_faed ),0,15,decode [0],decode [1]))&0xf);_edfd =uint8 (uint32 (LinearInterpolate (float64 (_edfd ),0,15,decode [2],decode [3]))&0xf);_gcg =uint8 (uint32 (LinearInterpolate (float64 (_gcg ),0,15,decode [4],decode [5]))&0xf);};return _bf .NRGBA {R :(_faed <<4)|(_faed &0xf),G :(_edfd <<4)|(_edfd &0xf),B :(_gcg <<4)|(_gcg &0xf),A :_fdab },nil ;};func (_edb *NRGBA16 )Validate ()error {if len (_edb .Data )!=3*_edb .Width *_edb .Height /2{return _b .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 (_cdad *Gray8 )Copy ()Image {return &Gray8 {ImageBase :_cdad .copy ()}};f