forked from Blendman974/faceclaw
Center the phone screen preview
This commit is contained in:
1 parent
f6201d8e41
commit
96e3bd95f7
18 files changed
+311
-24
No files matched your search
@@ -242,6 +242,15 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre
|
||||
java.nio.ByteBuffer.wrap(composite.gray), composite.width, composite.height, brightenGamma, green)
|
||||
}
|
||||
|
||||
/** As above, cropped to a screen area (Settings > Phone display > Preview scaling); black past the screen's edges. */
|
||||
fun getCompositePreviewBitmap(brightenGamma: Double, green: Boolean,
|
||||
cropX: Int, cropY: Int, cropWidth: Int, cropHeight: Int): android.graphics.Bitmap? {
|
||||
val composite = core.previewComposite() ?: return null
|
||||
return PreviewBitmapUtil.fromGray(
|
||||
java.nio.ByteBuffer.wrap(composite.gray), composite.width, composite.height, brightenGamma, green,
|
||||
cropX, cropY, cropWidth, cropHeight)
|
||||
}
|
||||
|
||||
/**
|
||||
* Posted to the main looper after each step of an animation the preview is replaying (menu
|
||||
* highlight slides, scrolls), so the mirror can pull the new frame; frame metrics only cover
|
||||
|
||||
@@ -139,6 +139,15 @@ class FaceclawPreviewCompositor(context: Context) {
|
||||
java.nio.ByteBuffer.wrap(composite.gray), composite.width, composite.height, brightenGamma, green)
|
||||
}
|
||||
|
||||
/** As above, cropped to a screen area (Settings > Phone display > Preview scaling); black past the screen's edges. */
|
||||
fun getCompositePreviewBitmap(brightenGamma: Double, green: Boolean,
|
||||
cropX: Int, cropY: Int, cropWidth: Int, cropHeight: Int): android.graphics.Bitmap? {
|
||||
val composite = compositor.previewComposite() ?: return null
|
||||
return PreviewBitmapUtil.fromGray(
|
||||
java.nio.ByteBuffer.wrap(composite.gray), composite.width, composite.height, brightenGamma, green,
|
||||
cropX, cropY, cropWidth, cropHeight)
|
||||
}
|
||||
|
||||
/** Save the current composite as a 4-bit grayscale PNG; returns the path or "". */
|
||||
@Throws(java.io.IOException::class)
|
||||
fun saveCompositePngScreenshot(): String {
|
||||
|
||||
@@ -31,6 +31,34 @@ class PreviewBitmapUtil private constructor() {
|
||||
return Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888)
|
||||
}
|
||||
|
||||
/**
|
||||
* As above, showing only the cropWidth x cropHeight area at (cropX, cropY) (the
|
||||
* mirror's Scaled preview). The area may extend past the frame's edges; it is black
|
||||
* there.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun fromGray(gray: ByteBuffer?, width: Int, height: Int, brightenGamma: Double, green: Boolean,
|
||||
cropX: Int, cropY: Int, cropWidth: Int, cropHeight: Int): Bitmap {
|
||||
if (gray == null || width <= 0 || height <= 0 || gray.remaining() < width * height) {
|
||||
throw IllegalArgumentException("invalid gray preview buffer")
|
||||
}
|
||||
if (cropWidth <= 0 || cropHeight <= 0) {
|
||||
throw IllegalArgumentException("invalid preview crop")
|
||||
}
|
||||
val bytes = ByteArray(width * height)
|
||||
gray.get(bytes)
|
||||
val cropped = ByteArray(cropWidth * cropHeight)
|
||||
val left = maxOf(cropX, 0)
|
||||
val right = minOf(cropX + cropWidth, width)
|
||||
if (right > left) {
|
||||
for (y in maxOf(cropY, 0) until minOf(cropY + cropHeight, height)) {
|
||||
System.arraycopy(bytes, y * width + left, cropped, (y - cropY) * cropWidth + (left - cropX), right - left)
|
||||
}
|
||||
}
|
||||
val colors = PreviewPalette.expand(cropped, 0, cropped.size, brightenGamma, green)
|
||||
return Bitmap.createBitmap(colors, cropWidth, cropHeight, Bitmap.Config.ARGB_8888)
|
||||
}
|
||||
|
||||
/**
|
||||
* A white-on-transparent bitmap of an 8bpp glasses icon (gray becomes
|
||||
* alpha; black, which the glasses show as unlit, is transparent), for
|
||||
|
||||
Reference in new issue
Block a user