Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix screen size of kotlin minicap #15

Merged
merged 2 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions experimental/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ android {
applicationId "io.devicefarmer.minicap"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "0.3"
versionCode 2
versionName "0.7"
archivesBaseName = "minicap"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
15 changes: 12 additions & 3 deletions experimental/app/src/main/java/io/devicefarmer/minicap/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ package io.devicefarmer.minicap
import android.os.Looper
import android.util.Size
import io.devicefarmer.minicap.provider.SurfaceProvider
import org.slf4j.LoggerFactory
import java.io.PrintStream
import kotlin.math.roundToInt
import kotlin.system.exitProcess


Expand Down Expand Up @@ -58,6 +57,7 @@ class Main {
provider = if (params.projection == null) {
SurfaceProvider()
} else {
params.projection.forceAspectRatio()
SurfaceProvider(
Size(
params.projection.targetSize.width,
Expand Down Expand Up @@ -106,9 +106,18 @@ class Main {
}

data class Projection(
val realSize: Size, val targetSize: Size,
val realSize: Size, var targetSize: Size,
val orientation: Int
) {
fun forceAspectRatio() {
val aspect = realSize.width.toFloat() / realSize.height.toFloat()
targetSize = if (targetSize.height > targetSize.width / aspect) {
Size(targetSize.width, ((targetSize.width / aspect)).roundToInt())
} else {
Size((targetSize.height * aspect).roundToInt(), targetSize.height)
}
}

override fun toString(): String =
"${realSize.width}x${realSize.height}@${targetSize.width}x${targetSize.height}/${orientation}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ abstract class BaseProvider(private val targetSize: Size) : SimpleServer.Listene

fun init(out: DisplayOutput) {
imageReader = ImageReader.newInstance(
getScreenSize().width,
getScreenSize().height,
getTargetSize().width,
getTargetSize().height,
PixelFormat.RGBA_8888,
2
)
Expand Down Expand Up @@ -111,6 +111,10 @@ abstract class BaseProvider(private val targetSize: Size) : SimpleServer.Listene
Bitmap.Config.ARGB_8888
).apply {
copyPixelsFromBuffer(buffer)
}.run {
//the image need to be cropped
Bitmap.createBitmap(this, 0, 0, getTargetSize().width, getTargetSize().height)
}.apply {
compress(Bitmap.CompressFormat.JPEG, q, out)
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devicefarmer/minicap-prebuilt",
"version": "2.6.1",
"version": "2.7.0",
"description": "Prebuilt binaries of minicap.",
"keywords": [
"minicap"
Expand Down