2020-11-23 22:15:56 +00:00
|
|
|
package classer ;import (_dd "github.com/unidoc/unipdf/v3/common";_b "github.com/unidoc/unipdf/v3/internal/jbig2/basic";_f "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_e "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_g "image";_d "math";);const (RankHaus Method =iota ;Correlation ;);type Classer struct{BaseIndex int ;Settings Settings ;ComponentsNumber *_b .IntSlice ;TemplateAreas *_b .IntSlice ;Widths map[int ]int ;Heights map[int ]int ;NumberOfClasses int ;ClassInstances *_f .BitmapsArray ;UndilatedTemplates *_f .Bitmaps ;DilatedTemplates *_f .Bitmaps ;TemplatesSize _b .IntsMap ;FgTemplates *_b .NumSlice ;CentroidPoints *_f .Points ;CentroidPointsTemplates *_f .Points ;ClassIDs *_b .IntSlice ;ComponentPageNumbers *_b .IntSlice ;PtaUL *_f .Points ;PtaLL *_f .Points ;};type Method int ;func (_eef *Classer )ComputeLLCorners ()(_cdg error ){const _ff ="\u0043l\u0061\u0073\u0073\u0065\u0072\u002e\u0043\u006f\u006d\u0070\u0075t\u0065\u004c\u004c\u0043\u006f\u0072\u006e\u0065\u0072\u0073";if _eef .PtaUL ==nil {return _e .Error (_ff ,"\u0055\u004c\u0020\u0043or\u006e\u0065\u0072\u0073\u0020\u006e\u006f\u0074\u0020\u0064\u0065\u0066\u0069\u006ee\u0064");};_gcc :=len (*_eef .PtaUL );_eef .PtaLL =&_f .Points {};var (_fc ,_ec float32 ;_cc ,_fb int ;_ac *_f .Bitmap ;);for _ffd :=0;_ffd < _gcc ;_ffd ++{_fc ,_ec ,_cdg =_eef .PtaUL .GetGeometry (_ffd );if _cdg !=nil {_dd .Log .Debug ("\u0047e\u0074\u0074\u0069\u006e\u0067\u0020\u0050\u0074\u0061\u0055\u004c \u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0076",_cdg );return _e .Wrap (_cdg ,_ff ,"\u0050\u0074\u0061\u0055\u004c\u0020\u0047\u0065\u006fm\u0065\u0074\u0072\u0079");};_cc ,_cdg =_eef .ClassIDs .Get (_ffd );if _cdg !=nil {_dd .Log .Debug ("\u0047\u0065\u0074\u0074\u0069\u006e\u0067\u0020\u0043\u006c\u0061s\u0073\u0049\u0044\u0020\u0066\u0061\u0069\u006c\u0065\u0064:\u0020\u0025\u0076",_cdg );return _e .Wrap (_cdg ,_ff ,"\u0043l\u0061\u0073\u0073\u0049\u0044");};_ac ,_cdg =_eef .UndilatedTemplates .GetBitmap (_cc );if _cdg !=nil {_dd .Log .Debug ("\u0047\u0065t\u0074\u0069\u006e\u0067 \u0055\u006ed\u0069\u006c\u0061\u0074\u0065\u0064\u0054\u0065m\u0070\u006c\u0061\u0074\u0065\u0073\u0020\u0066\u0061\u0069\u006c\u0065d\u003a\u0020\u0025\u0076",_cdg );return _e .Wrap (_cdg ,_ff ,"\u0055\u006e\u0064\u0069la\u0074\u0065\u0064\u0020\u0054\u0065\u006d\u0070\u006c\u0061\u0074\u0065\u0073");};_fb =_ac .Height ;_eef .PtaLL .AddPoint (_fc ,_ec +float32 (_fb ));};return nil ;};func (_ae *Classer )getULCorners (_gf *_f .Bitmap ,_edd *_f .Boxes )error {const _cf ="\u0067\u0065\u0074U\u004c\u0043\u006f\u0072\u006e\u0065\u0072\u0073";if _gf ==nil {return _e .Error (_cf ,"\u006e\u0069l\u0020\u0069\u006da\u0067\u0065\u0020\u0062\u0069\u0074\u006d\u0061\u0070");};if _edd ==nil {return _e .Error (_cf ,"\u006e\u0069\u006c\u0020\u0062\u006f\u0075\u006e\u0064\u0073");};if _ae .PtaUL ==nil {_ae .PtaUL =&_f .Points {};};_fe :=len (*_edd );var (_cg ,_df ,_af ,_bbc int ;_faf ,_gg ,_ag ,_da float32 ;_be error ;_cga *_g .Rectangle ;_bgc *_f .Bitmap ;_ef _g .Point ;);for _bbd :=0;_bbd < _fe ;_bbd ++{_cg =_ae .BaseIndex +_bbd ;if _faf ,_gg ,_be =_ae .CentroidPoints .GetGeometry (_cg );_be !=nil {return _e .Wrap (_be ,_cf ,"\u0043\u0065\u006e\u0074\u0072\u006f\u0069\u0064\u0050o\u0069\u006e\u0074\u0073");};if _df ,_be =_ae .ClassIDs .Get (_cg );_be !=nil {return _e .Wrap (_be ,_cf ,"\u0043\u006c\u0061s\u0073\u0049\u0044\u0073\u002e\u0047\u0065\u0074");};if _ag ,_da ,_be =_ae .CentroidPointsTemplates .GetGeometry (_df );_be !=nil {return _e .Wrap (_be ,_cf ,"\u0043\u0065\u006etr\u006f\u0069\u0064\u0050\u006f\u0069\u006e\u0074\u0073\u0054\u0065\u006d\u0070\u006c\u0061\u0074\u0065\u0073");};_ggb :=_ag -_faf ;_ebe :=_da -_gg ;if _ggb >=0{_af =int (_ggb +0.5);}else {_af =int (_ggb -0.5);};if _ebe >=0{_bbc =int (_ebe +0.5);}else {_bbc =int (_ebe -0.5);};if _cga ,_be =_edd .Get (_bbd );_be !=nil {return _e .Wrap (_be ,_cf ,"");};_bee ,_ebf :=_cga .Min .X ,_cga .Min .Y ;_bgc ,_be =_ae .UndilatedTemplates .GetBitmap (_df );if _be !=nil {return _e .Wrap (_be ,_cf ,"\u0055\u006e\u0064\u0069\u006
|