/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.test.silkfx.hdr import android.graphics.Gainmap import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Button import android.widget.PopupWindow import android.widget.SeekBar import android.widget.TextView import com.android.test.silkfx.R data class GainmapMetadata( var ratioMin: Float, var ratioMax: Float, var capacityMin: Float, var capacityMax: Float, var gamma: Float, var offsetSdr: Float, var offsetHdr: Float ) /** * Note: This can only handle single-channel gainmaps nicely. It will force all 3-channel * metadata to have the same value single value and is not intended to be a robust demonstration * of gainmap metadata editing */ class GainmapMetadataEditor(val parent: ViewGroup, val renderView: View) { private lateinit var gainmap: Gainmap private var metadataPopup: PopupWindow? = null private var originalMetadata: GainmapMetadata = GainmapMetadata( 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f) private var currentMetadata: GainmapMetadata = originalMetadata.copy() private val maxProgress = 100.0f private val minRatioMin = .001f private val maxRatioMin = 1.0f private val minRatioMax = 1.0f private val maxRatioMax = 16.0f private val minCapacityMin = 1.0f private val maxCapacityMin = maxRatioMax private val minCapacityMax = 1.001f private val maxCapacityMax = maxRatioMax private val minGamma = 0.1f private val maxGamma = 3.0f // Min and max offsets are 0.0 and 1.0 respectively fun setGainmap(newGainmap: Gainmap) { gainmap = newGainmap originalMetadata = GainmapMetadata(gainmap.getRatioMin()[0], gainmap.getRatioMax()[0], gainmap.getMinDisplayRatioForHdrTransition(), gainmap.getDisplayRatioForFullHdr(), gainmap.getGamma()[0], gainmap.getEpsilonSdr()[0], gainmap.getEpsilonHdr()[0]) currentMetadata = originalMetadata.copy() } fun editedGainmap(): Gainmap { applyMetadata(currentMetadata) return gainmap } fun closeEditor() { metadataPopup?.let { it.dismiss() metadataPopup = null } } fun openEditor() { if (metadataPopup != null) return val view = LayoutInflater.from(parent.getContext()).inflate(R.layout.gainmap_metadata, null) metadataPopup = PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) metadataPopup!!.showAtLocation(view, Gravity.CENTER, 0, 0) (view.getParent() as ViewGroup).removeView(view) parent.addView(view) view.requireViewById