comparison app/src/main/java/com/bartsent/simpleresizer/lib/Resizer.kt @ 17:86740f593b6c

Better memoization, more rational API.
author David Barts <n5jrn@me.com>
date Sun, 21 Feb 2021 22:14:07 -0800
parents b1605be35bcc
children eedf995462d9
comparison
equal deleted inserted replaced
16:3ed74dc0e34a 17:86740f593b6c
115 for (i in 0 until target.size) { 115 for (i in 0 until target.size) {
116 resample(target, i, weights[i], source) 116 resample(target, i, weights[i], source)
117 } 117 }
118 } 118 }
119 119
120 private val DEFAULT_KERNEL = LanczosKernel()
121
122 /** 120 /**
123 * Resize the horizontal aspect. 121 * Resize the horizontal aspect.
124 * @param newWidth Width of new image 122 * @param newWidth Width of new image
125 * @param kernel Scaling kernel to use (default: LanczosKernel) 123 * @param kernel Scaling kernel to use (default: LanczosKernel)
126 * @return A new Resizer object, resampled per specifications 124 * @return A new Resizer object, resampled per specifications
127 */ 125 */
128 fun horizontal(newWidth: Int, kernel: ScalingKernel = DEFAULT_KERNEL): Resizer { 126 fun horizontal(newWidth: Int, kernel: ScalingKernel): Resizer {
129 val dst = Resizer(newWidth, height) 127 val dst = Resizer(newWidth, height)
130 val weights = precomputeWeights(newWidth, width, kernel) 128 val weights = precomputeWeights(newWidth, width, kernel)
131 for (y in 0 until height) { 129 for (y in 0 until height) {
132 resampleBand(Row(dst, y), weights, Row(this, y)) 130 resampleBand(Row(dst, y), weights, Row(this, y))
133 } 131 }
138 * Resize the vertical aspect. 136 * Resize the vertical aspect.
139 * @param newHeight Height of new image 137 * @param newHeight Height of new image
140 * @param kernel Scaling kernel to use (default: LanczosKernel) 138 * @param kernel Scaling kernel to use (default: LanczosKernel)
141 * @return A new Resizer object, resampled per specifications 139 * @return A new Resizer object, resampled per specifications
142 */ 140 */
143 fun vertical(newHeight: Int, kernel: ScalingKernel = DEFAULT_KERNEL): Resizer { 141 fun vertical(newHeight: Int, kernel: ScalingKernel): Resizer {
144 val dst = Resizer(width, newHeight) 142 val dst = Resizer(width, newHeight)
145 val weights = precomputeWeights(newHeight, height, kernel) 143 val weights = precomputeWeights(newHeight, height, kernel)
146 for (x in 0 until width) { 144 for (x in 0 until width) {
147 resampleBand(Column(dst, x), weights, Column(this, x)) 145 resampleBand(Column(dst, x), weights, Column(this, x))
148 } 146 }