/* * Copyright (C) 2024 Niklas Haas * * 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 SWSCALE_AVSCALE_H #define SWSCALE_AVSCALE_H /** * @file * @ingroup libsws * Higher-level wrapper around libswscale + related libraries, which is * capable of handling more advanced colorspace transformations. */ #include "libavutil/frame.h" #include "libavutil/log.h" /** * Main external API structure. New fields cannot be added to the end with * minor version bumps. Removal, reordering and changes to existing fields * require a major version bump. sizeof(AVScaleContext) is not part of the ABI. */ typedef struct AVScaleContext { const AVClass *av_class; /** * Private context used for internal data. */ struct AVScaleInternal *internal; /** * Private data of the user, can be used to carry app specific stuff. */ void *opaque; /** * Bitmask of AV_SCALE_* flags. */ int64_t flags; /** * Bitmask of SWS_* flags. */ int sws_flags; /** * Bitmask of SWS_DITHER_* flags. */ int sws_dither; } AVScaleContext; enum { /** * Skip linearization, speeds up downscaling at the cost of quality. */ AV_SCALE_NOLINEAR = 1 << 0, /** * Force full internal conversion to RGB. May improve the quality of * certain operations, at the cost of performance. */ AV_SCALE_FULL_RGB = 1 << 1, /** * Perform perceptual conversion between colorspaces instead of clipping. */ AV_SCALE_PERCEPTUAL = 1 << 2, // ... }; /** * Allocate an AVScaleContext and set its fields to default values. The * resulting struct should be freed with avscale_free_context(). */ AVScaleContext *avscale_alloc_context(void); /** * Free the codec context and everything associated with it, and write NULL * to the provided pointer. */ void avscale_free_context(AVScaleContext **ctx); /** * Get the AVClass for AVScaleContext. It can be used in combination with * AV_OPT_SEARCH_FAKE_OBJ for examining options. * * @see av_opt_find(). */ const AVClass *avscale_get_class(void); /** * Scale source data from `src` and write the output to `dst`. * * @param ctx The scaling context. * @param dst The destination frame. * * The data buffers may either be already allocated by the caller * or left clear, in which case they will be allocated by the * scaler. The latter may have performance advantages - e.g. in * certain cases some output planes may be references to input * planes, rather than copies. * * @param src The source frame. If the data buffers are set to NULL, then * this function performs no conversion. It will instead merely * initialize internal state that *would* be required to perform * the operation, as well as returing the correct error code for * unsupported frame combinations. * * @return 0 on success, a negative AVERROR code on failure. */ int avscale_frame(AVScaleContext *ctx, AVFrame *dst, const AVFrame *src); #endif /* SWSCALE_AVSCALE_H */