(widthToScale, heightToScale int, po ProcessingOptions)
| 221 | } |
| 222 | |
| 223 | func (c *Context) limitScale(widthToScale, heightToScale int, po ProcessingOptions) { |
| 224 | maxresultDim := c.PO.MaxResultDimension() |
| 225 | |
| 226 | if maxresultDim <= 0 { |
| 227 | return |
| 228 | } |
| 229 | |
| 230 | outWidth := imath.MinNonZero(c.ScaledWidth, c.ResultCropWidth) |
| 231 | outHeight := imath.MinNonZero(c.ScaledHeight, c.ResultCropHeight) |
| 232 | |
| 233 | if po.ExtendEnabled() { |
| 234 | outWidth = max(outWidth, c.TargetWidth) |
| 235 | outHeight = max(outHeight, c.TargetHeight) |
| 236 | } else if po.ExtendAspectRatioEnabled() { |
| 237 | outWidth = max(outWidth, c.ExtendAspectRatioWidth) |
| 238 | outHeight = max(outHeight, c.ExtendAspectRatioHeight) |
| 239 | } |
| 240 | |
| 241 | outWidth += imath.ScaleToEven(po.PaddingLeft(), c.DprScale) |
| 242 | outWidth += imath.ScaleToEven(po.PaddingRight(), c.DprScale) |
| 243 | outHeight += imath.ScaleToEven(po.PaddingTop(), c.DprScale) |
| 244 | outHeight += imath.ScaleToEven(po.PaddingBottom(), c.DprScale) |
| 245 | |
| 246 | if maxresultDim > 0 && (outWidth > maxresultDim || outHeight > maxresultDim) { |
| 247 | downScale := float64(maxresultDim) / float64(max(outWidth, outHeight)) |
| 248 | |
| 249 | c.WScale *= downScale |
| 250 | c.HScale *= downScale |
| 251 | |
| 252 | // Prevent scaling below 1px |
| 253 | if minWScale := 1.0 / float64(widthToScale); c.WScale < minWScale { |
| 254 | c.WScale = minWScale |
| 255 | } |
| 256 | if minHScale := 1.0 / float64(heightToScale); c.HScale < minHScale { |
| 257 | c.HScale = minHScale |
| 258 | } |
| 259 | |
| 260 | c.DprScale *= downScale |
| 261 | |
| 262 | // Recalculate the sizes after changing the scales |
| 263 | c.calcSizes(widthToScale, heightToScale, po) |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | // CalcParams calculates context image parameters based on the current image size. |
| 268 | // Some steps (like trim) must call this function when finished. |
no test coverage detected