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 /* copy input cs to output for skiping gamut and gamma conversion */
42 vpe_priv->output_ctx.surface.cs.primaries = param->streams[0].surface_info.cs.primaries;
43 vpe_priv->output_ctx.surface.cs.tf = param->streams[0].surface_info.cs.tf;
44 vpe_priv->output_ctx.surface.cs.cositing = VPE_CHROMA_COSITING_NONE;
45 vpe_priv->output_ctx.surface.cs.range = VPE_COLOR_RANGE_FULL;
46
47 /* skip tone mapping */
48 vpe_priv->stream_ctx[0].stream.tm_params.UID = 0;
49 vpe_priv->stream_ctx[0].stream.tm_params.enable_3dlut = false;
50
51 /* disable blending */
52 vpe_priv->stream_ctx[0].stream.blend_info.blending = false;
53
54 }
55
56 /*
57 * Geometric scaling feature has two requirement when enabled:
58 * 1. only support single input stream, no blending support.
59 * 2. the target rect must equal to destination rect.
60 */
61
vpe_validate_geometric_scaling_support(const struct vpe_build_param * param)62 enum vpe_status vpe_validate_geometric_scaling_support(const struct vpe_build_param *param)
63 {
64 if (param->streams[0].flags.geometric_scaling) {
65 /* only support 1 stream */
66 if (param->num_streams > 1) {
67 return VPE_STATUS_GEOMETRICSCALING_ERROR;
68 }
69
70 /* dest rect must equal to target rect */
71 if (param->target_rect.height != param->streams[0].scaling_info.dst_rect.height ||
72 param->target_rect.width != param->streams[0].scaling_info.dst_rect.width ||
73 param->target_rect.x != param->streams[0].scaling_info.dst_rect.x ||
74 param->target_rect.y != param->streams[0].scaling_info.dst_rect.y)
75 return VPE_STATUS_GEOMETRICSCALING_ERROR;
76 }
77 return VPE_STATUS_OK;
78 }
79
vpe_update_geometric_scaling(struct vpe_priv * vpe_priv,const struct vpe_build_param * param,bool * geometric_update,bool * geometric_scaling)80 void vpe_update_geometric_scaling(struct vpe_priv *vpe_priv, const struct vpe_build_param *param,
81 bool *geometric_update, bool *geometric_scaling)
82 {
83 bool cached_gds = vpe_priv->stream_ctx[0].geometric_scaling;
84 bool is_gds = (bool)vpe_priv->stream_ctx[0].stream.flags.geometric_scaling;
85 if (param->num_streams == 1) {
86 if (cached_gds != is_gds) {
87 *geometric_update = true;
88 // Vpe needs to apply the cooresponding whitepoint on the last pass
89 // based on the input format of the first pass
90 if (is_gds) { // First pass
91 vpe_priv->stream_ctx[0].is_yuv_input =
92 vpe_priv->stream_ctx[0].stream.surface_info.cs.encoding ==
93 VPE_PIXEL_ENCODING_YCbCr;
94 }
95 }
96
97 *geometric_scaling = is_gds;
98 }
99 }
100