[FFmpeg-devel] [PATCH] imgconvert: move pix_fmt_info array to internal pixcolorinfo.[hc] files in lavu
Stefano Sabatini
stefano.sabatini-lala at poste.it
Sun Jul 24 01:59:49 CEST 2011
This way this information can be used in libswscale/libavfilter,
avoiding code duplication.
---
libavcodec/imgconvert.c | 272 +--------------------------------------------
libavutil/Makefile | 1 +
libavutil/pixcolorinfo.c | 274 ++++++++++++++++++++++++++++++++++++++++++++++
libavutil/pixcolorinfo.h | 45 ++++++++
4 files changed, 326 insertions(+), 266 deletions(-)
create mode 100644 libavutil/pixcolorinfo.c
create mode 100644 libavutil/pixcolorinfo.h
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 35dc6d8..87b21ac 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -36,17 +36,13 @@
#include "imgconvert.h"
#include "libavutil/colorspace.h"
#include "libavutil/pixdesc.h"
+#include "libavutil/pixcolorinfo.h"
#include "libavutil/imgutils.h"
#if HAVE_MMX && HAVE_YASM
#include "x86/dsputil_mmx.h"
#endif
-#define FF_COLOR_RGB 0 /**< RGB color space */
-#define FF_COLOR_GRAY 1 /**< gray color space */
-#define FF_COLOR_YUV 2 /**< YUV color space. 16 <= Y <= 235, 16 <= U, V <= 240 */
-#define FF_COLOR_YUV_JPEG 3 /**< YUV color space. 0 <= Y <= 255, 0 <= U, V <= 255 */
-
#if HAVE_MMX && HAVE_YASM
#define deinterlace_line_inplace ff_deinterlace_line_inplace_mmx
#define deinterlace_line ff_deinterlace_line_mmx
@@ -55,262 +51,6 @@
#define deinterlace_line deinterlace_line_c
#endif
-typedef struct PixFmtInfo {
- uint8_t color_type; /**< color type (see FF_COLOR_xxx constants) */
- uint8_t is_alpha : 1; /**< true if alpha can be specified */
- uint8_t depth; /**< bit depth of the color components */
- uint8_t padded_size; /**< padded size in bits if different from the non-padded size */
-} PixFmtInfo;
-
-/* this table gives more information about formats */
-static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
- /* YUV formats */
- [PIX_FMT_YUV420P] = {
- .color_type = FF_COLOR_YUV,
- .depth = 8,
- },
- [PIX_FMT_YUV422P] = {
- .color_type = FF_COLOR_YUV,
- .depth = 8,
- },
- [PIX_FMT_YUV444P] = {
- .color_type = FF_COLOR_YUV,
- .depth = 8,
- },
- [PIX_FMT_YUYV422] = {
- .color_type = FF_COLOR_YUV,
- .depth = 8,
- },
- [PIX_FMT_UYVY422] = {
- .color_type = FF_COLOR_YUV,
- .depth = 8,
- },
- [PIX_FMT_YUV410P] = {
- .color_type = FF_COLOR_YUV,
- .depth = 8,
- },
- [PIX_FMT_YUV411P] = {
- .color_type = FF_COLOR_YUV,
- .depth = 8,
- },
- [PIX_FMT_YUV440P] = {
- .color_type = FF_COLOR_YUV,
- .depth = 8,
- },
- [PIX_FMT_YUV420P16LE] = {
- .color_type = FF_COLOR_YUV,
- .depth = 16,
- },
- [PIX_FMT_YUV422P16LE] = {
- .color_type = FF_COLOR_YUV,
- .depth = 16,
- },
- [PIX_FMT_YUV444P16LE] = {
- .color_type = FF_COLOR_YUV,
- .depth = 16,
- },
- [PIX_FMT_YUV420P16BE] = {
- .color_type = FF_COLOR_YUV,
- .depth = 16,
- },
- [PIX_FMT_YUV422P16BE] = {
- .color_type = FF_COLOR_YUV,
- .depth = 16,
- },
- [PIX_FMT_YUV444P16BE] = {
- .color_type = FF_COLOR_YUV,
- .depth = 16,
- },
-
- /* YUV formats with alpha plane */
- [PIX_FMT_YUVA420P] = {
- .color_type = FF_COLOR_YUV,
- .depth = 8,
- },
-
- /* JPEG YUV */
- [PIX_FMT_YUVJ420P] = {
- .color_type = FF_COLOR_YUV_JPEG,
- .depth = 8,
- },
- [PIX_FMT_YUVJ422P] = {
- .color_type = FF_COLOR_YUV_JPEG,
- .depth = 8,
- },
- [PIX_FMT_YUVJ444P] = {
- .color_type = FF_COLOR_YUV_JPEG,
- .depth = 8,
- },
- [PIX_FMT_YUVJ440P] = {
- .color_type = FF_COLOR_YUV_JPEG,
- .depth = 8,
- },
-
- /* RGB formats */
- [PIX_FMT_RGB24] = {
- .color_type = FF_COLOR_RGB,
- .depth = 8,
- },
- [PIX_FMT_BGR24] = {
- .color_type = FF_COLOR_RGB,
- .depth = 8,
- },
- [PIX_FMT_ARGB] = {
- .is_alpha = 1,
- .color_type = FF_COLOR_RGB,
- .depth = 8,
- },
- [PIX_FMT_RGB48BE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 16,
- },
- [PIX_FMT_RGB48LE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 16,
- },
- [PIX_FMT_RGB565BE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 5,
- },
- [PIX_FMT_RGB565LE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 5,
- },
- [PIX_FMT_RGB555BE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 5,
- .padded_size = 16,
- },
- [PIX_FMT_RGB555LE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 5,
- .padded_size = 16,
- },
- [PIX_FMT_RGB444BE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 4,
- .padded_size = 16,
- },
- [PIX_FMT_RGB444LE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 4,
- .padded_size = 16,
- },
-
- /* gray / mono formats */
- [PIX_FMT_GRAY16BE] = {
- .color_type = FF_COLOR_GRAY,
- .depth = 16,
- },
- [PIX_FMT_GRAY16LE] = {
- .color_type = FF_COLOR_GRAY,
- .depth = 16,
- },
- [PIX_FMT_GRAY8] = {
- .color_type = FF_COLOR_GRAY,
- .depth = 8,
- },
- [PIX_FMT_MONOWHITE] = {
- .color_type = FF_COLOR_GRAY,
- .depth = 1,
- },
- [PIX_FMT_MONOBLACK] = {
- .color_type = FF_COLOR_GRAY,
- .depth = 1,
- },
-
- /* paletted formats */
- [PIX_FMT_PAL8] = {
- .is_alpha = 1,
- .color_type = FF_COLOR_RGB,
- .depth = 8,
- },
- [PIX_FMT_UYYVYY411] = {
- .color_type = FF_COLOR_YUV,
- .depth = 8,
- },
- [PIX_FMT_ABGR] = {
- .is_alpha = 1,
- .color_type = FF_COLOR_RGB,
- .depth = 8,
- },
- [PIX_FMT_BGR565BE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 5,
- .padded_size = 16,
- },
- [PIX_FMT_BGR565LE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 5,
- .padded_size = 16,
- },
- [PIX_FMT_BGR555BE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 5,
- .padded_size = 16,
- },
- [PIX_FMT_BGR555LE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 5,
- .padded_size = 16,
- },
- [PIX_FMT_BGR444BE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 4,
- .padded_size = 16,
- },
- [PIX_FMT_BGR444LE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 4,
- .padded_size = 16,
- },
- [PIX_FMT_RGB8] = {
- .color_type = FF_COLOR_RGB,
- .depth = 8,
- },
- [PIX_FMT_RGB4] = {
- .color_type = FF_COLOR_RGB,
- .depth = 4,
- },
- [PIX_FMT_RGB4_BYTE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 8,
- .padded_size = 8,
- },
- [PIX_FMT_BGR8] = {
- .color_type = FF_COLOR_RGB,
- .depth = 8,
- },
- [PIX_FMT_BGR4] = {
- .color_type = FF_COLOR_RGB,
- .depth = 4,
- },
- [PIX_FMT_BGR4_BYTE] = {
- .color_type = FF_COLOR_RGB,
- .depth = 8,
- .padded_size = 8,
- },
- [PIX_FMT_NV12] = {
- .color_type = FF_COLOR_YUV,
- .depth = 8,
- },
- [PIX_FMT_NV21] = {
- .color_type = FF_COLOR_YUV,
- .depth = 8,
- },
-
- [PIX_FMT_BGRA] = {
- .is_alpha = 1,
- .color_type = FF_COLOR_RGB,
- .depth = 8,
- },
- [PIX_FMT_RGBA] = {
- .is_alpha = 1,
- .color_type = FF_COLOR_RGB,
- .depth = 8,
- },
-};
-
void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift)
{
*h_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_w;
@@ -401,11 +141,11 @@ int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_
const AVPixFmtDescriptor *dst_desc = &av_pix_fmt_descriptors[dst_pix_fmt];
int loss;
- ps = &pix_fmt_info[src_pix_fmt];
+ ps = &ff_pix_fmt_info[src_pix_fmt];
/* compute loss */
loss = 0;
- pf = &pix_fmt_info[dst_pix_fmt];
+ pf = &ff_pix_fmt_info[dst_pix_fmt];
if (pf->depth < ps->depth ||
((dst_pix_fmt == PIX_FMT_RGB555BE || dst_pix_fmt == PIX_FMT_RGB555LE ||
dst_pix_fmt == PIX_FMT_BGR555BE || dst_pix_fmt == PIX_FMT_BGR555LE) &&
@@ -454,7 +194,7 @@ int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_
static int avg_bits_per_pixel(enum PixelFormat pix_fmt)
{
- const PixFmtInfo *info = &pix_fmt_info[pix_fmt];
+ const PixFmtInfo *info = &ff_pix_fmt_info[pix_fmt];
const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
return info->padded_size ?
@@ -635,7 +375,7 @@ void avpicture_free(AVPicture *picture)
/* return true if yuv planar */
static inline int is_yuv_planar(enum PixelFormat fmt)
{
- const PixFmtInfo *info = &pix_fmt_info[fmt];
+ const PixFmtInfo *info = &ff_pix_fmt_info[fmt];
const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[fmt];
int i;
int planes[4] = { 0 };
@@ -774,7 +514,7 @@ static int get_alpha_info_pal8(const AVPicture *src, int width, int height)
int img_get_alpha_info(const AVPicture *src,
enum PixelFormat pix_fmt, int width, int height)
{
- const PixFmtInfo *pf = &pix_fmt_info[pix_fmt];
+ const PixFmtInfo *pf = &ff_pix_fmt_info[pix_fmt];
int ret;
/* no alpha can be represented in format */
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 5ff5cb8..5bea360 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -64,6 +64,7 @@ OBJS = adler32.o \
dict.o \
opt.o \
parseutils.o \
+ pixcolorinfo.o \
pixdesc.o \
random_seed.o \
rational.o \
diff --git a/libavutil/pixcolorinfo.c b/libavutil/pixcolorinfo.c
new file mode 100644
index 0000000..82a0472
--- /dev/null
+++ b/libavutil/pixcolorinfo.c
@@ -0,0 +1,274 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * misc struct used to contain pixel format colorspace informations.
+ * Ported from libavcodec/imgconvert.c.
+ */
+
+#include "pixcolorinfo.h"
+
+/* this table gives more information about formats */
+const PixFmtInfo ff_pix_fmt_info[PIX_FMT_NB] = {
+ /* YUV formats */
+ [PIX_FMT_YUV420P] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 8,
+ },
+ [PIX_FMT_YUV422P] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 8,
+ },
+ [PIX_FMT_YUV444P] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 8,
+ },
+ [PIX_FMT_YUYV422] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 8,
+ },
+ [PIX_FMT_UYVY422] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 8,
+ },
+ [PIX_FMT_YUV410P] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 8,
+ },
+ [PIX_FMT_YUV411P] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 8,
+ },
+ [PIX_FMT_YUV440P] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 8,
+ },
+ [PIX_FMT_YUV420P16LE] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 16,
+ },
+ [PIX_FMT_YUV422P16LE] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 16,
+ },
+ [PIX_FMT_YUV444P16LE] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 16,
+ },
+ [PIX_FMT_YUV420P16BE] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 16,
+ },
+ [PIX_FMT_YUV422P16BE] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 16,
+ },
+ [PIX_FMT_YUV444P16BE] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 16,
+ },
+
+ /* YUV formats with alpha plane */
+ [PIX_FMT_YUVA420P] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 8,
+ },
+
+ /* JPEG YUV */
+ [PIX_FMT_YUVJ420P] = {
+ .color_type = FF_COLOR_YUV_JPEG,
+ .depth = 8,
+ },
+ [PIX_FMT_YUVJ422P] = {
+ .color_type = FF_COLOR_YUV_JPEG,
+ .depth = 8,
+ },
+ [PIX_FMT_YUVJ444P] = {
+ .color_type = FF_COLOR_YUV_JPEG,
+ .depth = 8,
+ },
+ [PIX_FMT_YUVJ440P] = {
+ .color_type = FF_COLOR_YUV_JPEG,
+ .depth = 8,
+ },
+
+ /* RGB formats */
+ [PIX_FMT_RGB24] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 8,
+ },
+ [PIX_FMT_BGR24] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 8,
+ },
+ [PIX_FMT_ARGB] = {
+ .is_alpha = 1,
+ .color_type = FF_COLOR_RGB,
+ .depth = 8,
+ },
+ [PIX_FMT_RGB48BE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 16,
+ },
+ [PIX_FMT_RGB48LE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 16,
+ },
+ [PIX_FMT_RGB565BE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 5,
+ },
+ [PIX_FMT_RGB565LE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 5,
+ },
+ [PIX_FMT_RGB555BE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 5,
+ .padded_size = 16,
+ },
+ [PIX_FMT_RGB555LE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 5,
+ .padded_size = 16,
+ },
+ [PIX_FMT_RGB444BE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 4,
+ .padded_size = 16,
+ },
+ [PIX_FMT_RGB444LE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 4,
+ .padded_size = 16,
+ },
+
+ /* gray / mono formats */
+ [PIX_FMT_GRAY16BE] = {
+ .color_type = FF_COLOR_GRAY,
+ .depth = 16,
+ },
+ [PIX_FMT_GRAY16LE] = {
+ .color_type = FF_COLOR_GRAY,
+ .depth = 16,
+ },
+ [PIX_FMT_GRAY8] = {
+ .color_type = FF_COLOR_GRAY,
+ .depth = 8,
+ },
+ [PIX_FMT_MONOWHITE] = {
+ .color_type = FF_COLOR_GRAY,
+ .depth = 1,
+ },
+ [PIX_FMT_MONOBLACK] = {
+ .color_type = FF_COLOR_GRAY,
+ .depth = 1,
+ },
+
+ /* paletted formats */
+ [PIX_FMT_PAL8] = {
+ .is_alpha = 1,
+ .color_type = FF_COLOR_RGB,
+ .depth = 8,
+ },
+ [PIX_FMT_UYYVYY411] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 8,
+ },
+ [PIX_FMT_ABGR] = {
+ .is_alpha = 1,
+ .color_type = FF_COLOR_RGB,
+ .depth = 8,
+ },
+ [PIX_FMT_BGR565BE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 5,
+ .padded_size = 16,
+ },
+ [PIX_FMT_BGR565LE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 5,
+ .padded_size = 16,
+ },
+ [PIX_FMT_BGR555BE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 5,
+ .padded_size = 16,
+ },
+ [PIX_FMT_BGR555LE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 5,
+ .padded_size = 16,
+ },
+ [PIX_FMT_BGR444BE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 4,
+ .padded_size = 16,
+ },
+ [PIX_FMT_BGR444LE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 4,
+ .padded_size = 16,
+ },
+ [PIX_FMT_RGB8] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 8,
+ },
+ [PIX_FMT_RGB4] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 4,
+ },
+ [PIX_FMT_RGB4_BYTE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 8,
+ .padded_size = 8,
+ },
+ [PIX_FMT_BGR8] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 8,
+ },
+ [PIX_FMT_BGR4] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 4,
+ },
+ [PIX_FMT_BGR4_BYTE] = {
+ .color_type = FF_COLOR_RGB,
+ .depth = 8,
+ .padded_size = 8,
+ },
+ [PIX_FMT_NV12] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 8,
+ },
+ [PIX_FMT_NV21] = {
+ .color_type = FF_COLOR_YUV,
+ .depth = 8,
+ },
+
+ [PIX_FMT_BGRA] = {
+ .is_alpha = 1,
+ .color_type = FF_COLOR_RGB,
+ .depth = 8,
+ },
+ [PIX_FMT_RGBA] = {
+ .is_alpha = 1,
+ .color_type = FF_COLOR_RGB,
+ .depth = 8,
+ },
+};
diff --git a/libavutil/pixcolorinfo.h b/libavutil/pixcolorinfo.h
new file mode 100644
index 0000000..61eb64f
--- /dev/null
+++ b/libavutil/pixcolorinfo.h
@@ -0,0 +1,45 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_PIXCOLORINFO_H
+#define AVUTIL_PIXCOLORINFO_H
+
+#include <stdint.h>
+#include "pixfmt.h"
+
+/**
+ * @file
+ * misc struct used to contain pixel format colorspace informations.
+ * Ported from libavcodec/imgconvert.c.
+ */
+
+#define FF_COLOR_RGB 0 /**< RGB color space */
+#define FF_COLOR_GRAY 1 /**< gray color space */
+#define FF_COLOR_YUV 2 /**< YUV color space. 16 <= Y <= 235, 16 <= U, V <= 240 */
+#define FF_COLOR_YUV_JPEG 3 /**< YUV color space. 0 <= Y <= 255, 0 <= U, V <= 255 */
+
+typedef struct PixFmtInfo {
+ uint8_t color_type; /**< color type (see FF_COLOR_xxx constants) */
+ uint8_t is_alpha : 1; /**< true if alpha can be specified */
+ uint8_t depth; /**< bit depth of the color components */
+ uint8_t padded_size; /**< padded size in bits if different from the non-padded size */
+} PixFmtInfo;
+
+extern const PixFmtInfo ff_pix_fmt_info[];
+
+#endif /* AVUTIL_PIXCOLORINFO_H */
--
1.7.2.5
More information about the ffmpeg-devel
mailing list