[FFmpeg-devel] [PATCH] avcodec: add farbfeld encoder

Rémi Denis-Courmont remi at remlab.net
Mon Jun 3 09:05:58 EEST 2024



Le 3 juin 2024 06:27:16 GMT+03:00, Marcus B Spencer <marcus at marcusspencer.xyz> a écrit :
>farbfeld is an uncompressed image format that is a part of suckless
>tools (https://tools.suckless.org).
>
>Its documentation is available at https://tools.suckless.org/farbfeld.
>
>Add support for this image format in avcodec and update the image2
>format accordingly.
>
>Signed-off-by: Marcus B Spencer <marcus at marcusspencer.xyz>
>---
> Changelog                 |  1 +
> doc/general_contents.texi |  2 +
> libavcodec/Makefile       |  1 +
> libavcodec/allcodecs.c    |  1 +
> libavcodec/codec_desc.c   |  7 ++++
> libavcodec/codec_id.h     |  1 +
> libavcodec/farbfeldenc.c  | 84 +++++++++++++++++++++++++++++++++++++++
> libavcodec/version.h      |  2 +-
> libavformat/img2.c        |  1 +
> libavformat/img2enc.c     |  2 +-
> 10 files changed, 100 insertions(+), 2 deletions(-)
> create mode 100644 libavcodec/farbfeldenc.c

>diff --git a/libavcodec/farbfeldenc.c b/libavcodec/farbfeldenc.c
>new file mode 100644
>index 0000000000..e48eba680e
>--- /dev/null
>+++ b/libavcodec/farbfeldenc.c
>@@ -0,0 +1,84 @@
>+/*
>+ * Copyright (c) 2024 Marcus B Spencer <marcus at marcusspencer.xyz>
>+ *
>+ * Permission is hereby granted, free of charge, to any person obtaining a copy
>+ * of this software and associated documentation files (the “Software”), to
>+ * deal in the Software without restriction, including without limitation the
>+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
>+ * sell copies of the Software, and to permit persons to whom the Software is
>+ * furnished to do so, subject to the following conditions:
>+ *
>+ * The above copyright notice and this permission notice shall be included in
>+ * all copies or substantial portions of the Software.
>+ *
>+ * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
>+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
>+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
>+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
>+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
>+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
>+ * IN THE SOFTWARE.
>+ */
>+
>+#include "libavutil/imgutils.h"
>+#include "codec_internal.h"
>+#include "bytestream.h"
>+#include "avcodec.h"
>+#include "encode.h"
>+
>+#define HEADER_SIZE 16
>+
>+static int farbfeld_encode_frame(AVCodecContext *ctx, AVPacket *pkt,
>+                                 const AVFrame *p, int *got_packet)
>+{
>+    int pkt_size = HEADER_SIZE + av_image_get_buffer_size(
>+        p->format,
>+        p->width,
>+        p->height,
>+        1
>+    );
>+    uint8_t *buf;
>+    int ret;
>+
>+    if (pkt_size < 0)
>+        return pkt_size;
>+
>+    // 16 is the header size
>+    if ((ret = ff_get_encode_buffer(ctx, pkt, pkt_size, 0)) < 0)
>+        return ret;
>+
>+    buf = pkt->data;
>+
>+    bytestream_put_buffer(&buf, "farbfeld", 8);
>+
>+    bytestream_put_be32(&buf, ctx->width);
>+    bytestream_put_be32(&buf, ctx->height);
>+
>+    av_image_copy_to_buffer(
>+        buf,
>+        pkt_size - HEADER_SIZE,
>+        (const uint8_t **)p->data,

Bogus cast / aliasing violation.

>+        p->linesize,
>+        p->format,
>+        p->width,
>+        p->height,
>+        1
>+    );
>+
>+    *got_packet = 1;
>+
>+    return 0;
>+}
>+
>+const FFCodec ff_farbfeld_encoder = {
>+    .p.name         = "farbfeld",
>+    CODEC_LONG_NAME("farbfeld uncompressed image"),
>+    .p.type         = AVMEDIA_TYPE_VIDEO,
>+    .p.id           = AV_CODEC_ID_FARBFELD,
>+    .p.capabilities = AV_CODEC_CAP_DR1,
>+    FF_CODEC_ENCODE_CB(farbfeld_encode_frame),
>+    .p.pix_fmts     = (const enum AVPixelFormat[]){
>+        AV_PIX_FMT_RGBA64BE,
>+        AV_PIX_FMT_NONE
>+    },
>+};


More information about the ffmpeg-devel mailing list