in amazon-chime-sdk/src/main/java/com/amazonaws/services/chime/sdk/meetings/audiovideo/video/capture/ScreenCaptureResolutionCalculator.kt [32:67]
fun computeTargetSize(displayWidth: Int, displayHeight: Int, targetResolutionLong: Int, targetResolutionShort: Int): IntArray {
val displayResolutionShort = min(displayWidth, displayHeight)
val displayResolutionLong = max(displayWidth, displayHeight)
val scaledWidth: Int
val scaledHeight: Int
val resolutionOverConstraint: Boolean = (displayResolutionShort > targetResolutionShort || displayResolutionLong > targetResolutionLong)
if (resolutionOverConstraint) {
val resolutionShortScale: Double = displayResolutionShort.toDouble() / targetResolutionShort.toDouble()
val resolutionLongScale: Double = displayResolutionLong.toDouble() / targetResolutionLong.toDouble()
if (resolutionShortScale > resolutionLongScale) {
if (displayResolutionShort == displayWidth) {
scaledWidth = targetResolutionShort
scaledHeight = (displayHeight.toDouble() / resolutionShortScale).toInt()
} else {
scaledHeight = targetResolutionShort
scaledWidth = (displayWidth.toDouble() / resolutionShortScale).toInt()
}
} else {
if (displayResolutionLong == displayWidth) {
scaledWidth = targetResolutionLong
scaledHeight = (displayHeight.toDouble() / resolutionLongScale).toInt()
} else {
scaledHeight = targetResolutionLong
scaledWidth = (displayWidth.toDouble() / resolutionLongScale).toInt()
}
}
} else {
scaledWidth = displayWidth
scaledHeight = displayHeight
}
val resolutions = IntArray(2)
resolutions[0] = scaledWidth
resolutions[1] = scaledHeight
return resolutions
}