2025-08-16 19:54:50 +03:00
|
|
|
package processing
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"math"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// vectorGuardScale checks if the image is a vector format and downscales it
|
|
|
|
|
// to the maximum allowed resolution if necessary
|
2025-09-23 15:55:04 +02:00
|
|
|
func (p *Processor) vectorGuardScale(c *Context) error {
|
2025-09-18 10:29:42 +02:00
|
|
|
if c.ImgData == nil || !c.ImgData.Format().IsVector() {
|
2025-08-16 19:54:50 +03:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-23 20:16:36 +03:00
|
|
|
if resolution := c.Img.Width() * c.Img.Height(); resolution > c.SecOps.MaxSrcResolution {
|
2025-09-26 20:34:51 +03:00
|
|
|
shrink := math.Sqrt(float64(resolution) / float64(c.SecOps.MaxSrcResolution))
|
|
|
|
|
c.VectorBaseShrink = shrink
|
2025-08-16 19:54:50 +03:00
|
|
|
|
2025-09-26 20:34:51 +03:00
|
|
|
if err := c.Img.Load(c.ImgData, shrink, 0, 1); err != nil {
|
2025-08-16 19:54:50 +03:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-23 15:55:04 +02:00
|
|
|
c.CalcParams()
|
2025-08-16 19:54:50 +03:00
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|