Coverage Report

Created: 2026-09-14 08:00

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
#include <assert.h>
11
12
#include "vp9/vp9_iface_common.h"
13
void yuvconfig2image(vpx_image_t *img, const YV12_BUFFER_CONFIG *yv12,
14
12.9k
                     void *user_priv) {
15
  /** vpx_img_wrap() doesn't allow specifying independent strides for
16
   * the Y, U, and V planes, nor other alignment adjustments that
17
   * might be representable by a YV12_BUFFER_CONFIG, so we just
18
   * initialize all the fields.*/
19
12.9k
  int bps;
20
12.9k
  if (!yv12->subsampling_y) {
21
5.22k
    if (!yv12->subsampling_x) {
22
4.24k
      img->fmt = VPX_IMG_FMT_I444;
23
4.24k
      bps = 24;
24
4.24k
    } else {
25
975
      img->fmt = VPX_IMG_FMT_I422;
26
975
      bps = 16;
27
975
    }
28
7.71k
  } else {
29
7.71k
    if (!yv12->subsampling_x) {
30
6.47k
      img->fmt = VPX_IMG_FMT_I440;
31
6.47k
      bps = 16;
32
6.47k
    } else {
33
1.23k
      img->fmt = VPX_IMG_FMT_I420;
34
1.23k
      bps = 12;
35
1.23k
    }
36
7.71k
  }
37
12.9k
  img->cs = yv12->color_space;
38
12.9k
  img->range = yv12->color_range;
39
12.9k
  img->bit_depth = 8;
40
12.9k
  img->w = yv12->y_width;
41
12.9k
  img->h = yv12->y_height;
42
12.9k
  img->d_w = yv12->y_crop_width;
43
12.9k
  img->d_h = yv12->y_crop_height;
44
12.9k
  img->r_w = yv12->render_width;
45
12.9k
  img->r_h = yv12->render_height;
46
12.9k
  img->x_chroma_shift = yv12->subsampling_x;
47
12.9k
  img->y_chroma_shift = yv12->subsampling_y;
48
12.9k
  img->planes[VPX_PLANE_Y] = yv12->y_buffer;
49
12.9k
  img->planes[VPX_PLANE_U] = yv12->u_buffer;
50
12.9k
  img->planes[VPX_PLANE_V] = yv12->v_buffer;
51
12.9k
  img->planes[VPX_PLANE_ALPHA] = NULL;
52
12.9k
  img->stride[VPX_PLANE_Y] = yv12->y_stride;
53
12.9k
  img->stride[VPX_PLANE_U] = yv12->uv_stride;
54
12.9k
  img->stride[VPX_PLANE_V] = yv12->uv_stride;
55
12.9k
  img->stride[VPX_PLANE_ALPHA] = yv12->y_stride;
56
12.9k
#if CONFIG_VP9_HIGHBITDEPTH
57
12.9k
  if (yv12->flags & YV12_FLAG_HIGHBITDEPTH) {
58
    // vpx_image_t uses byte strides and a pointer to the first byte
59
    // of the image.
60
11.7k
    img->fmt = (vpx_img_fmt_t)(img->fmt | VPX_IMG_FMT_HIGHBITDEPTH);
61
11.7k
    img->bit_depth = yv12->bit_depth;
62
11.7k
    img->planes[VPX_PLANE_Y] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->y_buffer);
63
11.7k
    img->planes[VPX_PLANE_U] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->u_buffer);
64
11.7k
    img->planes[VPX_PLANE_V] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->v_buffer);
65
11.7k
    img->planes[VPX_PLANE_ALPHA] = NULL;
66
11.7k
    img->stride[VPX_PLANE_Y] = 2 * yv12->y_stride;
67
11.7k
    img->stride[VPX_PLANE_U] = 2 * yv12->uv_stride;
68
11.7k
    img->stride[VPX_PLANE_V] = 2 * yv12->uv_stride;
69
11.7k
    img->stride[VPX_PLANE_ALPHA] = 2 * yv12->y_stride;
70
11.7k
  }
71
12.9k
#endif  // CONFIG_VP9_HIGHBITDEPTH
72
12.9k
  img->bps = bps;
73
12.9k
  img->user_priv = user_priv;
74
12.9k
  img->img_data = yv12->buffer_alloc;
75
12.9k
  img->img_data_owner = 0;
76
12.9k
  img->self_allocd = 0;
77
12.9k
}
78
79
vpx_codec_err_t image2yuvconfig(const vpx_image_t *img,
80
60.9k
                                YV12_BUFFER_CONFIG *yv12) {
81
60.9k
  yv12->y_buffer = img->planes[VPX_PLANE_Y];
82
60.9k
  yv12->u_buffer = img->planes[VPX_PLANE_U];
83
60.9k
  yv12->v_buffer = img->planes[VPX_PLANE_V];
84
85
60.9k
  yv12->y_crop_width = img->d_w;
86
60.9k
  yv12->y_crop_height = img->d_h;
87
60.9k
  yv12->render_width = img->r_w;
88
60.9k
  yv12->render_height = img->r_h;
89
60.9k
  yv12->y_width = img->w;
90
60.9k
  yv12->y_height = img->h;
91
92
60.9k
  yv12->uv_width = (yv12->y_width + img->x_chroma_shift) >> img->x_chroma_shift;
93
60.9k
  yv12->uv_height =
94
60.9k
      (yv12->y_height + img->y_chroma_shift) >> img->y_chroma_shift;
95
60.9k
  yv12->uv_crop_width =
96
60.9k
      (yv12->y_crop_width + img->x_chroma_shift) >> img->x_chroma_shift;
97
60.9k
  yv12->uv_crop_height =
98
60.9k
      (yv12->y_crop_height + img->y_chroma_shift) >> img->y_chroma_shift;
99
100
60.9k
  yv12->y_stride = img->stride[VPX_PLANE_Y];
101
60.9k
  assert(img->stride[VPX_PLANE_U] == img->stride[VPX_PLANE_V]);
102
60.9k
  yv12->uv_stride = img->stride[VPX_PLANE_U];
103
60.9k
  yv12->color_space = img->cs;
104
60.9k
  yv12->color_range = img->range;
105
106
60.9k
#if CONFIG_VP9_HIGHBITDEPTH
107
60.9k
  if (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
108
    // In vpx_image_t
109
    //     planes point to uint8 address of start of data
110
    //     stride counts uint8s to reach next row
111
    // In YV12_BUFFER_CONFIG
112
    //     y_buffer, u_buffer, v_buffer point to uint16 address of data
113
    //     stride and border counts in uint16s
114
    // This means that all the address calculations in the main body of code
115
    // should work correctly.
116
    // However, before we do any pixel operations we need to cast the address
117
    // to a uint16 ponter and double its value.
118
2.69k
    yv12->y_buffer = CONVERT_TO_BYTEPTR(yv12->y_buffer);
119
2.69k
    yv12->u_buffer = CONVERT_TO_BYTEPTR(yv12->u_buffer);
120
2.69k
    yv12->v_buffer = CONVERT_TO_BYTEPTR(yv12->v_buffer);
121
2.69k
    yv12->y_stride >>= 1;
122
2.69k
    yv12->uv_stride >>= 1;
123
2.69k
    yv12->flags = YV12_FLAG_HIGHBITDEPTH;
124
58.2k
  } else {
125
58.2k
    yv12->flags = 0;
126
58.2k
  }
127
60.9k
  yv12->border = (yv12->y_stride - img->w) / 2;
128
#else
129
  yv12->border = (img->stride[VPX_PLANE_Y] - img->w) / 2;
130
#endif  // CONFIG_VP9_HIGHBITDEPTH
131
60.9k
  yv12->subsampling_x = img->x_chroma_shift;
132
60.9k
  yv12->subsampling_y = img->y_chroma_shift;
133
60.9k
  return VPX_CODEC_OK;
134
60.9k
}