FFmpeg  4.3.6
rpi_sand_fns.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2018 Raspberry Pi (Trading) Ltd.
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the copyright holder nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 Authors: John Cox
28 */
29 
30 #ifndef AVUTIL_RPI_SAND_FNS
31 #define AVUTIL_RPI_SAND_FNS
32 
33 #include "libavutil/frame.h"
34 
35 // For all these fns _x & _w are measured as coord * PW
36 // For the C fns coords are in chroma pels (so luma / 2)
37 // Strides are in bytes
38 
39 void av_rpi_sand_to_planar_y8(uint8_t * dst, const unsigned int dst_stride,
40  const uint8_t * src,
41  unsigned int stride1, unsigned int stride2,
42  unsigned int _x, unsigned int y,
43  unsigned int _w, unsigned int h);
44 void av_rpi_sand_to_planar_y16(uint8_t * dst, const unsigned int dst_stride,
45  const uint8_t * src,
46  unsigned int stride1, unsigned int stride2,
47  unsigned int _x, unsigned int y,
48  unsigned int _w, unsigned int h);
49 
50 void av_rpi_sand_to_planar_c8(uint8_t * dst_u, const unsigned int dst_stride_u,
51  uint8_t * dst_v, const unsigned int dst_stride_v,
52  const uint8_t * src,
53  unsigned int stride1, unsigned int stride2,
54  unsigned int _x, unsigned int y,
55  unsigned int _w, unsigned int h);
56 void av_rpi_sand_to_planar_c16(uint8_t * dst_u, const unsigned int dst_stride_u,
57  uint8_t * dst_v, const unsigned int dst_stride_v,
58  const uint8_t * src,
59  unsigned int stride1, unsigned int stride2,
60  unsigned int _x, unsigned int y,
61  unsigned int _w, unsigned int h);
62 
63 void av_rpi_planar_to_sand_c8(uint8_t * dst_c,
64  unsigned int stride1, unsigned int stride2,
65  const uint8_t * src_u, const unsigned int src_stride_u,
66  const uint8_t * src_v, const unsigned int src_stride_v,
67  unsigned int _x, unsigned int y,
68  unsigned int _w, unsigned int h);
69 void av_rpi_planar_to_sand_c16(uint8_t * dst_c,
70  unsigned int stride1, unsigned int stride2,
71  const uint8_t * src_u, const unsigned int src_stride_u,
72  const uint8_t * src_v, const unsigned int src_stride_v,
73  unsigned int _x, unsigned int y,
74  unsigned int _w, unsigned int h);
75 
76 void av_rpi_sand30_to_planar_y16(uint8_t * dst, const unsigned int dst_stride,
77  const uint8_t * src,
78  unsigned int stride1, unsigned int stride2,
79  unsigned int _x, unsigned int y,
80  unsigned int _w, unsigned int h);
81 void av_rpi_sand30_to_planar_c16(uint8_t * dst_u, const unsigned int dst_stride_u,
82  uint8_t * dst_v, const unsigned int dst_stride_v,
83  const uint8_t * src,
84  unsigned int stride1, unsigned int stride2,
85  unsigned int _x, unsigned int y,
86  unsigned int _w, unsigned int h);
87 
88 void av_rpi_sand30_to_planar_y8(uint8_t * dst, const unsigned int dst_stride,
89  const uint8_t * src,
90  unsigned int stride1, unsigned int stride2,
91  unsigned int _x, unsigned int y,
92  unsigned int _w, unsigned int h);
93 
94 // w/h in pixels
95 void av_rpi_sand16_to_sand8(uint8_t * dst, const unsigned int dst_stride1, const unsigned int dst_stride2,
96  const uint8_t * src, const unsigned int src_stride1, const unsigned int src_stride2,
97  unsigned int w, unsigned int h, const unsigned int shr);
98 
99 
100 // dst must contain required pixel format & allocated data buffers
101 // Cropping on the src buffer will be honoured and dst crop will be set to zero
102 int av_rpi_sand_to_planar_frame(AVFrame * const dst, const AVFrame * const src);
103 
104 
105 static inline unsigned int av_rpi_sand_frame_stride1(const AVFrame * const frame)
106 {
107 #ifdef RPI_ZC_SAND128_ONLY
108  // If we are sure we only only support 128 byte sand formats replace the
109  // var with a constant which should allow for better optimisation
110  return 128;
111 #else
112  return frame->linesize[0];
113 #endif
114 }
115 
116 static inline unsigned int av_rpi_sand_frame_stride2(const AVFrame * const frame)
117 {
118  return frame->linesize[3];
119 }
120 
121 
122 static inline int av_rpi_is_sand_format(const int format)
123 {
124  return (format >= AV_PIX_FMT_SAND128 && format <= AV_PIX_FMT_RPI4_10);
125 }
126 
127 static inline int av_rpi_is_sand_frame(const AVFrame * const frame)
128 {
130 }
131 
132 static inline int av_rpi_is_sand8_frame(const AVFrame * const frame)
133 {
135 }
136 
137 static inline int av_rpi_is_sand16_frame(const AVFrame * const frame)
138 {
140 }
141 
142 static inline int av_rpi_is_sand30_frame(const AVFrame * const frame)
143 {
144  return (frame->format == AV_PIX_FMT_RPI4_10);
145 }
146 
147 static inline int av_rpi_sand_frame_xshl(const AVFrame * const frame)
148 {
149  return av_rpi_is_sand8_frame(frame) ? 0 : 1;
150 }
151 
152 // If x is measured in bytes (not pixels) then this works for sand64_16 as
153 // well as sand128 - but in the general case we work that out
154 
155 static inline unsigned int av_rpi_sand_frame_off_y(const AVFrame * const frame, const unsigned int x_y, const unsigned int y)
156 {
157  const unsigned int stride1 = av_rpi_sand_frame_stride1(frame);
158  const unsigned int stride2 = av_rpi_sand_frame_stride2(frame);
159  const unsigned int x = x_y << av_rpi_sand_frame_xshl(frame);
160  const unsigned int x1 = x & (stride1 - 1);
161  const unsigned int x2 = x ^ x1;
162 
163  return x1 + stride1 * y + stride2 * x2;
164 }
165 
166 static inline unsigned int av_rpi_sand_frame_off_c(const AVFrame * const frame, const unsigned int x_c, const unsigned int y_c)
167 {
168  const unsigned int stride1 = av_rpi_sand_frame_stride1(frame);
169  const unsigned int stride2 = av_rpi_sand_frame_stride2(frame);
170  const unsigned int x = x_c << (av_rpi_sand_frame_xshl(frame) + 1);
171  const unsigned int x1 = x & (stride1 - 1);
172  const unsigned int x2 = x ^ x1;
173 
174  return x1 + stride1 * y_c + stride2 * x2;
175 }
176 
177 static inline uint8_t * av_rpi_sand_frame_pos_y(const AVFrame * const frame, const unsigned int x, const unsigned int y)
178 {
179  return frame->data[0] + av_rpi_sand_frame_off_y(frame, x, y);
180 }
181 
182 static inline uint8_t * av_rpi_sand_frame_pos_c(const AVFrame * const frame, const unsigned int x, const unsigned int y)
183 {
184  return frame->data[1] + av_rpi_sand_frame_off_c(frame, x, y);
185 }
186 
187 #endif
188 
static AVFrame * frame
reference-counted frame API
@ AV_PIX_FMT_SAND128
4:2:0 8-bit 128x*Y stripe, 64x*UV stripe, then next x stripe, mysterious padding
Definition: pixfmt.h:363
@ AV_PIX_FMT_RPI4_8
Definition: pixfmt.h:366
@ AV_PIX_FMT_RPI4_10
Definition: pixfmt.h:367
@ AV_PIX_FMT_SAND64_10
4:2:0 10-bit 64x*Y stripe, 32x*UV stripe, then next x stripe, mysterious padding
Definition: pixfmt.h:364
@ AV_PIX_FMT_SAND64_16
4:2:0 16-bit 64x*Y stripe, 32x*UV stripe, then next x stripe, mysterious padding
Definition: pixfmt.h:365
static int av_rpi_is_sand16_frame(const AVFrame *const frame)
Definition: rpi_sand_fns.h:137
static unsigned int av_rpi_sand_frame_stride2(const AVFrame *const frame)
Definition: rpi_sand_fns.h:116
void av_rpi_sand_to_planar_y8(uint8_t *dst, const unsigned int dst_stride, const uint8_t *src, unsigned int stride1, unsigned int stride2, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
static unsigned int av_rpi_sand_frame_off_y(const AVFrame *const frame, const unsigned int x_y, const unsigned int y)
Definition: rpi_sand_fns.h:155
static uint8_t * av_rpi_sand_frame_pos_c(const AVFrame *const frame, const unsigned int x, const unsigned int y)
Definition: rpi_sand_fns.h:182
void av_rpi_sand_to_planar_y16(uint8_t *dst, const unsigned int dst_stride, const uint8_t *src, unsigned int stride1, unsigned int stride2, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
static int av_rpi_is_sand8_frame(const AVFrame *const frame)
Definition: rpi_sand_fns.h:132
void av_rpi_planar_to_sand_c8(uint8_t *dst_c, unsigned int stride1, unsigned int stride2, const uint8_t *src_u, const unsigned int src_stride_u, const uint8_t *src_v, const unsigned int src_stride_v, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
void av_rpi_sand_to_planar_c8(uint8_t *dst_u, const unsigned int dst_stride_u, uint8_t *dst_v, const unsigned int dst_stride_v, const uint8_t *src, unsigned int stride1, unsigned int stride2, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
void av_rpi_sand30_to_planar_y8(uint8_t *dst, const unsigned int dst_stride, const uint8_t *src, unsigned int stride1, unsigned int stride2, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
int av_rpi_sand_to_planar_frame(AVFrame *const dst, const AVFrame *const src)
static uint8_t * av_rpi_sand_frame_pos_y(const AVFrame *const frame, const unsigned int x, const unsigned int y)
Definition: rpi_sand_fns.h:177
void av_rpi_sand_to_planar_c16(uint8_t *dst_u, const unsigned int dst_stride_u, uint8_t *dst_v, const unsigned int dst_stride_v, const uint8_t *src, unsigned int stride1, unsigned int stride2, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
static unsigned int av_rpi_sand_frame_off_c(const AVFrame *const frame, const unsigned int x_c, const unsigned int y_c)
Definition: rpi_sand_fns.h:166
static int av_rpi_is_sand30_frame(const AVFrame *const frame)
Definition: rpi_sand_fns.h:142
static int av_rpi_is_sand_frame(const AVFrame *const frame)
Definition: rpi_sand_fns.h:127
static int av_rpi_is_sand_format(const int format)
Definition: rpi_sand_fns.h:122
void av_rpi_sand30_to_planar_c16(uint8_t *dst_u, const unsigned int dst_stride_u, uint8_t *dst_v, const unsigned int dst_stride_v, const uint8_t *src, unsigned int stride1, unsigned int stride2, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
void av_rpi_planar_to_sand_c16(uint8_t *dst_c, unsigned int stride1, unsigned int stride2, const uint8_t *src_u, const unsigned int src_stride_u, const uint8_t *src_v, const unsigned int src_stride_v, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
void av_rpi_sand16_to_sand8(uint8_t *dst, const unsigned int dst_stride1, const unsigned int dst_stride2, const uint8_t *src, const unsigned int src_stride1, const unsigned int src_stride2, unsigned int w, unsigned int h, const unsigned int shr)
static int av_rpi_sand_frame_xshl(const AVFrame *const frame)
Definition: rpi_sand_fns.h:147
void av_rpi_sand30_to_planar_y16(uint8_t *dst, const unsigned int dst_stride, const uint8_t *src, unsigned int stride1, unsigned int stride2, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
static unsigned int av_rpi_sand_frame_stride1(const AVFrame *const frame)
Definition: rpi_sand_fns.h:105
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:314
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:331
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:373