aboutsummaryrefslogtreecommitdiff
path: root/libavutil/imgutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavutil/imgutils.c')
-rw-r--r--libavutil/imgutils.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
index fdc07f87a7..e661e1bf8d 100644
--- a/libavutil/imgutils.c
+++ b/libavutil/imgutils.c
@@ -47,11 +47,14 @@ void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4],
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
{
- const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
int max_step [4]; /* max pixel step for each plane */
int max_step_comp[4]; /* the component for each plane which has the max pixel step */
int s;
+ if (!desc)
+ return AVERROR(EINVAL);
+
if (desc->flags & PIX_FMT_BITSTREAM)
return (width * (desc->comp[0].step_minus1+1) + 7) >> 3;
@@ -63,13 +66,13 @@ int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
{
int i;
- const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
int max_step [4]; /* max pixel step for each plane */
int max_step_comp[4]; /* the component for each plane which has the max pixel step */
memset(linesizes, 0, 4*sizeof(linesizes[0]));
- if ((unsigned)pix_fmt >= AV_PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL)
+ if (!desc || desc->flags & PIX_FMT_HWACCEL)
return AVERROR(EINVAL);
if (desc->flags & PIX_FMT_BITSTREAM) {
@@ -96,10 +99,10 @@ int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int hei
{
int i, total_size, size[4] = { 0 }, has_plane[4] = { 0 };
- const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
memset(data , 0, sizeof(data[0])*4);
- if ((unsigned)pix_fmt >= AV_PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL)
+ if (!desc || desc->flags & PIX_FMT_HWACCEL)
return AVERROR(EINVAL);
data[0] = ptr;
@@ -176,9 +179,13 @@ int ff_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
int w, int h, enum AVPixelFormat pix_fmt, int align)
{
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
int i, ret;
uint8_t *buf;
+ if (!desc)
+ return AVERROR(EINVAL);
+
if ((ret = av_image_check_size(w, h, 0, NULL)) < 0)
return ret;
if ((ret = av_image_fill_linesizes(linesizes, pix_fmt, w)) < 0)
@@ -196,8 +203,7 @@ int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
av_free(buf);
return ret;
}
- if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_PAL ||
- av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_PSEUDOPAL)
+ if (desc->flags & PIX_FMT_PAL || desc->flags & PIX_FMT_PSEUDOPAL)
ff_set_systematic_pal2((uint32_t*)pointers[1], pix_fmt);
return ret;
@@ -239,9 +245,9 @@ 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)
{
- const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
- if (desc->flags & PIX_FMT_HWACCEL)
+ if (!desc || desc->flags & PIX_FMT_HWACCEL)
return;
if (desc->flags & PIX_FMT_PAL ||