Skip to content

Commit

Permalink
Rename destWidth/destHeight to dstWidth/dstHeight.
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrtwhite committed Feb 3, 2020
1 parent 10498ae commit 95515d4
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 43 deletions.
4 changes: 2 additions & 2 deletions coil-base/src/main/java/coil/RealImageLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ internal class RealImageLoader(
val multiple = DecodeUtils.computeSizeMultiplier(
srcWidth = bitmap.width,
srcHeight = bitmap.height,
destWidth = size.width,
destHeight = size.height,
dstWidth = size.width,
dstHeight = size.height,
scale = scale
)
if (multiple != 1.0 && !requestService.allowInexactSize(request)) {
Expand Down
4 changes: 2 additions & 2 deletions coil-base/src/main/java/coil/decode/BitmapFactoryDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ internal class BitmapFactoryDecoder(private val context: Context) : Decoder {
val rawScale = DecodeUtils.computeSizeMultiplier(
srcWidth = srcWidth / inSampleSize.toDouble(),
srcHeight = srcHeight / inSampleSize.toDouble(),
destWidth = width.toDouble(),
destHeight = height.toDouble(),
dstWidth = width.toDouble(),
dstHeight = height.toDouble(),
scale = options.scale
)

Expand Down
34 changes: 17 additions & 17 deletions coil-base/src/main/java/coil/decode/DecodeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ object DecodeUtils {

/**
* Calculate the [BitmapFactory.Options.inSampleSize] given the source dimensions of the image
* ([srcWidth] and [srcHeight]), the output dimensions ([destWidth], [destHeight]), and the [scale].
* ([srcWidth] and [srcHeight]), the output dimensions ([dstWidth], [dstHeight]), and the [scale].
*/
@JvmStatic
fun calculateInSampleSize(
@Px srcWidth: Int,
@Px srcHeight: Int,
@Px destWidth: Int,
@Px destHeight: Int,
@Px dstWidth: Int,
@Px dstHeight: Int,
scale: Scale
): Int {
val widthInSampleSize = Integer.highestOneBit(srcWidth / destWidth).coerceAtLeast(1)
val heightInSampleSize = Integer.highestOneBit(srcHeight / destHeight).coerceAtLeast(1)
val widthInSampleSize = Integer.highestOneBit(srcWidth / dstWidth).coerceAtLeast(1)
val heightInSampleSize = Integer.highestOneBit(srcHeight / dstHeight).coerceAtLeast(1)
return when (scale) {
Scale.FILL -> min(widthInSampleSize, heightInSampleSize)
Scale.FIT -> max(widthInSampleSize, heightInSampleSize)
Expand All @@ -69,12 +69,12 @@ object DecodeUtils {
fun computeSizeMultiplier(
@Px srcWidth: Int,
@Px srcHeight: Int,
@Px destWidth: Int,
@Px destHeight: Int,
@Px dstWidth: Int,
@Px dstHeight: Int,
scale: Scale
): Double {
val widthPercent = destWidth / srcWidth.toDouble()
val heightPercent = destHeight / srcHeight.toDouble()
val widthPercent = dstWidth / srcWidth.toDouble()
val heightPercent = dstHeight / srcHeight.toDouble()
return when (scale) {
Scale.FILL -> max(widthPercent, heightPercent)
Scale.FIT -> min(widthPercent, heightPercent)
Expand All @@ -86,12 +86,12 @@ object DecodeUtils {
fun computeSizeMultiplier(
@Px srcWidth: Float,
@Px srcHeight: Float,
@Px destWidth: Float,
@Px destHeight: Float,
@Px dstWidth: Float,
@Px dstHeight: Float,
scale: Scale
): Float {
val widthPercent = destWidth / srcWidth
val heightPercent = destHeight / srcHeight
val widthPercent = dstWidth / srcWidth
val heightPercent = dstHeight / srcHeight
return when (scale) {
Scale.FILL -> max(widthPercent, heightPercent)
Scale.FIT -> min(widthPercent, heightPercent)
Expand All @@ -103,12 +103,12 @@ object DecodeUtils {
fun computeSizeMultiplier(
@Px srcWidth: Double,
@Px srcHeight: Double,
@Px destWidth: Double,
@Px destHeight: Double,
@Px dstWidth: Double,
@Px dstHeight: Double,
scale: Scale
): Double {
val widthPercent = destWidth / srcWidth
val heightPercent = destHeight / srcHeight
val widthPercent = dstWidth / srcWidth
val heightPercent = dstHeight / srcHeight
return when (scale) {
Scale.FILL -> max(widthPercent, heightPercent)
Scale.FIT -> min(widthPercent, heightPercent)
Expand Down
4 changes: 2 additions & 2 deletions coil-base/src/main/java/coil/decode/DrawableDecoderService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ internal class DrawableDecoderService(private val bitmapPool: BitmapPool) {
val multiplier = DecodeUtils.computeSizeMultiplier(
srcWidth = intrinsicWidth,
srcHeight = intrinsicHeight,
destWidth = size.width,
destHeight = size.height,
dstWidth = size.width,
dstHeight = size.height,
scale = Scale.FIT
)
width = (multiplier * intrinsicWidth).roundToInt()
Expand Down
8 changes: 1 addition & 7 deletions coil-base/src/main/java/coil/drawable/CrossfadeDrawable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,7 @@ class CrossfadeDrawable(

val targetWidth = targetBounds.width()
val targetHeight = targetBounds.height()
val multiplier = DecodeUtils.computeSizeMultiplier(
srcWidth = width,
srcHeight = height,
destWidth = targetWidth,
destHeight = targetHeight,
scale = scale
)
val multiplier = DecodeUtils.computeSizeMultiplier(width, height, targetWidth, targetHeight, scale)
val dx = ((targetWidth - multiplier * width) / 2).roundToInt()
val dy = ((targetHeight - multiplier * height) / 2).roundToInt()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class RoundedCornersTransformation(
val multiplier = DecodeUtils.computeSizeMultiplier(
srcWidth = input.width,
srcHeight = input.height,
destWidth = size.width,
destHeight = size.height,
dstWidth = size.width,
dstHeight = size.height,
scale = Scale.FILL
)
outputWidth = (size.width / multiplier).roundToInt()
Expand Down
4 changes: 2 additions & 2 deletions coil-gif/src/main/java/coil/decode/ImageDecoderDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class ImageDecoderDecoder : Decoder {
val multiplier = DecodeUtils.computeSizeMultiplier(
srcWidth = infoSize.width,
srcHeight = infoSize.height,
destWidth = size.width,
destHeight = size.height,
dstWidth = size.width,
dstHeight = size.height,
scale = options.scale
)
if (multiplier < 1) {
Expand Down
8 changes: 1 addition & 7 deletions coil-gif/src/main/java/coil/drawable/ScaleDrawable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,7 @@ class ScaleDrawable(

val targetWidth = bounds.width()
val targetHeight = bounds.height()
val multiplier = DecodeUtils.computeSizeMultiplier(
srcWidth = width,
srcHeight = height,
destWidth = targetWidth,
destHeight = targetHeight,
scale = scale
)
val multiplier = DecodeUtils.computeSizeMultiplier(width, height, targetWidth, targetHeight, scale)

val left = ((targetWidth - multiplier * width) / 2).roundToInt()
val top = ((targetHeight - multiplier * height) / 2).roundToInt()
Expand Down
4 changes: 2 additions & 2 deletions coil-svg/src/main/java/coil/decode/SvgDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class SvgDecoder(private val context: Context) : Decoder {
val multiplier = DecodeUtils.computeSizeMultiplier(
srcWidth = svgWidth,
srcHeight = svgHeight,
destWidth = size.width.toFloat(),
destHeight = size.height.toFloat(),
dstWidth = size.width.toFloat(),
dstHeight = size.height.toFloat(),
scale = options.scale
)
bitmapWidth = (multiplier * svgWidth).toInt()
Expand Down

0 comments on commit 95515d4

Please # to comment.