mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2026-03-13 09:00:40 +08:00
swscale/tests/swscale: split init_ref() out of main()
Sponsored-by: Sovereign Tech Fund Signed-off-by: Ramiro Polla <ramiro.polla@gmail.com>
This commit is contained in:
@@ -517,6 +517,40 @@ static int run_file_tests(const AVFrame *ref, FILE *fp, struct options opts)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init_ref(AVFrame *ref, const struct options *opts)
|
||||
{
|
||||
SwsContext *ctx = sws_alloc_context();
|
||||
AVFrame *rgb = av_frame_alloc();
|
||||
AVLFG rand;
|
||||
int ret = -1;
|
||||
|
||||
if (!ctx || !rgb)
|
||||
goto error;
|
||||
|
||||
rgb->width = opts->w / 12;
|
||||
rgb->height = opts->h / 12;
|
||||
rgb->format = AV_PIX_FMT_RGBA;
|
||||
ret = av_frame_get_buffer(rgb, 32);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
av_lfg_init(&rand, 1);
|
||||
for (int y = 0; y < rgb->height; y++) {
|
||||
for (int x = 0; x < rgb->width; x++) {
|
||||
for (int c = 0; c < 4; c++)
|
||||
rgb->data[0][y * rgb->linesize[0] + x * 4 + c] = av_lfg_get(&rand);
|
||||
}
|
||||
}
|
||||
|
||||
ctx->flags = SWS_BILINEAR;
|
||||
ret = sws_scale_frame(ctx, ref, rgb);
|
||||
|
||||
error:
|
||||
sws_free_context(&ctx);
|
||||
av_frame_free(&rgb);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int parse_options(int argc, char **argv, struct options *opts, FILE **fp)
|
||||
{
|
||||
for (int i = 1; i < argc; i += 2) {
|
||||
@@ -628,16 +662,14 @@ int main(int argc, char **argv)
|
||||
.dither = -1,
|
||||
};
|
||||
|
||||
AVFrame *rgb = NULL, *ref = NULL;
|
||||
AVFrame *ref = NULL;
|
||||
FILE *fp = NULL;
|
||||
AVLFG rand;
|
||||
int ret = -1;
|
||||
|
||||
if (parse_options(argc, argv, &opts, &fp) < 0)
|
||||
goto error;
|
||||
|
||||
ff_sfc64_init(&prng_state, 0, 0, 0, 12);
|
||||
av_lfg_init(&rand, 1);
|
||||
signal(SIGINT, exit_handler);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
@@ -647,22 +679,6 @@ int main(int argc, char **argv)
|
||||
sws[i]->flags = SWS_BILINEAR;
|
||||
}
|
||||
|
||||
rgb = av_frame_alloc();
|
||||
if (!rgb)
|
||||
goto error;
|
||||
rgb->width = opts.w / 12;
|
||||
rgb->height = opts.h / 12;
|
||||
rgb->format = AV_PIX_FMT_RGBA;
|
||||
if (av_frame_get_buffer(rgb, 32) < 0)
|
||||
goto error;
|
||||
|
||||
for (int y = 0; y < rgb->height; y++) {
|
||||
for (int x = 0; x < rgb->width; x++) {
|
||||
for (int c = 0; c < 4; c++)
|
||||
rgb->data[0][y * rgb->linesize[0] + x * 4 + c] = av_lfg_get(&rand);
|
||||
}
|
||||
}
|
||||
|
||||
ref = av_frame_alloc();
|
||||
if (!ref)
|
||||
goto error;
|
||||
@@ -670,7 +686,7 @@ int main(int argc, char **argv)
|
||||
ref->height = opts.h;
|
||||
ref->format = AV_PIX_FMT_YUVA444P;
|
||||
|
||||
if (sws_scale_frame(sws[0], ref, rgb) < 0)
|
||||
if (init_ref(ref, &opts) < 0)
|
||||
goto error;
|
||||
|
||||
ret = fp ? run_file_tests(ref, fp, opts)
|
||||
@@ -680,7 +696,6 @@ int main(int argc, char **argv)
|
||||
error:
|
||||
for (int i = 0; i < 3; i++)
|
||||
sws_free_context(&sws[i]);
|
||||
av_frame_free(&rgb);
|
||||
av_frame_free(&ref);
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
|
||||
Reference in New Issue
Block a user