MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / av_image_alloc

Function av_image_alloc

libavutil/imgutils.c:218–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216}
217
218int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
219 int w, int h, enum AVPixelFormat pix_fmt, int align)
220{
221 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
222 int i, ret;
223 ptrdiff_t linesizes1[4];
224 size_t total_size, sizes[4];
225 uint8_t *buf;
226
227 if (!desc)
228 return AVERROR(EINVAL);
229
230 if ((ret = av_image_check_size(w, h, 0, NULL)) < 0)
231 return ret;
232 if ((ret = av_image_fill_linesizes(linesizes, pix_fmt, align>7 ? FFALIGN(w, 8) : w)) < 0)
233 return ret;
234
235 for (i = 0; i < 4; i++) {
236 linesizes[i] = FFALIGN(linesizes[i], align);
237 linesizes1[i] = linesizes[i];
238 }
239
240 if ((ret = av_image_fill_plane_sizes(sizes, pix_fmt, h, linesizes1)) < 0)
241 return ret;
242 total_size = align;
243 for (i = 0; i < 4; i++) {
244 if (total_size > SIZE_MAX - sizes[i])
245 return AVERROR(EINVAL);
246 total_size += sizes[i];
247 }
248 buf = av_malloc(total_size);
249 if (!buf)
250 return AVERROR(ENOMEM);
251 if ((ret = av_image_fill_pointers(pointers, pix_fmt, h, buf, linesizes)) < 0) {
252 av_free(buf);
253 return ret;
254 }
255 if (desc->flags & AV_PIX_FMT_FLAG_PAL) {
256 avpriv_set_systematic_pal2((uint32_t*)pointers[1], pix_fmt);
257 if (align < 4) {
258 av_log(NULL, AV_LOG_ERROR, "Formats with a palette require a minimum alignment of 4\n");
259 av_free(buf);
260 return AVERROR(EINVAL);
261 }
262 }
263
264 if (desc->flags & AV_PIX_FMT_FLAG_PAL && pointers[1] &&
265 pointers[1] - pointers[0] > linesizes[0] * h) {
266 /* zero-initialize the padding before the palette */
267 memset(pointers[0] + linesizes[0] * h, 0,
268 pointers[1] - pointers[0] - linesizes[0] * h);
269 }
270
271 return ret;
272}
273
274typedef struct ImgUtils {
275 const AVClass *class;

Callers 13

check_image_fill_blackFunction · 0.85
decode_frameFunction · 0.85
dxv_encodeFunction · 0.85
sws_setColorspaceDetailsFunction · 0.85
config_propsFunction · 0.85
config_inputFunction · 0.85
draw_qrcodeFunction · 0.85
config_propsFunction · 0.85
config_out_propsFunction · 0.85
ff_scale_imageFunction · 0.85
mainFunction · 0.85

Calls 9

av_pix_fmt_desc_getFunction · 0.85
av_image_check_sizeFunction · 0.85
av_image_fill_linesizesFunction · 0.85
av_image_fill_pointersFunction · 0.85
av_logFunction · 0.85
av_mallocFunction · 0.70
av_freeFunction · 0.70

Tested by 1

check_image_fill_blackFunction · 0.68