1 /* Copyright 2022 Advanced Micro Devices, Inc.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom thesrc/core/color.c
8 * Software is furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
17 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19 * OTHER DEALINGS IN THE SOFTWARE.
20 *
21 * Authors: AMD
22 *
23 */
24
25 #include "geometric_scaling.h"
26
27 /*
28 * Geometric scaling is to support multiple pass resizing to achieve larger resize ratio.
29 * User will need to set stream.flags.geometric_scaling = 1
30 * With the gs flag set to true, VPE will disable following feature
31 * 1. gamma remapping, the input tf will be used for output tf.
32 * 2. gamut remapping, the input primiaries/range will be used for output.
33 * 3. tone mapping, tone mapping will be disabled.
34 * 4. blending, blending will be disabled.
35 *
36 */
37
vpe_geometric_scaling_feature_skip(struct vpe_priv * vpe_priv,const struct vpe_build_param * param)38 void vpe_geometric_scaling_feature_skip(
39 struct vpe_priv *vpe_priv, const struct vpe_build_param *param)
40 {
41 if (param->streams && param->streams->flags.geometric_scaling) {
42 /* copy input cs to output for skiping gamut and gamma conversion */
43 vpe_priv->output_ctx.surface.cs.primaries = param->streams[0].surface_info.cs.primaries;
44 vpe_priv->output_ctx.surface.cs.tf = param->streams[0].surface_info.cs.tf;
45 vpe_priv->output_ctx.surface.cs.cositing = VPE_CHROMA_COSITING_NONE;
46 vpe_priv->output_ctx.surface.cs.range = VPE_COLOR_RANGE_FULL;
47
48 /* skip tone mapping */
49 vpe_priv->stream_ctx[0].stream.tm_params.UID = 0;
50 vpe_priv->stream_ctx[0].stream.tm_params.enable_3dlut = false;
51
52 /* disable blending */
53 vpe_priv->stream_ctx[0].stream.blend_info.blending = false;
54 }
55
56 }
57
58 /*
59 * Geometric scaling feature has two requirement when enabled:
60 * 1. only support single input stream, no blending support.
61 * 2. the target rect must equal to destination rect.
62 */
63
vpe_validate_geometric_scaling_support(const struct vpe_build_param * param)64 enum vpe_status vpe_validate_geometric_scaling_support(const struct vpe_build_param *param)
65 {
66 if (param->num_streams && param->streams) {
67 if (param->streams[0].flags.geometric_scaling) {
68 /* only support 1 stream */
69 if (param->num_streams > 1) {
70 return VPE_STATUS_GEOMETRICSCALING_ERROR;
71 }
72
73 /* dest rect must equal to target rect */
74 if (param->target_rect.height != param->streams[0].scaling_info.dst_rect.height ||
75 param->target_rect.width != param->streams[0].scaling_info.dst_rect.width ||
76 param->target_rect.x != param->streams[0].scaling_info.dst_rect.x ||
77 param->target_rect.y != param->streams[0].scaling_info.dst_rect.y)
78 return VPE_STATUS_GEOMETRICSCALING_ERROR;
79 }
80 }
81 return VPE_STATUS_OK;
82 }
83
vpe_update_geometric_scaling(struct vpe_priv * vpe_priv,const struct vpe_build_param * param,bool * geometric_update,bool * geometric_scaling)84 void vpe_update_geometric_scaling(struct vpe_priv *vpe_priv, const struct vpe_build_param *param,
85 bool *geometric_update, bool *geometric_scaling)
86 {
87 bool cached_gds = false;
88 bool is_gds = false;
89
90 if (param->num_streams == 1 && vpe_priv->stream_ctx) {
91 cached_gds = vpe_priv->stream_ctx[0].geometric_scaling;
92 is_gds = (bool)vpe_priv->stream_ctx[0].stream.flags.geometric_scaling;
93
94 if (cached_gds != is_gds) {
95 *geometric_update = true;
96 // Vpe needs to apply the cooresponding whitepoint on the last pass
97 // based on the input format of the first pass
98 if (is_gds) { // First pass
99 vpe_priv->stream_ctx[0].is_yuv_input =
100 vpe_priv->stream_ctx[0].stream.surface_info.cs.encoding ==
101 VPE_PIXEL_ENCODING_YCbCr;
102 }
103 }
104 }
105 *geometric_scaling = is_gds;
106 }
107