Coverage Report

Created: 2022-08-24 06:15

/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 AOM_INLINE void yuvconfig2image(aom_image_t *img,
22
                                       const YV12_BUFFER_CONFIG *yv12,
23
0
                                       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
0
  int bps;
30
0
  if (!yv12->subsampling_y) {
31
0
    if (!yv12->subsampling_x) {
32
0
      img->fmt = AOM_IMG_FMT_I444;
33
0
      bps = 24;
34
0
    } else {
35
0
      img->fmt = AOM_IMG_FMT_I422;
36
0
      bps = 16;
37
0
    }
38
0
  } else {
39
0
    img->fmt = AOM_IMG_FMT_I420;
40
0
    bps = 12;
41
0
  }
42
0
  img->cp = yv12->color_primaries;
43
0
  img->tc = yv12->transfer_characteristics;
44
0
  img->mc = yv12->matrix_coefficients;
45
0
  img->monochrome = yv12->monochrome;
46
0
  img->csp = yv12->chroma_sample_position;
47
0
  img->range = yv12->color_range;
48
0
  img->bit_depth = 8;
49
0
  img->w = yv12->y_width;
50
0
  img->h = yv12->y_height;
51
0
  img->d_w = yv12->y_crop_width;
52
0
  img->d_h = yv12->y_crop_height;
53
0
  img->r_w = yv12->render_width;
54
0
  img->r_h = yv12->render_height;
55
0
  img->x_chroma_shift = yv12->subsampling_x;
56
0
  img->y_chroma_shift = yv12->subsampling_y;
57
0
  img->planes[AOM_PLANE_Y] = yv12->y_buffer;
58
0
  img->planes[AOM_PLANE_U] = yv12->u_buffer;
59
0
  img->planes[AOM_PLANE_V] = yv12->v_buffer;
60
0
  img->stride[AOM_PLANE_Y] = yv12->y_stride;
61
0
  img->stride[AOM_PLANE_U] = yv12->uv_stride;
62
0
  img->stride[AOM_PLANE_V] = yv12->uv_stride;
63
0
  if (yv12->flags & YV12_FLAG_HIGHBITDEPTH) {
64
0
    bps *= 2;
65
    // aom_image_t uses byte strides and a pointer to the first byte
66
    // of the image.
67
0
    img->fmt = (aom_img_fmt_t)(img->fmt | AOM_IMG_FMT_HIGHBITDEPTH);
68
0
    img->bit_depth = yv12->bit_depth;
69
0
    img->planes[AOM_PLANE_Y] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->y_buffer);
70
0
    img->planes[AOM_PLANE_U] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->u_buffer);
71
0
    img->planes[AOM_PLANE_V] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->v_buffer);
72
0
    img->stride[AOM_PLANE_Y] = 2 * yv12->y_stride;
73
0
    img->stride[AOM_PLANE_U] = 2 * yv12->uv_stride;
74
0
    img->stride[AOM_PLANE_V] = 2 * yv12->uv_stride;
75
0
  }
76
0
  img->bps = bps;
77
0
  img->user_priv = user_priv;
78
0
  img->img_data = yv12->buffer_alloc;
79
0
  img->img_data_owner = 0;
80
0
  img->self_allocd = 0;
81
0
  img->sz = yv12->frame_size;
82
0
  assert(!yv12->metadata);
83
0
  img->metadata = NULL;
84
0
}
Unexecuted instantiation: av1_dx_iface.c:yuvconfig2image
Unexecuted instantiation: av1_cx_iface.c:yuvconfig2image
Unexecuted instantiation: thirdpass.c:yuvconfig2image
85
86
static AOM_INLINE aom_codec_err_t image2yuvconfig(const aom_image_t *img,
87
1.26k
                                                  YV12_BUFFER_CONFIG *yv12) {
88
1.26k
  yv12->y_buffer = img->planes[AOM_PLANE_Y];
89
1.26k
  yv12->u_buffer = img->planes[AOM_PLANE_U];
90
1.26k
  yv12->v_buffer = img->planes[AOM_PLANE_V];
91
92
1.26k
  yv12->y_crop_width = img->d_w;
93
1.26k
  yv12->y_crop_height = img->d_h;
94
1.26k
  yv12->render_width = img->r_w;
95
1.26k
  yv12->render_height = img->r_h;
96
1.26k
  yv12->y_width = img->w;
97
1.26k
  yv12->y_height = img->h;
98
99
1.26k
  yv12->uv_width = (yv12->y_width + img->x_chroma_shift) >> img->x_chroma_shift;
100
1.26k
  yv12->uv_height =
101
1.26k
      (yv12->y_height + img->y_chroma_shift) >> img->y_chroma_shift;
102
1.26k
  yv12->uv_crop_width =
103
1.26k
      (yv12->y_crop_width + img->x_chroma_shift) >> img->x_chroma_shift;
104
1.26k
  yv12->uv_crop_height =
105
1.26k
      (yv12->y_crop_height + img->y_chroma_shift) >> img->y_chroma_shift;
106
107
1.26k
  yv12->y_stride = img->stride[AOM_PLANE_Y];
108
1.26k
  yv12->uv_stride = img->stride[AOM_PLANE_U];
109
1.26k
  yv12->color_primaries = img->cp;
110
1.26k
  yv12->transfer_characteristics = img->tc;
111
1.26k
  yv12->matrix_coefficients = img->mc;
112
1.26k
  yv12->monochrome = img->monochrome;
113
1.26k
  yv12->chroma_sample_position = img->csp;
114
1.26k
  yv12->color_range = img->range;
115
116
1.26k
  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
1.26k
  } else {
134
1.26k
    yv12->flags = 0;
135
1.26k
  }
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
1.26k
  int border = (yv12->y_stride - (int)((img->w + 31) & ~31)) / 2;
141
1.26k
  yv12->border = (border < 0) ? 0 : border;
142
1.26k
  yv12->subsampling_x = img->x_chroma_shift;
143
1.26k
  yv12->subsampling_y = img->y_chroma_shift;
144
1.26k
  yv12->metadata = img->metadata;
145
1.26k
  return AOM_CODEC_OK;
146
1.26k
}
Unexecuted instantiation: av1_dx_iface.c:image2yuvconfig
av1_cx_iface.c:image2yuvconfig
Line
Count
Source
87
1.26k
                                                  YV12_BUFFER_CONFIG *yv12) {
88
1.26k
  yv12->y_buffer = img->planes[AOM_PLANE_Y];
89
1.26k
  yv12->u_buffer = img->planes[AOM_PLANE_U];
90
1.26k
  yv12->v_buffer = img->planes[AOM_PLANE_V];
91
92
1.26k
  yv12->y_crop_width = img->d_w;
93
1.26k
  yv12->y_crop_height = img->d_h;
94
1.26k
  yv12->render_width = img->r_w;
95
1.26k
  yv12->render_height = img->r_h;
96
1.26k
  yv12->y_width = img->w;
97
1.26k
  yv12->y_height = img->h;
98
99
1.26k
  yv12->uv_width = (yv12->y_width + img->x_chroma_shift) >> img->x_chroma_shift;
100
1.26k
  yv12->uv_height =
101
1.26k
      (yv12->y_height + img->y_chroma_shift) >> img->y_chroma_shift;
102
1.26k
  yv12->uv_crop_width =
103
1.26k
      (yv12->y_crop_width + img->x_chroma_shift) >> img->x_chroma_shift;
104
1.26k
  yv12->uv_crop_height =
105
1.26k
      (yv12->y_crop_height + img->y_chroma_shift) >> img->y_chroma_shift;
106
107
1.26k
  yv12->y_stride = img->stride[AOM_PLANE_Y];
108
1.26k
  yv12->uv_stride = img->stride[AOM_PLANE_U];
109
1.26k
  yv12->color_primaries = img->cp;
110
1.26k
  yv12->transfer_characteristics = img->tc;
111
1.26k
  yv12->matrix_coefficients = img->mc;
112
1.26k
  yv12->monochrome = img->monochrome;
113
1.26k
  yv12->chroma_sample_position = img->csp;
114
1.26k
  yv12->color_range = img->range;
115
116
1.26k
  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
1.26k
  } else {
134
1.26k
    yv12->flags = 0;
135
1.26k
  }
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
1.26k
  int border = (yv12->y_stride - (int)((img->w + 31) & ~31)) / 2;
141
1.26k
  yv12->border = (border < 0) ? 0 : border;
142
1.26k
  yv12->subsampling_x = img->x_chroma_shift;
143
1.26k
  yv12->subsampling_y = img->y_chroma_shift;
144
1.26k
  yv12->metadata = img->metadata;
145
1.26k
  return AOM_CODEC_OK;
146
1.26k
}
Unexecuted instantiation: thirdpass.c:image2yuvconfig
147
148
#endif  // AOM_AV1_AV1_IFACE_COMMON_H_