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]) {
46 max_pixsteps[
comp->plane] =
comp->step;
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;
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 };
122 if (linesizes[0] > SIZE_MAX /
height)
131 for (
i = 0;
i < 4;
i++)
132 has_plane[
desc->comp[
i].plane] = 1;
134 for (
i = 1;
i < 4 && has_plane[
i];
i++) {
135 int h,
s = (
i == 1 ||
i == 2) ?
desc->log2_chroma_h : 0;
137 if (linesizes[
i] > SIZE_MAX /
h)
139 sizes[
i] = (size_t)
h * linesizes[
i];
146 uint8_t *ptr,
const int linesizes[4])
149 ptrdiff_t linesizes1[4];
152 memset(
data , 0,
sizeof(
data[0])*4);
154 for (
i = 0;
i < 4;
i++)
155 linesizes1[
i] = linesizes[
i];
162 for (
i = 0;
i < 4;
i++) {
163 if (
sizes[
i] > INT_MAX - ret)
182 for (
i = 0;
i < 256;
i++) {
212 pal[
i] =
b + (
g << 8) + (
r << 16) + (0xFFU << 24);
223 ptrdiff_t linesizes1[4];
224 size_t total_size,
sizes[4];
235 for (
i = 0;
i < 4;
i++) {
237 linesizes1[
i] = linesizes[
i];
243 for (
i = 0;
i < 4;
i++) {
244 if (total_size > SIZE_MAX -
sizes[
i])
265 pointers[1] - pointers[0] > linesizes[0] *
h) {
267 memset(pointers[0] + linesizes[0] *
h, 0,
268 pointers[1] - pointers[0] - linesizes[0] *
h);
281 .class_name =
"IMGUTILS",
285 .log_level_offset_offset = offsetof(
ImgUtils, log_offset),
286 .parent_log_context_offset = offsetof(
ImgUtils, log_ctx),
293 .log_offset = log_offset,
301 if (
w==0 ||
h==0 ||
w > INT32_MAX ||
h > INT32_MAX ||
stride >= INT_MAX ||
stride*(
h + 128ULL) >= INT_MAX) {
306 if (max_pixels < INT64_MAX) {
309 "Picture size %ux%u exceeds specified max pixel count %"PRId64
", see the documentation if you wish to increase it\n",
327 if (sar.
den <= 0 || sar.
num < 0)
345 const uint8_t *
src, ptrdiff_t src_linesize,
346 ptrdiff_t bytewidth,
int height)
353 memcpy(
dst,
src, bytewidth);
360 const uint8_t *
src, ptrdiff_t src_linesize,
361 ptrdiff_t bytewidth,
int height)
365#if ARCH_X86 && HAVE_X86ASM
375 const uint8_t *
src,
int src_linesize,
376 int bytewidth,
int height)
381static void image_copy(uint8_t *
const dst_data[4],
const ptrdiff_t dst_linesizes[4],
382 const uint8_t *
const src_data[4],
const ptrdiff_t src_linesizes[4],
384 void (*
copy_plane)(uint8_t *, ptrdiff_t,
const uint8_t *,
385 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;
402 for (
i = 0;
i <
desc->nb_components;
i++)
403 planes_nb =
FFMAX(planes_nb,
desc->comp[
i].plane + 1);
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 *
const 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];
439 const uint8_t *
const src_data[4],
const ptrdiff_t src_linesizes[4],
460 for (
i = 0;
i < 4;
i++)
471 ptrdiff_t aligned_linesize[4];
485 for (
i = 0;
i < 4;
i++)
493 for (
i = 0;
i < 4;
i++) {
494 if (
sizes[
i] > INT_MAX - ret)
502 const uint8_t *
const src_data[4],
503 const int src_linesize[4],
507 int i, j, nb_planes = 0, linesize[4];
515 for (
i = 0;
i <
desc->nb_components;
i++)
516 nb_planes =
FFMAX(
desc->comp[
i].plane, nb_planes);
523 for (
i = 0;
i < nb_planes;
i++) {
524 int h,
shift = (
i == 1 ||
i == 2) ?
desc->log2_chroma_h : 0;
525 const uint8_t *
src = src_data[
i];
528 for (j = 0; j <
h; j++) {
531 src += src_linesize[
i];
536 uint32_t *d32 = (uint32_t *)
dst;
538 for (
i = 0;
i<256;
i++)
559 for (
i = 0;
i < clear_size;
i++) {
560 if (clear[
i] != clear[0]) {
568 if (clear_size == 1) {
569 memset(
dst, clear[0], dst_size);
571 if (clear_size > dst_size)
572 clear_size = dst_size;
573 memcpy(
dst, clear, clear_size);
580#define MAX_BLOCK_SIZE 32
591 int clear_block_size[4] = {0};
592 ptrdiff_t plane_line_bytes[4] = {0};
601 for (
c = 0;
c <
desc->nb_components;
c++) {
613 for (
c = 0;
c <
desc->nb_components;
c++) {
616 int w = (bitstream ? 8 : 1) * clear_block_size[
comp.plane] /
comp.step;
618 const int c_linesize[4] = {0};
627 for (x = 0; x <
w; x++)
630 for (x = 0; x < 4; x++)
631 c_data[x] = &clear_block[x][0];
636 for (plane = 0; plane < nb_planes; plane++) {
638 if (plane_line_bytes[plane] < 0)
645 for (plane = 0; plane < nb_planes; plane++) {
646 size_t bytewidth = plane_line_bytes[plane];
647 uint8_t *
data = dst_data[plane];
648 int chroma_div = plane == 1 || plane == 2 ?
desc->log2_chroma_h : 0;
651 for (; plane_h > 0; plane_h--) {
652 memset_bytes(
data, bytewidth, &clear_block[plane][0], clear_block_size[plane]);
653 data += dst_linesize[plane];
666 int rgb, xyz, pal, limited,
alpha, fltp;
667 uint32_t colors[4] = {0};
679 for (
int c = 0;
c <
desc->nb_components;
c++) {
688 }
else if (
c + 1 ==
desc->nb_components &&
alpha) {
691 if (
comp.depth != 16 &&
comp.depth != 32)
693 color = (
comp.depth == 16 ? 0x3C00 : 0x3F800000);
697 }
else if (
c == 0 && limited &&
comp.depth > 1) {
698 if (
comp.depth < 8 || (fltp &&
comp.depth != 16 &&
comp.depth != 32))
701 color = (
comp.depth == 16 ? 0x2C00 : 0x3D800000);
704 }
else if ((
c == 1 ||
c == 2) && !
rgb && !xyz) {
705 if (
comp.depth < 8 || fltp &&
comp.depth != 16 &&
comp.depth != 32)
708 color = (
comp.depth == 16 ? 0x3800 : 0x3F000000);
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static enum AVPixelFormat pix_fmt
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
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.
@ AV_ROUND_ZERO
Round toward zero.
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
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.
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...
int av_image_fill_black(uint8_t *const 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.
void av_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)
Copy image data located in uncacheable (e.g.
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.
void av_image_copy(uint8_t *const dst_data[4], const int dst_linesizes[4], const uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
int av_image_fill_color(uint8_t *const dst_data[4], const ptrdiff_t dst_linesize[4], enum AVPixelFormat pix_fmt, const uint32_t color[4], int width, int height, int flags)
Overwrite the image data with a color.
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.
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.
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.
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.
void av_image_copy_uc_from(uint8_t *const dst_data[4], const ptrdiff_t dst_linesizes[4], const uint8_t *const 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.
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...
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.
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_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
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.
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.
#define LIBAVUTIL_VERSION_INT
static const int16_t alpha[]
static const int sizes[][2]
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
static int image_get_linesize(int width, int plane, int max_step, int max_step_comp, const AVPixFmtDescriptor *desc)
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)
static const AVClass imgutils_class
static void image_copy(uint8_t *const dst_data[4], const ptrdiff_t dst_linesizes[4], const uint8_t *const 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))
static void memset_bytes(uint8_t *dst, size_t dst_size, uint8_t *clear, size_t clear_size)
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)
static int shift(int a, int b)
Memory handling functions.
void av_write_image_line2(const void *src, uint8_t *data[4], const int linesize[4], const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int src_element_size)
Write the values from src to the pixel format component c of an image line.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
#define AV_PIX_FMT_FLAG_XYZ
The pixel format contains XYZ-like data (as opposed to YUV/RGB/grayscale).
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
AVColorRange
Visual content value range.
@ AVCOL_RANGE_JPEG
Full range content.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_RGB8
packed RGB 3:3:2, 8bpp, (msb)3R 3G 2B(lsb)
@ AV_PIX_FMT_BGR8
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
@ AV_PIX_FMT_RGB4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
@ AV_PIX_FMT_BGR4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
@ AV_PIX_FMT_MONOWHITE
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb.
static void copy_plane(AVCodecContext *avctx, AVFrame *src, AVFrame *dst)
Utilities for rational number calculation.
Describe the class of an AVClass context structure.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Rational number (pair of numerator and denominator).