]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/imgconvert.c
Merge commit '79922d7237aba2b8c6abbd2e06a0c08e4f498ad4'
[ffmpeg] / libavcodec / imgconvert.c
index 27f179a943a3f7e5ad299bb574337444367e02c3..202fbf522ebbf56e878caa7c2e5c443072ab1a97 100644 (file)
@@ -33,7 +33,6 @@
 #include "avcodec.h"
 #include "dsputil.h"
 #include "internal.h"
-#include "imgconvert.h"
 #include "libavutil/colorspace.h"
 #include "libavutil/common.h"
 #include "libavutil/pixdesc.h"
@@ -65,349 +64,351 @@ typedef struct PixFmtInfo {
 } PixFmtInfo;
 
 /* this table gives more information about formats */
-static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
+static const PixFmtInfo pix_fmt_info[AV_PIX_FMT_NB] = {
     /* YUV formats */
-    [PIX_FMT_YUV420P] = {
+    [AV_PIX_FMT_YUV420P] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV422P] = {
+    [AV_PIX_FMT_YUV422P] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV444P] = {
+    [AV_PIX_FMT_YUV444P] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUYV422] = {
+    [AV_PIX_FMT_YUYV422] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_UYVY422] = {
+    [AV_PIX_FMT_UYVY422] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV410P] = {
+    [AV_PIX_FMT_YUV410P] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV411P] = {
+    [AV_PIX_FMT_YUV411P] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV440P] = {
+    [AV_PIX_FMT_YUV440P] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV420P9LE] = {
+    [AV_PIX_FMT_YUV420P9LE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV422P9LE] = {
+    [AV_PIX_FMT_YUV422P9LE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV444P9LE] = {
+    [AV_PIX_FMT_YUV444P9LE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV420P9BE] = {
+    [AV_PIX_FMT_YUV420P9BE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV422P9BE] = {
+    [AV_PIX_FMT_YUV422P9BE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV444P9BE] = {
+    [AV_PIX_FMT_YUV444P9BE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV420P10LE] = {
+    [AV_PIX_FMT_YUV420P10LE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV422P10LE] = {
+    [AV_PIX_FMT_YUV422P10LE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV444P10LE] = {
+    [AV_PIX_FMT_YUV444P10LE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV420P10BE] = {
+    [AV_PIX_FMT_YUV420P10BE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV422P10BE] = {
+    [AV_PIX_FMT_YUV422P10BE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV444P10BE] = {
+    [AV_PIX_FMT_YUV444P10BE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV420P12LE] = {
+    [AV_PIX_FMT_YUV420P12LE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV422P12LE] = {
+    [AV_PIX_FMT_YUV422P12LE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV444P12LE] = {
+    [AV_PIX_FMT_YUV444P12LE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV420P12BE] = {
+    [AV_PIX_FMT_YUV420P12BE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV422P12BE] = {
+    [AV_PIX_FMT_YUV422P12BE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV444P12BE] = {
+    [AV_PIX_FMT_YUV444P12BE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV420P14LE] = {
+    [AV_PIX_FMT_YUV420P14LE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV422P14LE] = {
+    [AV_PIX_FMT_YUV422P14LE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV444P14LE] = {
+    [AV_PIX_FMT_YUV444P14LE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV420P14BE] = {
+    [AV_PIX_FMT_YUV420P14BE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV422P14BE] = {
+    [AV_PIX_FMT_YUV422P14BE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV444P14BE] = {
+    [AV_PIX_FMT_YUV444P14BE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV420P16LE] = {
+    [AV_PIX_FMT_YUV420P16LE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV422P16LE] = {
+    [AV_PIX_FMT_YUV422P16LE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV444P16LE] = {
+    [AV_PIX_FMT_YUV444P16LE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV420P16BE] = {
+    [AV_PIX_FMT_YUV420P16BE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV422P16BE] = {
+    [AV_PIX_FMT_YUV422P16BE] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_YUV444P16BE] = {
+    [AV_PIX_FMT_YUV444P16BE] = {
         .color_type = FF_COLOR_YUV,
     },
 
     /* YUV formats with alpha plane */
-    [PIX_FMT_YUVA420P] = {
+    [AV_PIX_FMT_YUVA420P] = {
         .color_type = FF_COLOR_YUV,
     },
 
-    [PIX_FMT_YUVA422P] = {
+    [AV_PIX_FMT_YUVA422P] = {
         .color_type = FF_COLOR_YUV,
     },
 
-    [PIX_FMT_YUVA444P] = {
+    [AV_PIX_FMT_YUVA444P] = {
         .color_type = FF_COLOR_YUV,
     },
 
     /* JPEG YUV */
-    [PIX_FMT_YUVJ420P] = {
+    [AV_PIX_FMT_YUVJ420P] = {
         .color_type = FF_COLOR_YUV_JPEG,
     },
-    [PIX_FMT_YUVJ422P] = {
+    [AV_PIX_FMT_YUVJ422P] = {
         .color_type = FF_COLOR_YUV_JPEG,
     },
-    [PIX_FMT_YUVJ444P] = {
+    [AV_PIX_FMT_YUVJ444P] = {
         .color_type = FF_COLOR_YUV_JPEG,
     },
-    [PIX_FMT_YUVJ440P] = {
+    [AV_PIX_FMT_YUVJ440P] = {
         .color_type = FF_COLOR_YUV_JPEG,
     },
 
     /* RGB formats */
-    [PIX_FMT_RGB24] = {
+    [AV_PIX_FMT_RGB24] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_BGR24] = {
+    [AV_PIX_FMT_BGR24] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_ARGB] = {
+    [AV_PIX_FMT_ARGB] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_RGB48BE] = {
+    [AV_PIX_FMT_RGB48BE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_RGB48LE] = {
+    [AV_PIX_FMT_RGB48LE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_RGBA64BE] = {
+    [AV_PIX_FMT_RGBA64BE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_RGBA64LE] = {
+    [AV_PIX_FMT_RGBA64LE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_RGB565BE] = {
+    [AV_PIX_FMT_RGB565BE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_RGB565LE] = {
+    [AV_PIX_FMT_RGB565LE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_RGB555BE] = {
+    [AV_PIX_FMT_RGB555BE] = {
         .color_type = FF_COLOR_RGB,
         .padded_size = 16,
     },
-    [PIX_FMT_RGB555LE] = {
+    [AV_PIX_FMT_RGB555LE] = {
         .color_type = FF_COLOR_RGB,
         .padded_size = 16,
     },
-    [PIX_FMT_RGB444BE] = {
+    [AV_PIX_FMT_RGB444BE] = {
         .color_type = FF_COLOR_RGB,
         .padded_size = 16,
     },
-    [PIX_FMT_RGB444LE] = {
+    [AV_PIX_FMT_RGB444LE] = {
         .color_type = FF_COLOR_RGB,
         .padded_size = 16,
     },
 
     /* gray / mono formats */
-    [PIX_FMT_GRAY16BE] = {
+    [AV_PIX_FMT_GRAY16BE] = {
         .color_type = FF_COLOR_GRAY,
     },
-    [PIX_FMT_GRAY16LE] = {
+    [AV_PIX_FMT_GRAY16LE] = {
         .color_type = FF_COLOR_GRAY,
     },
-    [PIX_FMT_GRAY8] = {
+    [AV_PIX_FMT_GRAY8] = {
         .color_type = FF_COLOR_GRAY,
     },
-    [PIX_FMT_GRAY8A] = {
+    [AV_PIX_FMT_GRAY8A] = {
         .color_type = FF_COLOR_GRAY,
     },
-    [PIX_FMT_MONOWHITE] = {
+    [AV_PIX_FMT_MONOWHITE] = {
         .color_type = FF_COLOR_GRAY,
     },
-    [PIX_FMT_MONOBLACK] = {
+    [AV_PIX_FMT_MONOBLACK] = {
         .color_type = FF_COLOR_GRAY,
     },
 
     /* paletted formats */
-    [PIX_FMT_PAL8] = {
+    [AV_PIX_FMT_PAL8] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_UYYVYY411] = {
+    [AV_PIX_FMT_UYYVYY411] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_ABGR] = {
+    [AV_PIX_FMT_ABGR] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_BGR48BE] = {
+    [AV_PIX_FMT_BGR48BE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_BGR48LE] = {
+    [AV_PIX_FMT_BGR48LE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_BGRA64BE] = {
+    [AV_PIX_FMT_BGRA64BE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_BGRA64LE] = {
+    [AV_PIX_FMT_BGRA64LE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_BGR565BE] = {
+    [AV_PIX_FMT_BGR565BE] = {
         .color_type = FF_COLOR_RGB,
         .padded_size = 16,
     },
-    [PIX_FMT_BGR565LE] = {
+    [AV_PIX_FMT_BGR565LE] = {
         .color_type = FF_COLOR_RGB,
         .padded_size = 16,
     },
-    [PIX_FMT_BGR555BE] = {
+    [AV_PIX_FMT_BGR555BE] = {
         .color_type = FF_COLOR_RGB,
         .padded_size = 16,
     },
-    [PIX_FMT_BGR555LE] = {
+    [AV_PIX_FMT_BGR555LE] = {
         .color_type = FF_COLOR_RGB,
         .padded_size = 16,
     },
-    [PIX_FMT_BGR444BE] = {
+    [AV_PIX_FMT_BGR444BE] = {
         .color_type = FF_COLOR_RGB,
         .padded_size = 16,
     },
-    [PIX_FMT_BGR444LE] = {
+    [AV_PIX_FMT_BGR444LE] = {
         .color_type = FF_COLOR_RGB,
         .padded_size = 16,
     },
-    [PIX_FMT_RGB8] = {
+    [AV_PIX_FMT_RGB8] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_RGB4] = {
+    [AV_PIX_FMT_RGB4] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_RGB4_BYTE] = {
+    [AV_PIX_FMT_RGB4_BYTE] = {
         .color_type = FF_COLOR_RGB,
         .padded_size = 8,
     },
-    [PIX_FMT_BGR8] = {
+    [AV_PIX_FMT_BGR8] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_BGR4] = {
+    [AV_PIX_FMT_BGR4] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_BGR4_BYTE] = {
+    [AV_PIX_FMT_BGR4_BYTE] = {
         .color_type = FF_COLOR_RGB,
         .padded_size = 8,
     },
-    [PIX_FMT_NV12] = {
+    [AV_PIX_FMT_NV12] = {
         .color_type = FF_COLOR_YUV,
     },
-    [PIX_FMT_NV21] = {
+    [AV_PIX_FMT_NV21] = {
         .color_type = FF_COLOR_YUV,
     },
 
-    [PIX_FMT_BGRA] = {
+    [AV_PIX_FMT_BGRA] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_RGBA] = {
+    [AV_PIX_FMT_RGBA] = {
         .color_type = FF_COLOR_RGB,
     },
 
-    [PIX_FMT_GBRP] = {
+    [AV_PIX_FMT_GBRP] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_GBRP9BE] = {
+    [AV_PIX_FMT_GBRP9BE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_GBRP9LE] = {
+    [AV_PIX_FMT_GBRP9LE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_GBRP10BE] = {
+    [AV_PIX_FMT_GBRP10BE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_GBRP10LE] = {
+    [AV_PIX_FMT_GBRP10LE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_GBRP12BE] = {
+    [AV_PIX_FMT_GBRP12BE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_GBRP12LE] = {
+    [AV_PIX_FMT_GBRP12LE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_GBRP14BE] = {
+    [AV_PIX_FMT_GBRP14BE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_GBRP14LE] = {
+    [AV_PIX_FMT_GBRP14LE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_GBRP16BE] = {
+    [AV_PIX_FMT_GBRP16BE] = {
         .color_type = FF_COLOR_RGB,
     },
-    [PIX_FMT_GBRP16LE] = {
+    [AV_PIX_FMT_GBRP16LE] = {
         .color_type = FF_COLOR_RGB,
     },
 };
 
-void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift)
+void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
 {
-    *h_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_w;
-    *v_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
+    *h_shift = desc->log2_chroma_w;
+    *v_shift = desc->log2_chroma_h;
 }
 
-int ff_is_hwaccel_pix_fmt(enum PixelFormat pix_fmt)
+int ff_is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)
 {
-    return av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_HWACCEL;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
+    return desc->flags & PIX_FMT_HWACCEL;
 }
 
 int avpicture_fill(AVPicture *picture, uint8_t *ptr,
-                   enum PixelFormat pix_fmt, int width, int height)
+                   enum AVPixelFormat pix_fmt, int width, int height)
 {
     return av_image_fill_arrays(picture->data, picture->linesize,
                                 ptr, pix_fmt, width, height, 1);
 }
 
-int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width, int height,
+int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt, int width, int height,
                      unsigned char *dest, int dest_size)
 {
     return av_image_copy_to_buffer(dest, dest_size,
@@ -415,17 +416,17 @@ int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width,
                                    pix_fmt, width, height, 1);
 }
 
-int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height)
+int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height)
 {
     return av_image_get_buffer_size(pix_fmt, width, height, 1);
 }
 
-static int get_pix_fmt_depth(int *min, int *max, enum PixelFormat pix_fmt)
+static int get_pix_fmt_depth(int *min, int *max, enum AVPixelFormat pix_fmt)
 {
-    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     int i;
 
-    if (!desc->nb_components) {
+    if (!desc || !desc->nb_components) {
         *min = *max = 0;
         return AVERROR(EINVAL);
     }
@@ -438,20 +439,18 @@ static int get_pix_fmt_depth(int *min, int *max, enum PixelFormat pix_fmt)
     return 0;
 }
 
-int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_pix_fmt,
+int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt, enum AVPixelFormat src_pix_fmt,
                              int has_alpha)
 {
     const PixFmtInfo *pf, *ps;
-    const AVPixFmtDescriptor *src_desc;
-    const AVPixFmtDescriptor *dst_desc;
+    const AVPixFmtDescriptor *src_desc = av_pix_fmt_desc_get(src_pix_fmt);
+    const AVPixFmtDescriptor *dst_desc = av_pix_fmt_desc_get(dst_pix_fmt);
     int src_min_depth, src_max_depth, dst_min_depth, dst_max_depth;
     int ret, loss;
 
-    if (dst_pix_fmt >= PIX_FMT_NB || dst_pix_fmt <= PIX_FMT_NONE)
+    if (dst_pix_fmt >= AV_PIX_FMT_NB || dst_pix_fmt <= AV_PIX_FMT_NONE)
         return ~0;
 
-    src_desc = &av_pix_fmt_descriptors[src_pix_fmt];
-    dst_desc = &av_pix_fmt_descriptors[dst_pix_fmt];
     ps = &pix_fmt_info[src_pix_fmt];
 
     /* compute loss */
@@ -500,34 +499,34 @@ int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_
         loss |= FF_LOSS_CHROMA;
     if (!pixdesc_has_alpha(dst_desc) && (pixdesc_has_alpha(src_desc) && has_alpha))
         loss |= FF_LOSS_ALPHA;
-    if (dst_pix_fmt == PIX_FMT_PAL8 &&
-        (src_pix_fmt != PIX_FMT_PAL8 && (ps->color_type != FF_COLOR_GRAY || (pixdesc_has_alpha(src_desc) && has_alpha))))
+    if (dst_pix_fmt == AV_PIX_FMT_PAL8 &&
+        (src_pix_fmt != AV_PIX_FMT_PAL8 && (ps->color_type != FF_COLOR_GRAY || (pixdesc_has_alpha(src_desc) && has_alpha))))
         loss |= FF_LOSS_COLORQUANT;
 
     return loss;
 }
 
-static int avg_bits_per_pixel(enum PixelFormat pix_fmt)
+static int avg_bits_per_pixel(enum AVPixelFormat pix_fmt)
 {
     const PixFmtInfo *info = &pix_fmt_info[pix_fmt];
-    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
 
     return info->padded_size ?
         info->padded_size : av_get_bits_per_pixel(desc);
 }
 
 #if FF_API_FIND_BEST_PIX_FMT
-enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt,
+enum AVPixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum AVPixelFormat src_pix_fmt,
                                             int has_alpha, int *loss_ptr)
 {
-    enum PixelFormat dst_pix_fmt;
+    enum AVPixelFormat dst_pix_fmt;
     int i;
 
     if (loss_ptr) /* all losses count (for backward compatibility) */
         *loss_ptr = 0;
 
-    dst_pix_fmt = PIX_FMT_NONE; /* so first iteration doesn't have to be treated special */
-    for(i = 0; i< FFMIN(PIX_FMT_NB, 64); i++){
+    dst_pix_fmt = AV_PIX_FMT_NONE; /* so first iteration doesn't have to be treated special */
+    for(i = 0; i< FFMIN(AV_PIX_FMT_NB, 64); i++){
         if (pix_fmt_mask & (1ULL << i))
             dst_pix_fmt = avcodec_find_best_pix_fmt_of_2(dst_pix_fmt, i, src_pix_fmt, has_alpha, loss_ptr);
     }
@@ -535,10 +534,10 @@ enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelForma
 }
 #endif /* FF_API_FIND_BEST_PIX_FMT */
 
-enum PixelFormat avcodec_find_best_pix_fmt_of_2(enum PixelFormat dst_pix_fmt1, enum PixelFormat dst_pix_fmt2,
-                                            enum PixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
+enum AVPixelFormat avcodec_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2,
+                                            enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
 {
-    enum PixelFormat dst_pix_fmt;
+    enum AVPixelFormat dst_pix_fmt;
     int loss1, loss2, loss_order1, loss_order2, i, loss_mask;
     static const int loss_mask_order[] = {
         ~0, /* no loss first */
@@ -556,16 +555,16 @@ enum PixelFormat avcodec_find_best_pix_fmt_of_2(enum PixelFormat dst_pix_fmt1, e
     };
 
     loss_mask= loss_ptr?~*loss_ptr:~0; /* use loss mask if provided */
-    dst_pix_fmt = PIX_FMT_NONE;
+    dst_pix_fmt = AV_PIX_FMT_NONE;
     loss1 = avcodec_get_pix_fmt_loss(dst_pix_fmt1, src_pix_fmt, has_alpha) & loss_mask;
     loss2 = avcodec_get_pix_fmt_loss(dst_pix_fmt2, src_pix_fmt, has_alpha) & loss_mask;
 
     /* try with successive loss */
-    for(i = 0;loss_mask_order[i] != 0 && dst_pix_fmt == PIX_FMT_NONE;i++) {
+    for(i = 0;loss_mask_order[i] != 0 && dst_pix_fmt == AV_PIX_FMT_NONE;i++) {
         loss_order1 = loss1 & loss_mask_order[i];
         loss_order2 = loss2 & loss_mask_order[i];
 
-        if (loss_order1 == 0 && loss_order2 == 0){ /* use format with smallest depth */
+        if (loss_order1 == 0 && loss_order2 == 0 && dst_pix_fmt2 != AV_PIX_FMT_NONE && dst_pix_fmt1 != AV_PIX_FMT_NONE){ /* use format with smallest depth */
             dst_pix_fmt = avg_bits_per_pixel(dst_pix_fmt2) < avg_bits_per_pixel(dst_pix_fmt1) ? dst_pix_fmt2 : dst_pix_fmt1;
         } else if (loss_order1 == 0 || loss_order2 == 0) { /* use format with no loss */
             dst_pix_fmt = loss_order2 ? dst_pix_fmt1 : dst_pix_fmt2;
@@ -578,34 +577,34 @@ enum PixelFormat avcodec_find_best_pix_fmt_of_2(enum PixelFormat dst_pix_fmt1, e
 }
 
 #if AV_HAVE_INCOMPATIBLE_FORK_ABI
-enum PixelFormat avcodec_find_best_pix_fmt2(enum PixelFormat *pix_fmt_list,
-                                            enum PixelFormat src_pix_fmt,
+enum AVPixelFormat avcodec_find_best_pix_fmt2(enum AVPixelFormat *pix_fmt_list,
+                                            enum AVPixelFormat src_pix_fmt,
                                             int has_alpha, int *loss_ptr){
     return avcodec_find_best_pix_fmt_of_list(pix_fmt_list, src_pix_fmt, has_alpha, loss_ptr);
 }
 #else
-enum PixelFormat avcodec_find_best_pix_fmt2(enum PixelFormat dst_pix_fmt1, enum PixelFormat dst_pix_fmt2,
-                                            enum PixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
+enum AVPixelFormat avcodec_find_best_pix_fmt2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2,
+                                            enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
 {
     return avcodec_find_best_pix_fmt_of_2(dst_pix_fmt1, dst_pix_fmt2, src_pix_fmt, has_alpha, loss_ptr);
 }
 #endif
 
-enum PixelFormat avcodec_find_best_pix_fmt_of_list(enum PixelFormat *pix_fmt_list,
-                                            enum PixelFormat src_pix_fmt,
+enum AVPixelFormat avcodec_find_best_pix_fmt_of_list(enum AVPixelFormat *pix_fmt_list,
+                                            enum AVPixelFormat src_pix_fmt,
                                             int has_alpha, int *loss_ptr){
     int i;
 
-    enum PixelFormat best = PIX_FMT_NONE;
+    enum AVPixelFormat best = AV_PIX_FMT_NONE;
 
-    for(i=0; pix_fmt_list[i] != PIX_FMT_NONE; i++)
+    for(i=0; pix_fmt_list[i] != AV_PIX_FMT_NONE; i++)
         best = avcodec_find_best_pix_fmt_of_2(best, pix_fmt_list[i], src_pix_fmt, has_alpha, loss_ptr);
 
     return best;
 }
 
 void av_picture_copy(AVPicture *dst, const AVPicture *src,
-                     enum PixelFormat pix_fmt, int width, int height)
+                     enum AVPixelFormat pix_fmt, int width, int height)
 {
     av_image_copy(dst->data, dst->linesize, (const uint8_t **)src->data,
                   src->linesize, pix_fmt, width, height);
@@ -699,7 +698,7 @@ void ff_shrink88(uint8_t *dst, int dst_wrap,
 
 
 int avpicture_alloc(AVPicture *picture,
-                    enum PixelFormat pix_fmt, int width, int height)
+                    enum AVPixelFormat pix_fmt, int width, int height)
 {
     int ret;
 
@@ -717,10 +716,10 @@ void avpicture_free(AVPicture *picture)
 }
 
 /* return true if yuv planar */
-static inline int is_yuv_planar(enum PixelFormat fmt)
+static inline int is_yuv_planar(enum AVPixelFormat fmt)
 {
     const PixFmtInfo         *info = &pix_fmt_info[fmt];
-    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[fmt];
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
     int i;
     int planes[4] = { 0 };
 
@@ -740,16 +739,17 @@ static inline int is_yuv_planar(enum PixelFormat fmt)
 }
 
 int av_picture_crop(AVPicture *dst, const AVPicture *src,
-                    enum PixelFormat pix_fmt, int top_band, int left_band)
+                    enum AVPixelFormat pix_fmt, int top_band, int left_band)
 {
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     int y_shift;
     int x_shift;
 
-    if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB)
+    if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)
         return -1;
 
-    y_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h;
-    x_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_w;
+    y_shift = desc->log2_chroma_h;
+    x_shift = desc->log2_chroma_w;
 
     if (is_yuv_planar(pix_fmt)) {
     dst->data[0] = src->data[0] + (top_band * src->linesize[0]) + left_band;
@@ -770,21 +770,22 @@ int av_picture_crop(AVPicture *dst, const AVPicture *src,
 }
 
 int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width,
-                   enum PixelFormat pix_fmt, int padtop, int padbottom, int padleft, int padright,
+                   enum AVPixelFormat pix_fmt, int padtop, int padbottom, int padleft, int padright,
             int *color)
 {
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     uint8_t *optr;
     int y_shift;
     int x_shift;
     int yheight;
     int i, y;
 
-    if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB ||
+    if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB ||
         !is_yuv_planar(pix_fmt)) return -1;
 
     for (i = 0; i < 3; i++) {
-        x_shift = i ? av_pix_fmt_descriptors[pix_fmt].log2_chroma_w : 0;
-        y_shift = i ? av_pix_fmt_descriptors[pix_fmt].log2_chroma_h : 0;
+        x_shift = i ? desc->log2_chroma_w : 0;
+        y_shift = i ? desc->log2_chroma_h : 0;
 
         if (padtop || padleft) {
             memset(dst->data[i], color[i],
@@ -938,17 +939,17 @@ static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,
 }
 
 int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
-                          enum PixelFormat pix_fmt, int width, int height)
+                          enum AVPixelFormat pix_fmt, int width, int height)
 {
     int i;
 
-    if (pix_fmt != PIX_FMT_YUV420P &&
-        pix_fmt != PIX_FMT_YUVJ420P &&
-        pix_fmt != PIX_FMT_YUV422P &&
-        pix_fmt != PIX_FMT_YUVJ422P &&
-        pix_fmt != PIX_FMT_YUV444P &&
-        pix_fmt != PIX_FMT_YUV411P &&
-        pix_fmt != PIX_FMT_GRAY8)
+    if (pix_fmt != AV_PIX_FMT_YUV420P &&
+        pix_fmt != AV_PIX_FMT_YUVJ420P &&
+        pix_fmt != AV_PIX_FMT_YUV422P &&
+        pix_fmt != AV_PIX_FMT_YUVJ422P &&
+        pix_fmt != AV_PIX_FMT_YUV444P &&
+        pix_fmt != AV_PIX_FMT_YUV411P &&
+        pix_fmt != AV_PIX_FMT_GRAY8)
         return -1;
     if ((width & 3) != 0 || (height & 3) != 0)
         return -1;
@@ -956,22 +957,22 @@ int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
     for(i=0;i<3;i++) {
         if (i == 1) {
             switch(pix_fmt) {
-            case PIX_FMT_YUVJ420P:
-            case PIX_FMT_YUV420P:
+            case AV_PIX_FMT_YUVJ420P:
+            case AV_PIX_FMT_YUV420P:
                 width >>= 1;
                 height >>= 1;
                 break;
-            case PIX_FMT_YUV422P:
-            case PIX_FMT_YUVJ422P:
+            case AV_PIX_FMT_YUV422P:
+            case AV_PIX_FMT_YUVJ422P:
                 width >>= 1;
                 break;
-            case PIX_FMT_YUV411P:
+            case AV_PIX_FMT_YUV411P:
                 width >>= 2;
                 break;
             default:
                 break;
             }
-            if (pix_fmt == PIX_FMT_GRAY8) {
+            if (pix_fmt == AV_PIX_FMT_GRAY8) {
                 break;
             }
         }