3

I was inspired by this topic to implement brightness and contrass in my camera app, but when I playing with gamma/contrast it doesn't work at all. Im using createCaptureRequest(CameraDevice.TEMPLATE_RECORD) mode in Android Camera2 API.

The problem is the bellow code has no effect on the video preview:

captureRequestBuilder.set(CaptureRequest.TONEMAP_MODE, CaptureRequest.TONEMAP_MODE_GAMMA_VALUE)
captureRequestBuilder.set(CaptureRequest.TONEMAP_GAMMA, level)
captureSession.setRepeatingRequest(
                captureRequestBuilder.build(), null, null)

Whatever level value I set it's just nothing.

Another problem with contrast:

private val channels by lazy {
    val tc = captureRequestBuilder.get(CaptureRequest.TONEMAP_CURVE) ?: return@lazy null
    val channels = arrayOf(floatArrayOf(), floatArrayOf(), floatArrayOf())
    for(channel in TonemapCurve.CHANNEL_RED .. TonemapCurve.CHANNEL_BLUE) {
        val contrast = FloatArray(tc.getPointCount(channel) * 2)
        tc.copyColorCurve(channel, contrast, 0)
        channels[channel] = contrast
    }
    channels
}
fun setContrast(level: Float) {
        val level = level.coerceIn(0f, 1f)
        val channels = channels ?: return
        val newContrast = arrayOf(floatArrayOf(), floatArrayOf(), floatArrayOf())
        for(channel in TonemapCurve.CHANNEL_RED .. TonemapCurve.CHANNEL_BLUE) {
            val contrast = FloatArray(channels[channel].size)
            System.arraycopy(channels[channel], 0, contrast, 0, contrast.size)
            contrast.forEachIndexed { index, _ ->
                contrast[index] *= level
            }
            newContrast[channel] = contrast
        }

        val newValue = TonemapCurve(newContrast[TonemapCurve.CHANNEL_RED],
                newContrast[TonemapCurve.CHANNEL_GREEN],
                newContrast[TonemapCurve.CHANNEL_BLUE])
        captureRequestBuilder.set(CaptureRequest.TONEMAP_MODE, CaptureRequest.TONEMAP_MODE_CONTRAST_CURVE)
        captureRequestBuilder.set(CaptureRequest.TONEMAP_CURVE, newValue)
        captureSession.setRepeatingRequest(
                captureRequestBuilder.build(), null, null)
    }

captureRequestBuilder.get(CaptureRequest.TONEMAP_CURVE) always return null and even if try to set manually captureRequestBuilder.set(CaptureRequest.TONEMAP_CURVE, newValue) is still no any changes on video preview.

There is any solution how to implement contrast and gamma properly on Android camera video preview with CameraDevice.TEMPLATE_RECORD ?

Arsenius
  • 4,972
  • 4
  • 26
  • 39

0 Answers0