38 memset(max_pixsteps, 0, 4*
sizeof(max_pixsteps[0]));
39 if (max_pixstep_comps)
40 memset(max_pixstep_comps, 0, 4*
sizeof(max_pixstep_comps[0]));
42 for (i = 0; i < 4; i++) {
44 if (comp->
step > max_pixsteps[comp->
plane]) {
46 if (max_pixstep_comps)
47 max_pixstep_comps[comp->
plane] = i;
54 int max_step,
int max_step_comp,
57 int s, shifted_w, linesize;
64 s = (max_step_comp == 1 || max_step_comp == 2) ? desc->
log2_chroma_w : 0;
65 shifted_w = ((width + (1 << s) - 1)) >> s;
66 if (shifted_w && max_step > INT_MAX / shifted_w)
68 linesize = max_step * shifted_w;
71 linesize = (linesize + 7) >> 3;
95 memset(linesizes, 0, 4*
sizeof(linesizes[0]));
101 for (i = 0; i < 4; i++) {
111 uint8_t *ptr,
const int linesizes[4])
113 int i, total_size,
size[4] = { 0 }, has_plane[4] = { 0 };
116 memset(data , 0,
sizeof(data[0])*4);
122 if (linesizes[0] > (INT_MAX - 1024) / height)
124 size[0] = linesizes[0] *
height;
128 data[1] = ptr + size[0];
129 return size[0] + 256 * 4;
132 for (i = 0; i < 4; i++)
135 total_size = size[0];
136 for (i = 1; i < 4 && has_plane[i]; i++) {
138 data[i] = data[i-1] + size[i-1];
139 h = (height + (1 << s) - 1) >> s;
140 if (linesizes[i] > INT_MAX / h)
142 size[i] = h * linesizes[i];
143 if (total_size > INT_MAX - size[i])
145 total_size += size[i];
155 for (i = 0; i < 256; i++) {
185 pal[i] = b + (g << 8) + (r << 16) + (0xFF
U << 24);
206 for (i = 0; i < 4; i++)
207 linesizes[i] =
FFALIGN(linesizes[i], align);
228 pointers[1] - pointers[0] > linesizes[0] * h) {
230 memset(pointers[0] + linesizes[0] * h, 0,
231 pointers[1] - pointers[0] - linesizes[0] * h);
247 .log_level_offset_offset = offsetof(
ImgUtils, log_offset),
248 .parent_log_context_offset = offsetof(
ImgUtils, log_ctx),
255 .log_offset = log_offset,
259 if ((
int)w>0 && (
int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8)
270 if (sar.
den <= 0 || sar.
num < 0)
289 int bytewidth,
int height)
295 for (;height > 0; height--) {
296 memcpy(dst, src, bytewidth);
303 const uint8_t *src_data[4],
const int src_linesizes[4],
314 src_data[0], src_linesizes[0],
317 memcpy(dst_data[1], src_data[1], 4*256);
319 int i, planes_nb = 0;
324 for (i = 0; i < planes_nb; i++) {
331 if (i == 1 || i == 2) {
335 src_data[i], src_linesizes[i],
355 for (i = 0; i < 4; i++)
356 dst_linesize[i] =
FFALIGN(dst_linesize[i], align);
380 width, height, align);
384 const uint8_t *
const src_data[4],
385 const int src_linesize[4],
389 int i, j, nb_planes = 0, linesize[4];
393 if (size > dst_size || size < 0 || !desc)
402 for (i = 0; i < nb_planes; i++) {
405 h = (height + (1 << shift) - 1) >> shift;
407 for (j = 0; j <
h; j++) {
408 memcpy(dst,
src, linesize[i]);
409 dst +=
FFALIGN(linesize[i], align);
410 src += src_linesize[i];
415 uint32_t *
d32 = (uint32_t *)dst;
417 for (i = 0; i<256; i++)
#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.
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.
#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...
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.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
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.
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.
#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 AV_PIX_FMT_FLAG_PSEUDOPAL
The pixel format is "pseudo-paletted".
static int image_get_linesize(int width, int plane, int max_step, int max_step_comp, const AVPixFmtDescriptor *desc)
const AVS_VideoInfo int align
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...
BYTE int const BYTE int int int height
Describe the class of an AVClass context structure.
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 numerator/denominator
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
common internal and external API header
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
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.
AVPixelFormat
Pixel format.
int step
Number of elements between 2 horizontally consecutive pixels.
#define AV_CEIL_RSHIFT(a, b)