vector_guard_scale.go 614 B

12345678910111213141516171819202122232425
  1. package processing
  2. import (
  3. "math"
  4. )
  5. // vectorGuardScale checks if the image is a vector format and downscales it
  6. // to the maximum allowed resolution if necessary
  7. func (p *Processor) vectorGuardScale(c *Context) error {
  8. if c.ImgData == nil || !c.ImgData.Format().IsVector() {
  9. return nil
  10. }
  11. if resolution := c.Img.Width() * c.Img.Height(); resolution > c.SecOps.MaxSrcResolution {
  12. shrink := math.Sqrt(float64(resolution) / float64(c.SecOps.MaxSrcResolution))
  13. c.VectorBaseShrink = shrink
  14. if err := c.Img.Load(c.ImgData, shrink, 0, 1); err != nil {
  15. return err
  16. }
  17. }
  18. c.CalcParams()
  19. return nil
  20. }