unipdf/internal/imageutil/imageutil.go

12 lines
49 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-28 23:18:17 +00:00
package imageutil ;import (_e "errors";_a "fmt";_ee "github.com/unidoc/unipdf/v3/internal/bitwise";_egg "image";_eg "image/color";_d "image/draw";_g "math";);var _ Image =&NRGBA32 {};func _fdf (_bdac _eg .Color )_eg .Color {_aea :=_eg .GrayModel .Convert (_bdac ).(_eg .Gray );return _defe (_aea );};type ColorConverter interface{Convert (_bge _egg .Image )(Image ,error );};func (_gceg *Gray4 )At (x ,y int )_eg .Color {_gcg ,_ :=_gceg .ColorAt (x ,y );return _gcg };func (_edb *Gray2 )ColorAt (x ,y int )(_eg .Color ,error ){return ColorAtGray2BPC (x ,y ,_edb .BytesPerLine ,_edb .Data ,_edb .Decode );};func (_efdd *Gray16 )ColorAt (x ,y int )(_eg .Color ,error ){return ColorAtGray16BPC (x ,y ,_efdd .BytesPerLine ,_efdd .Data ,_efdd .Decode );};var (Gray2Model =_eg .ModelFunc (_fcbf );Gray4Model =_eg .ModelFunc (_fdf );NRGBA16Model =_eg .ModelFunc (_eeac ););type monochromeThresholdConverter struct{Threshold uint8 ;};func (_decf *NRGBA64 )ColorModel ()_eg .Model {return _eg .NRGBA64Model };func (_addc *Gray2 )GrayAt (x ,y int )_eg .Gray {_cafb ,_ :=ColorAtGray2BPC (x ,y ,_addc .BytesPerLine ,_addc .Data ,_addc .Decode );return _cafb ;};func _eeca (_bcb _egg .Image ,_dbecc uint8 )*_egg .Gray {_dbgc :=_bcb .Bounds ();_bdag :=_egg .NewGray (_dbgc );var (_gdgd _eg .Color ;_aabe _eg .Gray ;);for _bga :=0;_bga < _dbgc .Max .X ;_bga ++{for _gaea :=0;_gaea < _dbgc .Max .Y ;_gaea ++{_gdgd =_bcb .At (_bga ,_gaea );_bdag .Set (_bga ,_gaea ,_gdgd );_aabe =_bdag .GrayAt (_bga ,_gaea );_bdag .SetGray (_bga ,_gaea ,_eg .Gray {Y :_dgg (_aabe .Y ,_dbecc )});};};return _bdag ;};func _def (_gbc _egg .Image )(Image ,error ){if _gce ,_gbe :=_gbc .(*Monochrome );_gbe {return _gce ,nil ;};_ccag ,_edg :=_gbc .(Gray );if !_edg {_gfcc ,_aff :=GrayConverter .Convert (_gbc );if _aff !=nil {return nil ,_aff ;};_ccag =_gfcc .(Gray );};_bdc :=_gbc .Bounds ();_dad ,_ggc :=NewImage (_bdc .Max .X ,_bdc .Max .Y ,1,1,nil ,nil ,nil );if _ggc !=nil {return nil ,_ggc ;};_fdg :=_dad .(*Monochrome );_gedfb :=AutoThresholdTriangle (GrayHistogram (_ccag ));for _gfca :=0;_gfca < _bdc .Max .X ;_gfca ++{for _fca :=0;_fca < _bdc .Max .Y ;_fca ++{_abd :=_cfbg (_ccag .GrayAt (_gfca ,_fca ),monochromeModel (_gedfb ));_fdg .SetGray (_gfca ,_fca ,_abd );};};return _dad ,nil ;};func _abgea (_fbf ,_aagc NRGBA ,_fdge _egg .Rectangle ){for _fgac :=0;_fgac < _fdge .Max .X ;_fgac ++{for _ebfc :=0;_ebfc < _fdge .Max .Y ;_ebfc ++{_aagc .SetNRGBA (_fgac ,_ebfc ,_fbf .NRGBAAt (_fgac ,_ebfc ));};};};func _bbe (_cdcd _eg .Gray )_eg .CMYK {return _eg .CMYK {K :0xff-_cdcd .Y }};var _ Gray =&Monochrome {};func (_faa *monochromeThresholdConverter )Convert (img _egg .Image )(Image ,error ){if _dfa ,_fbda :=img .(*Monochrome );_fbda {return _dfa .Copy (),nil ;};_bda :=img .Bounds ();_deg ,_ecd :=NewImage (_bda .Max .X ,_bda .Max .Y ,1,1,nil ,nil ,nil );if _ecd !=nil {return nil ,_ecd ;};_deg .(*Monochrome ).ModelThreshold =_faa .Threshold ;for _fea :=0;_fea < _bda .Max .X ;_fea ++{for _acee :=0;_acee < _bda .Max .Y ;_acee ++{_ggg :=img .At (_fea ,_acee );_deg .Set (_fea ,_acee ,_ggg );};};return _deg ,nil ;};func (_adab *NRGBA16 )Bounds ()_egg .Rectangle {return _egg .Rectangle {Max :_egg .Point {X :_adab .Width ,Y :_adab .Height }};};func (_dgbe *Gray4 )GrayAt (x ,y int )_eg .Gray {_ebg ,_ :=ColorAtGray4BPC (x ,y ,_dgbe .BytesPerLine ,_dgbe .Data ,_dgbe .Decode );return _ebg ;};func (_afd monochromeModel )Convert (c _eg .Color )_eg .Color {_fac :=_eg .GrayModel .Convert (c ).(_eg .Gray );return _cfbg (_fac ,_afd );};func (_dbbeb *ImageBase )Pix ()[]byte {return _dbbeb .Data };func (_ded *Gray16 )Bounds ()_egg .Rectangle {return _egg .Rectangle {Max :_egg .Point {X :_ded .Width ,Y :_ded .Height }};};func (_fbag *Gray16 )At (x ,y int )_eg .Color {_bdd ,_ :=_fbag .ColorAt (x ,y );return _bdd };var _ Image =&Gray8 {};func ColorAtGray8BPC (x ,y ,bytesPerLine int ,data []byte ,decode []float64 )(_eg .Gray ,error ){_cab :=y *bytesPerLine +x ;if _cab >=len (data ){return _eg .Gray {},_a .Errorf ("\u0069\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006f\u0072\u0064\u0069\u006ea\u0074\u0065\u0073\u0020\u