(width, height int, po ProcessingOptions)
| 65 | } |
| 66 | |
| 67 | func (c *Context) calcScale(width, height int, po ProcessingOptions) { |
| 68 | wshrink, hshrink := 1.0, 1.0 |
| 69 | srcW, srcH := float64(width), float64(height) |
| 70 | |
| 71 | poWidth := po.Width() |
| 72 | poHeight := po.Height() |
| 73 | |
| 74 | dstW := imath.NonZero(float64(poWidth), srcW) |
| 75 | dstH := imath.NonZero(float64(poHeight), srcH) |
| 76 | |
| 77 | if dstW != srcW { |
| 78 | wshrink = srcW / dstW |
| 79 | } |
| 80 | |
| 81 | if dstH != srcH { |
| 82 | hshrink = srcH / dstH |
| 83 | } |
| 84 | |
| 85 | if wshrink != 1 || hshrink != 1 { |
| 86 | rt := po.ResizingType() |
| 87 | |
| 88 | if rt == ResizeAuto { |
| 89 | srcD := srcW - srcH |
| 90 | dstD := dstW - dstH |
| 91 | |
| 92 | if (srcD >= 0 && dstD >= 0) || (srcD < 0 && dstD < 0) { |
| 93 | rt = ResizeFill |
| 94 | } else { |
| 95 | rt = ResizeFit |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | switch { |
| 100 | case poWidth == 0 && rt != ResizeForce: |
| 101 | wshrink = hshrink |
| 102 | case poHeight == 0 && rt != ResizeForce: |
| 103 | hshrink = wshrink |
| 104 | case rt == ResizeFit: |
| 105 | wshrink = math.Max(wshrink, hshrink) |
| 106 | hshrink = wshrink |
| 107 | case rt == ResizeFill || rt == ResizeFillDown: |
| 108 | wshrink = math.Min(wshrink, hshrink) |
| 109 | hshrink = wshrink |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | wshrink /= po.ZoomWidth() |
| 114 | hshrink /= po.ZoomHeight() |
| 115 | |
| 116 | c.DprScale = po.DPR() |
| 117 | |
| 118 | isVector := c.ImgData != nil && c.ImgData.Format().IsVector() |
| 119 | |
| 120 | if !po.Enlarge() && !isVector { |
| 121 | minShrink := math.Min(wshrink, hshrink) |
| 122 | if minShrink < 1 { |
| 123 | wshrink /= minShrink |
| 124 | hshrink /= minShrink |
no test coverage detected