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]));
43 for (i = 0; i < 4; i++) {
45 if (comp->
step > max_pixsteps[comp->
plane]) {
47 if (max_pixstep_comps)
48 max_pixstep_comps[comp->
plane] =
i;
55 int max_step,
int max_step_comp,
58 int s, shifted_w, linesize;
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)
69 linesize = max_step * shifted_w;
72 linesize = (linesize + 7) >> 3;
96 memset(linesizes, 0, 4*
sizeof(linesizes[0]));
102 for (i = 0; i < 4; i++) {
112 int height,
const ptrdiff_t linesizes[4])
114 int i, has_plane[4] = { 0 };
117 memset(sizes , 0,
sizeof(sizes[0])*4);
122 if (linesizes[0] > SIZE_MAX / height)
124 sizes[0] = linesizes[0] * (size_t)height;
132 for (i = 0; i < 4; i++)
135 for (i = 1; i < 4 && has_plane[
i]; i++) {
137 h = (height + (1 << s) - 1) >> s;
138 if (linesizes[i] > SIZE_MAX / h)
140 sizes[
i] = (size_t)h * linesizes[i];
147 uint8_t *ptr,
const int linesizes[4])
150 ptrdiff_t linesizes1[4];
153 memset(data , 0,
sizeof(data[0])*4);
155 for (i = 0; i < 4; i++)
156 linesizes1[i] = linesizes[i];
163 for (i = 0; i < 4; i++) {
164 if (sizes[i] > INT_MAX - ret)
170 for (i = 1; i < 4 && sizes[
i]; i++)
171 data[i] = data[i - 1] + sizes[i - 1];
180 for (i = 0; i < 256; i++) {
210 pal[
i] = b + (g << 8) + (r << 16) + (0xFF
U << 24);
221 ptrdiff_t linesizes1[4];
222 size_t total_size,
sizes[4];
233 for (i = 0; i < 4; i++) {
234 linesizes[
i] =
FFALIGN(linesizes[i], align);
235 linesizes1[
i] = linesizes[
i];
241 for (i = 0; i < 4; i++) {
242 if (total_size > SIZE_MAX - sizes[i])
244 total_size += sizes[
i];
264 pointers[1] - pointers[0] > linesizes[0] * h) {
266 memset(pointers[0] + linesizes[0] * h, 0,
267 pointers[1] - pointers[0] - linesizes[0] * h);
300 if ((
int)w<=0 || (
int)h<=0 || stride >= INT_MAX || stride*(uint64_t)(h+128) >= INT_MAX) {
305 if (max_pixels < INT64_MAX) {
306 if (w*(int64_t)h > max_pixels) {
308 "Picture size %ux%u exceeds specified max pixel count %"PRId64
", see the documentation if you wish to increase it\n",
326 if (sar.
den <= 0 || sar.
num < 0)
345 ptrdiff_t bytewidth,
int height)
351 for (;height > 0; height--) {
352 memcpy(dst, src, bytewidth);
360 ptrdiff_t bytewidth,
int height)
375 int bytewidth,
int height)
381 const uint8_t *src_data[4],
const ptrdiff_t src_linesizes[4],
384 ptrdiff_t, ptrdiff_t,
int))
394 src_data[0], src_linesizes[0],
398 memcpy(dst_data[1], src_data[1], 4*256);
400 int i, planes_nb = 0;
405 for (i = 0; i < planes_nb; i++) {
412 if (i == 1 || i == 2) {
416 src_data[i], src_linesizes[i],
423 const uint8_t *src_data[4],
const int src_linesizes[4],
426 ptrdiff_t dst_linesizes1[4], src_linesizes1[4];
429 for (i = 0; i < 4; i++) {
430 dst_linesizes1[
i] = dst_linesizes[
i];
431 src_linesizes1[
i] = src_linesizes[
i];
434 image_copy(dst_data, dst_linesizes1, src_data, src_linesizes1, pix_fmt,
439 const uint8_t *src_data[4],
const ptrdiff_t src_linesizes[4],
442 image_copy(dst_data, dst_linesizes, src_data, src_linesizes, pix_fmt,
448 int width,
int height,
int align)
460 for (i = 0; i < 4; i++)
461 dst_linesize[i] =
FFALIGN(dst_linesize[i], align);
467 int width,
int height,
int align)
471 ptrdiff_t aligned_linesize[4];
489 for (i = 0; i < 4; i++)
490 aligned_linesize[i] =
FFALIGN(linesize[i], align);
497 for (i = 0; i < 4; i++) {
498 if (sizes[i] > INT_MAX - ret)
506 const uint8_t *
const src_data[4],
507 const int src_linesize[4],
509 int width,
int height,
int align)
511 int i, j, nb_planes = 0, linesize[4];
516 if (size > dst_size || size < 0 || !desc)
527 for (i = 0; i < nb_planes; i++) {
530 h = (height + (1 << shift) - 1) >> shift;
532 for (j = 0; j <
h; j++) {
533 memcpy(dst,
src, linesize[i]);
534 dst +=
FFALIGN(linesize[i], align);
535 src += src_linesize[
i];
540 uint32_t *
d32 = (uint32_t *)dst;
542 for (i = 0; i<256; i++)
563 for (i = 0; i < clear_size; i++) {
564 if (clear[i] != clear[0]) {
572 if (clear_size == 1) {
573 memset(dst, clear[0], dst_size);
575 if (clear_size > dst_size)
576 clear_size = dst_size;
577 memcpy(dst, clear, clear_size);
584 #define MAX_BLOCK_SIZE 32 588 int width,
int height)
595 int clear_block_size[4] = {0};
596 ptrdiff_t plane_line_bytes[4] = {0};
611 if (nb_planes != 1 || !(rgb || mono) || bytewidth < 1)
620 for (;height > 0; height--) {
621 memset(data, fill, bytewidth);
622 data += dst_linesize[0];
642 int w = clear_block_size[comp.
plane] / comp.
step;
644 const int c_linesize[4] = {0};
651 if (!rgb && comp.
depth < 8)
656 if (c == 0 && limited) {
657 src = 16 << (comp.
depth - 8);
658 }
else if ((c == 1 || c == 2) && !
rgb) {
659 src = 128 << (comp.
depth - 8);
662 src = (1 << comp.
depth) - 1;
665 for (x = 0; x <
w; x++)
668 for (x = 0; x < 4; x++)
669 c_data[x] = &clear_block[x][0];
674 for (plane = 0; plane < nb_planes; plane++) {
676 if (plane_line_bytes[plane] < 0)
683 for (plane = 0; plane < nb_planes; plane++) {
684 size_t bytewidth = plane_line_bytes[plane];
686 int chroma_div = plane == 1 || plane == 2 ? desc->
log2_chroma_h : 0;
687 int plane_h = ((height + ( 1 << chroma_div) - 1)) >> chroma_div;
689 for (; plane_h > 0; plane_h--) {
690 memset_bytes(data, bytewidth, &clear_block[plane][0], clear_block_size[plane]);
691 data += dst_linesize[plane];
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
int plane
Which of the 4 planes contains the component.
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...
static enum AVPixelFormat pix_fmt
static int shift(int a, int b)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
ptrdiff_t const GLvoid * data
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.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
#define LIBAVUTIL_VERSION_INT
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...
static const AVClass imgutils_class
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...
const char * av_default_item_name(void *ptr)
Return the context name.
static void memset_bytes(uint8_t *dst, size_t dst_size, uint8_t *clear, size_t clear_size)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
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.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Undefined Behavior In the C some operations are like signed integer dereferencing freed pointers
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
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
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)
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.
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
AVColorRange
Visual content value range.
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...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
static const int sizes[][2]
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
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)
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
simple assert() macros that are a bit more flexible than ISO C assert().
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.
common internal API header
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
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...
uint8_t nb_components
The number of components each pixel has, (1-4)
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static int image_get_linesize(int width, int plane, int max_step, int max_step_comp, const AVPixFmtDescriptor *desc)
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.
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
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.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static void copy_plane(AVCodecContext *avctx, AVFrame *src, AVFrame *dst)
Describe the class of an AVClass context structure.
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))
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.
Rational number (pair of numerator and denominator).
static const SheerTable rgb[2]
int av_image_fill_plane_sizes(size_t sizes[4], enum AVPixelFormat pix_fmt, int height, const ptrdiff_t linesizes[4])
Fill plane sizes for an image with pixel format pix_fmt and height height.
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
GLint GLenum GLboolean GLsizei stride
common internal and external API header
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb...
Utilties for rational number calculation.
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.
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
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...
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.
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)
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.
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)
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
int depth
Number of bits in the component.
AVPixelFormat
Pixel format.
int step
Number of elements between 2 horizontally consecutive pixels.
#define AV_CEIL_RSHIFT(a, b)