Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH v2] avcodec: add farbfeld encoder
@ 2024-06-03  3:33 Marcus B Spencer
  2024-06-03  9:39 ` Stefano Sabatini
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Marcus B Spencer @ 2024-06-03  3:33 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marcus B Spencer

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@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  | 83 +++++++++++++++++++++++++++++++++++++++
 libavcodec/version.h      |  2 +-
 libavformat/img2.c        |  1 +
 libavformat/img2enc.c     |  2 +-
 10 files changed, 99 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/farbfeldenc.c

diff --git a/Changelog b/Changelog
index 03d6b29ad8..d2b831c623 100644
--- a/Changelog
+++ b/Changelog
@@ -12,6 +12,7 @@ version <next>:
 - qsv_params option added for QSV encoders
 - VVC decoder compatible with DVB test content
 - xHE-AAC decoder
+- farbfeld encoder
 
 
 version 7.0:
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index e7cf4f8239..129a325ecf 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -853,6 +853,8 @@ following image formats are supported:
     @tab X PixMap image format
 @item XWD  @tab X @tab X
     @tab X Window Dump image format
+@item FF           @tab X @tab
+    @tab farbfeld uncompressed image format
 @end multitable
 
 @code{X} means that the feature in that column (encoding / decoding) is supported.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 2443d2c6fd..808f2a5d54 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -359,6 +359,7 @@ OBJS-$(CONFIG_ESCAPE130_DECODER)       += escape130.o
 OBJS-$(CONFIG_EVRC_DECODER)            += evrcdec.o acelp_vectors.o lsp.o
 OBJS-$(CONFIG_EXR_DECODER)             += exr.o exrdsp.o half2float.o
 OBJS-$(CONFIG_EXR_ENCODER)             += exrenc.o float2half.o
+OBJS-$(CONFIG_FARBFELD_ENCODER)        += farbfeldenc.o
 OBJS-$(CONFIG_FASTAUDIO_DECODER)       += fastaudio.o
 OBJS-$(CONFIG_FFV1_DECODER)            += ffv1dec.o ffv1.o
 OBJS-$(CONFIG_FFV1_ENCODER)            += ffv1enc.o ffv1.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index b102a8069e..b0ebb72396 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -115,6 +115,7 @@ extern const FFCodec ff_escape124_decoder;
 extern const FFCodec ff_escape130_decoder;
 extern const FFCodec ff_exr_encoder;
 extern const FFCodec ff_exr_decoder;
+extern const FFCodec ff_farbfeld_encoder;
 extern const FFCodec ff_ffv1_encoder;
 extern const FFCodec ff_ffv1_decoder;
 extern const FFCodec ff_ffvhuff_encoder;
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index a28ef68061..33dbd2ce94 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1959,6 +1959,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
         .long_name = NULL_IF_CONFIG_SMALL("LEAD MCMP"),
         .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
     },
+    {
+        .id        = AV_CODEC_ID_FARBFELD,
+        .type      = AVMEDIA_TYPE_VIDEO,
+        .name      = "farbfeld",
+        .long_name = NULL_IF_CONFIG_SMALL("farbfeld uncompressed image"),
+        .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
+    },
 
     /* various PCM "codecs" */
     {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index 0ab1e34a61..d4b0d23f7e 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -322,6 +322,7 @@ enum AVCodecID {
     AV_CODEC_ID_RTV1,
     AV_CODEC_ID_VMIX,
     AV_CODEC_ID_LEAD,
+    AV_CODEC_ID_FARBFELD,
 
     /* various PCM "codecs" */
     AV_CODEC_ID_FIRST_AUDIO = 0x10000,     ///< A dummy id pointing at the start of audio codecs
diff --git a/libavcodec/farbfeldenc.c b/libavcodec/farbfeldenc.c
new file mode 100644
index 0000000000..6ef9763dab
--- /dev/null
+++ b/libavcodec/farbfeldenc.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2024 Marcus B Spencer <marcus@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;
+
+    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,
+        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
+    },
+};
diff --git a/libavcodec/version.h b/libavcodec/version.h
index da54f87887..7acb261bb3 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR   6
+#define LIBAVCODEC_VERSION_MINOR   7
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavformat/img2.c b/libavformat/img2.c
index 9981867f82..77edc7ff9b 100644
--- a/libavformat/img2.c
+++ b/libavformat/img2.c
@@ -95,6 +95,7 @@
     TAG(QOI,             qoi      ) \
     TAG(RADIANCE_HDR,    hdr      ) \
     TAG(WBMP,            wbmp     ) \
+    TAG(FARBFELD,        ff       ) \
     TAG(NONE,                     )
 
 #define LENGTH_CHECK(CODECID, STR) \
diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index 526a11e5ee..13355a6fad 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -276,7 +276,7 @@ const FFOutputFormat ff_image2_muxer = {
     .p.long_name    = NULL_IF_CONFIG_SMALL("image2 sequence"),
     .p.extensions   = "bmp,dpx,exr,jls,jpeg,jpg,jxl,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv,phm,"
                       "png,ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8,"
-                      "im24,sunras,vbn,xbm,xface,pix,y,avif,qoi,hdr,wbmp",
+                      "im24,sunras,vbn,xbm,xface,pix,y,avif,qoi,hdr,wbmp,ff",
     .priv_data_size = sizeof(VideoMuxData),
     .p.video_codec  = AV_CODEC_ID_MJPEG,
     .write_header   = write_header,
-- 
2.45.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2] avcodec: add farbfeld encoder
  2024-06-03  3:33 [FFmpeg-devel] [PATCH v2] avcodec: add farbfeld encoder Marcus B Spencer
@ 2024-06-03  9:39 ` Stefano Sabatini
  2024-06-03 12:10 ` Tomas Härdin
  2024-06-18 21:40 ` Lynne via ffmpeg-devel
  2 siblings, 0 replies; 7+ messages in thread
From: Stefano Sabatini @ 2024-06-03  9:39 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Marcus B Spencer

On date Sunday 2024-06-02 22:33:20 -0500, Marcus B Spencer wrote:
> 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@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  | 83 +++++++++++++++++++++++++++++++++++++++
>  libavcodec/version.h      |  2 +-
>  libavformat/img2.c        |  1 +
>  libavformat/img2enc.c     |  2 +-
>  10 files changed, 99 insertions(+), 2 deletions(-)
>  create mode 100644 libavcodec/farbfeldenc.c
> 
> diff --git a/Changelog b/Changelog
> index 03d6b29ad8..d2b831c623 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -12,6 +12,7 @@ version <next>:
>  - qsv_params option added for QSV encoders
>  - VVC decoder compatible with DVB test content
>  - xHE-AAC decoder
> +- farbfeld encoder
>  
>  
>  version 7.0:
> diff --git a/doc/general_contents.texi b/doc/general_contents.texi
> index e7cf4f8239..129a325ecf 100644
> --- a/doc/general_contents.texi
> +++ b/doc/general_contents.texi
> @@ -853,6 +853,8 @@ following image formats are supported:
>      @tab X PixMap image format
>  @item XWD  @tab X @tab X
>      @tab X Window Dump image format
> +@item FF           @tab X @tab
> +    @tab farbfeld uncompressed image format
>  @end multitable
>  
>  @code{X} means that the feature in that column (encoding / decoding) is supported.
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 2443d2c6fd..808f2a5d54 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -359,6 +359,7 @@ OBJS-$(CONFIG_ESCAPE130_DECODER)       += escape130.o
>  OBJS-$(CONFIG_EVRC_DECODER)            += evrcdec.o acelp_vectors.o lsp.o
>  OBJS-$(CONFIG_EXR_DECODER)             += exr.o exrdsp.o half2float.o
>  OBJS-$(CONFIG_EXR_ENCODER)             += exrenc.o float2half.o
> +OBJS-$(CONFIG_FARBFELD_ENCODER)        += farbfeldenc.o
>  OBJS-$(CONFIG_FASTAUDIO_DECODER)       += fastaudio.o
>  OBJS-$(CONFIG_FFV1_DECODER)            += ffv1dec.o ffv1.o
>  OBJS-$(CONFIG_FFV1_ENCODER)            += ffv1enc.o ffv1.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index b102a8069e..b0ebb72396 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -115,6 +115,7 @@ extern const FFCodec ff_escape124_decoder;
>  extern const FFCodec ff_escape130_decoder;
>  extern const FFCodec ff_exr_encoder;
>  extern const FFCodec ff_exr_decoder;
> +extern const FFCodec ff_farbfeld_encoder;
>  extern const FFCodec ff_ffv1_encoder;
>  extern const FFCodec ff_ffv1_decoder;
>  extern const FFCodec ff_ffvhuff_encoder;
> diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> index a28ef68061..33dbd2ce94 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -1959,6 +1959,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
>          .long_name = NULL_IF_CONFIG_SMALL("LEAD MCMP"),
>          .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
>      },
> +    {
> +        .id        = AV_CODEC_ID_FARBFELD,
> +        .type      = AVMEDIA_TYPE_VIDEO,
> +        .name      = "farbfeld",
> +        .long_name = NULL_IF_CONFIG_SMALL("farbfeld uncompressed image"),
> +        .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
> +    },
>  
>      /* various PCM "codecs" */
>      {
> diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
> index 0ab1e34a61..d4b0d23f7e 100644
> --- a/libavcodec/codec_id.h
> +++ b/libavcodec/codec_id.h
> @@ -322,6 +322,7 @@ enum AVCodecID {
>      AV_CODEC_ID_RTV1,
>      AV_CODEC_ID_VMIX,
>      AV_CODEC_ID_LEAD,
> +    AV_CODEC_ID_FARBFELD,
>  
>      /* various PCM "codecs" */
>      AV_CODEC_ID_FIRST_AUDIO = 0x10000,     ///< A dummy id pointing at the start of audio codecs
> diff --git a/libavcodec/farbfeldenc.c b/libavcodec/farbfeldenc.c
> new file mode 100644
> index 0000000000..6ef9763dab
> --- /dev/null
> +++ b/libavcodec/farbfeldenc.c
> @@ -0,0 +1,83 @@
> +/*
> + * Copyright (c) 2024 Marcus B Spencer <marcus@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;
> +
> +    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,

nit++: for readability it might help to have a dedicated variable
buf_size

> +        (const uint8_t **)p->data,
> +        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
> +    },
> +};
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index da54f87887..7acb261bb3 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -29,7 +29,7 @@
>  
>  #include "version_major.h"
>  
> -#define LIBAVCODEC_VERSION_MINOR   6
> +#define LIBAVCODEC_VERSION_MINOR   7
>  #define LIBAVCODEC_VERSION_MICRO 100
>  
>  #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
> diff --git a/libavformat/img2.c b/libavformat/img2.c
> index 9981867f82..77edc7ff9b 100644
> --- a/libavformat/img2.c
> +++ b/libavformat/img2.c
> @@ -95,6 +95,7 @@
>      TAG(QOI,             qoi      ) \
>      TAG(RADIANCE_HDR,    hdr      ) \
>      TAG(WBMP,            wbmp     ) \
> +    TAG(FARBFELD,        ff       ) \
>      TAG(NONE,                     )

Looks good to me.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2] avcodec: add farbfeld encoder
  2024-06-03  3:33 [FFmpeg-devel] [PATCH v2] avcodec: add farbfeld encoder Marcus B Spencer
  2024-06-03  9:39 ` Stefano Sabatini
@ 2024-06-03 12:10 ` Tomas Härdin
  2024-06-03 12:35   ` Tomas Härdin
  2024-06-18 21:40 ` Lynne via ffmpeg-devel
  2 siblings, 1 reply; 7+ messages in thread
From: Tomas Härdin @ 2024-06-03 12:10 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


This format seems to reproduce some of the same issues as QOI:

> The RGB-data should be sRGB for best interoperability and not alpha-
> premultiplied.

This seems to imply it could be something other than sRGB since it says
SHOULD rather than MUST. This probably isn't a huge issue, but it
should be clearer on the website. It also doesn't say whether alpha is
linear or not.

> +    int pkt_size = HEADER_SIZE + av_image_get_buffer_size(
> +        p->format,
> +        p->width,
> +        p->height,
> +        1
> +    );

Check the return value of av_image_get_buffer_size() before adding
HEADER_SIZE to it. There will be a signed overflow (UB) for images of
size 16385x16385 (and many others).

Aside: av_image_get_buffer_size() will UB for sizes above INT_MAX
because the size_t's in sizes[] get accumulated into an int. Besides
the UB it also returns incorrect values.

/Tomas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2] avcodec: add farbfeld encoder
  2024-06-03 12:10 ` Tomas Härdin
@ 2024-06-03 12:35   ` Tomas Härdin
  2024-06-03 19:16     ` marcus
  0 siblings, 1 reply; 7+ messages in thread
From: Tomas Härdin @ 2024-06-03 12:35 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

> Check the return value of av_image_get_buffer_size() before adding
> HEADER_SIZE to it. There will be a signed overflow (UB) for images of
> size 16385x16385 (and many others).

Sorry, I missed the multiplication by h+128 in av_image_check_size2().
So this isn't a problem in this specific case.

> Aside: av_image_get_buffer_size() will UB for sizes above INT_MAX
> because the size_t's in sizes[] get accumulated into an int. Besides
> the UB it also returns incorrect values.

This however *is* a problem for planar formats. This doesn't affect
this patch however.

/Tomass
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2] avcodec: add farbfeld encoder
  2024-06-03 12:35   ` Tomas Härdin
@ 2024-06-03 19:16     ` marcus
  2024-06-18 14:48       ` Tomas Härdin
  0 siblings, 1 reply; 7+ messages in thread
From: marcus @ 2024-06-03 19:16 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

> 
> 
> > Check the return value of av_image_get_buffer_size() before adding
> 
> > HEADER_SIZE to it. There will be a signed overflow (UB) for images of
> > size 16385x16385 (and many others).
> 
> 
> Sorry, I missed the multiplication by h+128 in av_image_check_size2().
> So this isn't a problem in this specific case.
> 
> > Aside: av_image_get_buffer_size() will UB for sizes above INT_MAX
> > because the size_t's in sizes[] get accumulated into an int. Besides
> > the UB it also returns incorrect values.
>
>
> This however is a problem for planar formats. This doesn't affect
> this patch however.
Did you incorrectly format that message? Or did you really mean that the UB when the size is greater than INT_MAX doesn't affect my patch?
> 
> /Tomass
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2] avcodec: add farbfeld encoder
  2024-06-03 19:16     ` marcus
@ 2024-06-18 14:48       ` Tomas Härdin
  0 siblings, 0 replies; 7+ messages in thread
From: Tomas Härdin @ 2024-06-18 14:48 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

mån 2024-06-03 klockan 19:16 +0000 skrev marcus:
> > 
> > 
> > > Check the return value of av_image_get_buffer_size() before
> > > adding
> > 
> > > HEADER_SIZE to it. There will be a signed overflow (UB) for
> > > images of
> > > size 16385x16385 (and many others).
> > 
> > 
> > Sorry, I missed the multiplication by h+128 in
> > av_image_check_size2().
> > So this isn't a problem in this specific case.
> > 
> > > Aside: av_image_get_buffer_size() will UB for sizes above INT_MAX
> > > because the size_t's in sizes[] get accumulated into an int.
> > > Besides
> > > the UB it also returns incorrect values.
> > 
> > 
> > This however is a problem for planar formats. This doesn't affect
> > this patch however.
> Did you incorrectly format that message? Or did you really mean that
> the UB when the size is greater than INT_MAX doesn't affect my patch?

It doesn't affect this patch because AV_PIX_FMT_RGBA64BE isn't planar

/Tomas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2] avcodec: add farbfeld encoder
  2024-06-03  3:33 [FFmpeg-devel] [PATCH v2] avcodec: add farbfeld encoder Marcus B Spencer
  2024-06-03  9:39 ` Stefano Sabatini
  2024-06-03 12:10 ` Tomas Härdin
@ 2024-06-18 21:40 ` Lynne via ffmpeg-devel
  2 siblings, 0 replies; 7+ messages in thread
From: Lynne via ffmpeg-devel @ 2024-06-18 21:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Lynne


[-- Attachment #1.1.1.1: Type: text/plain, Size: 9054 bytes --]

On 03/06/2024 05:33, Marcus B Spencer wrote:
> 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@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  | 83 +++++++++++++++++++++++++++++++++++++++
>   libavcodec/version.h      |  2 +-
>   libavformat/img2.c        |  1 +
>   libavformat/img2enc.c     |  2 +-
>   10 files changed, 99 insertions(+), 2 deletions(-)
>   create mode 100644 libavcodec/farbfeldenc.c
> 
> diff --git a/Changelog b/Changelog
> index 03d6b29ad8..d2b831c623 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -12,6 +12,7 @@ version <next>:
>   - qsv_params option added for QSV encoders
>   - VVC decoder compatible with DVB test content
>   - xHE-AAC decoder
> +- farbfeld encoder
>   
>   
>   version 7.0:
> diff --git a/doc/general_contents.texi b/doc/general_contents.texi
> index e7cf4f8239..129a325ecf 100644
> --- a/doc/general_contents.texi
> +++ b/doc/general_contents.texi
> @@ -853,6 +853,8 @@ following image formats are supported:
>       @tab X PixMap image format
>   @item XWD  @tab X @tab X
>       @tab X Window Dump image format
> +@item FF           @tab X @tab
> +    @tab farbfeld uncompressed image format
>   @end multitable
>   
>   @code{X} means that the feature in that column (encoding / decoding) is supported.
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 2443d2c6fd..808f2a5d54 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -359,6 +359,7 @@ OBJS-$(CONFIG_ESCAPE130_DECODER)       += escape130.o
>   OBJS-$(CONFIG_EVRC_DECODER)            += evrcdec.o acelp_vectors.o lsp.o
>   OBJS-$(CONFIG_EXR_DECODER)             += exr.o exrdsp.o half2float.o
>   OBJS-$(CONFIG_EXR_ENCODER)             += exrenc.o float2half.o
> +OBJS-$(CONFIG_FARBFELD_ENCODER)        += farbfeldenc.o
>   OBJS-$(CONFIG_FASTAUDIO_DECODER)       += fastaudio.o
>   OBJS-$(CONFIG_FFV1_DECODER)            += ffv1dec.o ffv1.o
>   OBJS-$(CONFIG_FFV1_ENCODER)            += ffv1enc.o ffv1.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index b102a8069e..b0ebb72396 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -115,6 +115,7 @@ extern const FFCodec ff_escape124_decoder;
>   extern const FFCodec ff_escape130_decoder;
>   extern const FFCodec ff_exr_encoder;
>   extern const FFCodec ff_exr_decoder;
> +extern const FFCodec ff_farbfeld_encoder;
>   extern const FFCodec ff_ffv1_encoder;
>   extern const FFCodec ff_ffv1_decoder;
>   extern const FFCodec ff_ffvhuff_encoder;
> diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> index a28ef68061..33dbd2ce94 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -1959,6 +1959,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
>           .long_name = NULL_IF_CONFIG_SMALL("LEAD MCMP"),
>           .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
>       },
> +    {
> +        .id        = AV_CODEC_ID_FARBFELD,
> +        .type      = AVMEDIA_TYPE_VIDEO,
> +        .name      = "farbfeld",
> +        .long_name = NULL_IF_CONFIG_SMALL("farbfeld uncompressed image"),
> +        .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
> +    },
>   
>       /* various PCM "codecs" */
>       {
> diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
> index 0ab1e34a61..d4b0d23f7e 100644
> --- a/libavcodec/codec_id.h
> +++ b/libavcodec/codec_id.h
> @@ -322,6 +322,7 @@ enum AVCodecID {
>       AV_CODEC_ID_RTV1,
>       AV_CODEC_ID_VMIX,
>       AV_CODEC_ID_LEAD,
> +    AV_CODEC_ID_FARBFELD,
>   
>       /* various PCM "codecs" */
>       AV_CODEC_ID_FIRST_AUDIO = 0x10000,     ///< A dummy id pointing at the start of audio codecs
> diff --git a/libavcodec/farbfeldenc.c b/libavcodec/farbfeldenc.c
> new file mode 100644
> index 0000000000..6ef9763dab
> --- /dev/null
> +++ b/libavcodec/farbfeldenc.c
> @@ -0,0 +1,83 @@
> +/*
> + * Copyright (c) 2024 Marcus B Spencer <marcus@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;
> +
> +    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,
> +        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
> +    },
> +};
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index da54f87887..7acb261bb3 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -29,7 +29,7 @@
>   
>   #include "version_major.h"
>   
> -#define LIBAVCODEC_VERSION_MINOR   6
> +#define LIBAVCODEC_VERSION_MINOR   7
>   #define LIBAVCODEC_VERSION_MICRO 100
>   
>   #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
> diff --git a/libavformat/img2.c b/libavformat/img2.c
> index 9981867f82..77edc7ff9b 100644
> --- a/libavformat/img2.c
> +++ b/libavformat/img2.c
> @@ -95,6 +95,7 @@
>       TAG(QOI,             qoi      ) \
>       TAG(RADIANCE_HDR,    hdr      ) \
>       TAG(WBMP,            wbmp     ) \
> +    TAG(FARBFELD,        ff       ) \
>       TAG(NONE,                     )
>   
>   #define LENGTH_CHECK(CODECID, STR) \
> diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
> index 526a11e5ee..13355a6fad 100644
> --- a/libavformat/img2enc.c
> +++ b/libavformat/img2enc.c
> @@ -276,7 +276,7 @@ const FFOutputFormat ff_image2_muxer = {
>       .p.long_name    = NULL_IF_CONFIG_SMALL("image2 sequence"),
>       .p.extensions   = "bmp,dpx,exr,jls,jpeg,jpg,jxl,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv,phm,"
>                         "png,ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8,"
> -                      "im24,sunras,vbn,xbm,xface,pix,y,avif,qoi,hdr,wbmp",
> +                      "im24,sunras,vbn,xbm,xface,pix,y,avif,qoi,hdr,wbmp,ff",
>       .priv_data_size = sizeof(VideoMuxData),
>       .p.video_codec  = AV_CODEC_ID_MJPEG,
>       .write_header   = write_header,

Again, there is reason for this to be a codec at all.

[-- Attachment #1.1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 637 bytes --]

[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-06-18 21:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-03  3:33 [FFmpeg-devel] [PATCH v2] avcodec: add farbfeld encoder Marcus B Spencer
2024-06-03  9:39 ` Stefano Sabatini
2024-06-03 12:10 ` Tomas Härdin
2024-06-03 12:35   ` Tomas Härdin
2024-06-03 19:16     ` marcus
2024-06-18 14:48       ` Tomas Härdin
2024-06-18 21:40 ` Lynne via ffmpeg-devel

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git