FFmpeg
imgutils.c
Go to the documentation of this file.
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 /**
20  * @file
21  * misc image utilities
22  */
23 
24 #include "avassert.h"
25 #include "common.h"
26 #include "imgutils.h"
27 #include "imgutils_internal.h"
28 #include "internal.h"
29 #include "intreadwrite.h"
30 #include "log.h"
31 #include "mathematics.h"
32 #include "pixdesc.h"
33 #include "rational.h"
34 
35 void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4],
36  const AVPixFmtDescriptor *pixdesc)
37 {
38  int i;
39  memset(max_pixsteps, 0, 4*sizeof(max_pixsteps[0]));
40  if (max_pixstep_comps)
41  memset(max_pixstep_comps, 0, 4*sizeof(max_pixstep_comps[0]));
42 
43  for (i = 0; i < 4; i++) {
44  const AVComponentDescriptor *comp = &(pixdesc->comp[i]);
45  if (comp->step > max_pixsteps[comp->plane]) {
46  max_pixsteps[comp->plane] = comp->step;
47  if (max_pixstep_comps)
48  max_pixstep_comps[comp->plane] = i;
49  }
50  }
51 }
52 
53 static inline
55  int max_step, int max_step_comp,
56  const AVPixFmtDescriptor *desc)
57 {
58  int s, shifted_w, linesize;
59 
60  if (!desc)
61  return AVERROR(EINVAL);
62 
63  if (width < 0)
64  return AVERROR(EINVAL);
65  s = (max_step_comp == 1 || max_step_comp == 2) ? desc->log2_chroma_w : 0;
66  shifted_w = ((width + (1 << s) - 1)) >> s;
67  if (shifted_w && max_step > INT_MAX / shifted_w)
68  return AVERROR(EINVAL);
69  linesize = max_step * shifted_w;
70 
71  if (desc->flags & AV_PIX_FMT_FLAG_BITSTREAM)
72  linesize = (linesize + 7) >> 3;
73  return linesize;
74 }
75 
77 {
79  int max_step [4]; /* max pixel step for each plane */
80  int max_step_comp[4]; /* the component for each plane which has the max pixel step */
81 
82  if (!desc || desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
83  return AVERROR(EINVAL);
84 
85  av_image_fill_max_pixsteps(max_step, max_step_comp, desc);
86  return image_get_linesize(width, plane, max_step[plane], max_step_comp[plane], desc);
87 }
88 
89 int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
90 {
91  int i, ret;
93  int max_step [4]; /* max pixel step for each plane */
94  int max_step_comp[4]; /* the component for each plane which has the max pixel step */
95 
96  memset(linesizes, 0, 4*sizeof(linesizes[0]));
97 
98  if (!desc || desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
99  return AVERROR(EINVAL);
100 
101  av_image_fill_max_pixsteps(max_step, max_step_comp, desc);
102  for (i = 0; i < 4; i++) {
103  if ((ret = image_get_linesize(width, i, max_step[i], max_step_comp[i], desc)) < 0)
104  return ret;
105  linesizes[i] = ret;
106  }
107 
108  return 0;
109 }
110 
112  uint8_t *ptr, const int linesizes[4])
113 {
114  int i, total_size, size[4] = { 0 }, has_plane[4] = { 0 };
115 
117  memset(data , 0, sizeof(data[0])*4);
118 
119  if (!desc || desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
120  return AVERROR(EINVAL);
121 
122  data[0] = ptr;
123  if (linesizes[0] > (INT_MAX - 1024) / height)
124  return AVERROR(EINVAL);
125  size[0] = linesizes[0] * height;
126 
127  if (desc->flags & AV_PIX_FMT_FLAG_PAL ||
128  desc->flags & FF_PSEUDOPAL) {
129  data[1] = ptr + size[0]; /* palette is stored here as 256 32 bits words */
130  return size[0] + 256 * 4;
131  }
132 
133  for (i = 0; i < 4; i++)
134  has_plane[desc->comp[i].plane] = 1;
135 
136  total_size = size[0];
137  for (i = 1; i < 4 && has_plane[i]; i++) {
138  int h, s = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
139  data[i] = data[i-1] + size[i-1];
140  h = (height + (1 << s) - 1) >> s;
141  if (linesizes[i] > INT_MAX / h)
142  return AVERROR(EINVAL);
143  size[i] = h * linesizes[i];
144  if (total_size > INT_MAX - size[i])
145  return AVERROR(EINVAL);
146  total_size += size[i];
147  }
148 
149  return total_size;
150 }
151 
153 {
154  int i;
155 
156  for (i = 0; i < 256; i++) {
157  int r, g, b;
158 
159  switch (pix_fmt) {
160  case AV_PIX_FMT_RGB8:
161  r = (i>>5 )*36;
162  g = ((i>>2)&7)*36;
163  b = (i&3 )*85;
164  break;
165  case AV_PIX_FMT_BGR8:
166  b = (i>>6 )*85;
167  g = ((i>>3)&7)*36;
168  r = (i&7 )*36;
169  break;
171  r = (i>>3 )*255;
172  g = ((i>>1)&3)*85;
173  b = (i&1 )*255;
174  break;
176  b = (i>>3 )*255;
177  g = ((i>>1)&3)*85;
178  r = (i&1 )*255;
179  break;
180  case AV_PIX_FMT_GRAY8:
181  r = b = g = i;
182  break;
183  default:
184  return AVERROR(EINVAL);
185  }
186  pal[i] = b + (g << 8) + (r << 16) + (0xFFU << 24);
187  }
188 
189  return 0;
190 }
191 
192 int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
193  int w, int h, enum AVPixelFormat pix_fmt, int align)
194 {
196  int i, ret;
197  uint8_t *buf;
198 
199  if (!desc)
200  return AVERROR(EINVAL);
201 
202  if ((ret = av_image_check_size(w, h, 0, NULL)) < 0)
203  return ret;
204  if ((ret = av_image_fill_linesizes(linesizes, pix_fmt, align>7 ? FFALIGN(w, 8) : w)) < 0)
205  return ret;
206 
207  for (i = 0; i < 4; i++)
208  linesizes[i] = FFALIGN(linesizes[i], align);
209 
210  if ((ret = av_image_fill_pointers(pointers, pix_fmt, h, NULL, linesizes)) < 0)
211  return ret;
212  buf = av_malloc(ret + align);
213  if (!buf)
214  return AVERROR(ENOMEM);
215  if ((ret = av_image_fill_pointers(pointers, pix_fmt, h, buf, linesizes)) < 0) {
216  av_free(buf);
217  return ret;
218  }
219  if (desc->flags & AV_PIX_FMT_FLAG_PAL || (desc->flags & FF_PSEUDOPAL && pointers[1])) {
221  if (align < 4) {
222  av_log(NULL, AV_LOG_ERROR, "Formats with a palette require a minimum alignment of 4\n");
223  return AVERROR(EINVAL);
224  }
225  }
226 
227  if ((desc->flags & AV_PIX_FMT_FLAG_PAL ||
228  desc->flags & FF_PSEUDOPAL) && pointers[1] &&
229  pointers[1] - pointers[0] > linesizes[0] * h) {
230  /* zero-initialize the padding before the palette */
231  memset(pointers[0] + linesizes[0] * h, 0,
232  pointers[1] - pointers[0] - linesizes[0] * h);
233  }
234 
235  return ret;
236 }
237 
238 typedef struct ImgUtils {
239  const AVClass *class;
241  void *log_ctx;
242 } ImgUtils;
243 
244 static const AVClass imgutils_class = {
245  .class_name = "IMGUTILS",
246  .item_name = av_default_item_name,
247  .option = NULL,
248  .version = LIBAVUTIL_VERSION_INT,
249  .log_level_offset_offset = offsetof(ImgUtils, log_offset),
250  .parent_log_context_offset = offsetof(ImgUtils, log_ctx),
251 };
252 
253 int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
254 {
255  ImgUtils imgutils = {
256  .class = &imgutils_class,
257  .log_offset = log_offset,
258  .log_ctx = log_ctx,
259  };
260  int64_t stride = av_image_get_linesize(pix_fmt, w, 0);
261  if (stride <= 0)
262  stride = 8LL*w;
263  stride += 128*8;
264 
265  if ((int)w<=0 || (int)h<=0 || stride >= INT_MAX || stride*(uint64_t)(h+128) >= INT_MAX) {
266  av_log(&imgutils, AV_LOG_ERROR, "Picture size %ux%u is invalid\n", w, h);
267  return AVERROR(EINVAL);
268  }
269 
270  if (max_pixels < INT64_MAX) {
271  if (w*(int64_t)h > max_pixels) {
272  av_log(&imgutils, AV_LOG_ERROR,
273  "Picture size %ux%u exceeds specified max pixel count %"PRId64", see the documentation if you wish to increase it\n",
274  w, h, max_pixels);
275  return AVERROR(EINVAL);
276  }
277  }
278 
279  return 0;
280 }
281 
282 int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
283 {
284  return av_image_check_size2(w, h, INT64_MAX, AV_PIX_FMT_NONE, log_offset, log_ctx);
285 }
286 
287 int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar)
288 {
289  int64_t scaled_dim;
290 
291  if (sar.den <= 0 || sar.num < 0)
292  return AVERROR(EINVAL);
293 
294  if (!sar.num || sar.num == sar.den)
295  return 0;
296 
297  if (sar.num < sar.den)
298  scaled_dim = av_rescale_rnd(w, sar.num, sar.den, AV_ROUND_ZERO);
299  else
300  scaled_dim = av_rescale_rnd(h, sar.den, sar.num, AV_ROUND_ZERO);
301 
302  if (scaled_dim > 0)
303  return 0;
304 
305  return AVERROR(EINVAL);
306 }
307 
308 static void image_copy_plane(uint8_t *dst, ptrdiff_t dst_linesize,
309  const uint8_t *src, ptrdiff_t src_linesize,
310  ptrdiff_t bytewidth, int height)
311 {
312  if (!dst || !src)
313  return;
314  av_assert0(FFABS(src_linesize) >= bytewidth);
315  av_assert0(FFABS(dst_linesize) >= bytewidth);
316  for (;height > 0; height--) {
317  memcpy(dst, src, bytewidth);
318  dst += dst_linesize;
319  src += src_linesize;
320  }
321 }
322 
323 static void image_copy_plane_uc_from(uint8_t *dst, ptrdiff_t dst_linesize,
324  const uint8_t *src, ptrdiff_t src_linesize,
325  ptrdiff_t bytewidth, int height)
326 {
327  int ret = -1;
328 
329 #if ARCH_X86
330  ret = ff_image_copy_plane_uc_from_x86(dst, dst_linesize, src, src_linesize,
331  bytewidth, height);
332 #endif
333 
334  if (ret < 0)
335  image_copy_plane(dst, dst_linesize, src, src_linesize, bytewidth, height);
336 }
337 
338 void av_image_copy_plane(uint8_t *dst, int dst_linesize,
339  const uint8_t *src, int src_linesize,
340  int bytewidth, int height)
341 {
342  image_copy_plane(dst, dst_linesize, src, src_linesize, bytewidth, height);
343 }
344 
345 static void image_copy(uint8_t *dst_data[4], const ptrdiff_t dst_linesizes[4],
346  const uint8_t *src_data[4], const ptrdiff_t src_linesizes[4],
347  enum AVPixelFormat pix_fmt, int width, int height,
348  void (*copy_plane)(uint8_t *, ptrdiff_t, const uint8_t *,
349  ptrdiff_t, ptrdiff_t, int))
350 {
352 
353  if (!desc || desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
354  return;
355 
356  if (desc->flags & AV_PIX_FMT_FLAG_PAL ||
357  desc->flags & FF_PSEUDOPAL) {
358  copy_plane(dst_data[0], dst_linesizes[0],
359  src_data[0], src_linesizes[0],
360  width, height);
361  /* copy the palette */
362  if ((desc->flags & AV_PIX_FMT_FLAG_PAL) || (dst_data[1] && src_data[1]))
363  memcpy(dst_data[1], src_data[1], 4*256);
364  } else {
365  int i, planes_nb = 0;
366 
367  for (i = 0; i < desc->nb_components; i++)
368  planes_nb = FFMAX(planes_nb, desc->comp[i].plane + 1);
369 
370  for (i = 0; i < planes_nb; i++) {
371  int h = height;
372  ptrdiff_t bwidth = av_image_get_linesize(pix_fmt, width, i);
373  if (bwidth < 0) {
374  av_log(NULL, AV_LOG_ERROR, "av_image_get_linesize failed\n");
375  return;
376  }
377  if (i == 1 || i == 2) {
378  h = AV_CEIL_RSHIFT(height, desc->log2_chroma_h);
379  }
380  copy_plane(dst_data[i], dst_linesizes[i],
381  src_data[i], src_linesizes[i],
382  bwidth, h);
383  }
384  }
385 }
386 
387 void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4],
388  const uint8_t *src_data[4], const int src_linesizes[4],
389  enum AVPixelFormat pix_fmt, int width, int height)
390 {
391  ptrdiff_t dst_linesizes1[4], src_linesizes1[4];
392  int i;
393 
394  for (i = 0; i < 4; i++) {
395  dst_linesizes1[i] = dst_linesizes[i];
396  src_linesizes1[i] = src_linesizes[i];
397  }
398 
399  image_copy(dst_data, dst_linesizes1, src_data, src_linesizes1, pix_fmt,
401 }
402 
403 void av_image_copy_uc_from(uint8_t *dst_data[4], const ptrdiff_t dst_linesizes[4],
404  const uint8_t *src_data[4], const ptrdiff_t src_linesizes[4],
405  enum AVPixelFormat pix_fmt, int width, int height)
406 {
407  image_copy(dst_data, dst_linesizes, src_data, src_linesizes, pix_fmt,
409 }
410 
411 int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4],
412  const uint8_t *src, enum AVPixelFormat pix_fmt,
413  int width, int height, int align)
414 {
415  int ret, i;
416 
418  if (ret < 0)
419  return ret;
420 
421  ret = av_image_fill_linesizes(dst_linesize, pix_fmt, width);
422  if (ret < 0)
423  return ret;
424 
425  for (i = 0; i < 4; i++)
426  dst_linesize[i] = FFALIGN(dst_linesize[i], align);
427 
428  return av_image_fill_pointers(dst_data, pix_fmt, height, (uint8_t *)src, dst_linesize);
429 }
430 
432  int width, int height, int align)
433 {
434  uint8_t *data[4];
435  int linesize[4];
436  int ret;
438  if (!desc)
439  return AVERROR(EINVAL);
440 
442  if (ret < 0)
443  return ret;
444 
445  // do not include palette for these pseudo-paletted formats
446  if (desc->flags & FF_PSEUDOPAL)
447  return FFALIGN(width, align) * height;
448 
449  return av_image_fill_arrays(data, linesize, NULL, pix_fmt,
450  width, height, align);
451 }
452 
453 int av_image_copy_to_buffer(uint8_t *dst, int dst_size,
454  const uint8_t * const src_data[4],
455  const int src_linesize[4],
456  enum AVPixelFormat pix_fmt,
457  int width, int height, int align)
458 {
459  int i, j, nb_planes = 0, linesize[4];
462  int ret;
463 
464  if (size > dst_size || size < 0 || !desc)
465  return AVERROR(EINVAL);
466 
467  for (i = 0; i < desc->nb_components; i++)
468  nb_planes = FFMAX(desc->comp[i].plane, nb_planes);
469 
470  nb_planes++;
471 
473  av_assert0(ret >= 0); // was checked previously
474 
475  for (i = 0; i < nb_planes; i++) {
476  int h, shift = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
477  const uint8_t *src = src_data[i];
478  h = (height + (1 << shift) - 1) >> shift;
479 
480  for (j = 0; j < h; j++) {
481  memcpy(dst, src, linesize[i]);
482  dst += FFALIGN(linesize[i], align);
483  src += src_linesize[i];
484  }
485  }
486 
487  if (desc->flags & AV_PIX_FMT_FLAG_PAL) {
488  uint32_t *d32 = (uint32_t *)dst;
489 
490  for (i = 0; i<256; i++)
491  AV_WL32(d32 + i, AV_RN32(src_data[1] + 4*i));
492  }
493 
494  return size;
495 }
496 
497 // Fill dst[0..dst_size] with the bytes in clear[0..clear_size]. The clear
498 // bytes are repeated until dst_size is reached. If dst_size is unaligned (i.e.
499 // dst_size%clear_size!=0), the remaining data will be filled with the beginning
500 // of the clear data only.
501 static void memset_bytes(uint8_t *dst, size_t dst_size, uint8_t *clear,
502  size_t clear_size)
503 {
504  int same = 1;
505  int i;
506 
507  if (!clear_size)
508  return;
509 
510  // Reduce to memset() if possible.
511  for (i = 0; i < clear_size; i++) {
512  if (clear[i] != clear[0]) {
513  same = 0;
514  break;
515  }
516  }
517  if (same)
518  clear_size = 1;
519 
520  if (clear_size == 1) {
521  memset(dst, clear[0], dst_size);
522  dst_size = 0;
523  } else {
524  if (clear_size > dst_size)
525  clear_size = dst_size;
526  memcpy(dst, clear, clear_size);
527  av_memcpy_backptr(dst + clear_size, clear_size, dst_size - clear_size);
528  }
529 }
530 
531 // Maximum size in bytes of a plane element (usually a pixel, or multiple pixels
532 // if it's a subsampled packed format).
533 #define MAX_BLOCK_SIZE 32
534 
535 int av_image_fill_black(uint8_t *dst_data[4], const ptrdiff_t dst_linesize[4],
536  enum AVPixelFormat pix_fmt, enum AVColorRange range,
537  int width, int height)
538 {
540  int nb_planes = av_pix_fmt_count_planes(pix_fmt);
541  // A pixel or a group of pixels on each plane, with a value that represents black.
542  // Consider e.g. AV_PIX_FMT_UYVY422 for non-trivial cases.
543  uint8_t clear_block[4][MAX_BLOCK_SIZE] = {{0}}; // clear padding with 0
544  int clear_block_size[4] = {0};
545  ptrdiff_t plane_line_bytes[4] = {0};
546  int rgb, limited;
547  int plane, c;
548 
549  if (!desc || nb_planes < 1 || nb_planes > 4 || desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
550  return AVERROR(EINVAL);
551 
552  rgb = !!(desc->flags & AV_PIX_FMT_FLAG_RGB);
553  limited = !rgb && range != AVCOL_RANGE_JPEG;
554 
555  if (desc->flags & AV_PIX_FMT_FLAG_BITSTREAM) {
556  ptrdiff_t bytewidth = av_image_get_linesize(pix_fmt, width, 0);
557  uint8_t *data;
559  int fill = pix_fmt == AV_PIX_FMT_MONOWHITE ? 0xFF : 0;
560  if (nb_planes != 1 || !(rgb || mono) || bytewidth < 1)
561  return AVERROR(EINVAL);
562 
563  if (!dst_data)
564  return 0;
565 
566  data = dst_data[0];
567 
568  // (Bitstream + alpha will be handled incorrectly - it'll remain transparent.)
569  for (;height > 0; height--) {
570  memset(data, fill, bytewidth);
571  data += dst_linesize[0];
572  }
573  return 0;
574  }
575 
576  for (c = 0; c < desc->nb_components; c++) {
577  const AVComponentDescriptor comp = desc->comp[c];
578 
579  // We try to operate on entire non-subsampled pixel groups (for
580  // AV_PIX_FMT_UYVY422 this would mean two consecutive pixels).
581  clear_block_size[comp.plane] = FFMAX(clear_block_size[comp.plane], comp.step);
582 
583  if (clear_block_size[comp.plane] > MAX_BLOCK_SIZE)
584  return AVERROR(EINVAL);
585  }
586 
587  // Create a byte array for clearing 1 pixel (sometimes several pixels).
588  for (c = 0; c < desc->nb_components; c++) {
589  const AVComponentDescriptor comp = desc->comp[c];
590  // (Multiple pixels happen e.g. with AV_PIX_FMT_UYVY422.)
591  int w = clear_block_size[comp.plane] / comp.step;
592  uint8_t *c_data[4];
593  const int c_linesize[4] = {0};
594  uint16_t src_array[MAX_BLOCK_SIZE];
595  uint16_t src = 0;
596  int x;
597 
598  if (comp.depth > 16)
599  return AVERROR(EINVAL);
600  if (!rgb && comp.depth < 8)
601  return AVERROR(EINVAL);
602  if (w < 1)
603  return AVERROR(EINVAL);
604 
605  if (c == 0 && limited) {
606  src = 16 << (comp.depth - 8);
607  } else if ((c == 1 || c == 2) && !rgb) {
608  src = 128 << (comp.depth - 8);
609  } else if (c == 3) {
610  // (Assume even limited YUV uses full range alpha.)
611  src = (1 << comp.depth) - 1;
612  }
613 
614  for (x = 0; x < w; x++)
615  src_array[x] = src;
616 
617  for (x = 0; x < 4; x++)
618  c_data[x] = &clear_block[x][0];
619 
620  av_write_image_line(src_array, c_data, c_linesize, desc, 0, 0, c, w);
621  }
622 
623  for (plane = 0; plane < nb_planes; plane++) {
624  plane_line_bytes[plane] = av_image_get_linesize(pix_fmt, width, plane);
625  if (plane_line_bytes[plane] < 0)
626  return AVERROR(EINVAL);
627  }
628 
629  if (!dst_data)
630  return 0;
631 
632  for (plane = 0; plane < nb_planes; plane++) {
633  size_t bytewidth = plane_line_bytes[plane];
634  uint8_t *data = dst_data[plane];
635  int chroma_div = plane == 1 || plane == 2 ? desc->log2_chroma_h : 0;
636  int plane_h = ((height + ( 1 << chroma_div) - 1)) >> chroma_div;
637 
638  for (; plane_h > 0; plane_h--) {
639  memset_bytes(data, bytewidth, &clear_block[plane][0], clear_block_size[plane]);
640  data += dst_linesize[plane];
641  }
642  }
643 
644  return 0;
645 }
stride
int stride
Definition: mace.c:144
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
image_get_linesize
static int image_get_linesize(int width, int plane, int max_step, int max_step_comp, const AVPixFmtDescriptor *desc)
Definition: imgutils.c:54
r
const char * r
Definition: vf_curves.c:114
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
comp
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition: eamad.c:83
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2522
rational.h
av_write_image_line
void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesize[4], const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
Definition: pixdesc.c:162
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:38
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:522
b
#define b
Definition: input.c:41
data
const char data[16]
Definition: mxf.c:91
AV_PIX_FMT_MONOWHITE
@ AV_PIX_FMT_MONOWHITE
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb.
Definition: pixfmt.h:75
ImgUtils
Definition: imgutils.c:238
mathematics.h
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
av_image_copy_plane
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:338
image_copy
static void image_copy(uint8_t *dst_data[4], const ptrdiff_t dst_linesizes[4], const uint8_t *src_data[4], const ptrdiff_t src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height, void(*copy_plane)(uint8_t *, ptrdiff_t, const uint8_t *, ptrdiff_t, ptrdiff_t, int))
Definition: imgutils.c:345
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2562
U
#define U(x)
Definition: vp56_arith.h:37
ImgUtils::log_ctx
void * log_ctx
Definition: imgutils.c:241
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:140
plane
int plane
Definition: avisynth_c.h:384
av_image_fill_pointers
int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int height, uint8_t *ptr, const int linesizes[4])
Fill plane data pointers for an image with pixel format pix_fmt and height height.
Definition: imgutils.c:111
AVRational::num
int num
Numerator.
Definition: rational.h:59
src
#define src
Definition: vp8dsp.c:254
copy_plane
static void copy_plane(AVCodecContext *avctx, AVFrame *src, AVFrame *dst)
Definition: rasc.c:82
av_image_check_size2
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
Definition: imgutils.c:253
ff_image_copy_plane_uc_from_x86
int ff_image_copy_plane_uc_from_x86(uint8_t *dst, ptrdiff_t dst_linesize, const uint8_t *src, ptrdiff_t src_linesize, ptrdiff_t bytewidth, int height)
Definition: imgutils_init.c:34
AV_PIX_FMT_BGR8
@ AV_PIX_FMT_BGR8
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:83
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
buf
void * buf
Definition: avisynth_c.h:766
ImgUtils::class
const AVClass * class
Definition: imgutils.c:239
av_memcpy_backptr
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
Definition: mem.c:426
width
#define width
av_image_fill_linesizes
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:89
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
g
const char * g
Definition: vf_curves.c:115
ImgUtils::log_offset
int log_offset
Definition: imgutils.c:240
image_copy_plane
static void image_copy_plane(uint8_t *dst, ptrdiff_t dst_linesize, const uint8_t *src, ptrdiff_t src_linesize, ptrdiff_t bytewidth, int height)
Definition: imgutils.c:308
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
pointers
Undefined Behavior In the C some operations are like signed integer dereferencing freed pointers
Definition: undefined.txt:4
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demuxing_decoding.c:40
avpriv_set_systematic_pal2
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
Definition: imgutils.c:152
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
AVComponentDescriptor
Definition: pixdesc.h:31
MAX_BLOCK_SIZE
#define MAX_BLOCK_SIZE
Definition: imgutils.c:533
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_PIX_FMT_MONOBLACK
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
Definition: pixfmt.h:76
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
AV_RN32
#define AV_RN32(p)
Definition: intreadwrite.h:364
AV_PIX_FMT_RGB8
@ AV_PIX_FMT_RGB8
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:86
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
av_image_fill_black
int av_image_fill_black(uint8_t *dst_data[4], const ptrdiff_t dst_linesize[4], enum AVPixelFormat pix_fmt, enum AVColorRange range, int width, int height)
Overwrite the image data with black.
Definition: imgutils.c:535
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
AV_PIX_FMT_BGR4_BYTE
@ AV_PIX_FMT_BGR4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
Definition: pixfmt.h:85
av_image_alloc
int av_image_alloc(uint8_t *pointers[4], int linesizes[4], int w, int h, enum AVPixelFormat pix_fmt, int align)
Allocate an image with size w and h and pixel format pix_fmt, and fill pointers and linesizes accordi...
Definition: imgutils.c:192
av_rescale_rnd
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
Definition: mathematics.c:58
desc
const char * desc
Definition: nvenc.c:68
memset_bytes
static void memset_bytes(uint8_t *dst, size_t dst_size, uint8_t *clear, size_t clear_size)
Definition: imgutils.c:501
av_image_fill_arrays
int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4], const uint8_t *src, enum AVPixelFormat pix_fmt, int width, int height, int align)
Setup the data pointers and linesizes based on the specified image parameters and the provided array.
Definition: imgutils.c:411
AV_PIX_FMT_FLAG_RGB
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:148
AV_ROUND_ZERO
@ AV_ROUND_ZERO
Round toward zero.
Definition: mathematics.h:80
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
size
int size
Definition: twinvq_data.h:11134
AV_PIX_FMT_FLAG_BITSTREAM
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
Definition: pixdesc.h:136
height
#define height
av_image_get_buffer_size
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters.
Definition: imgutils.c:431
imgutils_internal.h
imgutils_class
static const AVClass imgutils_class
Definition: imgutils.c:244
av_image_get_linesize
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
Compute the size of an image line with format pix_fmt and width width for the plane plane.
Definition: imgutils.c:76
av_image_copy_uc_from
void av_image_copy_uc_from(uint8_t *dst_data[4], const ptrdiff_t dst_linesizes[4], const uint8_t *src_data[4], const ptrdiff_t src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image data located in uncacheable (e.g.
Definition: imgutils.c:403
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
internal.h
common.h
uint8_t
uint8_t
Definition: audio_convert.c:194
AV_PIX_FMT_RGB4_BYTE
@ AV_PIX_FMT_RGB4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
Definition: pixfmt.h:88
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
align
const AVS_VideoInfo int align
Definition: avisynth_c.h:887
av_image_copy
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
Definition: imgutils.c:387
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AVPixFmtDescriptor::comp
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
av_image_fill_max_pixsteps
void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], const AVPixFmtDescriptor *pixdesc)
Compute the max pixel step for each plane of an image with a format described by pixdesc.
Definition: imgutils.c:35
shift
static int shift(int a, int b)
Definition: sonic.c:82
d32
const uint8_t * d32
Definition: yuv2rgb.c:502
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
av_image_copy_to_buffer
int av_image_copy_to_buffer(uint8_t *dst, int dst_size, const uint8_t *const src_data[4], const int src_linesize[4], enum AVPixelFormat pix_fmt, int width, int height, int align)
Copy image data from an image into a buffer.
Definition: imgutils.c:453
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:48
imgutils.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
FF_PSEUDOPAL
#define FF_PSEUDOPAL
Definition: internal.h:369
h
h
Definition: vp9dsp_template.c:2038
av_image_check_sar
int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar)
Check if the given sample aspect ratio of an image is valid.
Definition: imgutils.c:287
av_image_check_size
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:282
AVColorRange
AVColorRange
MPEG vs JPEG YUV range.
Definition: pixfmt.h:519
AV_PIX_FMT_FLAG_PAL
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:132
image_copy_plane_uc_from
static void image_copy_plane_uc_from(uint8_t *dst, ptrdiff_t dst_linesize, const uint8_t *src, ptrdiff_t src_linesize, ptrdiff_t bytewidth, int height)
Definition: imgutils.c:323