18 1.164, 1.164, 1.164, 0.0,
19 0.0, -0.392, 2.017, 0.0,
20 1.596, -0.813, 0.0, 0.0,
26 0.0, -0.344, 1.772, 0.0,
27 1.402, -0.714, 0.0, 0.0,
37 yuv_color_space_ = yuv_color_space;
40 std::optional<Entity> YUVToRGBFilterContents::RenderFilter(
44 const Matrix& effect_transform,
46 const std::optional<Rect>& coverage_hint)
const {
47 if (inputs.size() < 2) {
54 auto y_input_snapshot =
55 inputs[0]->GetSnapshot(
"YUVToRGB(Y)", renderer, entity);
56 auto uv_input_snapshot =
57 inputs[1]->GetSnapshot(
"YUVToRGB(UV)", renderer, entity);
58 if (!y_input_snapshot.has_value() || !uv_input_snapshot.has_value()) {
62 if (y_input_snapshot->texture->GetTextureDescriptor().format !=
64 uv_input_snapshot->texture->GetTextureDescriptor().format !=
72 RenderProc render_proc = [y_input_snapshot, uv_input_snapshot,
73 yuv_color_space = yuv_color_space_](
74 const ContentContext& renderer,
75 const Entity& entity, RenderPass& pass) ->
bool {
78 cmd.stencil_reference = entity.GetStencilDepth();
81 cmd.pipeline = renderer.GetYUVToRGBFilterPipeline(options);
83 auto size = y_input_snapshot->texture->GetSize();
85 VertexBufferBuilder<VS::PerVertexData> vtx_builder;
86 vtx_builder.AddVertices({
95 auto& host_buffer = pass.GetTransientsBuffer();
96 auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
97 cmd.BindVertices(vtx_buffer);
99 VS::FrameInfo frame_info;
101 entity.GetTransformation() * y_input_snapshot->transform *
103 frame_info.texture_sampler_y_coord_scale =
104 y_input_snapshot->texture->GetYCoordScale();
106 FS::FragInfo frag_info;
107 frag_info.yuv_color_space =
static_cast<Scalar>(yuv_color_space);
108 switch (yuv_color_space) {
117 auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
118 FS::BindYTexture(cmd, y_input_snapshot->texture, sampler);
119 FS::BindUvTexture(cmd, uv_input_snapshot->texture, sampler);
121 FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
122 VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
124 return pass.AddCommand(std::move(cmd));
128 [coverage](
const Entity& entity) -> std::optional<Rect> {
135 sub_entity.SetContents(std::move(contents));
136 sub_entity.SetStencilDepth(entity.GetStencilDepth());
137 sub_entity.SetBlendMode(entity.GetBlendMode());