From cbc0ff435fa99230ba950117fbed683d58e91b7e Mon Sep 17 00:00:00 2001 From: Markus Fisch Date: Sun, 3 Sep 2017 12:26:49 +0200 Subject: [PATCH] Invert every second frame Forgot to invert every second frame to also read inverted barcodes while simplifying image processing. --- .../de/markusfisch/android/binaryeye/rs/YuvToGray.kt | 10 +++++++++- app/src/main/rs/yuv2gray.rs | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/de/markusfisch/android/binaryeye/rs/YuvToGray.kt b/app/src/main/kotlin/de/markusfisch/android/binaryeye/rs/YuvToGray.kt index 5092292c..5c3f7472 100644 --- a/app/src/main/kotlin/de/markusfisch/android/binaryeye/rs/YuvToGray.kt +++ b/app/src/main/kotlin/de/markusfisch/android/binaryeye/rs/YuvToGray.kt @@ -21,6 +21,7 @@ class YuvToGray(context: Context) { private var rgbaAlloc: Allocation? = null private var destAlloc: Allocation? = null private var dest: Bitmap? = null + private var odd = true fun destroy() { yuvType?.destroy() @@ -76,7 +77,14 @@ class YuvToGray(context: Context) { // width/height are uint_32 but Kotlin wants toLong() yuv2grayScript._inWidth = width.toLong() yuv2grayScript._inHeight = height.toLong() - yuv2grayScript.forEach_yuv2gray(rgbaAlloc) + + // invert every second frame to also read inverted barcodes + if (odd) { + yuv2grayScript.forEach_yuv2gray(rgbaAlloc) + } else { + yuv2grayScript.forEach_yuv2inverted(rgbaAlloc) + } + odd = odd xor true rotatorScript._inImage = rgbaAlloc rotatorScript._inWidth = width diff --git a/app/src/main/rs/yuv2gray.rs b/app/src/main/rs/yuv2gray.rs index 8cca4cc9..a8c33d2f 100644 --- a/app/src/main/rs/yuv2gray.rs +++ b/app/src/main/rs/yuv2gray.rs @@ -15,3 +15,13 @@ uchar4 RS_KERNEL yuv2gray(uint32_t x, uint32_t y) { out.a = 255; return out; } + +uchar4 RS_KERNEL yuv2inverted(uint32_t x, uint32_t y) { + uchar Y = 255 - rsGetElementAt_uchar(inYUV, x, y); + uchar4 out; + out.r = Y; + out.g = Y; + out.b = Y; + out.a = 255; + return out; +}