Coverage Report

Created: 2025-10-12 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvpx/vp9/vp9_iface_common.c
Line
Count
Source
1
/*
2
 *  Copyright (c) 2019 The WebM project authors. All Rights Reserved.
3
 *
4
 *  Use of this source code is governed  by a BSD-style license that can be
5
 *  found in the LICENSE file in the root of the source tree. An additional
6
 *  intellectual property  rights grant can  be found in the  file PATENTS.
7
 *  All contributing  project authors may be  found in the AUTHORS  file in
8
 *  the root of the source tree.
9
 */
10
11
#include "vp9/vp9_iface_common.h"
12
void yuvconfig2image(vpx_image_t *img, const YV12_BUFFER_CONFIG *yv12,
13
20.5k
                     void *user_priv) {
14
  /** vpx_img_wrap() doesn't allow specifying independent strides for
15
   * the Y, U, and V planes, nor other alignment adjustments that
16
   * might be representable by a YV12_BUFFER_CONFIG, so we just
17
   * initialize all the fields.*/
18
20.5k
  int bps;
19
20.5k
  if (!yv12->subsampling_y) {
20
660
    if (!yv12->subsampling_x) {
21
289
      img->fmt = VPX_IMG_FMT_I444;
22
289
      bps = 24;
23
371
    } else {
24
371
      img->fmt = VPX_IMG_FMT_I422;
25
371
      bps = 16;
26
371
    }
27
19.8k
  } else {
28
19.8k
    if (!yv12->subsampling_x) {
29
77
      img->fmt = VPX_IMG_FMT_I440;
30
77
      bps = 16;
31
19.7k
    } else {
32
19.7k
      img->fmt = VPX_IMG_FMT_I420;
33
19.7k
      bps = 12;
34
19.7k
    }
35
19.8k
  }
36
20.5k
  img->cs = yv12->color_space;
37
20.5k
  img->range = yv12->color_range;
38
20.5k
  img->bit_depth = 8;
39
20.5k
  img->w = yv12->y_stride;
40
20.5k
  img->h = ALIGN_POWER_OF_TWO(yv12->y_height + 2 * VP9_ENC_BORDER_IN_PIXELS, 3);
41
20.5k
  img->d_w = yv12->y_crop_width;
42
20.5k
  img->d_h = yv12->y_crop_height;
43
20.5k
  img->r_w = yv12->render_width;
44
20.5k
  img->r_h = yv12->render_height;
45
20.5k
  img->x_chroma_shift = yv12->subsampling_x;
46
20.5k
  img->y_chroma_shift = yv12->subsampling_y;
47
20.5k
  img->planes[VPX_PLANE_Y] = yv12->y_buffer;
48
20.5k
  img->planes[VPX_PLANE_U] = yv12->u_buffer;
49
20.5k
  img->planes[VPX_PLANE_V] = yv12->v_buffer;
50
20.5k
  img->planes[VPX_PLANE_ALPHA] = NULL;
51
20.5k
  img->stride[VPX_PLANE_Y] = yv12->y_stride;
52
20.5k
  img->stride[VPX_PLANE_U] = yv12->uv_stride;
53
20.5k
  img->stride[VPX_PLANE_V] = yv12->uv_stride;
54
20.5k
  img->stride[VPX_PLANE_ALPHA] = yv12->y_stride;
55
20.5k
#if CONFIG_VP9_HIGHBITDEPTH
56
20.5k
  if (yv12->flags & YV12_FLAG_HIGHBITDEPTH) {
57
    // vpx_image_t uses byte strides and a pointer to the first byte
58
    // of the image.
59
453
    img->fmt = (vpx_img_fmt_t)(img->fmt | VPX_IMG_FMT_HIGHBITDEPTH);
60
453
    img->bit_depth = yv12->bit_depth;
61
453
    img->planes[VPX_PLANE_Y] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->y_buffer);
62
453
    img->planes[VPX_PLANE_U] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->u_buffer);
63
453
    img->planes[VPX_PLANE_V] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->v_buffer);
64
453
    img->planes[VPX_PLANE_ALPHA] = NULL;
65
453
    img->stride[VPX_PLANE_Y] = 2 * yv12->y_stride;
66
453
    img->stride[VPX_PLANE_U] = 2 * yv12->uv_stride;
67
453
    img->stride[VPX_PLANE_V] = 2 * yv12->uv_stride;
68
453
    img->stride[VPX_PLANE_ALPHA] = 2 * yv12->y_stride;
69
453
  }
70
20.5k
#endif  // CONFIG_VP9_HIGHBITDEPTH
71
20.5k
  img->bps = bps;
72
20.5k
  img->user_priv = user_priv;
73
20.5k
  img->img_data = yv12->buffer_alloc;
74
20.5k
  img->img_data_owner = 0;
75
20.5k
  img->self_allocd = 0;
76
20.5k
}
77
78
vpx_codec_err_t image2yuvconfig(const vpx_image_t *img,
79
0
                                YV12_BUFFER_CONFIG *yv12) {
80
0
  yv12->y_buffer = img->planes[VPX_PLANE_Y];
81
0
  yv12->u_buffer = img->planes[VPX_PLANE_U];
82
0
  yv12->v_buffer = img->planes[VPX_PLANE_V];
83
84
0
  yv12->y_crop_width = img->d_w;
85
0
  yv12->y_crop_height = img->d_h;
86
0
  yv12->render_width = img->r_w;
87
0
  yv12->render_height = img->r_h;
88
0
  yv12->y_width = img->d_w;
89
0
  yv12->y_height = img->d_h;
90
91
0
  yv12->uv_width = img->x_chroma_shift == 1 || img->fmt == VPX_IMG_FMT_NV12
92
0
                       ? (1 + yv12->y_width) / 2
93
0
                       : yv12->y_width;
94
0
  yv12->uv_height =
95
0
      img->y_chroma_shift == 1 ? (1 + yv12->y_height) / 2 : yv12->y_height;
96
0
  yv12->uv_crop_width = yv12->uv_width;
97
0
  yv12->uv_crop_height = yv12->uv_height;
98
99
0
  yv12->y_stride = img->stride[VPX_PLANE_Y];
100
0
  yv12->uv_stride = img->stride[VPX_PLANE_U];
101
0
  yv12->color_space = img->cs;
102
0
  yv12->color_range = img->range;
103
104
0
#if CONFIG_VP9_HIGHBITDEPTH
105
0
  if (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
106
    // In vpx_image_t
107
    //     planes point to uint8 address of start of data
108
    //     stride counts uint8s to reach next row
109
    // In YV12_BUFFER_CONFIG
110
    //     y_buffer, u_buffer, v_buffer point to uint16 address of data
111
    //     stride and border counts in uint16s
112
    // This means that all the address calculations in the main body of code
113
    // should work correctly.
114
    // However, before we do any pixel operations we need to cast the address
115
    // to a uint16 ponter and double its value.
116
0
    yv12->y_buffer = CONVERT_TO_BYTEPTR(yv12->y_buffer);
117
0
    yv12->u_buffer = CONVERT_TO_BYTEPTR(yv12->u_buffer);
118
0
    yv12->v_buffer = CONVERT_TO_BYTEPTR(yv12->v_buffer);
119
0
    yv12->y_stride >>= 1;
120
0
    yv12->uv_stride >>= 1;
121
0
    yv12->flags = YV12_FLAG_HIGHBITDEPTH;
122
0
  } else {
123
0
    yv12->flags = 0;
124
0
  }
125
0
  yv12->border = (yv12->y_stride - img->w) / 2;
126
#else
127
  yv12->border = (img->stride[VPX_PLANE_Y] - img->w) / 2;
128
#endif  // CONFIG_VP9_HIGHBITDEPTH
129
0
  yv12->subsampling_x = img->x_chroma_shift;
130
0
  yv12->subsampling_y = img->y_chroma_shift;
131
  // When reading the data, UV are in one plane for NV12 format, thus
132
  // x_chroma_shift is 0. After converting, UV are in separate planes, and
133
  // subsampling_x should be set to 1.
134
0
  if (img->fmt == VPX_IMG_FMT_NV12) yv12->subsampling_x = 1;
135
0
  return VPX_CODEC_OK;
136
0
}