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 #include "libavutil/imgutils.c"
20 #include "libavutil/crc.h"
21 
22 #undef printf
23 static int check_image_fill(enum AVPixelFormat pix_fmt, int w, int h) {
24  uint8_t *data[4];
25  size_t sizes[4];
26  ptrdiff_t linesizes1[4], offsets[3] = { 0 };
27  int i, total_size, linesizes[4];
28 
29  if (av_image_fill_linesizes(linesizes, pix_fmt, w) < 0)
30  return -1;
31  for (i = 0; i < 4; i++)
32  linesizes1[i] = linesizes[i];
33  if (av_image_fill_plane_sizes(sizes, pix_fmt, h, linesizes1) < 0)
34  return -1;
35  total_size = av_image_fill_pointers(data, pix_fmt, h, (void *)1, linesizes);
36  if (total_size < 0)
37  return -1;
38  for (i = 0; i < 4 && data[i]; i++);
39  printf("planes: %d", i);
40  // Test the output of av_image_fill_linesizes()
41  printf(", linesizes:");
42  for (i = 0; i < 4; i++)
43  printf(" %3d", linesizes[i]);
44  // Test the output of av_image_fill_plane_sizes()
45  printf(", plane_sizes:");
46  for (i = 0; i < 4; i++)
47  printf(" %5"SIZE_SPECIFIER, sizes[i]);
48  // Test the output of av_image_fill_pointers()
49  for (i = 0; i < 3 && data[i + 1]; i++)
50  offsets[i] = data[i + 1] - data[i];
51  printf(", plane_offsets:");
52  for (i = 0; i < 3; i++)
54  printf(", total_size: %d", total_size);
55 
56  return 0;
57 }
58 
60 {
61  uint8_t *data[4];
62  ptrdiff_t linesizes1[4];
63  int ret, total_size, linesizes[4];
64 
65  ret = av_image_fill_linesizes(linesizes, pix_fmt, w);
66  if (ret < 0)
67  return ret;
68  total_size = av_image_alloc(data, linesizes, w, h, pix_fmt, 4);
69  if (total_size < 0) {
70  printf("alloc failure");
71  return total_size;
72  }
73  printf("total_size: %6d", total_size);
74  if (desc->flags & AV_PIX_FMT_FLAG_PAL)
75  total_size -= 256 * 4;
76  // Make it non-black by default...
77  memset(data[0], 0xA3, total_size);
78  for (int i = 0; i < 4; i++)
79  linesizes1[i] = linesizes[i];
80  for (enum AVColorRange range = 0; range < AVCOL_RANGE_NB; range++) {
81  ret = av_image_fill_black(data, linesizes1, pix_fmt, range, w, h);
82  printf(", black_%s_crc: ", av_color_range_name(range));
83  if (ret < 0) {
84  printf("----------");
85  } else {
87  printf("0x%08"PRIx32, av_crc(crc, 0, data[0], total_size));
88  }
89  }
90  av_freep(&data[0]);
91 
92  return 0;
93 }
94 
95 int main(void)
96 {
97  int64_t x, y;
98 
99  for (y = -1; y<UINT_MAX; y+= y/2 + 1) {
100  for (x = -1; x<UINT_MAX; x+= x/2 + 1) {
101  int ret = av_image_check_size(x, y, 0, NULL);
102  printf("%d", ret >= 0);
103  }
104  printf("\n");
105  }
106  printf("\n");
107 
108  for (int i = 0; i < 2; i++) {
109  printf(i ? "\nimage_fill_black tests\n" : "image_fill tests\n");
111  int w = 64, h = 48;
113 
114  if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
115  continue;
116 
117  printf("%-16s", desc->name);
118  if (i == 0)
120  else
122  printf("\n");
123  }
124  }
125 
126  return 0;
127 }
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AVCRC
uint32_t AVCRC
Definition: crc.h:46
w
uint8_t w
Definition: llviddspenc.c:38
check_image_fill_black
static int check_image_fill_black(const AVPixFmtDescriptor *desc, enum AVPixelFormat pix_fmt, int w, int h)
Definition: imgutils.c:59
data
const char data[16]
Definition: mxf.c:148
av_pix_fmt_desc_next
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
Definition: pixdesc.c:2975
crc.h
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:128
AVCOL_RANGE_NB
@ AVCOL_RANGE_NB
Not part of ABI.
Definition: pixfmt.h:688
imgutils.c
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:145
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
offsets
static const int offsets[]
Definition: hevc_pel.c:34
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demux_decode.c:41
av_color_range_name
const char * av_color_range_name(enum AVColorRange range)
Definition: pixdesc.c:3284
PTRDIFF_SPECIFIER
#define PTRDIFF_SPECIFIER
Definition: internal.h:140
NULL
#define NULL
Definition: coverity.c:32
sizes
static const int sizes[][2]
Definition: img2dec.c:58
av_image_fill_plane_sizes
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.
Definition: imgutils.c:111
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:218
av_image_fill_black
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.
Definition: imgutils.c:660
printf
printf("static const uint8_t my_array[100] = {\n")
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2646
av_crc_get_table
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
av_pix_fmt_desc_get_id
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
Definition: pixdesc.c:2987
check_image_fill
static int check_image_fill(enum AVPixelFormat pix_fmt, int w, int h)
Definition: imgutils.c:23
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
main
int main(void)
Definition: imgutils.c:95
ret
ret
Definition: filter_design.txt:187
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:141
av_crc
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
Definition: crc.c:392
AV_CRC_32_IEEE_LE
@ AV_CRC_32_IEEE_LE
Definition: crc.h:53
desc
const char * desc
Definition: libsvtav1.c:83
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
h
h
Definition: vp9dsp_template.c:2038
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:318
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:652
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:120