/* * 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; /** * How many threads to use for processing, or 0 for automatic selection. */ int threads; /** * Quality factor (0-10). The default quality is [TBD]. Higher values * sacrifice speed in exchange for quality. * * TODO: explain what changes at each level */ int quality; } AVScaleContext; enum { /** * Force bit-exact output. This will prevent the use of platform-specific * optimizations that may lead to slight difference in rounding, in favor * of always maintaining exact bit output compatibility with the reference * C code. * * Note: This is also available under the name "accurate_rnd" for * backwards compatibility. */ AV_SCALE_BITEXACT = 1 << 0, /** * Return an error on underspecified conversions. Without this flag, * unspecified fields are defaulted to sensible values. */ AV_SCALE_STRICT = 1 << 1, }; /** * 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); /** * Statically test if a conversion is supported. Values of (respectively) * NONE/UNSPECIFIED are ignored. * * Returns 1 if the conversion is supported, or 0 otherwise. */ int avscale_test_format(enum AVPixelFormat dst, enum AVPixelFormat src); int avscale_test_colorspace(enum AVColorSpace dst, enum AVColorSpace src); int avscale_test_primaries(enum AVColorPrimaries dst, enum AVColorPrimaries src); int avscale_test_transfer(enum AVColorTransferCharacteristic dst, enum AVColorTransferCharacteristic src); /** * Scale source data from `src` and write the output to `dst`. This is * merely a convenience wrapper around `avscale_frame_slice(ctx, dst, src, 0, * src->height)`. * * @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 (or all) 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); /** * Like `avscale_frame`, but operates only on the (source) range from `ystart` * to `height`. * * Note: For interlaced or vertically subsampled frames, `ystart` and `height` * must be aligned to a multiple of the subsampling size (typically 2, or 4 in * the case of interlaced subsampled material). * * @param ctx The scaling context. * @param dst The destination frame. See avscale_framee() for more details. * @param src The source frame. See avscale_framee() for more details. * @param slice_start First row of slice, relative to `src` * @param slice_height Number of (source) rows in the slice * * @return 0 on success, a negative AVERROR code on failure. */ int avscale_frame_slice(AVScaleContext *ctx, AVFrame *dst, const AVFrame *src, int slice_start, int slice_height); #endif /* SWSCALE_AVSCALE_H */