avpicture.c
Go to the documentation of this file.
1 /*
2  * AVPicture management routines
3  * Copyright (c) 2001, 2002, 2003 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * AVPicture management routines
25  */
26 
27 #include "avcodec.h"
28 #include "internal.h"
29 #include "libavutil/common.h"
30 #include "libavutil/pixdesc.h"
31 #include "libavutil/imgutils.h"
32 #include "libavutil/colorspace.h"
33 
34 int avpicture_fill(AVPicture *picture, const uint8_t *ptr,
35  enum AVPixelFormat pix_fmt, int width, int height)
36 {
37  return av_image_fill_arrays(picture->data, picture->linesize,
38  ptr, pix_fmt, width, height, 1);
39 }
40 
42  unsigned char *dest, int dest_size)
43 {
44  return av_image_copy_to_buffer(dest, dest_size,
45  (const uint8_t * const*)src->data, src->linesize,
46  pix_fmt, width, height, 1);
47 }
48 
50 {
51  return av_image_get_buffer_size(pix_fmt, width, height, 1);
52 }
53 
55  enum AVPixelFormat pix_fmt, int width, int height)
56 {
57  int ret = av_image_alloc(picture->data, picture->linesize,
58  width, height, pix_fmt, 1);
59  if (ret < 0) {
60  memset(picture, 0, sizeof(AVPicture));
61  return ret;
62  }
63 
64  return 0;
65 }
66 
67 void avpicture_free(AVPicture *picture)
68 {
69  av_free(picture->data[0]);
70 }
71 
73  enum AVPixelFormat pix_fmt, int width, int height)
74 {
75  av_image_copy(dst->data, dst->linesize, (const uint8_t **)src->data,
76  src->linesize, pix_fmt, width, height);
77 }
78 
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
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:333
misc image utilities
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:190
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:296
Various defines for YUV<->RGB conversion.
int avpicture_layout(const AVPicture *src, enum AVPixelFormat pix_fmt, int width, int height, unsigned char *dest, int dest_size)
Copy pixel data from an AVPicture into a buffer, always assume a linesize alignment of 1...
Definition: avpicture.c:41
four components are given, that&#39;s all.
int avpicture_fill(AVPicture *picture, const uint8_t *ptr, enum AVPixelFormat pix_fmt, int width, int height)
Fill in the AVPicture fields, always assume a linesize alignment of 1.
Definition: avpicture.c:34
void av_picture_copy(AVPicture *dst, const AVPicture *src, enum AVPixelFormat pix_fmt, int width, int height)
Copy image src to dst.
Definition: avpicture.c:72
uint8_t
uint8_t * data[AV_NUM_DATA_POINTERS]
enum AVPixelFormat pix_fmt
Definition: v4l.c:63
void avpicture_free(AVPicture *picture)
Free a picture previously allocated by avpicture_alloc().
Definition: avpicture.c:67
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:317
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
external API header
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:257
ret
Definition: avfilter.c:821
static int width
Definition: tests/utils.c:158
dest
Definition: start.py:60
AVS_Value src
Definition: avisynth_c.h:523
BYTE int const BYTE int int int height
Definition: avisynth_c.h:713
int avpicture_alloc(AVPicture *picture, enum AVPixelFormat pix_fmt, int width, int height)
Allocate memory for a picture.
Definition: avpicture.c:54
common internal api header.
common internal and external API header
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height)
Calculate the size in bytes that a picture of the given width and height would occupy if stored in th...
Definition: avpicture.c:49
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66