Currently only AV_PIX_FMT_XYZ12 is supported to fix the jpeg2000-dcinema
fate test on big-endian systems.
---
libavfilter/Makefile | 1 +
libavfilter/allfilters.c | 1 +
libavfilter/vf_byteswap2le.c | 142 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 144 insertions(+)
create mode 100644 libavfilter/vf_byteswap2le.c
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 0927157..b2414a1 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -42,6 +42,7 @@ OBJS-$(CONFIG_ANULLSINK_FILTER) +=
asink_anullsink.o
OBJS-$(CONFIG_BLACKFRAME_FILTER) += vf_blackframe.o
OBJS-$(CONFIG_BOXBLUR_FILTER) += vf_boxblur.o
+OBJS-$(CONFIG_BS2LE_FILTER) += vf_byteswap2le.o
OBJS-$(CONFIG_COPY_FILTER) += vf_copy.o
OBJS-$(CONFIG_CROP_FILTER) += vf_crop.o
OBJS-$(CONFIG_CROPDETECT_FILTER) += vf_cropdetect.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 7b407cd..6afda75 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -62,6 +62,7 @@ void avfilter_register_all(void)
REGISTER_FILTER(BLACKFRAME, blackframe, vf);
REGISTER_FILTER(BOXBLUR, boxblur, vf);
+ REGISTER_FILTER(BS2LE, bs2le, vf);
REGISTER_FILTER(COPY, copy, vf);
REGISTER_FILTER(CROP, crop, vf);
REGISTER_FILTER(CROPDETECT, cropdetect, vf);
diff --git a/libavfilter/vf_byteswap2le.c b/libavfilter/vf_byteswap2le.c
new file mode 100644
index 0000000..1a280b4
--- /dev/null
+++ b/libavfilter/vf_byteswap2le.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2013 Janne Grunau
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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 Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * video byte swap to little-endian filter
+ */
+
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+#include "libavutil/bswap.h"
+#include "libavutil/internal.h"
+#include "libavutil/pixdesc.h"
+
+typedef struct {
+ const AVClass *class;
+ int swap;
+} Bs2leContext;
+
+static int query_formats(AVFilterContext *ctx)
+{
+ int count = 0, i;
+ AVFilterFormats *input_fmts, *output_fmts;
+ enum AVPixelFormat in[] = {AV_PIX_FMT_XYZ12BE,
+ AV_PIX_FMT_XYZ12LE,
+ AV_PIX_FMT_NONE};
+ enum AVPixelFormat out[] = {AV_PIX_FMT_XYZ12LE,
+ AV_PIX_FMT_NONE};
+
+ input_fmts = ff_make_format_list(in);
+ output_fmts = ff_make_format_list(out);
+
+ for (i = 0; i < ctx->nb_inputs; i++) {
+ if (ctx->inputs[i]) {
+ ff_formats_ref(input_fmts, &ctx->inputs[i]->out_formats);
+ count++;
+ }
+ }
+ for (i = 0; i < ctx->nb_outputs; i++) {
+ if (ctx->outputs[i]) {
+ ff_formats_ref(output_fmts, &ctx->outputs[i]->in_formats);
+ count++;
+ }
+ }
+
+ return 0;
+}
+
+static int config_input(AVFilterLink *link)
+{
+ AVFilterContext *ctx = link->dst;
+ Bs2leContext *bs2le = ctx->priv;
+
+ const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(link->format);
+ if (!pixdesc) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid pixel format %d\n", link->format);
+ return -1;
+ }
+
+ if (pixdesc->flags & PIX_FMT_BE)
+ bs2le->swap = !!(pixdesc->flags & PIX_FMT_BE);
+
+ av_log(ctx, AV_LOG_INFO, "vf_bs2le %s: input pix_fmt=%d, swap=%d\n",
+ __func__, link->format, bs2le->swap);
+
+ return 0;
+}
+
+static int filter_frame(AVFilterLink *link, AVFrame *frame)
+{
+ AVFilterContext *ctx = link->dst;
+ Bs2leContext *bs2le = ctx->priv;
+
+ if (bs2le->swap) {
+ int x,y;
+
+ for (y = 0; y < frame->height; y += 1) {
+ uint16_t *tmp = (uint16_t *) (frame->data[0] + y *
frame->linesize[0]);
+ for (x = 0; x < frame->linesize[0] / 2; x += 1) {
+ tmp[x] = av_bswap16(tmp[x]);
+ }
+ }
+ }
+ return ff_filter_frame(link->dst->outputs[0], frame);
+}
+
+static const AVClass bs2le_class = {
+ .class_name = "bs2le",
+ .item_name = av_default_item_name,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+static const AVFilterPad avfilter_vf_bs2le_inputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .filter_frame = filter_frame,
+ .get_video_buffer = ff_null_get_video_buffer,
+ .config_props = config_input,
+ },
+ { NULL }
+};
+
+static const AVFilterPad avfilter_vf_bs2le_outputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ },
+ { NULL }
+};
+
+AVFilter avfilter_vf_bs2le = {
+ .name = "bs2le",
+ .description = NULL_IF_CONFIG_SMALL("Always output little-endian data"),
+
+ .priv_size = sizeof(Bs2leContext),
+ .priv_class = &bs2le_class,
+
+ .query_formats = query_formats,
+
+ .inputs = avfilter_vf_bs2le_inputs,
+ .outputs = avfilter_vf_bs2le_outputs,
+};
--
1.8.2.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel