[Mesa-dev] [PATCH 2/2] st/vdpau: use lumakey filter to apply luma keyring
Nayan Deshmukh
nayan26deshmukh at gmail.com
Fri May 27 10:50:50 UTC 2016
Signed-off-by: Nayan Deshmukh <nayan26deshmukh at gmail.com>
---
src/gallium/state_trackers/vdpau/mixer.c | 76 +++++++++++++++++++-----
src/gallium/state_trackers/vdpau/vdpau_private.h | 8 ++-
2 files changed, 68 insertions(+), 16 deletions(-)
diff --git a/src/gallium/state_trackers/vdpau/mixer.c b/src/gallium/state_trackers/vdpau/mixer.c
index dec79ff..f44d5c9 100644
--- a/src/gallium/state_trackers/vdpau/mixer.c
+++ b/src/gallium/state_trackers/vdpau/mixer.c
@@ -92,7 +92,6 @@ vlVdpVideoMixerCreate(VdpDevice device,
case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8:
case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9:
case VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE:
- case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY:
break;
case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL:
@@ -107,6 +106,10 @@ vlVdpVideoMixerCreate(VdpDevice device,
vmixer->noise_reduction.supported = true;
break;
+ case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY:
+ vmixer->luma_key.supported = true;
+ break;
+
default: goto no_params;
}
}
@@ -148,8 +151,8 @@ vlVdpVideoMixerCreate(VdpDevice device,
vmixer->video_height, max_size);
goto no_params;
}
- vmixer->luma_key_min = 0.f;
- vmixer->luma_key_max = 1.f;
+ vmixer->luma_key.min_luma = 0.f;
+ vmixer->luma_key.max_luma = 1.f;
pipe_mutex_unlock(dev->mutex);
return VDP_STATUS_OK;
@@ -199,6 +202,12 @@ vlVdpVideoMixerDestroy(VdpVideoMixer mixer)
vl_matrix_filter_cleanup(vmixer->sharpness.filter);
FREE(vmixer->sharpness.filter);
}
+
+ if (vmixer->luma_key.filter) {
+ vl_lumakey_filter_cleanup(vmixer->luma_key.filter);
+ FREE(vmixer->luma_key.filter);
+ }
+
pipe_mutex_unlock(vmixer->device->mutex);
DeviceReference(&vmixer->device, NULL);
@@ -341,7 +350,7 @@ VdpStatus vlVdpVideoMixerRender(VdpVideoMixer mixer,
}
vl_compositor_set_dst_clip(&vmixer->cstate, RectToPipe(destination_rect, &clip));
- if (!vmixer->noise_reduction.filter && !vmixer->sharpness.filter)
+ if (!vmixer->noise_reduction.filter && !vmixer->sharpness.filter && !vmixer->luma_key.filter)
vlVdpSave4DelayedRendering(vmixer->device, destination_surface, &vmixer->cstate);
else {
vl_compositor_render(&vmixer->cstate, compositor, dst->surface, &dst->dirty_area, true);
@@ -356,6 +365,11 @@ VdpStatus vlVdpVideoMixerRender(VdpVideoMixer mixer,
if (vmixer->sharpness.filter)
vl_matrix_filter_render(vmixer->sharpness.filter,
dst->sampler_view, dst->surface);
+
+ if (vmixer->luma_key.filter)
+ vl_lumakey_filter_render(vmixer->luma_key.filter,
+ dst->sampler_view, dst->surface);
+
}
pipe_mutex_unlock(vmixer->device->mutex);
@@ -457,6 +471,27 @@ vlVdpVideoMixerUpdateSharpnessFilter(vlVdpVideoMixer *vmixer)
}
}
+static void
+vlVdpVideoMixerUpdateLumaKeyFilter(vlVdpVideoMixer *vmixer)
+{
+ assert(vmixer);
+
+ /* if present remove the old filter first */
+ if (vmixer->luma_key.filter) {
+ vl_lumakey_filter_cleanup(vmixer->luma_key.filter);
+ FREE(vmixer->luma_key.filter);
+ vmixer->luma_key.filter = NULL;
+ }
+
+ /* and create a new filter as needed */
+ if (vmixer->luma_key.enabled) {
+ vmixer->luma_key.filter = MALLOC(sizeof(struct vl_lumakey_filter));
+ vl_lumakey_filter_init(vmixer->luma_key.filter, vmixer->device->context,
+ vmixer->video_width, vmixer->video_height,
+ vmixer->luma_key.min_luma, vmixer->luma_key.max_luma);
+ }
+}
+
/**
* Retrieve whether features were requested at creation time.
*/
@@ -490,7 +525,6 @@ vlVdpVideoMixerGetFeatureSupport(VdpVideoMixer mixer,
case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8:
case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9:
case VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE:
- case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY:
feature_supports[i] = false;
break;
@@ -506,6 +540,10 @@ vlVdpVideoMixerGetFeatureSupport(VdpVideoMixer mixer,
feature_supports[i] = vmixer->noise_reduction.supported;
break;
+ case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY:
+ feature_supports[i] = vmixer->luma_key.supported;
+ break;
+
default:
return VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE;
}
@@ -548,7 +586,6 @@ vlVdpVideoMixerSetFeatureEnables(VdpVideoMixer mixer,
case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8:
case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9:
case VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE:
- case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY:
break;
case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL:
@@ -566,6 +603,11 @@ vlVdpVideoMixerSetFeatureEnables(VdpVideoMixer mixer,
vlVdpVideoMixerUpdateNoiseReductionFilter(vmixer);
break;
+ case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY:
+ vmixer->luma_key.enabled = feature_enables[i];
+ vlVdpVideoMixerUpdateLumaKeyFilter(vmixer);
+ break;
+
default:
pipe_mutex_unlock(vmixer->device->mutex);
return VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE;
@@ -610,7 +652,6 @@ vlVdpVideoMixerGetFeatureEnables(VdpVideoMixer mixer,
case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8:
case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9:
case VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE:
- case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY:
break;
case VDP_VIDEO_MIXER_FEATURE_SHARPNESS:
@@ -621,6 +662,10 @@ vlVdpVideoMixerGetFeatureEnables(VdpVideoMixer mixer,
feature_enables[i] = vmixer->noise_reduction.enabled;
break;
+ case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY:
+ feature_enables[i] = vmixer->luma_key.enabled;
+ break;
+
default:
return VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE;
}
@@ -663,6 +708,7 @@ vlVdpVideoMixerSetAttributeValues(VdpVideoMixer mixer,
color.f[3] = background_color->alpha;
vl_compositor_set_clear_color(&vmixer->cstate, &color);
break;
+
case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX:
vdp_csc = attribute_values[i];
vmixer->custom_csc = !!vdp_csc;
@@ -675,13 +721,11 @@ vlVdpVideoMixerSetAttributeValues(VdpVideoMixer mixer,
break;
case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL:
-
val = *(float*)attribute_values[i];
if (val < 0.f || val > 1.f) {
ret = VDP_STATUS_INVALID_VALUE;
goto fail;
}
-
vmixer->noise_reduction.level = val * 10;
vlVdpVideoMixerUpdateNoiseReductionFilter(vmixer);
break;
@@ -692,25 +736,26 @@ vlVdpVideoMixerSetAttributeValues(VdpVideoMixer mixer,
ret = VDP_STATUS_INVALID_VALUE;
goto fail;
}
- vmixer->luma_key_min = val;
+ vmixer->luma_key.min_luma = val;
+ vlVdpVideoMixerUpdateLumaKeyFilter(vmixer);
break;
+
case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA:
val = *(float*)attribute_values[i];
if (val < 0.f || val > 1.f) {
ret = VDP_STATUS_INVALID_VALUE;
goto fail;
}
- vmixer->luma_key_max = val;
+ vmixer->luma_key.max_luma = val;
+ vlVdpVideoMixerUpdateLumaKeyFilter(vmixer);
break;
case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL:
-
val = *(float*)attribute_values[i];
if (val < -1.f || val > 1.f) {
ret = VDP_STATUS_INVALID_VALUE;
goto fail;
}
-
vmixer->sharpness.value = val;
vlVdpVideoMixerUpdateSharpnessFilter(vmixer);
break;
@@ -723,6 +768,7 @@ vlVdpVideoMixerSetAttributeValues(VdpVideoMixer mixer,
vmixer->skip_chroma_deint = *(uint8_t*)attribute_values[i];
vlVdpVideoMixerUpdateDeinterlaceFilter(vmixer);
break;
+
default:
ret = VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE;
goto fail;
@@ -814,10 +860,10 @@ vlVdpVideoMixerGetAttributeValues(VdpVideoMixer mixer,
break;
case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA:
- *(float*)attribute_values[i] = vmixer->luma_key_min;
+ *(float*)attribute_values[i] = vmixer->luma_key.min_luma;
break;
case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA:
- *(float*)attribute_values[i] = vmixer->luma_key_max;
+ *(float*)attribute_values[i] = vmixer->luma_key.max_luma;
break;
case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL:
*(float*)attribute_values[i] = vmixer->sharpness.value;
diff --git a/src/gallium/state_trackers/vdpau/vdpau_private.h b/src/gallium/state_trackers/vdpau/vdpau_private.h
index 3b6647e..b38f47c 100644
--- a/src/gallium/state_trackers/vdpau/vdpau_private.h
+++ b/src/gallium/state_trackers/vdpau/vdpau_private.h
@@ -50,6 +50,7 @@
#include "vl/vl_deint_filter.h"
#include "vl/vl_matrix_filter.h"
#include "vl/vl_median_filter.h"
+#include "vl/vl_lumakey_filter.h"
#include "vl/vl_winsys.h"
/* Full VDPAU API documentation available at :
@@ -363,6 +364,12 @@ typedef struct
struct vl_compositor_state cstate;
struct {
+ bool supported, enabled;
+ float min_luma, max_luma;
+ struct vl_lumakey_filter *filter;
+ } luma_key;
+
+ struct {
bool supported, enabled, spatial;
struct vl_deint_filter *filter;
} deint;
@@ -382,7 +389,6 @@ typedef struct
unsigned video_width, video_height;
enum pipe_video_chroma_format chroma_format;
unsigned max_layers, skip_chroma_deint;
- float luma_key_min, luma_key_max;
bool custom_csc;
vl_csc_matrix csc;
--
2.5.5
More information about the mesa-dev
mailing list