1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */18 19 moduleffmpeg.libavutil.imgutils;
20 21 importffmpeg.libavutil.pixdesc;
22 importffmpeg.libavutil.pixfmt;
23 importffmpeg.libavutil.rational;
24 25 extern (C):
26 importffmpeg; @nogcnothrow:
27 28 /**
29 * @file
30 * misc image utilities
31 *
32 * @addtogroup lavu_picture
33 * @{
34 */35 36 /**
37 * Compute the max pixel step for each plane of an image with a
38 * format described by pixdesc.
39 *
40 * The pixel step is the distance in bytes between the first byte of
41 * the group of bytes which describe a pixel component and the first
42 * byte of the successive group in the same plane for the same
43 * component.
44 *
45 * @param max_pixsteps an array which is filled with the max pixel step
46 * for each plane. Since a plane may contain different pixel
47 * components, the computed max_pixsteps[plane] is relative to the
48 * component in the plane with the max pixel step.
49 * @param max_pixstep_comps an array which is filled with the component
50 * for each plane which has the max pixel step. May be NULL.
51 */52 voidav_image_fill_max_pixsteps (
53 refint[4] max_pixsteps,
54 refint[4] max_pixstep_comps,
55 const(AVPixFmtDescriptor)* pixdesc);
56 57 /**
58 * Compute the size of an image line with format pix_fmt and width
59 * width for the plane plane.
60 *
61 * @return the computed size in bytes
62 */63 intav_image_get_linesize (AVPixelFormatpix_fmt, intwidth, intplane);
64 65 /**
66 * Fill plane linesizes for an image with pixel format pix_fmt and
67 * width width.
68 *
69 * @param linesizes array to be filled with the linesize for each plane
70 * @return >= 0 in case of success, a negative error code otherwise
71 */72 intav_image_fill_linesizes (refint[4] linesizes, AVPixelFormatpix_fmt, intwidth);
73 74 /**
75 * Fill plane data pointers for an image with pixel format pix_fmt and
76 * height height.
77 *
78 * @param data pointers array to be filled with the pointer for each image plane
79 * @param ptr the pointer to a buffer which will contain the image
80 * @param linesizes the array containing the linesize for each
81 * plane, should be filled by av_image_fill_linesizes()
82 * @return the size in bytes required for the image buffer, a negative
83 * error code in case of failure
84 */85 intav_image_fill_pointers (
86 refubyte*[4] data,
87 AVPixelFormatpix_fmt,
88 intheight,
89 ubyte* ptr,
90 refconst(int)[4] linesizes);
91 92 /**
93 * Allocate an image with size w and h and pixel format pix_fmt, and
94 * fill pointers and linesizes accordingly.
95 * The allocated image buffer has to be freed by using
96 * av_freep(&pointers[0]).
97 *
98 * @param align the value to use for buffer size alignment
99 * @return the size in bytes required for the image buffer, a negative
100 * error code in case of failure
101 */102 intav_image_alloc (
103 refubyte*[4] pointers,
104 refint[4] linesizes,
105 intw,
106 inth,
107 AVPixelFormatpix_fmt,
108 intalign_);
109 110 /**
111 * Copy image plane from src to dst.
112 * That is, copy "height" number of lines of "bytewidth" bytes each.
113 * The first byte of each successive line is separated by *_linesize
114 * bytes.
115 *
116 * bytewidth must be contained by both absolute values of dst_linesize
117 * and src_linesize, otherwise the function behavior is undefined.
118 *
119 * @param dst_linesize linesize for the image plane in dst
120 * @param src_linesize linesize for the image plane in src
121 */122 voidav_image_copy_plane (
123 ubyte* dst,
124 intdst_linesize,
125 const(ubyte)* src,
126 intsrc_linesize,
127 intbytewidth,
128 intheight);
129 130 /**
131 * Copy image in src_data to dst_data.
132 *
133 * @param dst_linesizes linesizes for the image in dst_data
134 * @param src_linesizes linesizes for the image in src_data
135 */136 voidav_image_copy (
137 refubyte*[4] dst_data,
138 refint[4] dst_linesizes,
139 refconst(ubyte)*[4] src_data,
140 refconst(int)[4] src_linesizes,
141 AVPixelFormatpix_fmt,
142 intwidth,
143 intheight);
144 145 /**
146 * Copy image data located in uncacheable (e.g. GPU mapped) memory. Where
147 * available, this function will use special functionality for reading from such
148 * memory, which may result in greatly improved performance compared to plain
149 * av_image_copy().
150 *
151 * The data pointers and the linesizes must be aligned to the maximum required
152 * by the CPU architecture.
153 *
154 * @note The linesize parameters have the type ptrdiff_t here, while they are
155 * int for av_image_copy().
156 * @note On x86, the linesizes currently need to be aligned to the cacheline
157 * size (i.e. 64) to get improved performance.
158 */159 voidav_image_copy_uc_from (
160 refubyte*[4] dst_data,
161 refconst(ptrdiff_t)[4] dst_linesizes,
162 refconst(ubyte)*[4] src_data,
163 refconst(ptrdiff_t)[4] src_linesizes,
164 AVPixelFormatpix_fmt,
165 intwidth,
166 intheight);
167 168 /**
169 * Setup the data pointers and linesizes based on the specified image
170 * parameters and the provided array.
171 *
172 * The fields of the given image are filled in by using the src
173 * address which points to the image data buffer. Depending on the
174 * specified pixel format, one or multiple image data pointers and
175 * line sizes will be set. If a planar format is specified, several
176 * pointers will be set pointing to the different picture planes and
177 * the line sizes of the different planes will be stored in the
178 * lines_sizes array. Call with src == NULL to get the required
179 * size for the src buffer.
180 *
181 * To allocate the buffer and fill in the dst_data and dst_linesize in
182 * one call, use av_image_alloc().
183 *
184 * @param dst_data data pointers to be filled in
185 * @param dst_linesize linesizes for the image in dst_data to be filled in
186 * @param src buffer which will contain or contains the actual image data, can be NULL
187 * @param pix_fmt the pixel format of the image
188 * @param width the width of the image in pixels
189 * @param height the height of the image in pixels
190 * @param align the value used in src for linesize alignment
191 * @return the size in bytes required for src, a negative error code
192 * in case of failure
193 */194 intav_image_fill_arrays (
195 refubyte*[4] dst_data,
196 refint[4] dst_linesize,
197 const(ubyte)* src,
198 AVPixelFormatpix_fmt,
199 intwidth,
200 intheight,
201 intalign_);
202 203 /**
204 * Return the size in bytes of the amount of data required to store an
205 * image with the given parameters.
206 *
207 * @param pix_fmt the pixel format of the image
208 * @param width the width of the image in pixels
209 * @param height the height of the image in pixels
210 * @param align the assumed linesize alignment
211 * @return the buffer size in bytes, a negative error code in case of failure
212 */213 intav_image_get_buffer_size (AVPixelFormatpix_fmt, intwidth, intheight, intalign_);
214 215 /**
216 * Copy image data from an image into a buffer.
217 *
218 * av_image_get_buffer_size() can be used to compute the required size
219 * for the buffer to fill.
220 *
221 * @param dst a buffer into which picture data will be copied
222 * @param dst_size the size in bytes of dst
223 * @param src_data pointers containing the source image data
224 * @param src_linesize linesizes for the image in src_data
225 * @param pix_fmt the pixel format of the source image
226 * @param width the width of the source image in pixels
227 * @param height the height of the source image in pixels
228 * @param align the assumed linesize alignment for dst
229 * @return the number of bytes written to dst, or a negative value
230 * (error code) on error
231 */232 intav_image_copy_to_buffer (
233 ubyte* dst,
234 intdst_size,
235 refconst(ubyte*)[4] src_data,
236 refconst(int)[4] src_linesize,
237 AVPixelFormatpix_fmt,
238 intwidth,
239 intheight,
240 intalign_);
241 242 /**
243 * Check if the given dimension of an image is valid, meaning that all
244 * bytes of the image can be addressed with a signed int.
245 *
246 * @param w the width of the picture
247 * @param h the height of the picture
248 * @param log_offset the offset to sum to the log level for logging with log_ctx
249 * @param log_ctx the parent logging context, it may be NULL
250 * @return >= 0 if valid, a negative error code otherwise
251 */252 intav_image_check_size (uintw, uinth, intlog_offset, void* log_ctx);
253 254 /**
255 * Check if the given dimension of an image is valid, meaning that all
256 * bytes of a plane of an image with the specified pix_fmt can be addressed
257 * with a signed int.
258 *
259 * @param w the width of the picture
260 * @param h the height of the picture
261 * @param max_pixels the maximum number of pixels the user wants to accept
262 * @param pix_fmt the pixel format, can be AV_PIX_FMT_NONE if unknown.
263 * @param log_offset the offset to sum to the log level for logging with log_ctx
264 * @param log_ctx the parent logging context, it may be NULL
265 * @return >= 0 if valid, a negative error code otherwise
266 */267 intav_image_check_size2 (uintw, uinth, longmax_pixels, AVPixelFormatpix_fmt, intlog_offset, void* log_ctx);
268 269 /**
270 * Check if the given sample aspect ratio of an image is valid.
271 *
272 * It is considered invalid if the denominator is 0 or if applying the ratio
273 * to the image size would make the smaller dimension less than 1. If the
274 * sar numerator is 0, it is considered unknown and will return as valid.
275 *
276 * @param w width of the image
277 * @param h height of the image
278 * @param sar sample aspect ratio of the image
279 * @return 0 if valid, a negative AVERROR code otherwise
280 */281 intav_image_check_sar (uintw, uinth, AVRationalsar);
282 283 /**
284 * Overwrite the image data with black. This is suitable for filling a
285 * sub-rectangle of an image, meaning the padding between the right most pixel
286 * and the left most pixel on the next line will not be overwritten. For some
287 * formats, the image size might be rounded up due to inherent alignment.
288 *
289 * If the pixel format has alpha, the alpha is cleared to opaque.
290 *
291 * This can return an error if the pixel format is not supported. Normally, all
292 * non-hwaccel pixel formats should be supported.
293 *
294 * Passing NULL for dst_data is allowed. Then the function returns whether the
295 * operation would have succeeded. (It can return an error if the pix_fmt is
296 * not supported.)
297 *
298 * @param dst_data data pointers to destination image
299 * @param dst_linesize linesizes for the destination image
300 * @param pix_fmt the pixel format of the image
301 * @param range the color range of the image (important for colorspaces such as YUV)
302 * @param width the width of the image in pixels
303 * @param height the height of the image in pixels
304 * @return 0 if the image data was cleared, a negative AVERROR code otherwise
305 */306 intav_image_fill_black (
307 refubyte*[4] dst_data,
308 refconst(ptrdiff_t)[4] dst_linesize,
309 AVPixelFormatpix_fmt,
310 AVColorRangerange,
311 intwidth,
312 intheight);
313 314 /**
315 * @}
316 */317 318 /* AVUTIL_IMGUTILS_H */