Coverage Report

Created: 2025-06-22 08:04

/src/aom/av1/av1_iface_common.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3
 *
4
 * This source code is subject to the terms of the BSD 2 Clause License and
5
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6
 * was not distributed with this source code in the LICENSE file, you can
7
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8
 * Media Patent License 1.0 was not distributed with this source code in the
9
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10
 */
11
#ifndef AOM_AV1_AV1_IFACE_COMMON_H_
12
#define AOM_AV1_AV1_IFACE_COMMON_H_
13
14
#include <assert.h>
15
16
#include "aom_ports/mem.h"
17
#include "aom_scale/yv12config.h"
18
19
extern aom_codec_iface_t aom_codec_av1_inspect_algo;
20
21
static inline void yuvconfig2image(aom_image_t *img,
22
                                   const YV12_BUFFER_CONFIG *yv12,
23
3.39k
                                   void *user_priv) {
24
  /* aom_img_wrap() doesn't allow specifying independent strides for
25
   * the Y, U, and V planes, nor other alignment adjustments that
26
   * might be representable by a YV12_BUFFER_CONFIG, so we just
27
   * initialize all the fields.
28
   */
29
3.39k
  int bps;
30
3.39k
  if (!yv12->subsampling_y) {
31
2.24k
    if (!yv12->subsampling_x) {
32
1.99k
      img->fmt = AOM_IMG_FMT_I444;
33
1.99k
      bps = 24;
34
1.99k
    } else {
35
247
      img->fmt = AOM_IMG_FMT_I422;
36
247
      bps = 16;
37
247
    }
38
2.24k
  } else {
39
1.15k
    img->fmt = AOM_IMG_FMT_I420;
40
1.15k
    bps = 12;
41
1.15k
  }
42
3.39k
  img->cp = yv12->color_primaries;
43
3.39k
  img->tc = yv12->transfer_characteristics;
44
3.39k
  img->mc = yv12->matrix_coefficients;
45
3.39k
  img->monochrome = yv12->monochrome;
46
3.39k
  img->csp = yv12->chroma_sample_position;
47
3.39k
  img->range = yv12->color_range;
48
3.39k
  img->bit_depth = 8;
49
3.39k
  img->w = yv12->y_width;
50
3.39k
  img->h = yv12->y_height;
51
3.39k
  img->d_w = yv12->y_crop_width;
52
3.39k
  img->d_h = yv12->y_crop_height;
53
3.39k
  img->r_w = yv12->render_width;
54
3.39k
  img->r_h = yv12->render_height;
55
3.39k
  img->x_chroma_shift = yv12->subsampling_x;
56
3.39k
  img->y_chroma_shift = yv12->subsampling_y;
57
3.39k
  img->planes[AOM_PLANE_Y] = yv12->y_buffer;
58
3.39k
  img->planes[AOM_PLANE_U] = yv12->u_buffer;
59
3.39k
  img->planes[AOM_PLANE_V] = yv12->v_buffer;
60
3.39k
  img->stride[AOM_PLANE_Y] = yv12->y_stride;
61
3.39k
  img->stride[AOM_PLANE_U] = yv12->uv_stride;
62
3.39k
  img->stride[AOM_PLANE_V] = yv12->uv_stride;
63
3.39k
  if (yv12->flags & YV12_FLAG_HIGHBITDEPTH) {
64
1.33k
    bps *= 2;
65
    // aom_image_t uses byte strides and a pointer to the first byte
66
    // of the image.
67
1.33k
    img->fmt = (aom_img_fmt_t)(img->fmt | AOM_IMG_FMT_HIGHBITDEPTH);
68
1.33k
    img->bit_depth = yv12->bit_depth;
69
1.33k
    img->planes[AOM_PLANE_Y] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->y_buffer);
70
1.33k
    img->planes[AOM_PLANE_U] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->u_buffer);
71
1.33k
    img->planes[AOM_PLANE_V] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->v_buffer);
72
1.33k
    img->stride[AOM_PLANE_Y] = 2 * yv12->y_stride;
73
1.33k
    img->stride[AOM_PLANE_U] = 2 * yv12->uv_stride;
74
1.33k
    img->stride[AOM_PLANE_V] = 2 * yv12->uv_stride;
75
1.33k
  }
76
3.39k
  img->bps = bps;
77
3.39k
  img->user_priv = user_priv;
78
3.39k
  img->img_data = yv12->buffer_alloc;
79
3.39k
  img->img_data_owner = 0;
80
3.39k
  img->self_allocd = 0;
81
3.39k
  img->sz = yv12->frame_size;
82
3.39k
  assert(!yv12->metadata);
83
3.39k
  img->metadata = NULL;
84
3.39k
}
av1_dx_iface.c:yuvconfig2image
Line
Count
Source
23
3.39k
                                   void *user_priv) {
24
  /* aom_img_wrap() doesn't allow specifying independent strides for
25
   * the Y, U, and V planes, nor other alignment adjustments that
26
   * might be representable by a YV12_BUFFER_CONFIG, so we just
27
   * initialize all the fields.
28
   */
29
3.39k
  int bps;
30
3.39k
  if (!yv12->subsampling_y) {
31
2.24k
    if (!yv12->subsampling_x) {
32
1.99k
      img->fmt = AOM_IMG_FMT_I444;
33
1.99k
      bps = 24;
34
1.99k
    } else {
35
247
      img->fmt = AOM_IMG_FMT_I422;
36
247
      bps = 16;
37
247
    }
38
2.24k
  } else {
39
1.15k
    img->fmt = AOM_IMG_FMT_I420;
40
1.15k
    bps = 12;
41
1.15k
  }
42
3.39k
  img->cp = yv12->color_primaries;
43
3.39k
  img->tc = yv12->transfer_characteristics;
44
3.39k
  img->mc = yv12->matrix_coefficients;
45
3.39k
  img->monochrome = yv12->monochrome;
46
3.39k
  img->csp = yv12->chroma_sample_position;
47
3.39k
  img->range = yv12->color_range;
48
3.39k
  img->bit_depth = 8;
49
3.39k
  img->w = yv12->y_width;
50
3.39k
  img->h = yv12->y_height;
51
3.39k
  img->d_w = yv12->y_crop_width;
52
3.39k
  img->d_h = yv12->y_crop_height;
53
3.39k
  img->r_w = yv12->render_width;
54
3.39k
  img->r_h = yv12->render_height;
55
3.39k
  img->x_chroma_shift = yv12->subsampling_x;
56
3.39k
  img->y_chroma_shift = yv12->subsampling_y;
57
3.39k
  img->planes[AOM_PLANE_Y] = yv12->y_buffer;
58
3.39k
  img->planes[AOM_PLANE_U] = yv12->u_buffer;
59
3.39k
  img->planes[AOM_PLANE_V] = yv12->v_buffer;
60
3.39k
  img->stride[AOM_PLANE_Y] = yv12->y_stride;
61
3.39k
  img->stride[AOM_PLANE_U] = yv12->uv_stride;
62
3.39k
  img->stride[AOM_PLANE_V] = yv12->uv_stride;
63
3.39k
  if (yv12->flags & YV12_FLAG_HIGHBITDEPTH) {
64
1.33k
    bps *= 2;
65
    // aom_image_t uses byte strides and a pointer to the first byte
66
    // of the image.
67
1.33k
    img->fmt = (aom_img_fmt_t)(img->fmt | AOM_IMG_FMT_HIGHBITDEPTH);
68
1.33k
    img->bit_depth = yv12->bit_depth;
69
1.33k
    img->planes[AOM_PLANE_Y] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->y_buffer);
70
1.33k
    img->planes[AOM_PLANE_U] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->u_buffer);
71
1.33k
    img->planes[AOM_PLANE_V] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->v_buffer);
72
1.33k
    img->stride[AOM_PLANE_Y] = 2 * yv12->y_stride;
73
1.33k
    img->stride[AOM_PLANE_U] = 2 * yv12->uv_stride;
74
1.33k
    img->stride[AOM_PLANE_V] = 2 * yv12->uv_stride;
75
1.33k
  }
76
3.39k
  img->bps = bps;
77
3.39k
  img->user_priv = user_priv;
78
3.39k
  img->img_data = yv12->buffer_alloc;
79
3.39k
  img->img_data_owner = 0;
80
3.39k
  img->self_allocd = 0;
81
3.39k
  img->sz = yv12->frame_size;
82
3.39k
  assert(!yv12->metadata);
83
3.39k
  img->metadata = NULL;
84
3.39k
}
Unexecuted instantiation: av1_cx_iface.c:yuvconfig2image
85
86
static inline aom_codec_err_t image2yuvconfig(const aom_image_t *img,
87
0
                                              YV12_BUFFER_CONFIG *yv12) {
88
0
  yv12->y_buffer = img->planes[AOM_PLANE_Y];
89
0
  yv12->u_buffer = img->planes[AOM_PLANE_U];
90
0
  yv12->v_buffer = img->planes[AOM_PLANE_V];
91
92
0
  yv12->y_crop_width = img->d_w;
93
0
  yv12->y_crop_height = img->d_h;
94
0
  yv12->render_width = img->r_w;
95
0
  yv12->render_height = img->r_h;
96
0
  yv12->y_width = img->w;
97
0
  yv12->y_height = img->h;
98
99
0
  yv12->uv_width = (yv12->y_width + img->x_chroma_shift) >> img->x_chroma_shift;
100
0
  yv12->uv_height =
101
0
      (yv12->y_height + img->y_chroma_shift) >> img->y_chroma_shift;
102
0
  yv12->uv_crop_width =
103
0
      (yv12->y_crop_width + img->x_chroma_shift) >> img->x_chroma_shift;
104
0
  yv12->uv_crop_height =
105
0
      (yv12->y_crop_height + img->y_chroma_shift) >> img->y_chroma_shift;
106
107
0
  yv12->y_stride = img->stride[AOM_PLANE_Y];
108
0
  yv12->uv_stride = img->stride[AOM_PLANE_U];
109
0
  yv12->color_primaries = img->cp;
110
0
  yv12->transfer_characteristics = img->tc;
111
0
  yv12->matrix_coefficients = img->mc;
112
0
  yv12->monochrome = img->monochrome;
113
0
  yv12->chroma_sample_position = img->csp;
114
0
  yv12->color_range = img->range;
115
116
0
  if (img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) {
117
    // In aom_image_t
118
    //     planes point to uint8 address of start of data
119
    //     stride counts uint8s to reach next row
120
    // In YV12_BUFFER_CONFIG
121
    //     y_buffer, u_buffer, v_buffer point to uint16 address of data
122
    //     stride and border counts in uint16s
123
    // This means that all the address calculations in the main body of code
124
    // should work correctly.
125
    // However, before we do any pixel operations we need to cast the address
126
    // to a uint16 ponter and double its value.
127
0
    yv12->y_buffer = CONVERT_TO_BYTEPTR(yv12->y_buffer);
128
0
    yv12->u_buffer = CONVERT_TO_BYTEPTR(yv12->u_buffer);
129
0
    yv12->v_buffer = CONVERT_TO_BYTEPTR(yv12->v_buffer);
130
0
    yv12->y_stride >>= 1;
131
0
    yv12->uv_stride >>= 1;
132
0
    yv12->flags = YV12_FLAG_HIGHBITDEPTH;
133
0
  } else {
134
0
    yv12->flags = 0;
135
0
  }
136
137
  // Note(yunqing): if img is allocated the same as the frame buffer, y_stride
138
  // is 32-byte aligned. Also, handle the cases while allocating img without a
139
  // border or stride_align is less than 32.
140
0
  int border = (yv12->y_stride - (int)((img->w + 31) & ~31u)) / 2;
141
0
  yv12->border = (border < 0) ? 0 : border;
142
0
  yv12->subsampling_x = img->x_chroma_shift;
143
0
  yv12->subsampling_y = img->y_chroma_shift;
144
0
  yv12->metadata = img->metadata;
145
0
  return AOM_CODEC_OK;
146
0
}
Unexecuted instantiation: av1_dx_iface.c:image2yuvconfig
Unexecuted instantiation: av1_cx_iface.c:image2yuvconfig
147
148
#endif  // AOM_AV1_AV1_IFACE_COMMON_H_