[FFmpeg-devel] [PATCH v7 04/12] swscale: expose SwsContext publicly

Michael Niedermayer michael at niedermayer.cc
Fri Nov 22 05:14:06 EET 2024


On Thu, Nov 21, 2024 at 01:13:45PM +0100, Niklas Haas wrote:
> On Thu, 21 Nov 2024 00:42:23 +0100 Michael Niedermayer <michael at niedermayer.cc> wrote:
> > Hi Niklas
> >
> > On Sat, Nov 16, 2024 at 12:24:59PM +0100, Niklas Haas wrote:
> > > From: Niklas Haas <git at haasn.dev>
> > >
> > > Following in the footsteps of the work in the previous commit, it's now
> > > relatively straightforward to expose the options struct publicly as
> > > SwsContext. This is a step towards making this more user friendly, as
> > > well as following API conventions established elsewhere.
> > >
> > > Sponsored-by: Sovereign Tech Fund
> > > Signed-off-by: Niklas Haas <git at haasn.dev>
> > > ---
> > >  libswscale/swscale.h          |  93 +++++++++++++++++++++++--
> > >  libswscale/swscale_internal.h |  45 +------------
> > >  libswscale/utils.c            | 123 +++++++++++++++-------------------
> > >  3 files changed, 144 insertions(+), 117 deletions(-)
> > >
> > > diff --git a/libswscale/swscale.h b/libswscale/swscale.h
> > > index 50c705ae06..4baef532b6 100644
> > > --- a/libswscale/swscale.h
> > > +++ b/libswscale/swscale.h
> > > @@ -42,8 +42,6 @@
> > >  #include "version.h"
> > >  #endif
> > >
> > > -typedef struct SwsContext SwsContext;
> > > -
> > >  /**
> > >   * @defgroup libsws libswscale
> > >   * Color conversion and scaling library.
> > > @@ -65,17 +63,98 @@ const char *swscale_configuration(void);
> > >  const char *swscale_license(void);
> > >
> > >  /**
> > > - * Get the AVClass for swsContext. It can be used in combination with
> > > + * Get the AVClass for SwsContext. It can be used in combination with
> > >   * AV_OPT_SEARCH_FAKE_OBJ for examining options.
> > >   *
> > >   * @see av_opt_find().
> > >   */
> > >  const AVClass *sws_get_class(void);
> > >
> > > -/**
> > > - * Allocate an empty SwsContext. This must be filled and passed to
> > > - * sws_init_context(). For filling see AVOptions, options.c and
> > > - * sws_setColorspaceDetails().
> > > +/******************************
> > > + * Flags and quality settings *
> > > + ******************************/
> > > +
> > > +typedef enum SwsDither {
> > > +    SWS_DITHER_NONE = 0, /* disable dithering */
> > > +    SWS_DITHER_AUTO,     /* auto-select from preset */
> > > +    SWS_DITHER_BAYER,    /* ordered dither matrix */
> > > +    SWS_DITHER_ED,       /* error diffusion */
> > > +    SWS_DITHER_A_DITHER, /* arithmetic addition */
> > > +    SWS_DITHER_X_DITHER, /* arithmetic xor */
> > > +    SWS_DITHER_NB,       /* not part of the ABI */
> > > +} SwsDither;
> > > +
> > > +typedef enum SwsAlphaBlend {
> > > +    SWS_ALPHA_BLEND_NONE = 0,
> > > +    SWS_ALPHA_BLEND_UNIFORM,
> > > +    SWS_ALPHA_BLEND_CHECKERBOARD,
> > > +    SWS_ALPHA_BLEND_NB,  /* not part of the ABI */
> > > +} SwsAlphaBlend;
> > > +
> > > +/***********************************
> > > + * Context creation and management *
> > > + ***********************************/
> > > +
> > > +/**
> > > + * Main external API structure. New fields can be added to the end with
> > > + * minor version bumps. Removal, reordering and changes to existing fields
> > > + * require a major version bump. sizeof(SwsContext) is not part of the ABI.
> > > + */
> > > +typedef struct SwsContext {
> > > +    const AVClass *av_class;
> > > +
> > > +    /**
> > > +     * Private data of the user, can be used to carry app specific stuff.
> > > +     */
> > > +    void *opaque;
> > > +
> >
> > > +    /**
> > > +     * Bitmask of SWS_*.
> > > +     */
> > > +    unsigned flags;
> >
> > uint64_t seems more future proof
> >
> >
> > > +
> > > +    /**
> > > +     * Extra parameters for fine-tuning certain scalers.
> > > +     */
> > > +    double scaler_params[2];
> > > +
> > > +    /**
> > > +     * How many threads to use for processing, or 0 for automatic selection.
> > > +     */
> > > +    int threads;
> > > +
> >
> > > +    /**
> > > +     * Dither mode.
> > > +     */
> > > +    SwsDither dither;
> > > +
> > > +    /**
> > > +     * Alpha blending mode. See `SwsAlphaBlend` for details.
> > > +     */
> > > +    SwsAlphaBlend alpha_blend;
> >
> > Is this intended to be used with AVOptions ?
> > enums as type can be problematic IIRC
> 
> AVCodecContext does the same thing with all of its enums, see AVColorSpace for
> example. (used as AV_OPT_TYPE_INT in libavcodec/options_table.h)

do we require all enum to be int (when the values fit) ?

The C spec seems to say: 6.7.2.2 Enumeration specifiers ()
The choice of type is implementation-defined

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The misfortune of the wise is better than the prosperity of the fool.
-- Epicurus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20241122/6e06f76f/attachment.sig>


More information about the ffmpeg-devel mailing list