[FFmpeg-cvslog] swscale/utils: Move functions to avoid forward declarations
Andreas Rheinhardt
git at videolan.org
Thu Nov 24 22:15:41 EET 2022
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sat Nov 19 05:58:59 2022 +0100| [ff39dcb129806477e9a05c30dfdefb96f7fb0a25] | committer: Andreas Rheinhardt
swscale/utils: Move functions to avoid forward declarations
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ff39dcb129806477e9a05c30dfdefb96f7fb0a25
---
libswscale/utils.c | 407 ++++++++++++++++++++++++++---------------------------
1 file changed, 200 insertions(+), 207 deletions(-)
diff --git a/libswscale/utils.c b/libswscale/utils.c
index fb788fc330..cdd89e4b58 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -59,13 +59,6 @@
#include "swscale.h"
#include "swscale_internal.h"
-static SwsVector *sws_getIdentityVec(void);
-static void sws_addVec(SwsVector *a, SwsVector *b);
-static void sws_shiftVec(SwsVector *a, int shift);
-static void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level);
-
-static void handle_formats(SwsContext *c);
-
typedef struct FormatEntry {
uint8_t is_supported_in :1;
uint8_t is_supported_out :1;
@@ -926,6 +919,74 @@ static void fill_xyztables(struct SwsContext *c)
}
}
+static int handle_jpeg(enum AVPixelFormat *format)
+{
+ switch (*format) {
+ case AV_PIX_FMT_YUVJ420P:
+ *format = AV_PIX_FMT_YUV420P;
+ return 1;
+ case AV_PIX_FMT_YUVJ411P:
+ *format = AV_PIX_FMT_YUV411P;
+ return 1;
+ case AV_PIX_FMT_YUVJ422P:
+ *format = AV_PIX_FMT_YUV422P;
+ return 1;
+ case AV_PIX_FMT_YUVJ444P:
+ *format = AV_PIX_FMT_YUV444P;
+ return 1;
+ case AV_PIX_FMT_YUVJ440P:
+ *format = AV_PIX_FMT_YUV440P;
+ return 1;
+ case AV_PIX_FMT_GRAY8:
+ case AV_PIX_FMT_YA8:
+ case AV_PIX_FMT_GRAY9LE:
+ case AV_PIX_FMT_GRAY9BE:
+ case AV_PIX_FMT_GRAY10LE:
+ case AV_PIX_FMT_GRAY10BE:
+ case AV_PIX_FMT_GRAY12LE:
+ case AV_PIX_FMT_GRAY12BE:
+ case AV_PIX_FMT_GRAY14LE:
+ case AV_PIX_FMT_GRAY14BE:
+ case AV_PIX_FMT_GRAY16LE:
+ case AV_PIX_FMT_GRAY16BE:
+ case AV_PIX_FMT_YA16BE:
+ case AV_PIX_FMT_YA16LE:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+static int handle_0alpha(enum AVPixelFormat *format)
+{
+ switch (*format) {
+ case AV_PIX_FMT_0BGR : *format = AV_PIX_FMT_ABGR ; return 1;
+ case AV_PIX_FMT_BGR0 : *format = AV_PIX_FMT_BGRA ; return 4;
+ case AV_PIX_FMT_0RGB : *format = AV_PIX_FMT_ARGB ; return 1;
+ case AV_PIX_FMT_RGB0 : *format = AV_PIX_FMT_RGBA ; return 4;
+ default: return 0;
+ }
+}
+
+static int handle_xyz(enum AVPixelFormat *format)
+{
+ switch (*format) {
+ case AV_PIX_FMT_XYZ12BE : *format = AV_PIX_FMT_RGB48BE; return 1;
+ case AV_PIX_FMT_XYZ12LE : *format = AV_PIX_FMT_RGB48LE; return 1;
+ default: return 0;
+ }
+}
+
+static void handle_formats(SwsContext *c)
+{
+ c->src0Alpha |= handle_0alpha(&c->srcFormat);
+ c->dst0Alpha |= handle_0alpha(&c->dstFormat);
+ c->srcXYZ |= handle_xyz(&c->srcFormat);
+ c->dstXYZ |= handle_xyz(&c->dstFormat);
+ if (c->srcXYZ || c->dstXYZ)
+ fill_xyztables(c);
+}
+
static int range_override_needed(enum AVPixelFormat format)
{
return !isYUV(format) && !isGray(format);
@@ -1112,74 +1173,6 @@ int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table,
return 0;
}
-static int handle_jpeg(enum AVPixelFormat *format)
-{
- switch (*format) {
- case AV_PIX_FMT_YUVJ420P:
- *format = AV_PIX_FMT_YUV420P;
- return 1;
- case AV_PIX_FMT_YUVJ411P:
- *format = AV_PIX_FMT_YUV411P;
- return 1;
- case AV_PIX_FMT_YUVJ422P:
- *format = AV_PIX_FMT_YUV422P;
- return 1;
- case AV_PIX_FMT_YUVJ444P:
- *format = AV_PIX_FMT_YUV444P;
- return 1;
- case AV_PIX_FMT_YUVJ440P:
- *format = AV_PIX_FMT_YUV440P;
- return 1;
- case AV_PIX_FMT_GRAY8:
- case AV_PIX_FMT_YA8:
- case AV_PIX_FMT_GRAY9LE:
- case AV_PIX_FMT_GRAY9BE:
- case AV_PIX_FMT_GRAY10LE:
- case AV_PIX_FMT_GRAY10BE:
- case AV_PIX_FMT_GRAY12LE:
- case AV_PIX_FMT_GRAY12BE:
- case AV_PIX_FMT_GRAY14LE:
- case AV_PIX_FMT_GRAY14BE:
- case AV_PIX_FMT_GRAY16LE:
- case AV_PIX_FMT_GRAY16BE:
- case AV_PIX_FMT_YA16BE:
- case AV_PIX_FMT_YA16LE:
- return 1;
- default:
- return 0;
- }
-}
-
-static int handle_0alpha(enum AVPixelFormat *format)
-{
- switch (*format) {
- case AV_PIX_FMT_0BGR : *format = AV_PIX_FMT_ABGR ; return 1;
- case AV_PIX_FMT_BGR0 : *format = AV_PIX_FMT_BGRA ; return 4;
- case AV_PIX_FMT_0RGB : *format = AV_PIX_FMT_ARGB ; return 1;
- case AV_PIX_FMT_RGB0 : *format = AV_PIX_FMT_RGBA ; return 4;
- default: return 0;
- }
-}
-
-static int handle_xyz(enum AVPixelFormat *format)
-{
- switch (*format) {
- case AV_PIX_FMT_XYZ12BE : *format = AV_PIX_FMT_RGB48BE; return 1;
- case AV_PIX_FMT_XYZ12LE : *format = AV_PIX_FMT_RGB48LE; return 1;
- default: return 0;
- }
-}
-
-static void handle_formats(SwsContext *c)
-{
- c->src0Alpha |= handle_0alpha(&c->srcFormat);
- c->dst0Alpha |= handle_0alpha(&c->dstFormat);
- c->srcXYZ |= handle_xyz(&c->srcFormat);
- c->dstXYZ |= handle_xyz(&c->dstFormat);
- if (c->srcXYZ || c->dstXYZ)
- fill_xyztables(c);
-}
-
SwsContext *sws_alloc_context(void)
{
SwsContext *c = av_mallocz(sizeof(SwsContext));
@@ -1271,55 +1264,6 @@ static enum AVPixelFormat alphaless_fmt(enum AVPixelFormat fmt)
static int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
SwsFilter *dstFilter);
-static int context_init_threaded(SwsContext *c,
- SwsFilter *src_filter, SwsFilter *dst_filter)
-{
- int ret;
-
- ret = avpriv_slicethread_create(&c->slicethread, (void*)c,
- ff_sws_slice_worker, NULL, c->nb_threads);
- if (ret == AVERROR(ENOSYS)) {
- c->nb_threads = 1;
- return 0;
- } else if (ret < 0)
- return ret;
-
- c->nb_threads = ret;
-
- c->slice_ctx = av_calloc(c->nb_threads, sizeof(*c->slice_ctx));
- c->slice_err = av_calloc(c->nb_threads, sizeof(*c->slice_err));
- if (!c->slice_ctx || !c->slice_err)
- return AVERROR(ENOMEM);
-
- for (int i = 0; i < c->nb_threads; i++) {
- c->slice_ctx[i] = sws_alloc_context();
- if (!c->slice_ctx[i])
- return AVERROR(ENOMEM);
-
- c->slice_ctx[i]->parent = c;
-
- ret = av_opt_copy((void*)c->slice_ctx[i], (void*)c);
- if (ret < 0)
- return ret;
-
- c->slice_ctx[i]->nb_threads = 1;
-
- ret = sws_init_single_context(c->slice_ctx[i], src_filter, dst_filter);
- if (ret < 0)
- return ret;
-
- c->nb_slice_ctx++;
-
- if (c->slice_ctx[i]->dither == SWS_DITHER_ED) {
- av_log(c, AV_LOG_VERBOSE,
- "Error-diffusion dither is in use, scaling will be single-threaded.");
- break;
- }
- }
-
- return 0;
-}
-
static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
SwsFilter *dstFilter)
{
@@ -2037,6 +1981,55 @@ fail: // FIXME replace things by appropriate error codes
return ret;
}
+static int context_init_threaded(SwsContext *c,
+ SwsFilter *src_filter, SwsFilter *dst_filter)
+{
+ int ret;
+
+ ret = avpriv_slicethread_create(&c->slicethread, (void*)c,
+ ff_sws_slice_worker, NULL, c->nb_threads);
+ if (ret == AVERROR(ENOSYS)) {
+ c->nb_threads = 1;
+ return 0;
+ } else if (ret < 0)
+ return ret;
+
+ c->nb_threads = ret;
+
+ c->slice_ctx = av_calloc(c->nb_threads, sizeof(*c->slice_ctx));
+ c->slice_err = av_calloc(c->nb_threads, sizeof(*c->slice_err));
+ if (!c->slice_ctx || !c->slice_err)
+ return AVERROR(ENOMEM);
+
+ for (int i = 0; i < c->nb_threads; i++) {
+ c->slice_ctx[i] = sws_alloc_context();
+ if (!c->slice_ctx[i])
+ return AVERROR(ENOMEM);
+
+ c->slice_ctx[i]->parent = c;
+
+ ret = av_opt_copy((void*)c->slice_ctx[i], (void*)c);
+ if (ret < 0)
+ return ret;
+
+ c->slice_ctx[i]->nb_threads = 1;
+
+ ret = sws_init_single_context(c->slice_ctx[i], src_filter, dst_filter);
+ if (ret < 0)
+ return ret;
+
+ c->nb_slice_ctx++;
+
+ if (c->slice_ctx[i]->dither == SWS_DITHER_ED) {
+ av_log(c, AV_LOG_VERBOSE,
+ "Error-diffusion dither is in use, scaling will be single-threaded.");
+ break;
+ }
+ }
+
+ return 0;
+}
+
av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
SwsFilter *dstFilter)
{
@@ -2123,89 +2116,6 @@ static void makenan_vec(SwsVector *a)
a->coeff[i] = NAN;
}
-SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
- float lumaSharpen, float chromaSharpen,
- float chromaHShift, float chromaVShift,
- int verbose)
-{
- SwsFilter *filter = av_malloc(sizeof(SwsFilter));
- if (!filter)
- return NULL;
-
- if (lumaGBlur != 0.0) {
- filter->lumH = sws_getGaussianVec(lumaGBlur, 3.0);
- filter->lumV = sws_getGaussianVec(lumaGBlur, 3.0);
- } else {
- filter->lumH = sws_getIdentityVec();
- filter->lumV = sws_getIdentityVec();
- }
-
- if (chromaGBlur != 0.0) {
- filter->chrH = sws_getGaussianVec(chromaGBlur, 3.0);
- filter->chrV = sws_getGaussianVec(chromaGBlur, 3.0);
- } else {
- filter->chrH = sws_getIdentityVec();
- filter->chrV = sws_getIdentityVec();
- }
-
- if (!filter->lumH || !filter->lumV || !filter->chrH || !filter->chrV)
- goto fail;
-
- if (chromaSharpen != 0.0) {
- SwsVector *id = sws_getIdentityVec();
- if (!id)
- goto fail;
- sws_scaleVec(filter->chrH, -chromaSharpen);
- sws_scaleVec(filter->chrV, -chromaSharpen);
- sws_addVec(filter->chrH, id);
- sws_addVec(filter->chrV, id);
- sws_freeVec(id);
- }
-
- if (lumaSharpen != 0.0) {
- SwsVector *id = sws_getIdentityVec();
- if (!id)
- goto fail;
- sws_scaleVec(filter->lumH, -lumaSharpen);
- sws_scaleVec(filter->lumV, -lumaSharpen);
- sws_addVec(filter->lumH, id);
- sws_addVec(filter->lumV, id);
- sws_freeVec(id);
- }
-
- if (chromaHShift != 0.0)
- sws_shiftVec(filter->chrH, (int)(chromaHShift + 0.5));
-
- if (chromaVShift != 0.0)
- sws_shiftVec(filter->chrV, (int)(chromaVShift + 0.5));
-
- sws_normalizeVec(filter->chrH, 1.0);
- sws_normalizeVec(filter->chrV, 1.0);
- sws_normalizeVec(filter->lumH, 1.0);
- sws_normalizeVec(filter->lumV, 1.0);
-
- if (isnan_vec(filter->chrH) ||
- isnan_vec(filter->chrV) ||
- isnan_vec(filter->lumH) ||
- isnan_vec(filter->lumV))
- goto fail;
-
- if (verbose)
- sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG);
- if (verbose)
- sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG);
-
- return filter;
-
-fail:
- sws_freeVec(filter->lumH);
- sws_freeVec(filter->lumV);
- sws_freeVec(filter->chrH);
- sws_freeVec(filter->chrV);
- av_freep(&filter);
- return NULL;
-}
-
SwsVector *sws_allocVec(int length)
{
SwsVector *vec;
@@ -2417,6 +2327,89 @@ void sws_freeFilter(SwsFilter *filter)
av_free(filter);
}
+SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
+ float lumaSharpen, float chromaSharpen,
+ float chromaHShift, float chromaVShift,
+ int verbose)
+{
+ SwsFilter *filter = av_malloc(sizeof(SwsFilter));
+ if (!filter)
+ return NULL;
+
+ if (lumaGBlur != 0.0) {
+ filter->lumH = sws_getGaussianVec(lumaGBlur, 3.0);
+ filter->lumV = sws_getGaussianVec(lumaGBlur, 3.0);
+ } else {
+ filter->lumH = sws_getIdentityVec();
+ filter->lumV = sws_getIdentityVec();
+ }
+
+ if (chromaGBlur != 0.0) {
+ filter->chrH = sws_getGaussianVec(chromaGBlur, 3.0);
+ filter->chrV = sws_getGaussianVec(chromaGBlur, 3.0);
+ } else {
+ filter->chrH = sws_getIdentityVec();
+ filter->chrV = sws_getIdentityVec();
+ }
+
+ if (!filter->lumH || !filter->lumV || !filter->chrH || !filter->chrV)
+ goto fail;
+
+ if (chromaSharpen != 0.0) {
+ SwsVector *id = sws_getIdentityVec();
+ if (!id)
+ goto fail;
+ sws_scaleVec(filter->chrH, -chromaSharpen);
+ sws_scaleVec(filter->chrV, -chromaSharpen);
+ sws_addVec(filter->chrH, id);
+ sws_addVec(filter->chrV, id);
+ sws_freeVec(id);
+ }
+
+ if (lumaSharpen != 0.0) {
+ SwsVector *id = sws_getIdentityVec();
+ if (!id)
+ goto fail;
+ sws_scaleVec(filter->lumH, -lumaSharpen);
+ sws_scaleVec(filter->lumV, -lumaSharpen);
+ sws_addVec(filter->lumH, id);
+ sws_addVec(filter->lumV, id);
+ sws_freeVec(id);
+ }
+
+ if (chromaHShift != 0.0)
+ sws_shiftVec(filter->chrH, (int)(chromaHShift + 0.5));
+
+ if (chromaVShift != 0.0)
+ sws_shiftVec(filter->chrV, (int)(chromaVShift + 0.5));
+
+ sws_normalizeVec(filter->chrH, 1.0);
+ sws_normalizeVec(filter->chrV, 1.0);
+ sws_normalizeVec(filter->lumH, 1.0);
+ sws_normalizeVec(filter->lumV, 1.0);
+
+ if (isnan_vec(filter->chrH) ||
+ isnan_vec(filter->chrV) ||
+ isnan_vec(filter->lumH) ||
+ isnan_vec(filter->lumV))
+ goto fail;
+
+ if (verbose)
+ sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG);
+ if (verbose)
+ sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG);
+
+ return filter;
+
+fail:
+ sws_freeVec(filter->lumH);
+ sws_freeVec(filter->lumV);
+ sws_freeVec(filter->chrH);
+ sws_freeVec(filter->chrV);
+ av_freep(&filter);
+ return NULL;
+}
+
void sws_freeContext(SwsContext *c)
{
int i;
More information about the ffmpeg-cvslog
mailing list