Skip to content
Open
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 build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.72'
ext.kotlin_version = '1.6.21'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0-beta04'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// TODO: Close JCenter on May 1st https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.caching=true
android.enableBuildCache=true

VERSION_NAME=2.1.0
VERSION_CODE=14
Expand Down
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Tue Jun 10 09:06:40 CST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion library/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)
cmake_minimum_required(VERSION 3.5)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Camera2Loader(private val activity: Activity) : CameraLoader() {

private val cameraManager: CameraManager by lazy {
activity.getSystemService(Context.CAMERA_SERVICE) as CameraManager

}

override fun onResume(width: Int, height: Int) {
Expand Down Expand Up @@ -120,21 +121,35 @@ class Camera2Loader(private val activity: Activity) : CameraLoader() {
return Size(0, 0)
}
val cameraId = getCameraId(cameraFacing) ?: return Size(0, 0)
val outputSizes = cameraManager.getCameraCharacteristics(cameraId)
val map = cameraManager
.getCameraCharacteristics(cameraId)
.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)
?.getOutputSizes(ImageFormat.YUV_420_888)
val outputSizes = map?.getOutputSizes(ImageFormat.YUV_420_888) ?: return Size(PREVIEW_WIDTH, PREVIEW_HEIGHT)

val degrees = when (activity.windowManager.defaultDisplay.rotation) {
Surface.ROTATION_0 -> 0
Surface.ROTATION_90 -> 90
Surface.ROTATION_180 -> 180
Surface.ROTATION_270 -> 270
else -> 0
}
val isRotated = (degrees == 90 || degrees == 270)
val maxPreviewWidth = if (isRotated) viewHeight else viewWidth
val maxPreviewHeight = if (isRotated) viewWidth else viewHeight

val orientation = getCameraOrientation()
val maxPreviewWidth = if (orientation == 90 or 270) viewHeight else viewWidth
val maxPreviewHeight = if (orientation == 90 or 270) viewWidth else viewHeight
val candidates = outputSizes.filter {
it.width < maxPreviewWidth / 2 &&
it.height < maxPreviewHeight / 2
}

return outputSizes?.filter {
it.width < maxPreviewWidth / 2 && it.height < maxPreviewHeight / 2
}?.maxBy {
it.width * it.height
} ?: Size(PREVIEW_WIDTH, PREVIEW_HEIGHT)
val best = candidates.maxByOrNull { size ->
size.width * size.height
}

return best ?: Size(PREVIEW_WIDTH, PREVIEW_HEIGHT)
}


private inner class CameraDeviceCallback : CameraDevice.StateCallback() {
override fun onOpened(camera: CameraDevice) {
cameraInstance = camera
Expand Down