feat(core/camera_tweaks): black photos

This commit is contained in:
rhunk 2023-11-08 17:30:48 +01:00
parent 8823093b30
commit 81f626cc3b
3 changed files with 24 additions and 0 deletions

View File

@ -434,6 +434,10 @@
"name": "Disable Camera",
"description": "Prevents Snapchat from using the cameras available on your device"
},
"black_photos": {
"name": "Black Photos",
"description": "Replaces captured photos with a black background\nVideos are not affected"
},
"immersive_camera_preview": {
"name": "Immersive Preview",
"description": "Prevents Snapchat from Cropping the Camera preview\nThis might cause the camera to flicker on some devices"

View File

@ -40,6 +40,7 @@ class Camera : ConfigContainer() {
val disable = boolean("disable_camera")
val immersiveCameraPreview = boolean("immersive_camera_preview") { addNotices(FeatureNotice.UNSTABLE) }
val blackPhotos = boolean("black_photos")
val overridePreviewResolution get() = _overridePreviewResolution
val overridePictureResolution get() = _overridePictureResolution
val customFrameRate = unique("custom_frame_rate",

View File

@ -4,9 +4,11 @@ import android.Manifest
import android.annotation.SuppressLint
import android.content.ContextWrapper
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.hardware.camera2.CameraCharacteristics
import android.hardware.camera2.CameraCharacteristics.Key
import android.hardware.camera2.CameraManager
import android.media.Image
import android.util.Range
import me.rhunk.snapenhance.core.features.Feature
import me.rhunk.snapenhance.core.features.FeatureLoadParams
@ -15,6 +17,8 @@ import me.rhunk.snapenhance.core.util.hook.hook
import me.rhunk.snapenhance.core.util.hook.hookConstructor
import me.rhunk.snapenhance.core.util.ktx.setObjectField
import me.rhunk.snapenhance.core.wrapper.impl.ScSize
import java.io.ByteArrayOutputStream
import java.nio.ByteBuffer
class CameraTweaks : Feature("Camera Tweaks", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) {
@ -71,5 +75,20 @@ class CameraTweaks : Feature("Camera Tweaks", loadParams = FeatureLoadParams.ACT
}
}
}
if (context.config.camera.blackPhotos.get()) {
findClass("android.media.ImageReader\$SurfaceImage").hook("getPlanes", HookStage.AFTER) { param ->
val image = param.thisObject() as? Image ?: return@hook
val planes = param.getResult() as? Array<*> ?: return@hook
val output = ByteArrayOutputStream()
Bitmap.createBitmap(image.width, image.height, Bitmap.Config.ARGB_8888).apply {
compress(Bitmap.CompressFormat.JPEG, 100, output)
recycle()
}
planes.filterNotNull().forEach { plane ->
plane.setObjectField("mBuffer", ByteBuffer.wrap(output.toByteArray()))
}
}
}
}
}